1 /*
2  * Copyright (c) 2024 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_service_inner.h"
19 
20 using namespace testing;
21 using namespace testing::ext;
22 
23 namespace OHOS {
24 namespace Rosen {
25 namespace {
26 constexpr uint32_t SLEEP_TIME_US = 100000;
27 }
28 class DisplayManagerServiceInnerTest : public testing::Test {
29 public:
30     static void SetUpTestCase();
31     static void TearDownTestCase();
32     void SetUp() override;
33     void TearDown() override;
34 };
35 
SetUpTestCase()36 void DisplayManagerServiceInnerTest::SetUpTestCase()
37 {
38 }
39 
TearDownTestCase()40 void DisplayManagerServiceInnerTest::TearDownTestCase()
41 {
42 }
43 
SetUp()44 void DisplayManagerServiceInnerTest::SetUp()
45 {
46 }
47 
TearDown()48 void DisplayManagerServiceInnerTest::TearDown()
49 {
50     usleep(SLEEP_TIME_US);
51 }
52 
53 namespace {
54 /**
55  * @tc.name: RegisterWindowInfoQueriedListener
56  * @tc.desc: test function : RegisterWindowInfoQueriedListener
57  * @tc.type: FUNC
58  */
59 HWTEST_F(DisplayManagerServiceInnerTest, RegisterWindowInfoQueriedListener, Function | SmallTest | Level1)
60 {
61     DisplayManagerServiceInner inner;
62     sptr<IWindowInfoQueriedListener> listener = nullptr;
63     inner.RegisterWindowInfoQueriedListener(listener);
64     EXPECT_EQ(nullptr, listener);
65 }
66 
67 /**
68  * @tc.name: GetAllDisplays
69  * @tc.desc: test function : GetAllDisplays
70  * @tc.type: FUNC
71  */
72 HWTEST_F(DisplayManagerServiceInnerTest, GetAllDisplays, Function | SmallTest | Level1)
73 {
74     DisplayManagerServiceInner inner;
75     auto ret = inner.GetAllDisplays();
76     EXPECT_EQ(true, ret.empty());
77 }
78 
79 /**
80  * @tc.name: UpdateRSTree
81  * @tc.desc: test function : UpdateRSTree
82  * @tc.type: FUNC
83  */
84 HWTEST_F(DisplayManagerServiceInnerTest, UpdateRSTree, Function | SmallTest | Level1)
85 {
86     DisplayId displayId = 0;
87     DisplayId parentDisplayId = 0;
88     std::shared_ptr<RSSurfaceNode> surfaceNode = nullptr;
89     bool isAdd = false;
90     bool isMultiDisplay = false;
91 
92     DisplayManagerServiceInner inner;
93     inner.UpdateRSTree(displayId, parentDisplayId, surfaceNode, isAdd, isMultiDisplay);
94     EXPECT_EQ(nullptr, surfaceNode);
95 }
96 
97 /**
98  * @tc.name: GetScreenGroupIdByDisplayId
99  * @tc.desc: test function : GetScreenGroupIdByDisplayId
100  * @tc.type: FUNC
101  */
102 HWTEST_F(DisplayManagerServiceInnerTest, GetScreenGroupIdByDisplayId, Function | SmallTest | Level1)
103 {
104     DisplayId displayId = 0;
105     DisplayManagerServiceInner inner;
106     auto ret = inner.GetScreenGroupIdByDisplayId(displayId);
107     EXPECT_EQ(INVALID_SCREEN_ID, ret);
108 
109     displayId = 1;
110     ret = inner.GetScreenGroupIdByDisplayId(displayId);
111     EXPECT_EQ(INVALID_SCREEN_ID, ret);
112 }
113 
114 /**
115  * @tc.name: GetDisplaySnapshot
116  * @tc.desc: test function : GetDisplaySnapshot
117  * @tc.type: FUNC
118  */
119 HWTEST_F(DisplayManagerServiceInnerTest, GetDisplaySnapshot, Function | SmallTest | Level1)
120 {
121     DisplayId displayId = 0;
122     DmErrorCode* errorCode = nullptr;
123     DisplayManagerServiceInner inner;
124     auto ret = inner.GetDisplaySnapshot(displayId, errorCode);
125     EXPECT_EQ(nullptr, ret);
126 }
127 
128 /**
129  * @tc.name: RegisterDisplayChangeListener
130  * @tc.desc: test function : RegisterDisplayChangeListener
131  * @tc.type: FUNC
132  */
133 HWTEST_F(DisplayManagerServiceInnerTest, RegisterDisplayChangeListener, Function | SmallTest | Level1)
134 {
135     sptr<IDisplayChangeListener> listener = nullptr;
136     DisplayManagerServiceInner inner;
137     inner.RegisterDisplayChangeListener(listener);
138     EXPECT_EQ(nullptr, listener);
139 }
140 
141 /**
142  * @tc.name: SetOrientationFromWindow
143  * @tc.desc: test function : SetOrientationFromWindow
144  * @tc.type: FUNC
145  */
146 HWTEST_F(DisplayManagerServiceInnerTest, SetOrientationFromWindow, Function | SmallTest | Level1)
147 {
148     DisplayId displayId = 0;
149     Orientation orientation = Orientation::BEGIN;
150     bool withAnimation = false;
151     DisplayManagerServiceInner inner;
152     auto ret = inner.SetOrientationFromWindow(displayId, orientation, withAnimation);
153     EXPECT_EQ(DMError::DM_ERROR_NULLPTR, ret);
154 
155     displayId = 1;
156     ret = inner.SetOrientationFromWindow(displayId, orientation, withAnimation);
157     EXPECT_EQ(DMError::DM_ERROR_NULLPTR, ret);
158 }
159 
160 /**
161  * @tc.name: SetRotationFromWindow
162  * @tc.desc: test function : SetRotationFromWindow
163  * @tc.type: FUNC
164  */
165 HWTEST_F(DisplayManagerServiceInnerTest, SetRotationFromWindow, Function | SmallTest | Level1)
166 {
167     DisplayId displayId = 0;
168     Rotation targetRotation = Rotation::ROTATION_0;
169     bool withAnimation = false;
170     DisplayManagerServiceInner inner;
171     auto ret = inner.SetRotationFromWindow(displayId, targetRotation, withAnimation);
172     EXPECT_EQ(false, ret);
173 
174     displayId = 1;
175     ret = inner.SetRotationFromWindow(displayId, targetRotation, withAnimation);
176     EXPECT_EQ(false, ret);
177 }
178 
179 /**
180  * @tc.name: SetGravitySensorSubscriptionEnabled
181  * @tc.desc: test function : RegisterDisplayChangeListener
182  * @tc.type: FUNC
183  */
184 HWTEST_F(DisplayManagerServiceInnerTest, SetGravitySensorSubscriptionEnabled, Function | SmallTest | Level1)
185 {
186     DisplayManagerServiceInner inner;
187     inner.SetGravitySensorSubscriptionEnabled();
188     EXPECT_TRUE(true);
189 }
190 
191 /**
192  * @tc.name: GetCutoutInfo
193  * @tc.desc: test function : GetCutoutInfo
194  * @tc.type: FUNC
195  */
196 HWTEST_F(DisplayManagerServiceInnerTest, GetCutoutInfo, Function | SmallTest | Level1)
197 {
198     DisplayId displayId = 0;
199     DisplayManagerServiceInner inner;
200     auto ret = inner.GetCutoutInfo(displayId);
201     EXPECT_NE(nullptr, ret);
202 }
203 
204 /**
205  * @tc.name: NotifyPrivateWindowStateChanged
206  * @tc.desc: test function : NotifyPrivateWindowStateChanged
207  * @tc.type: FUNC
208  */
209 HWTEST_F(DisplayManagerServiceInnerTest, NotifyPrivateWindowStateChanged, Function | SmallTest | Level1)
210 {
211     bool hasPrivate = false;
212     DisplayManagerServiceInner inner;
213     inner.NotifyPrivateWindowStateChanged(hasPrivate);
214     EXPECT_EQ(false, hasPrivate);
215 }
216 }
217 }
218 }