• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 #include "display_manager.h"
18 #include "display_manager_proxy.h"
19 #include "screen_manager.h"
20 #include "screen_manager_utils.h"
21 #include "mock_display_manager_adapter.h"
22 #include "singleton_mocker.h"
23 #include "scene_board_judgement.h"
24 #include "../../../window_scene/screen_session_manager/include/screen_scene_config.h"
25 
26 using namespace testing;
27 using namespace testing::ext;
28 
29 namespace OHOS {
30 namespace Rosen {
31 namespace {
32     constexpr uint32_t SLEEP_TIME_IN_US = 100000; // 100ms
33 }
34 using Mocker = SingletonMocker<ScreenManagerAdapter, MockScreenManagerAdapter>;
35 class ScreenTest : public testing::Test {
36 public:
37     static void SetUpTestCase();
38     static void TearDownTestCase();
39     virtual void SetUp() override;
40     virtual void TearDown() override;
41 
42     static sptr<Display> defaultDisplay_;
43     static ScreenId defaultScreenId_;
44     static sptr<Screen> screen_;
45 };
46 sptr<Display> ScreenTest::defaultDisplay_ = nullptr;
47 ScreenId ScreenTest::defaultScreenId_ = SCREEN_ID_INVALID;
48 sptr<Screen> ScreenTest::screen_ = nullptr;
49 bool g_isPcDevice = ScreenSceneConfig::GetExternalScreenDefaultMode() == "none";
50 
SetUpTestCase()51 void ScreenTest::SetUpTestCase()
52 {
53     defaultDisplay_ = DisplayManager::GetInstance().GetDefaultDisplay();
54     defaultScreenId_ = static_cast<ScreenId>(defaultDisplay_->GetId());
55     screen_ = ScreenManager::GetInstance().GetScreenById(defaultScreenId_);
56     usleep(SLEEP_TIME_IN_US);
57 }
58 
TearDownTestCase()59 void ScreenTest::TearDownTestCase()
60 {
61     defaultDisplay_ = nullptr;
62     screen_ = nullptr;
63 }
64 
SetUp()65 void ScreenTest::SetUp()
66 {
67 }
68 
TearDown()69 void ScreenTest::TearDown()
70 {
71 }
72 
73 namespace {
74 /**
75  * @tc.name: GetBasicProperty01
76  * @tc.desc: Basic property getter test
77  * @tc.type: FUNC
78  */
79 HWTEST_F(ScreenTest, GetBasicProperty01, Function | SmallTest | Level1)
80 {
81     ASSERT_GT(screen_->GetName().size(), 0);
82     ASSERT_GT(screen_->GetWidth(), 0);
83     ASSERT_GT(screen_->GetHeight(), 0);
84     ASSERT_GT(screen_->GetVirtualWidth(), 0);
85     ASSERT_GT(screen_->GetVirtualHeight(), 0);
86     ASSERT_GT(screen_->GetVirtualPixelRatio(), 0);
87     ASSERT_EQ(screen_->IsReal(), true);
88     ASSERT_NE(screen_->GetScreenInfo(), nullptr);
89 }
90 
91 /**
92  * @tc.name: SetScreenActiveMode01
93  * @tc.desc: SetScreenActiveMode with valid modeId and return success
94  * @tc.type: FUNC
95  */
96 HWTEST_F(ScreenTest, SetScreenActiveMode01, Function | SmallTest | Level1)
97 {
98     auto supportedModes = screen_->GetSupportedModes();
99     ASSERT_GT(supportedModes.size(), 0);
100     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
101     EXPECT_CALL(m->Mock(), SetScreenActiveMode(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
102     DMError res = screen_->SetScreenActiveMode(supportedModes.size() - 1);
103     ASSERT_EQ(DMError::DM_OK, res);
104 }
105 
106 /**
107  * @tc.name: SetScreenActiveMode02
108  * @tc.desc: SetScreenActiveMode with valid modeId and return failed
109  * @tc.type: FUNC
110  */
111 HWTEST_F(ScreenTest, SetScreenActiveMode02, Function | SmallTest | Level1)
112 {
113     auto supportedModes = screen_->GetSupportedModes();
114     ASSERT_GT(supportedModes.size(), 0);
115     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
116     EXPECT_CALL(m->Mock(), SetScreenActiveMode(_, _)).Times(1).WillOnce(Return(DMError::DM_ERROR_NULLPTR));
117     DMError res = screen_->SetScreenActiveMode(supportedModes.size() - 1);
118     ASSERT_TRUE(DMError::DM_OK != res);
119 }
120 
121 /**
122  * @tc.name: GetScreenSupportedColorGamuts01
123  * @tc.desc: GetScreenSupportedColorGamuts
124  * @tc.type: FUNC
125  */
126 HWTEST_F(ScreenTest, GetScreenSupportedColorGamuts01, Function | SmallTest | Level2)
127 {
128     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
129     EXPECT_CALL(m->Mock(), GetScreenSupportedColorGamuts(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
130     std::vector<ScreenColorGamut> colorGamuts;
131     auto res = screen_->GetScreenSupportedColorGamuts(colorGamuts);
132     ASSERT_EQ(DMError::DM_OK, res);
133 }
134 
135 /**
136  * @tc.name: GetScreenColorGamut01
137  * @tc.desc: GetScreenColorGamut
138  * @tc.type: FUNC
139  */
140 HWTEST_F(ScreenTest, GetScreenColorGamut01, Function | SmallTest | Level2)
141 {
142     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
143     EXPECT_CALL(m->Mock(), GetScreenColorGamut(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
144     ScreenColorGamut colorGamut = ScreenColorGamut::COLOR_GAMUT_SRGB;
145     auto res = screen_->GetScreenColorGamut(colorGamut);
146     ASSERT_EQ(DMError::DM_OK, res);
147 }
148 
149 /**
150  * @tc.name: SetScreenColorGamut01
151  * @tc.desc: SetScreenColorGamut
152  * @tc.type: FUNC
153  */
154 HWTEST_F(ScreenTest, SetScreenColorGamut01, Function | SmallTest | Level2)
155 {
156     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
157     EXPECT_CALL(m->Mock(), SetScreenColorGamut(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
158     ScreenColorGamut colorGamut = ScreenColorGamut::COLOR_GAMUT_SRGB;
159     auto res = screen_->SetScreenColorGamut(colorGamut);
160     ASSERT_EQ(DMError::DM_OK, res);
161 }
162 
163 /**
164  * @tc.name: GetScreenGamutMap01
165  * @tc.desc: GetScreenGamutMap
166  * @tc.type: FUNC
167  */
168 HWTEST_F(ScreenTest, GetScreenGamutMap01, Function | SmallTest | Level2)
169 {
170     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
171     EXPECT_CALL(m->Mock(), GetScreenGamutMap(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
172     ScreenGamutMap gamutMap = ScreenGamutMap::GAMUT_MAP_CONSTANT;
173     auto res = screen_->GetScreenGamutMap(gamutMap);
174     ASSERT_EQ(DMError::DM_OK, res);
175 }
176 
177 /**
178  * @tc.name: SetScreenGamutMap01
179  * @tc.desc: SetScreenGamutMap
180  * @tc.type: FUNC
181  */
182 HWTEST_F(ScreenTest, SetScreenGamutMap01, Function | SmallTest | Level2)
183 {
184     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
185     EXPECT_CALL(m->Mock(), SetScreenGamutMap(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
186     ScreenGamutMap gamutMap = ScreenGamutMap::GAMUT_MAP_CONSTANT;
187     auto res = screen_->SetScreenGamutMap(gamutMap);
188     ASSERT_EQ(DMError::DM_OK, res);
189 }
190 
191 /**
192  * @tc.name: SetScreenColorTransform01
193  * @tc.desc: SetScreenColorTransform
194  * @tc.type: FUNC
195  */
196 HWTEST_F(ScreenTest, SetScreenColorTransform01, Function | SmallTest | Level2)
197 {
198     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
199     EXPECT_CALL(m->Mock(), SetScreenColorTransform(_)).Times(1).WillOnce(Return(DMError::DM_OK));
200     auto res = screen_->SetScreenColorTransform();
201     ASSERT_EQ(DMError::DM_OK, res);
202 }
203 
204 /**
205  * @tc.name: IsGroup
206  * @tc.desc: for interface coverage and check IsGroup
207  * @tc.type: FUNC
208  */
209 HWTEST_F(ScreenTest, IsGroup, Function | SmallTest | Level2)
210 {
211     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
212     sptr<ScreenInfo> screenInfo = screen_->GetScreenInfo();
213     screenInfo->SetIsScreenGroup(true);
214     EXPECT_CALL(m->Mock(), GetScreenInfo(_)).Times(1).WillOnce(Return(screenInfo));
215     ASSERT_EQ(true, screen_->IsGroup());
216     screenInfo->SetIsScreenGroup(false);
217     EXPECT_CALL(m->Mock(), GetScreenInfo(_)).Times(1).WillOnce(Return(screenInfo));
218     ASSERT_EQ(false, screen_->IsGroup());
219 }
220 
221 /**
222  * @tc.name: GetParentId
223  * @tc.desc: for interface coverage and check GetParentId
224  * @tc.type: FUNC
225  */
226 HWTEST_F(ScreenTest, GetParentId, Function | SmallTest | Level2)
227 {
228     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
229     sptr<ScreenInfo> screenInfo = screen_->GetScreenInfo();
230     screenInfo->SetParentId(0);
231     EXPECT_CALL(m->Mock(), GetScreenInfo(_)).Times(1).WillOnce(Return(screenInfo));
232     ASSERT_EQ(0, screen_->GetParentId());
233     screenInfo->SetParentId(SCREEN_ID_INVALID);
234     EXPECT_CALL(m->Mock(), GetScreenInfo(_)).Times(1).WillOnce(Return(screenInfo));
235     ASSERT_EQ(SCREEN_ID_INVALID, screen_->GetParentId());
236 }
237 
238 /**
239  * @tc.name: GetRotation
240  * @tc.desc: for interface coverage and check GetRotation
241  * @tc.type: FUNC
242  */
243 HWTEST_F(ScreenTest, GetRotation, Function | SmallTest | Level2)
244 {
245     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
246     sptr<ScreenInfo> screenInfo = screen_->GetScreenInfo();
247     screenInfo->SetParentId(0);
248     EXPECT_CALL(m->Mock(), GetScreenInfo(_)).Times(1).WillOnce(Return(screenInfo));
249     ASSERT_EQ(Rotation::ROTATION_0, screen_->GetRotation());
250 }
251 
252 /**
253  * @tc.name: GetOrientation
254  * @tc.desc: for interface coverage and check GetOrientation
255  * @tc.type: FUNC
256  */
257 HWTEST_F(ScreenTest, GetOrientation, Function | SmallTest | Level2)
258 {
259     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
260     sptr<ScreenInfo> screenInfo = screen_->GetScreenInfo();
261     screenInfo->SetParentId(0);
262     EXPECT_CALL(m->Mock(), GetScreenInfo(_)).Times(1).WillOnce(Return(screenInfo));
263     if (g_isPcDevice) {
264         ASSERT_EQ(Orientation::VERTICAL, screen_->GetOrientation());
265     } else {
266         ASSERT_EQ(Orientation::BEGIN, screen_->GetOrientation());
267     }
268 }
269 
270 /**
271  * @tc.name: SetOrientation
272  * @tc.desc: SetOrientation
273  * @tc.type: FUNC
274  */
275 HWTEST_F(ScreenTest, SetOrientation, Function | SmallTest | Level2)
276 {
277     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
278     EXPECT_CALL(m->Mock(), SetOrientation(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
279     Orientation orientation = Orientation{0};
280     auto res = screen_->SetOrientation(orientation);
281     ASSERT_EQ(DMError::DM_OK, res);
282 }
283 
284 /**
285  * @tc.name: GetPixelFormat
286  * @tc.desc: GetPixelFormat
287  * @tc.type: FUNC
288  */
289 HWTEST_F(ScreenTest, GetPixelFormat, Function | SmallTest | Level2)
290 {
291     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
292     EXPECT_CALL(m->Mock(), GetPixelFormat(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
293     GraphicPixelFormat pixelFormat = GraphicPixelFormat{GRAPHIC_PIXEL_FMT_CLUT8};
294     auto res = screen_->GetPixelFormat(pixelFormat);
295     ASSERT_EQ(DMError::DM_OK, res);
296 }
297 
298 /**
299  * @tc.name: SetPixelFormat
300  * @tc.desc: SetPixelFormat
301  * @tc.type: FUNC
302  */
303 HWTEST_F(ScreenTest, SetPixelFormat, Function | SmallTest | Level2)
304 {
305     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
306     EXPECT_CALL(m->Mock(), SetPixelFormat(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
307     GraphicPixelFormat pixelFormat = GraphicPixelFormat{GRAPHIC_PIXEL_FMT_CLUT8};
308     auto res = screen_->SetPixelFormat(pixelFormat);
309     ASSERT_EQ(DMError::DM_OK, res);
310 }
311 
312 /**
313  * @tc.name: GetSupportedHDRFormats
314  * @tc.desc: GetSupportedHDRFormats
315  * @tc.type: FUNC
316  */
317 HWTEST_F(ScreenTest, GetSupportedHDRFormats, Function | SmallTest | Level2)
318 {
319     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
320     EXPECT_CALL(m->Mock(), GetSupportedHDRFormats(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
321     std::vector<ScreenHDRFormat> hdrFormats;
322     auto res = screen_->GetSupportedHDRFormats(hdrFormats);
323     ASSERT_EQ(DMError::DM_OK, res);
324 }
325 
326 /**
327  * @tc.name: GetScreenHDRFormat
328  * @tc.desc: GetScreenHDRFormat
329  * @tc.type: FUNC
330  */
331 HWTEST_F(ScreenTest, GetScreenHDRFormat, Function | SmallTest | Level2)
332 {
333     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
334     EXPECT_CALL(m->Mock(), GetScreenHDRFormat(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
335     ScreenHDRFormat hdrFormat = ScreenHDRFormat{0};
336     auto res = screen_->GetScreenHDRFormat(hdrFormat);
337     ASSERT_EQ(DMError::DM_OK, res);
338 }
339 
340 /**
341  * @tc.name: SetScreenHDRFormat
342  * @tc.desc: SetScreenHDRFormat
343  * @tc.type: FUNC
344  */
345 HWTEST_F(ScreenTest, SetScreenHDRFormat, Function | SmallTest | Level2)
346 {
347     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
348     EXPECT_CALL(m->Mock(), SetScreenHDRFormat(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
349     auto res = screen_->SetScreenHDRFormat(0);
350     ASSERT_EQ(DMError::DM_OK, res);
351 }
352 
353 /**
354  * @tc.name: GetSupportedColorSpaces
355  * @tc.desc: GetSupportedColorSpaces
356  * @tc.type: FUNC
357  */
358 HWTEST_F(ScreenTest, GetSupportedColorSpaces, Function | SmallTest | Level2)
359 {
360     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
361     EXPECT_CALL(m->Mock(), GetSupportedColorSpaces(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
362     std::vector<GraphicCM_ColorSpaceType> colorSpaces;
363     auto res = screen_->GetSupportedColorSpaces(colorSpaces);
364     ASSERT_EQ(DMError::DM_OK, res);
365 }
366 
367 /**
368  * @tc.name: GetScreenColorSpace
369  * @tc.desc: GetScreenColorSpace
370  * @tc.type: FUNC
371  */
372 HWTEST_F(ScreenTest, GetScGetScreenColorSpacereenHDRFormat, Function | SmallTest | Level2)
373 {
374     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
375     EXPECT_CALL(m->Mock(), GetScreenColorSpace(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
376     GraphicCM_ColorSpaceType colorSpace = GraphicCM_ColorSpaceType{GRAPHIC_CM_COLORSPACE_NONE};
377     auto res = screen_->GetScreenColorSpace(colorSpace);
378     ASSERT_EQ(DMError::DM_OK, res);
379 }
380 
381 /**
382  * @tc.name: SetScreenColorSpace
383  * @tc.desc: SetScreenColorSpace
384  * @tc.type: FUNC
385  */
386 HWTEST_F(ScreenTest, SetScreenColorSpace, Function | SmallTest | Level2)
387 {
388     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
389     EXPECT_CALL(m->Mock(), SetScreenColorSpace(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
390     GraphicCM_ColorSpaceType colorSpace = GraphicCM_ColorSpaceType{GRAPHIC_CM_COLORSPACE_NONE};
391     auto res = screen_->SetScreenColorSpace(colorSpace);
392     ASSERT_EQ(DMError::DM_OK, res);
393 }
394 
395 /**
396  * @tc.name: SetDensityDpi01
397  * @tc.desc: SetDensityDpi
398  * @tc.type: FUNC
399  */
400 HWTEST_F(ScreenTest, SetDensityDpi, Function | SmallTest | Level2)
401 {
402     auto res = screen_->SetDensityDpi(DOT_PER_INCH_MAXIMUM_VALUE + 1);
403     ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, res);
404 
405     res = screen_->SetDensityDpi(100);
406     ASSERT_EQ(DMError::DM_OK, res);
407 }
408 
409 /**
410  * @tc.name: SetResolution
411  * @tc.desc: SetResolution
412  * @tc.type: FUNC
413  */
414 HWTEST_F(ScreenTest, SetResolution, Function | SmallTest | Level2)
415 {
416     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
417     EXPECT_CALL(m->Mock(), SetResolution(_, _, _, _)).Times(1).WillOnce(Return(DMError::DM_OK));
418     auto res = screen_->SetResolution(0, 0, 1000);
419     ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, res);
420 
421     res = screen_->SetResolution(1, 1, 100);
422     ASSERT_EQ(DMError::DM_OK, res);
423 }
424 
425 /**
426  * @tc.name: SetDensityDpiSystem01
427  * @tc.desc: SetDensityDpiSystem
428  * @tc.type: FUNC
429  */
430 HWTEST_F(ScreenTest, SetDensityDpiSystem, Function | SmallTest | Level2)
431 {
432     auto res = screen_->SetDensityDpiSystem(DOT_PER_INCH_MAXIMUM_VALUE + 1);
433     ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, res);
434 
435     res = screen_->SetDensityDpiSystem(100);
436     if (SceneBoardJudgement::IsSceneBoardEnabled()) {
437         ASSERT_EQ(DMError::DM_OK, res);
438     } else {
439         ASSERT_NE(DMError::DM_OK, res);
440     }
441 }
442 
443 /**
444  * @tc.name: GetDensityInCurResolution
445  * @tc.desc: GetDensityInCurResolution
446  * @tc.type: FUNC
447  */
448 HWTEST_F(ScreenTest, GetDensityInCurResolution, Function | SmallTest | Level2)
449 {
450     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
451     EXPECT_CALL(m->Mock(), GetDensityInCurResolution(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
452     float virtualPixelRatio;
453     auto res = screen_->GetDensityInCurResolution(virtualPixelRatio);
454     ASSERT_EQ(DMError::DM_OK, res);
455 }
456 
457 /**
458  * @tc.name: SetDefaultDensityDpi01
459  * @tc.desc: SetDefaultDensityDpi
460  * @tc.type: FUNC
461  *
462  */
463 HWTEST_F(ScreenTest, SetDefaultDensityDpi, Function | SmallTest | Level2)
464 {
465     auto res = screen_->SetDefaultDensityDpi(DOT_PER_INCH_MAXIMUM_VALUE + 1);
466     ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, res);
467 
468     res = screen_->SetDefaultDensityDpi(100);
469     if (SceneBoardJudgement::IsSceneBoardEnabled()) {
470         ASSERT_EQ(DMError::DM_OK, res);
471     } else {
472         ASSERT_NE(DMError::DM_OK, res);
473     }
474 }
475 
476 /**
477  * @tc.name: GetSerialNumber
478  * @tc.desc: GetSerialNumber
479  * @tc.type: FUNC
480  */
481 HWTEST_F(ScreenTest, GetSerialNumber, Function | SmallTest | Level2)
482 {
483     auto res = screen_->GetSerialNumber();
484     ASSERT_EQ(res, "");
485 }
486 }
487 } // namespace Rosen
488 } // namespace OHOS