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 <cstdio>
17 #include <fstream>
18
19 #include <gtest/gtest.h>
20
21 #include "event_log_helper.h"
22 #include "image_source.h"
23 #include "input_device_manager.h"
24 #include "input_windows_manager_mock.h"
25 #include "i_preference_manager.h"
26 #include "knuckle_drawing_manager.h"
27 #include "libinput_mock.h"
28 #include "mmi_log.h"
29 #include "parameters.h"
30 #include "pixel_map.h"
31 #include "pointer_drawing_manager.h"
32 #include "pointer_event.h"
33 #include "pointer_style.h"
34
35 #undef MMI_LOG_TAG
36 #define MMI_LOG_TAG "PointerDrawingManagerExTest"
37
38 namespace OHOS {
39 namespace MMI {
40 namespace {
41 using namespace testing;
42 using namespace testing::ext;
43 constexpr int32_t MOUSE_ICON_SIZE = 64;
44 constexpr uint32_t DEFAULT_ICON_COLOR { 0xFF };
45 constexpr int32_t MIDDLE_PIXEL_MAP_WIDTH { 400 };
46 constexpr int32_t MIDDLE_PIXEL_MAP_HEIGHT { 400 };
47 constexpr int32_t MAX_PIXEL_MAP_WIDTH { 600 };
48 constexpr int32_t MAX_PIXEL_MAP_HEIGHT { 600 };
49 constexpr int32_t INT32_BYTE { 4 };
50 constexpr int32_t WINDOW_ROTATE { 0 };
51 constexpr int32_t FOLDABLE_DEVICE { 2 };
52 const std::string POINTER_COLOR { "pointerColor" };
53 const std::string POINTER_SIZE { "pointerSize" };
54 constexpr uint32_t RGB_CHANNEL_BITS_LENGTH { 24 };
55 constexpr float MAX_ALPHA_VALUE { 255.f };
56 const std::string MOUSE_FILE_NAME { "mouse_settings.xml" };
57 const int32_t ROTATE_POLICY = system::GetIntParameter("const.window.device.rotate_policy", 0);
58 } // namespace
59
60 class PointerDrawingManagerExTest : public testing::Test {
61 public:
SetUpTestCase(void)62 static void SetUpTestCase(void) {};
TearDownTestCase(void)63 static void TearDownTestCase(void) {};
64 static std::shared_ptr<Media::PixelMap> CreatePixelMap(int32_t width, int32_t height);
SetUp(void)65 void SetUp(void) {}
TearDown(void)66 void TearDown(void) {}
67
68 std::unique_ptr<OHOS::Media::PixelMap> SetMouseIconTest(const std::string iconPath);
69 };
70
SetMouseIconTest(const std::string iconPath)71 std::unique_ptr<OHOS::Media::PixelMap> PointerDrawingManagerExTest::SetMouseIconTest(const std::string iconPath)
72 {
73 CALL_DEBUG_ENTER;
74 OHOS::Media::SourceOptions opts;
75 opts.formatHint = "image/svg+xml";
76 uint32_t ret = 0;
77 auto imageSource = OHOS::Media::ImageSource::CreateImageSource(iconPath, opts, ret);
78 CHKPP(imageSource);
79 std::set<std::string> formats;
80 ret = imageSource->GetSupportedFormats(formats);
81 MMI_HILOGD("Get supported format ret:%{public}u", ret);
82
83 OHOS::Media::DecodeOptions decodeOpts;
84 decodeOpts.desiredSize = {.width = MOUSE_ICON_SIZE, .height = MOUSE_ICON_SIZE};
85
86 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, ret);
87 CHKPL(pixelMap);
88 return pixelMap;
89 }
90
CreatePixelMap(int32_t width,int32_t height)91 std::shared_ptr<Media::PixelMap> PointerDrawingManagerExTest::CreatePixelMap(int32_t width, int32_t height)
92 {
93 CALL_DEBUG_ENTER;
94 if (width <= 0 || width > MAX_PIXEL_MAP_WIDTH || height <= 0 || height > MAX_PIXEL_MAP_HEIGHT) {
95 return nullptr;
96 }
97 Media::InitializationOptions opts;
98 opts.size.height = height;
99 opts.size.width = width;
100 opts.pixelFormat = Media::PixelFormat::BGRA_8888;
101 opts.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
102 opts.scaleMode = Media::ScaleMode::FIT_TARGET_SIZE;
103
104 int32_t colorLen = width * height;
105 uint32_t *pixelColors = new (std::nothrow) uint32_t[colorLen];
106 CHKPP(pixelColors);
107 int32_t colorByteCount = colorLen * INT32_BYTE;
108 errno_t ret = memset_s(pixelColors, colorByteCount, DEFAULT_ICON_COLOR, colorByteCount);
109 if (ret != EOK) {
110 delete[] pixelColors;
111 return nullptr;
112 }
113 std::shared_ptr<Media::PixelMap> pixelMap = Media::PixelMap::Create(pixelColors, colorLen, opts);
114 if (pixelMap == nullptr) {
115 delete[] pixelColors;
116 return nullptr;
117 }
118 delete[] pixelColors;
119 return pixelMap;
120 }
121
122 /**
123 * @tc.name: InputWindowsManagerTest_SwitchPointerStyle_01
124 * @tc.desc: Test SwitchPointerStyle
125 * @tc.type: FUNC
126 * @tc.require:
127 */
128 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_SwitchPointerStyle_01, TestSize.Level1)
129 {
130 CALL_TEST_DEBUG;
131 PointerDrawingManager pointerDrawingManager;
132 int32_t size = pointerDrawingManager.GetPointerSize();
133 size = -1;
134 int32_t ret = pointerDrawingManager.SwitchPointerStyle();
135 EXPECT_EQ(ret, RET_ERR);
136 size = 8;
137 int32_t ret2 = pointerDrawingManager.SwitchPointerStyle();
138 EXPECT_EQ(ret2, RET_ERR);
139
140 size = 5;
141 EXPECT_FALSE(pointerDrawingManager.HasMagicCursor());
142 int32_t ret3 = pointerDrawingManager.SwitchPointerStyle();
143 EXPECT_EQ(ret3, RET_ERR);
144 }
145
146 /**
147 * @tc.name: InputWindowsManagerTest_UpdateMouseStyle_01
148 * @tc.desc: Test UpdateMouseStyle
149 * @tc.type: FUNC
150 * @tc.require:
151 */
152 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_UpdateMouseStyle_01, TestSize.Level1)
153 {
154 CALL_TEST_DEBUG;
155 PointerDrawingManager pointerDrawingManager;
156 PointerStyle curPointerStyle;
157 curPointerStyle.id = 41;
158 pointerDrawingManager.pid_ = 2;
159 int ret = pointerDrawingManager.SetPointerStyle(pointerDrawingManager.pid_, GLOBAL_WINDOW_ID, curPointerStyle);
160 EXPECT_EQ(ret, RET_OK);
161 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.UpdateMouseStyle());
162
163 curPointerStyle.id = 10;
164 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.UpdateMouseStyle());
165 }
166
167 /**
168 * @tc.name: InputWindowsManagerTest_DrawMovePointer_01
169 * @tc.desc: Test DrawMovePointer
170 * @tc.type: FUNC
171 * @tc.require:
172 */
173 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_DrawMovePointer_01, TestSize.Level1)
174 {
175 CALL_TEST_DEBUG;
176 uint64_t displayId = 1;
177 int32_t physicalX = 100;
178 int32_t physicalY = 150;
179 PointerDrawingManager pointerDrawingManager;
180 Rosen::RSSurfaceNodeConfig surfaceNodeConfig;
181 surfaceNodeConfig.SurfaceNodeName = "pointer window";
182 Rosen::RSSurfaceNodeType surfaceNodeType = Rosen::RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE;
183 pointerDrawingManager.surfaceNode_ = Rosen::RSSurfaceNode::Create(surfaceNodeConfig, surfaceNodeType);
184 ASSERT_TRUE(pointerDrawingManager.surfaceNode_ != nullptr);
185 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.DrawMovePointer(displayId, physicalX, physicalY));
186 }
187
188 /**
189 * @tc.name: InputWindowsManagerTest_DrawMovePointer_02
190 * @tc.desc: Test DestroyPointerWindow
191 * @tc.type: FUNC
192 * @tc.require:
193 */
194 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_DrawMovePointer_02, TestSize.Level1)
195 {
196 CALL_TEST_DEBUG;
197 uint64_t displayId = 2;
198 int32_t physicalX = 60;
199 int32_t physicalY = 80;
200 PointerDrawingManager pointerDrawingManager;
201 ASSERT_TRUE(pointerDrawingManager.surfaceNode_ == nullptr);
202 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.DrawMovePointer(displayId, physicalX, physicalY));
203 }
204
205 /**
206 * @tc.name: InputWindowsManagerTest_DrawMovePointer_04
207 * @tc.desc: Test DestroyPointerWindow
208 * @tc.type: FUNC
209 * @tc.require:
210 */
211 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_DrawMovePointer_04, TestSize.Level1)
212 {
213 CALL_TEST_DEBUG;
214 uint64_t displayId = 2;
215 int32_t physicalX = 60;
216 int32_t physicalY = 80;
217 PointerStyle pointerStyle;
218 pointerStyle.id = 1;
219 pointerStyle.color = 0;
220
221 Direction direction;
222 direction = DIRECTION90;
223 PointerDrawingManager pointerDrawingManager;
224 ASSERT_TRUE(pointerDrawingManager.surfaceNode_ == nullptr);
225 int32_t ret = pointerDrawingManager.DrawMovePointer(displayId, physicalX, physicalY, pointerStyle, direction);
226 EXPECT_EQ(ret, RET_ERR);
227 }
228
229 /**
230 * @tc.name: InputWindowsManagerTest_DestroyPointerWindow_01
231 * @tc.desc: Test DestroyPointerWindow
232 * @tc.type: FUNC
233 * @tc.require:
234 */
235 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_DestroyPointerWindow_01, TestSize.Level1)
236 {
237 CALL_TEST_DEBUG;
238 PointerDrawingManager pointerDrawingManager;
239 Rosen::RSSurfaceNodeConfig surfaceNodeConfig;
240 surfaceNodeConfig.SurfaceNodeName = "pointer window";
241 Rosen::RSSurfaceNodeType surfaceNodeType = Rosen::RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE;
242 pointerDrawingManager.surfaceNode_ = Rosen::RSSurfaceNode::Create(surfaceNodeConfig, surfaceNodeType);
243 ASSERT_TRUE(pointerDrawingManager.surfaceNode_ != nullptr);
244 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.DestroyPointerWindow());
245 }
246
247 /**
248 * @tc.name: InputWindowsManagerTest_DestroyPointerWindow_02
249 * @tc.desc: Test DestroyPointerWindow
250 * @tc.type: FUNC
251 * @tc.require:
252 */
253 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_DestroyPointerWindow_02, TestSize.Level1)
254 {
255 CALL_TEST_DEBUG;
256 PointerDrawingManager pointerDrawingManager;
257 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.DestroyPointerWindow());
258 }
259
260 /**
261 * @tc.name: InputWindowsManagerTest_SetPointerStyle_001
262 * @tc.desc: Test SetPointerStyle
263 * @tc.type: FUNC
264 * @tc.require:
265 */
266 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_SetPointerStyle_001, TestSize.Level1)
267 {
268 CALL_TEST_DEBUG;
269 PointerDrawingManager pointerDrawingManager;
270 bool isUiExtension = true;
271 PointerStyle pointerStyle;
272 pointerStyle.id = 1;
273 pointerStyle.color = 0;
274 pointerStyle.size = 2;
275
276 int32_t pid = 1;
277 int32_t windowId = 2;
278 bool ret1 = pointerDrawingManager.CheckPointerStyleParam(windowId, pointerStyle);
279 EXPECT_TRUE(ret1);
280 int32_t ret2 = pointerDrawingManager.UpdateDefaultPointerStyle(pid, windowId, pointerStyle);
281 EXPECT_EQ(ret2, RET_OK);
282 int32_t ret3 = WIN_MGR->SetPointerStyle(pid, windowId, pointerStyle, isUiExtension);
283 EXPECT_EQ(ret3, RET_OK);
284
285 EXPECT_FALSE(INPUT_DEV_MGR->HasPointerDevice());
286 EXPECT_FALSE(WIN_MGR->IsMouseSimulate());
287 EXPECT_FALSE(WIN_MGR->IsNeedRefreshLayer(windowId));
288 int32_t ret4 = pointerDrawingManager.SetPointerStyle(pid, windowId, pointerStyle, isUiExtension);
289 EXPECT_EQ(ret4, RET_OK);
290 }
291
292 /**
293 * @tc.name: InputWindowsManagerTest_SetPointerLocation_01
294 * @tc.desc: Test SetPointerLocation
295 * @tc.type: FUNC
296 * @tc.require:
297 */
298 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_SetPointerLocation_01, TestSize.Level1)
299 {
300 CALL_TEST_DEBUG;
301 PointerDrawingManager pointerDrawingManager;
302 int32_t x = 100;
303 int32_t y = 100;
304 pointerDrawingManager.surfaceNode_ = nullptr;
305 uint64_t displayId = 0;
306 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.SetPointerLocation(x, y, displayId));
307 }
308
309 /**
310 * @tc.name: InputWindowsManagerTest_SetPointerLocation_02
311 * @tc.desc: Test SetPointerLocation
312 * @tc.type: FUNC
313 * @tc.require:
314 */
315 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_SetPointerLocation_02, TestSize.Level1)
316 {
317 CALL_TEST_DEBUG;
318 PointerDrawingManager pointerDrawingManager;
319 int32_t x = 100;
320 int32_t y = 100;
321 Rosen::RSSurfaceNodeConfig surfaceNodeConfig;
322 surfaceNodeConfig.SurfaceNodeName = "pointer window";
323 Rosen::RSSurfaceNodeType surfaceNodeType = Rosen::RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE;
324 pointerDrawingManager.surfaceNode_ = Rosen::RSSurfaceNode::Create(surfaceNodeConfig, surfaceNodeType);
325 ASSERT_TRUE(pointerDrawingManager.surfaceNode_ != nullptr);
326 uint64_t displayId = 0;
327 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.SetPointerLocation(x, y, displayId));
328 }
329
330 /**
331 * @tc.name: InputWindowsManagerTest_UpdateDefaultPointerStyle_01
332 * @tc.desc: Test UpdateDefaultPointerStyle
333 * @tc.type: FUNC
334 * @tc.require:
335 */
336 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_UpdateDefaultPointerStyle_01, TestSize.Level1)
337 {
338 CALL_TEST_DEBUG;
339 PointerDrawingManager pointerDrawingManager;
340 int32_t pid = 1;
341 int32_t windowId = 2;
342 EXPECT_TRUE(windowId != GLOBAL_WINDOW_ID);
343 PointerStyle pointerStyle;
344 bool isUiExtension = true;
345 pointerStyle.id = 1;
346 int32_t ret1 = pointerDrawingManager.UpdateDefaultPointerStyle(pid, windowId, pointerStyle, isUiExtension);
347 EXPECT_EQ(ret1, RET_OK);
348
349 PointerStyle style;
350 windowId = -1;
351 EXPECT_FALSE(windowId != GLOBAL_WINDOW_ID);
352 pointerStyle.id = 2;
353 style.id = 3;
354 EXPECT_TRUE(pointerStyle.id != style.id);
355 int32_t ret2 = pointerDrawingManager.UpdateDefaultPointerStyle(pid, windowId, pointerStyle, isUiExtension);
356 EXPECT_EQ(ret2, RET_OK);
357
358 pointerStyle.id = MOUSE_ICON::DEFAULT;
359 int32_t ret3 = pointerDrawingManager.UpdateDefaultPointerStyle(pid, windowId, pointerStyle, isUiExtension);
360 EXPECT_EQ(ret3, RET_OK);
361
362 pointerStyle.id = 3;
363 EXPECT_TRUE(pointerStyle.id == style.id);
364 int32_t ret4 = pointerDrawingManager.UpdateDefaultPointerStyle(pid, windowId, pointerStyle, isUiExtension);
365 EXPECT_EQ(ret4, RET_OK);
366 }
367
368 /**
369 * @tc.name: InputWindowsManagerTest_UpdateIconPath_01
370 * @tc.desc: Test UpdateIconPath
371 * @tc.type: FUNC
372 * @tc.require:
373 */
374 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_UpdateIconPath_01, TestSize.Level1)
375 {
376 CALL_TEST_DEBUG;
377 PointerDrawingManager pointerDrawingManager;
378 pointerDrawingManager.mouseIcons_[DEFAULT] = {0, "/system/etc/multimodalinput/mouse_icon/default_icon.svg"};
379 pointerDrawingManager.mouseIcons_[EAST] = {1, "/system/etc/multimodalinput/mouse_icon/east_icon.png"};
380 pointerDrawingManager.mouseIcons_[WEST] = {2, "/system/etc/multimodalinput/mouse_icon/west_icon.png"};
381 pointerDrawingManager.mouseIcons_[SOUTH] = {3, "/system/etc/multimodalinput/mouse_icon/south_icon.png"};
382 pointerDrawingManager.mouseIcons_[NORTH] = {4, "/system/etc/multimodalinput/mouse_icon/north_icon.png"};
383
384 MOUSE_ICON mouseStyle = EAST;
385 std::string iconPath = ("/system/etc/multimodalinput/mouse_icon/Loading_Left.svg");
386 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.UpdateIconPath(mouseStyle, iconPath));
387 }
388
389 /**
390 * @tc.name: InputWindowsManagerTest_UpdateIconPath_02
391 * @tc.desc: Test UpdateIconPath
392 * @tc.type: FUNC
393 * @tc.require:
394 */
395 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_UpdateIconPath_02, TestSize.Level1)
396 {
397 CALL_TEST_DEBUG;
398 PointerDrawingManager pointerDrawingManager;
399 pointerDrawingManager.mouseIcons_[DEFAULT] = {0, "/system/etc/multimodalinput/mouse_icon/default_icon.svg"};
400 pointerDrawingManager.mouseIcons_[EAST] = {1, "/system/etc/multimodalinput/mouse_icon/east_icon.png"};
401 pointerDrawingManager.mouseIcons_[WEST] = {2, "/system/etc/multimodalinput/mouse_icon/west_icon.png"};
402 pointerDrawingManager.mouseIcons_[SOUTH] = {3, "/system/etc/multimodalinput/mouse_icon/south_icon.png"};
403 pointerDrawingManager.mouseIcons_[NORTH] = {4, "/system/etc/multimodalinput/mouse_icon/north_icon.png"};
404
405 MOUSE_ICON mouseStyle = WEST_EAST;
406 std::string iconPath = ("/system/etc/multimodalinput/mouse_icon/Loading_Left.svg");
407 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.UpdateIconPath(mouseStyle, iconPath));
408 }
409
410 /**
411 * @tc.name: InputWindowsManagerTest_CheckPointerStyleParam_01
412 * @tc.desc: Test CheckPointerStyleParam
413 * @tc.type: FUNC
414 * @tc.require:
415 */
416 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_CheckPointerStyleParam_01, TestSize.Level1)
417 {
418 CALL_TEST_DEBUG;
419 PointerDrawingManager pointerDrawingManager;
420 int32_t windowId = 2;
421 PointerStyle pointerStyle;
422 pointerStyle.id = -2;
423 bool ret1 = pointerDrawingManager.CheckPointerStyleParam(windowId, pointerStyle);
424 EXPECT_FALSE(ret1);
425
426 pointerStyle.id = 46;
427 bool ret2 = pointerDrawingManager.CheckPointerStyleParam(windowId, pointerStyle);
428 EXPECT_TRUE(ret2);
429
430 windowId = -3;
431 bool ret3 = pointerDrawingManager.CheckPointerStyleParam(windowId, pointerStyle);
432 EXPECT_FALSE(ret3);
433 }
434
435 /**
436 * @tc.name: InputWindowsManagerTest_UpdateStyleOptions_01
437 * @tc.desc: Test UpdateStyleOptions
438 * @tc.type: FUNC
439 * @tc.require:
440 */
441 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_UpdateStyleOptions_01, TestSize.Level1)
442 {
443 CALL_TEST_DEBUG;
444 PointerDrawingManager pointerDrawMgr;
445 pointerDrawMgr.pid_ = 3;
446 PointerStyle curPointerStyle;
447 curPointerStyle.options = 1;
448 int ret = WIN_MGR->SetPointerStyle(pointerDrawMgr.pid_, GLOBAL_WINDOW_ID, curPointerStyle);
449 EXPECT_EQ(ret, RET_OK);
450 ASSERT_NO_FATAL_FAILURE(pointerDrawMgr.UpdateStyleOptions());
451 }
452
453 /**
454 * @tc.name: InputWindowsManagerTest_AdjustMouseFocus_01
455 * @tc.desc: Test AdjustMouseFocus
456 * @tc.type: FUNC
457 * @tc.require:
458 */
459 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_AdjustMouseFocus_01, TestSize.Level1)
460 {
461 CALL_TEST_DEBUG;
462 PointerDrawingManager pointerDrawMgr;
463 Direction direction;
464 ICON_TYPE iconType = ANGLE_SW;
465 int32_t physicalX = 50;
466 int32_t physicalY = 60;
467
468 direction = DIRECTION0;
469 ASSERT_NO_FATAL_FAILURE(pointerDrawMgr.AdjustMouseFocus(direction, iconType, physicalX, physicalY));
470 direction = DIRECTION90;
471 ASSERT_NO_FATAL_FAILURE(pointerDrawMgr.AdjustMouseFocus(direction, iconType, physicalX, physicalY));
472 direction = DIRECTION180;
473 ASSERT_NO_FATAL_FAILURE(pointerDrawMgr.AdjustMouseFocus(direction, iconType, physicalX, physicalY));
474 direction = DIRECTION270;
475 ASSERT_NO_FATAL_FAILURE(pointerDrawMgr.AdjustMouseFocus(direction, iconType, physicalX, physicalY));
476 }
477
478 /**
479 * @tc.name: PointerDrawingManagerExTest_ConvertToColorSpace
480 * @tc.desc: Test ConvertToColorSpace
481 * @tc.type: FUNC
482 * @tc.require:
483 */
484 HWTEST_F(PointerDrawingManagerExTest, PointerDrawingManagerExTest_ConvertToColorSpace, TestSize.Level1)
485 {
486 CALL_TEST_DEBUG;
487 PointerDrawingManager pointerDrawingManager;
488 Media::ColorSpace colorSpace = Media::ColorSpace::DISPLAY_P3;
489 EXPECT_NE(pointerDrawingManager.ConvertToColorSpace(colorSpace), nullptr);
490 colorSpace = Media::ColorSpace::LINEAR_SRGB;
491 EXPECT_NE(pointerDrawingManager.ConvertToColorSpace(colorSpace), nullptr);
492 colorSpace = Media::ColorSpace::SRGB;
493 EXPECT_NE(pointerDrawingManager.ConvertToColorSpace(colorSpace), nullptr);
494 colorSpace = static_cast<Media::ColorSpace>(5);
495 EXPECT_NE(pointerDrawingManager.ConvertToColorSpace(colorSpace), nullptr);
496 }
497
498 /**
499 * @tc.name: PointerDrawingManagerExTest_PixelFormatToColorType
500 * @tc.desc: Test PixelFormatToColorType
501 * @tc.type: FUNC
502 * @tc.require:
503 */
504 HWTEST_F(PointerDrawingManagerExTest, PointerDrawingManagerExTest_PixelFormatToColorType, TestSize.Level1)
505 {
506 CALL_TEST_DEBUG;
507 PointerDrawingManager pointerDrawingManager;
508 Media::PixelFormat pixelFmt = Media::PixelFormat::RGB_565;
509 EXPECT_EQ(pointerDrawingManager.PixelFormatToColorType(pixelFmt), Rosen::Drawing::ColorType::COLORTYPE_RGB_565);
510 pixelFmt = Media::PixelFormat::RGBA_8888;
511 EXPECT_EQ(pointerDrawingManager.PixelFormatToColorType(pixelFmt), Rosen::Drawing::ColorType::COLORTYPE_RGBA_8888);
512 pixelFmt = Media::PixelFormat::BGRA_8888;
513 EXPECT_EQ(pointerDrawingManager.PixelFormatToColorType(pixelFmt), Rosen::Drawing::ColorType::COLORTYPE_BGRA_8888);
514 pixelFmt = Media::PixelFormat::ALPHA_8;
515 EXPECT_EQ(pointerDrawingManager.PixelFormatToColorType(pixelFmt), Rosen::Drawing::ColorType::COLORTYPE_ALPHA_8);
516 pixelFmt = Media::PixelFormat::RGBA_F16;
517 EXPECT_EQ(pointerDrawingManager.PixelFormatToColorType(pixelFmt), Rosen::Drawing::ColorType::COLORTYPE_RGBA_F16);
518 pixelFmt = Media::PixelFormat::UNKNOWN;
519 EXPECT_EQ(pointerDrawingManager.PixelFormatToColorType(pixelFmt), Rosen::Drawing::ColorType::COLORTYPE_UNKNOWN);
520 pixelFmt = Media::PixelFormat::ARGB_8888;
521 EXPECT_EQ(pointerDrawingManager.PixelFormatToColorType(pixelFmt), Rosen::Drawing::ColorType::COLORTYPE_UNKNOWN);
522 pixelFmt = Media::PixelFormat::RGB_888;
523 EXPECT_EQ(pointerDrawingManager.PixelFormatToColorType(pixelFmt), Rosen::Drawing::ColorType::COLORTYPE_UNKNOWN);
524 pixelFmt = Media::PixelFormat::NV21;
525 EXPECT_EQ(pointerDrawingManager.PixelFormatToColorType(pixelFmt), Rosen::Drawing::ColorType::COLORTYPE_UNKNOWN);
526 pixelFmt = Media::PixelFormat::NV12;
527 EXPECT_EQ(pointerDrawingManager.PixelFormatToColorType(pixelFmt), Rosen::Drawing::ColorType::COLORTYPE_UNKNOWN);
528 pixelFmt = Media::PixelFormat::CMYK;
529 EXPECT_EQ(pointerDrawingManager.PixelFormatToColorType(pixelFmt), Rosen::Drawing::ColorType::COLORTYPE_UNKNOWN);
530 pixelFmt = static_cast<Media::PixelFormat>(100);
531 EXPECT_EQ(pointerDrawingManager.PixelFormatToColorType(pixelFmt), Rosen::Drawing::ColorType::COLORTYPE_UNKNOWN);
532 }
533
534 /**
535 * @tc.name: PointerDrawingManagerExTest__AlphaTypeToAlphaType
536 * @tc.desc: Test AlphaTypeToAlphaType
537 * @tc.type: Function
538 * @tc.require:
539 */
540 HWTEST_F(PointerDrawingManagerExTest, PointerDrawingManagerExTest_AlphaTypeToAlphaType, TestSize.Level1)
541 {
542 CALL_TEST_DEBUG;
543 PointerDrawingManager pointerDrawingManager;
544 Media::AlphaType alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN;
545 EXPECT_EQ(pointerDrawingManager.AlphaTypeToAlphaType(alphaType), Rosen::Drawing::AlphaType::ALPHATYPE_UNKNOWN);
546 alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
547 EXPECT_EQ(pointerDrawingManager.AlphaTypeToAlphaType(alphaType), Rosen::Drawing::AlphaType::ALPHATYPE_OPAQUE);
548 alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_PREMUL;
549 EXPECT_EQ(pointerDrawingManager.AlphaTypeToAlphaType(alphaType), Rosen::Drawing::AlphaType::ALPHATYPE_PREMUL);
550 alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_UNPREMUL;
551 EXPECT_EQ(pointerDrawingManager.AlphaTypeToAlphaType(alphaType), Rosen::Drawing::AlphaType::ALPHATYPE_UNPREMUL);
552 alphaType = static_cast<Media::AlphaType>(5);
553 EXPECT_EQ(pointerDrawingManager.AlphaTypeToAlphaType(alphaType), Rosen::Drawing::AlphaType::ALPHATYPE_UNKNOWN);
554 }
555
556 /**
557 * @tc.name: InputWindowsManagerTest_DrawPointerStyle_01
558 * @tc.desc: Test DrawPointerStyle
559 * @tc.type: FUNC
560 * @tc.require:
561 */
562 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_DrawPointerStyle_01, TestSize.Level1)
563 {
564 CALL_TEST_DEBUG;
565 PointerDrawingManager pointerDrawingManager;
566 pointerDrawingManager.hasDisplay_ = true;
567 pointerDrawingManager.hasPointerDevice_ = true;
568 pointerDrawingManager.surfaceNode_ = nullptr;
569
570 PointerStyle pointerStyle;
571 pointerStyle.id = 1;
572 pointerStyle.color = 1;
573 pointerStyle.size = 2;
574
575 int32_t ROTATE_POLICY;
576 ROTATE_POLICY = WINDOW_ROTATE;
577 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.DrawPointerStyle(pointerStyle));
578 }
579
580 /**
581 * @tc.name: InputWindowsManagerTest_DrawPointerStyle_02
582 * @tc.desc: Test DrawPointerStyle
583 * @tc.type: FUNC
584 * @tc.require:
585 */
586 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_DrawPointerStyle_02, TestSize.Level1)
587 {
588 CALL_TEST_DEBUG;
589 PointerDrawingManager pointerDrawingManager;
590 pointerDrawingManager.hasDisplay_ = true;
591 pointerDrawingManager.hasPointerDevice_ = true;
592 pointerDrawingManager.surfaceNode_ = nullptr;
593
594 PointerStyle pointerStyle;
595 pointerStyle.id = 1;
596 pointerStyle.color = 1;
597 pointerStyle.size = 2;
598
599 int32_t ROTATE_POLICY;
600 ROTATE_POLICY = FOLDABLE_DEVICE;
601 pointerDrawingManager.lastPhysicalX_ = -1;
602 pointerDrawingManager.lastPhysicalY_ = -1;
603 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.DrawPointerStyle(pointerStyle));
604 }
605
606 /**
607 * @tc.name: InputWindowsManagerTest_DrawPointerStyle_03
608 * @tc.desc: Test DrawPointerStyle
609 * @tc.type: FUNC
610 * @tc.require:
611 */
612 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_DrawPointerStyle_03, TestSize.Level1)
613 {
614 CALL_TEST_DEBUG;
615 PointerDrawingManager pointerDrawingManager;
616 pointerDrawingManager.hasDisplay_ = true;
617 pointerDrawingManager.hasPointerDevice_ = true;
618 pointerDrawingManager.surfaceNode_ = nullptr;
619
620 PointerStyle pointerStyle;
621 pointerStyle.id = 1;
622 pointerStyle.color = 1;
623 pointerStyle.size = 2;
624
625 int32_t ROTATE_POLICY;
626 ROTATE_POLICY = FOLDABLE_DEVICE;
627 pointerDrawingManager.lastPhysicalX_ = 1;
628 pointerDrawingManager.lastPhysicalY_ = -1;
629 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.DrawPointerStyle(pointerStyle));
630 }
631
632 /**
633 * @tc.name: InputWindowsManagerTest_DrawPointerStyle_04
634 * @tc.desc: Test DrawPointerStyle
635 * @tc.type: FUNC
636 * @tc.require:
637 */
638 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_DrawPointerStyle_04, TestSize.Level1)
639 {
640 CALL_TEST_DEBUG;
641 PointerDrawingManager pointerDrawingManager;
642 pointerDrawingManager.hasDisplay_ = true;
643 pointerDrawingManager.hasPointerDevice_ = true;
644 pointerDrawingManager.surfaceNode_ = nullptr;
645
646 PointerStyle pointerStyle;
647 pointerStyle.id = 1;
648 pointerStyle.color = 1;
649 pointerStyle.size = 2;
650
651 int32_t ROTATE_POLICY;
652 ROTATE_POLICY = FOLDABLE_DEVICE;
653 pointerDrawingManager.lastPhysicalX_ = 2;
654 pointerDrawingManager.lastPhysicalY_ = 2;
655 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.DrawPointerStyle(pointerStyle));
656 }
657
658 /**
659 * @tc.name: InputWindowsManagerTest_SetPointerStyle_01
660 * @tc.desc: Test SetPointerStyle
661 * @tc.type: FUNC
662 * @tc.require:
663 */
664 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_SetPointerStyle_01, TestSize.Level1)
665 {
666 CALL_TEST_DEBUG;
667 PointerDrawingManager pointerDrawingManager;
668 bool isUiExtension = false;
669
670 PointerStyle pointerStyle;
671 pointerStyle.id = 1;
672 pointerStyle.color = 0;
673 pointerStyle.size = 2;
674
675 int32_t pid = 1;
676 int32_t windowId = -2;
677 bool ret = pointerDrawingManager.CheckPointerStyleParam(windowId, pointerStyle);
678 EXPECT_FALSE(ret);
679
680 int32_t ret2 = pointerDrawingManager.SetPointerStyle(pid, windowId, pointerStyle, isUiExtension);
681 EXPECT_EQ(ret2, RET_ERR);
682 }
683
684 /**
685 * @tc.name: InputWindowsManagerTest_SetPointerStyle_02
686 * @tc.desc: Test SetPointerStyle
687 * @tc.type: FUNC
688 * @tc.require:
689 */
690 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_SetPointerStyle_02, TestSize.Level1)
691 {
692 CALL_TEST_DEBUG;
693 PointerDrawingManager pointerDrawingManager;
694 bool isUiExtension = true;
695
696 PointerStyle pointerStyle;
697 pointerStyle.id = 1;
698 pointerStyle.color = 0;
699 pointerStyle.size = 2;
700
701 int32_t pid = 1;
702 int32_t windowId = GLOBAL_WINDOW_ID;
703 bool ret = pointerDrawingManager.CheckPointerStyleParam(windowId, pointerStyle);
704 EXPECT_TRUE(ret);
705
706 int32_t ret2 = pointerDrawingManager.SetPointerStyle(pid, windowId, pointerStyle, isUiExtension);
707 EXPECT_EQ(ret2, RET_OK);
708 }
709
710 /**
711 * @tc.name: InputWindowsManagerTest_SetPointerStylePreference_01
712 * @tc.desc: Test SetPointerStylePreference
713 * @tc.type: FUNC
714 * @tc.require:
715 */
716 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_SetPointerStylePreference_01, TestSize.Level1)
717 {
718 CALL_TEST_DEBUG;
719 PointerDrawingManager pointerDrawingManager;
720 PointerStyle pointerStyle;
721 pointerStyle.id = 1;
722 pointerStyle.color = 1;
723 pointerStyle.size = 2;
724
725 std::string name = "pointerStyle";
726 int32_t ret = PREFERENCES_MGR->SetIntValue(name, MOUSE_FILE_NAME, pointerStyle.id);
727 EXPECT_EQ(ret, RET_OK);
728
729 int32_t ret2 = pointerDrawingManager.SetPointerStylePreference(pointerStyle);
730 EXPECT_EQ(ret2, RET_OK);
731 }
732
733 /**
734 * @tc.name: InputWindowsManagerTest_SetMouseHotSpot_01
735 * @tc.desc: Test SetMouseHotSpot
736 * @tc.type: FUNC
737 * @tc.require:
738 */
739 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_SetMouseHotSpot_01, TestSize.Level1)
740 {
741 CALL_TEST_DEBUG;
742 PointerDrawingManager pointerDrawingManager;
743 int32_t pid = -1;
744 int32_t windowId = 2;
745 int32_t hotSpotX = 3;
746 int32_t hotSpotY = 4;
747 int32_t ret = pointerDrawingManager.SetMouseHotSpot(pid, windowId, hotSpotX, hotSpotY);
748 ASSERT_EQ(ret, RET_ERR);
749 }
750
751 /**
752 * @tc.name: InputWindowsManagerTest_SetMouseHotSpot_02
753 * @tc.desc: Test SetMouseHotSpot
754 * @tc.type: FUNC
755 * @tc.require:
756 */
757 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_SetMouseHotSpot_02, TestSize.Level1)
758 {
759 CALL_TEST_DEBUG;
760 PointerDrawingManager pointerDrawingManager;
761 int32_t pid = 1;
762 int32_t windowId = -2;
763 int32_t hotSpotX = 3;
764 int32_t hotSpotY = 4;
765 int32_t ret = pointerDrawingManager.SetMouseHotSpot(pid, windowId, hotSpotX, hotSpotY);
766 ASSERT_EQ(ret, RET_ERR);
767 }
768
769 /**
770 * @tc.name: InputWindowsManagerTest_SetMouseHotSpot_03
771 * @tc.desc: Test SetMouseHotSpot
772 * @tc.type: FUNC
773 * @tc.require:
774 */
775 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_SetMouseHotSpot_03, TestSize.Level1)
776 {
777 CALL_TEST_DEBUG;
778 PointerDrawingManager pointerDrawingManager;
779 int32_t pid = 1;
780 int32_t windowId = 2;
781 EXPECT_CALL(*WIN_MGR_MOCK, CheckWindowIdPermissionByPid).WillRepeatedly(testing::Return(RET_ERR));
782 int32_t hotSpotX = 3;
783 int32_t hotSpotY = 4;
784 int32_t ret = pointerDrawingManager.SetMouseHotSpot(pid, windowId, hotSpotX, hotSpotY);
785 ASSERT_EQ(ret, RET_ERR);
786 }
787
788 /**
789 * @tc.name: InputWindowsManagerTest_SetMouseHotSpot_04
790 * @tc.desc: Test SetMouseHotSpot
791 * @tc.type: FUNC
792 * @tc.require:
793 */
794 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_SetMouseHotSpot_04, TestSize.Level1)
795 {
796 CALL_TEST_DEBUG;
797 PointerDrawingManager pointerDrawingManager;
798 int32_t pid = 1;
799 int32_t windowId = 2;
800 EXPECT_CALL(*WIN_MGR_MOCK, CheckWindowIdPermissionByPid).WillRepeatedly(testing::Return(RET_OK));
801 int32_t hotSpotX = -3;
802 int32_t hotSpotY = -4;
803 pointerDrawingManager.userIcon_ = nullptr;
804 int32_t ret = pointerDrawingManager.SetMouseHotSpot(pid, windowId, hotSpotX, hotSpotY);
805 ASSERT_EQ(ret, RET_ERR);
806 }
807
808 /**
809 * @tc.name: InputWindowsManagerTest_SetMouseHotSpot_05
810 * @tc.desc: Test SetMouseHotSpot
811 * @tc.type: FUNC
812 * @tc.require:
813 */
814 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_SetMouseHotSpot_05, TestSize.Level1)
815 {
816 CALL_TEST_DEBUG;
817 PointerDrawingManager pointerDrawingManager;
818 int32_t pid = 1;
819 int32_t windowId = 2;
820 auto winmgrmock = std::make_shared<InputWindowsManagerMock>();
821 EXPECT_CALL(*winmgrmock, CheckWindowIdPermissionByPid).WillRepeatedly(testing::Return(RET_OK));
822
823 int32_t hotSpotX = -3;
824 int32_t hotSpotY = -4;
825 int32_t ret = pointerDrawingManager.SetMouseHotSpot(pid, windowId, hotSpotX, hotSpotY);
826 EXPECT_EQ(ret, RET_ERR);
827 }
828
829 /**
830 * @tc.name: InputWindowsManagerTest_SetMouseHotSpot_06
831 * @tc.desc: Test SetMouseHotSpot
832 * @tc.type: FUNC
833 * @tc.require:
834 */
835 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_SetMouseHotSpot_06, TestSize.Level1)
836 {
837 CALL_TEST_DEBUG;
838 PointerDrawingManager pointerDrawingManager;
839 int32_t pid = 1;
840 int32_t windowId = 2;
841 auto winmgrmock = std::make_shared<InputWindowsManagerMock>();
842 EXPECT_CALL(*winmgrmock, CheckWindowIdPermissionByPid).WillRepeatedly(testing::Return(RET_OK));
843 int32_t hotSpotX = 3;
844 int32_t hotSpotY = 4;
845 PointerStyle pointerStyle;
846 pointerStyle.id = 1;
847 pointerStyle.size = 2;
848 EXPECT_TRUE(pointerStyle.id != MOUSE_ICON::DEVELOPER_DEFINED_ICON);
849 int32_t ret = pointerDrawingManager.SetMouseHotSpot(pid, windowId, hotSpotX, hotSpotY);
850 EXPECT_EQ(ret, RET_ERR);
851 }
852
853 /**
854 * @tc.name: InputWindowsManagerTest_SetMouseIcon_01
855 * @tc.desc: Test SetMouseIcon
856 * @tc.type: FUNC
857 * @tc.require:
858 */
859 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_SetMouseIcon_01, TestSize.Level1)
860 {
861 CALL_TEST_DEBUG;
862 PointerDrawingManager pointerDrawingManager;
863 int32_t pid = -1;
864 int32_t windowId = -2;
865 CursorPixelMap curPixelMap;
866 int32_t ret = pointerDrawingManager.SetMouseIcon(pid, windowId, curPixelMap);
867 ASSERT_EQ(ret, RET_ERR);
868 }
869
870 /**
871 * @tc.name: InputWindowsManagerTest_SetMouseIcon_02
872 * @tc.desc: Test SetMouseIcon
873 * @tc.type: FUNC
874 * @tc.require:
875 */
876 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_SetMouseIcon_02, TestSize.Level1)
877 {
878 CALL_TEST_DEBUG;
879 PointerDrawingManager pointerDrawingManager;
880 int32_t pid = 1;
881 int32_t windowId = -2;
882 CursorPixelMap curPixelMap;
883 int32_t ret = pointerDrawingManager.SetMouseIcon(pid, windowId, curPixelMap);
884 ASSERT_EQ(ret, RET_ERR);
885 }
886
887 /**
888 * @tc.name: InputWindowsManagerTest_SetMouseIcon_03
889 * @tc.desc: Test SetMouseIcon
890 * @tc.type: FUNC
891 * @tc.require:
892 */
893 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_SetMouseIcon_03, TestSize.Level1)
894 {
895 CALL_TEST_DEBUG;
896 PointerDrawingManager pointerDrawingManager;
897 int32_t pid = 1;
898 int32_t windowId = 2;
899 PointerStyle style;
900 int32_t ret1 = pointerDrawingManager.SetPointerStyle(pid, windowId, style);
901 EXPECT_EQ(ret1, RET_OK);
902
903 CursorPixelMap curPixelMap;
904 int32_t ret = pointerDrawingManager.SetMouseIcon(pid, windowId, curPixelMap);
905 ASSERT_EQ(ret, RET_ERR);
906 }
907
908 /**
909 * @tc.name: InputWindowsManagerTest_AdjustMouseFocusByDirection270_01
910 * @tc.desc: Test AdjustMouseFocusByDirection270
911 * @tc.type: FUNC
912 * @tc.require:
913 */
914 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_AdjustMouseFocusByDirection270_01, TestSize.Level1)
915 {
916 CALL_TEST_DEBUG;
917 PointerDrawingManager pointerDrawingManager;
918 ICON_TYPE iconType = ANGLE_SW;
919 int32_t physicalX = 150;
920 int32_t physicalY = 200;
921 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.AdjustMouseFocusByDirection270(iconType, physicalX, physicalY));
922 }
923
924 /**
925 * @tc.name: InputWindowsManagerTest_AdjustMouseFocusByDirection270_02
926 * @tc.desc: Test AdjustMouseFocusByDirection270
927 * @tc.type: FUNC
928 * @tc.require:
929 */
930 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_AdjustMouseFocusByDirection270_02, TestSize.Level1)
931 {
932 CALL_TEST_DEBUG;
933 PointerDrawingManager pointerDrawingManager;
934 ICON_TYPE iconType = ANGLE_CENTER;
935 int32_t physicalX = 100;
936 int32_t physicalY = 150;
937 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.AdjustMouseFocusByDirection270(iconType, physicalX, physicalY));
938 }
939
940 /**
941 * @tc.name: InputWindowsManagerTest_AdjustMouseFocusByDirection270_03
942 * @tc.desc: Test AdjustMouseFocusByDirection270
943 * @tc.type: FUNC
944 * @tc.require:
945 */
946 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_AdjustMouseFocusByDirection270_03, TestSize.Level1)
947 {
948 CALL_TEST_DEBUG;
949 PointerDrawingManager pointerDrawingManager;
950 ICON_TYPE iconType = ANGLE_NW_RIGHT;
951 int32_t physicalX = 50;
952 int32_t physicalY = 150;
953 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.AdjustMouseFocusByDirection270(iconType, physicalX, physicalY));
954 }
955
956 /**
957 * @tc.name: InputWindowsManagerTest_AdjustMouseFocusByDirection270_04
958 * @tc.desc: Test AdjustMouseFocusByDirection270
959 * @tc.type: FUNC
960 * @tc.require:
961 */
962 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_AdjustMouseFocusByDirection270_04, TestSize.Level1)
963 {
964 CALL_TEST_DEBUG;
965 PointerDrawingManager pointerDrawingManager;
966 ICON_TYPE iconType = ANGLE_NW;
967 int32_t physicalX = 100;
968 int32_t physicalY = 50;
969 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.AdjustMouseFocusByDirection270(iconType, physicalX, physicalY));
970 }
971
972 /**
973 * @tc.name: InputWindowsManagerTest_AdjustMouseFocusByDirection180
974 * @tc.desc: Test AdjustMouseFocusByDirection180
975 * @tc.type: FUNC
976 * @tc.require:
977 */
978 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_AdjustMouseFocusByDirection180, TestSize.Level1)
979 {
980 CALL_TEST_DEBUG;
981 PointerDrawingManager pointerDrawingManager;
982 int32_t physicalX = 100;
983 int32_t physicalY = 50;
984 ICON_TYPE iconType = ANGLE_SW;
985 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.AdjustMouseFocusByDirection180(iconType, physicalX, physicalY));
986
987 iconType = ANGLE_CENTER;
988 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.AdjustMouseFocusByDirection180(iconType, physicalX, physicalY));
989
990 iconType = ANGLE_NW_RIGHT;
991 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.AdjustMouseFocusByDirection180(iconType, physicalX, physicalY));
992
993 iconType = ANGLE_NW;
994 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.AdjustMouseFocusByDirection180(iconType, physicalX, physicalY));
995 }
996
997 /**
998 * @tc.name: InputWindowsManagerTest_AdjustMouseFocusByDirection90
999 * @tc.desc: Test AdjustMouseFocusByDirection90
1000 * @tc.type: FUNC
1001 * @tc.require:
1002 */
1003 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_AdjustMouseFocusByDirection90, TestSize.Level1)
1004 {
1005 CALL_TEST_DEBUG;
1006 PointerDrawingManager pointerDrawingManager;
1007 int32_t physicalX = 100;
1008 int32_t physicalY = 150;
1009 ICON_TYPE iconType = ANGLE_SW;
1010 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.AdjustMouseFocusByDirection90(iconType, physicalX, physicalY));
1011
1012 iconType = ANGLE_CENTER;
1013 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.AdjustMouseFocusByDirection90(iconType, physicalX, physicalY));
1014
1015 iconType = ANGLE_NW_RIGHT;
1016 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.AdjustMouseFocusByDirection90(iconType, physicalX, physicalY));
1017
1018 iconType = ANGLE_NW;
1019 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.AdjustMouseFocusByDirection90(iconType, physicalX, physicalY));
1020 }
1021
1022 /**
1023 * @tc.name: InputWindowsManagerTest_AdjustMouseFocusByDirection0
1024 * @tc.desc: Test AdjustMouseFocusByDirection0
1025 * @tc.type: FUNC
1026 * @tc.require:
1027 */
1028 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_AdjustMouseFocusByDirection0, TestSize.Level1)
1029 {
1030 CALL_TEST_DEBUG;
1031 PointerDrawingManager pointerDrawingManager;
1032 int32_t physicalX = 150;
1033 int32_t physicalY = 200;
1034 ICON_TYPE iconType = ANGLE_SW;
1035 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.AdjustMouseFocusByDirection0(iconType, physicalX, physicalY));
1036
1037 iconType = ANGLE_CENTER;
1038 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.AdjustMouseFocusByDirection0(iconType, physicalX, physicalY));
1039
1040 iconType = ANGLE_NW_RIGHT;
1041 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.AdjustMouseFocusByDirection0(iconType, physicalX, physicalY));
1042
1043 iconType = ANGLE_NW;
1044 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.AdjustMouseFocusByDirection0(iconType, physicalX, physicalY));
1045 }
1046
1047 /**
1048 * @tc.name: InputWindowsManagerTest_DrawPixelmap_001
1049 * @tc.desc: Test DrawPixelmap
1050 * @tc.type: FUNC
1051 * @tc.require:
1052 */
1053 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_DrawPixelmap_001, TestSize.Level1)
1054 {
1055 CALL_TEST_DEBUG;
1056 PointerDrawingManager pointerDrawingManager;
1057 pointerDrawingManager.userIcon_ = std::make_unique<OHOS::Media::PixelMap>();
1058 OHOS::Rosen::Drawing::Canvas canvas;
1059 MOUSE_ICON mouseStyle = MOUSE_ICON::DEVELOPER_DEFINED_ICON;
1060 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.DrawPixelmap(canvas, mouseStyle));
1061 }
1062
1063 /**
1064 * @tc.name: InputWindowsManagerTest_DrawPixelmap_002
1065 * @tc.desc: Test DrawPixelmap
1066 * @tc.type: FUNC
1067 * @tc.require:
1068 */
1069 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_DrawPixelmap_002, TestSize.Level1)
1070 {
1071 CALL_TEST_DEBUG;
1072 PointerDrawingManager pointerDrawingManager;
1073 pointerDrawingManager.userIcon_ = std::make_unique<OHOS::Media::PixelMap>();
1074 OHOS::Rosen::Drawing::Canvas canvas;
1075 MOUSE_ICON mouseStyle = MOUSE_ICON::RUNNING;
1076 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.DrawPixelmap(canvas, mouseStyle));
1077 }
1078
1079 /**
1080 * @tc.name: InputWindowsManagerTest_DrawPixelmap_003
1081 * @tc.desc: Test DrawPixelmap
1082 * @tc.type: FUNC
1083 * @tc.require:
1084 */
1085 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_DrawPixelmap_003, TestSize.Level1)
1086 {
1087 CALL_TEST_DEBUG;
1088 PointerDrawingManager pointerDrawingManager;
1089 pointerDrawingManager.userIcon_ = std::make_unique<OHOS::Media::PixelMap>();
1090 OHOS::Rosen::Drawing::Canvas canvas;
1091 MOUSE_ICON mouseStyle = MOUSE_ICON::WEST_EAST;
1092 ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.DrawPixelmap(canvas, mouseStyle));
1093 }
1094
1095 /**
1096 * @tc.name: InputWindowsManagerTest_SetCustomCursor_001
1097 * @tc.desc: Test SetCustomCursor
1098 * @tc.type: FUNC
1099 * @tc.require:
1100 */
1101 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_SetCustomCursor_001, TestSize.Level1)
1102 {
1103 CALL_TEST_DEBUG;
1104 PointerDrawingManager pointerDrawingManager;
1105 const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/North_South.svg";
1106 std::unique_ptr<OHOS::Media::PixelMap> pixelMap = SetMouseIconTest(iconPath);
1107 ASSERT_NE(pixelMap, nullptr);
1108 int32_t pid = -1;
1109 int32_t windowId = 1;
1110 int32_t focusX = 2;
1111 int32_t focusY = 3;
1112 CursorPixelMap curPixelMap;
1113 curPixelMap.pixelMap = (void *)pixelMap.get();
1114 int32_t ret = pointerDrawingManager.SetCustomCursor(curPixelMap, pid, windowId, focusX, focusY);
1115 ASSERT_EQ(ret, RET_ERR);
1116 }
1117
1118 /**
1119 * @tc.name: InputWindowsManagerTest_SetPointerColor_01
1120 * @tc.desc: Test SetPointerColor
1121 * @tc.type: FUNC
1122 * @tc.require:
1123 */
1124 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_SetPointerColor_01, TestSize.Level1)
1125 {
1126 CALL_TEST_DEBUG;
1127 PointerDrawingManager pointerDrawingManager;
1128 Rosen::RSSurfaceNodeConfig surfaceNodeConfig;
1129 surfaceNodeConfig.SurfaceNodeName = "pointer window";
1130 Rosen::RSSurfaceNodeType surfaceNodeType = Rosen::RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE;
1131 pointerDrawingManager.surfaceNode_ = Rosen::RSSurfaceNode::Create(surfaceNodeConfig, surfaceNodeType);
1132 EXPECT_TRUE(pointerDrawingManager.surfaceNode_ != nullptr);
1133 int32_t color = 0;
1134 float alphaRatio = (static_cast<uint32_t>(color) >> RGB_CHANNEL_BITS_LENGTH) / MAX_ALPHA_VALUE;
1135 EXPECT_FALSE(alphaRatio > 1);
1136 int32_t ret = pointerDrawingManager.SetPointerColor(color);
1137 EXPECT_EQ(ret, RET_OK);
1138 }
1139
1140 /**
1141 * @tc.name: InputWindowsManagerTest_SetPointerColor_02
1142 * @tc.desc: Test SetPointerColor
1143 * @tc.type: FUNC
1144 * @tc.require:
1145 */
1146 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_SetPointerColor_02, TestSize.Level1)
1147 {
1148 CALL_TEST_DEBUG;
1149 PointerDrawingManager pointerDrawingManager;
1150 pointerDrawingManager.surfaceNode_ = nullptr;
1151 std::string name = POINTER_COLOR;
1152 int32_t color = 0;
1153 int32_t ret = PREFERENCES_MGR->SetIntValue(name, MOUSE_FILE_NAME, color);
1154 EXPECT_EQ(ret, RET_OK);
1155 int32_t ret2 = pointerDrawingManager.SetPointerColor(color);
1156 EXPECT_EQ(ret2, RET_ERR);
1157 }
1158
1159 /**
1160 * @tc.name: InputWindowsManagerTest_SetPointerSize_01
1161 * @tc.desc: Test SetPointerSize
1162 * @tc.type: FUNC
1163 * @tc.require:
1164 */
1165 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_SetPointerSize_01, TestSize.Level1)
1166 {
1167 CALL_TEST_DEBUG;
1168 PointerDrawingManager pointerDrawingManager;
1169 int32_t size = 0;
1170 EXPECT_EQ(pointerDrawingManager.SetPointerSize(size), RET_OK);
1171 size = 9;
1172 EXPECT_EQ(pointerDrawingManager.SetPointerSize(size), RET_OK);
1173
1174 size = 3;
1175 std::string name = POINTER_SIZE;
1176 int32_t ret = PREFERENCES_MGR->SetIntValue(name, MOUSE_FILE_NAME, size);
1177 EXPECT_EQ(ret, RET_OK);
1178 EXPECT_EQ(pointerDrawingManager.SetPointerSize(size), RET_OK);
1179 }
1180
1181 /**
1182 * @tc.name: InputWindowsManagerTest_SetPointerSize_02
1183 * @tc.desc: Test SetPointerSize
1184 * @tc.type: FUNC
1185 * @tc.require:
1186 */
1187 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_SetPointerSize_02, TestSize.Level1)
1188 {
1189 CALL_TEST_DEBUG;
1190 PointerDrawingManager pointerDrawingManager;
1191 int32_t size = 5;
1192 std::string name = POINTER_SIZE;
1193 int32_t ret = PREFERENCES_MGR->SetIntValue(name, MOUSE_FILE_NAME, size);
1194 EXPECT_EQ(ret, RET_OK);
1195 pointerDrawingManager.surfaceNode_ = nullptr;
1196 EXPECT_EQ(pointerDrawingManager.SetPointerSize(size), RET_OK);
1197 }
1198
1199 /**
1200 * @tc.name: InputWindowsManagerTest_SetPointerSize_03
1201 * @tc.desc: Test SetPointerSize
1202 * @tc.type: FUNC
1203 * @tc.require:
1204 */
1205 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_SetPointerSize_03, TestSize.Level1)
1206 {
1207 CALL_TEST_DEBUG;
1208 PointerDrawingManager pointerDrawingManager;
1209 int32_t size = 5;
1210 std::string name = POINTER_SIZE;
1211 int32_t ret = PREFERENCES_MGR->SetIntValue(name, MOUSE_FILE_NAME, size);
1212 EXPECT_EQ(ret, RET_OK);
1213
1214 Rosen::RSSurfaceNodeConfig surfaceNodeConfig;
1215 surfaceNodeConfig.SurfaceNodeName = "pointer window";
1216 Rosen::RSSurfaceNodeType surfaceNodeType = Rosen::RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE;
1217 pointerDrawingManager.surfaceNode_ = Rosen::RSSurfaceNode::Create(surfaceNodeConfig, surfaceNodeType);
1218 EXPECT_TRUE(pointerDrawingManager.surfaceNode_ != nullptr);
1219 EXPECT_EQ(pointerDrawingManager.SetPointerSize(size), RET_OK);
1220 }
1221
1222 /**
1223 * @tc.name: InputWindowsManagerTest_UpdatePointerDevice_01
1224 * @tc.desc: Test UpdatePointerDevice
1225 * @tc.type: FUNC
1226 * @tc.require:
1227 */
1228 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_UpdatePointerDevice_01, TestSize.Level1)
1229 {
1230 CALL_TEST_DEBUG;
1231 PointerDrawingManager manager;
1232 bool hasPointerDevice = true;
1233 bool isPointerVisible = true;
1234 bool isHotPlug = false;
1235 ASSERT_NO_FATAL_FAILURE(manager.UpdatePointerDevice(hasPointerDevice, isPointerVisible, isHotPlug));
1236 }
1237
1238 /**
1239 * @tc.name: InputWindowsManagerTest_UpdatePointerDevice_02
1240 * @tc.desc: Test UpdatePointerDevice
1241 * @tc.type: FUNC
1242 * @tc.require:
1243 */
1244 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_UpdatePointerDevice_02, TestSize.Level1)
1245 {
1246 CALL_TEST_DEBUG;
1247 PointerDrawingManager manager;
1248 bool hasPointerDevice = true;
1249 bool isPointerVisible = true;
1250 bool isHotPlug = true;
1251 ASSERT_NO_FATAL_FAILURE(manager.UpdatePointerDevice(hasPointerDevice, isPointerVisible, isHotPlug));
1252 }
1253
1254 /**
1255 * @tc.name: InputWindowsManagerTest_UpdatePointerDevice_03
1256 * @tc.desc: Test UpdatePointerDevice
1257 * @tc.type: FUNC
1258 * @tc.require:
1259 */
1260 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_UpdatePointerDevice_03, TestSize.Level1)
1261 {
1262 CALL_TEST_DEBUG;
1263 PointerDrawingManager manager;
1264 bool hasPointerDevice = false;
1265 bool isPointerVisible = false;
1266 bool isHotPlug = true;
1267
1268 Rosen::RSSurfaceNodeConfig surfaceNodeConfig;
1269 surfaceNodeConfig.SurfaceNodeName = "pointer window";
1270 Rosen::RSSurfaceNodeType surfaceNodeType = Rosen::RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE;
1271 manager.surfaceNode_ = Rosen::RSSurfaceNode::Create(surfaceNodeConfig, surfaceNodeType);
1272 EXPECT_TRUE(manager.surfaceNode_ != nullptr);
1273 ASSERT_NO_FATAL_FAILURE(manager.UpdatePointerDevice(hasPointerDevice, isPointerVisible, isHotPlug));
1274 }
1275
1276 /**
1277 * @tc.name: InputWindowsManagerTest_UpdatePointerDevice_04
1278 * @tc.desc: Test UpdatePointerDevice
1279 * @tc.type: FUNC
1280 * @tc.require:
1281 */
1282 HWTEST_F(PointerDrawingManagerExTest, InputWindowsManagerTest_UpdatePointerDevice_04, TestSize.Level1)
1283 {
1284 CALL_TEST_DEBUG;
1285 PointerDrawingManager manager;
1286 bool hasPointerDevice = false;
1287 bool isPointerVisible = false;
1288 bool isHotPlug = true;
1289 manager.surfaceNode_ = nullptr;
1290 ASSERT_NO_FATAL_FAILURE(manager.UpdatePointerDevice(hasPointerDevice, isPointerVisible, isHotPlug));
1291 }
1292
1293 /**
1294 * @tc.name: PointerDrawingManagerExTest_OnDisplayInfo
1295 * @tc.desc: Test OnDisplayInfo
1296 * @tc.type: FUNC
1297 * @tc.require:
1298 */
1299 HWTEST_F(PointerDrawingManagerExTest, PointerDrawingManagerExTest_OnDisplayInfo, TestSize.Level1)
1300 {
1301 CALL_TEST_DEBUG;
1302 PointerDrawingManager pointerDrawMgr;
1303 OLD::DisplayInfo displayInfo;
1304 OLD::DisplayGroupInfo displayGroupInfo;
1305 displayInfo.id = 10;
1306 displayInfo.width = 600;
1307 displayInfo.height = 600;
1308 displayGroupInfo.displaysInfo.push_back(displayInfo);
1309 pointerDrawMgr.displayInfo_.id = 15;
1310 pointerDrawMgr.surfaceNode_ = nullptr;
1311 ASSERT_NO_FATAL_FAILURE(pointerDrawMgr.OnDisplayInfo(displayGroupInfo));
1312
1313 Rosen::RSSurfaceNodeConfig surfaceNodeConfig;
1314 surfaceNodeConfig.SurfaceNodeName = "pointer window";
1315 Rosen::RSSurfaceNodeType surfaceNodeType = Rosen::RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE;
1316 pointerDrawMgr.surfaceNode_ = Rosen::RSSurfaceNode::Create(surfaceNodeConfig, surfaceNodeType);
1317 ASSERT_NE(pointerDrawMgr.surfaceNode_, nullptr);
1318 pointerDrawMgr.displayInfo_.id = 30;
1319 pointerDrawMgr.screenId_ = 100;
1320 ASSERT_NO_FATAL_FAILURE(pointerDrawMgr.OnDisplayInfo(displayGroupInfo));
1321 }
1322
1323 /**
1324 * @tc.name: PointerDrawingManagerExTest_DrawManager
1325 * @tc.desc: Test DrawManager
1326 * @tc.type: FUNC
1327 * @tc.require:
1328 */
1329 HWTEST_F(PointerDrawingManagerExTest, PointerDrawingManagerExTest_DrawManager, TestSize.Level1)
1330 {
1331 CALL_TEST_DEBUG;
1332 PointerDrawingManager pointerDrawMgr;
1333 pointerDrawMgr.hasDisplay_ = false;
1334 ASSERT_NO_FATAL_FAILURE(pointerDrawMgr.DrawManager());
1335 pointerDrawMgr.hasDisplay_ = true;
1336 pointerDrawMgr.hasPointerDevice_ = false;
1337 ASSERT_NO_FATAL_FAILURE(pointerDrawMgr.DrawManager());
1338 pointerDrawMgr.hasPointerDevice_ = true;
1339 Rosen::RSSurfaceNodeConfig surfaceNodeConfig;
1340 surfaceNodeConfig.SurfaceNodeName = "pointer window";
1341 Rosen::RSSurfaceNodeType surfaceNodeType = Rosen::RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE;
1342 pointerDrawMgr.surfaceNode_ = Rosen::RSSurfaceNode::Create(surfaceNodeConfig, surfaceNodeType);
1343 ASSERT_NE(pointerDrawMgr.surfaceNode_, nullptr);
1344 ASSERT_NO_FATAL_FAILURE(pointerDrawMgr.DrawManager());
1345 pointerDrawMgr.surfaceNode_ = nullptr;
1346 pointerDrawMgr.displayInfo_.id = 100;
1347 pointerDrawMgr.displayInfo_.width = 600;
1348 pointerDrawMgr.displayInfo_.height = 600;
1349 pointerDrawMgr.displayInfo_.direction = DIRECTION0;
1350 pointerDrawMgr.lastPhysicalX_ = -1;
1351 ASSERT_NO_FATAL_FAILURE(pointerDrawMgr.DrawManager());
1352 pointerDrawMgr.surfaceNode_ = nullptr;
1353 pointerDrawMgr.lastPhysicalY_ = 100;
1354 pointerDrawMgr.lastPhysicalY_ = -1;
1355 ASSERT_NO_FATAL_FAILURE(pointerDrawMgr.DrawManager());
1356 pointerDrawMgr.surfaceNode_ = nullptr;
1357 pointerDrawMgr.lastPhysicalY_ = 100;
1358 ASSERT_NO_FATAL_FAILURE(pointerDrawMgr.DrawManager());
1359 }
1360
1361 /**
1362 * @tc.name: PointerDrawingManagerExTest_DeletePointerVisible
1363 * @tc.desc: Test DeletePointerVisible
1364 * @tc.type: FUNC
1365 * @tc.require:
1366 */
1367 HWTEST_F(PointerDrawingManagerExTest, PointerDrawingManagerExTest_DeletePointerVisible, TestSize.Level1)
1368 {
1369 CALL_TEST_DEBUG;
1370 PointerDrawingManager pointerDrawMgr;
1371 int32_t pid = 100;
1372 PointerDrawingManager::PidInfo pidInfo;
1373 pidInfo.pid = 50;
1374 pointerDrawMgr.pidInfos_.push_back(pidInfo);
1375 pidInfo.pid = 100;
1376 pointerDrawMgr.pidInfos_.push_back(pidInfo);
1377 pidInfo.pid = 300;
1378 pidInfo.visible = true;
1379 pointerDrawMgr.hapPidInfos_.push_back(pidInfo);
1380 pointerDrawMgr.pid_ = 300;
1381 ASSERT_NO_FATAL_FAILURE(pointerDrawMgr.DeletePointerVisible(pid));
1382 }
1383
1384 /**
1385 * @tc.name: PointerDrawingManagerExTest_DeletePointerVisible_001
1386 * @tc.desc: Test DeletePointerVisible
1387 * @tc.type: FUNC
1388 * @tc.require:
1389 */
1390 HWTEST_F(PointerDrawingManagerExTest, PointerDrawingManagerExTest_DeletePointerVisible_001, TestSize.Level1)
1391 {
1392 CALL_TEST_DEBUG;
1393 PointerDrawingManager pointerDrawMgr;
1394 int32_t pid = 100;
1395 PointerDrawingManager::PidInfo pidInfo;
1396 pidInfo.pid = 100;
1397 pointerDrawMgr.pidInfos_.push_back(pidInfo);
1398 pidInfo.visible = false;
1399 pointerDrawMgr.hapPidInfos_.push_back(pidInfo);
1400 pointerDrawMgr.pid_ = 100;
1401 ASSERT_NO_FATAL_FAILURE(pointerDrawMgr.DeletePointerVisible(pid));
1402 }
1403
1404 /**
1405 * @tc.name: PointerDrawingManagerExTest_DeletePointerVisible_002
1406 * @tc.desc: Test DeletePointerVisible
1407 * @tc.type: FUNC
1408 * @tc.require:
1409 */
1410 HWTEST_F(PointerDrawingManagerExTest, PointerDrawingManagerExTest_DeletePointerVisible_002, TestSize.Level1)
1411 {
1412 CALL_TEST_DEBUG;
1413 PointerDrawingManager pointerDrawMgr;
1414 int32_t pid = 100;
1415 PointerDrawingManager::PidInfo pidInfo;
1416 pidInfo.pid = 500;
1417 pointerDrawMgr.pidInfos_.push_back(pidInfo);
1418 ASSERT_NO_FATAL_FAILURE(pointerDrawMgr.DeletePointerVisible(pid));
1419 }
1420
1421 /**
1422 * @tc.name: PointerDrawingManagerExTest_OnSessionLost
1423 * @tc.desc: Test OnSessionLost
1424 * @tc.type: FUNC
1425 * @tc.require:
1426 */
1427 HWTEST_F(PointerDrawingManagerExTest, PointerDrawingManagerExTest_OnSessionLost, TestSize.Level1)
1428 {
1429 CALL_TEST_DEBUG;
1430 PointerDrawingManager pointerDrawMgr;
1431 int32_t pid = 100;
1432 PointerDrawingManager::PidInfo pidInfo;
1433 pidInfo.pid = 200;
1434 pointerDrawMgr.hapPidInfos_.push_back(pidInfo);
1435 pidInfo.pid = 100;
1436 pointerDrawMgr.hapPidInfos_.push_back(pidInfo);
1437 ASSERT_NO_FATAL_FAILURE(pointerDrawMgr.OnSessionLost(pid));
1438 }
1439
1440 /**
1441 * @tc.name: PointerDrawingManagerExTest_GetIconStyle
1442 * @tc.desc: Test GetIconStyle
1443 * @tc.type: FUNC
1444 * @tc.require:
1445 */
1446 HWTEST_F(PointerDrawingManagerExTest, PointerDrawingManagerExTest_GetIconStyle, TestSize.Level1)
1447 {
1448 CALL_TEST_DEBUG;
1449 PointerDrawingManager pointerDrawMgr;
1450 MOUSE_ICON mouseStyle = CURSOR_MOVE;
1451 IconStyle iconStyle;
1452 pointerDrawMgr.mouseIcons_.insert(std::make_pair(mouseStyle, iconStyle));
1453 ASSERT_NO_FATAL_FAILURE(pointerDrawMgr.GetIconStyle(mouseStyle));
1454 mouseStyle = static_cast<MOUSE_ICON>(100);
1455 ASSERT_NO_FATAL_FAILURE(pointerDrawMgr.GetIconStyle(mouseStyle));
1456 }
1457
1458 /**
1459 * @tc.name: PointerDrawingManagerExTest_SetPointerVisible
1460 * @tc.desc: Test SetPointerVisible
1461 * @tc.type: FUNC
1462 * @tc.require:
1463 */
1464 HWTEST_F(PointerDrawingManagerExTest, PointerDrawingManagerExTest_SetPointerVisible, TestSize.Level1)
1465 {
1466 CALL_TEST_DEBUG;
1467 PointerDrawingManager pointerDrawMgr;
1468 int32_t pid = 1;
1469 bool visible = true;
1470 int32_t priority = 0;
1471 bool isHap = true;
1472 int32_t count = 101;
1473 PointerDrawingManager::PidInfo pidInfo;
1474 Rosen::RSSurfaceNodeConfig surfaceNodeConfig;
1475 surfaceNodeConfig.SurfaceNodeName = "pointer window";
1476 Rosen::RSSurfaceNodeType surfaceNodeType = Rosen::RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE;
1477 pointerDrawMgr.surfaceNode_ = Rosen::RSSurfaceNode::Create(surfaceNodeConfig, surfaceNodeType);
1478 ASSERT_NE(pointerDrawMgr.surfaceNode_, nullptr);
1479 for (int32_t i = 0; i < count; ++i) {
1480 pidInfo.pid = i;
1481 pointerDrawMgr.hapPidInfos_.push_back(pidInfo);
1482 }
1483 ASSERT_EQ(pointerDrawMgr.SetPointerVisible(pid, visible, priority, isHap), RET_OK);
1484 pid = 5;
1485 pointerDrawMgr.hapPidInfos_.pop_front();
1486 ASSERT_EQ(pointerDrawMgr.SetPointerVisible(pid, visible, priority, isHap), RET_OK);
1487 }
1488
1489 /**
1490 * @tc.name: PointerDrawingManagerExTest_SetPointerVisible_001
1491 * @tc.desc: Test SetPointerVisible
1492 * @tc.type: FUNC
1493 * @tc.require:
1494 */
1495 HWTEST_F(PointerDrawingManagerExTest, PointerDrawingManagerExTest_SetPointerVisible_001, TestSize.Level1)
1496 {
1497 CALL_TEST_DEBUG;
1498 PointerDrawingManager pointerDrawMgr;
1499 int32_t pid = 0;
1500 bool visible = true;
1501 int32_t priority = 50;
1502 bool isHap = false;
1503 int32_t count = 105;
1504 PointerDrawingManager::PidInfo pidInfo;
1505 Rosen::RSSurfaceNodeConfig surfaceNodeConfig;
1506 surfaceNodeConfig.SurfaceNodeName = "pointer window";
1507 Rosen::RSSurfaceNodeType surfaceNodeType = Rosen::RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE;
1508 pointerDrawMgr.surfaceNode_ = Rosen::RSSurfaceNode::Create(surfaceNodeConfig, surfaceNodeType);
1509 ASSERT_NE(pointerDrawMgr.surfaceNode_, nullptr);
1510 for (int32_t i = 0; i < count; ++i) {
1511 pidInfo.pid = i;
1512 pointerDrawMgr.pidInfos_.push_back(pidInfo);
1513 }
1514 ASSERT_EQ(pointerDrawMgr.SetPointerVisible(pid, visible, priority, isHap), RET_OK);
1515 }
1516
1517 /**
1518 * @tc.name: PointerDrawingManagerExTest_SetMouseIcon
1519 * @tc.desc: Test SetCustomCursor
1520 * @tc.type: FUNC
1521 * @tc.require:
1522 */
1523 HWTEST_F(PointerDrawingManagerExTest, PointerDrawingManagerExTest_SetMouseIcon, TestSize.Level1)
1524 {
1525 CALL_TEST_DEBUG;
1526 PointerDrawingManager pointerDrawMgr;
1527 std::shared_ptr<Media::PixelMap> pixelMapPtr = CreatePixelMap(MIDDLE_PIXEL_MAP_WIDTH, MIDDLE_PIXEL_MAP_HEIGHT);
1528 int32_t pid = 50;
1529 int32_t windowId = -1;
1530 CursorPixelMap curPixelMap;
1531 curPixelMap.pixelMap = (void *)pixelMapPtr.get();
1532 EXPECT_EQ(pointerDrawMgr.SetMouseIcon(pid, windowId, curPixelMap), RET_ERR);
1533 }
1534
1535 /**
1536 * @tc.name: PointerDrawingManagerExTest_SetMouseHotSpot
1537 * @tc.desc: Test SetCustomCursor
1538 * @tc.type: FUNC
1539 * @tc.require:
1540 */
1541 HWTEST_F(PointerDrawingManagerExTest, PointerDrawingManagerExTest_SetMouseHotSpot, TestSize.Level1)
1542 {
1543 CALL_TEST_DEBUG;
1544 auto winmgrmock = std::make_shared<InputWindowsManagerMock>();
1545 EXPECT_CALL(*winmgrmock, CheckWindowIdPermissionByPid).WillRepeatedly(Return(RET_OK));
1546 PointerDrawingManager pointerDrawMgr;
1547 int32_t pid = 10;
1548 int32_t windowId = 100;
1549 int32_t hotSpotX = -1;
1550 int32_t hotSpotY = 100;
1551 EXPECT_EQ(pointerDrawMgr.SetMouseHotSpot(pid, windowId, hotSpotX, hotSpotY), RET_ERR);
1552 }
1553
1554 /**
1555 * @tc.name: PointerDrawingManagerExTest_SetMouseHotSpot_001
1556 * @tc.desc: Test SetCustomCursor
1557 * @tc.type: FUNC
1558 * @tc.require:
1559 */
1560 HWTEST_F(PointerDrawingManagerExTest, PointerDrawingManagerExTest_SetMouseHotSpot_001, TestSize.Level1)
1561 {
1562 CALL_TEST_DEBUG;
1563 auto winmgrmock = std::make_shared<InputWindowsManagerMock>();
1564 EXPECT_CALL(*winmgrmock, CheckWindowIdPermissionByPid).WillRepeatedly(Return(RET_OK));
1565 PointerDrawingManager pointerDrawMgr;
1566 int32_t pid = 10;
1567 int32_t windowId = 100;
1568 int32_t hotSpotX = 100;
1569 int32_t hotSpotY = -1;
1570 EXPECT_EQ(pointerDrawMgr.SetMouseHotSpot(pid, windowId, hotSpotX, hotSpotY), RET_ERR);
1571 }
1572
1573 /**
1574 * @tc.name: PointerDrawingManagerExTest_SetMouseHotSpot_002
1575 * @tc.desc: Test SetCustomCursor
1576 * @tc.type: FUNC
1577 * @tc.require:
1578 */
1579 HWTEST_F(PointerDrawingManagerExTest, PointerDrawingManagerExTest_SetMouseHotSpot_002, TestSize.Level1)
1580 {
1581 CALL_TEST_DEBUG;
1582 auto winmgrmock = std::make_shared<InputWindowsManagerMock>();
1583 EXPECT_CALL(*winmgrmock, CheckWindowIdPermissionByPid).WillRepeatedly(Return(RET_OK));
1584 PointerDrawingManager pointerDrawMgr;
1585 int32_t pid = 10;
1586 int32_t windowId = 100;
1587 int32_t hotSpotX = 100;
1588 int32_t hotSpotY = 100;
1589 pointerDrawMgr.userIcon_ = nullptr;
1590 EXPECT_EQ(pointerDrawMgr.SetMouseHotSpot(pid, windowId, hotSpotX, hotSpotY), RET_ERR);
1591 }
1592
1593 /**
1594 * @tc.name: PointerDrawingManagerExTest_SetMouseHotSpot_003
1595 * @tc.desc: Test SetCustomCursor
1596 * @tc.type: FUNC
1597 * @tc.require:
1598 */
1599 HWTEST_F(PointerDrawingManagerExTest, PointerDrawingManagerExTest_SetMouseHotSpot_003, TestSize.Level1)
1600 {
1601 CALL_TEST_DEBUG;
1602 PointerStyle pointerStyle;
1603 pointerStyle.id = MOUSE_ICON::DEFAULT;
1604 auto winmgrmock = std::make_shared<InputWindowsManagerMock>();
1605 EXPECT_CALL(*winmgrmock, CheckWindowIdPermissionByPid).WillRepeatedly(Return(RET_OK));
1606 PointerDrawingManager pointerDrawMgr;
1607 int32_t pid = 10;
1608 int32_t windowId = 100;
1609 int32_t hotSpotX = 100;
1610 int32_t hotSpotY = 100;
1611 pointerDrawMgr.userIcon_ = std::make_unique<OHOS::Media::PixelMap>();
1612 EXPECT_EQ(pointerDrawMgr.SetMouseHotSpot(pid, windowId, hotSpotX, hotSpotY), RET_ERR);
1613 }
1614
1615 /**
1616 * @tc.name: PointerDrawingManagerExTest_AttachToDisplay_001
1617 * @tc.desc: Test the funcation AttachToDisplay
1618 * @tc.type: FUNC
1619 * @tc.require:
1620 */
1621 HWTEST_F(PointerDrawingManagerExTest, PointerDrawingManagerExTest_AttachToDisplay_001, TestSize.Level1)
1622 {
1623 CALL_TEST_DEBUG;
1624 EXPECT_CALL(*WIN_MGR_MOCK, GetDisplayMode).WillRepeatedly(testing::Return(DisplayMode::MAIN));
1625 PointerDrawingManager pointerDrawMgr;
1626 Rosen::RSSurfaceNodeConfig surfaceNodeConfig;
1627 surfaceNodeConfig.SurfaceNodeName = "pointer window";
1628 Rosen::RSSurfaceNodeType surfaceNodeType = Rosen::RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE;
1629 pointerDrawMgr.surfaceNode_ = Rosen::RSSurfaceNode::Create(surfaceNodeConfig, surfaceNodeType);
1630 EXPECT_TRUE(pointerDrawMgr.surfaceNode_ != nullptr);
1631 pointerDrawMgr.screenId_ = 0;
1632 ASSERT_NO_FATAL_FAILURE(pointerDrawMgr.AttachToDisplay());
1633 pointerDrawMgr.screenId_ = 10;
1634 ASSERT_NO_FATAL_FAILURE(pointerDrawMgr.AttachToDisplay());
1635 }
1636
1637 /**
1638 * @tc.name: PointerDrawingManagerExTest_AttachToDisplay_002
1639 * @tc.desc: Test the funcation AttachToDisplay
1640 * @tc.type: FUNC
1641 * @tc.require:
1642 */
1643 HWTEST_F(PointerDrawingManagerExTest, PointerDrawingManagerExTest_AttachToDisplay_002, TestSize.Level1)
1644 {
1645 CALL_TEST_DEBUG;
1646 EXPECT_CALL(*WIN_MGR_MOCK, GetDisplayMode).WillRepeatedly(testing::Return(DisplayMode::SUB));
1647 PointerDrawingManager pointerDrawMgr;
1648 Rosen::RSSurfaceNodeConfig surfaceNodeConfig;
1649 surfaceNodeConfig.SurfaceNodeName = "pointer window";
1650 Rosen::RSSurfaceNodeType surfaceNodeType = Rosen::RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE;
1651 pointerDrawMgr.surfaceNode_ = Rosen::RSSurfaceNode::Create(surfaceNodeConfig, surfaceNodeType);
1652 EXPECT_TRUE(pointerDrawMgr.surfaceNode_ != nullptr);
1653 pointerDrawMgr.screenId_ = 5;
1654 ASSERT_NO_FATAL_FAILURE(pointerDrawMgr.AttachToDisplay());
1655 pointerDrawMgr.screenId_ = 0;
1656 ASSERT_NO_FATAL_FAILURE(pointerDrawMgr.AttachToDisplay());
1657 }
1658
1659 /**
1660 * @tc.name: PointerDrawingManagerExTest_SkipPointerLayer_001
1661 * @tc.desc: Test the funcation SkipPointerLayer
1662 * @tc.type: FUNC
1663 * @tc.require:
1664 */
1665 HWTEST_F(PointerDrawingManagerExTest, PointerDrawingManagerExTest_SkipPointerLayer_001, TestSize.Level1)
1666 {
1667 CALL_TEST_DEBUG;
1668 PointerDrawingManager pointerDrawMgr;
1669 bool isSkip = true;
1670 pointerDrawMgr.surfaceNode_ = nullptr;
1671 ASSERT_NO_FATAL_FAILURE(pointerDrawMgr.SkipPointerLayer(isSkip));
1672 Rosen::RSSurfaceNodeConfig surfaceNodeConfig;
1673 surfaceNodeConfig.SurfaceNodeName = "pointer window";
1674 Rosen::RSSurfaceNodeType surfaceNodeType = Rosen::RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE;
1675 pointerDrawMgr.surfaceNode_ = Rosen::RSSurfaceNode::Create(surfaceNodeConfig, surfaceNodeType);
1676 ASSERT_TRUE(pointerDrawMgr.surfaceNode_ != nullptr);
1677 ASSERT_NO_FATAL_FAILURE(pointerDrawMgr.SkipPointerLayer(isSkip));
1678 }
1679
1680 /**
1681 * @tc.name: PointerDrawingManagerExTest_SkipPointerLayer_002
1682 * @tc.desc: Test the funcation SkipPointerLayer
1683 * @tc.type: FUNC
1684 * @tc.require:
1685 */
1686 HWTEST_F(PointerDrawingManagerExTest, PointerDrawingManagerExTest_SkipPointerLayer_002, TestSize.Level1)
1687 {
1688 CALL_TEST_DEBUG;
1689 PointerDrawingManager pointerDrawMgr;
1690 bool isSkip = false;
1691 pointerDrawMgr.surfaceNode_ = nullptr;
1692 ASSERT_NO_FATAL_FAILURE(pointerDrawMgr.SkipPointerLayer(isSkip));
1693 Rosen::RSSurfaceNodeConfig surfaceNodeConfig;
1694 surfaceNodeConfig.SurfaceNodeName = "SkipPointerLayer";
1695 Rosen::RSSurfaceNodeType surfaceNodeType = Rosen::RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE;
1696 pointerDrawMgr.surfaceNode_ = Rosen::RSSurfaceNode::Create(surfaceNodeConfig, surfaceNodeType);
1697 ASSERT_TRUE(pointerDrawMgr.surfaceNode_ != nullptr);
1698 ASSERT_NO_FATAL_FAILURE(pointerDrawMgr.SkipPointerLayer(isSkip));
1699 }
1700
1701 /**
1702 @tc.name: PointerDrawingManagerExTest_PixelFormatToColorType_001
1703 @tc.desc: Test the funcation PixelFormatToColorType
1704 @tc.type: FUNC
1705 @tc.require:
1706 */
1707 HWTEST_F(PointerDrawingManagerExTest, PointerDrawingManagerExTest_PixelFormatToColorType_001, TestSize.Level1)
1708 {
1709 CALL_TEST_DEBUG;
1710 PointerDrawingManager pointerDrawMgr;
1711 Media::PixelFormat pixelFormat = Media::PixelFormat::RGB_565;
1712 auto value = Rosen::Drawing::ColorType::COLORTYPE_RGB_565;
1713 Rosen::Drawing::ColorType ret = pointerDrawMgr.PixelFormatToColorType(pixelFormat);
1714 EXPECT_EQ(ret, value);
1715 pixelFormat = Media::PixelFormat::RGBA_8888;
1716 value = Rosen::Drawing::ColorType::COLORTYPE_RGBA_8888;
1717 ret = pointerDrawMgr.PixelFormatToColorType(pixelFormat);
1718 EXPECT_EQ(ret, value);
1719 pixelFormat = Media::PixelFormat::BGRA_8888;
1720 value = Rosen::Drawing::ColorType::COLORTYPE_BGRA_8888;
1721 ret = pointerDrawMgr.PixelFormatToColorType(pixelFormat);
1722 EXPECT_EQ(ret, value);
1723 pixelFormat = Media::PixelFormat::ALPHA_8;
1724 value = Rosen::Drawing::ColorType::COLORTYPE_ALPHA_8;
1725 ret = pointerDrawMgr.PixelFormatToColorType(pixelFormat);
1726 EXPECT_EQ(ret, value);
1727 pixelFormat = Media::PixelFormat::RGBA_F16;
1728 value = Rosen::Drawing::ColorType::COLORTYPE_RGBA_F16;
1729 ret = pointerDrawMgr.PixelFormatToColorType(pixelFormat);
1730 EXPECT_EQ(ret, value);
1731 pixelFormat = Media::PixelFormat::UNKNOWN;
1732 value = Rosen::Drawing::ColorType::COLORTYPE_UNKNOWN;
1733 ret = pointerDrawMgr.PixelFormatToColorType(pixelFormat);
1734 EXPECT_EQ(ret, value);
1735 pixelFormat = Media::PixelFormat::ARGB_8888;
1736 ret = pointerDrawMgr.PixelFormatToColorType(pixelFormat);
1737 EXPECT_EQ(ret, value);
1738 pixelFormat = Media::PixelFormat::RGB_888;
1739 ret = pointerDrawMgr.PixelFormatToColorType(pixelFormat);
1740 EXPECT_EQ(ret, value);
1741 pixelFormat = Media::PixelFormat::NV21;
1742 ret = pointerDrawMgr.PixelFormatToColorType(pixelFormat);
1743 EXPECT_EQ(ret, value);
1744 pixelFormat = Media::PixelFormat::NV12;
1745 ret = pointerDrawMgr.PixelFormatToColorType(pixelFormat);
1746 EXPECT_EQ(ret, value);
1747 pixelFormat = Media::PixelFormat::CMYK;
1748 ret = pointerDrawMgr.PixelFormatToColorType(pixelFormat);
1749 EXPECT_EQ(ret, value);
1750 }
1751
1752 /**
1753 @tc.name: PointerDrawingManagerExTest_AlphaTypeToAlphaType_001
1754 @tc.desc: Test the funcation AlphaTypeToAlphaType
1755 @tc.type: FUNC
1756 @tc.require:
1757 */
1758 HWTEST_F(PointerDrawingManagerExTest, PointerDrawingManagerExTest_AlphaTypeToAlphaType_001, TestSize.Level1)
1759 {
1760 CALL_TEST_DEBUG;
1761 PointerDrawingManager pointerDrawMgr;
1762 Media::AlphaType alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN;
1763 auto value = Rosen::Drawing::AlphaType::ALPHATYPE_UNKNOWN;
1764 Rosen::Drawing::AlphaType ret = pointerDrawMgr.AlphaTypeToAlphaType(alphaType);
1765 EXPECT_EQ(ret, value);
1766 alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
1767 value = Rosen::Drawing::AlphaType::ALPHATYPE_OPAQUE;
1768 ret = pointerDrawMgr.AlphaTypeToAlphaType(alphaType);
1769 EXPECT_EQ(ret, value);
1770 alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_PREMUL;
1771 value = Rosen::Drawing::AlphaType::ALPHATYPE_PREMUL;
1772 ret = pointerDrawMgr.AlphaTypeToAlphaType(alphaType);
1773 EXPECT_EQ(ret, value);
1774 alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_UNPREMUL;
1775 value = Rosen::Drawing::AlphaType::ALPHATYPE_UNPREMUL;
1776 ret = pointerDrawMgr.AlphaTypeToAlphaType(alphaType);
1777 EXPECT_EQ(ret, value);
1778 }
1779
1780 /**
1781 @tc.name: PointerDrawingManagerExTest_ClearWindowPointerStyle_001
1782 @tc.desc: Test the funcation ClearWindowPointerStyle
1783 @tc.type: FUNC
1784 @tc.require:
1785 */
1786 HWTEST_F(PointerDrawingManagerExTest, PointerDrawingManagerExTest_ClearWindowPointerStyle_001, TestSize.Level1)
1787 {
1788 CALL_TEST_DEBUG;
1789 PointerDrawingManager pointerDrawMgr;
1790 int32_t pid = 2;
1791 int32_t windowId = 1;
1792 ASSERT_NO_FATAL_FAILURE(pointerDrawMgr.ClearWindowPointerStyle(pid, windowId));
1793 }
1794
1795 /**
1796 * @tc.name: PointerDrawingManagerExTest_IsWindowRotation_001
1797 * @tc.desc: Test the funcation IsWindowRotation
1798 * @tc.type: FUNC
1799 * @tc.require:
1800 */
1801 HWTEST_F(PointerDrawingManagerExTest, PointerDrawingManagerExTest_IsWindowRotation_001, TestSize.Level1)
1802 {
1803 OLD::DisplayInfo displayInfo;
1804 auto *pointerDrawingManager = static_cast<PointerDrawingManager *>(IPointerDrawingManager::GetInstance());
1805 bool ret = pointerDrawingManager->IsWindowRotation(&displayInfo);
1806 if (ROTATE_POLICY == WINDOW_ROTATE) {
1807 ASSERT_EQ(ret, true);
1808 } else {
1809 ASSERT_EQ(ret, false);
1810 }
1811 }
1812 } // namespace MMI
1813 } // namespace OHOS