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