1 /*
2  * Copyright (c) 2023 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 "interfaces/include/ws_common.h"
18 #include "session_manager/include/scene_session_manager.h"
19 #include "session_info.h"
20 #include "session/host/include/scene_session.h"
21 #include "window_manager_agent.h"
22 #include "session_manager.h"
23 #include "screen_cutout_controller.h"
24 #include "zidl/window_manager_agent_interface.h"
25 
26 using namespace testing;
27 using namespace testing::ext;
28 
29 namespace OHOS {
30 namespace Rosen {
31 namespace {
32     constexpr uint32_t SLEEP_TIME_US = 100000;
33 }
34 
35 class ScreenCutoutControllerTest : public testing::Test {
36 public:
37     static void SetUpTestCase();
38     static void TearDownTestCase();
39     void SetUp() override;
40     void TearDown() override;
41 };
42 
SetUpTestCase()43 void ScreenCutoutControllerTest::SetUpTestCase()
44 {
45 }
46 
TearDownTestCase()47 void ScreenCutoutControllerTest::TearDownTestCase()
48 {
49 }
50 
SetUp()51 void ScreenCutoutControllerTest::SetUp()
52 {
53 }
54 
TearDown()55 void ScreenCutoutControllerTest::TearDown()
56 {
57     usleep(SLEEP_TIME_US);
58 }
59 
60 namespace {
61 
62     /**
63      * @tc.name: CreateWaterfallRect
64      * @tc.desc: CreateWaterfallRect func
65      * @tc.type: FUNC
66      */
67     HWTEST_F(ScreenCutoutControllerTest, CreateWaterfallRect, Function | SmallTest | Level3)
68     {
69         DMRect emptyRect = {0, 0, 0, 0};
70         DMRect emptyRect_ = {1, 2, 3, 3};
71         sptr<ScreenCutoutController> controller = new ScreenCutoutController();
72 
73         DMRect result = controller->CreateWaterfallRect(0, 0, 0, 0);
74         ASSERT_EQ(result, emptyRect);
75         DMRect result_ = controller->CreateWaterfallRect(1, 2, 3, 3);
76         ASSERT_EQ(result_, emptyRect_);
77     }
78 
79     /**
80      * @tc.name: GetScreenCutoutInfo
81      * @tc.desc: GetScreenCutoutInfo func
82      * @tc.type: FUNC
83      */
84     HWTEST_F(ScreenCutoutControllerTest, GetScreenCutoutInfo, Function | SmallTest | Level3)
85     {
86         sptr<ScreenCutoutController> controller = new ScreenCutoutController();
87         DisplayId displayId = 0;
88         ASSERT_NE(nullptr, controller->GetScreenCutoutInfo(displayId));
89     }
90 
91     /**
92      * @tc.name: ConvertBoundaryRectsByRotation
93      * @tc.desc: ScreenCutoutController convert boundary rects by rotation
94      * @tc.type: FUNC
95      */
96     HWTEST_F(ScreenCutoutControllerTest, ConvertBoundaryRectsByRotation, Function | SmallTest | Level3)
97     {
98         sptr<ScreenCutoutController> controller = new ScreenCutoutController();
99         DMRect emptyRect = {0, 0, 0, 0};
100         DMRect emptyRect_ = {1, 2, 3, 3};
101         DisplayId displayId = 0;
102         std::vector<DMRect> boundaryRects = {emptyRect, emptyRect_};
103 
104         ASSERT_TRUE(controller != nullptr);
105         controller->ConvertBoundaryRectsByRotation(boundaryRects, displayId);
106     }
107 
108     /**
109      * @tc.name: CheckBoundaryRects
110      * @tc.desc: ScreenCutoutController check boundary rects
111      * @tc.type: FUNC
112      */
113     HWTEST_F(ScreenCutoutControllerTest, CheckBoundaryRects, Function | SmallTest | Level3)
114     {
115         sptr<ScreenCutoutController> controller = new ScreenCutoutController();
116         DMRect emptyRect = {-15, -15, 8, 8};
117         DMRect emptyRect_ = {21, 21, 3, 3};
118         std::vector<DMRect> boundaryRects = {emptyRect_, emptyRect};
119         ScreenProperty screenProperty;
120         auto screenBounds = RRect({ 0, 0, 35, 35 }, 0.0f, 0.0f);
121         screenProperty.SetBounds(screenBounds);
122         ASSERT_TRUE(controller != nullptr);
123         controller->CheckBoundaryRects(boundaryRects, screenProperty);
124     }
125 
126     /**
127      * @tc.name: CalcWaterfallRects
128      * @tc.desc: ScreenCutoutController calc waterfall rects
129      * @tc.type: FUNC
130      */
131     HWTEST_F(ScreenCutoutControllerTest, CalcWaterfallRects, Function | SmallTest | Level3)
132     {
133         DisplayId displayId = 0;
134         sptr<ScreenCutoutController> controller = new ScreenCutoutController();
135         ASSERT_TRUE(controller != nullptr);
136         controller->CalcWaterfallRects(displayId);
137     }
138 
139     /**
140      * @tc.name: CalcWaterfallRectsByRotation
141      * @tc.desc: ScreenCutoutController calc waterfall rects by rotation
142      * @tc.type: FUNC
143      */
144     HWTEST_F(ScreenCutoutControllerTest, CalcWaterfallRectsByRotation, Function | SmallTest | Level3)
145     {
146         sptr<ScreenCutoutController> controller = new ScreenCutoutController();
147         Rotation rotation;
148         uint32_t displayHeight = 1024;
149         uint32_t displayWidth = 512;
150         std::vector<uint32_t> realNumVec = {16, 32, 8, 8};
151         rotation = Rotation::ROTATION_0;
152         ASSERT_TRUE(controller != nullptr);
153         controller->CalcWaterfallRectsByRotation(rotation, displayHeight, displayWidth, realNumVec);
154         rotation = Rotation::ROTATION_90;
155         controller->CalcWaterfallRectsByRotation(rotation, displayHeight, displayWidth, realNumVec);
156         rotation = Rotation::ROTATION_180;
157         controller->CalcWaterfallRectsByRotation(rotation, displayHeight, displayWidth, realNumVec);
158         rotation = Rotation::ROTATION_270;
159         controller->CalcWaterfallRectsByRotation(rotation, displayHeight, displayWidth, realNumVec);
160     }
161 
162     /**
163      * @tc.name: CalculateCurvedCompression
164      * @tc.desc: ScreenCutoutController calculate curved compression
165      * @tc.type: FUNC
166      */
167     HWTEST_F(ScreenCutoutControllerTest, CalculateCurvedCompression, Function | SmallTest | Level3)
168     {
169         sptr<ScreenCutoutController> controller = new ScreenCutoutController();
170         RectF finalRect = RectF(0, 0, 0, 0);
171         ScreenProperty screenProperty;
172         RectF result = controller->CalculateCurvedCompression(screenProperty);
173         ASSERT_EQ(finalRect.left_, result.left_);
174         ASSERT_EQ(finalRect.top_, result.top_);
175         ASSERT_EQ(finalRect.width_, result.width_);
176         ASSERT_EQ(finalRect.height_, result.height_);
177     }
178 
179     /**
180      * @tc.name: IsDisplayRotationHorizontal
181      * @tc.desc: IsDisplayRotationHorizontal func
182      * @tc.type: FUNC
183      */
184     HWTEST_F(ScreenCutoutControllerTest, IsDisplayRotationHorizontal, Function | SmallTest | Level3)
185     {
186         sptr<ScreenCutoutController> controller = new ScreenCutoutController();
187         ASSERT_EQ(false, controller->IsDisplayRotationHorizontal(Rotation::ROTATION_0));
188         ASSERT_EQ(false, controller->IsDisplayRotationHorizontal(Rotation::ROTATION_180));
189         ASSERT_EQ(true, controller->IsDisplayRotationHorizontal(Rotation::ROTATION_90));
190         ASSERT_EQ(true, controller->IsDisplayRotationHorizontal(Rotation::ROTATION_270));
191     }
192 
193     /**
194      * @tc.name: ConvertDeviceToDisplayRotation01
195      * @tc.desc: ConvertDeviceToDisplayRotation func
196      * @tc.type: FUNC
197      */
198     HWTEST_F(ScreenCutoutControllerTest, ConvertDeviceToDisplayRotation01, Function | SmallTest | Level3)
199     {
200         sptr<ScreenCutoutController> controller = new ScreenCutoutController();
201         ASSERT_EQ(Rotation::ROTATION_0, controller->ConvertDeviceToDisplayRotation(DeviceRotationValue::INVALID));
202         DeviceRotationValue deviceRotation;
203         deviceRotation = DeviceRotationValue::ROTATION_PORTRAIT;
204         Rotation result01 = controller->ConvertDeviceToDisplayRotation(deviceRotation);
205         ASSERT_EQ(result01, Rotation::ROTATION_0);
206     }
207 
208     /**
209      * @tc.name: GetCurrentDisplayRotation01
210      * @tc.desc: GetCurrentDisplayRotation func
211      * @tc.type: FUNC
212      */
213     HWTEST_F(ScreenCutoutControllerTest, GetCurrentDisplayRotation01, Function | SmallTest | Level3)
214     {
215         DisplayId displayId = 0;
216         sptr<ScreenCutoutController> controller = new ScreenCutoutController();
217         ASSERT_EQ(Rotation::ROTATION_0, controller->GetCurrentDisplayRotation(displayId));
218     }
219 
220     /**
221      * @tc.name: ProcessRotationMapping
222      * @tc.desc: ProcessRotationMapping func
223      * @tc.type: FUNC
224      */
225     HWTEST_F(ScreenCutoutControllerTest, ProcessRotationMapping, Function | SmallTest | Level3)
226     {
227         sptr<ScreenCutoutController> controller = new ScreenCutoutController();
228         ASSERT_TRUE(controller != nullptr);
229         controller->ProcessRotationMapping();
230     }
231 
232     /**
233      * @tc.name: GetOffsetY
234      * @tc.desc: GetOffsetY func
235      * @tc.type: FUNC
236      */
237     HWTEST_F(ScreenCutoutControllerTest, GetOffsetY, Function | SmallTest | Level3)
238     {
239         sptr<ScreenCutoutController> controller = new ScreenCutoutController();
240         ASSERT_EQ(0, controller->GetOffsetY());
241     }
242 }
243 } // namespace Rosen
244 } // namespace OHOS
245 
246