From fed90c92a76c4aba806a710999e61efaff5c6e37 Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Thu, 5 Jan 2023 16:58:41 +0900 Subject: [PATCH] Improve unittests and adds omitted code - Improve coverage - Add some tests - Adds omitted code for ondemand launch app - bundle -> bundle_cpp Change-Id: I6dfc36bb4b1f4a389d0431304741b3cda5110670 Signed-off-by: Inkyun Kil --- src/modules/dbus_event/dbus_event_module.cc | 43 ++-- src/modules/dbus_event/event_launch.cc | 9 + tests/cion_unit_tests/CMakeLists.txt | 2 +- tests/cion_unit_tests/src/test_cion_module.cc | 6 +- tests/dbus_event_unit_tests/CMakeLists.txt | 2 +- .../src/test_dbus_event_module.cc | 256 +++++++++++++++++++++ .../dbus_event_unit_tests/src/test_earlier_item.cc | 72 ++++++ .../dbus_event_unit_tests/src/test_event_launch.cc | 100 ++++++++ .../src/test_privilege_checker.cc | 6 +- .../src/test_vconf_handler.cc | 10 +- tests/mock/aul_mock.cc | 14 +- tests/mock/aul_mock.h | 6 +- tests/mock/eventsystem_mock.cc | 5 + tests/mock/eventsystem_mock.h | 3 +- tests/mock/gio_mock.cc | 54 ++++- tests/mock/gio_mock.h | 29 ++- tests/mock/pkgmgr_info_mock.cc | 82 +++++-- tests/mock/pkgmgr_info_mock.h | 21 +- tests/mock/tzplatform_config_mock.h | 6 +- tests/mock/vconf_mock.cc | 33 +++ tests/mock/vconf_mock.h | 35 +++ 21 files changed, 698 insertions(+), 96 deletions(-) create mode 100644 tests/dbus_event_unit_tests/src/test_dbus_event_module.cc create mode 100644 tests/dbus_event_unit_tests/src/test_earlier_item.cc create mode 100644 tests/dbus_event_unit_tests/src/test_event_launch.cc create mode 100644 tests/mock/vconf_mock.cc create mode 100644 tests/mock/vconf_mock.h diff --git a/src/modules/dbus_event/dbus_event_module.cc b/src/modules/dbus_event/dbus_event_module.cc index 9469ae9..8ed90ff 100644 --- a/src/modules/dbus_event/dbus_event_module.cc +++ b/src/modules/dbus_event/dbus_event_module.cc @@ -406,18 +406,15 @@ void __esd_signal_handler(GDBusConnection *connection, GVariant *parameters, gpointer user_data) { int handle; - bundle *b; guint64 uid = 0; if (!g_strcmp0(signal_name, SYSTEMD_DBUS_SIGNAL_STARTUP_FINISHED)) { _I("System session finished"); - b = bundle_create(); - bundle_add_str(b, EVT_KEY_BOOT_COMPLETED, - EVT_VAL_BOOT_COMPLETED_TRUE); - eventsystem_send_system_event(SYS_EVENT_BOOT_COMPLETED, b); - bundle_free(b); + tizen_base::Bundle b; + b.Add(EVT_KEY_BOOT_COMPLETED, EVT_VAL_BOOT_COMPLETED_TRUE); + eventsystem_send_system_event(SYS_EVENT_BOOT_COMPLETED, b.GetHandle()); handle = creat(ESD_BOOT_COMPLETED, 0640); if (handle != -1) @@ -538,15 +535,13 @@ void __esd_on_bus_acquired(GDBusConnection *connection, void __esd_on_name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data) { - bundle *b; + tizen_base::Bundle b; __esd_check_trusted_events(connection, "ListNames"); __esd_check_trusted_events(connection, "ListActivatableNames"); - b = bundle_create(); - bundle_add_str(b, EVT_KEY_ESD_STATUS, EVT_VAL_ESD_STARTED); - eventsystem_send_system_event(SYS_EVENT_ESD_STATUS, b); - bundle_free(b); + b.Add(EVT_KEY_ESD_STATUS, EVT_VAL_ESD_STARTED); + eventsystem_send_system_event(SYS_EVENT_ESD_STATUS, b.GetHandle()); esd::module::DbusEventModule* mod = static_cast(user_data); @@ -1080,30 +1075,20 @@ void DbusEventModule::CheckLastDataMethodCall(GDBusConnection* connection, auto it = user_last_event_table_.find(key); if (it != user_last_event_table_.end()) { GVariant *gv; - bundle *b; - bundle_raw *raw; - int len; + tizen_base::Bundle b; int ret; GError *error = nullptr; - b = bundle_create(); - if (!b) { - result = ES_R_ERROR; - param = g_variant_new("(i)", result); - g_dbus_method_invocation_return_value(invocation, param); - return; - } - - bundle_add_str(b, EVT_KEY_KEPT_EVENT_NAME, event_name); - bundle_add_str(b, EVT_KEY_KEPT_OWN_NAME, own_name); + b.Add(EVT_KEY_KEPT_EVENT_NAME, event_name); + b.Add(EVT_KEY_KEPT_OWN_NAME, own_name); if (CertificateMatcher::Match((*it).second.GetUid(), (*it).second.GetAppId(), sender_uid, app_id) == ES_R_OK) - bundle_add_str(b, EVT_KEY_KEPT_IS_TRUSTED, "true"); + b.Add(EVT_KEY_KEPT_IS_TRUSTED, "true"); else - bundle_add_str(b, EVT_KEY_KEPT_IS_TRUSTED, "false"); + b.Add(EVT_KEY_KEPT_IS_TRUSTED, "false"); - bundle_encode(b, &raw, &len); - gv = g_variant_new("(us)", len, raw); + auto raw = b.ToRaw(); + gv = g_variant_new("(us)", raw.second, raw.first.get()); ret = g_dbus_connection_emit_signal(connection, (*it).second.GetOwnName().c_str(), SYS_EVENT_OBJ_PATH, @@ -1115,8 +1100,6 @@ void DbusEventModule::CheckLastDataMethodCall(GDBusConnection* connection, _E("Unable to emit signal: %s", error->message); g_error_free(error); } - bundle_free_encoded_rawdata(&raw); - bundle_free(b); } param = g_variant_new("(i)", result); diff --git a/src/modules/dbus_event/event_launch.cc b/src/modules/dbus_event/event_launch.cc index 0df70a4..a03436b 100644 --- a/src/modules/dbus_event/event_launch.cc +++ b/src/modules/dbus_event/event_launch.cc @@ -120,6 +120,15 @@ bool EventLaunch::CheckEvent(std::string_view event_name, _D("msg_id(%s)", msg_id.c_str()); if (msg_id.empty()) return false; + } else if (event_name == SYS_EVENT_OUTGOING_MSG) { + auto msg_type = data.GetString(EVT_KEY_OUT_MSG_TYPE); + _D("msg_type(%s)", msg_type.c_str()); + if (msg_type.empty()) + return false; + auto msg_id = data.GetString(EVT_KEY_OUT_MSG_ID); + _D("msg_id(%s)", msg_id.c_str()); + if (msg_id.empty()) + return false; } else if (event_name == SYS_EVENT_WIFI_STATE) { auto val = data.GetString(EVT_KEY_WIFI_STATE); if (val.empty()) diff --git a/tests/cion_unit_tests/CMakeLists.txt b/tests/cion_unit_tests/CMakeLists.txt index 520dd1e..2ae201c 100644 --- a/tests/cion_unit_tests/CMakeLists.txt +++ b/tests/cion_unit_tests/CMakeLists.txt @@ -12,7 +12,7 @@ ADD_EXECUTABLE(${TARGET_ESD_MOD_CION_UNITTESTS} TARGET_INCLUDE_DIRECTORIES(${TARGET_ESD_MOD_CION_UNITTESTS} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../src/modules) TARGET_INCLUDE_DIRECTORIES(${TARGET_ESD_MOD_CION_UNITTESTS} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/../mock) + ${CMAKE_CURRENT_SOURCE_DIR}/../) TARGET_LINK_LIBRARIES(${TARGET_ESD_MOD_CION_UNITTESTS} PRIVATE ${TARGET_LIB_ESD}) diff --git a/tests/cion_unit_tests/src/test_cion_module.cc b/tests/cion_unit_tests/src/test_cion_module.cc index 68e1bfb..2312d65 100644 --- a/tests/cion_unit_tests/src/test_cion_module.cc +++ b/tests/cion_unit_tests/src/test_cion_module.cc @@ -17,9 +17,9 @@ #include #include "cion/cion_module.hh" -#include "pkgmgr_info_mock.h" -#include "tzplatform_config_mock.h" -#include "test_fixture.h" +#include "mock/pkgmgr_info_mock.h" +#include "mock/tzplatform_config_mock.h" +#include "mock/test_fixture.h" using ::testing::_; using ::testing::DoAll; diff --git a/tests/dbus_event_unit_tests/CMakeLists.txt b/tests/dbus_event_unit_tests/CMakeLists.txt index be32285..57bb450 100644 --- a/tests/dbus_event_unit_tests/CMakeLists.txt +++ b/tests/dbus_event_unit_tests/CMakeLists.txt @@ -12,7 +12,7 @@ ADD_EXECUTABLE(${TARGET_ESD_MOD_DBUS_EVENT_UNITTESTS} TARGET_INCLUDE_DIRECTORIES(${TARGET_ESD_MOD_DBUS_EVENT_UNITTESTS} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../src/modules) TARGET_INCLUDE_DIRECTORIES(${TARGET_ESD_MOD_DBUS_EVENT_UNITTESTS} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/../mock) + ${CMAKE_CURRENT_SOURCE_DIR}/..) TARGET_LINK_LIBRARIES(${TARGET_ESD_MOD_DBUS_EVENT_UNITTESTS} PRIVATE ${TARGET_LIB_ESD}) diff --git a/tests/dbus_event_unit_tests/src/test_dbus_event_module.cc b/tests/dbus_event_unit_tests/src/test_dbus_event_module.cc new file mode 100644 index 0000000..5662feb --- /dev/null +++ b/tests/dbus_event_unit_tests/src/test_dbus_event_module.cc @@ -0,0 +1,256 @@ +/* + * Copyright (c) 2023 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 + +#include +#include + +#include "mock/test_fixture.h" +#include "mock/aul_mock.h" +#include "mock/cynara_mock.h" +#include "mock/eventsystem_mock.h" +#include "mock/gio_mock.h" +#include "mock/pkgmgr_info_mock.h" +#include "mock/vconf_mock.h" +#include "dbus_event/dbus_event_module.hh" + +using ::testing::_; +using ::testing::DoAll; +using ::testing::Invoke; +using ::testing::InvokeArgument; +using ::testing::Return; + +namespace { + +struct AppCtrlData { + AppCtrlData(std::string_view appid, std::string_view pkgid, uid_t uid) + : appid_(appid), pkgid_(pkgid), uid_(uid) { + } + + std::string_view appid_; + std::string_view pkgid_; + uid_t uid_; +}; + +std::string pkgid_str("pkgid"); + +class Mocks : public ::testing::NiceMock, + public ::testing::NiceMock, + public ::testing::NiceMock, + public ::testing::NiceMock, + public ::testing::NiceMock, + public ::testing::NiceMock {}; + +} // namespace + +class DbusEventMoudleTest : public TestFixture { + public: + DbusEventMoudleTest() : TestFixture(std::make_unique()) {} + virtual ~DbusEventMoudleTest() {} + + virtual void SetUp() { + info_ = reinterpret_cast(malloc(sizeof(GDBusNodeInfo))); + pc_ = reinterpret_cast(malloc(sizeof(pkgmgr_client))); + + EXPECT_CALL(GetMock(), g_dbus_node_info_new_for_xml(_, _)) + .WillOnce(Return(info_)); + EXPECT_CALL(GetMock(), g_dbus_method_invocation_return_value(_, _)) + .WillRepeatedly(Return()); + EXPECT_CALL(GetMock(), eventsystem_register_event(_, _, _, _)) + .WillRepeatedly(Return(ES_R_OK)); + + module_ = std::make_unique(); + tools_ = std::make_unique(); + } + + virtual void TearDown() { + module_->Shutdown(); + module_.reset(); + tools_.reset(); + free(info_); + free(pc_); + } + + std::unique_ptr module_; + std::unique_ptr tools_; + GDBusNodeInfo* info_; + pkgmgr_client* pc_; +}; + +TEST_F(DbusEventMoudleTest, Startup) { + EXPECT_CALL(GetMock(), pkgmgr_client_listen_status(_, _, _)) + .WillOnce(DoAll(InvokeArgument<1>(0, 0, "pkgtype", "pkgid", "start", + "install", "psms", module_.get()), Return(1))); + EXPECT_CALL(GetMock(), pkgmgr_client_new(_)) + .WillOnce(Return(pc_)); + EXPECT_CALL(GetMock(), g_bus_own_name(_, _, _, _, _, _, _, _)) + .WillOnce(Return(1)); + EXPECT_CALL(GetMock(), vconf_get_int(_, _)) + .WillRepeatedly(Return(VCONF_OK)); + EXPECT_CALL(GetMock(), vconf_get_bool(_, _)) + .WillRepeatedly(Return(VCONF_OK)); + EXPECT_CALL(GetMock(), vconf_notify_key_changed(_, _, _)) + .WillRepeatedly(DoAll( + InvokeArgument<1>(nullptr, nullptr), + InvokeArgument<1>(nullptr, nullptr), + InvokeArgument<1>(nullptr, nullptr), + InvokeArgument<1>(nullptr, nullptr), + InvokeArgument<1>(nullptr, nullptr), + InvokeArgument<1>(nullptr, nullptr), + InvokeArgument<1>(nullptr, nullptr), + InvokeArgument<1>(nullptr, nullptr), + InvokeArgument<1>(nullptr, nullptr), + InvokeArgument<1>(nullptr, nullptr), + InvokeArgument<1>(nullptr, nullptr), + InvokeArgument<1>(nullptr, nullptr), Return(1))); + + bool ret = module_->Startup(tools_.get()); + EXPECT_EQ(ret, true); + module_->SetVconfHandler(); +} + +TEST_F(DbusEventMoudleTest, HandleMethodCallCb) { + EXPECT_CALL(GetMock(), pkgmgr_client_listen_status(_, _, _)) + .WillOnce(DoAll(InvokeArgument<1>(0, 0, "pkgtype", "pkgid", "start", + "install", "psms", module_.get()), Return(1))); + EXPECT_CALL(GetMock(), pkgmgr_client_new(_)) + .WillOnce(Return(pc_)); + EXPECT_CALL(GetMock(), g_bus_own_name(_, _, _, _, _, _, _, _)) + .WillOnce(Return(1)); + bool ret = module_->Startup(tools_.get()); + ASSERT_EQ(ret, true); + + GDBusMessage* msg = g_dbus_message_new(); + GDBusMessage* reply = g_dbus_message_new(); + GVariant* body = g_variant_new("(u)", 5001); + EXPECT_CALL(GetMock(), g_dbus_message_new_method_call(_, _, _, _)) + .WillRepeatedly(Return(msg)); + EXPECT_CALL(GetMock(), g_dbus_connection_send_message_with_reply_sync( + _, _, _, _, _, _, _)).WillRepeatedly(Return(reply)); + EXPECT_CALL(GetMock(), g_dbus_message_get_body(_)) + .WillRepeatedly(Return(body)); + EXPECT_CALL(GetMock(), g_dbus_connection_emit_signal(_, _, _, _, _, + _, _)).WillOnce(Return(1)); + EXPECT_CALL(GetMock(), aul_app_get_appid_bypid_for_uid(_, _, _, _)) + .WillRepeatedly(Invoke([](int pid, char* appid, int size, uid_t uid) { + snprintf(appid, size, "%s", "org.tizen.helloworld"); + return AUL_R_OK; + })); + EXPECT_CALL(GetMock(), aul_app_get_appid_bypid(_, _, _)) + .WillRepeatedly(Invoke([](int pid, char* appid, int size) { + snprintf(appid, size, "%s", "org.tizen.helloworld"); + return AUL_R_OK; + })); + + GVariant* var = g_variant_new("(is)", 5001, SYS_EVENT_DISPLAY_STATE); + module_->HandleMethodCallCb(nullptr, nullptr, nullptr, nullptr, + "CheckSenderValidation", var, nullptr, module_.get()); + + GVariant* var2 = g_variant_new("(s)", SYS_EVENT_DISPLAY_STATE); + module_->HandleMethodCallCb(nullptr, nullptr, nullptr, nullptr, + "GetTrustedPeerList", var2, nullptr, module_.get()); + + GVariant* var3 = g_variant_new("(ss)", SYS_EVENT_DISPLAY_STATE, "dest"); + module_->HandleMethodCallCb(nullptr, nullptr, nullptr, nullptr, + "SetupTrustedPeer", var3, nullptr, module_.get()); + + GVariant* var5 = g_variant_new("(s)", SYS_EVENT_DISPLAY_STATE); + module_->HandleMethodCallCb(nullptr, nullptr, nullptr, nullptr, + "CheckUserSendValidation", var5, nullptr, module_.get()); + + module_->HandleMethodCallCb(nullptr, nullptr, nullptr, nullptr, + "CionGetUuid", nullptr, nullptr, module_.get()); + + GVariant* var10 = g_variant_new("(ss)", "service", "display"); + module_->HandleMethodCallCb(nullptr, nullptr, nullptr, nullptr, + "CionSetDisplayName", var10, nullptr, module_.get()); + + GVariant* var11 = g_variant_new("(s)", "service"); + module_->HandleMethodCallCb(nullptr, nullptr, nullptr, nullptr, + "CionGetDisplayName", var11, nullptr, module_.get()); + + GVariant* var12 = g_variant_new("(sb)", "service", true); + module_->HandleMethodCallCb(nullptr, nullptr, nullptr, nullptr, + "CionSetEnabled", var12, nullptr, module_.get()); + + GVariant* var13 = g_variant_new("(s)", "service"); + module_->HandleMethodCallCb(nullptr, nullptr, nullptr, nullptr, + "CionGetEnabled", var13, nullptr, module_.get()); + + GVariant* var4 = g_variant_new("(s)", SYS_EVENT_DISPLAY_STATE); + module_->HandleMethodCallCb(nullptr, nullptr, nullptr, nullptr, + "CheckPrivilegeValidation", var4, nullptr, module_.get()); + + GVariant* var6 = g_variant_new("(s)", SYS_EVENT_BOOT_COMPLETED); + module_->HandleMethodCallCb(nullptr, nullptr, nullptr, nullptr, + "GetEarlierData", var6, nullptr, module_.get()); + + GVariant* var7 = g_variant_new("(ss)", SYS_EVENT_DISPLAY_STATE, "own"); + module_->HandleMethodCallCb(nullptr, nullptr, nullptr, nullptr, + "KeepLastData", var7, nullptr, module_.get()); + + GVariant* var8 = g_variant_new("(ss)", SYS_EVENT_DISPLAY_STATE, "own"); + module_->HandleMethodCallCb(nullptr, nullptr, nullptr, nullptr, + "CheckLastData", var8, nullptr, module_.get()); + + tizen_base::Bundle b; + b.Add("key", "value"); + auto raw = b.ToRaw(); + GVariant* var9 = g_variant_new("(ssib)", SYS_EVENT_DISPLAY_STATE, + raw.first.get(), raw.second, true); + module_->HandleMethodCallCb(nullptr, nullptr, nullptr, nullptr, + "LaunchOnEventFromUserEvent", var9, nullptr, module_.get()); +} + +TEST_F(DbusEventMoudleTest, PkgmgrEventCb) { + EXPECT_CALL(GetMock(), g_bus_own_name(_, _, _, _, _, _, _, _)) + .WillOnce(Return(1)); + EXPECT_CALL(GetMock(), pkgmgr_client_listen_status(_, _, _)) + .WillOnce(DoAll( + InvokeArgument<1>(0, 0, "pkgtype", "pkgid", "start", + "install", "psms", module_.get()), + InvokeArgument<1>(0, 0, "pkgtype", "pkgid", "end", + "ok", "psms", module_.get()), Return(1))); + EXPECT_CALL(GetMock(), pkgmgr_client_new(_)) + .WillOnce(Return(pc_)); + EXPECT_CALL(GetMock(), pkgmgrinfo_pkginfo_get_usr_pkginfo(_, + _, _)).WillOnce(Return(0)); + EXPECT_CALL(GetMock(), pkgmgrinfo_pkginfo_destroy_pkginfo(_)) + .WillOnce(Return(0)); + uid_t uid = 5001; + EXPECT_CALL(GetMock(), pkgmgrinfo_appinfo_get_usr_list(_, _, + _, _, _)) + .WillOnce(DoAll(InvokeArgument<2>(nullptr, &uid), Return(1))); + EXPECT_CALL(GetMock(), pkgmgrinfo_appinfo_get_pkgid(_, _)) + .WillOnce(Invoke([](pkgmgrinfo_appinfo_h handle, char **pkgid) { + *pkgid = const_cast(pkgid_str.c_str()); + return 0; + })); + EXPECT_CALL(GetMock(), pkgmgrinfo_appinfo_get_appid(_, _)) + .WillOnce(Invoke([](pkgmgrinfo_appinfo_h handle, char **appid) { + *appid = const_cast(pkgid_str.c_str()); + return 0; + })); + + AppCtrlData cb_data("appid", "pkgid", 5001); + EXPECT_CALL(GetMock(), pkgmgrinfo_appinfo_foreach_appcontrol( + _, _, _)) + .WillOnce(DoAll(InvokeArgument<1>("operation", "uri", "mime", &cb_data), Return(1))); + + bool ret = module_->Startup(tools_.get()); + EXPECT_EQ(ret, true); +} \ No newline at end of file diff --git a/tests/dbus_event_unit_tests/src/test_earlier_item.cc b/tests/dbus_event_unit_tests/src/test_earlier_item.cc new file mode 100644 index 0000000..512f26a --- /dev/null +++ b/tests/dbus_event_unit_tests/src/test_earlier_item.cc @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2023 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 + +#include +#include + +#include "mock/test_fixture.h" +#include "mock/eventsystem_mock.h" +#include "mock/vconf_mock.h" +#include "dbus_event/earlier_item.hh" + +using ::testing::_; +using ::testing::Return; + +namespace { + +class Mocks : public ::testing::NiceMock, + public ::testing::NiceMock {}; + +} // namespace + +class EarlierItemTest : public TestFixture { + public: + EarlierItemTest() : TestFixture(std::make_unique()) {} + virtual ~EarlierItemTest() {} + + virtual void SetUp() { + tizen_base::Bundle b; + b.Add("key", "value"); + item_ = std::make_unique(b); + } + + virtual void TearDown() { + } + + std::unique_ptr item_; +}; + +TEST_F(EarlierItemTest, Register) { + EXPECT_CALL(GetMock(), eventsystem_register_event(_, _, _, _)) + .WillOnce(Return(ES_R_OK)); + bool ret = item_->Register(std::string_view("str")); + EXPECT_EQ(ret, true); +} + +TEST_F(EarlierItemTest, GetData) { + tizen_base::Bundle b = item_->GetData(); + EXPECT_STREQ(b.GetString("key").c_str(), "value"); +} + +TEST_F(EarlierItemTest, CreateMap) { + EXPECT_CALL(GetMock(), vconf_get_int(_, _)) + .WillRepeatedly(Return(VCONF_OK)); + std::map> items = + item_->CreateMap(); + EXPECT_EQ(items.size(), 5); +} \ No newline at end of file diff --git a/tests/dbus_event_unit_tests/src/test_event_launch.cc b/tests/dbus_event_unit_tests/src/test_event_launch.cc new file mode 100644 index 0000000..2dc0fc8 --- /dev/null +++ b/tests/dbus_event_unit_tests/src/test_event_launch.cc @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2023 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 + +#include +#include + +#include "mock/test_fixture.h" +#include "mock/aul_mock.h" +#include "mock/eventsystem_mock.h" +#include "dbus_event/event_launch.hh" + +using ::testing::_; +using ::testing::DoAll; +using ::testing::InvokeArgument; +using ::testing::Return; + +namespace { + +class Mocks : public ::testing::NiceMock, + public ::testing::NiceMock {}; + +} // namespace + +class EventLaunchTest : public TestFixture { + public: + EventLaunchTest() : TestFixture(std::make_unique()) {} + virtual ~EventLaunchTest() {} + + virtual void SetUp() { + event_launch_ = std::make_unique( + std::string("pkgid"), std::string("appid"), 5001); + } + + virtual void TearDown() { + } + + std::unique_ptr event_launch_; +}; + +TEST_F(EventLaunchTest, Register) { + EXPECT_CALL(GetMock(), eventsystem_register_event(_, _, _, _)) + .WillOnce(DoAll(InvokeArgument<2>("event_name", nullptr, + event_launch_.get()), Return(0))); + bool ret = event_launch_->Register(SYS_EVENT_OUTGOING_MSG); + EXPECT_EQ(ret, true); +} + +TEST_F(EventLaunchTest, GetUid) { + uid_t ret = event_launch_->GetUid(); + EXPECT_EQ(ret, 5001); +} + +TEST_F(EventLaunchTest, GetPackageName) { + std::string pkg_name = event_launch_->GetPackageName(); + EXPECT_STREQ(pkg_name.c_str(), "pkgid"); +} + +TEST_F(EventLaunchTest, GetAppListEventLaunch) { + std::list list = + event_launch_->GetAppListEventLaunch(); + EXPECT_NE(list.size(), 0); +} + +TEST_F(EventLaunchTest, Notify) { + EXPECT_CALL(GetMock(), aul_app_is_running_for_uid(_, _)) + .WillOnce(Return(0)); + EXPECT_CALL(GetMock(), aul_svc_run_service_async_for_uid(_, _, _, _, _)) + .WillOnce(Return(0)); + + tizen_base::Bundle b; + event_launch_->Notify(std::string_view(SYS_EVENT_BATTERY_CHARGER_STATUS), + b, false, false, 5001, std::string_view("sender")); + event_launch_->Notify(std::string_view(SYS_EVENT_USB_STATUS), + b, false, false, 5001, std::string_view("sender")); + event_launch_->Notify(std::string_view(SYS_EVENT_EARJACK_STATUS), + b, false, false, 5001, std::string_view("sender")); + event_launch_->Notify(std::string_view(SYS_EVENT_INCOMMING_MSG), + b, false, false, 5001, std::string_view("sender")); + event_launch_->Notify(std::string_view(SYS_EVENT_OUTGOING_MSG), + b, false, false, 5001, std::string_view("sender")); + event_launch_->Notify(std::string_view(SYS_EVENT_WIFI_STATE), + b, false, false, 5001, std::string_view("sender")); + event_launch_->Notify(std::string_view("User"), + b, false, true, 5001, std::string_view("sender")); +} \ No newline at end of file diff --git a/tests/dbus_event_unit_tests/src/test_privilege_checker.cc b/tests/dbus_event_unit_tests/src/test_privilege_checker.cc index c5c5ce9..5ce7689 100644 --- a/tests/dbus_event_unit_tests/src/test_privilege_checker.cc +++ b/tests/dbus_event_unit_tests/src/test_privilege_checker.cc @@ -19,9 +19,9 @@ #include #include -#include "cynara_mock.h" -#include "security_manager_mock.h" -#include "test_fixture.h" +#include "mock/cynara_mock.h" +#include "mock/security_manager_mock.h" +#include "mock/test_fixture.h" #include "dbus_event/privilege_checker.hh" diff --git a/tests/dbus_event_unit_tests/src/test_vconf_handler.cc b/tests/dbus_event_unit_tests/src/test_vconf_handler.cc index 7472c39..6d3c4be 100644 --- a/tests/dbus_event_unit_tests/src/test_vconf_handler.cc +++ b/tests/dbus_event_unit_tests/src/test_vconf_handler.cc @@ -20,17 +20,21 @@ #include #include -#include "test_fixture.h" -#include "eventsystem_mock.h" +#include "mock/test_fixture.h" +#include "mock/eventsystem_mock.h" +#include "mock/vconf_mock.h" #include "dbus_event/vconf_event_handler.hh" // using namespace tizen_base; using ::testing::_; +using ::testing::DoAll; +using ::testing::InvokeArgument; using ::testing::Return; namespace { -class Mocks : public ::testing::NiceMock {}; +class Mocks : public ::testing::NiceMock, + public ::testing::NiceMock {}; } // namespace diff --git a/tests/mock/aul_mock.cc b/tests/mock/aul_mock.cc index d4129dd..87a0cd8 100644 --- a/tests/mock/aul_mock.cc +++ b/tests/mock/aul_mock.cc @@ -18,10 +18,6 @@ #include "mock_hook.h" #include "test_fixture.h" -extern "C" int aul_app_get_appid_bypid(int pid, char* appid, int size) { - return MOCK_HOOK_P3(AulMock, aul_app_get_appid_bypid, pid, appid, size); -} - extern "C" int aul_svc_run_service_async_for_uid(bundle* arg0, int arg1, aul_svc_res_fn arg2, void* arg3, uid_t arg4) { return MOCK_HOOK_P5(AulMock, aul_svc_run_service_async_for_uid, arg0, arg1, @@ -32,3 +28,13 @@ extern "C" int aul_app_is_running_for_uid(const char* arg0, uid_t arg1) { return MOCK_HOOK_P2(AulMock, aul_app_is_running_for_uid, arg0, arg1); } +extern "C" int aul_app_get_appid_bypid_for_uid(int arg0, char* arg1, int arg2, + uid_t arg3) { + return MOCK_HOOK_P4(AulMock, aul_app_get_appid_bypid_for_uid, arg0, arg1, + arg2, arg3); +} + +extern "C" int aul_app_get_appid_bypid(int pid, char* appid, int size) { + return MOCK_HOOK_P3(AulMock, aul_app_get_appid_bypid, pid, appid, size); +} + diff --git a/tests/mock/aul_mock.h b/tests/mock/aul_mock.h index 9f15d18..63f6535 100644 --- a/tests/mock/aul_mock.h +++ b/tests/mock/aul_mock.h @@ -20,8 +20,9 @@ #include #include #include -#include #include +#include +#include #include #include "module_mock.h" @@ -30,10 +31,11 @@ class AulMock : public virtual ModuleMock { public: virtual ~AulMock() {} - MOCK_METHOD3(aul_app_get_appid_bypid, int (int, char*, int)); MOCK_METHOD5(aul_svc_run_service_async_for_uid, int(bundle*, int, aul_svc_res_fn, void*, uid_t)); MOCK_METHOD2(aul_app_is_running_for_uid, int(const char*, uid_t)); + MOCK_METHOD4(aul_app_get_appid_bypid_for_uid, int (int, char*, int, uid_t)); + MOCK_METHOD3(aul_app_get_appid_bypid, int (int, char*, int)); }; #endif // MOCK_AUL_MOCK_H_ \ No newline at end of file diff --git a/tests/mock/eventsystem_mock.cc b/tests/mock/eventsystem_mock.cc index d992e1a..149d558 100644 --- a/tests/mock/eventsystem_mock.cc +++ b/tests/mock/eventsystem_mock.cc @@ -22,3 +22,8 @@ extern "C" int eventsystem_send_system_event(const char* arg0, bundle* arg1) { return MOCK_HOOK_P2(EventSystemMock, eventsystem_send_system_event, arg0, arg1); } +extern "C" int eventsystem_register_event(const char* arg0, unsigned int* arg1, + eventsystem_handler arg2, void* arg3) { + return MOCK_HOOK_P4(EventSystemMock, eventsystem_register_event, arg0, arg1, + arg2, arg3); +} diff --git a/tests/mock/eventsystem_mock.h b/tests/mock/eventsystem_mock.h index e2a9fb9..d040ff4 100644 --- a/tests/mock/eventsystem_mock.h +++ b/tests/mock/eventsystem_mock.h @@ -28,7 +28,8 @@ class EventSystemMock : public virtual ModuleMock { virtual ~EventSystemMock() {} MOCK_METHOD2(eventsystem_send_system_event, int(const char*, bundle*)); - + MOCK_METHOD4(eventsystem_register_event, int(const char*, unsigned int*, + eventsystem_handler, void*)); }; #endif // MOCK_EVENTSYSTEM_MOCK_H_ \ No newline at end of file diff --git a/tests/mock/gio_mock.cc b/tests/mock/gio_mock.cc index 34c4086..b461fd2 100644 --- a/tests/mock/gio_mock.cc +++ b/tests/mock/gio_mock.cc @@ -20,12 +20,12 @@ #include "mock_hook.h" #include "test_fixture.h" -extern "C" GDBusMessage* g_dbus_connection_send_message_with_reply_sync( - GDBusConnection* conn, GDBusMessage* msg, GDBusSendMessageFlags flags, - gint timeout, volatile guint32* out_serial, GCancellable* cancellable, - GError** error) { - return MOCK_HOOK_P7(GioMock, g_dbus_connection_send_message_with_reply_sync, - conn, msg, flags, timeout, out_serial, cancellable, error); +extern "C" guint g_dbus_connection_register_object(GDBusConnection* arg0, + const gchar* arg1, GDBusInterfaceInfo* arg2, + const GDBusInterfaceVTable* arg3, gpointer arg4, + GDestroyNotify arg5, GError** arg6) { + return MOCK_HOOK_P7(GioMock, g_dbus_connection_register_object, + arg0, arg1, arg2, arg3, arg4, arg5, arg6); } extern "C" guint g_dbus_connection_signal_subscribe(GDBusConnection* arg0, @@ -36,10 +36,24 @@ extern "C" guint g_dbus_connection_signal_subscribe(GDBusConnection* arg0, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); } -extern "C" GDBusMessage* g_dbus_message_new_method_call(const gchar* arg0, - const gchar* arg1, const gchar* arg2, const gchar* arg3) { - return MOCK_HOOK_P4(GioMock, g_dbus_message_new_method_call, arg0, arg1, arg2, - arg3); +extern "C" guint g_bus_own_name(GBusType arg0, const gchar* arg1, + GBusNameOwnerFlags arg2, GBusAcquiredCallback arg3, + GBusNameAcquiredCallback arg4, GBusNameLostCallback arg5, gpointer arg6, + GDestroyNotify arg7) { + return MOCK_HOOK_P8(GioMock, g_bus_own_name, arg0, arg1, arg2, arg3, arg4, + arg5, arg6, arg7); +} + +extern "C" GDBusMessage* g_dbus_connection_send_message_with_reply_sync( + GDBusConnection* conn, GDBusMessage* msg, GDBusSendMessageFlags flags, + gint timeout, volatile guint32* out_serial, GCancellable* cancellable, + GError** error) { + return MOCK_HOOK_P7(GioMock, g_dbus_connection_send_message_with_reply_sync, + conn, msg, flags, timeout, out_serial, cancellable, error); +} + +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* arg1, @@ -49,11 +63,27 @@ extern "C" gboolean g_dbus_connection_emit_signal(GDBusConnection* arg1, arg3, arg4, arg5, arg6, arg7); } +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); +} + +extern "C" void g_dbus_method_invocation_return_value( + GDBusMethodInvocation* arg0, GVariant* arg1) { + MOCK_HOOK_P2(GioMock, g_dbus_method_invocation_return_value, arg0, arg1); +} + extern "C" void g_dbus_message_set_body(GDBusMessage* arg0, GVariant* arg1) { return MOCK_HOOK_P2(GioMock, g_dbus_message_set_body, arg0, arg1); } -extern "C" GVariant* g_dbus_message_get_body(GDBusMessage* arg0) { - return MOCK_HOOK_P1(GioMock, g_dbus_message_get_body, arg0); +extern "C" void g_object_unref(gpointer arg0) { + return MOCK_HOOK_P1(GioMock, g_object_unref, arg0); +} + +extern "C" GDBusMessage* g_dbus_message_new_method_call(const gchar* arg0, + const gchar* arg1, const gchar* arg2, const gchar* arg3) { + return MOCK_HOOK_P4(GioMock, g_dbus_message_new_method_call, arg0, arg1, arg2, + arg3); } diff --git a/tests/mock/gio_mock.h b/tests/mock/gio_mock.h index 0239667..cf28e11 100644 --- a/tests/mock/gio_mock.h +++ b/tests/mock/gio_mock.h @@ -26,25 +26,42 @@ class GioMock : public virtual ModuleMock { public: virtual ~GioMock() {} - MOCK_METHOD7(g_dbus_connection_send_message_with_reply_sync, - GDBusMessage*(GDBusConnection*, GDBusMessage*, GDBusSendMessageFlags, - gint, volatile guint32*, GCancellable*, 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_METHOD4(g_dbus_message_new_method_call, - GDBusMessage*(const gchar*, const gchar*, const gchar*, const gchar*)); + MOCK_METHOD8(g_bus_own_name, + guint(GBusType, const gchar*, + GBusNameOwnerFlags, GBusAcquiredCallback, GBusNameAcquiredCallback, + GBusNameLostCallback, gpointer, GDestroyNotify)); + + MOCK_METHOD7(g_dbus_connection_send_message_with_reply_sync, + GDBusMessage*(GDBusConnection*, GDBusMessage*, GDBusSendMessageFlags, + gint, volatile guint32*, GCancellable*, GError**)); + + MOCK_METHOD1(g_dbus_message_get_body, GVariant*(GDBusMessage*)); MOCK_METHOD7(g_dbus_connection_emit_signal, gboolean (GDBusConnection*, const gchar*, const gchar*, const gchar*, const gchar*, GVariant*, GError**)); + MOCK_METHOD2(g_dbus_node_info_new_for_xml, GDBusNodeInfo* (const gchar*, + GError**)); + + MOCK_METHOD2(g_dbus_method_invocation_return_value, + void (GDBusMethodInvocation*, GVariant*)); + MOCK_METHOD2(g_dbus_message_set_body, void(GDBusMessage*, GVariant*)); - MOCK_METHOD1(g_dbus_message_get_body, GVariant*(GDBusMessage*)); + MOCK_METHOD1(g_object_unref, void(gpointer)); + + MOCK_METHOD4(g_dbus_message_new_method_call, + GDBusMessage*(const gchar*, const gchar*, const gchar*, const gchar*)); }; diff --git a/tests/mock/pkgmgr_info_mock.cc b/tests/mock/pkgmgr_info_mock.cc index 969f45e..363703a 100644 --- a/tests/mock/pkgmgr_info_mock.cc +++ b/tests/mock/pkgmgr_info_mock.cc @@ -18,37 +18,77 @@ #include "mock_hook.h" #include "test_fixture.h" -extern "C" int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char* arg1, uid_t arg2, - pkgmgrinfo_pkginfo_h* arg3) { - return MOCK_HOOK_P3(PkgmgrInfoMock, pkgmgrinfo_pkginfo_get_usr_pkginfo, arg1, - arg2, arg3); +extern "C" int pkgmgr_client_free(pkgmgr_client* arg0) { + return MOCK_HOOK_P1(PkgmgrInfoMock, pkgmgr_client_free, arg0); } -extern "C" int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_pkginfo_h arg1, - char** arg2) { - return MOCK_HOOK_P2(PkgmgrInfoMock, pkgmgrinfo_appinfo_get_pkgid, arg1, - arg2); +extern "C" int pkgmgrinfo_appinfo_get_appid( + pkgmgrinfo_appinfo_h arg0, char** arg1) { + return MOCK_HOOK_P2(PkgmgrInfoMock, pkgmgrinfo_appinfo_get_appid, + arg0, arg1); } -extern "C" int pkgmgrinfo_appinfo_destroy_appinfo( - pkgmgrinfo_appinfo_h arg0) { - return MOCK_HOOK_P1(PkgmgrInfoMock, pkgmgrinfo_appinfo_destroy_appinfo, +extern "C" int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h arg0) { + return MOCK_HOOK_P1(PkgmgrInfoMock, pkgmgrinfo_pkginfo_destroy_pkginfo, arg0); } -extern "C" int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h arg1) { - return MOCK_HOOK_P1(PkgmgrInfoMock, pkgmgrinfo_pkginfo_destroy_pkginfo, - arg1); +extern "C" int pkgmgrinfo_pkginfo_compare_usr_app_cert_info(const char* arg0, + const char* arg1, uid_t arg2, pkgmgrinfo_cert_compare_result_type_e* arg3) { + return MOCK_HOOK_P4(PkgmgrInfoMock, pkgmgrinfo_pkginfo_compare_usr_app_cert_info, + arg0, arg1, arg2, arg3); } -extern "C" int pkgmgrinfo_appinfo_get_usr_appinfo(const char* arg1, uid_t arg2, - pkgmgrinfo_appinfo_h* arg3) { - return MOCK_HOOK_P3(PkgmgrInfoMock, pkgmgrinfo_appinfo_get_usr_appinfo, arg1, - arg2, arg3); +extern "C" int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h arg0, + pkgmgrinfo_app_control_list_cb arg1, void* arg2) { + return MOCK_HOOK_P3(PkgmgrInfoMock, pkgmgrinfo_appinfo_foreach_appcontrol, + arg0, arg1, arg2); } -extern "C" int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, - char** version) { +extern "C" int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h arg0, + char **arg1) { return MOCK_HOOK_P2(PkgmgrInfoMock, pkgmgrinfo_pkginfo_get_version, - handle, version); + arg0, arg1); +} + +extern "C" int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h arg0, + pkgmgrinfo_app_component arg1, pkgmgrinfo_app_list_cb arg2, void* arg3, + uid_t arg4) { + return MOCK_HOOK_P5(PkgmgrInfoMock, pkgmgrinfo_appinfo_get_usr_list, arg0, + arg1, arg2, arg3, arg4); +} + +extern "C" int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char* arg0, uid_t arg1, + pkgmgrinfo_pkginfo_h* arg2) { + return MOCK_HOOK_P3(PkgmgrInfoMock, pkgmgrinfo_pkginfo_get_usr_pkginfo, arg0, + arg1, arg2); +} + +extern "C" pkgmgr_client* pkgmgr_client_new(pkgmgr_client_type arg0) { + return MOCK_HOOK_P1(PkgmgrInfoMock, pkgmgr_client_new, arg0); +} + +extern "C" int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_pkginfo_h arg0, + char** arg1) { + return MOCK_HOOK_P2(PkgmgrInfoMock, pkgmgrinfo_appinfo_get_pkgid, arg0, + arg1); +} + +extern "C" int pkgmgr_client_listen_status(pkgmgr_client* arg0, + pkgmgr_handler arg1, void* arg2) { + return MOCK_HOOK_P3(PkgmgrInfoMock, pkgmgr_client_listen_status, arg0, arg1, + arg2); +} + +extern "C" int pkgmgrinfo_appinfo_destroy_appinfo( + pkgmgrinfo_appinfo_h arg0) { + return MOCK_HOOK_P1(PkgmgrInfoMock, pkgmgrinfo_appinfo_destroy_appinfo, + arg0); } + +extern "C" int pkgmgrinfo_appinfo_get_usr_appinfo(const char* arg0, uid_t arg1, + pkgmgrinfo_appinfo_h* arg2) { + return MOCK_HOOK_P3(PkgmgrInfoMock, pkgmgrinfo_appinfo_get_usr_appinfo, arg0, + arg1, arg2); +} + diff --git a/tests/mock/pkgmgr_info_mock.h b/tests/mock/pkgmgr_info_mock.h index 24a9ab1..3d703a1 100644 --- a/tests/mock/pkgmgr_info_mock.h +++ b/tests/mock/pkgmgr_info_mock.h @@ -18,6 +18,7 @@ #define MOCK_PKGMGR_INFO_MOCK_H_ #include +#include #include #include "module_mock.h" @@ -26,18 +27,30 @@ class PkgmgrInfoMock : public virtual ModuleMock { public: virtual ~PkgmgrInfoMock() {} + MOCK_METHOD1(pkgmgr_client_free, int (pkgmgr_client*)); + MOCK_METHOD2(pkgmgrinfo_appinfo_get_appid, int (pkgmgrinfo_appinfo_h, + char**)); + MOCK_METHOD1(pkgmgrinfo_pkginfo_destroy_pkginfo, + int (pkgmgrinfo_pkginfo_h)); + MOCK_METHOD4(pkgmgrinfo_pkginfo_compare_usr_app_cert_info, int (const char*, + const char*, uid_t, pkgmgrinfo_cert_compare_result_type_e*)); + MOCK_METHOD3(pkgmgrinfo_appinfo_foreach_appcontrol, int ( + pkgmgrinfo_appinfo_h , pkgmgrinfo_app_control_list_cb, void*)); + MOCK_METHOD2(pkgmgrinfo_pkginfo_get_version, int (pkgmgrinfo_pkginfo_h, + char**)); + MOCK_METHOD5(pkgmgrinfo_appinfo_get_usr_list, int (pkgmgrinfo_pkginfo_h, + pkgmgrinfo_app_component, pkgmgrinfo_app_list_cb, void*, uid_t)); MOCK_METHOD3(pkgmgrinfo_pkginfo_get_usr_pkginfo, int (const char *, uid_t, pkgmgrinfo_pkginfo_h*)); + MOCK_METHOD1(pkgmgr_client_new, pkgmgr_client* (pkgmgr_client_type)); MOCK_METHOD2(pkgmgrinfo_appinfo_get_pkgid, int (pkgmgrinfo_pkginfo_h, char **)); + MOCK_METHOD3(pkgmgr_client_listen_status, int (pkgmgr_client*, + pkgmgr_handler, void*)); MOCK_METHOD1(pkgmgrinfo_appinfo_destroy_appinfo, int (pkgmgrinfo_appinfo_h)); - MOCK_METHOD1(pkgmgrinfo_pkginfo_destroy_pkginfo, - int (pkgmgrinfo_pkginfo_h)); MOCK_METHOD3(pkgmgrinfo_appinfo_get_usr_appinfo, int (const char *, uid_t, pkgmgrinfo_appinfo_h*)); - MOCK_METHOD2(pkgmgrinfo_pkginfo_get_version, - int (pkgmgrinfo_pkginfo_h, char**)); }; #endif // MOCK_PKMGR_INFO_MOCK_H_ \ No newline at end of file diff --git a/tests/mock/tzplatform_config_mock.h b/tests/mock/tzplatform_config_mock.h index a251057..8696222 100644 --- a/tests/mock/tzplatform_config_mock.h +++ b/tests/mock/tzplatform_config_mock.h @@ -24,11 +24,7 @@ class TzplatformConfigMock : public virtual ModuleMock { public: - TzplatformConfigMock() { - using ::testing::_; - using ::testing::Return; - using ::testing::Invoke; - } + virtual ~TzplatformConfigMock() {} MOCK_METHOD2(tzplatform_mkpath, const char* (enum tzplatform_variable, const char*)); diff --git a/tests/mock/vconf_mock.cc b/tests/mock/vconf_mock.cc new file mode 100644 index 0000000..90cb11b --- /dev/null +++ b/tests/mock/vconf_mock.cc @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 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 "vconf_mock.h" +#include "mock_hook.h" +#include "test_fixture.h" + +extern "C" int vconf_get_int(const char* arg0, int* arg1) { + return MOCK_HOOK_P2(VconfMock, vconf_get_int, arg0, arg1); +} + +extern "C" int vconf_get_bool(const char* arg0, int* arg1) { + return MOCK_HOOK_P2(VconfMock, vconf_get_bool, arg0, arg1); +} + +extern "C" int vconf_notify_key_changed(const char* arg0, + vconf_callback_fn arg1, void* arg2) { + return MOCK_HOOK_P3(VconfMock, vconf_notify_key_changed, arg0, arg1, arg2); +} + diff --git a/tests/mock/vconf_mock.h b/tests/mock/vconf_mock.h new file mode 100644 index 0000000..bea8279 --- /dev/null +++ b/tests/mock/vconf_mock.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 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 MOCK_VCONF_MOCK_H_ +#define MOCK_VCONF_MOCK_H_ + +#include +#include + +#include "module_mock.h" + +class VconfMock : public virtual ModuleMock { + public: + virtual ~VconfMock() {} + + MOCK_METHOD2(vconf_get_int, int (const char*, int*)); + MOCK_METHOD2(vconf_get_bool, int (const char*, int*)); + MOCK_METHOD3(vconf_notify_key_changed, int (const char*, + vconf_callback_fn, void*)); +}; + +#endif // MOCK_VCONF_MOCK_H_ \ No newline at end of file -- 2.7.4