+++ /dev/null
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "app_common_mock.h"
-
-#include "mock_hook.h"
-#include "test_fixture.h"
-
-extern "C" int app_get_id(char **id) {
- return MOCK_HOOK_P1(AppCommonMock, app_get_id, id);
-}
+++ /dev/null
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef UNIT_TESTS_MOCK_APP_COMMON_MOCK_H_
-#define UNIT_TESTS_MOCK_APP_COMMON_MOCK_H_
-
-#include <gmock/gmock.h>
-
-#include "module_mock.h"
-
-class AppCommonMock : public virtual ModuleMock {
- public:
- virtual ~AppCommonMock() {}
-
- MOCK_METHOD1(app_get_id, int (char **id));
-};
-
-#endif // UNIT_TESTS_MOCK_APP_COMMON_MOCK_H_
-
+++ /dev/null
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "aul_mock.h"
-
-#include "mock_hook.h"
-#include "test_fixture.h"
-
-extern "C" int aul_app_get_pkgid_bypid(int pid, char *pkgid, int len) {
- return MOCK_HOOK_P3(AulMock, aul_app_get_pkgid_bypid, pid, pkgid, len);
-}
+++ /dev/null
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef UNIT_TESTS_MOCK_AUL_MOCK_H_
-#define UNIT_TESTS_MOCK_AUL_MOCK_H_
-
-#include <gmock/gmock.h>
-
-#include "module_mock.h"
-
-class AulMock : public virtual ModuleMock {
- public:
- virtual ~AulMock() {}
-
- MOCK_METHOD3(aul_app_get_pkgid_bypid, int (int , char *, int));
-};
-
-#endif // UNIT_TESTS_MOCK_AUL_MOCK_H_
-
return MOCK_HOOK_P1(GioMock, g_dbus_message_get_body, arg0);
}
-extern "C" gboolean g_dbus_connection_emit_signal(GDBusConnection* arg0,
- const gchar* arg1, const gchar* arg2, const gchar* arg3, const gchar* arg4,
- GVariant* arg5, GError** arg6) {
- return MOCK_HOOK_P7(GioMock, g_dbus_connection_emit_signal,
- arg0, arg1, arg2, arg3, arg4, arg5, arg6);
-}
-
extern "C" GDBusNodeInfo* g_dbus_node_info_new_for_xml(
const gchar* arg0, GError** arg1) {
return MOCK_HOOK_P2(GioMock, g_dbus_node_info_new_for_xml, arg0, arg1);
connection, registration_id);
}
-extern "C" guint g_bus_own_name_on_connection(GDBusConnection* arg0,
- const gchar* arg1, GBusNameOwnerFlags arg2,
- GBusNameAcquiredCallback arg3, GBusNameLostCallback arg4,
- gpointer arg5, GDestroyNotify arg6) {
- return MOCK_HOOK_P7(GioMock, g_bus_own_name_on_connection,
- arg0, arg1, arg2, arg3, arg4, arg5, arg6);
-}
-
-extern "C" guint g_dbus_connection_signal_subscribe(GDBusConnection* arg0,
- const gchar* arg1, const gchar* arg2, const gchar* arg3, const gchar* arg4,
- const gchar* arg5, GDBusSignalFlags arg6, GDBusSignalCallback arg7,
- gpointer arg8, GDestroyNotify arg9) {
- return MOCK_HOOK_P10(GioMock, g_dbus_connection_signal_subscribe,
- arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
-}
-
-extern "C" void g_dbus_connection_send_message_with_reply(GDBusConnection* arg0,
- GDBusMessage* arg1, GDBusSendMessageFlags arg2, gint arg3,
- volatile guint32* arg4, GCancellable* arg5, GAsyncReadyCallback arg6,
- gpointer arg7) {
- return MOCK_HOOK_P8(GioMock, g_dbus_connection_send_message_with_reply,
- arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
-}
-
-extern "C" GDBusMessage* g_dbus_connection_send_message_with_reply_finish(
- GDBusConnection* arg0, GAsyncResult* arg1, GError** arg2) {
- return MOCK_HOOK_P3(GioMock, g_dbus_connection_send_message_with_reply_finish,
- arg0, arg1, arg2);
-}
-
extern "C" gboolean g_dbus_connection_send_message(GDBusConnection* arg0,
GDBusMessage* arg1, GDBusSendMessageFlags arg2,
volatile guint32* arg3, GError** arg4) {
MOCK_METHOD3(g_bus_get_sync,
GDBusConnection*(GBusType, GCancellable*, GError**));
- MOCK_METHOD7(g_bus_own_name_on_connection,
- guint(GDBusConnection*, const gchar*, GBusNameOwnerFlags,
- GBusNameAcquiredCallback, GBusNameLostCallback,
- gpointer, GDestroyNotify));
MOCK_METHOD4(g_dbus_message_new_method_call,
GDBusMessage*(const gchar*, const gchar*, const gchar*, const gchar*));
MOCK_METHOD7(g_dbus_connection_send_message_with_reply_sync,
GDBusMessage*(GDBusConnection*, GDBusMessage*, GDBusSendMessageFlags,
gint, volatile guint32*, GCancellable*, GError**));
- MOCK_METHOD7(g_dbus_connection_emit_signal,
- gboolean(GDBusConnection*, const gchar*, const gchar*, const gchar*,
- const gchar*, GVariant*, GError**));
MOCK_METHOD7(g_dbus_connection_register_object,
guint(GDBusConnection*, const gchar*, GDBusInterfaceInfo*,
const GDBusInterfaceVTable*, gpointer, GDestroyNotify, GError**));
- MOCK_METHOD10(g_dbus_connection_signal_subscribe,
- guint(GDBusConnection*, const gchar*, const gchar*, const gchar*,
- const gchar*, const gchar*, GDBusSignalFlags, GDBusSignalCallback,
- gpointer, GDestroyNotify));
- MOCK_METHOD8(g_dbus_connection_send_message_with_reply,
- void(GDBusConnection*, GDBusMessage*, GDBusSendMessageFlags, gint,
- volatile guint32*, GCancellable*, GAsyncReadyCallback, gpointer));
- MOCK_METHOD3(g_dbus_connection_send_message_with_reply_finish,
- GDBusMessage*(GDBusConnection*, GAsyncResult*, GError**));
MOCK_METHOD2(g_dbus_node_info_new_for_xml,
GDBusNodeInfo*(const gchar*, GError**));
while (left && (retry_cnt < MAX_RETRY_CNT)) {
nb = write(fd, buffer, left);
if (nb == -1) {
+/* LCOV_EXCL_START */
if (errno == EINTR) {
LOGW("write_socket: EINTR continue ...");
retry_cnt++;
return MESSAGE_PORT_ERROR_IO_ERROR;
}
-
+/* LCOV_EXCL_STOP */
left -= nb;
buffer += nb;
*bytes_write += nb;
LOGE("read_socket: ...read EOF, socket closed %d: nb %zd\n", fd, nb);
return MESSAGE_PORT_ERROR_IO_ERROR;
} else if (nb == -1) {
+/* LCOV_EXCL_START */
/* wrt(nodejs) could change socket to none-blocking socket :-( */
if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) {
LOGW("read_socket: %d , sleep and retry ...", errno);
}
LOGE("read_socket: ...error fd %d: errno %d\n", fd, errno);
return MESSAGE_PORT_ERROR_IO_ERROR;
+/* LCOV_EXCL_STOP */
}
left -= nb;
pkgmgrinfo_appinfo_h handle = NULL;
int ret = pkgmgrinfo_appinfo_get_usr_appinfo(local_appid, getuid(), &handle);
- if (ret != PMINFO_R_OK) {
+ if (ret != PMINFO_R_OK) {
_LOGE("Failed to get the appinfo. %d", ret);
pkgmgrinfo_appinfo_destroy_appinfo(handle);
return false;
__free_key_info(key_info);
}
-
+/* LCOV_EXCL_START */
static void __delay_socket_destroy_handler(gpointer data)
{
_LOGI("__delay_socket_destroy_handler");
FREE_AND_NULL(delay_info->key_info);
free(delay_info);
}
+/* LCOV_EXCL_STOP */
static int __create_port_key_info(
port_list_info_s *port_info,
return ret;
}
-/* LCOV_EXCL_STOP */
static bool __can_write(int fd)
{
return true;
}
+/* LCOV_EXCL_STOP */
static int __message_port_send_async(port_list_info_s *port_info, bundle *kb, const char *local_port,
bool local_trusted, bool is_bidirection)
}
out:
-
+/* LCOV_EXCL_START */
if (ret == MESSAGE_PORT_ERROR_RESOURCE_UNAVAILABLE) {
ret = __push_delayed_message(port_info, sequence, kb_data, data_len, nb,
local_port, local_trusted, is_bidirection);
}
}
}
-
+/* LCOV_EXCL_STOP */
if (kb_data)
free(kb_data);
registered_cb_info,
NULL);
if (registered_cb_info->watcher_id == 0) {
+/* LCOV_EXCL_START */
free(registered_cb_info->remote_app_id);
free(registered_cb_info->remote_port);
free(registered_cb_info);
_LOGE("Failed to watch name");
return MESSAGE_PORT_ERROR_IO_ERROR;
+/* LCOV_EXCL_STOP */
}
g_hash_table_insert(__registered_callback_info_hash,
callback_info_list = g_hash_table_lookup(__callback_info_hash, GUINT_TO_POINTER(local_id));
if (callback_info_list != NULL) {
+/* LCOV_EXCL_START */
for (iter = callback_info_list; iter != NULL; iter = iter->next) {
callback_info = (message_port_callback_info_s *)iter->data;
if (callback_info->local_info != NULL) {
callback_info->local_info->user_data = user_data;
}
}
+/* LCOV_EXCL_STOP */
} else {
_LOGE("fail to find local_id %d ", local_id);
}
goto out;
}
if (remote_trusted) {
+/* LCOV_EXCL_START */
if (g_hash_table_lookup(__trusted_app_list_hash, (gpointer)local_appid) == NULL) {
if (!is_preloaded(local_appid, remote_appid)) {
int ret = check_certificate(local_appid, remote_appid);
}
}
}
+/* LCOV_EXCL_STOP */
}
data = bundle_decode(raw, len);
}
return true;
}
-
+/* LCOV_EXCL_START */
static void __close_socket(GDBusMethodInvocation *invocation)
{
GDBusMessage *msg;
}
}
}
+/* LCOV_EXCL_STOP */
static void __dbus_method_call_handler(GDBusConnection *conn,
const gchar *sender, const gchar *object_path,
const gchar *iface_name, const gchar *method_name,
if (result)
g_variant_unref(result);
-
+/* LCOV_EXCL_START */
if (ret != DBUS_RELEASE_NAME_REPLY_RELEASED) {
-
if (ret == DBUS_RELEASE_NAME_REPLY_NON_EXISTENT) {
_LOGE("Port Not exist");
return MESSAGE_PORT_ERROR_PORT_NOT_FOUND;
return MESSAGE_PORT_ERROR_INVALID_PARAMETER;
}
}
+/* LCOV_EXCL_STOP */
g_hash_table_remove(__local_port_info, GINT_TO_POINTER(local_port_id));
return MESSAGE_PORT_ERROR_NONE;
#include <memory>
#include "message_port.h"
-#include "app_common_mock.h"
#include "gio_mock.h"
-#include "aul_mock.h"
+#include "aul.h"
#include "test_fixture.h"
using ::testing::_;
return g_variant_new("(u)", 1);
}
-class Mocks : public ::testing::NiceMock<AppCommonMock>,
- public ::testing::NiceMock<GioMock>,
- public ::testing::NiceMock<AulMock> {};
+class Mocks : public ::testing::NiceMock<GioMock> {};
class MessagePortTest : public TestFixture {
public:
return __port_id;
}
+static guint __connection_register_object_trusted(GDBusConnection* connection,
+ const gchar* object_path, GDBusInterfaceInfo* interface_info,
+ const GDBusInterfaceVTable* vtable, gpointer user_data,
+ GDestroyNotify user_data_free_func, GError** error) {
+ tizen_base::Bundle msg;
+ vtable->method_call(&__gdbus_conn, "sender", "obj_path", "iface_name",
+ "send_message",
+ g_variant_new("(ssbbssbus)", "test", "PORT", 1, 0, "test",
+ "PORT", 0, 1, msg.ToRaw().first.get()),
+ nullptr, nullptr);
+ return __port_id;
+}
+
TEST_F(MessagePortTest, message_port_register_local_port) {
EXPECT_CALL(GetMock<GioMock>(), g_bus_get_sync(_, _, _)).
WillOnce(Return(&__gdbus_conn));
g_dbus_node_info_new_for_xml(_, _)).WillOnce(Return(info));
EXPECT_CALL(GetMock<GioMock>(),
g_dbus_connection_register_object(_, _, _, _, _, _, _)).
- WillOnce(Invoke(__connection_register_object));
+ WillOnce(Invoke(__connection_register_object_trusted));
__port_id = 20;
int port = message_port_register_local_port("PORT3", __message_cb, nullptr);