-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+CMAKE_MINIMUM_REQUIRED(VERSION 3.2)
-PROJECT(eventsystem C)
-AUX_SOURCE_DIRECTORY(src/ SRCS)
+PROJECT(eventsystem)
+SET(CMAKE_INSTALL_PREFIX /usr)
SET(PREFIX ${CMAKE_INSTALL_PREFIX})
-SET(EXEC_PREFIX "\${prefix}")
-SET(LIBDIR "\${prefix}/lib")
-SET(INCLUDEDIR "\${prefix}/include")
+SET(PC_NAME "libeventsystem")
+SET(PC_REQUIRED "bundle capi-base-common")
+SET(PC_VERSION ${FULLVER})
+SET(PC_LDFLAGS "-leventsystem")
+SET(PC_PACKAGE_DESCRIPTION "Event System Library")
-set(CMAKE_SKIP_BUILD_RPATH true)
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-zdefs")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
+SET(CMAKE_C_FLAGS_RELEASE "-O2")
-### Local include directories
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src)
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_C_FLAGS} -std=c++17")
+SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
+SET(CMAKE_CXX_FLAGS_RELEASE "-O2")
-### Required packages
-INCLUDE(FindPkgConfig)
-
-pkg_check_modules(libpkgs REQUIRED aul dlog bundle glib-2.0 capi-base-common)
-
-#FIND_LIBRARY(LIB_DL dl)
-
-FOREACH(flag ${libpkgs_CFLAGS})
- SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
-
-## Additional flag
-SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
-SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -Wall")
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
-
-## Linker flags
-SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
+SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
+ "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
-## build eventsystem library
-add_library(eventsystem SHARED ${SRCS})
+SET(TARGET_EVENTSYSTEM "eventsystem")
+SET(TARGET_EVENTSYSTEM_UNITTESTS "eventsystem-unittests")
-#TARGET_LINK_LIBRARIES(eventsystem "-ldl")
-TARGET_LINK_LIBRARIES(eventsystem ${libpkgs_LDFLAGS})
-SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${MAJORVER})
-SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${FULLVER})
-
-# pkgconfig file
-CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/eventsystem.pc.in ${CMAKE_BINARY_DIR}/eventsystem.pc @ONLY)
-configure_file(eventsystem.manifest.in eventsystem.manifest @ONLY)
-
-INSTALL(TARGETS eventsystem DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries)
-INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/eventsystem.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
-INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION include/
- FILES_MATCHING
- PATTERN "*.h"
- )
-
-IF(NOT DEFINED MINIMUM_BUILD)
+INCLUDE(FindPkgConfig)
+INCLUDE(ApplyPkgConfig)
+
+PKG_CHECK_MODULES(AUL_DEPS REQUIRED aul)
+PKG_CHECK_MODULES(BUNDLE_DEPS REQUIRED bundle)
+PKG_CHECK_MODULES(CAPI_BASE_COMMON_DEPS REQUIRED capi-base-common)
+PKG_CHECK_MODULES(DLOG_DEPS REQUIRED dlog)
+PKG_CHECK_MODULES(GLIB_DEPS REQUIRED glib-2.0)
+PKG_CHECK_MODULES(GIO_DEPS REQUIRED gio-2.0)
+PKG_CHECK_MODULES(GMOCK_DEPS REQUIRED gmock)
+PKG_CHECK_MODULES(PKGMGR_INFO_DEPS REQUIRED pkgmgr-info)
+
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_EVENTSYSTEM}.pc.in
+ ${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_EVENTSYSTEM}.pc @ONLY)
+CONFIGURE_FILE(${TARGET_EVENTSYSTEM}.manifest.in
+ ${TARGET_EVENTSYSTEM}.manifest @ONLY)
+
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_EVENTSYSTEM}.pc
+ DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
+ DESTINATION include/
+ FILES_MATCHING
+ PATTERN "*.h"
+)
+
+ADD_SUBDIRECTORY(src)
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
+ENABLE_TESTING()
+ADD_TEST(NAME ${TARGET_EVENTSYSTEM_UNITTESTS}
+ COMMAND ${TARGET_EVENTSYSTEM_UNITTESTS}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests/unit_tests
+)
\ No newline at end of file
--- /dev/null
+# Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+#
+# This function applies external (out of source tree) dependencies
+# to given target. Arguments are:
+# TARGET - valid cmake target
+# PRIVACY - dependency can be inherited by dependent targets or not:
+# PUBLIC - this should be used by default, cause compile/link flags passing
+# PRIVATE - do not passes any settings to dependent targets,
+# may be usefull for static libraries from the inside of the project
+# Argument ARGV2 and following are supposed to be names of checked pkg config
+# packages. This function will use variables created by check_pkg_modules().
+# - ${DEP_NAME}_LIBRARIES
+# - ${DEP_NAME}_INCLUDE_DIRS
+# - ${DEP_NAME}_CFLAGS
+#
+FUNCTION(APPLY_PKG_CONFIG TARGET PRIVACY)
+ MATH(EXPR DEST_INDEX "${ARGC}-1")
+ FOREACH(I RANGE 2 ${DEST_INDEX})
+ IF(NOT ${ARGV${I}}_FOUND)
+ MESSAGE(FATAL_ERROR "Not found dependency - ${ARGV${I}}_FOUND")
+ ENDIF(NOT ${ARGV${I}}_FOUND)
+ TARGET_LINK_LIBRARIES(${TARGET} ${PRIVACY} "${${ARGV${I}}_LIBRARIES}")
+ TARGET_INCLUDE_DIRECTORIES(${TARGET} ${PRIVACY} SYSTEM "${${ARGV${I}}_INCLUDE_DIRS}")
+ STRING(REPLACE ";" " " CFLAGS_STR "${${ARGV${I}}_CFLAGS}")
+ SET(CFLAGS_LIST ${CFLAGS_STR})
+ SEPARATE_ARGUMENTS(CFLAGS_LIST)
+ FOREACH(OPTION ${CFLAGS_LIST})
+ TARGET_COMPILE_OPTIONS(${TARGET} ${PRIVACY} ${OPTION})
+ ENDFOREACH(OPTION)
+ SET_TARGET_PROPERTIES(${TARGET} PROPERTIES SKIP_BUILD_RPATH true)
+ ENDFOREACH(I RANGE 2 ${DEST_INDEX})
+ENDFUNCTION(APPLY_PKG_CONFIG TARGET PRIVACY)
# Package Information for pkg-config
-prefix=/usr
-exec_prefix=${prefix}
+prefix=@PREFIX@
+exec_prefix=@PREFIX@
libdir=@LIB_INSTALL_DIR@
-includedir=${prefix}/include
+includedir=@INCLUDE_INSTALL_DIR@
-Name: libeventsystem
-Description: event system library
-Version: @VERSION@
-Requires: bundle glib-2.0 gio-2.0
-Libs: -L${libdir} -leventsystem
+Name: @PC_NAME@
+Description: @PC_PACKAGE_DESCRIPTION@
+Version: @PC_VERSION@
+Requires: @PC_REQUIRED@
+Libs: -L${libdir} @PC_LDFLAGS@
Cflags: -I${includedir}
/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2015 - 2024 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* header file for eventsystem
*/
-#include <stdbool.h>
+#include <bundle.h>
#include <eventsystem_internal.h>
+#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2015 - 2024 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
*/
#ifndef __EVENTSYSTEM_INTERNAL_H__
-#define ___EVENTSYSTEM_INTERNAL_H__
+#define __EVENTSYSTEM_INTERNAL_H__
#ifdef __cplusplus
extern "C" {
Source0: %{name}-%{version}.tar.gz
BuildRequires: cmake
BuildRequires: pkgconfig(aul)
-BuildRequires: pkgconfig(ecore)
BuildRequires: pkgconfig(bundle)
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(gio-2.0)
BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(capi-base-common)
BuildRequires: pkgconfig(gmock)
+BuildRequires: pkgconfig(pkgmgr-info)
%if 0%{?gcov:1}
BuildRequires: lcov
make %{?jobs:-j%jobs}
%check
+export LD_LIBRARY_PATH="../../src"
ctest -V
+
%if 0%{?gcov:1}
lcov -c --ignore-errors mismatch,graph,unused --no-external -q -d . -o ${name}.info
genhtml ${name}.info -o out --legend --show-details
--- /dev/null
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SRCS)
+
+ADD_LIBRARY(${TARGET_EVENTSYSTEM} SHARED ${SRCS})
+
+APPLY_PKG_CONFIG(${TARGET_EVENTSYSTEM} PUBLIC
+ AUL_DEPS
+ BUNDLE_DEPS
+ CAPI_BASE_COMMON_DEPS
+ DLOG_DEPS
+ GLIB_DEPS
+ GIO_DEPS
+ PKGMGR_INFO_DEPS
+)
+
+SET_TARGET_PROPERTIES(${TARGET_EVENTSYSTEM} PROPERTIES SOVERSION ${MAJORVER})
+SET_TARGET_PROPERTIES(${TARGET_EVENTSYSTEM} PROPERTIES VERSION ${FULLVER})
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_EVENTSYSTEM} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/../
+ ${CMAKE_CURRENT_SOURCE_DIR}/../include
+)
+
+INSTALL(TARGETS ${TARGET_EVENTSYSTEM} DESTINATION ${LIB_INSTALL_DIR}
+ COMPONENT RuntimeLibraries)
#ifndef __EVENTSYSTEM_PRIVATE_H__
#define __EVENTSYSTEM_PRIVATE_H__
-#ifdef API
#undef API
-#endif
-
#define API __attribute__ ((visibility("default")))
#define EVENTSYSTEM_CTOR __attribute__((constructor))
+++ /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" gboolean g_dbus_is_interface_name(const gchar* arg0) {
- return MOCK_HOOK_P1(GioMock, g_dbus_is_interface_name, arg0);
-}
-
-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" 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" guint g_bus_own_name_on_connection(GDBusConnection* arg0,
- const gchar* arg1, GBusNameOwnerFlags arg2, GBusNameAcquiredCallback arg3,
- GBusNameLostCallback arg4, gpointer arg5, GDestroyNotify arg6) {
- return MOCK_HOOK_P7(GioMock, g_bus_own_name_on_connection,
- arg0, arg1, arg2, arg3, arg4, arg5, arg6);
-}
-
-extern "C" GDBusProxy* g_dbus_proxy_new_sync(GDBusConnection* arg0,
- GDBusProxyFlags arg1, GDBusInterfaceInfo* arg2, const gchar* arg3,
- const gchar* arg4, const gchar* arg5, GCancellable* arg6, GError** arg7) {
- return MOCK_HOOK_P8(GioMock, g_dbus_proxy_new_sync,
- arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
-}
-
-extern "C" GVariant* g_dbus_proxy_call_sync(GDBusProxy* arg1,
- const gchar* arg2, GVariant* arg3, GDBusCallFlags arg4, gint arg5,
- GCancellable* arg6, GError** arg7) {
- return MOCK_HOOK_P7(GioMock, g_dbus_proxy_call_sync, arg1, arg2,
- arg3, arg4, arg5, arg6, arg7);
-}
-
-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_connection_signal_unsubscribe(
- GDBusConnection* arg0, guint arg1) {
- return MOCK_HOOK_P2(GioMock, g_dbus_connection_signal_unsubscribe,
- arg0, arg1);
-}
-
-extern "C" gboolean g_dbus_connection_flush_sync(GDBusConnection* arg1,
- GCancellable* arg2,
- GError** arg3) {
- return MOCK_HOOK_P3(GioMock, g_dbus_connection_flush_sync, arg1, arg2, arg3);
-}
+++ /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:
- GioMock() {
- using ::testing::_;
- using ::testing::Return;
- using ::testing::Invoke;
-
- // static int dummy;
- GDBusConnection *conn = reinterpret_cast<GDBusConnection *>(
- g_object_new(G_TYPE_OBJECT, nullptr));
-
- ON_CALL(*this, g_bus_get_sync(_, _, _))
- .WillByDefault(Return(conn));
- }
- virtual ~GioMock() {}
-
- MOCK_METHOD1(g_dbus_is_interface_name, gboolean(const gchar *));
- MOCK_METHOD3(g_bus_get_sync,
- GDBusConnection *(GBusType, GCancellable *, GError **));
- MOCK_METHOD7(g_bus_own_name_on_connection,
- guint(GDBusConnection *, const gchar *, GBusNameOwnerFlags,
- GBusNameAcquiredCallback, GBusNameLostCallback, gpointer,
- GDestroyNotify));
- 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_proxy_new_sync,
- GDBusProxy *(GDBusConnection *, GDBusProxyFlags,
- GDBusInterfaceInfo *, const gchar *, const gchar *,
- const gchar *, GCancellable *, GError **));
- MOCK_METHOD7(g_dbus_proxy_call_sync,
- GVariant *(GDBusProxy *, const gchar *, GVariant *,
- GDBusCallFlags, gint, GCancellable *, GError **));
- MOCK_METHOD7(g_dbus_connection_emit_signal,
- gboolean(GDBusConnection *, const gchar *, const gchar *,
- const gchar *, const gchar *, GVariant *, GError **));
- MOCK_METHOD2(g_dbus_connection_signal_unsubscribe,
- void(GDBusConnection *, guint));
- MOCK_METHOD3(g_dbus_connection_flush_sync,
- gboolean(GDBusConnection *, GCancellable *, GError **));
-};
-
-#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_
-CMAKE_MINIMUM_REQUIRED(VERSION 2.8)\r
-PROJECT(eventsystem-unittests C CXX)\r
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} UNIT_TEST_SRCS)\r
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/mock MOCK_SRCS)\r
\r
-INCLUDE(FindPkgConfig)\r
-PKG_CHECK_MODULES(eventsystem-unittests REQUIRED\r
- aul\r
- gmock\r
- dlog\r
- bundle\r
- glib-2.0\r
- gio-2.0\r
+ADD_EXECUTABLE(${TARGET_EVENTSYSTEM_UNITTESTS}\r
+ ${UNIT_TEST_SRCS}\r
+ ${MOCK_SRCS}\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
+APPLY_PKG_CONFIG(${TARGET_EVENTSYSTEM_UNITTESTS} PUBLIC\r
+ AUL_DEPS\r
+ BUNDLE_DEPS\r
+ DLOG_DEPS\r
+ GLIB_DEPS\r
+ GIO_DEPS\r
+ GMOCK_DEPS\r
+ PKGMGR_INFO_DEPS\r
)\r
\r
-SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${EXTRA_CFLAGS}")\r
-TARGET_LINK_LIBRARIES(${PROJECT_NAME}\r
- ${eventsystem-unittests_LDFLAGS}\r
+TARGET_INCLUDE_DIRECTORIES(${TARGET_EVENTSYSTEM_UNITTESTS} PUBLIC\r
+ ${CMAKE_CURRENT_SOURCE_DIR}\r
+ ${CMAKE_CURRENT_SOURCE_DIR}/src\r
+ ${CMAKE_CURRENT_SOURCE_DIR}/mock\r
+ ${CMAKE_CURRENT_SOURCE_DIR}/../\r
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../src\r
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../include\r
)\r
\r
-INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin/)\r
+TARGET_LINK_LIBRARIES(${TARGET_EVENTSYSTEM_UNITTESTS} PUBLIC\r
+ ${TARGET_EVENTSYSTEM})\r
+SET_TARGET_PROPERTIES(${TARGET_EVENTSYSTEM_UNITTESTS} PROPERTIES\r
+ COMPILE_FLAGS "-fPIE")\r
+SET_TARGET_PROPERTIES(${TARGET_EVENTSYSTEM_UNITTESTS} PROPERTIES\r
+ LINK_FLAGS "-pie")\r
+\r
+INSTALL(TARGETS ${TARGET_EVENTSYSTEM_UNITTESTS} DESTINATION bin)\r
--- /dev/null
+/*
+ * Copyright (c) 2022 - 2024 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/eventsystem.h"
+
+#include <aul.h>
+#include <dlog.h>
+#include <glib.h>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <memory>
+#include <string>
+
+#include "mock/aul_mock.hh"
+#include "mock/gio_mock.hh"
+#include "mock/libc_mock.hh"
+#include "mock/test_fixture.hh"
+
+// using namespace tizen_base;
+using ::testing::_;
+using ::testing::DoAll;
+using ::testing::Invoke;
+using ::testing::Return;
+using ::testing::SetArgPointee;
+
+#undef LOG_TAG
+#define LOG_TAG "ES_UNITTEST"
+
+namespace {
+
+gboolean FakeGDBusIsInterfaceName(const gchar* string) { return TRUE; }
+
+GDBusConnection* FakeGBusGetSync(GBusType type, GCancellable* cancellable,
+ GError** error) {
+ GDBusConnection* conn = reinterpret_cast<GDBusConnection*>(
+ g_object_new(G_TYPE_DBUS_CONNECTION, nullptr));
+ return conn;
+}
+
+guint FakeGDBusConnectionSignalSubscribe(
+ GDBusConnection* connection, const gchar* sender,
+ const gchar* interface_name, const gchar* member, const gchar* object_path,
+ const gchar* arg0, GDBusSignalFlags flags, GDBusSignalCallback callback,
+ gpointer user_data, GDestroyNotify user_data_free_func) {
+ return 1;
+}
+
+guint FakeGBusOwnNameOnConnection(
+ GDBusConnection* connection, const gchar* name, GBusNameOwnerFlags flags,
+ GBusNameAcquiredCallback name_acquired_handler,
+ GBusNameLostCallback name_lost_handler, gpointer user_data,
+ GDestroyNotify user_data_free_func) {
+ return 1;
+}
+
+GDBusProxy* FakeGDBusProxyNewSync(
+ GDBusConnection* connection, GDBusProxyFlags flags,
+ GDBusInterfaceInfo* info, const gchar* name, const gchar* object_path,
+ const gchar* interface_name, GCancellable* cancellable, GError** error) {
+ GDBusProxy* proxy =
+ reinterpret_cast<GDBusProxy*>(g_object_new(G_TYPE_OBJECT, nullptr));
+ return proxy;
+}
+
+GVariant* FakeGDBusProxyCallSync(GDBusProxy* proxy, const gchar* method_name,
+ GVariant* parameters, GDBusCallFlags flags,
+ gint timeout_msec, GCancellable* cancellable,
+ GError** error) {
+ *error = nullptr;
+ return g_variant_new("(i)", 1);
+}
+
+gboolean FakeGDBusConnectionEmitSignal(
+ GDBusConnection* connection, const gchar* destination_bus_name,
+ const gchar* object_path, const gchar* interface_name,
+ const gchar* signal_name, GVariant* parameters, GError** error) {
+ return TRUE;
+}
+
+void FakeGDBusConnectionSignalUnsubscribe(GDBusConnection* connection,
+ guint subscription_id) {
+}
+
+gboolean FakeGDBusConnectionFlushSync(GDBusConnection* connection,
+ GCancellable* cancellable,
+ GError** error) {
+ return TRUE;
+}
+
+int FakeAulAppGetAppidByPidForUid(int pid, char* appid, int len, uid_t uid) {
+ return AUL_R_OK;
+}
+
+int FakeGetUid(void) { return 5001; }
+
+} // namespace
+
+class Mocks : public ::testing::NiceMock<GioMock>,
+ public ::testing::NiceMock<AulMock>,
+ public ::testing::NiceMock<LibcMock> {};
+
+class EventSystemTest : public TestFixture {
+ public:
+ EventSystemTest() : TestFixture(std::make_unique<Mocks>()) {}
+ virtual ~EventSystemTest() {}
+
+ virtual void SetUp() { SetFakeFuncs(); }
+ virtual void TearDown() {}
+
+ void SetFakeFuncs() {
+ EXPECT_CALL(GetMock<GioMock>(), g_dbus_is_interface_name(_))
+ .WillRepeatedly(Invoke(FakeGDBusIsInterfaceName));
+ EXPECT_CALL(GetMock<GioMock>(), g_bus_get_sync(_, _, _))
+ .WillRepeatedly(Invoke(FakeGBusGetSync));
+ EXPECT_CALL(GetMock<GioMock>(),
+ g_bus_own_name_on_connection(_, _, _, _, _, _, _))
+ .WillRepeatedly(Invoke(FakeGBusOwnNameOnConnection));
+ EXPECT_CALL(GetMock<GioMock>(), g_dbus_connection_signal_subscribe(
+ _, _, _, _, _, _, _, _, _, _))
+ .WillRepeatedly(Invoke(FakeGDBusConnectionSignalSubscribe));
+ EXPECT_CALL(GetMock<GioMock>(),
+ g_dbus_proxy_new_sync(_, _, _, _, _, _, _, _))
+ .WillRepeatedly(Invoke(FakeGDBusProxyNewSync));
+ EXPECT_CALL(GetMock<GioMock>(), g_dbus_proxy_call_sync(_, _, _, _, _, _, _))
+ .WillRepeatedly(Invoke(FakeGDBusProxyCallSync));
+ EXPECT_CALL(GetMock<GioMock>(),
+ g_dbus_connection_emit_signal(_, _, _, _, _, _, _))
+ .WillRepeatedly(Invoke(FakeGDBusConnectionEmitSignal));
+ EXPECT_CALL(GetMock<GioMock>(), g_dbus_connection_signal_unsubscribe(_, _))
+ .WillRepeatedly(Invoke(FakeGDBusConnectionSignalUnsubscribe));
+ EXPECT_CALL(GetMock<GioMock>(), g_dbus_connection_flush_sync(_, _, _))
+ .WillRepeatedly(Invoke(FakeGDBusConnectionFlushSync));
+
+ EXPECT_CALL(GetMock<AulMock>(), aul_app_get_appid_bypid_for_uid(_, _, _, _))
+ .WillRepeatedly(Invoke(FakeAulAppGetAppidByPidForUid));
+
+ EXPECT_CALL(GetMock<LibcMock>(), getuid())
+ .WillRepeatedly(Invoke(FakeGetUid));
+ }
+};
+
+static void UserEventCb(const char* event_name, bundle* data, void* user_data) {
+}
+
+static void SystemEventCb(const char* event_name, bundle_raw* event_data,
+ int len, void* user_data) {}
+
+TEST_F(EventSystemTest, eventsystem_register_system_event) {
+ unsigned int id;
+ int ret = eventsystem_register_event("tizen.system.event.test", &id,
+ UserEventCb, nullptr);
+ EXPECT_EQ(ret, ES_R_OK);
+}
+
+TEST_F(EventSystemTest, eventsystem_register_user_event) {
+ unsigned int id;
+ int ret = eventsystem_register_event("event.test", &id, UserEventCb, nullptr);
+ EXPECT_EQ(ret, ES_R_OK);
+}
+
+TEST_F(EventSystemTest, eventsystem_unregister_event) {
+ unsigned int id;
+ int ret = eventsystem_register_event("tizen.system.event.test", &id,
+ UserEventCb, nullptr);
+ EXPECT_EQ(ret, ES_R_OK);
+
+ ret = eventsystem_unregister_event(id);
+ EXPECT_EQ(ret, ES_R_OK);
+}
+
+TEST_F(EventSystemTest, eventsystem_send_user_event) {
+ bundle* data = bundle_create();
+ int ret = eventsystem_send_user_event("event.test", data, false);
+ EXPECT_EQ(ret, ES_R_OK);
+}
+
+TEST_F(EventSystemTest, eventsystem_send_system_event) {
+ bundle* data = bundle_create();
+ int ret = eventsystem_send_system_event("tizen.system.event.test", data);
+ EXPECT_EQ(ret, ES_R_OK);
+}
+
+TEST_F(EventSystemTest, eventsystem_request_sending_system_event) {
+ bundle* data = bundle_create();
+ int ret = eventsystem_request_sending_system_event("event.test", data);
+ EXPECT_EQ(ret, ES_R_OK);
+}
+
+TEST_F(EventSystemTest, eventsystem_register_application_event) {
+ EXPECT_CALL(GetMock<GioMock>(), g_dbus_proxy_call_sync(_, _, _, _, _, _, _))
+ .WillOnce(Invoke([&](GDBusProxy* p, const gchar* method, GVariant* v,
+ GDBusCallFlags flag, gint msec, GCancellable* c,
+ GError** e) -> GVariant* {
+ *e = nullptr;
+ return g_variant_new("(i)", 1);
+ }))
+ .WillOnce(Invoke([&](GDBusProxy* p, const gchar* method, GVariant* v,
+ GDBusCallFlags flag, gint msec, GCancellable* c,
+ GError** e) -> GVariant* {
+ *e = nullptr;
+ return g_variant_new("(iis)", 1, 1, "a");
+ }));
+ unsigned int id;
+ int type;
+ int ret = eventsystem_register_application_event(
+ "tizen.system.event.test", &id, &type, SystemEventCb, NULL);
+ EXPECT_EQ(ret, ES_R_OK);
+}
+
+TEST_F(EventSystemTest, eventsystem_unregister_application_event) {
+ EXPECT_CALL(GetMock<GioMock>(), g_dbus_proxy_call_sync(_, _, _, _, _, _, _))
+ .WillOnce(Invoke([&](GDBusProxy* p, const gchar* method, GVariant* v,
+ GDBusCallFlags flag, gint msec, GCancellable* c,
+ GError** e) -> GVariant* {
+ *e = nullptr;
+ return g_variant_new("(i)", 1);
+ }))
+ .WillOnce(Invoke([&](GDBusProxy* p, const gchar* method, GVariant* v,
+ GDBusCallFlags flag, gint msec, GCancellable* c,
+ GError** e) -> GVariant* {
+ *e = nullptr;
+ return g_variant_new("(iis)", 1, 1, "a");
+ }));
+
+ unsigned int id;
+ int type;
+ int ret = eventsystem_register_application_event(
+ "tizen.system.event.test", &id, &type, SystemEventCb, NULL);
+ EXPECT_EQ(ret, ES_R_OK);
+
+ ret = eventsystem_unregister_application_event(id);
+ EXPECT_EQ(ret, ES_R_OK);
+}
+
+TEST_F(EventSystemTest, eventsystem_keep_last_event_data) {
+ EXPECT_CALL(GetMock<GioMock>(), g_dbus_proxy_call_sync(_, _, _, _, _, _, _))
+ .WillRepeatedly(Invoke([&](GDBusProxy* p, const gchar* method,
+ GVariant* v, GDBusCallFlags flag, gint msec,
+ GCancellable* c, GError** e) -> GVariant* {
+ *e = nullptr;
+ return g_variant_new("(i)", 0);
+ }));
+
+ int ret = eventsystem_keep_last_event_data("tizen.system.event.test");
+ EXPECT_EQ(ret, ES_R_OK);
+}
+
+TEST_F(EventSystemTest, eventsystem_application_finalize) {
+ int ret = eventsystem_application_finalize();
+ EXPECT_EQ(ret, ES_R_OK);
+}
--- /dev/null
+/*
+ * Copyright (c) 2022 - 2024 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 <dlog.h>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+// LCOV_EXCL_START
+extern "C" int __dlog_sec_print(log_id_t log_id, int prio, const char* tag,
+ const char* fmt, ...) {
+ printf("%s:", tag);
+ va_list ap;
+ va_start(ap, fmt);
+ vprintf(fmt, ap);
+ va_end(ap);
+ printf("\n");
+ return 0;
+}
+
+extern "C" int dlog_vprint(log_priority prio, const char* tag, const char* fmt,
+ va_list ap) {
+ printf("%s:", tag);
+ vprintf(fmt, ap);
+ printf("\n");
+ return 0;
+}
+
+extern "C" int __dlog_print(log_id_t log_id, int prio, const char* tag,
+ const char* fmt, ...) {
+ printf("%s:", tag);
+ va_list ap;
+ va_start(ap, fmt);
+ vprintf(fmt, ap);
+ va_end(ap);
+ printf("\n");
+ return 0;
+}
+// LCOV_EXCL_STOP
+
+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;
+}
--- /dev/null
+/*
+ * Copyright (c) 2024 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 "mock/aul_mock.hh"
+
+#include "mock/mock_hook.hh"
+#include "mock/test_fixture.hh"
+
+extern "C" int aul_app_get_appid_bypid_for_uid(int pid, char* appid, int len,
+ uid_t uid) {
+ return MOCK_HOOK_P4(AulMock, aul_app_get_appid_bypid_for_uid, pid, appid,
+ len, uid);
+}
--- /dev/null
+/*
+ * Copyright (c) 2024 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_AUL_MOCK_HH_
+#define UNIT_TESTS_MOCK_AUL_MOCK_HH_
+
+#include <aul.h>
+#include <gmock/gmock.h>
+
+#include "mock/module_mock.hh"
+
+class AulMock : public virtual ModuleMock {
+ public:
+ AulMock() {}
+ virtual ~AulMock() {}
+
+ MOCK_METHOD4(aul_app_get_appid_bypid_for_uid, int(int, char*, int, uid_t));
+};
+
+#endif // UNIT_TESTS_MOCK_AUL_MOCK_HH_
--- /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 "mock/gio_mock.hh"
+
+#include "mock/mock_hook.hh"
+#include "mock/test_fixture.hh"
+
+extern "C" gboolean g_dbus_is_interface_name(const gchar* arg0) {
+ return MOCK_HOOK_P1(GioMock, g_dbus_is_interface_name, arg0);
+}
+
+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" 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" guint g_bus_own_name_on_connection(GDBusConnection* arg0,
+ const gchar* arg1, GBusNameOwnerFlags arg2, GBusNameAcquiredCallback arg3,
+ GBusNameLostCallback arg4, gpointer arg5, GDestroyNotify arg6) {
+ return MOCK_HOOK_P7(GioMock, g_bus_own_name_on_connection,
+ arg0, arg1, arg2, arg3, arg4, arg5, arg6);
+}
+
+extern "C" GDBusProxy* g_dbus_proxy_new_sync(GDBusConnection* arg0,
+ GDBusProxyFlags arg1, GDBusInterfaceInfo* arg2, const gchar* arg3,
+ const gchar* arg4, const gchar* arg5, GCancellable* arg6, GError** arg7) {
+ return MOCK_HOOK_P8(GioMock, g_dbus_proxy_new_sync,
+ arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
+}
+
+extern "C" GVariant* g_dbus_proxy_call_sync(GDBusProxy* arg1,
+ const gchar* arg2, GVariant* arg3, GDBusCallFlags arg4, gint arg5,
+ GCancellable* arg6, GError** arg7) {
+ return MOCK_HOOK_P7(GioMock, g_dbus_proxy_call_sync, arg1, arg2,
+ arg3, arg4, arg5, arg6, arg7);
+}
+
+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_connection_signal_unsubscribe(
+ GDBusConnection* arg0, guint arg1) {
+ return MOCK_HOOK_P2(GioMock, g_dbus_connection_signal_unsubscribe,
+ arg0, arg1);
+}
+
+extern "C" gboolean g_dbus_connection_flush_sync(GDBusConnection* arg1,
+ GCancellable* arg2,
+ GError** arg3) {
+ return MOCK_HOOK_P3(GioMock, g_dbus_connection_flush_sync, arg1, arg2, arg3);
+}
--- /dev/null
+/*
+ * Copyright (c) 2022 - 2024 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_GIO_MOCK_HH_
+#define UNIT_TESTS_MOCK_GIO_MOCK_HH_
+
+#include <gio/gio.h>
+#include <gmock/gmock.h>
+
+#include "mock/module_mock.hh"
+
+class GioMock : public virtual ModuleMock {
+ public:
+ GioMock() {}
+ virtual ~GioMock() {}
+
+ MOCK_METHOD1(g_dbus_is_interface_name, gboolean(const gchar *));
+ MOCK_METHOD3(g_bus_get_sync,
+ GDBusConnection *(GBusType, GCancellable *, GError **));
+ MOCK_METHOD7(g_bus_own_name_on_connection,
+ guint(GDBusConnection *, const gchar *, GBusNameOwnerFlags,
+ GBusNameAcquiredCallback, GBusNameLostCallback, gpointer,
+ GDestroyNotify));
+ 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_proxy_new_sync,
+ GDBusProxy *(GDBusConnection *, GDBusProxyFlags,
+ GDBusInterfaceInfo *, const gchar *, const gchar *,
+ const gchar *, GCancellable *, GError **));
+ MOCK_METHOD7(g_dbus_proxy_call_sync,
+ GVariant *(GDBusProxy *, const gchar *, GVariant *,
+ GDBusCallFlags, gint, GCancellable *, GError **));
+ MOCK_METHOD7(g_dbus_connection_emit_signal,
+ gboolean(GDBusConnection *, const gchar *, const gchar *,
+ const gchar *, const gchar *, GVariant *, GError **));
+ MOCK_METHOD2(g_dbus_connection_signal_unsubscribe,
+ void(GDBusConnection *, guint));
+ MOCK_METHOD3(g_dbus_connection_flush_sync,
+ gboolean(GDBusConnection *, GCancellable *, GError **));
+};
+
+#endif // UNIT_TESTS_MOCK_GIO_MOCK_HH_
--- /dev/null
+/*
+ * Copyright (c) 2024 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 "mock/libc_mock.hh"
+
+#include "mock/mock_hook.hh"
+#include "mock/test_fixture.hh"
+
+extern "C" uid_t getuid(void) { return MOCK_HOOK_P0(LibcMock, getuid); }
--- /dev/null
+/*
+ * Copyright (c) 2024 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_LIBC_MOCK_HH_
+#define UNIT_TESTS_MOCK_LIBC_MOCK_HH_
+
+#include <unistd.h>
+#include <gmock/gmock.h>
+
+#include "mock/module_mock.hh"
+
+class LibcMock : public virtual ModuleMock {
+ public:
+ LibcMock() {}
+ virtual ~LibcMock() {}
+
+ MOCK_METHOD0(getuid, uid_t(void));
+};
+
+#endif // UNIT_TESTS_MOCK_LIBC_MOCK_HH_
--- /dev/null
+/*
+ * Copyright (c) 2022 - 2024 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_MOCK_HOOK_HH_
+#define UNIT_TESTS_MOCK_MOCK_HOOK_HH_
+
+#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 // UNIT_TESTS_MOCK_MOCK_HOOK_HH_
--- /dev/null
+/*
+ * Copyright (c) 2022 - 2024 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_MODULE_MOCK_HH_
+#define UNIT_TESTS_MOCK_MODULE_MOCK_HH_
+
+class ModuleMock {
+ public:
+ virtual ~ModuleMock() {}
+};
+
+#endif // UNIT_TESTS_MOCK_MODULE_MOCK_HH_
--- /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 "mock/test_fixture.hh"
+
+#include <memory>
+
+std::unique_ptr<ModuleMock> TestFixture::mock_;
--- /dev/null
+/*
+ * Copyright (c) 2022 - 2024 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_TEST_FIXTURE_HH_
+#define UNIT_TESTS_MOCK_TEST_FIXTURE_HH_
+
+#include <gtest/gtest.h>
+
+#include <memory>
+#include <stdexcept>
+#include <string>
+#include <utility>
+
+#include "mock/module_mock.hh"
+
+class TestFixture : public ::testing::Test {
+ public:
+ explicit TestFixture(std::unique_ptr<ModuleMock> mock) {
+ mock_ = std::move(mock);
+ }
+
+ virtual ~TestFixture() {}
+
+ virtual void SetUp() {}
+ virtual void TearDown() {}
+
+ template <typename T>
+ static T& GetMock() {
+ auto ptr = dynamic_cast<T*>(mock_.get());
+ if (ptr == nullptr) {
+ throw std::invalid_argument("The test does not provide mock of \"" +
+ std::string(typeid(T).name()) + "\"");
+ }
+
+ return *ptr;
+ }
+
+ static std::unique_ptr<ModuleMock> mock_;
+};
+
+#endif // UNIT_TESTS_MOCK_TEST_FIXTURE_HH_
+++ /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 <aul.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::Invoke;
-using ::testing::Return;
-using ::testing::SetArgPointee;
-
-extern "C" uid_t getuid() { return 5001; }
-
-extern "C" int aul_app_get_appid_bypid_for_uid(int pid, char* appid, int len,
- uid_t uid) {
- return AUL_R_OK;
-}
-
-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() {}
-};
-
-static void callback(const char* event_name, bundle* data, void* user_data) {}
-
-static void system_callback(const char* event_name, bundle_raw* event_data,
- int len, void* user_data) {}
-
-TEST_F(EventSystemTest, eventsystem_register_system_event) {
- EXPECT_CALL(GetMock<GioMock>(), g_dbus_is_interface_name(_))
- .WillOnce(Return(true));
- EXPECT_CALL(GetMock<GioMock>(),
- g_dbus_connection_signal_subscribe(_, _, _, _, _, _, _, _, _, _))
- .WillOnce(Return(1));
- EXPECT_CALL(GetMock<GioMock>(), g_bus_get_sync(_, _, _))
- .WillOnce(Invoke([&](GBusType type, GCancellable* cancellable,
- GError** error) -> GDBusConnection* {
- GDBusConnection* con = reinterpret_cast<GDBusConnection*>(
- g_object_new(G_TYPE_DBUS_CONNECTION, nullptr));
- return con;
- }));
- EXPECT_CALL(GetMock<GioMock>(),
- g_bus_own_name_on_connection(_, _, _, _, _, _, _))
- .WillOnce(Return(1));
-
- unsigned int id;
- int ret = eventsystem_register_event("tizen.system.event.test", &id, callback,
- nullptr);
- EXPECT_EQ(ret, ES_R_OK);
-}
-
-TEST_F(EventSystemTest, eventsystem_register_user_event) {
- EXPECT_CALL(GetMock<GioMock>(), g_dbus_is_interface_name(_))
- .WillRepeatedly(Return(true));
- EXPECT_CALL(GetMock<GioMock>(),
- g_dbus_connection_signal_subscribe(_, _, _, _, _, _, _, _, _, _))
- .WillOnce(Return(1));
- EXPECT_CALL(GetMock<GioMock>(), g_bus_get_sync(_, _, _))
- .WillRepeatedly(Invoke([&](GBusType type, GCancellable* cancellable,
- GError** error) -> GDBusConnection* {
- GDBusConnection* con = reinterpret_cast<GDBusConnection*>(
- g_object_new(G_TYPE_DBUS_CONNECTION, nullptr));
- return con;
- }));
-
- unsigned int id;
- int ret = eventsystem_register_event("event.test", &id, callback, nullptr);
- EXPECT_EQ(ret, ES_R_OK);
-}
-
-TEST_F(EventSystemTest, eventsystem_unregister_event) {
- EXPECT_CALL(GetMock<GioMock>(), g_dbus_is_interface_name(_))
- .WillOnce(Return(true));
- EXPECT_CALL(GetMock<GioMock>(),
- g_dbus_connection_signal_subscribe(_, _, _, _, _, _, _, _, _, _))
- .WillOnce(Return(1));
- EXPECT_CALL(GetMock<GioMock>(), g_bus_get_sync(_, _, _))
- .WillRepeatedly(Invoke([&](GBusType type, GCancellable* cancellable,
- GError** error) -> GDBusConnection* {
- GDBusConnection* con = reinterpret_cast<GDBusConnection*>(
- g_object_new(G_TYPE_DBUS_CONNECTION, nullptr));
- return con;
- }));
-
- unsigned int id;
- int ret = eventsystem_register_event("tizen.system.event.test", &id, callback,
- nullptr);
- EXPECT_EQ(ret, ES_R_OK);
-
- ret = eventsystem_unregister_event(id);
- EXPECT_EQ(ret, ES_R_OK);
-}
-
-TEST_F(EventSystemTest, eventsystem_send_user_event) {
- EXPECT_CALL(GetMock<GioMock>(), g_bus_get_sync(_, _, _))
- .WillRepeatedly(Invoke([&](GBusType type, GCancellable* cancellable,
- GError** error) -> GDBusConnection* {
- GDBusConnection* con = reinterpret_cast<GDBusConnection*>(
- g_object_new(G_TYPE_DBUS_CONNECTION, nullptr));
- return con;
- }));
- EXPECT_CALL(GetMock<GioMock>(),
- g_bus_own_name_on_connection(_, _, _, _, _, _, _))
- .WillRepeatedly(Return(1));
- EXPECT_CALL(GetMock<GioMock>(), g_dbus_proxy_new_sync(_, _, _, _, _, _, _, _))
- .WillRepeatedly(Invoke([&](GDBusConnection* con, GDBusProxyFlags flag,
- GDBusInterfaceInfo* info, const gchar* name,
- const gchar* path, const gchar* interface,
- GCancellable* cancellable,
- GError** error) -> GDBusProxy* {
- GDBusProxy* proxy =
- reinterpret_cast<GDBusProxy*>(g_object_new(G_TYPE_OBJECT, nullptr));
- return proxy;
- }));
- EXPECT_CALL(GetMock<GioMock>(), g_dbus_proxy_call_sync(_, _, _, _, _, _, _))
- .WillRepeatedly(Invoke([&](GDBusProxy* p, const gchar* method,
- GVariant* v, GDBusCallFlags flag, gint msec,
- GCancellable* c, GError** e) -> GVariant* {
- *e = nullptr;
- return g_variant_new("(i)", 1);
- }));
- EXPECT_CALL(GetMock<GioMock>(),
- g_dbus_connection_emit_signal(_, _, _, _, _, _, _))
- .WillRepeatedly(Return(TRUE));
-
- bundle* data = bundle_create();
- int ret = eventsystem_send_user_event("event.test", data, false);
- EXPECT_EQ(ret, ES_R_OK);
-}
-
-TEST_F(EventSystemTest, eventsystem_send_system_event) {
- EXPECT_CALL(GetMock<GioMock>(), g_dbus_is_interface_name(_))
- .WillOnce(Return(true));
- EXPECT_CALL(GetMock<GioMock>(),
- g_bus_own_name_on_connection(_, _, _, _, _, _, _))
- .WillRepeatedly(Return(1));
- EXPECT_CALL(GetMock<GioMock>(),
- g_dbus_connection_emit_signal(_, _, _, _, _, _, _))
- .WillRepeatedly(Return(TRUE));
- EXPECT_CALL(GetMock<GioMock>(), g_dbus_connection_flush_sync(_, _, _))
- .WillRepeatedly(Return(TRUE));
-
- bundle* data = bundle_create();
- int ret = eventsystem_send_system_event("tizen.system.event.test", data);
- EXPECT_EQ(ret, ES_R_OK);
-}
-
-TEST_F(EventSystemTest, eventsystem_request_sending_system_event) {
- EXPECT_CALL(GetMock<GioMock>(),
- g_bus_own_name_on_connection(_, _, _, _, _, _, _))
- .WillRepeatedly(Return(1));
- EXPECT_CALL(GetMock<GioMock>(), g_dbus_proxy_new_sync(_, _, _, _, _, _, _, _))
- .WillRepeatedly(Invoke([&](GDBusConnection* con, GDBusProxyFlags flag,
- GDBusInterfaceInfo* info, const gchar* name,
- const gchar* path, const gchar* interface,
- GCancellable* cancellable,
- GError** error) -> GDBusProxy* {
- GDBusProxy* proxy =
- reinterpret_cast<GDBusProxy*>(g_object_new(G_TYPE_OBJECT, nullptr));
- return proxy;
- }));
- EXPECT_CALL(GetMock<GioMock>(), g_dbus_proxy_call_sync(_, _, _, _, _, _, _))
- .WillRepeatedly(Invoke([&](GDBusProxy* p, const gchar* method,
- GVariant* v, GDBusCallFlags flag, gint msec,
- GCancellable* c, GError** e) -> GVariant* {
- *e = nullptr;
- return g_variant_new("(i)", 1);
- }));
- EXPECT_CALL(GetMock<GioMock>(),
- g_dbus_connection_emit_signal(_, _, _, _, _, _, _))
- .WillRepeatedly(Return(TRUE));
-
- bundle* data = bundle_create();
- int ret = eventsystem_request_sending_system_event("event.test", data);
- EXPECT_EQ(ret, ES_R_OK);
-}
-
-TEST_F(EventSystemTest, eventsystem_register_application_event) {
- EXPECT_CALL(GetMock<GioMock>(), g_bus_get_sync(_, _, _))
- .WillRepeatedly(Invoke([&](GBusType type, GCancellable* cancellable,
- GError** error) -> GDBusConnection* {
- GDBusConnection* con = reinterpret_cast<GDBusConnection*>(
- g_object_new(G_TYPE_DBUS_CONNECTION, nullptr));
- return con;
- }));
- EXPECT_CALL(GetMock<GioMock>(), g_dbus_is_interface_name(_))
- .WillOnce(Return(true));
- EXPECT_CALL(GetMock<GioMock>(),
- g_dbus_connection_signal_subscribe(_, _, _, _, _, _, _, _, _, _))
- .WillOnce(Return(1));
- EXPECT_CALL(GetMock<GioMock>(),
- g_bus_own_name_on_connection(_, _, _, _, _, _, _))
- .WillRepeatedly(Return(1));
- EXPECT_CALL(GetMock<GioMock>(), g_dbus_proxy_new_sync(_, _, _, _, _, _, _, _))
- .WillRepeatedly(Invoke([&](GDBusConnection* con, GDBusProxyFlags flag,
- GDBusInterfaceInfo* info, const gchar* name,
- const gchar* path, const gchar* interface,
- GCancellable* cancellable,
- GError** error) -> GDBusProxy* {
- GDBusProxy* proxy =
- reinterpret_cast<GDBusProxy*>(g_object_new(G_TYPE_OBJECT, nullptr));
- return proxy;
- }));
- EXPECT_CALL(GetMock<GioMock>(), g_dbus_proxy_call_sync(_, _, _, _, _, _, _))
- .WillOnce(Invoke([&](GDBusProxy* p, const gchar* method, GVariant* v,
- GDBusCallFlags flag, gint msec, GCancellable* c,
- GError** e) -> GVariant* {
- *e = nullptr;
- return g_variant_new("(i)", 1);
- }))
- .WillOnce(Invoke([&](GDBusProxy* p, const gchar* method, GVariant* v,
- GDBusCallFlags flag, gint msec, GCancellable* c,
- GError** e) -> GVariant* {
- *e = nullptr;
- return g_variant_new("(iis)", 1, 1, "a");
- }));
- unsigned int id;
- int type;
- int ret = eventsystem_register_application_event(
- "tizen.system.event.test", &id, &type, system_callback, NULL);
- EXPECT_EQ(ret, ES_R_OK);
-}
-
-TEST_F(EventSystemTest, eventsystem_unregister_application_event) {
- EXPECT_CALL(GetMock<GioMock>(), g_bus_get_sync(_, _, _))
- .WillRepeatedly(Invoke([&](GBusType type, GCancellable* cancellable,
- GError** error) -> GDBusConnection* {
- GDBusConnection* con = reinterpret_cast<GDBusConnection*>(
- g_object_new(G_TYPE_DBUS_CONNECTION, nullptr));
- return con;
- }));
- EXPECT_CALL(GetMock<GioMock>(), g_dbus_is_interface_name(_))
- .WillOnce(Return(true));
- EXPECT_CALL(GetMock<GioMock>(),
- g_dbus_connection_signal_subscribe(_, _, _, _, _, _, _, _, _, _))
- .WillOnce(Return(1));
- EXPECT_CALL(GetMock<GioMock>(),
- g_bus_own_name_on_connection(_, _, _, _, _, _, _))
- .WillRepeatedly(Return(1));
- EXPECT_CALL(GetMock<GioMock>(), g_dbus_proxy_new_sync(_, _, _, _, _, _, _, _))
- .WillRepeatedly(Invoke([&](GDBusConnection* con, GDBusProxyFlags flag,
- GDBusInterfaceInfo* info, const gchar* name,
- const gchar* path, const gchar* interface,
- GCancellable* cancellable,
- GError** error) -> GDBusProxy* {
- GDBusProxy* proxy =
- reinterpret_cast<GDBusProxy*>(g_object_new(G_TYPE_OBJECT, nullptr));
- return proxy;
- }));
- EXPECT_CALL(GetMock<GioMock>(), g_dbus_proxy_call_sync(_, _, _, _, _, _, _))
- .WillOnce(Invoke([&](GDBusProxy* p, const gchar* method, GVariant* v,
- GDBusCallFlags flag, gint msec, GCancellable* c,
- GError** e) -> GVariant* {
- *e = nullptr;
- return g_variant_new("(i)", 1);
- }))
- .WillOnce(Invoke([&](GDBusProxy* p, const gchar* method, GVariant* v,
- GDBusCallFlags flag, gint msec, GCancellable* c,
- GError** e) -> GVariant* {
- *e = nullptr;
- return g_variant_new("(iis)", 1, 1, "a");
- }));
-
- unsigned int id;
- int type;
- int ret = eventsystem_register_application_event(
- "tizen.system.event.test", &id, &type, system_callback, NULL);
- EXPECT_EQ(ret, ES_R_OK);
-
- ret = eventsystem_unregister_application_event(id);
- EXPECT_EQ(ret, ES_R_OK);
-}
-
-TEST_F(EventSystemTest, eventsystem_keep_last_event_data) {
- EXPECT_CALL(GetMock<GioMock>(), g_bus_get_sync(_, _, _))
- .WillRepeatedly(Invoke([&](GBusType type, GCancellable* cancellable,
- GError** error) -> GDBusConnection* {
- GDBusConnection* con = reinterpret_cast<GDBusConnection*>(
- g_object_new(G_TYPE_DBUS_CONNECTION, nullptr));
- return con;
- }));
- EXPECT_CALL(GetMock<GioMock>(), g_dbus_is_interface_name(_))
- .WillOnce(Return(true));
- EXPECT_CALL(GetMock<GioMock>(),
- g_dbus_connection_signal_subscribe(_, _, _, _, _, _, _, _, _, _))
- .WillOnce(Return(1));
- EXPECT_CALL(GetMock<GioMock>(),
- g_bus_own_name_on_connection(_, _, _, _, _, _, _))
- .WillRepeatedly(Return(1));
- EXPECT_CALL(GetMock<GioMock>(), g_dbus_proxy_new_sync(_, _, _, _, _, _, _, _))
- .WillRepeatedly(Invoke([&](GDBusConnection* con, GDBusProxyFlags flag,
- GDBusInterfaceInfo* info, const gchar* name,
- const gchar* path, const gchar* interface,
- GCancellable* cancellable,
- GError** error) -> GDBusProxy* {
- GDBusProxy* proxy =
- reinterpret_cast<GDBusProxy*>(g_object_new(G_TYPE_OBJECT, nullptr));
- return proxy;
- }));
- EXPECT_CALL(GetMock<GioMock>(), g_dbus_proxy_call_sync(_, _, _, _, _, _, _))
- .WillRepeatedly(Invoke([&](GDBusProxy* p, const gchar* method,
- GVariant* v, GDBusCallFlags flag, gint msec,
- GCancellable* c, GError** e) -> GVariant* {
- *e = nullptr;
- return g_variant_new("(i)", 0);
- }));
-
- int ret = eventsystem_keep_last_event_data("tizen.system.event.test");
- EXPECT_EQ(ret, ES_R_OK);
-}
-
-TEST_F(EventSystemTest, eventsystem_application_finalize) {
- int ret = eventsystem_application_finalize();
- EXPECT_EQ(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;
-}