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, Function | SmallTest | 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, Function | SmallTest | 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, Function | SmallTest | 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: UnRegistrationTransitionCallback01
105 * @tc.desc: UnRegistrationTransitionCallback01 func
106 * @tc.type: FUNC
107 */
108 HWTEST_F(FoldScreenStateMachineTest, UnRegistrationTransitionCallback01, Function | SmallTest | Level1)
109 {
110 std::shared_ptr<TransitionCallback> callback;
111 FoldScreenStateMachine fsm;
112 fsm.UnRegistrationTransitionCallback(callback);
113 ASSERT_EQ(fsm.GetCurrentState(), fsm.currState_);
114 }
115
116 /**
117 * @tc.name: UnRegistrationTransitionCallback02
118 * @tc.desc: UnRegistrationTransitionCallback02 func
119 * @tc.type: FUNC
120 */
121 HWTEST_F(FoldScreenStateMachineTest, UnRegistrationTransitionCallback02, Function | SmallTest | Level1)
122 {
123 std::shared_ptr<TransitionCallback> callback = std::make_shared<TransitionCallback>();
124 FoldScreenStateMachine fsm;
125 fsm.UnRegistrationTransitionCallback(callback);
126 ASSERT_EQ(fsm.GetCurrentState(), fsm.currState_);
127 }
128
129 /**
130 * @tc.name: UnRegistrationTransitionCallback03
131 * @tc.desc: UnRegistrationTransitionCallback03 func
132 * @tc.type: FUNC
133 */
134 HWTEST_F(FoldScreenStateMachineTest, UnRegistrationTransitionCallback03, Function | SmallTest | Level1)
135 {
136 std::shared_ptr<TransitionCallback> callback = std::make_shared<TransitionCallback>();
137 FoldScreenStateMachine fsm;
138 fsm.callbacks_.push_back(callback);
139 fsm.UnRegistrationTransitionCallback(callback);
140 ASSERT_EQ(fsm.GetCurrentState(), fsm.currState_);
141 }
142
143 /**
144 * @tc.name: TransitionTo01
145 * @tc.desc: TransitionTo01 func
146 * @tc.type: FUNC
147 */
148 HWTEST_F(FoldScreenStateMachineTest, TransitionTo01, Function | SmallTest | Level1)
149 {
150 FoldScreenState state = FoldScreenState::UNKNOWN;
151 FoldScreenStateMachine fsm;
152 fsm.TransitionTo(state);
153 ASSERT_EQ(fsm.GetCurrentState(), fsm.currState_);
154 state = FoldScreenState::FOLDED;
155 fsm.TransitionTo(state);
156 ASSERT_EQ(fsm.GetCurrentState(), fsm.currState_);
157 }
158
159 /**
160 * @tc.name: TransitionTo02
161 * @tc.desc: TransitionTo02 func
162 * @tc.type: FUNC
163 */
164 HWTEST_F(FoldScreenStateMachineTest, TransitionTo02, Function | SmallTest | Level1)
165 {
166 std::shared_ptr<TransitionCallback> callback = std::make_shared<TransitionCallback>();
167 FoldScreenState state = FoldScreenState::UNKNOWN;
168 FoldScreenStateMachine fsm;
169 fsm.callbacks_.push_back(callback);
170 fsm.TransitionTo(state);
171 ASSERT_EQ(fsm.GetCurrentState(), fsm.currState_);
172 state = FoldScreenState::FOLDED;
173 fsm.TransitionTo(state);
174 ASSERT_EQ(fsm.GetCurrentState(), fsm.currState_);
175 }
176
177 /**
178 * @tc.name: GetCurrentState
179 * @tc.desc: GetCurrentState func
180 * @tc.type: FUNC
181 */
182 HWTEST_F(FoldScreenStateMachineTest, GetCurrentState, Function | SmallTest | Level1)
183 {
184 FoldScreenStateMachine fsm;
185 FoldScreenState state = fsm.GetCurrentState();
186 ASSERT_EQ(state, fsm.currState_);
187 }
188
189 /**
190 * @tc.name: GenStateMachineInfo
191 * @tc.desc: GenStateMachineInfo func
192 * @tc.type: FUNC
193 */
194 HWTEST_F(FoldScreenStateMachineTest, GenStateMachineInfo, Function | SmallTest | Level1)
195 {
196 FoldScreenStateMachine fsm;
197 std::string info = fsm.GenStateMachineInfo();
198 ASSERT_EQ(fsm.GetCurrentState(), fsm.currState_);
199 }
200
201 }
202 } // namespace Rosen
203 } // namespace OHOS
204