1 /* 2 * Copyright (C) 2023-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include <gtest/gtest.h> 17 18 #include "joystick_event_processor.h" 19 #include "mmi_log.h" 20 #include <iomanip> 21 #include "key_map_manager.h" 22 #include "key_event_normalize.h" 23 #include "key_unicode_transformation.h" 24 25 #undef MMI_LOG_TAG 26 #define MMI_LOG_TAG "JoystickEventProcessorTest" 27 28 #define KEY_MAX 0x2ff 29 #define KEY_CNT (KEY_MAX + 1) 30 31 typedef void (*libinput_seat_destroy_func) (struct libinput_seat *seat); 32 33 struct libinput_device_config {}; 34 35 struct list { 36 struct list *next, *prev; 37 }; 38 39 struct libinput_device_group { 40 int refcount; 41 void *user_data; 42 char *identifier; /* unique identifier or NULL for singletons */ 43 struct list link; 44 }; 45 46 struct libinput_seat { 47 struct libinput *libinput; 48 struct list link; 49 struct list devices_list; 50 void *user_data; 51 int refcount; 52 libinput_seat_destroy_func destroy; 53 54 char *physical_name; 55 char *logical_name; 56 57 uint32_t slot_map; 58 59 uint32_t button_count[KEY_CNT]; 60 }; 61 62 struct libinput_device { 63 struct libinput_seat *seat; 64 struct libinput_device_group *group; 65 struct list link; 66 struct list event_listeners; 67 void *user_data; 68 int refcount; 69 struct libinput_device_config config; 70 }; 71 72 struct libinput_event { 73 enum libinput_event_type type; 74 struct libinput_device *device; 75 }; 76 77 namespace OHOS { 78 namespace MMI { 79 namespace { 80 using namespace testing::ext; 81 } // namespace 82 83 class JoystickEventProcessorTest : public testing::Test { 84 public: SetUpTestCase(void)85 static void SetUpTestCase(void) {} TearDownTestCase(void)86 static void TearDownTestCase(void) {} SetUp()87 void SetUp() {} TearDown()88 void TearDown() {} 89 }; 90 91 /** 92 * @tc.name: JoystickEventProcessorTest_OnButtonEvent 93 * @tc.desc: Test OnButtonEvent 94 * @tc.type: FUNC 95 * @tc.require: 96 */ 97 HWTEST_F(JoystickEventProcessorTest, JoystickEventProcessorTest_OnButtonEvent, TestSize.Level1) 98 { 99 CALL_TEST_DEBUG; 100 std::shared_ptr<JoystickEventProcessor> JoystickEvent; 101 libinput_event libInputEvent; 102 ASSERT_EQ(JoystickEvent->OnButtonEvent(&libInputEvent), nullptr); 103 } 104 105 /** 106 * @tc.name: JoystickEventProcessorTest_CheckIntention 107 * @tc.desc: Test CheckIntention 108 * @tc.type: FUNC 109 * @tc.require: 110 */ 111 HWTEST_F(JoystickEventProcessorTest, JoystickEventProcessorTest_CheckIntention, TestSize.Level1) 112 { 113 CALL_TEST_DEBUG; 114 auto JoystickEvent = new JoystickEventProcessor(2); 115 std::shared_ptr<PointerEvent> pointerEvent; 116 ASSERT_NO_FATAL_FAILURE( __anona80e4ef30202(std::shared_ptr<OHOS::MMI::KeyEvent>) 117 JoystickEvent->CheckIntention(pointerEvent, [=] (std::shared_ptr<OHOS::MMI::KeyEvent>) { return; })); 118 } 119 120 /** 121 * @tc.name: JoystickEventProcessorTest_CheckHAT0X 122 * @tc.desc: Test CheckHAT0X 123 * @tc.type: FUNC 124 * @tc.require: 125 */ 126 HWTEST_F(JoystickEventProcessorTest, JoystickEventProcessorTest_CheckHAT0X, TestSize.Level1) 127 { 128 CALL_TEST_DEBUG; 129 auto JoystickEvent = new JoystickEventProcessor(2); 130 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 131 std::vector<KeyEvent::KeyItem> buttonEvents; 132 ASSERT_NO_FATAL_FAILURE(JoystickEvent->CheckHAT0X(pointerEvent, buttonEvents)); 133 } 134 135 /** 136 * @tc.name: JoystickEventProcessorTest_CheckHAT0Y 137 * @tc.desc: Test CheckHAT0Y 138 * @tc.type: FUNC 139 * @tc.require: 140 */ 141 HWTEST_F(JoystickEventProcessorTest, JoystickEventProcessorTest_CheckHAT0Y, TestSize.Level1) 142 { 143 CALL_TEST_DEBUG; 144 auto JoystickEvent = new JoystickEventProcessor(2); 145 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 146 std::vector<KeyEvent::KeyItem> buttonEvents; 147 ASSERT_NO_FATAL_FAILURE(JoystickEvent->CheckHAT0Y(pointerEvent, buttonEvents)); 148 } 149 150 /** 151 * @tc.name: JoystickEventProcessorTest_UpdateButtonState 152 * @tc.desc: Test UpdateButtonState 153 * @tc.type: FUNC 154 * @tc.require: 155 */ 156 HWTEST_F(JoystickEventProcessorTest, JoystickEventProcessorTest_UpdateButtonState, TestSize.Level1) 157 { 158 CALL_TEST_DEBUG; 159 auto JoystickEvent = new JoystickEventProcessor(2); 160 const KeyEvent::KeyItem keyItem; 161 ASSERT_NO_FATAL_FAILURE(JoystickEvent->UpdateButtonState(keyItem)); 162 } 163 164 /** 165 * @tc.name: JoystickEventProcessorTest_FormatButtonEvent 166 * @tc.desc: Test FormatButtonEvent 167 * @tc.type: FUNC 168 * @tc.require: 169 */ 170 HWTEST_F(JoystickEventProcessorTest, JoystickEventProcessorTest_FormatButtonEvent, TestSize.Level1) 171 { 172 CALL_TEST_DEBUG; 173 auto JoystickEvent = new JoystickEventProcessor(2); 174 const KeyEvent::KeyItem keyItem; 175 ASSERT_NE(JoystickEvent->FormatButtonEvent(keyItem), nullptr); 176 } 177 178 /** 179 * @tc.name: JoystickEventProcessorTest_CleanUpKeyEvent 180 * @tc.desc: Test CleanUpKeyEvent 181 * @tc.type: FUNC 182 * @tc.require: 183 */ 184 HWTEST_F(JoystickEventProcessorTest, JoystickEventProcessorTest_CleanUpKeyEvent, TestSize.Level1) 185 { 186 CALL_TEST_DEBUG; 187 auto JoystickEvent = new JoystickEventProcessor(2); 188 ASSERT_NE(JoystickEvent->CleanUpKeyEvent(), nullptr); 189 } 190 191 /** 192 * @tc.name: JoystickEventProcessorTest_DumpJoystickAxisEvent 193 * @tc.desc: Test DumpJoystickAxisEvent 194 * @tc.type: FUNC 195 * @tc.require: 196 */ 197 HWTEST_F(JoystickEventProcessorTest, JoystickEventProcessorTest_DumpJoystickAxisEvent, TestSize.Level1) 198 { 199 CALL_TEST_DEBUG; 200 auto JoystickEvent = new JoystickEventProcessor(2); 201 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 202 ASSERT_NE(JoystickEvent->DumpJoystickAxisEvent(pointerEvent), ""); 203 } 204 205 /** 206 * @tc.name: JoystickEventProcessorTest_Normalize 207 * @tc.desc: Test Normalize 208 * @tc.type: FUNC 209 * @tc.require: 210 */ 211 HWTEST_F(JoystickEventProcessorTest, JoystickEventProcessorTest_Normalize, TestSize.Level1) 212 { 213 CALL_TEST_DEBUG; 214 auto JoystickEvent = new JoystickEventProcessor(2); 215 const struct libinput_event_joystick_axis_abs_info axis{ 0 }; 216 double low = 2.1f; 217 double high = 1.3f; 218 ASSERT_NE(JoystickEvent->Normalize(axis, low, high), 3.5f); 219 } 220 } // namespace MMI 221 } // namespace OHOS 222