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