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