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 #include "bundle_info.h"
34 #include "bundle_installer_host.h"
35 #include "bundle_mgr_service.h"
36 #include "directory_ex.h"
37 #include "install_param.h"
38 #include "installd/installd_service.h"
39 #include "installd_client.h"
40 #include "mock_status_receiver.h"
41 #include "scope_guard.h"
42 #include "shared/shared_bundle_installer.h"
43 #include "system_bundle_installer.h"
44 #include "want.h"
45 #include "file_ex.h"
46
47 using namespace testing::ext;
48 using namespace std::chrono_literals;
49 using namespace OHOS::AppExecFwk;
50 using OHOS::DelayedSingleton;
51
52 namespace OHOS {
53 namespace {
54 const std::string SYSTEMFIEID_NAME = "com.query.test";
55 const std::string SYSTEMFIEID_BUNDLE = "system_module.hap";
56 const std::string BUNDLE_NAME = "com.example.l3jsdemo";
57 const std::string MODULE_NAME_TEST = "moduleName";
58 const std::string RESOURCE_ROOT_PATH = "/data/test/resource/bms/install_bundle/";
59 const std::string TEST_CREATE_DIR_PATH = "/data/test/resource/bms/install_bundle/test_create_dir";
60 const std::string TEST_CREATE_FILE_PATH = "/data/test/resource/bms/install_bundle/test_create_dir/test.hap";
61 const std::string INVALID_PATH = "/install_bundle/";
62 const std::string RIGHT_BUNDLE = "right.hap";
63 const std::string TYPE_BUNDLE = "devicetype_error.hap";
64 const std::string INVALID_BUNDLE = "nonfile.hap";
65 const std::string WRONG_BUNDLE_NAME = "wrong_bundle_name.ha";
66 const std::string BUNDLE_DATA_DIR = "/data/app/el2/100/base/com.example.l3jsdemo";
67 const std::string BUNDLE_CODE_DIR = "/data/app/el1/bundle/public/com.example.l3jsdemo";
68 const int32_t USERID = 100;
69 const int32_t WAIT_TIME = 5; // init mocked bms
70 const std::string BUNDLE_BACKUP_TEST = "backup.hap";
71 const std::string BUNDLE_MODULEJSON_TEST = "moduleJsonTest.hap";
72 const std::string BUNDLE_PREVIEW_TEST = "preview.hap";
73 const std::string BUNDLE_THUMBNAIL_TEST = "thumbnail.hap";
74 const std::string BUNDLE_BACKUP_NAME = "com.example.backuptest";
75 const std::string BUNDLE_MODULEJSON_NAME = "com.test.modulejsontest";
76 const std::string BUNDLE_PREVIEW_NAME = "com.example.previewtest";
77 const std::string BUNDLE_THUMBNAIL_NAME = "com.example.thumbnailtest";
78 const std::string MODULE_NAME = "entry";
79 const std::string EXTENSION_ABILITY_NAME = "extensionAbility_A";
80 const std::string TEST_STRING = "test.string";
81 const std::string TEST_PACK_AGE = "entry";
82 const std::string NOEXIST = "noExist";
83 const std::string CURRENT_PATH = "/data/service/el2/100/hmdfs/account/data/test_max";
84 const size_t NUMBER_ONE = 1;
85 const int32_t INVAILD_CODE = -1;
86 const int32_t ZERO_CODE = 0;
87 const std::string LOG = "log";
88 const int32_t EDM_UID = 3057;
89 #ifdef BUNDLE_FRAMEWORK_APP_CONTROL
90 const std::string EMPTY_STRING = "";
91 const std::string APPID_INPUT = "com.third.hiworld.example1";
92 const std::string APPID = "com.third.hiworld.example1_BNtg4JBClbl92Rgc3jm/"
93 "RfcAdrHXaM8F0QOiwVEhnV5ebE5jNIYnAx+weFRT3QTyUjRNdhmc2aAzWyi+5t5CoBM=";
94 const std::string NORMAL_BUNDLE_NAME = "bundleName";
95 const std::string FIRST_RIGHT_HAP = "first_right.hap";
96 #endif
97 const std::string BUNDLE_LIBRARY_PATH_DIR = "/data/app/el1/bundle/public/com.example.l3jsdemo/libs/arm";
98 const std::string BUNDLE_NAME_TEST = "bundleNameTest";
99 const std::string BUNDLE_NAME_TEST1 = "bundleNameTest1";
100 const std::string DEVICE_ID = "PHONE-001";
101 const std::string TEST_CPU_ABI = "arm64";
102 } // namespace
103
104 class BmsBundleInstallerTest : public testing::Test {
105 public:
106 BmsBundleInstallerTest();
107 ~BmsBundleInstallerTest();
108 static void SetUpTestCase();
109 static void TearDownTestCase();
110 void SetUp();
111 void TearDown();
112 bool InstallSystemBundle(const std::string &filePath) const;
113 bool OTAInstallSystemBundle(const std::string &filePath) const;
114 ErrCode InstallThirdPartyBundle(const std::string &filePath) const;
115 ErrCode UpdateThirdPartyBundle(const std::string &filePath) const;
116 ErrCode UnInstallBundle(const std::string &bundleName) const;
117 void CheckFileExist() const;
118 void CheckFileNonExist() const;
119 const std::shared_ptr<BundleDataMgr> GetBundleDataMgr() const;
120 const std::shared_ptr<BundleInstallerManager> GetBundleInstallerManager() const;
121 void StopInstalldService() const;
122 void StopBundleService();
123 void CreateInstallerManager();
124 void ClearBundleInfo();
125 void ClearDataMgr();
126 void ResetDataMgr();
127
128 private:
129 std::shared_ptr<BundleInstallerManager> manager_ = nullptr;
130 static std::shared_ptr<InstalldService> installdService_;
131 static std::shared_ptr<BundleMgrService> bundleMgrService_;
132 };
133
134 std::shared_ptr<BundleMgrService> BmsBundleInstallerTest::bundleMgrService_ =
135 DelayedSingleton<BundleMgrService>::GetInstance();
136
137 std::shared_ptr<InstalldService> BmsBundleInstallerTest::installdService_ =
138 std::make_shared<InstalldService>();
139
BmsBundleInstallerTest()140 BmsBundleInstallerTest::BmsBundleInstallerTest()
141 {}
142
~BmsBundleInstallerTest()143 BmsBundleInstallerTest::~BmsBundleInstallerTest()
144 {}
145
InstallSystemBundle(const std::string & filePath) const146 bool BmsBundleInstallerTest::InstallSystemBundle(const std::string &filePath) const
147 {
148 bundleMgrService_->GetDataMgr()->AddUserId(USERID);
149 auto installer = std::make_unique<SystemBundleInstaller>();
150 InstallParam installParam;
151 installParam.userId = USERID;
152 installParam.isPreInstallApp = true;
153 installParam.noSkipsKill = false;
154 installParam.needSendEvent = false;
155 installParam.needSavePreInstallInfo = true;
156 installParam.copyHapToInstallPath = false;
157 return installer->InstallSystemBundle(filePath, installParam, Constants::AppType::SYSTEM_APP);
158 }
159
OTAInstallSystemBundle(const std::string & filePath) const160 bool BmsBundleInstallerTest::OTAInstallSystemBundle(const std::string &filePath) const
161 {
162 bundleMgrService_->GetDataMgr()->AddUserId(USERID);
163 auto installer = std::make_unique<SystemBundleInstaller>();
164 std::vector<std::string> filePaths;
165 filePaths.push_back(filePath);
166 InstallParam installParam;
167 installParam.userId = USERID;
168 installParam.isPreInstallApp = true;
169 installParam.noSkipsKill = false;
170 installParam.needSendEvent = false;
171 installParam.needSavePreInstallInfo = true;
172 installParam.copyHapToInstallPath = false;
173 return installer->OTAInstallSystemBundle(filePaths, installParam, Constants::AppType::SYSTEM_APP);
174 }
175
InstallThirdPartyBundle(const std::string & filePath) const176 ErrCode BmsBundleInstallerTest::InstallThirdPartyBundle(const std::string &filePath) const
177 {
178 bundleMgrService_->GetDataMgr()->AddUserId(USERID);
179 auto installer = bundleMgrService_->GetBundleInstaller();
180 if (!installer) {
181 EXPECT_FALSE(true) << "the installer is nullptr";
182 return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR;
183 }
184 sptr<MockStatusReceiver> receiver = new (std::nothrow) MockStatusReceiver();
185 if (!receiver) {
186 EXPECT_FALSE(true) << "the receiver is nullptr";
187 return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR;
188 }
189 InstallParam installParam;
190 installParam.userId = USERID;
191 installParam.installFlag = InstallFlag::NORMAL;
192 bool result = installer->Install(filePath, installParam, receiver);
193 EXPECT_TRUE(result);
194 return receiver->GetResultCode();
195 }
196
UpdateThirdPartyBundle(const std::string & filePath) const197 ErrCode BmsBundleInstallerTest::UpdateThirdPartyBundle(const std::string &filePath) const
198 {
199 bundleMgrService_->GetDataMgr()->AddUserId(USERID);
200 auto installer = bundleMgrService_->GetBundleInstaller();
201 if (!installer) {
202 EXPECT_FALSE(true) << "the installer is nullptr";
203 return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR;
204 }
205 sptr<MockStatusReceiver> receiver = new (std::nothrow) MockStatusReceiver();
206 if (!receiver) {
207 EXPECT_FALSE(true) << "the receiver is nullptr";
208 return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR;
209 }
210 InstallParam installParam;
211 installParam.userId = USERID;
212 installParam.installFlag = InstallFlag::REPLACE_EXISTING;
213 bool result = installer->Install(filePath, installParam, receiver);
214 EXPECT_TRUE(result);
215 return receiver->GetResultCode();
216 }
217
UnInstallBundle(const std::string & bundleName) const218 ErrCode BmsBundleInstallerTest::UnInstallBundle(const std::string &bundleName) const
219 {
220 bundleMgrService_->GetDataMgr()->AddUserId(USERID);
221 auto installer = bundleMgrService_->GetBundleInstaller();
222 if (!installer) {
223 EXPECT_FALSE(true) << "the installer is nullptr";
224 return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR;
225 }
226 sptr<MockStatusReceiver> receiver = new (std::nothrow) MockStatusReceiver();
227 if (!receiver) {
228 EXPECT_FALSE(true) << "the receiver is nullptr";
229 return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR;
230 }
231 InstallParam installParam;
232 installParam.userId = USERID;
233 installParam.installFlag = InstallFlag::NORMAL;
234 bool result = installer->Uninstall(bundleName, installParam, receiver);
235 EXPECT_TRUE(result);
236 return receiver->GetResultCode();
237 }
238
SetUpTestCase()239 void BmsBundleInstallerTest::SetUpTestCase()
240 {
241 }
242
TearDownTestCase()243 void BmsBundleInstallerTest::TearDownTestCase()
244 {
245 bundleMgrService_->OnStop();
246 }
247
SetUp()248 void BmsBundleInstallerTest::SetUp()
249 {
250 if (!installdService_->IsServiceReady()) {
251 installdService_->Start();
252 }
253 if (!bundleMgrService_->IsServiceReady()) {
254 bundleMgrService_->OnStart();
255 std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME));
256 }
257 }
258
TearDown()259 void BmsBundleInstallerTest::TearDown()
260 {
261 OHOS::ForceRemoveDirectory(BUNDLE_DATA_DIR);
262 OHOS::ForceRemoveDirectory(BUNDLE_CODE_DIR);
263 OHOS::ForceRemoveDirectory(BUNDLE_LIBRARY_PATH_DIR);
264 }
265
CheckFileExist() const266 void BmsBundleInstallerTest::CheckFileExist() const
267 {
268 int bundleCodeExist = access(BUNDLE_CODE_DIR.c_str(), F_OK);
269 EXPECT_EQ(bundleCodeExist, 0) << "the bundle code dir does not exists: " << BUNDLE_CODE_DIR;
270
271 int bundleDataExist = access(BUNDLE_DATA_DIR.c_str(), F_OK);
272 EXPECT_EQ(bundleDataExist, 0) << "the bundle data dir does not exists: " << BUNDLE_DATA_DIR;
273 }
274
CheckFileNonExist() const275 void BmsBundleInstallerTest::CheckFileNonExist() const
276 {
277 int bundleCodeExist = access(BUNDLE_CODE_DIR.c_str(), F_OK);
278 EXPECT_NE(bundleCodeExist, 0) << "the bundle code dir exists: " << BUNDLE_CODE_DIR;
279
280 int bundleDataExist = access(BUNDLE_DATA_DIR.c_str(), F_OK);
281 EXPECT_NE(bundleDataExist, 0) << "the bundle data dir exists: " << BUNDLE_DATA_DIR;
282 }
283
GetBundleDataMgr() const284 const std::shared_ptr<BundleDataMgr> BmsBundleInstallerTest::GetBundleDataMgr() const
285 {
286 return bundleMgrService_->GetDataMgr();
287 }
288
GetBundleInstallerManager() const289 const std::shared_ptr<BundleInstallerManager> BmsBundleInstallerTest::GetBundleInstallerManager() const
290 {
291 return manager_;
292 }
293
ClearDataMgr()294 void BmsBundleInstallerTest::ClearDataMgr()
295 {
296 bundleMgrService_->dataMgr_ = nullptr;
297 }
298
ResetDataMgr()299 void BmsBundleInstallerTest::ResetDataMgr()
300 {
301 bundleMgrService_->dataMgr_ = std::make_shared<BundleDataMgr>();
302 EXPECT_NE(bundleMgrService_->dataMgr_, nullptr);
303 }
304
StopInstalldService() const305 void BmsBundleInstallerTest::StopInstalldService() const
306 {
307 if (installdService_->IsServiceReady()) {
308 installdService_->Stop();
309 InstalldClient::GetInstance()->ResetInstalldProxy();
310 }
311 }
312
StopBundleService()313 void BmsBundleInstallerTest::StopBundleService()
314 {
315 if (bundleMgrService_->IsServiceReady()) {
316 bundleMgrService_->OnStop();
317 bundleMgrService_.reset();
318 }
319 }
320
CreateInstallerManager()321 void BmsBundleInstallerTest::CreateInstallerManager()
322 {
323 if (manager_ != nullptr) {
324 return;
325 }
326 manager_ = std::make_shared<BundleInstallerManager>();
327 EXPECT_NE(nullptr, manager_);
328 }
329
ClearBundleInfo()330 void BmsBundleInstallerTest::ClearBundleInfo()
331 {
332 if (bundleMgrService_ == nullptr) {
333 return;
334 }
335 auto dataMgt = bundleMgrService_->GetDataMgr();
336 if (dataMgt == nullptr) {
337 return;
338 }
339 auto dataStorage = dataMgt->GetDataStorage();
340 if (dataStorage == nullptr) {
341 return;
342 }
343
344 // clear innerBundleInfo from data manager
345 dataMgt->UpdateBundleInstallState(BUNDLE_NAME, InstallState::UNINSTALL_START);
346 dataMgt->UpdateBundleInstallState(BUNDLE_NAME, InstallState::UNINSTALL_SUCCESS);
347
348 InnerBundleInfo innerBundleInfo;
349 ApplicationInfo applicationInfo;
350 applicationInfo.bundleName = BUNDLE_NAME;
351 innerBundleInfo.SetBaseApplicationInfo(applicationInfo);
352 // clear innerBundleInfo from data storage
353 bool result = dataStorage->DeleteStorageBundleInfo(innerBundleInfo);
354 EXPECT_TRUE(result) << "the bundle info in db clear fail: " << BUNDLE_NAME;
355 }
356
357 /**
358 * @tc.number: SystemInstall_0100
359 * @tc.name: test the right system bundle file can be installed
360 * @tc.desc: 1.the system bundle file exists
361 * 2.the system bundle can be installed successfully and can get the bundle info
362 */
363 HWTEST_F(BmsBundleInstallerTest, SystemInstall_0100, Function | SmallTest | Level0)
364 {
365 std::string bundleFile = RESOURCE_ROOT_PATH + RIGHT_BUNDLE;
366 bool result = InstallSystemBundle(bundleFile);
367 EXPECT_TRUE(result) << "the bundle file install failed: " << bundleFile;
368 CheckFileExist();
369 ClearBundleInfo();
370 }
371
372 /**
373 * @tc.number: SystemInstall_0200
374 * @tc.name: test the wrong system bundle file can't be installed
375 * @tc.desc: 1.the system bundle file don't exists
376 * 2.the system bundle can't be installed and the result is fail
377 */
378 HWTEST_F(BmsBundleInstallerTest, SystemInstall_0200, Function | SmallTest | Level0)
379 {
380 std::string nonExistFile = RESOURCE_ROOT_PATH + INVALID_BUNDLE;
381 bool result = InstallSystemBundle(nonExistFile);
382 EXPECT_FALSE(result) << "the bundle file install success: " << nonExistFile;
383 CheckFileNonExist();
384 }
385
386 /**
387 * @tc.number: SystemInstall_0300
388 * @tc.name: test the empty path can't be installed
389 * @tc.desc: 1.the system bundle file path is empty
390 * 2.the system bundle can't be installed and the result is fail
391 */
392 HWTEST_F(BmsBundleInstallerTest, SystemInstall_0300, Function | SmallTest | Level0)
393 {
394 bool result = InstallSystemBundle("");
395 EXPECT_FALSE(result) << "the empty path install success";
396 CheckFileNonExist();
397 }
398
399 /**
400 * @tc.number: SystemInstall_0400
401 * @tc.name: test the illegal bundleName file can't be installed
402 * @tc.desc: 1.the system bundle name is illegal
403 * 2.the system bundle can't be installed and the result is fail
404 */
405 HWTEST_F(BmsBundleInstallerTest, SystemInstall_0400, Function | SmallTest | Level0)
406 {
407 std::string wrongBundleName = RESOURCE_ROOT_PATH + WRONG_BUNDLE_NAME;
408 bool result = InstallSystemBundle(wrongBundleName);
409 EXPECT_FALSE(result) << "the wrong bundle file install success";
410 CheckFileNonExist();
411 }
412
413 /**
414 * @tc.number: SystemInstall_0500
415 * @tc.name: test the bundle file with invalid path will cause the result of install failure
416 * @tc.desc: 1.the bundle file has invalid path
417 * 2.the system bundle can't be installed and the result is fail
418 */
419 HWTEST_F(BmsBundleInstallerTest, SystemInstall_0500, Function | SmallTest | Level0)
420 {
421 std::string bundleFile = INVALID_PATH + RIGHT_BUNDLE;
422 bool result = InstallSystemBundle(bundleFile);
423 EXPECT_FALSE(result) << "the invalid path install success";
424 CheckFileNonExist();
425 }
426
427 /**
428 * @tc.number: SystemInstall_0600
429 * @tc.name: test the install will fail when installd service has error
430 * @tc.desc: 1.the installd service has error
431 * 2.the install result is fail
432 */
433 HWTEST_F(BmsBundleInstallerTest, SystemInstall_0600, Function | SmallTest | Level0)
434 {
435 StopInstalldService();
436 std::string bundleFile = RESOURCE_ROOT_PATH + RIGHT_BUNDLE;
437 bool result = InstallSystemBundle(bundleFile);
438 EXPECT_FALSE(result);
439 }
440
441 /**
442 * @tc.number: ThirdPartyInstall_0100
443 * @tc.name: test the install will fail when installd service has error
444 * @tc.desc: 1.the installd service has error
445 * 2.the install result is fail
446 */
447 HWTEST_F(BmsBundleInstallerTest, ThirdPartyInstall_0100, Function | SmallTest | Level0)
448 {
449 StopInstalldService();
450 std::string bundleFile = RESOURCE_ROOT_PATH + TYPE_BUNDLE;
451 auto result = InstallThirdPartyBundle(bundleFile);
452 EXPECT_EQ(result, ERR_APPEXECFWK_INSTALL_DEVICE_TYPE_NOT_SUPPORTED);
453 }
454
455 /**
456 * @tc.number: SystemUpdateData_0100
457 * @tc.name: test the right bundle file can be installed and update its info to bms
458 * @tc.desc: 1.the system bundle is available
459 * 2.the right bundle can be installed and update its info to bms
460 */
461 HWTEST_F(BmsBundleInstallerTest, SystemUpdateData_0100, Function | SmallTest | Level0)
462 {
463 ApplicationInfo info;
464 auto dataMgr = GetBundleDataMgr();
465 EXPECT_NE(dataMgr, nullptr);
466 bool result = dataMgr->GetApplicationInfo(BUNDLE_NAME, ApplicationFlag::GET_BASIC_APPLICATION_INFO, USERID, info);
467 EXPECT_FALSE(result);
468 std::string bundleFile = RESOURCE_ROOT_PATH + RIGHT_BUNDLE;
469 bool installResult = InstallSystemBundle(bundleFile);
470 EXPECT_TRUE(installResult);
471 result = dataMgr->GetApplicationInfo(BUNDLE_NAME, ApplicationFlag::GET_BASIC_APPLICATION_INFO, USERID, info);
472 EXPECT_TRUE(result);
473 EXPECT_EQ(info.name, BUNDLE_NAME);
474 ClearBundleInfo();
475 }
476
477 /**
478 * @tc.number: SystemUpdateData_0200
479 * @tc.name: test the wrong bundle file can't be installed and its info will not updated to bms
480 * @tc.desc: 1.the system bundle is wrong
481 * 2.the wrong bundle can't be installed and its info will not updated to bms
482 */
483 HWTEST_F(BmsBundleInstallerTest, SystemUpdateData_0200, Function | SmallTest | Level0)
484 {
485 ApplicationInfo info;
486 auto dataMgr = GetBundleDataMgr();
487 EXPECT_NE(dataMgr, nullptr);
488 bool result = dataMgr->GetApplicationInfo(BUNDLE_NAME, ApplicationFlag::GET_BASIC_APPLICATION_INFO, USERID, info);
489 EXPECT_FALSE(result);
490 std::string wrongBundleName = RESOURCE_ROOT_PATH + WRONG_BUNDLE_NAME;
491 bool installResult = InstallSystemBundle(wrongBundleName);
492 EXPECT_FALSE(installResult);
493 result = dataMgr->GetApplicationInfo(BUNDLE_NAME, ApplicationFlag::GET_BASIC_APPLICATION_INFO, USERID, info);
494 EXPECT_FALSE(result);
495 }
496
497 /**
498 * @tc.number: SystemUpdateData_0300
499 * @tc.name: test the already installed bundle can't be reinstalled and update its info to bms
500 * @tc.desc: 1.the bundle is already installed
501 * 2.the already installed bundle can't be reinstalled and update its info to bms
502 */
503 HWTEST_F(BmsBundleInstallerTest, SystemUpdateData_0300, Function | SmallTest | Level0)
504 {
505 auto dataMgr = GetBundleDataMgr();
506 EXPECT_NE(dataMgr, nullptr);
507 // prepare already install information.
508 std::string bundleFile = RESOURCE_ROOT_PATH + RIGHT_BUNDLE;
509 bool firstInstall = InstallSystemBundle(bundleFile);
510 EXPECT_TRUE(firstInstall);
511 ApplicationInfo info;
512 auto result = dataMgr->GetApplicationInfo(BUNDLE_NAME, ApplicationFlag::GET_BASIC_APPLICATION_INFO, USERID, info);
513 EXPECT_TRUE(result);
514 EXPECT_EQ(info.name, BUNDLE_NAME);
515 bool secondInstall = InstallSystemBundle(bundleFile);
516 EXPECT_FALSE(secondInstall);
517 ClearBundleInfo();
518 }
519
520 /**
521 * @tc.number: SystemUpdateData_0400
522 * @tc.name: test the already installing bundle can't be reinstalled and update its info to bms
523 * @tc.desc: 1.the bundle is already installing.
524 * 2.the already installing bundle can't be reinstalled and update its info to bms
525 */
526 HWTEST_F(BmsBundleInstallerTest, SystemUpdateData_0400, Function | SmallTest | Level0)
527 {
528 // prepare already install information.
529 auto dataMgr = GetBundleDataMgr();
530 EXPECT_NE(dataMgr, nullptr);
531 dataMgr->UpdateBundleInstallState(BUNDLE_NAME, InstallState::INSTALL_START);
532 // begin to reinstall package
533 std::string bundleFile = RESOURCE_ROOT_PATH + RIGHT_BUNDLE;
534 bool installResult = InstallSystemBundle(bundleFile);
535 EXPECT_FALSE(installResult);
536 // reset the install state
537 dataMgr->UpdateBundleInstallState(BUNDLE_NAME, InstallState::INSTALL_FAIL);
538 ClearBundleInfo();
539 }
540
541 /**
542 * @tc.number: CreateInstallTask_0100
543 * @tc.name: test the installer manager can create task
544 * @tc.desc: 1.the bundle file exists
545 * 2.the bundle can be installed successfully
546 */
547 HWTEST_F(BmsBundleInstallerTest, CreateInstallTask_0100, Function | SmallTest | Level0)
548 {
549 CreateInstallerManager();
550 sptr<MockStatusReceiver> receiver = new (std::nothrow) MockStatusReceiver();
551 EXPECT_NE(receiver, nullptr);
552 InstallParam installParam;
553 installParam.userId = USERID;
554 std::string bundleFile = RESOURCE_ROOT_PATH + RIGHT_BUNDLE;
555 GetBundleInstallerManager()->CreateInstallTask(bundleFile, installParam, receiver);
556 ErrCode result = receiver->GetResultCode();
557 EXPECT_EQ(ERR_OK, result);
558 ClearBundleInfo();
559 }
560
561 /**
562 * @tc.number: CreateInstallTask_0200
563 * @tc.name: test the installer manager can not create task while bundle invalid
564 * @tc.desc: 1.the invalid bundle file exists
565 * 2.install the invalid bundle failed
566 */
567 HWTEST_F(BmsBundleInstallerTest, CreateInstallTask_0200, Function | SmallTest | Level0)
568 {
569 CreateInstallerManager();
570 sptr<MockStatusReceiver> receiver = new (std::nothrow) MockStatusReceiver();
571 EXPECT_NE(receiver, nullptr);
572 InstallParam installParam;
573 installParam.userId = USERID;
574 std::string bundleFile = RESOURCE_ROOT_PATH + INVALID_BUNDLE;
575 GetBundleInstallerManager()->CreateInstallTask(bundleFile, installParam, receiver);
576 ErrCode result = receiver->GetResultCode();
577 EXPECT_NE(ERR_OK, result);
578 }
579
580 /**
581 * @tc.number: CreateUninstallTask_0200
582 * @tc.name: test the installer manager can not create task while bundle invalid
583 * @tc.desc: 1.the invalid bundle file exists
584 * 2.uninstall the bundle failed
585 */
586 HWTEST_F(BmsBundleInstallerTest, CreateUninstallTask_0200, Function | SmallTest | Level0)
587 {
588 CreateInstallerManager();
589 sptr<MockStatusReceiver> receiver = new (std::nothrow) MockStatusReceiver();
590 EXPECT_NE(receiver, nullptr);
591 InstallParam installParam;
592 installParam.userId = USERID;
593 std::string bundleFile = RESOURCE_ROOT_PATH + INVALID_BUNDLE;
594 GetBundleInstallerManager()->CreateUninstallTask(bundleFile, installParam, receiver);
595 ErrCode result = receiver->GetResultCode();
596 EXPECT_NE(ERR_OK, result);
597 }
598
599 /**
600 * @tc.number: ParseModuleJson_0100
601 * @tc.name: parse module json
602 * @tc.desc: 1.the bundle is already installing.
603 * 2.You can query the related moudle.json information
604 * 3.The system field tested is the configured field
605 */
606 HWTEST_F(BmsBundleInstallerTest, ParseModuleJson_0100, Function | SmallTest | Level0)
607 {
608 ApplicationInfo info;
609 auto dataMgr = GetBundleDataMgr();
610 EXPECT_NE(dataMgr, nullptr);
611 std::string bundleFile = RESOURCE_ROOT_PATH + SYSTEMFIEID_BUNDLE;
612 ErrCode installResult = InstallThirdPartyBundle(bundleFile);
613 EXPECT_EQ(installResult, ERR_OK);
614 bool result =
615 dataMgr->GetApplicationInfo(SYSTEMFIEID_NAME, ApplicationFlag::GET_BASIC_APPLICATION_INFO, USERID, info);
616 EXPECT_TRUE(result);
617 if (result) {
618 EXPECT_EQ(info.name, "com.query.test");
619 EXPECT_EQ(info.description, "$string:description_application");
620 EXPECT_EQ(info.descriptionId, 16777217);
621 EXPECT_EQ(info.label, "$string:app_name");
622 EXPECT_EQ(info.labelId, 16777216);
623 EXPECT_EQ(info.iconPath, "$media:app_icon");
624 EXPECT_EQ(info.iconId, 16777228);
625 EXPECT_EQ(static_cast<uint32_t>(info.versionCode), 1);
626 EXPECT_EQ(info.versionName, "1.0");
627 EXPECT_EQ(info.minCompatibleVersionCode, 1);
628 EXPECT_EQ(info.apiCompatibleVersion, 8);
629 EXPECT_EQ(info.apiTargetVersion, 8);
630 AbilityInfo abilityInfo;
631 abilityInfo.bundleName = SYSTEMFIEID_NAME;
632 abilityInfo.package = "module01";
633 HapModuleInfo hapModuleInfo;
634 bool ret = dataMgr->GetHapModuleInfo(abilityInfo, hapModuleInfo);
635 EXPECT_TRUE(ret);
636 EXPECT_EQ(hapModuleInfo.name, "module01");
637 EXPECT_EQ(hapModuleInfo.description, "$string:description_application");
638 EXPECT_EQ(hapModuleInfo.mainAbility, "MainAbility");
639 EXPECT_EQ(hapModuleInfo.process, "bba");
640 EXPECT_EQ(hapModuleInfo.virtualMachine, "");
641 EXPECT_EQ(hapModuleInfo.uiSyntax, "hml");
642 EXPECT_EQ(hapModuleInfo.pages, "$profile:page_config");
643 EXPECT_EQ(hapModuleInfo.deliveryWithInstall, true);
644 EXPECT_EQ(hapModuleInfo.installationFree, false);
645 EXPECT_EQ(hapModuleInfo.srcEntrance, "./MyAbilityStage.ts");
646 EXPECT_EQ(hapModuleInfo.isolationMode, IsolationMode::NONISOLATION_FIRST);
647
648 auto abilityInfos = hapModuleInfo.abilityInfos.front();
649 EXPECT_EQ(abilityInfos.name, "MainAbility");
650 EXPECT_EQ(abilityInfos.srcEntrance, "./login/MyLoginAbility.ts");
651 EXPECT_EQ(abilityInfos.description, "$string:description_main_ability");
652 EXPECT_EQ(abilityInfos.descriptionId, 16777219);
653 EXPECT_EQ(hapModuleInfo.label, "Login");
654
655 auto metadata = abilityInfos.metadata.front();
656 EXPECT_EQ(metadata.name, "a01");
657 EXPECT_EQ(metadata.value, "v01");
658 EXPECT_EQ(metadata.resource, "hello");
659
660 auto extensionInfos = hapModuleInfo.extensionInfos.front();
661 EXPECT_EQ(extensionInfos.name, "FormName");
662 EXPECT_EQ(extensionInfos.srcEntrance, "./form/MyForm.ts");
663 EXPECT_EQ(extensionInfos.description, "$string:form_description");
664 EXPECT_EQ(extensionInfos.descriptionId, 16777221);
665 EXPECT_EQ(extensionInfos.visible, true);
666 EXPECT_EQ(extensionInfos.icon, "$media:icon");
667 EXPECT_EQ(extensionInfos.iconId, 16777229);
668 EXPECT_EQ(extensionInfos.label, "$string:extension_name");
669 EXPECT_EQ(extensionInfos.labelId, 16777220);
670 }
671 UnInstallBundle(SYSTEMFIEID_NAME);
672 }
673
674 /**
675 * @tc.number: BackupExtension_0100
676 * @tc.name: test the backup type
677 * @tc.desc: 1.install the hap
678 * 2.query extensionAbilityInfos
679 */
680 HWTEST_F(BmsBundleInstallerTest, BackupExtension_0100, Function | SmallTest | Level0)
681 {
682 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
683 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
684 EXPECT_EQ(installResult, ERR_OK);
685
686 auto dataMgr = GetBundleDataMgr();
687 EXPECT_NE(dataMgr, nullptr);
688 AAFwk::Want want;
689 want.SetAction("action.system.home");
690 want.AddEntity("entity.system.home");
691 want.SetElementName("", BUNDLE_BACKUP_NAME, "", "");
692 std::vector<ExtensionAbilityInfo> infos;
693 bool result = dataMgr->QueryExtensionAbilityInfos(want, 0, USERID, infos);
694 EXPECT_TRUE(result);
695 EXPECT_EQ(infos.size(), NUMBER_ONE);
696 if (infos.size() > 0) {
697 EXPECT_EQ(infos[0].bundleName, BUNDLE_BACKUP_NAME);
698 EXPECT_EQ(infos[0].type, ExtensionAbilityType::BACKUP);
699 }
700 UnInstallBundle(BUNDLE_BACKUP_NAME);
701 }
702
703 /**
704 * @tc.name: PREVIEWExtension_0100
705 * @tc.desc: 1.install the hap
706 * 2.query extensionAbilityInfos
707 * @tc.type: FUNC
708 * @tc.require: issueI5MZ33
709 */
710 HWTEST_F(BmsBundleInstallerTest, PREVIEWExtension_0100, Function | SmallTest | Level0)
711 {
712 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_PREVIEW_TEST;
713 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
714 EXPECT_EQ(installResult, ERR_OK);
715
716 auto dataMgr = GetBundleDataMgr();
717 EXPECT_NE(dataMgr, nullptr);
718 AAFwk::Want want;
719 want.SetAction("action.system.home");
720 want.AddEntity("entity.system.home");
721 want.SetElementName("", BUNDLE_PREVIEW_NAME, "", "");
722 std::vector<ExtensionAbilityInfo> infos;
723 bool result = dataMgr->QueryExtensionAbilityInfos(want, 0, USERID, infos);
724 EXPECT_TRUE(result);
725 EXPECT_EQ(infos.size(), NUMBER_ONE);
726 if (infos.size() > 0) {
727 EXPECT_EQ(infos[0].bundleName, BUNDLE_PREVIEW_NAME);
728 EXPECT_EQ(infos[0].type, ExtensionAbilityType::PREVIEW);
729 }
730 UnInstallBundle(BUNDLE_PREVIEW_NAME);
731 }
732
733 /**
734 * @tc.name: THUMBNAILExtension_0100
735 * @tc.desc: 1.install the hap
736 * 2.query extensionAbilityInfos
737 * @tc.type: FUNC
738 * @tc.require: issueI5MZ33
739 */
740 HWTEST_F(BmsBundleInstallerTest, THUMBNAILExtension_0100, Function | SmallTest | Level0)
741 {
742 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_THUMBNAIL_TEST;
743 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
744 EXPECT_EQ(installResult, ERR_OK);
745
746 auto dataMgr = GetBundleDataMgr();
747 EXPECT_NE(dataMgr, nullptr);
748 AAFwk::Want want;
749 want.SetAction("action.system.home");
750 want.AddEntity("entity.system.home");
751 want.SetElementName("", BUNDLE_THUMBNAIL_NAME, "", "");
752 std::vector<ExtensionAbilityInfo> infos;
753 bool result = dataMgr->QueryExtensionAbilityInfos(want, 0, USERID, infos);
754 EXPECT_TRUE(result);
755 EXPECT_EQ(infos.size(), NUMBER_ONE);
756 if (infos.size() > 0) {
757 EXPECT_EQ(infos[0].bundleName, BUNDLE_THUMBNAIL_NAME);
758 EXPECT_EQ(infos[0].type, ExtensionAbilityType::THUMBNAIL);
759 }
760 UnInstallBundle(BUNDLE_THUMBNAIL_NAME);
761 }
762
763 /**
764 * @tc.number: QueryExtensionAbilityInfos_0100
765 * @tc.name: test the backup type
766 * @tc.desc: 1.install the hap
767 * 2.query extensionAbilityInfos
768 */
769 HWTEST_F(BmsBundleInstallerTest, QueryExtensionAbilityInfos_0100, Function | SmallTest | Level0)
770 {
771 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
772 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
773 EXPECT_EQ(installResult, ERR_OK);
774
775 auto dataMgr = GetBundleDataMgr();
776 EXPECT_NE(dataMgr, nullptr);
777 AAFwk::Want want;
778 want.SetAction("action.system.home");
779 want.AddEntity("entity.system.home");
780 want.SetElementName("", BUNDLE_BACKUP_NAME, "", MODULE_NAME);
781 std::vector<ExtensionAbilityInfo> infos;
782 bool result = dataMgr->QueryExtensionAbilityInfos(want, 0, USERID, infos);
783 EXPECT_TRUE(result);
784 EXPECT_EQ(infos.size(), NUMBER_ONE);
785 if (infos.size() > 0) {
786 EXPECT_EQ(infos[0].bundleName, BUNDLE_BACKUP_NAME);
787 EXPECT_EQ(infos[0].moduleName, MODULE_NAME);
788 EXPECT_EQ(infos[0].type, ExtensionAbilityType::BACKUP);
789 }
790 UnInstallBundle(BUNDLE_BACKUP_NAME);
791 }
792
793 /**
794 * @tc.number: QueryExtensionAbilityInfos_0200
795 * @tc.name: test the backup type
796 * @tc.desc: 1.install the hap
797 * 2.query extensionAbilityInfos
798 */
799 HWTEST_F(BmsBundleInstallerTest, QueryExtensionAbilityInfos_0200, Function | SmallTest | Level0)
800 {
801 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
802 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
803 EXPECT_EQ(installResult, ERR_OK);
804
805 auto dataMgr = GetBundleDataMgr();
806 EXPECT_NE(dataMgr, nullptr);
807 AAFwk::Want want;
808 want.SetElementName("", BUNDLE_BACKUP_NAME, "", MODULE_NAME);
809 std::vector<ExtensionAbilityInfo> infos;
810 bool result = dataMgr->QueryExtensionAbilityInfos(want, 0, USERID, infos);
811 EXPECT_FALSE(result);
812 UnInstallBundle(BUNDLE_BACKUP_NAME);
813 }
814
815 /**
816 * @tc.number: QueryExtensionAbilityInfos_0300
817 * @tc.name: test the backup type
818 * @tc.desc: 1.install the hap
819 * 2.query extensionAbilityInfos
820 */
821 HWTEST_F(BmsBundleInstallerTest, QueryExtensionAbilityInfos_0300, Function | SmallTest | Level0)
822 {
823 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
824 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
825 EXPECT_EQ(installResult, ERR_OK);
826
827 auto dataMgr = GetBundleDataMgr();
828 EXPECT_NE(dataMgr, nullptr);
829 AAFwk::Want want;
830 want.SetElementName("", BUNDLE_BACKUP_NAME, EXTENSION_ABILITY_NAME, "");
831 std::vector<ExtensionAbilityInfo> infos;
832 bool result = dataMgr->QueryExtensionAbilityInfos(want, 0, USERID, infos);
833 EXPECT_TRUE(result);
834 EXPECT_EQ(infos.size(), NUMBER_ONE);
835 if (infos.size() > 0) {
836 EXPECT_EQ(infos[0].bundleName, BUNDLE_BACKUP_NAME);
837 EXPECT_EQ(infos[0].name, EXTENSION_ABILITY_NAME);
838 EXPECT_EQ(infos[0].type, ExtensionAbilityType::BACKUP);
839 }
840 UnInstallBundle(BUNDLE_BACKUP_NAME);
841 }
842
843 /**
844 * @tc.number: QueryExtensionAbilityInfos_0400
845 * @tc.name: test the backup type
846 * @tc.desc: 1.install the hap
847 * 2.query extensionAbilityInfos
848 */
849 HWTEST_F(BmsBundleInstallerTest, QueryExtensionAbilityInfos_0400, Function | SmallTest | Level0)
850 {
851 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
852 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
853 EXPECT_EQ(installResult, ERR_OK);
854
855 auto dataMgr = GetBundleDataMgr();
856 EXPECT_NE(dataMgr, nullptr);
857 AAFwk::Want want;
858 want.SetElementName("", BUNDLE_BACKUP_NAME, EXTENSION_ABILITY_NAME, MODULE_NAME);
859 std::vector<ExtensionAbilityInfo> infos;
860 bool result = dataMgr->QueryExtensionAbilityInfos(want, 0, USERID, infos);
861 EXPECT_TRUE(result);
862 EXPECT_EQ(infos.size(), NUMBER_ONE);
863 if (infos.size() > 0) {
864 EXPECT_EQ(infos[0].bundleName, BUNDLE_BACKUP_NAME);
865 EXPECT_EQ(infos[0].moduleName, MODULE_NAME);
866 EXPECT_EQ(infos[0].name, EXTENSION_ABILITY_NAME);
867 EXPECT_EQ(infos[0].type, ExtensionAbilityType::BACKUP);
868 }
869 UnInstallBundle(BUNDLE_BACKUP_NAME);
870 }
871
872 /**
873 * @tc.name: QueryExtensionAbilityInfos_0500
874 * @tc.desc: 1.install the hap
875 * 2.query extensionAbilityInfos
876 * @tc.type: FUNC
877 * @tc.require: issueI5MZ33
878 */
879 HWTEST_F(BmsBundleInstallerTest, QueryExtensionAbilityInfos_0500, Function | SmallTest | Level0)
880 {
881 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_PREVIEW_TEST;
882 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
883 EXPECT_EQ(installResult, ERR_OK);
884
885 auto dataMgr = GetBundleDataMgr();
886 EXPECT_NE(dataMgr, nullptr);
887 AAFwk::Want want;
888 want.SetAction("action.system.home");
889 want.AddEntity("entity.system.home");
890 want.SetElementName("", BUNDLE_PREVIEW_NAME, "", MODULE_NAME);
891 std::vector<ExtensionAbilityInfo> infos;
892 bool result = dataMgr->QueryExtensionAbilityInfos(want, 0, USERID, infos);
893 EXPECT_TRUE(result);
894 EXPECT_EQ(infos.size(), NUMBER_ONE);
895 if (infos.size() > 0) {
896 EXPECT_EQ(infos[0].bundleName, BUNDLE_PREVIEW_NAME);
897 EXPECT_EQ(infos[0].moduleName, MODULE_NAME);
898 EXPECT_EQ(infos[0].type, ExtensionAbilityType::PREVIEW);
899 }
900 UnInstallBundle(BUNDLE_PREVIEW_NAME);
901 }
902
903 /**
904 * @tc.name: QueryExtensionAbilityInfos_0600
905 * @tc.desc: 1.install the hap
906 * 2.query extensionAbilityInfos
907 * @tc.type: FUNC
908 * @tc.require: issueI5MZ33
909 */
910 HWTEST_F(BmsBundleInstallerTest, QueryExtensionAbilityInfos_0600, Function | SmallTest | Level0)
911 {
912 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_PREVIEW_TEST;
913 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
914 EXPECT_EQ(installResult, ERR_OK);
915
916 auto dataMgr = GetBundleDataMgr();
917 EXPECT_NE(dataMgr, nullptr);
918 AAFwk::Want want;
919 want.SetElementName("", BUNDLE_PREVIEW_NAME, "", MODULE_NAME);
920 std::vector<ExtensionAbilityInfo> infos;
921 bool result = dataMgr->QueryExtensionAbilityInfos(want, 0, USERID, infos);
922 EXPECT_FALSE(result);
923 UnInstallBundle(BUNDLE_PREVIEW_NAME);
924 }
925
926 /**
927 * @tc.name: QueryExtensionAbilityInfos_0700
928 * @tc.desc: 1.install the hap
929 * 2.query extensionAbilityInfos
930 * @tc.type: FUNC
931 * @tc.require: issueI5MZ33
932 */
933 HWTEST_F(BmsBundleInstallerTest, QueryExtensionAbilityInfos_0700, Function | SmallTest | Level0)
934 {
935 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_PREVIEW_TEST;
936 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
937 EXPECT_EQ(installResult, ERR_OK);
938
939 auto dataMgr = GetBundleDataMgr();
940 EXPECT_NE(dataMgr, nullptr);
941 AAFwk::Want want;
942 want.SetElementName("", BUNDLE_PREVIEW_NAME, EXTENSION_ABILITY_NAME, "");
943 std::vector<ExtensionAbilityInfo> infos;
944 bool result = dataMgr->QueryExtensionAbilityInfos(want, 0, USERID, infos);
945 EXPECT_TRUE(result);
946 EXPECT_EQ(infos.size(), NUMBER_ONE);
947 if (infos.size() > 0) {
948 EXPECT_EQ(infos[0].bundleName, BUNDLE_PREVIEW_NAME);
949 EXPECT_EQ(infos[0].name, EXTENSION_ABILITY_NAME);
950 EXPECT_EQ(infos[0].type, ExtensionAbilityType::PREVIEW);
951 }
952 UnInstallBundle(BUNDLE_PREVIEW_NAME);
953 }
954
955 /**
956 * @tc.name: QueryExtensionAbilityInfos_0800
957 * @tc.desc: 1.install the hap
958 * 2.query extensionAbilityInfos
959 * @tc.type: FUNC
960 * @tc.require: issueI5MZ33
961 */
962 HWTEST_F(BmsBundleInstallerTest, QueryExtensionAbilityInfos_0800, Function | SmallTest | Level0)
963 {
964 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_PREVIEW_TEST;
965 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
966 EXPECT_EQ(installResult, ERR_OK);
967
968 auto dataMgr = GetBundleDataMgr();
969 EXPECT_NE(dataMgr, nullptr);
970 AAFwk::Want want;
971 want.SetElementName("", BUNDLE_PREVIEW_NAME, EXTENSION_ABILITY_NAME, MODULE_NAME);
972 std::vector<ExtensionAbilityInfo> infos;
973 bool result = dataMgr->QueryExtensionAbilityInfos(want, 0, USERID, infos);
974 EXPECT_TRUE(result);
975 EXPECT_EQ(infos.size(), NUMBER_ONE);
976 if (infos.size() > 0) {
977 EXPECT_EQ(infos[0].bundleName, BUNDLE_PREVIEW_NAME);
978 EXPECT_EQ(infos[0].moduleName, MODULE_NAME);
979 EXPECT_EQ(infos[0].name, EXTENSION_ABILITY_NAME);
980 EXPECT_EQ(infos[0].type, ExtensionAbilityType::PREVIEW);
981 }
982 UnInstallBundle(BUNDLE_PREVIEW_NAME);
983 }
984
985 /**
986 * @tc.name: QueryExtensionAbilityInfos_0900
987 * @tc.desc: 1.install the hap
988 * 2.query extensionAbilityInfos
989 * @tc.type: FUNC
990 * @tc.require: issueI5MZ33
991 */
992 HWTEST_F(BmsBundleInstallerTest, QueryExtensionAbilityInfos_0900, Function | SmallTest | Level0)
993 {
994 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_THUMBNAIL_TEST;
995 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
996 EXPECT_EQ(installResult, ERR_OK);
997
998 auto dataMgr = GetBundleDataMgr();
999 EXPECT_NE(dataMgr, nullptr);
1000 AAFwk::Want want;
1001 want.SetAction("action.system.home");
1002 want.AddEntity("entity.system.home");
1003 want.SetElementName("", BUNDLE_THUMBNAIL_NAME, "", MODULE_NAME);
1004 std::vector<ExtensionAbilityInfo> infos;
1005 bool result = dataMgr->QueryExtensionAbilityInfos(want, 0, USERID, infos);
1006 EXPECT_TRUE(result);
1007 EXPECT_EQ(infos.size(), NUMBER_ONE);
1008 if (infos.size() > 0) {
1009 EXPECT_EQ(infos[0].bundleName, BUNDLE_THUMBNAIL_NAME);
1010 EXPECT_EQ(infos[0].moduleName, MODULE_NAME);
1011 EXPECT_EQ(infos[0].type, ExtensionAbilityType::THUMBNAIL);
1012 }
1013 UnInstallBundle(BUNDLE_THUMBNAIL_NAME);
1014 }
1015
1016 /**
1017 * @tc.name: QueryExtensionAbilityInfos_1000
1018 * @tc.desc: 1.install the hap
1019 * 2.query extensionAbilityInfos
1020 * @tc.type: FUNC
1021 * @tc.require: issueI5MZ33
1022 */
1023 HWTEST_F(BmsBundleInstallerTest, QueryExtensionAbilityInfos_1000, Function | SmallTest | Level0)
1024 {
1025 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_THUMBNAIL_TEST;
1026 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
1027 EXPECT_EQ(installResult, ERR_OK);
1028
1029 auto dataMgr = GetBundleDataMgr();
1030 EXPECT_NE(dataMgr, nullptr);
1031 AAFwk::Want want;
1032 want.SetElementName("", BUNDLE_THUMBNAIL_NAME, "", MODULE_NAME);
1033 std::vector<ExtensionAbilityInfo> infos;
1034 bool result = dataMgr->QueryExtensionAbilityInfos(want, 0, USERID, infos);
1035 EXPECT_FALSE(result);
1036 UnInstallBundle(BUNDLE_THUMBNAIL_NAME);
1037 }
1038
1039 /**
1040 * @tc.name: QueryExtensionAbilityInfos_1100
1041 * @tc.desc: 1.install the hap
1042 * 2.query extensionAbilityInfos
1043 * @tc.type: FUNC
1044 * @tc.require: issueI5MZ33
1045 */
1046 HWTEST_F(BmsBundleInstallerTest, QueryExtensionAbilityInfos_1100, Function | SmallTest | Level0)
1047 {
1048 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_THUMBNAIL_TEST;
1049 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
1050 EXPECT_EQ(installResult, ERR_OK);
1051
1052 auto dataMgr = GetBundleDataMgr();
1053 EXPECT_NE(dataMgr, nullptr);
1054 AAFwk::Want want;
1055 want.SetElementName("", BUNDLE_THUMBNAIL_NAME, EXTENSION_ABILITY_NAME, "");
1056 std::vector<ExtensionAbilityInfo> infos;
1057 bool result = dataMgr->QueryExtensionAbilityInfos(want, 0, USERID, infos);
1058 EXPECT_TRUE(result);
1059 EXPECT_EQ(infos.size(), NUMBER_ONE);
1060 if (infos.size() > 0) {
1061 EXPECT_EQ(infos[0].bundleName, BUNDLE_THUMBNAIL_NAME);
1062 EXPECT_EQ(infos[0].name, EXTENSION_ABILITY_NAME);
1063 EXPECT_EQ(infos[0].type, ExtensionAbilityType::THUMBNAIL);
1064 }
1065 UnInstallBundle(BUNDLE_THUMBNAIL_NAME);
1066 }
1067
1068 /**
1069 * @tc.name: QueryExtensionAbilityInfos_1200
1070 * @tc.desc: 1.install the hap
1071 * 2.query extensionAbilityInfos
1072 * @tc.type: FUNC
1073 * @tc.require: issueI5MZ33
1074 */
1075 HWTEST_F(BmsBundleInstallerTest, QueryExtensionAbilityInfos_1200, Function | SmallTest | Level0)
1076 {
1077 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_THUMBNAIL_TEST;
1078 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
1079 EXPECT_EQ(installResult, ERR_OK);
1080
1081 auto dataMgr = GetBundleDataMgr();
1082 EXPECT_NE(dataMgr, nullptr);
1083 AAFwk::Want want;
1084 want.SetElementName("", BUNDLE_THUMBNAIL_NAME, EXTENSION_ABILITY_NAME, MODULE_NAME);
1085 std::vector<ExtensionAbilityInfo> infos;
1086 bool result = dataMgr->QueryExtensionAbilityInfos(want, 0, USERID, infos);
1087 EXPECT_TRUE(result);
1088 EXPECT_EQ(infos.size(), NUMBER_ONE);
1089 if (infos.size() > 0) {
1090 EXPECT_EQ(infos[0].bundleName, BUNDLE_THUMBNAIL_NAME);
1091 EXPECT_EQ(infos[0].moduleName, MODULE_NAME);
1092 EXPECT_EQ(infos[0].name, EXTENSION_ABILITY_NAME);
1093 EXPECT_EQ(infos[0].type, ExtensionAbilityType::THUMBNAIL);
1094 }
1095 UnInstallBundle(BUNDLE_THUMBNAIL_NAME);
1096 }
1097
1098 /**
1099 * @tc.number: GetBundleStats_001
1100 * @tc.name: test the GetBundleStats
1101 * @tc.desc: 1.install the hap
1102 * 2.GetBundleStats
1103 */
1104 HWTEST_F(BmsBundleInstallerTest, GetBundleStats_001, Function | SmallTest | Level0)
1105 {
1106 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
1107 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
1108 EXPECT_EQ(installResult, ERR_OK);
1109
1110 std::vector<int64_t> bundleStats;
1111 auto ret = InstalldClient::GetInstance()->GetBundleStats(BUNDLE_BACKUP_NAME, USERID, bundleStats);
1112 EXPECT_EQ(ret, ERR_OK);
1113 if (!bundleStats.empty()) {
1114 EXPECT_NE(bundleStats[0], 0);
1115 for (size_t index = NUMBER_ONE; index < bundleStats.size(); index++) {
1116 EXPECT_EQ(bundleStats[index], 0);
1117 }
1118 }
1119 UnInstallBundle(BUNDLE_BACKUP_NAME);
1120 }
1121
1122 /**
1123 * @tc.number: CreateInstallTempDir_0100
1124 * @tc.name: test CreateInstallTempDir
1125 * @tc.desc: 1.create install temp dir success
1126 */
1127 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_0100, Function | SmallTest | Level0)
1128 {
1129 BundleUtil bundleUtil;
1130 const int32_t installId = 2022;
1131 std::string res = bundleUtil.CreateInstallTempDir(installId, DirType::STREAM_INSTALL_DIR);
1132 EXPECT_NE(res, "");
1133 }
1134
1135 /**
1136 * @tc.number: CreateInstallTempDir_0200
1137 * @tc.name: test CreateInstallTempDir
1138 * @tc.desc: 1.create install temp dir success
1139 */
1140 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_0200, Function | SmallTest | Level0)
1141 {
1142 BundleUtil bundleUtil;
1143 const int32_t installId = 2023;
1144 std::string res = bundleUtil.CreateInstallTempDir(installId, DirType::QUICK_FIX_DIR);
1145 EXPECT_NE(res, "");
1146
1147 UnInstallBundle(BUNDLE_BACKUP_NAME);
1148 }
1149
1150 /**
1151 * @tc.number: CreateInstallTempDir_0300
1152 * @tc.name: test CreateInstallTempDir
1153 * @tc.desc: 1.create install temp dir failed
1154 */
1155 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_0300, Function | SmallTest | Level0)
1156 {
1157 BundleUtil bundleUtil;
1158 const int32_t installId = 2023;
1159 std::string res = bundleUtil.CreateInstallTempDir(installId, DirType::UNKNOWN);
1160 EXPECT_EQ(res, "");
1161
1162 UnInstallBundle(BUNDLE_BACKUP_NAME);
1163 }
1164
1165 /**
1166 * @tc.number: CreateInstallTempDir_0400
1167 * @tc.name: test CheckFileName, the name max size is 256
1168 * @tc.desc: 1.test CheckFileName of BundleUtil
1169 */
1170 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_0400, Function | SmallTest | Level0)
1171 {
1172 BundleUtil bundleUtil;
1173 std::string maxFileName = std::string(256, 'a');
1174 bool res = bundleUtil.CheckFileName(maxFileName);
1175 EXPECT_EQ(res, true);
1176 maxFileName.append(".txt");
1177 res = bundleUtil.CheckFileName(maxFileName);
1178 EXPECT_EQ(res, false);
1179 }
1180
1181 /**
1182 * @tc.number: CreateInstallTempDir_0500
1183 * @tc.name: test CheckFileSize, size is not right
1184 * @tc.desc: 1.test CheckFileSize of BundleUtil
1185 */
1186 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_0500, Function | SmallTest | Level0)
1187 {
1188 BundleUtil bundleUtil;
1189 bool res = bundleUtil.CheckFileSize(BUNDLE_NAME, 0);
1190 EXPECT_EQ(res, false);
1191 }
1192
1193 /**
1194 * @tc.number: CreateInstallTempDir_0600
1195 * @tc.name: test GetHapFilesFromBundlePath, current path is empty or failed
1196 * @tc.desc: 1.test GetHapFilesFromBundlePath of BundleUtil
1197 */
1198 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_0600, Function | SmallTest | Level0)
1199 {
1200 BundleUtil bundleUtil;
1201 std::string currentPath = "";
1202 std::vector<std::string> fileList = {"test1.hap"};
1203 bool res = bundleUtil.GetHapFilesFromBundlePath(currentPath, fileList);
1204 EXPECT_EQ(res, false);
1205 currentPath = "/data/test/test2.hap";
1206 res = bundleUtil.GetHapFilesFromBundlePath(currentPath, fileList);
1207 EXPECT_EQ(res, false);
1208 }
1209
1210 /**
1211 * @tc.number: CreateInstallTempDir_0700
1212 * @tc.name: test DeviceAndNameToKey, key is id and name
1213 * @tc.desc: 1.test DeviceAndNameToKey of BundleUtil
1214 */
1215 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_0700, Function | SmallTest | Level0)
1216 {
1217 BundleUtil bundleUtil;
1218 std::string key = "";
1219 bundleUtil.DeviceAndNameToKey(
1220 Constants::CURRENT_DEVICE_ID, BUNDLE_NAME, key);
1221 EXPECT_EQ(key, "PHONE-001_com.example.l3jsdemo");
1222 }
1223
1224 /**
1225 * @tc.number: CreateInstallTempDir_0800
1226 * @tc.name: test KeyToDeviceAndName, split with underline
1227 * @tc.desc: 1.test KeyToDeviceAndName of BundleUtil
1228 */
1229 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_0800, Function | SmallTest | Level0)
1230 {
1231 BundleUtil bundleUtil;
1232 std::string underline = "_";
1233 std::string deviceId = Constants::CURRENT_DEVICE_ID;
1234 std::string bundleName = "com.split.underline";
1235 std::string key = deviceId + underline + bundleName;
1236 bool ret = bundleUtil.KeyToDeviceAndName(key, deviceId, bundleName);
1237 EXPECT_EQ(ret, true);
1238 key = deviceId + bundleName;
1239 ret = bundleUtil.KeyToDeviceAndName(key, deviceId, bundleName);
1240 EXPECT_EQ(ret, false);
1241 }
1242
1243 /**
1244 * @tc.number: CreateInstallTempDir_0900
1245 * @tc.name: test CreateFileDescriptorForReadOnly, path is file
1246 * @tc.desc: 1.test CreateFileDescriptorForReadOnly of BundleUtil
1247 */
1248 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_0900, Function | SmallTest | Level0)
1249 {
1250 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
1251 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
1252 EXPECT_EQ(installResult, ERR_OK);
1253
1254 BundleUtil bundleUtil;
1255 long long offset = 0;
1256 auto ret = bundleUtil.CreateFileDescriptorForReadOnly(bundlePath, offset);
1257 EXPECT_NE(ret, ERR_OK);
1258 bundlePath.append(std::string(256, '/'));
1259 ret = bundleUtil.CreateFileDescriptorForReadOnly(bundlePath, offset);
1260 EXPECT_NE(ret, ERR_OK);
1261
1262 UnInstallBundle(BUNDLE_BACKUP_NAME);
1263 }
1264
1265 /**
1266 * @tc.number: CreateInstallTempDir_1000
1267 * @tc.name: test RenameFile, oldPath or newPath is empty
1268 * @tc.desc: 1.test RenameFile of BundleUtil
1269 */
1270 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_1000, Function | SmallTest | Level0)
1271 {
1272 BundleUtil bundleUtil;
1273 bool ret = bundleUtil.RenameFile("", "");
1274 EXPECT_EQ(ret, false);
1275 ret = bundleUtil.RenameFile("oldPath", "");
1276 EXPECT_EQ(ret, false);
1277 ret = bundleUtil.RenameFile("", "newPath");
1278 EXPECT_EQ(ret, false);
1279 ret = bundleUtil.RenameFile("", "newPath");
1280 EXPECT_EQ(ret, false);
1281 ret = bundleUtil.RenameFile("oldPath", "newPath");
1282 EXPECT_EQ(ret, false);
1283 }
1284
1285 /**
1286 * @tc.number: CreateInstallTempDir_1100
1287 * @tc.name: test CopyFile, source or destination file is empty
1288 * @tc.desc: 1.test CopyFile of BundleUtil
1289 */
1290 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_1100, Function | SmallTest | Level0)
1291 {
1292 BundleUtil bundleUtil;
1293 bool ret = bundleUtil.CopyFile("", "");
1294 EXPECT_EQ(ret, false);
1295 ret = bundleUtil.CopyFile("source", "");
1296 EXPECT_EQ(ret, false);
1297 ret = bundleUtil.CopyFile("", "destinationFile");
1298 EXPECT_EQ(ret, false);
1299 ret = bundleUtil.CopyFile("source", "destinationFile");
1300 EXPECT_EQ(ret, false);
1301 }
1302
1303 /**
1304 * @tc.number: CreateInstallTempDir_1200
1305 * @tc.name: test CreateDir, param is empty return false
1306 * @tc.desc: 1.test CreateDir of BundleUtil
1307 */
1308 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_1200, Function | SmallTest | Level0)
1309 {
1310 BundleUtil bundleUtil;
1311 bool ret = bundleUtil.CreateDir("");
1312 EXPECT_EQ(ret, false);
1313 ret = bundleUtil.CreateDir(BUNDLE_CODE_DIR);
1314 EXPECT_EQ(ret, true);
1315 }
1316
1317 /**
1318 * @tc.number: CreateInstallTempDir_1300
1319 * @tc.name: test RevertToRealPath, one param is empty return false
1320 * @tc.desc: 1.test RevertToRealPath of BundleUtil
1321 */
1322 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_1300, Function | SmallTest | Level0)
1323 {
1324 BundleUtil util;
1325 std::string empty = "";
1326 bool ret = util.RevertToRealPath(empty, empty, empty);
1327 EXPECT_EQ(ret, false);
1328 ret = util.RevertToRealPath("/data/storage/el2/base", empty, empty);
1329 EXPECT_EQ(ret, false);
1330 ret = util.RevertToRealPath("/data/storage/el2/base", "com.ohos.test", empty);
1331 EXPECT_EQ(ret, true);
1332 }
1333
1334 /**
1335 * @tc.number: CreateInstallTempDir_1400
1336 * @tc.name: test StartWith, one of param is empty return false
1337 * @tc.desc: 1.test StartWith of BundleUtil
1338 */
1339 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_1400, Function | SmallTest | Level0)
1340 {
1341 BundleUtil util;
1342 bool ret = util.StartWith("", BUNDLE_DATA_DIR);
1343 EXPECT_EQ(ret, false);
1344 ret = util.StartWith(BUNDLE_DATA_DIR, "");
1345 EXPECT_EQ(ret, false);
1346 ret = util.StartWith(BUNDLE_DATA_DIR, BUNDLE_DATA_DIR);
1347 EXPECT_EQ(ret, true);
1348 }
1349
1350 /**
1351 * @tc.number: CreateInstallTempDir_1500
1352 * @tc.name: test EndWith, one of param is empty return false
1353 * @tc.desc: 1.test EndWith of BundleUtil
1354 */
1355 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_1500, Function | SmallTest | Level0)
1356 {
1357 BundleUtil util;
1358 bool ret = util.EndWith("", BUNDLE_DATA_DIR);
1359 EXPECT_EQ(ret, false);
1360 ret = util.EndWith(BUNDLE_DATA_DIR, "");
1361 EXPECT_EQ(ret, false);
1362 ret = util.EndWith(BUNDLE_DATA_DIR, BUNDLE_CODE_DIR);
1363 EXPECT_EQ(ret, false);
1364 ret = util.EndWith(BUNDLE_DATA_DIR, BUNDLE_DATA_DIR);
1365 EXPECT_EQ(ret, true);
1366 }
1367
1368 /**
1369 * @tc.number: CreateInstallTempDir_1600
1370 * @tc.name: test file size
1371 * @tc.desc: 1.test GetFileSize of BundleUtil
1372 */
1373 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_1600, Function | SmallTest | Level0)
1374 {
1375 BundleUtil util;
1376 int64_t ret = util.GetFileSize("");
1377 EXPECT_EQ(ret, 0);
1378 std::string bundleFile = RESOURCE_ROOT_PATH + RIGHT_BUNDLE;
1379
1380 bool installResult = InstallSystemBundle(bundleFile);
1381 EXPECT_TRUE(installResult);
1382 ret = util.GetFileSize(bundleFile);
1383 EXPECT_NE(ret, 0);
1384 CheckFileExist();
1385 ClearBundleInfo();
1386 }
1387
1388 /**
1389 * @tc.number: GetBaseSharedBundleInfosTest
1390 * @tc.name: Test use different param with GetBaseSharedBundleInfos
1391 * @tc.desc: 1.Test the GetBaseSharedBundleInfos with BundleDataMgr
1392 */
1393 HWTEST_F(BmsBundleInstallerTest, GetBaseSharedBundleInfosTest, Function | SmallTest | Level0)
1394 {
1395 auto dataMgr = GetBundleDataMgr();
1396 std::vector<BaseSharedBundleInfo> infos;
1397 auto ret = dataMgr->GetBaseSharedBundleInfos("", infos);
1398 EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST);
1399 }
1400
1401 /**
1402 * @tc.number: GetBaseSharedBundleInfoTest
1403 * @tc.name: Test use different param with GetBaseSharedBundleInfos
1404 * @tc.desc: 1.Test the GetBaseSharedBundleInfo with BundleDataMgr
1405 */
1406 HWTEST_F(BmsBundleInstallerTest, GetBaseSharedBundleInfoTest, Function | SmallTest | Level0)
1407 {
1408 auto dataMgr = GetBundleDataMgr();
1409 Dependency dependency;
1410 BaseSharedBundleInfo info;
1411 auto ret = dataMgr->GetBaseSharedBundleInfo(dependency, info);
1412 EXPECT_EQ(ret, false);
1413 dependency.bundleName = BUNDLE_NAME;
1414 InnerBundleInfo innerBundleInfo;
1415 dataMgr->bundleInfos_[BUNDLE_NAME] = innerBundleInfo;
1416 ret = dataMgr->GetBaseSharedBundleInfo(dependency, info);
1417 EXPECT_EQ(ret, false);
1418 dataMgr->bundleInfos_.clear();
1419 innerBundleInfo.baseApplicationInfo_->bundleType = BundleType::SHARED;
1420 dataMgr->bundleInfos_[BUNDLE_NAME] = innerBundleInfo;
1421 ret = dataMgr->GetBaseSharedBundleInfo(dependency, info);
1422 EXPECT_EQ(ret, true);
1423 dataMgr->bundleInfos_.clear();
1424 }
1425
1426 /**
1427 * @tc.number: OTASystemInstall_0100
1428 * @tc.name: test the right system bundle file can be installed
1429 * @tc.desc: 1.the system bundle file exists
1430 * 2.the system bundle can be installed successfully and can get the bundle info
1431 */
1432 HWTEST_F(BmsBundleInstallerTest, OTASystemInstall_0100, Function | SmallTest | Level0)
1433 {
1434 std::string bundleFile = RESOURCE_ROOT_PATH + RIGHT_BUNDLE;
1435 bool result = OTAInstallSystemBundle(bundleFile);
1436 EXPECT_TRUE(result) << "the bundle file install failed: " << bundleFile;
1437 CheckFileExist();
1438 ClearBundleInfo();
1439 }
1440
1441 /**
1442 * @tc.number: baseBundleInstaller_0100
1443 * @tc.name: test BuildTempNativeLibraryPath, needSendEvent is true
1444 * @tc.desc: 1.Test the BuildTempNativeLibraryPath of BaseBundleInstaller
1445 */
1446 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_0100, Function | SmallTest | Level0)
1447 {
1448 BaseBundleInstaller installer;
1449 installer.dataMgr_ = GetBundleDataMgr();
1450 InstallParam installParam;
1451 installParam.needSendEvent = true;
1452 ErrCode ret = installer.InstallBundleByBundleName(
1453 BUNDLE_NAME, installParam);
1454 EXPECT_NE(ret, ERR_OK);
1455 }
1456
1457 /**
1458 * @tc.number: baseBundleInstaller_0200
1459 * @tc.name: test Recover, needSendEvent is true
1460 * @tc.desc: 1.Test the Recover of BaseBundleInstaller
1461 */
1462 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_0200, Function | SmallTest | Level0)
1463 {
1464 BaseBundleInstaller installer;
1465 installer.dataMgr_ = GetBundleDataMgr();
1466 installer.bundleName_ = BUNDLE_NAME;
1467 installer.modulePackage_ = "entry";
1468 InstallParam installParam;
1469 installParam.needSendEvent = true;
1470 ErrCode ret = installer.Recover(BUNDLE_NAME, installParam);
1471 EXPECT_NE(ret, ERR_OK);
1472 }
1473
1474 /**
1475 * @tc.number: baseBundleInstaller_0300
1476 * @tc.name: test ProcessBundleInstall
1477 * @tc.desc: 1.Test the ProcessBundleInstall of BaseBundleInstaller
1478 */
1479 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_0300, Function | SmallTest | Level0)
1480 {
1481 BaseBundleInstaller installer;
1482 std::vector<std::string> inBundlePaths;
1483 InstallParam installParam;
1484 auto appType = Constants::AppType::THIRD_PARTY_APP;
1485 int32_t uid = 0;
1486 ErrCode ret = installer.ProcessBundleInstall(
1487 inBundlePaths, installParam, appType, uid);
1488 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_FILE_PATH_INVALID);
1489 installer.dataMgr_ = GetBundleDataMgr();
1490
1491 installParam.userId = Constants::INVALID_USERID;
1492 ret = installer.ProcessBundleInstall(
1493 inBundlePaths, installParam, appType, uid);
1494 EXPECT_NE(ret, ERR_OK);
1495 }
1496
1497 /**
1498 * @tc.number: baseBundleInstaller_0400
1499 * @tc.name: test CheckVersionCompatibilityForHmService
1500 * @tc.desc: 1.Test the CheckVersionCompatibilityForHmService of BaseBundleInstaller
1501 */
1502 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_0400, Function | SmallTest | Level0)
1503 {
1504 BaseBundleInstaller installer;
1505 installer.versionCode_ = 1;
1506 InnerBundleInfo oldInfo;
1507 oldInfo.baseBundleInfo_->versionCode = 2;
1508 auto ret = installer.CheckVersionCompatibilityForHmService(oldInfo);
1509 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_VERSION_DOWNGRADE);
1510
1511 installer.versionCode_ = 3;
1512 ret = installer.CheckVersionCompatibilityForHmService(oldInfo);
1513 EXPECT_EQ(ret, ERR_OK);
1514 }
1515
1516 /**
1517 * @tc.number: baseBundleInstaller_0500
1518 * @tc.name: test CreateBundleUserData, user id is different
1519 * @tc.desc: 1.Test the CreateBundleUserData of BaseBundleInstaller
1520 */
1521 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_0500, Function | SmallTest | Level0)
1522 {
1523 BaseBundleInstaller installer;
1524 InnerBundleInfo innerBundleInfo;
1525 auto ret = installer.CreateBundleUserData(innerBundleInfo);
1526 EXPECT_EQ(ret, ERR_APPEXECFWK_USER_NOT_EXIST);
1527 }
1528
1529 /**
1530 * @tc.number: baseBundleInstaller_0600
1531 * @tc.name: test RemoveBundleUserData, InnerBundleInfo id is different
1532 * @tc.desc: 1.Test the RemoveBundleUserData of BaseBundleInstaller
1533 */
1534 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_0600, Function | SmallTest | Level0)
1535 {
1536 BaseBundleInstaller installer;
1537 InnerBundleInfo innerBundleInfo;
1538 InnerBundleUserInfo userInfo;
1539 bool needRemoveData = false;
1540 auto ret = installer.RemoveBundleUserData(innerBundleInfo, needRemoveData);
1541 EXPECT_EQ(ret, ERR_APPEXECFWK_USER_NOT_EXIST);
1542 innerBundleInfo.innerBundleUserInfos_.emplace("key", userInfo);
1543 installer.userId_ = Constants::ALL_USERID;
1544 ret = installer.RemoveBundleUserData(innerBundleInfo, needRemoveData);
1545 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
1546 }
1547
1548 /**
1549 * @tc.number: baseBundleInstaller_0700
1550 * @tc.name: test VerifyUriPrefix, InnerBundleInfo id is different
1551 * @tc.desc: 1.Test the VerifyUriPrefix of BaseBundleInstaller
1552 */
1553 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_0700, Function | SmallTest | Level0)
1554 {
1555 BaseBundleInstaller installer;
1556 installer.dataMgr_ = GetBundleDataMgr();
1557 InnerBundleInfo innerBundleInfo;
1558 bool isUpdate = false;
1559 bool ret = installer.VerifyUriPrefix(
1560 innerBundleInfo, Constants::ALL_USERID, isUpdate);
1561 EXPECT_EQ(ret, true);
1562
1563 AbilityInfo info;
1564 info.uri = "dataability://";
1565 innerBundleInfo.baseAbilityInfos_.emplace("key", info);
1566 ret = installer.VerifyUriPrefix(
1567 innerBundleInfo, Constants::ALL_USERID, isUpdate);
1568 EXPECT_EQ(ret, false);
1569
1570 info.uri = "dataability://com.ohos.test";
1571 ret = installer.VerifyUriPrefix(
1572 innerBundleInfo, Constants::ALL_USERID, isUpdate);
1573 EXPECT_EQ(ret, false);
1574 }
1575
1576 /**
1577 * @tc.number: baseBundleInstaller_0800
1578 * @tc.name: test ProcessInstallBundleByBundleName
1579 * @tc.desc: 1.Test the ProcessInstallBundleByBundleName of BaseBundleInstaller
1580 */
1581 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_0800, Function | SmallTest | Level0)
1582 {
1583 BaseBundleInstaller installer;
1584 InnerBundleInfo innerBundleInfo;
1585 InstallParam installParam;
1586 int32_t uid = 0;
1587 ErrCode ret = installer.ProcessInstallBundleByBundleName(
1588 BUNDLE_NAME, installParam, uid);
1589 EXPECT_NE(ret, ERR_OK);
1590 }
1591
1592 /**
1593 * @tc.number: baseBundleInstaller_0900
1594 * @tc.name: test ProcessRecover
1595 * @tc.desc: 1.Test the ProcessRecover of BaseBundleInstaller
1596 */
1597 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_0900, Function | SmallTest | Level0)
1598 {
1599 BaseBundleInstaller installer;
1600 InnerBundleInfo innerBundleInfo;
1601 InstallParam installParam;
1602 int32_t uid = 0;
1603 ErrCode ret = installer.ProcessRecover(
1604 BUNDLE_NAME, installParam, uid);
1605 EXPECT_NE(ret, ERR_OK);
1606 }
1607
1608 /**
1609 * @tc.number: baseBundleInstaller_1000
1610 * @tc.name: test InnerProcessInstallByPreInstallInfo
1611 * @tc.desc: 1.Test the InnerProcessInstallByPreInstallInfo of BaseBundleInstaller
1612 */
1613 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_1000, Function | SmallTest | Level0)
1614 {
1615 BaseBundleInstaller installer;
1616 installer.dataMgr_ = GetBundleDataMgr();
1617 InnerBundleInfo innerBundleInfo;
1618 bool recoverMode = true;
1619 int32_t uid = 0;
1620 InstallParam installParam;
1621 installParam.userId = Constants::INVALID_USERID;
1622 ErrCode ret = installer.InnerProcessInstallByPreInstallInfo(
1623 BUNDLE_NAME_TEST1, installParam, uid, recoverMode);
1624 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_PARAM_ERROR);
1625 }
1626
1627 /**
1628 * @tc.number: baseBundleInstaller_1100
1629 * @tc.name: test ProcessDeployedHqfInfo
1630 * @tc.desc: 1.Test the ProcessDeployedHqfInfo of BaseBundleInstaller
1631 */
1632 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_1100, Function | SmallTest | Level0)
1633 {
1634 BaseBundleInstaller installer;
1635 std::string nativeLibraryPath = "X86";
1636 std::string cpuAbi = "armeabi";
1637 InnerBundleInfo newInfo;
1638 AppQuickFix oldAppQuickFix;
1639 ErrCode ret = installer.ProcessDeployedHqfInfo(
1640 nativeLibraryPath, cpuAbi, newInfo, oldAppQuickFix);
1641 EXPECT_EQ(ret, ERR_OK);
1642 }
1643
1644 /**
1645 * @tc.number: baseBundleInstaller_1200
1646 * @tc.name: test ProcessDeployingHqfInfo
1647 * @tc.desc: 1.Test the ProcessDeployingHqfInfo of BaseBundleInstaller
1648 */
1649 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_1200, Function | SmallTest | Level0)
1650 {
1651 BaseBundleInstaller installer;
1652 std::string nativeLibraryPath = "X86";
1653 std::string cpuAbi = "armeabi";
1654 InnerBundleInfo newInfo;
1655 ErrCode ret = installer.ProcessDeployingHqfInfo(
1656 nativeLibraryPath, cpuAbi, newInfo);
1657 EXPECT_EQ(ret, ERR_OK);
1658 }
1659
1660 /**
1661 * @tc.number: baseBundleInstaller_1300
1662 * @tc.name: test UpdateLibAttrs
1663 * @tc.desc: 1.Test the UpdateLibAttrs of BaseBundleInstaller
1664 */
1665 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_1300, Function | SmallTest | Level0)
1666 {
1667 BaseBundleInstaller installer;
1668 std::string nativeLibraryPath = "X86";
1669 std::string cpuAbi = "armeabi";
1670 InnerBundleInfo newInfo;
1671 AppqfInfo appQfInfo;
1672 ErrCode ret = installer.UpdateLibAttrs(
1673 newInfo, cpuAbi, nativeLibraryPath, appQfInfo);
1674 EXPECT_EQ(ret, ERR_OK);
1675 }
1676
1677 /**
1678 * @tc.number: baseBundleInstaller_1400
1679 * @tc.name: test CheckHapLibsWithPatchLibs
1680 * @tc.desc: 1.Test the CheckHapLibsWithPatchLibs of BaseBundleInstaller
1681 */
1682 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_1400, Function | SmallTest | Level0)
1683 {
1684 BaseBundleInstaller installer;
1685 std::string nativeLibraryPath = "";
1686 std::string hqfLibraryPath = "a.hqf";
1687 bool ret = installer.CheckHapLibsWithPatchLibs(
1688 nativeLibraryPath, hqfLibraryPath);
1689 EXPECT_EQ(ret, false);
1690
1691 hqfLibraryPath = "/data/storage/el1/a.hqf";
1692 ret = installer.CheckHapLibsWithPatchLibs(
1693 nativeLibraryPath, hqfLibraryPath);
1694 EXPECT_EQ(ret, false);
1695
1696 nativeLibraryPath = hqfLibraryPath;
1697 ret = installer.CheckHapLibsWithPatchLibs(
1698 nativeLibraryPath, hqfLibraryPath);
1699 EXPECT_EQ(ret, true);
1700
1701 ret = installer.CheckHapLibsWithPatchLibs(
1702 nativeLibraryPath, "");
1703 EXPECT_EQ(ret, true);
1704
1705 ret = installer.CheckHapLibsWithPatchLibs(
1706 nativeLibraryPath, hqfLibraryPath);
1707 EXPECT_EQ(ret, true);
1708 }
1709
1710 /**
1711 * @tc.number: baseBundleInstaller_1500
1712 * @tc.name: test ProcessDiffFiles
1713 * @tc.desc: 1.Test the ProcessDiffFiles of BaseBundleInstaller
1714 */
1715 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_1500, Function | SmallTest | Level0)
1716 {
1717 BaseBundleInstaller installer;
1718 installer.modulePackage_ = "entry";
1719 std::vector<HqfInfo> hqfInfos;
1720 HqfInfo info;
1721 info.moduleName = "entry";
1722 hqfInfos.emplace_back(info);
1723 AppqfInfo appQfInfo;
1724 appQfInfo.hqfInfos = hqfInfos;
1725 std::string nativeLibraryPath = "libs/armeabi-v7a/";
1726 std::string cpuAbi = "arm";
1727 ErrCode ret = installer.ProcessDiffFiles(
1728 appQfInfo, nativeLibraryPath, cpuAbi);
1729 EXPECT_EQ(ret, ERR_BUNDLEMANAGER_QUICK_FIX_EXTRACT_DIFF_FILES_FAILED);
1730 }
1731
1732 /**
1733 * @tc.number: baseBundleInstaller_1600
1734 * @tc.name: test SaveOldRemovableInfo
1735 * @tc.desc: 1.Test the SaveOldRemovableInfo of BaseBundleInstaller
1736 */
1737 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_1600, Function | SmallTest | Level0)
1738 {
1739 BaseBundleInstaller installer;
1740 InnerBundleInfo oldInfo;
1741 InnerModuleInfo info;
1742 info.isRemovable.try_emplace("removeInfo1", false);
1743 info.isRemovable.try_emplace("removeInfo2", true);
1744 oldInfo.innerModuleInfos_.try_emplace("entry", info);
1745 InnerModuleInfo newModuleInfo;
1746 bool existModule = true;
1747 installer.SaveOldRemovableInfo(newModuleInfo, oldInfo, existModule);
1748 newModuleInfo.modulePackage = "entry";
1749 installer.SaveOldRemovableInfo(newModuleInfo, oldInfo, existModule);
1750 EXPECT_EQ(newModuleInfo.isRemovable["removeInfo1"], false);
1751 EXPECT_EQ(newModuleInfo.isRemovable["removeInfo2"], true);
1752 }
1753
1754 /**
1755 * @tc.number: baseBundleInstaller_1700
1756 * @tc.name: test ExtractArkNativeFile
1757 * @tc.desc: 1.Test the ExtractArkNativeFile of BaseBundleInstaller
1758 */
1759 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_1700, Function | SmallTest | Level0)
1760 {
1761 BaseBundleInstaller installer;
1762 InnerBundleInfo info;
1763 std::string modulePath;
1764 ErrCode ret = installer.ExtractArkNativeFile(info, modulePath);
1765 EXPECT_EQ(ret, ERR_OK);
1766
1767 info.baseApplicationInfo_->arkNativeFilePath = "";
1768 info.baseApplicationInfo_->arkNativeFileAbi = "errorType";
1769 ret = installer.ExtractArkNativeFile(info, modulePath);
1770 EXPECT_EQ(ret, ERR_APPEXECFWK_PARSE_AN_FAILED);
1771
1772 info.baseApplicationInfo_->arkNativeFileAbi = "x86";
1773 ret = installer.ExtractArkNativeFile(info, modulePath);
1774 EXPECT_NE(ret, ERR_OK);
1775 }
1776
1777 /**
1778 * @tc.number: baseBundleInstaller_1800
1779 * @tc.name: test DeleteOldArkNativeFile
1780 * @tc.desc: 1.Test the DeleteOldArkNativeFile of BaseBundleInstaller
1781 */
1782 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_1800, Function | SmallTest | Level0)
1783 {
1784 BaseBundleInstaller installer;
1785 InnerBundleInfo oldInfo;
1786 oldInfo.baseApplicationInfo_->arkNativeFilePath = "/an/x86/x86.so";
1787 ErrCode ret = installer.DeleteOldArkNativeFile(oldInfo);
1788 EXPECT_EQ(ret, ERR_OK);
1789 }
1790
1791 /**
1792 * @tc.number: baseBundleInstaller_1900
1793 * @tc.name: test CheckArkNativeFileWithOldInfo
1794 * @tc.desc: 1.Test the CheckArkNativeFileWithOldInfo of BaseBundleInstaller
1795 */
1796 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_1900, Function | SmallTest | Level0)
1797 {
1798 BaseBundleInstaller installer;
1799 InnerBundleInfo oldInfo;
1800 std::unordered_map<std::string, InnerBundleInfo> newInfos;
1801 ApplicationInfo applicationInfo;
1802 oldInfo.SetBaseApplicationInfo(applicationInfo);
1803 oldInfo.SetArkNativeFileAbi("x86");
1804 InnerBundleInfo info;
1805 info.SetBaseApplicationInfo(applicationInfo);
1806 info.SetArkNativeFileAbi("");
1807 newInfos.try_emplace("so", info);
1808 ErrCode ret = installer.CheckArkNativeFileWithOldInfo(oldInfo, newInfos);
1809 EXPECT_EQ(ret, ERR_OK);
1810
1811 newInfos.clear();
1812 info.SetArkNativeFileAbi("arm");
1813 newInfos.try_emplace("so", info);
1814 ret = installer.CheckArkNativeFileWithOldInfo(oldInfo, newInfos);
1815 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_AN_INCOMPATIBLE);
1816
1817 newInfos.clear();
1818 info.SetArkNativeFileAbi("x86");
1819 newInfos.try_emplace("so", info);
1820 ret = installer.CheckArkNativeFileWithOldInfo(oldInfo, newInfos);
1821 EXPECT_EQ(ret, ERR_OK);
1822 }
1823
1824 /**
1825 * @tc.number: baseBundleInstaller_2000
1826 * @tc.name: test CheckNativeSoWithOldInfo
1827 * @tc.desc: 1.Test the CheckNativeSoWithOldInfo of BaseBundleInstaller
1828 */
1829 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_2000, Function | SmallTest | Level0)
1830 {
1831 BaseBundleInstaller installer;
1832 InnerBundleInfo oldInfo;
1833 ApplicationInfo applicationInfo;
1834 oldInfo.SetBaseApplicationInfo(applicationInfo);
1835 oldInfo.SetNativeLibraryPath("/an/x86/x86.so");
1836 InnerBundleInfo info;
1837 info.SetBaseApplicationInfo(applicationInfo);
1838 info.SetNativeLibraryPath("/an/arm/arm.so");
1839 std::unordered_map<std::string, InnerBundleInfo> newInfos;
1840 newInfos.try_emplace("so", info);
1841 ErrCode ret = installer.CheckNativeSoWithOldInfo(oldInfo, newInfos);
1842 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_SO_INCOMPATIBLE);
1843
1844 newInfos.clear();
1845 info.SetNativeLibraryPath("/an/x86/x86.so");
1846 oldInfo.SetCpuAbi("arm");
1847 info.SetCpuAbi("x86");
1848 newInfos.try_emplace("so", info);
1849 ret = installer.CheckNativeSoWithOldInfo(oldInfo, newInfos);
1850 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_SO_INCOMPATIBLE);
1851
1852 newInfos.clear();
1853 info.SetNativeLibraryPath("");
1854 oldInfo.SetCpuAbi("x86");
1855 newInfos.try_emplace("so", info);
1856 ret = installer.CheckNativeSoWithOldInfo(oldInfo, newInfos);
1857 EXPECT_EQ(ret, ERR_OK);
1858 }
1859
1860 /**
1861 * @tc.number: baseBundleInstaller_2100
1862 * @tc.name: test baseBundleInstaller
1863 * @tc.desc: 1.Test the dataMgr_ is nullptr
1864 */
1865 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_2100, Function | SmallTest | Level0)
1866 {
1867 BaseBundleInstaller installer;
1868 installer.dataMgr_ = nullptr;
1869 ClearDataMgr();
1870 std::vector<std::string> inBundlePaths;
1871 InstallParam installParam;
1872 auto appType = Constants::AppType::THIRD_PARTY_APP;
1873 int32_t uid = 0;
1874 bool recoverMode = true;
1875 ErrCode ret = installer.ProcessBundleInstall(
1876 inBundlePaths, installParam, appType, uid);
1877 EXPECT_EQ(ret, ERR_APPEXECFWK_UNINSTALL_BUNDLE_MGR_SERVICE_ERROR);
1878 ret = installer.ProcessBundleUninstall(
1879 "bundleName", installParam, uid);
1880 EXPECT_EQ(ret, ERR_APPEXECFWK_UNINSTALL_BUNDLE_MGR_SERVICE_ERROR);
1881 ret = installer.ProcessBundleUninstall(
1882 "bundleName", "modulePackage", installParam, uid);
1883 EXPECT_EQ(ret, ERR_APPEXECFWK_UNINSTALL_BUNDLE_MGR_SERVICE_ERROR);
1884 ret = installer.InnerProcessInstallByPreInstallInfo(
1885 "bundleName", installParam, uid, recoverMode);
1886 EXPECT_EQ(ret, ERR_APPEXECFWK_UNINSTALL_BUNDLE_MGR_SERVICE_ERROR);
1887 InnerBundleInfo info;
1888 bool res = installer.GetInnerBundleInfo(info, recoverMode);
1889 EXPECT_EQ(res, false);
1890 ResetDataMgr();
1891
1892 installParam.userId = Constants::INVALID_USERID;
1893 ret = installer.ProcessBundleUninstall(
1894 "bundleName", installParam, uid);
1895 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_PARAM_ERROR);
1896 ret = installer.ProcessBundleUninstall(
1897 "bundleName", "modulePackage", installParam, uid);
1898 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_PARAM_ERROR);
1899 }
1900
1901 /**
1902 * @tc.number: baseBundleInstaller_2200
1903 * @tc.name: test RemoveBundle
1904 * @tc.desc: 1.Test the RemoveBundle
1905 */
1906 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_2200, Function | SmallTest | Level0)
1907 {
1908 BaseBundleInstaller installer;
1909 InnerBundleInfo info;
1910 ErrCode res = installer.RemoveBundle(info, false);
1911 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
1912
1913 res = installer.RemoveBundle(info, true);
1914 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
1915 }
1916
1917 /**
1918 * @tc.number: baseBundleInstaller_2300
1919 * @tc.name: test ProcessBundleUpdateStatus
1920 * @tc.desc: 1.Test the ProcessBundleUpdateStatus
1921 */
1922 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_2300, Function | SmallTest | Level0)
1923 {
1924 BaseBundleInstaller installer;
1925 InnerBundleInfo oldInfo;
1926 InnerBundleInfo newInfo;
1927 installer.isFeatureNeedUninstall_ = true;
1928 ErrCode res = installer.ProcessBundleUpdateStatus(oldInfo, newInfo, false, false);
1929 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_PARAM_ERROR);
1930 }
1931
1932 /**
1933 * @tc.number: baseBundleInstaller_2400
1934 * @tc.name: test ProcessBundleUpdateStatus
1935 * @tc.desc: 1.Test the ProcessBundleUpdateStatus
1936 */
1937 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_2400, Function | SmallTest | Level0)
1938 {
1939 BaseBundleInstaller installer;
1940 installer.userId_ = USERID;
1941 InnerBundleInfo info;
1942 ErrCode res = installer.CreateBundleDataDir(info);
1943 EXPECT_EQ(res, ERR_APPEXECFWK_USER_NOT_EXIST);
1944
1945 installer.userId_ = Constants::INVALID_USERID;
1946 ApplicationInfo applicationInfo;
1947 applicationInfo.bundleName = BUNDLE_NAME;
1948 info.SetBaseApplicationInfo(applicationInfo);
1949 res = installer.CreateBundleDataDir(info);
1950 EXPECT_EQ(res, ERR_APPEXECFWK_USER_NOT_EXIST);
1951 }
1952
1953 /**
1954 * @tc.number: baseBundleInstaller_2500
1955 * @tc.name: test UpdateDefineAndRequestPermissions
1956 * @tc.desc: 1.Test the UpdateDefineAndRequestPermissions of BaseBundleInstaller
1957 */
1958 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_2500, Function | SmallTest | Level0)
1959 {
1960 BaseBundleInstaller installer;
1961 InnerBundleInfo oldInfo;
1962 InnerBundleInfo newInfo;
1963 InnerBundleUserInfo userInfo;
1964 userInfo.accessTokenId = 0;
1965 newInfo.innerBundleUserInfos_.insert(pair<std::string, InnerBundleUserInfo>("1", userInfo));
1966
1967 auto res = installer.UpdateDefineAndRequestPermissions(oldInfo, newInfo);
1968 EXPECT_EQ(res, ERR_OK);
1969 }
1970
1971 /**
1972 * @tc.number: baseBundleInstaller_2600
1973 * @tc.name: test ProcessBundleUninstall
1974 * @tc.desc: 1.Test the ProcessBundleUninstall of BaseBundleInstaller
1975 */
1976 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_2600, Function | SmallTest | Level0)
1977 {
1978 BaseBundleInstaller installer;
1979 std::string bundleName = SYSTEMFIEID_NAME;
1980 std::string modulePackage = MODULE_NAME;
1981 InstallParam installParam;
1982 installParam.userId = -1;
1983 int32_t uid = USERID;
1984
1985 auto res = installer.ProcessBundleUninstall(bundleName, installParam, uid);
1986 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_PARAM_ERROR);
1987 res = installer.ProcessBundleUninstall(bundleName, modulePackage, installParam, uid);
1988 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_PARAM_ERROR);
1989 }
1990
1991 /**
1992 * @tc.number: baseBundleInstaller_2700
1993 * @tc.name: test ProcessBundleUpdateStatus
1994 * @tc.desc: 1.Test the ProcessBundleUpdateStatus of BaseBundleInstaller
1995 */
1996 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_2700, Function | SmallTest | Level0)
1997 {
1998 BaseBundleInstaller installer;
1999 InnerBundleInfo oldInfo;
2000 InnerBundleInfo newInfo;
2001 newInfo.currentPackage_ = "";
2002 bool isReplace = false;
2003 bool noSkipsKill = false;
2004
2005 auto res = installer.ProcessBundleUpdateStatus(oldInfo, newInfo, isReplace, noSkipsKill);
2006 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_PARAM_ERROR);
2007 }
2008
2009 /**
2010 * @tc.number: baseBundleInstaller_2800
2011 * @tc.name: test ProcessBundleUpdateStatus
2012 * @tc.desc: 1.Test the ProcessBundleUpdateStatus of BaseBundleInstaller
2013 */
2014 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_2800, Function | SmallTest | Level0)
2015 {
2016 BaseBundleInstaller installer;
2017 InnerBundleInfo oldInfo;
2018 oldInfo.baseApplicationInfo_->singleton = true;
2019 InnerBundleInfo newInfo;
2020 newInfo.currentPackage_ = MODULE_NAME;
2021 bool isReplace = false;
2022 bool noSkipsKill = false;
2023
2024 auto res = installer.ProcessBundleUpdateStatus(oldInfo, newInfo, isReplace, noSkipsKill);
2025 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_STATE_ERROR);
2026 }
2027
2028 /**
2029 * @tc.number: baseBundleInstaller_2900
2030 * @tc.name: test ProcessBundleUpdateStatus
2031 * @tc.desc: 1.Test the ProcessBundleUpdateStatus of BaseBundleInstaller
2032 */
2033 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_2900, Function | SmallTest | Level0)
2034 {
2035 BaseBundleInstaller installer;
2036 InnerBundleInfo oldInfo;
2037 InnerBundleInfo newInfo;
2038 newInfo.currentPackage_ = MODULE_NAME;
2039 newInfo.baseApplicationInfo_->singleton = true;
2040 bool isReplace = false;
2041 bool noSkipsKill = false;
2042
2043 auto res = installer.ProcessBundleUpdateStatus(oldInfo, newInfo, isReplace, noSkipsKill);
2044 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_STATE_ERROR);
2045
2046 installer.modulePackage_ = MODULE_NAME;
2047 InnerModuleInfo moduleInfo;
2048 moduleInfo.isLibIsolated = true;
2049 moduleInfo.cpuAbi = "123";
2050 moduleInfo.nativeLibraryPath = "/data/test";
2051 newInfo.innerModuleInfos_.insert(pair<std::string, InnerModuleInfo>(MODULE_NAME, moduleInfo));
2052 installer.ProcessHqfInfo(oldInfo, newInfo);
2053 }
2054
2055 /**
2056 * @tc.number: baseBundleInstaller_3000
2057 * @tc.name: test ProcessDeployedHqfInfo
2058 * @tc.desc: 1.Test the ProcessDeployedHqfInfo of BaseBundleInstaller
2059 */
2060 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_3000, Function | SmallTest | Level0)
2061 {
2062 BaseBundleInstaller installer;
2063 installer.isFeatureNeedUninstall_ = false;
2064 std::string nativeLibraryPath = "/data/test";
2065 std::string cpuAbi = "123";
2066 InnerBundleInfo newInfo;
2067 AppQuickFix oldAppQuickFix;
2068 HqfInfo hqfInfo;
2069 oldAppQuickFix.deployedAppqfInfo.hqfInfos.push_back(hqfInfo);
2070
2071 auto res = installer.ProcessDeployedHqfInfo(nativeLibraryPath, cpuAbi, newInfo, oldAppQuickFix);
2072 EXPECT_EQ(res, ERR_BUNDLEMANAGER_QUICK_FIX_EXTRACT_DIFF_FILES_FAILED);
2073
2074 hqfInfo.moduleName = MODULE_NAME;
2075 installer.modulePackage_ = "123";
2076 res = installer.ProcessDeployedHqfInfo(nativeLibraryPath, cpuAbi, newInfo, oldAppQuickFix);
2077 EXPECT_EQ(res, ERR_OK);
2078 }
2079
2080 /**
2081 * @tc.number: baseBundleInstaller_3100
2082 * @tc.name: test UpdateLibAttrs
2083 * @tc.desc: 1.Test the UpdateLibAttrs of BaseBundleInstaller
2084 */
2085 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_3100, Function | SmallTest | Level0)
2086 {
2087 BaseBundleInstaller installer;
2088 InnerBundleInfo newInfo;
2089 newInfo.currentPackage_ = MODULE_NAME;
2090 InnerModuleInfo moduleInfo;
2091 moduleInfo.moduleName = MODULE_NAME;
2092 newInfo.innerModuleInfos_.insert(pair<std::string, InnerModuleInfo>(MODULE_NAME, moduleInfo));
2093 std::string cpuAbi = "123";
2094 std::string nativeLibraryPath = "/data/test";
2095 AppqfInfo appQfInfo;
2096
2097 auto res = installer.UpdateLibAttrs(newInfo, cpuAbi, nativeLibraryPath, appQfInfo);
2098 EXPECT_EQ(res, ERR_OK);
2099 }
2100
2101 /**
2102 * @tc.number: baseBundleInstaller_3200
2103 * @tc.name: test InstallAppControl
2104 * @tc.desc: 1.Test the InstallAppControl of BaseBundleInstaller
2105 */
2106 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_3200, Function | SmallTest | Level0)
2107 {
2108 BaseBundleInstaller installer;
2109 std::string installAppId;
2110 int32_t userId = Constants::DEFAULT_USERID;;
2111 OHOS::ErrCode ret = installer.InstallNormalAppControl(installAppId, userId);
2112 EXPECT_EQ(ret, OHOS::ERR_OK);
2113 }
2114
2115 /**
2116 * @tc.number: BundleInstaller_3300
2117 * @tc.name: test InstallAppControl
2118 * @tc.desc: 1.Test the InstallAppControl of BaseBundleInstaller
2119 */
2120 HWTEST_F(BmsBundleInstallerTest, BundleInstaller_3300, Function | SmallTest | Level0)
2121 {
2122 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_MODULEJSON_TEST;
2123 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
2124 EXPECT_EQ(installResult, ERR_OK);
2125
2126 UnInstallBundle(BUNDLE_MODULEJSON_NAME);
2127 }
2128
2129 /**
2130 * @tc.number: baseBundleInstaller_3500
2131 * @tc.name: test ProcessBundleInstallStatus
2132 * @tc.desc: 1.Test the ProcessBundleInstallStatus
2133 */
2134 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_3500, Function | SmallTest | Level0)
2135 {
2136 BaseBundleInstaller installer;
2137 InnerBundleInfo innerBundleInfo;
2138 AbilityInfo info;
2139 int32_t uid = 0;
2140 info.uri = "dataability://";
2141 innerBundleInfo.userId_ = Constants::ALL_USERID;
2142 innerBundleInfo.baseAbilityInfos_.emplace("key", info);
2143 ErrCode res = installer.ProcessBundleInstallStatus(innerBundleInfo, uid);
2144 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_URI_DUPLICATE);
2145 }
2146
2147 /**
2148 * @tc.number: baseBundleInstaller_3600
2149 * @tc.name: test ProcessNewModuleInstall
2150 * @tc.desc: 1.Test the ProcessNewModuleInstall
2151 */
2152 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_3600, Function | SmallTest | Level0)
2153 {
2154 BaseBundleInstaller installer;
2155 InnerBundleInfo oldInfo;
2156 InnerBundleInfo newInfo;
2157 InnerModuleInfo innerModuleInfo;
2158 innerModuleInfo.isEntry = true;
2159 newInfo.InsertInnerModuleInfo("", innerModuleInfo);
2160 oldInfo.InsertInnerModuleInfo("", innerModuleInfo);
2161 ErrCode res = installer.ProcessNewModuleInstall(newInfo, oldInfo);
2162 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_ENTRY_ALREADY_EXIST);
2163 }
2164
2165 /**
2166 * @tc.number: baseBundleInstaller_3700
2167 * @tc.name: test ProcessModuleUpdate
2168 * @tc.desc: 1.Test the ProcessModuleUpdate
2169 */
2170 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_3700, Function | SmallTest | Level0)
2171 {
2172 BaseBundleInstaller installer;
2173 InnerBundleInfo oldInfo;
2174 InnerBundleInfo newInfo;
2175 InnerModuleInfo innerModuleInfo;
2176 innerModuleInfo.isEntry = true;
2177 newInfo.InsertInnerModuleInfo("", innerModuleInfo);
2178 oldInfo.InsertInnerModuleInfo("", innerModuleInfo);
2179 installer.modulePackage_ = NOEXIST;
2180 ErrCode res = installer.ProcessModuleUpdate(newInfo, oldInfo, false, false);
2181 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_ENTRY_ALREADY_EXIST);
2182 }
2183
2184 /**
2185 * @tc.number: baseBundleInstaller_3800
2186 * @tc.name: test UpdateLibAttrs
2187 * @tc.desc: 1.Test the UpdateLibAttrs of BaseBundleInstaller
2188 */
2189 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_3800, Function | SmallTest | Level0)
2190 {
2191 BaseBundleInstaller installer;
2192 std::string nativeLibraryPath = "X86";
2193 std::string cpuAbi = "armeabi";
2194 InnerBundleInfo newInfo;
2195 newInfo.currentPackage_ = MODULE_NAME_TEST;
2196 AppqfInfo appQfInfo;
2197 ErrCode ret = installer.UpdateLibAttrs(
2198 newInfo, cpuAbi, nativeLibraryPath, appQfInfo);
2199 EXPECT_EQ(ret, ERR_OK);
2200 }
2201
2202 /**
2203 * @tc.number: baseBundleInstaller_3900
2204 * @tc.name: test UpdateLibAttrs
2205 * @tc.desc: 1.Test the UpdateLibAttrs of BaseBundleInstaller
2206 */
2207 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_3900, Function | SmallTest | Level0)
2208 {
2209 BaseBundleInstaller installer;
2210 InnerBundleInfo newInfo;
2211 newInfo.currentPackage_ = MODULE_NAME_TEST;
2212 ErrCode ret = installer.SetDirApl(newInfo);
2213 EXPECT_EQ(ret, ERR_OK);
2214 }
2215
2216 /**
2217 * @tc.number: baseBundleInstaller_4000
2218 * @tc.name: test CreateBundleDataDir
2219 * @tc.desc: 1.Test the CreateBundleDataDir
2220 */
2221 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_4000, Function | SmallTest | Level0)
2222 {
2223 BaseBundleInstaller installer;
2224 installer.userId_ = USERID;
2225 InnerBundleInfo info;
2226 ErrCode res = installer.CreateBundleDataDir(info);
2227 EXPECT_EQ(res, ERR_APPEXECFWK_USER_NOT_EXIST);
2228 }
2229
2230 /**
2231 * @tc.number: baseBundleInstaller_4100
2232 * @tc.name: test ExtractArkNativeFile
2233 * @tc.desc: 1.Test the ExtractArkNativeFile of BaseBundleInstaller
2234 */
2235 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_4100, Function | SmallTest | Level0)
2236 {
2237 BaseBundleInstaller installer;
2238 InnerBundleInfo info;
2239 std::string modulePath;
2240 info.SetArkNativeFilePath("///");
2241 ErrCode ret = installer.ExtractArkNativeFile(info, modulePath);
2242 EXPECT_EQ(ret, ERR_OK);
2243 }
2244
2245 /**
2246 * @tc.number: baseBundleInstaller_4200
2247 * @tc.name: test GetModuleNames
2248 * @tc.desc: 1.Test the GetModuleNames of BaseBundleInstaller
2249 */
2250 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_4200, Function | SmallTest | Level0)
2251 {
2252 BaseBundleInstaller installer;
2253 std::unordered_map<std::string, InnerBundleInfo> infos;
2254 std::string ret = installer.GetModuleNames(infos);
2255 EXPECT_EQ(ret, Constants::EMPTY_STRING);
2256 }
2257
2258 /**
2259 * @tc.number: baseBundleInstaller_4300
2260 * @tc.name: test RemoveModuleDataDir
2261 * @tc.desc: 1.Test the RemoveModuleDataDir of BaseBundleInstaller
2262 */
2263 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_4300, Function | SmallTest | Level0)
2264 {
2265 BaseBundleInstaller installer;
2266 InnerBundleInfo info;
2267 std::string modulePackage = "";
2268 ErrCode res = installer.RemoveModuleAndDataDir(info, modulePackage, USERID, false);
2269 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2270
2271 res = installer.RemoveModuleDataDir(info, modulePackage, USERID);
2272 EXPECT_EQ(res, ERR_NO_INIT);
2273
2274 std::map<std::string, InnerModuleInfo> innerModuleInfos;
2275 InnerModuleInfo moduleInfo;
2276 moduleInfo.moduleName = TEST_PACK_AGE;
2277 moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY;
2278 innerModuleInfos[TEST_PACK_AGE] = moduleInfo;
2279 info.innerModuleInfos_ = innerModuleInfos;
2280 info.AddInnerModuleInfo(innerModuleInfos);
2281
2282 res = installer.RemoveModuleDataDir(info, TEST_PACK_AGE, INVAILD_CODE);
2283 EXPECT_NE(res, ERR_NO_INIT);
2284 }
2285
2286 /**
2287 * @tc.number: InstalldHostImpl_0100
2288 * @tc.name: test CheckArkNativeFileWithOldInfo
2289 * @tc.desc: 1.Test the CreateBundleDir of InstalldHostImpl
2290 */
2291 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_0100, Function | SmallTest | Level0)
2292 {
2293 InstalldHostImpl impl;
2294 auto ret = impl.CreateBundleDir("");
2295 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2296 }
2297
2298 /**
2299 * @tc.number: InstalldHostImpl_0200
2300 * @tc.name: test CheckArkNativeFileWithOldInfo
2301 * @tc.desc: 1.Test the ExtractModuleFiles of InstalldHostImpl
2302 */
2303 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_0200, Function | SmallTest | Level0)
2304 {
2305 InstalldHostImpl impl;
2306 auto ret = impl.ExtractModuleFiles("", "", TEST_STRING, TEST_STRING);
2307 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2308
2309 ret = impl.ExtractModuleFiles("", TEST_STRING, TEST_STRING, TEST_STRING);
2310 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2311
2312 ret = impl.ExtractModuleFiles(TEST_STRING, "", TEST_STRING, TEST_STRING);
2313 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2314
2315 ret = impl.ExtractModuleFiles("wrong", TEST_STRING, "wrong", "wrong");
2316 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_DISK_MEM_INSUFFICIENT);
2317 }
2318
2319 /**
2320 * @tc.number: InstalldHostImpl_0300
2321 * @tc.name: test CheckArkNativeFileWithOldInfo
2322 * @tc.desc: 1.Test the RenameModuleDir of InstalldHostImpl
2323 */
2324 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_0300, Function | SmallTest | Level0)
2325 {
2326 InstalldHostImpl impl;
2327 auto ret = impl.RenameModuleDir("", "");
2328 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2329
2330 ret = impl.RenameModuleDir("", TEST_STRING);
2331 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2332
2333 ret = impl.RenameModuleDir(TEST_STRING, " ");
2334 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_RNAME_DIR_FAILED);
2335
2336 ret = impl.RenameModuleDir("wrong", "wrong");
2337 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_RNAME_DIR_FAILED);
2338
2339 ret = impl.RenameModuleDir(TEST_STRING, TEST_STRING);
2340 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_RNAME_DIR_FAILED);
2341 }
2342
2343 /**
2344 * @tc.number: InstalldHostImpl_0400
2345 * @tc.name: test CheckArkNativeFileWithOldInfo
2346 * @tc.desc: 1.Test the CreateBundleDataDir of InstalldHostImpl
2347 */
2348 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_0400, Function | SmallTest | Level0)
2349 {
2350 InstalldHostImpl impl;
2351 CreateDirParam createDirParam;
2352 createDirParam.bundleName = "";
2353 createDirParam.userId = INVAILD_CODE;
2354 createDirParam.uid = INVAILD_CODE;
2355 createDirParam.gid = INVAILD_CODE;
2356 createDirParam.apl = TEST_STRING;
2357 createDirParam.isPreInstallApp = false;
2358 auto ret = impl.CreateBundleDataDir(createDirParam);
2359 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2360 CreateDirParam createDirParam2;
2361 createDirParam2.bundleName = TEST_STRING;
2362 createDirParam2.userId = 99;
2363 createDirParam2.uid = ZERO_CODE;
2364 createDirParam2.gid = ZERO_CODE;
2365 createDirParam2.apl = TEST_STRING;
2366 createDirParam2.isPreInstallApp = false;
2367 ret = impl.CreateBundleDataDir(createDirParam2);
2368 EXPECT_EQ(ret, ERR_OK);
2369 }
2370
2371 /**
2372 * @tc.number: InstalldHostImpl_0500
2373 * @tc.name: test CheckArkNativeFileWithOldInfo
2374 * @tc.desc: 1.Test the RemoveBundleDataDir of InstalldHostImpl
2375 */
2376 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_0500, Function | SmallTest | Level0)
2377 {
2378 InstalldHostImpl impl;
2379
2380 auto ret = impl.RemoveBundleDataDir("", USERID);
2381 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2382
2383 ret = impl.RemoveBundleDataDir(TEST_STRING, INVAILD_CODE);
2384 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2385
2386 ret = impl.RemoveBundleDataDir("", INVAILD_CODE);
2387 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2388
2389 ret = impl.RemoveBundleDataDir(TEST_STRING, USERID);
2390 EXPECT_EQ(ret, ERR_OK);
2391 }
2392
2393 /**
2394 * @tc.number: InstalldHostImpl_0600
2395 * @tc.name: test CheckArkNativeFileWithOldInfo
2396 * @tc.desc: 1.Test the RemoveModuleDataDir of InstalldHostImpl
2397 */
2398 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_0600, Function | SmallTest | Level0)
2399 {
2400 InstalldHostImpl impl;
2401 auto ret = impl.RemoveModuleDataDir(TEST_STRING, INVAILD_CODE);
2402 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2403
2404 ret = impl.RemoveModuleDataDir("", USERID);
2405 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2406
2407 ret = impl.RemoveModuleDataDir("", INVAILD_CODE);
2408 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2409
2410 ret = impl.RemoveModuleDataDir(TEST_STRING, USERID);
2411 EXPECT_EQ(ret, ERR_OK);
2412 }
2413
2414 /**
2415 * @tc.number: InstalldHostImpl_0700
2416 * @tc.name: test CheckArkNativeFileWithOldInfo
2417 * @tc.desc: 1.Test the GetBundleCachePath of InstalldHostImpl
2418 */
2419 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_0700, Function | SmallTest | Level0)
2420 {
2421 InstalldHostImpl impl;
2422 std::vector<std::string> vec;
2423 auto ret = impl.GetBundleCachePath(TEST_STRING, vec);
2424 EXPECT_EQ(ret, ERR_OK);
2425
2426 ret = impl.GetBundleCachePath("", vec);
2427 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2428 }
2429
2430 /**
2431 * @tc.number: InstalldHostImpl_0800
2432 * @tc.name: test CheckArkNativeFileWithOldInfo
2433 * @tc.desc: 1.Test the Mkdir of InstalldHostImpl
2434 */
2435 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_0800, Function | SmallTest | Level0)
2436 {
2437 InstalldHostImpl impl;
2438 auto ret = impl.Mkdir("", ZERO_CODE, ZERO_CODE, ZERO_CODE);
2439 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2440 }
2441
2442 /**
2443 * @tc.number: InstalldHostImpl_0900
2444 * @tc.name: test CheckArkNativeFileWithOldInfo
2445 * @tc.desc: 1.Test the ExtractFiles of InstalldHostImpl
2446 */
2447 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_0900, Function | SmallTest | Level0)
2448 {
2449 InstalldHostImpl impl;
2450
2451 ExtractParam extractParam;
2452 auto ret = impl.ExtractFiles(extractParam);
2453 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2454
2455 extractParam.srcPath = "/data/app/el1/bundle/public/com.example.test/entry.hap";
2456 extractParam.targetPath = "/data/app/el1/bundle/public/com.example.test/";
2457 extractParam.cpuAbi = "arm64";
2458 extractParam.extractFileType = ExtractFileType::AN;
2459
2460 ret = impl.ExtractFiles(extractParam);
2461 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_DISK_MEM_INSUFFICIENT);
2462 }
2463
2464 /**
2465 * @tc.number: InstalldHostImpl_1000
2466 * @tc.name: test Install
2467 * @tc.desc: 1.Test the Install of BundleInstallerHost
2468 */
2469 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_1000, Function | SmallTest | Level0)
2470 {
2471 auto installer = DelayedSingleton<BundleMgrService>::GetInstance()->GetBundleInstaller();
2472 InstallParam installParam;
2473 bool ret = installer->Install("", installParam, nullptr);
2474 EXPECT_EQ(ret, false);
2475 std::vector<std::string> bundleFilePaths;
2476 ret = installer->Install(bundleFilePaths, installParam, nullptr);
2477 EXPECT_EQ(ret, false);
2478 }
2479
2480 /**
2481 * @tc.number: InstalldHostImpl_1100
2482 * @tc.name: test Install
2483 * @tc.desc: 1.Test the Uninstall of BundleInstallerHost
2484 */
2485 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_1100, Function | SmallTest | Level0)
2486 {
2487 auto installer = DelayedSingleton<BundleMgrService>::GetInstance()->GetBundleInstaller();
2488 InstallParam installParam;
2489 bool ret = installer->Uninstall("", "", installParam, nullptr);
2490 EXPECT_EQ(ret, false);
2491 ret = installer->InstallByBundleName("", installParam, nullptr);
2492 EXPECT_EQ(ret, false);
2493 }
2494
2495 /**
2496 * @tc.number: InstalldHostImpl_1200
2497 * @tc.name: test Install
2498 * @tc.desc: 1.Test the CheckBundleInstallerManager of BundleInstallerHost
2499 */
2500 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_1200, Function | SmallTest | Level0)
2501 {
2502 BundleInstallerHost bundleInstallerHost;
2503 sptr<IStatusReceiver> statusReceiver;
2504 bundleInstallerHost.manager_ = nullptr;
2505 bool ret = bundleInstallerHost.CheckBundleInstallerManager(statusReceiver);
2506 EXPECT_EQ(ret, false);
2507 }
2508
2509 /**
2510 * @tc.number: InstalldHostImpl_1300
2511 * @tc.name: test Install
2512 * @tc.desc: 1.Test the RemoveDir of InstalldHostImpl
2513 */
2514 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_1300, Function | SmallTest | Level0)
2515 {
2516 InstalldHostImpl impl;
2517 ErrCode ret = impl.RemoveDir("");
2518 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2519 }
2520
2521 /**
2522 * @tc.number: InstalldHostImpl_1400
2523 * @tc.name: test Install
2524 * @tc.desc: 1.Test the CleanBundleDataDir of InstalldHostImpl
2525 */
2526 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_1400, Function | SmallTest | Level0)
2527 {
2528 InstalldHostImpl impl;
2529 ErrCode ret = impl.CleanBundleDataDir("");
2530 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2531 }
2532
2533 /**
2534 * @tc.number: InstalldHostImpl_1500
2535 * @tc.name: test Install
2536 * @tc.desc: 1.Test the GetBundleStats of InstalldHostImpl
2537 */
2538 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_1500, Function | SmallTest | Level0)
2539 {
2540 InstalldHostImpl impl;
2541 std::vector<int64_t> bundleStats;
2542 ErrCode ret = impl.GetBundleStats("", USERID, bundleStats);
2543 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2544 }
2545
2546 /**
2547 * @tc.number: InstalldHostImpl_1600
2548 * @tc.name: test Install
2549 * @tc.desc: 1.Test the GetBundleStats of InstalldHostImpl
2550 */
2551 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_1600, Function | SmallTest | Level0)
2552 {
2553 InstalldHostImpl impl;
2554 std::vector<std::string> paths;
2555 ErrCode ret = impl.ScanDir(
2556 "", ScanMode::SUB_FILE_ALL, ResultMode::ABSOLUTE_PATH, paths);
2557 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
2558
2559 ret = impl.ScanDir(
2560 BUNDLE_DATA_DIR, ScanMode::SUB_FILE_ALL, ResultMode::ABSOLUTE_PATH, paths);
2561 EXPECT_EQ(ret, ERR_OK);
2562 }
2563
2564 /**
2565 * @tc.number: InstalldHostImpl_1700
2566 * @tc.name: test Install
2567 * @tc.desc: 1.Test the CopyFile of InstalldHostImpl
2568 */
2569 HWTEST_F(BmsBundleInstallerTest, InstalldHostImpl_1700, Function | SmallTest | Level0)
2570 {
2571 InstalldHostImpl impl;
2572 std::vector<std::string> paths;
2573 ErrCode ret = impl.CopyFile("", "");
2574 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_COPY_FILE_FAILED);
2575 }
2576
2577 /**
2578 * @tc.number: ZipFile_0100
2579 * @tc.name: Test ZipFile
2580 * @tc.desc: 1.Test ParseEndDirectory of ZipFile
2581 */
2582 HWTEST_F(BmsBundleInstallerTest, ZipFile_0100, Function | SmallTest | Level1)
2583 {
2584 ZipFile file("/test.zip");
2585 ZipPos start = 0;
2586 size_t length = 0;
2587 file.SetContentLocation(start, length);
2588 bool ret = file.ParseEndDirectory();
2589 EXPECT_EQ(ret, false);
2590
2591 std::string maxFileName = std::string(256, 'a');
2592 maxFileName.append(".zip");
2593 file.pathName_ = maxFileName;
2594 ret = file.Open();
2595 EXPECT_EQ(ret, false);
2596
2597 file.pathName_ = "/test.zip";
2598 file.isOpen_ = true;
2599 ret = file.Open();
2600 EXPECT_EQ(ret, true);
2601
2602 ret = file.IsDirExist("");
2603 EXPECT_EQ(ret, false);
2604
2605 ret = file.IsDirExist("/test.zip");
2606 EXPECT_EQ(ret, false);
2607 }
2608
2609 /**
2610 * @tc.number: ZipFile_0200
2611 * @tc.name: Test ZipFile
2612 * @tc.desc: 1.Test open file, file name is bigger than PATH_MAX
2613 */
2614 HWTEST_F(BmsBundleInstallerTest, ZipFile_0200, Function | SmallTest | Level1)
2615 {
2616 ZipFile file("/test.zip");
2617 ZipPos start = 0;
2618 size_t length = 0;
2619 file.SetContentLocation(start, length);
2620 bool ret = file.ParseEndDirectory();
2621 EXPECT_EQ(ret, false);
2622
2623 std::string maxFileName = std::string(4096, 'a');
2624 maxFileName.append(".zip");
2625 file.pathName_ = maxFileName;
2626 ret = file.Open();
2627 EXPECT_EQ(ret, false);
2628 }
2629
2630 /**
2631 * @tc.number: ZipFile_0300
2632 * @tc.name: Test ZipFile
2633 * @tc.desc: 1.Test CheckCoherencyLocalHeader
2634 */
2635 HWTEST_F(BmsBundleInstallerTest, ZipFile_0300, Function | SmallTest | Level1)
2636 {
2637 ZipFile file("/test.zip");
2638 ZipEntry zipEntry;
2639 zipEntry.localHeaderOffset = -1;
2640 uint16_t extraSize = 0;
2641 bool ret = file.CheckCoherencyLocalHeader(zipEntry, extraSize);
2642 EXPECT_EQ(ret, false);
2643 }
2644
2645 /**
2646 * @tc.number: ZipFile_0400
2647 * @tc.name: Test ZipFile
2648 * @tc.desc: 1.Test SeekToEntryStart
2649 */
2650 HWTEST_F(BmsBundleInstallerTest, ZipFile_0400, Function | SmallTest | Level1)
2651 {
2652 ZipFile file("/test.zip");
2653 ZipEntry zipEntry;
2654 zipEntry.localHeaderOffset = 1;
2655 uint16_t extraSize = 0;
2656 bool ret = file.SeekToEntryStart(zipEntry, extraSize);
2657 EXPECT_EQ(ret, false);
2658 }
2659
2660 /**
2661 * @tc.number: BaseExtractor_0100
2662 * @tc.name: Test HasEntry
2663 * @tc.desc: 1.Test HasEntry of BaseExtractor
2664 */
2665 HWTEST_F(BmsBundleInstallerTest, BaseExtractor_0100, Function | SmallTest | Level1)
2666 {
2667 BaseExtractor extractor("file.zip");
2668 extractor.initial_ = false;
2669 bool ret = extractor.HasEntry("entry");
2670 EXPECT_EQ(ret, false);
2671
2672 extractor.initial_ = true;
2673 ret = extractor.HasEntry("");
2674 EXPECT_EQ(ret, false);
2675 }
2676
2677 /**
2678 * @tc.number: BaseExtractor_0200
2679 * @tc.name: Test HasEntry
2680 * @tc.desc: 1.Test HasEntry of BaseExtractor
2681 */
2682 HWTEST_F(BmsBundleInstallerTest, BaseExtractor_0200, Function | SmallTest | Level1)
2683 {
2684 BaseExtractor extractor("file.zip");
2685 bool ret = extractor.ExtractFile("entry", "/data/test");
2686 EXPECT_EQ(ret, false);
2687 }
2688
2689 /**
2690 * @tc.number: BaseExtractor_0300
2691 * @tc.name: Test HasEntry
2692 * @tc.desc: 1.Test HasEntry of BaseExtractor
2693 */
2694 HWTEST_F(BmsBundleInstallerTest, BaseExtractor_0300, Function | SmallTest | Level1)
2695 {
2696 BaseExtractor extractor("file.zip");
2697 uint32_t offset = 1;
2698 uint32_t length = 10;
2699 bool ret = extractor.GetFileInfo("bootpic.zip", offset, length);
2700 EXPECT_EQ(ret, false);
2701 }
2702
2703 /**
2704 * @tc.number: BaseExtractor_0400
2705 * @tc.name: Test HasEntry
2706 * @tc.desc: 1.Test HasEntry of BaseExtractor
2707 */
2708 HWTEST_F(BmsBundleInstallerTest, BaseExtractor_0400, Function | SmallTest | Level1)
2709 {
2710 BaseExtractor extractor("/system/etc/graphic/bootpic.zip");
2711 extractor.initial_ = true;
2712 uint32_t offset = 1;
2713 uint32_t length = 10;
2714 bool ret = extractor.GetFileInfo("bootpic.zip", offset, length);
2715 EXPECT_EQ(ret, false);
2716 }
2717
2718 /**
2719 * @tc.number: InstallFailed_0100
2720 * @tc.name: Test CheckHapHashParams
2721 * @tc.desc: 1.Test CheckHapHashParams of BundleInstallChecker
2722 */
2723 HWTEST_F(BmsBundleInstallerTest, InstallFailed_0100, Function | SmallTest | Level1)
2724 {
2725 BundleInstallChecker installChecker;
2726 std::vector<std::string> bundlePaths;
2727 ErrCode ret = installChecker.CheckSysCap(bundlePaths);
2728 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_PARAM_ERROR);
2729
2730 std::map<std::string, std::string> hashParams;
2731 hashParams.try_emplace("entry", "hashValue");
2732 std::unordered_map<std::string, InnerBundleInfo> infos;
2733 ret = installChecker.CheckHapHashParams(infos, hashParams);
2734 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_FAILED_CHECK_HAP_HASH_PARAM);
2735
2736 InnerBundleInfo innerBundleInfo;
2737 infos.try_emplace("hashParam", innerBundleInfo);
2738 ret = installChecker.CheckHapHashParams(infos, hashParams);
2739 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_FAILED_MODULE_NAME_EMPTY);
2740
2741 InnerModuleInfo innerModuleInfo;
2742 innerModuleInfo.moduleName = "entry";
2743 innerBundleInfo.innerModuleInfos_.clear();
2744 innerBundleInfo.innerModuleInfos_.try_emplace("module1", innerModuleInfo);
2745 innerBundleInfo.innerModuleInfos_.try_emplace("module1", innerModuleInfo);
2746 infos.clear();
2747 infos.try_emplace("hashParam", innerBundleInfo);
2748 ret = installChecker.CheckHapHashParams(infos, hashParams);
2749 EXPECT_EQ(ret, ERR_OK);
2750 }
2751
2752 /**
2753 * @tc.number: InstallChecker_0100
2754 * @tc.name: test the start function of CheckSysCap
2755 * @tc.desc: 1. BundleInstallChecker
2756 */
2757 HWTEST_F(BmsBundleInstallerTest, InstallChecker_0100, Function | SmallTest | Level0)
2758 {
2759 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
2760 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
2761 EXPECT_EQ(installResult, ERR_OK);
2762
2763 std::vector<std::string> bundlePaths;
2764 bundlePaths.push_back(bundlePath);
2765 BundleInstallChecker installChecker;
2766 auto ret = installChecker.CheckSysCap(bundlePaths);
2767 EXPECT_EQ(ret, ERR_OK);
2768
2769 UnInstallBundle(BUNDLE_BACKUP_NAME);
2770 }
2771
2772 /**
2773 * @tc.number: InstallChecker_0200
2774 * @tc.name: test the start function of CheckSysCap
2775 * @tc.desc: 1. BundleInstallChecker
2776 */
2777 HWTEST_F(BmsBundleInstallerTest, InstallChecker_0200, Function | SmallTest | Level0)
2778 {
2779 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST + "rpcid.sc";
2780 std::vector<std::string> bundlePaths;
2781 bundlePaths.push_back(bundlePath);
2782 BundleInstallChecker installChecker;
2783 auto ret = installChecker.CheckSysCap(bundlePaths);
2784 EXPECT_EQ(ret, ERR_APPEXECFWK_PARSE_UNEXPECTED);
2785 }
2786
2787 /**
2788 * @tc.number: InstallChecker_0300
2789 * @tc.name: test the start function of CheckMultipleHapsSignInfo
2790 * @tc.desc: 1. BundleInstallChecker
2791 */
2792 HWTEST_F(BmsBundleInstallerTest, InstallChecker_0300, Function | SmallTest | Level0)
2793 {
2794 std::vector<std::string> bundlePaths;
2795 bundlePaths.push_back("data");
2796 std::vector<Security::Verify::HapVerifyResult> hapVerifyRes;
2797 Security::Verify::HapVerifyResult hapVerifyResult;
2798 hapVerifyResult.GetProvisionInfo().appId = "8519754";
2799 hapVerifyRes.emplace_back(hapVerifyResult);
2800 BundleInstallChecker installChecker;
2801 auto ret = installChecker.CheckMultipleHapsSignInfo(bundlePaths, hapVerifyRes);
2802 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_FAILED_INVALID_SIGNATURE_FILE_PATH);
2803 }
2804
2805 /**
2806 * @tc.number: InstallChecker_0400
2807 * @tc.name: test the start function of CheckDependency
2808 * @tc.desc: 1. BundleInstallChecker
2809 */
2810 HWTEST_F(BmsBundleInstallerTest, InstallChecker_0400, Function | SmallTest | Level0)
2811 {
2812 std::unordered_map<std::string, InnerBundleInfo> infos;
2813 BundleInstallChecker installChecker;
2814 auto ret = installChecker.CheckDependency(infos);
2815 EXPECT_EQ(ret, ERR_OK);
2816
2817 InnerBundleInfo innerBundleInfo;
2818 ApplicationInfo applicationInfo;
2819 applicationInfo.bundleName = "moduleName";
2820 innerBundleInfo.SetBaseApplicationInfo(applicationInfo);
2821 InnerModuleInfo innerModuleInfo;
2822 innerModuleInfo.moduleName = "moduleName";
2823 Dependency dependency;
2824 dependency.moduleName = "moduleName";
2825 dependency.bundleName = "bundleName";
2826 innerModuleInfo.dependencies.push_back(dependency);
2827 innerBundleInfo.innerModuleInfos_.insert(
2828 pair<std::string, InnerModuleInfo>("moduleName", innerModuleInfo));
2829 infos.insert(pair<std::string, InnerBundleInfo>("moduleName", innerBundleInfo));
2830
2831 ret = installChecker.CheckDependency(infos);
2832 EXPECT_EQ(ret, ERR_OK);
2833 }
2834
2835 /**
2836 * @tc.number: InstallChecker_0500
2837 * @tc.name: test the start function of NeedCheckDependency
2838 * @tc.desc: 1. BundleInstallChecker
2839 */
2840 HWTEST_F(BmsBundleInstallerTest, InstallChecker_0500, Function | SmallTest | Level0)
2841 {
2842 BundleInstallChecker installChecker;
2843 InnerBundleInfo innerBundleInfo;
2844 ApplicationInfo applicationInfo;
2845 applicationInfo.bundleName = "bundleName1";
2846 innerBundleInfo.SetBaseApplicationInfo(applicationInfo);
2847 Dependency dependency;
2848 dependency.bundleName = "bundleName2";
2849 auto ret = installChecker.NeedCheckDependency(dependency, innerBundleInfo);
2850 EXPECT_EQ(ret, false);
2851 BundlePackInfo bundlePackInfo;
2852 PackageModule packageModule;
2853 bundlePackInfo.summary.modules.push_back(packageModule);
2854 innerBundleInfo.SetBundlePackInfo(bundlePackInfo);
2855 ret = installChecker.NeedCheckDependency(dependency, innerBundleInfo);
2856 EXPECT_EQ(ret, false);
2857 }
2858
2859 /**
2860 * @tc.number: InstallChecker_0600
2861 * @tc.name: test the start function of FindModuleInInstallingPackage
2862 * @tc.desc: 1. BundleInstallChecker
2863 */
2864 HWTEST_F(BmsBundleInstallerTest, InstallChecker_0600, Function | SmallTest | Level0)
2865 {
2866 std::unordered_map<std::string, InnerBundleInfo> infos;
2867
2868 BundleInstallChecker installChecker;
2869 auto ret = installChecker.FindModuleInInstallingPackage("moduleName", "bundleName", infos);
2870 EXPECT_EQ(ret, false);
2871
2872 InnerBundleInfo innerBundleInfo;
2873 ApplicationInfo applicationInfo;
2874 applicationInfo.bundleName = "bundleName";
2875 innerBundleInfo.SetBaseApplicationInfo(applicationInfo);
2876 InnerModuleInfo innerModuleInfo;
2877 innerModuleInfo.moduleName = "moduleName";
2878 innerBundleInfo.innerModuleInfos_.insert(
2879 pair<std::string, InnerModuleInfo>("moduleName", innerModuleInfo));
2880 infos.insert(pair<std::string, InnerBundleInfo>("moduleName", innerBundleInfo));
2881 ret = installChecker.FindModuleInInstallingPackage("moduleName", "bundleName", infos);
2882 EXPECT_EQ(ret, true);
2883 }
2884
2885 /**
2886 * @tc.number: InstallChecker_0700
2887 * @tc.name: test the start function of FindModuleInInstalledPackage
2888 * @tc.desc: 1. BundleInstallChecker
2889 */
2890 HWTEST_F(BmsBundleInstallerTest, InstallChecker_0700, Function | SmallTest | Level0)
2891 {
2892 BundleInstallChecker installChecker;
2893 auto ret = installChecker.FindModuleInInstalledPackage("", "", 0);
2894 EXPECT_EQ(ret, false);
2895 ret = installChecker.FindModuleInInstalledPackage("moduleName", "moduleName", 0);
2896 EXPECT_EQ(ret, false);
2897 }
2898
2899 /**
2900 * @tc.number: InstallChecker_0800
2901 * @tc.name: test the start function of ParseBundleInfo
2902 * @tc.desc: 1. BundleInstallChecker
2903 */
2904 HWTEST_F(BmsBundleInstallerTest, InstallChecker_0800, Function | SmallTest | Level0)
2905 {
2906 BundleInstallChecker installChecker;
2907 InnerBundleInfo info;
2908 BundlePackInfo packInfo;
2909 auto ret = installChecker.ParseBundleInfo("", info, packInfo);
2910 EXPECT_EQ(ret, ERR_APPEXECFWK_PARSE_UNEXPECTED);
2911 }
2912
2913 /**
2914 * @tc.number: InstallChecker_0900
2915 * @tc.name: test the start function of CheckDeviceType
2916 * @tc.desc: 1. BundleInstallChecker
2917 */
2918 HWTEST_F(BmsBundleInstallerTest, InstallChecker_0900, Function | SmallTest | Level0)
2919 {
2920 BundleInstallChecker installChecker;
2921 std::unordered_map<std::string, InnerBundleInfo> infos;
2922 infos.clear();
2923 auto ret = installChecker.CheckDeviceType(infos);
2924 EXPECT_EQ(ret, ERR_OK);
2925 }
2926
2927 /**
2928 * @tc.number: InstallChecker_1000
2929 * @tc.name: test the start function of CheckBundleName
2930 * @tc.desc: 1. BundleInstallChecker
2931 */
2932 HWTEST_F(BmsBundleInstallerTest, InstallChecker_1000, Function | SmallTest | Level0)
2933 {
2934 BundleInstallChecker installChecker;
2935 std::string provisionBundleName;
2936 auto ret = installChecker.CheckBundleName("", "");
2937 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_FAILED_BUNDLE_SIGNATURE_VERIFICATION_FAILURE);
2938 }
2939
2940 /**
2941 * @tc.number: InstallChecker_1100
2942 * @tc.name: test the start function of CheckBundleName
2943 * @tc.desc: 1. BundleInstallChecker
2944 */
2945 HWTEST_F(BmsBundleInstallerTest, InstallChecker_1100, Function | SmallTest | Level0)
2946 {
2947 BundleInstallChecker installChecker;
2948 std::string provisionBundleName = BUNDLE_NAME;
2949 auto ret = installChecker.CheckBundleName(provisionBundleName, "");
2950 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_FAILED_BUNDLE_SIGNATURE_VERIFICATION_FAILURE);
2951 }
2952
2953 /**
2954 * @tc.number: InstallChecker_1200
2955 * @tc.name: test the start function of CheckBundleName
2956 * @tc.desc: 1. BundleInstallChecker
2957 */
2958 HWTEST_F(BmsBundleInstallerTest, InstallChecker_1200, Function | SmallTest | Level0)
2959 {
2960 BundleInstallChecker installChecker;
2961 std::string provisionBundleName = BUNDLE_NAME;
2962 auto ret = installChecker.CheckBundleName(provisionBundleName, BUNDLE_NAME);
2963 EXPECT_EQ(ret, ERR_OK);
2964 }
2965
2966 /**
2967 * @tc.number: InstallChecker_1300
2968 * @tc.name: test the start function of CheckBundleName
2969 * @tc.desc: 1. BundleInstallChecker
2970 */
2971 HWTEST_F(BmsBundleInstallerTest, InstallChecker_1300, Function | SmallTest | Level0)
2972 {
2973 BundleInstallChecker installChecker;
2974 auto ret = installChecker.CheckBundleName("", BUNDLE_NAME);
2975 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_FAILED_BUNDLE_SIGNATURE_VERIFICATION_FAILURE);
2976 }
2977
2978 /**
2979 * @tc.number: InstallChecker_1400
2980 * @tc.name: test the start function of VaildInstallPermission
2981 * @tc.desc: 1. BundleInstallChecker
2982 */
2983 HWTEST_F(BmsBundleInstallerTest, InstallChecker_1400, Function | SmallTest | Level0)
2984 {
2985 BundleInstallChecker installChecker;
2986 InstallParam installParam;
2987 installParam.isCallByShell = true;
2988 std::vector<Security::Verify::HapVerifyResult> hapVerifyRes;
2989 bool ret = installChecker.VaildInstallPermission(installParam, hapVerifyRes);
2990 EXPECT_EQ(ret, true);
2991 }
2992
2993 /**
2994 * @tc.number: InstallChecker_1500
2995 * @tc.name: test the start function of VaildInstallPermission
2996 * @tc.desc: 1. BundleInstallChecker
2997 */
2998 HWTEST_F(BmsBundleInstallerTest, InstallChecker_1500, Function | SmallTest | Level0)
2999 {
3000 BundleInstallChecker installChecker;
3001 InstallParam installParam;
3002 installParam.isCallByShell = false;
3003 std::vector<Security::Verify::HapVerifyResult> hapVerifyRes;
3004 bool ret = installChecker.VaildInstallPermission(installParam, hapVerifyRes);
3005 EXPECT_EQ(ret, true);
3006 installParam.installBundlePermissionStatus = PermissionStatus::HAVE_PERMISSION_STATUS;
3007 ret = installChecker.VaildInstallPermission(installParam, hapVerifyRes);
3008 EXPECT_EQ(ret, true);
3009 installParam.installEnterpriseBundlePermissionStatus = PermissionStatus::HAVE_PERMISSION_STATUS;
3010 ret = installChecker.VaildInstallPermission(installParam, hapVerifyRes);
3011 EXPECT_EQ(ret, true);
3012 }
3013
3014 /**
3015 * @tc.number: InstallChecker_1600
3016 * @tc.name: test the start function of VaildInstallPermission
3017 * @tc.desc: 1. BundleInstallChecker
3018 */
3019 HWTEST_F(BmsBundleInstallerTest, InstallChecker_1600, Function | SmallTest | Level0)
3020 {
3021 BundleInstallChecker installChecker;
3022 InstallParam installParam;
3023 installParam.isCallByShell = true;
3024 std::vector<Security::Verify::HapVerifyResult> hapVerifyRes;
3025 Security::Verify::HapVerifyResult result;
3026 Security::Verify::ProvisionInfo info;
3027 info.distributionType = Security::Verify::AppDistType::ENTERPRISE;
3028 info.type = Security::Verify::ProvisionType::DEBUG;
3029 result.SetProvisionInfo(info);
3030 bool ret = installChecker.VaildInstallPermission(installParam, hapVerifyRes);
3031 EXPECT_EQ(ret, true);
3032 }
3033
3034 /**
3035 * @tc.number: InstallChecker_1700
3036 * @tc.name: test the start function of VaildInstallPermission
3037 * @tc.desc: 1. BundleInstallChecker
3038 */
3039 HWTEST_F(BmsBundleInstallerTest, InstallChecker_1700, Function | SmallTest | Level0)
3040 {
3041 BundleInstallChecker installChecker;
3042 InstallParam installParam;
3043 installParam.isCallByShell = true;
3044 installParam.installEnterpriseBundlePermissionStatus = PermissionStatus::NON_HAVE_PERMISSION_STATUS;
3045 std::vector<Security::Verify::HapVerifyResult> hapVerifyRes;
3046 Security::Verify::HapVerifyResult result;
3047 Security::Verify::ProvisionInfo info;
3048 info.distributionType = Security::Verify::AppDistType::ENTERPRISE;
3049 info.type = Security::Verify::ProvisionType::RELEASE;
3050 result.SetProvisionInfo(info);
3051 hapVerifyRes.emplace_back(result);
3052 bool ret = installChecker.VaildInstallPermission(installParam, hapVerifyRes);
3053 EXPECT_EQ(ret, false);
3054 }
3055
3056 /**
3057 * @tc.number: InstallChecker_1800
3058 * @tc.name: test the start function of VaildInstallPermission
3059 * @tc.desc: 1. BundleInstallChecker
3060 */
3061 HWTEST_F(BmsBundleInstallerTest, InstallChecker_1800, Function | SmallTest | Level0)
3062 {
3063 BundleInstallChecker installChecker;
3064 InstallParam installParam;
3065 installParam.isCallByShell = true;
3066 std::vector<Security::Verify::HapVerifyResult> hapVerifyRes;
3067 Security::Verify::HapVerifyResult result;
3068 hapVerifyRes.emplace_back(result);
3069 bool ret = installChecker.VaildInstallPermission(installParam, hapVerifyRes);
3070 EXPECT_EQ(ret, false);
3071 }
3072
3073 /**
3074 * @tc.number: InstallChecker_1900
3075 * @tc.name: test the start function of VaildInstallPermission
3076 * @tc.desc: 1. BundleInstallChecker
3077 */
3078 HWTEST_F(BmsBundleInstallerTest, InstallChecker_1900, Function | SmallTest | Level0)
3079 {
3080 BundleInstallChecker installChecker;
3081 InstallParam installParam;
3082 installParam.isCallByShell = false;
3083 std::vector<Security::Verify::HapVerifyResult> hapVerifyRes;
3084 Security::Verify::HapVerifyResult result;
3085 Security::Verify::ProvisionInfo info;
3086 info.distributionType = Security::Verify::AppDistType::ENTERPRISE;
3087 result.SetProvisionInfo(info);
3088 hapVerifyRes.emplace_back(result);
3089 bool ret = installChecker.VaildInstallPermission(installParam, hapVerifyRes);
3090 EXPECT_EQ(ret, false);
3091 }
3092
3093 /**
3094 * @tc.number: BmsBundleSignatureType_0100
3095 * @tc.name: test signed name is not the same
3096 * @tc.desc: 1. system running normally
3097 * 2. install a hap failed
3098 */
3099 HWTEST_F(BmsBundleInstallerTest, BmsBundleSignatureType_0100, Function | SmallTest | Level0)
3100 {
3101 std::string bundlePath = RESOURCE_ROOT_PATH + "signatureTest.hap";
3102 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
3103 EXPECT_EQ(installResult, ERR_APPEXECFWK_INSTALL_FAILED_BUNDLE_SIGNATURE_VERIFICATION_FAILURE);
3104 }
3105
3106 /**
3107 * @tc.number: ExtractArkProfileFile_0100
3108 * @tc.name: test ExtractArkProfileFile
3109 * @tc.desc: 1.Test ExtractArkProfileFile
3110 */
3111 HWTEST_F(BmsBundleInstallerTest, ExtractArkProfileFile_0100, Function | SmallTest | Level0)
3112 {
3113 BaseBundleInstaller installer;
3114 std::string modulePath = "";
3115 std::string bundleName = "";
3116 auto ret = installer.ExtractArkProfileFile(modulePath, bundleName, USERID);
3117 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
3118 }
3119
3120 /**
3121 * @tc.number: ExtractArkProfileFile_0200
3122 * @tc.name: test ExtractArkProfileFile
3123 * @tc.desc: 1.Test ExtractArkProfileFile
3124 */
3125 HWTEST_F(BmsBundleInstallerTest, ExtractArkProfileFile_0200, Function | SmallTest | Level0)
3126 {
3127 BaseBundleInstaller installer;
3128 std::string modulePath = RESOURCE_ROOT_PATH + RIGHT_BUNDLE;
3129 std::string bundleName = BUNDLE_NAME;
3130 auto ret = installer.ExtractArkProfileFile(modulePath, bundleName, USERID);
3131 EXPECT_EQ(ret, ERR_OK);
3132 }
3133
3134 /**
3135 * @tc.number: ExtractAllArkProfileFile_0100
3136 * @tc.name: test ExtractAllArkProfileFile
3137 * @tc.desc: 1.Test ExtractAllArkProfileFile
3138 */
3139 HWTEST_F(BmsBundleInstallerTest, ExtractAllArkProfileFile_0100, Function | SmallTest | Level0)
3140 {
3141 InnerBundleInfo innerBundleInfo;
3142 BaseBundleInstaller installer;
3143 auto ret = installer.ExtractAllArkProfileFile(innerBundleInfo);
3144 EXPECT_EQ(ret, ERR_OK);
3145 }
3146
3147 /**
3148 * @tc.number: ExtractAllArkProfileFile_0200
3149 * @tc.name: test ExtractAllArkProfileFile
3150 * @tc.desc: 1.Test ExtractAllArkProfileFile
3151 */
3152 HWTEST_F(BmsBundleInstallerTest, ExtractAllArkProfileFile_0200, Function | SmallTest | Level0)
3153 {
3154 InnerModuleInfo innerModuleInfo;
3155 innerModuleInfo.name = MODULE_NAME;
3156 innerModuleInfo.modulePackage = MODULE_NAME;
3157 InnerBundleInfo innerBundleInfo;
3158 innerBundleInfo.SetIsNewVersion(true);
3159 innerBundleInfo.InsertInnerModuleInfo(MODULE_NAME, innerModuleInfo);
3160 BaseBundleInstaller installer;
3161 auto ret = installer.ExtractAllArkProfileFile(innerBundleInfo);
3162 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
3163 }
3164
3165 /**
3166 * @tc.number: ExtractAllArkProfileFile_0300
3167 * @tc.name: test ExtractAllArkProfileFile
3168 * @tc.desc: 1.Test ExtractAllArkProfileFile
3169 */
3170 HWTEST_F(BmsBundleInstallerTest, ExtractAllArkProfileFile_0300, Function | SmallTest | Level0)
3171 {
3172 InnerModuleInfo innerModuleInfo;
3173 innerModuleInfo.name = MODULE_NAME;
3174 innerModuleInfo.modulePackage = MODULE_NAME;
3175 innerModuleInfo.hapPath = RESOURCE_ROOT_PATH + RIGHT_BUNDLE;
3176 InnerBundleInfo innerBundleInfo;
3177 innerBundleInfo.InsertInnerModuleInfo(MODULE_NAME, innerModuleInfo);
3178 ApplicationInfo applicationInfo;
3179 applicationInfo.bundleName = BUNDLE_NAME;
3180 applicationInfo.name = BUNDLE_NAME;
3181 innerBundleInfo.SetBaseApplicationInfo(applicationInfo);
3182 innerBundleInfo.SetIsNewVersion(true);
3183 BaseBundleInstaller installer;
3184 auto ret = installer.ExtractAllArkProfileFile(innerBundleInfo);
3185 EXPECT_EQ(ret, ERR_OK);
3186 }
3187
3188 /**
3189 * @tc.number: ExtractAllArkProfileFile_0400
3190 * @tc.name: test ExtractAllArkProfileFile
3191 * @tc.desc: 1.Test ExtractAllArkProfileFile
3192 */
3193 HWTEST_F(BmsBundleInstallerTest, ExtractAllArkProfileFile_0400, Function | SmallTest | Level0)
3194 {
3195 InnerBundleInfo innerBundleInfo;
3196 innerBundleInfo.SetIsNewVersion(false);
3197 BaseBundleInstaller installer;
3198 auto ret = installer.ExtractAllArkProfileFile(innerBundleInfo);
3199 EXPECT_EQ(ret, ERR_OK);
3200 }
3201
3202 /**
3203 * @tc.number: CheckArkProfileDir_0100
3204 * @tc.name: test CheckArkProfileDir
3205 * @tc.desc: 1.Test CheckArkProfileDir
3206 */
3207 HWTEST_F(BmsBundleInstallerTest, CheckArkProfileDir_0100, Function | SmallTest | Level0)
3208 {
3209 BundleInfo bundleInfo;
3210 bundleInfo.versionCode = 100;
3211 InnerBundleInfo innerBundleInfo;
3212 innerBundleInfo.SetBaseBundleInfo(bundleInfo);
3213 innerBundleInfo.SetIsNewVersion(false);
3214 BaseBundleInstaller installer;
3215 installer.bundleName_ = BUNDLE_NAME;
3216 installer.userId_ = USERID;
3217 InnerBundleInfo oldInnerBundleInfo;
3218 BundleInfo oldBundleInfo;
3219 oldBundleInfo.versionCode = 101;
3220 oldInnerBundleInfo.SetBaseBundleInfo(oldBundleInfo);
3221 auto ret = installer.CheckArkProfileDir(innerBundleInfo, oldInnerBundleInfo);
3222 EXPECT_EQ(ret, ERR_OK);
3223 }
3224
3225 /**
3226 * @tc.number: CheckArkProfileDir_0200
3227 * @tc.name: test CheckArkProfileDir
3228 * @tc.desc: 1.Test CheckArkProfileDir
3229 */
3230 HWTEST_F(BmsBundleInstallerTest, CheckArkProfileDir_0200, Function | SmallTest | Level0)
3231 {
3232 BundleInfo bundleInfo;
3233 bundleInfo.versionCode = 101;
3234 InnerBundleInfo innerBundleInfo;
3235 innerBundleInfo.SetBaseBundleInfo(bundleInfo);
3236 innerBundleInfo.SetIsNewVersion(false);
3237 BaseBundleInstaller installer;
3238 installer.bundleName_ = BUNDLE_NAME;
3239 installer.userId_ = USERID;
3240 InnerBundleInfo oldInnerBundleInfo;
3241 BundleInfo oldBundleInfo;
3242 oldBundleInfo.versionCode = 100;
3243 oldInnerBundleInfo.SetBaseBundleInfo(oldBundleInfo);
3244 auto ret = installer.CheckArkProfileDir(innerBundleInfo, oldInnerBundleInfo);
3245 EXPECT_EQ(ret, ERR_OK);
3246 }
3247
3248 /**
3249 * @tc.number: CheckArkProfileDir_0300
3250 * @tc.name: test CheckArkProfileDir
3251 * @tc.desc: 1.Test CheckArkProfileDir
3252 */
3253 HWTEST_F(BmsBundleInstallerTest, CheckArkProfileDir_0300, Function | SmallTest | Level0)
3254 {
3255 BundleInfo bundleInfo;
3256 bundleInfo.versionCode = 101;
3257 InnerBundleInfo innerBundleInfo;
3258 innerBundleInfo.SetBaseBundleInfo(bundleInfo);
3259 innerBundleInfo.SetIsNewVersion(false);
3260 BaseBundleInstaller installer;
3261 installer.bundleName_ = BUNDLE_NAME;
3262 installer.userId_ = USERID;
3263 InnerBundleInfo oldInnerBundleInfo;
3264 BundleInfo oldBundleInfo;
3265 oldBundleInfo.versionCode = 100;
3266 oldInnerBundleInfo.SetBaseBundleInfo(oldBundleInfo);
3267 InnerBundleUserInfo innerBundleUserInfo;
3268 innerBundleUserInfo.bundleUserInfo.userId = USERID;
3269 innerBundleUserInfo.bundleName = BUNDLE_NAME;
3270 oldInnerBundleInfo.AddInnerBundleUserInfo(innerBundleUserInfo);
3271 auto ret = installer.CheckArkProfileDir(innerBundleInfo, oldInnerBundleInfo);
3272 EXPECT_EQ(ret, ERR_OK);
3273 ret = installer.DeleteArkProfile(installer.bundleName_, installer.userId_);
3274 EXPECT_EQ(ret, ERR_OK);
3275 }
3276
3277 /**
3278 * @tc.number: CheckArkProfileDir_0400
3279 * @tc.name: test CheckArkProfileDir
3280 * @tc.desc: 1.Test CheckArkProfileDir
3281 */
3282 HWTEST_F(BmsBundleInstallerTest, CheckArkProfileDir_0400, Function | SmallTest | Level0)
3283 {
3284 BundleInfo bundleInfo;
3285 bundleInfo.versionCode = 101;
3286 InnerBundleInfo innerBundleInfo;
3287 innerBundleInfo.SetBaseBundleInfo(bundleInfo);
3288 innerBundleInfo.SetIsNewVersion(true);
3289 BaseBundleInstaller installer;
3290 installer.bundleName_ = BUNDLE_NAME;
3291 installer.userId_ = USERID;
3292 InnerBundleInfo oldInnerBundleInfo;
3293 BundleInfo oldBundleInfo;
3294 oldBundleInfo.versionCode = 100;
3295 oldInnerBundleInfo.SetBaseBundleInfo(oldBundleInfo);
3296 InnerBundleUserInfo innerBundleUserInfo;
3297 innerBundleUserInfo.bundleUserInfo.userId = USERID;
3298 innerBundleUserInfo.bundleName = BUNDLE_NAME;
3299 oldInnerBundleInfo.AddInnerBundleUserInfo(innerBundleUserInfo);
3300 auto ret = installer.CheckArkProfileDir(innerBundleInfo, oldInnerBundleInfo);
3301 EXPECT_EQ(ret, ERR_OK);
3302 ret = installer.DeleteArkProfile(installer.bundleName_, installer.userId_);
3303 EXPECT_EQ(ret, ERR_OK);
3304 }
3305
3306 /**
3307 * @tc.number: asanEnabled_0100
3308 * @tc.name: test checkAsanEnabled when asanEnabled is set to be ture
3309 * @tc.desc: 1.Test checkAsanEnabled
3310 */
3311 HWTEST_F(BmsBundleInstallerTest, checkAsanEnabled_0100, Function | SmallTest | Level0)
3312 {
3313 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
3314 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
3315 EXPECT_EQ(installResult, ERR_OK);
3316 ApplicationInfo info;
3317 auto dataMgr = GetBundleDataMgr();
3318 EXPECT_NE(dataMgr, nullptr);
3319 bool result = dataMgr->GetApplicationInfo(BUNDLE_BACKUP_NAME,
3320 ApplicationFlag::GET_BASIC_APPLICATION_INFO, USERID, info);
3321 EXPECT_TRUE(result);
3322 EXPECT_TRUE(info.asanEnabled);
3323 std::string asanLogPath = LOG;
3324 EXPECT_EQ(asanLogPath, info.asanLogPath);
3325 UnInstallBundle(BUNDLE_BACKUP_NAME);
3326 }
3327
3328 HWTEST_F(BmsBundleInstallerTest, checkAsanEnabled_0200, Function | SmallTest | Level0)
3329 {
3330 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_PREVIEW_TEST;
3331 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
3332 EXPECT_EQ(installResult, ERR_OK);
3333 auto dataMgr = GetBundleDataMgr();
3334 EXPECT_NE(dataMgr, nullptr);
3335 ApplicationInfo info;
3336 bool result = dataMgr->GetApplicationInfo(BUNDLE_PREVIEW_NAME,
3337 ApplicationFlag::GET_BASIC_APPLICATION_INFO, USERID, info);
3338 EXPECT_TRUE(result);
3339 EXPECT_FALSE(info.asanEnabled);
3340 std::string asanLogPath = "";
3341 EXPECT_EQ(asanLogPath, info.asanLogPath);
3342 UnInstallBundle(BUNDLE_PREVIEW_NAME);
3343 }
3344
3345 #ifdef BUNDLE_FRAMEWORK_APP_CONTROL
3346
3347 /**
3348 * @tc.number: baseBundleInstaller_4400
3349 * @tc.name: test InstallNormalAppControl
3350 * @tc.desc: 1.Test the InstallNormalAppControl of BaseBundleInstaller
3351 */
3352 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_4400, Function | SmallTest | Level0)
3353 {
3354 std::string installAppId = APPID;
3355 BaseBundleInstaller installer;
3356 int32_t userId = Constants::DEFAULT_USERID;
3357 std::vector<std::string> appIds;
3358 appIds.emplace_back(APPID);
3359
3360 auto resultAddAppInstallAppControlDisallow = DelayedSingleton<AppControlManager>::GetInstance()->
3361 AddAppInstallControlRule(AppControlConstants::EDM_CALLING,
3362 appIds, AppControlConstants::APP_DISALLOWED_INSTALL, userId);
3363 EXPECT_EQ(resultAddAppInstallAppControlDisallow, OHOS::ERR_OK);
3364
3365 auto ret = installer.InstallNormalAppControl(installAppId, userId);
3366 EXPECT_EQ(ret, OHOS::ERR_BUNDLE_MANAGER_APP_CONTROL_DISALLOWED_INSTALL);
3367
3368 auto resultDeleteAppInstallAppControlDisallow = DelayedSingleton<AppControlManager>::GetInstance()->
3369 DeleteAppInstallControlRule(AppControlConstants::EDM_CALLING,
3370 AppControlConstants::APP_DISALLOWED_INSTALL, appIds, userId);
3371 EXPECT_EQ(resultDeleteAppInstallAppControlDisallow, OHOS::ERR_OK);
3372 }
3373
3374 /**
3375 * @tc.number: baseBundleInstaller_4500
3376 * @tc.name: test InstallNormalAppControl
3377 * @tc.desc: 1.Test the InstallNormalAppControl of BaseBundleInstaller
3378 */
3379 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_4500, Function | SmallTest | Level0)
3380 {
3381 std::string installAppId = APPID;
3382 BaseBundleInstaller installer;
3383 int32_t userId = Constants::DEFAULT_USERID;
3384 std::vector<std::string> appIds;
3385 appIds.emplace_back(SYSTEMFIEID_NAME);
3386
3387 auto resultAddAppInstallAppControlAllow = DelayedSingleton<AppControlManager>::GetInstance()->
3388 AddAppInstallControlRule(AppControlConstants::EDM_CALLING,
3389 appIds, AppControlConstants::APP_DISALLOWED_INSTALL, userId);
3390 EXPECT_EQ(resultAddAppInstallAppControlAllow, OHOS::ERR_OK);
3391
3392 auto ret = installer.InstallNormalAppControl(installAppId, userId);
3393 EXPECT_EQ(ret, OHOS::ERR_OK);
3394
3395 auto resultDeleteAppInstallAppControlAllow = DelayedSingleton<AppControlManager>::GetInstance()->
3396 DeleteAppInstallControlRule(AppControlConstants::EDM_CALLING,
3397 AppControlConstants::APP_DISALLOWED_INSTALL, appIds, userId);
3398 EXPECT_EQ(resultDeleteAppInstallAppControlAllow, OHOS::ERR_OK);
3399 }
3400
3401 /**
3402 * @tc.number: baseBundleInstaller_4600
3403 * @tc.name: test InstallNormalAppControl
3404 * @tc.desc: 1.Test the InstallNormalAppControl of BaseBundleInstaller
3405 */
3406 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_4600, Function | SmallTest | Level0)
3407 {
3408 std::string installAppId = APPID;
3409 BaseBundleInstaller installer;
3410 int32_t userId = Constants::DEFAULT_USERID;
3411 std::vector<std::string> appIds;
3412 appIds.emplace_back(APPID);
3413 seteuid(EDM_UID);
3414 auto resultAddAppInstallAppControlAllow = DelayedSingleton<AppControlManager>::GetInstance()->
3415 AddAppInstallControlRule(AppControlConstants::EDM_CALLING,
3416 appIds, AppControlConstants::APP_ALLOWED_INSTALL, userId);
3417 EXPECT_EQ(resultAddAppInstallAppControlAllow, OHOS::ERR_OK);
3418
3419 auto resultAddAppInstallAppControlDisallow = DelayedSingleton<AppControlManager>::GetInstance()->
3420 AddAppInstallControlRule(AppControlConstants::EDM_CALLING,
3421 appIds, AppControlConstants::APP_DISALLOWED_INSTALL, userId);
3422 EXPECT_EQ(resultAddAppInstallAppControlDisallow, OHOS::ERR_OK);
3423
3424 auto ret = installer.InstallNormalAppControl(installAppId, userId);
3425 EXPECT_EQ(ret, OHOS::ERR_BUNDLE_MANAGER_APP_CONTROL_DISALLOWED_INSTALL);
3426
3427 auto resultDeleteAppInstallAppControlAllow = DelayedSingleton<AppControlManager>::GetInstance()->
3428 DeleteAppInstallControlRule(AppControlConstants::EDM_CALLING,
3429 AppControlConstants::APP_ALLOWED_INSTALL, appIds, userId);
3430 EXPECT_EQ(resultDeleteAppInstallAppControlAllow, OHOS::ERR_OK);
3431
3432 auto resultDeleteAppInstallAppControlDisallow = DelayedSingleton<AppControlManager>::GetInstance()->
3433 DeleteAppInstallControlRule(AppControlConstants::EDM_CALLING,
3434 AppControlConstants::APP_DISALLOWED_INSTALL, appIds, userId);
3435 EXPECT_EQ(resultDeleteAppInstallAppControlDisallow, OHOS::ERR_OK);
3436 }
3437
3438 /**
3439 * @tc.number: baseBundleInstaller_4700
3440 * @tc.name: test InstallNormalAppControl
3441 * @tc.desc: 1.Test the InstallNormalAppControl of BaseBundleInstaller
3442 */
3443 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_4700, Function | SmallTest | Level0)
3444 {
3445 std::string installAppId = APPID;
3446 BaseBundleInstaller installer;
3447 int32_t userId = Constants::DEFAULT_USERID;
3448 std::vector<std::string> appIds;
3449 std::vector<std::string> appIdsAllow;
3450 appIds.emplace_back(APPID);
3451 appIdsAllow.emplace_back(SYSTEMFIEID_NAME);
3452 seteuid(EDM_UID);
3453 auto resultAddAppInstallAppControlAllow = DelayedSingleton<AppControlManager>::GetInstance()->
3454 AddAppInstallControlRule(AppControlConstants::EDM_CALLING,
3455 appIdsAllow, AppControlConstants::APP_ALLOWED_INSTALL, userId);
3456 EXPECT_EQ(resultAddAppInstallAppControlAllow, OHOS::ERR_OK);
3457
3458 auto resultAddAppInstallAppControlDisallow = DelayedSingleton<AppControlManager>::GetInstance()->
3459 AddAppInstallControlRule(AppControlConstants::EDM_CALLING,
3460 appIds, AppControlConstants::APP_DISALLOWED_INSTALL, userId);
3461 EXPECT_EQ(resultAddAppInstallAppControlDisallow, OHOS::ERR_OK);
3462
3463 auto ret = installer.InstallNormalAppControl(installAppId, userId);
3464 EXPECT_EQ(ret, OHOS::ERR_BUNDLE_MANAGER_APP_CONTROL_DISALLOWED_INSTALL);
3465
3466 auto resultDeleteAppInstallAppControlAllow = DelayedSingleton<AppControlManager>::GetInstance()->
3467 DeleteAppInstallControlRule(AppControlConstants::EDM_CALLING,
3468 AppControlConstants::APP_ALLOWED_INSTALL, appIdsAllow, userId);
3469 EXPECT_EQ(resultDeleteAppInstallAppControlAllow, OHOS::ERR_OK);
3470
3471 auto resultDeleteAppInstallAppControlDisallow = DelayedSingleton<AppControlManager>::GetInstance()->
3472 DeleteAppInstallControlRule(AppControlConstants::EDM_CALLING,
3473 AppControlConstants::APP_DISALLOWED_INSTALL, appIds, userId);
3474 EXPECT_EQ(resultDeleteAppInstallAppControlDisallow, OHOS::ERR_OK);
3475 }
3476
3477 /**
3478 * @tc.number: baseBundleInstaller_4800
3479 * @tc.name: test InstallNormalAppControl
3480 * @tc.desc: 1.Test the InstallNormalAppControl of BaseBundleInstaller
3481 */
3482 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_4800, Function | SmallTest | Level0)
3483 {
3484 std::string installAppId = APPID;
3485 BaseBundleInstaller installer;
3486 int32_t userId = Constants::DEFAULT_USERID;
3487 std::vector<std::string> appIds;
3488 std::vector<std::string> appIdsAllow;
3489 appIds.emplace_back(APPID);
3490 appIdsAllow.emplace_back(SYSTEMFIEID_NAME);
3491 seteuid(EDM_UID);
3492 auto resultAddAppInstallAppControlAllow = DelayedSingleton<AppControlManager>::GetInstance()->
3493 AddAppInstallControlRule(AppControlConstants::EDM_CALLING,
3494 appIds, AppControlConstants::APP_ALLOWED_INSTALL, userId);
3495 EXPECT_EQ(resultAddAppInstallAppControlAllow, OHOS::ERR_OK);
3496
3497 auto resultAddAppInstallAppControlDisallow = DelayedSingleton<AppControlManager>::GetInstance()->
3498 AddAppInstallControlRule(AppControlConstants::EDM_CALLING,
3499 appIdsAllow, AppControlConstants::APP_DISALLOWED_INSTALL, userId);
3500 EXPECT_EQ(resultAddAppInstallAppControlDisallow, OHOS::ERR_OK);
3501
3502 auto ret = installer.InstallNormalAppControl(installAppId, userId);
3503 EXPECT_EQ(ret, OHOS::ERR_OK);
3504
3505 auto resultDeleteAppInstallAppControlAllow = DelayedSingleton<AppControlManager>::GetInstance()->
3506 DeleteAppInstallControlRule(AppControlConstants::EDM_CALLING,
3507 AppControlConstants::APP_ALLOWED_INSTALL, appIds, userId);
3508 EXPECT_EQ(resultDeleteAppInstallAppControlAllow, OHOS::ERR_OK);
3509
3510 auto resultDeleteAppInstallAppControlDisallow = DelayedSingleton<AppControlManager>::GetInstance()->
3511 DeleteAppInstallControlRule(AppControlConstants::EDM_CALLING,
3512 AppControlConstants::APP_DISALLOWED_INSTALL, appIdsAllow, userId);
3513 EXPECT_EQ(resultDeleteAppInstallAppControlDisallow, OHOS::ERR_OK);
3514 }
3515
3516 /**
3517 * @tc.number: baseBundleInstaller_4900
3518 * @tc.name: test InstallNormalAppControl
3519 * @tc.desc: 1.Test the InstallNormalAppControl of BaseBundleInstaller
3520 */
3521 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_4900, Function | SmallTest | Level0)
3522 {
3523 std::string installAppId = APPID;
3524 BaseBundleInstaller installer;
3525 int32_t userId = Constants::DEFAULT_USERID;
3526 std::vector<std::string> appIds;
3527 std::vector<std::string> appIdsAllow;
3528 appIds.emplace_back(SYSTEMFIEID_NAME);
3529 seteuid(EDM_UID);
3530 auto resultAddAppInstallAppControlAllow = DelayedSingleton<AppControlManager>::GetInstance()->
3531 AddAppInstallControlRule(AppControlConstants::EDM_CALLING,
3532 appIds, AppControlConstants::APP_ALLOWED_INSTALL, userId);
3533 EXPECT_EQ(resultAddAppInstallAppControlAllow, OHOS::ERR_OK);
3534
3535 auto resultAddAppInstallAppControlDisallow = DelayedSingleton<AppControlManager>::GetInstance()->
3536 AddAppInstallControlRule(AppControlConstants::EDM_CALLING,
3537 appIds, AppControlConstants::APP_DISALLOWED_INSTALL, userId);
3538 EXPECT_EQ(resultAddAppInstallAppControlDisallow, OHOS::ERR_OK);
3539
3540 auto ret = installer.InstallNormalAppControl(installAppId, userId);
3541 EXPECT_EQ(ret, OHOS::ERR_BUNDLE_MANAGER_APP_CONTROL_DISALLOWED_INSTALL);
3542
3543 auto resultDeleteAppInstallAppControlAllow = DelayedSingleton<AppControlManager>::GetInstance()->
3544 DeleteAppInstallControlRule(AppControlConstants::EDM_CALLING,
3545 AppControlConstants::APP_ALLOWED_INSTALL, appIds, userId);
3546 EXPECT_EQ(resultDeleteAppInstallAppControlAllow, OHOS::ERR_OK);
3547
3548 auto resultDeleteAppInstallAppControlDisallow = DelayedSingleton<AppControlManager>::GetInstance()->
3549 DeleteAppInstallControlRule(AppControlConstants::EDM_CALLING,
3550 AppControlConstants::APP_DISALLOWED_INSTALL, appIds, userId);
3551 EXPECT_EQ(resultDeleteAppInstallAppControlDisallow, OHOS::ERR_OK);
3552 }
3553
3554 /**
3555 * @tc.number: baseBundleInstaller_5000
3556 * @tc.name: test ProcessBundleInstall
3557 * @tc.desc: 1.Test the ProcessBundleInstall of BaseBundleInstaller
3558 */
3559 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_5000, Function | SmallTest | Level0)
3560 {
3561 BaseBundleInstaller installer;
3562 std::vector<std::string> inBundlePaths;
3563 auto bundleFile = RESOURCE_ROOT_PATH + FIRST_RIGHT_HAP;
3564 inBundlePaths.emplace_back(bundleFile);
3565 InstallParam installParam;
3566 installParam.isPreInstallApp = false;
3567 auto appType = Constants::AppType::THIRD_PARTY_APP;
3568 int32_t uid = 0;
3569 ErrCode ret = installer.ProcessBundleInstall(
3570 inBundlePaths, installParam, appType, uid);
3571 EXPECT_EQ(ret, ERR_OK);
3572 ClearBundleInfo();
3573 }
3574
3575 /**
3576 * @tc.number: baseBundleInstaller_5100
3577 * @tc.name: test InnerProcessInstallByPreInstallInfo
3578 * @tc.desc: 1.Test the InnerProcessInstallByPreInstallInfo of BaseBundleInstaller
3579 */
3580 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_5100, Function | SmallTest | Level0)
3581 {
3582 DelayedSingleton<BundleMgrService>::GetInstance()->dataMgr_ = std::make_shared<BundleDataMgr>();
3583 BaseBundleInstaller installer;
3584 installer.dataMgr_ = DelayedSingleton<BundleMgrService>::GetInstance()->GetDataMgr();
3585 installer.dataMgr_->AddUserId(100);
3586 InstallParam installParam;
3587 installParam.isPreInstallApp = false;
3588 installParam.userId = 100;
3589 installer.userId_ = 100;
3590 int32_t uid = 100;
3591 bool recoverMode = true;
3592 auto ret = installer.InnerProcessInstallByPreInstallInfo(BUNDLE_MODULEJSON_TEST, installParam, uid, recoverMode);
3593 EXPECT_EQ(ret, ERR_APPEXECFWK_RECOVER_INVALID_BUNDLE_NAME);
3594 ClearBundleInfo();
3595 }
3596
3597 /**
3598 * @tc.number: baseBundleInstaller_5200
3599 * @tc.name: test InnerProcessInstallByPreInstallInfo
3600 * @tc.desc: 1.Test the InnerProcessInstallByPreInstallInfo of BaseBundleInstaller
3601 */
3602 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_5200, Function | SmallTest | Level0)
3603 {
3604 BaseBundleInstaller installer;
3605 UninstallParam uninstallParam;
3606 uninstallParam.bundleName = "";
3607 auto ret = installer.UninstallBundleByUninstallParam(uninstallParam);
3608 EXPECT_EQ(ret, ERR_APPEXECFWK_UNINSTALL_SHARE_APP_LIBRARY_IS_NOT_EXIST);
3609 }
3610
3611 /**
3612 * @tc.number: baseBundleInstaller_5300
3613 * @tc.name: test InnerProcessInstallByPreInstallInfo
3614 * @tc.desc: 1.Test the InnerProcessInstallByPreInstallInfo of BaseBundleInstaller
3615 */
3616 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_5300, Function | SmallTest | Level0)
3617 {
3618 BaseBundleInstaller installer;
3619 UninstallParam uninstallParam;
3620 uninstallParam.bundleName = BUNDLE_NAME;
3621 ClearDataMgr();
3622 auto ret = installer.UninstallBundleByUninstallParam(uninstallParam);
3623 EXPECT_EQ(ret, ERR_APPEXECFWK_UNINSTALL_BUNDLE_MGR_SERVICE_ERROR);
3624 ResetDataMgr();
3625 }
3626
3627 /**
3628 * @tc.number: appControlManagerHostImpl_0100
3629 * @tc.name: test GetControlRuleType
3630 * @tc.desc: 1.Test the GetControlRuleType of AppControlManagerHostImpl
3631 */
3632 HWTEST_F(BmsBundleInstallerTest, appControlManagerHostImpl_0100, Function | SmallTest | Level0)
3633 {
3634 AppControlManagerHostImpl impl;
3635 auto ret = impl.GetControlRuleType(AppInstallControlRuleType::DISALLOWED_UNINSTALL);
3636 EXPECT_EQ(ret, AppControlConstants::APP_DISALLOWED_UNINSTALL);
3637 }
3638
3639 /**
3640 * @tc.number: appControlManagerHostImpl_0200
3641 * @tc.name: test GetControlRuleType
3642 * @tc.desc: 1.Test the GetControlRuleType of AppControlManagerHostImpl
3643 */
3644 HWTEST_F(BmsBundleInstallerTest, appControlManagerHostImpl_0200, Function | SmallTest | Level0)
3645 {
3646 AppControlManagerHostImpl impl;
3647 auto ret = impl.GetControlRuleType(AppInstallControlRuleType::UNSPECIFIED);
3648 EXPECT_EQ(ret, EMPTY_STRING);
3649 }
3650 #endif
3651
3652 /**
3653 * @tc.number: baseBundleInstaller_5400
3654 * @tc.name: test checkAsanEnabled when asanEnabled is set to be ture
3655 * @tc.desc: 1.Test checkAsanEnabled
3656 */
3657 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_5400, Function | SmallTest | Level0)
3658 {
3659 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
3660 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
3661 EXPECT_EQ(installResult, ERR_OK);
3662
3663 BaseBundleInstaller installer;
3664 InstallParam installParam;
3665 installParam.userId = USERID;
3666 installParam.installFlag = InstallFlag::REPLACE_EXISTING;
3667 int32_t uid = USERID;
3668
3669 auto dataMgr = GetBundleDataMgr();
3670 EXPECT_NE(dataMgr, nullptr);
3671 bool ret = GetBundleDataMgr()->UpdateBundleInstallState(BUNDLE_BACKUP_NAME, InstallState::UNINSTALL_START);
3672 EXPECT_EQ(ret, true);
3673
3674 auto res = installer.ProcessBundleUninstall(BUNDLE_BACKUP_NAME, installParam, uid);
3675 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_BUNDLE_MGR_SERVICE_ERROR);
3676
3677 UnInstallBundle(BUNDLE_BACKUP_NAME);
3678
3679 ret = GetBundleDataMgr()->UpdateBundleInstallState(BUNDLE_BACKUP_NAME, InstallState::UNINSTALL_SUCCESS);
3680 EXPECT_EQ(ret, true);
3681 }
3682
3683 /**
3684 * @tc.number: baseBundleInstaller_5500
3685 * @tc.name: test ProcessBundleUninstall
3686 * @tc.desc: 1.Test ProcessBundleUninstall
3687 */
3688 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_5500, Function | SmallTest | Level0)
3689 {
3690 BaseBundleInstaller installer;
3691 InstallParam installParam;
3692 installParam.userId = 999;
3693 installParam.installFlag = InstallFlag::NORMAL;
3694 int32_t uid = USERID;
3695
3696 auto res = installer.ProcessBundleUninstall(BUNDLE_BACKUP_NAME, TEST_PACK_AGE, installParam, uid);
3697 EXPECT_EQ(res, ERR_APPEXECFWK_USER_NOT_EXIST);
3698 }
3699
3700 /**
3701 * @tc.number: baseBundleInstaller_5600
3702 * @tc.name: test ProcessBundleUninstall
3703 * @tc.desc: 1.Test ProcessBundleUninstall
3704 */
3705 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_5600, Function | SmallTest | Level0)
3706 {
3707 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
3708 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
3709 EXPECT_EQ(installResult, ERR_OK);
3710
3711 BaseBundleInstaller installer;
3712 InstallParam installParam;
3713 installParam.userId = USERID;
3714 installParam.installFlag = InstallFlag::NORMAL;
3715 int32_t uid = USERID;
3716
3717 auto res = installer.ProcessBundleUninstall(BUNDLE_BACKUP_NAME, WRONG_BUNDLE_NAME, installParam, uid);
3718 EXPECT_EQ(res, ERR_APPEXECFWK_UNINSTALL_MISSING_INSTALLED_MODULE);
3719
3720 UnInstallBundle(BUNDLE_BACKUP_NAME);
3721 }
3722
3723 /**
3724 * @tc.number: baseBundleInstaller_5700
3725 * @tc.name: test ProcessBundleUninstall
3726 * @tc.desc: 1.Test ProcessBundleUninstall
3727 */
3728 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_5700, Function | SmallTest | Level0)
3729 {
3730 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
3731 ErrCode installResult = InstallThirdPartyBundle(bundlePath);
3732 EXPECT_EQ(installResult, ERR_OK);
3733
3734 BaseBundleInstaller installer;
3735 InstallParam installParam;
3736 installParam.userId = USERID;
3737 installParam.installFlag = InstallFlag::REPLACE_EXISTING;
3738 int32_t uid = USERID;
3739
3740 auto dataMgr = GetBundleDataMgr();
3741 EXPECT_NE(dataMgr, nullptr);
3742 bool ret = GetBundleDataMgr()->UpdateBundleInstallState(BUNDLE_BACKUP_NAME, InstallState::UNINSTALL_START);
3743 EXPECT_EQ(ret, true);
3744
3745 auto res = installer.ProcessBundleUninstall(BUNDLE_BACKUP_NAME, TEST_PACK_AGE, installParam, uid);
3746 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_BUNDLE_MGR_SERVICE_ERROR);
3747
3748 UnInstallBundle(BUNDLE_BACKUP_NAME);
3749
3750 ret = GetBundleDataMgr()->UpdateBundleInstallState(BUNDLE_BACKUP_NAME, InstallState::UNINSTALL_SUCCESS);
3751 EXPECT_EQ(ret, true);
3752 }
3753
3754 #ifdef BUNDLE_FRAMEWORK_QUICK_FIX
3755
3756 /**
3757 * @tc.number: baseBundleInstaller_5800
3758 * @tc.name: test UpdateLibAttrs
3759 * @tc.desc: 1.Test the UpdateLibAttrs of BaseBundleInstaller
3760 */
3761 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_5800, Function | SmallTest | Level0)
3762 {
3763 BaseBundleInstaller installer;
3764 InnerBundleInfo newInfo;
3765 newInfo.SetCurrentModulePackage(MODULE_NAME_TEST);
3766 InnerModuleInfo innerModuleInfo;
3767 innerModuleInfo.moduleName = MODULE_NAME_TEST;
3768 innerModuleInfo.isLibIsolated = true;
3769 newInfo.innerModuleInfos_.insert(
3770 std::pair<std::string, InnerModuleInfo>(MODULE_NAME_TEST, innerModuleInfo));
3771 AppqfInfo appQfInfo;
3772 auto ret = installer.UpdateLibAttrs(newInfo, TEST_CPU_ABI, BUNDLE_LIBRARY_PATH_DIR, appQfInfo);
3773 EXPECT_EQ(ret, ERR_BUNDLEMANAGER_QUICK_FIX_MODULE_NAME_NOT_EXIST);
3774 }
3775
3776 /**
3777 * @tc.number: baseBundleInstaller_5900
3778 * @tc.name: test UpdateLibAttrs
3779 * @tc.desc: 1.Test the UpdateLibAttrs of BaseBundleInstaller
3780 */
3781 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_5900, Function | SmallTest | Level0)
3782 {
3783 BaseBundleInstaller installer;
3784 InnerBundleInfo newInfo;
3785 newInfo.SetCurrentModulePackage(MODULE_NAME_TEST);
3786 InnerModuleInfo innerModuleInfo;
3787 innerModuleInfo.moduleName = MODULE_NAME_TEST;
3788 innerModuleInfo.isLibIsolated = false;
3789 AppqfInfo appQfInfo;
3790 auto ret = installer.UpdateLibAttrs(newInfo, TEST_CPU_ABI, BUNDLE_LIBRARY_PATH_DIR, appQfInfo);
3791 EXPECT_EQ(ret, ERR_OK);
3792 }
3793
3794 /**
3795 * @tc.number: baseBundleInstaller_6000
3796 * @tc.name: test UpdateLibAttrs
3797 * @tc.desc: 1.Test the UpdateLibAttrs of BaseBundleInstaller
3798 */
3799 HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_6000, Function | SmallTest | Level0)
3800 {
3801 BaseBundleInstaller installer;
3802 InnerBundleInfo newInfo;
3803 newInfo.SetCurrentModulePackage(MODULE_NAME_TEST);
3804 InnerModuleInfo innerModuleInfo;
3805 innerModuleInfo.moduleName = MODULE_NAME_TEST;
3806 innerModuleInfo.isLibIsolated = true;
3807 newInfo.innerModuleInfos_.insert(
3808 std::pair<std::string, InnerModuleInfo>(MODULE_NAME_TEST, innerModuleInfo));
3809 AppqfInfo appQfInfo;
3810 std::vector<HqfInfo> hqfInfos;
3811 HqfInfo info;
3812 info.moduleName = MODULE_NAME;
3813 hqfInfos.emplace_back(info);
3814 info.moduleName = MODULE_NAME_TEST;
3815 info.nativeLibraryPath = BUNDLE_LIBRARY_PATH_DIR;
3816 info.cpuAbi = TEST_CPU_ABI;
3817 hqfInfos.emplace_back(info);
3818 appQfInfo.hqfInfos = hqfInfos;
3819 auto ret = installer.UpdateLibAttrs(newInfo, TEST_CPU_ABI, BUNDLE_LIBRARY_PATH_DIR, appQfInfo);
3820 EXPECT_EQ(ret, ERR_OK);
3821 }
3822
3823 #endif
3824
3825 /**
3826 * @tc.number: ParseFiles_0100
3827 * @tc.name: test the start function of ParseFiles
3828 * @tc.desc: 1.Test ParseFiles
3829 */
3830 HWTEST_F(BmsBundleInstallerTest, ParseFiles_0100, Function | SmallTest | Level0)
3831 {
3832 InstallParam installParam;
3833 auto appType = Constants::AppType::THIRD_PARTY_APP;
3834 SharedBundleInstaller installer(installParam, appType);
3835 installer.installParam_.sharedBundleDirPaths.clear();
3836 auto res = installer.ParseFiles();
3837 EXPECT_EQ(res, ERR_OK);
3838 }
3839
3840 /**
3841 * @tc.number: CheckDependency_0100
3842 * @tc.name: test the start function of CheckDependency
3843 * @tc.desc: 1.Test CheckDependency
3844 */
3845 HWTEST_F(BmsBundleInstallerTest, CheckDependency_0100, Function | SmallTest | Level0)
3846 {
3847 InstallParam installParam;
3848 auto appType = Constants::AppType::THIRD_PARTY_APP;
3849 SharedBundleInstaller installer(installParam, appType);
3850 Dependency dependency;
3851 dependency.bundleName = "";
3852 InnerModuleInfo innerModuleInfo;
3853 innerModuleInfo.dependencies.push_back(dependency);
3854 InnerBundleInfo innerBundleInfo;
3855 innerBundleInfo.baseApplicationInfo_->bundleName = "";
3856 innerBundleInfo.innerModuleInfos_.insert(pair<std::string, InnerModuleInfo>("1", innerModuleInfo));
3857 auto res = installer.CheckDependency(innerBundleInfo);
3858 EXPECT_TRUE(res);
3859
3860 innerBundleInfo.baseApplicationInfo_->bundleName = BUNDLE_NAME;
3861 res = installer.CheckDependency(innerBundleInfo);
3862 EXPECT_TRUE(res);
3863
3864 Dependency dependency1;
3865 dependency1.bundleName = BUNDLE_NAME;
3866 InnerModuleInfo innerModuleInfo1;
3867 innerModuleInfo1.dependencies.push_back(dependency1);
3868 innerBundleInfo.innerModuleInfos_.insert(pair<std::string, InnerModuleInfo>("2", innerModuleInfo1));
3869 res = installer.CheckDependency(innerBundleInfo);
3870 EXPECT_TRUE(res);
3871
3872 innerBundleInfo.baseApplicationInfo_->bundleName = WRONG_BUNDLE_NAME;
3873 res = installer.CheckDependency(innerBundleInfo);
3874 EXPECT_FALSE(res);
3875 }
3876
3877 /**
3878 * @tc.number: CheckDependency_0100
3879 * @tc.name: test the start function of CheckDependency
3880 * @tc.desc: 1.Test CheckDependency
3881 */
3882 HWTEST_F(BmsBundleInstallerTest, CheckDependency_0200, Function | SmallTest | Level0)
3883 {
3884 InstallParam installParam;
3885 auto appType = Constants::AppType::THIRD_PARTY_APP;
3886 SharedBundleInstaller installer(installParam, appType);
3887 Dependency dependency;
3888 dependency.bundleName = BUNDLE_NAME;
3889 InnerModuleInfo innerModuleInfo;
3890 innerModuleInfo.dependencies.push_back(dependency);
3891 InnerBundleInfo innerBundleInfo;
3892 innerBundleInfo.baseApplicationInfo_->bundleName = WRONG_BUNDLE_NAME;
3893 innerBundleInfo.innerModuleInfos_.insert(pair<std::string, InnerModuleInfo>("1", innerModuleInfo));
3894 std::string path = BUNDLE_DATA_DIR;
3895 std::shared_ptr<InnerSharedBundleInstaller> innerSharedBundleInstaller =
3896 std::make_shared<InnerSharedBundleInstaller>(path);
3897 innerSharedBundleInstaller->bundleName_ = WRONG_BUNDLE_NAME;
3898 installer.innerInstallers_.insert(pair<std::string,
3899 std::shared_ptr<InnerSharedBundleInstaller>>(WRONG_BUNDLE_NAME, innerSharedBundleInstaller));
3900 auto res = installer.CheckDependency(innerBundleInfo);
3901 EXPECT_FALSE(res);
3902 }
3903
3904 /**
3905 * @tc.number: GetNativeLibraryFileNames_0001
3906 * @tc.name: test GetNativeLibraryFileNames
3907 * @tc.desc: 1.Test the GetNativeLibraryFileNames of InstalldHostImpl
3908 */
3909 HWTEST_F(BmsBundleInstallerTest, GetNativeLibraryFileNames_0001, Function | SmallTest | Level0)
3910 {
3911 InstalldHostImpl impl;
3912 std::vector<std::string> fileNames;
3913 auto ret = impl.GetNativeLibraryFileNames("", "", fileNames);
3914 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
3915
3916 ret = impl.GetNativeLibraryFileNames("/data/test/xxx.hap", "libs/arm", fileNames);
3917 EXPECT_EQ(ret, ERR_OK);
3918 EXPECT_TRUE(fileNames.empty());
3919 }
3920
3921 /**
3922 * @tc.number: BmsBundleInstallerTest_0010
3923 * @tc.name: InnerProcessNativeLibs
3924 * @tc.desc: test InnerProcessNativeLibs isLibIsolated false
3925 */
3926 HWTEST_F(BmsBundleInstallerTest, BmsBundleInstallerTest_0010, TestSize.Level1)
3927 {
3928 InnerBundleInfo info;
3929 info.currentPackage_ = MODULE_NAME_TEST;
3930 InnerModuleInfo moduleInfo;
3931 moduleInfo.name = MODULE_NAME_TEST;
3932 moduleInfo.moduleName = MODULE_NAME_TEST;
3933 moduleInfo.modulePackage = MODULE_NAME_TEST;
3934 moduleInfo.isLibIsolated = false;
3935 moduleInfo.compressNativeLibs = true;
3936 info.innerModuleInfos_[MODULE_NAME_TEST] = moduleInfo;
3937 info.baseApplicationInfo_->cpuAbi = "";
3938 info.baseApplicationInfo_->nativeLibraryPath = "";
3939
3940 BaseBundleInstaller installer;
3941 installer.modulePackage_ = MODULE_NAME_TEST;
3942 installer.modulePath_ = "";
3943 std::string modulePath = "";
3944 // nativeLibraryPath empty, compressNativeLibs true
3945 ErrCode ret = installer.InnerProcessNativeLibs(info, modulePath);
3946 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
3947
3948 info.innerModuleInfos_[MODULE_NAME_TEST].compressNativeLibs = false;
3949 // nativeLibraryPath empty, compressNativeLibs false
3950 ret = installer.InnerProcessNativeLibs(info, modulePath);
3951 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
3952
3953 // nativeLibraryPath not empty, compressNativeLibs true
3954 info.baseApplicationInfo_->cpuAbi = "libs/arm";
3955 info.baseApplicationInfo_->nativeLibraryPath = "libs/arm";
3956 modulePath = "package_tmp";
3957 info.innerModuleInfos_[MODULE_NAME_TEST].compressNativeLibs = true;
3958 ret = installer.InnerProcessNativeLibs(info, modulePath);
3959 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
3960
3961 // nativeLibraryPath not empty, compressNativeLibs false
3962 info.innerModuleInfos_[MODULE_NAME_TEST].compressNativeLibs = false;
3963 ret = installer.InnerProcessNativeLibs(info, modulePath);
3964 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
3965
3966 modulePath = "/data/test/bms_bundle_installer";
3967 installer.modulePath_ = RESOURCE_ROOT_PATH + RIGHT_BUNDLE;
3968 ret = installer.InnerProcessNativeLibs(info, modulePath);
3969 EXPECT_EQ(ret, ERR_OK);
3970 }
3971
3972 /**
3973 * @tc.number: BmsBundleInstallerTest_0020
3974 * @tc.name: InnerProcessNativeLibs
3975 * @tc.desc: test InnerProcessNativeLibs isLibIsolated true
3976 */
3977 HWTEST_F(BmsBundleInstallerTest, BmsBundleInstallerTest_0020, TestSize.Level1)
3978 {
3979 InnerBundleInfo info;
3980 info.currentPackage_ = MODULE_NAME_TEST;
3981 InnerModuleInfo moduleInfo;
3982 moduleInfo.name = MODULE_NAME_TEST;
3983 moduleInfo.moduleName = MODULE_NAME_TEST;
3984 moduleInfo.modulePackage = MODULE_NAME_TEST;
3985 moduleInfo.cpuAbi = "libs/arm";
3986 moduleInfo.nativeLibraryPath = "libs/arm";
3987 moduleInfo.isLibIsolated = true;
3988 moduleInfo.compressNativeLibs = true;
3989 info.innerModuleInfos_[MODULE_NAME_TEST] = moduleInfo;
3990 info.baseApplicationInfo_->cpuAbi = "";
3991 info.baseApplicationInfo_->nativeLibraryPath = "";
3992
3993 BaseBundleInstaller installer;
3994 installer.modulePackage_ = MODULE_NAME_TEST;
3995 installer.modulePath_ = "";
3996 std::string modulePath = "";
3997 // nativeLibraryPath empty, compressNativeLibs true
3998 ErrCode ret = installer.InnerProcessNativeLibs(info, modulePath);
3999 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
4000
4001 modulePath = "package_tmp";
4002 ret = installer.InnerProcessNativeLibs(info, modulePath);
4003 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
4004 modulePath = "/data/test/bms_bundle_installer";
4005 installer.modulePath_ = RESOURCE_ROOT_PATH + RIGHT_BUNDLE;
4006 ret = installer.InnerProcessNativeLibs(info, modulePath);
4007 EXPECT_EQ(ret, ERR_OK);
4008 }
4009
4010 /**
4011 * @tc.number: BmsBundleInstallerTest_0030
4012 * @tc.name: ExtractSoFiles
4013 * @tc.desc: test ExtractSoFiles
4014 */
4015 HWTEST_F(BmsBundleInstallerTest, BmsBundleInstallerTest_0030, TestSize.Level1)
4016 {
4017 BaseBundleInstaller installer;
4018 auto ret = installer.ExtractSoFiles("/data/test", "libs/arm");
4019 EXPECT_FALSE(ret);
4020
4021 installer.modulePath_ = RESOURCE_ROOT_PATH + RIGHT_BUNDLE;
4022 ret = installer.ExtractSoFiles("/data/test", "libs/arm");
4023 EXPECT_TRUE(ret);
4024 }
4025
4026 /**
4027 * @tc.number: ProcessOldNativeLibraryPath_0010
4028 * @tc.name: ExtractSoFiles
4029 * @tc.desc: test ProcessOldNativeLibraryPath
4030 */
4031 HWTEST_F(BmsBundleInstallerTest, ProcessOldNativeLibraryPath_0010, TestSize.Level1)
4032 {
4033 bool ret = OHOS::ForceCreateDirectory(BUNDLE_LIBRARY_PATH_DIR);
4034 EXPECT_TRUE(ret);
4035
4036 BaseBundleInstaller installer;
4037 installer.bundleName_ = BUNDLE_NAME;
4038 std::unordered_map<std::string, InnerBundleInfo> newInfos;
4039 int32_t oldVersionCode = 1000;
4040 std::string nativeLibraryPath = "";
4041 installer.ProcessOldNativeLibraryPath(newInfos, oldVersionCode, nativeLibraryPath);
4042 auto exist = access(BUNDLE_LIBRARY_PATH_DIR.c_str(), F_OK);
4043 EXPECT_EQ(exist, 0);
4044
4045 nativeLibraryPath = "libs/arm";
4046 installer.ProcessOldNativeLibraryPath(newInfos, oldVersionCode, nativeLibraryPath);
4047 exist = access(BUNDLE_LIBRARY_PATH_DIR.c_str(), F_OK);
4048 EXPECT_EQ(exist, 0);
4049
4050 installer.versionCode_ = 2000;
4051 nativeLibraryPath = "";
4052 installer.ProcessOldNativeLibraryPath(newInfos, oldVersionCode, nativeLibraryPath);
4053 exist = access(BUNDLE_LIBRARY_PATH_DIR.c_str(), F_OK);
4054 EXPECT_EQ(exist, 0);
4055
4056 nativeLibraryPath = "libs/arm";
4057 InnerBundleInfo innerBundleInfo;
4058 InnerModuleInfo moduleInfo;
4059 moduleInfo.compressNativeLibs = true;
4060 innerBundleInfo.innerModuleInfos_["aaa"] = moduleInfo;
4061 moduleInfo.compressNativeLibs = false;
4062 innerBundleInfo.innerModuleInfos_["bbb"] = moduleInfo;
4063 newInfos["a"] = innerBundleInfo;
4064 installer.ProcessOldNativeLibraryPath(newInfos, oldVersionCode, nativeLibraryPath);
4065 exist = access(BUNDLE_LIBRARY_PATH_DIR.c_str(), F_OK);
4066 EXPECT_EQ(exist, 0);
4067
4068 moduleInfo.compressNativeLibs = false;
4069 innerBundleInfo.innerModuleInfos_["aaa"] = moduleInfo;
4070 newInfos["a"] = innerBundleInfo;
4071
4072 installer.ProcessOldNativeLibraryPath(newInfos, oldVersionCode, nativeLibraryPath);
4073 exist = access(BUNDLE_LIBRARY_PATH_DIR.c_str(), F_OK);
4074 EXPECT_NE(exist, 0);
4075 }
4076
4077 /**
4078 * @tc.number: UninstallHspVersion_0010
4079 * @tc.name: UninstallHspVersion
4080 * @tc.desc: test UninstallHspVersion
4081 */
4082 HWTEST_F(BmsBundleInstallerTest, UninstallHspVersion_0010, TestSize.Level1)
4083 {
4084 BaseBundleInstaller installer;
4085 int32_t versionCode = 9;
4086 InnerBundleInfo info;
4087 std::string uninstallDir;
4088 auto ret = installer.UninstallHspVersion(uninstallDir, versionCode, info);
4089 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_BUNDLE_MGR_SERVICE_ERROR);
4090 }
4091
4092 /**
4093 * @tc.number: CheckEnableRemovable_0010
4094 * @tc.name: CheckEnableRemovable
4095 * @tc.desc: test CheckEnableRemovable
4096 */
4097 HWTEST_F(BmsBundleInstallerTest, CheckEnableRemovable_0010, TestSize.Level1)
4098 {
4099 BaseBundleInstaller installer;
4100 InnerBundleInfo newInfo;
4101 std::unordered_map<std::string, InnerBundleInfo> newInfos;
4102 newInfos.emplace("", newInfo);
4103 InnerBundleInfo oldInfo;
4104 bool isFreeInstallFlag = true;
4105 bool isAppExist = false;
4106 int32_t userId = 100;
4107 installer.CheckEnableRemovable(newInfos, oldInfo, userId, isFreeInstallFlag, isAppExist);
4108
4109 bool existModule = oldInfo.FindModule(MODULE_NAME);
4110 EXPECT_EQ(existModule, false);
4111 }
4112
4113 /**
4114 * @tc.number: CheckEnableRemovable_0020
4115 * @tc.name: CheckEnableRemovable
4116 * @tc.desc: test CheckEnableRemovable
4117 */
4118 HWTEST_F(BmsBundleInstallerTest, CheckEnableRemovable_0020, TestSize.Level1)
4119 {
4120 BaseBundleInstaller installer;
4121 InnerBundleInfo newInfo;
4122 std::unordered_map<std::string, InnerBundleInfo> newInfos;
4123 newInfos.emplace("", newInfo);
4124 InnerBundleInfo oldInfo;
4125 bool isFreeInstallFlag = true;
4126 bool isAppExist = false;
4127 int32_t userId = 100;
4128
4129 InnerModuleInfo innerModuleInfo;
4130 innerModuleInfo.name = MODULE_NAME;
4131 innerModuleInfo.modulePackage = MODULE_NAME;
4132 newInfo.InsertInnerModuleInfo(MODULE_NAME, innerModuleInfo);
4133 oldInfo.InsertInnerModuleInfo(MODULE_NAME, innerModuleInfo);
4134
4135 installer.CheckEnableRemovable(newInfos, oldInfo, userId, isFreeInstallFlag, isAppExist);
4136 bool existModule = oldInfo.FindModule(MODULE_NAME);
4137 EXPECT_EQ(existModule, true);
4138 }
4139
4140 /**
4141 * @tc.number: CheckEnableRemovable_0030
4142 * @tc.name: CheckEnableRemovable
4143 * @tc.desc: test CheckEnableRemovable
4144 */
4145 HWTEST_F(BmsBundleInstallerTest, CheckEnableRemovable_0030, TestSize.Level1)
4146 {
4147 BaseBundleInstaller installer;
4148 InnerBundleInfo newInfo;
4149 std::unordered_map<std::string, InnerBundleInfo> newInfos;
4150 newInfos.emplace("", newInfo);
4151 InnerBundleInfo oldInfo;
4152 bool isFreeInstallFlag = true;
4153 bool isAppExist = true;
4154 int32_t userId = 100;
4155
4156 InnerModuleInfo innerModuleInfo;
4157 innerModuleInfo.name = MODULE_NAME;
4158 innerModuleInfo.modulePackage = MODULE_NAME;
4159 newInfo.InsertInnerModuleInfo(MODULE_NAME, innerModuleInfo);
4160 oldInfo.InsertInnerModuleInfo(MODULE_NAME, innerModuleInfo);
4161 installer.CheckEnableRemovable(newInfos, oldInfo, userId, isFreeInstallFlag, isAppExist);
4162
4163 bool existModule = oldInfo.FindModule(MODULE_NAME);
4164 EXPECT_EQ(existModule, true);
4165 }
4166
4167 /**
4168 * @tc.number: CheckEnableRemovable_0040
4169 * @tc.name: CheckEnableRemovable
4170 * @tc.desc: test CheckEnableRemovable
4171 */
4172 HWTEST_F(BmsBundleInstallerTest, CheckEnableRemovable_0040, TestSize.Level1)
4173 {
4174 BaseBundleInstaller installer;
4175 InnerBundleInfo newInfo;
4176 std::unordered_map<std::string, InnerBundleInfo> newInfos;
4177 InnerBundleInfo oldInfo;
4178 int32_t userId = USERID;
4179 installer.CheckEnableRemovable(newInfos, oldInfo, userId, true, true);
4180 bool existModule = oldInfo.FindModule(MODULE_NAME);
4181 EXPECT_EQ(existModule, false);
4182 }
4183
4184 /**
4185 * @tc.number: CheckEnableRemovable_0050
4186 * @tc.name: CheckEnableRemovable
4187 * @tc.desc: test CheckEnableRemovable
4188 */
4189 HWTEST_F(BmsBundleInstallerTest, CheckEnableRemovable_0050, TestSize.Level1)
4190 {
4191 BaseBundleInstaller installer;
4192 InnerBundleInfo newInfo;
4193 std::unordered_map<std::string, InnerBundleInfo> newInfos;
4194 newInfos.emplace("", newInfo);
4195 InnerBundleInfo oldInfo;
4196 InnerBundleUserInfo innerBundleUserInfo;
4197 std::string key = BUNDLE_NAME + "_100";
4198 oldInfo.innerBundleUserInfos_.insert(pair<std::string, InnerBundleUserInfo>(key, innerBundleUserInfo));
4199 int32_t userId = USERID;
4200 InnerModuleInfo innerModuleInfo;
4201 innerModuleInfo.name = MODULE_NAME;
4202 innerModuleInfo.modulePackage = MODULE_NAME;
4203 newInfo.InsertInnerModuleInfo(MODULE_NAME, innerModuleInfo);
4204 oldInfo.InsertInnerModuleInfo(MODULE_NAME, innerModuleInfo);
4205 installer.CheckEnableRemovable(newInfos, oldInfo, userId, true, true);
4206
4207 bool existModule = oldInfo.FindModule(MODULE_NAME);
4208 EXPECT_EQ(existModule, true);
4209 }
4210
4211 /**
4212 * @tc.number: InnerProcessBundleInstall_0010
4213 * @tc.name: CheckEnableRemovable
4214 * @tc.desc: test CheckEnableRemovable
4215 */
4216 HWTEST_F(BmsBundleInstallerTest, InnerProcessBundleInstall_0010, TestSize.Level1)
4217 {
4218 BaseBundleInstaller installer;
4219 std::unordered_map<std::string, InnerBundleInfo> newInfos;
4220 InnerBundleInfo innerBundleInfo;
4221 innerBundleInfo.SetSingleton(false);
4222 newInfos.insert(pair<std::string, InnerBundleInfo>());
4223 InnerBundleInfo oldInfo;
4224 InstallParam installParam;
4225 installParam.needSavePreInstallInfo = false;
4226 int32_t uid = EDM_UID;
4227 installer.isAppExist_ = true;
4228 ClearDataMgr();
4229 auto res = installer.InnerProcessBundleInstall(newInfos, oldInfo, installParam, uid);
4230 installer.RollBack(newInfos, oldInfo);
4231 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_BUNDLE_MGR_SERVICE_ERROR);
4232 ResetDataMgr();
4233 }
4234
4235 /**
4236 * @tc.number: InnerProcessBundleInstall_0020
4237 * @tc.name: CheckEnableRemovable
4238 * @tc.desc: test CheckEnableRemovable
4239 */
4240 HWTEST_F(BmsBundleInstallerTest, InnerProcessBundleInstall_0020, TestSize.Level1)
4241 {
4242 BaseBundleInstaller installer;
4243 std::unordered_map<std::string, InnerBundleInfo> newInfos;
4244 InnerBundleInfo innerBundleInfo;
4245 innerBundleInfo.SetSingleton(false);
4246 newInfos.insert(std::pair<std::string, InnerBundleInfo>(BUNDLE_NAME_TEST, innerBundleInfo));
4247 int32_t uid = EDM_UID;
4248 InnerBundleInfo oldInfo;
4249 InstallParam installParam;
4250 installParam.needSavePreInstallInfo = false;
4251 installer.isAppExist_ = true;
4252 oldInfo.SetApplicationBundleType(BundleType::SHARED);
4253 auto res = installer.InnerProcessBundleInstall(newInfos, oldInfo, installParam, uid);
4254 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_STATE_ERROR);
4255 }
4256
4257 /**
4258 * @tc.number: ProcessModuleUpdate_0010
4259 * @tc.name: test ProcessBundleInstallStatus
4260 * @tc.desc: 1.Test the ProcessBundleInstallStatus
4261 */
4262 HWTEST_F(BmsBundleInstallerTest, ProcessModuleUpdate_0010, Function | SmallTest | Level0)
4263 {
4264 BaseBundleInstaller installer;
4265 InnerBundleInfo innerBundleInfo;
4266 InnerBundleInfo oldInfo;
4267 AbilityInfo info;
4268 bool isReplace = false;
4269 bool noSkipsKill = false;
4270 info.uri = "dataability://";
4271 innerBundleInfo.userId_ = Constants::ALL_USERID;
4272 innerBundleInfo.baseAbilityInfos_.emplace("key", info);
4273 ErrCode res = installer.ProcessModuleUpdate(innerBundleInfo, oldInfo, isReplace, noSkipsKill);
4274 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_URI_DUPLICATE);
4275 }
4276
4277 /**
4278 * @tc.number: ProcessModuleUpdate_0020
4279 * @tc.name: test ProcessBundleInstallStatus
4280 * @tc.desc: 1.Test the ProcessBundleInstallStatus
4281 */
4282 HWTEST_F(BmsBundleInstallerTest, ProcessModuleUpdate_0020, Function | SmallTest | Level0)
4283 {
4284 BaseBundleInstaller installer;
4285 InnerBundleInfo innerBundleInfo;
4286 InnerBundleInfo oldInfo;
4287 bool isReplace = true;
4288 bool noSkipsKill = false;
4289 innerBundleInfo.userId_ = USERID;
4290 ErrCode res = installer.ProcessModuleUpdate(innerBundleInfo, oldInfo, isReplace, noSkipsKill);
4291 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_INCONSISTENT_MODULE_NAME);
4292 }
4293
4294 /**
4295 * @tc.number: CreateBundleDataDir_0010
4296 * @tc.name: test CreateBundleDataDir
4297 * @tc.desc: 1.Test the CreateBundleDataDir
4298 */
4299 HWTEST_F(BmsBundleInstallerTest, CreateBundleDataDir_0010, Function | SmallTest | Level0)
4300 {
4301 BaseBundleInstaller installer;
4302 installer.userId_ = Constants::NOT_EXIST_USERID;
4303 InnerBundleInfo info;
4304 ErrCode res = installer.CreateBundleDataDir(info);
4305 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_GENERATE_UID_ERROR);
4306 }
4307
4308 /**
4309 * @tc.number: CreateBundleDataDir_0020
4310 * @tc.name: test CreateBundleDataDir
4311 * @tc.desc: 1.Test the CreateBundleDataDir
4312 */
4313 HWTEST_F(BmsBundleInstallerTest, CreateBundleDataDir_0020, Function | SmallTest | Level0)
4314 {
4315 InnerBundleInfo info;
4316 BundleInfo bundleInfo;
4317 bundleInfo.name = BUNDLE_NAME_TEST;
4318 bundleInfo.applicationInfo.name = BUNDLE_NAME;
4319 ApplicationInfo applicationInfo;
4320 applicationInfo.name = BUNDLE_NAME_TEST;
4321 applicationInfo.deviceId = DEVICE_ID;
4322 applicationInfo.bundleName = BUNDLE_NAME_TEST;
4323 info.SetBaseBundleInfo(bundleInfo);
4324 info.SetBaseApplicationInfo(applicationInfo);
4325 info.SetAppType(Constants::AppType::SYSTEM_APP);
4326 InnerBundleUserInfo innerBundleUserInfo;
4327 innerBundleUserInfo.bundleUserInfo.userId = 0;
4328 innerBundleUserInfo.bundleName = BUNDLE_NAME_TEST;
4329 auto dataMgr = DelayedSingleton<BundleMgrService>::GetInstance()->GetDataMgr();
4330 ASSERT_NE(dataMgr, nullptr);
4331 dataMgr->installStates_.clear();
4332 dataMgr->bundleInfos_.clear();
4333 bool ret1 = dataMgr->UpdateBundleInstallState(BUNDLE_NAME_TEST, InstallState::INSTALL_START);
4334 bool ret2 = dataMgr->AddInnerBundleInfo(BUNDLE_NAME_TEST, info);
4335 bool ret3 = dataMgr->GenerateUidAndGid(innerBundleUserInfo);
4336 EXPECT_TRUE(ret1);
4337 EXPECT_TRUE(ret2);
4338 EXPECT_TRUE(ret3);
4339
4340 BaseBundleInstaller installer;
4341 installer.userId_ = Constants::NOT_EXIST_USERID;
4342 ErrCode res = installer.CreateBundleDataDir(info);
4343 EXPECT_NE(res, ERR_OK);
4344
4345 ret3 = dataMgr->UpdateBundleInstallState(BUNDLE_NAME_TEST, InstallState::UNINSTALL_START);
4346 EXPECT_TRUE(ret3);
4347 }
4348
4349 /**
4350 * @tc.number: ExtractModule_0010
4351 * @tc.name: test ExtractModule
4352 * @tc.desc: 1.Test the ExtractModule
4353 */
4354 HWTEST_F(BmsBundleInstallerTest, ExtractModule_0010, Function | SmallTest | Level0)
4355 {
4356 InnerBundleInfo info;
4357 info.currentPackage_ = MODULE_NAME_TEST;
4358 InnerModuleInfo moduleInfo;
4359 moduleInfo.name = MODULE_NAME_TEST;
4360 moduleInfo.moduleName = MODULE_NAME_TEST;
4361 moduleInfo.modulePackage = MODULE_NAME_TEST;
4362 moduleInfo.isLibIsolated = false;
4363 moduleInfo.compressNativeLibs = true;
4364 info.innerModuleInfos_[MODULE_NAME_TEST] = moduleInfo;
4365 info.baseApplicationInfo_->cpuAbi = TEST_CPU_ABI;
4366 info.baseApplicationInfo_->nativeLibraryPath = "";
4367
4368 BaseBundleInstaller installer;
4369 installer.modulePackage_ = MODULE_NAME_TEST;
4370 std::string modulePath = "/data/test/bms_bundle_installer";
4371 installer.modulePath_ = RESOURCE_ROOT_PATH + RIGHT_BUNDLE;
4372 ErrCode ret = installer.InnerProcessNativeLibs(info, modulePath);
4373 EXPECT_EQ(ret, ERR_OK);
4374
4375 info.SetIsNewVersion(true);
4376 ErrCode res = installer.ExtractModule(info, modulePath);
4377 EXPECT_EQ(res, ERR_OK);
4378
4379 info.baseApplicationInfo_->arkNativeFilePath = "";
4380 info.baseApplicationInfo_->arkNativeFileAbi = "errorType";
4381 res = installer.ExtractModule(info, modulePath);
4382 EXPECT_EQ(res, ERR_APPEXECFWK_PARSE_AN_FAILED);
4383 }
4384
4385 /**
4386 * @tc.number: RenameModuleDir_0010
4387 * @tc.name: test RenameModuleDir
4388 * @tc.desc: 1.Test the RenameModuleDir
4389 */
4390 HWTEST_F(BmsBundleInstallerTest, RenameModuleDir_0010, Function | SmallTest | Level0)
4391 {
4392 BaseBundleInstaller installer;
4393 InnerBundleInfo info;
4394 info.currentPackage_ = BUNDLE_NAME_TEST;
4395 ErrCode res = installer.RenameModuleDir(info);
4396 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALLD_RNAME_DIR_FAILED);
4397 }
4398
4399 /**
4400 * @tc.number: CheckApiInfo_0010
4401 * @tc.name: test CheckApiInfo
4402 * @tc.desc: 1.Test the CheckApiInfo
4403 */
4404 HWTEST_F(BmsBundleInstallerTest, CheckApiInfo_0010, Function | SmallTest | Level0)
4405 {
4406 BaseBundleInstaller installer;
4407 installer.singletonState_ = AppExecFwk::BaseBundleInstaller::SingletonState::SINGLETON_TO_NON;
4408 bool noSkipsKill = false;
4409 std::unordered_map<std::string, InnerBundleInfo> info;
4410 InnerBundleInfo innerBundleInfo;
4411 innerBundleInfo.baseApplicationInfo_->compileSdkType = "OpenHarmony";
4412 installer.OnSingletonChange(noSkipsKill);
4413 info.try_emplace("OpenHarmony", innerBundleInfo);
4414
4415 bool res = installer.CheckApiInfo(info);
4416 EXPECT_EQ(res, true);
4417 }
4418
4419 /**
4420 * @tc.number: CheckApiInfo_0020
4421 * @tc.name: test CheckApiInfo
4422 * @tc.desc: 1.Test the CheckApiInfo
4423 */
4424 HWTEST_F(BmsBundleInstallerTest, CheckApiInfo_0020, Function | SmallTest | Level0)
4425 {
4426 BaseBundleInstaller installer;
4427 installer.singletonState_ = AppExecFwk::BaseBundleInstaller::SingletonState::NON_TO_SINGLETON;
4428 bool noSkipsKill = false;
4429 std::unordered_map<std::string, InnerBundleInfo> info;
4430 InnerBundleInfo innerBundleInfo;
4431 innerBundleInfo.baseApplicationInfo_->compileSdkType = "OpenHarmony1";
4432 innerBundleInfo.baseBundleInfo_->compatibleVersion = 40000 * 1000 + 10;
4433 installer.OnSingletonChange(noSkipsKill);
4434 info.try_emplace("OpenHarmony2", innerBundleInfo);
4435
4436 bool res = installer.CheckApiInfo(info);
4437 EXPECT_EQ(res, true);
4438 }
4439
4440 /**
4441 * @tc.number: CheckApiInfo_0030
4442 * @tc.name: test CheckApiInfo
4443 * @tc.desc: 1.Test the CheckApiInfo
4444 */
4445 HWTEST_F(BmsBundleInstallerTest, CheckApiInfo_0030, Function | SmallTest | Level0)
4446 {
4447 BaseBundleInstaller installer;
4448 installer.singletonState_ = AppExecFwk::BaseBundleInstaller::SingletonState::NON_TO_SINGLETON;
4449 bool noSkipsKill = false;
4450 std::unordered_map<std::string, InnerBundleInfo> info;
4451 InnerBundleInfo innerBundleInfo;
4452 innerBundleInfo.baseApplicationInfo_->compileSdkType = "OpenHarmony1";
4453 innerBundleInfo.baseBundleInfo_->compatibleVersion = 40000 * 1000 + 100;
4454 installer.OnSingletonChange(noSkipsKill);
4455 info.try_emplace("OpenHarmony2", innerBundleInfo);
4456
4457 bool res = installer.CheckApiInfo(info);
4458 EXPECT_EQ(res, false);
4459 }
4460
4461 /**
4462 * @tc.number: UninstallLowerVersionFeature_0010
4463 * @tc.name: test UninstallLowerVersionFeature
4464 * @tc.desc: 1.Test the UninstallLowerVersionFeature
4465 */
4466 HWTEST_F(BmsBundleInstallerTest, UninstallLowerVersionFeature_0010, Function | SmallTest | Level0)
4467 {
4468 BaseBundleInstaller installer;
4469 std::vector<std::string> packageVec;
4470 ClearDataMgr();
__anon02b290760202null4471 ScopeGuard stateGuard([&] { ResetDataMgr(); });
4472 ErrCode res = installer.UninstallLowerVersionFeature(packageVec);
4473 EXPECT_EQ(res, ERR_APPEXECFWK_UNINSTALL_BUNDLE_MGR_SERVICE_ERROR);
4474 }
4475
4476 /**
4477 * @tc.number: UninstallLowerVersionFeature_0020
4478 * @tc.name: test UninstallLowerVersionFeature
4479 * @tc.desc: 1.Test the UninstallLowerVersionFeature
4480 */
4481 HWTEST_F(BmsBundleInstallerTest, UninstallLowerVersionFeature_0020, Function | SmallTest | Level0)
4482 {
4483 BaseBundleInstaller installer;
4484 std::vector<std::string> packageVec;
4485 installer.bundleName_ = "";
4486 ErrCode res = installer.UninstallLowerVersionFeature(packageVec);
4487 EXPECT_EQ(res, ERR_APPEXECFWK_UNINSTALL_BUNDLE_MGR_SERVICE_ERROR);
4488 }
4489
4490 /**
4491 * @tc.number: GetUserId_0010
4492 * @tc.name: test GetUserId
4493 * @tc.desc: 1.Test the GetUserId
4494 */
4495 HWTEST_F(BmsBundleInstallerTest, GetUserId_0010, Function | SmallTest | Level0)
4496 {
4497 BaseBundleInstaller installer;
4498 int32_t res = installer.GetUserId(Constants::INVALID_USERID);
4499 EXPECT_EQ(res, Constants::INVALID_USERID);
4500 }
4501
4502 /**
4503 * @tc.number: CheckAppLabel_0010
4504 * @tc.name: test CheckAppLabel
4505 * @tc.desc: 1.Test the CheckAppLabel
4506 */
4507 HWTEST_F(BmsBundleInstallerTest, CheckAppLabel_0010, Function | SmallTest | Level0)
4508 {
4509 BaseBundleInstaller installer;
4510 InnerBundleInfo oldInfo;
4511 InnerBundleInfo newInfo;
4512 oldInfo.baseBundleInfo_->versionName = BUNDLE_NAME_TEST;
4513 ErrCode res = installer.CheckAppLabel(oldInfo, newInfo);
4514 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_VERSIONNAME_NOT_SAME);
4515 }
4516
4517 /**
4518 * @tc.number: CheckAppLabel_0020
4519 * @tc.name: test CheckAppLabel
4520 * @tc.desc: 1.Test the CheckAppLabel
4521 */
4522 HWTEST_F(BmsBundleInstallerTest, CheckAppLabel_0020, Function | SmallTest | Level0)
4523 {
4524 BaseBundleInstaller installer;
4525 InnerBundleInfo oldInfo;
4526 InnerBundleInfo newInfo;
4527 oldInfo.baseBundleInfo_->minCompatibleVersionCode = USERID;
4528 ErrCode res = installer.CheckAppLabel(oldInfo, newInfo);
4529 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_MINCOMPATIBLE_VERSIONCODE_NOT_SAME);
4530 }
4531
4532 /**
4533 * @tc.number: CheckAppLabel_0030
4534 * @tc.name: test CheckAppLabel
4535 * @tc.desc: 1.Test the CheckAppLabel
4536 */
4537 HWTEST_F(BmsBundleInstallerTest, CheckAppLabel_0030, Function | SmallTest | Level0)
4538 {
4539 BaseBundleInstaller installer;
4540 InnerBundleInfo oldInfo;
4541 InnerBundleInfo newInfo;
4542 oldInfo.baseBundleInfo_->vendor = BUNDLE_NAME_TEST;
4543 ErrCode res = installer.CheckAppLabel(oldInfo, newInfo);
4544 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_VENDOR_NOT_SAME);
4545 }
4546
4547 /**
4548 * @tc.number: CheckAppLabel_0040
4549 * @tc.name: test CheckAppLabel
4550 * @tc.desc: 1.Test the CheckAppLabel
4551 */
4552 HWTEST_F(BmsBundleInstallerTest, CheckAppLabel_0040, Function | SmallTest | Level0)
4553 {
4554 BaseBundleInstaller installer;
4555 InnerBundleInfo oldInfo;
4556 InnerBundleInfo newInfo;
4557 oldInfo.baseBundleInfo_->targetVersion = USERID;
4558 ErrCode res = installer.CheckAppLabel(oldInfo, newInfo);
4559 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_RELEASETYPE_TARGET_NOT_SAME);
4560 }
4561
4562 /**
4563 * @tc.number: CheckAppLabel_0050
4564 * @tc.name: test CheckAppLabel
4565 * @tc.desc: 1.Test the CheckAppLabel
4566 */
4567 HWTEST_F(BmsBundleInstallerTest, CheckAppLabel_0050, Function | SmallTest | Level0)
4568 {
4569 BaseBundleInstaller installer;
4570 InnerBundleInfo oldInfo;
4571 InnerBundleInfo newInfo;
4572 oldInfo.baseBundleInfo_->compatibleVersion = USERID;
4573 ErrCode res = installer.CheckAppLabel(oldInfo, newInfo);
4574 EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_RELEASETYPE_COMPATIBLE_NOT_SAME);
4575 }
4576
4577 /**
4578 * @tc.number: ExecuteAOT_0100
4579 * @tc.name: test CheckAppLabel
4580 * @tc.desc: 1.Test the CheckAppLabel
4581 */
4582 HWTEST_F(BmsBundleInstallerTest, ExecuteAOT_0100, Function | SmallTest | Level0)
4583 {
4584 InstalldHostImpl impl;
4585 AOTArgs aotArgs;
4586 auto ret = impl.ExecuteAOT(aotArgs);
4587 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
4588 }
4589
4590 /**
4591 * @tc.number: SetDirApl_0100
4592 * @tc.name: test CheckAppLabel
4593 * @tc.desc: 1.Test the CheckAppLabel
4594 */
4595 HWTEST_F(BmsBundleInstallerTest, SetDirApl_0100, Function | SmallTest | Level0)
4596 {
4597 InstalldHostImpl impl;
4598 bool isPreInstallApp = false;
4599 bool debug = false;
4600 auto ret = impl.SetDirApl("", BUNDLE_NAME, "", isPreInstallApp, debug);
4601 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
4602
4603 ret = impl.SetDirApl(BUNDLE_DATA_DIR, "", "", isPreInstallApp, debug);
4604 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
4605
4606 ret = impl.SetDirApl("", "", "", isPreInstallApp, debug);
4607 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR);
4608
4609 ret = impl.SetDirApl(BUNDLE_DATA_DIR, BUNDLE_NAME, "", isPreInstallApp, debug);
4610 EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_SET_SELINUX_LABEL_FAILED);
4611 }
4612
4613 /**
4614 * @tc.number: GetHapFilesFromBundlePath_0100
4615 * @tc.name: test GetHapFilesFromBundlePath, reach the max hap number 128, stop to add more
4616 * @tc.desc: 1.test GetHapFilesFromBundlePath of BundleUtil
4617 */
4618 HWTEST_F(BmsBundleInstallerTest, GetHapFilesFromBundlePath_0100, Function | SmallTest | Level0)
4619 {
4620 BundleUtil bundleUtil;
4621 auto ret = bundleUtil.CreateTempDir(CURRENT_PATH);
4622 EXPECT_EQ(ret, CURRENT_PATH);
4623 std::vector<std::string> fileList;
4624 for (int i = 0; i < Constants::MAX_HAP_NUMBER + 1; i++) {
4625 std::string tmpFile = CURRENT_PATH + Constants::PATH_SEPARATOR + "test" + std::to_string(i) + ".hap";
4626 bool ret2 = SaveStringToFile(tmpFile, tmpFile);
4627 EXPECT_EQ(ret2, true);
4628 fileList.emplace_back(tmpFile);
4629 }
4630 bundleUtil.MakeFsConfig("testWrong.hap", 1, "/data/testWrong");
4631 bool res = bundleUtil.GetHapFilesFromBundlePath(CURRENT_PATH, fileList);
4632 EXPECT_EQ(res, false);
4633 bundleUtil.DeleteTempDirs(fileList);
4634 }
4635
4636 /**
4637 * @tc.number: CreateInstallTempDir_1700
4638 * @tc.name: test CreateInstallTempDir
4639 * @tc.desc: 1.test type == DirType::SIG_FILE_DIR
4640 */
4641 HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_1700, Function | SmallTest | Level0)
4642 {
4643 BundleUtil bundleUtil;
4644 const int32_t installId = 2022;
4645 std::string res = bundleUtil.CreateInstallTempDir(installId, DirType::SIG_FILE_DIR);
4646 EXPECT_NE(res, "");
4647 auto ret = bundleUtil.DeleteDir(res);
4648 EXPECT_EQ(ret, true);
4649 }
4650
4651 /**
4652 * @tc.number: CreateFileDescriptor_100
4653 * @tc.name: test CreateFileDescriptor
4654 * @tc.desc: 1.test the length of the bundlePath exceeds maximum limitation
4655 */
4656 HWTEST_F(BmsBundleInstallerTest, CreateFileDescriptor_100, Function | SmallTest | Level0)
4657 {
4658 BundleUtil bundleUtil;
4659 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
4660 bundlePath.append(std::string(256, '/'));
4661 long long offset = 0;
4662 auto ret = bundleUtil.CreateFileDescriptor(bundlePath, offset);
4663 EXPECT_EQ(ret, -1);
4664 }
4665
4666 /**
4667 * @tc.number: CreateFileDescriptor_200
4668 * @tc.name: test CreateFileDescriptor
4669 * @tc.desc: 1.test offset > 0
4670 */
4671 HWTEST_F(BmsBundleInstallerTest, CreateFileDescriptor_200, Function | SmallTest | Level0)
4672 {
4673 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
4674 BundleUtil bundleUtil;
4675 long long offset = 1;
4676 auto ret = bundleUtil.CreateFileDescriptor(bundlePath, offset);
4677 EXPECT_NE(ret, -1);
4678 }
4679
4680 /**
4681 * @tc.number: CreateFileDescriptorForReadOnly_100
4682 * @tc.name: test CreateFileDescriptorForReadOnly
4683 * @tc.desc: 1.file is not real path
4684 */
4685 HWTEST_F(BmsBundleInstallerTest, CreateFileDescriptorForReadOnly_100, Function | SmallTest | Level0)
4686 {
4687 std::string bundlePath = "/testWrong/testWrong.hap";
4688 BundleUtil bundleUtil;
4689 long long offset = 1;
4690 auto ret = bundleUtil.CreateFileDescriptorForReadOnly(bundlePath, offset);
4691 EXPECT_EQ(ret, -1);
4692 }
4693
4694 /**
4695 * @tc.number: CreateFileDescriptorForReadOnly_200
4696 * @tc.name: test CreateFileDescriptorForReadOnly
4697 * @tc.desc: 1.test offset > 0
4698 */
4699 HWTEST_F(BmsBundleInstallerTest, CreateFileDescriptorForReadOnly_200, Function | SmallTest | Level0)
4700 {
4701 std::string bundlePath = RESOURCE_ROOT_PATH + BUNDLE_BACKUP_TEST;
4702 BundleUtil bundleUtil;
4703 long long offset = 1;
4704 auto ret = bundleUtil.CreateFileDescriptorForReadOnly(bundlePath, offset);
4705 EXPECT_NE(ret, -1);
4706 }
4707
4708 /**
4709 * @tc.number: CreateDir_DeleteDir_100
4710 * @tc.name: test CreateDir and DeleteDir
4711 * @tc.desc: 1.file exist
4712 */
4713 HWTEST_F(BmsBundleInstallerTest, CreateDir_DeleteDir_100, Function | SmallTest | Level0)
4714 {
4715 BundleUtil bundleUtil;
4716 auto ret = bundleUtil.CreateDir(TEST_CREATE_FILE_PATH);
4717 EXPECT_EQ(ret, true);
4718 auto ret2 = bundleUtil.CreateDir(TEST_CREATE_FILE_PATH);
4719 EXPECT_EQ(ret2, true);
4720 auto ret3 = bundleUtil.DeleteDir(TEST_CREATE_FILE_PATH);
4721 EXPECT_EQ(ret3, true);
4722 }
4723
4724 /**
4725 * @tc.number: CopyFileToSecurityDir_100
4726 * @tc.name: test CopyFileToSecurityDir
4727 * @tc.desc: 1.CopyFileToSecurityDir
4728 */
4729 HWTEST_F(BmsBundleInstallerTest, CopyFileToSecurityDir_100, Function | SmallTest | Level0)
4730 {
4731 BundleUtil bundleUtil;
4732 std::vector<std::string> toDeletePaths;
4733 auto ret = bundleUtil.CopyFileToSecurityDir("", DirType::STREAM_INSTALL_DIR, toDeletePaths);
4734 EXPECT_EQ(ret, "");
4735 EXPECT_EQ(toDeletePaths.size(), 0);
4736 }
4737
4738 /**
4739 * @tc.number: CopyFileToSecurityDir_200
4740 * @tc.name: test CopyFileToSecurityDir
4741 * @tc.desc: 1.CopyFileToSecurityDir
4742 */
4743 HWTEST_F(BmsBundleInstallerTest, CopyFileToSecurityDir_200, Function | SmallTest | Level0)
4744 {
4745 BundleUtil bundleUtil;
4746 std::vector<std::string> toDeletePaths;
4747 bool res1 = bundleUtil.CreateDir(TEST_CREATE_DIR_PATH);
4748 EXPECT_TRUE(res1);
4749 bool res2 = SaveStringToFile(TEST_CREATE_FILE_PATH, TEST_CREATE_FILE_PATH);
4750 EXPECT_TRUE(res2);
4751 bundleUtil.CopyFileToSecurityDir(TEST_CREATE_FILE_PATH, DirType::SIG_FILE_DIR, toDeletePaths);
4752 bool res3 = bundleUtil.DeleteDir(TEST_CREATE_DIR_PATH);
4753 EXPECT_TRUE(res3);
4754 ASSERT_GT(toDeletePaths.size(), 0);
4755 bundleUtil.DeleteTempDirs(toDeletePaths);
4756 }
4757
4758 /**
4759 * @tc.number: CopyFileToSecurityDir_300
4760 * @tc.name: test CopyFileToSecurityDir
4761 * @tc.desc: 1.CopyFileToSecurityDir
4762 */
4763 HWTEST_F(BmsBundleInstallerTest, CopyFileToSecurityDir_300, Function | SmallTest | Level0)
4764 {
4765 BundleUtil bundleUtil;
4766 std::vector<std::string> toDeletePaths;
4767 std::string sourcePath = TEST_CREATE_DIR_PATH + Constants::PATH_SEPARATOR + Constants::SIGNATURE_FILE_PATH;
4768 auto ret = bundleUtil.CopyFileToSecurityDir(sourcePath, DirType::SIG_FILE_DIR, toDeletePaths);
4769 EXPECT_EQ(ret, "");
4770 EXPECT_EQ(toDeletePaths.size(), 0);
4771 }
4772
4773 /**
4774 * @tc.number: CopyFileToSecurityDir_400
4775 * @tc.name: test CopyFileToSecurityDir
4776 * @tc.desc: 1.CopyFileToSecurityDir
4777 */
4778 HWTEST_F(BmsBundleInstallerTest, CopyFileToSecurityDir_400, Function | SmallTest | Level0)
4779 {
4780 BundleUtil bundleUtil;
4781 std::vector<std::string> toDeletePaths;
4782 std::string sourcePath = TEST_CREATE_DIR_PATH + Constants::PATH_SEPARATOR +
4783 Constants::SIGNATURE_FILE_PATH + Constants::PATH_SEPARATOR;
4784 auto ret = bundleUtil.CopyFileToSecurityDir(sourcePath, DirType::SIG_FILE_DIR, toDeletePaths);
4785 EXPECT_EQ(ret, "");
4786 EXPECT_EQ(toDeletePaths.size(), 0);
4787 }
4788
4789 /**
4790 * @tc.number: CopyFileToSecurityDir_500
4791 * @tc.name: test CopyFileToSecurityDir
4792 * @tc.desc: 1.CopyFileToSecurityDir
4793 */
4794 HWTEST_F(BmsBundleInstallerTest, CopyFileToSecurityDir_500, Function | SmallTest | Level0)
4795 {
4796 BundleUtil bundleUtil;
4797 std::vector<std::string> toDeletePaths;
4798 std::string sourcePath = TEST_CREATE_DIR_PATH + Constants::PATH_SEPARATOR +
4799 Constants::SIGNATURE_FILE_PATH + Constants::PATH_SEPARATOR;
4800 sourcePath.append("test");
4801 auto ret1 = bundleUtil.CopyFileToSecurityDir(sourcePath, DirType::SIG_FILE_DIR, toDeletePaths);
4802 EXPECT_EQ(ret1, "");
4803 EXPECT_EQ(toDeletePaths.size(), 0);
4804 sourcePath.append(Constants::PATH_SEPARATOR);
4805 auto ret2 = bundleUtil.CopyFileToSecurityDir(sourcePath, DirType::SIG_FILE_DIR, toDeletePaths);
4806 EXPECT_EQ(ret2, "");
4807 EXPECT_EQ(toDeletePaths.size(), 0);
4808 }
4809
4810 /**
4811 * @tc.number: CopyFileToSecurityDir_600
4812 * @tc.name: test CopyFileToSecurityDir
4813 * @tc.desc: 1.CopyFileToSecurityDir
4814 */
4815 HWTEST_F(BmsBundleInstallerTest, CopyFileToSecurityDir_600, Function | SmallTest | Level0)
4816 {
4817 BundleUtil bundleUtil;
4818 std::vector<std::string> toDeletePaths;
4819 std::string sourcePath = TEST_CREATE_DIR_PATH + Constants::PATH_SEPARATOR +
4820 Constants::SIGNATURE_FILE_PATH + Constants::PATH_SEPARATOR + "test" +
4821 Constants::PATH_SEPARATOR + "testSourcePath";
4822 bool ret1 = bundleUtil.CreateDir(sourcePath);
4823 EXPECT_TRUE(ret1);
4824 std::string sourceFile = sourcePath.append(Constants::PATH_SEPARATOR).append("testSourceFile.hap");
4825 bool ret2 = SaveStringToFile(sourceFile, sourceFile);
4826 EXPECT_TRUE(ret2);
4827 bundleUtil.CopyFileToSecurityDir(sourcePath, DirType::SIG_FILE_DIR, toDeletePaths);
4828 bool ret3 = bundleUtil.DeleteDir(sourcePath);
4829 EXPECT_TRUE(ret3);
4830 ASSERT_GT(toDeletePaths.size(), 0);
4831 bundleUtil.DeleteTempDirs(toDeletePaths);
4832 }
4833
4834 /**
4835 * @tc.number: CheckDependency_0010
4836 * @tc.name: test CheckDependency
4837 * @tc.desc: 1.CheckDependency
4838 */
4839 HWTEST_F(BmsBundleInstallerTest, CheckDependency_0010, Function | SmallTest | Level0)
4840 {
4841 InstallParam installParam;
4842 auto appType = Constants::AppType::THIRD_PARTY_APP;
4843 SharedBundleInstaller bundleInstaller(installParam, appType);
4844
4845 Dependency dependency;
4846 dependency.bundleName = BUNDLE_NAME;
4847 InnerModuleInfo innerModuleInfo;
4848 innerModuleInfo.dependencies.push_back(dependency);
4849 InnerBundleInfo innerBundleInfo;
4850 innerBundleInfo.innerModuleInfos_.insert(std::pair<std::string, InnerModuleInfo>(BUNDLE_NAME, innerModuleInfo));
4851 ClearDataMgr();
__anon02b290760302null4852 ScopeGuard stateGuard([&] { ResetDataMgr(); });
4853 auto res = bundleInstaller.CheckDependency(innerBundleInfo);
4854 EXPECT_FALSE(res);
4855 }
4856
4857 /**
4858 * @tc.number: FindDependencyInInstalledBundles_0010
4859 * @tc.name: test FindDependencyInInstalledBundles
4860 * @tc.desc: 1.FindDependencyInInstalledBundles
4861 */
4862 HWTEST_F(BmsBundleInstallerTest, FindDependencyInInstalledBundles_0010, Function | SmallTest | Level0)
4863 {
4864 InstallParam installParam;
4865 auto appType = Constants::AppType::THIRD_PARTY_APP;
4866 SharedBundleInstaller bundleInstaller(installParam, appType);
4867
4868 Dependency dependency;
4869 ClearDataMgr();
__anon02b290760402null4870 ScopeGuard stateGuard([&] { ResetDataMgr(); });
4871 auto res = bundleInstaller.FindDependencyInInstalledBundles(dependency);
4872 EXPECT_FALSE(res);
4873 }
4874
4875 /**
4876 * @tc.number: GetCallingEventInfo_0010
4877 * @tc.name: test GetCallingEventInfo
4878 * @tc.desc: 1.GetCallingEventInfo
4879 */
4880 HWTEST_F(BmsBundleInstallerTest, GetCallingEventInfo_0010, Function | SmallTest | Level0)
4881 {
4882 InstallParam installParam;
4883 auto appType = Constants::AppType::THIRD_PARTY_APP;
4884 SharedBundleInstaller bundleInstaller(installParam, appType);
4885
4886 EventInfo eventInfo;
4887 ClearDataMgr();
__anon02b290760502null4888 ScopeGuard stateGuard([&] { ResetDataMgr(); });
4889 bundleInstaller.GetCallingEventInfo(eventInfo);
4890 EXPECT_EQ(eventInfo.callingBundleName, EMPTY_STRING);
4891 }
4892 } // OHOS
4893