FILES_MATCHING
PATTERN "*.h"
)
+
+IF(NOT DEFINED MINIMUM_BUILD)
+ADD_SUBDIRECTORY(tests)
+ENABLE_TESTING()
+SET(EVENTSYSTEM_UNIT_TESTS eventsystem-unittests)
+ADD_TEST(NAME ${EVENTSYSTEM_UNIT_TESTS} COMMAND ${EVENTSYSTEM_UNIT_TESTS})
+
+ADD_DEPENDENCIES(${EVENTSYSTEM_UNIT_TESTS} eventsystem)
+ENDIF(NOT DEFINED MINIMUM_BUILD)
\ No newline at end of file
BuildRequires: pkgconfig(gio-2.0)
BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(capi-base-common)
+BuildRequires: pkgconfig(gmock)
+
+%if 0%{?gcov:1}
+BuildRequires: lcov
+BuildRequires: zip
+%endif
Requires(post): /sbin/ldconfig
Requires(postun): /sbin/ldconfig
%description devel
Event system library (devel)
+#################################################
+# eventsystem-unittests
+#################################################
+%package -n %{name}-unittests
+Summary: GTest for EventySystem API
+Group: Application Framework/Testing
+Requires: %{name}
+
+%description -n %{name}-unittests
+GTest for EventSystem API
+
+#################################################
+# gcov
+#################################################
+%if 0%{?gcov:1}
+%package gcov
+Summary: Event System API(gcov)
+Group: Application Framework/Testing
+
+%description gcov
+gcov objects of a eventsystem
+%endif
+
%prep
%setup -q
export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE"
export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE"
+%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}'`
%cmake . -DFULLVER=%{version} -DMAJORVER=${MAJORVER}
make %{?jobs:-j%jobs}
+%check
+ctest -V
+%if 0%{?gcov:1}
+lcov -c --ignore-errors graph --no-external -q -d . -o ${name}.info
+genhtml ${name}.info -o out --legend --show-details
+%endif
+
%install
rm -rf %{buildroot}
%make_install
+%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/eventsystem-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}/
+
+
%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig
%{_includedir}/*.h
%{_libdir}/libeventsystem.so
%{_libdir}/pkgconfig/eventsystem.pc
+
+#################################################
+# eventsystem-unittests
+#################################################
+%files -n %{name}-unittests
+%{_bindir}/%{name}-unittests
+%{_bindir}/tizen-unittests/%{name}/run-unittest.sh
+
+#################################################
+# eventsystem-gcov
+#################################################
+%if 0%{?gcov:1}
+%files gcov
+%{_datadir}/gcov/obj/*
+%endif
\ No newline at end of file
--- /dev/null
+ADD_SUBDIRECTORY(unit_tests)
--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+/*
+ * 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_
--- /dev/null
+/*
+ * 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_
--- /dev/null
+/*
+ * 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_
--- /dev/null
+/*
+ * 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_;
--- /dev/null
+/*
+ * 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_
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.8)\r
+PROJECT(eventsystem-unittests C CXX)\r
+\r
+INCLUDE(FindPkgConfig)\r
+PKG_CHECK_MODULES(eventsystem-unittests REQUIRED\r
+ gmock\r
+ dlog\r
+ bundle\r
+ glib-2.0\r
+ gio-2.0\r
+)\r
+\r
+FOREACH(flag ${eventsystem-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
+ ${eventsystem-unittests_LDFLAGS}\r
+)\r
+\r
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin/)\r
--- /dev/null
+/*
+ * 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 <bundle.h>
+
+#include "eventsystem.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 EventSystemTest : public TestFixture {
+ public:
+ EventSystemTest() : TestFixture(std::make_unique<Mocks>()) {}
+ virtual ~EventSystemTest() {}
+
+ virtual void SetUp() {
+ }
+
+ virtual void TearDown() {
+ }
+};
+
+TEST_F(EventSystemTest, eventsystem_keep_last_event_data) {
+ int ret = eventsystem_keep_last_event_data("test");
+ EXPECT_NE(ret, ES_R_OK);
+}
--- /dev/null
+/*
+ * 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;
+}