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 "session_manager/include/screen_rotation_property.h"
17 #include <gtest/gtest.h>
18
19 #include "window_manager_hilog.h"
20 #include "screen_session_manager.h"
21 #include <chrono>
22
23 using namespace testing;
24 using namespace testing::ext;
25
26 namespace OHOS {
27 namespace Rosen {
28 class ScreenRotationPropertyTest : public testing::Test {
29 public:
30 static void SetUpTestCase();
31 static void TearDownTestCase();
32 void SetUp() override;
33 void TearDown() override;
34 };
35
SetUpTestCase()36 void ScreenRotationPropertyTest::SetUpTestCase()
37 {
38 }
39
TearDownTestCase()40 void ScreenRotationPropertyTest::TearDownTestCase()
41 {
42 }
43
SetUp()44 void ScreenRotationPropertyTest::SetUp()
45 {
46 }
47
TearDown()48 void ScreenRotationPropertyTest::TearDown()
49 {
50 }
51
52 namespace {
53 /**
54 * @tc.name: Init
55 * @tc.desc: test function : Init
56 * @tc.type: FUNC
57 */
58 HWTEST_F(ScreenRotationPropertyTest, Init, Function | SmallTest | Level1)
59 {
60 int res = 0;
61 ScreenRotationProperty::Init();
62 ASSERT_EQ(0, res);
63 }
64
65 /**
66 * @tc.name: GetDefaultDisplayId
67 * @tc.desc: test function : GetDefaultDisplayId
68 * @tc.type: FUNC
69 */
70 HWTEST_F(ScreenRotationPropertyTest, GetDefaultDisplayId, Function | SmallTest | Level1)
71 {
72 ScreenRotationProperty::Init();
73 int res = 0;
74 ScreenRotationProperty::GetDefaultDisplayId();
75 ASSERT_EQ(0, res);
76 }
77
78 /**
79 * @tc.name: IsScreenRotationLocked
80 * @tc.desc: test function : IsScreenRotationLocked
81 * @tc.type: FUNC
82 */
83 HWTEST_F(ScreenRotationPropertyTest, IsScreenRotationLocked, Function | SmallTest | Level1)
84 {
85 ScreenRotationProperty::Init();
86 ScreenRotationProperty::SetScreenRotationLocked(true);
87 bool isLocked = ScreenRotationProperty::IsScreenRotationLocked();
88 ASSERT_EQ(true, isLocked);
89 }
90
91 /**
92 * @tc.name: SetScreenRotationLocked
93 * @tc.desc: test function : SetScreenRotationLocked
94 * @tc.type: FUNC
95 */
96 HWTEST_F(ScreenRotationPropertyTest, SetScreenRotationLocked, Function | SmallTest | Level1)
97 {
98 ScreenRotationProperty::Init();
99 bool isLocked = true;
100 DMError ret = ScreenRotationProperty::SetScreenRotationLocked(isLocked);
101 ASSERT_EQ(DMError::DM_OK, ret);
102 isLocked = false;
103 ScreenRotationProperty::GetCurrentDisplayRotation();
104 ScreenRotationProperty::ConvertDeviceToDisplayRotation(DeviceRotation::INVALID);
105 ret = ScreenRotationProperty::SetScreenRotationLocked(isLocked);
106 ASSERT_EQ(DMError::DM_OK, ret);
107 ScreenRotationProperty::ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE);
108 Orientation currentOrientation = ScreenRotationProperty::GetPreferredOrientation();
109 ScreenRotationProperty::IsSensorRelatedOrientation(currentOrientation);
110 ret = ScreenRotationProperty::SetScreenRotationLocked(isLocked);
111 ScreenRotationProperty::IsSensorRelatedOrientation(Orientation::UNSPECIFIED);
112 ret = ScreenRotationProperty::SetScreenRotationLocked(isLocked);
113 ASSERT_EQ(DMError::DM_OK, ret);
114 }
115
116 /**
117 * @tc.name: SetDefaultDeviceRotationOffset
118 * @tc.desc: test function : SetDefaultDeviceRotationOffset
119 * @tc.type: FUNC
120 */
121 HWTEST_F(ScreenRotationPropertyTest, SetDefaultDeviceRotationOffset, Function | SmallTest | Level1)
122 {
123 ScreenRotationProperty::Init();
124 uint32_t offset = -1;
125 ScreenRotationProperty::SetDefaultDeviceRotationOffset(offset);
126 offset = 0;
127 ScreenRotationProperty::SetDefaultDeviceRotationOffset(offset);
128 ASSERT_EQ(offset, ScreenRotationProperty::defaultDeviceRotationOffset_);
129 }
130
131 /**
132 * @tc.name: GetPreferredOrientation
133 * @tc.desc: test function : GetPreferredOrientation
134 * @tc.type: FUNC
135 */
136 HWTEST_F(ScreenRotationPropertyTest, GetPreferredOrientation, Function | SmallTest | Level1)
137 {
138 ScreenRotationProperty::Init();
139 Orientation res = ScreenRotationProperty::GetPreferredOrientation();
140 ASSERT_EQ(Orientation::SENSOR, res);
141 }
142
143 /**
144 * @tc.name: SetScreenRotation
145 * @tc.desc: test function : SetScreenRotation
146 * @tc.type: FUNC
147 */
148 HWTEST_F(ScreenRotationPropertyTest, SetScreenRotation, Function | SmallTest | Level1)
149 {
150 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: SetScreenRotation start";
151 ScreenRotationProperty::Init();
152 Rotation targetRotation = ScreenRotationProperty::GetCurrentDisplayRotation();
153 ScreenRotationProperty::SetScreenRotation(targetRotation);
154 targetRotation = Rotation::ROTATION_90;
155 ScreenRotationProperty::SetScreenRotation(targetRotation);
156 ASSERT_EQ(false, ScreenSessionManager::GetInstance().SetRotationFromWindow(targetRotation));
157 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: SetScreenRotation end";
158 }
159
160 /**
161 * @tc.name: IsSensorRelatedOrientation
162 * @tc.desc: test function : IsSensorRelatedOrientation
163 * @tc.type: FUNC
164 */
165 HWTEST_F(ScreenRotationPropertyTest, IsSensorRelatedOrientation, Function | SmallTest | Level1)
166 {
167 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsSensorRelatedOrientation start";
168 ScreenRotationProperty::Init();
169 bool res = ScreenRotationProperty::IsSensorRelatedOrientation(Orientation::VERTICAL);
170 ASSERT_EQ(false, res);
171 res = ScreenRotationProperty::IsSensorRelatedOrientation(Orientation::SENSOR_VERTICAL);
172 ASSERT_EQ(true, res);
173 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsSensorRelatedOrientation end";
174 }
175
176 /**
177 * @tc.name: ProcessSwitchToAutoRotation
178 * @tc.desc: test function : ProcessSwitchToAutoRotation
179 * @tc.type: FUNC
180 */
181 HWTEST_F(ScreenRotationPropertyTest, ProcessSwitchToAutoRotation, Function | SmallTest | Level1)
182 {
183 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessSwitchToAutoRotation start";
184 ScreenRotationProperty::Init();
185 int32_t res = 0;
186 ScreenRotationProperty::ProcessSwitchToAutoRotation(DeviceRotation::ROTATION_PORTRAIT);
187 ASSERT_EQ(0, res);
188 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessSwitchToAutoRotation end";
189 }
190
191 /**
192 * @tc.name: ProcessSwitchToAutoRotation
193 * @tc.desc: test function : ProcessSwitchToAutoRotation
194 * @tc.type: FUNC
195 */
196 HWTEST_F(ScreenRotationPropertyTest, ProcessSwitchToAutoRotationPortrait, Function | SmallTest | Level1)
197 {
198 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessSwitchToAutoRotationPortrait start";
199 ScreenRotationProperty::Init();
200 int32_t res = 0;
201 ScreenRotationProperty::ProcessSwitchToAutoRotationPortrait(DeviceRotation::ROTATION_PORTRAIT);
202 ASSERT_EQ(0, res);
203 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessSwitchToAutoRotationPortrait end";
204 }
205
206 /**
207 * @tc.name: ProcessSwitchToAutoRotation
208 * @tc.desc: test function : ProcessSwitchToAutoRotation
209 * @tc.type: FUNC
210 */
211 HWTEST_F(ScreenRotationPropertyTest, ProcessSwitchToAutoRotationLandscape, Function | SmallTest | Level1)
212 {
213 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessSwitchToAutoRotationLandscape start";
214 ScreenRotationProperty::Init();
215 int32_t res = 0;
216 ScreenRotationProperty::ProcessSwitchToAutoRotationLandscape(DeviceRotation::ROTATION_PORTRAIT);
217 ASSERT_EQ(0, res);
218 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessSwitchToAutoRotationLandscape end";
219 }
220
221 /**
222 * @tc.name: ProcessSwitchToAutoRotation
223 * @tc.desc: test function : ProcessSwitchToAutoRotation
224 * @tc.type: FUNC
225 */
226 HWTEST_F(ScreenRotationPropertyTest, ProcessSwitchToAutoRotationPortraitRestricted, Function | SmallTest | Level1)
227 {
228 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessSwitchToAutoRotationPortraitRestricted start";
229 ScreenRotationProperty::Init();
230 int32_t res = 0;
231 ScreenRotationProperty::ProcessSwitchToAutoRotationPortraitRestricted();
232 ASSERT_EQ(0, res);
233 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessSwitchToAutoRotationPortraitRestricted end";
234 }
235
236 /**
237 * @tc.name: ConvertSensorToDeviceRotation
238 * @tc.desc: test function : ConvertSensorToDeviceRotation
239 * @tc.type: FUNC
240 */
241 HWTEST_F(ScreenRotationPropertyTest, ConvertSensorToDeviceRotation, Function | SmallTest | Level1)
242 {
243 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ConvertSensorToDeviceRotation start";
244 ScreenRotationProperty::Init();
245 int32_t res = 0;
246 ScreenRotationProperty::ConvertSensorToDeviceRotation(SensorRotation::ROTATION_90);
247 ASSERT_EQ(0, res);
248 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ConvertSensorToDeviceRotation end";
249 }
250
251 /**
252 * @tc.name: ProcessSwitchToAutoRotationLandscapeRestricted
253 * @tc.desc: test function : ProcessSwitchToAutoRotationLandscapeRestricted
254 * @tc.type: FUNC
255 */
256 HWTEST_F(ScreenRotationPropertyTest, ProcessSwitchToAutoRotationLandscapeRestricted, Function | SmallTest | Level1)
257 {
258 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessSwitchToAutoRotationLandscapeRestricted start";
259 ScreenRotationProperty::Init();
260 int32_t res = 0;
261 ScreenRotationProperty::ProcessSwitchToAutoRotationLandscapeRestricted();
262 ASSERT_EQ(0, res);
263 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessSwitchToAutoRotationLandscapeRestricted end";
264 }
265
266 /**
267 * @tc.name: ConvertRotationToDisplayOrientation
268 * @tc.desc: test function : ConvertRotationToDisplayOrientation
269 * @tc.type: FUNC
270 */
271 HWTEST_F(ScreenRotationPropertyTest, ConvertRotationToDisplayOrientation, Function | SmallTest | Level1)
272 {
273 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ConvertRotationToDisplayOrientation start";
274 ScreenRotationProperty::Init();
275 int32_t res = 0;
276 ScreenRotationProperty::ConvertRotationToDisplayOrientation(Rotation::ROTATION_90);
277 ASSERT_EQ(0, res);
278 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ConvertSensorToDeviceRotation end";
279 }
280
281 /**
282 * @tc.name: ConvertDeviceToDisplayRotation
283 * @tc.desc: test function : ConvertDeviceToDisplayRotation
284 * @tc.type: FUNC
285 */
286 HWTEST_F(ScreenRotationPropertyTest, ConvertDeviceToDisplayRotation, Function | SmallTest | Level1)
287 {
288 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ConvertDeviceToDisplayRotation start";
289 ScreenRotationProperty::Init();
290 DeviceRotation deviceRotation = DeviceRotation::INVALID;
291 Rotation rotation = ScreenRotationProperty::ConvertDeviceToDisplayRotation(deviceRotation);
292 ASSERT_EQ(ScreenRotationProperty::GetCurrentDisplayRotation(), rotation);
293 deviceRotation = DeviceRotation::ROTATION_PORTRAIT;
294 rotation = ScreenRotationProperty::ConvertDeviceToDisplayRotation(deviceRotation);
295 ASSERT_EQ(ScreenRotationProperty::deviceToDisplayRotationMap_.at(deviceRotation), rotation);
296 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ConvertDeviceToDisplayRotation end";
297 }
298
299 /**
300 * @tc.name: ProcessRotationMapping
301 * @tc.desc: test function : ProcessRotationMapping
302 * @tc.type: FUNC
303 */
304 HWTEST_F(ScreenRotationPropertyTest, ProcessRotationMapping, Function | SmallTest | Level1)
305 {
306 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessRotationMapping_PORTRAIT start";
307 ScreenRotationProperty::defaultDeviceRotation_ = 0;
308 ScreenRotationProperty::ProcessRotationMapping();
309 ASSERT_EQ(Rotation::ROTATION_0,
310 ScreenRotationProperty::deviceToDisplayRotationMap_.at(DeviceRotation::ROTATION_PORTRAIT));
311 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessRotationMapping_PORTRAIT end";
312 }
313
314 /**
315 * @tc.name: ProcessSwitchToSensorRelatedOrientation
316 * @tc.desc: test function : ProcessSwitchToSensorRelatedOrientation
317 * @tc.type: FUNC
318 */
319 HWTEST_F(ScreenRotationPropertyTest, ProcessSwitchToSensorRelatedOrientation, Function | SmallTest | Level1)
320 {
321 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessSwitchToSensorRelatedOrientation start";
322 ScreenRotationProperty::Init();
323 Orientation orientation = Orientation::AUTO_ROTATION_RESTRICTED;
324 DeviceRotation sensorRotationConverted = DeviceRotation::INVALID;
325 ScreenRotationProperty::isScreenRotationLocked_ = true;
326 ScreenRotationProperty::ProcessSwitchToSensorRelatedOrientation(orientation, sensorRotationConverted);
327 ASSERT_EQ(ScreenRotationProperty::GetCurrentDisplayRotation(), ScreenRotationProperty::rotationLockedRotation_);
328 orientation = Orientation::SENSOR;
329 sensorRotationConverted = DeviceRotation::ROTATION_PORTRAIT;
330 ScreenRotationProperty::ProcessSwitchToSensorRelatedOrientation(orientation, sensorRotationConverted);
331 ASSERT_EQ(ScreenRotationProperty::deviceToDisplayRotationMap_.at(sensorRotationConverted),
332 ScreenRotationProperty::ConvertDeviceToDisplayRotation(sensorRotationConverted));
333 orientation = Orientation::AUTO_ROTATION_PORTRAIT_RESTRICTED;
334 ScreenRotationProperty::ProcessSwitchToSensorRelatedOrientation(orientation, sensorRotationConverted);
335 orientation = Orientation::SENSOR_VERTICAL;
336 ScreenRotationProperty::ProcessSwitchToSensorRelatedOrientation(orientation, sensorRotationConverted);
337 orientation = Orientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED;
338 ScreenRotationProperty::ProcessSwitchToSensorRelatedOrientation(orientation, sensorRotationConverted);
339 orientation = Orientation::SENSOR_HORIZONTAL;
340 ScreenRotationProperty::ProcessSwitchToSensorRelatedOrientation(orientation, sensorRotationConverted);
341 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessSwitchToSensorRelatedOrientation end";
342 }
343
344 /**
345 * @tc.name: HandleSensorEventInput
346 * @tc.desc: test function : HandleSensorEventInput
347 * @tc.type: FUNC
348 */
349 HWTEST_F(ScreenRotationPropertyTest, HandleSensorEventInput, Function | SmallTest | Level1)
350 {
351 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: HandleSensorEventInput start";
352 ScreenRotationProperty::Init();
353 DeviceRotation deviceRotation = DeviceRotation::INVALID;
354 ScreenRotationProperty::HandleSensorEventInput(deviceRotation);
355 deviceRotation = DeviceRotation::ROTATION_PORTRAIT;
356 ScreenSessionManager *screenSessionManager = new ScreenSessionManager;
357 auto defaultDisplayInfo = screenSessionManager->GetDefaultDisplayInfo();
358 ScreenRotationProperty::HandleSensorEventInput(deviceRotation);
359 Orientation orientation = Orientation::BEGIN;
360 ScreenRotationProperty::IsSensorRelatedOrientation(orientation);
361 ScreenRotationProperty::HandleSensorEventInput(deviceRotation);
362 orientation = Orientation::SENSOR;
363 ScreenRotationProperty::GetCurrentDisplayRotation();
364 ScreenRotationProperty::ConvertDeviceToDisplayRotation(deviceRotation);
365 ScreenRotationProperty::HandleSensorEventInput(deviceRotation);
366 int32_t res = 0;
367 ScreenRotationProperty::HandleSensorEventInput(DeviceRotation::INVALID);
368 ASSERT_EQ(0, res);
369 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: HandleSensorEventInput end";
370 }
371
372 /**
373 * @tc.name: ProcessSwitchToSensorUnrelatedOrientation
374 * @tc.desc: test function : ProcessSwitchToSensorUnrelatedOrientation
375 * @tc.type: FUNC
376 */
377 HWTEST_F(ScreenRotationPropertyTest, ProcessSwitchToSensorUnrelatedOrientation, Function | SmallTest | Level1)
378 {
379 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessSwitchToSensorUnrelatedOrientation start";
380 ScreenRotationProperty::Init();
381 int32_t res = 0;
382 ScreenRotationProperty::ProcessSwitchToSensorUnrelatedOrientation(ScreenRotationProperty::lastOrientationType_);
383 ASSERT_EQ(0, res);
384 ScreenRotationProperty::ProcessSwitchToSensorUnrelatedOrientation(Orientation::UNSPECIFIED);
385 ASSERT_EQ(0, res);
386 ScreenRotationProperty::ProcessSwitchToSensorUnrelatedOrientation(Orientation::VERTICAL);
387 ASSERT_EQ(0, res);
388 ScreenRotationProperty::ProcessSwitchToSensorUnrelatedOrientation(Orientation::REVERSE_VERTICAL);
389 ASSERT_EQ(0, res);
390 ScreenRotationProperty::ProcessSwitchToSensorUnrelatedOrientation(Orientation::HORIZONTAL);
391 ASSERT_EQ(0, res);
392 ScreenRotationProperty::ProcessSwitchToSensorUnrelatedOrientation(Orientation::REVERSE_HORIZONTAL);
393 ASSERT_EQ(0, res);
394 ScreenRotationProperty::ProcessSwitchToSensorUnrelatedOrientation(Orientation::BEGIN);
395 ASSERT_EQ(0, res);
396 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessSwitchToSensorUnrelatedOrientation end";
397 }
398
399 /**
400 * @tc.name: ProcessAutoRotationPortraitOrientation
401 * @tc.desc: ProcessAutoRotationPortraitOrientation func
402 * @tc.type: FUNC
403 */
404 HWTEST_F(ScreenRotationPropertyTest, ProcessAutoRotationPortraitOrientation, Function | SmallTest | Level1)
405 {
406 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessAutoRotationPortraitOrientation start";
407 ScreenRotationProperty::Init();
408 DeviceRotation sensorRotationConverted = DeviceRotation::ROTATION_LANDSCAPE;
409 auto result = ScreenRotationProperty::ProcessAutoRotationPortraitOrientation(sensorRotationConverted);
410 ASSERT_EQ(ScreenRotationProperty::GetCurrentDisplayRotation(), result);
411 sensorRotationConverted = DeviceRotation::ROTATION_PORTRAIT;
412 result = ScreenRotationProperty::ProcessAutoRotationPortraitOrientation(sensorRotationConverted);
413 ASSERT_EQ(ScreenRotationProperty::ConvertDeviceToDisplayRotation(sensorRotationConverted), result);
414 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessAutoRotationPortraitOrientation end";
415 }
416
417 /**
418 * @tc.name: ProcessAutoRotationLandscapeOrientation
419 * @tc.desc: ProcessAutoRotationLandscapeOrientation func
420 * @tc.type: FUNC
421 */
422 HWTEST_F(ScreenRotationPropertyTest, ProcessAutoRotationLandscapeOrientation, Function | SmallTest | Level1)
423 {
424 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessAutoRotationLandscapeOrientation start";
425 ScreenRotationProperty::Init();
426 DeviceRotation sensorRotationConverted = DeviceRotation::ROTATION_PORTRAIT;
427 auto result = ScreenRotationProperty::ProcessAutoRotationPortraitOrientation(sensorRotationConverted);
428 ASSERT_EQ(ScreenRotationProperty::currentDisplayRotation_, result);
429 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessAutoRotationLandscapeOrientation end";
430 }
431
432 /**
433 * @tc.name: CalcDeviceRotation
434 * @tc.desc: CalcDeviceRotation func
435 * @tc.type: FUNC
436 */
437 HWTEST_F(ScreenRotationPropertyTest, CalcDeviceRotation, Function | SmallTest | Level1)
438 {
439 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: CalcDeviceRotation start";
440 ScreenRotationProperty::Init();
441 SensorRotation sensorRotation = SensorRotation::INVALID;
442 auto result = ScreenRotationProperty::CalcDeviceRotation(sensorRotation);
443 ASSERT_EQ(DeviceRotation::INVALID, result);
444 sensorRotation = SensorRotation::ROTATION_0;
445 ScreenRotationProperty::defaultDeviceRotationOffset_ = 90;
446 ScreenRotationProperty::defaultDeviceRotation_ = 1;
447 result = ScreenRotationProperty::CalcDeviceRotation(sensorRotation);
448 ASSERT_EQ(DeviceRotation::ROTATION_PORTRAIT_INVERTED, result);
449 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: CalcDeviceRotation end";
450 }
451
452 /**
453 * @tc.name: CalcTargetDisplayRotation
454 * @tc.desc: CalcTargetDisplayRotation func
455 * @tc.type: FUNC
456 */
457 HWTEST_F(ScreenRotationPropertyTest, CalcTargetDisplayRotation, Function | SmallTest | Level1)
458 {
459 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: CalcTargetDisplayRotation start";
460 ScreenRotationProperty::Init();
461 Orientation requestedOrientation = Orientation::SENSOR;
462 DeviceRotation sensorRotationConverted = DeviceRotation::ROTATION_LANDSCAPE;
463 auto result = ScreenRotationProperty::CalcTargetDisplayRotation(requestedOrientation, sensorRotationConverted);
464 ASSERT_EQ(ScreenRotationProperty::ConvertDeviceToDisplayRotation(sensorRotationConverted), result);
465 requestedOrientation = Orientation::SENSOR_VERTICAL;
466 result = ScreenRotationProperty::CalcTargetDisplayRotation(requestedOrientation, sensorRotationConverted);
467 ASSERT_EQ(ScreenRotationProperty::ProcessAutoRotationPortraitOrientation(sensorRotationConverted), result);
468 requestedOrientation = Orientation::SENSOR_HORIZONTAL;
469 result = ScreenRotationProperty::CalcTargetDisplayRotation(requestedOrientation, sensorRotationConverted);
470 ASSERT_EQ(ScreenRotationProperty::ProcessAutoRotationLandscapeOrientation(sensorRotationConverted), result);
471 requestedOrientation = Orientation::AUTO_ROTATION_RESTRICTED;
472 ScreenRotationProperty::isScreenRotationLocked_ = true;
473 result = ScreenRotationProperty::CalcTargetDisplayRotation(requestedOrientation, sensorRotationConverted);
474 ASSERT_EQ(ScreenRotationProperty::GetCurrentDisplayRotation(), result);
475 ScreenRotationProperty::isScreenRotationLocked_ = false;
476 result = ScreenRotationProperty::CalcTargetDisplayRotation(requestedOrientation, sensorRotationConverted);
477 ASSERT_EQ(ScreenRotationProperty::ConvertDeviceToDisplayRotation(sensorRotationConverted), result);
478 requestedOrientation = Orientation::AUTO_ROTATION_PORTRAIT_RESTRICTED;
479 ScreenRotationProperty::isScreenRotationLocked_ = true;
480 result = ScreenRotationProperty::CalcTargetDisplayRotation(requestedOrientation, sensorRotationConverted);
481 ASSERT_EQ(ScreenRotationProperty::GetCurrentDisplayRotation(), result);
482 ScreenRotationProperty::isScreenRotationLocked_ = false;
483 result = ScreenRotationProperty::CalcTargetDisplayRotation(requestedOrientation, sensorRotationConverted);
484 ASSERT_EQ(ScreenRotationProperty::ProcessAutoRotationPortraitOrientation(sensorRotationConverted), result);
485 requestedOrientation = Orientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED;
486 ScreenRotationProperty::isScreenRotationLocked_ = true;
487 result = ScreenRotationProperty::CalcTargetDisplayRotation(requestedOrientation, sensorRotationConverted);
488 ASSERT_EQ(ScreenRotationProperty::GetCurrentDisplayRotation(), result);
489 ScreenRotationProperty::isScreenRotationLocked_ = false;
490 result = ScreenRotationProperty::CalcTargetDisplayRotation(requestedOrientation, sensorRotationConverted);
491 ASSERT_EQ(ScreenRotationProperty::ProcessAutoRotationLandscapeOrientation(sensorRotationConverted), result);
492 requestedOrientation = Orientation::LOCKED;
493 result = ScreenRotationProperty::CalcTargetDisplayRotation(requestedOrientation, sensorRotationConverted);
494 ASSERT_EQ(ScreenRotationProperty::GetCurrentDisplayRotation(), result);
495 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: CalcTargetDisplayRotation end";
496 }
497
498 /**
499 * @tc.name: IsCurrentDisplayVertical
500 * @tc.desc: IsCurrentDisplayVertical func
501 * @tc.type: FUNC
502 */
503 HWTEST_F(ScreenRotationPropertyTest, IsCurrentDisplayVertical, Function | SmallTest | Level1)
504 {
505 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsCurrentDisplayVertical start";
506 ScreenRotationProperty::Init();
507 auto result = ScreenRotationProperty::IsCurrentDisplayVertical();
508 ASSERT_EQ(true, result);
509 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsCurrentDisplayVertical end";
510 }
511
512 /**
513 * @tc.name: IsDeviceRotationVertical
514 * @tc.desc: IsDeviceRotationVertical func
515 * @tc.type: FUNC
516 */
517 HWTEST_F(ScreenRotationPropertyTest, IsDeviceRotationVertical, Function | SmallTest | Level1)
518 {
519 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsDeviceRotationVertical start";
520 ScreenRotationProperty::Init();
521 DeviceRotation deviceRotation = DeviceRotation::ROTATION_PORTRAIT;
522 auto result = ScreenRotationProperty::IsDeviceRotationVertical(deviceRotation);
523 ASSERT_EQ(true, result);
524 deviceRotation = DeviceRotation::ROTATION_PORTRAIT_INVERTED;
525 result = ScreenRotationProperty::IsDeviceRotationVertical(deviceRotation);
526 ASSERT_EQ(true, result);
527 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsDeviceRotationVertical end";
528 }
529
530 /**
531 * @tc.name: IsDeviceRotationHorizontal
532 * @tc.desc: IsDeviceRotationHorizontal func
533 * @tc.type: FUNC
534 */
535 HWTEST_F(ScreenRotationPropertyTest, IsDeviceRotationHorizontal, Function | SmallTest | Level1)
536 {
537 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsDeviceRotationHorizontal start";
538 ScreenRotationProperty::Init();
539 DeviceRotation deviceRotation = DeviceRotation::ROTATION_LANDSCAPE;
540 auto result = ScreenRotationProperty::IsDeviceRotationHorizontal(deviceRotation);
541 ASSERT_EQ(true, result);
542 deviceRotation = DeviceRotation::ROTATION_LANDSCAPE_INVERTED;
543 result = ScreenRotationProperty::IsDeviceRotationHorizontal(deviceRotation);
544 ASSERT_EQ(true, result);
545 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsDeviceRotationHorizontal end";
546 }
547
548 /**
549 * @tc.name: IsCurrentDisplayHorizontal
550 * @tc.desc: IsCurrentDisplayHorizontal func
551 * @tc.type: FUNC
552 */
553 HWTEST_F(ScreenRotationPropertyTest, IsCurrentDisplayHorizontal, Function | SmallTest | Level1)
554 {
555 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsCurrentDisplayHorizontal start";
556 ScreenRotationProperty::Init();
557 auto result = ScreenRotationProperty::IsCurrentDisplayHorizontal();
558 ASSERT_EQ(false, result);
559 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsCurrentDisplayHorizontal end";
560 }
561
562 /**
563 * @tc.name: IsDefaultDisplayRotationPortrait
564 * @tc.desc: IsDefaultDisplayRotationPortrait func
565 * @tc.type: FUNC
566 */
567 HWTEST_F(ScreenRotationPropertyTest, IsDefaultDisplayRotationPortrait, Function | SmallTest | Level1)
568 {
569 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsDefaultDisplayRotationPortrait start";
570 ScreenRotationProperty::Init();
571 auto result = ScreenRotationProperty::IsDefaultDisplayRotationPortrait();
572 ASSERT_EQ(true, result);
573 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsDefaultDisplayRotationPortrait end";
574 }
575
576 /**
577 * @tc.name: IsDisplayRotationVertical
578 * @tc.desc: IsDisplayRotationVertical func
579 * @tc.type: FUNC
580 */
581 HWTEST_F(ScreenRotationPropertyTest, IsDisplayRotationVertical, Function | SmallTest | Level1)
582 {
583 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsDisplayRotationVertical start";
584 ScreenRotationProperty::Init();
585 Rotation rotation = Rotation::ROTATION_0;
586 auto result = ScreenRotationProperty::IsDisplayRotationVertical(rotation);
587 ASSERT_EQ(true, result);
588 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsDisplayRotationVertical end";
589 }
590
591 /**
592 * @tc.name: IsDisplayRotationHorizontal
593 * @tc.desc: IsDisplayRotationHorizontal func
594 * @tc.type: FUNC
595 */
596 HWTEST_F(ScreenRotationPropertyTest, IsDisplayRotationHorizontal, Function | SmallTest | Level1)
597 {
598 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsDisplayRotationHorizontal start";
599 ScreenRotationProperty::Init();
600 Rotation rotation = Rotation::ROTATION_90;
601 auto result = ScreenRotationProperty::IsDisplayRotationHorizontal(rotation);
602 ASSERT_EQ(true, result);
603 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsDisplayRotationHorizontal end";
604 }
605
606 /**
607 * @tc.name: ProcessOrientationSwitch
608 * @tc.desc: ProcessOrientationSwitch func
609 * @tc.type: FUNC
610 */
611 HWTEST_F(ScreenRotationPropertyTest, ProcessOrientationSwitch, Function | SmallTest | Level1)
612 {
613 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessOrientationSwitch start";
614 ScreenRotationProperty::Init();
615 Orientation orientation = Orientation::BEGIN;
616 int res = 0;
617 ScreenRotationProperty::ProcessOrientationSwitch(orientation);
618 ASSERT_EQ(res, 0);
619 orientation = Orientation::SENSOR;
620 ScreenRotationProperty::ProcessOrientationSwitch(orientation);
621 ASSERT_EQ(res, 0);
622 GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessOrientationSwitch start";
623 }
624
625 }
626
627 }
628 }