1 /*
2 * Copyright (c) 2022-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 <cstdlib>
17 #include <gtest/gtest.h>
18
19 #define private public
20 #include "app_mgr_proxy.h"
21 #include "app_mgr_stub.h"
22 #include "main_thread.h"
23 #include "hilog_wrapper.h"
24 #include "if_system_ability_manager.h"
25 #include "iservice_registry.h"
26 #include "mock_bundle_manager.h"
27 #include "process_info.h"
28 #include "quick_fix_callback_stub.h"
29 #include "system_ability_definition.h"
30 #include "sys_mgr_client.h"
31 #include "ohos_application.h"
32 #undef private
33
34 using namespace testing;
35 using namespace testing::ext;
36
37 namespace OHOS {
38 namespace AppExecFwk {
39 constexpr uint32_t CHECK_MAIN_THREAD_IS_ALIVE = 1;
40 class QuickFixCallbackImpl : public AppExecFwk::QuickFixCallbackStub {
41 public:
42 QuickFixCallbackImpl() = default;
43 virtual ~QuickFixCallbackImpl() = default;
44
OnLoadPatchDone(int32_t resultCode,int32_t recordId)45 void OnLoadPatchDone(int32_t resultCode, int32_t recordId) override
46 {
47 HILOG_DEBUG("function called.");
48 }
49
OnUnloadPatchDone(int32_t resultCode,int32_t recordId)50 void OnUnloadPatchDone(int32_t resultCode, int32_t recordId) override
51 {
52 HILOG_DEBUG("function called.");
53 }
54
OnReloadPageDone(int32_t resultCode,int32_t recordId)55 void OnReloadPageDone(int32_t resultCode, int32_t recordId) override
56 {
57 HILOG_DEBUG("function called.");
58 }
59 };
60
61 class MainThreadTest : public testing::Test {
62 public:
63 static void SetUpTestCase();
64 static void TearDownTestCase();
65 void SetUp() override;
66 void TearDown() override;
67
68 sptr<MainThread> mainThread_ = nullptr;
69 };
70
SetUpTestCase()71 void MainThreadTest::SetUpTestCase()
72 {
73 sptr<IRemoteObject> bundleObject = new (std::nothrow) BundleMgrService();
74 auto sysMgr = DelayedSingleton<SysMrgClient>::GetInstance();
75 if (sysMgr == nullptr) {
76 GTEST_LOG_(ERROR) << "Failed to get ISystemAbilityManager.";
77 return;
78 }
79
80 sysMgr->RegisterSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, bundleObject);
81 }
82
TearDownTestCase()83 void MainThreadTest::TearDownTestCase()
84 {}
85
SetUp()86 void MainThreadTest::SetUp()
87 {
88 std::shared_ptr<EventRunner> runner = EventRunner::GetMainEventRunner();
89 ASSERT_NE(runner, nullptr);
90
91 mainThread_ = sptr<MainThread>(new (std::nothrow) MainThread());
92 ASSERT_NE(mainThread_, nullptr);
93
94 mainThread_->Init(runner);
95 }
96
TearDown()97 void MainThreadTest::TearDown()
98 {
99 mainThread_->applicationForDump_.reset();
100 }
101
102 class MockAppMgrStub : public AppMgrStub {
103 MockAppMgrStub() = default;
104 virtual ~MockAppMgrStub() = default;
105
AttachApplication(const sptr<IRemoteObject> & app)106 void AttachApplication(const sptr<IRemoteObject> &app) override
107 {}
108
ApplicationForegrounded(const int32_t recordId)109 void ApplicationForegrounded(const int32_t recordId) override
110 {}
111
ApplicationBackgrounded(const int32_t recordId)112 void ApplicationBackgrounded(const int32_t recordId) override
113 {}
114
ApplicationTerminated(const int32_t recordId)115 void ApplicationTerminated(const int32_t recordId) override
116 {}
117
CheckPermission(const int32_t recordId,const std::string & permission)118 int CheckPermission(const int32_t recordId, const std::string &permission) override
119 {
120 return 0;
121 }
122
AbilityCleaned(const sptr<IRemoteObject> & token)123 void AbilityCleaned(const sptr<IRemoteObject> &token) override
124 {}
125
GetAmsMgr()126 sptr<IAmsMgr> GetAmsMgr() override
127 {
128 return nullptr;
129 }
130
ClearUpApplicationData(const std::string & bundleName)131 int32_t ClearUpApplicationData(const std::string &bundleName) override
132 {
133 return 0;
134 }
135
GetAllRunningProcesses(std::vector<RunningProcessInfo> & info)136 int GetAllRunningProcesses(std::vector<RunningProcessInfo> &info) override
137 {
138 return 0;
139 }
140
GetProcessRunningInfosByUserId(std::vector<RunningProcessInfo> & info,int32_t userId)141 int GetProcessRunningInfosByUserId(std::vector<RunningProcessInfo> &info, int32_t userId) override
142 {
143 return 0;
144 }
145
NotifyMemoryLevel(int32_t level)146 int NotifyMemoryLevel(int32_t level) override
147 {
148 return 0;
149 }
150
AddAbilityStageDone(const int32_t recordId)151 void AddAbilityStageDone(const int32_t recordId) override
152 {}
153
StartupResidentProcess(const std::vector<AppExecFwk::BundleInfo> & bundleInfos)154 void StartupResidentProcess(const std::vector<AppExecFwk::BundleInfo> &bundleInfos) override
155 {}
156
RegisterApplicationStateObserver(const sptr<IApplicationStateObserver> & observer,const std::vector<std::string> & bundleNameList={})157 int32_t RegisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer,
158 const std::vector<std::string> &bundleNameList = {}) override
159 {
160 return 0;
161 }
162
UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver> & observer)163 int32_t UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer) override
164 {
165 return 0;
166 }
167
GetForegroundApplications(std::vector<AppStateData> & list)168 int32_t GetForegroundApplications(std::vector<AppStateData> &list) override
169 {
170 return 0;
171 }
172
StartUserTestProcess(const AAFwk::Want & want,const sptr<IRemoteObject> & observer,const BundleInfo & bundleInfo,int32_t userId)173 int StartUserTestProcess(
174 const AAFwk::Want &want, const sptr<IRemoteObject> &observer, const BundleInfo &bundleInfo, int32_t userId) override
175 {
176 return 0;
177 }
178
FinishUserTest(const std::string & msg,const int64_t & resultCode,const std::string & bundleName)179 int FinishUserTest(const std::string &msg, const int64_t &resultCode, const std::string &bundleName) override
180 {
181 return 0;
182 }
183
ScheduleAcceptWantDone(const int32_t recordId,const AAFwk::Want & want,const std::string & flag)184 void ScheduleAcceptWantDone(const int32_t recordId, const AAFwk::Want &want, const std::string &flag) override
185 {}
186
GetAbilityRecordsByProcessID(const int pid,std::vector<sptr<IRemoteObject>> & tokens)187 int GetAbilityRecordsByProcessID(const int pid, std::vector<sptr<IRemoteObject>> &tokens) override
188 {
189 return 0;
190 }
191
192 #ifdef ABILITY_COMMAND_FOR_TEST
BlockAppService()193 int BlockAppService() override
194 {
195 return 0;
196 }
197 #endif
198
PreStartNWebSpawnProcess()199 int PreStartNWebSpawnProcess() override
200 {
201 return 0;
202 }
203
StartRenderProcess(const std::string & renderParam,int32_t ipcFd,int32_t sharedFd,int32_t crashFd,pid_t & renderPid)204 int StartRenderProcess(const std::string &renderParam, int32_t ipcFd,
205 int32_t sharedFd, int32_t crashFd, pid_t &renderPid) override
206 {
207 return 0;
208 }
209
AttachRenderProcess(const sptr<IRemoteObject> & renderScheduler)210 void AttachRenderProcess(const sptr<IRemoteObject> &renderScheduler) override
211 {}
212
GetRenderProcessTerminationStatus(pid_t renderPid,int & status)213 int GetRenderProcessTerminationStatus(pid_t renderPid, int &status) override
214 {
215 return 0;
216 }
217
GetConfiguration(Configuration & config)218 int32_t GetConfiguration(Configuration& config) override
219 {
220 return 0;
221 }
222
UpdateConfiguration(const Configuration & config)223 int32_t UpdateConfiguration(const Configuration &config) override
224 {
225 return 0;
226 }
227
RegisterConfigurationObserver(const sptr<IConfigurationObserver> & observer)228 int32_t RegisterConfigurationObserver(const sptr<IConfigurationObserver> &observer) override
229 {
230 return 0;
231 }
232
UnregisterConfigurationObserver(const sptr<IConfigurationObserver> & observer)233 int32_t UnregisterConfigurationObserver(const sptr<IConfigurationObserver> &observer) override
234 {
235 return 0;
236 }
237
GetAppRunningStateByBundleName(const std::string & bundleName)238 bool GetAppRunningStateByBundleName(const std::string &bundleName) override
239 {
240 return false;
241 }
242
NotifyLoadRepairPatch(const std::string & bundleName,const sptr<IQuickFixCallback> & callback)243 int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback) override
244 {
245 return 0;
246 }
247
NotifyHotReloadPage(const std::string & bundleName,const sptr<IQuickFixCallback> & callback)248 int32_t NotifyHotReloadPage(const std::string &bundleName, const sptr<IQuickFixCallback> &callback) override
249 {
250 return 0;
251 }
252
NotifyUnLoadRepairPatch(const std::string & bundleName,const sptr<IQuickFixCallback> & callback)253 int32_t NotifyUnLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback) override
254 {
255 return 0;
256 }
257
NotifyAppFault(const FaultData & faultData)258 int32_t NotifyAppFault(const FaultData &faultData) override
259 {
260 return 0;
261 }
262
NotifyAppFaultBySA(const AppFaultDataBySA & faultData)263 int32_t NotifyAppFaultBySA(const AppFaultDataBySA &faultData) override
264 {
265 return 0;
266 }
267 };
268
269 /*
270 * Feature: MainThread
271 * Function: GetMainThreadState
272 * SubFunction: NA
273 * FunctionPoints: MainThread GetMainThreadState
274 * EnvConditions: NA
275 * CaseDescription: Verify GetMainThreadState
276 */
277 HWTEST_F(MainThreadTest, GetMainThreadState_0100, TestSize.Level1)
278 {
279 HILOG_INFO("%{public}s start.", __func__);
280 EXPECT_EQ(mainThread_->GetMainThreadState(), MainThreadState::INIT);
281 HILOG_INFO("%{public}s end.", __func__);
282 }
283
284 /*
285 * Feature: MainThread
286 * Function: SetRunnerStarted
287 * SubFunction: NA
288 * FunctionPoints: MainThread SetRunnerStarted
289 * EnvConditions: NA
290 * CaseDescription: Verify SetRunnerStarted
291 */
292 HWTEST_F(MainThreadTest, SetRunnerStarted_0100, TestSize.Level1)
293 {
294 HILOG_INFO("%{public}s start.", __func__);
295 mainThread_->SetRunnerStarted(true);
296 EXPECT_TRUE(mainThread_->isRunnerStarted_);
297 HILOG_INFO("%{public}s end.", __func__);
298 }
299
300 /*
301 * Feature: MainThread
302 * Function: GetRunnerStarted
303 * SubFunction: NA
304 * FunctionPoints: MainThread GetRunnerStarted
305 * EnvConditions: NA
306 * CaseDescription: Verify GetRunnerStarted
307 */
308 HWTEST_F(MainThreadTest, GetRunnerStarted_0100, TestSize.Level1)
309 {
310 HILOG_INFO("%{public}s start.", __func__);
311 EXPECT_FALSE(mainThread_->GetRunnerStarted());
312 HILOG_INFO("%{public}s end.", __func__);
313 }
314
315 /*
316 * Feature: MainThread
317 * Function: GetNewThreadId
318 * SubFunction: NA
319 * FunctionPoints: MainThread GetNewThreadId
320 * EnvConditions: NA
321 * CaseDescription: Verify GetNewThreadId
322 */
323 HWTEST_F(MainThreadTest, GetNewThreadId_0100, TestSize.Level1)
324 {
325 HILOG_INFO("%{public}s start.", __func__);
326 EXPECT_EQ(mainThread_->GetNewThreadId(), -1);
327 HILOG_INFO("%{public}s end.", __func__);
328 }
329
330 /*
331 * Feature: MainThread
332 * Function: GetApplication
333 * SubFunction: NA
334 * FunctionPoints: MainThread GetApplication
335 * EnvConditions: NA
336 * CaseDescription: Verify GetApplication
337 */
338 HWTEST_F(MainThreadTest, GetApplication_0100, TestSize.Level1)
339 {
340 HILOG_INFO("%{public}s start.", __func__);
341 EXPECT_EQ(mainThread_->GetApplication(), nullptr);
342 HILOG_INFO("%{public}s end.", __func__);
343 }
344
345 /*
346 * Feature: MainThread
347 * Function: GetApplicationInfo
348 * SubFunction: NA
349 * FunctionPoints: MainThread GetApplicationInfo
350 * EnvConditions: NA
351 * CaseDescription: Verify GetApplicationInfo
352 */
353 HWTEST_F(MainThreadTest, GetApplicationInfo_0100, TestSize.Level1)
354 {
355 HILOG_INFO("%{public}s start.", __func__);
356 EXPECT_EQ(mainThread_->GetApplicationInfo(), nullptr);
357 HILOG_INFO("%{public}s end.", __func__);
358 }
359
360 /*
361 * Feature: MainThread
362 * Function: GetApplicationImpl
363 * SubFunction: NA
364 * FunctionPoints: MainThread GetApplicationImpl
365 * EnvConditions: NA
366 * CaseDescription: Verify GetApplicationImpl
367 */
368 HWTEST_F(MainThreadTest, GetApplicationImpl_0100, TestSize.Level1)
369 {
370 HILOG_INFO("%{public}s start.", __func__);
371 EXPECT_EQ(mainThread_->GetApplicationImpl(), nullptr);
372 HILOG_INFO("%{public}s end.", __func__);
373 }
374
375 /*
376 * Feature: MainThread
377 * Function: GetMainHandler
378 * SubFunction: NA
379 * FunctionPoints: MainThread GetMainHandler
380 * EnvConditions: NA
381 * CaseDescription: Verify GetMainHandler
382 */
383 HWTEST_F(MainThreadTest, GetMainHandler_0100, TestSize.Level1)
384 {
385 HILOG_INFO("%{public}s start.", __func__);
386 EXPECT_NE(mainThread_->GetMainHandler(), nullptr);
387 mainThread_->ScheduleForegroundApplication();
388 mainThread_->ScheduleBackgroundApplication();
389 mainThread_->ScheduleTerminateApplication();
390 mainThread_->ScheduleShrinkMemory(1);
391 mainThread_->ScheduleMemoryLevel(1);
392 mainThread_->ScheduleProcessSecurityExit();
393 mainThread_->ScheduleLowMemory();
394 AppLaunchData data;
395 Configuration config;
396 mainThread_->ScheduleLaunchApplication(data, config);
397 HapModuleInfo abilityStage;
398 mainThread_->ScheduleAbilityStage(abilityStage);
399 AbilityInfo info;
400 sptr<IRemoteObject> Token = nullptr;
401 std::shared_ptr<AAFwk::Want> want = std::make_shared<AAFwk::Want>();
402 mainThread_->ScheduleLaunchAbility(info, Token, want);
403 mainThread_->ScheduleCleanAbility(Token);
404 Profile profile;
405 mainThread_->ScheduleProfileChanged(profile);
406 mainThread_->ScheduleConfigurationUpdated(config);
407 HILOG_INFO("%{public}s end.", __func__);
408 }
409
410 /*
411 * Feature: MainThread
412 * Function: InitCreate
413 * SubFunction: NA
414 * FunctionPoints: MainThread InitCreate
415 * EnvConditions: NA
416 * CaseDescription: Verify InitCreate
417 */
418 HWTEST_F(MainThreadTest, InitCreate_0100, TestSize.Level1)
419 {
420 HILOG_INFO("%{public}s start.", __func__);
421 std::shared_ptr<ContextDeal> contextDeal;
422 ApplicationInfo appInfo;
423 ProcessInfo processInfo;
424 EXPECT_TRUE(mainThread_->InitCreate(contextDeal, appInfo, processInfo));
425 HILOG_INFO("%{public}s end.", __func__);
426 }
427
428 /**
429 * @tc.name: ScheduleNotifyLoadRepairPatch_0100
430 * @tc.desc: schedule notify load repair patch.
431 * @tc.type: FUNC
432 * @tc.require: issueI581VW
433 */
434 HWTEST_F(MainThreadTest, ScheduleNotifyLoadRepairPatch_0100, TestSize.Level1)
435 {
436 HILOG_INFO("%{public}s start.", __func__);
437 std::string bundleName;
438 sptr<IQuickFixCallback> callback = new QuickFixCallbackImpl();
439 int32_t recordId = 0;
440 auto ret = mainThread_->ScheduleNotifyLoadRepairPatch(bundleName, callback, recordId);
441 EXPECT_EQ(ret, NO_ERROR);
442 HILOG_INFO("%{public}s end.", __func__);
443 }
444
445 /**
446 * @tc.name: ScheduleNotifyHotReloadPage_0100
447 * @tc.desc: schedule notify ace hot reload page.
448 * @tc.type: FUNC
449 * @tc.require: issueI581VW
450 */
451 HWTEST_F(MainThreadTest, ScheduleNotifyHotReloadPage_0100, TestSize.Level1)
452 {
453 HILOG_INFO("%{public}s start.", __func__);
454 sptr<IQuickFixCallback> callback = new QuickFixCallbackImpl();
455 int32_t recordId = 0;
456 auto ret = mainThread_->ScheduleNotifyHotReloadPage(callback, recordId);
457 EXPECT_EQ(ret, NO_ERROR);
458 HILOG_INFO("%{public}s end.", __func__);
459 }
460
461 /**
462 * @tc.name: GetHqfFileAndHapPath_0100
463 * @tc.desc: get patch file and hap path.
464 * @tc.type: FUNC
465 * @tc.require: issueI581VW
466 */
467 HWTEST_F(MainThreadTest, GetHqfFileAndHapPath_0100, TestSize.Level1)
468 {
469 HILOG_INFO("%{public}s start.", __func__);
470 ProcessInfo processInfo("test_quickfix", 1);
471 mainThread_->processInfo_ = std::make_shared<ProcessInfo>(processInfo);
472 std::string bundleName = "com.ohos.quickfix";
473 std::vector<std::pair<std::string, std::string>> fileMap;
474 auto ret = mainThread_->GetHqfFileAndHapPath(bundleName, fileMap);
475 EXPECT_FALSE(ret);
476 HILOG_INFO("%{public}s end.", __func__);
477 }
478
479 /**
480 * @tc.name: ScheduleNotifyUnLoadRepairPatch_0100
481 * @tc.desc: schedule notify unload repair patch.
482 * @tc.type: FUNC
483 * @tc.require: issueI581VW
484 */
485 HWTEST_F(MainThreadTest, ScheduleNotifyUnLoadRepairPatch_0100, TestSize.Level1)
486 {
487 HILOG_INFO("%{public}s start.", __func__);
488 std::string bundleName;
489 int32_t recordId = 0;
490 sptr<IQuickFixCallback> callback = new QuickFixCallbackImpl();
491 auto ret = mainThread_->ScheduleNotifyUnLoadRepairPatch(bundleName, callback, recordId);
492 EXPECT_EQ(ret, NO_ERROR);
493
494 mainThread_->mainHandler_ = nullptr;
495 EXPECT_EQ(mainThread_->ScheduleNotifyUnLoadRepairPatch(bundleName, callback, recordId), ERR_INVALID_VALUE);
496 HILOG_INFO("%{public}s end.", __func__);
497 }
498
499 /**
500 * @tc.name: InitResourceManager_0100
501 * @tc.desc: init resourceManager.
502 * @tc.type: FUNC
503 * @tc.require: issueI581VW
504 */
505 HWTEST_F(MainThreadTest, InitResourceManager_0100, TestSize.Level1)
506 {
507 std::shared_ptr<Global::Resource::ResourceManager> resourceManager(Global::Resource::CreateResourceManager());
508 EXPECT_TRUE(resourceManager != nullptr);
509 HapModuleInfo info;
510 Configuration config;
511 bool multiProjects = true;
512 mainThread_->InitResourceManager(resourceManager, info, info.bundleName, multiProjects, config);
513 EXPECT_TRUE(resourceManager != nullptr);
514 multiProjects = false;
515 mainThread_->InitResourceManager(resourceManager, info, info.bundleName, multiProjects, config);
516 EXPECT_TRUE(resourceManager != nullptr);
517
518 info.name = "com.ohos.contactsdataability";
519 info.moduleName = "entry";
520 info.description = "dataability_description";
521 info.iconPath = "$media:icon";
522 info.deviceTypes = { "smartVision" };
523 info.bundleName = "com.ohos.contactsdataability";
524 multiProjects = true;
525 mainThread_->InitResourceManager(resourceManager, info, info.bundleName, multiProjects, config);
526 EXPECT_TRUE(resourceManager != nullptr);
527
528 multiProjects = false;
529 mainThread_->InitResourceManager(resourceManager, info, info.bundleName, multiProjects, config);
530 EXPECT_TRUE(resourceManager != nullptr);
531
532 info.resourcePath = "/data/app/el1/budle/public/com.ohos.contactsdataability"\
533 "/com.ohos.contactsdataability/assets/entry/resources.index";
534 mainThread_->InitResourceManager(resourceManager, info, info.bundleName, multiProjects, config);
535 EXPECT_TRUE(resourceManager != nullptr);
536
537 info.hapPath = "/system/app/com.ohos.contactsdataability/Contacts_DataAbility.hap";
538 mainThread_->InitResourceManager(resourceManager, info, info.bundleName, multiProjects, config);
539 EXPECT_TRUE(resourceManager != nullptr);
540
541 info.resourcePath = "";
542 mainThread_->InitResourceManager(resourceManager, info, info.bundleName, multiProjects, config);
543 EXPECT_TRUE(resourceManager != nullptr);
544 }
545
546 /**
547 * @tc.name: HandleLaunchApplication_0100
548 * @tc.desc: Handle launch application.
549 * @tc.type: FUNC
550 * @tc.require: issueI581VW
551 */
552 HWTEST_F(MainThreadTest, HandleLaunchApplication_0100, TestSize.Level1)
553 {
554 Configuration config;
555 AppLaunchData lanchdata;
556 ProcessInfo processing("TestProcess", 9999);
557 ApplicationInfo appinf;
558 appinf.name = "MockTestApplication";
559 appinf.moduleSourceDirs.push_back("/hos/lib/libabilitydemo_native.z.so");
560 lanchdata.SetApplicationInfo(appinf);
561 lanchdata.SetProcessInfo(processing);
562 mainThread_->HandleLaunchApplication(lanchdata, config);
563 EXPECT_TRUE(mainThread_->application_ != nullptr);
564
565 lanchdata.SetAppIndex(1);
566 mainThread_->HandleLaunchApplication(lanchdata, config);
567 }
568
569 /**
570 * @tc.name: SetNativeLibPath_0100
571 * @tc.desc: set native lib path.
572 * @tc.type: FUNC
573 * @tc.require: issueI64MUJ
574 */
575 HWTEST_F(MainThreadTest, SetNativeLibPath_0100, TestSize.Level1)
576 {
577 HILOG_INFO("%{public}s start.", __func__);
578 Configuration config;
579 AppLaunchData launchData;
580 ProcessInfo processInfo("test_quickfix", 9999);
581 ApplicationInfo appInfo;
582 appInfo.name = "MainAbility";
583 appInfo.bundleName = "com.ohos.quickfix";
584 launchData.SetApplicationInfo(appInfo);
585 launchData.SetProcessInfo(processInfo);
586
587 // SetNativeLibPath is implemented in anonymous space, called by HandleLaunchApplication
588 mainThread_->HandleLaunchApplication(launchData, config);
589 ASSERT_NE(mainThread_->application_, nullptr);
590 EXPECT_NE(mainThread_->application_->abilityRuntimeContext_, nullptr);
591 HILOG_INFO("%{public}s end.", __func__);
592 }
593
594 /**
595 * @tc.name: ConnectToAppMgr_0100
596 * @tc.desc: ConnectToAppMgr.
597 * @tc.type: FUNC
598 * @tc.require: issueI64MUJ
599 */
600 HWTEST_F(MainThreadTest, ConnectToAppMgr_0100, TestSize.Level1)
601 {
602 HILOG_INFO("%{public}s start.", __func__);
603 EXPECT_TRUE(mainThread_->ConnectToAppMgr());
604 HILOG_INFO("%{public}s end.", __func__);
605 }
606
607 /**
608 * @tc.name: Attach_0100
609 * @tc.desc: Attach.
610 * @tc.type: FUNC
611 * @tc.require: issueI64MUJ
612 */
613 HWTEST_F(MainThreadTest, Attach_0100, TestSize.Level1)
614 {
615 HILOG_INFO("%{public}s start.", __func__);
616 mainThread_->Attach();
617 EXPECT_EQ(MainThreadState::ATTACH, mainThread_->mainThreadState_);
618 HILOG_INFO("%{public}s end.", __func__);
619 }
620
621 /**
622 * @tc.name: RemoveAppMgrDeathRecipient_0100
623 * @tc.desc: RemoveAppMgrDeathRecipient.
624 * @tc.type: FUNC
625 * @tc.require: issueI64MUJ
626 */
627 HWTEST_F(MainThreadTest, RemoveAppMgrDeathRecipient_0100, TestSize.Level1)
628 {
629 HILOG_INFO("%{public}s start.", __func__);
630 mainThread_->RemoveAppMgrDeathRecipient();
631 EXPECT_TRUE(mainThread_->ConnectToAppMgr());
632 mainThread_->RemoveAppMgrDeathRecipient();
633 HILOG_INFO("%{public}s end.", __func__);
634 }
635
636 /**
637 * @tc.name: CheckLaunchApplicationParam_0100
638 * @tc.desc: CheckLaunchApplicationParam.
639 * @tc.type: FUNC
640 * @tc.require: issueI64MUJ
641 */
642 HWTEST_F(MainThreadTest, CheckLaunchApplicationParam_0100, TestSize.Level1)
643 {
644 HILOG_INFO("%{public}s start.", __func__);
645 AppLaunchData appLaunchData;
646 ApplicationInfo appInfo;
647 appInfo.name = "";
648 ProcessInfo processInfo("test", 1);
649 appLaunchData.SetApplicationInfo(appInfo);
650 appLaunchData.SetProcessInfo(processInfo);
651 EXPECT_FALSE(mainThread_->CheckLaunchApplicationParam(appLaunchData));
652 HILOG_INFO("%{public}s end.", __func__);
653 }
654
655 /**
656 * @tc.name: CheckLaunchApplicationParam_0200
657 * @tc.desc: CheckLaunchApplicationParam.
658 * @tc.type: FUNC
659 * @tc.require: issueI64MUJ
660 */
661 HWTEST_F(MainThreadTest, CheckLaunchApplicationParam_0200, TestSize.Level1)
662 {
663 HILOG_INFO("%{public}s start.", __func__);
664 AppLaunchData appLaunchData;
665 ApplicationInfo appInfo;
666 appInfo.name = "test";
667 ProcessInfo processInfo("", 1);
668 appLaunchData.SetApplicationInfo(appInfo);
669 appLaunchData.SetProcessInfo(processInfo);
670 EXPECT_FALSE(mainThread_->CheckLaunchApplicationParam(appLaunchData));
671
672 ProcessInfo processInfo2("test", 1);
673 appLaunchData.SetProcessInfo(processInfo2);
674 EXPECT_TRUE(mainThread_->CheckLaunchApplicationParam(appLaunchData));
675 HILOG_INFO("%{public}s end.", __func__);
676 }
677
678 /**
679 * @tc.name: CheckAbilityItem_0100
680 * @tc.desc: CheckAbilityItem.
681 * @tc.type: FUNC
682 * @tc.require: issueI64MUJ
683 */
684 HWTEST_F(MainThreadTest, CheckAbilityItem_0100, TestSize.Level1)
685 {
686 HILOG_INFO("%{public}s start.", __func__);
687 std::shared_ptr<AbilityInfo> info = std::make_shared<AbilityInfo>();
688 std::shared_ptr<AbilityLocalRecord> record = std::make_shared<AbilityLocalRecord>(info, nullptr);
689 EXPECT_FALSE(mainThread_->CheckAbilityItem(record));
690 HILOG_INFO("%{public}s end.", __func__);
691 }
692
693 /**
694 * @tc.name: CheckAbilityItem_0200
695 * @tc.desc: CheckAbilityItem.
696 * @tc.type: FUNC
697 * @tc.require: issueI64MUJ
698 */
699 HWTEST_F(MainThreadTest, CheckAbilityItem_0200, TestSize.Level1)
700 {
701 HILOG_INFO("%{public}s start.", __func__);
702 std::shared_ptr<AbilityLocalRecord> record = std::make_shared<AbilityLocalRecord>(nullptr, nullptr);
703 EXPECT_FALSE(mainThread_->CheckAbilityItem(record));
704 HILOG_INFO("%{public}s end.", __func__);
705 }
706
707 /**
708 * @tc.name: CheckAbilityItem_0300
709 * @tc.desc: CheckAbilityItem.
710 * @tc.type: FUNC
711 * @tc.require: issueI64MUJ
712 */
713 HWTEST_F(MainThreadTest, CheckAbilityItem_0300, TestSize.Level1)
714 {
715 HILOG_INFO("%{public}s start.", __func__);
716 EXPECT_FALSE(mainThread_->CheckAbilityItem(nullptr));
717 HILOG_INFO("%{public}s end.", __func__);
718 }
719
720 /**
721 * @tc.name: HandleTerminateApplicationLocal_0100
722 * @tc.desc: HandleTerminateApplicationLocal.
723 * @tc.type: FUNC
724 * @tc.require: issueI64MUJ
725 */
726 HWTEST_F(MainThreadTest, HandleTerminateApplicationLocal_0100, TestSize.Level1)
727 {
728 HILOG_INFO("%{public}s start.", __func__);
729 ASSERT_NE(mainThread_, nullptr);
730 mainThread_->application_ = nullptr;
731 mainThread_->HandleTerminateApplicationLocal();
732 HILOG_INFO("%{public}s end.", __func__);
733 }
734
735 /**
736 * @tc.name: HandleTerminateApplicationLocal_0200
737 * @tc.desc: HandleTerminateApplicationLocal.
738 * @tc.type: FUNC
739 * @tc.require: issueI64MUJ
740 */
741 HWTEST_F(MainThreadTest, HandleTerminateApplicationLocal_0200, TestSize.Level1)
742 {
743 HILOG_INFO("%{public}s start.", __func__);
744 ASSERT_NE(mainThread_, nullptr);
745 mainThread_->signalHandler_->SetEventRunner(nullptr);
746 mainThread_->HandleTerminateApplicationLocal();
747 HILOG_INFO("%{public}s end.", __func__);
748 }
749
750 /**
751 * @tc.name: HandleTerminateApplicationLocal_0300
752 * @tc.desc: HandleTerminateApplicationLocal.
753 * @tc.type: FUNC
754 * @tc.require: issueI64MUJ
755 */
756 HWTEST_F(MainThreadTest, HandleTerminateApplicationLocal_0300, TestSize.Level1)
757 {
758 HILOG_INFO("%{public}s start.", __func__);
759 ASSERT_NE(mainThread_, nullptr);
760 mainThread_->mainHandler_->SetEventRunner(nullptr);
761 mainThread_->HandleTerminateApplicationLocal();
762 HILOG_INFO("%{public}s end.", __func__);
763 }
764
765 /**
766 * @tc.name: HandleTerminateApplicationLocal_0400
767 * @tc.desc: HandleTerminateApplicationLocal.
768 * @tc.type: FUNC
769 * @tc.require: issueI64MUJ
770 */
771 HWTEST_F(MainThreadTest, HandleTerminateApplicationLocal_0400, TestSize.Level1)
772 {
773 HILOG_INFO("%{public}s start.", __func__);
774 ASSERT_NE(mainThread_, nullptr);
775 mainThread_->watchdog_ = nullptr;
776 mainThread_->HandleTerminateApplicationLocal();
777 HILOG_INFO("%{public}s end.", __func__);
778 }
779
780 /**
781 * @tc.name: HandleProcessSecurityExit_0100
782 * @tc.desc: HandleProcessSecurityExit.
783 * @tc.type: FUNC
784 * @tc.require: issueI64MUJ
785 */
786 HWTEST_F(MainThreadTest, HandleProcessSecurityExit_0100, TestSize.Level1)
787 {
788 HILOG_INFO("%{public}s start.", __func__);
789 ASSERT_NE(mainThread_, nullptr);
790 mainThread_->abilityRecordMgr_ = nullptr;
791 mainThread_->HandleProcessSecurityExit();
792
793 std::shared_ptr<ContextDeal> contextDeal;
794 ApplicationInfo appInfo;
795 ProcessInfo processInfo;
796 mainThread_->InitCreate(contextDeal, appInfo, processInfo);
797 mainThread_->HandleProcessSecurityExit();
798 HILOG_INFO("%{public}s end.", __func__);
799 }
800
801 /**
802 * @tc.name: HandleProcessSecurityExit_0200
803 * @tc.desc: HandleProcessSecurityExit.
804 * @tc.type: FUNC
805 * @tc.require: issueI64MUJ
806 */
807 HWTEST_F(MainThreadTest, HandleProcessSecurityExit_0200, TestSize.Level1)
808 {
809 HILOG_INFO("%{public}s start.", __func__);
810 ASSERT_NE(mainThread_, nullptr);
811 mainThread_->HandleProcessSecurityExit();
812 HILOG_INFO("%{public}s end.", __func__);
813 }
814
815 /**
816 * @tc.name: CheckForHandleLaunchApplication_0100
817 * @tc.desc: CheckForHandleLaunchApplication.
818 * @tc.type: FUNC
819 * @tc.require: issueI64MUJ
820 */
821 HWTEST_F(MainThreadTest, CheckForHandleLaunchApplication_0100, TestSize.Level1)
822 {
823 HILOG_INFO("%{public}s start.", __func__);
824 mainThread_->application_ = nullptr;
825 AppLaunchData appLaunchData;
826 ApplicationInfo appInfo;
827 appInfo.name = "test";
828 ProcessInfo processInfo("test", 1);
829 appLaunchData.SetApplicationInfo(appInfo);
830 appLaunchData.SetProcessInfo(processInfo);
831 EXPECT_TRUE(mainThread_->CheckForHandleLaunchApplication(appLaunchData));
832 HILOG_INFO("%{public}s end.", __func__);
833 }
834
835 /**
836 * @tc.name: CheckForHandleLaunchApplication_0200
837 * @tc.desc: CheckForHandleLaunchApplication.
838 * @tc.type: FUNC
839 * @tc.require: issueI64MUJ
840 */
841 HWTEST_F(MainThreadTest, CheckForHandleLaunchApplication_0200, TestSize.Level1)
842 {
843 HILOG_INFO("%{public}s start.", __func__);
844 mainThread_->application_ = std::make_shared<OHOSApplication>();
845 AppLaunchData appLaunchData;
846 ApplicationInfo appInfo;
847 appInfo.name = "test";
848 ProcessInfo processInfo("test", 1);
849 appLaunchData.SetApplicationInfo(appInfo);
850 appLaunchData.SetProcessInfo(processInfo);
851 EXPECT_FALSE(mainThread_->CheckForHandleLaunchApplication(appLaunchData));
852 HILOG_INFO("%{public}s end.", __func__);
853 }
854
855 /**
856 * @tc.name: CheckForHandleLaunchApplication_0300
857 * @tc.desc: CheckForHandleLaunchApplication.
858 * @tc.type: FUNC
859 * @tc.require: issueI64MUJ
860 */
861 HWTEST_F(MainThreadTest, CheckForHandleLaunchApplication_0300, TestSize.Level1)
862 {
863 HILOG_INFO("%{public}s start.", __func__);
864 AppLaunchData appLaunchData;
865 ApplicationInfo appInfo;
866 appInfo.name = "";
867 ProcessInfo processInfo("test", 1);
868 appLaunchData.SetApplicationInfo(appInfo);
869 appLaunchData.SetProcessInfo(processInfo);
870 EXPECT_FALSE(mainThread_->CheckForHandleLaunchApplication(appLaunchData));
871 HILOG_INFO("%{public}s end.", __func__);
872 }
873
874 /**
875 * @tc.name: HandleAbilityStage_0100
876 * @tc.desc: HandleAbilityStage.
877 * @tc.type: FUNC
878 * @tc.require: issueI64MUJ
879 */
880 HWTEST_F(MainThreadTest, HandleAbilityStage_0100, TestSize.Level1)
881 {
882 HILOG_INFO("%{public}s start.", __func__);
883 ASSERT_NE(mainThread_, nullptr);
884 HapModuleInfo info;
885 mainThread_->HandleAbilityStage(info);
886 HILOG_INFO("%{public}s end.", __func__);
887 }
888
889 /**
890 * @tc.name: HandleAbilityStage_0200
891 * @tc.desc: HandleAbilityStage.
892 * @tc.type: FUNC
893 * @tc.require: issueI64MUJ
894 */
895 HWTEST_F(MainThreadTest, HandleAbilityStage_0200, TestSize.Level1)
896 {
897 HILOG_INFO("%{public}s start.", __func__);
898 ASSERT_NE(mainThread_, nullptr);
899 mainThread_->application_ = nullptr;
900 HapModuleInfo info;
901 mainThread_->HandleAbilityStage(info);
902 HILOG_INFO("%{public}s end.", __func__);
903 }
904
905 /**
906 * @tc.name: HandleAbilityStage_0300
907 * @tc.desc: HandleAbilityStage.
908 * @tc.type: FUNC
909 * @tc.require: issueI64MUJ
910 */
911 HWTEST_F(MainThreadTest, HandleAbilityStage_0300, TestSize.Level1)
912 {
913 HILOG_INFO("%{public}s start.", __func__);
914 ASSERT_NE(mainThread_, nullptr);
915 mainThread_->appMgr_ = nullptr;
916 HapModuleInfo info;
917 mainThread_->HandleAbilityStage(info);
918 HILOG_INFO("%{public}s end.", __func__);
919 }
920
921 /**
922 * @tc.name: HandleAbilityStage_0400
923 * @tc.desc: HandleAbilityStage.
924 * @tc.type: FUNC
925 * @tc.require: issueI64MUJ
926 */
927 HWTEST_F(MainThreadTest, HandleAbilityStage_0400, TestSize.Level1)
928 {
929 HILOG_INFO("%{public}s start.", __func__);
930 ASSERT_NE(mainThread_, nullptr);
931 mainThread_->applicationImpl_ = nullptr;
932 HapModuleInfo info;
933 mainThread_->HandleAbilityStage(info);
934 HILOG_INFO("%{public}s end.", __func__);
935 }
936
937 /**
938 * @tc.name: PrepareAbilityDelegator_0100
939 * @tc.desc: PrepareAbilityDelegator.
940 * @tc.type: FUNC
941 * @tc.require: issueI64MUJ
942 */
943 HWTEST_F(MainThreadTest, PrepareAbilityDelegator_0100, TestSize.Level1)
944 {
945 HILOG_INFO("%{public}s start.", __func__);
946 mainThread_->application_ = std::make_shared<OHOSApplication>();
947 std::shared_ptr<UserTestRecord> usertestInfo = std::make_shared<UserTestRecord>();
948 bool isStageBased = true;
949 HapModuleInfo hapModuleInfo;
950 EXPECT_TRUE(mainThread_->PrepareAbilityDelegator(usertestInfo, isStageBased, hapModuleInfo));
951 HILOG_INFO("%{public}s end.", __func__);
952 }
953
954 /**
955 * @tc.name: PrepareAbilityDelegator_0200
956 * @tc.desc: PrepareAbilityDelegator.
957 * @tc.type: FUNC
958 * @tc.require: issueI64MUJ
959 */
960 HWTEST_F(MainThreadTest, PrepareAbilityDelegator_0200, TestSize.Level1)
961 {
962 HILOG_INFO("%{public}s start.", __func__);
963 bool isStageBased = true;
964 HapModuleInfo hapModuleInfo;
965 EXPECT_FALSE(mainThread_->PrepareAbilityDelegator(nullptr, isStageBased, hapModuleInfo));
966 HILOG_INFO("%{public}s end.", __func__);
967 }
968
969 /**
970 * @tc.name: PrepareAbilityDelegator_0300
971 * @tc.desc: PrepareAbilityDelegator.
972 * @tc.type: FUNC
973 * @tc.require: issueI64MUJ
974 */
975 HWTEST_F(MainThreadTest, PrepareAbilityDelegator_0300, TestSize.Level1)
976 {
977 HILOG_INFO("%{public}s start.", __func__);
978 mainThread_->application_ = std::make_shared<OHOSApplication>();
979 std::shared_ptr<UserTestRecord> usertestInfo = std::make_shared<UserTestRecord>();
980 bool isStageBased = false;
981 AbilityInfo abilityInfo;
982 HapModuleInfo hapModuleInfo;
983 hapModuleInfo.abilityInfos.emplace_back(abilityInfo);
984 EXPECT_FALSE(mainThread_->PrepareAbilityDelegator(usertestInfo, isStageBased, hapModuleInfo));
985 HILOG_INFO("%{public}s end.", __func__);
986 }
987
988 /**
989 * @tc.name: PrepareAbilityDelegator_0400
990 * @tc.desc: PrepareAbilityDelegator.
991 * @tc.type: FUNC
992 * @tc.require: issueI64MUJ
993 */
994 HWTEST_F(MainThreadTest, PrepareAbilityDelegator_0400, TestSize.Level1)
995 {
996 HILOG_INFO("%{public}s start.", __func__);
997 mainThread_->application_ = std::make_shared<OHOSApplication>();
998 std::shared_ptr<UserTestRecord> usertestInfo = std::make_shared<UserTestRecord>();
999 bool isStageBased = false;
1000 HapModuleInfo hapModuleInfo;
1001 EXPECT_FALSE(mainThread_->PrepareAbilityDelegator(usertestInfo, isStageBased, hapModuleInfo));
1002 HILOG_INFO("%{public}s end.", __func__);
1003 }
1004
1005 /**
1006 * @tc.name: HandleLaunchAbility_0100
1007 * @tc.desc: HandleLaunchAbility.
1008 * @tc.type: FUNC
1009 * @tc.require: issueI64MUJ
1010 */
1011 HWTEST_F(MainThreadTest, HandleLaunchAbility_0100, TestSize.Level1)
1012 {
1013 HILOG_INFO("%{public}s start.", __func__);
1014 std::shared_ptr<AbilityLocalRecord> abilityRecord = std::make_shared<AbilityLocalRecord>(nullptr, nullptr);
1015 ASSERT_NE(abilityRecord, nullptr);
1016 mainThread_->HandleLaunchAbility(abilityRecord);
1017 HILOG_INFO("%{public}s end.", __func__);
1018 }
1019
1020 /**
1021 * @tc.name: HandleCleanAbilityLocal_0100
1022 * @tc.desc: HandleCleanAbilityLocal.
1023 * @tc.type: FUNC
1024 * @tc.require: issueI64MUJ
1025 */
1026 HWTEST_F(MainThreadTest, HandleCleanAbilityLocal_0100, TestSize.Level1)
1027 {
1028 HILOG_INFO("%{public}s start.", __func__);
1029 ASSERT_NE(mainThread_, nullptr);
1030 mainThread_->application_ = nullptr;
1031 mainThread_->HandleCleanAbilityLocal(nullptr);
1032 HILOG_INFO("%{public}s end.", __func__);
1033 }
1034
1035 /**
1036 * @tc.name: HandleCleanAbilityLocal_0200
1037 * @tc.desc: HandleCleanAbilityLocal.
1038 * @tc.type: FUNC
1039 * @tc.require: issueI64MUJ
1040 */
1041 HWTEST_F(MainThreadTest, HandleCleanAbilityLocal_0200, TestSize.Level1)
1042 {
1043 HILOG_INFO("%{public}s start.", __func__);
1044 ASSERT_NE(mainThread_, nullptr);
1045 mainThread_->HandleCleanAbilityLocal(nullptr);
1046 HILOG_INFO("%{public}s end.", __func__);
1047 }
1048
1049 /**
1050 * @tc.name: HandleForegroundApplication_0100
1051 * @tc.desc: HandleForegroundApplication.
1052 * @tc.type: FUNC
1053 * @tc.require: issueI64MUJ
1054 */
1055 HWTEST_F(MainThreadTest, HandleForegroundApplication_0100, TestSize.Level1)
1056 {
1057 HILOG_INFO("%{public}s start.", __func__);
1058 ASSERT_NE(mainThread_, nullptr);
1059 mainThread_->HandleForegroundApplication();
1060 HILOG_INFO("%{public}s end.", __func__);
1061 }
1062
1063 /**
1064 * @tc.name: HandleForegroundApplication_0200
1065 * @tc.desc: HandleForegroundApplication.
1066 * @tc.type: FUNC
1067 * @tc.require: issueI64MUJ
1068 */
1069 HWTEST_F(MainThreadTest, HandleForegroundApplication_0200, TestSize.Level1)
1070 {
1071 HILOG_INFO("%{public}s start.", __func__);
1072 ASSERT_NE(mainThread_, nullptr);
1073 mainThread_->application_ = nullptr;
1074 mainThread_->HandleForegroundApplication();
1075 HILOG_INFO("%{public}s end.", __func__);
1076 }
1077
1078 /**
1079 * @tc.name: HandleForegroundApplication_0300
1080 * @tc.desc: HandleForegroundApplication.
1081 * @tc.type: FUNC
1082 * @tc.require: issueI64MUJ
1083 */
1084 HWTEST_F(MainThreadTest, HandleForegroundApplication_0300, TestSize.Level1)
1085 {
1086 HILOG_INFO("%{public}s start.", __func__);
1087 ASSERT_NE(mainThread_, nullptr);
1088 mainThread_->appMgr_ = nullptr;
1089 mainThread_->HandleForegroundApplication();
1090 HILOG_INFO("%{public}s end.", __func__);
1091 }
1092
1093 /**
1094 * @tc.name: HandleBackgroundApplication_0100
1095 * @tc.desc: HandleBackgroundApplication.
1096 * @tc.type: FUNC
1097 * @tc.require: issueI64MUJ
1098 */
1099 HWTEST_F(MainThreadTest, HandleBackgroundApplication_0100, TestSize.Level1)
1100 {
1101 HILOG_INFO("%{public}s start.", __func__);
1102 ASSERT_NE(mainThread_, nullptr);
1103 mainThread_->HandleBackgroundApplication();
1104 HILOG_INFO("%{public}s end.", __func__);
1105 }
1106
1107 /**
1108 * @tc.name: HandleBackgroundApplication_0200
1109 * @tc.desc: HandleBackgroundApplication.
1110 * @tc.type: FUNC
1111 * @tc.require: issueI64MUJ
1112 */
1113 HWTEST_F(MainThreadTest, HandleBackgroundApplication_0200, TestSize.Level1)
1114 {
1115 HILOG_INFO("%{public}s start.", __func__);
1116 ASSERT_NE(mainThread_, nullptr);
1117 mainThread_->application_ = nullptr;
1118 mainThread_->HandleBackgroundApplication();
1119 HILOG_INFO("%{public}s end.", __func__);
1120 }
1121
1122 /**
1123 * @tc.name: HandleBackgroundApplication_0300
1124 * @tc.desc: HandleBackgroundApplication.
1125 * @tc.type: FUNC
1126 * @tc.require: issueI64MUJ
1127 */
1128 HWTEST_F(MainThreadTest, HandleBackgroundApplication_0300, TestSize.Level1)
1129 {
1130 HILOG_INFO("%{public}s start.", __func__);
1131 ASSERT_NE(mainThread_, nullptr);
1132 mainThread_->appMgr_ = nullptr;
1133 mainThread_->HandleBackgroundApplication();
1134 HILOG_INFO("%{public}s end.", __func__);
1135 }
1136
1137 /**
1138 * @tc.name: HandleTerminateApplication_0100
1139 * @tc.desc: HandleTerminateApplication.
1140 * @tc.type: FUNC
1141 * @tc.require: issueI64MUJ
1142 */
1143 HWTEST_F(MainThreadTest, HandleTerminateApplication_0100, TestSize.Level1)
1144 {
1145 HILOG_INFO("%{public}s start.", __func__);
1146 ASSERT_NE(mainThread_, nullptr);
1147 mainThread_->HandleTerminateApplication();
1148 HILOG_INFO("%{public}s end.", __func__);
1149 }
1150
1151 /**
1152 * @tc.name: HandleTerminateApplication_0200
1153 * @tc.desc: HandleTerminateApplication.
1154 * @tc.type: FUNC
1155 * @tc.require: issueI64MUJ
1156 */
1157 HWTEST_F(MainThreadTest, HandleTerminateApplication_0200, TestSize.Level1)
1158 {
1159 HILOG_INFO("%{public}s start.", __func__);
1160 ASSERT_NE(mainThread_, nullptr);
1161 mainThread_->application_ = nullptr;
1162 mainThread_->HandleTerminateApplication();
1163 HILOG_INFO("%{public}s end.", __func__);
1164 }
1165
1166 /**
1167 * @tc.name: HandleTerminateApplication_0300
1168 * @tc.desc: HandleTerminateApplication.
1169 * @tc.type: FUNC
1170 * @tc.require: issueI64MUJ
1171 */
1172 HWTEST_F(MainThreadTest, HandleTerminateApplication_0300, TestSize.Level1)
1173 {
1174 HILOG_INFO("%{public}s start.", __func__);
1175 ASSERT_NE(mainThread_, nullptr);
1176 mainThread_->appMgr_ = nullptr;
1177 mainThread_->HandleTerminateApplication();
1178 HILOG_INFO("%{public}s end.", __func__);
1179 }
1180
1181 /**
1182 * @tc.name: HandleTerminateApplication_0400
1183 * @tc.desc: HandleTerminateApplication.
1184 * @tc.type: FUNC
1185 * @tc.require: issueI64MUJ
1186 */
1187 HWTEST_F(MainThreadTest, HandleTerminateApplication_0400, TestSize.Level1)
1188 {
1189 HILOG_INFO("%{public}s start.", __func__);
1190 ASSERT_NE(mainThread_, nullptr);
1191 mainThread_->signalHandler_->SetEventRunner(nullptr);
1192 mainThread_->HandleTerminateApplication();
1193 HILOG_INFO("%{public}s end.", __func__);
1194 }
1195
1196 /**
1197 * @tc.name: HandleTerminateApplication_0500
1198 * @tc.desc: HandleTerminateApplication.
1199 * @tc.type: FUNC
1200 * @tc.require: issueI64MUJ
1201 */
1202 HWTEST_F(MainThreadTest, HandleTerminateApplication_0500, TestSize.Level1)
1203 {
1204 HILOG_INFO("%{public}s start.", __func__);
1205 ASSERT_NE(mainThread_, nullptr);
1206 mainThread_->mainHandler_->SetEventRunner(nullptr);
1207 mainThread_->HandleTerminateApplication();
1208 HILOG_INFO("%{public}s end.", __func__);
1209 }
1210
1211 /**
1212 * @tc.name: HandleTerminateApplication_0600
1213 * @tc.desc: HandleTerminateApplication.
1214 * @tc.type: FUNC
1215 * @tc.require: issueI64MUJ
1216 */
1217 HWTEST_F(MainThreadTest, HandleTerminateApplication_0600, TestSize.Level1)
1218 {
1219 HILOG_INFO("%{public}s start.", __func__);
1220 ASSERT_NE(mainThread_, nullptr);
1221 mainThread_->watchdog_ = nullptr;
1222 mainThread_->HandleTerminateApplication();
1223 HILOG_INFO("%{public}s end.", __func__);
1224 }
1225
1226 /**
1227 * @tc.name: HandleShrinkMemory_0100
1228 * @tc.desc: HandleShrinkMemory.
1229 * @tc.type: FUNC
1230 * @tc.require: issueI64MUJ
1231 */
1232 HWTEST_F(MainThreadTest, HandleShrinkMemory_0100, TestSize.Level1)
1233 {
1234 HILOG_INFO("%{public}s start.", __func__);
1235 ASSERT_NE(mainThread_, nullptr);
1236 mainThread_->HandleShrinkMemory(1);
1237 HILOG_INFO("%{public}s end.", __func__);
1238 }
1239
1240 /**
1241 * @tc.name: HandleShrinkMemory_0200
1242 * @tc.desc: HandleShrinkMemory.
1243 * @tc.type: FUNC
1244 * @tc.require: issueI64MUJ
1245 */
1246 HWTEST_F(MainThreadTest, HandleShrinkMemory_0200, TestSize.Level1)
1247 {
1248 HILOG_INFO("%{public}s start.", __func__);
1249 ASSERT_NE(mainThread_, nullptr);
1250 mainThread_->applicationImpl_ = nullptr;
1251 mainThread_->HandleShrinkMemory(1);
1252 HILOG_INFO("%{public}s end.", __func__);
1253 }
1254
1255 /**
1256 * @tc.name: HandleMemoryLevel_0100
1257 * @tc.desc: HandleMemoryLevel.
1258 * @tc.type: FUNC
1259 * @tc.require: issueI64MUJ
1260 */
1261 HWTEST_F(MainThreadTest, HandleMemoryLevel_0100, TestSize.Level1)
1262 {
1263 HILOG_INFO("%{public}s start.", __func__);
1264 ASSERT_NE(mainThread_, nullptr);
1265 mainThread_->HandleMemoryLevel(1);
1266 HILOG_INFO("%{public}s end.", __func__);
1267 }
1268
1269 /**
1270 * @tc.name: HandleMemoryLevel_0200
1271 * @tc.desc: HandleMemoryLevel.
1272 * @tc.type: FUNC
1273 * @tc.require: issueI64MUJ
1274 */
1275 HWTEST_F(MainThreadTest, HandleMemoryLevel_0200, TestSize.Level1)
1276 {
1277 HILOG_INFO("%{public}s start.", __func__);
1278 ASSERT_NE(mainThread_, nullptr);
1279 mainThread_->application_ = nullptr;
1280 mainThread_->HandleMemoryLevel(1);
1281 HILOG_INFO("%{public}s end.", __func__);
1282 }
1283
1284 /**
1285 * @tc.name: HandleConfigurationUpdated_0100
1286 * @tc.desc: HandleConfigurationUpdated.
1287 * @tc.type: FUNC
1288 * @tc.require: issueI64MUJ
1289 */
1290 HWTEST_F(MainThreadTest, HandleConfigurationUpdated_0100, TestSize.Level1)
1291 {
1292 HILOG_INFO("%{public}s start.", __func__);
1293 ASSERT_NE(mainThread_, nullptr);
1294 Configuration config;
1295 mainThread_->HandleConfigurationUpdated(config);
1296 HILOG_INFO("%{public}s end.", __func__);
1297 }
1298
1299 /**
1300 * @tc.name: HandleConfigurationUpdated_0200
1301 * @tc.desc: HandleConfigurationUpdated.
1302 * @tc.type: FUNC
1303 * @tc.require: issueI64MUJ
1304 */
1305 HWTEST_F(MainThreadTest, HandleConfigurationUpdated_0200, TestSize.Level1)
1306 {
1307 HILOG_INFO("%{public}s start.", __func__);
1308 ASSERT_NE(mainThread_, nullptr);
1309 mainThread_->applicationImpl_ = nullptr;
1310 Configuration config;
1311 mainThread_->HandleConfigurationUpdated(config);
1312 HILOG_INFO("%{public}s end.", __func__);
1313 }
1314
1315 /**
1316 * @tc.name: HandleSignal_0100
1317 * @tc.desc: HandleSignal.
1318 * @tc.type: FUNC
1319 * @tc.require: issueI64MUJ
1320 */
1321 HWTEST_F(MainThreadTest, HandleSignal_0100, TestSize.Level1)
1322 {
1323 HILOG_INFO("%{public}s start.", __func__);
1324 ASSERT_NE(mainThread_, nullptr);
1325 constexpr int SIGNAL_JS_HEAP = 39;
1326 mainThread_->HandleSignal(SIGNAL_JS_HEAP);
1327 HILOG_INFO("%{public}s end.", __func__);
1328 }
1329
1330 /**
1331 * @tc.name: HandleSignal_0200
1332 * @tc.desc: HandleSignal.
1333 * @tc.type: FUNC
1334 * @tc.require: issueI64MUJ
1335 */
1336 HWTEST_F(MainThreadTest, HandleSignal_0200, TestSize.Level1)
1337 {
1338 HILOG_INFO("%{public}s start.", __func__);
1339 ASSERT_NE(mainThread_, nullptr);
1340 constexpr int SIGNAL_JS_HEAP_PRIV = 40;
1341 mainThread_->HandleSignal(SIGNAL_JS_HEAP_PRIV);
1342 HILOG_INFO("%{public}s end.", __func__);
1343 }
1344
1345 /**
1346 * @tc.name: HandleSignal_0300
1347 * @tc.desc: HandleSignal.
1348 * @tc.type: FUNC
1349 * @tc.require: issueI64MUJ
1350 */
1351 HWTEST_F(MainThreadTest, HandleSignal_0300, TestSize.Level1)
1352 {
1353 HILOG_INFO("%{public}s start.", __func__);
1354 ASSERT_NE(mainThread_, nullptr);
1355 mainThread_->HandleSignal(-1);
1356 HILOG_INFO("%{public}s end.", __func__);
1357 }
1358
1359 /**
1360 * @tc.name: IsApplicationReady_0100
1361 * @tc.desc: IsApplicationReady.
1362 * @tc.type: FUNC
1363 * @tc.require: issueI64MUJ
1364 */
1365 HWTEST_F(MainThreadTest, IsApplicationReady_0100, TestSize.Level1)
1366 {
1367 HILOG_INFO("%{public}s start.", __func__);
1368 mainThread_->application_ = std::make_shared<OHOSApplication>();
1369 mainThread_->applicationImpl_ = std::make_shared<ApplicationImpl>();
1370 EXPECT_TRUE(mainThread_->IsApplicationReady());
1371 HILOG_INFO("%{public}s end.", __func__);
1372 }
1373
1374 /**
1375 * @tc.name: IsApplicationReady_0200
1376 * @tc.desc: IsApplicationReady.
1377 * @tc.type: FUNC
1378 * @tc.require: issueI64MUJ
1379 */
1380 HWTEST_F(MainThreadTest, IsApplicationReady_0200, TestSize.Level1)
1381 {
1382 HILOG_INFO("%{public}s start.", __func__);
1383 mainThread_->application_ = nullptr;
1384 mainThread_->applicationImpl_ = std::make_shared<ApplicationImpl>();
1385 EXPECT_FALSE(mainThread_->IsApplicationReady());
1386 HILOG_INFO("%{public}s end.", __func__);
1387 }
1388
1389 /**
1390 * @tc.name: IsApplicationReady_0300
1391 * @tc.desc: IsApplicationReady.
1392 * @tc.type: FUNC
1393 * @tc.require: issueI64MUJ
1394 */
1395 HWTEST_F(MainThreadTest, IsApplicationReady_0300, TestSize.Level1)
1396 {
1397 HILOG_INFO("%{public}s start.", __func__);
1398 mainThread_->application_ = std::make_shared<OHOSApplication>();
1399 mainThread_->applicationImpl_ = nullptr;
1400 EXPECT_FALSE(mainThread_->IsApplicationReady());
1401 HILOG_INFO("%{public}s end.", __func__);
1402 }
1403
1404 /**
1405 * @tc.name: CheckFileType_0100
1406 * @tc.desc: CheckFileType.
1407 * @tc.type: FUNC
1408 * @tc.require: issueI64MUJ
1409 */
1410 HWTEST_F(MainThreadTest, CheckFileType_0100, TestSize.Level1)
1411 {
1412 HILOG_INFO("%{public}s start.", __func__);
1413 std::string fileName = "test.testExtension";
1414 std::string extensionName = "testExtension";
1415 EXPECT_FALSE(mainThread_->CheckFileType(fileName, extensionName));
1416 HILOG_INFO("%{public}s end.", __func__);
1417 }
1418
1419 /**
1420 * @tc.name: CheckFileType_0200
1421 * @tc.desc: CheckFileType.
1422 * @tc.type: FUNC
1423 * @tc.require: issueI64MUJ
1424 */
1425 HWTEST_F(MainThreadTest, CheckFileType_0200, TestSize.Level1)
1426 {
1427 HILOG_INFO("%{public}s start.", __func__);
1428 std::string fileName = "";
1429 std::string extensionName = "testExtension";
1430 EXPECT_FALSE(mainThread_->CheckFileType(fileName, extensionName));
1431 HILOG_INFO("%{public}s end.", __func__);
1432 }
1433
1434 /**
1435 * @tc.name: CheckFileType_0300
1436 * @tc.desc: CheckFileType.
1437 * @tc.type: FUNC
1438 * @tc.require: issueI64MUJ
1439 */
1440 HWTEST_F(MainThreadTest, CheckFileType_0300, TestSize.Level1)
1441 {
1442 HILOG_INFO("%{public}s start.", __func__);
1443 std::string fileName = "testExtension";
1444 std::string extensionName = "testExtension";
1445 EXPECT_FALSE(mainThread_->CheckFileType(fileName, extensionName));
1446 HILOG_INFO("%{public}s end.", __func__);
1447 }
1448
1449 /**
1450 * @tc.name: HandleScheduleAcceptWant_0100
1451 * @tc.desc: HandleScheduleAcceptWant.
1452 * @tc.type: FUNC
1453 * @tc.require: issueI64MUJ
1454 */
1455 HWTEST_F(MainThreadTest, HandleScheduleAcceptWant_0100, TestSize.Level1)
1456 {
1457 HILOG_INFO("%{public}s start.", __func__);
1458 Want want;
1459 std::string moduleName;
1460 ASSERT_NE(mainThread_, nullptr);
1461 mainThread_->HandleScheduleAcceptWant(want, moduleName);
1462 HILOG_INFO("%{public}s end.", __func__);
1463 }
1464
1465 /**
1466 * @tc.name: HandleScheduleAcceptWant_0200
1467 * @tc.desc: HandleScheduleAcceptWant.
1468 * @tc.type: FUNC
1469 * @tc.require: issueI64MUJ
1470 */
1471 HWTEST_F(MainThreadTest, HandleScheduleAcceptWant_0200, TestSize.Level1)
1472 {
1473 HILOG_INFO("%{public}s start.", __func__);
1474 mainThread_->application_ = nullptr;
1475 Want want;
1476 std::string moduleName;
1477 ASSERT_NE(mainThread_, nullptr);
1478 mainThread_->HandleScheduleAcceptWant(want, moduleName);
1479 HILOG_INFO("%{public}s end.", __func__);
1480 }
1481
1482 /**
1483 * @tc.name: HandleScheduleAcceptWant_0300
1484 * @tc.desc: HandleScheduleAcceptWant.
1485 * @tc.type: FUNC
1486 * @tc.require: issueI64MUJ
1487 */
1488 HWTEST_F(MainThreadTest, HandleScheduleAcceptWant_0300, TestSize.Level1)
1489 {
1490 HILOG_INFO("%{public}s start.", __func__);
1491 mainThread_->appMgr_ = nullptr;
1492 Want want;
1493 std::string moduleName;
1494 ASSERT_NE(mainThread_, nullptr);
1495 mainThread_->HandleScheduleAcceptWant(want, moduleName);
1496 HILOG_INFO("%{public}s end.", __func__);
1497 }
1498
1499 /**
1500 * @tc.name: HandleScheduleAcceptWant_0400
1501 * @tc.desc: HandleScheduleAcceptWant.
1502 * @tc.type: FUNC
1503 * @tc.require: issueI64MUJ
1504 */
1505 HWTEST_F(MainThreadTest, HandleScheduleAcceptWant_0400, TestSize.Level1)
1506 {
1507 HILOG_INFO("%{public}s start.", __func__);
1508 mainThread_->applicationImpl_ = nullptr;
1509 Want want;
1510 std::string moduleName;
1511 ASSERT_NE(mainThread_, nullptr);
1512 mainThread_->HandleScheduleAcceptWant(want, moduleName);
1513 HILOG_INFO("%{public}s end.", __func__);
1514 }
1515
1516 #ifdef ABILITY_LIBRARY_LOADER
1517 /*
1518 * Feature: MainThread
1519 * Function: LoadNativeLiabrary
1520 * SubFunction: NA
1521 * FunctionPoints: MainThread LoadNativeLiabrary
1522 * EnvConditions: NA
1523 * CaseDescription: Verify LoadNativeLiabrary
1524 */
1525 HWTEST_F(MainThreadTest, LoadNativeLiabrary_0100, TestSize.Level1)
1526 {
1527 HILOG_INFO("%{public}s start.", __func__);
1528 std::string nativeLibraryPath = "";
1529 ASSERT_NE(mainThread_, nullptr);
1530 BundleInfo bundleInfo;
1531 mainThread_->LoadNativeLiabrary(bundleInfo, nativeLibraryPath);
1532
1533 nativeLibraryPath = "test/";
1534 mainThread_->LoadNativeLiabrary(bundleInfo, nativeLibraryPath);
1535 HILOG_INFO("%{public}s end.", __func__);
1536 }
1537 #endif
1538
1539 /*
1540 * Feature: MainThread
1541 * Function: TaskTimeoutDetected
1542 * SubFunction: NA
1543 * FunctionPoints: MainThread TaskTimeoutDetected
1544 * EnvConditions: NA
1545 * CaseDescription: Verify TaskTimeoutDetected
1546 */
1547 HWTEST_F(MainThreadTest, TaskTimeoutDetected_0100, TestSize.Level1)
1548 {
1549 HILOG_INFO("%{public}s start.", __func__);
1550 ASSERT_NE(mainThread_, nullptr);
1551 mainThread_->TaskTimeoutDetected(nullptr);
1552
1553 std::shared_ptr<EventRunner> runner = EventRunner::GetMainEventRunner();
1554 mainThread_->TaskTimeoutDetected(runner);
1555
1556 mainThread_->mainHandler_.reset();
1557 mainThread_->TaskTimeoutDetected(runner);
1558 HILOG_INFO("%{public}s end.", __func__);
1559 }
1560
1561 /*
1562 * Feature: MainThread
1563 * Function: HandleDumpHeap
1564 * SubFunction: NA
1565 * FunctionPoints: MainThread HandleDumpHeap
1566 * EnvConditions: NA
1567 * CaseDescription: Verify HandleDumpHeap
1568 */
1569 HWTEST_F(MainThreadTest, HandleDumpHeap_0100, TestSize.Level1)
1570 {
1571 HILOG_INFO("%{public}s start.", __func__);
1572 bool isPrivate = false;
1573 ASSERT_NE(mainThread_, nullptr);
1574 mainThread_->HandleDumpHeap(isPrivate);
1575
1576 mainThread_->mainHandler_ = nullptr;
1577 mainThread_->HandleDumpHeap(isPrivate);
1578 HILOG_INFO("%{public}s end.", __func__);
1579 }
1580
1581 /**
1582 * @tc.name: ScheduleNotifyLoadRepairPatch_0200
1583 * @tc.desc: schedule notify load repair patch.
1584 * @tc.type: FUNC
1585 */
1586 HWTEST_F(MainThreadTest, ScheduleNotifyLoadRepairPatch_0200, TestSize.Level1)
1587 {
1588 HILOG_INFO("%{public}s start.", __func__);
1589 std::string bundleName;
1590 sptr<IQuickFixCallback> callback = new QuickFixCallbackImpl();
1591 int32_t recordId = 0;
1592 auto bakHandler = mainThread_->mainHandler_;
1593 mainThread_->mainHandler_ = nullptr;
1594 auto ret = mainThread_->ScheduleNotifyLoadRepairPatch(bundleName, callback, recordId);
1595 mainThread_->mainHandler_ = bakHandler;
1596 EXPECT_EQ(ret, ERR_INVALID_VALUE);
1597 HILOG_INFO("%{public}s end.", __func__);
1598 }
1599
1600 /**
1601 * @tc.name: ScheduleNotifyHotReloadPage_0200
1602 * @tc.desc: schedule notify ace hot reload page.
1603 * @tc.type: FUNC
1604 */
1605 HWTEST_F(MainThreadTest, ScheduleNotifyHotReloadPage_0200, TestSize.Level1)
1606 {
1607 HILOG_INFO("%{public}s start.", __func__);
1608 sptr<IQuickFixCallback> callback = new QuickFixCallbackImpl();
1609 int32_t recordId = 0;
1610 auto bakHandler = mainThread_->mainHandler_;
1611 mainThread_->mainHandler_ = nullptr;
1612 auto ret = mainThread_->ScheduleNotifyHotReloadPage(callback, recordId);
1613 mainThread_->mainHandler_ = bakHandler;
1614 EXPECT_EQ(ret, ERR_INVALID_VALUE);
1615 HILOG_INFO("%{public}s end.", __func__);
1616 }
1617
1618 /**
1619 * @tc.name: ScheduleNotifyUnLoadRepairPatch_0200
1620 * @tc.desc: schedule notify unload repair patch.
1621 * @tc.type: FUNC
1622 */
1623 HWTEST_F(MainThreadTest, ScheduleNotifyUnLoadRepairPatch_0200, TestSize.Level1)
1624 {
1625 HILOG_INFO("%{public}s start.", __func__);
1626 std::string bundleName;
1627 int32_t recordId = 0;
1628 sptr<IQuickFixCallback> callback = new QuickFixCallbackImpl();
1629 auto bakHandler = mainThread_->mainHandler_;
1630 mainThread_->mainHandler_ = nullptr;
1631 auto ret = mainThread_->ScheduleNotifyUnLoadRepairPatch(bundleName, callback, recordId);
1632 mainThread_->mainHandler_ = bakHandler;
1633 EXPECT_EQ(ret, ERR_INVALID_VALUE);
1634 HILOG_INFO("%{public}s end.", __func__);
1635 }
1636
1637 /**
1638 * @tc.name: InitResourceManager_0200
1639 * @tc.desc: init resourceManager.
1640 * @tc.type: FUNC
1641 */
1642 HWTEST_F(MainThreadTest, InitResourceManager_0200, TestSize.Level1)
1643 {
1644 std::shared_ptr<Global::Resource::ResourceManager> resourceManager(Global::Resource::CreateResourceManager());
1645 EXPECT_TRUE(resourceManager != nullptr);
1646 Configuration config;
1647 HapModuleInfo hapModuleInfo = {};
1648 hapModuleInfo.isStageBasedModel = true;
1649 const std::string bundleName = "bundleName";
1650 bool multiProjects = true;
1651 mainThread_->InitResourceManager(resourceManager, hapModuleInfo, bundleName, multiProjects, config);
1652 EXPECT_TRUE(resourceManager != nullptr);
1653 }
1654
1655 /**
1656 * @tc.name: HandleLaunchApplication_0200
1657 * @tc.desc: Handle launch application.
1658 * @tc.type: FUNC
1659 */
1660 HWTEST_F(MainThreadTest, HandleLaunchApplication_0200, TestSize.Level1)
1661 {
1662 Configuration config;
1663 AppLaunchData lanchdate;
1664 ProcessInfo processing("TestProcess", 9999);
1665 ApplicationInfo appinf;
1666 appinf.name = "MockTestApplication";
1667 appinf.moduleSourceDirs.push_back("/hos/lib/libabilitydemo_native.z.so");
1668 lanchdate.SetApplicationInfo(appinf);
1669 lanchdate.SetProcessInfo(processing);
1670 mainThread_->application_ = nullptr;
1671 mainThread_->HandleLaunchApplication(lanchdate, config);
1672 EXPECT_TRUE(mainThread_->application_ != nullptr);
1673 }
1674
1675 /**
1676 * @tc.name: HandleLaunchApplication_0300
1677 * @tc.desc: Handle launch application.
1678 * @tc.type: FUNC
1679 */
1680 HWTEST_F(MainThreadTest, HandleLaunchApplication_0300, TestSize.Level1)
1681 {
1682 Configuration config;
1683 AppLaunchData lanchdate;
1684 ProcessInfo processing("TestProcess", 9999);
1685 ApplicationInfo appinf;
1686 appinf.name = "MockTestApplication";
1687 lanchdate.SetProcessInfo(processing);
1688 appinf.bundleName = "com.ohos.contactsdataability";
1689 lanchdate.SetApplicationInfo(appinf);
1690 mainThread_->HandleLaunchApplication(lanchdate, config);
1691 appinf.bundleName = "com.ohos.medialibrary.medialibrarydata";
1692 lanchdate.SetApplicationInfo(appinf);
1693 mainThread_->HandleLaunchApplication(lanchdate, config);
1694 appinf.bundleName = "com.ohos.telephonydataability";
1695 lanchdate.SetApplicationInfo(appinf);
1696 mainThread_->HandleLaunchApplication(lanchdate, config);
1697 appinf.bundleName = "com.ohos.FusionSearch";
1698 lanchdate.SetApplicationInfo(appinf);
1699 mainThread_->HandleLaunchApplication(lanchdate, config);
1700 EXPECT_TRUE(mainThread_->application_ != nullptr);
1701 mainThread_->handleAbilityLib_.clear();
1702 }
1703
1704 /**
1705 * @tc.name: HandleLaunchApplication_0400
1706 * @tc.desc: Handle launch application.
1707 * @tc.type: FUNC
1708 */
1709 HWTEST_F(MainThreadTest, HandleLaunchApplication_0400, TestSize.Level1)
1710 {
1711 Configuration config;
1712 AppLaunchData lanchdate;
1713 ProcessInfo processing("TestProcess", 9999);
1714 ApplicationInfo appinf;
1715 appinf.name = "MockTestApplication";
1716 appinf.moduleSourceDirs.push_back("/hos/lib/libabilitydemo_native.z.so");
1717 lanchdate.SetAppIndex(1);
1718 lanchdate.SetApplicationInfo(appinf);
1719 lanchdate.SetProcessInfo(processing);
1720 mainThread_->HandleLaunchApplication(lanchdate, config);
1721 EXPECT_TRUE(mainThread_->application_ != nullptr);
1722 }
1723
1724 /**
1725 * @tc.name: OnRemoteDied_0100
1726 * @tc.desc: remote Object OnRemoteDied callde.
1727 * @tc.type: FUNC
1728 */
1729 HWTEST_F(MainThreadTest, OnRemoteDied_0100, TestSize.Level1)
1730 {
1731 sptr<AppMgrDeathRecipient> death = new (std::nothrow) AppMgrDeathRecipient();
1732 EXPECT_TRUE(death != nullptr);
1733 wptr<IRemoteObject> remote = nullptr;
1734 death->OnRemoteDied(remote);
1735 }
1736
1737 /**
1738 * @tc.name: RemoveAppMgrDeathRecipient_0200
1739 * @tc.desc: Remove app mgr death recipient.
1740 * @tc.type: FUNC
1741 */
1742 HWTEST_F(MainThreadTest, RemoveAppMgrDeathRecipient_0200, TestSize.Level1)
1743 {
1744 EXPECT_TRUE(mainThread_ != nullptr);
1745 EXPECT_TRUE(mainThread_->appMgr_ == nullptr);
1746 sptr<IRemoteObject> object;
1747 EXPECT_TRUE(object == nullptr);
1748 mainThread_->appMgr_ = new (std::nothrow) AppMgrProxy(object);
1749 mainThread_->RemoveAppMgrDeathRecipient();
1750 EXPECT_TRUE(mainThread_->appMgr_ != nullptr);
1751 }
1752
1753 /**
1754 * @tc.name: RemoveAppMgrDeathRecipient_0300
1755 * @tc.desc: Remove app mgr death recipient.
1756 * @tc.type: FUNC
1757 */
1758 HWTEST_F(MainThreadTest, RemoveAppMgrDeathRecipient_0300, TestSize.Level1)
1759 {
1760 EXPECT_TRUE(mainThread_ != nullptr);
1761 EXPECT_TRUE(mainThread_->appMgr_ == nullptr);
1762 mainThread_->appMgr_ = new (std::nothrow) AppMgrProxy(mainThread_);
1763 mainThread_->RemoveAppMgrDeathRecipient();
1764 EXPECT_TRUE(mainThread_->appMgr_ != nullptr);
1765 }
1766
1767 /**
1768 * @tc.name: PostTask_0100
1769 * @tc.desc: Post task.
1770 * @tc.type: FUNC
1771 */
1772 HWTEST_F(MainThreadTest, PostTask_0100, TestSize.Level1)
1773 {
1774 EXPECT_TRUE(mainThread_ != nullptr);
1775 mainThread_->applicationInfo_ = std::make_shared<ApplicationInfo>();
1776 EXPECT_TRUE(mainThread_->applicationInfo_ != nullptr);
1777 mainThread_->application_ = std::make_shared<OHOSApplication>();
1778 EXPECT_TRUE(mainThread_->application_ != nullptr);
1779 mainThread_->applicationImpl_ = std::make_shared<ApplicationImpl>();
1780 EXPECT_TRUE(mainThread_->applicationImpl_ != nullptr);
__anon66e42e180102() 1781 auto startThreadTask = [main = mainThread_] () {
1782 main->Start();
1783 };
1784 std::thread testThread(startThreadTask);
1785 std::this_thread::sleep_for(std::chrono::seconds(1));
1786 mainThread_->ScheduleForegroundApplication();
1787 mainThread_->ScheduleBackgroundApplication();
1788 mainThread_->ScheduleTerminateApplication();
1789 constexpr int32_t level = 0;
1790 mainThread_->ScheduleShrinkMemory(level);
1791 mainThread_->ScheduleMemoryLevel(level);
1792 mainThread_->ScheduleProcessSecurityExit();
1793 mainThread_->ScheduleLowMemory();
1794 AppLaunchData applaunchData = {};
1795 Configuration configuration = {};
1796 mainThread_->ScheduleLaunchApplication(applaunchData, configuration);
1797 HapModuleInfo hapModuleInfo = {};
1798 mainThread_->ScheduleAbilityStage(hapModuleInfo);
1799 AbilityInfo abilityInfo = {};
1800 sptr<IRemoteObject> token = nullptr;
1801 std::shared_ptr<AAFwk::Want> want = std::make_shared<AAFwk::Want>();
1802 mainThread_->ScheduleLaunchAbility(abilityInfo, token, want);
1803 mainThread_->ScheduleCleanAbility(token);
1804 Profile profile = {};
1805 mainThread_->ScheduleProfileChanged(profile);
1806 mainThread_->ScheduleConfigurationUpdated(configuration);
1807 bool isPrivate = false;
1808 mainThread_->HandleDumpHeap(isPrivate);
1809 const std::string moduleName = "";
1810 mainThread_->ScheduleAcceptWant(*want, moduleName);
1811 const std::string bundleName = "";
1812 sptr<IQuickFixCallback> callback = nullptr;
1813 constexpr int32_t recordId = 0;
1814 mainThread_->ScheduleNotifyLoadRepairPatch(bundleName, callback, recordId);
1815 mainThread_->ScheduleNotifyHotReloadPage(callback, recordId);
1816 mainThread_->ScheduleNotifyUnLoadRepairPatch(bundleName, callback, recordId);
1817 std::this_thread::sleep_for(std::chrono::seconds(1));
1818 mainThread_->HandleTerminateApplicationLocal();
1819 testThread.join();
1820 }
1821
1822 /**
1823 * @tc.name: ChangeToLocalPath_0100
1824 * @tc.desc: Change to local path.
1825 * @tc.type: FUNC
1826 */
1827 HWTEST_F(MainThreadTest, ChangeToLocalPath_0100, TestSize.Level1)
1828 {
1829 EXPECT_TRUE(mainThread_ != nullptr);
1830 const std::string bundleName = "";
1831 const std::vector<std::string> sourceDirs1 = { "test1", "", "test3" };
1832 std::vector<std::string> localPath = {};
1833 mainThread_->ChangeToLocalPath(bundleName, sourceDirs1, localPath);
1834
1835 const std::vector<std::string> sourceDirs2 = {};
1836 mainThread_->ChangeToLocalPath(bundleName, sourceDirs2, localPath);
1837 }
1838
1839 /**
1840 * @tc.name: HandleLaunchAbility_0200
1841 * @tc.desc: handle launch ability.
1842 * @tc.type: FUNC
1843 */
1844 HWTEST_F(MainThreadTest, HandleLaunchAbility_0200, TestSize.Level1)
1845 {
1846 EXPECT_TRUE(mainThread_ != nullptr);
1847 const std::shared_ptr<AbilityLocalRecord> abilityRecord1 = nullptr;
1848 AAFwk::Want want = {};
1849 want.SetParam("debugApp", false);
1850 EXPECT_TRUE(abilityRecord1 == nullptr);
1851 mainThread_->HandleLaunchAbility(abilityRecord1);
1852
1853 mainThread_->applicationImpl_ = std::make_shared<ApplicationImpl>();
1854 mainThread_->HandleLaunchAbility(abilityRecord1);
1855
1856 mainThread_->abilityRecordMgr_ = std::make_shared<AbilityRecordMgr>();
1857 mainThread_->HandleLaunchAbility(abilityRecord1);
1858
1859 const std::shared_ptr<AbilityInfo> info1 = nullptr;
1860 const sptr<IRemoteObject> token = nullptr;
1861 const std::shared_ptr<AbilityLocalRecord> abilityRecord2 = std::make_shared<AbilityLocalRecord>(info1, token);
1862 mainThread_->HandleLaunchAbility(abilityRecord2);
1863
1864 const std::shared_ptr<AbilityInfo> info2 = std::make_shared<AbilityInfo>();
1865 const std::shared_ptr<AbilityLocalRecord> abilityRecord3 = std::make_shared<AbilityLocalRecord>(info2, token);
1866 mainThread_->application_ = std::make_shared<OHOSApplication>();
1867 mainThread_->HandleLaunchAbility(abilityRecord3);
1868
1869 abilityRecord3->token_ = mainThread_;
1870 abilityRecord3->abilityInfo_ = nullptr;
1871 AbilityRuntime::Runtime::Options options;
1872 auto runtime = AbilityRuntime::Runtime::Create(options);
1873 mainThread_->application_->SetRuntime(std::move(runtime));
1874 auto contextDeal = std::make_shared<ContextDeal>();
1875 auto appInfo = std::make_shared<ApplicationInfo>();
1876 appInfo->debug = true;
1877 contextDeal->SetApplicationInfo(appInfo);
1878 mainThread_->application_->AttachBaseContext(contextDeal);
1879 mainThread_->HandleLaunchAbility(abilityRecord3);
1880 }
1881
1882 /**
1883 * @tc.name: HandleCleanAbility_0100
1884 * @tc.desc: handle clean ability.
1885 * @tc.type: FUNC
1886 */
1887 HWTEST_F(MainThreadTest, HandleCleanAbility_0100, TestSize.Level1)
1888 {
1889 EXPECT_TRUE(mainThread_ != nullptr);
1890 mainThread_->abilityRecordMgr_ = std::make_shared<AbilityRecordMgr>();
1891 EXPECT_TRUE(mainThread_->abilityRecordMgr_ != nullptr);
1892 mainThread_->applicationInfo_ = std::make_shared<ApplicationInfo>();
1893 EXPECT_TRUE(mainThread_->applicationInfo_ != nullptr);
1894 mainThread_->application_ = std::make_shared<OHOSApplication>();
1895 EXPECT_TRUE(mainThread_->application_ != nullptr);
1896 mainThread_->applicationImpl_ = std::make_shared<ApplicationImpl>();
1897 EXPECT_TRUE(mainThread_->applicationImpl_ != nullptr);
1898 mainThread_->appMgr_ = new (std::nothrow) AppMgrProxy(mainThread_);
1899 EXPECT_TRUE(mainThread_->appMgr_ != nullptr);
1900
1901 sptr<IRemoteObject> token = nullptr;
1902 mainThread_->HandleCleanAbility(token);
1903
1904 token = new (std::nothrow) BundleMgrService();
1905 mainThread_->HandleCleanAbility(token);
1906
1907 std::shared_ptr<AbilityLocalRecord> abilityRecord = nullptr;
1908 mainThread_->abilityRecordMgr_->abilityRecords_[token] = abilityRecord;
1909 mainThread_->HandleCleanAbility(token);
1910
1911 std::shared_ptr<AbilityInfo> info = nullptr;
1912 abilityRecord = std::make_shared<AbilityLocalRecord>(info, token);
1913 mainThread_->abilityRecordMgr_->AddAbilityRecord(token, abilityRecord);
1914 mainThread_->HandleCleanAbility(token);
1915
1916 info = std::make_shared<AbilityInfo>();
1917 abilityRecord->abilityInfo_ = info;
1918 mainThread_->abilityRecordMgr_->AddAbilityRecord(token, abilityRecord);
1919 mainThread_->HandleCleanAbility(token);
1920
1921 mainThread_->application_ = nullptr;
1922 mainThread_->HandleCleanAbility(token);
1923 }
1924
1925 /**
1926 * @tc.name: LoadAbilityLibrary_0100
1927 * @tc.desc: Load ability library.
1928 * @tc.type: FUNC
1929 */
1930 HWTEST_F(MainThreadTest, LoadAbilityLibrary_0100, TestSize.Level1)
1931 {
1932 EXPECT_TRUE(mainThread_ != nullptr);
1933 const std::vector<std::string> libraryPaths = {
1934 "/system/lib/module/web/",
1935 };
1936
1937 mainThread_->LoadAbilityLibrary(libraryPaths);
1938 mainThread_->handleAbilityLib_.clear();
1939 }
1940
1941 /**
1942 * @tc.name: ScanDir_0100
1943 * @tc.desc: Close ability library.
1944 * @tc.type: FUNC
1945 */
1946 HWTEST_F(MainThreadTest, ScanDir_0100, TestSize.Level1)
1947 {
1948 EXPECT_TRUE(mainThread_ != nullptr);
1949 const std::string path1 = "";
1950 std::vector<std::string> files1;
1951 mainThread_->ScanDir(path1, files1);
1952
1953 const std::string path2 = "/system/lib/module/web/";
1954 std::vector<std::string> files2;
1955 mainThread_->ScanDir(path2, files2);
1956 }
1957
1958 /**
1959 * @tc.name: CheckMainThreadIsAlive_0100
1960 * @tc.desc: Close ability library.
1961 * @tc.type: FUNC
1962 */
1963 HWTEST_F(MainThreadTest, CheckMainThreadIsAlive_0100, TestSize.Level1)
1964 {
1965 EXPECT_TRUE(mainThread_ != nullptr);
1966 mainThread_->watchdog_ = std::make_shared<Watchdog>();
1967 EXPECT_TRUE(mainThread_->watchdog_ != nullptr);
1968
1969 mainThread_->CheckMainThreadIsAlive();
1970 }
1971
1972 /**
1973 * @tc.name: ProcessEvent_0100
1974 * @tc.desc: Main handler process event.
1975 * @tc.type: FUNC
1976 */
1977 HWTEST_F(MainThreadTest, ProcessEvent_0100, TestSize.Level1)
1978 {
1979 EXPECT_TRUE(mainThread_ != nullptr);
__anon66e42e180202() 1980 auto callback = [] () {};
1981 const std::string name = "";
1982 auto event = InnerEvent::Get(callback, name);
1983 mainThread_->mainHandler_->ProcessEvent(event);
1984
1985 event->innerEventId_ = CHECK_MAIN_THREAD_IS_ALIVE;
1986 mainThread_->mainHandler_->ProcessEvent(event);
1987
1988 auto mainThreadObj = mainThread_->mainHandler_->mainThreadObj_.promote();
1989 mainThread_->mainHandler_->mainThreadObj_ = nullptr;
1990 mainThread_->mainHandler_->ProcessEvent(event);
1991 mainThread_->mainHandler_->mainThreadObj_ = mainThreadObj;
1992 }
1993
1994 /**
1995 * @tc.name: Start_0100
1996 * @tc.desc: Main thread start.
1997 * @tc.type: FUNC
1998 */
1999 HWTEST_F(MainThreadTest, Start_0100, TestSize.Level1)
2000 {
2001 EXPECT_TRUE(mainThread_ != nullptr);
2002 mainThread_->application_ = std::make_shared<OHOSApplication>();
2003 EXPECT_TRUE(mainThread_->application_ != nullptr);
2004 mainThread_->applicationImpl_ = std::make_shared<ApplicationImpl>();
2005 EXPECT_TRUE(mainThread_->applicationImpl_ != nullptr);
__anon66e42e180302() 2006 auto startThreadTask = [main = mainThread_] () {
2007 GTEST_LOG_(INFO) << "main thread Begin.";
2008 main->Start();
2009 GTEST_LOG_(INFO) << "main thread End.";
2010 };
2011
2012 std::thread testThread(startThreadTask);
2013 GTEST_LOG_(INFO) << "Wait main thread run.";
2014 std::this_thread::sleep_for(std::chrono::seconds(1));
2015 GTEST_LOG_(INFO) << "Stop to main thread called.";
2016 mainThread_->HandleTerminateApplicationLocal();
2017 GTEST_LOG_(INFO) << "Wait main thread release.";
2018 testThread.join();
2019 }
2020
2021 /**
2022 * @tc.name: ChangeToLocalPath_0200
2023 * @tc.desc: Change the inner path to local path.
2024 * @tc.type: FUNC
2025 * @tc.require: issueI6SAQC
2026 */
2027 HWTEST_F(MainThreadTest, ChangeToLocalPath_0200, TestSize.Level1)
2028 {
2029 EXPECT_TRUE(mainThread_ != nullptr);
2030 std::string bundleName = "com.ohos.demo";
2031 std::string localPath = "/data/app/el1/bundle/public/com.ohos.demo/";
2032 mainThread_->ChangeToLocalPath(bundleName, localPath, localPath);
2033 EXPECT_TRUE(localPath == "/data/storage/el1/bundle/");
2034 }
2035
2036 /**
2037 * @tc.name: ChangeToLocalPath_0300
2038 * @tc.desc: Change the outter path to local path.
2039 * @tc.type: FUNC
2040 * @tc.require: issueI6SAQC
2041 */
2042 HWTEST_F(MainThreadTest, ChangeToLocalPath_0300, TestSize.Level1)
2043 {
2044 EXPECT_TRUE(mainThread_ != nullptr);
2045 std::string bundleName = "com.ohos.demo";
2046 std::string outBundleName = "com.example.demo";
2047 std::string localPath = "/data/app/el1/bundle/public/com.example.demo/";
2048 mainThread_->ChangeToLocalPath(bundleName, localPath, localPath);
2049 EXPECT_TRUE(localPath == "/data/bundles/com.example.demo/");
2050 }
2051
2052 /**
2053 * @tc.name: GetAddOverlayPaths_0100
2054 * @tc.desc: Get overlay paths that need add.
2055 * @tc.type: FUNC
2056 * @tc.require: issueI6SAQC
2057 */
2058 HWTEST_F(MainThreadTest, GetAddOverlayPaths_0100, TestSize.Level1)
2059 {
2060 EXPECT_TRUE(mainThread_ != nullptr);
2061 std::vector<OverlayModuleInfo> overlayModuleInfos;
2062 OverlayModuleInfo overlayModuleInfo;
2063 overlayModuleInfo.bundleName = "com.ohos.demo";
2064 overlayModuleInfo.moduleName = "entry";
2065 overlayModuleInfo.hapPath = "test";
2066 overlayModuleInfo.state = OverlayState::OVERLAY_ENABLE;
2067 overlayModuleInfos.emplace_back(overlayModuleInfo);
2068 mainThread_->overlayModuleInfos_ = overlayModuleInfos;
2069
2070 std::vector<std::string> result = mainThread_->GetAddOverlayPaths(overlayModuleInfos);
2071 EXPECT_TRUE(result.size() == 1);
2072 EXPECT_TRUE(result[0] == "test");
2073 }
2074
2075 /**
2076 * @tc.name: GetRemoveOverlayPaths_0100
2077 * @tc.desc: Get overlay paths that need remove.
2078 * @tc.type: FUNC
2079 * @tc.require: issueI6SAQC
2080 */
2081 HWTEST_F(MainThreadTest, GetRemoveOverlayPaths_0100, TestSize.Level1)
2082 {
2083 EXPECT_TRUE(mainThread_ != nullptr);
2084 std::vector<OverlayModuleInfo> overlayModuleInfos;
2085 OverlayModuleInfo overlayModuleInfo;
2086 overlayModuleInfo.bundleName = "com.ohos.demo";
2087 overlayModuleInfo.moduleName = "entry";
2088 overlayModuleInfo.hapPath = "test";
2089 overlayModuleInfo.state = OverlayState::OVERLAY_ENABLE;
2090 overlayModuleInfos.emplace_back(overlayModuleInfo);
2091 mainThread_->overlayModuleInfos_ = overlayModuleInfos;
2092 overlayModuleInfos[0].state = OverlayState::OVERLAY_DISABLED;
2093
2094 std::vector<std::string> result = mainThread_->GetRemoveOverlayPaths(overlayModuleInfos);
2095 EXPECT_TRUE(result.size() == 1);
2096 EXPECT_TRUE(result[0] == "test");
2097 }
2098
2099 /**
2100 * @tc.name: GetOverlayModuleInfos_0100
2101 * @tc.desc: Get overlay paths form mock bms.
2102 * @tc.type: FUNC
2103 * @tc.require: issueI6SAQC
2104 */
2105 HWTEST_F(MainThreadTest, GetOverlayModuleInfos_0100, TestSize.Level1)
2106 {
2107 EXPECT_TRUE(mainThread_ != nullptr);
2108 std::string bundleName = "com.ohos.demo";
2109 std::string moduleName = "entry";
2110 std::vector<OverlayModuleInfo> overlayModuleInfos;
2111 OverlayModuleInfo overlayModuleInfo;
2112 overlayModuleInfo.bundleName = "com.ohos.demo";
2113 overlayModuleInfo.moduleName = "entry";
2114 overlayModuleInfo.hapPath = "test";
2115 overlayModuleInfo.priority = 99;
2116 overlayModuleInfo.state = OverlayState::OVERLAY_ENABLE;
2117 overlayModuleInfos.emplace_back(overlayModuleInfo);
2118 overlayModuleInfos[0].state = OverlayState::OVERLAY_DISABLED;
2119
2120 int result = mainThread_->GetOverlayModuleInfos(bundleName, moduleName, overlayModuleInfos);
2121 EXPECT_TRUE(result == 0);
2122 EXPECT_TRUE(overlayModuleInfos.size() == 1);
2123 }
2124
2125 /**
2126 * @tc.name: OnOverlayChanged_0100
2127 * @tc.desc: On overlay path changed.
2128 * @tc.type: FUNC
2129 * @tc.require: issueI6SAQC
2130 */
2131 HWTEST_F(MainThreadTest, OnOverlayChanged_0100, TestSize.Level1)
2132 {
2133 EXPECT_TRUE(mainThread_ != nullptr);
2134 std::shared_ptr<Global::Resource::ResourceManager> resourceManager(Global::Resource::CreateResourceManager());
2135 EXPECT_TRUE(resourceManager != nullptr);
2136 std::string bundleName = "com.ohos.demo";
2137 std::string moduleName = "entry";
2138 std::string loadPath = "test";
2139 std::vector<OverlayModuleInfo> overlayModuleInfos;
2140 OverlayModuleInfo overlayModuleInfo;
2141 overlayModuleInfo.bundleName = "com.ohos.demo";
2142 overlayModuleInfo.moduleName = "entry";
2143 overlayModuleInfo.hapPath = "test";
2144 overlayModuleInfo.state = OverlayState::OVERLAY_ENABLE;
2145 overlayModuleInfos.emplace_back(overlayModuleInfo);
2146 overlayModuleInfos[0].state = OverlayState::OVERLAY_DISABLED;
2147 OHOS::EventFwk::CommonEventData data;
2148 AAFwk::Want want;
2149 want.SetElementName("com.ohos.demo", "MainAbility", "entry");
2150 want.SetAction("usual.event.OVERLAY_STATE_CHANGED");
2151 data.SetWant(want);
2152
2153 mainThread_->OnOverlayChanged(data, resourceManager, bundleName, moduleName, loadPath);
2154 }
2155
2156 /**
2157 * @tc.name: HandleOnOverlayChanged_0100
2158 * @tc.desc: Handle the function OnOverlayChanged.
2159 * @tc.type: FUNC
2160 * @tc.require: issueI6SAQC
2161 */
2162 HWTEST_F(MainThreadTest, HandleOnOverlayChanged_0100, TestSize.Level1)
2163 {
2164 EXPECT_TRUE(mainThread_ != nullptr);
2165 std::shared_ptr<Global::Resource::ResourceManager> resourceManager(Global::Resource::CreateResourceManager());
2166 EXPECT_TRUE(resourceManager != nullptr);
2167 std::string bundleName = "com.ohos.demo";
2168 std::string moduleName = "entry";
2169 std::string loadPath = "test";
2170 std::vector<OverlayModuleInfo> overlayModuleInfos;
2171 OverlayModuleInfo overlayModuleInfo;
2172 overlayModuleInfo.bundleName = "com.ohos.demo";
2173 overlayModuleInfo.moduleName = "entry";
2174 overlayModuleInfo.hapPath = "test";
2175 overlayModuleInfo.state = OverlayState::OVERLAY_ENABLE;
2176 overlayModuleInfos.emplace_back(overlayModuleInfo);
2177 overlayModuleInfos[0].state = OverlayState::OVERLAY_DISABLED;
2178 OHOS::EventFwk::CommonEventData data;
2179 AAFwk::Want want;
2180 want.SetElementName("com.ohos.demo", "MainAbility", "entry");
2181 want.SetAction("usual.event.OVERLAY_STATE_CHANGED");
2182 data.SetWant(want);
2183
2184 mainThread_->HandleOnOverlayChanged(data, resourceManager, bundleName, moduleName, loadPath);
2185 }
2186
2187 /**
2188 * @tc.name: ScheduleNotifyAppFault_0100
2189 * @tc.desc: Schedule notify app Fault.
2190 * @tc.type: FUNC
2191 * @tc.require: issueI79RY8
2192 */
2193 HWTEST_F(MainThreadTest, ScheduleNotifyAppFault_0100, TestSize.Level1)
2194 {
2195 FaultData faultData;
2196 faultData.faultType = FaultDataType::JS_ERROR;
2197 faultData.errorObject.message = "msgContent";
2198 faultData.errorObject.stack = "stack";
2199 faultData.errorObject.name = "eventType";
2200 auto ret = mainThread_->ScheduleNotifyAppFault(faultData);
2201 EXPECT_EQ(ret, NO_ERROR);
2202 }
2203
2204 /**
2205 * @tc.name: GetNativeLibPath_0100
2206 * @tc.desc: Get native library path when lib compressed and not isolated.
2207 * @tc.type: FUNC
2208 * @tc.require: issueI7KMGU
2209 */
2210 HWTEST_F(MainThreadTest, GetNativeLibPath_0100, TestSize.Level1)
2211 {
2212 BundleInfo bundleInfo;
2213 HspList hspList;
2214 AppLibPathMap appLibPaths;
2215
2216 bundleInfo.applicationInfo.appQuickFix.deployedAppqfInfo.nativeLibraryPath = "patch_1001/libs/arm";
2217 bundleInfo.applicationInfo.nativeLibraryPath = "libs/arm";
2218
2219 HapModuleInfo hapModuleInfo1;
2220 hapModuleInfo1.isLibIsolated = false;
2221 hapModuleInfo1.compressNativeLibs = true;
2222 // if isLibIsolated is false, hapModuleInfo.hqfInfo.nativeLibraryPath and hapModuleInfo.nativeLibraryPath is empty.
2223 bundleInfo.hapModuleInfos.emplace_back(hapModuleInfo1);
2224
2225 BaseSharedBundleInfo hspInfo1;
2226 hspList.emplace_back(hspInfo1);
2227
2228 mainThread_->GetNativeLibPath(bundleInfo, hspList, appLibPaths);
2229 ASSERT_EQ(appLibPaths.size(), size_t(1));
2230 ASSERT_EQ(appLibPaths["default"].size(), size_t(2));
2231 EXPECT_EQ(appLibPaths["default"][0], "/data/storage/el1/bundle/patch_1001/libs/arm");
2232 EXPECT_EQ(appLibPaths["default"][1], "/data/storage/el1/bundle/libs/arm");
2233 }
2234
2235 /**
2236 * @tc.name: GetNativeLibPath_0200
2237 * @tc.desc: Get native library path when lib compressed and isolated.
2238 * @tc.type: FUNC
2239 * @tc.require: issueI7KMGU
2240 */
2241 HWTEST_F(MainThreadTest, GetNativeLibPath_0200, TestSize.Level1)
2242 {
2243 BundleInfo bundleInfo;
2244 HspList hspList;
2245 AppLibPathMap appLibPaths;
2246
2247 // if all hap lib is compressed and isolated, nativeLibraryPath of application is empty.
2248 HapModuleInfo hapModuleInfo1;
2249 hapModuleInfo1.isLibIsolated = true;
2250 hapModuleInfo1.compressNativeLibs = true;
2251 hapModuleInfo1.bundleName = "com.ohos.myapplication";
2252 hapModuleInfo1.moduleName = "entry";
2253 hapModuleInfo1.nativeLibraryPath = "entry/libs/arm";
2254 hapModuleInfo1.hqfInfo.nativeLibraryPath = "patch_1001/entry/libs/arm";
2255 bundleInfo.hapModuleInfos.emplace_back(hapModuleInfo1);
2256
2257 HapModuleInfo hapModuleInfo2;
2258 hapModuleInfo2.isLibIsolated = true;
2259 hapModuleInfo2.compressNativeLibs = true;
2260 hapModuleInfo2.bundleName = "com.ohos.myapplication";
2261 hapModuleInfo2.moduleName = "feature";
2262 hapModuleInfo2.nativeLibraryPath = "feature/libs/arm";
2263 hapModuleInfo2.hqfInfo.nativeLibraryPath = "patch_1001/feature/libs/arm";
2264 bundleInfo.hapModuleInfos.emplace_back(hapModuleInfo2);
2265
2266 BaseSharedBundleInfo hspInfo1;
2267 hspInfo1.compressNativeLibs = true;
2268 hspInfo1.bundleName = "com.ohos.myapplication";
2269 hspInfo1.moduleName = "library";
2270 hspInfo1.nativeLibraryPath = "library/libs/arm";
2271 hspList.emplace_back(hspInfo1);
2272
2273 mainThread_->GetNativeLibPath(bundleInfo, hspList, appLibPaths);
2274 ASSERT_EQ(appLibPaths.size(), size_t(3));
2275 ASSERT_EQ(appLibPaths["com.ohos.myapplication/entry"].size(), size_t(2));
2276 EXPECT_EQ(appLibPaths["com.ohos.myapplication/entry"][0], "/data/storage/el1/bundle/patch_1001/entry/libs/arm");
2277 EXPECT_EQ(appLibPaths["com.ohos.myapplication/entry"][1], "/data/storage/el1/bundle/entry/libs/arm");
2278
2279 ASSERT_EQ(appLibPaths["com.ohos.myapplication/feature"].size(), size_t(2));
2280 EXPECT_EQ(appLibPaths["com.ohos.myapplication/feature"][0], "/data/storage/el1/bundle/patch_1001/feature/libs/arm");
2281 EXPECT_EQ(appLibPaths["com.ohos.myapplication/feature"][1], "/data/storage/el1/bundle/feature/libs/arm");
2282
2283 ASSERT_EQ(appLibPaths["com.ohos.myapplication/library"].size(), size_t(1));
2284 EXPECT_EQ(appLibPaths["com.ohos.myapplication/library"][0],
2285 "/data/storage/el1/bundle/com.ohos.myapplication/library/libs/arm");
2286 }
2287
2288 /**
2289 * @tc.name: GetNativeLibPath_0300
2290 * @tc.desc: Get native library path when lib uncompressed and not isolated.
2291 * @tc.type: FUNC
2292 * @tc.require: issueI7KMGU
2293 */
2294 HWTEST_F(MainThreadTest, GetNativeLibPath_0300, TestSize.Level1)
2295 {
2296 BundleInfo bundleInfo;
2297 HspList hspList;
2298 AppLibPathMap appLibPaths;
2299
2300 // if all hap lib is uncompressed, nativeLibraryPath of application is empty.
2301 bundleInfo.applicationInfo.appQuickFix.deployedAppqfInfo.nativeLibraryPath = "patch_1001/libs/arm";
2302
2303 HapModuleInfo hapModuleInfo1;
2304 hapModuleInfo1.isLibIsolated = false;
2305 hapModuleInfo1.compressNativeLibs = false;
2306 hapModuleInfo1.bundleName = "com.ohos.myapplication";
2307 hapModuleInfo1.moduleName = "entry";
2308 hapModuleInfo1.hapPath = "/data/app/el1/bundle/public/com.ohos.myapplication/entry.hap";
2309 hapModuleInfo1.nativeLibraryPath = "entry.hap!/libs/armeabi-v7a";
2310 bundleInfo.hapModuleInfos.emplace_back(hapModuleInfo1);
2311
2312 HapModuleInfo hapModuleInfo2;
2313 hapModuleInfo2.isLibIsolated = false;
2314 hapModuleInfo2.compressNativeLibs = false;
2315 hapModuleInfo2.bundleName = "com.ohos.myapplication";
2316 hapModuleInfo2.moduleName = "feature";
2317 hapModuleInfo2.hapPath = "/data/app/el1/bundle/public/com.ohos.myapplication/feature.hap";
2318 hapModuleInfo2.nativeLibraryPath = "feature.hap!/libs/armeabi-v7a";
2319 bundleInfo.hapModuleInfos.emplace_back(hapModuleInfo2);
2320
2321 BaseSharedBundleInfo hspInfo1;
2322 hspInfo1.compressNativeLibs = false;
2323 hspInfo1.hapPath = "/data/app/el1/bundle/public/com.ohos.myapplication/library.hsp";
2324 hspInfo1.bundleName = "com.ohos.myapplication";
2325 hspInfo1.moduleName = "library";
2326 hspInfo1.nativeLibraryPath = "library.hsp!/libs/armeabi-v7a";
2327 hspList.emplace_back(hspInfo1);
2328
2329 mainThread_->GetNativeLibPath(bundleInfo, hspList, appLibPaths);
2330 ASSERT_EQ(appLibPaths.size(), size_t(4));
2331 ASSERT_EQ(appLibPaths["default"].size(), size_t(1));
2332 EXPECT_EQ(appLibPaths["default"][0], "/data/storage/el1/bundle/patch_1001/libs/arm");
2333
2334 ASSERT_EQ(appLibPaths["com.ohos.myapplication/entry"].size(), size_t(2));
2335 EXPECT_EQ(appLibPaths["com.ohos.myapplication/entry"][0], "/data/storage/el1/bundle/patch_1001/libs/arm");
2336 EXPECT_EQ(appLibPaths["com.ohos.myapplication/entry"][1], "/data/storage/el1/bundle/entry.hap!/libs/armeabi-v7a");
2337
2338 ASSERT_EQ(appLibPaths["com.ohos.myapplication/feature"].size(), size_t(2));
2339 EXPECT_EQ(appLibPaths["com.ohos.myapplication/feature"][0], "/data/storage/el1/bundle/patch_1001/libs/arm");
2340 EXPECT_EQ(appLibPaths["com.ohos.myapplication/feature"][1],
2341 "/data/storage/el1/bundle/feature.hap!/libs/armeabi-v7a");
2342
2343 ASSERT_EQ(appLibPaths["com.ohos.myapplication/library"].size(), size_t(1));
2344 EXPECT_EQ(appLibPaths["com.ohos.myapplication/library"][0],
2345 "/data/storage/el1/bundle/com.ohos.myapplication/library/library.hsp!/libs/armeabi-v7a");
2346 }
2347
2348 /**
2349 * @tc.name: GetNativeLibPath_0400
2350 * @tc.desc: Get native library path when lib uncompressed and isolated.
2351 * @tc.type: FUNC
2352 * @tc.require: issueI7KMGU
2353 */
2354 HWTEST_F(MainThreadTest, GetNativeLibPath_0400, TestSize.Level1)
2355 {
2356 BundleInfo bundleInfo;
2357 HspList hspList;
2358 AppLibPathMap appLibPaths;
2359
2360 // if all hap lib is uncompressed and isolated, nativeLibraryPath of application is empty.
2361 HapModuleInfo hapModuleInfo1;
2362 hapModuleInfo1.isLibIsolated = true;
2363 hapModuleInfo1.compressNativeLibs = false;
2364 hapModuleInfo1.bundleName = "com.ohos.myapplication";
2365 hapModuleInfo1.moduleName = "entry";
2366 hapModuleInfo1.hapPath = "/data/app/el1/bundle/public/com.ohos.myapplication/entry.hap";
2367 hapModuleInfo1.nativeLibraryPath = "entry.hap!/libs/armeabi-v7a";
2368 hapModuleInfo1.hqfInfo.nativeLibraryPath = "patch_1001/entry/libs/arm";
2369 bundleInfo.hapModuleInfos.emplace_back(hapModuleInfo1);
2370
2371 HapModuleInfo hapModuleInfo2;
2372 hapModuleInfo2.isLibIsolated = true;
2373 hapModuleInfo2.compressNativeLibs = false;
2374 hapModuleInfo2.bundleName = "com.ohos.myapplication";
2375 hapModuleInfo2.moduleName = "feature";
2376 hapModuleInfo2.hapPath = "/data/app/el1/bundle/public/com.ohos.myapplication/feature.hap";
2377 hapModuleInfo2.nativeLibraryPath = "feature.hap!/libs/armeabi-v7a";
2378 hapModuleInfo2.hqfInfo.nativeLibraryPath = "patch_1001/feature/libs/arm";
2379 bundleInfo.hapModuleInfos.emplace_back(hapModuleInfo2);
2380
2381 BaseSharedBundleInfo hspInfo1;
2382 hspInfo1.compressNativeLibs = false;
2383 hspInfo1.bundleName = "com.ohos.myapplication";
2384 hspInfo1.moduleName = "library";
2385 hspInfo1.hapPath = "/data/app/el1/bundle/public/com.ohos.myapplication/library.hsp";
2386 hspInfo1.nativeLibraryPath = "library.hsp!/libs/armeabi-v7a";
2387 hspList.emplace_back(hspInfo1);
2388
2389 mainThread_->GetNativeLibPath(bundleInfo, hspList, appLibPaths);
2390 ASSERT_EQ(appLibPaths.size(), size_t(3));
2391 ASSERT_EQ(appLibPaths["com.ohos.myapplication/entry"].size(), size_t(2));
2392 EXPECT_EQ(appLibPaths["com.ohos.myapplication/entry"][0], "/data/storage/el1/bundle/patch_1001/entry/libs/arm");
2393 EXPECT_EQ(appLibPaths["com.ohos.myapplication/entry"][1], "/data/storage/el1/bundle/entry.hap!/libs/armeabi-v7a");
2394
2395 ASSERT_EQ(appLibPaths["com.ohos.myapplication/feature"].size(), size_t(2));
2396 EXPECT_EQ(appLibPaths["com.ohos.myapplication/feature"][0], "/data/storage/el1/bundle/patch_1001/feature/libs/arm");
2397 EXPECT_EQ(appLibPaths["com.ohos.myapplication/feature"][1],
2398 "/data/storage/el1/bundle/feature.hap!/libs/armeabi-v7a");
2399
2400 ASSERT_EQ(appLibPaths["com.ohos.myapplication/library"].size(), size_t(1));
2401 EXPECT_EQ(appLibPaths["com.ohos.myapplication/library"][0],
2402 "/data/storage/el1/bundle/com.ohos.myapplication/library/library.hsp!/libs/armeabi-v7a");
2403 }
2404 } // namespace AppExecFwk
2405 } // namespace OHOS