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