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 // redefine private and protected since testcase need to invoke and test private function
17 #define private public
18 #define protected public
19 #include "app_mgr_service.h"
20 #undef private
21 #undef protected
22 #include <gtest/gtest.h>
23 #include "errors.h"
24 #include "hilog_tag_wrapper.h"
25 #include "iremote_object.h"
26 #include "mock_app_mgr_service_inner.h"
27 #include "mock_native_token.h"
28 #include "system_memory_attr.h"
29
30 using namespace testing;
31 using namespace testing::ext;
32 using namespace OHOS::AppExecFwk;
33 using OHOS::iface_cast;
34 using OHOS::IRemoteObject;
35 using OHOS::sptr;
36 using testing::_;
37 using testing::InvokeWithoutArgs;
38
39 class AmsServiceEventDriveTest : public testing::Test {
40 public:
41 static void SetUpTestCase();
42 static void TearDownTestCase();
43 void SetUp();
44 void TearDown();
45
46 std::shared_ptr<MockAppMgrServiceInner> GetMockAppMgrServiceInner();
47 std::shared_ptr<AMSEventHandler> GetAmsEventHandler();
48
49 protected:
50 std::shared_ptr<AppMgrService> appMgrService_ = std::make_shared<AppMgrService>();
51 };
52
SetUpTestCase()53 void AmsServiceEventDriveTest::SetUpTestCase()
54 {
55 MockNativeToken::SetNativeToken();
56 }
57
TearDownTestCase()58 void AmsServiceEventDriveTest::TearDownTestCase()
59 {}
60
SetUp()61 void AmsServiceEventDriveTest::SetUp()
62 {
63 appMgrService_->OnStart();
64 }
65
TearDown()66 void AmsServiceEventDriveTest::TearDown()
67 {
68 appMgrService_->OnStop();
69 }
70
71 /*
72 * Feature: AppMgrService
73 * Function: Service
74 * SubFunction: EventDrive
75 * FunctionPoints: AppMgrService event drive program model
76 * EnvConditions: Mobile that can run ohos test framework
77 * CaseDescription: Verify if post AttachApplication task success
78 */
79 HWTEST_F(AmsServiceEventDriveTest, EventDrive_001, TestSize.Level1)
80 {
81 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_001 start");
82
83 std::shared_ptr<MockAppMgrServiceInner> innerService = std::make_shared<MockAppMgrServiceInner>();
84 appMgrService_->SetInnerService(innerService);
85 appMgrService_->OnStart();
86 innerService->SetWaitCount(2);
87
88 EXPECT_CALL(*innerService, AddAppDeathRecipient(_, _))
89 .WillOnce(InvokeWithoutArgs(innerService.get(), &MockAppMgrServiceInner::Post));
90 EXPECT_CALL(*innerService, AttachApplication(_, _))
91 .WillOnce(InvokeWithoutArgs(innerService.get(), &MockAppMgrServiceInner::Post));
92
93 sptr<IRemoteObject> client;
94 appMgrService_->AttachApplication(client);
95 innerService->Wait();
96
97 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_001 end");
98 }
99
100 /*
101 * Feature: AppMgrService
102 * Function: Service
103 * SubFunction: EventDrive
104 * FunctionPoints: AppMgrService event drive program model
105 * EnvConditions: Mobile that can run ohos test framework
106 * CaseDescription: Verify if post ApplicationForegrounded task success
107 */
108 HWTEST_F(AmsServiceEventDriveTest, EventDrive_002, TestSize.Level1)
109 {
110 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_002 start");
111
112 std::shared_ptr<MockAppMgrServiceInner> innerService = std::make_shared<MockAppMgrServiceInner>();
113 std::unique_ptr<AppMgrService> appMgrService = std::make_unique<AppMgrService>();
114 appMgrService->SetInnerService(innerService);
115 appMgrService->OnStart();
116
117 EXPECT_CALL(*innerService, ApplicationForegrounded(_))
118 .WillOnce(InvokeWithoutArgs(innerService.get(), &MockAppMgrServiceInner::Post));
119
120 int32_t recordId = 0;
121 appMgrService->ApplicationForegrounded(recordId);
122 innerService->Wait();
123
124 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_002 end");
125 }
126
127 /*
128 * Feature: AppMgrService
129 * Function: Service
130 * SubFunction: EventDrive
131 * FunctionPoints: AppMgrService event drive program model
132 * EnvConditions: Mobile that can run ohos test framework
133 * CaseDescription: Verify if post ApplicationBackgrounded task success
134 */
135 HWTEST_F(AmsServiceEventDriveTest, EventDrive_003, TestSize.Level1)
136 {
137 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_003 start");
138
139 std::shared_ptr<MockAppMgrServiceInner> innerService = std::make_shared<MockAppMgrServiceInner>();
140 appMgrService_->SetInnerService(innerService);
141 appMgrService_->OnStart();
142
143 EXPECT_CALL(*innerService, ApplicationBackgrounded(_))
144 .WillOnce(InvokeWithoutArgs(innerService.get(), &MockAppMgrServiceInner::Post));
145
146 int32_t recordId = 0;
147 appMgrService_->ApplicationBackgrounded(recordId);
148 innerService->Wait();
149
150 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_003 end");
151 }
152
153 /*
154 * Feature: AppMgrService
155 * Function: Service
156 * SubFunction: EventDrive
157 * FunctionPoints: AppMgrService event drive program model
158 * EnvConditions: Mobile that can run ohos test framework
159 * CaseDescription: Verify if post ApplicationTerminated task success
160 */
161 HWTEST_F(AmsServiceEventDriveTest, EventDrive_004, TestSize.Level1)
162 {
163 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_004 start");
164
165 std::shared_ptr<MockAppMgrServiceInner> innerService = std::make_shared<MockAppMgrServiceInner>();
166 appMgrService_->SetInnerService(innerService);
167 appMgrService_->OnStart();
168
169 EXPECT_CALL(*innerService, ApplicationTerminated(_))
170 .WillOnce(InvokeWithoutArgs(innerService.get(), &MockAppMgrServiceInner::Post));
171
172 int32_t recordId = 0;
173 appMgrService_->ApplicationTerminated(recordId);
174 innerService->Wait();
175
176 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_004 end");
177 }
178
179 /*
180 * Feature: AppMgrService
181 * Function: Service
182 * SubFunction: EventDrive
183 * FunctionPoints: AppMgrService event drive program model
184 * EnvConditions: Mobile that can run ohos test framework
185 * CaseDescription: Verify if post ClearUpApplicationData task success
186 */
187 HWTEST_F(AmsServiceEventDriveTest, EventDrive_006, TestSize.Level1)
188 {
189 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_006 start");
190
191 auto appMgrService = std::make_shared<AppMgrService>();
192 std::shared_ptr<OHOS::AAFwk::TaskHandlerWrap> taskHandler_ =
193 OHOS::AAFwk::TaskHandlerWrap::CreateQueueHandler(Constants::APP_MGR_SERVICE_NAME);
194 std::string bundleName = "bundleName";
195 appMgrService->SetInnerService(std::make_shared<AppMgrServiceInner>());
196 appMgrService->eventHandler_ = std::make_shared<AMSEventHandler>(taskHandler_, appMgrService->appMgrServiceInner_);
197 int32_t res = appMgrService->ClearUpApplicationData(bundleName, 0);
198 EXPECT_EQ(res, OHOS::ERR_INVALID_OPERATION);
199
200 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_006 end");
201 }
202
203 /*
204 * Feature: AppMgrService
205 * Function: Service
206 * SubFunction: EventDrive
207 * FunctionPoints: AppMgrService event drive program model
208 * EnvConditions: Mobile that can run ohos test framework
209 * CaseDescription: Verify if post IsBackgroundRunningRestricted task success
210 */
211 HWTEST_F(AmsServiceEventDriveTest, EventDrive_008, TestSize.Level1)
212 {
213 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_008 start");
214
215 std::shared_ptr<MockAppMgrServiceInner> innerService = std::make_shared<MockAppMgrServiceInner>();
216 appMgrService_->SetInnerService(innerService);
217 appMgrService_->OnStart();
218
219 EXPECT_CALL(*innerService, GetAllRunningProcesses(_)).WillOnce(Return(0));
220
221 std::vector<RunningProcessInfo> runningProcessInfo;
222 EXPECT_EQ(0, appMgrService_->GetAllRunningProcesses(runningProcessInfo));
223
224 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_008 end");
225 }
226
227 /*
228 * Feature: AppMgrService
229 * Function: Service
230 * SubFunction: EventDrive
231 * FunctionPoints: AppMgrService event drive program model
232 * EnvConditions: Mobile that can run ohos test framework
233 * CaseDescription: Verify if AttachApplication act normal without initialize AppMgrService
234 */
235 HWTEST_F(AmsServiceEventDriveTest, EventDrive_009, TestSize.Level1)
236 {
237 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_009 start");
238
239 appMgrService_->OnStop();
240 std::shared_ptr<MockAppMgrServiceInner> innerService = std::make_shared<MockAppMgrServiceInner>();
241 appMgrService_->SetInnerService(innerService);
242
243 EXPECT_CALL(*innerService, AttachApplication(_, _)).Times(0);
244
245 sptr<IRemoteObject> client;
246 appMgrService_->AttachApplication(client);
247
248 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_009 end");
249 }
250
251 /*
252 * Feature: AppMgrService
253 * Function: Service
254 * SubFunction: EventDrive
255 * FunctionPoints: AppMgrService event drive program model
256 * EnvConditions: Mobile that can run ohos test framework
257 * CaseDescription: Verify if ApplicationForegrounded act normal without initialize AppMgrService
258 */
259 HWTEST_F(AmsServiceEventDriveTest, EventDrive_010, TestSize.Level1)
260 {
261 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_010 start");
262
263 appMgrService_->OnStop();
264 std::shared_ptr<MockAppMgrServiceInner> innerService = std::make_shared<MockAppMgrServiceInner>();
265 appMgrService_->SetInnerService(innerService);
266
267 EXPECT_CALL(*innerService, ApplicationForegrounded(_)).Times(0);
268
269 int32_t recordId = 0;
270 appMgrService_->ApplicationForegrounded(recordId);
271
272 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_010 end");
273 }
274
275 /*
276 * Feature: AppMgrService
277 * Function: Service
278 * SubFunction: EventDrive
279 * FunctionPoints: AppMgrService event drive program model
280 * EnvConditions: Mobile that can run ohos test framework
281 * CaseDescription: Verify if ApplicationBackgrounded act normal without initialize AppMgrService
282 */
283 HWTEST_F(AmsServiceEventDriveTest, EventDrive_011, TestSize.Level1)
284 {
285 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_011 start");
286
287 appMgrService_->OnStop();
288 std::shared_ptr<MockAppMgrServiceInner> innerService = std::make_shared<MockAppMgrServiceInner>();
289 appMgrService_->SetInnerService(innerService);
290
291 EXPECT_CALL(*innerService, ApplicationBackgrounded(_)).Times(0);
292
293 int32_t recordId = 0;
294 appMgrService_->ApplicationBackgrounded(recordId);
295
296 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_011 end");
297 }
298
299 /*
300 * Feature: AppMgrService
301 * Function: Service
302 * SubFunction: EventDrive
303 * FunctionPoints: AppMgrService event drive program model
304 * EnvConditions: Mobile that can run ohos test framework
305 * CaseDescription: Verify if ApplicationTerminated act normal without initialize AppMgrService
306 */
307 HWTEST_F(AmsServiceEventDriveTest, EventDrive_012, TestSize.Level1)
308 {
309 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_012 start");
310
311 appMgrService_->OnStop();
312 std::shared_ptr<MockAppMgrServiceInner> innerService = std::make_shared<MockAppMgrServiceInner>();
313 appMgrService_->SetInnerService(innerService);
314
315 EXPECT_CALL(*innerService, ApplicationTerminated(_)).Times(0);
316
317 int32_t recordId = 0;
318 appMgrService_->ApplicationTerminated(recordId);
319
320 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_012 end");
321 }
322
323 /*
324 * Feature: AppMgrService
325 * Function: Service
326 * SubFunction: EventDrive
327 * FunctionPoints: AppMgrService event drive program model
328 * EnvConditions: Mobile that can run ohos test framework
329 * CaseDescription: Verify if AbilityCleaned act normal without initialize AppMgrService
330 */
331 HWTEST_F(AmsServiceEventDriveTest, EventDrive_013, TestSize.Level1)
332 {
333 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_013 start");
334
335 appMgrService_->OnStop();
336 std::shared_ptr<MockAppMgrServiceInner> innerService = std::make_shared<MockAppMgrServiceInner>();
337 appMgrService_->SetInnerService(innerService);
338
339 EXPECT_CALL(*innerService, AbilityTerminated(_)).Times(0);
340
341 sptr<IRemoteObject> token;
342 appMgrService_->AbilityCleaned(token);
343
344 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_013 end");
345 }
346
347 /*
348 * Feature: AppMgrService
349 * Function: Service
350 * SubFunction: EventDrive
351 * FunctionPoints: AppMgrService event drive program model
352 * EnvConditions: Mobile that can run ohos test framework
353 * CaseDescription: Verify if ClearUpApplicationData act normal without initialize AppMgrService
354 */
355 HWTEST_F(AmsServiceEventDriveTest, EventDrive_014, TestSize.Level1)
356 {
357 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_014 start");
358
359 appMgrService_->OnStop();
360 std::shared_ptr<MockAppMgrServiceInner> innerService = std::make_shared<MockAppMgrServiceInner>();
361 appMgrService_->SetInnerService(innerService);
362
363 std::string bundleName = "bundleName";
364 int32_t res = appMgrService_->ClearUpApplicationData(bundleName, 0);
365 EXPECT_EQ(res, OHOS::ERR_INVALID_OPERATION);
366
367 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_014 end");
368 }
369
370 /*
371 * Feature: AppMgrService
372 * Function: Service
373 * SubFunction: EventDrive
374 * FunctionPoints: AppMgrService event drive program model
375 * EnvConditions: Mobile that can run ohos test framework
376 * CaseDescription: Verify if GetAllRunningProcesses act normal after AppMgrService stopped
377 */
378 HWTEST_F(AmsServiceEventDriveTest, EventDrive_016, TestSize.Level1)
379 {
380 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_016 start");
381
382 appMgrService_->OnStop();
383 std::shared_ptr<MockAppMgrServiceInner> innerService = std::make_shared<MockAppMgrServiceInner>();
384 appMgrService_->SetInnerService(innerService);
385
386 std::vector<RunningProcessInfo> runningProcessInfo;
387 EXPECT_EQ(OHOS::ERR_INVALID_OPERATION, appMgrService_->GetAllRunningProcesses(runningProcessInfo));
388
389 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_016 end");
390 }
391
392 /*
393 * Feature: AppMgrService
394 * Function: Service
395 * SubFunction: EventDrive
396 * FunctionPoints: AppMgrService event drive program model
397 * EnvConditions: Mobile that can run ohos test framework
398 * CaseDescription: Verify if AttachApplication act normal after AppMgrService stopped
399 */
400 HWTEST_F(AmsServiceEventDriveTest, EventDrive_017, TestSize.Level1)
401 {
402 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_017 start");
403
404 std::shared_ptr<MockAppMgrServiceInner> innerService = std::make_shared<MockAppMgrServiceInner>();
405 appMgrService_->SetInnerService(innerService);
406 appMgrService_->OnStart();
407 appMgrService_->OnStop();
408
409 EXPECT_CALL(*innerService, AttachApplication(_, _)).Times(0);
410
411 sptr<IRemoteObject> client;
412 appMgrService_->AttachApplication(client);
413
414 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_017 end");
415 }
416
417 /*
418 * Feature: AppMgrService
419 * Function: Service
420 * SubFunction: EventDrive
421 * FunctionPoints: AppMgrService event drive program model
422 * EnvConditions: Mobile that can run ohos test framework
423 * CaseDescription: Verify if ApplicationForegrounded act normal after AppMgrService stopped
424 */
425 HWTEST_F(AmsServiceEventDriveTest, EventDrive_018, TestSize.Level1)
426 {
427 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_018 start");
428
429 std::shared_ptr<MockAppMgrServiceInner> innerService = std::make_shared<MockAppMgrServiceInner>();
430 appMgrService_->SetInnerService(innerService);
431 appMgrService_->OnStart();
432 appMgrService_->OnStop();
433
434 EXPECT_CALL(*innerService, ApplicationForegrounded(_)).Times(0);
435
436 int32_t recordId = 0;
437 appMgrService_->ApplicationForegrounded(recordId);
438
439 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_018 end");
440 }
441
442 /*
443 * Feature: AppMgrService
444 * Function: Service
445 * SubFunction: EventDrive
446 * FunctionPoints: AppMgrService event drive program model
447 * EnvConditions: Mobile that can run ohos test framework
448 * CaseDescription: Verify if ApplicationBackgrounded act normal after AppMgrService stopped
449 */
450 HWTEST_F(AmsServiceEventDriveTest, EventDrive_019, TestSize.Level1)
451 {
452 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_019 start");
453
454 std::shared_ptr<MockAppMgrServiceInner> innerService = std::make_shared<MockAppMgrServiceInner>();
455 appMgrService_->SetInnerService(innerService);
456 appMgrService_->OnStart();
457 appMgrService_->OnStop();
458
459 EXPECT_CALL(*innerService, ApplicationBackgrounded(_)).Times(0);
460
461 int32_t recordId = 0;
462 appMgrService_->ApplicationBackgrounded(recordId);
463
464 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_019 end");
465 }
466
467 /*
468 * Feature: AppMgrService
469 * Function: Service
470 * SubFunction: EventDrive
471 * FunctionPoints: AppMgrService event drive program model
472 * EnvConditions: Mobile that can run ohos test framework
473 * CaseDescription: Verify if ApplicationTerminated act normal after AppMgrService stopped
474 */
475 HWTEST_F(AmsServiceEventDriveTest, EventDrive_020, TestSize.Level1)
476 {
477 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_020 start");
478
479 std::shared_ptr<MockAppMgrServiceInner> innerService = std::make_shared<MockAppMgrServiceInner>();
480 appMgrService_->SetInnerService(innerService);
481 appMgrService_->OnStart();
482 appMgrService_->OnStop();
483
484 EXPECT_CALL(*innerService, ApplicationTerminated(_)).Times(0);
485
486 int32_t recordId = 0;
487 appMgrService_->ApplicationTerminated(recordId);
488
489 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_020 end");
490 }
491
492 /*
493 * Feature: AppMgrService
494 * Function: Service
495 * SubFunction: EventDrive
496 * FunctionPoints: AppMgrService event drive program model
497 * EnvConditions: Mobile that can run ohos test framework
498 * CaseDescription: Verify if AbilityCleaned act normal after AppMgrService stopped
499 */
500 HWTEST_F(AmsServiceEventDriveTest, EventDrive_021, TestSize.Level1)
501 {
502 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_021 start");
503 std::shared_ptr<MockAppMgrServiceInner> innerService = std::make_shared<MockAppMgrServiceInner>();
504 appMgrService_->SetInnerService(innerService);
505 appMgrService_->OnStart();
506 appMgrService_->OnStop();
507
508 EXPECT_CALL(*innerService, AbilityTerminated(_)).Times(0);
509
510 sptr<IRemoteObject> token;
511 appMgrService_->AbilityCleaned(token);
512
513 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_021 end");
514 }
515
516 /*
517 * Feature: AppMgrService
518 * Function: Service
519 * SubFunction: EventDrive
520 * FunctionPoints: AppMgrService event drive program model
521 * EnvConditions: Mobile that can run ohos test framework
522 * CaseDescription: Verify if ClearUpApplicationData act normal after AppMgrService stopped
523 */
524 HWTEST_F(AmsServiceEventDriveTest, EventDrive_022, TestSize.Level1)
525 {
526 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_022 start");
527 std::shared_ptr<MockAppMgrServiceInner> innerService = std::make_shared<MockAppMgrServiceInner>();
528 appMgrService_->SetInnerService(innerService);
529 appMgrService_->OnStart();
530 appMgrService_->OnStop();
531
532 std::string bundleName = "bundleName";
533 int32_t res = appMgrService_->ClearUpApplicationData(bundleName, 0);
534 EXPECT_EQ(res, OHOS::ERR_INVALID_OPERATION);
535
536 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_022 end");
537 }
538
539 /*
540 * Feature: AppMgrService
541 * Function: Service
542 * SubFunction: EventDrive
543 * FunctionPoints: AppMgrService event drive program model
544 * EnvConditions: Mobile that can run ohos test framework
545 * CaseDescription: Verify if GetAllRunningProcesses act normal after AppMgrService stopped
546 */
547 HWTEST_F(AmsServiceEventDriveTest, EventDrive_024, TestSize.Level1)
548 {
549 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_024 start");
550 std::shared_ptr<MockAppMgrServiceInner> innerService = std::make_shared<MockAppMgrServiceInner>();
551 appMgrService_->SetInnerService(innerService);
552 appMgrService_->OnStart();
553 appMgrService_->OnStop();
554
555 appMgrService_->SetInnerService(innerService);
556
557 std::vector<RunningProcessInfo> runningProcessInfo;
558 EXPECT_EQ(OHOS::ERR_INVALID_OPERATION, appMgrService_->GetAllRunningProcesses(runningProcessInfo));
559
560 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_024 end");
561 }
562
563 /*
564 * Feature: AppMgrService
565 * Function: Service
566 * SubFunction: EventDrive
567 * FunctionPoints: AppMgrService event drive program model
568 * EnvConditions: Mobile that can run ohos test framework
569 * CaseDescription: Verify if post application from background to foreground task act normal
570 */
571 HWTEST_F(AmsServiceEventDriveTest, EventDrive_025, TestSize.Level1)
572 {
573 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_025 start");
574 std::shared_ptr<MockAppMgrServiceInner> innerService = std::make_shared<MockAppMgrServiceInner>();
575 appMgrService_->SetInnerService(innerService);
576 appMgrService_->OnStart();
577 int32_t waitCount = 2;
578 innerService->SetWaitCount(waitCount);
579
580 EXPECT_CALL(*innerService, ApplicationBackgrounded(_))
581 .WillOnce(InvokeWithoutArgs(innerService.get(), &MockAppMgrServiceInner::Post));
582 EXPECT_CALL(*innerService, ApplicationForegrounded(_))
583 .WillOnce(InvokeWithoutArgs(innerService.get(), &MockAppMgrServiceInner::Post));
584
585 int32_t recordId = 0;
586 appMgrService_->ApplicationBackgrounded(recordId);
587 appMgrService_->ApplicationForegrounded(recordId);
588 innerService->Wait();
589 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_025 end");
590 }
591
592 /*
593 * Feature: AppMgrService
594 * Function: Service
595 * SubFunction: EventDrive
596 * FunctionPoints: AppMgrService event drive program model
597 * EnvConditions: Mobile that can run ohos test framework
598 * CaseDescription: Verify if post application from foreground to background task act normal
599 */
600 HWTEST_F(AmsServiceEventDriveTest, EventDrive_026, TestSize.Level1)
601 {
602 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_026 start");
603 std::shared_ptr<MockAppMgrServiceInner> innerService = std::make_shared<MockAppMgrServiceInner>();
604 appMgrService_->SetInnerService(innerService);
605 appMgrService_->OnStart();
606 int32_t waitCount = 2;
607 innerService->SetWaitCount(waitCount);
608
609 EXPECT_CALL(*innerService, ApplicationForegrounded(_))
610 .WillOnce(InvokeWithoutArgs(innerService.get(), &MockAppMgrServiceInner::Post));
611 EXPECT_CALL(*innerService, ApplicationBackgrounded(_))
612 .WillOnce(InvokeWithoutArgs(innerService.get(), &MockAppMgrServiceInner::Post));
613
614 int32_t recordId = 0;
615 appMgrService_->ApplicationForegrounded(recordId);
616 appMgrService_->ApplicationBackgrounded(recordId);
617 innerService->Wait();
618 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_026 end");
619 }
620
621 /*
622 * Feature: AppMgrService
623 * Function: Service
624 * SubFunction: EventDrive
625 * FunctionPoints: AppMgrService event drive program model
626 * EnvConditions: Mobile that can run ohos test framework
627 * CaseDescription: Verify if post application from background to terminate task act normal
628 */
629 HWTEST_F(AmsServiceEventDriveTest, EventDrive_027, TestSize.Level1)
630 {
631 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_027 start");
632 std::shared_ptr<MockAppMgrServiceInner> innerService = std::make_shared<MockAppMgrServiceInner>();
633 appMgrService_->SetInnerService(innerService);
634 appMgrService_->OnStart();
635 int32_t waitCount = 2;
636 innerService->SetWaitCount(waitCount);
637
638 EXPECT_CALL(*innerService, ApplicationBackgrounded(_))
639 .WillOnce(InvokeWithoutArgs(innerService.get(), &MockAppMgrServiceInner::Post));
640 EXPECT_CALL(*innerService, ApplicationTerminated(_))
641 .WillOnce(InvokeWithoutArgs(innerService.get(), &MockAppMgrServiceInner::Post));
642
643 int32_t recordId = 0;
644 appMgrService_->ApplicationBackgrounded(recordId);
645 appMgrService_->ApplicationTerminated(recordId);
646 innerService->Wait();
647 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_027 end");
648 }
649
650 /*
651 * Feature: AppMgrService
652 * Function: Service
653 * SubFunction: EventDrive
654 * FunctionPoints: AppMgrService event drive program model
655 * EnvConditions: Mobile that can run ohos test framework
656 * CaseDescription: Verify if post application from foreground to terminated task act normal
657 */
658 HWTEST_F(AmsServiceEventDriveTest, EventDrive_028, TestSize.Level1)
659 {
660 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_028 start");
661 std::shared_ptr<MockAppMgrServiceInner> innerService = std::make_shared<MockAppMgrServiceInner>();
662 appMgrService_->SetInnerService(innerService);
663 appMgrService_->OnStart();
664 int32_t waitCount = 2;
665 innerService->SetWaitCount(waitCount);
666
667 EXPECT_CALL(*innerService, ApplicationForegrounded(_))
668 .WillOnce(InvokeWithoutArgs(innerService.get(), &MockAppMgrServiceInner::Post));
669 EXPECT_CALL(*innerService, ApplicationTerminated(_))
670 .WillOnce(InvokeWithoutArgs(innerService.get(), &MockAppMgrServiceInner::Post));
671
672 int32_t recordId = 0;
673 appMgrService_->ApplicationForegrounded(recordId);
674 appMgrService_->ApplicationTerminated(recordId);
675 innerService->Wait();
676 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_028 end");
677 }
678
679 /*
680 * Feature: AppMgrService
681 * Function: Service
682 * SubFunction: EventDrive
683 * FunctionPoints: AppMgrService event drive program model
684 * EnvConditions: Mobile that can run ohos test framework
685 * CaseDescription: Verify if post application from terminate to foreground task act normal
686 */
687 HWTEST_F(AmsServiceEventDriveTest, EventDrive_029, TestSize.Level1)
688 {
689 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_029 start");
690 std::shared_ptr<MockAppMgrServiceInner> innerService = std::make_shared<MockAppMgrServiceInner>();
691 appMgrService_->SetInnerService(innerService);
692 appMgrService_->OnStart();
693 int32_t waitCount = 2;
694 innerService->SetWaitCount(waitCount);
695
696 EXPECT_CALL(*innerService, ApplicationTerminated(_))
697 .WillOnce(InvokeWithoutArgs(innerService.get(), &MockAppMgrServiceInner::Post));
698 EXPECT_CALL(*innerService, ApplicationForegrounded(_))
699 .WillOnce(InvokeWithoutArgs(innerService.get(), &MockAppMgrServiceInner::Post));
700
701 int32_t recordId = 0;
702 appMgrService_->ApplicationTerminated(recordId);
703 appMgrService_->ApplicationForegrounded(recordId);
704 innerService->Wait();
705 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_029 end");
706 }
707
708 /*
709 * Feature: AppMgrService
710 * Function: Service
711 * SubFunction: EventDrive
712 * FunctionPoints: AppMgrService event drive program model
713 * EnvConditions: Mobile that can run ohos test framework.
714 * CaseDescription: Verify if post application from terminate to background task act normal
715 */
716 HWTEST_F(AmsServiceEventDriveTest, EventDrive_030, TestSize.Level1)
717 {
718 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_030 start");
719 std::shared_ptr<MockAppMgrServiceInner> innerService = std::make_shared<MockAppMgrServiceInner>();
720 appMgrService_->SetInnerService(innerService);
721 appMgrService_->OnStart();
722 int32_t waitCount = 2;
723 innerService->SetWaitCount(waitCount);
724
725 EXPECT_CALL(*innerService, ApplicationTerminated(_))
726 .WillOnce(InvokeWithoutArgs(innerService.get(), &MockAppMgrServiceInner::Post));
727 EXPECT_CALL(*innerService, ApplicationBackgrounded(_))
728 .WillOnce(InvokeWithoutArgs(innerService.get(), &MockAppMgrServiceInner::Post));
729
730 int32_t recordId = 0;
731 appMgrService_->ApplicationTerminated(recordId);
732 appMgrService_->ApplicationBackgrounded(recordId);
733 innerService->Wait();
734 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_030 end");
735 }
736
737 /*
738 * Feature: AppMgrService
739 * Function: Service
740 * SubFunction: EventDrive
741 * FunctionPoints: AppMgrService event drive program model
742 * EnvConditions: Mobile that can run ohos test framework
743 * CaseDescription: Verify if QueryServiceState act normal
744 */
745 HWTEST_F(AmsServiceEventDriveTest, EventDrive_037, TestSize.Level1)
746 {
747 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_037 start");
748
749 std::shared_ptr<MockAppMgrServiceInner> innerService = std::make_shared<MockAppMgrServiceInner>();
750 appMgrService_->SetInnerService(innerService);
751 appMgrService_->OnStart();
752
753 EXPECT_CALL(*innerService, QueryAppSpawnConnectionState())
754 .WillRepeatedly(Return(SpawnConnectionState::STATE_CONNECTED));
755 EXPECT_EQ(ServiceRunningState::STATE_RUNNING, appMgrService_->QueryServiceState().serviceRunningState);
756 EXPECT_EQ(SpawnConnectionState::STATE_CONNECTED, appMgrService_->QueryServiceState().connectionState);
757
758 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_037 end");
759 }
760
761 /*
762 * Feature: AppMgrService
763 * Function: Service
764 * SubFunction: EventDrive
765 * FunctionPoints: AppMgrService event drive program model
766 * EnvConditions: Mobile that can run ohos test framework
767 * CaseDescription: Verify if QueryServiceState act normal without initialize AppMgrService
768 */
769 HWTEST_F(AmsServiceEventDriveTest, EventDrive_038, TestSize.Level1)
770 {
771 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_038 start");
772
773 appMgrService_->OnStop();
774 std::shared_ptr<MockAppMgrServiceInner> innerService = std::make_shared<MockAppMgrServiceInner>();
775 appMgrService_->SetInnerService(innerService);
776
777 EXPECT_CALL(*innerService, QueryAppSpawnConnectionState()).Times(2);
778 EXPECT_EQ(ServiceRunningState::STATE_NOT_START, appMgrService_->QueryServiceState().serviceRunningState);
779 EXPECT_EQ(SpawnConnectionState::STATE_NOT_CONNECT, appMgrService_->QueryServiceState().connectionState);
780
781 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_038 end");
782 }
783
784 /*
785 * Feature: AppMgrService
786 * Function: Service
787 * SubFunction: EventDrive
788 * FunctionPoints: AppMgrService event drive program model
789 * EnvConditions: Mobile that can run ohos test framework
790 * CaseDescription: Verify if QueryServiceState act normal after AppMgrService stopped
791 */
792 HWTEST_F(AmsServiceEventDriveTest, EventDrive_039, TestSize.Level1)
793 {
794 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_039 start");
795
796 std::shared_ptr<MockAppMgrServiceInner> innerService = std::make_shared<MockAppMgrServiceInner>();
797 appMgrService_->SetInnerService(innerService);
798 appMgrService_->OnStart();
799 appMgrService_->OnStop();
800
801 EXPECT_CALL(*innerService, QueryAppSpawnConnectionState()).Times(2);
802 EXPECT_EQ(ServiceRunningState::STATE_NOT_START, appMgrService_->QueryServiceState().serviceRunningState);
803 EXPECT_EQ(SpawnConnectionState::STATE_NOT_CONNECT, appMgrService_->QueryServiceState().connectionState);
804
805 TAG_LOGI(AAFwkTag::TEST, "ams_service_event_drive_test_039 end");
806 }
807