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, Function | SmallTest | Level2)
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, Function | SmallTest | Level2)
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, Function | SmallTest | Level2)
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, Function | SmallTest | Level2)
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, Function | SmallTest | Level2)
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, Function | SmallTest | Level2)
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, Function | SmallTest | Level2)
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, Function | SmallTest | Level2)
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, Function | SmallTest | Level2)
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, Function | SmallTest | Level2)
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, Function | SmallTest | 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, Function | SmallTest | Level1)
193 {
194 auto ret = SingletonContainer::Get<DisplayManagerAdapterLite>().SetSystemKeyboardStatus(false);
195 ASSERT_NE(ret, DMError::DM_OK);
196 }
197 }
198 }
199 }
200