Add gmock tests 44/284744/2
authorInkyun Kil <inkyun.kil@samsung.com>
Fri, 25 Nov 2022 01:34:12 +0000 (10:34 +0900)
committerInkyun Kil <inkyun.kil@samsung.com>
Fri, 25 Nov 2022 01:36:30 +0000 (10:36 +0900)
- Initialize gmock test environment

Change-Id: I3e6f49969e766dcefdb9edfdbecc3e5fe0404ee5
Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
15 files changed:
CMakeLists.txt
packaging/esd.spec
tests/CMakeLists.txt [new file with mode: 0644]
tests/mock/aul_mock.cc [new file with mode: 0644]
tests/mock/aul_mock.h [new file with mode: 0644]
tests/mock/gio_mock.cc [new file with mode: 0644]
tests/mock/gio_mock.h [new file with mode: 0644]
tests/mock/mock_hook.h [new file with mode: 0644]
tests/mock/module_mock.h [new file with mode: 0644]
tests/mock/pkgmgr_info_mock.cc [new file with mode: 0644]
tests/mock/pkgmgr_info_mock.h [new file with mode: 0644]
tests/mock/test_fixture.cc [new file with mode: 0644]
tests/mock/test_fixture.h [new file with mode: 0644]
tests/unit_tests/CMakeLists.txt [new file with mode: 0644]
tests/unit_tests/src/main.cc [new file with mode: 0644]

index 60b5383..6123889 100644 (file)
@@ -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)
index cfbe03b..e633ce3 100644 (file)
@@ -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 (file)
index 0000000..c90fac8
--- /dev/null
@@ -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 (file)
index 0000000..d4129dd
--- /dev/null
@@ -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 (file)
index 0000000..9f15d18
--- /dev/null
@@ -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 <aul.h>
+#include <aul_rsc_mgr.h>
+#include <aul_rpc_port.h>
+#include <aul_svc.h>
+#include <aul_app_com.h>
+#include <gmock/gmock.h>
+
+#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 (file)
index 0000000..34c4086
--- /dev/null
@@ -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 <gio/gio.h>
+
+#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 (file)
index 0000000..0239667
--- /dev/null
@@ -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 <gio/gio.h>
+#include <gmock/gmock.h>
+
+#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 (file)
index 0000000..42f06f5
--- /dev/null
@@ -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<MOCK_CLASS>().f()
+#define MOCK_HOOK_P1(MOCK_CLASS, f, p1)                                        \
+    TestFixture::GetMock<MOCK_CLASS>().f(p1)
+#define MOCK_HOOK_P2(MOCK_CLASS, f, p1, p2)                                    \
+    TestFixture::GetMock<MOCK_CLASS>().f(p1, p2)
+#define MOCK_HOOK_P3(MOCK_CLASS, f, p1, p2, p3)                                \
+    TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3)
+#define MOCK_HOOK_P4(MOCK_CLASS, f, p1, p2, p3, p4)                            \
+    TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4)
+#define MOCK_HOOK_P5(MOCK_CLASS, f, p1, p2, p3, p4, p5)                        \
+    TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4, p5)
+#define MOCK_HOOK_P6(MOCK_CLASS, f, p1, p2, p3, p4, p5, p6)                    \
+    TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4, p5, p6)
+#define MOCK_HOOK_P7(MOCK_CLASS, f, p1, p2, p3, p4, p5, p6, p7)                \
+    TestFixture::GetMock<MOCK_CLASS>().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<MOCK_CLASS>().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<MOCK_CLASS>().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 (file)
index 0000000..bfc64f7
--- /dev/null
@@ -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 (file)
index 0000000..e459f52
--- /dev/null
@@ -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 (file)
index 0000000..b49a879
--- /dev/null
@@ -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 <pkgmgr-info.h>
+#include <gmock/gmock.h>
+
+#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 (file)
index 0000000..e9e0e93
--- /dev/null
@@ -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 <memory>
+
+std::unique_ptr<ModuleMock> TestFixture::mock_;
diff --git a/tests/mock/test_fixture.h b/tests/mock/test_fixture.h
new file mode 100644 (file)
index 0000000..10173ca
--- /dev/null
@@ -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 <gtest/gtest.h>
+
+#include <memory>
+#include <stdexcept>
+#include <string>
+#include <utility>
+
+#include "module_mock.h"
+
+class TestFixture : public ::testing::Test {
+ public:
+  explicit TestFixture(std::unique_ptr<ModuleMock>&& mock) {
+    mock_ = std::move(mock);
+  }
+  virtual ~TestFixture() {
+    mock_.reset();
+  }
+
+  virtual void SetUp() {}
+  virtual void TearDown() {}
+
+  template <typename T>
+  static T& GetMock() {
+    auto ptr = dynamic_cast<T*>(mock_.get());
+    return *ptr;
+  }
+
+  static std::unique_ptr<ModuleMock> mock_;
+};
+
+#endif  // MOCK_TEST_FIXTURE_H_
diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt
new file mode 100644 (file)
index 0000000..90e8a31
--- /dev/null
@@ -0,0 +1,59 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.8)\r
+PROJECT(${PROJECT_NAME}-unittests C CXX)\r
+\r
+INCLUDE(FindPkgConfig)\r
+PKG_CHECK_MODULES(${PROJECT_NAME}-unittests REQUIRED\r
+    aul\r
+    bundle\r
+    parcel\r
+    dlog\r
+    pkgmgr-info\r
+    appsvc\r
+    gio-2.0\r
+    glib-2.0\r
+    pkgmgr\r
+    eventsystem\r
+    vconf\r
+    libtzplatform-config\r
+    systemd\r
+    cert-svc-vcore\r
+    cynara-client\r
+    cynara-creds-gdbus\r
+    cynara-session\r
+    security-manager\r
+    uuid\r
+    sqlite3\r
+    cion\r
+    capi-system-info\r
+    gmock\r
+)\r
+\r
+FOREACH(flag ${${PROJECT_NAME}-unittests_CFLAGS})\r
+    SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")\r
+ENDFOREACH(flag)\r
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Werror")\r
+\r
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=c++14")\r
+SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")\r
+SET(CMAKE_CXX_FLAGS_RELEASE "-O2")\r
+\r
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../include)\r
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../src/lib/modules/dbus_event)\r
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../mock)\r
+\r
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src TEST_SOURCES)\r
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../mock MOCK_SOURCES)\r
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/lib/modules/dbus_event/* LIB_SOURCES)\r
+\r
+ADD_EXECUTABLE(${PROJECT_NAME}\r
+    ${TEST_SOURCES}\r
+    ${LIB_SOURCES}\r
+    ${MOCK_SOURCES}\r
+)\r
+\r
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${EXTRA_CFLAGS}")\r
+TARGET_LINK_LIBRARIES(${PROJECT_NAME}\r
+    ${${PROJECT_NAME}-unittests_LDFLAGS}\r
+)\r
+\r
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin/)\r
diff --git a/tests/unit_tests/src/main.cc b/tests/unit_tests/src/main.cc
new file mode 100644 (file)
index 0000000..d473442
--- /dev/null
@@ -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 <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+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;
+}