From 166e0a1c3d5e97f9e03025631cfb6269c59af202 Mon Sep 17 00:00:00 2001 From: "jh9216.park" Date: Tue, 13 Dec 2022 05:42:24 -0500 Subject: [PATCH] Add unit tests for cion module - add unittests - fix bugs - Requires : https://review.tizen.org/gerrit/#/c/platform/core/base/bundle/+/285480/ Change-Id: I3c1c44254533661ee9922e43486d8e6c43b7aa35 Signed-off-by: jh9216.park --- CMakeLists.txt | 12 +- packaging/esd.spec | 5 +- src/lib/method_broker.hh | 4 + src/modules/cion/cion_module.cc | 30 +++-- src/modules/cion/cion_module.hh | 10 +- src/modules/dbus_event/CMakeLists.txt | 1 + tests/CMakeLists.txt | 3 +- tests/cion_unit_tests/CMakeLists.txt | 41 ++++++ tests/{unit_tests => cion_unit_tests}/src/main.cc | 0 tests/cion_unit_tests/src/test_cion_module.cc | 141 +++++++++++++++++++++ tests/dbus_event_unit_tests/CMakeLists.txt | 39 ++++++ tests/dbus_event_unit_tests/src/main.cc | 37 ++++++ .../src/test_privilege_checker.cc | 2 +- .../src/test_vconf_handler.cc | 2 +- tests/mock/cion_mock.cc | 83 ++++++++++++ tests/mock/pkgmgr_info_mock.cc | 5 + tests/mock/pkgmgr_info_mock.h | 2 + tests/mock/tzplatform_config_mock.cc | 24 ++++ tests/mock/tzplatform_config_mock.h | 37 ++++++ tests/unit_tests/CMakeLists.txt | 62 --------- 20 files changed, 456 insertions(+), 84 deletions(-) create mode 100644 tests/cion_unit_tests/CMakeLists.txt rename tests/{unit_tests => cion_unit_tests}/src/main.cc (100%) create mode 100644 tests/cion_unit_tests/src/test_cion_module.cc create mode 100644 tests/dbus_event_unit_tests/CMakeLists.txt create mode 100644 tests/dbus_event_unit_tests/src/main.cc rename tests/{unit_tests => dbus_event_unit_tests}/src/test_privilege_checker.cc (98%) rename tests/{unit_tests => dbus_event_unit_tests}/src/test_vconf_handler.cc (97%) create mode 100644 tests/mock/cion_mock.cc create mode 100644 tests/mock/tzplatform_config_mock.cc create mode 100644 tests/mock/tzplatform_config_mock.h delete mode 100644 tests/unit_tests/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index f566092..e13f6ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,8 @@ SET(TARGET_LIB_ESD "libesd") ## Target modules SET(TARGET_ESD_MOD_CION "esd-mod-cion") SET(TARGET_ESD_MOD_DBUS_EVENT "esd-mod-dbus-event") +SET(TARGET_ESD_MOD_CION_UNITTESTS "esd-mod-cion-unittests") +SET(TARGET_ESD_MOD_DBUS_EVENT_UNITTESTS "esd-mod-dbus-event-unittests") #ENABLE_TESTING() #SET(TARGET_ESD_UNIT_TESTS "esd-unit-tests") @@ -52,14 +54,18 @@ PKG_CHECK_MODULES(VCONF_DEPS REQUIRED vconf) PKG_CHECK_MODULES(PKGMGR_DEPS REQUIRED pkgmgr) PKG_CHECK_MODULES(EVENTSYSTEM_DEPS REQUIRED eventsystem) PKG_CHECK_MODULES(DATABASE_DEPS REQUIRED tizen-database) +PKG_CHECK_MODULES(GMOCK_DEPS REQUIRED gmock) +PKG_CHECK_MODULES(APPSVC_DEPS REQUIRED appsvc) ADD_SUBDIRECTORY(src) IF(NOT DEFINED MINIMUM_BUILD) ADD_SUBDIRECTORY(tests) ENABLE_TESTING() -SET(UNIT_TESTS ${PROJECT_NAME}-unittests) -ADD_TEST(NAME ${UNIT_TESTS} COMMAND ${UNIT_TESTS}) -ADD_DEPENDENCIES(${UNIT_TESTS} ${PROJECT_NAME}) +ADD_TEST(NAME ${TARGET_ESD_MOD_CION_UNITTESTS} COMMAND ${TARGET_ESD_MOD_CION_UNITTESTS}) +ADD_DEPENDENCIES(${TARGET_ESD_MOD_CION_UNITTESTS} ${PROJECT_NAME}) + +ADD_TEST(NAME ${TARGET_ESD_MOD_DBUS_EVENT_UNITTESTS} COMMAND ${TARGET_ESD_MOD_DBUS_EVENT_UNITTESTS}) +ADD_DEPENDENCIES(${TARGET_ESD_MOD_DBUS_EVENT_UNITTESTS} ${PROJECT_NAME}) ENDIF(NOT DEFINED MINIMUM_BUILD) diff --git a/packaging/esd.spec b/packaging/esd.spec index e8d92e7..660ba30 100644 --- a/packaging/esd.spec +++ b/packaging/esd.spec @@ -106,7 +106,8 @@ setup() { test_main() { echo "test_main start" - /usr/bin/%{name}-unittests + /usr/bin/esd-mod-cion-unittests + /usr/bin/esd-mod-dbus_event-unittests } teardown() { @@ -163,5 +164,5 @@ ln -sf ../esd.service %{buildroot}%{_unitdir}/multi-user.target.wants/esd.servic # unittests ################################################# %files -n %{name}-unittests -%{_bindir}/%{name}-unittests +%{_bindir}/esd-*-unittests %{_bindir}/tizen-unittests/%{name}/run-unittest.sh diff --git a/src/lib/method_broker.hh b/src/lib/method_broker.hh index 00d1d35..bc667e7 100644 --- a/src/lib/method_broker.hh +++ b/src/lib/method_broker.hh @@ -54,6 +54,10 @@ class MethodBroker { std::shared_ptr>(name, std::make_shared(cmd))); } + void Unregister(std::string name) { + fmap_.erase(std::move(name)); + } + template bool Invoke(std::string name, ArgTypes... args) { using ParamsType = Params; diff --git a/src/modules/cion/cion_module.cc b/src/modules/cion/cion_module.cc index 758ea7f..691aa7d 100644 --- a/src/modules/cion/cion_module.cc +++ b/src/modules/cion/cion_module.cc @@ -81,6 +81,7 @@ bool IsEnabledForeignKeys(const tizen_base::Database& db) { } // namespace bool CionModule::Startup(api::ToolBox* tools) { + tools_ = tools; tools->GetMethodBroker().Register("Cion.GetUuidWithGenerate", api::Params&>( [this](const std::string& appid, std::optional& uuid) { @@ -116,7 +117,14 @@ bool CionModule::Startup(api::ToolBox* tools) { } void CionModule::Shutdown() { - + if (!tools_) + return; + tools_->GetMethodBroker().Unregister("Cion.GetUuidWithGenerate"); + tools_->GetMethodBroker().Unregister("Cion.SetDisplayName"); + tools_->GetMethodBroker().Unregister("Cion.GetDisplayName"); + tools_->GetMethodBroker().Unregister("Cion.SetEnabled"); + tools_->GetMethodBroker().Unregister("Cion.GetEnabled"); + tools_ = nullptr; } bool CionModule::Init() { @@ -256,7 +264,7 @@ void CionModule::GetUuidWithGenerate(const std::string& appid, try { tizen_base::Database db(DBPATH, SQLITE_OPEN_READWRITE); std::string uuid_str; - int ret = 0; + bool ret = true; if (!GetUuidFromDb(db, appid, uuid_str)) { uuid_str = GenUuid(); @@ -264,8 +272,10 @@ void CionModule::GetUuidWithGenerate(const std::string& appid, _E("get uuid generate"); } - if (ret == 0) + if (ret) uuid = std::move(uuid_str); + else + uuid = std::nullopt; } catch(const std::runtime_error&) { uuid = std::nullopt; } @@ -278,12 +288,14 @@ void CionModule::SetDisplayName(const std::string& appid, tizen_base::Database db(DBPATH, SQLITE_OPEN_READWRITE); std::string uuid; - ret = 0; + bool result; + ret = -1; if (!GetUuidFromDb(db, appid, uuid)) { uuid = GenUuid(); - ret = SetUuidToDb(db, appid, uuid); - if (ret != 0) + result = SetUuidToDb(db, appid, uuid); + if (!result) { return; + } } auto q = tizen_base::Database::Sql( @@ -298,8 +310,8 @@ void CionModule::SetDisplayName(const std::string& appid, .Bind(service_name) .Bind(appid); auto r = db.Exec(q); - if (!static_cast(r)) - ret = -1; + if (static_cast(r)) + ret = 0; } catch(const std::runtime_error&) { ret = -1; } @@ -350,7 +362,7 @@ void CionModule::SetEnabled(const std::string& appid, auto q2 = tizen_base::Database::Sql( "SELECT display_name FROM cion_display_name " - "WHERE appid = %Q AND service_name = %Q") + "WHERE appid = ? AND service_name = ?") .Bind(appid) .Bind(service_name); diff --git a/src/modules/cion/cion_module.hh b/src/modules/cion/cion_module.hh index 8c2f23a..067406b 100644 --- a/src/modules/cion/cion_module.hh +++ b/src/modules/cion/cion_module.hh @@ -36,11 +36,6 @@ class CionModule : public api::IModule { bool Startup(api::ToolBox* tools) override; void Shutdown() override; - - void AddEnabledApp(const std::string& service_name, - const std::string& app_id, const std::string& display_name); - void RemoveEnabledApp(const std::string& service_name, - const std::string& app_id); std::optional> GetEnabledServiceList(); void GetUuidWithGenerate(const std::string& appid, std::optional& uuid); @@ -48,6 +43,10 @@ class CionModule : public api::IModule { private: bool Init(); bool DbInit(); + void AddEnabledApp(const std::string& service_name, + const std::string& app_id, const std::string& display_name); + void RemoveEnabledApp(const std::string& service_name, + const std::string& app_id); void ChangeListenStatusCionServer(); void SetDisplayName(const std::string& appid, const std::string& service_name, @@ -68,6 +67,7 @@ class CionModule : public api::IModule { private: std::shared_ptr esd_cion_server_; bool is_listening_ = false; + api::ToolBox* tools_ = nullptr; }; } // namespace esd::module diff --git a/src/modules/dbus_event/CMakeLists.txt b/src/modules/dbus_event/CMakeLists.txt index 869df0b..88fd52a 100644 --- a/src/modules/dbus_event/CMakeLists.txt +++ b/src/modules/dbus_event/CMakeLists.txt @@ -23,6 +23,7 @@ APPLY_PKG_CONFIG(${TARGET_ESD_MOD_DBUS_EVENT} PUBLIC CAPI_SYSTEM_INFO_DEPS PKGMGR_DEPS EVENTSYSTEM_DEPS + APPSVC_DEPS ) INSTALL(TARGETS ${TARGET_ESD_MOD_DBUS_EVENT} DESTINATION ${ESD_MODULES_DIR}/mod diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c90fac8..9bfec7e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1 +1,2 @@ -ADD_SUBDIRECTORY(unit_tests) +ADD_SUBDIRECTORY(cion_unit_tests) +ADD_SUBDIRECTORY(dbus_event_unit_tests) diff --git a/tests/cion_unit_tests/CMakeLists.txt b/tests/cion_unit_tests/CMakeLists.txt new file mode 100644 index 0000000..520dd1e --- /dev/null +++ b/tests/cion_unit_tests/CMakeLists.txt @@ -0,0 +1,41 @@ +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/modules/cion/ ESD_MOD_CION_SRCS) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/lib/ ESD_LIB_SRCS) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/ ESD_MOD_CION_TEST_SRCS) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../mock/ ESD_MOD_CION_MOCK_SRCS) +ADD_EXECUTABLE(${TARGET_ESD_MOD_CION_UNITTESTS} + ${ESD_MOD_CION_SRCS} + ${ESD_LIB_SRCS} + ${ESD_MOD_CION_TEST_SRCS} + ${ESD_MOD_CION_MOCK_SRCS} +) + +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) + +TARGET_LINK_LIBRARIES(${TARGET_ESD_MOD_CION_UNITTESTS} PRIVATE ${TARGET_LIB_ESD}) + +APPLY_PKG_CONFIG(${TARGET_ESD_MOD_CION_UNITTESTS} PUBLIC + AUL_DEPS + BUNDLE_DEPS + PARCEL_DEPS + PKGMGR_INFO_DEPS + DLOG_DEPS + GIO_DEPS + GLIB_DEPS + CION_DEPS + VCONF_DEPS + CAPI_SYSTEM_INFO_DEPS + LIBTZPLATFORM_CONFIG_DEPS + UUID_DEPS + SQLITE3_DEPS + DATABASE_DEPS + SECURITY_MANAGER_DEPS + CYNARA_CLIENT_DEPS + CYNARA_CREDS_DBUS_DEPS + CYNARA_SESSION_DEPS + GMOCK_DEPS +) + +INSTALL(TARGETS ${TARGET_ESD_MOD_CION_UNITTESTS} DESTINATION bin) diff --git a/tests/unit_tests/src/main.cc b/tests/cion_unit_tests/src/main.cc similarity index 100% rename from tests/unit_tests/src/main.cc rename to tests/cion_unit_tests/src/main.cc diff --git a/tests/cion_unit_tests/src/test_cion_module.cc b/tests/cion_unit_tests/src/test_cion_module.cc new file mode 100644 index 0000000..68e1bfb --- /dev/null +++ b/tests/cion_unit_tests/src/test_cion_module.cc @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2022 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 "cion/cion_module.hh" +#include "pkgmgr_info_mock.h" +#include "tzplatform_config_mock.h" +#include "test_fixture.h" + +using ::testing::_; +using ::testing::DoAll; +using ::testing::Invoke; +using ::testing::Return; +using ::testing::SetArgPointee; + +namespace { + +class Mocks : public ::testing::NiceMock, + public ::testing::NiceMock {}; + +const char *__fake_tzplatform_mkpath(enum tzplatform_variable id, const char *path) { + return ".cion_test.db"; +} + +} //namespace + +class CionModuleTest : public TestFixture { + public: + CionModuleTest() : TestFixture(std::make_unique()) {} + virtual ~CionModuleTest() {} + + virtual void SetUp() { + remove(".cion_test.db"); + tools_ = std::make_unique(); + mod_ = std::make_unique(); + EXPECT_CALL(GetMock(), tzplatform_mkpath(_, _)) + .WillRepeatedly(Invoke(__fake_tzplatform_mkpath)); + mod_->Startup(tools_.get()); + } + + virtual void TearDown() { + mod_->Shutdown(); + mod_.reset(); + tools_.reset(); + } + + std::unique_ptr mod_; + std::unique_ptr tools_; +}; + +TEST_F(CionModuleTest, GetUuidWithGenerate) { + EXPECT_CALL(GetMock(), tzplatform_mkpath(_, _)) + .WillRepeatedly(Invoke(__fake_tzplatform_mkpath)); + + std::string app_id = "org.tizen.test"; + std::optional uuid; + bool ret = tools_->GetMethodBroker() + .Invoke&>( + "Cion.GetUuidWithGenerate", app_id, uuid); + EXPECT_TRUE(ret); + EXPECT_TRUE(uuid); +} + +TEST_F(CionModuleTest, SetDisplayNameGetDisplayName) { + EXPECT_CALL(GetMock(), tzplatform_mkpath(_, _)) + .WillRepeatedly(Invoke(__fake_tzplatform_mkpath)); + + std::string app_id = "org.tizen.test"; + std::string service_name = "test_service"; + std::string display_name = "TEST_SERVICE"; + int ret = -1; + bool r = tools_->GetMethodBroker() + .Invoke( + "Cion.SetDisplayName", app_id, service_name, display_name, ret); + EXPECT_TRUE(r); + EXPECT_EQ(ret, 0); + + ret = -1; + std::string result_display_name; + r = tools_->GetMethodBroker() + .Invoke( + "Cion.GetDisplayName", app_id, service_name, result_display_name, + ret); + EXPECT_TRUE(r); + EXPECT_EQ(ret, 0); + EXPECT_EQ(display_name, result_display_name); +} + +TEST_F(CionModuleTest, SetEnabledGetEnabled) { + EXPECT_CALL(GetMock(), tzplatform_mkpath(_, _)) + .WillRepeatedly(Invoke(__fake_tzplatform_mkpath)); + EXPECT_CALL(GetMock(), pkgmgrinfo_pkginfo_get_version(_, _)) + .WillRepeatedly(Invoke([](pkgmgrinfo_pkginfo_h handle, char** version) { + *version = const_cast("1.0.0"); + return PMINFO_R_OK; + })); + + std::string app_id = "org.tizen.test"; + std::string service_name = "test_service"; + std::string display_name = "TEST_SERVICE"; + int ret = -1; + bool r = tools_->GetMethodBroker() + .Invoke( + "Cion.SetDisplayName", app_id, service_name, display_name, ret); + ASSERT_EQ(ret, 0); + + bool enabled = true; + ret = -1; + r = tools_->GetMethodBroker() + .Invoke( + "Cion.SetEnabled", app_id, service_name, enabled, ret); + EXPECT_TRUE(r); + EXPECT_EQ(ret, 0); + + ret = -1; + std::string result_display_name; + bool result_enabled = false; + r = tools_->GetMethodBroker() + .Invoke( + "Cion.GetEnabled", app_id, service_name, result_enabled, ret); + EXPECT_TRUE(r); + EXPECT_EQ(ret, 0); + EXPECT_EQ(enabled, result_enabled); +} diff --git a/tests/dbus_event_unit_tests/CMakeLists.txt b/tests/dbus_event_unit_tests/CMakeLists.txt new file mode 100644 index 0000000..be32285 --- /dev/null +++ b/tests/dbus_event_unit_tests/CMakeLists.txt @@ -0,0 +1,39 @@ +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/modules/dbus_event/ ESD_MOD_DBUS_EVENT_SRC) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/lib/ ESD_LIB_SRCS) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/ ESD_MOD_DBUS_EVENT_TEST_SRCS) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../mock/ ESD_MOD_DBUS_EVENT_MOCK_SRCS) +ADD_EXECUTABLE(${TARGET_ESD_MOD_DBUS_EVENT_UNITTESTS} + ${ESD_MOD_DBUS_EVENT_SRC} + ${ESD_LIB_SRCS} + ${ESD_MOD_DBUS_EVENT_TEST_SRCS} + ${ESD_MOD_DBUS_EVENT_MOCK_SRCS} +) + +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) + +TARGET_LINK_LIBRARIES(${TARGET_ESD_MOD_DBUS_EVENT_UNITTESTS} PRIVATE ${TARGET_LIB_ESD}) + +APPLY_PKG_CONFIG(${TARGET_ESD_MOD_DBUS_EVENT_UNITTESTS} PUBLIC + AUL_DEPS + DLOG_DEPS + GIO_DEPS + GLIB_DEPS + VCONF_DEPS + PKGMGR_INFO_DEPS + SECURITY_MANAGER_DEPS + CYNARA_CLIENT_DEPS + CYNARA_CREDS_DBUS_DEPS + CYNARA_SESSION_DEPS + LIBTZPLATFORM_CONFIG_DEPS + CERT_SVC_VCORE_DEPS + CAPI_SYSTEM_INFO_DEPS + PKGMGR_DEPS + EVENTSYSTEM_DEPS + GMOCK_DEPS + APPSVC_DEPS +) + +INSTALL(TARGETS ${TARGET_ESD_MOD_DBUS_EVENT_UNITTESTS} DESTINATION bin) diff --git a/tests/dbus_event_unit_tests/src/main.cc b/tests/dbus_event_unit_tests/src/main.cc new file mode 100644 index 0000000..d473442 --- /dev/null +++ b/tests/dbus_event_unit_tests/src/main.cc @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2022 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 + +int main(int argc, char** argv) { + int ret = -1; + + try { + testing::InitGoogleTest(&argc, argv); + } catch(...) { + std::cout << "Exception occurred" << std::endl; + } + + try { + ret = RUN_ALL_TESTS(); + } catch (const ::testing::internal::GoogleTestFailureException& e) { + ret = -1; + std::cout << "GoogleTestFailureException was thrown:" << e.what() << std::endl; + } + + return ret; +} diff --git a/tests/unit_tests/src/test_privilege_checker.cc b/tests/dbus_event_unit_tests/src/test_privilege_checker.cc similarity index 98% rename from tests/unit_tests/src/test_privilege_checker.cc rename to tests/dbus_event_unit_tests/src/test_privilege_checker.cc index c4dbf3c..c5c5ce9 100644 --- a/tests/unit_tests/src/test_privilege_checker.cc +++ b/tests/dbus_event_unit_tests/src/test_privilege_checker.cc @@ -22,7 +22,7 @@ #include "cynara_mock.h" #include "security_manager_mock.h" #include "test_fixture.h" -#include "privilege_checker.hh" +#include "dbus_event/privilege_checker.hh" // using namespace tizen_base; diff --git a/tests/unit_tests/src/test_vconf_handler.cc b/tests/dbus_event_unit_tests/src/test_vconf_handler.cc similarity index 97% rename from tests/unit_tests/src/test_vconf_handler.cc rename to tests/dbus_event_unit_tests/src/test_vconf_handler.cc index 16d72b6..7472c39 100644 --- a/tests/unit_tests/src/test_vconf_handler.cc +++ b/tests/dbus_event_unit_tests/src/test_vconf_handler.cc @@ -22,7 +22,7 @@ #include "test_fixture.h" #include "eventsystem_mock.h" -#include "vconf_event_handler.hh" +#include "dbus_event/vconf_event_handler.hh" // using namespace tizen_base; using ::testing::_; diff --git a/tests/mock/cion_mock.cc b/tests/mock/cion_mock.cc new file mode 100644 index 0000000..39bb275 --- /dev/null +++ b/tests/mock/cion_mock.cc @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2022 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 + +namespace cion { +namespace channel { + +class ServerChannel::Impl { +}; + +ServerChannel::ServerChannel(std::string service_name, std::string display_name) { +} + +ServerChannel::ServerChannel(std::string service_name, std::string display_name, + SecurityInfo security) { +} + +ServerChannel::~ServerChannel() = default; + +void ServerChannel::Listen() { + +} + +void ServerChannel::Stop() { + +} + +void ServerChannel::Disconnect(std::shared_ptr) { + +} + +void ServerChannel::Accept(std::shared_ptr peer) { + +} + +void ServerChannel::Reject(std::shared_ptr peer, std::string reason) { + +} + +void ServerChannel::SendPayloadAsync(IPayload* data, + PayloadAsyncResult::PayloadAsyncResultCallback func) { +} + +void ServerChannel::SendPayloadAsync(IPayload* data, std::shared_ptr peer, + PayloadAsyncResult::PayloadAsyncResultCallback func) { +} + +std::list> ServerChannel::GetConnectedPeerList() { + return {}; +} + +std::string GetServiceName() { + return ""; +} + +std::string GetDisplayName() { + return ""; +} + +void SetDisplayName(std::string display_name) { +} + +void SetOndemandLaunchEnable(bool enable) { +} + +} +} diff --git a/tests/mock/pkgmgr_info_mock.cc b/tests/mock/pkgmgr_info_mock.cc index e459f52..969f45e 100644 --- a/tests/mock/pkgmgr_info_mock.cc +++ b/tests/mock/pkgmgr_info_mock.cc @@ -47,3 +47,8 @@ extern "C" int pkgmgrinfo_appinfo_get_usr_appinfo(const char* arg1, uid_t arg2, arg2, arg3); } +extern "C" int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, + char** version) { + return MOCK_HOOK_P2(PkgmgrInfoMock, pkgmgrinfo_pkginfo_get_version, + handle, version); +} diff --git a/tests/mock/pkgmgr_info_mock.h b/tests/mock/pkgmgr_info_mock.h index b49a879..24a9ab1 100644 --- a/tests/mock/pkgmgr_info_mock.h +++ b/tests/mock/pkgmgr_info_mock.h @@ -36,6 +36,8 @@ class PkgmgrInfoMock : public virtual ModuleMock { 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.cc b/tests/mock/tzplatform_config_mock.cc new file mode 100644 index 0000000..05e3211 --- /dev/null +++ b/tests/mock/tzplatform_config_mock.cc @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2022 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 "tzplatform_config_mock.h" + +#include "mock_hook.h" +#include "test_fixture.h" + +extern "C" const char* tzplatform_mkpath(enum tzplatform_variable arg1, const char* arg2) { + return MOCK_HOOK_P2(TzplatformConfigMock, tzplatform_mkpath, arg1, arg2); +} \ No newline at end of file diff --git a/tests/mock/tzplatform_config_mock.h b/tests/mock/tzplatform_config_mock.h new file mode 100644 index 0000000..a251057 --- /dev/null +++ b/tests/mock/tzplatform_config_mock.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2022 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_TZPLATFORM_CONFIG_MOCK_H_ +#define UNIT_TESTS_MOCK_TZPLATFORM_CONFIG_MOCK_H_ + +#include +#include + +#include "module_mock.h" + +class TzplatformConfigMock : public virtual ModuleMock { + public: + TzplatformConfigMock() { + using ::testing::_; + using ::testing::Return; + using ::testing::Invoke; + } + + MOCK_METHOD2(tzplatform_mkpath, const char* (enum tzplatform_variable, + const char*)); +}; + +#endif // UNIT_TESTS_MOCK_TZPLATFORM_CONFIG_MOCK_H_ \ No newline at end of file diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt deleted file mode 100644 index 56e001d..0000000 --- a/tests/unit_tests/CMakeLists.txt +++ /dev/null @@ -1,62 +0,0 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8) -PROJECT(${PROJECT_NAME}-unittests C CXX) - -INCLUDE(FindPkgConfig) -PKG_CHECK_MODULES(${PROJECT_NAME}-unittests REQUIRED - aul - bundle - parcel - dlog - pkgmgr-info - appsvc - gio-2.0 - glib-2.0 - pkgmgr - eventsystem - vconf - libtzplatform-config - systemd - cert-svc-vcore - cynara-client - cynara-creds-gdbus - cynara-session - security-manager - uuid - sqlite3 - cion - capi-system-info - gmock -) - -FOREACH(flag ${${PROJECT_NAME}-unittests_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") -ENDFOREACH(flag) -SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Werror") - -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=c++17") -SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") -SET(CMAKE_CXX_FLAGS_RELEASE "-O2") - -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../include) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../src/lib) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../src/modules/dbus_event) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../mock) - -AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src TEST_SOURCES) -AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../mock MOCK_SOURCES) -AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/lib LIB_SOURCES) -AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/modules/dbus_event DBUS_SOURCES) - -ADD_EXECUTABLE(${PROJECT_NAME} - ${TEST_SOURCES} - ${LIB_SOURCES} - ${DBUS_SOURCES} - ${MOCK_SOURCES} -) - -SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${EXTRA_CFLAGS}") -TARGET_LINK_LIBRARIES(${PROJECT_NAME} - ${${PROJECT_NAME}-unittests_LDFLAGS} -) - -INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin/) -- 2.7.4