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 <gtest/gtest.h>
17 #include "utils/window_manager_service_utils.h"
18 
19 using namespace testing;
20 using namespace testing::ext;
21 
22 namespace OHOS {
23 namespace Rosen {
24 class WmsUtilsTest : public testing::Test {
25 public:
26     static void SetUpTestCase();
27     static void TearDownTestCase();
28     void SetUp() override;
29     void TearDown() override;
30 };
31 
SetUpTestCase()32 void WmsUtilsTest::SetUpTestCase()
33 {
34 }
35 
TearDownTestCase()36 void WmsUtilsTest::TearDownTestCase()
37 {
38 }
39 
SetUp()40 void WmsUtilsTest::SetUp()
41 {
42 }
43 
TearDown()44 void WmsUtilsTest::TearDown()
45 {
46 }
47 namespace {
48 /**
49  * @tc.name: IsFixedOrientation01
50  * @tc.desc: normal test
51  * @tc.type: FUNC
52  */
53 HWTEST_F(WmsUtilsTest, IsFixedOrientation01, Function | SmallTest | Level2)
54 {
55     bool ret = WmsUtils::IsFixedOrientation(Orientation::HORIZONTAL, WindowMode::WINDOW_MODE_FULLSCREEN, 0);
56     ASSERT_TRUE(ret);
57 }
58 
59 /**
60  * @tc.name: IsFixedOrientation02
61  * @tc.desc: more then Orientation::REVERSE_HORIZONTAL
62  * @tc.type: FUNC
63  */
64 HWTEST_F(WmsUtilsTest, IsFixedOrientation02, Function | SmallTest | Level2)
65 {
66     bool ret = WmsUtils::IsFixedOrientation(Orientation::SENSOR, WindowMode::WINDOW_MODE_FULLSCREEN, 0);
67     ASSERT_FALSE(ret);
68 }
69 
70 /**
71  * @tc.name: IsFixedOrientation03
72  * @tc.desc: less then Orientation::VERTICAL
73  * @tc.type: FUNC
74  */
75 HWTEST_F(WmsUtilsTest, IsFixedOrientation03, Function | SmallTest | Level2)
76 {
77     bool ret = WmsUtils::IsFixedOrientation(Orientation::UNSPECIFIED, WindowMode::WINDOW_MODE_FULLSCREEN, 0);
78     ASSERT_FALSE(ret);
79 }
80 
81 /**
82  * @tc.name: IsFixedOrientation04
83  * @tc.desc: flags is WindowFlag::WINDOW_FLAG_NEED_AVOID
84  * @tc.type: FUNC
85  */
86 HWTEST_F(WmsUtilsTest, IsFixedOrientation04, Function | SmallTest | Level2)
87 {
88     bool ret = WmsUtils::IsFixedOrientation(Orientation::HORIZONTAL, WindowMode::WINDOW_MODE_FULLSCREEN,
89         static_cast<int32_t>(WindowFlag::WINDOW_FLAG_NEED_AVOID));
90     ASSERT_FALSE(ret);
91 }
92 
93 /**
94  * @tc.name: IsFixedOrientation05
95  * @tc.desc: mode is not WindowMode::WINDOW_MODE_FULLSCREEN
96  * @tc.type: FUNC
97  */
98 HWTEST_F(WmsUtilsTest, IsFixedOrientation05, Function | SmallTest | Level2)
99 {
100     bool ret = WmsUtils::IsFixedOrientation(Orientation::HORIZONTAL, WindowMode::WINDOW_MODE_FLOATING, 0);
101     ASSERT_FALSE(ret);
102 }
103 
104 /**
105  * @tc.name: IsExpectedRotateLandscapeWindow01
106  * @tc.desc: requestOrientation is not HORIZONTAL
107  * @tc.type: FUNC
108  */
109 HWTEST_F(WmsUtilsTest, IsExpectedRotateLandscapeWindow01, Function | SmallTest | Level2)
110 {
111     bool ret = WmsUtils::IsExpectedRotateLandscapeWindow(Orientation::VERTICAL, DisplayOrientation::PORTRAIT, 0);
112     ASSERT_FALSE(ret);
113 }
114 
115 /**
116  * @tc.name: IsExpectedRotatableWindow01
117  * @tc.desc: flags is WindowFlag::WINDOW_FLAG_NEED_AVOID
118  * @tc.type: FUNC
119  */
120 HWTEST_F(WmsUtilsTest, IsExpectedRotatableWindow01, Function | SmallTest | Level2)
121 {
122     bool ret = WmsUtils::IsExpectedRotatableWindow(Orientation::VERTICAL, DisplayOrientation::PORTRAIT,
123         static_cast<int32_t>(WindowFlag::WINDOW_FLAG_NEED_AVOID));
124     ASSERT_FALSE(ret);
125 }
126 
127 /**
128  * @tc.name: IsExpectedRotatableWindow02
129  * @tc.desc: disOrientation == currentOrientation
130  * @tc.type: FUNC
131  */
132 HWTEST_F(WmsUtilsTest, IsExpectedRotatableWindow02, Function | SmallTest | Level2)
133 {
134     bool ret = WmsUtils::IsExpectedRotatableWindow(Orientation::VERTICAL, DisplayOrientation::PORTRAIT, 0);
135     ASSERT_FALSE(ret);
136 }
137 
138 /**
139  * @tc.name: IsExpectedRotatableWindow03
140  * @tc.desc: disOrientation == currentOrientation
141  * @tc.type: FUNC
142  */
143 HWTEST_F(WmsUtilsTest, IsExpectedRotatableWindow03, Function | SmallTest | Level2)
144 {
145     bool ret = WmsUtils::IsExpectedRotatableWindow(Orientation::VERTICAL, DisplayOrientation::PORTRAIT, 0);
146     ASSERT_FALSE(ret);
147 }
148 
149 /**
150  * @tc.name: IsExpectedRotatableWindow04
151  * @tc.desc: disOrientation - currentOrientation == 2
152  * @tc.type: FUNC
153  */
154 HWTEST_F(WmsUtilsTest, IsExpectedRotatableWindow04, Function | SmallTest | Level2)
155 {
156     bool ret = WmsUtils::IsExpectedRotatableWindow(Orientation::REVERSE_VERTICAL, DisplayOrientation::PORTRAIT, 0);
157     ASSERT_FALSE(ret);
158 }
159 
160 /**
161  * @tc.name: IsExpectedRotatableWindow05
162  * @tc.desc: disOrientation - currentOrientation == 2
163  * @tc.type: FUNC
164  */
165 HWTEST_F(WmsUtilsTest, IsExpectedRotatableWindow05, Function | SmallTest | Level2)
166 {
167     bool ret = WmsUtils::IsExpectedRotatableWindow(Orientation::REVERSE_VERTICAL,
168         DisplayOrientation::PORTRAIT, 0, false);
169     ASSERT_TRUE(ret);
170 }
171 
172 /**
173  * @tc.name: IsExpectedRotatableWindow06
174  * @tc.desc: mode is not WindowMode::WINDOW_MODE_FULLSCREEN
175  * @tc.type: FUNC
176  */
177 HWTEST_F(WmsUtilsTest, IsExpectedRotatableWindow06, Function | SmallTest | Level2)
178 {
179     bool ret = WmsUtils::IsExpectedRotatableWindow(Orientation::REVERSE_VERTICAL,
180         DisplayOrientation::PORTRAIT,  WindowMode::WINDOW_MODE_FLOATING, 0);
181     ASSERT_FALSE(ret);
182 }
183 }
184 }
185 }