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