• 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 <gtest/gtest.h>
17 #include "interfaces/include/ws_common.h"
18 #include "session_manager/include/scene_session_manager.h"
19 #include "session_info.h"
20 #include "session/host/include/scene_session.h"
21 #include "window_manager_agent.h"
22 #include "session_manager.h"
23 #include "mission_info.h"
24 #include "fold_screen_controller/fold_screen_state_machine.h"
25 #include "zidl/window_manager_agent_interface.h"
26 
27 using namespace testing;
28 using namespace testing::ext;
29 
30 namespace OHOS {
31 namespace Rosen {
32 namespace {
33 constexpr uint32_t SLEEP_TIME_US = 100000;
34 }
35 
36 class FoldScreenStateMachineTest : public testing::Test {
37 public:
38     static void SetUpTestCase();
39     static void TearDownTestCase();
40     void SetUp() override;
41     void TearDown() override;
42 };
43 
SetUpTestCase()44 void FoldScreenStateMachineTest::SetUpTestCase()
45 {
46 }
47 
TearDownTestCase()48 void FoldScreenStateMachineTest::TearDownTestCase()
49 {
50 }
51 
SetUp()52 void FoldScreenStateMachineTest::SetUp()
53 {
54 }
55 
TearDown()56 void FoldScreenStateMachineTest::TearDown()
57 {
58     usleep(SLEEP_TIME_US);
59 }
60 
61 namespace {
62 
63 /**
64  * @tc.name: RegistrationTransitionCallback01
65  * @tc.desc: RegistrationTransitionCallback01 func
66  * @tc.type: FUNC
67  */
68 HWTEST_F(FoldScreenStateMachineTest, RegistrationTransitionCallback01, TestSize.Level1)
69 {
70     std::shared_ptr<TransitionCallback> callback;
71     FoldScreenStateMachine fsm;
72     fsm.RegistrationTransitionCallback(callback);
73     ASSERT_EQ(fsm.GetCurrentState(), fsm.currState_);
74 }
75 
76 /**
77  * @tc.name: RegistrationTransitionCallback02
78  * @tc.desc: RegistrationTransitionCallback02 func
79  * @tc.type: FUNC
80  */
81 HWTEST_F(FoldScreenStateMachineTest, RegistrationTransitionCallback02, TestSize.Level1)
82 {
83     std::shared_ptr<TransitionCallback> callback = std::make_shared<TransitionCallback>();
84     FoldScreenStateMachine fsm;
85     fsm.RegistrationTransitionCallback(callback);
86     ASSERT_EQ(fsm.GetCurrentState(), fsm.currState_);
87 }
88 
89 /**
90  * @tc.name: RegistrationTransitionCallback03
91  * @tc.desc: RegistrationTransitionCallback03 func
92  * @tc.type: FUNC
93  */
94 HWTEST_F(FoldScreenStateMachineTest, RegistrationTransitionCallback03, TestSize.Level1)
95 {
96     std::shared_ptr<TransitionCallback> callback = std::make_shared<TransitionCallback>();
97     FoldScreenStateMachine fsm;
98     fsm.callbacks_.push_back(callback);
99     fsm.RegistrationTransitionCallback(callback);
100     ASSERT_EQ(fsm.GetCurrentState(), fsm.currState_);
101 }
102 
103 /**
104  * @tc.name: RegistrationTransitionCallback04
105  * @tc.desc: RegistrationTransitionCallback04 func
106  * @tc.type: FUNC
107  */
108 HWTEST_F(FoldScreenStateMachineTest, RegistrationTransitionCallback04, TestSize.Level1)
109 {
110     std::shared_ptr<TransitionCallback> callback = std::make_shared<TransitionCallback>();
111     std::shared_ptr<TransitionCallback> callback1 = std::make_shared<TransitionCallback>();
112     FoldScreenStateMachine fsm;
113     fsm.callbacks_.push_back(callback);
114     fsm.callbacks_.push_back(callback1);
115     fsm.RegistrationTransitionCallback(callback);
116     fsm.RegistrationTransitionCallback(callback1);
117     ASSERT_EQ(fsm.GetCurrentState(), fsm.currState_);
118 }
119 
120 /**
121  * @tc.name: UnRegistrationTransitionCallback01
122  * @tc.desc: UnRegistrationTransitionCallback01 func
123  * @tc.type: FUNC
124  */
125 HWTEST_F(FoldScreenStateMachineTest, UnRegistrationTransitionCallback01, TestSize.Level1)
126 {
127     std::shared_ptr<TransitionCallback> callback;
128     FoldScreenStateMachine fsm;
129     fsm.UnRegistrationTransitionCallback(callback);
130     ASSERT_EQ(fsm.GetCurrentState(), fsm.currState_);
131 }
132 
133 /**
134  * @tc.name: UnRegistrationTransitionCallback02
135  * @tc.desc: UnRegistrationTransitionCallback02 func
136  * @tc.type: FUNC
137  */
138 HWTEST_F(FoldScreenStateMachineTest, UnRegistrationTransitionCallback02, TestSize.Level1)
139 {
140     std::shared_ptr<TransitionCallback> callback = std::make_shared<TransitionCallback>();
141     FoldScreenStateMachine fsm;
142     fsm.UnRegistrationTransitionCallback(callback);
143     ASSERT_EQ(fsm.GetCurrentState(), fsm.currState_);
144 }
145 
146 /**
147  * @tc.name: UnRegistrationTransitionCallback03
148  * @tc.desc: UnRegistrationTransitionCallback03 func
149  * @tc.type: FUNC
150  */
151 HWTEST_F(FoldScreenStateMachineTest, UnRegistrationTransitionCallback03, TestSize.Level1)
152 {
153     std::shared_ptr<TransitionCallback> callback = std::make_shared<TransitionCallback>();
154     FoldScreenStateMachine fsm;
155     fsm.callbacks_.push_back(callback);
156     fsm.UnRegistrationTransitionCallback(callback);
157     ASSERT_EQ(fsm.GetCurrentState(), fsm.currState_);
158 }
159 
160 /**
161  * @tc.name: UnRegistrationTransitionCallback04
162  * @tc.desc: UnRegistrationTransitionCallback04 func
163  * @tc.type: FUNC
164  */
165 HWTEST_F(FoldScreenStateMachineTest, UnRegistrationTransitionCallback04, TestSize.Level1)
166 {
167     std::shared_ptr<TransitionCallback> callback = std::make_shared<TransitionCallback>();
168     std::shared_ptr<TransitionCallback> callback1 = std::make_shared<TransitionCallback>();
169     FoldScreenStateMachine fsm;
170     fsm.callbacks_.push_back(callback);
171     fsm.callbacks_.push_back(callback1);
172     fsm.RegistrationTransitionCallback(callback);
173     fsm.RegistrationTransitionCallback(callback1);
174     fsm.UnRegistrationTransitionCallback(callback);
175     fsm.UnRegistrationTransitionCallback(callback1);
176     ASSERT_EQ(fsm.GetCurrentState(), fsm.currState_);
177 }
178 
179 /**
180  * @tc.name: TransitionTo01
181  * @tc.desc: TransitionTo01 func
182  * @tc.type: FUNC
183  */
184 HWTEST_F(FoldScreenStateMachineTest, TransitionTo01, TestSize.Level1)
185 {
186     FoldScreenState state = FoldScreenState::UNKNOWN;
187     FoldScreenStateMachine fsm;
188     fsm.TransitionTo(state);
189     ASSERT_EQ(fsm.GetCurrentState(), fsm.currState_);
190     state = FoldScreenState::FOLDED;
191     fsm.TransitionTo(state);
192     ASSERT_EQ(fsm.GetCurrentState(), fsm.currState_);
193 }
194 
195 /**
196  * @tc.name: TransitionTo02
197  * @tc.desc: TransitionTo02 func
198  * @tc.type: FUNC
199  */
200 HWTEST_F(FoldScreenStateMachineTest, TransitionTo02, TestSize.Level1)
201 {
202     std::shared_ptr<TransitionCallback> callback = std::make_shared<TransitionCallback>();
203     FoldScreenState state = FoldScreenState::UNKNOWN;
204     FoldScreenStateMachine fsm;
205     fsm.callbacks_.push_back(callback);
206     fsm.TransitionTo(state);
207     ASSERT_EQ(fsm.GetCurrentState(), fsm.currState_);
208     state = FoldScreenState::FOLDED;
209     fsm.TransitionTo(state);
210     ASSERT_EQ(fsm.GetCurrentState(), fsm.currState_);
211 }
212 
213 /**
214  * @tc.name: TransitionTo03
215  * @tc.desc: TransitionTo03 func
216  * @tc.type: FUNC
217  */
218 HWTEST_F(FoldScreenStateMachineTest, TransitionTo03, TestSize.Level1)
219 {
220     std::shared_ptr<TransitionCallback> callback = std::make_shared<TransitionCallback>();
221     FoldScreenState state = FoldScreenState::HALF_FOLDED;
222     FoldScreenStateMachine fsm;
223     fsm.callbacks_.push_back(callback);
224     fsm.TransitionTo(state);
225     ASSERT_EQ(fsm.GetCurrentState(), fsm.currState_);
226     state = FoldScreenState::FOLDED;
227     fsm.TransitionTo(state);
228     ASSERT_EQ(fsm.GetCurrentState(), fsm.currState_);
229 }
230 
231 /**
232  * @tc.name: TransitionTo04
233  * @tc.desc: TransitionTo04 func
234  * @tc.type: FUNC
235  */
236 HWTEST_F(FoldScreenStateMachineTest, TransitionTo04, TestSize.Level1)
237 {
238     std::shared_ptr<TransitionCallback> callback = std::make_shared<TransitionCallback>();
239     FoldScreenState state = FoldScreenState::FULL;
240     FoldScreenStateMachine fsm;
241     fsm.callbacks_.push_back(callback);
242     fsm.TransitionTo(state);
243     ASSERT_EQ(fsm.GetCurrentState(), fsm.currState_);
244     state = FoldScreenState::FOLDED;
245     fsm.TransitionTo(state);
246     ASSERT_EQ(fsm.GetCurrentState(), fsm.currState_);
247 }
248 
249 /**
250  * @tc.name: GetCurrentState
251  * @tc.desc: GetCurrentState func
252  * @tc.type: FUNC
253  */
254 HWTEST_F(FoldScreenStateMachineTest, GetCurrentState, TestSize.Level1)
255 {
256     FoldScreenStateMachine fsm;
257     FoldScreenState state = fsm.GetCurrentState();
258     ASSERT_EQ(state, fsm.currState_);
259 }
260 
261 /**
262  * @tc.name: GenStateMachineInfo
263  * @tc.desc: GenStateMachineInfo func
264  * @tc.type: FUNC
265  */
266 HWTEST_F(FoldScreenStateMachineTest, GenStateMachineInfo, TestSize.Level1)
267 {
268     FoldScreenStateMachine fsm;
269     std::string info = fsm.GenStateMachineInfo();
270     ASSERT_EQ(fsm.GetCurrentState(), fsm.currState_);
271 }
272 
273 }
274 } // namespace Rosen
275 } // namespace OHOS
276