1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #define private public
17 #include "app_mgr_client.h"
18 #undef private
19 #include <gtest/gtest.h>
20 #include "ability_info.h"
21 #include "application_info.h"
22 #include "hilog_tag_wrapper.h"
23 #include "iapp_state_callback.h"
24 #include "mock_ability_token.h"
25 #include "mock_ams_mgr_scheduler.h"
26 #include "mock_app_mgr_service.h"
27 #include "mock_app_service_mgr.h"
28 #include "mock_iapp_state_callback.h"
29 #include "mock_native_token.h"
30 #include "param.h"
31 #include "running_process_info.h"
32 
33 using namespace testing::ext;
34 using testing::_;
35 using testing::Invoke;
36 using testing::InvokeWithoutArgs;
37 using testing::Return;
38 using testing::SetArgReferee;
39 
40 namespace OHOS {
41 namespace AppExecFwk {
42 namespace {
43 const int32_t USER_ID = 100;
44 }  // namespace
45 
46 class AmsAppMgrClientTest : public testing::Test {
47 public:
48     static void SetUpTestCase();
49     static void TearDownTestCase();
50     void SetUp();
51     void TearDown();
52 
53 protected:
54     sptr<MockAbilityToken> token_;
55     sptr<MockAbilityToken> preToken_;
56     std::unique_ptr<AppMgrClient> client_;
57 };
58 
SetUpTestCase()59 void AmsAppMgrClientTest::SetUpTestCase()
60 {
61     MockNativeToken::SetNativeToken();
62 }
63 
TearDownTestCase()64 void AmsAppMgrClientTest::TearDownTestCase()
65 {}
66 
SetUp()67 void AmsAppMgrClientTest::SetUp()
68 {
69     client_.reset(new (std::nothrow) AppMgrClient());
70     client_->SetServiceManager(std::make_unique<MockAppServiceMgr>());
71     token_ = new (std::nothrow) MockAbilityToken();
72 }
73 
TearDown()74 void AmsAppMgrClientTest::TearDown()
75 {}
76 
77 /**
78  * @tc.name: AppMgrClient_GetProcessRunningInfosByUserId_0100
79  * @tc.desc: GetProcessRunningInfosByUserId
80  * @tc.type: FUNC
81  * @tc.require: SR000GH1GO
82  */
83 HWTEST_F(AmsAppMgrClientTest, AppMgrClient_GetProcessRunningInfosByUserId_0100, TestSize.Level1)
84 {
85     TAG_LOGI(AAFwkTag::TEST, "AppMgrClient_GetProcessRunningInfosByUserId_0100 start");
86 
87     EXPECT_EQ(AppMgrResultCode::RESULT_OK, client_->ConnectAppMgrService());
88 
89     EXPECT_CALL(
90         *(static_cast<MockAppMgrService*>((iface_cast<IAppMgr>(client_->GetRemoteObject())).GetRefPtr())),
91         GetProcessRunningInfosByUserId(_, _))
92         .Times(1)
93         .WillOnce(Return(AppMgrResultCode::RESULT_OK));
94 
95     std::vector<RunningProcessInfo> info;
96     int32_t userId = USER_ID;
97     auto result = client_->GetProcessRunningInfosByUserId(info, userId);
98     TAG_LOGI(AAFwkTag::TEST, "result = %{public}d", result);
99 
100     EXPECT_EQ(result, AppMgrResultCode::RESULT_OK);
101 
102     TAG_LOGI(AAFwkTag::TEST, "AppMgrClient_GetProcessRunningInfosByUserId_0100 end");
103 }
104 
105 /*
106  * Feature: AppMgrService
107  * Function: AppMgrClient
108  * SubFunction: LoadAbility Function
109  * FunctionPoints: AppMgrClient LoadAbility interface
110  * EnvConditions: Mobile that can run ohos test framework
111  * CaseDescription: Verify if AppMgrClient invoke LoadAbility works.
112  */
113 HWTEST_F(AmsAppMgrClientTest, AppMgrClient_001, TestSize.Level1)
114 {
115     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_001 start");
116     EXPECT_EQ(AppMgrResultCode::RESULT_OK, client_->ConnectAppMgrService());
117 
118     AbilityInfo abilityInfo;
119     ApplicationInfo appInfo;
120     Want want;
121 
122     sptr<IAmsMgr> amsMgrScheduler(new MockAmsMgrScheduler());
123 
124     EXPECT_CALL(*(static_cast<MockAmsMgrScheduler*>(amsMgrScheduler.GetRefPtr())),
125         LoadAbility(_, _, _, _)).Times(1);
126 
127     EXPECT_CALL(*(static_cast<MockAppMgrService*>((iface_cast<IAppMgr>(client_->GetRemoteObject())).GetRefPtr())),
128         GetAmsMgr())
129         .Times(1)
130         .WillOnce(Return(amsMgrScheduler));
131     AbilityRuntime::LoadParam loadParam;
132     loadParam.token = token_;
133     loadParam.preToken = preToken_;
134     EXPECT_EQ(AppMgrResultCode::RESULT_OK, client_->LoadAbility(abilityInfo, appInfo, want, loadParam));
135     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_001 end");
136 }
137 
138 /*
139  * Feature: AppMgrService
140  * Function: AppMgrClient
141  * SubFunction: LoadAbility Function
142  * FunctionPoints: AppMgrClient LoadAbility interface
143  * EnvConditions: Mobile that can run ohos test framework
144  * CaseDescription: Verify if AppMgrClient invoke LoadAbility act normal without connect to service.
145  */
146 HWTEST_F(AmsAppMgrClientTest, AppMgrClient_002, TestSize.Level1)
147 {
148     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_002 start");
149     AbilityInfo abilityInfo;
150     ApplicationInfo appInfo;
151     Want want;
152     AbilityRuntime::LoadParam loadParam;
153     loadParam.token = token_;
154     loadParam.preToken = preToken_;
155     EXPECT_EQ(
156         AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED, client_->LoadAbility(abilityInfo, appInfo, want, loadParam));
157     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_002 end");
158 }
159 
160 /*
161  * Feature: AppMgrService
162  * Function: AppMgrClient
163  * SubFunction: TerminateAbility Function
164  * FunctionPoints: AppMgrClient TerminateAbility interface
165  * EnvConditions: Mobile that can run ohos test framework
166  * CaseDescription: Verify if AppMgrClient invoke TerminateAbility works.
167  */
168 HWTEST_F(AmsAppMgrClientTest, AppMgrClient_003, TestSize.Level1)
169 {
170     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_003 start");
171     EXPECT_EQ(AppMgrResultCode::RESULT_OK, client_->ConnectAppMgrService());
172 
173     sptr<IAmsMgr> amsMgrScheduler(new MockAmsMgrScheduler());
174     EXPECT_CALL(*(static_cast<MockAppMgrService*>((iface_cast<IAppMgr>(client_->GetRemoteObject())).GetRefPtr())),
175         GetAmsMgr())
176         .Times(1)
177         .WillOnce(Return(amsMgrScheduler));
178     EXPECT_CALL(*(static_cast<MockAmsMgrScheduler*>(amsMgrScheduler.GetRefPtr())), TerminateAbility(_, _)).Times(1);
179 
180     EXPECT_EQ(AppMgrResultCode::RESULT_OK, client_->TerminateAbility(token_, false));
181     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_003 end");
182 }
183 
184 /*
185  * Feature: AppMgrService
186  * Function: AppMgrClient
187  * SubFunction: TerminateAbility Function
188  * FunctionPoints: AppMgrClient TerminateAbility interface
189  * EnvConditions: Mobile that can run ohos test framework
190  * CaseDescription: Verify if AppMgrClient invoke TerminateAbility act normal without connect to service.
191  */
192 HWTEST_F(AmsAppMgrClientTest, AppMgrClient_004, TestSize.Level1)
193 {
194     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_004 start");
195     EXPECT_EQ(AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED, client_->TerminateAbility(token_, false));
196     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_004 end");
197 }
198 
199 /*
200  * Feature: AppMgrService
201  * Function: AppMgrClient
202  * SubFunction: UpdateAbilityState Function
203  * FunctionPoints: AppMgrClient UpdateAbilityState interface
204  * EnvConditions: Mobile that can run ohos test framework
205  * CaseDescription: Verify if AppMgrClient invoke UpdateAbilityState works.
206  */
207 HWTEST_F(AmsAppMgrClientTest, AppMgrClient_005, TestSize.Level1)
208 {
209     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_005 start");
210     EXPECT_EQ(AppMgrResultCode::RESULT_OK, client_->ConnectAppMgrService());
211 
212     sptr<IAmsMgr> amsMgrScheduler(new MockAmsMgrScheduler());
213     EXPECT_CALL(*(static_cast<MockAmsMgrScheduler*>(amsMgrScheduler.GetRefPtr())), UpdateAbilityState(_, _)).Times(1);
214     EXPECT_CALL(*(static_cast<MockAppMgrService*>((iface_cast<IAppMgr>(client_->GetRemoteObject())).GetRefPtr())),
215         GetAmsMgr())
216         .Times(1)
217         .WillOnce(Return(amsMgrScheduler));
218 
219     AbilityState state = AbilityState::ABILITY_STATE_CREATE;
220     EXPECT_EQ(AppMgrResultCode::RESULT_OK, client_->UpdateAbilityState(token_, state));
221     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_005 end");
222 }
223 
224 /*
225  * Feature: AppMgrService
226  * Function: AppMgrClient
227  * SubFunction: UpdateAbilityState Function
228  * FunctionPoints: AppMgrClient UpdateAbilityState interface
229  * EnvConditions: Mobile that can run ohos test framework
230  * CaseDescription: Verify if AppMgrClient invoke UpdateAbilityState act normal without connect to service.
231  */
232 HWTEST_F(AmsAppMgrClientTest, AppMgrClient_006, TestSize.Level1)
233 {
234     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_006 start");
235     AbilityState state = AbilityState::ABILITY_STATE_CREATE;
236     EXPECT_EQ(AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED, client_->UpdateAbilityState(token_, state));
237     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_006 end");
238 }
239 
240 /*
241  * Feature: AppMgrService
242  * Function: AppMgrClient
243  * SubFunction: RegisterAppStateCallback Function
244  * FunctionPoints: AppMgrClient RegisterAppStateCallback interface
245  * EnvConditions: Mobile that can run ohos test framework
246  * CaseDescription: Verify if AppMgrClient invoke RegisterAppStateCallback works.
247  */
248 HWTEST_F(AmsAppMgrClientTest, AppMgrClient_007, TestSize.Level1)
249 {
250     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_007 start");
251     EXPECT_EQ(AppMgrResultCode::RESULT_OK, client_->ConnectAppMgrService());
252     sptr<MockAppStateCallback> mockCallback(new MockAppStateCallback());
253     sptr<IAppStateCallback> callback = iface_cast<IAppStateCallback>(mockCallback);
254 
255     sptr<IAmsMgr> amsMgrScheduler(new MockAmsMgrScheduler());
256     EXPECT_CALL(*(static_cast<MockAppMgrService*>((iface_cast<IAppMgr>(client_->GetRemoteObject())).GetRefPtr())),
257         GetAmsMgr())
258         .Times(1)
259         .WillOnce(Return(amsMgrScheduler));
260 
261     EXPECT_CALL(*mockCallback, OnAbilityRequestDone(_, _)).Times(1);
262     EXPECT_CALL(*mockCallback, OnAppStateChanged(_)).Times(1);
263 
264     EXPECT_EQ(AppMgrResultCode::RESULT_OK, client_->RegisterAppStateCallback(callback));
265     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_007 end");
266 }
267 
268 /*
269  * Feature: AppMgrService
270  * Function: AppMgrClient
271  * SubFunction: RegisterAppStateCallback Function
272  * FunctionPoints: AppMgrClient RegisterAppStateCallback interface
273  * EnvConditions: Mobile that can run ohos test framework
274  * CaseDescription: Verify if AppMgrClient invoke RegisterAppStateCallback act normal without connect to service.
275  */
276 HWTEST_F(AmsAppMgrClientTest, AppMgrClient_008, TestSize.Level1)
277 {
278     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_008 start");
279     sptr<IAppStateCallback> callback;
280     EXPECT_EQ(AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED, client_->RegisterAppStateCallback(callback));
281     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_008 end");
282 }
283 
284 /*
285  * Feature: AppMgrService
286  * Function: AppMgrClient::AbilityBehaviorAnalysis
287  * SubFunction: RegisterAppStateCallback Function
288  * FunctionPoints: AppMgrClient AbilityBehaviorAnalysis interface
289  * EnvConditions: Mobile that can run ohos test framework
290  * CaseDescription: ability behavior notification
291  */
292 HWTEST_F(AmsAppMgrClientTest, AppMgrClient_009, TestSize.Level1)
293 {
294     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_008 start");
295     EXPECT_EQ(AppMgrResultCode::RESULT_OK, client_->ConnectAppMgrService());
296     sptr<IRemoteObject> token;
297     sptr<IRemoteObject> preToken;
298 
299     sptr<IAmsMgr> amsMgrScheduler(new MockAmsMgrScheduler());
300     EXPECT_CALL(
301         *(static_cast<MockAmsMgrScheduler*>(amsMgrScheduler.GetRefPtr())), AbilityBehaviorAnalysis(_, _, _, _, _))
302         .Times(1);
303     EXPECT_CALL(*(static_cast<MockAppMgrService*>((iface_cast<IAppMgr>(client_->GetRemoteObject())).GetRefPtr())),
304         GetAmsMgr())
305         .Times(1)
306         .WillOnce(Return(amsMgrScheduler));
307 
308     EXPECT_EQ(AppMgrResultCode::RESULT_OK, client_->AbilityBehaviorAnalysis(token, preToken, 1, 1, 1));
309     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_008 end");
310 }
311 
312 /*
313  * Feature: AppMgrService
314  * Function: AppMgrClient::KillApplication
315  * SubFunction: RegisterAppStateCallback Function
316  * FunctionPoints: AppMgrClient KillApplication interface
317  * EnvConditions: Mobile that can run ohos test framework
318  * CaseDescription: Notify app of death
319  */
320 HWTEST_F(AmsAppMgrClientTest, AppMgrClient_010, TestSize.Level1)
321 {
322     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_008 start");
323     EXPECT_EQ(AppMgrResultCode::RESULT_OK, client_->ConnectAppMgrService());
324     sptr<IRemoteObject> token;
325     sptr<IRemoteObject> preToken;
326 
327     sptr<IAmsMgr> amsMgrScheduler(new MockAmsMgrScheduler());
328     EXPECT_CALL(*(static_cast<MockAmsMgrScheduler*>(amsMgrScheduler.GetRefPtr())), KillApplication(_, _))
329         .Times(1)
330         .WillOnce(Return(ERR_OK));
331     EXPECT_CALL(*(static_cast<MockAppMgrService*>((iface_cast<IAppMgr>(client_->GetRemoteObject())).GetRefPtr())),
332         GetAmsMgr())
333         .Times(1)
334         .WillOnce(Return(amsMgrScheduler));
335 
336     EXPECT_EQ(AppMgrResultCode::RESULT_OK, client_->KillApplication(""));
337     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_008 end");
338 }
339 
340 /*
341  * Feature: AppMgrService
342  * Function: AppMgrClient::KillApplication
343  * SubFunction: RegisterAppStateCallback Function
344  * FunctionPoints: AppMgrClient KillApplication interface
345  * EnvConditions: Mobile that can run ohos test framework
346  * CaseDescription: Notify app of death
347  */
348 HWTEST_F(AmsAppMgrClientTest, AppMgrClient_011, TestSize.Level1)
349 {
350     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_011 start");
351     sptr<IRemoteObject> token;
352     sptr<IRemoteObject> preToken;
353     EXPECT_EQ(AppMgrResultCode::RESULT_OK, client_->ConnectAppMgrService());
354     sptr<IAmsMgr> amsMgrScheduler(new MockAmsMgrScheduler());
355     EXPECT_CALL(*(static_cast<MockAmsMgrScheduler*>(amsMgrScheduler.GetRefPtr())), KillApplication(_, _))
356         .Times(1)
357         .WillOnce(Return(ERR_NO_MEMORY));
358     EXPECT_CALL(*(static_cast<MockAppMgrService*>((iface_cast<IAppMgr>(client_->GetRemoteObject())).GetRefPtr())),
359         GetAmsMgr())
360         .Times(1)
361         .WillOnce(Return(amsMgrScheduler));
362 
363     EXPECT_EQ(AppMgrResultCode::ERROR_SERVICE_NOT_READY, client_->KillApplication(""));
364     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_011 end");
365 }
366 
367 /*
368  * Feature: AppMgrService
369  * Function: AppMgrClient::KillProcessByAbilityToken
370  * SubFunction: RegisterAppStateCallback Function
371  * FunctionPoints: AppMgrClient KillApplication interface
372  * EnvConditions: Mobile that can run ohos test framework
373  * CaseDescription: Notify app of death
374  */
375 HWTEST_F(AmsAppMgrClientTest, AppMgrClient_012, TestSize.Level1)
376 {
377     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_012 start");
378     sptr<IRemoteObject> token;
379     EXPECT_EQ(AppMgrResultCode::RESULT_OK, client_->ConnectAppMgrService());
380     sptr<IAmsMgr> amsMgrScheduler(new MockAmsMgrScheduler());
381     EXPECT_CALL(*(static_cast<MockAmsMgrScheduler*>(amsMgrScheduler.GetRefPtr())), KillProcessByAbilityToken(_))
382         .Times(1);
383 
384     EXPECT_CALL(*(static_cast<MockAppMgrService*>((iface_cast<IAppMgr>(client_->GetRemoteObject())).GetRefPtr())),
385         GetAmsMgr())
386         .Times(1)
387         .WillOnce(Return(amsMgrScheduler));
388 
389     EXPECT_EQ(AppMgrResultCode::RESULT_OK, client_->KillProcessByAbilityToken(token));
390     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_012 end");
391 }
392 
393 /*
394  * Feature: AppMgrService
395  * Function: AppMgrClient::KillProcessByAbilityToken
396  * SubFunction: RegisterAppStateCallback Function
397  * FunctionPoints: AppMgrClient KillApplication interface
398  * EnvConditions: Mobile that can run ohos test framework
399  * CaseDescription: Notify app of death
400  */
401 HWTEST_F(AmsAppMgrClientTest, AppMgrClient_013, TestSize.Level1)
402 {
403     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_013 start");
404     sptr<IRemoteObject> token;
405     EXPECT_EQ(AppMgrResultCode::RESULT_OK, client_->ConnectAppMgrService());
406     sptr<IAmsMgr> amsMgrScheduler(new MockAmsMgrScheduler());
407     EXPECT_CALL(*(static_cast<MockAmsMgrScheduler*>(amsMgrScheduler.GetRefPtr())), KillProcessByAbilityToken(_))
408         .Times(0);
409 
410     EXPECT_CALL(*(static_cast<MockAppMgrService*>((iface_cast<IAppMgr>(client_->GetRemoteObject())).GetRefPtr())),
411         GetAmsMgr())
412         .Times(1)
413         .WillOnce(Return(nullptr));
414 
415     EXPECT_EQ(AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED, client_->KillProcessByAbilityToken(token));
416     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_013 end");
417 }
418 
419 /*
420  * Feature: AppMgrService
421  * Function: AppMgrClient::ClearUpApplicationData
422  * SubFunction: ClearUpApplicationData
423  * FunctionPoints: AppMgrClient ClearUpApplicationData interface
424  * EnvConditions: Mobile that can run ohos test framework
425  * CaseDescription: clear the application data.
426  */
427 HWTEST_F(AmsAppMgrClientTest, AppMgrClient_014, TestSize.Level1)
428 {
429     sptr<IRemoteObject> token;
430     EXPECT_EQ(AppMgrResultCode::RESULT_OK, client_->ConnectAppMgrService());
431     EXPECT_CALL(*(static_cast<MockAppMgrService*>((iface_cast<IAppMgr>(client_->GetRemoteObject())).GetRefPtr())),
432         ClearUpApplicationData(_, _, _))
433         .Times(1)
434         .WillOnce(Return(ERR_NO_MEMORY));
435     EXPECT_EQ(AppMgrResultCode::ERROR_SERVICE_NOT_READY, client_->ClearUpApplicationData("com.test", 0));
436 }
437 
438 /*
439  * Feature: AppMgrService
440  * Function: AppMgrClient::ClearUpApplicationData
441  * SubFunction: ClearUpApplicationData
442  * FunctionPoints: AppMgrClient ClearUpApplicationData interface
443  * EnvConditions: Mobile that can run ohos test framework
444  * CaseDescription: clear the application data.
445  */
446 HWTEST_F(AmsAppMgrClientTest, AppMgrClient_015, TestSize.Level1)
447 {
448     sptr<IRemoteObject> token;
449     EXPECT_EQ(AppMgrResultCode::RESULT_OK, client_->ConnectAppMgrService());
450     sptr<IAppMgr> appMgr(new MockAppMgrService());
451     EXPECT_CALL(*(static_cast<MockAppMgrService*>((iface_cast<IAppMgr>(client_->GetRemoteObject())).GetRefPtr())),
452         ClearUpApplicationData(_, _, _))
453         .Times(1)
454         .WillOnce(Return(ERR_OK));
455     EXPECT_EQ(AppMgrResultCode::RESULT_OK, client_->ClearUpApplicationData("com.test", 0));
456 }
457 
458 /**
459  * @tc.name: AppMgrClient_016
460  * @tc.desc: Verify the function when parameter is 2
461  * @tc.type: FUNC
462  * @tc.require: issueI5823X
463  */
464 HWTEST_F(AmsAppMgrClientTest, AppMgrClient_016, TestSize.Level1)
465 {
466     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_016 start");
467     AppMgrClient* ret = new AppMgrClient();
468     auto ans = ret->NotifyMemoryLevel(MemoryLevel::MEMORY_LEVEL_CRITICAL);
469     EXPECT_EQ(ans, ERR_INVALID_VALUE);
470     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_016 end");
471 }
472 
473 /**
474  * @tc.name: AppMgrClient_017
475  * @tc.desc: Verify the function when parameter is 1
476  * @tc.type: FUNC
477  * @tc.require: issueI5823X
478  */
479 HWTEST_F(AmsAppMgrClientTest, AppMgrClient_017, TestSize.Level1)
480 {
481     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_017 start");
482     AppMgrClient* ret = new AppMgrClient();
483     auto ans = ret->NotifyMemoryLevel(MemoryLevel::MEMORY_LEVEL_LOW);
484     EXPECT_EQ(ans, ERR_INVALID_VALUE);
485     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_017 end");
486 }
487 
488 /**
489  * @tc.name: AppMgrClient_018
490  * @tc.desc: Verify the function when parameter is 0
491  * @tc.type: FUNC
492  * @tc.require: issueI5823X
493  */
494 HWTEST_F(AmsAppMgrClientTest, AppMgrClient_018, TestSize.Level1)
495 {
496     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_018 start");
497     AppMgrClient* ret = new AppMgrClient();
498     auto ans = ret->NotifyMemoryLevel(MemoryLevel::MEMORY_LEVEL_MODERATE);
499     EXPECT_EQ(ans, ERR_INVALID_VALUE);
500     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_018 end");
501 }
502 
503 /**
504  * @tc.name: AppMgrClient_019
505  * @tc.desc: Verify the function when parameter is 2
506  * @tc.type: FUNC
507  * @tc.require: issueI581UZ
508  */
509 HWTEST_F(AmsAppMgrClientTest, AppMgrClient_019, TestSize.Level1)
510 {
511     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_019 start");
512     AppMgrClient* ret = new AppMgrClient();
513     auto ans = ret->NotifyMemoryLevel(MemoryLevel::MEMORY_LEVEL_CRITICAL);
514     EXPECT_EQ(ans, ERR_INVALID_VALUE);
515     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_019 end");
516 }
517 
518 /**
519  * @tc.name: AppMgrClient_020
520  * @tc.desc: Verify the function when parameter is 1
521  * @tc.type: FUNC
522  * @tc.require: issueI581UZ
523  */
524 HWTEST_F(AmsAppMgrClientTest, AppMgrClient_020, TestSize.Level1)
525 {
526     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_020 start");
527     AppMgrClient* ret = new AppMgrClient();
528     auto ans = ret->NotifyMemoryLevel(MemoryLevel::MEMORY_LEVEL_LOW);
529     EXPECT_EQ(ans, ERR_INVALID_VALUE);
530     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_020 end");
531 }
532 
533 /**
534  * @tc.name: AppMgrClient_021
535  * @tc.desc: Verify the function when parameter is 0
536  * @tc.type: FUNC
537  * @tc.require: issueI581UZ
538  */
539 HWTEST_F(AmsAppMgrClientTest, AppMgrClient_021, TestSize.Level1)
540 {
541     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_021 start");
542     AppMgrClient* ret = new AppMgrClient();
543     auto ans = ret->NotifyMemoryLevel(MemoryLevel::MEMORY_LEVEL_MODERATE);
544     EXPECT_EQ(ans, ERR_INVALID_VALUE);
545     TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_021 end");
546 }
547 }  // namespace AppExecFwk
548 }  // namespace OHOS
549