• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 <cstdio>
17 #include <fstream>
18 #include <gtest/gtest.h>
19 
20 #include "mmi_log.h"
21 #include "pointer_event.h"
22 #ifndef USE_ROSEN_DRAWING
23 #define USE_ROSEN_DRAWING
24 #endif
25 #include "touch_drawing_manager.h"
26 #include "window_info.h"
27 
28 #undef MMI_LOG_TAG
29 #define MMI_LOG_TAG "TouchDrawingManagerTest"
30 
31 namespace OHOS {
32 namespace MMI {
33 namespace {
34 using namespace testing::ext;
35 constexpr int32_t ONE_SECOND = 1000;
36 } // namespace
37 class TouchDrawingManagerTest : public testing::Test {
38 public:
SetUpTestCase(void)39     static void SetUpTestCase(void) {};
TearDownTestCase(void)40     static void TearDownTestCase(void) {};
SetUp(void)41     void SetUp(void)
42     {
43         OLD::DisplayInfo info;
44         info.id = 1;
45         info.x = 1;
46         info.y = 1;
47         info.width = 1;
48         info.height = 1;
49         int32_t displayDpi = 240;
50         info.dpi = displayDpi;
51         info.name = "xx";
52         info.uniq = "xx";
53         info.direction = DIRECTION0;
54         TOUCH_DRAWING_MGR->UpdateDisplayInfo(info);
55     }
56 
TearDown()57     void TearDown()
58     {
59         std::this_thread::sleep_for(std::chrono::milliseconds(ONE_SECOND));
60     }
61 };
62 
63 /**
64  * @tc.name: TouchDrawingManagerTest_GetOriginalTouchScreenCoordinates_001
65  * @tc.desc: Test GetOriginalTouchScreenCoordinates
66  * @tc.type: Function
67  * @tc.require:
68  */
69 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_GetOriginalTouchScreenCoordinates_001, TestSize.Level1)
70 {
71     CALL_TEST_DEBUG;
72     int32_t width = 100;
73     int32_t height = 200;
74     int32_t physicalX = 50;
75     int32_t physicalY = 60;
76     TOUCH_DRAWING_MGR->GetOriginalTouchScreenCoordinates(DIRECTION0, width, height, physicalX, physicalY);
77     EXPECT_EQ(physicalX, 50);
78     EXPECT_EQ(physicalY, 60);
79 }
80 
81 /**
82  * @tc.name: TouchDrawingManagerTest_GetOriginalTouchScreenCoordinates_002
83  * @tc.desc: Test GetOriginalTouchScreenCoordinates
84  * @tc.type: Function
85  * @tc.require:
86  */
87 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_GetOriginalTouchScreenCoordinates_002, TestSize.Level1)
88 {
89     CALL_TEST_DEBUG;
90     int32_t width = 100;
91     int32_t height = 200;
92     int32_t physicalX = 50;
93     int32_t physicalY = 60;
94     TOUCH_DRAWING_MGR->GetOriginalTouchScreenCoordinates(DIRECTION90, width, height, physicalX, physicalY);
95     EXPECT_EQ(physicalX, 60);
96     EXPECT_EQ(physicalY, 50);
97 }
98 
99 /**
100  * @tc.name: TouchDrawingManagerTest_GetOriginalTouchScreenCoordinates_003
101  * @tc.desc: Test GetOriginalTouchScreenCoordinates
102  * @tc.type: Function
103  * @tc.require:
104  */
105 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_GetOriginalTouchScreenCoordinates_003, TestSize.Level1)
106 {
107     CALL_TEST_DEBUG;
108     int32_t width = 100;
109     int32_t height = 200;
110     int32_t physicalX = 50;
111     int32_t physicalY = 60;
112     TOUCH_DRAWING_MGR->GetOriginalTouchScreenCoordinates(DIRECTION180, width, height, physicalX, physicalY);
113     EXPECT_EQ(physicalX, 50);
114     EXPECT_EQ(physicalY, 140);
115 }
116 
117 /**
118  * @tc.name: TouchDrawingManagerTest_GetOriginalTouchScreenCoordinates_004
119  * @tc.desc: Test GetOriginalTouchScreenCoordinates
120  * @tc.type: Function
121  * @tc.require:
122  */
123 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_GetOriginalTouchScreenCoordinates_004, TestSize.Level1)
124 {
125     CALL_TEST_DEBUG;
126     int32_t width = 100;
127     int32_t height = 200;
128     int32_t physicalX = 50;
129     int32_t physicalY = 60;
130     TOUCH_DRAWING_MGR->GetOriginalTouchScreenCoordinates(DIRECTION270, width, height, physicalX, physicalY);
131     EXPECT_EQ(physicalX, 140);
132     EXPECT_EQ(physicalY, 50);
133 }
134 
135 /**
136  * @tc.name: TouchDrawingManagerTest_RotationScreen_001
137  * @tc.desc: Test TouchDrawingManager::RotationScreen
138  * @tc.type: Function
139  * @tc.require:
140  */
141 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_RotationScreen_001, TestSize.Level1)
142 {
143     CALL_TEST_DEBUG;
144     TOUCH_DRAWING_MGR->LoadTouchDrawingHandler();
145     EXPECT_NO_FATAL_FAILURE(TOUCH_DRAWING_MGR->RotationScreen());
146 }
147 
148 /**
149  * @tc.name: TouchDrawingManagerTest_UpdateLabels_001
150  * @tc.desc: Test TouchDrawingManager::UpdateLabels
151  * @tc.type: Function
152  * @tc.require:
153  */
154 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_UpdateLabels_001, TestSize.Level1)
155 {
156     CALL_TEST_DEBUG;
157     TOUCH_DRAWING_MGR->pointerMode_.isShow = true;
158     EXPECT_NO_FATAL_FAILURE(TOUCH_DRAWING_MGR->UpdateLabels());
159     EXPECT_NE(TOUCH_DRAWING_MGR->GetTouchDrawingHandler(), nullptr);
160 }
161 
162 /**
163  * @tc.name: TouchDrawingManagerTest_UpdateLabels_002
164  * @tc.desc: Test TouchDrawingManager::UpdateLabels
165  * @tc.type: Function
166  * @tc.require:
167  */
168 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_UpdateLabels_002, TestSize.Level1)
169 {
170     CALL_TEST_DEBUG;
171     TOUCH_DRAWING_MGR->pointerMode_.isShow = false;
172     EXPECT_NO_FATAL_FAILURE(TOUCH_DRAWING_MGR->UpdateLabels());
173     EXPECT_EQ(TOUCH_DRAWING_MGR->GetTouchDrawingHandler(), nullptr);
174 }
175 
176 /**
177  * @tc.name: TouchDrawingManagerTest_UpdateBubbleData_001
178  * @tc.desc: Test TouchDrawingManager::UpdateBubbleData
179  * @tc.type: Function
180  * @tc.require:
181  */
182 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_UpdateBubbleData_001, TestSize.Level1)
183 {
184     CALL_TEST_DEBUG;
185     TOUCH_DRAWING_MGR->bubbleMode_.isShow = true;
186     EXPECT_NO_FATAL_FAILURE(TOUCH_DRAWING_MGR->UpdateBubbleData());
187     EXPECT_NE(TOUCH_DRAWING_MGR->GetTouchDrawingHandler(), nullptr);
188 }
189 
190 /**
191  * @tc.name: TouchDrawingManagerTest_UpdateBubbleData_002
192  * @tc.desc: Test TouchDrawingManager::UpdateBubbleData
193  * @tc.type: Function
194  * @tc.require:
195  */
196 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_UpdateBubbleData_002, TestSize.Level1)
197 {
198     CALL_TEST_DEBUG;
199     TOUCH_DRAWING_MGR->bubbleMode_.isShow = false;
200     EXPECT_NO_FATAL_FAILURE(TOUCH_DRAWING_MGR->UpdateBubbleData());
201     EXPECT_EQ(TOUCH_DRAWING_MGR->GetTouchDrawingHandler(), nullptr);
202 }
203 
204 /**
205  * @tc.name: TouchDrawingManagerTest_LoadTouchDrawingHandler_001
206  * @tc.desc: Test TouchDrawingManager::LoadTouchDrawingHandler
207  * @tc.type: Function
208  * @tc.require:
209  */
210 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_LoadTouchDrawingHandler_001, TestSize.Level1)
211 {
212     CALL_TEST_DEBUG;
213     EXPECT_NO_FATAL_FAILURE(TOUCH_DRAWING_MGR->LoadTouchDrawingHandler());
214     EXPECT_NE(TOUCH_DRAWING_MGR->GetTouchDrawingHandler(), nullptr);
215 }
216 
217 /**
218  * @tc.name: TouchDrawingManagerTest_TouchDrawHandler
219  * @tc.desc: Test TouchDrawHandler
220  * @tc.type: Function
221  * @tc.require:
222  */
223 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_TouchDrawHandler, TestSize.Level1)
224 {
225     CALL_TEST_DEBUG;
226     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
227     ASSERT_NE(pointerEvent, nullptr);
228     PointerEvent::PointerItem item;
229     item.SetPointerId(1);
230     item.SetPressed(false);
231     pointerEvent->AddPointerItem(item);
232     pointerEvent->SetPointerId(1);
233     pointerEvent->SetTargetDisplayId(10);
234     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
235     EXPECT_NO_FATAL_FAILURE(TOUCH_DRAWING_MGR->TouchDrawHandler(pointerEvent));
236 }
237 
238 /**
239  * @tc.name: TouchDrawingManagerTest_UpdateDisplayInfo
240  * @tc.desc: Test UpdateDisplayInfo
241  * @tc.type: Function
242  * @tc.require:
243  */
244 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_UpdateDisplayInfo, TestSize.Level1)
245 {
246     CALL_TEST_DEBUG;
247     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
248     ASSERT_NE(pointerEvent, nullptr);
249     PointerEvent::PointerItem item;
250     item.SetPointerId(1);
251     item.SetPressed(false);
252     OLD::DisplayInfo displayInfo;
253     displayInfo.id = 0;
254     displayInfo.width = 10;
255     displayInfo.height = 20;
256     displayInfo.validWidth = displayInfo.width;
257     displayInfo.validHeight = displayInfo.height;
258     displayInfo.direction = DIRECTION90;
259     displayInfo.name = "Main Display";
260     EXPECT_NO_FATAL_FAILURE(TOUCH_DRAWING_MGR->UpdateDisplayInfo(displayInfo));
261 }
262 
263 /**
264  * @tc.name: TouchDrawingManagerTest_UpdateLabels
265  * @tc.desc: Test UpdateLabels
266  * @tc.type: Function
267  * @tc.require:
268  */
269 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_UpdateLabels, TestSize.Level1)
270 {
271     CALL_TEST_DEBUG;
272     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
273     ASSERT_NE(pointerEvent, nullptr);
274     TOUCH_DRAWING_MGR->pointerMode_.isShow = true;
275     PointerEvent::PointerItem item;
276     item.SetPointerId(1);
277     item.SetPressed(true);
278     EXPECT_NO_FATAL_FAILURE(TOUCH_DRAWING_MGR->UpdateLabels());
279 
280     TOUCH_DRAWING_MGR->pointerMode_.isShow = false;
281     EXPECT_NO_FATAL_FAILURE(TOUCH_DRAWING_MGR->UpdateLabels());
282 }
283 
284 /**
285  * @tc.name: TouchDrawingManagerTest_UpdateBubbleData
286  * @tc.desc: Test UpdateBubbleData
287  * @tc.type: Function
288  * @tc.require:
289  */
290 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_UpdateBubbleData, TestSize.Level1)
291 {
292     CALL_TEST_DEBUG;
293     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
294     ASSERT_NE(pointerEvent, nullptr);
295     TOUCH_DRAWING_MGR->bubbleMode_.isShow = true;
296     PointerEvent::PointerItem item;
297     item.SetPointerId(1);
298     item.SetPressed(true);
299     EXPECT_NO_FATAL_FAILURE(TOUCH_DRAWING_MGR->UpdateBubbleData());
300 
301     TOUCH_DRAWING_MGR->bubbleMode_.isShow = false;
302     EXPECT_NO_FATAL_FAILURE(TOUCH_DRAWING_MGR->UpdateBubbleData());
303 }
304 
305 /**
306  * @tc.name: TouchDrawingManagerTest_IsWindowRotation
307  * @tc.desc: Test IsWindowRotation
308  * @tc.type: Function
309  * @tc.require:
310  */
311 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_IsWindowRotation, TestSize.Level1)
312 {
313     CALL_TEST_DEBUG;
314     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
315     ASSERT_NE(pointerEvent, nullptr);
316     PointerEvent::PointerItem item;
317     item.SetPointerId(1);
318     item.SetPressed(true);
319     EXPECT_NO_FATAL_FAILURE(TOUCH_DRAWING_MGR->IsWindowRotation());
320 }
321 
322 /**
323  * @tc.name: TouchDrawingManagerTest_SetDelegateProxy
324  * @tc.desc: Test SetDelegateProxy
325  * @tc.type: Function
326  * @tc.require:
327  */
328 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_SetDelegateProxy, TestSize.Level1)
329 {
330     CALL_TEST_DEBUG;
331     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
332     ASSERT_NE(pointerEvent, nullptr);
333     PointerEvent::PointerItem item;
334     item.SetPointerId(1);
335     item.SetPressed(true);
336     std::shared_ptr<DelegateInterface> proxy;
337     EXPECT_NO_FATAL_FAILURE(TOUCH_DRAWING_MGR->SetDelegateProxy(proxy));
338     EXPECT_EQ(TOUCH_DRAWING_MGR->delegateProxy_, proxy);
339 }
340 
341 /**
342  * @tc.name: TouchDrawingManagerTest_SetMultiWindowScreenId
343  * @tc.desc: Test SetMultiWindowScreenId
344  * @tc.type: Function
345  * @tc.require:
346  */
347 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_SetMultiWindowScreenId, TestSize.Level1)
348 {
349     CALL_TEST_DEBUG;
350     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
351     ASSERT_NE(pointerEvent, nullptr);
352     uint64_t screenId = 1000;
353     uint64_t displayNodeScreenId = 0;
354     PointerEvent::PointerItem item;
355     item.SetPointerId(1);
356     item.SetPressed(true);
357     std::shared_ptr<DelegateInterface> proxy;
358     EXPECT_NO_FATAL_FAILURE(TOUCH_DRAWING_MGR->SetMultiWindowScreenId(screenId, displayNodeScreenId));
359 }
360 
361 /**
362  * @tc.name: TouchDrawingManagerTest_ResetTouchWindow
363  * @tc.desc: Test ResetTouchWindow
364  * @tc.type: Function
365  * @tc.require:
366  */
367 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_ResetTouchWindow, TestSize.Level1)
368 {
369     CALL_TEST_DEBUG;
370     TouchDrawingManager touchDrawingMgr;
371     touchDrawingMgr.bubbleMode_.isShow = true;
372     touchDrawingMgr.pointerMode_.isShow = true;
373     EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.ResetTouchWindow());
374     touchDrawingMgr.touchDrawingHandler_ = ComponentManager::LoadLibrary<ITouchDrawingHandler>(nullptr,
375         "libmmi_touch_drawing_handler.z.so");
376     EXPECT_NO_FATAL_FAILURE(touchDrawingMgr.ResetTouchWindow());
377 }
378 
379 /**
380  * @tc.name: TouchDrawingManagerTest_AddUpdateLabelsTimer_ShouldDoNothing_WhenTimerIsRunning
381  * @tc.desc: Test AddUpdateLabelsTimer
382  * @tc.type: Function
383  * @tc.require:
384  */
385 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_AddUpdateLabelsTimer_ShouldDoNothing_WhenTimerIsRunning,
386     TestSize.Level1)
387 {
388     CALL_TEST_DEBUG;
389     TouchDrawingManager touchDrawingMgr;
390     touchDrawingMgr.timerId_ = 1;
391     touchDrawingMgr.AddUpdateLabelsTimer();
392     EXPECT_EQ(touchDrawingMgr.timerId_, 1);
393 }
394 
395 /**
396  * @tc.name: TouchDrawingManagerTest_AddUpdateLabelsTimer_ShouldDoNothing_WhenTimerIsRunning
397  * @tc.desc: Test AddUpdateLabelsTimer
398  * @tc.type: Function
399  * @tc.require:
400  */
401 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_AddUpdateLabelsTimer_WhenTouchDrawingHandler,
402     TestSize.Level1)
403 {
404     CALL_TEST_DEBUG;
405     TouchDrawingManager touchDrawingMgr;
406     touchDrawingMgr.timerId_ = -1;
407     touchDrawingMgr.LoadTouchDrawingHandler();
408     touchDrawingMgr.AddUpdateLabelsTimer();
409     EXPECT_NE(touchDrawingMgr.timerId_, -1);
410 }
411 
412 /**
413  * @tc.name: TouchDrawingManagerTest_RemoveUpdateLabelsTimer_ShouldRemoveTimer
414  * @tc.desc: Test RemoveUpdateLabelsTimer
415  * @tc.type: Function
416  * @tc.require:
417  */
418 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_RemoveUpdateLabelsTimer_ShouldRemoveTimer, TestSize.Level1)
419 {
420     CALL_TEST_DEBUG;
421     TouchDrawingManager touchDrawingMgr;
422     touchDrawingMgr.timerId_ = 1;
423     touchDrawingMgr.RemoveUpdateLabelsTimer();
424     EXPECT_EQ(touchDrawingMgr.timerId_, -1);
425 }
426 
427 /**
428  * @tc.name: TouchDrawingManagerTest_RemoveUpdateLabelsTimer_ShouldRemoveTimer
429  * @tc.desc: Test RemoveUpdateLabelsTimer
430  * @tc.type: Function
431  * @tc.require:
432  */
433 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_RemoveUpdateLabelsTimer_ShouldNotRemoveTimer, TestSize.Level1)
434 {
435     CALL_TEST_DEBUG;
436     TouchDrawingManager touchDrawingMgr;
437     touchDrawingMgr.timerId_ = -1;
438     touchDrawingMgr.RemoveUpdateLabelsTimer();
439     EXPECT_EQ(touchDrawingMgr.timerId_, -1);
440 }
441 } // namespace MMI
442 } // namespace OHOS
443