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