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 "session_manager/include/fold_screen_controller/sensor_fold_state_manager/secondary_display_sensor_fold_state_manager.h"
18
19 using namespace testing;
20 using namespace testing::ext;
21
22 namespace OHOS {
23 namespace Rosen {
24 namespace {
25 constexpr uint32_t SLEEP_TIME_IN_US = 100000; // 100ms
26 }
27 class SecondaryDisplaySensorFoldStateManagerTest : public testing::Test {
28 public:
29 static void SetUpTestCase();
30 static void TearDownTestCase();
31 void SetUp() override;
32 void TearDown() override;
33 };
34
SetUpTestCase()35 void SecondaryDisplaySensorFoldStateManagerTest::SetUpTestCase()
36 {
37 }
38
TearDownTestCase()39 void SecondaryDisplaySensorFoldStateManagerTest::TearDownTestCase()
40 {
41 usleep(SLEEP_TIME_IN_US);
42 }
43
SetUp()44 void SecondaryDisplaySensorFoldStateManagerTest::SetUp()
45 {
46 }
47
TearDown()48 void SecondaryDisplaySensorFoldStateManagerTest::TearDown()
49 {
50 }
51
52 namespace {
53 /**
54 * @tc.name: HandleAngleOrHallChange
55 * @tc.desc: test function : HandleAngleOrHallChange
56 * @tc.type: FUNC
57 */
58 HWTEST_F(SecondaryDisplaySensorFoldStateManagerTest, HandleAngleOrHallChange, Function | SmallTest | Level1)
59 {
60 std::vector<float> angels = {0, 0};
61 std::vector<uint16_t> halls = {0, 0};
62 sptr<FoldScreenPolicy> foldScreenPolicy = nullptr;
63 SecondaryDisplaySensorFoldStateManager manager;
64 manager.HandleAngleOrHallChange(angels, halls, foldScreenPolicy);
65 EXPECT_TRUE(true);
66 }
67
68 /**
69 * @tc.name: UpdateSwitchScreenBoundaryForLargeFoldDeviceAB
70 * @tc.desc: test function : UpdateSwitchScreenBoundaryForLargeFoldDeviceAB
71 * @tc.type: FUNC
72 */
73 HWTEST_F(SecondaryDisplaySensorFoldStateManagerTest, UpdateSwitchScreenBoundaryForLargeFoldDeviceAB,
74 Function | SmallTest | Level1)
75 {
76 float angel = 0;
77 uint16_t hall = 0;
78 SecondaryDisplaySensorFoldStateManager manager;
79 FoldStatus state = FoldStatus::UNKNOWN;
80 manager.UpdateSwitchScreenBoundaryForLargeFoldDeviceAB(angel, hall, state);
81 EXPECT_EQ(manager.allowUserSensorForLargeFoldDeviceAB, 0);
82
83 angel = 91.0F;
84 hall = 1;
85 manager.UpdateSwitchScreenBoundaryForLargeFoldDeviceAB(angel, hall, state);
86 EXPECT_EQ(manager.allowUserSensorForLargeFoldDeviceAB, 1);
87 }
88
89 /**
90 * @tc.name: UpdateSwitchScreenBoundaryForLargeFoldDeviceBC
91 * @tc.desc: test function : UpdateSwitchScreenBoundaryForLargeFoldDeviceBC
92 * @tc.type: FUNC
93 */
94 HWTEST_F(SecondaryDisplaySensorFoldStateManagerTest, UpdateSwitchScreenBoundaryForLargeFoldDeviceBC,
95 Function | SmallTest | Level1)
96 {
97 float angel = 0;
98 uint16_t hall = 0;
99 SecondaryDisplaySensorFoldStateManager manager;
100 FoldStatus state = FoldStatus::UNKNOWN;
101 manager.UpdateSwitchScreenBoundaryForLargeFoldDeviceBC(angel, hall, state);
102 EXPECT_EQ(manager.allowUserSensorForLargeFoldDeviceBC, 0);
103
104 angel = 91.0F;
105 hall = 1;
106 manager.UpdateSwitchScreenBoundaryForLargeFoldDeviceBC(angel, hall, state);
107 EXPECT_EQ(manager.allowUserSensorForLargeFoldDeviceBC, 1);
108 }
109
110 /**
111 * @tc.name: GetNextFoldStateHalf01
112 * @tc.desc: test function : GetNextFoldStateHalf
113 * @tc.type: FUNC
114 */
115 HWTEST_F(SecondaryDisplaySensorFoldStateManagerTest, GetNextFoldStateHalf01, Function | SmallTest | Level1)
116 {
117 float angel = -0.1;
118 uint16_t hall = 0;
119 int32_t allowUserSensorForLargeFoldDevice = 0;
120 SecondaryDisplaySensorFoldStateManager manager;
121 FoldStatus state = FoldStatus::UNKNOWN;
122 auto result1 = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice);
123 EXPECT_EQ(static_cast<int>(result1), 0);
124
125 angel = 90.0F;
126 hall = 1;
127 auto result2 = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice);
128 EXPECT_EQ(static_cast<int>(result2), 3);
129
130 angel = 130.0F - 0.1;
131 hall = 1;
132 auto result3 = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice);
133 EXPECT_EQ(static_cast<int>(result3), 3);
134
135 angel = 130.0F - 0.1;
136 hall = 0;
137 auto result4 = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice);
138 EXPECT_EQ(static_cast<int>(result4), 3);
139
140 angel = 130.0F + 0.1;
141 hall = 0;
142 auto result5 = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice);
143 EXPECT_EQ(static_cast<int>(result5), 3);
144
145 angel = 140.0F + 0.1;
146 hall = 0;
147 auto result6 = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice);
148 EXPECT_EQ(static_cast<int>(result6), 3);
149
150 angel = 140.0F + 0.1;
151 hall = 1;
152 auto result7 = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice);
153 EXPECT_EQ(static_cast<int>(result7), 1);
154 }
155
156 /**
157 * @tc.name: GetNextFoldStateHalf02
158 * @tc.desc: test function : GetNextFoldStateHalf
159 * @tc.type: FUNC
160 */
161 HWTEST_F(SecondaryDisplaySensorFoldStateManagerTest, GetNextFoldStateHalf02, Function | SmallTest | Level1)
162 {
163 SecondaryDisplaySensorFoldStateManager manager;
164 int32_t allowUserSensorForLargeFoldDevice = 1;
165 FoldStatus state = FoldStatus::UNKNOWN;
166 float angel = 25.0F;
167 uint16_t hall = 1;
168 auto result1 = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice);
169 EXPECT_EQ(static_cast<int>(result1), 0);
170
171 angel = 70.0F - 0.1;
172 auto result2 = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice);
173 EXPECT_EQ(static_cast<int>(result2), 2);
174
175 angel = 70.0F + 0.1;
176 auto result3 = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice);
177 EXPECT_EQ(static_cast<int>(result3), 3);
178
179 angel = 130.0F - 0.1;
180 auto result4 = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice);
181 EXPECT_EQ(static_cast<int>(result4), 3);
182
183 angel = 130.0F + 0.1;
184 auto result5 = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice);
185 EXPECT_EQ(static_cast<int>(result5), 3);
186
187 angel = 80.0F - 0.1;
188 auto result6 = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice);
189 EXPECT_EQ(static_cast<int>(result6), 3);
190
191 angel = 70.0F + 0.1;
192 hall = 0;
193 auto result7 = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice);
194 EXPECT_EQ(static_cast<int>(result7), 3);
195
196 angel = 130.0F + 0.1;
197 auto result8 = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice);
198 EXPECT_EQ(static_cast<int>(result8), 3);
199 }
200
201 /**
202 * @tc.name: GetGlobalFoldState
203 * @tc.desc: test function : GetGlobalFoldState
204 * @tc.type: FUNC
205 */
206 HWTEST_F(SecondaryDisplaySensorFoldStateManagerTest, GetGlobalFoldState, Function | SmallTest | Level1)
207 {
208 SecondaryDisplaySensorFoldStateManager manager;
209 FoldStatus nextStatePrimary = FoldStatus::EXPAND;
210 FoldStatus nextStateSecondary = FoldStatus::EXPAND;
211 EXPECT_EQ(manager.GetGlobalFoldState(nextStatePrimary, nextStateSecondary),
212 FoldStatus::FOLD_STATE_EXPAND_WITH_SECOND_EXPAND);
213
214 nextStatePrimary = FoldStatus::FOLDED;
215 nextStateSecondary = FoldStatus::EXPAND;
216 EXPECT_EQ(manager.GetGlobalFoldState(nextStatePrimary, nextStateSecondary),
217 FoldStatus::FOLD_STATE_FOLDED_WITH_SECOND_EXPAND);
218
219 nextStatePrimary = FoldStatus::HALF_FOLD;
220 nextStateSecondary = FoldStatus::EXPAND;
221 EXPECT_EQ(manager.GetGlobalFoldState(nextStatePrimary, nextStateSecondary),
222 FoldStatus::FOLD_STATE_HALF_FOLDED_WITH_SECOND_EXPAND);
223
224 nextStatePrimary = FoldStatus::EXPAND;
225 nextStateSecondary = FoldStatus::FOLDED;
226 EXPECT_EQ(manager.GetGlobalFoldState(nextStatePrimary, nextStateSecondary),
227 FoldStatus::EXPAND);
228
229 nextStatePrimary = FoldStatus::FOLDED;
230 nextStateSecondary = FoldStatus::FOLDED;
231 EXPECT_EQ(manager.GetGlobalFoldState(nextStatePrimary, nextStateSecondary),
232 FoldStatus::FOLDED);
233
234 nextStatePrimary = FoldStatus::HALF_FOLD;
235 nextStateSecondary = FoldStatus::FOLDED;
236 EXPECT_EQ(manager.GetGlobalFoldState(nextStatePrimary, nextStateSecondary),
237 FoldStatus::HALF_FOLD);
238
239 nextStatePrimary = FoldStatus::EXPAND;
240 nextStateSecondary = FoldStatus::HALF_FOLD;
241 EXPECT_EQ(manager.GetGlobalFoldState(nextStatePrimary, nextStateSecondary),
242 FoldStatus::FOLD_STATE_EXPAND_WITH_SECOND_HALF_FOLDED);
243
244 nextStatePrimary = FoldStatus::FOLDED;
245 nextStateSecondary = FoldStatus::HALF_FOLD;
246 EXPECT_EQ(manager.GetGlobalFoldState(nextStatePrimary, nextStateSecondary),
247 FoldStatus::FOLD_STATE_FOLDED_WITH_SECOND_HALF_FOLDED);
248
249 nextStatePrimary = FoldStatus::HALF_FOLD;
250 nextStateSecondary = FoldStatus::HALF_FOLD;
251 EXPECT_EQ(manager.GetGlobalFoldState(nextStatePrimary, nextStateSecondary),
252 FoldStatus::FOLD_STATE_HALF_FOLDED_WITH_SECOND_HALF_FOLDED);
253 }
254 }
255 }
256 }