• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <chrono>
17 
18 #include <gtest/gtest.h>
19 
20 #include "window_manager_hilog.h"
21 #include "screen_session_manager.h"
22 
23 #include "screen_session_manager/include/screen_rotation_property.h"
24 
25 using namespace testing;
26 using namespace testing::ext;
27 
28 namespace OHOS {
29 namespace Rosen {
30 namespace {
31 constexpr uint32_t SLEEP_TIME_US = 100000;
32 }
33 
34 class ScreenRotationPropertyTest : public testing::Test {
35 public:
36     static void SetUpTestCase();
37     static void TearDownTestCase();
38     void SetUp() override;
39     void TearDown() override;
40 };
41 
SetUpTestCase()42 void ScreenRotationPropertyTest::SetUpTestCase()
43 {
44 }
45 
TearDownTestCase()46 void ScreenRotationPropertyTest::TearDownTestCase()
47 {
48 }
49 
SetUp()50 void ScreenRotationPropertyTest::SetUp()
51 {
52 }
53 
TearDown()54 void ScreenRotationPropertyTest::TearDown()
55 {
56     usleep(SLEEP_TIME_US);
57 }
58 
59 namespace {
60 
61 /**
62  * @tc.name: HandleSensorEventInput
63  * @tc.desc: test function : HandleSensorEventInput
64  * @tc.type: FUNC
65  */
66 HWTEST_F(ScreenRotationPropertyTest, HandleSensorEventInput, TestSize.Level1)
67 {
68     ScreenRotationProperty::HandleSensorEventInput(DeviceRotation::INVALID);
69     ScreenRotationProperty::HandleSensorEventInput(DeviceRotation::ROTATION_PORTRAIT);
70     ScreenRotationProperty::HandleSensorEventInput(DeviceRotation::ROTATION_LANDSCAPE);
71     auto screenSession = ScreenSessionManager::GetInstance().GetDefaultScreenSession();
72     ASSERT_EQ(screenSession, nullptr);
73 }
74 
75 /**
76  * @tc.name: HandleHoverStatusEventInput
77  * @tc.desc: test function : HandleHoverStatusEventInput
78  * @tc.type: FUNC
79  */
80 HWTEST_F(ScreenRotationPropertyTest, HandleHoverStatusEventInput, TestSize.Level1)
81 {
82     ScreenRotationProperty::HandleHoverStatusEventInput(DeviceHoverStatus::INVALID);
83     ScreenRotationProperty::HandleHoverStatusEventInput(DeviceHoverStatus::TENT_STATUS);
84     ScreenRotationProperty::HandleHoverStatusEventInput(DeviceHoverStatus::TENT_STATUS_CANCEL);
85     ScreenRotationProperty::HandleHoverStatusEventInput(DeviceHoverStatus::CAMERA_STATUS);
86     ScreenRotationProperty::HandleHoverStatusEventInput(DeviceHoverStatus::CAMERA_STATUS_CANCEL);
87     auto screenSession = ScreenSessionManager::GetInstance().GetDefaultScreenSession();
88     ASSERT_EQ(screenSession, nullptr);
89 }
90 
91 /**
92  * @tc.name: ConvertDeviceToFloat
93  * @tc.desc: test function : ConvertDeviceToFloat
94  * @tc.type: FUNC
95  */
96 HWTEST_F(ScreenRotationPropertyTest, ConvertDeviceToFloat, TestSize.Level1)
97 {
98     float ret;
99     ret = ScreenRotationProperty::ConvertDeviceToFloat(DeviceRotation::INVALID);
100     ASSERT_EQ(ret, -1.0f);
101 
102     ret = ScreenRotationProperty::ConvertDeviceToFloat(DeviceRotation::ROTATION_PORTRAIT);
103     ASSERT_EQ(ret, 0.0f);
104 
105     ret = ScreenRotationProperty::ConvertDeviceToFloat(DeviceRotation::ROTATION_LANDSCAPE);
106     ASSERT_EQ(ret, 90.0f);
107 
108     ret = ScreenRotationProperty::ConvertDeviceToFloat(DeviceRotation::ROTATION_PORTRAIT_INVERTED);
109     ASSERT_EQ(ret, 180.0f);
110 
111     ret = ScreenRotationProperty::ConvertDeviceToFloat(DeviceRotation::ROTATION_LANDSCAPE_INVERTED);
112     ASSERT_EQ(ret, 270.0f);
113 }
114 
115 }
116 
117 }
118 }