Add gmock tests 95/278995/5
authorInkyun Kil <inkyun.kil@samsung.com>
Fri, 29 Jul 2022 04:16:23 +0000 (13:16 +0900)
committerInkyun Kil <inkyun.kil@samsung.com>
Thu, 25 Aug 2022 07:48:00 +0000 (16:48 +0900)
- Initialize gmock test environment

Change-Id: Icf04e1948dbb48d3f324a17dfe108ca6c4d48a3a
Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
12 files changed:
CMakeLists.txt
packaging/data-provider-master.spec
tests/CMakeLists.txt [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/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/test_badge_service.cc [new file with mode: 0644]
tests/unit_tests/src/test_main.cc [new file with mode: 0644]

index b54c738aad00a9d84405ea96e3c55494063fa782..d9355ec9cb58a0f2bdd1dda0364f2c5bd84e5cc4 100644 (file)
@@ -58,3 +58,12 @@ CONFIGURE_FILE(org.tizen.data-provider-master.service.in org.tizen.data_provider
 
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.tizen.data_provider_service.service DESTINATION ${SHARE_INSTALL_PREFIX}/dbus-1/system-services/)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.conf DESTINATION ${SYSCONF_INSTALL_DIR}/dbus-1/system.d/)
+
+IF(NOT DEFINED MINIMUM_BUILD)
+ADD_SUBDIRECTORY(tests)
+ENABLE_TESTING()
+SET(DATA_PROVIDER_MASTER_UNIT_TESTS data-provider-master-unittests)
+ADD_TEST(NAME ${DATA_PROVIDER_MASTER_UNIT_TESTS} COMMAND ${DATA_PROVIDER_MASTER_UNIT_TESTS})
+
+ADD_DEPENDENCIES(${DATA_PROVIDER_MASTER_UNIT_TESTS} data-provider-master)
+ENDIF(NOT DEFINED MINIMUM_BUILD)
\ No newline at end of file
index 22476028945bcf3bbec7ed80e5efc77a17ca4284..f7b719aec2b58a1bd1e6a594d9738bc0693a2a10 100644 (file)
@@ -31,16 +31,52 @@ BuildRequires: pkgconfig(libsystemd)
 BuildRequires: pkgconfig(alarm-service)
 BuildRequires: pkgconfig(libtzplatform-config)
 BuildRequires: pkgconfig(security-manager)
+BuildRequires: pkgconfig(gmock)
+
+%if 0%{?gcov:1}
+BuildRequires:  lcov
+BuildRequires:  zip
+%endif
 
 Requires: notification-ex
 Requires(post): dbus
 %description
 
+#################################################
+# data-provider-master-unittests
+#################################################
+%package -n %{name}-unittests
+Summary:    GTest for Data Provider Master API
+Group:      Application Framework/Testing
+Requires:   %{name}
+
+%description -n %{name}-unittests
+GTest for data-provider-master API
+
+#################################################
+# gcov
+#################################################
+%if 0%{?gcov:1}
+%package gcov
+Summary:  Data Provider Master API(gcov)
+Group:    Application Framework/Testing
+
+%description gcov
+gcov objects of a data provider master
+%endif
+
 %prep
 %setup -q
 cp %{SOURCE1001} .
 
 %build
+%if 0%{?gcov:1}
+export CFLAGS+=" -fprofile-arcs -ftest-coverage"
+export CXXFLAGS+=" -fprofile-arcs -ftest-coverage"
+export FFLAGS+=" -fprofile-arcs -ftest-coverage"
+export LDFLAGS+=" -lgcov"
+%endif
+
 MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
 
 %ifarch %ix86
@@ -57,12 +93,53 @@ export TARGET=device
 
 CFLAGS="${CFLAGS} -Wall -Winline -Werror" LDFLAGS="${LDFLAGS}" make %{?jobs:-j%jobs}
 
