From: Yunhee Seo Date: Tue, 15 Oct 2024 10:19:33 +0000 (+0900) Subject: input: Add input plugin backend module test X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Ftizen_8.0;p=platform%2Fcore%2Fsystem%2Fdeviced.git input: Add input plugin backend module test To test input module plugin backend loading and initializing, this is necessary. With this, plugin backend initialization and key input event callback can be tested. Change-Id: Ic111aaa5b257eb63a8e445721370f8030aecfe7b Signed-off-by: Yunhee Seo --- diff --git a/tests/syscommon-plugin-test/CMakeLists.txt b/tests/syscommon-plugin-test/CMakeLists.txt index 8bbb146d..c40cf548 100644 --- a/tests/syscommon-plugin-test/CMakeLists.txt +++ b/tests/syscommon-plugin-test/CMakeLists.txt @@ -7,6 +7,7 @@ SET(SRCS main.cc battery.cc display.cc + input.cc syscommon-plugin-test.h) INCLUDE(FindPkgConfig) diff --git a/tests/syscommon-plugin-test/input.cc b/tests/syscommon-plugin-test/input.cc new file mode 100644 index 00000000..99433413 --- /dev/null +++ b/tests/syscommon-plugin-test/input.cc @@ -0,0 +1,107 @@ +#include +#include +#include +#include +#include +#include + +#include "syscommon-plugin-test.h" + +#define PLUGIN_INPUT_CONF_FILE "/etc/deviced/conf.d/input.conf" + +class InputTest : public testing::Test { + public: + static bool input_key_pressed; + static bool input_key_relased; + static int input_check_key_pressed_cb(void *data) { + if (!data) + return 0; + + int *keycode = (int *)data; + DEBUG_MESSAGE("Input keycode %d is pressed", keycode); + input_key_pressed = true; + return 0; + } + static int input_check_key_released_cb(void *data) { + if (!data) + return 0; + + int *keycode = (int *)data; + DEBUG_MESSAGE("Input keycode %d is released", keycode); + input_key_relased = true; + return 0; + } + protected: + void SetUp() override { + int ret_val; + + ret_val = syscommon_plugin_deviced_input_get_backend(); + if (ret_val == 0) + input_plugin_backend_supported = true; + else + input_plugin_backend_supported = false; + + ret_val = access(PLUGIN_INPUT_CONF_FILE, F_OK); + if (ret_val == 0) + input_plugin_backend_conf_exist = true; + else + input_plugin_backend_conf_exist = false; + } + ~InputTest() {} + void TearDown() override { + int ret_val; + + ret_val = syscommon_plugin_deviced_input_put_backend(); + if (ret_val != 0) + DEBUG_MESSAGE("Failed to put input backend, ret(%d).", ret_val); + } + bool input_plugin_backend_supported; + bool input_plugin_backend_conf_exist; +}; + +bool InputTest::input_key_pressed = false; +bool InputTest::input_key_relased = false; + +TEST_F(InputTest, GetInputBackend) +{ + if (!input_plugin_backend_supported) { + DEBUG_MESSAGE("Input plugin backend is not supported."); + return; + } + + EXPECT_EQ(input_plugin_backend_supported, true); + DEBUG_MESSAGE("Input plugin backend is supported."); + return; +} + +TEST_F(InputTest, InputEventCb) +{ + struct timeval tv; + memset(&tv, 0, sizeof(struct timeval)); + + if (!input_plugin_backend_supported) { + DEBUG_MESSAGE("Input plugin backend is not supported."); + return; + } + + if (!input_plugin_backend_conf_exist) { + DEBUG_MESSAGE("Input plugin backend conf file does not exist."); + return; + } + + syscommon_notifier_subscribe_notify(DEVICED_NOTIFIER_KEY_PRESS, input_check_key_pressed_cb); + syscommon_notifier_subscribe_notify(DEVICED_NOTIFIER_KEY_RELEASE, input_check_key_released_cb); + + /* Input key event press/release invoke with power key value */ + syscommon_plugin_deviced_input_event_cb(tv, 0x01, 116, SYSCOMMON_DEVICED_INPUT_KEY_PRESSED); + syscommon_plugin_deviced_input_event_cb(tv, 0x01, 116, SYSCOMMON_DEVICED_INPUT_KEY_RELEASED); + sleep(1); + + /* After input key event callback called, flag value will be set as true */ + EXPECT_EQ(input_key_pressed, true); + EXPECT_EQ(input_key_relased, true); + + syscommon_notifier_unsubscribe_notify(DEVICED_NOTIFIER_KEY_PRESS, input_check_key_pressed_cb); + syscommon_notifier_unsubscribe_notify(DEVICED_NOTIFIER_KEY_RELEASE, input_check_key_released_cb); + return; +}