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