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 <gtest/gtest.h>
17 
18 #include "anr_manager.h"
19 #include "define_multimodal.h"
20 #include "event_dispatch_handler.h"
21 #include "i_input_windows_manager.h"
22 #include "input_event_handler.h"
23 
24 namespace OHOS {
25 namespace MMI {
26 namespace {
27 using namespace testing::ext;
28 constexpr int32_t UID_ROOT { 0 };
29 static constexpr char PROGRAM_NAME[] = "uds_sesion_test";
30 int32_t g_moduleType = 3;
31 int32_t g_pid = 0;
32 int32_t g_writeFd = -1;
33 } // namespace
34 
35 class EventDispatchTest : public testing::Test {
36 public:
SetUpTestCase(void)37     static void SetUpTestCase(void) {}
TearDownTestCase(void)38     static void TearDownTestCase(void) {}
39 };
40 
41 /**
42  * @tc.name: EventDispatchTest_SearchWindow_001
43  * @tc.desc: Test the function SearchWindow
44  * @tc.type: FUNC
45  * @tc.require:
46  */
47 HWTEST_F(EventDispatchTest, EventDispatchTest_SearchWindow_001, TestSize.Level1)
48 {
49     EventDispatchHandler edh;
50     WindowInfo info;
51     auto windowInfo1 = std::make_shared<WindowInfo>(info);
52     windowInfo1->id = 1;
53     auto windowInfo2 = std::make_shared<WindowInfo>(info);
54     windowInfo2->id = 2;
55     auto windowInfo3 = std::make_shared<WindowInfo>(info);
56     windowInfo3->id = 3;
57     auto windowInfo4 = std::make_shared<WindowInfo>(info);
58     windowInfo4->id = 4;
59     std::vector<std::shared_ptr<WindowInfo>> windowList;
60     windowList.push_back(windowInfo1);
61     windowList.push_back(windowInfo2);
62     windowList.push_back(windowInfo3);
63     EXPECT_TRUE(edh.SearchWindow(windowList, windowInfo2));
64     EXPECT_TRUE(edh.SearchWindow(windowList, windowInfo3));
65     EXPECT_FALSE(edh.SearchWindow(windowList, windowInfo4));
66 }
67 
68 /**
69  * @tc.name: EventDispatchTest_DispatchKeyEvent_01
70  * @tc.desc: Test DispatchKeyEvent
71  * @tc.type: FUNC
72  * @tc.require:
73  */
74 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchKeyEvent_01, TestSize.Level1)
75 {
76     EventDispatchHandler dispatch;
77     UDSServer udsServer;
78     int32_t fd;
79     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
80     ASSERT_NE(keyEvent, nullptr);
81 
82     int32_t currentTime = dispatch.currentTime_;
83     int32_t eventTime = dispatch.eventTime_;
84     int32_t INTERVAL_TIME = 3000;
85     currentTime = 6000;
86     eventTime = 1000;
87     EXPECT_TRUE(currentTime - eventTime > INTERVAL_TIME);
88     fd = -1;
89     int32_t ret = dispatch.DispatchKeyEvent(fd, udsServer, keyEvent);
90     EXPECT_EQ(ret, RET_ERR);
91 }
92 
93 /**
94  * @tc.name: EventDispatchTest_DispatchKeyEvent_02
95  * @tc.desc: Test DispatchKeyEvent
96  * @tc.type: FUNC
97  * @tc.require:
98  */
99 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchKeyEvent_02, TestSize.Level1)
100 {
101     EventDispatchHandler dispatch;
102     UDSServer udsServer;
103     int32_t fd;
104     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
105     ASSERT_NE(keyEvent, nullptr);
106 
107     int32_t currentTime = dispatch.currentTime_;
108     int32_t eventTime = dispatch.eventTime_;
109     int32_t INTERVAL_TIME = 3000;
110     currentTime = 2000;
111     eventTime = 1000;
112     EXPECT_FALSE(currentTime - eventTime > INTERVAL_TIME);
113     fd = 1;
114     int32_t ret = dispatch.DispatchKeyEvent(fd, udsServer, keyEvent);
115     EXPECT_EQ(ret, RET_ERR);
116 }
117 
118 /**
119  * @tc.name: EventDispatchTest_DispatchKeyEvent_03
120  * @tc.desc: Test DispatchKeyEvent
121  * @tc.type: FUNC
122  * @tc.require:
123  */
124 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchKeyEvent_03, TestSize.Level1)
125 {
126     EventDispatchHandler dispatch;
127     UDSServer udsServer;
128     int32_t fd = 2;
129     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
130     ASSERT_NE(keyEvent, nullptr);
131     auto currentTime = GetSysClockTime();
132     auto session = udsServer.GetSession(fd);
133 
134     bool ret1 = ANRMgr->TriggerANR(ANR_DISPATCH, currentTime, session);
135     EXPECT_FALSE(ret1);
136     int32_t ret2 = dispatch.DispatchKeyEvent(fd, udsServer, keyEvent);
137     EXPECT_EQ(ret2, RET_ERR);
138 }
139 
140 /**
141  * @tc.name: EventDispatchTest_DispatchKeyEvent_04
142  * @tc.desc: Test DispatchKeyEvent
143  * @tc.type: FUNC
144  * @tc.require:
145  */
146 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchKeyEvent_04, TestSize.Level1)
147 {
148     EventDispatchHandler dispatch;
149     UDSServer udsServer;
150     int32_t fd = -1;
151     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
152     ASSERT_NE(keyEvent, nullptr);
153 
154     int32_t currentTime = dispatch.currentTime_;
155     int32_t eventTime = dispatch.eventTime_;
156     int32_t INTERVAL_TIME = 3000;
157     currentTime = 2000;
158     eventTime = 1000;
159     EXPECT_FALSE(currentTime - eventTime > INTERVAL_TIME);
160 
161     auto currentTime1 = GetSysClockTime();
162     auto session = udsServer.GetSession(fd);
163     bool ret1 = ANRMgr->TriggerANR(ANR_DISPATCH, currentTime1, session);
164     EXPECT_FALSE(ret1);
165     int32_t ret2 = dispatch.DispatchKeyEvent(fd, udsServer, keyEvent);
166     EXPECT_EQ(ret2, RET_ERR);
167 }
168 
169 /**
170  * @tc.name: EventDispatchTest_DispatchKeyEvent_05
171  * @tc.desc: Test DispatchKeyEvent
172  * @tc.type: FUNC
173  * @tc.require:
174  */
175 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchKeyEvent_05, TestSize.Level1)
176 {
177     EventDispatchHandler dispatch;
178     UDSServer udsServer;
179     int32_t fd = 2;
180     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
181     ASSERT_NE(keyEvent, nullptr);
182     auto currentTime = GetSysClockTime();
183     auto session = udsServer.GetSession(fd);
184     bool ret1 = ANRMgr->TriggerANR(ANR_DISPATCH, currentTime, session);
185     EXPECT_FALSE(ret1);
186     NetPacket pkt(MmiMessageId::INVALID);
187     EXPECT_FALSE(pkt.ChkRWError());
188     EXPECT_FALSE(udsServer.SendMsg(fd, pkt));
189     int32_t ret2 = dispatch.DispatchKeyEvent(fd, udsServer, keyEvent);
190     EXPECT_EQ(ret2, RET_ERR);
191 }
192 
193 /**
194  * @tc.name: FilterInvalidPointerItem_01
195  * @tc.desc: Test the function FilterInvalidPointerItem
196  * @tc.type: FUNC
197  * @tc.require:
198  */
199 HWTEST_F(EventDispatchTest, FilterInvalidPointerItem_01, TestSize.Level1)
200 {
201     EventDispatchHandler eventdispatchhandler;
202     int32_t fd = 1;
203     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
204     ASSERT_NE(pointerEvent, nullptr);
205 
206     std::vector<int32_t> pointerIdList;
207     pointerEvent->pointerId_ = 3;
208     pointerIdList.push_back(pointerEvent->pointerId_);
209     pointerEvent->pointerId_ = 5;
210     pointerIdList.push_back(pointerEvent->pointerId_);
211     EXPECT_TRUE(pointerIdList.size() > 1);
212 
213     PointerEvent::PointerItem pointeritem;
214     pointeritem.SetWindowX(10);
215     pointeritem.SetWindowY(20);
216     pointeritem.SetTargetWindowId(2);
217     int32_t id = 1;
218     EXPECT_FALSE(pointerEvent->GetPointerItem(id, pointeritem));
219 
220     pointeritem.targetWindowId_ = 3;
221     auto itemPid = WIN_MGR->GetWindowPid(pointeritem.targetWindowId_);
222     EXPECT_FALSE(itemPid >= 0);
223     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.FilterInvalidPointerItem(pointerEvent, fd));
224 }
225 
226 /**
227  * @tc.name: EventDispatchTest_DispatchKeyEventPid_01
228  * @tc.desc: Test DispatchKeyEventPid
229  * @tc.type: FUNC
230  * @tc.require:
231  */
232 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchKeyEventPid_01, TestSize.Level1)
233 {
234     EventDispatchHandler dispatch;
235     UDSServer udsServer;
236     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
237     ASSERT_NE(keyEvent, nullptr);
238     std::vector<std::pair<int32_t, TargetInfo>> vecTarget;
239 
240     TargetInfo target1;
241     target1.privacyMode = SecureFlag::PRIVACY_MODE;
242     target1.id = 1;
243     target1.agentWindowId = 3;
244     vecTarget.push_back(std::make_pair(1, target1));
245 
246     TargetInfo target2;
247     target2.privacyMode = SecureFlag::PRIVACY_MODE;
248     target2.id = 2;
249     target2.agentWindowId = 5;
250     vecTarget.push_back(std::make_pair(2, target2));
251 
252     int32_t ret = dispatch.DispatchKeyEventPid(udsServer, keyEvent);
253     EXPECT_EQ(ret, RET_OK);
254 }
255 
256 /**
257  * @tc.name: EventDispatchTest_DispatchKeyEventPid_02
258  * @tc.desc: Test DispatchKeyEventPid
259  * @tc.type: FUNC
260  * @tc.require:
261  */
262 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchKeyEventPid_02, TestSize.Level1)
263 {
264     EventDispatchHandler dispatch;
265     UDSServer udsServer;
266     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
267     ASSERT_NE(keyEvent, nullptr);
268     std::vector<std::pair<int32_t, TargetInfo>> vecTarget;
269 
270     TargetInfo target1;
271     target1.privacyMode = SecureFlag::DEFAULT_MODE;
272     target1.id = 2;
273     target1.agentWindowId = 5;
274     vecTarget.push_back(std::make_pair(1, target1));
275 
276     TargetInfo target2;
277     target2.privacyMode = SecureFlag::DEFAULT_MODE;
278     target2.id = 3;
279     target2.agentWindowId = 6;
280     vecTarget.push_back(std::make_pair(2, target2));
281 
282     int32_t ret = dispatch.DispatchKeyEventPid(udsServer, keyEvent);
283     EXPECT_EQ(ret, RET_OK);
284 }
285 
286 /**
287  * @tc.name: DispatchPointerEventInner_01
288  * @tc.desc: Test DispatchKeyEvent
289  * @tc.type: FUNC
290  * @tc.require:
291  */
292 HWTEST_F(EventDispatchTest, DispatchPointerEventInner_01, TestSize.Level1)
293 {
294     EventDispatchHandler dispatch;
295     UDSServer udsServer;
296     int32_t fd = 2;
297     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
298     ASSERT_NE(pointerEvent, nullptr);
299     auto currentTime = GetSysClockTime();
300     auto session = udsServer.GetSession(fd);
301     bool ret = ANRMgr->TriggerANR(ANR_DISPATCH, currentTime, session);
302     EXPECT_FALSE(ret);
303     pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_DOWN;
304     ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd));
305 }
306 
307 /**
308  * @tc.name: DispatchPointerEventInner_02
309  * @tc.desc: Test DispatchKeyEvent
310  * @tc.type: FUNC
311  * @tc.require:
312  */
313 HWTEST_F(EventDispatchTest, DispatchPointerEventInner_02, TestSize.Level1)
314 {
315     EventDispatchHandler dispatch;
316     UDSServer udsServer;
317     int32_t fd = 3;
318     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
319     ASSERT_NE(pointerEvent, nullptr);
320     auto currentTime = GetSysClockTime();
321     auto session = udsServer.GetSession(fd);
322     bool ret = ANRMgr->TriggerANR(ANR_DISPATCH, currentTime, session);
323     EXPECT_FALSE(ret);
324     pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_UP;
325     ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd));
326 }
327 
328 /**
329  * @tc.name: DispatchPointerEventInner_03
330  * @tc.desc: Test DispatchKeyEvent
331  * @tc.type: FUNC
332  * @tc.require:
333  */
334 HWTEST_F(EventDispatchTest, DispatchPointerEventInner_03, TestSize.Level1)
335 {
336     EventDispatchHandler dispatch;
337     UDSServer udsServer;
338     int32_t fd = 3;
339     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
340     ASSERT_NE(pointerEvent, nullptr);
341     auto currentTime = GetSysClockTime();
342     auto session = udsServer.GetSession(fd);
343     bool ret = ANRMgr->TriggerANR(ANR_DISPATCH, currentTime, session);
344     EXPECT_FALSE(ret);
345     pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_PULL_DOWN;
346     ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd));
347 }
348 
349 /**
350  * @tc.name: DispatchPointerEventInner_04
351  * @tc.desc: Test DispatchKeyEvent
352  * @tc.type: FUNC
353  * @tc.require:
354  */
355 HWTEST_F(EventDispatchTest, DispatchPointerEventInner_04, TestSize.Level1)
356 {
357     EventDispatchHandler dispatch;
358     UDSServer udsServer;
359     int32_t fd = 3;
360     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
361     ASSERT_NE(pointerEvent, nullptr);
362     auto currentTime = GetSysClockTime();
363     auto session = udsServer.GetSession(fd);
364     bool ret = ANRMgr->TriggerANR(ANR_DISPATCH, currentTime, session);
365     EXPECT_FALSE(ret);
366     pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_PULL_UP;
367     ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd));
368 }
369 
370 /**
371  * @tc.name: DispatchPointerEventInner_05
372  * @tc.desc: Test DispatchKeyEvent
373  * @tc.type: FUNC
374  * @tc.require:
375  */
376 HWTEST_F(EventDispatchTest, DispatchPointerEventInner_05, TestSize.Level1)
377 {
378     EventDispatchHandler dispatch;
379     UDSServer udsServer;
380     int32_t fd = 3;
381     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
382     ASSERT_NE(pointerEvent, nullptr);
383     auto currentTime = GetSysClockTime();
384     auto session = udsServer.GetSession(fd);
385     bool ret = ANRMgr->TriggerANR(ANR_DISPATCH, currentTime, session);
386     EXPECT_FALSE(ret);
387     pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_MOVE;
388 
389     NetPacket pkt(MmiMessageId::INVALID);
390     EXPECT_FALSE(udsServer.SendMsg(fd, pkt));
391     ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd));
392 }
393 
394 /**
395  * @tc.name: EventDispatchTest_HandleTouchEvent_001
396  * @tc.desc: Test the function HandleTouchEvent
397  * @tc.type: FUNC
398  * @tc.require:
399  */
400 HWTEST_F(EventDispatchTest, EventDispatchTest_HandleTouchEvent_001, TestSize.Level1)
401 {
402     EventDispatchHandler eventdispatchhandler;
403     int32_t eventType = 3;
404     std::shared_ptr<PointerEvent> sharedPointerEvent = std::make_shared<PointerEvent>(eventType);
405     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleTouchEvent(sharedPointerEvent));
406 }
407 
408 /**
409  * @tc.name: EventDispatchTest_FilterInvalidPointerItem_001
410  * @tc.desc: Test the function FilterInvalidPointerItem
411  * @tc.type: FUNC
412  * @tc.require:
413  */
414 HWTEST_F(EventDispatchTest, EventDispatchTest_FilterInvalidPointerItem_001, TestSize.Level1)
415 {
416     EventDispatchHandler eventdispatchhandler;
417     int32_t fd = 1;
418     int32_t eventType = 3;
419     std::shared_ptr<PointerEvent> sharedPointerEvent = std::make_shared<PointerEvent>(eventType);
420     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.FilterInvalidPointerItem(sharedPointerEvent, fd));
421 }
422 
423 /**
424  * @tc.name: EventDispatchTest_FilterInvalidPointerItem_002
425  * @tc.desc: Test the function FilterInvalidPointerItem
426  * @tc.type: FUNC
427  * @tc.require:
428  */
429 HWTEST_F(EventDispatchTest, EventDispatchTest_FilterInvalidPointerItem_002, TestSize.Level1)
430 {
431     EventDispatchHandler eventdispatchhandler;
432     int32_t fd = 1;
433     int32_t eventType = 3;
434     std::shared_ptr<PointerEvent> sharedPointerEvent = std::make_shared<PointerEvent>(eventType);
435     EXPECT_NE(sharedPointerEvent, nullptr);
436 
437     std::vector<int32_t> pointerIdList;
438     pointerIdList.push_back(1);
439     pointerIdList.push_back(2);
440     EXPECT_TRUE(pointerIdList.size() > 1);
441     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.FilterInvalidPointerItem(sharedPointerEvent, fd));
442 }
443 
444 /**
445  * @tc.name: EventDispatchTest_FilterInvalidPointerItem_003
446  * @tc.desc: Test the function FilterInvalidPointerItem
447  * @tc.type: FUNC
448  * @tc.require:
449  */
450 HWTEST_F(EventDispatchTest, EventDispatchTest_FilterInvalidPointerItem_003, TestSize.Level1)
451 {
452     EventDispatchHandler eventdispatchhandler;
453     int32_t fd = 1;
454     int32_t eventType = 3;
455     std::shared_ptr<PointerEvent> sharedPointerEvent = std::make_shared<PointerEvent>(eventType);
456     EXPECT_NE(sharedPointerEvent, nullptr);
457 
458     std::vector<int32_t> pointerIdList;
459     pointerIdList.push_back(1);
460     pointerIdList.push_back(2);
461     pointerIdList.push_back(3);
462     EXPECT_TRUE(pointerIdList.size() > 1);
463 
464     int32_t itemPid = 5;
465     EXPECT_TRUE(itemPid >= 0);
466     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.FilterInvalidPointerItem(sharedPointerEvent, fd));
467 }
468 
469 /**
470  * @tc.name: EventDispatchTest_HandleMultiWindowPointerEvent_001
471  * @tc.desc: Test HandleMultiWindowPointerEvent
472  * @tc.type: FUNC
473  * @tc.require:
474  */
475 HWTEST_F(EventDispatchTest, EventDispatchTest_HandleMultiWindowPointerEvent_001, TestSize.Level1)
476 {
477     EventDispatchHandler eventdispatchhandler;
478     int32_t eventType = 3;
479     std::shared_ptr<PointerEvent> point = std::make_shared<PointerEvent>(eventType);
480     EXPECT_NE(point, nullptr);
481 
482     std::vector<int32_t> windowIds;
483     windowIds.push_back(1);
484     windowIds.push_back(2);
485     windowIds.push_back(3);
486 
487     PointerEvent::PointerItem pointerItem;
488     pointerItem.SetWindowX(10);
489     pointerItem.SetWindowY(20);
490     pointerItem.SetTargetWindowId(2);
491 
492     std::optional<WindowInfo> windowInfo;
493     windowInfo = std::nullopt;
494     EXPECT_TRUE(windowInfo == std::nullopt);
495     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleMultiWindowPointerEvent(point, pointerItem));
496 }
497 
498 /**
499  * @tc.name: EventDispatchTest_HandleMultiWindowPointerEvent_002
500  * @tc.desc: Test HandleMultiWindowPointerEvent
501  * @tc.type: FUNC
502  * @tc.require:
503  */
504 HWTEST_F(EventDispatchTest, EventDispatchTest_HandleMultiWindowPointerEvent_002, TestSize.Level1)
505 {
506     EventDispatchHandler eventdispatchhandler;
507     int32_t eventType = 2;
508     std::shared_ptr<PointerEvent> point = std::make_shared<PointerEvent>(eventType);
509     EXPECT_NE(point, nullptr);
510 
511     std::vector<int32_t> windowIds;
512     windowIds.push_back(1);
513     windowIds.push_back(2);
514     windowIds.push_back(3);
515 
516     PointerEvent::PointerItem pointerItem;
517     pointerItem.SetWindowX(20);
518     pointerItem.SetWindowY(30);
519     pointerItem.SetTargetWindowId(3);
520 
521     std::optional<WindowInfo> windowInfo;
522     EXPECT_TRUE(windowInfo->transform.empty());
523     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleMultiWindowPointerEvent(point, pointerItem));
524 }
525 
526 /**
527  * @tc.name: EventDispatchTest_HandleMultiWindowPointerEvent_003
528  * @tc.desc: Test HandleMultiWindowPointerEvent
529  * @tc.type: FUNC
530  * @tc.require:
531  */
532 HWTEST_F(EventDispatchTest, EventDispatchTest_HandleMultiWindowPointerEvent_003, TestSize.Level1)
533 {
534     EventDispatchHandler eventdispatchhandler;
535     int32_t eventType = 5;
536     std::shared_ptr<PointerEvent> point = std::make_shared<PointerEvent>(eventType);
537     EXPECT_NE(point, nullptr);
538     point->pointerAction_ = PointerEvent::POINTER_ACTION_UP;
539 
540     std::vector<int32_t> windowIds;
541     windowIds.push_back(1);
542     windowIds.push_back(2);
543     windowIds.push_back(3);
544 
545     PointerEvent::PointerItem pointerItem;
546     pointerItem.SetWindowX(30);
547     pointerItem.SetWindowY(40);
548     pointerItem.SetTargetWindowId(5);
549 
550     std::optional<WindowInfo> windowInfo;
551     windowInfo = std::nullopt;
552     int32_t windowId = 2;
553     bool ret = eventdispatchhandler.ReissueEvent(point, windowId, windowInfo);
554     EXPECT_FALSE(ret);
555     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleMultiWindowPointerEvent(point, pointerItem));
556 }
557 
558 /**
559  * @tc.name: EventDispatchTest_HandleMultiWindowPointerEvent_004
560  * @tc.desc: Test HandleMultiWindowPointerEvent
561  * @tc.type: FUNC
562  * @tc.require:
563  */
564 HWTEST_F(EventDispatchTest, EventDispatchTest_HandleMultiWindowPointerEvent_004, TestSize.Level1)
565 {
566     EventDispatchHandler eventdispatchhandler;
567     int32_t eventType = 6;
568     std::shared_ptr<PointerEvent> point = std::make_shared<PointerEvent>(eventType);
569     EXPECT_NE(point, nullptr);
570     point->pointerAction_ = PointerEvent::POINTER_ACTION_DOWN;
571     point->pointerId_ = 2;
572 
573     std::vector<int32_t> windowIds;
574     windowIds.push_back(1);
575     windowIds.push_back(2);
576     windowIds.push_back(3);
577 
578     PointerEvent::PointerItem pointerItem;
579     pointerItem.SetWindowX(40);
580     pointerItem.SetWindowY(50);
581     pointerItem.SetTargetWindowId(5);
582 
583     std::optional<WindowInfo> windowInfo;
584     windowInfo = std::nullopt;
585     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleMultiWindowPointerEvent(point, pointerItem));
586 }
587 
588 /**
589  * @tc.name: EventDispatchTest_HandleMultiWindowPointerEvent_005
590  * @tc.desc: Test HandleMultiWindowPointerEvent
591  * @tc.type: FUNC
592  * @tc.require:
593  */
594 HWTEST_F(EventDispatchTest, EventDispatchTest_HandleMultiWindowPointerEvent_005, TestSize.Level1)
595 {
596     EventDispatchHandler eventdispatchhandler;
597     int32_t eventType = 6;
598     std::shared_ptr<PointerEvent> point = std::make_shared<PointerEvent>(eventType);
599     EXPECT_NE(point, nullptr);
600     point->pointerAction_ = PointerEvent::POINTER_ACTION_PULL_UP;
601 
602     std::vector<int32_t> windowIds;
603     windowIds.push_back(1);
604     windowIds.push_back(2);
605     windowIds.push_back(3);
606 
607     PointerEvent::PointerItem pointerItem;
608     pointerItem.SetWindowX(45);
609     pointerItem.SetWindowY(55);
610     pointerItem.SetTargetWindowId(3);
611 
612     std::optional<WindowInfo> windowInfo;
613     windowInfo = std::nullopt;
614     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleMultiWindowPointerEvent(point, pointerItem));
615 }
616 
617 /**
618  * @tc.name: EventDispatchTest_HandleMultiWindowPointerEvent_006
619  * @tc.desc: Test HandleMultiWindowPointerEvent
620  * @tc.type: FUNC
621  * @tc.require:
622  */
623 HWTEST_F(EventDispatchTest, EventDispatchTest_HandleMultiWindowPointerEvent_006, TestSize.Level1)
624 {
625     EventDispatchHandler eventdispatchhandler;
626     int32_t eventType = 6;
627     std::shared_ptr<PointerEvent> point = std::make_shared<PointerEvent>(eventType);
628     EXPECT_NE(point, nullptr);
629     point->pointerAction_ = PointerEvent::POINTER_ACTION_CANCEL;
630 
631     std::vector<int32_t> windowIds;
632     windowIds.push_back(1);
633     windowIds.push_back(2);
634     windowIds.push_back(3);
635 
636     PointerEvent::PointerItem pointerItem;
637     pointerItem.SetWindowX(35);
638     pointerItem.SetWindowY(50);
639     pointerItem.SetTargetWindowId(2);
640 
641     std::optional<WindowInfo> windowInfo;
642     windowInfo = std::nullopt;
643     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleMultiWindowPointerEvent(point, pointerItem));
644 }
645 
646 /**
647  * @tc.name: EventDispatchTest_NotifyPointerEventToRS_001
648  * @tc.desc: Test the function NotifyPointerEventToRS
649  * @tc.type: FUNC
650  * @tc.require:
651  */
652 HWTEST_F(EventDispatchTest, EventDispatchTest_NotifyPointerEventToRS_001, TestSize.Level1)
653 {
654     EventDispatchHandler eventdispatchhandler;
655     int32_t action = 1;
656     std::string name = "ExampleProgram";
657     uint32_t processId = 12345;
658     int32_t touchCnt = 0;
659     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.NotifyPointerEventToRS(action, name, processId, touchCnt));
660 }
661 
662 /**
663  * @tc.name: EventDispatchTest_HandlePointerEventInner_001
664  * @tc.desc: Test the function HandlePointerEventInner
665  * @tc.type: FUNC
666  * @tc.require:
667  */
668 HWTEST_F(EventDispatchTest, EventDispatchTest_HandlePointerEventInner_001, TestSize.Level1)
669 {
670     EventDispatchHandler eventdispatchhandler;
671     int32_t eventType = 3;
672     PointerEvent* pointerEvent = new PointerEvent(eventType);
673     std::shared_ptr<PointerEvent> sharedPointerEvent(pointerEvent);
674     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandlePointerEventInner(sharedPointerEvent));
675 }
676 
677 /**
678  * @tc.name: EventDispatchTest_HandlePointerEventInner_002
679  * @tc.desc: Test the function HandlePointerEventInner
680  * @tc.type: FUNC
681  * @tc.require:
682  */
683 HWTEST_F(EventDispatchTest, EventDispatchTest_HandlePointerEventInner_002, TestSize.Level1)
684 {
685     EventDispatchHandler eventdispatchhandler;
686     int32_t eventType = 3;
687     std::shared_ptr<PointerEvent> point = std::make_shared<PointerEvent>(eventType);
688     EXPECT_NE(point, nullptr);
689     std::vector<int32_t> windowIds;
690     windowIds.push_back(1);
691     windowIds.push_back(2);
692     EXPECT_FALSE(windowIds.empty());
693     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandlePointerEventInner(point));
694 }
695 
696 /**
697  * @tc.name: EventDispatchTest_DispatchKeyEventPid_001
698  * @tc.desc: Test the function DispatchKeyEventPid
699  * @tc.type: FUNC
700  * @tc.require:
701  */
702 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchKeyEventPid_001, TestSize.Level1)
703 {
704     EventDispatchHandler eventdispatchhandler;
705     UDSServer udsServer;
706     int32_t keyevent = 3;
707     KeyEvent* keyEvent = new KeyEvent(keyevent);
708     std::shared_ptr<KeyEvent> sharedKeyEvent(keyEvent);
709     int32_t ret = eventdispatchhandler.DispatchKeyEventPid(udsServer, sharedKeyEvent);
710     EXPECT_EQ(ret, RET_OK);
711 }
712 
713 /**
714  * @tc.name: EventDispatchTest_AcquireEnableMark
715  * @tc.desc: Test Acquire Enable Mark
716  * @tc.type: FUNC
717  * @tc.require:
718  */
719 HWTEST_F(EventDispatchTest, EventDispatchTest_AcquireEnableMark, TestSize.Level1)
720 {
721     EventDispatchHandler dispatch;
722     std::shared_ptr<PointerEvent> event = PointerEvent::Create();
723     ASSERT_NE(event, nullptr);
724     event->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
725     ASSERT_FALSE(dispatch.AcquireEnableMark(event));
726     event->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
727     ASSERT_TRUE(dispatch.AcquireEnableMark(event));
728 }
729 
730 /**
731  * @tc.name: EventDispatchTest_DispatchPointerEventInner_001
732  * @tc.desc: Test Dispatch Pointer Event Inner
733  * @tc.type: FUNC
734  * @tc.require:
735  */
736 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchPointerEventInner_001, TestSize.Level1)
737 {
738     EventDispatchHandler dispatch;
739     int32_t fd = -1;
740     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
741     ASSERT_NE(pointerEvent, nullptr);
742     dispatch.eventTime_ = 1000;
743     pointerEvent->SetActionTime(5000);
744     ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd));
745 }
746 
747 /**
748  * @tc.name: EventDispatchTest_DispatchPointerEventInner_002
749  * @tc.desc: Test Dispatch Pointer Event Inner
750  * @tc.type: FUNC
751  * @tc.require:
752  */
753 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchPointerEventInner_002, TestSize.Level1)
754 {
755     EventDispatchHandler dispatch;
756     int32_t fd = -1;
757     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
758     ASSERT_NE(pointerEvent, nullptr);
759     int32_t currentTime = dispatch.currentTime_;
760     int32_t eventTime = dispatch.eventTime_;
761     int32_t INTERVAL_TIME = 3000;
762     currentTime = 6000;
763     eventTime = 1000;
764     EXPECT_TRUE(currentTime - eventTime > INTERVAL_TIME);
765     ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd));
766 }
767 
768 /**
769  * @tc.name: EventDispatchTest_DispatchPointerEventInner_003
770  * @tc.desc: Test Dispatch Pointer Event Inner
771  * @tc.type: FUNC
772  * @tc.require:
773  */
774 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchPointerEventInner_003, TestSize.Level1)
775 {
776     EventDispatchHandler dispatch;
777     int32_t fd = 1;
778     std::shared_ptr<PointerEvent> point = PointerEvent::Create();
779     ASSERT_NE(point, nullptr);
780     int32_t pointerAction;
781     pointerAction = PointerEvent::POINTER_ACTION_DOWN;
782     ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(point, fd));
783 }
784 
785 /**
786  * @tc.name: EventDispatchTest_DispatchPointerEventInner_004
787  * @tc.desc: Test Dispatch Pointer Event Inner
788  * @tc.type: FUNC
789  * @tc.require:
790  */
791 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchPointerEventInner_004, TestSize.Level1)
792 {
793     EventDispatchHandler dispatch;
794     SessionPtr sess = nullptr;
795     int32_t fd = 1;
796     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
797     ASSERT_NE(pointerEvent, nullptr);
798 
799     int32_t type = 0;
800     int64_t time = 3000;
801     sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
802     bool ret = ANRMgr->TriggerANR(type, time, sess);
803     EXPECT_FALSE(ret);
804     ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd));
805 }
806 
807 /**
808  * @tc.name: EventDispatchTest_DispatchPointerEventInner_005
809  * @tc.desc: Test Dispatch Pointer Event Inner
810  * @tc.type: FUNC
811  * @tc.require:
812  */
813 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchPointerEventInner_005, TestSize.Level1)
814 {
815     EventDispatchHandler dispatch;
816     SessionPtr sess = nullptr;
817     int32_t fd = 1;
818     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
819     ASSERT_NE(pointerEvent, nullptr);
820 
821     int32_t type = 0;
822     int64_t time = 3000;
823     sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
824     bool ret = ANRMgr->TriggerANR(type, time, sess);
825     EXPECT_FALSE(ret);
826 
827     pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_DOWN;
828     ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd));
829 }
830 
831 /**
832  * @tc.name: EventDispatchTest_DispatchPointerEventInner_006
833  * @tc.desc: Test Dispatch Pointer Event Inner
834  * @tc.type: FUNC
835  * @tc.require:
836  */
837 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchPointerEventInner_006, TestSize.Level1)
838 {
839     EventDispatchHandler dispatch;
840     SessionPtr sess = nullptr;
841     int32_t fd = 2;
842     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
843     ASSERT_NE(pointerEvent, nullptr);
844 
845     int32_t type = 0;
846     int64_t time = 3000;
847     sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
848     bool ret = ANRMgr->TriggerANR(type, time, sess);
849     EXPECT_FALSE(ret);
850 
851     pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_UP;
852     ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd));
853 }
854 
855 /**
856  * @tc.name: EventDispatchTest_DispatchPointerEventInner_007
857  * @tc.desc: Test Dispatch Pointer Event Inner
858  * @tc.type: FUNC
859  * @tc.require:
860  */
861 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchPointerEventInner_007, TestSize.Level1)
862 {
863     EventDispatchHandler dispatch;
864     SessionPtr sess = nullptr;
865     int32_t fd = 2;
866     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
867     ASSERT_NE(pointerEvent, nullptr);
868 
869     int32_t type = 0;
870     int64_t time = 3000;
871     sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
872     bool ret = ANRMgr->TriggerANR(type, time, sess);
873     EXPECT_FALSE(ret);
874 
875     pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_PULL_DOWN;
876     ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd));
877 }
878 
879 /**
880  * @tc.name: EventDispatchTest_DispatchPointerEventInner_008
881  * @tc.desc: Test Dispatch Pointer Event Inner
882  * @tc.type: FUNC
883  * @tc.require:
884  */
885 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchPointerEventInner_008, TestSize.Level1)
886 {
887     EventDispatchHandler dispatch;
888     SessionPtr sess = nullptr;
889     int32_t fd = 2;
890     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
891     ASSERT_NE(pointerEvent, nullptr);
892 
893     int32_t type = 0;
894     int64_t time = 3000;
895     sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
896     bool ret = ANRMgr->TriggerANR(type, time, sess);
897     EXPECT_FALSE(ret);
898 
899     pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_PULL_UP;
900     ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd));
901 }
902 
903 /**
904  * @tc.name: EventDispatchTest_DispatchPointerEventInner_009
905  * @tc.desc: Test Dispatch Pointer Event Inner
906  * @tc.type: FUNC
907  * @tc.require:
908  */
909 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchPointerEventInner_009, TestSize.Level1)
910 {
911     EventDispatchHandler dispatch;
912     SessionPtr sess = nullptr;
913     int32_t fd = 2;
914     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
915     ASSERT_NE(pointerEvent, nullptr);
916 
917     int32_t type = 0;
918     int64_t time = 3000;
919     sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
920     bool ret = ANRMgr->TriggerANR(type, time, sess);
921     EXPECT_FALSE(ret);
922 
923     pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_MOVE;
924     ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd));
925 }
926 
927 /**
928  * @tc.name: EventDispatchTest_DispatchKeyEventPid_002
929  * @tc.desc: Test Dispatch Key Event Pid
930  * @tc.type: FUNC
931  * @tc.require:
932  */
933 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchKeyEventPid_002, TestSize.Level1)
934 {
935     EventDispatchHandler dispatch;
936     UDSServer udsServer;
937     std::shared_ptr<KeyEvent> KeyEvent = KeyEvent::Create();
938     ASSERT_NE(KeyEvent, nullptr);
939     dispatch.eventTime_ = 1000;
940     KeyEvent->SetActionTime(5000);
941     ASSERT_EQ(dispatch.DispatchKeyEventPid(udsServer, KeyEvent), RET_OK);
942 }
943 
944 /**
945  * @tc.name: EventDispatchTest_DispatchKeyEventPid_003
946  * @tc.desc: Test DispatchKeyEventPid
947  * @tc.type: FUNC
948  * @tc.require:
949  */
950 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchKeyEventPid_003, TestSize.Level1)
951 {
952     EventDispatchHandler dispatch;
953     UDSServer udsServer;
954     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
955     ASSERT_NE(keyEvent, nullptr);
956     int32_t currentTime = dispatch.currentTime_;
957     int32_t eventTime = dispatch.eventTime_;
958     int32_t INTERVAL_TIME = 3000;
959     currentTime = 6000;
960     eventTime = 1000;
961     EXPECT_TRUE(currentTime - eventTime > INTERVAL_TIME);
962     int32_t ret = dispatch.DispatchKeyEventPid(udsServer, keyEvent);
963     EXPECT_EQ(ret, RET_OK);
964 }
965 
966 /**
967  * @tc.name: EventDispatchTest_DispatchKeyEventPid_004
968  * @tc.desc: Test DispatchKeyEventPid
969  * @tc.type: FUNC
970  * @tc.require:
971  */
972 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchKeyEventPid_004, TestSize.Level1)
973 {
974     EventDispatchHandler dispatch;
975     UDSServer udsServer;
976     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
977     ASSERT_NE(keyEvent, nullptr);
978 
979     NetPacket pkt(MmiMessageId::INVALID);
980     EXPECT_FALSE(pkt.ChkRWError());
981     int32_t ret = dispatch.DispatchKeyEventPid(udsServer, keyEvent);
982     EXPECT_EQ(ret, RET_OK);
983 }
984 
985 /**
986  * @tc.name: EventDispatchTest_DispatchKeyEventPid_005
987  * @tc.desc: Test DispatchKeyEventPid
988  * @tc.type: FUNC
989  * @tc.require:
990  */
991 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchKeyEventPid_005, TestSize.Level1)
992 {
993     EventDispatchHandler dispatch;
994     UDSServer udsServer;
995     SessionPtr sess = nullptr;
996     std::shared_ptr<KeyEvent> KeyEvent = KeyEvent::Create();
997     ASSERT_NE(KeyEvent, nullptr);
998     dispatch.eventTime_ = 1000;
999     KeyEvent->SetActionTime(2000);
1000 
1001     int32_t type = 0;
1002     int64_t time = 2000;
1003     sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
1004     bool ret = ANRMgr->TriggerANR(type, time, sess);
1005     EXPECT_FALSE(ret);
1006 
1007     ASSERT_EQ(dispatch.DispatchKeyEventPid(udsServer, KeyEvent), RET_OK);
1008 }
1009 
1010 /**
1011  * @tc.name: EventDispatchTest_ReissueEvent_001
1012  * @tc.desc: Test ReissueEvent
1013  * @tc.type: FUNC
1014  * @tc.require:
1015  */
1016 HWTEST_F(EventDispatchTest, EventDispatchTest_ReissueEvent_001, TestSize.Level1)
1017 {
1018     EventDispatchHandler dispatch;
1019     std::shared_ptr<PointerEvent> point = PointerEvent::Create();
1020     ASSERT_NE(point, nullptr);
1021     point->pointerAction_ = PointerEvent::POINTER_ACTION_UP;
1022     int32_t windowId = 100;
1023     std::optional<WindowInfo> windowInfo = std::nullopt;
1024     bool result = dispatch.ReissueEvent(point, windowId, windowInfo);
1025     EXPECT_FALSE(result);
1026 }
1027 
1028 /**
1029  * @tc.name: EventDispatchTest_ReissueEvent_002
1030  * @tc.desc: Test ReissueEvent
1031  * @tc.type: FUNC
1032  * @tc.require:
1033  */
1034 HWTEST_F(EventDispatchTest, EventDispatchTest_ReissueEvent_002, TestSize.Level1)
1035 {
1036     EventDispatchHandler dispatch;
1037     std::shared_ptr<PointerEvent> point = PointerEvent::Create();
1038     ASSERT_NE(point, nullptr);
1039     point->pointerAction_ = PointerEvent::POINTER_ACTION_DOWN;
1040     int32_t windowId = 100;
1041     std::optional<WindowInfo> windowInfo = std::nullopt;
1042     bool result = dispatch.ReissueEvent(point, windowId, windowInfo);
1043     EXPECT_FALSE(result);
1044 }
1045 
1046 /**
1047  * @tc.name: EventDispatchTest_ReissueEvent_003
1048  * @tc.desc: Test ReissueEvent
1049  * @tc.type: FUNC
1050  * @tc.require:
1051  */
1052 HWTEST_F(EventDispatchTest, EventDispatchTest_ReissueEvent_003, TestSize.Level1)
1053 {
1054     EventDispatchHandler handler;
1055     std::shared_ptr<PointerEvent> point = PointerEvent::Create();
1056     ASSERT_NE(point, nullptr);
1057     point->pointerAction_ = PointerEvent::POINTER_ACTION_UP;
1058     int32_t windowId = 1;
1059     point->pointerId_ = 1;
1060     point->SetPointerId(point->pointerId_);
1061     std::optional<WindowInfo> windowInfo = std::nullopt;
1062     std::shared_ptr<WindowInfo> windowInfo1 = std::make_shared<WindowInfo>();
1063     windowInfo1->id = 1;
1064     handler.cancelEventList_[1].push_back(windowInfo1);
1065     bool result = handler.ReissueEvent(point, windowId, windowInfo);
1066     EXPECT_TRUE(result);
1067 }
1068 
1069 /**
1070  * @tc.name: EventDispatchTest_ReissueEvent_004
1071  * @tc.desc: Test ReissueEvent
1072  * @tc.type: FUNC
1073  * @tc.require:
1074  */
1075 HWTEST_F(EventDispatchTest, EventDispatchTest_ReissueEvent_004, TestSize.Level1)
1076 {
1077     EventDispatchHandler handler;
1078     std::shared_ptr<PointerEvent> point = PointerEvent::Create();
1079     ASSERT_NE(point, nullptr);
1080     point->pointerAction_ = PointerEvent::POINTER_ACTION_DOWN;
1081     int32_t windowId = 1;
1082     point->pointerId_ = 1;
1083     point->SetPointerId(point->pointerId_);
1084     std::optional<WindowInfo> windowInfo = std::nullopt;
1085     std::shared_ptr<WindowInfo> windowInfo1 = std::make_shared<WindowInfo>();
1086     windowInfo1->id = 1;
1087     handler.cancelEventList_[1].push_back(windowInfo1);
1088     bool result = handler.ReissueEvent(point, windowId, windowInfo);
1089     EXPECT_FALSE(result);
1090 }
1091 
1092 /**
1093  * @tc.name: EventDispatchTest_ReissueEvent_005
1094  * @tc.desc: Test ReissueEvent
1095  * @tc.type: FUNC
1096  * @tc.require:
1097  */
1098 HWTEST_F(EventDispatchTest, EventDispatchTest_ReissueEvent_005, TestSize.Level1)
1099 {
1100     EventDispatchHandler dispatch;
1101     std::shared_ptr<PointerEvent> point = PointerEvent::Create();
1102     ASSERT_NE(point, nullptr);
1103     point->pointerAction_ = PointerEvent::POINTER_ACTION_DOWN;
1104     int32_t windowId = 100;
1105     std::optional<WindowInfo> windowInfo = std::make_optional<WindowInfo>();
1106     ASSERT_NE(windowInfo, std::nullopt);
1107     point->pointerId_ = 1;
1108     point->SetPointerId(point->pointerId_);
1109     std::shared_ptr<WindowInfo> windowInfo1 = std::make_shared<WindowInfo>();
1110     windowInfo1->id = 1;
1111     dispatch.cancelEventList_[1].push_back(windowInfo1);
1112     bool result = dispatch.ReissueEvent(point, windowId, windowInfo);
1113     EXPECT_TRUE(result);
1114 }
1115 
1116 /**
1117  * @tc.name: EventDispatchTest_ReissueEvent_006
1118  * @tc.desc: Test ReissueEvent
1119  * @tc.type: FUNC
1120  * @tc.require:
1121  */
1122 HWTEST_F(EventDispatchTest, EventDispatchTest_ReissueEvent_006, TestSize.Level1)
1123 {
1124     EventDispatchHandler dispatch;
1125     std::shared_ptr<PointerEvent> point = PointerEvent::Create();
1126     ASSERT_NE(point, nullptr);
1127     point->pointerAction_ = PointerEvent::POINTER_ACTION_DOWN;
1128     int32_t windowId = 100;
1129     std::optional<WindowInfo> windowInfo = std::make_optional<WindowInfo>();
1130     ASSERT_NE(windowInfo, std::nullopt);
1131     point->pointerId_ = 5;
1132     point->SetPointerId(point->pointerId_);
1133     std::shared_ptr<WindowInfo> windowInfo1 = std::make_shared<WindowInfo>();
1134     windowInfo1->id = 1;
1135     dispatch.cancelEventList_[1].push_back(windowInfo1);
1136     bool result = dispatch.ReissueEvent(point, windowId, windowInfo);
1137     EXPECT_TRUE(result);
1138 }
1139 
1140 /**
1141  * @tc.name: EventDispatchTest_ReissueEvent_007
1142  * @tc.desc: Test ReissueEvent
1143  * @tc.type: FUNC
1144  * @tc.require:
1145  */
1146 HWTEST_F(EventDispatchTest, EventDispatchTest_ReissueEvent_007, TestSize.Level1)
1147 {
1148     EventDispatchHandler dispatch;
1149     std::shared_ptr<PointerEvent> point = PointerEvent::Create();
1150     ASSERT_NE(point, nullptr);
1151     point->pointerAction_ = PointerEvent::POINTER_ACTION_UP;
1152     int32_t windowId = 100;
1153     std::optional<WindowInfo> windowInfo = std::make_optional<WindowInfo>();
1154     ASSERT_NE(windowInfo, std::nullopt);
1155     point->pointerId_ = 1;
1156     point->SetPointerId(point->pointerId_);
1157     std::shared_ptr<WindowInfo> windowInfo1 = std::make_shared<WindowInfo>();
1158     windowInfo1->id = 1;
1159     dispatch.cancelEventList_[1].push_back(windowInfo1);
1160     bool result = dispatch.ReissueEvent(point, windowId, windowInfo);
1161     EXPECT_FALSE(result);
1162 }
1163 
1164 /**
1165  * @tc.name: EventDispatchTest_ReissueEvent_008
1166  * @tc.desc: Test ReissueEvent
1167  * @tc.type: FUNC
1168  * @tc.require:
1169  */
1170 HWTEST_F(EventDispatchTest, EventDispatchTest_ReissueEvent_008, TestSize.Level1)
1171 {
1172     EventDispatchHandler dispatch;
1173     std::shared_ptr<PointerEvent> point = PointerEvent::Create();
1174     ASSERT_NE(point, nullptr);
1175     point->pointerAction_ = PointerEvent::POINTER_ACTION_UP;
1176     int32_t windowId = 100;
1177     std::optional<WindowInfo> windowInfo = std::make_optional<WindowInfo>();
1178     ASSERT_NE(windowInfo, std::nullopt);
1179     point->pointerId_ = 5;
1180     point->SetPointerId(point->pointerId_);
1181     std::shared_ptr<WindowInfo> windowInfo1 = std::make_shared<WindowInfo>();
1182     windowInfo1->id = 1;
1183     dispatch.cancelEventList_[1].push_back(windowInfo1);
1184     bool result = dispatch.ReissueEvent(point, windowId, windowInfo);
1185     EXPECT_FALSE(result);
1186 }
1187 
1188 /**
1189  * @tc.name: EventDispatchTest_ReissueEvent_009
1190  * @tc.desc: Test ReissueEvent
1191  * @tc.type: FUNC
1192  * @tc.require:
1193  */
1194 HWTEST_F(EventDispatchTest, EventDispatchTest_ReissueEvent_009, TestSize.Level1)
1195 {
1196     EventDispatchHandler dispatch;
1197     std::shared_ptr<PointerEvent> point = PointerEvent::Create();
1198     ASSERT_NE(point, nullptr);
1199     point->pointerAction_ = PointerEvent::POINTER_ACTION_CANCEL;
1200     int32_t windowId = 100;
1201     std::optional<WindowInfo> windowInfo = std::make_optional<WindowInfo>();
1202     ASSERT_NE(windowInfo, std::nullopt);
1203     point->pointerId_ = 5;
1204     point->SetPointerId(point->pointerId_);
1205     std::shared_ptr<WindowInfo> windowInfo1 = std::make_shared<WindowInfo>();
1206     windowInfo1->id = 1;
1207     dispatch.cancelEventList_[1].push_back(windowInfo1);
1208     bool result = dispatch.ReissueEvent(point, windowId, windowInfo);
1209     EXPECT_FALSE(result);
1210 }
1211 
1212 /**
1213  * @tc.name: EventDispatchTest_ReissueEvent_010
1214  * @tc.desc: Test ReissueEvent
1215  * @tc.type: FUNC
1216  * @tc.require:
1217  */
1218 HWTEST_F(EventDispatchTest, EventDispatchTest_ReissueEvent_010, TestSize.Level1)
1219 {
1220     EventDispatchHandler dispatch;
1221     std::shared_ptr<PointerEvent> point = PointerEvent::Create();
1222     ASSERT_NE(point, nullptr);
1223     point->pointerAction_ = PointerEvent::POINTER_ACTION_CANCEL;
1224     int32_t windowId = 100;
1225     std::optional<WindowInfo> windowInfo = std::make_optional<WindowInfo>();
1226     ASSERT_NE(windowInfo, std::nullopt);
1227     point->pointerId_ = 1;
1228     point->SetPointerId(point->pointerId_);
1229     std::shared_ptr<WindowInfo> windowInfo1 = std::make_shared<WindowInfo>();
1230     windowInfo1->id = 1;
1231     dispatch.cancelEventList_[1].push_back(windowInfo1);
1232     bool result = dispatch.ReissueEvent(point, windowId, windowInfo);
1233     EXPECT_FALSE(result);
1234 }
1235 
1236 /**
1237  * @tc.name: EventDispatchTest_ReissueEvent_011
1238  * @tc.desc: Test ReissueEvent
1239  * @tc.type: FUNC
1240  * @tc.require:
1241  */
1242 HWTEST_F(EventDispatchTest, EventDispatchTest_ReissueEvent_011, TestSize.Level1)
1243 {
1244     EventDispatchHandler dispatch;
1245     std::shared_ptr<PointerEvent> point = PointerEvent::Create();
1246     ASSERT_NE(point, nullptr);
1247     point->pointerAction_ = PointerEvent::POINTER_ACTION_MOVE;
1248     int32_t windowId = 100;
1249     std::optional<WindowInfo> windowInfo = std::make_optional<WindowInfo>();
1250     ASSERT_NE(windowInfo, std::nullopt);
1251     point->pointerId_ = 1;
1252     point->SetPointerId(point->pointerId_);
1253     std::shared_ptr<WindowInfo> windowInfo1 = std::make_shared<WindowInfo>();
1254     windowInfo1->id = 1;
1255     dispatch.cancelEventList_[1].push_back(windowInfo1);
1256     bool result = dispatch.ReissueEvent(point, windowId, windowInfo);
1257     EXPECT_TRUE(result);
1258 }
1259 
1260 /**
1261  * @tc.name: EventDispatchTest_SearchCancelList_001
1262  * @tc.desc: Test SearchCancelList
1263  * @tc.type: FUNC
1264  * @tc.require:
1265  */
1266 HWTEST_F(EventDispatchTest, EventDispatchTest_SearchCancelList_001, TestSize.Level1)
1267 {
1268     EventDispatchHandler handler;
1269     int32_t pointerId = 1;
1270     int32_t windowId = 2;
1271     std::shared_ptr<WindowInfo> result = handler.SearchCancelList(pointerId, windowId);
1272     ASSERT_EQ(result, nullptr);
1273 }
1274 
1275 /**
1276  * @tc.name: EventDispatchTest_SearchCancelList_002
1277  * @tc.desc: Test SearchCancelList
1278  * @tc.type: FUNC
1279  * @tc.require:
1280  */
1281 HWTEST_F(EventDispatchTest, EventDispatchTest_SearchCancelList_002, TestSize.Level1)
1282 {
1283     EventDispatchHandler handler;
1284     int32_t pointerId = 5;
1285     int32_t windowId = 2;
1286     std::shared_ptr<WindowInfo> windowInfo1 = std::make_shared<WindowInfo>();
1287     windowInfo1->id = 1;
1288     handler.cancelEventList_[1].push_back(windowInfo1);
1289     std::shared_ptr<WindowInfo> result = handler.SearchCancelList(pointerId, windowId);
1290     ASSERT_EQ(result, nullptr);
1291 }
1292 
1293 /**
1294  * @tc.name: EventDispatchTest_SearchCancelList_003
1295  * @tc.desc: Test SearchCancelList
1296  * @tc.type: FUNC
1297  * @tc.require:
1298  */
1299 HWTEST_F(EventDispatchTest, EventDispatchTest_SearchCancelList_003, TestSize.Level1)
1300 {
1301     EventDispatchHandler handler;
1302     int32_t pointerId = 1;
1303     int32_t windowId = 1;
1304     std::shared_ptr<WindowInfo> windowInfo1 = std::make_shared<WindowInfo>();
1305     windowInfo1->id = 1;
1306     handler.cancelEventList_[1].push_back(windowInfo1);
1307     std::shared_ptr<WindowInfo> result = handler.SearchCancelList(pointerId, windowId);
1308     ASSERT_NE(result, nullptr);
1309 }
1310 
1311 /**
1312  * @tc.name: EventDispatchTest_FilterInvalidPointerItem_004
1313  * @tc.desc: Test the function FilterInvalidPointerItem
1314  * @tc.type: FUNC
1315  * @tc.require:
1316  */
1317 HWTEST_F(EventDispatchTest, EventDispatchTest_FilterInvalidPointerItem_004, TestSize.Level1)
1318 {
1319     EventDispatchHandler eventdispatchhandler;
1320     int32_t fd = 1;
1321     int32_t eventType = 3;
1322     UDSServer* udsServer = new UDSServer();
1323     InputHandler->udsServer_ = udsServer;
1324     std::shared_ptr<PointerEvent> sharedPointerEvent = std::make_shared<PointerEvent>(eventType);
1325     EXPECT_NE(sharedPointerEvent, nullptr);
1326     std::vector<int32_t> pointerIdList;
1327     EXPECT_FALSE(pointerIdList.size() > 1);
1328     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.FilterInvalidPointerItem(sharedPointerEvent, fd));
1329 }
1330 
1331 /**
1332  * @tc.name: EventDispatchTest_FilterInvalidPointerItem_005
1333  * @tc.desc: Test the function FilterInvalidPointerItem
1334  * @tc.type: FUNC
1335  * @tc.require:
1336  */
1337 HWTEST_F(EventDispatchTest, EventDispatchTest_FilterInvalidPointerItem_005, TestSize.Level1)
1338 {
1339     EventDispatchHandler eventdispatchhandler;
1340     PointerEvent::PointerItem testPointerItem;
1341     UDSServer* udsServer = new UDSServer();
1342     InputHandler->udsServer_ = udsServer;
1343     int32_t fd = 1;
1344     int32_t eventType = 3;
1345     std::shared_ptr<PointerEvent> event = std::make_shared<PointerEvent>(eventType);
1346     event->pointers_.push_back(PointerEvent::PointerItem());
1347     event->pointers_.push_back(PointerEvent::PointerItem());
1348     std::vector<int32_t> pointerIds = event->GetPointerIds();
1349     ASSERT_TRUE(pointerIds.size() > 1);
1350     event->AddPointerItem(testPointerItem);
1351     int32_t testPointerId = 1;
1352     testPointerItem.SetPointerId(testPointerId);
1353     event->AddPointerItem(testPointerItem);
1354     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.FilterInvalidPointerItem(event, fd));
1355 }
1356 
1357 /**
1358  * @tc.name: EventDispatchTest_FilterInvalidPointerItem_006
1359  * @tc.desc: Test the function FilterInvalidPointerItem
1360  * @tc.type: FUNC
1361  * @tc.require:
1362  */
1363 HWTEST_F(EventDispatchTest, EventDispatchTest_FilterInvalidPointerItem_006, TestSize.Level1)
1364 {
1365     EventDispatchHandler eventdispatchhandler;
1366     PointerEvent::PointerItem testPointerItem;
1367     UDSServer* udsServer = new UDSServer();
1368     InputHandler->udsServer_ = udsServer;
1369     int32_t fd = 1;
1370     int32_t eventType = 3;
1371     std::shared_ptr<PointerEvent> event = std::make_shared<PointerEvent>(eventType);
1372     event->pointers_.push_back(PointerEvent::PointerItem());
1373     event->pointers_.push_back(PointerEvent::PointerItem());
1374     std::vector<int32_t> pointerIds = event->GetPointerIds();
1375     ASSERT_TRUE(pointerIds.size() > 1);
1376     event->AddPointerItem(testPointerItem);
1377     int32_t testPointerId = 1;
1378     testPointerItem.SetPointerId(testPointerId + 1);
1379     event->AddPointerItem(testPointerItem);
1380     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.FilterInvalidPointerItem(event, fd));
1381 }
1382 
1383 /**
1384  * @tc.name: EventDispatchTest_FilterInvalidPointerItem_007
1385  * @tc.desc: Test the function FilterInvalidPointerItem
1386  * @tc.type: FUNC
1387  * @tc.require:
1388  */
1389 HWTEST_F(EventDispatchTest, EventDispatchTest_FilterInvalidPointerItem_007, TestSize.Level1)
1390 {
1391     EventDispatchHandler eventdispatchhandler;
1392     int32_t fd = 1;
1393     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
1394     ASSERT_NE(pointerEvent, nullptr);
1395     UDSServer udsServer;
1396     InputHandler->udsServer_ = &udsServer;
1397     PointerEvent::PointerItem testPointerItem;
1398     testPointerItem.pointerId_ = -1;
1399     pointerEvent->pointers_.push_back(testPointerItem);
1400     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.FilterInvalidPointerItem(pointerEvent, fd));
1401     testPointerItem.pressed_ = false;
1402     testPointerItem.displayX_ = 50;
1403     testPointerItem.displayY_ = 100;
1404     pointerEvent->pointers_.push_back(testPointerItem);
1405     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.FilterInvalidPointerItem(pointerEvent, fd));
1406 }
1407 
1408 /**
1409  * @tc.name: EventDispatchTest_HandleMultiWindowPointerEvent_007
1410  * @tc.desc: Test the function HandleMultiWindowPointerEvent
1411  * @tc.type: FUNC
1412  * @tc.require:
1413  */
1414 HWTEST_F(EventDispatchTest, EventDispatchTest_HandleMultiWindowPointerEvent_007, TestSize.Level1)
1415 {
1416     EventDispatchHandler eventdispatchhandler;
1417     std::shared_ptr<PointerEvent> point = PointerEvent::Create();
1418     ASSERT_NE(point, nullptr);
1419     PointerEvent::PointerItem pointerItem;
1420     pointerItem.SetWindowX(35);
1421     pointerItem.SetWindowY(50);
1422     pointerItem.SetTargetWindowId(2);
1423     point->pointerAction_ = PointerEvent::POINTER_ACTION_DOWN;
1424     point->pointerId_ = 1;
1425     std::shared_ptr<WindowInfo> windowInfo = std::make_shared<WindowInfo>();
1426     windowInfo->id = 5;
1427     eventdispatchhandler.cancelEventList_[1].push_back(windowInfo);
1428     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleMultiWindowPointerEvent(point, pointerItem));
1429     windowInfo->id = 1;
1430     eventdispatchhandler.cancelEventList_[2].push_back(windowInfo);
1431     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleMultiWindowPointerEvent(point, pointerItem));
1432     point->pointerAction_ = PointerEvent::POINTER_ACTION_MOVE;
1433     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleMultiWindowPointerEvent(point, pointerItem));
1434     point->pointerAction_ = PointerEvent::POINTER_ACTION_UP;
1435     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleMultiWindowPointerEvent(point, pointerItem));
1436     point->pointerAction_ = PointerEvent::POINTER_ACTION_PULL_UP;
1437     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleMultiWindowPointerEvent(point, pointerItem));
1438     point->pointerAction_ = PointerEvent::POINTER_ACTION_CANCEL;
1439     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleMultiWindowPointerEvent(point, pointerItem));
1440 }
1441 
1442 /**
1443  * @tc.name: EventDispatchTest_DispatchPointerEventInner_010
1444  * @tc.desc: Test the function DispatchPointerEventInner
1445  * @tc.type: FUNC
1446  * @tc.require:
1447  */
1448 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchPointerEventInner_010, TestSize.Level1)
1449 {
1450     EventDispatchHandler eventDispatchHandler;
1451     int32_t fd = 2;
1452     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
1453     ASSERT_NE(pointerEvent, nullptr);
1454     UDSServer udsServer;
1455     InputHandler->udsServer_ = &udsServer;
1456     SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
1457     udsServer.sessionsMap_.insert(std::make_pair(fd, session));
1458     pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_DOWN;
1459     ASSERT_NO_FATAL_FAILURE(eventDispatchHandler.DispatchPointerEventInner(pointerEvent, fd));
1460     pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_UP;
1461     ASSERT_NO_FATAL_FAILURE(eventDispatchHandler.DispatchPointerEventInner(pointerEvent, fd));
1462     pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_PULL_DOWN;
1463     ASSERT_NO_FATAL_FAILURE(eventDispatchHandler.DispatchPointerEventInner(pointerEvent, fd));
1464     pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_PULL_UP;
1465     ASSERT_NO_FATAL_FAILURE(eventDispatchHandler.DispatchPointerEventInner(pointerEvent, fd));
1466     pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW;
1467     ASSERT_NO_FATAL_FAILURE(eventDispatchHandler.DispatchPointerEventInner(pointerEvent, fd));
1468     pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_MOVE;
1469     ASSERT_NO_FATAL_FAILURE(eventDispatchHandler.DispatchPointerEventInner(pointerEvent, fd));
1470     fd = -2;
1471     ASSERT_NO_FATAL_FAILURE(eventDispatchHandler.DispatchPointerEventInner(pointerEvent, fd));
1472     fd = 5;
1473     udsServer.sessionsMap_.insert(std::make_pair(5, session));
1474     ASSERT_NO_FATAL_FAILURE(eventDispatchHandler.DispatchPointerEventInner(pointerEvent, fd));
1475 }
1476 
1477 /**
1478  * @tc.name: EventDispatchTest_DispatchKeyEventPid_006
1479  * @tc.desc: Test the function DispatchKeyEventPid
1480  * @tc.type: FUNC
1481  * @tc.require:
1482  */
1483 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchKeyEventPid_006, TestSize.Level1)
1484 {
1485     EventDispatchHandler eventDispatchHandler;
1486     UDSServer udsServer;
1487     std::shared_ptr<KeyEvent> KeyEvent = KeyEvent::Create();
1488     ASSERT_NE(KeyEvent, nullptr);
1489     ASSERT_EQ(eventDispatchHandler.DispatchKeyEventPid(udsServer, KeyEvent), RET_OK);
1490     SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
1491     udsServer.sessionsMap_.insert(std::make_pair(-1, session));
1492     StreamBuffer streamBuffer;
1493     streamBuffer.rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_READ;
1494     eventDispatchHandler.DispatchKeyEventPid(udsServer, KeyEvent);
1495     streamBuffer.rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_READ;
1496     ASSERT_EQ(eventDispatchHandler.DispatchKeyEventPid(udsServer, KeyEvent), RET_OK);
1497 }
1498 
1499 /**
1500  * @tc.name: DispatchPointerEventInner_06
1501  * @tc.desc: Test the funcation DispatchKeyEvent
1502  * @tc.type: FUNC
1503  * @tc.require:
1504  */
1505 HWTEST_F(EventDispatchTest, DispatchPointerEventInner_06, TestSize.Level1)
1506 {
1507     EventDispatchHandler handler;
1508     std::shared_ptr<PointerEvent> point = PointerEvent::Create();
1509     ASSERT_NE(point, nullptr);
1510     int32_t fd = -5;
1511     auto inputEvent = InputEvent::Create();
1512     ASSERT_NE(inputEvent, nullptr);
1513     inputEvent->actionTime_ = 3100;
1514     handler.eventTime_ = 10;
1515     ASSERT_NO_FATAL_FAILURE(handler.DispatchPointerEventInner(point, fd));
1516     inputEvent->actionTime_ = 200;
1517     ASSERT_NO_FATAL_FAILURE(handler.DispatchPointerEventInner(point, fd));
1518     fd = 5;
1519     bool status = true;
1520     SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, 1, 1, 100, 100);
1521     session->SetTokenType(TokenType::TOKEN_HAP);
1522     session->SetAnrStatus(0, status);
1523     ASSERT_NO_FATAL_FAILURE(handler.DispatchPointerEventInner(point, fd));
1524     status = false;
1525     point->pointerAction_ = PointerEvent::POINTER_ACTION_DOWN;
1526     ASSERT_NO_FATAL_FAILURE(handler.DispatchPointerEventInner(point, fd));
1527     point->pointerAction_ = PointerEvent::POINTER_ACTION_UP;
1528     ASSERT_NO_FATAL_FAILURE(handler.DispatchPointerEventInner(point, fd));
1529     point->pointerAction_ = PointerEvent::POINTER_ACTION_PULL_DOWN;
1530     ASSERT_NO_FATAL_FAILURE(handler.DispatchPointerEventInner(point, fd));
1531     point->pointerAction_ = PointerEvent::POINTER_ACTION_PULL_UP;
1532     ASSERT_NO_FATAL_FAILURE(handler.DispatchPointerEventInner(point, fd));
1533     point->pointerAction_ = PointerEvent::POINTER_ACTION_PULL_MOVE;
1534     ASSERT_NO_FATAL_FAILURE(handler.DispatchPointerEventInner(point, fd));
1535     point->pointerAction_ = PointerEvent::POINTER_ACTION_MOVE;
1536     ASSERT_NO_FATAL_FAILURE(handler.DispatchPointerEventInner(point, fd));
1537     point->pointerAction_ = PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW;
1538     ASSERT_NO_FATAL_FAILURE(handler.DispatchPointerEventInner(point, fd));
1539     point->pointerAction_ = PointerEvent::POINTER_ACTION_AXIS_END;
1540     ASSERT_NO_FATAL_FAILURE(handler.DispatchPointerEventInner(point, fd));
1541 }
1542 
1543 /**
1544  * @tc.name: EventDispatchTest_DispatchKeyEvent_001
1545  * @tc.desc: Test the funcation DispatchKeyEvent
1546  * @tc.type: FUNC
1547  * @tc.require:
1548  */
1549 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchKeyEvent_001, TestSize.Level1)
1550 {
1551     EventDispatchHandler handler;
1552     int32_t fd = -2;
1553     UDSServer udsServer;
1554     std::shared_ptr<KeyEvent> key = KeyEvent::Create();
1555     ASSERT_NE(key, nullptr);
1556     auto inputEvent = InputEvent::Create();
1557     ASSERT_NE(inputEvent, nullptr);
1558     inputEvent->actionTime_ = 4000;
1559     handler.eventTime_ = 200;
1560     int32_t ret = handler.DispatchKeyEvent(fd, udsServer, key);
1561     EXPECT_EQ(ret, RET_ERR);
1562     inputEvent->actionTime_ = 2000;
1563     ret = handler.DispatchKeyEvent(fd, udsServer, key);
1564     EXPECT_EQ(ret, RET_ERR);
1565     fd = 9;
1566     bool status = true;
1567     SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, 1, 1, 100, 100);
1568     session->SetTokenType(TokenType::TOKEN_HAP);
1569     session->SetAnrStatus(0, status);
1570     ret = handler.DispatchKeyEvent(fd, udsServer, key);
1571     EXPECT_EQ(ret, RET_ERR);
1572     status = false;
1573     StreamBuffer streamBuffer;
1574     streamBuffer.rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_READ;
1575     ret = handler.DispatchKeyEvent(fd, udsServer, key);
1576     EXPECT_EQ(ret, RET_ERR);
1577     streamBuffer.rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_OK;
1578     udsServer.pid_ = 1;
1579     ret = handler.DispatchKeyEvent(fd, udsServer, key);
1580     EXPECT_EQ(ret, RET_ERR);
1581     udsServer.pid_ = -1;
1582     ret = handler.DispatchKeyEvent(fd, udsServer, key);
1583     EXPECT_EQ(ret, RET_ERR);
1584 }
1585 
1586 /**
1587  * @tc.name: EventDispatchTest_FilterInvalidPointerItem_008
1588  * @tc.desc: Test the function FilterInvalidPointerItem
1589  * @tc.type: FUNC
1590  * @tc.require:
1591  */
1592 HWTEST_F(EventDispatchTest, EventDispatchTest_FilterInvalidPointerItem_008, TestSize.Level1)
1593 {
1594     EventDispatchHandler eventdispatchhandler;
1595     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
1596     ASSERT_NE(pointerEvent, nullptr);
1597     int32_t fd = 10;
1598     PointerEvent::PointerItem item1;
1599     item1.pointerId_ = 1;
1600     item1.pressed_ = true;
1601     item1.displayX_ = 10;
1602     item1.displayY_ = 20;
1603     pointerEvent->pointers_.push_back(item1);
1604     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.FilterInvalidPointerItem(pointerEvent, fd));
1605     PointerEvent::PointerItem item2;
1606     item2.pointerId_ = 2;
1607     item2.pressed_ = false;
1608     item2.displayX_ = 20;
1609     item2.displayY_ = 30;
1610     item2.targetWindowId_ = 1;
1611     pointerEvent->pointers_.push_back(item2);
1612     UDSServer udsServer;
1613     udsServer.pid_ = 1;
1614     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.FilterInvalidPointerItem(pointerEvent, fd));
1615     udsServer.pid_ = -1;
1616     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.FilterInvalidPointerItem(pointerEvent, fd));
1617 }
1618 
1619 /**
1620  * @tc.name: EventDispatchTest_HandleMultiWindowPointerEvent_008
1621  * @tc.desc: Test the function HandleMultiWindowPointerEvent
1622  * @tc.type: FUNC
1623  * @tc.require:
1624  */
1625 HWTEST_F(EventDispatchTest, EventDispatchTest_HandleMultiWindowPointerEvent_008, TestSize.Level1)
1626 {
1627     EventDispatchHandler eventdispatchhandler;
1628     std::shared_ptr<PointerEvent> point = PointerEvent::Create();
1629     ASSERT_NE(point, nullptr);
1630     PointerEvent::PointerItem pointerItem;
1631     pointerItem.SetWindowX(1);
1632     pointerItem.SetWindowY(2);
1633     pointerItem.SetTargetWindowId(3);
1634     point->pointerAction_ = PointerEvent::POINTER_ACTION_UP;
1635     point->pointerId_ = 3;
1636     std::shared_ptr<WindowInfo> windowInfo = std::make_shared<WindowInfo>();
1637     windowInfo->id = 3;
1638     eventdispatchhandler.cancelEventList_[1].push_back(windowInfo);
1639     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleMultiWindowPointerEvent(point, pointerItem));
1640     windowInfo->id = 1;
1641     eventdispatchhandler.cancelEventList_[2].push_back(windowInfo);
1642     point->pointerAction_ = PointerEvent::POINTER_ACTION_MOVE;
1643     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleMultiWindowPointerEvent(point, pointerItem));
1644     point->pointerAction_ = PointerEvent::POINTER_ACTION_CANCEL;
1645     ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleMultiWindowPointerEvent(point, pointerItem));
1646 }
1647 
1648 /**
1649  * @tc.name: EventDispatchTest_DispatchKeyEvent_002
1650  * @tc.desc: Test the funcation DispatchKeyEvent
1651  * @tc.type: FUNC
1652  * @tc.require:
1653  */
1654 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchKeyEvent_002, TestSize.Level1)
1655 {
1656     EventDispatchHandler handler;
1657     int32_t fd = 1;
1658     UDSServer udsServer;
1659     std::shared_ptr<KeyEvent> key = KeyEvent::Create();
1660     ASSERT_NE(key, nullptr);
1661     SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, 1, 1, 100, 100);
1662     session->tokenType_ = 0;
1663     session->isAnrProcess_.insert(std::make_pair(1, true));
1664     int32_t ret = handler.DispatchKeyEvent(fd, udsServer, key);
1665     EXPECT_EQ(ret, RET_ERR);
1666     fd = 2;
1667     session->isAnrProcess_.insert(std::make_pair(2, false));
1668     ret = handler.DispatchKeyEvent(fd, udsServer, key);
1669     EXPECT_EQ(ret, RET_ERR);
1670 }
1671 } // namespace MMI
1672 } // namespace OHOS
1673