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 
16 #include <gtest/gtest.h>
17 #include "display_zoom_controller.h"
18 #include "display_manager.h"
19 
20 using namespace testing;
21 using namespace testing::ext;
22 namespace OHOS {
23 namespace Rosen {
24 class WindowDisplayZoomControllerTest : public testing::Test {
25 public:
26     static void SetUpTestCase();
27     static void TearDownTestCase();
28     void SetUp() override;
29     void TearDown() override;
30     sptr<WindowRoot> windowRoot_;
31     sptr<DisplayZoomController> displayController_;
32 };
33 
SetUpTestCase()34 void WindowDisplayZoomControllerTest::SetUpTestCase()
35 {
36 }
37 
TearDownTestCase()38 void WindowDisplayZoomControllerTest::TearDownTestCase()
39 {
40 }
41 
SetUp()42 void WindowDisplayZoomControllerTest::SetUp()
43 {
44     windowRoot_ = new WindowRoot(nullptr);
45     displayController_ = new DisplayZoomController(windowRoot_);
46 }
47 
TearDown()48 void WindowDisplayZoomControllerTest::TearDown()
49 {
50 }
51 
52 namespace {
53 /**
54  * @tc.name: WindowDisplayZoomControllerTest01
55  * @tc.desc: test WindowDisplayZoomController
56  * @tc.type: FUNC
57  */
58 HWTEST_F(WindowDisplayZoomControllerTest, WindowDisplayZoomControllerTest01, Function | SmallTest | Level2)
59 {
60     DisplayId displayId;
61     uint32_t windowId;
62 
63     // windowNodeContainer is null
64     displayController_->SetAnchorAndScale(1, 1, 10.0);
65     displayController_->SetAnchorOffset(1, 1);
66     displayController_->OffWindowZoom();
67     displayId = DisplayManagerServiceInner::GetInstance().GetDefaultDisplayId();
68     displayController_->UpdateAllWindowsZoomInfo(displayId);
69     windowId = INVALID_WINDOW_ID;
70     displayController_->UpdateWindowZoomInfo(windowId);
71 
72     auto display = DisplayManager::GetInstance().GetDefaultDisplay();
73     ASSERT_NE(display, nullptr);
74     sptr<DisplayInfo> displayInfo = display->GetDisplayInfo();
75     ASSERT_NE(displayInfo, nullptr);
76     auto container = windowRoot_->CreateWindowNodeContainer(0, displayInfo);
77     ASSERT_NE(container, nullptr);
78 
79     // windowNodeContainer is not null
80     displayController_->SetAnchorAndScale(1, 1, 10.0);
81     displayController_->SetAnchorOffset(1, 1);
82     displayId = DisplayManagerServiceInner::GetInstance().GetDefaultDisplayId();
83 
84     ASSERT_EQ(true, true);
85 }
86 
87 /**
88  * @tc.name: WindowDisplayZoomControllerTest02
89  * @tc.desc: test WindowDisplayZoomController
90  * @tc.type: FUNC
91  */
92 HWTEST_F(WindowDisplayZoomControllerTest, WindowDisplayZoomControllerTest02, Function | SmallTest | Level2)
93 {
94     DisplayId displayId = 0;
95     displayController_->SetAnchorAndScale(1, 1, -1);
96     displayController_->SetAnchorAndScale(1, 1, 0.1);
97     displayController_->UpdateAllWindowsZoomInfo(displayId);
98 
99     displayController_->UpdateWindowZoomInfo(1);
100     std::vector<sptr<WindowNode>> nodes;
101     displayController_->ClearZoomTransform(nodes);
102     ASSERT_EQ(displayId, 0);
103 }
104 }
105 }
106 }
107