• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "gtest/gtest.h"
17 #include "core/common/event_dump.h"
18 #include "test/unittest/core/event/event_manager_test_ng.h"
19 
20 using namespace testing;
21 using namespace testing::ext;
22 
23 namespace OHOS::Ace::NG {
24 namespace {
25 constexpr size_t MAX_EVENT_TREE_RECORD_CNT = 5;
26 constexpr int32_t MAX_EVENT_TREE_TOUCH_DOWN_CNT = 10;
27 constexpr int32_t MAX_EVENT_TREE_TOUCH_POINT_CNT = 20;
28 constexpr int32_t MAX_EVENT_TREE_AXIS_UPDATE_CNT = 20;
29 constexpr int32_t MAX_EVENT_TREE_AXIS_CNT = 20;
30 constexpr int32_t PARENT_NODEID = 0;
31 constexpr int32_t DEFAULT_HITTEST_MODE = 0;
32 constexpr int32_t DEFAULT_DEPTH = 1;
33 constexpr int64_t DEFAULT_TIME_STAMP = 65536;
34 const std::string JSON_KEY_COM_ID = "comId";
35 const std::string ID_0 = "0x0";
36 const std::string ID_1 = "0x1";
37 const std::string PARENT_ID_0 = "0x0";
38 const std::string PARENT_ID_1 = "0x1";
39 const std::string TAG = "column";
40 } // namespace
41 
42 class EventDumpTestNg : public testing::Test {
43 public:
44     static void SetUpTestSuite();
45     static void TearDownTestSuite();
46     void SetUp() override;
47     void TearDown() override;
48 
49     std::shared_ptr<FrameNodeSnapshot> CreateFrameNodeSnapshotWithInitValue();
50     std::shared_ptr<TouchPointSnapshot> CreateTouchPointSnapshot(const TouchEvent& event);
51     std::shared_ptr<AxisSnapshot> CreateAxisSnapshot(const AxisEvent& event);
52     std::shared_ptr<EventTreeRecord> CreateEventTreeRecord();
53     void FillTouchDownEventToEventTree(std::shared_ptr<EventTreeRecord> eventTreeRecord, const TouchEvent& event,
54         int32_t eventTreeRecordCount = 0, int32_t touchDownCount = 0, int32_t touchPointCount = 0);
55     void FillAxisUpdateEventToEventTree(std::shared_ptr<EventTreeRecord> eventTreeRecord, const AxisEvent& event,
56         int32_t eventTreeRecordCount = 0, int32_t axisUpdateCount = 0, int32_t AxisCount = 0);
57 };
58 
SetUp()59 void EventDumpTestNg::SetUp()
60 {}
61 
TearDown()62 void EventDumpTestNg::TearDown()
63 {}
64 
SetUpTestSuite()65 void EventDumpTestNg::SetUpTestSuite()
66 {}
67 
TearDownTestSuite()68 void EventDumpTestNg::TearDownTestSuite()
69 {}
70 
CreateFrameNodeSnapshotWithInitValue()71 std::shared_ptr<FrameNodeSnapshot> EventDumpTestNg::CreateFrameNodeSnapshotWithInitValue()
72 {
73     auto frameNodeSnapshotInstance = std::make_shared<FrameNodeSnapshot>();
74     CHECK_NULL_RETURN(frameNodeSnapshotInstance, nullptr);
75     frameNodeSnapshotInstance->nodeId = NODEID;
76     frameNodeSnapshotInstance->parentNodeId = PARENT_NODEID;
77     frameNodeSnapshotInstance->tag = TAG;
78     frameNodeSnapshotInstance->comId = "comId_01";
79     frameNodeSnapshotInstance->monopolizeEvents = true;
80     frameNodeSnapshotInstance->isHit = true;
81     frameNodeSnapshotInstance->hitTestMode = DEFAULT_HITTEST_MODE;
82     frameNodeSnapshotInstance->responseRegionList = { RectF(0, 0, 20, 10), RectF(25, 0, 20, 10) };
83     return frameNodeSnapshotInstance;
84 }
85 
CreateTouchPointSnapshot(const TouchEvent & event)86 std::shared_ptr<TouchPointSnapshot> EventDumpTestNg::CreateTouchPointSnapshot(const TouchEvent& event)
87 {
88     return std::make_shared<TouchPointSnapshot>(event);
89 }
90 
CreateAxisSnapshot(const AxisEvent & event)91 std::shared_ptr<AxisSnapshot> EventDumpTestNg::CreateAxisSnapshot(const AxisEvent& event)
92 {
93     return std::make_shared<AxisSnapshot>(event);
94 }
95 
CreateEventTreeRecord()96 std::shared_ptr<EventTreeRecord> EventDumpTestNg::CreateEventTreeRecord()
97 {
98     return std::make_shared<EventTreeRecord>();
99 }
100 
FillTouchDownEventToEventTree(std::shared_ptr<EventTreeRecord> eventTreeRecord,const TouchEvent & event,const int32_t eventTreeRecordCount,int32_t touchDownCount,int32_t touchPointCount)101 void EventDumpTestNg::FillTouchDownEventToEventTree(std::shared_ptr<EventTreeRecord> eventTreeRecord,
102     const TouchEvent& event, const int32_t eventTreeRecordCount, int32_t touchDownCount, int32_t touchPointCount)
103 {
104     if (!eventTreeRecord || event.type != Ace::TouchType::DOWN) {
105         return;
106     }
107     eventTreeRecord->eventTreeList.clear();
108     for (int32_t i = 0; i < eventTreeRecordCount; ++i) {
109         eventTreeRecord->eventTreeList.emplace_back(EventTree());
110     }
111     if (!eventTreeRecord->eventTreeList.empty()) {
112         for (int32_t i = 0; i < touchPointCount; ++i) {
113             eventTreeRecord->eventTreeList.back().touchPoints.emplace_back(TouchPointSnapshot(event));
114         }
115         eventTreeRecord->eventTreeList.back().touchDownCount = touchDownCount;
116     }
117 }
118 
FillAxisUpdateEventToEventTree(std::shared_ptr<EventTreeRecord> eventTreeRecord,const AxisEvent & event,const int32_t eventTreeRecordCount,int32_t axisUpdateCount,int32_t AxisCount)119 void EventDumpTestNg::FillAxisUpdateEventToEventTree(std::shared_ptr<EventTreeRecord> eventTreeRecord,
120     const AxisEvent& event, const int32_t eventTreeRecordCount, int32_t axisUpdateCount, int32_t AxisCount)
121 {
122     if (!eventTreeRecord || event.action != Ace::AxisAction::BEGIN) {
123         return;
124     }
125     eventTreeRecord->eventTreeList.clear();
126     for (int32_t i = 0; i < eventTreeRecordCount; ++i) {
127         eventTreeRecord->eventTreeList.emplace_back(EventTree());
128     }
129     if (!eventTreeRecord->eventTreeList.empty()) {
130         for (int32_t i = 0; i < AxisCount; ++i) {
131             eventTreeRecord->eventTreeList.back().axis.emplace_back(AxisSnapshot(event));
132         }
133         eventTreeRecord->eventTreeList.back().axisUpdateCount = axisUpdateCount;
134     }
135 }
136 
137 
138 /**
139  * @tc.name: EventDumpTestNg001
140  * @tc.desc: FrameNodeSnapshot dump function test.
141  * @tc.type: FUNC
142  */
143 HWTEST_F(EventDumpTestNg, EventDumpTestNg001, TestSize.Level1)
144 {
145     /**
146      * @tc.steps: step1. create FrameNodeSnapshot instance and init value.
147      */
148     auto frameNodeSnapshotInstance = CreateFrameNodeSnapshotWithInitValue();
149 
150     /**
151      * @tc.steps: step2. Invoke dump function.
152      * @tc.expected: dump list exist data, size is not empty.
153      */
154     ASSERT_NE(frameNodeSnapshotInstance, nullptr);
155     std::list<std::pair<int32_t, std::string>> dumpList;
156     EXPECT_TRUE(dumpList.empty());
157     frameNodeSnapshotInstance->Dump(dumpList, DEFAULT_DEPTH);
158     EXPECT_FALSE(dumpList.empty());
159 }
160 
161 /**
162  * @tc.name: EventDumpTestNg002
163  * @tc.desc: TouchPointSnapshot dump function test.
164  * @tc.type: FUNC
165  */
166 HWTEST_F(EventDumpTestNg, EventDumpTestNg002, TestSize.Level1)
167 {
168     /**
169      * @tc.steps: step1. create TouchPointSnapshot instance and init value.
170      */
171     TouchEvent event;
172     auto touchPointSnapshot = CreateTouchPointSnapshot(event);
173 
174     /**
175      * @tc.steps: step2. Invoke dump function.
176      * @tc.expected: dump list exist data, size is not empty.
177      */
178     ASSERT_NE(touchPointSnapshot, nullptr);
179     std::list<std::pair<int32_t, std::string>> dumpList;
180     EXPECT_TRUE(dumpList.empty());
181     touchPointSnapshot->Dump(dumpList, DEFAULT_DEPTH);
182     EXPECT_FALSE(dumpList.empty());
183 
184     std::unique_ptr<JsonValue> dumpJson = JsonUtil::Create(true);
185     touchPointSnapshot->Dump(dumpJson);
186     EXPECT_TRUE(dumpJson->Contains("isInjected"));
187 }
188 
189 /**
190  * @tc.name: EventDumpTestNg003
191  * @tc.desc: EventTreeRecord AddTouchPoint function test.
192  * @tc.type: FUNC
193  */
194 HWTEST_F(EventDumpTestNg, EventDumpTestNg003, TestSize.Level1)
195 {
196     /**
197      * @tc.steps: step1. create EventTreeRecord instance.
198      */
199     auto eventTreeRecord = CreateEventTreeRecord();
200     ASSERT_NE(eventTreeRecord, nullptr);
201 
202     /**
203      * @tc.steps: step2. mock touch event DOWN to UP.
204      * @tc.expected: touchDownCount is zero.
205      */
206     const std::vector<Ace::TouchType> touchTypeArray = { Ace::TouchType::DOWN, Ace::TouchType::UP };
207     TouchEvent event;
208     int32_t eventTreeRecordCount = 1;
209     int32_t touchDownCount = 4;
210     for (int32_t i = 0; i < eventTreeRecordCount * touchDownCount; ++i) {
211         int32_t index = i % touchTypeArray.size();
212         event.type = touchTypeArray[index];
213         event.id = touchTypeArray.size() > 0 ? i / touchTypeArray.size() : i;
214         eventTreeRecord->AddTouchPoint(event);
215     }
216     ASSERT_FALSE(eventTreeRecord->eventTreeList.empty());
217     EXPECT_EQ(eventTreeRecord->eventTreeList.back().touchDownCount, (eventTreeRecordCount * touchDownCount) % 2);
218 }
219 
220 /**
221  * @tc.name: EventDumpTestNg004
222  * @tc.desc: EventTreeRecord AddTouchPoint function test.
223  * @tc.type: FUNC
224  */
225 HWTEST_F(EventDumpTestNg, EventDumpTestNg004, TestSize.Level2)
226 {
227     /**
228      * @tc.steps: step1. create EventTreeRecord instance.
229      */
230     auto eventTreeRecord = CreateEventTreeRecord();
231     ASSERT_NE(eventTreeRecord, nullptr);
232     TouchEvent event;
233     event.type = Ace::TouchType::DOWN;
234     event.id = 1;
235 
236     /**
237      * @tc.steps: step2. fill touch event vale to eventTree.
238      * @tc.expected: list is not empty.
239      */
240     FillTouchDownEventToEventTree(eventTreeRecord, event, MAX_EVENT_TREE_RECORD_CNT + 1,
241         MAX_EVENT_TREE_TOUCH_DOWN_CNT, MAX_EVENT_TREE_TOUCH_POINT_CNT + 1);
242     eventTreeRecord->AddTouchPoint(event);
243     ASSERT_FALSE(eventTreeRecord->eventTreeList.empty());
244     EXPECT_EQ(eventTreeRecord->eventTreeList.size(), MAX_EVENT_TREE_RECORD_CNT);
245 }
246 
247 /**
248  * @tc.name: EventDumpTestNg005
249  * @tc.desc: EventTreeRecord AddGestureSnapshot function test.
250  * @tc.type: FUNC
251  */
252 HWTEST_F(EventDumpTestNg, EventDumpTestNg005, TestSize.Level1)
253 {
254     /**
255      * @tc.steps: step1. create EventTreeRecord instance and fill touch event vale to eventTree.
256      */
257     auto eventTreeRecord = CreateEventTreeRecord();
258     ASSERT_NE(eventTreeRecord, nullptr);
259     TouchEvent event;
260     event.type = Ace::TouchType::DOWN;
261     event.id = 1;
262     eventTreeRecord->AddTouchPoint(event);
263 
264     /**
265      * @tc.steps: step2. Invoke AddGestureSnapshot function.
266      * @tc.expected: list is not empty.
267      */
268     auto gestureSnapshot = AceType::MakeRefPtr<GestureSnapshot>();
269     int32_t finger = 0;
270     eventTreeRecord->AddGestureSnapshot(finger, std::move(gestureSnapshot));
271 
272     EXPECT_FALSE(eventTreeRecord->eventTreeList.back().gestureTree.empty());
273     EXPECT_FALSE(eventTreeRecord->eventTreeList.back().gestureMap.empty());
274 }
275 
276 /**
277  * @tc.name: EventDumpTestNg006
278  * @tc.desc: EventTreeRecord AddGestureSnapshot function test.
279  * @tc.type: FUNC
280  */
281 HWTEST_F(EventDumpTestNg, EventDumpTestNg006, TestSize.Level2)
282 {
283     /**
284      * @tc.steps: step1. create EventTreeRecord instance and fill touch event vale to eventTree.
285      */
286     auto eventTreeRecord = CreateEventTreeRecord();
287     ASSERT_NE(eventTreeRecord, nullptr);
288     TouchEvent event;
289     event.type = Ace::TouchType::DOWN;
290     event.id = 1;
291 
292     /**
293      * @tc.steps: step2. Invoke AddGestureSnapshot function.
294      * @tc.expected: list is empty.
295      */
296     FillTouchDownEventToEventTree(eventTreeRecord, event, MAX_EVENT_TREE_RECORD_CNT + 1,
297         MAX_EVENT_TREE_TOUCH_DOWN_CNT, MAX_EVENT_TREE_TOUCH_POINT_CNT + 1);
298 
299     int32_t finger = 0;
300     eventTreeRecord->AddGestureSnapshot(finger, nullptr);
301     EXPECT_TRUE(eventTreeRecord->eventTreeList.empty());
302 }
303 
304 /**
305  * @tc.name: EventDumpTestNg007
306  * @tc.desc: EventTreeRecord AddGestureProcedure function test.
307  * @tc.type: FUNC
308  */
309 HWTEST_F(EventDumpTestNg, EventDumpTestNg007, TestSize.Level1)
310 {
311     /**
312      * @tc.steps: step1. create EventTreeRecord instance and fill touch event vale to eventTree.
313      */
314     auto eventTreeRecord = CreateEventTreeRecord();
315     ASSERT_NE(eventTreeRecord, nullptr);
316     TouchEvent event;
317     event.type = Ace::TouchType::DOWN;
318     event.id = 1;
319     eventTreeRecord->AddTouchPoint(event);
320     auto gestureSnapshot = AceType::MakeRefPtr<GestureSnapshot>();
321     int32_t finger = 0;
322     eventTreeRecord->AddGestureSnapshot(finger, std::move(gestureSnapshot));
323 
324     /**
325      * @tc.steps: step2. Invoke AddGestureProcedure function.
326      * @tc.expected: stateHistory is not empty.
327      */
328     std::string procedure = "HandleTouchDown";
329     std::string state = "current";
330     std::string disposal = "mainThread";
331 
332     eventTreeRecord->AddGestureProcedure(finger + 1, procedure, "", state, disposal, DEFAULT_TIME_STAMP);
333     ASSERT_FALSE(eventTreeRecord->eventTreeList.empty());
334     auto iter0 = eventTreeRecord->eventTreeList.back().gestureMap.find(finger + 1);
335     EXPECT_TRUE(iter0 == eventTreeRecord->eventTreeList.back().gestureMap.end());
336 
337     eventTreeRecord->AddGestureProcedure(finger, procedure, "", state, disposal, DEFAULT_TIME_STAMP);
338     ASSERT_FALSE(eventTreeRecord->eventTreeList.empty());
339     auto iter = eventTreeRecord->eventTreeList.back().gestureMap.find(finger);
340     ASSERT_TRUE(iter != eventTreeRecord->eventTreeList.back().gestureMap.end());
341     ASSERT_TRUE(iter->second != nullptr);
342     EXPECT_FALSE(iter->second->stateHistory.empty());
343 }
344 
345 /**
346  * @tc.name: EventDumpTestNg008
347  * @tc.desc: EventTreeRecord AddGestureProcedure function test.
348  * @tc.type: FUNC
349  */
350 HWTEST_F(EventDumpTestNg, EventDumpTestNg008, TestSize.Level2)
351 {
352     /**
353      * @tc.steps: step1. create EventTreeRecord instance and fill touch event vale to eventTree.
354      */
355     auto eventTreeRecord = CreateEventTreeRecord();
356     ASSERT_NE(eventTreeRecord, nullptr);
357     TouchEvent event;
358     event.type = Ace::TouchType::DOWN;
359     event.id = 1;
360     eventTreeRecord->AddTouchPoint(event);
361     auto gestureSnapshot = AceType::MakeRefPtr<GestureSnapshot>();
362     gestureSnapshot->type = "TouchEventActuator";
363     int32_t finger = 0;
364     eventTreeRecord->AddGestureSnapshot(finger, std::move(gestureSnapshot));
365 
366     /**
367      * @tc.steps: step2. Invoke AddGestureProcedure function.
368      * @tc.expected: stateHistory is empty.
369      */
370     std::string procedure = "HandleTouchMove";
371     std::string state = "current";
372     std::string disposal = "mainThread";
373     eventTreeRecord->AddGestureProcedure(finger, procedure, "", state, disposal, DEFAULT_TIME_STAMP);
374     ASSERT_FALSE(eventTreeRecord->eventTreeList.empty());
375     auto iter = eventTreeRecord->eventTreeList.back().gestureMap.find(finger);
376     ASSERT_TRUE(iter != eventTreeRecord->eventTreeList.back().gestureMap.end());
377     ASSERT_TRUE(iter->second != nullptr);
378     EXPECT_TRUE(iter->second->stateHistory.empty());
379 }
380 
381 /**
382  * @tc.name: EventDumpTestNg009
383  * @tc.desc: EventTreeRecord AddGestureProcedure function test.
384  * @tc.type: FUNC
385  */
386 HWTEST_F(EventDumpTestNg, EventDumpTestNg009, TestSize.Level1)
387 {
388     /**
389      * @tc.steps: step1. create EventTreeRecord instance and fill touch event vale to eventTree.
390      */
391     auto eventTreeRecord = CreateEventTreeRecord();
392     ASSERT_NE(eventTreeRecord, nullptr);
393     TouchEvent event;
394     event.type = Ace::TouchType::DOWN;
395     event.id = 1;
396     eventTreeRecord->AddTouchPoint(event);
397 
398     /**
399      * @tc.steps: step2. Invoke AddGestureProcedure function.
400      * @tc.expected: stateHistory is not empty.
401      */
402     auto gestureSnapshot = AceType::MakeRefPtr<GestureSnapshot>();
403     int32_t finger = 0;
404     eventTreeRecord->AddGestureSnapshot(finger, std::move(gestureSnapshot));
405     std::string state = "current";
406     std::string disposal = "mainThread";
407 
408     eventTreeRecord->AddGestureProcedure(finger + 1, event, "", state, disposal, DEFAULT_TIME_STAMP);
409     ASSERT_FALSE(eventTreeRecord->eventTreeList.empty());
410     auto iter0 = eventTreeRecord->eventTreeList.back().gestureMap.find(finger + 1);
411     EXPECT_TRUE(iter0 == eventTreeRecord->eventTreeList.back().gestureMap.end());
412 
413     eventTreeRecord->AddGestureProcedure(finger, event, "", state, disposal, DEFAULT_TIME_STAMP);
414     ASSERT_FALSE(eventTreeRecord->eventTreeList.empty());
415     auto iter = eventTreeRecord->eventTreeList.back().gestureMap.find(finger);
416     ASSERT_TRUE(iter != eventTreeRecord->eventTreeList.back().gestureMap.end());
417     ASSERT_TRUE(iter->second != nullptr);
418     EXPECT_FALSE(iter->second->stateHistory.empty());
419 }
420 
421 /**
422  * @tc.name: EventDumpTestNg010
423  * @tc.desc: EventTreeRecord dump function test.
424  * @tc.type: FUNC
425  */
426 HWTEST_F(EventDumpTestNg, EventDumpTestNg010, TestSize.Level1)
427 {
428     /**
429      * @tc.steps: step1. create EventTreeRecord instance and fill touch event vale to eventTree.
430      */
431     auto eventTreeRecord = CreateEventTreeRecord();
432     ASSERT_NE(eventTreeRecord, nullptr);
433     TouchEvent event;
434     event.type = Ace::TouchType::DOWN;
435     event.id = 1;
436     eventTreeRecord->AddTouchPoint(event);
437     auto frameNodeSnapshotInstance = CreateFrameNodeSnapshotWithInitValue();
438     ASSERT_NE(frameNodeSnapshotInstance, nullptr);
439     eventTreeRecord->AddFrameNodeSnapshot(std::move(*frameNodeSnapshotInstance));
440     auto gestureSnapshot = AceType::MakeRefPtr<GestureSnapshot>();
441     int32_t finger = 0;
442     eventTreeRecord->AddGestureSnapshot(finger, std::move(gestureSnapshot));
443     std::string state = "current";
444     std::string disposal = "mainThread";
445     eventTreeRecord->AddGestureProcedure(finger, event, "", state, disposal, DEFAULT_TIME_STAMP);
446 
447     /**
448      * @tc.steps: step2. Invoke dump function.
449      * @tc.expected: dump list exist data, size is not empty.
450      */
451     std::list<std::pair<int32_t, std::string>> dumpList;
452     EXPECT_TRUE(dumpList.empty());
453     eventTreeRecord->Dump(dumpList, DEFAULT_DEPTH);
454     EXPECT_FALSE(dumpList.empty());
455 
456     std::unique_ptr<JsonValue> dumpJson = JsonUtil::Create(true);
457     int32_t depth = 0;
458     int32_t startNumber = -1;
459     std::string header = "event tree_0";
460     eventTreeRecord->Dump(dumpJson, depth, startNumber);
461     EXPECT_FALSE(dumpJson->Contains(header));
462 }
463 
464 /**
465  * @tc.name: EventDumpTestNg011
466  * @tc.desc: FrameNodeSnapshot Dump function test.
467  * @tc.type: FUNC
468  */
469 HWTEST_F(EventDumpTestNg, EventDumpTestNg011, TestSize.Level1)
470 {
471     /**
472      * @tc.steps: step1. create FrameNodeSnapshot instance and init value.
473      */
474     auto frameNodeSnapshotInstance = CreateFrameNodeSnapshotWithInitValue();
475 
476     /**
477      * @tc.steps: step2. set frameNodeSnapshotInstance->comId is "" and call Dump function.
478      * @tc.expected: comId does not exist in json.
479      */
480     ASSERT_NE(frameNodeSnapshotInstance, nullptr);
481     std::unique_ptr<JsonValue> json = JsonUtil::Create(true);
482     frameNodeSnapshotInstance->comId = "";
483     frameNodeSnapshotInstance->Dump(json);
484     EXPECT_FALSE(json->Contains(JSON_KEY_COM_ID));
485 
486     /**
487      * @tc.steps: step3. set frameNodeSnapshotInstance->comId is "comId_02" and call Dump function.
488      * @tc.expected: comId exists in json.
489      */
490     frameNodeSnapshotInstance->comId = "comId_02";
491     frameNodeSnapshotInstance->Dump(json);
492     EXPECT_TRUE(json->Contains(JSON_KEY_COM_ID));
493 }
494 
495 /**
496  * @tc.name: EventDumpTestNg012
497  * @tc.desc: MountToParent function test.
498  * @tc.type: FUNC
499  */
500 HWTEST_F(EventDumpTestNg, EventDumpTestNg012, TestSize.Level1)
501 {
502     /**
503      * @tc.steps: step1. create EventTreeRecord instance.
504      */
505     auto eventTreeRecord = CreateEventTreeRecord();
506     ASSERT_NE(eventTreeRecord, nullptr);
507 
508     /**
509      * @tc.steps: step2. call MountToParent function.
510      * @tc.expected: expected value does not exist in json.
511      */
512     std::vector<std::pair<std::string, std::pair<std::string, std::unique_ptr<JsonValue>>>> stateInfoList;
513     std::unique_ptr<JsonValue> json = JsonUtil::Create(true);
514     eventTreeRecord->MountToParent(std::move(stateInfoList), json);
515     EXPECT_FALSE(json->Contains(("detail_" + ID_0).c_str()));
516 
517     /**
518      * @tc.steps: step3. set stateInfoList not empty and call MountToParent function.
519      * @tc.expected: expected value exists in json.
520      */
521     stateInfoList.push_back(std::make_pair(ID_0, std::make_pair(PARENT_ID_0, JsonUtil::Create(true))));
522     stateInfoList.push_back(std::make_pair(ID_1, std::make_pair(PARENT_ID_1, JsonUtil::Create(true))));
523     eventTreeRecord->MountToParent(std::move(stateInfoList), json);
524     EXPECT_TRUE(json->Contains(("detail_" + ID_0).c_str()));
525 }
526 
527 /**
528  * @tc.name: EventDumpTestNg013
529  * @tc.desc: EventTreeRecord Dump function test.
530  * @tc.type: FUNC
531  */
532 HWTEST_F(EventDumpTestNg, EventDumpTestNg013, TestSize.Level1)
533 {
534     /**
535      * @tc.steps: step1. create EventTreeRecord instance and fill touch event vale to eventTree.
536      */
537     auto eventTreeRecord = CreateEventTreeRecord();
538     ASSERT_NE(eventTreeRecord, nullptr);
539     TouchEvent event;
540     event.type = Ace::TouchType::DOWN;
541     event.id = 1;
542     FillTouchDownEventToEventTree(eventTreeRecord, event, MAX_EVENT_TREE_RECORD_CNT + 1, 0, 0);
543 
544     /**
545      * @tc.steps: step2. set startNumber is -1 and call Dump function.
546      * @tc.expected: "event tree_0" exists in json.
547      */
548     std::unique_ptr<JsonValue> json = JsonUtil::Create(true);
549     int32_t depth = 0;
550     int32_t startNumber = -1;
551     std::string header = "event tree_0";
552     eventTreeRecord->Dump(json, depth, startNumber);
553     EXPECT_FALSE(json->Contains(header));
554 
555     /**
556      * @tc.steps: step3. set startNumber is 1 and call Dump function.
557      * @tc.expected: "event tree_1" exists in json.
558      */
559     startNumber = 1;
560     header = "event tree_1";
561     eventTreeRecord->Dump(json, depth, startNumber);
562     EXPECT_TRUE(json->Contains(header));
563 }
564 
565 /**
566  * @tc.name: EventDumpTestNg014
567  * @tc.desc: BuildGestureTree function test.
568  * @tc.type: FUNC
569  */
570 HWTEST_F(EventDumpTestNg, EventDumpTestNg014, TestSize.Level1)
571 {
572     /**
573      * @tc.steps: step1. create EventTreeRecord instance.
574      */
575     auto eventTreeRecord = CreateEventTreeRecord();
576     ASSERT_NE(eventTreeRecord, nullptr);
577 
578     /**
579      * @tc.steps: step2. call BuildGestureTree function.
580      * @tc.expected: "event procedures" exists in json.
581      */
582     auto gestureSnapshot = AceType::MakeRefPtr<GestureSnapshot>();
583     std::list<RefPtr<GestureSnapshot>> gestureSnapshotList;
584     gestureSnapshotList.push_back(gestureSnapshot);
585 
586     std::map<int32_t, std::list<RefPtr<GestureSnapshot>>> gestureTreeMap;
587     gestureTreeMap.insert({1, gestureSnapshotList});
588     std::unique_ptr<JsonValue> json = JsonUtil::Create(true);
589     eventTreeRecord->BuildGestureTree(gestureTreeMap, json);
590     EXPECT_TRUE(json->Contains("event procedures"));
591 }
592 
593 /**
594  * @tc.name: EventDumpTestNg015
595  * @tc.desc: FrameNodeSnapshot Dump function test.
596  * @tc.type: FUNC
597  */
598 HWTEST_F(EventDumpTestNg, EventDumpTestNg015, TestSize.Level1)
599 {
600     /**
601      * @tc.steps: step1. create FrameNodeSnapshot instance and init value.
602      */
603     auto frameNodeSnapshotInstance = CreateFrameNodeSnapshotWithInitValue();
604     ASSERT_NE(frameNodeSnapshotInstance, nullptr);
605 
606     /**
607      * @tc.steps: step2. set comId is "" and call Dump function.
608      * @tc.expected: dump list exist data, size is not empty.
609      */
610     frameNodeSnapshotInstance->comId = "";
611     std::list<std::pair<int32_t, std::string>> dumpList;
612     frameNodeSnapshotInstance->Dump(dumpList, DEFAULT_DEPTH);
613     EXPECT_FALSE(dumpList.empty());
614 }
615 
616 /**
617  * @tc.name: EventDumpTestNg016
618  * @tc.desc: EventTreeRecord Dump function test.
619  * @tc.type: FUNC
620  */
621 HWTEST_F(EventDumpTestNg, EventDumpTestNg016, TestSize.Level1)
622 {
623     /**
624      * @tc.steps: step1. create EventTreeRecord instance and fill touch event vale to eventTree.
625      */
626     auto eventTreeRecord = CreateEventTreeRecord();
627     ASSERT_NE(eventTreeRecord, nullptr);
628     TouchEvent event;
629     event.type = Ace::TouchType::DOWN;
630     event.id = 1;
631     FillTouchDownEventToEventTree(eventTreeRecord, event, MAX_EVENT_TREE_RECORD_CNT + 1, 0, 0);
632 
633     /**
634      * @tc.steps: step2. call Dump function.
635      * @tc.expected: dump list exist data, size is not empty.
636      */
637     std::list<std::pair<int32_t, std::string>> dumpList;
638     EXPECT_TRUE(dumpList.empty());
639     int32_t startNumber = 1;
640     eventTreeRecord->Dump(dumpList, DEFAULT_DEPTH, startNumber);
641     EXPECT_FALSE(dumpList.empty());
642 
643     std::unique_ptr<JsonValue> dumpJson = JsonUtil::Create(true);
644     int32_t depth = 0;
645     std::string header = "event tree_0";
646     eventTreeRecord->Dump(dumpJson, depth, startNumber);
647     EXPECT_TRUE(dumpJson->Contains(header));
648 }
649 
650 /**
651  * @tc.name: EventDumpTestNg017
652  * @tc.desc: AxisSnapshot dump function test.
653  * @tc.type: FUNC
654  */
655 HWTEST_F(EventDumpTestNg, EventDumpTestNg017, TestSize.Level1)
656 {
657     AxisEvent event;
658     const std::vector<Ace::AxisAction> axisActionArray = {Ace::AxisAction::BEGIN, Ace::AxisAction::UPDATE,
659         Ace::AxisAction::END, Ace::AxisAction::CANCEL};
660     std::unique_ptr<JsonValue> dumpJson = JsonUtil::Create(true);
661     std::list<std::pair<int32_t, std::string>> dumpList;
662     EXPECT_TRUE(dumpList.empty());
663 
664     for (int32_t i = 0; i < axisActionArray.size(); ++i) {
665         event.action = axisActionArray[i];
666         auto axisSnapshot = CreateAxisSnapshot(event);
667         ASSERT_NE(axisSnapshot, nullptr);
668         axisSnapshot->Dump(dumpList, DEFAULT_DEPTH + i);
669         axisSnapshot->Dump(dumpJson);
670     }
671     EXPECT_FALSE(dumpList.empty());
672     EXPECT_TRUE(dumpJson->Contains("isInjected"));
673 }
674 
675 /**
676  * @tc.name: EventDumpTestNg018
677  * @tc.desc: TouchPointSnapshot dump function test.
678  * @tc.type: FUNC
679  */
680 HWTEST_F(EventDumpTestNg, EventDumpTestNg018, TestSize.Level1)
681 {
682     /**
683      * @tc.steps: step1. create TouchPointSnapshot instance and init value.
684      */
685     MockPipelineContext::SetUp();
686     auto pipeline = NG::PipelineContext::GetCurrentContext();
687     ASSERT_NE(pipeline, nullptr);
688     auto eventManager = pipeline->GetEventManager();
689     ASSERT_NE(eventManager, nullptr);
690     int32_t fingerId = 1;
691     eventManager->downFingerIds_[fingerId] = 1;
692     TouchEvent event;
693     auto touchPointSnapshot = CreateTouchPointSnapshot(event);
694     ASSERT_NE(touchPointSnapshot, nullptr);
695     EXPECT_FALSE(touchPointSnapshot->downFingerIds.empty());
696 
697     /**
698      * @tc.steps: step2. Invoke dump function.
699      * @tc.expected: dump list exist data, size is not empty.
700      */
701     std::list<std::pair<int32_t, std::string>> dumpList;
702     EXPECT_TRUE(dumpList.empty());
703     touchPointSnapshot->Dump(dumpList, DEFAULT_DEPTH);
704     EXPECT_FALSE(dumpList.empty());
705 
706     std::unique_ptr<JsonValue> dumpJson = JsonUtil::Create(true);
707     touchPointSnapshot->Dump(dumpJson);
708     EXPECT_TRUE(dumpJson->Contains("downFingerIds"));
709 
710     MockPipelineContext::TearDown();
711 }
712 
713 /**
714  * @tc.name: EventDumpTestNg019
715  * @tc.desc: EventTreeRecord AddAxis function test.
716  * @tc.type: FUNC
717  */
718 HWTEST_F(EventDumpTestNg, EventDumpTestNg019, TestSize.Level1)
719 {
720     /**
721      * @tc.steps: step1. create EventTreeRecord instance.
722      */
723     auto eventTreeRecord = CreateEventTreeRecord();
724     ASSERT_NE(eventTreeRecord, nullptr);
725 
726     /**
727      * @tc.steps: step2. mock Axis event BEGIN to END.
728      */
729     const std::vector<Ace::AxisAction> axisActionArray = {Ace::AxisAction::BEGIN, Ace::AxisAction::END,
730         Ace::AxisAction::BEGIN, Ace::AxisAction::CANCEL};
731     AxisEvent event;
732     int32_t eventTreeRecordCount = 1;
733     int32_t axisUpdateCount = 8;
734     for (int32_t i = 0; i < eventTreeRecordCount * axisUpdateCount; ++i) {
735         int32_t index = i % axisActionArray.size();
736         event.action = axisActionArray[index];
737         event.id = axisActionArray.size() > 0 ? i / axisActionArray.size() : i;
738         eventTreeRecord->AddAxis(event);
739     }
740     ASSERT_FALSE(eventTreeRecord->eventTreeList.empty());
741     EXPECT_EQ(eventTreeRecord->eventTreeList.back().axisUpdateCount, (eventTreeRecordCount * axisUpdateCount) % 2);
742 }
743 
744 /**
745  * @tc.name: EventDumpTestNg020
746  * @tc.desc: EventTreeRecord AddAxis function test.
747  * @tc.type: FUNC
748  */
749 HWTEST_F(EventDumpTestNg, EventDumpTestNg020, TestSize.Level1)
750 {
751     /**
752      * @tc.steps: step1. create EventTreeRecord instance.
753      */
754     auto eventTreeRecord = CreateEventTreeRecord();
755     ASSERT_NE(eventTreeRecord, nullptr);
756     AxisEvent event;
757     event.action = Ace::AxisAction::BEGIN;
758     event.id = 1;
759 
760     /**
761      * @tc.steps: step2. fill touch event vale to eventTree.
762      * @tc.expected: list is not empty.
763      */
764     FillAxisUpdateEventToEventTree(eventTreeRecord, event, MAX_EVENT_TREE_RECORD_CNT + 1,
765         MAX_EVENT_TREE_AXIS_UPDATE_CNT, MAX_EVENT_TREE_AXIS_CNT + 1);
766     eventTreeRecord->AddAxis(event);
767     ASSERT_FALSE(eventTreeRecord->eventTreeList.empty());
768     EXPECT_EQ(eventTreeRecord->eventTreeList.size(), MAX_EVENT_TREE_RECORD_CNT);
769 }
770 
771 /**
772  * @tc.name: EventDumpTestNg021
773  * @tc.desc: EventTreeRecord AddAxis function test.
774  * @tc.type: FUNC
775  */
776 HWTEST_F(EventDumpTestNg, EventDumpTestNg021, TestSize.Level1)
777 {
778     /**
779      * @tc.steps: step1. create EventTreeRecord instance.
780      */
781     auto eventTreeRecord = CreateEventTreeRecord();
782     ASSERT_NE(eventTreeRecord, nullptr);
783 
784     /**
785      * @tc.steps: step2. mock Axis event END.
786      */
787     AxisEvent event;
788     event.action = Ace::AxisAction::END;
789     eventTreeRecord->AddAxis(event);
790     EXPECT_TRUE(eventTreeRecord->eventTreeList.empty());
791 }
792 
793 /**
794  * @tc.name: EventDumpTestNg022
795  * @tc.desc: EventTreeRecord AddTouchPoint function test.
796  * @tc.type: FUNC
797  */
798 HWTEST_F(EventDumpTestNg, EventDumpTestNg022, TestSize.Level1)
799 {
800     /**
801      * @tc.steps: step1. create EventTreeRecord instance.
802      */
803     auto eventTreeRecord = CreateEventTreeRecord();
804     ASSERT_NE(eventTreeRecord, nullptr);
805 
806     /**
807      * @tc.steps: step2. mock touch event UP.
808      */
809     TouchEvent event;
810     event.type = Ace::TouchType::UP;
811     eventTreeRecord->AddTouchPoint(event);
812     EXPECT_TRUE(eventTreeRecord->eventTreeList.empty());
813 }
814 
815 /**
816  * @tc.name: EventDumpTestNg023
817  * @tc.desc: EventTreeRecord AddGestureProcedure function test.
818  * @tc.type: FUNC
819  */
820 HWTEST_F(EventDumpTestNg, EventDumpTestNg023, TestSize.Level1)
821 {
822     /**
823      * @tc.steps: step1. create EventTreeRecord instance and fill touch event vale to eventTree.
824      */
825     auto eventTreeRecord = CreateEventTreeRecord();
826     ASSERT_NE(eventTreeRecord, nullptr);
827     AxisEvent event;
828     event.action = Ace::AxisAction::BEGIN;
829     event.id = 1;
830     eventTreeRecord->AddAxis(event);
831     AxisEvent event2;
832     event2.action = Ace::AxisAction::UPDATE;
833     event2.id = 2;
834     eventTreeRecord->AddAxis(event2);
835     AxisEvent event3;
836     event3.action = Ace::AxisAction::UPDATE;
837     event3.id = 3;
838     eventTreeRecord->AddAxis(event3);
839 
840     /**
841      * @tc.steps: step2. Invoke AddGestureProcedure function.
842      */
843     auto gestureSnapshot = AceType::MakeRefPtr<GestureSnapshot>();
844     int32_t finger = 0;
845     eventTreeRecord->AddGestureSnapshot(finger, std::move(gestureSnapshot));
846 
847     std::string state = "current";
848     std::string disposal = "mainThread";
849     std::string state2 = "current2";
850     std::string disposal2 = "mainThread2";
851     eventTreeRecord->AddGestureProcedure(finger + 1, event, "", state, disposal, DEFAULT_TIME_STAMP);
852     ASSERT_FALSE(eventTreeRecord->eventTreeList.empty());
853     auto iter = eventTreeRecord->eventTreeList.back().gestureMap.find(finger + 1);
854     EXPECT_TRUE(iter == eventTreeRecord->eventTreeList.back().gestureMap.end());
855 
856     eventTreeRecord->AddGestureProcedure(finger, event, "", state, disposal, DEFAULT_TIME_STAMP);
857     eventTreeRecord->AddGestureProcedure(finger, event2, "", state, disposal, DEFAULT_TIME_STAMP);
858     eventTreeRecord->AddGestureProcedure(finger, event3, "", state2, disposal2, DEFAULT_TIME_STAMP);
859 
860     ASSERT_FALSE(eventTreeRecord->eventTreeList.empty());
861     iter = eventTreeRecord->eventTreeList.back().gestureMap.find(finger);
862     ASSERT_TRUE(iter != eventTreeRecord->eventTreeList.back().gestureMap.end());
863     ASSERT_TRUE(iter->second != nullptr);
864     EXPECT_FALSE(iter->second->stateHistory.empty());
865 
866     std::list<std::pair<int32_t, std::string>> dumpList;
867     EXPECT_TRUE(dumpList.empty());
868     eventTreeRecord->Dump(dumpList, DEFAULT_DEPTH);
869     EXPECT_FALSE(dumpList.empty());
870 
871     std::unique_ptr<JsonValue> dumpJson = JsonUtil::Create(true);
872     int32_t depth = 0;
873     int32_t startNumber = -1;
874     std::string header = "event tree_0";
875     eventTreeRecord->Dump(dumpJson, depth, startNumber);
876     EXPECT_FALSE(dumpJson->Contains(header));
877 }
878 } // namespace OHOS::Ace::NG
879