• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 
18 #include "ability_manager_errors.h"
19 #define private public
20 #define protected public
21 #include "ability_record.h"
22 #include "app_scheduler.h"
23 #undef private
24 #undef protected
25 #include "app_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     ASSERT_NE(token, nullptr);
341 
342     DelayedSingleton<AppScheduler>::GetInstance()->MoveToForeground(token);
343 }
344 
345 /*
346  * Feature: AppScheduler
347  * Function: MoveToForeground
348  * SubFunction: NA
349  * FunctionPoints: AppScheduler MoveToForeground
350  * EnvConditions:NA
351  * CaseDescription: Verify the normal process of movetoforground
352  */
353 HWTEST_F(AppSchedulerTest, AppScheduler_oprator_009, TestSize.Level1)
354 {
355     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::make_unique<AppExecFwk::AppMgrClient>();
356 
357     std::string deviceName = "device";
358     std::string abilityName = "FirstAbility";
359     std::string appName = "FirstApp";
360     std::string bundleName = "com.ix.First.Test";
361     auto abilityReq = GenerateAbilityRequest(deviceName, abilityName, appName, bundleName);
362     auto record = AbilityRecord::CreateAbilityRecord(abilityReq);
363     auto token = record->GetToken();
364     ASSERT_NE(token, nullptr);
365 
366     DelayedSingleton<AppScheduler>::GetInstance()->MoveToForeground(token);
367 }
368 
369 /*
370  * Feature: AppScheduler
371  * Function: MoveToBackground
372  * SubFunction: NA
373  * FunctionPoints: AppScheduler MoveToBackground
374  * EnvConditions:NA
375  * CaseDescription: Verify appmgrclient_ Is null causes OnAbilityRequestDone to be invalid
376  */
377 HWTEST_F(AppSchedulerTest, AppScheduler_oprator_010, TestSize.Level1)
378 {
379     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = nullptr;
380 
381     std::string deviceName = "device";
382     std::string abilityName = "FirstAbility";
383     std::string appName = "FirstApp";
384     std::string bundleName = "com.ix.First";
385     auto abilityReq = GenerateAbilityRequest(deviceName, abilityName, appName, bundleName);
386     auto record = AbilityRecord::CreateAbilityRecord(abilityReq);
387     auto token = record->GetToken();
388     ASSERT_NE(token, nullptr);
389 
390     DelayedSingleton<AppScheduler>::GetInstance()->MoveToBackground(token);
391 }
392 
393 /*
394  * Feature: AppScheduler
395  * Function: MoveToBackground GetAbilityState
396  * SubFunction: NA
397  * FunctionPoints: AppScheduler MoveToBackground and GetAbilityState
398  * EnvConditions:NA
399  * CaseDescription: Verify appmgrclient_ Is not nullptr causes onabilityrequestdone invoke
400  */
401 HWTEST_F(AppSchedulerTest, AppScheduler_oprator_011, TestSize.Level1)
402 {
403     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::make_unique<AppExecFwk::AppMgrClient>();
404     std::string deviceName = "device";
405     std::string abilityName = "FirstAbility";
406     std::string appName = "FirstApp";
407     std::string bundleName = "com.ix.First";
408     auto abilityReq = GenerateAbilityRequest(deviceName, abilityName, appName, bundleName);
409     auto record = AbilityRecord::CreateAbilityRecord(abilityReq);
410     auto token = record->GetToken();
411 
412     DelayedSingleton<AppScheduler>::GetInstance()->MoveToBackground(token);
413     EXPECT_EQ(
414         AppAbilityState::ABILITY_STATE_UNDEFINED, DelayedSingleton<AppScheduler>::GetInstance()->GetAbilityState());
415 }
416 
417 /*
418  * Feature: AppScheduler
419  * Function: ConvertToAppAbilityState
420  * SubFunction: NA
421  * FunctionPoints: AppScheduler ConvertToAppAbilityState
422  * EnvConditions:NA
423  * CaseDescription: Verify ConvertToAppAbilityState result
424  */
425 HWTEST_F(AppSchedulerTest, AppScheduler_oprator_012, TestSize.Level1)
426 {
427     EXPECT_EQ(AppAbilityState::ABILITY_STATE_FOREGROUND,
428         DelayedSingleton<AppScheduler>::GetInstance()->ConvertToAppAbilityState(
429             static_cast<int>(AppExecFwk::AbilityState::ABILITY_STATE_FOREGROUND)));
430 
431     EXPECT_EQ(AppAbilityState::ABILITY_STATE_BACKGROUND,
432         DelayedSingleton<AppScheduler>::GetInstance()->ConvertToAppAbilityState(
433             static_cast<int>(AppExecFwk::AbilityState::ABILITY_STATE_BACKGROUND)));
434 
435     EXPECT_EQ(AppAbilityState::ABILITY_STATE_UNDEFINED,
436         DelayedSingleton<AppScheduler>::GetInstance()->ConvertToAppAbilityState(
437             static_cast<int>(AppExecFwk::AbilityState::ABILITY_STATE_CREATE)));
438 }
439 
440 /*
441  * Feature: AppScheduler
442  * Function: ConvertToAppAbilityState
443  * SubFunction: NA
444  * FunctionPoints: AppScheduler ConvertToAppAbilityState
445  * EnvConditions:NA
446  * CaseDescription: Verify ConvertToAppAbilityState result
447  */
448 HWTEST_F(AppSchedulerTest, AppScheduler_oprator_013, TestSize.Level1)
449 {
450     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = nullptr;
451     EXPECT_EQ(false, DelayedSingleton<AppScheduler>::GetInstance()->Init(appStateMock_));
452 }
453 
454 /*
455  * Feature: AppScheduler
456  * Function: AbilityBehaviorAnalysis
457  * SubFunction: NA
458  * FunctionPoints: AppScheduler AbilityBehaviorAnalysis
459  * EnvConditions:NA
460  * CaseDescription: Verify appmgrclient_ Is not nullptr causes AbilityBehaviorAnalysis to success
461  */
462 HWTEST_F(AppSchedulerTest, AppScheduler_oprator_014, TestSize.Level1)
463 {
464     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::make_unique<AppExecFwk::AppMgrClient>();
465 
466     std::string deviceName = "device";
467     std::string abilityName = "FirstAbility";
468     std::string appName = "FirstApp";
469     std::string bundleName = "com.ix.First";
470     auto abilityReq = GenerateAbilityRequest(deviceName, abilityName, appName, bundleName);
471     auto record = AbilityRecord::CreateAbilityRecord(abilityReq);
472     auto token = record->GetToken();
473     ASSERT_NE(token, nullptr);
474     const int32_t visibility = 1;
475     const int32_t perceptibility = 1;
476     const int32_t connectionState = 1;
477 
478     DelayedSingleton<AppScheduler>::GetInstance()->AbilityBehaviorAnalysis(
479         token, nullptr, visibility, perceptibility, connectionState);
480 
481     auto pretoken = record->GetToken();
482     DelayedSingleton<AppScheduler>::GetInstance()->AbilityBehaviorAnalysis(
483         token, pretoken, visibility, perceptibility, connectionState);
484 
485     const int32_t visibility_1 = 0;
486     DelayedSingleton<AppScheduler>::GetInstance()->AbilityBehaviorAnalysis(
487         token, token, visibility_1, perceptibility, connectionState);
488 
489     const int32_t perceptibility_1 = 0;
490     DelayedSingleton<AppScheduler>::GetInstance()->AbilityBehaviorAnalysis(
491         token, token, visibility_1, perceptibility_1, connectionState);
492 
493     const int32_t connectionState_1 = 0;
494     DelayedSingleton<AppScheduler>::GetInstance()->AbilityBehaviorAnalysis(
495         token, token, visibility_1, perceptibility_1, connectionState_1);
496 }
497 
498 /*
499  * Feature: AppScheduler
500  * Function: AbilityBehaviorAnalysis
501  * SubFunction: NA
502  * FunctionPoints: AppScheduler AbilityBehaviorAnalysis
503  * EnvConditions:NA
504  * CaseDescription: Verify appmgrclient_ Is nullptr causes AbilityBehaviorAnalysis to fail
505  */
506 HWTEST_F(AppSchedulerTest, AppScheduler_oprator_015, TestSize.Level1)
507 {
508     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = nullptr;
509 
510     std::string deviceName = "device";
511     std::string abilityName = "FirstAbility";
512     std::string appName = "FirstApp";
513     std::string bundleName = "com.ix.First";
514     auto abilityReq = GenerateAbilityRequest(deviceName, abilityName, appName, bundleName);
515     auto record = AbilityRecord::CreateAbilityRecord(abilityReq);
516     auto token = record->GetToken();
517     ASSERT_NE(token, nullptr);
518     const int32_t visibility = 0;
519     const int32_t perceptibility = 1;
520     const int32_t connectionState = 1;
521 
522     DelayedSingleton<AppScheduler>::GetInstance()->AbilityBehaviorAnalysis(
523         token, nullptr, visibility, perceptibility, connectionState);
524 }
525 
526 /*
527  * Feature: AppScheduler
528  * Function: KillProcessByAbilityToken
529  * SubFunction: NA
530  * FunctionPoints: AppScheduler KillProcessByAbilityToken
531  * EnvConditions:NA
532  * CaseDescription: Verify appmgrclient_ Is not nullptr causes KillProcessByAbilityToken to success
533  */
534 HWTEST_F(AppSchedulerTest, AppScheduler_oprator_016, TestSize.Level1)
535 {
536     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::make_unique<AppExecFwk::AppMgrClient>();
537 
538     std::string deviceName = "device";
539     std::string abilityName = "FirstAbility";
540     std::string appName = "FirstApp";
541     std::string bundleName = "com.ix.First";
542     auto abilityReq = GenerateAbilityRequest(deviceName, abilityName, appName, bundleName);
543     auto record = AbilityRecord::CreateAbilityRecord(abilityReq);
544     auto token = record->GetToken();
545     ASSERT_NE(token, nullptr);
546 
547     DelayedSingleton<AppScheduler>::GetInstance()->KillProcessByAbilityToken(token);
548 }
549 
550 /*
551  * Feature: AppScheduler
552  * Function: KillProcessByAbilityToken
553  * SubFunction: NA
554  * FunctionPoints: AppScheduler KillProcessByAbilityToken
555  * EnvConditions:NA
556  * CaseDescription: Verify appmgrclient_ Is nullptr causes KillProcessByAbilityToken to fail
557  */
558 HWTEST_F(AppSchedulerTest, AppScheduler_oprator_017, TestSize.Level1)
559 {
560     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = nullptr;
561 
562     std::string deviceName = "device";
563     std::string abilityName = "FirstAbility";
564     std::string appName = "FirstApp";
565     std::string bundleName = "com.ix.First";
566     auto abilityReq = GenerateAbilityRequest(deviceName, abilityName, appName, bundleName);
567     auto record = AbilityRecord::CreateAbilityRecord(abilityReq);
568     auto token = record->GetToken();
569     ASSERT_NE(token, nullptr);
570 
571     DelayedSingleton<AppScheduler>::GetInstance()->KillProcessByAbilityToken(token);
572 }
573 
574 /*
575  * Feature: AppScheduler
576  * Function: UpdateAbilityState
577  * SubFunction: NA
578  * FunctionPoints: AppScheduler UpdateAbilityState
579  * EnvConditions: NA
580  * CaseDescription: Verify UpdateAbilityState
581  */
582 HWTEST_F(AppSchedulerTest, AppScheduler_UpdateAbilityState_001, TestSize.Level1)
583 {
584     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::make_unique<AppExecFwk::AppMgrClient>();
585     ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_, nullptr);
586     sptr<IRemoteObject> token = nullptr;
587     AppExecFwk::AbilityState state = AppExecFwk::AbilityState::ABILITY_STATE_CREATE;
588     DelayedSingleton<AppScheduler>::GetInstance()->UpdateAbilityState(token, state);
589 }
590 
591 /*
592  * Feature: AppScheduler
593  * Function: UpdateExtensionState
594  * SubFunction: NA
595  * FunctionPoints: AppScheduler UpdateExtensionState
596  * EnvConditions: NA
597  * CaseDescription: Verify UpdateExtensionState
598  */
599 HWTEST_F(AppSchedulerTest, AppScheduler_UpdateExtensionState_001, TestSize.Level1)
600 {
601     EXPECT_CALL(*clientMock_, UpdateExtensionState(_, _)).Times(1)
602         .WillOnce(Return(AppMgrResultCode::RESULT_OK));
603     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
604     ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_, nullptr);
605     sptr<IRemoteObject> token = nullptr;
606     AppExecFwk::ExtensionState state = AppExecFwk::ExtensionState::EXTENSION_STATE_READY;
607     DelayedSingleton<AppScheduler>::GetInstance()->UpdateExtensionState(token, state);
608 }
609 
610 /*
611  * Feature: AppScheduler
612  * Function: KillProcessesByUserId
613  * SubFunction: NA
614  * FunctionPoints: AppScheduler KillProcessesByUserId
615  * EnvConditions: NA
616  * CaseDescription: Verify KillProcessesByUserId
617  */
618 HWTEST_F(AppSchedulerTest, AppScheduler_KillProcessesByUserId_001, TestSize.Level1)
619 {
620     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::make_unique<AppExecFwk::AppMgrClient>();
621     ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_, nullptr);
622     int32_t userId = 0;
623     DelayedSingleton<AppScheduler>::GetInstance()->KillProcessesByUserId(userId);
624 }
625 
626 /*
627  * Feature: AppScheduler
628  * Function: OnAbilityRequestDone
629  * SubFunction: NA
630  * FunctionPoints: AppScheduler OnAbilityRequestDone
631  * EnvConditions: NA
632  * CaseDescription: Verify OnAbilityRequestDone
633  */
634 HWTEST_F(AppSchedulerTest, AppScheduler_OnAbilityRequestDone_001, TestSize.Level1)
635 {
636     sptr<IRemoteObject> token = nullptr;
637     AppExecFwk::AbilityState state = AppExecFwk::AbilityState::ABILITY_STATE_CREATE;
638     ASSERT_NE(appStateMock_, nullptr);
639     DelayedSingleton<AppScheduler>::GetInstance()->callback_ = appStateMock_;
640     DelayedSingleton<AppScheduler>::GetInstance()->OnAbilityRequestDone(token, state);
641 }
642 
643 /*
644  * Feature: AppScheduler
645  * Function: KillApplication
646  * SubFunction: NA
647  * FunctionPoints: AppScheduler KillApplication
648  * EnvConditions: NA
649  * CaseDescription: Verify KillApplication
650  */
651 HWTEST_F(AppSchedulerTest, AppScheduler_KillApplication_001, TestSize.Level1)
652 {
653     EXPECT_CALL(*clientMock_, KillApplication(_)).Times(1)
654         .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY));
655     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
656     std::string bundleName = "bundleName";
657     int res = DelayedSingleton<AppScheduler>::GetInstance()->KillApplication(bundleName);
658     EXPECT_EQ(res, INNER_ERR);
659 }
660 
661 /*
662  * Feature: AppScheduler
663  * Function: KillApplication
664  * SubFunction: NA
665  * FunctionPoints: AppScheduler KillApplication
666  * EnvConditions: NA
667  * CaseDescription: Verify KillApplication
668  */
669 HWTEST_F(AppSchedulerTest, AppScheduler_KillApplication_002, TestSize.Level1)
670 {
671     EXPECT_CALL(*clientMock_, KillApplication(_)).Times(1)
672         .WillOnce(Return(AppMgrResultCode::RESULT_OK));
673     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
674     std::string bundleName = "bundleName";
675     int res = DelayedSingleton<AppScheduler>::GetInstance()->KillApplication(bundleName);
676     EXPECT_EQ(res, ERR_OK);
677 }
678 
679 /*
680  * Feature: AppScheduler
681  * Function: KillApplicationByUid
682  * SubFunction: NA
683  * FunctionPoints: AppScheduler KillApplicationByUid
684  * EnvConditions: NA
685  * CaseDescription: Verify KillApplicationByUid
686  */
687 HWTEST_F(AppSchedulerTest, AppScheduler_KillApplicationByUid_001, TestSize.Level1)
688 {
689     EXPECT_CALL(*clientMock_, KillApplicationByUid(_, _)).Times(1)
690         .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY));
691     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
692     std::string bundleName = "bundleName";
693     int32_t uid = 0;
694     int res = DelayedSingleton<AppScheduler>::GetInstance()->KillApplicationByUid(bundleName, uid);
695     EXPECT_EQ(res, INNER_ERR);
696 }
697 
698 /*
699  * Feature: AppScheduler
700  * Function: KillApplicationByUid
701  * SubFunction: NA
702  * FunctionPoints: AppScheduler KillApplicationByUid
703  * EnvConditions: NA
704  * CaseDescription: Verify KillApplicationByUid
705  */
706 HWTEST_F(AppSchedulerTest, AppScheduler_KillApplicationByUid_002, TestSize.Level1)
707 {
708     EXPECT_CALL(*clientMock_, KillApplicationByUid(_, _)).Times(1)
709         .WillOnce(Return(AppMgrResultCode::RESULT_OK));
710     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
711     std::string bundleName = "bundleName";
712     int32_t uid = 0;
713     int res = DelayedSingleton<AppScheduler>::GetInstance()->KillApplicationByUid(bundleName, uid);
714     EXPECT_EQ(res, ERR_OK);
715 }
716 
717 /*
718  * Feature: AppScheduler
719  * Function: ClearUpApplicationData
720  * SubFunction: NA
721  * FunctionPoints: AppScheduler ClearUpApplicationData
722  * EnvConditions: NA
723  * CaseDescription: Verify ClearUpApplicationData
724  */
725 HWTEST_F(AppSchedulerTest, AppScheduler_ClearUpApplicationData_001, TestSize.Level1)
726 {
727     EXPECT_CALL(*clientMock_, ClearUpApplicationData(_)).Times(1)
728         .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY));
729     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
730     std::string bundleName = "bundleName";
731     int res = DelayedSingleton<AppScheduler>::GetInstance()->ClearUpApplicationData(bundleName);
732     EXPECT_EQ(res, INNER_ERR);
733 }
734 
735 /*
736  * Feature: AppScheduler
737  * Function: ClearUpApplicationData
738  * SubFunction: NA
739  * FunctionPoints: AppScheduler ClearUpApplicationData
740  * EnvConditions: NA
741  * CaseDescription: Verify ClearUpApplicationData
742  */
743 HWTEST_F(AppSchedulerTest, AppScheduler_ClearUpApplicationData_002, TestSize.Level1)
744 {
745     EXPECT_CALL(*clientMock_, ClearUpApplicationData(_)).Times(1)
746         .WillOnce(Return(AppMgrResultCode::RESULT_OK));
747     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
748     std::string bundleName = "bundleName";
749     int res = DelayedSingleton<AppScheduler>::GetInstance()->ClearUpApplicationData(bundleName);
750     EXPECT_EQ(res, ERR_OK);
751 }
752 
753 /*
754  * Feature: AppScheduler
755  * Function: PrepareTerminate
756  * SubFunction: NA
757  * FunctionPoints: AppScheduler PrepareTerminate
758  * EnvConditions: NA
759  * CaseDescription: Verify PrepareTerminate
760  */
761 HWTEST_F(AppSchedulerTest, AppScheduler_PrepareTerminate_001, TestSize.Level1)
762 {
763     sptr<IRemoteObject> token = nullptr;
764     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::make_unique<AppExecFwk::AppMgrClient>();
765     ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_, nullptr);
766     DelayedSingleton<AppScheduler>::GetInstance()->PrepareTerminate(token);
767 }
768 
769 /*
770  * Feature: AppScheduler
771  * Function: OnAppStateChanged
772  * SubFunction: NA
773  * FunctionPoints: AppScheduler OnAppStateChanged
774  * EnvConditions: NA
775  * CaseDescription: Verify OnAppStateChanged
776  */
777 HWTEST_F(AppSchedulerTest, AppScheduler_OnAppStateChanged_001, TestSize.Level1)
778 {
779     AppExecFwk::AppProcessData appData;
780     ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance(), nullptr);
781     DelayedSingleton<AppScheduler>::GetInstance()->OnAppStateChanged(appData);
782 }
783 
784 /*
785  * Feature: AppScheduler
786  * Function: GetRunningProcessInfoByToken
787  * SubFunction: NA
788  * FunctionPoints: AppScheduler GetRunningProcessInfoByToken
789  * EnvConditions: NA
790  * CaseDescription: Verify GetRunningProcessInfoByToken
791  */
792 HWTEST_F(AppSchedulerTest, AppScheduler_GetRunningProcessInfoByToken_001, TestSize.Level1)
793 {
794     sptr<IRemoteObject> token;
795     AppExecFwk::RunningProcessInfo info;
796     ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance(), nullptr);
797     DelayedSingleton<AppScheduler>::GetInstance()->GetRunningProcessInfoByToken(token, info);
798 }
799 
800 /*
801  * Feature: AppScheduler
802  * Function: GetRunningProcessInfoByPid
803  * SubFunction: NA
804  * FunctionPoints: AppScheduler GetRunningProcessInfoByPid
805  * EnvConditions: NA
806  * CaseDescription: Verify GetRunningProcessInfoByPid
807  */
808 HWTEST_F(AppSchedulerTest, AppScheduler_GetRunningProcessInfoByPid_001, TestSize.Level1)
809 {
810     pid_t pid = 0;
811     AppExecFwk::RunningProcessInfo info;
812     ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance(), nullptr);
813     DelayedSingleton<AppScheduler>::GetInstance()->GetRunningProcessInfoByPid(pid, info);
814 }
815 
816 /*
817  * Feature: AppScheduler
818  * Function: StartupResidentProcess
819  * SubFunction: NA
820  * FunctionPoints: AppScheduler StartupResidentProcess
821  * EnvConditions: NA
822  * CaseDescription: Verify StartupResidentProcess
823  */
824 HWTEST_F(AppSchedulerTest, AppScheduler_StartupResidentProcess_001, TestSize.Level1)
825 {
826     EXPECT_CALL(*clientMock_, StartupResidentProcess(_)).Times(1);
827     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
828     ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_, nullptr);
829     std::vector<AppExecFwk::BundleInfo> bundleInfos;
830     DelayedSingleton<AppScheduler>::GetInstance()->StartupResidentProcess(bundleInfos);
831 }
832 
833 /*
834  * Feature: AppScheduler
835  * Function: StartSpecifiedAbility
836  * SubFunction: NA
837  * FunctionPoints: AppScheduler StartSpecifiedAbility
838  * EnvConditions: NA
839  * CaseDescription: Verify StartSpecifiedAbility
840  */
841 HWTEST_F(AppSchedulerTest, AppScheduler_StartSpecifiedAbility_001, TestSize.Level1)
842 {
843     EXPECT_CALL(*clientMock_, StartSpecifiedAbility(_, _)).Times(1);
844     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
845     ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_, nullptr);
846     AAFwk::Want want;
847     AppExecFwk::AbilityInfo abilityInfo;
848     DelayedSingleton<AppScheduler>::GetInstance()->StartSpecifiedAbility(want, abilityInfo);
849 }
850 
851 /*
852  * Feature: AppScheduler
853  * Function: GetProcessRunningInfos
854  * SubFunction: NA
855  * FunctionPoints: AppScheduler GetProcessRunningInfos
856  * EnvConditions: NA
857  * CaseDescription: Verify GetProcessRunningInfos
858  */
859 HWTEST_F(AppSchedulerTest, AppScheduler_GetProcessRunningInfos_001, TestSize.Level1)
860 {
861     EXPECT_CALL(*clientMock_, GetAllRunningProcesses(_)).Times(1);
862     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
863     ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_, nullptr);
864     std::vector<AppExecFwk::RunningProcessInfo> info;
865     DelayedSingleton<AppScheduler>::GetInstance()->GetProcessRunningInfos(info);
866 }
867 
868 /*
869  * Feature: AppScheduler
870  * Function: GetProcessRunningInfosByUserId
871  * SubFunction: NA
872  * FunctionPoints: AppScheduler GetProcessRunningInfosByUserId
873  * EnvConditions: NA
874  * CaseDescription: Verify GetProcessRunningInfosByUserId
875  */
876 HWTEST_F(AppSchedulerTest, AppScheduler_GetProcessRunningInfosByUserId_001, TestSize.Level1)
877 {
878     EXPECT_CALL(*clientMock_, GetProcessRunningInfosByUserId(_, _)).Times(1);
879     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
880     ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_, nullptr);
881     std::vector<AppExecFwk::RunningProcessInfo> info;
882     int32_t userId = 0;
883     DelayedSingleton<AppScheduler>::GetInstance()->GetProcessRunningInfosByUserId(info, userId);
884 }
885 
886 /*
887  * Feature: AppScheduler
888  * Function: ConvertAppState
889  * SubFunction: NA
890  * FunctionPoints: AppScheduler ConvertAppState
891  * EnvConditions: NA
892  * CaseDescription: Verify ConvertAppState
893  */
894 HWTEST_F(AppSchedulerTest, AppScheduler_ConvertAppState_001, TestSize.Level1)
895 {
896     AppState state = AppState::BEGIN;
897     ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance(), nullptr);
898     DelayedSingleton<AppScheduler>::GetInstance()->ConvertAppState(state);
899 }
900 
901 /*
902  * Feature: AppScheduler
903  * Function: StartUserTest
904  * SubFunction: NA
905  * FunctionPoints: AppScheduler StartUserTest
906  * EnvConditions: NA
907  * CaseDescription: Verify StartUserTest
908  */
909 HWTEST_F(AppSchedulerTest, AppScheduler_StartUserTest_001, TestSize.Level1)
910 {
911     EXPECT_CALL(*clientMock_, StartUserTestProcess(_, _, _, _)).Times(1)
912         .WillOnce(Return(AppMgrResultCode::RESULT_OK));
913     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
914     Want want;
915     sptr<IRemoteObject> observer;
916     AppExecFwk::BundleInfo bundleInfo;
917     int32_t userId = 0;
918     int res = DelayedSingleton<AppScheduler>::GetInstance()->StartUserTest(want, observer, bundleInfo, userId);
919     EXPECT_EQ(res, ERR_OK);
920 }
921 
922 /*
923  * Feature: AppScheduler
924  * Function: StartUserTest
925  * SubFunction: NA
926  * FunctionPoints: AppScheduler StartUserTest
927  * EnvConditions: NA
928  * CaseDescription: Verify StartUserTest
929  */
930 HWTEST_F(AppSchedulerTest, AppScheduler_StartUserTest_002, TestSize.Level1)
931 {
932     EXPECT_CALL(*clientMock_, StartUserTestProcess(_, _, _, _)).Times(1)
933         .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY));
934     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
935     Want want;
936     sptr<IRemoteObject> observer;
937     AppExecFwk::BundleInfo bundleInfo;
938     int32_t userId = 0;
939     int res = DelayedSingleton<AppScheduler>::GetInstance()->StartUserTest(want, observer, bundleInfo, userId);
940     EXPECT_EQ(res, INNER_ERR);
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_001, TestSize.Level1)
952 {
953     EXPECT_CALL(*clientMock_, FinishUserTest(_, _, _)).Times(1)
954         .WillOnce(Return(AppMgrResultCode::RESULT_OK));
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, ERR_OK);
961 }
962 
963 /*
964  * Feature: AppScheduler
965  * Function: FinishUserTest
966  * SubFunction: NA
967  * FunctionPoints: AppScheduler FinishUserTest
968  * EnvConditions: NA
969  * CaseDescription: Verify FinishUserTest
970  */
971 HWTEST_F(AppSchedulerTest, AppScheduler_FinishUserTest_002, TestSize.Level1)
972 {
973     EXPECT_CALL(*clientMock_, FinishUserTest(_, _, _)).Times(1)
974         .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY));
975     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
976     std::string msg = "msg";
977     int64_t resultCode = 0;
978     std::string bundleName = "bundleName";
979     int res = DelayedSingleton<AppScheduler>::GetInstance()->FinishUserTest(msg, resultCode, bundleName);
980     EXPECT_EQ(res, INNER_ERR);
981 }
982 
983 /*
984  * Feature: AppScheduler
985  * Function: UpdateConfiguration
986  * SubFunction: NA
987  * FunctionPoints: AppScheduler UpdateConfiguration
988  * EnvConditions: NA
989  * CaseDescription: Verify UpdateConfiguration
990  */
991 HWTEST_F(AppSchedulerTest, AppScheduler_UpdateConfiguration_001, TestSize.Level1)
992 {
993     EXPECT_CALL(*clientMock_, UpdateConfiguration(_)).Times(1)
994         .WillOnce(Return(AppMgrResultCode::RESULT_OK));
995     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
996     AppExecFwk::Configuration config;
997     int res = DelayedSingleton<AppScheduler>::GetInstance()->UpdateConfiguration(config);
998     EXPECT_EQ(res, ERR_OK);
999 }
1000 
1001 /*
1002  * Feature: AppScheduler
1003  * Function: UpdateConfiguration
1004  * SubFunction: NA
1005  * FunctionPoints: AppScheduler UpdateConfiguration
1006  * EnvConditions: NA
1007  * CaseDescription: Verify UpdateConfiguration
1008  */
1009 HWTEST_F(AppSchedulerTest, AppScheduler_UpdateConfiguration_002, TestSize.Level1)
1010 {
1011     EXPECT_CALL(*clientMock_, UpdateConfiguration(_)).Times(1)
1012         .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY));
1013     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
1014     AppExecFwk::Configuration config;
1015     int res = DelayedSingleton<AppScheduler>::GetInstance()->UpdateConfiguration(config);
1016     EXPECT_EQ(res, INNER_ERR);
1017 }
1018 
1019 /*
1020  * Feature: AppScheduler
1021  * Function: GetConfiguration
1022  * SubFunction: NA
1023  * FunctionPoints: AppScheduler GetConfiguration
1024  * EnvConditions: NA
1025  * CaseDescription: Verify GetConfiguration
1026  */
1027 HWTEST_F(AppSchedulerTest, AppScheduler_GetConfiguration_001, TestSize.Level1)
1028 {
1029     EXPECT_CALL(*clientMock_, GetConfiguration(_)).Times(1)
1030         .WillOnce(Return(AppMgrResultCode::RESULT_OK));
1031     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
1032     AppExecFwk::Configuration config;
1033     int res = DelayedSingleton<AppScheduler>::GetInstance()->GetConfiguration(config);
1034     EXPECT_EQ(res, ERR_OK);
1035 }
1036 
1037 /*
1038  * Feature: AppScheduler
1039  * Function: GetConfiguration
1040  * SubFunction: NA
1041  * FunctionPoints: AppScheduler GetConfiguration
1042  * EnvConditions: NA
1043  * CaseDescription: Verify GetConfiguration
1044  */
1045 HWTEST_F(AppSchedulerTest, AppScheduler_GetConfiguration_002, TestSize.Level1)
1046 {
1047     EXPECT_CALL(*clientMock_, GetConfiguration(_)).Times(1)
1048         .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY));
1049     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
1050     AppExecFwk::Configuration config;
1051     int res = DelayedSingleton<AppScheduler>::GetInstance()->GetConfiguration(config);
1052     EXPECT_EQ(res, INNER_ERR);
1053 }
1054 
1055 /*
1056  * Feature: AppScheduler
1057  * Function: GetAbilityRecordsByProcessID
1058  * SubFunction: NA
1059  * FunctionPoints: AppScheduler GetAbilityRecordsByProcessID
1060  * EnvConditions: NA
1061  * CaseDescription: Verify GetAbilityRecordsByProcessID
1062  */
1063 HWTEST_F(AppSchedulerTest, AppScheduler_GetAbilityRecordsByProcessID_001, TestSize.Level1)
1064 {
1065     EXPECT_CALL(*clientMock_, GetAbilityRecordsByProcessID(_, _)).Times(1)
1066         .WillOnce(Return(AppMgrResultCode::RESULT_OK));
1067     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
1068     int pid = 0;
1069     std::vector<sptr<IRemoteObject>> tokens;
1070     int res = DelayedSingleton<AppScheduler>::GetInstance()->GetAbilityRecordsByProcessID(pid, tokens);
1071     EXPECT_EQ(res, ERR_OK);
1072 }
1073 
1074 /*
1075  * Feature: AppScheduler
1076  * Function: GetAbilityRecordsByProcessID
1077  * SubFunction: NA
1078  * FunctionPoints: AppScheduler GetAbilityRecordsByProcessID
1079  * EnvConditions: NA
1080  * CaseDescription: Verify GetAbilityRecordsByProcessID
1081  */
1082 HWTEST_F(AppSchedulerTest, AppScheduler_GetAbilityRecordsByProcessID_002, TestSize.Level1)
1083 {
1084     EXPECT_CALL(*clientMock_, GetAbilityRecordsByProcessID(_, _)).Times(1)
1085         .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY));
1086     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
1087     int pid = 0;
1088     std::vector<sptr<IRemoteObject>> tokens;
1089     int res = DelayedSingleton<AppScheduler>::GetInstance()->GetAbilityRecordsByProcessID(pid, tokens);
1090     EXPECT_EQ(res, INNER_ERR);
1091     clientMock_.reset();
1092     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_.reset();
1093 }
1094 
1095 /*
1096  * Feature: AppScheduler
1097  * Function: BlockAppService
1098  * SubFunction: NA
1099  * FunctionPoints: AppScheduler BlockAppService
1100  * EnvConditions: NA
1101  * CaseDescription: Verify BlockAppService
1102  */
1103 #ifdef ABILITY_COMMAND_FOR_TEST
1104 HWTEST_F(AppSchedulerTest, AppScheduler_BlockAppService_001, TestSize.Level1)
1105 {
1106     clientMock_ = std::make_unique<AppMgrClientMock>();
1107     EXPECT_CALL(*clientMock_, BlockAppService()).Times(1)
1108         .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY));
1109     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
1110     int res = DelayedSingleton<AppScheduler>::GetInstance()->BlockAppService();
1111     EXPECT_EQ(res, INNER_ERR);
1112     clientMock_.reset();
1113     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_.reset();
1114 }
1115 #endif
1116 
1117 /*
1118  * Feature: AppScheduler
1119  * Function: BlockAppService
1120  * SubFunction: NA
1121  * FunctionPoints: AppScheduler BlockAppService
1122  * EnvConditions: NA
1123  * CaseDescription: Verify BlockAppService
1124  */
1125 #ifdef ABILITY_COMMAND_FOR_TEST
1126 HWTEST_F(AppSchedulerTest, AppScheduler_BlockAppService_002, TestSize.Level1)
1127 {
1128     clientMock_ = std::make_unique<AppMgrClientMock>();
1129     EXPECT_CALL(*clientMock_, BlockAppService()).Times(1)
1130         .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY));
1131     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
1132     int res = DelayedSingleton<AppScheduler>::GetInstance()->BlockAppService();
1133     EXPECT_EQ(res, INNER_ERR);
1134     clientMock_.reset();
1135     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_.reset();
1136 }
1137 #endif
1138 
1139 /**
1140  * @tc.name: SetCurrentUserId_001
1141  * @tc.desc: set current userId.
1142  * @tc.type: FUNC
1143  */
1144 HWTEST_F(AppSchedulerTest, AppScheduler_SetCurrentUserId_001, TestSize.Level1)
1145 {
1146     int32_t userId = 0;
1147     DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::make_unique<AppExecFwk::AppMgrClient>();
1148     ASSERT_NE(DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_, nullptr);
1149     DelayedSingleton<AppScheduler>::GetInstance()->SetCurrentUserId(userId);
1150 }
1151 
1152 /**
1153  * @tc.name: AppScheduler_NotifyFault_001
1154  * @tc.desc: Verify that the NotifyFault interface calls normally
1155  * @tc.type: FUNC
1156  */
1157 HWTEST_F(AppSchedulerTest, AppScheduler_NotifyFault_001, TestSize.Level1)
1158 {
1159     AppExecFwk::FaultData faultData;
1160     int res = DelayedSingleton<AppScheduler>::GetInstance()->NotifyFault(faultData);
1161     EXPECT_EQ(res, INNER_ERR);
1162 }
1163 }  // namespace AAFwk
1164 }  // namespace OHOS
1165