1 /*
2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #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 #ifdef BUNDLE_FRAMEWORK_APP_CONTROL
30 #include "app_control_manager_host_impl.h"
31 #include "app_control_constants.h"
32 #endif
33 #ifdef APP_DOMAIN_VERIFY_ENABLED
34 #include "app_domain_verify_mgr_client.h"
35 #endif
36 #include "app_service_fwk/app_service_fwk_installer.h"
37 #include "bundle_info.h"
38 #include "bundle_installer_host.h"
39 #include "bundle_mgr_service.h"
40 #include "directory_ex.h"
41 #include "file_ex.h"
42 #include "install_param.h"
43 #include "installd/installd_service.h"
44 #include "installd_client.h"
45 #include "mock_status_receiver.h"
46 #include "scope_guard.h"
47 #include "shared/shared_bundle_installer.h"
48 #include "system_bundle_installer.h"
49 #include "utd_handler.h"
50 #include "want.h"
51
52 using namespace testing::ext;
53 using namespace std::chrono_literals;
54 using namespace OHOS::AppExecFwk;
55 using OHOS::DelayedSingleton;
56
57 namespace OHOS {
58 namespace {
59 const std::string SYSTEMFIEID_NAME = "com.query.test";
60 const std::string SYSTEMFIEID_BUNDLE = "system_module.hap";
61 const std::string SYSTEMFIEID_HAP_PATH = "/data/app/el1/bundle/public/com.query.test/module01.hap";
62 const std::string BUNDLE_NAME = "com.example.l3jsdemo";
63 const std::string MODULE_NAME_TEST = "moduleName";
64 const std::string RESOURCE_ROOT_PATH = "/data/test/resource/bms/install_bundle/";
65 const std::string TEST_CREATE_DIR_PATH = "/data/test/resource/bms/install_bundle/test_create_dir";
66 const std::string TEST_CREATE_FILE_PATH = "/data/test/resource/bms/install_bundle/test_create_dir/test.hap";
67 const std::string INVALID_PATH = "/install_bundle/";
68 const std::string RIGHT_BUNDLE = "right.hap";
69 const std::string TYPE_BUNDLE = "devicetype_error.hap";
70 const std::string INVALID_BUNDLE = "nonfile.hap";
71 const std::string WRONG_BUNDLE_NAME = "wrong_bundle_name.ha";
72 const std::string BUNDLE_DATA_DIR = "/data/app/el2/100/base/com.example.l3jsdemo";
73 const std::string BUNDLE_CODE_DIR = "/data/app/el1/bundle/public/com.example.l3jsdemo";
74 const int32_t USERID = 100;
75 const int32_t WAIT_TIME = 5; // init mocked bms
76 const std::string BUNDLE_BACKUP_TEST = "backup.hap";
77 const std::string BUNDLE_MODULEJSON_TEST = "moduleJsonTest.hap";
78 const std::string BUNDLE_PREVIEW_TEST = "preview.hap";
79 const std::string BUNDLE_THUMBNAIL_TEST = "thumbnail.hap";
80 const std::string BUNDLE_BACKUP_NAME = "com.example.backuptest";
81 const std::string BUNDLE_MODULEJSON_NAME = "com.test.modulejsontest";
82 const std::string BUNDLE_PREVIEW_NAME = "com.example.previewtest";
83 const std::string BUNDLE_THUMBNAIL_NAME = "com.example.thumbnailtest";
84 const std::string MODULE_NAME = "entry";
85 const std::string EXTENSION_ABILITY_NAME = "extensionAbility_A";
86 const std::string TEST_STRING = "test.string";
87 const std::string TEST_PACK_AGE = "entry";
88 const std::string NOEXIST = "noExist";
89 const std::string CURRENT_PATH = "/data/service/el2/100/hmdfs/account/data/test_max";
90 const size_t NUMBER_ONE = 1;
91 const int32_t INVAILD_CODE = -1;
92 const int32_t ZERO_CODE = 0;
93 const uint32_t COMPATIBLE_VERSION = 11;
94 const std::string LOG = "log";
95 const int32_t EDM_UID = 3057;
96 const uint32_t INSTALLER_ID = 1;
97 const uint32_t INDEX = 1;
98 #ifdef BUNDLE_FRAMEWORK_APP_CONTROL
99 const std::string EMPTY_STRING = "";
100 const std::string APPID_INPUT = "com.third.hiworld.example1";
101 const std::string APPID = "com.third.hiworld.example1_BNtg4JBClbl92Rgc3jm/"
102 "RfcAdrHXaM8F0QOiwVEhnV5ebE5jNIYnAx+weFRT3QTyUjRNdhmc2aAzWyi+5t5CoBM=";
103 const std::string NORMAL_BUNDLE_NAME = "bundleName";
104 const std::string FIRST_RIGHT_HAP = "first_right.hap";
105 #endif
106 const std::string BUNDLE_LIBRARY_PATH_DIR = "/data/app/el1/bundle/public/com.example.l3jsdemo/libs/arm";
107 const std::string BUNDLE_NAME_TEST = "bundleNameTest";
108 const std::string BUNDLE_NAME_TEST1 = "bundleNameTest1";
109 const std::string DEVICE_ID = "PHONE-001";
110 const std::string TEST_CPU_ABI = "arm64";
111 } // namespace
112
113 class BmsBundleInstallerTest : public testing::Test {
114 public:
115 BmsBundleInstallerTest();
116 ~BmsBundleInstallerTest();
117 static void SetUpTestCase();
118 static void TearDownTestCase();
119 void SetUp();
120 void TearDown();
121 bool InstallSystemBundle(const std::string &filePath) const;
122 bool OTAInstallSystemBundle(const std::string &filePath) const;
123 ErrCode InstallThirdPartyBundle(const std::string &filePath) const;
124 ErrCode UpdateThirdPartyBundle(const std::string &filePath) const;
125 ErrCode UnInstallBundle(const std::string &bundleName) const;
126 void CheckFileExist() const;
127 void CheckFileNonExist() const;
128 const std::shared_ptr<BundleDataMgr> GetBundleDataMgr() const;
129 const std::shared_ptr<BundleInstallerManager> GetBundleInstallerManager() const;
130 void StopInstalldService() const;
131 void StopBundleService();
132 void CreateInstallerManager();
133 void ClearBundleInfo();
134 void ClearDataMgr();
135 void ResetDataMgr();
136
137 private:
138 std::shared_ptr<BundleInstallerManager> manager_ = nullptr;
139 static std::shared_ptr<InstalldService> installdService_;
140 static std::shared_ptr<BundleMgrService> bundleMgrService_;
141 };
142
143 std::shared_ptr<BundleMgrService> BmsBundleInstallerTest::bundleMgrService_ =
144 DelayedSingleton<BundleMgrService>::GetInstance();
145
146 std::shared_ptr<InstalldService> BmsBundleInstallerTest::installdService_ =
147 std::make_shared<InstalldService>();
148
BmsBundleInstallerTest()149 BmsBundleInstallerTest::BmsBundleInstallerTest()
150 {}
151
~BmsBundleInstallerTest()152 BmsBundleInstallerTest::~BmsBundleInstallerTest()
153 {}
154
InstallSystemBundle(const std::string & filePath) const155 bool BmsBundleInstallerTest::InstallSystemBundle(const std::string &filePath) const
156 {
157 bundleMgrService_->GetDataMgr()->AddUserId(USERID);
158 auto installer = std::make_unique<SystemBundleInstaller>();
159 InstallParam installParam;
160 installParam.userId = USERID;
161 installParam.isPreInstallApp = true;
162 setuid(Constants::FOUNDATION_UID);
163 installParam.SetKillProcess(false);
164 setuid(Constants::ROOT_UID);
165 installParam.needSendEvent = false;
166 installParam.needSavePreInstallInfo = true;
167 installParam.copyHapToInstallPath = false;
168 return installer->InstallSystemBundle(
169 filePath, installParam, Constants::AppType::SYSTEM_APP) == ERR_OK;
170 }
171
OTAInstallSystemBundle(const std::string & filePath) const172 bool BmsBundleInstallerTest::OTAInstallSystemBundle(const std::string &filePath) const
173 {
174 bundleMgrService_->GetDataMgr()->AddUserId(USERID);
175 auto installer = std::make_unique<SystemBundleInstaller>();
176 std::vector<std::string> filePaths;
177 filePaths.push_back(filePath);
178 InstallParam installParam;
179 installParam.userId = USERID;
180 installParam.isPreInstallApp = true;
181 setuid(Constants::FOUNDATION_UID);
182 installParam.SetKillProcess(false);
183 setuid(Constants::ROOT_UID);
184 installParam.needSendEvent = false;
185 installParam.needSavePreInstallInfo = true;
186 installParam.copyHapToInstallPath = false;
187 return installer->OTAInstallSystemBundle(
188 filePaths, installParam, Constants::AppType::SYSTEM_APP) == ERR_OK;
189 }
190
InstallThirdPartyBundle(const std::string & filePath) const191 ErrCode BmsBundleInstallerTest::InstallThirdPartyBundle(const std::string &filePath) const
192 {
193 bundleMgrService_->GetDataMgr()->AddUserId(USERID);
194 auto installer = bundleMgrService_->GetBundleInstaller();
195 if (!installer) {
196 EXPECT_FALSE(true) << "the installer is nullptr";
197 return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR;
198 }
199 sptr<MockStatusReceiver> receiver = new (std::nothrow) MockStatusReceiver();
200 if (!receiver) {
201 EXPECT_FALSE(true) << "the receiver is nullptr";
202 return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR;
203 }
204 InstallParam installParam;
205 installParam.userId = USERID;
206 installParam.installFlag = InstallFlag::NORMAL;
207 installParam.withCopyHaps = true;
208 bool result = installer->Install(filePath, installParam, receiver);
209 EXPECT_TRUE(result);
210 return receiver->GetResultCode();
211 }
212
UpdateThirdPartyBundle(const std::string & filePath) const213 ErrCode BmsBundleInstallerTest::UpdateThirdPartyBundle(const std::string &filePath) const
214 {
215 bundleMgrService_->GetDataMgr()->AddUserId(USERID);
216 auto installer = bundleMgrService_->GetBundleInstaller();
217 if (!installer) {
218 EXPECT_FALSE(true) << "the installer is nullptr";
219 return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR;
220 }
221 sptr<MockStatusReceiver> receiver = new (std::nothrow) MockStatusReceiver();
222 if (!receiver) {
223 EXPECT_FALSE(true) << "the receiver is nullptr";
224 return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR;
225 }
226 InstallParam installParam;
227 installParam.userId = USERID;
228 installParam.installFlag = InstallFlag::REPLACE_EXISTING;
229 installParam.withCopyHaps = true;
230 bool result = installer->Install(filePath, installParam, receiver);
231 EXPECT_TRUE(result);
232 return receiver->GetResultCode();
233 }
234
UnInstallBundle(const std::string & bundleName) const235 ErrCode BmsBundleInstallerTest::UnInstallBundle(const std::string &bundleName) const
236 {
237 bundleMgrService_->GetDataMgr()->AddUserId(USERID);
238 auto installer = bundleMgrService_->GetBundleInstaller();
239 if (!installer) {
240 EXPECT_FALSE(true) << "the installer is nullptr";
241 return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR;
242 }
243 sptr<MockStatusReceiver> receiver = new (std::nothrow) MockStatusReceiver();
244 if (!receiver) {
245 EXPECT_FALSE(true) << "the receiver is nullptr";
246 return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR;
247 }
248 InstallParam installParam;
249 installParam.userId = USERID;
250 installParam.installFlag = InstallFlag::NORMAL;
251 bool result = installer->Uninstall(bundleName, installParam, receiver);
252 EXPECT_TRUE(result);
253 return receiver->GetResultCode();
254 }
255
SetUpTestCase()256 void BmsBundleInstallerTest::SetUpTestCase()
257 {
258 }
259
TearDownTestCase()260 void BmsBundleInstallerTest::TearDownTestCase()
261 {
262 bundleMgrService_->OnStop();
263 }
264
SetUp()265 void BmsBundleInstallerTest::SetUp()
266 {
267 if (!installdService_->IsServiceReady()) {
268 installdService_->Start();
269 }
270 if (!bundleMgrService_->IsServiceReady()) {
271 bundleMgrService_->OnStart();
272 bundleMgrService_->GetDataMgr()->AddUserId(USERID);
273 std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME));
274 }
275 }
276
TearDown()277 void BmsBundleInstallerTest::TearDown()
278 {
279 OHOS::ForceRemoveDirectory(BUNDLE_DATA_DIR);
280 OHOS::ForceRemoveDirectory(BUNDLE_CODE_DIR);
281 OHOS::ForceRemoveDirectory(BUNDLE_LIBRARY_PATH_DIR);
282 }
283
CheckFileExist() const284 void BmsBundleInstallerTest::CheckFileExist() const
285 {
286 int bundleCodeExist = access(BUNDLE_CODE_DIR.c_str(), F_OK);
287 EXPECT_EQ(bundleCodeExist, 0) << "the bundle code dir does not exists: " << BUNDLE_CODE_DIR;
288
289 int bundleDataExist = access(BUNDLE_DATA_DIR.c_str(), F_OK);
290 EXPECT_EQ(bundleDataExist, 0) << "the bundle data dir does not exists: " << BUNDLE_DATA_DIR;
291 }
292
CheckFileNonExist() const293 void BmsBundleInstallerTest::CheckFileNonExist() const
294 {
295 int bundleCodeExist = access(BUNDLE_CODE_DIR.c_str(), F_OK);
296 EXPECT_NE(bundleCodeExist, 0) << "the bundle code dir exists: " << BUNDLE_CODE_DIR;
297
298 int bundleDataExist = access(BUNDLE_DATA_DIR.c_str(), F_OK);
299 EXPECT_NE(bundleDataExist, 0) << "the bundle data dir exists: " << BUNDLE_DATA_DIR;
300 }
301
GetBundleDataMgr() const302 const std::shared_ptr<BundleDataMgr> BmsBundleInstallerTest::GetBundleDataMgr() const
303 {
304 return bundleMgrService_->GetDataMgr();
305 }
306
GetBundleInstallerManager() const307 const std::shared_ptr<BundleInstallerManager> BmsBundleInstallerTest::GetBundleInstallerManager() const
308 {
309 return manager_;
310 }
311
ClearDataMgr()312 void BmsBundleInstallerTest::ClearDataMgr()
313 {
314 bundleMgrService_->dataMgr_ = nullptr;
315 }
316
ResetDataMgr()317 void BmsBundleInstallerTest::ResetDataMgr()
318 {
319 bundleMgrService_->dataMgr_ = std::make_shared<BundleDataMgr>();
320 EXPECT_NE(bundleMgrService_->dataMgr_, nullptr);
321 }
322
StopInstalldService() const323 void BmsBundleInstallerTest::StopInstalldService() const
324 {
325 if (installdService_->IsServiceReady()) {
326 installdService_->Stop();
327 InstalldClient::GetInstance()->ResetInstalldProxy();
328 }
329 }
330
StopBundleService()331 void BmsBundleInstallerTest::StopBundleService()
332 {
333 if (bundleMgrService_->IsServiceReady()) {
334 bundleMgrService_->OnStop();
335 bundleMgrService_.reset();
336 }
337 }
338
CreateInstallerManager()339 void BmsBundleInstallerTest::CreateInstallerManager()
340 {
341 if (manager_ != nullptr) {
342 return;
343 }
344 manager_ = std::make_shared<BundleInstallerManager>();
345 EXPECT_NE(nullptr, manager_);
346 }
347
ClearBundleInfo()348 void BmsBundleInstallerTest::ClearBundleInfo()
349 {
350 if (bundleMgrService_ == nullptr) {
351 return;
352 }
353 auto dataMgt = bundleMgrService_->GetDataMgr();
354 if (dataMgt == nullptr) {
355 return;
356 }
357 auto dataStorage = dataMgt->GetDataStorage();
358 if (dataStorage == nullptr) {
359 return;
360 }
361
362 // clear innerBundleInfo from data manager
363 dataMgt->UpdateBundleInstallState(BUNDLE_NAME, InstallState::UNINSTALL_START);
364 dataMgt->UpdateBundleInstallState(BUNDLE_NAME, InstallState::UNINSTALL_SUCCESS);
365
366 InnerBundleInfo innerBundleInfo;
367 ApplicationInfo applicationInfo;
368 applicationInfo.bundleName = BUNDLE_NAME;
369 innerBundleInfo.SetBaseApplicationInfo(applicationInfo);
370 // clear innerBundleInfo from data storage
371 bool result = dataStorage->DeleteStorageBundleInfo(innerBundleInfo);
372 EXPECT_TRUE(result) << "the bundle info in db clear fail: " << BUNDLE_NAME;
373 }
374
375
376 /**
377 * @tc.number: SetEncryptionDirPolicy_0100
378 * @tc.name: test SetEncryptionDirPolicy
379 * @tc.desc: test SetEncryptionDirPolicy of BaseBundleInstaller
380 */
381 HWTEST_F(BmsBundleInstallerTest, SetEncryptionDirPolicy_0100, Function | SmallTest | Level0)
382 {
383 BaseBundleInstaller installer;
384 InnerBundleInfo info;
385 bool ret = installer.SetEncryptionDirPolicy(info);
386 EXPECT_FALSE(ret);
387 }
388
389 /**
390 * @tc.number: PrepareSkillUri_0100
391 * @tc.name: test PrepareSkillUri
392 * @tc.desc: test PrepareSkillUri of BaseBundleInstaller
393 */
394 HWTEST_F(BmsBundleInstallerTest, PrepareSkillUri_0100, Function | SmallTest | Level0)
395 {
396 BaseBundleInstaller installer;
397 std::vector<Skill> skills;
398 Skill skill;
399 OHOS::AppExecFwk::SkillUri uri;
400 uri.scheme = "https";
401 uri.host = "host";
402 uri.port = "port";
403 uri.path = "path";
404 uri.pathStartWith = "pathStartWith";
405 uri.pathRegex = "pathRegex";
406 uri.type = "type";
407 skill.domainVerify = true;
408 skill.uris.push_back(uri);
409 skills.push_back(skill);
410 std::vector<AppDomainVerify::SkillUri> skillUris;
411 installer.PrepareSkillUri(skills, skillUris);
412 EXPECT_EQ(skills.at(0).uris.size(), skillUris.size());
413 }
414
415 /**
416 * @tc.number: SystemInstall_0100
417 * @tc.name: test the right system bundle file can be installed
418 * @tc.desc: 1.the system bundle file exists
419 * 2.the system bundle can be installed successfully and can get the bundle info
420 */
421 HWTEST_F(BmsBundleInstallerTest, SystemInstall_0100, Function | SmallTest | Level0)
422 {
423 std::string bundleFile = RESOURCE_ROOT_PATH + RIGHT_BUNDLE;
424 bool result = InstallSystemBundle(bundleFile);
425 EXPECT_TRUE(result) << "the bundle file install failed: " << bundleFile;
426 CheckFileExist();
427 ClearBundleInfo();
428 }
429
430 /**
431 * @tc.number: SystemInstall_0200
432 * @tc.name: test the wrong system bundle file can't be installed
433 * @tc.desc: 1.the system bundle file don't exists
434 * 2.the system bundle can't be installed and the result is fail
435 */
436 HWTEST_F(BmsBundleInstallerTest, SystemInstall_0200, Function | SmallTest | Level0)
437 {
438 std::string nonExistFile = RESOURCE_ROOT_PATH + INVALID_BUNDLE;
439 bool result = InstallSystemBundle(nonExistFile);
440 EXPECT_FALSE(result) << "the bundle file install success: " << nonExistFile;
441 CheckFileNonExist();
442 }
443
444 /**
445 * @tc.number: SystemInstall_0300
446 * @tc.name: test the empty path can't be installed
447 * @tc.desc: 1.the system bundle file path is empty
448 * 2.the system bundle can't be installed and the result is fail
449 */
450 HWTEST_F(BmsBundleInstallerTest, SystemInstall_0300, Function | SmallTest | Level0)
451 {
452 bool result = InstallSystemBundle("");
453 EXPECT_FALSE(result) << "the empty path install success";
454 CheckFileNonExist();
455 }
456
457 /**
458 * @tc.number: SystemInstall_0400
459 * @tc.name: test the illegal bundleName file can't be installed
460 * @tc.desc: 1.the system bundle name is illegal
461 * 2.the system bundle can't be installed and the result is fail
462 */
463 HWTEST_F(BmsBundleInstallerTest, SystemInstall_0400, Function | SmallTest | Level0)
464 {
465 std::string wrongBundleName = RESOURCE_ROOT_PATH + WRONG_BUNDLE_NAME;
466 bool result = InstallSystemBundle(wrongBundleName);
467 EXPECT_FALSE(result) << "the wrong bundle file install success";
468 CheckFileNonExist();
469 }
470
471 /**
472 * @tc.number: SystemInstall_0500
473 * @tc.name: test the bundle file with invalid path will cause the result of install failure
474 * @tc.desc: 1.the bundle file has invalid path
475 * 2.the system bundle can't be installed and the result is fail
476 */
477 HWTEST_F(BmsBundleInstallerTest, SystemInstall_0500, Function | SmallTest | Level0)
478 {
479 std::string bundleFile = INVALID_PATH + RIGHT_BUNDLE;
480 bool result = InstallSystemBundle(bundleFile);
481 EXPECT_FALSE(result) << "the invalid path install success";
482 CheckFileNonExist();
483 }
484
485 /**
486 * @tc.number: SystemInstall_0600
487 * @tc.name: test the install will fail when installd service has error
488 * @tc.desc: 1.the installd service has error
489 * 2.the install result is fail
490 */
491 HWTEST_F(BmsBundleInstallerTest, SystemInstall_0600, Function | SmallTest | Level0)
492 {
493 StopInstalldService();
494 std::string bundleFile = RESOURCE_ROOT_PATH + RIGHT_BUNDLE;
495 bool result = InstallSystemBundle(bundleFile);
496 EXPECT_FALSE(result);
497 }
498
499 /**
500 * @tc.number: ThirdPartyInstall_0100
501 * @tc.name: test the install will fail when installd service has error
502 * @tc.desc: 1.the installd service has error
503 * 2.the install result is fail
504 */
505 HWTEST_F(BmsBundleInstallerTest, ThirdPartyInstall_0100, Function | SmallTest | Level0)
506 {
507 StopInstalldService();
508 std::string bundleFile = RESOURCE_ROOT_PATH + TYPE_BUNDLE;
509 auto result = InstallThirdPartyBundle(bundleFile);
510 EXPECT_EQ(result, ERR_APPEXECFWK_INSTALL_DEVICE_TYPE_NOT_SUPPORTED);
511 }
512
513 /**
514 * @tc.number: SystemUpdateData_0100
515 * @tc.name: test the right bundle file can be installed and update its info to bms
516 * @tc.desc: 1.the system bundle is available
517 * 2.the right bundle can be installed and update its info to bms
518 */
519 HWTEST_F(BmsBundleInstallerTest, SystemUpdateData_0100, Function | SmallTest | Level0)
520 {
521 ApplicationInfo info;
522 auto dataMgr = GetBundleDataMgr();
523 EXPECT_NE(dataMgr, nullptr);
524 bool result = dataMgr->GetApplicationInfo(BUNDLE_NAME, ApplicationFlag::GET_BASIC_APPLICATION_INFO, USERID, info);
525 EXPECT_FALSE(result);
526 std::string bundleFile = RESOURCE_ROOT_PATH + RIGHT_BUNDLE;
527 bool installResult = InstallSystemBundle(bundleFile);
528 EXPECT_TRUE(installResult);
529 result = dataMgr->GetApplicationInfo(BUNDLE_NAME, ApplicationFlag::GET_BASIC_APPLICATION_INFO, USERID, info);
530 EXPECT_TRUE(result);
531 EXPECT_EQ(info.name, BUNDLE_NAME);
532 ClearBundleInfo();
533 }
534
535 /**
536 * @tc.number: SystemUpdateData_0200
537 * @tc.name: test the wrong bundle file can't be installed and its info will not updated to bms
538 * @tc.desc: 1.the system bundle is wrong
539 * 2.the wrong bundle can't be installed and its info will not updated to bms
540 */
541 HWTEST_F(BmsBundleInstallerTest, SystemUpdateData_0200, Function | SmallTest | Level0)
542 {
543 ApplicationInfo info;
544 auto dataMgr = GetBundleDataMgr();
545 EXPECT_NE(dataMgr, nullptr);
546 bool result = dataMgr->GetApplicationInfo(BUNDLE_NAME, ApplicationFlag::GET_BASIC_APPLICATION_INFO, USERID, info);
547 EXPECT_FALSE(result);
548 std::string wrongBundleName = RESOURCE_ROOT_PATH + WRONG_BUNDLE_NAME;
549 bool installResult = InstallSystemBundle(wrongBundleName);
550 EXPECT_FALSE(installResult);
551 result = dataMgr->GetApplicationInfo(BUNDLE_NAME, ApplicationFlag::GET_BASIC_APPLICATION_INFO, USERID, info);
552 EXPECT_FALSE(result);
553 }
554
555 /**
556 * @tc.number: SystemUpdateData_0300
557 * @tc.name: test the already installed bundle can't be reinstalled and update its info to bms
558 * @tc.desc: 1.the bundle is already installed
559 * 2.the already installed bundle can't be reinstalled and update its info to bms
560 */
561 HWTEST_F(BmsBundleInstallerTest, SystemUpdateData_0300, Function | SmallTest | Level0)
562 {
563 auto dataMgr = GetBundleDataMgr();
564 EXPECT_NE(dataMgr, nullptr);
565 // prepare already install information.
566 std::string bundleFile = RESOURCE_ROOT_PATH + RIGHT_BUNDLE;
567 bool firstInstall = InstallSystemBundle(bundleFile);
568 EXPECT_TRUE(firstInstall);
569 ApplicationInfo info;
570 auto result = dataMgr->GetApplicationInfo(BUNDLE_NAME, ApplicationFlag::GET_BASIC_APPLICATION_INFO, USERID, info);
571 EXPECT_TRUE(result);
572 EXPECT_EQ(info.name, BUNDLE_NAME);
573 bool secondInstall = InstallSystemBundle(bundleFile);
574 EXPECT_FALSE(secondInstall);
575 ClearBundleInfo();
576 }
577
578 /**
579 * @tc.number: SystemUpdateData_0400
580 * @tc.name: test the already installing bundle can't be reinstalled and update its info to bms
581 * @tc.desc: 1.the bundle is already installing.
582 * 2.the already installing bundle can't be reinstalled and update its info to bms
583 */
584 HWTEST_F(BmsBundleInstallerTest, SystemUpdateData_0400, Function | SmallTest | Level0)
585 {
586 // prepare already install information.
587 auto dataMgr = GetBundleDataMgr();
588 EXPECT_NE(dataMgr, nullptr);
589 dataMgr->UpdateBundleInstallState(BUNDLE_NAME, InstallState::INSTALL_START);
590 // begin to reinstall package
591 std::string bundleFile = RESOURCE_ROOT_PATH + RIGHT_BUNDLE;
592 bool installResult = InstallSystemBundle(bundleFile);
593 EXPECT_FALSE(installResult);
594 // reset the install state
595 dataMgr->UpdateBundleInstallState(BUNDLE_NAME, InstallState::INSTALL_FAIL);
596 ClearBundleInfo();
597 }
598
599 /**
600 * @tc.number: CreateInstallTask_0100
601 * @tc.name: test the installer manager can create task
602 * @tc.desc: 1.the bundle file exists
603 * 2.the bundle can be installed successfully
604 */
605 HWTEST_F(BmsBundleInstallerTest, CreateInstallTask_0100, Function | SmallTest | Level0)
606 {
607 CreateInstallerManager();
608 sptr<MockStatusReceiver> receiver = new (std::nothrow) MockStatusReceiver();
609 EXPECT_NE(receiver, nullptr);
610 InstallParam installParam;
611 installParam.userId = USERID;
612 installParam.withCopyHaps = true;
613 std::string bundleFile = RESOURCE_ROOT_PATH + RIGHT_BUNDLE;
614 GetBundleInstallerManager()->CreateInstallTask(bundleFile, installParam, receiver);
615 ErrCode result = receiver->GetResultCode();
616 EXPECT_EQ(ERR_OK, result);
617 ClearBundleInfo();
618 }
619
620 /**
621 * @tc.number: CreateInstallTask_0200
622 * @tc.name: test the installer manager can not create task while bundle invalid
623 * @tc.desc: 1.the invalid bundle file exists
624 * 2.install the invalid bundle failed
625 */
626 HWTEST_F(BmsBundleInstallerTest, CreateInstallTask_0200, Function | SmallTest | Level0)
627 {
628 CreateInstallerManager();
629 sptr<MockStatusReceiver> receiver = new (std::nothrow) MockStatusReceiver();
630 EXPECT_NE(receiver, nullptr);
631 InstallParam installParam;
632 installParam.userId = USERID;
633 installParam.withCopyHaps = true;
634 std::string bundleFile = RESOURCE_ROOT_PATH + INVALID_BUNDLE;
635 GetBundleInstallerManager()->CreateInstallTask(bundleFile, installParam, receiver);
636 ErrCode result = receiver->GetResultCode();
637 EXPECT_NE(ERR_OK, result);
638 }
639
640 /**
641 * @tc.number: CreateUninstallTask_0200
642 * @tc.name: test the installer manager can not create task while bundle invalid
643 * @tc.desc: 1.the invalid bundle file exists
644 * 2.uninstall the bundle failed
645 */
646 HWTEST_F(BmsBundleInstallerTest, CreateUninstallTask_0200, Function | SmallTest | Level0)
647 {
648 CreateInstallerManager();
649 sptr<MockStatusReceiver> receiver = new (std::nothrow) MockStatusReceiver();
650 EXPECT_NE(receiver, nullptr);
651 InstallParam installParam;
652 installParam.userId = USERID;
653 std::string bundleFile = RESOURCE_ROOT_PATH + INVALID_BUNDLE;
654 GetBundleInstallerManager()->CreateUninstallTask(bundleFile, installParam, receiver);
655 ErrCode result = receiver->GetResultCode();
656 EXPECT_NE(ERR_OK, result);
657 }
658
659 /**
660 * @tc.number: ParseModuleJson_0100
661 * @tc.name: parse module json
662 * @tc.desc: 1.the bundle is already installing.
663 * 2.You can query the related moudle.json information
664 * 3.The system field tested is the configured field
665 */
666 HWTEST_F(BmsBundleInstallerTest, ParseModuleJson_0100, Function | SmallTest | Level0)
667 {
668 ApplicationInfo info;
669 auto dataMgr = GetBundleDataMgr();
670 EXPECT_NE(dataMgr, nullptr);
671 std::string bundleFile = RESOURCE_ROOT_PATH + SYSTEMFIEID_BUNDLE;
672 ErrCode installResult = InstallThirdPartyBundle(bundleFile);
673 EXPECT_EQ(installResult, ERR_OK);
674 bool result =
675 dataMgr->GetApplicationInfo(SYSTEMFIEID_NAME, ApplicationFlag::GET_BASIC_APPLICATION_INFO, USERID, info);
676 EXPECT_TRUE(result);
677 if (result) {
678 EXPECT_EQ(info.name, "com.query.test");
679 EXPECT_EQ(info.description, "$string:description_application");
680 EXPECT_EQ(info.descriptionId, 16777217);
681 EXPECT_EQ(info.label, "$string:app_name");
682 EXPECT_EQ(info.labelId, 16777216);
683 EXPECT_EQ(info.iconPath, "$media:app_icon");
684 EXPECT_EQ(info.iconId, 16777229);
685 EXPECT_EQ(static_cast<uint32_t>(info.versionCode), 1);
686 EXPECT_EQ(info.versionName, "1.0");
687 EXPECT_EQ(info.minCompatibleVersionCode, 1);
688 EXPECT_EQ(info.apiCompatibleVersion, 8);
689 EXPECT_EQ(info.apiTargetVersion, 8);
690 EXPECT_EQ(info.gwpAsanEnabled, false);
691 EXPECT_EQ(info.tsanEnabled, false);
692 EXPECT_EQ(info.hwasanEnabled, false);
693 AbilityInfo abilityInfo;
694 abilityInfo.bundleName = SYSTEMFIEID_NAME;
695 abilityInfo.package = "module01";
696 HapModuleInfo hapModuleInfo;
697 bool ret = dataMgr->GetHapModuleInfo(abilityInfo, hapModuleInfo);
698 EXPECT_TRUE(ret);
699 EXPECT_EQ(hapModuleInfo.name, "module01");
700 EXPECT_EQ(hapModuleInfo.description, "$string:description_application");
701 EXPECT_EQ(hapModuleInfo.mainAbility, "MainAbility");
702 EXPECT_EQ(hapModuleInfo.process, "bba");
703 EXPECT_EQ(hapModuleInfo.virtualMachine, "");
704 EXPECT_EQ(hapModuleInfo.uiSyntax, "hml");
705 EXPECT_EQ(hapModuleInfo.pages, "$profile:page_config");
706 EXPECT_EQ(hapModuleInfo.deliveryWithInstall, true);
707 EXPECT_EQ(hapModuleInfo.installationFree, false);
708 EXPECT_EQ(hapModuleInfo.srcEntrance, "./MyAbilityStage.ts");
709 EXPECT_EQ(hapModuleInfo.isolationMode, IsolationMode::NONISOLATION_FIRST);
710
711 auto abilityInfos = hapModuleInfo.abilityInfos.front();
712 EXPECT_EQ(abilityInfos.name, "MainAbility");
713 EXPECT_EQ(abilityInfos.srcEntrance, "./login/MyLoginAbility.ts");
714 EXPECT_EQ(abilityInfos.description, "$string:description_main_ability");
715 EXPECT_EQ(abilityInfos.descriptionId, 16777219);
716 EXPECT_EQ(abilityInfos.isolationProcess, true);
717 EXPECT_EQ(hapModuleInfo.label, "Login");
718
719 auto metadata = abilityInfos.metadata.front();
720 EXPECT_EQ(metadata.name, "a01");
721 EXPECT_EQ(metadata.value, "v01");
722 EXPECT_EQ(metadata.resource, "hello");
723
724 auto extensionInfos = hapModuleInfo.extensionInfos.front();
725 EXPECT_EQ(extensionInfos.name, "FormName");
726 EXPECT_EQ(extensionInfos.srcEntrance, "./form/MyForm.ts");
727 EXPECT_EQ(extensionInfos.description, "$string:form_description");
728 EXPECT_EQ(extensionInfos.descriptionId, 16777221);
729 EXPECT_EQ(extensionInfos.visible, true);
730 EXPECT_EQ(extensionInfos.icon, "$media:icon");
731 EXPECT_EQ(extensionInfos.iconId, 16777229);
732 EXPECT_EQ(extensionInfos.label, "$string:extension_name");
733 EXPECT_EQ(extensionInfos.labelId, 16777220);
734
735 EXPECT_EQ(hapModuleInfo.packageName, "packageNameTest");
736 }
737 UnInstallBundle(SYSTEMFIEID_NAME);
738 }
739
740 /**
741 * @tc.number: BackupExtension_0100
742 * @tc.name: test the backup type
743 * @tc.desc: 1.install the hap
744 * 2.query extensionAbilityInfos
745 */
746 HWTEST_F(BmsBundleInstallerTest, BackupExtension_0100, Function | SmallTest | Level0)
747 {
748 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
749 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
750 EXPECT_EQ(installResult, ERR_OK);
751
752 auto dataMgr = GetBundleDataMgr();
753 EXPECT_NE(dataMgr, nullptr);
754 AAFwk::Want want;
755 want.SetAction("action.system.home");
756 want.AddEntity("entity.system.home");
757 want.SetElementName("", BUNDLE_BACKUP_NAME, "", "");
758 std::vector<ExtensionAbilityInfo> infos;
759 bool result = dataMgr->QueryExtensionAbilityInfos(want, 0, USERID, infos);
760 EXPECT_TRUE(result);
761 EXPECT_EQ(infos.size(), NUMBER_ONE);
762 if (infos.size() > 0) {
763 EXPECT_EQ(infos[0].bundleName, BUNDLE_BACKUP_NAME);
764 EXPECT_EQ(infos[0].type, ExtensionAbilityType::BACKUP);
765 }
766 UnInstallBundle(BUNDLE_BACKUP_NAME);
767 }
768
769 /**
770 * @tc.name: PREVIEWExtension_0100
771 * @tc.desc: 1.install the hap
772 * 2.query extensionAbilityInfos
773 * @tc.type: FUNC
774 * @tc.require: issueI5MZ33
775 */
776 HWTEST_F(BmsBundleInstallerTest, PREVIEWExtension_0100, Function | SmallTest | Level0)
777 {
778 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_PREVIEW_TEST;
779 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
780 EXPECT_EQ(installResult, ERR_OK);
781
782 auto dataMgr = GetBundleDataMgr();
783 EXPECT_NE(dataMgr, nullptr);
784 AAFwk::Want want;
785 want.SetAction("action.system.home");
786 want.AddEntity("entity.system.home");
787 want.SetElementName("", BUNDLE_PREVIEW_NAME, "", "");
788 std::vector<ExtensionAbilityInfo> infos;
789 bool result = dataMgr->QueryExtensionAbilityInfos(want, 0, USERID, infos);
790 EXPECT_TRUE(result);
791 EXPECT_EQ(infos.size(), NUMBER_ONE);
792 if (infos.size() > 0) {
793 EXPECT_EQ(infos[0].bundleName, BUNDLE_PREVIEW_NAME);
794 EXPECT_EQ(infos[0].type, ExtensionAbilityType::PREVIEW);
795 }
796 UnInstallBundle(BUNDLE_PREVIEW_NAME);
797 }
798
799 /**
800 * @tc.name: THUMBNAILExtension_0100
801 * @tc.desc: 1.install the hap
802 * 2.query extensionAbilityInfos
803 * @tc.type: FUNC
804 * @tc.require: issueI5MZ33
805 */
806 HWTEST_F(BmsBundleInstallerTest, THUMBNAILExtension_0100, Function | SmallTest | Level0)
807 {
808 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_THUMBNAIL_TEST;
809 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
810 EXPECT_EQ(installResult, ERR_OK);
811
812 auto dataMgr = GetBundleDataMgr();
813 EXPECT_NE(dataMgr, nullptr);
814 AAFwk::Want want;
815 want.SetAction("action.system.home");
816 want.AddEntity("entity.system.home");
817 want.SetElementName("", BUNDLE_THUMBNAIL_NAME, "", "");
818 std::vector<ExtensionAbilityInfo> infos;
819 bool result = dataMgr->QueryExtensionAbilityInfos(want, 0, USERID, infos);
820 EXPECT_TRUE(result);
821 EXPECT_EQ(infos.size(), NUMBER_ONE);
822 if (infos.size() > 0) {
823 EXPECT_EQ(infos[0].bundleName, BUNDLE_THUMBNAIL_NAME);
824 EXPECT_EQ(infos[0].type, ExtensionAbilityType::THUMBNAIL);
825 }
826 UnInstallBundle(BUNDLE_THUMBNAIL_NAME);
827 }
828
829 /**
830 * @tc.number: QueryExtensionAbilityInfos_0100
831 * @tc.name: test the backup type
832 * @tc.desc: 1.install the hap
833 * 2.query extensionAbilityInfos
834 */
835 HWTEST_F(BmsBundleInstallerTest, QueryExtensionAbilityInfos_0100, Function | SmallTest | Level0)
836 {
837 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
838 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
839 EXPECT_EQ(installResult, ERR_OK);
840
841 auto dataMgr = GetBundleDataMgr();
842 EXPECT_NE(dataMgr, nullptr);
843 AAFwk::Want want;
844 want.SetAction("action.system.home");
845 want.AddEntity("entity.system.home");
846 want.SetElementName("", BUNDLE_BACKUP_NAME, "", MODULE_NAME);
847 std::vector<ExtensionAbilityInfo> infos;
848 bool result = dataMgr->QueryExtensionAbilityInfos(want, 0, USERID, infos);
849 EXPECT_TRUE(result);
850 EXPECT_EQ(infos.size(), NUMBER_ONE);
851 if (infos.size() > 0) {
852 EXPECT_EQ(infos[0].bundleName, BUNDLE_BACKUP_NAME);
853 EXPECT_EQ(infos[0].moduleName, MODULE_NAME);
854 EXPECT_EQ(infos[0].type, ExtensionAbilityType::BACKUP);
855 }
856 UnInstallBundle(BUNDLE_BACKUP_NAME);
857 }
858
859 /**
860 * @tc.number: QueryExtensionAbilityInfos_0200
861 * @tc.name: test the backup type
862 * @tc.desc: 1.install the hap
863 * 2.query extensionAbilityInfos
864 */
865 HWTEST_F(BmsBundleInstallerTest, QueryExtensionAbilityInfos_0200, Function | SmallTest | Level0)
866 {
867 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
868 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
869 EXPECT_EQ(installResult, ERR_OK);
870
871 auto dataMgr = GetBundleDataMgr();
872 EXPECT_NE(dataMgr, nullptr);
873 AAFwk::Want want;
874 want.SetElementName("", BUNDLE_BACKUP_NAME, "", MODULE_NAME);
875 std::vector<ExtensionAbilityInfo> infos;
876 bool result = dataMgr->QueryExtensionAbilityInfos(want, 0, USERID, infos);
877 EXPECT_FALSE(result);
878 UnInstallBundle(BUNDLE_BACKUP_NAME);
879 }
880
881 /**
882 * @tc.number: QueryExtensionAbilityInfos_0300
883 * @tc.name: test the backup type
884 * @tc.desc: 1.install the hap
885 * 2.query extensionAbilityInfos
886 */
887 HWTEST_F(BmsBundleInstallerTest, QueryExtensionAbilityInfos_0300, Function | SmallTest | Level0)
888 {
889 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
890 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
891 EXPECT_EQ(installResult, ERR_OK);
892
893 auto dataMgr = GetBundleDataMgr();
894 EXPECT_NE(dataMgr, nullptr);
895 AAFwk::Want want;
896 want.SetElementName("", BUNDLE_BACKUP_NAME, EXTENSION_ABILITY_NAME, "");
897 std::vector<ExtensionAbilityInfo> infos;
898 bool result = dataMgr->QueryExtensionAbilityInfos(want, 0, USERID, infos);
899 EXPECT_TRUE(result);
900 EXPECT_EQ(infos.size(), NUMBER_ONE);
901 if (infos.size() > 0) {
902 EXPECT_EQ(infos[0].bundleName, BUNDLE_BACKUP_NAME);
903 EXPECT_EQ(infos[0].name, EXTENSION_ABILITY_NAME);
904 EXPECT_EQ(infos[0].type, ExtensionAbilityType::BACKUP);
905 }
906 UnInstallBundle(BUNDLE_BACKUP_NAME);
907 }
908
909 /**
910 * @tc.number: QueryExtensionAbilityInfos_0400
911 * @tc.name: test the backup type
912 * @tc.desc: 1.install the hap
913 * 2.query extensionAbilityInfos
914 */
915 HWTEST_F(BmsBundleInstallerTest, QueryExtensionAbilityInfos_0400, Function | SmallTest | Level0)
916 {
917 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
918 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
919 EXPECT_EQ(installResult, ERR_OK);
920
921 auto dataMgr = GetBundleDataMgr();
922 EXPECT_NE(dataMgr, nullptr);
923 AAFwk::Want want;
924 want.SetElementName("", BUNDLE_BACKUP_NAME, EXTENSION_ABILITY_NAME, MODULE_NAME);
925 std::vector<ExtensionAbilityInfo> infos;
926 bool result = dataMgr->QueryExtensionAbilityInfos(want, 0, USERID, infos);
927 EXPECT_TRUE(result);
928 EXPECT_EQ(infos.size(), NUMBER_ONE);
929 if (infos.size() > 0) {
930 EXPECT_EQ(infos[0].bundleName, BUNDLE_BACKUP_NAME);
931 EXPECT_EQ(infos[0].moduleName, MODULE_NAME);
932 EXPECT_EQ(infos[0].name, EXTENSION_ABILITY_NAME);
933 EXPECT_EQ(infos[0].type, ExtensionAbilityType::BACKUP);
934 }
935 UnInstallBundle(BUNDLE_BACKUP_NAME);
936 }
937
938 /**
939 * @tc.name: QueryExtensionAbilityInfos_0500
940 * @tc.desc: 1.install the hap
941 * 2.query extensionAbilityInfos
942 * @tc.type: FUNC
943 * @tc.require: issueI5MZ33
944 */
945 HWTEST_F(BmsBundleInstallerTest, QueryExtensionAbilityInfos_0500, Function | SmallTest | Level0)
946 {
947 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_PREVIEW_TEST;
948 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
949 EXPECT_EQ(installResult, ERR_OK);
950
951 auto dataMgr = GetBundleDataMgr();
952 EXPECT_NE(dataMgr, nullptr);
953 AAFwk::Want want;
954 want.SetAction("action.system.home");
955 want.AddEntity("entity.system.home");
956 want.SetElementName("", BUNDLE_PREVIEW_NAME, "", MODULE_NAME);
957 std::vector<ExtensionAbilityInfo> infos;
958 bool result = dataMgr->QueryExtensionAbilityInfos(want, 0, USERID, infos);
959 EXPECT_TRUE(result);
960 EXPECT_EQ(infos.size(), NUMBER_ONE);
961 if (infos.size() > 0) {
962 EXPECT_EQ(infos[0].bundleName, BUNDLE_PREVIEW_NAME);
963 EXPECT_EQ(infos[0].moduleName, MODULE_NAME);
964 EXPECT_EQ(infos[0].type, ExtensionAbilityType::PREVIEW);
965 }
966 UnInstallBundle(BUNDLE_PREVIEW_NAME);
967 }
968
969 /**
970 * @tc.name: QueryExtensionAbilityInfos_0600
971 * @tc.desc: 1.install the hap
972 * 2.query extensionAbilityInfos
973 * @tc.type: FUNC
974 * @tc.require: issueI5MZ33
975 */
976 HWTEST_F(BmsBundleInstallerTest, QueryExtensionAbilityInfos_0600, Function | SmallTest | Level0)
977 {
978 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_PREVIEW_TEST;
979 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
980 EXPECT_EQ(installResult, ERR_OK);
981
982 auto dataMgr = GetBundleDataMgr();
983 EXPECT_NE(dataMgr, nullptr);
984 AAFwk::Want want;
985 want.SetElementName("", BUNDLE_PREVIEW_NAME, "", MODULE_NAME);
986 std::vector<ExtensionAbilityInfo> infos;
987 bool result = dataMgr->QueryExtensionAbilityInfos(want, 0, USERID, infos);
988 EXPECT_FALSE(result);
989 UnInstallBundle(BUNDLE_PREVIEW_NAME);
990 }
991
992 /**
993 * @tc.name: QueryExtensionAbilityInfos_0700
994 * @tc.desc: 1.install the hap
995 * 2.query extensionAbilityInfos
996 * @tc.type: FUNC
997 * @tc.require: issueI5MZ33
998 */
999 HWTEST_F(BmsBundleInstallerTest, QueryExtensionAbilityInfos_0700, Function | SmallTest | Level0)
1000 {
1001 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_PREVIEW_TEST;
1002 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
1003 EXPECT_EQ(installResult, ERR_OK);
1004
1005 auto dataMgr = GetBundleDataMgr();
1006 EXPECT_NE(dataMgr, nullptr);
1007 AAFwk::Want want;
1008 want.SetElementName("", BUNDLE_PREVIEW_NAME, EXTENSION_ABILITY_NAME, "");
1009 std::vector<ExtensionAbilityInfo> infos;
1010 bool result = dataMgr->QueryExtensionAbilityInfos(want, 0, USERID, infos);
1011 EXPECT_TRUE(result);
1012 EXPECT_EQ(infos.size(), NUMBER_ONE);
1013 if (infos.size() > 0) {
1014 EXPECT_EQ(infos[0].bundleName, BUNDLE_PREVIEW_NAME);
1015 EXPECT_EQ(infos[0].name, EXTENSION_ABILITY_NAME);
1016 EXPECT_EQ(infos[0].type, ExtensionAbilityType::PREVIEW);
1017 }
1018 UnInstallBundle(BUNDLE_PREVIEW_NAME);
1019 }
1020
1021 /**
1022 * @tc.name: QueryExtensionAbilityInfos_0800
1023 * @tc.desc: 1.install the hap
1024 * 2.query extensionAbilityInfos
1025 * @tc.type: FUNC
1026 * @tc.require: issueI5MZ33
1027 */
1028 HWTEST_F(BmsBundleInstallerTest, QueryExtensionAbilityInfos_0800, Function | SmallTest | Level0)
1029 {
1030 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_PREVIEW_TEST;
1031 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
1032 EXPECT_EQ(installResult, ERR_OK);
1033
1034 auto dataMgr = GetBundleDataMgr();
1035 EXPECT_NE(dataMgr, nullptr);
1036 AAFwk::Want want;
1037 want.SetElementName("", BUNDLE_PREVIEW_NAME, EXTENSION_ABILITY_NAME, MODULE_NAME);
1038 std::vector<ExtensionAbilityInfo> infos;
1039 bool result = dataMgr->QueryExtensionAbilityInfos(want, 0, USERID, infos);
1040 EXPECT_TRUE(result);
1041 EXPECT_EQ(infos.size(), NUMBER_ONE);
1042 if (infos.size() > 0) {
1043 EXPECT_EQ(infos[0].bundleName, BUNDLE_PREVIEW_NAME);
1044 EXPECT_EQ(infos[0].moduleName, MODULE_NAME);
1045 EXPECT_EQ(infos[0].name, EXTENSION_ABILITY_NAME);
1046 EXPECT_EQ(infos[0].type, ExtensionAbilityType::PREVIEW);
1047 }
1048 UnInstallBundle(BUNDLE_PREVIEW_NAME);
1049 }
1050
1051 /**
1052 * @tc.name: QueryExtensionAbilityInfos_0900
1053 * @tc.desc: 1.install the hap
1054 * 2.query extensionAbilityInfos
1055 * @tc.type: FUNC
1056 * @tc.require: issueI5MZ33
1057 */
1058 HWTEST_F(BmsBundleInstallerTest, QueryExtensionAbilityInfos_0900, Function | SmallTest | Level0)
1059 {
1060 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_THUMBNAIL_TEST;
1061 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
1062 EXPECT_EQ(installResult, ERR_OK);
1063
1064 auto dataMgr = GetBundleDataMgr();
1065 EXPECT_NE(dataMgr, nullptr);
1066 AAFwk::Want want;
1067 want.SetAction("action.system.home");
1068 want.AddEntity("entity.system.home");
1069 want.SetElementName("", BUNDLE_THUMBNAIL_NAME, "", MODULE_NAME);
1070 std::vector<ExtensionAbilityInfo> infos;
1071 bool result = dataMgr->QueryExtensionAbilityInfos(want, 0, USERID, infos);
1072 EXPECT_TRUE(result);
1073 EXPECT_EQ(infos.size(), NUMBER_ONE);
1074 if (infos.size() > 0) {
1075 EXPECT_EQ(infos[0].bundleName, BUNDLE_THUMBNAIL_NAME);
1076 EXPECT_EQ(infos[0].moduleName, MODULE_NAME);
1077 EXPECT_EQ(infos[0].type, ExtensionAbilityType::THUMBNAIL);
1078 }
1079 UnInstallBundle(BUNDLE_THUMBNAIL_NAME);
1080 }
1081
1082 /**
1083 * @tc.name: QueryExtensionAbilityInfos_1000
1084 * @tc.desc: 1.install the hap
1085 * 2.query extensionAbilityInfos
1086 * @tc.type: FUNC
1087 * @tc.require: issueI5MZ33
1088 */
1089 HWTEST_F(BmsBundleInstallerTest, QueryExtensionAbilityInfos_1000, Function | SmallTest | Level0)
1090 {
1091 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_THUMBNAIL_TEST;
1092 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
1093 EXPECT_EQ(installResult, ERR_OK);
1094
1095 auto dataMgr = GetBundleDataMgr();
1096 EXPECT_NE(dataMgr, nullptr);
1097 AAFwk::Want want;
1098 want.SetElementName("", BUNDLE_THUMBNAIL_NAME, "", MODULE_NAME);
1099 std::vector<ExtensionAbilityInfo> infos;
1100 bool result = dataMgr->QueryExtensionAbilityInfos(want, 0, USERID, infos);
1101 EXPECT_FALSE(result);
1102 UnInstallBundle(BUNDLE_THUMBNAIL_NAME);
1103 }
1104
1105 /**
1106 * @tc.name: QueryExtensionAbilityInfos_1100
1107 * @tc.desc: 1.install the hap
1108 * 2.query extensionAbilityInfos
1109 * @tc.type: FUNC
1110 * @tc.require: issueI5MZ33
1111 */
1112 HWTEST_F(BmsBundleInstallerTest, QueryExtensionAbilityInfos_1100, Function | SmallTest | Level0)
1113 {
1114 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_THUMBNAIL_TEST;
1115 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
1116 EXPECT_EQ(installResult, ERR_OK);
1117
1118 auto dataMgr = GetBundleDataMgr();
1119 EXPECT_NE(dataMgr, nullptr);
1120 AAFwk::Want want;
1121 want.SetElementName("", BUNDLE_THUMBNAIL_NAME, EXTENSION_ABILITY_NAME, "");
1122 std::vector<ExtensionAbilityInfo> infos;
1123 bool result = dataMgr->QueryExtensionAbilityInfos(want, 0, USERID, infos);
1124 EXPECT_TRUE(result);
1125 EXPECT_EQ(infos.size(), NUMBER_ONE);
1126 if (infos.size() > 0) {
1127 EXPECT_EQ(infos[0].bundleName, BUNDLE_THUMBNAIL_NAME);
1128 EXPECT_EQ(infos[0].name, EXTENSION_ABILITY_NAME);
1129 EXPECT_EQ(infos[0].type, ExtensionAbilityType::THUMBNAIL);
1130 }
1131 UnInstallBundle(BUNDLE_THUMBNAIL_NAME);
1132 }
1133
1134 /**
1135 * @tc.name: QueryExtensionAbilityInfos_1200
1136 * @tc.desc: 1.install the hap
1137 * 2.query extensionAbilityInfos
1138 * @tc.type: FUNC
1139 * @tc.require: issueI5MZ33
1140 */
1141 HWTEST_F(BmsBundleInstallerTest, QueryExtensionAbilityInfos_1200, Function | SmallTest | Level0)
1142 {
1143 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_THUMBNAIL_TEST;
1144 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
1145 EXPECT_EQ(installResult, ERR_OK);
1146
1147 auto dataMgr = GetBundleDataMgr();
1148 EXPECT_NE(dataMgr, nullptr);
1149 AAFwk::Want want;
1150 want.SetElementName("", BUNDLE_THUMBNAIL_NAME, EXTENSION_ABILITY_NAME, MODULE_NAME);
1151 std::vector<ExtensionAbilityInfo> infos;
1152 bool result = dataMgr->QueryExtensionAbilityInfos(want, 0, USERID, infos);
1153 EXPECT_TRUE(result);
1154 EXPECT_EQ(infos.size(), NUMBER_ONE);
1155 if (infos.size() > 0) {
1156 EXPECT_EQ(infos[0].bundleName, BUNDLE_THUMBNAIL_NAME);
1157 EXPECT_EQ(infos[0].moduleName, MODULE_NAME);
1158 EXPECT_EQ(infos[0].name, EXTENSION_ABILITY_NAME);
1159 EXPECT_EQ(infos[0].type, ExtensionAbilityType::THUMBNAIL);
1160 }
1161 UnInstallBundle(BUNDLE_THUMBNAIL_NAME);
1162 }
1163
1164 /**
1165 * @tc.number: QueryExtensionAbilityInfos_1300
1166 * @tc.name: test implicit query extensionAbilityInfos with skill flag
1167 * @tc.desc: 1.install the hap
1168 * 2.query extensionAbilityInfos with skill flag by implicit query
1169 */
1170 HWTEST_F(BmsBundleInstallerTest, QueryExtensionAbilityInfos_1300, Function | SmallTest | Level0)
1171 {
1172 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
1173 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
1174 EXPECT_EQ(installResult, ERR_OK);
1175
1176 auto dataMgr = GetBundleDataMgr();
1177 EXPECT_NE(dataMgr, nullptr);
1178 AAFwk::Want want;
1179 want.SetAction("action.system.home");
1180 want.AddEntity("entity.system.home");
1181 want.SetElementName("", BUNDLE_BACKUP_NAME, "", MODULE_NAME);
1182 std::vector<ExtensionAbilityInfo> infos;
1183 bool result = dataMgr->QueryExtensionAbilityInfos(want, GET_EXTENSION_INFO_WITH_SKILL, USERID, infos);
1184 EXPECT_TRUE(result);
1185 EXPECT_EQ(infos.size(), NUMBER_ONE);
1186 UnInstallBundle(BUNDLE_BACKUP_NAME);
1187 }
1188
1189 /**
1190 * @tc.number: QueryExtensionAbilityInfos_1400
1191 * @tc.name: test explicit query extensionAbilityInfos with skill flag
1192 * @tc.desc: 1.install the hap
1193 * 2.query extensionAbilityInfos with skill flag by explicit query
1194 */
1195 HWTEST_F(BmsBundleInstallerTest, QueryExtensionAbilityInfos_1400, Function | SmallTest | Level0)
1196 {
1197 std::string bundlePath = RESOURCE_ROOT_PATH + SYSTEMFIEID_BUNDLE;
1198 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
1199 EXPECT_EQ(installResult, ERR_OK);
1200
1201 auto dataMgr = GetBundleDataMgr();
1202 EXPECT_NE(dataMgr, nullptr);
1203 AAFwk::Want want;
1204 want.SetElementName(SYSTEMFIEID_NAME, "FormName");
1205 std::vector<ExtensionAbilityInfo> infos;
1206 bool result = dataMgr->QueryExtensionAbilityInfos(want, GET_EXTENSION_INFO_WITH_SKILL, USERID, infos);
1207 EXPECT_TRUE(result);
1208 EXPECT_EQ(infos.size(), NUMBER_ONE);
1209 UnInstallBundle(SYSTEMFIEID_NAME);
1210 }
1211
1212 /**
1213 * @tc.number: GetBundleStats_001
1214 * @tc.name: test the GetBundleStats
1215 * @tc.desc: 1.install the hap
1216 * 2.GetBundleStats
1217 */
1218 HWTEST_F(BmsBundleInstallerTest, GetBundleStats_001, Function | SmallTest | Level0)
1219 {
1220 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
1221 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
1222 EXPECT_EQ(installResult, ERR_OK);
1223
1224 std::vector<int64_t> bundleStats;
1225 auto ret = InstalldClient::GetInstance()->GetBundleStats(BUNDLE_BACKUP_NAME, USERID, bundleStats, 0);
1226 EXPECT_EQ(ret, ERR_OK);
1227 if (!bundleStats.empty()) {
1228 EXPECT_NE(bundleStats[0], 0);
1229 EXPECT_NE(bundleStats[1], 0);
1230 for (size_t index = 2; index < bundleStats.size(); index++) {
1231 EXPECT_EQ(bundleStats[index], 0);
1232 }
1233 }
1234 UnInstallBundle(BUNDLE_BACKUP_NAME);
1235 }
1236
1237 /**
1238 * @tc.number: CreateInstallTempDir_0100
1239 * @tc.name: test CreateInstallTempDir
1240 * @tc.desc: 1.create install temp dir success
1241 */
1242 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_0100, Function | SmallTest | Level0)
1243 {
1244 BundleUtil bundleUtil;
1245 const int32_t installId = 2022;
1246 std::string res = bundleUtil.CreateInstallTempDir(installId, DirType::STREAM_INSTALL_DIR);
1247 EXPECT_NE(res, "");
1248 }
1249
1250 /**
1251 * @tc.number: CreateInstallTempDir_0200
1252 * @tc.name: test CreateInstallTempDir
1253 * @tc.desc: 1.create install temp dir success
1254 */
1255 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_0200, Function | SmallTest | Level0)
1256 {
1257 BundleUtil bundleUtil;
1258 const int32_t installId = 2023;
1259 std::string res = bundleUtil.CreateInstallTempDir(installId, DirType::QUICK_FIX_DIR);
1260 EXPECT_NE(res, "");
1261
1262 UnInstallBundle(BUNDLE_BACKUP_NAME);
1263 }
1264
1265 /**
1266 * @tc.number: CreateInstallTempDir_0300
1267 * @tc.name: test CreateInstallTempDir
1268 * @tc.desc: 1.create install temp dir failed
1269 */
1270 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_0300, Function | SmallTest | Level0)
1271 {
1272 BundleUtil bundleUtil;
1273 const int32_t installId = 2023;
1274 std::string res = bundleUtil.CreateInstallTempDir(installId, DirType::UNKNOWN);
1275 EXPECT_EQ(res, "");
1276
1277 UnInstallBundle(BUNDLE_BACKUP_NAME);
1278 }
1279
1280 /**
1281 * @tc.number: CreateInstallTempDir_0400
1282 * @tc.name: test CheckFileName, the name max size is 256
1283 * @tc.desc: 1.test CheckFileName of BundleUtil
1284 */
1285 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_0400, Function | SmallTest | Level0)
1286 {
1287 BundleUtil bundleUtil;
1288 std::string maxFileName = std::string(256, 'a');
1289 bool res = bundleUtil.CheckFileName(maxFileName);
1290 EXPECT_EQ(res, true);
1291 maxFileName.append(".txt");
1292 res = bundleUtil.CheckFileName(maxFileName);
1293 EXPECT_EQ(res, false);
1294 }
1295
1296 /**
1297 * @tc.number: CreateInstallTempDir_0500
1298 * @tc.name: test CheckFileSize, size is not right
1299 * @tc.desc: 1.test CheckFileSize of BundleUtil
1300 */
1301 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_0500, Function | SmallTest | Level0)
1302 {
1303 BundleUtil bundleUtil;
1304 bool res = bundleUtil.CheckFileSize(BUNDLE_NAME, 0);
1305 EXPECT_EQ(res, false);
1306 }
1307
1308 /**
1309 * @tc.number: CreateInstallTempDir_0600
1310 * @tc.name: test GetHapFilesFromBundlePath, current path is empty or failed
1311 * @tc.desc: 1.test GetHapFilesFromBundlePath of BundleUtil
1312 */
1313 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_0600, Function | SmallTest | Level0)
1314 {
1315 BundleUtil bundleUtil;
1316 std::string currentPath = "";
1317 std::vector<std::string> fileList = {"test1.hap"};
1318 bool res = bundleUtil.GetHapFilesFromBundlePath(currentPath, fileList);
1319 EXPECT_EQ(res, false);
1320 currentPath = "/data/test/test2.hap";
1321 res = bundleUtil.GetHapFilesFromBundlePath(currentPath, fileList);
1322 EXPECT_EQ(res, false);
1323 }
1324
1325 /**
1326 * @tc.number: CreateInstallTempDir_0700
1327 * @tc.name: test DeviceAndNameToKey, key is id and name
1328 * @tc.desc: 1.test DeviceAndNameToKey of BundleUtil
1329 */
1330 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_0700, Function | SmallTest | Level0)
1331 {
1332 BundleUtil bundleUtil;
1333 std::string key = "";
1334 bundleUtil.DeviceAndNameToKey(
1335 ServiceConstants::CURRENT_DEVICE_ID, BUNDLE_NAME, key);
1336 EXPECT_EQ(key, "PHONE-001_com.example.l3jsdemo");
1337 }
1338
1339 /**
1340 * @tc.number: CreateInstallTempDir_0800
1341 * @tc.name: test KeyToDeviceAndName, split with underline
1342 * @tc.desc: 1.test KeyToDeviceAndName of BundleUtil
1343 */
1344 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_0800, Function | SmallTest | Level0)
1345 {
1346 BundleUtil bundleUtil;
1347 std::string underline = "_";
1348 std::string deviceId = ServiceConstants::CURRENT_DEVICE_ID;
1349 std::string bundleName = "com.split.underline";
1350 std::string key = deviceId + underline + bundleName;
1351 bool ret = bundleUtil.KeyToDeviceAndName(key, deviceId, bundleName);
1352 EXPECT_EQ(ret, true);
1353 key = deviceId + bundleName;
1354 ret = bundleUtil.KeyToDeviceAndName(key, deviceId, bundleName);
1355 EXPECT_EQ(ret, false);
1356 }
1357
1358 /**
1359 * @tc.number: CreateInstallTempDir_0900
1360 * @tc.name: test CreateFileDescriptorForReadOnly, path is file
1361 * @tc.desc: 1.test CreateFileDescriptorForReadOnly of BundleUtil
1362 */
1363 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_0900, Function | SmallTest | Level0)
1364 {
1365 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
1366 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
1367 EXPECT_EQ(installResult, ERR_OK);
1368
1369 BundleUtil bundleUtil;
1370 long long offset = 0;
1371 auto ret = bundleUtil.CreateFileDescriptorForReadOnly(bundlePath, offset);
1372 EXPECT_NE(ret, ERR_OK);
1373 bundlePath.append(std::string(256, '/'));
1374 ret = bundleUtil.CreateFileDescriptorForReadOnly(bundlePath, offset);
1375 EXPECT_NE(ret, ERR_OK);
1376
1377 UnInstallBundle(BUNDLE_BACKUP_NAME);
1378 }
1379
1380 /**
1381 * @tc.number: CreateInstallTempDir_1000
1382 * @tc.name: test RenameFile, oldPath or newPath is empty
1383 * @tc.desc: 1.test RenameFile of BundleUtil
1384 */
1385 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_1000, Function | SmallTest | Level0)
1386 {
1387 BundleUtil bundleUtil;
1388 bool ret = bundleUtil.RenameFile("", "");
1389 EXPECT_EQ(ret, false);
1390 ret = bundleUtil.RenameFile("oldPath", "");
1391 EXPECT_EQ(ret, false);
1392 ret = bundleUtil.RenameFile("", "newPath");
1393 EXPECT_EQ(ret, false);
1394 ret = bundleUtil.RenameFile("", "newPath");
1395 EXPECT_EQ(ret, false);
1396 ret = bundleUtil.RenameFile("oldPath", "newPath");
1397 EXPECT_EQ(ret, false);
1398 }
1399
1400 /**
1401 * @tc.number: CreateInstallTempDir_1100
1402 * @tc.name: test CopyFile, source or destination file is empty
1403 * @tc.desc: 1.test CopyFile of BundleUtil
1404 */
1405 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_1100, Function | SmallTest | Level0)
1406 {
1407 BundleUtil bundleUtil;
1408 bool ret = bundleUtil.CopyFile("", "");
1409 EXPECT_EQ(ret, false);
1410 ret = bundleUtil.CopyFile("source", "");
1411 EXPECT_EQ(ret, false);
1412 ret = bundleUtil.CopyFile("", "destinationFile");
1413 EXPECT_EQ(ret, false);
1414 ret = bundleUtil.CopyFile("source", "destinationFile");
1415 EXPECT_EQ(ret, false);
1416 }
1417
1418 /**
1419 * @tc.number: CreateInstallTempDir_1200
1420 * @tc.name: test CreateDir, param is empty return false
1421 * @tc.desc: 1.test CreateDir of BundleUtil
1422 */
1423 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_1200, Function | SmallTest | Level0)
1424 {
1425 BundleUtil bundleUtil;
1426 bool ret = bundleUtil.CreateDir("");
1427 EXPECT_EQ(ret, false);
1428 ret = bundleUtil.CreateDir(BUNDLE_CODE_DIR);
1429 EXPECT_EQ(ret, true);
1430 }
1431
1432 /**
1433 * @tc.number: CreateInstallTempDir_1300
1434 * @tc.name: test RevertToRealPath, one param is empty return false
1435 * @tc.desc: 1.test RevertToRealPath of BundleUtil
1436 */
1437 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_1300, Function | SmallTest | Level0)
1438 {
1439 BundleUtil util;
1440 std::string empty = "";
1441 bool ret = util.RevertToRealPath(empty, empty, empty);
1442 EXPECT_EQ(ret, false);
1443 ret = util.RevertToRealPath("/data/storage/el2/base", empty, empty);
1444 EXPECT_EQ(ret, false);
1445 ret = util.RevertToRealPath("/data/storage/el2/base", "com.ohos.test", empty);
1446 EXPECT_EQ(ret, true);
1447 }
1448
1449 /**
1450 * @tc.number: CreateInstallTempDir_1400
1451 * @tc.name: test StartWith, one of param is empty return false
1452 * @tc.desc: 1.test StartWith of BundleUtil
1453 */
1454 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_1400, Function | SmallTest | Level0)
1455 {
1456 BundleUtil util;
1457 bool ret = util.StartWith("", BUNDLE_DATA_DIR);
1458 EXPECT_EQ(ret, false);
1459 ret = util.StartWith(BUNDLE_DATA_DIR, "");
1460 EXPECT_EQ(ret, false);
1461 ret = util.StartWith(BUNDLE_DATA_DIR, BUNDLE_DATA_DIR);
1462 EXPECT_EQ(ret, true);
1463 }
1464
1465 /**
1466 * @tc.number: CreateInstallTempDir_1500
1467 * @tc.name: test EndWith, one of param is empty return false
1468 * @tc.desc: 1.test EndWith of BundleUtil
1469 */
1470 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_1500, Function | SmallTest | Level0)
1471 {
1472 BundleUtil util;
1473 bool ret = util.EndWith("", BUNDLE_DATA_DIR);
1474 EXPECT_EQ(ret, false);
1475 ret = util.EndWith(BUNDLE_DATA_DIR, "");
1476 EXPECT_EQ(ret, false);
1477 ret = util.EndWith(BUNDLE_DATA_DIR, BUNDLE_CODE_DIR);
1478 EXPECT_EQ(ret, false);
1479 ret = util.EndWith(BUNDLE_DATA_DIR, BUNDLE_DATA_DIR);
1480 EXPECT_EQ(ret, true);
1481 }
1482
1483 /**
1484 * @tc.number: CreateInstallTempDir_1600
1485 * @tc.name: test file size
1486 * @tc.desc: 1.test GetFileSize of BundleUtil
1487 */
1488 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_1600, Function | SmallTest | Level0)
1489 {
1490 BundleUtil util;
1491 int64_t ret = util.GetFileSize("");
1492 EXPECT_EQ(ret, 0);
1493 std::string bundleFile = RESOURCE_ROOT_PATH + RIGHT_BUNDLE;
1494
1495 bool installResult = InstallSystemBundle(bundleFile);
1496 EXPECT_TRUE(installResult);
1497 ret = util.GetFileSize(bundleFile);
1498 EXPECT_NE(ret, 0);
1499 CheckFileExist();
1500 ClearBundleInfo();
1501 }
1502
1503 /**
1504 * @tc.number: GetBaseSharedBundleInfosTest
1505 * @tc.name: Test use different param with GetBaseSharedBundleInfos
1506 * @tc.desc: 1.Test the GetBaseSharedBundleInfos with BundleDataMgr
1507 */
1508 HWTEST_F(BmsBundleInstallerTest, GetBaseSharedBundleInfosTest, Function | SmallTest | Level0)
1509 {
1510 auto dataMgr = GetBundleDataMgr();
1511 std::vector<BaseSharedBundleInfo> infos;
1512 auto ret = dataMgr->GetBaseSharedBundleInfos("", infos);
1513 EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST);
1514 }
1515
1516 /**
1517 * @tc.number: GetBaseSharedBundleInfosTest_0010
1518 * @tc.name: Test use different param with GetBaseSharedBundleInfos
1519 * @tc.desc: 1.Test the GetBaseSharedBundleInfos with BundleDataMgr
1520 */
1521 HWTEST_F(BmsBundleInstallerTest, GetBaseSharedBundleInfosTest_0010, Function | SmallTest | Level0)
1522 {
1523 auto dataMgr = GetBundleDataMgr();
1524 std::vector<BaseSharedBundleInfo> infos;
1525 auto ret = dataMgr->GetBaseSharedBundleInfos("", infos, GetDependentBundleInfoFlag::GET_APP_CROSS_HSP_BUNDLE_INFO);
1526 EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST);
1527 }
1528
1529 /**
1530 * @tc.number: GetBaseSharedBundleInfosTest_0020
1531 * @tc.name: Test use different param with GetBaseSharedBundleInfos
1532 * @tc.desc: 1.Test the GetBaseSharedBundleInfos with BundleDataMgr
1533 */
1534 HWTEST_F(BmsBundleInstallerTest, GetBaseSharedBundleInfosTest_0020, Function | SmallTest | Level0)
1535 {
1536 auto dataMgr = GetBundleDataMgr();
1537 std::vector<BaseSharedBundleInfo> infos;
1538 auto ret = dataMgr->GetBaseSharedBundleInfos(BUNDLE_NAME, infos,
1539 GetDependentBundleInfoFlag::GET_APP_SERVICE_HSP_BUNDLE_INFO);
1540 EXPECT_EQ(ret, ERR_OK);
1541 }
1542
1543 /**
1544 * @tc.number: GetBaseSharedBundleInfosTest_0030
1545 * @tc.name: Test use different param with GetBaseSharedBundleInfos
1546 * @tc.desc: 1.Test the GetBaseSharedBundleInfos with BundleDataMgr
1547 */
1548 HWTEST_F(BmsBundleInstallerTest, GetBaseSharedBundleInfosTest_0030, Function | SmallTest | Level0)
1549 {
1550 auto dataMgr = GetBundleDataMgr();
1551 std::vector<BaseSharedBundleInfo> infos;
1552 auto ret = dataMgr->GetBaseSharedBundleInfos(BUNDLE_NAME, infos,
1553 GetDependentBundleInfoFlag::GET_ALL_DEPENDENT_BUNDLE_INFO);
1554 EXPECT_EQ(ret, ERR_OK);
1555 }
1556
1557 /**
1558 * @tc.number: GetBaseSharedBundleInfoTest
1559 * @tc.name: Test use different param with GetBaseSharedBundleInfos
1560 * @tc.desc: 1.Test the GetBaseSharedBundleInfo with BundleDataMgr
1561 */
1562 HWTEST_F(BmsBundleInstallerTest, GetBaseSharedBundleInfoTest, Function | SmallTest | Level0)
1563 {
1564 auto dataMgr = GetBundleDataMgr();
1565 Dependency dependency;
1566 BaseSharedBundleInfo info;
1567 auto ret = dataMgr->GetBaseSharedBundleInfo(dependency, info);
1568 EXPECT_EQ(ret, false);
1569 dependency.bundleName = BUNDLE_NAME;
1570 InnerBundleInfo innerBundleInfo;
1571 dataMgr->bundleInfos_[BUNDLE_NAME] = innerBundleInfo;
1572 ret = dataMgr->GetBaseSharedBundleInfo(dependency, info);
1573 EXPECT_EQ(ret, false);
1574 dataMgr->bundleInfos_.clear();
1575 innerBundleInfo.baseApplicationInfo_->bundleType = BundleType::SHARED;
1576 dataMgr->bundleInfos_[BUNDLE_NAME] = innerBundleInfo;
1577 ret = dataMgr->GetBaseSharedBundleInfo(dependency, info);
1578 EXPECT_EQ(ret, true);
1579 dataMgr->bundleInfos_.clear();
1580 }
1581
1582 /**
1583 * @tc.number: OTASystemInstall_0100
1584 * @tc.name: test the right system bundle file can be installed
1585 * @tc.desc: 1.the system bundle file exists
1586 * 2.the system bundle can be installed successfully and can get the bundle info
1587 */
1588 HWTEST_F(BmsBundleInstallerTest, OTASystemInstall_0100, Function | SmallTest | Level0)
1589 {
1590 std::string bundleFile = RESOURCE_ROOT_PATH + RIGHT_BUNDLE;
1591 bool result = OTAInstallSystemBundle(bundleFile);
1592 EXPECT_TRUE(result) << "the bundle file install failed: " << bundleFile;
1593 CheckFileExist();
1594 ClearBundleInfo();
1595 }
1596
1597 /**
1598 * @tc.number: baseBundleInstaller_0100
1599 * @tc.name: test BuildTempNativeLibraryPath, needSendEvent is true
1600 * @tc.desc: 1.Test the BuildTempNativeLibraryPath of BaseBundleInstaller
1601 */
1602 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_0100, Function | SmallTest | Level0)
1603 {
1604 BaseBundleInstaller installer;
1605 installer.dataMgr_ = GetBundleDataMgr();
1606 InstallParam installParam;
1607 installParam.needSendEvent = true;
1608 ErrCode ret = installer.InstallBundleByBundleName(
1609 BUNDLE_NAME, installParam);
1610 EXPECT_NE(ret, ERR_OK);
1611 }
1612
1613 /**
1614 * @tc.number: baseBundleInstaller_0200
1615 * @tc.name: test Recover, needSendEvent is true
1616 * @tc.desc: 1.Test the Recover of BaseBundleInstaller
1617 */
1618 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_0200, Function | SmallTest | Level0)
1619 {
1620 BaseBundleInstaller installer;
1621 installer.dataMgr_ = GetBundleDataMgr();
1622 installer.bundleName_ = BUNDLE_NAME;
1623 installer.modulePackage_ = "entry";
1624 InstallParam installParam;
1625 installParam.needSendEvent = true;
1626 ErrCode ret = installer.Recover(BUNDLE_NAME, installParam);
1627 EXPECT_NE(ret, ERR_OK);
1628 }
1629
1630 /**
1631 * @tc.number: baseBundleInstaller_0300
1632 * @tc.name: test ProcessBundleInstall
1633 * @tc.desc: 1.Test the ProcessBundleInstall of BaseBundleInstaller
1634 */
1635 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_0300, Function | SmallTest | Level0)
1636 {
1637 BaseBundleInstaller installer;
1638 std::vector<std::string> inBundlePaths;
1639 InstallParam installParam;
1640 auto appType = Constants::AppType::THIRD_PARTY_APP;
1641 int32_t uid = 0;
1642 ErrCode ret = installer.ProcessBundleInstall(
1643 inBundlePaths, installParam, appType, uid);
1644 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_FILE_PATH_INVALID);
1645 installer.dataMgr_ = GetBundleDataMgr();
1646
1647 installParam.userId = Constants::INVALID_USERID;
1648 ret = installer.ProcessBundleInstall(
1649 inBundlePaths, installParam, appType, uid);
1650 EXPECT_NE(ret, ERR_OK);
1651 }
1652
1653 /**
1654 * @tc.number: baseBundleInstaller_0400
1655 * @tc.name: test CheckVersionCompatibilityForHmService
1656 * @tc.desc: 1.Test the CheckVersionCompatibilityForHmService of BaseBundleInstaller
1657 */
1658 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_0400, Function | SmallTest | Level0)
1659 {
1660 BaseBundleInstaller installer;
1661 installer.versionCode_ = 1;
1662 InnerBundleInfo oldInfo;
1663 oldInfo.baseBundleInfo_->versionCode = 2;
1664 auto ret = installer.CheckVersionCompatibilityForHmService(oldInfo);
1665 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_VERSION_DOWNGRADE);
1666
1667 installer.versionCode_ = 3;
1668 ret = installer.CheckVersionCompatibilityForHmService(oldInfo);
1669 EXPECT_EQ(ret, ERR_OK);
1670 }
1671
1672 /**
1673 * @tc.number: baseBundleInstaller_0500
1674 * @tc.name: test CreateBundleUserData, user id is different
1675 * @tc.desc: 1.Test the CreateBundleUserData of BaseBundleInstaller
1676 */
1677 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_0500, Function | SmallTest | Level0)
1678 {
1679 BaseBundleInstaller installer;
1680 InnerBundleInfo innerBundleInfo;
1681 auto ret = installer.CreateBundleUserData(innerBundleInfo);
1682 EXPECT_EQ(ret, ERR_APPEXECFWK_USER_NOT_EXIST);
1683 }
1684
1685 /**
1686 * @tc.number: baseBundleInstaller_0600
1687 * @tc.name: test RemoveBundleUserData, InnerBundleInfo id is different
1688 * @tc.desc: 1.Test the RemoveBundleUserData of BaseBundleInstaller
1689 */
1690 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_0600, Function | SmallTest | Level0)
1691 {
1692 BaseBundleInstaller installer;
1693 InnerBundleInfo innerBundleInfo;
1694 InnerBundleUserInfo userInfo;
1695 bool needRemoveData = false;
1696 auto ret = installer.RemoveBundleUserData(innerBundleInfo, needRemoveData);
1697 EXPECT_EQ(ret, ERR_APPEXECFWK_USER_NOT_EXIST);
1698 innerBundleInfo.innerBundleUserInfos_.emplace("key", userInfo);
1699 installer.userId_ = Constants::ALL_USERID;
1700 installer.dataMgr_ = GetBundleDataMgr();
1701 ret = installer.RemoveBundleUserData(innerBundleInfo, needRemoveData);
1702 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_BUNDLE_MGR_SERVICE_ERROR);
1703 }
1704
1705 /**
1706 * @tc.number: baseBundleInstaller_0800
1707 * @tc.name: test ProcessInstallBundleByBundleName
1708 * @tc.desc: 1.Test the ProcessInstallBundleByBundleName of BaseBundleInstaller
1709 */
1710 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_0800, Function | SmallTest | Level0)
1711 {
1712 BaseBundleInstaller installer;
1713 InnerBundleInfo innerBundleInfo;
1714 InstallParam installParam;
1715 int32_t uid = 0;
1716 ErrCode ret = installer.ProcessInstallBundleByBundleName(
1717 BUNDLE_NAME, installParam, uid);
1718 EXPECT_NE(ret, ERR_OK);
1719 }
1720
1721 /**
1722 * @tc.number: baseBundleInstaller_0900
1723 * @tc.name: test ProcessRecover
1724 * @tc.desc: 1.Test the ProcessRecover of BaseBundleInstaller
1725 */
1726 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_0900, Function | SmallTest | Level0)
1727 {
1728 BaseBundleInstaller installer;
1729 InnerBundleInfo innerBundleInfo;
1730 InstallParam installParam;
1731 int32_t uid = 0;
1732 ErrCode ret = installer.ProcessRecover(
1733 BUNDLE_NAME, installParam, uid);
1734 EXPECT_NE(ret, ERR_OK);
1735 }
1736
1737 /**
1738 * @tc.number: baseBundleInstaller_1000
1739 * @tc.name: test InnerProcessInstallByPreInstallInfo
1740 * @tc.desc: 1.Test the InnerProcessInstallByPreInstallInfo of BaseBundleInstaller
1741 */
1742 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_1000, Function | SmallTest | Level0)
1743 {
1744 BaseBundleInstaller installer;
1745 installer.dataMgr_ = GetBundleDataMgr();
1746 InnerBundleInfo innerBundleInfo;
1747 int32_t uid = 0;
1748 InstallParam installParam;
1749 installParam.userId = Constants::INVALID_USERID;
1750 ErrCode ret = installer.InnerProcessInstallByPreInstallInfo(
1751 BUNDLE_NAME_TEST1, installParam, uid);
1752 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_PARAM_ERROR);
1753 }
1754
1755 /**
1756 * @tc.number: baseBundleInstaller_1100
1757 * @tc.name: test ProcessDeployedHqfInfo
1758 * @tc.desc: 1.Test the ProcessDeployedHqfInfo of BaseBundleInstaller
1759 */
1760 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_1100, Function | SmallTest | Level0)
1761 {
1762 BaseBundleInstaller installer;
1763 installer.dataMgr_ = GetBundleDataMgr();
1764 std::string nativeLibraryPath = "X86";
1765 std::string cpuAbi = "armeabi";
1766 InnerBundleInfo newInfo;
1767 AppQuickFix oldAppQuickFix;
1768 ErrCode ret = installer.ProcessDeployedHqfInfo(
1769 nativeLibraryPath, cpuAbi, newInfo, oldAppQuickFix);
1770 EXPECT_EQ(ret, ERR_OK);
1771 }
1772
1773 /**
1774 * @tc.number: baseBundleInstaller_1200
1775 * @tc.name: test ProcessDeployingHqfInfo
1776 * @tc.desc: 1.Test the ProcessDeployingHqfInfo of BaseBundleInstaller
1777 */
1778 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_1200, Function | SmallTest | Level0)
1779 {
1780 BaseBundleInstaller installer;
1781 std::string nativeLibraryPath = "X86";
1782 std::string cpuAbi = "armeabi";
1783 InnerBundleInfo newInfo;
1784 ErrCode ret = installer.ProcessDeployingHqfInfo(
1785 nativeLibraryPath, cpuAbi, newInfo);
1786 EXPECT_EQ(ret, ERR_OK);
1787 }
1788
1789 /**
1790 * @tc.number: baseBundleInstaller_1300
1791 * @tc.name: test UpdateLibAttrs
1792 * @tc.desc: 1.Test the UpdateLibAttrs of BaseBundleInstaller
1793 */
1794 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_1300, Function | SmallTest | Level0)
1795 {
1796 BaseBundleInstaller installer;
1797 std::string nativeLibraryPath = "X86";
1798 std::string cpuAbi = "armeabi";
1799 InnerBundleInfo newInfo;
1800 AppqfInfo appQfInfo;
1801 ErrCode ret = installer.UpdateLibAttrs(
1802 newInfo, cpuAbi, nativeLibraryPath, appQfInfo);
1803 EXPECT_EQ(ret, ERR_OK);
1804 }
1805
1806 /**
1807 * @tc.number: baseBundleInstaller_1400
1808 * @tc.name: test CheckHapLibsWithPatchLibs
1809 * @tc.desc: 1.Test the CheckHapLibsWithPatchLibs of BaseBundleInstaller
1810 */
1811 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_1400, Function | SmallTest | Level0)
1812 {
1813 BaseBundleInstaller installer;
1814 std::string nativeLibraryPath = "";
1815 std::string hqfLibraryPath = "a.hqf";
1816 bool ret = installer.CheckHapLibsWithPatchLibs(
1817 nativeLibraryPath, hqfLibraryPath);
1818 EXPECT_EQ(ret, false);
1819
1820 hqfLibraryPath = "/data/storage/el1/a.hqf";
1821 ret = installer.CheckHapLibsWithPatchLibs(
1822 nativeLibraryPath, hqfLibraryPath);
1823 EXPECT_EQ(ret, false);
1824
1825 nativeLibraryPath = hqfLibraryPath;
1826 ret = installer.CheckHapLibsWithPatchLibs(
1827 nativeLibraryPath, hqfLibraryPath);
1828 EXPECT_EQ(ret, true);
1829
1830 ret = installer.CheckHapLibsWithPatchLibs(
1831 nativeLibraryPath, "");
1832 EXPECT_EQ(ret, true);
1833
1834 ret = installer.CheckHapLibsWithPatchLibs(
1835 nativeLibraryPath, hqfLibraryPath);
1836 EXPECT_EQ(ret, true);
1837 }
1838
1839 /**
1840 * @tc.number: baseBundleInstaller_1500
1841 * @tc.name: test ProcessDiffFiles
1842 * @tc.desc: 1.Test the ProcessDiffFiles of BaseBundleInstaller
1843 */
1844 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_1500, Function | SmallTest | Level0)
1845 {
1846 BaseBundleInstaller installer;
1847 installer.modulePackage_ = "entry";
1848 std::vector<HqfInfo> hqfInfos;
1849 HqfInfo info;
1850 info.moduleName = "entry";
1851 hqfInfos.emplace_back(info);
1852 AppqfInfo appQfInfo;
1853 appQfInfo.hqfInfos = hqfInfos;
1854 std::string nativeLibraryPath = "libs/armeabi-v7a/";
1855 std::string cpuAbi = "arm";
1856 ErrCode ret = installer.ProcessDiffFiles(
1857 appQfInfo, nativeLibraryPath, cpuAbi);
1858 EXPECT_EQ(ret, ERR_BUNDLEMANAGER_QUICK_FIX_BUNDLE_NAME_NOT_EXIST);
1859 }
1860
1861 /**
1862 * @tc.number: baseBundleInstaller_1600
1863 * @tc.name: test SaveOldRemovableInfo
1864 * @tc.desc: 1.Test the SaveOldRemovableInfo of BaseBundleInstaller
1865 */
1866 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_1600, Function | SmallTest | Level0)
1867 {
1868 BaseBundleInstaller installer;
1869 InnerBundleInfo oldInfo;
1870 InnerModuleInfo info;
1871 info.isRemovable.try_emplace("removeInfo1", false);
1872 info.isRemovable.try_emplace("removeInfo2", true);
1873 oldInfo.innerModuleInfos_.try_emplace("entry", info);
1874 InnerModuleInfo newModuleInfo;
1875 bool existModule = true;
1876 installer.SaveOldRemovableInfo(newModuleInfo, oldInfo, existModule);
1877 newModuleInfo.modulePackage = "entry";
1878 installer.SaveOldRemovableInfo(newModuleInfo, oldInfo, existModule);
1879 EXPECT_EQ(newModuleInfo.isRemovable["removeInfo1"], false);
1880 EXPECT_EQ(newModuleInfo.isRemovable["removeInfo2"], true);
1881 }
1882
1883 /**
1884 * @tc.number: baseBundleInstaller_1700
1885 * @tc.name: test ExtractArkNativeFile
1886 * @tc.desc: 1.Test the ExtractArkNativeFile of BaseBundleInstaller
1887 */
1888 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_1700, Function | SmallTest | Level0)
1889 {
1890 BaseBundleInstaller installer;
1891 InnerBundleInfo info;
1892 std::string modulePath;
1893 ErrCode ret = installer.ExtractArkNativeFile(info, modulePath);
1894 EXPECT_EQ(ret, ERR_OK);
1895
1896 info.baseApplicationInfo_->arkNativeFilePath = "";
1897 info.baseApplicationInfo_->arkNativeFileAbi = "errorType";
1898 ret = installer.ExtractArkNativeFile(info, modulePath);
1899 EXPECT_EQ(ret, ERR_APPEXECFWK_PARSE_AN_FAILED);
1900
1901 info.baseApplicationInfo_->arkNativeFileAbi = "x86";
1902 ret = installer.ExtractArkNativeFile(info, modulePath);
1903 EXPECT_NE(ret, ERR_OK);
1904 }
1905
1906 /**
1907 * @tc.number: baseBundleInstaller_1800
1908 * @tc.name: test DeleteOldArkNativeFile
1909 * @tc.desc: 1.Test the DeleteOldArkNativeFile of BaseBundleInstaller
1910 */
1911 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_1800, Function | SmallTest | Level0)
1912 {
1913 BaseBundleInstaller installer;
1914 InnerBundleInfo oldInfo;
1915 oldInfo.baseApplicationInfo_->arkNativeFilePath = "/an/x86/x86.so";
1916 ErrCode ret = installer.DeleteOldArkNativeFile(oldInfo);
1917 EXPECT_EQ(ret, ERR_OK);
1918 }
1919
1920 /**
1921 * @tc.number: baseBundleInstaller_2100
1922 * @tc.name: test baseBundleInstaller
1923 * @tc.desc: 1.Test the dataMgr_ is nullptr
1924 */
1925 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_2100, Function | SmallTest | Level0)
1926 {
1927 BaseBundleInstaller installer;
1928 installer.dataMgr_ = nullptr;
1929 ClearDataMgr();
1930 std::vector<std::string> inBundlePaths;
1931 InstallParam installParam;
1932 auto appType = Constants::AppType::THIRD_PARTY_APP;
1933 int32_t uid = 0;
1934 bool recoverMode = true;
1935 ErrCode ret = installer.ProcessBundleInstall(
1936 inBundlePaths, installParam, appType, uid);
1937 EXPECT_EQ(ret, ERR_APPEXECFWK_UNINSTALL_BUNDLE_MGR_SERVICE_ERROR);
1938 ret = installer.ProcessBundleUninstall(
1939 "bundleName", installParam, uid);
1940 EXPECT_EQ(ret, ERR_APPEXECFWK_UNINSTALL_BUNDLE_MGR_SERVICE_ERROR);
1941 ret = installer.ProcessBundleUninstall(
1942 "bundleName", "modulePackage", installParam, uid);
1943 EXPECT_EQ(ret, ERR_APPEXECFWK_UNINSTALL_BUNDLE_MGR_SERVICE_ERROR);
1944 ret = installer.InnerProcessInstallByPreInstallInfo(
1945 "bundleName", installParam, uid);
1946 EXPECT_EQ(ret, ERR_APPEXECFWK_UNINSTALL_BUNDLE_MGR_SERVICE_ERROR);
1947 InnerBundleInfo info;
1948 bool res = installer.GetInnerBundleInfo(info, recoverMode);
1949 EXPECT_EQ(res, false);
1950 ResetDataMgr();
1951
1952 installParam.userId = Constants::INVALID_USERID;
1953 ret = installer.ProcessBundleUninstall(
1954 "bundleName", installParam, uid);
1955 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_PARAM_ERROR);
1956 ret = installer.ProcessBundleUninstall(
1957 "bundleName", "modulePackage", installParam, uid);
1958 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_PARAM_ERROR);
1959 }
1960
1961 /**
1962 * @tc.number: baseBundleInstaller_2200
1963 * @tc.name: test RemoveBundle
1964 * @tc.desc: 1.Test the RemoveBundle
1965 */
1966 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_2200, Function | SmallTest | Level0)
1967 {
1968 BaseBundleInstaller installer;
1969 InnerBundleInfo info;
1970 installer.InitDataMgr();
1971 ErrCode res = installer.RemoveBundle(info, false);
1972 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_BUNDLE_MGR_SERVICE_ERROR);
1973
1974 res = installer.RemoveBundle(info, true);
1975 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_BUNDLE_MGR_SERVICE_ERROR);
1976 }
1977
1978 /**
1979 * @tc.number: baseBundleInstaller_2300
1980 * @tc.name: test ProcessBundleUpdateStatus
1981 * @tc.desc: 1.Test the ProcessBundleUpdateStatus
1982 */
1983 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_2300, Function | SmallTest | Level0)
1984 {
1985 BaseBundleInstaller installer;
1986 InnerBundleInfo oldInfo;
1987 InnerBundleInfo newInfo;
1988 installer.isFeatureNeedUninstall_ = true;
1989 ErrCode res = installer.ProcessBundleUpdateStatus(oldInfo, newInfo, false, false);
1990 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_PARAM_ERROR);
1991 }
1992
1993 /**
1994 * @tc.number: baseBundleInstaller_2400
1995 * @tc.name: test ProcessBundleUpdateStatus
1996 * @tc.desc: 1.Test the ProcessBundleUpdateStatus
1997 */
1998 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_2400, Function | SmallTest | Level0)
1999 {
2000 BaseBundleInstaller installer;
2001 installer.dataMgr_ = GetBundleDataMgr();
2002 installer.userId_ = USERID;
2003 InnerBundleInfo info;
2004 ErrCode res = installer.CreateBundleDataDir(info);
2005 EXPECT_EQ(res, ERR_APPEXECFWK_USER_NOT_EXIST);
2006
2007 installer.userId_ = Constants::INVALID_USERID;
2008 ApplicationInfo applicationInfo;
2009 applicationInfo.bundleName = BUNDLE_NAME;
2010 info.SetBaseApplicationInfo(applicationInfo);
2011 res = installer.CreateBundleDataDir(info);
2012 EXPECT_EQ(res, ERR_APPEXECFWK_USER_NOT_EXIST);
2013 }
2014
2015 /**
2016 * @tc.number: baseBundleInstaller_2600
2017 * @tc.name: test ProcessBundleUninstall
2018 * @tc.desc: 1.Test the ProcessBundleUninstall of BaseBundleInstaller
2019 */
2020 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_2600, Function | SmallTest | Level0)
2021 {
2022 BaseBundleInstaller installer;
2023 std::string bundleName = SYSTEMFIEID_NAME;
2024 std::string modulePackage = MODULE_NAME;
2025 InstallParam installParam;
2026 installParam.userId = -1;
2027 int32_t uid = USERID;
2028
2029 auto res = installer.ProcessBundleUninstall(bundleName, installParam, uid);
2030 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_PARAM_ERROR);
2031 res = installer.ProcessBundleUninstall(bundleName, modulePackage, installParam, uid);
2032 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_PARAM_ERROR);
2033 }
2034
2035 /**
2036 * @tc.number: baseBundleInstaller_2700
2037 * @tc.name: test ProcessBundleUpdateStatus
2038 * @tc.desc: 1.Test the ProcessBundleUpdateStatus of BaseBundleInstaller
2039 */
2040 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_2700, Function | SmallTest | Level0)
2041 {
2042 BaseBundleInstaller installer;
2043 InnerBundleInfo oldInfo;
2044 InnerBundleInfo newInfo;
2045 newInfo.currentPackage_ = "";
2046 bool isReplace = false;
2047 bool killProcess = false;
2048
2049 auto res = installer.ProcessBundleUpdateStatus(oldInfo, newInfo, isReplace, killProcess);
2050 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_PARAM_ERROR);
2051 }
2052
2053 /**
2054 * @tc.number: baseBundleInstaller_2800
2055 * @tc.name: test ProcessBundleUpdateStatus
2056 * @tc.desc: 1.Test the ProcessBundleUpdateStatus of BaseBundleInstaller
2057 */
2058 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_2800, Function | SmallTest | Level0)
2059 {
2060 BaseBundleInstaller installer;
2061 InnerBundleInfo oldInfo;
2062 oldInfo.baseApplicationInfo_->singleton = true;
2063 InnerBundleInfo newInfo;
2064 newInfo.currentPackage_ = MODULE_NAME;
2065 bool isReplace = false;
2066 bool killProcess = false;
2067
2068 auto res = installer.ProcessBundleUpdateStatus(oldInfo, newInfo, isReplace, killProcess);
2069 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_SINGLETON_INCOMPATIBLE);
2070 }
2071
2072 /**
2073 * @tc.number: baseBundleInstaller_2900
2074 * @tc.name: test ProcessBundleUpdateStatus
2075 * @tc.desc: 1.Test the ProcessBundleUpdateStatus of BaseBundleInstaller
2076 */
2077 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_2900, Function | SmallTest | Level0)
2078 {
2079 BaseBundleInstaller installer;
2080 InnerBundleInfo oldInfo;
2081 InnerBundleInfo newInfo;
2082 newInfo.currentPackage_ = MODULE_NAME;
2083 newInfo.baseApplicationInfo_->singleton = true;
2084 bool isReplace = false;
2085 bool killProcess = false;
2086
2087 auto res = installer.ProcessBundleUpdateStatus(oldInfo, newInfo, isReplace, killProcess);
2088 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_SINGLETON_INCOMPATIBLE);
2089
2090 installer.modulePackage_ = MODULE_NAME;
2091 InnerModuleInfo moduleInfo;
2092 moduleInfo.isLibIsolated = true;
2093 moduleInfo.cpuAbi = "123";
2094 moduleInfo.nativeLibraryPath = "/data/test";
2095 newInfo.innerModuleInfos_.insert(pair<std::string, InnerModuleInfo>(MODULE_NAME, moduleInfo));
2096 installer.ProcessHqfInfo(oldInfo, newInfo);
2097 }
2098
2099 /**
2100 * @tc.number: baseBundleInstaller_3000
2101 * @tc.name: test ProcessDeployedHqfInfo
2102 * @tc.desc: 1.Test the ProcessDeployedHqfInfo of BaseBundleInstaller
2103 */
2104 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_3000, Function | SmallTest | Level0)
2105 {
2106 BaseBundleInstaller installer;
2107 installer.dataMgr_ = GetBundleDataMgr();
2108 installer.isFeatureNeedUninstall_ = false;
2109 std::string nativeLibraryPath = "/data/test";
2110 std::string cpuAbi = "123";
2111 InnerBundleInfo newInfo;
2112 AppQuickFix oldAppQuickFix;
2113 HqfInfo hqfInfo;
2114 oldAppQuickFix.deployedAppqfInfo.hqfInfos.push_back(hqfInfo);
2115
2116 auto res = installer.ProcessDeployedHqfInfo(nativeLibraryPath, cpuAbi, newInfo, oldAppQuickFix);
2117 EXPECT_EQ(res, ERR_BUNDLEMANAGER_QUICK_FIX_BUNDLE_NAME_NOT_EXIST);
2118
2119 hqfInfo.moduleName = MODULE_NAME;
2120 installer.modulePackage_ = "123";
2121 res = installer.ProcessDeployedHqfInfo(nativeLibraryPath, cpuAbi, newInfo, oldAppQuickFix);
2122 EXPECT_EQ(res, ERR_OK);
2123 }
2124
2125 /**
2126 * @tc.number: baseBundleInstaller_3100
2127 * @tc.name: test UpdateLibAttrs
2128 * @tc.desc: 1.Test the UpdateLibAttrs of BaseBundleInstaller
2129 */
2130 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_3100, Function | SmallTest | Level0)
2131 {
2132 BaseBundleInstaller installer;
2133 InnerBundleInfo newInfo;
2134 newInfo.currentPackage_ = MODULE_NAME;
2135 InnerModuleInfo moduleInfo;
2136 moduleInfo.moduleName = MODULE_NAME;
2137 newInfo.innerModuleInfos_.insert(pair<std::string, InnerModuleInfo>(MODULE_NAME, moduleInfo));
2138 std::string cpuAbi = "123";
2139 std::string nativeLibraryPath = "/data/test";
2140 AppqfInfo appQfInfo;
2141
2142 auto res = installer.UpdateLibAttrs(newInfo, cpuAbi, nativeLibraryPath, appQfInfo);
2143 EXPECT_EQ(res, ERR_OK);
2144 }
2145
2146 /**
2147 * @tc.number: baseBundleInstaller_3200
2148 * @tc.name: test InstallAppControl
2149 * @tc.desc: 1.Test the InstallAppControl of BaseBundleInstaller
2150 */
2151 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_3200, Function | SmallTest | Level0)
2152 {
2153 BaseBundleInstaller installer;
2154 std::string installAppId;
2155 int32_t userId = Constants::DEFAULT_USERID;;
2156 OHOS::ErrCode ret = installer.InstallNormalAppControl(installAppId, userId);
2157 EXPECT_EQ(ret, OHOS::ERR_OK);
2158 }
2159
2160 /**
2161 * @tc.number: BundleInstaller_3300
2162 * @tc.name: test InstallAppControl
2163 * @tc.desc: 1.Test the InstallAppControl of BaseBundleInstaller
2164 */
2165 HWTEST_F(BmsBundleInstallerTest, BundleInstaller_3300, Function | SmallTest | Level0)
2166 {
2167 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_MODULEJSON_TEST;
2168 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
2169 EXPECT_EQ(installResult, ERR_OK);
2170
2171 UnInstallBundle(BUNDLE_MODULEJSON_NAME);
2172 }
2173
2174 /**
2175 * @tc.number: baseBundleInstaller_3600
2176 * @tc.name: test ProcessNewModuleInstall
2177 * @tc.desc: 1.Test the ProcessNewModuleInstall
2178 */
2179 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_3600, Function | SmallTest | Level0)
2180 {
2181 BaseBundleInstaller installer;
2182 InnerBundleInfo oldInfo;
2183 InnerBundleInfo newInfo;
2184 InnerModuleInfo innerModuleInfo;
2185 innerModuleInfo.isEntry = true;
2186 newInfo.InsertInnerModuleInfo("", innerModuleInfo);
2187 oldInfo.InsertInnerModuleInfo("", innerModuleInfo);
2188 ErrCode res = installer.ProcessNewModuleInstall(newInfo, oldInfo);
2189 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_ENTRY_ALREADY_EXIST);
2190 }
2191
2192 /**
2193 * @tc.number: baseBundleInstaller_3700
2194 * @tc.name: test ProcessModuleUpdate
2195 * @tc.desc: 1.Test the ProcessModuleUpdate
2196 */
2197 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_3700, Function | SmallTest | Level0)
2198 {
2199 BaseBundleInstaller installer;
2200 InnerBundleInfo oldInfo;
2201 InnerBundleInfo newInfo;
2202 InnerModuleInfo innerModuleInfo;
2203 innerModuleInfo.isEntry = true;
2204 newInfo.InsertInnerModuleInfo("", innerModuleInfo);
2205 oldInfo.InsertInnerModuleInfo("", innerModuleInfo);
2206 installer.modulePackage_ = NOEXIST;
2207 ErrCode res = installer.ProcessModuleUpdate(newInfo, oldInfo, false, false);
2208 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_ENTRY_ALREADY_EXIST);
2209 }
2210
2211 /**
2212 * @tc.number: baseBundleInstaller_3800
2213 * @tc.name: test UpdateLibAttrs
2214 * @tc.desc: 1.Test the UpdateLibAttrs of BaseBundleInstaller
2215 */
2216 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_3800, Function | SmallTest | Level0)
2217 {
2218 BaseBundleInstaller installer;
2219 std::string nativeLibraryPath = "X86";
2220 std::string cpuAbi = "armeabi";
2221 InnerBundleInfo newInfo;
2222 newInfo.currentPackage_ = MODULE_NAME_TEST;
2223 AppqfInfo appQfInfo;
2224 ErrCode ret = installer.UpdateLibAttrs(
2225 newInfo, cpuAbi, nativeLibraryPath, appQfInfo);
2226 EXPECT_EQ(ret, ERR_OK);
2227 }
2228
2229 /**
2230 * @tc.number: baseBundleInstaller_3900
2231 * @tc.name: test UpdateLibAttrs
2232 * @tc.desc: 1.Test the UpdateLibAttrs of BaseBundleInstaller
2233 */
2234 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_3900, Function | SmallTest | Level0)
2235 {
2236 BaseBundleInstaller installer;
2237 InnerBundleInfo newInfo;
2238 newInfo.currentPackage_ = MODULE_NAME_TEST;
2239 ErrCode ret = installer.SetDirApl(newInfo);
2240 EXPECT_EQ(ret, ERR_OK);
2241 }
2242
2243 /**
2244 * @tc.number: baseBundleInstaller_4000
2245 * @tc.name: test CreateBundleDataDir
2246 * @tc.desc: 1.Test the CreateBundleDataDir
2247 */
2248 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_4000, Function | SmallTest | Level0)
2249 {
2250 BaseBundleInstaller installer;
2251 installer.dataMgr_ = GetBundleDataMgr();
2252 installer.userId_ = USERID;
2253 InnerBundleInfo info;
2254 ErrCode res = installer.CreateBundleDataDir(info);
2255 EXPECT_EQ(res, ERR_APPEXECFWK_USER_NOT_EXIST);
2256 }
2257
2258 /**
2259 * @tc.number: baseBundleInstaller_4100
2260 * @tc.name: test ExtractArkNativeFile
2261 * @tc.desc: 1.Test the ExtractArkNativeFile of BaseBundleInstaller
2262 */
2263 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_4100, Function | SmallTest | Level0)
2264 {
2265 BaseBundleInstaller installer;
2266 InnerBundleInfo info;
2267 std::string modulePath;
2268 info.SetArkNativeFilePath("///");
2269 ErrCode ret = installer.ExtractArkNativeFile(info, modulePath);
2270 EXPECT_EQ(ret, ERR_OK);
2271 }
2272
2273 /**
2274 * @tc.number: baseBundleInstaller_4200
2275 * @tc.name: test GetModuleNames
2276 * @tc.desc: 1.Test the GetModuleNames of BaseBundleInstaller
2277 */
2278 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_4200, Function | SmallTest | Level0)
2279 {
2280 BaseBundleInstaller installer;
2281 std::unordered_map<std::string, InnerBundleInfo> infos;
2282 std::string ret = installer.GetModuleNames(infos);
2283 EXPECT_EQ(ret, Constants::EMPTY_STRING);
2284 }
2285
2286 /**
2287 * @tc.number: baseBundleInstaller_6100
2288 * @tc.name: test ProcessBundleInstallNative
2289 * @tc.desc: 1.Test the ProcessBundleInstallNative
2290 */
2291 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_6100, Function | SmallTest | Level0)
2292 {
2293 BaseBundleInstaller installer;
2294 InnerBundleInfo info;
2295 int32_t userId = USERID;
2296 ErrCode res = installer.ProcessBundleInstallNative(info, userId);
2297 EXPECT_EQ(res, ERR_OK);
2298 }
2299
2300 /**
2301 * @tc.number: baseBundleInstaller_6200
2302 * @tc.name: test ProcessBundleUnInstallNative
2303 * @tc.desc: 1.Test the ProcessBundleUnInstallNative
2304 */
2305 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_6200, Function | SmallTest | Level0)
2306 {
2307 BaseBundleInstaller installer;
2308 InnerBundleInfo info;
2309 int32_t userId = USERID;
2310 std::string bundleName = "com.example.test";
2311 ErrCode res = installer.ProcessBundleUnInstallNative(info, userId, bundleName);
2312 EXPECT_EQ(res, ERR_OK);
2313 }
2314
2315 /**
2316 * @tc.number: InstalldHostImpl_0100
2317 * @tc.name: test CheckArkNativeFileWithOldInfo
2318 * @tc.desc: 1.Test the CreateBundleDir of InstalldHostImpl
2319 */
2320 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_0100, Function | SmallTest | Level0)
2321 {
2322 InstalldHostImpl impl;
2323 auto ret = impl.CreateBundleDir("");
2324 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2325 }
2326
2327 /**
2328 * @tc.number: InstalldHostImpl_0200
2329 * @tc.name: test CheckArkNativeFileWithOldInfo
2330 * @tc.desc: 1.Test the ExtractModuleFiles of InstalldHostImpl
2331 */
2332 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_0200, Function | SmallTest | Level0)
2333 {
2334 InstalldHostImpl impl;
2335 auto ret = impl.ExtractModuleFiles("", "", TEST_STRING, TEST_STRING);
2336 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2337
2338 ret = impl.ExtractModuleFiles("", TEST_STRING, TEST_STRING, TEST_STRING);
2339 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2340
2341 ret = impl.ExtractModuleFiles(TEST_STRING, "", TEST_STRING, TEST_STRING);
2342 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2343
2344 ret = impl.ExtractModuleFiles("wrong", TEST_STRING, "wrong", "wrong");
2345 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_DISK_MEM_INSUFFICIENT);
2346 }
2347
2348 /**
2349 * @tc.number: InstalldHostImpl_0300
2350 * @tc.name: test CheckArkNativeFileWithOldInfo
2351 * @tc.desc: 1.Test the RenameModuleDir of InstalldHostImpl
2352 */
2353 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_0300, Function | SmallTest | Level0)
2354 {
2355 InstalldHostImpl impl;
2356 auto ret = impl.RenameModuleDir("", "");
2357 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2358
2359 ret = impl.RenameModuleDir("", TEST_STRING);
2360 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2361
2362 ret = impl.RenameModuleDir(TEST_STRING, " ");
2363 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_RNAME_DIR_FAILED);
2364
2365 ret = impl.RenameModuleDir("wrong", "wrong");
2366 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_RNAME_DIR_FAILED);
2367
2368 ret = impl.RenameModuleDir(TEST_STRING, TEST_STRING);
2369 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_RNAME_DIR_FAILED);
2370 }
2371
2372 /**
2373 * @tc.number: InstalldHostImpl_0400
2374 * @tc.name: test CheckArkNativeFileWithOldInfo
2375 * @tc.desc: 1.Test the CreateBundleDataDir of InstalldHostImpl
2376 */
2377 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_0400, Function | SmallTest | Level0)
2378 {
2379 InstalldHostImpl impl;
2380 CreateDirParam createDirParam;
2381 createDirParam.bundleName = "";
2382 createDirParam.userId = INVAILD_CODE;
2383 createDirParam.uid = INVAILD_CODE;
2384 createDirParam.gid = INVAILD_CODE;
2385 createDirParam.apl = TEST_STRING;
2386 createDirParam.isPreInstallApp = false;
2387 auto ret = impl.CreateBundleDataDir(createDirParam);
2388 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2389 CreateDirParam createDirParam2;
2390 createDirParam2.bundleName = TEST_STRING;
2391 createDirParam2.userId = 99;
2392 createDirParam2.uid = ZERO_CODE;
2393 createDirParam2.gid = ZERO_CODE;
2394 createDirParam2.apl = TEST_STRING;
2395 createDirParam2.isPreInstallApp = false;
2396 ret = impl.CreateBundleDataDir(createDirParam2);
2397 EXPECT_EQ(ret, ERR_OK);
2398 }
2399
2400 /**
2401 * @tc.number: InstalldHostImpl_0500
2402 * @tc.name: test CheckArkNativeFileWithOldInfo
2403 * @tc.desc: 1.Test the RemoveBundleDataDir of InstalldHostImpl
2404 */
2405 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_0500, Function | SmallTest | Level0)
2406 {
2407 InstalldHostImpl impl;
2408
2409 auto ret = impl.RemoveBundleDataDir("", USERID);
2410 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2411
2412 ret = impl.RemoveBundleDataDir(TEST_STRING, INVAILD_CODE);
2413 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2414
2415 ret = impl.RemoveBundleDataDir("", INVAILD_CODE);
2416 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2417
2418 ret = impl.RemoveBundleDataDir(TEST_STRING, USERID);
2419 EXPECT_EQ(ret, ERR_OK);
2420 }
2421
2422 /**
2423 * @tc.number: InstalldHostImpl_0600
2424 * @tc.name: test CheckArkNativeFileWithOldInfo
2425 * @tc.desc: 1.Test the RemoveModuleDataDir of InstalldHostImpl
2426 */
2427 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_0600, Function | SmallTest | Level0)
2428 {
2429 InstalldHostImpl impl;
2430 auto ret = impl.RemoveModuleDataDir(TEST_STRING, INVAILD_CODE);
2431 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2432
2433 ret = impl.RemoveModuleDataDir("", USERID);
2434 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2435
2436 ret = impl.RemoveModuleDataDir("", INVAILD_CODE);
2437 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2438
2439 ret = impl.RemoveModuleDataDir(TEST_STRING, USERID);
2440 EXPECT_EQ(ret, ERR_OK);
2441 }
2442
2443 /**
2444 * @tc.number: InstalldHostImpl_0700
2445 * @tc.name: test CheckArkNativeFileWithOldInfo
2446 * @tc.desc: 1.Test the GetBundleCachePath of InstalldHostImpl
2447 */
2448 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_0700, Function | SmallTest | Level0)
2449 {
2450 InstalldHostImpl impl;
2451 std::vector<std::string> vec;
2452 auto ret = impl.GetBundleCachePath(TEST_STRING, vec);
2453 EXPECT_EQ(ret, ERR_OK);
2454
2455 ret = impl.GetBundleCachePath("", vec);
2456 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2457 }
2458
2459 /**
2460 * @tc.number: InstalldHostImpl_0800
2461 * @tc.name: test CheckArkNativeFileWithOldInfo
2462 * @tc.desc: 1.Test the Mkdir of InstalldHostImpl
2463 */
2464 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_0800, Function | SmallTest | Level0)
2465 {
2466 InstalldHostImpl impl;
2467 auto ret = impl.Mkdir("", ZERO_CODE, ZERO_CODE, ZERO_CODE);
2468 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2469 }
2470
2471 /**
2472 * @tc.number: InstalldHostImpl_0900
2473 * @tc.name: test CheckArkNativeFileWithOldInfo
2474 * @tc.desc: 1.Test the ExtractFiles of InstalldHostImpl
2475 */
2476 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_0900, Function | SmallTest | Level0)
2477 {
2478 InstalldHostImpl impl;
2479
2480 ExtractParam extractParam;
2481 auto ret = impl.ExtractFiles(extractParam);
2482 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2483
2484 extractParam.srcPath = "/data/app/el1/bundle/public/com.example.test/entry.hap";
2485 extractParam.targetPath = "/data/app/el1/bundle/public/com.example.test/";
2486 extractParam.cpuAbi = "arm64";
2487 extractParam.extractFileType = ExtractFileType::AN;
2488
2489 ret = impl.ExtractFiles(extractParam);
2490 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_DISK_MEM_INSUFFICIENT);
2491 }
2492
2493 /**
2494 * @tc.number: InstalldHostImpl_1000
2495 * @tc.name: test Install
2496 * @tc.desc: 1.Test the Install of BundleInstallerHost
2497 */
2498 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_1000, Function | SmallTest | Level0)
2499 {
2500 auto installer = DelayedSingleton<BundleMgrService>::GetInstance()->GetBundleInstaller();
2501 InstallParam installParam;
2502 bool ret = installer->Install("", installParam, nullptr);
2503 EXPECT_EQ(ret, false);
2504 std::vector<std::string> bundleFilePaths;
2505 ret = installer->Install(bundleFilePaths, installParam, nullptr);
2506 EXPECT_EQ(ret, false);
2507 }
2508
2509 /**
2510 * @tc.number: InstalldHostImpl_1100
2511 * @tc.name: test Install
2512 * @tc.desc: 1.Test the Uninstall of BundleInstallerHost
2513 */
2514 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_1100, Function | SmallTest | Level0)
2515 {
2516 auto installer = DelayedSingleton<BundleMgrService>::GetInstance()->GetBundleInstaller();
2517 InstallParam installParam;
2518 bool ret = installer->Uninstall("", "", installParam, nullptr);
2519 EXPECT_EQ(ret, false);
2520 ret = installer->InstallByBundleName("", installParam, nullptr);
2521 EXPECT_EQ(ret, false);
2522 }
2523
2524 /**
2525 * @tc.number: InstalldHostImpl_1200
2526 * @tc.name: test Install
2527 * @tc.desc: 1.Test the CheckBundleInstallerManager of BundleInstallerHost
2528 */
2529 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_1200, Function | SmallTest | Level0)
2530 {
2531 BundleInstallerHost bundleInstallerHost;
2532 sptr<IStatusReceiver> statusReceiver;
2533 bundleInstallerHost.manager_ = nullptr;
2534 bool ret = bundleInstallerHost.CheckBundleInstallerManager(statusReceiver);
2535 EXPECT_EQ(ret, false);
2536 }
2537
2538 /**
2539 * @tc.number: InstalldHostImpl_1300
2540 * @tc.name: test Install
2541 * @tc.desc: 1.Test the RemoveDir of InstalldHostImpl
2542 */
2543 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_1300, Function | SmallTest | Level0)
2544 {
2545 InstalldHostImpl impl;
2546 ErrCode ret = impl.RemoveDir("");
2547 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2548 }
2549
2550 /**
2551 * @tc.number: InstalldHostImpl_1400
2552 * @tc.name: test Install
2553 * @tc.desc: 1.Test the CleanBundleDataDir of InstalldHostImpl
2554 */
2555 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_1400, Function | SmallTest | Level0)
2556 {
2557 InstalldHostImpl impl;
2558 ErrCode ret = impl.CleanBundleDataDir("");
2559 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2560 }
2561
2562 /**
2563 * @tc.number: InstalldHostImpl_1500
2564 * @tc.name: test Install
2565 * @tc.desc: 1.Test the GetBundleStats of InstalldHostImpl
2566 */
2567 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_1500, Function | SmallTest | Level0)
2568 {
2569 InstalldHostImpl impl;
2570 std::vector<int64_t> bundleStats;
2571 ErrCode ret = impl.GetBundleStats("", USERID, bundleStats, 0);
2572 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2573 }
2574
2575 /**
2576 * @tc.number: InstalldHostImpl_1600
2577 * @tc.name: test Install
2578 * @tc.desc: 1.Test the GetBundleStats of InstalldHostImpl
2579 */
2580 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_1600, Function | SmallTest | Level0)
2581 {
2582 InstalldHostImpl impl;
2583 std::vector<std::string> paths;
2584 ErrCode ret = impl.ScanDir(
2585 "", ScanMode::SUB_FILE_ALL, ResultMode::ABSOLUTE_PATH, paths);
2586 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2587
2588 ret = impl.ScanDir(
2589 BUNDLE_DATA_DIR, ScanMode::SUB_FILE_ALL, ResultMode::ABSOLUTE_PATH, paths);
2590 EXPECT_EQ(ret, ERR_OK);
2591 }
2592
2593 /**
2594 * @tc.number: InstalldHostImpl_1700
2595 * @tc.name: test Install
2596 * @tc.desc: 1.Test the CopyFile of InstalldHostImpl
2597 */
2598 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_1700, Function | SmallTest | Level0)
2599 {
2600 InstalldHostImpl impl;
2601 std::vector<std::string> paths;
2602 ErrCode ret = impl.CopyFile("", "");
2603 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_COPY_FILE_FAILED);
2604 }
2605
2606 /**
2607 * @tc.number: InstalldHostImpl_1800
2608 * @tc.name: test Install
2609 * @tc.desc: 1.Test the ExtractHnpFiles of InstalldHostImpl
2610 */
2611 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_1800, Function | SmallTest | Level0)
2612 {
2613 InstalldHostImpl impl;
2614 std::string hnpPackageInfo;
2615 ExtractParam extractParam;
2616 auto ret = impl.ExtractHnpFiles(hnpPackageInfo, extractParam);
2617 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2618 }
2619
2620 /**
2621 * @tc.number: InstalldHostImpl_1900
2622 * @tc.name: test Install
2623 * @tc.desc: 1.Test the ProcessBundleInstallNative of InstalldHostImpl
2624 */
2625 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_1900, Function | SmallTest | Level0)
2626 {
2627 InstalldHostImpl impl;
2628 std::string userId = std::to_string(USERID);
2629 std::string hnpRootPath = "/data/app/el1/bundle/public/com.example.test/entry_tmp/hnp_tmp_extract_dir/";
2630 std::string hapPath = "/system/app/module01/module01.hap";
2631 std::string cpuAbi = "arm64";
2632 std::string packageName = "com.example.test";
2633 auto ret = impl.ProcessBundleInstallNative(userId, hnpRootPath, hapPath, cpuAbi, packageName);
2634 EXPECT_EQ(ret, ERR_APPEXECFWK_NATIVE_INSTALL_FAILED);
2635 }
2636
2637 /**
2638 * @tc.number: InstalldHostImpl_2000
2639 * @tc.name: test Install
2640 * @tc.desc: 1.Test the ProcessBundleInstallNative of InstalldHostImpl
2641 */
2642 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_2000, Function | SmallTest | Level0)
2643 {
2644 InstalldHostImpl impl;
2645 std::string userId = std::to_string(USERID);
2646 std::string packageName = "com.example.test";
2647 auto ret = impl.ProcessBundleUnInstallNative(userId, packageName);
2648 EXPECT_EQ(ret, ERR_OK);
2649 }
2650
2651 /**
2652 * @tc.number: ZipFile_0100
2653 * @tc.name: Test ZipFile
2654 * @tc.desc: 1.Test ParseEndDirectory of ZipFile
2655 */
2656 HWTEST_F(BmsBundleInstallerTest, ZipFile_0100, Function | SmallTest | Level1)
2657 {
2658 ZipFile file("/test.zip");
2659 ZipPos start = 0;
2660 size_t length = 0;
2661 file.SetContentLocation(start, length);
2662 bool ret = file.ParseEndDirectory();
2663 EXPECT_EQ(ret, false);
2664
2665 std::string maxFileName = std::string(256, 'a');
2666 maxFileName.append(".zip");
2667 file.pathName_ = maxFileName;
2668 ret = file.Open();
2669 EXPECT_EQ(ret, false);
2670
2671 file.pathName_ = "/test.zip";
2672 file.isOpen_ = true;
2673 ret = file.Open();
2674 EXPECT_EQ(ret, true);
2675
2676 ret = file.IsDirExist("");
2677 EXPECT_EQ(ret, false);
2678
2679 ret = file.IsDirExist("/test.zip");
2680 EXPECT_EQ(ret, false);
2681 }
2682
2683 /**
2684 * @tc.number: ZipFile_0200
2685 * @tc.name: Test ZipFile
2686 * @tc.desc: 1.Test open file, file name is bigger than PATH_MAX
2687 */
2688 HWTEST_F(BmsBundleInstallerTest, ZipFile_0200, Function | SmallTest | Level1)
2689 {
2690 ZipFile file("/test.zip");
2691 ZipPos start = 0;
2692 size_t length = 0;
2693 file.SetContentLocation(start, length);
2694 bool ret = file.ParseEndDirectory();
2695 EXPECT_EQ(ret, false);
2696
2697 std::string maxFileName = std::string(4096, 'a');
2698 maxFileName.append(".zip");
2699 file.pathName_ = maxFileName;
2700 ret = file.Open();
2701 EXPECT_EQ(ret, false);
2702 }
2703
2704 /**
2705 * @tc.number: ZipFile_0300
2706 * @tc.name: Test ZipFile
2707 * @tc.desc: 1.Test CheckCoherencyLocalHeader
2708 */
2709 HWTEST_F(BmsBundleInstallerTest, ZipFile_0300, Function | SmallTest | Level1)
2710 {
2711 ZipFile file("/test.zip");
2712 ZipEntry zipEntry;
2713 zipEntry.localHeaderOffset = -1;
2714 uint16_t extraSize = 0;
2715 bool ret = file.CheckCoherencyLocalHeader(zipEntry, extraSize);
2716 EXPECT_EQ(ret, false);
2717 }
2718
2719 /**
2720 * @tc.number: ZipFile_0400
2721 * @tc.name: Test ZipFile
2722 * @tc.desc: 1.Test SeekToEntryStart
2723 */
2724 HWTEST_F(BmsBundleInstallerTest, ZipFile_0400, Function | SmallTest | Level1)
2725 {
2726 ZipFile file("/test.zip");
2727 ZipEntry zipEntry;
2728 zipEntry.localHeaderOffset = 1;
2729 uint16_t extraSize = 0;
2730 bool ret = file.SeekToEntryStart(zipEntry, extraSize);
2731 EXPECT_EQ(ret, false);
2732 }
2733
2734 /**
2735 * @tc.number: ZipFile_0500
2736 * @tc.name: Test ZipFile
2737 * @tc.desc: 1.Test GetAllEntries
2738 */
2739 HWTEST_F(BmsBundleInstallerTest, ZipFile_0500, Function | SmallTest | Level1)
2740 {
2741 ZipFile file("/test.zip");
2742 ZipEntryMap ret = file.GetAllEntries();
2743 EXPECT_EQ(ret.size(), 0);
2744 }
2745
2746 /**
2747 * @tc.number: ZipFile_0600
2748 * @tc.name: Test ZipFile
2749 * @tc.desc: 1.Test HasEntry
2750 */
2751 HWTEST_F(BmsBundleInstallerTest, ZipFile_0600, Function | SmallTest | Level1)
2752 {
2753 ZipFile file("/test.zip");
2754
2755 std::string entryName = "entryName";
2756 bool ret = file.HasEntry(entryName);
2757 EXPECT_EQ(ret, false);
2758 }
2759
2760 /**
2761 * @tc.number: ZipFile_0700
2762 * @tc.name: Test ZipFile
2763 * @tc.desc: 1.Test GetEntry
2764 */
2765 HWTEST_F(BmsBundleInstallerTest, ZipFile_0700, Function | SmallTest | Level1)
2766 {
2767 ZipFile file("/test.zip");
2768
2769 std::string entryName = "entryName";
2770 ZipEntry resultEntry;
2771 bool ret = file.GetEntry(entryName, resultEntry);
2772 EXPECT_EQ(ret, false);
2773 }
2774
2775 /**
2776 * @tc.number: ZipFile_0800
2777 * @tc.name: Test ZipFile
2778 * @tc.desc: 1.Test GetDataOffsetRelative
2779 */
2780 HWTEST_F(BmsBundleInstallerTest, ZipFile_0800, Function | SmallTest | Level1)
2781 {
2782 ZipFile file("/test.zip");
2783
2784 std::string f = "test.file";
2785 ZipPos offset;
2786 uint32_t length = 100;
2787 bool ret = file.GetDataOffsetRelative(f, offset, length);
2788 EXPECT_EQ(ret, false);
2789 }
2790
2791 /**
2792 * @tc.number: ZipFile_0900
2793 * @tc.name: Test ZipFile
2794 * @tc.desc: 1.Test CheckEndDir
2795 */
2796 HWTEST_F(BmsBundleInstallerTest, ZipFile_0900, Function | SmallTest | Level1)
2797 {
2798 ZipFile file("/test.zip");
2799
2800 EndDir endDir;
2801 bool ret = file.CheckEndDir(endDir);
2802 EXPECT_EQ(ret, false);
2803 }
2804
2805 /**
2806 * @tc.number: ZipFile_1000
2807 * @tc.name: Test ZipFile
2808 * @tc.desc: 1.Test ParseAllEntries
2809 */
2810 HWTEST_F(BmsBundleInstallerTest, ZipFile_1000, Function | SmallTest | Level1)
2811 {
2812 ZipFile file("/test.zip");
2813
2814 bool ret = file.ParseAllEntries();
2815 EXPECT_EQ(ret, true);
2816 }
2817
2818 /**
2819 * @tc.number: ZipFile_1100
2820 * @tc.name: Test ZipFile
2821 * @tc.desc: 1.Test GetLocalHeaderSize
2822 */
2823 HWTEST_F(BmsBundleInstallerTest, ZipFile_1100, Function | SmallTest | Level1)
2824 {
2825 ZipFile file("/test.zip");
2826
2827 uint16_t nameSize = 100;
2828 uint16_t extraSize = 100;
2829 size_t ret = file.GetLocalHeaderSize(nameSize, extraSize);
2830 EXPECT_NE(ret, 0);
2831 }
2832
2833 /**
2834 * @tc.number: ZipFile_1200
2835 * @tc.name: Test ZipFile
2836 * @tc.desc: 1.Test GetEntryDataOffset
2837 */
2838 HWTEST_F(BmsBundleInstallerTest, ZipFile_1200, Function | SmallTest | Level1)
2839 {
2840 ZipFile file("/test.zip");
2841
2842 ZipEntry zipEntry;
2843 uint16_t extraSize = 100;
2844 ZipPos ret = file.GetEntryDataOffset(zipEntry, extraSize);
2845 EXPECT_NE(ret, 0);
2846 }
2847
2848 /**
2849 * @tc.number: ZipFile_1300
2850 * @tc.name: Test ZipFile
2851 * @tc.desc: 1.Test CheckDataDesc
2852 */
2853 HWTEST_F(BmsBundleInstallerTest, ZipFile_1300, Function | SmallTest | Level1)
2854 {
2855 ZipFile file("/test.zip");
2856
2857 ZipEntry zipEntry;
2858 LocalHeader localHeader;
2859 bool ret = file.CheckDataDesc(zipEntry, localHeader);
2860 EXPECT_EQ(ret, true);
2861 }
2862
2863 /**
2864 * @tc.number: ZipFile_1400
2865 * @tc.name: Test ZipFile
2866 * @tc.desc: 1.Test InitZStream
2867 */
2868 HWTEST_F(BmsBundleInstallerTest, ZipFile_1400, Function | SmallTest | Level1)
2869 {
2870 ZipFile file("/test.zip");
2871
2872 z_stream zstream;
2873 bool ret = file.InitZStream(zstream);
2874 EXPECT_EQ(ret, true);
2875 }
2876
2877 /**
2878 * @tc.number: BaseExtractor_0100
2879 * @tc.name: Test HasEntry
2880 * @tc.desc: 1.Test HasEntry of BaseExtractor
2881 */
2882 HWTEST_F(BmsBundleInstallerTest, BaseExtractor_0100, Function | SmallTest | Level1)
2883 {
2884 BaseExtractor extractor("file.zip");
2885 extractor.initial_ = false;
2886 bool ret = extractor.HasEntry("entry");
2887 EXPECT_EQ(ret, false);
2888
2889 extractor.initial_ = true;
2890 ret = extractor.HasEntry("");
2891 EXPECT_EQ(ret, false);
2892 }
2893
2894 /**
2895 * @tc.number: BaseExtractor_0200
2896 * @tc.name: Test HasEntry
2897 * @tc.desc: 1.Test HasEntry of BaseExtractor
2898 */
2899 HWTEST_F(BmsBundleInstallerTest, BaseExtractor_0200, Function | SmallTest | Level1)
2900 {
2901 BaseExtractor extractor("file.zip");
2902 bool ret = extractor.ExtractFile("entry", "/data/test");
2903 EXPECT_EQ(ret, false);
2904 }
2905
2906 /**
2907 * @tc.number: BaseExtractor_0300
2908 * @tc.name: Test HasEntry
2909 * @tc.desc: 1.Test HasEntry of BaseExtractor
2910 */
2911 HWTEST_F(BmsBundleInstallerTest, BaseExtractor_0300, Function | SmallTest | Level1)
2912 {
2913 BaseExtractor extractor("file.zip");
2914 uint32_t offset = 1;
2915 uint32_t length = 10;
2916 bool ret = extractor.GetFileInfo("bootpic.zip", offset, length);
2917 EXPECT_EQ(ret, false);
2918 }
2919
2920 /**
2921 * @tc.number: BaseExtractor_0400
2922 * @tc.name: Test HasEntry
2923 * @tc.desc: 1.Test HasEntry of BaseExtractor
2924 */
2925 HWTEST_F(BmsBundleInstallerTest, BaseExtractor_0400, Function | SmallTest | Level1)
2926 {
2927 BaseExtractor extractor("/system/etc/graphic/bootpic.zip");
2928 extractor.initial_ = true;
2929 uint32_t offset = 1;
2930 uint32_t length = 10;
2931 bool ret = extractor.GetFileInfo("bootpic.zip", offset, length);
2932 EXPECT_EQ(ret, false);
2933 }
2934
2935 /**
2936 * @tc.number: BaseExtractor_0500
2937 * @tc.name: Test Init
2938 * @tc.desc: 1.Test Init of BaseExtractor
2939 */
2940 HWTEST_F(BmsBundleInstallerTest, BaseExtractor_0500, Function | SmallTest | Level1)
2941 {
2942 BaseExtractor extractor("/system/etc/graphic/bootpic.zip");
2943
2944 bool ret = extractor.Init();
2945 EXPECT_EQ(ret, true);
2946 }
2947
2948 /**
2949 * @tc.number: BaseExtractor_0600
2950 * @tc.name: Test GetZipFileNames
2951 * @tc.desc: 1.Test GetZipFileNames of BaseExtractor
2952 */
2953 HWTEST_F(BmsBundleInstallerTest, BaseExtractor_0600, Function | SmallTest | Level1)
2954 {
2955 BaseExtractor extractor("/system/etc/graphic/bootpic.zip");
2956
2957 std::vector<std::string> fileNames;
2958 fileNames.push_back("test1.zip");
2959 fileNames.push_back("test2.zip");
2960 bool ret = extractor.GetZipFileNames(fileNames);
2961 EXPECT_EQ(ret, true);
2962 }
2963
2964 /**
2965 * @tc.number: BaseExtractor_0700
2966 * @tc.name: Test IsDirExist
2967 * @tc.desc: 1.Test IsDirExist of BaseExtractor
2968 */
2969 HWTEST_F(BmsBundleInstallerTest, BaseExtractor_0700, Function | SmallTest | Level1)
2970 {
2971 BaseExtractor extractor("/system/etc/graphic/bootpic.zip");
2972 extractor.initial_ = false;
2973
2974 std::string dir = "/data";
2975 bool ret = extractor.IsDirExist(dir);
2976 EXPECT_EQ(ret, false);
2977
2978 dir = "";
2979 ret = extractor.IsDirExist(dir);
2980 EXPECT_EQ(ret, false);
2981
2982 extractor.initial_ = true;
2983 dir = "/data";
2984 ret = extractor.IsDirExist(dir);
2985 EXPECT_EQ(ret, false);
2986 }
2987
2988 /**
2989 * @tc.number: BaseExtractor_0800
2990 * @tc.name: Test IsStageBasedModel
2991 * @tc.desc: 1.Test IsStageBasedModel of BaseExtractor
2992 */
2993 HWTEST_F(BmsBundleInstallerTest, BaseExtractor_0800, Function | SmallTest | Level1)
2994 {
2995 BaseExtractor extractor("/system/etc/graphic/bootpic.zip");
2996 extractor.initial_ = false;
2997
2998 std::string abilityName = "EntryAbility";
2999 bool ret = extractor.IsStageBasedModel(abilityName);
3000 EXPECT_EQ(ret, false);
3001 }
3002
3003 /**
3004 * @tc.number: BaseExtractor_0900
3005 * @tc.name: Test IsNewVersion
3006 * @tc.desc: 1.Test IsNewVersion of BaseExtractor
3007 */
3008 HWTEST_F(BmsBundleInstallerTest, BaseExtractor_0900, Function | SmallTest | Level1)
3009 {
3010 BaseExtractor extractor("/system/etc/graphic/bootpic.zip");
3011
3012 bool ret = extractor.IsNewVersion();
3013 EXPECT_EQ(ret, true);
3014 }
3015
3016 /**
3017 * @tc.number: InstallFailed_0100
3018 * @tc.name: Test CheckHapHashParams
3019 * @tc.desc: 1.Test CheckHapHashParams of BundleInstallChecker
3020 */
3021 HWTEST_F(BmsBundleInstallerTest, InstallFailed_0100, Function | SmallTest | Level1)
3022 {
3023 BundleInstallChecker installChecker;
3024 std::vector<std::string> bundlePaths;
3025 ErrCode ret = installChecker.CheckSysCap(bundlePaths);
3026 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_PARAM_ERROR);
3027
3028 std::map<std::string, std::string> hashParams;
3029 hashParams.try_emplace("entry", "hashValue");
3030 std::unordered_map<std::string, InnerBundleInfo> infos;
3031 ret = installChecker.CheckHapHashParams(infos, hashParams);
3032 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_FAILED_CHECK_HAP_HASH_PARAM);
3033
3034 InnerBundleInfo innerBundleInfo;
3035 infos.try_emplace("hashParam", innerBundleInfo);
3036 ret = installChecker.CheckHapHashParams(infos, hashParams);
3037 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_FAILED_MODULE_NAME_EMPTY);
3038
3039 InnerModuleInfo innerModuleInfo;
3040 innerModuleInfo.moduleName = "entry";
3041 innerBundleInfo.innerModuleInfos_.clear();
3042 innerBundleInfo.innerModuleInfos_.try_emplace("module1", innerModuleInfo);
3043 innerBundleInfo.innerModuleInfos_.try_emplace("module1", innerModuleInfo);
3044 infos.clear();
3045 infos.try_emplace("hashParam", innerBundleInfo);
3046 ret = installChecker.CheckHapHashParams(infos, hashParams);
3047 EXPECT_EQ(ret, ERR_OK);
3048 }
3049
3050 /**
3051 * @tc.number: InstallChecker_0100
3052 * @tc.name: test the start function of CheckSysCap
3053 * @tc.desc: 1. BundleInstallChecker
3054 */
3055 HWTEST_F(BmsBundleInstallerTest, InstallChecker_0100, Function | SmallTest | Level0)
3056 {
3057 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
3058 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
3059 EXPECT_EQ(installResult, ERR_OK);
3060
3061 std::vector<std::string> bundlePaths;
3062 bundlePaths.push_back(bundlePath);
3063 BundleInstallChecker installChecker;
3064 auto ret = installChecker.CheckSysCap(bundlePaths);
3065 EXPECT_EQ(ret, ERR_OK);
3066
3067 UnInstallBundle(BUNDLE_BACKUP_NAME);
3068 }
3069
3070 /**
3071 * @tc.number: InstallChecker_0200
3072 * @tc.name: test the start function of CheckSysCap
3073 * @tc.desc: 1. BundleInstallChecker
3074 */
3075 HWTEST_F(BmsBundleInstallerTest, InstallChecker_0200, Function | SmallTest | Level0)
3076 {
3077 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST + "rpcid.sc";
3078 std::vector<std::string> bundlePaths;
3079 bundlePaths.push_back(bundlePath);
3080 BundleInstallChecker installChecker;
3081 auto ret = installChecker.CheckSysCap(bundlePaths);
3082 EXPECT_EQ(ret, ERR_APPEXECFWK_PARSE_UNEXPECTED);
3083 }
3084
3085 /**
3086 * @tc.number: InstallChecker_0300
3087 * @tc.name: test the start function of CheckMultipleHapsSignInfo
3088 * @tc.desc: 1. BundleInstallChecker
3089 */
3090 HWTEST_F(BmsBundleInstallerTest, InstallChecker_0300, Function | SmallTest | Level0)
3091 {
3092 std::vector<std::string> bundlePaths;
3093 bundlePaths.push_back("data");
3094 std::vector<Security::Verify::HapVerifyResult> hapVerifyRes;
3095 Security::Verify::HapVerifyResult hapVerifyResult;
3096 hapVerifyResult.GetProvisionInfo().appId = "8519754";
3097 hapVerifyRes.emplace_back(hapVerifyResult);
3098 BundleInstallChecker installChecker;
3099 auto ret = installChecker.CheckMultipleHapsSignInfo(bundlePaths, hapVerifyRes);
3100 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_FAILED_INVALID_SIGNATURE_FILE_PATH);
3101 }
3102
3103 /**
3104 * @tc.number: InstallChecker_0400
3105 * @tc.name: test the start function of CheckDependency
3106 * @tc.desc: 1. BundleInstallChecker
3107 */
3108 HWTEST_F(BmsBundleInstallerTest, InstallChecker_0400, Function | SmallTest | Level0)
3109 {
3110 std::unordered_map<std::string, InnerBundleInfo> infos;
3111 BundleInstallChecker installChecker;
3112 auto ret = installChecker.CheckDependency(infos);
3113 EXPECT_EQ(ret, ERR_OK);
3114
3115 InnerBundleInfo innerBundleInfo;
3116 ApplicationInfo applicationInfo;
3117 applicationInfo.bundleName = "moduleName";
3118 innerBundleInfo.SetBaseApplicationInfo(applicationInfo);
3119 InnerModuleInfo innerModuleInfo;
3120 innerModuleInfo.moduleName = "moduleName";
3121 Dependency dependency;
3122 dependency.moduleName = "moduleName";
3123 dependency.bundleName = "bundleName";
3124 innerModuleInfo.dependencies.push_back(dependency);
3125 innerBundleInfo.innerModuleInfos_.insert(
3126 pair<std::string, InnerModuleInfo>("moduleName", innerModuleInfo));
3127 infos.insert(pair<std::string, InnerBundleInfo>("moduleName", innerBundleInfo));
3128
3129 ret = installChecker.CheckDependency(infos);
3130 EXPECT_EQ(ret, ERR_OK);
3131 }
3132
3133 /**
3134 * @tc.number: InstallChecker_0500
3135 * @tc.name: test the start function of NeedCheckDependency
3136 * @tc.desc: 1. BundleInstallChecker
3137 */
3138 HWTEST_F(BmsBundleInstallerTest, InstallChecker_0500, Function | SmallTest | Level0)
3139 {
3140 BundleInstallChecker installChecker;
3141 InnerBundleInfo innerBundleInfo;
3142 ApplicationInfo applicationInfo;
3143 applicationInfo.bundleName = "bundleName1";
3144 innerBundleInfo.SetBaseApplicationInfo(applicationInfo);
3145 Dependency dependency;
3146 dependency.bundleName = "bundleName2";
3147 auto ret = installChecker.NeedCheckDependency(dependency, innerBundleInfo);
3148 EXPECT_EQ(ret, false);
3149 BundlePackInfo bundlePackInfo;
3150 PackageModule packageModule;
3151 bundlePackInfo.summary.modules.push_back(packageModule);
3152 innerBundleInfo.SetBundlePackInfo(bundlePackInfo);
3153 ret = installChecker.NeedCheckDependency(dependency, innerBundleInfo);
3154 EXPECT_EQ(ret, false);
3155 }
3156
3157 /**
3158 * @tc.number: InstallChecker_0600
3159 * @tc.name: test the start function of FindModuleInInstallingPackage
3160 * @tc.desc: 1. BundleInstallChecker
3161 */
3162 HWTEST_F(BmsBundleInstallerTest, InstallChecker_0600, Function | SmallTest | Level0)
3163 {
3164 std::unordered_map<std::string, InnerBundleInfo> infos;
3165
3166 BundleInstallChecker installChecker;
3167 auto ret = installChecker.FindModuleInInstallingPackage("moduleName", "bundleName", infos);
3168 EXPECT_EQ(ret, false);
3169
3170 InnerBundleInfo innerBundleInfo;
3171 ApplicationInfo applicationInfo;
3172 applicationInfo.bundleName = "bundleName";
3173 innerBundleInfo.SetBaseApplicationInfo(applicationInfo);
3174 InnerModuleInfo innerModuleInfo;
3175 innerModuleInfo.moduleName = "moduleName";
3176 innerBundleInfo.innerModuleInfos_.insert(
3177 pair<std::string, InnerModuleInfo>("moduleName", innerModuleInfo));
3178 infos.insert(pair<std::string, InnerBundleInfo>("moduleName", innerBundleInfo));
3179 ret = installChecker.FindModuleInInstallingPackage("moduleName", "bundleName", infos);
3180 EXPECT_EQ(ret, true);
3181 }
3182
3183 /**
3184 * @tc.number: InstallChecker_0700
3185 * @tc.name: test the start function of FindModuleInInstalledPackage
3186 * @tc.desc: 1. BundleInstallChecker
3187 */
3188 HWTEST_F(BmsBundleInstallerTest, InstallChecker_0700, Function | SmallTest | Level0)
3189 {
3190 BundleInstallChecker installChecker;
3191 auto ret = installChecker.FindModuleInInstalledPackage("", "", 0);
3192 EXPECT_EQ(ret, false);
3193 ret = installChecker.FindModuleInInstalledPackage("moduleName", "moduleName", 0);
3194 EXPECT_EQ(ret, false);
3195 }
3196
3197 /**
3198 * @tc.number: InstallChecker_0800
3199 * @tc.name: test the start function of ParseBundleInfo
3200 * @tc.desc: 1. BundleInstallChecker
3201 */
3202 HWTEST_F(BmsBundleInstallerTest, InstallChecker_0800, Function | SmallTest | Level0)
3203 {
3204 BundleInstallChecker installChecker;
3205 InnerBundleInfo info;
3206 BundlePackInfo packInfo;
3207 auto ret = installChecker.ParseBundleInfo("", info, packInfo);
3208 EXPECT_EQ(ret, ERR_APPEXECFWK_PARSE_UNEXPECTED);
3209 }
3210
3211 /**
3212 * @tc.number: InstallChecker_0900
3213 * @tc.name: test the start function of CheckDeviceType
3214 * @tc.desc: 1. BundleInstallChecker
3215 */
3216 HWTEST_F(BmsBundleInstallerTest, InstallChecker_0900, Function | SmallTest | Level0)
3217 {
3218 BundleInstallChecker installChecker;
3219 std::unordered_map<std::string, InnerBundleInfo> infos;
3220 infos.clear();
3221 auto ret = installChecker.CheckDeviceType(infos);
3222 EXPECT_EQ(ret, ERR_OK);
3223 }
3224
3225 /**
3226 * @tc.number: InstallChecker_1000
3227 * @tc.name: test the start function of CheckBundleName
3228 * @tc.desc: 1. BundleInstallChecker
3229 */
3230 HWTEST_F(BmsBundleInstallerTest, InstallChecker_1000, Function | SmallTest | Level0)
3231 {
3232 BundleInstallChecker installChecker;
3233 std::string provisionBundleName;
3234 auto ret = installChecker.CheckBundleName("", "");
3235 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_FAILED_BUNDLE_SIGNATURE_VERIFICATION_FAILURE);
3236 }
3237
3238 /**
3239 * @tc.number: InstallChecker_1100
3240 * @tc.name: test the start function of CheckBundleName
3241 * @tc.desc: 1. BundleInstallChecker
3242 */
3243 HWTEST_F(BmsBundleInstallerTest, InstallChecker_1100, Function | SmallTest | Level0)
3244 {
3245 BundleInstallChecker installChecker;
3246 std::string provisionBundleName = BUNDLE_NAME;
3247 auto ret = installChecker.CheckBundleName(provisionBundleName, "");
3248 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_FAILED_BUNDLE_SIGNATURE_VERIFICATION_FAILURE);
3249 }
3250
3251 /**
3252 * @tc.number: InstallChecker_1200
3253 * @tc.name: test the start function of CheckBundleName
3254 * @tc.desc: 1. BundleInstallChecker
3255 */
3256 HWTEST_F(BmsBundleInstallerTest, InstallChecker_1200, Function | SmallTest | Level0)
3257 {
3258 BundleInstallChecker installChecker;
3259 std::string provisionBundleName = BUNDLE_NAME;
3260 auto ret = installChecker.CheckBundleName(provisionBundleName, BUNDLE_NAME);
3261 EXPECT_EQ(ret, ERR_OK);
3262 }
3263
3264 /**
3265 * @tc.number: InstallChecker_1300
3266 * @tc.name: test the start function of CheckBundleName
3267 * @tc.desc: 1. BundleInstallChecker
3268 */
3269 HWTEST_F(BmsBundleInstallerTest, InstallChecker_1300, Function | SmallTest | Level0)
3270 {
3271 BundleInstallChecker installChecker;
3272 auto ret = installChecker.CheckBundleName("", BUNDLE_NAME);
3273 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_FAILED_BUNDLE_SIGNATURE_VERIFICATION_FAILURE);
3274 }
3275
3276 /**
3277 * @tc.number: InstallChecker_1400
3278 * @tc.name: test the start function of VaildInstallPermission
3279 * @tc.desc: 1. BundleInstallChecker
3280 */
3281 HWTEST_F(BmsBundleInstallerTest, InstallChecker_1400, Function | SmallTest | Level0)
3282 {
3283 BundleInstallChecker installChecker;
3284 InstallParam installParam;
3285 installParam.isCallByShell = true;
3286 std::vector<Security::Verify::HapVerifyResult> hapVerifyRes;
3287 bool ret = installChecker.VaildInstallPermission(installParam, hapVerifyRes);
3288 EXPECT_EQ(ret, true);
3289 }
3290
3291 /**
3292 * @tc.number: InstallChecker_1500
3293 * @tc.name: test the start function of VaildInstallPermission
3294 * @tc.desc: 1. BundleInstallChecker
3295 */
3296 HWTEST_F(BmsBundleInstallerTest, InstallChecker_1500, Function | SmallTest | Level0)
3297 {
3298 BundleInstallChecker installChecker;
3299 InstallParam installParam;
3300 installParam.isCallByShell = false;
3301 std::vector<Security::Verify::HapVerifyResult> hapVerifyRes;
3302 bool ret = installChecker.VaildInstallPermission(installParam, hapVerifyRes);
3303 EXPECT_EQ(ret, true);
3304 installParam.installBundlePermissionStatus = PermissionStatus::HAVE_PERMISSION_STATUS;
3305 ret = installChecker.VaildInstallPermission(installParam, hapVerifyRes);
3306 EXPECT_EQ(ret, true);
3307 installParam.installEnterpriseBundlePermissionStatus = PermissionStatus::HAVE_PERMISSION_STATUS;
3308 ret = installChecker.VaildInstallPermission(installParam, hapVerifyRes);
3309 EXPECT_EQ(ret, true);
3310 }
3311
3312 /**
3313 * @tc.number: InstallChecker_1600
3314 * @tc.name: test the start function of VaildInstallPermission
3315 * @tc.desc: 1. BundleInstallChecker
3316 */
3317 HWTEST_F(BmsBundleInstallerTest, InstallChecker_1600, Function | SmallTest | Level0)
3318 {
3319 BundleInstallChecker installChecker;
3320 InstallParam installParam;
3321 installParam.isCallByShell = true;
3322 std::vector<Security::Verify::HapVerifyResult> hapVerifyRes;
3323 Security::Verify::HapVerifyResult result;
3324 Security::Verify::ProvisionInfo info;
3325 info.distributionType = Security::Verify::AppDistType::ENTERPRISE;
3326 info.type = Security::Verify::ProvisionType::DEBUG;
3327 result.SetProvisionInfo(info);
3328 bool ret = installChecker.VaildInstallPermission(installParam, hapVerifyRes);
3329 EXPECT_EQ(ret, true);
3330 }
3331
3332 /**
3333 * @tc.number: InstallChecker_1700
3334 * @tc.name: test the start function of VaildInstallPermission
3335 * @tc.desc: 1. BundleInstallChecker
3336 */
3337 HWTEST_F(BmsBundleInstallerTest, InstallChecker_1700, Function | SmallTest | Level0)
3338 {
3339 BundleInstallChecker installChecker;
3340 InstallParam installParam;
3341 installParam.isCallByShell = true;
3342 installParam.installEnterpriseBundlePermissionStatus = PermissionStatus::NON_HAVE_PERMISSION_STATUS;
3343 std::vector<Security::Verify::HapVerifyResult> hapVerifyRes;
3344 Security::Verify::HapVerifyResult result;
3345 Security::Verify::ProvisionInfo info;
3346 info.distributionType = Security::Verify::AppDistType::ENTERPRISE;
3347 info.type = Security::Verify::ProvisionType::RELEASE;
3348 result.SetProvisionInfo(info);
3349 hapVerifyRes.emplace_back(result);
3350 bool ret = installChecker.VaildInstallPermission(installParam, hapVerifyRes);
3351 EXPECT_EQ(ret, false);
3352 }
3353
3354 /**
3355 * @tc.number: InstallChecker_1800
3356 * @tc.name: test the start function of VaildInstallPermission
3357 * @tc.desc: 1. BundleInstallChecker
3358 */
3359 HWTEST_F(BmsBundleInstallerTest, InstallChecker_1800, Function | SmallTest | Level0)
3360 {
3361 BundleInstallChecker installChecker;
3362 InstallParam installParam;
3363 installParam.isCallByShell = true;
3364 std::vector<Security::Verify::HapVerifyResult> hapVerifyRes;
3365 Security::Verify::HapVerifyResult result;
3366 hapVerifyRes.emplace_back(result);
3367 bool ret = installChecker.VaildInstallPermission(installParam, hapVerifyRes);
3368 EXPECT_EQ(ret, false);
3369 }
3370
3371 /**
3372 * @tc.number: InstallChecker_1900
3373 * @tc.name: test the start function of VaildInstallPermission
3374 * @tc.desc: 1. BundleInstallChecker
3375 */
3376 HWTEST_F(BmsBundleInstallerTest, InstallChecker_1900, Function | SmallTest | Level0)
3377 {
3378 BundleInstallChecker installChecker;
3379 InstallParam installParam;
3380 installParam.isCallByShell = false;
3381 std::vector<Security::Verify::HapVerifyResult> hapVerifyRes;
3382 Security::Verify::HapVerifyResult result;
3383 Security::Verify::ProvisionInfo info;
3384 info.distributionType = Security::Verify::AppDistType::ENTERPRISE;
3385 result.SetProvisionInfo(info);
3386 hapVerifyRes.emplace_back(result);
3387 bool ret = installChecker.VaildInstallPermission(installParam, hapVerifyRes);
3388 EXPECT_EQ(ret, false);
3389 }
3390
3391 /**
3392 * @tc.number: InstallChecker_2000
3393 * @tc.name: test the start function of ParseHapFiles
3394 * @tc.desc: 1. BundleInstallChecker
3395 */
3396 HWTEST_F(BmsBundleInstallerTest, InstallChecker_2000, Function | SmallTest | Level0)
3397 {
3398 BundleInstallChecker installChecker;
3399 std::vector<std::string> bundlePaths;
3400 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
3401 bundlePaths.push_back(bundlePath);
3402
3403 InstallCheckParam checkParam;
3404
3405 std::vector<Security::Verify::HapVerifyResult> hapVerifyRes;
3406 Security::Verify::HapVerifyResult result;
3407 Security::Verify::ProvisionInfo info;
3408 info.distributionType = Security::Verify::AppDistType::ENTERPRISE;
3409 info.type = Security::Verify::ProvisionType::RELEASE;
3410 info.bundleInfo.appFeature = "hos_system_app";
3411 info.bundleInfo.bundleName = BUNDLE_BACKUP_NAME;
3412 result.SetProvisionInfo(info);
3413 hapVerifyRes.emplace_back(result);
3414
3415 std::unordered_map<std::string, InnerBundleInfo> infos;
3416 InnerBundleInfo innerBundleInfo;
3417 ApplicationInfo applicationInfo;
3418 applicationInfo.bundleName = BUNDLE_BACKUP_NAME;
3419 innerBundleInfo.SetBaseApplicationInfo(applicationInfo);
3420 InnerModuleInfo innerModuleInfo;
3421 innerModuleInfo.moduleName = "moduleName";
3422 innerBundleInfo.innerModuleInfos_.insert(
3423 pair<std::string, InnerModuleInfo>("moduleName", innerModuleInfo));
3424 infos.insert(pair<std::string, InnerBundleInfo>("moduleName", innerBundleInfo));
3425
3426 auto ret = installChecker.ParseHapFiles(bundlePaths, checkParam, hapVerifyRes, infos);
3427 EXPECT_EQ(ret, ERR_OK);
3428 }
3429
3430 /**
3431 * @tc.number: InstallChecker_2100
3432 * @tc.name: test the start function of ParseHapFiles
3433 * @tc.desc: 1. BundleInstallChecker
3434 */
3435 HWTEST_F(BmsBundleInstallerTest, InstallChecker_2100, Function | SmallTest | Level0)
3436 {
3437 BundleInstallChecker installChecker;
3438 std::vector<std::string> bundlePaths;
3439 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
3440 bundlePaths.push_back(bundlePath);
3441
3442 InstallCheckParam checkParam;
3443
3444 std::vector<Security::Verify::HapVerifyResult> hapVerifyRes;
3445 Security::Verify::HapVerifyResult result;
3446 Security::Verify::ProvisionInfo info;
3447 info.distributionType = Security::Verify::AppDistType::ENTERPRISE;
3448 info.type = Security::Verify::ProvisionType::RELEASE;
3449 info.bundleInfo.appFeature = "hos_normal_app";
3450 info.bundleInfo.bundleName = BUNDLE_BACKUP_NAME;
3451 result.SetProvisionInfo(info);
3452 hapVerifyRes.emplace_back(result);
3453
3454 std::unordered_map<std::string, InnerBundleInfo> infos;
3455 InnerBundleInfo innerBundleInfo;
3456 ApplicationInfo applicationInfo;
3457 applicationInfo.bundleName = BUNDLE_BACKUP_NAME;
3458 innerBundleInfo.SetBaseApplicationInfo(applicationInfo);
3459 InnerModuleInfo innerModuleInfo;
3460 innerModuleInfo.moduleName = "moduleName";
3461 innerBundleInfo.innerModuleInfos_.insert(
3462 pair<std::string, InnerModuleInfo>("moduleName", innerModuleInfo));
3463 infos.insert(pair<std::string, InnerBundleInfo>("moduleName", innerBundleInfo));
3464
3465 auto ret = installChecker.ParseHapFiles(bundlePaths, checkParam, hapVerifyRes, infos);
3466 EXPECT_EQ(ret, ERR_OK);
3467 }
3468
3469 /**
3470 * @tc.number: BmsBundleSignatureType_0100
3471 * @tc.name: test signed name is not the same
3472 * @tc.desc: 1. system running normally
3473 * 2. install a hap failed
3474 */
3475 HWTEST_F(BmsBundleInstallerTest, BmsBundleSignatureType_0100, Function | SmallTest | Level0)
3476 {
3477 std::string bundlePath = RESOURCE_ROOT_PATH + "signatureTest.hap";
3478 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
3479 EXPECT_EQ(installResult, ERR_APPEXECFWK_INSTALL_FAILED_BUNDLE_SIGNATURE_VERIFICATION_FAILURE);
3480 }
3481
3482 /**
3483 * @tc.number: ExtractArkProfileFile_0100
3484 * @tc.name: test ExtractArkProfileFile
3485 * @tc.desc: 1.Test ExtractArkProfileFile
3486 */
3487 HWTEST_F(BmsBundleInstallerTest, ExtractArkProfileFile_0100, Function | SmallTest | Level0)
3488 {
3489 BaseBundleInstaller installer;
3490 std::string modulePath = "";
3491 std::string bundleName = "";
3492 auto ret = installer.ExtractArkProfileFile(modulePath, bundleName, USERID);
3493 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
3494 }
3495
3496 /**
3497 * @tc.number: ExtractArkProfileFile_0200
3498 * @tc.name: test ExtractArkProfileFile
3499 * @tc.desc: 1.Test ExtractArkProfileFile
3500 */
3501 HWTEST_F(BmsBundleInstallerTest, ExtractArkProfileFile_0200, Function | SmallTest | Level0)
3502 {
3503 BaseBundleInstaller installer;
3504 std::string modulePath = RESOURCE_ROOT_PATH + RIGHT_BUNDLE;
3505 std::string bundleName = BUNDLE_NAME;
3506 auto ret = installer.ExtractArkProfileFile(modulePath, bundleName, USERID);
3507 EXPECT_EQ(ret, ERR_OK);
3508 }
3509
3510 /**
3511 * @tc.number: ExtractAllArkProfileFile_0100
3512 * @tc.name: test ExtractAllArkProfileFile
3513 * @tc.desc: 1.Test ExtractAllArkProfileFile
3514 */
3515 HWTEST_F(BmsBundleInstallerTest, ExtractAllArkProfileFile_0100, Function | SmallTest | Level0)
3516 {
3517 InnerBundleInfo innerBundleInfo;
3518 BaseBundleInstaller installer;
3519 auto ret = installer.ExtractAllArkProfileFile(innerBundleInfo);
3520 EXPECT_EQ(ret, ERR_OK);
3521 }
3522
3523 /**
3524 * @tc.number: ExtractAllArkProfileFile_0200
3525 * @tc.name: test ExtractAllArkProfileFile
3526 * @tc.desc: 1.Test ExtractAllArkProfileFile
3527 */
3528 HWTEST_F(BmsBundleInstallerTest, ExtractAllArkProfileFile_0200, Function | SmallTest | Level0)
3529 {
3530 InnerModuleInfo innerModuleInfo;
3531 innerModuleInfo.name = MODULE_NAME;
3532 innerModuleInfo.modulePackage = MODULE_NAME;
3533 InnerBundleInfo innerBundleInfo;
3534 innerBundleInfo.SetIsNewVersion(true);
3535 innerBundleInfo.InsertInnerModuleInfo(MODULE_NAME, innerModuleInfo);
3536 BaseBundleInstaller installer;
3537 auto ret = installer.ExtractAllArkProfileFile(innerBundleInfo);
3538 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
3539 }
3540
3541 /**
3542 * @tc.number: ExtractAllArkProfileFile_0300
3543 * @tc.name: test ExtractAllArkProfileFile
3544 * @tc.desc: 1.Test ExtractAllArkProfileFile
3545 */
3546 HWTEST_F(BmsBundleInstallerTest, ExtractAllArkProfileFile_0300, Function | SmallTest | Level0)
3547 {
3548 InnerModuleInfo innerModuleInfo;
3549 innerModuleInfo.name = MODULE_NAME;
3550 innerModuleInfo.modulePackage = MODULE_NAME;
3551 innerModuleInfo.hapPath = RESOURCE_ROOT_PATH + RIGHT_BUNDLE;
3552 InnerBundleInfo innerBundleInfo;
3553 innerBundleInfo.InsertInnerModuleInfo(MODULE_NAME, innerModuleInfo);
3554 ApplicationInfo applicationInfo;
3555 applicationInfo.bundleName = BUNDLE_NAME;
3556 applicationInfo.name = BUNDLE_NAME;
3557 innerBundleInfo.SetBaseApplicationInfo(applicationInfo);
3558 innerBundleInfo.SetIsNewVersion(true);
3559 BaseBundleInstaller installer;
3560 auto ret = installer.ExtractAllArkProfileFile(innerBundleInfo);
3561 EXPECT_EQ(ret, ERR_OK);
3562 }
3563
3564 /**
3565 * @tc.number: ExtractAllArkProfileFile_0400
3566 * @tc.name: test ExtractAllArkProfileFile
3567 * @tc.desc: 1.Test ExtractAllArkProfileFile
3568 */
3569 HWTEST_F(BmsBundleInstallerTest, ExtractAllArkProfileFile_0400, Function | SmallTest | Level0)
3570 {
3571 InnerBundleInfo innerBundleInfo;
3572 innerBundleInfo.SetIsNewVersion(false);
3573 BaseBundleInstaller installer;
3574 auto ret = installer.ExtractAllArkProfileFile(innerBundleInfo);
3575 EXPECT_EQ(ret, ERR_OK);
3576 }
3577
3578 /**
3579 * @tc.number: CheckArkProfileDir_0100
3580 * @tc.name: test CheckArkProfileDir
3581 * @tc.desc: 1.Test CheckArkProfileDir
3582 */
3583 HWTEST_F(BmsBundleInstallerTest, CheckArkProfileDir_0100, Function | SmallTest | Level0)
3584 {
3585 BundleInfo bundleInfo;
3586 bundleInfo.versionCode = 100;
3587 InnerBundleInfo innerBundleInfo;
3588 innerBundleInfo.SetBaseBundleInfo(bundleInfo);
3589 innerBundleInfo.SetIsNewVersion(false);
3590 BaseBundleInstaller installer;
3591 installer.bundleName_ = BUNDLE_NAME;
3592 installer.userId_ = USERID;
3593 InnerBundleInfo oldInnerBundleInfo;
3594 BundleInfo oldBundleInfo;
3595 oldBundleInfo.versionCode = 101;
3596 oldInnerBundleInfo.SetBaseBundleInfo(oldBundleInfo);
3597 auto ret = installer.CheckArkProfileDir(innerBundleInfo, oldInnerBundleInfo);
3598 EXPECT_EQ(ret, ERR_OK);
3599 }
3600
3601 /**
3602 * @tc.number: CheckArkProfileDir_0200
3603 * @tc.name: test CheckArkProfileDir
3604 * @tc.desc: 1.Test CheckArkProfileDir
3605 */
3606 HWTEST_F(BmsBundleInstallerTest, CheckArkProfileDir_0200, Function | SmallTest | Level0)
3607 {
3608 BundleInfo bundleInfo;
3609 bundleInfo.versionCode = 101;
3610 InnerBundleInfo innerBundleInfo;
3611 innerBundleInfo.SetBaseBundleInfo(bundleInfo);
3612 innerBundleInfo.SetIsNewVersion(false);
3613 BaseBundleInstaller installer;
3614 installer.bundleName_ = BUNDLE_NAME;
3615 installer.userId_ = USERID;
3616 InnerBundleInfo oldInnerBundleInfo;
3617 BundleInfo oldBundleInfo;
3618 oldBundleInfo.versionCode = 100;
3619 oldInnerBundleInfo.SetBaseBundleInfo(oldBundleInfo);
3620 auto ret = installer.CheckArkProfileDir(innerBundleInfo, oldInnerBundleInfo);
3621 EXPECT_EQ(ret, ERR_OK);
3622 }
3623
3624 /**
3625 * @tc.number: CheckArkProfileDir_0300
3626 * @tc.name: test CheckArkProfileDir
3627 * @tc.desc: 1.Test CheckArkProfileDir
3628 */
3629 HWTEST_F(BmsBundleInstallerTest, CheckArkProfileDir_0300, Function | SmallTest | Level0)
3630 {
3631 BundleInfo bundleInfo;
3632 bundleInfo.versionCode = 101;
3633 InnerBundleInfo innerBundleInfo;
3634 innerBundleInfo.SetBaseBundleInfo(bundleInfo);
3635 innerBundleInfo.SetIsNewVersion(false);
3636 BaseBundleInstaller installer;
3637 installer.bundleName_ = BUNDLE_NAME;
3638 installer.userId_ = USERID;
3639 InnerBundleInfo oldInnerBundleInfo;
3640 BundleInfo oldBundleInfo;
3641 oldBundleInfo.versionCode = 100;
3642 oldInnerBundleInfo.SetBaseBundleInfo(oldBundleInfo);
3643 InnerBundleUserInfo innerBundleUserInfo;
3644 innerBundleUserInfo.bundleUserInfo.userId = USERID;
3645 innerBundleUserInfo.bundleName = BUNDLE_NAME;
3646 oldInnerBundleInfo.AddInnerBundleUserInfo(innerBundleUserInfo);
3647 auto ret = installer.CheckArkProfileDir(innerBundleInfo, oldInnerBundleInfo);
3648 EXPECT_EQ(ret, ERR_OK);
3649 ret = installer.DeleteArkProfile(installer.bundleName_, installer.userId_);
3650 EXPECT_EQ(ret, ERR_OK);
3651 }
3652
3653 /**
3654 * @tc.number: CheckArkProfileDir_0400
3655 * @tc.name: test CheckArkProfileDir
3656 * @tc.desc: 1.Test CheckArkProfileDir
3657 */
3658 HWTEST_F(BmsBundleInstallerTest, CheckArkProfileDir_0400, Function | SmallTest | Level0)
3659 {
3660 BundleInfo bundleInfo;
3661 bundleInfo.versionCode = 101;
3662 InnerBundleInfo innerBundleInfo;
3663 innerBundleInfo.SetBaseBundleInfo(bundleInfo);
3664 innerBundleInfo.SetIsNewVersion(true);
3665 BaseBundleInstaller installer;
3666 installer.bundleName_ = BUNDLE_NAME;
3667 installer.userId_ = USERID;
3668 InnerBundleInfo oldInnerBundleInfo;
3669 BundleInfo oldBundleInfo;
3670 oldBundleInfo.versionCode = 100;
3671 oldInnerBundleInfo.SetBaseBundleInfo(oldBundleInfo);
3672 InnerBundleUserInfo innerBundleUserInfo;
3673 innerBundleUserInfo.bundleUserInfo.userId = USERID;
3674 innerBundleUserInfo.bundleName = BUNDLE_NAME;
3675 oldInnerBundleInfo.AddInnerBundleUserInfo(innerBundleUserInfo);
3676 auto ret = installer.CheckArkProfileDir(innerBundleInfo, oldInnerBundleInfo);
3677 EXPECT_EQ(ret, ERR_OK);
3678 ret = installer.DeleteArkProfile(installer.bundleName_, installer.userId_);
3679 EXPECT_EQ(ret, ERR_OK);
3680 }
3681
3682 /**
3683 * @tc.number: asanEnabled_0100
3684 * @tc.name: test checkAsanEnabled when asanEnabled is set to be ture
3685 * @tc.desc: 1.Test checkAsanEnabled
3686 */
3687 HWTEST_F(BmsBundleInstallerTest, checkAsanEnabled_0100, Function | SmallTest | Level0)
3688 {
3689 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
3690 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
3691 EXPECT_EQ(installResult, ERR_OK);
3692 ApplicationInfo info;
3693 auto dataMgr = GetBundleDataMgr();
3694 EXPECT_NE(dataMgr, nullptr);
3695 bool result = dataMgr->GetApplicationInfo(BUNDLE_BACKUP_NAME,
3696 ApplicationFlag::GET_BASIC_APPLICATION_INFO, USERID, info);
3697 EXPECT_TRUE(result);
3698 EXPECT_TRUE(info.asanEnabled);
3699 std::string asanLogPath = LOG;
3700 EXPECT_EQ(asanLogPath, info.asanLogPath);
3701 UnInstallBundle(BUNDLE_BACKUP_NAME);
3702 }
3703
3704 HWTEST_F(BmsBundleInstallerTest, checkAsanEnabled_0200, Function | SmallTest | Level0)
3705 {
3706 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_PREVIEW_TEST;
3707 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
3708 EXPECT_EQ(installResult, ERR_OK);
3709 auto dataMgr = GetBundleDataMgr();
3710 EXPECT_NE(dataMgr, nullptr);
3711 ApplicationInfo info;
3712 bool result = dataMgr->GetApplicationInfo(BUNDLE_PREVIEW_NAME,
3713 ApplicationFlag::GET_BASIC_APPLICATION_INFO, USERID, info);
3714 EXPECT_TRUE(result);
3715 EXPECT_FALSE(info.asanEnabled);
3716 std::string asanLogPath = "";
3717 EXPECT_EQ(asanLogPath, info.asanLogPath);
3718 UnInstallBundle(BUNDLE_PREVIEW_NAME);
3719 }
3720
3721 #ifdef BUNDLE_FRAMEWORK_APP_CONTROL
3722
3723 /**
3724 * @tc.number: baseBundleInstaller_4400
3725 * @tc.name: test InstallNormalAppControl
3726 * @tc.desc: 1.Test the InstallNormalAppControl of BaseBundleInstaller
3727 */
3728 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_4400, Function | SmallTest | Level0)
3729 {
3730 std::string installAppId = APPID;
3731 BaseBundleInstaller installer;
3732 int32_t userId = Constants::DEFAULT_USERID;
3733 std::vector<std::string> appIds;
3734 appIds.emplace_back(APPID);
3735
3736 auto resultAddAppInstallAppControlDisallow = DelayedSingleton<AppControlManager>::GetInstance()->
3737 AddAppInstallControlRule(AppControlConstants::EDM_CALLING,
3738 appIds, AppControlConstants::APP_DISALLOWED_INSTALL, userId);
3739 EXPECT_EQ(resultAddAppInstallAppControlDisallow, OHOS::ERR_OK);
3740
3741 auto ret = installer.InstallNormalAppControl(installAppId, userId);
3742 EXPECT_EQ(ret, OHOS::ERR_BUNDLE_MANAGER_APP_CONTROL_DISALLOWED_INSTALL);
3743
3744 auto resultDeleteAppInstallAppControlDisallow = DelayedSingleton<AppControlManager>::GetInstance()->
3745 DeleteAppInstallControlRule(AppControlConstants::EDM_CALLING,
3746 AppControlConstants::APP_DISALLOWED_INSTALL, appIds, userId);
3747 EXPECT_EQ(resultDeleteAppInstallAppControlDisallow, OHOS::ERR_OK);
3748 }
3749
3750 /**
3751 * @tc.number: baseBundleInstaller_4500
3752 * @tc.name: test InstallNormalAppControl
3753 * @tc.desc: 1.Test the InstallNormalAppControl of BaseBundleInstaller
3754 */
3755 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_4500, Function | SmallTest | Level0)
3756 {
3757 std::string installAppId = APPID;
3758 BaseBundleInstaller installer;
3759 int32_t userId = Constants::DEFAULT_USERID;
3760 std::vector<std::string> appIds;
3761 appIds.emplace_back(SYSTEMFIEID_NAME);
3762
3763 auto resultAddAppInstallAppControlAllow = DelayedSingleton<AppControlManager>::GetInstance()->
3764 AddAppInstallControlRule(AppControlConstants::EDM_CALLING,
3765 appIds, AppControlConstants::APP_DISALLOWED_INSTALL, userId);
3766 EXPECT_EQ(resultAddAppInstallAppControlAllow, OHOS::ERR_OK);
3767
3768 auto ret = installer.InstallNormalAppControl(installAppId, userId);
3769 EXPECT_EQ(ret, OHOS::ERR_OK);
3770
3771 auto resultDeleteAppInstallAppControlAllow = DelayedSingleton<AppControlManager>::GetInstance()->
3772 DeleteAppInstallControlRule(AppControlConstants::EDM_CALLING,
3773 AppControlConstants::APP_DISALLOWED_INSTALL, appIds, userId);
3774 EXPECT_EQ(resultDeleteAppInstallAppControlAllow, OHOS::ERR_OK);
3775 }
3776
3777 /**
3778 * @tc.number: baseBundleInstaller_4600
3779 * @tc.name: test InstallNormalAppControl
3780 * @tc.desc: 1.Test the InstallNormalAppControl of BaseBundleInstaller
3781 */
3782 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_4600, Function | SmallTest | Level0)
3783 {
3784 std::string installAppId = APPID;
3785 BaseBundleInstaller installer;
3786 int32_t userId = Constants::DEFAULT_USERID;
3787 std::vector<std::string> appIds;
3788 appIds.emplace_back(APPID);
3789 seteuid(EDM_UID);
3790 auto resultAddAppInstallAppControlAllow = DelayedSingleton<AppControlManager>::GetInstance()->
3791 AddAppInstallControlRule(AppControlConstants::EDM_CALLING,
3792 appIds, AppControlConstants::APP_ALLOWED_INSTALL, userId);
3793 EXPECT_EQ(resultAddAppInstallAppControlAllow, OHOS::ERR_OK);
3794
3795 auto resultAddAppInstallAppControlDisallow = DelayedSingleton<AppControlManager>::GetInstance()->
3796 AddAppInstallControlRule(AppControlConstants::EDM_CALLING,
3797 appIds, AppControlConstants::APP_DISALLOWED_INSTALL, userId);
3798 EXPECT_EQ(resultAddAppInstallAppControlDisallow, OHOS::ERR_OK);
3799
3800 auto ret = installer.InstallNormalAppControl(installAppId, userId);
3801 EXPECT_EQ(ret, OHOS::ERR_BUNDLE_MANAGER_APP_CONTROL_DISALLOWED_INSTALL);
3802
3803 auto resultDeleteAppInstallAppControlAllow = DelayedSingleton<AppControlManager>::GetInstance()->
3804 DeleteAppInstallControlRule(AppControlConstants::EDM_CALLING,
3805 AppControlConstants::APP_ALLOWED_INSTALL, appIds, userId);
3806 EXPECT_EQ(resultDeleteAppInstallAppControlAllow, OHOS::ERR_OK);
3807
3808 auto resultDeleteAppInstallAppControlDisallow = DelayedSingleton<AppControlManager>::GetInstance()->
3809 DeleteAppInstallControlRule(AppControlConstants::EDM_CALLING,
3810 AppControlConstants::APP_DISALLOWED_INSTALL, appIds, userId);
3811 EXPECT_EQ(resultDeleteAppInstallAppControlDisallow, OHOS::ERR_OK);
3812 }
3813
3814 /**
3815 * @tc.number: baseBundleInstaller_4700
3816 * @tc.name: test InstallNormalAppControl
3817 * @tc.desc: 1.Test the InstallNormalAppControl of BaseBundleInstaller
3818 */
3819 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_4700, Function | SmallTest | Level0)
3820 {
3821 std::string installAppId = APPID;
3822 BaseBundleInstaller installer;
3823 int32_t userId = Constants::DEFAULT_USERID;
3824 std::vector<std::string> appIds;
3825 std::vector<std::string> appIdsAllow;
3826 appIds.emplace_back(APPID);
3827 appIdsAllow.emplace_back(SYSTEMFIEID_NAME);
3828 seteuid(EDM_UID);
3829 auto resultAddAppInstallAppControlAllow = DelayedSingleton<AppControlManager>::GetInstance()->
3830 AddAppInstallControlRule(AppControlConstants::EDM_CALLING,
3831 appIdsAllow, AppControlConstants::APP_ALLOWED_INSTALL, userId);
3832 EXPECT_EQ(resultAddAppInstallAppControlAllow, OHOS::ERR_OK);
3833
3834 auto resultAddAppInstallAppControlDisallow = DelayedSingleton<AppControlManager>::GetInstance()->
3835 AddAppInstallControlRule(AppControlConstants::EDM_CALLING,
3836 appIds, AppControlConstants::APP_DISALLOWED_INSTALL, userId);
3837 EXPECT_EQ(resultAddAppInstallAppControlDisallow, OHOS::ERR_OK);
3838
3839 auto ret = installer.InstallNormalAppControl(installAppId, userId);
3840 EXPECT_EQ(ret, OHOS::ERR_BUNDLE_MANAGER_APP_CONTROL_DISALLOWED_INSTALL);
3841
3842 auto resultDeleteAppInstallAppControlAllow = DelayedSingleton<AppControlManager>::GetInstance()->
3843 DeleteAppInstallControlRule(AppControlConstants::EDM_CALLING,
3844 AppControlConstants::APP_ALLOWED_INSTALL, appIdsAllow, userId);
3845 EXPECT_EQ(resultDeleteAppInstallAppControlAllow, OHOS::ERR_OK);
3846
3847 auto resultDeleteAppInstallAppControlDisallow = DelayedSingleton<AppControlManager>::GetInstance()->
3848 DeleteAppInstallControlRule(AppControlConstants::EDM_CALLING,
3849 AppControlConstants::APP_DISALLOWED_INSTALL, appIds, userId);
3850 EXPECT_EQ(resultDeleteAppInstallAppControlDisallow, OHOS::ERR_OK);
3851 }
3852
3853 /**
3854 * @tc.number: baseBundleInstaller_4800
3855 * @tc.name: test InstallNormalAppControl
3856 * @tc.desc: 1.Test the InstallNormalAppControl of BaseBundleInstaller
3857 */
3858 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_4800, Function | SmallTest | Level0)
3859 {
3860 std::string installAppId = APPID;
3861 BaseBundleInstaller installer;
3862 int32_t userId = Constants::DEFAULT_USERID;
3863 std::vector<std::string> appIds;
3864 std::vector<std::string> appIdsAllow;
3865 appIds.emplace_back(APPID);
3866 appIdsAllow.emplace_back(SYSTEMFIEID_NAME);
3867 seteuid(EDM_UID);
3868 auto resultAddAppInstallAppControlAllow = DelayedSingleton<AppControlManager>::GetInstance()->
3869 AddAppInstallControlRule(AppControlConstants::EDM_CALLING,
3870 appIds, AppControlConstants::APP_ALLOWED_INSTALL, userId);
3871 EXPECT_EQ(resultAddAppInstallAppControlAllow, OHOS::ERR_OK);
3872
3873 auto resultAddAppInstallAppControlDisallow = DelayedSingleton<AppControlManager>::GetInstance()->
3874 AddAppInstallControlRule(AppControlConstants::EDM_CALLING,
3875 appIdsAllow, AppControlConstants::APP_DISALLOWED_INSTALL, userId);
3876 EXPECT_EQ(resultAddAppInstallAppControlDisallow, OHOS::ERR_OK);
3877
3878 auto ret = installer.InstallNormalAppControl(installAppId, userId);
3879 EXPECT_EQ(ret, OHOS::ERR_OK);
3880
3881 auto resultDeleteAppInstallAppControlAllow = DelayedSingleton<AppControlManager>::GetInstance()->
3882 DeleteAppInstallControlRule(AppControlConstants::EDM_CALLING,
3883 AppControlConstants::APP_ALLOWED_INSTALL, appIds, userId);
3884 EXPECT_EQ(resultDeleteAppInstallAppControlAllow, OHOS::ERR_OK);
3885
3886 auto resultDeleteAppInstallAppControlDisallow = DelayedSingleton<AppControlManager>::GetInstance()->
3887 DeleteAppInstallControlRule(AppControlConstants::EDM_CALLING,
3888 AppControlConstants::APP_DISALLOWED_INSTALL, appIdsAllow, userId);
3889 EXPECT_EQ(resultDeleteAppInstallAppControlDisallow, OHOS::ERR_OK);
3890 }
3891
3892 /**
3893 * @tc.number: baseBundleInstaller_4900
3894 * @tc.name: test InstallNormalAppControl
3895 * @tc.desc: 1.Test the InstallNormalAppControl of BaseBundleInstaller
3896 */
3897 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_4900, Function | SmallTest | Level0)
3898 {
3899 std::string installAppId = APPID;
3900 BaseBundleInstaller installer;
3901 int32_t userId = Constants::DEFAULT_USERID;
3902 std::vector<std::string> appIds;
3903 std::vector<std::string> appIdsAllow;
3904 appIds.emplace_back(SYSTEMFIEID_NAME);
3905 seteuid(EDM_UID);
3906 auto resultAddAppInstallAppControlAllow = DelayedSingleton<AppControlManager>::GetInstance()->
3907 AddAppInstallControlRule(AppControlConstants::EDM_CALLING,
3908 appIds, AppControlConstants::APP_ALLOWED_INSTALL, userId);
3909 EXPECT_EQ(resultAddAppInstallAppControlAllow, OHOS::ERR_OK);
3910
3911 auto resultAddAppInstallAppControlDisallow = DelayedSingleton<AppControlManager>::GetInstance()->
3912 AddAppInstallControlRule(AppControlConstants::EDM_CALLING,
3913 appIds, AppControlConstants::APP_DISALLOWED_INSTALL, userId);
3914 EXPECT_EQ(resultAddAppInstallAppControlDisallow, OHOS::ERR_OK);
3915
3916 auto ret = installer.InstallNormalAppControl(installAppId, userId);
3917 EXPECT_EQ(ret, OHOS::ERR_BUNDLE_MANAGER_APP_CONTROL_DISALLOWED_INSTALL);
3918
3919 auto resultDeleteAppInstallAppControlAllow = DelayedSingleton<AppControlManager>::GetInstance()->
3920 DeleteAppInstallControlRule(AppControlConstants::EDM_CALLING,
3921 AppControlConstants::APP_ALLOWED_INSTALL, appIds, userId);
3922 EXPECT_EQ(resultDeleteAppInstallAppControlAllow, OHOS::ERR_OK);
3923
3924 auto resultDeleteAppInstallAppControlDisallow = DelayedSingleton<AppControlManager>::GetInstance()->
3925 DeleteAppInstallControlRule(AppControlConstants::EDM_CALLING,
3926 AppControlConstants::APP_DISALLOWED_INSTALL, appIds, userId);
3927 EXPECT_EQ(resultDeleteAppInstallAppControlDisallow, OHOS::ERR_OK);
3928 }
3929
3930 /**
3931 * @tc.number: baseBundleInstaller_5000
3932 * @tc.name: test ProcessBundleInstall
3933 * @tc.desc: 1.Test the ProcessBundleInstall of BaseBundleInstaller
3934 */
3935 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_5000, Function | SmallTest | Level0)
3936 {
3937 BaseBundleInstaller installer;
3938 std::vector<std::string> inBundlePaths;
3939 auto bundleFile = RESOURCE_ROOT_PATH + FIRST_RIGHT_HAP;
3940 inBundlePaths.emplace_back(bundleFile);
3941 InstallParam installParam;
3942 installParam.isPreInstallApp = false;
3943 installParam.withCopyHaps = true;
3944 auto appType = Constants::AppType::THIRD_PARTY_APP;
3945 int32_t uid = 0;
3946 ErrCode ret = installer.ProcessBundleInstall(
3947 inBundlePaths, installParam, appType, uid);
3948 EXPECT_EQ(ret, ERR_OK);
3949 ClearBundleInfo();
3950 }
3951
3952 /**
3953 * @tc.number: baseBundleInstaller_5100
3954 * @tc.name: test InnerProcessInstallByPreInstallInfo
3955 * @tc.desc: 1.Test the InnerProcessInstallByPreInstallInfo of BaseBundleInstaller
3956 */
3957 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_5100, Function | SmallTest | Level0)
3958 {
3959 DelayedSingleton<BundleMgrService>::GetInstance()->dataMgr_ = std::make_shared<BundleDataMgr>();
3960 BaseBundleInstaller installer;
3961 installer.dataMgr_ = DelayedSingleton<BundleMgrService>::GetInstance()->GetDataMgr();
3962 installer.dataMgr_->AddUserId(100);
3963 InstallParam installParam;
3964 installParam.isPreInstallApp = false;
3965 installParam.userId = 100;
3966 installer.userId_ = 100;
3967 int32_t uid = 100;
3968 auto ret = installer.InnerProcessInstallByPreInstallInfo(BUNDLE_MODULEJSON_TEST, installParam, uid);
3969 EXPECT_EQ(ret, ERR_APPEXECFWK_RECOVER_INVALID_BUNDLE_NAME);
3970 ClearBundleInfo();
3971 }
3972
3973 /**
3974 * @tc.number: baseBundleInstaller_5200
3975 * @tc.name: test InnerProcessInstallByPreInstallInfo
3976 * @tc.desc: 1.Test the InnerProcessInstallByPreInstallInfo of BaseBundleInstaller
3977 */
3978 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_5200, Function | SmallTest | Level0)
3979 {
3980 BaseBundleInstaller installer;
3981 UninstallParam uninstallParam;
3982 uninstallParam.bundleName = "";
3983 auto ret = installer.UninstallBundleByUninstallParam(uninstallParam);
3984 EXPECT_EQ(ret, ERR_APPEXECFWK_UNINSTALL_SHARE_APP_LIBRARY_IS_NOT_EXIST);
3985 }
3986
3987 /**
3988 * @tc.number: baseBundleInstaller_5300
3989 * @tc.name: test InnerProcessInstallByPreInstallInfo
3990 * @tc.desc: 1.Test the InnerProcessInstallByPreInstallInfo of BaseBundleInstaller
3991 */
3992 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_5300, Function | SmallTest | Level0)
3993 {
3994 BaseBundleInstaller installer;
3995 UninstallParam uninstallParam;
3996 uninstallParam.bundleName = BUNDLE_NAME;
3997 ClearDataMgr();
3998 auto ret = installer.UninstallBundleByUninstallParam(uninstallParam);
3999 EXPECT_EQ(ret, ERR_APPEXECFWK_UNINSTALL_BUNDLE_MGR_SERVICE_ERROR);
4000 ResetDataMgr();
4001 }
4002
4003 /**
4004 * @tc.number: appControlManagerHostImpl_0100
4005 * @tc.name: test GetControlRuleType
4006 * @tc.desc: 1.Test the GetControlRuleType of AppControlManagerHostImpl
4007 */
4008 HWTEST_F(BmsBundleInstallerTest, appControlManagerHostImpl_0100, Function | SmallTest | Level0)
4009 {
4010 auto impl = std::make_shared<AppControlManagerHostImpl>();
4011 auto ret = impl->GetControlRuleType(AppInstallControlRuleType::DISALLOWED_UNINSTALL);
4012 EXPECT_EQ(ret, AppControlConstants::APP_DISALLOWED_UNINSTALL);
4013 }
4014
4015 /**
4016 * @tc.number: appControlManagerHostImpl_0200
4017 * @tc.name: test GetControlRuleType
4018 * @tc.desc: 1.Test the GetControlRuleType of AppControlManagerHostImpl
4019 */
4020 HWTEST_F(BmsBundleInstallerTest, appControlManagerHostImpl_0200, Function | SmallTest | Level0)
4021 {
4022 auto impl = std::make_shared<AppControlManagerHostImpl>();
4023 auto ret = impl->GetControlRuleType(AppInstallControlRuleType::UNSPECIFIED);
4024 EXPECT_EQ(ret, EMPTY_STRING);
4025 }
4026 #endif
4027
4028 /**
4029 * @tc.number: baseBundleInstaller_5400
4030 * @tc.name: test checkAsanEnabled when asanEnabled is set to be ture
4031 * @tc.desc: 1.Test checkAsanEnabled
4032 */
4033 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_5400, Function | SmallTest | Level0)
4034 {
4035 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
4036 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
4037 EXPECT_EQ(installResult, ERR_OK);
4038
4039 BaseBundleInstaller installer;
4040 InstallParam installParam;
4041 installParam.userId = USERID;
4042 installParam.installFlag = InstallFlag::REPLACE_EXISTING;
4043 int32_t uid = USERID;
4044
4045 auto dataMgr = GetBundleDataMgr();
4046 EXPECT_NE(dataMgr, nullptr);
4047 bool ret = GetBundleDataMgr()->UpdateBundleInstallState(BUNDLE_BACKUP_NAME, InstallState::UNINSTALL_START);
4048 EXPECT_EQ(ret, true);
4049
4050 auto res = installer.ProcessBundleUninstall(BUNDLE_BACKUP_NAME, installParam, uid);
4051 EXPECT_EQ(res, ERR_OK);
4052
4053 UnInstallBundle(BUNDLE_BACKUP_NAME);
4054
4055 ret = GetBundleDataMgr()->UpdateBundleInstallState(BUNDLE_BACKUP_NAME, InstallState::UNINSTALL_SUCCESS);
4056 EXPECT_EQ(ret, false);
4057 }
4058
4059 /**
4060 * @tc.number: baseBundleInstaller_5500
4061 * @tc.name: test ProcessBundleUninstall
4062 * @tc.desc: 1.Test ProcessBundleUninstall
4063 */
4064 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_5500, Function | SmallTest | Level0)
4065 {
4066 BaseBundleInstaller installer;
4067 InstallParam installParam;
4068 installParam.userId = 999;
4069 installParam.installFlag = InstallFlag::NORMAL;
4070 int32_t uid = USERID;
4071
4072 auto res = installer.ProcessBundleUninstall(BUNDLE_BACKUP_NAME, TEST_PACK_AGE, installParam, uid);
4073 EXPECT_EQ(res, ERR_APPEXECFWK_USER_NOT_EXIST);
4074 }
4075
4076 /**
4077 * @tc.number: baseBundleInstaller_5600
4078 * @tc.name: test ProcessBundleUninstall
4079 * @tc.desc: 1.Test ProcessBundleUninstall
4080 */
4081 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_5600, Function | SmallTest | Level0)
4082 {
4083 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
4084 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
4085 EXPECT_EQ(installResult, ERR_OK);
4086
4087 BaseBundleInstaller installer;
4088 InstallParam installParam;
4089 installParam.userId = USERID;
4090 installParam.installFlag = InstallFlag::NORMAL;
4091 int32_t uid = USERID;
4092
4093 auto res = installer.ProcessBundleUninstall(BUNDLE_BACKUP_NAME, WRONG_BUNDLE_NAME, installParam, uid);
4094 EXPECT_EQ(res, ERR_APPEXECFWK_UNINSTALL_MISSING_INSTALLED_MODULE);
4095
4096 UnInstallBundle(BUNDLE_BACKUP_NAME);
4097 }
4098
4099 /**
4100 * @tc.number: baseBundleInstaller_5700
4101 * @tc.name: test ProcessBundleUninstall
4102 * @tc.desc: 1.Test ProcessBundleUninstall
4103 */
4104 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_5700, Function | SmallTest | Level0)
4105 {
4106 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
4107 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
4108 EXPECT_EQ(installResult, ERR_OK);
4109
4110 BaseBundleInstaller installer;
4111 InstallParam installParam;
4112 installParam.userId = USERID;
4113 installParam.installFlag = InstallFlag::REPLACE_EXISTING;
4114 int32_t uid = USERID;
4115
4116 auto dataMgr = GetBundleDataMgr();
4117 EXPECT_NE(dataMgr, nullptr);
4118 bool ret = GetBundleDataMgr()->UpdateBundleInstallState(BUNDLE_BACKUP_NAME, InstallState::UNINSTALL_START);
4119 EXPECT_EQ(ret, true);
4120
4121 auto res = installer.ProcessBundleUninstall(BUNDLE_BACKUP_NAME, TEST_PACK_AGE, installParam, uid);
4122 EXPECT_EQ(res, ERR_OK);
4123
4124 UnInstallBundle(BUNDLE_BACKUP_NAME);
4125
4126 ret = GetBundleDataMgr()->UpdateBundleInstallState(BUNDLE_BACKUP_NAME, InstallState::UNINSTALL_SUCCESS);
4127 EXPECT_EQ(ret, false);
4128 }
4129
4130 #ifdef BUNDLE_FRAMEWORK_QUICK_FIX
4131
4132 /**
4133 * @tc.number: baseBundleInstaller_5800
4134 * @tc.name: test UpdateLibAttrs
4135 * @tc.desc: 1.Test the UpdateLibAttrs of BaseBundleInstaller
4136 */
4137 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_5800, Function | SmallTest | Level0)
4138 {
4139 BaseBundleInstaller installer;
4140 InnerBundleInfo newInfo;
4141 newInfo.SetCurrentModulePackage(MODULE_NAME_TEST);
4142 InnerModuleInfo innerModuleInfo;
4143 innerModuleInfo.moduleName = MODULE_NAME_TEST;
4144 innerModuleInfo.isLibIsolated = true;
4145 newInfo.innerModuleInfos_.insert(
4146 std::pair<std::string, InnerModuleInfo>(MODULE_NAME_TEST, innerModuleInfo));
4147 AppqfInfo appQfInfo;
4148 auto ret = installer.UpdateLibAttrs(newInfo, TEST_CPU_ABI, BUNDLE_LIBRARY_PATH_DIR, appQfInfo);
4149 EXPECT_EQ(ret, ERR_BUNDLEMANAGER_QUICK_FIX_MODULE_NAME_NOT_EXIST);
4150 }
4151
4152 /**
4153 * @tc.number: baseBundleInstaller_5900
4154 * @tc.name: test UpdateLibAttrs
4155 * @tc.desc: 1.Test the UpdateLibAttrs of BaseBundleInstaller
4156 */
4157 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_5900, Function | SmallTest | Level0)
4158 {
4159 BaseBundleInstaller installer;
4160 InnerBundleInfo newInfo;
4161 newInfo.SetCurrentModulePackage(MODULE_NAME_TEST);
4162 InnerModuleInfo innerModuleInfo;
4163 innerModuleInfo.moduleName = MODULE_NAME_TEST;
4164 innerModuleInfo.isLibIsolated = false;
4165 AppqfInfo appQfInfo;
4166 auto ret = installer.UpdateLibAttrs(newInfo, TEST_CPU_ABI, BUNDLE_LIBRARY_PATH_DIR, appQfInfo);
4167 EXPECT_EQ(ret, ERR_OK);
4168 }
4169
4170 /**
4171 * @tc.number: baseBundleInstaller_6000
4172 * @tc.name: test UpdateLibAttrs
4173 * @tc.desc: 1.Test the UpdateLibAttrs of BaseBundleInstaller
4174 */
4175 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_6000, Function | SmallTest | Level0)
4176 {
4177 BaseBundleInstaller installer;
4178 InnerBundleInfo newInfo;
4179 newInfo.SetCurrentModulePackage(MODULE_NAME_TEST);
4180 InnerModuleInfo innerModuleInfo;
4181 innerModuleInfo.moduleName = MODULE_NAME_TEST;
4182 innerModuleInfo.isLibIsolated = true;
4183 newInfo.innerModuleInfos_.insert(
4184 std::pair<std::string, InnerModuleInfo>(MODULE_NAME_TEST, innerModuleInfo));
4185 AppqfInfo appQfInfo;
4186 std::vector<HqfInfo> hqfInfos;
4187 HqfInfo info;
4188 info.moduleName = MODULE_NAME;
4189 hqfInfos.emplace_back(info);
4190 info.moduleName = MODULE_NAME_TEST;
4191 info.nativeLibraryPath = BUNDLE_LIBRARY_PATH_DIR;
4192 info.cpuAbi = TEST_CPU_ABI;
4193 hqfInfos.emplace_back(info);
4194 appQfInfo.hqfInfos = hqfInfos;
4195 auto ret = installer.UpdateLibAttrs(newInfo, TEST_CPU_ABI, BUNDLE_LIBRARY_PATH_DIR, appQfInfo);
4196 EXPECT_EQ(ret, ERR_OK);
4197 }
4198
4199 #endif
4200
4201 /**
4202 * @tc.number: ParseFiles_0100
4203 * @tc.name: test the start function of ParseFiles
4204 * @tc.desc: 1.Test ParseFiles
4205 */
4206 HWTEST_F(BmsBundleInstallerTest, ParseFiles_0100, Function | SmallTest | Level0)
4207 {
4208 InstallParam installParam;
4209 auto appType = Constants::AppType::THIRD_PARTY_APP;
4210 SharedBundleInstaller installer(installParam, appType);
4211 installer.installParam_.sharedBundleDirPaths.clear();
4212 auto res = installer.ParseFiles();
4213 EXPECT_EQ(res, ERR_OK);
4214 bool result = installer.NeedToInstall();
4215 EXPECT_FALSE(result);
4216 }
4217
4218 /**
4219 * @tc.number: ParseFiles_0200
4220 * @tc.name: test the start function of ParseFiles
4221 * @tc.desc: 1.Test ParseFiles
4222 */
4223 HWTEST_F(BmsBundleInstallerTest, ParseFiles_0200, Function | SmallTest | Level0)
4224 {
4225 InstallParam installParam;
4226 auto appType = Constants::AppType::THIRD_PARTY_APP;
4227 SharedBundleInstaller installer(installParam, appType);
4228 installParam.sharedBundleDirPaths = {"/path/to/test1", "/path/to/test2"};
4229 installer.installParam_.sharedBundleDirPaths = installParam.sharedBundleDirPaths;
4230 auto ret = installer.ParseFiles();
4231 EXPECT_NE(ret, ERR_OK);
4232 }
4233
4234 /**
4235 * @tc.number: UtdHandler_0100
4236 * @tc.name: test UtdHandler
4237 * @tc.desc: 1.call GetEntryHapPath, if exist entry then return entry path, otherwise return empty string
4238 */
4239 HWTEST_F(BmsBundleInstallerTest, UtdHandler_0100, Function | SmallTest | Level0)
4240 {
4241 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
4242 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
4243 EXPECT_EQ(installResult, ERR_OK);
4244
4245 auto dataMgr = GetBundleDataMgr();
4246 EXPECT_NE(dataMgr, nullptr);
4247
4248 std::string entryHapPath;
4249 entryHapPath = UtdHandler::GetEntryHapPath(BUNDLE_BACKUP_NAME, USERID);
4250 EXPECT_NE(entryHapPath, EMPTY_STRING);
4251
4252 entryHapPath = UtdHandler::GetEntryHapPath(EMPTY_STRING, USERID);
4253 EXPECT_EQ(entryHapPath, EMPTY_STRING);
4254
4255 int32_t invalidUserId = -200;
4256 entryHapPath = UtdHandler::GetEntryHapPath(BUNDLE_BACKUP_NAME, invalidUserId);
4257 EXPECT_EQ(entryHapPath, EMPTY_STRING);
4258
4259 UnInstallBundle(BUNDLE_BACKUP_NAME);
4260 }
4261
4262 /**
4263 * @tc.number: UtdHandler_0200
4264 * @tc.name: test UtdHandler
4265 * @tc.desc: 1.call GetUtdProfileFromHap, if exist utd.json5 then return content, otherwise return empty string
4266 */
4267 HWTEST_F(BmsBundleInstallerTest, UtdHandler_0200, Function | SmallTest | Level0)
4268 {
4269 std::string utdProfile;
4270 std::string withUtdHapPath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
4271 utdProfile = UtdHandler::GetUtdProfileFromHap(withUtdHapPath);
4272 EXPECT_NE(utdProfile, EMPTY_STRING);
4273
4274 std::string noUtdHapPath = RESOURCE_ROOT_PATH + RIGHT_BUNDLE;
4275 utdProfile = UtdHandler::GetUtdProfileFromHap(noUtdHapPath);
4276 EXPECT_EQ(utdProfile, EMPTY_STRING);
4277
4278 utdProfile = UtdHandler::GetUtdProfileFromHap(EMPTY_STRING);
4279 EXPECT_EQ(utdProfile, EMPTY_STRING);
4280 }
4281
4282 /**
4283 * @tc.number: CheckDependency_0100
4284 * @tc.name: test the start function of CheckDependency
4285 * @tc.desc: 1.Test CheckDependency
4286 */
4287 HWTEST_F(BmsBundleInstallerTest, CheckDependency_0100, Function | SmallTest | Level0)
4288 {
4289 InstallParam installParam;
4290 auto appType = Constants::AppType::THIRD_PARTY_APP;
4291 SharedBundleInstaller installer(installParam, appType);
4292 Dependency dependency;
4293 dependency.bundleName = "";
4294 InnerModuleInfo innerModuleInfo;
4295 innerModuleInfo.dependencies.push_back(dependency);
4296 InnerBundleInfo innerBundleInfo;
4297 innerBundleInfo.baseApplicationInfo_->bundleName = "";
4298 innerBundleInfo.innerModuleInfos_.insert(pair<std::string, InnerModuleInfo>("1", innerModuleInfo));
4299 auto res = installer.CheckDependency(innerBundleInfo);
4300 EXPECT_TRUE(res);
4301
4302 innerBundleInfo.baseApplicationInfo_->bundleName = BUNDLE_NAME;
4303 res = installer.CheckDependency(innerBundleInfo);
4304 EXPECT_TRUE(res);
4305
4306 Dependency dependency1;
4307 dependency1.bundleName = BUNDLE_NAME;
4308 InnerModuleInfo innerModuleInfo1;
4309 innerModuleInfo1.dependencies.push_back(dependency1);
4310 innerBundleInfo.innerModuleInfos_.insert(pair<std::string, InnerModuleInfo>("2", innerModuleInfo1));
4311 res = installer.CheckDependency(innerBundleInfo);
4312 EXPECT_TRUE(res);
4313
4314 innerBundleInfo.baseApplicationInfo_->bundleName = WRONG_BUNDLE_NAME;
4315 res = installer.CheckDependency(innerBundleInfo);
4316 EXPECT_FALSE(res);
4317 }
4318
4319 /**
4320 * @tc.number: CheckDependency_0100
4321 * @tc.name: test the start function of CheckDependency
4322 * @tc.desc: 1.Test CheckDependency
4323 */
4324 HWTEST_F(BmsBundleInstallerTest, CheckDependency_0200, Function | SmallTest | Level0)
4325 {
4326 InstallParam installParam;
4327 auto appType = Constants::AppType::THIRD_PARTY_APP;
4328 SharedBundleInstaller installer(installParam, appType);
4329 Dependency dependency;
4330 dependency.bundleName = BUNDLE_NAME;
4331 InnerModuleInfo innerModuleInfo;
4332 innerModuleInfo.dependencies.push_back(dependency);
4333 InnerBundleInfo innerBundleInfo;
4334 innerBundleInfo.baseApplicationInfo_->bundleName = WRONG_BUNDLE_NAME;
4335 innerBundleInfo.innerModuleInfos_.insert(pair<std::string, InnerModuleInfo>("1", innerModuleInfo));
4336 std::string path = BUNDLE_DATA_DIR;
4337 std::shared_ptr<InnerSharedBundleInstaller> innerSharedBundleInstaller =
4338 std::make_shared<InnerSharedBundleInstaller>(path);
4339 innerSharedBundleInstaller->bundleName_ = WRONG_BUNDLE_NAME;
4340 installer.innerInstallers_.insert(pair<std::string,
4341 std::shared_ptr<InnerSharedBundleInstaller>>(WRONG_BUNDLE_NAME, innerSharedBundleInstaller));
4342 auto res = installer.CheckDependency(innerBundleInfo);
4343 EXPECT_FALSE(res);
4344 }
4345
4346 /**
4347 * @tc.number: GetNativeLibraryFileNames_0001
4348 * @tc.name: test GetNativeLibraryFileNames
4349 * @tc.desc: 1.Test the GetNativeLibraryFileNames of InstalldHostImpl
4350 */
4351 HWTEST_F(BmsBundleInstallerTest, GetNativeLibraryFileNames_0001, Function | SmallTest | Level0)
4352 {
4353 InstalldHostImpl impl;
4354 std::vector<std::string> fileNames;
4355 auto ret = impl.GetNativeLibraryFileNames("", "", fileNames);
4356 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
4357
4358 ret = impl.GetNativeLibraryFileNames("/data/test/xxx.hap", "libs/arm", fileNames);
4359 EXPECT_EQ(ret, ERR_OK);
4360 EXPECT_TRUE(fileNames.empty());
4361 }
4362
4363 /**
4364 * @tc.number: BmsBundleInstallerTest_0010
4365 * @tc.name: InnerProcessNativeLibs
4366 * @tc.desc: test InnerProcessNativeLibs isLibIsolated false
4367 */
4368 HWTEST_F(BmsBundleInstallerTest, BmsBundleInstallerTest_0010, TestSize.Level1)
4369 {
4370 InnerBundleInfo info;
4371 info.currentPackage_ = MODULE_NAME_TEST;
4372 InnerModuleInfo moduleInfo;
4373 moduleInfo.name = MODULE_NAME_TEST;
4374 moduleInfo.moduleName = MODULE_NAME_TEST;
4375 moduleInfo.modulePackage = MODULE_NAME_TEST;
4376 moduleInfo.isLibIsolated = false;
4377 moduleInfo.compressNativeLibs = true;
4378 info.innerModuleInfos_[MODULE_NAME_TEST] = moduleInfo;
4379 info.baseApplicationInfo_->cpuAbi = "";
4380 info.baseApplicationInfo_->nativeLibraryPath = "";
4381
4382 BaseBundleInstaller installer;
4383 installer.modulePackage_ = MODULE_NAME_TEST;
4384 installer.modulePath_ = "";
4385 std::string modulePath = "";
4386 // nativeLibraryPath empty, compressNativeLibs true
4387 ErrCode ret = installer.InnerProcessNativeLibs(info, modulePath);
4388 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
4389
4390 info.innerModuleInfos_[MODULE_NAME_TEST].compressNativeLibs = false;
4391 // nativeLibraryPath empty, compressNativeLibs false
4392 ret = installer.InnerProcessNativeLibs(info, modulePath);
4393 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
4394
4395 // nativeLibraryPath not empty, compressNativeLibs true
4396 info.baseApplicationInfo_->cpuAbi = "libs/arm";
4397 info.baseApplicationInfo_->nativeLibraryPath = "libs/arm";
4398 modulePath = "package_tmp";
4399 info.innerModuleInfos_[MODULE_NAME_TEST].compressNativeLibs = true;
4400 ret = installer.InnerProcessNativeLibs(info, modulePath);
4401 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
4402
4403 // nativeLibraryPath not empty, compressNativeLibs false
4404 info.innerModuleInfos_[MODULE_NAME_TEST].compressNativeLibs = false;
4405 ret = installer.InnerProcessNativeLibs(info, modulePath);
4406 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
4407
4408 modulePath = "/data/test/bms_bundle_installer";
4409 installer.modulePath_ = RESOURCE_ROOT_PATH + RIGHT_BUNDLE;
4410 ret = installer.InnerProcessNativeLibs(info, modulePath);
4411 EXPECT_EQ(ret, ERR_OK);
4412 }
4413
4414 /**
4415 * @tc.number: BmsBundleInstallerTest_0020
4416 * @tc.name: InnerProcessNativeLibs
4417 * @tc.desc: test InnerProcessNativeLibs isLibIsolated true
4418 */
4419 HWTEST_F(BmsBundleInstallerTest, BmsBundleInstallerTest_0020, TestSize.Level1)
4420 {
4421 InnerBundleInfo info;
4422 info.currentPackage_ = MODULE_NAME_TEST;
4423 InnerModuleInfo moduleInfo;
4424 moduleInfo.name = MODULE_NAME_TEST;
4425 moduleInfo.moduleName = MODULE_NAME_TEST;
4426 moduleInfo.modulePackage = MODULE_NAME_TEST;
4427 moduleInfo.cpuAbi = "libs/arm";
4428 moduleInfo.nativeLibraryPath = "libs/arm";
4429 moduleInfo.isLibIsolated = true;
4430 moduleInfo.compressNativeLibs = true;
4431 info.innerModuleInfos_[MODULE_NAME_TEST] = moduleInfo;
4432 info.baseApplicationInfo_->cpuAbi = "";
4433 info.baseApplicationInfo_->nativeLibraryPath = "";
4434
4435 BaseBundleInstaller installer;
4436 installer.modulePackage_ = MODULE_NAME_TEST;
4437 installer.modulePath_ = "";
4438 std::string modulePath = "";
4439 // nativeLibraryPath empty, compressNativeLibs true
4440 ErrCode ret = installer.InnerProcessNativeLibs(info, modulePath);
4441 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
4442
4443 modulePath = "package_tmp";
4444 ret = installer.InnerProcessNativeLibs(info, modulePath);
4445 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
4446 modulePath = "/data/test/bms_bundle_installer";
4447 installer.modulePath_ = RESOURCE_ROOT_PATH + RIGHT_BUNDLE;
4448 ret = installer.InnerProcessNativeLibs(info, modulePath);
4449 EXPECT_EQ(ret, ERR_OK);
4450 }
4451
4452 /**
4453 * @tc.number: BmsBundleInstallerTest_0030
4454 * @tc.name: ExtractSoFiles
4455 * @tc.desc: test ExtractSoFiles
4456 */
4457 HWTEST_F(BmsBundleInstallerTest, BmsBundleInstallerTest_0030, TestSize.Level1)
4458 {
4459 BaseBundleInstaller installer;
4460 auto ret = installer.ExtractSoFiles("/data/test", "libs/arm");
4461 EXPECT_FALSE(ret);
4462
4463 installer.modulePath_ = RESOURCE_ROOT_PATH + RIGHT_BUNDLE;
4464 ret = installer.ExtractSoFiles("/data/test", "libs/arm");
4465 EXPECT_TRUE(ret);
4466 }
4467
4468 /**
4469 * @tc.number: ProcessOldNativeLibraryPath_0010
4470 * @tc.name: ExtractSoFiles
4471 * @tc.desc: test ProcessOldNativeLibraryPath
4472 */
4473 HWTEST_F(BmsBundleInstallerTest, ProcessOldNativeLibraryPath_0010, TestSize.Level1)
4474 {
4475 bool ret = OHOS::ForceCreateDirectory(BUNDLE_LIBRARY_PATH_DIR);
4476 EXPECT_TRUE(ret);
4477
4478 BaseBundleInstaller installer;
4479 installer.bundleName_ = BUNDLE_NAME;
4480 std::unordered_map<std::string, InnerBundleInfo> newInfos;
4481 int32_t oldVersionCode = 1000;
4482 std::string nativeLibraryPath = "";
4483 installer.ProcessOldNativeLibraryPath(newInfos, oldVersionCode, nativeLibraryPath);
4484 auto exist = access(BUNDLE_LIBRARY_PATH_DIR.c_str(), F_OK);
4485 EXPECT_EQ(exist, 0);
4486
4487 nativeLibraryPath = "libs/arm";
4488 installer.ProcessOldNativeLibraryPath(newInfos, oldVersionCode, nativeLibraryPath);
4489 exist = access(BUNDLE_LIBRARY_PATH_DIR.c_str(), F_OK);
4490 EXPECT_EQ(exist, 0);
4491
4492 installer.versionCode_ = 2000;
4493 nativeLibraryPath = "";
4494 installer.ProcessOldNativeLibraryPath(newInfos, oldVersionCode, nativeLibraryPath);
4495 exist = access(BUNDLE_LIBRARY_PATH_DIR.c_str(), F_OK);
4496 EXPECT_EQ(exist, 0);
4497
4498 nativeLibraryPath = "libs/arm";
4499 InnerBundleInfo innerBundleInfo;
4500 InnerModuleInfo moduleInfo;
4501 moduleInfo.compressNativeLibs = true;
4502 innerBundleInfo.innerModuleInfos_["aaa"] = moduleInfo;
4503 moduleInfo.compressNativeLibs = false;
4504 innerBundleInfo.innerModuleInfos_["bbb"] = moduleInfo;
4505 newInfos["a"] = innerBundleInfo;
4506 installer.ProcessOldNativeLibraryPath(newInfos, oldVersionCode, nativeLibraryPath);
4507 exist = access(BUNDLE_LIBRARY_PATH_DIR.c_str(), F_OK);
4508 EXPECT_EQ(exist, 0);
4509
4510 moduleInfo.compressNativeLibs = false;
4511 innerBundleInfo.innerModuleInfos_["aaa"] = moduleInfo;
4512 newInfos["a"] = innerBundleInfo;
4513
4514 installer.ProcessOldNativeLibraryPath(newInfos, oldVersionCode, nativeLibraryPath);
4515 exist = access(BUNDLE_LIBRARY_PATH_DIR.c_str(), F_OK);
4516 EXPECT_NE(exist, 0);
4517 }
4518
4519 /**
4520 * @tc.number: UninstallHspVersion_0010
4521 * @tc.name: UninstallHspVersion
4522 * @tc.desc: test UninstallHspVersion
4523 */
4524 HWTEST_F(BmsBundleInstallerTest, UninstallHspVersion_0010, TestSize.Level1)
4525 {
4526 BaseBundleInstaller installer;
4527 int32_t versionCode = 9;
4528 InnerBundleInfo info;
4529 std::string uninstallDir;
4530 installer.InitDataMgr();
4531 auto ret = installer.UninstallHspVersion(uninstallDir, versionCode, info);
4532 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_BUNDLE_MGR_SERVICE_ERROR);
4533 }
4534
4535 /**
4536 * @tc.number: CheckEnableRemovable_0010
4537 * @tc.name: CheckEnableRemovable
4538 * @tc.desc: test CheckEnableRemovable
4539 */
4540 HWTEST_F(BmsBundleInstallerTest, CheckEnableRemovable_0010, TestSize.Level1)
4541 {
4542 BaseBundleInstaller installer;
4543 InnerBundleInfo newInfo;
4544 std::unordered_map<std::string, InnerBundleInfo> newInfos;
4545 newInfos.emplace("", newInfo);
4546 InnerBundleInfo oldInfo;
4547 bool isFreeInstallFlag = true;
4548 bool isAppExist = false;
4549 int32_t userId = 100;
4550 installer.CheckEnableRemovable(newInfos, oldInfo, userId, isFreeInstallFlag, isAppExist);
4551
4552 bool existModule = oldInfo.FindModule(MODULE_NAME);
4553 EXPECT_EQ(existModule, false);
4554 }
4555
4556 /**
4557 * @tc.number: CheckEnableRemovable_0020
4558 * @tc.name: CheckEnableRemovable
4559 * @tc.desc: test CheckEnableRemovable
4560 */
4561 HWTEST_F(BmsBundleInstallerTest, CheckEnableRemovable_0020, TestSize.Level1)
4562 {
4563 BaseBundleInstaller installer;
4564 InnerBundleInfo newInfo;
4565 std::unordered_map<std::string, InnerBundleInfo> newInfos;
4566 newInfos.emplace("", newInfo);
4567 InnerBundleInfo oldInfo;
4568 bool isFreeInstallFlag = true;
4569 bool isAppExist = false;
4570 int32_t userId = 100;
4571
4572 InnerModuleInfo innerModuleInfo;
4573 innerModuleInfo.name = MODULE_NAME;
4574 innerModuleInfo.modulePackage = MODULE_NAME;
4575 newInfo.InsertInnerModuleInfo(MODULE_NAME, innerModuleInfo);
4576 oldInfo.InsertInnerModuleInfo(MODULE_NAME, innerModuleInfo);
4577
4578 installer.CheckEnableRemovable(newInfos, oldInfo, userId, isFreeInstallFlag, isAppExist);
4579 bool existModule = oldInfo.FindModule(MODULE_NAME);
4580 EXPECT_EQ(existModule, true);
4581 }
4582
4583 /**
4584 * @tc.number: CheckEnableRemovable_0030
4585 * @tc.name: CheckEnableRemovable
4586 * @tc.desc: test CheckEnableRemovable
4587 */
4588 HWTEST_F(BmsBundleInstallerTest, CheckEnableRemovable_0030, TestSize.Level1)
4589 {
4590 BaseBundleInstaller installer;
4591 InnerBundleInfo newInfo;
4592 std::unordered_map<std::string, InnerBundleInfo> newInfos;
4593 newInfos.emplace("", newInfo);
4594 InnerBundleInfo oldInfo;
4595 bool isFreeInstallFlag = true;
4596 bool isAppExist = true;
4597 int32_t userId = 100;
4598
4599 InnerModuleInfo innerModuleInfo;
4600 innerModuleInfo.name = MODULE_NAME;
4601 innerModuleInfo.modulePackage = MODULE_NAME;
4602 newInfo.InsertInnerModuleInfo(MODULE_NAME, innerModuleInfo);
4603 oldInfo.InsertInnerModuleInfo(MODULE_NAME, innerModuleInfo);
4604 installer.CheckEnableRemovable(newInfos, oldInfo, userId, isFreeInstallFlag, isAppExist);
4605
4606 bool existModule = oldInfo.FindModule(MODULE_NAME);
4607 EXPECT_EQ(existModule, true);
4608 }
4609
4610 /**
4611 * @tc.number: CheckEnableRemovable_0040
4612 * @tc.name: CheckEnableRemovable
4613 * @tc.desc: test CheckEnableRemovable
4614 */
4615 HWTEST_F(BmsBundleInstallerTest, CheckEnableRemovable_0040, TestSize.Level1)
4616 {
4617 BaseBundleInstaller installer;
4618 InnerBundleInfo newInfo;
4619 std::unordered_map<std::string, InnerBundleInfo> newInfos;
4620 InnerBundleInfo oldInfo;
4621 int32_t userId = USERID;
4622 installer.CheckEnableRemovable(newInfos, oldInfo, userId, true, true);
4623 bool existModule = oldInfo.FindModule(MODULE_NAME);
4624 EXPECT_EQ(existModule, false);
4625 }
4626
4627 /**
4628 * @tc.number: CheckEnableRemovable_0050
4629 * @tc.name: CheckEnableRemovable
4630 * @tc.desc: test CheckEnableRemovable
4631 */
4632 HWTEST_F(BmsBundleInstallerTest, CheckEnableRemovable_0050, TestSize.Level1)
4633 {
4634 BaseBundleInstaller installer;
4635 InnerBundleInfo newInfo;
4636 std::unordered_map<std::string, InnerBundleInfo> newInfos;
4637 newInfos.emplace("", newInfo);
4638 InnerBundleInfo oldInfo;
4639 InnerBundleUserInfo innerBundleUserInfo;
4640 std::string key = BUNDLE_NAME + "_100";
4641 oldInfo.innerBundleUserInfos_.insert(pair<std::string, InnerBundleUserInfo>(key, innerBundleUserInfo));
4642 int32_t userId = USERID;
4643 InnerModuleInfo innerModuleInfo;
4644 innerModuleInfo.name = MODULE_NAME;
4645 innerModuleInfo.modulePackage = MODULE_NAME;
4646 newInfo.InsertInnerModuleInfo(MODULE_NAME, innerModuleInfo);
4647 oldInfo.InsertInnerModuleInfo(MODULE_NAME, innerModuleInfo);
4648 installer.CheckEnableRemovable(newInfos, oldInfo, userId, true, true);
4649
4650 bool existModule = oldInfo.FindModule(MODULE_NAME);
4651 EXPECT_EQ(existModule, true);
4652 }
4653
4654 /**
4655 * @tc.number: InnerProcessBundleInstall_0010
4656 * @tc.name: CheckEnableRemovable
4657 * @tc.desc: test CheckEnableRemovable
4658 */
4659 HWTEST_F(BmsBundleInstallerTest, InnerProcessBundleInstall_0010, TestSize.Level1)
4660 {
4661 BaseBundleInstaller installer;
4662 std::unordered_map<std::string, InnerBundleInfo> newInfos;
4663 InnerBundleInfo innerBundleInfo;
4664 innerBundleInfo.SetSingleton(false);
4665 newInfos.insert(pair<std::string, InnerBundleInfo>());
4666 InnerBundleInfo oldInfo;
4667 InstallParam installParam;
4668 installParam.needSavePreInstallInfo = false;
4669 int32_t uid = EDM_UID;
4670 installer.isAppExist_ = true;
4671 ClearDataMgr();
4672 auto res = installer.InnerProcessBundleInstall(newInfos, oldInfo, installParam, uid);
4673 installer.RollBack(newInfos, oldInfo);
4674 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_BUNDLE_MGR_SERVICE_ERROR);
4675 ResetDataMgr();
4676 }
4677
4678 /**
4679 * @tc.number: InnerProcessBundleInstall_0020
4680 * @tc.name: CheckEnableRemovable
4681 * @tc.desc: test CheckEnableRemovable
4682 */
4683 HWTEST_F(BmsBundleInstallerTest, InnerProcessBundleInstall_0020, TestSize.Level1)
4684 {
4685 BaseBundleInstaller installer;
4686 std::unordered_map<std::string, InnerBundleInfo> newInfos;
4687 InnerBundleInfo innerBundleInfo;
4688 innerBundleInfo.SetSingleton(false);
4689 newInfos.insert(std::pair<std::string, InnerBundleInfo>(BUNDLE_NAME_TEST, innerBundleInfo));
4690 int32_t uid = EDM_UID;
4691 InnerBundleInfo oldInfo;
4692 InstallParam installParam;
4693 installParam.needSavePreInstallInfo = false;
4694 installer.isAppExist_ = true;
4695 oldInfo.SetApplicationBundleType(BundleType::SHARED);
4696 auto res = installer.InnerProcessBundleInstall(newInfos, oldInfo, installParam, uid);
4697 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_COMPATIBLE_POLICY_NOT_SAME);
4698 }
4699
4700 /**
4701 * @tc.number: ProcessModuleUpdate_0020
4702 * @tc.name: test ProcessBundleInstallStatus
4703 * @tc.desc: 1.Test the ProcessBundleInstallStatus
4704 */
4705 HWTEST_F(BmsBundleInstallerTest, ProcessModuleUpdate_0020, Function | SmallTest | Level0)
4706 {
4707 BaseBundleInstaller installer;
4708 InnerBundleInfo innerBundleInfo;
4709 InnerBundleInfo oldInfo;
4710 bool isReplace = true;
4711 bool killProcess = false;
4712 innerBundleInfo.userId_ = USERID;
4713 ErrCode res = installer.ProcessModuleUpdate(innerBundleInfo, oldInfo, isReplace, killProcess);
4714 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_INCONSISTENT_MODULE_NAME);
4715 }
4716
4717 /**
4718 * @tc.number: CreateBundleDataDir_0010
4719 * @tc.name: test CreateBundleDataDir
4720 * @tc.desc: 1.Test the CreateBundleDataDir
4721 */
4722 HWTEST_F(BmsBundleInstallerTest, CreateBundleDataDir_0010, Function | SmallTest | Level0)
4723 {
4724 BaseBundleInstaller installer;
4725 installer.userId_ = ServiceConstants::NOT_EXIST_USERID;
4726 InnerBundleInfo info;
4727 installer.InitDataMgr();
4728 ErrCode res = installer.CreateBundleDataDir(info);
4729 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_GENERATE_UID_ERROR);
4730 }
4731
4732 /**
4733 * @tc.number: CreateBundleDataDir_0020
4734 * @tc.name: test CreateBundleDataDir
4735 * @tc.desc: 1.Test the CreateBundleDataDir
4736 */
4737 HWTEST_F(BmsBundleInstallerTest, CreateBundleDataDir_0020, Function | SmallTest | Level0)
4738 {
4739 InnerBundleInfo info;
4740 BundleInfo bundleInfo;
4741 bundleInfo.name = BUNDLE_NAME_TEST;
4742 bundleInfo.applicationInfo.name = BUNDLE_NAME;
4743 ApplicationInfo applicationInfo;
4744 applicationInfo.name = BUNDLE_NAME_TEST;
4745 applicationInfo.deviceId = DEVICE_ID;
4746 applicationInfo.bundleName = BUNDLE_NAME_TEST;
4747 info.SetBaseBundleInfo(bundleInfo);
4748 info.SetBaseApplicationInfo(applicationInfo);
4749 info.SetAppType(Constants::AppType::SYSTEM_APP);
4750 InnerBundleUserInfo innerBundleUserInfo;
4751 innerBundleUserInfo.bundleUserInfo.userId = 0;
4752 innerBundleUserInfo.bundleName = BUNDLE_NAME_TEST;
4753 auto dataMgr = DelayedSingleton<BundleMgrService>::GetInstance()->GetDataMgr();
4754 ASSERT_NE(dataMgr, nullptr);
4755 dataMgr->installStates_.clear();
4756 dataMgr->bundleInfos_.clear();
4757 bool ret1 = dataMgr->UpdateBundleInstallState(BUNDLE_NAME_TEST, InstallState::INSTALL_START);
4758 bool ret2 = dataMgr->AddInnerBundleInfo(BUNDLE_NAME_TEST, info);
4759 bool ret3 = dataMgr->GenerateUidAndGid(innerBundleUserInfo);
4760 EXPECT_TRUE(ret1);
4761 EXPECT_TRUE(ret2);
4762 EXPECT_TRUE(ret3);
4763
4764 BaseBundleInstaller installer;
4765 installer.InitDataMgr();
4766 installer.userId_ = ServiceConstants::NOT_EXIST_USERID;
4767 ErrCode res = installer.CreateBundleDataDir(info);
4768 EXPECT_NE(res, ERR_OK);
4769
4770 ret3 = dataMgr->UpdateBundleInstallState(BUNDLE_NAME_TEST, InstallState::UNINSTALL_START);
4771 EXPECT_TRUE(ret3);
4772 ret3 = dataMgr->UpdateBundleInstallState(BUNDLE_NAME_TEST, InstallState::UNINSTALL_SUCCESS);
4773 EXPECT_TRUE(ret3);
4774 }
4775
4776 /**
4777 * @tc.number: ExtractModule_0010
4778 * @tc.name: test ExtractModule
4779 * @tc.desc: 1.Test the ExtractModule
4780 */
4781 HWTEST_F(BmsBundleInstallerTest, ExtractModule_0010, Function | SmallTest | Level0)
4782 {
4783 InnerBundleInfo info;
4784 info.currentPackage_ = MODULE_NAME_TEST;
4785 InnerModuleInfo moduleInfo;
4786 moduleInfo.name = MODULE_NAME_TEST;
4787 moduleInfo.moduleName = MODULE_NAME_TEST;
4788 moduleInfo.modulePackage = MODULE_NAME_TEST;
4789 moduleInfo.isLibIsolated = false;
4790 moduleInfo.compressNativeLibs = true;
4791 info.innerModuleInfos_[MODULE_NAME_TEST] = moduleInfo;
4792 info.baseApplicationInfo_->cpuAbi = TEST_CPU_ABI;
4793 info.baseApplicationInfo_->nativeLibraryPath = "";
4794
4795 BaseBundleInstaller installer;
4796 installer.modulePackage_ = MODULE_NAME_TEST;
4797 std::string modulePath = "/data/test/bms_bundle_installer";
4798 installer.modulePath_ = RESOURCE_ROOT_PATH + RIGHT_BUNDLE;
4799 ErrCode ret = installer.InnerProcessNativeLibs(info, modulePath);
4800 EXPECT_EQ(ret, ERR_OK);
4801
4802 info.SetIsNewVersion(true);
4803 ErrCode res = installer.ExtractModule(info, modulePath);
4804 EXPECT_EQ(res, ERR_OK);
4805
4806 info.baseApplicationInfo_->arkNativeFilePath = "";
4807 info.baseApplicationInfo_->arkNativeFileAbi = "errorType";
4808 res = installer.ExtractModule(info, modulePath);
4809 EXPECT_EQ(res, ERR_APPEXECFWK_PARSE_AN_FAILED);
4810 }
4811
4812 /**
4813 * @tc.number: RenameModuleDir_0010
4814 * @tc.name: test RenameModuleDir
4815 * @tc.desc: 1.Test the RenameModuleDir
4816 */
4817 HWTEST_F(BmsBundleInstallerTest, RenameModuleDir_0010, Function | SmallTest | Level0)
4818 {
4819 BaseBundleInstaller installer;
4820 InnerBundleInfo info;
4821 info.currentPackage_ = BUNDLE_NAME_TEST;
4822 ErrCode res = installer.RenameModuleDir(info);
4823 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALLD_RNAME_DIR_FAILED);
4824 }
4825
4826 /**
4827 * @tc.number: CheckApiInfo_0010
4828 * @tc.name: test CheckApiInfo
4829 * @tc.desc: 1.Test the CheckApiInfo
4830 */
4831 HWTEST_F(BmsBundleInstallerTest, CheckApiInfo_0010, Function | SmallTest | Level0)
4832 {
4833 BaseBundleInstaller installer;
4834 installer.singletonState_ = AppExecFwk::BaseBundleInstaller::SingletonState::SINGLETON_TO_NON;
4835 bool killProcess = false;
4836 std::unordered_map<std::string, InnerBundleInfo> info;
4837 InnerBundleInfo innerBundleInfo;
4838 innerBundleInfo.baseApplicationInfo_->compileSdkType = "OpenHarmony";
4839 installer.OnSingletonChange(killProcess);
4840 info.try_emplace("OpenHarmony", innerBundleInfo);
4841
4842 bool res = installer.CheckApiInfo(info);
4843 EXPECT_EQ(res, true);
4844 }
4845
4846 /**
4847 * @tc.number: CheckApiInfo_0030
4848 * @tc.name: test CheckApiInfo
4849 * @tc.desc: 1.Test the CheckApiInfo
4850 */
4851 HWTEST_F(BmsBundleInstallerTest, CheckApiInfo_0030, Function | SmallTest | Level0)
4852 {
4853 BaseBundleInstaller installer;
4854 installer.singletonState_ = AppExecFwk::BaseBundleInstaller::SingletonState::NON_TO_SINGLETON;
4855 bool killProcess = false;
4856 std::unordered_map<std::string, InnerBundleInfo> info;
4857 InnerBundleInfo innerBundleInfo;
4858 innerBundleInfo.baseApplicationInfo_->compileSdkType = "OpenHarmony1";
4859 innerBundleInfo.baseBundleInfo_->compatibleVersion = COMPATIBLE_VERSION;
4860 installer.OnSingletonChange(killProcess);
4861 info.try_emplace("OpenHarmony2", innerBundleInfo);
4862
4863 bool res = installer.CheckApiInfo(info);
4864 EXPECT_EQ(res, true);
4865 }
4866
4867 /**
4868 * @tc.number: UninstallLowerVersionFeature_0010
4869 * @tc.name: test UninstallLowerVersionFeature
4870 * @tc.desc: 1.Test the UninstallLowerVersionFeature
4871 */
4872 HWTEST_F(BmsBundleInstallerTest, UninstallLowerVersionFeature_0010, Function | SmallTest | Level0)
4873 {
4874 BaseBundleInstaller installer;
4875 installer.dataMgr_ = GetBundleDataMgr();
4876 std::vector<std::string> packageVec;
4877 ClearDataMgr();
__anon6182b48f0202null4878 ScopeGuard stateGuard([&] { ResetDataMgr(); });
4879 ErrCode res = installer.UninstallLowerVersionFeature(packageVec);
4880 EXPECT_EQ(res, ERR_APPEXECFWK_UNINSTALL_BUNDLE_MGR_SERVICE_ERROR);
4881 }
4882
4883 /**
4884 * @tc.number: UninstallLowerVersionFeature_0020
4885 * @tc.name: test UninstallLowerVersionFeature
4886 * @tc.desc: 1.Test the UninstallLowerVersionFeature
4887 */
4888 HWTEST_F(BmsBundleInstallerTest, UninstallLowerVersionFeature_0020, Function | SmallTest | Level0)
4889 {
4890 BaseBundleInstaller installer;
4891 std::vector<std::string> packageVec;
4892 installer.bundleName_ = "";
4893 ErrCode res = installer.UninstallLowerVersionFeature(packageVec);
4894 EXPECT_EQ(res, ERR_APPEXECFWK_UNINSTALL_BUNDLE_MGR_SERVICE_ERROR);
4895 }
4896
4897 /**
4898 * @tc.number: GetUserId_0010
4899 * @tc.name: test GetUserId
4900 * @tc.desc: 1.Test the GetUserId
4901 */
4902 HWTEST_F(BmsBundleInstallerTest, GetUserId_0010, Function | SmallTest | Level0)
4903 {
4904 BaseBundleInstaller installer;
4905 int32_t res = installer.GetUserId(Constants::INVALID_USERID);
4906 EXPECT_EQ(res, Constants::INVALID_USERID);
4907 }
4908
4909 /**
4910 * @tc.number: CheckAppLabel_0020
4911 * @tc.name: test CheckAppLabel
4912 * @tc.desc: 1.Test the CheckAppLabel
4913 */
4914 HWTEST_F(BmsBundleInstallerTest, CheckAppLabel_0020, Function | SmallTest | Level0)
4915 {
4916 BaseBundleInstaller installer;
4917 InnerBundleInfo oldInfo;
4918 InnerBundleInfo newInfo;
4919 oldInfo.baseBundleInfo_->minCompatibleVersionCode = USERID;
4920 ErrCode res = installer.CheckAppLabel(oldInfo, newInfo);
4921 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_MINCOMPATIBLE_VERSIONCODE_NOT_SAME);
4922 }
4923
4924 /**
4925 * @tc.number: CheckAppLabel_0040
4926 * @tc.name: test CheckAppLabel
4927 * @tc.desc: 1.Test the CheckAppLabel
4928 */
4929 HWTEST_F(BmsBundleInstallerTest, CheckAppLabel_0040, Function | SmallTest | Level0)
4930 {
4931 BaseBundleInstaller installer;
4932 InnerBundleInfo oldInfo;
4933 InnerBundleInfo newInfo;
4934 oldInfo.baseBundleInfo_->targetVersion = USERID;
4935 ErrCode res = installer.CheckAppLabel(oldInfo, newInfo);
4936 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_RELEASETYPE_TARGET_NOT_SAME);
4937 }
4938
4939 /**
4940 * @tc.number: CheckAppLabel_0050
4941 * @tc.name: test CheckAppLabel
4942 * @tc.desc: 1.Test the CheckAppLabel
4943 */
4944 HWTEST_F(BmsBundleInstallerTest, CheckAppLabel_0050, Function | SmallTest | Level0)
4945 {
4946 BaseBundleInstaller installer;
4947 InnerBundleInfo oldInfo;
4948 InnerBundleInfo newInfo;
4949 oldInfo.baseBundleInfo_->compatibleVersion = USERID;
4950 ErrCode res = installer.CheckAppLabel(oldInfo, newInfo);
4951 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_RELEASETYPE_COMPATIBLE_NOT_SAME);
4952 }
4953
4954 /**
4955 * @tc.number: ExecuteAOT_0100
4956 * @tc.name: test CheckAppLabel
4957 * @tc.desc: 1.Test the CheckAppLabel
4958 */
4959 HWTEST_F(BmsBundleInstallerTest, ExecuteAOT_0100, Function | SmallTest | Level0)
4960 {
4961 InstalldHostImpl impl;
4962 AOTArgs aotArgs;
4963 std::vector<uint8_t> pendSignData;
4964 auto ret = impl.ExecuteAOT(aotArgs, pendSignData);
4965 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
4966 }
4967
4968 /**
4969 * @tc.number: SetDirApl_0100
4970 * @tc.name: test CheckAppLabel
4971 * @tc.desc: 1.Test the CheckAppLabel
4972 */
4973 HWTEST_F(BmsBundleInstallerTest, SetDirApl_0100, Function | SmallTest | Level0)
4974 {
4975 InstalldHostImpl impl;
4976 bool isPreInstallApp = false;
4977 bool debug = false;
4978 auto ret = impl.SetDirApl("", BUNDLE_NAME, "", isPreInstallApp, debug);
4979 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
4980
4981 ret = impl.SetDirApl(BUNDLE_DATA_DIR, "", "", isPreInstallApp, debug);
4982 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
4983
4984 ret = impl.SetDirApl("", "", "", isPreInstallApp, debug);
4985 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
4986
4987 ret = impl.SetDirApl(BUNDLE_DATA_DIR, BUNDLE_NAME, "", isPreInstallApp, debug);
4988 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_SET_SELINUX_LABEL_FAILED);
4989 }
4990
4991 /**
4992 * @tc.number: GetHapFilesFromBundlePath_0100
4993 * @tc.name: test GetHapFilesFromBundlePath, reach the max hap number 128, stop to add more
4994 * @tc.desc: 1.test GetHapFilesFromBundlePath of BundleUtil
4995 */
4996 HWTEST_F(BmsBundleInstallerTest, GetHapFilesFromBundlePath_0100, Function | SmallTest | Level0)
4997 {
4998 BundleUtil bundleUtil;
4999 auto ret = bundleUtil.CreateTempDir(CURRENT_PATH);
5000 EXPECT_EQ(ret, CURRENT_PATH);
5001 std::vector<std::string> fileList;
5002 for (int i = 0; i < ServiceConstants::MAX_HAP_NUMBER + 1; i++) {
5003 std::string tmpFile = CURRENT_PATH + ServiceConstants::PATH_SEPARATOR + "test" + std::to_string(i) + ".hap";
5004 bool ret2 = SaveStringToFile(tmpFile, tmpFile);
5005 EXPECT_EQ(ret2, true);
5006 fileList.emplace_back(tmpFile);
5007 }
5008 bundleUtil.MakeFsConfig("testWrong.hap", 1, "/data/testWrong");
5009 bool res = bundleUtil.GetHapFilesFromBundlePath(CURRENT_PATH, fileList);
5010 EXPECT_EQ(res, false);
5011 bundleUtil.DeleteTempDirs(fileList);
5012 }
5013
5014 /**
5015 * @tc.number: CreateInstallTempDir_1700
5016 * @tc.name: test CreateInstallTempDir
5017 * @tc.desc: 1.test type == DirType::SIG_FILE_DIR
5018 */
5019 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_1700, Function | SmallTest | Level0)
5020 {
5021 BundleUtil bundleUtil;
5022 const int32_t installId = 2022;
5023 std::string res = bundleUtil.CreateInstallTempDir(installId, DirType::SIG_FILE_DIR);
5024 EXPECT_NE(res, "");
5025 auto ret = bundleUtil.DeleteDir(res);
5026 EXPECT_EQ(ret, true);
5027 }
5028
5029 /**
5030 * @tc.number: CreateFileDescriptor_100
5031 * @tc.name: test CreateFileDescriptor
5032 * @tc.desc: 1.test the length of the bundlePath exceeds maximum limitation
5033 */
5034 HWTEST_F(BmsBundleInstallerTest, CreateFileDescriptor_100, Function | SmallTest | Level0)
5035 {
5036 BundleUtil bundleUtil;
5037 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
5038 bundlePath.append(std::string(256, '/'));
5039 long long offset = 0;
5040 auto ret = bundleUtil.CreateFileDescriptor(bundlePath, offset);
5041 EXPECT_EQ(ret, -1);
5042 }
5043
5044 /**
5045 * @tc.number: CreateFileDescriptor_200
5046 * @tc.name: test CreateFileDescriptor
5047 * @tc.desc: 1.test offset > 0
5048 */
5049 HWTEST_F(BmsBundleInstallerTest, CreateFileDescriptor_200, Function | SmallTest | Level0)
5050 {
5051 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
5052 BundleUtil bundleUtil;
5053 long long offset = 1;
5054 auto ret = bundleUtil.CreateFileDescriptor(bundlePath, offset);
5055 EXPECT_NE(ret, -1);
5056 }
5057
5058 /**
5059 * @tc.number: CreateFileDescriptorForReadOnly_100
5060 * @tc.name: test CreateFileDescriptorForReadOnly
5061 * @tc.desc: 1.file is not real path
5062 */
5063 HWTEST_F(BmsBundleInstallerTest, CreateFileDescriptorForReadOnly_100, Function | SmallTest | Level0)
5064 {
5065 std::string bundlePath = "/testWrong/testWrong.hap";
5066 BundleUtil bundleUtil;
5067 long long offset = 1;
5068 auto ret = bundleUtil.CreateFileDescriptorForReadOnly(bundlePath, offset);
5069 EXPECT_EQ(ret, -1);
5070 }
5071
5072 /**
5073 * @tc.number: CreateFileDescriptorForReadOnly_200
5074 * @tc.name: test CreateFileDescriptorForReadOnly
5075 * @tc.desc: 1.test offset > 0
5076 */
5077 HWTEST_F(BmsBundleInstallerTest, CreateFileDescriptorForReadOnly_200, Function | SmallTest | Level0)
5078 {
5079 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
5080 BundleUtil bundleUtil;
5081 long long offset = 1;
5082 auto ret = bundleUtil.CreateFileDescriptorForReadOnly(bundlePath, offset);
5083 EXPECT_NE(ret, -1);
5084 }
5085
5086 /**
5087 * @tc.number: CreateDir_DeleteDir_100
5088 * @tc.name: test CreateDir and DeleteDir
5089 * @tc.desc: 1.file exist
5090 */
5091 HWTEST_F(BmsBundleInstallerTest, CreateDir_DeleteDir_100, Function | SmallTest | Level0)
5092 {
5093 BundleUtil bundleUtil;
5094 auto ret = bundleUtil.CreateDir(TEST_CREATE_FILE_PATH);
5095 EXPECT_EQ(ret, true);
5096 auto ret2 = bundleUtil.CreateDir(TEST_CREATE_FILE_PATH);
5097 EXPECT_EQ(ret2, true);
5098 auto ret3 = bundleUtil.DeleteDir(TEST_CREATE_FILE_PATH);
5099 EXPECT_EQ(ret3, true);
5100 }
5101
5102 /**
5103 * @tc.number: CopyFileToSecurityDir_100
5104 * @tc.name: test CopyFileToSecurityDir
5105 * @tc.desc: 1.CopyFileToSecurityDir
5106 */
5107 HWTEST_F(BmsBundleInstallerTest, CopyFileToSecurityDir_100, Function | SmallTest | Level0)
5108 {
5109 BundleUtil bundleUtil;
5110 std::vector<std::string> toDeletePaths;
5111 auto ret = bundleUtil.CopyFileToSecurityDir("", DirType::STREAM_INSTALL_DIR, toDeletePaths);
5112 EXPECT_EQ(ret, "");
5113 EXPECT_EQ(toDeletePaths.size(), 0);
5114 }
5115
5116 /**
5117 * @tc.number: CopyFileToSecurityDir_200
5118 * @tc.name: test CopyFileToSecurityDir
5119 * @tc.desc: 1.CopyFileToSecurityDir
5120 */
5121 HWTEST_F(BmsBundleInstallerTest, CopyFileToSecurityDir_200, Function | SmallTest | Level0)
5122 {
5123 BundleUtil bundleUtil;
5124 std::vector<std::string> toDeletePaths;
5125 bool res1 = bundleUtil.CreateDir(TEST_CREATE_DIR_PATH);
5126 EXPECT_TRUE(res1);
5127 bool res2 = SaveStringToFile(TEST_CREATE_FILE_PATH, TEST_CREATE_FILE_PATH);
5128 EXPECT_TRUE(res2);
5129 bundleUtil.CopyFileToSecurityDir(TEST_CREATE_FILE_PATH, DirType::SIG_FILE_DIR, toDeletePaths);
5130 bool res3 = bundleUtil.DeleteDir(TEST_CREATE_DIR_PATH);
5131 EXPECT_TRUE(res3);
5132 ASSERT_GT(toDeletePaths.size(), 0);
5133 bundleUtil.DeleteTempDirs(toDeletePaths);
5134 }
5135
5136 /**
5137 * @tc.number: CopyFileToSecurityDir_300
5138 * @tc.name: test CopyFileToSecurityDir
5139 * @tc.desc: 1.CopyFileToSecurityDir
5140 */
5141 HWTEST_F(BmsBundleInstallerTest, CopyFileToSecurityDir_300, Function | SmallTest | Level0)
5142 {
5143 BundleUtil bundleUtil;
5144 std::vector<std::string> toDeletePaths;
5145 std::string sourcePath = TEST_CREATE_DIR_PATH + ServiceConstants::PATH_SEPARATOR
5146 + ServiceConstants::SIGNATURE_FILE_PATH;
5147 auto ret = bundleUtil.CopyFileToSecurityDir(sourcePath, DirType::SIG_FILE_DIR, toDeletePaths);
5148 EXPECT_EQ(ret, "");
5149 EXPECT_EQ(toDeletePaths.size(), 0);
5150 }
5151
5152 /**
5153 * @tc.number: CopyFileToSecurityDir_400
5154 * @tc.name: test CopyFileToSecurityDir
5155 * @tc.desc: 1.CopyFileToSecurityDir
5156 */
5157 HWTEST_F(BmsBundleInstallerTest, CopyFileToSecurityDir_400, Function | SmallTest | Level0)
5158 {
5159 BundleUtil bundleUtil;
5160 std::vector<std::string> toDeletePaths;
5161 std::string sourcePath = TEST_CREATE_DIR_PATH + ServiceConstants::PATH_SEPARATOR +
5162 ServiceConstants::SIGNATURE_FILE_PATH + ServiceConstants::PATH_SEPARATOR;
5163 auto ret = bundleUtil.CopyFileToSecurityDir(sourcePath, DirType::SIG_FILE_DIR, toDeletePaths);
5164 EXPECT_EQ(ret, "");
5165 EXPECT_EQ(toDeletePaths.size(), 0);
5166 }
5167
5168 /**
5169 * @tc.number: CopyFileToSecurityDir_500
5170 * @tc.name: test CopyFileToSecurityDir
5171 * @tc.desc: 1.CopyFileToSecurityDir
5172 */
5173 HWTEST_F(BmsBundleInstallerTest, CopyFileToSecurityDir_500, Function | SmallTest | Level0)
5174 {
5175 BundleUtil bundleUtil;
5176 std::vector<std::string> toDeletePaths;
5177 std::string sourcePath = TEST_CREATE_DIR_PATH + ServiceConstants::PATH_SEPARATOR +
5178 ServiceConstants::SIGNATURE_FILE_PATH + ServiceConstants::PATH_SEPARATOR;
5179 sourcePath.append("test");
5180 auto ret1 = bundleUtil.CopyFileToSecurityDir(sourcePath, DirType::SIG_FILE_DIR, toDeletePaths);
5181 EXPECT_EQ(ret1, "");
5182 EXPECT_EQ(toDeletePaths.size(), 0);
5183 sourcePath.append(ServiceConstants::PATH_SEPARATOR);
5184 auto ret2 = bundleUtil.CopyFileToSecurityDir(sourcePath, DirType::SIG_FILE_DIR, toDeletePaths);
5185 EXPECT_EQ(ret2, "");
5186 EXPECT_EQ(toDeletePaths.size(), 0);
5187 }
5188
5189 /**
5190 * @tc.number: CopyFileToSecurityDir_600
5191 * @tc.name: test CopyFileToSecurityDir
5192 * @tc.desc: 1.CopyFileToSecurityDir
5193 */
5194 HWTEST_F(BmsBundleInstallerTest, CopyFileToSecurityDir_600, Function | SmallTest | Level0)
5195 {
5196 BundleUtil bundleUtil;
5197 std::vector<std::string> toDeletePaths;
5198 std::string sourcePath = TEST_CREATE_DIR_PATH + ServiceConstants::PATH_SEPARATOR +
5199 ServiceConstants::SIGNATURE_FILE_PATH + ServiceConstants::PATH_SEPARATOR + "test" +
5200 ServiceConstants::PATH_SEPARATOR + "testSourcePath";
5201 bool ret1 = bundleUtil.CreateDir(sourcePath);
5202 EXPECT_TRUE(ret1);
5203 std::string sourceFile = sourcePath.append(ServiceConstants::PATH_SEPARATOR).append("testSourceFile.hap");
5204 bool ret2 = SaveStringToFile(sourceFile, sourceFile);
5205 EXPECT_TRUE(ret2);
5206 bundleUtil.CopyFileToSecurityDir(sourcePath, DirType::SIG_FILE_DIR, toDeletePaths);
5207 bool ret3 = bundleUtil.DeleteDir(sourcePath);
5208 EXPECT_TRUE(ret3);
5209 ASSERT_GT(toDeletePaths.size(), 0);
5210 bundleUtil.DeleteTempDirs(toDeletePaths);
5211 }
5212
5213 /**
5214 * @tc.number: CheckDependency_0010
5215 * @tc.name: test CheckDependency
5216 * @tc.desc: 1.CheckDependency
5217 */
5218 HWTEST_F(BmsBundleInstallerTest, CheckDependency_0010, Function | SmallTest | Level0)
5219 {
5220 InstallParam installParam;
5221 auto appType = Constants::AppType::THIRD_PARTY_APP;
5222 SharedBundleInstaller bundleInstaller(installParam, appType);
5223
5224 Dependency dependency;
5225 dependency.bundleName = BUNDLE_NAME;
5226 InnerModuleInfo innerModuleInfo;
5227 innerModuleInfo.dependencies.push_back(dependency);
5228 InnerBundleInfo innerBundleInfo;
5229 innerBundleInfo.innerModuleInfos_.insert(std::pair<std::string, InnerModuleInfo>(BUNDLE_NAME, innerModuleInfo));
5230 ClearDataMgr();
__anon6182b48f0302null5231 ScopeGuard stateGuard([&] { ResetDataMgr(); });
5232 auto res = bundleInstaller.CheckDependency(innerBundleInfo);
5233 EXPECT_FALSE(res);
5234 }
5235
5236 /**
5237 * @tc.number: FindDependencyInInstalledBundles_0010
5238 * @tc.name: test FindDependencyInInstalledBundles
5239 * @tc.desc: 1.FindDependencyInInstalledBundles
5240 */
5241 HWTEST_F(BmsBundleInstallerTest, FindDependencyInInstalledBundles_0010, Function | SmallTest | Level0)
5242 {
5243 InstallParam installParam;
5244 auto appType = Constants::AppType::THIRD_PARTY_APP;
5245 SharedBundleInstaller bundleInstaller(installParam, appType);
5246
5247 Dependency dependency;
5248 ClearDataMgr();
__anon6182b48f0402null5249 ScopeGuard stateGuard([&] { ResetDataMgr(); });
5250 auto res = bundleInstaller.FindDependencyInInstalledBundles(dependency);
5251 EXPECT_FALSE(res);
5252 }
5253
5254 /**
5255 * @tc.number: GetCallingEventInfo_0010
5256 * @tc.name: test GetCallingEventInfo
5257 * @tc.desc: 1.GetCallingEventInfo
5258 */
5259 HWTEST_F(BmsBundleInstallerTest, GetCallingEventInfo_0010, Function | SmallTest | Level0)
5260 {
5261 InstallParam installParam;
5262 auto appType = Constants::AppType::THIRD_PARTY_APP;
5263 SharedBundleInstaller bundleInstaller(installParam, appType);
5264
5265 EventInfo eventInfo;
5266 ClearDataMgr();
__anon6182b48f0502null5267 ScopeGuard stateGuard([&] { ResetDataMgr(); });
5268 bundleInstaller.GetCallingEventInfo(eventInfo);
5269 EXPECT_EQ(eventInfo.callingBundleName, EMPTY_STRING);
5270 }
5271
5272 /**
5273 * @tc.number: baseBundleInstaller_0100
5274 * @tc.name: test CheckAppIdentifier
5275 * @tc.desc: 1.Test the CheckAppIdentifier
5276 */
5277 HWTEST_F(BmsBundleInstallerTest, CheckAppIdentifier_0100, Function | SmallTest | Level0)
5278 {
5279 std::string oldAppIdentifier = "appIdentifier";
5280 std::string newAppIdentifier = "appIdentifier";
5281 std::string oldAppId = "appId";
5282 std::string newAppId = "appId";
5283 BaseBundleInstaller installer;
5284 bool res = installer.CheckAppIdentifier(oldAppIdentifier, newAppIdentifier, oldAppId, newAppId);
5285 EXPECT_TRUE(res);
5286 }
5287
5288 /**
5289 * @tc.number: baseBundleInstaller_0200
5290 * @tc.name: test CheckAppIdentifier
5291 * @tc.desc: 1.Test the CheckAppIdentifier
5292 */
5293 HWTEST_F(BmsBundleInstallerTest, CheckAppIdentifier_0200, Function | SmallTest | Level0)
5294 {
5295 std::string oldAppIdentifier = "";
5296 std::string newAppIdentifier = "appIdentifier";
5297 std::string oldAppId = "oldAppId";
5298 std::string newAppId = "newAppId";
5299 BaseBundleInstaller installer;
5300 bool res = installer.CheckAppIdentifier(oldAppIdentifier, newAppIdentifier, oldAppId, newAppId);
5301 EXPECT_FALSE(res);
5302 }
5303
5304 /**
5305 * @tc.number: baseBundleInstaller_0300
5306 * @tc.name: test CheckAppIdentifier
5307 * @tc.desc: 1.Test the CheckAppIdentifier
5308 */
5309 HWTEST_F(BmsBundleInstallerTest, CheckAppIdentifier_0300, Function | SmallTest | Level0)
5310 {
5311 std::string oldAppIdentifier = "appIdentifier";
5312 std::string newAppIdentifier = "";
5313 std::string oldAppId = "oldAppId";
5314 std::string newAppId = "newAppId";
5315 BaseBundleInstaller installer;
5316 bool res = installer.CheckAppIdentifier(oldAppIdentifier, newAppIdentifier, oldAppId, newAppId);
5317 EXPECT_FALSE(res);
5318 }
5319
5320 /**
5321 * @tc.number: CheckAppIdentifier_0400
5322 * @tc.name: test CheckAppIdentifier
5323 * @tc.desc: 1.Test the CheckAppIdentifier
5324 */
5325 HWTEST_F(BmsBundleInstallerTest, CheckAppIdentifier_0400, Function | SmallTest | Level0)
5326 {
5327 std::string oldAppIdentifier = "";
5328 std::string newAppIdentifier = "";
5329 std::string oldAppId = "oldAppId";
5330 std::string newAppId = "newAppId";
5331 BaseBundleInstaller installer;
5332 bool res = installer.CheckAppIdentifier(oldAppIdentifier, newAppIdentifier, oldAppId, newAppId);
5333 EXPECT_FALSE(res);
5334 }
5335
5336 /**
5337 * @tc.number: CheckAppIdentifier_0500
5338 * @tc.name: test CheckAppIdentifier
5339 * @tc.desc: 1.Test the CheckAppIdentifier
5340 */
5341 HWTEST_F(BmsBundleInstallerTest, CheckAppIdentifier_0500, Function | SmallTest | Level0)
5342 {
5343 std::string oldAppIdentifier = "";
5344 std::string newAppIdentifier = "";
5345 std::string oldAppId = "appId";
5346 std::string newAppId = "appId";
5347 BaseBundleInstaller installer;
5348 bool res = installer.CheckAppIdentifier(oldAppIdentifier, newAppIdentifier, oldAppId, newAppId);
5349 EXPECT_TRUE(res);
5350 }
5351
5352 /**
5353 * @tc.number: CheckAppIdentifier_0600
5354 * @tc.name: test CheckAppIdentifier
5355 * @tc.desc: 1.Test the CheckAppIdentifier
5356 */
5357 HWTEST_F(BmsBundleInstallerTest, CheckAppIdentifier_0600, Function | SmallTest | Level0)
5358 {
5359 std::string oldAppIdentifier = "";
5360 std::string newAppIdentifier = "newAppIdentifier";
5361 std::string oldAppId = "appId";
5362 std::string newAppId = "appId";
5363 BaseBundleInstaller installer;
5364 bool res = installer.CheckAppIdentifier(oldAppIdentifier, newAppIdentifier, oldAppId, newAppId);
5365 EXPECT_TRUE(res);
5366 }
5367
5368 /**
5369 * @tc.number: CheckAppIdentifier_0700
5370 * @tc.name: test CheckAppIdentifier
5371 * @tc.desc: 1.Test the CheckAppIdentifier
5372 */
5373 HWTEST_F(BmsBundleInstallerTest, CheckAppIdentifier_0700, Function | SmallTest | Level0)
5374 {
5375 std::string oldAppIdentifier = "oldAppIdentifier";
5376 std::string newAppIdentifier = "";
5377 std::string oldAppId = "appId";
5378 std::string newAppId = "appId";
5379 BaseBundleInstaller installer;
5380 bool res = installer.CheckAppIdentifier(oldAppIdentifier, newAppIdentifier, oldAppId, newAppId);
5381 EXPECT_TRUE(res);
5382 }
5383
5384 /**
5385 * @tc.number: CheckAppIdentifier_0800
5386 * @tc.name: test CheckAppIdentifier
5387 * @tc.desc: 1.Test the CheckAppIdentifier
5388 */
5389 HWTEST_F(BmsBundleInstallerTest, CheckAppIdentifier_0800, Function | SmallTest | Level0)
5390 {
5391 std::string oldAppIdentifier = "oldAppIdentifier";
5392 std::string newAppIdentifier = "newAppIdentifier";
5393 std::string oldAppId = "oldAppId";
5394 std::string newAppId = "newAppId";
5395 BaseBundleInstaller installer;
5396 bool res = installer.CheckAppIdentifier(oldAppIdentifier, newAppIdentifier, oldAppId, newAppId);
5397 EXPECT_FALSE(res);
5398 }
5399
5400 /**
5401 * @tc.number: CheckAppIdentifier_0900
5402 * @tc.name: test CheckAppIdentifier
5403 * @tc.desc: 1.Test the CheckAppIdentifier
5404 */
5405 HWTEST_F(BmsBundleInstallerTest, CheckAppIdentifier_0900, Function | SmallTest | Level0)
5406 {
5407 std::string oldAppIdentifier = "appIdentifier";
5408 std::string newAppIdentifier = "appIdentifier";
5409 std::string oldAppId = "oldAppId";
5410 std::string newAppId = "newAppId";
5411 BaseBundleInstaller installer;
5412 bool res = installer.CheckAppIdentifier(oldAppIdentifier, newAppIdentifier, oldAppId, newAppId);
5413 EXPECT_TRUE(res);
5414 }
5415
5416 /**
5417 * @tc.number: BeforeInstall_0100
5418 * @tc.name: test BeforeInstall
5419 * @tc.desc: 1.Test the BeforeInstall
5420 */
5421 HWTEST_F(BmsBundleInstallerTest, BeforeInstall_0100, Function | SmallTest | Level0)
5422 {
5423 AppServiceFwkInstaller appServiceFwkInstaller;
5424 std::vector<std::string> hspPaths;
5425 hspPaths.push_back(TEST_CREATE_FILE_PATH);
5426 InstallParam installParam;
5427 installParam.isPreInstallApp = false;
5428
5429 auto res = appServiceFwkInstaller.BeforeInstall(hspPaths, installParam);
5430 EXPECT_EQ(res, ERR_OK);
5431
5432 installParam.isPreInstallApp = true;
5433 res = appServiceFwkInstaller.BeforeInstall(hspPaths, installParam);
5434 EXPECT_EQ(res, ERR_OK);
5435
5436 ClearDataMgr();
5437 res = appServiceFwkInstaller.BeforeInstall(hspPaths, installParam);
5438 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_BUNDLE_MGR_SERVICE_ERROR);
5439 ResetDataMgr();
5440 }
5441
5442 /**
5443 * @tc.number: BeforeInstall_0200
5444 * @tc.name: test BeforeInstall
5445 * @tc.desc: 1.Test the BeforeInstall
5446 */
5447 HWTEST_F(BmsBundleInstallerTest, BeforeInstall_0200, Function | SmallTest | Level0)
5448 {
5449 AppServiceFwkInstaller appServiceFwkInstaller;
5450 std::vector<std::string> hspPaths;
5451 InstallParam installParam;
5452 installParam.isPreInstallApp = false;
5453
5454 ErrCode res = appServiceFwkInstaller.BeforeInstall(hspPaths, installParam);
5455 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_PARAM_ERROR);
5456 }
5457
5458 /**
5459 * @tc.number: CheckFileType_0100
5460 * @tc.name: test CheckFileType
5461 * @tc.desc: 1.Test the CheckFileType
5462 */
5463 HWTEST_F(BmsBundleInstallerTest, CheckFileType_0100, Function | SmallTest | Level0)
5464 {
5465 AppServiceFwkInstaller appServiceFwkInstaller;
5466 std::vector<std::string> hspPaths;
5467 auto res = appServiceFwkInstaller.CheckFileType(hspPaths);
5468 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_PARAM_ERROR);
5469
5470 hspPaths.push_back(TEST_CREATE_FILE_PATH);
5471 res = appServiceFwkInstaller.CheckFileType(hspPaths);
5472 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_INVALID_HAP_NAME);
5473 }
5474
5475 /**
5476 * @tc.number: CheckAppLabelInfo_0100
5477 * @tc.name: test CheckAppLabelInfo
5478 * @tc.desc: 1.Test the CheckAppLabelInfo
5479 */
5480 HWTEST_F(BmsBundleInstallerTest, CheckAppLabelInfo_0100, Function | SmallTest | Level0)
5481 {
5482 AppServiceFwkInstaller appServiceFwkInstaller;
5483 InnerBundleInfo innerBundleInfo;
5484 innerBundleInfo.baseApplicationInfo_->bundleType = BundleType::APP;
5485 std::unordered_map<std::string, InnerBundleInfo> infos;
5486 infos.emplace(TEST_CREATE_FILE_PATH, innerBundleInfo);
5487 auto res = appServiceFwkInstaller.CheckAppLabelInfo(infos);
5488 EXPECT_EQ(res, ERR_APP_SERVICE_FWK_INSTALL_TYPE_FAILED);
5489
5490 innerBundleInfo.baseApplicationInfo_->bundleType = BundleType::APP_SERVICE_FWK;
5491 res = appServiceFwkInstaller.CheckAppLabelInfo(infos);
5492 EXPECT_EQ(res, ERR_OK);
5493
5494 innerBundleInfo.currentPackage_ = MODULE_NAME_TEST;
5495 InnerModuleInfo innerModuleInfo;
5496 innerModuleInfo.moduleName = MODULE_NAME_TEST;
5497 innerBundleInfo.innerModuleInfos_.emplace(MODULE_NAME_TEST, innerModuleInfo);
5498 res = appServiceFwkInstaller.CheckAppLabelInfo(infos);
5499 EXPECT_EQ(res, ERR_OK);
5500
5501 innerModuleInfo.bundleType = BundleType::SHARED;
5502 res = appServiceFwkInstaller.CheckAppLabelInfo(infos);
5503 EXPECT_EQ(res, ERR_OK);
5504 }
5505
5506 /**
5507 * @tc.number: InstalldOperatorTest_7600
5508 * @tc.name: test function of InstalldOperator
5509 * @tc.desc: 1. calling VerifyCodeSignature of InstalldHostImpl
5510 * 2. return false
5511 * @tc.require: issueI6PNQX
5512 */
5513 HWTEST_F(BmsBundleInstallerTest, InstalldOperatorTest_7600, Function | SmallTest | Level0)
5514 {
5515 InstalldHostImpl hostImpl;
5516 CodeSignatureParam codeSignatureParam;
5517 codeSignatureParam.modulePath = "";
5518 auto ret = hostImpl.VerifyCodeSignature(codeSignatureParam);
5519 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
5520 }
5521
5522 /**
5523 * @tc.number: InstalldOperatorTest_7700
5524 * @tc.name: test function of CheckEncryption
5525 * @tc.desc: 1. calling CheckEncryption
5526 */
5527 HWTEST_F(BmsBundleInstallerTest, InstalldOperatorTest_7700, Function | SmallTest | Level0)
5528 {
5529 InstalldHostImpl hostImpl;
5530 CheckEncryptionParam checkEncryptionParam;
5531 checkEncryptionParam.modulePath = "";
5532 bool isEncrypted = false;
5533 ErrCode res = hostImpl.CheckEncryption(checkEncryptionParam, isEncrypted);
5534 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
5535 }
5536
5537 /**
5538 * @tc.number: InstalldOperatorTest_7800
5539 * @tc.name: test RegisterBundleStatusCallback
5540 * @tc.desc: 1.system run normally
5541 * 2.RegisterBundleStatusCallback failed
5542 */
5543 HWTEST_F(BmsBundleInstallerTest, InstalldOperatorTest_7800, Function | SmallTest | Level1)
5544 {
5545 InstalldHostImpl hostImpl;
5546 std::vector<std::string> fileNames;
5547 auto ret = hostImpl.MoveFiles("", "");
5548 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
5549
5550 ret = hostImpl.MoveFiles(TEST_STRING, "");
5551 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
5552
5553 ret = hostImpl.MoveFiles("", TEST_STRING);
5554 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
5555 }
5556
5557 /**
5558 * @tc.number: InstalldOperatorTest_7800
5559 * @tc.name: test RegisterBundleStatusCallback
5560 * @tc.desc: 1.system run normally
5561 * 2.RegisterBundleStatusCallback failed
5562 */
5563 HWTEST_F(BmsBundleInstallerTest, InstalldOperatorTest_7900, Function | SmallTest | Level1)
5564 {
5565 InstalldHostImpl hostImpl;
5566 std::unordered_multimap<std::string, std::string> dirMap;
5567 auto ret = hostImpl.ExtractDriverSoFiles("", dirMap);
5568 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
5569 }
5570
5571 /**
5572 * @tc.number: InstalldOperatorTest_8000
5573 * @tc.name: test CheckPathValid
5574 * @tc.desc: 1.system run normally
5575 * 2.CheckPathValid failed
5576 */
5577 HWTEST_F(BmsBundleInstallerTest, InstalldOperatorTest_8000, Function | SmallTest | Level1)
5578 {
5579 InstalldHostImpl hostImpl;
5580 auto ret = hostImpl.CheckPathValid("", "");
5581 EXPECT_EQ(ret, true);
5582 }
5583
5584 /**
5585 * @tc.number: InstalldOperatorTest_8100
5586 * @tc.name: test CheckPathValid
5587 * @tc.desc: 1.system run normally
5588 * 2.CheckPathValid failed
5589 */
5590 HWTEST_F(BmsBundleInstallerTest, InstalldOperatorTest_8100, Function | SmallTest | Level1)
5591 {
5592 InstalldHostImpl hostImpl;
5593 std::string path = "../";
5594 auto ret = hostImpl.CheckPathValid(path, "");
5595 EXPECT_EQ(ret, false);
5596 }
5597
5598 /**
5599 * @tc.number: InstalldOperatorTest_8200
5600 * @tc.name: test CheckPathValid
5601 * @tc.desc: 1.system run normally
5602 * 2.CheckPathValid failed
5603 */
5604 HWTEST_F(BmsBundleInstallerTest, InstalldOperatorTest_8200, Function | SmallTest | Level1)
5605 {
5606 InstalldHostImpl hostImpl;
5607 std::string path = "./";
5608 std::string prefix = "npos";
5609 auto ret = hostImpl.CheckPathValid(path, prefix);
5610 EXPECT_EQ(ret, false);
5611 }
5612
5613 /**
5614 * @tc.number: InstalldOperatorTest_8300
5615 * @tc.name: test CheckPathValid
5616 * @tc.desc: 1.system run normally
5617 * 2.CheckPathValid failed
5618 */
5619 HWTEST_F(BmsBundleInstallerTest, InstalldOperatorTest_8300, Function | SmallTest | Level1)
5620 {
5621 InstalldHostImpl hostImpl;
5622 std::string path = "./npos";
5623 std::string prefix = "npos";
5624 auto ret = hostImpl.CheckPathValid(path, prefix);
5625 EXPECT_EQ(ret, true);
5626 }
5627
5628 /**
5629 * @tc.number: DeleteOldNativeLibraryPath_0010
5630 * @tc.name: DeleteOldNativeLibraryPath
5631 * @tc.desc: test DeleteOldNativeLibraryPath
5632 */
5633 HWTEST_F(BmsBundleInstallerTest, DeleteOldNativeLibraryPath_0010, TestSize.Level1)
5634 {
5635 bool ret = OHOS::ForceCreateDirectory(BUNDLE_LIBRARY_PATH_DIR);
5636 EXPECT_TRUE(ret);
5637 BaseBundleInstaller installer;
5638 installer.bundleName_ = BUNDLE_NAME;
5639 installer.DeleteOldNativeLibraryPath();
5640 auto exist = access(BUNDLE_LIBRARY_PATH_DIR.c_str(), F_OK);
5641 EXPECT_NE(exist, 0);
5642 }
5643
5644 /**
5645 * @tc.number: DeleteOldNativeLibraryPath_0020
5646 * @tc.name: NeedDeleteOldNativeLib
5647 * @tc.desc: test NeedDeleteOldNativeLib
5648 */
5649 HWTEST_F(BmsBundleInstallerTest, DeleteOldNativeLibraryPath_0020, TestSize.Level1)
5650 {
5651 BaseBundleInstaller installer;
5652 installer.bundleName_ = BUNDLE_NAME;
5653
5654 InnerBundleInfo oldInfo;
5655 InnerBundleInfo newInfo;
5656 InnerModuleInfo innerModuleInfo;
5657 oldInfo.InsertInnerModuleInfo("module1", innerModuleInfo);
5658 newInfo.InsertInnerModuleInfo("module2", innerModuleInfo);
5659 // 1. NewInfos is null, return false
5660 std::unordered_map<std::string, InnerBundleInfo> newInfo1;
5661 bool ret = installer.NeedDeleteOldNativeLib(newInfo1, oldInfo);
5662 EXPECT_FALSE(ret);
5663
5664 // 2. No old app, return false
5665 newInfo1.insert(std::pair<std::string, InnerBundleInfo>(BUNDLE_NAME_TEST, newInfo));
5666 ret = installer.NeedDeleteOldNativeLib(newInfo1, oldInfo);
5667 EXPECT_FALSE(ret);
5668
5669 // 3. Old app no library, return false
5670 installer.isAppExist_ = true;
5671 ret = installer.NeedDeleteOldNativeLib(newInfo1, oldInfo);
5672 EXPECT_FALSE(ret);
5673
5674 // 4. Not all module update, return false
5675 oldInfo.SetNativeLibraryPath("libs/arm");
5676 ret = installer.NeedDeleteOldNativeLib(newInfo1, oldInfo);
5677 EXPECT_FALSE(ret);
5678
5679 // 5. Higher versionCode, return true
5680 BundleInfo oldBundleInfo;
5681 oldBundleInfo.versionCode = 900;
5682 oldInfo.UpdateBaseBundleInfo(oldBundleInfo, true);
5683 BundleInfo newBundleInfo;
5684 newBundleInfo.versionCode = 1000;
5685 newInfo.UpdateBaseBundleInfo(newBundleInfo, true);
5686 std::unordered_map<std::string, InnerBundleInfo> newInfo2;
5687 newInfo2.insert(std::pair<std::string, InnerBundleInfo>(BUNDLE_NAME_TEST, newInfo));
5688 ret = installer.NeedDeleteOldNativeLib(newInfo2, oldInfo);
5689 EXPECT_TRUE(ret);
5690 }
5691
5692 /**
5693 * @tc.number: DeleteOldNativeLibraryPath_0030
5694 * @tc.name: NeedDeleteOldNativeLib
5695 * @tc.desc: test NeedDeleteOldNativeLib multihap
5696 */
5697 HWTEST_F(BmsBundleInstallerTest, DeleteOldNativeLibraryPath_0030, TestSize.Level1)
5698 {
5699 BaseBundleInstaller installer;
5700 installer.bundleName_ = BUNDLE_NAME;
5701 installer.isAppExist_ = true;
5702
5703 InnerModuleInfo innerModuleInfo;
5704
5705 InnerBundleInfo oldInfo;
5706 oldInfo.SetNativeLibraryPath("libs/arm");
5707 oldInfo.InsertInnerModuleInfo("module1", innerModuleInfo);
5708 oldInfo.InsertInnerModuleInfo("module2", innerModuleInfo);
5709
5710 InnerBundleInfo newInfo1;
5711 newInfo1.InsertInnerModuleInfo("module1", innerModuleInfo);
5712 InnerBundleInfo newInfo2;
5713 newInfo2.InsertInnerModuleInfo("module2", innerModuleInfo);
5714 InnerBundleInfo newInfo3;
5715 newInfo2.InsertInnerModuleInfo("module3", innerModuleInfo);
5716
5717 std::unordered_map<std::string, InnerBundleInfo> newInfos;
5718 newInfos.insert(std::pair<std::string, InnerBundleInfo>("hap1", newInfo1));
5719 bool ret = installer.NeedDeleteOldNativeLib(newInfos, oldInfo);
5720 EXPECT_FALSE(ret);
5721
5722 newInfos.insert(std::pair<std::string, InnerBundleInfo>("hap3", newInfo3));
5723 ret = installer.NeedDeleteOldNativeLib(newInfos, oldInfo);
5724 EXPECT_FALSE(ret);
5725
5726 newInfos.insert(std::pair<std::string, InnerBundleInfo>("hap2", newInfo2));
5727 ret = installer.NeedDeleteOldNativeLib(newInfos, oldInfo);
5728 EXPECT_TRUE(ret);
5729 }
5730
5731 /**
5732 * @tc.number: DeleteOldNativeLibraryPath_0040
5733 * @tc.name: NeedDeleteOldNativeLib
5734 * @tc.desc: test NeedDeleteOldNativeLib multihap IsOnlyCreateBundleUser
5735 */
5736 HWTEST_F(BmsBundleInstallerTest, DeleteOldNativeLibraryPath_0040, TestSize.Level1)
5737 {
5738 BaseBundleInstaller installer;
5739 installer.bundleName_ = BUNDLE_NAME;
5740 installer.isAppExist_ = true;
5741
5742 InnerModuleInfo innerModuleInfo;
5743 InnerBundleInfo oldInfo;
5744 oldInfo.SetNativeLibraryPath("arm");
5745 oldInfo.InsertInnerModuleInfo("module1", innerModuleInfo);
5746 oldInfo.InsertInnerModuleInfo("module2", innerModuleInfo);
5747
5748 InnerBundleInfo newInfo1;
5749 newInfo1.InsertInnerModuleInfo("module1", innerModuleInfo);
5750 InnerBundleInfo newInfo2;
5751 newInfo2.InsertInnerModuleInfo("module2", innerModuleInfo);
5752 InnerBundleInfo newInfo3;
5753 newInfo3.SetOnlyCreateBundleUser(true);
5754 newInfo2.InsertInnerModuleInfo("module3", innerModuleInfo);
5755
5756 std::unordered_map<std::string, InnerBundleInfo> newInfos;
5757 newInfos.insert(std::pair<std::string, InnerBundleInfo>("hap1", newInfo1));
5758 newInfos.insert(std::pair<std::string, InnerBundleInfo>("hap2", newInfo2));
5759 newInfos.insert(std::pair<std::string, InnerBundleInfo>("hap3", newInfo3));
5760 bool ret = installer.NeedDeleteOldNativeLib(newInfos, oldInfo);
5761 EXPECT_FALSE(ret);
5762 }
5763
5764 /**
5765 * @tc.number: DeleteOldNativeLibraryPath_0050
5766 * @tc.name: NeedDeleteOldNativeLib
5767 * @tc.desc: test NeedDeleteOldNativeLib multihap otaInstall
5768 */
5769 HWTEST_F(BmsBundleInstallerTest, DeleteOldNativeLibraryPath_0050, TestSize.Level1)
5770 {
5771 BaseBundleInstaller installer;
5772 installer.bundleName_ = BUNDLE_NAME;
5773 installer.isAppExist_ = true;
5774
5775 InnerModuleInfo innerModuleInfo;
5776
5777 InnerBundleInfo oldInfo;
5778 oldInfo.SetNativeLibraryPath("libs/arm");
5779 oldInfo.InsertInnerModuleInfo("module1", innerModuleInfo);
5780 oldInfo.InsertInnerModuleInfo("module2", innerModuleInfo);
5781
5782 InnerBundleInfo newInfo1;
5783 newInfo1.InsertInnerModuleInfo("module1", innerModuleInfo);
5784 InnerBundleInfo newInfo2;
5785 newInfo2.InsertInnerModuleInfo("module2", innerModuleInfo);
5786 InnerBundleInfo newInfo3;
5787 newInfo2.InsertInnerModuleInfo("module3", innerModuleInfo);
5788
5789 std::unordered_map<std::string, InnerBundleInfo> newInfos;
5790 newInfos.insert(std::pair<std::string, InnerBundleInfo>("hap1", newInfo1));
5791 bool ret = installer.NeedDeleteOldNativeLib(newInfos, oldInfo);
5792 EXPECT_FALSE(ret);
5793
5794 newInfos.insert(std::pair<std::string, InnerBundleInfo>("hap3", newInfo3));
5795 ret = installer.NeedDeleteOldNativeLib(newInfos, oldInfo);
5796 EXPECT_FALSE(ret);
5797
5798 installer.otaInstall_ = true;
5799 ret = installer.NeedDeleteOldNativeLib(newInfos, oldInfo);
5800 EXPECT_TRUE(ret);
5801 }
5802
5803 /**
5804 * @tc.number: RemoveOldHapIfOTA_0010
5805 * @tc.name: RemoveOldHapIfOTANotOTA
5806 * @tc.desc: test RemoveOldHapIfOTA not OTA
5807 */
5808 HWTEST_F(BmsBundleInstallerTest, RemoveOldHapIfOTA_0010, Function | SmallTest | Level1)
5809 {
5810 std::string bundleFile = RESOURCE_ROOT_PATH + SYSTEMFIEID_BUNDLE;
5811 ErrCode installResult = InstallThirdPartyBundle(bundleFile);
5812 EXPECT_EQ(installResult, ERR_OK);
5813
5814 InnerBundleInfo newInfo;
5815 newInfo.currentPackage_ = MODULE_NAME;
5816 std::unordered_map<std::string, InnerBundleInfo> newInfos;
5817 newInfos.try_emplace(bundleFile, newInfo);
5818
5819 InnerBundleInfo oldInfo;
5820 InnerModuleInfo innerModuleInfo;
5821 innerModuleInfo.hapPath = SYSTEMFIEID_HAP_PATH;
5822 oldInfo.innerModuleInfos_.insert(pair<std::string, InnerModuleInfo>(MODULE_NAME, innerModuleInfo));
5823
5824 InstallParam installParam;
5825 installParam.isOTA = false;
5826 installParam.copyHapToInstallPath = true;
5827 BaseBundleInstaller installer;
5828 installer.RemoveOldHapIfOTA(installParam, newInfos, oldInfo);
5829 auto exist = access(SYSTEMFIEID_HAP_PATH.c_str(), F_OK);
5830 EXPECT_EQ(exist, 0);
5831 UnInstallBundle(SYSTEMFIEID_NAME);
5832 }
5833
5834 /**
5835 * @tc.number: RemoveOldHapIfOTA_0020
5836 * @tc.name: RemoveOldHapIfOTANoHapInData
5837 * @tc.desc: test RemoveOldHapIfOTA no hap in data
5838 */
5839 HWTEST_F(BmsBundleInstallerTest, RemoveOldHapIfOTA_0020, Function | SmallTest | Level1)
5840 {
5841 std::string bundleFile = RESOURCE_ROOT_PATH + SYSTEMFIEID_BUNDLE;
5842 ErrCode installResult = InstallThirdPartyBundle(bundleFile);
5843 EXPECT_EQ(installResult, ERR_OK);
5844
5845 InnerBundleInfo newInfo;
5846 newInfo.currentPackage_ = MODULE_NAME;
5847 std::unordered_map<std::string, InnerBundleInfo> newInfos;
5848 newInfos.try_emplace(bundleFile, newInfo);
5849
5850 InnerBundleInfo oldInfo;
5851 InnerModuleInfo innerModuleInfo;
5852 innerModuleInfo.hapPath = "/system/app/module01/module01.hap";
5853 oldInfo.innerModuleInfos_.insert(pair<std::string, InnerModuleInfo>(MODULE_NAME, innerModuleInfo));
5854
5855 InstallParam installParam;
5856 installParam.isOTA = true;
5857 installParam.copyHapToInstallPath = false;
5858 BaseBundleInstaller installer;
5859 installer.RemoveOldHapIfOTA(installParam, newInfos, oldInfo);
5860 auto exist = access(SYSTEMFIEID_HAP_PATH.c_str(), F_OK);
5861 EXPECT_EQ(exist, 0);
5862 UnInstallBundle(SYSTEMFIEID_NAME);
5863 }
5864
5865 /**
5866 * @tc.number: RemoveOldHapIfOTA_0030
5867 * @tc.name: RemoveOldHapIfOTASuccess
5868 * @tc.desc: test RemoveOldHapIfOTA success
5869 */
5870 HWTEST_F(BmsBundleInstallerTest, RemoveOldHapIfOTA_0030, Function | SmallTest | Level1)
5871 {
5872 std::string bundleFile = RESOURCE_ROOT_PATH + SYSTEMFIEID_BUNDLE;
5873 ErrCode installResult = InstallThirdPartyBundle(bundleFile);
5874 EXPECT_EQ(installResult, ERR_OK);
5875
5876 InnerBundleInfo newInfo;
5877 newInfo.currentPackage_ = MODULE_NAME;
5878 std::unordered_map<std::string, InnerBundleInfo> newInfos;
5879 newInfos.try_emplace(bundleFile, newInfo);
5880
5881 InnerBundleInfo oldInfo;
5882 InnerModuleInfo innerModuleInfo;
5883 innerModuleInfo.hapPath = SYSTEMFIEID_HAP_PATH;
5884 oldInfo.innerModuleInfos_.insert(pair<std::string, InnerModuleInfo>(MODULE_NAME, innerModuleInfo));
5885
5886 InstallParam installParam;
5887 installParam.isOTA = true;
5888 installParam.copyHapToInstallPath = false;
5889 BaseBundleInstaller installer;
5890 installer.RemoveOldHapIfOTA(installParam, newInfos, oldInfo);
5891 auto exist = access(SYSTEMFIEID_HAP_PATH.c_str(), F_OK);
5892 EXPECT_EQ(exist, -1);
5893 UnInstallBundle(SYSTEMFIEID_NAME);
5894 }
5895
5896 /**
5897 * @tc.number: RemoveOldHapIfOTA_0040
5898 * @tc.name: RemoveOldHapIfOTAQuickFix
5899 * @tc.desc: test RemoveOldHapIfOTA when quickfix
5900 */
5901 HWTEST_F(BmsBundleInstallerTest, RemoveOldHapIfOTA_0040, Function | SmallTest | Level1)
5902 {
5903 std::string bundleFile = RESOURCE_ROOT_PATH + SYSTEMFIEID_BUNDLE;
5904 ErrCode installResult = InstallThirdPartyBundle(bundleFile);
5905 EXPECT_EQ(installResult, ERR_OK);
5906
5907 InnerBundleInfo newInfo;
5908 newInfo.currentPackage_ = MODULE_NAME;
5909 std::unordered_map<std::string, InnerBundleInfo> newInfos;
5910 newInfos.try_emplace(bundleFile, newInfo);
5911
5912 InnerBundleInfo oldInfo;
5913 InnerModuleInfo innerModuleInfo;
5914 innerModuleInfo.hapPath = SYSTEMFIEID_HAP_PATH;
5915 oldInfo.innerModuleInfos_.insert(pair<std::string, InnerModuleInfo>(MODULE_NAME, innerModuleInfo));
5916
5917 InstallParam installParam;
5918 installParam.isOTA = true;
5919 installParam.copyHapToInstallPath = true;
5920 BaseBundleInstaller installer;
5921 installer.RemoveOldHapIfOTA(installParam, newInfos, oldInfo);
5922 auto exist = access(SYSTEMFIEID_HAP_PATH.c_str(), F_OK);
5923 EXPECT_EQ(exist, 0);
5924 UnInstallBundle(SYSTEMFIEID_NAME);
5925 }
5926
5927 /**
5928 * @tc.number: PrepareSkillUri_0010
5929 * @tc.name: PrepareSkillUriNotDomainVerify
5930 * @tc.desc: test PrepareSkillUri without domainVerify
5931 */
5932 HWTEST_F(BmsBundleInstallerTest, PrepareSkillUri_0010, Function | SmallTest | Level1)
5933 {
5934 std::vector<Skill> skills;
5935 Skill skill;
5936 SkillUri skillUri;
5937 skillUri.scheme = "https";
5938 skillUri.host = "www.test.com";
5939 skill.uris.push_back(skillUri);
5940 skill.domainVerify = false;
5941 skills.push_back(skill);
5942 std::vector<AppDomainVerify::SkillUri> skillUris;
5943
5944 BaseBundleInstaller installer;
5945 installer.PrepareSkillUri(skills, skillUris);
5946 EXPECT_EQ(skillUris.size(), 0);
5947 }
5948
5949 /**
5950 * @tc.number: PrepareSkillUri_0020
5951 * @tc.name: PrepareSkillUriNotHttps
5952 * @tc.desc: test PrepareSkillUri without https
5953 */
5954 HWTEST_F(BmsBundleInstallerTest, PrepareSkillUri_0020, Function | SmallTest | Level1)
5955 {
5956 std::vector<Skill> skills;
5957 Skill skill;
5958 SkillUri skillUri;
5959 skillUri.scheme = "http";
5960 skillUri.host = "www.test.com";
5961 skill.uris.push_back(skillUri);
5962 skill.domainVerify = true;
5963 skills.push_back(skill);
5964 std::vector<AppDomainVerify::SkillUri> skillUris;
5965
5966 BaseBundleInstaller installer;
5967 installer.PrepareSkillUri(skills, skillUris);
5968 EXPECT_EQ(skillUris.size(), 0);
5969 }
5970
5971 /**
5972 * @tc.number: PrepareSkillUri_0030
5973 * @tc.name: PrepareSkillUriSuccess
5974 * @tc.desc: test PrepareSkillUri success
5975 */
5976 HWTEST_F(BmsBundleInstallerTest, PrepareSkillUri_0030, Function | SmallTest | Level1)
5977 {
5978 std::vector<Skill> skills;
5979 Skill skill;
5980 SkillUri skillUri;
5981 skillUri.scheme = "https";
5982 skillUri.host = "www.test.com";
5983 skill.uris.push_back(skillUri);
5984 skill.domainVerify = true;
5985 skills.push_back(skill);
5986 std::vector<AppDomainVerify::SkillUri> skillUris;
5987
5988 BaseBundleInstaller installer;
5989 installer.PrepareSkillUri(skills, skillUris);
5990 EXPECT_EQ(skillUris.size(), 1);
5991 }
5992
5993 /**
5994 * @tc.number: UpdateBundleForSelf_0100
5995 * @tc.name: test Install
5996 * @tc.desc: test UpdateBundleForSelf of BundleInstallerHost
5997 */
5998 HWTEST_F(BmsBundleInstallerTest, UpdateBundleForSelf_0100, Function | SmallTest | Level0)
5999 {
6000 BundleInstallerHost bundleInstallerHost;
6001 std::vector<std::string> bundleFilePaths;
6002 InstallParam installParam;
6003 sptr<IStatusReceiver> statusReceiver;
6004 bool ret = bundleInstallerHost.UpdateBundleForSelf(bundleFilePaths, installParam, statusReceiver);
6005 EXPECT_EQ(ret, false);
6006 }
6007
6008 /**
6009 * @tc.number: ExtractEncryptedSoFiles_0100
6010 * @tc.name: test ExtractEncryptedSoFiles
6011 * @tc.desc: test ExtractEncryptedSoFiles of BaseBundleInstaller
6012 */
6013 HWTEST_F(BmsBundleInstallerTest, ExtractEncryptedSoFiles_0100, Function | SmallTest | Level0)
6014 {
6015 BaseBundleInstaller installer;
6016 InnerBundleInfo info;
6017 std::string tmpSoPath = "";
6018 int32_t uid = -1;
6019 bool ret = installer.ExtractEncryptedSoFiles(info, tmpSoPath, uid);
6020 EXPECT_EQ(ret, true);
6021 }
6022
6023 /**
6024 * @tc.number: CopyPgoFile_0100
6025 * @tc.name: test CopyPgoFile
6026 * @tc.desc: test CopyPgoFile of BaseBundleInstaller
6027 */
6028 HWTEST_F(BmsBundleInstallerTest, CopyPgoFile_0100, Function | SmallTest | Level0)
6029 {
6030 BaseBundleInstaller installer;
6031 auto ret = installer.CopyPgoFile("", "", "", USERID);
6032 EXPECT_NE(ret, ERR_OK);
6033 }
6034
6035 /**
6036 * @tc.number: UninstallBundleFromBmsExtension_0100
6037 * @tc.name: test UninstallBundleFromBmsExtension
6038 * @tc.desc: test UninstallBundleFromBmsExtension of BaseBundleInstaller
6039 */
6040 HWTEST_F(BmsBundleInstallerTest, UninstallBundleFromBmsExtension_0100, Function | SmallTest | Level0)
6041 {
6042 BaseBundleInstaller installer;
6043 auto ret = installer.UninstallBundleFromBmsExtension("");
6044 EXPECT_NE(ret, ERR_OK);
6045 }
6046
6047 /**
6048 * @tc.number: UninstallBundleFromBmsExtension_0200
6049 * @tc.name: test UninstallBundleFromBmsExtension_0100
6050 * @tc.desc: test UninstallBundleFromBmsExtension_0100 of BaseBundleInstaller
6051 */
6052 HWTEST_F(BmsBundleInstallerTest, UninstallBundleFromBmsExtension_0200, Function | SmallTest | Level0)
6053 {
6054 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
6055 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
6056 EXPECT_EQ(installResult, ERR_OK);
6057
6058 BaseBundleInstaller installer;
6059 auto ret = installer.UninstallBundleFromBmsExtension(BUNDLE_BACKUP_NAME);
6060 EXPECT_NE(ret, ERR_OK);
6061 UnInstallBundle(BUNDLE_BACKUP_NAME);
6062 }
6063
6064 /**
6065 * @tc.number: CheckBundleInBmsExtension_0100
6066 * @tc.name: test CheckBundleInBmsExtension
6067 * @tc.desc: test CheckBundleInBmsExtension of BaseBundleInstaller
6068 */
6069 HWTEST_F(BmsBundleInstallerTest, CheckBundleInBmsExtension, Function | SmallTest | Level0)
6070 {
6071 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
6072 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
6073 EXPECT_EQ(installResult, ERR_OK);
6074
6075 BaseBundleInstaller installer;
6076 auto ret = installer.CheckBundleInBmsExtension(BUNDLE_BACKUP_NAME, USERID);
6077 EXPECT_EQ(ret, ERR_OK);
6078 UnInstallBundle(BUNDLE_BACKUP_NAME);
6079 }
6080
6081 /**
6082 * @tc.number: UpdateHapToken_0100
6083 * @tc.name: test UpdateHapToken
6084 * @tc.desc: test UpdateHapToken of BaseBundleInstaller
6085 */
6086 HWTEST_F(BmsBundleInstallerTest, UpdateHapToken_0100, Function | SmallTest | Level0)
6087 {
6088 InnerBundleInfo newInfo;
6089 std::map<std::string, InnerBundleUserInfo> innerBundleUserInfos;
6090 InnerBundleUserInfo info;
6091 info.accessTokenId = 0;
6092 innerBundleUserInfos.try_emplace(BUNDLE_NAME, info);
6093 info.accessTokenId = -1;
6094 innerBundleUserInfos.try_emplace(BUNDLE_NAME, info);
6095 newInfo.innerBundleUserInfos_ = innerBundleUserInfos;
6096 BaseBundleInstaller installer;
6097 installer.InitDataMgr();
6098 auto ret = installer.UpdateHapToken(true, newInfo);
6099 EXPECT_NE(ret, ERR_OK);
6100
6101 ret = installer.UpdateHapToken(false, newInfo);
6102 EXPECT_EQ(ret, ERR_OK);
6103 }
6104
6105 /**
6106 * @tc.number: AllowSingletonChange_0100
6107 * @tc.name: test AllowSingletonChange
6108 * @tc.desc: test AllowSingletonChange of BaseBundleInstaller
6109 */
6110 HWTEST_F(BmsBundleInstallerTest, AllowSingletonChange_0100, Function | SmallTest | Level0)
6111 {
6112 BaseBundleInstaller installer;
6113 std::string bundleName = "com.acts.example";
6114 bool ret = installer.AllowSingletonChange(bundleName);
6115 EXPECT_EQ(ret, false);
6116 }
6117
6118 /**
6119 * @tc.number: ExtractHnpFileDir_0100
6120 * @tc.name: test ExtractHnpFileDir
6121 * @tc.desc: test ExtractHnpFileDir of BaseBundleInstaller
6122 */
6123 HWTEST_F(BmsBundleInstallerTest, ExtractHnpFileDir_0100, Function | SmallTest | Level0)
6124 {
6125 BaseBundleInstaller installer;
6126 std::string cpuAbi;
6127 std::string hnpPackageInfoString;
6128 std::string modulePath;
6129 ErrCode ret = installer.ExtractHnpFileDir(cpuAbi, hnpPackageInfoString, modulePath);
6130 EXPECT_EQ(ret, ERR_APPEXECFWK_NATIVE_HNP_EXTRACT_FAILED);
6131 }
6132
6133 /**
6134 * @tc.number: AddBundleStatus_0100
6135 * @tc.name: test AddBundleStatus
6136 * @tc.desc: test AddBundleStatus of BaseBundleInstaller
6137 */
6138 HWTEST_F(BmsBundleInstallerTest, AddBundleStatus_0100, Function | SmallTest | Level0)
6139 {
6140 BaseBundleInstaller installer;
6141 NotifyBundleEvents installRes;
6142 installRes.abilityName = "testAbilityName";
6143 installer.AddBundleStatus(installRes);
6144 EXPECT_NE(installer.bundleEvents_.end().base()->abilityName.c_str(),
6145 installRes.abilityName.c_str());
6146 }
6147
6148 /**
6149 * @tc.number: CreateBundleDataDirWithVector_0100
6150 * @tc.name: test CreateBundleDataDirWithVector
6151 * @tc.desc: test CreateBundleDataDirWithVector of InstalldHostImpl
6152 */
6153 HWTEST_F(BmsBundleInstallerTest, CreateBundleDataDirWithVector_0100, Function | SmallTest | Level1)
6154 {
6155 InstalldHostImpl hostImpl;
6156 std::vector<CreateDirParam> createDirParams;
6157 auto ret = hostImpl.CreateBundleDataDirWithVector(createDirParams);
6158 EXPECT_EQ(ret, ERR_OK);
6159
6160 CreateDirParam createDirParam;
6161 createDirParams.push_back(createDirParam);
6162 ret = hostImpl.CreateBundleDataDirWithVector(createDirParams);
6163 EXPECT_NE(ret, ERR_OK);
6164 }
6165
6166 /**
6167 * @tc.number: GetAllBundleStats_0100
6168 * @tc.name: test GetAllBundleStats
6169 * @tc.desc: test GetAllBundleStats of InstalldHostImpl
6170 */
6171 HWTEST_F(BmsBundleInstallerTest, GetAllBundleStats_0100, Function | SmallTest | Level1)
6172 {
6173 InstalldHostImpl hostImpl;
6174 std::vector<int64_t> bundleStats = { 0 };
6175 std::vector<int32_t> uids;
6176 uids.push_back(EDM_UID);
6177 auto ret = hostImpl.GetAllBundleStats(EDM_UID, bundleStats, uids);
6178 EXPECT_EQ(ret, ERR_OK);
6179 }
6180
6181 /**
6182 * @tc.number: IsExistApFile_0100
6183 * @tc.name: test IsExistApFile
6184 * @tc.desc: test IsExistApFile of InstalldHostImpl
6185 */
6186 HWTEST_F(BmsBundleInstallerTest, IsExistApFile_0100, Function | SmallTest | Level1)
6187 {
6188 InstalldHostImpl hostImpl;
6189 bool isExist = true;
6190 auto ret = hostImpl.IsExistApFile(TEST_STRING, isExist);
6191 EXPECT_EQ(ret, ERR_OK);
6192 }
6193
6194 /**
6195 * @tc.number: Install_0001
6196 * @tc.name: test the start function of Install
6197 */
6198 HWTEST_F(BmsBundleInstallerTest, Install_0001, Function | SmallTest | Level0)
6199 {
6200 InstallParam installParam;
6201 auto appType = Constants::AppType::THIRD_PARTY_APP;
6202 SharedBundleInstaller bundleInstaller(installParam, appType);
6203
6204 EventInfo eventTemplate;
6205
6206 ErrCode ret = bundleInstaller.Install(eventTemplate);
6207 EXPECT_EQ(ret, ERR_OK);
6208 }
6209
6210 /**
6211 * @tc.number: SendBundleSystemEvent_0010
6212 * @tc.name: test SendBundleSystemEvent
6213 * @tc.desc: 1.SendBundleSystemEvent
6214 */
6215 HWTEST_F(BmsBundleInstallerTest, SendBundleSystemEvent_0010, Function | SmallTest | Level0)
6216 {
6217 InstallParam installParam;
6218 auto appType = Constants::AppType::THIRD_PARTY_APP;
6219 SharedBundleInstaller bundleInstaller(installParam, appType);
6220 EventInfo eventTemplate;
6221 ErrCode errCode = 0;
6222 string path = "test";
6223 bundleInstaller.innerInstallers_["test"] = std::make_shared<InnerSharedBundleInstaller>(path);
6224 bundleInstaller.SendBundleSystemEvent(eventTemplate, errCode);
6225 ASSERT_FALSE(bundleInstaller.innerInstallers_["test"]->isBundleExist_);
6226 }
6227
6228 /**
6229 * @tc.number: CreateSharedBundleTempDir_0100
6230 * @tc.name: test CreateSharedBundleTempDir
6231 * @tc.desc: 1.test CreateSharedBundleTempDir of BundleUtil
6232 */
6233 HWTEST_F(BmsBundleInstallerTest, CreateSharedBundleTempDir_0100, Function | SmallTest | Level0)
6234 {
6235 BundleUtil bundleUtil;
6236 auto ret = bundleUtil.CreateSharedBundleTempDir(INSTALLER_ID, INDEX);
6237 EXPECT_FALSE(ret.empty());
6238 }
6239
6240 /**
6241 * @tc.number: AddNotifyBundleEvents_0100
6242 * @tc.name: test AddNotifyBundleEvents
6243 * @tc.desc: test AddNotifyBundleEvents of BaseBundleInstaller
6244 */
6245 HWTEST_F(BmsBundleInstallerTest, AddNotifyBundleEvents_0100, Function | SmallTest | Level1)
6246 {
6247 BaseBundleInstaller installer;
6248 NotifyBundleEvents installRes;
6249 installer.AddNotifyBundleEvents(installRes);
6250 installRes.abilityName = "testAbilityName";
6251 installer.AddBundleStatus(installRes);
6252 bool ret = installer.NotifyAllBundleStatus();
6253 EXPECT_TRUE(ret);
6254 }
6255
6256 /**
6257 * @tc.number: GetInstallEventInfo_0100
6258 * @tc.name: test GetInstallEventInfo
6259 * @tc.desc: test GetInstallEventInfo of BaseBundleInstaller
6260 */
6261 HWTEST_F(BmsBundleInstallerTest, GetInstallEventInfo_0100, Function | SmallTest | Level1)
6262 {
6263 BaseBundleInstaller installer;
6264 InnerBundleInfo bundleInfo;
6265 EventInfo eventInfo;
6266 installer.GetInstallEventInfo(bundleInfo, eventInfo);
6267 EXPECT_EQ(eventInfo.hideDesktopIcon, bundleInfo.IsHideDesktopIcon());
6268
6269 std::string appDistributionType = "hos_normal_type";
6270 bundleInfo.SetAppDistributionType(appDistributionType);
6271 installer.GetInstallEventInfo(bundleInfo, eventInfo);
6272 EXPECT_EQ(eventInfo.appDistributionType, appDistributionType);
6273 }
6274
6275 /**
6276 * @tc.number: CheckArkNativeFileWithOldInfo_0100
6277 * @tc.name: test CheckArkNativeFileWithOldInfo
6278 * @tc.desc: test CheckArkNativeFileWithOldInfo of BaseBundleInstaller
6279 */
6280 HWTEST_F(BmsBundleInstallerTest, CheckArkNativeFileWithOldInfo_0100, Function | SmallTest | Level1)
6281 {
6282 BaseBundleInstaller installer;
6283 InnerBundleInfo oldInfo;
6284 std::unordered_map<std::string, InnerBundleInfo> newInfos;
6285 ApplicationInfo applicationInfo;
6286 oldInfo.SetBaseApplicationInfo(applicationInfo);
6287 oldInfo.SetArkNativeFileAbi("x86");
6288 ErrCode ret = installer.CheckArkNativeFileWithOldInfo(oldInfo, newInfos);
6289 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_AN_INCOMPATIBLE);
6290 }
6291
6292 /**
6293 * @tc.number: SetAppDistributionType_0100
6294 * @tc.name: test SetAppDistributionType
6295 * @tc.desc: test SetAppDistributionType of BaseBundleInstaller
6296 */
6297 HWTEST_F(BmsBundleInstallerTest, SetAppDistributionType_0100, Function | SmallTest | Level1)
6298 {
6299 BaseBundleInstaller installer;
6300 InnerBundleInfo oldInfo;
6301 std::unordered_map<std::string, InnerBundleInfo> innerBundleInfos;
6302 installer.SetAppDistributionType(innerBundleInfos);
6303
6304 ApplicationInfo applicationInfo;
6305 InnerBundleInfo info;
6306 info.SetBaseApplicationInfo(applicationInfo);
6307 std::string appDistributionType = "hos_normal_type";
6308 info.SetAppDistributionType(appDistributionType);
6309 innerBundleInfos.try_emplace("so", info);
6310 installer.SetAppDistributionType(innerBundleInfos);
6311 EXPECT_EQ(installer.appDistributionType_, appDistributionType);
6312 }
6313
6314 /**
6315 * @tc.number: RemoveOldExtensionDirs_0100
6316 * @tc.name: test RemoveOldExtensionDirs
6317 * @tc.desc: test RemoveOldExtensionDirs of BaseBundleInstaller
6318 */
6319 HWTEST_F(BmsBundleInstallerTest, RemoveOldExtensionDirs_0100, Function | SmallTest | Level1)
6320 {
6321 BaseBundleInstaller installer;
6322 installer.removeExtensionDirs_.clear();
6323 installer.RemoveOldExtensionDirs();
6324 EXPECT_TRUE(installer.removeExtensionDirs_.empty());
6325
6326 installer.createExtensionDirs_.clear();
6327 installer.RemoveCreatedExtensionDirsForException();
6328 EXPECT_TRUE(installer.createExtensionDirs_.empty());
6329 }
6330
6331 /**
6332 * @tc.number: GetValidDataGroupIds_0100
6333 * @tc.name: test GetValidDataGroupIds
6334 * @tc.desc: test GetValidDataGroupIds of BaseBundleInstaller
6335 */
6336 HWTEST_F(BmsBundleInstallerTest, GetValidDataGroupIds_0100, Function | SmallTest | Level1)
6337 {
6338 BaseBundleInstaller installer;
6339 std::vector<std::string> extensionDataGroupIds;
6340 std::vector<std::string> bundleDataGroupIds;
6341 std::vector<std::string> validGroupIds;
6342 installer.GetValidDataGroupIds(extensionDataGroupIds, bundleDataGroupIds, validGroupIds);
6343
6344 extensionDataGroupIds.push_back(TEST_STRING);
6345 installer.GetValidDataGroupIds(extensionDataGroupIds, bundleDataGroupIds, validGroupIds);
6346
6347 bundleDataGroupIds.push_back(TEST_STRING);
6348 installer.GetValidDataGroupIds(extensionDataGroupIds, bundleDataGroupIds, validGroupIds);
6349 std::string dataGroupId = validGroupIds.back();
6350 EXPECT_EQ(dataGroupId, TEST_STRING);
6351 }
6352
6353 /**
6354 * @tc.number: SetDisposedRuleWhenBundleUpdateStart_0010
6355 * @tc.name: test SetDisposedRuleWhenBundleUpdateStart
6356 * @tc.desc: 1.SetDisposedRuleWhenBundleUpdateStart
6357 */
6358 HWTEST_F(BmsBundleInstallerTest, SetDisposedRuleWhenBundleUpdateStart_0010, Function | SmallTest | Level0)
6359 {
6360 BaseBundleInstaller installer;
6361 std::unordered_map<std::string, InnerBundleInfo> infos;
6362 InnerBundleInfo oldBundleInfo;
6363 bool ret = installer.SetDisposedRuleWhenBundleUpdateStart(infos, oldBundleInfo, true);
6364 EXPECT_FALSE(ret);
6365 installer.isAppExist_ = false;
6366 ret = installer.SetDisposedRuleWhenBundleUpdateStart(infos, oldBundleInfo, false);
6367 EXPECT_FALSE(ret);
6368 installer.isAppExist_ = true;
6369 ret = installer.SetDisposedRuleWhenBundleUpdateStart(infos, oldBundleInfo, false);
6370 EXPECT_FALSE(ret);
6371 EXPECT_FALSE(installer.needSetDisposeRule_);
6372 ret = installer.DeleteDisposedRuleWhenBundleUpdateEnd(oldBundleInfo);
6373 EXPECT_FALSE(ret);
6374 }
6375
6376 /**
6377 * @tc.number: SetDisposedRuleWhenBundleUpdateStart_0020
6378 * @tc.name: test SetDisposedRuleWhenBundleUpdateStart
6379 * @tc.desc: 1.SetDisposedRuleWhenBundleUpdateStart
6380 */
6381 HWTEST_F(BmsBundleInstallerTest, SetDisposedRuleWhenBundleUpdateStart_0020, Function | SmallTest | Level0)
6382 {
6383 InnerBundleInfo oldBundleInfo;
6384 InnerModuleInfo innerModuleInfo;
6385 innerModuleInfo.moduleName = MODULE_NAME;
6386 oldBundleInfo.innerModuleInfos_[BUNDLE_NAME] = innerModuleInfo;
6387
6388 std::unordered_map<std::string, InnerBundleInfo> infos;
6389 infos[BUNDLE_NAME] = oldBundleInfo;
6390 BaseBundleInstaller installer;
6391 installer.isAppExist_ = true;
6392 bool ret = installer.SetDisposedRuleWhenBundleUpdateStart(infos, oldBundleInfo, false);
6393 EXPECT_TRUE(ret);
6394 EXPECT_TRUE(installer.needSetDisposeRule_);
6395 ret = installer.DeleteDisposedRuleWhenBundleUpdateEnd(oldBundleInfo);
6396 EXPECT_TRUE(ret);
6397 }
6398
6399 /**
6400 * @tc.number: SetDisposedRuleWhenBundleUpdateStart_0030
6401 * @tc.name: test SetDisposedRuleWhenBundleUpdateStart
6402 * @tc.desc: 1.SetDisposedRuleWhenBundleUpdateStart
6403 */
6404 HWTEST_F(BmsBundleInstallerTest, SetDisposedRuleWhenBundleUpdateStart_0030, Function | SmallTest | Level0)
6405 {
6406 InnerBundleInfo oldBundleInfo;
6407 InnerModuleInfo innerModuleInfo;
6408 innerModuleInfo.moduleName = MODULE_NAME;
6409 oldBundleInfo.innerModuleInfos_[BUNDLE_NAME] = innerModuleInfo;
6410
6411 InnerBundleInfo newBundleInfo;
6412 InnerModuleInfo newInnerModuleInfo;
6413 newInnerModuleInfo.moduleName = BUNDLE_NAME;
6414 newBundleInfo.innerModuleInfos_[BUNDLE_NAME] = newInnerModuleInfo;
6415 std::unordered_map<std::string, InnerBundleInfo> infos;
6416 infos[BUNDLE_NAME] = newBundleInfo;
6417
6418 BaseBundleInstaller installer;
6419 installer.isAppExist_ = true;
6420 bool ret = installer.SetDisposedRuleWhenBundleUpdateStart(infos, oldBundleInfo, false);
6421 EXPECT_FALSE(ret);
6422 EXPECT_FALSE(installer.needSetDisposeRule_);
6423 ret = installer.DeleteDisposedRuleWhenBundleUpdateEnd(oldBundleInfo);
6424 EXPECT_FALSE(ret);
6425 }
6426
6427 /**
6428 * @tc.number: VerifyCodeSignatureForNativeFiles_0100
6429 * @tc.name: test VerifyCodeSignatureForNativeFiles
6430 * @tc.desc: test VerifyCodeSignatureForNativeFiles of BundleInstallerManager
6431 */
6432 HWTEST_F(BmsBundleInstallerTest, VerifyCodeSignatureForNativeFiles_0100, Function | SmallTest | Level1)
6433 {
6434 AppServiceFwkInstaller appServiceFwkInstaller;
6435
6436 std::string bundlePath;
6437 std::string cpuAbi;
6438 std::string targetSoPath;
6439 ErrCode ret = appServiceFwkInstaller.VerifyCodeSignatureForNativeFiles(bundlePath, cpuAbi, targetSoPath);
6440
6441 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
6442 }
6443
6444 /**
6445 * @tc.number: ExtractModule_0100
6446 * @tc.name: test ExtractModule
6447 * @tc.desc: 1.Test the ExtractModule
6448 */
6449 HWTEST_F(BmsBundleInstallerTest, ExtractModule_0100, Function | SmallTest | Level0)
6450 {
6451 AppServiceFwkInstaller appServiceFwkInstaller;
6452 InnerBundleInfo newInfo;
6453 std::string bundlePath;
6454
6455 appServiceFwkInstaller.newInnerBundleInfo_.baseApplicationInfo_->bundleName = "com.acts.example";
6456 appServiceFwkInstaller.MergeBundleInfos(newInfo);
6457
6458 std::unordered_map<std::string, InnerBundleInfo> infos;
6459 std::vector<Security::Verify::HapVerifyResult> hapVerifyRes;
6460
6461 appServiceFwkInstaller.GenerateOdid(infos, hapVerifyRes);
6462
6463 Security::Verify::HapVerifyResult hapVerifyResult;
6464 Security::Verify::ProvisionInfo provisionInfo;
6465 hapVerifyResult.SetProvisionInfo(provisionInfo);
6466 hapVerifyRes.push_back(hapVerifyResult);
6467
6468 appServiceFwkInstaller.GenerateOdid(infos, hapVerifyRes);
6469
6470 ErrCode ret = appServiceFwkInstaller.ExtractModule(newInfo, bundlePath);
6471 EXPECT_EQ(ret, ERR_OK);
6472 }
6473 } // OHOS
6474