1 /*
2 * Copyright (c) 2022-2025 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 "display_manager.h"
19 #include "display_manager_adapter.h"
20 #include "display_manager_proxy.h"
21 #include "scene_board_judgement.h"
22 #include "screen_manager.h"
23 #include "window_scene.h"
24
25 using namespace testing;
26 using namespace testing::ext;
27
28 namespace OHOS::Rosen {
29 class DisplayManagerAdapterUtTest : 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 DisplayManagerAdapterUtTest::SetUpTestCase()
38 {
39 }
40
TearDownTestCase()41 void DisplayManagerAdapterUtTest::TearDownTestCase()
42 {
43 }
44
SetUp()45 void DisplayManagerAdapterUtTest::SetUp()
46 {
47 }
48
TearDown()49 void DisplayManagerAdapterUtTest::TearDown()
50 {
51 }
52
53 namespace {
54 /**
55 * @tc.name: GetDisplayInfo
56 * @tc.desc: test nullptr
57 * @tc.type: FUNC
58 */
59 HWTEST_F(DisplayManagerAdapterUtTest, GetDisplayInfo, TestSize.Level1)
60 {
61 sptr<DisplayInfo> info = SingletonContainer::Get<DisplayManagerAdapter>().GetDisplayInfo(DISPLAY_ID_INVALID);
62 ASSERT_EQ(info, nullptr);
63 }
64
65 /**
66 * @tc.name: GetCutoutInfo
67 * @tc.desc: test nullptr
68 * @tc.type: FUNC
69 */
70 HWTEST_F(DisplayManagerAdapterUtTest, GetCutoutInfo, TestSize.Level1)
71 {
72 sptr<CutoutInfo> info = SingletonContainer::Get<DisplayManagerAdapter>().GetCutoutInfo(DISPLAY_ID_INVALID);
73 ASSERT_EQ(info, nullptr);
74 }
75
76 /**
77 * @tc.name: GetCutoutInfoWithRotation
78 * @tc.desc: test nullptr
79 * @tc.type: FUNC
80 */
81 HWTEST_F(DisplayManagerAdapterUtTest, GetCutoutInfoWithRotation, Function | SmallTest | Level2)
82 {
83 int32_t rotation = 0;
84 sptr<CutoutInfo> info = SingletonContainer::Get<DisplayManagerAdapter>().
85 GetCutoutInfoWithRotation(DISPLAY_ID_INVALID, rotation);
86 ASSERT_EQ(info, nullptr);
87 }
88
89 /**
90 * @tc.name: GetScreenSupportedColorGamuts
91 * @tc.desc: test success
92 * @tc.type: FUNC
93 */
94 HWTEST_F(DisplayManagerAdapterUtTest, GetScreenSupportedColorGamuts, TestSize.Level1)
95 {
96 std::vector<ScreenColorGamut> colorGamuts;
97 DMError err = SingletonContainer::Get<ScreenManagerAdapter>().GetScreenSupportedColorGamuts(0, colorGamuts);
98 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
99 ASSERT_EQ(err, DMError::DM_ERROR_RENDER_SERVICE_FAILED);
100 } else {
101 ASSERT_EQ(err, DMError::DM_OK);
102 }
103 }
104
105 /**
106 * @tc.name: SetScreenColorGamut
107 * @tc.desc: test success
108 * @tc.type: FUNC
109 */
110 HWTEST_F(DisplayManagerAdapterUtTest, SetScreenColorGamut, TestSize.Level1)
111 {
112 std::vector<ScreenColorGamut> colorGamuts;
113 DMError err = SingletonContainer::Get<ScreenManagerAdapter>().SetScreenColorGamut(0, -1);
114 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
115 ASSERT_EQ(err, DMError::DM_ERROR_RENDER_SERVICE_FAILED);
116 } else {
117 ASSERT_EQ(err, DMError::DM_ERROR_INVALID_PARAM);
118 }
119 }
120
121 /**
122 * @tc.name: GetScreenColorGamut
123 * @tc.desc: test success
124 * @tc.type: FUNC
125 */
126 HWTEST_F(DisplayManagerAdapterUtTest, GetScreenColorGamut, TestSize.Level1)
127 {
128 ScreenColorGamut colorGamut;
129 DMError err = SingletonContainer::Get<ScreenManagerAdapter>().GetScreenColorGamut(0, colorGamut);
130 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
131 ASSERT_EQ(err, DMError::DM_ERROR_RENDER_SERVICE_FAILED);
132 } else {
133 ASSERT_EQ(err, DMError::DM_OK);
134 }
135 }
136
137 /**
138 * @tc.name: GetScreenGamutMap
139 * @tc.desc: test success
140 * @tc.type: FUNC
141 */
142 HWTEST_F(DisplayManagerAdapterUtTest, GetScreenGamutMap, TestSize.Level1)
143 {
144 ScreenGamutMap gamutMap;
145 DMError err = SingletonContainer::Get<ScreenManagerAdapter>().GetScreenGamutMap(0, gamutMap);
146 ASSERT_EQ(err, DMError::DM_ERROR_RENDER_SERVICE_FAILED);
147 }
148
149 /**
150 * @tc.name: SetScreenGamutMap
151 * @tc.desc: test success
152 * @tc.type: FUNC
153 */
154 HWTEST_F(DisplayManagerAdapterUtTest, SetScreenGamutMap, TestSize.Level1)
155 {
156 DMError err = SingletonContainer::Get<ScreenManagerAdapter>().SetScreenGamutMap(0, GAMUT_MAP_CONSTANT);
157 ASSERT_EQ(err, DMError::DM_ERROR_RENDER_SERVICE_FAILED);
158 }
159
160 /**
161 * @tc.name: SetScreenColorTransform
162 * @tc.desc: test success
163 * @tc.type: FUNC
164 */
165 HWTEST_F(DisplayManagerAdapterUtTest, SetScreenColorTransform, TestSize.Level1)
166 {
167 DMError err = SingletonContainer::Get<ScreenManagerAdapter>().SetScreenColorTransform(0);
168 ASSERT_EQ(err, DMError::DM_OK);
169 }
170
171 /**
172 * @tc.name: SetFreeze
173 * @tc.desc: test success
174 * @tc.type: FUNC
175 */
176 HWTEST_F(DisplayManagerAdapterUtTest, SetFreeze, TestSize.Level1)
177 {
178 std::vector<DisplayId> displayIds;
179 bool ret = SingletonContainer::Get<DisplayManagerAdapter>().SetFreeze(displayIds, false);
180 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
181 ASSERT_TRUE(ret);
182 } else {
183 ASSERT_FALSE(ret);
184 }
185 }
186
187 /**
188 * @tc.name: GetScreenGroupInfoById
189 * @tc.desc: test nullptr
190 * @tc.type: FUNC
191 */
192 HWTEST_F(DisplayManagerAdapterUtTest, GetScreenGroupInfoById, TestSize.Level1)
193 {
194 auto info = SingletonContainer::Get<ScreenManagerAdapter>().GetScreenGroupInfoById(SCREEN_ID_INVALID);
195 ASSERT_EQ(info, nullptr);
196 }
197
198 /**
199 * @tc.name: GetScreenInfo
200 * @tc.desc: test nullptr
201 * @tc.type: FUNC
202 */
203 HWTEST_F(DisplayManagerAdapterUtTest, GetScreenInfo, TestSize.Level1)
204 {
205 sptr<ScreenInfo> info = SingletonContainer::Get<ScreenManagerAdapter>().GetScreenInfo(SCREEN_ID_INVALID);
206 ASSERT_EQ(info, nullptr);
207 }
208
209 /**
210 * @tc.name: OnRemoteDied
211 * @tc.desc: test nullptr
212 * @tc.type: FUNC
213 */
214 HWTEST_F(DisplayManagerAdapterUtTest, OnRemoteDied, TestSize.Level1)
215 {
216 sptr<IRemoteObject::DeathRecipient> dmsDeath_ = nullptr;
217 dmsDeath_ = new(std::nothrow) DMSDeathRecipient(SingletonContainer::Get<ScreenManagerAdapter>());
218 dmsDeath_->OnRemoteDied(nullptr);
219 EXPECT_NE(nullptr, dmsDeath_);
220 }
221
222 /**
223 * @tc.name: OnRemoteDied01
224 * @tc.desc: test nullptr
225 * @tc.type: FUNC
226 */
227 HWTEST_F(DisplayManagerAdapterUtTest, OnRemoteDied01, TestSize.Level1)
228 {
229 sptr<IRemoteObject::DeathRecipient> dmsDeath =
230 new (std::nothrow) DMSDeathRecipient(SingletonContainer::Get<ScreenManagerAdapter>());
231 SingletonContainer::Get<ScreenManagerAdapter>().InitDMSProxy();
232 sptr<IRemoteObject> remoteObject;
233 if (SceneBoardJudgement::IsSceneBoardEnabled()) {
234 remoteObject = SingletonContainer::Get<ScreenManagerAdapter>().screenSessionManagerServiceProxy_->AsObject();
235 } else {
236 remoteObject = SingletonContainer::Get<DisplayManagerAdapter>().displayManagerServiceProxy_->AsObject();
237 }
238 wptr<IRemoteObject> wptrDeath = remoteObject;
239 dmsDeath->OnRemoteDied(wptrDeath);
240 EXPECT_NE(nullptr, dmsDeath);
241 }
242
243 /**
244 * @tc.name: Clear
245 * @tc.desc: test success
246 * @tc.type: FUNC
247 */
248 HWTEST_F(DisplayManagerAdapterUtTest, Clear, TestSize.Level1)
249 {
250 if (SceneBoardJudgement::IsSceneBoardEnabled()) {
251 SingletonContainer::Get<ScreenManagerAdapter>().InitDMSProxy();
252 SingletonContainer::Get<ScreenManagerAdapter>().Clear();
253 ASSERT_FALSE(SingletonContainer::Get<ScreenManagerAdapter>().isProxyValid_);
254 } else {
255 SingletonContainer::Get<DisplayManagerAdapter>().InitDMSProxy();
256 SingletonContainer::Get<DisplayManagerAdapter>().Clear();
257 ASSERT_FALSE(SingletonContainer::Get<DisplayManagerAdapter>().isProxyValid_);
258 }
259 }
260
261 /**
262 * @tc.name: Clear01
263 * @tc.desc: test success
264 * @tc.type: FUNC
265 */
266 HWTEST_F(DisplayManagerAdapterUtTest, Clear01, TestSize.Level1)
267 {
268 if (SceneBoardJudgement::IsSceneBoardEnabled()) {
269 SingletonContainer::Get<ScreenManagerAdapter>().InitDMSProxy();
270 SingletonContainer::Get<ScreenManagerAdapter>().screenSessionManagerServiceProxy_ = nullptr;
271 SingletonContainer::Get<ScreenManagerAdapter>().Clear();
272 ASSERT_FALSE(SingletonContainer::Get<ScreenManagerAdapter>().isProxyValid_);
273 } else {
274 SingletonContainer::Get<DisplayManagerAdapter>().InitDMSProxy();
275 SingletonContainer::Get<DisplayManagerAdapter>().displayManagerServiceProxy_ = nullptr;
276 SingletonContainer::Get<DisplayManagerAdapter>().Clear();
277 ASSERT_FALSE(SingletonContainer::Get<DisplayManagerAdapter>().isProxyValid_);
278 }
279 }
280
281 /**
282 * @tc.name: DisableMirror
283 * @tc.desc: DisableMirror test
284 * @tc.type: FUNC
285 */
286 HWTEST_F(DisplayManagerAdapterUtTest, DisableMirror, TestSize.Level1)
287 {
288 DMError ret = SingletonContainer::Get<ScreenManagerAdapter>().DisableMirror(false);
289 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
290 ASSERT_EQ(ret, DMError::DM_ERROR_INVALID_PERMISSION);
291 } else {
292 ASSERT_EQ(ret, DMError::DM_OK);
293 }
294 }
295
296 /**
297 * @tc.name: HasImmersiveWindow
298 * @tc.desc: test HasImmersiveWindow
299 * @tc.type: FUNC
300 */
301 HWTEST_F(DisplayManagerAdapterUtTest, HasImmersiveWindow, TestSize.Level1)
302 {
303 bool immersive = false;
304 DMError ret = SingletonContainer::Get<DisplayManagerAdapter>().HasImmersiveWindow(0u, immersive);
305 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
306 ASSERT_EQ(ret, DMError::DM_ERROR_DEVICE_NOT_SUPPORT);
307 } else {
308 ASSERT_EQ(ret, DMError::DM_OK);
309 }
310 }
311
312 /**
313 * @tc.name: GetPixelFormat
314 * @tc.desc: test success
315 * @tc.type: FUNC
316 */
317 HWTEST_F(DisplayManagerAdapterUtTest, GetPixelFormat, TestSize.Level1)
318 {
319 GraphicPixelFormat pixelFormat = GraphicPixelFormat::GRAPHIC_PIXEL_FMT_CLUT8;
320 DMError err = SingletonContainer::Get<ScreenManagerAdapter>().GetPixelFormat(0, pixelFormat);
321 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
322 ASSERT_EQ(err, DMError::DM_ERROR_DEVICE_NOT_SUPPORT);
323 } else {
324 ASSERT_EQ(err, DMError::DM_OK);
325 }
326 }
327
328 /**
329 * @tc.name: SetPixelFormat
330 * @tc.desc: test success
331 * @tc.type: FUNC
332 */
333 HWTEST_F(DisplayManagerAdapterUtTest, SetPixelFormat, TestSize.Level1)
334 {
335 GraphicPixelFormat pixelFormat = GraphicPixelFormat::GRAPHIC_PIXEL_FMT_CLUT8;
336 DMError err = SingletonContainer::Get<ScreenManagerAdapter>().SetPixelFormat(0, pixelFormat);
337 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
338 ASSERT_EQ(err, DMError::DM_ERROR_DEVICE_NOT_SUPPORT);
339 } else {
340 ASSERT_EQ(err, DMError::DM_OK);
341 }
342 }
343
344 /**
345 * @tc.name: GetSupportedHDRFormats
346 * @tc.desc: test success
347 * @tc.type: FUNC
348 */
349 HWTEST_F(DisplayManagerAdapterUtTest, GetSupportedHDRFormats, TestSize.Level1)
350 {
351 std::vector<ScreenHDRFormat> hdrFormats;
352 DMError err = SingletonContainer::Get<ScreenManagerAdapter>().GetSupportedHDRFormats(0, hdrFormats);
353 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
354 ASSERT_EQ(err, DMError::DM_ERROR_DEVICE_NOT_SUPPORT);
355 } else {
356 ASSERT_EQ(err, DMError::DM_OK);
357 }
358 }
359
360 /**
361 * @tc.name: GetScreenHDRFormat
362 * @tc.desc: test success
363 * @tc.type: FUNC
364 */
365 HWTEST_F(DisplayManagerAdapterUtTest, GetScreenHDRFormat, TestSize.Level1)
366 {
367 ScreenHDRFormat hdrFormat = ScreenHDRFormat::NOT_SUPPORT_HDR;
368 DMError err = SingletonContainer::Get<ScreenManagerAdapter>().GetScreenHDRFormat(0, hdrFormat);
369 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
370 ASSERT_EQ(err, DMError::DM_ERROR_DEVICE_NOT_SUPPORT);
371 } else {
372 ASSERT_EQ(err, DMError::DM_OK);
373 }
374 }
375
376 /**
377 * @tc.name: SetScreenHDRFormat
378 * @tc.desc: test success
379 * @tc.type: FUNC
380 */
381 HWTEST_F(DisplayManagerAdapterUtTest, SetScreenHDRFormat, TestSize.Level1)
382 {
383 DMError err = SingletonContainer::Get<ScreenManagerAdapter>().SetScreenHDRFormat(0, 0);
384 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
385 ASSERT_EQ(err, DMError::DM_ERROR_DEVICE_NOT_SUPPORT);
386 } else {
387 ASSERT_EQ(err, DMError::DM_OK);
388 }
389 }
390
391 /**
392 * @tc.name: GetSupportedColorSpaces
393 * @tc.desc: test success
394 * @tc.type: FUNC
395 */
396 HWTEST_F(DisplayManagerAdapterUtTest, GetSupportedColorSpaces, TestSize.Level1)
397 {
398 std::vector<GraphicCM_ColorSpaceType> colorSpaces;
399 DMError err = SingletonContainer::Get<ScreenManagerAdapter>().GetSupportedColorSpaces(0, colorSpaces);
400 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
401 ASSERT_EQ(err, DMError::DM_ERROR_DEVICE_NOT_SUPPORT);
402 } else {
403 ASSERT_EQ(err, DMError::DM_OK);
404 }
405 }
406
407 /**
408 * @tc.name: GetScreenColorSpace
409 * @tc.desc: test success
410 * @tc.type: FUNC
411 */
412 HWTEST_F(DisplayManagerAdapterUtTest, GetScreenColorSpace, TestSize.Level1)
413 {
414 GraphicCM_ColorSpaceType colorSpace = GraphicCM_ColorSpaceType::GRAPHIC_CM_COLORSPACE_NONE;
415 DMError err = SingletonContainer::Get<ScreenManagerAdapter>().GetScreenColorSpace(0, colorSpace);
416 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
417 ASSERT_EQ(err, DMError::DM_ERROR_DEVICE_NOT_SUPPORT);
418 } else {
419 ASSERT_EQ(err, DMError::DM_OK);
420 }
421 }
422
423 /**
424 * @tc.name: SetScreenColorSpace
425 * @tc.desc: test success
426 * @tc.type: FUNC
427 */
428 HWTEST_F(DisplayManagerAdapterUtTest, SetScreenColorSpace, TestSize.Level1)
429 {
430 GraphicCM_ColorSpaceType colorSpace = GraphicCM_ColorSpaceType::GRAPHIC_CM_COLORSPACE_NONE;
431 DMError err = SingletonContainer::Get<ScreenManagerAdapter>().SetScreenColorSpace(0, colorSpace);
432 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
433 ASSERT_EQ(err, DMError::DM_ERROR_DEVICE_NOT_SUPPORT);
434 } else {
435 ASSERT_EQ(err, DMError::DM_ERROR_RENDER_SERVICE_FAILED);
436 }
437 }
438
439 /**
440 * @tc.name: DestroyVirtualScreen
441 * @tc.desc: test success
442 * @tc.type: FUNC
443 */
444 HWTEST_F(DisplayManagerAdapterUtTest, DestroyVirtualScreen, TestSize.Level1)
445 {
446 VirtualScreenOption defaultOption = { "virtualScreen01", 480, 320, 2.0, nullptr, 0 };
447 ScreenId id = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption);
448 DMError err = SingletonContainer::Get<ScreenManagerAdapter>().DestroyVirtualScreen(id);
449 ASSERT_EQ(err, DMError::DM_OK);
450 }
451
452 /**
453 * @tc.name: SetVirtualMirrorScreenCanvasRotation
454 * @tc.desc: test SetVirtualMirrorScreenCanvasRotation
455 * @tc.type: FUNC
456 */
457 HWTEST_F(DisplayManagerAdapterUtTest, SetVirtualMirrorScreenCanvasRotation, TestSize.Level1)
458 {
459 bool canvasRotation = false;
460 DMError ret = SingletonContainer::Get<ScreenManagerAdapter>().
461 SetVirtualMirrorScreenCanvasRotation(0, canvasRotation);
462 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
463 ASSERT_EQ(ret, DMError::DM_OK);
464 } else {
465 ASSERT_EQ(ret, DMError::DM_ERROR_RENDER_SERVICE_FAILED);
466 }
467 }
468
469 /**
470 * @tc.name: SetScreenRotationLocked
471 * @tc.desc: test SetScreenRotationLocked
472 * @tc.type: FUNC
473 */
474 HWTEST_F(DisplayManagerAdapterUtTest, SetScreenRotationLocked, TestSize.Level1)
475 {
476 bool isLocked = false;
477 DMError ret = SingletonContainer::Get<ScreenManagerAdapter>().SetScreenRotationLocked(isLocked);
478 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
479 ASSERT_EQ(ret, DMError::DM_OK);
480 } else {
481 ASSERT_EQ(ret, DMError::DM_OK);
482 }
483 }
484
485 /**
486 * @tc.name: IsScreenRotationLocked
487 * @tc.desc: test IsScreenRotationLocked
488 * @tc.type: FUNC
489 */
490 HWTEST_F(DisplayManagerAdapterUtTest, IsScreenRotationLocked, TestSize.Level1)
491 {
492 bool isLocked = false;
493 DMError ret = SingletonContainer::Get<ScreenManagerAdapter>().IsScreenRotationLocked(isLocked);
494 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
495 ASSERT_EQ(ret, DMError::DM_OK);
496 } else {
497 ASSERT_EQ(ret, DMError::DM_OK);
498 }
499 }
500
501 /**
502 * @tc.name: SetSpecifiedScreenPower
503 * @tc.desc: test SetSpecifiedScreenPower
504 * @tc.type: FUNC
505 */
506 HWTEST_F(DisplayManagerAdapterUtTest, SetSpecifiedScreenPower, TestSize.Level1)
507 {
508 ScreenPowerState state = ScreenPowerState::POWER_ON;
509 PowerStateChangeReason reason = PowerStateChangeReason::POWER_BUTTON;
510 bool ret = SingletonContainer::Get<ScreenManagerAdapter>().SetSpecifiedScreenPower(0, state, reason);
511 if (SceneBoardJudgement::IsSceneBoardEnabled()) {
512 ASSERT_TRUE(ret);
513 } else {
514 ASSERT_FALSE(ret);
515 }
516 }
517
518 /**
519 * @tc.name: SetOrientation
520 * @tc.desc: SetOrientation success
521 * @tc.type: FUNC
522 */
523 HWTEST_F(DisplayManagerAdapterUtTest, SetOrientation, TestSize.Level1)
524 {
525 Orientation orientation = Orientation::BEGIN;
526 DMError err = SingletonContainer::Get<ScreenManagerAdapter>().SetOrientation(0, orientation);
527 ASSERT_EQ(err, DMError::DM_OK);
528 }
529
530 /**
531 * @tc.name: WakeUpBegin
532 * @tc.desc: test WakeUpBegin
533 * @tc.type: FUNC
534 */
535 HWTEST_F(DisplayManagerAdapterUtTest, WakeUpBegin, TestSize.Level1)
536 {
537 PowerStateChangeReason reason = PowerStateChangeReason::POWER_BUTTON;
538 bool ret = SingletonContainer::Get<DisplayManagerAdapter>().WakeUpBegin(reason);
539 ASSERT_TRUE(ret);
540 }
541
542 /**
543 * @tc.name: WakeUpEnd
544 * @tc.desc: test WakeUpEnd
545 * @tc.type: FUNC
546 */
547 HWTEST_F(DisplayManagerAdapterUtTest, WakeUpEnd, TestSize.Level1)
548 {
549 bool ret = SingletonContainer::Get<DisplayManagerAdapter>().WakeUpEnd();
550 ASSERT_TRUE(ret);
551 }
552
553 /**
554 * @tc.name: SuspendBegin
555 * @tc.desc: test SuspendBegin
556 * @tc.type: FUNC
557 */
558 HWTEST_F(DisplayManagerAdapterUtTest, SuspendBegin, TestSize.Level1)
559 {
560 PowerStateChangeReason reason = PowerStateChangeReason::POWER_BUTTON;
561 bool ret = SingletonContainer::Get<DisplayManagerAdapter>().SuspendBegin(reason);
562 ASSERT_TRUE(ret);
563 }
564
565 /**
566 * @tc.name: SuspendEnd
567 * @tc.desc: test SuspendEnd
568 * @tc.type: FUNC
569 */
570 HWTEST_F(DisplayManagerAdapterUtTest, SuspendEnd, TestSize.Level1)
571 {
572 bool ret = SingletonContainer::Get<DisplayManagerAdapter>().SuspendEnd();
573 ASSERT_TRUE(ret);
574 }
575
576 /**
577 * @tc.name: SetDisplayState
578 * @tc.desc: test SetDisplayState
579 * @tc.type: FUNC
580 */
581 HWTEST_F(DisplayManagerAdapterUtTest, SetDisplayState, TestSize.Level1)
582 {
583 DisplayState state = DisplayState::OFF;
584 bool ret = SingletonContainer::Get<DisplayManagerAdapter>().SetDisplayState(state);
585 if (SceneBoardJudgement::IsSceneBoardEnabled()) {
586 ASSERT_TRUE(ret);
587 }
588 }
589
590 /**
591 * @tc.name: MakeMirror
592 * @tc.desc: test success
593 * @tc.type: FUNC
594 */
595 HWTEST_F(DisplayManagerAdapterUtTest, MakeMirror, TestSize.Level1)
596 {
597 std::vector<ScreenId> mirrorScreenId;
598 ScreenId screenGroupId;
599 DMError err = SingletonContainer::Get<ScreenManagerAdapter>().MakeMirror(0, mirrorScreenId, screenGroupId);
600 ASSERT_EQ(err, DMError::DM_ERROR_INVALID_PARAM);
601 }
602
603 /**
604 * @tc.name: StopMirror
605 * @tc.desc: test success
606 * @tc.type: FUNC
607 */
608 HWTEST_F(DisplayManagerAdapterUtTest, StopMirror, TestSize.Level1)
609 {
610 std::vector<ScreenId> mirrorScreenIds;
611 DMError err = SingletonContainer::Get<ScreenManagerAdapter>().StopMirror(mirrorScreenIds);
612 ASSERT_EQ(err, DMError::DM_OK);
613 }
614
615 /**
616 * @tc.name: HasPrivateWindow
617 * @tc.desc: test success
618 * @tc.type: FUNC
619 */
620 HWTEST_F(DisplayManagerAdapterUtTest, HasPrivateWindow, TestSize.Level1)
621 {
622 bool hasPrivateWindow = false;
623 DMError err = SingletonContainer::Get<DisplayManagerAdapter>().HasPrivateWindow(0, hasPrivateWindow);
624 ASSERT_EQ(DMError::DM_OK, err);
625 }
626
627 /**
628 * @tc.name: AddSurfaceNodeToDisplay
629 * @tc.desc: test success
630 * @tc.type: FUNC
631 */
632 HWTEST_F(DisplayManagerAdapterUtTest, AddSurfaceNodeToDisplay, TestSize.Level1)
633 {
634 RSSurfaceNodeConfig rsSurfaceNodeConfig;
635 std::shared_ptr<RSSurfaceNode> surfaceNode = std::make_shared<RSSurfaceNode>(rsSurfaceNodeConfig, true, 0);
636 DMError err = SingletonContainer::Get<DisplayManagerAdapter>().AddSurfaceNodeToDisplay(0, surfaceNode);
637 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
638 ASSERT_EQ(DMError::DM_ERROR_NULLPTR, err);
639 } else {
640 ASSERT_EQ(DMError::DM_OK, err);
641 }
642 }
643
644 /**
645 * @tc.name: RemoveSurfaceNodeFromDisplay
646 * @tc.desc: test success
647 * @tc.type: FUNC
648 */
649 HWTEST_F(DisplayManagerAdapterUtTest, RemoveSurfaceNodeFromDisplay, TestSize.Level1)
650 {
651 RSSurfaceNodeConfig rsSurfaceNodeConfig;
652 std::shared_ptr<RSSurfaceNode> surfaceNode = std::make_shared<RSSurfaceNode>(rsSurfaceNodeConfig, true, 0);
653 DMError err = SingletonContainer::Get<DisplayManagerAdapter>().RemoveSurfaceNodeFromDisplay(0, surfaceNode);
654 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
655 ASSERT_EQ(DMError::DM_ERROR_NULLPTR, err);
656 } else {
657 ASSERT_EQ(DMError::DM_OK, err);
658 }
659 }
660
661 /**
662 * @tc.name: MakeExpand
663 * @tc.desc: test success
664 * @tc.type: FUNC
665 */
666 HWTEST_F(DisplayManagerAdapterUtTest, MakeExpand, TestSize.Level1)
667 {
668 std::vector<ScreenId> screenId;
669 std::vector<Point> startPoint;
670 ScreenId screenGroupId;
671 DMError err = SingletonContainer::Get<ScreenManagerAdapter>().MakeExpand(screenId, startPoint, screenGroupId);
672 ASSERT_EQ(err, DMError::DM_ERROR_INVALID_PARAM);
673 }
674
675 /**
676 * @tc.name: StopExpand
677 * @tc.desc: test success
678 * @tc.type: FUNC
679 */
680 HWTEST_F(DisplayManagerAdapterUtTest, StopExpand, TestSize.Level1)
681 {
682 std::vector<ScreenId> expandScreenIds;
683 DMError err = SingletonContainer::Get<ScreenManagerAdapter>().StopExpand(expandScreenIds);
684 ASSERT_EQ(err, DMError::DM_OK);
685 }
686
687 /**
688 * @tc.name: RemoveVirtualScreenFromGroup
689 * @tc.desc: test success
690 * @tc.type: FUNC
691 */
692 HWTEST_F(DisplayManagerAdapterUtTest, RemoveVirtualScreenFromGroup, TestSize.Level1)
693 {
694 std::vector<ScreenId> screens;
695 int resultValue = 0;
__anon0147157f0202() 696 std::function<void()> func = [&]() {
697 SingletonContainer::Get<ScreenManagerAdapter>().RemoveVirtualScreenFromGroup(screens);
698 resultValue = 1;
699 };
700 func();
701 ASSERT_EQ(resultValue, 1);
702 }
703
704 /**
705 * @tc.name: SetScreenActiveMode
706 * @tc.desc: test success
707 * @tc.type: FUNC
708 */
709 HWTEST_F(DisplayManagerAdapterUtTest, SetScreenActiveMode, TestSize.Level1)
710 {
711 VirtualScreenOption defaultOption = {"virtualScreen02", 480, 320, 2.0, nullptr, 0};
712 ScreenId id = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption);
713 DMError err = SingletonContainer::Get<ScreenManagerAdapter>().SetScreenActiveMode(id, 100);
714 ASSERT_EQ(err, DMError::DM_OK);
715 SingletonContainer::Get<ScreenManagerAdapter>().DestroyVirtualScreen(id);
716 }
717
718 /**
719 * @tc.name: SetVirtualPixelRatio
720 * @tc.desc: test success
721 * @tc.type: FUNC
722 */
723 HWTEST_F(DisplayManagerAdapterUtTest, SetVirtualPixelRatio, TestSize.Level1)
724 {
725 VirtualScreenOption defaultOption = {"virtualScreen03", 480, 320, 2.0, nullptr, 0};
726 ScreenId id = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption);
727 DMError err = SingletonContainer::Get<ScreenManagerAdapter>().SetVirtualPixelRatio(id, 0);
728 ASSERT_EQ(err, DMError::DM_OK);
729 SingletonContainer::Get<ScreenManagerAdapter>().DestroyVirtualScreen(id);
730 }
731
732 /**
733 * @tc.name: SetResolution
734 * @tc.desc: test success
735 * @tc.type: FUNC
736 */
737 HWTEST_F(DisplayManagerAdapterUtTest, SetResolution, TestSize.Level1)
738 {
739 VirtualScreenOption defaultOption = {"virtualScreen04", 480, 320, 2.0, nullptr, 0};
740 ScreenId id = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption);
741 DMError err = SingletonContainer::Get<ScreenManagerAdapter>().SetResolution(id, 70, 100, 1);
742 ASSERT_EQ(err, DMError::DM_OK);
743 SingletonContainer::Get<ScreenManagerAdapter>().DestroyVirtualScreen(id);
744 }
745
746 /**
747 * @tc.name: ResizeVirtualScreen
748 * @tc.desc: test success
749 * @tc.type: FUNC
750 */
751 HWTEST_F(DisplayManagerAdapterUtTest, ResizeVirtualScreen, TestSize.Level1)
752 {
753 DMError err = SingletonContainer::Get<ScreenManagerAdapter>().ResizeVirtualScreen(0, 70, 100);
754 ASSERT_EQ(err, DMError::DM_OK);
755 }
756
757 /**
758 * @tc.name: MakeUniqueScreen
759 * @tc.desc: test success
760 * @tc.type: FUNC
761 */
762 HWTEST_F(DisplayManagerAdapterUtTest, MakeUniqueScreen, TestSize.Level1)
763 {
764 std::vector<ScreenId> screenIds;
765 std::vector<DisplayId> displayIds;
766 DMError err = SingletonContainer::Get<ScreenManagerAdapter>().MakeUniqueScreen(screenIds, displayIds);
767 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
768 ASSERT_EQ(err, DMError::DM_ERROR_DEVICE_NOT_SUPPORT);
769 } else {
770 ASSERT_EQ(err, DMError::DM_ERROR_INVALID_PARAM);
771 }
772 }
773
774 /**
775 * @tc.name: GetAvailableArea
776 * @tc.desc: test success
777 * @tc.type: FUNC
778 */
779 HWTEST_F(DisplayManagerAdapterUtTest, GetAvailableArea, TestSize.Level1)
780 {
781 DMRect area{};
782 DMError err = SingletonContainer::Get<DisplayManagerAdapter>().GetAvailableArea(0, area);
783 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
784 ASSERT_EQ(err, DMError::DM_ERROR_DEVICE_NOT_SUPPORT);
785 } else {
786 ASSERT_EQ(err, DMError::DM_OK);
787 }
788 }
789
790 /**
791 * @tc.name: GetAllDisplayPhysicalResolution
792 * @tc.desc: test success
793 * @tc.type: FUNC
794 */
795 HWTEST_F(DisplayManagerAdapterUtTest, GetAllDisplayPhysicalResolution, TestSize.Level1)
796 {
797 std::vector<DisplayPhysicalResolution> allSize =
798 SingletonContainer::Get<DisplayManagerAdapter>().GetAllDisplayPhysicalResolution();
799 ASSERT_FALSE(allSize.empty());
800 }
801
802 /**
803 * @tc.name: SetDisplayScale
804 * @tc.desc: SetDisplayScale test
805 * @tc.type: FUNC
806 */
807 HWTEST_F(DisplayManagerAdapterUtTest, SetDisplayScale, TestSize.Level1)
808 {
809 auto& displayManagerAdapter = SingletonContainer::Get<DisplayManagerAdapter>();
810 constexpr float scaleX = 1.0f;
811 constexpr float scaleY = 1.0f;
812 constexpr float pivotX = 0.5f;
813 constexpr float pivotY = 0.5f;
814 sptr<DisplayInfo> displayInfo = displayManagerAdapter.GetDefaultDisplayInfo();
815 ASSERT_NE(displayInfo, nullptr);
816 ScreenId screenId = displayInfo->GetScreenId();
817 displayManagerAdapter.SetDisplayScale(screenId, scaleX, scaleY, pivotX, pivotY);
818 }
819
820 /**
821 * @tc.name: GetPrimaryDisplayInfo
822 * @tc.desc: GetPrimaryDisplayInfo test
823 * @tc.type: FUNC
824 */
825 HWTEST_F(DisplayManagerAdapterUtTest, GetPrimaryDisplayInfo, TestSize.Level1)
826 {
827 sptr<DisplayInfo> displayInfo = SingletonContainer::Get<DisplayManagerAdapter>().GetPrimaryDisplayInfo();
828 ASSERT_NE(displayInfo, nullptr);
829 }
830
831 /**
832 * @tc.name: SetScreenSkipProtectedWindow
833 * @tc.desc: SetScreenSkipProtectedWindow test
834 * @tc.type: FUNC
835 */
836 HWTEST_F(DisplayManagerAdapterUtTest, SetScreenSkipProtectedWindow, TestSize.Level1)
837 {
838 const std::vector<ScreenId> screenIds = {1001, 1002};
839 bool isEnable = true;
840 auto result = SingletonContainer::Get<ScreenManagerAdapter>().SetScreenSkipProtectedWindow(screenIds, isEnable);
841 ASSERT_EQ(result, DMError::DM_OK);
842 }
843
844 /**
845 * @tc.name: GetDisplayCapability
846 * @tc.desc: GetDisplayCapability test success
847 * @tc.type: FUNC
848 */
849 HWTEST_F(DisplayManagerAdapterUtTest, GetDisplayCapability, TestSize.Level1)
850 {
851 std::string capabilitInfo;
852 auto result = SingletonContainer::Get<DisplayManagerAdapter>().GetDisplayCapability(capabilitInfo);
853 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
854 ASSERT_EQ(result, DMError::DM_ERROR_DEVICE_NOT_SUPPORT);
855 } else {
856 ASSERT_EQ(result, DMError::DM_OK);
857 }
858 }
859
860 /**
861 * @tc.name: GetVisibleAreaDisplayInfoById
862 * @tc.desc: Test GetVisibleAreaDisplayInfoById function with invalid displayId.
863 * @tc.type: FUNC
864 */
865 HWTEST_F(DisplayManagerAdapterUtTest, GetVisibleAreaDisplayInfoById, TestSize.Level1)
866 {
867 sptr<DisplayInfo> info =
868 SingletonContainer::Get<DisplayManagerAdapter>().GetVisibleAreaDisplayInfoById(DISPLAY_ID_INVALID);
869 EXPECT_EQ(info, nullptr);
870 }
871
872 /**
873 * @tc.name: GetExpandAvailableArea
874 * @tc.desc: test success
875 * @tc.type: FUNC
876 */
877 HWTEST_F(DisplayManagerAdapterUtTest, GetExpandAvailableArea, TestSize.Level1)
878 {
879 DMRect area;
880 DMError err = SingletonContainer::Get<DisplayManagerAdapter>().GetExpandAvailableArea(0, area);
881 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
882 EXPECT_EQ(err, DMError::DM_ERROR_DEVICE_NOT_SUPPORT);
883 } else {
884 EXPECT_EQ(err, DMError::DM_OK);
885 }
886 }
887 }
888 }
889