1 /*
2 * Copyright (c) 2021-2023 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 "event_log_helper.h"
17 #include "event_util_test.h"
18 #include "input_manager_util.h"
19 #include "multimodal_event_handler.h"
20 #include "system_info.h"
21
22 namespace OHOS {
23 namespace MMI {
24 namespace {
25 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "InputManagerTest"};
26 constexpr int32_t TIME_WAIT_FOR_OP = 100;
27 constexpr int32_t NANOSECOND_TO_MILLISECOND = 1000000;
28 constexpr int32_t SLEEP_MILLISECONDS = 1000;
29 constexpr int32_t DEFAULT_DEVICE_ID = 0;
30 constexpr int32_t KEY_REPEAT_DELAY = 350;
31 constexpr int32_t KEY_REPEAT_RATE = 60;
32 constexpr int32_t POINTER_ITEM_DISPLAY_X_ONE = 147;
33 constexpr int32_t POINTER_ITEM_DISPLAY_X_TWO = 456;
34 constexpr int32_t POINTER_ITEM_DISPLAY_Y_ONE = 123;
35 constexpr int32_t POINTER_ITEM_DISPLAY_Y_TWO = 258;
36 constexpr int32_t KEY_DOWN_DURATION = 300;
37 constexpr int32_t FINAL_KEY_DOWN_DURATION_ONE = 10;
38 constexpr int32_t FINAL_KEY_DOWN_DURATION_TWO = 2000;
39 constexpr int32_t POINTER_SENSOR_INPUT_TIME = 2000;
40 constexpr int32_t BUFFER_SIZE = 512;
41 constexpr int32_t KEYBOARD_TYPE_SIZE = 20;
42 constexpr int32_t PARAMETER_ERROR = 401;
43 constexpr int32_t INVAID_VALUE = -1;
44 constexpr double POINTER_ITEM_PRESSURE = 5.0;
45 } // namespace
46
47 class InputManagerTest : public testing::Test {
48 public:
49 void SetUp();
50 void TearDown();
51 static void SetUpTestCase();
52 std::string GetEventDump();
53 };
54
SetUpTestCase()55 void InputManagerTest::SetUpTestCase()
56 {
57 ASSERT_TRUE(TestUtil->Init());
58 }
59
SetUp()60 void InputManagerTest::SetUp()
61 {
62 TestUtil->SetRecvFlag(RECV_FLAG::RECV_FOCUS);
63 }
64
TearDown()65 void InputManagerTest::TearDown()
66 {
67 TestUtil->AddEventDump("");
68 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
69 }
70
GetEventDump()71 std::string InputManagerTest::GetEventDump()
72 {
73 return TestUtil->GetEventDump();
74 }
75
76 /**
77 * @tc.name: InputManager_NotResponse_001
78 * @tc.desc: detection of not response
79 * @tc.type: FUNC
80 * @tc.require:AR000GJG6G
81 */
82 HWTEST_F(InputManagerTest, InputManager_NotResponse_001, TestSize.Level1)
83 {
84 CALL_TEST_DEBUG;
85 auto pointerEvent = PointerEvent::Create();
86 ASSERT_NE(pointerEvent, nullptr);
87
88 PointerEvent::PointerItem item;
89 item.SetPressure(POINTER_ITEM_PRESSURE);
90 item.SetPointerId(0);
91 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_TWO);
92 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_ONE);
93 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
94 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
95 pointerEvent->SetPointerId(0);
96 pointerEvent->AddPointerItem(item);
97 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
98 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
99 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
100 }
101
102 /**
103 * @tc.name: InputManager_NotResponse_002
104 * @tc.desc: detection of not response
105 * @tc.type: FUNC
106 * @tc.require:SR000GGN6G
107 */
108 HWTEST_F(InputManagerTest, InputManager_NotResponse_002, TestSize.Level1)
109 {
110 CALL_TEST_DEBUG;
111 auto pointerEvent = PointerEvent::Create();
112 ASSERT_NE(pointerEvent, nullptr);
113
114 PointerEvent::PointerItem item;
115 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_TWO);
116 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_ONE);
117 item.SetPressure(POINTER_ITEM_PRESSURE);
118 item.SetPointerId(0);
119 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
120 pointerEvent->SetPointerId(0);
121 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
122 pointerEvent->AddPointerItem(item);
123 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
124 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
125 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
126 }
127
128 /**
129 * @tc.name: InputManagerTest_SubscribeKeyEvent_001
130 * @tc.desc: Verify invalid parameter.
131 * @tc.type: FUNC
132 * @tc.require:SR000GGQL4 AR000GJNGN
133 * @tc.author: yangguang
134 */
135 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_001, TestSize.Level1)
136 {
137 CALL_TEST_DEBUG;
138 std::set<int32_t> preKeys;
139 std::shared_ptr<KeyOption> keyOption =
140 InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_VOLUME_MUTE, true, 0);
141 int32_t response = INVAID_VALUE;
142 response = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, nullptr);
143 EXPECT_TRUE(response < 0);
144 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
145 InputManager::GetInstance()->UnsubscribeKeyEvent(response);
146 }
147
148 /**
149 * @tc.name: InputManagerTest_SubscribeKeyEvent_02
150 * @tc.desc: Verify subscribe power key event.
151 * @tc.type: FUNC
152 * @tc.require:SR000GGQL4 AR000GJNGN
153 * @tc.author: zhaoxueyuan
154 */
155 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_02, TestSize.Level1)
156 {
157 CALL_TEST_DEBUG;
158 ASSERT_TRUE(MMIEventHdl.InitClient());
159 // 电源键长按按下订阅
160 std::set<int32_t> preKeys;
161 std::shared_ptr<KeyOption> keyOption =
162 InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_POWER, true, FINAL_KEY_DOWN_DURATION_TWO);
163 int32_t subscribeId1 = INVAID_VALUE;
__anond4639ab20202(std::shared_ptr<KeyEvent> keyEvent) 164 subscribeId1 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
165 EventLogHelper::PrintEventData(keyEvent);
166 MMI_HILOGD("Subscribe key event KEYCODE_POWER down trigger callback");
167 });
168 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
169 EXPECT_TRUE(subscribeId1 >= 0);
170 #else
171 EXPECT_TRUE(subscribeId1 < 0);
172 #endif // OHOS_BUILD_ENABLE_KEYBOARD
173
174 // 电源键抬起订阅
175 std::shared_ptr<KeyOption> keyOption2 = InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_POWER, false, 0);
176 int32_t subscribeId2 = INVAID_VALUE;
__anond4639ab20302(std::shared_ptr<KeyEvent> keyEvent) 177 subscribeId2 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption2, [](std::shared_ptr<KeyEvent> keyEvent) {
178 EventLogHelper::PrintEventData(keyEvent);
179 MMI_HILOGD("Subscribe key event KEYCODE_POWER up trigger callback");
180 });
181 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
182 EXPECT_TRUE(subscribeId2 >= 0);
183 #else
184 EXPECT_TRUE(subscribeId2 < 0);
185 #endif // OHOS_BUILD_ENABLE_KEYBOARD
186
187 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
188 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId1);
189 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId2);
190 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
191 }
192
193 /**
194 * @tc.name: InputManagerTest_SubscribeKeyEvent_03
195 * @tc.desc: Verify subscribe volume up key event.
196 * @tc.type: FUNC
197 * @tc.require:
198 */
199 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_03, TestSize.Level1)
200 {
201 CALL_TEST_DEBUG;
202 ASSERT_TRUE(MMIEventHdl.InitClient());
203 std::set<int32_t> preKeys;
204 std::shared_ptr<KeyOption> keyOption1 =
205 InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_VOLUME_UP, true, FINAL_KEY_DOWN_DURATION_ONE);
206 int32_t subscribeId1 = INVAID_VALUE;
__anond4639ab20402(std::shared_ptr<KeyEvent> keyEvent) 207 subscribeId1 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption1, [](std::shared_ptr<KeyEvent> keyEvent) {
208 EventLogHelper::PrintEventData(keyEvent);
209 MMI_HILOGD("Subscribe key event KEYCODE_VOLUME_UP down trigger callback");
210 });
211 std::shared_ptr<KeyOption> keyOption2 =
212 InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_VOLUME_UP, false, 0);
213 int32_t subscribeId2 = INVAID_VALUE;
__anond4639ab20502(std::shared_ptr<KeyEvent> keyEvent) 214 subscribeId2 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption2, [](std::shared_ptr<KeyEvent> keyEvent) {
215 EventLogHelper::PrintEventData(keyEvent);
216 MMI_HILOGD("Subscribe key event KEYCODE_VOLUME_UP up trigger callback");
217 });
218 std::shared_ptr<KeyOption> keyOption3 = InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_VOLUME_UP, true, 0);
219 int32_t subscribeId3 = INVAID_VALUE;
__anond4639ab20602(std::shared_ptr<KeyEvent> keyEvent) 220 subscribeId3 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption3, [](std::shared_ptr<KeyEvent> keyEvent) {
221 EventLogHelper::PrintEventData(keyEvent);
222 MMI_HILOGD("Subscribe key event KEYCODE_VOLUME_UP down trigger callback");
223 });
224 std::shared_ptr<KeyOption> keyOption4 =
225 InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_VOLUME_UP, false, 0);
226 int32_t subscribeId4 = INVAID_VALUE;
__anond4639ab20702(std::shared_ptr<KeyEvent> keyEvent) 227 subscribeId4 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption4, [](std::shared_ptr<KeyEvent> keyEvent) {
228 EventLogHelper::PrintEventData(keyEvent);
229 MMI_HILOGD("Subscribe key event KEYCODE_VOLUME_UP up trigger callback");
230 });
231
232 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
233 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId1);
234 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId2);
235 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId3);
236 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId4);
237 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
238 }
239
240 /**
241 * @tc.name: InputManagerTest_SubscribeKeyEvent_04
242 * @tc.desc: Verify subscribe key event.
243 * @tc.type: FUNC
244 * @tc.require:
245 * @tc.author:
246 */
247 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_04, TestSize.Level1)
248 {
249 CALL_TEST_DEBUG;
250 std::set<int32_t> preKeys;
251 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
252 keyOption->SetPreKeys(preKeys);
253 keyOption->SetFinalKey(KeyEvent::KEYCODE_VOLUME_DOWN);
254 keyOption->SetFinalKeyDown(true);
255 keyOption->SetFinalKeyDownDuration(INVAID_VALUE);
256 int32_t subscribeId = INVAID_VALUE;
__anond4639ab20802(std::shared_ptr<KeyEvent> keyEvent) 257 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
258 EventLogHelper::PrintEventData(keyEvent);
259 MMI_HILOGD("Subscribe key event KEYCODE_POWER down trigger callback");
260 });
261 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
262 EXPECT_TRUE(subscribeId >= 0);
263 #else
264 EXPECT_TRUE(subscribeId < 0);
265 #endif // OHOS_BUILD_ENABLE_KEYBOARD
266 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
267 ASSERT_TRUE(injectDownEvent != nullptr);
268 int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
269 KeyEvent::KeyItem kitDown;
270 kitDown.SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
271 kitDown.SetPressed(true);
272 kitDown.SetDownTime(downTime);
273 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
274 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
275 injectDownEvent->AddPressedKeyItems(kitDown);
276 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
277 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN);
278 }
279
280 /**
281 * @tc.name: TestGetKeystrokeAbility_001
282 * @tc.desc: Verify SupportKeys
283 * @tc.type: FUNC
284 * @tc.require:
285 */
286 HWTEST_F(InputManagerTest, TestGetKeystrokeAbility_001, TestSize.Level1)
287 {
288 CALL_TEST_DEBUG;
289 std::vector<int32_t> keyCodes = {
290 KeyEvent::KEYCODE_VOLUME_DOWN, KeyEvent::KEYCODE_VOLUME_MUTE, KeyEvent::KEYCODE_DEL};
291 int32_t result = InputManager::GetInstance()->SupportKeys(
__anond4639ab20902(std::vector<bool> keystrokeAbility) 292 0, keyCodes, [](std::vector<bool> keystrokeAbility) { MMI_HILOGD("TestGetKeystrokeAbility_001 callback ok"); });
293 ASSERT_EQ(result, 0);
294 MMI_HILOGD("Stop TestGetKeystrokeAbility_001");
295 }
296
297 /**
298 * @tc.name: InputManagerTest_RemoteControlAutoRepeat
299 * @tc.desc: After the key is pressed, repeatedly trigger the key to press the input
300 * @tc.type: FUNC
301 * @tc.require: I530XB
302 */
303 HWTEST_F(InputManagerTest, InputManagerTest_RemoteControlAutoRepeat, TestSize.Level1)
304 {
305 CALL_TEST_DEBUG;
306 int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
307 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
308 injectDownEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
309 ASSERT_TRUE(injectDownEvent != nullptr);
310 KeyEvent::KeyItem kitDown;
311 kitDown.SetKeyCode(KeyEvent::KEYCODE_A);
312 kitDown.SetPressed(true);
313 kitDown.SetDownTime(downTime);
314 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_A);
315 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
316 injectDownEvent->AddPressedKeyItems(kitDown);
317 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
318 SimulateInputEventUtilTest(injectDownEvent);
319 #endif // OHOS_BUILD_ENABLE_KEYBOARD
320
321 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
322
323 std::shared_ptr<KeyEvent> injectUpEvent = KeyEvent::Create();
324 ASSERT_TRUE(injectUpEvent != nullptr);
325 downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
326 KeyEvent::KeyItem kitUp;
327 kitUp.SetKeyCode(KeyEvent::KEYCODE_A);
328 kitUp.SetPressed(false);
329 kitUp.SetDownTime(downTime);
330 injectUpEvent->SetKeyCode(KeyEvent::KEYCODE_A);
331 injectUpEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
332 injectUpEvent->RemoveReleasedKeyItems(kitUp);
333 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
334 SimulateInputEventUtilTest(injectUpEvent);
335 #endif // OHOS_BUILD_ENABLE_KEYBOARD
336 }
337
338 static int32_t deviceIDtest = 0;
GetKeyboardTypeCallback(int32_t keyboardType)339 static void GetKeyboardTypeCallback(int32_t keyboardType)
340 {
341 switch (keyboardType) {
342 case KEYBOARD_TYPE_NONE: {
343 MMI_HILOGD("deviceIDtest:%{public}d-->KeyboardType:%{public}s", deviceIDtest, "None");
344 break;
345 }
346 case KEYBOARD_TYPE_UNKNOWN: {
347 MMI_HILOGD("deviceIDtest:%{public}d-->KeyboardType:%{public}s", deviceIDtest, "unknown");
348 break;
349 }
350 case KEYBOARD_TYPE_ALPHABETICKEYBOARD: {
351 MMI_HILOGD("deviceIDtest:%{public}d-->KeyboardType:%{public}s", deviceIDtest, "alphabetickeyboard");
352 break;
353 }
354 case KEYBOARD_TYPE_DIGITALKEYBOARD: {
355 MMI_HILOGD("deviceIDtest:%{public}d-->KeyboardType:%{public}s", deviceIDtest, "digitalkeyboard");
356 break;
357 }
358 case KEYBOARD_TYPE_HANDWRITINGPEN: {
359 MMI_HILOGD("deviceIDtest:%{public}d-->KeyboardType:%{public}s", deviceIDtest, "handwritingpen");
360 break;
361 }
362 case KEYBOARD_TYPE_REMOTECONTROL: {
363 MMI_HILOGD("deviceIDtest:%{public}d-->KeyboardType:%{public}s", deviceIDtest, "remotecontrol");
364 break;
365 }
366 default: {
367 MMI_HILOGW("Error obtaining keyboard type");
368 break;
369 }
370 }
371 }
372
373 /**
374 * @tc.name: InputManagerTest_GetKeyboardType
375 * @tc.desc: Verify Get Keyboard Type
376 * @tc.type: FUNC
377 * @tc.require:
378 */
379 HWTEST_F(InputManagerTest, InputManagerTest_GetKeyboardType, TestSize.Level1)
380 {
381 MMI_HILOGD("Start InputManagerTest_GetKeyboardType");
382 for (int32_t i = 0; i < KEYBOARD_TYPE_SIZE; ++i) {
383 deviceIDtest = i;
384 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->GetKeyboardType(i, GetKeyboardTypeCallback));
385 MMI_HILOGD("i:%{public}d", i);
386 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
387 }
388 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
389 MMI_HILOGD("Stop InputManagerTest_GetKeyboardType");
390 }
391
392 /**
393 * @tc.name: InputManagerTest_SetKeyboardRepeatDelay
394 * @tc.desc: Verify Set Keyboard Repeat Delay
395 * @tc.type: FUNC
396 * @tc.require:
397 */
398 HWTEST_F(InputManagerTest, InputManagerTest_SetKeyboardRepeatDelay, TestSize.Level1)
399 {
400 MMI_HILOGD("Start InputManagerTest_SetKeyboardRepeatDelay");
401 int32_t ret = InputManager::GetInstance()->SetKeyboardRepeatDelay(KEY_REPEAT_DELAY);
402 ASSERT_EQ(ret, RET_OK);
403 const char *keyboardFileName = "/data/service/el1/public/multimodalinput/keyboard_settings.xml";
404 ASSERT_TRUE(remove(keyboardFileName) == RET_OK);
405 MMI_HILOGD("Stop InputManagerTest_SetKeyboardRepeatDelay");
406 }
407
408 /**
409 * @tc.name: InputManagerTest_SetKeyboardRepeatRate
410 * @tc.desc: Verify Set Keyboard Repeat Rate
411 * @tc.type: FUNC
412 * @tc.require:
413 */
414 HWTEST_F(InputManagerTest, InputManagerTest_SetKeyboardRepeatRate, TestSize.Level1)
415 {
416 MMI_HILOGD("Start InputManagerTest_SetKeyboardRepeatRate");
417 int32_t ret = InputManager::GetInstance()->SetKeyboardRepeatRate(KEY_REPEAT_RATE);
418 ASSERT_EQ(ret, RET_OK);
419 const char *keyboardFileName = "/data/service/el1/public/multimodalinput/keyboard_settings.xml";
420 ASSERT_TRUE(remove(keyboardFileName) == RET_OK);
421 MMI_HILOGD("Stop InputManagerTest_SetKeyboardRepeatRate");
422 }
423
424 /**
425 * @tc.name: InputManagerTest_GetKeyboardRepeatDelay
426 * @tc.desc: Verify Get Keyboard Repeat Delay
427 * @tc.type: FUNC
428 * @tc.require:
429 */
430 HWTEST_F(InputManagerTest, InputManagerTest_GetKeyboardRepeatDelay, TestSize.Level1)
431 {
432 MMI_HILOGD("Start InputManagerTest_GetKeyboardRepeatDelay");
__anond4639ab20a02(int32_t delay) 433 auto callback = [](int32_t delay) {
434 ASSERT_TRUE(delay == KEY_REPEAT_DELAY);
435 MMI_HILOGD("Get keyboard repeat delay success");
436 };
437 if (InputManager::GetInstance()->SetKeyboardRepeatDelay(KEY_REPEAT_DELAY) == RET_OK) {
438 ASSERT_TRUE(InputManager::GetInstance()->GetKeyboardRepeatDelay(callback) == RET_OK);
439 }
440 const char *keyboardFileName = "/data/service/el1/public/multimodalinput/keyboard_settings.xml";
441 ASSERT_TRUE(remove(keyboardFileName) == RET_OK);
442 MMI_HILOGD("Stop InputManagerTest_GetKeyboardRepeatDelay");
443 }
444
445 /**
446 * @tc.name: InputManagerTest_GetKeyboardRepeatRate
447 * @tc.desc: Verify Get Keyboard Repeat Rate
448 * @tc.type: FUNC
449 * @tc.require:
450 */
451 HWTEST_F(InputManagerTest, InputManagerTest_GetKeyboardRepeatRate, TestSize.Level1)
452 {
453 MMI_HILOGD("Start InputManagerTest_GetKeyboardRepeatRate");
__anond4639ab20b02(int32_t rate) 454 auto callback = [](int32_t rate) {
455 ASSERT_TRUE(rate == KEY_REPEAT_RATE);
456 MMI_HILOGD("Get keyboard repeat rate success");
457 };
458 if (InputManager::GetInstance()->SetKeyboardRepeatRate(KEY_REPEAT_RATE) == RET_OK) {
459 ASSERT_TRUE(InputManager::GetInstance()->GetKeyboardRepeatRate(callback) == RET_OK);
460 }
461 const char *keyboardFileName = "/data/service/el1/public/multimodalinput/keyboard_settings.xml";
462 ASSERT_TRUE(remove(keyboardFileName) == RET_OK);
463 MMI_HILOGD("Stop InputManagerTest_GetKeyboardRepeatRate");
464 }
465
466 HWTEST_F(InputManagerTest, InputManagerTest_GetProcCpuUsage, TestSize.Level1)
467 {
468 CALL_TEST_DEBUG;
469 SYSTEM_INFO::CpuInfo cpuInfo;
470 const std::string process_name = "multimodalinput";
471 auto usage = cpuInfo.GetProcCpuUsage(process_name);
472 MMI_HILOGD("The CPU usage of the %{public}s process is %{public}.2f", process_name.c_str(), usage);
473 ASSERT_TRUE(usage < SYSTEM_INFO::CPU_USAGE_LOAD && usage != SYSTEM_INFO::CPU_USAGE_UNKNOWN);
474 }
475
476 /**
477 * @tc.name: InputManagerTest_FunctionKeyState_001
478 * @tc.desc: Set NumLock for the keyboard enablement state to true
479 * @tc.type: FUNC
480 * @tc.require: I5HMCX
481 */
482 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_001, TestSize.Level1)
483 {
484 CALL_TEST_DEBUG;
485 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::NUM_LOCK_FUNCTION_KEY, true);
486 ASSERT_FALSE(InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::NUM_LOCK_FUNCTION_KEY));
487 }
488
489 /**
490 * @tc.name: InputManagerTest_FunctionKeyState_002
491 * @tc.desc: Set NumLock for the keyboard enablement state to false
492 * @tc.type: FUNC
493 * @tc.require: I5HMCX
494 */
495 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_002, TestSize.Level1)
496 {
497 CALL_TEST_DEBUG;
498 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::NUM_LOCK_FUNCTION_KEY, false);
499 bool result = InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::NUM_LOCK_FUNCTION_KEY);
500 ASSERT_FALSE(result);
501 }
502
503 /**
504 * @tc.name: InputManagerTest_FunctionKeyState_003
505 * @tc.desc: Set ScrollLock for the keyboard enablement state to true
506 * @tc.type: FUNC
507 * @tc.require: I5HMCX
508 */
509 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_003, TestSize.Level1)
510 {
511 CALL_TEST_DEBUG;
512 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::SCROLL_LOCK_FUNCTION_KEY, true);
513 ASSERT_FALSE(InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::SCROLL_LOCK_FUNCTION_KEY));
514 }
515
516 /**
517 * @tc.name: InputManagerTest_FunctionKeyState_004
518 * @tc.desc: Set ScrollLock for the keyboard enablement state to false
519 * @tc.type: FUNC
520 * @tc.require: I5HMCX
521 */
522 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_004, TestSize.Level1)
523 {
524 CALL_TEST_DEBUG;
525 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::SCROLL_LOCK_FUNCTION_KEY, false);
526 bool result = InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::SCROLL_LOCK_FUNCTION_KEY);
527 ASSERT_FALSE(result);
528 }
529
530 /**
531 * @tc.name: InputManagerTest_FunctionKeyState_005
532 * @tc.desc: Set CapsLock for the keyboard enablement state to true
533 * @tc.type: FUNC
534 * @tc.require: I5HMCX
535 */
536 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_005, TestSize.Level1)
537 {
538 CALL_TEST_DEBUG;
539 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::CAPS_LOCK_FUNCTION_KEY, true);
540 ASSERT_FALSE(InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::CAPS_LOCK_FUNCTION_KEY));
541 }
542
543 /**
544 * @tc.name: InputManagerTest_FunctionKeyState_006
545 * @tc.desc: Set CapsLock for the keyboard enablement state to false
546 * @tc.type: FUNC
547 * @tc.require: I5HMCX
548 */
549 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_006, TestSize.Level1)
550 {
551 CALL_TEST_DEBUG;
552 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::CAPS_LOCK_FUNCTION_KEY, false);
553 bool result = InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::CAPS_LOCK_FUNCTION_KEY);
554 ASSERT_FALSE(result);
555 }
556
557 /**
558 * @tc.name: InputManagerTest_FunctionKeyState_007
559 * @tc.desc: Set other function keys
560 * @tc.type: FUNC
561 * @tc.require: I5HMCX
562 */
563 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_007, TestSize.Level1)
564 {
565 CALL_TEST_DEBUG;
566 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::UNKNOWN_FUNCTION_KEY, true);
567 bool result = InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::UNKNOWN_FUNCTION_KEY);
568 ASSERT_FALSE(result);
569
570 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::UNKNOWN_FUNCTION_KEY, false);
571 result = InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::UNKNOWN_FUNCTION_KEY);
572 ASSERT_FALSE(result);
573 }
574
575 /**
576 * @tc.name: InputManagerTest_TouchScreenHotArea_001
577 * @tc.desc: Touch event Search window by defaultHotAreas
578 * @tc.type: FUNC
579 * @tc.require: I5HMCB
580 */
581 HWTEST_F(InputManagerTest, InputManagerTest_TouchScreenHotArea_001, TestSize.Level1)
582 {
583 CALL_TEST_DEBUG;
584 std::shared_ptr<PointerEvent> pointerEvent{InputManagerUtil::SetupTouchScreenEvent001()};
585 ASSERT_TRUE(pointerEvent != nullptr);
586 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
587 ASSERT_EQ(pointerEvent->GetSourceType(), PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
588 }
589
590 /**
591 * @tc.name: InputManagerTest_TouchScreenHotArea_002
592 * @tc.desc: Touch event Search window by pointerHotAreas
593 * @tc.type: FUNC
594 * @tc.require: I5HMCB
595 */
596 HWTEST_F(InputManagerTest, InputManagerTest_TouchScreenHotArea_002, TestSize.Level1)
597 {
598 CALL_TEST_DEBUG;
599 std::shared_ptr<PointerEvent> pointerEvent{InputManagerUtil::SetupTouchScreenEvent002()};
600 ASSERT_TRUE(pointerEvent != nullptr);
601 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
602 ASSERT_EQ(pointerEvent->GetSourceType(), PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
603 }
604
605 /**
606 * @tc.name: InputManagerTest_UpdateDisplayInfo
607 * @tc.desc: Update window information
608 * @tc.type: FUNC
609 * @tc.require:
610 */
611 HWTEST_F(InputManagerTest, InputManagerTest_UpdateDisplayInfo, TestSize.Level1)
612 {
613 CALL_TEST_DEBUG;
614 DisplayGroupInfo displayGroupInfo;
615 displayGroupInfo.focusWindowId = 0;
616 displayGroupInfo.width = 0;
617 displayGroupInfo.height = 0;
618 InputManager::GetInstance()->UpdateDisplayInfo(displayGroupInfo);
619 ASSERT_TRUE(displayGroupInfo.displaysInfo.empty());
620 }
621
622 #ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT
623 /**
624 * @tc.name: InputManagerTest_SetEnhanceConfig_001
625 * @tc.desc: Set Secutity component enhance config
626 * @tc.type: FUNC
627 * @tc.require:
628 */
629 HWTEST_F(InputManagerTest, InputManagerTest_SetEnhanceConfig_001, TestSize.Level1)
630 {
631 CALL_TEST_DEBUG;
632 uint8_t cfgData[16] = {0};
633 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->SetEnhanceConfig(cfgData, 16));
634 }
635 #endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT
636
637 /**
638 * @tc.name: InputManagerTest_GetDevice_001
639 * @tc.desc: Verify the fetch device info
640 * @tc.type: FUNC
641 * @tc.require:
642 */
643 HWTEST_F(InputManagerTest, InputManagerTest_GetDevice_001, TestSize.Level1)
644 {
645 CALL_TEST_DEBUG;
646 int32_t deviceId = 0;
__anond4639ab20c02(std::shared_ptr<InputDevice> inputDevice) 647 auto callback = [](std::shared_ptr<InputDevice> inputDevice) {
648 MMI_HILOGD("Get device success");
649 ASSERT_TRUE(inputDevice != nullptr);
650 };
651 InputManager::GetInstance()->GetDevice(deviceId, callback);
652 }
653
654 /**
655 * @tc.name: InputManagerTest_GetDevice_002
656 * @tc.desc: Verify the fetch device info
657 * @tc.type: FUNC
658 * @tc.require:
659 */
660 HWTEST_F(InputManagerTest, InputManagerTest_GetDevice_002, TestSize.Level1)
661 {
662 CALL_TEST_DEBUG;
663 int32_t deviceId = INVAID_VALUE;
__anond4639ab20d02(std::shared_ptr<InputDevice> inputDevice) 664 auto callback = [](std::shared_ptr<InputDevice> inputDevice) {
665 MMI_HILOGD("Get device success");
666 ASSERT_TRUE(inputDevice != nullptr);
667 };
668 int32_t ret = InputManager::GetInstance()->GetDevice(deviceId, callback);
669 ASSERT_NE(ret, RET_OK);
670 }
671
672 /**
673 * @tc.name: InputManagerTest_GetDeviceIds
674 * @tc.desc: Verify the fetch device list
675 * @tc.type: FUNC
676 * @tc.require:
677 */
678 HWTEST_F(InputManagerTest, InputManagerTest_GetDeviceIds, TestSize.Level1)
679 {
680 CALL_TEST_DEBUG;
__anond4639ab20e02(std::vector<int32_t> ids) 681 auto callback = [](std::vector<int32_t> ids) { MMI_HILOGD("Get device success"); };
682 int32_t ret = InputManager::GetInstance()->GetDeviceIds(callback);
683 ASSERT_EQ(ret, RET_OK);
684 }
685
686 /**
687 * @tc.name: InputManagerTest_EventTypeToString
688 * @tc.desc: Verify inputevent interface
689 * @tc.type: FUNC
690 * @tc.require:
691 */
692 HWTEST_F(InputManagerTest, InputManagerTest_EventTypeToString, TestSize.Level1)
693 {
694 CALL_TEST_DEBUG;
695 auto inputEvent = InputEvent::Create();
696 ASSERT_NE(inputEvent, nullptr);
697 auto ret = inputEvent->EventTypeToString(InputEvent::EVENT_TYPE_BASE);
698 ASSERT_STREQ(ret, "base");
699 ret = inputEvent->EventTypeToString(InputEvent::EVENT_TYPE_KEY);
700 ASSERT_STREQ(ret, "key");
701 ret = inputEvent->EventTypeToString(InputEvent::EVENT_TYPE_AXIS);
702 ASSERT_STREQ(ret, "axis");
703 ret = inputEvent->EventTypeToString(INVAID_VALUE);
704 ASSERT_STREQ(ret, "unknown");
705 }
706
707 /**
708 * @tc.name: InputManagerTest_InputDeviceInterface_001
709 * @tc.desc: Verify inputdevice interface
710 * @tc.type: FUNC
711 * @tc.require:
712 */
713 HWTEST_F(InputManagerTest, InputManagerTest_InputDeviceInterface_001, TestSize.Level1)
714 {
715 CALL_TEST_DEBUG;
716 std::shared_ptr<InputDevice> inputDevice = std::make_shared<InputDevice>();
717 ASSERT_NE(inputDevice, nullptr);
718 inputDevice->SetId(0);
719 ASSERT_EQ(inputDevice->GetId(), 0);
720 inputDevice->SetName("name");
721 ASSERT_STREQ(inputDevice->GetName().c_str(), "name");
722 inputDevice->SetType(0);
723 ASSERT_EQ(inputDevice->GetType(), 0);
724 inputDevice->SetBus(0);
725 ASSERT_EQ(inputDevice->GetBus(), 0);
726 inputDevice->SetVersion(0);
727 ASSERT_EQ(inputDevice->GetVersion(), 0);
728 inputDevice->SetProduct(0);
729 ASSERT_EQ(inputDevice->GetProduct(), 0);
730 inputDevice->SetVendor(0);
731 ASSERT_EQ(inputDevice->GetVendor(), 0);
732 inputDevice->SetPhys("phys");
733 ASSERT_STREQ(inputDevice->GetPhys().c_str(), "phys");
734 inputDevice->SetUniq("uniq");
735 ASSERT_STREQ(inputDevice->GetUniq().c_str(), "uniq");
736 }
737
738 /**
739 * @tc.name: InputManagerTest_InputDeviceInterface_002
740 * @tc.desc: Verify inputdevice interface
741 * @tc.type: FUNC
742 * @tc.require:
743 */
744 HWTEST_F(InputManagerTest, InputManagerTest_InputDeviceInterface_002, TestSize.Level1)
745 {
746 CALL_TEST_DEBUG;
747 std::shared_ptr<InputDevice> inputDevice = std::make_shared<InputDevice>();
748 ASSERT_NE(inputDevice, nullptr);
749 InputDevice::AxisInfo axis;
750 axis.SetAxisType(0);
751 axis.SetMinimum(0);
752 axis.SetMaximum(1);
753 axis.SetFuzz(0);
754 axis.SetFlat(1);
755 axis.SetResolution(0);
756 inputDevice->AddAxisInfo(axis);
757 auto iter = inputDevice->GetAxisInfo();
758 ASSERT_EQ(iter[0].GetAxisType(), 0);
759 ASSERT_EQ(iter[0].GetMinimum(), 0);
760 ASSERT_EQ(iter[0].GetMaximum(), 1);
761 ASSERT_EQ(iter[0].GetFuzz(), 0);
762 ASSERT_EQ(iter[0].GetFlat(), 1);
763 ASSERT_EQ(iter[0].GetResolution(), 0);
764 }
765
766 /**
767 * @tc.name: InputManagerTest_SetAnrObserver
768 * @tc.desc: Verify the observer for events
769 * @tc.type: FUNC
770 * @tc.require:
771 */
772 HWTEST_F(InputManagerTest, InputManagerTest_SetAnrObserver, TestSize.Level1)
773 {
774 CALL_TEST_DEBUG;
775 class IAnrObserverTest : public IAnrObserver {
776 public:
IAnrObserverTest()777 IAnrObserverTest() : IAnrObserver()
778 {}
~IAnrObserverTest()779 virtual ~IAnrObserverTest()
780 {}
OnAnr(int32_t pid) const781 void OnAnr(int32_t pid) const override
782 {
783 MMI_HILOGD("Set anr success");
784 };
785 };
786
787 std::shared_ptr<IAnrObserverTest> observer = std::make_shared<IAnrObserverTest>();
788 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->SetAnrObserver(observer));
789 }
790
791 #ifdef OHOS_BUILD_ENABLE_INTERCEPTOR
792 /**
793 * @tc.name: InputManagerTest_InterceptTabletToolEvent_001
794 * @tc.desc: Verify intercepting tablet tool event
795 * @tc.type: FUNC
796 * @tc.require:
797 */
798 HWTEST_F(InputManagerTest, InputManagerTest_InterceptTabletToolEvent_001, TestSize.Level1)
799 {
800 CALL_TEST_DEBUG;
801 auto interceptor = GetPtr<InputEventCallback>();
802 int32_t interceptorId{InputManager::GetInstance()->AddInterceptor(interceptor)};
803 EXPECT_TRUE(IsValidHandlerId(interceptorId));
804 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
805
806 #ifdef OHOS_BUILD_ENABLE_TOUCH
807 auto pointerEvent = InputManagerUtil::SetupTabletToolEvent001();
808 ASSERT_NE(pointerEvent, nullptr);
809 TestSimulateInputEvent(pointerEvent);
810
811 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
812 TestSimulateInputEvent(pointerEvent);
813 #endif // OHOS_BUILD_ENABLE_TOUCH
814
815 if (IsValidHandlerId(interceptorId)) {
816 InputManager::GetInstance()->RemoveInterceptor(interceptorId);
817 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
818 }
819 }
820 #endif // OHOS_BUILD_ENABLE_INTERCEPTOR
821
822 #ifdef OHOS_BUILD_ENABLE_TOUCH
823 HWTEST_F(InputManagerTest, AppendExtraData_001, TestSize.Level1)
824 {
825 CALL_TEST_DEBUG;
826 auto consumer = GetPtr<InputEventConsumer>();
827 ASSERT_TRUE(consumer != nullptr);
828 const std::string threadTest = "EventUtilTest";
829 auto runner = AppExecFwk::EventRunner::Create(threadTest);
830 ASSERT_TRUE(runner != nullptr);
831 auto eventHandler = std::make_shared<AppExecFwk::EventHandler>(runner);
832 MMI::InputManager::GetInstance()->SetWindowInputEventConsumer(consumer, eventHandler);
833 std::vector<uint8_t> buffer(BUFFER_SIZE, 1);
834 ExtraData extraData;
835 extraData.appended = true;
836 extraData.buffer = buffer;
837 extraData.sourceType = PointerEvent::SOURCE_TYPE_TOUCHSCREEN;
838 extraData.pointerId = 1;
839 InputManager::GetInstance()->AppendExtraData(extraData);
840 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
841 auto pointerEvent = InputManagerUtil::SetupPointerEvent001();
842 pointerEvent->AddFlag(PointerEvent::EVENT_FLAG_NO_INTERCEPT);
843 ASSERT_TRUE(pointerEvent != nullptr);
844 TestSimulateInputEvent(pointerEvent, TestScene::EXCEPTION_TEST);
845
846 extraData.appended = false;
847 extraData.buffer.clear();
848 extraData.pointerId = INVAID_VALUE;
849 InputManager::GetInstance()->AppendExtraData(extraData);
850 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
851 ASSERT_TRUE(pointerEvent != nullptr);
852 SimulateInputEventUtilTest(pointerEvent);
853 }
854 #endif // OHOS_BUILD_ENABLE_TOUCH
855
856 #ifdef OHOS_BUILD_ENABLE_POINTER
857 HWTEST_F(InputManagerTest, AppendExtraData_002, TestSize.Level1)
858 {
859 CALL_TEST_DEBUG;
860 std::vector<uint8_t> buffer(BUFFER_SIZE, 1);
861 ExtraData extraData;
862 extraData.appended = true;
863 extraData.buffer = buffer;
864 extraData.sourceType = PointerEvent::SOURCE_TYPE_MOUSE;
865 InputManager::GetInstance()->AppendExtraData(extraData);
866 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
867 auto pointerEvent = InputManagerUtil::SetupPointerEvent006();
868 pointerEvent->AddFlag(PointerEvent::EVENT_FLAG_NO_INTERCEPT);
869 ASSERT_TRUE(pointerEvent != nullptr);
870 TestSimulateInputEvent(pointerEvent, TestScene::EXCEPTION_TEST);
871
872 extraData.appended = false;
873 extraData.buffer.clear();
874 InputManager::GetInstance()->AppendExtraData(extraData);
875 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
876 ASSERT_TRUE(pointerEvent != nullptr);
877 SimulateInputEventUtilTest(pointerEvent);
878 }
879 #endif // OHOS_BUILD_ENABLE_POINTER
880
881 /**
882 * @tc.name: InputManagerTest_EnableInputDevice_001
883 * @tc.desc: Enable input device
884 * @tc.type: FUNC
885 * @tc.require:
886 */
887 HWTEST_F(InputManagerTest, InputManagerTest_EnableInputDevice_001, TestSize.Level1)
888 {
889 CALL_TEST_DEBUG;
890 auto ret = InputManager::GetInstance()->EnableInputDevice(false);
891 ASSERT_EQ(ret, RET_OK);
892 ret = InputManager::GetInstance()->EnableInputDevice(true);
893 ASSERT_EQ(ret, RET_OK);
894 }
895
896 /**
897 * @tc.name: InputManagerTest_SensorInputTime_001
898 * @tc.desc: Test SensorTime
899 * @tc.type: FUNC
900 * @tc.require:
901 */
902 HWTEST_F(InputManagerTest, InputManagerTest_SensorInputTime_001, TestSize.Level1)
903 {
904 CALL_TEST_DEBUG;
905 auto pointerEvent = PointerEvent::Create();
906 ASSERT_TRUE(pointerEvent != nullptr);
907 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
908 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
909 pointerEvent->SetPointerId(0);
910 pointerEvent->SetSensorInputTime(POINTER_SENSOR_INPUT_TIME);
911 ASSERT_TRUE(pointerEvent->GetSensorInputTime() == POINTER_SENSOR_INPUT_TIME);
912 }
913
914 /**
915 * @tc.name: InputManagerTest_GetDisplayBindInfo_001
916 * @tc.desc: Get diaplay bind information
917 * @tc.type: FUNC
918 * @tc.require:
919 */
920 HWTEST_F(InputManagerTest, InputManagerTest_GetDisplayBindInfo_001, TestSize.Level1)
921 {
922 CALL_TEST_DEBUG;
923 OHOS::MMI::DisplayBindInfos infos;
924 int32_t ret = InputManager::GetInstance()->GetDisplayBindInfo(infos);
925 ASSERT_TRUE(ret == RET_OK);
926 if (ret != RET_OK) {
927 MMI_HILOGE("Call GetDisplayBindInfo failed, ret:%{public}d", ret);
928 }
929 }
930
931 /**
932 * @tc.name: InputManagerTest_SetDisplayBind_001
933 * @tc.desc: Set diaplay bind information
934 * @tc.type: FUNC
935 * @tc.require:
936 */
937 HWTEST_F(InputManagerTest, InputManagerTest_SetDisplayBind_001, TestSize.Level1)
938 {
939 CALL_TEST_DEBUG;
940 int32_t deviceId = DEFAULT_DEVICE_ID;
941 int32_t displayId = INVAID_VALUE;
942 std::string msg;
943 int32_t ret = InputManager::GetInstance()->SetDisplayBind(deviceId, displayId, msg);
944 ASSERT_TRUE(ret == RET_OK);
945 if (ret != RET_OK) {
946 MMI_HILOGE("Call SetDisplayBind failed, ret:%{public}d", ret);
947 }
948 }
949
950 /**
951 * @tc.name: InputManagerTest_MarkConsumed_001
952 * @tc.desc: Mark Cosumer
953 * @tc.type: FUNC
954 * @tc.require:
955 */
956 HWTEST_F(InputManagerTest, InputManagerTest_MarkConsumed_001, TestSize.Level1)
957 {
958 CALL_TEST_DEBUG;
959 auto consumer = GetPtr<InputEventConsumer>();
960 ASSERT_TRUE(consumer != nullptr);
961 int32_t monitorId = InputManager::GetInstance()->AddMonitor(consumer);
962 auto pointerEvent = PointerEvent::Create();
963 ASSERT_TRUE(pointerEvent != nullptr);
964 auto eventId = pointerEvent->GetId();
965 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->MarkConsumed(monitorId, eventId));
966 }
967
968 /**
969 * @tc.name: InputManagerTest_SimulateInputEventToHmosContainer_001
970 * @tc.desc: Simulate input event to HmosContainer
971 * @tc.type: FUNC
972 * @tc.require:
973 */
974 HWTEST_F(InputManagerTest, InputManagerTest_SimulateInputEventToHmosContainer_001, TestSize.Level1)
975 {
976 CALL_TEST_DEBUG;
977 auto pointerEvent = PointerEvent::Create();
978 ASSERT_TRUE(pointerEvent != nullptr);
979 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->SimulateInputEventToHmosContainer(pointerEvent));
980 }
981
982 /**
983 * @tc.name: InputManagerTest_EnterCaptureMode_001
984 * @tc.desc: Entering capture mode.
985 * @tc.type: FUNC
986 * @tc.require:
987 */
988 HWTEST_F(InputManagerTest, InputManagerTest_EnterCaptureMode_001, TestSize.Level1)
989 {
990 CALL_TEST_DEBUG;
991 auto window = WindowUtilsTest::GetInstance()->GetWindow();
992 CHKPV(window);
993 uint32_t windowId = window->GetWindowId();
994 int32_t ret = InputManager::GetInstance()->EnterCaptureMode(windowId);
995 ASSERT_TRUE(ret == RET_OK);
996 if (ret != RET_OK) {
997 MMI_HILOGE("Call EnterCaptureMode failed, ret:%{public}d", ret);
998 }
999 }
1000
1001 /**
1002 * @tc.name: InputManagerTest_LeaveCaptureMode_001
1003 * @tc.desc: Leaving capture mode.
1004 * @tc.type: FUNC
1005 * @tc.require:
1006 */
1007 HWTEST_F(InputManagerTest, InputManagerTest_LeaveCaptureMode_001, TestSize.Level1)
1008 {
1009 CALL_TEST_DEBUG;
1010 auto window = WindowUtilsTest::GetInstance()->GetWindow();
1011 CHKPV(window);
1012 uint32_t windowId = window->GetWindowId();
1013 int32_t ret = InputManager::GetInstance()->LeaveCaptureMode(windowId);
1014 ASSERT_TRUE(ret == RET_OK);
1015 if (ret != RET_OK) {
1016 MMI_HILOGE("Call LeaveCaptureMode failed, ret:%{public}d", ret);
1017 }
1018 }
1019
1020 /**
1021 * @tc.name: InputManagerTest_GetWindowPid_001
1022 * @tc.desc: Get window pid.
1023 * @tc.type: FUNC
1024 * @tc.require:
1025 */
1026 HWTEST_F(InputManagerTest, InputManagerTest_GetWindowPid_001, TestSize.Level1)
1027 {
1028 CALL_TEST_DEBUG;
1029 auto window = WindowUtilsTest::GetInstance()->GetWindow();
1030 CHKPV(window);
1031 uint32_t windowId = window->GetWindowId();
1032 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->GetWindowPid(windowId));
1033 int32_t ret = InputManager::GetInstance()->GetWindowPid(windowId);
1034 if (ret == RET_ERR) {
1035 MMI_HILOGE("Call GetWindowPid failed, ret:%{public}d", ret);
1036 }
1037 }
1038
1039 /**
1040 * @tc.name: InputManagerTest_SetKeyDownDuration_001
1041 * @tc.desc: Customize the delay time for starting the ability by using the shortcut key.
1042 * @tc.type: FUNC
1043 * @tc.require:
1044 */
1045 HWTEST_F(InputManagerTest, InputManagerTest_SetKeyDownDuration_001, TestSize.Level1)
1046 {
1047 CALL_TEST_DEBUG;
1048 std::string businessId = "";
1049 int32_t delay = KEY_DOWN_DURATION;
1050 ASSERT_EQ(PARAMETER_ERROR, InputManager::GetInstance()->SetKeyDownDuration(businessId, delay));
1051 }
1052
1053 /**
1054 * @tc.name: InputManagerTest_UnsubscribeSwitchEvent_001
1055 * @tc.desc: Unsubscribes from a switch input event.
1056 * @tc.type: FUNC
1057 * @tc.require:
1058 */
1059 HWTEST_F(InputManagerTest, InputManagerTest_UnsubscribeSwitchEvent_001, TestSize.Level1)
1060 {
1061 CALL_TEST_DEBUG;
1062 int32_t subscriberId = INVAID_VALUE;
1063 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UnsubscribeSwitchEvent(subscriberId));
1064 }
1065 } // namespace MMI
1066 } // namespace OHOS