From: Inkyun Kil Date: Fri, 4 Aug 2023 02:04:15 +0000 (+0900) Subject: Improves code coverage X-Git-Tag: accepted/tizen/unified/20230913.091619~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c230e092eb1d2760e4dcd872c25a94693daa110d;p=platform%2Fcore%2Fappfw%2Fmessage-port.git Improves code coverage Change-Id: I8aa04fdb1822ac83d962ca09880008ca8f6dec3f Signed-off-by: Inkyun Kil --- diff --git a/mock/app_common_mock.cc b/mock/app_common_mock.cc deleted file mode 100644 index 801c681..0000000 --- a/mock/app_common_mock.cc +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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); -} diff --git a/mock/app_common_mock.h b/mock/app_common_mock.h deleted file mode 100644 index 835062d..0000000 --- a/mock/app_common_mock.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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 - -#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_ - diff --git a/mock/aul_mock.cc b/mock/aul_mock.cc deleted file mode 100644 index 96d66ca..0000000 --- a/mock/aul_mock.cc +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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); -} diff --git a/mock/aul_mock.h b/mock/aul_mock.h deleted file mode 100644 index 92b7ad4..0000000 --- a/mock/aul_mock.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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 - -#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_ - diff --git a/mock/gio_mock.cc b/mock/gio_mock.cc index 0b88132..4d084ef 100644 --- a/mock/gio_mock.cc +++ b/mock/gio_mock.cc @@ -46,13 +46,6 @@ extern "C" GVariant* g_dbus_message_get_body(GDBusMessage* arg0) { 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); @@ -72,36 +65,6 @@ extern "C" gboolean g_dbus_connection_unregister_object (GDBusConnection *connec 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) { diff --git a/mock/gio_mock.h b/mock/gio_mock.h index 3867d5c..5925d36 100644 --- a/mock/gio_mock.h +++ b/mock/gio_mock.h @@ -28,10 +28,6 @@ class GioMock : public virtual ModuleMock { 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*)); @@ -43,21 +39,9 @@ class GioMock : public virtual ModuleMock { 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**)); diff --git a/src/message_port_common.c b/src/message_port_common.c index 5c96428..2230e6b 100644 --- a/src/message_port_common.c +++ b/src/message_port_common.c @@ -63,6 +63,7 @@ int write_socket(int fd, 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++; @@ -76,7 +77,7 @@ int write_socket(int fd, return MESSAGE_PORT_ERROR_IO_ERROR; } - +/* LCOV_EXCL_STOP */ left -= nb; buffer += nb; *bytes_write += nb; @@ -136,6 +137,7 @@ int read_socket(int fd, 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); @@ -146,6 +148,7 @@ int read_socket(int fd, } LOGE("read_socket: ...error fd %d: errno %d\n", fd, errno); return MESSAGE_PORT_ERROR_IO_ERROR; +/* LCOV_EXCL_STOP */ } left -= nb; @@ -237,7 +240,7 @@ bool is_preloaded(const char *local_appid, const char *remote_appid) 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; diff --git a/src/message_port_local.c b/src/message_port_local.c index 0090517..af75486 100644 --- a/src/message_port_local.c +++ b/src/message_port_local.c @@ -397,7 +397,7 @@ static void __socket_destroy_handler(gpointer data) __free_key_info(key_info); } - +/* LCOV_EXCL_START */ static void __delay_socket_destroy_handler(gpointer data) { _LOGI("__delay_socket_destroy_handler"); @@ -408,6 +408,7 @@ static void __delay_socket_destroy_handler(gpointer data) 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, @@ -888,7 +889,6 @@ out: return ret; } -/* LCOV_EXCL_STOP */ static bool __can_write(int fd) { @@ -905,6 +905,7 @@ 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) @@ -964,7 +965,7 @@ static int __message_port_send_async(port_list_info_s *port_info, bundle *kb, co } 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); @@ -989,7 +990,7 @@ out: } } } - +/* LCOV_EXCL_STOP */ if (kb_data) free(kb_data); @@ -1247,11 +1248,13 @@ int watch_remote_port(int *watcher_id, const char *remote_app_id, const char *re 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, diff --git a/src/message_port_remote.c b/src/message_port_remote.c index a872890..0b3debe 100644 --- a/src/message_port_remote.c +++ b/src/message_port_remote.c @@ -533,6 +533,7 @@ static void __callback_info_update_user_data(int local_id, message_port_message_ 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) { @@ -540,6 +541,7 @@ static void __callback_info_update_user_data(int local_id, message_port_message_ callback_info->local_info->user_data = user_data; } } +/* LCOV_EXCL_STOP */ } else { _LOGE("fail to find local_id %d ", local_id); } @@ -620,6 +622,7 @@ static bool __receive_message(GVariant *parameters, GDBusMethodInvocation *invoc 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); @@ -634,6 +637,7 @@ static bool __receive_message(GVariant *parameters, GDBusMethodInvocation *invoc } } } +/* LCOV_EXCL_STOP */ } data = bundle_decode(raw, len); @@ -804,7 +808,7 @@ static bool __check_sender_validation(GVariant *parameters, const char *sender, } return true; } - +/* LCOV_EXCL_START */ static void __close_socket(GDBusMethodInvocation *invocation) { GDBusMessage *msg; @@ -822,6 +826,7 @@ static void __close_socket(GDBusMethodInvocation *invocation) } } } +/* 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, @@ -1084,9 +1089,8 @@ int unregister_local_port(int local_port_id, bool trusted_port) 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; @@ -1095,6 +1099,7 @@ int unregister_local_port(int local_port_id, bool trusted_port) 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; diff --git a/test/unit_tests/test_message_port.cc b/test/unit_tests/test_message_port.cc index 5f59fa5..425dbe9 100644 --- a/test/unit_tests/test_message_port.cc +++ b/test/unit_tests/test_message_port.cc @@ -28,9 +28,8 @@ #include #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::_; @@ -127,9 +126,7 @@ extern "C" GVariant* g_dbus_connection_call_sync( return g_variant_new("(u)", 1); } -class Mocks : public ::testing::NiceMock, - public ::testing::NiceMock, - public ::testing::NiceMock {}; +class Mocks : public ::testing::NiceMock {}; class MessagePortTest : public TestFixture { public: @@ -189,6 +186,19 @@ static guint __connection_register_object(GDBusConnection* connection, 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(), g_bus_get_sync(_, _, _)). WillOnce(Return(&__gdbus_conn)); @@ -315,7 +325,7 @@ TEST_F(MessagePortTest, message_port_register_local_port3) { g_dbus_node_info_new_for_xml(_, _)).WillOnce(Return(info)); EXPECT_CALL(GetMock(), 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);