1 /*
2 * Copyright (c) 2021-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 <cinttypes>
17 #include <semaphore.h>
18
19 #include "event_log_helper.h"
20 #include "event_util_test.h"
21 #include "input_manager.h"
22 #include "input_manager_util.h"
23 #include "multimodal_event_handler.h"
24 #include "system_info.h"
25
26 #undef MMI_LOG_TAG
27 #define MMI_LOG_TAG "InputManagerTest"
28
29 namespace OHOS {
30 namespace MMI {
31 namespace {
32 constexpr int32_t TUPLE_PID = 0;
33 constexpr int32_t TUPLE_UID = 1;
34 constexpr int32_t TUPLE_NAME = 2;
35 constexpr int32_t ITEM_WIDTH = 20;
36 constexpr int32_t ITEM_HEIGHT = 60;
37 constexpr int32_t TIME_WAIT_FOR_OP = 100;
38 constexpr int32_t NANOSECOND_TO_MILLISECOND = 1000000;
39 constexpr int32_t SLEEP_MILLISECONDS = 1000;
40 constexpr int32_t DEFAULT_DEVICE_ID = 0;
41 constexpr int32_t KEY_REPEAT_DELAY = 350;
42 constexpr int32_t KEY_REPEAT_RATE = 60;
43 constexpr int32_t POINTER_ITEM_DISPLAY_X_ONE = 147;
44 constexpr int32_t POINTER_ITEM_DISPLAY_X_TWO = 456;
45 constexpr int32_t POINTER_ITEM_DISPLAY_Y_ONE = 123;
46 constexpr int32_t POINTER_ITEM_DISPLAY_Y_TWO = 258;
47 constexpr int32_t POINTER_ITEM_WINDOW_X = 701;
48 constexpr int32_t POINTER_ITEM_WINDOW_Y = 702;
49 constexpr int32_t KEY_DOWN_DURATION = 300;
50 constexpr int32_t FINAL_KEY_DOWN_DURATION_ONE = 10;
51 constexpr int32_t FINAL_KEY_DOWN_DURATION_TWO = 2000;
52 constexpr int32_t POINTER_SENSOR_INPUT_TIME = 2000;
53 constexpr int32_t KEYBOARD_TYPE_SIZE = 20;
54 constexpr int32_t PARAMETER_ERROR = 401;
55 constexpr int32_t INVAID_VALUE = -1;
56 constexpr uint32_t MAX_WINDOW_NUMS = 15;
57 constexpr int32_t MOUSE_ICON_SIZE = 64;
58 constexpr int32_t DEFAULT_SAMPLING_PERIOD { 8 }; // 8ms
59 #ifdef OHOS_BUILD_ENABLE_ANCO
60 constexpr uint32_t SHELL_FLAGS_VALUE = 2;
61 #endif // OHOS_BUILD_ENABLE_ANCO
62
63 constexpr double POINTER_ITEM_PRESSURE = 5.0;
64 } // namespace
65
66 class InputManagerTest : public testing::Test {
67 public:
68 void SetUp();
69 void TearDown();
70 static void SetUpTestCase();
71 std::string GetEventDump();
72 std::unique_ptr<OHOS::Media::PixelMap> SetMouseIconTest(const std::string iconPath);
73
74 protected:
75 void InjectAltTabs(size_t nTriggers);
76 void InjectAltL(size_t nTriggers);
77
78 private:
79 int32_t keyboardRepeatRate_ { 50 };
80 int32_t keyboardRepeatDelay_ { 500 };
81 };
82
83 class MMIWindowChecker : public MMI::IWindowChecker {
84 public:
85 int32_t CheckWindowId(int32_t windowId) const override;
86 };
87
88 class IEventObserver : public MMI::MMIEventObserver {
89 public:
90 void SyncBundleName(int32_t pid, int32_t uid, std::string bundleName, int32_t syncStatus) override;
91 };
92
SyncBundleName(int32_t pid,int32_t uid,std::string bundleName,int32_t syncStatus)93 void IEventObserver::SyncBundleName(int32_t pid, int32_t uid, std::string bundleName, int32_t syncStatus)
94 {
95 int32_t getPid = pid;
96 int32_t getUid = uid;
97 std::string getName = bundleName;
98 int32_t getStatus = syncStatus;
99 MMI_HILOGD("SyncBundleName info is :%{public}d, %{public}d, %{public}s, %{public}d",
100 getPid, getUid, getName.c_str(), getStatus);
101 }
102
CheckWindowId(int32_t windowId) const103 int32_t MMIWindowChecker::CheckWindowId(int32_t windowId) const
104 {
105 return getpid();
106 }
107
SetUpTestCase()108 void InputManagerTest::SetUpTestCase()
109 {
110 ASSERT_TRUE(TestUtil->Init());
111 }
112
SetUp()113 void InputManagerTest::SetUp()
114 {
115 TestUtil->SetRecvFlag(RECV_FLAG::RECV_FOCUS);
116 }
117
TearDown()118 void InputManagerTest::TearDown()
119 {
120 TestUtil->AddEventDump("");
121 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
122 InputManager::GetInstance()->SetKeyboardRepeatDelay(keyboardRepeatDelay_);
123 InputManager::GetInstance()->SetKeyboardRepeatRate(keyboardRepeatRate_);
124 }
125
GetEventDump()126 std::string InputManagerTest::GetEventDump()
127 {
128 return TestUtil->GetEventDump();
129 }
130
SetMouseIconTest(const std::string iconPath)131 std::unique_ptr<OHOS::Media::PixelMap> InputManagerTest::SetMouseIconTest(const std::string iconPath)
132 {
133 CALL_DEBUG_ENTER;
134 OHOS::Media::SourceOptions opts;
135 opts.formatHint = "image/svg+xml";
136 uint32_t ret = 0;
137 auto imageSource = OHOS::Media::ImageSource::CreateImageSource(iconPath, opts, ret);
138 CHKPP(imageSource);
139 std::set<std::string> formats;
140 ret = imageSource->GetSupportedFormats(formats);
141 MMI_HILOGD("Get supported format ret:%{public}u", ret);
142
143 OHOS::Media::DecodeOptions decodeOpts;
144 decodeOpts.desiredSize = {.width = MOUSE_ICON_SIZE, .height = MOUSE_ICON_SIZE};
145
146 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, ret);
147 CHKPL(pixelMap);
148 return pixelMap;
149 }
150
151 /**
152 * @tc.name: InputManagerTest_SetTouchpadThreeFingersTapSwitch_001
153 * @tc.desc: Test the funcation SetTouchpadThreeFingersTapSwitch
154 * @tc.type: FUNC
155 * @tc.require:
156 */
157 HWTEST_F(InputManagerTest, InputManagerTest_SetTouchpadThreeFingersTapSwitch_001, TestSize.Level1)
158 {
159 CALL_TEST_DEBUG;
160 bool switchFlag = true;
161 int32_t ret = InputManager::GetInstance()->SetTouchpadThreeFingersTapSwitch(switchFlag);
162 EXPECT_EQ(ret, RET_OK);
163 }
164
165 /**
166 * @tc.name: InputManagerTest_GetTouchpadThreeFingersTapSwitch_001
167 * @tc.desc: Test the funcation GetTouchpadThreeFingersTapSwitch
168 * @tc.type: FUNC
169 * @tc.require:
170 */
171 HWTEST_F(InputManagerTest, InputManagerTest_GetTouchpadThreeFingersTapSwitch_001, TestSize.Level1)
172 {
173 CALL_TEST_DEBUG;
174 bool switchFlag = true;
175 int32_t ret = InputManager::GetInstance()->GetTouchpadThreeFingersTapSwitch(switchFlag);
176 EXPECT_EQ(ret, RET_OK);
177 }
178
179 /**
180 * @tc.name: InputManagerTest_SetKeyDownDuration_01
181 * @tc.desc: Test SetKeyDownDuration
182 * @tc.type: FUNC
183 * @tc.require:
184 */
185 HWTEST_F(InputManagerTest, InputManagerTest_SetKeyDownDuration_01, TestSize.Level1)
186 {
187 CALL_TEST_DEBUG;
188 std::string businessId = "";
189 int32_t delay = 4500;
190 int32_t ret = InputManager::GetInstance()->SetKeyDownDuration(businessId, delay);
191 EXPECT_EQ(ret, RET_ERR);
192 }
193
194 /**
195 * @tc.name: InputManagerTest_SetKeyDownDuration_02
196 * @tc.desc: Test SetKeyDownDuration
197 * @tc.type: FUNC
198 * @tc.require:
199 */
200 HWTEST_F(InputManagerTest, InputManagerTest_SetKeyDownDuration_02, TestSize.Level1)
201 {
202 CALL_TEST_DEBUG;
203 std::string businessId = "";
204 int32_t delay = 0;
205 int32_t ret = InputManager::GetInstance()->SetKeyDownDuration(businessId, delay);
206 EXPECT_EQ(ret, PARAMETER_ERROR);
207 }
208
209 /**
210 * @tc.name: InputManagerTest_SetMouseIcon_01
211 * @tc.desc: Test SetMouseIcon
212 * @tc.type: FUNC
213 * @tc.require:
214 */
215 HWTEST_F(InputManagerTest, InputManagerTest_SetMouseIcon_01, TestSize.Level1)
216 {
217 CALL_TEST_DEBUG;
218 int32_t windowId = 2;
219 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/North_South.svg";
220 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerTest::SetMouseIconTest(iconPath);
221 ASSERT_NE(pixelMap, nullptr);
222
223 int32_t ret = InputManager::GetInstance()->SetMouseIcon(windowId, (void *)pixelMap.get());
224 EXPECT_EQ(ret, RET_ERR);
225 pixelMap = nullptr;
226 }
227
228 /**
229 * @tc.name: InputManagerTest_EnableHardwareCursorStats_01
230 * @tc.desc: Test EnableHardwareCursorStats
231 * @tc.type: FUNC
232 * @tc.require:
233 */
234 HWTEST_F(InputManagerTest, InputManagerTest_EnableHardwareCursorStats_01, TestSize.Level1)
235 {
236 CALL_TEST_DEBUG;
237 bool enable = true;
238 int32_t ret = InputManager::GetInstance()->EnableHardwareCursorStats(enable);
239 EXPECT_EQ(ret, RET_OK);
240 }
241
242 /**
243 * @tc.name: InputManagerTest_EnableHardwareCursorStats_02
244 * @tc.desc: Test EnableHardwareCursorStats
245 * @tc.type: FUNC
246 * @tc.require:
247 */
248 HWTEST_F(InputManagerTest, InputManagerTest_EnableHardwareCursorStats_02, TestSize.Level1)
249 {
250 CALL_TEST_DEBUG;
251 bool enable = false;
252 int32_t ret = InputManager::GetInstance()->EnableHardwareCursorStats(enable);
253 EXPECT_EQ(ret, RET_OK);
254 }
255
256 /**
257 * @tc.name: InputManagerTest_SetMouseHotSpot_01
258 * @tc.desc: Test SetMouseHotSpot
259 * @tc.type: FUNC
260 * @tc.require:
261 */
262 HWTEST_F(InputManagerTest, InputManagerTest_SetMouseHotSpot_01, TestSize.Level1)
263 {
264 CALL_TEST_DEBUG;
265 int32_t windowId = 8;
266 int32_t hotSpotX = 3;
267 int32_t hotSpotY = 5;
268
269 int32_t winPid = InputManager::GetInstance()->GetWindowPid(windowId);
270 EXPECT_TRUE(winPid != -2);
271 int32_t ret = InputManager::GetInstance()->SetMouseHotSpot(windowId, hotSpotX, hotSpotY);
272 EXPECT_EQ(ret, RET_ERR);
273 }
274
275 /**
276 * @tc.name: InputManagerTest_GetWinSyncBatchSize
277 * @tc.desc: Test GetWinSyncBatchSize
278 * @tc.type: FUNC
279 * @tc.require:
280 */
281 HWTEST_F(InputManagerTest, InputManagerTest_GetWinSyncBatchSize, TestSize.Level1)
282 {
283 int32_t maxAreasCount = 1;
284 int32_t displayCount = 2;
285 int32_t ret = InputManager::GetInstance()->GetWinSyncBatchSize(maxAreasCount, displayCount);
286 EXPECT_NE(ret, 0);
287 }
288
289 /**
290 * @tc.name: InputManager_NotResponse_001
291 * @tc.desc: detection of not response
292 * @tc.type: FUNC
293 * @tc.require:AR000GJG6G
294 */
295 HWTEST_F(InputManagerTest, InputManager_NotResponse_001, TestSize.Level1)
296 {
297 CALL_TEST_DEBUG;
298 auto pointerEvent = PointerEvent::Create();
299 ASSERT_NE(pointerEvent, nullptr);
300
301 PointerEvent::PointerItem item;
302 item.SetPressure(POINTER_ITEM_PRESSURE);
303 item.SetPointerId(0);
304 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_TWO);
305 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_ONE);
306 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
307 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
308 pointerEvent->SetPointerId(0);
309 pointerEvent->AddPointerItem(item);
310 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
311 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
312 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
313 }
314
315 /**
316 * @tc.name: InputManager_NotResponse_002
317 * @tc.desc: detection of not response
318 * @tc.type: FUNC
319 * @tc.require:SR000GGN6G
320 */
321 HWTEST_F(InputManagerTest, InputManager_NotResponse_002, TestSize.Level1)
322 {
323 CALL_TEST_DEBUG;
324 auto pointerEvent = PointerEvent::Create();
325 ASSERT_NE(pointerEvent, nullptr);
326
327 PointerEvent::PointerItem item;
328 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_TWO);
329 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_ONE);
330 item.SetPressure(POINTER_ITEM_PRESSURE);
331 item.SetPointerId(0);
332 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
333 pointerEvent->SetPointerId(0);
334 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
335 pointerEvent->AddPointerItem(item);
336 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
337 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
338 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
339 }
340
341 /**
342 * @tc.name: InputManagerTest_SubscribeKeyEvent_001
343 * @tc.desc: Verify invalid parameter.
344 * @tc.type: FUNC
345 * @tc.require:SR000GGQL4 AR000GJNGN
346 * @tc.author: yangguang
347 */
348 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_001, TestSize.Level1)
349 {
350 CALL_TEST_DEBUG;
351 std::set<int32_t> preKeys;
352 std::shared_ptr<KeyOption> keyOption =
353 InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_VOLUME_MUTE, true, 0);
354 int32_t response = INVAID_VALUE;
355 response = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, nullptr);
356 EXPECT_TRUE(response < 0);
357 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
358 InputManager::GetInstance()->UnsubscribeKeyEvent(response);
359 }
360
361 /**
362 * @tc.name: InputManagerTest_SubscribeKeyEvent_02
363 * @tc.desc: Verify subscribe power key event.
364 * @tc.type: FUNC
365 * @tc.require:SR000GGQL4 AR000GJNGN
366 * @tc.author: zhaoxueyuan
367 */
368 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_02, TestSize.Level1)
369 {
370 CALL_TEST_DEBUG;
371 ASSERT_TRUE(MMIEventHdl.InitClient());
372 // 电源键长按按下订阅
373 std::set<int32_t> preKeys;
374 std::shared_ptr<KeyOption> keyOption =
375 InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_POWER, true, FINAL_KEY_DOWN_DURATION_TWO);
376 int32_t subscribeId1 = INVAID_VALUE;
__anonce2bd3130202(std::shared_ptr<KeyEvent> keyEvent) 377 subscribeId1 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
378 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
379 MMI_HILOGD("Subscribe key event KEYCODE_POWER down trigger callback");
380 });
381 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
382 EXPECT_FALSE(subscribeId1 >= 0);
383 #else
384 EXPECT_TRUE(subscribeId1 < 0);
385 #endif // OHOS_BUILD_ENABLE_KEYBOARD
386
387 // 电源键抬起订阅
388 std::shared_ptr<KeyOption> keyOption2 = InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_POWER, false, 0);
389 int32_t subscribeId2 = INVAID_VALUE;
__anonce2bd3130302(std::shared_ptr<KeyEvent> keyEvent) 390 subscribeId2 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption2, [](std::shared_ptr<KeyEvent> keyEvent) {
391 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
392 MMI_HILOGD("Subscribe key event KEYCODE_POWER up trigger callback");
393 });
394 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
395 EXPECT_TRUE(subscribeId2 >= 0);
396 #else
397 EXPECT_TRUE(subscribeId2 < 0);
398 #endif // OHOS_BUILD_ENABLE_KEYBOARD
399
400 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
401 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId1);
402 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId2);
403 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
404 }
405
406 /**
407 * @tc.name: InputManagerTest_SubscribeKeyEvent_03
408 * @tc.desc: Verify subscribe volume up key event.
409 * @tc.type: FUNC
410 * @tc.require:
411 */
412 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_03, TestSize.Level1)
413 {
414 CALL_TEST_DEBUG;
415 ASSERT_TRUE(MMIEventHdl.InitClient());
416 std::set<int32_t> preKeys;
417 std::shared_ptr<KeyOption> keyOption1 =
418 InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_VOLUME_UP, true, FINAL_KEY_DOWN_DURATION_ONE);
419 int32_t subscribeId1 = INVAID_VALUE;
__anonce2bd3130402(std::shared_ptr<KeyEvent> keyEvent) 420 subscribeId1 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption1, [](std::shared_ptr<KeyEvent> keyEvent) {
421 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
422 MMI_HILOGD("Subscribe key event KEYCODE_VOLUME_UP down trigger callback");
423 });
424 std::shared_ptr<KeyOption> keyOption2 =
425 InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_VOLUME_UP, false, 0);
426 int32_t subscribeId2 = INVAID_VALUE;
__anonce2bd3130502(std::shared_ptr<KeyEvent> keyEvent) 427 subscribeId2 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption2, [](std::shared_ptr<KeyEvent> keyEvent) {
428 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
429 MMI_HILOGD("Subscribe key event KEYCODE_VOLUME_UP up trigger callback");
430 });
431 std::shared_ptr<KeyOption> keyOption3 = InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_VOLUME_UP, true, 0);
432 int32_t subscribeId3 = INVAID_VALUE;
__anonce2bd3130602(std::shared_ptr<KeyEvent> keyEvent) 433 subscribeId3 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption3, [](std::shared_ptr<KeyEvent> keyEvent) {
434 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
435 MMI_HILOGD("Subscribe key event KEYCODE_VOLUME_UP down trigger callback");
436 });
437 std::shared_ptr<KeyOption> keyOption4 =
438 InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_VOLUME_UP, false, 0);
439 int32_t subscribeId4 = INVAID_VALUE;
__anonce2bd3130702(std::shared_ptr<KeyEvent> keyEvent) 440 subscribeId4 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption4, [](std::shared_ptr<KeyEvent> keyEvent) {
441 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
442 MMI_HILOGD("Subscribe key event KEYCODE_VOLUME_UP up trigger callback");
443 });
444
445 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
446 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId1);
447 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId2);
448 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId3);
449 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId4);
450 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
451 }
452
453 /**
454 * @tc.name: InputManagerTest_SubscribeKeyEvent_04
455 * @tc.desc: Verify subscribe key event.
456 * @tc.type: FUNC
457 * @tc.require:
458 * @tc.author:
459 */
460 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_04, TestSize.Level1)
461 {
462 CALL_TEST_DEBUG;
463 std::set<int32_t> preKeys;
464 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
465 keyOption->SetPreKeys(preKeys);
466 keyOption->SetFinalKey(KeyEvent::KEYCODE_VOLUME_DOWN);
467 keyOption->SetFinalKeyDown(true);
468 keyOption->SetFinalKeyDownDuration(INVAID_VALUE);
469 int32_t subscribeId = INVAID_VALUE;
__anonce2bd3130802(std::shared_ptr<KeyEvent> keyEvent) 470 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
471 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
472 MMI_HILOGD("Subscribe key event KEYCODE_POWER down trigger callback");
473 });
474 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
475 EXPECT_TRUE(subscribeId >= 0);
476 #else
477 EXPECT_TRUE(subscribeId < 0);
478 #endif // OHOS_BUILD_ENABLE_KEYBOARD
479 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
480 ASSERT_TRUE(injectDownEvent != nullptr);
481 int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
482 KeyEvent::KeyItem kitDown;
483 kitDown.SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
484 kitDown.SetPressed(true);
485 kitDown.SetDownTime(downTime);
486 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
487 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
488 injectDownEvent->AddPressedKeyItems(kitDown);
489 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
490 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN);
491 }
492
493 /**
494 * @tc.name: InputManagerTest_SubscribeKeyEvent_08
495 * @tc.desc: Verify subscribe key event.
496 * @tc.type: FUNC
497 * @tc.require:
498 * @tc.author:
499 */
500 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_08, TestSize.Level1)
501 {
502 CALL_TEST_DEBUG;
503 std::set<int32_t> preKeys;
504 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
505 keyOption->SetPreKeys(preKeys);
506 keyOption->SetFinalKey(KeyEvent::KEYCODE_DAGGER_CLICK);
507 keyOption->SetFinalKeyDown(true);
508 keyOption->SetFinalKeyDownDuration(0);
509 int32_t subscribeId = INVAID_VALUE;
__anonce2bd3130902(std::shared_ptr<KeyEvent> keyEvent) 510 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
511 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
512 MMI_HILOGD("Subscribe key event KEYCODE_DAGGER_CLICK down trigger callback");
513 });
514 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
515 EXPECT_TRUE(subscribeId >= 0);
516 #else
517 EXPECT_TRUE(subscribeId < 0);
518 #endif // OHOS_BUILD_ENABLE_KEYBOARD
519 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
520 ASSERT_TRUE(injectDownEvent != nullptr);
521 int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
522 KeyEvent::KeyItem kitDown;
523 kitDown.SetKeyCode(KeyEvent::KEYCODE_DAGGER_CLICK);
524 kitDown.SetPressed(true);
525 kitDown.SetDownTime(downTime);
526 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_DAGGER_CLICK);
527 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
528 injectDownEvent->AddPressedKeyItems(kitDown);
529 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
530 }
531
532 /**
533 * @tc.name: InputManagerTest_SubscribeKeyEvent_06
534 * @tc.desc: Verify subscribe key event.
535 * @tc.type: FUNC
536 * @tc.require:
537 * @tc.author:
538 */
539 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_06, TestSize.Level1)
540 {
541 CALL_TEST_DEBUG;
542 std::set<int32_t> preKeys;
543 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
544 keyOption->SetPreKeys(preKeys);
545 keyOption->SetFinalKey(KeyEvent::KEYCODE_DAGGER_DOUBLE_CLICK);
546 keyOption->SetFinalKeyDown(true);
547 keyOption->SetFinalKeyDownDuration(0);
548 int32_t subscribeId = INVAID_VALUE;
__anonce2bd3130a02(std::shared_ptr<KeyEvent> keyEvent) 549 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
550 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
551 MMI_HILOGD("Subscribe key event KEYCODE_DAGGER_DOUBLE_CLICK down trigger callback");
552 });
553 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
554 EXPECT_TRUE(subscribeId >= 0);
555 #else
556 EXPECT_TRUE(subscribeId < 0);
557 #endif // OHOS_BUILD_ENABLE_KEYBOARD
558 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
559 ASSERT_TRUE(injectDownEvent != nullptr);
560 int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
561 KeyEvent::KeyItem kitDown;
562 kitDown.SetKeyCode(KeyEvent::KEYCODE_DAGGER_DOUBLE_CLICK);
563 kitDown.SetPressed(true);
564 kitDown.SetDownTime(downTime);
565 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_DAGGER_DOUBLE_CLICK);
566 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
567 injectDownEvent->AddPressedKeyItems(kitDown);
568 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
569 }
570
571 /**
572 * @tc.name: InputManagerTest_SubscribeKeyEvent_07
573 * @tc.desc: Verify subscribe key event.
574 * @tc.type: FUNC
575 * @tc.require:
576 * @tc.author:
577 */
578 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_07, TestSize.Level1)
579 {
580 CALL_TEST_DEBUG;
581 std::set<int32_t> preKeys;
582 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
583 keyOption->SetPreKeys(preKeys);
584 keyOption->SetFinalKey(KeyEvent::KEYCODE_DAGGER_LONG_PRESS);
585 keyOption->SetFinalKeyDown(true);
586 keyOption->SetFinalKeyDownDuration(0);
587 int32_t subscribeId = INVAID_VALUE;
__anonce2bd3130b02(std::shared_ptr<KeyEvent> keyEvent) 588 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
589 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
590 MMI_HILOGD("Subscribe key event KEYCODE_DAGGER_LONG_PRESS down trigger callback");
591 });
592 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
593 EXPECT_TRUE(subscribeId >= 0);
594 #else
595 EXPECT_TRUE(subscribeId < 0);
596 #endif // OHOS_BUILD_ENABLE_KEYBOARD
597 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
598 ASSERT_TRUE(injectDownEvent != nullptr);
599 int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
600 KeyEvent::KeyItem kitDown;
601 kitDown.SetKeyCode(KeyEvent::KEYCODE_DAGGER_LONG_PRESS);
602 kitDown.SetPressed(true);
603 kitDown.SetDownTime(downTime);
604 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_DAGGER_LONG_PRESS);
605 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
606 injectDownEvent->AddPressedKeyItems(kitDown);
607 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
608 }
609
InjectAltTabs(size_t nTriggers)610 void InputManagerTest::InjectAltTabs(size_t nTriggers)
611 {
612 auto keyEvent = KeyEvent::Create();
613 ASSERT_NE(keyEvent, nullptr);
614 keyEvent->SetKeyCode(KeyEvent::KEYCODE_TAB);
615
616 KeyEvent::KeyItem keyItem {};
617 keyItem.SetKeyCode(KeyEvent::KEYCODE_ALT_LEFT);
618 keyItem.SetPressed(true);
619 keyItem.SetDownTime(GetSysClockTime() - MS2US(DEFAULT_SAMPLING_PERIOD));
620 keyEvent->AddKeyItem(keyItem);
621 keyItem.SetKeyCode(KeyEvent::KEYCODE_TAB);
622
623 while (nTriggers-- > 0) {
624 auto now = GetSysClockTime();
625 keyItem.SetPressed(true);
626 keyItem.SetDownTime(now);
627 keyEvent->AddKeyItem(keyItem);
628 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
629 keyEvent->SetActionTime(now);
630 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
631 std::this_thread::sleep_for(std::chrono::milliseconds(DEFAULT_SAMPLING_PERIOD));
632
633 keyItem.SetPressed(false);
634 keyEvent->RemoveReleasedKeyItems(keyItem);
635
636 now = GetSysClockTime();
637 keyEvent->AddKeyItem(keyItem);
638 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
639 keyEvent->SetActionTime(now);
640 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
641 keyEvent->RemoveReleasedKeyItems(keyItem);
642 std::this_thread::sleep_for(std::chrono::milliseconds(DEFAULT_SAMPLING_PERIOD));
643 }
644 }
645
646 /**
647 * @tc.name: InputManagerTest_SubscribeKeyEvent_05
648 * @tc.desc: Verify subscription and unsubscription of ALT+TAB.
649 * @tc.type: FUNC
650 * @tc.require:
651 * @tc.author:
652 */
653 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_05, TestSize.Level1)
654 {
655 CALL_TEST_DEBUG;
656 size_t nCalls { 0 };
657 std::set<int32_t> preKeys { KeyEvent::KEYCODE_ALT_LEFT };
658 std::shared_ptr<KeyOption> keyOption = InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_TAB, true, 0);
659 auto subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption,
__anonce2bd3130c02(std::shared_ptr<KeyEvent> keyEvent) 660 [&nCalls](std::shared_ptr<KeyEvent> keyEvent) {
661 if ((keyEvent->GetKeyCode() == KeyEvent::KEYCODE_TAB) &&
662 (keyEvent->GetKeyAction() == KeyEvent::KEY_ACTION_DOWN)) {
663 auto pressedKeys = keyEvent->GetPressedKeys();
664 if (std::any_of(pressedKeys.cbegin(), pressedKeys.cend(),
665 [](const auto keyCode) {
666 return (keyCode == KeyEvent::KEYCODE_ALT_LEFT);
667 })) {
668 ++nCalls;
669 }
670 }
671 });
672 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
673 ASSERT_TRUE(subscribeId >= 0);
674 size_t nTriggers { 0 };
675 InjectAltTabs(nTriggers);
676 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId);
677 EXPECT_EQ(nTriggers, nCalls);
678 InjectAltTabs(nTriggers);
679 EXPECT_EQ(nTriggers, nCalls);
680 #else
681 EXPECT_TRUE(subscribeId < 0);
682 #endif // OHOS_BUILD_ENABLE_KEYBOARD
683 }
684
685 /**
686 * @tc.name: InputManagerTest_SubscribeKeyEvent_09
687 * @tc.desc: Verify subscribe key event.
688 * @tc.type: FUNC
689 * @tc.require:
690 * @tc.author:
691 */
692 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_09, TestSize.Level1)
693 {
694 CALL_TEST_DEBUG;
695 std::set<int32_t> preKeys;
696 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
697 keyOption->SetPreKeys(preKeys);
698 keyOption->SetFinalKey(KeyEvent::KEYCODE_KEY_PEN_AIR_MOUSE);
699 keyOption->SetFinalKeyDown(true);
700 keyOption->SetFinalKeyDownDuration(0);
701 int32_t subscribeId = INVAID_VALUE;
__anonce2bd3130e02(std::shared_ptr<KeyEvent> keyEvent) 702 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
703 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
704 MMI_HILOGD("[YKP] Subscribe key event KEYCODE_KEY_PEN_AIR_MOUSE down trigger callback");
705 });
706 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
707 EXPECT_TRUE(subscribeId >= 0);
708 #else
709 EXPECT_TRUE(subscribeId < 0);
710 #endif // OHOS_BUILD_ENABLE_KEYBOARD
711 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
712 ASSERT_TRUE(injectDownEvent != nullptr);
713 int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
714 KeyEvent::KeyItem kitDown;
715 kitDown.SetKeyCode(KeyEvent::KEYCODE_KEY_PEN_AIR_MOUSE);
716 kitDown.SetPressed(true);
717 kitDown.SetDownTime(downTime);
718 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_KEY_PEN_AIR_MOUSE);
719 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
720 injectDownEvent->AddPressedKeyItems(kitDown);
721 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
722 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN);
723
724 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
725 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId);
726 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
727 }
728
729 /**
730 * @tc.name: InputManagerTest_SubscribeKeyEvent_10
731 * @tc.desc: Verify subscribe key event.
732 * @tc.type: FUNC
733 * @tc.require:
734 * @tc.author:
735 */
736 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_10, TestSize.Level1)
737 {
738 CALL_TEST_DEBUG;
739 std::set<int32_t> preKeys;
740 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
741 keyOption->SetPreKeys(preKeys);
742 keyOption->SetFinalKey(KeyEvent::KEYCODE_KEY_PEN_LIGHT_PINCH);
743 keyOption->SetFinalKeyDown(true);
744 keyOption->SetFinalKeyDownDuration(0);
745 int32_t subscribeId = INVAID_VALUE;
__anonce2bd3130f02(std::shared_ptr<KeyEvent> keyEvent) 746 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
747 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
748 MMI_HILOGD("[YKP] Subscribe key event KEYCODE_KEY_PEN_LIGHT_PINCH down trigger callback");
749 });
750 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
751 EXPECT_TRUE(subscribeId >= 0);
752 #else
753 EXPECT_TRUE(subscribeId < 0);
754 #endif // OHOS_BUILD_ENABLE_KEYBOARD
755 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
756 ASSERT_TRUE(injectDownEvent != nullptr);
757 int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
758 KeyEvent::KeyItem kitDown;
759 kitDown.SetKeyCode(KeyEvent::KEYCODE_KEY_PEN_LIGHT_PINCH);
760 kitDown.SetPressed(true);
761 kitDown.SetDownTime(downTime);
762 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_KEY_PEN_LIGHT_PINCH);
763 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
764 injectDownEvent->AddPressedKeyItems(kitDown);
765 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
766 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN);
767
768 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
769 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId);
770 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
771 }
772
773 /**
774 * @tc.name: InputManagerTest_SubscribeKeyEvent_13
775 * @tc.desc: Verify subscribe key event.
776 * @tc.type: FUNC
777 * @tc.require:
778 * @tc.author:
779 */
780 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_13, TestSize.Level1)
781 {
782 CALL_TEST_DEBUG;
783 std::set<int32_t> preKeys;
784 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
785 keyOption->SetPreKeys(preKeys);
786 keyOption->SetFinalKey(KeyEvent::KEYCODE_KEY_PEN_AI);
787 keyOption->SetFinalKeyDown(true);
788 keyOption->SetFinalKeyDownDuration(0);
789 int32_t subscribeId = INVAID_VALUE;
__anonce2bd3131002(std::shared_ptr<KeyEvent> keyEvent) 790 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
791 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
792 MMI_HILOGD("[YKP] Subscribe key event KEYCODE_KEY_PEN_AI down trigger callback");
793 });
794 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
795 EXPECT_TRUE(subscribeId >= 0);
796 #else
797 EXPECT_TRUE(subscribeId < 0);
798 #endif // OHOS_BUILD_ENABLE_KEYBOARD
799 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
800 ASSERT_TRUE(injectDownEvent != nullptr);
801 int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
802 KeyEvent::KeyItem kitDown;
803 kitDown.SetKeyCode(KeyEvent::KEYCODE_KEY_PEN_AI);
804 kitDown.SetPressed(true);
805 kitDown.SetDownTime(downTime);
806 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_KEY_PEN_AI);
807 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
808 injectDownEvent->AddPressedKeyItems(kitDown);
809 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
810 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN);
811
812 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
813 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId);
814 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
815 }
816
817 /**
818 * @tc.name: InputManagerTest_SubscribeKeyEvent_11
819 * @tc.desc: Verify subscribe key event.
820 * @tc.type: FUNC
821 * @tc.require:
822 * @tc.author:
823 */
824 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_11, TestSize.Level1)
825 {
826 CALL_TEST_DEBUG;
827 std::set<int32_t> preKeys;
828 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
829 keyOption->SetPreKeys(preKeys);
830 keyOption->SetFinalKey(KeyEvent::KEYCODE_KEY_PEN_END_CLICK);
831 keyOption->SetFinalKeyDown(true);
832 keyOption->SetFinalKeyDownDuration(0);
833 int32_t subscribeId = INVAID_VALUE;
__anonce2bd3131102(std::shared_ptr<KeyEvent> keyEvent) 834 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
835 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
836 MMI_HILOGD("Subscribe key event KEYCODE_KEY_PEN_END_CLICK down trigger callback");
837 });
838 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
839 EXPECT_TRUE(subscribeId >= 0);
840 #else
841 EXPECT_TRUE(subscribeId < 0);
842 #endif // OHOS_BUILD_ENABLE_KEYBOARD
843 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
844 ASSERT_TRUE(injectDownEvent != nullptr);
845 int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
846 KeyEvent::KeyItem kitDown;
847 kitDown.SetKeyCode(KeyEvent::KEYCODE_KEY_PEN_END_CLICK);
848 kitDown.SetPressed(true);
849 kitDown.SetDownTime(downTime);
850 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_KEY_PEN_END_CLICK);
851 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
852 injectDownEvent->AddPressedKeyItems(kitDown);
853 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
854 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN);
855
856 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
857 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId);
858 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
859 }
860
861 /**
862 * @tc.name: InputManagerTest_SubscribeKeyEvent_12
863 * @tc.desc: Verify subscribe key event.
864 * @tc.type: FUNC
865 * @tc.require:
866 * @tc.author:
867 */
868 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_12, TestSize.Level1)
869 {
870 CALL_TEST_DEBUG;
871 std::set<int32_t> preKeys;
872 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
873 keyOption->SetPreKeys(preKeys);
874 keyOption->SetFinalKey(KeyEvent::KEYCODE_KEY_PEN_END_DOUBLE_CLICK);
875 keyOption->SetFinalKeyDown(true);
876 keyOption->SetFinalKeyDownDuration(0);
877 int32_t subscribeId = INVAID_VALUE;
__anonce2bd3131202(std::shared_ptr<KeyEvent> keyEvent) 878 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
879 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
880 MMI_HILOGD("[YKP] Subscribe key event KEYCODE_KEY_PEN_END_DOUBLE_CLICK down trigger callback");
881 });
882 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
883 EXPECT_TRUE(subscribeId >= 0);
884 #else
885 EXPECT_TRUE(subscribeId < 0);
886 #endif // OHOS_BUILD_ENABLE_KEYBOARD
887 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
888 ASSERT_TRUE(injectDownEvent != nullptr);
889 int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
890 KeyEvent::KeyItem kitDown;
891 kitDown.SetKeyCode(KeyEvent::KEYCODE_KEY_PEN_END_DOUBLE_CLICK);
892 kitDown.SetPressed(true);
893 kitDown.SetDownTime(downTime);
894 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_KEY_PEN_END_DOUBLE_CLICK);
895 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
896 injectDownEvent->AddPressedKeyItems(kitDown);
897 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
898 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN);
899
900 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
901 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId);
902 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
903 }
904
905 /**
906 * @tc.name: InputManagerTest_SubscribeKeyEvent_14
907 * @tc.desc: Verify subscribe key event.
908 * @tc.type: FUNC
909 * @tc.require:
910 * @tc.author:
911 */
912 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_14, TestSize.Level1)
913 {
914 CALL_TEST_DEBUG;
915 int32_t tvPower = 4000;
916 std::set<int32_t> preKeys;
917 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
918 keyOption->SetPreKeys(preKeys);
919 keyOption->SetFinalKey(tvPower);
920 keyOption->SetFinalKeyDown(true);
921 keyOption->SetFinalKeyDownDuration(0);
922 int32_t subscribeId = INVAID_VALUE;
__anonce2bd3131302(std::shared_ptr<KeyEvent> keyEvent) 923 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
924 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
925 MMI_HILOGD("Subscribe key event %{public}d down trigger callback", keyEvent->GetKeyCode());
926 });
927 EXPECT_TRUE(subscribeId >= 0);
928 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
929 ASSERT_TRUE(injectDownEvent != nullptr);
930 int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
931 KeyEvent::KeyItem kitDown;
932 kitDown.SetKeyCode(tvPower);
933 kitDown.SetPressed(true);
934 kitDown.SetDownTime(downTime);
935 injectDownEvent->SetKeyCode(tvPower);
936 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
937 injectDownEvent->AddPressedKeyItems(kitDown);
938 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
939 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN);
940 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
941 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId);
942 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
943 }
944
945 /**
946 * @tc.name: InputManagerTest_SubscribeKeyEvent_15
947 * @tc.desc: Verify subscribe key event.
948 * @tc.type: FUNC
949 * @tc.require:
950 * @tc.author:
951 */
952 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_15, TestSize.Level1)
953 {
954 CALL_TEST_DEBUG;
955 int32_t tvPower = 4000;
956 std::set<int32_t> preKeys;
957 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
958 keyOption->SetPreKeys(preKeys);
959 keyOption->SetFinalKey(tvPower);
960 keyOption->SetFinalKeyDown(true);
961 keyOption->SetFinalKeyDownDuration(0);
962 int32_t subscribeId = INVAID_VALUE;
__anonce2bd3131402(std::shared_ptr<KeyEvent> keyEvent) 963 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
964 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
965 MMI_HILOGD("Subscribe key event %{public}d down trigger callback", keyEvent->GetKeyCode());
966 });
967 EXPECT_TRUE(subscribeId >= 0);
968 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId);
969 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
970 }
971
972 /**
973 * @tc.name: TestGetKeystrokeAbility_001
974 * @tc.desc: Verify SupportKeys
975 * @tc.type: FUNC
976 * @tc.require:
977 */
978 HWTEST_F(InputManagerTest, TestGetKeystrokeAbility_001, TestSize.Level1)
979 {
980 CALL_TEST_DEBUG;
981 std::vector<int32_t> keyCodes = {
982 KeyEvent::KEYCODE_VOLUME_DOWN, KeyEvent::KEYCODE_VOLUME_MUTE, KeyEvent::KEYCODE_DEL};
983 int32_t result = InputManager::GetInstance()->SupportKeys(
__anonce2bd3131502(std::vector<bool> keystrokeAbility) 984 0, keyCodes, [](std::vector<bool> keystrokeAbility) { MMI_HILOGD("TestGetKeystrokeAbility_001 callback ok"); });
985 ASSERT_EQ(result, 0);
986 MMI_HILOGD("Stop TestGetKeystrokeAbility_001");
987 }
988
989 static int32_t g_deviceIDtest = 0;
GetKeyboardTypeCallback(int32_t keyboardType)990 static void GetKeyboardTypeCallback(int32_t keyboardType)
991 {
992 switch (keyboardType) {
993 case KEYBOARD_TYPE_NONE: {
994 MMI_HILOGD("The g_deviceIDtest:%{public}d, KeyboardType:%{public}s", g_deviceIDtest, "None");
995 break;
996 }
997 case KEYBOARD_TYPE_UNKNOWN: {
998 MMI_HILOGD("The g_deviceIDtest:%{public}d, KeyboardType:%{public}s", g_deviceIDtest, "unknown");
999 break;
1000 }
1001 case KEYBOARD_TYPE_ALPHABETICKEYBOARD: {
1002 MMI_HILOGD("The g_deviceIDtest:%{public}d, KeyboardType:%{public}s", g_deviceIDtest, "alphabetickeyboard");
1003 break;
1004 }
1005 case KEYBOARD_TYPE_DIGITALKEYBOARD: {
1006 MMI_HILOGD("The g_deviceIDtest:%{public}d, KeyboardType:%{public}s", g_deviceIDtest, "digitalkeyboard");
1007 break;
1008 }
1009 case KEYBOARD_TYPE_HANDWRITINGPEN: {
1010 MMI_HILOGD("The g_deviceIDtest:%{public}d, KeyboardType:%{public}s", g_deviceIDtest, "handwritingpen");
1011 break;
1012 }
1013 case KEYBOARD_TYPE_REMOTECONTROL: {
1014 MMI_HILOGD("The g_deviceIDtest:%{public}d, KeyboardType:%{public}s", g_deviceIDtest, "remotecontrol");
1015 break;
1016 }
1017 default: {
1018 MMI_HILOGW("Error obtaining keyboard type");
1019 break;
1020 }
1021 }
1022 }
1023
1024 /**
1025 * @tc.name: InputManagerTest_GetKeyboardType
1026 * @tc.desc: Verify Get Keyboard Type
1027 * @tc.type: FUNC
1028 * @tc.require:
1029 */
1030 HWTEST_F(InputManagerTest, InputManagerTest_GetKeyboardType, TestSize.Level1)
1031 {
1032 MMI_HILOGD("Start InputManagerTest_GetKeyboardType");
1033 for (int32_t i = 0; i < KEYBOARD_TYPE_SIZE; ++i) {
1034 g_deviceIDtest = i;
1035 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->GetKeyboardType(i, GetKeyboardTypeCallback));
1036 MMI_HILOGD("The i:%{public}d", i);
1037 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1038 }
1039 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1040 MMI_HILOGD("Stop InputManagerTest_GetKeyboardType");
1041 }
1042
1043 /**
1044 * @tc.name: InputManagerTest_SetKeyboardRepeatDelay
1045 * @tc.desc: Verify Set Keyboard Repeat Delay
1046 * @tc.type: FUNC
1047 * @tc.require:
1048 */
1049 HWTEST_F(InputManagerTest, InputManagerTest_SetKeyboardRepeatDelay, TestSize.Level1)
1050 {
1051 MMI_HILOGD("Start InputManagerTest_SetKeyboardRepeatDelay");
1052 int32_t ret = InputManager::GetInstance()->SetKeyboardRepeatDelay(KEY_REPEAT_DELAY);
1053 ASSERT_EQ(ret, RET_OK);
1054 MMI_HILOGD("Stop InputManagerTest_SetKeyboardRepeatDelay");
1055 }
1056
1057 /**
1058 * @tc.name: InputManagerTest_SetKeyboardRepeatRate
1059 * @tc.desc: Verify Set Keyboard Repeat Rate
1060 * @tc.type: FUNC
1061 * @tc.require:
1062 */
1063 HWTEST_F(InputManagerTest, InputManagerTest_SetKeyboardRepeatRate, TestSize.Level1)
1064 {
1065 MMI_HILOGD("Start InputManagerTest_SetKeyboardRepeatRate");
1066 int32_t ret = InputManager::GetInstance()->SetKeyboardRepeatRate(KEY_REPEAT_RATE);
1067 ASSERT_EQ(ret, RET_OK);
1068 MMI_HILOGD("Stop InputManagerTest_SetKeyboardRepeatRate");
1069 }
1070
1071 /**
1072 * @tc.name: InputManagerTest_GetKeyboardRepeatDelay
1073 * @tc.desc: Verify Get Keyboard Repeat Delay
1074 * @tc.type: FUNC
1075 * @tc.require:
1076 */
1077 HWTEST_F(InputManagerTest, InputManagerTest_GetKeyboardRepeatDelay, TestSize.Level1)
1078 {
1079 MMI_HILOGD("Start InputManagerTest_GetKeyboardRepeatDelay");
__anonce2bd3131602(int32_t delay) 1080 auto callback = [](int32_t delay) {
1081 ASSERT_TRUE(delay == KEY_REPEAT_DELAY);
1082 MMI_HILOGD("Get keyboard repeat delay success");
1083 };
1084 if (InputManager::GetInstance()->SetKeyboardRepeatDelay(KEY_REPEAT_DELAY) == RET_OK) {
1085 ASSERT_TRUE(InputManager::GetInstance()->GetKeyboardRepeatDelay(callback) == RET_OK);
1086 }
1087 MMI_HILOGD("Stop InputManagerTest_GetKeyboardRepeatDelay");
1088 }
1089
1090 /**
1091 * @tc.name: InputManagerTest_GetKeyboardRepeatRate
1092 * @tc.desc: Verify Get Keyboard Repeat Rate
1093 * @tc.type: FUNC
1094 * @tc.require:
1095 */
1096 HWTEST_F(InputManagerTest, InputManagerTest_GetKeyboardRepeatRate, TestSize.Level1)
1097 {
1098 MMI_HILOGD("Start InputManagerTest_GetKeyboardRepeatRate");
__anonce2bd3131702(int32_t rate) 1099 auto callback = [](int32_t rate) {
1100 ASSERT_TRUE(rate == KEY_REPEAT_RATE);
1101 MMI_HILOGD("Get keyboard repeat rate success");
1102 };
1103 if (InputManager::GetInstance()->SetKeyboardRepeatRate(KEY_REPEAT_RATE) == RET_OK) {
1104 ASSERT_TRUE(InputManager::GetInstance()->GetKeyboardRepeatRate(callback) == RET_OK);
1105 }
1106 MMI_HILOGD("Stop InputManagerTest_GetKeyboardRepeatRate");
1107 }
1108
1109 HWTEST_F(InputManagerTest, InputManagerTest_GetProcCpuUsage, TestSize.Level1)
1110 {
1111 CALL_TEST_DEBUG;
1112 SYSTEM_INFO::CpuInfo cpuInfo;
1113 const std::string process_name = "multimodalinput";
1114 auto usage = cpuInfo.GetProcCpuUsage(process_name);
1115 MMI_HILOGD("The CPU usage of the %{public}s process is %{public}.2f", process_name.c_str(), usage);
1116 ASSERT_TRUE(usage < SYSTEM_INFO::CPU_USAGE_LOAD && usage != SYSTEM_INFO::CPU_USAGE_UNKNOWN);
1117 }
1118
1119 /**
1120 * @tc.name: InputManagerTest_FunctionKeyState_001
1121 * @tc.desc: Set NumLock for the keyboard enablement state to true
1122 * @tc.type: FUNC
1123 * @tc.require: I5HMCX
1124 */
1125 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_001, TestSize.Level1)
1126 {
1127 CALL_TEST_DEBUG;
1128 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::NUM_LOCK_FUNCTION_KEY, true);
1129 bool state = false;
1130 InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::NUM_LOCK_FUNCTION_KEY, state);
1131 ASSERT_FALSE(state);
1132 }
1133
1134 /**
1135 * @tc.name: InputManagerTest_FunctionKeyState_002
1136 * @tc.desc: Set NumLock for the keyboard enablement state to false
1137 * @tc.type: FUNC
1138 * @tc.require: I5HMCX
1139 */
1140 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_002, TestSize.Level1)
1141 {
1142 CALL_TEST_DEBUG;
1143 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::NUM_LOCK_FUNCTION_KEY, false);
1144 bool state = true;
1145 InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::NUM_LOCK_FUNCTION_KEY, state);
1146 ASSERT_FALSE(state);
1147 }
1148
1149 /**
1150 * @tc.name: InputManagerTest_FunctionKeyState_003
1151 * @tc.desc: Set ScrollLock for the keyboard enablement state to true
1152 * @tc.type: FUNC
1153 * @tc.require: I5HMCX
1154 */
1155 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_003, TestSize.Level1)
1156 {
1157 CALL_TEST_DEBUG;
1158 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::SCROLL_LOCK_FUNCTION_KEY, true);
1159 bool state = false;
1160 InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::SCROLL_LOCK_FUNCTION_KEY, state);
1161 ASSERT_FALSE(state);
1162 }
1163
1164 /**
1165 * @tc.name: InputManagerTest_FunctionKeyState_004
1166 * @tc.desc: Set ScrollLock for the keyboard enablement state to false
1167 * @tc.type: FUNC
1168 * @tc.require: I5HMCX
1169 */
1170 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_004, TestSize.Level1)
1171 {
1172 CALL_TEST_DEBUG;
1173 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::SCROLL_LOCK_FUNCTION_KEY, false);
1174 bool state = true;
1175 InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::SCROLL_LOCK_FUNCTION_KEY, state);
1176 ASSERT_FALSE(state);
1177 }
1178
1179 /**
1180 * @tc.name: InputManagerTest_FunctionKeyState_005
1181 * @tc.desc: Set CapsLock for the keyboard enablement state to true
1182 * @tc.type: FUNC
1183 * @tc.require: I5HMCX
1184 */
1185 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_005, TestSize.Level1)
1186 {
1187 CALL_TEST_DEBUG;
1188 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::CAPS_LOCK_FUNCTION_KEY, true);
1189 bool state = false;
1190 InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::CAPS_LOCK_FUNCTION_KEY, state);
1191 ASSERT_FALSE(state);
1192 }
1193
1194 /**
1195 * @tc.name: InputManagerTest_FunctionKeyState_006
1196 * @tc.desc: Set CapsLock for the keyboard enablement state to false
1197 * @tc.type: FUNC
1198 * @tc.require: I5HMCX
1199 */
1200 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_006, TestSize.Level1)
1201 {
1202 CALL_TEST_DEBUG;
1203 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::CAPS_LOCK_FUNCTION_KEY, false);
1204 bool state = true;
1205 InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::CAPS_LOCK_FUNCTION_KEY, state);
1206 ASSERT_FALSE(state);
1207 }
1208
1209 /**
1210 * @tc.name: InputManagerTest_FunctionKeyState_007
1211 * @tc.desc: Set other function keys
1212 * @tc.type: FUNC
1213 * @tc.require: I5HMCX
1214 */
1215 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_007, TestSize.Level1)
1216 {
1217 CALL_TEST_DEBUG;
1218 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::UNKNOWN_FUNCTION_KEY, true);
1219 bool state = true;
1220 InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::UNKNOWN_FUNCTION_KEY, state);
1221 ASSERT_FALSE(state);
1222
1223 InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::UNKNOWN_FUNCTION_KEY, false);
1224 InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::UNKNOWN_FUNCTION_KEY, state);
1225 ASSERT_FALSE(state);
1226 }
1227
1228 /**
1229 * @tc.name: InputManagerTest_EnableCombineKey_001
1230 * @tc.desc: Enable combine key
1231 * @tc.type: FUNC
1232 * @tc.require: I5HMCX
1233 */
1234 HWTEST_F(InputManagerTest, InputManagerTest_EnableCombineKey_001, TestSize.Level1)
1235 {
1236 CALL_TEST_DEBUG;
1237 ASSERT_EQ(InputManager::GetInstance()->EnableCombineKey(false), RET_OK);
1238 }
1239
1240 /**
1241 * @tc.name: InputManagerTest_EnableCombineKey_002
1242 * @tc.desc: Enable combine key
1243 * @tc.type: FUNC
1244 * @tc.require: I5HMCX
1245 */
1246 HWTEST_F(InputManagerTest, InputManagerTest_EnableCombineKey_002, TestSize.Level1)
1247 {
1248 CALL_TEST_DEBUG;
1249 ASSERT_EQ(InputManager::GetInstance()->EnableCombineKey(true), RET_OK);
1250 }
1251
1252 /**
1253 * @tc.name: InputManagerTest_TouchScreenHotArea_001
1254 * @tc.desc: Touch event Search window by defaultHotAreas
1255 * @tc.type: FUNC
1256 * @tc.require: I5HMCB
1257 */
1258 HWTEST_F(InputManagerTest, InputManagerTest_TouchScreenHotArea_001, TestSize.Level1)
1259 {
1260 CALL_TEST_DEBUG;
1261 std::shared_ptr<PointerEvent> pointerEvent{InputManagerUtil::SetupTouchScreenEvent001()};
1262 ASSERT_TRUE(pointerEvent != nullptr);
1263 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
1264 ASSERT_EQ(pointerEvent->GetSourceType(), PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
1265 }
1266
1267 /**
1268 * @tc.name: InputManagerTest_TouchScreenHotArea_002
1269 * @tc.desc: Touch event Search window by pointerHotAreas
1270 * @tc.type: FUNC
1271 * @tc.require: I5HMCB
1272 */
1273 HWTEST_F(InputManagerTest, InputManagerTest_TouchScreenHotArea_002, TestSize.Level1)
1274 {
1275 CALL_TEST_DEBUG;
1276 std::shared_ptr<PointerEvent> pointerEvent{InputManagerUtil::SetupTouchScreenEvent002()};
1277 ASSERT_TRUE(pointerEvent != nullptr);
1278 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
1279 ASSERT_EQ(pointerEvent->GetSourceType(), PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
1280 }
1281
1282 /**
1283 * @tc.name: InputManagerTest_UpdateDisplayInfo
1284 * @tc.desc: Update window information
1285 * @tc.type: FUNC
1286 * @tc.require:
1287 */
1288 HWTEST_F(InputManagerTest, InputManagerTest_UpdateDisplayInfo, TestSize.Level1)
1289 {
1290 CALL_TEST_DEBUG;
1291 DisplayGroupInfo displayGroupInfo;
1292 displayGroupInfo.focusWindowId = 0;
1293 displayGroupInfo.width = 0;
1294 displayGroupInfo.height = 0;
1295 InputManager::GetInstance()->UpdateDisplayInfo(displayGroupInfo);
1296 ASSERT_TRUE(displayGroupInfo.displaysInfo.empty());
1297 }
1298
1299 /**
1300 * @tc.name: InputManagerTest_UpdateDisplayInfo for 1 display and 1 window
1301 * @tc.desc: Update window information
1302 * @tc.type: FUNC
1303 * @tc.require:
1304 */
1305 HWTEST_F(InputManagerTest, InputManagerTest_UpdateDisplayInfo001, TestSize.Level1)
1306 {
1307 CALL_TEST_DEBUG;
1308 DisplayGroupInfo displayGroupInfo;
1309 displayGroupInfo.focusWindowId = 1;
1310 displayGroupInfo.width = 1000;
1311 displayGroupInfo.height = 2000;
1312 DisplayInfo displayInfo;
1313 displayInfo.id = 0;
1314 displayInfo.x =1;
1315 displayInfo.y = 1;
1316 displayInfo.width = 2;
1317 displayInfo.height = 2;
1318 displayInfo.dpi = 240;
1319 displayInfo.name = "pp";
1320 displayInfo.uniq = "pp";
1321 displayInfo.direction = DIRECTION0;
1322 displayGroupInfo.displaysInfo.push_back(displayInfo);
1323 WindowInfo info;
1324 info.id = 1;
1325 info.pid = 1;
1326 info.uid = 1;
1327 info.area = {1, 1, 1, 1};
1328 info.defaultHotAreas = { info.area };
1329 info.pointerHotAreas = { info.area };
1330 info.pointerChangeAreas = {16, 5, 16, 5, 16, 5, 16, 5};
1331 info.transform = {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f};
1332 info.agentWindowId = 1;
1333 info.flags = 0;
1334 info.displayId = 0;
1335 displayGroupInfo.windowsInfo.push_back(info);
1336 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateDisplayInfo(displayGroupInfo));
1337 }
1338
1339 /**
1340 * @tc.name: InputManagerTest_UpdateDisplayInfo for 1 display and max-windows
1341 * @tc.desc: Update window information
1342 * @tc.type: FUNC
1343 * @tc.require:
1344 */
1345 HWTEST_F(InputManagerTest, InputManagerTest_UpdateDisplayInfo002, TestSize.Level1)
1346 {
1347 CALL_TEST_DEBUG;
1348 DisplayGroupInfo displayGroupInfo;
1349 displayGroupInfo.focusWindowId = 0;
1350 displayGroupInfo.width = 1000;
1351 displayGroupInfo.height = 2000;
1352 DisplayInfo displayInfo;
1353 displayInfo.id = 0;
1354 displayInfo.x =1;
1355 displayInfo.y = 1;
1356 displayInfo.width = 2;
1357 displayInfo.height = 2;
1358 displayInfo.dpi = 240;
1359 displayInfo.name = "pp";
1360 displayInfo.uniq = "pp";
1361 displayInfo.direction = DIRECTION0;
1362 displayInfo.displayMode = DisplayMode::FULL;
1363 displayGroupInfo.displaysInfo.push_back(displayInfo);
1364 for (uint32_t i = 0; i < MAX_WINDOW_NUMS; i++) {
1365 WindowInfo info;
1366 info.id = i + 1;
1367 info.pid = 1;
1368 info.uid = 1;
1369 info.area = {1, 1, 1, 1};
1370 info.defaultHotAreas = { info.area };
1371 info.pointerHotAreas = { info.area };
1372 info.pointerChangeAreas = {16, 5, 16, 5, 16, 5, 16, 5};
1373 info.transform = {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f};
1374 info.agentWindowId = 1;
1375 info.flags = 0;
1376 info.displayId = 0;
1377 info.zOrder = static_cast<float>(MAX_WINDOW_NUMS - i);
1378 displayGroupInfo.windowsInfo.push_back(info);
1379 }
1380 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateDisplayInfo(displayGroupInfo));
1381 }
1382
1383 /**
1384 * @tc.name: InputManagerTest_UpdateDisplayInfo for 1 display and 1 window
1385 * @tc.desc: Update window information
1386 * @tc.type: FUNC
1387 * @tc.require:
1388 */
1389 HWTEST_F(InputManagerTest, InputManagerTest_UpdateDisplayInfo003, TestSize.Level1)
1390 {
1391 CALL_TEST_DEBUG;
1392 DisplayGroupInfo displayGroupInfo;
1393 displayGroupInfo.focusWindowId = 1;
1394 displayGroupInfo.width = 1000;
1395 displayGroupInfo.height = 2000;
1396 DisplayInfo displayInfo;
1397 for (uint32_t i = 0; i < 2; i++) { // one is default-display and another is simulate display
1398 displayInfo.id = i;
1399 displayInfo.x =1;
1400 displayInfo.y = 1;
1401 displayInfo.width = 2;
1402 displayInfo.height = 2;
1403 displayInfo.dpi = 240;
1404 displayInfo.name = "pp";
1405 displayInfo.uniq = "pp";
1406 displayInfo.direction = DIRECTION0;
1407 displayGroupInfo.displaysInfo.push_back(displayInfo);
1408 }
1409 WindowInfo info;
1410 for (uint32_t i = 0; i < 2; i++) { // 2 widnows for 2 display
1411 info.id = 1;
1412 info.pid = 1;
1413 info.uid = 1;
1414 info.defaultHotAreas = { {1, 1, 1, 1} };
1415 info.agentWindowId = 1;
1416 info.flags = 0;
1417 info.displayId = i;
1418 displayGroupInfo.windowsInfo.push_back(info);
1419 }
1420 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateDisplayInfo(displayGroupInfo));
1421 }
1422
1423 /**
1424 * @tc.name: InputManagerTest_UpdateWindowGroupInfo_001
1425 * @tc.desc: Update window information
1426 * @tc.type: FUNC
1427 * @tc.require:
1428 */
1429 HWTEST_F(InputManagerTest, InputManagerTest_UpdateWindowGroupInfo_001, TestSize.Level1)
1430 {
1431 CALL_TEST_DEBUG;
1432 WindowInfo window;
1433 window.id = 1;
1434 window.action = WINDOW_UPDATE_ACTION::ADD;
1435 WindowGroupInfo windowGroupInfo;
1436 windowGroupInfo.displayId = 0;
1437 windowGroupInfo.focusWindowId = 1;
1438 windowGroupInfo.windowsInfo = {window};
1439 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateWindowInfo(windowGroupInfo));
1440 }
1441
1442 /**
1443 * @tc.name: InputManagerTest_UpdateWindowGroupInfo_002
1444 * @tc.desc: Update window information
1445 * @tc.type: FUNC
1446 * @tc.require:
1447 */
1448 HWTEST_F(InputManagerTest, InputManagerTest_UpdateWindowGroupInfo_002, TestSize.Level1)
1449 {
1450 CALL_TEST_DEBUG;
1451 WindowInfo window;
1452 window.id = 1;
1453 window.action = WINDOW_UPDATE_ACTION::CHANGE;
1454 WindowGroupInfo windowGroupInfo;
1455 windowGroupInfo.windowsInfo = {window};
1456 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateWindowInfo(windowGroupInfo));
1457 }
1458
1459 /**
1460 * @tc.name: InputManagerTest_UpdateWindowGroupInfo_003
1461 * @tc.desc: Update window information
1462 * @tc.type: FUNC
1463 * @tc.require:
1464 */
1465 HWTEST_F(InputManagerTest, InputManagerTest_UpdateWindowGroupInfo_003, TestSize.Level1)
1466 {
1467 CALL_TEST_DEBUG;
1468 WindowInfo window;
1469 window.id = 1;
1470 window.action = WINDOW_UPDATE_ACTION::DEL;
1471 WindowGroupInfo windowGroupInfo;
1472 windowGroupInfo.windowsInfo = {window};
1473 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateWindowInfo(windowGroupInfo));
1474 }
1475
1476 /**
1477 * @tc.name: InputManagerTest_UpdateWindowGroupInfo_004
1478 * @tc.desc: Update window information
1479 * @tc.type: FUNC
1480 * @tc.require:
1481 */
1482 HWTEST_F(InputManagerTest, InputManagerTest_UpdateWindowGroupInfo_004, TestSize.Level1)
1483 {
1484 CALL_TEST_DEBUG;
1485 WindowInfo window;
1486 window.id = 1;
1487 window.action = WINDOW_UPDATE_ACTION::UNKNOWN;
1488
1489 WindowGroupInfo windowGroupInfo;
1490 windowGroupInfo.windowsInfo = {window};
1491 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateWindowInfo(windowGroupInfo));
1492 }
1493
1494 /**
1495 * @tc.name: InputManagerTest_UpdateWindowGroupInfo_005
1496 * @tc.desc: Update window information
1497 * @tc.type: FUNC
1498 * @tc.require:
1499 */
1500 HWTEST_F(InputManagerTest, InputManagerTest_UpdateWindowGroupInfo_005, TestSize.Level1)
1501 {
1502 CALL_TEST_DEBUG;
1503 WindowInfo window;
1504 window.id = 1;
1505 window.action = WINDOW_UPDATE_ACTION::CHANGE;
1506 #ifdef OHOS_BUILD_ENABLE_ANCO
1507 window.flags |= SHELL_FLAGS_VALUE;
1508 #endif // OHOS_BUILD_ENABLE_ANCO
1509 WindowGroupInfo windowGroupInfo;
1510 windowGroupInfo.windowsInfo = {window};
1511 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UpdateWindowInfo(windowGroupInfo));
1512 }
1513
1514 #ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT
1515 /**
1516 * @tc.name: InputManagerTest_SetEnhanceConfig_001
1517 * @tc.desc: Set Secutity component enhance config
1518 * @tc.type: FUNC
1519 * @tc.require:
1520 */
1521 HWTEST_F(InputManagerTest, InputManagerTest_SetEnhanceConfig_001, TestSize.Level1)
1522 {
1523 CALL_TEST_DEBUG;
1524 uint8_t cfgData[16] = {0};
1525 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->SetEnhanceConfig(cfgData, 16));
1526 }
1527 #endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT
1528
1529 /**
1530 * @tc.name: InputManagerTest_GetDevice_001
1531 * @tc.desc: Verify the fetch device info
1532 * @tc.type: FUNC
1533 * @tc.require:
1534 */
1535 HWTEST_F(InputManagerTest, InputManagerTest_GetDevice_001, TestSize.Level1)
1536 {
1537 CALL_TEST_DEBUG;
1538 int32_t deviceId = 0;
__anonce2bd3131802(std::shared_ptr<InputDevice> inputDevice) 1539 auto callback = [](std::shared_ptr<InputDevice> inputDevice) {
1540 MMI_HILOGD("Get device success");
1541 ASSERT_TRUE(inputDevice != nullptr);
1542 };
1543 InputManager::GetInstance()->GetDevice(deviceId, callback);
1544 }
1545
1546 /**
1547 * @tc.name: InputManagerTest_GetDevice_002
1548 * @tc.desc: Verify the fetch device info
1549 * @tc.type: FUNC
1550 * @tc.require:
1551 */
1552 HWTEST_F(InputManagerTest, InputManagerTest_GetDevice_002, TestSize.Level1)
1553 {
1554 CALL_TEST_DEBUG;
1555 int32_t deviceId = INVAID_VALUE;
__anonce2bd3131902(std::shared_ptr<InputDevice> inputDevice) 1556 auto callback = [](std::shared_ptr<InputDevice> inputDevice) {
1557 MMI_HILOGD("Get device success");
1558 ASSERT_TRUE(inputDevice != nullptr);
1559 };
1560 int32_t ret = InputManager::GetInstance()->GetDevice(deviceId, callback);
1561 ASSERT_NE(ret, RET_OK);
1562 }
1563
1564 /**
1565 * @tc.name: InputManagerTest_GetDeviceIds
1566 * @tc.desc: Verify the fetch device list
1567 * @tc.type: FUNC
1568 * @tc.require:
1569 */
1570 HWTEST_F(InputManagerTest, InputManagerTest_GetDeviceIds, TestSize.Level1)
1571 {
1572 CALL_TEST_DEBUG;
__anonce2bd3131a02(std::vector<int32_t> ids) 1573 auto callback = [](std::vector<int32_t> ids) { MMI_HILOGD("Get device success"); };
1574 int32_t ret = InputManager::GetInstance()->GetDeviceIds(callback);
1575 ASSERT_EQ(ret, RET_OK);
1576 }
1577
1578 /**
1579 * @tc.name: InputManagerTest_EventTypeToString
1580 * @tc.desc: Verify inputevent interface
1581 * @tc.type: FUNC
1582 * @tc.require:
1583 */
1584 HWTEST_F(InputManagerTest, InputManagerTest_EventTypeToString, TestSize.Level1)
1585 {
1586 CALL_TEST_DEBUG;
1587 auto inputEvent = InputEvent::Create();
1588 ASSERT_NE(inputEvent, nullptr);
1589 auto ret = inputEvent->EventTypeToString(InputEvent::EVENT_TYPE_BASE);
1590 ASSERT_STREQ(ret, "base");
1591 ret = inputEvent->EventTypeToString(InputEvent::EVENT_TYPE_KEY);
1592 ASSERT_STREQ(ret, "key");
1593 ret = inputEvent->EventTypeToString(InputEvent::EVENT_TYPE_AXIS);
1594 ASSERT_STREQ(ret, "axis");
1595 ret = inputEvent->EventTypeToString(INVAID_VALUE);
1596 ASSERT_STREQ(ret, "unknown");
1597 }
1598
1599 /**
1600 * @tc.name: InputManagerTest_InputDeviceInterface_001
1601 * @tc.desc: Verify inputdevice interface
1602 * @tc.type: FUNC
1603 * @tc.require:
1604 */
1605 HWTEST_F(InputManagerTest, InputManagerTest_InputDeviceInterface_001, TestSize.Level1)
1606 {
1607 CALL_TEST_DEBUG;
1608 std::shared_ptr<InputDevice> inputDevice = std::make_shared<InputDevice>();
1609 ASSERT_NE(inputDevice, nullptr);
1610 inputDevice->SetId(0);
1611 ASSERT_EQ(inputDevice->GetId(), 0);
1612 inputDevice->SetName("name");
1613 ASSERT_STREQ(inputDevice->GetName().c_str(), "name");
1614 inputDevice->SetType(0);
1615 ASSERT_EQ(inputDevice->GetType(), 0);
1616 inputDevice->SetBus(0);
1617 ASSERT_EQ(inputDevice->GetBus(), 0);
1618 inputDevice->SetVersion(0);
1619 ASSERT_EQ(inputDevice->GetVersion(), 0);
1620 inputDevice->SetProduct(0);
1621 ASSERT_EQ(inputDevice->GetProduct(), 0);
1622 inputDevice->SetVendor(0);
1623 ASSERT_EQ(inputDevice->GetVendor(), 0);
1624 inputDevice->SetPhys("phys");
1625 ASSERT_STREQ(inputDevice->GetPhys().c_str(), "phys");
1626 inputDevice->SetUniq("uniq");
1627 ASSERT_STREQ(inputDevice->GetUniq().c_str(), "uniq");
1628 }
1629
1630 /**
1631 * @tc.name: InputManagerTest_InputDeviceInterface_002
1632 * @tc.desc: Verify inputdevice interface
1633 * @tc.type: FUNC
1634 * @tc.require:
1635 */
1636 HWTEST_F(InputManagerTest, InputManagerTest_InputDeviceInterface_002, TestSize.Level1)
1637 {
1638 CALL_TEST_DEBUG;
1639 std::shared_ptr<InputDevice> inputDevice = std::make_shared<InputDevice>();
1640 ASSERT_NE(inputDevice, nullptr);
1641 InputDevice::AxisInfo axis;
1642 axis.SetAxisType(0);
1643 axis.SetMinimum(0);
1644 axis.SetMaximum(1);
1645 axis.SetFuzz(0);
1646 axis.SetFlat(1);
1647 axis.SetResolution(0);
1648 inputDevice->AddAxisInfo(axis);
1649 auto iter = inputDevice->GetAxisInfo();
1650 ASSERT_EQ(iter[0].GetAxisType(), 0);
1651 ASSERT_EQ(iter[0].GetMinimum(), 0);
1652 ASSERT_EQ(iter[0].GetMaximum(), 1);
1653 ASSERT_EQ(iter[0].GetFuzz(), 0);
1654 ASSERT_EQ(iter[0].GetFlat(), 1);
1655 ASSERT_EQ(iter[0].GetResolution(), 0);
1656 }
1657
1658 /**
1659 * @tc.name: InputManagerTest_SetAnrObserver
1660 * @tc.desc: Verify the observer for events
1661 * @tc.type: FUNC
1662 * @tc.require:
1663 */
1664 HWTEST_F(InputManagerTest, InputManagerTest_SetAnrObserver, TestSize.Level1)
1665 {
1666 CALL_TEST_DEBUG;
1667 class IAnrObserverTest : public IAnrObserver {
1668 public:
IAnrObserverTest()1669 IAnrObserverTest() : IAnrObserver()
1670 {}
~IAnrObserverTest()1671 virtual ~IAnrObserverTest()
1672 {}
OnAnr(int32_t pid,int32_t eventId) const1673 void OnAnr(int32_t pid, int32_t eventId) const override
1674 {
1675 MMI_HILOGD("Set anr success");
1676 };
1677 };
1678
1679 std::shared_ptr<IAnrObserverTest> observer = std::make_shared<IAnrObserverTest>();
1680 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->SetAnrObserver(observer));
1681 }
1682
1683 /**
1684 * @tc.name: InputManagerTest_EnableInputDevice_001
1685 * @tc.desc: Enable input device
1686 * @tc.type: FUNC
1687 * @tc.require:
1688 */
1689 HWTEST_F(InputManagerTest, InputManagerTest_EnableInputDevice_001, TestSize.Level1)
1690 {
1691 CALL_TEST_DEBUG;
1692 auto ret = InputManager::GetInstance()->EnableInputDevice(false);
1693 ASSERT_EQ(ret, RET_OK);
1694 ret = InputManager::GetInstance()->EnableInputDevice(true);
1695 ASSERT_EQ(ret, RET_OK);
1696 }
1697
1698 /**
1699 * @tc.name: InputManagerTest_SensorInputTime_001
1700 * @tc.desc: Test SensorTime
1701 * @tc.type: FUNC
1702 * @tc.require:
1703 */
1704 HWTEST_F(InputManagerTest, InputManagerTest_SensorInputTime_001, TestSize.Level1)
1705 {
1706 CALL_TEST_DEBUG;
1707 auto pointerEvent = PointerEvent::Create();
1708 ASSERT_TRUE(pointerEvent != nullptr);
1709 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
1710 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
1711 pointerEvent->SetPointerId(0);
1712 pointerEvent->SetSensorInputTime(POINTER_SENSOR_INPUT_TIME);
1713 ASSERT_TRUE(pointerEvent->GetSensorInputTime() == POINTER_SENSOR_INPUT_TIME);
1714 }
1715
1716 /**
1717 * @tc.name: InputManagerTest_GetDisplayBindInfo_001
1718 * @tc.desc: Get diaplay bind information
1719 * @tc.type: FUNC
1720 * @tc.require:
1721 */
1722 HWTEST_F(InputManagerTest, InputManagerTest_GetDisplayBindInfo_001, TestSize.Level1)
1723 {
1724 CALL_TEST_DEBUG;
1725 OHOS::MMI::DisplayBindInfos infos;
1726 int32_t ret = InputManager::GetInstance()->GetDisplayBindInfo(infos);
1727 ASSERT_TRUE(ret == RET_OK);
1728 if (ret != RET_OK) {
1729 MMI_HILOGE("Call GetDisplayBindInfo failed, ret:%{public}d", ret);
1730 }
1731 }
1732
1733 /**
1734 * @tc.name: InputManagerTest_SetDisplayBind_001
1735 * @tc.desc: Set diaplay bind information
1736 * @tc.type: FUNC
1737 * @tc.require:
1738 */
1739 HWTEST_F(InputManagerTest, InputManagerTest_SetDisplayBind_001, TestSize.Level1)
1740 {
1741 CALL_TEST_DEBUG;
1742 int32_t deviceId = DEFAULT_DEVICE_ID;
1743 int32_t displayId = INVAID_VALUE;
1744 std::string msg;
1745 int32_t ret = InputManager::GetInstance()->SetDisplayBind(deviceId, displayId, msg);
1746 ASSERT_TRUE(ret == RET_OK);
1747 if (ret != RET_OK) {
1748 MMI_HILOGE("Call SetDisplayBind failed, ret:%{public}d", ret);
1749 }
1750 }
1751
1752 /**
1753 * @tc.name: InputManagerTest_MarkConsumed_001
1754 * @tc.desc: Mark Cosumer
1755 * @tc.type: FUNC
1756 * @tc.require:
1757 */
1758 HWTEST_F(InputManagerTest, InputManagerTest_MarkConsumed_001, TestSize.Level1)
1759 {
1760 CALL_TEST_DEBUG;
1761 auto consumer = GetPtr<InputEventConsumer>();
1762 ASSERT_TRUE(consumer != nullptr);
1763 int32_t monitorId = InputManager::GetInstance()->AddMonitor(consumer);
1764 auto pointerEvent = PointerEvent::Create();
1765 ASSERT_TRUE(pointerEvent != nullptr);
1766 auto eventId = pointerEvent->GetId();
1767 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->MarkConsumed(monitorId, eventId));
1768 }
1769
1770 /**
1771 * @tc.name: InputManagerTest_EnterCaptureMode_001
1772 * @tc.desc: Entering capture mode.
1773 * @tc.type: FUNC
1774 * @tc.require:
1775 */
1776 HWTEST_F(InputManagerTest, InputManagerTest_EnterCaptureMode_001, TestSize.Level1)
1777 {
1778 CALL_TEST_DEBUG;
1779 auto window = WindowUtilsTest::GetInstance()->GetWindow();
1780 CHKPV(window);
1781 uint32_t windowId = window->GetWindowId();
1782 int32_t ret = InputManager::GetInstance()->EnterCaptureMode(windowId);
1783 ASSERT_TRUE(ret == RET_OK);
1784 if (ret != RET_OK) {
1785 MMI_HILOGE("Call EnterCaptureMode failed, ret:%{public}d", ret);
1786 }
1787 }
1788
1789 /**
1790 * @tc.name: InputManagerTest_LeaveCaptureMode_001
1791 * @tc.desc: Leaving capture mode.
1792 * @tc.type: FUNC
1793 * @tc.require:
1794 */
1795 HWTEST_F(InputManagerTest, InputManagerTest_LeaveCaptureMode_001, TestSize.Level1)
1796 {
1797 CALL_TEST_DEBUG;
1798 auto window = WindowUtilsTest::GetInstance()->GetWindow();
1799 CHKPV(window);
1800 uint32_t windowId = window->GetWindowId();
1801 int32_t ret = InputManager::GetInstance()->LeaveCaptureMode(windowId);
1802 ASSERT_TRUE(ret == RET_OK);
1803 if (ret != RET_OK) {
1804 MMI_HILOGE("Call LeaveCaptureMode failed, ret:%{public}d", ret);
1805 }
1806 }
1807
1808 /**
1809 * @tc.name: InputManagerTest_GetWindowPid_001
1810 * @tc.desc: Get window pid.
1811 * @tc.type: FUNC
1812 * @tc.require:
1813 */
1814 HWTEST_F(InputManagerTest, InputManagerTest_GetWindowPid_001, TestSize.Level1)
1815 {
1816 CALL_TEST_DEBUG;
1817 auto window = WindowUtilsTest::GetInstance()->GetWindow();
1818 CHKPV(window);
1819 uint32_t windowId = window->GetWindowId();
1820 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->GetWindowPid(windowId));
1821 int32_t ret = InputManager::GetInstance()->GetWindowPid(windowId);
1822 if (ret == RET_ERR) {
1823 MMI_HILOGE("Call GetWindowPid failed, ret:%{public}d", ret);
1824 }
1825 }
1826
1827 /**
1828 * @tc.name: InputManagerTest_SetHoverScrollState_001
1829 * @tc.desc: Set hover scroll state
1830 * @tc.type: FUNC
1831 * @tc.require:
1832 */
1833 HWTEST_F(InputManagerTest, InputManagerTest_SetHoverScrollState_001, TestSize.Level1)
1834 {
1835 CALL_TEST_DEBUG;
1836 auto ret = InputManager::GetInstance()->SetHoverScrollState(false);
1837 ASSERT_EQ(ret, RET_OK);
1838 ret = InputManager::GetInstance()->SetHoverScrollState(true);
1839 ASSERT_EQ(ret, RET_OK);
1840 }
1841
1842 /**
1843 * @tc.name: InputManagerTest_GetHoverScrollState_001
1844 * @tc.desc: Get hover scroll state
1845 * @tc.type: FUNC
1846 * @tc.require:
1847 */
1848 HWTEST_F(InputManagerTest, InputManagerTest_GetHoverScrollState_001, TestSize.Level1)
1849 {
1850 CALL_TEST_DEBUG;
1851 bool statefalse = false;
1852 auto ret = InputManager::GetInstance()->GetHoverScrollState(statefalse);
1853 ASSERT_EQ(ret, RET_OK);
1854 bool statetrue = true;
1855 ret = InputManager::GetInstance()->GetHoverScrollState(statetrue);
1856 ASSERT_EQ(ret, RET_OK);
1857 }
1858
1859 /**
1860 * @tc.name: InputManagerTest_SetPointerVisible_001
1861 * @tc.desc: Set pointer visible
1862 * @tc.type: FUNC
1863 * @tc.require:
1864 */
1865 HWTEST_F(InputManagerTest, InputManagerTest_SetPointerVisible_001, TestSize.Level1)
1866 {
1867 CALL_TEST_DEBUG;
1868 auto ret = InputManager::GetInstance()->SetPointerVisible(false);
1869 ASSERT_EQ(ret, RET_OK);
1870 bool isVisible{true};
1871 if (InputManager::GetInstance()->SetPointerVisible(isVisible) == RET_OK) {
1872 ASSERT_TRUE(InputManager::GetInstance()->IsPointerVisible() == isVisible);
1873 }
1874 }
1875
1876 /**
1877 * @tc.name: InputManagerTest_IsPointerVisible_001
1878 * @tc.desc: Test flag `InputEvent::EVENT_FLAG_HIDE_POINTER` on controlling pointer visibility
1879 * @tc.type: FUNC
1880 * @tc.require:
1881 */
1882 HWTEST_F(InputManagerTest, InputManagerTest_IsPointerVisible_001, TestSize.Level1)
1883 {
1884 CALL_TEST_DEBUG;
1885 PointerEvent::PointerItem item;
1886 item.SetPointerId(0);
1887 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_ONE);
1888 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_ONE);
1889
1890 auto pointerEvent = PointerEvent::Create();
1891 ASSERT_NE(pointerEvent, nullptr);
1892 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
1893 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
1894 pointerEvent->AddFlag(InputEvent::EVENT_FLAG_HIDE_POINTER);
1895 pointerEvent->SetPointerId(0);
1896 pointerEvent->AddPointerItem(item);
1897
1898 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
1899 ASSERT_TRUE(InputManager::GetInstance()->IsPointerVisible());
1900 }
1901
1902 /**
1903 * @tc.name: InputManagerTest_IsPointerVisible_002
1904 * @tc.desc: Test flag `InputEvent::EVENT_FLAG_HIDE_POINTER` on controlling pointer visibility
1905 * @tc.type: FUNC
1906 * @tc.require:
1907 */
1908 HWTEST_F(InputManagerTest, InputManagerTest_IsPointerVisible_002, TestSize.Level1)
1909 {
1910 CALL_TEST_DEBUG;
1911 PointerEvent::PointerItem item;
1912 item.SetPointerId(0);
1913 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_TWO);
1914 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_TWO);
1915
1916 auto pointerEvent = PointerEvent::Create();
1917 ASSERT_NE(pointerEvent, nullptr);
1918 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
1919 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
1920 pointerEvent->SetPointerId(0);
1921 pointerEvent->AddPointerItem(item);
1922
1923 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
1924 ASSERT_TRUE(InputManager::GetInstance()->IsPointerVisible());
1925 }
1926
1927 /**
1928 * @tc.name: InputManagerTest_SetTouchpadScrollSwitch_001
1929 * @tc.desc: Set touchpad scroll switch
1930 * @tc.type: FUNC
1931 * @tc.require:
1932 */
1933 HWTEST_F(InputManagerTest, InputManagerTest_SetTouchpadScrollSwitch_001, TestSize.Level1)
1934 {
1935 CALL_TEST_DEBUG;
1936 auto ret = InputManager::GetInstance()->SetTouchpadScrollSwitch(false);
1937 ASSERT_EQ(ret, RET_OK);
1938 ret = InputManager::GetInstance()->SetTouchpadScrollSwitch(true);
1939 ASSERT_EQ(ret, RET_OK);
1940 }
1941
1942 /**
1943 * @tc.name: InputManagerTest_GetTouchpadScrollSwitch_001
1944 * @tc.desc: Get touchpad scroll switch
1945 * @tc.type: FUNC
1946 * @tc.require:
1947 */
1948 HWTEST_F(InputManagerTest, InputManagerTest_GetTouchpadScrollSwitch_001, TestSize.Level1)
1949 {
1950 CALL_TEST_DEBUG;
1951 bool flagfalse = false;
1952 auto ret = InputManager::GetInstance()->GetTouchpadScrollSwitch(flagfalse);
1953 ASSERT_EQ(ret, RET_OK);
1954 bool flagtrue = true;
1955 ret = InputManager::GetInstance()->GetTouchpadScrollSwitch(flagtrue);
1956 ASSERT_EQ(ret, RET_OK);
1957 }
1958
1959 /**
1960 * @tc.name: InputManagerTest_SetTouchpadScrollDirection_001
1961 * @tc.desc: Set touchpad scroll direction
1962 * @tc.type: FUNC
1963 * @tc.require:
1964 */
1965 HWTEST_F(InputManagerTest, InputManagerTest_SetTouchpadScrollDirection_001, TestSize.Level1)
1966 {
1967 CALL_TEST_DEBUG;
1968 auto ret = InputManager::GetInstance()->SetTouchpadScrollDirection(false);
1969 ASSERT_EQ(ret, RET_OK);
1970 ret = InputManager::GetInstance()->SetTouchpadScrollDirection(true);
1971 ASSERT_EQ(ret, RET_OK);
1972 }
1973
1974 /**
1975 * @tc.name: InputManagerTest_GetTouchpadScrollDirection_001
1976 * @tc.desc: Get touchpad scroll direction
1977 * @tc.type: FUNC
1978 * @tc.require:
1979 */
1980 HWTEST_F(InputManagerTest, InputManagerTest_GetTouchpadScrollDirection_001, TestSize.Level1)
1981 {
1982 CALL_TEST_DEBUG;
1983 bool statefalse = false;
1984 auto ret = InputManager::GetInstance()->GetTouchpadScrollDirection(statefalse);
1985 ASSERT_EQ(ret, RET_OK);
1986 bool statetrue = true;
1987 ret = InputManager::GetInstance()->GetTouchpadScrollDirection(statetrue);
1988 ASSERT_EQ(ret, RET_OK);
1989 }
1990
1991 /**
1992 * @tc.name: InputManagerTest_SetPointerSpeed_001
1993 * @tc.desc: Set pointer speed
1994 * @tc.type: FUNC
1995 * @tc.require:
1996 */
1997 HWTEST_F(InputManagerTest, InputManagerTest_SetPointerSpeed_001, TestSize.Level1)
1998 {
1999 CALL_TEST_DEBUG;
2000 const int32_t speed = INVAID_VALUE;
2001 InputManager::GetInstance()->SetPointerSpeed(speed);
2002 int32_t speed1;
2003 InputManager::GetInstance()->GetPointerSpeed(speed1);
2004 ASSERT_EQ(speed1, 1);
2005 }
2006
2007 /**
2008 * @tc.name: InputManagerTest_SetPointerLocation_001
2009 * @tc.desc: Set pointer location
2010 * @tc.type: FUNC
2011 * @tc.require:
2012 */
2013 HWTEST_F(InputManagerTest, InputManagerTest_SetPointerLocation_001, TestSize.Level1)
2014 {
2015 CALL_TEST_DEBUG;
2016 int32_t x = 0;
2017 int32_t y = 0;
2018 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->SetPointerLocation(x, y));
2019 }
2020
2021 /**
2022 * @tc.name: InputManagerTest_SetPointerLocation_002
2023 * @tc.desc: Set pointer location
2024 * @tc.type: FUNC
2025 * @tc.require:
2026 */
2027 HWTEST_F(InputManagerTest, InputManagerTest_SetPointerLocation_002, TestSize.Level1)
2028 {
2029 CALL_TEST_DEBUG;
2030 int32_t x = 10;
2031 int32_t y = 20;
2032 int32_t displayId = 32;
2033 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->SetPointerLocation(x, y, displayId));
2034 }
2035
2036 /**
2037 * @tc.name: InputManagerTest_GetTouchpadRightClickType_001
2038 * @tc.desc: Get touchpad right click type
2039 * @tc.type: FUNC
2040 * @tc.require:
2041 */
2042 HWTEST_F(InputManagerTest, InputManagerTest_GetTouchpadRightClickType_001, TestSize.Level1)
2043 {
2044 CALL_TEST_DEBUG;
2045 int32_t newType = 1;
2046 int32_t ret = InputManager::GetInstance()->GetTouchpadRightClickType(newType);
2047 ASSERT_EQ(ret, RET_OK);
2048 }
2049
2050 /**
2051 * @tc.name: InputManagerTest_GetKeyState_001
2052 * @tc.desc: Get key state
2053 * @tc.type: FUNC
2054 * @tc.require:
2055 */
2056 HWTEST_F(InputManagerTest, InputManagerTest_GetKeyState_001, TestSize.Level1)
2057 {
2058 CALL_TEST_DEBUG;
2059 std::vector<int32_t> pressedKeys;
2060 std::map<int32_t, int32_t> specialKeysState;
2061 int32_t ret = InputManager::GetInstance()->GetKeyState(pressedKeys, specialKeysState);
2062 ASSERT_EQ(ret, RET_OK);
2063 }
2064
2065 /**
2066 * @tc.name: InputManagerTest_MarkProcessed_001
2067 * @tc.desc: Mark processed
2068 * @tc.type: FUNC
2069 * @tc.require:
2070 */
2071 HWTEST_F(InputManagerTest, InputManagerTest_MarkProcessed_001, TestSize.Level1)
2072 {
2073 CALL_TEST_DEBUG;
2074 int32_t x = 0;
2075 int64_t y = 0;
2076 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->MarkProcessed(x, y));
2077 }
2078
2079 /**
2080 * @tc.name: InputManagerTest_SetCustomCursor
2081 * @tc.desc: Test set the wrong windowId for SetCustomCursor
2082 * @tc.type: FUNC
2083 * @tc.require:
2084 */
2085 HWTEST_F(InputManagerTest, InputManagerTest_SetCustomCursor, TestSize.Level1)
2086 {
2087 CALL_TEST_DEBUG;
2088 int32_t fakeWindowId = 100;
2089 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/North_South.svg";
2090 PointerStyle pointerStyle;
2091 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerUtil::SetMouseIconTest(iconPath);
2092 ASSERT_NE(pixelMap, nullptr);
2093 pointerStyle.id = MOUSE_ICON::DEVELOPER_DEFINED_ICON;
2094 ASSERT_FALSE(InputManager::GetInstance()->SetCustomCursor(fakeWindowId, (void *)pixelMap.get(), 32, 32) == RET_ERR);
2095 pixelMap = nullptr;
2096 }
2097
2098 /**
2099 * @tc.name: InputManagerTest_SetMouseIcon
2100 * @tc.desc: Test set the wrong windowId for SetMouseIcon
2101 * @tc.type: FUNC
2102 * @tc.require:
2103 */
2104 HWTEST_F(InputManagerTest, InputManagerTest_SetMouseIcon, TestSize.Level1)
2105 {
2106 CALL_TEST_DEBUG;
2107 int32_t fakeWindoId = 100;
2108 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/North_South.svg";
2109 PointerStyle pointerStyle;
2110 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerUtil::SetMouseIconTest(iconPath);
2111 ASSERT_NE(pixelMap, nullptr);
2112 pointerStyle.id = MOUSE_ICON::DEVELOPER_DEFINED_ICON;
2113 ASSERT_TRUE(InputManager::GetInstance()->SetMouseIcon(fakeWindoId, (void *)pixelMap.get()) == RET_ERR);
2114 pixelMap = nullptr;
2115 }
2116
2117 /**
2118 * @tc.name: InputManagerTest_SetMouseHotSpot
2119 * @tc.desc: Test set the wrong windowId for SetMouseHotSpot
2120 * @tc.type: FUNC
2121 * @tc.require:
2122 */
2123 HWTEST_F(InputManagerTest, InputManagerTest_SetMouseHotSpot, TestSize.Level1)
2124 {
2125 CALL_TEST_DEBUG;
2126 PointerStyle pointerStyle;
2127 pointerStyle.id = MOUSE_ICON::CROSS;
2128 int32_t fakeWindoId = 100;
2129 int32_t mouseIcon = 20;
2130 ASSERT_TRUE(
2131 InputManager::GetInstance()->SetMouseHotSpot(fakeWindoId, mouseIcon, mouseIcon) == RET_ERR);
2132 }
2133
2134
2135 /**
2136 * @tc.name: InputManagerTest_SetKeyDownDuration_001
2137 * @tc.desc: Customize the delay time for starting the ability by using the shortcut key.
2138 * @tc.type: FUNC
2139 * @tc.require:
2140 */
2141 HWTEST_F(InputManagerTest, InputManagerTest_SetKeyDownDuration_001, TestSize.Level1)
2142 {
2143 CALL_TEST_DEBUG;
2144 std::string businessId = "";
2145 int32_t delay = KEY_DOWN_DURATION;
2146 ASSERT_EQ(PARAMETER_ERROR, InputManager::GetInstance()->SetKeyDownDuration(businessId, delay));
2147 }
2148
2149 /**
2150 * @tc.name: InputManagerTest_SubscribeSwitchEvent_001
2151 * @tc.desc: Subscribes from a switch input event.
2152 * @tc.type: FUNC
2153 * @tc.require:
2154 */
2155 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeSwitchEvent_001, TestSize.Level1)
2156 {
__anonce2bd3131b02(std::shared_ptr<SwitchEvent> event) 2157 auto fun = [](std::shared_ptr<SwitchEvent> event) {
2158 MMI_HILOGD("Subscribe switch event success, type:%{public}d, value:%{public}d",
2159 event->GetSwitchType(), event->GetSwitchValue());
2160 };
2161 int32_t subscribeId = InputManager::GetInstance()->SubscribeSwitchEvent(fun, SwitchEvent::SwitchType::SWITCH_LID);
2162 ASSERT_NE(subscribeId, INVAID_VALUE);
2163 InputManager::GetInstance()->UnsubscribeSwitchEvent(subscribeId);
2164 }
2165
2166 /**
2167 * @tc.name: InputManagerTest_SubscribeSwitchEvent_002
2168 * @tc.desc: Subscribes from a switch input event.
2169 * @tc.type: FUNC
2170 * @tc.require:
2171 */
2172 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeSwitchEvent_002, TestSize.Level1)
2173 {
2174 ASSERT_EQ(InputManager::GetInstance()->SubscribeSwitchEvent(nullptr), -1);
2175 }
2176
2177 /**
2178 * @tc.name: InputManagerTest_SubscribeSwitchEvent_003
2179 * @tc.desc: Subscribes from a switch input event.
2180 * @tc.type: FUNC
2181 * @tc.require:
2182 */
2183 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeSwitchEvent_003, TestSize.Level1)
2184 {
__anonce2bd3131c02(std::shared_ptr<SwitchEvent> event) 2185 auto fun = [](std::shared_ptr<SwitchEvent> event) {
2186 MMI_HILOGD("Subscribe switch event success, type:%{public}d, value:%{public}d",
2187 event->GetSwitchType(), event->GetSwitchValue());
2188 };
2189 ASSERT_EQ(InputManager::GetInstance()->SubscribeSwitchEvent(
2190 fun, SwitchEvent::SwitchType(INVAID_VALUE)), -1);
2191 }
2192
2193 /**
2194 * @tc.name: InputManagerTest_UnsubscribeSwitchEvent_001
2195 * @tc.desc: Unsubscribes from a switch input event.
2196 * @tc.type: FUNC
2197 * @tc.require:
2198 */
2199 HWTEST_F(InputManagerTest, InputManagerTest_UnsubscribeSwitchEvent_001, TestSize.Level1)
2200 {
2201 CALL_TEST_DEBUG;
2202 int32_t subscriberId = INVAID_VALUE;
2203 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UnsubscribeSwitchEvent(subscriberId));
2204 }
2205
2206 /**
2207 * @tc.name: InputManagerTest_SubscribeLongPressEvent_01
2208 * @tc.desc: Verify invalid parameter : finger count less than 0.
2209 * @tc.type: FUNC
2210 * @tc.require: AR2024112192028
2211 * @tc.author:
2212 */
2213 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeLongPressEvent_01, TestSize.Level1)
2214 {
2215 CALL_TEST_DEBUG;
2216 LongPressRequest longPressRequest;
2217 longPressRequest.fingerCount = -1;
2218 longPressRequest.duration = 300;
2219 int32_t subscribeId = INVAID_VALUE;
2220 subscribeId = InputManager::GetInstance()->SubscribeLongPressEvent(longPressRequest,
__anonce2bd3131d02(const LongPressEvent &longPressEvent) 2221 [](const LongPressEvent &longPressEvent) {
2222 MMI_HILOGD("Subscribe long press event trigger callback");
2223 });
2224 EXPECT_TRUE(subscribeId < 0);
2225 }
2226
2227 /**
2228 * @tc.name: InputManagerTest_SubscribeLongPressEvent_02
2229 * @tc.desc: Verify invalid parameter : finger count equals 0.
2230 * @tc.type: FUNC
2231 * @tc.require: AR2024112192028
2232 * @tc.author:
2233 */
2234 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeLongPressEvent_02, TestSize.Level1)
2235 {
2236 CALL_TEST_DEBUG;
2237 LongPressRequest longPressRequest;
2238 longPressRequest.fingerCount = 0;
2239 longPressRequest.duration = 300;
2240 int32_t subscribeId = INVAID_VALUE;
2241 subscribeId = InputManager::GetInstance()->SubscribeLongPressEvent(longPressRequest,
__anonce2bd3131e02(const LongPressEvent &longPressEvent) 2242 [](const LongPressEvent &longPressEvent) {
2243 MMI_HILOGD("Subscribe long press event trigger callback");
2244 });
2245 EXPECT_TRUE(subscribeId < 0);
2246 }
2247
2248 /**
2249 * @tc.name: InputManagerTest_SubscribeLongPressEvent_03
2250 * @tc.desc: Verify valid parameter : finger count equals 2.
2251 * @tc.type: FUNC
2252 * @tc.require: AR2024112192028
2253 * @tc.author:
2254 */
2255 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeLongPressEvent_03, TestSize.Level1)
2256 {
2257 CALL_TEST_DEBUG;
2258 LongPressRequest longPressRequest;
2259 longPressRequest.fingerCount = 2;
2260 longPressRequest.duration = 300;
2261 int32_t subscribeId = INVAID_VALUE;
2262 subscribeId = InputManager::GetInstance()->SubscribeLongPressEvent(longPressRequest,
__anonce2bd3131f02(const LongPressEvent &longPressEvent) 2263 [](const LongPressEvent &longPressEvent) {
2264 MMI_HILOGD("Subscribe long press event trigger callback");
2265 });
2266 EXPECT_TRUE(subscribeId >= 0);
2267 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2268 InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId);
2269 }
2270
2271 /**
2272 * @tc.name: InputManagerTest_SubscribeLongPressEvent_04
2273 * @tc.desc: Verify invalid parameter : finger count greater than 2.
2274 * @tc.type: FUNC
2275 * @tc.require: AR2024112192028
2276 * @tc.author:
2277 */
2278 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeLongPressEvent_04, TestSize.Level1)
2279 {
2280 CALL_TEST_DEBUG;
2281 LongPressRequest longPressRequest;
2282 longPressRequest.fingerCount = 4;
2283 longPressRequest.duration = 300;
2284 int32_t subscribeId = INVAID_VALUE;
2285 subscribeId = InputManager::GetInstance()->SubscribeLongPressEvent(longPressRequest,
__anonce2bd3132002(const LongPressEvent &longPressEvent) 2286 [](const LongPressEvent &longPressEvent) {
2287 MMI_HILOGD("Subscribe long press event trigger callback");
2288 });
2289 EXPECT_TRUE(subscribeId < 0);
2290 }
2291
2292 /**
2293 * @tc.name: InputManagerTest_SubscribeLongPressEvent_05
2294 * @tc.desc: Verify invalid parameter : duration less than 0ms.
2295 * @tc.type: FUNC
2296 * @tc.require: AR2024112192028
2297 * @tc.author:
2298 */
2299 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeLongPressEvent_05, TestSize.Level1)
2300 {
2301 CALL_TEST_DEBUG;
2302 LongPressRequest longPressRequest;
2303 longPressRequest.fingerCount = 1;
2304 longPressRequest.duration = -1;
2305 int32_t subscribeId = INVAID_VALUE;
2306 subscribeId = InputManager::GetInstance()->SubscribeLongPressEvent(longPressRequest,
__anonce2bd3132102(const LongPressEvent &longPressEvent) 2307 [](const LongPressEvent &longPressEvent) {
2308 MMI_HILOGD("Subscribe long press event trigger callback");
2309 });
2310 EXPECT_TRUE(subscribeId < 0);
2311 }
2312
2313 /**
2314 * @tc.name: InputManagerTest_SubscribeLongPressEvent_06
2315 * @tc.desc: Verify invalid parameter : duration equals 0ms.
2316 * @tc.type: FUNC
2317 * @tc.require: AR2024112192028
2318 * @tc.author:
2319 */
2320 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeLongPressEvent_06, TestSize.Level1)
2321 {
2322 CALL_TEST_DEBUG;
2323 LongPressRequest longPressRequest;
2324 longPressRequest.fingerCount = 1;
2325 longPressRequest.duration = 0;
2326 int32_t subscribeId = INVAID_VALUE;
2327 subscribeId = InputManager::GetInstance()->SubscribeLongPressEvent(longPressRequest,
__anonce2bd3132202(const LongPressEvent &longPressEvent) 2328 [](const LongPressEvent &longPressEvent) {
2329 MMI_HILOGD("Subscribe long press event trigger callback");
2330 });
2331 EXPECT_TRUE(subscribeId < 0);
2332 }
2333
2334 /**
2335 * @tc.name: InputManagerTest_SubscribeLongPressEvent_07
2336 * @tc.desc: Verify valid parameter : duration equals 3000ms.
2337 * @tc.type: FUNC
2338 * @tc.require: AR2024112192028
2339 * @tc.author:
2340 */
2341 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeLongPressEvent_07, TestSize.Level1)
2342 {
2343 CALL_TEST_DEBUG;
2344 LongPressRequest longPressRequest;
2345 longPressRequest.fingerCount = 1;
2346 longPressRequest.duration = 3000;
2347 int32_t subscribeId = INVAID_VALUE;
2348 subscribeId = InputManager::GetInstance()->SubscribeLongPressEvent(longPressRequest,
__anonce2bd3132302(const LongPressEvent &longPressEvent) 2349 [](const LongPressEvent &longPressEvent) {
2350 MMI_HILOGD("Subscribe long press event trigger callback");
2351 });
2352 EXPECT_TRUE(subscribeId >= 0);
2353 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2354 InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId);
2355 }
2356
2357 /**
2358 * @tc.name: InputManagerTest_SubscribeLongPressEvent_08
2359 * @tc.desc: Verify invalid parameter : duration greater than 3000ms.
2360 * @tc.type: FUNC
2361 * @tc.require: AR2024112192028
2362 * @tc.author:
2363 */
2364 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeLongPressEvent_08, TestSize.Level1)
2365 {
2366 CALL_TEST_DEBUG;
2367 LongPressRequest longPressRequest;
2368 longPressRequest.fingerCount = 4;
2369 longPressRequest.duration = 3001;
2370 int32_t subscribeId = INVAID_VALUE;
2371 subscribeId = InputManager::GetInstance()->SubscribeLongPressEvent(longPressRequest,
__anonce2bd3132402(const LongPressEvent &longPressEvent) 2372 [](const LongPressEvent &longPressEvent) {
2373 MMI_HILOGD("Subscribe long press event trigger callback");
2374 });
2375 EXPECT_TRUE(subscribeId < 0);
2376 }
2377
2378 /**
2379 * @tc.name: InputManagerTest_SubscribeLongPressEvent_09
2380 * @tc.desc: Verify invalid parameter : null callback.
2381 * @tc.type: FUNC
2382 * @tc.require: AR2024112192028
2383 * @tc.author:
2384 */
2385 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeLongPressEvent_09, TestSize.Level1)
2386 {
2387 CALL_TEST_DEBUG;
2388 LongPressRequest longPressRequest;
2389 longPressRequest.fingerCount = 1;
2390 longPressRequest.duration = 300;
2391 int32_t subscribeId = INVAID_VALUE;
2392 subscribeId = InputManager::GetInstance()->SubscribeLongPressEvent(longPressRequest, nullptr);
2393 EXPECT_TRUE(subscribeId < 0);
2394 }
2395
2396 /**
2397 * @tc.name: InputManagerTest_SubscribeLongPressEvent_10
2398 * @tc.desc: Verify subscribe repeat long press event.
2399 * @tc.type: FUNC
2400 * @tc.require: AR2024112192028
2401 * @tc.author:
2402 */
2403 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeLongPressEvent_10, TestSize.Level1)
2404 {
2405 CALL_TEST_DEBUG;
2406 ASSERT_TRUE(MMIEventHdl.InitClient());
2407 int32_t subscribeId1 = INVAID_VALUE;
2408 LongPressRequest pressEvent;
2409 pressEvent.fingerCount = 1;
2410 pressEvent.duration = 300;
2411 subscribeId1 = InputManager::GetInstance()->SubscribeLongPressEvent(pressEvent,
__anonce2bd3132502(const LongPressEvent &longPressEvent) 2412 [](const LongPressEvent &longPressEvent) {
2413 MMI_HILOGD("Subscribe long press event trigger callback");
2414 });
2415 EXPECT_TRUE(subscribeId1 >= 0);
2416
2417 int32_t subscribeId2 = INVAID_VALUE;
2418 subscribeId2 = InputManager::GetInstance()->SubscribeLongPressEvent(pressEvent,
__anonce2bd3132602(const LongPressEvent &longPressEvent) 2419 [](const LongPressEvent &longPressEvent) {
2420 MMI_HILOGD("Subscribe long press event trigger callback");
2421 });
2422 EXPECT_TRUE(subscribeId2 >= 0);
2423
2424 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
2425 InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId1);
2426 InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId2);
2427 }
2428
2429
2430 /**
2431 * @tc.name: InputManagerTest_SubscribeLongPressEvent_11
2432 * @tc.desc: Verify subscribe ten long press event.
2433 * @tc.type: FUNC
2434 * @tc.require: AR2024112192028
2435 * @tc.author:
2436 */
2437 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeLongPressEvent_11, TestSize.Level1)
2438 {
2439 CALL_TEST_DEBUG;
2440 ASSERT_TRUE(MMIEventHdl.InitClient());
2441 int32_t subscribeId = INVAID_VALUE;
2442 LongPressRequest pressEvent;
2443 pressEvent.fingerCount = 1;
2444 pressEvent.duration = 300;
2445 std::vector<int32_t> ids;
2446 for (size_t i = 0; i < 10; ++i) {
2447 subscribeId = InputManager::GetInstance()->SubscribeLongPressEvent(pressEvent,
__anonce2bd3132702(const LongPressEvent &longPressEvent) 2448 [](const LongPressEvent &longPressEvent) {
2449 MMI_HILOGD("Subscribe long press event trigger callback");
2450 });
2451 EXPECT_TRUE(subscribeId >= 0);
2452 ids.push_back(subscribeId);
2453 pressEvent.duration += 100;
2454 }
2455 EXPECT_TRUE(ids.size() == 10);
2456 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
2457 for (size_t i = 0; i < ids.size(); ++i) {
2458 InputManager::GetInstance()->UnsubscribeLongPressEvent(ids[i]);
2459 }
2460 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
2461 }
2462
2463 /**
2464 * @tc.name: InputManagerTest_SubscribeLongPressEvent_12
2465 * @tc.desc: Verify subscribe two long press event.
2466 * @tc.type: FUNC
2467 * @tc.require: AR2024112192028
2468 * @tc.author:
2469 */
2470 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeLongPressEvent_12, TestSize.Level1)
2471 {
2472 CALL_TEST_DEBUG;
2473 ASSERT_TRUE(MMIEventHdl.InitClient());
2474 int32_t subscribeId1 = INVAID_VALUE;
2475 LongPressRequest pressEvent1;
2476 pressEvent1.fingerCount = 1;
2477 pressEvent1.duration = 300;
2478 subscribeId1 = InputManager::GetInstance()->SubscribeLongPressEvent(pressEvent1,
__anonce2bd3132802(const LongPressEvent &longPressEvent) 2479 [](const LongPressEvent &longPressEvent) {
2480 MMI_HILOGD("Subscribe long press event trigger callback");
2481 });
2482 EXPECT_TRUE(subscribeId1 >= 0);
2483
2484 int32_t subscribeId2 = INVAID_VALUE;
2485 LongPressRequest pressEvent2;
2486 pressEvent2.fingerCount = 2;
2487 pressEvent2.duration = 300;
2488 subscribeId2 = InputManager::GetInstance()->SubscribeLongPressEvent(pressEvent2,
__anonce2bd3132902(const LongPressEvent &longPressEvent) 2489 [](const LongPressEvent &longPressEvent) {
2490 MMI_HILOGD("Subscribe long press event trigger callback");
2491 });
2492 EXPECT_TRUE(subscribeId2 >= 0);
2493
2494 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
2495 InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId1);
2496 InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId2);
2497 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
2498 }
2499
2500 /**
2501 * @tc.name: InputManagerTest_SubscribeLongPressEvent_13
2502 * @tc.desc: Verify recognition algorithm of long press event, only subscribe two finger.
2503 * @tc.type: FUNC
2504 * @tc.require: AR2024112192028
2505 * @tc.author:
2506 */
2507 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeLongPressEvent_13, TestSize.Level1)
2508 {
2509 CALL_TEST_DEBUG;
2510 ASSERT_TRUE(MMIEventHdl.InitClient());
2511 int32_t subscribeId1 = INVAID_VALUE;
2512 LongPressRequest pressEvent1;
2513 pressEvent1.fingerCount = 2;
2514 pressEvent1.duration = 300;
2515 subscribeId1 = InputManager::GetInstance()->SubscribeLongPressEvent(pressEvent1,
__anonce2bd3132a02(const LongPressEvent &longPressEvent) 2516 [](const LongPressEvent &longPressEvent) {
2517 MMI_HILOGD("Subscribe long press event trigger callback");
2518 });
2519 EXPECT_TRUE(subscribeId1 >= 0);
2520
2521 int32_t subscribeId2 = INVAID_VALUE;
2522 LongPressRequest pressEvent2;
2523 pressEvent2.fingerCount = 2;
2524 pressEvent2.duration = 900;
2525 subscribeId2 = InputManager::GetInstance()->SubscribeLongPressEvent(pressEvent2,
__anonce2bd3132b02(const LongPressEvent &longPressEvent) 2526 [](const LongPressEvent &longPressEvent) {
2527 MMI_HILOGD("Subscribe long press event trigger callback");
2528 });
2529 EXPECT_TRUE(subscribeId2 >= 0);
2530
2531 int32_t subscribeId3 = INVAID_VALUE;
2532 LongPressRequest pressEvent3;
2533 pressEvent3.fingerCount = 2;
2534 pressEvent3.duration = 1500;
2535 subscribeId3 = InputManager::GetInstance()->SubscribeLongPressEvent(pressEvent3,
__anonce2bd3132c02(const LongPressEvent &longPressEvent) 2536 [](const LongPressEvent &longPressEvent) {
2537 MMI_HILOGD("Subscribe long press event trigger callback");
2538 });
2539 EXPECT_TRUE(subscribeId3 >= 0);
2540
2541 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
2542 InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId1);
2543 InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId2);
2544 InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId3);
2545 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
2546 }
2547
2548 /**
2549 * @tc.name: InputManagerTest_SubscribeLongPressEvent_14
2550 * @tc.desc: Verify recognition algorithm of long press event, subscribe one finger and two finger.
2551 * @tc.type: FUNC
2552 * @tc.require: AR2024112192028
2553 * @tc.author:
2554 */
2555 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeLongPressEvent_14, TestSize.Level1)
2556 {
2557 CALL_TEST_DEBUG;
2558 ASSERT_TRUE(MMIEventHdl.InitClient());
2559 int32_t subscribeId1 = INVAID_VALUE;
2560 LongPressRequest pressEvent1;
2561 pressEvent1.fingerCount = 1;
2562 pressEvent1.duration = 300;
2563 subscribeId1 = InputManager::GetInstance()->SubscribeLongPressEvent(pressEvent1,
__anonce2bd3132d02(const LongPressEvent &longPressEvent) 2564 [](const LongPressEvent &longPressEvent) {
2565 MMI_HILOGD("Subscribe long press event trigger callback");
2566 });
2567 EXPECT_TRUE(subscribeId1 >= 0);
2568
2569 int32_t subscribeId2 = INVAID_VALUE;
2570 LongPressRequest pressEvent2;
2571 pressEvent2.fingerCount = 2;
2572 pressEvent2.duration = 300;
2573 subscribeId2 = InputManager::GetInstance()->SubscribeLongPressEvent(pressEvent2,
__anonce2bd3132e02(const LongPressEvent &longPressEvent) 2574 [](const LongPressEvent &longPressEvent) {
2575 MMI_HILOGD("Subscribe long press event trigger callback");
2576 });
2577 EXPECT_TRUE(subscribeId2 >= 0);
2578
2579 int32_t subscribeId3 = INVAID_VALUE;
2580 LongPressRequest pressEvent3;
2581 pressEvent3.fingerCount = 1;
2582 pressEvent3.duration = 900;
2583 subscribeId3 = InputManager::GetInstance()->SubscribeLongPressEvent(pressEvent3,
__anonce2bd3132f02(const LongPressEvent &longPressEvent) 2584 [](const LongPressEvent &longPressEvent) {
2585 MMI_HILOGD("Subscribe long press event trigger callback");
2586 });
2587 EXPECT_TRUE(subscribeId3 >= 0);
2588
2589 int32_t subscribeId4 = INVAID_VALUE;
2590 LongPressRequest pressEvent4;
2591 pressEvent4.fingerCount = 2;
2592 pressEvent4.duration = 900;
2593 subscribeId4 = InputManager::GetInstance()->SubscribeLongPressEvent(pressEvent4,
__anonce2bd3133002(const LongPressEvent &longPressEvent) 2594 [](const LongPressEvent &longPressEvent) {
2595 MMI_HILOGD("Subscribe long press event trigger callback");
2596 });
2597 EXPECT_TRUE(subscribeId4 >= 0);
2598
2599 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
2600 InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId1);
2601 InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId2);
2602 InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId3);
2603 InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId4);
2604 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
2605 }
2606
2607 /**
2608 * @tc.name: InputManagerTest_UnsubscribeLongPressEvent_01
2609 * @tc.desc: Verify invalid parameter : subscribe id less than 0.
2610 * @tc.type: FUNC
2611 * @tc.require: AR2024112192028
2612 * @tc.author:
2613 */
2614 HWTEST_F(InputManagerTest, InputManagerTest_UnsubscribeLongPressEvent_01, TestSize.Level1)
2615 {
2616 CALL_TEST_DEBUG;
2617 LongPressRequest longPressRequest;
2618 longPressRequest.fingerCount = 1;
2619 longPressRequest.duration = 300;
2620 int32_t subscribeId = INVAID_VALUE;
2621 subscribeId = InputManager::GetInstance()->SubscribeLongPressEvent(longPressRequest,
__anonce2bd3133102(const LongPressEvent &longPressEvent) 2622 [](const LongPressEvent &longPressEvent) {
2623 MMI_HILOGD("Subscribe long press event trigger callback");
2624 });
2625 EXPECT_TRUE(subscribeId >= 0);
2626 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2627 subscribeId = -1;
2628 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId));
2629 }
2630
2631 /**
2632 * @tc.name: InputManagerTest_UnsubscribeLongPressEvent_02
2633 * @tc.desc: Verify invalid parameter : subscribe id less than 0.
2634 * @tc.type: FUNC
2635 * @tc.require: AR2024112192028
2636 * @tc.author:
2637 */
2638 HWTEST_F(InputManagerTest, InputManagerTest_UnsubscribeLongPressEvent_02, TestSize.Level1)
2639 {
2640 CALL_TEST_DEBUG;
2641 int32_t subscribeId = INVAID_VALUE;
2642 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId));
2643 }
2644
2645 /**
2646 * @tc.name: InputManagerTest_UnsubscribeLongPressEvent_03
2647 * @tc.desc: Verify invalid parameter : subscribe id is not a subscribed value.
2648 * @tc.type: FUNC
2649 * @tc.require: AR2024112192028
2650 * @tc.author:
2651 */
2652 HWTEST_F(InputManagerTest, InputManagerTest_UnsubscribeLongPressEvent_03, TestSize.Level1)
2653 {
2654 CALL_TEST_DEBUG;
2655 LongPressRequest longPressRequest;
2656 longPressRequest.fingerCount = 1;
2657 longPressRequest.duration = 300;
2658 int32_t subscribeId = INVAID_VALUE;
2659 subscribeId = InputManager::GetInstance()->SubscribeLongPressEvent(longPressRequest,
__anonce2bd3133202(const LongPressEvent &longPressEvent) 2660 [](const LongPressEvent &longPressEvent) {
2661 MMI_HILOGD("Subscribe long press event trigger callback");
2662 });
2663 EXPECT_TRUE(subscribeId >= 0);
2664 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2665 subscribeId += 10;
2666 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId));
2667 }
2668
2669 /**
2670 * @tc.name: InputManagerTest_UnsubscribeLongPressEvent_04
2671 * @tc.desc: Verify cancel ten subscription.
2672 * @tc.type: FUNC
2673 * @tc.require: AR2024112192028
2674 * @tc.author:
2675 */
2676 HWTEST_F(InputManagerTest, InputManagerTest_UnsubscribeLongPressEvent_04, TestSize.Level1)
2677 {
2678 CALL_TEST_DEBUG;
2679 int32_t subscribeId = INVAID_VALUE;
2680 LongPressRequest pressEvent;
2681 pressEvent.fingerCount = 1;
2682 pressEvent.duration = 300;
2683 std::vector<int32_t> ids;
2684 for (size_t i = 0; i < 10; ++i) {
2685 subscribeId = InputManager::GetInstance()->SubscribeLongPressEvent(pressEvent,
__anonce2bd3133302(const LongPressEvent &longPressEvent) 2686 [](const LongPressEvent &longPressEvent) {
2687 MMI_HILOGD("Subscribe long press event trigger callback");
2688 });
2689 EXPECT_TRUE(subscribeId >= 0);
2690 ids.push_back(subscribeId);
2691 pressEvent.duration += 100;
2692 }
2693 EXPECT_TRUE(ids.size() == 10);
2694 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
2695 for (size_t i = 0; i < ids.size(); ++i) {
2696 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UnsubscribeLongPressEvent(subscribeId));
2697 }
2698 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
2699 }
2700
2701 /**
2702 * @tc.name: InputManagerTest_ClearWindowPointerStyle_001
2703 * @tc.desc: Verify invalid parameter.
2704 * @tc.type: FUNC
2705 * @tc.require:SR000GGQL4 AR000GJNGN
2706 * @tc.author: yangguang
2707 */
2708 HWTEST_F(InputManagerTest, InputManagerTest_ClearWindowPointerStyle_001, TestSize.Level1)
2709 {
2710 CALL_TEST_DEBUG;
2711 auto window = WindowUtilsTest::GetInstance()->GetWindow();
2712 CHKPV(window);
2713 uint32_t windowId = window->GetWindowId();
2714 PointerStyle pointerStyle;
2715 pointerStyle.id = MOUSE_ICON::CROSS;
2716 int32_t ret = InputManager::GetInstance()->SetPointerStyle(windowId, pointerStyle);
2717 InputManager::GetInstance()->ClearWindowPointerStyle(getpid(), windowId);
2718 PointerStyle style;
2719 ret = InputManager::GetInstance()->GetPointerStyle(windowId, style);
2720 EXPECT_TRUE(ret == RET_OK);
2721 }
2722
2723 HWTEST_F(InputManagerTest, InputManagerTest_SyncBundleName_001, TestSize.Level1)
2724 {
2725 CALL_TEST_DEBUG;
2726 auto mmiObserver = std::make_shared<IEventObserver>();
2727 InputManager::GetInstance()->AddInputEventObserver(mmiObserver);
2728 auto callbackPtr = GetPtr<InputEventCallback>();
2729 ASSERT_TRUE(callbackPtr != nullptr);
2730 int32_t monitorId = InputManagerUtil::TestAddMonitor(callbackPtr);
2731 InputManager::GetInstance()->SetNapStatus(10, 20, "bundleName_test", 0);
2732 std::map<std::tuple<int32_t, int32_t, std::string>, int32_t> mapBefore;
2733 InputManager::GetInstance()->GetAllMmiSubscribedEvents(mapBefore);
2734 for (auto map = mapBefore.begin(); map != mapBefore.end(); ++map) {
2735 if (std::get<TUPLE_PID>(map->first) == 10) {
2736 EXPECT_TRUE(std::get<TUPLE_UID>(map->first) == 20);
2737 EXPECT_TRUE(std::get<TUPLE_NAME>(map->first) == "bundleName_test");
2738 EXPECT_TRUE(map->second == 0);
2739 }
2740 }
2741 for (const auto& map : mapBefore) {
2742 MMI_HILOGD("All NapStatus in mapBefore pid:%{public}d, uid:%{public}d, name:%{public}s, status:%{public}d",
2743 std::get<TUPLE_PID>(map.first), std::get<TUPLE_UID>(map.first), std::get<TUPLE_NAME>(map.first).c_str(),
2744 map.second);
2745 }
2746 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2747 InputManagerUtil::TestRemoveMonitor(monitorId);
2748 InputManager::GetInstance()->SetNapStatus(10, 20, "bundleName_test", 2);
2749 std::map<std::tuple<int32_t, int32_t, std::string>, int32_t> mapAfter;
2750 InputManager::GetInstance()->GetAllMmiSubscribedEvents(mapAfter);
2751 for (const auto& map : mapAfter) {
2752 EXPECT_FALSE(std::get<TUPLE_PID>(map.first) == 10);
2753 EXPECT_FALSE(std::get<TUPLE_UID>(map.first) == 20);
2754 EXPECT_FALSE(std::get<TUPLE_NAME>(map.first) == "bundleName_test");
2755 }
2756 for (const auto& map : mapAfter) {
2757 MMI_HILOGD("All NapStatus in mapAfter pid:%{public}d, uid:%{public}d, name:%{public}s, status:%{public}d",
2758 std::get<TUPLE_PID>(map.first), std::get<TUPLE_UID>(map.first), std::get<TUPLE_NAME>(map.first).c_str(),
2759 map.second);
2760 }
2761 InputManager::GetInstance()->RemoveInputEventObserver(mmiObserver);
2762 }
2763
2764 /**
2765 * @tc.name: InputManager_InjectMouseEvent_001
2766 * @tc.desc: Injection interface detection
2767 * @tc.type: FUNC
2768 * @tc.require:AR000GJG6G
2769 */
2770 HWTEST_F(InputManagerTest, InputManager_InjectMouseEvent_001, TestSize.Level1)
2771 {
2772 CALL_TEST_DEBUG;
2773 auto pointerEvent = PointerEvent::Create();
2774 pointerEvent->SetButtonId(PointerEvent::MOUSE_BUTTON_LEFT);
2775 pointerEvent->SetButtonPressed(PointerEvent::MOUSE_BUTTON_LEFT);
2776 ASSERT_NE(pointerEvent, nullptr);
2777
2778 PointerEvent::PointerItem item;
2779 item.SetPointerId(0);
2780 item.SetDisplayX(200);
2781 item.SetDisplayY(200);
2782 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN);
2783 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
2784 pointerEvent->SetPointerId(0);
2785 pointerEvent->AddPointerItem(item);
2786 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2787 }
2788
2789 /**
2790 * @tc.name: InputManager_InjectMouseEvent_002
2791 * @tc.desc: Injection interface detection
2792 * @tc.type: FUNC
2793 * @tc.require:AR000GJG6G
2794 */
2795 HWTEST_F(InputManagerTest, InputManager_InjectMouseEvent_002, TestSize.Level1)
2796 {
2797 CALL_TEST_DEBUG;
2798 auto pointerEvent = PointerEvent::Create();
2799 pointerEvent->SetButtonId(PointerEvent::MOUSE_BUTTON_LEFT);
2800 pointerEvent->SetButtonPressed(PointerEvent::MOUSE_BUTTON_LEFT);
2801 ASSERT_NE(pointerEvent, nullptr);
2802
2803 PointerEvent::PointerItem item;
2804 item.SetPointerId(0);
2805 item.SetDisplayX(200);
2806 item.SetDisplayY(200);
2807 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_UP);
2808 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
2809 pointerEvent->SetPointerId(0);
2810 pointerEvent->AddPointerItem(item);
2811 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2812 }
2813
2814 /**
2815 * @tc.name: InputManager_InjectMouseEvent_003
2816 * @tc.desc: Injection interface detection
2817 * @tc.type: FUNC
2818 * @tc.require:AR000GJG6G
2819 */
2820 HWTEST_F(InputManagerTest, InputManager_InjectMouseEvent_003, TestSize.Level1)
2821 {
2822 CALL_TEST_DEBUG;
2823 auto pointerEvent = PointerEvent::Create();
2824 ASSERT_NE(pointerEvent, nullptr);
2825
2826 PointerEvent::PointerItem item;
2827 item.SetPointerId(0);
2828 item.SetDisplayX(200);
2829 item.SetDisplayY(200);
2830 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
2831 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
2832 pointerEvent->SetPointerId(0);
2833 pointerEvent->AddPointerItem(item);
2834 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2835 }
2836
SimulateInputEventInjectKeyTest(int32_t keyAction,int32_t keyCode,bool isPressed,int32_t downTime)2837 static bool SimulateInputEventInjectKeyTest(int32_t keyAction, int32_t keyCode, bool isPressed, int32_t downTime)
2838 {
2839 auto keyEvent = KeyEvent::Create();
2840 if (keyEvent == nullptr) {
2841 return false;
2842 }
2843 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
2844 keyEvent->SetKeyCode(keyCode);
2845
2846 KeyEvent::KeyItem item;
2847 keyEvent->SetKeyAction(keyAction);
2848 item.SetKeyCode(keyCode);
2849 item.SetPressed(isPressed);
2850 item.SetDownTime(downTime);
2851 keyEvent->AddKeyItem(item);
2852 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
2853 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
2854 return true;
2855 }
2856
2857 /**
2858 * @tc.name: InputManager_InjectKeyEvent_001
2859 * @tc.desc: Injection interface detection
2860 * @tc.type: FUNC
2861 * @tc.require:
2862 */
2863 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_001, TestSize.Level1)
2864 {
2865 CALL_TEST_DEBUG;
__anonce2bd3133402(std::shared_ptr<KeyEvent> event) 2866 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
2867 MMI_HILOGD("Add monitor success");
2868 };
2869 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
2870 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
2871 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
2872 KeyEvent::KEYCODE_CALL_NOTIFICATION_CENTER, true, 500));
2873 InputManager::GetInstance()->RemoveMonitor(monitorId);
2874 }
2875
2876 /**
2877 * @tc.name: InputManager_InjectKeyEvent_002
2878 * @tc.desc: Injection interface detection
2879 * @tc.type: FUNC
2880 * @tc.require:
2881 */
2882 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_002, TestSize.Level1)
2883 {
2884 CALL_TEST_DEBUG;
__anonce2bd3133502(std::shared_ptr<KeyEvent> event) 2885 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
2886 MMI_HILOGD("Add monitor success");
2887 };
2888 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
2889 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
2890 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
2891 KeyEvent::KEYCODE_CALL_CONTROL_CENTER, true, 500));
2892 InputManager::GetInstance()->RemoveMonitor(monitorId);
2893 }
2894
2895 /**
2896 * @tc.name: InputManager_InjectKeyEvent_003
2897 * @tc.desc: Injection interface detection
2898 * @tc.type: FUNC
2899 * @tc.require:
2900 */
2901 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_003, TestSize.Level1)
2902 {
2903 CALL_TEST_DEBUG;
__anonce2bd3133602(std::shared_ptr<KeyEvent> event) 2904 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
2905 MMI_HILOGD("Add monitor success");
2906 };
2907 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
2908 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
2909 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
2910 KeyEvent::KEYCODE_CALL_NOTIFICATION_CENTER, false, 500));
2911 InputManager::GetInstance()->RemoveMonitor(monitorId);
2912 }
2913
2914 /**
2915 * @tc.name: InputManager_InjectKeyEvent_004
2916 * @tc.desc: Injection interface detection
2917 * @tc.type: FUNC
2918 * @tc.require:
2919 */
2920 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_004, TestSize.Level1)
2921 {
2922 CALL_TEST_DEBUG;
__anonce2bd3133702(std::shared_ptr<KeyEvent> event) 2923 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
2924 MMI_HILOGD("Add monitor success");
2925 };
2926 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
2927 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
2928 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
2929 KeyEvent::KEYCODE_CALL_CONTROL_CENTER, false, 500));
2930 InputManager::GetInstance()->RemoveMonitor(monitorId);
2931 }
2932
2933 /**
2934 * @tc.name: InputManager_InjectKeyEvent_005
2935 * @tc.desc: Injection interface detection
2936 * @tc.type: FUNC
2937 * @tc.require:
2938 */
2939 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_005, TestSize.Level1)
2940 {
2941 CALL_TEST_DEBUG;
__anonce2bd3133802(std::shared_ptr<KeyEvent> event) 2942 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
2943 MMI_HILOGD("Add monitor success");
2944 };
2945 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
2946 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
2947 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
2948 KeyEvent::KEYCODE_CALL_NOTIFICATION_CENTER, true, 1000));
2949 InputManager::GetInstance()->RemoveMonitor(monitorId);
2950 }
2951
2952 /**
2953 * @tc.name: InputManager_InjectKeyEvent_006
2954 * @tc.desc: Injection interface detection
2955 * @tc.type: FUNC
2956 * @tc.require:
2957 */
2958 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_006, TestSize.Level1)
2959 {
2960 CALL_TEST_DEBUG;
__anonce2bd3133902(std::shared_ptr<KeyEvent> event) 2961 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
2962 MMI_HILOGD("Add monitor success");
2963 };
2964 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
2965 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
2966 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
2967 KeyEvent::KEYCODE_CALL_CONTROL_CENTER, true, 1000));
2968 InputManager::GetInstance()->RemoveMonitor(monitorId);
2969 }
2970
2971 /**
2972 * @tc.name: InputManager_InjectKeyEvent_007
2973 * @tc.desc: Injection interface detection
2974 * @tc.type: FUNC
2975 * @tc.require:
2976 */
2977 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_007, TestSize.Level1)
2978 {
2979 CALL_TEST_DEBUG;
__anonce2bd3133a02(std::shared_ptr<KeyEvent> event) 2980 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
2981 MMI_HILOGD("Add monitor success");
2982 };
2983 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
2984 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
2985 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
2986 KeyEvent::KEYCODE_CALL_NOTIFICATION_CENTER, false, 1000));
2987 InputManager::GetInstance()->RemoveMonitor(monitorId);
2988 }
2989
2990 /**
2991 * @tc.name: InputManager_InjectKeyEvent_008
2992 * @tc.desc: Injection interface detection
2993 * @tc.type: FUNC
2994 * @tc.require:
2995 */
2996 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_008, TestSize.Level1)
2997 {
2998 CALL_TEST_DEBUG;
__anonce2bd3133b02(std::shared_ptr<KeyEvent> event) 2999 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
3000 MMI_HILOGD("Add monitor success");
3001 };
3002 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
3003 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
3004 ASSERT_TRUE(SimulateInputEventInjectKeyTest(KeyEvent::KEY_ACTION_DOWN,
3005 KeyEvent::KEYCODE_CALL_CONTROL_CENTER, false, 1000));
3006 InputManager::GetInstance()->RemoveMonitor(monitorId);
3007 }
3008
3009 /**
3010 * @tc.name: InputManager_InjectKeyEvent_009
3011 * @tc.desc: Injection interface detection
3012 * @tc.type: FUNC
3013 * @tc.require:
3014 */
3015 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_009, TestSize.Level1)
3016 {
3017 CALL_TEST_DEBUG;
__anonce2bd3133c02(std::shared_ptr<KeyEvent> event) 3018 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
3019 MMI_HILOGD("Add monitor success");
3020 };
3021 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
3022 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
3023 auto keyEvent = KeyEvent::Create();
3024 ASSERT_NE(keyEvent, nullptr);
3025 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
3026
3027 KeyEvent::KeyItem itemFirst;
3028 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
3029 keyEvent->SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
3030
3031 itemFirst.SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
3032 itemFirst.SetPressed(false);
3033 itemFirst.SetDownTime(1000);
3034 keyEvent->AddKeyItem(itemFirst);
3035
3036 KeyEvent::KeyItem itemSecond;
3037 itemSecond.SetKeyCode(KeyEvent::KEYCODE_R);
3038 itemSecond.SetPressed(true);
3039 itemSecond.SetDownTime(1000);
3040 keyEvent->AddKeyItem(itemSecond);
3041 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
3042 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
3043 InputManager::GetInstance()->RemoveMonitor(monitorId);
3044 }
3045
3046 /**
3047 * @tc.name: InputManager_InjectKeyEvent_010
3048 * @tc.desc: Injection interface detection
3049 * @tc.type: FUNC
3050 * @tc.require:
3051 */
3052 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_010, TestSize.Level1)
3053 {
3054 CALL_TEST_DEBUG;
__anonce2bd3133d02(std::shared_ptr<KeyEvent> event) 3055 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
3056 MMI_HILOGD("Add monitor success");
3057 };
3058 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
3059 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
3060 auto keyEvent = KeyEvent::Create();
3061 ASSERT_NE(keyEvent, nullptr);
3062 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
3063
3064 KeyEvent::KeyItem itemFirst;
3065 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
3066 keyEvent->SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
3067
3068 itemFirst.SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
3069 itemFirst.SetPressed(false);
3070 itemFirst.SetDownTime(1000);
3071 keyEvent->AddKeyItem(itemFirst);
3072
3073 KeyEvent::KeyItem itemSecond;
3074 itemSecond.SetKeyCode(KeyEvent::KEYCODE_R);
3075 itemSecond.SetPressed(false);
3076 itemSecond.SetDownTime(1000);
3077 keyEvent->AddKeyItem(itemSecond);
3078 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
3079 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
3080 InputManager::GetInstance()->RemoveMonitor(monitorId);
3081 }
3082
3083 /**
3084 * @tc.name: InputManager_InjectKeyEvent_011
3085 * @tc.desc: Injection interface detection
3086 * @tc.type: FUNC
3087 * @tc.require:AR000GJG6G mymy
3088 */
3089 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_011, TestSize.Level1)
3090 {
3091 CALL_TEST_DEBUG;
__anonce2bd3133e02(std::shared_ptr<KeyEvent> event) 3092 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
3093 MMI_HILOGD("Add monitor success");
3094 };
3095 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
3096 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
3097 auto keyEvent = KeyEvent::Create();
3098 ASSERT_NE(keyEvent, nullptr);
3099 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
3100
3101 KeyEvent::KeyItem itemFirst;
3102 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
3103 keyEvent->SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
3104
3105 itemFirst.SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
3106 itemFirst.SetPressed(false);
3107 itemFirst.SetDownTime(500);
3108 keyEvent->AddKeyItem(itemFirst);
3109
3110 KeyEvent::KeyItem itemSecond;
3111 itemSecond.SetKeyCode(KeyEvent::KEYCODE_R);
3112 itemSecond.SetPressed(false);
3113 itemSecond.SetDownTime(500);
3114 keyEvent->AddKeyItem(itemSecond);
3115 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
3116 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
3117 InputManager::GetInstance()->RemoveMonitor(monitorId);
3118 }
3119
3120 /**
3121 * @tc.name: InputManager_InjectKeyEvent_012
3122 * @tc.desc: Injection interface detection
3123 * @tc.type: FUNC
3124 * @tc.require:AR000GJG6G mymy
3125 */
3126 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_012, TestSize.Level1)
3127 {
3128 CALL_TEST_DEBUG;
__anonce2bd3133f02(std::shared_ptr<KeyEvent> event) 3129 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
3130 MMI_HILOGD("Add monitor success");
3131 };
3132 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
3133 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
3134 auto keyEvent = KeyEvent::Create();
3135 ASSERT_NE(keyEvent, nullptr);
3136 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
3137
3138 KeyEvent::KeyItem itemFirst;
3139 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
3140 keyEvent->SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
3141
3142 itemFirst.SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
3143 itemFirst.SetPressed(false);
3144 itemFirst.SetDownTime(500);
3145 keyEvent->AddKeyItem(itemFirst);
3146
3147 KeyEvent::KeyItem itemSecond;
3148 itemSecond.SetKeyCode(KeyEvent::KEYCODE_R);
3149 itemSecond.SetPressed(true);
3150 itemSecond.SetDownTime(500);
3151 keyEvent->AddKeyItem(itemSecond);
3152 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
3153 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
3154 InputManager::GetInstance()->RemoveMonitor(monitorId);
3155 }
3156
3157 /**
3158 * @tc.name: InputManager_InjectKeyEvent_013
3159 * @tc.desc: Injection interface detection
3160 * @tc.type: FUNC
3161 * @tc.require:
3162 */
3163 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_013, TestSize.Level1)
3164 {
3165 CALL_TEST_DEBUG;
__anonce2bd3134002(std::shared_ptr<KeyEvent> event) 3166 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
3167 MMI_HILOGD("Add monitor success");
3168 };
3169 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
3170 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
3171 auto keyEvent = KeyEvent::Create();
3172 ASSERT_NE(keyEvent, nullptr);
3173 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
3174
3175 KeyEvent::KeyItem itemFirst;
3176 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
3177 keyEvent->SetKeyCode(KeyEvent::KEYCODE_DAGGER_CLICK);
3178
3179 itemFirst.SetKeyCode(KeyEvent::KEYCODE_DAGGER_CLICK);
3180 itemFirst.SetPressed(true);
3181 itemFirst.SetDownTime(500);
3182 keyEvent->AddKeyItem(itemFirst);
3183
3184 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
3185 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
3186 InputManager::GetInstance()->RemoveMonitor(monitorId);
3187 }
3188
3189 /**
3190 * @tc.name: InputManager_InjectKeyEvent_014
3191 * @tc.desc: Injection interface detection
3192 * @tc.type: FUNC
3193 * @tc.require:
3194 */
3195 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_014, TestSize.Level1)
3196 {
3197 CALL_TEST_DEBUG;
__anonce2bd3134102(std::shared_ptr<KeyEvent> event) 3198 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
3199 MMI_HILOGD("Add monitor success");
3200 };
3201 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
3202 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
3203 auto keyEvent = KeyEvent::Create();
3204 ASSERT_NE(keyEvent, nullptr);
3205 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
3206
3207 KeyEvent::KeyItem itemFirst;
3208 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
3209 keyEvent->SetKeyCode(KeyEvent::KEYCODE_DAGGER_DOUBLE_CLICK);
3210
3211 itemFirst.SetKeyCode(KeyEvent::KEYCODE_DAGGER_DOUBLE_CLICK);
3212 itemFirst.SetPressed(true);
3213 itemFirst.SetDownTime(500);
3214 keyEvent->AddKeyItem(itemFirst);
3215
3216 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
3217 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
3218 InputManager::GetInstance()->RemoveMonitor(monitorId);
3219 }
3220
3221 /**
3222 * @tc.name: InputManager_InjectKeyEvent_015
3223 * @tc.desc: Injection interface detection
3224 * @tc.type: FUNC
3225 * @tc.require:
3226 */
3227 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_015, TestSize.Level1)
3228 {
3229 CALL_TEST_DEBUG;
__anonce2bd3134202(std::shared_ptr<KeyEvent> event) 3230 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
3231 MMI_HILOGD("Add monitor success");
3232 };
3233 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
3234 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
3235 auto keyEvent = KeyEvent::Create();
3236 ASSERT_NE(keyEvent, nullptr);
3237 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
3238
3239 KeyEvent::KeyItem itemFirst;
3240 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
3241 keyEvent->SetKeyCode(KeyEvent::KEYCODE_DAGGER_LONG_PRESS);
3242
3243 itemFirst.SetKeyCode(KeyEvent::KEYCODE_DAGGER_LONG_PRESS);
3244 itemFirst.SetPressed(true);
3245 itemFirst.SetDownTime(500);
3246 keyEvent->AddKeyItem(itemFirst);
3247
3248 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
3249 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
3250 InputManager::GetInstance()->RemoveMonitor(monitorId);
3251 }
3252
3253 /**
3254 * @tc.name: InputManager_InjectKeyEvent_016
3255 * @tc.desc: Injection interface detection
3256 * @tc.type: FUNC
3257 * @tc.require:
3258 */
3259 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_016, TestSize.Level1)
3260 {
3261 CALL_TEST_DEBUG;
__anonce2bd3134302(std::shared_ptr<KeyEvent> event) 3262 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
3263 MMI_HILOGD("Add monitor success");
3264 };
3265 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
3266 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
3267 auto keyEvent = KeyEvent::Create();
3268 ASSERT_NE(keyEvent, nullptr);
3269 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
3270
3271 KeyEvent::KeyItem itemFirst;
3272 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
3273 keyEvent->SetKeyCode(KeyEvent::KEYCODE_DAGGER_CLICK);
3274
3275 itemFirst.SetKeyCode(KeyEvent::KEYCODE_DAGGER_CLICK);
3276 itemFirst.SetPressed(false);
3277 itemFirst.SetDownTime(500);
3278 keyEvent->AddKeyItem(itemFirst);
3279
3280 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
3281 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
3282 InputManager::GetInstance()->RemoveMonitor(monitorId);
3283 }
3284
3285 /**
3286 * @tc.name: InputManager_InjectKeyEvent_017
3287 * @tc.desc: Injection interface detection
3288 * @tc.type: FUNC
3289 * @tc.require:
3290 */
3291 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_017, TestSize.Level1)
3292 {
3293 CALL_TEST_DEBUG;
__anonce2bd3134402(std::shared_ptr<KeyEvent> event) 3294 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
3295 MMI_HILOGD("Add monitor success");
3296 };
3297 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
3298 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
3299 auto keyEvent = KeyEvent::Create();
3300 ASSERT_NE(keyEvent, nullptr);
3301 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
3302
3303 KeyEvent::KeyItem itemFirst;
3304 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
3305 keyEvent->SetKeyCode(KeyEvent::KEYCODE_DAGGER_DOUBLE_CLICK);
3306
3307 itemFirst.SetKeyCode(KeyEvent::KEYCODE_DAGGER_DOUBLE_CLICK);
3308 itemFirst.SetPressed(false);
3309 itemFirst.SetDownTime(500);
3310 keyEvent->AddKeyItem(itemFirst);
3311
3312 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
3313 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
3314 InputManager::GetInstance()->RemoveMonitor(monitorId);
3315 }
3316
3317 /**
3318 * @tc.name: InputManager_InjectKeyEvent_018
3319 * @tc.desc: Injection interface detection
3320 * @tc.type: FUNC
3321 * @tc.require:
3322 */
3323 HWTEST_F(InputManagerTest, InputManager_InjectKeyEvent_018, TestSize.Level1)
3324 {
3325 CALL_TEST_DEBUG;
__anonce2bd3134502(std::shared_ptr<KeyEvent> event) 3326 auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
3327 MMI_HILOGD("Add monitor success");
3328 };
3329 int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
3330 ASSERT_NE(monitorId, ERROR_UNSUPPORT);
3331 auto keyEvent = KeyEvent::Create();
3332 ASSERT_NE(keyEvent, nullptr);
3333 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
3334
3335 KeyEvent::KeyItem itemFirst;
3336 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
3337 keyEvent->SetKeyCode(KeyEvent::KEYCODE_DAGGER_LONG_PRESS);
3338
3339 itemFirst.SetKeyCode(KeyEvent::KEYCODE_DAGGER_LONG_PRESS);
3340 itemFirst.SetPressed(false);
3341 itemFirst.SetDownTime(500);
3342 keyEvent->AddKeyItem(itemFirst);
3343
3344 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
3345 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
3346 InputManager::GetInstance()->RemoveMonitor(monitorId);
3347 }
3348
3349 /**
3350 * @tc.name: InputManager_InjectTouchEvent_001
3351 * @tc.desc: Injection interface detection
3352 * @tc.type: FUNC
3353 * @tc.require:AR000GJG6G
3354 */
3355 HWTEST_F(InputManagerTest, InputManager_InjectTouchEvent_001, TestSize.Level1)
3356 {
3357 CALL_TEST_DEBUG;
3358 auto pointerEvent = PointerEvent::Create();
3359 ASSERT_NE(pointerEvent, nullptr);
3360
3361 PointerEvent::PointerItem item;
3362 item.SetPointerId(0);
3363 item.SetDisplayX(200);
3364 item.SetDisplayY(200);
3365 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
3366 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
3367 pointerEvent->SetPointerId(0);
3368 pointerEvent->AddPointerItem(item);
3369 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3370 }
3371
3372 /**
3373 * @tc.name: InputManager_InjectTouchEvent_002
3374 * @tc.desc: Injection interface detection
3375 * @tc.type: FUNC
3376 * @tc.require:AR000GJG6G
3377 */
3378 HWTEST_F(InputManagerTest, InputManager_InjectTouchEvent_002, TestSize.Level1)
3379 {
3380 CALL_TEST_DEBUG;
3381 auto pointerEvent = PointerEvent::Create();
3382 ASSERT_NE(pointerEvent, nullptr);
3383
3384 PointerEvent::PointerItem item;
3385 item.SetPointerId(0);
3386 item.SetDisplayX(200);
3387 item.SetDisplayY(200);
3388 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
3389 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
3390 pointerEvent->SetPointerId(0);
3391 pointerEvent->AddPointerItem(item);
3392 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3393 }
3394
3395 /**
3396 * @tc.name: InputManager_InjectEvent_003
3397 * @tc.desc: Injection interface detection
3398 * @tc.type: FUNC
3399 * @tc.require:AR000GJG6G
3400 */
3401 HWTEST_F(InputManagerTest, InputManager_InjectEvent_003, TestSize.Level1)
3402 {
3403 CALL_TEST_DEBUG;
3404 auto keyEvent = KeyEvent::Create();
3405 ASSERT_NE(keyEvent, nullptr);
3406 ASSERT_NO_FATAL_FAILURE(keyEvent->SetRepeat(true));
3407 }
3408
3409 /**
3410 * @tc.name: InputManager_InjectEvent_001
3411 * @tc.desc: Injection interface detection
3412 * @tc.type: FUNC
3413 * @tc.require:AR000GJG6G
3414 */
3415 HWTEST_F(InputManagerTest, InputManager_InjectEvent_001, TestSize.Level1)
3416 {
3417 CALL_TEST_DEBUG;
3418 auto keyEvent = KeyEvent::Create();
3419 ASSERT_NE(keyEvent, nullptr);
3420 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
3421
3422 KeyEvent::KeyItem item;
3423 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
3424 item.SetKeyCode(2017);
3425 item.SetPressed(true);
3426 item.SetDownTime(500);
3427 keyEvent->AddKeyItem(item);
3428 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
3429 }
3430
3431 /**
3432 * @tc.name: InputManager_InjectEvent_002
3433 * @tc.desc: Injection interface detection
3434 * @tc.type: FUNC
3435 * @tc.require:AR000GJG6G
3436 */
3437 HWTEST_F(InputManagerTest, InputManager_InjectEvent_002, TestSize.Level1)
3438 {
3439 CALL_TEST_DEBUG;
3440 auto keyEvent = KeyEvent::Create();
3441 ASSERT_NE(keyEvent, nullptr);
3442 keyEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
3443 std::vector<int32_t> downKey;
3444 downKey.push_back(2072);
3445 downKey.push_back(2017);
3446
3447 KeyEvent::KeyItem item[downKey.size()];
3448 for (size_t i = 0; i < downKey.size(); i++) {
3449 keyEvent->SetKeyCode(2072);
3450 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
3451 item[i].SetKeyCode(downKey[i]);
3452 item[i].SetPressed(true);
3453 item[i].SetDownTime(0);
3454 keyEvent->AddKeyItem(item[i]);
3455 }
3456 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
3457 }
3458
3459 /**
3460 * @tc.name: InputManagerTest_GetPointerColor_001
3461 * @tc.desc: Obtains the mouse color.
3462 * @tc.type: FUNC
3463 * @tc.require:
3464 */
3465 HWTEST_F(InputManagerTest, InputManagerTest_GetPointerColor_001, TestSize.Level1)
3466 {
3467 CALL_TEST_DEBUG;
3468 int32_t setColor = 0x000000;
3469 InputManager::GetInstance()->SetPointerColor(setColor);
3470 int32_t getColor = 3;
3471 ASSERT_TRUE(InputManager::GetInstance()->GetPointerColor(getColor) == RET_OK);
3472 }
3473
3474 /**
3475 * @tc.name: InputManagerTest_SimulateInputEventExt_001
3476 * @tc.desc: Obtains the mouse color.
3477 * @tc.type: FUNC
3478 * @tc.require:
3479 */
3480 HWTEST_F(InputManagerTest, InputManagerTest_SimulateInputEventExt_001, TestSize.Level1)
3481 {
3482 CALL_TEST_DEBUG;
3483 auto pointerEvent = PointerEvent::Create();
3484 ASSERT_NE(pointerEvent, nullptr);
3485
3486 PointerEvent::PointerItem item;
3487 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_TWO);
3488 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_ONE);
3489 item.SetPressure(POINTER_ITEM_PRESSURE);
3490 item.SetPointerId(0);
3491 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
3492 pointerEvent->SetPointerId(0);
3493 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
3494 pointerEvent->AddPointerItem(item);
3495
3496 #ifdef OHOS_BUILD_ENABLE_ANCO
3497 InputManager::GetInstance()->SimulateInputEventExt(pointerEvent);
3498 InputManager::GetInstance()->SimulateInputEventExt(pointerEvent);
3499 InputManager::GetInstance()->SimulateInputEventExt(pointerEvent);
3500 #endif // OHOS_BUILD_ENABLE_ANCO
3501 }
3502
3503 /**
3504 * @tc.name: InputManagerTest_SimulateInputEventExt_002
3505 * @tc.desc: Obtains the mouse color.
3506 * @tc.type: FUNC
3507 * @tc.require:
3508 */
3509 HWTEST_F(InputManagerTest, InputManagerTest_SimulateInputEventExt_002, TestSize.Level1)
3510 {
3511 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
3512 ASSERT_TRUE(injectDownEvent != nullptr);
3513 int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
3514 KeyEvent::KeyItem kitDown;
3515 kitDown.SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
3516 kitDown.SetPressed(true);
3517 kitDown.SetDownTime(downTime);
3518 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
3519 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
3520 injectDownEvent->AddPressedKeyItems(kitDown);
3521
3522 #ifdef OHOS_BUILD_ENABLE_ANCO
3523 InputManager::GetInstance()->SimulateInputEventExt(injectDownEvent);
3524 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN);
3525 #endif // OHOS_BUILD_ENABLE_ANCO
3526 }
3527
3528 /**
3529 * @tc.name: InputManagerTest_SimulateInputEventZorder_001
3530 * @tc.desc: Simulate input evnet with zOrder.
3531 * @tc.type: FUNC
3532 * @tc.require:
3533 */
3534 HWTEST_F(InputManagerTest, InputManagerTest_SimulateInputEventZorder_001, TestSize.Level1)
3535 {
3536 CALL_TEST_DEBUG;
3537 auto pointerEvent = PointerEvent::Create();
3538 ASSERT_NE(pointerEvent, nullptr);
3539
3540 PointerEvent::PointerItem item;
3541 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_TWO);
3542 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_ONE);
3543 item.SetPressure(POINTER_ITEM_PRESSURE);
3544 item.SetPointerId(0);
3545 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
3546 pointerEvent->SetPointerId(0);
3547 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
3548 pointerEvent->AddPointerItem(item);
3549 pointerEvent->SetZOrder(10.0);
3550 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->SimulateInputEvent(pointerEvent, 10.0, false));
3551 }
3552
3553 /**
3554 * @tc.name: InputManagerTest_SetShieldStatus_001
3555 * @tc.desc: Test set shield status
3556 * @tc.type: FUNC
3557 * @tc.require:
3558 */
3559 HWTEST_F(InputManagerTest, InputManagerTest_SetShieldStatus_001, TestSize.Level1)
3560 {
3561 bool factoryModeStatus = false;
3562 bool oobeModeStatus = false;
3563 int32_t ret = InputManager::GetInstance()->SetShieldStatus(SHIELD_MODE::FACTORY_MODE, true);
3564 ASSERT_EQ(ret, RET_OK);
3565 ret = InputManager::GetInstance()->GetShieldStatus(SHIELD_MODE::FACTORY_MODE, factoryModeStatus);
3566 ASSERT_EQ(ret, RET_OK);
3567 ret = InputManager::GetInstance()->GetShieldStatus(SHIELD_MODE::OOBE_MODE, oobeModeStatus);
3568 ASSERT_EQ(ret, RET_OK);
3569 ASSERT_TRUE(factoryModeStatus);
3570 ASSERT_FALSE(oobeModeStatus);
3571 ret = InputManager::GetInstance()->SetShieldStatus(SHIELD_MODE::OOBE_MODE, true);
3572 ASSERT_EQ(ret, RET_OK);
3573 ret = InputManager::GetInstance()->GetShieldStatus(SHIELD_MODE::FACTORY_MODE, factoryModeStatus);
3574 ASSERT_EQ(ret, RET_OK);
3575 ret = InputManager::GetInstance()->GetShieldStatus(SHIELD_MODE::OOBE_MODE, oobeModeStatus);
3576 ASSERT_EQ(ret, RET_OK);
3577 ASSERT_FALSE(factoryModeStatus);
3578 ASSERT_TRUE(oobeModeStatus);
3579 ret = InputManager::GetInstance()->SetShieldStatus(SHIELD_MODE::OOBE_MODE, false);
3580 ASSERT_EQ(ret, RET_OK);
3581 ret = InputManager::GetInstance()->GetShieldStatus(SHIELD_MODE::FACTORY_MODE, factoryModeStatus);
3582 ASSERT_EQ(ret, RET_OK);
3583 ret = InputManager::GetInstance()->GetShieldStatus(SHIELD_MODE::OOBE_MODE, oobeModeStatus);
3584 ASSERT_EQ(ret, RET_OK);
3585 ASSERT_FALSE(factoryModeStatus);
3586 ASSERT_FALSE(oobeModeStatus);
3587 }
3588
3589 /**
3590 * @tc.name: InputManager_SimulateInputEvent_001
3591 * @tc.desc: Set SourceType to SOURCE_TYPE_MOUSE
3592 * @tc.type: FUNC
3593 * @tc.require:SR000GGN6G
3594 */
3595 HWTEST_F(InputManagerTest, InputManager_SimulateInputEvent_001, TestSize.Level1)
3596 {
3597 CALL_TEST_DEBUG;
3598 auto pointerEvent = PointerEvent::Create();
3599 ASSERT_NE(pointerEvent, nullptr);
3600 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
3601 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3602 }
3603
3604 /**
3605 * @tc.name: InputManager_SimulateInputEvent_002
3606 * @tc.desc: Set SourceType to SOURCE_TYPE_TOUCHPAD
3607 * @tc.type: FUNC
3608 * @tc.require:SR000GGN6G
3609 */
3610 HWTEST_F(InputManagerTest, InputManager_SimulateInputEvent_002, TestSize.Level1)
3611 {
3612 CALL_TEST_DEBUG;
3613 auto pointerEvent = PointerEvent::Create();
3614 ASSERT_NE(pointerEvent, nullptr);
3615 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD);
3616 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3617 }
3618
3619 /**
3620 * @tc.name: InputManager_SimulateInputEvent_003
3621 * @tc.desc: Set SourceType to SOURCE_TYPE_TOUCHSCREEN
3622 * @tc.type: FUNC
3623 * @tc.require:SR000GGN6G
3624 */
3625 HWTEST_F(InputManagerTest, InputManager_SimulateInputEvent_003, TestSize.Level1)
3626 {
3627 CALL_TEST_DEBUG;
3628 auto pointerEvent = PointerEvent::Create();
3629 ASSERT_NE(pointerEvent, nullptr);
3630 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
3631 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3632 }
3633
3634 /**
3635 * @tc.name: InputManager_SimulateInputEvent_004
3636 * @tc.desc: Set SourceType to SOURCE_TYPE_JOYSTICK
3637 * @tc.type: FUNC
3638 * @tc.require:SR000GGN6G
3639 */
3640 HWTEST_F(InputManagerTest, InputManager_SimulateInputEvent_004, TestSize.Level1)
3641 {
3642 CALL_TEST_DEBUG;
3643 auto pointerEvent = PointerEvent::Create();
3644 ASSERT_NE(pointerEvent, nullptr);
3645 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_JOYSTICK);
3646 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3647 }
3648
3649 /**
3650 * @tc.name: InputManager_SimulateInputEvent_005
3651 * @tc.desc: Set SourceType to invalid
3652 * @tc.type: FUNC
3653 * @tc.require:SR000GGN6G
3654 */
3655 HWTEST_F(InputManagerTest, InputManager_SimulateInputEvent_005, TestSize.Level1)
3656 {
3657 CALL_TEST_DEBUG;
3658 auto pointerEvent = PointerEvent::Create();
3659 ASSERT_NE(pointerEvent, nullptr);
3660 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_UNKNOWN);
3661 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3662 }
3663
3664 /**
3665 * @tc.name: InputManager_SimulateInputEvent_001
3666 * @tc.desc: SimulateInputEvent interface detection
3667 * @tc.type: FUNC
3668 * @tc.require:SR000GGN6G
3669 */
3670 HWTEST_F(InputManagerTest, InputManager_SimulateInputKeyEvent_001, TestSize.Level1)
3671 {
3672 CALL_TEST_DEBUG;
3673 auto keyEvent = KeyEvent::Create();
3674 ASSERT_NE(keyEvent, nullptr);
3675 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
3676 }
3677
3678 /**
3679 * @tc.name: InputManagerTest_RemoveInputEventFilter_001
3680 * @tc.desc: When eventFilterService is empty
3681 * @tc.type: FUNC
3682 * @tc.require:
3683 */
3684 HWTEST_F(InputManagerTest, InputManagerTest_RemoveInputEventFilter_001, TestSize.Level1)
3685 {
3686 CALL_TEST_DEBUG;
3687 int32_t ret = InputManager::GetInstance()->RemoveInputEventFilter(-1);
3688 ASSERT_EQ(ret, RET_OK);
3689 ret = InputManager::GetInstance()->RemoveInputEventFilter(0);
3690 ASSERT_EQ(ret, RET_OK);
3691 ret = InputManager::GetInstance()->RemoveInputEventFilter(1);
3692 ASSERT_EQ(ret, RET_OK);
3693 }
3694
3695 /**
3696 * @tc.name: InputManagerTest_RemoveInputEventFilter_002
3697 * @tc.desc: When the eventFilterService is full
3698 * @tc.type: FUNC
3699 * @tc.require:
3700 */
3701 HWTEST_F(InputManagerTest, InputManagerTest_RemoveInputEventFilter_002, TestSize.Level1)
3702 {
3703 CALL_DEBUG_ENTER;
3704 struct KeyFilter : public IInputEventFilter {
OnInputEventOHOS::MMI::KeyFilter3705 bool OnInputEvent(std::shared_ptr<KeyEvent> keyEvent) const override
3706 {
3707 MMI_HILOGI("KeyFilter::OnInputEvent enter,pid:%{public}d", getpid());
3708 return false;
3709 }
OnInputEventOHOS::MMI::KeyFilter3710 bool OnInputEvent(std::shared_ptr<PointerEvent> pointerEvent) const override
3711 {
3712 return false;
3713 }
3714 };
__anonce2bd3134602() 3715 auto addFilter = []() -> int32_t {
3716 auto filter = std::make_shared<KeyFilter>();
3717 uint32_t touchTags = CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX);
3718 const int32_t filterId = InputManager::GetInstance()->AddInputEventFilter(filter, 220, touchTags);
3719 return filterId;
3720 };
3721 const size_t singleClientSuportMaxNum = 4;
3722 for (size_t i = 0; i < singleClientSuportMaxNum; ++i) {
3723 int32_t filterId = addFilter();
3724 ASSERT_NE(filterId, RET_ERR);
3725 }
3726 int32_t filterId = addFilter();
3727 ASSERT_EQ(filterId, RET_ERR);
3728 auto ret = InputManager::GetInstance()->RemoveInputEventFilter(RET_ERR);
3729 ASSERT_EQ(ret, RET_OK);
3730 }
3731
3732 /**
3733 * @tc.name: InputManagerTest_RemoveInputEventFilter_003
3734 * @tc.desc: Verify valid parameter.
3735 * @tc.type: FUNC
3736 * @tc.require:
3737 */
3738 HWTEST_F(InputManagerTest, InputManagerTest_RemoveInputEventFilter_003, TestSize.Level1)
3739 {
3740 CALL_DEBUG_ENTER;
3741 struct KeyFilter : public IInputEventFilter {
OnInputEventOHOS::MMI::KeyFilter3742 bool OnInputEvent(std::shared_ptr<KeyEvent> keyEvent) const override
3743 {
3744 MMI_HILOGI("KeyFilter::OnInputEvent enter,pid:%{public}d", getpid());
3745 return false;
3746 }
OnInputEventOHOS::MMI::KeyFilter3747 bool OnInputEvent(std::shared_ptr<PointerEvent> pointerEvent) const override
3748 {
3749 return false;
3750 }
3751 };
__anonce2bd3134702() 3752 auto addFilter = []() -> int32_t {
3753 auto filter = std::make_shared<KeyFilter>();
3754 uint32_t touchTags = CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX);
3755 int32_t filterId = InputManager::GetInstance()->AddInputEventFilter(filter, 220, touchTags);
3756 return filterId;
3757 };
3758 int32_t filterId = addFilter();
3759 ASSERT_NE(filterId, RET_ERR);
3760 auto ret = InputManager::GetInstance()->RemoveInputEventFilter(filterId);
3761 ASSERT_EQ(ret, RET_OK);
3762 filterId = addFilter();
3763 ASSERT_NE(filterId, RET_ERR);
3764 ret = InputManager::GetInstance()->RemoveInputEventFilter(filterId);
3765 ASSERT_EQ(ret, RET_OK);
3766 }
3767
3768 /**
3769 * @tc.name: InputManager_SlideUpBrightScreenUnlockEvent_001
3770 * @tc.desc: Injection interface detection
3771 * @tc.type: FUNC
3772 * @tc.require:AR000GJG6G
3773 */
3774 HWTEST_F(InputManagerTest, InputManager_SlideUpBrightScreenUnlockEvent_001, TestSize.Level1)
3775 {
3776 CALL_TEST_DEBUG;
3777 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
3778 ASSERT_NE(injectDownEvent, nullptr);
3779 injectDownEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
3780
3781 KeyEvent::KeyItem kitDown;
3782 kitDown.SetKeyCode(KeyEvent::KEYCODE_F5);
3783 kitDown.SetPressed(true);
3784 kitDown.SetDownTime(500);
3785 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_F5);
3786 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
3787 injectDownEvent->AddPressedKeyItems(kitDown);
3788 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
3789
3790 std::shared_ptr<KeyEvent> injectUpEvent = KeyEvent::Create();
3791 ASSERT_NE(injectUpEvent, nullptr);
3792 injectDownEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
3793
3794 KeyEvent::KeyItem kitUp;
3795 kitUp.SetKeyCode(KeyEvent::KEYCODE_F5);
3796 kitUp.SetPressed(false);
3797 kitUp.SetDownTime(500);
3798 injectUpEvent->SetKeyCode(KeyEvent::KEYCODE_F5);
3799 injectUpEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
3800 injectUpEvent->RemoveReleasedKeyItems(kitUp);
3801 InputManager::GetInstance()->SimulateInputEvent(injectUpEvent);
3802 }
3803
3804 /**
3805 * @tc.name: InputManager_SimulateEvent_001
3806 * @tc.desc: Injection interface detection
3807 * @tc.type: FUNC
3808 * @tc.require:AR20240223308600
3809 */
3810 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_001, TestSize.Level1)
3811 {
3812 CALL_TEST_DEBUG;
3813 auto pointerEvent = InputManagerUtil::SetupSimulateEvent001();
3814 MMI_HILOGI("Before handle SimulateInputEvent");
3815 InputManagerUtil::PrintPointerEventId(pointerEvent);
3816 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3817 MMI_HILOGI("After handle SimulateInputEvent");
3818 InputManagerUtil::PrintPointerEventId(pointerEvent);
3819 }
3820
3821 /**
3822 * @tc.name: InputManager_SimulateEvent_002
3823 * @tc.desc: Injection interface detection
3824 * @tc.type: FUNC
3825 * @tc.require:AR20240223308600
3826 */
3827 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_002, TestSize.Level1)
3828 {
3829 CALL_TEST_DEBUG;
3830 auto pointerEvent = InputManagerUtil::SetupSimulateEvent002();
3831 MMI_HILOGI("Before handle SimulateInputEvent");
3832 InputManagerUtil::PrintPointerEventId(pointerEvent);
3833 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3834 MMI_HILOGI("After handle SimulateInputEvent");
3835 InputManagerUtil::PrintPointerEventId(pointerEvent);
3836 }
3837
3838 /**
3839 * @tc.name: InputManager_SimulateEvent_003
3840 * @tc.desc: Injection interface detection
3841 * @tc.type: FUNC
3842 * @tc.require:AR20240223308600
3843 */
3844 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_003, TestSize.Level1)
3845 {
3846 CALL_TEST_DEBUG;
3847 auto pointerEvent = InputManagerUtil::SetupSimulateEvent003();
3848 MMI_HILOGI("Before handle SimulateInputEvent");
3849 InputManagerUtil::PrintPointerEventId(pointerEvent);
3850 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3851 MMI_HILOGI("After handle SimulateInputEvent");
3852 InputManagerUtil::PrintPointerEventId(pointerEvent);
3853 }
3854
3855 /**
3856 * @tc.name: InputManager_SimulateEvent_004
3857 * @tc.desc: Injection interface detection
3858 * @tc.type: FUNC
3859 * @tc.require:AR20240223308600
3860 */
3861 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_004, TestSize.Level1)
3862 {
3863 CALL_TEST_DEBUG;
3864 auto pointerEvent = InputManagerUtil::SetupSimulateEvent004();
3865 MMI_HILOGI("Before handle SimulateInputEvent");
3866 InputManagerUtil::PrintPointerEventId(pointerEvent);
3867 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3868 MMI_HILOGI("After handle SimulateInputEvent");
3869 InputManagerUtil::PrintPointerEventId(pointerEvent);
3870 }
3871
3872 /**
3873 * @tc.name: InputManager_SimulateEvent_005
3874 * @tc.desc: Injection interface detection
3875 * @tc.type: FUNC
3876 * @tc.require:AR20240223308600
3877 */
3878 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_005, TestSize.Level1)
3879 {
3880 CALL_TEST_DEBUG;
3881 auto pointerEvent = InputManagerUtil::SetupSimulateEvent005();
3882 MMI_HILOGI("Before handle SimulateInputEvent");
3883 InputManagerUtil::PrintPointerEventId(pointerEvent);
3884 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3885 MMI_HILOGI("After handle SimulateInputEvent");
3886 InputManagerUtil::PrintPointerEventId(pointerEvent);
3887 }
3888
3889 /**
3890 * @tc.name: InputManager_SimulateEvent_006
3891 * @tc.desc: Injection interface detection
3892 * @tc.type: FUNC
3893 * @tc.require:AR20240223308600
3894 */
3895 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_006, TestSize.Level1)
3896 {
3897 CALL_TEST_DEBUG;
3898 auto pointerEvent = InputManagerUtil::SetupSimulateEvent006();
3899 MMI_HILOGI("Before handle SimulateInputEvent");
3900 InputManagerUtil::PrintPointerEventId(pointerEvent);
3901 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3902 MMI_HILOGI("After handle SimulateInputEvent");
3903 InputManagerUtil::PrintPointerEventId(pointerEvent);
3904 }
3905
3906 /**
3907 * @tc.name: InputManager_SimulateEvent_007
3908 * @tc.desc: Injection interface detection
3909 * @tc.type: FUNC
3910 * @tc.require:AR20240223308600
3911 */
3912 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_007, TestSize.Level1)
3913 {
3914 CALL_TEST_DEBUG;
3915 auto pointerEvent = InputManagerUtil::SetupSimulateEvent007();
3916 MMI_HILOGI("Before handle SimulateInputEvent");
3917 InputManagerUtil::PrintPointerEventId(pointerEvent);
3918 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3919 MMI_HILOGI("After handle SimulateInputEvent");
3920 InputManagerUtil::PrintPointerEventId(pointerEvent);
3921 }
3922
3923 /**
3924 * @tc.name: InputManager_SimulateEvent_008
3925 * @tc.desc: Injection interface detection
3926 * @tc.type: FUNC
3927 * @tc.require:AR20240223308600
3928 */
3929 HWTEST_F(InputManagerTest, InputManager_SimulateEvent_008, TestSize.Level1)
3930 {
3931 CALL_TEST_DEBUG;
3932 auto pointerEvent = InputManagerUtil::SetupSimulateEvent008();
3933 MMI_HILOGI("Before handle SimulateInputEvent");
3934 InputManagerUtil::PrintPointerEventId(pointerEvent);
3935 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3936 MMI_HILOGI("After handle SimulateInputEvent");
3937 InputManagerUtil::PrintPointerEventId(pointerEvent);
3938 }
3939
3940 class ServiceWatcher final : public IInputServiceWatcher {
3941 public:
3942 ServiceWatcher() = default;
3943 ~ServiceWatcher() = default;
3944
OnServiceDied()3945 void OnServiceDied() override
3946 {}
3947 };
3948
3949 /**
3950 * @tc.name: InputManagerTest_InputServiceWatcher
3951 * @tc.desc: Verify service watcher.
3952 * @tc.type: FUNC
3953 * @tc.require:
3954 */
3955 HWTEST_F(InputManagerTest, InputManagerTest_InputServiceWatcher, TestSize.Level1)
3956 {
3957 auto watcher = std::make_shared<ServiceWatcher>();
3958 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->AddServiceWatcher(watcher));
3959 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->RemoveServiceWatcher(watcher));
3960 }
3961
3962 /**
3963 * @tc.name: InputManagerTest_MoveMouse_001
3964 * @tc.desc: MoveMouse interface detection
3965 * @tc.type: FUNC
3966 * @tc.require:
3967 */
3968 HWTEST_F(InputManagerTest, InputManagerTest_MoveMouse_001, TestSize.Level1)
3969 {
3970 CALL_TEST_DEBUG;
3971 int32_t offsetX = 20;
3972 int32_t offsetY = 20;
3973 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->MoveMouse(offsetX, offsetY));
3974 }
3975
3976 /**
3977 * @tc.name: InputManagerTest_MouseScrollRows_001
3978 * @tc.desc: SetMouseScrollRows and GetMouseScrollRows interface detection
3979 * @tc.type: FUNC
3980 * @tc.require:
3981 */
3982 HWTEST_F(InputManagerTest, InputManagerTest_MouseScrollRows_001, TestSize.Level1)
3983 {
3984 CALL_TEST_DEBUG;
3985 int32_t rows = 1;
3986 int32_t result = InputManager::GetInstance()->SetMouseScrollRows(rows);
3987 ASSERT_EQ(result, RET_OK);
3988 result = InputManager::GetInstance()->GetMouseScrollRows(rows);
3989 ASSERT_EQ(rows, 1);
3990 ASSERT_EQ(result, RET_OK);
3991 }
3992
3993 /**
3994 * @tc.name: InputManagerTest_SetCustomCursor_001
3995 * @tc.desc: SetCustomCursor interface detection
3996 * @tc.type: FUNC
3997 * @tc.require:
3998 */
3999 HWTEST_F(InputManagerTest, InputManagerTest_SetCustomCursor_001, TestSize.Level1)
4000 {
4001 CALL_TEST_DEBUG;
4002 int32_t windowId = 500;
4003 void* pixelMap = nullptr;
4004 int32_t result = InputManager::GetInstance()->SetCustomCursor(windowId, pixelMap);
4005 ASSERT_EQ(result, 22);
4006 }
4007
4008 /**
4009 * @tc.name: InputManagerTest_SetMouseIcon_001
4010 * @tc.desc: SetMouseIcon interface detection
4011 * @tc.type: FUNC
4012 * @tc.require:
4013 */
4014 HWTEST_F(InputManagerTest, InputManagerTest_SetMouseIcon_001, TestSize.Level1)
4015 {
4016 CALL_TEST_DEBUG;
4017 int32_t windowId = 500;
4018 void* pixelMap = nullptr;
4019 int32_t result = InputManager::GetInstance()->SetMouseIcon(windowId, pixelMap);
4020 ASSERT_NE(result, RET_OK);
4021 }
4022
4023 /**
4024 * @tc.name: InputManagerTest_SetMouseHotSpot_001
4025 * @tc.desc: SetMouseHotSpot interface detection
4026 * @tc.type: FUNC
4027 * @tc.require:
4028 */
4029 HWTEST_F(InputManagerTest, InputManagerTest_SetMouseHotSpot_001, TestSize.Level1)
4030 {
4031 CALL_TEST_DEBUG;
4032 int32_t windowId = 500;
4033 int32_t hotSpotX = 20;
4034 int32_t hotSpotY = 20;
4035 int32_t result = InputManager::GetInstance()->SetMouseHotSpot(windowId, hotSpotX, hotSpotY);
4036 ASSERT_EQ(result, RET_ERR);
4037 }
4038
4039 /**
4040 * @tc.name: InputManagerTest_PointerSize_001
4041 * @tc.desc: SetPointerSize and GetPointerSize interface detection
4042 * @tc.type: FUNC
4043 * @tc.require:
4044 */
4045 HWTEST_F(InputManagerTest, InputManagerTest_PointerSize_001, TestSize.Level1)
4046 {
4047 CALL_TEST_DEBUG;
4048 int32_t size = 5;
4049 int32_t result = InputManager::GetInstance()->SetPointerSize(size);
4050 ASSERT_EQ(result, RET_OK);
4051 result = InputManager::GetInstance()->GetPointerSize(size);
4052 ASSERT_EQ(size, 5);
4053 ASSERT_EQ(result, RET_OK);
4054 }
4055
4056 /**
4057 * @tc.name: InputManagerTest_GetCursorSurfaceId_001
4058 * @tc.desc: SetPointerSize and GetPointerSize interface detection
4059 * @tc.type: FUNC
4060 * @tc.require:
4061 */
4062 HWTEST_F(InputManagerTest, InputManagerTest_GetCursorSurfaceId_001, TestSize.Level1)
4063 {
4064 CALL_TEST_DEBUG;
4065 uint64_t surfaceId {};
4066 auto result = InputManager::GetInstance()->GetCursorSurfaceId(surfaceId);
4067 ASSERT_EQ(result, RET_OK);
4068 std::cout << "CursorSurfaceId:" << surfaceId << std::endl;
4069 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->GetCursorSurfaceId(surfaceId));
4070 }
4071
4072 /**
4073 * @tc.name: InputManagerTest_MousePrimaryButton_001
4074 * @tc.desc: SetMousePrimaryButton and GetMousePrimaryButton interface detection
4075 * @tc.type: FUNC
4076 * @tc.require:
4077 */
4078 HWTEST_F(InputManagerTest, InputManagerTest_MousePrimaryButton_001, TestSize.Level1)
4079 {
4080 CALL_TEST_DEBUG;
4081 int32_t primaryButton = 2;
4082 int32_t result = InputManager::GetInstance()->SetMousePrimaryButton(primaryButton);
4083 ASSERT_EQ(result, RET_ERR);
4084 primaryButton = 1;
4085 result = InputManager::GetInstance()->SetMousePrimaryButton(primaryButton);
4086 ASSERT_EQ(result, RET_OK);
4087 result = InputManager::GetInstance()->GetMousePrimaryButton(primaryButton);
4088 ASSERT_EQ(primaryButton, 1);
4089 ASSERT_EQ(result, RET_OK);
4090 }
4091
4092 /**
4093 * @tc.name: InputManagerTest_TouchpadScrollDirection_001
4094 * @tc.desc: SetTouchpadScrollDirection and GetTouchpadScrollDirection interface detection
4095 * @tc.type: FUNC
4096 * @tc.require:
4097 */
4098 HWTEST_F(InputManagerTest, InputManagerTest_TouchpadScrollDirection_001, TestSize.Level1)
4099 {
4100 CALL_TEST_DEBUG;
4101 bool state = true;
4102 int32_t result = InputManager::GetInstance()->SetTouchpadScrollDirection(state);
4103 ASSERT_EQ(result, RET_OK);
4104 result = InputManager::GetInstance()->GetTouchpadScrollDirection(state);
4105 ASSERT_EQ(state, true);
4106 ASSERT_EQ(result, RET_OK);
4107 }
4108
4109 /**
4110 * @tc.name: InputManagerTest_TouchpadScrollDirection_001
4111 * @tc.desc: SetTouchpadScrollDirection and GetTouchpadScrollDirection interface detection
4112 * @tc.type: FUNC
4113 * @tc.require:
4114 */
4115 HWTEST_F(InputManagerTest, InputManagerTest_TouchpadScrollSwitch_001, TestSize.Level1)
4116 {
4117 CALL_TEST_DEBUG;
4118 bool switchFlag = true;
4119 int32_t result = InputManager::GetInstance()->SetTouchpadScrollSwitch(switchFlag);
4120 ASSERT_EQ(result, RET_OK);
4121 result = InputManager::GetInstance()->GetTouchpadScrollSwitch(switchFlag);
4122 ASSERT_EQ(switchFlag, true);
4123 ASSERT_EQ(result, RET_OK);
4124 }
4125
4126 /**
4127 * @tc.name: InputManagerTest_TouchpadPointerSpeed_001
4128 * @tc.desc: SetTouchpadPointerSpeed and GetTouchpadPointerSpeed interface detection
4129 * @tc.type: FUNC
4130 * @tc.require:
4131 */
4132 HWTEST_F(InputManagerTest, InputManagerTest_TouchpadPointerSpeed_001, TestSize.Level1)
4133 {
4134 CALL_TEST_DEBUG;
4135 int32_t speed = 1;
4136 int32_t result = InputManager::GetInstance()->SetTouchpadPointerSpeed(speed);
4137 ASSERT_EQ(result, RET_OK);
4138 result = InputManager::GetInstance()->GetTouchpadPointerSpeed(speed);
4139 ASSERT_EQ(speed, 1);
4140 ASSERT_EQ(result, RET_OK);
4141 }
4142
4143 /**
4144 * @tc.name: InputManagerTest_TouchpadPinchSwitch_001
4145 * @tc.desc: SetTouchpadPinchSwitch and GetTouchpadPinchSwitch interface detection
4146 * @tc.type: FUNC
4147 * @tc.require:
4148 */
4149 HWTEST_F(InputManagerTest, InputManagerTest_TouchpadPinchSwitch_001, TestSize.Level1)
4150 {
4151 CALL_TEST_DEBUG;
4152 bool switchFlag = true;
4153 int32_t result = InputManager::GetInstance()->SetTouchpadPinchSwitch(switchFlag);
4154 ASSERT_EQ(result, RET_OK);
4155 result = InputManager::GetInstance()->GetTouchpadPinchSwitch(switchFlag);
4156 ASSERT_EQ(switchFlag, true);
4157 ASSERT_EQ(result, RET_OK);
4158 }
4159
4160 /**
4161 * @tc.name: InputManagerTest_TouchpadSwipeSwitch_001
4162 * @tc.desc: SetTouchpadSwipeSwitch and GetTouchpadSwipeSwitch interface detection
4163 * @tc.type: FUNC
4164 * @tc.require:
4165 */
4166 HWTEST_F(InputManagerTest, InputManagerTest_TouchpadSwipeSwitch_001, TestSize.Level1)
4167 {
4168 CALL_TEST_DEBUG;
4169 bool switchFlag = true;
4170 int32_t result = InputManager::GetInstance()->SetTouchpadSwipeSwitch(switchFlag);
4171 ASSERT_EQ(result, RET_OK);
4172 result = InputManager::GetInstance()->GetTouchpadSwipeSwitch(switchFlag);
4173 ASSERT_EQ(switchFlag, true);
4174 ASSERT_EQ(result, RET_OK);
4175 }
4176
4177 /**
4178 * @tc.name: InputManagerTest_TouchpadRightClickType_001
4179 * @tc.desc: SetTouchpadRightClickType and GetTouchpadRightClickType interface detection
4180 * @tc.type: FUNC
4181 * @tc.require:
4182 */
4183 HWTEST_F(InputManagerTest, InputManagerTest_TouchpadRightClickType_001, TestSize.Level1)
4184 {
4185 CALL_TEST_DEBUG;
4186 int32_t type = 1;
4187 int32_t result = InputManager::GetInstance()->SetTouchpadRightClickType(type);
4188 ASSERT_EQ(result, RET_OK);
4189 result = InputManager::GetInstance()->GetTouchpadRightClickType(type);
4190 ASSERT_EQ(type, 1);
4191 ASSERT_EQ(result, RET_OK);
4192 }
4193
4194 /**
4195 * @tc.name: InputManagerTest_SetTouchpadTapSwitch_001
4196 * @tc.desc: Set touchpad tap switch
4197 * @tc.type: FUNC
4198 * @tc.require:
4199 */
4200 HWTEST_F(InputManagerTest, InputManagerTest_SetTouchpadTapSwitch_001, TestSize.Level1)
4201 {
4202 CALL_TEST_DEBUG;
4203 bool flag = false;
4204 InputManager::GetInstance()->Authorize(true);
4205 ASSERT_TRUE(InputManager::GetInstance()->SetTouchpadTapSwitch(flag) == RET_OK);
4206 }
4207
4208 /**
4209 * @tc.name: InputManagerTest_GetTouchpadTapSwitch_001
4210 * @tc.desc: Get touchpad tap switch
4211 * @tc.type: FUNC
4212 * @tc.require:
4213 */
4214 HWTEST_F(InputManagerTest, InputManagerTest_GetTouchpadTapSwitch_001, TestSize.Level1)
4215 {
4216 CALL_TEST_DEBUG;
4217 bool flag = true;
4218 InputManager::GetInstance()->SetTouchpadTapSwitch(flag);
4219 bool newFlag = true;
4220 InputManager::GetInstance()->Authorize(true);
4221 ASSERT_TRUE(InputManager::GetInstance()->GetTouchpadTapSwitch(newFlag) == RET_OK);
4222 ASSERT_TRUE(flag == newFlag);
4223 }
4224
4225 /**
4226 * @tc.name: InputManagerTest_SetTouchpadDoubleTapAndDragState_001
4227 * @tc.desc: Set Touchpad Double Tap And Drag State
4228 * @tc.type: FUNC
4229 * @tc.require:
4230 */
4231 HWTEST_F(InputManagerTest, InputManagerTest_SetTouchpadDoubleTapAndDragState_001, TestSize.Level1)
4232 {
4233 CALL_TEST_DEBUG;
4234 bool switchFlag = true;
4235 int32_t ret = InputManager::GetInstance()->SetTouchpadDoubleTapAndDragState(switchFlag);
4236 EXPECT_EQ(ret, RET_OK);
4237 }
4238
4239 /**
4240 * @tc.name: InputManagerTest_GetTouchpadDoubleTapAndDragState_001
4241 * @tc.desc: Get touchpad tap switch
4242 * @tc.type: FUNC
4243 * @tc.require:
4244 */
4245 HWTEST_F(InputManagerTest, InputManagerTest_GetTouchpadDoubleTapAndDragState_001, TestSize.Level1)
4246 {
4247 CALL_TEST_DEBUG;
4248 bool flag = true;
4249 InputManager::GetInstance()->SetTouchpadDoubleTapAndDragState(flag);
4250 bool newFlag = true;
4251 ASSERT_TRUE(InputManager::GetInstance()->GetTouchpadDoubleTapAndDragState(newFlag) == RET_OK);
4252 ASSERT_TRUE(flag == newFlag);
4253 }
4254
4255 /**
4256 * @tc.name: InputManagerTest_SetTouchpadRotateSwitch_001
4257 * @tc.desc: Set touchpad rotate switch
4258 * @tc.type: FUNC
4259 * @tc.require:
4260 */
4261 HWTEST_F(InputManagerTest, InputManagerTest_SetTouchpadRotateSwitch_001, TestSize.Level1)
4262 {
4263 CALL_TEST_DEBUG;
4264 bool rotateSwitch = false;
4265 ASSERT_TRUE(InputManager::GetInstance()->SetTouchpadRotateSwitch(rotateSwitch) == RET_OK);
4266 }
4267
4268 /**
4269 * @tc.name: InputManagerTest_GetTouchpadRotateSwitch_001
4270 * @tc.desc: Get touchpad rotate switch
4271 * @tc.type: FUNC
4272 * @tc.require:
4273 */
4274 HWTEST_F(InputManagerTest, InputManagerTest_GetTouchpadRotateSwitch_001, TestSize.Level1)
4275 {
4276 CALL_TEST_DEBUG;
4277 bool rotateSwitch = true;
4278 InputManager::GetInstance()->SetTouchpadRotateSwitch(rotateSwitch);
4279 bool newRotateSwitch = true;
4280 ASSERT_TRUE(InputManager::GetInstance()->GetTouchpadRotateSwitch(newRotateSwitch) == RET_OK);
4281 ASSERT_TRUE(rotateSwitch == newRotateSwitch);
4282 }
4283
4284 /**
4285 * @tc.name: InputManagerTest_SetCurrentUser_001
4286 * @tc.desc: set current user id
4287 * @tc.type: FUNC
4288 * @tc.require:
4289 */
4290 HWTEST_F(InputManagerTest, InputManagerTest_SetCurrentUser_001, TestSize.Level1)
4291 {
4292 int32_t userId = 10;
4293 int32_t ret = InputManager::GetInstance()->SetCurrentUser(userId);
4294 EXPECT_FALSE(ret == RET_OK);
4295 }
4296
4297 /**
4298 * @tc.name: InputManagerTest_HasIrEmitter
4299 * @tc.desc: Test HasIrEmitter
4300 * @tc.type: FUNC
4301 * @tc.require:
4302 */
4303 HWTEST_F(InputManagerTest, InputManagerTest_HasIrEmitter, TestSize.Level1)
4304 {
4305 bool hasIrEmitter = false;
4306 int32_t ret = InputManager::GetInstance()->HasIrEmitter(hasIrEmitter);
4307 EXPECT_EQ(ret, RET_OK);
4308 }
4309
4310 /**
4311 * @tc.name: InputManagerTest_GetInfraredFrequencies
4312 * @tc.desc: Test GetInfraredFrequencies
4313 * @tc.type: FUNC
4314 * @tc.require:
4315 */
4316 HWTEST_F(InputManagerTest, InputManagerTest_GetInfraredFrequencies, TestSize.Level1)
4317 {
4318 InfraredFrequency infraredFrequency;
4319 infraredFrequency.max_ = 30;
4320 infraredFrequency.min_ = 10;
4321 std::vector<InfraredFrequency> requencys;
4322 requencys.push_back(infraredFrequency);
4323 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->GetInfraredFrequencies(requencys));
4324 }
4325
4326 /**
4327 * @tc.name: InputManagerTest_TransmitInfrared
4328 * @tc.desc: Test TransmitInfrared
4329 * @tc.type: FUNC
4330 * @tc.require:
4331 */
4332 HWTEST_F(InputManagerTest, InputManagerTest_TransmitInfrared, TestSize.Level1)
4333 {
4334 int64_t number = 10;
4335 std::vector<int64_t> pattern = { 10, 20, 30 };
4336 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->TransmitInfrared(number, pattern));
4337 }
4338
4339 /**
4340 * @tc.name: InputManagerTest_EnableHardwareCursorStats_001
4341 * @tc.desc: Enable hardware cursor stats
4342 * @tc.type: FUNC
4343 * @tc.require:
4344 */
4345 HWTEST_F(InputManagerTest, InputManagerTest_EnableHardwareCursorStats_001, TestSize.Level1)
4346 {
4347 CALL_TEST_DEBUG;
4348 #ifdef OHOS_BUILD_ENABLE_POINTER
4349 auto ret = InputManager::GetInstance()->EnableHardwareCursorStats(false);
4350 ASSERT_EQ(ret, RET_OK);
4351 ret = InputManager::GetInstance()->EnableHardwareCursorStats(true);
4352 ASSERT_EQ(ret, RET_OK);
4353 #else
4354 auto ret = InputManager::GetInstance()->EnableHardwareCursorStats(false);
4355 ASSERT_EQ(ret, ERROR_UNSUPPORT);
4356 ret = InputManager::GetInstance()->EnableHardwareCursorStats(true);
4357 ASSERT_EQ(ret, ERROR_UNSUPPORT);
4358 #endif // OHOS_BUILD_ENABLE_POINTER
4359 }
4360
4361 /**
4362 * @tc.name: InputManagerTest_GetHardwareCursorStats_001
4363 * @tc.desc: get hardware cursor stats
4364 * @tc.type: FUNC
4365 * @tc.require:
4366 */
4367 HWTEST_F(InputManagerTest, InputManagerTest_GetHardwareCursorStats_001, TestSize.Level1)
4368 {
4369 CALL_TEST_DEBUG;
4370 uint32_t frameCount = 1;
4371 uint32_t vsyncCount = 1;
4372 #ifdef OHOS_BUILD_ENABLE_POINTER
4373 auto ret = InputManager::GetInstance()->EnableHardwareCursorStats(true);
4374 ASSERT_EQ(ret, RET_OK);
4375 ret = InputManager::GetInstance()->EnableHardwareCursorStats(false);
4376 ASSERT_EQ(ret, RET_OK);
4377 ret = InputManager::GetInstance()->GetHardwareCursorStats(frameCount, vsyncCount);
4378 ASSERT_EQ(ret, RET_OK);
4379 ASSERT_EQ(frameCount, 0);
4380 ASSERT_EQ(vsyncCount, 0);
4381 #else
4382 auto ret = InputManager::GetInstance()->GetHardwareCursorStats(frameCount, vsyncCount);
4383 ASSERT_EQ(ret, ERROR_UNSUPPORT);
4384 #endif // OHOS_BUILD_ENABLE_POINTER
4385 }
4386
4387 /**
4388 * @tc.name: InputManagerTest_AppendExtraData_001
4389 * @tc.desc: Append Extra Data
4390 * @tc.type: FUNC
4391 * @tc.require:
4392 */
4393 HWTEST_F(InputManagerTest, InputManagerTest_AppendExtraData_001, TestSize.Level1)
4394 {
4395 CALL_TEST_DEBUG;
4396 ExtraData data;
4397 data.buffer.resize(1025);
4398 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->AppendExtraData(data));
4399 data.buffer.resize(512);
4400 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->AppendExtraData(data));
4401 }
4402
4403 /**
4404 * @tc.name: InputManagerTest_TouchpadScrollRows_001
4405 * @tc.desc: SetTouchpadScrollRows and GetTouchpadScrollRows interface detection
4406 * @tc.type: FUNC
4407 * @tc.require:
4408 */
4409 HWTEST_F(InputManagerTest, InputManagerTest_TouchpadScrollRows_001, TestSize.Level1)
4410 {
4411 CALL_TEST_DEBUG;
4412 int32_t rows = 1;
4413 int32_t result = InputManager::GetInstance()->SetTouchpadScrollRows(rows);
4414 ASSERT_EQ(result, RET_OK);
4415 result = InputManager::GetInstance()->GetTouchpadScrollRows(rows);
4416 ASSERT_EQ(rows, 1);
4417 ASSERT_EQ(result, RET_OK);
4418 }
4419
4420 /**
4421 * @tc.name: InputManagerTest_TouchpadScrollRows_002
4422 * @tc.desc: SetTouchpadScrollRows and GetTouchpadScrollRows interface detection
4423 * @tc.type: FUNC
4424 * @tc.require:
4425 */
4426 HWTEST_F(InputManagerTest, InputManagerTest_TouchpadScrollRows_002, TestSize.Level1)
4427 {
4428 CALL_TEST_DEBUG;
4429 int32_t rows = -1;
4430 InputManager::GetInstance()->SetTouchpadScrollRows(rows);
4431 int32_t result = InputManager::GetInstance()->GetTouchpadScrollRows(rows);
4432 ASSERT_EQ(rows, 1);
4433 ASSERT_EQ(result, RET_OK);
4434 rows = 101;
4435 InputManager::GetInstance()->SetTouchpadScrollRows(rows);
4436 result = InputManager::GetInstance()->GetTouchpadScrollRows(rows);
4437 ASSERT_EQ(rows, 100);
4438 ASSERT_EQ(result, RET_OK);
4439 }
4440
4441 /**
4442 * @tc.name: InputManagerTest_GetPointerSnapshot
4443 * @tc.desc: Test GetPointerSnapshot
4444 * @tc.require:
4445 */
4446 HWTEST_F(InputManagerTest, InputManagerTest_GetPointerSnapshot, TestSize.Level1)
4447 {
4448 CALL_TEST_DEBUG;
4449 void *pixelMap = nullptr;
4450 EXPECT_NE(InputManager::GetInstance()->GetPointerSnapshot(pixelMap), RET_OK);
4451 }
4452
4453 /**
4454 * @tc.name: InputManagerTest_GetIntervalSinceLastInput001
4455 * @tc.desc: GetIntervalSinceLastInput interface detection
4456 * @tc.type: FUNC
4457 * @tc.require:
4458 */
4459 HWTEST_F(InputManagerTest, InputManagerTest_GetIntervalSinceLastInput001, TestSize.Level1)
4460 {
4461 CALL_TEST_DEBUG;
4462 int64_t timeInterval = -1;
4463 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->GetIntervalSinceLastInput(timeInterval));
4464 }
4465
4466 /**
4467 * @tc.name: InputManagerTest_GetIntervalSinceLastInput002
4468 * @tc.desc: GetIntervalSinceLastInput interface detection
4469 * @tc.type: FUNC
4470 * @tc.require:
4471 */
4472 HWTEST_F(InputManagerTest, InputManagerTest_GetIntervalSinceLastInput002, TestSize.Level1)
4473 {
4474 CALL_TEST_DEBUG;
4475 auto pointerEvent = PointerEvent::Create();
4476 ASSERT_NE(pointerEvent, nullptr);
4477 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD);
4478 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
4479 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
4480 int64_t timeInterval = 0;
4481 int32_t result =InputManager::GetInstance()->GetIntervalSinceLastInput(timeInterval);
4482 ASSERT_EQ(result, RET_OK);
4483 EXPECT_GE(timeInterval, (TIME_WAIT_FOR_OP * SLEEP_MILLISECONDS));
4484 }
4485
4486 /**
4487 * @tc.name: InputManagerTest_GetIntervalSinceLastInput003
4488 * @tc.desc: GetIntervalSinceLastInput interface detection
4489 * @tc.type: FUNC
4490 * @tc.require:
4491 */
4492 HWTEST_F(InputManagerTest, InputManagerTest_GetIntervalSinceLastInput003, TestSize.Level1)
4493 {
4494 CALL_TEST_DEBUG;
4495 auto pointerEvent = PointerEvent::Create();
4496 ASSERT_NE(pointerEvent, nullptr);
4497 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD);
4498 InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
4499 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
4500 auto keyEvent = KeyEvent::Create();
4501 ASSERT_NE(keyEvent, nullptr);
4502 KeyEvent::KeyItem itemSecond;
4503 itemSecond.SetKeyCode(KeyEvent::KEYCODE_R);
4504 itemSecond.SetPressed(true);
4505 itemSecond.SetDownTime(500);
4506 keyEvent->AddKeyItem(itemSecond);
4507 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
4508 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
4509 int64_t timeInterval = 0;
4510 int32_t result =InputManager::GetInstance()->GetIntervalSinceLastInput(timeInterval);
4511 ASSERT_EQ(result, RET_OK);
4512 EXPECT_GE(timeInterval, (TIME_WAIT_FOR_OP * SLEEP_MILLISECONDS));
4513 }
4514
4515 /**
4516 * @tc.name: InputManagerTest_GetAllSystemHotkey
4517 * @tc.desc: Obtains all hot keys supported by the system.
4518 * @tc.type: FUNC
4519 * @tc.require:
4520 */
4521 HWTEST_F(InputManagerTest, InputManagerTest_GetAllSystemHotkey_001, TestSize.Level1)
4522 {
4523 CALL_TEST_DEBUG;
4524 int32_t count = 0;
4525 std::vector<std::unique_ptr<KeyOption>> keyOptions;
4526 int32_t ret = InputManager::GetInstance()->GetAllSystemHotkeys(keyOptions, count);
4527 ASSERT_EQ(ret, RET_OK);
4528 }
4529
4530 /**
4531 * @tc.name: InputManagerTest_SkipPointerLayer_001
4532 * @tc.desc: Test SkipPointerLayer
4533 * @tc.require:
4534 */
4535 HWTEST_F(InputManagerTest, InputManagerTest_SkipPointerLayer_001, TestSize.Level1)
4536 {
4537 CALL_TEST_DEBUG;
4538 bool isSkip = true;
4539 int32_t ret = InputManager::GetInstance()->SkipPointerLayer(isSkip);
4540 EXPECT_EQ(ret, 305);
4541 isSkip = false;
4542 ret = InputManager::GetInstance()->SkipPointerLayer(isSkip);
4543 EXPECT_EQ(ret, 305);
4544 }
4545
4546 /**
4547 * @tc.name: InputManagerTest_ConvertToCapiKeyAction_001
4548 * @tc.desc: Test the funcation ConvertToCapiKeyAction
4549 * @tc.require:
4550 */
4551 HWTEST_F(InputManagerTest, InputManagerTest_ConvertToCapiKeyAction_001, TestSize.Level1)
4552 {
4553 CALL_TEST_DEBUG;
4554 int32_t keyAction = 0X00000002;
4555 int32_t ret = InputManager::GetInstance()->ConvertToCapiKeyAction(keyAction);
4556 EXPECT_NE(ret, -1);
4557 }
4558
4559 /**
4560 * @tc.name: InputManagerTest_GestureMonitor_001
4561 * @tc.desc: Gesture Monitor
4562 * @tc.type: FUNC
4563 * @tc.require:
4564 */
4565 HWTEST_F(InputManagerTest, InputManagerTest_GestureMonitor_001, TestSize.Level1)
4566 {
4567 CALL_TEST_DEBUG;
4568 auto consumer = GetPtr<InputEventConsumer>();
4569 ASSERT_TRUE(consumer != nullptr);
4570 int32_t monitorId = InputManager::GetInstance()->AddGestureMonitor(consumer, TOUCH_GESTURE_TYPE_ALL, 1);
4571 #ifdef OHOS_BUILD_ENABLE_MONITOR
4572 ASSERT_TRUE(monitorId == INVALID_HANDLER_ID);
4573 #else
4574 ASSERT_TRUE(monitorId == ERROR_UNSUPPORT);
4575 #endif // OHOS_BUILD_ENABLE_MONITOR
4576 }
4577
4578 /**
4579 * @tc.name: InputManagerTest_GestureMonitor_002
4580 * @tc.desc: Gesture Monitor
4581 * @tc.type: FUNC
4582 * @tc.require:
4583 */
4584 HWTEST_F(InputManagerTest, InputManagerTest_GestureMonitor_002, TestSize.Level1)
4585 {
4586 CALL_TEST_DEBUG;
4587 auto consumer = GetPtr<InputEventConsumer>();
4588 ASSERT_TRUE(consumer != nullptr);
4589 int32_t monitorId = InputManager::GetInstance()->AddGestureMonitor(consumer, TOUCH_GESTURE_TYPE_PINCH, 3);
4590 #ifdef OHOS_BUILD_ENABLE_MONITOR
4591 ASSERT_TRUE(monitorId == INVALID_HANDLER_ID);
4592 #else
4593 ASSERT_TRUE(monitorId == ERROR_UNSUPPORT);
4594 #endif // OHOS_BUILD_ENABLE_MONITOR
4595 }
4596
4597 /**
4598 * @tc.name: InputManagerTest_GestureMonitor_003
4599 * @tc.desc: Gesture Monitor
4600 * @tc.type: FUNC
4601 * @tc.require:
4602 */
4603 HWTEST_F(InputManagerTest, InputManagerTest_GestureMonitor_003, TestSize.Level1)
4604 {
4605 CALL_TEST_DEBUG;
4606 auto consumer = GetPtr<InputEventConsumer>();
4607 ASSERT_TRUE(consumer != nullptr);
4608 int32_t monitorId = InputManager::GetInstance()->AddGestureMonitor(consumer, TOUCH_GESTURE_TYPE_ALL, 0);
4609 #ifdef OHOS_BUILD_ENABLE_MONITOR
4610 ASSERT_TRUE(monitorId != INVALID_HANDLER_ID);
4611 #else
4612 ASSERT_TRUE(monitorId == ERROR_UNSUPPORT);
4613 #endif // OHOS_BUILD_ENABLE_MONITOR
4614
4615 int32_t ret = InputManager::GetInstance()->RemoveGestureMonitor(monitorId);
4616 #ifdef OHOS_BUILD_ENABLE_MONITOR
4617 ASSERT_TRUE(ret == RET_OK);
4618 #else
4619 ASSERT_TRUE(ret == ERROR_UNSUPPORT);
4620 #endif // OHOS_BUILD_ENABLE_MONITOR
4621 }
4622
4623 /**
4624 @tc.name: InputManagerTest_SubscribeHotkey_001
4625 @tc.desc: Test the funcation SubscribeHotkey
4626 @tc.type: FUNC
4627 @tc.require:
4628 */
4629 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeHotkey_001, TestSize.Level1)
4630 {
4631 CALL_TEST_DEBUG;
4632 std::set<int32_t> preKeys;
4633 std::shared_ptr keyOption =
4634 InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_POWER, true, 0);
4635 int32_t response = INVAID_VALUE;
4636 response = InputManager::GetInstance()->SubscribeHotkey(keyOption, nullptr);
4637 EXPECT_TRUE(response < 0);
4638 }
4639
4640 /**
4641 @tc.name: InputManagerTest_UnsubscribeHotkey_001
4642 @tc.desc: Test the funcation UnsubscribeHotkey
4643 @tc.type: FUNC
4644 @tc.require:
4645 */
4646 HWTEST_F(InputManagerTest, InputManagerTest_UnsubscribeHotkey_001, TestSize.Level1)
4647 {
4648 CALL_TEST_DEBUG;
4649 int32_t subscriberId = 1;
4650 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->UnsubscribeHotkey(subscriberId));
4651 }
4652
InjectAltL(size_t nTriggers)4653 void InputManagerTest::InjectAltL(size_t nTriggers)
4654 {
4655 auto keyEvent = KeyEvent::Create();
4656 ASSERT_NE(keyEvent, nullptr);
4657 keyEvent->SetKeyCode(KeyEvent::KEYCODE_L);
4658
4659 KeyEvent::KeyItem keyItem {};
4660 keyItem.SetKeyCode(KeyEvent::KEYCODE_ALT_LEFT);
4661 keyItem.SetPressed(true);
4662 keyItem.SetDownTime(GetSysClockTime() - MS2US(DEFAULT_SAMPLING_PERIOD));
4663 keyEvent->AddKeyItem(keyItem);
4664 keyItem.SetKeyCode(KeyEvent::KEYCODE_L);
4665
4666 while (nTriggers-- > 0) {
4667 auto now = GetSysClockTime();
4668 keyItem.SetPressed(true);
4669 keyItem.SetDownTime(now);
4670 keyEvent->AddKeyItem(keyItem);
4671 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
4672 keyEvent->SetActionTime(now);
4673 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
4674 std::this_thread::sleep_for(std::chrono::milliseconds(DEFAULT_SAMPLING_PERIOD));
4675
4676 keyItem.SetPressed(false);
4677 keyEvent->RemoveReleasedKeyItems(keyItem);
4678
4679 now = GetSysClockTime();
4680 keyEvent->AddKeyItem(keyItem);
4681 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
4682 keyEvent->SetActionTime(now);
4683 InputManager::GetInstance()->SimulateInputEvent(keyEvent);
4684 keyEvent->RemoveReleasedKeyItems(keyItem);
4685 std::this_thread::sleep_for(std::chrono::milliseconds(DEFAULT_SAMPLING_PERIOD));
4686 }
4687 }
4688
4689 /**
4690 * @tc.name: InputManagerTest_SubscribeHotkey_002
4691 * @tc.desc: Verify subscription and unsubscription of hot key.
4692 * @tc.type: FUNC
4693 * @tc.require:
4694 * @tc.author:
4695 */
4696 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeHotkey_002, TestSize.Level1)
4697 {
4698 CALL_TEST_DEBUG;
4699 size_t nCalls { 0 };
4700 std::set<int32_t> preKeys { KeyEvent::KEYCODE_ALT_LEFT };
4701 std::shared_ptr<KeyOption> keyOption = InputManagerUtil::InitOption(preKeys, KeyEvent::KEYCODE_L, true, 0);
4702 auto subscribeId = InputManager::GetInstance()->SubscribeHotkey(keyOption,
__anonce2bd3134802(std::shared_ptr<KeyEvent> keyEvent) 4703 [&nCalls](std::shared_ptr<KeyEvent> keyEvent) {
4704 if ((keyEvent->GetKeyCode() == KeyEvent::KEYCODE_L) &&
4705 (keyEvent->GetKeyAction() == KeyEvent::KEY_ACTION_DOWN)) {
4706 auto pressedKeys = keyEvent->GetPressedKeys();
4707 if (std::any_of(pressedKeys.cbegin(), pressedKeys.cend(),
4708 [](const auto keyCode) {
4709 return (keyCode == KeyEvent::KEYCODE_ALT_LEFT);
4710 })) {
4711 ++nCalls;
4712 }
4713 }
4714 });
4715 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
4716 ASSERT_TRUE(subscribeId >= 0);
4717 size_t nTriggers { 30 };
4718 InjectAltL(nTriggers);
4719 InputManager::GetInstance()->UnsubscribeHotkey(subscribeId);
4720 EXPECT_EQ(nTriggers, nCalls);
4721 InjectAltL(nTriggers);
4722 EXPECT_EQ(nTriggers, nCalls);
4723 #else
4724 ASSERT_TRUE(subscribeId < 0);
4725 #endif // OHOS_BUILD_ENABLE_KEYBOARD
4726 }
4727
4728 /*
4729 * @tc.name: InputManagerTest_SetTouchpadScrollRows_001
4730 * @tc.desc: Test the funcation SetTouchpadScrollRows
4731 * @tc.type: FUNC
4732 * @tc.require:
4733 */
4734 HWTEST_F(InputManagerTest, InputManagerTest_SetTouchpadScrollRows_001, TestSize.Level1)
4735 {
4736 CALL_TEST_DEBUG;
4737 int32_t rows = 1;
4738 int32_t ret = InputManager::GetInstance()->SetTouchpadScrollRows(rows);
4739 ASSERT_EQ(ret, RET_OK);
4740 }
4741
4742 /*
4743 * @tc.name: InputManagerTest_GetTouchpadScrollRows_001
4744 * @tc.desc: Test the funcation GetTouchpadScrollRows
4745 * @tc.type: FUNC
4746 * @tc.require:
4747 */
4748 HWTEST_F(InputManagerTest, InputManagerTest_GetTouchpadScrollRows_001, TestSize.Level1)
4749 {
4750 CALL_TEST_DEBUG;
4751 int32_t rows = 2;
4752 int32_t ret = InputManager::GetInstance()->GetTouchpadScrollRows(rows);
4753 ASSERT_EQ(ret, RET_OK);
4754 }
4755
4756 /**
4757 * @tc.name: InputManagerTest_SetInputDeviceEnable_001
4758 * @tc.desc: Set input device enable
4759 * @tc.type: FUNC
4760 * @tc.require:
4761 */
4762 HWTEST_F(InputManagerTest, InputManagerTest_SetInputDeviceEnable_001, TestSize.Level1)
4763 {
4764 CALL_TEST_DEBUG;
4765 std::vector<int32_t> aucids;
__anonce2bd3134a02(std::vector<int32_t> ids) 4766 auto callback = [&aucids](std::vector<int32_t> ids) { aucids = std::move(ids); };
4767 InputManager::GetInstance()->GetDeviceIds(callback);
4768 for (const auto &iter : aucids) {
4769 MMI_HILOGI("Set inputdevice %{public}d disable", iter);
__anonce2bd3134b02(int32_t result) 4770 auto cb = [](int32_t result) {
4771 MMI_HILOGI("Set input device result:%{public}d ", result);
4772 ASSERT_EQ(result, RET_OK);
4773 };
4774 InputManager::GetInstance()->SetInputDeviceEnabled(iter, false, cb);
4775 }
4776 }
4777
4778 /**
4779 * @tc.name: InputManagerTest_SetInputDeviceEnable_002
4780 * @tc.desc: Set input device enable
4781 * @tc.type: FUNC
4782 * @tc.require:
4783 */
4784 HWTEST_F(InputManagerTest, InputManagerTest_SetInputDeviceEnable_002, TestSize.Level1)
4785 {
4786 CALL_TEST_DEBUG;
4787 std::vector<int32_t> aucids;
__anonce2bd3134c02(std::vector<int32_t> ids) 4788 auto callback = [&aucids](std::vector<int32_t> ids) { aucids = std::move(ids); };
4789 InputManager::GetInstance()->GetDeviceIds(callback);
4790 for (const auto &iter : aucids) {
4791 MMI_HILOGI("Set inputdevice %{public}d enable", iter);
__anonce2bd3134d02(int32_t result) 4792 auto cb = [](int32_t result) {
4793 MMI_HILOGI("Set input device result:%{public}d ", result);
4794 ASSERT_EQ(result, RET_OK);
4795 };
4796 InputManager::GetInstance()->SetInputDeviceEnabled(iter, true, cb);
4797 }
4798 }
4799
4800 /**
4801 * @tc.name: InputManagerTest_SetInputDeviceEnable_003
4802 * @tc.desc: Set input device enable
4803 * @tc.type: FUNC
4804 * @tc.require:
4805 */
4806 HWTEST_F(InputManagerTest, InputManagerTest_SetInputDeviceEnable_003, TestSize.Level1)
4807 {
4808 CALL_TEST_DEBUG;
__anonce2bd3134e02(int32_t result) 4809 auto cb = [](int32_t result) {
4810 MMI_HILOGI("Set input device result:%{public}d ", result);
4811 ASSERT_EQ(result, ERROR_DEVICE_NOT_EXIST);
4812 };
4813 InputManager::GetInstance()->SetInputDeviceEnabled(10000, true, cb);
4814 }
4815
4816 /*
4817 * @tc.name: InputManagerTest_ShiftAppPointerEvent_001
4818 * @tc.desc: Test the funcation ShiftAppPointerEvent
4819 * @tc.type: FUNC
4820 * @tc.require:
4821 */
4822 HWTEST_F(InputManagerTest, InputManagerTest_ShiftAppPointerEvent_001, TestSize.Level1)
4823 {
4824 CALL_TEST_DEBUG;
4825 int32_t sourceWindowId = 99;
4826 int32_t targetWindowId = 99;
4827 ShiftWindowParam param {
4828 .sourceWindowId = sourceWindowId,
4829 .targetWindowId = targetWindowId,
4830 };
4831 bool autoGenDown = true;
4832 int32_t ret = InputManager::GetInstance()->ShiftAppPointerEvent(param, autoGenDown);
4833 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
4834 ASSERT_EQ(ret, ARGV_VALID);
4835 #else
4836 ASSERT_EQ(ret, ERROR_UNSUPPORT);
4837 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
4838 }
4839
4840 /*
4841 * @tc.name: InputManagerTest_ShiftAppPointerEvent_002
4842 * @tc.desc: Test the funcation ShiftAppPointerEvent
4843 * @tc.type: FUNC
4844 * @tc.require:
4845 */
4846 HWTEST_F(InputManagerTest, InputManagerTest_ShiftAppPointerEvent_002, TestSize.Level1)
4847 {
4848 CALL_TEST_DEBUG;
4849 int32_t sourceWindowId = -150;
4850 int32_t targetWindowId = -99;
4851 ShiftWindowParam param {
4852 .sourceWindowId = sourceWindowId,
4853 .targetWindowId = targetWindowId,
4854 };
4855 bool autoGenDown = true;
4856 int32_t ret = InputManager::GetInstance()->ShiftAppPointerEvent(param, autoGenDown);
4857 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
4858 ASSERT_EQ(ret, RET_ERR);
4859 #else
4860 ASSERT_EQ(ret, ERROR_UNSUPPORT);
4861 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
4862 }
4863
4864 /**
4865 * @tc.name: InputManagerTest_SetCustomCursorEx_001
4866 * @tc.desc: Test SetCustomCursorEx_001
4867 * @tc.type: FUNC
4868 * @tc.require:
4869 */
4870 HWTEST_F(InputManagerTest, InputManagerTest_SetCustomCursorEx_001, TestSize.Level1)
4871 {
4872 CALL_TEST_DEBUG;
4873 int32_t fakeWindowId = 100;
4874 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/North_South.svg";
4875 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerUtil::SetMouseIconTest(iconPath);
4876 ASSERT_NE(pixelMap, nullptr);
4877 CustomCursor cursor;
4878 cursor.pixelMap = (void *)pixelMap.get();
4879 cursor.focusX = 32;
4880 cursor.focusY = 32;
4881 CursorOptions options;
4882 options.followSystem = true;
4883 ASSERT_TRUE(InputManager::GetInstance()->SetCustomCursor(fakeWindowId, cursor, options) != RET_ERR);
4884 pixelMap = nullptr;
4885 }
4886
4887 /**
4888 * @tc.name: InputManagerTest_SetCustomCursorEx_002
4889 * @tc.desc: Test SetCustomCursorEx_002
4890 * @tc.type: FUNC
4891 * @tc.require:
4892 */
4893 HWTEST_F(InputManagerTest, InputManagerTest_SetCustomCursorEx_002, TestSize.Level1)
4894 {
4895 CALL_TEST_DEBUG;
4896 int32_t fakeWindowId = 100;
4897 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/North_South.svg";
4898 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerUtil::SetMouseIconTest(iconPath);
4899 ASSERT_NE(pixelMap, nullptr);
4900 CustomCursor cursor;
4901 cursor.pixelMap = (void *)pixelMap.get();
4902 cursor.focusX = 32;
4903 cursor.focusY = 32;
4904 CursorOptions options;
4905 options.followSystem = false;
4906 ASSERT_TRUE(InputManager::GetInstance()->SetCustomCursor(fakeWindowId, cursor, options) != RET_ERR);
4907 pixelMap = nullptr;
4908 }
4909
4910 /**
4911 * @tc.name: InputManagerTest_SetCustomCursorEx_003
4912 * @tc.desc: Test SetCustomCursorEx_003
4913 * @tc.type: FUNC
4914 * @tc.require:
4915 */
4916 HWTEST_F(InputManagerTest, InputManagerTest_SetCustomCursorEx_003, TestSize.Level1)
4917 {
4918 CALL_TEST_DEBUG;
4919 int32_t fakeWindowId = 100;
4920 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/North_South.svg";
4921 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerUtil::SetMouseIconTest(iconPath);
4922 ASSERT_NE(pixelMap, nullptr);
4923 CustomCursor cursor;
4924 cursor.pixelMap = (void *)pixelMap.get();
4925 cursor.focusX = 512;
4926 cursor.focusY = 512;
4927 CursorOptions options;
4928 options.followSystem = false;
4929 ASSERT_TRUE(InputManager::GetInstance()->SetCustomCursor(fakeWindowId, cursor, options) != RET_ERR);
4930 pixelMap = nullptr;
4931 }
4932
4933 /**
4934 * @tc.name: InputManagerTest_SetCustomCursorEx_004
4935 * @tc.desc: Test SetCustomCursorEx_004
4936 * @tc.type: FUNC
4937 * @tc.require:
4938 */
4939 HWTEST_F(InputManagerTest, InputManagerTest_SetCustomCursorEx_004, TestSize.Level1)
4940 {
4941 CALL_TEST_DEBUG;
4942 int32_t fakeWindowId = 100;
4943 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/North_South.svg";
4944 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = InputManagerUtil::SetMouseIconTest(iconPath);
4945 ASSERT_NE(pixelMap, nullptr);
4946 Media::ImageInfo imageInfo;
4947 imageInfo.size.width = 280;
4948 imageInfo.size.height = 280;
4949 pixelMap->SetImageInfo(imageInfo);
4950 CustomCursor cursor;
4951 cursor.pixelMap = (void *)pixelMap.get();
4952 cursor.focusX = 32;
4953 cursor.focusY = 32;
4954 CursorOptions options;
4955 options.followSystem = false;
4956 ASSERT_TRUE(InputManager::GetInstance()->SetCustomCursor(fakeWindowId, cursor, options) != RET_ERR);
4957 pixelMap = nullptr;
4958 }
4959
CreatePointerEventTest()4960 std::shared_ptr<PointerEvent> CreatePointerEventTest()
4961 {
4962 auto pointerEvent = PointerEvent::Create();
4963 CHKPP(pointerEvent);
4964 pointerEvent->SetPointerId(1);
4965 PointerEvent::PointerItem item;
4966 item.SetDisplayY(POINTER_ITEM_DISPLAY_Y_TWO);
4967 item.SetPressed(true);
4968 item.SetDisplayX(POINTER_ITEM_DISPLAY_X_ONE);
4969 item.SetWindowX(POINTER_ITEM_WINDOW_X);
4970 item.SetPointerId(1);
4971 item.SetWindowY(POINTER_ITEM_WINDOW_Y);
4972 item.SetDeviceId(0);
4973 item.SetWidth(ITEM_WIDTH);
4974 item.SetHeight(ITEM_HEIGHT);
4975 item.SetPressure(POINTER_ITEM_PRESSURE);
4976 pointerEvent->AddPointerItem(item);
4977 return pointerEvent;
4978 }
4979
4980 /*
4981 * @tc.name: InputManagerTest_TransformMouseEventToTouchEvent_001
4982 * @tc.desc: Test the funcation PointerEventMouseToTouch, convert mouse events to touch events
4983 * @tc.type: FUNC
4984 * @tc.require:
4985 */
4986 HWTEST_F(InputManagerTest, InputManagerTest_TransformMouseEventToTouchEvent_001, TestSize.Level1)
4987 {
4988 CALL_TEST_DEBUG;
4989 auto pointerEvent = CreatePointerEventTest();
4990 bool ret = false;
4991 int32_t pointerId = pointerEvent->GetPointerId();
4992 PointerEvent::PointerItem pointerItem;
4993 ret = pointerEvent->GetPointerItem(pointerId, pointerItem);
4994 ASSERT_EQ(ret, true);
4995 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
4996 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN);
4997 ret = MMI::InputManager::GetInstance()->TransformMouseEventToTouchEvent(pointerEvent);
4998 ASSERT_EQ(ret, true);
4999 }
5000
5001 /*
5002 * @tc.name: InputManagerTest_TransformMouseEventToTouchEvent_002
5003 * @tc.desc: Test the funcation PointerEventMouseToTouch, convert mouse events to touch events
5004 * @tc.type: FUNC
5005 * @tc.require:
5006 */
5007 HWTEST_F(InputManagerTest, InputManagerTest_TransformMouseEventToTouchEvent_002, TestSize.Level1)
5008 {
5009 CALL_TEST_DEBUG;
5010 auto pointerEvent = CreatePointerEventTest();
5011 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
5012 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN);
5013 bool ret = false;
5014 int32_t pointerId = pointerEvent->GetPointerId();
5015 PointerEvent::PointerItem pointerItem;
5016 ret = pointerEvent->GetPointerItem(pointerId, pointerItem);
5017 ASSERT_EQ(ret, true);
5018 pointerItem.SetToolType(PointerEvent::TOOL_TYPE_FINGER);
5019 ret = MMI::InputManager::GetInstance()->TransformMouseEventToTouchEvent(pointerEvent);
5020 ASSERT_EQ(ret, true);
5021 }
5022
5023 /*
5024 * @tc.name: InputManagerTest_TransformMouseEventToTouchEvent_003
5025 * @tc.desc: Test the funcation PointerEventMouseToTouch, convert mouse events to touch events
5026 * @tc.type: FUNC
5027 * @tc.require:
5028 */
5029 HWTEST_F(InputManagerTest, InputManagerTest_TransformMouseEventToTouchEvent_003, TestSize.Level1)
5030 {
5031 CALL_TEST_DEBUG;
5032 auto pointerEvent = CreatePointerEventTest();
5033 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
5034 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN);
5035 bool ret = false;
5036 int32_t pointerId = pointerEvent->GetPointerId();
5037 PointerEvent::PointerItem pointerItem;
5038 ret = pointerEvent->GetPointerItem(pointerId, pointerItem);
5039 ASSERT_EQ(ret, true);
5040 pointerItem.SetToolType(PointerEvent::TOOL_TYPE_FINGER);
5041 ret = MMI::InputManager::GetInstance()->TransformMouseEventToTouchEvent(pointerEvent);
5042 ASSERT_EQ(ret, true);
5043 }
5044
5045 /*
5046 * @tc.name: InputManagerTest_TransformMouseEventToTouchEvent_004
5047 * @tc.desc: Test the funcation PointerEventMouseToTouch, convert mouse events to touch events
5048 * @tc.type: FUNC
5049 * @tc.require:
5050 */
5051 HWTEST_F(InputManagerTest, InputManagerTest_TransformMouseEventToTouchEvent_004, TestSize.Level1)
5052 {
5053 CALL_TEST_DEBUG;
5054 auto pointerEvent = PointerEvent::Create();
5055 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
5056 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN);
5057 pointerEvent->SetPointerId(1);
5058 bool ret = false;
5059 int32_t pointerId = pointerEvent->GetPointerId();
5060 PointerEvent::PointerItem pointerItem;
5061 ret = pointerEvent->GetPointerItem(pointerId, pointerItem);
5062 ASSERT_EQ(ret, false);
5063 }
5064
5065 /*
5066 * @tc.name: InputManagerTest_TransformTouchEventToMouseEvent_001
5067 * @tc.desc: Test the funcation PointerEventTouchToMouse, convert touch events to mouse events
5068 * @tc.type: FUNC
5069 * @tc.require:
5070 */
5071 HWTEST_F(InputManagerTest, InputManagerTest_TransformTouchEventToMouseEvent_001, TestSize.Level1)
5072 {
5073 CALL_TEST_DEBUG;
5074 auto pointerEvent = CreatePointerEventTest();
5075 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
5076 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
5077 bool ret = false;
5078 int32_t pointerId = pointerEvent->GetPointerId();
5079 PointerEvent::PointerItem pointerItem;
5080 ret = pointerEvent->GetPointerItem(pointerId, pointerItem);
5081 ASSERT_EQ(ret, true);
5082 ret = MMI::InputManager::GetInstance()->TransformTouchEventToMouseEvent(pointerEvent);
5083 ASSERT_EQ(ret, true);
5084 }
5085
5086 /*
5087 * @tc.name: InputManagerTest_TransformTouchEventToMouseEvent_002
5088 * @tc.desc: Test the funcation PointerEventTouchToMouse, convert touch events to mouse events
5089 * @tc.type: FUNC
5090 * @tc.require:
5091 */
5092 HWTEST_F(InputManagerTest, InputManagerTest_TransformTouchEventToMouseEvent_002, TestSize.Level1)
5093 {
5094 CALL_TEST_DEBUG;
5095 auto pointerEvent = CreatePointerEventTest();
5096 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
5097 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
5098 bool ret = false;
5099 int32_t pointerId = pointerEvent->GetPointerId();
5100 PointerEvent::PointerItem pointerItem;
5101 ret = pointerEvent->GetPointerItem(pointerId, pointerItem);
5102 ASSERT_EQ(ret, true);
5103 pointerItem.SetToolType(PointerEvent::TOOL_TYPE_MOUSE);
5104 ret = MMI::InputManager::GetInstance()->TransformTouchEventToMouseEvent(pointerEvent);
5105 ASSERT_EQ(ret, true);
5106 }
5107
5108 /*
5109 * @tc.name: InputManagerTest_TransformTouchEventToMouseEvent_003
5110 * @tc.desc: Test the funcation PointerEventTouchToMouse, convert touch events to mouse events
5111 * @tc.type: FUNC
5112 * @tc.require:
5113 */
5114 HWTEST_F(InputManagerTest, InputManagerTest_TransformTouchEventToMouseEvent_003, TestSize.Level1)
5115 {
5116 CALL_TEST_DEBUG;
5117 auto pointerEvent = CreatePointerEventTest();
5118 bool ret = false;
5119 int32_t pointerId = pointerEvent->GetPointerId();
5120 PointerEvent::PointerItem pointerItem;
5121 ret = pointerEvent->GetPointerItem(pointerId, pointerItem);
5122 ASSERT_EQ(ret, true);
5123 pointerItem.SetToolType(PointerEvent::TOOL_TYPE_FINGER);
5124 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
5125 ret = MMI::InputManager::GetInstance()->TransformTouchEventToMouseEvent(pointerEvent);
5126 ASSERT_EQ(ret, true);
5127 }
5128
5129 /*
5130 * @tc.name: InputManagerTest_TransformTouchEventToMouseEvent_004
5131 * @tc.desc: Test the funcation PointerEventTouchToMouse, convert touch events to mouse events
5132 * @tc.type: FUNC
5133 * @tc.require:
5134 */
5135 HWTEST_F(InputManagerTest, InputManagerTest_TransformTouchEventToMouseEvent_004, TestSize.Level1)
5136 {
5137 CALL_TEST_DEBUG;
5138 auto pointerEvent = PointerEvent::Create();
5139 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
5140 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
5141 pointerEvent->SetPointerId(1);
5142 bool ret = false;
5143 int32_t pointerId = pointerEvent->GetPointerId();
5144 PointerEvent::PointerItem pointerItem;
5145 ret = pointerEvent->GetPointerItem(pointerId, pointerItem);
5146 ASSERT_EQ(ret, false);
5147 }
5148
5149 /*
5150 * @tc.name: InputManagerTest_SubscribeKeyEvent_016
5151 * @tc.desc: Verify subscribe KEYCODE_HOME key up event.
5152 * @tc.type: FUNC
5153 * @tc.require:
5154 */
5155 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_016, TestSize.Level1)
5156 {
5157 CALL_TEST_DEBUG;
5158 std::set<int32_t> preKeys;
5159 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
5160 keyOption->SetPreKeys(preKeys);
5161 keyOption->SetFinalKey(KeyEvent::KEYCODE_HOME);
5162 keyOption->SetFinalKeyDown(false);
5163 keyOption->SetFinalKeyDownDuration(0);
5164 int32_t subscribeId = INVAID_VALUE;
__anonce2bd3134f02(std::shared_ptr<KeyEvent> keyEvent) 5165 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
5166 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
5167 MMI_HILOGD("Subscribe key event KEYCODE_HOME up trigger callback");
5168 });
5169 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
5170 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
5171 EXPECT_TRUE(subscribeId >= 0);
5172 #else
5173 EXPECT_TRUE(subscribeId < 0);
5174 #endif // OHOS_BUILD_ENABLE_KEYBOARD
5175 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
5176 ASSERT_TRUE(injectDownEvent != nullptr);
5177 KeyEvent::KeyItem kitDown;
5178 kitDown.SetKeyCode(KeyEvent::KEYCODE_HOME);
5179 kitDown.SetPressed(false);
5180 kitDown.SetDownTime(0);
5181 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_HOME);
5182 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
5183 injectDownEvent->AddPressedKeyItems(kitDown);
5184 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
5185 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_UP);
5186
5187 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
5188 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId);
5189 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
5190 }
5191
5192 /*
5193 * @tc.name: InputManagerTest_SubscribeKeyEvent_017
5194 * @tc.desc: Verify subscribe KEYCODE_HOME key down event.
5195 * @tc.type: FUNC
5196 * @tc.require:
5197 */
5198 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_017, TestSize.Level1)
5199 {
5200 CALL_TEST_DEBUG;
5201 std::set<int32_t> preKeys;
5202 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
5203 keyOption->SetPreKeys(preKeys);
5204 keyOption->SetFinalKey(KeyEvent::KEYCODE_HOME);
5205 keyOption->SetFinalKeyDown(true);
5206 keyOption->SetFinalKeyDownDuration(0);
5207 int32_t subscribeId = INVAID_VALUE;
__anonce2bd3135002(std::shared_ptr<KeyEvent> keyEvent) 5208 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
5209 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
5210 MMI_HILOGD("Subscribe key event KEYCODE_HOME down trigger callback");
5211 });
5212 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
5213 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
5214 EXPECT_TRUE(subscribeId >= 0);
5215 #else
5216 EXPECT_TRUE(subscribeId < 0);
5217 #endif // OHOS_BUILD_ENABLE_KEYBOARD
5218 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
5219 ASSERT_TRUE(injectDownEvent != nullptr);
5220 KeyEvent::KeyItem kitDown;
5221 kitDown.SetKeyCode(KeyEvent::KEYCODE_HOME);
5222 kitDown.SetPressed(true);
5223 kitDown.SetDownTime(0);
5224 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_HOME);
5225 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
5226 injectDownEvent->AddPressedKeyItems(kitDown);
5227 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
5228 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN);
5229
5230 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
5231 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId);
5232 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
5233 }
5234
5235 /*
5236 * @tc.name: InputManagerTest_SubscribeKeyEvent_018
5237 * @tc.desc: Verify subscribe KEYCODE_MENU key up event.
5238 * @tc.type: FUNC
5239 * @tc.require:
5240 */
5241 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_018, TestSize.Level1)
5242 {
5243 CALL_TEST_DEBUG;
5244 std::set<int32_t> preKeys;
5245 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
5246 keyOption->SetPreKeys(preKeys);
5247 keyOption->SetFinalKey(KeyEvent::KEYCODE_MENU);
5248 keyOption->SetFinalKeyDown(false);
5249 keyOption->SetFinalKeyDownDuration(0);
5250 int32_t subscribeId = INVAID_VALUE;
__anonce2bd3135102(std::shared_ptr<KeyEvent> keyEvent) 5251 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
5252 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
5253 MMI_HILOGD("Subscribe key event KEYCODE_MENU up trigger callback");
5254 });
5255 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
5256 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
5257 EXPECT_TRUE(subscribeId >= 0);
5258 #else
5259 EXPECT_TRUE(subscribeId < 0);
5260 #endif // OHOS_BUILD_ENABLE_KEYBOARD
5261 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
5262 ASSERT_TRUE(injectDownEvent != nullptr);
5263 KeyEvent::KeyItem kitDown;
5264 kitDown.SetKeyCode(KeyEvent::KEYCODE_MENU);
5265 kitDown.SetPressed(false);
5266 kitDown.SetDownTime(0);
5267 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_MENU);
5268 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
5269 injectDownEvent->AddPressedKeyItems(kitDown);
5270 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
5271 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_UP);
5272
5273 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
5274 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId);
5275 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
5276 }
5277
5278 /*
5279 * @tc.name: InputManagerTest_SubscribeKeyEvent_019
5280 * @tc.desc: Verify subscribe KEYCODE_MENU key down event.
5281 * @tc.type: FUNC
5282 * @tc.require:
5283 */
5284 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_019, TestSize.Level1)
5285 {
5286 CALL_TEST_DEBUG;
5287 std::set<int32_t> preKeys;
5288 std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
5289 keyOption->SetPreKeys(preKeys);
5290 keyOption->SetFinalKey(KeyEvent::KEYCODE_MENU);
5291 keyOption->SetFinalKeyDown(true);
5292 keyOption->SetFinalKeyDownDuration(0);
5293 int32_t subscribeId = INVAID_VALUE;
__anonce2bd3135202(std::shared_ptr<KeyEvent> keyEvent) 5294 subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr<KeyEvent> keyEvent) {
5295 EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER);
5296 MMI_HILOGD("Subscribe key event KEYCODE_MENU down trigger callback");
5297 });
5298 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
5299 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
5300 EXPECT_TRUE(subscribeId >= 0);
5301 #else
5302 EXPECT_TRUE(subscribeId < 0);
5303 #endif // OHOS_BUILD_ENABLE_KEYBOARD
5304 std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
5305 ASSERT_TRUE(injectDownEvent != nullptr);
5306 KeyEvent::KeyItem kitDown;
5307 kitDown.SetKeyCode(KeyEvent::KEYCODE_MENU);
5308 kitDown.SetPressed(true);
5309 kitDown.SetDownTime(0);
5310 injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_MENU);
5311 injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
5312 injectDownEvent->AddPressedKeyItems(kitDown);
5313 InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
5314 ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN);
5315
5316 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
5317 InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId);
5318 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
5319 }
5320
5321 /*
5322 * @tc.name: InputManagerTest_CreateVKeyboardDevice_001
5323 * @tc.desc: CreateVKeyboardDevice test.
5324 * @tc.type: FUNC
5325 * @tc.require:
5326 */
5327 HWTEST_F(InputManagerTest, InputManagerTest_CreateVKeyboardDevice_001, TestSize.Level1)
5328 {
5329 CALL_TEST_DEBUG;
5330 #ifdef OHOS_BUILD_ENABLE_VKEYBOARD
5331 int32_t ret = InputManager::GetInstance()->CreateVKeyboardDevice(nullptr);
5332 ASSERT_EQ(ret, INVALID_HANDLER_ID);
5333 #endif // OHOS_BUILD_ENABLE_VKEYBOARD
5334 }
5335
5336 /*
5337 * @tc.name: InputManagerTest_AddPreMonitor_001
5338 * @tc.desc: AddPreMonitor.
5339 * @tc.type: FUNC
5340 * @tc.require:
5341 */
5342 HWTEST_F(InputManagerTest, InputManagerTest_AddPreMonitor_001, TestSize.Level1)
5343 {
5344 CALL_TEST_DEBUG;
5345 std::vector<int32_t> keys;
5346 keys.push_back(3);
5347 uint32_t handleEventType = 0;
5348 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->AddPreMonitor(nullptr, handleEventType, keys));
5349 }
5350
5351 /*
5352 * @tc.name: InputManagerTest_RemovePreMonitor_001
5353 * @tc.desc: RemovePreMonitor.
5354 * @tc.type: FUNC
5355 * @tc.require:
5356 */
5357 HWTEST_F(InputManagerTest, InputManagerTest_RemovePreMonitor_001, TestSize.Level1)
5358 {
5359 CALL_TEST_DEBUG;
5360 int32_t monitorId = 0;
5361 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->RemovePreMonitor(monitorId));
5362 }
5363
5364 /*
5365 * @tc.name: InputManagerTest_SetMultiWindowScreenId_001
5366 * @tc.desc: SetMultiWindowScreenId.
5367 * @tc.type: FUNC
5368 * @tc.require:
5369 */
5370 HWTEST_F(InputManagerTest, InputManagerTest_SetMultiWindowScreenId_001, TestSize.Level1)
5371 {
5372 CALL_TEST_DEBUG;
5373 uint64_t screenId = 1;
5374 uint64_t displayNodeScreenId = 2;
5375 ASSERT_NO_FATAL_FAILURE(InputManager::GetInstance()->SetMultiWindowScreenId(screenId, displayNodeScreenId));
5376 }
5377 } // namespace MMI
5378 } // namespace OHOS
5379