• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #include "display_manager_adapter_lite.h"
18 
19 using namespace testing;
20 using namespace testing::ext;
21 
22 namespace OHOS {
23 namespace Rosen {
24 class DisplayManagerAdapterLiteTest : public testing::Test {
25 public:
26     static void SetUpTestCase();
27     static void TearDownTestCase();
28     void SetUp() override;
29     void TearDown() override;
30 };
31 
SetUpTestCase()32 void DisplayManagerAdapterLiteTest::SetUpTestCase()
33 {
34 }
35 
TearDownTestCase()36 void DisplayManagerAdapterLiteTest::TearDownTestCase()
37 {
38 }
39 
SetUp()40 void DisplayManagerAdapterLiteTest::SetUp()
41 {
42 }
43 
TearDown()44 void DisplayManagerAdapterLiteTest::TearDown()
45 {
46 }
47 
48 namespace {
49 /**
50  * @tc.name: OnRemoteDied
51  * @tc.desc: test nullptr
52  * @tc.type: FUNC
53  */
54 HWTEST_F(DisplayManagerAdapterLiteTest, OnRemoteDied, TestSize.Level1)
55 {
56     sptr<IRemoteObject::DeathRecipient> dmsDeath_ = nullptr;
57     dmsDeath_ = new(std::nothrow) DMSDeathRecipientLite(SingletonContainer::Get<DisplayManagerAdapterLite>());
58     dmsDeath_->OnRemoteDied(nullptr);
59     ASSERT_NE(dmsDeath_, nullptr);
60 }
61 
62 /**
63  * @tc.name: OnRemoteDied01
64  * @tc.desc: test nullptr
65  * @tc.type: FUNC
66  */
67 HWTEST_F(DisplayManagerAdapterLiteTest, OnRemoteDied01, TestSize.Level1)
68 {
69     sptr<IRemoteObject::DeathRecipient> dmsDeath_ = nullptr;
70     dmsDeath_ = new(std::nothrow) DMSDeathRecipientLite(SingletonContainer::Get<DisplayManagerAdapterLite>());
71     SingletonContainer::Get<DisplayManagerAdapterLite>().InitDMSProxy();
72     sptr<IRemoteObject> obj =
73         SingletonContainer::Get<DisplayManagerAdapterLite>().displayManagerServiceProxy_->AsObject();
74     wptr<IRemoteObject> wptrDeath = obj;
75     dmsDeath_->OnRemoteDied(wptrDeath);
76     ASSERT_NE(dmsDeath_, nullptr);
77 }
78 
79 /**
80  * @tc.name: Clear
81  * @tc.desc: test success
82  * @tc.type: FUNC
83  */
84 HWTEST_F(DisplayManagerAdapterLiteTest, Clear, TestSize.Level1)
85 {
86     SingletonContainer::Get<DisplayManagerAdapterLite>().InitDMSProxy();
87     SingletonContainer::Get<DisplayManagerAdapterLite>().Clear();
88     ASSERT_FALSE(SingletonContainer::Get<DisplayManagerAdapterLite>().isProxyValid_);
89 }
90 
91 /**
92  * @tc.name: Clear01
93  * @tc.desc: test success
94  * @tc.type: FUNC
95  */
96 HWTEST_F(DisplayManagerAdapterLiteTest, Clear01, TestSize.Level1)
97 {
98     SingletonContainer::Get<DisplayManagerAdapterLite>().InitDMSProxy();
99     SingletonContainer::Get<DisplayManagerAdapterLite>().displayManagerServiceProxy_ = nullptr;
100     SingletonContainer::Get<DisplayManagerAdapterLite>().Clear();
101     ASSERT_FALSE(SingletonContainer::Get<DisplayManagerAdapterLite>().isProxyValid_);
102 }
103 
104 /**
105  * @tc.name: WakeUpBegin
106  * @tc.desc: test WakeUpBegin
107  * @tc.type: FUNC
108  */
109 HWTEST_F(DisplayManagerAdapterLiteTest, WakeUpBegin, TestSize.Level1)
110 {
111     PowerStateChangeReason reason = PowerStateChangeReason{0};
112     bool ret = SingletonContainer::Get<DisplayManagerAdapterLite>().WakeUpBegin(reason);
113     ASSERT_TRUE(ret);
114 }
115 
116 /**
117  * @tc.name: WakeUpEnd
118  * @tc.desc: test WakeUpEnd
119  * @tc.type: FUNC
120  */
121 HWTEST_F(DisplayManagerAdapterLiteTest, WakeUpEnd, TestSize.Level1)
122 {
123     bool ret = SingletonContainer::Get<DisplayManagerAdapterLite>().WakeUpEnd();
124     ASSERT_TRUE(ret);
125 }
126 
127 /**
128  * @tc.name: SuspendBegin
129  * @tc.desc: test SuspendBegin
130  * @tc.type: FUNC
131  */
132 HWTEST_F(DisplayManagerAdapterLiteTest, SuspendBegin, TestSize.Level1)
133 {
134     PowerStateChangeReason reason = PowerStateChangeReason{0};
135     bool ret = SingletonContainer::Get<DisplayManagerAdapterLite>().SuspendBegin(reason);
136     ASSERT_TRUE(ret);
137 }
138 
139 /**
140  * @tc.name: SuspendEnd
141  * @tc.desc: test SuspendEnd
142  * @tc.type: FUNC
143  */
144 HWTEST_F(DisplayManagerAdapterLiteTest, SuspendEnd, TestSize.Level1)
145 {
146     bool ret = SingletonContainer::Get<DisplayManagerAdapterLite>().SuspendEnd();
147     ASSERT_TRUE(ret);
148 }
149 
150 /**
151  * @tc.name: SetDisplayState
152  * @tc.desc: test SetDisplayState
153  * @tc.type: FUNC
154  */
155 HWTEST_F(DisplayManagerAdapterLiteTest, SetDisplayState, TestSize.Level1)
156 {
157     DisplayState state = DisplayState{1};
158     bool ret = SingletonContainer::Get<DisplayManagerAdapterLite>().SetDisplayState(state);
159     ASSERT_FALSE(ret);
160 }
161 
162 /**
163  * @tc.name: GetVirtualScreenFlag
164  * @tc.desc: test GetVirtualScreenFlag
165  * @tc.type: FUNC
166  */
167 HWTEST_F(DisplayManagerAdapterLiteTest, GetVirtualScreenFlag, TestSize.Level1)
168 {
169     if (SceneBoardJudgement::IsSceneBoardEnabled()) {
170         uint64_t screenId = 0;
171         auto ret = SingletonContainer::Get<DisplayManagerAdapterLite>().GetVirtualScreenFlag(screenId);
172         ASSERT_EQ(ret, VirtualScreenFlag::DEFAULT);
173     }
174 }
175 
176 /**
177  * @tc.name: SetSystemKeyboardStatus
178  * @tc.desc: SetSystemKeyboardStatus with true as parameter
179  * @tc.type: FUNC
180  */
181 HWTEST_F(DisplayManagerAdapterLiteTest, SetSystemKeyboardStatus01, TestSize.Level1)
182 {
183     auto ret = SingletonContainer::Get<DisplayManagerAdapterLite>().SetSystemKeyboardStatus(true);
184     ASSERT_NE(ret, DMError::DM_OK);
185 }
186 
187 /**
188  * @tc.name: SetSystemKeyboardStatus
189  * @tc.desc: SetSystemKeyboardStatus with false as parameter
190  * @tc.type: FUNC
191  */
192 HWTEST_F(DisplayManagerAdapterLiteTest, SetSystemKeyboardStatus02, TestSize.Level1)
193 {
194     auto ret = SingletonContainer::Get<DisplayManagerAdapterLite>().SetSystemKeyboardStatus(false);
195     ASSERT_NE(ret, DMError::DM_OK);
196 }
197 
198 /**
199  * @tc.name: GetPhysicalScreenIds
200  * @tc.desc: GetPhysicalScreenIds
201  * @tc.type: FUNC
202  */
203 HWTEST_F(DisplayManagerAdapterLiteTest, GetPhysicalScreenIds, TestSize.Level1)
204 {
205     std::vector<ScreenId> screenIds;
206     auto ret = SingletonContainer::Get<ScreenManagerAdapterLite>().GetPhysicalScreenIds(screenIds);
207     EXPECT_NE(ret, DMError::DM_OK);
208 }
209 
210 /**
211  * @tc.name: SetSpecifiedScreenPowerPiling
212  * @tc.desc: test piling success
213  * @tc.type: FUNC
214  */
215 HWTEST_F(DisplayManagerAdapterLiteTest, SetSpecifiedScreenPowerPiling, TestSize.Level1)
216 {
217 #define SCREENLESS_ENABLE
218     uint64_t screenId = 0;
219     auto ret = SingletonContainer::Get<ScreenManagerAdapterLite>().SetSpecifiedScreenPower(screenId,
220         ScreenPowerState::POWER_ON, PowerStateChangeReason::POWER_BUTTON);
221     EXPECT_TRUE(ret);
222 #undef SCREENLESS_ENABLE
223 }
224 
225 /**
226  * @tc.name: GetScreenPowerPiling
227  * @tc.desc: test piling success
228  * @tc.type: FUNC
229  */
230 HWTEST_F(DisplayManagerAdapterLiteTest, GetScreenPowerPiling, TestSize.Level1)
231 {
232 #define SCREENLESS_ENABLE
233     uint64_t screenId = 0;
234     auto ret = SingletonContainer::Get<ScreenManagerAdapterLite>().GetScreenPower(screenId);
235     EXPECT_EQ(ret, ScreenPowerState::POWER_STAND_BY);
236 #undef SCREENLESS_ENABLE
237 }
238 
239 /**
240  * @tc.name: SetScreenBrightnessPiling
241  * @tc.desc: test piling success
242  * @tc.type: FUNC
243  */
244 HWTEST_F(DisplayManagerAdapterLiteTest, SetScreenBrightnessPiling, TestSize.Level1)
245 {
246 #define SCREENLESS_ENABLE
247     uint64_t screenId = 0;
248     auto ret = SingletonContainer::Get<DisplayManagerAdapterLite>().SetScreenBrightness(screenId, 0);
249     EXPECT_TRUE(ret);
250 #undef SCREENLESS_ENABLE
251 }
252 
253 /**
254  * @tc.name: SetDisplayStatePiling
255  * @tc.desc: test piling success
256  * @tc.type: FUNC
257  */
258 HWTEST_F(DisplayManagerAdapterLiteTest, SetDisplayStatePiling, TestSize.Level1)
259 {
260 #define SCREENLESS_ENABLE
261     auto ret = SingletonContainer::Get<DisplayManagerAdapterLite>().SetDisplayState(DisplayState::ON);
262     EXPECT_TRUE(ret);
263 #undef SCREENLESS_ENABLE
264 }
265 
266 /**
267  * @tc.name: SetScreenPowerForAllPiling
268  * @tc.desc: test piling success
269  * @tc.type: FUNC
270  */
271 HWTEST_F(DisplayManagerAdapterLiteTest, SetScreenPowerForAllPiling, TestSize.Level1)
272 {
273 #define SCREENLESS_ENABLE
274     auto ret = SingletonContainer::Get<ScreenManagerAdapterLite>().SetScreenPowerForAll(ScreenPowerState::POWER_ON,
275         PowerStateChangeReason::POWER_BUTTON);
276     EXPECT_TRUE(ret);
277 #undef SCREENLESS_ENABLE
278 }
279 
280 /**
281  * @tc.name: SuspendEndPiling
282  * @tc.desc: test piling success
283  * @tc.type: FUNC
284  */
285 HWTEST_F(DisplayManagerAdapterLiteTest, SuspendEndPiling, TestSize.Level1)
286 {
287 #define SCREENLESS_ENABLE
288     auto ret = SingletonContainer::Get<DisplayManagerAdapterLite>().SuspendEnd();
289     EXPECT_TRUE(ret);
290 #undef SCREENLESS_ENABLE
291 }
292 
293 /**
294  * @tc.name: SetScreenPowerByIdPiling
295  * @tc.desc: test piling success
296  * @tc.type: FUNC
297  */
298 HWTEST_F(DisplayManagerAdapterLiteTest, SetScreenPowerByIdPiling, TestSize.Level1)
299 {
300 #define SCREENLESS_ENABLE
301     uint64_t screenId = 0;
302     auto ret = SingletonContainer::Get<DisplayManagerAdapterLite>().SetScreenPowerById(screenId,
303         ScreenPowerState::POWER_ON, PowerStateChangeReason::POWER_BUTTON);
304     EXPECT_TRUE(ret);
305 #undef SCREENLESS_ENABLE
306 }
307 
308 /**
309  * @tc.name: SuspendBeginPiling
310  * @tc.desc: test piling success
311  * @tc.type: FUNC
312  */
313 HWTEST_F(DisplayManagerAdapterLiteTest, SuspendBeginPiling, TestSize.Level1)
314 {
315 #define SCREENLESS_ENABLE
316     auto ret = SingletonContainer::Get<DisplayManagerAdapterLite>().SuspendBegin(PowerStateChangeReason::POWER_BUTTON);
317     EXPECT_TRUE(ret);
318 #undef SCREENLESS_ENABLE
319 }
320 
321 /**
322  * @tc.name: WakeUpEndPiling
323  * @tc.desc: test piling success
324  * @tc.type: FUNC
325  */
326 HWTEST_F(DisplayManagerAdapterLiteTest, WakeUpEndPiling, TestSize.Level1)
327 {
328 #define SCREENLESS_ENABLE
329     auto ret = SingletonContainer::Get<DisplayManagerAdapterLite>().WakeUpEnd();
330     EXPECT_TRUE(ret);
331 #undef SCREENLESS_ENABLE
332 }
333 
334 /**
335  * @tc.name: GetScreenBrightnessPiling
336  * @tc.desc: test piling success
337  * @tc.type: FUNC
338  */
339 HWTEST_F(DisplayManagerAdapterLiteTest, GetScreenBrightnessPiling, TestSize.Level1)
340 {
341 #define SCREENLESS_ENABLE
342     auto ret = SingletonContainer::Get<DisplayManagerAdapterLite>().GetScreenBrightness(0);
343     EXPECT_EQ(ret, 0);
344 #undef SCREENLESS_ENABLE
345 }
346 
347 /**
348  * @tc.name: TryToCancelScreenOffPiling
349  * @tc.desc: test piling success
350  * @tc.type: FUNC
351  */
352 HWTEST_F(DisplayManagerAdapterLiteTest, TryToCancelScreenOffPiling, TestSize.Level1)
353 {
354 #define SCREENLESS_ENABLE
355     auto ret = SingletonContainer::Get<DisplayManagerAdapterLite>().TryToCancelScreenOff();
356     EXPECT_TRUE(ret);
357 #undef SCREENLESS_ENABLE
358 }
359 
360 /**
361  * @tc.name: IsFoldablePiling
362  * @tc.desc: test piling success
363  * @tc.type: FUNC
364  */
365 HWTEST_F(DisplayManagerAdapterLiteTest, IsFoldablePiling, TestSize.Level1)
366 {
367 #define SCREENLESS_ENABLE
368     auto ret = SingletonContainer::Get<DisplayManagerAdapterLite>().IsFoldable();
369     EXPECT_FALSE(ret);
370 #undef SCREENLESS_ENABLE
371 }
372 
373 
374 /**
375  * @tc.name: GetInternalScreenIdPiling
376  * @tc.desc: test piling success
377  * @tc.type: FUNC
378  */
379 HWTEST_F(DisplayManagerAdapterLiteTest, GetInternalScreenIdPiling, TestSize.Level1)
380 {
381 #define SCREENLESS_ENABLE
382     auto ret = SingletonContainer::Get<DisplayManagerAdapterLite>().GetInternalScreenId();
383     EXPECT_EQ(ret, 0);
384 #undef SCREENLESS_ENABLE
385 }
386 
387 /**
388  * @tc.name: WakeUpBeginPiling
389  * @tc.desc: test piling success
390  * @tc.type: FUNC
391  */
392 HWTEST_F(DisplayManagerAdapterLiteTest, WakeUpBeginPiling, TestSize.Level1)
393 {
394 #define SCREENLESS_ENABLE
395     auto ret = SingletonContainer::Get<DisplayManagerAdapterLite>().WakeUpBegin(PowerStateChangeReason::POWER_BUTTON);
396     EXPECT_TRUE(ret);
397 #undef SCREENLESS_ENABLE
398 }
399 }
400 }
401 }
402