1 /*
2 * Copyright (c) 2022 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 <iremote_broker.h>
19 #include <iremote_object.h>
20 #include "display_manager_proxy.h"
21 #include "iremote_object_mocker.h"
22
23 #include "iconsumer_surface.h"
24 #include <surface.h>
25
26 using namespace testing;
27 using namespace testing::ext;
28
29 namespace OHOS {
30 namespace Rosen {
31 using RemoteMocker = MockIRemoteObject;
32 class DisplayManagerProxyTest : public testing::Test {
33 public:
34 static void SetUpTestCase();
35 static void TearDownTestCase();
36 void SetUp() override;
37 void TearDown() override;
38 };
39
SetUpTestCase()40 void DisplayManagerProxyTest::SetUpTestCase()
41 {
42 }
43
TearDownTestCase()44 void DisplayManagerProxyTest::TearDownTestCase()
45 {
46 }
47
SetUp()48 void DisplayManagerProxyTest::SetUp()
49 {
50 }
51
TearDown()52 void DisplayManagerProxyTest::TearDown()
53 {
54 }
55
56 namespace {
57 /**
58 * @tc.name: GetDefaultDisplayInfo
59 * @tc.desc: test DisplayManagerProxy::GetDefaultDisplayInfo
60 * @tc.type: FUNC
61 */
62 HWTEST_F(DisplayManagerProxyTest, GetDefaultDisplayInfo01, Function | SmallTest | Level1)
63 {
64 DisplayManagerProxy proxy1(nullptr);
65 ASSERT_EQ(nullptr, proxy1.remoteObject_);
66 auto displayInfo1 = proxy1.GetDefaultDisplayInfo();
67 ASSERT_EQ(nullptr, displayInfo1);
68
69 sptr<RemoteMocker> remoteMocker = new RemoteMocker();
70 DisplayManagerProxy proxy2(remoteMocker);
71 ASSERT_EQ(static_cast<sptr<IRemoteObject>>(remoteMocker), proxy2.remoteObject_);
72 auto displayInfo2 = proxy2.GetDefaultDisplayInfo();
73 ASSERT_EQ(nullptr, displayInfo2);
74
75 remoteMocker->sendRequestResult_ = 1;
76 auto displayInfo3 = proxy2.GetDefaultDisplayInfo();
77 ASSERT_EQ(nullptr, displayInfo3);
78 }
79 /**
80 * @tc.name: GetDisplayInfoById01
81 * @tc.desc: test DisplayManagerProxy::GetDisplayInfoById
82 * @tc.type: FUNC
83 */
84 HWTEST_F(DisplayManagerProxyTest, GetDisplayInfoById01, Function | SmallTest | Level1)
85 {
86 DisplayManagerProxy proxy1(nullptr);
87 ASSERT_EQ(nullptr, proxy1.remoteObject_);
88 auto displayInfo1 = proxy1.GetDisplayInfoById(0);
89 ASSERT_EQ(nullptr, displayInfo1);
90
91 sptr<RemoteMocker> remoteMocker = new RemoteMocker();
92 DisplayManagerProxy proxy2(remoteMocker);
93 ASSERT_EQ(static_cast<sptr<IRemoteObject>>(remoteMocker), proxy2.remoteObject_);
94
95 auto displayInfo2 = proxy2.GetDisplayInfoById(0);
96 ASSERT_EQ(nullptr, displayInfo2);
97
98 remoteMocker->sendRequestResult_ = 1;
99 auto displayInfo3 = proxy2.GetDisplayInfoById(0);
100 ASSERT_EQ(nullptr, displayInfo3);
101 }
102 /**
103 * @tc.name: GetDisplayInfoByScreen01
104 * @tc.desc: test DisplayManagerProxy::GetDisplayInfoByScreen
105 * @tc.type: FUNC
106 */
107 HWTEST_F(DisplayManagerProxyTest, GetDisplayInfoByScreen01, Function | SmallTest | Level1)
108 {
109 DisplayManagerProxy proxy1(nullptr);
110 ASSERT_EQ(nullptr, proxy1.remoteObject_);
111 auto displayInfo1 = proxy1.GetDisplayInfoByScreen(0);
112 ASSERT_EQ(nullptr, displayInfo1);
113
114 sptr<RemoteMocker> remoteMocker = new RemoteMocker();
115 DisplayManagerProxy proxy2(remoteMocker);
116 ASSERT_EQ(static_cast<sptr<IRemoteObject>>(remoteMocker), proxy2.remoteObject_);
117
118 auto displayInfo2 = proxy2.GetDisplayInfoByScreen(0);
119 ASSERT_EQ(nullptr, displayInfo2);
120
121 remoteMocker->sendRequestResult_ = 1;
122 auto displayInfo3 = proxy2.GetDisplayInfoByScreen(0);
123 ASSERT_EQ(nullptr, displayInfo3);
124 }
125 /**
126 * @tc.name: CreateVirtualScreen01
127 * @tc.desc: test DisplayManagerProxy::CreateVirtualScreen
128 * @tc.type: FUNC
129 */
130 HWTEST_F(DisplayManagerProxyTest, CreateVirtualScreen01, Function | SmallTest | Level1)
131 {
132 DisplayManagerProxy proxy1(nullptr);
133 ASSERT_EQ(nullptr, proxy1.remoteObject_);
134 VirtualScreenOption virtualOption1;
135 virtualOption1.name_ = "testVirtualOption";
136 sptr<IRemoteObject> displayManagerAgent1 = new RemoteMocker();
137 auto screenId1 = proxy1.CreateVirtualScreen(virtualOption1, displayManagerAgent1);
138 ASSERT_EQ(SCREEN_ID_INVALID, screenId1);
139
140 sptr<RemoteMocker> remoteMocker = new RemoteMocker();
141 DisplayManagerProxy proxy2(remoteMocker);
142 ASSERT_EQ(static_cast<sptr<IRemoteObject>>(remoteMocker), proxy2.remoteObject_);
143
144 VirtualScreenOption virtualOption2;
145 virtualOption2.name_ = "testVirtualOption";
146 sptr<IRemoteObject> displayManagerAgent2 = new RemoteMocker();
147 auto screenId2 = proxy2.CreateVirtualScreen(virtualOption2, displayManagerAgent2);
148 ASSERT_EQ(0, screenId2);
149
150 remoteMocker->sendRequestResult_ = 1;
151 auto screenId3 = proxy2.CreateVirtualScreen(virtualOption2, displayManagerAgent2);
152 ASSERT_EQ(SCREEN_ID_INVALID, screenId3);
153 }
154 /**
155 * @tc.name: DestroyVirtualScreen01
156 * @tc.desc: test DisplayManagerProxy::DestroyVirtualScreen
157 * @tc.type: FUNC
158 */
159 HWTEST_F(DisplayManagerProxyTest, DestroyVirtualScreen01, Function | SmallTest | Level1)
160 {
161 DisplayManagerProxy proxy1(nullptr);
162 ASSERT_EQ(nullptr, proxy1.remoteObject_);
163 auto result1 = proxy1.DestroyVirtualScreen(0);
164 ASSERT_EQ(DMError::DM_ERROR_REMOTE_CREATE_FAILED, result1);
165
166 sptr<RemoteMocker> remoteMocker = new RemoteMocker();
167 DisplayManagerProxy proxy2(remoteMocker);
168 ASSERT_EQ(static_cast<sptr<IRemoteObject>>(remoteMocker), proxy2.remoteObject_);
169
170 auto result2 = proxy2.DestroyVirtualScreen(0);
171 ASSERT_EQ(DMError::DM_OK, result2);
172
173 remoteMocker->sendRequestResult_ = 1;
174 auto result3 = proxy2.DestroyVirtualScreen(0);
175 ASSERT_EQ(DMError::DM_ERROR_IPC_FAILED, result3);
176 }
177 /**
178 * @tc.name: SetVirtualScreenSurface01
179 * @tc.desc: test DisplayManagerProxy::SetVirtualScreenSurface
180 * @tc.type: FUNC
181 */
182 HWTEST_F(DisplayManagerProxyTest, SetVirtualScreenSurface01, Function | SmallTest | Level1)
183 {
184 DisplayManagerProxy proxy1(nullptr);
185 ASSERT_EQ(nullptr, proxy1.remoteObject_);
186 auto result1 = proxy1.SetVirtualScreenSurface(0, nullptr);
187 ASSERT_EQ(DMError::DM_ERROR_REMOTE_CREATE_FAILED, result1);
188
189 sptr<RemoteMocker> remoteMocker = new RemoteMocker();
190 DisplayManagerProxy proxy2(remoteMocker);
191 ASSERT_EQ(static_cast<sptr<IRemoteObject>>(remoteMocker), proxy2.remoteObject_);
192
193 auto result2 = proxy2.SetVirtualScreenSurface(0, nullptr);
194 ASSERT_EQ(DMError::DM_OK, result2);
195 sptr<IConsumerSurface> surface = OHOS::IConsumerSurface::Create();
196 auto result3 = proxy2.SetVirtualScreenSurface(0, surface->GetProducer());
197 ASSERT_EQ(DMError::DM_OK, result3);
198
199 remoteMocker->sendRequestResult_ = 1;
200 auto result4 = proxy2.SetVirtualScreenSurface(0, surface->GetProducer());
201 ASSERT_EQ(DMError::DM_ERROR_IPC_FAILED, result4);
202 }
203 /**
204 * @tc.name: SetOrientation01
205 * @tc.desc: test DisplayManagerProxy::SetOrientation
206 * @tc.type: FUNC
207 */
208 HWTEST_F(DisplayManagerProxyTest, SetOrientation01, Function | SmallTest | Level1)
209 {
210 DisplayManagerProxy proxy1(nullptr);
211 ASSERT_EQ(nullptr, proxy1.remoteObject_);
212 auto result1 = proxy1.SetOrientation(0, Orientation::VERTICAL);
213 ASSERT_TRUE(DMError::DM_OK != result1);
214
215 sptr<RemoteMocker> remoteMocker = new RemoteMocker();
216 DisplayManagerProxy proxy2(remoteMocker);
217 ASSERT_EQ(static_cast<sptr<IRemoteObject>>(remoteMocker), proxy2.remoteObject_);
218
219 auto result2 = proxy2.SetOrientation(0, Orientation::VERTICAL);
220 ASSERT_TRUE(DMError::DM_OK == result2);
221
222 remoteMocker->sendRequestResult_ = 1;
223 auto result3 = proxy2.SetOrientation(0, Orientation::VERTICAL);
224 ASSERT_EQ(DMError::DM_ERROR_IPC_FAILED, result3);
225 }
226 /**
227 * @tc.name: GetDisplaySnapshot01
228 * @tc.desc: test DisplayManagerProxy::GetDisplaySnapshot
229 * @tc.type: FUNC
230 */
231 HWTEST_F(DisplayManagerProxyTest, GetDisplaySnapshot01, Function | SmallTest | Level1)
232 {
233 DisplayManagerProxy proxy1(nullptr);
234 ASSERT_EQ(nullptr, proxy1.remoteObject_);
235 auto result1 = proxy1.GetDisplaySnapshot(0);
236 ASSERT_EQ(nullptr, result1);
237
238 sptr<RemoteMocker> remoteMocker = new RemoteMocker();
239 DisplayManagerProxy proxy2(remoteMocker);
240 ASSERT_EQ(static_cast<sptr<IRemoteObject>>(remoteMocker), proxy2.remoteObject_);
241
242 auto result2 = proxy2.GetDisplaySnapshot(0);
243 ASSERT_EQ(nullptr, result2);
244 remoteMocker->sendRequestResult_ = 1;
245 auto result3 = proxy2.GetDisplaySnapshot(0);
246 ASSERT_EQ(nullptr, result3);
247 }
248 /**
249 * @tc.name: GetScreenSupportedColorGamuts01
250 * @tc.desc: test DisplayManagerProxy::GetScreenSupportedColorGamuts
251 * @tc.type: FUNC
252 */
253 HWTEST_F(DisplayManagerProxyTest, GetScreenSupportedColorGamuts01, Function | SmallTest | Level1)
254 {
255 std::vector<ScreenColorGamut> gamutVector;
256 DisplayManagerProxy proxy1(nullptr);
257 ASSERT_EQ(nullptr, proxy1.remoteObject_);
258 auto result1 = proxy1.GetScreenSupportedColorGamuts(0, gamutVector);
259 ASSERT_EQ(DMError::DM_ERROR_NULLPTR, result1);
260 gamutVector.clear();
261
262 sptr<RemoteMocker> remoteMocker = new RemoteMocker();
263 DisplayManagerProxy proxy2(remoteMocker);
264 ASSERT_EQ(static_cast<sptr<IRemoteObject>>(remoteMocker), proxy2.remoteObject_);
265 auto result2 = proxy2.GetScreenSupportedColorGamuts(0, gamutVector);
266 ASSERT_EQ(DMError::DM_OK, result2);
267 remoteMocker->sendRequestResult_ = 1;
268 auto result3 = proxy2.GetScreenSupportedColorGamuts(0, gamutVector);
269 ASSERT_EQ(DMError::DM_ERROR_IPC_FAILED, result3);
270 }
271 /**
272 * @tc.name: GetScreenColorGamut01
273 * @tc.desc: test DisplayManagerProxy::GetScreenColorGamut
274 * @tc.type: FUNC
275 */
276 HWTEST_F(DisplayManagerProxyTest, GetScreenColorGamut01, Function | SmallTest | Level1)
277 {
278 DisplayManagerProxy proxy1(nullptr);
279 ASSERT_EQ(nullptr, proxy1.remoteObject_);
280 ScreenColorGamut screenColorGamut;
281 auto result1 = proxy1.GetScreenColorGamut(0, screenColorGamut);
282 ASSERT_EQ(DMError::DM_ERROR_NULLPTR, result1);
283
284 sptr<RemoteMocker> remoteMocker = new RemoteMocker();
285 DisplayManagerProxy proxy2(remoteMocker);
286 ASSERT_EQ(static_cast<sptr<IRemoteObject>>(remoteMocker), proxy2.remoteObject_);
287 screenColorGamut = ScreenColorGamut::COLOR_GAMUT_ADOBE_RGB;
288 auto result2 = proxy2.GetScreenColorGamut(0, screenColorGamut);
289 ASSERT_EQ(DMError::DM_OK, result2);
290 ASSERT_EQ(ScreenColorGamut::COLOR_GAMUT_NATIVE, screenColorGamut);
291
292 screenColorGamut = ScreenColorGamut::COLOR_GAMUT_ADOBE_RGB;
293 remoteMocker->sendRequestResult_ = 1;
294 auto result3 = proxy2.GetScreenColorGamut(0, screenColorGamut);
295 ASSERT_EQ(DMError::DM_ERROR_IPC_FAILED, result3);
296 ASSERT_EQ(ScreenColorGamut::COLOR_GAMUT_ADOBE_RGB, screenColorGamut);
297 }
298 }
299 } // namespace Rosen
300 } // namespace OHOS