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 #include "product_name_definition.h" 22 #include "product_type_parser.h" 23 24 #undef MMI_LOG_TAG 25 #define MMI_LOG_TAG "ScreenPointerTest" 26 27 namespace OHOS { 28 namespace MMI { 29 namespace { 30 using namespace testing::ext; 31 } // namespace 32 class ScreenPointerTest : public testing::Test { 33 public: SetUpTestCase(void)34 static void SetUpTestCase(void) {}; TearDownTestCase(void)35 static void TearDownTestCase(void) {}; SetUp(void)36 void SetUp(void) {}; 37 }; 38 39 /** 40 * @tc.name: ScreenPointerTest_UpdateScreenInfo_001 41 * @tc.desc: Test UpdateScreenInfo 42 * @tc.type: Function 43 * @tc.require: 44 */ 45 HWTEST_F(ScreenPointerTest, ScreenPointerTest_UpdateScreenInfo_001, TestSize.Level1) 46 { 47 CALL_TEST_DEBUG; 48 hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>(); 49 ASSERT_NE(hwcmgr, nullptr); 50 handler_ptr_t handler = nullptr; 51 sptr<OHOS::Rosen::ScreenInfo> screenInfo = new OHOS::Rosen::ScreenInfo(); 52 ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, screenInfo); 53 ASSERT_NE(screenpointer, nullptr); 54 auto ret = screenpointer->InitSurface(); 55 EXPECT_EQ(ret, true); 56 uint32_t width = screenpointer->GetScreenWidth(); 57 EXPECT_EQ(width, 0); 58 uint32_t height = screenpointer->GetScreenHeight(); 59 EXPECT_EQ(height, 0); 60 EXPECT_NO_FATAL_FAILURE(screenpointer->UpdateScreenInfo(screenInfo)); 61 } 62 63 /** 64 * @tc.name: ScreenPointerTest_GetRenderDPI_001 65 * @tc.desc: Test GetRenderDPI 66 * @tc.type: Function 67 * @tc.require: 68 */ 69 HWTEST_F(ScreenPointerTest, ScreenPointerTest_GetRenderDPI_001, TestSize.Level1) 70 { 71 CALL_TEST_DEBUG; 72 hwcmgr_ptr_t hwcmgr = nullptr; 73 handler_ptr_t handler = nullptr; 74 OLD::DisplayInfo di; 75 ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di); 76 ASSERT_NE(screenpointer, nullptr); 77 screenpointer->isCurrentOffScreenRendering_ = true; 78 screenpointer->mode_ = mode_t::SCREEN_MIRROR; 79 float ret = screenpointer->GetRenderDPI(); 80 EXPECT_EQ(ret, 0); 81 screenpointer->mode_ = mode_t::SCREEN_MAIN; 82 ret = screenpointer->GetRenderDPI(); 83 screenpointer->isCurrentOffScreenRendering_ = false; 84 screenpointer->mode_ = mode_t::SCREEN_MIRROR; 85 ret = screenpointer->GetRenderDPI(); 86 screenpointer->mode_ = mode_t::SCREEN_MAIN; 87 ret = screenpointer->GetRenderDPI(); 88 EXPECT_EQ(ret, 0); 89 } 90 91 /** 92 * @tc.name: ScreenPointerTest_SetInvisible_001 93 * @tc.desc: Test SetInvisible 94 * @tc.type: Function 95 * @tc.require: 96 */ 97 HWTEST_F(ScreenPointerTest, ScreenPointerTest_SetInvisible_001, TestSize.Level1) 98 { 99 CALL_TEST_DEBUG; 100 hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>(); 101 ASSERT_NE(hwcmgr, nullptr); 102 handler_ptr_t handler = nullptr; 103 OLD::DisplayInfo di; 104 ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di); 105 ASSERT_NE(screenpointer, nullptr); 106 PointerRenderer renderer; 107 ASSERT_TRUE(screenpointer->Init(renderer)); 108 bool ret = screenpointer->SetInvisible(); 109 EXPECT_EQ(ret, hwcmgr->IsSupported()); 110 } 111 112 /** 113 * @tc.name: ScreenPointerTest_SetInvisible_002 114 * @tc.desc: Test SetInvisible 115 * @tc.type: Function 116 * @tc.require: 117 */ 118 HWTEST_F(ScreenPointerTest, ScreenPointerTest_SetInvisible_002, TestSize.Level1) 119 { 120 CALL_TEST_DEBUG; 121 hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>(); 122 ASSERT_NE(hwcmgr, nullptr); 123 handler_ptr_t handler = nullptr; 124 OLD::DisplayInfo di; 125 ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di); 126 ASSERT_NE(screenpointer, nullptr); 127 PointerRenderer renderer; 128 ASSERT_TRUE(screenpointer->Init(renderer)); 129 screenpointer->SetVirtualExtend(true); 130 bool ret = screenpointer->SetInvisible(); 131 EXPECT_TRUE(ret); 132 } 133 134 /** 135 * @tc.name: ScreenPointerTest_MoveSoft_001 136 * @tc.desc: Test MoveSoft 137 * @tc.type: Function 138 * @tc.require: 139 */ 140 HWTEST_F(ScreenPointerTest, ScreenPointerTest_MoveSoft_001, TestSize.Level1) 141 { 142 CALL_TEST_DEBUG; 143 hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>(); 144 ASSERT_NE(hwcmgr, nullptr); 145 handler_ptr_t handler = nullptr; 146 OLD::DisplayInfo di; 147 ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di); 148 ASSERT_NE(screenpointer, nullptr); 149 Rosen::RSSurfaceNodeConfig surfaceNodeConfig; 150 surfaceNodeConfig.SurfaceNodeName = "pointer window"; 151 screenpointer->surfaceNode_ = Rosen::RSSurfaceNode::Create(surfaceNodeConfig, 152 Rosen::RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE); 153 ASSERT_NE(screenpointer->surfaceNode_, nullptr); 154 screenpointer->mode_ = mode_t::SCREEN_MIRROR; 155 ICON_TYPE align = ANGLE_W; 156 int32_t x = 0; 157 int32_t y = 0; 158 bool ret = screenpointer->MoveSoft(x, y, align); 159 EXPECT_TRUE(ret); 160 screenpointer->mode_ = mode_t::SCREEN_MAIN; 161 ret = screenpointer->MoveSoft(x, y, align); 162 EXPECT_TRUE(ret); 163 screenpointer->mode_ = mode_t::SCREEN_EXTEND; 164 ret = screenpointer->MoveSoft(x, y, align); 165 EXPECT_TRUE(ret); 166 } 167 168 /** 169 * @tc.name: ScreenPointerTest_MoveSoft_002 170 * @tc.desc: Test MoveSoft 171 * @tc.type: Function 172 * @tc.require: 173 */ 174 HWTEST_F(ScreenPointerTest, ScreenPointerTest_MoveSoft_002, TestSize.Level1) 175 { 176 CALL_TEST_DEBUG; 177 hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>(); 178 ASSERT_NE(hwcmgr, nullptr); 179 handler_ptr_t handler = nullptr; 180 OLD::DisplayInfo di; 181 di.id = 1; 182 ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di); 183 Rosen::RSSurfaceNodeConfig surfaceNodeConfig; 184 surfaceNodeConfig.SurfaceNodeName = "pointer window"; 185 screenpointer->surfaceNode_ = Rosen::RSSurfaceNode::Create(surfaceNodeConfig, 186 Rosen::RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE); 187 screenpointer->isCurrentOffScreenRendering_ = true; 188 screenpointer->mode_ = mode_t::SCREEN_MIRROR; 189 190 int32_t x = -1; 191 int32_t y = -1; 192 ICON_TYPE align = ICON_TYPE::ANGLE_N; 193 auto ret = screenpointer->MoveSoft(x, y, align); 194 EXPECT_TRUE(ret); 195 } 196 197 /** 198 * @tc.name: ScreenPointerTest_Move_001 199 * @tc.desc: Test Move 200 * @tc.type: Function 201 * @tc.require: 202 */ 203 HWTEST_F(ScreenPointerTest, ScreenPointerTest_Move_001, 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 OLD::DisplayInfo di; 210 ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di); 211 ASSERT_NE(screenpointer, nullptr); 212 PointerRenderer renderer; 213 ASSERT_TRUE(screenpointer->Init(renderer)); 214 Rosen::RSSurfaceNodeConfig surfaceNodeConfig; 215 surfaceNodeConfig.SurfaceNodeName = "pointer window"; 216 screenpointer->surfaceNode_ = Rosen::RSSurfaceNode::Create(surfaceNodeConfig, 217 Rosen::RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE); 218 ASSERT_NE(screenpointer->surfaceNode_, nullptr); 219 screenpointer->mode_ = mode_t::SCREEN_MIRROR; 220 screenpointer->isCurrentOffScreenRendering_ = true; 221 ICON_TYPE align = ANGLE_W; 222 int32_t x = 0; 223 int32_t y = 0; 224 bool ret = screenpointer->Move(x, y, align); 225 EXPECT_EQ(ret, hwcmgr->IsSupported()); 226 screenpointer->mode_ = mode_t::SCREEN_MAIN; 227 screenpointer->isCurrentOffScreenRendering_ = true; 228 ret = screenpointer->Move(x, y, align); 229 EXPECT_EQ(ret, hwcmgr->IsSupported()); 230 screenpointer->mode_ = mode_t::SCREEN_MAIN; 231 screenpointer->isWindowRotation_ = true; 232 ret = screenpointer->Move(x, y, align); 233 EXPECT_EQ(ret, hwcmgr->IsSupported()); 234 screenpointer->mode_ = mode_t::SCREEN_EXTEND; 235 screenpointer->isCurrentOffScreenRendering_ = false; 236 ret = screenpointer->Move(x, y, align); 237 EXPECT_EQ(ret, hwcmgr->IsSupported()); 238 screenpointer->mode_ = mode_t::SCREEN_MIRROR; 239 screenpointer->isCurrentOffScreenRendering_ = false; 240 ret = screenpointer->Move(x, y, align); 241 EXPECT_EQ(ret, hwcmgr->IsSupported()); 242 } 243 244 /** 245 * @tc.name: ScreenPointerTest_Move_002 246 * @tc.desc: Test Move 247 * @tc.type: Function 248 * @tc.require: 249 */ 250 HWTEST_F(ScreenPointerTest, ScreenPointerTest_Move_002, TestSize.Level1) 251 { 252 CALL_TEST_DEBUG; 253 hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>(); 254 ASSERT_NE(hwcmgr, nullptr); 255 handler_ptr_t handler = nullptr; 256 OLD::DisplayInfo di; 257 ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di); 258 ASSERT_NE(screenpointer, nullptr); 259 PointerRenderer renderer; 260 ASSERT_TRUE(screenpointer->Init(renderer)); 261 Rosen::RSSurfaceNodeConfig surfaceNodeConfig; 262 surfaceNodeConfig.SurfaceNodeName = "pointer window"; 263 screenpointer->surfaceNode_ = Rosen::RSSurfaceNode::Create(surfaceNodeConfig, 264 Rosen::RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE); 265 ASSERT_NE(screenpointer->surfaceNode_, nullptr); 266 screenpointer->mode_ = mode_t::SCREEN_MIRROR; 267 screenpointer->isWindowRotation_ = true; 268 ICON_TYPE align = ANGLE_W; 269 int32_t x = 0; 270 int32_t y = 0; 271 bool ret = screenpointer->Move(x, y, align); 272 EXPECT_FALSE(ret); 273 screenpointer->mode_ = mode_t::SCREEN_MAIN; 274 screenpointer->isWindowRotation_ = true; 275 ret = screenpointer->Move(x, y, align); 276 EXPECT_FALSE(ret); 277 x = -1; 278 y = -1; 279 ret = screenpointer->Move(x, y, align); 280 EXPECT_FALSE(ret); 281 } 282 283 /** 284 * @tc.name: ScreenPointerTest_Move_003 285 * @tc.desc: Test Move 286 * @tc.type: Function 287 * @tc.require: 288 */ 289 HWTEST_F(ScreenPointerTest, ScreenPointerTest_Move_003, TestSize.Level1) 290 { 291 CALL_TEST_DEBUG; 292 hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>(); 293 ASSERT_NE(hwcmgr, nullptr); 294 handler_ptr_t handler = nullptr; 295 OLD::DisplayInfo di; 296 ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di); 297 ASSERT_NE(screenpointer, nullptr); 298 PointerRenderer renderer; 299 ASSERT_TRUE(screenpointer->Init(renderer)); 300 Rosen::RSSurfaceNodeConfig surfaceNodeConfig; 301 surfaceNodeConfig.SurfaceNodeName = "pointer window"; 302 screenpointer->surfaceNode_ = Rosen::RSSurfaceNode::Create(surfaceNodeConfig, 303 Rosen::RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE); 304 ASSERT_NE(screenpointer->surfaceNode_, nullptr); 305 screenpointer->mode_ = mode_t::SCREEN_MIRROR; 306 screenpointer->isCurrentOffScreenRendering_ = true; 307 ICON_TYPE align = ANGLE_W; 308 int32_t x = 0; 309 int32_t y = 0; 310 screenpointer->SetVirtualExtend(true); 311 bool ret = screenpointer->Move(x, y, align); 312 EXPECT_TRUE(ret); 313 } 314 315 /** 316 * @tc.name: ScreenPointerTest_Rotate_001 317 * @tc.desc: Test Rotate 318 * @tc.type: Function 319 * @tc.require: 320 */ 321 HWTEST_F(ScreenPointerTest, ScreenPointerTest_Rotate_001, TestSize.Level1) 322 { 323 CALL_TEST_DEBUG; 324 hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>(); 325 ASSERT_NE(hwcmgr, nullptr); 326 handler_ptr_t handler = nullptr; 327 OLD::DisplayInfo di; 328 ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di); 329 ASSERT_NE(screenpointer, nullptr); 330 int32_t x = 0; 331 int32_t y = 0; 332 rotation_t rotation = rotation_t(DIRECTION90); 333 screenpointer->mode_ = mode_t::SCREEN_MIRROR; 334 screenpointer->rotation_ = rotation_t::ROTATION_0; 335 EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); 336 screenpointer->rotation_ = rotation_t::ROTATION_90; 337 EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); 338 screenpointer->rotation_ = rotation_t::ROTATION_180; 339 EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); 340 screenpointer->rotation_ = rotation_t::ROTATION_270; 341 EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); 342 screenpointer->mode_ = mode_t::SCREEN_MAIN; 343 screenpointer->rotation_ = rotation_t::ROTATION_0; 344 EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); 345 screenpointer->rotation_ = rotation_t::ROTATION_90; 346 EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); 347 screenpointer->rotation_ = rotation_t::ROTATION_180; 348 EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); 349 screenpointer->rotation_ = rotation_t::ROTATION_270; 350 EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); 351 } 352 353 /** 354 * @tc.name: ScreenPointerTest_Rotate_002 355 * @tc.desc: Test Rotate 356 * @tc.type: Function 357 * @tc.require: 358 */ 359 HWTEST_F(ScreenPointerTest, ScreenPointerTest_Rotate_002, TestSize.Level1) 360 { 361 CALL_TEST_DEBUG; 362 hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>(); 363 ASSERT_NE(hwcmgr, nullptr); 364 handler_ptr_t handler = nullptr; 365 OLD::DisplayInfo di; 366 ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di); 367 ASSERT_NE(screenpointer, nullptr); 368 int32_t x = 0; 369 int32_t y = 0; 370 screenpointer->mode_ = mode_t::SCREEN_MAIN; 371 screenpointer->rotation_ = rotation_t::ROTATION_180; 372 rotation_t rotation = rotation_t(DIRECTION90); 373 EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); 374 rotation = rotation_t(DIRECTION180); 375 EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); 376 rotation = rotation_t(DIRECTION270); 377 EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); 378 rotation = rotation_t(DIRECTION0); 379 EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); 380 } 381 382 /** 383 * @tc.name: ScreenPointerTest_Rotate_003 384 * @tc.desc: Test Rotate 385 * @tc.type: Function 386 * @tc.require: 387 */ 388 HWTEST_F(ScreenPointerTest, ScreenPointerTest_Rotate_003, TestSize.Level1) 389 { 390 CALL_TEST_DEBUG; 391 hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>(); 392 ASSERT_NE(hwcmgr, nullptr); 393 handler_ptr_t handler = nullptr; 394 OLD::DisplayInfo di; 395 ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di); 396 ASSERT_NE(screenpointer, nullptr); 397 int32_t x = 0; 398 int32_t y = 0; 399 screenpointer->mode_ = mode_t::SCREEN_MAIN; 400 screenpointer->rotation_ = rotation_t::ROTATION_0; 401 screenpointer->isWindowRotation_ = true; 402 screenpointer->displayDirection_ = DIRECTION90; 403 rotation_t rotation = rotation_t(DIRECTION90); 404 EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); 405 rotation = rotation_t(DIRECTION180); 406 EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); 407 rotation = rotation_t(DIRECTION270); 408 EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); 409 rotation = rotation_t(DIRECTION0); 410 EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); 411 screenpointer->displayDirection_ = DIRECTION270; 412 rotation = rotation_t(DIRECTION90); 413 EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); 414 rotation = rotation_t(DIRECTION180); 415 EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); 416 rotation = rotation_t(DIRECTION270); 417 EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); 418 rotation = rotation_t(DIRECTION0); 419 EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); 420 } 421 422 /** 423 * @tc.name: ScreenPointerTest_Rotate_004 424 * @tc.desc: Test Rotate 425 * @tc.type: Function 426 * @tc.require: 427 */ 428 HWTEST_F(ScreenPointerTest, ScreenPointerTest_Rotate_004, TestSize.Level1) 429 { 430 CALL_TEST_DEBUG; 431 hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>(); 432 ASSERT_NE(hwcmgr, nullptr); 433 handler_ptr_t handler = nullptr; 434 OLD::DisplayInfo di; 435 ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di); 436 ASSERT_NE(screenpointer, nullptr); 437 int32_t x = 0; 438 int32_t y = 0; 439 screenpointer->mode_ = mode_t::SCREEN_MIRROR; 440 screenpointer->rotation_ = rotation_t::ROTATION_0; 441 screenpointer->isWindowRotation_ = true; 442 screenpointer->displayDirection_ = DIRECTION90; 443 rotation_t rotation = rotation_t(DIRECTION90); 444 EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); 445 rotation = rotation_t(DIRECTION180); 446 EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); 447 rotation = rotation_t(DIRECTION270); 448 EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); 449 rotation = rotation_t(DIRECTION0); 450 EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); 451 screenpointer->displayDirection_ = DIRECTION270; 452 rotation = rotation_t(DIRECTION90); 453 EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); 454 rotation = rotation_t(DIRECTION180); 455 EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); 456 rotation = rotation_t(DIRECTION270); 457 EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); 458 rotation = rotation_t(DIRECTION0); 459 EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); 460 } 461 462 /** 463 * @tc.name: ScreenPointerTest_GetDefaultBuffer_001 464 * @tc.desc: Test GetDefaultBuffer 465 * @tc.type: Function 466 * @tc.require: 467 */ 468 HWTEST_F(ScreenPointerTest, ScreenPointerTest_GetDefaultBufferr_001, TestSize.Level1) 469 { 470 CALL_TEST_DEBUG; 471 hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>(); 472 ASSERT_NE(hwcmgr, nullptr); 473 handler_ptr_t handler = nullptr; 474 OLD::DisplayInfo di; 475 ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di); 476 ASSERT_NE(screenpointer, nullptr); 477 PointerRenderer renderer; 478 ASSERT_TRUE(screenpointer->Init(renderer)); 479 ASSERT_NE(screenpointer->GetDefaultBuffer(), nullptr); 480 delete screenpointer; 481 } 482 483 /** 484 * @tc.name: ScreenPointerTest_GetTransparentBuffer_001 485 * @tc.desc: Test GetTransparentBuffer 486 * @tc.type: Function 487 * @tc.require: 488 */ 489 HWTEST_F(ScreenPointerTest, ScreenPointerTest_GetTransparentBuffer_001, TestSize.Level1) 490 { 491 CALL_TEST_DEBUG; 492 hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>(); 493 ASSERT_NE(hwcmgr, nullptr); 494 handler_ptr_t handler = nullptr; 495 OLD::DisplayInfo di; 496 ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di); 497 ASSERT_NE(screenpointer, nullptr); 498 PointerRenderer renderer; 499 ASSERT_TRUE(screenpointer->Init(renderer)); 500 ASSERT_NE(screenpointer->GetTransparentBuffer(), nullptr); 501 delete screenpointer; 502 } 503 504 /** 505 * @tc.name: ScreenPointerTest_GetCommonBuffer_001 506 * @tc.desc: Test GetCommonBuffer 507 * @tc.type: Function 508 * @tc.require: 509 */ 510 HWTEST_F(ScreenPointerTest, ScreenPointerTest_GetCommonBuffer_001, TestSize.Level1) 511 { 512 CALL_TEST_DEBUG; 513 hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>(); 514 ASSERT_NE(hwcmgr, nullptr); 515 handler_ptr_t handler = nullptr; 516 OLD::DisplayInfo di; 517 ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di); 518 ASSERT_NE(screenpointer, nullptr); 519 PointerRenderer renderer; 520 ASSERT_TRUE(screenpointer->Init(renderer)); 521 ASSERT_NE(screenpointer->GetCommonBuffer(), nullptr); 522 delete screenpointer; 523 } 524 525 /** 526 * @tc.name: ScreenPointerTest_GetCurrentBuffer_001 527 * @tc.desc: Test GetCurrentBuffer 528 * @tc.type: Function 529 * @tc.require: 530 */ 531 HWTEST_F(ScreenPointerTest, ScreenPointerTest_GetCurrentBuffer_001, TestSize.Level1) 532 { 533 CALL_TEST_DEBUG; 534 hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>(); 535 ASSERT_NE(hwcmgr, nullptr); 536 handler_ptr_t handler = nullptr; 537 OLD::DisplayInfo di; 538 ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di); 539 ASSERT_NE(screenpointer, nullptr); 540 PointerRenderer renderer; 541 ASSERT_TRUE(screenpointer->Init(renderer)); 542 ASSERT_NE(screenpointer->GetCurrentBuffer(), nullptr); 543 ASSERT_NE(screenpointer->GetTransparentBuffer(), nullptr); 544 ASSERT_NE(screenpointer->GetCurrentBuffer(), nullptr); 545 delete screenpointer; 546 } 547 548 /** 549 * @tc.name: ScreenPointerTest_RequestBuffer_001 550 * @tc.desc: Test RequestBuffer 551 * @tc.type: Function 552 * @tc.require: 553 */ 554 HWTEST_F(ScreenPointerTest, ScreenPointerTest_RequestBuffer_001, TestSize.Level1) 555 { 556 CALL_TEST_DEBUG; 557 hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>(); 558 ASSERT_NE(hwcmgr, nullptr); 559 handler_ptr_t handler = nullptr; 560 OLD::DisplayInfo di; 561 ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di); 562 ASSERT_NE(screenpointer, nullptr); 563 PointerRenderer renderer; 564 ASSERT_TRUE(screenpointer->Init(renderer)); 565 screenpointer->bufferId_ = 5; 566 bool isCommonBuffer; 567 const RenderConfig cfg = { 568 .style_ = TRANSPARENT_ICON, 569 }; 570 ASSERT_NE(screenpointer->RequestBuffer(cfg, isCommonBuffer), nullptr); 571 ASSERT_FALSE(isCommonBuffer); 572 ASSERT_NE(screenpointer->GetCurrentBuffer(), nullptr); 573 delete screenpointer; 574 } 575 576 /** 577 * @tc.name: ScreenPointerTest_RequestBuffer_002 578 * @tc.desc: Test RequestBuffer 579 * @tc.type: Function 580 * @tc.require: 581 */ 582 HWTEST_F(ScreenPointerTest, ScreenPointerTest_RequestBuffer_002, TestSize.Level1) 583 { 584 CALL_TEST_DEBUG; 585 hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>(); 586 ASSERT_NE(hwcmgr, nullptr); 587 handler_ptr_t handler = nullptr; 588 OLD::DisplayInfo di; 589 ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di); 590 ASSERT_NE(screenpointer, nullptr); 591 PointerRenderer renderer; 592 ASSERT_TRUE(screenpointer->Init(renderer)); 593 screenpointer->bufferId_ = 5; 594 RenderConfig defaultCursorCfg { 595 .style_ = MOUSE_ICON::DEFAULT, 596 .align_ = ICON_TYPE::ANGLE_NW, 597 .path_ = "/system/etc/multimodalinput/mouse_icon/Default.svg", 598 .color = 0, 599 .size = 1, 600 .direction = Direction::DIRECTION0, 601 .dpi = screenpointer->GetDPI() * screenpointer->GetScale(), 602 .isHard = true, 603 }; 604 if (OHOS::system::GetParameter("const.build.product", "HYM") == DEVICE_TYPE_FOLD_PC) { 605 defaultCursorCfg.size = 2; 606 } 607 bool isCommoBuffer; 608 ASSERT_TRUE(screenpointer->IsDefaultCfg(defaultCursorCfg)); 609 ASSERT_NE(screenpointer->RequestBuffer(defaultCursorCfg, isCommoBuffer), nullptr); 610 ASSERT_FALSE(isCommoBuffer); 611 ASSERT_NE(screenpointer->GetCurrentBuffer(), nullptr); 612 delete screenpointer; 613 } 614 615 /** 616 * @tc.name: ScreenPointerTest_UpdatePadding_001 617 * @tc.desc: Test UpdatePadding 618 * @tc.type: Function 619 * @tc.require: 620 */ 621 HWTEST_F(ScreenPointerTest, ScreenPointerTest_UpdatePadding_001, TestSize.Level1) 622 { 623 CALL_TEST_DEBUG; 624 hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>(); 625 ASSERT_NE(hwcmgr, nullptr); 626 handler_ptr_t handler = nullptr; 627 OLD::DisplayInfo di; 628 ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di); 629 ASSERT_NE(screenpointer, nullptr); 630 screenpointer->mode_ = mode_t::SCREEN_MAIN; 631 uint32_t mainWidth = 0; 632 uint32_t mainHeight = 0; 633 bool ret = screenpointer->UpdatePadding(mainWidth, mainHeight); 634 EXPECT_FALSE(ret); 635 screenpointer->mode_ = mode_t::SCREEN_MIRROR; 636 mainWidth = 0; 637 mainHeight = 0; 638 ret = screenpointer->UpdatePadding(mainWidth, mainHeight); 639 EXPECT_FALSE(ret); 640 mainWidth = 0; 641 mainHeight = 5; 642 ret = screenpointer->UpdatePadding(mainWidth, mainHeight); 643 EXPECT_FALSE(ret); 644 mainWidth = 5; 645 mainHeight = 0; 646 ret = screenpointer->UpdatePadding(mainWidth, mainHeight); 647 EXPECT_FALSE(ret); 648 mainWidth = 5; 649 mainHeight = 5; 650 screenpointer->rotation_ = rotation_t::ROTATION_90; 651 ret = screenpointer->UpdatePadding(mainWidth, mainHeight); 652 EXPECT_TRUE(ret); 653 screenpointer->rotation_ = rotation_t::ROTATION_180; 654 ret = screenpointer->UpdatePadding(mainWidth, mainHeight); 655 EXPECT_TRUE(ret); 656 screenpointer->rotation_ = rotation_t::ROTATION_270; 657 ret = screenpointer->UpdatePadding(mainWidth, mainHeight); 658 EXPECT_TRUE(ret); 659 } 660 661 /** 662 * @tc.name: ScreenPointerTest_OnDisplayInfo_001 663 * @tc.desc: Test OnDisplayInfo 664 * @tc.type: Function 665 * @tc.require: 666 */ 667 HWTEST_F(ScreenPointerTest, ScreenPointerTest_OnDisplayInfo_001, TestSize.Level1) 668 { 669 CALL_TEST_DEBUG; 670 hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>(); 671 ASSERT_NE(hwcmgr, nullptr); 672 handler_ptr_t handler = nullptr; 673 OLD::DisplayInfo di; 674 di.id = 1; 675 ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di); 676 ASSERT_NE(screenpointer, nullptr); 677 screenpointer->bufferId_ = 5; 678 EXPECT_NO_FATAL_FAILURE(screenpointer->OnDisplayInfo(di, false)); 679 screenpointer->bufferId_ = 1; 680 screenpointer->isCurrentOffScreenRendering_ = true; 681 EXPECT_NO_FATAL_FAILURE(screenpointer->OnDisplayInfo(di, false)); 682 screenpointer->isCurrentOffScreenRendering_ = false; 683 EXPECT_NO_FATAL_FAILURE(screenpointer->OnDisplayInfo(di, false)); 684 685 screenpointer->screenId_ = 1; 686 EXPECT_NO_FATAL_FAILURE(screenpointer->OnDisplayInfo(di, false)); 687 } 688 689 /** 690 * @tc.name: ScreenPointerTest_ScreenPointer_001 691 * @tc.desc: Test ScreenPointer 692 * @tc.type: Function 693 * @tc.require: 694 */ 695 HWTEST_F(ScreenPointerTest, ScreenPointerTest_ScreenPointer_001, TestSize.Level1) 696 { 697 CALL_TEST_DEBUG; 698 hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>(); 699 ASSERT_NE(hwcmgr, nullptr); 700 handler_ptr_t handler = nullptr; 701 OLD::DisplayInfo di; 702 di.id = 1; 703 ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di); 704 screenpointer->rotation_ = rotation_t::ROTATION_90; 705 ScreenPointer(hwcmgr, handler, di); 706 screenpointer->rotation_ = rotation_t::ROTATION_180; 707 ScreenPointer(hwcmgr, handler, di); 708 screenpointer->rotation_ = rotation_t::ROTATION_270; 709 ScreenPointer(hwcmgr, handler, di); 710 } 711 712 /** 713 * @tc.name: ScreenPointerTest_ScreenPointer_002 714 * @tc.desc: Test ScreenPointer 715 * @tc.type: Function 716 * @tc.require: 717 */ 718 HWTEST_F(ScreenPointerTest, ScreenPointerTest_ScreenPointer_002, TestSize.Level1) 719 { 720 CALL_TEST_DEBUG; 721 hwcmgr_ptr_t hwcmgr = nullptr; 722 handler_ptr_t handler = nullptr; 723 OLD::DisplayInfo di; 724 di.width = 5; 725 di.height = 6; 726 di.direction = Direction::DIRECTION90; 727 ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di); 728 ASSERT_NE(screenpointer, nullptr); 729 730 EXPECT_EQ(screenpointer->width_, di.height); 731 EXPECT_EQ(screenpointer->height_, di.width); 732 } 733 734 /** 735 * @tc.name: ScreenPointerTest_ScreenPointer_003 736 * @tc.desc: Test ScreenPointer 737 * @tc.type: Function 738 * @tc.require: 739 */ 740 HWTEST_F(ScreenPointerTest, ScreenPointerTest_ScreenPointer_003, TestSize.Level1) 741 { 742 CALL_TEST_DEBUG; 743 hwcmgr_ptr_t hwcmgr = nullptr; 744 handler_ptr_t handler = nullptr; 745 OLD::DisplayInfo di; 746 di.width = 5; 747 di.height = 6; 748 di.direction = Direction::DIRECTION270; 749 ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di); 750 ASSERT_NE(screenpointer, nullptr); 751 752 EXPECT_EQ(screenpointer->width_, di.height); 753 EXPECT_EQ(screenpointer->height_, di.width); 754 755 PointerRenderer render; 756 ASSERT_TRUE(screenpointer->Init(render)); 757 delete screenpointer; 758 } 759 760 /** 761 * @tc.name: ScreenPointerTest_IsPositionOutScreen_001 762 * @tc.desc: Test IsPositionOutScreen 763 * @tc.type: Function 764 * @tc.require: 765 */ 766 HWTEST_F(ScreenPointerTest, ScreenPointerTest_IsPositionOutScreen_001, TestSize.Level1) 767 { 768 CALL_TEST_DEBUG; 769 hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>(); 770 ASSERT_NE(hwcmgr, nullptr); 771 handler_ptr_t handler = nullptr; 772 OLD::DisplayInfo di; 773 di.id = 1; 774 ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di); 775 screenpointer->isCurrentOffScreenRendering_ = false; 776 777 int32_t x = -1; 778 int32_t y = -1; 779 auto ret = screenpointer->IsPositionOutScreen(x, y); 780 EXPECT_TRUE(ret); 781 782 x = 1; 783 ret = screenpointer->IsPositionOutScreen(x, y); 784 EXPECT_TRUE(ret); 785 786 y = 1; 787 screenpointer->width_ = 0; 788 ret = screenpointer->IsPositionOutScreen(x, y); 789 EXPECT_TRUE(ret); 790 791 screenpointer->width_ = 2; 792 screenpointer->height_ = 0; 793 ret = screenpointer->IsPositionOutScreen(x, y); 794 EXPECT_TRUE(ret); 795 796 screenpointer->height_ = 2; 797 ret = screenpointer->IsPositionOutScreen(x, y); 798 EXPECT_FALSE(ret); 799 } 800 801 /** 802 * @tc.name: ScreenPointerTest_IsPositionOutScreen_002 803 * @tc.desc: Test IsPositionOutScreen 804 * @tc.type: Function 805 * @tc.require: 806 */ 807 HWTEST_F(ScreenPointerTest, ScreenPointerTest_IsPositionOutScreen_002, TestSize.Level1) 808 { 809 CALL_TEST_DEBUG; 810 hwcmgr_ptr_t hwcmgr = std::make_shared<HardwareCursorPointerManager>(); 811 ASSERT_NE(hwcmgr, nullptr); 812 handler_ptr_t handler = nullptr; 813 OLD::DisplayInfo di; 814 di.id = 1; 815 ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di); 816 screenpointer->isCurrentOffScreenRendering_ = true; 817 screenpointer->mode_ = mode_t::SCREEN_MIRROR; 818 819 int32_t x = -1; 820 int32_t y = -1; 821 auto ret = screenpointer->IsPositionOutScreen(x, y); 822 EXPECT_TRUE(ret); 823 824 screenpointer->mode_ = mode_t::SCREEN_MAIN; 825 screenpointer->offRenderScale_ = 2.0; 826 ret = screenpointer->IsPositionOutScreen(x, y); 827 EXPECT_TRUE(ret); 828 } 829 } // namespace MMI 830 } // namespace OHOS