• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 "screen_session_manager/include/fold_screen_controller/sensor_fold_state_manager/secondary_display_sensor_fold_state_manager.h"
18 #include "screen_session_manager/include/fold_screen_controller/secondary_display_fold_policy.h"
19 #include "fold_screen_state_internel.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace Rosen {
26 namespace {
27 constexpr uint32_t SLEEP_TIME_IN_US = 100000; // 100ms
28 }
29 class SecondaryDisplaySensorFoldStateManagerTest : public testing::Test {
30 public:
31     static void SetUpTestCase();
32     static void TearDownTestCase();
33     void SetUp() override;
34     void TearDown() override;
35 };
36 
SetUpTestCase()37 void SecondaryDisplaySensorFoldStateManagerTest::SetUpTestCase()
38 {
39 }
40 
TearDownTestCase()41 void SecondaryDisplaySensorFoldStateManagerTest::TearDownTestCase()
42 {
43     usleep(SLEEP_TIME_IN_US);
44 }
45 
SetUp()46 void SecondaryDisplaySensorFoldStateManagerTest::SetUp()
47 {
48 }
49 
TearDown()50 void SecondaryDisplaySensorFoldStateManagerTest::TearDown()
51 {
52 }
53 
54 namespace {
55 /**
56  * @tc.name: HandleAngleOrHallChange01
57  * @tc.desc: test function : HandleAngleOrHallChange
58  * @tc.type: FUNC
59  */
60 HWTEST_F(SecondaryDisplaySensorFoldStateManagerTest, HandleAngleOrHallChange01, Function | SmallTest | Level1)
61 {
62     if (!FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) {
63         return;
64     }
65     std::vector<float> angels = {0, 0, 0};
66     std::vector<uint16_t> halls = {0, 0};
67     sptr<FoldScreenPolicy> foldScreenPolicy = nullptr;
68     SecondaryDisplaySensorFoldStateManager manager;
69     manager.HandleAngleOrHallChange(angels, halls, foldScreenPolicy);
70     EXPECT_EQ(manager.GetNextFoldState(angels, halls), FoldStatus::FOLDED);
71 }
72 
73 /**
74  * @tc.name: HandleAngleOrHallChange02
75  * @tc.desc: test angles.size() != 3
76  * @tc.type: FUNC
77  */
78 HWTEST_F(SecondaryDisplaySensorFoldStateManagerTest, HandleAngleOrHallChange02, Function | SmallTest | Level1)
79 {
80     if (!FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) {
81         return;
82     }
83     std::vector<float> angels = {0, 0};
84     std::vector<uint16_t> halls = {0, 0};
85     sptr<FoldScreenPolicy> foldScreenPolicy = nullptr;
86     SecondaryDisplaySensorFoldStateManager manager;
87     manager.HandleAngleOrHallChange(angels, halls, foldScreenPolicy);
88     angels = {0, 0, 0};
89     EXPECT_EQ(manager.GetNextFoldState(angels, halls), FoldStatus::FOLDED);
90 }
91 
92 /**
93  * @tc.name: HandleAngleOrHallChange03
94  * @tc.desc: test isSecondaryReflexion
95  * @tc.type: FUNC
96  */
97 HWTEST_F(SecondaryDisplaySensorFoldStateManagerTest, HandleAngleOrHallChange03, Function | SmallTest | Level1)
98 {
99     if (!FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) {
100         return;
101     }
102     std::vector<float> angels = {180, 180, 1};
103     std::vector<uint16_t> halls = {1, 1};
104     std::recursive_mutex displayInfoMutex;
105     std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
106     sptr<FoldScreenPolicy> foldScreenPolicy = new SecondaryDisplayFoldPolicy(displayInfoMutex,
107         screenPowerTaskScheduler);
108     EXPECT_NE(foldScreenPolicy, nullptr);
109     SecondaryDisplaySensorFoldStateManager manager;
110     manager.HandleAngleOrHallChange(angels, halls, foldScreenPolicy);
111     EXPECT_EQ(manager.GetNextFoldState(angels, halls), FoldStatus::FOLD_STATE_EXPAND_WITH_SECOND_EXPAND);
112 }
113 
114 /**
115  * @tc.name: HandleAngleOrHallChange04
116  * @tc.desc: test isHasReflexioned && !isSecondaryReflexion
117  * @tc.type: FUNC
118  */
119 HWTEST_F(SecondaryDisplaySensorFoldStateManagerTest, HandleAngleOrHallChange04, Function | SmallTest | Level1)
120 {
121     if (!FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) {
122         return;
123     }
124     std::vector<float> angels = {180, 180, 0};
125     std::vector<uint16_t> halls = {1, 1};
126     std::recursive_mutex displayInfoMutex;
127     std::shared_ptr<TaskScheduler> screenPowerTaskScheduler = nullptr;
128     sptr<FoldScreenPolicy> foldScreenPolicy = new SecondaryDisplayFoldPolicy(displayInfoMutex,
129         screenPowerTaskScheduler);
130     EXPECT_NE(foldScreenPolicy, nullptr);
131     SecondaryDisplaySensorFoldStateManager manager;
132     manager.HandleAngleOrHallChange(angels, halls, foldScreenPolicy);
133     EXPECT_EQ(manager.GetNextFoldState(angels, halls), FoldStatus::FOLD_STATE_EXPAND_WITH_SECOND_EXPAND);
134 }
135 
136 /**
137  * @tc.name: UpdateSwitchScreenBoundaryForLargeFoldDeviceAB
138  * @tc.desc: test function : UpdateSwitchScreenBoundaryForLargeFoldDeviceAB
139  * @tc.type: FUNC
140  */
141 HWTEST_F(SecondaryDisplaySensorFoldStateManagerTest, UpdateSwitchScreenBoundaryForLargeFoldDeviceAB,
142         Function | SmallTest | Level1)
143 {
144     if (!FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) {
145         return;
146     }
147     float angel = 0;
148     uint16_t hall = 0;
149     SecondaryDisplaySensorFoldStateManager manager;
150     FoldStatus state = FoldStatus::UNKNOWN;
151     manager.UpdateSwitchScreenBoundaryForLargeFoldDeviceAB(angel, hall, state);
152     EXPECT_EQ(manager.allowUserSensorForLargeFoldDeviceAB, 0);
153 
154     angel = 91.0F;
155     hall = 1;
156     manager.UpdateSwitchScreenBoundaryForLargeFoldDeviceAB(angel, hall, state);
157     EXPECT_EQ(manager.allowUserSensorForLargeFoldDeviceAB, 1);
158 }
159 
160 /**
161  * @tc.name: UpdateSwitchScreenBoundaryForLargeFoldDeviceBC
162  * @tc.desc: test function : UpdateSwitchScreenBoundaryForLargeFoldDeviceBC
163  * @tc.type: FUNC
164  */
165 HWTEST_F(SecondaryDisplaySensorFoldStateManagerTest, UpdateSwitchScreenBoundaryForLargeFoldDeviceBC,
166         Function | SmallTest | Level1)
167 {
168     if (!FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) {
169         return;
170     }
171     float angel = 0;
172     uint16_t hall = 0;
173     SecondaryDisplaySensorFoldStateManager manager;
174     FoldStatus state = FoldStatus::UNKNOWN;
175     manager.UpdateSwitchScreenBoundaryForLargeFoldDeviceBC(angel, hall, state);
176     EXPECT_EQ(manager.allowUserSensorForLargeFoldDeviceBC, 0);
177 
178     angel = 91.0F;
179     hall = 1;
180     manager.UpdateSwitchScreenBoundaryForLargeFoldDeviceBC(angel, hall, state);
181     EXPECT_EQ(manager.allowUserSensorForLargeFoldDeviceBC, 1);
182 }
183 
184 /**
185  * @tc.name: GetNextFoldStateHalf01
186  * @tc.desc: test function : GetNextFoldStateHalf
187  * @tc.type: FUNC
188  */
189 HWTEST_F(SecondaryDisplaySensorFoldStateManagerTest, GetNextFoldStateHalf01, Function | SmallTest | Level1)
190 {
191     if (!FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) {
192         return;
193     }
194     float angel = -0.1;
195     uint16_t hall = 0;
196     int32_t allowUserSensorForLargeFoldDevice = 0;
197     SecondaryDisplaySensorFoldStateManager manager;
198     FoldStatus state = FoldStatus::UNKNOWN;
199     auto result1 = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice);
200     EXPECT_EQ(static_cast<int>(result1), 0);
201 
202     angel = 90.0F;
203     hall = 1;
204     auto result2 = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice);
205     EXPECT_EQ(static_cast<int>(result2), 3);
206 
207     angel = 130.0F - 0.1;
208     hall = 1;
209     auto result3 = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice);
210     EXPECT_EQ(static_cast<int>(result3), 3);
211 
212     angel = 130.0F - 0.1;
213     hall = 0;
214     auto result4 = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice);
215     EXPECT_EQ(static_cast<int>(result4), 3);
216 
217     angel = 130.0F + 0.1;
218     hall = 0;
219     auto result5 = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice);
220     EXPECT_EQ(static_cast<int>(result5), 3);
221 
222     angel = 140.0F + 0.1;
223     hall = 0;
224     auto result6 = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice);
225     EXPECT_EQ(static_cast<int>(result6), 3);
226 
227     angel = 140.0F + 0.1;
228     hall = 1;
229     auto result7 = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice);
230     EXPECT_EQ(static_cast<int>(result7), 1);
231 }
232 
233 /**
234  * @tc.name: GetNextFoldStateHalf02
235  * @tc.desc: test function : GetNextFoldStateHalf
236  * @tc.type: FUNC
237  */
238 HWTEST_F(SecondaryDisplaySensorFoldStateManagerTest, GetNextFoldStateHalf02, Function | SmallTest | Level1)
239 {
240     if (!FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) {
241         return;
242     }
243     SecondaryDisplaySensorFoldStateManager manager;
244     int32_t allowUserSensorForLargeFoldDevice = 1;
245     FoldStatus state = FoldStatus::UNKNOWN;
246     float angel = 45.0F;
247     uint16_t hall = 1;
248     auto result1 = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice);
249     EXPECT_EQ(static_cast<int>(result1), 0);
250 
251     angel = 70.0F - 0.1;
252     auto result2 = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice);
253     EXPECT_EQ(static_cast<int>(result2), 2);
254 
255     angel = 70.0F + 0.1;
256     auto result3 = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice);
257     EXPECT_EQ(static_cast<int>(result3), 3);
258 
259     angel = 130.0F - 0.1;
260     auto result4 = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice);
261     EXPECT_EQ(static_cast<int>(result4), 3);
262 
263     angel = 130.0F + 0.1;
264     auto result5 = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice);
265     EXPECT_EQ(static_cast<int>(result5), 3);
266 
267     angel = 80.0F - 0.1;
268     auto result6 = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice);
269     EXPECT_EQ(static_cast<int>(result6), 3);
270 
271     angel = 70.0F + 0.1;
272     hall = 0;
273     auto result7 = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice);
274     EXPECT_EQ(static_cast<int>(result7), 3);
275 
276     angel = 130.0F + 0.1;
277     auto result8 = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice);
278     EXPECT_EQ(static_cast<int>(result8), 3);
279 }
280 
281 /**
282  * @tc.name: GetGlobalFoldState
283  * @tc.desc: test function : GetGlobalFoldState
284  * @tc.type: FUNC
285  */
286 HWTEST_F(SecondaryDisplaySensorFoldStateManagerTest, GetGlobalFoldState, Function | SmallTest | Level1)
287 {
288     if (!FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) {
289         return;
290     }
291     SecondaryDisplaySensorFoldStateManager manager;
292     FoldStatus nextStatePrimary = FoldStatus::EXPAND;
293     FoldStatus nextStateSecondary = FoldStatus::EXPAND;
294     EXPECT_EQ(manager.GetGlobalFoldState(nextStatePrimary, nextStateSecondary),
295     FoldStatus::FOLD_STATE_EXPAND_WITH_SECOND_EXPAND);
296 
297     nextStatePrimary = FoldStatus::FOLDED;
298     nextStateSecondary = FoldStatus::EXPAND;
299     EXPECT_EQ(manager.GetGlobalFoldState(nextStatePrimary, nextStateSecondary),
300     FoldStatus::FOLD_STATE_FOLDED_WITH_SECOND_EXPAND);
301 
302     nextStatePrimary = FoldStatus::HALF_FOLD;
303     nextStateSecondary = FoldStatus::EXPAND;
304     EXPECT_EQ(manager.GetGlobalFoldState(nextStatePrimary, nextStateSecondary),
305     FoldStatus::FOLD_STATE_HALF_FOLDED_WITH_SECOND_EXPAND);
306 
307     nextStatePrimary = FoldStatus::EXPAND;
308     nextStateSecondary = FoldStatus::FOLDED;
309     EXPECT_EQ(manager.GetGlobalFoldState(nextStatePrimary, nextStateSecondary),
310     FoldStatus::EXPAND);
311 
312     nextStatePrimary = FoldStatus::FOLDED;
313     nextStateSecondary = FoldStatus::FOLDED;
314     EXPECT_EQ(manager.GetGlobalFoldState(nextStatePrimary, nextStateSecondary),
315     FoldStatus::FOLDED);
316 
317     nextStatePrimary = FoldStatus::HALF_FOLD;
318     nextStateSecondary = FoldStatus::FOLDED;
319     EXPECT_EQ(manager.GetGlobalFoldState(nextStatePrimary, nextStateSecondary),
320     FoldStatus::HALF_FOLD);
321 
322     nextStatePrimary = FoldStatus::EXPAND;
323     nextStateSecondary = FoldStatus::HALF_FOLD;
324     EXPECT_EQ(manager.GetGlobalFoldState(nextStatePrimary, nextStateSecondary),
325     FoldStatus::FOLD_STATE_EXPAND_WITH_SECOND_HALF_FOLDED);
326 
327     nextStatePrimary = FoldStatus::FOLDED;
328     nextStateSecondary = FoldStatus::HALF_FOLD;
329     EXPECT_EQ(manager.GetGlobalFoldState(nextStatePrimary, nextStateSecondary),
330     FoldStatus::FOLD_STATE_FOLDED_WITH_SECOND_HALF_FOLDED);
331 
332     nextStatePrimary = FoldStatus::HALF_FOLD;
333     nextStateSecondary = FoldStatus::HALF_FOLD;
334     EXPECT_EQ(manager.GetGlobalFoldState(nextStatePrimary, nextStateSecondary),
335     FoldStatus::FOLD_STATE_HALF_FOLDED_WITH_SECOND_HALF_FOLDED);
336 }
337 }
338 }
339 }