• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "event_log_helper.h"
17 #include "event_util_test.h"
18 #include "input_handler_type.h"
19 #include "mmi_log.h"
20 #include "multimodal_event_handler.h"
21 #include "system_info.h"
22 #include "util.h"
23 
24 namespace OHOS {
25 namespace MMI {
26 namespace {
27 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "InputManagerTest" };
28 constexpr int32_t TIME_WAIT_FOR_OP = 100;
29 constexpr int32_t NANOSECOND_TO_MILLISECOND = 1000000;
30 constexpr int32_t DEFAULT_POINTER_ID = 0;
31 constexpr int32_t DEFAULT_DEVICE_ID = 0;
32 constexpr int32_t INDEX_FIRST = 1;
33 constexpr int32_t INDEX_SECOND = 2;
34 constexpr int32_t INDEX_THIRD = 3;
35 } // namespace
36 
37 class InputManagerTest : public testing::Test {
38 public:
39     void SetUp();
40     void TearDown();
41     static void SetUpTestCase();
42     std::string GetEventDump();
43     std::shared_ptr<PointerEvent> SetupPointerEvent001();
44     std::shared_ptr<PointerEvent> SetupPointerEvent002();
45     std::shared_ptr<PointerEvent> SetupPointerEvent003();
46     std::shared_ptr<PointerEvent> SetupPointerEvent005();
47     std::shared_ptr<PointerEvent> SetupPointerEvent006();
48     std::shared_ptr<PointerEvent> SetupPointerEvent007();
49     std::shared_ptr<PointerEvent> SetupPointerEvent009();
50     std::shared_ptr<PointerEvent> SetupPointerEvent010();
51     std::shared_ptr<PointerEvent> SetupPointerEvent011();
52     std::shared_ptr<PointerEvent> SetupPointerEvent012();
53     std::shared_ptr<PointerEvent> SetupPointerEvent013();
54     std::shared_ptr<PointerEvent> SetupPointerEvent014();
55     std::shared_ptr<PointerEvent> SetupPointerEvent015();
56 #ifdef OHOS_BUILD_ENABLE_JOYSTICK
57     std::shared_ptr<PointerEvent> SetupPointerEvent016();
58 #endif // OHOS_BUILD_ENABLE_JOYSTICK
59     std::shared_ptr<PointerEvent> SetupmouseEvent001();
60     std::shared_ptr<PointerEvent> SetupmouseEvent002();
61     std::shared_ptr<PointerEvent> SetupTouchScreenEvent001();
62     std::shared_ptr<PointerEvent> SetupTouchScreenEvent002();
63     std::shared_ptr<KeyEvent> SetupKeyEvent001();
64     std::shared_ptr<KeyEvent> SetupKeyEvent002();
65     std::shared_ptr<KeyEvent> SetupKeyEvent003();
66     std::shared_ptr<PointerEvent> TestMarkConsumedStep1();
67     std::shared_ptr<PointerEvent> TestMarkConsumedStep2();
68     void TestMarkConsumedStep3(int32_t monitorId, int32_t eventId);
69     void TestMarkConsumedStep4();
70     void TestMarkConsumedStep5();
71     void TestMarkConsumedStep6();
72     int32_t TestAddMonitor(std::shared_ptr<IInputEventConsumer> consumer);
73     void TestRemoveMonitor(int32_t monitorId);
74     void TestMarkConsumed(int32_t monitorId, int32_t eventId);
75     std::shared_ptr<PointerEvent> SetupTabletToolEvent001();
76 };
77 
SetUpTestCase()78 void InputManagerTest::SetUpTestCase()
79 {
80     ASSERT_TRUE(TestUtil->Init());
81 }
82 
SetUp()83 void InputManagerTest::SetUp()
84 {
85     TestUtil->SetRecvFlag(RECV_FLAG::RECV_FOCUS);
86 }
87 
TearDown()88 void InputManagerTest::TearDown()
89 {
90     TestUtil->AddEventDump("");
91     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
92 }
93 
GetEventDump()94 std::string InputManagerTest::GetEventDump()
95 {
96     return TestUtil->GetEventDump();
97 }
98 
SetupPointerEvent001()99 std::shared_ptr<PointerEvent> InputManagerTest::SetupPointerEvent001()
100 {
101     auto pointerEvent = PointerEvent::Create();
102     CHKPP(pointerEvent);
103     PointerEvent::PointerItem item;
104     item.SetPointerId(0);   // test code,set the PointerId = 0
105     item.SetDisplayX(523);   // test code,set the DisplayX = 523
106     item.SetDisplayY(723);   // test code,set the DisplayY = 723
107     item.SetPressure(5);    // test code,set the Pressure = 5
108     item.SetDeviceId(1);    // test code,set the DeviceId = 1
109     pointerEvent->AddPointerItem(item);
110 
111     item.SetPointerId(1);   // test code,set the PointerId = 1
112     item.SetDisplayX(610);   // test code,set the DisplayX = 610
113     item.SetDisplayY(910);   // test code,set the DisplayY = 910
114     item.SetPressure(7);    // test code,set the Pressure = 7
115     item.SetDeviceId(1);    // test code,set the DeviceId = 1
116     pointerEvent->AddPointerItem(item);
117 
118     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
119     pointerEvent->SetPointerId(1);  // test code,set the PointerId = 1
120     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
121     return pointerEvent;
122 }
123 
SetupPointerEvent002()124 std::shared_ptr<PointerEvent> InputManagerTest::SetupPointerEvent002()
125 {
126     auto pointerEvent = PointerEvent::Create();
127     CHKPP(pointerEvent);
128     PointerEvent::PointerItem item;
129     item.SetPointerId(0);   // test code,set the PointerId = 0
130     item.SetDisplayX(523);   // test code,set the DisplayX = 523
131     item.SetDisplayY(723);   // test code,set the DisplayY = 723
132     item.SetPressure(5);    // test code,set the Pressure = 5
133     item.SetDeviceId(1);    // test code,set the DeviceId = 1
134     pointerEvent->AddPointerItem(item);
135 
136     item.SetPointerId(1);   // test code,set the PointerId = 1
137     item.SetDisplayX(600);   // test code,set the DisplayX = 600
138     item.SetDisplayY(610);   // test code,set the DisplayY = 610
139     item.SetPressure(7);    // test code,set the Pressure = 7
140     item.SetDeviceId(1);    // test code,set the DeviceId = 1
141     pointerEvent->AddPointerItem(item);
142 
143     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
144     pointerEvent->SetPointerId(1);  // test code,set the PointerId = 1
145     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
146     return pointerEvent;
147 }
148 
SetupPointerEvent003()149 std::shared_ptr<PointerEvent> InputManagerTest::SetupPointerEvent003()
150 {
151     auto pointerEvent = PointerEvent::Create();
152     CHKPP(pointerEvent);
153     PointerEvent::PointerItem item;
154     item.SetPointerId(0);   // test code,set the PointerId = 0
155     item.SetDisplayX(523);   // test code,set the DisplayX = 523
156     item.SetDisplayY(723);   // test code,set the DisplayY = 723
157     item.SetPressure(5);    // test code,set the Pressure = 5
158     item.SetDeviceId(1);    // test code,set the DeviceId = 1
159     pointerEvent->AddPointerItem(item);
160 
161     item.SetPointerId(1);   // test code,set the PointerId = 1
162     item.SetDisplayX(623);   // test code,set the DisplayX = 623
163     item.SetDisplayY(823);   // test code,set the DisplayY = 823
164     item.SetPressure(0);    // test code,set the Pressure = 0
165     item.SetDeviceId(1);    // test code,set the DeviceId = 1
166     pointerEvent->AddPointerItem(item);
167 
168     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
169     pointerEvent->SetPointerId(1);  // test code,set the PointerId = 1
170     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
171     return pointerEvent;
172 }
173 
SetupPointerEvent005()174 std::shared_ptr<PointerEvent> InputManagerTest::SetupPointerEvent005()
175 {
176     auto pointerEvent = PointerEvent::Create();
177     CHKPP(pointerEvent);
178     int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
179     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
180     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN);
181     pointerEvent->SetButtonId(PointerEvent::MOUSE_BUTTON_LEFT);
182     pointerEvent->SetPointerId(0);
183     pointerEvent->SetButtonPressed(PointerEvent::MOUSE_BUTTON_LEFT);
184     PointerEvent::PointerItem item;
185     item.SetPointerId(0);
186     item.SetDownTime(downTime);
187     item.SetPressed(true);
188 
189     item.SetDisplayX(50);
190     item.SetDisplayY(50);
191     item.SetWindowX(70);
192     item.SetWindowY(70);
193 
194     item.SetWidth(0);
195     item.SetHeight(0);
196     item.SetPressure(0);
197     item.SetDeviceId(0);
198     pointerEvent->AddPointerItem(item);
199     return pointerEvent;
200 }
201 
SetupPointerEvent006()202 std::shared_ptr<PointerEvent> InputManagerTest::SetupPointerEvent006()
203 {
204     auto EventTest = PointerEvent::Create();
205     CHKPP(EventTest);
206     EventTest->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
207     EventTest->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
208     EventTest->SetPointerId(0);
209     PointerEvent::PointerItem pointerItem;
210     pointerItem.SetPointerId(0);
211     pointerItem.SetDownTime(0);
212     pointerItem.SetPressed(false);
213     pointerItem.SetDisplayX(50);
214     pointerItem.SetDisplayY(50);
215     pointerItem.SetWindowX(70);
216     pointerItem.SetWindowY(70);
217     pointerItem.SetWidth(0);
218     pointerItem.SetHeight(0);
219     pointerItem.SetPressure(0);
220     pointerItem.SetDeviceId(0);
221     EventTest->AddPointerItem(pointerItem);
222     return EventTest;
223 }
224 
SetupPointerEvent007()225 std::shared_ptr<PointerEvent> InputManagerTest::SetupPointerEvent007()
226 {
227     auto pointerEvent = PointerEvent::Create();
228     CHKPP(pointerEvent);
229     int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
230     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
231     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_UP);
232     pointerEvent->SetButtonId(PointerEvent::MOUSE_BUTTON_LEFT);
233     pointerEvent->SetPointerId(0);
234     pointerEvent->SetButtonPressed(PointerEvent::MOUSE_BUTTON_LEFT);
235     PointerEvent::PointerItem item;
236     item.SetPointerId(0);
237     item.SetDownTime(downTime);
238     item.SetPressed(false);
239 
240     item.SetDisplayX(50);
241     item.SetDisplayY(50);
242     item.SetWindowX(70);
243     item.SetWindowY(70);
244 
245     item.SetWidth(0);
246     item.SetHeight(0);
247     item.SetPressure(0);
248     item.SetDeviceId(0);
249     pointerEvent->AddPointerItem(item);
250     return pointerEvent;
251 }
252 
SetupPointerEvent009()253 std::shared_ptr<PointerEvent> InputManagerTest::SetupPointerEvent009()
254 {
255     auto pointerEvent = PointerEvent::Create();
256     CHKPP(pointerEvent);
257     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
258     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_AXIS_UPDATE);
259     pointerEvent->SetPointerId(1);
260     pointerEvent->SetAxisValue(PointerEvent::AXIS_TYPE_SCROLL_VERTICAL, -1.0000);
261     PointerEvent::PointerItem item;
262     item.SetPointerId(1);
263     item.SetDownTime(0);
264     item.SetPressed(false);
265 
266     item.SetDisplayX(50);
267     item.SetDisplayY(50);
268     item.SetWindowX(70);
269     item.SetWindowY(70);
270 
271     item.SetWidth(0);
272     item.SetHeight(0);
273     item.SetPressure(0);
274     item.SetDeviceId(0);
275     pointerEvent->AddPointerItem(item);
276     return pointerEvent;
277 }
278 
SetupPointerEvent010()279 std::shared_ptr<PointerEvent> InputManagerTest::SetupPointerEvent010()
280 {
281     auto pointerEvent = PointerEvent::Create();
282     CHKPP(pointerEvent);
283     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
284     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_AXIS_UPDATE);
285     pointerEvent->SetPointerId(1);
286     pointerEvent->SetAxisValue(PointerEvent::AXIS_TYPE_SCROLL_VERTICAL, 30.0);
287     pointerEvent->SetAxisValue(PointerEvent::AXIS_TYPE_SCROLL_HORIZONTAL, 40.0);
288     PointerEvent::PointerItem item;
289     item.SetPointerId(1);
290     item.SetDownTime(0);
291     item.SetPressed(false);
292 
293     item.SetDisplayX(200);
294     item.SetDisplayY(200);
295     item.SetWindowX(300);
296     item.SetWindowY(300);
297 
298     item.SetWidth(0);
299     item.SetHeight(0);
300     item.SetPressure(0);
301     item.SetDeviceId(0);
302     pointerEvent->AddPointerItem(item);
303     return pointerEvent;
304 }
305 
SetupPointerEvent011()306 std::shared_ptr<PointerEvent> InputManagerTest::SetupPointerEvent011()
307 {
308     auto Event = PointerEvent::Create();
309     CHKPP(Event);
310     Event->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
311     Event->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
312     Event->SetPointerId(1);
313     PointerEvent::PointerItem item;
314     item.SetDownTime(0);
315     item.SetPointerId(0);
316     item.SetDisplayX(523);
317     item.SetPressure(0.15);
318     item.SetDisplayY(723);
319     item.SetWindowX(323);
320     item.SetWindowY(453);
321     item.SetWidth(0);
322     item.SetHeight(0);
323     item.SetDeviceId(1);
324     item.SetTiltX(2.12);
325     item.SetTiltY(5.43);
326     Event->AddPointerItem(item);
327 
328     item.SetPointerId(1);
329     item.SetDownTime(0);
330     item.SetDisplayX(50);
331     item.SetPressure(0.45);
332     item.SetDisplayY(50);
333     item.SetWindowX(70);
334     item.SetWindowY(70);
335     item.SetWidth(0);
336     item.SetHeight(0);
337     item.SetDeviceId(1);
338     item.SetTiltX(12.22);
339     item.SetTiltY(15.33);
340 
341     Event->AddPointerItem(item);
342     return Event;
343 }
344 
SetupPointerEvent012()345 std::shared_ptr<PointerEvent> InputManagerTest::SetupPointerEvent012()
346 {
347     auto pointerEvent = PointerEvent::Create();
348     CHKPP(pointerEvent);
349     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
350     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
351     pointerEvent->SetPointerId(1);
352     PointerEvent::PointerItem item;
353     item.SetPointerId(0);
354     item.SetDownTime(0);
355     item.SetDisplayX(523);
356     item.SetDisplayY(723);
357     item.SetWindowX(323);
358     item.SetWindowY(453);
359     item.SetWidth(0);
360     item.SetHeight(0);
361     item.SetTiltX(2.12);
362     item.SetTiltY(5.43);
363     item.SetPressure(0.15);
364     item.SetDeviceId(1);
365     pointerEvent->AddPointerItem(item);
366 
367     item.SetPointerId(1);
368     item.SetDownTime(0);
369     item.SetDisplayX(50);
370     item.SetDisplayY(50);
371     item.SetWindowX(70);
372     item.SetWindowY(70);
373     item.SetWidth(0);
374     item.SetHeight(0);
375     item.SetTiltX(12.22);
376     item.SetTiltY(15.33);
377     item.SetPressure(0.45);
378     item.SetDeviceId(1);
379     pointerEvent->AddPointerItem(item);
380     return pointerEvent;
381 }
382 
SetupPointerEvent013()383 std::shared_ptr<PointerEvent> InputManagerTest::SetupPointerEvent013()
384 {
385     auto pointerEvent = PointerEvent::Create();
386     CHKPP(pointerEvent);
387     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
388     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
389     pointerEvent->SetPointerId(1);
390     PointerEvent::PointerItem item;
391     item.SetPointerId(0);
392     item.SetDownTime(0);
393     item.SetDisplayX(523);
394     item.SetDisplayY(723);
395     item.SetWindowX(323);
396     item.SetWindowY(453);
397     item.SetWidth(0);
398     item.SetHeight(0);
399     item.SetTiltX(2.12);
400     item.SetTiltY(5.43);
401     item.SetPressure(0.15);
402     item.SetDeviceId(1);
403     pointerEvent->AddPointerItem(item);
404 
405     item.SetPointerId(1);
406     item.SetDownTime(0);
407     item.SetDisplayX(50);
408     item.SetDisplayY(50);
409     item.SetWindowX(70);
410     item.SetWindowY(70);
411     item.SetWidth(0);
412     item.SetHeight(0);
413     item.SetTiltX(12.22);
414     item.SetTiltY(15.33);
415     item.SetPressure(0.45);
416     item.SetDeviceId(1);
417     pointerEvent->AddPointerItem(item);
418     return pointerEvent;
419 }
420 
SetupPointerEvent014()421 std::shared_ptr<PointerEvent> InputManagerTest::SetupPointerEvent014()
422 {
423     auto mouseEvent = PointerEvent::Create();
424     CHKPP(mouseEvent);
425     mouseEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
426     mouseEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
427     mouseEvent->SetPointerId(0);
428     PointerEvent::PointerItem mouseItem;
429     mouseItem.SetDownTime(0);
430     mouseItem.SetPointerId(0);
431     mouseItem.SetPressed(false);
432 
433     mouseItem.SetDisplayX(10);
434     mouseItem.SetWindowX(10);
435     mouseItem.SetDisplayY(10);
436     mouseItem.SetWindowY(10);
437 
438     mouseItem.SetWidth(0);
439     mouseItem.SetPressure(0);
440     mouseItem.SetHeight(0);
441     mouseItem.SetDeviceId(0);
442     mouseEvent->AddPointerItem(mouseItem);
443     return mouseEvent;
444 }
445 
SetupPointerEvent015()446 std::shared_ptr<PointerEvent> InputManagerTest::SetupPointerEvent015()
447 {
448     auto pointerEvent = PointerEvent::Create();
449     CHKPP(pointerEvent);
450     pointerEvent->SetPointerId(0);
451     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
452     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
453     PointerEvent::PointerItem pointItem;
454     pointItem.SetPointerId(0);
455     pointItem.SetDownTime(0);
456     pointItem.SetPressed(false);
457     pointItem.SetDisplayY(1259);
458     pointItem.SetDisplayX(0);
459     pointItem.SetWindowX(10);
460     pointItem.SetWindowY(10);
461     pointItem.SetWidth(0);
462     pointItem.SetPressure(0);
463     pointItem.SetHeight(0);
464     pointItem.SetDeviceId(0);
465     pointerEvent->AddPointerItem(pointItem);
466     return pointerEvent;
467 }
468 
469 #ifdef OHOS_BUILD_ENABLE_JOYSTICK
SetupPointerEvent016()470 std::shared_ptr<PointerEvent> InputManagerTest::SetupPointerEvent016()
471 {
472     auto pointerEvent = PointerEvent::Create();
473     CHKPP(pointerEvent);
474     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_JOYSTICK);
475     return pointerEvent;
476 }
477 #endif // OHOS_BUILD_ENABLE_JOYSTICK
478 
SetupKeyEvent001()479 std::shared_ptr<KeyEvent> InputManagerTest::SetupKeyEvent001()
480 {
481     std::shared_ptr<KeyEvent> pointEvent = KeyEvent::Create();
482     CHKPP(pointEvent);
483     int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
484     KeyEvent::KeyItem kitDown;
485     kitDown.SetPressed(true);
486     kitDown.SetKeyCode(KeyEvent::KEYCODE_BACK);
487     kitDown.SetDownTime(downTime);
488 
489     pointEvent->AddPressedKeyItems(kitDown);
490     pointEvent->SetKeyCode(KeyEvent::KEYCODE_BACK);
491     pointEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
492 
493     return pointEvent;
494 }
495 
SetupKeyEvent002()496 std::shared_ptr<KeyEvent> InputManagerTest::SetupKeyEvent002()
497 {
498     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
499     CHKPP(keyEvent);
500     int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
501     KeyEvent::KeyItem kitDown;
502     kitDown.SetKeyCode(KeyEvent::KEYCODE_BACK);
503     kitDown.SetPressed(true);
504     kitDown.SetDownTime(downTime);
505     keyEvent->SetKeyCode(KeyEvent::KEYCODE_BACK);
506     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
507     keyEvent->AddPressedKeyItems(kitDown);
508 
509     return keyEvent;
510 }
511 
SetupKeyEvent003()512 std::shared_ptr<KeyEvent> InputManagerTest::SetupKeyEvent003()
513 {
514     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
515     CHKPP(keyEvent);
516     int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
517     KeyEvent::KeyItem kitDown;
518     kitDown.SetKeyCode(KeyEvent::KEYCODE_HOME);
519     kitDown.SetPressed(true);
520     kitDown.SetDownTime(downTime);
521     keyEvent->SetKeyCode(KeyEvent::KEYCODE_HOME);
522     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
523     keyEvent->AddPressedKeyItems(kitDown);
524 
525     return keyEvent;
526 }
527 
TestMarkConsumedStep1()528 std::shared_ptr<PointerEvent> InputManagerTest::TestMarkConsumedStep1()
529 {
530     auto pointerEvent = PointerEvent::Create();
531     CHKPP(pointerEvent);
532     PointerEvent::PointerItem item;
533     item.SetPointerId(0);   // test code,set the PointerId = 0
534     item.SetDisplayX(523);   // test code,set the DisplayX = 523
535     item.SetDisplayY(723);   // test code,set the DisplayY = 723
536     item.SetPressure(5);    // test code,set the Pressure = 5
537     item.SetDeviceId(1);    // test code,set the DeviceId = 1
538     pointerEvent->AddPointerItem(item);
539 
540     pointerEvent->SetId(std::numeric_limits<int32_t>::max() - INDEX_THIRD);
541     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
542     pointerEvent->SetPointerId(0);  // test code,set the PointerId = 1
543     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
544 
545 #if defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR)
546     TestSimulateInputEvent(pointerEvent);
547 #endif // OHOS_BUILD_ENABLE_TOUCH && OHOS_BUILD_ENABLE_MONITOR
548     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
549     return pointerEvent;
550 }
551 
TestMarkConsumedStep2()552 std::shared_ptr<PointerEvent> InputManagerTest::TestMarkConsumedStep2()
553 {
554     auto pointerEvent = PointerEvent::Create();
555     CHKPP(pointerEvent);
556     PointerEvent::PointerItem item;
557     item.SetPointerId(0);   // test code,set the PointerId = 0
558     item.SetDisplayX(623);  // test code,set the DisplayX = 623
559     item.SetDisplayY(723);   // test code,set the DisplayY = 723
560     item.SetPressure(5);    // test code,set the Pressure = 5
561     item.SetDeviceId(1);    // test code,set the DeviceId = 1
562     pointerEvent->AddPointerItem(item);
563 
564     pointerEvent->SetId(std::numeric_limits<int32_t>::max() - INDEX_SECOND);
565     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
566     pointerEvent->SetPointerId(0);  // test code,set the PointerId = 1
567     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
568 
569 #if defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR)
570     TestSimulateInputEvent(pointerEvent);
571 #endif // OHOS_BUILD_ENABLE_TOUCH && OHOS_BUILD_ENABLE_MONITOR
572     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
573     return pointerEvent;
574 }
575 
TestMarkConsumedStep3(int32_t monitorId,int32_t eventId)576 void InputManagerTest::TestMarkConsumedStep3(int32_t monitorId, int32_t eventId)
577 {
578     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
579     TestUtil->SetRecvFlag(RECV_FLAG::RECV_MARK_CONSUMED);
580     TestMarkConsumed(monitorId, eventId);
581     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
582 }
583 
TestMarkConsumedStep4()584 void InputManagerTest::TestMarkConsumedStep4()
585 {
586     auto keyEvent = PointerEvent::Create();
587     CHKPV(keyEvent);
588     PointerEvent::PointerItem item;
589     item.SetDisplayX(523);  // test code,set the DisplayX = 523
590     item.SetPointerId(0);   // test code,set the PointerId = 0
591     item.SetDeviceId(1);    // test code,set the DeviceId = 1
592     item.SetPressure(5);    // test code,set the Pressure = 5
593     item.SetDisplayY(723);   // test code,set the DisplayY = 723
594     keyEvent->AddPointerItem(item);
595 
596     keyEvent->SetId(std::numeric_limits<int32_t>::max() - INDEX_FIRST);
597     keyEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
598     keyEvent->SetPointerId(0);  // test code,set the PointerId = 1
599     keyEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
600 
601 #if defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR)
602     TestSimulateInputEvent(keyEvent, TestScene::EXCEPTION_TEST);
603 #endif // OHOS_BUILD_ENABLE_TOUCH && OHOS_BUILD_ENABLE_MONITOR
604     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
605 }
606 
TestMarkConsumedStep5()607 void InputManagerTest::TestMarkConsumedStep5()
608 {
609     auto mouseEventTest = PointerEvent::Create();
610     CHKPV(mouseEventTest);
611     PointerEvent::PointerItem item;
612     item.SetPointerId(0);   // test code,set the PointerId = 0
613     item.SetDisplayX(523);  // test code,set the DisplayX = 523
614     item.SetDisplayY(723);   // test code,set the DisplayY = 723
615     item.SetPressure(5);    // test code,set the Pressure = 5
616     item.SetDeviceId(1);    // test code,set the DeviceId = 1
617     mouseEventTest->AddPointerItem(item);
618 
619     mouseEventTest->SetId(std::numeric_limits<int32_t>::max());
620     mouseEventTest->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
621     mouseEventTest->SetPointerId(0);  // test code,set the PointerId = 0
622     mouseEventTest->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
623 
624 #if defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR)
625     TestSimulateInputEvent(mouseEventTest, TestScene::EXCEPTION_TEST);
626 #endif // OHOS_BUILD_ENABLE_TOUCH && OHOS_BUILD_ENABLE_MONITOR
627     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
628 }
629 
TestMarkConsumedStep6()630 void InputManagerTest::TestMarkConsumedStep6()
631 {
632     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
633     auto pointerEvent = PointerEvent::Create();
634     CHKPV(pointerEvent);
635     PointerEvent::PointerItem item;
636     item.SetPointerId(0);   // test code,set the PointerId = 0
637     item.SetDisplayY(723);   // test code,set the DisplayY = 723
638     item.SetDeviceId(1);    // test code,set the DeviceId = 1
639     item.SetDisplayX(523);   // test code,set the DisplayX = 523
640     item.SetPressure(5);    // test code,set the Pressure = 5
641     pointerEvent->AddPointerItem(item);
642 
643     pointerEvent->SetId(std::numeric_limits<int32_t>::max());
644     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
645     pointerEvent->SetPointerId(0);  // test code,set the PointerId = 0
646     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
647 
648     TestUtil->SetRecvFlag(RECV_FLAG::RECV_FOCUS);
649 #if defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR)
650     TestSimulateInputEvent(pointerEvent);
651 #endif // OHOS_BUILD_ENABLE_TOUCH && OHOS_BUILD_ENABLE_MONITOR
652     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
653 }
654 
SetupmouseEvent001()655 std::shared_ptr<PointerEvent> InputManagerTest::SetupmouseEvent001()
656 {
657     auto pointerEvent = PointerEvent::Create();
658     CHKPP(pointerEvent);
659     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
660     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
661     pointerEvent->SetPointerId(0);
662     PointerEvent::PointerItem item;
663     item.SetPointerId(0);
664     item.SetDownTime(0);
665     item.SetPressed(false);
666 
667     item.SetDisplayX(10);
668     item.SetDisplayY(10);
669     item.SetWindowX(10);
670     item.SetWindowY(10);
671 
672     item.SetWidth(0);
673     item.SetHeight(0);
674     item.SetPressure(0);
675     item.SetDeviceId(0);
676     pointerEvent->AddPointerItem(item);
677     return pointerEvent;
678 }
679 
SetupmouseEvent002()680 std::shared_ptr<PointerEvent> InputManagerTest::SetupmouseEvent002()
681 {
682     auto pointerEvent = PointerEvent::Create();
683     CHKPP(pointerEvent);
684     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
685     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
686     pointerEvent->SetPointerId(0);
687     PointerEvent::PointerItem item;
688     item.SetPointerId(0);
689     item.SetDownTime(0);
690     item.SetPressed(false);
691 
692     item.SetDisplayX(50);
693     item.SetDisplayY(50);
694     item.SetWindowX(70);
695     item.SetWindowY(70);
696 
697     item.SetWidth(0);
698     item.SetHeight(0);
699     item.SetPressure(0);
700     item.SetDeviceId(0);
701     pointerEvent->AddPointerItem(item);
702     return pointerEvent;
703 }
704 
SetupTouchScreenEvent001()705 std::shared_ptr<PointerEvent> InputManagerTest::SetupTouchScreenEvent001()
706 {
707     auto pointerEvent = PointerEvent::Create();
708     CHKPP(pointerEvent);
709     PointerEvent::PointerItem item;
710     item.SetPointerId(0);
711     item.SetDisplayX(10);
712     item.SetDisplayY(10);
713     item.SetPressure(5);
714     item.SetDeviceId(1);
715     pointerEvent->AddPointerItem(item);
716     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
717     pointerEvent->SetPointerId(0);
718     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
719     return pointerEvent;
720 }
721 
SetupTouchScreenEvent002()722 std::shared_ptr<PointerEvent> InputManagerTest::SetupTouchScreenEvent002()
723 {
724     auto pointerEvent = PointerEvent::Create();
725     CHKPP(pointerEvent);
726     PointerEvent::PointerItem item;
727     item.SetPointerId(0);
728     item.SetDisplayX(50);
729     item.SetDisplayY(50);
730     item.SetPressure(5);
731     item.SetDeviceId(1);
732     pointerEvent->AddPointerItem(item);
733     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
734     pointerEvent->SetPointerId(0);
735     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
736     return pointerEvent;
737 }
738 
TestAddMonitor(std::shared_ptr<IInputEventConsumer> consumer)739 int32_t InputManagerTest::TestAddMonitor(std::shared_ptr<IInputEventConsumer> consumer)
740 {
741     AccessMonitor monitor;
742     return InputManager::GetInstance()->AddMonitor(consumer);
743 }
744 
TestRemoveMonitor(int32_t monitorId)745 void InputManagerTest::TestRemoveMonitor(int32_t monitorId)
746 {
747     AccessMonitor monitor;
748     InputManager::GetInstance()->RemoveMonitor(monitorId);
749 }
750 
TestMarkConsumed(int32_t monitorId,int32_t eventId)751 void InputManagerTest::TestMarkConsumed(int32_t monitorId, int32_t eventId)
752 {
753     AccessMonitor monitor;
754     InputManager::GetInstance()->MarkConsumed(monitorId, eventId);
755 }
756 
757 /**
758  * @tc.name: InputManagerTest_AddMonitor_001
759  * @tc.desc: Verify pointerevent monitor
760  * @tc.type: FUNC
761  * @tc.require:
762  */
763 HWTEST_F(InputManagerTest, InputManagerTest_AddMonitor_001, TestSize.Level1)
764 {
765     CALL_DEBUG_ENTER;
__anonebfd6e530202(std::shared_ptr<PointerEvent> event) 766     auto PointerEventFun = [](std::shared_ptr<PointerEvent> event) {
767         MMI_HILOGD("Add monitor success");
768     };
769     int32_t monitorId = InputManager::GetInstance()->AddMonitor(PointerEventFun);
770 #if (defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)) && defined(OHOS_BUILD_ENABLE_MONITOR)
771     ASSERT_NE(monitorId, INVALID_HANDLER_ID);
772 #else
773     ASSERT_EQ(monitorId, ERROR_UNSUPPORT);
774 #endif // OHOS_BUILD_ENABLE_MONITOR ||  OHOS_BUILD_ENABLE_TOUCH && OHOS_BUILD_ENABLE_MONITOR
775 }
776 
777 /**
778  * @tc.name: InputManagerTest_AddMonitor_002
779  * @tc.desc: Verify keyevent monitor
780  * @tc.type: FUNC
781  * @tc.require:
782  */
783 HWTEST_F(InputManagerTest, InputManagerTest_AddMonitor_002, TestSize.Level1)
784 {
785     CALL_DEBUG_ENTER;
__anonebfd6e530302(std::shared_ptr<KeyEvent> event) 786     auto keyEventFun = [](std::shared_ptr<KeyEvent> event) {
787         MMI_HILOGD("Add monitor success");
788     };
789     int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun);
790 #if defined(OHOS_BUILD_ENABLE_KEYBOARD) && defined(OHOS_BUILD_ENABLE_MONITOR)
791     ASSERT_NE(monitorId, INVALID_HANDLER_ID);
792 #else
793     ASSERT_EQ(monitorId, ERROR_UNSUPPORT);
794 #endif // OHOS_BUILD_ENABLE_KEYBOARD || OHOS_BUILD_ENABLE_MONITOR
795 }
796 
797 /**
798  * @tc.name: MultimodalEventHandler_SimulateKeyEvent_001
799  * @tc.desc: Verify simulate the back key is long pressed and lifted
800  * @tc.type: FUNC
801  * @tc.require:
802  */
803 HWTEST_F(InputManagerTest, InputManagerTest_SimulateKeyEvent_001, TestSize.Level1)
804 {
805     CALL_DEBUG_ENTER;
806     int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
807     std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
808     ASSERT_TRUE(injectDownEvent != nullptr);
809     KeyEvent::KeyItem kitDownTest;
810     kitDownTest.SetPressed(true);
811     kitDownTest.SetKeyCode(KeyEvent::KEYCODE_BACK);
812     kitDownTest.SetDownTime(downTime);
813     injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_BACK);
814     injectDownEvent->AddPressedKeyItems(kitDownTest);
815     injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
816 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
817     TestSimulateInputEvent(injectDownEvent);
818 #endif // OHOS_BUILD_ENABLE_KEYBOARD
819 
820     std::shared_ptr<KeyEvent> injectUpEvent = KeyEvent::Create();
821     ASSERT_TRUE(injectUpEvent != nullptr);
822     downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
823     KeyEvent::KeyItem kitUpTest;
824     kitUpTest.SetPressed(false);
825     kitUpTest.SetKeyCode(KeyEvent::KEYCODE_BACK);
826     kitUpTest.SetDownTime(downTime);
827     injectUpEvent->RemoveReleasedKeyItems(kitUpTest);
828     injectUpEvent->SetKeyCode(KeyEvent::KEYCODE_BACK);
829     injectUpEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
830 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
831     TestSimulateInputEvent(injectUpEvent);
832 #endif // OHOS_BUILD_ENABLE_KEYBOARD
833 }
834 
835 /**
836  * @tc.name: MultimodalEventHandler_SimulateKeyEvent_002
837  * @tc.desc: Verify simulate the back home is pressed
838  * @tc.type: FUNC
839  * @tc.require:
840  */
841 HWTEST_F(InputManagerTest, InputManagerTest_SimulateKeyEvent_002, TestSize.Level1)
842 {
843     CALL_DEBUG_ENTER;
844     std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
845     ASSERT_TRUE(injectDownEvent != nullptr);
846     int64_t downTime = -1;
847     KeyEvent::KeyItem kitDown;
848     kitDown.SetKeyCode(KeyEvent::KEYCODE_HOME);
849     kitDown.SetPressed(true);
850     kitDown.SetDownTime(downTime);
851     injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_HOME);
852     injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
853     injectDownEvent->AddPressedKeyItems(kitDown);
854 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
855     TestSimulateInputEvent(injectDownEvent);
856 #endif // OHOS_BUILD_ENABLE_KEYBOARD
857 }
858 
859 /**
860  * @tc.name: MultimodalEventHandler_SimulateKeyEvent_003
861  * @tc.desc: Verify simulate the back key is pressed and lifted
862  * @tc.type: FUNC
863  * @tc.require:
864  */
865 HWTEST_F(InputManagerTest, InputManagerTest_SimulateKeyEvent_003, TestSize.Level1)
866 {
867     CALL_DEBUG_ENTER;
868     std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
869     ASSERT_TRUE(injectDownEvent != nullptr);
870     int64_t downTime = 0;
871     KeyEvent::KeyItem kitDown;
872     kitDown.SetKeyCode(KeyEvent::KEYCODE_BACK);
873     kitDown.SetPressed(true);
874     kitDown.SetDownTime(downTime);
875     injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_BACK);
876     injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
877     injectDownEvent->AddPressedKeyItems(kitDown);
878 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
879     TestSimulateInputEvent(injectDownEvent);
880 #endif // OHOS_BUILD_ENABLE_KEYBOARD
881 
882     std::shared_ptr<KeyEvent> injectUpEvent = KeyEvent::Create();
883     ASSERT_TRUE(injectUpEvent != nullptr);
884     KeyEvent::KeyItem kitUp;
885     kitUp.SetKeyCode(KeyEvent::KEYCODE_BACK);
886     kitUp.SetPressed(false);
887     kitUp.SetDownTime(downTime);
888     injectUpEvent->SetKeyCode(KeyEvent::KEYCODE_BACK);
889     injectUpEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
890     injectUpEvent->RemoveReleasedKeyItems(kitUp);
891 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
892     TestSimulateInputEvent(injectUpEvent);
893 #endif // OHOS_BUILD_ENABLE_KEYBOARD
894 }
895 
896 /**
897  * @tc.name: MultimodalEventHandler_SimulateKeyEvent_004
898  * @tc.desc: Verify simulate key exception event
899  * @tc.type: FUNC
900  * @tc.require:
901  */
902 HWTEST_F(InputManagerTest, InputManagerTest_SimulateKeyEvent_004, TestSize.Level1)
903 {
904     CALL_DEBUG_ENTER;
905     std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
906     ASSERT_TRUE(injectDownEvent != nullptr);
907     int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
908     KeyEvent::KeyItem kitDown;
909     kitDown.SetKeyCode(KeyEvent::KEYCODE_UNKNOWN);
910     kitDown.SetPressed(true);
911     kitDown.SetDownTime(downTime);
912     injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_UNKNOWN);
913     injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
914     injectDownEvent->AddPressedKeyItems(kitDown);
915 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
916     TestSimulateInputEvent(injectDownEvent, TestScene::EXCEPTION_TEST);
917 #endif // OHOS_BUILD_ENABLE_KEYBOARD
918 }
919 
920 /**
921  * @tc.name: MultimodalEventHandler_SimulateKeyEvent_005
922  * @tc.desc: Verify simulate the fn key is long pressed and lifted
923  * @tc.type: FUNC
924  * @tc.require:
925  */
926 HWTEST_F(InputManagerTest, InputManagerTest_SimulateKeyEvent_005, TestSize.Level1)
927 {
928     CALL_DEBUG_ENTER;
929     std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
930     ASSERT_TRUE(injectDownEvent != nullptr);
931     int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
932     KeyEvent::KeyItem kitDown;
933     kitDown.SetKeyCode(KeyEvent::KEYCODE_FN);
934     kitDown.SetPressed(true);
935     kitDown.SetDownTime(downTime);
936     injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_FN);
937     injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
938     injectDownEvent->AddPressedKeyItems(kitDown);
939 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
940     TestSimulateInputEvent(injectDownEvent);
941 #endif // OHOS_BUILD_ENABLE_KEYBOARD
942 
943     std::shared_ptr<KeyEvent> injectUpEvent = KeyEvent::Create();
944     ASSERT_TRUE(injectUpEvent != nullptr);
945     downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
946     KeyEvent::KeyItem kitUp;
947     kitUp.SetKeyCode(KeyEvent::KEYCODE_FN);
948     kitUp.SetPressed(false);
949     kitUp.SetDownTime(downTime);
950     injectUpEvent->SetKeyCode(KeyEvent::KEYCODE_FN);
951     injectUpEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
952     injectUpEvent->RemoveReleasedKeyItems(kitUp);
953 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
954     TestSimulateInputEvent(injectUpEvent);
955 #endif // OHOS_BUILD_ENABLE_KEYBOARD
956 }
957 
958 /**
959  * @tc.name: MultimodalEventHandler_SimulatePointerEvent_001
960  * @tc.desc: Verify simulate screen down event
961  * @tc.type: FUNC
962  * @tc.require:
963  */
964 HWTEST_F(InputManagerTest, InputManagerTest_SimulatePointerEvent_001, TestSize.Level1)
965 {
966     CALL_DEBUG_ENTER;
967     std::shared_ptr<PointerEvent> pointerEvent { SetupPointerEvent001() };
968     ASSERT_TRUE(pointerEvent != nullptr);
969 #ifdef OHOS_BUILD_ENABLE_TOUCH
970     TestSimulateInputEvent(pointerEvent);
971 #endif // OHOS_BUILD_ENABLE_TOUCH
972 }
973 
974 /**
975  * @tc.name: MultimodalEventHandler_SimulatePointerEvent_002
976  * @tc.desc: Verify simulate screen move event
977  * @tc.type: FUNC
978  * @tc.require:
979  */
980 HWTEST_F(InputManagerTest, InputManagerTest_SimulatePointerEvent_002, TestSize.Level1)
981 {
982     CALL_DEBUG_ENTER;
983     std::shared_ptr<PointerEvent> pointerEvent { SetupPointerEvent002() };
984     ASSERT_TRUE(pointerEvent != nullptr);
985 #ifdef OHOS_BUILD_ENABLE_TOUCH
986     TestSimulateInputEvent(pointerEvent);
987 #endif // OHOS_BUILD_ENABLE_TOUCH
988 }
989 
990 /**
991  * @tc.name: MultimodalEventHandler_SimulatePointerEvent_003
992  * @tc.desc: Verify simulate screen up event
993  * @tc.type: FUNC
994  * @tc.require:
995  */
996 HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_003, TestSize.Level1)
997 {
998     CALL_DEBUG_ENTER;
999     std::shared_ptr<PointerEvent> pointerEvent { SetupPointerEvent003() };
1000     ASSERT_TRUE(pointerEvent != nullptr);
1001 #ifdef OHOS_BUILD_ENABLE_TOUCH
1002     TestSimulateInputEvent(pointerEvent);
1003 #endif // OHOS_BUILD_ENABLE_TOUCH
1004 }
1005 
1006 /**
1007  * @tc.name: MultimodalEventHandler_SimulatePointerEvent_004
1008  * @tc.desc: Verify simulate screen exception event
1009  * @tc.type: FUNC
1010  * @tc.require:
1011  */
1012 HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_004, TestSize.Level1)
1013 {
1014     CALL_DEBUG_ENTER;
1015     auto pointerEvent = PointerEvent::Create();
1016     ASSERT_TRUE(pointerEvent != nullptr);
1017     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
1018     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
1019     pointerEvent->SetPointerId(-1);
1020 #ifdef OHOS_BUILD_ENABLE_TOUCH
1021     TestSimulateInputEvent(pointerEvent, TestScene::EXCEPTION_TEST);
1022 #endif // OHOS_BUILD_ENABLE_TOUCH
1023 }
1024 
1025 /**
1026  * @tc.name: MultimodalEventHandler_SimulatePointerEvent_005
1027  * @tc.desc: Verify simulate mouse down event
1028  * @tc.type: FUNC
1029  * @tc.require:
1030  */
1031 HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_005, TestSize.Level1)
1032 {
1033     CALL_DEBUG_ENTER;
1034     std::shared_ptr<PointerEvent> pointerEvent { SetupPointerEvent005() };
1035     ASSERT_TRUE(pointerEvent != nullptr);
1036 #ifdef OHOS_BUILD_ENABLE_POINTER
1037     TestSimulateInputEvent(pointerEvent);
1038 #endif // OHOS_BUILD_ENABLE_POINTER
1039 }
1040 
1041 /**
1042  * @tc.name: MultimodalEventHandler_SimulatePointerEvent_006
1043  * @tc.desc: Verify simulate mouse move event
1044  * @tc.type: FUNC
1045  * @tc.require:
1046  */
1047 HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_006, TestSize.Level1)
1048 {
1049     CALL_DEBUG_ENTER;
1050     std::shared_ptr<PointerEvent> pointerEvent { SetupPointerEvent006() };
1051     ASSERT_TRUE(pointerEvent != nullptr);
1052 #ifdef OHOS_BUILD_ENABLE_POINTER
1053     TestSimulateInputEvent(pointerEvent);
1054 #endif // OHOS_BUILD_ENABLE_POINTER
1055 }
1056 
1057 /**
1058  * @tc.name: MultimodalEventHandler_SimulatePointerEvent_007
1059  * @tc.desc: Verify simulate mouse up event
1060  * @tc.type: FUNC
1061  * @tc.require:
1062  */
1063 HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_007, TestSize.Level1)
1064 {
1065     CALL_DEBUG_ENTER;
1066     std::shared_ptr<PointerEvent> pointerEvent { SetupPointerEvent007() };
1067     ASSERT_TRUE(pointerEvent != nullptr);
1068 #ifdef OHOS_BUILD_ENABLE_POINTER
1069     TestSimulateInputEvent(pointerEvent);
1070 #endif // OHOS_BUILD_ENABLE_POINTER
1071 }
1072 
1073 /**
1074  * @tc.name: MultimodalEventHandler_SimulatePointerEvent_008
1075  * @tc.desc: Verify simulate mouse exception event
1076  * @tc.type: FUNC
1077  * @tc.require:
1078  */
1079 HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_008, TestSize.Level1)
1080 {
1081     CALL_DEBUG_ENTER;
1082     auto pointerEvent = PointerEvent::Create();
1083     ASSERT_TRUE(pointerEvent != nullptr);
1084     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
1085     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
1086     pointerEvent->SetPointerId(-1);
1087 #ifdef OHOS_BUILD_ENABLE_POINTER
1088     TestSimulateInputEvent(pointerEvent, TestScene::EXCEPTION_TEST);
1089 #endif // OHOS_BUILD_ENABLE_POINTER
1090 }
1091 
1092 /**
1093  * @tc.name: MultimodalEventHandler_SimulatePointerEvent_009
1094  * @tc.desc: Verify simulate mouse VERTICAL axis event
1095  * @tc.type: FUNC
1096  * @tc.require:
1097  */
1098 HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_009, TestSize.Level1)
1099 {
1100     CALL_DEBUG_ENTER;
1101     std::shared_ptr<PointerEvent> pointerEvent { SetupPointerEvent009() };
1102     ASSERT_TRUE(pointerEvent != nullptr);
1103 #ifdef OHOS_BUILD_ENABLE_POINTER
1104     TestSimulateInputEvent(pointerEvent);
1105 #endif // OHOS_BUILD_ENABLE_POINTER
1106 }
1107 
1108 /**
1109  * @tc.name: MultimodalEventHandler_SimulatePointerEvent_010
1110  * @tc.desc: Verify simulate mouse VERTICAL HORIZONTAL axis event
1111  * @tc.type: FUNC
1112  * @tc.require:
1113  */
1114 HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_010, TestSize.Level1)
1115 {
1116     CALL_DEBUG_ENTER;
1117     std::shared_ptr<PointerEvent> pointerEvent { SetupPointerEvent010() };
1118     ASSERT_TRUE(pointerEvent != nullptr);
1119 #ifdef OHOS_BUILD_ENABLE_POINTER
1120     TestSimulateInputEvent(pointerEvent);
1121 #endif // OHOS_BUILD_ENABLE_POINTER
1122 }
1123 
1124 /**
1125  * @tc.name: MultimodalEventHandler_SimulatePointerEvent_011
1126  * @tc.desc: Verify simulate mouse AXIS_BEGIN event
1127  * @tc.type: FUNC
1128  * @tc.require:
1129  */
1130 HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_011, TestSize.Level1)
1131 {
1132     CALL_DEBUG_ENTER;
1133     auto pointerEvent = PointerEvent::Create();
1134     ASSERT_TRUE(pointerEvent != nullptr);
1135     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
1136     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_AXIS_BEGIN);
1137     pointerEvent->SetPointerId(1);
1138     pointerEvent->SetAxisValue(PointerEvent::AXIS_TYPE_SCROLL_VERTICAL, 30.0);
1139     PointerEvent::PointerItem item;
1140     item.SetPointerId(1);
1141     item.SetDownTime(0);
1142     item.SetPressed(false);
1143 
1144     item.SetDisplayX(200);
1145     item.SetDisplayY(200);
1146     item.SetWindowX(300);
1147     item.SetWindowY(300);
1148 
1149     item.SetWidth(0);
1150     item.SetHeight(0);
1151     item.SetPressure(0);
1152     item.SetDeviceId(0);
1153     pointerEvent->AddPointerItem(item);
1154 
1155 #ifdef OHOS_BUILD_ENABLE_POINTER
1156     TestSimulateInputEvent(pointerEvent);
1157 #endif // OHOS_BUILD_ENABLE_POINTER
1158 }
1159 
1160 /**
1161  * @tc.name: MultimodalEventHandler_SimulatePointerEvent_012
1162  * @tc.desc: Verify simulate mouse AXIS_UPDATE event
1163  * @tc.type: FUNC
1164  * @tc.require:
1165  */
1166 HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_012, TestSize.Level1)
1167 {
1168     CALL_DEBUG_ENTER;
1169     auto pointerEvent = PointerEvent::Create();
1170     ASSERT_TRUE(pointerEvent != nullptr);
1171     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
1172     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_AXIS_UPDATE);
1173     pointerEvent->SetPointerId(1);
1174     pointerEvent->SetAxisValue(PointerEvent::AXIS_TYPE_SCROLL_VERTICAL, 30.0);
1175     PointerEvent::PointerItem item;
1176     item.SetPointerId(1);
1177     item.SetDownTime(0);
1178     item.SetPressed(false);
1179 
1180     item.SetDisplayX(200);
1181     item.SetDisplayY(200);
1182     item.SetWindowX(300);
1183     item.SetWindowY(300);
1184 
1185     item.SetWidth(0);
1186     item.SetHeight(0);
1187     item.SetPressure(0);
1188     item.SetDeviceId(0);
1189     pointerEvent->AddPointerItem(item);
1190 
1191 #ifdef OHOS_BUILD_ENABLE_POINTER
1192     TestSimulateInputEvent(pointerEvent);
1193 #endif // OHOS_BUILD_ENABLE_POINTER
1194 }
1195 
1196 /**
1197  * @tc.name: MultimodalEventHandler_SimulatePointerEvent_013
1198  * @tc.desc: Verify simulate mouse AXIS_END event
1199  * @tc.type: FUNC
1200  * @tc.require:
1201  */
1202 HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_013, TestSize.Level1)
1203 {
1204     CALL_DEBUG_ENTER;
1205     auto pointerEvent = PointerEvent::Create();
1206     ASSERT_TRUE(pointerEvent != nullptr);
1207     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
1208     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_AXIS_END);
1209     pointerEvent->SetPointerId(1);
1210     pointerEvent->SetAxisValue(PointerEvent::AXIS_TYPE_SCROLL_VERTICAL, 30.0);
1211     PointerEvent::PointerItem item;
1212     item.SetPointerId(1);
1213     item.SetDownTime(0);
1214     item.SetPressed(false);
1215 
1216     item.SetDisplayX(200);
1217     item.SetDisplayY(200);
1218     item.SetWindowX(300);
1219     item.SetWindowY(300);
1220 
1221     item.SetWidth(0);
1222     item.SetHeight(0);
1223     item.SetPressure(0);
1224     item.SetDeviceId(0);
1225     pointerEvent->AddPointerItem(item);
1226 
1227 #ifdef OHOS_BUILD_ENABLE_POINTER
1228     TestSimulateInputEvent(pointerEvent);
1229 #endif // OHOS_BUILD_ENABLE_POINTER
1230 }
1231 
1232 #ifdef OHOS_BUILD_ENABLE_JOYSTICK
1233 /**
1234  * @tc.name: MultimodalEventHandler_SimulatePointerEvent_014
1235  * @tc.desc: Dispatch joystick event dispatch to focus window
1236  * @tc.type: FUNC
1237  * @tc.require:
1238  */
1239 HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_014, TestSize.Level1)
1240 {
1241     CALL_DEBUG_ENTER;
1242     std::shared_ptr<PointerEvent> pointerEvent { SetupPointerEvent016() };
1243     ASSERT_TRUE(pointerEvent != nullptr);
1244     TestSimulateInputEvent(pointerEvent);
1245 }
1246 #endif // OHOS_BUILD_ENABLE_JOYSTICK
1247 
1248 /**
1249  * @tc.name: InputManagerTest_MouseEventEnterAndLeave_001
1250  * @tc.desc: Verify that the mouse moves away from the window
1251  * @tc.type: FUNC
1252  * @tc.require: I5HMF3 I5HMEF
1253  */
1254 HWTEST_F(InputManagerTest, InputManagerTest_MouseEventEnterAndLeave_001, TestSize.Level1)
1255 {
1256     CALL_DEBUG_ENTER;
1257     std::shared_ptr<PointerEvent> pointerEvent { SetupPointerEvent014() };
1258     ASSERT_TRUE(pointerEvent != nullptr);
1259 #ifdef OHOS_BUILD_ENABLE_POINTER
1260     TestSimulateInputEvent(pointerEvent);
1261 #endif // OHOS_BUILD_ENABLE_POINTER
1262 }
1263 
1264 /**
1265  * @tc.name: InputManagerTest_MouseEventEnterAndLeave_002
1266  * @tc.desc: Verify return mouse away from the window
1267  * @tc.type: FUNC
1268  * @tc.require: I5HMF3 I5HMEF
1269  */
1270 HWTEST_F(InputManagerTest, InputManagerTest_MouseEventEnterAndLeave_002, TestSize.Level1)
1271 {
1272     CALL_DEBUG_ENTER;
1273     std::shared_ptr<KeyEvent> keyEvent { SetupKeyEvent002() };
1274     ASSERT_TRUE(keyEvent != nullptr);
1275 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
1276     TestSimulateInputEvent(keyEvent);
1277 #endif // OHOS_BUILD_ENABLE_KEYBOARD
1278 }
1279 
1280 /**
1281  * @tc.name: InputManagerTest_MouseEventEnterAndLeave_003
1282  * @tc.desc: Verify that the home button and mouse leave the window
1283  * @tc.type: FUNC
1284  * @tc.require: I5HMF3 I5HMEF
1285  */
1286 HWTEST_F(InputManagerTest, InputManagerTest_MouseEventEnterAndLeave_003, TestSize.Level1)
1287 {
1288     CALL_DEBUG_ENTER;
1289     std::shared_ptr<KeyEvent> keyEvent { SetupKeyEvent003() };
1290     ASSERT_TRUE(keyEvent != nullptr);
1291 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
1292     TestSimulateInputEvent(keyEvent);
1293 #endif // OHOS_BUILD_ENABLE_KEYBOARD
1294 }
1295 
1296 /**
1297  * @tc.name: InputManagerTest_MouseEventEnterAndLeave_004
1298  * @tc.desc: Verify that the mouse moves to the navigation bar to leave the window
1299  * @tc.type: FUNC
1300  * @tc.require: I5HMF3 I5HMEF
1301  */
1302 HWTEST_F(InputManagerTest, InputManagerTest_MouseEventEnterAndLeave_004, TestSize.Level1)
1303 {
1304     CALL_DEBUG_ENTER;
1305     std::shared_ptr<PointerEvent> pointerEvent { SetupPointerEvent015() };
1306     ASSERT_TRUE(pointerEvent != nullptr);
1307 #ifdef OHOS_BUILD_ENABLE_POINTER
1308     TestSimulateInputEvent(pointerEvent);
1309 #endif // OHOS_BUILD_ENABLE_POINTER
1310 }
1311 
1312 /**
1313  * @tc.name: MultimodalEventHandler_SimulatePencil2Event_001
1314  * @tc.desc: Verify simulate pencil2 down event
1315  * @tc.type: FUNC
1316  * @tc.require:
1317  */
1318 HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePencil2Event_001, TestSize.Level1)
1319 {
1320     CALL_DEBUG_ENTER;
1321     std::shared_ptr<PointerEvent> pointerEvent { SetupPointerEvent011() };
1322     ASSERT_TRUE(pointerEvent != nullptr);
1323 #ifdef OHOS_BUILD_ENABLE_TOUCH
1324     TestSimulateInputEvent(pointerEvent);
1325 #endif // OHOS_BUILD_ENABLE_TOUCH
1326 }
1327 
1328 /**
1329  * @tc.name: MultimodalEventHandler_SimulatePencil2Event_002
1330  * @tc.desc: Verify simulate pencil2 move event
1331  * @tc.type: FUNC
1332  * @tc.require:
1333  */
1334 HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePencil2Event_002, TestSize.Level1)
1335 {
1336     CALL_DEBUG_ENTER;
1337     std::shared_ptr<PointerEvent> pointerEvent { SetupPointerEvent012() };
1338     ASSERT_TRUE(pointerEvent != nullptr);
1339 #ifdef OHOS_BUILD_ENABLE_TOUCH
1340     TestSimulateInputEvent(pointerEvent);
1341 #endif // OHOS_BUILD_ENABLE_TOUCH
1342 }
1343 
1344 /**
1345  * @tc.name: MultimodalEventHandler_SimulatePencil2Event_003
1346  * @tc.desc: Verify simulate pencil2 up event
1347  * @tc.type: FUNC
1348  * @tc.require:
1349  */
1350 HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePencil2Event_003, TestSize.Level1)
1351 {
1352     CALL_DEBUG_ENTER;
1353     std::shared_ptr<PointerEvent> pointerEvent { SetupPointerEvent013() };
1354     ASSERT_TRUE(pointerEvent != nullptr);
1355 #ifdef OHOS_BUILD_ENABLE_TOUCH
1356     TestSimulateInputEvent(pointerEvent);
1357 #endif // OHOS_BUILD_ENABLE_TOUCH
1358 }
1359 
1360 /**
1361  * @tc.name: InputManager_Pencil2InputEvent_004
1362  * @tc.desc: Verify simulate exception event
1363  * @tc.type: FUNC
1364  * @tc.require:
1365  */
1366 HWTEST_F(InputManagerTest, InputManager_Pencil2InputEvent_004, TestSize.Level1)
1367 {
1368     CALL_DEBUG_ENTER;
1369     auto pointerEvent = PointerEvent::Create();
1370     ASSERT_TRUE(pointerEvent != nullptr);
1371     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
1372     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
1373     pointerEvent->SetPointerId(-1);
1374 #ifdef OHOS_BUILD_ENABLE_TOUCH
1375     TestSimulateInputEvent(pointerEvent, TestScene::EXCEPTION_TEST);
1376 #endif // OHOS_BUILD_ENABLE_TOUCH
1377 }
1378 
1379 /**
1380  * @tc.name: InputManager_NotResponse_001
1381  * @tc.desc: detection of not response
1382  * @tc.type: FUNC
1383  * @tc.require:AR000GJG6G
1384  */
1385 HWTEST_F(InputManagerTest, InputManager_NotResponse_001, TestSize.Level1)
1386 {
1387     CALL_DEBUG_ENTER;
1388     auto keyEventTest = PointerEvent::Create();
1389     ASSERT_NE(keyEventTest, nullptr);
1390 
1391     PointerEvent::PointerItem item;
1392     item.SetPointerId(0);
1393     item.SetDisplayX(523);
1394     item.SetPressure(5);
1395     item.SetDisplayY(723);
1396     keyEventTest->AddPointerItem(item);
1397     keyEventTest->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
1398     keyEventTest->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
1399     keyEventTest->SetPointerId(0);
1400     InputManager::GetInstance()->SimulateInputEvent(keyEventTest);
1401     InputManager::GetInstance()->SimulateInputEvent(keyEventTest);
1402     InputManager::GetInstance()->SimulateInputEvent(keyEventTest);
1403 }
1404 
1405 /**
1406  * @tc.name: InputManager_NotResponse_002
1407  * @tc.desc: detection of not response
1408  * @tc.type: FUNC
1409  * @tc.require:SR000GGN6G
1410  */
1411 HWTEST_F(InputManagerTest, InputManager_NotResponse_002, TestSize.Level1)
1412 {
1413     CALL_DEBUG_ENTER;
1414     auto pointerEvent = PointerEvent::Create();
1415     ASSERT_NE(pointerEvent, nullptr);
1416 
1417     PointerEvent::PointerItem item;
1418     item.SetPressure(5);
1419     item.SetPointerId(0);
1420     item.SetDisplayX(523);
1421     item.SetDisplayY(723);
1422     pointerEvent->SetPointerId(0);
1423     pointerEvent->AddPointerItem(item);
1424     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
1425     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
1426     InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
1427     InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
1428     InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
1429 }
1430 
1431 /**
1432  * @tc.name: InputManagerTest_SubscribeKeyEvent_001
1433  * @tc.desc: Verify invalid parameter.
1434  * @tc.type: FUNC
1435  * @tc.require:SR000GGQL4  AR000GJNGN
1436  * @tc.author: yangguang
1437  */
1438 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_001, TestSize.Level1)
1439 {
1440     CALL_DEBUG_ENTER;
1441     std::set<int32_t> preKeys;
1442     std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
1443     keyOption->SetPreKeys(preKeys);
1444     keyOption->SetFinalKey(KeyEvent::KEYCODE_VOLUME_MUTE);
1445     keyOption->SetFinalKeyDown(true);
1446     keyOption->SetFinalKeyDownDuration(0);
1447     int32_t response = -1;
1448     response = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, nullptr);
1449     EXPECT_TRUE(response < 0);
1450     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1451     InputManager::GetInstance()->UnsubscribeKeyEvent(response);
1452 }
1453 
1454 /**
1455  * @tc.name: InputManagerTest_SubscribeKeyEvent_02
1456  * @tc.desc: Verify subscribe power key event.
1457  * @tc.type: FUNC
1458  * @tc.require:SR000GGQL4  AR000GJNGN
1459  * @tc.author: zhaoxueyuan
1460  */
1461 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_02, TestSize.Level1)
1462 {
1463     CALL_DEBUG_ENTER;
1464     ASSERT_TRUE(MMIEventHdl.InitClient());
1465     // 电源键长按按下订阅
1466     std::set<int32_t> preKeys;
1467     std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
1468     keyOption->SetPreKeys(preKeys);
1469     keyOption->SetFinalKey(KeyEvent::KEYCODE_POWER);
1470     keyOption->SetFinalKeyDown(true);
1471     keyOption->SetFinalKeyDownDuration(2000);
1472     int32_t subscribeId1 = -1;
1473     subscribeId1 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption,
__anonebfd6e530402(std::shared_ptr<KeyEvent> keyEvent) 1474         [](std::shared_ptr<KeyEvent> keyEvent) {
1475         EventLogHelper::PrintEventData(keyEvent);
1476         MMI_HILOGD("Subscribe key event KEYCODE_POWER down trigger callback");
1477     });
1478 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
1479     EXPECT_TRUE(subscribeId1 >= 0);
1480 #else
1481     EXPECT_TRUE(subscribeId1 < 0);
1482 #endif // OHOS_BUILD_ENABLE_KEYBOARD
1483 
1484     // 电源键抬起订阅
1485     std::shared_ptr<KeyOption> keyOption2 = std::make_shared<KeyOption>();
1486     keyOption2->SetPreKeys(preKeys);
1487     keyOption2->SetFinalKey(KeyEvent::KEYCODE_POWER);
1488     keyOption2->SetFinalKeyDown(false);
1489     keyOption2->SetFinalKeyDownDuration(0);
1490     int32_t subscribeId2 = -1;
1491     subscribeId2 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption2,
__anonebfd6e530502(std::shared_ptr<KeyEvent> keyEvent) 1492         [](std::shared_ptr<KeyEvent> keyEvent) {
1493         EventLogHelper::PrintEventData(keyEvent);
1494         MMI_HILOGD("Subscribe key event KEYCODE_POWER up trigger callback");
1495     });
1496 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
1497     EXPECT_TRUE(subscribeId2 >= 0);
1498 #else
1499     EXPECT_TRUE(subscribeId2 < 0);
1500 #endif // OHOS_BUILD_ENABLE_KEYBOARD
1501 
1502     std::this_thread::sleep_for(std::chrono::milliseconds(1000));
1503     InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId1);
1504     InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId2);
1505     std::this_thread::sleep_for(std::chrono::milliseconds(1000));
1506 }
1507 
1508 /**
1509  * @tc.name: InputManagerTest_SubscribeKeyEvent_03
1510  * @tc.desc: Verify subscribe volume up key event.
1511  * @tc.type: FUNC
1512  * @tc.require:
1513  */
1514 HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_03, TestSize.Level1)
1515 {
1516     CALL_DEBUG_ENTER;
1517     ASSERT_TRUE(MMIEventHdl.InitClient());
1518     std::set<int32_t> preKeys;
1519     std::shared_ptr<KeyOption> keyOption1 = std::make_shared<KeyOption>();
1520     keyOption1->SetPreKeys(preKeys);
1521     keyOption1->SetFinalKey(KeyEvent::KEYCODE_VOLUME_UP);
1522     keyOption1->SetFinalKeyDown(true);
1523     keyOption1->SetFinalKeyDownDuration(10);
1524     int32_t subscribeId1 = -1;
1525     subscribeId1 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption1,
__anonebfd6e530602(std::shared_ptr<KeyEvent> keyEvent) 1526         [](std::shared_ptr<KeyEvent> keyEvent) {
1527         EventLogHelper::PrintEventData(keyEvent);
1528         MMI_HILOGD("Subscribe key event KEYCODE_VOLUME_UP down trigger callback");
1529     });
1530     std::shared_ptr<KeyOption> keyOption2 = std::make_shared<KeyOption>();
1531     keyOption2->SetPreKeys(preKeys);
1532     keyOption2->SetFinalKey(KeyEvent::KEYCODE_VOLUME_UP);
1533     keyOption2->SetFinalKeyDown(false);
1534     keyOption2->SetFinalKeyDownDuration(0);
1535     int32_t subscribeId2 = -1;
1536     subscribeId2 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption2,
__anonebfd6e530702(std::shared_ptr<KeyEvent> keyEvent) 1537         [](std::shared_ptr<KeyEvent> keyEvent) {
1538         EventLogHelper::PrintEventData(keyEvent);
1539         MMI_HILOGD("Subscribe key event KEYCODE_VOLUME_UP up trigger callback");
1540     });
1541     std::shared_ptr<KeyOption> keyOption3 = std::make_shared<KeyOption>();
1542     keyOption3->SetPreKeys(preKeys);
1543     keyOption3->SetFinalKey(KeyEvent::KEYCODE_VOLUME_UP);
1544     keyOption3->SetFinalKeyDown(true);
1545     keyOption3->SetFinalKeyDownDuration(0);
1546     int32_t subscribeId3 = -1;
1547     subscribeId3 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption3,
__anonebfd6e530802(std::shared_ptr<KeyEvent> keyEvent) 1548         [](std::shared_ptr<KeyEvent> keyEvent) {
1549         EventLogHelper::PrintEventData(keyEvent);
1550         MMI_HILOGD("Subscribe key event KEYCODE_VOLUME_UP down trigger callback");
1551     });
1552     std::shared_ptr<KeyOption> keyOption4 = std::make_shared<KeyOption>();
1553     keyOption4->SetPreKeys(preKeys);
1554     keyOption4->SetFinalKey(KeyEvent::KEYCODE_VOLUME_UP);
1555     keyOption4->SetFinalKeyDown(false);
1556     keyOption4->SetFinalKeyDownDuration(0);
1557     int32_t subscribeId4 = -1;
1558     subscribeId4 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption4,
__anonebfd6e530902(std::shared_ptr<KeyEvent> keyEvent) 1559         [](std::shared_ptr<KeyEvent> keyEvent) {
1560         EventLogHelper::PrintEventData(keyEvent);
1561         MMI_HILOGD("Subscribe key event KEYCODE_VOLUME_UP up trigger callback");
1562     });
1563 
1564     std::this_thread::sleep_for(std::chrono::milliseconds(1000));
1565     InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId1);
1566     InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId2);
1567     InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId3);
1568     InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId4);
1569     std::this_thread::sleep_for(std::chrono::milliseconds(1000));
1570 }
1571 
1572 /**
1573  * @tc.name: TestGetKeystrokeAbility_001
1574  * @tc.desc: Verify SupportKeys
1575  * @tc.type: FUNC
1576  * @tc.require:
1577  */
1578 HWTEST_F(InputManagerTest, TestGetKeystrokeAbility_001, TestSize.Level1)
1579 {
1580     CALL_DEBUG_ENTER;
1581     std::vector<int32_t> keyCodes = {17, 22, 2055};
__anonebfd6e530a02(std::vector<bool> keystrokeAbility) 1582     InputManager::GetInstance()->SupportKeys(0, keyCodes, [](std::vector<bool> keystrokeAbility) {
1583         MMI_HILOGD("TestGetKeystrokeAbility_001 callback ok");
1584     });
1585     MMI_HILOGD("Stop TestGetKeystrokeAbility_001");
1586 }
1587 
1588 /**
1589  * @tc.name: TestInputEventInterceptor_001
1590  * @tc.desc: Verify mouse down event interceptor
1591  * @tc.type: FUNC
1592  * @tc.require:
1593  */
1594 HWTEST_F(InputManagerTest, TestInputEventInterceptor_001, TestSize.Level1)
1595 {
1596     CALL_DEBUG_ENTER;
1597     auto pointerEvent = PointerEvent::Create();
1598     ASSERT_TRUE(pointerEvent != nullptr);
1599     PointerEvent::PointerItem item;
1600     item.SetDownTime(10010);
1601     item.SetPointerId(DEFAULT_POINTER_ID);
1602     item.SetPressed(true);
1603     pointerEvent->AddPointerItem(item);
1604     item.SetDisplayY(723);
1605     item.SetDisplayX(523);
1606     item.SetDeviceId(1);
1607     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
1608     pointerEvent->SetPointerId(DEFAULT_POINTER_ID);
1609     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
1610 
1611     auto interceptor = GetPtr<InputEventCallback>();
1612     int32_t interceptorId { InputManager::GetInstance()->AddInterceptor(interceptor) };
1613 #ifdef OHOS_BUILD_ENABLE_INTERCEPTOR
1614     EXPECT_TRUE(IsValidHandlerId(interceptorId));
1615 #else
1616     EXPECT_EQ(interceptorId, ERROR_UNSUPPORT);
1617 #endif // OHOS_BUILD_ENABLE_INTERCEPTOR
1618     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1619 
1620 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_INTERCEPTOR)
1621     TestSimulateInputEvent(pointerEvent);
1622 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_INTERCEPTOR
1623 
1624     if (IsValidHandlerId(interceptorId)) {
1625         InputManager::GetInstance()->RemoveInterceptor(interceptorId);
1626         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1627     }
1628 }
1629 
1630 /**
1631  * @tc.name: TestInputEventInterceptor_002
1632  * @tc.desc: Verify mouse move event interceptor
1633  * @tc.type: FUNC
1634  * @tc.require:
1635  */
1636 HWTEST_F(InputManagerTest, TestInputEventInterceptor_002, TestSize.Level1)
1637 {
1638     CALL_DEBUG_ENTER;
1639     auto pointerEvent = PointerEvent::Create();
1640     ASSERT_TRUE(pointerEvent != nullptr);
1641     PointerEvent::PointerItem item;
1642     item.SetPointerId(DEFAULT_POINTER_ID);
1643     item.SetDisplayX(523);
1644     item.SetDisplayY(723);
1645     item.SetDeviceId(1);
1646     item.SetDownTime(10010);
1647     pointerEvent->AddPointerItem(item);
1648     item.SetPressed(true);
1649     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
1650     pointerEvent->SetPointerId(DEFAULT_POINTER_ID);
1651     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
1652 
1653     auto interceptor = GetPtr<InputEventCallback>();
1654     int32_t interceptorId { InputManager::GetInstance()->AddInterceptor(interceptor) };
1655 #ifdef OHOS_BUILD_ENABLE_INTERCEPTOR
1656     EXPECT_TRUE(IsValidHandlerId(interceptorId));
1657 #else
1658     EXPECT_EQ(interceptorId, ERROR_UNSUPPORT);
1659 #endif // OHOS_BUILD_ENABLE_INTERCEPTOR
1660     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1661 
1662 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_INTERCEPTOR)
1663     TestSimulateInputEvent(pointerEvent);
1664 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_INTERCEPTOR
1665 
1666     if (IsValidHandlerId(interceptorId)) {
1667         InputManager::GetInstance()->RemoveInterceptor(interceptorId);
1668         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1669     }
1670 }
1671 
1672 /**
1673  * @tc.name: TestInputEventInterceptor_003
1674  * @tc.desc: Verify mouse up event interceptor
1675  * @tc.type: FUNC
1676  * @tc.require:
1677  */
1678 HWTEST_F(InputManagerTest, TestInputEventInterceptor_003, TestSize.Level1)
1679 {
1680     CALL_DEBUG_ENTER;
1681     auto pointerEvent = PointerEvent::Create();
1682     ASSERT_TRUE(pointerEvent != nullptr);
1683     PointerEvent::PointerItem item;
1684     item.SetPointerId(DEFAULT_POINTER_ID);
1685     item.SetDownTime(10010);
1686     item.SetPressed(true);
1687     item.SetDisplayX(523);
1688     item.SetDisplayY(723);
1689     item.SetDeviceId(1);
1690     pointerEvent->AddPointerItem(item);
1691     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
1692     pointerEvent->SetPointerId(DEFAULT_POINTER_ID);
1693     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
1694 
1695     auto interceptor = GetPtr<InputEventCallback>();
1696     int32_t interceptorId { InputManager::GetInstance()->AddInterceptor(interceptor) };
1697 #ifdef OHOS_BUILD_ENABLE_INTERCEPTOR
1698     EXPECT_TRUE(IsValidHandlerId(interceptorId));
1699 #else
1700     EXPECT_EQ(interceptorId, ERROR_UNSUPPORT);
1701 #endif // OHOS_BUILD_ENABLE_INTERCEPTOR
1702     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1703 
1704 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_INTERCEPTOR)
1705     TestSimulateInputEvent(pointerEvent);
1706 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_INTERCEPTOR
1707 
1708     if (IsValidHandlerId(interceptorId)) {
1709         InputManager::GetInstance()->RemoveInterceptor(interceptorId);
1710         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1711     }
1712 }
1713 
1714 /**
1715  * @tc.name: TestInputEventInterceptor_004
1716  * @tc.desc: Verify multiple interceptor
1717  * @tc.type: FUNC
1718  * @tc.require:
1719  */
1720 HWTEST_F(InputManagerTest, TestInputEventInterceptor_004, TestSize.Level1)
1721 {
1722     CALL_DEBUG_ENTER;
1723     TestUtil->SetRecvFlag(RECV_FLAG::RECV_INTERCEPT);
1724     auto pointerEvent = PointerEvent::Create();
1725     ASSERT_TRUE(pointerEvent != nullptr);
1726     PointerEvent::PointerItem item;
1727     item.SetPointerId(0);
1728     item.SetDownTime(10010);
1729     item.SetPressed(true);
1730     item.SetDisplayX(523);
1731     item.SetDisplayY(723);
1732     item.SetDeviceId(1);
1733     pointerEvent->AddPointerItem(item);
1734     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
1735     pointerEvent->SetPointerId(0);
1736     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD);
1737 
1738     const std::vector<int32_t>::size_type N_TEST_CASES { 3 };
1739     std::vector<int32_t> ids(N_TEST_CASES);
1740     auto interceptor = GetPtr<InputEventCallback>();
1741 
1742     for (std::vector<int32_t>::size_type i = 0; i < N_TEST_CASES; ++i) {
1743         ids[i] = InputManager::GetInstance()->AddInterceptor(interceptor);
1744 #ifdef OHOS_BUILD_ENABLE_INTERCEPTOR
1745         EXPECT_TRUE(IsValidHandlerId(ids[i]));
1746 #else
1747         EXPECT_EQ(ids[i], ERROR_UNSUPPORT);
1748 #endif // OHOS_BUILD_ENABLE_INTERCEPTOR
1749         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1750     }
1751 
1752     InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
1753 
1754     for (const auto &id : ids) {
1755         std::string sPointerEs = InputManagerTest::GetEventDump();
1756         MMI_HILOGD("sPointerEs:%{public}s", sPointerEs.c_str());
1757 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_INTERCEPTOR)
1758         ASSERT_TRUE(!sPointerEs.empty());
1759 #else
1760         ASSERT_TRUE(sPointerEs.empty());
1761 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_INTERCEPTOR
1762         if (IsValidHandlerId(id)) {
1763             InputManager::GetInstance()->RemoveInterceptor(id);
1764         }
1765         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1766     }
1767 }
1768 
1769 /**
1770  * @tc.name: TestInputEventInterceptor_005
1771  * @tc.desc: Verify mouse button interceptor
1772  * @tc.type: FUNC
1773  * @tc.require:
1774  */
1775 HWTEST_F(InputManagerTest, TestInputEventInterceptor_005, TestSize.Level1)
1776 {
1777     CALL_DEBUG_ENTER;
1778     auto pointerEvent = PointerEvent::Create();
1779     ASSERT_TRUE(pointerEvent != nullptr);
1780     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
1781     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN);
1782     pointerEvent->SetButtonId(PointerEvent::MOUSE_BUTTON_LEFT);
1783     pointerEvent->SetPointerId(DEFAULT_POINTER_ID);
1784     pointerEvent->SetButtonPressed(PointerEvent::MOUSE_BUTTON_LEFT);
1785     PointerEvent::PointerItem item;
1786     item.SetPointerId(DEFAULT_POINTER_ID);
1787     item.SetDownTime(GetNanoTime() / NANOSECOND_TO_MILLISECOND);
1788     item.SetPressed(true);
1789     item.SetDisplayX(200);
1790     item.SetDisplayY(300);
1791     pointerEvent->AddPointerItem(item);
1792 
1793     auto interceptor = GetPtr<InputEventCallback>();
1794     int32_t interceptorId { InputManager::GetInstance()->AddInterceptor(interceptor) };
1795 #ifdef OHOS_BUILD_ENABLE_INTERCEPTOR
1796     EXPECT_TRUE(IsValidHandlerId(interceptorId));
1797 #else
1798     EXPECT_EQ(interceptorId, ERROR_UNSUPPORT);
1799 #endif // OHOS_BUILD_ENABLE_INTERCEPTOR
1800     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1801 
1802 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_INTERCEPTOR)
1803     TestSimulateInputEvent(pointerEvent);
1804 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_INTERCEPTOR
1805 
1806     if (IsValidHandlerId(interceptorId)) {
1807         InputManager::GetInstance()->RemoveInterceptor(interceptorId);
1808         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1809     }
1810 }
1811 
1812 /**
1813  * @tc.name: TestInputEventInterceptor_006
1814  * @tc.desc: Verify touchscreen interceptor
1815  * @tc.type: FUNC
1816  * @tc.require:
1817  */
1818 HWTEST_F(InputManagerTest, TestInputEventInterceptor_006, TestSize.Level1)
1819 {
1820     CALL_DEBUG_ENTER;
1821     auto pointerEvent = PointerEvent::Create();
1822     ASSERT_TRUE(pointerEvent != nullptr);
1823     PointerEvent::PointerItem item;
1824     item.SetPointerId(0);   // test code,set the PointerId = 0
1825     item.SetDisplayX(523);   // test code,set the DisplayX = 523
1826     item.SetDisplayY(723);   // test code,set the DisplayY = 723
1827     item.SetPressure(5);    // test code,set the Pressure = 5
1828     item.SetDeviceId(1);    // test code,set the DeviceId = 1
1829     pointerEvent->AddPointerItem(item);
1830     item.SetPointerId(1);   // test code,set the PointerId = 1
1831     item.SetDisplayX(710);   // test code,set the DisplayX = 710
1832     item.SetDisplayY(910);   // test code,set the DisplayY = 910
1833     item.SetPressure(7);    // test code,set the Pressure = 7
1834     item.SetDeviceId(1);    // test code,set the DeviceId = 1
1835     pointerEvent->AddPointerItem(item);
1836     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
1837     pointerEvent->SetPointerId(1);  // test code,set the PointerId = 1
1838     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
1839 
1840     auto interceptor = GetPtr<InputEventCallback>();
1841     int32_t interceptorId { InputManager::GetInstance()->AddInterceptor(interceptor) };
1842 #ifdef OHOS_BUILD_ENABLE_INTERCEPTOR
1843     EXPECT_TRUE(IsValidHandlerId(interceptorId));
1844 #else
1845     EXPECT_EQ(interceptorId, ERROR_UNSUPPORT);
1846 #endif // OHOS_BUILD_ENABLE_INTERCEPTOR
1847     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1848 
1849 #if defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_INTERCEPTOR)
1850     TestSimulateInputEvent(pointerEvent);
1851 #endif // OHOS_BUILD_ENABLE_TOUCH && OHOS_BUILD_ENABLE_INTERCEPTOR
1852 
1853     if (IsValidHandlerId(interceptorId)) {
1854         InputManager::GetInstance()->RemoveInterceptor(interceptorId);
1855         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1856     }
1857 }
1858 
1859 /**
1860  * @tc.name: TestInputEventInterceptor_007
1861  * @tc.desc: Verify key interceptor
1862  * @tc.type: FUNC
1863  * @tc.require:
1864  */
1865 HWTEST_F(InputManagerTest, TestInputEventInterceptor_007, TestSize.Level1)
1866 {
1867     CALL_DEBUG_ENTER;
1868     std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
1869     ASSERT_TRUE(injectDownEvent != nullptr);
1870     int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
1871     KeyEvent::KeyItem kitDown;
1872     kitDown.SetKeyCode(KeyEvent::KEYCODE_BACK);
1873     kitDown.SetPressed(true);
1874     kitDown.SetDownTime(downTime);
1875     injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_BACK);
1876     injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
1877     injectDownEvent->AddPressedKeyItems(kitDown);
1878 
1879     auto interceptor = GetPtr<InputEventCallback>();
1880     int32_t interceptorId { InputManager::GetInstance()->AddInterceptor(interceptor) };
1881 #ifdef OHOS_BUILD_ENABLE_INTERCEPTOR
1882     EXPECT_TRUE(IsValidHandlerId(interceptorId));
1883 #else
1884     EXPECT_EQ(interceptorId, ERROR_UNSUPPORT);
1885 #endif // OHOS_BUILD_ENABLE_INTERCEPTOR
1886     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1887 
1888 #if defined(OHOS_BUILD_ENABLE_KEYBOARD) && defined(OHOS_BUILD_ENABLE_INTERCEPTOR)
1889     TestSimulateInputEvent(injectDownEvent);
1890 #endif // OHOS_BUILD_ENABLE_KEYBOARD
1891 
1892     if (IsValidHandlerId(interceptorId)) {
1893         InputManager::GetInstance()->RemoveInterceptor(interceptorId);
1894         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1895     }
1896 }
1897 
1898 /**
1899  * @tc.name: TestInputEventInterceptor_008
1900  * @tc.desc: Verify touchscreen interceptor
1901  * @tc.type: FUNC
1902  * @tc.require:
1903  */
1904 HWTEST_F(InputManagerTest, TestInputEventInterceptor_008, TestSize.Level1)
1905 {
1906     CALL_DEBUG_ENTER;
1907     TestUtil->SetRecvFlag(RECV_FLAG::RECV_INTERCEPT);
1908     auto keyEvent = PointerEvent::Create();
1909     ASSERT_TRUE(keyEvent != nullptr);
1910     PointerEvent::PointerItem item;
1911     item.SetPointerId(0);
1912     item.SetDownTime(10010);
1913     item.SetPressed(true);
1914     item.SetDisplayX(523);
1915     item.SetDisplayY(723);
1916     item.SetDeviceId(1);
1917     keyEvent->AddPointerItem(item);
1918     keyEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
1919     keyEvent->SetPointerId(0);
1920     keyEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
1921 
1922     auto interceptor = GetPtr<InputEventCallback>();
1923     int32_t interceptorId = InputManager::GetInstance()->AddInterceptor(interceptor);
1924 #ifdef OHOS_BUILD_ENABLE_INTERCEPTOR
1925     EXPECT_TRUE(IsValidHandlerId(interceptorId));
1926 #else
1927     EXPECT_EQ(interceptorId, ERROR_UNSUPPORT);
1928 #endif // OHOS_BUILD_ENABLE_INTERCEPTOR
1929     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1930 
1931     InputManager::GetInstance()->SimulateInputEvent(keyEvent);
1932 
1933     std::string sPointerEs = InputManagerTest::GetEventDump();
1934     MMI_HILOGD("sPointerEs:%{public}s", sPointerEs.c_str());
1935 #if defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_INTERCEPTOR)
1936     ASSERT_TRUE(!sPointerEs.empty());
1937 #else
1938     ASSERT_TRUE(sPointerEs.empty());
1939 #endif // OHOS_BUILD_ENABLE_TOUCH && OHOS_BUILD_ENABLE_INTERCEPTOR
1940     if (IsValidHandlerId(interceptorId)) {
1941         InputManager::GetInstance()->RemoveInterceptor(interceptorId);
1942         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1943     }
1944 }
1945 
1946 /**
1947  * @tc.name: TestInputEventInterceptor_009
1948  * @tc.desc: Verify mouse interceptor
1949  * @tc.type: FUNC
1950  * @tc.require:
1951  */
1952 HWTEST_F(InputManagerTest, TestInputEventInterceptor_009, TestSize.Level1)
1953 {
1954     CALL_DEBUG_ENTER;
1955     TestUtil->SetRecvFlag(RECV_FLAG::RECV_INTERCEPT);
1956     auto pointerEvent = PointerEvent::Create();
1957     ASSERT_TRUE(pointerEvent != nullptr);
1958     PointerEvent::PointerItem item;
1959     item.SetPointerId(0);
1960     item.SetDownTime(10010);
1961     item.SetPressed(true);
1962     item.SetDisplayX(523);
1963     item.SetDisplayY(723);
1964     item.SetDeviceId(1);
1965     pointerEvent->AddPointerItem(item);
1966     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
1967     pointerEvent->SetPointerId(0);
1968     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
1969 
1970     auto interceptor = GetPtr<InputEventCallback>();
1971     int32_t interceptorId = InputManager::GetInstance()->AddInterceptor(interceptor);
1972 #ifdef OHOS_BUILD_ENABLE_INTERCEPTOR
1973     EXPECT_TRUE(IsValidHandlerId(interceptorId));
1974 #else
1975     EXPECT_EQ(interceptorId, ERROR_UNSUPPORT);
1976 #endif // OHOS_BUILD_ENABLE_INTERCEPTOR
1977     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1978 
1979     InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
1980 
1981     std::string sPointerEs = InputManagerTest::GetEventDump();
1982     MMI_HILOGD("sPointerEs:%{public}s", sPointerEs.c_str());
1983 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_INTERCEPTOR)
1984     ASSERT_TRUE(!sPointerEs.empty());
1985 #else
1986     ASSERT_TRUE(sPointerEs.empty());
1987 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_INTERCEPTOR
1988     if (IsValidHandlerId(interceptorId)) {
1989         InputManager::GetInstance()->RemoveInterceptor(interceptorId);
1990         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
1991     }
1992 }
1993 
1994 /**
1995  * @tc.name: TestInputEventInterceptor_010
1996  * @tc.desc: Verify volume key interceptor
1997  * @tc.type: FUNC
1998  * @tc.require:
1999  */
2000 HWTEST_F(InputManagerTest, TestInputEventInterceptor_010, TestSize.Level1)
2001 {
2002     CALL_DEBUG_ENTER;
2003     TestUtil->SetRecvFlag(RECV_FLAG::RECV_INTERCEPT);
2004     std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
2005     ASSERT_TRUE(injectDownEvent != nullptr);
2006     int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
2007     KeyEvent::KeyItem kitDown;
2008     kitDown.SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
2009     kitDown.SetPressed(true);
2010     kitDown.SetDownTime(downTime);
2011     injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
2012     injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
2013     injectDownEvent->AddPressedKeyItems(kitDown);
2014 
2015     auto interceptor = GetPtr<InputEventCallback>();
2016     int32_t interceptorId { InputManager::GetInstance()->AddInterceptor(interceptor) };
2017 #ifdef OHOS_BUILD_ENABLE_INTERCEPTOR
2018     EXPECT_TRUE(IsValidHandlerId(interceptorId));
2019 #else
2020     EXPECT_EQ(interceptorId, ERROR_UNSUPPORT);
2021 #endif // OHOS_BUILD_ENABLE_INTERCEPTOR
2022     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2023 
2024     InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
2025 
2026     std::string sPointerEs = InputManagerTest::GetEventDump();
2027     MMI_HILOGD("sPointerEs:%{public}s", sPointerEs.c_str());
2028 #if defined(OHOS_BUILD_ENABLE_KEYBOARD) && defined(OHOS_BUILD_ENABLE_INTERCEPTOR)
2029     ASSERT_TRUE(!sPointerEs.empty());
2030 #else
2031     ASSERT_TRUE(sPointerEs.empty());
2032 #endif // OHOS_BUILD_ENABLE_KEYBOARD && OHOS_BUILD_ENABLE_INTERCEPTOR
2033     if (IsValidHandlerId(interceptorId)) {
2034         InputManager::GetInstance()->RemoveInterceptor(interceptorId);
2035         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2036     }
2037 }
2038 
2039 /**
2040  * @tc.name: TestInputEventInterceptor_011
2041  * @tc.desc: Verify space key interceptor
2042  * @tc.type: FUNC
2043  * @tc.require:
2044  */
2045 HWTEST_F(InputManagerTest, TestInputEventInterceptor_011, TestSize.Level1)
2046 {
2047     CALL_DEBUG_ENTER;
2048     TestUtil->SetRecvFlag(RECV_FLAG::RECV_INTERCEPT);
2049     std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
2050     ASSERT_TRUE(injectDownEvent != nullptr);
2051     int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
2052     KeyEvent::KeyItem kitDown;
2053     kitDown.SetKeyCode(KeyEvent::KEYCODE_SPACE);
2054     kitDown.SetPressed(true);
2055     kitDown.SetDownTime(downTime);
2056     injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_SPACE);
2057     injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
2058     injectDownEvent->AddPressedKeyItems(kitDown);
2059 
2060     auto interceptor = GetPtr<InputEventCallback>();
2061     int32_t interceptorId { InputManager::GetInstance()->AddInterceptor(interceptor) };
2062 #ifdef OHOS_BUILD_ENABLE_INTERCEPTOR
2063     EXPECT_TRUE(IsValidHandlerId(interceptorId));
2064 #else
2065     EXPECT_EQ(interceptorId, ERROR_UNSUPPORT);
2066 #endif // OHOS_BUILD_ENABLE_INTERCEPTOR
2067     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2068 
2069     InputManager::GetInstance()->SimulateInputEvent(injectDownEvent);
2070 
2071     std::string sPointerEs = InputManagerTest::GetEventDump();
2072     MMI_HILOGD("sPointerEs:%{public}s", sPointerEs.c_str());
2073 #if defined(OHOS_BUILD_ENABLE_KEYBOARD) && defined(OHOS_BUILD_ENABLE_INTERCEPTOR)
2074     ASSERT_TRUE(!sPointerEs.empty());
2075 #else
2076     ASSERT_TRUE(sPointerEs.empty());
2077 #endif // OHOS_BUILD_ENABLE_KEYBOARD && OHOS_BUILD_ENABLE_INTERCEPTOR
2078     if (IsValidHandlerId(interceptorId)) {
2079         InputManager::GetInstance()->RemoveInterceptor(interceptorId);
2080         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2081     }
2082 }
2083 
2084 /**
2085  * @tc.name: TestInputEventInterceptor_012
2086  * @tc.desc: Verify keyevent interceptor
2087  * @tc.type: FUNC
2088  * @tc.require:
2089  */
2090 HWTEST_F(InputManagerTest, TestInputEventInterceptor_012, TestSize.Level1)
2091 {
2092     CALL_DEBUG_ENTER;
__anonebfd6e530b02(std::shared_ptr<KeyEvent> keyEvent) 2093     auto fun = [](std::shared_ptr<KeyEvent> keyEvent) {
2094         MMI_HILOGD("Add interceptor success");
2095     };
2096     int32_t interceptorId = InputManager::GetInstance()->AddInterceptor(fun);
2097 #if defined(OHOS_BUILD_ENABLE_KEYBOARD) && defined(OHOS_BUILD_ENABLE_INTERCEPTOR)
2098     ASSERT_NE(interceptorId, INVALID_HANDLER_ID);
2099 #else
2100     ASSERT_EQ(interceptorId, ERROR_UNSUPPORT);
2101 #endif // OHOS_BUILD_ENABLE_KEYBOARD && OHOS_BUILD_ENABLE_INTERCEPTOR
2102     if (IsValidHandlerId(interceptorId)) {
2103         InputManager::GetInstance()->RemoveInterceptor(interceptorId);
2104     }
2105 }
2106 
2107 /**
2108  * @tc.name: InputManagerTest_OnAddScreenMonitor_001
2109  * @tc.desc: Verify touchscreen down event monitor
2110  * @tc.type: FUNC
2111  * @tc.require:
2112  */
2113 HWTEST_F(InputManagerTest, InputManagerTest_OnAddScreenMonitor_001, TestSize.Level1)
2114 {
2115     CALL_DEBUG_ENTER;
2116     auto pointerEventTest = SetupPointerEvent001();
2117     ASSERT_TRUE(pointerEventTest != nullptr);
2118 
2119     auto callbackPtr = GetPtr<InputEventCallback>();
2120     ASSERT_TRUE(callbackPtr != nullptr);
2121     int32_t monitorIdTest = TestAddMonitor(callbackPtr);
2122 #ifdef OHOS_BUILD_ENABLE_MONITOR
2123     EXPECT_TRUE(IsValidHandlerId(monitorIdTest));
2124 #else
2125     EXPECT_EQ(monitorIdTest, ERROR_UNSUPPORT);
2126 #endif // OHOS_BUILD_ENABLE_MONITOR
2127     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2128 
2129 #if defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR)
2130     TestSimulateInputEvent(pointerEventTest);
2131 #endif // OHOS_BUILD_ENABLE_TOUCH && OHOS_BUILD_ENABLE_MONITOR
2132 
2133     if (IsValidHandlerId(monitorIdTest)) {
2134         TestRemoveMonitor(monitorIdTest);
2135         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2136     }
2137 }
2138 
2139 /**
2140  * @tc.name: InputManagerTest_OnAddScreenMonitor_002
2141  * @tc.desc: Verify touchscreen move event multiple monitor
2142  * @tc.type: FUNC
2143  * @tc.require:
2144  */
2145 HWTEST_F(InputManagerTest, InputManagerTest_OnAddScreenMonitor_002, TestSize.Level1)
2146 {
2147     CALL_DEBUG_ENTER;
2148     TestUtil->SetRecvFlag(RECV_FLAG::RECV_MONITOR);
2149     const std::vector<int32_t>::size_type N_TEST_CASES { 3 };
2150     std::vector<int32_t> ids(N_TEST_CASES);
2151     std::vector<std::shared_ptr<InputEventCallback>> cbs(N_TEST_CASES);
2152 
2153     for (std::vector<int32_t>::size_type i = 0; i < N_TEST_CASES; i++) {
2154         cbs[i] = GetPtr<InputEventCallback>();
2155         ASSERT_TRUE(cbs[i] != nullptr);
2156         ids[i] = TestAddMonitor(cbs[i]);
2157 #ifdef OHOS_BUILD_ENABLE_MONITOR
2158         EXPECT_TRUE(IsValidHandlerId(ids[i]));
2159 #else
2160         EXPECT_EQ(ids[i], ERROR_UNSUPPORT);
2161 #endif // OHOS_BUILD_ENABLE_MONITOR
2162         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2163     }
2164 
2165     auto pointerEvent = SetupPointerEvent002();
2166     InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2167 
2168     for (const auto &id : ids) {
2169         std::string sPointerEs = InputManagerTest::GetEventDump();
2170         MMI_HILOGD("sPointerEs:%{public}s", sPointerEs.c_str());
2171 #if defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR)
2172         ASSERT_TRUE(!sPointerEs.empty());
2173 #else
2174         ASSERT_TRUE(sPointerEs.empty());
2175 #endif // OHOS_BUILD_ENABLE_TOUCH && OHOS_BUILD_ENABLE_MONITOR
2176         if (IsValidHandlerId(id)) {
2177             TestRemoveMonitor(id);
2178         }
2179         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2180     }
2181 }
2182 
2183 /**
2184  * @tc.name: InputManagerTest_OnAddScreenMonitor_003
2185  * @tc.desc: Verify touchscreen up event monitor
2186  * @tc.type: FUNC
2187  * @tc.require:
2188  */
2189 HWTEST_F(InputManagerTest, InputManagerTest_OnAddScreenMonitor_003, TestSize.Level1)
2190 {
2191     CALL_DEBUG_ENTER;
2192     auto pointerEvent = SetupPointerEvent003();
2193     ASSERT_TRUE(pointerEvent != nullptr);
2194 
2195     auto callbackPtr = GetPtr<InputEventCallback>();
2196     ASSERT_TRUE(callbackPtr != nullptr);
2197     int32_t monitorId = TestAddMonitor(callbackPtr);
2198 #ifdef OHOS_BUILD_ENABLE_MONITOR
2199     EXPECT_TRUE(IsValidHandlerId(monitorId));
2200 #else
2201     EXPECT_EQ(monitorId, ERROR_UNSUPPORT);
2202 #endif // OHOS_BUILD_ENABLE_MONITOR
2203     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2204 
2205 #if defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR)
2206     TestSimulateInputEvent(pointerEvent);
2207 #endif // OHOS_BUILD_ENABLE_TOUCH && OHOS_BUILD_ENABLE_MONITOR
2208 
2209     if (IsValidHandlerId(monitorId)) {
2210         TestRemoveMonitor(monitorId);
2211         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2212     }
2213 }
2214 
2215 /**
2216  * @tc.name: InputManagerTest_OnAddScreenMonitor_004
2217  * @tc.desc: Verify touchscreen MarkConsumed
2218  * @tc.type: FUNC
2219  * @tc.require:
2220  */
2221 HWTEST_F(InputManagerTest, InputManagerTest_OnAddScreenMonitor_004, TestSize.Level1)
2222 {
2223     CALL_DEBUG_ENTER;
2224     auto callbackPtr = GetPtr<InputEventCallback>();
2225     ASSERT_TRUE(callbackPtr != nullptr);
2226     int32_t monitorId = TestAddMonitor(callbackPtr);
2227 #ifdef OHOS_BUILD_ENABLE_MONITOR
2228     EXPECT_TRUE(IsValidHandlerId(monitorId));
2229 #else
2230     EXPECT_EQ(monitorId, ERROR_UNSUPPORT);
2231 #endif // OHOS_BUILD_ENABLE_MONITOR
2232     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2233 
2234     TestMarkConsumedStep1();
2235     auto pointerEvent = TestMarkConsumedStep2();
2236 
2237     TestMarkConsumedStep3(monitorId, callbackPtr->GetLastEventId());
2238 
2239     TestMarkConsumedStep4();
2240     TestMarkConsumedStep5();
2241 
2242     if (IsValidHandlerId(monitorId)) {
2243         TestRemoveMonitor(monitorId);
2244         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2245     }
2246 }
2247 
2248 /**
2249  * @tc.name: InputManagerTest_OnAddScreenMonitor_005
2250  * @tc.desc:  Verify touchscreen MarkConsumed
2251  * @tc.type: FUNC
2252  * @tc.require:
2253  */
2254 HWTEST_F(InputManagerTest, InputManagerTest_OnAddScreenMonitor_005, TestSize.Level1)
2255 {
2256     CALL_DEBUG_ENTER;
2257     auto callbackPtr = GetPtr<InputEventCallback>();
2258     ASSERT_TRUE(callbackPtr != nullptr);
2259     int32_t monitorId = TestAddMonitor(callbackPtr);
2260 #ifdef OHOS_BUILD_ENABLE_MONITOR
2261     EXPECT_TRUE(IsValidHandlerId(monitorId));
2262 #else
2263     EXPECT_EQ(monitorId, ERROR_UNSUPPORT);
2264 #endif // OHOS_BUILD_ENABLE_MONITOR
2265     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2266 
2267     auto pointerEvent = TestMarkConsumedStep1();
2268 
2269     TestMarkConsumedStep3(monitorId, callbackPtr->GetLastEventId());
2270 
2271     TestMarkConsumedStep4();
2272     TestMarkConsumedStep6();
2273 
2274     if (IsValidHandlerId(monitorId)) {
2275         TestRemoveMonitor(monitorId);
2276         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2277     }
2278 }
2279 
2280 /**
2281  * @tc.name: InputManagerTest_OnAddTouchPadMonitor_001
2282  * @tc.desc: Verify touchpad down event monitor
2283  * @tc.type: FUNC
2284  * @tc.require:
2285  */
2286 HWTEST_F(InputManagerTest, InputManagerTest_OnAddTouchPadMonitor_001, TestSize.Level1)
2287 {
2288     CALL_DEBUG_ENTER;
2289     auto pointerEvent = PointerEvent::Create();
2290     ASSERT_TRUE(pointerEvent != nullptr);
2291     PointerEvent::PointerItem item;
2292     item.SetPointerId(0);
2293     item.SetDownTime(10010);
2294     item.SetPressed(true);
2295     item.SetDisplayX(523);
2296     item.SetDisplayY(723);
2297     item.SetDeviceId(1);
2298     pointerEvent->AddPointerItem(item);
2299     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
2300     pointerEvent->SetPointerId(0);
2301     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
2302 
2303     auto callbackPtr = GetPtr<InputEventCallback>();
2304     ASSERT_TRUE(callbackPtr != nullptr);
2305     int32_t monitorId = TestAddMonitor(callbackPtr);
2306 #ifdef OHOS_BUILD_ENABLE_MONITOR
2307     EXPECT_TRUE(IsValidHandlerId(monitorId));
2308 #else
2309     EXPECT_EQ(monitorId, ERROR_UNSUPPORT);
2310 #endif // OHOS_BUILD_ENABLE_MONITOR
2311     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2312 
2313 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_MONITOR)
2314     TestSimulateInputEvent(pointerEvent);
2315 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_MONITOR
2316 
2317     if (IsValidHandlerId(monitorId)) {
2318         TestRemoveMonitor(monitorId);
2319         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2320     }
2321 }
2322 
2323 /**
2324  * @tc.name: InputManagerTest_OnAddTouchPadMonitor_002
2325  * @tc.desc: Verify touchpad move event monitor
2326  * @tc.type: FUNC
2327  * @tc.require:
2328  */
2329 HWTEST_F(InputManagerTest, InputManagerTest_OnAddTouchPadMonitor_002, TestSize.Level1)
2330 {
2331     CALL_DEBUG_ENTER;
2332     auto pointerEvent = PointerEvent::Create();
2333     ASSERT_TRUE(pointerEvent != nullptr);
2334     PointerEvent::PointerItem item;
2335     item.SetPointerId(0);
2336     item.SetDownTime(10010);
2337     item.SetPressed(true);
2338     item.SetDisplayX(523);
2339     item.SetDisplayY(723);
2340     item.SetDeviceId(1);
2341     pointerEvent->AddPointerItem(item);
2342     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
2343     pointerEvent->SetPointerId(0);
2344     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
2345 
2346     auto callbackPtr = GetPtr<InputEventCallback>();
2347     ASSERT_TRUE(callbackPtr != nullptr);
2348     int32_t monitorId = TestAddMonitor(callbackPtr);
2349 #ifdef OHOS_BUILD_ENABLE_MONITOR
2350     EXPECT_TRUE(IsValidHandlerId(monitorId));
2351 #else
2352     EXPECT_EQ(monitorId, ERROR_UNSUPPORT);
2353 #endif // OHOS_BUILD_ENABLE_MONITOR
2354     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2355 
2356 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_MONITOR)
2357     TestSimulateInputEvent(pointerEvent);
2358 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_MONITOR
2359 
2360     if (IsValidHandlerId(monitorId)) {
2361         TestRemoveMonitor(monitorId);
2362         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2363     }
2364 }
2365 
2366 /**
2367  * @tc.name: InputManagerTest_OnAddTouchPadMonitor_003
2368  * @tc.desc: Verify touchpad up event monitor
2369  * @tc.type: FUNC
2370  * @tc.require:
2371  */
2372 HWTEST_F(InputManagerTest, InputManagerTest_OnAddTouchPadMonitor_003, TestSize.Level1)
2373 {
2374     CALL_DEBUG_ENTER;
2375     auto pointerEvent = PointerEvent::Create();
2376     ASSERT_TRUE(pointerEvent != nullptr);
2377     PointerEvent::PointerItem item;
2378     item.SetDownTime(10010);
2379     item.SetPointerId(0);
2380     item.SetPressed(true);
2381     item.SetDisplayY(723);
2382     item.SetDisplayX(523);
2383     item.SetDeviceId(1);
2384     pointerEvent->AddPointerItem(item);
2385     pointerEvent->SetPointerId(0);
2386     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
2387     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
2388     auto callbackPtr = GetPtr<InputEventCallback>();
2389     ASSERT_TRUE(callbackPtr != nullptr);
2390     int32_t monitorId = TestAddMonitor(callbackPtr);
2391 #ifdef OHOS_BUILD_ENABLE_MONITOR
2392     EXPECT_TRUE(IsValidHandlerId(monitorId));
2393 #else
2394     EXPECT_EQ(monitorId, ERROR_UNSUPPORT);
2395 #endif // OHOS_BUILD_ENABLE_MONITOR
2396     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2397 
2398 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_MONITOR)
2399     TestSimulateInputEvent(pointerEvent);
2400 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_MONITOR
2401 
2402     if (IsValidHandlerId(monitorId)) {
2403         TestRemoveMonitor(monitorId);
2404         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2405     }
2406 }
2407 
2408 /**
2409  * @tc.name: InputManagerTest_OnAddTouchPadMonitor_004
2410  * @tc.desc: Verify touchpad multiple monitor
2411  * @tc.type: FUNC
2412  * @tc.require:
2413  */
2414 HWTEST_F(InputManagerTest, InputManagerTest_OnAddTouchPadMonitor_004, TestSize.Level1)
2415 {
2416     CALL_DEBUG_ENTER;
2417     TestUtil->SetRecvFlag(RECV_FLAG::RECV_MONITOR);
2418     auto pointerEvent = PointerEvent::Create();
2419     ASSERT_TRUE(pointerEvent != nullptr);
2420     PointerEvent::PointerItem item;
2421     item.SetPressed(true);
2422     item.SetPointerId(0);
2423     item.SetDownTime(10010);
2424     item.SetDisplayX(523);
2425     item.SetDeviceId(1);
2426     item.SetDisplayY(723);
2427     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
2428     pointerEvent->AddPointerItem(item);
2429     pointerEvent->SetPointerId(0);
2430     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
2431 
2432     const std::vector<int32_t>::size_type N_TEST_CASES { 3 };
2433     std::vector<int32_t> ids(N_TEST_CASES);
2434     auto callbackPtr = GetPtr<InputEventCallback>();
2435     ASSERT_TRUE(callbackPtr != nullptr);
2436     for (std::vector<int32_t>::size_type i = 0; i < N_TEST_CASES; ++i) {
2437         ids[i] = TestAddMonitor(callbackPtr);
2438 #ifdef OHOS_BUILD_ENABLE_MONITOR
2439         EXPECT_TRUE(IsValidHandlerId(ids[i]));
2440 #else
2441         EXPECT_EQ(ids[i], ERROR_UNSUPPORT);
2442 #endif // OHOS_BUILD_ENABLE_MONITOR
2443         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2444     }
2445 
2446     InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2447 
2448     for (const auto &id : ids) {
2449         std::string sPointerEs = InputManagerTest::GetEventDump();
2450         MMI_HILOGD("sPointerEs:%{public}s", sPointerEs.c_str());
2451 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_MONITOR)
2452         ASSERT_TRUE(!sPointerEs.empty());
2453 #else
2454         ASSERT_TRUE(sPointerEs.empty());
2455 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_MONITOR
2456         if (IsValidHandlerId(id)) {
2457             TestRemoveMonitor(id);
2458         }
2459         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2460     }
2461 }
2462 
2463 /**
2464  * @tc.name: InputManagerTest_OnAddTouchPadMonitor_005
2465  * @tc.desc: Verify touchpad monitor
2466  * @tc.type: FUNC
2467  * @tc.require:
2468  */
2469 HWTEST_F(InputManagerTest, InputManagerTest_OnAddTouchPadMonitor_005, TestSize.Level1)
2470 {
2471     CALL_DEBUG_ENTER;
2472     auto pointerEvent = PointerEvent::Create();
2473     ASSERT_TRUE(pointerEvent != nullptr);
2474     PointerEvent::PointerItem item;
2475     item.SetPointerId(0);
2476     item.SetDeviceId(1);
2477     item.SetDownTime(10010);
2478     item.SetPressed(true);
2479     item.SetDisplayX(523);
2480     item.SetDisplayY(723);
2481     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
2482     pointerEvent->AddPointerItem(item);
2483     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
2484     pointerEvent->SetPointerId(0);
2485 
2486     auto callbackPtr = GetPtr<InputEventCallback>();
2487     ASSERT_TRUE(callbackPtr != nullptr);
2488     int32_t monitorId = TestAddMonitor(callbackPtr);
2489 #ifdef OHOS_BUILD_ENABLE_MONITOR
2490     EXPECT_TRUE(IsValidHandlerId(monitorId));
2491 #else
2492     EXPECT_EQ(monitorId, ERROR_UNSUPPORT);
2493 #endif // OHOS_BUILD_ENABLE_MONITOR
2494     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2495 
2496 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_MONITOR)
2497     TestSimulateInputEvent(pointerEvent);
2498 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_MONITOR
2499 
2500     if (IsValidHandlerId(monitorId)) {
2501         TestRemoveMonitor(monitorId);
2502         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2503     }
2504 }
2505 
2506 /**
2507  * @tc.name: InputManager_TouchPadSimulateInputEvent_001
2508  * @tc.desc: Verify touchpad simulate and monitor
2509  * @tc.type: FUNC
2510  * @tc.require:
2511  */
2512 HWTEST_F(InputManagerTest, InputManager_TouchPadSimulateInputEvent_001, TestSize.Level1)
2513 {
2514     CALL_DEBUG_ENTER;
2515     auto callbackPtr = GetPtr<InputEventCallback>();
2516     ASSERT_TRUE(callbackPtr != nullptr);
2517     int32_t monitorId { TestAddMonitor(callbackPtr) };
2518 #ifdef OHOS_BUILD_ENABLE_MONITOR
2519     EXPECT_TRUE(monitorId >= MIN_HANDLER_ID);
2520 #else
2521     EXPECT_EQ(monitorId, ERROR_UNSUPPORT);
2522 #endif // OHOS_BUILD_ENABLE_MONITOR
2523     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2524 
2525     int64_t actionTime = GetSysClockTime();
2526     auto pointerEvent = PointerEvent::Create();
2527     ASSERT_TRUE(pointerEvent != nullptr);
2528     PointerEvent::PointerItem item {};
2529     item.SetPointerId(DEFAULT_POINTER_ID);
2530     item.SetDownTime(actionTime);
2531     item.SetPressed(true);
2532     item.SetDisplayX(523);
2533     item.SetDisplayY(723);
2534     item.SetDeviceId(DEFAULT_DEVICE_ID);
2535     pointerEvent->AddPointerItem(item);
2536     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
2537     pointerEvent->SetActionTime(actionTime);
2538     pointerEvent->SetPointerId(DEFAULT_POINTER_ID);
2539     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
2540 
2541 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_MONITOR)
2542     TestSimulateInputEvent(pointerEvent);
2543 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_MONITOR
2544 
2545     if (IsValidHandlerId(monitorId)) {
2546         TestRemoveMonitor(monitorId);
2547         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2548     }
2549 }
2550 
2551 /**
2552  * @tc.name: InputManager_TouchPadSimulateInputEvent_002
2553  * @tc.desc: Verify touchpad simulate and monitor
2554  * @tc.type: FUNC
2555  * @tc.require:
2556  */
2557 HWTEST_F(InputManagerTest, InputManager_TouchPadSimulateInputEvent_002, TestSize.Level1)
2558 {
2559     CALL_DEBUG_ENTER;
2560     auto callbackPtr = GetPtr<InputEventCallback>();
2561     ASSERT_TRUE(callbackPtr != nullptr);
2562     int32_t monitorId { TestAddMonitor(callbackPtr) };
2563 #ifdef OHOS_BUILD_ENABLE_MONITOR
2564     EXPECT_TRUE(monitorId >= MIN_HANDLER_ID);
2565 #else
2566     EXPECT_EQ(monitorId, ERROR_UNSUPPORT);
2567 #endif // OHOS_BUILD_ENABLE_MONITOR
2568     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2569 
2570     int64_t actionTime = GetSysClockTime();
2571     auto pointerEvent = PointerEvent::Create();
2572     ASSERT_TRUE(pointerEvent != nullptr);
2573     PointerEvent::PointerItem item {};
2574     item.SetPointerId(DEFAULT_POINTER_ID);
2575     item.SetDownTime(actionTime);
2576     item.SetPressed(true);
2577     item.SetDisplayX(700);
2578     item.SetDisplayY(610);
2579     item.SetDeviceId(DEFAULT_DEVICE_ID);
2580     pointerEvent->AddPointerItem(item);
2581     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
2582     pointerEvent->SetActionTime(actionTime);
2583     pointerEvent->SetPointerId(DEFAULT_POINTER_ID);
2584     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
2585 
2586 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_MONITOR)
2587     TestSimulateInputEvent(pointerEvent);
2588 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_MONITOR
2589 
2590     if (IsValidHandlerId(monitorId)) {
2591         TestRemoveMonitor(monitorId);
2592         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2593     }
2594 }
2595 
2596 /**
2597  * @tc.name: InputManager_TouchPadSimulateInputEvent_003
2598  * @tc.desc: Verify touchpad simulate and monitor
2599  * @tc.type: FUNC
2600  * @tc.require:
2601  */
2602 HWTEST_F(InputManagerTest, InputManager_TouchPadSimulateInputEvent_003, TestSize.Level1)
2603 {
2604     CALL_DEBUG_ENTER;
2605     auto callbackPtr = GetPtr<InputEventCallback>();
2606     ASSERT_TRUE(callbackPtr != nullptr);
2607     int32_t monitorId { TestAddMonitor(callbackPtr) };
2608 #ifdef OHOS_BUILD_ENABLE_MONITOR
2609     EXPECT_TRUE(monitorId >= MIN_HANDLER_ID);
2610 #else
2611     EXPECT_EQ(monitorId, ERROR_UNSUPPORT);
2612 #endif // OHOS_BUILD_ENABLE_MONITOR
2613     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2614 
2615     int64_t actionTime = GetSysClockTime();
2616     auto pointerEvent = PointerEvent::Create();
2617     ASSERT_TRUE(pointerEvent != nullptr);
2618     PointerEvent::PointerItem item {};
2619     item.SetPointerId(DEFAULT_POINTER_ID);
2620     item.SetDownTime(actionTime);
2621     item.SetPressed(false);
2622     item.SetDisplayX(50);
2623     item.SetDisplayY(50);
2624     item.SetDeviceId(DEFAULT_DEVICE_ID);
2625     pointerEvent->AddPointerItem(item);
2626     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
2627     pointerEvent->SetActionTime(actionTime);
2628     pointerEvent->SetPointerId(DEFAULT_POINTER_ID);
2629     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
2630 
2631 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_MONITOR)
2632     TestSimulateInputEvent(pointerEvent);
2633 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_MONITOR
2634 
2635     if (IsValidHandlerId(monitorId)) {
2636         TestRemoveMonitor(monitorId);
2637         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2638     }
2639 }
2640 
2641 /**
2642  * @tc.name: InputManager_TouchPadSimulateInputEvent_004
2643  * @tc.desc: Verify touchpad simulate and monitor
2644  * @tc.type: FUNC
2645  * @tc.require:
2646  */
2647 HWTEST_F(InputManagerTest, InputManager_TouchPadSimulateInputEvent_004, TestSize.Level1)
2648 {
2649     CALL_DEBUG_ENTER;
2650     auto callbackPtr = GetPtr<InputEventCallback>();
2651     ASSERT_TRUE(callbackPtr != nullptr);
2652     int32_t monitorId { TestAddMonitor(callbackPtr) };
2653 #ifdef OHOS_BUILD_ENABLE_MONITOR
2654     EXPECT_TRUE(monitorId >= MIN_HANDLER_ID);
2655 #else
2656     EXPECT_EQ(monitorId, ERROR_UNSUPPORT);
2657 #endif // OHOS_BUILD_ENABLE_MONITOR
2658     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2659 
2660     int64_t actionTime = GetSysClockTime();
2661     auto pointerEvent = PointerEvent::Create();
2662     ASSERT_TRUE(pointerEvent != nullptr);
2663     PointerEvent::PointerItem item {};
2664     item.SetPointerId(DEFAULT_POINTER_ID);
2665     item.SetDownTime(actionTime);
2666     item.SetPressed(true);
2667     item.SetDisplayX(523);
2668     item.SetDisplayY(723);
2669     item.SetDeviceId(DEFAULT_DEVICE_ID);
2670     pointerEvent->AddPointerItem(item);
2671     item.SetPointerId(1);
2672     item.SetDownTime(actionTime);
2673     item.SetPressed(true);
2674     item.SetDisplayX(540);
2675     item.SetDisplayY(740);
2676     item.SetDeviceId(DEFAULT_DEVICE_ID);
2677     pointerEvent->AddPointerItem(item);
2678     item.SetPointerId(2);
2679     item.SetDownTime(actionTime);
2680     item.SetPressed(true);
2681     item.SetDisplayX(560);
2682     item.SetDisplayY(760);
2683     item.SetDeviceId(DEFAULT_DEVICE_ID);
2684     pointerEvent->AddPointerItem(item);
2685     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
2686     pointerEvent->SetActionTime(actionTime);
2687     pointerEvent->SetPointerId(DEFAULT_POINTER_ID);
2688     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
2689 
2690 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_MONITOR)
2691     TestSimulateInputEvent(pointerEvent);
2692 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_MONITOR
2693 
2694     if (IsValidHandlerId(monitorId)) {
2695         TestRemoveMonitor(monitorId);
2696         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2697     }
2698 }
2699 
2700 /**
2701  * @tc.name: InputManagerTest_AddMouseMonitor_001
2702  * @tc.desc: Verify mouse down event monitor
2703  * @tc.type: FUNC
2704  * @tc.require:
2705  */
2706 HWTEST_F(InputManagerTest, InputManagerTest_AddMouseMonitor_001, TestSize.Level1)
2707 {
2708     CALL_DEBUG_ENTER;
2709     auto callbackPtr = GetPtr<InputEventCallback>();
2710     ASSERT_TRUE(callbackPtr != nullptr);
2711     int32_t monitorId = TestAddMonitor(callbackPtr);
2712 #ifdef OHOS_BUILD_ENABLE_MONITOR
2713     EXPECT_TRUE(IsValidHandlerId(monitorId));
2714 #else
2715     EXPECT_EQ(monitorId, ERROR_UNSUPPORT);
2716 #endif // OHOS_BUILD_ENABLE_MONITOR
2717     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2718 
2719     auto pointerEvent = SetupPointerEvent005();
2720 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_MONITOR)
2721     TestSimulateInputEvent(pointerEvent);
2722 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_MONITOR
2723 
2724     if (IsValidHandlerId(monitorId)) {
2725         TestRemoveMonitor(monitorId);
2726         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2727     }
2728 }
2729 
2730 /**
2731  * @tc.name: InputManagerTest_AddMouseMonitor_002
2732  * @tc.desc: Verify mouse move event monitor
2733  * @tc.type: FUNC
2734  * @tc.require:
2735  */
2736 HWTEST_F(InputManagerTest, InputManagerTest_AddMouseMonitor_002, TestSize.Level1)
2737 {
2738     CALL_DEBUG_ENTER;
2739     auto callbackPtr = GetPtr<InputEventCallback>();
2740     ASSERT_TRUE(callbackPtr != nullptr);
2741     int32_t monitorId = TestAddMonitor(callbackPtr);
2742 #ifdef OHOS_BUILD_ENABLE_MONITOR
2743     EXPECT_TRUE(IsValidHandlerId(monitorId));
2744 #else
2745     EXPECT_EQ(monitorId, ERROR_UNSUPPORT);
2746 #endif // OHOS_BUILD_ENABLE_MONITOR
2747     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2748 
2749     auto pointerEvent = SetupPointerEvent006();
2750 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_MONITOR)
2751     TestSimulateInputEvent(pointerEvent);
2752 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_MONITOR
2753 
2754     if (IsValidHandlerId(monitorId)) {
2755         TestRemoveMonitor(monitorId);
2756         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2757     }
2758 
2759 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_MONITOR)
2760     TestSimulateInputEvent(pointerEvent, TestScene::EXCEPTION_TEST);
2761 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_MONITOR
2762 }
2763 
2764 /**
2765  * @tc.name: InputManagerTest_AddMouseMonitor_003
2766  * @tc.desc: Verify mouse up event monitor
2767  * @tc.type: FUNC
2768  * @tc.require:
2769  */
2770 HWTEST_F(InputManagerTest, InputManagerTest_AddMouseMonitor_003, TestSize.Level1)
2771 {
2772     CALL_DEBUG_ENTER;
2773     auto callbackPtr = GetPtr<InputEventCallback>();
2774     ASSERT_TRUE(callbackPtr != nullptr);
2775     int32_t monitorId = TestAddMonitor(callbackPtr);
2776 #ifdef OHOS_BUILD_ENABLE_MONITOR
2777     EXPECT_TRUE(IsValidHandlerId(monitorId));
2778 #else
2779     EXPECT_EQ(monitorId, ERROR_UNSUPPORT);
2780 #endif // OHOS_BUILD_ENABLE_MONITOR
2781     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2782 
2783     auto pointerEvent = SetupPointerEvent007();
2784     ASSERT_TRUE(pointerEvent != nullptr);
2785 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_MONITOR)
2786     TestSimulateInputEvent(pointerEvent);
2787 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_MONITOR
2788 
2789     if (IsValidHandlerId(monitorId)) {
2790         TestRemoveMonitor(monitorId);
2791         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2792     }
2793 }
2794 
2795 /**
2796  * @tc.name: InputManagerTest_AddMouseMonitor_004
2797  * @tc.desc: Verify monitor upper limit
2798  * @tc.type: FUNC
2799  * @tc.require:
2800  */
2801 HWTEST_F(InputManagerTest, InputManagerTest_AddMouseMonitor_004, TestSize.Level1)
2802 {
2803     CALL_DEBUG_ENTER;
2804     TestUtil->SetRecvFlag(RECV_FLAG::RECV_MONITOR);
2805     const std::vector<int32_t>::size_type N_TEST_CASES { MAX_N_INPUT_HANDLERS - 1 };
2806     std::vector<int32_t> ids;
2807     int32_t maxMonitor = 0;
2808 
2809     for (std::vector<int32_t>::size_type i = 0; i < N_TEST_CASES; ++i) {
2810         auto callbackPtr = GetPtr<InputEventCallback>();
2811         ASSERT_TRUE(callbackPtr != nullptr);
2812         maxMonitor = TestAddMonitor(callbackPtr);
2813         if (IsValidHandlerId(maxMonitor)) {
2814             ids.push_back(maxMonitor);
2815             std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2816         }
2817     }
2818 
2819     auto pointerEvent = SetupPointerEvent007();
2820     ASSERT_TRUE(pointerEvent != nullptr);
2821     InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
2822     maxMonitor = 0;
2823     for (const auto &id : ids) {
2824         if (!InputManagerTest::GetEventDump().empty()) {
2825             maxMonitor++;
2826         }
2827         if (IsValidHandlerId(id)) {
2828             TestRemoveMonitor(id);
2829             std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2830         }
2831     }
2832 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_MONITOR)
2833     ASSERT_EQ(maxMonitor, ids.size());
2834 #else
2835     ASSERT_EQ(maxMonitor, 0);
2836 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_MONITOR
2837 }
2838 
2839 /**
2840  * @tc.name: InputManagerTest_OnAddKeyboardMonitor_001
2841  * @tc.desc: Verify Keyboard multiple monitor
2842  * @tc.type: FUNC
2843  * @tc.require:
2844  */
2845 HWTEST_F(InputManagerTest, InputManagerTest_OnAddKeyboardMonitor_001, TestSize.Level1)
2846 {
2847     CALL_DEBUG_ENTER;
2848     TestUtil->SetRecvFlag(RECV_FLAG::RECV_MONITOR);
2849     const std::vector<int32_t>::size_type N_TEST_CASES { 3 };
2850     std::vector<int32_t> ids;
2851     auto callbackPtr = GetPtr<InputEventCallback>();
2852     ASSERT_TRUE(callbackPtr != nullptr);
2853     for (std::vector<int32_t>::size_type i = 0; i < N_TEST_CASES; ++i) {
2854         int32_t id = TestAddMonitor(callbackPtr);
2855         if (IsValidHandlerId(id)) {
2856             ids.push_back(id);
2857             std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2858         }
2859     }
2860 
2861     auto injectEvent = SetupKeyEvent001();
2862     ASSERT_TRUE(injectEvent != nullptr);
2863     InputManager::GetInstance()->SimulateInputEvent(injectEvent);
2864 
2865     for (const auto &id : ids) {
2866         std::string sPointerEs = InputManagerTest::GetEventDump();
2867         MMI_HILOGD("sPointerEs:%{public}s", sPointerEs.c_str());
2868 #if defined(OHOS_BUILD_ENABLE_KEYBOARD) && defined(OHOS_BUILD_ENABLE_MONITOR)
2869         ASSERT_TRUE(!sPointerEs.empty());
2870 #else
2871         ASSERT_TRUE(sPointerEs.empty());
2872 #endif // OHOS_BUILD_ENABLE_KEYBOARD && OHOS_BUILD_ENABLE_MONITOR
2873         if (IsValidHandlerId(id)) {
2874             TestRemoveMonitor(id);
2875         }
2876         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2877     }
2878 }
2879 
2880 /**
2881  * @tc.name: InputManagerTest_OnAddKeyboardMonitor_002
2882  * @tc.desc: Verify Keyboard multiple monitor
2883  * @tc.type: FUNC
2884  * @tc.require:
2885  */
2886 HWTEST_F(InputManagerTest, InputManagerTest_OnAddKeyboardMonitor_002, TestSize.Level1)
2887 {
2888     CALL_DEBUG_ENTER;
2889     const std::vector<int32_t>::size_type N_TEST_CASES { 3 };
2890     std::vector<int32_t> ids;
2891     auto callbackPtr = GetPtr<InputEventCallback>();
2892     ASSERT_TRUE(callbackPtr != nullptr);
2893     for (std::vector<int32_t>::size_type i = 0; i < N_TEST_CASES; ++i) {
2894         int32_t id = TestAddMonitor(callbackPtr);
2895         if (IsValidHandlerId(id)) {
2896             ids.push_back(id);
2897             std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2898         }
2899     }
2900 
2901     auto injectEvent = SetupKeyEvent001();
2902     ASSERT_TRUE(injectEvent != nullptr);
2903     injectEvent->SetKeyCode(KeyEvent::KEYCODE_UNKNOWN);
2904     InputManager::GetInstance()->SimulateInputEvent(injectEvent);
2905 
2906     for (const auto &id : ids) {
2907         std::string sPointerEs = InputManagerTest::GetEventDump();
2908         MMI_HILOGD("sPointerEs:%{public}s", sPointerEs.c_str());
2909         ASSERT_TRUE(sPointerEs.empty());
2910         if (IsValidHandlerId(id)) {
2911             TestRemoveMonitor(id);
2912         }
2913         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
2914     }
2915 }
2916 
2917 /**
2918  * @tc.name: InputManagerTest_RemoteControlAutoRepeat
2919  * @tc.desc: After the key is pressed, repeatedly trigger the key to press the input
2920  * @tc.type: FUNC
2921  * @tc.require: I530XB
2922  */
2923 HWTEST_F(InputManagerTest, InputManagerTest_RemoteControlAutoRepeat, TestSize.Level1)
2924 {
2925     CALL_DEBUG_ENTER;
2926     int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
2927     std::shared_ptr<KeyEvent> injectDownEvent = KeyEvent::Create();
2928     ASSERT_TRUE(injectDownEvent != nullptr);
2929     KeyEvent::KeyItem kitDown;
2930     kitDown.SetKeyCode(KeyEvent::KEYCODE_A);
2931     kitDown.SetPressed(true);
2932     kitDown.SetDownTime(downTime);
2933     injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_A);
2934     injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
2935     injectDownEvent->AddPressedKeyItems(kitDown);
2936 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
2937     TestSimulateInputEvent(injectDownEvent);
2938 #endif // OHOS_BUILD_ENABLE_KEYBOARD
2939 
2940     std::this_thread::sleep_for(std::chrono::milliseconds(1000));
2941 
2942     std::shared_ptr<KeyEvent> injectUpEvent = KeyEvent::Create();
2943     ASSERT_TRUE(injectUpEvent != nullptr);
2944     downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND;
2945     KeyEvent::KeyItem kitUp;
2946     kitUp.SetKeyCode(KeyEvent::KEYCODE_A);
2947     kitUp.SetPressed(false);
2948     kitUp.SetDownTime(downTime);
2949     injectUpEvent->SetKeyCode(KeyEvent::KEYCODE_A);
2950     injectUpEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
2951     injectUpEvent->RemoveReleasedKeyItems(kitUp);
2952 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
2953     TestSimulateInputEvent(injectUpEvent);
2954 #endif // OHOS_BUILD_ENABLE_KEYBOARD
2955 }
2956 
2957 /**
2958  * @tc.name: InputManagerTest_MoveMouse_01
2959  * @tc.desc: Verify move mouse
2960  * @tc.type: FUNC
2961  * @tc.require:
2962  */
2963 HWTEST_F(InputManagerTest, InputManagerTest_MoveMouse_01, TestSize.Level1)
2964 {
2965     CALL_DEBUG_ENTER;
2966     InputManager::GetInstance()->MoveMouse(50, 50);
2967 }
2968 
2969 /**
2970  * @tc.name: InputManagerTest_MoveMouse_02
2971  * @tc.desc: Verify move mouse
2972  * @tc.type: FUNC
2973  * @tc.require:
2974  */
2975 HWTEST_F(InputManagerTest, InputManagerTest_MoveMouse_02, TestSize.Level1)
2976 {
2977     CALL_DEBUG_ENTER;
2978     InputManager::GetInstance()->MoveMouse(-1000, 100);
2979 }
2980 
2981 static int32_t deviceIDtest = 0;
GetKeyboardTypeCallback(int32_t keyboardType)2982 static void GetKeyboardTypeCallback(int32_t keyboardType)
2983 {
2984     switch (keyboardType) {
2985         case KEYBOARD_TYPE_NONE: {
2986             MMI_HILOGD("deviceIDtest:%{public}d-->KeyboardType:%{public}s", deviceIDtest, "None");
2987             break;
2988             }
2989         case KEYBOARD_TYPE_UNKNOWN: {
2990             MMI_HILOGD("deviceIDtest:%{public}d-->KeyboardType:%{public}s", deviceIDtest, "unknown");
2991             break;
2992         }
2993         case KEYBOARD_TYPE_ALPHABETICKEYBOARD: {
2994             MMI_HILOGD("deviceIDtest:%{public}d-->KeyboardType:%{public}s", deviceIDtest, "alphabetickeyboard");
2995             break;
2996         }
2997         case KEYBOARD_TYPE_DIGITALKEYBOARD: {
2998             MMI_HILOGD("deviceIDtest:%{public}d-->KeyboardType:%{public}s", deviceIDtest, "digitalkeyboard");
2999             break;
3000         }
3001         case KEYBOARD_TYPE_HANDWRITINGPEN: {
3002             MMI_HILOGD("deviceIDtest:%{public}d-->KeyboardType:%{public}s", deviceIDtest, "handwritingpen");
3003             break;
3004         }
3005         case KEYBOARD_TYPE_REMOTECONTROL: {
3006             MMI_HILOGD("deviceIDtest:%{public}d-->KeyboardType:%{public}s", deviceIDtest, "remotecontrol");
3007             break;
3008         }
3009         default: {
3010             MMI_HILOGW("Error obtaining keyboard type");
3011             break;
3012         }
3013     }
3014 }
3015 
3016 /**
3017  * @tc.name: InputManagerTest_GetKeyboardType
3018  * @tc.desc: Verify Get Keyboard Type
3019  * @tc.type: FUNC
3020  * @tc.require:
3021  */
3022 HWTEST_F(InputManagerTest, InputManagerTest_GetKeyboardType, TestSize.Level1)
3023 {
3024     MMI_HILOGD("Start InputManagerTest_GetKeyboardType");
3025     for (int32_t i = 0; i < 20; ++i)
3026     {
3027         deviceIDtest = i;
3028         InputManager::GetInstance()->GetKeyboardType(i, GetKeyboardTypeCallback);
3029         MMI_HILOGD("i:%{public}d", i);
3030         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3031     }
3032     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3033     MMI_HILOGD("Stop InputManagerTest_GetKeyboardType");
3034 }
3035 
3036 HWTEST_F(InputManagerTest, InputManagerTest_GetProcCpuUsage, TestSize.Level1)
3037 {
3038     CALL_DEBUG_ENTER;
3039     SYSTEM_INFO::CpuInfo cpuInfo;
3040     const std::string process_name = "multimodalinput";
3041     auto usage = cpuInfo.GetProcCpuUsage(process_name);
3042     MMI_HILOGD("The CPU usage of the %{public}s process is %{public}.2f", process_name.c_str(), usage);
3043     ASSERT_TRUE(usage < SYSTEM_INFO::CPU_USAGE_LOAD && usage != SYSTEM_INFO::CPU_USAGE_UNKONW);
3044 }
3045 
3046 /**
3047  * @tc.name: InputManagerTest_SetWindowInputEventConsumer_001
3048  * @tc.desc: Verify pointerEvent report eventHandler
3049  * @tc.type: FUNC
3050  * @tc.require: I5HMDY
3051  */
3052 HWTEST_F(InputManagerTest, InputManagerTest_SetWindowInputEventConsumer_001, TestSize.Level1)
3053 {
3054     CALL_DEBUG_ENTER;
3055     auto runner = AppExecFwk::EventRunner::Create(true);
3056     ASSERT_TRUE(runner != nullptr);
3057     auto eventHandler = std::make_shared<AppExecFwk::EventHandler>(runner);
3058     ASSERT_TRUE(eventHandler != nullptr);
3059     uint64_t runnerThreadId = 0;
3060 
__anonebfd6e530c02() 3061     auto fun = [&runnerThreadId]() {
3062         runnerThreadId = GetThisThreadId();
3063         MMI_HILOGD("Create eventHandler is threadId:%{public}" PRIu64, runnerThreadId);
3064         ASSERT_TRUE(runnerThreadId != 0);
3065     };
3066     eventHandler->PostSyncTask(fun, AppExecFwk::EventHandler::Priority::IMMEDIATE);
3067     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3068     auto consumer = GetPtr<WindowEventConsumer>();
3069     ASSERT_TRUE(consumer != nullptr);
3070     MMI::InputManager::GetInstance()->SetWindowInputEventConsumer(consumer, eventHandler);
3071     auto pointerEvent = SetupPointerEvent005();
3072     ASSERT_TRUE(pointerEvent != nullptr);
3073     InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3074     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3075     uint64_t consumerThreadId = consumer->GetConsumerThreadId();
3076 #ifdef OHOS_BUILD_ENABLE_POINTER
3077     EXPECT_EQ(runnerThreadId, consumerThreadId);
3078 #else
3079     ASSERT_TRUE(runnerThreadId != consumerThreadId);
3080 #endif // OHOS_BUILD_ENABLE_POINTER
3081 }
3082 
3083 /**
3084  * @tc.name: InputManagerTest_SetWindowInputEventConsumer_002
3085  * @tc.desc: Verify keyEvent report eventHandler
3086  * @tc.type: FUNC
3087  * @tc.require: I5HMDY
3088  */
3089 HWTEST_F(InputManagerTest, InputManagerTest_SetWindowInputEventConsumer_002, TestSize.Level1)
3090 {
3091     CALL_DEBUG_ENTER;
3092     const std::string threadTest = "threadNameTest";
3093     auto runner = AppExecFwk::EventRunner::Create(threadTest);
3094     ASSERT_TRUE(runner != nullptr);
3095     auto eventHandler = std::make_shared<AppExecFwk::EventHandler>(runner);
3096     ASSERT_TRUE(eventHandler != nullptr);
3097     uint64_t runnerThreadId = 0;
3098 
__anonebfd6e530d02() 3099     auto fun = [&runnerThreadId]() {
3100         runnerThreadId = GetThisThreadId();
3101         MMI_HILOGD("Create eventHandler is threadId:%{public}" PRIu64, runnerThreadId);
3102         ASSERT_TRUE(runnerThreadId != 0);
3103     };
3104     eventHandler->PostSyncTask(fun, AppExecFwk::EventHandler::Priority::IMMEDIATE);
3105     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3106     auto consumer = GetPtr<WindowEventConsumer>();
3107     ASSERT_TRUE(consumer != nullptr);
3108     MMI::InputManager::GetInstance()->SetWindowInputEventConsumer(consumer, eventHandler);
3109     auto keyEvent = SetupKeyEvent001();
3110     ASSERT_TRUE(keyEvent != nullptr);
3111     keyEvent->SetKeyCode(KeyEvent::KEYCODE_A);
3112     InputManager::GetInstance()->SimulateInputEvent(keyEvent);
3113     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3114     uint64_t consumerThreadId = consumer->GetConsumerThreadId();
3115 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
3116     EXPECT_EQ(runnerThreadId, consumerThreadId);
3117 #else
3118     ASSERT_TRUE(runnerThreadId != consumerThreadId);
3119 #endif // OHOS_BUILD_ENABLE_KEYBOARD
3120 }
3121 
3122 /**
3123  * @tc.name: InputManagerTest_SetPointerVisible_001
3124  * @tc.desc: Sets whether the pointer icon is visible
3125  * @tc.type: FUNC
3126  * @tc.require: I530VT
3127  */
3128 HWTEST_F(InputManagerTest, InputManagerTest_SetPointerVisible_001, TestSize.Level1)
3129 {
3130     bool isVisible { true };
3131     if (InputManager::GetInstance()->SetPointerVisible(isVisible) == RET_OK) {
3132         ASSERT_TRUE(InputManager::GetInstance()->IsPointerVisible() == isVisible);
3133     }
3134 }
3135 
3136 /**
3137  * @tc.name: InputManagerTest_SetPointerVisible_002
3138  * @tc.desc: Sets whether the pointer icon is visible
3139  * @tc.type: FUNC
3140  * @tc.require: I530VT
3141  */
3142 HWTEST_F(InputManagerTest, InputManagerTest_SetPointerVisible_002, TestSize.Level1)
3143 {
3144     bool isVisible { false };
3145     if (InputManager::GetInstance()->SetPointerVisible(isVisible) == RET_OK) {
3146         ASSERT_TRUE(InputManager::GetInstance()->IsPointerVisible() == isVisible);
3147     }
3148 }
3149 
3150 /**
3151  * @tc.name: InputManagerTest_SetPointSpeed_001
3152  * @tc.desc: Abnormal speed value processing
3153  * @tc.type: FUNC
3154  * @tc.require: I530XP I530UX
3155  */
3156 HWTEST_F(InputManagerTest, InputManagerTest_SetPointSpeed_001, TestSize.Level1)
3157 {
3158     CALL_DEBUG_ENTER;
3159     const int32_t speed = -1;
3160     InputManager::GetInstance()->SetPointerSpeed(speed);
3161     int32_t speed1;
3162     InputManager::GetInstance()->GetPointerSpeed(speed1);
3163     ASSERT_EQ(speed1, 1);
3164     InputManager::GetInstance()->MoveMouse(-2000, -2000);
3165     InputManager::GetInstance()->MoveMouse(50, 50);
3166     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3167     InputManager::GetInstance()->MoveMouse(100, 150);
3168     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3169     InputManager::GetInstance()->MoveMouse(300, 350);
3170     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3171     InputManager::GetInstance()->MoveMouse(400, 450);
3172     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3173     InputManager::GetInstance()->MoveMouse(500, 550);
3174     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3175     InputManager::GetInstance()->MoveMouse(700, 1000);
3176     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3177 }
3178 
3179 /**
3180  * @tc.name: InputManagerTest_SetPointSpeed_002
3181  * @tc.desc: Normal speed value processing
3182  * @tc.type: FUNC
3183  * @tc.require: I530XP I530UX
3184  */
3185 HWTEST_F(InputManagerTest, InputManagerTest_SetPointSpeed_002, TestSize.Level1)
3186 {
3187     CALL_DEBUG_ENTER;
3188     const int32_t speed = 1;
3189     InputManager::GetInstance()->SetPointerSpeed(speed);
3190     int32_t speed1;
3191     InputManager::GetInstance()->GetPointerSpeed(speed1);
3192     ASSERT_EQ(speed1, speed);
3193     InputManager::GetInstance()->MoveMouse(-2000, -2000);
3194     InputManager::GetInstance()->MoveMouse(50, 50);
3195     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3196     InputManager::GetInstance()->MoveMouse(100, 150);
3197     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3198     InputManager::GetInstance()->MoveMouse(300, 350);
3199     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3200     InputManager::GetInstance()->MoveMouse(400, 450);
3201     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3202     InputManager::GetInstance()->MoveMouse(500, 550);
3203     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3204     InputManager::GetInstance()->MoveMouse(700, 1000);
3205     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3206 }
3207 
3208 /**
3209  * @tc.name: InputManagerTest_SetPointSpeed_003
3210  * @tc.desc: Normal speed value processing
3211  * @tc.type: FUNC
3212  * @tc.require: I530XP I530UX
3213  */
3214 HWTEST_F(InputManagerTest, InputManagerTest_SetPointSpeed_003, TestSize.Level1)
3215 {
3216     CALL_DEBUG_ENTER;
3217     const int32_t speed = 4;
3218     InputManager::GetInstance()->SetPointerSpeed(speed);
3219     int32_t speed1;
3220     InputManager::GetInstance()->GetPointerSpeed(speed1);
3221     ASSERT_EQ(speed1, speed);
3222     InputManager::GetInstance()->MoveMouse(-2000, -2000);
3223     InputManager::GetInstance()->MoveMouse(50, 50);
3224     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3225     InputManager::GetInstance()->MoveMouse(100, 150);
3226     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3227     InputManager::GetInstance()->MoveMouse(300, 350);
3228     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3229     InputManager::GetInstance()->MoveMouse(400, 450);
3230     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3231     InputManager::GetInstance()->MoveMouse(500, 550);
3232     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3233     InputManager::GetInstance()->MoveMouse(700, 1000);
3234     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3235 }
3236 
3237 /**
3238  * @tc.name: InputManagerTest_SetPointSpeed_004
3239  * @tc.desc: Normal speed value processing
3240  * @tc.type: FUNC
3241  * @tc.require: I530XP I530UX
3242  */
3243 HWTEST_F(InputManagerTest, InputManagerTest_SetPointSpeed_004, TestSize.Level1)
3244 {
3245     CALL_DEBUG_ENTER;
3246     const int32_t speed = 11;
3247     InputManager::GetInstance()->SetPointerSpeed(speed);
3248     int32_t speed1;
3249     InputManager::GetInstance()->GetPointerSpeed(speed1);
3250     ASSERT_EQ(speed1, speed);
3251     InputManager::GetInstance()->MoveMouse(-2000, -2000);
3252     InputManager::GetInstance()->MoveMouse(50, 50);
3253     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3254     InputManager::GetInstance()->MoveMouse(100, 150);
3255     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3256     InputManager::GetInstance()->MoveMouse(300, 350);
3257     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3258     InputManager::GetInstance()->MoveMouse(400, 450);
3259     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3260     InputManager::GetInstance()->MoveMouse(500, 550);
3261     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3262     InputManager::GetInstance()->MoveMouse(700, 1000);
3263     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3264 }
3265 
3266 /**
3267  * @tc.name: InputManagerTest_SetPointSpeed_005
3268  * @tc.desc: Abnormal speed value processing
3269  * @tc.type: FUNC
3270  * @tc.require: I530XP I530UX
3271  */
3272 HWTEST_F(InputManagerTest, InputManagerTest_SetPointSpeed_005, TestSize.Level1)
3273 {
3274     CALL_DEBUG_ENTER;
3275     const int32_t speed = 20;
3276     InputManager::GetInstance()->SetPointerSpeed(speed);
3277     int32_t speed1;
3278     InputManager::GetInstance()->GetPointerSpeed(speed1);
3279     ASSERT_EQ(speed1, 11);
3280     InputManager::GetInstance()->MoveMouse(-2000, -2000);
3281     InputManager::GetInstance()->MoveMouse(50, 50);
3282     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3283     InputManager::GetInstance()->MoveMouse(100, 150);
3284     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3285     InputManager::GetInstance()->MoveMouse(300, 350);
3286     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3287     InputManager::GetInstance()->MoveMouse(400, 450);
3288     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3289     InputManager::GetInstance()->MoveMouse(500, 550);
3290     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3291     InputManager::GetInstance()->MoveMouse(700, 1000);
3292     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3293 }
3294 
3295 /**
3296  * @tc.name: InputManagerTest_SetPointerStyle_001
3297  * @tc.desc: Sets the pointer style of the window
3298  * @tc.type: FUNC
3299  * @tc.require: I530XS
3300  */
3301 HWTEST_F(InputManagerTest, InputManagerTest_SetPointerStyle_001, TestSize.Level1)
3302 {
3303     CALL_DEBUG_ENTER;
3304     auto window = WindowUtilsTest::GetInstance()->GetWindow();
3305     uint32_t windowId = window->GetWindowId();
3306     int32_t pointerStyle;
3307     if (InputManager::GetInstance()->SetPointerStyle(windowId, MOUSE_ICON::CROSS) == RET_OK) {
3308         ASSERT_TRUE(InputManager::GetInstance()->GetPointerStyle(windowId, pointerStyle) == RET_OK);
3309         ASSERT_EQ(pointerStyle, MOUSE_ICON::CROSS);
3310     }
3311 }
3312 
3313 /**
3314  * @tc.name: InputManagerTest_FunctionKeyState_001
3315  * @tc.desc: Set NumLock for the keyboard enablement state to true
3316  * @tc.type: FUNC
3317  * @tc.require: I5HMCX
3318  */
3319 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_001, TestSize.Level1)
3320 {
3321     CALL_DEBUG_ENTER;
3322     InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::NUM_LOCK_FUNCTION_KEY, true);
3323     InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::NUM_LOCK_FUNCTION_KEY);
3324 }
3325 
3326 /**
3327  * @tc.name: InputManagerTest_FunctionKeyState_002
3328  * @tc.desc: Set NumLock for the keyboard enablement state to false
3329  * @tc.type: FUNC
3330  * @tc.require: I5HMCX
3331  */
3332 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_002, TestSize.Level1)
3333 {
3334     CALL_DEBUG_ENTER;
3335     InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::NUM_LOCK_FUNCTION_KEY, false);
3336     bool result = InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::NUM_LOCK_FUNCTION_KEY);
3337     ASSERT_FALSE(result);
3338 }
3339 
3340 /**
3341  * @tc.name: InputManagerTest_FunctionKeyState_003
3342  * @tc.desc: Set ScrollLock for the keyboard enablement state to true
3343  * @tc.type: FUNC
3344  * @tc.require: I5HMCX
3345  */
3346 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_003, TestSize.Level1)
3347 {
3348     CALL_DEBUG_ENTER;
3349     InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::SCROLL_LOCK_FUNCTION_KEY, true);
3350     InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::SCROLL_LOCK_FUNCTION_KEY);
3351 }
3352 
3353 /**
3354  * @tc.name: InputManagerTest_FunctionKeyState_004
3355  * @tc.desc: Set ScrollLock for the keyboard enablement state to false
3356  * @tc.type: FUNC
3357  * @tc.require: I5HMCX
3358  */
3359 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_004, TestSize.Level1)
3360 {
3361     CALL_DEBUG_ENTER;
3362     InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::SCROLL_LOCK_FUNCTION_KEY, false);
3363     bool result = InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::SCROLL_LOCK_FUNCTION_KEY);
3364     ASSERT_FALSE(result);
3365 }
3366 
3367 /**
3368  * @tc.name: InputManagerTest_FunctionKeyState_005
3369  * @tc.desc: Set CapsLock for the keyboard enablement state to true
3370  * @tc.type: FUNC
3371  * @tc.require: I5HMCX
3372  */
3373 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_005, TestSize.Level1)
3374 {
3375     CALL_DEBUG_ENTER;
3376     InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::CAPS_LOCK_FUNCTION_KEY, true);
3377     InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::CAPS_LOCK_FUNCTION_KEY);
3378 }
3379 
3380 /**
3381  * @tc.name: InputManagerTest_FunctionKeyState_006
3382  * @tc.desc: Set CapsLock for the keyboard enablement state to false
3383  * @tc.type: FUNC
3384  * @tc.require: I5HMCX
3385  */
3386 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_006, TestSize.Level1)
3387 {
3388     CALL_DEBUG_ENTER;
3389     InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::CAPS_LOCK_FUNCTION_KEY, false);
3390     bool result = InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::CAPS_LOCK_FUNCTION_KEY);
3391     ASSERT_FALSE(result);
3392 }
3393 
3394 /**
3395  * @tc.name: InputManagerTest_FunctionKeyState_007
3396  * @tc.desc: Set other function keys
3397  * @tc.type: FUNC
3398  * @tc.require: I5HMCX
3399  */
3400 HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_007, TestSize.Level1)
3401 {
3402     CALL_DEBUG_ENTER;
3403     InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::UNKOWN_FUNCTION_KEY, true);
3404     bool result = InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::UNKOWN_FUNCTION_KEY);
3405     ASSERT_FALSE(result);
3406 
3407     InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::UNKOWN_FUNCTION_KEY, false);
3408     result = InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::UNKOWN_FUNCTION_KEY);
3409     ASSERT_FALSE(result);
3410 }
3411 
3412 /**
3413  * @tc.name: InputManagerTest_TouchScreenHotArea_001
3414  * @tc.desc: Touch event Search window by defaultHotAreas
3415  * @tc.type: FUNC
3416  * @tc.require: I5HMCB
3417  */
3418 HWTEST_F(InputManagerTest, InputManagerTest_TouchScreenHotArea_001, TestSize.Level1)
3419 {
3420     CALL_DEBUG_ENTER;
3421     std::shared_ptr<PointerEvent> pointerEvent { SetupTouchScreenEvent001() };
3422     ASSERT_TRUE(pointerEvent != nullptr);
3423     InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3424     ASSERT_EQ(pointerEvent->GetSourceType(), PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
3425 }
3426 
3427 /**
3428  * @tc.name: InputManagerTest_TouchScreenHotArea_002
3429  * @tc.desc: Touch event Search window by pointerHotAreas
3430  * @tc.type: FUNC
3431  * @tc.require: I5HMCB
3432  */
3433 HWTEST_F(InputManagerTest, InputManagerTest_TouchScreenHotArea_002, TestSize.Level1)
3434 {
3435     CALL_DEBUG_ENTER;
3436     std::shared_ptr<PointerEvent> pointerEvent { SetupTouchScreenEvent002() };
3437     ASSERT_TRUE(pointerEvent != nullptr);
3438     InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3439     ASSERT_EQ(pointerEvent->GetSourceType(), PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
3440 }
3441 
3442 /**
3443  * @tc.name: InputManagerTest_MouseHotArea_001
3444  * @tc.desc: Mouse event Search window by pointerHotAreas
3445  * @tc.type: FUNC
3446  * @tc.require: I5HMCB
3447  */
3448 HWTEST_F(InputManagerTest, InputManagerTest_MouseHotArea_001, TestSize.Level1)
3449 {
3450     CALL_DEBUG_ENTER;
3451     std::shared_ptr<PointerEvent> pointerEvent { SetupmouseEvent001() };
3452     ASSERT_TRUE(pointerEvent != nullptr);
3453     InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
3454     ASSERT_EQ(pointerEvent->GetSourceType(), PointerEvent::SOURCE_TYPE_MOUSE);
3455 }
3456 
3457 /**
3458  * @tc.name: InputManagerTest_MouseHotArea_002
3459  * @tc.desc: Mouse event Search window by pointerHotAreas
3460  * @tc.type: FUNC
3461  * @tc.require: I5HMCB
3462  */
3463 HWTEST_F(InputManagerTest, InputManagerTest_MouseHotArea_002, TestSize.Level1)
3464 {
3465     CALL_DEBUG_ENTER;
3466     std::shared_ptr<PointerEvent> pointerEvent { SetupmouseEvent002() };
3467     ASSERT_TRUE(pointerEvent != nullptr);
3468     ASSERT_EQ(pointerEvent->GetSourceType(), PointerEvent::SOURCE_TYPE_MOUSE);
3469 }
3470 
3471 /**
3472  * @tc.name: InputManagerTest_UpdateDisplayInfo
3473  * @tc.desc: Update window information
3474  * @tc.type: FUNC
3475  * @tc.require:
3476  */
3477 HWTEST_F(InputManagerTest, InputManagerTest_UpdateDisplayInfo, TestSize.Level1)
3478 {
3479     CALL_DEBUG_ENTER;
3480     DisplayGroupInfo displayGroupInfo;
3481     displayGroupInfo.focusWindowId = 0;
3482     displayGroupInfo.width = 0;
3483     displayGroupInfo.height = 0;
3484     InputManager::GetInstance()->UpdateDisplayInfo(displayGroupInfo);
3485     ASSERT_TRUE(displayGroupInfo.displaysInfo.empty());
3486 }
3487 
3488 /**
3489  * @tc.name: InputManagerTest_SetInputDevice
3490  * @tc.desc: Set input device
3491  * @tc.type: FUNC
3492  * @tc.require:
3493  */
3494 HWTEST_F(InputManagerTest, InputManagerTest_SetInputDevice, TestSize.Level1)
3495 {
3496     CALL_DEBUG_ENTER;
3497     std::string dhid("");
3498     std::string screenId("");
3499     int32_t ret = InputManager::GetInstance()->SetInputDevice(dhid, screenId);
3500 #ifdef OHOS_BUILD_ENABLE_COOPERATE
3501     ASSERT_EQ(ret, RET_ERR);
3502 #else
3503     ASSERT_EQ(ret, ERROR_UNSUPPORT);
3504 #endif // OHOS_BUILD_ENABLE_COOPERATE
3505 }
3506 
3507 /**
3508  * @tc.name: InputManagerTest_RegisterCooperateListener_001
3509  * @tc.desc: Register cooperate listener
3510  * @tc.type: FUNC
3511  * @tc.require:
3512  */
3513 HWTEST_F(InputManagerTest, InputManagerTest_RegisterCooperateListener_001, TestSize.Level1)
3514 {
3515     CALL_DEBUG_ENTER;
3516     std::shared_ptr<IInputDeviceCooperateListener> consumer = nullptr;
3517     int32_t ret = InputManager::GetInstance()->RegisterCooperateListener(consumer);
3518 #ifdef OHOS_BUILD_ENABLE_COOPERATE
3519     ASSERT_EQ(ret, RET_ERR);
3520 #else
3521     ASSERT_EQ(ret, ERROR_UNSUPPORT);
3522 #endif // OHOS_BUILD_ENABLE_COOPERATE
3523 }
3524 
3525 /**
3526  * @tc.name: InputManagerTest_RegisterCooperateListener_002
3527  * @tc.desc: Register cooperate listener
3528  * @tc.type: FUNC
3529  * @tc.require:
3530  */
3531 HWTEST_F(InputManagerTest, InputManagerTest_RegisterCooperateListener_002, TestSize.Level1)
3532 {
3533     CALL_DEBUG_ENTER;
3534     class InputDeviceCooperateListenerTest : public IInputDeviceCooperateListener {
3535     public:
InputDeviceCooperateListenerTest()3536         InputDeviceCooperateListenerTest() : IInputDeviceCooperateListener() {}
OnCooperateMessage(const std::string & deviceId,CooperationMessage msg)3537         void OnCooperateMessage(const std::string &deviceId, CooperationMessage msg) override
3538         {
3539             MMI_HILOGD("RegisterCooperateListenerTest");
3540         };
3541     };
3542     std::shared_ptr<InputDeviceCooperateListenerTest> consumer = std::make_shared<InputDeviceCooperateListenerTest>();
3543     int32_t ret = InputManager::GetInstance()->RegisterCooperateListener(consumer);
3544 #ifdef OHOS_BUILD_ENABLE_COOPERATE
3545     ASSERT_EQ(ret, RET_OK);
3546 #else
3547     ASSERT_EQ(ret, ERROR_UNSUPPORT);
3548 #endif // OHOS_BUILD_ENABLE_COOPERATE
3549     ret = InputManager::GetInstance()->UnregisterCooperateListener(consumer);
3550 #ifdef OHOS_BUILD_ENABLE_COOPERATE
3551     ASSERT_EQ(ret, RET_OK);
3552 #else
3553     ASSERT_EQ(ret, ERROR_UNSUPPORT);
3554 #endif // OHOS_BUILD_ENABLE_COOPERATE
3555 }
3556 
3557 /**
3558  * @tc.name: InputManagerTest_UnregisterCooperateListener
3559  * @tc.desc: Unregister cooperate listener
3560  * @tc.type: FUNC
3561  * @tc.require:
3562  */
3563 HWTEST_F(InputManagerTest, InputManagerTest_UnregisterCooperateListener, TestSize.Level1)
3564 {
3565     CALL_DEBUG_ENTER;
3566     std::shared_ptr<IInputDeviceCooperateListener> consumer = nullptr;
3567     int32_t ret = InputManager::GetInstance()->UnregisterCooperateListener(consumer);
3568 #ifdef OHOS_BUILD_ENABLE_COOPERATE
3569     ASSERT_EQ(ret, RET_OK);
3570 #else
3571     ASSERT_EQ(ret, ERROR_UNSUPPORT);
3572 #endif // OHOS_BUILD_ENABLE_COOPERATE
3573 }
3574 
3575 /**
3576  * @tc.name: InputManagerTest_EnableInputDeviceCooperate
3577  * @tc.desc: Enable input device cooperate
3578  * @tc.type: FUNC
3579  * @tc.require:
3580  */
3581 HWTEST_F(InputManagerTest, InputManagerTest_EnableInputDeviceCooperate, TestSize.Level1)
3582 {
3583     CALL_DEBUG_ENTER;
3584     bool enabled = false;
__anonebfd6e530e02(std::string listener, CooperationMessage cooperateMessages) 3585     auto fun = [](std::string listener, CooperationMessage cooperateMessages) {
3586         MMI_HILOGD("Enable input device cooperate success");
3587     };
3588     int32_t ret = InputManager::GetInstance()->EnableInputDeviceCooperate(enabled, fun);
3589 #ifdef OHOS_BUILD_ENABLE_COOPERATE
3590     ASSERT_EQ(ret, RET_OK);
3591 #else
3592     ASSERT_EQ(ret, ERROR_UNSUPPORT);
3593 #endif // OHOS_BUILD_ENABLE_COOPERATE
3594 }
3595 
3596 /**
3597  * @tc.name: InputManagerTest_StartInputDeviceCooperate
3598  * @tc.desc: Start input device cooperate
3599  * @tc.type: FUNC
3600  * @tc.require:
3601  */
3602 HWTEST_F(InputManagerTest, InputManagerTest_StartInputDeviceCooperate, TestSize.Level1)
3603 {
3604     CALL_DEBUG_ENTER;
3605     std::string sinkDeviceId("");
3606     int32_t srcInputDeviceId = -1;
__anonebfd6e530f02(std::string listener, CooperationMessage cooperateMessages) 3607     auto fun = [](std::string listener, CooperationMessage cooperateMessages) {
3608         MMI_HILOGD("Start input device cooperate success");
3609     };
3610     int32_t ret = InputManager::GetInstance()->StartInputDeviceCooperate(sinkDeviceId, srcInputDeviceId, fun);
3611 #ifdef OHOS_BUILD_ENABLE_COOPERATE
3612     ASSERT_NE(ret, RET_OK);
3613 #else
3614     ASSERT_EQ(ret, ERROR_UNSUPPORT);
3615 #endif // OHOS_BUILD_ENABLE_COOPERATE
3616 }
3617 
3618 /**
3619  * @tc.name: InputManagerTest_StopDeviceCooperate
3620  * @tc.desc: Stop device cooperate
3621  * @tc.type: FUNC
3622  * @tc.require:
3623  */
3624 HWTEST_F(InputManagerTest, InputManagerTest_StopDeviceCooperate, TestSize.Level1)
3625 {
3626     CALL_DEBUG_ENTER;
__anonebfd6e531002(std::string listener, CooperationMessage cooperateMessages) 3627     auto fun = [](std::string listener, CooperationMessage cooperateMessages) {
3628         MMI_HILOGD("Start input device cooperate success");
3629     };
3630     int32_t ret = InputManager::GetInstance()->StopDeviceCooperate(fun);
3631 #ifdef OHOS_BUILD_ENABLE_COOPERATE
3632     ASSERT_NE(ret, ERROR_UNSUPPORT);
3633 #else
3634     ASSERT_EQ(ret, ERROR_UNSUPPORT);
3635 #endif // OHOS_BUILD_ENABLE_COOPERATE
3636 }
3637 
3638 /**
3639  * @tc.name: InputManagerTest_GetInputDeviceCooperateState
3640  * @tc.desc: Get input device cooperate state
3641  * @tc.type: FUNC
3642  * @tc.require:
3643  */
3644 HWTEST_F(InputManagerTest, InputManagerTest_GetInputDeviceCooperateState, TestSize.Level1)
3645 {
3646     CALL_DEBUG_ENTER;
3647     const std::string deviceId("");
__anonebfd6e531102(bool inputdevice) 3648     auto fun = [](bool inputdevice) {
3649         MMI_HILOGD("Get inputdevice state success");
3650     };
3651     int32_t ret = InputManager::GetInstance()->GetInputDeviceCooperateState(deviceId, fun);
3652 #ifdef OHOS_BUILD_ENABLE_COOPERATE
3653     ASSERT_EQ(ret, RET_OK);
3654 #else
3655     ASSERT_EQ(ret, ERROR_UNSUPPORT);
3656 #endif // OHOS_BUILD_ENABLE_COOPERATE
3657 }
3658 
3659 /**
3660  * @tc.name: InputManagerTest_GetDevice_001
3661  * @tc.desc: Verify the fetch device info
3662  * @tc.type: FUNC
3663  * @tc.require:
3664  */
3665 HWTEST_F(InputManagerTest, InputManagerTest_GetDevice_001, TestSize.Level1)
3666 {
3667     CALL_DEBUG_ENTER;
3668     int32_t deviceId = 0;
__anonebfd6e531202(std::shared_ptr<InputDevice> inputDevice) 3669     auto callback = [](std::shared_ptr<InputDevice> inputDevice) {
3670         MMI_HILOGD("Get device success");
3671         ASSERT_TRUE(inputDevice != nullptr);
3672     };
3673     int32_t ret = InputManager::GetInstance()->GetDevice(deviceId, callback);
3674     ASSERT_EQ(ret, RET_OK);
3675 }
3676 
3677 /**
3678  * @tc.name: InputManagerTest_GetDevice_002
3679  * @tc.desc: Verify the fetch device info
3680  * @tc.type: FUNC
3681  * @tc.require:
3682  */
3683 HWTEST_F(InputManagerTest, InputManagerTest_GetDevice_002, TestSize.Level1)
3684 {
3685     CALL_DEBUG_ENTER;
3686     int32_t deviceId = -1;
__anonebfd6e531302(std::shared_ptr<InputDevice> inputDevice) 3687     auto callback = [](std::shared_ptr<InputDevice> inputDevice) {
3688         MMI_HILOGD("Get device success");
3689         ASSERT_TRUE(inputDevice != nullptr);
3690     };
3691     int32_t ret = InputManager::GetInstance()->GetDevice(deviceId, callback);
3692     ASSERT_NE(ret, RET_OK);
3693 }
3694 
3695 /**
3696  * @tc.name: InputManagerTest_GetDeviceIds
3697  * @tc.desc: Verify the fetch device list
3698  * @tc.type: FUNC
3699  * @tc.require:
3700  */
3701 HWTEST_F(InputManagerTest, InputManagerTest_GetDeviceIds, TestSize.Level1)
3702 {
3703     CALL_DEBUG_ENTER;
__anonebfd6e531402(std::vector<int32_t> ids) 3704     auto callback = [](std::vector<int32_t> ids) {
3705         MMI_HILOGD("Get device success");
3706     };
3707     int32_t ret = InputManager::GetInstance()->GetDeviceIds(callback);
3708     ASSERT_EQ(ret, RET_OK);
3709 }
3710 
3711 /**
3712  * @tc.name: InputManagerTest_SetAnrObserver
3713  * @tc.desc: Verify the observer for events
3714  * @tc.type: FUNC
3715  * @tc.require:
3716  */
3717 HWTEST_F(InputManagerTest, InputManagerTest_SetAnrObserver, TestSize.Level1)
3718 {
3719     CALL_DEBUG_ENTER;
3720     class IAnrObserverTest : public IAnrObserver {
3721     public:
IAnrObserverTest()3722         IAnrObserverTest() : IAnrObserver() {}
~IAnrObserverTest()3723         virtual ~IAnrObserverTest() {}
OnAnr(int32_t pid) const3724         void OnAnr(int32_t pid) const override
3725         {
3726             MMI_HILOGD("Set anr success");
3727         };
3728     };
3729 
3730     std::shared_ptr<IAnrObserverTest> observer = std::make_shared<IAnrObserverTest>();
3731     InputManager::GetInstance()->SetAnrObserver(observer);
3732 }
3733 
SetupTabletToolEvent001()3734 std::shared_ptr<PointerEvent> InputManagerTest::SetupTabletToolEvent001()
3735 {
3736     auto pointerEvent = PointerEvent::Create();
3737     CHKPP(pointerEvent);
3738     PointerEvent::PointerItem item;
3739     item.SetPointerId(DEFAULT_POINTER_ID);   // test code,set the PointerId = 0
3740     item.SetDisplayX(523);   // test code,set the DisplayX = 523
3741     item.SetDisplayY(723);   // test code,set the DisplayY = 723
3742     item.SetPressure(0.7);    // test code,set the Pressure = 0.7
3743     item.SetTiltX(10.0);     // test code,set the TiltX = 10.0
3744     item.SetTiltY(-9.0);     // test code,set the TiltX = -9.0
3745     item.SetDeviceId(DEFAULT_DEVICE_ID);    // test code,set the DeviceId = 0
3746     item.SetToolType(PointerEvent::TOOL_TYPE_PEN);
3747     pointerEvent->AddPointerItem(item);
3748 
3749     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
3750     pointerEvent->SetPointerId(DEFAULT_POINTER_ID);  // test code,set the PointerId = 0
3751     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
3752     return pointerEvent;
3753 }
3754 
3755 #ifdef OHOS_BUILD_ENABLE_MONITOR
3756 /**
3757  * @tc.name: InputManagerTest_MonitorTabletToolEvent_001
3758  * @tc.desc: Verify monitoring tablet tool down event
3759  * @tc.type: FUNC
3760  * @tc.require:
3761  */
3762 HWTEST_F(InputManagerTest, InputManagerTest_MonitorTabletToolEvent_001, TestSize.Level1)
3763 {
3764     CALL_DEBUG_ENTER;
3765     auto callbackPtr = GetPtr<InputEventCallback>();
3766     ASSERT_TRUE(callbackPtr != nullptr);
3767     int32_t monitorId = TestAddMonitor(callbackPtr);
3768     EXPECT_TRUE(IsValidHandlerId(monitorId));
3769     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3770 
3771 #ifdef OHOS_BUILD_ENABLE_TOUCH
3772     auto pointerEvent = SetupTabletToolEvent001();
3773     ASSERT_TRUE(pointerEvent != nullptr);
3774     TestSimulateInputEvent(pointerEvent);
3775 
3776     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
3777     TestSimulateInputEvent(pointerEvent);
3778 #endif // OHOS_BUILD_ENABLE_TOUCH
3779 
3780     if (IsValidHandlerId(monitorId)) {
3781         TestRemoveMonitor(monitorId);
3782         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3783     }
3784 }
3785 #endif // OHOS_BUILD_ENABLE_MONITOR
3786 
3787 #ifdef OHOS_BUILD_ENABLE_INTERCEPTOR
3788 /**
3789  * @tc.name: InputManagerTest_InterceptTabletToolEvent_001
3790  * @tc.desc: Verify intercepting tablet tool event
3791  * @tc.type: FUNC
3792  * @tc.require:
3793  */
3794 HWTEST_F(InputManagerTest, InputManagerTest_InterceptTabletToolEvent_001, TestSize.Level1)
3795 {
3796     CALL_DEBUG_ENTER;
3797     auto interceptor = GetPtr<InputEventCallback>();
3798     int32_t interceptorId { InputManager::GetInstance()->AddInterceptor(interceptor) };
3799     EXPECT_TRUE(IsValidHandlerId(interceptorId));
3800     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3801 
3802 #ifdef OHOS_BUILD_ENABLE_TOUCH
3803     auto pointerEvent = SetupTabletToolEvent001();
3804     ASSERT_TRUE(pointerEvent != nullptr);
3805     TestSimulateInputEvent(pointerEvent);
3806 
3807     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
3808     TestSimulateInputEvent(pointerEvent);
3809 #endif // OHOS_BUILD_ENABLE_TOUCH
3810 
3811     if (IsValidHandlerId(interceptorId)) {
3812         InputManager::GetInstance()->RemoveInterceptor(interceptorId);
3813         std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP));
3814     }
3815 }
3816 #endif // OHOS_BUILD_ENABLE_INTERCEPTOR
3817 } // namespace MMI
3818 } // namespace OHOS
3819