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 #include "scene_board_judgement.h"
19 
20 using namespace testing;
21 using namespace testing::ext;
22 
23 namespace OHOS {
24 namespace Rosen {
25 class DisplayManagerAdapterLiteTest : public testing::Test {
26 public:
27     static void SetUpTestCase();
28     static void TearDownTestCase();
29     void SetUp() override;
30     void TearDown() override;
31 };
32 
SetUpTestCase()33 void DisplayManagerAdapterLiteTest::SetUpTestCase()
34 {
35 }
36 
TearDownTestCase()37 void DisplayManagerAdapterLiteTest::TearDownTestCase()
38 {
39 }
40 
SetUp()41 void DisplayManagerAdapterLiteTest::SetUp()
42 {
43 }
44 
TearDown()45 void DisplayManagerAdapterLiteTest::TearDown()
46 {
47 }
48 
49 namespace {
50 /**
51  * @tc.name: OnRemoteDied
52  * @tc.desc: test nullptr
53  * @tc.type: FUNC
54  */
55 HWTEST_F(DisplayManagerAdapterLiteTest, OnRemoteDied, Function | SmallTest | Level2)
56 {
57     sptr<IRemoteObject::DeathRecipient> dmsDeath_ = nullptr;
58     dmsDeath_ = new(std::nothrow) DMSDeathRecipientLite(SingletonContainer::Get<DisplayManagerAdapterLite>());
59     dmsDeath_->OnRemoteDied(nullptr);
60     ASSERT_NE(dmsDeath_, nullptr);
61 }
62 
63 /**
64  * @tc.name: OnRemoteDied01
65  * @tc.desc: test nullptr
66  * @tc.type: FUNC
67  */
68 HWTEST_F(DisplayManagerAdapterLiteTest, OnRemoteDied01, Function | SmallTest | Level2)
69 {
70     sptr<IRemoteObject::DeathRecipient> dmsDeath_ = nullptr;
71     dmsDeath_ = new(std::nothrow) DMSDeathRecipientLite(SingletonContainer::Get<DisplayManagerAdapterLite>());
72     SingletonContainer::Get<DisplayManagerAdapterLite>().InitDMSProxy();
73     sptr<IRemoteObject> obj =
74         SingletonContainer::Get<DisplayManagerAdapterLite>().displayManagerServiceProxy_->AsObject();
75     wptr<IRemoteObject> wptrDeath = obj;
76     dmsDeath_->OnRemoteDied(wptrDeath);
77     ASSERT_NE(dmsDeath_, nullptr);
78 }
79 
80 /**
81  * @tc.name: Clear
82  * @tc.desc: test success
83  * @tc.type: FUNC
84  */
85 HWTEST_F(DisplayManagerAdapterLiteTest, Clear, Function | SmallTest | Level2)
86 {
87     SingletonContainer::Get<DisplayManagerAdapterLite>().InitDMSProxy();
88     SingletonContainer::Get<DisplayManagerAdapterLite>().Clear();
89     ASSERT_FALSE(SingletonContainer::Get<DisplayManagerAdapterLite>().isProxyValid_);
90 }
91 
92 /**
93  * @tc.name: Clear01
94  * @tc.desc: test success
95  * @tc.type: FUNC
96  */
97 HWTEST_F(DisplayManagerAdapterLiteTest, Clear01, Function | SmallTest | Level2)
98 {
99     SingletonContainer::Get<DisplayManagerAdapterLite>().InitDMSProxy();
100     SingletonContainer::Get<DisplayManagerAdapterLite>().displayManagerServiceProxy_ = nullptr;
101     SingletonContainer::Get<DisplayManagerAdapterLite>().Clear();
102     ASSERT_FALSE(SingletonContainer::Get<DisplayManagerAdapterLite>().isProxyValid_);
103 }
104 
105 /**
106  * @tc.name: WakeUpBegin
107  * @tc.desc: test WakeUpBegin
108  * @tc.type: FUNC
109  */
110 HWTEST_F(DisplayManagerAdapterLiteTest, WakeUpBegin, Function | SmallTest | Level2)
111 {
112     PowerStateChangeReason reason = PowerStateChangeReason{0};
113     bool ret = SingletonContainer::Get<DisplayManagerAdapterLite>().WakeUpBegin(reason);
114     ASSERT_TRUE(ret);
115 }
116 
117 /**
118  * @tc.name: WakeUpEnd
119  * @tc.desc: test WakeUpEnd
120  * @tc.type: FUNC
121  */
122 HWTEST_F(DisplayManagerAdapterLiteTest, WakeUpEnd, Function | SmallTest | Level2)
123 {
124     bool ret = SingletonContainer::Get<DisplayManagerAdapterLite>().WakeUpEnd();
125     ASSERT_TRUE(ret);
126 }
127 
128 /**
129  * @tc.name: SuspendBegin
130  * @tc.desc: test SuspendBegin
131  * @tc.type: FUNC
132  */
133 HWTEST_F(DisplayManagerAdapterLiteTest, SuspendBegin, Function | SmallTest | Level2)
134 {
135     PowerStateChangeReason reason = PowerStateChangeReason{0};
136     bool ret = SingletonContainer::Get<DisplayManagerAdapterLite>().SuspendBegin(reason);
137     ASSERT_TRUE(ret);
138 }
139 
140 /**
141  * @tc.name: SuspendEnd
142  * @tc.desc: test SuspendEnd
143  * @tc.type: FUNC
144  */
145 HWTEST_F(DisplayManagerAdapterLiteTest, SuspendEnd, Function | SmallTest | Level2)
146 {
147     bool ret = SingletonContainer::Get<DisplayManagerAdapterLite>().SuspendEnd();
148     ASSERT_TRUE(ret);
149 }
150 
151 /**
152  * @tc.name: SetDisplayState
153  * @tc.desc: test SetDisplayState
154  * @tc.type: FUNC
155  */
156 HWTEST_F(DisplayManagerAdapterLiteTest, SetDisplayState, Function | SmallTest | Level2)
157 {
158     DisplayState state = DisplayState{1};
159     bool ret = SingletonContainer::Get<DisplayManagerAdapterLite>().SetDisplayState(state);
160     if (SceneBoardJudgement::IsSceneBoardEnabled()) {
161         ASSERT_TRUE(ret);
162     } else {
163         ASSERT_FALSE(ret);
164     }
165 }
166 }
167 }
168 }
169