• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 <optional>
17 
18 #include "gtest/gtest.h"
19 
20 #include "base/geometry/ng/offset_t.h"
21 #include "base/geometry/ng/size_t.h"
22 #include "base/memory/ace_type.h"
23 #include "core/components_ng/base/frame_node.h"
24 #include "core/components_ng/manager/event/json_child_report.h"
25 #include "core/components_ng/manager/event/json_report.h"
26 #include "core/gestures/gesture_info.h"
27 
28 using namespace testing;
29 using namespace testing::ext;
30 
31 namespace OHOS::Ace::NG {
32 namespace {
33 const Point globalPoint { 100.0, 100.0 };
34 const int32_t id = 1;
35 const int32_t startId = 1;
36 const int32_t dropId = 2;
37 const Offset offset(10, 10);
38 const Offset offsetLocal(15, 15);
39 const Offset offsetGlobal(20, 20);
40 const Offset offsetGlobalDisplay(30, 30);
41 const FingerInfo fingerInfo = { 0, 0, offset, offsetLocal, offsetGlobal, offsetGlobalDisplay, SourceType::TOUCH,
42     SourceTool::FINGER };
43 const std::list<FingerInfo> fingerList = { fingerInfo };
44 } // namespace
45 
46 class JsonReportTestNg : public testing::Test {};
47 /**
48  * @tc.name: JsonReportTestNgTypeTest001
49  * @tc.desc: RequestJsonReport Successfully and then ExitFullScreen Successfully
50  * @tc.type: FUNC
51  * @tc.author:
52  */
53 HWTEST_F(JsonReportTestNg, JsonReportTestNgTypeTest001, TestSize.Level1)
54 {
55     PanJsonReport panReport;
56     panReport.SetPoint(globalPoint);
57     panReport.SetCallbackType(GestureCallbackType::START);
58     panReport.SetId(id);
59     panReport.SetPanDirection(1);
60     auto valueStart = panReport.GetJsonData();
61     std::string JsonStrStart = valueStart->ToString().c_str();
62     std::string JsonStrStart1 =
63         "{\"GestureType\":\"Pan\",\"id\":1,\"action\":\"start\",\"point\":[100,100],\"direction\":1}";
64     EXPECT_EQ(JsonStrStart, JsonStrStart1);
65     panReport.SetCallbackType(GestureCallbackType::END);
66     auto valueEnd = panReport.GetJsonData();
67     std::string JsonStrEnd = valueEnd->ToString().c_str();
68     std::string JsonStrEnd1 =
69         "{\"GestureType\":\"Pan\",\"id\":1,\"action\":\"end\",\"point\":[100,100],\"direction\":1}";
70     EXPECT_EQ(JsonStrEnd, JsonStrEnd1);
71     panReport.SetCallbackType(GestureCallbackType::CANCEL);
72     auto valueCancel = panReport.GetJsonData();
73     std::string JsonStrCancel = valueCancel->ToString().c_str();
74     std::string JsonStrCancel1 = "{\"GestureType\":\"Pan\",\"action\":\"cancel\"}";
75     EXPECT_EQ(JsonStrCancel, JsonStrCancel1);
76 }
77 
78 /**
79  * @tc.name: JsonReportTestNgTypeTest002
80  * @tc.desc: RequestJsonReport Successfully and then ExitFullScreen Successfully
81  * @tc.type: FUNC
82  * @tc.author:
83  */
84 HWTEST_F(JsonReportTestNg, JsonReportTestNgTypeTest002, TestSize.Level1)
85 {
86     TapJsonReport tapReport;
87     tapReport.SetPoint(globalPoint);
88     tapReport.SetCount(0);
89     tapReport.SetId(id);
90     tapReport.SetFingerList(fingerList);
91     auto value = tapReport.GetJsonData();
92     std::string JsonStr = value->ToString().c_str();
93     std::string JsonStr1 = "{\"GestureType\":\"Tap\",\"id\":1,\"point\":[100,100],\"count\":0,\"fingers\":1}";
94     EXPECT_EQ(JsonStr, JsonStr1);
95 }
96 
97 /**
98  * @tc.name: JsonReportTestNgTypeTest003
99  * @tc.desc: RequestJsonReport Successfully and then ExitFullScreen Successfully
100  * @tc.type: FUNC
101  * @tc.author:
102  */
103 HWTEST_F(JsonReportTestNg, JsonReportTestNgTypeTest003, TestSize.Level1)
104 {
105     LongPressJsonReport longPressReport;
106     longPressReport.SetPoint(globalPoint);
107     longPressReport.SetId(id);
108     longPressReport.SetDuration(100000000);
109     auto value = longPressReport.GetJsonData();
110     std::string JsonStr = value->ToString().c_str();
111     std::string JsonStr1 =
112         "{\"GestureType\":\"LongPress\",\"id\":1,\"action\":\"end\",\"point\":[100,100],\"actualDuration\":100}";
113     EXPECT_EQ(JsonStr, JsonStr1);
114 }
115 /**
116  * @tc.name: JsonReportTestNgTypeTest004
117  * @tc.desc: RequestJsonReport Successfully and then ExitFullScreen Successfully
118  * @tc.type: FUNC
119  * @tc.author:
120  */
121 HWTEST_F(JsonReportTestNg, JsonReportTestNgTypeTest004, TestSize.Level1)
122 {
123     PinchJsonReport pinchReport;
124     pinchReport.SetPoint(globalPoint);
125     pinchReport.SetCallbackType(GestureCallbackType::START);
126     pinchReport.SetId(id);
127     pinchReport.SetFingerList(fingerList);
128     auto valueStart = pinchReport.GetJsonData();
129     std::string JsonStrStart = valueStart->ToString().c_str();
130     std::string JsonStrStart1 =
131         "{\"GestureType\":\"Pinch\",\"id\":1,\"action\":\"start\",\"point\":[[10,10]],\"fingers\":1}";
132     EXPECT_EQ(JsonStrStart, JsonStrStart1);
133     pinchReport.SetCallbackType(GestureCallbackType::END);
134     pinchReport.SetScale(1);
135     auto valueEnd = pinchReport.GetJsonData();
136     std::string JsonStrEnd = valueEnd->ToString().c_str();
137     std::string JsonStrEnd1 =
138         "{\"GestureType\":\"Pinch\",\"id\":1,\"action\":\"end\",\"point\":[[10,10]],\"fingers\":1,\"scale\":1}";
139     EXPECT_EQ(JsonStrEnd, JsonStrEnd1);
140     pinchReport.SetCallbackType(GestureCallbackType::CANCEL);
141     auto valueCancel = pinchReport.GetJsonData();
142     std::string JsonStrCancel = valueCancel->ToString().c_str();
143     std::string JsonStrCancel1 = "{\"GestureType\":\"Pinch\",\"action\":\"cancel\"}";
144     EXPECT_EQ(JsonStrCancel, JsonStrCancel1);
145 }
146 
147 /**
148  * @tc.name: JsonReportTestNgTypeTest005
149  * @tc.desc: RequestJsonReport Successfully and then ExitFullScreen Successfully
150  * @tc.type: FUNC
151  * @tc.author:
152  */
153 HWTEST_F(JsonReportTestNg, JsonReportTestNgTypeTest005, TestSize.Level1)
154 {
155     RotationJsonReport rotationReport;
156     rotationReport.SetPoint(globalPoint);
157     rotationReport.SetCallbackType(GestureCallbackType::START);
158     rotationReport.SetId(id);
159     rotationReport.SetFingerList(fingerList);
160     auto valueStart = rotationReport.GetJsonData();
161     std::string JsonStrStart = valueStart->ToString().c_str();
162     std::string JsonStrStart1 =
163         "{\"GestureType\":\"Rotation\",\"id\":1,\"action\":\"start\",\"point\":[[10,10]],\"fingers\":1}";
164     EXPECT_EQ(JsonStrStart, JsonStrStart1);
165     rotationReport.SetCallbackType(GestureCallbackType::END);
166     rotationReport.SetAngle(1.0);
167     auto valueEnd = rotationReport.GetJsonData();
168     std::string JsonStrEnd = valueEnd->ToString().c_str();
169     std::string JsonStrEnd1 =
170         "{\"GestureType\":\"Rotation\",\"id\":1,\"action\":\"end\",\"point\":[[10,10]],\"fingers\":1,\"angle\":1}";
171     EXPECT_EQ(JsonStrEnd, JsonStrEnd1);
172     rotationReport.SetCallbackType(GestureCallbackType::CANCEL);
173     auto valueCancel = rotationReport.GetJsonData();
174     std::string JsonStrCancel = valueCancel->ToString().c_str();
175     std::string JsonStrCancel1 = "{\"GestureType\":\"Rotation\",\"action\":\"cancel\"}";
176     EXPECT_EQ(JsonStrCancel, JsonStrCancel1);
177 }
178 /**
179  * @tc.name: JsonReportTestNgTypeTest006
180  * @tc.desc: RequestJsonReport Successfully and then ExitFullScreen Successfully
181  * @tc.type: FUNC
182  * @tc.author:
183  */
184 HWTEST_F(JsonReportTestNg, JsonReportTestNgTypeTest006, TestSize.Level1)
185 {
186     std::map<int32_t, TouchEvent> touchPoints_;
187     std::map<int32_t, TouchEvent> touchPointsEmpty_;
188     TouchEvent point;
189     point.id = 1;
190     point.x = 20;
191     point.y = 20;
192     touchPoints_[1] = point;
193     SwipeJsonReport swipeReport;
194     swipeReport.SetPoint(globalPoint);
195     swipeReport.SetId(id);
196     swipeReport.SetSwipeDirection(2);
197     swipeReport.SetSpeed(1.0);
198     swipeReport.SetActualSpeed(1.0);
199     swipeReport.SetFingerList(fingerList);
200     swipeReport.SetTouchEvents(touchPoints_);
201     auto value = swipeReport.GetJsonData();
202     std::string JsonStr = value->ToString().c_str();
203     std::string JsonStr1 = "{\"GestureType\":\"Swipe\",\"id\":1,\"upPoint\":[[10,10]],\"downPoint\":[[20,20]],"
204                            "\"direction\":2,\"speed\":0,\"actualSpeed\":0}";
205     EXPECT_EQ(JsonStr, JsonStr1);
206     swipeReport.SetTouchEvents(touchPointsEmpty_);
207     auto value1 = swipeReport.GetJsonData();
208     std::string JsonUisessionStr = value1->ToString().c_str();
209     std::string JsonUisessionStr1 = "{\"GestureType\":\"Swipe\",\"id\":1,\"upPoint\":[[10,10]],\"downPoint\":[[10,10]],"
210                            "\"direction\":2,\"speed\":0,\"actualSpeed\":0}";
211     EXPECT_EQ(JsonUisessionStr, JsonUisessionStr1);
212 }
213 /**
214  * @tc.name: JsonReportTestNgTypeTest007
215  * @tc.desc: RequestJsonReport Successfully and then ExitFullScreen Successfully
216  * @tc.type: FUNC
217  * @tc.author:
218  */
219 HWTEST_F(JsonReportTestNg, JsonReportTestNgTypeTest007, TestSize.Level1)
220 {
221     ClickJsonReport clickReport;
222     clickReport.SetPoint(globalPoint);
223     clickReport.SetId(id);
224     clickReport.SetCount(12);
225     clickReport.SetFingerList(fingerList);
226     auto value = clickReport.GetJsonData();
227     std::string JsonStr = value->ToString().c_str();
228     std::string JsonStr1 = "{\"GestureType\":\"Click\",\"id\":1,\"point\":[100,100],\"count\":12,\"fingers\":1}";
229     EXPECT_EQ(JsonStr, JsonStr1);
230 }
231 /**
232  * @tc.name: JsonReportTestNgTypeTest008
233  * @tc.desc: RequestJsonReport Successfully and then ExitFullScreen Successfully
234  * @tc.type: FUNC
235  * @tc.author:
236  */
237 HWTEST_F(JsonReportTestNg, JsonReportTestNgTypeTest008, TestSize.Level1)
238 {
239     DragJsonReport dragReport;
240     dragReport.SetPoint(globalPoint);
241     dragReport.SetDragReporterPharse(DragReporterPharse::DRAG_START);
242     dragReport.SetStartId(startId);
243     dragReport.SetDropId(dropId);
244     dragReport.SetHostName("test");
245     dragReport.SetActualDuration(2);
246     auto valueDragstart = dragReport.GetJsonData();
247     std::string JsonStrDragstart = valueDragstart->ToString().c_str();
248     std::string JsonStrDragstart1 =
249         "{\"GestureType\":\"DragStart\",\"id\":1,\"point\":[0,0],\"hostName\":\"test\",\"actualDuration\":2}";
250     EXPECT_EQ(JsonStrDragstart, JsonStrDragstart1);
251 
252     dragReport.SetDragReporterPharse(DragReporterPharse::DRAG_STOP);
253     dragReport.SetDropResult(DropResult::DROP_SUCCESS);
254     auto valueDropsuccess = dragReport.GetJsonData();
255     std::string JsonStrDropsuccess = valueDropsuccess->ToString().c_str();
256     std::string JsonStrDropsuccess1 =
257         "{\"GestureType\":\"DrageEnd\",\"point\":[0,0],\"dropResult\":\"success\",\"id\":2,\"hostName\":\"test\"}";
258     EXPECT_EQ(JsonStrDropsuccess, JsonStrDropsuccess1);
259 
260     dragReport.SetDragReporterPharse(DragReporterPharse::DRAG_STOP);
261     dragReport.SetDropResult(DropResult::DROP_FAIL);
262     auto valueDopfail = dragReport.GetJsonData();
263     std::string JsonStrDopfail = valueDopfail->ToString().c_str();
264     std::string JsonStrDopfail1 =
265         "{\"GestureType\":\"DrageEnd\",\"point\":[0,0],\"dropResult\":\"fail\",\"hostName\":\"test\"}";
266     EXPECT_EQ(JsonStrDopfail, JsonStrDopfail1);
267 }
268 } // namespace OHOS::Ace::NG
269