From: Inkyun Kil Date: Fri, 25 Nov 2022 01:34:12 +0000 (+0900) Subject: Add gmock tests X-Git-Tag: accepted/tizen/unified/20221209.124053~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=26315a426955b92cba309274b331c9fd6586e46f;p=platform%2Fcore%2Fappfw%2Fevent-system.git Add gmock tests - Initialize gmock test environment Change-Id: I3e6f49969e766dcefdb9edfdbecc3e5fe0404ee5 Signed-off-by: Inkyun Kil --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 60b5383..6123889 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,3 +53,12 @@ PKG_CHECK_MODULES(PKGMGR_DEPS REQUIRED pkgmgr) PKG_CHECK_MODULES(EVENTSYSTEM_DEPS REQUIRED eventsystem) 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}) +ENDIF(NOT DEFINED MINIMUM_BUILD) diff --git a/packaging/esd.spec b/packaging/esd.spec index cfbe03b..e633ce3 100644 --- a/packaging/esd.spec +++ b/packaging/esd.spec @@ -30,6 +30,7 @@ BuildRequires: pkgconfig(uuid) BuildRequires: pkgconfig(sqlite3) BuildRequires: pkgconfig(cion) BuildRequires: pkgconfig(capi-system-info) +BuildRequires: pkgconfig(gmock) Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig @@ -61,6 +62,17 @@ This module is for event system using dbus %define _moddir %{_datadir}/esd +################################################# +# unittests +################################################# +%package -n %{name}-unittests +Summary: GTest for API +Group: Application Framework/Testing +Requires: %{name} + +%description -n %{name}-unittests +GTest for API + %prep %setup -q cp %{SOURCE1001} . @@ -79,9 +91,38 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` make %{?jobs:-j%jobs} +%check +ctest -v + %install rm -rf %{buildroot} %make_install +cat << EOF > run-unittest.sh +#!/bin/sh +setup() { + echo "setup start" +} + +test_main() { + echo "test_main start" + /usr/bin/%{name}-unittests +} + +teardown() { + echo "teardown start" +} + +main() { + setup + test_main + teardown +} + +main "\$*" +EOF + +mkdir -p %{buildroot}%{_bindir}/tizen-unittests/%{name} +install -m 0755 run-unittest.sh %{buildroot}%{_bindir}/tizen-unittests/%{name}/ mkdir -p %{buildroot}%{_unitdir}/multi-user.target.wants install -m 0644 %SOURCE1 %{buildroot}%{_unitdir}/esd.service @@ -116,3 +157,9 @@ ln -sf ../esd.service %{buildroot}%{_unitdir}/multi-user.target.wants/esd.servic %manifest %{name}.manifest %license LICENSE %{_moddir}/mod/libesd-mod-dbus-event.so +################################################# +# unittests +################################################# +%files -n %{name}-unittests +%{_bindir}/%{name}-unittests +%{_bindir}/tizen-unittests/%{name}/run-unittest.sh diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..c90fac8 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1 @@ +ADD_SUBDIRECTORY(unit_tests) diff --git a/tests/mock/aul_mock.cc b/tests/mock/aul_mock.cc new file mode 100644 index 0000000..d4129dd --- /dev/null +++ b/tests/mock/aul_mock.cc @@ -0,0 +1,34 @@ +/* + * 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 "aul_mock.h" +#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, + arg2, arg3, arg4); +} + +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); +} + diff --git a/tests/mock/aul_mock.h b/tests/mock/aul_mock.h new file mode 100644 index 0000000..9f15d18 --- /dev/null +++ b/tests/mock/aul_mock.h @@ -0,0 +1,39 @@ +/* + * 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 MOCK_AUL_MOCK_H_ +#define MOCK_AUL_MOCK_H_ + +#include +#include +#include +#include +#include +#include + +#include "module_mock.h" + +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)); +}; + +#endif // MOCK_AUL_MOCK_H_ \ No newline at end of file diff --git a/tests/mock/gio_mock.cc b/tests/mock/gio_mock.cc new file mode 100644 index 0000000..34c4086 --- /dev/null +++ b/tests/mock/gio_mock.cc @@ -0,0 +1,59 @@ +/* + * 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 "gio_mock.h" +#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_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" 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" gboolean g_dbus_connection_emit_signal(GDBusConnection* arg1, + const gchar* arg2, const gchar* arg3, const gchar* arg4, const gchar* arg5, + GVariant* arg6, GError** arg7) { + return MOCK_HOOK_P7(GioMock, g_dbus_connection_emit_signal, arg1, arg2, + arg3, arg4, arg5, arg6, arg7); +} + +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); +} + diff --git a/tests/mock/gio_mock.h b/tests/mock/gio_mock.h new file mode 100644 index 0000000..0239667 --- /dev/null +++ b/tests/mock/gio_mock.h @@ -0,0 +1,51 @@ +/* + * 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 MOCK_GIO_MOCK_H_ +#define MOCK_GIO_MOCK_H_ + +#include +#include + +#include "module_mock.h" + +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_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_METHOD7(g_dbus_connection_emit_signal, gboolean (GDBusConnection*, + const gchar*, const gchar*, const gchar*, const gchar*, GVariant*, + GError**)); + + MOCK_METHOD2(g_dbus_message_set_body, void(GDBusMessage*, GVariant*)); + + MOCK_METHOD1(g_dbus_message_get_body, GVariant*(GDBusMessage*)); + +}; + +#endif // MOCK_GIO_MOCK_H_ \ No newline at end of file diff --git a/tests/mock/mock_hook.h b/tests/mock/mock_hook.h new file mode 100644 index 0000000..42f06f5 --- /dev/null +++ b/tests/mock/mock_hook.h @@ -0,0 +1,42 @@ +/* + * 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 MOCK_MOCK_HOOK_H_ +#define MOCK_MOCK_HOOK_H_ + +#define MOCK_HOOK_P0(MOCK_CLASS, f) \ + TestFixture::GetMock().f() +#define MOCK_HOOK_P1(MOCK_CLASS, f, p1) \ + TestFixture::GetMock().f(p1) +#define MOCK_HOOK_P2(MOCK_CLASS, f, p1, p2) \ + TestFixture::GetMock().f(p1, p2) +#define MOCK_HOOK_P3(MOCK_CLASS, f, p1, p2, p3) \ + TestFixture::GetMock().f(p1, p2, p3) +#define MOCK_HOOK_P4(MOCK_CLASS, f, p1, p2, p3, p4) \ + TestFixture::GetMock().f(p1, p2, p3, p4) +#define MOCK_HOOK_P5(MOCK_CLASS, f, p1, p2, p3, p4, p5) \ + TestFixture::GetMock().f(p1, p2, p3, p4, p5) +#define MOCK_HOOK_P6(MOCK_CLASS, f, p1, p2, p3, p4, p5, p6) \ + TestFixture::GetMock().f(p1, p2, p3, p4, p5, p6) +#define MOCK_HOOK_P7(MOCK_CLASS, f, p1, p2, p3, p4, p5, p6, p7) \ + TestFixture::GetMock().f(p1, p2, p3, p4, p5, p6, p7) +#define MOCK_HOOK_P8(MOCK_CLASS, f, p1, p2, p3, p4, p5, p6, p7, p8) \ + TestFixture::GetMock().f(p1, p2, p3, p4, p5, p6, p7, p8) +#define MOCK_HOOK_P10(MOCK_CLASS, f, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) \ + TestFixture::GetMock().f( \ + p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) + +#endif // MOCK_MOCK_HOOK_H_ diff --git a/tests/mock/module_mock.h b/tests/mock/module_mock.h new file mode 100644 index 0000000..bfc64f7 --- /dev/null +++ b/tests/mock/module_mock.h @@ -0,0 +1,25 @@ +/* + * 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 MOCK_MODULE_MOCK_H_ +#define MOCK_MODULE_MOCK_H_ + +class ModuleMock { + public: + virtual ~ModuleMock() {} +}; + +#endif // MOCK_MODULE_MOCK_H_ diff --git a/tests/mock/pkgmgr_info_mock.cc b/tests/mock/pkgmgr_info_mock.cc new file mode 100644 index 0000000..e459f52 --- /dev/null +++ b/tests/mock/pkgmgr_info_mock.cc @@ -0,0 +1,49 @@ +/* + * 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 "pkgmgr_info_mock.h" +#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 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_destroy_appinfo( + pkgmgrinfo_appinfo_h arg0) { + return MOCK_HOOK_P1(PkgmgrInfoMock, pkgmgrinfo_appinfo_destroy_appinfo, + 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_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); +} + diff --git a/tests/mock/pkgmgr_info_mock.h b/tests/mock/pkgmgr_info_mock.h new file mode 100644 index 0000000..b49a879 --- /dev/null +++ b/tests/mock/pkgmgr_info_mock.h @@ -0,0 +1,41 @@ +/* + * 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 MOCK_PKGMGR_INFO_MOCK_H_ +#define MOCK_PKGMGR_INFO_MOCK_H_ + +#include +#include + +#include "module_mock.h" + +class PkgmgrInfoMock : public virtual ModuleMock { + public: + virtual ~PkgmgrInfoMock() {} + + MOCK_METHOD3(pkgmgrinfo_pkginfo_get_usr_pkginfo, + int (const char *, uid_t, pkgmgrinfo_pkginfo_h*)); + MOCK_METHOD2(pkgmgrinfo_appinfo_get_pkgid, + int (pkgmgrinfo_pkginfo_h, char **)); + 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*)); +}; + +#endif // MOCK_PKMGR_INFO_MOCK_H_ \ No newline at end of file diff --git a/tests/mock/test_fixture.cc b/tests/mock/test_fixture.cc new file mode 100644 index 0000000..e9e0e93 --- /dev/null +++ b/tests/mock/test_fixture.cc @@ -0,0 +1,21 @@ +/* + * 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 "test_fixture.h" + +#include + +std::unique_ptr TestFixture::mock_; diff --git a/tests/mock/test_fixture.h b/tests/mock/test_fixture.h new file mode 100644 index 0000000..10173ca --- /dev/null +++ b/tests/mock/test_fixture.h @@ -0,0 +1,50 @@ +/* + * 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 MOCK_TEST_FIXTURE_H_ +#define MOCK_TEST_FIXTURE_H_ + +#include + +#include +#include +#include +#include + +#include "module_mock.h" + +class TestFixture : public ::testing::Test { + public: + explicit TestFixture(std::unique_ptr&& mock) { + mock_ = std::move(mock); + } + virtual ~TestFixture() { + mock_.reset(); + } + + virtual void SetUp() {} + virtual void TearDown() {} + + template + static T& GetMock() { + auto ptr = dynamic_cast(mock_.get()); + return *ptr; + } + + static std::unique_ptr mock_; +}; + +#endif // MOCK_TEST_FIXTURE_H_ diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt new file mode 100644 index 0000000..90e8a31 --- /dev/null +++ b/tests/unit_tests/CMakeLists.txt @@ -0,0 +1,59 @@ +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++14") +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/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/modules/dbus_event/* LIB_SOURCES) + +ADD_EXECUTABLE(${PROJECT_NAME} + ${TEST_SOURCES} + ${LIB_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/) diff --git a/tests/unit_tests/src/main.cc b/tests/unit_tests/src/main.cc new file mode 100644 index 0000000..d473442 --- /dev/null +++ b/tests/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; +}