• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 
18 #define private public
19 #include "ability_manager_service.h"
20 #include "user_controller.h"
21 #undef private
22 using namespace testing;
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace AAFwk {
27 class UserControllerTest : 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 UserControllerTest::SetUpTestCase()
36 {
37     auto abilityMs = OHOS::DelayedSingleton<AbilityManagerService>::GetInstance();
38     AmsConfigurationParameter::GetInstance().Parse();
39 }
40 
TearDownTestCase()41 void UserControllerTest::TearDownTestCase()
42 {}
43 
SetUp()44 void UserControllerTest::SetUp()
45 {}
46 
TearDown()47 void UserControllerTest::TearDown()
48 {}
49 
50 /**
51  * @tc.name: UserItemSetState_0100
52  * @tc.desc: UserItemSetState Test
53  * @tc.type: FUNC
54  * @tc.require: issueI581SE
55  */
56 HWTEST_F(UserControllerTest, UserItemSetState_0100, TestSize.Level0)
57 {
58     UserItem item(100);
59     item.SetState(UserState::STATE_BOOTING);
60     EXPECT_TRUE(item.GetState() == UserState::STATE_BOOTING);
61 
62     item.SetState(UserState::STATE_STARTED);
63     EXPECT_TRUE(item.GetState() == UserState::STATE_STARTED);
64 }
65 
66 /**
67  * @tc.name: StartUserTest_0100
68  * @tc.desc: StartUser Test
69  * @tc.type: FUNC
70  * @tc.require: issueI581SE
71  */
72 HWTEST_F(UserControllerTest, StartUserTest_0100, TestSize.Level0)
73 {
74     UserController userController;
75     userController.StartUser(0, true);
76     userController.StartUser(-1, true);
77     userController.StartUser(100, true);
78     EXPECT_TRUE(userController.StartUser(100, true) == 0);
79 }
80 
81 /**
82  * @tc.name: StartUserTest_0200
83  * @tc.desc: StartUser Test
84  * @tc.type: FUNC
85  * @tc.require: issueI581SE
86  */
87 HWTEST_F(UserControllerTest, StartUserTest_0200, TestSize.Level0)
88 {
89     UserController userController;
90     EXPECT_TRUE(userController.StartUser(666, true) == -1);
91 }
92 
93 /**
94  * @tc.name: StopUserTest_0100
95  * @tc.desc: StopUser Test
96  * @tc.type: FUNC
97  * @tc.require: issueI581SE
98  */
99 HWTEST_F(UserControllerTest, StopUserTest_0100, TestSize.Level0)
100 {
101     UserController userController;
102     userController.StopUser(-1);
103     userController.StopUser(0);
104     EXPECT_TRUE(userController.StopUser(100) == -1);
105 }
106 
107 /**
108  * @tc.name: StopUserTest_0200
109  * @tc.desc: StopUser Test
110  * @tc.type: FUNC
111  * @tc.require: issueI581SE
112  */
113 HWTEST_F(UserControllerTest, StopUserTest_0200, TestSize.Level0)
114 {
115     UserController userController;
116     EXPECT_TRUE(userController.StopUser(666) == -1);
117 }
118 
119 /**
120  * @tc.name: StopUserTest_0300
121  * @tc.desc: StopUser Test
122  * @tc.type: FUNC
123  * @tc.require: issueI581SE
124  */
125 HWTEST_F(UserControllerTest, StopUserTest_0300, TestSize.Level0)
126 {
127     UserController userController;
128     userController.GetOrCreateUserItem(1000);
129     userController.StopUser(1000);
130     EXPECT_TRUE(true);
131 }
132 
133 /**
134  * @tc.name: HandleContinueUserSwitchTest_0100
135  * @tc.desc: HandleContinueUserSwitch Test
136  * @tc.type: FUNC
137  * @tc.require: issueI581SE
138  */
139 HWTEST_F(UserControllerTest, HandleContinueUserSwitchTest_0100, TestSize.Level0)
140 {
141     UserController userController;
142     auto userItem = std::make_shared<UserItem>(1000);
143     userController.HandleContinueUserSwitch(1000, 1000, userItem);
144     EXPECT_TRUE(true);
145 }
146 
147 /**
148  * @tc.name: SendUserSwitchDoneTest_0100
149  * @tc.desc: SendUserSwitchDone Test
150  * @tc.type: FUNC
151  * @tc.require: issueI581SE
152  */
153 HWTEST_F(UserControllerTest, SendUserSwitchDoneTest_0100, TestSize.Level0)
154 {
155     UserController userController;
156     userController.SendUserSwitchDone(1000);
157     userController.Init();
158     userController.SendUserSwitchDone(1001);
159     EXPECT_TRUE(true);
160 }
161 
162 /**
163  * @tc.name: SendContinueUserSwitchTest_0200
164  * @tc.desc: SendContinueUserSwitch Test
165  * @tc.type: FUNC
166  * @tc.require: issueI581SE
167  */
168 HWTEST_F(UserControllerTest, SendContinueUserSwitchTest_0200, TestSize.Level0)
169 {
170     UserController userController;
171     auto userItem = std::make_shared<UserItem>(1000);
172     userController.SendContinueUserSwitch(1000, 1000, userItem);
173     userController.Init();
174     userController.SendContinueUserSwitch(1000, 1000, userItem);
175     EXPECT_TRUE(true);
176 }
177 
178 /**
179  * @tc.name: SendUserSwitchTimeoutTest_0100
180  * @tc.desc: SendUserSwitchTimeout Test
181  * @tc.type: FUNC
182  * @tc.require: issueI581SE
183  */
184 HWTEST_F(UserControllerTest, SendUserSwitchTimeoutTest_0100, TestSize.Level0)
185 {
186     UserController userController;
187     auto userItem = std::make_shared<UserItem>(1000);
188     userController.SendUserSwitchTimeout(1000, 1000, userItem);
189     userController.Init();
190     userController.SendUserSwitchTimeout(1000, 1000, userItem);
191     EXPECT_TRUE(true);
192 }
193 
194 /**
195  * @tc.name: SendReportUserSwitchTest_0100
196  * @tc.desc: SendReportUserSwitch Test
197  * @tc.type: FUNC
198  * @tc.require: issueI581SE
199  */
200 HWTEST_F(UserControllerTest, SendReportUserSwitchTest_0100, TestSize.Level0)
201 {
202     UserController userController;
203     auto userItem = std::make_shared<UserItem>(1000);
204     userController.SendReportUserSwitch(1000, 1000, userItem);
205     userController.Init();
206     userController.SendReportUserSwitch(1000, 1000, userItem);
207     EXPECT_TRUE(true);
208 }
209 
210 /**
211  * @tc.name: SendSystemUserCurrentTest_0100
212  * @tc.desc: SendSystemUserCurrent Test
213  * @tc.type: FUNC
214  * @tc.require: issueI581SE
215  */
216 HWTEST_F(UserControllerTest, SendSystemUserCurrentTest_0100, TestSize.Level0)
217 {
218     UserController userController;
219     userController.SendSystemUserCurrent(1000, 1000);
220     userController.Init();
221     userController.SendSystemUserCurrent(1000, 1000);
222     EXPECT_TRUE(true);
223 }
224 
225 /**
226  * @tc.name: SendSystemUserStartTest_0100
227  * @tc.desc: SendSystemUserStart Test
228  * @tc.type: FUNC
229  * @tc.require: issueI581SE
230  */
231 HWTEST_F(UserControllerTest, SendSystemUserStartTest_0100, TestSize.Level0)
232 {
233     UserController userController;
234     userController.SendSystemUserStart(1000);
235     userController.Init();
236     userController.SendSystemUserStart(1000);
237     EXPECT_TRUE(true);
238 }
239 }  // namespace AAFwk
240 }  // namespace OHOS
241