• 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 #include <cstdio>
16 #include <fstream>
17 #include <gtest/gtest.h>
18 
19 #include "mmi_log.h"
20 #include "screen_pointer.h"
21 
22 #undef MMI_LOG_TAG
23 #define MMI_LOG_TAG "ScreenPointerTest"
24 
25 namespace OHOS {
26 namespace MMI {
27 namespace {
28 using namespace testing::ext;
29 } // namespace
30 class ScreenPointerTest : public testing::Test {
31 public:
SetUpTestCase(void)32     static void SetUpTestCase(void) {};
TearDownTestCase(void)33     static void TearDownTestCase(void) {};
SetUp(void)34     void SetUp(void) {};
35 };
36 
37 /**
38  * @tc.name: ScreenPointerTest_GetRenderDPI_001
39  * @tc.desc: Test GetRenderDPI
40  * @tc.type: Function
41  * @tc.require:
42  */
43 HWTEST_F(ScreenPointerTest, ScreenPointerTest_GetRenderDPI_001, TestSize.Level1)
44 {
45     CALL_TEST_DEBUG;
46     hwcmgr_ptr_t hwcmgr = nullptr;
47     handler_ptr_t handler = nullptr;
48     DisplayInfo di;
49     ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di);
50     ASSERT_NE(screenpointer, nullptr);
51     screenpointer->isCurrentOffScreenRendering_ = true;
52     screenpointer->mode_ = mode_t::SCREEN_MIRROR;
53     float ret = screenpointer->GetRenderDPI();
54     EXPECT_EQ(ret, 0);
55     screenpointer->mode_ = mode_t::SCREEN_MAIN;
56     ret = screenpointer->GetRenderDPI();
57     screenpointer->isCurrentOffScreenRendering_ = false;
58     screenpointer->mode_ = mode_t::SCREEN_MIRROR;
59     ret = screenpointer->GetRenderDPI();
60     screenpointer->mode_ = mode_t::SCREEN_MAIN;
61     ret = screenpointer->GetRenderDPI();
62     EXPECT_EQ(ret, 0);
63 }
64 
65 /**
66  * @tc.name: ScreenPointerTest_SetInvisible_001
67  * @tc.desc: Test SetInvisible
68  * @tc.type: Function
69  * @tc.require:
70  */
71 HWTEST_F(ScreenPointerTest, ScreenPointerTest_SetInvisible_001, TestSize.Level1)
72 {
73     CALL_TEST_DEBUG;
74     hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>();
75     ASSERT_NE(hwcmgr, nullptr);
76     handler_ptr_t handler = nullptr;
77     DisplayInfo di;
78     ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di);
79     ASSERT_NE(screenpointer, nullptr);
80     bool ret = screenpointer->SetInvisible();
81     EXPECT_TRUE(ret);
82 }
83 
84 /**
85  * @tc.name: ScreenPointerTest_MoveSoft_001
86  * @tc.desc: Test MoveSoft
87  * @tc.type: Function
88  * @tc.require:
89  */
90 HWTEST_F(ScreenPointerTest, ScreenPointerTest_MoveSoft_001, TestSize.Level1)
91 {
92     CALL_TEST_DEBUG;
93     hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>();
94     ASSERT_NE(hwcmgr, nullptr);
95     handler_ptr_t handler = nullptr;
96     DisplayInfo di;
97     ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di);
98     ASSERT_NE(screenpointer, nullptr);
99     Rosen::RSSurfaceNodeConfig surfaceNodeConfig;
100     surfaceNodeConfig.SurfaceNodeName = "pointer window";
101     screenpointer->surfaceNode_ = Rosen::RSSurfaceNode::Create(surfaceNodeConfig,
102         Rosen::RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE);
103     ASSERT_NE(screenpointer->surfaceNode_, nullptr);
104     screenpointer->mode_ = mode_t::SCREEN_MIRROR;
105     ICON_TYPE align = ANGLE_W;
106     int32_t x = 0;
107     int32_t y = 0;
108     bool ret = screenpointer->MoveSoft(x, y, align);
109     EXPECT_TRUE(ret);
110     screenpointer->mode_ = mode_t::SCREEN_MAIN;
111     ret = screenpointer->MoveSoft(x, y, align);
112     EXPECT_TRUE(ret);
113     screenpointer->mode_ = mode_t::SCREEN_EXTEND;
114     ret = screenpointer->MoveSoft(x, y, align);
115     EXPECT_TRUE(ret);
116 }
117 
118 /**
119  * @tc.name: ScreenPointerTest_Move_001
120  * @tc.desc: Test Move
121  * @tc.type: Function
122  * @tc.require:
123  */
124 HWTEST_F(ScreenPointerTest, ScreenPointerTest_Move_001, TestSize.Level1)
125 {
126     CALL_TEST_DEBUG;
127     hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>();
128     ASSERT_NE(hwcmgr, nullptr);
129     handler_ptr_t handler = nullptr;
130     DisplayInfo di;
131     ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di);
132     ASSERT_NE(screenpointer, nullptr);
133     Rosen::RSSurfaceNodeConfig surfaceNodeConfig;
134     surfaceNodeConfig.SurfaceNodeName = "pointer window";
135     screenpointer->surfaceNode_ = Rosen::RSSurfaceNode::Create(surfaceNodeConfig,
136         Rosen::RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE);
137     ASSERT_NE(screenpointer->surfaceNode_, nullptr);
138     screenpointer->mode_ = mode_t::SCREEN_MIRROR;
139     screenpointer->isCurrentOffScreenRendering_ = true;
140     ICON_TYPE align = ANGLE_W;
141     int32_t x = 0;
142     int32_t y = 0;
143     bool ret = screenpointer->Move(x, y, align);
144     EXPECT_TRUE(ret);
145     screenpointer->mode_ = mode_t::SCREEN_MAIN;
146     screenpointer->isCurrentOffScreenRendering_ = true;
147     ret = screenpointer->Move(x, y, align);
148     EXPECT_TRUE(ret);
149     screenpointer->mode_ = mode_t::SCREEN_EXTEND;
150     screenpointer->isCurrentOffScreenRendering_ = false;
151     ret = screenpointer->Move(x, y, align);
152     EXPECT_TRUE(ret);
153     screenpointer->mode_ = mode_t::SCREEN_MIRROR;
154     screenpointer->isCurrentOffScreenRendering_ = false;
155     ret = screenpointer->Move(x, y, align);
156     EXPECT_TRUE(ret);
157 }
158 
159 /**
160  * @tc.name: ScreenPointerTest_Rotate_001
161  * @tc.desc: Test Rotate
162  * @tc.type: Function
163  * @tc.require:
164  */
165 HWTEST_F(ScreenPointerTest, ScreenPointerTest_Rotate_001, TestSize.Level1)
166 {
167     CALL_TEST_DEBUG;
168     hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>();
169     ASSERT_NE(hwcmgr, nullptr);
170     handler_ptr_t handler = nullptr;
171     DisplayInfo di;
172     ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di);
173     ASSERT_NE(screenpointer, nullptr);
174     int32_t x = 0;
175     int32_t y = 0;
176     rotation_t rotation = rotation_t(DIRECTION90);
177     screenpointer->mode_ = mode_t::SCREEN_MIRROR;
178     screenpointer->rotation_ = rotation_t::ROTATION_0;
179     EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y));
180     screenpointer->rotation_ = rotation_t::ROTATION_90;
181     EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y));
182     screenpointer->rotation_ = rotation_t::ROTATION_180;
183     EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y));
184     screenpointer->rotation_ = rotation_t::ROTATION_270;
185     EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y));
186     screenpointer->mode_ = mode_t::SCREEN_MAIN;
187     screenpointer->rotation_ = rotation_t::ROTATION_0;
188     EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y));
189     screenpointer->rotation_ = rotation_t::ROTATION_90;
190     EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y));
191     screenpointer->rotation_ = rotation_t::ROTATION_180;
192     EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y));
193     screenpointer->rotation_ = rotation_t::ROTATION_270;
194     EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y));
195 }
196 
197 /**
198  * @tc.name: ScreenPointerTest_Rotate_002
199  * @tc.desc: Test Rotate
200  * @tc.type: Function
201  * @tc.require:
202  */
203 HWTEST_F(ScreenPointerTest, ScreenPointerTest_Rotate_002, TestSize.Level1)
204 {
205     CALL_TEST_DEBUG;
206     hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>();
207     ASSERT_NE(hwcmgr, nullptr);
208     handler_ptr_t handler = nullptr;
209     DisplayInfo di;
210     ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di);
211     ASSERT_NE(screenpointer, nullptr);
212     int32_t x = 0;
213     int32_t y = 0;
214     screenpointer->mode_ = mode_t::SCREEN_MAIN;
215     screenpointer->rotation_ = rotation_t::ROTATION_180;
216     rotation_t rotation = rotation_t(DIRECTION90);
217     EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y));
218     rotation = rotation_t(DIRECTION180);
219     EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y));
220     rotation = rotation_t(DIRECTION270);
221     EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y));
222     rotation = rotation_t(DIRECTION0);
223     EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y));
224 }
225 
226 /**
227  * @tc.name: ScreenPointerTest_GetCurrentBuffer_001
228  * @tc.desc: Test GetCurrentBuffer
229  * @tc.type: Function
230  * @tc.require:
231  */
232 HWTEST_F(ScreenPointerTest, ScreenPointerTest_GetCurrentBuffer_001, TestSize.Level1)
233 {
234     CALL_TEST_DEBUG;
235     hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>();
236     ASSERT_NE(hwcmgr, nullptr);
237     handler_ptr_t handler = nullptr;
238     DisplayInfo di;
239     ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di);
240     ASSERT_NE(screenpointer, nullptr);
241     screenpointer->bufferId_ = 0;
242     EXPECT_NO_FATAL_FAILURE(screenpointer->GetCurrentBuffer());
243     sptr<OHOS::SurfaceBuffer> buffer = OHOS::SurfaceBuffer::Create();
244     screenpointer->buffers_.push_back(buffer);
245     EXPECT_NO_FATAL_FAILURE(screenpointer->GetCurrentBuffer());
246 }
247 
248 /**
249  * @tc.name: ScreenPointerTest_RequestBuffer_001
250  * @tc.desc: Test RequestBuffer
251  * @tc.type: Function
252  * @tc.require:
253  */
254 HWTEST_F(ScreenPointerTest, ScreenPointerTest_RequestBuffer_001, TestSize.Level1)
255 {
256     CALL_TEST_DEBUG;
257     hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>();
258     ASSERT_NE(hwcmgr, nullptr);
259     handler_ptr_t handler = nullptr;
260     DisplayInfo di;
261     ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di);
262     ASSERT_NE(screenpointer, nullptr);
263     screenpointer->bufferId_ = 1;
264     EXPECT_NO_FATAL_FAILURE(screenpointer->RequestBuffer());
265     sptr<OHOS::SurfaceBuffer> buffer = OHOS::SurfaceBuffer::Create();
266     screenpointer->buffers_.push_back(buffer);
267     EXPECT_NO_FATAL_FAILURE(screenpointer->RequestBuffer());
268 }
269 
270 /**
271  * @tc.name: ScreenPointerTest_UpdatePadding_001
272  * @tc.desc: Test UpdatePadding
273  * @tc.type: Function
274  * @tc.require:
275  */
276 HWTEST_F(ScreenPointerTest, ScreenPointerTest_UpdatePadding_001, TestSize.Level1)
277 {
278     CALL_TEST_DEBUG;
279     hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>();
280     ASSERT_NE(hwcmgr, nullptr);
281     handler_ptr_t handler = nullptr;
282     DisplayInfo di;
283     ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di);
284     ASSERT_NE(screenpointer, nullptr);
285     screenpointer->mode_ = mode_t::SCREEN_MAIN;
286     uint32_t mainWidth = 0;
287     uint32_t mainHeight = 0;
288     bool ret = screenpointer->UpdatePadding(mainWidth, mainHeight);
289     EXPECT_FALSE(ret);
290     screenpointer->mode_ = mode_t::SCREEN_MIRROR;
291     mainWidth = 0;
292     mainHeight = 0;
293     ret = screenpointer->UpdatePadding(mainWidth, mainHeight);
294     EXPECT_FALSE(ret);
295     mainWidth = 0;
296     mainHeight = 5;
297     ret = screenpointer->UpdatePadding(mainWidth, mainHeight);
298     EXPECT_FALSE(ret);
299     mainWidth = 5;
300     mainHeight = 0;
301     ret = screenpointer->UpdatePadding(mainWidth, mainHeight);
302     EXPECT_FALSE(ret);
303     mainWidth = 5;
304     mainHeight = 5;
305     screenpointer->rotation_ = rotation_t::ROTATION_90;
306     ret = screenpointer->UpdatePadding(mainWidth, mainHeight);
307     EXPECT_TRUE(ret);
308     screenpointer->rotation_ = rotation_t::ROTATION_180;
309     ret = screenpointer->UpdatePadding(mainWidth, mainHeight);
310     EXPECT_TRUE(ret);
311     screenpointer->rotation_ = rotation_t::ROTATION_270;
312     ret = screenpointer->UpdatePadding(mainWidth, mainHeight);
313     EXPECT_TRUE(ret);
314 }
315 
316 /**
317  * @tc.name: ScreenPointerTest_OnDisplayInfo_001
318  * @tc.desc: Test OnDisplayInfo
319  * @tc.type: Function
320  * @tc.require:
321  */
322 HWTEST_F(ScreenPointerTest, ScreenPointerTest_OnDisplayInfo_001, TestSize.Level1)
323 {
324     CALL_TEST_DEBUG;
325     hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>();
326     ASSERT_NE(hwcmgr, nullptr);
327     handler_ptr_t handler = nullptr;
328     DisplayInfo di;
329     di.id = 1;
330     ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di);
331     ASSERT_NE(screenpointer, nullptr);
332     screenpointer->bufferId_ = 5;
333     EXPECT_NO_FATAL_FAILURE(screenpointer->OnDisplayInfo(di));
334     screenpointer->bufferId_ = 1;
335     screenpointer->isCurrentOffScreenRendering_ = true;
336     EXPECT_NO_FATAL_FAILURE(screenpointer->OnDisplayInfo(di));
337     screenpointer->isCurrentOffScreenRendering_ = false;
338     EXPECT_NO_FATAL_FAILURE(screenpointer->OnDisplayInfo(di));
339 }
340 
341 /**
342  * @tc.name: ScreenPointerTest_ScreenPointer_001
343  * @tc.desc: Test ScreenPointer
344  * @tc.type: Function
345  * @tc.require:
346  */
347 HWTEST_F(ScreenPointerTest, ScreenPointerTest_ScreenPointer_001, TestSize.Level1)
348 {
349     CALL_TEST_DEBUG;
350     hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>();
351     ASSERT_NE(hwcmgr, nullptr);
352     handler_ptr_t handler = nullptr;
353     DisplayInfo di;
354     di.id = 1;
355     ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di);
356     screenpointer->rotation_ = rotation_t::ROTATION_90;
357     ScreenPointer(hwcmgr, handler, di);
358     screenpointer->rotation_ = rotation_t::ROTATION_180;
359     ScreenPointer(hwcmgr, handler, di);
360     screenpointer->rotation_ = rotation_t::ROTATION_270;
361     ScreenPointer(hwcmgr, handler, di);
362 }
363 } // namespace MMI
364 } // namespace OHOS