CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
-PROJECT(capi-system-media-key CXX)
-INCLUDE(FindPkgConfig)
-
-SET(requires "dlog capi-base-common ecore ecore-input evas ecore-wl2")
-SET(pc_requires "capi-base-common")
+PROJECT(capi-system-media-key)
-PKG_CHECK_MODULES(capi-system-media-key REQUIRED ${requires})
+SET(CMAKE_INSTALL_PREFIX /usr)
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(PC_PREFIX ${PREFIX})
+SET(PC_NAME "capi-system-media-key")
+SET(PC_REQUIRED "capi-base-common")
+SET(PC_LDFLAGS "-lcapi-system-media-key")
-FOREACH(flag ${capi-system-media-key_CFLAGS})
- SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
-SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Werror -Winline")
+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 "${CMAKE_C_FLAGS} -Wno-error=deprecated-declarations")
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
+SET(CMAKE_C_FLAGS_RELEASE "-O2")
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=c++14")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_C_FLAGS} -fPIC")
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
SET(CMAKE_CXX_FLAGS_RELEASE "-O2")
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
+ "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SOURCES)
-ADD_LIBRARY(${PROJECT_NAME} SHARED ${SOURCES})
+SET(TARGET_MEDIA_KEY "capi-system-media-key")
-SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${MAJORVER})
-SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${FULLVER})
-
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${capi-system-media-key_LDFLAGS})
+INCLUDE(FindPkgConfig)
+INCLUDE(ApplyPkgConfig)
-SET(PC_NAME capi-system-media-key)
-SET(PC_REQUIRED ${pc_requires})
-SET(PC_LDFLAGS -lcapi-system-media-key)
-SET(PC_CFLAGS -I\${includedir}/system)
+PKG_CHECK_MODULES(DLOG_DEPS REQUIRED dlog)
+PKG_CHECK_MODULES(CAPI_BASE_COMMON_DEPS REQUIRED capi-base-common)
+PKG_CHECK_MODULES(ECORE_DEPS REQUIRED ecore)
+PKG_CHECK_MODULES(ECORE_INPUT_DEPS REQUIRED ecore-input)
+PKG_CHECK_MODULES(EVAS_DEPS REQUIRED evas)
+PKG_CHECK_MODULES(ECORE_WL2_DEPS REQUIRED ecore-wl2)
+PKG_CHECK_MODULES(GLIB_DEPS REQUIRED glib-2.0)
+PKG_CHECK_MODULES(GMOCK_DEPS REQUIRED gmock)
-CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY)
-SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${PROJECT_NAME}.pc")
+CONFIGURE_FILE(${TARGET_MEDIA_KEY}.pc.in ${TARGET_MEDIA_KEY}.pc @ONLY)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_MEDIA_KEY}.pc
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
-INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR})
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
- DESTINATION include/system
- FILES_MATCHING PATTERN "*.h")
+ DESTINATION include/system
+ FILES_MATCHING PATTERN "*.h")
-ADD_SUBDIRECTORY(unittest)
\ No newline at end of file
+ADD_SUBDIRECTORY(src)
+ADD_SUBDIRECTORY(tests)
\ No newline at end of file
includedir=/usr/include/system
Name: @PC_NAME@
-Description: @PACKAGE_DESCRIPTION@
+Description: Media Key Library
Version: @VERSION@
Requires: @PC_REQUIRED@
Libs: -L${libdir} @PC_LDFLAGS@
--- /dev/null
+# Copyright (c) 2023 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)
+++ /dev/null
-/*
- * Copyright (c) 2020 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 "ecore_wl2_mock.h"
-
-#include <gio/gio.h>
-
-#include "mock_hook.h"
-#include "test_fixture.h"
-
-
-extern "C" Eina_Bool ecore_wl2_window_keygrab_set(Ecore_Wl2_Window* win, const char* key, int mod, int not_mod, int priority, Ecore_Wl2_Window_Keygrab_Mode grab_mode) {
- return MOCK_HOOK_P6(EcoreWl2Mock, ecore_wl2_window_keygrab_set, win, key, mod, not_mod, priority, grab_mode);
-}
-
-extern "C" Ecore_Event_Handler* ecore_event_handler_add(int type, Ecore_Event_Handler_Cb func, const void* data) {
- return MOCK_HOOK_P3(EcoreWl2Mock, ecore_event_handler_add, type, func, data);
-}
-
-extern "C" void* ecore_event_handler_del(Ecore_Event_Handler* event_handler) {
- return MOCK_HOOK_P1(EcoreWl2Mock, ecore_event_handler_del, event_handler);
-}
-
-extern "C" Eina_Bool ecore_wl2_window_keygrab_unset(Ecore_Wl2_Window* win, const char* key, int mod, int any_mod) {
- return MOCK_HOOK_P4(EcoreWl2Mock, ecore_wl2_window_keygrab_unset, win, key, mod, any_mod);
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2020 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_ECORE_WL2_MOCK_H_
-#define UNIT_TESTS_MOCK_ECORE_WL2_MOCK_H_
-
-#include <gmock/gmock.h>
-#include <Eina.h>
-#include <Ecore.h>
-#include <Ecore_Wl2.h>
-
-#include "module_mock.h"
-
-typedef Eina_Bool(*Ecore_Event_Handler_Cb)(
- void* data, int type, void* event);
-
-class EcoreWl2Mock : public virtual ModuleMock {
- public:
- virtual ~EcoreWl2Mock() {}
-
- MOCK_METHOD6(ecore_wl2_window_keygrab_set,
- Eina_Bool (Ecore_Wl2_Window*, const char*, int, int, int, Ecore_Wl2_Window_Keygrab_Mode));
- MOCK_METHOD3(ecore_event_handler_add,
- Ecore_Event_Handler* (int, Ecore_Event_Handler_Cb, const void*));
- MOCK_METHOD1(ecore_event_handler_del,
- void*(Ecore_Event_Handler*));
- MOCK_METHOD4(ecore_wl2_window_keygrab_unset,
- Eina_Bool(Ecore_Wl2_Window*, const char*, int , int));
-};
-
-#endif // UNIT_TESTS_MOCK_ECORE_WL2_MOCK_H_
+++ /dev/null
-/*
- * Copyright (c) 2020 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_H_
-#define UNIT_TESTS_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 // UNIT_TESTS_MOCK_MOCK_HOOK_H_
+++ /dev/null
-/*
- * Copyright (c) 2020 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_H_
-#define UNIT_TESTS_MOCK_MODULE_MOCK_H_
-
-class ModuleMock {
- public:
- virtual ~ModuleMock() {}
-};
-
-#endif // UNIT_TESTS_MOCK_MODULE_MOCK_H_
+++ /dev/null
-/*
- * Copyright (c) 2020 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"
-
-std::unique_ptr<ModuleMock> TestFixture::mock_;
+++ /dev/null
-/*
- * Copyright (c) 2020 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_H_
-#define UNIT_TESTS_MOCK_TEST_FIXTURE_H_
-
-#include <gtest/gtest.h>
-
-#include <memory>
-#include <stdexcept>
-#include <string>
-#include <utility>
-
-#include "module_mock.h"
-#include "test_fixture.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());
- if (!ptr)
- 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_H_
BuildRequires: pkgconfig(evas)
BuildRequires: pkgconfig(ecore-wl2)
BuildRequires: pkgconfig(gmock)
+BuildRequires: pkgconfig(glib-2.0)
%if 0%{?gcov:1}
BuildRequires: lcov
test_main() {
echo "test_main start"
- /usr/bin/mediakey-unittest
+ /usr/bin/media-key-unittests
}
teardown() {
install -m 0755 run-unittest.sh %{buildroot}%{_bindir}/tizen-unittests/%{name}/
%check
-(cd unittest && LD_LIBRARY_PATH=../ ctest -V)
+(cd tests/media-key_unittests && LD_LIBRARY_PATH=../../src ctest -V)
%if 0%{?gcov:1}
lcov -c --ignore-errors graph --no-external -q -d . -o media_key.info
genhtml media_key.info -o media_key.out
%{_libdir}/libcapi-system-media-key.so
%files unittests
-%{_bindir}/mediakey-unittest
+%{_bindir}/media-key-unittests
%{_bindir}/tizen-unittests/%{name}/run-unittest.sh
%if 0%{?gcov:1}
--- /dev/null
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} MEDIA_KEY_SRCS)
+
+ADD_LIBRARY(${TARGET_MEDIA_KEY} SHARED ${MEDIA_KEY_SRCS})
+
+SET_TARGET_PROPERTIES(${TARGET_MEDIA_KEY} PROPERTIES SOVERSION ${MAJORVER})
+SET_TARGET_PROPERTIES(${TARGET_MEDIA_KEY} PROPERTIES VERSION ${FULLVER})
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_MEDIA_KEY} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/../
+ ${CMAKE_CURRENT_SOURCE_DIR}/../include/)
+
+APPLY_PKG_CONFIG(${TARGET_MEDIA_KEY} PUBLIC
+ DLOG_DEPS
+ CAPI_BASE_COMMON_DEPS
+ ECORE_DEPS
+ ECORE_INPUT_DEPS
+ EVAS_DEPS
+ ECORE_WL2_DEPS
+)
+
+INSTALL(TARGETS ${TARGET_MEDIA_KEY} DESTINATION ${LIB_INSTALL_DIR})
\ No newline at end of file
/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2020 - 2023 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.
* limitations under the License.
*/
+#include "include/media_key.h"
+
#include <Ecore.h>
#include <Ecore_Input.h>
#include <Ecore_Wl2.h>
#include <string>
#include <thread>
-#include "media_key.h"
#include "log_private.hh"
#ifdef EXPORT_API
cb_ = nullptr;
data_ = nullptr;
+ Dispose();
}
private:
ecore_wl2_init();
if (!ecore_wl2_display_connect(NULL)) {
+ // LCOV_EXCL_START
_E("Failed to connect to wl2 display");
ecore_wl2_shutdown();
return;
+ // LCOV_EXCL_STOP
}
disposed_ = false;
key_down_handler_ = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
MediaKeyPressCb, this);
if (!key_down_handler_)
- _E("Failed to register key down event handler");
+ _E("Failed to register key down event handler"); // LCOV_EXCL_LINE
key_up_handler_ = ecore_event_handler_add(ECORE_EVENT_KEY_UP,
MediaKeyReleaseCb, this);
if (!key_up_handler_)
- _E("Failed to register key up event handler");
+ _E("Failed to register key up event handler"); // LCOV_EXCL_LINE
grabbed_ = true;
return 0;
_D("key(%s)", i->first.c_str());
auto ret = ecore_wl2_window_keygrab_unset(NULL, i->first.c_str(), 0, 0);
if (ret != EINA_TRUE)
- _W("Failed to ungrab key(%s)", i->first.c_str());
+ _W("Failed to ungrab key(%s)", i->first.c_str()); // LCOV_EXCL_LINE
}
grabbed_ = false;
static Eina_Bool MediaKeyPressCb(void* data, int type, void* event) {
Evas_Event_Key_Down* ev = static_cast<Evas_Event_Key_Down*>(event);
if (ev == nullptr) {
+ // LCOV_EXCL_START
_E("Invalid parameter");
return ECORE_CALLBACK_RENEW;
+ // LCOV_EXCL_STOP
}
auto* handle = static_cast<MediaKey*>(data);
static Eina_Bool MediaKeyReleaseCb(void* data, int type, void* event) {
Evas_Event_Key_Up* ev = static_cast<Evas_Event_Key_Up*>(event);
if (ev == nullptr) {
+ // LCOV_EXCL_START
_E("Invalid parameter");
return ECORE_CALLBACK_RENEW;
+ // LCOV_EXCL_STOP
}
auto* handle = static_cast<MediaKey*>(data);
--- /dev/null
+ADD_SUBDIRECTORY(media-key_unittests)
\ No newline at end of file
--- /dev/null
+ENABLE_TESTING()
+SET(TARGET_MEDIA_KEY_UNITTESTS "media-key-unittests")
+
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ UNIT_TESTS_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/mock/ MOCK_SRCS)
+
+ADD_EXECUTABLE(${TARGET_MEDIA_KEY_UNITTESTS}
+ ${UNIT_TESTS_SRCS}
+ ${MOCK_SRCS}
+)
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_MEDIA_KEY_UNITTESTS} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../include
+ ${CMAKE_CURRENT_SOURCE_DIR}/
+)
+
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(gtest_pkgs REQUIRED gmock)
+
+TARGET_LINK_LIBRARIES(${TARGET_MEDIA_KEY_UNITTESTS} PUBLIC
+ ${TARGET_MEDIA_KEY})
+
+APPLY_PKG_CONFIG(${TARGET_MEDIA_KEY_UNITTESTS} PUBLIC
+ DLOG_DEPS
+ GLIB_DEPS
+ GMOCK_DEPS
+)
+
+ADD_TEST(NAME ${TARGET_MEDIA_KEY_UNITTESTS} COMMAND ${TARGET_MEDIA_KEY_UNITTESTS})
+
+INSTALL(PROGRAMS ${TARGET_MEDIA_KEY_UNITTESTS} DESTINATION ${BIN_INSTALL_DIR})
--- /dev/null
+// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include <dlog.h>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+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;
+}
+
+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) 2020 - 2023 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 <Ecore_Input.h>
+#include <Evas.h>
+#include <gtest/gtest.h>
+#include <glib.h>
+#include <media_key.h>
+
+#include "mock/ecore_wl2_mock.h"
+#include "mock/test_fixture.h"
+
+using ::testing::_;
+using ::testing::Return;
+using ::testing::Invoke;
+
+namespace {
+
+std::vector<std::string> keys = {
+ "XF86AudioPlay", "XF86AudioStop", "XF86AudioPause",
+ "XF86AudioNext", "XF86AudioPrev", "XF86AudioRewind",
+ "XF86AudioForward", "XF86AudioPlayPause", "XF86AudioMedia" };
+
+int dummy;
+class Mocks : public ::testing::NiceMock<EcoreWl2Mock> {};
+
+class EcoreEventHandler {
+ public:
+ EcoreEventHandler(int type, Ecore_Event_Handler_Cb func, void* user_data)
+ : type_(type), func_(func), user_data_(user_data) {}
+
+ void Invoke() {
+ if (type_ == ECORE_EVENT_KEY_DOWN) {
+ for (int i = 0; i < 9; i++) {
+ Evas_Event_Key_Down event_key_down = {0};
+ event_key_down.keyname = const_cast<char*>(keys[i].c_str());
+ func_(user_data_, type_, &event_key_down);
+ }
+ } else if (type_ == ECORE_EVENT_KEY_UP) {
+ for (int i = 0; i < 9; i++) {
+ Evas_Event_Key_Up event_key_up = { 0 };
+ event_key_up.keyname = const_cast<char*>(keys[i].c_str());
+ func_(user_data_, type_, &event_key_up);
+ }
+ }
+ }
+
+ private:
+ int type_;
+ Ecore_Event_Handler_Cb func_;
+ void* user_data_;
+};
+
+int fake_ecore_wl2_init() {
+ return 1;
+}
+
+int fake_ecore_wl2_shutdown() {
+ return 0;
+}
+
+Ecore_Wl2_Display* fake_ecore_wl2_display_connect(const char* name) {
+ return reinterpret_cast<Ecore_Wl2_Display*>(&dummy);
+}
+
+void fake_ecore_wl2_display_disconnect(Ecore_Wl2_Display* display) {
+}
+
+Ecore_Wl2_Display* fake_ecore_wl2_connected_display_get(const char* name) {
+ return reinterpret_cast<Ecore_Wl2_Display*>(&dummy);
+}
+
+Eina_Bool fake_ecore_wl2_window_keygrab_set(
+ Ecore_Wl2_Window* window, const char* key, int mod, int not_mod,
+ int priority, Ecore_Wl2_Window_Keygrab_Mode grab_mode) {
+ return EINA_TRUE;
+}
+
+Eina_Bool fake_ecore_wl2_window_keygrab_set_return_false(
+ Ecore_Wl2_Window* window, const char* key, int mod, int not_mod,
+ int priority, Ecore_Wl2_Window_Keygrab_Mode grab_mode) {
+ return EINA_FALSE;
+}
+
+Eina_Bool fake_ecore_wl2_window_keygrab_unset(Ecore_Wl2_Window* window,
+ const char* key, int mod,
+ int any_mod) {
+ return EINA_TRUE;
+}
+
+Ecore_Event_Handler* fake_ecore_event_handler_add(int type,
+ Ecore_Event_Handler_Cb func,
+ const void* data) {
+ auto* event = new EcoreEventHandler(type, func, const_cast<void*>(data));
+ g_idle_add(
+ [](gpointer user_data) {
+ auto* handle = static_cast<EcoreEventHandler*>(user_data);
+ handle->Invoke();
+ delete handle;
+ return G_SOURCE_REMOVE;
+ },
+ event);
+
+ return reinterpret_cast<Ecore_Event_Handler*>(&dummy);
+}
+
+void* fake_ecore_event_handler_del(Ecore_Event_Handler* event_handler) {
+ return reinterpret_cast<void*>(&dummy);
+}
+
+} // namespace
+
+class MediaKeyTest : public TestFixture {
+ public:
+ MediaKeyTest() : TestFixture(std::make_unique<Mocks>()) {}
+ virtual ~MediaKeyTest() {}
+
+ virtual void SetUp() {
+ EXPECT_CALL(GetMock<EcoreWl2Mock>(), ecore_wl2_init())
+ .WillRepeatedly(Invoke(fake_ecore_wl2_init));
+ EXPECT_CALL(GetMock<EcoreWl2Mock>(), ecore_wl2_shutdown())
+ .WillRepeatedly(Invoke(fake_ecore_wl2_shutdown));
+ EXPECT_CALL(GetMock<EcoreWl2Mock>(), ecore_wl2_display_connect(_))
+ .WillRepeatedly(Invoke(fake_ecore_wl2_display_connect));
+ EXPECT_CALL(GetMock<EcoreWl2Mock>(), ecore_wl2_display_disconnect(_))
+ .WillRepeatedly(Invoke(fake_ecore_wl2_display_disconnect));
+ EXPECT_CALL(GetMock<EcoreWl2Mock>(), ecore_wl2_connected_display_get(_))
+ .WillRepeatedly(Invoke(fake_ecore_wl2_connected_display_get));
+
+ loop_ = g_main_loop_new(nullptr, FALSE);
+ }
+
+ virtual void TearDown() {
+ if (loop_ != nullptr) {
+ g_main_loop_unref(loop_);
+ loop_ = nullptr;
+ }
+ }
+
+ void RunMainLoop() {
+ g_main_loop_run(loop_);
+ }
+
+ void QuitMainLoop() {
+ g_main_loop_quit(loop_);
+ }
+
+ int count_ = 0;
+
+ private:
+ GMainLoop* loop_ = nullptr;
+};
+
+static void MediaKeyEventCb(media_key_e key, media_key_event_e status,
+ void* user_data) {
+ auto* test = static_cast<MediaKeyTest*>(user_data);
+ test->count_++;
+ if (test->count_ == static_cast<int>(keys.size() * 2))
+ test->QuitMainLoop();
+}
+
+TEST_F(MediaKeyTest, media_key_reserve_P) {
+ EXPECT_CALL(GetMock<EcoreWl2Mock>(),
+ ecore_wl2_window_keygrab_set(_, _, _, _, _, _))
+ .Times(9)
+ .WillRepeatedly(Invoke(fake_ecore_wl2_window_keygrab_set));
+ EXPECT_CALL(GetMock<EcoreWl2Mock>(), ecore_event_handler_add(_, _, _))
+ .Times(2)
+ .WillRepeatedly(Invoke(fake_ecore_event_handler_add));
+
+ count_ = 0;
+ int ret = media_key_reserve(MediaKeyEventCb, this);
+ EXPECT_EQ(ret, MEDIA_KEY_ERROR_NONE);
+ RunMainLoop();
+ EXPECT_EQ(count_, static_cast<int>(keys.size() * 2));
+
+ EXPECT_CALL(GetMock<EcoreWl2Mock>(),
+ ecore_wl2_window_keygrab_unset(_, _, _, _))
+ .Times(9)
+ .WillRepeatedly(Invoke(fake_ecore_wl2_window_keygrab_unset));
+ EXPECT_CALL(GetMock<EcoreWl2Mock>(), ecore_event_handler_del(_))
+ .Times(2)
+ .WillRepeatedly(Invoke(fake_ecore_event_handler_del));
+
+ ret = media_key_release();
+ EXPECT_EQ(ret, MEDIA_KEY_ERROR_NONE);
+}
+
+TEST_F(MediaKeyTest, media_key_reserve_N1) {
+ EXPECT_CALL(GetMock<EcoreWl2Mock>(),
+ ecore_wl2_window_keygrab_set(_, _, _, _, _, _))
+ .Times(1)
+ .WillRepeatedly(Invoke(fake_ecore_wl2_window_keygrab_set_return_false));
+ EXPECT_CALL(GetMock<EcoreWl2Mock>(),
+ ecore_wl2_window_keygrab_unset(_, _, _, _))
+ .Times(9)
+ .WillRepeatedly(Invoke(fake_ecore_wl2_window_keygrab_unset));
+
+ int ret = media_key_reserve(MediaKeyEventCb, this);
+ EXPECT_EQ(ret, MEDIA_KEY_ERROR_OPERATION_FAILED);
+}
+
+TEST_F(MediaKeyTest, media_key_reserve_N2) {
+ int ret = media_key_reserve(nullptr, nullptr);
+ EXPECT_EQ(ret, MEDIA_KEY_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(MediaKeyTest, media_key_release_P) {
+ int ret = media_key_release();
+ EXPECT_EQ(ret, MEDIA_KEY_ERROR_NONE);
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 - 2023 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/ecore_wl2_mock.h"
+
+#include "mock/mock_hook.h"
+#include "mock/test_fixture.h"
+
+extern "C" int ecore_wl2_init() {
+ return MOCK_HOOK_P0(EcoreWl2Mock, ecore_wl2_init);
+}
+
+extern "C" int ecore_wl2_shutdown() {
+ return MOCK_HOOK_P0(EcoreWl2Mock, ecore_wl2_shutdown);
+}
+
+extern "C" Ecore_Wl2_Display* ecore_wl2_display_connect(const char* name) {
+ return MOCK_HOOK_P1(EcoreWl2Mock, ecore_wl2_display_connect, name);
+}
+
+extern "C" void ecore_wl2_display_disconnect(Ecore_Wl2_Display* display) {
+ MOCK_HOOK_P1(EcoreWl2Mock, ecore_wl2_display_disconnect, display);
+}
+
+extern "C" Ecore_Wl2_Display* ecore_wl2_connected_display_get(
+ const char* name) {
+ return MOCK_HOOK_P1(EcoreWl2Mock, ecore_wl2_connected_display_get, name);
+}
+
+extern "C" Eina_Bool ecore_wl2_window_keygrab_set(
+ Ecore_Wl2_Window* win, const char* key, int mod, int not_mod, int priority,
+ Ecore_Wl2_Window_Keygrab_Mode grab_mode) {
+ return MOCK_HOOK_P6(EcoreWl2Mock, ecore_wl2_window_keygrab_set, win, key, mod,
+ not_mod, priority, grab_mode);
+}
+
+extern "C" Eina_Bool ecore_wl2_window_keygrab_unset(Ecore_Wl2_Window* win,
+ const char* key, int mod,
+ int any_mod) {
+ return MOCK_HOOK_P4(EcoreWl2Mock, ecore_wl2_window_keygrab_unset, win, key,
+ mod, any_mod);
+}
+
+extern "C" Ecore_Event_Handler* ecore_event_handler_add(
+ int type, Ecore_Event_Handler_Cb func, const void* data) {
+ return MOCK_HOOK_P3(EcoreWl2Mock, ecore_event_handler_add, type, func, data);
+}
+
+extern "C" void* ecore_event_handler_del(Ecore_Event_Handler* event_handler) {
+ return MOCK_HOOK_P1(EcoreWl2Mock, ecore_event_handler_del, event_handler);
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 - 2023 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 MEDIA_KEY_UNITTESTS_MOCK_ECORE_WL2_MOCK_H_
+#define MEDIA_KEY_UNITTESTS_MOCK_ECORE_WL2_MOCK_H_
+
+#include <Ecore.h>
+#include <Ecore_Wl2.h>
+#include <Eina.h>
+#include <gmock/gmock.h>
+
+#include "mock/module_mock.h"
+
+typedef Eina_Bool(*Ecore_Event_Handler_Cb)(
+ void* data, int type, void* event);
+
+class EcoreWl2Mock : public virtual ModuleMock {
+ public:
+ virtual ~EcoreWl2Mock() {}
+
+ MOCK_METHOD0(ecore_wl2_init, int());
+ MOCK_METHOD0(ecore_wl2_shutdown, int());
+ MOCK_METHOD1(ecore_wl2_display_connect, Ecore_Wl2_Display*(const char*));
+ MOCK_METHOD1(ecore_wl2_display_disconnect, void(Ecore_Wl2_Display*));
+ MOCK_METHOD1(ecore_wl2_connected_display_get,
+ Ecore_Wl2_Display*(const char*));
+ MOCK_METHOD6(ecore_wl2_window_keygrab_set,
+ Eina_Bool(Ecore_Wl2_Window*, const char*, int, int, int,
+ Ecore_Wl2_Window_Keygrab_Mode));
+ MOCK_METHOD4(ecore_wl2_window_keygrab_unset,
+ Eina_Bool(Ecore_Wl2_Window*, const char*, int, int));
+ MOCK_METHOD3(ecore_event_handler_add,
+ Ecore_Event_Handler*(int, Ecore_Event_Handler_Cb, const void*));
+ MOCK_METHOD1(ecore_event_handler_del, void*(Ecore_Event_Handler*));
+};
+
+#endif // MEDIA_KEY_UNITTESTS_MOCK_ECORE_WL2_MOCK_H_
--- /dev/null
+/*
+ * Copyright (c) 2020 - 2023 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 MEDIA_KEY_UNITTESTS_MOCK_MOCK_HOOK_H_
+#define MEDIA_KEY_UNITTESTS_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 // MEDIA_KEY_UNITTESTS_MOCK_MOCK_HOOK_H_
--- /dev/null
+/*
+ * Copyright (c) 2020 - 2023 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 MEDIA_KEY_UNITTESTS_MOCK_MODULE_MOCK_H_
+#define MEDIA_KEY_UNITTESTS_MOCK_MODULE_MOCK_H_
+
+class ModuleMock {
+ public:
+ virtual ~ModuleMock() {}
+};
+
+#endif // MEDIA_KEY_UNITTESTS_MOCK_MODULE_MOCK_H_
--- /dev/null
+/*
+ * Copyright (c) 2020 - 2023 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.h"
+
+std::unique_ptr<ModuleMock> TestFixture::mock_;
--- /dev/null
+/*
+ * Copyright (c) 2020 - 2023 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 MEDIA_KEY_UNITTESTS_MOCK_TEST_FIXTURE_H_
+#define MEDIA_KEY_UNITTESTS_MOCK_TEST_FIXTURE_H_
+
+#include <gtest/gtest.h>
+
+#include <memory>
+#include <stdexcept>
+#include <string>
+#include <utility>
+
+#include "mock/module_mock.h"
+#include "mock/test_fixture.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());
+ if (!ptr)
+ 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 // MEDIA_KEY_UNITTESTS_MOCK_TEST_FIXTURE_H_
+++ /dev/null
-ENABLE_TESTING()
-SET(TARGET_UNIT_TEST "mediakey-unittest")
-
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ UNIT_TESTS_SRCS)
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../mock/ UNIT_TESTS_SRCS)
-ADD_EXECUTABLE(${TARGET_UNIT_TEST}
- ${UNIT_TESTS_SRCS}
-)
-
-TARGET_INCLUDE_DIRECTORIES(${TARGET_UNIT_TEST} PUBLIC
- "${CMAKE_CURRENT_SOURCE_DIR}/../include"
- "${CMAKE_CURRENT_SOURCE_DIR}/../mock"
-)
-
-INCLUDE(FindPkgConfig)
-PKG_CHECK_MODULES(gtest_pkgs REQUIRED gmock)
-
-TARGET_LINK_LIBRARIES(${TARGET_UNIT_TEST} PUBLIC ${gtest_pkgs_LDFLAGS} ${PROJECT_NAME})
-
-ADD_TEST(
- NAME ${TARGET_UNIT_TEST}
- COMMAND ${TARGET_UNIT_TEST}
-)
-
-INSTALL(PROGRAMS ${TARGET_UNIT_TEST} DESTINATION ${BIN_INSTALL_DIR})
+++ /dev/null
-// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
-// Use of this source code is governed by a apache 2.0 license that can be
-// found in the LICENSE file.
-
-#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;
-}
+++ /dev/null
-/*
- * Copyright (c) 2020 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 <media_key.h>
-#include <Evas.h>
-#include <Ecore_Input.h>
-
-#include "test_fixture.h"
-#include "ecore_wl2_mock.h"
-
-using ::testing::_;
-using ::testing::Return;
-using ::testing::Invoke;
-
-class Mocks : public ::testing::NiceMock<EcoreWl2Mock> {};
-
-class MediaKeyTest : public TestFixture {
- public:
- MediaKeyTest() : TestFixture(std::make_unique<Mocks>()) {}
- virtual ~MediaKeyTest() {}
-
- virtual void SetUp() {
- }
-
- virtual void TearDown() {
- }
-};
-
-Ecore_Event_Handler* __ecore_event_handler_add_fake(int type, Ecore_Event_Handler_Cb func,
- const void* data) {
- if (type == ECORE_EVENT_KEY_DOWN || type == ECORE_EVENT_KEY_UP) {
- func(nullptr, 0, nullptr);
- }
- return nullptr;
-}
-
-TEST_F(MediaKeyTest, media_key_reserve_N1) {
- int ret = media_key_reserve(
- [](media_key_e key, media_key_event_e status, void* user_data) -> void {
- }, nullptr);
- EXPECT_EQ(ret, MEDIA_KEY_ERROR_OPERATION_FAILED);
-}
-
-TEST_F(MediaKeyTest, media_key_reserve_P) {
- EXPECT_CALL(GetMock<EcoreWl2Mock>(),
- ecore_wl2_window_keygrab_set(_, _, _, _, _, _)).
- WillRepeatedly(Return(EINA_TRUE));
- EXPECT_CALL(GetMock<EcoreWl2Mock>(),
- ecore_event_handler_add(_, _, _)).
- WillRepeatedly(Invoke(__ecore_event_handler_add_fake));
-
- int ret = media_key_reserve(
- [](media_key_e key, media_key_event_e status, void* user_data) -> void {
- }, nullptr);
- EXPECT_EQ(ret, MEDIA_KEY_ERROR_NONE);
-}
-
-TEST_F(MediaKeyTest, media_key_reserve_N2) {
- int ret = media_key_reserve(nullptr, nullptr);
- EXPECT_EQ(ret, MEDIA_KEY_ERROR_INVALID_PARAMETER);
-}
-
-TEST_F(MediaKeyTest, media_key_release) {
- int ret = media_key_release();
- EXPECT_EQ(ret, MEDIA_KEY_ERROR_NONE);
-}
\ No newline at end of file