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 "common_test_utils.h"
19 #include "display_manager_adapter.h"
20 #include "display_manager_config.h"
21 #include "display_manager_service.h"
22 #include "mock_rs_display_node.h"
23 #include "scene_board_judgement.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 }
33 class DisplayManagerServiceTest : public testing::Test {
34 public:
35 static void SetUpTestCase();
36 static void TearDownTestCase();
37 void SetUp() override;
38 void TearDown() override;
39
40 static std::unique_ptr<DisplayManagerService> dms_;
41 static constexpr DisplayId DEFAULT_DISPLAY = 0ULL;
42 static constexpr DisplayId DEFAULT_SCREEN = 0ULL;
43 };
44
45 std::unique_ptr<DisplayManagerService> DisplayManagerServiceTest::dms_ = nullptr;
46
SetUpTestCase()47 void DisplayManagerServiceTest::SetUpTestCase()
48 {
49 dms_ = std::make_unique<DisplayManagerService>();
50
51 dms_->abstractScreenController_->defaultRsScreenId_ = 0;
52 dms_->abstractScreenController_->screenIdManager_.rs2DmsScreenIdMap_.clear();
53 dms_->abstractScreenController_->screenIdManager_.rs2DmsScreenIdMap_ = {
54 {0, 0}
55 };
56 dms_->abstractScreenController_->screenIdManager_.dms2RsScreenIdMap_.clear();
57 dms_->abstractScreenController_->screenIdManager_.dms2RsScreenIdMap_ = {
58 {0, 0}
59 };
60 const char** perms = new const char *[1];
61 perms[0] = "ohos.permission.CAPTURE_SCREEN";
62 CommonTestUtils::SetAceessTokenPermission("DisplayManagerServiceTest", perms, 1);
63 }
64
TearDownTestCase()65 void DisplayManagerServiceTest::TearDownTestCase()
66 {
67 dms_ = nullptr;
68 }
69
SetUp()70 void DisplayManagerServiceTest::SetUp()
71 {
72 }
73
TearDown()74 void DisplayManagerServiceTest::TearDown()
75 {
76 usleep(SLEEP_TIME_US);
77 }
78
79 class DisplayChangeListenerTest : public IDisplayChangeListener {
80 public:
OnDisplayStateChange(DisplayId defaultDisplayId,sptr<DisplayInfo> displayInfo,const std::map<DisplayId,sptr<DisplayInfo>> & displayInfoMap,DisplayStateChangeType type)81 void OnDisplayStateChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
82 const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type) override {};
OnScreenshot(DisplayId displayId)83 void OnScreenshot(DisplayId displayId) override {};
84 };
85
86 class WindowInfoQueriedListenerTest : public IWindowInfoQueriedListener {
87 public:
HasPrivateWindow(DisplayId id,bool & hasPrivateWindow)88 void HasPrivateWindow(DisplayId id, bool& hasPrivateWindow) override {};
89 };
90
91 namespace {
92
93 /**
94 * @tc.name: Dump
95 * @tc.desc: DMS dump
96 * @tc.type: FUNC
97 */
98 HWTEST_F(DisplayManagerServiceTest, Dump, TestSize.Level1)
99 {
100 std::vector<std::u16string> args;
101 ASSERT_EQ(static_cast<int>(DMError::DM_ERROR_INVALID_PARAM), dms_->Dump(-1, args));
102 }
103
104 /**
105 * @tc.name: Config
106 * @tc.desc: DMS config
107 * @tc.type: FUNC
108 */
109 HWTEST_F(DisplayManagerServiceTest, Config, TestSize.Level1)
110 {
111 DisplayManagerConfig::intNumbersConfig_.clear();
112 DisplayManagerConfig::enableConfig_.clear();
113 DisplayManagerConfig::stringConfig_.clear();
114 dms_->ConfigureDisplayManagerService();
115
116 DisplayManagerConfig::intNumbersConfig_ = {
117 {"dpi", {320}},
118 {"defaultDeviceRotationOffset", {90}},
119 {"curvedScreenBoundary", {20, 30, 40, 50}},
120 {"buildInDefaultOrientation", {90}},
121 {"waterfallAreaCompressionSizeWhenHorzontal", {90}}
122 };
123 DisplayManagerConfig::enableConfig_ = {
124 {"isWaterfallDisplay", false},
125 {"isWaterfallAreaCompressionEnableWhenHorizontal", false}
126 };
127 DisplayManagerConfig::stringConfig_ = {
128 {"defaultDisplayCutoutPath", "/path"}
129 };
130
131 dms_->ConfigureDisplayManagerService();
132
133 ASSERT_NE(dms_->displayCutoutController_, nullptr);
134 ASSERT_FALSE(dms_->displayCutoutController_->isWaterfallDisplay_);
135 ASSERT_EQ(dms_->displayCutoutController_->curvedScreenBoundary_[0],
136 DisplayManagerConfig::intNumbersConfig_["curvedScreenBoundary"][0]);
137 }
138
139 /**
140 * @tc.name: DisplayChange
141 * @tc.desc: DMS display change
142 * @tc.type: FUNC
143 */
144 HWTEST_F(DisplayManagerServiceTest, DisplayChange, TestSize.Level1)
145 {
146 std::map<DisplayId, sptr<DisplayInfo>> displayInfoMap;
147 sptr<DisplayChangeListenerTest> displayChangeListener = new DisplayChangeListenerTest();
148 ASSERT_NE(nullptr, displayChangeListener);
149 dms_->RegisterDisplayChangeListener(displayChangeListener);
150
151 dms_->RegisterDisplayChangeListener(nullptr);
152 dms_->NotifyDisplayStateChange(0, nullptr, displayInfoMap, DisplayStateChangeType::SIZE_CHANGE);
153 dms_->NotifyScreenshot(0);
154 }
155
156 /**
157 * @tc.name: HasPrivateWindow
158 * @tc.desc: DMS has private window
159 * @tc.type: FUNC
160 */
161 HWTEST_F(DisplayManagerServiceTest, HasPrivateWindow, TestSize.Level1)
162 {
163 bool hasPrivateWindow = false;
164 dms_->abstractDisplayController_->abstractDisplayMap_.clear();
165 dms_->abstractDisplayController_->abstractDisplayMap_ = {
166 {1, nullptr}
167 };
168 ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, dms_->HasPrivateWindow(0, hasPrivateWindow));
169
170 dms_->RegisterWindowInfoQueriedListener(nullptr);
171 ASSERT_EQ(DMError::DM_ERROR_NULLPTR, dms_->HasPrivateWindow(1, hasPrivateWindow));
172 }
173
174 /**
175 * @tc.name: GetScreenIdByDisplayId
176 * @tc.desc: DMS get screen id by display id
177 * @tc.type: FUNC
178 */
179 HWTEST_F(DisplayManagerServiceTest, GetScreenIdByDisplayId, TestSize.Level1)
180 {
181 std::string name = "testDisplay";
182 sptr<SupportedScreenModes> info = new SupportedScreenModes();
183 sptr<AbstractScreen> absScreen = new AbstractScreen(dms_->abstractScreenController_, name, 0, 0);
184 sptr<AbstractDisplay> absDisplay = new AbstractDisplay(0, info, absScreen);
185 dms_->abstractDisplayController_->abstractDisplayMap_.clear();
186 dms_->abstractDisplayController_->abstractDisplayMap_ = {
187 {0, absDisplay}
188 };
189
190 absDisplay->screenId_ = 0;
191 EXPECT_EQ(SCREEN_ID_INVALID, dms_->GetScreenIdByDisplayId(1));
192 EXPECT_EQ(0, dms_->GetScreenIdByDisplayId(0));
193 }
194
195 /**
196 * @tc.name: GetScreenInfoById01
197 * @tc.desc: DMS get screen info by id
198 * @tc.type: FUNC
199 */
200 HWTEST_F(DisplayManagerServiceTest, GetScreenInfoById01, TestSize.Level1)
201 {
202 ScreenId screenId = dms_->GetScreenIdByDisplayId(1000);
203 auto ret = dms_->GetScreenInfoById(screenId);
204 EXPECT_EQ(ret, nullptr);
205 }
206
207 /**
208 * @tc.name: GetScreenBrightness
209 * @tc.desc: DMS get screen brightness
210 * @tc.type: FUNC
211 */
212 HWTEST_F(DisplayManagerServiceTest, GetScreenBrightness, TestSize.Level1)
213 {
214 auto ret = dms_->GetScreenBrightness(0);
215 EXPECT_GT(static_cast<int32_t>(ret), -1);
216 }
217
218 /**
219 * @tc.name: GetDisplayInfo
220 * @tc.desc: DMS get display info
221 * @tc.type: FUNC
222 */
223 HWTEST_F(DisplayManagerServiceTest, GetDisplayInfo, TestSize.Level1)
224 {
225 // build abstractDisplayController_ env
226 std::string name = "testDisplay";
227 sptr<SupportedScreenModes> info = new SupportedScreenModes();
228 sptr<AbstractScreen> absScreen = new AbstractScreen(dms_->abstractScreenController_, name, 0, 0);
229 sptr<AbstractDisplay> absDisplay = new AbstractDisplay(0, info, absScreen);
230
231 dms_->abstractDisplayController_->abstractDisplayMap_.clear();
232 ASSERT_EQ(nullptr, dms_->GetDefaultDisplayInfo());
233
234 dms_->abstractDisplayController_->abstractDisplayMap_ = {
235 {0, absDisplay}
236 };
237 ASSERT_EQ(absDisplay->name_, dms_->GetDefaultDisplayInfo()->name_);
238
239 ASSERT_EQ(nullptr, dms_->GetDisplayInfoById(1));
240 ASSERT_EQ(absDisplay->name_, dms_->GetDisplayInfoById(0)->name_);
241
242 ASSERT_EQ(nullptr, dms_->GetDisplayInfoByScreen(1));
243 ASSERT_EQ(absDisplay->name_, dms_->GetDisplayInfoByScreen(0)->name_);
244
245 absDisplay->screenId_ = 0;
246
247 ASSERT_EQ(SCREEN_ID_INVALID, dms_->GetScreenIdByDisplayId(1));
248 ASSERT_EQ(0, dms_->GetScreenIdByDisplayId(0));
249
250 ASSERT_EQ(nullptr, dms_->GetScreenInfoById(1));
251 ASSERT_EQ(nullptr, dms_->GetScreenInfoById(0));
252
253 ASSERT_EQ(nullptr, dms_->GetScreenGroupInfoById(1));
254 ASSERT_EQ(nullptr, dms_->GetScreenGroupInfoById(0));
255
256 ASSERT_EQ(SCREEN_ID_INVALID, dms_->GetScreenGroupIdByScreenId(1));
257 ASSERT_EQ(SCREEN_ID_INVALID, dms_->GetScreenGroupIdByScreenId(0));
258
259 dms_->GetAllDisplayIds();
260 std::vector<sptr<ScreenInfo>> screenInfos;
261 dms_->GetAllScreenInfos(screenInfos);
262
263 dms_->abstractDisplayController_->abstractDisplayMap_.clear();
264 }
265
266 /**
267 * @tc.name: VirtualScreen
268 * @tc.desc: DMS virtual screen
269 * @tc.type: FUNC
270 */
271 HWTEST_F(DisplayManagerServiceTest, VirtualScreen, TestSize.Level1)
272 {
273 VirtualScreenOption option{};
274 ASSERT_EQ(-1, dms_->CreateVirtualScreen(option, nullptr));
275
276 ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, dms_->SetVirtualScreenSurface(-1, nullptr));
277 ASSERT_EQ(DMError::DM_ERROR_RENDER_SERVICE_FAILED, dms_->SetVirtualScreenSurface(0, nullptr));
278
279 std::vector<ScreenId> screens;
280 dms_->RemoveVirtualScreenFromGroup(screens);
281
282 DMError result = dms_->DestroyVirtualScreen(10086);
283 EXPECT_EQ(result, DMError::DM_ERROR_INVALID_CALLING);
284 }
285
286 /**
287 * @tc.name: OrientationAndRotation
288 * @tc.desc: DMS set orientation and rotation
289 * @tc.type: FUNC
290 */
291 HWTEST_F(DisplayManagerServiceTest, OrientationAndRotation, TestSize.Level1)
292 {
293 Orientation orientation = Orientation::VERTICAL;
294 ASSERT_TRUE(DMError::DM_OK != dms_->SetOrientation(0, orientation));
295 orientation = Orientation::SENSOR_VERTICAL;
296 ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, dms_->SetOrientation(0, orientation));
297
298 orientation = Orientation::UNSPECIFIED;
299 ASSERT_TRUE(DMError::DM_OK != dms_->SetOrientation(0, orientation));
300 ASSERT_EQ(DMError::DM_ERROR_NULLPTR, dms_->SetOrientationFromWindow(0, orientation, true));
301 Rotation rotation = Rotation::ROTATION_0;
302 ASSERT_EQ(false, dms_->SetRotationFromWindow(0, rotation, true));
303 }
304
305 /**
306 * @tc.name: ScreenColor
307 * @tc.desc: DMS screen color
308 * @tc.type: FUNC
309 */
310 HWTEST_F(DisplayManagerServiceTest, ScreenColor, TestSize.Level1)
311 {
312 std::vector<ScreenColorGamut> colorGamuts;
313 ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, dms_->GetScreenSupportedColorGamuts(SCREEN_ID_INVALID, colorGamuts));
314 ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, dms_->GetScreenSupportedColorGamuts(0, colorGamuts));
315
316 ScreenColorGamut colorGamut = ScreenColorGamut::COLOR_GAMUT_SRGB;
317 ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, dms_->GetScreenColorGamut(SCREEN_ID_INVALID, colorGamut));
318 ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, dms_->GetScreenColorGamut(0, colorGamut));
319
320 colorGamut = ScreenColorGamut::COLOR_GAMUT_SRGB;
321 ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, dms_->SetScreenColorGamut(SCREEN_ID_INVALID, colorGamut));
322 ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, dms_->SetScreenColorGamut(0, colorGamut));
323
324 ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, dms_->SetScreenColorGamut(SCREEN_ID_INVALID, 0));
325 ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, dms_->SetScreenColorGamut(0, 0));
326
327 ScreenGamutMap gamutMap;
328 ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, dms_->GetScreenGamutMap(SCREEN_ID_INVALID, gamutMap));
329 ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, dms_->GetScreenGamutMap(0, gamutMap));
330
331 ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, dms_->SetScreenGamutMap(SCREEN_ID_INVALID, gamutMap));
332 ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, dms_->SetScreenGamutMap(0, gamutMap));
333
334 ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, dms_->SetScreenColorTransform(SCREEN_ID_INVALID));
335 ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, dms_->SetScreenColorTransform(0));
336 }
337
338 /**
339 * @tc.name: RegisterDisplayManagerAgent
340 * @tc.desc: DMS register display manager agent
341 * @tc.type: FUNC
342 */
343 HWTEST_F(DisplayManagerServiceTest, RegisterDisplayManagerAgent, TestSize.Level1)
344 {
345 DisplayManagerAgentType type = DisplayManagerAgentType::DISPLAY_STATE_LISTENER;
346
347 ASSERT_EQ(DMError::DM_ERROR_NULLPTR, dms_->RegisterDisplayManagerAgent(nullptr, type));
348 ASSERT_EQ(DMError::DM_ERROR_NULLPTR, dms_->UnregisterDisplayManagerAgent(nullptr, type));
349 }
350
351 /**
352 * @tc.name: ScreenPower
353 * @tc.desc: DMS screen power
354 * @tc.type: FUNC
355 */
356 HWTEST_F(DisplayManagerServiceTest, ScreenPower, TestSize.Level1)
357 {
358 PowerStateChangeReason reason = PowerStateChangeReason::POWER_BUTTON;
359 ScreenPowerState state = ScreenPowerState::POWER_ON;
360 DisplayState displayState = DisplayState::ON;
361
362 ASSERT_EQ(false, dms_->WakeUpBegin(reason));
363 ASSERT_EQ(false, dms_->WakeUpEnd());
364
365 ASSERT_EQ(false, dms_->SuspendBegin(reason));
366 ASSERT_EQ(false, dms_->SuspendEnd());
367
368 ASSERT_EQ(false, dms_->SetScreenPowerForAll(state, reason));
369
370 ScreenId dmsScreenId = 2;
371 ScreenPowerState result = dms_->GetScreenPower(dmsScreenId);
372 EXPECT_EQ(result, ScreenPowerState::INVALID_STATE);
373
374 ASSERT_EQ(true, dms_->SetDisplayState(displayState));
375 ASSERT_EQ(DisplayState::ON, dms_->GetDisplayState(0));
376 }
377
378 /**
379 * @tc.name: RsDisplayNode
380 * @tc.desc: DMS rs display node
381 * @tc.type: FUNC
382 */
383 HWTEST_F(DisplayManagerServiceTest, RsDisplayNode, TestSize.Level1)
384 {
385 struct RSSurfaceNodeConfig config;
386 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
387 dms_->UpdateRSTree(DISPLAY_ID_INVALID, DISPLAY_ID_INVALID, surfaceNode, true, false);
388 EXPECT_EQ(dms_->abstractScreenController_->GetAbstractScreen(DISPLAY_ID_INVALID), nullptr);
389 dms_->UpdateRSTree(0, 0, surfaceNode, true, false);
390 }
391
392 /**
393 * @tc.name: MirrorAndExpand
394 * @tc.desc: DMS mirror
395 * @tc.type: FUNC
396 */
397 HWTEST_F(DisplayManagerServiceTest, MirrorAndExpand, TestSize.Level1)
398 {
399 std::vector<ScreenId> mirrorScreenIds;
400 ScreenId screenGroupId1 = DISPLAY_ID_INVALID;
401 dms_->MakeMirror(DISPLAY_ID_INVALID, mirrorScreenIds, screenGroupId1);
402 ASSERT_EQ(SCREEN_ID_INVALID, screenGroupId1);
403 ASSERT_EQ(DMError::DM_OK, dms_->StopMirror(mirrorScreenIds));
404
405 std::vector<ScreenId> expandScreenIds;
406 std::vector<Point> startPoints;
407 ScreenId screenGroupId2 = DISPLAY_ID_INVALID;
408 dms_->MakeExpand(expandScreenIds, startPoints, screenGroupId2);
409 ASSERT_EQ(SCREEN_ID_INVALID, screenGroupId2);
410 ASSERT_EQ(DMError::DM_OK, dms_->StopExpand(expandScreenIds));
411 }
412
413 /**
414 * @tc.name: ScreenActiveMode
415 * @tc.desc: DMS mirror
416 * @tc.type: FUNC
417 */
418 HWTEST_F(DisplayManagerServiceTest, ScreenActiveMode, TestSize.Level1)
419 {
420 ASSERT_EQ(DMError::DM_ERROR_NULLPTR, dms_->SetScreenActiveMode(SCREEN_ID_INVALID, 0));
421 }
422
423 /**
424 * @tc.name: VirtualPixelRatio
425 * @tc.desc: DMS mirror
426 * @tc.type: FUNC
427 */
428 HWTEST_F(DisplayManagerServiceTest, VirtualPixelRatio, TestSize.Level1)
429 {
430 ASSERT_TRUE(DMError::DM_OK != dms_->SetVirtualPixelRatio(SCREEN_ID_INVALID, 0.f));
431 }
432
433 /**
434 * @tc.name: AddSurfaceNodeToDisplay | RemoveSurfaceNodeFromDisplay
435 * @tc.desc: add/remove surfaceNode to/from display
436 * @tc.type: FUNC
437 */
438 HWTEST_F(DisplayManagerServiceTest, AddAndRemoveSurfaceNode, TestSize.Level1)
439 {
440 std::shared_ptr<RSSurfaceNode> surfaceNode = nullptr;
441 DMError result = dms_->RemoveSurfaceNodeFromDisplay(DEFAULT_DISPLAY, surfaceNode);
442 EXPECT_EQ(result, DMError::DM_ERROR_NULLPTR);
443 }
444
445 /**
446 * @tc.name: NotifyDisplayEvent
447 * @tc.desc: NotifyDisplayEvent
448 * @tc.type: FUNC
449 */
450 HWTEST_F(DisplayManagerServiceTest, NotifyDisplayEvent, TestSize.Level1)
451 {
452 DisplayEvent event = DisplayEvent::KEYGUARD_DRAWN;
453 dms_->NotifyDisplayEvent(event);
454 ASSERT_NE(dms_->displayPowerController_, nullptr);
455 }
456
457 /**
458 * @tc.name: SetFreeze
459 * @tc.desc: SetFreeze
460 * @tc.type: FUNC
461 */
462 HWTEST_F(DisplayManagerServiceTest, SetFreeze, TestSize.Level1)
463 {
464 std::vector<DisplayId> displayIds = { 0 };
465 bool isFreeze = false;
466 dms_->SetFreeze(displayIds, isFreeze);
467 ASSERT_NE(dms_->abstractDisplayController_, nullptr);
468 }
469
470 /**
471 * @tc.name: AddSurfaceNodeToDisplay
472 * @tc.desc: AddSurfaceNodeToDisplay
473 * @tc.type: FUNC
474 */
475 HWTEST_F(DisplayManagerServiceTest, AddSurfaceNodeToDisplay, TestSize.Level1)
476 {
477 DisplayId displayId = 1;
478 struct RSSurfaceNodeConfig config;
479 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
480 bool onTop = true;
481 dms_->AddSurfaceNodeToDisplay(displayId, surfaceNode, onTop);
482 ASSERT_NE(dms_->abstractScreenController_, nullptr);
483 }
484
485 /**
486 * @tc.name: IsScreenRotationLocked
487 * @tc.desc: IsScreenRotationLocked
488 * @tc.type: FUNC
489 */
490 HWTEST_F(DisplayManagerServiceTest, IsScreenRotationLocked, TestSize.Level1)
491 {
492 bool isLocked = true;
493 DMError ret = dms_->IsScreenRotationLocked(isLocked);
494 ASSERT_EQ(ret, DMError::DM_OK);
495 }
496
497 /**
498 * @tc.name: SetScreenRotationLocked
499 * @tc.desc: SetScreenRotationLocked
500 * @tc.type: FUNC
501 */
502 HWTEST_F(DisplayManagerServiceTest, SetScreenRotationLocked, TestSize.Level1)
503 {
504 bool isLocked = true;
505 DMError ret = dms_->SetScreenRotationLocked(isLocked);
506 ASSERT_EQ(ret, DMError::DM_OK);
507 }
508
509 /**
510 * @tc.name: SetScreenRotationLockedFromJs
511 * @tc.desc: SetScreenRotationLockedFromJs
512 * @tc.type: FUNC
513 */
514 HWTEST_F(DisplayManagerServiceTest, SetScreenRotationLockedFromJs, TestSize.Level1)
515 {
516 bool isLocked = true;
517 DMError ret = dms_->SetScreenRotationLockedFromJs(isLocked);
518 ASSERT_EQ(ret, DMError::DM_OK);
519 }
520
521 /**
522 * @tc.name: SetGravitySensorSubscriptionEnabled
523 * @tc.desc: SetGravitySensorSubscriptionEnabled
524 * @tc.type: FUNC
525 */
526 HWTEST_F(DisplayManagerServiceTest, SetGravitySensorSubscriptionEnabled, TestSize.Level1)
527 {
528 dms_->isAutoRotationOpen_ = true;
529 dms_->SetGravitySensorSubscriptionEnabled();
530 ASSERT_TRUE(dms_->isAutoRotationOpen_);
531
532 dms_->isAutoRotationOpen_ = false;
533 dms_->SetGravitySensorSubscriptionEnabled();
534 ASSERT_FALSE(dms_->isAutoRotationOpen_);
535 }
536
537 /**
538 * @tc.name: MakeMirror
539 * @tc.desc: MakeMirror
540 * @tc.type: FUNC
541 */
542 HWTEST_F(DisplayManagerServiceTest, MakeMirror, TestSize.Level1)
543 {
544 ScreenId mainScreenId = 1;
545 std::vector<ScreenId> mirrorScreenIds = { 2 };
546 ScreenId screenGroupId = 3;
547 sptr<AbstractScreen> absScreen =
548 new AbstractScreen(nullptr, "", INVALID_SCREEN_ID, INVALID_SCREEN_ID);
549 dms_->abstractScreenController_->dmsScreenMap_.insert(std::make_pair(mainScreenId, absScreen));
550 DMError ret = dms_->MakeMirror(mainScreenId, mirrorScreenIds, screenGroupId);
551 ASSERT_EQ(ret, DMError::DM_ERROR_INVALID_PARAM);
552 dms_->abstractScreenController_->dmsScreenMap_.clear();
553 }
554
555 /**
556 * @tc.name: StopMirror
557 * @tc.desc: StopMirror
558 * @tc.type: FUNC
559 */
560 HWTEST_F(DisplayManagerServiceTest, StopMirror, TestSize.Level1)
561 {
562 std::vector<ScreenId> mirrorScreenIds = { 2 };
563 sptr<AbstractScreen> absScreen =
564 new AbstractScreen(nullptr, "", INVALID_SCREEN_ID, INVALID_SCREEN_ID);
565 dms_->abstractScreenController_->dmsScreenMap_.insert(std::make_pair(2, absScreen));
566 DMError ret = dms_->StopMirror(mirrorScreenIds);
567 ASSERT_EQ(ret, DMError::DM_OK);
568 }
569
570 /**
571 * @tc.name: RemoveSurfaceNodeFromDisplay
572 * @tc.desc: RemoveSurfaceNodeFromDisplay
573 * @tc.type: FUNC
574 */
575 HWTEST_F(DisplayManagerServiceTest, RemoveSurfaceNodeFromDisplay, TestSize.Level1)
576 {
577 DisplayId displayId = 1;
578 struct RSSurfaceNodeConfig config;
579 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
580 DMError ret = dms_->RemoveSurfaceNodeFromDisplay(displayId, surfaceNode);
581 ASSERT_EQ(ret, DMError::DM_ERROR_NULLPTR);
582 }
583
584 /**
585 * @tc.name: SetOrientation
586 * @tc.desc: DMS SetOrientation
587 * @tc.type: FUNC
588 */
589 HWTEST_F(DisplayManagerServiceTest, SetOrientation, TestSize.Level1)
590 {
591 ScreenId screenId = 0;
592 Orientation orientation = Orientation::VERTICAL;
593 auto ret = dms_->SetOrientation(screenId, orientation);
594 ASSERT_NE(ret, DMError::DM_ERROR_INVALID_PARAM);
595 }
596
597 /**
598 * @tc.name: GetDisplaySnapshot
599 * @tc.desc: DMS GetDisplaySnapshot
600 * @tc.type: FUNC
601 */
602 HWTEST_F(DisplayManagerServiceTest, GetDisplaySnapshot, TestSize.Level1)
603 {
604 DisplayId displayId = -1;
605 DmErrorCode* errorCode = nullptr;
606 auto ret = dms_->GetDisplaySnapshot(displayId, errorCode, false);
607 ASSERT_EQ(nullptr, ret);
608 }
609
610 /**
611 * @tc.name: AddSurfaceNodeToDisplay
612 * @tc.desc: DMS AddSurfaceNodeToDisplay
613 * @tc.type: FUNC
614 */
615 HWTEST_F(DisplayManagerServiceTest, AddSurfaceNodeToDisplay02, TestSize.Level1)
616 {
617 DisplayId displayId = 1;
618 std::shared_ptr<RSSurfaceNode> surfaceNode = nullptr;
619 bool onTop = true;
620 auto ret = dms_->AddSurfaceNodeToDisplay(displayId, surfaceNode, onTop);
621 ASSERT_EQ(DMError::DM_ERROR_NULLPTR, ret);
622 }
623
624 /**
625 * @tc.name: GetAllScreenInfos
626 * @tc.desc: DMS GetAllScreenInfos
627 * @tc.type: FUNC
628 */
629 HWTEST_F(DisplayManagerServiceTest, GetAllScreenInfos, TestSize.Level1)
630 {
631 std::vector<sptr<ScreenInfo>> screenInfos;
632 auto ret = dms_->GetAllScreenInfos(screenInfos);
633 ASSERT_EQ(DMError::DM_OK, ret);
634 }
635
636 /**
637 * @tc.name: MakeExpand
638 * @tc.desc: DMS MakeExpand
639 * @tc.type: FUNC
640 */
641 HWTEST_F(DisplayManagerServiceTest, MakeExpand01, TestSize.Level1)
642 {
643 std::vector<ScreenId> expandScreenIds{1};
644 std::vector<Point> startPoints(1);
645 ScreenId screenGroupId = 3;
646 auto ret = dms_->MakeExpand(expandScreenIds, startPoints, screenGroupId);
647 ASSERT_NE(ret, DMError::DM_ERROR_INVALID_PARAM);
648 }
649
650 /**
651 * @tc.name: MakeExpand
652 * @tc.desc: DMS MakeExpand
653 * @tc.type: FUNC
654 */
655 HWTEST_F(DisplayManagerServiceTest, MakeExpand02, TestSize.Level1)
656 {
657 std::vector<ScreenId> expandScreenIds{1, 2, 3, 4, 5};
658 std::vector<Point> startPoints(1);
659 ScreenId screenGroupId = 3;
660 auto ret = dms_->MakeExpand(expandScreenIds, startPoints, screenGroupId);
661 ASSERT_NE(ret, DMError::DM_ERROR_NOT_SYSTEM_APP);
662 }
663
664 /**
665 * @tc.name: StopExpand
666 * @tc.desc: DMS StopExpand
667 * @tc.type: FUNC
668 */
669 HWTEST_F(DisplayManagerServiceTest, StopExpand, TestSize.Level1)
670 {
671 std::vector<ScreenId> expandScreenIds{0, 1, 2, 3, 4, 5};
672 auto ret = dms_->StopExpand(expandScreenIds);
673 ASSERT_EQ(ret, DMError::DM_OK);
674 }
675
676 /**
677 * @tc.name: GetVisibleAreaDisplayInfoById01
678 * @tc.desc: GetVisibleAreaDisplayInfoById
679 * @tc.type: FUNC
680 */
681 HWTEST_F(DisplayManagerServiceTest, GetVisibleAreaDisplayInfoById01, TestSize.Level1)
682 {
683 DisplayId displayId = DISPLAY_ID_INVALID;
684 auto ret = dms_->GetVisibleAreaDisplayInfoById(displayId);
685 EXPECT_EQ(ret, nullptr);
686 }
687
688 /**
689 * @tc.name: GetVisibleAreaDisplayInfoById02
690 * @tc.desc: GetVisibleAreaDisplayInfoById
691 * @tc.type: FUNC
692 */
693 HWTEST_F(DisplayManagerServiceTest, GetVisibleAreaDisplayInfoById02, TestSize.Level1)
694 {
695 DisplayId displayId = 2;
696 std::string name = "testDisplay";
697 sptr<SupportedScreenModes> info = new SupportedScreenModes();
698 sptr<AbstractScreen> absScreen = new AbstractScreen(dms_->abstractScreenController_, name, 0, 0);
699 sptr<AbstractDisplay> absDisplay = new AbstractDisplay(0, info, absScreen);
700 dms_->abstractDisplayController_->abstractDisplayMap_.insert({displayId, absDisplay});
701 auto ret = dms_->GetVisibleAreaDisplayInfoById(displayId);
702 EXPECT_NE(ret, nullptr);
703 }
704
705 /**
706 * @tc.name: SetScreenBrightness
707 * @tc.desc: SetScreenBrightness
708 * @tc.type: FUNC
709 */
710 HWTEST_F(DisplayManagerServiceTest, SetScreenBrightness, TestSize.Level1)
711 {
712 uint64_t screenId = 1;
713 uint32_t level = 2;
714 EXPECT_TRUE(dms_->SetScreenBrightness(screenId, level));
715 }
716
717 /**
718 * @tc.name: GetAllDisplayPhysicalResolution01
719 * @tc.desc: Test GetAllDisplayPhysicalResolution function when allDisplayPhysicalResolution_ is empty.
720 * @tc.type: FUNC
721 */
722 HWTEST_F(DisplayManagerServiceTest, GetAllDisplayPhysicalResolution01, TestSize.Level1)
723 {
724 dms_->allDisplayPhysicalResolution_.clear();
725 auto result = dms_->GetAllDisplayPhysicalResolution();
726 EXPECT_FALSE(result.empty());
727 }
728
729 /**
730 * @tc.name: GetAllDisplayPhysicalResolution02
731 * @tc.desc: Test GetAllDisplayPhysicalResolution function when allDisplayPhysicalResolution_ is not empty.
732 * @tc.type: FUNC
733 */
734 HWTEST_F(DisplayManagerServiceTest, GetAllDisplayPhysicalResolution02, TestSize.Level1)
735 {
736 dms_->allDisplayPhysicalResolution_.emplace_back(DisplayPhysicalResolution());
737 auto result = dms_->GetAllDisplayPhysicalResolution();
738 EXPECT_FALSE(result.empty());
739 }
740
741 /**
742 * @tc.name: GetAllDisplayPhysicalResolution03
743 * @tc.desc: Test GetAllDisplayPhysicalResolution function when default display info is null.
744 * @tc.type: FUNC
745 */
746 HWTEST_F(DisplayManagerServiceTest, GetAllDisplayPhysicalResolution03, TestSize.Level1)
747 {
748 dms_->allDisplayPhysicalResolution_.clear();
749 dms_->GetDefaultDisplayInfo();
750 auto result = dms_->GetAllDisplayPhysicalResolution();
751 EXPECT_FALSE(result.empty());
752 }
753
754 /**
755 * @tc.name: SetVirtualScreenAsDefault
756 * @tc.desc: Test GetAllDisplayPhysicalResolution function when default display info is null.
757 * @tc.type: FUNC
758 */
759 HWTEST_F(DisplayManagerServiceTest, SetVirtualScreenAsDefault, TestSize.Level1)
760 {
761 ScreenId screenId = 0;
762 auto res = dms_->SetVirtualScreenAsDefault(screenId);
763 EXPECT_FALSE(res);
764 }
765 }
766 } // namespace Rosen
767 } // namespace OHOS
768