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 #include "screen_property.h"
16 #include <gtest/gtest.h>
17 
18 // using namespace FRAME_TRACE;
19 using namespace testing;
20 using namespace testing::ext;
21 namespace OHOS {
22 namespace Rosen {
23 class ScreenPropertyTest : public testing::Test {
24   public:
ScreenPropertyTest()25     ScreenPropertyTest() {}
~ScreenPropertyTest()26     ~ScreenPropertyTest() {}
27 };
28 
29 namespace {
30 /**
31  * @tc.name: SetScreenRotation
32  * @tc.desc: normal function
33  * @tc.type: FUNC
34  */
35 HWTEST_F(ScreenPropertyTest, SetScreenRotation, Function | SmallTest | Level2)
36 {
37     GTEST_LOG_(INFO) << "ScreenPropertyTest: SetScreenRotation start";
38     ScreenProperty* property = new(std::nothrow) ScreenProperty();
39     int64_t ret = 0;
40     Rotation rotation = Rotation::ROTATION_0;
41     property->SetScreenRotation(rotation);
42 
43     rotation = Rotation::ROTATION_90;
44     property->SetScreenRotation(rotation);
45 
46     rotation = Rotation::ROTATION_180;
47     property->SetScreenRotation(rotation);
48 
49     rotation = Rotation::ROTATION_270;
50     property->SetScreenRotation(rotation);
51     ASSERT_EQ(ret, 0);
52     GTEST_LOG_(INFO) << "ScreenPropertyTest: SetScreenRotation end";
53 }
54 
55 /**
56  * @tc.name: UpdateDeviceRotation
57  * @tc.desc: normal function
58  * @tc.type: FUNC
59  */
60 HWTEST_F(ScreenPropertyTest, UpdateDeviceRotation, Function | SmallTest | Level2)
61 {
62     GTEST_LOG_(INFO) << "ScreenPropertyTest: UpdateDeviceRotation start";
63     ScreenProperty* property = new(std::nothrow) ScreenProperty();
64     Rotation ret = Rotation::ROTATION_0;
65     Rotation rotation = Rotation::ROTATION_0;
66     property->UpdateDeviceRotation(rotation);
67     ret = property->GetDeviceRotation();
68     ASSERT_EQ(ret, rotation);
69 
70     rotation = Rotation::ROTATION_90;
71     property->UpdateDeviceRotation(rotation);
72     ret = property->GetDeviceRotation();
73     ASSERT_EQ(ret, rotation);
74 
75     rotation = Rotation::ROTATION_180;
76     property->UpdateDeviceRotation(rotation);
77     ret = property->GetDeviceRotation();
78     ASSERT_EQ(ret, rotation);
79 
80     rotation = Rotation::ROTATION_270;
81     property->UpdateDeviceRotation(rotation);
82     ret = property->GetDeviceRotation();
83     ASSERT_EQ(ret, rotation);
84     GTEST_LOG_(INFO) << "ScreenPropertyTest: UpdateDeviceRotation end";
85 }
86 
87 /**
88  * @tc.name: SetDeviceOrientation
89  * @tc.desc: normal function
90  * @tc.type: FUNC
91  */
92 HWTEST_F(ScreenPropertyTest, SetDeviceOrientation, Function | SmallTest | Level2)
93 {
94     GTEST_LOG_(INFO) << "ScreenPropertyTest: SetDeviceOrientation start";
95     ScreenProperty* property = new(std::nothrow) ScreenProperty();
96     DisplayOrientation ret = DisplayOrientation::PORTRAIT;
97     DisplayOrientation displayOrientation = DisplayOrientation::PORTRAIT;
98     property->SetDeviceOrientation(displayOrientation);
99     ret = property->GetDeviceOrientation();
100     ASSERT_EQ(ret, displayOrientation);
101 
102     displayOrientation = DisplayOrientation::LANDSCAPE;
103     property->SetDeviceOrientation(displayOrientation);
104     ret = property->GetDeviceOrientation();
105     ASSERT_EQ(ret, displayOrientation);
106 
107     displayOrientation = DisplayOrientation::PORTRAIT_INVERTED;
108     property->SetDeviceOrientation(displayOrientation);
109     ret = property->GetDeviceOrientation();
110     ASSERT_EQ(ret, displayOrientation);
111 
112     displayOrientation = DisplayOrientation::LANDSCAPE_INVERTED;
113     property->SetDeviceOrientation(displayOrientation);
114     ret = property->GetDeviceOrientation();
115     ASSERT_EQ(ret, displayOrientation);
116     GTEST_LOG_(INFO) << "ScreenPropertyTest: SetDeviceOrientation end";
117 }
118 
119 /**
120  * @tc.name: UpdateVirtualPixelRatio
121  * @tc.desc: normal function
122  * @tc.type: FUNC
123  */
124 HWTEST_F(ScreenPropertyTest, UpdateVirtualPixelRatio, Function | SmallTest | Level2)
125 {
126     GTEST_LOG_(INFO) << "ScreenPropertyTest: UpdateVirtualPixelRatio start";
127     ScreenProperty* property = new(std::nothrow) ScreenProperty();
128     int64_t ret = 0;
129     RRect bounds;
130     bounds.rect_.width_ = 1344;
131     bounds.rect_.height_ = 2772;
132 
133     property->UpdateVirtualPixelRatio(bounds);
134 
135     bounds.rect_.height_ = 1111;
136     property->UpdateVirtualPixelRatio(bounds);
137 
138     bounds.rect_.width_ = 1111;
139     bounds.rect_.height_ = 2772;
140     property->UpdateVirtualPixelRatio(bounds);
141 
142     bounds.rect_.width_ = 1111;
143     bounds.rect_.height_ = 1111;
144     property->UpdateVirtualPixelRatio(bounds);
145     ASSERT_EQ(ret, 0);
146     GTEST_LOG_(INFO) << "ScreenPropertyTest: UpdateVirtualPixelRatio end";
147 }
148 
149 /**
150  * @tc.name: SetBounds
151  * @tc.desc: normal function
152  * @tc.type: FUNC
153  */
154 HWTEST_F(ScreenPropertyTest, SetBounds, Function | SmallTest | Level2)
155 {
156     GTEST_LOG_(INFO) << "ScreenPropertyTest: SetBounds start";
157     ScreenProperty* property = new(std::nothrow) ScreenProperty();
158     int64_t ret = 0;
159     RRect bounds;
160     bounds.rect_.width_ = 1344;
161     bounds.rect_.height_ = 2772;
162 
163     uint32_t phyWidth = UINT32_MAX;
164     property->SetPhyWidth(phyWidth);
165     uint32_t phyHeigth = UINT32_MAX;
166     property->SetPhyHeight(phyHeigth);
167     property->SetBounds(bounds);
168 
169     bounds.rect_.width_ = 2772;
170     bounds.rect_.height_ = 1344;
171 
172     uint32_t phyWidth1 = 2772;
173     property->SetPhyWidth(phyWidth1);
174     uint32_t phyHeigth1 = 1344;
175     property->SetPhyHeight(phyHeigth1);
176     property->SetBounds(bounds);
177     ASSERT_EQ(ret, 0);
178     GTEST_LOG_(INFO) << "ScreenPropertyTest: SetBounds end";
179 }
180 
181 /**
182  * @tc.name: CalculateXYDpi
183  * @tc.desc: normal function
184  * @tc.type: FUNC
185  */
186 HWTEST_F(ScreenPropertyTest, CalculateXYDpi, Function | SmallTest | Level2)
187 {
188     GTEST_LOG_(INFO) << "ScreenPropertyTest: CalculateXYDpi start";
189     ScreenProperty* property = new(std::nothrow) ScreenProperty();
190     uint32_t phyWidth = 0;
191     uint32_t phyHeight = 0;
192     int ret = 0;
193     property->CalculateXYDpi(phyWidth, phyHeight);
194     phyWidth = 1;
195     phyHeight = 1;
196     property->CalculateXYDpi(phyWidth, phyHeight);
197     ASSERT_EQ(ret, 0);
198     delete property;
199     GTEST_LOG_(INFO) << "ScreenPropertyTest: CalculateXYDpi end";
200 }
201 
202 /**
203  * @tc.name: SetOffsetX
204  * @tc.desc: normal function
205  * @tc.type: FUNC
206  */
207 HWTEST_F(ScreenPropertyTest, SetOffsetX, Function | SmallTest | Level2)
208 {
209     GTEST_LOG_(INFO) << "ScreenPropertyTest: SetOffsetX start";
210     ScreenProperty* property = new(std::nothrow) ScreenProperty();
211     int32_t offsetX = 0;
212     property->SetOffsetX(offsetX);
213     int32_t ret = property->GetOffsetX();
214     ASSERT_EQ(ret, offsetX);
215     delete property;
216     GTEST_LOG_(INFO) << "ScreenPropertyTest: SetOffsetX end";
217 }
218 
219 /**
220  * @tc.name: SetOffsetY
221  * @tc.desc: normal function
222  * @tc.type: FUNC
223  */
224 HWTEST_F(ScreenPropertyTest, SetOffsetY, Function | SmallTest | Level2)
225 {
226     GTEST_LOG_(INFO) << "ScreenPropertyTest: SetOffsetY start";
227     ScreenProperty* property = new(std::nothrow) ScreenProperty();
228     int32_t offsetY = 0;
229     property->SetOffsetY(offsetY);
230     int32_t ret = property->GetOffsetY();
231     ASSERT_EQ(ret, offsetY);
232     delete property;
233     GTEST_LOG_(INFO) << "ScreenPropertyTest: SetOffsetY end";
234 }
235 
236 /**
237  * @tc.name: SetOffset
238  * @tc.desc: normal function
239  * @tc.type: FUNC
240  */
241 HWTEST_F(ScreenPropertyTest, SetOffset, Function | SmallTest | Level2)
242 {
243     GTEST_LOG_(INFO) << "ScreenPropertyTest: SetOffset start";
244     ScreenProperty* property = new(std::nothrow) ScreenProperty();
245     int32_t offsetX = 0;
246     int32_t offsetY = 0;
247     property->SetOffset(offsetX, offsetY);
248     int32_t ret_x = property->GetOffsetX();
249     int32_t ret_y = property->GetOffsetY();
250     ASSERT_EQ(ret_x, offsetX);
251     ASSERT_EQ(ret_y, offsetY);
252     delete property;
253     GTEST_LOG_(INFO) << "ScreenPropertyTest: SetOffset end";
254 }
255 
256 /**
257  * @tc.name: SetScreenRequestedOrientation
258  * @tc.desc: normal function
259  * @tc.type: FUNC
260  */
261 HWTEST_F(ScreenPropertyTest, SetScreenRequestedOrientation, Function | SmallTest | Level2)
262 {
263     GTEST_LOG_(INFO) << "ScreenPropertyTest: SetScreenRequestedOrientation start";
264     ScreenProperty* property = new(std::nothrow) ScreenProperty();
265     Orientation orientation = Orientation::UNSPECIFIED;
266     property->SetScreenRequestedOrientation(orientation);
267     Orientation ret = property->GetScreenRequestedOrientation();
268     ASSERT_EQ(ret, orientation);
269     delete property;
270     GTEST_LOG_(INFO) << "ScreenPropertyTest: SetScreenRequestedOrientation end";
271 }
272 
273 /**
274  * @tc.name: GetPhyHeight
275  * @tc.desc: normal function
276  * @tc.type: FUNC
277  */
278 HWTEST_F(ScreenPropertyTest, GetPhyHeight, Function | SmallTest | Level2)
279 {
280     GTEST_LOG_(INFO) << "ScreenPropertyTest: GetPhyHeight start";
281     ScreenProperty* property = new(std::nothrow) ScreenProperty();
282     uint32_t phyHeight = 1;
283     property->SetPhyHeight(phyHeight);
284     int32_t ret = property->GetPhyHeight();
285     ASSERT_EQ(ret, phyHeight);
286     delete property;
287     GTEST_LOG_(INFO) << "ScreenPropertyTest: GetPhyHeight end";
288 }
289 
290 /**
291  * @tc.name: SetRotation
292  * @tc.desc: normal function
293  * @tc.type: FUNC
294  */
295 HWTEST_F(ScreenPropertyTest, SetRotation, Function | SmallTest | Level2)
296 {
297     GTEST_LOG_(INFO) << "ScreenPropertyTest: SetRotation start";
298     ScreenProperty* property = new(std::nothrow) ScreenProperty();
299     ASSERT_NE(property, nullptr);
300     float rotation = 2.0f;
301     property->SetRotation(rotation);
302     ASSERT_EQ(property->rotation_, rotation);
303     delete property;
304     GTEST_LOG_(INFO) << "ScreenPropertyTest: SetRotation end";
305 }
306 
307 /**
308  * @tc.name: GetRotation
309  * @tc.desc: normal function
310  * @tc.type: FUNC
311  */
312 HWTEST_F(ScreenPropertyTest, GetRotation, Function | SmallTest | Level2)
313 {
314     GTEST_LOG_(INFO) << "ScreenPropertyTest: GetRotation start";
315     ScreenProperty* property = new(std::nothrow) ScreenProperty();
316     ASSERT_NE(property, nullptr);
317     float rotation = property->GetRotation();
318     ASSERT_EQ(property->rotation_, rotation);
319     delete property;
320     GTEST_LOG_(INFO) << "ScreenPropertyTest: GetRotation end";
321 }
322 
323 /**
324  * @tc.name: SetPhysicalRotation
325  * @tc.desc: normal function
326  * @tc.type: FUNC
327  */
328 HWTEST_F(ScreenPropertyTest, SetPhysicalRotation, Function | SmallTest | Level2)
329 {
330     GTEST_LOG_(INFO) << "ScreenPropertyTest: SetPhysicalRotation start";
331     ScreenProperty* property = new(std::nothrow) ScreenProperty();
332     ASSERT_NE(property, nullptr);
333     float rotation = 2.0f;
334     property->SetPhysicalRotation(rotation);
335     ASSERT_EQ(property->physicalRotation_, rotation);
336     delete property;
337     GTEST_LOG_(INFO) << "ScreenPropertyTest: SetPhysicalRotation end";
338 }
339 
340 /**
341  * @tc.name: GetPhysicalRotation
342  * @tc.desc: normal function
343  * @tc.type: FUNC
344  */
345 HWTEST_F(ScreenPropertyTest, GetPhysicalRotation, Function | SmallTest | Level2)
346 {
347     GTEST_LOG_(INFO) << "ScreenPropertyTest: GetPhysicalRotation start";
348     ScreenProperty* property = new(std::nothrow) ScreenProperty();
349     ASSERT_NE(property, nullptr);
350     float rotation = property->GetPhysicalRotation();
351     ASSERT_EQ(property->physicalRotation_, rotation);
352     delete property;
353     GTEST_LOG_(INFO) << "ScreenPropertyTest: GetPhysicalRotation end";
354 }
355 
356 /**
357  * @tc.name: SetScreenComponentRotation
358  * @tc.desc: normal function
359  * @tc.type: FUNC
360  */
361 HWTEST_F(ScreenPropertyTest, SetScreenComponentRotation, Function | SmallTest | Level2)
362 {
363     GTEST_LOG_(INFO) << "ScreenPropertyTest: SetScreenComponentRotation start";
364     ScreenProperty* property = new(std::nothrow) ScreenProperty();
365     ASSERT_NE(property, nullptr);
366     float rotation = 2.0f;
367     property->SetScreenComponentRotation(rotation);
368     ASSERT_EQ(property->screenComponentRotation_, rotation);
369     delete property;
370     GTEST_LOG_(INFO) << "ScreenPropertyTest: SetScreenComponentRotation end";
371 }
372 
373 /**
374  * @tc.name: GetScreenComponentRotation
375  * @tc.desc: normal function
376  * @tc.type: FUNC
377  */
378 HWTEST_F(ScreenPropertyTest, GetScreenComponentRotation, Function | SmallTest | Level2)
379 {
380     GTEST_LOG_(INFO) << "ScreenPropertyTest: GetScreenComponentRotation start";
381     ScreenProperty* property = new(std::nothrow) ScreenProperty();
382     ASSERT_NE(property, nullptr);
383     float rotation = property->GetScreenComponentRotation();
384     ASSERT_EQ(property->screenComponentRotation_, rotation);
385     delete property;
386     GTEST_LOG_(INFO) << "ScreenPropertyTest: GetScreenComponentRotation end";
387 }
388 
389 /**
390  * @tc.name: GetBounds
391  * @tc.desc: normal function
392  * @tc.type: FUNC
393  */
394 HWTEST_F(ScreenPropertyTest, GetBounds, Function | SmallTest | Level2)
395 {
396     GTEST_LOG_(INFO) << "ScreenPropertyTest: GetBounds start";
397     ScreenProperty* property = new(std::nothrow) ScreenProperty();
398     ASSERT_NE(property, nullptr);
399     RRect bounds = property->GetBounds();
400     ASSERT_EQ(property->bounds_, bounds);
401     delete property;
402     GTEST_LOG_(INFO) << "ScreenPropertyTest: GetBounds end";
403 }
404 
405 /**
406  * @tc.name: SetPhyBounds
407  * @tc.desc: normal function
408  * @tc.type: FUNC
409  */
410 HWTEST_F(ScreenPropertyTest, SetPhyBounds, Function | SmallTest | Level2)
411 {
412     GTEST_LOG_(INFO) << "ScreenPropertyTest: SetPhyBounds start";
413     ScreenProperty* property = new(std::nothrow) ScreenProperty();
414     ASSERT_NE(property, nullptr);
415     RRect phyBounds;
416     phyBounds.rect_.width_ = 1344;
417     phyBounds.rect_.height_ = 2772;
418     property->SetPhyBounds(phyBounds);
419     ASSERT_EQ(property->phyBounds_, phyBounds);
420     delete property;
421     GTEST_LOG_(INFO) << "ScreenPropertyTest: SetPhyBounds end";
422 }
423 
424 /**
425  * @tc.name: GetPhyBounds
426  * @tc.desc: normal function
427  * @tc.type: FUNC
428  */
429 HWTEST_F(ScreenPropertyTest, GetPhyBounds, Function | SmallTest | Level2)
430 {
431     GTEST_LOG_(INFO) << "ScreenPropertyTest: GetPhyBounds start";
432     ScreenProperty* property = new(std::nothrow) ScreenProperty();
433     ASSERT_NE(property, nullptr);
434     RRect phyBounds = property->GetPhyBounds();
435     ASSERT_EQ(property->phyBounds_, phyBounds);
436     delete property;
437     GTEST_LOG_(INFO) << "ScreenPropertyTest: GetPhyBounds end";
438 }
439 
440 /**
441  * @tc.name: GetDensity
442  * @tc.desc: normal function
443  * @tc.type: FUNC
444  */
445 HWTEST_F(ScreenPropertyTest, GetDensity, Function | SmallTest | Level2)
446 {
447     GTEST_LOG_(INFO) << "ScreenPropertyTest: GetDensity start";
448     ScreenProperty* property = new(std::nothrow) ScreenProperty();
449     ASSERT_NE(property, nullptr);
450     float virtualPixelRatio = 1.0f;
451     ASSERT_EQ(property->virtualPixelRatio_, virtualPixelRatio);
452     delete property;
453     GTEST_LOG_(INFO) << "ScreenPropertyTest: GetDensity end";
454 }
455 
456 /**
457  * @tc.name: GetDefaultDensity
458  * @tc.desc: normal function
459  * @tc.type: FUNC
460  */
461 HWTEST_F(ScreenPropertyTest, GetDefaultDensity, Function | SmallTest | Level2)
462 {
463     GTEST_LOG_(INFO) << "ScreenPropertyTest: GetDefaultDensity start";
464     ScreenProperty* property = new(std::nothrow) ScreenProperty();
465     ASSERT_NE(property, nullptr);
466     float defaultDensity = 1.0f;
467     ASSERT_EQ(property->GetDefaultDensity(), defaultDensity);
468     delete property;
469     GTEST_LOG_(INFO) << "ScreenPropertyTest: GetDefaultDensity end";
470 }
471 
472 /**
473  * @tc.name: SetDefaultDensity
474  * @tc.desc: normal function
475  * @tc.type: FUNC
476  */
477 HWTEST_F(ScreenPropertyTest, SetDefaultDensity, Function | SmallTest | Level2)
478 {
479     GTEST_LOG_(INFO) << "ScreenPropertyTest: SetDefaultDensity start";
480     ScreenProperty* property = new(std::nothrow) ScreenProperty();
481     ASSERT_NE(property, nullptr);
482     float defaultDensity = 1.0f;
483     property->SetDefaultDensity(defaultDensity);
484     ASSERT_EQ(property->defaultDensity_, defaultDensity);
485     delete property;
486     GTEST_LOG_(INFO) << "ScreenPropertyTest: SetDefaultDensity end";
487 }
488 
489 /**
490  * @tc.name: GetDensityInCurResolution
491  * @tc.desc: normal function
492  * @tc.type: FUNC
493  */
494 HWTEST_F(ScreenPropertyTest, GetDensityInCurResolution, Function | SmallTest | Level2)
495 {
496     GTEST_LOG_(INFO) << "ScreenPropertyTest: GetDensityInCurResolution start";
497     ScreenProperty* property = new(std::nothrow) ScreenProperty();
498     ASSERT_NE(property, nullptr);
499     float densityInCurResolution = 1.0f;
500     ASSERT_EQ(property->GetDensityInCurResolution(), densityInCurResolution);
501     delete property;
502     GTEST_LOG_(INFO) << "ScreenPropertyTest: GetDensityInCurResolution end";
503 }
504 
505 /**
506  * @tc.name: SetDensityInCurResolution
507  * @tc.desc: normal function
508  * @tc.type: FUNC
509  */
510 HWTEST_F(ScreenPropertyTest, SetDensityInCurResolution, Function | SmallTest | Level2)
511 {
512     GTEST_LOG_(INFO) << "ScreenPropertyTest: SetDensityInCurResolution start";
513     ScreenProperty* property = new(std::nothrow) ScreenProperty();
514     ASSERT_NE(property, nullptr);
515     float densityInCurResolution = 1.0f;
516     property->SetDensityInCurResolution(densityInCurResolution);
517     ASSERT_EQ(property->densityInCurResolution_, densityInCurResolution);
518     delete property;
519     GTEST_LOG_(INFO) << "ScreenPropertyTest: SetDensityInCurResolution end";
520 }
521 } // namespace
522 } // namespace Rosen
523 } // namespace OHOS
524