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 <parameter.h>
19 #include <parameters.h>
20 #include "screen_session_manager.h"
21 #include "screen_session_manager/include/fold_screen_controller/secondary_display_fold_policy.h"
22 #include "fold_screen_state_internel.h"
23 #include "window_manager_hilog.h"
24
25 using namespace testing;
26 using namespace testing::ext;
27
28 namespace OHOS {
29 namespace Rosen {
30 namespace {
31 constexpr uint32_t SLEEP_TIME_US = 100000;
32 constexpr uint32_t INDEX_TWO = 2;
33 constexpr uint32_t INDEX_THREE = 3;
34 constexpr uint32_t SECONDARY_INIT_PARAM_SIZE = 5;
35 #define ONLY_FOR_SECONDARY_DISPLAY_FOLD if (!FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) {return;}
36 }
37 namespace {
38 std::string g_errLog;
MyLogCallback(const LogType type,const LogLevel level,const unsigned int domain,const char * tag,const char * msg)39 void MyLogCallback(const LogType type, const LogLevel level, const unsigned int domain, const char* tag,
40 const char* msg)
41 {
42 g_errLog += msg;
43 }
44 }
45
46 class SecondaryDisplayFoldPolicyTest : public testing::Test {
47 public:
48 static void SetUpTestCase();
49 static void TearDownTestCase();
50 void SetUp() override;
51 void TearDown() override;
52 };
53
SetUpTestCase()54 void SecondaryDisplayFoldPolicyTest::SetUpTestCase()
55 {
56 }
57
TearDownTestCase()58 void SecondaryDisplayFoldPolicyTest::TearDownTestCase()
59 {
60 }
61
SetUp()62 void SecondaryDisplayFoldPolicyTest::SetUp()
63 {
64 }
65
TearDown()66 void SecondaryDisplayFoldPolicyTest::TearDown()
67 {
68 g_errLog.clear();
69 usleep(SLEEP_TIME_US);
70 }
71
72 namespace {
73 /**
74 * @tc.name: ChangeScreenDisplayMode
75 * @tc.desc: test function : ChangeScreenDisplayMode
76 * @tc.type: FUNC
77 */
78 HWTEST_F(SecondaryDisplayFoldPolicyTest, ChangeScreenDisplayMode, TestSize.Level1)
79 {
80 ONLY_FOR_SECONDARY_DISPLAY_FOLD
81 std::recursive_mutex displayInfoMutex;
82 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
83 DisplayModeChangeReason reason = DisplayModeChangeReason::DEFAULT;
84 SecondaryDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
85
86 FoldDisplayMode displayMode = FoldDisplayMode::UNKNOWN;
87 policy.ChangeScreenDisplayMode(displayMode, reason);
88 EXPECT_FALSE(policy.onBootAnimation_);
89
90 displayMode = FoldDisplayMode::MAIN;
91 policy.ChangeScreenDisplayMode(displayMode, reason);
92 EXPECT_FALSE(policy.onBootAnimation_);
93
94 displayMode = FoldDisplayMode::FULL;
95 policy.ChangeScreenDisplayMode(displayMode, reason);
96 EXPECT_FALSE(policy.onBootAnimation_);
97
98 displayMode = FoldDisplayMode::GLOBAL_FULL;
99 policy.ChangeScreenDisplayMode(displayMode, reason);
100 EXPECT_FALSE(policy.onBootAnimation_);
101
102 ScreenId screenId = 0;
103 auto screenSession = ScreenSessionManager::GetInstance().GetScreenSession(screenId);
104 if (nullptr == screenSession) {
105 return;
106 }
107 displayMode = FoldDisplayMode::MAIN;
108 policy.ChangeScreenDisplayMode(displayMode);
109 EXPECT_EQ(OHOS::system::GetParameter("persist.dms.device.status", "0"), "0");
110
111 displayMode = FoldDisplayMode::GLOBAL_FULL;
112 policy.ChangeScreenDisplayMode(displayMode);
113 EXPECT_EQ(OHOS::system::GetParameter("persist.dms.device.status", "0"), "4");
114 }
115
116 /**
117 * @tc.name: SendSensorResult
118 * @tc.desc: test function : SendSensorResult
119 * @tc.type: FUNC
120 */
121 HWTEST_F(SecondaryDisplayFoldPolicyTest, SendSensorResult, TestSize.Level1)
122 {
123 ONLY_FOR_SECONDARY_DISPLAY_FOLD
124 std::recursive_mutex displayInfoMutex;
125 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
126 SecondaryDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
127
128 FoldStatus foldStatus = FoldStatus::UNKNOWN;
129 policy.SendSensorResult(foldStatus);
130 EXPECT_FALSE(policy.onBootAnimation_);
131 }
132
133 /**
134 * @tc.name: SetOnBootAnimation
135 * @tc.desc: test function : SetOnBootAnimation
136 * @tc.type: FUNC
137 */
138 HWTEST_F(SecondaryDisplayFoldPolicyTest, SetOnBootAnimation, TestSize.Level1)
139 {
140 ONLY_FOR_SECONDARY_DISPLAY_FOLD
141 std::recursive_mutex displayInfoMutex;
142 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
143 SecondaryDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
144
145 policy.SetOnBootAnimation(false);
146 EXPECT_FALSE(policy.onBootAnimation_);
147
148 policy.SetOnBootAnimation(true);
149 EXPECT_TRUE(policy.onBootAnimation_);
150 }
151
152 /**
153 * @tc.name: RecoverWhenBootAnimationExit
154 * @tc.desc: test function : RecoverWhenBootAnimationExit
155 * @tc.type: FUNC
156 */
157 HWTEST_F(SecondaryDisplayFoldPolicyTest, RecoverWhenBootAnimationExit, TestSize.Level1)
158 {
159 ONLY_FOR_SECONDARY_DISPLAY_FOLD
160 std::recursive_mutex displayInfoMutex;
161 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
162 SecondaryDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
163
164 policy.currentDisplayMode_ = FoldDisplayMode::UNKNOWN;
165 policy.RecoverWhenBootAnimationExit();
166 EXPECT_FALSE(policy.onBootAnimation_);
167
168 policy.currentDisplayMode_ = FoldDisplayMode::GLOBAL_FULL;
169 policy.RecoverWhenBootAnimationExit();
170 EXPECT_FALSE(policy.onBootAnimation_);
171
172 policy.currentDisplayMode_ = FoldDisplayMode::FULL;
173 policy.RecoverWhenBootAnimationExit();
174 EXPECT_FALSE(policy.onBootAnimation_);
175
176 policy.currentDisplayMode_ = FoldDisplayMode::MAIN;
177 policy.RecoverWhenBootAnimationExit();
178 EXPECT_FALSE(policy.onBootAnimation_);
179 }
180
181 /**
182 * @tc.name: GetModeMatchStatus
183 * @tc.desc: test function : GetModeMatchStatus
184 * @tc.type: FUNC
185 */
186 HWTEST_F(SecondaryDisplayFoldPolicyTest, GetModeMatchStatus, TestSize.Level1)
187 {
188 ONLY_FOR_SECONDARY_DISPLAY_FOLD
189 std::recursive_mutex displayInfoMutex;
190 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
191 SecondaryDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
192 FoldDisplayMode displayMode = FoldDisplayMode::UNKNOWN;
193
194 policy.currentFoldStatus_ = FoldStatus::EXPAND;
195 displayMode = policy.GetModeMatchStatus();
196 EXPECT_EQ(FoldDisplayMode::FULL, displayMode);
197
198 policy.currentFoldStatus_ = FoldStatus::FOLDED;
199 displayMode = policy.GetModeMatchStatus();
200 EXPECT_EQ(FoldDisplayMode::MAIN, displayMode);
201
202 policy.currentFoldStatus_ = FoldStatus::HALF_FOLD;
203 displayMode = policy.GetModeMatchStatus();
204 EXPECT_EQ(FoldDisplayMode::FULL, displayMode);
205
206 policy.currentFoldStatus_ = FoldStatus::FOLD_STATE_EXPAND_WITH_SECOND_EXPAND;
207 displayMode = policy.GetModeMatchStatus();
208 EXPECT_EQ(FoldDisplayMode::GLOBAL_FULL, displayMode);
209
210 policy.currentFoldStatus_ = FoldStatus::FOLD_STATE_EXPAND_WITH_SECOND_HALF_FOLDED;
211 displayMode = policy.GetModeMatchStatus();
212 EXPECT_EQ(FoldDisplayMode::GLOBAL_FULL, displayMode);
213
214 policy.currentFoldStatus_ = FoldStatus::FOLD_STATE_FOLDED_WITH_SECOND_EXPAND;
215 displayMode = policy.GetModeMatchStatus();
216 EXPECT_EQ(FoldDisplayMode::MAIN, displayMode);
217
218 policy.currentFoldStatus_ = FoldStatus::FOLD_STATE_FOLDED_WITH_SECOND_HALF_FOLDED;
219 displayMode = policy.GetModeMatchStatus();
220 EXPECT_EQ(FoldDisplayMode::MAIN, displayMode);
221
222 policy.currentFoldStatus_ = FoldStatus::FOLD_STATE_HALF_FOLDED_WITH_SECOND_EXPAND;
223 displayMode = policy.GetModeMatchStatus();
224 EXPECT_EQ(FoldDisplayMode::GLOBAL_FULL, displayMode);
225
226 policy.currentFoldStatus_ = FoldStatus::FOLD_STATE_HALF_FOLDED_WITH_SECOND_HALF_FOLDED;
227 displayMode = policy.GetModeMatchStatus();
228 EXPECT_EQ(FoldDisplayMode::GLOBAL_FULL, displayMode);
229 }
230
231 /**
232 * @tc.name: ChangeSuperScreenDisplayMode01
233 * @tc.desc: test function : ChangeSuperScreenDisplayMode
234 * @tc.type: FUNC
235 */
236 HWTEST_F(SecondaryDisplayFoldPolicyTest, ChangeSuperScreenDisplayMode01, TestSize.Level1)
237 {
238 ONLY_FOR_SECONDARY_DISPLAY_FOLD
239 std::recursive_mutex displayInfoMutex;
240 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = std::make_shared<TaskScheduler>("test");
241 SecondaryDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
242 sptr<ScreenSession> screenSession = new ScreenSession;
243
244 std::vector<uint32_t> secondaryDisplayParams = policy.GetScreenParams();
245 EXPECT_EQ(secondaryDisplayParams.size(), SECONDARY_INIT_PARAM_SIZE);
246
247 FoldDisplayMode displayMode = FoldDisplayMode::MAIN;
248 policy.ChangeSuperScreenDisplayMode(screenSession, displayMode);
249 ScreenProperty screenProperty = screenSession->GetScreenProperty();
250 uint32_t currentWidth = screenProperty.GetBounds().rect_.GetWidth();
251 uint32_t currentHeight = screenProperty.GetBounds().rect_.GetHeight();
252 EXPECT_EQ(currentWidth, secondaryDisplayParams[0]);
253 EXPECT_EQ(currentHeight, secondaryDisplayParams[INDEX_THREE]);
254
255 displayMode = FoldDisplayMode::FULL;
256 policy.ChangeSuperScreenDisplayMode(screenSession, displayMode);
257 screenProperty = screenSession->GetScreenProperty();
258 currentWidth = screenProperty.GetBounds().rect_.GetWidth();
259 currentHeight = screenProperty.GetBounds().rect_.GetHeight();
260 EXPECT_EQ(currentWidth, secondaryDisplayParams[1]);
261 EXPECT_EQ(currentHeight, secondaryDisplayParams[INDEX_THREE]);
262
263 displayMode = FoldDisplayMode::GLOBAL_FULL;
264 policy.ChangeSuperScreenDisplayMode(screenSession, displayMode);
265 screenProperty = screenSession->GetScreenProperty();
266 currentWidth = screenProperty.GetBounds().rect_.GetWidth();
267 currentHeight = screenProperty.GetBounds().rect_.GetHeight();
268 EXPECT_EQ(currentWidth, secondaryDisplayParams[INDEX_TWO]);
269 EXPECT_EQ(currentHeight, secondaryDisplayParams[INDEX_THREE]);
270 }
271
272 /**
273 * @tc.name: SendPropertyChangeResult01
274 * @tc.desc: test function : SendPropertyChangeResult
275 * @tc.type: FUNC
276 */
277 HWTEST_F(SecondaryDisplayFoldPolicyTest, SendPropertyChangeResult01, TestSize.Level1)
278 {
279 ONLY_FOR_SECONDARY_DISPLAY_FOLD
280 std::recursive_mutex displayInfoMutex;
281 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = std::make_shared<TaskScheduler>("test");
282 SecondaryDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
283 sptr<ScreenSession> screenSession = new ScreenSession;
284 std::vector<uint32_t> secondaryDisplayParams = policy.GetScreenParams();
285 EXPECT_EQ(secondaryDisplayParams.size(), SECONDARY_INIT_PARAM_SIZE);
286
287 ScreenSessionManager::GetInstance().SetCoordinationFlag(true);
288 FoldDisplayMode displayMode = FoldDisplayMode::MAIN;
289 policy.SendPropertyChangeResult(screenSession, 0, ScreenPropertyChangeReason::UNDEFINED, displayMode);
290 ScreenProperty screenProperty = screenSession->GetScreenProperty();
291 uint32_t currentWidth = screenProperty.GetBounds().rect_.GetWidth();
292 uint32_t currentHeight = screenProperty.GetBounds().rect_.GetHeight();
293 EXPECT_EQ(currentWidth, secondaryDisplayParams[0]);
294 EXPECT_EQ(currentHeight, secondaryDisplayParams[INDEX_THREE]);
295 }
296
297 /**
298 * @tc.name: SendPropertyChangeResult06
299 * @tc.desc: test function : SendPropertyChangeResult
300 * @tc.type: FUNC
301 */
302 HWTEST_F(SecondaryDisplayFoldPolicyTest, SendPropertyChangeResult06, TestSize.Level1)
303 {
304 ONLY_FOR_SECONDARY_DISPLAY_FOLD
305 std::recursive_mutex displayInfoMutex;
306 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = std::make_shared<TaskScheduler>("test");
307 SecondaryDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
308 sptr<ScreenSession> screenSession = new ScreenSession;
309 std::vector<uint32_t> secondaryDisplayParams = policy.GetScreenParams();
310 EXPECT_EQ(secondaryDisplayParams.size(), SECONDARY_INIT_PARAM_SIZE);
311
312 FoldDisplayMode displayMode = FoldDisplayMode::FULL;
313 policy.SendPropertyChangeResult(screenSession, 0, ScreenPropertyChangeReason::UNDEFINED, displayMode);
314 EXPECT_EQ(screenSession->GetScreenAreaOffsetY(), secondaryDisplayParams[4]);
315 EXPECT_EQ(screenSession->GetScreenAreaHeight(), secondaryDisplayParams[1]);
316
317 displayMode = FoldDisplayMode::MAIN;
318 policy.SendPropertyChangeResult(screenSession, 0, ScreenPropertyChangeReason::UNDEFINED, displayMode);
319 EXPECT_EQ(screenSession->GetScreenAreaOffsetY(), 0);
320 EXPECT_EQ(screenSession->GetScreenAreaHeight(), secondaryDisplayParams[0]);
321
322 displayMode = FoldDisplayMode::GLOBAL_FULL;
323 policy.SendPropertyChangeResult(screenSession, 0, ScreenPropertyChangeReason::UNDEFINED, displayMode);
324 EXPECT_EQ(screenSession->GetScreenAreaOffsetY(), 0);
325 EXPECT_EQ(screenSession->GetScreenAreaHeight(), secondaryDisplayParams[2]);
326 }
327
328 /**
329 * @tc.name: SetStatusFullActiveRectAndTpFeature
330 * @tc.desc: test function : SetStatusFullActiveRectAndTpFeature
331 * @tc.type: FUNC
332 */
333 HWTEST_F(SecondaryDisplayFoldPolicyTest, SetStatusFullActiveRectAndTpFeature, TestSize.Level1)
334 {
335 ONLY_FOR_SECONDARY_DISPLAY_FOLD
336 std::recursive_mutex displayInfoMutex;
337 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
338 SecondaryDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
339 ScreenProperty property = policy.screenProperty_;
340 sptr<ScreenSession> screenSession = ScreenSessionManager::GetInstance().GetScreenSession(0);
341
342 policy.SetStatusFullActiveRectAndTpFeature(screenSession, property);
343 EXPECT_FALSE(policy.onBootAnimation_);
344 }
345
346 /**
347 * @tc.name: SetStatusMainActiveRectAndTpFeature
348 * @tc.desc: test function : SetStatusMainActiveRectAndTpFeature
349 * @tc.type: FUNC
350 */
351 HWTEST_F(SecondaryDisplayFoldPolicyTest, SetStatusMainActiveRectAndTpFeature, TestSize.Level1)
352 {
353 ONLY_FOR_SECONDARY_DISPLAY_FOLD
354 std::recursive_mutex displayInfoMutex;
355 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
356 SecondaryDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
357 ScreenProperty property = policy.screenProperty_;
358 sptr<ScreenSession> screenSession = ScreenSessionManager::GetInstance().GetScreenSession(0);
359
360 policy.SetStatusMainActiveRectAndTpFeature(screenSession, property);
361 EXPECT_FALSE(policy.onBootAnimation_);
362 }
363
364 /**
365 * @tc.name: SetStatusGlobalFullActiveRectAndTpFeature
366 * @tc.desc: test function : SetStatusGlobalFullActiveRectAndTpFeature
367 * @tc.type: FUNC
368 */
369 HWTEST_F(SecondaryDisplayFoldPolicyTest, SetStatusGlobalFullActiveRectAndTpFeature, TestSize.Level1)
370 {
371 ONLY_FOR_SECONDARY_DISPLAY_FOLD
372 std::recursive_mutex displayInfoMutex;
373 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
374 SecondaryDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
375 ScreenProperty property = policy.screenProperty_;
376 sptr<ScreenSession> screenSession = ScreenSessionManager::GetInstance().GetScreenSession(0);
377
378 policy.SetStatusGlobalFullActiveRectAndTpFeature(screenSession, property);
379 EXPECT_FALSE(policy.onBootAnimation_);
380 }
381
382 /**
383 * @tc.name: ReportFoldDisplayModeChange
384 * @tc.desc: test function : ReportFoldDisplayModeChange
385 * @tc.type: FUNC
386 */
387 HWTEST_F(SecondaryDisplayFoldPolicyTest, ReportFoldDisplayModeChange, TestSize.Level1)
388 {
389 ONLY_FOR_SECONDARY_DISPLAY_FOLD
390 std::recursive_mutex displayInfoMutex;
391 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
392 SecondaryDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
393
394 FoldDisplayMode displayMode = FoldDisplayMode::UNKNOWN;
395 policy.ReportFoldDisplayModeChange(displayMode);
396 EXPECT_EQ(FoldDisplayMode::UNKNOWN, displayMode);
397
398 displayMode = FoldDisplayMode::FULL;
399 policy.ReportFoldDisplayModeChange(displayMode);
400 EXPECT_NE(FoldDisplayMode::UNKNOWN, displayMode);
401 }
402
403 /**
404 * @tc.name: GetCurrentFoldCreaseRegion
405 * @tc.desc: test function : GetCurrentFoldCreaseRegion
406 * @tc.type: FUNC
407 */
408 HWTEST_F(SecondaryDisplayFoldPolicyTest, GetCurrentFoldCreaseRegion, TestSize.Level1)
409 {
410 ONLY_FOR_SECONDARY_DISPLAY_FOLD
411 std::recursive_mutex displayInfoMutex;
412 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
413 SecondaryDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
414
415 sptr<FoldCreaseRegion> foldCreaseRegion;
416 foldCreaseRegion = policy.GetCurrentFoldCreaseRegion();
417 EXPECT_EQ(policy.currentFoldCreaseRegion_, foldCreaseRegion);
418 }
419
420 /**
421 * @tc.name: InitScreenParams
422 * @tc.desc: test function : InitScreenParams
423 * @tc.type: FUNC
424 */
425 HWTEST_F(SecondaryDisplayFoldPolicyTest, InitScreenParams, TestSize.Level1)
426 {
427 ONLY_FOR_SECONDARY_DISPLAY_FOLD
428 std::recursive_mutex displayInfoMutex;
429 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
430 SecondaryDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
431
432 policy.InitScreenParams();
433 EXPECT_FALSE(policy.onBootAnimation_);
434 }
435
436 /**
437 * @tc.name: SetSecondaryDisplayModeChangeStatus01
438 * @tc.desc: test function : SetSecondaryDisplayModeChangeStatus
439 * @tc.type: FUNC
440 */
441 HWTEST_F(SecondaryDisplayFoldPolicyTest, SetSecondaryDisplayModeChangeStatus01, TestSize.Level1)
442 {
443 ONLY_FOR_SECONDARY_DISPLAY_FOLD
444 std::recursive_mutex displayInfoMutex;
445 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
446 SecondaryDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
447
448 policy.SetSecondaryDisplayModeChangeStatus(true);
449 EXPECT_EQ(policy.secondaryPengdingTask_, 2);
450
451 policy.SetSecondaryDisplayModeChangeStatus(false);
452 EXPECT_EQ(policy.secondaryPengdingTask_, 1);
453
454 policy.SetSecondaryDisplayModeChangeStatus(false);
455 EXPECT_EQ(policy.secondaryPengdingTask_, 0);
456 }
457
458 /**
459 * @tc.name: GetScreenSnapshotRect
460 * @tc.desc: test function : GetScreenSnapshotRect
461 * @tc.type: FUNC
462 */
463 HWTEST_F(SecondaryDisplayFoldPolicyTest, GetScreenSnapshotRect, TestSize.Level1)
464 {
465 ONLY_FOR_SECONDARY_DISPLAY_FOLD
466 std::recursive_mutex displayInfoMutex;
467 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
468 SecondaryDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
469
470 policy.currentDisplayMode_ = FoldDisplayMode::UNKNOWN;
471 Drawing::Rect snapshotRect = {0, 0, 0, 0};
472 Drawing::Rect targetSnapshotRect = policy.GetScreenSnapshotRect();
473 EXPECT_EQ(snapshotRect, targetSnapshotRect);
474
475 policy.currentDisplayMode_ = FoldDisplayMode::MAIN;
476 snapshotRect = {0, 0, 2232, 1008};
477 targetSnapshotRect = policy.GetScreenSnapshotRect();
478 EXPECT_EQ(snapshotRect, targetSnapshotRect);
479
480 policy.currentDisplayMode_ = FoldDisplayMode::FULL;
481 snapshotRect = {0, 1136, 2232, 3184};
482 targetSnapshotRect = policy.GetScreenSnapshotRect();
483 EXPECT_EQ(snapshotRect, targetSnapshotRect);
484
485 policy.currentDisplayMode_ = FoldDisplayMode::GLOBAL_FULL;
486 snapshotRect = {0, 0, 2232, 3184};
487 targetSnapshotRect = policy.GetScreenSnapshotRect();
488 EXPECT_EQ(snapshotRect, targetSnapshotRect);
489 }
490
491 /**
492 * @tc.name: SetMainScreenRegion
493 * @tc.desc: test function : SetMainScreenRegion
494 * @tc.type: FUNC
495 */
496 HWTEST_F(SecondaryDisplayFoldPolicyTest, SetMainScreenRegion, TestSize.Level1)
497 {
498 ONLY_FOR_SECONDARY_DISPLAY_FOLD
499 std::recursive_mutex displayInfoMutex;
500 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
501 SecondaryDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
502
503 policy.currentDisplayMode_ = FoldDisplayMode::UNKNOWN;
504 DMRect mainScreenRegion = {0, 0, 0, 0};
505 DMRect targetMainScreenRegion = {0, 0, 0, 0};
506 policy.SetMainScreenRegion(mainScreenRegion);
507 EXPECT_EQ(mainScreenRegion, targetMainScreenRegion);
508
509 policy.currentDisplayMode_ = FoldDisplayMode::MAIN;
510 mainScreenRegion = {0, 0, 0, 0};
511 targetMainScreenRegion = {0, 0, 2232, 1008};
512 policy.SetMainScreenRegion(mainScreenRegion);
513 EXPECT_EQ(mainScreenRegion, targetMainScreenRegion);
514
515 policy.currentDisplayMode_ = FoldDisplayMode::FULL;
516 mainScreenRegion = {0, 0, 0, 0};
517 targetMainScreenRegion = {0, 1136, 2232, 2048};
518 policy.SetMainScreenRegion(mainScreenRegion);
519 EXPECT_EQ(mainScreenRegion, targetMainScreenRegion);
520
521 policy.currentDisplayMode_ = FoldDisplayMode::GLOBAL_FULL;
522 mainScreenRegion = {0, 0, 0, 0};
523 targetMainScreenRegion = {0, 0, 2232, 3184};
524 policy.SetMainScreenRegion(mainScreenRegion);
525 EXPECT_EQ(mainScreenRegion, targetMainScreenRegion);
526 }
527
528 /**
529 * @tc.name: ChangeScreenDisplayModeToCoordinationFeatureTest
530 * @tc.desc: ChangeScreenDisplayModeToCoordinationFeatureTest
531 * @tc.type: FUNC
532 */
533 HWTEST_F(SecondaryDisplayFoldPolicyTest, ChangeScreenDisplayModeToCoordinationFeatureTest, TestSize.Level1)
534 {
535 if (!FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) {
536 GTEST_SKIP();
537 }
538 std::recursive_mutex displayInfoMutex;
539 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
540 SecondaryDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
541
542 policy.screenPowerTaskScheduler_ = std::make_shared<TaskScheduler>("Test");
543 policy.ChangeScreenDisplayModeToCoordination();
544 EXPECT_EQ(ScreenSessionManager::GetInstance().isCoordinationFlag_, true);
545 }
546
547 /**
548 * @tc.name: CloseCoordinationScreenFeatureTest
549 * @tc.desc: CloseCoordinationScreenFeatureTest
550 * @tc.type: FUNC
551 */
552 HWTEST_F(SecondaryDisplayFoldPolicyTest, CloseCoordinationScreenFeatureTest, TestSize.Level1)
553 {
554 if (FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) {
555 std::recursive_mutex displayInfoMutex;
556 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
557 SecondaryDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
558
559 policy.screenPowerTaskScheduler_ = std::make_shared<TaskScheduler>("Test");
560 policy.ChangeScreenDisplayModeToCoordination();
561 policy.CloseCoordinationScreen();
562 EXPECT_EQ(ScreenSessionManager::GetInstance().isCoordinationFlag_, false);
563 }
564 }
565
566 /**
567 * @tc.name: AddOrRemoveDisplayNodeToTreeFeatureTest
568 * @tc.desc: AddOrRemoveDisplayNodeToTreeFeatureTest
569 * @tc.type: FUNC
570 */
571 HWTEST_F(SecondaryDisplayFoldPolicyTest, AddOrRemoveDisplayNodeToTreeFeatureTest, TestSize.Level1)
572 {
573 if (!FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) {
574 GTEST_SKIP();
575 }
576 std::recursive_mutex displayInfoMutex;
577 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
578 SecondaryDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
579 // test invalid screen
580 ScreenId screenId = -1;
581 int32_t command = 1;
582 policy.AddOrRemoveDisplayNodeToTree(screenId, command);
583 EXPECT_EQ(ScreenSessionManager::GetInstance().isCoordinationFlag_, false);
584
585 // add to tree
586 screenId = 0;
587 command = 1;
588 policy.AddOrRemoveDisplayNodeToTree(screenId, command);
589 EXPECT_EQ(ScreenSessionManager::GetInstance().GetScreenSession(screenId), nullptr);
590
591 // move from tree
592 screenId = 0;
593 command = 0;
594 policy.AddOrRemoveDisplayNodeToTree(screenId, command);
595 EXPECT_EQ(ScreenSessionManager::GetInstance().GetScreenSession(screenId), nullptr);
596 }
597
598 /**
599 * @tc.name: ExitCoordinationFeatureTest
600 * @tc.desc: ExitCoordinationFeatureTest
601 * @tc.type: FUNC
602 */
603 HWTEST_F(SecondaryDisplayFoldPolicyTest, ExitCoordinationFeatureTest, TestSize.Level1)
604 {
605 if (FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) {
606 std::recursive_mutex displayInfoMutex;
607 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
608 SecondaryDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
609
610 policy.currentFoldStatus_ = FoldStatus::EXPAND;
611 policy.ChangeScreenDisplayModeToCoordination();
612 policy.ExitCoordination();
613 EXPECT_FALSE(ScreenSessionManager::GetInstance().GetCoordinationFlag());
614 }
615 }
616
617 /**
618 * @tc.name: SetStatusConditionalActiveRectAndTpFeature
619 * @tc.desc: test function : SetStatusGlobalFullActiveRectAndTpFeature
620 * @tc.type: FUNC
621 */
622 HWTEST_F(SecondaryDisplayFoldPolicyTest, SetStatusConditionalActiveRectAndTpFeature, TestSize.Level1)
623 {
624 if (!FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) {
625 GTEST_SKIP();
626 }
627 std::recursive_mutex displayInfoMutex;
628 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
629 SecondaryDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
630 ScreenProperty property = policy.screenProperty_;
631
632 policy.SetStatusConditionalActiveRectAndTpFeature(property);
633 EXPECT_FALSE(policy.onBootAnimation_);
634 }
635
636 /**
637 * @tc.name: InitPositionZInfosFeature
638 * @tc.desc: test function : InitPositionZInfosFeature
639 * @tc.type: FUNC
640 */
641 HWTEST_F(SecondaryDisplayFoldPolicyTest, InitPositionZInfosFeature, TestSize.Level1)
642 {
643 if (!FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) {
644 GTEST_SKIP();
645 }
646 std::recursive_mutex displayInfoMutex;
647 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
648 SecondaryDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
649
650 policy.dualDisplayNodePositionZ_.clear();
651 policy.InitPositionZInfos();
652 EXPECT_FALSE(policy.dualDisplayNodePositionZ_.empty());
653
654 policy.InitPositionZInfos();
655 EXPECT_FALSE(policy.dualDisplayNodePositionZ_.empty());
656 }
657
658 /**
659 * @tc.name: UpdatePositionZForDualDisplayNodeFeature
660 * @tc.desc: test function : UpdatePositionZForDualDisplayNodeFeature
661 * @tc.type: FUNC
662 */
663 HWTEST_F(SecondaryDisplayFoldPolicyTest, UpdatePositionZForDualDisplayNodeFeature, TestSize.Level1)
664 {
665 if (!FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) {
666 GTEST_SKIP();
667 }
668 std::recursive_mutex displayInfoMutex;
669 std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
670 SecondaryDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler);
671
672 policy.UpdatePositionZForDualDisplayNode();
673 EXPECT_FALSE(policy.dualDisplayNodePositionZ_.empty());
674 }
675 }
676 } // namespace Rosen
677 } // namespace OHOS