1 /*
2  * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #define private public
17 #define protected public
18 #include <gtest/gtest.h>
19 
20 #include <chrono>
21 #include <cstdio>
22 #include <dirent.h>
23 #include <fcntl.h>
24 #include <fstream>
25 #include <sys/stat.h>
26 #include <sys/types.h>
27 #include <unistd.h>
28 
29 #include "app_service_fwk/app_service_fwk_installer.h"
30 #include "bundle_mgr_service.h"
31 #include "directory_ex.h"
32 #include "install_param.h"
33 #include "installd/installd_service.h"
34 #include "installd_client.h"
35 #include "mock_status_receiver.h"
36 #include "scope_guard.h"
37 #include "shared/shared_bundle_installer.h"
38 #include "system_bundle_installer.h"
39 
40 using namespace testing::ext;
41 using namespace std::chrono_literals;
42 using namespace OHOS::AppExecFwk;
43 using OHOS::DelayedSingleton;
44 
45 namespace OHOS {
46 namespace {
47 const int32_t DEFAULT_USERID = 0;
48 const int32_t USERID = 100;
49 const int32_t VERSION_LOW = 0;
50 const int32_t VERSION = 1000000;
51 const int32_t WAIT_TIME = 5; // init mocked bms
52 const int32_t VERSION_HIGH = INT32_MAX;
53 const std::string BUNDLE_NAME = "com.example.appService";
54 const std::string BUNDLE_NAME_WRONG = "com.example.appService.wrong";
55 const std::string BUNDLE_NAME_TEST = "com.example.l3jsdemo";
56 const std::string MODULE_NAME_TEST = "moduleName";
57 const std::string MODULE_NAME_LIBRARY_ONE = "library_one";
58 const std::string EMPTY_STRING = "";
59 const std::string STRING = "string";
60 const std::string HAP_PATH_TEST = "/data/test/resource/bms/app_service_test/right.hap";
61 const std::string VERSION_ONE_LIBRARY_ONE_PATH = "/data/test/resource/bms/app_service_test/appService_v1_library1.hsp";
62 const std::string VERSION_ONE_LIBRARY_TWO_PATH = "/data/test/resource/bms/app_service_test/appService_v1_library2.hsp";
63 const std::string BUNDLE_DATA_DIR = "/data/app/el2/100/base/com.example.l3jsdemo";
64 const std::string BUNDLE_CODE_DIR = "/data/app/el1/bundle/public/com.example.l3jsdemo";
65 const std::string BUNDLE_LIBRARY_PATH_DIR = "/data/app/el1/bundle/public/com.example.l3jsdemo/libs/arm";
66 const std::string TEST_CREATE_FILE_PATH = "/data/test/resource/bms/app_service_test/test_create_dir/test.hap";
67 const std::string BUILD_HASH = "8670157ae28ac2dc08075c4a9364e320898b4aaf4c1ab691df6afdb854a6811b";
68 }  // namespace
69 
70 class BmsBundleAppServiceFwkInstallerTest : public testing::Test {
71 public:
72     BmsBundleAppServiceFwkInstallerTest();
73     ~BmsBundleAppServiceFwkInstallerTest();
74     static void SetUpTestCase();
75     static void TearDownTestCase();
76     void SetUp();
77     void TearDown();
78     ErrCode InstallSystemBundle(const std::string &filePath, int32_t userId) const;
79     ErrCode UnInstallBundle(const std::string &bundleName, int32_t userId) const;
80     ErrCode InstallSystemHsp(const std::string &filePath);
81     bool DeletePreBundleInfo(const std::string &bundleName);
82     const std::shared_ptr<BundleDataMgr> GetBundleDataMgr() const;
83     const std::shared_ptr<BundleInstallerManager> GetBundleInstallerManager() const;
84     void AddBundleInfo(const std::string &bundleName, const InnerBundleInfo& info);
85     void DeleteBundleInfo(const std::string &bundleName);
86     void StopInstalldService() const;
87     void StopBundleService();
88     void CreateInstallerManager();
89     void ClearBundleInfo(const std::string &bundleName);
90     void ClearDataMgr();
91     void ResetDataMgr();
92     void InitAppServiceFwkInstaller(AppServiceFwkInstaller &appServiceFwkInstaller);
93 
94 private:
95     std::shared_ptr<BundleInstallerManager> manager_ = nullptr;
96     static std::shared_ptr<InstalldService> installdService_;
97     static std::shared_ptr<BundleMgrService> bundleMgrService_;
98 };
99 
100 std::shared_ptr<BundleMgrService> BmsBundleAppServiceFwkInstallerTest::bundleMgrService_ =
101     DelayedSingleton<BundleMgrService>::GetInstance();
102 
103 std::shared_ptr<InstalldService> BmsBundleAppServiceFwkInstallerTest::installdService_ =
104     std::make_shared<InstalldService>();
105 
BmsBundleAppServiceFwkInstallerTest()106 BmsBundleAppServiceFwkInstallerTest::BmsBundleAppServiceFwkInstallerTest()
107 {}
108 
~BmsBundleAppServiceFwkInstallerTest()109 BmsBundleAppServiceFwkInstallerTest::~BmsBundleAppServiceFwkInstallerTest()
110 {}
111 
InstallSystemHsp(const std::string & filePath)112 ErrCode BmsBundleAppServiceFwkInstallerTest::InstallSystemHsp(const std::string &filePath)
113 {
114     AppServiceFwkInstaller appServiceFwkInstaller;
115     InitAppServiceFwkInstaller(appServiceFwkInstaller);
116     InstallParam installParam;
117     installParam.isPreInstallApp = true;
118     installParam.removable = false;
119     std::vector<std::string> hspPaths{ filePath };
120     return appServiceFwkInstaller.Install(hspPaths, installParam);
121 }
122 
InstallSystemBundle(const std::string & filePath,int32_t userId) const123 ErrCode BmsBundleAppServiceFwkInstallerTest::InstallSystemBundle(const std::string &filePath, int32_t userId) const
124 {
125     bundleMgrService_->GetDataMgr()->AddUserId(USERID);
126     auto installer = std::make_unique<SystemBundleInstaller>();
127     InstallParam installParam;
128     installParam.userId = userId;
129     installParam.isPreInstallApp = true;
130     setuid(Constants::FOUNDATION_UID);
131     installParam.SetKillProcess(false);
132     setuid(Constants::ROOT_UID);
133     installParam.needSendEvent = false;
134     installParam.needSavePreInstallInfo = true;
135     installParam.copyHapToInstallPath = false;
136     return installer->InstallSystemBundle(
137         filePath, installParam, Constants::AppType::SYSTEM_APP);
138 }
139 
UnInstallBundle(const std::string & bundleName,int32_t userId) const140 ErrCode BmsBundleAppServiceFwkInstallerTest::UnInstallBundle(const std::string &bundleName, int32_t userId) const
141 {
142     auto installer = bundleMgrService_->GetBundleInstaller();
143     if (!installer) {
144         EXPECT_FALSE(true) << "the installer is nullptr";
145         return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR;
146     }
147     sptr<MockStatusReceiver> receiver = new (std::nothrow) MockStatusReceiver();
148     if (!receiver) {
149         EXPECT_FALSE(true) << "the receiver is nullptr";
150         return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR;
151     }
152     InstallParam installParam;
153     installParam.userId = userId;
154     installParam.installFlag = InstallFlag::NORMAL;
155     bool result = installer->Uninstall(bundleName, installParam, receiver);
156     EXPECT_TRUE(result);
157     return receiver->GetResultCode();
158 }
159 
SetUpTestCase()160 void BmsBundleAppServiceFwkInstallerTest::SetUpTestCase()
161 {
162 }
163 
InitAppServiceFwkInstaller(AppServiceFwkInstaller & appServiceFwkInstaller)164 void BmsBundleAppServiceFwkInstallerTest::InitAppServiceFwkInstaller(AppServiceFwkInstaller &appServiceFwkInstaller)
165 {
166     std::vector<std::string> hspPaths;
167     hspPaths.push_back(VERSION_ONE_LIBRARY_ONE_PATH);
168     InstallParam installParam;
169     installParam.isPreInstallApp = true;
170 
171     appServiceFwkInstaller.BeforeInstall(hspPaths, installParam);
172     appServiceFwkInstaller.versionUpgrade_ = false;
173     appServiceFwkInstaller.moduleUpdate_ = false;
174 }
175 
TearDownTestCase()176 void BmsBundleAppServiceFwkInstallerTest::TearDownTestCase()
177 {
178     bundleMgrService_->OnStop();
179 }
180 
SetUp()181 void BmsBundleAppServiceFwkInstallerTest::SetUp()
182 {
183     if (!installdService_->IsServiceReady()) {
184         installdService_->Start();
185     }
186     if (!bundleMgrService_->IsServiceReady()) {
187         bundleMgrService_->OnStart();
188         bundleMgrService_->GetDataMgr()->AddUserId(USERID);
189         std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME));
190     }
191 }
192 
TearDown()193 void BmsBundleAppServiceFwkInstallerTest::TearDown()
194 {
195     OHOS::ForceRemoveDirectory(BUNDLE_DATA_DIR);
196     OHOS::ForceRemoveDirectory(BUNDLE_CODE_DIR);
197     OHOS::ForceRemoveDirectory(BUNDLE_LIBRARY_PATH_DIR);
198 }
199 
GetBundleDataMgr() const200 const std::shared_ptr<BundleDataMgr> BmsBundleAppServiceFwkInstallerTest::GetBundleDataMgr() const
201 {
202     return bundleMgrService_->GetDataMgr();
203 }
204 
GetBundleInstallerManager() const205 const std::shared_ptr<BundleInstallerManager> BmsBundleAppServiceFwkInstallerTest::GetBundleInstallerManager() const
206 {
207     return manager_;
208 }
209 
ClearDataMgr()210 void BmsBundleAppServiceFwkInstallerTest::ClearDataMgr()
211 {
212     bundleMgrService_->dataMgr_ = nullptr;
213 }
214 
ResetDataMgr()215 void BmsBundleAppServiceFwkInstallerTest::ResetDataMgr()
216 {
217     bundleMgrService_->dataMgr_ = std::make_shared<BundleDataMgr>();
218     EXPECT_NE(bundleMgrService_->dataMgr_, nullptr);
219 }
220 
StopInstalldService() const221 void BmsBundleAppServiceFwkInstallerTest::StopInstalldService() const
222 {
223     if (installdService_->IsServiceReady()) {
224         installdService_->Stop();
225         InstalldClient::GetInstance()->ResetInstalldProxy();
226     }
227 }
228 
StopBundleService()229 void BmsBundleAppServiceFwkInstallerTest::StopBundleService()
230 {
231     if (bundleMgrService_->IsServiceReady()) {
232         bundleMgrService_->OnStop();
233         bundleMgrService_.reset();
234     }
235 }
236 
CreateInstallerManager()237 void BmsBundleAppServiceFwkInstallerTest::CreateInstallerManager()
238 {
239     if (manager_ != nullptr) {
240         return;
241     }
242     manager_ = std::make_shared<BundleInstallerManager>();
243     EXPECT_NE(nullptr, manager_);
244 }
245 
ClearBundleInfo(const std::string & bundleName)246 void BmsBundleAppServiceFwkInstallerTest::ClearBundleInfo(const std::string &bundleName)
247 {
248     if (bundleMgrService_ == nullptr) {
249         return;
250     }
251     auto dataMgr = bundleMgrService_->GetDataMgr();
252     if (dataMgr == nullptr) {
253         return;
254     }
255     auto dataStorage = dataMgr->GetDataStorage();
256     if (dataStorage == nullptr) {
257         return;
258     }
259 
260     // clear innerBundleInfo from data manager
261     dataMgr->UpdateBundleInstallState(bundleName, InstallState::UNINSTALL_START);
262     dataMgr->UpdateBundleInstallState(bundleName, InstallState::UNINSTALL_SUCCESS);
263 
264     InnerBundleInfo innerBundleInfo;
265     ApplicationInfo applicationInfo;
266     applicationInfo.bundleName = bundleName;
267     innerBundleInfo.SetBaseApplicationInfo(applicationInfo);
268     // clear innerBundleInfo from data storage
269     bool result = dataStorage->DeleteStorageBundleInfo(innerBundleInfo);
270     EXPECT_TRUE(result) << "the bundle info in db clear fail: " << bundleName;
271 }
272 
AddBundleInfo(const std::string & bundleName,const InnerBundleInfo & info)273 void BmsBundleAppServiceFwkInstallerTest::AddBundleInfo(const std::string &bundleName, const InnerBundleInfo& info)
274 {
275     if (bundleMgrService_ == nullptr) {
276         return;
277     }
278     auto dataMgr = bundleMgrService_->GetDataMgr();
279     if (dataMgr == nullptr) {
280         return;
281     }
282 
283     dataMgr->bundleInfos_[bundleName] = info;
284 }
285 
DeleteBundleInfo(const std::string & bundleName)286 void BmsBundleAppServiceFwkInstallerTest::DeleteBundleInfo(const std::string &bundleName)
287 {
288     if (bundleMgrService_ == nullptr) {
289         return;
290     }
291     auto dataMgr = bundleMgrService_->GetDataMgr();
292     if (dataMgr == nullptr) {
293         return;
294     }
295 
296     dataMgr->bundleInfos_.erase(bundleName);
297 }
298 
DeletePreBundleInfo(const std::string & bundleName)299 bool BmsBundleAppServiceFwkInstallerTest::DeletePreBundleInfo(const std::string &bundleName)
300 {
301     auto dataMgr = bundleMgrService_->GetDataMgr();
302     if (dataMgr == nullptr) {
303         return false;
304     }
305 
306     PreInstallBundleInfo preInstallBundleInfo;
307     bool getRes = dataMgr->GetPreInstallBundleInfo(bundleName, preInstallBundleInfo);
308     if (!getRes) {
309         return false;
310     }
311     return dataMgr->DeletePreInstallBundleInfo(bundleName, preInstallBundleInfo);
312 }
313 
314 /**
315  * @tc.number: BeforeInstall_0100
316  * @tc.name: test BeforeInstall
317  * @tc.desc: 1.Test the BeforeInstall
318 */
319 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, BeforeInstall_0100, Function | SmallTest | Level0)
320 {
321     AppServiceFwkInstaller appServiceFwkInstaller;
322     std::vector<std::string> hspPaths;
323     hspPaths.push_back(TEST_CREATE_FILE_PATH);
324     InstallParam installParam;
325     installParam.isPreInstallApp = false;
326 
327     auto res1 = appServiceFwkInstaller.BeforeInstall(hspPaths, installParam);
328     EXPECT_EQ(res1, ERR_OK);
329 
330     installParam.isPreInstallApp = true;
331     auto res2 = appServiceFwkInstaller.BeforeInstall(hspPaths, installParam);
332     EXPECT_EQ(res2, ERR_OK);
333 
334     ClearDataMgr();
335     auto res3 = appServiceFwkInstaller.BeforeInstall(hspPaths, installParam);
336     EXPECT_EQ(res3, ERR_APPEXECFWK_INSTALL_BUNDLE_MGR_SERVICE_ERROR);
337 
338     std::vector<std::string> emptyVector;
339     auto res4 = appServiceFwkInstaller.BeforeInstall(emptyVector, installParam);
340     EXPECT_EQ(res4, ERR_APPEXECFWK_INSTALL_PARAM_ERROR);
341     ResetDataMgr();
342 }
343 
344 /**
345  * @tc.number: CheckFileType_0100
346  * @tc.name: test CheckFileType
347  * @tc.desc: 1.Test the CheckFileType
348 */
349 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckFileType_0100, Function | SmallTest | Level0)
350 {
351     AppServiceFwkInstaller appServiceFwkInstaller;
352     std::vector<std::string> hspPaths;
353     auto res = appServiceFwkInstaller.CheckFileType(hspPaths);
354     EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_PARAM_ERROR);
355 
356     hspPaths.push_back(TEST_CREATE_FILE_PATH);
357     res = appServiceFwkInstaller.CheckFileType(hspPaths);
358     EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_INVALID_HAP_NAME);
359 }
360 
361 /**
362  * @tc.number: CheckAppLabelInfo_0100
363  * @tc.name: test CheckAppLabelInfo
364  * @tc.desc: 1.Test the CheckAppLabelInfo
365 */
366 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckAppLabelInfo_0100, Function | SmallTest | Level0)
367 {
368     AppServiceFwkInstaller appServiceFwkInstaller;
369     InnerBundleInfo innerBundleInfo;
370     innerBundleInfo.baseApplicationInfo_->bundleType = BundleType::APP;
371     std::unordered_map<std::string, InnerBundleInfo> infos;
372     infos.emplace(TEST_CREATE_FILE_PATH, innerBundleInfo);
373     auto res = appServiceFwkInstaller.CheckAppLabelInfo(infos);
374     EXPECT_EQ(res, ERR_APP_SERVICE_FWK_INSTALL_TYPE_FAILED);
375 
376     innerBundleInfo.baseApplicationInfo_->bundleType = BundleType::APP_SERVICE_FWK;
377     res = appServiceFwkInstaller.CheckAppLabelInfo(infos);
378     EXPECT_EQ(res, ERR_OK);
379 
380     innerBundleInfo.currentPackage_ = MODULE_NAME_TEST;
381     InnerModuleInfo innerModuleInfo;
382     innerModuleInfo.moduleName = MODULE_NAME_TEST;
383     innerBundleInfo.innerModuleInfos_.emplace(MODULE_NAME_TEST, innerModuleInfo);
384     res = appServiceFwkInstaller.CheckAppLabelInfo(infos);
385     EXPECT_EQ(res, ERR_OK);
386 
387     innerModuleInfo.bundleType = BundleType::SHARED;
388     res = appServiceFwkInstaller.CheckAppLabelInfo(infos);
389     EXPECT_EQ(res, ERR_OK);
390 }
391 
392 /**
393  * @tc.number: CheckAppLabelInfo_0100
394  * @tc.name: test CheckAppLabelInfo
395  * @tc.desc: 1.Test the CheckAppLabelInfo
396 */
397 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckAppLabelInfo_0200, Function | SmallTest | Level0)
398 {
399     AppServiceFwkInstaller appServiceFwkInstaller;
400     InnerBundleInfo innerBundleInfo;
401     innerBundleInfo.baseApplicationInfo_->bundleType = BundleType::APP_SERVICE_FWK;
402     std::unordered_map<std::string, InnerBundleInfo> infos;
403     innerBundleInfo.currentPackage_ = MODULE_NAME_TEST;
404     InnerModuleInfo innerModuleInfo;
405     innerModuleInfo.moduleName = MODULE_NAME_TEST;
406     innerModuleInfo.bundleType = BundleType::APP;
407     innerBundleInfo.innerModuleInfos_.emplace(MODULE_NAME_TEST, innerModuleInfo);
408     infos.emplace(TEST_CREATE_FILE_PATH, innerBundleInfo);
409 
410     auto res = appServiceFwkInstaller.CheckAppLabelInfo(infos);
411     EXPECT_EQ(res, ERR_APP_SERVICE_FWK_INSTALL_TYPE_FAILED);
412 }
413 
414 /**
415  * @tc.number: CheckNeedInstall_0100
416  * @tc.name: test CheckNeedInstall
417  * @tc.desc: 1.Test the CheckNeedInstall
418 */
419 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckNeedInstall_0100, Function | SmallTest | Level0)
420 {
421     AppServiceFwkInstaller appServiceFwkInstaller;
422     std::unordered_map<std::string, InnerBundleInfo> infos;
423     InnerBundleInfo oldInfo;
424     bool result = appServiceFwkInstaller.CheckNeedInstall(infos, oldInfo);
425     EXPECT_FALSE(result);
426 }
427 
428 /**
429  * @tc.number: CheckNeedInstall_0200
430  * @tc.name: test CheckNeedInstall
431  * @tc.desc: 1.Test the CheckNeedInstall
432 */
433 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckNeedInstall_0200, Function | SmallTest | Level0)
434 {
435     AppServiceFwkInstaller appServiceFwkInstaller;
436     InitAppServiceFwkInstaller(appServiceFwkInstaller);
437     std::unordered_map<std::string, InnerBundleInfo> infos;
438     InnerBundleInfo oldInfo;
439 
440     appServiceFwkInstaller.bundleName_ = BUNDLE_NAME_WRONG;
441     infos[VERSION_ONE_LIBRARY_ONE_PATH] = oldInfo;
442     bool result = appServiceFwkInstaller.CheckNeedInstall(infos, oldInfo);
443     EXPECT_TRUE(result);
444 }
445 
446 /**
447  * @tc.number: CheckNeedInstall_0400
448  * @tc.name: test CheckNeedInstall
449  * @tc.desc: 1.Test the CheckNeedInstall
450 */
451 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckNeedInstall_0400, Function | SmallTest | Level0)
452 {
453     AppServiceFwkInstaller appServiceFwkInstaller;
454     InitAppServiceFwkInstaller(appServiceFwkInstaller);
455     std::unordered_map<std::string, InnerBundleInfo> infos;
456     InnerBundleInfo newInfo;
457     ApplicationInfo applicationInfo;
458     applicationInfo.bundleName = BUNDLE_NAME;
459     newInfo.SetBaseApplicationInfo(applicationInfo);
460     AddBundleInfo(BUNDLE_NAME, newInfo);
461 
462     appServiceFwkInstaller.bundleName_ = BUNDLE_NAME;
463     appServiceFwkInstaller.versionCode_ = VERSION_LOW;
464     infos[VERSION_ONE_LIBRARY_ONE_PATH] = newInfo;
465 
466     InnerBundleInfo oldInfo;
467     bool result = appServiceFwkInstaller.CheckNeedInstall(infos, oldInfo);
468     EXPECT_FALSE(result);
469 
470     DeleteBundleInfo(BUNDLE_NAME);
471 }
472 
473 /**
474  * @tc.number: CheckNeedInstall_0500
475  * @tc.name: test CheckNeedInstall
476  * @tc.desc: 1.Test the CheckNeedInstall
477 */
478 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckNeedInstall_0500, Function | SmallTest | Level0)
479 {
480     AppServiceFwkInstaller appServiceFwkInstaller;
481     InitAppServiceFwkInstaller(appServiceFwkInstaller);
482     std::unordered_map<std::string, InnerBundleInfo> infos;
483 
484     InnerBundleInfo innerBundleInfo;
485     ApplicationInfo applicationInfo;
486     applicationInfo.bundleName = BUNDLE_NAME;
487     innerBundleInfo.baseBundleInfo_->versionCode = VERSION;
488     innerBundleInfo.SetBaseApplicationInfo(applicationInfo);
489     AddBundleInfo(BUNDLE_NAME, innerBundleInfo);
490     auto dataMgr = bundleMgrService_->GetDataMgr();
491     ASSERT_NE(dataMgr, nullptr);
492 
493 
494     InnerBundleInfo newInfo;
495     bool getRes = dataMgr->FetchInnerBundleInfo(BUNDLE_NAME, newInfo);
496     EXPECT_TRUE(getRes);
497 
498     appServiceFwkInstaller.bundleName_ = BUNDLE_NAME;
499     appServiceFwkInstaller.versionCode_ = newInfo.GetVersionCode();
500     infos[VERSION_ONE_LIBRARY_ONE_PATH] = newInfo;
501 
502     InnerBundleInfo oldInfo;
503     bool result = appServiceFwkInstaller.CheckNeedInstall(infos, oldInfo);
504     EXPECT_FALSE(result);
505 
506     DeleteBundleInfo(BUNDLE_NAME);
507 }
508 
509 /**
510  * @tc.number: CheckNeedUpdate_0100
511  * @tc.name: test CheckNeedUpdate
512  * @tc.desc: 1.Test the CheckNeedUpdate
513 */
514 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckNeedUpdate_0100, Function | SmallTest | Level0)
515 {
516     AppServiceFwkInstaller appServiceFwkInstaller;
517     appServiceFwkInstaller.versionCode_ = VERSION;
518 
519     InnerBundleInfo oldInfo;
520     oldInfo.baseBundleInfo_->versionCode = VERSION_HIGH;
521     InnerBundleInfo newInfo;
522 
523     bool res = appServiceFwkInstaller.CheckNeedUpdate(newInfo, oldInfo);
524     EXPECT_FALSE(res);
525 }
526 
527 /**
528  * @tc.number: CheckNeedUpdate_0200
529  * @tc.name: test CheckNeedUpdate
530  * @tc.desc: 1.Test the CheckNeedUpdate
531 */
532 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckNeedUpdate_0200, Function | SmallTest | Level0)
533 {
534     AppServiceFwkInstaller appServiceFwkInstaller;
535     appServiceFwkInstaller.versionCode_ = VERSION_HIGH;
536 
537     InnerBundleInfo oldInfo;
538     oldInfo.baseBundleInfo_->versionCode = VERSION;
539     InnerBundleInfo newInfo;
540 
541     bool res = appServiceFwkInstaller.CheckNeedUpdate(newInfo, oldInfo);
542     EXPECT_TRUE(appServiceFwkInstaller.versionUpgrade_);
543     EXPECT_TRUE(res);
544 }
545 
546 /**
547  * @tc.number: CheckNeedUpdate_0300
548  * @tc.name: test CheckNeedUpdate
549  * @tc.desc: 1.Test the CheckNeedUpdate
550 */
551 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckNeedUpdate_0300, Function | SmallTest | Level0)
552 {
553     AppServiceFwkInstaller appServiceFwkInstaller;
554     appServiceFwkInstaller.versionCode_ = VERSION;
555 
556     InnerBundleInfo oldInfo;
557     oldInfo.baseBundleInfo_->versionCode = VERSION;
558     InnerBundleInfo newInfo;
559     newInfo.currentPackage_ = MODULE_NAME_TEST;
560 
561     bool res = appServiceFwkInstaller.CheckNeedUpdate(newInfo, oldInfo);
562     EXPECT_TRUE(appServiceFwkInstaller.moduleUpdate_);
563     EXPECT_TRUE(res);
564 }
565 
566 /**
567  * @tc.number: CheckNeedUpdate_0400
568  * @tc.name: test CheckNeedUpdate
569  * @tc.desc: 1.Test the CheckNeedUpdate
570 */
571 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckNeedUpdate_0400, Function | SmallTest | Level0)
572 {
573     AppServiceFwkInstaller appServiceFwkInstaller;
574     appServiceFwkInstaller.versionCode_ = VERSION;
575 
576     InnerBundleInfo oldInfo;
577     oldInfo.baseBundleInfo_->versionCode = VERSION;
578     oldInfo.currentPackage_ = MODULE_NAME_TEST;
579 
580     InnerModuleInfo innerModuleInfo;
581     innerModuleInfo.moduleName = MODULE_NAME_TEST;
582     oldInfo.innerModuleInfos_[MODULE_NAME_TEST] = innerModuleInfo;
583     InnerBundleInfo newInfo;
584     newInfo.currentPackage_ = MODULE_NAME_TEST;
585     newInfo.innerModuleInfos_[MODULE_NAME_TEST] = innerModuleInfo;
586 
587     bool res = appServiceFwkInstaller.CheckNeedUpdate(newInfo, oldInfo);
588     EXPECT_FALSE(appServiceFwkInstaller.moduleUpdate_);
589     EXPECT_FALSE(res);
590 }
591 
592 /**
593  * @tc.number: CheckNeedUpdate_0500
594  * @tc.name: test CheckNeedUpdate
595  * @tc.desc: 1.Test the CheckNeedUpdate
596 */
597 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckNeedUpdate_0500, Function | SmallTest | Level0)
598 {
599     AppServiceFwkInstaller appServiceFwkInstaller;
600     appServiceFwkInstaller.versionCode_ = VERSION;
601 
602     InnerBundleInfo oldInfo;
603     oldInfo.baseBundleInfo_->versionCode = VERSION;
604     oldInfo.currentPackage_ = MODULE_NAME_TEST;
605 
606     InnerModuleInfo innerModuleInfo;
607     innerModuleInfo.moduleName = MODULE_NAME_TEST;
608     oldInfo.innerModuleInfos_[MODULE_NAME_TEST] = innerModuleInfo;
609 
610     InnerBundleInfo newInfo;
611     newInfo.currentPackage_ = MODULE_NAME_TEST;
612     innerModuleInfo.buildHash = BUILD_HASH;
613     newInfo.innerModuleInfos_[MODULE_NAME_TEST] = innerModuleInfo;
614 
615     bool res = appServiceFwkInstaller.CheckNeedUpdate(newInfo, oldInfo);
616     EXPECT_TRUE(appServiceFwkInstaller.moduleUpdate_);
617     EXPECT_TRUE(res);
618 }
619 
620 /**
621  * @tc.number: RemoveBundleCodeDir_0010
622  * @tc.name: test RemoveBundleCodeDir
623  * @tc.desc: 1.Test the RemoveBundleCodeDir
624 */
625 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, RemoveBundleCodeDir_0010, Function | SmallTest | Level0)
626 {
627     AppServiceFwkInstaller appServiceFwkInstaller;
628 
629     InnerBundleInfo info;
630     auto res = appServiceFwkInstaller.RemoveBundleCodeDir(info);
631     if (appServiceFwkInstaller.dataMgr_ == nullptr) {
632         appServiceFwkInstaller.dataMgr_ = DelayedSingleton<BundleMgrService>::GetInstance()->GetDataMgr();
633     }
634     appServiceFwkInstaller.RemoveInfo(EMPTY_STRING);
635     EXPECT_NE(res, ERR_OK);
636 }
637 
638 /**
639  * @tc.number: GetInnerBundleInfo_0010
640  * @tc.name: test GetInnerBundleInfo
641  * @tc.desc: 1.Test the GetInnerBundleInfo
642 */
643 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, GetInnerBundleInfo_0010, Function | SmallTest | Level0)
644 {
645     AppServiceFwkInstaller appServiceFwkInstaller;
646     appServiceFwkInstaller.bundleName_ = BUNDLE_NAME;
647 
648     InnerBundleInfo info;
649     bool isAppExist;
650     auto res = appServiceFwkInstaller.GetInnerBundleInfo(info, isAppExist);
651     EXPECT_FALSE(isAppExist);
652     EXPECT_TRUE(res);
653 }
654 
655 /**
656  * @tc.number: UninstallLowerVersion_0010
657  * @tc.name: test UninstallLowerVersion
658  * @tc.desc: 1.Test the UninstallLowerVersion
659 */
660 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, UninstallLowerVersion_0010, Function | SmallTest | Level0)
661 {
662     AppServiceFwkInstaller appServiceFwkInstaller;
663     appServiceFwkInstaller.bundleName_ = BUNDLE_NAME;
664 
665     std::vector<std::string> moduleNameList;
666     auto res = appServiceFwkInstaller.UninstallLowerVersion(moduleNameList);
667     EXPECT_EQ(res, ERR_APPEXECFWK_UNINSTALL_BUNDLE_MGR_SERVICE_ERROR);
668 }
669 
670 /**
671  * @tc.number: UninstallLowerVersion_0020
672  * @tc.name: test UninstallLowerVersion
673  * @tc.desc: 1.Test the UninstallLowerVersion
674 */
675 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, UninstallLowerVersion_0020, Function | SmallTest | Level0)
676 {
677     auto installRes = InstallSystemHsp(VERSION_ONE_LIBRARY_ONE_PATH);
678     ASSERT_EQ(installRes, ERR_OK);
679 
680     AppServiceFwkInstaller appServiceFwkInstaller;
681     InitAppServiceFwkInstaller(appServiceFwkInstaller);
682     appServiceFwkInstaller.bundleName_ = BUNDLE_NAME;
683 
684     std::vector<std::string> moduleNameList;
685     auto res = appServiceFwkInstaller.UninstallLowerVersion(moduleNameList);
686     EXPECT_EQ(res, ERR_APPEXECFWK_UNINSTALL_BUNDLE_MGR_SERVICE_ERROR);
687 
688     DeleteBundleInfo(BUNDLE_NAME);
689     DeletePreBundleInfo(BUNDLE_NAME);
690 }
691 
692 /**
693  * @tc.number: UninstallLowerVersion_0030
694  * @tc.name: test UninstallLowerVersion
695  * @tc.desc: 1.Test the UninstallLowerVersion
696 */
697 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, UninstallLowerVersion_0030, Function | SmallTest | Level0)
698 {
699     auto installRes = InstallSystemHsp(VERSION_ONE_LIBRARY_ONE_PATH);
700     ASSERT_EQ(installRes, ERR_OK);
701 
702     AppServiceFwkInstaller appServiceFwkInstaller;
703     InitAppServiceFwkInstaller(appServiceFwkInstaller);
704     appServiceFwkInstaller.bundleName_ = BUNDLE_NAME;
705 
706     auto dataMgr = GetBundleDataMgr();
707     ASSERT_NE(dataMgr, nullptr);
708     dataMgr->installStates_[BUNDLE_NAME] = InstallState::INSTALL_SUCCESS;
709 
710     std::vector<std::string> moduleNameList;
711     auto res = appServiceFwkInstaller.UninstallLowerVersion(moduleNameList);
712     EXPECT_EQ(res, ERR_APPEXECFWK_UNINSTALL_BUNDLE_MGR_SERVICE_ERROR);
713 
714     DeleteBundleInfo(BUNDLE_NAME);
715     DeletePreBundleInfo(BUNDLE_NAME);
716     dataMgr->installStates_.erase(BUNDLE_NAME);
717 }
718 
719 /**
720  * @tc.number: UninstallLowerVersion_0040
721  * @tc.name: test UninstallLowerVersion
722  * @tc.desc: 1.Test the UninstallLowerVersion
723 */
724 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, UninstallLowerVersion_0040, Function | SmallTest | Level0)
725 {
726     auto installRes = InstallSystemHsp(VERSION_ONE_LIBRARY_ONE_PATH);
727     ASSERT_EQ(installRes, ERR_OK);
728 
729     AppServiceFwkInstaller appServiceFwkInstaller;
730     InitAppServiceFwkInstaller(appServiceFwkInstaller);
731     appServiceFwkInstaller.bundleName_ = BUNDLE_NAME;
732 
733     auto dataMgr = GetBundleDataMgr();
734     ASSERT_NE(dataMgr, nullptr);
735     dataMgr->installStates_[BUNDLE_NAME] = InstallState::INSTALL_SUCCESS;
736 
737     std::vector<std::string> moduleNameList { MODULE_NAME_TEST };
738     auto res = appServiceFwkInstaller.UninstallLowerVersion(moduleNameList);
739     EXPECT_EQ(res, ERR_APPEXECFWK_UNINSTALL_BUNDLE_MGR_SERVICE_ERROR);
740 
741     DeleteBundleInfo(BUNDLE_NAME);
742     DeletePreBundleInfo(BUNDLE_NAME);
743     dataMgr->installStates_.erase(BUNDLE_NAME);
744 }
745 
746 /**
747  * @tc.number: UninstallLowerVersion_0050
748  * @tc.name: test UninstallLowerVersion
749  * @tc.desc: 1.Test the UninstallLowerVersion
750 */
751 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, UninstallLowerVersion_0050, Function | SmallTest | Level0)
752 {
753     auto installRes = InstallSystemHsp(VERSION_ONE_LIBRARY_ONE_PATH);
754     ASSERT_EQ(installRes, ERR_OK);
755 
756     auto installRes2 = InstallSystemHsp(VERSION_ONE_LIBRARY_TWO_PATH);
757     ASSERT_EQ(installRes2, ERR_OK);
758 
759     AppServiceFwkInstaller appServiceFwkInstaller;
760     InitAppServiceFwkInstaller(appServiceFwkInstaller);
761     appServiceFwkInstaller.bundleName_ = BUNDLE_NAME;
762 
763     auto dataMgr = GetBundleDataMgr();
764     ASSERT_NE(dataMgr, nullptr);
765     dataMgr->installStates_[BUNDLE_NAME] = InstallState::INSTALL_SUCCESS;
766 
767     std::vector<std::string> moduleNameList { MODULE_NAME_LIBRARY_ONE };
768     auto res = appServiceFwkInstaller.UninstallLowerVersion(moduleNameList);
769     EXPECT_EQ(res, ERR_APPEXECFWK_UNINSTALL_BUNDLE_MGR_SERVICE_ERROR);
770 
771     DeleteBundleInfo(BUNDLE_NAME);
772     DeletePreBundleInfo(BUNDLE_NAME);
773     dataMgr->installStates_.erase(BUNDLE_NAME);
774 }
775 
776 /**
777  * @tc.number: ProcessNewModuleInstall_0010
778  * @tc.name: test ProcessNewModuleInstall
779  * @tc.desc: 1.Test the ProcessNewModuleInstall
780 */
781 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, ProcessNewModuleInstall_0010, Function | SmallTest | Level0)
782 {
783     auto installRes = InstallSystemHsp(VERSION_ONE_LIBRARY_ONE_PATH);
784     ASSERT_EQ(installRes, ERR_OK);
785 
786     auto installRes2 = InstallSystemHsp(VERSION_ONE_LIBRARY_TWO_PATH);
787     ASSERT_EQ(installRes2, ERR_OK);
788 
789     AppServiceFwkInstaller appServiceFwkInstaller;
790     InitAppServiceFwkInstaller(appServiceFwkInstaller);
791     appServiceFwkInstaller.bundleName_ = BUNDLE_NAME;
792 
793     auto dataMgr = GetBundleDataMgr();
794     ASSERT_NE(dataMgr, nullptr);
795     dataMgr->installStates_[BUNDLE_NAME] = InstallState::INSTALL_SUCCESS;
796 
797     std::vector<std::string> moduleNameList { MODULE_NAME_LIBRARY_ONE };
798     auto res = appServiceFwkInstaller.UninstallLowerVersion(moduleNameList);
799     EXPECT_EQ(res, ERR_APPEXECFWK_UNINSTALL_BUNDLE_MGR_SERVICE_ERROR);
800 
801     DeleteBundleInfo(BUNDLE_NAME);
802     DeletePreBundleInfo(BUNDLE_NAME);
803     dataMgr->installStates_.erase(BUNDLE_NAME);
804 }
805 
806 /**
807  * @tc.number: ProcessInstall_0010
808  * @tc.name: test ProcessInstall
809  * @tc.desc: 1.Test the ProcessInstall
810 */
811 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, ProcessInstall_0010, Function | SmallTest | Level0)
812 {
813     AppServiceFwkInstaller appServiceFwkInstaller;
814     InitAppServiceFwkInstaller(appServiceFwkInstaller);
815 
816     std::vector<std::string> hspPaths;
817     hspPaths.push_back(VERSION_ONE_LIBRARY_ONE_PATH);
818     InstallParam installParam;
819     installParam.isPreInstallApp = false;
820     installParam.specifiedDistributionType = BUNDLE_NAME;
821     installParam.additionalInfo = BUNDLE_NAME;
822     installParam.needSavePreInstallInfo = true;
823 
824     std::unordered_map<std::string, InnerBundleInfo> infos;
825     appServiceFwkInstaller.SavePreInstallBundleInfo(ERR_APPEXECFWK_INSTALL_PARAM_ERROR, infos, installParam);
826 
827     auto res = appServiceFwkInstaller.ProcessInstall(hspPaths, installParam);
828     appServiceFwkInstaller.SavePreInstallBundleInfo(res, infos, installParam);
829     EXPECT_EQ(res, ERR_OK);
830 
831     Security::Verify::ProvisionInfo provisionInfo;
832     appServiceFwkInstaller.AddAppProvisionInfo(BUNDLE_NAME, provisionInfo, installParam);
833 }
834 
835 /**
836  * @tc.number: ProcessInstall_0010
837  * @tc.name: test ProcessInstall
838  * @tc.desc: 1.Test the ProcessInstall
839 */
840 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, MkdirIfNotExist_0010, Function | SmallTest | Level0)
841 {
842     AppServiceFwkInstaller appServiceFwkInstaller;
843     InitAppServiceFwkInstaller(appServiceFwkInstaller);
844 
845     Security::Verify::ProvisionInfo provisionInfo;
846     InstallParam installParam;
847     appServiceFwkInstaller.AddAppProvisionInfo(BUNDLE_NAME, provisionInfo, installParam);
848     installParam.specifiedDistributionType = BUNDLE_NAME;
849     installParam.additionalInfo = BUNDLE_NAME;
850     appServiceFwkInstaller.AddAppProvisionInfo(BUNDLE_NAME, provisionInfo, installParam);
851 
852     auto res = appServiceFwkInstaller.MkdirIfNotExist(VERSION_ONE_LIBRARY_ONE_PATH);
853     EXPECT_EQ(res, ERR_APPEXECFWK_INSTALLD_CREATE_DIR_FAILED);
854 }
855 
856 /**
857  * @tc.number: InnerProcessInstall_0010
858  * @tc.name: test InnerProcessInstall
859  * @tc.desc: 1.Test the InnerProcessInstall
860 */
861 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, InnerProcessInstall_0010, Function | SmallTest | Level0)
862 {
863     AppServiceFwkInstaller appServiceFwkInstaller;
864     InitAppServiceFwkInstaller(appServiceFwkInstaller);
865 
866     InstallParam installParam;
867     installParam.copyHapToInstallPath = false;
868     std::unordered_map<std::string, InnerBundleInfo> infos;
869     InnerBundleInfo innerBundleInfo;
870     innerBundleInfo.currentPackage_ = MODULE_NAME_TEST;
871     infos.emplace(TEST_CREATE_FILE_PATH, innerBundleInfo);
872 
873     auto res = appServiceFwkInstaller.InnerProcessInstall(infos, installParam);
874     EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_STATE_ERROR);
875 }
876 
877 /**
878  * @tc.number: ProcessNativeLibrary_0010
879  * @tc.name: test ProcessNativeLibrary
880  * @tc.desc: 1.Test the ProcessNativeLibrary
881 */
882 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, ProcessNativeLibrary_0010, Function | SmallTest | Level0)
883 {
884     AppServiceFwkInstaller appServiceFwkInstaller;
885     InitAppServiceFwkInstaller(appServiceFwkInstaller);
886 
887     InnerBundleInfo innerBundleInfo;
888     innerBundleInfo.currentPackage_ = MODULE_NAME_TEST;
889     appServiceFwkInstaller.MergeBundleInfos(innerBundleInfo);
890     appServiceFwkInstaller.newInnerBundleInfo_.baseBundleInfo_->name = BUNDLE_NAME;
891     appServiceFwkInstaller.MergeBundleInfos(innerBundleInfo);
892 
893     auto res = appServiceFwkInstaller.ProcessNativeLibrary(
894         VERSION_ONE_LIBRARY_ONE_PATH, BUNDLE_DATA_DIR, MODULE_NAME_TEST, BUNDLE_DATA_DIR, innerBundleInfo);
895     EXPECT_EQ(res, ERR_OK);
896 
897     innerBundleInfo.currentPackage_ = MODULE_NAME_TEST;
898     InnerModuleInfo innerModuleInfo;
899     innerModuleInfo.moduleName = MODULE_NAME_TEST;
900     innerModuleInfo.nativeLibraryPath = BUNDLE_DATA_DIR;
901     innerModuleInfo.compressNativeLibs = false;
902     innerBundleInfo.innerModuleInfos_.emplace(MODULE_NAME_TEST, innerModuleInfo);
903 
904     res = appServiceFwkInstaller.ProcessNativeLibrary(
905         VERSION_ONE_LIBRARY_ONE_PATH, BUNDLE_DATA_DIR, MODULE_NAME_TEST, BUNDLE_DATA_DIR, innerBundleInfo);
906     EXPECT_EQ(res, ERR_OK);
907 
908     res = appServiceFwkInstaller.SaveBundleInfoToStorage();
909     EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_STATE_ERROR);
910 }
911 
912 /**
913  * @tc.number: MoveSoToRealPath_0010
914  * @tc.name: test MoveSoToRealPath
915  * @tc.desc: 1.Test the MoveSoToRealPath
916 */
917 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, MoveSoToRealPath_0010, Function | SmallTest | Level0)
918 {
919     AppServiceFwkInstaller appServiceFwkInstaller;
920     InitAppServiceFwkInstaller(appServiceFwkInstaller);
921 
922     auto res = appServiceFwkInstaller.MoveSoToRealPath(MODULE_NAME_LIBRARY_ONE, "data/test", MODULE_NAME_LIBRARY_ONE);
923     EXPECT_EQ(res, ERR_OK);
924 
925     InstallParam installParam;
926     std::unordered_map<std::string, InnerBundleInfo> infos;
927     InnerBundleInfo innerBundleInfo;
928     innerBundleInfo.currentPackage_ = MODULE_NAME_TEST;
929     infos.emplace(TEST_CREATE_FILE_PATH, innerBundleInfo);
930     res = appServiceFwkInstaller.UpdateAppService(innerBundleInfo, infos, installParam);
931     EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_STATE_ERROR);
932 }
933 
934 /**
935  * @tc.number: ProcessBundleUpdateStatus_0010
936  * @tc.name: test ProcessBundleUpdateStatus
937  * @tc.desc: 1.Test the ProcessBundleUpdateStatus
938 */
939 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, ProcessBundleUpdateStatus_0010, Function | SmallTest | Level0)
940 {
941     AppServiceFwkInstaller appServiceFwkInstaller;
942     InitAppServiceFwkInstaller(appServiceFwkInstaller);
943 
944     InnerBundleInfo oldInfo;
945     InnerBundleInfo newInfo;
946     InstallParam installParam;
947     installParam.copyHapToInstallPath = false;
948     auto res = appServiceFwkInstaller.ProcessBundleUpdateStatus(
949         oldInfo, newInfo, VERSION_ONE_LIBRARY_ONE_PATH, installParam);
950     EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_PARAM_ERROR);
951 
952     newInfo.currentPackage_ = MODULE_NAME_TEST;
953     res = appServiceFwkInstaller.ProcessBundleUpdateStatus(
954         oldInfo, newInfo, VERSION_ONE_LIBRARY_ONE_PATH, installParam);
955     EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_STATE_ERROR);
956 
957     appServiceFwkInstaller.versionUpgrade_ = true;
958     res = appServiceFwkInstaller.ProcessBundleUpdateStatus(
959         oldInfo, newInfo, VERSION_ONE_LIBRARY_ONE_PATH, installParam);
960     EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_STATE_ERROR);
961 }
962 
963 /**
964  * @tc.number: GetInnerBundleInfo_0020
965  * @tc.name: test GetInnerBundleInfo
966  * @tc.desc: 1.Test the GetInnerBundleInfo
967 */
968 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, GetInnerBundleInfo_0020, Function | SmallTest | Level0)
969 {
970     AppServiceFwkInstaller appServiceFwkInstaller;
971     InitAppServiceFwkInstaller(appServiceFwkInstaller);
972 
973     ClearDataMgr();
974     InnerBundleInfo info;
975     bool isAppExist;
976     auto res = appServiceFwkInstaller.GetInnerBundleInfo(info, isAppExist);
977     EXPECT_TRUE(res);
978     ResetDataMgr();
979 }
980 
981 /**
982  * @tc.number: CheckNeedInstall_0010
983  * @tc.name: test CheckNeedInstall
984  * @tc.desc: 1.Test the CheckNeedInstall
985 */
986 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckNeedInstall_0010, Function | SmallTest | Level0)
987 {
988     AppServiceFwkInstaller appServiceFwkInstaller;
989     InitAppServiceFwkInstaller(appServiceFwkInstaller);
990 
991     std::unordered_map<std::string, InnerBundleInfo> infos;
992     InnerBundleInfo oldInfo;
993     auto res = appServiceFwkInstaller.CheckNeedInstall(infos, oldInfo);
994     EXPECT_FALSE(res);
995 
996     InnerBundleInfo info;
997     infos.emplace(TEST_CREATE_FILE_PATH, info);
998     res = appServiceFwkInstaller.CheckNeedInstall(infos, oldInfo);
999     EXPECT_TRUE(res);
1000 }
1001 
1002 /**
1003  * @tc.number: CheckNeedUpdate_0010
1004  * @tc.name: test CheckNeedUpdate
1005  * @tc.desc: 1.Test the CheckNeedUpdate
1006 */
1007 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckNeedUpdate_0010, Function | SmallTest | Level0)
1008 {
1009     AppServiceFwkInstaller appServiceFwkInstaller;
1010     InitAppServiceFwkInstaller(appServiceFwkInstaller);
1011 
1012     InnerBundleInfo newInfo;
1013     InnerBundleInfo oldInfo;
1014     newInfo.currentPackage_ = MODULE_NAME_TEST;
1015     oldInfo.baseBundleInfo_->versionCode = 1;
1016     appServiceFwkInstaller.versionCode_ = 0;
1017     auto res = appServiceFwkInstaller.CheckNeedUpdate(newInfo, oldInfo);
1018     EXPECT_FALSE(res);
1019 
1020     appServiceFwkInstaller.versionCode_ = 2;
1021     res = appServiceFwkInstaller.CheckNeedUpdate(newInfo, oldInfo);
1022     EXPECT_TRUE(res);
1023 
1024     appServiceFwkInstaller.versionCode_ = 1;
1025     res = appServiceFwkInstaller.CheckNeedUpdate(newInfo, oldInfo);
1026     EXPECT_TRUE(res);
1027 }
1028 
1029 /**
1030  * @tc.number: RemoveLowerVersionSoDir_0010
1031  * @tc.name: test RemoveLowerVersionSoDir
1032  * @tc.desc: 1.Test the RemoveLowerVersionSoDir
1033 */
1034 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, RemoveLowerVersionSoDir_0010, Function | SmallTest | Level0)
1035 {
1036     AppServiceFwkInstaller appServiceFwkInstaller;
1037     InitAppServiceFwkInstaller(appServiceFwkInstaller);
1038 
1039     auto res = appServiceFwkInstaller.RemoveLowerVersionSoDir(VERSION_LOW);
1040     EXPECT_EQ(res, ERR_OK);
1041 
1042     appServiceFwkInstaller.versionUpgrade_ = true;
1043     res = appServiceFwkInstaller.RemoveLowerVersionSoDir(VERSION_LOW);
1044     EXPECT_EQ(res, ERR_OK);
1045 }
1046 
1047 /**
1048  * @tc.number: MoveFiles_0100
1049  * @tc.name: test function of MoveFiles
1050  * @tc.desc: calling MoveFiles of InstalldOperator
1051 */
1052 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, MoveFiles_0100, Function | SmallTest | Level1)
1053 {
1054     InstalldOperator installdOperator;
1055     bool ret = installdOperator.MoveFiles(TEST_CREATE_FILE_PATH, TEST_CREATE_FILE_PATH, true);
1056     EXPECT_EQ(ret, true);
1057 }
1058 
1059 /**
1060  * @tc.number: ExtractModule_0100
1061  * @tc.name: test function of ExtractModule
1062  * @tc.desc: 1. calling ExtractModule of AppServiceFwkInstaller
1063 */
1064 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, ExtractModule_0100, Function | SmallTest | Level1)
1065 {
1066     AppServiceFwkInstaller installer;
1067     InnerBundleInfo oldInfo;
1068     InnerBundleInfo newInfo;
1069     std::string bundlePath;
1070     auto ret = installer.ExtractModule(oldInfo, newInfo, bundlePath);
1071     EXPECT_EQ(ret, ERR_OK);
1072 }
1073 
1074 /**
1075  * @tc.number: MoveSoToRealPath_0100
1076  * @tc.name: test function of MoveSoToRealPath
1077  * @tc.desc: calling MoveSoToRealPath of AppServiceFwkInstaller
1078 */
1079 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, MoveSoToRealPath_0100, Function | SmallTest | Level1)
1080 {
1081     AppServiceFwkInstaller installer;
1082     auto ret1 = installer.MoveSoToRealPath("", "", "");
1083     EXPECT_EQ(ret1, ERR_OK);
1084 
1085     auto ret2 = installer.MoveSoToRealPath(STRING, STRING, "");
1086     EXPECT_EQ(ret2, ERR_OK);
1087 }
1088 
1089 /**
1090  * @tc.number: DeliveryProfileToCodeSign_0100
1091  * @tc.name: test function of DeliveryProfileToCodeSign
1092  * @tc.desc: calling DeliveryProfileToCodeSign of AppServiceFwkInstaller
1093 */
1094 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, DeliveryProfileToCodeSign_0100, Function | SmallTest | Level1)
1095 {
1096     AppServiceFwkInstaller installer;
1097     std::vector<Security::Verify::HapVerifyResult> hapVerifyResults;
1098     if (installer.dataMgr_ == nullptr) {
1099         installer.dataMgr_ = DelayedSingleton<BundleMgrService>::GetInstance()->GetDataMgr();
1100     }
1101     auto ret = installer.DeliveryProfileToCodeSign(hapVerifyResults);
1102     EXPECT_NE(ret, ERR_OK);
1103 }
1104 
1105 /**
1106  * @tc.number: CreateSignatureFileStream_0100
1107  * @tc.name: test function of CreateSignatureFileStream
1108  * @tc.desc: calling CreateSignatureFileStream of BundleStreamInstallerHostImpl
1109 */
1110 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CreateSignatureFileStream_0100, Function | SmallTest | Level1)
1111 {
1112     uint32_t installerId = 1;
1113     int32_t installedUid = 100;
1114     BundleStreamInstallerHostImpl impl(installerId, installedUid);
1115     auto ret1 = impl.CreateSignatureFileStream("", STRING);
1116     EXPECT_EQ(ret1, Constants::DEFAULT_STREAM_FD);
1117 
1118     auto ret2 = impl.CreateSignatureFileStream(STRING, "");
1119     EXPECT_EQ(ret2, Constants::DEFAULT_STREAM_FD);
1120 
1121     auto ret3 = impl.CreateSignatureFileStream("", "");
1122     EXPECT_EQ(ret3, Constants::DEFAULT_STREAM_FD);
1123 
1124     auto ret4 = impl.CreateSignatureFileStream(STRING, STRING);
1125     EXPECT_EQ(ret4, Constants::DEFAULT_STREAM_FD);
1126 }
1127 
1128 /**
1129  * @tc.number: GetAllBundleInfoByDeveloperId_0100
1130  * @tc.name: test function of GetAllBundleInfoByDeveloperId
1131  * @tc.desc: calling GetAllBundleInfoByDeveloperId of BundleDataMgr
1132 */
1133 HWTEST_F(BmsBundleAppServiceFwkInstallerTest, GetAllBundleInfoByDeveloperId_0100, Function | SmallTest | Level1)
1134 {
1135     auto dataMgr = GetBundleDataMgr();
1136     ASSERT_NE(dataMgr, nullptr);
1137     std::vector<BundleInfo> bundleInfos;
1138     auto ret1 = dataMgr->GetAllBundleInfoByDeveloperId(STRING, bundleInfos, Constants::INVALID_USERID);
1139     EXPECT_EQ(ret1, ERR_BUNDLE_MANAGER_INVALID_USER_ID);
1140 
1141     auto ret2 = dataMgr->GetAllBundleInfoByDeveloperId(STRING, bundleInfos, Constants::ANY_USERID);
1142     EXPECT_EQ(ret2, ERR_BUNDLE_MANAGER_INTERNAL_ERROR);
1143 
1144     std::map<std::string, InnerBundleInfo> map;
1145     InnerBundleInfo info;
1146     info.SetApplicationBundleType(BundleType::SHARED);
1147     map.try_emplace(BUNDLE_NAME, info);
1148     info.SetApplicationBundleType(BundleType::APP_SERVICE_FWK);
1149     map.try_emplace(BUNDLE_NAME_TEST, info);
1150     dataMgr->bundleInfos_ = map;
1151     auto ret3 = dataMgr->GetAllBundleInfoByDeveloperId(STRING, bundleInfos, Constants::ANY_USERID);
1152     EXPECT_NE(ret3, ERR_OK);
1153 }
1154 }
1155