--- /dev/null
+#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;
+}