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:
OnDisplayStateChange(DisplayId defaultDisplayId,sptr<DisplayInfo> displayInfo,const std::map<DisplayId,sptr<DisplayInfo>> & displayInfoMap,DisplayStateChangeType type)84     void OnDisplayStateChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
85         const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type) override {};
OnScreenshot(DisplayId displayId)86     void OnScreenshot(DisplayId displayId) override {};
87 };
88 
89 class WindowInfoQueriedListenerTest : public IWindowInfoQueriedListener {
90 public:
HasPrivateWindow(DisplayId id,bool & hasPrivateWindow)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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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     EXPECT_EQ(dms_->abstractScreenController_->GetAbstractScreen(DISPLAY_ID_INVALID), nullptr);
350     dms_->UpdateRSTree(0, 0, surfaceNode, true, false);
351 }
352 
353 /**
354  * @tc.name: MirrorAndExpand
355  * @tc.desc: DMS mirror
356  * @tc.type: FUNC
357  */
358 HWTEST_F(DisplayManagerServiceTest, MirrorAndExpand, Function | SmallTest | Level3)
359 {
360     std::vector<ScreenId> mirrorScreenIds;
361     ScreenId screenGroupId1 = DISPLAY_ID_INVALID;
362     dms_->MakeMirror(DISPLAY_ID_INVALID, mirrorScreenIds, screenGroupId1);
363     ASSERT_EQ(SCREEN_ID_INVALID, screenGroupId1);
364     ASSERT_EQ(DMError::DM_OK, dms_->StopMirror(mirrorScreenIds));
365 
366     std::vector<ScreenId> expandScreenIds;
367     std::vector<Point> startPoints;
368     ScreenId screenGroupId2 = DISPLAY_ID_INVALID;
369     dms_->MakeExpand(expandScreenIds, startPoints, screenGroupId2);
370     ASSERT_EQ(SCREEN_ID_INVALID, screenGroupId2);
371     ASSERT_EQ(DMError::DM_OK, dms_->StopExpand(expandScreenIds));
372 }
373 
374 /**
375  * @tc.name: ScreenActiveMode
376  * @tc.desc: DMS mirror
377  * @tc.type: FUNC
378  */
379 HWTEST_F(DisplayManagerServiceTest, ScreenActiveMode, Function | SmallTest | Level3)
380 {
381     ASSERT_EQ(DMError::DM_ERROR_NULLPTR, dms_->SetScreenActiveMode(SCREEN_ID_INVALID, 0));
382 }
383 
384 /**
385  * @tc.name: VirtualPixelRatio
386  * @tc.desc: DMS mirror
387  * @tc.type: FUNC
388  */
389 HWTEST_F(DisplayManagerServiceTest, VirtualPixelRatio, Function | SmallTest | Level3)
390 {
391     ASSERT_TRUE(DMError::DM_OK != dms_->SetVirtualPixelRatio(SCREEN_ID_INVALID, 0.f));
392 }
393 
394 /**
395  * @tc.name: AddSurfaceNodeToDisplay | RemoveSurfaceNodeFromDisplay
396  * @tc.desc: add/remove surfaceNode to/from display
397  * @tc.type: FUNC
398  */
399 HWTEST_F(DisplayManagerServiceTest, AddAndRemoveSurfaceNode, Function | SmallTest | Level3)
400 {
401     std::shared_ptr<RSSurfaceNode> surfaceNode = nullptr;
402     DMError result = dms_->RemoveSurfaceNodeFromDisplay(DEFAULT_DISPLAY, surfaceNode);
403     EXPECT_EQ(result, DMError::DM_ERROR_NULLPTR);
404 
405     surfaceNode = std::make_shared<RSSurfaceNode>(RSSurfaceNodeConfig{}, true);
406     std::shared_ptr<RSDisplayNode> displayNode = std::make_shared<MockRSDisplayNode>(RSDisplayNodeConfig{});
407     sptr<SupportedScreenModes> info = new SupportedScreenModes;
408     sptr<AbstractScreen> absScreen =
409         new AbstractScreen(nullptr, "", INVALID_SCREEN_ID, INVALID_SCREEN_ID);
410 }
411 
412 /**
413  * @tc.name: OnStop
414  * @tc.desc: DMS on stop
415  * @tc.type: FUNC
416  */
417 HWTEST_F(DisplayManagerServiceTest, OnStop, Function | SmallTest | Level3)
418 {
419     dms_->OnStop();
420     ASSERT_TRUE(true);
421 }
422 
423 /**
424  * @tc.name: NotifyDisplayEvent
425  * @tc.desc: NotifyDisplayEvent
426  * @tc.type: FUNC
427  */
428 HWTEST_F(DisplayManagerServiceTest, NotifyDisplayEvent, Function | SmallTest | Level3)
429 {
430     DisplayEvent event = DisplayEvent::KEYGUARD_DRAWN;
431     dms_->NotifyDisplayEvent(event);
432     ASSERT_NE(dms_->displayPowerController_, nullptr);
433 }
434 
435 /**
436  * @tc.name: SetFreeze
437  * @tc.desc: SetFreeze
438  * @tc.type: FUNC
439  */
440 HWTEST_F(DisplayManagerServiceTest, SetFreeze, Function | SmallTest | Level3)
441 {
442     std::vector<DisplayId> displayIds = { 0 };
443     bool isFreeze = false;
444     dms_->SetFreeze(displayIds, isFreeze);
445     ASSERT_NE(dms_->abstractDisplayController_, nullptr);
446 }
447 
448 /**
449  * @tc.name: AddSurfaceNodeToDisplay
450  * @tc.desc: AddSurfaceNodeToDisplay
451  * @tc.type: FUNC
452  */
453 HWTEST_F(DisplayManagerServiceTest, AddSurfaceNodeToDisplay, Function | SmallTest | Level3)
454 {
455     DisplayId displayId = 1;
456     struct RSSurfaceNodeConfig config;
457     std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
458     bool onTop = true;
459     dms_->AddSurfaceNodeToDisplay(displayId, surfaceNode, onTop);
460     ASSERT_NE(dms_->abstractScreenController_, nullptr);
461 }
462 
463 /**
464  * @tc.name: IsScreenRotationLocked
465  * @tc.desc: IsScreenRotationLocked
466  * @tc.type: FUNC
467  */
468 HWTEST_F(DisplayManagerServiceTest, IsScreenRotationLocked, Function | SmallTest | Level3)
469 {
470     bool isLocked = true;
471     DMError ret = dms_->IsScreenRotationLocked(isLocked);
472     ASSERT_EQ(ret, DMError::DM_OK);
473 }
474 
475 /**
476  * @tc.name: SetScreenRotationLocked
477  * @tc.desc: SetScreenRotationLocked
478  * @tc.type: FUNC
479  */
480 HWTEST_F(DisplayManagerServiceTest, SetScreenRotationLocked, Function | SmallTest | Level3)
481 {
482     bool isLocked = true;
483     DMError ret = dms_->SetScreenRotationLocked(isLocked);
484     ASSERT_EQ(ret, DMError::DM_OK);
485 }
486 
487 /**
488  * @tc.name: SetScreenRotationLockedFromJs
489  * @tc.desc: SetScreenRotationLockedFromJs
490  * @tc.type: FUNC
491  */
492 HWTEST_F(DisplayManagerServiceTest, SetScreenRotationLockedFromJs, Function | SmallTest | Level3)
493 {
494     bool isLocked = true;
495     DMError ret = dms_->SetScreenRotationLockedFromJs(isLocked);
496     ASSERT_EQ(ret, DMError::DM_OK);
497 }
498 
499 /**
500  * @tc.name: SetGravitySensorSubscriptionEnabled
501  * @tc.desc: SetGravitySensorSubscriptionEnabled
502  * @tc.type: FUNC
503  */
504 HWTEST_F(DisplayManagerServiceTest, SetGravitySensorSubscriptionEnabled, Function | SmallTest | Level3)
505 {
506     dms_->isAutoRotationOpen_ = true;
507     dms_->SetGravitySensorSubscriptionEnabled();
508     ASSERT_TRUE(dms_->isAutoRotationOpen_);
509 
510     dms_->isAutoRotationOpen_ = false;
511     dms_->SetGravitySensorSubscriptionEnabled();
512     ASSERT_FALSE(dms_->isAutoRotationOpen_);
513 }
514 
515 /**
516  * @tc.name: MakeMirror
517  * @tc.desc: MakeMirror
518  * @tc.type: FUNC
519  */
520 HWTEST_F(DisplayManagerServiceTest, MakeMirror, Function | SmallTest | Level3)
521 {
522     ScreenId mainScreenId = 1;
523     std::vector<ScreenId> mirrorScreenIds = { 2 };
524     ScreenId screenGroupId = 3;
525     sptr<AbstractScreen> absScreen =
526         new AbstractScreen(nullptr, "", INVALID_SCREEN_ID, INVALID_SCREEN_ID);
527     dms_->abstractScreenController_->dmsScreenMap_.insert(std::make_pair(mainScreenId, absScreen));
528     DMError ret = dms_->MakeMirror(mainScreenId, mirrorScreenIds, screenGroupId);
529     ASSERT_EQ(ret, DMError::DM_ERROR_INVALID_PARAM);
530     dms_->abstractScreenController_->dmsScreenMap_.clear();
531 }
532 
533 /**
534  * @tc.name: StopMirror
535  * @tc.desc: StopMirror
536  * @tc.type: FUNC
537  */
538 HWTEST_F(DisplayManagerServiceTest, StopMirror, Function | SmallTest | Level3)
539 {
540     std::vector<ScreenId> mirrorScreenIds = { 2 };
541     sptr<AbstractScreen> absScreen =
542         new AbstractScreen(nullptr, "", INVALID_SCREEN_ID, INVALID_SCREEN_ID);
543     dms_->abstractScreenController_->dmsScreenMap_.insert(std::make_pair(2, absScreen));
544     DMError ret = dms_->StopMirror(mirrorScreenIds);
545     ASSERT_EQ(ret, DMError::DM_OK);
546 }
547 
548 /**
549  * @tc.name: RemoveSurfaceNodeFromDisplay
550  * @tc.desc: RemoveSurfaceNodeFromDisplay
551  * @tc.type: FUNC
552  */
553 HWTEST_F(DisplayManagerServiceTest, RemoveSurfaceNodeFromDisplay, Function | SmallTest | Level3)
554 {
555     DisplayId displayId = 1;
556     struct RSSurfaceNodeConfig config;
557     std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
558     DMError ret = dms_->RemoveSurfaceNodeFromDisplay(displayId, surfaceNode);
559     ASSERT_EQ(ret, DMError::DM_ERROR_NULLPTR);
560 }
561 
562 /**
563  * @tc.name: GetDisplaySnapshot
564  * @tc.desc: DMS GetDisplaySnapshot
565  * @tc.type: FUNC
566  */
567 HWTEST_F(DisplayManagerServiceTest, GetDisplaySnapshot, Function | SmallTest | Level3)
568 {
569     DisplayId displayId = -1;
570     DmErrorCode* errorCode = nullptr;
571     auto ret = dms_->GetDisplaySnapshot(displayId, errorCode, false);
572     ASSERT_EQ(nullptr, ret);
573 }
574 }
575 } // namespace Rosen
576 } // namespace OHOS
577