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 #include <message_option.h>
18 #include <message_parcel.h>
19 #include <iremote_broker.h>
20 #include "display_manager_lite_proxy.h"
21 #include "display_manager_adapter_lite.h"
22 #include "display_manager_agent_default.h"
23 #include "scene_board_judgement.h"
24 
25 using namespace testing;
26 using namespace testing::ext;
27 namespace OHOS {
28 namespace Rosen {
29 class DisplayManagerLiteProxyTest : public testing::Test {
30 public:
31     static void SetUpTestCase();
32     static void TearDownTestCase();
33     void SetUp() override;
34     void TearDown() override;
35 };
36 
SetUpTestCase()37 void DisplayManagerLiteProxyTest::SetUpTestCase()
38 {
39 }
40 
TearDownTestCase()41 void DisplayManagerLiteProxyTest::TearDownTestCase()
42 {
43 }
44 
SetUp()45 void DisplayManagerLiteProxyTest::SetUp()
46 {
47 }
48 
TearDown()49 void DisplayManagerLiteProxyTest::TearDown()
50 {
51 }
52 
53 namespace {
54 /**
55  * @tc.name: RegisterDisplayManagerAgent
56  * @tc.desc: RegisterDisplayManagerAgent
57  * @tc.type: FUNC
58  */
59 HWTEST_F(DisplayManagerLiteProxyTest, RegisterDisplayManagerAgent, Function | SmallTest | Level1)
60 {
61     SingletonContainer::Get<DisplayManagerAdapterLite>().InitDMSProxy();
62     sptr<IRemoteObject> impl =
63         SingletonContainer::Get<DisplayManagerAdapterLite>().displayManagerServiceProxy_->AsObject();
64     sptr<DisplayManagerLiteProxy> displayManagerLiteProxy = new DisplayManagerLiteProxy(impl);
65     sptr<IDisplayManagerAgent> displayManagerAgent = new DisplayManagerAgentDefault();
66     DisplayManagerAgentType type = DisplayManagerAgentType::SCREEN_EVENT_LISTENER;
67     if (SceneBoardJudgement::IsSceneBoardEnabled()) {
68         EXPECT_EQ(DMError::DM_OK, displayManagerLiteProxy->RegisterDisplayManagerAgent(displayManagerAgent, type));
69     } else {
70         EXPECT_NE(DMError::DM_OK, displayManagerLiteProxy->RegisterDisplayManagerAgent(displayManagerAgent, type));
71     }
72     displayManagerAgent = nullptr;
73     EXPECT_EQ(DMError::DM_ERROR_INVALID_PARAM,
74               displayManagerLiteProxy->RegisterDisplayManagerAgent(displayManagerAgent, type));
75 }
76 
77 /**
78  * @tc.name: UnregisterDisplayManagerAgent
79  * @tc.desc: UnregisterDisplayManagerAgent
80  * @tc.type: FUNC
81  */
82 HWTEST_F(DisplayManagerLiteProxyTest, UnregisterDisplayManagerAgent, Function | SmallTest | Level1)
83 {
84     SingletonContainer::Get<DisplayManagerAdapterLite>().InitDMSProxy();
85     sptr<IRemoteObject> impl =
86         SingletonContainer::Get<DisplayManagerAdapterLite>().displayManagerServiceProxy_->AsObject();
87     sptr<DisplayManagerLiteProxy> displayManagerLiteProxy = new DisplayManagerLiteProxy(impl);
88     sptr<IDisplayManagerAgent> displayManagerAgent = new DisplayManagerAgentDefault();
89     DisplayManagerAgentType type = DisplayManagerAgentType::SCREEN_EVENT_LISTENER;
90     if (SceneBoardJudgement::IsSceneBoardEnabled()) {
91         EXPECT_EQ(DMError::DM_OK, displayManagerLiteProxy->UnregisterDisplayManagerAgent(displayManagerAgent, type));
92     } else {
93         EXPECT_NE(DMError::DM_OK, displayManagerLiteProxy->UnregisterDisplayManagerAgent(displayManagerAgent, type));
94     }
95     displayManagerAgent = nullptr;
96     EXPECT_EQ(DMError::DM_ERROR_INVALID_PARAM,
97               displayManagerLiteProxy->UnregisterDisplayManagerAgent(displayManagerAgent, type));
98 }
99 
100 /**
101  * @tc.name: GetFoldDisplayMode
102  * @tc.desc: GetFoldDisplayMode
103  * @tc.type: FUNC
104  */
105 HWTEST_F(DisplayManagerLiteProxyTest, GetFoldDisplayMode, Function | SmallTest | Level1)
106 {
107     SingletonContainer::Get<DisplayManagerAdapterLite>().InitDMSProxy();
108     sptr<IRemoteObject> impl =
109         SingletonContainer::Get<DisplayManagerAdapterLite>().displayManagerServiceProxy_->AsObject();
110     sptr<DisplayManagerLiteProxy> displayManagerLiteProxy = new DisplayManagerLiteProxy(impl);
111 
112     EXPECT_EQ(FoldDisplayMode::UNKNOWN,
113               displayManagerLiteProxy->GetFoldDisplayMode());
114 }
115 
116 /**
117  * @tc.name: SetFoldDisplayMode
118  * @tc.desc: SetFoldDisplayMode
119  * @tc.type: FUNC
120  */
121 HWTEST_F(DisplayManagerLiteProxyTest, SetFoldDisplayMode, Function | SmallTest | Level1)
122 {
123     SingletonContainer::Get<DisplayManagerAdapterLite>().InitDMSProxy();
124     sptr<IRemoteObject> impl =
125         SingletonContainer::Get<DisplayManagerAdapterLite>().displayManagerServiceProxy_->AsObject();
126     sptr<DisplayManagerLiteProxy> displayManagerLiteProxy = new DisplayManagerLiteProxy(impl);
127 
128     int resultValue = 0;
129     const FoldDisplayMode displayMode {0};
130     std::function<void()> func = [&]()
__anon6db42fc80202() 131     {
132         displayManagerLiteProxy->SetFoldDisplayMode(displayMode);
133         resultValue = 1;
134     };
135     func();
136     EXPECT_EQ(resultValue, 1);
137 }
138 
139 /**
140  * @tc.name: IsFoldable
141  * @tc.desc: IsFoldable
142  * @tc.type: FUNC
143  */
144 HWTEST_F(DisplayManagerLiteProxyTest, IsFoldable, Function | SmallTest | Level1)
145 {
146     SingletonContainer::Get<DisplayManagerAdapterLite>().InitDMSProxy();
147     sptr<IRemoteObject> impl =
148         SingletonContainer::Get<DisplayManagerAdapterLite>().displayManagerServiceProxy_->AsObject();
149     sptr<DisplayManagerLiteProxy> displayManagerLiteProxy = new DisplayManagerLiteProxy(impl);
150 
151     int resultValue = 0;
152     std::function<void()> func = [&]()
__anon6db42fc80302() 153     {
154         displayManagerLiteProxy->IsFoldable();
155         resultValue = 1;
156     };
157     func();
158     EXPECT_EQ(resultValue, 1);
159 }
160 
161 /**
162  * @tc.name: GetFoldStatus
163  * @tc.desc: GetFoldStatus
164  * @tc.type: FUNC
165  */
166 HWTEST_F(DisplayManagerLiteProxyTest, GetFoldStatus, Function | SmallTest | Level1)
167 {
168     SingletonContainer::Get<DisplayManagerAdapterLite>().InitDMSProxy();
169     sptr<IRemoteObject> impl =
170         SingletonContainer::Get<DisplayManagerAdapterLite>().displayManagerServiceProxy_->AsObject();
171     sptr<DisplayManagerLiteProxy> displayManagerLiteProxy = new DisplayManagerLiteProxy(impl);
172     ASSERT_NE(displayManagerLiteProxy, nullptr);
173     displayManagerLiteProxy->GetFoldStatus();
174 }
175 
176 /**
177  * @tc.name: GetDefaultDisplayInfo
178  * @tc.desc: GetDefaultDisplayInfo
179  * @tc.type: FUNC
180  */
181 HWTEST_F(DisplayManagerLiteProxyTest, GetDefaultDisplayInfo, Function | SmallTest | Level1)
182 {
183     SingletonContainer::Get<DisplayManagerAdapterLite>().InitDMSProxy();
184 
185     sptr<IRemoteObject> impl =
186         SingletonContainer::Get<DisplayManagerAdapterLite>().displayManagerServiceProxy_->AsObject();
187     sptr<DisplayManagerLiteProxy> displayManagerLiteProxy = new DisplayManagerLiteProxy(impl);
188 
189     sptr<DisplayInfo> expectation = nullptr;
190     sptr<DisplayInfo> res = nullptr;
191     std::function<void()> func = [&]()
__anon6db42fc80402() 192     {
193         res = displayManagerLiteProxy->GetDefaultDisplayInfo();
194     };
195     func();
196     if (SceneBoardJudgement::IsSceneBoardEnabled()) {
197         ASSERT_NE(res, expectation);
198     } else {
199         ASSERT_EQ(res, expectation);
200     }
201 }
202 
203 /**
204  * @tc.name: GetDisplayInfoById
205  * @tc.desc: GetDisplayInfoById
206  * @tc.type: FUNC
207  */
208 HWTEST_F(DisplayManagerLiteProxyTest, GetDisplayInfoById, Function | SmallTest | Level1)
209 {
210     SingletonContainer::Get<DisplayManagerAdapterLite>().InitDMSProxy();
211 
212     sptr<IRemoteObject> impl =
213         SingletonContainer::Get<DisplayManagerAdapterLite>().displayManagerServiceProxy_->AsObject();
214     sptr<DisplayManagerLiteProxy> displayManagerLiteProxy = new DisplayManagerLiteProxy(impl);
215 
216     sptr<DisplayInfo> expectation = nullptr;
217     sptr<DisplayInfo> res = nullptr;
218     DisplayId displayId {0};
219     std::function<void()> func = [&]()
__anon6db42fc80502() 220     {
221         res = displayManagerLiteProxy->GetDisplayInfoById(displayId);
222     };
223     func();
224     if (SceneBoardJudgement::IsSceneBoardEnabled()) {
225         ASSERT_NE(res, expectation);
226     } else {
227         ASSERT_EQ(res, expectation);
228     }
229 }
230 
231 /**
232  * @tc.name: GetCutoutInfo
233  * @tc.desc: GetCutoutInfo
234  * @tc.type: FUNC
235  */
236 HWTEST_F(DisplayManagerLiteProxyTest, GetCutoutInfo, Function | SmallTest | Level1)
237 {
238     SingletonContainer::Get<DisplayManagerAdapterLite>().InitDMSProxy();
239 
240     sptr<IRemoteObject> impl =
241         SingletonContainer::Get<DisplayManagerAdapterLite>().displayManagerServiceProxy_->AsObject();
242     sptr<DisplayManagerLiteProxy> displayManagerLiteProxy = new DisplayManagerLiteProxy(impl);
243 
244     sptr<CutoutInfo> expectation = nullptr;
245     sptr<CutoutInfo> res = nullptr;
246     DisplayId displayId = 0;
247     std::function<void()> func = [&]()
__anon6db42fc80602() 248     {
249         res = displayManagerLiteProxy->GetCutoutInfo(displayId);
250     };
251     func();
252     if (SceneBoardJudgement::IsSceneBoardEnabled()) {
253         ASSERT_NE(res, expectation);
254     } else {
255         ASSERT_EQ(res, expectation);
256     }
257 }
258 
259 
260 /**
261  * @tc.name: WakeUpBegin
262  * @tc.desc: WakeUpBegin
263  * @tc.type: FUNC
264  */
265 HWTEST_F(DisplayManagerLiteProxyTest, WakeUpBegin, Function | SmallTest | Level1)
266 {
267     SingletonContainer::Get<DisplayManagerAdapterLite>().InitDMSProxy();
268     sptr<IRemoteObject> impl =
269         SingletonContainer::Get<DisplayManagerAdapterLite>().displayManagerServiceProxy_->AsObject();
270     sptr<DisplayManagerLiteProxy> displayManagerLiteProxy = new DisplayManagerLiteProxy(impl);
271 
272     PowerStateChangeReason reason {0};
273     bool expectation = true;
274     if (SceneBoardJudgement::IsSceneBoardEnabled()) {
275         EXPECT_EQ(expectation, displayManagerLiteProxy->WakeUpBegin(reason));
276     } else {
277         EXPECT_NE(expectation, displayManagerLiteProxy->WakeUpBegin(reason));
278     }
279 }
280 
281 /**
282  * @tc.name: WakeUpEnd
283  * @tc.desc: WakeUpEnd
284  * @tc.type: FUNC
285  */
286 HWTEST_F(DisplayManagerLiteProxyTest, WakeUpEnd, Function | SmallTest | Level1)
287 {
288     SingletonContainer::Get<DisplayManagerAdapterLite>().InitDMSProxy();
289     sptr<IRemoteObject> impl =
290         SingletonContainer::Get<DisplayManagerAdapterLite>().displayManagerServiceProxy_->AsObject();
291     sptr<DisplayManagerLiteProxy> displayManagerLiteProxy = new DisplayManagerLiteProxy(impl);
292 
293     bool expectation = true;
294     if (SceneBoardJudgement::IsSceneBoardEnabled()) {
295         EXPECT_EQ(expectation, displayManagerLiteProxy->WakeUpEnd());
296     } else {
297         EXPECT_NE(expectation, displayManagerLiteProxy->WakeUpEnd());
298     }
299 }
300 
301 /**
302  * @tc.name: SuspendEnd
303  * @tc.desc: SuspendEnd
304  * @tc.type: FUNC
305  */
306 HWTEST_F(DisplayManagerLiteProxyTest, SuspendEnd, Function | SmallTest | Level1)
307 {
308     SingletonContainer::Get<DisplayManagerAdapterLite>().InitDMSProxy();
309     sptr<IRemoteObject> impl =
310         SingletonContainer::Get<DisplayManagerAdapterLite>().displayManagerServiceProxy_->AsObject();
311     sptr<DisplayManagerLiteProxy> displayManagerLiteProxy = new DisplayManagerLiteProxy(impl);
312 
313     bool expectation = true;
314     if (SceneBoardJudgement::IsSceneBoardEnabled()) {
315         EXPECT_EQ(expectation, displayManagerLiteProxy->SuspendEnd());
316     } else {
317         EXPECT_NE(expectation, displayManagerLiteProxy->SuspendEnd());
318     }
319 }
320 
321 /**
322  * @tc.name: SetDisplayState
323  * @tc.desc: SetDisplayState
324  * @tc.type: FUNC
325  */
326 HWTEST_F(DisplayManagerLiteProxyTest, SetDisplayState, Function | SmallTest | Level1)
327 {
328     SingletonContainer::Get<DisplayManagerAdapterLite>().InitDMSProxy();
329     sptr<IRemoteObject> impl =
330         SingletonContainer::Get<DisplayManagerAdapterLite>().displayManagerServiceProxy_->AsObject();
331     sptr<DisplayManagerLiteProxy> displayManagerLiteProxy = new DisplayManagerLiteProxy(impl);
332 
333     DisplayState state {1};
334     displayManagerLiteProxy->SetDisplayState(state);
335     int resultValue = 0;
336     ASSERT_EQ(resultValue, 0);
337 }
338 
339 /**
340  * @tc.name: SetSpecifiedScreenPower
341  * @tc.desc: SetSpecifiedScreenPower
342  * @tc.type: FUNC
343  */
344 HWTEST_F(DisplayManagerLiteProxyTest, SetSpecifiedScreenPower, Function | SmallTest | Level1)
345 {
346     SingletonContainer::Get<DisplayManagerAdapterLite>().InitDMSProxy();
347     sptr<IRemoteObject> impl =
348         SingletonContainer::Get<DisplayManagerAdapterLite>().displayManagerServiceProxy_->AsObject();
349     sptr<DisplayManagerLiteProxy> displayManagerLiteProxy = new DisplayManagerLiteProxy(impl);
350 
351     ScreenPowerState state {0};
352     ScreenId id = 1001;
353     PowerStateChangeReason reason {1};
354     bool expectation = true;
355     if (SceneBoardJudgement::IsSceneBoardEnabled()) {
356         EXPECT_EQ(expectation, displayManagerLiteProxy->SetSpecifiedScreenPower(id, state, reason));
357     } else {
358         EXPECT_NE(expectation, displayManagerLiteProxy->SetSpecifiedScreenPower(id, state, reason));
359     }
360 }
361 
362 /**
363  * @tc.name: SetScreenPowerForAll
364  * @tc.desc: SetScreenPowerForAll
365  * @tc.type: FUNC
366  */
367 HWTEST_F(DisplayManagerLiteProxyTest, SetScreenPowerForAll, Function | SmallTest | Level1)
368 {
369     SingletonContainer::Get<DisplayManagerAdapterLite>().InitDMSProxy();
370     sptr<IRemoteObject> impl =
371         SingletonContainer::Get<DisplayManagerAdapterLite>().displayManagerServiceProxy_->AsObject();
372     sptr<DisplayManagerLiteProxy> displayManagerLiteProxy = new DisplayManagerLiteProxy(impl);
373 
374     ScreenPowerState state {0};
375     PowerStateChangeReason reason {1};
376     bool expectation = true;
377     if (SceneBoardJudgement::IsSceneBoardEnabled()) {
378         EXPECT_EQ(expectation, displayManagerLiteProxy->SetScreenPowerForAll(state, reason));
379     } else {
380         EXPECT_NE(expectation, displayManagerLiteProxy->SetScreenPowerForAll(state, reason));
381     }
382 }
383 
384 /**
385  * @tc.name: GetScreenPower
386  * @tc.desc: GetScreenPower
387  * @tc.type: FUNC
388  */
389 HWTEST_F(DisplayManagerLiteProxyTest, GetScreenPower, Function | SmallTest | Level1)
390 {
391     SingletonContainer::Get<DisplayManagerAdapterLite>().InitDMSProxy();
392     sptr<IRemoteObject> impl =
393         SingletonContainer::Get<DisplayManagerAdapterLite>().displayManagerServiceProxy_->AsObject();
394     sptr<DisplayManagerLiteProxy> displayManagerLiteProxy = new DisplayManagerLiteProxy(impl);
395 
396     ScreenId dmsScreenId = 1001;
397     if (SceneBoardJudgement::IsSceneBoardEnabled()) {
398         EXPECT_NE(ScreenPowerState::INVALID_STATE, displayManagerLiteProxy->GetScreenPower(dmsScreenId));
399     } else {
400         EXPECT_EQ(ScreenPowerState::INVALID_STATE, displayManagerLiteProxy->GetScreenPower(dmsScreenId));
401     }
402 }
403 
404 /**
405  * @tc.name: GetDisplayState
406  * @tc.desc: GetDisplayState
407  * @tc.type: FUNC
408  */
409 HWTEST_F(DisplayManagerLiteProxyTest, GetDisplayState, Function | SmallTest | Level1)
410 {
411     SingletonContainer::Get<DisplayManagerAdapterLite>().InitDMSProxy();
412     sptr<IRemoteObject> impl =
413         SingletonContainer::Get<DisplayManagerAdapterLite>().displayManagerServiceProxy_->AsObject();
414     sptr<DisplayManagerLiteProxy> displayManagerLiteProxy = new DisplayManagerLiteProxy(impl);
415 
416     DisplayId displayId {0};
417     if (SceneBoardJudgement::IsSceneBoardEnabled()) {
418         EXPECT_NE(DisplayState::UNKNOWN, displayManagerLiteProxy->GetDisplayState(displayId));
419     } else {
420         EXPECT_EQ(DisplayState::UNKNOWN, displayManagerLiteProxy->GetDisplayState(displayId));
421     }
422 }
423 
424 /**
425  * @tc.name: GetAllDisplayIds
426  * @tc.desc: GetAllDisplayIds
427  * @tc.type: FUNC
428  */
429 HWTEST_F(DisplayManagerLiteProxyTest, GetAllDisplayIds, Function | SmallTest | Level1)
430 {
431     SingletonContainer::Get<DisplayManagerAdapterLite>().InitDMSProxy();
432 
433     sptr<IRemoteObject> impl =
434         SingletonContainer::Get<DisplayManagerAdapterLite>().displayManagerServiceProxy_->AsObject();
435     sptr<DisplayManagerLiteProxy> displayManagerLiteProxy = new DisplayManagerLiteProxy(impl);
436 
437     int resultValue = 0;
438     std::function<void()> func = [&]()
__anon6db42fc80702() 439     {
440         displayManagerLiteProxy->GetAllDisplayIds();
441         resultValue = 1;
442     };
443     func();
444     ASSERT_EQ(resultValue, 1);
445 }
446 }
447 }
448 }