input: Add input plugin backend module test 45/320345/1 tizen_8.0
authorYunhee Seo <yuni.seo@samsung.com>
Tue, 15 Oct 2024 10:19:33 +0000 (19:19 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Wed, 19 Feb 2025 04:59:01 +0000 (13:59 +0900)
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 <yuni.seo@samsung.com>
tests/syscommon-plugin-test/CMakeLists.txt
tests/syscommon-plugin-test/input.cc [new file with mode: 0644]

index 8bbb146d0dfec34f5b59998da5c498a729efd7d7..c40cf54866749e6a3782930b5f5982b00ccb203d 100644 (file)
@@ -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 (file)
index 0000000..9943341
--- /dev/null
@@ -0,0 +1,107 @@
+#include <libsyscommon/notifier.h>
+#include <system_info.h>
+#include <system/syscommon-plugin-common-interface.h>
+#include <system/syscommon-plugin-deviced-common-interface.h>
+#include <system/syscommon-plugin-deviced-input.h>
+#include <system/syscommon-plugin-deviced-input-interface.h>
+
+#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;
+}