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