1 /*
2 * Copyright (c) 2021-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
18 #include "ability_manager_errors.h"
19 #define private public
20 #define protected public
21 #include "ability_record.h"
22 #include "app_scheduler.h"
23 #undef private
24 #undef protected
25 #include "app_debug_listener_stub_mock.h"
26 #include "app_mgr_client_mock.h"
27 #include "app_process_data.h"
28 #include "app_state_call_back_mock.h"
29 #include "bundle_info.h"
30 #include "element_name.h"
31 #include "mock_sa_call.h"
32
33 using namespace testing;
34 using namespace testing::ext;
35 using namespace OHOS::AppExecFwk;
36
37 namespace OHOS {
38 namespace AAFwk {
39 namespace {
40 const int32_t USER_ID = 100;
41 const std::string STRING_APP_STATE = "BEGIN";
42 } // namespace
43
44 class AppSchedulerTest : public testing::Test {
45 public:
46 static void SetUpTestCase(void);
47 static void TearDownTestCase(void);
48 void SetUp();
49 void TearDown();
50
51 static AbilityRequest GenerateAbilityRequest(const std::string& deviceName, const std::string& abilityName,
52 const std::string& appName, const std::string& bundleName);
53
54 std::shared_ptr<AppStateCallbackMock> appStateMock_ = std::make_shared<AppStateCallbackMock>();
55 std::unique_ptr<AppMgrClientMock> clientMock_ = std::make_unique<AppMgrClientMock>();
56 };
57
SetUpTestCase(void)58 void AppSchedulerTest::SetUpTestCase(void)
59 {}
TearDownTestCase(void)60 void AppSchedulerTest::TearDownTestCase(void)
61 {}
SetUp()62 void AppSchedulerTest::SetUp()
63 {}
TearDown()64 void AppSchedulerTest::TearDown()
65 {}
66
GenerateAbilityRequest(const std::string& deviceName, const std::string& abilityName, const std::string& appName, const std::string& bundleName)67 AbilityRequest AppSchedulerTest::GenerateAbilityRequest(const std::string& deviceName, const std::string& abilityName,
68 const std::string& appName, const std::string& bundleName)
69 {
70 ElementName element(deviceName, abilityName, bundleName);
71 Want want;
72 want.SetElement(element);
73
74 AbilityInfo abilityInfo;
75 abilityInfo.applicationName = appName;
76 ApplicationInfo appinfo;
77 appinfo.name = appName;
78
79 AbilityRequest abilityRequest;
80 abilityRequest.want = want;
81 abilityRequest.abilityInfo = abilityInfo;
82 abilityRequest.appInfo = appinfo;
83
84 return abilityRequest;
85 }
86
87 /**
88 * @tc.name: AppScheduler_GetConfiguration_0100
89 * @tc.desc: GetConfiguration
90 * @tc.type: FUNC
91 * @tc.require: SR000GH1GO
92 */
HWTEST_F(AppSchedulerTest, AppScheduler_GetConfiguration_0100, TestSize.Level1)93 HWTEST_F(AppSchedulerTest, AppScheduler_GetConfiguration_0100, TestSize.Level1)
94 {
95 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = nullptr;
96
97 Configuration config;
98 auto result = DelayedSingleton<AppScheduler>::GetInstance()->GetConfiguration(config);
99
100 EXPECT_EQ(result, INNER_ERR);
101 }
102
103 /**
104 * @tc.name: AppScheduler_GetProcessRunningInfosByUserId_0100
105 * @tc.desc: GetProcessRunningInfosByUserId
106 * @tc.type: FUNC
107 * @tc.require: SR000GH1GO
108 */
HWTEST_F(AppSchedulerTest, AppScheduler_GetProcessRunningInfosByUserId_0100, TestSize.Level1)109 HWTEST_F(AppSchedulerTest, AppScheduler_GetProcessRunningInfosByUserId_0100, TestSize.Level1)
110 {
111 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = nullptr;
112
113 std::vector<RunningProcessInfo> info;
114 int32_t userId = USER_ID;
115 auto result = DelayedSingleton<AppScheduler>::GetInstance()->GetProcessRunningInfosByUserId(info, userId);
116
117 EXPECT_EQ(result, INNER_ERR);
118 }
119
120 /**
121 * @tc.name: AppScheduler_ConvertAppState_0100
122 * @tc.desc: ConvertAppState
123 * @tc.type: FUNC
124 * @tc.require: SR000GH1GO
125 */
HWTEST_F(AppSchedulerTest, AppScheduler_ConvertAppState_0100, TestSize.Level1)126 HWTEST_F(AppSchedulerTest, AppScheduler_ConvertAppState_0100, TestSize.Level1)
127 {
128 AppState state = AppState::BEGIN;
129 auto result = DelayedSingleton<AppScheduler>::GetInstance()->ConvertAppState(state);
130
131 EXPECT_EQ(result, STRING_APP_STATE);
132 }
133
134 /*
135 * Feature: AppScheduler
136 * Function: Init
137 * SubFunction: NA
138 * FunctionPoints: AppSchedulerTest Init
139 * EnvConditions:NA
140 * CaseDescription: Appstatecallback is nullptr causes init to fail
141 */
HWTEST_F(AppSchedulerTest, AppScheduler_oprator_001, TestSize.Level1)142 HWTEST_F(AppSchedulerTest, AppScheduler_oprator_001, TestSize.Level1)
143 {
144 std::shared_ptr<AppStateCallbackMock> appStateMock;
145 EXPECT_EQ(false, DelayedSingleton<AppScheduler>::GetInstance()->Init(appStateMock));
146 }
147
148 /*
149 * Feature: AppScheduler
150 * Function: Init
151 * SubFunction: NA
152 * FunctionPoints: AppScheduler Init
153 * EnvConditions: NA
154 * CaseDescription: Verify Init
155 */
HWTEST_F(AppSchedulerTest, AppScheduler_Init_001, TestSize.Level1)156 HWTEST_F(AppSchedulerTest, AppScheduler_Init_001, TestSize.Level1)
157 {
158 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::make_unique<AppExecFwk::AppMgrClient>();
159 DelayedSingleton<AppScheduler>::GetInstance()->isInit_ = true;
160 std::weak_ptr<AppStateCallback> callback(appStateMock_);
161 bool res = DelayedSingleton<AppScheduler>::GetInstance()->Init(callback);
162 EXPECT_TRUE(res);
163 }
164
165 /*
166 * Feature: AppScheduler
167 * Function: Init
168 * SubFunction: NA
169 * FunctionPoints: AppScheduler Init
170 * EnvConditions: NA
171 * CaseDescription: Verify Init
172 */
HWTEST_F(AppSchedulerTest, AppScheduler_Init_002, TestSize.Level1)173 HWTEST_F(AppSchedulerTest, AppScheduler_Init_002, TestSize.Level1)
174 {
175 EXPECT_CALL(*clientMock_, ConnectAppMgrService()).Times(1)
176 .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY));
177 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
178 DelayedSingleton<AppScheduler>::GetInstance()->isInit_ = false;
179 std::weak_ptr<AppStateCallback> callback(appStateMock_);
180 bool res = DelayedSingleton<AppScheduler>::GetInstance()->Init(callback);
181 EXPECT_FALSE(res);
182 clientMock_.reset();
183 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_.reset();
184 }
185
186 /*
187 * Feature: AppScheduler
188 * Function: Init
189 * SubFunction: NA
190 * FunctionPoints: AppScheduler Init
191 * EnvConditions: NA
192 * CaseDescription: Verify Init
193 */
HWTEST_F(AppSchedulerTest, AppScheduler_Init_003, TestSize.Level1)194 HWTEST_F(AppSchedulerTest, AppScheduler_Init_003, TestSize.Level1)
195 {
196 clientMock_ = std::make_unique<AppMgrClientMock>();
197 EXPECT_CALL(*clientMock_, RegisterAppStateCallback(_)).Times(1)
198 .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY));
199 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
200 DelayedSingleton<AppScheduler>::GetInstance()->isInit_ = false;
201 std::weak_ptr<AppStateCallback> callback(appStateMock_);
202 bool res = DelayedSingleton<AppScheduler>::GetInstance()->Init(callback);
203 EXPECT_FALSE(res);
204 }
205
206 /*
207 * Feature: AppScheduler
208 * Function: LoadAbility
209 * SubFunction: NA
210 * FunctionPoints: AppScheduler LoadAbility
211 * EnvConditions:NA
212 * CaseDescription: Verify the fail process of loadability
213 */
HWTEST_F(AppSchedulerTest, AppScheduler_oprator_004, TestSize.Level1)214 HWTEST_F(AppSchedulerTest, AppScheduler_oprator_004, TestSize.Level1)
215 {
216 std::string deviceName = "device";
217 std::string abilityName = "FirstAbility";
218 std::string appName = "FirstApp";
219 std::string bundleName = "com.ix.First.Test";
220 auto abilityReq = GenerateAbilityRequest(deviceName, abilityName, appName, bundleName);
221 auto record = AbilityRecord::CreateAbilityRecord(abilityReq);
222 auto token = record->GetToken();
223
224 std::string preDeviceName = "device";
225 std::string preAbilityName = "SecondAbility";
226 std::string preAppName = "SecondApp";
227 std::string preBundleName = "com.ix.Second.Test";
228 auto preAbilityReq = GenerateAbilityRequest(preDeviceName, preAbilityName, preAppName, preBundleName);
229 auto preRecord = AbilityRecord::CreateAbilityRecord(preAbilityReq);
230 auto pretoken = preRecord->GetToken();
231 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = nullptr;
232 EXPECT_NE((int)ERR_OK,
233 DelayedSingleton<AppScheduler>::GetInstance()->LoadAbility(
234 token, pretoken, record->GetAbilityInfo(), record->GetApplicationInfo(), record->GetWant(), 0, ""));
235 }
236
237 /*
238 * Feature: AppScheduler
239 * Function: LoadAbility
240 * SubFunction: NA
241 * FunctionPoints: AppScheduler LoadAbility
242 * EnvConditions: NA
243 * CaseDescription: Verify LoadAbility
244 */
HWTEST_F(AppSchedulerTest, AppScheduler_LoadAbility_001, TestSize.Level1)245 HWTEST_F(AppSchedulerTest, AppScheduler_LoadAbility_001, TestSize.Level1)
246 {
247 EXPECT_CALL(*clientMock_, LoadAbility(_, _, _, _)).Times(1)
248 .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY));
249 sptr<IRemoteObject> token;
250 sptr<IRemoteObject> preToken;
251 AbilityInfo abilityInfo;
252 ApplicationInfo applicationInfo;
253 Want want;
254 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
255 int res = DelayedSingleton<AppScheduler>::GetInstance()->LoadAbility(
256 token, preToken, abilityInfo, applicationInfo, want, 0, "");
257 EXPECT_EQ(res, INNER_ERR);
258 }
259
260 /*
261 * Feature: AppScheduler
262 * Function: TerminateAbility
263 * SubFunction: NA
264 * FunctionPoints: AppScheduler TerminateAbility
265 * EnvConditions: NA
266 * CaseDescription: Verify TerminateAbility
267 */
HWTEST_F(AppSchedulerTest, AppScheduler_TerminateAbility_001, TestSize.Level1)268 HWTEST_F(AppSchedulerTest, AppScheduler_TerminateAbility_001, TestSize.Level1)
269 {
270 EXPECT_CALL(*clientMock_, TerminateAbility(_, _)).Times(1)
271 .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY));
272 sptr<IRemoteObject> token;
273 bool clearMissionFlag = true;
274 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
275 int res = DelayedSingleton<AppScheduler>::GetInstance()->TerminateAbility(token, clearMissionFlag);
276 EXPECT_EQ(res, INNER_ERR);
277 }
278
279 /*
280 * Feature: AppScheduler
281 * Function: TerminateAbility
282 * SubFunction: NA
283 * FunctionPoints: AppScheduler TerminateAbility
284 * EnvConditions:NA
285 * CaseDescription: Verify appmgrclient_ Is nullptr causes TerminateAbility to fail
286 */
HWTEST_F(AppSchedulerTest, AppScheduler_oprator_006, TestSize.Level1)287 HWTEST_F(AppSchedulerTest, AppScheduler_oprator_006, TestSize.Level1)
288 {
289 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = nullptr;
290 std::string deviceName = "device";
291 std::string abilityName = "FirstAbility";
292 std::string appName = "FirstApp";
293 std::string bundleName = "com.ix.First.Test";
294 auto abilityReq = GenerateAbilityRequest(deviceName, abilityName, appName, bundleName);
295 auto record = AbilityRecord::CreateAbilityRecord(abilityReq);
296 auto token = record->GetToken();
297
298 EXPECT_NE((int)ERR_OK, DelayedSingleton<AppScheduler>::GetInstance()->TerminateAbility(token, false));
299 }
300
301 /*
302 * Feature: AppScheduler
303 * Function: TerminateAbility
304 * SubFunction: NA
305 * FunctionPoints: AppScheduler TerminateAbility
306 * EnvConditions:NA
307 * CaseDescription: Verify appmgrclient_ Is not nullptr causes TerminateAbility to success
308 */
HWTEST_F(AppSchedulerTest, AppScheduler_oprator_007, TestSize.Level1)309 HWTEST_F(AppSchedulerTest, AppScheduler_oprator_007, TestSize.Level1)
310 {
311 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::make_unique<AppExecFwk::AppMgrClient>();
312
313 std::string deviceName = "device";
314 std::string abilityName = "FirstAbility";
315 std::string appName = "FirstApp";
316 std::string bundleName = "com.ix.First.Test";
317 auto abilityReq = GenerateAbilityRequest(deviceName, abilityName, appName, bundleName);
318 auto record = AbilityRecord::CreateAbilityRecord(abilityReq);
319 auto token = record->GetToken();
320
321 EXPECT_EQ((int)ERR_OK, DelayedSingleton<AppScheduler>::GetInstance()->TerminateAbility(token, false));
322 }
323
324 /*
325 * Feature: AppScheduler
326 * Function: MoveToForeground
327 * SubFunction: NA
328 * FunctionPoints: AppScheduler MoveToForeground
329 * EnvConditions:NA
330 * CaseDescription: Verify appmgrclient_ Is null causes movetoforground to be invalid
331 */
HWTEST_F(AppSchedulerTest, AppScheduler_oprator_008, TestSize.Level1)332 HWTEST_F(AppSchedulerTest, AppScheduler_oprator_008, TestSize.Level1)
333 {
334 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = nullptr;
335
336 std::string deviceName = "device";
337 std::string abilityName = "FirstAbility";
338 std::string appName = "FirstApp";
339 std::string bundleName = "com.ix.First.Test";
340 auto abilityReq = GenerateAbilityRequest(deviceName, abilityName, appName, bundleName);
341 auto record = AbilityRecord::CreateAbilityRecord(abilityReq);
342 auto token = record->GetToken();
343 ASSERT_NE(token, nullptr);
344
345 DelayedSingleton<AppScheduler>::GetInstance()->MoveToForeground(token);
346 }
347
348 /*
349 * Feature: AppScheduler
350 * Function: MoveToForeground
351 * SubFunction: NA
352 * FunctionPoints: AppScheduler MoveToForeground
353 * EnvConditions:NA
354 * CaseDescription: Verify the normal process of movetoforground
355 */
HWTEST_F(AppSchedulerTest, AppScheduler_oprator_009, TestSize.Level1)356 HWTEST_F(AppSchedulerTest, AppScheduler_oprator_009, TestSize.Level1)
357 {
358 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::make_unique<AppExecFwk::AppMgrClient>();
359
360 std::string deviceName = "device";
361 std::string abilityName = "FirstAbility";
362 std::string appName = "FirstApp";
363 std::string bundleName = "com.ix.First.Test";
364 auto abilityReq = GenerateAbilityRequest(deviceName, abilityName, appName, bundleName);
365 auto record = AbilityRecord::CreateAbilityRecord(abilityReq);
366 auto token = record->GetToken();
367 ASSERT_NE(token, nullptr);
368
369 DelayedSingleton<AppScheduler>::GetInstance()->MoveToForeground(token);
370 }
371
372 /*
373 * Feature: AppScheduler
374 * Function: MoveToBackground
375 * SubFunction: NA
376 * FunctionPoints: AppScheduler MoveToBackground
377 * EnvConditions:NA
378 * CaseDescription: Verify appmgrclient_ Is null causes OnAbilityRequestDone to be invalid
379 */
HWTEST_F(AppSchedulerTest, AppScheduler_oprator_010, TestSize.Level1)380 HWTEST_F(AppSchedulerTest, AppScheduler_oprator_010, TestSize.Level1)
381 {
382 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = nullptr;
383
384 std::string deviceName = "device";
385 std::string abilityName = "FirstAbility";
386 std::string appName = "FirstApp";
387 std::string bundleName = "com.ix.First";
388 auto abilityReq = GenerateAbilityRequest(deviceName, abilityName, appName, bundleName);
389 auto record = AbilityRecord::CreateAbilityRecord(abilityReq);
390 auto token = record->GetToken();
391 ASSERT_NE(token, nullptr);
392
393 DelayedSingleton<AppScheduler>::GetInstance()->MoveToBackground(token);
394 }
395
396 /*
397 * Feature: AppScheduler
398 * Function: MoveToBackground GetAbilityState
399 * SubFunction: NA
400 * FunctionPoints: AppScheduler MoveToBackground and GetAbilityState
401 * EnvConditions:NA
402 * CaseDescription: Verify appmgrclient_ Is not nullptr causes onabilityrequestdone invoke
403 */
HWTEST_F(AppSchedulerTest, AppScheduler_oprator_011, TestSize.Level1)404 HWTEST_F(AppSchedulerTest, AppScheduler_oprator_011, TestSize.Level1)
405 {
406 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::make_unique<AppExecFwk::AppMgrClient>();
407 std::string deviceName = "device";
408 std::string abilityName = "FirstAbility";
409 std::string appName = "FirstApp";
410 std::string bundleName = "com.ix.First";
411 auto abilityReq = GenerateAbilityRequest(deviceName, abilityName, appName, bundleName);
412 auto record = AbilityRecord::CreateAbilityRecord(abilityReq);
413 auto token = record->GetToken();
414
415 DelayedSingleton<AppScheduler>::GetInstance()->MoveToBackground(token);
416 EXPECT_EQ(
417 AppAbilityState::ABILITY_STATE_UNDEFINED, DelayedSingleton<AppScheduler>::GetInstance()->GetAbilityState());
418 }
419
420 /*
421 * Feature: AppScheduler
422 * Function: ConvertToAppAbilityState
423 * SubFunction: NA
424 * FunctionPoints: AppScheduler ConvertToAppAbilityState
425 * EnvConditions:NA
426 * CaseDescription: Verify ConvertToAppAbilityState result
427 */
HWTEST_F(AppSchedulerTest, AppScheduler_oprator_012, TestSize.Level1)428 HWTEST_F(AppSchedulerTest, AppScheduler_oprator_012, TestSize.Level1)
429 {
430 EXPECT_EQ(AppAbilityState::ABILITY_STATE_FOREGROUND,
431 DelayedSingleton<AppScheduler>::GetInstance()->ConvertToAppAbilityState(
432 static_cast<int>(AppExecFwk::AbilityState::ABILITY_STATE_FOREGROUND)));
433
434 EXPECT_EQ(AppAbilityState::ABILITY_STATE_BACKGROUND,
435 DelayedSingleton<AppScheduler>::GetInstance()->ConvertToAppAbilityState(
436 static_cast<int>(AppExecFwk::AbilityState::ABILITY_STATE_BACKGROUND)));
437
438 EXPECT_EQ(AppAbilityState::ABILITY_STATE_UNDEFINED,
439 DelayedSingleton<AppScheduler>::GetInstance()->ConvertToAppAbilityState(
440 static_cast<int>(AppExecFwk::AbilityState::ABILITY_STATE_CREATE)));
441 }
442
443 /*
444 * Feature: AppScheduler
445 * Function: ConvertToAppAbilityState
446 * SubFunction: NA
447 * FunctionPoints: AppScheduler ConvertToAppAbilityState
448 * EnvConditions:NA
449 * CaseDescription: Verify ConvertToAppAbilityState result
450 */
HWTEST_F(AppSchedulerTest, AppScheduler_oprator_013, TestSize.Level1)451 HWTEST_F(AppSchedulerTest, AppScheduler_oprator_013, TestSize.Level1)
452 {
453 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = nullptr;
454 EXPECT_EQ(false, DelayedSingleton<AppScheduler>::GetInstance()->Init(appStateMock_));
455 }
456
457 /*
458 * Feature: AppScheduler
459 * Function: KillProcessByAbilityToken
460 * SubFunction: NA
461 * FunctionPoints: AppScheduler KillProcessByAbilityToken
462 * EnvConditions:NA
463 * CaseDescription: Verify appmgrclient_ Is not nullptr causes KillProcessByAbilityToken to success
464 */
HWTEST_F(AppSchedulerTest, AppScheduler_oprator_016, TestSize.Level1)465 HWTEST_F(AppSchedulerTest, AppScheduler_oprator_016, TestSize.Level1)
466 {
467 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::make_unique<AppExecFwk::AppMgrClient>();
468
469 std::string deviceName = "device";
470 std::string abilityName = "FirstAbility";
471 std::string appName = "FirstApp";
472 std::string bundleName = "com.ix.First";
473 auto abilityReq = GenerateAbilityRequest(deviceName, abilityName, appName, bundleName);
474 auto record = AbilityRecord::CreateAbilityRecord(abilityReq);
475 auto token = record->GetToken();
476 ASSERT_NE(token, nullptr);
477
478 DelayedSingleton<AppScheduler>::GetInstance()->KillProcessByAbilityToken(token);
479 }
480
481 /*
482 * Feature: AppScheduler
483 * Function: KillProcessByAbilityToken
484 * SubFunction: NA
485 * FunctionPoints: AppScheduler KillProcessByAbilityToken
486 * EnvConditions:NA
487 * CaseDescription: Verify appmgrclient_ Is nullptr causes KillProcessByAbilityToken to fail
488 */
HWTEST_F(AppSchedulerTest, AppScheduler_oprator_017, TestSize.Level1)489 HWTEST_F(AppSchedulerTest, AppScheduler_oprator_017, TestSize.Level1)
490 {
491 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = nullptr;
492
493 std::string deviceName = "device";
494 std::string abilityName = "FirstAbility";
495 std::string appName = "FirstApp";
496 std::string bundleName = "com.ix.First";
497 auto abilityReq = GenerateAbilityRequest(deviceName, abilityName, appName, bundleName);
498 auto record = AbilityRecord::CreateAbilityRecord(abilityReq);
499 auto token = record->GetToken();
500 ASSERT_NE(token, nullptr);
501
502 DelayedSingleton<AppScheduler>::GetInstance()->KillProcessByAbilityToken(token);
503 }
504
505 /*
506 * Feature: AppScheduler
507 * Function: UpdateAbilityState
508 * SubFunction: NA
509 * FunctionPoints: AppScheduler UpdateAbilityState
510 * EnvConditions: NA
511 * CaseDescription: Verify UpdateAbilityState
512 */
HWTEST_F(AppSchedulerTest, AppScheduler_UpdateAbilityState_001, TestSize.Level1)513 HWTEST_F(AppSchedulerTest, AppScheduler_UpdateAbilityState_001, TestSize.Level1)
514 {
515 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::make_unique<AppExecFwk::AppMgrClient>();
516 ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_, nullptr);
517 sptr<IRemoteObject> token = nullptr;
518 AppExecFwk::AbilityState state = AppExecFwk::AbilityState::ABILITY_STATE_CREATE;
519 DelayedSingleton<AppScheduler>::GetInstance()->UpdateAbilityState(token, state);
520 }
521
522 /*
523 * Feature: AppScheduler
524 * Function: UpdateExtensionState
525 * SubFunction: NA
526 * FunctionPoints: AppScheduler UpdateExtensionState
527 * EnvConditions: NA
528 * CaseDescription: Verify UpdateExtensionState
529 */
HWTEST_F(AppSchedulerTest, AppScheduler_UpdateExtensionState_001, TestSize.Level1)530 HWTEST_F(AppSchedulerTest, AppScheduler_UpdateExtensionState_001, TestSize.Level1)
531 {
532 EXPECT_CALL(*clientMock_, UpdateExtensionState(_, _)).Times(1)
533 .WillOnce(Return(AppMgrResultCode::RESULT_OK));
534 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
535 ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_, nullptr);
536 sptr<IRemoteObject> token = nullptr;
537 AppExecFwk::ExtensionState state = AppExecFwk::ExtensionState::EXTENSION_STATE_READY;
538 DelayedSingleton<AppScheduler>::GetInstance()->UpdateExtensionState(token, state);
539 }
540
541 /*
542 * Feature: AppScheduler
543 * Function: KillProcessesByUserId
544 * SubFunction: NA
545 * FunctionPoints: AppScheduler KillProcessesByUserId
546 * EnvConditions: NA
547 * CaseDescription: Verify KillProcessesByUserId
548 */
HWTEST_F(AppSchedulerTest, AppScheduler_KillProcessesByUserId_001, TestSize.Level1)549 HWTEST_F(AppSchedulerTest, AppScheduler_KillProcessesByUserId_001, TestSize.Level1)
550 {
551 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::make_unique<AppExecFwk::AppMgrClient>();
552 ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_, nullptr);
553 int32_t userId = 0;
554 DelayedSingleton<AppScheduler>::GetInstance()->KillProcessesByUserId(userId);
555 }
556
557 /*
558 * Feature: AppScheduler
559 * Function: OnAbilityRequestDone
560 * SubFunction: NA
561 * FunctionPoints: AppScheduler OnAbilityRequestDone
562 * EnvConditions: NA
563 * CaseDescription: Verify OnAbilityRequestDone
564 */
HWTEST_F(AppSchedulerTest, AppScheduler_OnAbilityRequestDone_001, TestSize.Level1)565 HWTEST_F(AppSchedulerTest, AppScheduler_OnAbilityRequestDone_001, TestSize.Level1)
566 {
567 sptr<IRemoteObject> token = nullptr;
568 AppExecFwk::AbilityState state = AppExecFwk::AbilityState::ABILITY_STATE_CREATE;
569 ASSERT_NE(appStateMock_, nullptr);
570 DelayedSingleton<AppScheduler>::GetInstance()->callback_ = appStateMock_;
571 DelayedSingleton<AppScheduler>::GetInstance()->OnAbilityRequestDone(token, state);
572 }
573
574 /*
575 * Feature: AppScheduler
576 * Function: NotifyStartResidentProcess
577 * SubFunction: NA
578 * FunctionPoints: AppScheduler NotifyStartResidentProcess
579 * EnvConditions: NA
580 * CaseDescription: Verify NotifyStartResidentProcess
581 */
HWTEST_F(AppSchedulerTest, AppScheduler_NotifyStartResidentProcess_001, TestSize.Level1)582 HWTEST_F(AppSchedulerTest, AppScheduler_NotifyStartResidentProcess_001, TestSize.Level1)
583 {
584 std::vector<AppExecFwk::BundleInfo> bundleInfos;
585 ASSERT_NE(appStateMock_, nullptr);
586 DelayedSingleton<AppScheduler>::GetInstance()->callback_ = appStateMock_;
587 DelayedSingleton<AppScheduler>::GetInstance()->NotifyStartResidentProcess(bundleInfos);
588 }
589
590 /*
591 * Feature: AppScheduler
592 * Function: KillApplication
593 * SubFunction: NA
594 * FunctionPoints: AppScheduler KillApplication
595 * EnvConditions: NA
596 * CaseDescription: Verify KillApplication
597 */
HWTEST_F(AppSchedulerTest, AppScheduler_KillApplication_001, TestSize.Level1)598 HWTEST_F(AppSchedulerTest, AppScheduler_KillApplication_001, TestSize.Level1)
599 {
600 EXPECT_CALL(*clientMock_, KillApplication(_, _)).Times(1)
601 .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY));
602 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
603 std::string bundleName = "bundleName";
604 int res = DelayedSingleton<AppScheduler>::GetInstance()->KillApplication(bundleName);
605 EXPECT_EQ(res, INNER_ERR);
606 }
607
608 /*
609 * Feature: AppScheduler
610 * Function: KillApplication
611 * SubFunction: NA
612 * FunctionPoints: AppScheduler KillApplication
613 * EnvConditions: NA
614 * CaseDescription: Verify KillApplication
615 */
HWTEST_F(AppSchedulerTest, AppScheduler_KillApplication_002, TestSize.Level1)616 HWTEST_F(AppSchedulerTest, AppScheduler_KillApplication_002, TestSize.Level1)
617 {
618 EXPECT_CALL(*clientMock_, KillApplication(_, _)).Times(1)
619 .WillOnce(Return(AppMgrResultCode::RESULT_OK));
620 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
621 std::string bundleName = "bundleName";
622 int res = DelayedSingleton<AppScheduler>::GetInstance()->KillApplication(bundleName);
623 EXPECT_EQ(res, ERR_OK);
624 }
625
626 /*
627 * Feature: AppScheduler
628 * Function: KillApplicationByUid
629 * SubFunction: NA
630 * FunctionPoints: AppScheduler KillApplicationByUid
631 * EnvConditions: NA
632 * CaseDescription: Verify KillApplicationByUid
633 */
HWTEST_F(AppSchedulerTest, AppScheduler_KillApplicationByUid_001, TestSize.Level1)634 HWTEST_F(AppSchedulerTest, AppScheduler_KillApplicationByUid_001, TestSize.Level1)
635 {
636 EXPECT_CALL(*clientMock_, KillApplicationByUid(_, _, _)).Times(1)
637 .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY));
638 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
639 std::string bundleName = "bundleName";
640 int32_t uid = 0;
641 int res = DelayedSingleton<AppScheduler>::GetInstance()->KillApplicationByUid(bundleName, uid);
642 EXPECT_EQ(res, INNER_ERR);
643 }
644
645 /*
646 * Feature: AppScheduler
647 * Function: KillApplicationByUid
648 * SubFunction: NA
649 * FunctionPoints: AppScheduler KillApplicationByUid
650 * EnvConditions: NA
651 * CaseDescription: Verify KillApplicationByUid
652 */
HWTEST_F(AppSchedulerTest, AppScheduler_KillApplicationByUid_002, TestSize.Level1)653 HWTEST_F(AppSchedulerTest, AppScheduler_KillApplicationByUid_002, TestSize.Level1)
654 {
655 EXPECT_CALL(*clientMock_, KillApplicationByUid(_, _, _)).Times(1)
656 .WillOnce(Return(AppMgrResultCode::RESULT_OK));
657 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
658 std::string bundleName = "bundleName";
659 int32_t uid = 0;
660 int res = DelayedSingleton<AppScheduler>::GetInstance()->KillApplicationByUid(bundleName, uid);
661 EXPECT_EQ(res, ERR_OK);
662 }
663
664 /*
665 * Feature: AppScheduler
666 * Function: PrepareTerminate
667 * SubFunction: NA
668 * FunctionPoints: AppScheduler PrepareTerminate
669 * EnvConditions: NA
670 * CaseDescription: Verify PrepareTerminate
671 */
HWTEST_F(AppSchedulerTest, AppScheduler_PrepareTerminate_001, TestSize.Level1)672 HWTEST_F(AppSchedulerTest, AppScheduler_PrepareTerminate_001, TestSize.Level1)
673 {
674 sptr<IRemoteObject> token = nullptr;
675 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::make_unique<AppExecFwk::AppMgrClient>();
676 ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_, nullptr);
677 DelayedSingleton<AppScheduler>::GetInstance()->PrepareTerminate(token);
678 }
679
680 /*
681 * Feature: AppScheduler
682 * Function: OnAppStateChanged
683 * SubFunction: NA
684 * FunctionPoints: AppScheduler OnAppStateChanged
685 * EnvConditions: NA
686 * CaseDescription: Verify OnAppStateChanged
687 */
HWTEST_F(AppSchedulerTest, AppScheduler_OnAppStateChanged_001, TestSize.Level1)688 HWTEST_F(AppSchedulerTest, AppScheduler_OnAppStateChanged_001, TestSize.Level1)
689 {
690 AppExecFwk::AppProcessData appData;
691 ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance(), nullptr);
692 DelayedSingleton<AppScheduler>::GetInstance()->OnAppStateChanged(appData);
693 }
694
695 /*
696 * Feature: AppScheduler
697 * Function: GetRunningProcessInfoByToken
698 * SubFunction: NA
699 * FunctionPoints: AppScheduler GetRunningProcessInfoByToken
700 * EnvConditions: NA
701 * CaseDescription: Verify GetRunningProcessInfoByToken
702 */
HWTEST_F(AppSchedulerTest, AppScheduler_GetRunningProcessInfoByToken_001, TestSize.Level1)703 HWTEST_F(AppSchedulerTest, AppScheduler_GetRunningProcessInfoByToken_001, TestSize.Level1)
704 {
705 sptr<IRemoteObject> token;
706 AppExecFwk::RunningProcessInfo info;
707 ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance(), nullptr);
708 DelayedSingleton<AppScheduler>::GetInstance()->GetRunningProcessInfoByToken(token, info);
709 }
710
711 /*
712 * Feature: AppScheduler
713 * Function: GetRunningProcessInfoByPid
714 * SubFunction: NA
715 * FunctionPoints: AppScheduler GetRunningProcessInfoByPid
716 * EnvConditions: NA
717 * CaseDescription: Verify GetRunningProcessInfoByPid
718 */
HWTEST_F(AppSchedulerTest, AppScheduler_GetRunningProcessInfoByPid_001, TestSize.Level1)719 HWTEST_F(AppSchedulerTest, AppScheduler_GetRunningProcessInfoByPid_001, TestSize.Level1)
720 {
721 pid_t pid = 0;
722 AppExecFwk::RunningProcessInfo info;
723 ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance(), nullptr);
724 DelayedSingleton<AppScheduler>::GetInstance()->GetRunningProcessInfoByPid(pid, info);
725 }
726
727 /*
728 * Feature: AppScheduler
729 * Function: StartupResidentProcess
730 * SubFunction: NA
731 * FunctionPoints: AppScheduler StartupResidentProcess
732 * EnvConditions: NA
733 * CaseDescription: Verify StartupResidentProcess
734 */
HWTEST_F(AppSchedulerTest, AppScheduler_StartupResidentProcess_001, TestSize.Level1)735 HWTEST_F(AppSchedulerTest, AppScheduler_StartupResidentProcess_001, TestSize.Level1)
736 {
737 EXPECT_CALL(*clientMock_, StartupResidentProcess(_)).Times(1);
738 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
739 ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_, nullptr);
740 std::vector<AppExecFwk::BundleInfo> bundleInfos;
741 DelayedSingleton<AppScheduler>::GetInstance()->StartupResidentProcess(bundleInfos);
742 }
743
744 /*
745 * Feature: AppScheduler
746 * Function: StartSpecifiedAbility
747 * SubFunction: NA
748 * FunctionPoints: AppScheduler StartSpecifiedAbility
749 * EnvConditions: NA
750 * CaseDescription: Verify StartSpecifiedAbility
751 */
HWTEST_F(AppSchedulerTest, AppScheduler_StartSpecifiedAbility_001, TestSize.Level1)752 HWTEST_F(AppSchedulerTest, AppScheduler_StartSpecifiedAbility_001, TestSize.Level1)
753 {
754 EXPECT_CALL(*clientMock_, StartSpecifiedAbility(_, _, _)).Times(1);
755 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
756 ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_, nullptr);
757 AAFwk::Want want;
758 AppExecFwk::AbilityInfo abilityInfo;
759 DelayedSingleton<AppScheduler>::GetInstance()->StartSpecifiedAbility(want, abilityInfo);
760 }
761
762 /*
763 * Feature: AppScheduler
764 * Function: GetProcessRunningInfos
765 * SubFunction: NA
766 * FunctionPoints: AppScheduler GetProcessRunningInfos
767 * EnvConditions: NA
768 * CaseDescription: Verify GetProcessRunningInfos
769 */
HWTEST_F(AppSchedulerTest, AppScheduler_GetProcessRunningInfos_001, TestSize.Level1)770 HWTEST_F(AppSchedulerTest, AppScheduler_GetProcessRunningInfos_001, TestSize.Level1)
771 {
772 EXPECT_CALL(*clientMock_, GetAllRunningProcesses(_)).Times(1);
773 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
774 ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_, nullptr);
775 std::vector<AppExecFwk::RunningProcessInfo> info;
776 DelayedSingleton<AppScheduler>::GetInstance()->GetProcessRunningInfos(info);
777 }
778
779 /*
780 * Feature: AppScheduler
781 * Function: GetProcessRunningInfosByUserId
782 * SubFunction: NA
783 * FunctionPoints: AppScheduler GetProcessRunningInfosByUserId
784 * EnvConditions: NA
785 * CaseDescription: Verify GetProcessRunningInfosByUserId
786 */
HWTEST_F(AppSchedulerTest, AppScheduler_GetProcessRunningInfosByUserId_001, TestSize.Level1)787 HWTEST_F(AppSchedulerTest, AppScheduler_GetProcessRunningInfosByUserId_001, TestSize.Level1)
788 {
789 EXPECT_CALL(*clientMock_, GetProcessRunningInfosByUserId(_, _)).Times(1);
790 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
791 ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_, nullptr);
792 std::vector<AppExecFwk::RunningProcessInfo> info;
793 int32_t userId = 0;
794 DelayedSingleton<AppScheduler>::GetInstance()->GetProcessRunningInfosByUserId(info, userId);
795 }
796
797 /*
798 * Feature: AppScheduler
799 * Function: ConvertAppState
800 * SubFunction: NA
801 * FunctionPoints: AppScheduler ConvertAppState
802 * EnvConditions: NA
803 * CaseDescription: Verify ConvertAppState
804 */
HWTEST_F(AppSchedulerTest, AppScheduler_ConvertAppState_001, TestSize.Level1)805 HWTEST_F(AppSchedulerTest, AppScheduler_ConvertAppState_001, TestSize.Level1)
806 {
807 AppState state = AppState::BEGIN;
808 ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance(), nullptr);
809 DelayedSingleton<AppScheduler>::GetInstance()->ConvertAppState(state);
810 }
811
812 /*
813 * Feature: AppScheduler
814 * Function: StartUserTest
815 * SubFunction: NA
816 * FunctionPoints: AppScheduler StartUserTest
817 * EnvConditions: NA
818 * CaseDescription: Verify StartUserTest
819 */
HWTEST_F(AppSchedulerTest, AppScheduler_StartUserTest_001, TestSize.Level1)820 HWTEST_F(AppSchedulerTest, AppScheduler_StartUserTest_001, TestSize.Level1)
821 {
822 EXPECT_CALL(*clientMock_, StartUserTestProcess(_, _, _, _)).Times(1)
823 .WillOnce(Return(AppMgrResultCode::RESULT_OK));
824 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
825 Want want;
826 sptr<IRemoteObject> observer;
827 AppExecFwk::BundleInfo bundleInfo;
828 int32_t userId = 0;
829 int res = DelayedSingleton<AppScheduler>::GetInstance()->StartUserTest(want, observer, bundleInfo, userId);
830 EXPECT_EQ(res, ERR_OK);
831 }
832
833 /*
834 * Feature: AppScheduler
835 * Function: StartUserTest
836 * SubFunction: NA
837 * FunctionPoints: AppScheduler StartUserTest
838 * EnvConditions: NA
839 * CaseDescription: Verify StartUserTest
840 */
HWTEST_F(AppSchedulerTest, AppScheduler_StartUserTest_002, TestSize.Level1)841 HWTEST_F(AppSchedulerTest, AppScheduler_StartUserTest_002, TestSize.Level1)
842 {
843 EXPECT_CALL(*clientMock_, StartUserTestProcess(_, _, _, _)).Times(1)
844 .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY));
845 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
846 Want want;
847 sptr<IRemoteObject> observer;
848 AppExecFwk::BundleInfo bundleInfo;
849 int32_t userId = 0;
850 int res = DelayedSingleton<AppScheduler>::GetInstance()->StartUserTest(want, observer, bundleInfo, userId);
851 EXPECT_EQ(res, INNER_ERR);
852 }
853
854 /*
855 * Feature: AppScheduler
856 * Function: FinishUserTest
857 * SubFunction: NA
858 * FunctionPoints: AppScheduler FinishUserTest
859 * EnvConditions: NA
860 * CaseDescription: Verify FinishUserTest
861 */
HWTEST_F(AppSchedulerTest, AppScheduler_FinishUserTest_001, TestSize.Level1)862 HWTEST_F(AppSchedulerTest, AppScheduler_FinishUserTest_001, TestSize.Level1)
863 {
864 EXPECT_CALL(*clientMock_, FinishUserTest(_, _, _)).Times(1)
865 .WillOnce(Return(AppMgrResultCode::RESULT_OK));
866 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
867 std::string msg = "msg";
868 int64_t resultCode = 0;
869 std::string bundleName = "bundleName";
870 int res = DelayedSingleton<AppScheduler>::GetInstance()->FinishUserTest(msg, resultCode, bundleName);
871 EXPECT_EQ(res, ERR_OK);
872 }
873
874 /*
875 * Feature: AppScheduler
876 * Function: FinishUserTest
877 * SubFunction: NA
878 * FunctionPoints: AppScheduler FinishUserTest
879 * EnvConditions: NA
880 * CaseDescription: Verify FinishUserTest
881 */
HWTEST_F(AppSchedulerTest, AppScheduler_FinishUserTest_002, TestSize.Level1)882 HWTEST_F(AppSchedulerTest, AppScheduler_FinishUserTest_002, TestSize.Level1)
883 {
884 EXPECT_CALL(*clientMock_, FinishUserTest(_, _, _)).Times(1)
885 .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY));
886 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
887 std::string msg = "msg";
888 int64_t resultCode = 0;
889 std::string bundleName = "bundleName";
890 int res = DelayedSingleton<AppScheduler>::GetInstance()->FinishUserTest(msg, resultCode, bundleName);
891 EXPECT_EQ(res, INNER_ERR);
892 }
893
894 /*
895 * Feature: AppScheduler
896 * Function: UpdateConfiguration
897 * SubFunction: NA
898 * FunctionPoints: AppScheduler UpdateConfiguration
899 * EnvConditions: NA
900 * CaseDescription: Verify UpdateConfiguration
901 */
HWTEST_F(AppSchedulerTest, AppScheduler_UpdateConfiguration_001, TestSize.Level1)902 HWTEST_F(AppSchedulerTest, AppScheduler_UpdateConfiguration_001, TestSize.Level1)
903 {
904 EXPECT_CALL(*clientMock_, UpdateConfiguration(_, _)).Times(1)
905 .WillOnce(Return(AppMgrResultCode::RESULT_OK));
906 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
907 AppExecFwk::Configuration config;
908 int res = DelayedSingleton<AppScheduler>::GetInstance()->UpdateConfiguration(config);
909 EXPECT_EQ(res, ERR_OK);
910 }
911
912 /*
913 * Feature: AppScheduler
914 * Function: UpdateConfiguration
915 * SubFunction: NA
916 * FunctionPoints: AppScheduler UpdateConfiguration
917 * EnvConditions: NA
918 * CaseDescription: Verify UpdateConfiguration
919 */
HWTEST_F(AppSchedulerTest, AppScheduler_UpdateConfiguration_002, TestSize.Level1)920 HWTEST_F(AppSchedulerTest, AppScheduler_UpdateConfiguration_002, TestSize.Level1)
921 {
922 EXPECT_CALL(*clientMock_, UpdateConfiguration(_, _)).Times(1)
923 .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY));
924 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
925 AppExecFwk::Configuration config;
926 int res = DelayedSingleton<AppScheduler>::GetInstance()->UpdateConfiguration(config);
927 EXPECT_EQ(res, INNER_ERR);
928 }
929
930 /*
931 * Feature: AppScheduler
932 * Function: GetConfiguration
933 * SubFunction: NA
934 * FunctionPoints: AppScheduler GetConfiguration
935 * EnvConditions: NA
936 * CaseDescription: Verify GetConfiguration
937 */
HWTEST_F(AppSchedulerTest, AppScheduler_GetConfiguration_001, TestSize.Level1)938 HWTEST_F(AppSchedulerTest, AppScheduler_GetConfiguration_001, TestSize.Level1)
939 {
940 EXPECT_CALL(*clientMock_, GetConfiguration(_)).Times(1)
941 .WillOnce(Return(AppMgrResultCode::RESULT_OK));
942 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
943 AppExecFwk::Configuration config;
944 int res = DelayedSingleton<AppScheduler>::GetInstance()->GetConfiguration(config);
945 EXPECT_EQ(res, ERR_OK);
946 }
947
948 /*
949 * Feature: AppScheduler
950 * Function: GetConfiguration
951 * SubFunction: NA
952 * FunctionPoints: AppScheduler GetConfiguration
953 * EnvConditions: NA
954 * CaseDescription: Verify GetConfiguration
955 */
HWTEST_F(AppSchedulerTest, AppScheduler_GetConfiguration_002, TestSize.Level1)956 HWTEST_F(AppSchedulerTest, AppScheduler_GetConfiguration_002, TestSize.Level1)
957 {
958 EXPECT_CALL(*clientMock_, GetConfiguration(_)).Times(1)
959 .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY));
960 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
961 AppExecFwk::Configuration config;
962 int res = DelayedSingleton<AppScheduler>::GetInstance()->GetConfiguration(config);
963 EXPECT_EQ(res, INNER_ERR);
964 }
965
966 /*
967 * Feature: AppScheduler
968 * Function: GetAbilityRecordsByProcessID
969 * SubFunction: NA
970 * FunctionPoints: AppScheduler GetAbilityRecordsByProcessID
971 * EnvConditions: NA
972 * CaseDescription: Verify GetAbilityRecordsByProcessID
973 */
HWTEST_F(AppSchedulerTest, AppScheduler_GetAbilityRecordsByProcessID_001, TestSize.Level1)974 HWTEST_F(AppSchedulerTest, AppScheduler_GetAbilityRecordsByProcessID_001, TestSize.Level1)
975 {
976 EXPECT_CALL(*clientMock_, GetAbilityRecordsByProcessID(_, _)).Times(1)
977 .WillOnce(Return(AppMgrResultCode::RESULT_OK));
978 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
979 int pid = 0;
980 std::vector<sptr<IRemoteObject>> tokens;
981 int res = DelayedSingleton<AppScheduler>::GetInstance()->GetAbilityRecordsByProcessID(pid, tokens);
982 EXPECT_EQ(res, ERR_OK);
983 }
984
985 /*
986 * Feature: AppScheduler
987 * Function: GetAbilityRecordsByProcessID
988 * SubFunction: NA
989 * FunctionPoints: AppScheduler GetAbilityRecordsByProcessID
990 * EnvConditions: NA
991 * CaseDescription: Verify GetAbilityRecordsByProcessID
992 */
HWTEST_F(AppSchedulerTest, AppScheduler_GetAbilityRecordsByProcessID_002, TestSize.Level1)993 HWTEST_F(AppSchedulerTest, AppScheduler_GetAbilityRecordsByProcessID_002, TestSize.Level1)
994 {
995 EXPECT_CALL(*clientMock_, GetAbilityRecordsByProcessID(_, _)).Times(1)
996 .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY));
997 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
998 int pid = 0;
999 std::vector<sptr<IRemoteObject>> tokens;
1000 int res = DelayedSingleton<AppScheduler>::GetInstance()->GetAbilityRecordsByProcessID(pid, tokens);
1001 EXPECT_EQ(res, INNER_ERR);
1002 clientMock_.reset();
1003 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_.reset();
1004 }
1005
1006 /**
1007 * @tc.name: SetCurrentUserId_001
1008 * @tc.desc: set current userId.
1009 * @tc.type: FUNC
1010 */
HWTEST_F(AppSchedulerTest, AppScheduler_SetCurrentUserId_001, TestSize.Level1)1011 HWTEST_F(AppSchedulerTest, AppScheduler_SetCurrentUserId_001, TestSize.Level1)
1012 {
1013 int32_t userId = 0;
1014 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::make_unique<AppExecFwk::AppMgrClient>();
1015 ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_, nullptr);
1016 DelayedSingleton<AppScheduler>::GetInstance()->SetCurrentUserId(userId);
1017 }
1018
1019 /**
1020 * @tc.name: AppScheduler_NotifyFault_001
1021 * @tc.desc: Verify that the NotifyFault interface calls normally
1022 * @tc.type: FUNC
1023 */
HWTEST_F(AppSchedulerTest, AppScheduler_NotifyFault_001, TestSize.Level1)1024 HWTEST_F(AppSchedulerTest, AppScheduler_NotifyFault_001, TestSize.Level1)
1025 {
1026 AppExecFwk::FaultData faultData;
1027 int res = DelayedSingleton<AppScheduler>::GetInstance()->NotifyFault(faultData);
1028 EXPECT_EQ(res, INNER_ERR);
1029 }
1030
1031 /**
1032 * @tc.name: AppScheduler_RegisterAppDebugListener_001
1033 * @tc.desc: Test the state of RegisterAppDebugListener
1034 * @tc.type: FUNC
1035 */
HWTEST_F(AppSchedulerTest, AppScheduler_RegisterAppDebugListener_001, TestSize.Level1)1036 HWTEST_F(AppSchedulerTest, AppScheduler_RegisterAppDebugListener_001, TestSize.Level1)
1037 {
1038 sptr<AppExecFwk::IAppDebugListener> listener = nullptr;
1039 int res = DelayedSingleton<AppScheduler>::GetInstance()->RegisterAppDebugListener(listener);
1040 EXPECT_EQ(res, INNER_ERR);
1041 }
1042
1043 /**
1044 * @tc.name: AppScheduler_RegisterAppDebugListener_002
1045 * @tc.desc: Test the state of RegisterAppDebugListener
1046 * @tc.type: FUNC
1047 */
HWTEST_F(AppSchedulerTest, AppScheduler_RegisterAppDebugListener_002, TestSize.Level1)1048 HWTEST_F(AppSchedulerTest, AppScheduler_RegisterAppDebugListener_002, TestSize.Level1)
1049 {
1050 AAFwk::IsMockSaCall::IsMockSaCallWithPermission();
1051 auto listener = new AppDebugListenerStubMock();
1052 int res = DelayedSingleton<AppScheduler>::GetInstance()->RegisterAppDebugListener(listener);
1053 EXPECT_EQ(res, ERR_OK);
1054 }
1055
1056 /**
1057 * @tc.name: AppScheduler_UnregisterAppDebugListener_001
1058 * @tc.desc: Test the state of UnregisterAppDebugListener
1059 * @tc.type: FUNC
1060 */
HWTEST_F(AppSchedulerTest, AppScheduler_UnregisterAppDebugListener_001, TestSize.Level1)1061 HWTEST_F(AppSchedulerTest, AppScheduler_UnregisterAppDebugListener_001, TestSize.Level1)
1062 {
1063 sptr<AppExecFwk::IAppDebugListener> listener = nullptr;
1064 int res = DelayedSingleton<AppScheduler>::GetInstance()->UnregisterAppDebugListener(listener);
1065 EXPECT_EQ(res, INNER_ERR);
1066 }
1067
1068 /**
1069 * @tc.name: AppScheduler_UnregisterAppDebugListener_002
1070 * @tc.desc: Test the state of UnregisterAppDebugListener
1071 * @tc.type: FUNC
1072 */
HWTEST_F(AppSchedulerTest, AppScheduler_UnregisterAppDebugListener_002, TestSize.Level1)1073 HWTEST_F(AppSchedulerTest, AppScheduler_UnregisterAppDebugListener_002, TestSize.Level1)
1074 {
1075 AAFwk::IsMockSaCall::IsMockSaCallWithPermission();
1076 auto listener = new AppDebugListenerStubMock();
1077 int res = DelayedSingleton<AppScheduler>::GetInstance()->UnregisterAppDebugListener(listener);
1078 EXPECT_EQ(res, ERR_OK);
1079 }
1080
1081 /**
1082 * @tc.name: AppScheduler_AttachAppDebug_001
1083 * @tc.desc: Test the state of AttachAppDebug
1084 * @tc.type: FUNC
1085 */
HWTEST_F(AppSchedulerTest, AppScheduler_AttachAppDebug_001, TestSize.Level1)1086 HWTEST_F(AppSchedulerTest, AppScheduler_AttachAppDebug_001, TestSize.Level1)
1087 {
1088 AAFwk::IsMockSaCall::IsMockSpecificSystemAbilityAccessPermission();
1089 std::string bundleName = "bundleName";
1090 int res = DelayedSingleton<AppScheduler>::GetInstance()->AttachAppDebug(bundleName);
1091 EXPECT_EQ(res, ERR_OK);
1092 }
1093
1094 /**
1095 * @tc.name: AppScheduler_DetachAppDebug_001
1096 * @tc.desc: Test the state of DetachAppDebug
1097 * @tc.type: FUNC
1098 */
HWTEST_F(AppSchedulerTest, AppScheduler_DetachAppDebug_001, TestSize.Level1)1099 HWTEST_F(AppSchedulerTest, AppScheduler_DetachAppDebug_001, TestSize.Level1)
1100 {
1101 std::string bundleName = "bundleName";
1102 int res = DelayedSingleton<AppScheduler>::GetInstance()->DetachAppDebug(bundleName);
1103 EXPECT_EQ(res, ERR_OK);
1104 }
1105
1106 /**
1107 * @tc.name: AppScheduler_RegisterAbilityDebugResponse_001
1108 * @tc.desc: Test the state of RegisterAbilityDebugResponse
1109 * @tc.type: FUNC
1110 */
HWTEST_F(AppSchedulerTest, AppScheduler_RegisterAbilityDebugResponse_001, TestSize.Level1)1111 HWTEST_F(AppSchedulerTest, AppScheduler_RegisterAbilityDebugResponse_001, TestSize.Level1)
1112 {
1113 sptr<AppExecFwk::IAbilityDebugResponse> response = nullptr;
1114 int res = DelayedSingleton<AppScheduler>::GetInstance()->RegisterAbilityDebugResponse(response);
1115 EXPECT_EQ(res, INNER_ERR);
1116 }
1117 } // namespace AAFwk
1118 } // namespace OHOS
1119