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
18 #include "session_manager/include/fold_screen_controller/fold_screen_controller.h"
19 #include "session_manager/include/screen_session_manager.h"
20
21 using namespace testing;
22 using namespace testing::ext;
23
24 namespace OHOS {
25 namespace Rosen {
26 namespace {
27 constexpr uint32_t SLEEP_TIME_IN_US = 100000; // 100ms
28 }
29 class FoldScreenControllerTest : public testing::Test {
30 public:
31 static void SetUpTestCase();
32 static void TearDownTestCase();
33 void SetUp() override;
34 void TearDown() override;
35
36 static ScreenSessionManager& ssm_;
37 };
38
39 ScreenSessionManager& FoldScreenControllerTest::ssm_ = ScreenSessionManager::GetInstance();
40
SetUpTestCase()41 void FoldScreenControllerTest::SetUpTestCase()
42 {
43 }
44
TearDownTestCase()45 void FoldScreenControllerTest::TearDownTestCase()
46 {
47 usleep(SLEEP_TIME_IN_US);
48 }
49
SetUp()50 void FoldScreenControllerTest::SetUp()
51 {
52 }
53
TearDown()54 void FoldScreenControllerTest::TearDown()
55 {
56 }
57
58 namespace {
59
60 /**
61 * @tc.name: GetFoldScreenPolicy
62 * @tc.desc: test function :GetFoldScreenPolicy
63 * @tc.type: FUNC
64 */
65 HWTEST_F(FoldScreenControllerTest, GetFoldScreenPolicy, Function | SmallTest | Level3)
66 {
67 std::recursive_mutex mutex;
68 FoldScreenController fsc_(mutex, std::shared_ptr<TaskScheduler>());
69
70 DisplayDeviceType productType = DisplayDeviceType::SINGLE_DISPLAY_DEVICE;
71 auto ret = fsc_.GetFoldScreenPolicy(productType);
72 ASSERT_NE(ret, nullptr);
73
74 productType = DisplayDeviceType::DOUBLE_DISPLAY_DEVICE;
75 ret = fsc_.GetFoldScreenPolicy(productType);
76 ASSERT_NE(ret, nullptr);
77
78 productType = DisplayDeviceType::SINGLE_DISPLAY_POCKET_DEVICE;
79 ret = fsc_.GetFoldScreenPolicy(productType);
80 ASSERT_NE(ret, nullptr);
81
82 productType = DisplayDeviceType::DISPLAY_DEVICE_UNKNOWN;
83 ret = fsc_.GetFoldScreenPolicy(productType);
84 ASSERT_EQ(ret, nullptr);
85 }
86
87 /**
88 * @tc.name: SetDisplayMode01
89 * @tc.desc: test function :SetDisplayMode
90 * @tc.type: FUNC
91 */
92 HWTEST_F(FoldScreenControllerTest, SetDisplayMode01, Function | SmallTest | Level3)
93 {
94 std::recursive_mutex mutex;
95 FoldScreenController fsc_(mutex, std::shared_ptr<TaskScheduler>());
96
97 fsc_.foldScreenPolicy_ = nullptr;
98 FoldDisplayMode displayMode = FoldDisplayMode::FULL;
99 fsc_.SetDisplayMode(displayMode);
100 ASSERT_EQ(fsc_.GetDisplayMode(), FoldDisplayMode::UNKNOWN);
101 }
102
103 /**
104 * @tc.name: SetDisplayMode02
105 * @tc.desc: test function :SetDisplayMode
106 * @tc.type: FUNC
107 */
108 HWTEST_F(FoldScreenControllerTest, SetDisplayMode02, Function | SmallTest | Level3)
109 {
110 std::recursive_mutex mutex;
111 FoldScreenController fsc_(mutex, std::shared_ptr<TaskScheduler>());
112
113 ASSERT_NE(fsc_.foldScreenPolicy_, nullptr);
114 auto mode = fsc_.GetDisplayMode();
115 FoldDisplayMode displayMode = FoldDisplayMode::UNKNOWN;
116 fsc_.SetDisplayMode(displayMode);
117 if (ssm_.IsFoldable()) {
118 ASSERT_EQ(fsc_.GetDisplayMode(), displayMode);
119 fsc_.SetDisplayMode(mode);
120 } else {
121 ASSERT_EQ(fsc_.GetDisplayMode(), FoldDisplayMode::UNKNOWN);
122 }
123 }
124
125 /**
126 * @tc.name: GetFoldDisplayMode
127 * @tc.desc: GetFoldDisplayMode get display mode
128 * @tc.type: FUNC
129 */
130 HWTEST_F(FoldScreenControllerTest, GetFoldDisplayMode, Function | SmallTest | Level3)
131 {
132 ssm_.SetFoldDisplayMode(FoldDisplayMode::MAIN);
133 ASSERT_EQ(FoldDisplayMode::UNKNOWN, ssm_.GetFoldDisplayMode());
134 ssm_.SetFoldDisplayMode(FoldDisplayMode::FULL);
135 ASSERT_EQ(FoldDisplayMode::UNKNOWN, ssm_.GetFoldDisplayMode());
136 }
137
138 /**
139 * @tc.name: LockDisplayStatus01
140 * @tc.desc: test function :LockDisplayStatus
141 * @tc.type: FUNC
142 */
143 HWTEST_F(FoldScreenControllerTest, LockDisplayStatus01, Function | SmallTest | Level3)
144 {
145 std::recursive_mutex mutex;
146 FoldScreenController fsc_(mutex, std::shared_ptr<TaskScheduler>());
147
148 fsc_.foldScreenPolicy_ = nullptr;
149 bool locked = false;
150 fsc_.LockDisplayStatus(locked);
151 ASSERT_EQ(fsc_.foldScreenPolicy_, nullptr);
152 }
153
154 /**
155 * @tc.name: LockDisplayStatus02
156 * @tc.desc: test function :LockDisplayStatus
157 * @tc.type: FUNC
158 */
159 HWTEST_F(FoldScreenControllerTest, LockDisplayStatus02, Function | SmallTest | Level3)
160 {
161 std::recursive_mutex mutex;
162 FoldScreenController fsc_(mutex, std::shared_ptr<TaskScheduler>());
163
164 fsc_.foldScreenPolicy_ = new FoldScreenPolicy();
165 bool locked = false;
166 fsc_.LockDisplayStatus(locked);
167 ASSERT_EQ((fsc_.foldScreenPolicy_)->lockDisplayStatus_, locked);
168 }
169
170 /**
171 * @tc.name: GetDisplayMode
172 * @tc.desc: test function :GetDisplayMode
173 * @tc.type: FUNC
174 */
175 HWTEST_F(FoldScreenControllerTest, GetDisplayMode01, Function | SmallTest | Level3)
176 {
177 std::recursive_mutex mutex;
178 FoldScreenController fsc_(mutex, std::shared_ptr<TaskScheduler>());
179
180 fsc_.foldScreenPolicy_ = nullptr;
181 auto ret = fsc_.GetDisplayMode();
182 ASSERT_EQ(ret, FoldDisplayMode::UNKNOWN);
183 }
184
185 /**
186 * @tc.name: GetDisplayMode
187 * @tc.desc: foldScreenPolicy_ is not nullptr
188 * @tc.type: FUNC
189 */
190 HWTEST_F(FoldScreenControllerTest, GetDisplayMode02, Function | SmallTest | Level3)
191 {
192 std::recursive_mutex mutex;
193 FoldScreenController fsc_(mutex, std::shared_ptr<TaskScheduler>());
194
195 fsc_.foldScreenPolicy_ = new FoldScreenPolicy();
196 auto ret = fsc_.GetDisplayMode();
197 ASSERT_EQ(ret, FoldDisplayMode::UNKNOWN);
198 }
199
200 /**
201 * @tc.name: GetFoldStatus
202 * @tc.desc: test function :GetFoldStatus
203 * @tc.type: FUNC
204 */
205 HWTEST_F(FoldScreenControllerTest, GetFoldStatus02, Function | SmallTest | Level3)
206 {
207 std::recursive_mutex mutex;
208 FoldScreenController fsc_(mutex, std::shared_ptr<TaskScheduler>());
209
210 fsc_.foldScreenPolicy_ = new FoldScreenPolicy();
211 auto ret = fsc_.GetFoldStatus();
212 ASSERT_EQ(ret, FoldStatus::UNKNOWN);
213 }
214
215 /**
216 * @tc.name: SetFoldStatus01
217 * @tc.desc: test function :SetFoldStatus
218 * @tc.type: FUNC
219 */
220 HWTEST_F(FoldScreenControllerTest, SetFoldStatus01, Function | SmallTest | Level3)
221 {
222 std::recursive_mutex mutex;
223 FoldScreenController fsc_(mutex, std::shared_ptr<TaskScheduler>());
224
225 FoldStatus foldStatus = FoldStatus::HALF_FOLD;
226 fsc_.foldScreenPolicy_ = nullptr;
227 fsc_.SetFoldStatus(foldStatus);
228 ASSERT_EQ(fsc_.GetFoldStatus(), FoldStatus::UNKNOWN);
229 }
230
231 /**
232 * @tc.name: SetFoldStatus02
233 * @tc.desc: test function :SetFoldStatus
234 * @tc.type: FUNC
235 */
236 HWTEST_F(FoldScreenControllerTest, SetFoldStatus02, Function | SmallTest | Level3)
237 {
238 std::recursive_mutex mutex;
239 FoldScreenController fsc_(mutex, std::shared_ptr<TaskScheduler>());
240
241 FoldStatus foldStatus = FoldStatus::HALF_FOLD;
242 fsc_.foldScreenPolicy_ = new FoldScreenPolicy();
243 fsc_.SetFoldStatus(foldStatus);
244 ASSERT_EQ(fsc_.GetFoldStatus(), foldStatus);
245 }
246
247 /**
248 * @tc.name: GetCurrentFoldCreaseRegion
249 * @tc.desc: FoldScreenController get crease region
250 * @tc.type: FUNC
251 */
252 HWTEST_F(FoldScreenControllerTest, GetCurrentFoldCreaseRegion01, Function | SmallTest | Level3)
253 {
254 std::recursive_mutex mutex;
255 FoldScreenController fsc_(mutex, std::shared_ptr<TaskScheduler>());
256
257 fsc_.foldScreenPolicy_ = nullptr;
258 auto ret = fsc_.GetCurrentFoldCreaseRegion();
259 ASSERT_EQ(ret, nullptr);
260 }
261
262 /**
263 * @tc.name: GetCurrentFoldCreaseRegion
264 * @tc.desc: test function :GetCurrentFoldCreaseRegion
265 * @tc.type: FUNC
266 */
267 HWTEST_F(FoldScreenControllerTest, GetCurrentFoldCreaseRegion02, Function | SmallTest | Level3)
268 {
269 std::recursive_mutex mutex;
270 FoldScreenController fsc_(mutex, std::shared_ptr<TaskScheduler>());
271
272 fsc_.foldScreenPolicy_ = new FoldScreenPolicy();
273 auto ret = fsc_.GetCurrentFoldCreaseRegion();
274 ASSERT_EQ(ret, fsc_.foldScreenPolicy_->GetCurrentFoldCreaseRegion());
275 }
276
277 /**
278 * @tc.name: GetCurrentScreenId01
279 * @tc.desc: test function :GetCurrentScreenId
280 * @tc.type: FUNC
281 */
282 HWTEST_F(FoldScreenControllerTest, GetCurrentScreenId01, Function | SmallTest | Level3)
283 {
284 std::recursive_mutex mutex;
285 FoldScreenController fsc_(mutex, std::shared_ptr<TaskScheduler>());
286
287 fsc_.foldScreenPolicy_ = nullptr;
288 auto ret = fsc_.GetCurrentScreenId();
289 ASSERT_EQ(ret, 0);
290 }
291
292 /**
293 * @tc.name: GetCurrentScreenId02
294 * @tc.desc: test function :GetCurrentScreenId
295 * @tc.type: FUNC
296 */
297 HWTEST_F(FoldScreenControllerTest, GetCurrentScreenId02, Function | SmallTest | Level3)
298 {
299 std::recursive_mutex mutex;
300 FoldScreenController fsc_(mutex, std::shared_ptr<TaskScheduler>());
301
302 fsc_.foldScreenPolicy_ = new FoldScreenPolicy();
303 auto ret = fsc_.GetCurrentScreenId();
304 ASSERT_NE(ret, 0);
305 }
306
307 /**
308 * @tc.name: SetOnBootAnimation01
309 * @tc.desc: test function :SetOnBootAnimation
310 * @tc.type: FUNC
311 */
312 HWTEST_F(FoldScreenControllerTest, SetOnBootAnimation01, Function | SmallTest | Level3)
313 {
314 std::recursive_mutex mutex;
315 FoldScreenController fsc_(mutex, std::shared_ptr<TaskScheduler>());
316
317 bool onBootAnimation = false;
318 fsc_.foldScreenPolicy_ = nullptr;
319 fsc_.SetOnBootAnimation(onBootAnimation);
320 ASSERT_EQ(onBootAnimation, false);
321 }
322
323 /**
324 * @tc.name: SetOnBootAnimation02
325 * @tc.desc: test function :SetOnBootAnimation
326 * @tc.type: FUNC
327 */
328 HWTEST_F(FoldScreenControllerTest, SetOnBootAnimation02, Function | SmallTest | Level3)
329 {
330 std::recursive_mutex mutex;
331 FoldScreenController fsc_(mutex, std::shared_ptr<TaskScheduler>());
332
333 bool onBootAnimation = true;
334 fsc_.foldScreenPolicy_ = new FoldScreenPolicy();
335 fsc_.SetOnBootAnimation(onBootAnimation);
336 ASSERT_EQ(onBootAnimation, true);
337 }
338
339 /**
340 * @tc.name: UpdateForPhyScreenPropertyChange01
341 * @tc.desc: test function :UpdateForPhyScreenPropertyChange
342 * @tc.type: FUNC
343 */
344 HWTEST_F(FoldScreenControllerTest, UpdateForPhyScreenPropertyChange01, Function | SmallTest | Level3)
345 {
346 std::recursive_mutex mutex;
347 FoldScreenController fsc_(mutex, std::shared_ptr<TaskScheduler>());
348
349 fsc_.foldScreenPolicy_ = nullptr;
350 fsc_.UpdateForPhyScreenPropertyChange();
351 ASSERT_EQ(fsc_.foldScreenPolicy_, nullptr);
352 }
353
354 /**
355 * @tc.name: UpdateForPhyScreenPropertyChange02
356 * @tc.desc: test function :UpdateForPhyScreenPropertyChange
357 * @tc.type: FUNC
358 */
359 HWTEST_F(FoldScreenControllerTest, UpdateForPhyScreenPropertyChange02, Function | SmallTest | Level3)
360 {
361 std::recursive_mutex mutex;
362 FoldScreenController fsc_(mutex, std::shared_ptr<TaskScheduler>());
363
364 fsc_.foldScreenPolicy_ = new FoldScreenPolicy();
365 fsc_.UpdateForPhyScreenPropertyChange();
366 ASSERT_NE(fsc_.foldScreenPolicy_, nullptr);
367 }
368
369 /**
370 * @tc.name: GetTentMode
371 * @tc.desc: test function :GetTentMode
372 * @tc.type: FUNC
373 */
374 HWTEST_F(FoldScreenControllerTest, GetTentMode, Function | SmallTest | Level1)
375 {
376 if (ssm_.IsFoldable()) {
377 ASSERT_NE(ssm_.foldScreenController_, nullptr);
378 auto tentMode = ssm_.foldScreenController_->GetTentMode();
379 ASSERT_EQ(tentMode, false);
380 }
381 }
382
383 /**
384 * @tc.name: OnTentModeChanged
385 * @tc.desc: test function :OnTentModeChanged
386 * @tc.type: FUNC
387 */
388 HWTEST_F(FoldScreenControllerTest, OnTentModeChanged, Function | SmallTest | Level1)
389 {
390 if (ssm_.IsFoldable()) {
391 bool isTentMode = false;
392 ssm_.foldScreenController_->OnTentModeChanged(isTentMode);
393 ASSERT_EQ(ssm_.foldScreenController_->GetTentMode(), false);
394 }
395 }
396 }
397 } // namespace Rosen
398 } // namespace OHOS
399
400