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 <climits>
17 #include <gtest/gtest.h>
18
19 #include "ability_impl_factory.h"
20 #include "ability_loader.h"
21 #include "ability_local_record.h"
22 #include "context_deal.h"
23 #include "data_ability_helper.h"
24 #include "ability_manager_client.h"
25 #include "ability_manager_interface.h"
26 #include "demo_ability_test.h"
27 #include "fa_ability_thread.h"
28 #include "mock_ability_manager_service.h"
29 #include "mock_bundle_manager.h"
30 #include "ohos_application.h"
31 #include "sys_mgr_client.h"
32 #include "system_ability_definition.h"
33
34 namespace OHOS {
35 namespace AppExecFwk {
36 using namespace testing::ext;
37 using namespace OHOS;
38 using namespace AAFwk;
39 using OHOS::AppExecFwk::ElementName;
40 using namespace OHOS::AppExecFwk;
41 /*
42 * Parameters:
43 * Action
44 * Entity
45 * Flag
46 * ElementName
47 */
48 const std::string ABILITY_NAME("DemoAbility");
49 class AbilityBaseTest : public testing::Test {
50 public:
51 static void SetUpTestCase(void);
52 static void TearDownTestCase(void);
53 void SetUp();
54 void TearDown();
55 OHOS::sptr<OHOS::IRemoteObject> abilityObject_;
56 static constexpr int TEST_WAIT_TIME = 500 * 1000; // 500 ms
57 static const int RESULT_CODE = 1992;
58 };
59
SetUpTestCase(void)60 void AbilityBaseTest::SetUpTestCase(void)
61 {}
62
TearDownTestCase(void)63 void AbilityBaseTest::TearDownTestCase(void)
64 {}
65
SetUp(void)66 void AbilityBaseTest::SetUp(void)
67 {
68 abilityObject_ = new MockAbilityManagerService();
69 auto sysMgr = OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance();
70 EXPECT_TRUE(sysMgr != nullptr);
71 sysMgr->RegisterSystemAbility(OHOS::ABILITY_MGR_SERVICE_ID, abilityObject_);
72 sysMgr->RegisterSystemAbility(OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, new BundleMgrService());
73 }
74
TearDown(void)75 void AbilityBaseTest::TearDown(void)
76 {
77 abilityObject_ = nullptr;
78 }
79
80 /**
81 * @tc.number: AaFwk_Ability_AbilityFwk_Start_Test_0100
82 * @tc.name: AbilityFwk Start
83 * @tc.desc: The first step of startability is the attach AMS.
84 */
85 HWTEST_F(AbilityBaseTest, AaFwk_Ability_AbilityFwk_Start_Test_0100, Function | MediumTest | Level1)
86 {
87 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
88
89 sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityRuntime::FAAbilityThread());
90 EXPECT_NE(abilityToken, nullptr);
91 if (abilityToken != nullptr) {
92 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
93 abilityInfo->type = AppExecFwk::AbilityType::PAGE;
94 abilityInfo->name = ABILITY_NAME;
95 abilityInfo->isNativeAbility = true;
96 std::shared_ptr<AbilityLocalRecord> abilityRecord =
97 std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
98
99 AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
100 usleep(AbilityBaseTest::TEST_WAIT_TIME);
101 }
102 }
103
104 /**
105 * @tc.number: AaFwk_Ability_AbilityFwk_Start_Test_0200
106 * @tc.name: AbilityFwk Start
107 * @tc.desc: When connecting AMS,the instance of application is empty.
108 */
109 HWTEST_F(AbilityBaseTest, AaFwk_Ability_AbilityFwk_Start_Test_0200, Function | MediumTest | Level1)
110 {
111 std::shared_ptr<OHOSApplication> application = nullptr;
112
113 sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityRuntime::FAAbilityThread());
114 EXPECT_NE(abilityToken, nullptr);
115 if (abilityToken != nullptr) {
116 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
117 abilityInfo->type = AppExecFwk::AbilityType::PAGE;
118 abilityInfo->name = ABILITY_NAME;
119 abilityInfo->isNativeAbility = true;
120 std::shared_ptr<AbilityLocalRecord> abilityRecord =
121 std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
122
123 AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
124 usleep(AbilityBaseTest::TEST_WAIT_TIME);
125 }
126 }
127
128 /**
129 * @tc.number: AaFwk_Ability_AbilityFwk_Start_Test_0300
130 * @tc.name: AbilityFwk Start
131 * @tc.desc: When connecting AMS,the instance of abilityRecord is empty
132 */
133 HWTEST_F(AbilityBaseTest, AaFwk_Ability_AbilityFwk_Start_Test_0300, Function | MediumTest | Level1)
134 {
135 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
136
137 std::shared_ptr<AbilityLocalRecord> abilityRecord = nullptr;
138
139 AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
140 usleep(AbilityBaseTest::TEST_WAIT_TIME);
141 }
142
143 /**
144 * @tc.number: AaFwk_Ability_AbilityFwk_Start_Test_0400
145 * @tc.name: AbilityFwk Start
146 * @tc.desc: The ability name is empty, so the ability instance cannot be created.
147 */
148 HWTEST_F(AbilityBaseTest, AaFwk_Ability_AbilityFwk_Start_Test_0400, Function | MediumTest | Level1)
149 {
150 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
151
152 sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityRuntime::FAAbilityThread());
153 EXPECT_NE(abilityToken, nullptr);
154 if (abilityToken != nullptr) {
155 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
156 abilityInfo->type = AppExecFwk::AbilityType::PAGE;
157 std::shared_ptr<AbilityLocalRecord> abilityRecord =
158 std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
159
160 AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
161 usleep(AbilityBaseTest::TEST_WAIT_TIME);
162 }
163 }
164
165 /**
166 * @tc.number: AaFwk_Ability_AbilityFwk_Start_Test_0500
167 * @tc.name: AbilityFwk Start
168 * @tc.desc: The ability type is unknown, so the AbilityImpl instance cannot be created.
169 */
170 HWTEST_F(AbilityBaseTest, AaFwk_Ability_AbilityFwk_Start_Test_0500, Function | MediumTest | Level1)
171 {
172 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
173
174 sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityRuntime::FAAbilityThread());
175 EXPECT_NE(abilityToken, nullptr);
176 if (abilityToken != nullptr) {
177 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
178 abilityInfo->name = ABILITY_NAME;
179 abilityInfo->isNativeAbility = true;
180 std::shared_ptr<AbilityLocalRecord> abilityRecord =
181 std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
182
183 AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
184 usleep(AbilityBaseTest::TEST_WAIT_TIME);
185 }
186 }
187
188 /**
189 * @tc.number: AaFwk_Ability_AbilityFwk_Start_Test_0600
190 * @tc.name: AbilityFwk Start
191 * @tc.desc: The interface OnSaveAbilityState()/OnRestoreAbilityState() of demoability was called.
192 */
193 HWTEST_F(AbilityBaseTest, AaFwk_Ability_AbilityFwk_Start_Test_0600, Function | MediumTest | Level1)
194 {
195 std::shared_ptr<ContextDeal> contextDeal = std::make_shared<ContextDeal>();
196 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
197 std::shared_ptr<ApplicationInfo> appInfo = std::make_shared<ApplicationInfo>();
198 std::shared_ptr<ProcessInfo> processInfo = std::make_shared<ProcessInfo>();
199
200 appInfo->codePath = "codePath";
201 appInfo->dataBaseDir = "dataBaseDir";
202 appInfo->dataDir = "dataDir";
203 appInfo->cacheDir = "cacheDir";
204 appInfo->bundleName = "bundleName";
205
206 application->SetProcessInfo(processInfo);
207 contextDeal->SetApplicationInfo(appInfo);
208 contextDeal->SetApplicationContext(application);
209 application->AttachBaseContext(contextDeal);
210
211 sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityRuntime::FAAbilityThread());
212 EXPECT_NE(abilityToken, nullptr);
213 if (abilityToken != nullptr) {
214 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
215 abilityInfo->codePath = "codePath";
216 abilityInfo->resourcePath = "resourcePath";
217
218 abilityInfo->type = AppExecFwk::AbilityType::PAGE;
219 abilityInfo->name = ABILITY_NAME;
220 abilityInfo->isNativeAbility = true;
221 std::shared_ptr<AbilityLocalRecord> abilityRecord =
222 std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
223
224 AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
225
226 sptr<IRemoteObject> remoteObject_ =
227 OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
228 sptr<AAFwk::IAbilityManager> abms = iface_cast<AAFwk::IAbilityManager>(remoteObject_);
229 Want want;
230 sptr<IAbilityConnection> connect = nullptr;
231
232 // Just to test two interfaces OnRestoreAbilityState/OnSaveAbilityState
233 abms->ConnectAbility(want, connect, abilityToken);
234 usleep(AbilityBaseTest::TEST_WAIT_TIME);
235 }
236 }
237
238 /**
239 * @tc.number: AaFwk_Ability_Lifecycle_Test_0100
240 * @tc.name: Ability Lifecycle
241 * @tc.desc: The ability life cycle will change from initial state initial to inactive by calling the interface
242 * OnnStart(), and then to active by calling OnActive().
243 */
244 HWTEST_F(AbilityBaseTest, AaFwk_Ability_Lifecycle_Test_0100, Function | MediumTest | Level1)
245 {
246 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
247
248 sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityRuntime::FAAbilityThread());
249 EXPECT_NE(abilityToken, nullptr);
250 if (abilityToken != nullptr) {
251 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
252 abilityInfo->type = AppExecFwk::AbilityType::PAGE;
253 abilityInfo->name = ABILITY_NAME;
254 abilityInfo->isNativeAbility = true;
255 std::shared_ptr<AbilityLocalRecord> abilityRecord =
256 std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
257
258 AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
259
260 sptr<IRemoteObject> remoteObject_ =
261 OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
262 sptr<AAFwk::IAbilityManager> abms = iface_cast<AAFwk::IAbilityManager>(remoteObject_);
263 Want want;
264 abms->StartAbility(want, AbilityLifeCycleState::ABILITY_STATE_ACTIVE);
265 usleep(AbilityBaseTest::TEST_WAIT_TIME);
266 }
267 }
268
269 /**
270 * @tc.number: AaFwk_Ability_AbilityFwk_Lifecycle_Test_0200
271 * @tc.name: Ability Lifecycle
272 * @tc.desc: The ability life cycle will change from initial state initial to inactive by calling the interface
273 * OnnStart(), and then to active by calling OnNewWant()+OnActive().
274 */
275 HWTEST_F(AbilityBaseTest, AaFwk_Ability_AbilityFwk_Lifecycle_Test_0200, Function | MediumTest | Level1)
276 {
277 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
278
279 sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityRuntime::FAAbilityThread());
280 EXPECT_NE(abilityToken, nullptr);
281 if (abilityToken != nullptr) {
282 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
283 abilityInfo->type = AppExecFwk::AbilityType::PAGE;
284 abilityInfo->name = ABILITY_NAME;
285 abilityInfo->isNativeAbility = true;
286 std::shared_ptr<AbilityLocalRecord> abilityRecord =
287 std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
288
289 AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
290
291 sptr<IRemoteObject> remoteObject_ =
292 OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
293 sptr<AAFwk::IAbilityManager> abms = iface_cast<AAFwk::IAbilityManager>(remoteObject_);
294
295 abms->DisconnectAbility(nullptr);
296 usleep(AbilityBaseTest::TEST_WAIT_TIME);
297 }
298 }
299
300 /**
301 * @tc.number: AaFwk_Ability_AbilityFwk_Lifecycle_Test_0300
302 * @tc.name: Ability Lifecycle
303 * @tc.desc: Ability life cycle changes: initial - > active - > background, the interface of demoability will be
304 called:
305 * OnStart()->OnActive()->OnInactive()->OnBackground().
306 */
307 HWTEST_F(AbilityBaseTest, AaFwk_Ability_AbilityFwk_Lifecycle_Test_0300, Function | MediumTest | Level1)
308 {
309 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
310
311 sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityRuntime::FAAbilityThread());
312 EXPECT_NE(abilityToken, nullptr);
313 if (abilityToken != nullptr) {
314 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
315 abilityInfo->type = AppExecFwk::AbilityType::PAGE;
316 abilityInfo->name = ABILITY_NAME;
317 abilityInfo->isNativeAbility = true;
318 std::shared_ptr<AbilityLocalRecord> abilityRecord =
319 std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
320
321 AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
322
323 sptr<IRemoteObject> remoteObject_ =
324 OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
325 sptr<AAFwk::IAbilityManager> abms = iface_cast<AAFwk::IAbilityManager>(remoteObject_);
326 Want want;
327
328 abms->StartAbility(want, AbilityLifeCycleState::ABILITY_STATE_ACTIVE);
329 usleep(AbilityBaseTest::TEST_WAIT_TIME);
330 abms->StartAbility(want, AbilityLifeCycleState::ABILITY_STATE_BACKGROUND);
331 usleep(AbilityBaseTest::TEST_WAIT_TIME);
332 }
333 }
334
335 /**
336 * @tc.number: AaFwk_Ability_AbilityFwk_Lifecycle_Test_0400
337 * @tc.name: Ability Lifecycle
338 * @tc.desc: Ability life cycle changes: initial - > active - > inactive, the interface of demoability will be
339 called:
340 * OnStart()->OnActive()->OnInactive().
341 */
342 HWTEST_F(AbilityBaseTest, AaFwk_Ability_AbilityFwk_Lifecycle_Test_0400, Function | MediumTest | Level1)
343 {
344 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
345
346 sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityRuntime::FAAbilityThread());
347 EXPECT_NE(abilityToken, nullptr);
348 if (abilityToken != nullptr) {
349 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
350 abilityInfo->type = AppExecFwk::AbilityType::PAGE;
351 abilityInfo->name = ABILITY_NAME;
352 abilityInfo->isNativeAbility = true;
353 std::shared_ptr<AbilityLocalRecord> abilityRecord =
354 std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
355
356 AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
357
358 sptr<IRemoteObject> remoteObject_ =
359 OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
360 sptr<AAFwk::IAbilityManager> abms = iface_cast<AAFwk::IAbilityManager>(remoteObject_);
361 Want want;
362
363 abms->StartAbility(want, AbilityLifeCycleState::ABILITY_STATE_ACTIVE);
364 usleep(AbilityBaseTest::TEST_WAIT_TIME);
365 abms->StartAbility(want, AbilityLifeCycleState::ABILITY_STATE_INACTIVE);
366 usleep(AbilityBaseTest::TEST_WAIT_TIME);
367 }
368 }
369
370 /**
371 * @tc.number: AaFwk_Ability_AbilityFwk_Lifecycle_Test_0500
372 * @tc.name: Ability Lifecycle
373 * @tc.desc: Ability life cycle changes: initial - > active , the interface of demoability will be called:
374 * OnStart()->OnActive()->OnInactive()->OnBackground()->OnForeground().
375 */
376 HWTEST_F(AbilityBaseTest, AaFwk_Ability_AbilityFwk_Lifecycle_Test_0500, Function | MediumTest | Level1)
377 {
378 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
379
380 sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityRuntime::FAAbilityThread());
381 EXPECT_NE(abilityToken, nullptr);
382 if (abilityToken != nullptr) {
383 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
384 abilityInfo->type = AppExecFwk::AbilityType::PAGE;
385 abilityInfo->name = ABILITY_NAME;
386 abilityInfo->isNativeAbility = true;
387 std::shared_ptr<AbilityLocalRecord> abilityRecord =
388 std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
389
390 AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
391
392 sptr<IRemoteObject> remoteObject_ =
393 OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
394 sptr<AAFwk::IAbilityManager> abms = iface_cast<AAFwk::IAbilityManager>(remoteObject_);
395 Want want;
396
397 abms->StartAbility(want, AbilityLifeCycleState::ABILITY_STATE_ACTIVE);
398 usleep(AbilityBaseTest::TEST_WAIT_TIME);
399 abms->StartAbility(want, AbilityLifeCycleState::ABILITY_STATE_BACKGROUND);
400 usleep(AbilityBaseTest::TEST_WAIT_TIME);
401 abms->StartAbility(want, AbilityLifeCycleState::ABILITY_STATE_INACTIVE);
402 usleep(AbilityBaseTest::TEST_WAIT_TIME);
403 }
404 }
405
406 /**
407 * @tc.number: AaFwk_Ability_AbilityFwk_Lifecycle_Test_0600
408 * @tc.name: Ability Lifecycle
409 * @tc.desc: Ability life cycle changes: initial - > active , the interface of demoability will be called:
410 * OnStart()->OnActive()->OnInactive()->OnBackground()->OnStop().
411 */
412 HWTEST_F(AbilityBaseTest, AaFwk_Ability_AbilityFwk_Lifecycle_Test_0600, Function | MediumTest | Level1)
413 {
414 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
415
416 sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityRuntime::FAAbilityThread());
417 EXPECT_NE(abilityToken, nullptr);
418 if (abilityToken != nullptr) {
419 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
420 abilityInfo->type = AppExecFwk::AbilityType::PAGE;
421 abilityInfo->name = ABILITY_NAME;
422 abilityInfo->isNativeAbility = true;
423 std::shared_ptr<AbilityLocalRecord> abilityRecord =
424 std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
425
426 AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
427
428 sptr<IRemoteObject> remoteObject_ =
429 OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
430 sptr<AAFwk::IAbilityManager> abms = iface_cast<AAFwk::IAbilityManager>(remoteObject_);
431 Want want;
432
433 abms->StartAbility(want, AbilityLifeCycleState::ABILITY_STATE_ACTIVE);
434 usleep(AbilityBaseTest::TEST_WAIT_TIME);
435 abms->StartAbility(want, AbilityLifeCycleState::ABILITY_STATE_BACKGROUND);
436 usleep(AbilityBaseTest::TEST_WAIT_TIME);
437 abms->StartAbility(want, AbilityLifeCycleState::ABILITY_STATE_INITIAL);
438 usleep(AbilityBaseTest::TEST_WAIT_TIME);
439 }
440 }
441
442 /**
443 * @tc.number: AaFwk_Ability_TerminateAbility_ForResult_Test_0100
444 * @tc.name: TerminateAbility_ForResult
445 * @tc.desc: 1. TerminateAbility with parameters
446 * 2. AMS returns parameters through sendresult
447 * 3. Compare the returned parameters with the passed in parameters.
448 */
449 HWTEST_F(AbilityBaseTest, AaFwk_Ability_TerminateAbility_ForResult_Test_0100, Function | MediumTest | Level1)
450 {
451 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
452
453 sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityRuntime::FAAbilityThread());
454 EXPECT_NE(abilityToken, nullptr);
455 if (abilityToken != nullptr) {
456 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
457 abilityInfo->type = AppExecFwk::AbilityType::PAGE;
458 abilityInfo->name = ABILITY_NAME;
459 abilityInfo->isNativeAbility = true;
460 std::shared_ptr<AbilityLocalRecord> abilityRecord =
461 std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
462
463 AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
464
465 sptr<IRemoteObject> remoteObject_ =
466 OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
467 sptr<AAFwk::IAbilityManager> abms = iface_cast<AAFwk::IAbilityManager>(remoteObject_);
468 Want want;
469 sptr<IAbilityConnection> connect = nullptr;
470
471 abms->TerminateAbility(nullptr, RESULT_CODE, &want);
472 usleep(AbilityBaseTest::TEST_WAIT_TIME);
473 }
474 }
475
476 /*
477 * Parameters:
478 * Action
479 * Entity
480 * Flag
481 * ElementName
482 */
483 class AbilityTerminateTest : public testing::Test {
484 public:
485 static void SetUpTestCase(void);
486 static void TearDownTestCase(void);
487 void SetUp();
488 void TearDown();
489
490 public:
491 OHOS::sptr<OHOS::IRemoteObject> abilityObject_;
492 static constexpr int TEST_WAIT_TIME = 500 * 1000; // 500 ms
493 static const int RESULT_CODE = 1992;
494 };
495
SetUpTestCase(void)496 void AbilityTerminateTest::SetUpTestCase(void)
497 {}
498
TearDownTestCase(void)499 void AbilityTerminateTest::TearDownTestCase(void)
500 {}
501
SetUp(void)502 void AbilityTerminateTest::SetUp(void)
503 {
504 abilityObject_ = new MockAbilityManagerService();
505 auto sysMgr = OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance();
506 EXPECT_TRUE(sysMgr != nullptr);
507 sysMgr->RegisterSystemAbility(OHOS::ABILITY_MGR_SERVICE_ID, abilityObject_);
508 }
509
TearDown(void)510 void AbilityTerminateTest::TearDown(void)
511 {
512 abilityObject_ = nullptr;
513 }
514
515 /**
516 * @tc.number: AaFwk_Ability_Terminate_test_0100
517 * @tc.name: TerminateAbility
518 * @tc.desc: When the ability state is inactive, the call to terminateability terminates.
519 */
520 HWTEST_F(AbilityTerminateTest, AaFwk_Ability_Terminate_test_0100, Function | MediumTest | Level1)
521 {
522 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
523 sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityRuntime::FAAbilityThread());
524 EXPECT_NE(abilityToken, nullptr);
525 if (abilityToken != nullptr) {
526 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
527 abilityInfo->type = AppExecFwk::AbilityType::PAGE;
528 abilityInfo->name = ABILITY_NAME;
529 abilityInfo->isNativeAbility = true;
530 std::shared_ptr<AbilityLocalRecord> abilityRecord =
531 std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
532
533 GTEST_LOG_(INFO) << "AaFwk_Ability_Terminate_test_001 AbilityThreadMain";
534 AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
535
536 Want want;
537 MockAbilityManagerService* mockAMS = iface_cast<MockAbilityManagerService>(abilityObject_);
538 mockAMS->StartAbility(want, AbilityLifeCycleState::ABILITY_STATE_INACTIVE);
539 usleep(AbilityTerminateTest::TEST_WAIT_TIME);
540
541 auto ability = AbilityLoader::GetInstance().GetAbilityByName(abilityInfo->name);
542 EXPECT_NE(ability, nullptr);
543 if (ability != nullptr) {
544 ability->SetResult(RESULT_CODE, want);
545 ability->TerminateAbility();
546 }
547 usleep(AbilityTerminateTest::TEST_WAIT_TIME);
548 }
549 GTEST_LOG_(INFO) << "AaFwk_Ability_Terminate_test_001 TerminateAbility";
550 }
551
552 /**
553 * @tc.number: AaFwk_Ability_Terminate_test_0200
554 * @tc.name: TerminateAbility
555 * @tc.desc: When the ability state is active, the call to terminateability terminates.
556 */
557 HWTEST_F(AbilityTerminateTest, AaFwk_Ability_Terminate_test_0200, Function | MediumTest | Level1)
558 {
559 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
560 sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityRuntime::FAAbilityThread());
561 EXPECT_NE(abilityToken, nullptr);
562 if (abilityToken != nullptr) {
563 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
564 abilityInfo->type = AppExecFwk::AbilityType::PAGE;
565 abilityInfo->name = ABILITY_NAME;
566 abilityInfo->isNativeAbility = true;
567 std::shared_ptr<AbilityLocalRecord> abilityRecord =
568 std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
569
570 GTEST_LOG_(INFO) << "AaFwk_Ability_Terminate_test_002 AbilityThreadMain";
571 AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
572
573 Want want;
574 MockAbilityManagerService* mockAMS = iface_cast<MockAbilityManagerService>(abilityObject_);
575 mockAMS->StartAbility(want, AbilityLifeCycleState::ABILITY_STATE_ACTIVE);
576 usleep(AbilityTerminateTest::TEST_WAIT_TIME);
577
578 auto ability = AbilityLoader::GetInstance().GetAbilityByName(abilityInfo->name);
579 EXPECT_NE(ability, nullptr);
580 if (ability != nullptr) {
581 ability->SetResult(RESULT_CODE, want);
582 ability->TerminateAbility();
583 }
584 usleep(AbilityTerminateTest::TEST_WAIT_TIME);
585 }
586 GTEST_LOG_(INFO) << "AaFwk_Ability_Terminate_test_002 TerminateAbility";
587 }
588
589 /**
590 * @tc.number: AaFwk_Ability_Terminate_test_0300
591 * @tc.name: TerminateAbility
592 * @tc.desc: When the ability state is BACKGROUND, the call to terminateability terminates.
593 */
594 HWTEST_F(AbilityTerminateTest, AaFwk_Ability_Terminate_test_0300, Function | MediumTest | Level1)
595 {
596 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
597 sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityRuntime::FAAbilityThread());
598 EXPECT_NE(abilityToken, nullptr);
599 if (abilityToken != nullptr) {
600 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
601 abilityInfo->type = AppExecFwk::AbilityType::PAGE;
602 abilityInfo->name = ABILITY_NAME;
603 abilityInfo->isNativeAbility = true;
604 std::shared_ptr<AbilityLocalRecord> abilityRecord =
605 std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
606
607 GTEST_LOG_(INFO) << "AaFwk_Ability_Terminate_test_0300 AbilityThreadMain";
608 AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
609
610 Want want;
611 MockAbilityManagerService* mockAMS = iface_cast<MockAbilityManagerService>(abilityObject_);
612 mockAMS->StartAbility(want, AbilityLifeCycleState::ABILITY_STATE_BACKGROUND);
613 usleep(AbilityTerminateTest::TEST_WAIT_TIME);
614
615 auto ability = AbilityLoader::GetInstance().GetAbilityByName(abilityInfo->name);
616 EXPECT_NE(ability, nullptr);
617 if (ability != nullptr) {
618 ability->SetResult(RESULT_CODE, want);
619 ability->TerminateAbility();
620 }
621 usleep(AbilityTerminateTest::TEST_WAIT_TIME);
622 }
623 GTEST_LOG_(INFO) << "AaFwk_Ability_Terminate_test_0300 TerminateAbility";
624 }
625
626 /**
627 * @tc.number: AaFwk_Ability_Terminate_test_0400
628 * @tc.name: TerminateAbility
629 * @tc.desc: When the ability state is ABILITY_STATE_INITIAL, the call to terminateability terminates.
630 */
631 HWTEST_F(AbilityTerminateTest, AaFwk_Ability_Terminate_test_0400, Function | MediumTest | Level1)
632 {
633 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
634 sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityRuntime::FAAbilityThread());
635 EXPECT_NE(abilityToken, nullptr);
636 if (abilityToken != nullptr) {
637 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
638 abilityInfo->type = AppExecFwk::AbilityType::PAGE;
639 abilityInfo->name = ABILITY_NAME;
640 abilityInfo->isNativeAbility = true;
641 std::shared_ptr<AbilityLocalRecord> abilityRecord =
642 std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
643
644 GTEST_LOG_(INFO) << "AaFwk_Ability_Terminate_test_0400 AbilityThreadMain";
645 AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
646
647 Want want;
648 MockAbilityManagerService* mockAMS = iface_cast<MockAbilityManagerService>(abilityObject_);
649 mockAMS->StartAbility(want, AbilityLifeCycleState::ABILITY_STATE_INITIAL);
650 usleep(AbilityTerminateTest::TEST_WAIT_TIME);
651
652 auto ability = AbilityLoader::GetInstance().GetAbilityByName(abilityInfo->name);
653 EXPECT_NE(ability, nullptr);
654 if (ability != nullptr) {
655 ability->SetResult(RESULT_CODE, want);
656 ability->TerminateAbility();
657 }
658 usleep(AbilityTerminateTest::TEST_WAIT_TIME);
659 }
660 GTEST_LOG_(INFO) << "AaFwk_Ability_Terminate_test_0400 TerminateAbility";
661 }
662
663 /**
664 * @tc.number: AaFwk_Ability_Terminate_test_0500
665 * @tc.name: TerminateAbility
666 * @tc.desc: When the ability state is inactive, the call to terminateability terminates.
667 */
668 HWTEST_F(AbilityTerminateTest, AaFwk_Ability_Terminate_test_0500, Function | MediumTest | Level1)
669 {
670 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
671 sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityRuntime::FAAbilityThread());
672 EXPECT_NE(abilityToken, nullptr);
673 if (abilityToken != nullptr) {
674 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
675 abilityInfo->type = AppExecFwk::AbilityType::PAGE;
676 abilityInfo->name = ABILITY_NAME;
677 abilityInfo->isNativeAbility = true;
678 std::shared_ptr<AbilityLocalRecord> abilityRecord =
679 std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
680
681 GTEST_LOG_(INFO) << "AaFwk_Ability_Terminate_test_005 AbilityThreadMain";
682 AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
683
684 Want want;
685 MockAbilityManagerService* mockAMS = iface_cast<MockAbilityManagerService>(abilityObject_);
686 mockAMS->StartAbility(want, AbilityLifeCycleState::ABILITY_STATE_INACTIVE);
687 usleep(AbilityTerminateTest::TEST_WAIT_TIME);
688
689 mockAMS->TerminateAbility(nullptr, RESULT_CODE, &want);
690 usleep(AbilityTerminateTest::TEST_WAIT_TIME);
691 }
692 GTEST_LOG_(INFO) << "AaFwk_Ability_Terminate_test_005 TerminateAbility";
693 }
694
695 /**
696 * @tc.number: AaFwk_Ability_Terminate_test_0600
697 * @tc.name: TerminateAbility
698 * @tc.desc: When the ability state is active, the call to terminateability terminates.
699 */
700 HWTEST_F(AbilityTerminateTest, AaFwk_Ability_Terminate_test_0600, Function | MediumTest | Level1)
701 {
702 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
703 sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityRuntime::FAAbilityThread());
704 EXPECT_NE(abilityToken, nullptr);
705 if (abilityToken != nullptr) {
706 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
707 abilityInfo->type = AppExecFwk::AbilityType::PAGE;
708 abilityInfo->name = ABILITY_NAME;
709 abilityInfo->isNativeAbility = true;
710 std::shared_ptr<AbilityLocalRecord> abilityRecord =
711 std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
712
713 GTEST_LOG_(INFO) << "AaFwk_Ability_Terminate_test_006 AbilityThreadMain";
714 AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
715
716 Want want;
717 MockAbilityManagerService* mockAMS = iface_cast<MockAbilityManagerService>(abilityObject_);
718 mockAMS->StartAbility(want, AbilityLifeCycleState::ABILITY_STATE_ACTIVE);
719 usleep(AbilityTerminateTest::TEST_WAIT_TIME);
720
721 mockAMS->TerminateAbility(nullptr, RESULT_CODE, &want);
722 usleep(AbilityTerminateTest::TEST_WAIT_TIME);
723 }
724 GTEST_LOG_(INFO) << "AaFwk_Ability_Terminate_test_006 TerminateAbility";
725 }
726
727 /**
728 * @tc.number: AaFwk_Ability_Terminate_test_0700
729 * @tc.name: TerminateAbility
730 * @tc.desc: When the ability state is background, the call to terminateability terminates.
731 */
732 HWTEST_F(AbilityTerminateTest, AaFwk_Ability_Terminate_test_0700, Function | MediumTest | Level1)
733 {
734 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
735 sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityRuntime::FAAbilityThread());
736 EXPECT_NE(abilityToken, nullptr);
737 if (abilityToken != nullptr) {
738 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
739 abilityInfo->type = AppExecFwk::AbilityType::PAGE;
740 abilityInfo->name = ABILITY_NAME;
741 abilityInfo->isNativeAbility = true;
742 std::shared_ptr<AbilityLocalRecord> abilityRecord =
743 std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
744
745 GTEST_LOG_(INFO) << "AaFwk_Ability_Terminate_test_007 AbilityThreadMain";
746 AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
747
748 Want want;
749 MockAbilityManagerService* mockAMS = iface_cast<MockAbilityManagerService>(abilityObject_);
750 mockAMS->StartAbility(want, AbilityLifeCycleState::ABILITY_STATE_BACKGROUND);
751 usleep(AbilityTerminateTest::TEST_WAIT_TIME);
752
753 mockAMS->TerminateAbility(nullptr, RESULT_CODE, &want);
754 usleep(AbilityTerminateTest::TEST_WAIT_TIME);
755 }
756 GTEST_LOG_(INFO) << "AaFwk_Ability_Terminate_test_007 TerminateAbility";
757 }
758
759 /**
760 * @tc.number: AaFwk_Ability_Terminate_test_0800
761 * @tc.name: TerminateAbility
762 * @tc.desc: When the ability state is initial, the call to terminateability terminates.
763 */
764 HWTEST_F(AbilityTerminateTest, AaFwk_Ability_Terminate_test_0800, Function | MediumTest | Level1)
765 {
766 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
767 sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityRuntime::FAAbilityThread());
768 EXPECT_NE(abilityToken, nullptr);
769 if (abilityToken != nullptr) {
770 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
771 abilityInfo->type = AppExecFwk::AbilityType::PAGE;
772 abilityInfo->name = ABILITY_NAME;
773 abilityInfo->isNativeAbility = true;
774 std::shared_ptr<AbilityLocalRecord> abilityRecord =
775 std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
776
777 GTEST_LOG_(INFO) << "AaFwk_Ability_Terminate_test_008 AbilityThreadMain";
778 AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
779
780 Want want;
781 MockAbilityManagerService* mockAMS = iface_cast<MockAbilityManagerService>(abilityObject_);
782 mockAMS->StartAbility(want, AbilityLifeCycleState::ABILITY_STATE_INITIAL);
783 usleep(AbilityTerminateTest::TEST_WAIT_TIME);
784
785 mockAMS->TerminateAbility(nullptr, RESULT_CODE, &want);
786 usleep(AbilityTerminateTest::TEST_WAIT_TIME);
787 }
788 GTEST_LOG_(INFO) << "AaFwk_Ability_Terminate_test_008 TerminateAbility";
789 }
790
791 /**
792 * @tc.number: AaFwk_WMS_window_test_0100
793 * @tc.name: WMS Link
794 * @tc.desc: Start pageability and call GetWindow to get the window handle.
795 */
796 HWTEST_F(AbilityTerminateTest, AaFwk_WMS_window_test_0100, Function | MediumTest | Level1)
797 {
798 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
799 sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityRuntime::FAAbilityThread());
800 EXPECT_NE(abilityToken, nullptr);
801 if (abilityToken != nullptr) {
802 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
803 abilityInfo->type = AppExecFwk::AbilityType::PAGE;
804 abilityInfo->name = ABILITY_NAME;
805 abilityInfo->isNativeAbility = true;
806 std::shared_ptr<AbilityLocalRecord> abilityRecord =
807 std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
808
809 GTEST_LOG_(INFO) << "AaFwk_WMS_window_test_001 AbilityThreadMain";
810 AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
811
812 Want want;
813 MockAbilityManagerService* mockAMS = iface_cast<MockAbilityManagerService>(abilityObject_);
814 GTEST_LOG_(INFO) << "AaFwk_WMS_window_test_001 StartAbility";
815 mockAMS->StartAbility(want, AbilityLifeCycleState::ABILITY_STATE_ACTIVE);
816 usleep(AbilityTerminateTest::TEST_WAIT_TIME);
817 mockAMS->TerminateAbility(nullptr, RESULT_CODE, &want);
818 usleep(AbilityTerminateTest::TEST_WAIT_TIME);
819 }
820 GTEST_LOG_(INFO) << "AaFwk_WMS_window_test_001 TerminateAbility";
821 }
822
823 /**
824 * @tc.number: AaFwk_WMS_window_test_0200
825 * @tc.name: WMS Link
826 * @tc.desc: Pageability switches to the foreground and calls Window.show.
827 * Pageability switches to the background and calls Window.hide.
828 */
829 HWTEST_F(AbilityTerminateTest, AaFwk_WMS_window_test_0200, Function | MediumTest | Level1)
830 {
831 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
832 sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityRuntime::FAAbilityThread());
833 EXPECT_NE(abilityToken, nullptr);
834 if (abilityToken != nullptr) {
835 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
836 abilityInfo->type = AppExecFwk::AbilityType::PAGE;
837 abilityInfo->name = ABILITY_NAME;
838 abilityInfo->isNativeAbility = true;
839 std::shared_ptr<AbilityLocalRecord> abilityRecord =
840 std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
841
842 GTEST_LOG_(INFO) << "AaFwk_WMS_window_test_002 AbilityThreadMain";
843 AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
844
845 Want want;
846 MockAbilityManagerService* mockAMS = iface_cast<MockAbilityManagerService>(abilityObject_);
847 mockAMS->StartAbility(want, AbilityLifeCycleState::ABILITY_STATE_BACKGROUND);
848 GTEST_LOG_(INFO) << "AaFwk_WMS_window_test_002 BackGround";
849 usleep(AbilityTerminateTest::TEST_WAIT_TIME);
850 mockAMS->StartAbility(want, AbilityLifeCycleState::ABILITY_STATE_ACTIVE);
851 GTEST_LOG_(INFO) << "AaFwk_WMS_window_test_002 Active";
852 usleep(AbilityTerminateTest::TEST_WAIT_TIME);
853
854 mockAMS->TerminateAbility(nullptr, RESULT_CODE, &want);
855 }
856 GTEST_LOG_(INFO) << "AaFwk_WMS_window_test_002 TerminateAbility";
857 }
858
859 /**
860 * @tc.number: AaFwk_DataAbility_Launch_0100
861 * @tc.name: DataAbilityHelper
862 * @tc.desc: The AbilityManager could receive the shelder of abilitythread for dataability when the dataability
863 * launched.
864 */
865 HWTEST_F(AbilityTerminateTest, AaFwk_DataAbility_Launch_0100, Function | MediumTest | Level1)
866 {
867 GTEST_LOG_(INFO) << "AaFwk_DataAbility_Launch_0100";
868
869 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
870 sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityRuntime::FAAbilityThread());
871 EXPECT_NE(abilityToken, nullptr);
872 if (abilityToken != nullptr) {
873 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
874 abilityInfo->type = AppExecFwk::AbilityType::DATA;
875 abilityInfo->name = "DemoAbility";
876 std::shared_ptr<AbilityLocalRecord> abilityRecord =
877 std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
878
879 AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
880
881 sptr<IRemoteObject> remoteObject_ =
882 OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
883 sptr<AAFwk::IAbilityManager> abms = iface_cast<AAFwk::IAbilityManager>(remoteObject_);
884
885 Uri uri("testuri");
886 EXPECT_TRUE(abms->AcquireDataAbility(uri, false, nullptr) == nullptr);
887 }
888 GTEST_LOG_(INFO) << "AaFwk_DataAbility_Launch_0100";
889 }
890
891 /**
892 * @tc.number: AaFwk_DataAbility_Start_0100
893 * @tc.name: DataAbilityHelper
894 * @tc.desc: The AbilityManager could receive the inactive state from abilitythread for dataability when the
895 dataability
896 * change its lifecycle state to inactive.
897 */
898 HWTEST_F(AbilityTerminateTest, AaFwk_DataAbility_Start_0100, Function | MediumTest | Level1)
899 {
900 GTEST_LOG_(INFO) << "AaFwk_DataAbility_Start_0100";
901
902 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
903 sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityRuntime::FAAbilityThread());
904 EXPECT_NE(abilityToken, nullptr);
905 if (abilityToken != nullptr) {
906 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
907 abilityInfo->type = AppExecFwk::AbilityType::DATA;
908 abilityInfo->name = "DemoAbility";
909 std::shared_ptr<AbilityLocalRecord> abilityRecord =
910 std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
911
912 AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
913
914 sptr<IRemoteObject> remoteObject_ =
915 OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
916 sptr<AAFwk::IAbilityManager> abms = iface_cast<AAFwk::IAbilityManager>(remoteObject_);
917 Want want;
918 abms->StartAbility(want, AbilityLifeCycleState::ABILITY_STATE_INACTIVE);
919
920 usleep(AbilityBaseTest::TEST_WAIT_TIME);
921 }
922 GTEST_LOG_(INFO) << "AaFwk_DataAbility_Start_0100";
923 }
924
925 /**
926 * @tc.number: AaFwk_DataAbility_Start_0200
927 * @tc.name: DataAbilityHelper
928 * @tc.desc: The AbilityManager could not receive the initial state from abilitythread for dataability.
929 * And the OnStop coulde be called. When the dataability change its lifecycle state to initial.
930 */
931 HWTEST_F(AbilityTerminateTest, AaFwk_DataAbility_Start_0200, Function | MediumTest | Level1)
932 {
933 GTEST_LOG_(INFO) << "AaFwk_DataAbility_Start_0200";
934
935 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
936 sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityRuntime::FAAbilityThread());
937 EXPECT_NE(abilityToken, nullptr);
938 if (abilityToken != nullptr) {
939 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
940 abilityInfo->type = AppExecFwk::AbilityType::DATA;
941 abilityInfo->name = "DemoAbility";
942 std::shared_ptr<AbilityLocalRecord> abilityRecord =
943 std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
944
945 AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
946
947 sptr<IRemoteObject> remoteObject_ =
948 OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
949 sptr<AAFwk::IAbilityManager> abms = iface_cast<AAFwk::IAbilityManager>(remoteObject_);
950 Want want;
951 abms->StartAbility(want, AbilityLifeCycleState::ABILITY_STATE_INITIAL);
952
953 usleep(AbilityBaseTest::TEST_WAIT_TIME);
954 }
955 GTEST_LOG_(INFO) << "AaFwk_DataAbility_Start_0200";
956 }
957
958 /**
959 * @tc.number: AaFwk_DataAbility_Start_0300
960 * @tc.name: DataAbilityHelper
961 * @tc.desc: The AbilityManager could not receive the active state from abilitythread for dataability.
962 * And the OnActive coulde be called. When the dataability change its lifecycle state to active.
963 */
964 HWTEST_F(AbilityTerminateTest, AaFwk_DataAbility_Start_0300, Function | MediumTest | Level1)
965 {
966 GTEST_LOG_(INFO) << "AaFwk_DataAbility_Start_0300";
967
968 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
969 sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityRuntime::FAAbilityThread());
970 EXPECT_NE(abilityToken, nullptr);
971 if (abilityToken != nullptr) {
972 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
973 abilityInfo->type = AppExecFwk::AbilityType::DATA;
974 abilityInfo->name = "DemoAbility";
975 std::shared_ptr<AbilityLocalRecord> abilityRecord =
976 std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
977
978 AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
979
980 sptr<IRemoteObject> remoteObject_ =
981 OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
982 sptr<AAFwk::IAbilityManager> abms = iface_cast<AAFwk::IAbilityManager>(remoteObject_);
983 Want want;
984 abms->StartAbility(want, AbilityLifeCycleState::ABILITY_STATE_ACTIVE);
985
986 usleep(AbilityBaseTest::TEST_WAIT_TIME);
987 }
988 GTEST_LOG_(INFO) << "AaFwk_DataAbility_Start_0300";
989 }
990
991 /**
992 * @tc.number: AaFwk_DataAbility_Start_0400
993 * @tc.name: DataAbilityHelper
994 * @tc.desc: The AbilityManager could not receive the background state from abilitythread for dataability.
995 * And the OnBackground coulde be called. When the dataability change its lifecycle state to background.
996 */
997 HWTEST_F(AbilityTerminateTest, AaFwk_DataAbility_Start_0400, Function | MediumTest | Level1)
998 {
999 GTEST_LOG_(INFO) << "AaFwk_DataAbility_Start_0400";
1000
1001 std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
1002 sptr<IRemoteObject> abilityToken = sptr<IRemoteObject>(new AbilityRuntime::FAAbilityThread());
1003 EXPECT_NE(abilityToken, nullptr);
1004 if (abilityToken != nullptr) {
1005 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
1006 abilityInfo->type = AppExecFwk::AbilityType::DATA;
1007 abilityInfo->name = "DemoAbility";
1008 std::shared_ptr<AbilityLocalRecord> abilityRecord =
1009 std::make_shared<AbilityLocalRecord>(abilityInfo, abilityToken);
1010
1011 AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr);
1012
1013 sptr<IRemoteObject> remoteObject_ =
1014 OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
1015 sptr<AAFwk::IAbilityManager> abms = iface_cast<AAFwk::IAbilityManager>(remoteObject_);
1016 Want want;
1017 abms->StartAbility(want, AbilityLifeCycleState::ABILITY_STATE_BACKGROUND);
1018
1019 usleep(AbilityBaseTest::TEST_WAIT_TIME);
1020 }
1021 GTEST_LOG_(INFO) << "AaFwk_DataAbility_Start_0400";
1022 }
1023
1024 /**
1025 * @tc.number: AaFwk_IAbilityManager_StartAbilityAsCaller_0100
1026 * @tc.name: StartAbilityAsCaller
1027 * @tc.desc: test StartAbilityAsCaller function
1028 */
1029 HWTEST_F(AbilityTerminateTest, AaFwk_IAbilityManager_StartAbilityAsCaller_0100, Function | MediumTest | Level1)
1030 {
1031 GTEST_LOG_(INFO) << "AaFwk_IAbilityManager_StartAbilityAsCaller_0100";
1032 sptr<IRemoteObject> remoteObject_ =
1033 OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
1034 sptr<AAFwk::IAbilityManager> abms = iface_cast<AAFwk::IAbilityManager>(remoteObject_);
1035 EXPECT_NE(abms, nullptr);
1036 Want want;
1037 EXPECT_EQ(0, abms->StartAbilityAsCaller(want, nullptr, nullptr));
1038 GTEST_LOG_(INFO) << "AaFwk_IAbilityManager_StartAbilityAsCaller_0100";
1039 }
1040
1041 /**
1042 * @tc.number: AaFwk_IAbilityManager_StartAbilityAsCaller_0200
1043 * @tc.name: StartAbilityAsCaller
1044 * @tc.desc: test StartAbilityAsCaller function
1045 */
1046 HWTEST_F(AbilityTerminateTest, AaFwk_IAbilityManager_StartAbilityAsCaller_0200, Function | MediumTest | Level1)
1047 {
1048 GTEST_LOG_(INFO) << "AaFwk_IAbilityManager_StartAbilityAsCaller_0200";
1049 sptr<IRemoteObject> remoteObject_ =
1050 OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
1051 sptr<AAFwk::IAbilityManager> abms = iface_cast<AAFwk::IAbilityManager>(remoteObject_);
1052 EXPECT_NE(abms, nullptr);
1053 Want want;
1054 StartOptions startOptions;
1055 EXPECT_EQ(0, abms->StartAbilityAsCaller(want, startOptions, nullptr, nullptr));
1056 GTEST_LOG_(INFO) << "AaFwk_IAbilityManager_StartAbilityAsCaller_0200";
1057 }
1058
1059 /**
1060 * @tc.number: AaFwk_IAbilityManager_StartUIExtensionAbility_0100
1061 * @tc.name: StartUIExtensionAbility
1062 * @tc.desc: test StartUIExtensionAbility function
1063 */
1064 HWTEST_F(AbilityTerminateTest, AaFwk_IAbilityManager_StartUIExtensionAbility_0100, Function | MediumTest | Level1)
1065 {
1066 GTEST_LOG_(INFO) << "AaFwk_IAbilityManager_StartUIExtensionAbility_0100";
1067 sptr<IRemoteObject> remoteObject_ =
1068 OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
1069 sptr<AAFwk::IAbilityManager> abms = iface_cast<AAFwk::IAbilityManager>(remoteObject_);
1070 EXPECT_NE(abms, nullptr);
1071 Want want;
1072 EXPECT_EQ(0, abms->StartAbilityAsCaller(want, nullptr, nullptr));
1073 GTEST_LOG_(INFO) << "AaFwk_IAbilityManager_StartUIExtensionAbility_0100";
1074 }
1075
1076 /**
1077 * @tc.number: AaFwk_IAbilityManager_TerminateUIExtensionAbility_0100
1078 * @tc.name: TerminateUIExtensionAbility
1079 * @tc.desc: test TerminateUIExtensionAbility function
1080 */
1081 HWTEST_F(AbilityTerminateTest, AaFwk_IAbilityManager_TerminateUIExtensionAbility_0100, Function | MediumTest | Level1)
1082 {
1083 GTEST_LOG_(INFO) << "AaFwk_IAbilityManager_TerminateUIExtensionAbility_0100";
1084 sptr<IRemoteObject> remoteObject_ =
1085 OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
1086 sptr<AAFwk::IAbilityManager> abms = iface_cast<AAFwk::IAbilityManager>(remoteObject_);
1087 EXPECT_NE(abms, nullptr);
1088 int resultCode = 1;
1089 EXPECT_EQ(0, abms->TerminateUIExtensionAbility(nullptr, resultCode));
1090 GTEST_LOG_(INFO) << "AaFwk_IAbilityManager_TerminateUIExtensionAbility_0100";
1091 }
1092
1093 /**
1094 * @tc.number: AaFwk_IAbilityManager_SendResultToAbility_0100
1095 * @tc.name: SendResultToAbility
1096 * @tc.desc: test SendResultToAbility function
1097 */
1098 HWTEST_F(AbilityTerminateTest, AaFwk_IAbilityManager_SendResultToAbility_0100, Function | MediumTest | Level1)
1099 {
1100 GTEST_LOG_(INFO) << "AaFwk_IAbilityManager_SendResultToAbility_0100";
1101 sptr<IRemoteObject> remoteObject_ =
1102 OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
1103 sptr<AAFwk::IAbilityManager> abms = iface_cast<AAFwk::IAbilityManager>(remoteObject_);
1104 EXPECT_NE(abms, nullptr);
1105 int requestCode = 1;
1106 int resultCode = 2;
1107 Want resultWant;
1108 EXPECT_EQ(0, abms->SendResultToAbility(requestCode, resultCode, resultWant));
1109 GTEST_LOG_(INFO) << "AaFwk_IAbilityManager_SendResultToAbility_0100";
1110 }
1111
1112 /**
1113 * @tc.number: AaFwk_IAbilityManager_MinimizeUIExtensionAbility_0100
1114 * @tc.name: MinimizeUIExtensionAbility
1115 * @tc.desc: test MinimizeUIExtensionAbility function
1116 */
1117 HWTEST_F(AbilityTerminateTest, AaFwk_IAbilityManager_MinimizeUIExtensionAbility_0100, Function | MediumTest | Level1)
1118 {
1119 GTEST_LOG_(INFO) << "AaFwk_IAbilityManager_MinimizeUIExtensionAbility_0100";
1120 sptr<IRemoteObject> remoteObject_ =
1121 OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
1122 sptr<AAFwk::IAbilityManager> abms = iface_cast<AAFwk::IAbilityManager>(remoteObject_);
1123 EXPECT_NE(abms, nullptr);
1124 EXPECT_EQ(0, abms->MinimizeUIExtensionAbility(nullptr));
1125 GTEST_LOG_(INFO) << "AaFwk_IAbilityManager_MinimizeUIExtensionAbility_0100";
1126 }
1127
1128 /**
1129 * @tc.number: AaFwk_IAbilityManager_CallRequestDone_0100
1130 * @tc.name: CallRequestDone
1131 * @tc.desc: test CallRequestDone function
1132 */
1133 HWTEST_F(AbilityTerminateTest, AaFwk_IAbilityManager_CallRequestDone_0100, Function | MediumTest | Level1)
1134 {
1135 GTEST_LOG_(INFO) << "AaFwk_IAbilityManager_CallRequestDone_0100";
1136 sptr<IRemoteObject> remoteObject_ =
1137 OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
1138 sptr<AAFwk::IAbilityManager> abms = iface_cast<AAFwk::IAbilityManager>(remoteObject_);
1139 EXPECT_NE(abms, nullptr);
1140 abms->CallRequestDone(nullptr, nullptr);
1141 GTEST_LOG_(INFO) << "AaFwk_IAbilityManager_CallRequestDone_0100";
1142 }
1143
1144 /**
1145 * @tc.number: AaFwk_IAbilityManager_AddFreeInstallObserver_0100
1146 * @tc.name: AddFreeInstallObserver
1147 * @tc.desc: test AddFreeInstallObserver function
1148 */
1149 HWTEST_F(AbilityTerminateTest, AaFwk_IAbilityManager_AddFreeInstallObserver_0100, Function | MediumTest | Level1)
1150 {
1151 GTEST_LOG_(INFO) << "AaFwk_IAbilityManager_AddFreeInstallObserver_0100";
1152 sptr<IRemoteObject> remoteObject_ =
1153 OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
1154 sptr<AAFwk::IAbilityManager> abms = iface_cast<AAFwk::IAbilityManager>(remoteObject_);
1155 EXPECT_NE(abms, nullptr);
1156 EXPECT_EQ(0, abms->AddFreeInstallObserver(nullptr));
1157 GTEST_LOG_(INFO) << "AaFwk_IAbilityManager_AddFreeInstallObserver_0100";
1158 }
1159
1160 /**
1161 * @tc.number: AaFwk_IAbilityManager_EnableRecoverAbility_0100
1162 * @tc.name: EnableRecoverAbility
1163 * @tc.desc: test EnableRecoverAbility function
1164 */
1165 HWTEST_F(AbilityTerminateTest, AaFwk_IAbilityManager_EnableRecoverAbility_0100, Function | MediumTest | Level1)
1166 {
1167 GTEST_LOG_(INFO) << "AaFwk_IAbilityManager_EnableRecoverAbility_0100";
1168 sptr<IRemoteObject> remoteObject_ =
1169 OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
1170 sptr<AAFwk::IAbilityManager> abms = iface_cast<AAFwk::IAbilityManager>(remoteObject_);
1171 EXPECT_NE(abms, nullptr);
1172 abms->EnableRecoverAbility(nullptr);
1173 GTEST_LOG_(INFO) << "AaFwk_IAbilityManager_EnableRecoverAbility_0100";
1174 }
1175
1176 /**
1177 * @tc.number: AaFwk_IAbilityManager_ScheduleRecoverAbility_0100
1178 * @tc.name: ScheduleRecoverAbility
1179 * @tc.desc: test ScheduleRecoverAbility function
1180 */
1181 HWTEST_F(AbilityTerminateTest, AaFwk_IAbilityManager_ScheduleRecoverAbility_0100, Function | MediumTest | Level1)
1182 {
1183 GTEST_LOG_(INFO) << "AaFwk_IAbilityManager_ScheduleRecoverAbility_0100";
1184 sptr<IRemoteObject> remoteObject_ =
1185 OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
1186 sptr<AAFwk::IAbilityManager> abms = iface_cast<AAFwk::IAbilityManager>(remoteObject_);
1187 EXPECT_NE(abms, nullptr);
1188 int32_t reason = 1;
1189 abms->ScheduleRecoverAbility(nullptr, reason);
1190 GTEST_LOG_(INFO) << "AaFwk_IAbilityManager_ScheduleRecoverAbility_0100";
1191 }
1192
1193 /**
1194 * @tc.number: AaFwk_IAbilityManager_VerifyPermission_0100
1195 * @tc.name: VerifyPermission
1196 * @tc.desc: test VerifyPermission function
1197 */
1198 HWTEST_F(AbilityTerminateTest, AaFwk_IAbilityManager_VerifyPermission_0100, Function | MediumTest | Level1)
1199 {
1200 GTEST_LOG_(INFO) << "AaFwk_IAbilityManager_VerifyPermission_0100";
1201 sptr<IRemoteObject> remoteObject_ =
1202 OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
1203 sptr<AAFwk::IAbilityManager> abms = iface_cast<AAFwk::IAbilityManager>(remoteObject_);
1204 EXPECT_NE(abms, nullptr);
1205 std::string permission = "<permission>";
1206 int pid = 1;
1207 int uid = 1;
1208 EXPECT_EQ(0, abms->VerifyPermission(permission, pid, uid));
1209 GTEST_LOG_(INFO) << "AaFwk_IAbilityManager_VerifyPermission_0100";
1210 }
1211 } // namespace AppExecFwk
1212 } // namespace OHOS
1213