+%check
+ctest -V
+%if 0%{?gcov:1}
+lcov -c --ignore-errors graph --no-external -b . -d . -o %{name}.info
+genhtml %{name}.info -o out --legend --show-details
+%endif
+
 %install
 rm -rf %{buildroot}
 %make_install
 mkdir -p %{buildroot}%{_prefix}/lib/systemd/system
 install -m 0644 %SOURCE1 %{buildroot}%{_unitdir}/data-provider-master.service
 
+%if 0%{?gcov:1}
+builddir=$(basename $PWD)
+gcno_obj_dir=%{buildroot}%{_datadir}/gcov/obj/%{name}/"$builddir"
+mkdir -p "$gcno_obj_dir"
+find . -name '*.gcno' -exec cp --parents '{}' "$gcno_obj_dir" ';'
+%endif
+
+cat << EOF > run-unittest.sh
+#!/bin/sh
+setup() {
+    echo "setup start"
+}
+
+test_main() {
+    echo "test_main start"
+    /usr/bin/data-provider-master-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}/
+
 %files
 %manifest %{name}.manifest
 %defattr(-,root,root,-)
@@ -74,4 +151,19 @@ install -m 0644 %SOURCE1 %{buildroot}%{_unitdir}/data-provider-master.service
 %{_prefix}/bin/%{name}
 #%defattr(-,owner,users,-)
 
