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 <gtest/gtest.h>
17
18 #include "session_manager/include/fold_screen_controller/single_display_fold_policy.h"
19
20 using namespace testing;
21 using namespace testing::ext;
22
23 namespace OHOS {
24 namespace Rosen {
25 namespace {
26 constexpr uint32_t SLEEP_TIME_US = 100000;
27 }
28
29 class SingleDisplayFoldPolicyTest : public testing::Test {
30 public:
31 static void SetUpTestCase();
32 static void TearDownTestCase();
33 void SetUp() override;
34 void TearDown() override;
35 };
36
SetUpTestCase()37 void SingleDisplayFoldPolicyTest::SetUpTestCase()
38 {
39 }
40
TearDownTestCase()41 void SingleDisplayFoldPolicyTest::TearDownTestCase()
42 {
43 }
44
SetUp()45 void SingleDisplayFoldPolicyTest::SetUp()
46 {
47 }
48
TearDown()49 void SingleDisplayFoldPolicyTest::TearDown()
50 {
51 usleep(SLEEP_TIME_US);
52 }
53
54 namespace {
55 /**
56 * @tc.name: ChangeScreenDisplayMode
57 * @tc.desc: test function : ChangeScreenDisplayMode
58 * @tc.type: FUNC
59 */
60 HWTEST_F(SingleDisplayFoldPolicyTest, ChangeScreenDisplayMode, Function | SmallTest | Level3)
61 {
62 std::recursive_mutex displayInfoMutex;
63 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
64 SingleDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
65
66 FoldDisplayMode displayMode = FoldDisplayMode::UNKNOWN;
67 policy.ChangeScreenDisplayMode(displayMode);
68 EXPECT_FALSE(policy.onBootAnimation_);
69
70 displayMode = FoldDisplayMode::MAIN;
71 policy.ChangeScreenDisplayMode(displayMode);
72 EXPECT_FALSE(policy.onBootAnimation_);
73
74 displayMode = FoldDisplayMode::FULL;
75 policy.ChangeScreenDisplayMode(displayMode);
76 EXPECT_FALSE(policy.onBootAnimation_);
77
78 displayMode = FoldDisplayMode::SUB;
79 policy.ChangeScreenDisplayMode(displayMode);
80 EXPECT_FALSE(policy.onBootAnimation_);
81 }
82
83 /**
84 * @tc.name: SendSensorResult
85 * @tc.desc: test function : SendSensorResult
86 * @tc.type: FUNC
87 */
88 HWTEST_F(SingleDisplayFoldPolicyTest, SendSensorResult, Function | SmallTest | Level3)
89 {
90 std::recursive_mutex displayInfoMutex;
91 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
92 SingleDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
93
94 FoldStatus foldStatus = FoldStatus::UNKNOWN;
95 policy.SendSensorResult(foldStatus);
96 EXPECT_FALSE(policy.onBootAnimation_);
97 }
98
99 /**
100 * @tc.name: GetCurrentFoldCreaseRegion
101 * @tc.desc: test function : GetCurrentFoldCreaseRegion
102 * @tc.type: FUNC
103 */
104 HWTEST_F(SingleDisplayFoldPolicyTest, GetCurrentFoldCreaseRegion, Function | SmallTest | Level3)
105 {
106 std::recursive_mutex displayInfoMutex;
107 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
108 SingleDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
109
110 sptr<FoldCreaseRegion> foldCreaseRegion;
111 foldCreaseRegion = policy.GetCurrentFoldCreaseRegion();
112 EXPECT_EQ(policy.currentFoldCreaseRegion_, foldCreaseRegion);
113 }
114
115 /**
116 * @tc.name: LockDisplayStatus
117 * @tc.desc: test function : LockDisplayStatus
118 * @tc.type: FUNC
119 */
120 HWTEST_F(SingleDisplayFoldPolicyTest, LockDisplayStatus, Function | SmallTest | Level3)
121 {
122 std::recursive_mutex displayInfoMutex;
123 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
124 SingleDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
125
126 policy.LockDisplayStatus(false);
127 EXPECT_EQ(policy.lockDisplayStatus_, false);
128 }
129
130 /**
131 * @tc.name: SetOnBootAnimation
132 * @tc.desc: test function : SetOnBootAnimation
133 * @tc.type: FUNC
134 */
135 HWTEST_F(SingleDisplayFoldPolicyTest, SetOnBootAnimation, Function | SmallTest | Level3)
136 {
137 std::recursive_mutex displayInfoMutex;
138 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
139 SingleDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
140
141 policy.SetOnBootAnimation(false);
142 EXPECT_FALSE(policy.onBootAnimation_);
143
144 policy.SetOnBootAnimation(true);
145 EXPECT_TRUE(policy.onBootAnimation_);
146 }
147
148 /**
149 * @tc.name: RecoverWhenBootAnimationExit
150 * @tc.desc: test function : RecoverWhenBootAnimationExit
151 * @tc.type: FUNC
152 */
153 HWTEST_F(SingleDisplayFoldPolicyTest, RecoverWhenBootAnimationExit, Function | SmallTest | Level3)
154 {
155 std::recursive_mutex displayInfoMutex;
156 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
157 SingleDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
158
159 policy.currentDisplayMode_ = FoldDisplayMode::UNKNOWN;
160 policy.RecoverWhenBootAnimationExit();
161 EXPECT_FALSE(policy.onBootAnimation_);
162
163 policy.currentDisplayMode_ = FoldDisplayMode::SUB;
164 policy.RecoverWhenBootAnimationExit();
165 EXPECT_FALSE(policy.onBootAnimation_);
166
167 policy.currentDisplayMode_ = FoldDisplayMode::FULL;
168 policy.RecoverWhenBootAnimationExit();
169 EXPECT_FALSE(policy.onBootAnimation_);
170
171 policy.currentDisplayMode_ = FoldDisplayMode::MAIN;
172 policy.RecoverWhenBootAnimationExit();
173 EXPECT_FALSE(policy.onBootAnimation_);
174
175 policy.currentDisplayMode_ = FoldDisplayMode::COORDINATION;
176 policy.RecoverWhenBootAnimationExit();
177 EXPECT_FALSE(policy.onBootAnimation_);
178 }
179
180 /**
181 * @tc.name: UpdateForPhyScreenPropertyChange
182 * @tc.desc: test function : UpdateForPhyScreenPropertyChange
183 * @tc.type: FUNC
184 */
185 HWTEST_F(SingleDisplayFoldPolicyTest, UpdateForPhyScreenPropertyChange, Function | SmallTest | Level3)
186 {
187 std::recursive_mutex displayInfoMutex;
188 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
189 SingleDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
190
191 policy.currentDisplayMode_ = FoldDisplayMode::UNKNOWN;
192 policy.UpdateForPhyScreenPropertyChange();
193 EXPECT_FALSE(policy.onBootAnimation_);
194
195 policy.currentDisplayMode_ = FoldDisplayMode::SUB;
196 policy.UpdateForPhyScreenPropertyChange();
197 EXPECT_FALSE(policy.onBootAnimation_);
198
199 policy.currentDisplayMode_ = FoldDisplayMode::FULL;
200 policy.UpdateForPhyScreenPropertyChange();
201 EXPECT_FALSE(policy.onBootAnimation_);
202
203 policy.currentDisplayMode_ = FoldDisplayMode::MAIN;
204 policy.UpdateForPhyScreenPropertyChange();
205 EXPECT_FALSE(policy.onBootAnimation_);
206
207 policy.currentDisplayMode_ = FoldDisplayMode::COORDINATION;
208 policy.UpdateForPhyScreenPropertyChange();
209 EXPECT_FALSE(policy.onBootAnimation_);
210 }
211
212 /**
213 * @tc.name: GetModeMatchStatus
214 * @tc.desc: test function : GetModeMatchStatus
215 * @tc.type: FUNC
216 */
217 HWTEST_F(SingleDisplayFoldPolicyTest, GetModeMatchStatus, Function | SmallTest | Level3)
218 {
219 std::recursive_mutex displayInfoMutex;
220 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
221 SingleDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
222 FoldDisplayMode displayMode = FoldDisplayMode::UNKNOWN;
223
224 policy.currentFoldStatus_ = FoldStatus::EXPAND;
225 displayMode = policy.GetModeMatchStatus();
226 EXPECT_EQ(FoldDisplayMode::FULL, displayMode);
227
228 policy.currentFoldStatus_ = FoldStatus::FOLDED;
229 displayMode = policy.GetModeMatchStatus();
230 EXPECT_EQ(FoldDisplayMode::MAIN, displayMode);
231
232 policy.currentFoldStatus_ = FoldStatus::HALF_FOLD;
233 displayMode = policy.GetModeMatchStatus();
234 EXPECT_EQ(FoldDisplayMode::FULL, displayMode);
235
236 policy.currentFoldStatus_ = FoldStatus::UNKNOWN;
237 displayMode = policy.GetModeMatchStatus();
238 EXPECT_EQ(FoldDisplayMode::UNKNOWN, displayMode);
239 }
240
241 /**
242 * @tc.name: ReportFoldDisplayModeChange
243 * @tc.desc: test function : ReportFoldDisplayModeChange
244 * @tc.type: FUNC
245 */
246 HWTEST_F(SingleDisplayFoldPolicyTest, ReportFoldDisplayModeChange, Function | SmallTest | Level3)
247 {
248 std::recursive_mutex displayInfoMutex;
249 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
250 SingleDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
251
252 FoldDisplayMode displayMode = FoldDisplayMode::UNKNOWN;
253 policy.ReportFoldDisplayModeChange(displayMode);
254 EXPECT_EQ(FoldDisplayMode::UNKNOWN, displayMode);
255
256 displayMode = FoldDisplayMode::FULL;
257 policy.ReportFoldDisplayModeChange(displayMode);
258 EXPECT_NE(FoldDisplayMode::UNKNOWN, displayMode);
259 }
260
261 /**
262 * @tc.name: ReportFoldStatusChangeBegin
263 * @tc.desc: test function : ReportFoldStatusChangeBegin
264 * @tc.type: FUNC
265 */
266 HWTEST_F(SingleDisplayFoldPolicyTest, ReportFoldStatusChangeBegin, Function | SmallTest | Level3)
267 {
268 std::recursive_mutex displayInfoMutex;
269 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
270 SingleDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
271
272 int32_t offScreen = 0;
273 int32_t onScreen = 1;
274 policy.ReportFoldStatusChangeBegin(offScreen, onScreen);
275 EXPECT_TRUE(onScreen);
276
277 policy.ReportFoldStatusChangeBegin(offScreen, onScreen);
278 EXPECT_TRUE(onScreen);
279 }
280
281 /**
282 * @tc.name: ChangeScreenDisplayModeToMain
283 * @tc.desc: test function : ChangeScreenDisplayModeToMain
284 * @tc.type: FUNC
285 */
286 HWTEST_F(SingleDisplayFoldPolicyTest, ChangeScreenDisplayModeToMain, Function | SmallTest | Level3)
287 {
288 std::recursive_mutex displayInfoMutex;
289 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
290 SingleDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
291 sptr<ScreenSession> screenSession = new ScreenSession;
292
293 policy.onBootAnimation_ = true;
294 policy.ChangeScreenDisplayModeToMain(screenSession);
295 EXPECT_TRUE(policy.onBootAnimation_);
296
297 policy.ChangeScreenDisplayModeToMain(screenSession);
298 EXPECT_TRUE(policy.onBootAnimation_);
299 }
300
301 /**
302 * @tc.name: ChangeScreenDisplayModeToFull
303 * @tc.desc: test function : ChangeScreenDisplayModeToFull
304 * @tc.type: FUNC
305 */
306 HWTEST_F(SingleDisplayFoldPolicyTest, ChangeScreenDisplayModeToFull, Function | SmallTest | Level3)
307 {
308 std::recursive_mutex displayInfoMutex;
309 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
310 SingleDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
311 sptr<ScreenSession> screenSession = new ScreenSession;
312
313 policy.onBootAnimation_ = true;
314 policy.ChangeScreenDisplayModeToFull(screenSession);
315 EXPECT_TRUE(policy.onBootAnimation_);
316
317 policy.ChangeScreenDisplayModeToFull(screenSession);
318 EXPECT_TRUE(policy.onBootAnimation_);
319 }
320
321 /**
322 * @tc.name: ChangeScreenDisplayModePower
323 * @tc.desc: test function : ChangeScreenDisplayModePower
324 * @tc.type: FUNC
325 */
326 HWTEST_F(SingleDisplayFoldPolicyTest, ChangeScreenDisplayModePower, Function | SmallTest | Level3)
327 {
328 std::recursive_mutex displayInfoMutex;
329 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
330 SingleDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
331 EXPECT_TRUE(1);
332 }
333
334 /**
335 * @tc.name: SendPropertyChangeResult
336 * @tc.desc: test function : SendPropertyChangeResult
337 * @tc.type: FUNC
338 */
339 HWTEST_F(SingleDisplayFoldPolicyTest, SendPropertyChangeResult, Function | SmallTest | Level3)
340 {
341 std::recursive_mutex displayInfoMutex;
342 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
343 SingleDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
344 sptr<ScreenSession> screenSession = new ScreenSession;
345 ScreenId screenId = 0;
346 ScreenPropertyChangeReason reason = ScreenPropertyChangeReason::UNDEFINED;
347
348 policy.SendPropertyChangeResult(screenSession, screenId, reason);
349 EXPECT_FALSE(policy.onBootAnimation_);
350 }
351
352 /**
353 * @tc.name: ChangeScreenDisplayModeToMainOnBootAnimation
354 * @tc.desc: test function : ChangeScreenDisplayModeToMainOnBootAnimation
355 * @tc.type: FUNC
356 */
357 HWTEST_F(SingleDisplayFoldPolicyTest, ChangeScreenDisplayModeToMainOnBootAnimation, Function | SmallTest | Level3)
358 {
359 std::recursive_mutex displayInfoMutex;
360 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
361 SingleDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
362 sptr<ScreenSession> screenSession = new ScreenSession;
363
364 policy.ChangeScreenDisplayModeToMainOnBootAnimation(screenSession);
365 EXPECT_FALSE(policy.onBootAnimation_);
366 }
367
368 /**
369 * @tc.name: ChangeScreenDisplayModeToFullOnBootAnimation
370 * @tc.desc: test function : ChangeScreenDisplayModeToFullOnBootAnimation
371 * @tc.type: FUNC
372 */
373 HWTEST_F(SingleDisplayFoldPolicyTest, ChangeScreenDisplayModeToFullOnBootAnimation, Function | SmallTest | Level3)
374 {
375 std::recursive_mutex displayInfoMutex;
376 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
377 SingleDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
378 sptr<ScreenSession> screenSession = new ScreenSession;
379
380 policy.ChangeScreenDisplayModeToFullOnBootAnimation(screenSession);
381 EXPECT_FALSE(policy.onBootAnimation_);
382 }
383 }
384 } // namespace Rosen
385 } // namespace OHOS