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, INNER_ERR);
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: KillApplicationByUid
653 * SubFunction: NA
654 * FunctionPoints: AppScheduler KillApplicationByUid
655 * EnvConditions: NA
656 * CaseDescription: Verify KillApplicationByUid
657 */
658 HWTEST_F(AppSchedulerTest, AppScheduler_KillApplicationByUid_001, TestSize.Level1)
659 {
660 EXPECT_CALL(*clientMock_, KillApplicationByUid(_, _, _)).Times(1)
661 .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY));
662 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
663 std::string bundleName = "bundleName";
664 int32_t uid = 0;
665 int res = DelayedSingleton<AppScheduler>::GetInstance()->KillApplicationByUid(bundleName, uid);
666 EXPECT_EQ(res, INNER_ERR);
667 }
668
669 /*
670 * Feature: AppScheduler
671 * Function: KillApplicationByUid
672 * SubFunction: NA
673 * FunctionPoints: AppScheduler KillApplicationByUid
674 * EnvConditions: NA
675 * CaseDescription: Verify KillApplicationByUid
676 */
677 HWTEST_F(AppSchedulerTest, AppScheduler_KillApplicationByUid_002, TestSize.Level1)
678 {
679 EXPECT_CALL(*clientMock_, KillApplicationByUid(_, _, _)).Times(1)
680 .WillOnce(Return(AppMgrResultCode::RESULT_OK));
681 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
682 std::string bundleName = "bundleName";
683 int32_t uid = 0;
684 int res = DelayedSingleton<AppScheduler>::GetInstance()->KillApplicationByUid(bundleName, uid);
685 EXPECT_EQ(res, ERR_OK);
686 }
687
688 /*
689 * Feature: AppScheduler
690 * Function: PrepareTerminate
691 * SubFunction: NA
692 * FunctionPoints: AppScheduler PrepareTerminate
693 * EnvConditions: NA
694 * CaseDescription: Verify PrepareTerminate
695 */
696 HWTEST_F(AppSchedulerTest, AppScheduler_PrepareTerminate_001, TestSize.Level1)
697 {
698 sptr<IRemoteObject> token = nullptr;
699 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::make_unique<AppExecFwk::AppMgrClient>();
700 ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_, nullptr);
701 DelayedSingleton<AppScheduler>::GetInstance()->PrepareTerminate(token);
702 }
703
704 /*
705 * Feature: AppScheduler
706 * Function: OnAppStateChanged
707 * SubFunction: NA
708 * FunctionPoints: AppScheduler OnAppStateChanged
709 * EnvConditions: NA
710 * CaseDescription: Verify OnAppStateChanged
711 */
712 HWTEST_F(AppSchedulerTest, AppScheduler_OnAppStateChanged_001, TestSize.Level1)
713 {
714 AppExecFwk::AppProcessData appData;
715 ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance(), nullptr);
716 DelayedSingleton<AppScheduler>::GetInstance()->OnAppStateChanged(appData);
717 }
718
719 /*
720 * Feature: AppScheduler
721 * Function: GetRunningProcessInfoByToken
722 * SubFunction: NA
723 * FunctionPoints: AppScheduler GetRunningProcessInfoByToken
724 * EnvConditions: NA
725 * CaseDescription: Verify GetRunningProcessInfoByToken
726 */
727 HWTEST_F(AppSchedulerTest, AppScheduler_GetRunningProcessInfoByToken_001, TestSize.Level1)
728 {
729 sptr<IRemoteObject> token;
730 AppExecFwk::RunningProcessInfo info;
731 ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance(), nullptr);
732 DelayedSingleton<AppScheduler>::GetInstance()->GetRunningProcessInfoByToken(token, info);
733 }
734
735 /*
736 * Feature: AppScheduler
737 * Function: GetRunningProcessInfoByPid
738 * SubFunction: NA
739 * FunctionPoints: AppScheduler GetRunningProcessInfoByPid
740 * EnvConditions: NA
741 * CaseDescription: Verify GetRunningProcessInfoByPid
742 */
743 HWTEST_F(AppSchedulerTest, AppScheduler_GetRunningProcessInfoByPid_001, TestSize.Level1)
744 {
745 pid_t pid = 0;
746 AppExecFwk::RunningProcessInfo info;
747 ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance(), nullptr);
748 DelayedSingleton<AppScheduler>::GetInstance()->GetRunningProcessInfoByPid(pid, info);
749 }
750
751 /*
752 * Feature: AppScheduler
753 * Function: StartupResidentProcess
754 * SubFunction: NA
755 * FunctionPoints: AppScheduler StartupResidentProcess
756 * EnvConditions: NA
757 * CaseDescription: Verify StartupResidentProcess
758 */
759 HWTEST_F(AppSchedulerTest, AppScheduler_StartupResidentProcess_001, TestSize.Level1)
760 {
761 EXPECT_CALL(*clientMock_, StartupResidentProcess(_)).Times(1);
762 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
763 ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_, nullptr);
764 std::vector<AppExecFwk::BundleInfo> bundleInfos;
765 DelayedSingleton<AppScheduler>::GetInstance()->StartupResidentProcess(bundleInfos);
766 }
767
768 /*
769 * Feature: AppScheduler
770 * Function: StartSpecifiedAbility
771 * SubFunction: NA
772 * FunctionPoints: AppScheduler StartSpecifiedAbility
773 * EnvConditions: NA
774 * CaseDescription: Verify StartSpecifiedAbility
775 */
776 HWTEST_F(AppSchedulerTest, AppScheduler_StartSpecifiedAbility_001, TestSize.Level1)
777 {
778 EXPECT_CALL(*clientMock_, StartSpecifiedAbility(_, _, _)).Times(1);
779 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
780 ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_, nullptr);
781 AAFwk::Want want;
782 AppExecFwk::AbilityInfo abilityInfo;
783 DelayedSingleton<AppScheduler>::GetInstance()->StartSpecifiedAbility(want, abilityInfo);
784 }
785
786 /*
787 * Feature: AppScheduler
788 * Function: GetProcessRunningInfos
789 * SubFunction: NA
790 * FunctionPoints: AppScheduler GetProcessRunningInfos
791 * EnvConditions: NA
792 * CaseDescription: Verify GetProcessRunningInfos
793 */
794 HWTEST_F(AppSchedulerTest, AppScheduler_GetProcessRunningInfos_001, TestSize.Level1)
795 {
796 EXPECT_CALL(*clientMock_, GetAllRunningProcesses(_)).Times(1);
797 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
798 ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_, nullptr);
799 std::vector<AppExecFwk::RunningProcessInfo> info;
800 DelayedSingleton<AppScheduler>::GetInstance()->GetProcessRunningInfos(info);
801 }
802
803 /*
804 * Feature: AppScheduler
805 * Function: GetProcessRunningInfosByUserId
806 * SubFunction: NA
807 * FunctionPoints: AppScheduler GetProcessRunningInfosByUserId
808 * EnvConditions: NA
809 * CaseDescription: Verify GetProcessRunningInfosByUserId
810 */
811 HWTEST_F(AppSchedulerTest, AppScheduler_GetProcessRunningInfosByUserId_001, TestSize.Level1)
812 {
813 EXPECT_CALL(*clientMock_, GetProcessRunningInfosByUserId(_, _)).Times(1);
814 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
815 ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_, nullptr);
816 std::vector<AppExecFwk::RunningProcessInfo> info;
817 int32_t userId = 0;
818 DelayedSingleton<AppScheduler>::GetInstance()->GetProcessRunningInfosByUserId(info, userId);
819 }
820
821 /*
822 * Feature: AppScheduler
823 * Function: ConvertAppState
824 * SubFunction: NA
825 * FunctionPoints: AppScheduler ConvertAppState
826 * EnvConditions: NA
827 * CaseDescription: Verify ConvertAppState
828 */
829 HWTEST_F(AppSchedulerTest, AppScheduler_ConvertAppState_001, TestSize.Level1)
830 {
831 AppState state = AppState::BEGIN;
832 ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance(), nullptr);
833 DelayedSingleton<AppScheduler>::GetInstance()->ConvertAppState(state);
834 }
835
836 /*
837 * Feature: AppScheduler
838 * Function: StartUserTest
839 * SubFunction: NA
840 * FunctionPoints: AppScheduler StartUserTest
841 * EnvConditions: NA
842 * CaseDescription: Verify StartUserTest
843 */
844 HWTEST_F(AppSchedulerTest, AppScheduler_StartUserTest_001, TestSize.Level1)
845 {
846 EXPECT_CALL(*clientMock_, StartUserTestProcess(_, _, _, _)).Times(1)
847 .WillOnce(Return(AppMgrResultCode::RESULT_OK));
848 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
849 Want want;
850 sptr<IRemoteObject> observer;
851 AppExecFwk::BundleInfo bundleInfo;
852 int32_t userId = 0;
853 int res = DelayedSingleton<AppScheduler>::GetInstance()->StartUserTest(want, observer, bundleInfo, userId);
854 EXPECT_EQ(res, ERR_OK);
855 }
856
857 /*
858 * Feature: AppScheduler
859 * Function: StartUserTest
860 * SubFunction: NA
861 * FunctionPoints: AppScheduler StartUserTest
862 * EnvConditions: NA
863 * CaseDescription: Verify StartUserTest
864 */
865 HWTEST_F(AppSchedulerTest, AppScheduler_StartUserTest_002, TestSize.Level1)
866 {
867 EXPECT_CALL(*clientMock_, StartUserTestProcess(_, _, _, _)).Times(1)
868 .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY));
869 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
870 Want want;
871 sptr<IRemoteObject> observer;
872 AppExecFwk::BundleInfo bundleInfo;
873 int32_t userId = 0;
874 int res = DelayedSingleton<AppScheduler>::GetInstance()->StartUserTest(want, observer, bundleInfo, userId);
875 EXPECT_EQ(res, INNER_ERR);
876 }
877
878 /*
879 * Feature: AppScheduler
880 * Function: FinishUserTest
881 * SubFunction: NA
882 * FunctionPoints: AppScheduler FinishUserTest
883 * EnvConditions: NA
884 * CaseDescription: Verify FinishUserTest
885 */
886 HWTEST_F(AppSchedulerTest, AppScheduler_FinishUserTest_001, TestSize.Level1)
887 {
888 EXPECT_CALL(*clientMock_, FinishUserTest(_, _, _)).Times(1)
889 .WillOnce(Return(AppMgrResultCode::RESULT_OK));
890 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
891 std::string msg = "msg";
892 int64_t resultCode = 0;
893 std::string bundleName = "bundleName";
894 int res = DelayedSingleton<AppScheduler>::GetInstance()->FinishUserTest(msg, resultCode, bundleName);
895 EXPECT_EQ(res, ERR_OK);
896 }
897
898 /*
899 * Feature: AppScheduler
900 * Function: FinishUserTest
901 * SubFunction: NA
902 * FunctionPoints: AppScheduler FinishUserTest
903 * EnvConditions: NA
904 * CaseDescription: Verify FinishUserTest
905 */
906 HWTEST_F(AppSchedulerTest, AppScheduler_FinishUserTest_002, TestSize.Level1)
907 {
908 EXPECT_CALL(*clientMock_, FinishUserTest(_, _, _)).Times(1)
909 .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY));
910 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
911 std::string msg = "msg";
912 int64_t resultCode = 0;
913 std::string bundleName = "bundleName";
914 int res = DelayedSingleton<AppScheduler>::GetInstance()->FinishUserTest(msg, resultCode, bundleName);
915 EXPECT_EQ(res, INNER_ERR);
916 }
917
918 /*
919 * Feature: AppScheduler
920 * Function: UpdateConfiguration
921 * SubFunction: NA
922 * FunctionPoints: AppScheduler UpdateConfiguration
923 * EnvConditions: NA
924 * CaseDescription: Verify UpdateConfiguration
925 */
926 HWTEST_F(AppSchedulerTest, AppScheduler_UpdateConfiguration_001, TestSize.Level1)
927 {
928 EXPECT_CALL(*clientMock_, UpdateConfiguration(_, _)).Times(1)
929 .WillOnce(Return(AppMgrResultCode::RESULT_OK));
930 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
931 AppExecFwk::Configuration config;
932 int res = DelayedSingleton<AppScheduler>::GetInstance()->UpdateConfiguration(config);
933 EXPECT_EQ(res, ERR_OK);
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_002, TestSize.Level1)
945 {
946 EXPECT_CALL(*clientMock_, UpdateConfiguration(_, _)).Times(1)
947 .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY));
948 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
949 AppExecFwk::Configuration config;
950 int res = DelayedSingleton<AppScheduler>::GetInstance()->UpdateConfiguration(config);
951 EXPECT_EQ(res, INNER_ERR);
952 }
953
954 /*
955 * Feature: AppScheduler
956 * Function: GetConfiguration
957 * SubFunction: NA
958 * FunctionPoints: AppScheduler GetConfiguration
959 * EnvConditions: NA
960 * CaseDescription: Verify GetConfiguration
961 */
962 HWTEST_F(AppSchedulerTest, AppScheduler_GetConfiguration_001, TestSize.Level1)
963 {
964 EXPECT_CALL(*clientMock_, GetConfiguration(_)).Times(1)
965 .WillOnce(Return(AppMgrResultCode::RESULT_OK));
966 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
967 AppExecFwk::Configuration config;
968 int res = DelayedSingleton<AppScheduler>::GetInstance()->GetConfiguration(config);
969 EXPECT_EQ(res, ERR_OK);
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_002, TestSize.Level1)
981 {
982 EXPECT_CALL(*clientMock_, GetConfiguration(_)).Times(1)
983 .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY));
984 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
985 AppExecFwk::Configuration config;
986 int res = DelayedSingleton<AppScheduler>::GetInstance()->GetConfiguration(config);
987 EXPECT_EQ(res, INNER_ERR);
988 }
989
990 /*
991 * Feature: AppScheduler
992 * Function: GetAbilityRecordsByProcessID
993 * SubFunction: NA
994 * FunctionPoints: AppScheduler GetAbilityRecordsByProcessID
995 * EnvConditions: NA
996 * CaseDescription: Verify GetAbilityRecordsByProcessID
997 */
998 HWTEST_F(AppSchedulerTest, AppScheduler_GetAbilityRecordsByProcessID_001, TestSize.Level1)
999 {
1000 EXPECT_CALL(*clientMock_, GetAbilityRecordsByProcessID(_, _)).Times(1)
1001 .WillOnce(Return(AppMgrResultCode::RESULT_OK));
1002 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
1003 int pid = 0;
1004 std::vector<sptr<IRemoteObject>> tokens;
1005 int res = DelayedSingleton<AppScheduler>::GetInstance()->GetAbilityRecordsByProcessID(pid, tokens);
1006 EXPECT_EQ(res, ERR_OK);
1007 }
1008
1009 /*
1010 * Feature: AppScheduler
1011 * Function: GetAbilityRecordsByProcessID
1012 * SubFunction: NA
1013 * FunctionPoints: AppScheduler GetAbilityRecordsByProcessID
1014 * EnvConditions: NA
1015 * CaseDescription: Verify GetAbilityRecordsByProcessID
1016 */
1017 HWTEST_F(AppSchedulerTest, AppScheduler_GetAbilityRecordsByProcessID_002, TestSize.Level1)
1018 {
1019 EXPECT_CALL(*clientMock_, GetAbilityRecordsByProcessID(_, _)).Times(1)
1020 .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY));
1021 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
1022 int pid = 0;
1023 std::vector<sptr<IRemoteObject>> tokens;
1024 int res = DelayedSingleton<AppScheduler>::GetInstance()->GetAbilityRecordsByProcessID(pid, tokens);
1025 EXPECT_EQ(res, INNER_ERR);
1026 clientMock_.reset();
1027 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_.reset();
1028 }
1029
1030 /**
1031 * @tc.name: SetCurrentUserId_001
1032 * @tc.desc: set current userId.
1033 * @tc.type: FUNC
1034 */
1035 HWTEST_F(AppSchedulerTest, AppScheduler_SetCurrentUserId_001, TestSize.Level1)
1036 {
1037 int32_t userId = 0;
1038 DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::make_unique<AppExecFwk::AppMgrClient>();
1039 ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_, nullptr);
1040 DelayedSingleton<AppScheduler>::GetInstance()->SetCurrentUserId(userId);
1041 }
1042
1043 /**
1044 * @tc.name: AppScheduler_NotifyFault_001
1045 * @tc.desc: Verify that the NotifyFault interface calls normally
1046 * @tc.type: FUNC
1047 */
1048 HWTEST_F(AppSchedulerTest, AppScheduler_NotifyFault_001, TestSize.Level1)
1049 {
1050 AppExecFwk::FaultData faultData;
1051 int res = DelayedSingleton<AppScheduler>::GetInstance()->NotifyFault(faultData);
1052 EXPECT_EQ(res, INNER_ERR);
1053 }
1054
1055 /**
1056 * @tc.name: AppScheduler_RegisterAppDebugListener_001
1057 * @tc.desc: Test the state of RegisterAppDebugListener
1058 * @tc.type: FUNC
1059 */
1060 HWTEST_F(AppSchedulerTest, AppScheduler_RegisterAppDebugListener_001, TestSize.Level1)
1061 {
1062 sptr<AppExecFwk::IAppDebugListener> listener = nullptr;
1063 int res = DelayedSingleton<AppScheduler>::GetInstance()->RegisterAppDebugListener(listener);
1064 EXPECT_EQ(res, INNER_ERR);
1065 }
1066
1067 /**
1068 * @tc.name: AppScheduler_RegisterAppDebugListener_002
1069 * @tc.desc: Test the state of RegisterAppDebugListener
1070 * @tc.type: FUNC
1071 */
1072 HWTEST_F(AppSchedulerTest, AppScheduler_RegisterAppDebugListener_002, TestSize.Level1)
1073 {
1074 AAFwk::IsMockSaCall::IsMockSaCallWithPermission();
1075 auto listener = new AppDebugListenerStubMock();
1076 int res = DelayedSingleton<AppScheduler>::GetInstance()->RegisterAppDebugListener(listener);
1077 EXPECT_EQ(res, ERR_OK);
1078 }
1079
1080 /**
1081 * @tc.name: AppScheduler_UnregisterAppDebugListener_001
1082 * @tc.desc: Test the state of UnregisterAppDebugListener
1083 * @tc.type: FUNC
1084 */
1085 HWTEST_F(AppSchedulerTest, AppScheduler_UnregisterAppDebugListener_001, TestSize.Level1)
1086 {
1087 sptr<AppExecFwk::IAppDebugListener> listener = nullptr;
1088 int res = DelayedSingleton<AppScheduler>::GetInstance()->UnregisterAppDebugListener(listener);
1089 EXPECT_EQ(res, INNER_ERR);
1090 }
1091
1092 /**
1093 * @tc.name: AppScheduler_UnregisterAppDebugListener_002
1094 * @tc.desc: Test the state of UnregisterAppDebugListener
1095 * @tc.type: FUNC
1096 */
1097 HWTEST_F(AppSchedulerTest, AppScheduler_UnregisterAppDebugListener_002, TestSize.Level1)
1098 {
1099 AAFwk::IsMockSaCall::IsMockSaCallWithPermission();
1100 auto listener = new AppDebugListenerStubMock();
1101 int res = DelayedSingleton<AppScheduler>::GetInstance()->UnregisterAppDebugListener(listener);
1102 EXPECT_EQ(res, ERR_OK);
1103 }
1104
1105 /**
1106 * @tc.name: AppScheduler_AttachAppDebug_001
1107 * @tc.desc: Test the state of AttachAppDebug
1108 * @tc.type: FUNC
1109 */
1110 HWTEST_F(AppSchedulerTest, AppScheduler_AttachAppDebug_001, TestSize.Level1)
1111 {
1112 AAFwk::IsMockSaCall::IsMockSpecificSystemAbilityAccessPermission();
1113 std::string bundleName = "bundleName";
1114 int res = DelayedSingleton<AppScheduler>::GetInstance()->AttachAppDebug(bundleName, false);
1115 EXPECT_EQ(res, ERR_OK);
1116 }
1117
1118 /**
1119 * @tc.name: AppScheduler_DetachAppDebug_001
1120 * @tc.desc: Test the state of DetachAppDebug
1121 * @tc.type: FUNC
1122 */
1123 HWTEST_F(AppSchedulerTest, AppScheduler_DetachAppDebug_001, TestSize.Level1)
1124 {
1125 std::string bundleName = "bundleName";
1126 int res = DelayedSingleton<AppScheduler>::GetInstance()->DetachAppDebug(bundleName);
1127 EXPECT_EQ(res, ERR_OK);
1128 }
1129
1130 /**
1131 * @tc.name: AppScheduler_RegisterAbilityDebugResponse_001
1132 * @tc.desc: Test the state of RegisterAbilityDebugResponse
1133 * @tc.type: FUNC
1134 */
1135 HWTEST_F(AppSchedulerTest, AppScheduler_RegisterAbilityDebugResponse_001, TestSize.Level1)
1136 {
1137 sptr<AppExecFwk::IAbilityDebugResponse> response = nullptr;
1138 int res = DelayedSingleton<AppScheduler>::GetInstance()->RegisterAbilityDebugResponse(response);
1139 EXPECT_EQ(res, INNER_ERR);
1140 }
1141 } // namespace AAFwk
1142 } // namespace OHOS
1143