-# End of a file
+#################################################
+# data-provider-master-unittests
+#################################################
+%files -n %{name}-unittests
+%{_bindir}/%{name}-unittests
+%{_bindir}/tizen-unittests/%{name}/run-unittest.sh
+
+#################################################
+# data-provider-master-gcov
+#################################################
+%if 0%{?gcov:1}
+%files gcov
+%{_datadir}/gcov/obj/*
+%endif
+
+# End of a file
\ No newline at end of file
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/gio_mock.cc b/tests/mock/gio_mock.cc
new file mode 100644 (file)
index 0000000..b0f7aa9
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * 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" GDBusConnection* g_bus_get_sync(GBusType type,
+    GCancellable* cancellable, GError** error) {
+  return MOCK_HOOK_P3(GioMock, g_bus_get_sync, type, cancellable, error);
+}
+
+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" 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" 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" guint g_dbus_connection_signal_subscribe(GDBusConnection* arg0,
+    const gchar* arg1, const gchar* arg2, const gchar* arg3, const gchar* arg4,
+    const gchar* arg5, GDBusSignalFlags arg6, GDBusSignalCallback arg7,
+    gpointer arg8, GDestroyNotify arg9) {
+  return MOCK_HOOK_P10(GioMock, g_dbus_connection_signal_subscribe,
+      arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
+}
+
+extern "C" void g_dbus_connection_send_message_with_reply(GDBusConnection* arg0,
+    GDBusMessage* arg1, GDBusSendMessageFlags arg2, gint arg3,
+    volatile guint32* arg4, GCancellable* arg5, GAsyncReadyCallback arg6,
+    gpointer arg7) {
+  return MOCK_HOOK_P8(GioMock, g_dbus_connection_send_message_with_reply,
+      arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
+}
+
+extern "C" guint g_bus_watch_name_on_connection(
+    GDBusConnection* arg0, const gchar* arg1, GBusNameWatcherFlags arg2,
+    GBusNameAppearedCallback arg3, GBusNameVanishedCallback arg4,
+    gpointer arg5, GDestroyNotify arg6) {
+  return MOCK_HOOK_P7(GioMock, g_bus_watch_name_on_connection,
+      arg0, arg1, arg2, arg3, arg4, arg5, arg6);
+}
+
+extern "C" void g_bus_unwatch_name(guint arg0) {
+  return MOCK_HOOK_P1(GioMock, g_bus_unwatch_name, arg0);
+}
+
+extern "C" void g_dbus_connection_signal_unsubscribe(
+    GDBusConnection* arg0, guint arg1) {
+  return MOCK_HOOK_P2(GioMock, g_dbus_connection_signal_unsubscribe,
+      arg0, arg1);
+}
+
+extern "C" const gchar* g_dbus_connection_get_unique_name(GDBusConnection* connection) {
+  return MOCK_HOOK_P1(GioMock, g_dbus_connection_get_unique_name, connection);
+}
+
+extern "C" gboolean g_source_remove(guint tag) {
+  return MOCK_HOOK_P1(GioMock, g_source_remove, tag);
+}
diff --git a/tests/mock/gio_mock.h b/tests/mock/gio_mock.h
new file mode 100644 (file)
index 0000000..97d29a8
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * 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_METHOD3(g_bus_get_sync,
+      GDBusConnection*(GBusType, GCancellable*, GError**));
+  MOCK_METHOD4(g_dbus_message_new_method_call,
+      GDBusMessage*(const gchar*, const gchar*, const gchar*, const gchar*));
+  MOCK_METHOD2(g_dbus_message_set_body, void(GDBusMessage*, GVariant*));
+  MOCK_METHOD1(g_dbus_message_get_body, GVariant*(GDBusMessage*));
+  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_METHOD8(g_dbus_connection_send_message_with_reply,
+      void(GDBusConnection*, GDBusMessage*, GDBusSendMessageFlags, gint,
+          volatile guint32*, GCancellable*, GAsyncReadyCallback, gpointer));
+  MOCK_METHOD7(g_bus_watch_name_on_connection,
+      guint(GDBusConnection*, const gchar*, GBusNameWatcherFlags,
+          GBusNameAppearedCallback, GBusNameVanishedCallback, gpointer,
+          GDestroyNotify));
+  MOCK_METHOD1(g_bus_unwatch_name, void(guint));
+  MOCK_METHOD2(g_dbus_connection_signal_unsubscribe,
+          void(GDBusConnection*, guint));
+  MOCK_METHOD1(g_dbus_connection_get_unique_name, const gchar*(GDBusConnection*));
+  MOCK_METHOD1(g_source_remove, gboolean(guint));
+};
+
+#endif  // MOCK_GIO_MOCK_H_
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/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..70a35d6
--- /dev/null
@@ -0,0 +1,43 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.8)\r
+PROJECT(data-provider-master-unittests C CXX)\r
+\r
+INCLUDE(FindPkgConfig)\r
+PKG_CHECK_MODULES(data-provider-master-unittests REQUIRED\r
+    gmock\r
+    dlog\r
+    bundle\r
+    glib-2.0\r
+    gio-2.0\r
+    sqlite3\r
+    aul\r
+)\r
+\r
+FOREACH(flag ${data-provider-master-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)\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_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
+    ${data-provider-master-unittests_LDFLAGS}\r
+)\r
+\r
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin/)\r
diff --git a/tests/unit_tests/src/test_badge_service.cc b/tests/unit_tests/src/test_badge_service.cc
new file mode 100644 (file)
index 0000000..822d969
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * 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 <stdlib.h>
+#include <gtest/gtest.h>
+#include <stdio.h>
+#include <glib.h>
+
+#include <memory>
+
+#include "service_common.h"
+#include "badge_service.h"
+#include "gio_mock.h"
+#include "test_fixture.h"
+
+// using namespace tizen_base;
+using ::testing::_;
+using ::testing::DoAll;
+using ::testing::Return;
+using ::testing::SetArgPointee;
+
+class Mocks : public ::testing::NiceMock<GioMock> {};
+
+class BadgeServiceTest : public TestFixture {
+ public:
+  BadgeServiceTest() : TestFixture(std::make_unique<Mocks>()) {}
+  virtual ~BadgeServiceTest() {}
+
+  virtual void SetUp() {
+  }
+
+  virtual void TearDown() {
+  }
+};
+
+TEST_F(BadgeServiceTest, badge_service_init) {
+  int ret;
+  ret = BADGE_ERROR_NONE;
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+
+}
diff --git a/tests/unit_tests/src/test_main.cc b/tests/unit_tests/src/test_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;
+}