1/* 2 * Copyright (c) 2022 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 <gtest/gtest.h> 16 17#include "display_manager.h" 18#include "display_manager_config.h" 19#include "future.h" 20#include "wm_math.h" 21#include "window_node.h" 22#include "window_node_container.h" 23 24using namespace testing; 25using namespace testing::ext; 26 27namespace OHOS { 28namespace Rosen { 29class WindowNodeTest : public testing::Test { 30public: 31 static void SetUpTestCase(); 32 static void TearDownTestCase(); 33 virtual void SetUp() override; 34 virtual void TearDown() override; 35}; 36 37void WindowNodeTest::SetUpTestCase() 38{ 39} 40 41void WindowNodeTest::TearDownTestCase() 42{ 43} 44 45void WindowNodeTest::SetUp() 46{ 47} 48 49void WindowNodeTest::TearDown() 50{ 51} 52class WindowListener : public IWindow { 53public: 54 virtual WMError UpdateWindowRect(const struct Rect& rect, bool decoStatus, WindowSizeChangeReason reason, 55 const std::shared_ptr<RSTransaction>& rsTransaction = nullptr) override 56 { 57 return WMError::WM_OK; 58 }; 59 virtual WMError UpdateWindowMode(WindowMode mode) override 60 { 61 return WMError::WM_OK; 62 }; 63 virtual WMError UpdateWindowModeSupportInfo(uint32_t modeSupportInfo) override 64 { 65 return WMError::WM_OK; 66 }; 67 virtual WMError UpdateFocusStatus(bool focused) override 68 { 69 return WMError::WM_OK; 70 }; 71 virtual WMError UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType type) override 72 { 73 return WMError::WM_OK; 74 }; 75 virtual WMError UpdateWindowState(WindowState state) override 76 { 77 return WMError::WM_OK; 78 }; 79 virtual WMError UpdateWindowDragInfo(const PointInfo& point, DragEvent event) override 80 { 81 return WMError::WM_OK; 82 }; 83 virtual WMError UpdateDisplayId(DisplayId from, DisplayId to) override 84 { 85 return WMError::WM_OK; 86 }; 87 virtual WMError UpdateOccupiedAreaChangeInfo(const sptr<OccupiedAreaChangeInfo>& info, 88 const std::shared_ptr<RSTransaction>& rsTransaction = nullptr) override 89 { 90 return WMError::WM_OK; 91 }; 92 virtual WMError UpdateOccupiedAreaAndRect(const sptr<OccupiedAreaChangeInfo>& info, const Rect& rect, 93 const std::shared_ptr<RSTransaction>& rsTransaction = nullptr) override 94 { 95 return WMError::WM_OK; 96 }; 97 virtual WMError UpdateActiveStatus(bool isActive) override 98 { 99 return WMError::WM_OK; 100 }; 101 virtual sptr<WindowProperty> GetWindowProperty() override 102 { 103 return nullptr; 104 }; 105 virtual WMError NotifyTouchOutside() override 106 { 107 return WMError::WM_OK; 108 }; 109 virtual WMError NotifyScreenshot() override 110 { 111 return WMError::WM_OK; 112 }; 113 virtual WMError DumpInfo(const std::vector<std::string>& params) override 114 { 115 return WMError::WM_OK; 116 }; 117 virtual WMError NotifyDestroy(void) override 118 { 119 return WMError::WM_OK; 120 }; 121 WMError NotifyForeground(void) override 122 { 123 return WMError::WM_OK; 124 }; 125 WMError NotifyBackground(void) override 126 { 127 return WMError::WM_OK; 128 }; 129 virtual WMError NotifyWindowClientPointUp(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) override 130 { 131 return WMError::WM_OK; 132 }; 133 WMError UpdateZoomTransform(const Transform& trans, bool isDisplayZoomOn) override 134 { 135 return WMError::WM_OK; 136 }; 137 virtual WMError RestoreSplitWindowMode(uint32_t mode) override 138 { 139 return WMError::WM_OK; 140 }; 141 142 virtual sptr<IRemoteObject> AsObject() override 143 { 144 return nullptr; 145 }; 146 void ConsumeKeyEvent(std::shared_ptr<MMI::KeyEvent> event) override {} 147 void NotifyForegroundInteractiveStatus(bool interactive) override {} 148}; 149 150sptr<WindowProperty> CreateWindowProperty(uint32_t windowId, const std::string& windowName) 151{ 152 sptr<WindowProperty> property = new WindowProperty(); 153 property->SetWindowId(windowId); 154 property->SetWindowName(windowName); 155 return property; 156} 157 158RSSurfaceNode::SharedPtr CreateRSSurfaceNode(std::string windowNode) 159{ 160 struct RSSurfaceNodeConfig rsSurfaceNodeConfig; 161 rsSurfaceNodeConfig.SurfaceNodeName = windowNode; 162 auto surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig); 163 return surfaceNode; 164} 165namespace { 166/** 167 * @tc.name: NewWindowNode01 168 * @tc.desc: new window node with WindowProperty 169 * @tc.type: FUNC 170 */ 171HWTEST_F(WindowNodeTest, NewWindowNode01, Function | SmallTest | Level3) 172{ 173 std::string windowName = "WindowNode01"; 174 auto property = CreateWindowProperty(1, windowName); 175 ASSERT_NE(nullptr, property); 176 177 sptr<WindowNode> windowNode2 = new WindowNode(property); 178 windowNode2->SetWindowProperty(property); 179 ASSERT_NE(nullptr, windowNode2); 180 ASSERT_EQ(windowName, windowNode2->GetWindowName()); 181} 182/** 183 * @tc.name: NewWindowNode02 184 * @tc.desc: new window node with WindowProperty, RSSurfaceNode, IWindow 185 * @tc.type: FUNC 186 */ 187HWTEST_F(WindowNodeTest, NewWindowNode02, Function | SmallTest | Level1) 188{ 189 std::string windowName = "WindowNode02"; 190 auto property = CreateWindowProperty(2, windowName); 191 ASSERT_NE(nullptr, property); 192 193 auto surfaceNode = CreateRSSurfaceNode(windowName); 194 ASSERT_NE(nullptr, surfaceNode); 195 196 WindowListener* iWindow = new WindowListener(); 197 ASSERT_NE(nullptr, iWindow); 198 199 sptr<WindowNode> windowNode = new WindowNode(property, iWindow, surfaceNode); 200 ASSERT_NE(nullptr, windowNode); 201 windowNode->SetWindowProperty(property); 202 ASSERT_EQ(windowName, windowNode->GetWindowName()); 203} 204/** 205 * @tc.name: NewWindowNode03 206 * @tc.desc: new window node with WindowProperty, RSSurfaceNode, IWindow, pid , uid 207 * @tc.type: FUNC 208 */ 209HWTEST_F(WindowNodeTest, NewWindowNode03, Function | SmallTest | Level1) 210{ 211 std::string windowName = "WindowNode03"; 212 auto property = CreateWindowProperty(3, windowName); 213 ASSERT_NE(nullptr, property); 214 auto surfaceNode = CreateRSSurfaceNode(windowName); 215 ASSERT_NE(nullptr, surfaceNode); 216 sptr<WindowListener> iWindow = new Rosen::WindowListener(); 217 ASSERT_NE(nullptr, iWindow); 218 219 int32_t pid = 1; 220 int32_t uid = 2; 221 WindowNode* windowNode = new WindowNode(property, iWindow, surfaceNode, pid, uid); 222 windowNode->SetWindowProperty(property); 223 ASSERT_NE(nullptr, windowNode); 224 225 ASSERT_EQ(0, windowNode->GetInputEventCallingPid()); 226 ASSERT_EQ(2, windowNode->GetCallingPid()); 227 ASSERT_EQ(0, windowNode->GetCallingUid()); 228} 229 230/** 231 * @tc.name: SetDisplayId01 232 * @tc.desc: SetDisplayId & GetDisplayId 233 * @tc.type: FUNC 234 */ 235HWTEST_F(WindowNodeTest, SetDisplayId01, Function | SmallTest | Level1) 236{ 237 std::string windowName = "WindowNode04"; 238 auto property = CreateWindowProperty(4, windowName); 239 ASSERT_NE(nullptr, property); 240 241 WindowNode* windowNode = new WindowNode(property); 242 windowNode->SetWindowProperty(property); 243 ASSERT_NE(nullptr, windowNode); 244 ASSERT_EQ(0, windowNode->GetDisplayId()); 245 246 windowNode->SetDisplayId(1); 247 ASSERT_EQ(1, windowNode->GetDisplayId()); 248} 249 250/** 251 * @tc.name: SetEntireWindowTouchHotArea01 252 * @tc.desc: SetEntireWindowTouchHotArea & GetEntireWindowTouchHotArea 253 * @tc.type: FUNC 254 */ 255HWTEST_F(WindowNodeTest, SetEntireWindowTouchHotArea01, Function | SmallTest | Level1) 256{ 257 std::string windowName = "WindowNode05"; 258 auto property = CreateWindowProperty(5, windowName); 259 ASSERT_NE(nullptr, property); 260 261 sptr<WindowNode> windowNode = new WindowNode(property); 262 ASSERT_NE(nullptr, windowNode); 263 windowNode->SetWindowProperty(property); 264 265 ASSERT_EQ(0, windowNode->GetEntireWindowTouchHotArea().posX_); 266 ASSERT_EQ(0, windowNode->GetEntireWindowTouchHotArea().posY_); 267 ASSERT_EQ(0, windowNode->GetEntireWindowTouchHotArea().width_); 268 ASSERT_EQ(0, windowNode->GetEntireWindowTouchHotArea().height_); 269 270 Rect testValue = { 10, 10, 255, 255 }; 271 windowNode->SetEntireWindowTouchHotArea(testValue); 272 ASSERT_EQ(testValue.posX_, windowNode->GetEntireWindowTouchHotArea().posX_); 273 ASSERT_EQ(testValue.posY_, windowNode->GetEntireWindowTouchHotArea().posY_); 274 ASSERT_EQ(testValue.width_, windowNode->GetEntireWindowTouchHotArea().width_); 275 ASSERT_EQ(testValue.height_, windowNode->GetEntireWindowTouchHotArea().height_); 276} 277/** 278 * @tc.name: SetEntireWindowPointerHotArea01 279 * @tc.desc: SetEntireWindowPointerHotArea & GetEntireWindowPointerHotArea 280 * @tc.type: FUNC 281 */ 282HWTEST_F(WindowNodeTest, SetEntireWindowPointerHotArea01, Function | SmallTest | Level1) 283{ 284 std::string windowName = "WindowNode06"; 285 auto property = CreateWindowProperty(6, windowName); 286 ASSERT_NE(nullptr, property); 287 288 sptr<WindowNode> windowNode = new WindowNode(property); 289 ASSERT_NE(nullptr, windowNode); 290 windowNode->SetWindowProperty(property); 291 292 Rect rect1 = {0, 0, 0, 0}; 293 windowNode->SetEntireWindowPointerHotArea(rect1); 294 ASSERT_EQ(0, windowNode->GetEntireWindowPointerHotArea().posX_); 295 ASSERT_EQ(0, windowNode->GetEntireWindowPointerHotArea().posY_); 296 ASSERT_EQ(0, windowNode->GetEntireWindowPointerHotArea().width_); 297 ASSERT_EQ(0, windowNode->GetEntireWindowPointerHotArea().height_); 298 299 Rect rect2 = {10, 10, 255, 255}; 300 windowNode->SetEntireWindowPointerHotArea(rect2); 301 ASSERT_EQ(10, windowNode->GetEntireWindowPointerHotArea().posX_); 302 ASSERT_EQ(10, windowNode->GetEntireWindowPointerHotArea().posY_); 303 ASSERT_EQ(255, windowNode->GetEntireWindowPointerHotArea().width_); 304 ASSERT_EQ(255, windowNode->GetEntireWindowPointerHotArea().height_); 305} 306/** 307 * @tc.name: SetWindowRect01 308 * @tc.desc: SetWindowRect & GetWindowRect 309 * @tc.type: FUNC 310 */ 311HWTEST_F(WindowNodeTest, SetWindowRect01, Function | SmallTest | Level1) 312{ 313 std::string windowName = "WindowNode07"; 314 auto property = CreateWindowProperty(7, windowName); 315 ASSERT_NE(nullptr, property); 316 317 sptr<WindowNode> windowNode = new WindowNode(property); 318 ASSERT_NE(nullptr, windowNode); 319 320 Rect rect1 = {0, 0, 0, 0}; 321 windowNode->SetWindowProperty(property); 322 windowNode->SetWindowRect(rect1); 323 ASSERT_EQ(0, windowNode->GetWindowRect().posX_); 324 ASSERT_EQ(0, windowNode->GetWindowRect().posY_); 325 ASSERT_EQ(0, windowNode->GetWindowRect().width_); 326 ASSERT_EQ(0, windowNode->GetWindowRect().height_); 327 328 Rect rect2 = {10, 10, 255, 255}; 329 windowNode->SetWindowRect(rect2); 330 ASSERT_EQ(10, windowNode->GetWindowRect().posX_); 331 ASSERT_EQ(10, windowNode->GetWindowRect().posY_); 332 ASSERT_EQ(255, windowNode->GetWindowRect().width_); 333 ASSERT_EQ(255, windowNode->GetWindowRect().height_); 334} 335/** 336 * @tc.name: SetDecoStatus01 337 * @tc.desc: SetDecoStatus & GetDecoStatus 338 * @tc.type: FUNC 339 */ 340HWTEST_F(WindowNodeTest, SetDecoStatus01, Function | SmallTest | Level1) 341{ 342 std::string windowName = "WindowNode08"; 343 auto property = CreateWindowProperty(8, windowName); 344 ASSERT_NE(nullptr, property); 345 sptr<WindowNode> windowNode = new WindowNode(property); 346 ASSERT_NE(nullptr, windowNode); 347 348 windowNode->SetWindowProperty(property); 349 windowNode->SetDecoStatus(true); 350 ASSERT_EQ(true, windowNode->GetDecoStatus()); 351 windowNode->SetDecoStatus(false); 352 ASSERT_EQ(false, windowNode->GetDecoStatus()); 353 354 windowNode->SetDecorEnable(true); 355 ASSERT_EQ(true, windowNode->GetWindowProperty()->GetDecorEnable()); 356 windowNode->SetDecorEnable(false); 357 ASSERT_EQ(false, windowNode->GetWindowProperty()->GetDecorEnable()); 358} 359/** 360 * @tc.name: SetRequestRect01 361 * @tc.desc: SetRequestRect & GetRequestRect 362 * @tc.type: FUNC 363 */ 364HWTEST_F(WindowNodeTest, SetRequestRect01, Function | SmallTest | Level1) 365{ 366 std::string windowName = "WindowNode09"; 367 auto property = CreateWindowProperty(9, windowName); 368 ASSERT_NE(nullptr, property); 369 sptr<WindowNode> windowNode = new WindowNode(property); 370 ASSERT_NE(nullptr, windowNode); 371 372 windowNode->SetWindowProperty(property); 373 Rect rect1 = { 0, 0, 0, 0 }; 374 windowNode->SetRequestRect(rect1); 375 ASSERT_EQ(0, windowNode->GetRequestRect().posX_); 376 ASSERT_EQ(0, windowNode->GetRequestRect().posY_); 377 ASSERT_EQ(0, windowNode->GetRequestRect().width_); 378 ASSERT_EQ(0, windowNode->GetRequestRect().height_); 379 380 Rect rect2 = { 10, 10, 255, 255 }; 381 windowNode->SetRequestRect(rect2); 382 ASSERT_EQ(10, windowNode->GetRequestRect().posX_); 383 ASSERT_EQ(10, windowNode->GetRequestRect().posY_); 384 ASSERT_EQ(255, windowNode->GetRequestRect().width_); 385 ASSERT_EQ(255, windowNode->GetRequestRect().height_); 386} 387/** 388 * @tc.name: SetWindowProperty01 389 * @tc.desc: SetWindowProperty & GetWindowProperty 390 * @tc.type: FUNC 391 */ 392HWTEST_F(WindowNodeTest, SetWindowProperty01, Function | SmallTest | Level1) 393{ 394 std::string windowName = "WindowNode09"; 395 auto property = CreateWindowProperty(9, windowName); 396 ASSERT_NE(nullptr, property); 397 sptr<WindowNode> windowNode = new WindowNode(property); 398 ASSERT_NE(nullptr, windowNode); 399 windowNode->SetWindowProperty(property); 400 ASSERT_EQ(property, windowNode->GetWindowProperty()); 401 402 auto property2 = CreateWindowProperty(10, windowName); 403 ASSERT_NE(nullptr, property2); 404 windowNode->SetWindowProperty(property2); 405 ASSERT_EQ(property2, windowNode->GetWindowProperty()); 406} 407/** 408 * @tc.name: SetSystemBarProperty01 409 * @tc.desc: SetSystemBarProperty & GetSystemBarProperty 410 * @tc.type: FUNC 411 */ 412HWTEST_F(WindowNodeTest, SetSystemBarProperty01, Function | SmallTest | Level1) 413{ 414 std::string windowName = "WindowNode10"; 415 auto property = CreateWindowProperty(10, windowName); 416 ASSERT_NE(nullptr, property); 417 sptr<WindowNode> windowNode = new WindowNode(property); 418 ASSERT_NE(nullptr, windowNode); 419 420 windowNode->SetWindowProperty(property); 421 SystemBarProperty systemBarProperty1; 422 SystemBarProperty systemBarProperty2; 423 SystemBarProperty systemBarProperty3; 424 windowNode->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, systemBarProperty1); 425 windowNode->SetSystemBarProperty(WindowType::WINDOW_TYPE_NAVIGATION_BAR, systemBarProperty2); 426 windowNode->SetSystemBarProperty(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, systemBarProperty3); 427 428 auto systemBarProperties = windowNode->GetSystemBarProperty(); 429 ASSERT_EQ(systemBarProperty1, systemBarProperties.find(WindowType::WINDOW_TYPE_STATUS_BAR)->second); 430 ASSERT_EQ(systemBarProperty2, systemBarProperties.find(WindowType::WINDOW_TYPE_NAVIGATION_BAR)->second); 431 ASSERT_EQ(systemBarProperties.end(), systemBarProperties.find(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW)); 432} 433/** 434 * @tc.name: SetWindowMode01 435 * @tc.desc: SetWindowMode & GetWindowMode 436 * @tc.type: FUNC 437 */ 438HWTEST_F(WindowNodeTest, SetWindowMode01, Function | SmallTest | Level1) 439{ 440 std::string windowName = "WindowNode11"; 441 auto property = CreateWindowProperty(11, windowName); 442 ASSERT_NE(nullptr, property); 443 sptr<WindowNode> windowNode = new WindowNode(property); 444 ASSERT_NE(nullptr, windowNode); 445 446 windowNode->SetWindowProperty(property); 447 ASSERT_EQ(WindowMode::WINDOW_MODE_UNDEFINED, windowNode->GetWindowMode()); 448 449 windowNode->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); 450 ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, windowNode->GetWindowMode()); 451} 452/** 453 * @tc.name: SetBrightness01 454 * @tc.desc: SetBrightness & GetBrightness 455 * @tc.type: FUNC 456 */ 457HWTEST_F(WindowNodeTest, SetBrightness01, Function | SmallTest | Level1) 458{ 459 std::string windowName = "WindowNode12"; 460 auto property = CreateWindowProperty(12, windowName); 461 ASSERT_NE(nullptr, property); 462 sptr<WindowNode> windowNode = new WindowNode(property); 463 ASSERT_NE(nullptr, windowNode); 464 465 windowNode->SetWindowProperty(property); 466 ASSERT_EQ(UNDEFINED_BRIGHTNESS, windowNode->GetBrightness()); 467 468 windowNode->SetBrightness(0.5f); 469 ASSERT_EQ(0.5f, windowNode->GetBrightness()); 470 windowNode->SetBrightness(1.1f); 471 ASSERT_EQ(1.1f, windowNode->GetBrightness()); 472} 473/** 474 * @tc.name: SetTurnScreenOn01 475 * @tc.desc: SetTurnScreenOn & IsTurnScreenOn 476 * @tc.type: FUNC 477 */ 478HWTEST_F(WindowNodeTest, SetTurnScreenOn01, Function | SmallTest | Level1) 479{ 480 std::string windowName = "WindowNode13"; 481 auto property = CreateWindowProperty(13, windowName); 482 ASSERT_NE(nullptr, property); 483 sptr<WindowNode> windowNode = new WindowNode(property); 484 ASSERT_NE(nullptr, windowNode); 485 windowNode->SetWindowProperty(property); 486 ASSERT_EQ(false, windowNode->IsTurnScreenOn()); 487 windowNode->SetTurnScreenOn(true); 488 ASSERT_EQ(true, windowNode->IsTurnScreenOn()); 489} 490/** 491 * @tc.name: SetKeepScreenOn01 492 * @tc.desc: SetKeepScreenOn & IsKeepScreenOn 493 * @tc.type: FUNC 494 */ 495HWTEST_F(WindowNodeTest, SetKeepScreenOn01, Function | SmallTest | Level1) 496{ 497 std::string windowName = "WindowNode14"; 498 auto property = CreateWindowProperty(14, windowName); 499 ASSERT_NE(nullptr, property); 500 sptr<WindowNode> windowNode = new WindowNode(property); 501 ASSERT_NE(nullptr, windowNode); 502 windowNode->SetWindowProperty(property); 503 ASSERT_EQ(false, windowNode->IsKeepScreenOn()); 504 windowNode->SetKeepScreenOn(true); 505 ASSERT_EQ(true, windowNode->IsKeepScreenOn()); 506} 507/** 508 * @tc.name: SetCallingWindow01 509 * @tc.desc: SetCallingWindow & GetCallingWindow 510 * @tc.type: FUNC 511 */ 512HWTEST_F(WindowNodeTest, SetCallingWindow01, Function | SmallTest | Level1) 513{ 514 std::string windowName = "WindowNode15"; 515 auto property = CreateWindowProperty(15, windowName); 516 ASSERT_NE(nullptr, property); 517 sptr<WindowNode> windowNode = new WindowNode(property); 518 ASSERT_NE(nullptr, windowNode); 519 windowNode->SetWindowProperty(property); 520 ASSERT_EQ(INVALID_WINDOW_ID, windowNode->GetCallingWindow()); 521 windowNode->SetCallingWindow(100); 522 ASSERT_EQ(100, windowNode->GetCallingWindow()); 523} 524/** 525 * @tc.name: SetCallingPid01 526 * @tc.desc: SetCallingPid & GetCallingPid, SetInputEventCallingPid & GetInputEventCallingPid 527 * @tc.type: FUNC 528 */ 529HWTEST_F(WindowNodeTest, SetCallingPid01, Function | SmallTest | Level1) 530{ 531 std::string windowName = "WindowNode16"; 532 auto property = CreateWindowProperty(16, windowName); 533 ASSERT_NE(nullptr, property); 534 sptr<WindowNode> windowNode = new WindowNode(property); 535 ASSERT_NE(nullptr, windowNode); 536 windowNode->SetWindowProperty(property); 537 ASSERT_EQ(0, windowNode->GetCallingPid()); 538 ASSERT_EQ(0, windowNode->GetInputEventCallingPid()); 539 540 windowNode->SetCallingPid(1); 541 ASSERT_EQ(1, windowNode->GetCallingPid()); 542 ASSERT_EQ(1, windowNode->GetInputEventCallingPid()); 543 544 windowNode->SetInputEventCallingPid(2); 545 ASSERT_EQ(1, windowNode->GetCallingPid()); 546 ASSERT_EQ(2, windowNode->GetInputEventCallingPid()); 547} 548/** 549 * @tc.name: SetCallingUid01 550 * @tc.desc: SetCallingUid & GetCallingUid 551 * @tc.type: FUNC 552 */ 553HWTEST_F(WindowNodeTest, SetCallingUid01, Function | SmallTest | Level1) 554{ 555 std::string windowName = "WindowNode17"; 556 auto property = CreateWindowProperty(17, windowName); 557 ASSERT_NE(nullptr, property); 558 sptr<WindowNode> windowNode = new WindowNode(property); 559 ASSERT_NE(nullptr, windowNode); 560 windowNode->SetWindowProperty(property); 561 562 ASSERT_EQ(0, windowNode->GetCallingUid()); 563 564 windowNode->SetCallingUid(1); 565 ASSERT_EQ(1, windowNode->GetCallingUid()); 566} 567/** 568 * @tc.name: SetWindowSizeChangeReason01 569 * @tc.desc: SetWindowSizeChangeReason & GetWindowSizeChangeReason & ResetWindowSizeChangeReason 570 * @tc.type: FUNC 571 */ 572HWTEST_F(WindowNodeTest, SetWindowSizeChangeReason01, Function | SmallTest | Level1) 573{ 574 std::string windowName = "WindowNode19"; 575 auto property = CreateWindowProperty(19, windowName); 576 ASSERT_NE(nullptr, property); 577 sptr<WindowNode> windowNode = new WindowNode(property); 578 ASSERT_NE(nullptr, windowNode); 579 windowNode->SetWindowProperty(property); 580 581 ASSERT_EQ(WindowSizeChangeReason::UNDEFINED, windowNode->GetWindowSizeChangeReason()); 582 windowNode->SetWindowSizeChangeReason(WindowSizeChangeReason::MAXIMIZE); 583 ASSERT_EQ(WindowSizeChangeReason::MAXIMIZE, windowNode->GetWindowSizeChangeReason()); 584 windowNode->ResetWindowSizeChangeReason(); 585 ASSERT_EQ(WindowSizeChangeReason::UNDEFINED, windowNode->GetWindowSizeChangeReason()); 586} 587/** 588 * @tc.name: SetRequestedOrientation01 589 * @tc.desc: SetRequestedOrientation & GetRequestedOrientation 590 * @tc.type: FUNC 591 */ 592HWTEST_F(WindowNodeTest, SetRequestedOrientation01, Function | SmallTest | Level1) 593{ 594 std::string windowName = "WindowNode20"; 595 auto property = CreateWindowProperty(20, windowName); 596 ASSERT_NE(nullptr, property); 597 sptr<WindowNode> windowNode = new WindowNode(property); 598 ASSERT_NE(nullptr, windowNode); 599 windowNode->SetWindowProperty(property); 600 ASSERT_EQ(Orientation::UNSPECIFIED, windowNode->GetRequestedOrientation()); 601 windowNode->SetRequestedOrientation(Orientation::REVERSE_VERTICAL); 602 ASSERT_EQ(Orientation::REVERSE_VERTICAL, windowNode->GetRequestedOrientation()); 603} 604/** 605 * @tc.name: SetShowingDisplays01 606 * @tc.desc: SetShowingDisplays & GetShowingDisplays 607 * @tc.type: FUNC 608 */ 609HWTEST_F(WindowNodeTest, SetShowingDisplays01, Function | SmallTest | Level1) 610{ 611 std::string windowName = "WindowNode21"; 612 auto property = CreateWindowProperty(21, windowName); 613 ASSERT_NE(nullptr, property); 614 sptr<WindowNode> windowNode = new WindowNode(property); 615 ASSERT_NE(nullptr, windowNode); 616 windowNode->SetWindowProperty(property); 617 618 auto displays = windowNode->GetShowingDisplays(); 619 ASSERT_EQ(true, displays.empty()); 620 621 std::vector<DisplayId> emptyDisplayIds; 622 windowNode->SetShowingDisplays(emptyDisplayIds); 623 ASSERT_EQ(true, windowNode->GetShowingDisplays().empty()); 624 625 displays.push_back(static_cast<DisplayId>(0)); 626 windowNode->SetShowingDisplays(displays); 627 ASSERT_EQ(1, windowNode->GetShowingDisplays().size()); 628} 629/** 630 * @tc.name: SetModeSupportInfo01 631 * @tc.desc: SetModeSupportInfo & GetModeSupportInfo 632 * @tc.type: FUNC 633 */ 634HWTEST_F(WindowNodeTest, SetModeSupportInfo01, Function | SmallTest | Level1) 635{ 636 std::string windowName = "WindowNode22"; 637 auto property = CreateWindowProperty(22, windowName); 638 ASSERT_NE(nullptr, property); 639 sptr<WindowNode> windowNode = new WindowNode(property); 640 ASSERT_NE(nullptr, windowNode); 641 windowNode->SetWindowProperty(property); 642 ASSERT_EQ(WindowModeSupport::WINDOW_MODE_SUPPORT_ALL, windowNode->GetModeSupportInfo()); 643 windowNode->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN); 644 ASSERT_EQ(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN, windowNode->GetModeSupportInfo()); 645} 646/** 647 * @tc.name: SetDragType01 648 * @tc.desc: SetDragType & GetDragType 649 * @tc.type: FUNC 650 */ 651HWTEST_F(WindowNodeTest, SetDragType01, Function | SmallTest | Level1) 652{ 653 std::string windowName = "WindowNode23"; 654 auto property = CreateWindowProperty(23, windowName); 655 ASSERT_NE(nullptr, property); 656 sptr<WindowNode> windowNode = new WindowNode(property); 657 ASSERT_NE(nullptr, windowNode); 658 windowNode->SetWindowProperty(property); 659 ASSERT_EQ(DragType::DRAG_UNDEFINED, windowNode->GetDragType()); 660 windowNode->SetDragType(DragType::DRAG_BOTTOM_OR_TOP); 661 ASSERT_EQ(DragType::DRAG_BOTTOM_OR_TOP, windowNode->GetDragType()); 662} 663/** 664 * @tc.name: SetOriginRect01 665 * @tc.desc: SetOriginRect & GetOriginRect 666 * @tc.type: FUNC 667 */ 668HWTEST_F(WindowNodeTest, SetOriginRect01, Function | SmallTest | Level1) 669{ 670 std::string windowName = "WindowNode24"; 671 auto property = CreateWindowProperty(24, windowName); 672 ASSERT_NE(nullptr, property); 673 sptr<WindowNode> windowNode = new WindowNode(property); 674 ASSERT_NE(nullptr, windowNode); 675 windowNode->SetWindowProperty(property); 676 auto defaultRect = windowNode->GetOriginRect(); 677 ASSERT_EQ(0, defaultRect.posX_); 678 ASSERT_EQ(0, defaultRect.posX_); 679 ASSERT_EQ(0, defaultRect.width_); 680 ASSERT_EQ(0, defaultRect.height_); 681 682 Rect testRect = { 10, 10, 150, 150 }; 683 windowNode->SetOriginRect(testRect); 684 auto resultRect = windowNode->GetOriginRect(); 685 ASSERT_EQ(testRect, resultRect); 686} 687/** 688 * @tc.name: SetTouchHotAreas01 689 * @tc.desc: SetTouchHotAreas & GetTouchHotAreas 690 * @tc.type: FUNC 691 */ 692HWTEST_F(WindowNodeTest, SetTouchHotAreas01, Function | SmallTest | Level1) 693{ 694 std::string windowName = "WindowNode25"; 695 auto property = CreateWindowProperty(25, windowName); 696 ASSERT_NE(nullptr, property); 697 sptr<WindowNode> windowNode = new WindowNode(property); 698 ASSERT_NE(nullptr, windowNode); 699 windowNode->SetWindowProperty(property); 700 std::vector<Rect> testRects; 701 windowNode->GetTouchHotAreas(testRects); 702 ASSERT_EQ(true, testRects.empty()); 703 704 Rect rect1 = { 10, 10, 10, 10 }; 705 testRects.push_back(rect1); 706 windowNode->SetTouchHotAreas(testRects); 707 708 std::vector<Rect> resultRect; 709 windowNode->GetTouchHotAreas(resultRect); 710 ASSERT_EQ(1, resultRect.size()); 711 ASSERT_EQ(rect1, resultRect[0]); 712} 713/** 714 * @tc.name: SetPointerHotAreas01 715 * @tc.desc: SetPointerHotAreas & GetPointerHotAreas 716 * @tc.type: FUNC 717 */ 718HWTEST_F(WindowNodeTest, SetPointerHotAreas01, Function | SmallTest | Level1) 719{ 720 std::string windowName = "WindowNode26"; 721 auto property = CreateWindowProperty(26, windowName); 722 ASSERT_NE(nullptr, property); 723 sptr<WindowNode> windowNode = new WindowNode(property); 724 ASSERT_NE(nullptr, windowNode); 725 windowNode->SetWindowProperty(property); 726 727 std::vector<Rect> testRects; 728 windowNode->GetPointerHotAreas(testRects); 729 ASSERT_EQ(true, testRects.empty()); 730 731 Rect rect1 = { 10, 10, 10, 10 }; 732 testRects.push_back(rect1); 733 windowNode->SetPointerHotAreas(testRects); 734 std::vector<Rect> resultRect; 735 windowNode->GetPointerHotAreas(resultRect); 736 ASSERT_EQ(1, resultRect.size()); 737 ASSERT_EQ(rect1, resultRect[0]); 738} 739/** 740 * @tc.name: SetPointerHotAreas01 741 * @tc.desc: SetWindowSizeLimits & GetWindowSizeLimits 742 * @tc.type: FUNC 743 */ 744HWTEST_F(WindowNodeTest, SetWindowSizeLimits01, Function | SmallTest | Level1) 745{ 746 std::string windowName = "WindowNode27"; 747 auto property = CreateWindowProperty(27, windowName); 748 ASSERT_NE(nullptr, property); 749 sptr<WindowNode> windowNode = new WindowNode(property); 750 ASSERT_NE(nullptr, windowNode); 751 windowNode->SetWindowProperty(property); 752 auto defaultValue = windowNode->GetWindowSizeLimits(); 753 ASSERT_EQ(0, defaultValue.minWidth_); 754 ASSERT_EQ(0, defaultValue.minHeight_); 755 ASSERT_EQ(0.0f, defaultValue.minRatio_); 756 ASSERT_EQ(UINT32_MAX, defaultValue.maxWidth_); 757 ASSERT_EQ(UINT32_MAX, defaultValue.maxHeight_); 758 ASSERT_EQ(FLT_MAX, defaultValue.maxRatio_); 759 760 WindowLimits testValue = { 200, 200, 50, 50, 2.0f, 2.0f }; 761 windowNode->SetWindowSizeLimits(testValue); 762 763 auto resultValue = windowNode->GetWindowSizeLimits(); 764 ASSERT_EQ(testValue.minWidth_, resultValue.minWidth_); 765 ASSERT_EQ(testValue.minHeight_, resultValue.minHeight_); 766 ASSERT_EQ(testValue.minRatio_, resultValue.minRatio_); 767 ASSERT_EQ(testValue.maxWidth_, resultValue.maxWidth_); 768 ASSERT_EQ(testValue.maxHeight_, resultValue.maxHeight_); 769 ASSERT_EQ(testValue.maxRatio_, resultValue.maxRatio_); 770} 771/** 772 * @tc.name: SetWindowUpdatedSizeLimits01 773 * @tc.desc: SetWindowUpdatedSizeLimits & GetWindowUpdatedSizeLimits 774 * @tc.type: FUNC 775 */ 776HWTEST_F(WindowNodeTest, SetWindowUpdatedSizeLimits01, Function | SmallTest | Level1) 777{ 778 std::string windowName = "WindowNode28"; 779 auto property = CreateWindowProperty(28, windowName); 780 ASSERT_NE(nullptr, property); 781 sptr<WindowNode> windowNode = new WindowNode(property); 782 ASSERT_NE(nullptr, windowNode); 783 windowNode->SetWindowProperty(property); 784 auto defaultValue = windowNode->GetWindowUpdatedSizeLimits(); 785 ASSERT_EQ(0, defaultValue.minWidth_); 786 ASSERT_EQ(0, defaultValue.minHeight_); 787 ASSERT_EQ(0.0f, defaultValue.minRatio_); 788 ASSERT_EQ(UINT32_MAX, defaultValue.maxWidth_); 789 ASSERT_EQ(UINT32_MAX, defaultValue.maxHeight_); 790 ASSERT_EQ(FLT_MAX, defaultValue.maxRatio_); 791 792 WindowLimits testValue = { 200, 200, 50, 50, 2.0f, 2.0f }; 793 windowNode->SetWindowUpdatedSizeLimits(testValue); 794 795 auto resultValue = windowNode->GetWindowUpdatedSizeLimits(); 796 ASSERT_EQ(testValue.minWidth_, resultValue.minWidth_); 797 ASSERT_EQ(testValue.minHeight_, resultValue.minHeight_); 798 ASSERT_EQ(testValue.minRatio_, resultValue.minRatio_); 799 ASSERT_EQ(testValue.maxWidth_, resultValue.maxWidth_); 800 ASSERT_EQ(testValue.maxHeight_, resultValue.maxHeight_); 801 ASSERT_EQ(testValue.maxRatio_, resultValue.maxRatio_); 802} 803/** 804 * @tc.name: SetSnapshot01 805 * @tc.desc: SetSnapshot & GetSnapshot 806 * @tc.type: FUNC 807 */ 808HWTEST_F(WindowNodeTest, SetSnapshot01, Function | SmallTest | Level1) 809{ 810 std::string windowName = "WindowNode29"; 811 auto property = CreateWindowProperty(29, windowName); 812 ASSERT_NE(nullptr, property); 813 sptr<WindowNode> windowNode = new WindowNode(property); 814 ASSERT_NE(nullptr, windowNode); 815 windowNode->SetWindowProperty(property); 816 817 auto defaultValue = windowNode->GetSnapshot(); 818 ASSERT_EQ(0, defaultValue.use_count()); 819 820 Media::InitializationOptions opts; 821 opts.size.width = 200; // 200: test width 822 opts.size.height = 300; // 300: test height 823 opts.pixelFormat = Media::PixelFormat::ARGB_8888; 824 opts.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_OPAQUE; 825 std::unique_ptr<Media::PixelMap> pixelMapPtr = Media::PixelMap::Create(opts); 826 std::shared_ptr<Media::PixelMap> pixelMap(pixelMapPtr.release()); 827 windowNode->SetSnapshot(pixelMap); 828 829 auto resultValue = windowNode->GetSnapshot(); 830 ASSERT_EQ(3, resultValue.use_count()); 831} 832/** 833 * @tc.name: UpdateZoomTransform01 834 * @tc.desc: UpdateZoomTransform & GetZoomTransform 835 * @tc.type: FUNC 836 */ 837HWTEST_F(WindowNodeTest, UpdateZoomTransform01, Function | SmallTest | Level1) 838{ 839 std::string windowName = "WindowNode30"; 840 auto property = CreateWindowProperty(30, windowName); 841 ASSERT_NE(nullptr, property); 842 sptr<WindowNode> windowNode = new WindowNode(property); 843 ASSERT_NE(nullptr, windowNode); 844 windowNode->SetWindowProperty(property); 845 Transform transformData; 846 auto defaultValue = windowNode->GetZoomTransform(); 847 ASSERT_EQ(transformData, defaultValue); 848 849 transformData.pivotX_ = 1.0f; 850 transformData.pivotY_ = 1.0f; 851 windowNode->UpdateZoomTransform(transformData, false); 852 853 auto resultValue = windowNode->GetZoomTransform(); 854 ASSERT_EQ(1.0f, resultValue.pivotX_); 855 ASSERT_EQ(1.0f, resultValue.pivotY_); 856} 857/** 858 * @tc.name: SetTransform01 859 * @tc.desc: SetTransform & ComputeTransform 860 * @tc.type: FUNC 861 */ 862HWTEST_F(WindowNodeTest, SetTransform01, Function | SmallTest | Level1) 863{ 864 std::string windowName = "WindowNode31"; 865 auto property = CreateWindowProperty(31, windowName); 866 ASSERT_NE(nullptr, property); 867 sptr<WindowNode> windowNode = new WindowNode(property); 868 ASSERT_NE(nullptr, windowNode); 869 windowNode->SetWindowProperty(property); 870 auto isSameValueMat4 = [](TransformHelper::Matrix4 expectVal, TransformHelper::Matrix4 checkValue) -> bool { 871 uint32_t m = 0, n = 0; 872 for (uint32_t i = 0; i < 16; i++) { 873 m = i / 4; 874 n = i % 4; 875 if (m > 4 || n > 4 || (expectVal.mat_[m][n] != checkValue.mat_[m][n])) { 876 return false; 877 } 878 } 879 return true; 880 }; 881 882 Transform transformData; 883 auto defaultTrans = windowNode->property_->trans_; 884 auto defaultWorldTransformMat4 = windowNode->property_->worldTransformMat_; 885 ASSERT_EQ(transformData, defaultTrans); 886 ASSERT_EQ(true, isSameValueMat4(TransformHelper::Matrix4::Identity, defaultWorldTransformMat4)); 887 888 transformData.pivotX_ = 1.0f; 889 transformData.pivotY_ = 1.0f; 890 transformData.translateX_ = 1.0f; 891 transformData.translateY_ = 1.0f; 892 windowNode->SetTransform(transformData); 893 windowNode->ComputeTransform(); 894 895 auto resultTrans = windowNode->property_->trans_; 896 auto resultWorldTransformMat4 = windowNode->property_->worldTransformMat_; 897 ASSERT_EQ(1.0f, resultTrans.pivotX_); 898 ASSERT_EQ(1.0f, resultTrans.pivotY_); 899 900 ASSERT_EQ(1.0f, resultWorldTransformMat4.mat_[3][0]); 901 ASSERT_EQ(1.0f, resultWorldTransformMat4.mat_[3][1]); 902} 903 904/** 905 * @tc.name: GetVisibilityState001 906 * @tc.desc: SetVisibilityState & GetVisibilityState 907 * @tc.type: FUNC 908 */ 909HWTEST_F(WindowNodeTest, GetVisibilityState001, Function | SmallTest | Level1) 910{ 911 std::string windowName = "WindowNode32"; 912 auto property = CreateWindowProperty(7, windowName); 913 ASSERT_NE(nullptr, property); 914 915 sptr<WindowNode> windowNode = new WindowNode(property); 916 ASSERT_NE(nullptr, windowNode); 917 windowNode->SetWindowProperty(property); 918 919 ASSERT_EQ(windowNode->GetVisibilityState(), WINDOW_VISIBILITY_STATE_NO_OCCLUSION); 920 windowNode->SetVisibilityState(WINDOW_VISIBILITY_STATE_PARTICALLY_OCCLUSION); 921 ASSERT_EQ(windowNode->GetVisibilityState(), WINDOW_VISIBILITY_STATE_PARTICALLY_OCCLUSION); 922} 923 924/** 925 * @tc.name: GetTouchable01 926 * @tc.desc: SetTouchable & GetTouchable 927 * @tc.type: FUNC 928 */ 929HWTEST_F(WindowNodeTest, GetTouchable01, Function | SmallTest | Level1) 930{ 931 std::string windowName = "WindowNode33"; 932 auto property = CreateWindowProperty(33, windowName); 933 ASSERT_NE(nullptr, property); 934 sptr<WindowNode> windowNode = new WindowNode(property); 935 ASSERT_NE(nullptr, windowNode); 936 937 windowNode->SetTouchable(false); 938 ASSERT_EQ(false, windowNode->GetTouchable()); 939 windowNode->SetTouchable(true); 940 ASSERT_EQ(true, windowNode->GetTouchable()); 941} 942} 943} 944}