From 515c230c25d46fd768067799ed64ba3421ef5011 Mon Sep 17 00:00:00 2001 From: xinking129 Date: Tue, 16 Jan 2024 10:12:55 +0800 Subject: [PATCH 1/6] tdd change Signed-off-by: xinking129 --- .../bms_bundle_data_mgr_test.cpp | 76 +- ...undle_mgr_service_death_recipient_test.cpp | 15 - ...ms_bundle_get_overlay_module_info_test.cpp | 1493 +++-- .../bms_bundle_manager_overlay_ipc_test.cpp | 393 +- .../bms_bundle_overlay_checker_test.cpp | 5759 ++++++++--------- .../bms_bundle_permission_false_test.cpp | 31 - .../bms_bundle_resource_manager_test.cpp | 16 - .../bms_bundle_resource_test.cpp | 3 +- .../bms_bundle_sandbox_app_test.cpp | 169 +- .../bms_bundle_uninstaller_test.cpp | 66 +- 10 files changed, 3976 insertions(+), 4045 deletions(-) diff --git a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test.cpp index eb4573cc8a..6a2f4168e3 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test.cpp @@ -1420,6 +1420,7 @@ HWTEST_F(BmsBundleDataMgrTest, GetBundleStats_0100, Function | SmallTest | Level * @tc.desc: 1.system run normally * 2.check GetBundleSpaceSize failed */ +#ifdef BUNDLE_FRAMEWORK_FREE_INSTALL HWTEST_F(BmsBundleDataMgrTest, GetBundleSpaceSize_0100, Function | SmallTest | Level1) { std::vector bundleStats; @@ -1459,6 +1460,7 @@ HWTEST_F(BmsBundleDataMgrTest, GetAllFreeInstallBundleSpaceSize_0100, Function | MockUninstallBundle(BUNDLE_NAME_TEST); } +#endif /** * @tc.number: QueryKeepAliveBundleInfos_0100 @@ -1708,9 +1710,27 @@ HWTEST_F(BmsBundleDataMgrTest, GetAllFormsInfo_0100, Function | SmallTest | Leve { std::vector formInfos; InnerBundleInfo innerBundleInfo; + GetBundleDataMgr()->bundleInfos_.clear(); innerBundleInfo.SetBundleStatus(InnerBundleInfo::BundleStatus::DISABLED); GetBundleDataMgr()->bundleInfos_.emplace(BUNDLE_NAME_TEST, innerBundleInfo); bool res = GetBundleDataMgr()->GetAllFormsInfo(formInfos); + EXPECT_EQ(res, false); +} + +/** + * @tc.number: GetAllFormsInfo_0200 + * @tc.name: test GetAllFormsInfo + * @tc.desc: 1.system run normally + * 2.check GetAllFormsInfo failed + */ +HWTEST_F(BmsBundleDataMgrTest, GetAllFormsInfo_0200, Function | SmallTest | Level1) +{ + std::vector formInfos; + InnerBundleInfo innerBundleInfo; + GetBundleDataMgr()->bundleInfos_.clear(); + innerBundleInfo.SetBundleStatus(InnerBundleInfo::BundleStatus::ENABLED); + GetBundleDataMgr()->bundleInfos_.emplace(BUNDLE_NAME_TEST, innerBundleInfo); + bool res = GetBundleDataMgr()->GetAllFormsInfo(formInfos); EXPECT_EQ(res, true); } @@ -1740,6 +1760,7 @@ HWTEST_F(BmsBundleDataMgrTest, GetFormsInfoByApp_0100, Function | SmallTest | Le { std::vector formInfos; InnerBundleInfo innerBundleInfo; + GetBundleDataMgr()->bundleInfos_.clear(); innerBundleInfo.SetBundleStatus(InnerBundleInfo::BundleStatus::DISABLED); GetBundleDataMgr()->bundleInfos_.emplace(BUNDLE_NAME_TEST, innerBundleInfo); bool res = GetBundleDataMgr()->GetFormsInfoByApp(BUNDLE_NAME_TEST, formInfos); @@ -1858,6 +1879,7 @@ HWTEST_F(BmsBundleDataMgrTest, QueryExtensionAbilityInfos_0300, Function | Small bool ret = GetBundleDataMgr()->QueryExtensionAbilityInfos( ExtensionAbilityType::FORM, USERID, extensionInfo); EXPECT_EQ(ret, true); + EXPECT_TRUE(extensionInfo.empty()); GetBundleDataMgr()->multiUserIdsSet_.clear(); } @@ -1894,23 +1916,6 @@ HWTEST_F(BmsBundleDataMgrTest, ExplicitQueryExtensionInfo_0100, Function | Small GetBundleDataMgr()->multiUserIdsSet_.clear(); } -/** - * @tc.number: ImplicitQueryCurExtensionInfos_0100 - * @tc.name: test ImplicitQueryCurExtensionInfos - * @tc.desc: 1.system run normally - * 2.check ImplicitQueryCurExtensionInfos failed - */ -HWTEST_F(BmsBundleDataMgrTest, ImplicitQueryCurExtensionInfos_0100, Function | SmallTest | Level1) -{ - Want want; - std::vector infos; - int32_t appIndex = 0; - GetBundleDataMgr()->sandboxAppHelper_ = DelayedSingleton::GetInstance(); - bool testRet = GetBundleDataMgr()->ImplicitQueryCurExtensionInfos( - want, GET_ABILITY_INFO_DEFAULT, USERID, infos, appIndex); - EXPECT_EQ(testRet, false); -} - /** * @tc.number: ImplicitQueryCurExtensionInfos_0200 * @tc.name: test ImplicitQueryCurExtensionInfos @@ -1928,6 +1933,10 @@ HWTEST_F(BmsBundleDataMgrTest, ImplicitQueryCurExtensionInfos_0200, Function | S bool testRet = GetBundleDataMgr()->ImplicitQueryCurExtensionInfos( want, GET_ABILITY_INFO_DEFAULT, Constants::INVALID_UID, infos, appIndex); EXPECT_EQ(testRet, false); + GetBundleDataMgr()->sandboxAppHelper_ = nullptr; + bool testRet1 = GetBundleDataMgr()->ImplicitQueryCurExtensionInfos( + want, GET_ABILITY_INFO_DEFAULT, Constants::INVALID_UID, infos, appIndex); + EXPECT_EQ(testRet1, false); } /** @@ -1977,32 +1986,6 @@ HWTEST_F(BmsBundleDataMgrTest, ImplicitQueryCurExtensionInfos_0400, Function | S EXPECT_EQ(testRet, false); } -/** - * @tc.number: ImplicitQueryCurExtensionInfos_0500 - * @tc.name: test ImplicitQueryCurExtensionInfos - * @tc.desc: 1.system run normally - * 2.check ImplicitQueryCurExtensionInfos failed - */ -HWTEST_F(BmsBundleDataMgrTest, ImplicitQueryCurExtensionInfos_0500, Function | SmallTest | Level1) -{ - InnerBundleInfo innerBundleInfo; - ApplicationInfo applicationInfo; - applicationInfo.bundleName = BUNDLE_NAME_TEST; - innerBundleInfo.SetBaseApplicationInfo(applicationInfo); - innerBundleInfo.SetBundleStatus(InnerBundleInfo::BundleStatus::DISABLED); - GetBundleDataMgr()->bundleInfos_.emplace(BUNDLE_NAME_TEST, innerBundleInfo); - - Want want; - std::vector infos; - int32_t appIndex = 0; - GetBundleDataMgr()->ImplicitQueryAllExtensionInfos( - want, GET_ABILITY_INFO_DEFAULT, USERID, infos, appIndex); - GetBundleDataMgr()->sandboxAppHelper_ = DelayedSingleton::GetInstance(); - bool testRet = GetBundleDataMgr()->ImplicitQueryCurExtensionInfos( - want, GET_ABILITY_INFO_DEFAULT, USERID, infos, appIndex); - EXPECT_EQ(testRet, false); -} - /** * @tc.number: QueryExtensionAbilityInfoByUri_0100 * @tc.name: test QueryExtensionAbilityInfoByUri @@ -2259,6 +2242,7 @@ HWTEST_F(BmsBundleDataMgrTest, CheckAbilityEnableInstall_0100, Function | Medium * @tc.name: test UpgradeAtomicService * @tc.desc: 1.test UpgradeAtomicService */ +#ifdef BUNDLE_FRAMEWORK_FREE_INSTALL HWTEST_F(BmsBundleDataMgrTest, UpgradeAtomicService_0100, Function | MediumTest | Level1) { AAFwk::Want want; @@ -2267,6 +2251,7 @@ HWTEST_F(BmsBundleDataMgrTest, UpgradeAtomicService_0100, Function | MediumTest bundleMgrHostImpl_->UpgradeAtomicService(want, USERID); ASSERT_NE(ret, nullptr); } +#endif /** * @tc.number: CheckAbilityEnableInstall_0200 @@ -3418,6 +3403,7 @@ HWTEST_F(BmsBundleDataMgrTest, RemoveModuleInfo_0300, Function | SmallTest | Lev std::string key = "key"; info.baseAbilityInfos_.try_emplace(key, abilityInfo); info.RemoveModuleInfo(PACKAGE_NAME); + EXPECT_TRUE(info.innerModuleInfos_.empty()); auto abilityItem = info.baseAbilityInfos_.find("keys"); EXPECT_EQ(abilityItem, info.baseAbilityInfos_.end()); @@ -3441,6 +3427,7 @@ HWTEST_F(BmsBundleDataMgrTest, RemoveModuleInfo_0400, Function | SmallTest | Lev std::string key = "key"; info.skillInfos_.try_emplace(key, skills); info.RemoveModuleInfo(PACKAGE_NAME); + EXPECT_TRUE(info.innerModuleInfos_.empty()); auto skillItem = info.skillInfos_.find("keys"); EXPECT_EQ(skillItem, info.skillInfos_.end()); @@ -3464,6 +3451,7 @@ HWTEST_F(BmsBundleDataMgrTest, RemoveModuleInfo_0500, Function | SmallTest | Lev std::string key = "key"; info.baseExtensionInfos_.try_emplace(key, extensionAbilityInfo); info.RemoveModuleInfo(PACKAGE_NAME); + EXPECT_TRUE(info.innerModuleInfos_.empty()); auto extensionItem = info.baseExtensionInfos_.find("keys"); EXPECT_EQ(extensionItem, info.baseExtensionInfos_.end()); @@ -3487,6 +3475,7 @@ HWTEST_F(BmsBundleDataMgrTest, RemoveModuleInfo_0600, Function | SmallTest | Lev std::string key = "key"; info.extensionSkillInfos_.try_emplace(key, skills); info.RemoveModuleInfo(PACKAGE_NAME); + EXPECT_TRUE(info.innerModuleInfos_.empty()); auto extensionSkillItem = info.extensionSkillInfos_.find("keys"); EXPECT_EQ(extensionSkillItem, info.extensionSkillInfos_.end()); @@ -3530,6 +3519,7 @@ HWTEST_F(BmsBundleDataMgrTest, ProcessBundleWithHapModuleInfoFlag_0100, Function static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE), bundleInfo, USERID); auto it = info.FindHapModuleInfo(PACKAGE_NAME, USERID); EXPECT_EQ(it->hqfInfo.moduleName, ""); + EXPECT_EQ(it->name, MODULE_NAME1); } /** diff --git a/services/bundlemgr/test/unittest/bms_bundle_mgr_service_death_recipient_test/bms_bundle_mgr_service_death_recipient_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_mgr_service_death_recipient_test/bms_bundle_mgr_service_death_recipient_test.cpp index 8a420183b7..94468d0751 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_mgr_service_death_recipient_test/bms_bundle_mgr_service_death_recipient_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_mgr_service_death_recipient_test/bms_bundle_mgr_service_death_recipient_test.cpp @@ -54,20 +54,5 @@ HWTEST_F(BmsBundleMgrServiceDeathRecipientTest, BundleMgrServiceDeathRecipient_0 bundleMgrServiceDeathRecipient.OnRemoteDied(object); EXPECT_EQ(bundleMgrServiceDeathRecipient.deathCallback_, nullptr); } - -/** - * @tc.number: BundleMgrServiceDeathRecipient_002 - * @tc.name: OnRemoteDied - * @tc.desc: When deathCallback_ is empty, Successful case of verifying OnRemoteDied. - */ -HWTEST_F(BmsBundleMgrServiceDeathRecipientTest, BundleMgrServiceDeathRecipient_002, TestSize.Level1) -{ - const wptr object; - const std::function& object)> deathCallback; - BundleMgrServiceDeathRecipient bundleMgrServiceDeathRecipient(deathCallback); - bundleMgrServiceDeathRecipient.deathCallback_ = nullptr; - bundleMgrServiceDeathRecipient.OnRemoteDied(object); - EXPECT_EQ(bundleMgrServiceDeathRecipient.deathCallback_, nullptr); -} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_get_overlay_module_info_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_get_overlay_module_info_test.cpp index e2c3a52bcb..0bf28f3e68 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_get_overlay_module_info_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_get_overlay_module_info_test.cpp @@ -1,755 +1,738 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define private public - -#include - -#include "appexecfwk_errors.h" -#include "bundle_overlay_data_manager.h" -#include "bundle_overlay_install_checker.h" -#include "bundle_overlay_manager.h" -#include "bundle_mgr_service.h" - -using namespace testing::ext; -using namespace OHOS::AppExecFwk; -using OHOS::DelayedSingleton; - -namespace OHOS { -namespace { -const std::string TEST_MODULE_NAME = "testModuleName"; -const std::string TEST_MODULE_NAME_SECOND = "testModuleNameSecond"; -const std::string TEST_MODULE_NAME_THIRD = "testModuleNameThird"; -const std::string TARGET_MODULE_NAME = "targetModuleName"; -const std::string TEST_BUNDLE_NAME = "testBundleName"; -const std::string TEST_HAP_PATH = "testHapPath"; -const std::string TEST_TARGET_BUNDLE_NAME = "testTargetBundleName"; -const std::string TEST_OVERLAY_BUNDLE_DIR = "testBundleDir"; -const int32_t DEFAULT_TARGET_PRIORITY_SECOND = 1; -const int32_t USERID = 100; -const int32_t UNSPECIFIED_USERID = -2; -const int32_t TEST_USERID = 101; -const int32_t OVERLAY_MODULE_INFO_SIZE = 1; -const int32_t DEFAULT_OVERLAY_MODULE_INFO_SIZE = 0; -const int32_t WAIT_TIME = 5; // init mocked bms -} // namespace - -class BmsBundleGetOverlayModuleInfoTest : public testing::Test { -public: - BmsBundleGetOverlayModuleInfoTest(); - ~BmsBundleGetOverlayModuleInfoTest(); - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); - - void AddOverlayInnerBundleInfo(int32_t overlayType); - void AddNonOverlayInnerBundleInfo(); - void AddOverlayBundleInfo(); - void RemoveBundleInfo(const std::string &bundleName); - void CheckEnabledState(int32_t state); - void CheckOverlayModuleInfo(const OverlayModuleInfo &info); - void CheckOverlayBundleInfo(const OverlayBundleInfo &info); - - const std::shared_ptr GetBundleDataMgr() const; - -private: - static std::shared_ptr bundleMgrService_; -}; - -std::shared_ptr BmsBundleGetOverlayModuleInfoTest::bundleMgrService_ = - DelayedSingleton::GetInstance(); - -BmsBundleGetOverlayModuleInfoTest::BmsBundleGetOverlayModuleInfoTest() -{} - -BmsBundleGetOverlayModuleInfoTest::~BmsBundleGetOverlayModuleInfoTest() -{} - -void BmsBundleGetOverlayModuleInfoTest::SetUpTestCase() -{} - -void BmsBundleGetOverlayModuleInfoTest::TearDownTestCase() -{ - bundleMgrService_->OnStop(); -} -void BmsBundleGetOverlayModuleInfoTest::SetUp() -{ - if (!bundleMgrService_->IsServiceReady()) { - bundleMgrService_->OnStart(); - std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME)); - } -} - -void BmsBundleGetOverlayModuleInfoTest::TearDown() -{} - -void BmsBundleGetOverlayModuleInfoTest::AddOverlayInnerBundleInfo(int32_t overlayType) -{ - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.name = TEST_MODULE_NAME; - innerModuleInfo.moduleName = TEST_MODULE_NAME; - innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; - innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; - innerModuleInfo.hapPath = TEST_HAP_PATH; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - ApplicationInfo applicationInfo; - applicationInfo.bundleName = TEST_BUNDLE_NAME; - innerBundleInfo.SetBaseApplicationInfo(applicationInfo); - innerBundleInfo.SetOverlayType(overlayType); - - InnerModuleInfo secondInnerModuleInfo; - secondInnerModuleInfo.name = TEST_MODULE_NAME_SECOND; - secondInnerModuleInfo.moduleName = TEST_MODULE_NAME_SECOND; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME_SECOND, secondInnerModuleInfo); - - InnerModuleInfo targetModuleInfo; - targetModuleInfo.name = TARGET_MODULE_NAME; - targetModuleInfo.moduleName = TARGET_MODULE_NAME; - OverlayModuleInfo overlayModuleInfo; - overlayModuleInfo.bundleName = TEST_BUNDLE_NAME; - overlayModuleInfo.moduleName = TEST_MODULE_NAME; - overlayModuleInfo.targetModuleName = TARGET_MODULE_NAME; - overlayModuleInfo.hapPath = TEST_HAP_PATH; - overlayModuleInfo.priority = DEFAULT_TARGET_PRIORITY_SECOND; - targetModuleInfo.overlayModuleInfo.emplace_back(overlayModuleInfo); - innerBundleInfo.InsertInnerModuleInfo(TARGET_MODULE_NAME, targetModuleInfo); - - InnerBundleUserInfo userInfo; - userInfo.bundleUserInfo.userId = USERID; - std::string state = TEST_MODULE_NAME + Constants::FILE_UNDERLINE + std::to_string(OVERLAY_ENABLE); - userInfo.bundleUserInfo.overlayModulesState.emplace_back(state); - innerBundleInfo.AddInnerBundleUserInfo(userInfo); - - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); - dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, innerBundleInfo); -} - -void BmsBundleGetOverlayModuleInfoTest::AddNonOverlayInnerBundleInfo() -{ - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.name = TEST_MODULE_NAME; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - ApplicationInfo applicationInfo; - applicationInfo.bundleName = TEST_BUNDLE_NAME; - innerBundleInfo.SetBaseApplicationInfo(applicationInfo); - - InnerBundleUserInfo userInfo; - userInfo.bundleUserInfo.userId = USERID; - innerBundleInfo.AddInnerBundleUserInfo(userInfo); - - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - innerBundleInfo.SetBaseApplicationInfo(applicationInfo); - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); - dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, innerBundleInfo); -} - -void BmsBundleGetOverlayModuleInfoTest::RemoveBundleInfo(const std::string &bundleName) -{ - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - bool startRet = dataMgr->UpdateBundleInstallState(bundleName, InstallState::UNINSTALL_START); - bool finishRet = dataMgr->UpdateBundleInstallState(bundleName, InstallState::UNINSTALL_SUCCESS); - - EXPECT_TRUE(startRet); - EXPECT_TRUE(finishRet); -} - -void BmsBundleGetOverlayModuleInfoTest::CheckOverlayModuleInfo(const OverlayModuleInfo &info) -{ - EXPECT_EQ(info.bundleName, TEST_BUNDLE_NAME); - EXPECT_EQ(info.moduleName, TEST_MODULE_NAME); - EXPECT_EQ(info.hapPath, TEST_HAP_PATH); - EXPECT_EQ(info.targetModuleName, TARGET_MODULE_NAME); - EXPECT_EQ(info.state, OVERLAY_ENABLE); - EXPECT_EQ(info.priority, DEFAULT_TARGET_PRIORITY_SECOND); -} - -void BmsBundleGetOverlayModuleInfoTest::CheckOverlayBundleInfo(const OverlayBundleInfo &info) -{ - EXPECT_EQ(info.bundleName, TEST_BUNDLE_NAME); - EXPECT_EQ(info.bundleDir, TEST_OVERLAY_BUNDLE_DIR); - EXPECT_EQ(info.state, OVERLAY_ENABLE); - EXPECT_EQ(info.priority, DEFAULT_TARGET_PRIORITY_SECOND); -} - -void BmsBundleGetOverlayModuleInfoTest::AddOverlayBundleInfo() -{ - InnerBundleInfo innerBundleInfo; - OverlayBundleInfo info; - info.bundleName = TEST_BUNDLE_NAME; - info.bundleDir = TEST_OVERLAY_BUNDLE_DIR; - info.state = OVERLAY_ENABLE; - info.priority = DEFAULT_TARGET_PRIORITY_SECOND; - innerBundleInfo.AddOverlayBundleInfo(info); - - InnerBundleUserInfo userInfo; - userInfo.bundleUserInfo.userId = USERID; - innerBundleInfo.AddInnerBundleUserInfo(userInfo); - - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - dataMgr->UpdateBundleInstallState(TEST_TARGET_BUNDLE_NAME, InstallState::INSTALL_START); - dataMgr->AddInnerBundleInfo(TEST_TARGET_BUNDLE_NAME, innerBundleInfo); -} - -const std::shared_ptr BmsBundleGetOverlayModuleInfoTest::GetBundleDataMgr() const -{ - return bundleMgrService_->GetDataMgr(); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_0100 - * @tc.name: test GetAllOverlayModuleInfo interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified bundleName is not existed. - * 2.get failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0100, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - std::vector vec; - auto res = hostImpl->GetAllOverlayModuleInfo(TEST_BUNDLE_NAME, vec); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_0200 - * @tc.name: test GetAllOverlayModuleInfo interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified bundle is not installed at specified user. - * 2.get failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0200, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); - - std::vector vec; - auto res = hostImpl->GetAllOverlayModuleInfo(TEST_BUNDLE_NAME, vec, TEST_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_0300 - * @tc.name: test GetAllOverlayModuleInfo interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified bundle does not contain any overlay module. - * 2.get failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0300, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddNonOverlayInnerBundleInfo(); - - std::vector vec; - auto res = hostImpl->GetAllOverlayModuleInfo(TEST_BUNDLE_NAME, vec, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_NON_OVERLAY_BUNDLE); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_0400 - * @tc.name: test GetAllOverlayModuleInfo interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified bundle is valid bundle - * 2.get successfully. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0400, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); - - std::vector vec; - auto res = hostImpl->GetAllOverlayModuleInfo(TEST_BUNDLE_NAME, vec, USERID); - EXPECT_EQ(res, ERR_OK); - - EXPECT_EQ(vec.size(), OVERLAY_MODULE_INFO_SIZE); - CheckOverlayModuleInfo(vec[0]); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_0500 - * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified bundleName is not existed. - * 2.get failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0500, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - OverlayModuleInfo overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_0600 - * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified bundle is not installed at specified user. - * 2.get failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0600, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); - - OverlayModuleInfo overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, TEST_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_0700 - * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified bundle is not overlay bundle - * 2.get failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0700, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddNonOverlayInnerBundleInfo(); - - OverlayModuleInfo overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_NON_OVERLAY_BUNDLE); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_0800 - * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified module is not existed. - * 2.get failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0800, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); - - OverlayModuleInfo overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_MODULE_NAME_THIRD, overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_MODULE); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_0900 - * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified bundle is not overlay bundle - * 2.get failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0900, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); - - OverlayModuleInfo overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_MODULE_NAME_SECOND, overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_NON_OVERLAY_MODULE); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_1000 - * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified bundle is not overlay bundle - * 2.get failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1000, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); - - OverlayModuleInfo overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_MODULE_NAME_SECOND, overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_NON_OVERLAY_MODULE); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_1100 - * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified bundle and module are valid - * 2.get successfully. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1100, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); - - OverlayModuleInfo overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_OK); - - CheckOverlayModuleInfo(overlayModuleInfo); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_1200 - * @tc.name: test GetOverlayBundleInfoForTarget interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified target bundle name is not existed. - * 2.get failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1200, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - std::vector overlayBundleInfo; - auto res = hostImpl->GetOverlayBundleInfoForTarget(TEST_BUNDLE_NAME, overlayBundleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_NOT_EXISTED); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_1300 - * @tc.name: test GetOverlayBundleInfoForTarget interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified target bundle does not installed at specified user. - * 2.get failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1300, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddOverlayBundleInfo(); - - std::vector overlayBundleInfo; - auto res = hostImpl->GetOverlayBundleInfoForTarget(TEST_TARGET_BUNDLE_NAME, overlayBundleInfo, TEST_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); - RemoveBundleInfo(TEST_TARGET_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_1400 - * @tc.name: test GetOverlayBundleInfoForTarget interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified target bundle is valid. - * 2.get successfully. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1400, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddOverlayBundleInfo(); - - std::vector overlayBundleInfo; - auto res = hostImpl->GetOverlayBundleInfoForTarget(TEST_TARGET_BUNDLE_NAME, overlayBundleInfo, USERID); - EXPECT_EQ(res, ERR_OK); - - EXPECT_EQ(overlayBundleInfo.size(), OVERLAY_MODULE_INFO_SIZE); - CheckOverlayBundleInfo(overlayBundleInfo[0]); - RemoveBundleInfo(TEST_TARGET_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_1500 - * @tc.name: test GetOverlayBundleInfoForTarget interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified target bundle is valid. - * 2.get successfully. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1500, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddNonOverlayInnerBundleInfo(); - - std::vector overlayBundleInfo; - auto res = hostImpl->GetOverlayBundleInfoForTarget(TEST_BUNDLE_NAME, overlayBundleInfo, USERID); - EXPECT_EQ(res, ERR_OK); - EXPECT_EQ(overlayBundleInfo.size(), DEFAULT_OVERLAY_MODULE_INFO_SIZE); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_1600 - * @tc.name: test GetOverlayModuleInfoForTarget interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified target bundle is not existed. - * 2.get successfully. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1600, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - std::vector overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfoForTarget(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_NOT_EXISTED); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_1700 - * @tc.name: test GetOverlayModuleInfoForTarget interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified target bundle is external overlay bundle. - * 2.get successfully. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1700, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddOverlayInnerBundleInfo(OverlayType::OVERLAY_EXTERNAL_BUNDLE); - - std::vector overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfoForTarget(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_IS_OVERLAY_BUNDLE); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_1800 - * @tc.name: test GetOverlayModuleInfoForTarget interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified target bundle is not installed at specified user. - * 2.get failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1800, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); - - std::vector overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfoForTarget(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, - TEST_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_1900 - * @tc.name: test GetOverlayModuleInfoForTarget interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified target module is not existed. - * 2.get failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1900, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); - - std::vector overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfoForTarget(TEST_BUNDLE_NAME, TEST_MODULE_NAME_THIRD, overlayModuleInfo, - USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_MODULE_NOT_EXISTED); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_2000 - * @tc.name: test GetOverlayModuleInfoForTarget interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified target module is overlay module. - * 2.get failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_2000, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); - - std::vector overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfoForTarget(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_MODULE_IS_OVERLAY_MODULE); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_2100 - * @tc.name: test GetOverlayModuleInfoForTarget interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified target bundle is valid. - * 2.get successfully. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_2100, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); - - std::vector overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfoForTarget(TEST_BUNDLE_NAME, TEST_MODULE_NAME_SECOND, overlayModuleInfo, - USERID); - EXPECT_EQ(res, ERR_OK); - EXPECT_EQ(overlayModuleInfo.size(), DEFAULT_OVERLAY_MODULE_INFO_SIZE); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_2200 - * @tc.name: test GetOverlayModuleInfoForTarget interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified target bundle is valid. - * 2.get successfully. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_2200, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); - - std::vector overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfoForTarget(TEST_BUNDLE_NAME, TARGET_MODULE_NAME, overlayModuleInfo, - USERID); - EXPECT_EQ(res, ERR_OK); - EXPECT_EQ(overlayModuleInfo.size(), OVERLAY_MODULE_INFO_SIZE); - - CheckOverlayModuleInfo(overlayModuleInfo[0]); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_2300 - * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl - * @tc.desc: 1.the specified bundle is valid bundle - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_2300, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - OverlayModuleInfo overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfo("", overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_2400 - * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl - * @tc.desc: 1.the specified bundle is valid bundle - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_2400, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - OverlayModuleInfo overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, overlayModuleInfo, UNSPECIFIED_USERID); - EXPECT_NE(res, ERR_OK); - - res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, overlayModuleInfo, USERID); - EXPECT_NE(res, ERR_OK); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_2500 - * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl - * @tc.desc: 1.the specified bundle is valid bundle - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_2500, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - std::vector overlayModuleInfos; - auto res = hostImpl->GetTargetOverlayModuleInfo(TARGET_MODULE_NAME, overlayModuleInfos, UNSPECIFIED_USERID); - EXPECT_NE(res, ERR_OK); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_2600 - * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl - * @tc.desc: 1.the specified bundle is valid bundle - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_2600, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - auto res = hostImpl->SetOverlayEnabledForSelf(TARGET_MODULE_NAME, false, UNSPECIFIED_USERID); - EXPECT_NE(res, ERR_OK); -} -} // OHOS +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public + +#include + +#include "appexecfwk_errors.h" +#include "bundle_overlay_data_manager.h" +#include "bundle_overlay_install_checker.h" +#include "bundle_overlay_manager.h" +#include "bundle_mgr_service.h" + +using namespace testing::ext; +using namespace OHOS::AppExecFwk; +using OHOS::DelayedSingleton; + +namespace OHOS { +namespace { +const std::string TEST_MODULE_NAME = "testModuleName"; +const std::string TEST_MODULE_NAME_SECOND = "testModuleNameSecond"; +const std::string TEST_MODULE_NAME_THIRD = "testModuleNameThird"; +const std::string TARGET_MODULE_NAME = "targetModuleName"; +const std::string TEST_BUNDLE_NAME = "testBundleName"; +const std::string TEST_HAP_PATH = "testHapPath"; +const std::string TEST_TARGET_BUNDLE_NAME = "testTargetBundleName"; +const std::string TEST_OVERLAY_BUNDLE_DIR = "testBundleDir"; +const int32_t DEFAULT_TARGET_PRIORITY_SECOND = 1; +const int32_t USERID = 100; +const int32_t UNSPECIFIED_USERID = -2; +const int32_t TEST_USERID = 101; +const int32_t OVERLAY_MODULE_INFO_SIZE = 1; +const int32_t DEFAULT_OVERLAY_MODULE_INFO_SIZE = 0; +const int32_t WAIT_TIME = 5; // init mocked bms +} // namespace + +class BmsBundleGetOverlayModuleInfoTest : public testing::Test { +public: + BmsBundleGetOverlayModuleInfoTest(); + ~BmsBundleGetOverlayModuleInfoTest(); + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); + + void AddOverlayInnerBundleInfo(int32_t overlayType); + void AddNonOverlayInnerBundleInfo(); + void AddOverlayBundleInfo(); + void RemoveBundleInfo(const std::string &bundleName); + void CheckEnabledState(int32_t state); + void CheckOverlayModuleInfo(const OverlayModuleInfo &info); + void CheckOverlayBundleInfo(const OverlayBundleInfo &info); + + const std::shared_ptr GetBundleDataMgr() const; + +private: + static std::shared_ptr bundleMgrService_; +}; + +std::shared_ptr BmsBundleGetOverlayModuleInfoTest::bundleMgrService_ = + DelayedSingleton::GetInstance(); + +BmsBundleGetOverlayModuleInfoTest::BmsBundleGetOverlayModuleInfoTest() +{} + +BmsBundleGetOverlayModuleInfoTest::~BmsBundleGetOverlayModuleInfoTest() +{} + +void BmsBundleGetOverlayModuleInfoTest::SetUpTestCase() +{} + +void BmsBundleGetOverlayModuleInfoTest::TearDownTestCase() +{ + bundleMgrService_->OnStop(); +} +void BmsBundleGetOverlayModuleInfoTest::SetUp() +{ + if (!bundleMgrService_->IsServiceReady()) { + bundleMgrService_->OnStart(); + std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME)); + } +} + +void BmsBundleGetOverlayModuleInfoTest::TearDown() +{} + +void BmsBundleGetOverlayModuleInfoTest::AddOverlayInnerBundleInfo(int32_t overlayType) +{ + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.name = TEST_MODULE_NAME; + innerModuleInfo.moduleName = TEST_MODULE_NAME; + innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; + innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; + innerModuleInfo.hapPath = TEST_HAP_PATH; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + ApplicationInfo applicationInfo; + applicationInfo.bundleName = TEST_BUNDLE_NAME; + innerBundleInfo.SetBaseApplicationInfo(applicationInfo); + innerBundleInfo.SetOverlayType(overlayType); + + InnerModuleInfo secondInnerModuleInfo; + secondInnerModuleInfo.name = TEST_MODULE_NAME_SECOND; + secondInnerModuleInfo.moduleName = TEST_MODULE_NAME_SECOND; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME_SECOND, secondInnerModuleInfo); + + InnerModuleInfo targetModuleInfo; + targetModuleInfo.name = TARGET_MODULE_NAME; + targetModuleInfo.moduleName = TARGET_MODULE_NAME; + OverlayModuleInfo overlayModuleInfo; + overlayModuleInfo.bundleName = TEST_BUNDLE_NAME; + overlayModuleInfo.moduleName = TEST_MODULE_NAME; + overlayModuleInfo.targetModuleName = TARGET_MODULE_NAME; + overlayModuleInfo.hapPath = TEST_HAP_PATH; + overlayModuleInfo.priority = DEFAULT_TARGET_PRIORITY_SECOND; + targetModuleInfo.overlayModuleInfo.emplace_back(overlayModuleInfo); + innerBundleInfo.InsertInnerModuleInfo(TARGET_MODULE_NAME, targetModuleInfo); + + InnerBundleUserInfo userInfo; + userInfo.bundleUserInfo.userId = USERID; + std::string state = TEST_MODULE_NAME + Constants::FILE_UNDERLINE + std::to_string(OVERLAY_ENABLE); + userInfo.bundleUserInfo.overlayModulesState.emplace_back(state); + innerBundleInfo.AddInnerBundleUserInfo(userInfo); + + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); + dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, innerBundleInfo); +} + +void BmsBundleGetOverlayModuleInfoTest::AddNonOverlayInnerBundleInfo() +{ + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.name = TEST_MODULE_NAME; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + ApplicationInfo applicationInfo; + applicationInfo.bundleName = TEST_BUNDLE_NAME; + innerBundleInfo.SetBaseApplicationInfo(applicationInfo); + + InnerBundleUserInfo userInfo; + userInfo.bundleUserInfo.userId = USERID; + innerBundleInfo.AddInnerBundleUserInfo(userInfo); + + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + innerBundleInfo.SetBaseApplicationInfo(applicationInfo); + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); + dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, innerBundleInfo); +} + +void BmsBundleGetOverlayModuleInfoTest::RemoveBundleInfo(const std::string &bundleName) +{ + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + bool startRet = dataMgr->UpdateBundleInstallState(bundleName, InstallState::UNINSTALL_START); + bool finishRet = dataMgr->UpdateBundleInstallState(bundleName, InstallState::UNINSTALL_SUCCESS); + + EXPECT_TRUE(startRet); + EXPECT_TRUE(finishRet); +} + +void BmsBundleGetOverlayModuleInfoTest::CheckOverlayModuleInfo(const OverlayModuleInfo &info) +{ + EXPECT_EQ(info.bundleName, TEST_BUNDLE_NAME); + EXPECT_EQ(info.moduleName, TEST_MODULE_NAME); + EXPECT_EQ(info.hapPath, TEST_HAP_PATH); + EXPECT_EQ(info.targetModuleName, TARGET_MODULE_NAME); + EXPECT_EQ(info.state, OVERLAY_ENABLE); + EXPECT_EQ(info.priority, DEFAULT_TARGET_PRIORITY_SECOND); +} + +void BmsBundleGetOverlayModuleInfoTest::CheckOverlayBundleInfo(const OverlayBundleInfo &info) +{ + EXPECT_EQ(info.bundleName, TEST_BUNDLE_NAME); + EXPECT_EQ(info.bundleDir, TEST_OVERLAY_BUNDLE_DIR); + EXPECT_EQ(info.state, OVERLAY_ENABLE); + EXPECT_EQ(info.priority, DEFAULT_TARGET_PRIORITY_SECOND); +} + +void BmsBundleGetOverlayModuleInfoTest::AddOverlayBundleInfo() +{ + InnerBundleInfo innerBundleInfo; + OverlayBundleInfo info; + info.bundleName = TEST_BUNDLE_NAME; + info.bundleDir = TEST_OVERLAY_BUNDLE_DIR; + info.state = OVERLAY_ENABLE; + info.priority = DEFAULT_TARGET_PRIORITY_SECOND; + innerBundleInfo.AddOverlayBundleInfo(info); + + InnerBundleUserInfo userInfo; + userInfo.bundleUserInfo.userId = USERID; + innerBundleInfo.AddInnerBundleUserInfo(userInfo); + + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + dataMgr->UpdateBundleInstallState(TEST_TARGET_BUNDLE_NAME, InstallState::INSTALL_START); + dataMgr->AddInnerBundleInfo(TEST_TARGET_BUNDLE_NAME, innerBundleInfo); +} + +const std::shared_ptr BmsBundleGetOverlayModuleInfoTest::GetBundleDataMgr() const +{ + return bundleMgrService_->GetDataMgr(); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_0100 + * @tc.name: test GetAllOverlayModuleInfo interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified bundleName is not existed. + * 2.get failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0100, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + std::vector vec; + auto res = hostImpl->GetAllOverlayModuleInfo(TEST_BUNDLE_NAME, vec); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_0200 + * @tc.name: test GetAllOverlayModuleInfo interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified bundle is not installed at specified user. + * 2.get failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0200, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); + + std::vector vec; + auto res = hostImpl->GetAllOverlayModuleInfo(TEST_BUNDLE_NAME, vec, TEST_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); + RemoveBundleInfo(TEST_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_0300 + * @tc.name: test GetAllOverlayModuleInfo interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified bundle does not contain any overlay module. + * 2.get failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0300, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddNonOverlayInnerBundleInfo(); + + std::vector vec; + auto res = hostImpl->GetAllOverlayModuleInfo(TEST_BUNDLE_NAME, vec, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_NON_OVERLAY_BUNDLE); + RemoveBundleInfo(TEST_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_0400 + * @tc.name: test GetAllOverlayModuleInfo interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified bundle is valid bundle + * 2.get successfully. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0400, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); + + std::vector vec; + auto res = hostImpl->GetAllOverlayModuleInfo(TEST_BUNDLE_NAME, vec, USERID); + EXPECT_EQ(res, ERR_OK); + + EXPECT_EQ(vec.size(), OVERLAY_MODULE_INFO_SIZE); + CheckOverlayModuleInfo(vec[0]); + RemoveBundleInfo(TEST_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_0500 + * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified bundleName is not existed. + * 2.get failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0500, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + OverlayModuleInfo overlayModuleInfo; + auto res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_0600 + * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified bundle is not installed at specified user. + * 2.get failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0600, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); + + OverlayModuleInfo overlayModuleInfo; + auto res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, TEST_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); + RemoveBundleInfo(TEST_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_0700 + * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified bundle is not overlay bundle + * 2.get failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0700, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddNonOverlayInnerBundleInfo(); + + OverlayModuleInfo overlayModuleInfo; + auto res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_NON_OVERLAY_BUNDLE); + RemoveBundleInfo(TEST_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_0800 + * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified module is not existed. + * 2.get failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0800, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); + + OverlayModuleInfo overlayModuleInfo; + auto res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_MODULE_NAME_THIRD, overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_MODULE); + RemoveBundleInfo(TEST_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_0900 + * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified bundle is not overlay bundle + * 2.get failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0900, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); + + OverlayModuleInfo overlayModuleInfo; + auto res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_MODULE_NAME_SECOND, overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_NON_OVERLAY_MODULE); + auto res1 = hostImpl->GetOverlayModuleInfo("", TEST_MODULE_NAME_SECOND, overlayModuleInfo, USERID); + EXPECT_EQ(res1, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + auto res2 = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, "", overlayModuleInfo, USERID); + EXPECT_EQ(res2, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + RemoveBundleInfo(TEST_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_1100 + * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified bundle and module are valid + * 2.get successfully. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1100, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); + + OverlayModuleInfo overlayModuleInfo; + auto res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_OK); + + CheckOverlayModuleInfo(overlayModuleInfo); + RemoveBundleInfo(TEST_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_1200 + * @tc.name: test GetOverlayBundleInfoForTarget interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified target bundle name is not existed. + * 2.get failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1200, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + std::vector overlayBundleInfo; + auto res = hostImpl->GetOverlayBundleInfoForTarget(TEST_BUNDLE_NAME, overlayBundleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_NOT_EXISTED); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_1300 + * @tc.name: test GetOverlayBundleInfoForTarget interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified target bundle does not installed at specified user. + * 2.get failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1300, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddOverlayBundleInfo(); + + std::vector overlayBundleInfo; + auto res = hostImpl->GetOverlayBundleInfoForTarget(TEST_TARGET_BUNDLE_NAME, overlayBundleInfo, TEST_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); + RemoveBundleInfo(TEST_TARGET_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_1400 + * @tc.name: test GetOverlayBundleInfoForTarget interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified target bundle is valid. + * 2.get successfully. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1400, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddOverlayBundleInfo(); + + std::vector overlayBundleInfo; + auto res = hostImpl->GetOverlayBundleInfoForTarget(TEST_TARGET_BUNDLE_NAME, overlayBundleInfo, USERID); + EXPECT_EQ(res, ERR_OK); + + EXPECT_EQ(overlayBundleInfo.size(), OVERLAY_MODULE_INFO_SIZE); + CheckOverlayBundleInfo(overlayBundleInfo[0]); + RemoveBundleInfo(TEST_TARGET_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_1500 + * @tc.name: test GetOverlayBundleInfoForTarget interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified target bundle is valid. + * 2.get successfully. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1500, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddNonOverlayInnerBundleInfo(); + + std::vector overlayBundleInfo; + auto res = hostImpl->GetOverlayBundleInfoForTarget(TEST_BUNDLE_NAME, overlayBundleInfo, USERID); + EXPECT_EQ(res, ERR_OK); + EXPECT_EQ(overlayBundleInfo.size(), DEFAULT_OVERLAY_MODULE_INFO_SIZE); + RemoveBundleInfo(TEST_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_1600 + * @tc.name: test GetOverlayModuleInfoForTarget interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified target bundle is not existed. + * 2.get successfully. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1600, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + std::vector overlayModuleInfo; + auto res = hostImpl->GetOverlayModuleInfoForTarget(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_NOT_EXISTED); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_1700 + * @tc.name: test GetOverlayModuleInfoForTarget interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified target bundle is external overlay bundle. + * 2.get successfully. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1700, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddOverlayInnerBundleInfo(OverlayType::OVERLAY_EXTERNAL_BUNDLE); + + std::vector overlayModuleInfo; + auto res = hostImpl->GetOverlayModuleInfoForTarget(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_IS_OVERLAY_BUNDLE); + RemoveBundleInfo(TEST_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_1800 + * @tc.name: test GetOverlayModuleInfoForTarget interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified target bundle is not installed at specified user. + * 2.get failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1800, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); + + std::vector overlayModuleInfo; + auto res = hostImpl->GetOverlayModuleInfoForTarget(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, + TEST_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); + RemoveBundleInfo(TEST_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_1900 + * @tc.name: test GetOverlayModuleInfoForTarget interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified target module is not existed. + * 2.get failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1900, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); + + std::vector overlayModuleInfo; + auto res = hostImpl->GetOverlayModuleInfoForTarget(TEST_BUNDLE_NAME, TEST_MODULE_NAME_THIRD, overlayModuleInfo, + USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_MODULE_NOT_EXISTED); + RemoveBundleInfo(TEST_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_2000 + * @tc.name: test GetOverlayModuleInfoForTarget interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified target module is overlay module. + * 2.get failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_2000, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); + + std::vector overlayModuleInfo; + auto res = hostImpl->GetOverlayModuleInfoForTarget(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_MODULE_IS_OVERLAY_MODULE); + RemoveBundleInfo(TEST_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_2100 + * @tc.name: test GetOverlayModuleInfoForTarget interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified target bundle is valid. + * 2.get successfully. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_2100, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); + + std::vector overlayModuleInfo; + auto res = hostImpl->GetOverlayModuleInfoForTarget(TEST_BUNDLE_NAME, TEST_MODULE_NAME_SECOND, overlayModuleInfo, + USERID); + EXPECT_EQ(res, ERR_OK); + EXPECT_EQ(overlayModuleInfo.size(), DEFAULT_OVERLAY_MODULE_INFO_SIZE); + RemoveBundleInfo(TEST_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_2200 + * @tc.name: test GetOverlayModuleInfoForTarget interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified target bundle is valid. + * 2.get successfully. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_2200, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); + + std::vector overlayModuleInfo; + auto res = hostImpl->GetOverlayModuleInfoForTarget(TEST_BUNDLE_NAME, TARGET_MODULE_NAME, overlayModuleInfo, + USERID); + EXPECT_EQ(res, ERR_OK); + EXPECT_EQ(overlayModuleInfo.size(), OVERLAY_MODULE_INFO_SIZE); + + CheckOverlayModuleInfo(overlayModuleInfo[0]); + RemoveBundleInfo(TEST_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_2300 + * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl + * @tc.desc: 1.the specified bundle is valid bundle + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_2300, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + OverlayModuleInfo overlayModuleInfo; + auto res = hostImpl->GetOverlayModuleInfo("", overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_2400 + * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl + * @tc.desc: 1.the specified bundle is valid bundle + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_2400, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + OverlayModuleInfo overlayModuleInfo; + auto res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, overlayModuleInfo, UNSPECIFIED_USERID); + EXPECT_NE(res, ERR_OK); + + res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, overlayModuleInfo, USERID); + EXPECT_NE(res, ERR_OK); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_2500 + * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl + * @tc.desc: 1.the specified bundle is valid bundle + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_2500, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + std::vector overlayModuleInfos; + auto res = hostImpl->GetTargetOverlayModuleInfo(TARGET_MODULE_NAME, overlayModuleInfos, UNSPECIFIED_USERID); + EXPECT_NE(res, ERR_OK); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_2600 + * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl + * @tc.desc: 1.the specified bundle is valid bundle + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_2600, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + auto res = hostImpl->SetOverlayEnabledForSelf(TARGET_MODULE_NAME, false, UNSPECIFIED_USERID); + EXPECT_NE(res, ERR_OK); +} +} // OHOS diff --git a/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_manager_overlay_ipc_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_manager_overlay_ipc_test.cpp index b6454f65fc..0f3a537e8c 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_manager_overlay_ipc_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_manager_overlay_ipc_test.cpp @@ -1,207 +1,188 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "appexecfwk_errors.h" -#include "bundle_framework_core_ipc_interface_code.h" -#include "bundle_mgr_host_impl.h" -#include "bundle_mgr_proxy.h" -#include "bundle_mgr_service.h" - -using namespace testing::ext; -using namespace OHOS::AppExecFwk; - -namespace OHOS { -namespace { -const std::u16string TEST_HOST_DESCRIPTOR = u"ohos.bundleManager.test"; -const int32_t WAIT_TIME = 5; // init mocked bms -} // namespace -class BundleMgrHostImplMock : public BundleMgrHostImpl { -public: - BundleMgrHostImplMock() = default; - virtual ~BundleMgrHostImplMock() = default; - - virtual sptr GetOverlayManagerProxy() override; -}; - -sptr BundleMgrHostImplMock::GetOverlayManagerProxy() -{ - return nullptr; -} - -class BmsBundleManagerIpcTest : public testing::Test { -public: - BmsBundleManagerIpcTest(); - ~BmsBundleManagerIpcTest(); - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); -private: - static std::shared_ptr bundleMgrService_; -}; - -std::shared_ptr BmsBundleManagerIpcTest::bundleMgrService_ = - DelayedSingleton::GetInstance(); - -BmsBundleManagerIpcTest::BmsBundleManagerIpcTest() -{} - -BmsBundleManagerIpcTest::~BmsBundleManagerIpcTest() -{} - -void BmsBundleManagerIpcTest::SetUpTestCase() -{} - -void BmsBundleManagerIpcTest::TearDownTestCase() -{ - bundleMgrService_->OnStop(); -} - -void BmsBundleManagerIpcTest::SetUp() -{ - if (!bundleMgrService_->IsServiceReady()) { - bundleMgrService_->OnStart(); - std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME)); - } -} - -void BmsBundleManagerIpcTest::TearDown() -{} - -/** - * @tc.number: BundleManagerOverlayIpcTest_0100 - * @tc.name: test GetOverlayManagerProxy interface in BundleMgrProxy. - * @tc.desc: 1.construct BundleMgrProxy instance. - * 2.calling GetOverlayManagerProxy interface by using BundleMgrProxy instance. - * 3.remote object is nullptr. - * 4.return nullptr. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleManagerIpcTest, BundleManagerIpcTest_0100, Function | SmallTest | Level0) -{ - sptr bundleManagerProxy = new (std::nothrow) BundleMgrProxy(nullptr); - EXPECT_NE(bundleManagerProxy, nullptr); - - auto overlayProxy = bundleManagerProxy->GetOverlayManagerProxy(); - EXPECT_EQ(overlayProxy, nullptr); -} - -/** - * @tc.number: BundleManagerOverlayIpcTest_0200 - * @tc.name: test GetOverlayManagerProxy interface in BundleMgrProxy. - * @tc.desc: 1.construct BundleMgrProxy instance. - * 2.calling GetOverlayManagerProxy interface by using BundleMgrProxy instance. - * 3.return overlay proxy. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleManagerIpcTest, BundleManagerOverlayIpcTest_0200, Function | SmallTest | Level0) -{ - sptr bundleManagerHostImpl = new (std::nothrow) BundleMgrHostImpl(); - EXPECT_NE(bundleManagerHostImpl, nullptr); - sptr bundleManagerProxy = new (std::nothrow) BundleMgrProxy(bundleManagerHostImpl->AsObject()); - EXPECT_NE(bundleManagerProxy, nullptr); - - auto overlayProxy = bundleManagerProxy->GetOverlayManagerProxy(); - EXPECT_NE(overlayProxy, nullptr); -} - -/** - * @tc.number: BundleManagerOverlayIpcTest_0300 - * @tc.name: test GetOverlayManagerProxy interface in BundleMgrProxy. - * @tc.desc: 1.construct BundleMgrProxy instance. - * 2.calling GetOverlayManagerProxy interface by using BundleMgrProxy instance. - * 3.return overlay proxy. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleManagerIpcTest, BundleManagerOverlayIpcTest_0300, Function | SmallTest | Level0) -{ - sptr bundleManagerHostImpl = new (std::nothrow) BundleMgrHostImpl(); - EXPECT_NE(bundleManagerHostImpl, nullptr); - sptr bundleManagerProxy = new (std::nothrow) BundleMgrProxy(bundleManagerHostImpl->AsObject()); - EXPECT_NE(bundleManagerProxy, nullptr); - - auto overlayProxy = bundleManagerProxy->GetOverlayManagerProxy(); - EXPECT_NE(overlayProxy, nullptr); -} - -/** - * @tc.number: BundleManagerOverlayIpcTest_0400 - * @tc.name: test HandleGetOverlayManagerProxy interface in BundleMgrHost. - * @tc.desc: 1.construct BundleMgrHost instance. - * 2.calling HandleGetOverlayManagerProxy interface by using BundleMgrHost instance. - * 3.return failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleManagerIpcTest, BundleManagerOverlayIpcTest_0400, Function | SmallTest | Level0) -{ - sptr bundleManagerHostImplMock = new (std::nothrow) BundleMgrHostImplMock(); - EXPECT_NE(bundleManagerHostImplMock, nullptr); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - data.WriteInterfaceToken(BundleMgrHost::GetDescriptor()); - auto errCode = bundleManagerHostImplMock->OnRemoteRequest( - static_cast(BundleMgrInterfaceCode::GET_OVERLAY_MANAGER_PROXY), data, reply, option); - EXPECT_EQ(errCode, UNKNOWN_ERROR); -} - -/** - * @tc.number: BundleManagerOverlayIpcTest_0500 - * @tc.name: test HandleGetOverlayManagerProxy interface in BundleMgrHost. - * @tc.desc: 1.construct BundleMgrHost instance. - * 2.calling HandleGetOverlayManagerProxy interface by using BundleMgrHost instance. - * 3.error interface descriptor - * 3.return failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleManagerIpcTest, BundleManagerOverlayIpcTest_0500, Function | SmallTest | Level0) -{ - sptr bundleManagerHostImplMock = new (std::nothrow) BundleMgrHostImplMock(); - EXPECT_NE(bundleManagerHostImplMock, nullptr); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - data.WriteInterfaceToken(TEST_HOST_DESCRIPTOR); - auto errCode = bundleManagerHostImplMock->OnRemoteRequest( - static_cast(BundleMgrInterfaceCode::GET_OVERLAY_MANAGER_PROXY), data, reply, option); - EXPECT_EQ(errCode, OBJECT_NULL); -} - -/** - * @tc.number: BundleManagerOverlayIpcTest_0600 - * @tc.name: test HandleGetOverlayManagerProxy interface in BundleMgrHost. - * @tc.desc: 1.construct BundleMgrHost instance. - * 2.calling HandleGetOverlayManagerProxy interface by using BundleMgrHost instance. - * 3.return ERR_OK. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleManagerIpcTest, BundleManagerOverlayIpcTest_0600, Function | SmallTest | Level0) -{ - sptr bundleManagerHostImpl = new (std::nothrow) BundleMgrHostImpl(); - EXPECT_NE(bundleManagerHostImpl, nullptr); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - data.WriteInterfaceToken(BundleMgrHost::GetDescriptor()); - auto errCode = bundleManagerHostImpl->OnRemoteRequest( - static_cast(BundleMgrInterfaceCode::GET_OVERLAY_MANAGER_PROXY), data, reply, option); - EXPECT_EQ(errCode, ERR_OK); -} +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "appexecfwk_errors.h" +#include "bundle_framework_core_ipc_interface_code.h" +#include "bundle_mgr_host_impl.h" +#include "bundle_mgr_proxy.h" +#include "bundle_mgr_service.h" + +using namespace testing::ext; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace { +const std::u16string TEST_HOST_DESCRIPTOR = u"ohos.bundleManager.test"; +const int32_t WAIT_TIME = 5; // init mocked bms +} // namespace +class BundleMgrHostImplMock : public BundleMgrHostImpl { +public: + BundleMgrHostImplMock() = default; + virtual ~BundleMgrHostImplMock() = default; + + virtual sptr GetOverlayManagerProxy() override; +}; + +sptr BundleMgrHostImplMock::GetOverlayManagerProxy() +{ + return nullptr; +} + +class BmsBundleManagerIpcTest : public testing::Test { +public: + BmsBundleManagerIpcTest(); + ~BmsBundleManagerIpcTest(); + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +private: + static std::shared_ptr bundleMgrService_; +}; + +std::shared_ptr BmsBundleManagerIpcTest::bundleMgrService_ = + DelayedSingleton::GetInstance(); + +BmsBundleManagerIpcTest::BmsBundleManagerIpcTest() +{} + +BmsBundleManagerIpcTest::~BmsBundleManagerIpcTest() +{} + +void BmsBundleManagerIpcTest::SetUpTestCase() +{} + +void BmsBundleManagerIpcTest::TearDownTestCase() +{ + bundleMgrService_->OnStop(); +} + +void BmsBundleManagerIpcTest::SetUp() +{ + if (!bundleMgrService_->IsServiceReady()) { + bundleMgrService_->OnStart(); + std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME)); + } +} + +void BmsBundleManagerIpcTest::TearDown() +{} + +/** + * @tc.number: BundleManagerOverlayIpcTest_0100 + * @tc.name: test GetOverlayManagerProxy interface in BundleMgrProxy. + * @tc.desc: 1.construct BundleMgrProxy instance. + * 2.calling GetOverlayManagerProxy interface by using BundleMgrProxy instance. + * 3.remote object is nullptr. + * 4.return nullptr. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleManagerIpcTest, BundleManagerIpcTest_0100, Function | SmallTest | Level0) +{ + sptr bundleManagerProxy = new (std::nothrow) BundleMgrProxy(nullptr); + EXPECT_NE(bundleManagerProxy, nullptr); + + auto overlayProxy = bundleManagerProxy->GetOverlayManagerProxy(); + EXPECT_EQ(overlayProxy, nullptr); +} + +/** + * @tc.number: BundleManagerOverlayIpcTest_0200 + * @tc.name: test GetOverlayManagerProxy interface in BundleMgrProxy. + * @tc.desc: 1.construct BundleMgrProxy instance. + * 2.calling GetOverlayManagerProxy interface by using BundleMgrProxy instance. + * 3.return overlay proxy. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleManagerIpcTest, BundleManagerOverlayIpcTest_0200, Function | SmallTest | Level0) +{ + sptr bundleManagerHostImpl = new (std::nothrow) BundleMgrHostImpl(); + EXPECT_NE(bundleManagerHostImpl, nullptr); + sptr bundleManagerProxy = new (std::nothrow) BundleMgrProxy(bundleManagerHostImpl->AsObject()); + EXPECT_NE(bundleManagerProxy, nullptr); + + auto overlayProxy = bundleManagerProxy->GetOverlayManagerProxy(); + EXPECT_NE(overlayProxy, nullptr); +} + +/** + * @tc.number: BundleManagerOverlayIpcTest_0400 + * @tc.name: test HandleGetOverlayManagerProxy interface in BundleMgrHost. + * @tc.desc: 1.construct BundleMgrHost instance. + * 2.calling HandleGetOverlayManagerProxy interface by using BundleMgrHost instance. + * 3.return failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleManagerIpcTest, BundleManagerOverlayIpcTest_0400, Function | SmallTest | Level0) +{ + sptr bundleManagerHostImplMock = new (std::nothrow) BundleMgrHostImplMock(); + EXPECT_NE(bundleManagerHostImplMock, nullptr); + + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteInterfaceToken(BundleMgrHost::GetDescriptor()); + auto errCode = bundleManagerHostImplMock->OnRemoteRequest( + static_cast(BundleMgrInterfaceCode::GET_OVERLAY_MANAGER_PROXY), data, reply, option); + EXPECT_EQ(errCode, UNKNOWN_ERROR); +} + +/** + * @tc.number: BundleManagerOverlayIpcTest_0500 + * @tc.name: test HandleGetOverlayManagerProxy interface in BundleMgrHost. + * @tc.desc: 1.construct BundleMgrHost instance. + * 2.calling HandleGetOverlayManagerProxy interface by using BundleMgrHost instance. + * 3.error interface descriptor + * 3.return failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleManagerIpcTest, BundleManagerOverlayIpcTest_0500, Function | SmallTest | Level0) +{ + sptr bundleManagerHostImplMock = new (std::nothrow) BundleMgrHostImplMock(); + EXPECT_NE(bundleManagerHostImplMock, nullptr); + + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteInterfaceToken(TEST_HOST_DESCRIPTOR); + auto errCode = bundleManagerHostImplMock->OnRemoteRequest( + static_cast(BundleMgrInterfaceCode::GET_OVERLAY_MANAGER_PROXY), data, reply, option); + EXPECT_EQ(errCode, OBJECT_NULL); +} + +/** + * @tc.number: BundleManagerOverlayIpcTest_0600 + * @tc.name: test HandleGetOverlayManagerProxy interface in BundleMgrHost. + * @tc.desc: 1.construct BundleMgrHost instance. + * 2.calling HandleGetOverlayManagerProxy interface by using BundleMgrHost instance. + * 3.return ERR_OK. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleManagerIpcTest, BundleManagerOverlayIpcTest_0600, Function | SmallTest | Level0) +{ + sptr bundleManagerHostImpl = new (std::nothrow) BundleMgrHostImpl(); + EXPECT_NE(bundleManagerHostImpl, nullptr); + + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteInterfaceToken(BundleMgrHost::GetDescriptor()); + auto errCode = bundleManagerHostImpl->OnRemoteRequest( + static_cast(BundleMgrInterfaceCode::GET_OVERLAY_MANAGER_PROXY), data, reply, option); + EXPECT_EQ(errCode, ERR_OK); +} } // OHOS \ No newline at end of file diff --git a/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_overlay_checker_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_overlay_checker_test.cpp index 580740867d..243c041d76 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_overlay_checker_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_overlay_checker_test.cpp @@ -1,2925 +1,2836 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#define private public - -#include - -#include "appexecfwk_errors.h" -#include "bundle_overlay_data_manager.h" -#include "bundle_overlay_install_checker.h" -#include "bundle_overlay_manager.h" -#include "bundle_mgr_service.h" - -#include - -using namespace testing::ext; -using namespace OHOS::AppExecFwk; -using OHOS::DelayedSingleton; - -namespace OHOS { -namespace { -const std::string TEST_MODULE_NAME = "testModuleName"; -const std::string TEST_MODULE_NAME_SECOND = "testModuleNameSecond"; -const std::string TARGET_MODULE_NAME = "targetModuleName"; -const std::string OTHER_TARGET_MODULE_NAME = "targetModuleNameTest"; -const std::string TARGET_BUNDLE_NAME = "targetBundleName"; -const std::string TEST_BUNDLE_NAME = "testBundleName"; -const std::string TEST_BUNDLE_NAME2 = "testBundleName2"; -const std::string TEST_PATH_FIRST = "testPath1"; -const std::string TEST_PATH_SECOND = "testPath2"; -const std::string TEST_PACK_AGE = "modulePackage"; -const std::string NO_EXIST = "noExist"; -const std::string BUNDLE_NAME = "oho.test.bundleName"; -const std::string SHARED_HAP_TYPE = "shared"; -const std::string FEATURE_HAP_TYPE = "feature"; -const std::string SHARED_TYPE = "shared"; -const int32_t INVALID_TARGET_PRIORITY_FIRST = 0; -const int32_t INVALID_TARGET_PRIORITY_SECOND = 101; -const int32_t DEFAULT_TARGET_PRIORITY_SECOND = 1; -const int32_t TEST_VERSION_CODE = 1000000; -const int32_t LOWER_TEST_VERSION_CODE = 999999; -const int32_t HIGHER_TEST_VERSION_CODE = 1000001; -const int32_t USERID = 100; -const int32_t NOT_EXIST_USERID = -5; -const int32_t FOUR = 4; -const int32_t DEFAULT_OVERLAY_BUNDLE_INFO = 0; -const int32_t WAIT_TIME = 5; // init mocked bms -} // namespace - -class BmsBundleOverlayCheckerTest : public testing::Test { -public: - BmsBundleOverlayCheckerTest(); - ~BmsBundleOverlayCheckerTest(); - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); - void AddInnerBundleInfo(); - void UninstallBundleInfo(); - void BuildInternalOverlayConnection(const std::string &moduleName, InnerBundleInfo &oldInfo, int32_t userId); - void RemoveOverlayBundleInfo(const std::string &targetBundleName, InnerBundleInfo &targetInnerBundleInfo); - void AddOverlayModuleStates(const InnerBundleInfo &innerBundleInfo, InnerBundleUserInfo &userInfo); - void ClearDataMgr(); - void ResetDataMgr(); - - const std::shared_ptr GetBundleDataMgr() const; - const std::shared_ptr GetBundleOverlayChecker() const; - -private: - std::shared_ptr overlayChecker_ = std::make_shared(); - static std::shared_ptr bundleMgrService_; -}; - -std::shared_ptr BmsBundleOverlayCheckerTest::bundleMgrService_ = - DelayedSingleton::GetInstance(); - -BmsBundleOverlayCheckerTest::BmsBundleOverlayCheckerTest() -{} - -BmsBundleOverlayCheckerTest::~BmsBundleOverlayCheckerTest() -{} - -void BmsBundleOverlayCheckerTest::SetUpTestCase() -{} - -void BmsBundleOverlayCheckerTest::TearDownTestCase() -{ - bundleMgrService_->OnStop(); -} - -void BmsBundleOverlayCheckerTest::SetUp() -{ - if (!bundleMgrService_->IsServiceReady()) { - bundleMgrService_->OnStart(); - std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME)); - } -} - -void BmsBundleOverlayCheckerTest::BuildInternalOverlayConnection( - const std::string &moduleName, InnerBundleInfo &oldInfo, int32_t userId) -{ - OverlayDataMgr overlayDataMgr; - return overlayDataMgr.BuildInternalOverlayConnection(TEST_MODULE_NAME, oldInfo, USERID); -} - -void BmsBundleOverlayCheckerTest::RemoveOverlayBundleInfo( - const std::string &targetBundleName, InnerBundleInfo &targetInnerBundleInfo) -{ - OverlayDataMgr overlayDataMgr; - return overlayDataMgr.RemoveOverlayBundleInfo(TEST_MODULE_NAME, targetInnerBundleInfo); -} - -void BmsBundleOverlayCheckerTest::AddOverlayModuleStates( - const InnerBundleInfo &innerBundleInfo, InnerBundleUserInfo &userInfo) -{ - OverlayDataMgr overlayDataMgr; - return overlayDataMgr.AddOverlayModuleStates(innerBundleInfo, userInfo); -} - -void BmsBundleOverlayCheckerTest::ClearDataMgr() -{ - bundleMgrService_->dataMgr_ = nullptr; -} - -void BmsBundleOverlayCheckerTest::ResetDataMgr() -{ - bundleMgrService_->dataMgr_ = std::make_shared(); - EXPECT_NE(bundleMgrService_->dataMgr_, nullptr); -} - -void BmsBundleOverlayCheckerTest::TearDown() -{} - -void BmsBundleOverlayCheckerTest::AddInnerBundleInfo() -{ - // construct innerBundleInfo - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.name = TEST_MODULE_NAME; - innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; - innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - ApplicationInfo applicationInfo; - applicationInfo.bundleName = TEST_BUNDLE_NAME; - applicationInfo.targetBundleName = TEST_BUNDLE_NAME; - innerBundleInfo.SetBaseApplicationInfo(applicationInfo); - - // construct target module - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - InnerBundleInfo oldInfo; - InnerModuleInfo targetModuleInfo; - targetModuleInfo.name = TARGET_MODULE_NAME; - targetModuleInfo.targetModuleName = OTHER_TARGET_MODULE_NAME; - targetModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; - ApplicationInfo targetApplicationInfo; - targetApplicationInfo.bundleName = TEST_BUNDLE_NAME; - - oldInfo.InsertInnerModuleInfo(TARGET_MODULE_NAME, targetModuleInfo); - oldInfo.SetBaseApplicationInfo(targetApplicationInfo); - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); - dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, oldInfo); -} - -void BmsBundleOverlayCheckerTest::UninstallBundleInfo() -{ - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - bool startRet = dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_START); - bool finishRet = dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_SUCCESS); - - EXPECT_TRUE(startRet); - EXPECT_TRUE(finishRet); -} - -const std::shared_ptr BmsBundleOverlayCheckerTest::GetBundleDataMgr() const -{ - return bundleMgrService_->GetDataMgr(); -} - -const std::shared_ptr BmsBundleOverlayCheckerTest::GetBundleOverlayChecker() const -{ - return overlayChecker_; -} - -/** - * @tc.number: OverlayCheckerTest_0100 - * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. - * @tc.desc: 1.the internal overlay hap is entry type. - * 2.check failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0100, Function | SmallTest | Level0) -{ - // construct innerBundleInfo - InnerModuleInfo innerModuleInfo; - Distro distro; - distro.moduleType = FEATURE_HAP_TYPE; - innerModuleInfo.distro = distro; - innerModuleInfo.name = TEST_MODULE_NAME; - InnerBundleInfo innerBundleInfo; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - std::unordered_map newInfos; - - auto overlayChecker = GetBundleOverlayChecker(); - EXPECT_NE(overlayChecker, nullptr); - auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_HAP_TYPE); -} - -/** - * @tc.number: OverlayCheckerTest_0200 - * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. - * @tc.desc: 1.the internal overlay bundle is service. - * 2.check failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0200, Function | SmallTest | Level0) -{ - // construct innerBundleInfo - InnerModuleInfo innerModuleInfo; - innerModuleInfo.name = TEST_MODULE_NAME; - Distro distro; - distro.moduleType = SHARED_HAP_TYPE; - innerModuleInfo.distro = distro; - InnerBundleInfo innerBundleInfo; - innerBundleInfo.SetEntryInstallationFree(true); - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - std::unordered_map newInfos; - - auto overlayChecker = GetBundleOverlayChecker(); - EXPECT_NE(overlayChecker, nullptr); - auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_BUNDLE_TYPE); -} - -/** - * @tc.number: OverlayCheckerTest_0400 - * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. - * @tc.desc: 1.target priority of internal overlay hap is invalid. - * 2.check failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0400, Function | SmallTest | Level0) -{ - // construct innerBundleInfo - InnerModuleInfo innerModuleInfo; - innerModuleInfo.name = TEST_MODULE_NAME; - Distro distro; - distro.moduleType = SHARED_HAP_TYPE; - innerModuleInfo.distro = distro; - innerModuleInfo.targetPriority = INVALID_TARGET_PRIORITY_FIRST; - InnerBundleInfo innerBundleInfo; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - std::unordered_map newInfos; - - auto overlayChecker = GetBundleOverlayChecker(); - EXPECT_NE(overlayChecker, nullptr); - auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_PRIORITY); -} - -/** - * @tc.number: OverlayCheckerTest_0500 - * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. - * @tc.desc: 1.target priority of internal overlay hap is invalid. - * 2.check failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0500, Function | SmallTest | Level0) -{ - // construct innerBundleInfo - InnerModuleInfo innerModuleInfo; - innerModuleInfo.name = TEST_MODULE_NAME; - Distro distro; - distro.moduleType = SHARED_HAP_TYPE; - innerModuleInfo.distro = distro; - innerModuleInfo.targetPriority = INVALID_TARGET_PRIORITY_SECOND; - InnerBundleInfo innerBundleInfo; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - std::unordered_map newInfos; - auto overlayChecker = GetBundleOverlayChecker(); - EXPECT_NE(overlayChecker, nullptr); - auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_PRIORITY); -} - -/** - * @tc.number: OverlayCheckerTest_0600 - * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. - * @tc.desc: 1.target module name of the internal overlay is same as the module name. - * 2.check failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0600, Function | SmallTest | Level0) -{ - // construct innerBundleInfo - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.name = TEST_MODULE_NAME; - innerModuleInfo.targetModuleName = TEST_MODULE_NAME; - innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; - Distro distro; - distro.moduleType = SHARED_HAP_TYPE; - innerModuleInfo.distro = distro; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - std::unordered_map newInfos; - - auto overlayChecker = GetBundleOverlayChecker(); - EXPECT_NE(overlayChecker, nullptr); - auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_MODULE_NAME); -} - -/** - * @tc.number: OverlayCheckerTest_0700 - * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. - * @tc.desc: 1.target module is overlay module. - * 2.check failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0700, Function | SmallTest | Level0) -{ - // construct innerBundleInfo - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.name = TEST_MODULE_NAME; - innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; - innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; - Distro distro; - distro.moduleType = SHARED_HAP_TYPE; - innerModuleInfo.distro = distro; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - ApplicationInfo applicationInfo; - applicationInfo.bundleName = TEST_BUNDLE_NAME; - innerBundleInfo.SetBaseApplicationInfo(applicationInfo); - - // construct target module - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - InnerBundleInfo oldInfo; - InnerModuleInfo targetModuleInfo; - targetModuleInfo.name = TARGET_MODULE_NAME; - targetModuleInfo.targetModuleName = OTHER_TARGET_MODULE_NAME; - targetModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; - Distro targetDistro; - targetDistro.moduleType = SHARED_HAP_TYPE; - innerModuleInfo.distro = targetDistro; - ApplicationInfo targetApplicationInfo; - targetApplicationInfo.bundleName = TEST_BUNDLE_NAME; - - oldInfo.InsertInnerModuleInfo(TARGET_MODULE_NAME, targetModuleInfo); - oldInfo.SetBaseApplicationInfo(targetApplicationInfo); - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); - dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, oldInfo); - std::unordered_map newInfos; - - auto overlayChecker = GetBundleOverlayChecker(); - EXPECT_NE(overlayChecker, nullptr); - auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_TARGET_MODULE_IS_OVERLAY_MODULE); - - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_START); - bool ret = dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_SUCCESS); - EXPECT_TRUE(ret); -} - -/** - * @tc.number: OverlayCheckerTest_0800 - * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. - * @tc.desc: 1.install overlay hap and non-overlay hap simultaneously. - * 2.check successfully. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0800, Function | SmallTest | Level0) -{ - // construct overlay innerBundleInfo - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.name = TEST_MODULE_NAME; - innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; - innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; - Distro distro; - distro.moduleType = SHARED_HAP_TYPE; - innerModuleInfo.distro = distro; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - - // construct non-overlay innerBundleInfo - InnerBundleInfo nonOverlayBundleInfo; - InnerModuleInfo nonInnerModuleInfo; - nonInnerModuleInfo.name = TEST_MODULE_NAME_SECOND; - nonOverlayBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME_SECOND); - nonOverlayBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME_SECOND, nonInnerModuleInfo); - - std::unordered_map newInfos; - newInfos.emplace(TEST_PATH_FIRST, innerBundleInfo); - newInfos.emplace(TEST_PATH_SECOND, nonOverlayBundleInfo); - - auto overlayChecker = GetBundleOverlayChecker(); - EXPECT_NE(overlayChecker, nullptr); - auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: OverlayCheckerTest_0900 - * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. - * @tc.desc: 1.install internal overlay hap. - * 2.the version code of overlay hap is larger than non-overlay module. - * 3.check failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0900, Function | SmallTest | Level0) -{ - // construct overlay innerBundleInfo - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.name = TEST_MODULE_NAME; - innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; - innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; - Distro distro; - distro.moduleType = SHARED_HAP_TYPE; - innerModuleInfo.distro = distro; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - BundleInfo bundleInfo; - bundleInfo.versionCode = HIGHER_TEST_VERSION_CODE; - innerBundleInfo.SetBaseBundleInfo(bundleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - ApplicationInfo applicationInfo; - applicationInfo.bundleName = TEST_BUNDLE_NAME; - innerBundleInfo.SetBaseApplicationInfo(applicationInfo); - std::unordered_map newInfos; - - // construct old innerBundleInfo - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - InnerBundleInfo oldInfo; - InnerModuleInfo oldInnerModuleInfo; - oldInnerModuleInfo.name = TEST_MODULE_NAME_SECOND; - oldInfo.InsertInnerModuleInfo(TEST_MODULE_NAME_SECOND, oldInnerModuleInfo); - BundleInfo oldBundleInfo; - oldBundleInfo.versionCode = TEST_VERSION_CODE; - oldInfo.SetBaseBundleInfo(oldBundleInfo); - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); - dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, oldInfo); - - auto overlayChecker = GetBundleOverlayChecker(); - EXPECT_NE(overlayChecker, nullptr); - auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INCONSISTENT_VERSION_CODE); - - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_START); - bool ret = dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_SUCCESS); - EXPECT_TRUE(ret); -} - -/** - * @tc.number: OverlayCheckerTest_1000 - * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. - * @tc.desc: 1.install internal overlay hap. - * 2.the version code of overlay hap is lower than non-overlay module. - * 3.check failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_1000, Function | SmallTest | Level0) -{ - // construct overlay innerBundleInfo - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.name = TEST_MODULE_NAME; - innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; - innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; - Distro distro; - distro.moduleType = SHARED_HAP_TYPE; - innerModuleInfo.distro = distro; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - BundleInfo bundleInfo; - bundleInfo.versionCode = LOWER_TEST_VERSION_CODE; - innerBundleInfo.SetBaseBundleInfo(bundleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - ApplicationInfo applicationInfo; - applicationInfo.bundleName = TEST_BUNDLE_NAME; - innerBundleInfo.SetBaseApplicationInfo(applicationInfo); - std::unordered_map newInfos; - - // construct old innerBundleInfo - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - InnerBundleInfo oldInfo; - InnerModuleInfo oldInnerModuleInfo; - oldInnerModuleInfo.name = TEST_MODULE_NAME_SECOND; - oldInfo.InsertInnerModuleInfo(TEST_MODULE_NAME_SECOND, oldInnerModuleInfo); - BundleInfo oldBundleInfo; - oldBundleInfo.versionCode = TEST_VERSION_CODE; - oldInfo.SetBaseBundleInfo(oldBundleInfo); - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); - dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, oldInfo); - - auto overlayChecker = GetBundleOverlayChecker(); - EXPECT_NE(overlayChecker, nullptr); - auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INCONSISTENT_VERSION_CODE); - - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_START); - bool ret = dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_SUCCESS); - EXPECT_TRUE(ret); -} - -/** - * @tc.number: BundleOverlayManagerTest_0100 - * @tc.name: check param is empty - * @tc.desc: 1.Test BundleOverlayManager - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, BundleOverlayManagerTest_0100, Function | SmallTest | Level0) -{ - BundleOverlayManager manager; - std::string bundleName = ""; - bool ret = manager.IsExistedNonOverlayHap(bundleName); - EXPECT_EQ(ret, false); - InnerBundleInfo innerBundleInfo; - ret = manager.GetInnerBundleInfo(bundleName, innerBundleInfo); - EXPECT_EQ(ret, false); - - int32_t userId = Constants::INVALID_USERID; - std::vector overlayModuleInfos; - auto code = manager.GetAllOverlayModuleInfo(bundleName, overlayModuleInfos, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - code = manager.GetAllOverlayModuleInfo("com.ohos.test", overlayModuleInfos, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - - std::string moduleName = ""; - OverlayModuleInfo overlayModuleInfo; - code = manager.GetOverlayModuleInfo(bundleName, moduleName, overlayModuleInfo, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - code = manager.GetOverlayModuleInfo("com.ohos.test", moduleName, overlayModuleInfo, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - code = manager.GetOverlayModuleInfo("com.ohos.test", "entry", overlayModuleInfo, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - - std::string targetBundleName = ""; - std::vector overlayBundleInfo; - code = manager.GetOverlayBundleInfoForTarget(targetBundleName, overlayBundleInfo, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - code = manager.GetOverlayBundleInfoForTarget("target", overlayBundleInfo, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - - code = manager.GetOverlayModuleInfoForTarget(targetBundleName, "", overlayModuleInfos, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - code = manager.GetOverlayModuleInfoForTarget("target", "", overlayModuleInfos, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - - userId = Constants::DEFAULT_USERID; - code = manager.GetAllOverlayModuleInfo("com.ohos.test", overlayModuleInfos, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); - code = manager.GetOverlayModuleInfo("com.ohos.test", "entry", overlayModuleInfo, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); -} - -/** - * @tc.number: CheckInternalBundle_0100 - * @tc.name: check hap type failed - * @tc.desc: 1.Test CheckInternalBundle - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckInternalBundle_0100, Function | SmallTest | Level0) -{ - BundleOverlayInstallChecker checker; - std::unordered_map newInfos; - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.isEntry = true; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - auto code = checker.CheckInternalBundle(newInfos, innerBundleInfo); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_HAP_TYPE); - innerModuleInfo.isEntry = false; - code = checker.CheckInternalBundle(newInfos, innerBundleInfo); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_HAP_TYPE); - - innerBundleInfo.SetEntryInstallationFree(true); - code = checker.CheckInternalBundle(newInfos, innerBundleInfo); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_HAP_TYPE); -} - -/** - * @tc.number: CheckInternalBundle_0200 - * @tc.name: check module target priority range - * @tc.desc: 1.Test CheckInternalBundle - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckInternalBundle_0200, Function | SmallTest | Level0) -{ - BundleOverlayInstallChecker checker; - std::unordered_map newInfos; - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - Distro distro; - distro.moduleType = SHARED_HAP_TYPE; - innerModuleInfo.distro = distro; - innerModuleInfo.targetPriority = Constants::OVERLAY_MINIMUM_PRIORITY - 1; - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - auto code = checker.CheckInternalBundle(newInfos, innerBundleInfo); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_PRIORITY); -} - -/** - * @tc.number: CheckInternalBundle_0300 - * @tc.name: check module target priority range - * @tc.desc: 1.Test CheckInternalBundle - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckInternalBundle_0300, Function | SmallTest | Level0) -{ - BundleOverlayInstallChecker checker; - std::unordered_map newInfos; - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - Distro distro; - distro.moduleType = SHARED_HAP_TYPE; - innerModuleInfo.distro = distro; - innerModuleInfo.targetPriority = Constants::OVERLAY_MINIMUM_PRIORITY + 1; - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - innerModuleInfo.targetModuleName = TEST_MODULE_NAME; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - - auto code = checker.CheckInternalBundle(newInfos, innerBundleInfo); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_MODULE_NAME); -} - -/** - * @tc.number: CheckExternalBundle_0100 - * @tc.name: check bundle priority - * @tc.desc: 1.Test CheckExternalBundle - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckExternalBundle_0100, Function | SmallTest | Level0) -{ - BundleOverlayInstallChecker checker; - InnerBundleInfo innerBundleInfo; - int32_t userId = Constants::INVALID_USERID; - BundleInfo bundleInfo; - bundleInfo.entryInstallationFree = true; - innerBundleInfo.SetBaseBundleInfo(bundleInfo); - auto code = checker.CheckExternalBundle(innerBundleInfo, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_BUNDLE_TYPE); - - bundleInfo.entryInstallationFree = false; - innerBundleInfo.SetBaseBundleInfo(bundleInfo); - ApplicationInfo applicationInfo; - applicationInfo.targetPriority = Constants::OVERLAY_MINIMUM_PRIORITY - 1; - innerBundleInfo.SetBaseApplicationInfo(applicationInfo); - InnerModuleInfo innerModuleInfo; - Distro distro; - distro.moduleType = SHARED_HAP_TYPE; - innerModuleInfo.distro = distro; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - code = checker.CheckExternalBundle(innerBundleInfo, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_PRIORITY); - - applicationInfo.targetPriority = Constants::OVERLAY_MAXIMUM_PRIORITY + 1; - innerBundleInfo.SetBaseApplicationInfo(applicationInfo); - code = checker.CheckExternalBundle(innerBundleInfo, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_PRIORITY); -} - -/** - * @tc.number: CheckExternalBundle_0200 - * @tc.name: check bundle priority - * @tc.desc: 1.Test CheckExternalBundle - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckExternalBundle_0200, Function | SmallTest | Level0) -{ - BundleOverlayInstallChecker checker; - InnerBundleInfo innerBundleInfo; - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - int32_t userId = Constants::INVALID_USERID; - ApplicationInfo applicationInfo; - applicationInfo.bundleName = TEST_BUNDLE_NAME; - applicationInfo.targetBundleName = TEST_BUNDLE_NAME; - applicationInfo.targetPriority = Constants::OVERLAY_MINIMUM_PRIORITY + 1; - innerBundleInfo.SetBaseApplicationInfo(applicationInfo); - InnerModuleInfo innerModuleInfo; - innerModuleInfo.targetPriority = Constants::OVERLAY_MINIMUM_PRIORITY + 1; - Distro distro; - distro.moduleType = SHARED_HAP_TYPE; - innerModuleInfo.distro = distro; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - auto code = checker.CheckExternalBundle(innerBundleInfo, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_BUNDLE_NAME_SAME_WITH_TARGET_BUNDLE_NAME); - applicationInfo.bundleName = ""; - innerBundleInfo.SetBaseApplicationInfo(applicationInfo); - code = checker.CheckExternalBundle(innerBundleInfo, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_NO_SYSTEM_APPLICATION_FOR_EXTERNAL_OVERLAY); - - innerBundleInfo.SetIsPreInstallApp(true); - code = checker.CheckExternalBundle(innerBundleInfo, userId); - EXPECT_EQ(code, ERR_OK); - - innerBundleInfo.SetCurrentModulePackage(SHARED_TYPE); - code = checker.CheckExternalBundle(innerBundleInfo, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_HAP_TYPE); -} - -/** - * @tc.number: OverlayDataMgr_0100 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of UpdateOverlayInfo. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0100, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - InnerBundleInfo targetInnerBundleInfo; - - newInfo.SetOverlayType(OverlayType::OVERLAY_INTERNAL_BUNDLE); - ErrCode res = overlayDataMgr.UpdateOverlayInfo(newInfo, oldInfo, targetInnerBundleInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); - newInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); - res = overlayDataMgr.UpdateOverlayInfo(newInfo, oldInfo, targetInnerBundleInfo); - EXPECT_EQ(res, ERR_OK); - newInfo.SetOverlayType(OverlayType::NON_OVERLAY_TYPE); - res = overlayDataMgr.UpdateOverlayInfo(newInfo, oldInfo, targetInnerBundleInfo); - EXPECT_EQ(res, ERR_OK); - - newInfo.SetOverlayType(FOUR); - res = overlayDataMgr.UpdateOverlayInfo(newInfo, oldInfo, targetInnerBundleInfo); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: OverlayDataMgr_0200 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of IsExistedNonOverlayHap. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0200, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - bool res = overlayDataMgr.IsExistedNonOverlayHap(""); - EXPECT_EQ(res, false); - res = overlayDataMgr.IsExistedNonOverlayHap("wrong"); - EXPECT_EQ(res, false); -} - -/** - * @tc.number: OverlayDataMgr_0300 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of UpdateInternalOverlayInfo. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0300, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - ErrCode res = overlayDataMgr.UpdateInternalOverlayInfo(newInfo, oldInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); - std::map innerModuleInfos; - InnerModuleInfo moduleInfo; - moduleInfo.moduleName = TEST_PACK_AGE; - moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; - innerModuleInfos[TEST_PACK_AGE] = moduleInfo; - newInfo.AddInnerModuleInfo(innerModuleInfos); - res = overlayDataMgr.UpdateInternalOverlayInfo(newInfo, oldInfo); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: OverlayDataMgr_0400 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of UpdateExternalOverlayInfo. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0400, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo innerBundleInfo; - InnerBundleInfo oldInfo; - InnerBundleInfo targetInnerBundleInfo; - - ErrCode res = overlayDataMgr.UpdateExternalOverlayInfo(innerBundleInfo, oldInfo, targetInnerBundleInfo); - EXPECT_EQ(res, ERR_OK); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - ApplicationInfo applicationInfo; - applicationInfo.bundleName = TEST_BUNDLE_NAME; - innerBundleInfo.SetBaseApplicationInfo(applicationInfo); - - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - ApplicationInfo targetApplicationInfo; - targetApplicationInfo.bundleName = TEST_BUNDLE_NAME; - - oldInfo.SetBaseApplicationInfo(targetApplicationInfo); - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); - dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, oldInfo); - innerBundleInfo.SetTargetBundleName(TEST_BUNDLE_NAME); - res = overlayDataMgr.UpdateExternalOverlayInfo(innerBundleInfo, oldInfo, oldInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); - - InnerModuleInfo moduleInfo; - std::map innerModuleInfos; - moduleInfo.moduleName = "moduleName"; - moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; - innerModuleInfos[TEST_PACK_AGE] = moduleInfo; - innerBundleInfo.AddInnerModuleInfo(innerModuleInfos); - res = overlayDataMgr.UpdateExternalOverlayInfo(innerBundleInfo, oldInfo, oldInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); - - innerBundleInfo.SetUserId(Constants::NOT_EXIST_USERID); - res = overlayDataMgr.UpdateExternalOverlayInfo(innerBundleInfo, oldInfo, oldInfo); - EXPECT_EQ(res, ERR_OK); - UninstallBundleInfo(); -} - -/** - * @tc.number: OverlayDataMgr_0500 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of UpdateExternalOverlayInfo. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0500, Function | SmallTest | Level0) -{ - AddInnerBundleInfo(); - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - InnerBundleInfo targetInnerBundleInfo; - - OverlayDataMgr overlayDataMgr; - ErrCode res = overlayDataMgr.UpdateExternalOverlayInfo(newInfo, oldInfo, targetInnerBundleInfo); - EXPECT_EQ(res, ERR_OK); - UninstallBundleInfo(); -} - -#ifdef BUNDLE_FRAMEWORK_OVERLAY_INSTALLATION -/** - * @tc.number: OverlayDataMgr_0600 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of BuildOverlayConnection and BuildOverlayConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0600, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - const auto &moduleInfos = newInfo.GetInnerModuleInfos(); - std::string moduleName = (moduleInfos.begin()->second).moduleName; - overlayDataMgr.BuildInternalOverlayConnection(moduleName, oldInfo, newInfo.GetUserId()); - EXPECT_EQ(oldInfo.FetchInnerModuleInfos().empty(), true); - - oldInfo.SetOverlayState(OverlayType::OVERLAY_INTERNAL_BUNDLE); - overlayDataMgr.BuildInternalOverlayConnection(moduleName, oldInfo, newInfo.GetUserId()); - EXPECT_EQ(oldInfo.FetchInnerModuleInfos().empty(), true); -} - -/** - * @tc.number: OverlayDataMgr_0700 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of BuildOverlayConnection and BuildOverlayConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0700, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo oldInfo; - oldInfo.SetIsPreInstallApp(false); - ApplicationInfo applicationInfo; - applicationInfo.bundleName = NO_EXIST; - oldInfo.SetBaseApplicationInfo(applicationInfo); - EXPECT_EQ(oldInfo.baseApplicationInfo_->bundleName, NO_EXIST); -} - -/** - * @tc.number: OverlayDataMgr_0900 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of BuildOverlayConnection and BuildOverlayConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0900, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo oldInfo; - oldInfo.SetIsPreInstallApp(true); - oldInfo.SetCertificateFingerprint(NO_EXIST); - EXPECT_EQ(oldInfo.baseApplicationInfo_->fingerprint, NO_EXIST); -} -#endif - -/** - * @tc.number: OverlayDataMgr_1200 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of GetBundleDir. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1200, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - std::string moduleHapPath = "xxx/"; - std::string bundleDir; - ErrCode res = overlayDataMgr.GetBundleDir(moduleHapPath, bundleDir); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_BUNDLE_DIR); - moduleHapPath = "//"; - res = overlayDataMgr.GetBundleDir(moduleHapPath, bundleDir); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: OverlayDataMgr_1300 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1300, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); - std::map innerModuleInfos; - InnerModuleInfo moduleInfo; - moduleInfo.moduleName = TEST_PACK_AGE; - moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; - innerModuleInfos[TEST_PACK_AGE] = moduleInfo; - newInfo.AddInnerModuleInfo(innerModuleInfos); - oldInfo.AddInnerModuleInfo(innerModuleInfos); - res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: OverlayDataMgr_1400 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1400, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - std::map innerModuleInfos; - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); - dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, newInfo); - ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); - UninstallBundleInfo(); -} - -/** - * @tc.number: OverlayDataMgr_1500 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1500, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - std::map innerModuleInfos; - InnerModuleInfo moduleInfo; - moduleInfo.moduleName = TEST_PACK_AGE; - moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; - innerModuleInfos[TEST_PACK_AGE] = moduleInfo; - newInfo.AddInnerModuleInfo(innerModuleInfos); - oldInfo.AddInnerModuleInfo(innerModuleInfos); - newInfo.SetOverlayType(OVERLAY_INTERNAL_BUNDLE); - - ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: OverlayDataMgr_1600 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of QueryOverlayInnerBundleInfo. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1600, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo info; - bool res = overlayDataMgr.QueryOverlayInnerBundleInfo("", info); - EXPECT_EQ(res, false); -} - -/** - * @tc.number: OverlayDataMgr_1700 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of GetAllOverlayModuleInfo. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1700, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - std::vector overlayModuleInfos; - ErrCode res = overlayDataMgr.GetAllOverlayModuleInfo("", overlayModuleInfos, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); - - AddInnerBundleInfo(); - res = overlayDataMgr.GetAllOverlayModuleInfo( - TEST_BUNDLE_NAME, overlayModuleInfos, Constants::NOT_EXIST_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_NON_OVERLAY_BUNDLE); - - res = overlayDataMgr.GetAllOverlayModuleInfo( - TEST_BUNDLE_NAME, overlayModuleInfos, Constants::INVALID_USERID); - EXPECT_EQ(res, - ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); - - OverlayModuleInfo overlayModuleInfo; - overlayModuleInfos.push_back(overlayModuleInfo); - res = overlayDataMgr.GetAllOverlayModuleInfo( - TEST_BUNDLE_NAME, overlayModuleInfos, Constants::NOT_EXIST_USERID); - - EXPECT_EQ(res, - ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_NON_OVERLAY_BUNDLE); - UninstallBundleInfo(); -} - -/** - * @tc.number: OverlayDataMgr_1800 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of GetOverlayModuleInfo. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1800, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - OverlayModuleInfo overlayModuleInfos; - ErrCode res = overlayDataMgr.GetOverlayModuleInfo("", "", overlayModuleInfos, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); - - AddInnerBundleInfo(); - res = overlayDataMgr.GetOverlayModuleInfo( - TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfos, Constants::INVALID_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); - - res = overlayDataMgr.GetOverlayModuleInfo( - TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfos, Constants::NOT_EXIST_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_NON_OVERLAY_BUNDLE); -} - -/** - * @tc.number: OverlayDataMgr_1900 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of GetOverlayBundleInfoForTarget. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1900, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - std::vector overlayBundleInfo; - ErrCode res = overlayDataMgr.GetOverlayBundleInfoForTarget("", overlayBundleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_NOT_EXISTED); - - AddInnerBundleInfo(); - res = overlayDataMgr.GetOverlayBundleInfoForTarget( - TEST_BUNDLE_NAME, overlayBundleInfo, Constants::NOT_EXIST_USERID); - EXPECT_EQ(res, ERR_OK); - EXPECT_EQ(overlayBundleInfo.size(), DEFAULT_OVERLAY_BUNDLE_INFO); - - res = overlayDataMgr.GetOverlayBundleInfoForTarget( - TEST_BUNDLE_NAME, overlayBundleInfo, Constants::INVALID_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); - - UninstallBundleInfo(); -} - -/** - * @tc.number: OverlayDataMgr_2000 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of GetOverlayModuleInfoForTarget. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2000, Function | SmallTest | Level0) -{ - AddInnerBundleInfo(); - OverlayDataMgr overlayDataMgr; - std::vector overlayModuleInfos; - ErrCode res = overlayDataMgr.GetOverlayModuleInfoForTarget( - TEST_BUNDLE_NAME, TARGET_MODULE_NAME, overlayModuleInfos, Constants::NOT_EXIST_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_MODULE_IS_OVERLAY_MODULE); - - res = overlayDataMgr.GetOverlayModuleInfoForTarget( - TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfos, Constants::NOT_EXIST_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_MODULE_NOT_EXISTED); - - res = overlayDataMgr.GetOverlayModuleInfoForTarget( - TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfos, Constants::INVALID_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); - - res = overlayDataMgr.GetOverlayModuleInfoForTarget( - TEST_BUNDLE_NAME, "", overlayModuleInfos, Constants::NOT_EXIST_USERID); - EXPECT_EQ(res, ERR_OK); - - res = overlayDataMgr.GetOverlayModuleInfoForTarget( - "", "", overlayModuleInfos, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_NOT_EXISTED); - - UninstallBundleInfo(); -} - -/** - * @tc.number: OverlayDataMgr_2100 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of SetOverlayEnabled. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2100, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - bool isEnabled = false; - ErrCode res = overlayDataMgr.SetOverlayEnabled(TEST_BUNDLE_NAME, "", isEnabled, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); - - AddInnerBundleInfo(); - res = overlayDataMgr.SetOverlayEnabled( - TEST_BUNDLE_NAME, TEST_MODULE_NAME, isEnabled, Constants::INVALID_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); - - res = overlayDataMgr.SetOverlayEnabled(TEST_BUNDLE_NAME, TEST_MODULE_NAME, isEnabled, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); - - UninstallBundleInfo(); -} - -/** - * @tc.number: OverlayDataMgr_2200 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of GetCallingBundleName. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2200, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - std::string res = overlayDataMgr.GetCallingBundleName(); - EXPECT_EQ(res, ""); -} - -/** - * @tc.number: OverlayDataMgr_2300 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of AddOverlayModuleStates. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2300, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo innerBundleInfo; - InnerBundleUserInfo userInfo; - overlayDataMgr.AddOverlayModuleStates(innerBundleInfo, userInfo); - EXPECT_EQ(userInfo.bundleUserInfo.userId, Constants::INVALID_USERID); - - userInfo.bundleUserInfo.userId = USERID; - innerBundleInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); - overlayDataMgr.AddOverlayModuleStates(innerBundleInfo, userInfo); - EXPECT_EQ(userInfo.bundleUserInfo.userId, USERID); -} - -/** - * @tc.number: OverlayDataMgr_2400 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of AddOverlayModuleStates. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2400, Function | SmallTest | Level0) -{ - AddInnerBundleInfo(); - OverlayDataMgr overlayDataMgr; - InnerBundleInfo innerBundleInfo; - InnerBundleUserInfo userInfo; - userInfo.bundleUserInfo.userId = USERID; - innerBundleInfo.SetOverlayType(OverlayType::OVERLAY_INTERNAL_BUNDLE); - innerBundleInfo.SetTargetBundleName(TEST_BUNDLE_NAME); - overlayDataMgr.AddOverlayModuleStates(innerBundleInfo, userInfo); - EXPECT_EQ(userInfo.bundleUserInfo.userId, USERID); - UninstallBundleInfo(); -} - -/** - * @tc.number: OverlayDataMgr_2500 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2500, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - std::map innerModuleInfos; - InnerModuleInfo moduleInfo; - moduleInfo.moduleName = TEST_PACK_AGE; - moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; - innerModuleInfos[TEST_PACK_AGE] = moduleInfo; - newInfo.AddInnerModuleInfo(innerModuleInfos); - oldInfo.AddInnerModuleInfo(innerModuleInfos); - newInfo.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); - - ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); - EXPECT_EQ(res, ERR_OK); - - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - ApplicationInfo applicationInfo; - applicationInfo.bundleName = TEST_BUNDLE_NAME; - applicationInfo.targetBundleName = TEST_BUNDLE_NAME; - oldInfo.SetBaseApplicationInfo(applicationInfo); - dataMgr->bundleInfos_.insert( - pair(TEST_BUNDLE_NAME, oldInfo)); - res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: OverlayDataMgr_2600 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2600, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - std::map innerModuleInfos; - InnerModuleInfo moduleInfo; - moduleInfo.moduleName = TEST_PACK_AGE; - moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; - innerModuleInfos[TEST_PACK_AGE] = moduleInfo; - newInfo.AddInnerModuleInfo(innerModuleInfos); - oldInfo.AddInnerModuleInfo(innerModuleInfos); - newInfo.SetOverlayType(NON_OVERLAY_TYPE); - - ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: OverlayDataMgr_2700 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2700, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - InnerBundleInfo targetInnerBundleInfo; - std::map innerModuleInfos; - - overlayDataMgr.RemoveOverlayBundleInfo(TEST_BUNDLE_NAME, targetInnerBundleInfo); - overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); - InnerModuleInfo moduleInfo; - moduleInfo.moduleName = TEST_PACK_AGE; - moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; - innerModuleInfos[TEST_PACK_AGE] = moduleInfo; - newInfo.AddInnerModuleInfo(innerModuleInfos); - oldInfo.AddInnerModuleInfo(innerModuleInfos); - newInfo.SetOverlayType(OVERLAY_INTERNAL_BUNDLE); - - ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: OverlayDataMgr_2800 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2800, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - std::map innerModuleInfos; - InnerModuleInfo moduleInfo; - moduleInfo.moduleName = TEST_PACK_AGE; - moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; - innerModuleInfos[TEST_PACK_AGE] = moduleInfo; - newInfo.AddInnerModuleInfo(innerModuleInfos); - oldInfo.AddInnerModuleInfo(innerModuleInfos); - newInfo.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); - - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - ApplicationInfo applicationInfo; - applicationInfo.bundleName = TEST_BUNDLE_NAME; - applicationInfo.targetBundleName = TEST_BUNDLE_NAME; - oldInfo.SetBaseApplicationInfo(applicationInfo); - newInfo.SetTargetBundleName(NO_EXIST); - dataMgr->bundleInfos_.insert( - pair(TEST_BUNDLE_NAME, oldInfo)); - ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: OverlayDataMgr_2900 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleInfo. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2900, Function | SmallTest | Level0) -{ - AddInnerBundleInfo(); - - OverlayDataMgr overlayDataMgr; - InnerBundleInfo oldInfo; - InnerBundleInfo targetInnerBundleInfo; - std::map innerModuleInfos; - InnerModuleInfo moduleInfo; - moduleInfo.moduleName = TEST_PACK_AGE; - moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; - innerModuleInfos[TEST_PACK_AGE] = moduleInfo; - oldInfo.AddInnerModuleInfo(innerModuleInfos); - overlayDataMgr.RemoveOverlayBundleInfo(TEST_BUNDLE_NAME, targetInnerBundleInfo); - overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); - - oldInfo.SetOverlayType(OVERLAY_INTERNAL_BUNDLE); - overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); - - oldInfo.SetTargetBundleName(TARGET_MODULE_NAME); - overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); - - oldInfo.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); - overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); - - oldInfo.SetTargetBundleName(TARGET_MODULE_NAME); - overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); - - oldInfo.SetOverlayType(NON_OVERLAY_TYPE); - overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); - overlayDataMgr.RemoveOverlayModuleInfo("noExits", TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); - UninstallBundleInfo(); -} - -/** - * @tc.number: OverlayDataMgr_3000 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3000, Function | SmallTest | Level0) -{ - InnerBundleInfo info; - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); - - info.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); - bool res = dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, info); - EXPECT_EQ(res, true); - - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME2, InstallState::INSTALL_START); - info.SetOverlayType(OverlayType::NON_OVERLAY_TYPE); - res = dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME2, info); - EXPECT_EQ(res, true); - - UninstallBundleInfo(); -} - -/** - * @tc.number: OverlayDataMgr_3100 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3100, Function | SmallTest | Level0) -{ - InnerBundleInfo info; - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); - - info.SetOverlayType(OverlayType::OVERLAY_INTERNAL_BUNDLE); - bool res = dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, info); - EXPECT_EQ(res, true); - - UninstallBundleInfo(); -} - -/** - * @tc.number: OverlayDataMgr_3200 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3200, Function | SmallTest | Level0) -{ - AddInnerBundleInfo(); - - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - std::map innerModuleInfos; - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - bool res = dataMgr->AddNewModuleInfo(TEST_BUNDLE_NAME, newInfo, oldInfo); - EXPECT_EQ(res, false); - - UninstallBundleInfo(); -} - -/** - * @tc.number: OverlayDataMgr_3300 - * @tc.name: AddBundleInfo - * @tc.desc: 1. add module info to the data manager - * 2. query data then verify - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3300, Function | SmallTest | Level0) -{ - InnerBundleInfo info1; - BundleInfo bundleInfo1; - bundleInfo1.name = TEST_BUNDLE_NAME; - bundleInfo1.applicationInfo.bundleName = TEST_BUNDLE_NAME; - ApplicationInfo applicationInfo1; - applicationInfo1.name = TEST_BUNDLE_NAME; - applicationInfo1.bundleName = TEST_BUNDLE_NAME; - info1.SetBaseBundleInfo(bundleInfo1); - info1.SetBaseApplicationInfo(applicationInfo1); - - InnerBundleInfo info2; - BundleInfo bundleInfo2; - bundleInfo2.name = TEST_BUNDLE_NAME; - bundleInfo2.applicationInfo.bundleName = TEST_BUNDLE_NAME; - ApplicationInfo applicationInfo2; - applicationInfo2.name = TEST_BUNDLE_NAME; - applicationInfo2.bundleName = TEST_BUNDLE_NAME; - info2.SetBaseBundleInfo(bundleInfo2); - info2.SetBaseApplicationInfo(applicationInfo2); - - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); - dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, info1); - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UPDATING_START); - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UPDATING_SUCCESS); - info1.SetOverlayType(OverlayType::NON_OVERLAY_TYPE); - info2.SetOverlayType(OverlayType::OVERLAY_INTERNAL_BUNDLE); - bool ret = dataMgr->AddNewModuleInfo(TEST_BUNDLE_NAME, info2, info1); - EXPECT_FALSE(ret); - - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_START); - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_SUCCESS); -} - - -/** - * @tc.number: OverlayDataMgr_3400 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of IsExistedNonOverlayHap. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3400, Function | SmallTest | Level0) -{ - AddInnerBundleInfo(); - OverlayDataMgr overlayDataMgr; - bool res = overlayDataMgr.IsExistedNonOverlayHap(TEST_BUNDLE_NAME); - EXPECT_EQ(res, false); - - UninstallBundleInfo(); -} - -/** - * @tc.number: OverlayDataMgr_3500 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of BuildInternalOverlayConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3500, Function | SmallTest | Level0) -{ - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.name = TEST_MODULE_NAME; - innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; - innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - ApplicationInfo applicationInfo; - applicationInfo.bundleName = TEST_BUNDLE_NAME; - applicationInfo.targetBundleName = TEST_BUNDLE_NAME; - innerBundleInfo.SetBaseApplicationInfo(applicationInfo); - - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); - dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, innerBundleInfo); - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UPDATING_START); - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UPDATING_SUCCESS); - OverlayDataMgr overlayDataMgr; - overlayDataMgr.BuildInternalOverlayConnection(TARGET_MODULE_NAME, innerBundleInfo, USERID); - EXPECT_EQ(innerBundleInfo.FetchInnerModuleInfos().empty(), false); - UninstallBundleInfo(); -} - -/** - * @tc.number: OverlayDataMgr_3600 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3600, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - std::map innerModuleInfos; - InnerModuleInfo moduleInfo; - moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; - innerModuleInfos[TEST_PACK_AGE] = moduleInfo; - newInfo.AddInnerModuleInfo(innerModuleInfos); - oldInfo.AddInnerModuleInfo(innerModuleInfos); - newInfo.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); - - ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); -} - -/** - * @tc.number: OverlayDataMgr_3700 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3700, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - std::map innerModuleInfos; - InnerModuleInfo moduleInfo; - moduleInfo.moduleName = TEST_PACK_AGE; - moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; - innerModuleInfos[TEST_PACK_AGE] = moduleInfo; - newInfo.AddInnerModuleInfo(innerModuleInfos); - oldInfo.AddInnerModuleInfo(innerModuleInfos); - newInfo.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); - - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - ApplicationInfo applicationInfo; - applicationInfo.bundleName = TEST_BUNDLE_NAME; - oldInfo.SetBaseApplicationInfo(applicationInfo); - newInfo.SetTargetBundleName(NO_EXIST); - oldInfo.SetTargetBundleName(TEST_BUNDLE_NAME); - dataMgr->bundleInfos_.insert( - pair(TEST_BUNDLE_NAME, oldInfo)); - ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: OverlayDataMgr_3800 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleInfo. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3800, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo targetInnerBundleInfo; - std::map innerModuleInfos; - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.name = TEST_MODULE_NAME; - innerModuleInfo.moduleName = TEST_PACK_AGE; - innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; - innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; - innerModuleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; - innerModuleInfos[TEST_PACK_AGE] = innerModuleInfo; - innerBundleInfo.AddInnerModuleInfo(innerModuleInfos); - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - ApplicationInfo applicationInfo; - applicationInfo.bundleName = TEST_BUNDLE_NAME; - applicationInfo.targetBundleName = TEST_BUNDLE_NAME; - innerBundleInfo.SetBaseApplicationInfo(applicationInfo); - - innerBundleInfo.SetOverlayType(OverlayType::OVERLAY_INTERNAL_BUNDLE); - overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, innerBundleInfo, targetInnerBundleInfo); - overlayDataMgr.ResetInternalOverlayModuleState(innerModuleInfos, TARGET_MODULE_NAME, innerBundleInfo); - EXPECT_EQ(innerModuleInfos.at(TEST_PACK_AGE).targetModuleName, TARGET_MODULE_NAME); -} - -/** - * @tc.number: OverlayDataMgr_3900 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of SaveInternalOverlayModuleState. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3900, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - std::map innerModuleInfos; - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.name = TEST_MODULE_NAME; - innerModuleInfo.moduleName = TEST_PACK_AGE; - innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; - innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; - innerModuleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; - innerModuleInfos[TEST_PACK_AGE] = innerModuleInfo; - innerBundleInfo.AddInnerModuleInfo(innerModuleInfos); - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - ApplicationInfo applicationInfo; - applicationInfo.bundleName = TEST_BUNDLE_NAME; - applicationInfo.targetBundleName = TEST_BUNDLE_NAME; - innerBundleInfo.SetBaseApplicationInfo(applicationInfo); - - OverlayModuleInfo overlayModuleInfo; - overlayModuleInfo.targetModuleName = TARGET_MODULE_NAME; - - ErrCode res = overlayDataMgr.SaveInternalOverlayModuleState(overlayModuleInfo, innerBundleInfo); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: OverlayDataMgr_4000 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of GetOverlayModuleInfoForTarget. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4000, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo innerBundleInfo; - std::vector overlayModuleInfos; - ErrCode res = overlayDataMgr.GetOverlayModuleInfoForTarget( - innerBundleInfo, overlayModuleInfos, Constants::NOT_EXIST_USERID); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: OverlayDataMgr_4100 - * @tc.name: test bundleName is empty. - * @tc.desc: 1.OverlayDataMgr with SetOverlayEnabled. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4100, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - bool isEnabled = false; - ErrCode res = overlayDataMgr.SetOverlayEnabled("", TEST_MODULE_NAME, isEnabled, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); -} - -/** - * @tc.number: OverlayDataMgr_4200 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of BuildInternalOverlayConnection. - * 2.system run normally. - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4200, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo oldInfo; - oldInfo.SetOverlayType(OVERLAY_INTERNAL_BUNDLE); - InnerModuleInfo moduleInfo; - moduleInfo.targetModuleName = TEST_MODULE_NAME; - std::map innerModuleInfos; - moduleInfo.moduleName = TEST_MODULE_NAME; - innerModuleInfos[TEST_PACK_AGE] = moduleInfo; - moduleInfo.moduleName = TEST_PACK_AGE; - moduleInfo.targetModuleName = TEST_PACK_AGE; - innerModuleInfos[TEST_MODULE_NAME] = moduleInfo; - oldInfo.AddInnerModuleInfo(innerModuleInfos); - - ClearDataMgr(); - BuildInternalOverlayConnection(TEST_MODULE_NAME, oldInfo, USERID); - ResetDataMgr(); -} - -/** - * @tc.number: OverlayDataMgr_4300 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of QueryOverlayInnerBundleInfo. - * 2.system run normally. - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4300, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - overlayDataMgr.dataMgr_ = std::make_shared(); - InnerBundleInfo info; - std::map innerModuleInfos; - info.AddInnerModuleInfo(innerModuleInfos); - overlayDataMgr.dataMgr_->bundleInfos_[NO_EXIST] = info; - bool ret = overlayDataMgr.QueryOverlayInnerBundleInfo(NO_EXIST, info); - auto iterator = overlayDataMgr.dataMgr_->bundleInfos_.find(NO_EXIST); - if (iterator != overlayDataMgr.dataMgr_->bundleInfos_.end()) { - overlayDataMgr.dataMgr_->bundleInfos_.erase(iterator); - } - EXPECT_EQ(ret, true); -} - -/** - * @tc.number: OverlayDataMgr_4400 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of QueryOverlayInnerBundleInfo. - * 2.system run normally. - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4400, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - overlayDataMgr.dataMgr_ = std::make_shared(); - InnerBundleInfo info; - info.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); - std::map innerModuleInfos; - InnerModuleInfo innerModuleInfo; - innerModuleInfos[TEST_MODULE_NAME] = innerModuleInfo; - info.AddInnerModuleInfo(innerModuleInfos); - overlayDataMgr.dataMgr_->bundleInfos_[NO_EXIST] = info; - std::vector overlayModuleInfo; - auto ret = overlayDataMgr.GetAllOverlayModuleInfo(NO_EXIST, overlayModuleInfo, - Constants::NOT_EXIST_USERID); - auto iterator = overlayDataMgr.dataMgr_->bundleInfos_.find(NO_EXIST); - if (iterator != overlayDataMgr.dataMgr_->bundleInfos_.end()) { - overlayDataMgr.dataMgr_->bundleInfos_.erase(iterator); - } - EXPECT_EQ(ret, ERR_OK); -} - -/** - * @tc.number: OverlayDataMgr_4500 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of BuildInternalOverlayConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4500, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo oldInfo; - oldInfo.overlayType_ = OVERLAY_INTERNAL_BUNDLE; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.targetModuleName = "errModuleName"; - oldInfo.innerModuleInfos_.insert(pair("1", innerModuleInfo)); - overlayDataMgr.BuildInternalOverlayConnection(TARGET_MODULE_NAME, oldInfo, USERID); - EXPECT_EQ(oldInfo.FetchInnerModuleInfos().empty(), false); -} - -/** - * @tc.number: OverlayDataMgr_4600 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of BuildInternalOverlayConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4600, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo oldInfo; - oldInfo.overlayType_ = OVERLAY_INTERNAL_BUNDLE; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; - innerModuleInfo.moduleName = TEST_MODULE_NAME; - oldInfo.innerModuleInfos_.insert(pair("1", innerModuleInfo)); - overlayDataMgr.BuildInternalOverlayConnection(TARGET_MODULE_NAME, oldInfo, USERID); - EXPECT_EQ(oldInfo.FetchInnerModuleInfos().empty(), false); -} - -/** - * @tc.number: OverlayDataMgr_4700 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of BuildInternalOverlayConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4700, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo oldInfo; - oldInfo.overlayType_ = OVERLAY_INTERNAL_BUNDLE; - oldInfo.innerModuleInfos_.clear(); - overlayDataMgr.BuildInternalOverlayConnection(TARGET_MODULE_NAME, oldInfo, USERID); - EXPECT_EQ(oldInfo.FetchInnerModuleInfos().empty(), true); -} - -/** - * @tc.number: OverlayDataMgr_4800 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of BuildInternalOverlayConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4800, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo oldInfo; - oldInfo.overlayType_ = OVERLAY_INTERNAL_BUNDLE; - oldInfo.innerModuleInfos_.clear(); - overlayDataMgr.BuildInternalOverlayConnection(TARGET_MODULE_NAME, oldInfo, USERID); - EXPECT_EQ(oldInfo.FetchInnerModuleInfos().empty(), true); -} - -/** - * @tc.number: OverlayDataMgr_4900 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of QueryOverlayInnerBundleInfo. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4900, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo innerBundleInfo; - overlayDataMgr.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); - overlayDataMgr.dataMgr_->bundleInfos_.insert(pair(TEST_BUNDLE_NAME, innerBundleInfo)); - auto res = overlayDataMgr.QueryOverlayInnerBundleInfo(NO_EXIST, innerBundleInfo); - EXPECT_FALSE(res); -} - -/** - * @tc.number: OverlayDataMgr_5000 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of QueryOverlayInnerBundleInfo. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_5000, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo innerBundleInfo; - ClearDataMgr(); - auto res = overlayDataMgr.QueryOverlayInnerBundleInfo(TEST_BUNDLE_NAME, innerBundleInfo); - EXPECT_FALSE(res); - ResetDataMgr(); -} - -/** - * @tc.number: OverlayDataMgr_5100 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of SaveInternalOverlayModuleState. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_5100, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - OverlayModuleInfo overlayModuleInfo; - overlayModuleInfo.targetModuleName = TARGET_MODULE_NAME; - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - innerBundleInfo.innerModuleInfos_.insert(pair(TARGET_MODULE_NAME, innerModuleInfo)); - overlayDataMgr.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); - overlayDataMgr.dataMgr_->AddUserId(NOT_EXIST_USERID); - auto res = overlayDataMgr.SaveInternalOverlayModuleState(overlayModuleInfo, innerBundleInfo); - EXPECT_FALSE(res); -} - -/** - * @tc.number: OverlayDataMgr_5200 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of SaveInternalOverlayModuleState. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_5200, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - OverlayModuleInfo overlayModuleInfo; - overlayModuleInfo.targetModuleName = TARGET_MODULE_NAME; - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - innerBundleInfo.innerModuleInfos_.insert(pair(TEST_MODULE_NAME, innerModuleInfo)); - overlayDataMgr.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); - overlayDataMgr.dataMgr_->AddUserId(NOT_EXIST_USERID); - auto res = overlayDataMgr.SaveInternalOverlayModuleState(overlayModuleInfo, innerBundleInfo); - EXPECT_FALSE(res); -} - -/** - * @tc.number: OverlayManagerHostImpl_0100 - * @tc.name: test overlayManagerHostImpl. - * @tc.desc: 1.overlayManagerHostImpl of GetAllOverlayModuleInfo. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayManagerHostImpl_0100, Function | SmallTest | Level0) -{ - OverlayManagerHostImpl overlayManagerHostImpl; - std::vector overlayModuleInfo; - ErrCode res = overlayManagerHostImpl.GetAllOverlayModuleInfo("", overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - - res = overlayManagerHostImpl.GetAllOverlayModuleInfo( - "bundleName", overlayModuleInfo, Constants::UNSPECIFIED_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); -} - -/** - * @tc.number: GetOverlayModuleInfo_0200 - * @tc.name: test overlayManagerHostImpl. - * @tc.desc: 1.overlayManagerHostImpl of GetOverlayModuleInfo. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_0200, Function | SmallTest | Level0) -{ - OverlayManagerHostImpl overlayManagerHostImpl; - OverlayModuleInfo overlayModuleInfo; - ErrCode res = overlayManagerHostImpl.GetOverlayModuleInfo( - "", "moduleName", overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - - res = overlayManagerHostImpl.GetOverlayModuleInfo( - "bundleName", "", overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - - res = overlayManagerHostImpl.GetOverlayModuleInfo( - "", "", overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - - res = overlayManagerHostImpl.GetOverlayModuleInfo( - "bundleName", "moduleName", overlayModuleInfo, Constants::UNSPECIFIED_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); -} - -/** - * @tc.number: GetOverlayModuleInfo_0300 - * @tc.name: test overlayManagerHostImpl. - * @tc.desc: 1.overlayManagerHostImpl of GetOverlayBundleInfoForTarget. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_0300, Function | SmallTest | Level0) -{ - OverlayManagerHostImpl overlayManagerHostImpl; - std::vector overlayBundleInfo; - ErrCode res = overlayManagerHostImpl.GetOverlayBundleInfoForTarget( - "", overlayBundleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - - res = overlayManagerHostImpl.GetOverlayBundleInfoForTarget( - "targetBundleName", overlayBundleInfo, Constants::UNSPECIFIED_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_NOT_EXISTED); -} - -/** - * @tc.number: GetOverlayModuleInfo_0400 - * @tc.name: test OverlayManagerHostImpl. - * @tc.desc: 1.OverlayManagerHostImpl of GetOverlayModuleInfoForTarget. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_0400, Function | SmallTest | Level0) -{ - OverlayManagerHostImpl overlayManagerHostImpl; - std::vector overlayModuleInfo; - ErrCode res = overlayManagerHostImpl.GetOverlayModuleInfoForTarget( - "", "targetModuleName", overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - - res = overlayManagerHostImpl.GetOverlayModuleInfoForTarget( - "targetBundleName", "", overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_NOT_EXISTED); - - res = overlayManagerHostImpl.GetOverlayModuleInfoForTarget( - "", "", overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - - res = overlayManagerHostImpl.GetOverlayModuleInfoForTarget( - "targetBundleName", "targetModuleName", overlayModuleInfo, Constants::UNSPECIFIED_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_NOT_EXISTED); -} - -/** - * @tc.number: GetOverlayModuleInfo_0500 - * @tc.name: test OverlayManagerHostImpl. - * @tc.desc: 1.OverlayManagerHostImpl of SetOverlayEnabled. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_0500, Function | SmallTest | Level0) -{ - OverlayManagerHostImpl overlayManagerHostImpl; - bool isEnabled = false; - ErrCode res = overlayManagerHostImpl.SetOverlayEnabled( - "", "moduleName", isEnabled, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_SET_OVERLAY_PARAM_ERROR); - - res = overlayManagerHostImpl.SetOverlayEnabled( - "bundleName", "", isEnabled, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_SET_OVERLAY_PARAM_ERROR); - - res = overlayManagerHostImpl.SetOverlayEnabled( - "", "", isEnabled, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_SET_OVERLAY_PARAM_ERROR); - - res = overlayManagerHostImpl.SetOverlayEnabled( - "bundleName", "moduleName", isEnabled, Constants::UNSPECIFIED_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); -} - -/** - * @tc.number: GetOverlayModuleInfo_0800 - * @tc.name: test overlayManagerHostImpl. - * @tc.desc: 1.OverlayManagerHostImpl with GetOverlayBundleInfoForTarget. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_0800, Function | SmallTest | Level0) -{ - OverlayManagerHostImpl overlayManagerHostImpl; - std::vector overlayBundleInfo; - ErrCode res = overlayManagerHostImpl.GetOverlayBundleInfoForTarget(TEST_BUNDLE_NAME, - overlayBundleInfo, Constants::INVALID_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); -} - -/** - * @tc.number: OverlayIpcTest_2000 - * @tc.name: test SetOverlayEnabled interface in OverlayManagerProxy. - * @tc.desc: 1.construct OverlayManagerProxy instance. - * 2.calling SetOverlayEnabled interface by using OverlayManagerProxy instance. - * 3.bundleName is empty and set failed - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_0900, Function | SmallTest | Level0) -{ - OverlayManagerHostImpl overlayManagerHostImpl; - - std::vector overlayModuleInfos; - auto errCode = overlayManagerHostImpl.GetTargetOverlayModuleInfo("", overlayModuleInfos, - USERID); - EXPECT_EQ(errCode, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - - errCode = overlayManagerHostImpl.GetTargetOverlayModuleInfo(TEST_BUNDLE_NAME, overlayModuleInfos, - Constants::UNSPECIFIED_USERID); - EXPECT_EQ(errCode, ERR_BUNDLE_MANAGER_INTERNAL_ERROR); -} - -/** - * @tc.number: OverlayIpcTest_2000 - * @tc.name: test SetOverlayEnabled interface in OverlayManagerProxy. - * @tc.desc: 1.construct GetOverlayModuleInfoByBundleName instance. - * 2.calling SetOverlayEnabled interface by using GetOverlayModuleInfoByBundleName instance. - * 3.bundleName is empty and set failed - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_1000, Function | SmallTest | Level0) -{ - OverlayManagerHostImpl overlayManagerHostImpl; - - std::vector overlayModuleInfos; - auto errCode = overlayManagerHostImpl.GetOverlayModuleInfoByBundleName("", TEST_MODULE_NAME, - overlayModuleInfos, USERID); - EXPECT_EQ(errCode, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - - errCode = overlayManagerHostImpl.GetOverlayModuleInfoByBundleName(TEST_BUNDLE_NAME, "", - overlayModuleInfos, Constants::UNSPECIFIED_USERID); - EXPECT_EQ(errCode, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); - - errCode = overlayManagerHostImpl.GetOverlayModuleInfoByBundleName(TEST_BUNDLE_NAME, TEST_MODULE_NAME, - overlayModuleInfos, Constants::UNSPECIFIED_USERID); - EXPECT_EQ(errCode, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); -} - -/** - * @tc.number: OverlayIpcTest_2000 - * @tc.name: test SetOverlayEnabledForSelf interface in OverlayManagerProxy. - * @tc.desc: 1.construct SetOverlayEnabledForSelf instance. - * 2.calling SetOverlayEnabled interface by using SetOverlayEnabledForSelf instance. - * 3.bundleName is empty and set failed - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_1100, Function | SmallTest | Level0) -{ - OverlayManagerHostImpl overlayManagerHostImpl; - - bool isEnabled = false; - auto errCode = overlayManagerHostImpl.SetOverlayEnabledForSelf("", - isEnabled, USERID); - EXPECT_EQ(errCode, ERR_BUNDLEMANAGER_OVERLAY_SET_OVERLAY_PARAM_ERROR); - - errCode = overlayManagerHostImpl.SetOverlayEnabledForSelf(TEST_MODULE_NAME, - isEnabled, Constants::UNSPECIFIED_USERID); - EXPECT_EQ(errCode, ERR_BUNDLE_MANAGER_INTERNAL_ERROR); -} - -/** - * @tc.number: CheckTargetBundle_0100 - * @tc.name: check bundle target priority range - * @tc.desc: Test CheckTargetBundle -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckTargetBundle_0100, Function | SmallTest | Level0) -{ - BundleOverlayInstallChecker checker; - auto code = checker.CheckTargetBundle("", "", "", USERID); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_BUNDLE_NAME); - code = checker.CheckTargetBundle(TEST_BUNDLE_NAME, "", "", USERID); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_NO_SYSTEM_APPLICATION_FOR_EXTERNAL_OVERLAY); -} - -/** - * @tc.number: UpdateInnerBundleInfo_0100 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, UpdateInnerBundleInfo_0100, Function | SmallTest | Level0) -{ - InnerBundleInfo info1; - BundleInfo bundleInfo1; - bundleInfo1.name = BUNDLE_NAME; - bundleInfo1.applicationInfo.bundleName = BUNDLE_NAME; - ApplicationInfo applicationInfo1; - applicationInfo1.name = BUNDLE_NAME; - applicationInfo1.bundleName = BUNDLE_NAME; - info1.SetBaseBundleInfo(bundleInfo1); - info1.SetBaseApplicationInfo(applicationInfo1); - - InnerBundleInfo info2; - BundleInfo bundleInfo2; - bundleInfo2.name = BUNDLE_NAME; - bundleInfo2.applicationInfo.bundleName = BUNDLE_NAME; - ApplicationInfo applicationInfo2; - applicationInfo2.name = BUNDLE_NAME; - applicationInfo2.bundleName = BUNDLE_NAME; - info2.SetBaseBundleInfo(bundleInfo2); - info2.SetBaseApplicationInfo(applicationInfo2); - info2.SetIsNewVersion(true); - info2.SetOverlayType(OverlayType::NON_OVERLAY_TYPE); - - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - dataMgr->AddUserId(USERID); - - bool ret1 = dataMgr->UpdateBundleInstallState(BUNDLE_NAME, InstallState::INSTALL_START); - bool ret2 = dataMgr->AddInnerBundleInfo(BUNDLE_NAME, info1); - bool ret3 = dataMgr->UpdateBundleInstallState(BUNDLE_NAME, InstallState::UPDATING_START); - bool ret4 = dataMgr->UpdateBundleInstallState(BUNDLE_NAME, InstallState::UPDATING_SUCCESS); - bool ret5 = dataMgr->UpdateInnerBundleInfo(BUNDLE_NAME, info2, info1); - EXPECT_TRUE(ret1); - EXPECT_TRUE(ret2); - EXPECT_TRUE(ret3); - EXPECT_TRUE(ret4); - EXPECT_TRUE(ret5); - - info2.SetOverlayType(OverlayType::OVERLAY_INTERNAL_BUNDLE); - ret5 = dataMgr->UpdateInnerBundleInfo(BUNDLE_NAME, info2, info1); - EXPECT_FALSE(ret5); - - info2.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); - ret5 = dataMgr->UpdateInnerBundleInfo(BUNDLE_NAME, info2, info1); - EXPECT_TRUE(ret5); - - ret5 = dataMgr->UpdateBundleInstallState(BUNDLE_NAME, InstallState::UNINSTALL_START); - EXPECT_TRUE(ret5); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_0100 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0100, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - - ClearDataMgr(); - bool resBool = overlayDataMgr.IsExistedNonOverlayHap(TEST_BUNDLE_NAME); - EXPECT_EQ(resBool, false); - ResetDataMgr(); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_0200 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0200, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - std::map innerModuleInfos; - InnerModuleInfo moduleInfo; - moduleInfo.moduleName = TEST_PACK_AGE; - moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; - innerModuleInfos[TEST_PACK_AGE] = moduleInfo; - newInfo.AddInnerModuleInfo(innerModuleInfos); - oldInfo.AddInnerModuleInfo(innerModuleInfos); - newInfo.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); - - ClearDataMgr(); - ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); - ResetDataMgr(); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_0300 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6S6E8 - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0300, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo oldInfo; - InnerBundleInfo targetInnerBundleInfo; - std::map innerModuleInfos; - InnerModuleInfo moduleInfo; - moduleInfo.moduleName = TEST_PACK_AGE; - moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; - innerModuleInfos[TEST_PACK_AGE] = moduleInfo; - oldInfo.AddInnerModuleInfo(innerModuleInfos); - oldInfo.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); - - ClearDataMgr(); - overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); - std::map moduleInfos = oldInfo.FetchInnerModuleInfos(); - EXPECT_EQ(moduleInfos.empty(), false); - ResetDataMgr(); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_0400 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0400, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleUserInfo userInfo; - userInfo.bundleUserInfo.overlayModulesState.clear(); - std::map statesMap; - std::map res = overlayDataMgr.GetModulesStateFromUserInfo(userInfo); - EXPECT_EQ(res, statesMap); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_0500 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0500, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - OverlayModuleInfo overlayModuleInfo; - overlayModuleInfo.bundleName = NO_EXIST; - ErrCode res = overlayDataMgr.ObtainOverlayModuleState(overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_0600 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0600, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - InnerBundleInfo targetInnerBundleInfo; - - ClearDataMgr(); - auto resCode = overlayDataMgr.UpdateExternalOverlayInfo(newInfo, oldInfo, targetInnerBundleInfo); - EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); - ResetDataMgr(); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_0700 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0700, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo oldInfo; - - ClearDataMgr(); - auto resBool = overlayDataMgr.QueryOverlayInnerBundleInfo(TEST_BUNDLE_NAME, oldInfo); - EXPECT_EQ(resBool, false); - ResetDataMgr(); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_0800 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0800, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo oldInfo; - - ClearDataMgr(); - OverlayModuleInfo overlayModuleInfo; - ErrCode resCode = overlayDataMgr.SaveInternalOverlayModuleState(overlayModuleInfo, oldInfo); - EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_SERVICE_EXCEPTION); - ResetDataMgr(); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_0900 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0900, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo oldInfo; - InnerBundleInfo targetBundleInfo; - - ClearDataMgr(); - OverlayModuleInfo overlayModuleInfo; - ErrCode resCode = overlayDataMgr.SaveExternalOverlayModuleState( - overlayModuleInfo, targetBundleInfo, USERID, oldInfo); - EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); - ResetDataMgr(); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_1000 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1000, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo oldInfo; - - ClearDataMgr(); - std::vector overlayModuleInfos; - ErrCode resCode = overlayDataMgr.GetAllOverlayModuleInfo(TEST_BUNDLE_NAME, overlayModuleInfos, USERID); - EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); - ResetDataMgr(); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_1100 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1100, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo oldInfo; - - ClearDataMgr(); - OverlayModuleInfo overlayModuleInfo; - ErrCode resCode = overlayDataMgr.GetOverlayModuleInfo( - TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, USERID); - EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); - ResetDataMgr(); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_1200 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1200, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - - ClearDataMgr(); - std::vector overlayBundleInfo; - ErrCode resCode = overlayDataMgr.GetOverlayBundleInfoForTarget( - TEST_MODULE_NAME, overlayBundleInfo, USERID); - EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); - ResetDataMgr(); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_1300 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1300, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - - ClearDataMgr(); - std::vector overlayModuleInfos; - ErrCode resCode = overlayDataMgr.GetOverlayModuleInfoForTarget( - TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfos, USERID); - EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); - ResetDataMgr(); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_1400 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1400, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - - ClearDataMgr(); - OverlayModuleInfo overlayModuleInfo; - ErrCode resCode = overlayDataMgr.ObtainOverlayModuleState(overlayModuleInfo, USERID); - EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); - ResetDataMgr(); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_1500 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1500, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - - ClearDataMgr(); - bool isEnabled = false; - ErrCode resCode = overlayDataMgr.SetOverlayEnabled(TEST_BUNDLE_NAME, TEST_MODULE_NAME, isEnabled, USERID); - EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); - ResetDataMgr(); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_1600 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1600, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - - ClearDataMgr(); - std::string resString = overlayDataMgr.GetCallingBundleName(); - EXPECT_EQ(resString.empty(), true); - ResetDataMgr(); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_1700 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1700, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo oldInfo; - oldInfo.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); - - ClearDataMgr(); - BuildInternalOverlayConnection(TEST_MODULE_NAME, oldInfo, USERID); - ResetDataMgr(); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_1900 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1900, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo targetInnerBundleInfo; - - ClearDataMgr(); - RemoveOverlayBundleInfo(TEST_MODULE_NAME, targetInnerBundleInfo); - ResetDataMgr(); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_2300 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_2300, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo newInfo; - InnerBundleUserInfo userInfo; - - ClearDataMgr(); - AddOverlayModuleStates(newInfo, userInfo); - ResetDataMgr(); -} - -/** - * @tc.number: CheckAppLabel_0010 - * @tc.name: test CheckAppLabel - * @tc.desc: 1.Test the CheckAppLabel -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckAppLabel_0010, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - InnerBundleInfo oldInfo; - InnerBundleInfo newInfo; - oldInfo.baseApplicationInfo_->targetBundleName = TEST_MODULE_NAME; - ErrCode res = installer.CheckAppLabel(oldInfo, newInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_TARGET_BUNDLE_NAME_NOT_SAME); -} - -/** - * @tc.number: CheckAppLabel_0020 - * @tc.name: test CheckAppLabel - * @tc.desc: 1.Test the CheckAppLabel -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckAppLabel_0020, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - InnerBundleInfo oldInfo; - InnerBundleInfo newInfo; - oldInfo.baseApplicationInfo_->targetPriority = FOUR; - ErrCode res = installer.CheckAppLabel(oldInfo, newInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_TARGET_PRIORITY_NOT_SAME); -} - -/** - * @tc.number: CheckOverlayInstallation_0010 - * @tc.name: test CheckOverlayInstallation - * @tc.desc: 1.Test the CheckOverlayInstallation -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayInstallation_0010, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - std::unordered_map newInfos; - InnerBundleInfo newInfo; - newInfo.SetOverlayState(NON_OVERLAY_TYPE); - newInfos.try_emplace(TEST_MODULE_NAME, newInfo); - ErrCode res = installer.CheckOverlayInstallation(newInfos, USERID); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: CheckOverlayInstallation_0020 - * @tc.name: test CheckOverlayInstallation - * @tc.desc: 1.Test the CheckOverlayInstallation -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayInstallation_0020, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - std::unordered_map newInfos; - InnerBundleInfo info1; - info1.SetOverlayType(OVERLAY_INTERNAL_BUNDLE); - newInfos.try_emplace(TEST_MODULE_NAME, info1); - ErrCode res = installer.CheckOverlayInstallation(newInfos, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_HAP_TYPE); -} - -/** - * @tc.number: CheckOverlayInstallation_0030 - * @tc.name: test CheckOverlayInstallation - * @tc.desc: 1.Test the CheckOverlayInstallation -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayInstallation_0030, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - std::unordered_map newInfos; - InnerBundleInfo info1; - info1.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); - newInfos.try_emplace(TEST_MODULE_NAME, info1); - ErrCode res = installer.CheckOverlayInstallation(newInfos, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_HAP_TYPE); -} - -/** - * @tc.number: GetNotifyType_0010 - * @tc.name: test GetNotifyType - * @tc.desc: 1.Test the GetNotifyType -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, GetNotifyType_0010, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - installer.isAppExist_ = true; - installer.hasInstalledInUser_ = true; - installer.overlayType_ = OVERLAY_EXTERNAL_BUNDLE; - NotifyType res = installer.GetNotifyType(); - EXPECT_EQ(res, NotifyType::OVERLAY_UPDATE); -} - -/** - * @tc.number: GetNotifyType_0020 - * @tc.name: test GetNotifyType - * @tc.desc: 1.Test the GetNotifyType -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, GetNotifyType_0020, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - installer.isAppExist_ = true; - installer.hasInstalledInUser_ = true; - installer.overlayType_ = NON_OVERLAY_TYPE; - NotifyType res = installer.GetNotifyType(); - EXPECT_EQ(res, NotifyType::UPDATE); -} - -/** - * @tc.number: GetNotifyType_0030 - * @tc.name: test GetNotifyType - * @tc.desc: 1.Test the GetNotifyType -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, GetNotifyType_0030, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - installer.isAppExist_ = false; - installer.hasInstalledInUser_ = true; - installer.overlayType_ = OVERLAY_EXTERNAL_BUNDLE; - NotifyType res = installer.GetNotifyType(); - EXPECT_EQ(res, NotifyType::OVERLAY_INSTALL); -} - -/** - * @tc.number: GetNotifyType_0040 - * @tc.name: test GetNotifyType - * @tc.desc: 1.Test the GetNotifyType -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, GetNotifyType_0040, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - installer.isAppExist_ = true; - installer.hasInstalledInUser_ = false; - installer.overlayType_ = NON_OVERLAY_TYPE; - NotifyType res = installer.GetNotifyType(); - EXPECT_EQ(res, NotifyType::INSTALL); -} - -/** - * @tc.number: CheckOverlayUpdate_0010 - * @tc.name: test CheckOverlayUpdate - * @tc.desc: 1.Test the CheckOverlayUpdate -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayUpdate_0010, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - InnerBundleInfo oldInfo; - InnerBundleInfo newInfo; - newInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); - oldInfo.SetOverlayType(OverlayType::OVERLAY_INTERNAL_BUNDLE); - ErrCode res = installer.CheckOverlayUpdate(oldInfo, newInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_OVERLAY_TYPE_NOT_SAME); -} - -/** - * @tc.number: CheckOverlayUpdate_0020 - * @tc.name: test CheckOverlayUpdate - * @tc.desc: 1.Test the CheckOverlayUpdate -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayUpdate_0020, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - InnerBundleInfo oldInfo; - InnerBundleInfo newInfo; - oldInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); - newInfo.SetOverlayType(OverlayType::OVERLAY_INTERNAL_BUNDLE); - ErrCode res = installer.CheckOverlayUpdate(oldInfo, newInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_OVERLAY_TYPE_NOT_SAME); -} - -/** - * @tc.number: CheckOverlayUpdate_0030 - * @tc.name: test CheckOverlayUpdate - * @tc.desc: 1.Test the CheckOverlayUpdate -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayUpdate_0030, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - InnerBundleInfo oldInfo; - InnerBundleInfo newInfo; - oldInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); - newInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); - newInfo.currentPackage_ = TEST_PACK_AGE; - ErrCode res = installer.CheckOverlayUpdate(oldInfo, newInfo, USERID); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: CheckOverlayUpdate_0040 - * @tc.name: test CheckOverlayUpdate - * @tc.desc: 1.Test the CheckOverlayUpdate -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayUpdate_0040, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - InnerBundleInfo oldInfo; - InnerBundleInfo newInfo; - oldInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); - newInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); - - newInfo.currentPackage_ = TEST_PACK_AGE; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.targetModuleName = ""; - oldInfo.innerModuleInfos_[TEST_PACK_AGE] = innerModuleInfo; - ErrCode res = installer.CheckOverlayUpdate(oldInfo, newInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_OVERLAY_TYPE_NOT_SAME); -} - -/** - * @tc.number: CheckOverlayUpdate_0050 - * @tc.name: test CheckOverlayUpdate - * @tc.desc: 1.Test the CheckOverlayUpdate -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayUpdate_0050, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - InnerBundleInfo oldInfo; - InnerBundleInfo newInfo; - oldInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); - newInfo.SetOverlayType(OverlayType::NON_OVERLAY_TYPE); - - newInfo.currentPackage_ = TEST_PACK_AGE; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.targetModuleName = "targetModuleName"; - oldInfo.innerModuleInfos_[TEST_PACK_AGE] = innerModuleInfo; - ErrCode res = installer.CheckOverlayUpdate(oldInfo, newInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_OVERLAY_TYPE_NOT_SAME); -} - -/** - * @tc.number: CheckOverlayUpdate_0060 - * @tc.name: test CheckOverlayUpdate - * @tc.desc: 1.Test the CheckOverlayUpdate -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayUpdate_0060, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - InnerBundleInfo oldInfo; - InnerBundleInfo newInfo; - oldInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); - newInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); - - newInfo.currentPackage_ = TEST_PACK_AGE; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.targetModuleName = "targetModuleName"; - oldInfo.innerModuleInfos_[TEST_PACK_AGE] = innerModuleInfo; - ErrCode res = installer.CheckOverlayUpdate(oldInfo, newInfo, USERID); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: CopyHapsToSecurityDir_0010 - * @tc.name: test CopyHapsToSecurityDir - * @tc.desc: 1.Test the CopyHapsToSecurityDir -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, CopyHapsToSecurityDir_0010, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - InstallParam installParam; - installParam.withCopyHaps = true; - std::vector bundlePaths; - bundlePaths.push_back("data/test/test"); - ErrCode res = installer.CopyHapsToSecurityDir(installParam, bundlePaths); - EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_DISK_MEM_INSUFFICIENT); -} - -/** - * @tc.number: CopyHapsToSecurityDir_0020 - * @tc.name: test CopyHapsToSecurityDir - * @tc.desc: 1.Test the CopyHapsToSecurityDir -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, CopyHapsToSecurityDir_0020, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - InstallParam installParam; - installParam.withCopyHaps = true; - std::vector bundlePaths; - ErrCode res = installer.CopyHapsToSecurityDir(installParam, bundlePaths); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: FindSignatureFileDir_0010 - * @tc.name: test FindSignatureFileDir - * @tc.desc: 1.Test the FindSignatureFileDir -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, FindSignatureFileDir_0010, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - std::string signatureFileDir; - - installer.verifyCodeParams_.emplace(TEST_MODULE_NAME, TEST_MODULE_NAME); - ErrCode res = installer.FindSignatureFileDir(TEST_MODULE_NAME + "1", signatureFileDir); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_INSTALL_CODE_SIGNATURE_FAILED); -} - -/** - * @tc.number: FindSignatureFileDir_0020 - * @tc.name: test FindSignatureFileDir - * @tc.desc: 1.Test the FindSignatureFileDir -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, FindSignatureFileDir_0020, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - std::string signatureFileDir; - - installer.verifyCodeParams_.emplace(TEST_MODULE_NAME, TEST_MODULE_NAME); - ErrCode res = installer.FindSignatureFileDir(TEST_MODULE_NAME, signatureFileDir); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_INSTALL_CODE_SIGNATURE_FILE_IS_INVALID); -} - -/** - * @tc.number: FindSignatureFileDir_0030 - * @tc.name: test FindSignatureFileDir - * @tc.desc: 1.Test the FindSignatureFileDir -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, FindSignatureFileDir_0030, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - std::string signatureFileDir = "testModuleName.sig"; - - installer.verifyCodeParams_.emplace(TEST_MODULE_NAME, signatureFileDir); - ErrCode res = installer.FindSignatureFileDir(TEST_MODULE_NAME, signatureFileDir); - EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_DISK_MEM_INSUFFICIENT); -} +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#define private public + +#include + +#include "appexecfwk_errors.h" +#include "bundle_overlay_data_manager.h" +#include "bundle_overlay_install_checker.h" +#include "bundle_overlay_manager.h" +#include "bundle_mgr_service.h" + +#include + +using namespace testing::ext; +using namespace OHOS::AppExecFwk; +using OHOS::DelayedSingleton; + +namespace OHOS { +namespace { +const std::string TEST_MODULE_NAME = "testModuleName"; +const std::string TEST_MODULE_NAME_SECOND = "testModuleNameSecond"; +const std::string TARGET_MODULE_NAME = "targetModuleName"; +const std::string OTHER_TARGET_MODULE_NAME = "targetModuleNameTest"; +const std::string TARGET_BUNDLE_NAME = "targetBundleName"; +const std::string TEST_BUNDLE_NAME = "testBundleName"; +const std::string TEST_BUNDLE_NAME2 = "testBundleName2"; +const std::string TEST_PATH_FIRST = "testPath1"; +const std::string TEST_PATH_SECOND = "testPath2"; +const std::string TEST_PACK_AGE = "modulePackage"; +const std::string NO_EXIST = "noExist"; +const std::string BUNDLE_NAME = "oho.test.bundleName"; +const std::string SHARED_HAP_TYPE = "shared"; +const std::string FEATURE_HAP_TYPE = "feature"; +const std::string SHARED_TYPE = "shared"; +const int32_t INVALID_TARGET_PRIORITY_FIRST = 0; +const int32_t INVALID_TARGET_PRIORITY_SECOND = 101; +const int32_t DEFAULT_TARGET_PRIORITY_SECOND = 1; +const int32_t TEST_VERSION_CODE = 1000000; +const int32_t LOWER_TEST_VERSION_CODE = 999999; +const int32_t HIGHER_TEST_VERSION_CODE = 1000001; +const int32_t USERID = 100; +const int32_t NOT_EXIST_USERID = -5; +const int32_t FOUR = 4; +const int32_t DEFAULT_OVERLAY_BUNDLE_INFO = 0; +const int32_t WAIT_TIME = 5; // init mocked bms +} // namespace + +class BmsBundleOverlayCheckerTest : public testing::Test { +public: + BmsBundleOverlayCheckerTest(); + ~BmsBundleOverlayCheckerTest(); + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); + void AddInnerBundleInfo(); + void UninstallBundleInfo(); + void BuildInternalOverlayConnection(const std::string &moduleName, InnerBundleInfo &oldInfo, int32_t userId); + void RemoveOverlayBundleInfo(const std::string &targetBundleName, InnerBundleInfo &targetInnerBundleInfo); + void AddOverlayModuleStates(const InnerBundleInfo &innerBundleInfo, InnerBundleUserInfo &userInfo); + void ClearDataMgr(); + void ResetDataMgr(); + + const std::shared_ptr GetBundleDataMgr() const; + const std::shared_ptr GetBundleOverlayChecker() const; + +private: + std::shared_ptr overlayChecker_ = std::make_shared(); + static std::shared_ptr bundleMgrService_; +}; + +std::shared_ptr BmsBundleOverlayCheckerTest::bundleMgrService_ = + DelayedSingleton::GetInstance(); + +BmsBundleOverlayCheckerTest::BmsBundleOverlayCheckerTest() +{} + +BmsBundleOverlayCheckerTest::~BmsBundleOverlayCheckerTest() +{} + +void BmsBundleOverlayCheckerTest::SetUpTestCase() +{} + +void BmsBundleOverlayCheckerTest::TearDownTestCase() +{ + bundleMgrService_->OnStop(); +} + +void BmsBundleOverlayCheckerTest::SetUp() +{ + if (!bundleMgrService_->IsServiceReady()) { + bundleMgrService_->OnStart(); + std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME)); + } +} + +void BmsBundleOverlayCheckerTest::BuildInternalOverlayConnection( + const std::string &moduleName, InnerBundleInfo &oldInfo, int32_t userId) +{ + OverlayDataMgr overlayDataMgr; + return overlayDataMgr.BuildInternalOverlayConnection(TEST_MODULE_NAME, oldInfo, USERID); +} + +void BmsBundleOverlayCheckerTest::RemoveOverlayBundleInfo( + const std::string &targetBundleName, InnerBundleInfo &targetInnerBundleInfo) +{ + OverlayDataMgr overlayDataMgr; + return overlayDataMgr.RemoveOverlayBundleInfo(TEST_MODULE_NAME, targetInnerBundleInfo); +} + +void BmsBundleOverlayCheckerTest::AddOverlayModuleStates( + const InnerBundleInfo &innerBundleInfo, InnerBundleUserInfo &userInfo) +{ + OverlayDataMgr overlayDataMgr; + return overlayDataMgr.AddOverlayModuleStates(innerBundleInfo, userInfo); +} + +void BmsBundleOverlayCheckerTest::ClearDataMgr() +{ + bundleMgrService_->dataMgr_ = nullptr; +} + +void BmsBundleOverlayCheckerTest::ResetDataMgr() +{ + bundleMgrService_->dataMgr_ = std::make_shared(); + EXPECT_NE(bundleMgrService_->dataMgr_, nullptr); +} + +void BmsBundleOverlayCheckerTest::TearDown() +{} + +void BmsBundleOverlayCheckerTest::AddInnerBundleInfo() +{ + // construct innerBundleInfo + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.name = TEST_MODULE_NAME; + innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; + innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + ApplicationInfo applicationInfo; + applicationInfo.bundleName = TEST_BUNDLE_NAME; + applicationInfo.targetBundleName = TEST_BUNDLE_NAME; + innerBundleInfo.SetBaseApplicationInfo(applicationInfo); + + // construct target module + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + + InnerBundleInfo oldInfo; + InnerModuleInfo targetModuleInfo; + targetModuleInfo.name = TARGET_MODULE_NAME; + targetModuleInfo.targetModuleName = OTHER_TARGET_MODULE_NAME; + targetModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; + ApplicationInfo targetApplicationInfo; + targetApplicationInfo.bundleName = TEST_BUNDLE_NAME; + + oldInfo.InsertInnerModuleInfo(TARGET_MODULE_NAME, targetModuleInfo); + oldInfo.SetBaseApplicationInfo(targetApplicationInfo); + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); + dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, oldInfo); +} + +void BmsBundleOverlayCheckerTest::UninstallBundleInfo() +{ + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + bool startRet = dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_START); + bool finishRet = dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_SUCCESS); + + EXPECT_TRUE(startRet); + EXPECT_TRUE(finishRet); +} + +const std::shared_ptr BmsBundleOverlayCheckerTest::GetBundleDataMgr() const +{ + return bundleMgrService_->GetDataMgr(); +} + +const std::shared_ptr BmsBundleOverlayCheckerTest::GetBundleOverlayChecker() const +{ + return overlayChecker_; +} + +/** + * @tc.number: OverlayCheckerTest_0100 + * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. + * @tc.desc: 1.the internal overlay hap is entry type. + * 2.check failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0100, Function | SmallTest | Level0) +{ + // construct innerBundleInfo + InnerModuleInfo innerModuleInfo; + Distro distro; + distro.moduleType = FEATURE_HAP_TYPE; + innerModuleInfo.distro = distro; + innerModuleInfo.name = TEST_MODULE_NAME; + InnerBundleInfo innerBundleInfo; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + std::unordered_map newInfos; + + auto overlayChecker = GetBundleOverlayChecker(); + EXPECT_NE(overlayChecker, nullptr); + auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_HAP_TYPE); +} + +/** + * @tc.number: OverlayCheckerTest_0200 + * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. + * @tc.desc: 1.the internal overlay bundle is service. + * 2.check failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0200, Function | SmallTest | Level0) +{ + // construct innerBundleInfo + InnerModuleInfo innerModuleInfo; + innerModuleInfo.name = TEST_MODULE_NAME; + Distro distro; + distro.moduleType = SHARED_HAP_TYPE; + innerModuleInfo.distro = distro; + InnerBundleInfo innerBundleInfo; + innerBundleInfo.SetEntryInstallationFree(true); + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + std::unordered_map newInfos; + + auto overlayChecker = GetBundleOverlayChecker(); + EXPECT_NE(overlayChecker, nullptr); + auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_BUNDLE_TYPE); +} + +/** + * @tc.number: OverlayCheckerTest_0400 + * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. + * @tc.desc: 1.target priority of internal overlay hap is invalid. + * 2.check failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0400, Function | SmallTest | Level0) +{ + // construct innerBundleInfo + InnerModuleInfo innerModuleInfo; + innerModuleInfo.name = TEST_MODULE_NAME; + Distro distro; + distro.moduleType = SHARED_HAP_TYPE; + innerModuleInfo.distro = distro; + innerModuleInfo.targetPriority = INVALID_TARGET_PRIORITY_FIRST; + InnerBundleInfo innerBundleInfo; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + std::unordered_map newInfos; + + auto overlayChecker = GetBundleOverlayChecker(); + EXPECT_NE(overlayChecker, nullptr); + auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_PRIORITY); +} + +/** + * @tc.number: OverlayCheckerTest_0500 + * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. + * @tc.desc: 1.target priority of internal overlay hap is invalid. + * 2.check failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0500, Function | SmallTest | Level0) +{ + // construct innerBundleInfo + InnerModuleInfo innerModuleInfo; + innerModuleInfo.name = TEST_MODULE_NAME; + Distro distro; + distro.moduleType = SHARED_HAP_TYPE; + innerModuleInfo.distro = distro; + innerModuleInfo.targetPriority = INVALID_TARGET_PRIORITY_SECOND; + InnerBundleInfo innerBundleInfo; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + std::unordered_map newInfos; + auto overlayChecker = GetBundleOverlayChecker(); + EXPECT_NE(overlayChecker, nullptr); + auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_PRIORITY); +} + +/** + * @tc.number: OverlayCheckerTest_0600 + * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. + * @tc.desc: 1.target module name of the internal overlay is same as the module name. + * 2.check failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0600, Function | SmallTest | Level0) +{ + // construct innerBundleInfo + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.name = TEST_MODULE_NAME; + innerModuleInfo.targetModuleName = TEST_MODULE_NAME; + innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; + Distro distro; + distro.moduleType = SHARED_HAP_TYPE; + innerModuleInfo.distro = distro; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + std::unordered_map newInfos; + + auto overlayChecker = GetBundleOverlayChecker(); + EXPECT_NE(overlayChecker, nullptr); + auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_MODULE_NAME); +} + +/** + * @tc.number: OverlayCheckerTest_0700 + * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. + * @tc.desc: 1.target module is overlay module. + * 2.check failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0700, Function | SmallTest | Level0) +{ + // construct innerBundleInfo + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.name = TEST_MODULE_NAME; + innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; + innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; + Distro distro; + distro.moduleType = SHARED_HAP_TYPE; + innerModuleInfo.distro = distro; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + ApplicationInfo applicationInfo; + applicationInfo.bundleName = TEST_BUNDLE_NAME; + innerBundleInfo.SetBaseApplicationInfo(applicationInfo); + + // construct target module + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + + InnerBundleInfo oldInfo; + InnerModuleInfo targetModuleInfo; + targetModuleInfo.name = TARGET_MODULE_NAME; + targetModuleInfo.targetModuleName = OTHER_TARGET_MODULE_NAME; + targetModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; + Distro targetDistro; + targetDistro.moduleType = SHARED_HAP_TYPE; + innerModuleInfo.distro = targetDistro; + ApplicationInfo targetApplicationInfo; + targetApplicationInfo.bundleName = TEST_BUNDLE_NAME; + + oldInfo.InsertInnerModuleInfo(TARGET_MODULE_NAME, targetModuleInfo); + oldInfo.SetBaseApplicationInfo(targetApplicationInfo); + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); + dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, oldInfo); + std::unordered_map newInfos; + + auto overlayChecker = GetBundleOverlayChecker(); + EXPECT_NE(overlayChecker, nullptr); + auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_TARGET_MODULE_IS_OVERLAY_MODULE); + + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_START); + bool ret = dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_SUCCESS); + EXPECT_TRUE(ret); +} + +/** + * @tc.number: OverlayCheckerTest_0800 + * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. + * @tc.desc: 1.install overlay hap and non-overlay hap simultaneously. + * 2.check successfully. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0800, Function | SmallTest | Level0) +{ + // construct overlay innerBundleInfo + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.name = TEST_MODULE_NAME; + innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; + innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; + Distro distro; + distro.moduleType = SHARED_HAP_TYPE; + innerModuleInfo.distro = distro; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + + // construct non-overlay innerBundleInfo + InnerBundleInfo nonOverlayBundleInfo; + InnerModuleInfo nonInnerModuleInfo; + nonInnerModuleInfo.name = TEST_MODULE_NAME_SECOND; + nonOverlayBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME_SECOND); + nonOverlayBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME_SECOND, nonInnerModuleInfo); + + std::unordered_map newInfos; + newInfos.emplace(TEST_PATH_FIRST, innerBundleInfo); + newInfos.emplace(TEST_PATH_SECOND, nonOverlayBundleInfo); + + auto overlayChecker = GetBundleOverlayChecker(); + EXPECT_NE(overlayChecker, nullptr); + auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: OverlayCheckerTest_0900 + * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. + * @tc.desc: 1.install internal overlay hap. + * 2.the version code of overlay hap is larger than non-overlay module. + * 3.check failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0900, Function | SmallTest | Level0) +{ + // construct overlay innerBundleInfo + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.name = TEST_MODULE_NAME; + innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; + innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; + Distro distro; + distro.moduleType = SHARED_HAP_TYPE; + innerModuleInfo.distro = distro; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + BundleInfo bundleInfo; + bundleInfo.versionCode = HIGHER_TEST_VERSION_CODE; + innerBundleInfo.SetBaseBundleInfo(bundleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + ApplicationInfo applicationInfo; + applicationInfo.bundleName = TEST_BUNDLE_NAME; + innerBundleInfo.SetBaseApplicationInfo(applicationInfo); + std::unordered_map newInfos; + + // construct old innerBundleInfo + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + + InnerBundleInfo oldInfo; + InnerModuleInfo oldInnerModuleInfo; + oldInnerModuleInfo.name = TEST_MODULE_NAME_SECOND; + oldInfo.InsertInnerModuleInfo(TEST_MODULE_NAME_SECOND, oldInnerModuleInfo); + BundleInfo oldBundleInfo; + oldBundleInfo.versionCode = TEST_VERSION_CODE; + oldInfo.SetBaseBundleInfo(oldBundleInfo); + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); + dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, oldInfo); + + auto overlayChecker = GetBundleOverlayChecker(); + EXPECT_NE(overlayChecker, nullptr); + auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INCONSISTENT_VERSION_CODE); + + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_START); + bool ret = dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_SUCCESS); + EXPECT_TRUE(ret); +} + +/** + * @tc.number: BundleOverlayManagerTest_0100 + * @tc.name: check param is empty + * @tc.desc: 1.Test BundleOverlayManager + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, BundleOverlayManagerTest_0100, Function | SmallTest | Level0) +{ + BundleOverlayManager manager; + std::string bundleName = ""; + bool ret = manager.IsExistedNonOverlayHap(bundleName); + EXPECT_EQ(ret, false); + InnerBundleInfo innerBundleInfo; + ret = manager.GetInnerBundleInfo(bundleName, innerBundleInfo); + EXPECT_EQ(ret, false); + + int32_t userId = Constants::INVALID_USERID; + std::vector overlayModuleInfos; + auto code = manager.GetAllOverlayModuleInfo(bundleName, overlayModuleInfos, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + code = manager.GetAllOverlayModuleInfo("com.ohos.test", overlayModuleInfos, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + + std::string moduleName = ""; + OverlayModuleInfo overlayModuleInfo; + code = manager.GetOverlayModuleInfo(bundleName, moduleName, overlayModuleInfo, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + code = manager.GetOverlayModuleInfo("com.ohos.test", moduleName, overlayModuleInfo, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + code = manager.GetOverlayModuleInfo("com.ohos.test", "entry", overlayModuleInfo, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + + std::string targetBundleName = ""; + std::vector overlayBundleInfo; + code = manager.GetOverlayBundleInfoForTarget(targetBundleName, overlayBundleInfo, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + code = manager.GetOverlayBundleInfoForTarget("target", overlayBundleInfo, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + + code = manager.GetOverlayModuleInfoForTarget(targetBundleName, "", overlayModuleInfos, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + code = manager.GetOverlayModuleInfoForTarget("target", "", overlayModuleInfos, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + + userId = Constants::DEFAULT_USERID; + code = manager.GetAllOverlayModuleInfo("com.ohos.test", overlayModuleInfos, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); + code = manager.GetOverlayModuleInfo("com.ohos.test", "entry", overlayModuleInfo, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); +} + +/** + * @tc.number: CheckInternalBundle_0100 + * @tc.name: check hap type failed + * @tc.desc: 1.Test CheckInternalBundle + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckInternalBundle_0100, Function | SmallTest | Level0) +{ + BundleOverlayInstallChecker checker; + std::unordered_map newInfos; + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.isEntry = true; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + auto code = checker.CheckInternalBundle(newInfos, innerBundleInfo); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_HAP_TYPE); + innerModuleInfo.isEntry = false; + code = checker.CheckInternalBundle(newInfos, innerBundleInfo); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_HAP_TYPE); + + innerBundleInfo.SetEntryInstallationFree(true); + code = checker.CheckInternalBundle(newInfos, innerBundleInfo); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_HAP_TYPE); +} + +/** + * @tc.number: CheckInternalBundle_0200 + * @tc.name: check module target priority range + * @tc.desc: 1.Test CheckInternalBundle + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckInternalBundle_0200, Function | SmallTest | Level0) +{ + BundleOverlayInstallChecker checker; + std::unordered_map newInfos; + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + Distro distro; + distro.moduleType = SHARED_HAP_TYPE; + innerModuleInfo.distro = distro; + innerModuleInfo.targetPriority = Constants::OVERLAY_MINIMUM_PRIORITY - 1; + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + auto code = checker.CheckInternalBundle(newInfos, innerBundleInfo); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_PRIORITY); +} + +/** + * @tc.number: CheckInternalBundle_0300 + * @tc.name: check module target priority range + * @tc.desc: 1.Test CheckInternalBundle + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckInternalBundle_0300, Function | SmallTest | Level0) +{ + BundleOverlayInstallChecker checker; + std::unordered_map newInfos; + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + Distro distro; + distro.moduleType = SHARED_HAP_TYPE; + innerModuleInfo.distro = distro; + innerModuleInfo.targetPriority = Constants::OVERLAY_MINIMUM_PRIORITY + 1; + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + innerModuleInfo.targetModuleName = TEST_MODULE_NAME; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + + auto code = checker.CheckInternalBundle(newInfos, innerBundleInfo); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_MODULE_NAME); +} + +/** + * @tc.number: CheckExternalBundle_0100 + * @tc.name: check bundle priority + * @tc.desc: 1.Test CheckExternalBundle + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckExternalBundle_0100, Function | SmallTest | Level0) +{ + BundleOverlayInstallChecker checker; + InnerBundleInfo innerBundleInfo; + int32_t userId = Constants::INVALID_USERID; + BundleInfo bundleInfo; + bundleInfo.entryInstallationFree = true; + innerBundleInfo.SetBaseBundleInfo(bundleInfo); + auto code = checker.CheckExternalBundle(innerBundleInfo, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_BUNDLE_TYPE); + + bundleInfo.entryInstallationFree = false; + innerBundleInfo.SetBaseBundleInfo(bundleInfo); + ApplicationInfo applicationInfo; + applicationInfo.targetPriority = Constants::OVERLAY_MINIMUM_PRIORITY - 1; + innerBundleInfo.SetBaseApplicationInfo(applicationInfo); + InnerModuleInfo innerModuleInfo; + Distro distro; + distro.moduleType = SHARED_HAP_TYPE; + innerModuleInfo.distro = distro; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + code = checker.CheckExternalBundle(innerBundleInfo, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_PRIORITY); + + applicationInfo.targetPriority = Constants::OVERLAY_MAXIMUM_PRIORITY + 1; + innerBundleInfo.SetBaseApplicationInfo(applicationInfo); + code = checker.CheckExternalBundle(innerBundleInfo, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_PRIORITY); +} + +/** + * @tc.number: CheckExternalBundle_0200 + * @tc.name: check bundle priority + * @tc.desc: 1.Test CheckExternalBundle + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckExternalBundle_0200, Function | SmallTest | Level0) +{ + BundleOverlayInstallChecker checker; + InnerBundleInfo innerBundleInfo; + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + int32_t userId = Constants::INVALID_USERID; + ApplicationInfo applicationInfo; + applicationInfo.bundleName = TEST_BUNDLE_NAME; + applicationInfo.targetBundleName = TEST_BUNDLE_NAME; + applicationInfo.targetPriority = Constants::OVERLAY_MINIMUM_PRIORITY + 1; + innerBundleInfo.SetBaseApplicationInfo(applicationInfo); + InnerModuleInfo innerModuleInfo; + innerModuleInfo.targetPriority = Constants::OVERLAY_MINIMUM_PRIORITY + 1; + Distro distro; + distro.moduleType = SHARED_HAP_TYPE; + innerModuleInfo.distro = distro; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + auto code = checker.CheckExternalBundle(innerBundleInfo, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_BUNDLE_NAME_SAME_WITH_TARGET_BUNDLE_NAME); + applicationInfo.bundleName = ""; + innerBundleInfo.SetBaseApplicationInfo(applicationInfo); + code = checker.CheckExternalBundle(innerBundleInfo, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_NO_SYSTEM_APPLICATION_FOR_EXTERNAL_OVERLAY); + + innerBundleInfo.SetIsPreInstallApp(true); + code = checker.CheckExternalBundle(innerBundleInfo, userId); + EXPECT_EQ(code, ERR_OK); + + innerBundleInfo.SetCurrentModulePackage(SHARED_TYPE); + code = checker.CheckExternalBundle(innerBundleInfo, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_HAP_TYPE); +} + +/** + * @tc.number: OverlayDataMgr_0100 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of UpdateOverlayInfo. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0100, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + InnerBundleInfo targetInnerBundleInfo; + + newInfo.SetOverlayType(OverlayType::OVERLAY_INTERNAL_BUNDLE); + ErrCode res = overlayDataMgr.UpdateOverlayInfo(newInfo, oldInfo, targetInnerBundleInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); + newInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); + res = overlayDataMgr.UpdateOverlayInfo(newInfo, oldInfo, targetInnerBundleInfo); + EXPECT_EQ(res, ERR_OK); + newInfo.SetOverlayType(OverlayType::NON_OVERLAY_TYPE); + res = overlayDataMgr.UpdateOverlayInfo(newInfo, oldInfo, targetInnerBundleInfo); + EXPECT_EQ(res, ERR_OK); + + newInfo.SetOverlayType(FOUR); + res = overlayDataMgr.UpdateOverlayInfo(newInfo, oldInfo, targetInnerBundleInfo); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: OverlayDataMgr_0200 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of IsExistedNonOverlayHap. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0200, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + bool res = overlayDataMgr.IsExistedNonOverlayHap(""); + EXPECT_EQ(res, false); + res = overlayDataMgr.IsExistedNonOverlayHap("wrong"); + EXPECT_EQ(res, false); +} + +/** + * @tc.number: OverlayDataMgr_0300 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of UpdateInternalOverlayInfo. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0300, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + ErrCode res = overlayDataMgr.UpdateInternalOverlayInfo(newInfo, oldInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); + std::map innerModuleInfos; + InnerModuleInfo moduleInfo; + moduleInfo.moduleName = TEST_PACK_AGE; + moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; + innerModuleInfos[TEST_PACK_AGE] = moduleInfo; + newInfo.AddInnerModuleInfo(innerModuleInfos); + res = overlayDataMgr.UpdateInternalOverlayInfo(newInfo, oldInfo); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: OverlayDataMgr_0400 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of UpdateExternalOverlayInfo. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0400, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo innerBundleInfo; + InnerBundleInfo oldInfo; + InnerBundleInfo targetInnerBundleInfo; + + ErrCode res = overlayDataMgr.UpdateExternalOverlayInfo(innerBundleInfo, oldInfo, targetInnerBundleInfo); + EXPECT_EQ(res, ERR_OK); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + ApplicationInfo applicationInfo; + applicationInfo.bundleName = TEST_BUNDLE_NAME; + innerBundleInfo.SetBaseApplicationInfo(applicationInfo); + + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + + ApplicationInfo targetApplicationInfo; + targetApplicationInfo.bundleName = TEST_BUNDLE_NAME; + + oldInfo.SetBaseApplicationInfo(targetApplicationInfo); + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); + dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, oldInfo); + innerBundleInfo.SetTargetBundleName(TEST_BUNDLE_NAME); + res = overlayDataMgr.UpdateExternalOverlayInfo(innerBundleInfo, oldInfo, oldInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); + + InnerModuleInfo moduleInfo; + std::map innerModuleInfos; + moduleInfo.moduleName = "moduleName"; + moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; + innerModuleInfos[TEST_PACK_AGE] = moduleInfo; + innerBundleInfo.AddInnerModuleInfo(innerModuleInfos); + res = overlayDataMgr.UpdateExternalOverlayInfo(innerBundleInfo, oldInfo, oldInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); + + innerBundleInfo.SetUserId(Constants::NOT_EXIST_USERID); + res = overlayDataMgr.UpdateExternalOverlayInfo(innerBundleInfo, oldInfo, oldInfo); + EXPECT_EQ(res, ERR_OK); + UninstallBundleInfo(); +} + +/** + * @tc.number: OverlayDataMgr_0500 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of UpdateExternalOverlayInfo. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0500, Function | SmallTest | Level0) +{ + AddInnerBundleInfo(); + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + InnerBundleInfo targetInnerBundleInfo; + + OverlayDataMgr overlayDataMgr; + ErrCode res = overlayDataMgr.UpdateExternalOverlayInfo(newInfo, oldInfo, targetInnerBundleInfo); + EXPECT_EQ(res, ERR_OK); + UninstallBundleInfo(); +} + +#ifdef BUNDLE_FRAMEWORK_OVERLAY_INSTALLATION +/** + * @tc.number: OverlayDataMgr_0600 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of BuildOverlayConnection and BuildOverlayConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0600, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + const auto &moduleInfos = newInfo.GetInnerModuleInfos(); + std::string moduleName = (moduleInfos.begin()->second).moduleName; + overlayDataMgr.BuildInternalOverlayConnection(moduleName, oldInfo, newInfo.GetUserId()); + EXPECT_EQ(oldInfo.FetchInnerModuleInfos().empty(), true); + + oldInfo.SetOverlayState(OverlayType::OVERLAY_INTERNAL_BUNDLE); + overlayDataMgr.BuildInternalOverlayConnection(moduleName, oldInfo, newInfo.GetUserId()); + EXPECT_EQ(oldInfo.FetchInnerModuleInfos().empty(), true); +} + +/** + * @tc.number: OverlayDataMgr_0700 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of BuildOverlayConnection and BuildOverlayConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0700, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo oldInfo; + oldInfo.SetIsPreInstallApp(false); + ApplicationInfo applicationInfo; + applicationInfo.bundleName = NO_EXIST; + oldInfo.SetBaseApplicationInfo(applicationInfo); + EXPECT_EQ(oldInfo.baseApplicationInfo_->bundleName, NO_EXIST); +} + +/** + * @tc.number: OverlayDataMgr_0900 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of BuildOverlayConnection and BuildOverlayConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0900, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo oldInfo; + oldInfo.SetIsPreInstallApp(true); + oldInfo.SetCertificateFingerprint(NO_EXIST); + EXPECT_EQ(oldInfo.baseApplicationInfo_->fingerprint, NO_EXIST); +} +#endif + +/** + * @tc.number: OverlayDataMgr_1200 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of GetBundleDir. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1200, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + std::string moduleHapPath = "xxx/"; + std::string bundleDir; + ErrCode res = overlayDataMgr.GetBundleDir(moduleHapPath, bundleDir); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_BUNDLE_DIR); + moduleHapPath = "//"; + res = overlayDataMgr.GetBundleDir(moduleHapPath, bundleDir); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: OverlayDataMgr_1300 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1300, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); + std::map innerModuleInfos; + InnerModuleInfo moduleInfo; + moduleInfo.moduleName = TEST_PACK_AGE; + moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; + innerModuleInfos[TEST_PACK_AGE] = moduleInfo; + newInfo.AddInnerModuleInfo(innerModuleInfos); + oldInfo.AddInnerModuleInfo(innerModuleInfos); + res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: OverlayDataMgr_1400 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1400, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + std::map innerModuleInfos; + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); + dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, newInfo); + ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); + UninstallBundleInfo(); +} + +/** + * @tc.number: OverlayDataMgr_1500 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1500, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + std::map innerModuleInfos; + InnerModuleInfo moduleInfo; + moduleInfo.moduleName = TEST_PACK_AGE; + moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; + innerModuleInfos[TEST_PACK_AGE] = moduleInfo; + newInfo.AddInnerModuleInfo(innerModuleInfos); + oldInfo.AddInnerModuleInfo(innerModuleInfos); + newInfo.SetOverlayType(OVERLAY_INTERNAL_BUNDLE); + + ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: OverlayDataMgr_1600 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of QueryOverlayInnerBundleInfo. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1600, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo info; + bool res = overlayDataMgr.QueryOverlayInnerBundleInfo("", info); + EXPECT_EQ(res, false); +} + +/** + * @tc.number: OverlayDataMgr_1700 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of GetAllOverlayModuleInfo. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1700, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + std::vector overlayModuleInfos; + ErrCode res = overlayDataMgr.GetAllOverlayModuleInfo("", overlayModuleInfos, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); + + AddInnerBundleInfo(); + res = overlayDataMgr.GetAllOverlayModuleInfo( + TEST_BUNDLE_NAME, overlayModuleInfos, Constants::NOT_EXIST_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_NON_OVERLAY_BUNDLE); + + res = overlayDataMgr.GetAllOverlayModuleInfo( + TEST_BUNDLE_NAME, overlayModuleInfos, Constants::INVALID_USERID); + EXPECT_EQ(res, + ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); + + OverlayModuleInfo overlayModuleInfo; + overlayModuleInfos.push_back(overlayModuleInfo); + res = overlayDataMgr.GetAllOverlayModuleInfo( + TEST_BUNDLE_NAME, overlayModuleInfos, Constants::NOT_EXIST_USERID); + + EXPECT_EQ(res, + ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_NON_OVERLAY_BUNDLE); + UninstallBundleInfo(); +} + +/** + * @tc.number: OverlayDataMgr_1800 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of GetOverlayModuleInfo. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1800, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + OverlayModuleInfo overlayModuleInfos; + ErrCode res = overlayDataMgr.GetOverlayModuleInfo("", "", overlayModuleInfos, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); + + AddInnerBundleInfo(); + res = overlayDataMgr.GetOverlayModuleInfo( + TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfos, Constants::INVALID_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); + + res = overlayDataMgr.GetOverlayModuleInfo( + TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfos, Constants::NOT_EXIST_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_NON_OVERLAY_BUNDLE); +} + +/** + * @tc.number: OverlayDataMgr_1900 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of GetOverlayBundleInfoForTarget. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1900, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + std::vector overlayBundleInfo; + ErrCode res = overlayDataMgr.GetOverlayBundleInfoForTarget("", overlayBundleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_NOT_EXISTED); + + AddInnerBundleInfo(); + res = overlayDataMgr.GetOverlayBundleInfoForTarget( + TEST_BUNDLE_NAME, overlayBundleInfo, Constants::NOT_EXIST_USERID); + EXPECT_EQ(res, ERR_OK); + EXPECT_EQ(overlayBundleInfo.size(), DEFAULT_OVERLAY_BUNDLE_INFO); + + res = overlayDataMgr.GetOverlayBundleInfoForTarget( + TEST_BUNDLE_NAME, overlayBundleInfo, Constants::INVALID_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); + + UninstallBundleInfo(); +} + +/** + * @tc.number: OverlayDataMgr_2000 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of GetOverlayModuleInfoForTarget. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2000, Function | SmallTest | Level0) +{ + AddInnerBundleInfo(); + OverlayDataMgr overlayDataMgr; + std::vector overlayModuleInfos; + ErrCode res = overlayDataMgr.GetOverlayModuleInfoForTarget( + TEST_BUNDLE_NAME, TARGET_MODULE_NAME, overlayModuleInfos, Constants::NOT_EXIST_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_MODULE_IS_OVERLAY_MODULE); + + res = overlayDataMgr.GetOverlayModuleInfoForTarget( + TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfos, Constants::NOT_EXIST_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_MODULE_NOT_EXISTED); + + res = overlayDataMgr.GetOverlayModuleInfoForTarget( + TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfos, Constants::INVALID_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); + + res = overlayDataMgr.GetOverlayModuleInfoForTarget( + TEST_BUNDLE_NAME, "", overlayModuleInfos, Constants::NOT_EXIST_USERID); + EXPECT_EQ(res, ERR_OK); + + res = overlayDataMgr.GetOverlayModuleInfoForTarget( + "", "", overlayModuleInfos, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_NOT_EXISTED); + + UninstallBundleInfo(); +} + +/** + * @tc.number: OverlayDataMgr_2100 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of SetOverlayEnabled. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2100, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + bool isEnabled = false; + ErrCode res = overlayDataMgr.SetOverlayEnabled(TEST_BUNDLE_NAME, "", isEnabled, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); + + AddInnerBundleInfo(); + res = overlayDataMgr.SetOverlayEnabled( + TEST_BUNDLE_NAME, TEST_MODULE_NAME, isEnabled, Constants::INVALID_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); + + res = overlayDataMgr.SetOverlayEnabled(TEST_BUNDLE_NAME, TEST_MODULE_NAME, isEnabled, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); + + UninstallBundleInfo(); +} + +/** + * @tc.number: OverlayDataMgr_2200 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of GetCallingBundleName. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2200, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + std::string res = overlayDataMgr.GetCallingBundleName(); + EXPECT_EQ(res, ""); +} + +/** + * @tc.number: OverlayDataMgr_2300 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of AddOverlayModuleStates. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2300, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo innerBundleInfo; + InnerBundleUserInfo userInfo; + overlayDataMgr.AddOverlayModuleStates(innerBundleInfo, userInfo); + EXPECT_EQ(userInfo.bundleUserInfo.userId, Constants::INVALID_USERID); + + userInfo.bundleUserInfo.userId = USERID; + innerBundleInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); + overlayDataMgr.AddOverlayModuleStates(innerBundleInfo, userInfo); + EXPECT_EQ(userInfo.bundleUserInfo.userId, USERID); +} + +/** + * @tc.number: OverlayDataMgr_2400 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of AddOverlayModuleStates. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2400, Function | SmallTest | Level0) +{ + AddInnerBundleInfo(); + OverlayDataMgr overlayDataMgr; + InnerBundleInfo innerBundleInfo; + InnerBundleUserInfo userInfo; + userInfo.bundleUserInfo.userId = USERID; + innerBundleInfo.SetOverlayType(OverlayType::OVERLAY_INTERNAL_BUNDLE); + innerBundleInfo.SetTargetBundleName(TEST_BUNDLE_NAME); + overlayDataMgr.AddOverlayModuleStates(innerBundleInfo, userInfo); + EXPECT_EQ(userInfo.bundleUserInfo.userId, USERID); + UninstallBundleInfo(); +} + +/** + * @tc.number: OverlayDataMgr_2500 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2500, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + std::map innerModuleInfos; + InnerModuleInfo moduleInfo; + moduleInfo.moduleName = TEST_PACK_AGE; + moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; + innerModuleInfos[TEST_PACK_AGE] = moduleInfo; + newInfo.AddInnerModuleInfo(innerModuleInfos); + oldInfo.AddInnerModuleInfo(innerModuleInfos); + newInfo.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); + + ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); + EXPECT_EQ(res, ERR_OK); + + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + + ApplicationInfo applicationInfo; + applicationInfo.bundleName = TEST_BUNDLE_NAME; + applicationInfo.targetBundleName = TEST_BUNDLE_NAME; + oldInfo.SetBaseApplicationInfo(applicationInfo); + dataMgr->bundleInfos_.insert( + pair(TEST_BUNDLE_NAME, oldInfo)); + res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: OverlayDataMgr_2600 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2600, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + std::map innerModuleInfos; + InnerModuleInfo moduleInfo; + moduleInfo.moduleName = TEST_PACK_AGE; + moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; + innerModuleInfos[TEST_PACK_AGE] = moduleInfo; + newInfo.AddInnerModuleInfo(innerModuleInfos); + oldInfo.AddInnerModuleInfo(innerModuleInfos); + newInfo.SetOverlayType(NON_OVERLAY_TYPE); + + ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: OverlayDataMgr_2700 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2700, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + InnerBundleInfo targetInnerBundleInfo; + std::map innerModuleInfos; + + overlayDataMgr.RemoveOverlayBundleInfo(TEST_BUNDLE_NAME, targetInnerBundleInfo); + overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); + InnerModuleInfo moduleInfo; + moduleInfo.moduleName = TEST_PACK_AGE; + moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; + innerModuleInfos[TEST_PACK_AGE] = moduleInfo; + newInfo.AddInnerModuleInfo(innerModuleInfos); + oldInfo.AddInnerModuleInfo(innerModuleInfos); + newInfo.SetOverlayType(OVERLAY_INTERNAL_BUNDLE); + + ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: OverlayDataMgr_2800 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2800, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + std::map innerModuleInfos; + InnerModuleInfo moduleInfo; + moduleInfo.moduleName = TEST_PACK_AGE; + moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; + innerModuleInfos[TEST_PACK_AGE] = moduleInfo; + newInfo.AddInnerModuleInfo(innerModuleInfos); + oldInfo.AddInnerModuleInfo(innerModuleInfos); + newInfo.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); + + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + + ApplicationInfo applicationInfo; + applicationInfo.bundleName = TEST_BUNDLE_NAME; + applicationInfo.targetBundleName = TEST_BUNDLE_NAME; + oldInfo.SetBaseApplicationInfo(applicationInfo); + newInfo.SetTargetBundleName(NO_EXIST); + dataMgr->bundleInfos_.insert( + pair(TEST_BUNDLE_NAME, oldInfo)); + ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: OverlayDataMgr_2900 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleInfo. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2900, Function | SmallTest | Level0) +{ + AddInnerBundleInfo(); + + OverlayDataMgr overlayDataMgr; + InnerBundleInfo oldInfo; + InnerBundleInfo targetInnerBundleInfo; + std::map innerModuleInfos; + InnerModuleInfo moduleInfo; + moduleInfo.moduleName = TEST_PACK_AGE; + moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; + innerModuleInfos[TEST_PACK_AGE] = moduleInfo; + oldInfo.AddInnerModuleInfo(innerModuleInfos); + + overlayDataMgr.RemoveOverlayBundleInfo(TEST_BUNDLE_NAME, targetInnerBundleInfo); + overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); + + oldInfo.SetOverlayType(OVERLAY_INTERNAL_BUNDLE); + overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); + EXPECT_EQ(oldInfo.GetOverlayType(), OVERLAY_INTERNAL_BUNDLE); + + oldInfo.SetTargetBundleName(TARGET_MODULE_NAME); + overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); + EXPECT_EQ(oldInfo.GetTargetBundleName(), TARGET_MODULE_NAME); + + oldInfo.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); + overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); + EXPECT_EQ(oldInfo.GetOverlayType(), OVERLAY_EXTERNAL_BUNDLE); + + oldInfo.SetTargetBundleName(TARGET_MODULE_NAME); + overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); + EXPECT_EQ(oldInfo.GetTargetBundleName(), TARGET_MODULE_NAME); + + oldInfo.SetOverlayType(NON_OVERLAY_TYPE); + overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); + overlayDataMgr.RemoveOverlayModuleInfo("noExits", TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); + EXPECT_EQ(oldInfo.GetOverlayType(), NON_OVERLAY_TYPE); + UninstallBundleInfo(); +} + +/** + * @tc.number: OverlayDataMgr_3000 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3000, Function | SmallTest | Level0) +{ + InnerBundleInfo info; + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); + + info.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); + bool res = dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, info); + EXPECT_EQ(res, true); + + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME2, InstallState::INSTALL_START); + info.SetOverlayType(OverlayType::NON_OVERLAY_TYPE); + res = dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME2, info); + EXPECT_EQ(res, true); + + UninstallBundleInfo(); +} + +/** + * @tc.number: OverlayDataMgr_3100 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3100, Function | SmallTest | Level0) +{ + InnerBundleInfo info; + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); + + info.SetOverlayType(OverlayType::OVERLAY_INTERNAL_BUNDLE); + bool res = dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, info); + EXPECT_EQ(res, true); + + UninstallBundleInfo(); +} + +/** + * @tc.number: OverlayDataMgr_3200 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3200, Function | SmallTest | Level0) +{ + AddInnerBundleInfo(); + + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + std::map innerModuleInfos; + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + + bool res = dataMgr->AddNewModuleInfo(TEST_BUNDLE_NAME, newInfo, oldInfo); + EXPECT_EQ(res, false); + + UninstallBundleInfo(); +} + +/** + * @tc.number: OverlayDataMgr_3300 + * @tc.name: AddBundleInfo + * @tc.desc: 1. add module info to the data manager + * 2. query data then verify + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3300, Function | SmallTest | Level0) +{ + InnerBundleInfo info1; + BundleInfo bundleInfo1; + bundleInfo1.name = TEST_BUNDLE_NAME; + bundleInfo1.applicationInfo.bundleName = TEST_BUNDLE_NAME; + ApplicationInfo applicationInfo1; + applicationInfo1.name = TEST_BUNDLE_NAME; + applicationInfo1.bundleName = TEST_BUNDLE_NAME; + info1.SetBaseBundleInfo(bundleInfo1); + info1.SetBaseApplicationInfo(applicationInfo1); + + InnerBundleInfo info2; + BundleInfo bundleInfo2; + bundleInfo2.name = TEST_BUNDLE_NAME; + bundleInfo2.applicationInfo.bundleName = TEST_BUNDLE_NAME; + ApplicationInfo applicationInfo2; + applicationInfo2.name = TEST_BUNDLE_NAME; + applicationInfo2.bundleName = TEST_BUNDLE_NAME; + info2.SetBaseBundleInfo(bundleInfo2); + info2.SetBaseApplicationInfo(applicationInfo2); + + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); + dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, info1); + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UPDATING_START); + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UPDATING_SUCCESS); + info1.SetOverlayType(OverlayType::NON_OVERLAY_TYPE); + info2.SetOverlayType(OverlayType::OVERLAY_INTERNAL_BUNDLE); + bool ret = dataMgr->AddNewModuleInfo(TEST_BUNDLE_NAME, info2, info1); + EXPECT_FALSE(ret); + + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_START); + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_SUCCESS); +} + + +/** + * @tc.number: OverlayDataMgr_3400 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of IsExistedNonOverlayHap. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3400, Function | SmallTest | Level0) +{ + AddInnerBundleInfo(); + OverlayDataMgr overlayDataMgr; + bool res = overlayDataMgr.IsExistedNonOverlayHap(TEST_BUNDLE_NAME); + EXPECT_EQ(res, false); + + UninstallBundleInfo(); +} + +/** + * @tc.number: OverlayDataMgr_3500 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of BuildInternalOverlayConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3500, Function | SmallTest | Level0) +{ + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.name = TEST_MODULE_NAME; + innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; + innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + ApplicationInfo applicationInfo; + applicationInfo.bundleName = TEST_BUNDLE_NAME; + applicationInfo.targetBundleName = TEST_BUNDLE_NAME; + innerBundleInfo.SetBaseApplicationInfo(applicationInfo); + + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); + dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, innerBundleInfo); + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UPDATING_START); + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UPDATING_SUCCESS); + OverlayDataMgr overlayDataMgr; + overlayDataMgr.BuildInternalOverlayConnection(TARGET_MODULE_NAME, innerBundleInfo, USERID); + EXPECT_EQ(innerBundleInfo.FetchInnerModuleInfos().empty(), false); + UninstallBundleInfo(); +} + +/** + * @tc.number: OverlayDataMgr_3600 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3600, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + std::map innerModuleInfos; + InnerModuleInfo moduleInfo; + moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; + innerModuleInfos[TEST_PACK_AGE] = moduleInfo; + newInfo.AddInnerModuleInfo(innerModuleInfos); + oldInfo.AddInnerModuleInfo(innerModuleInfos); + newInfo.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); + + ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); +} + +/** + * @tc.number: OverlayDataMgr_3800 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleInfo. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3800, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo targetInnerBundleInfo; + std::map innerModuleInfos; + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.name = TEST_MODULE_NAME; + innerModuleInfo.moduleName = TEST_PACK_AGE; + innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; + innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; + innerModuleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; + innerModuleInfos[TEST_PACK_AGE] = innerModuleInfo; + innerBundleInfo.AddInnerModuleInfo(innerModuleInfos); + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + ApplicationInfo applicationInfo; + applicationInfo.bundleName = TEST_BUNDLE_NAME; + applicationInfo.targetBundleName = TEST_BUNDLE_NAME; + innerBundleInfo.SetBaseApplicationInfo(applicationInfo); + + innerBundleInfo.SetOverlayType(OverlayType::OVERLAY_INTERNAL_BUNDLE); + overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, innerBundleInfo, targetInnerBundleInfo); + overlayDataMgr.ResetInternalOverlayModuleState(innerModuleInfos, TARGET_MODULE_NAME, innerBundleInfo); + EXPECT_EQ(innerModuleInfos.at(TEST_PACK_AGE).targetModuleName, TARGET_MODULE_NAME); +} + +/** + * @tc.number: OverlayDataMgr_3900 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of SaveInternalOverlayModuleState. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3900, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + std::map innerModuleInfos; + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.name = TEST_MODULE_NAME; + innerModuleInfo.moduleName = TEST_PACK_AGE; + innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; + innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; + innerModuleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; + innerModuleInfos[TEST_PACK_AGE] = innerModuleInfo; + innerBundleInfo.AddInnerModuleInfo(innerModuleInfos); + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + ApplicationInfo applicationInfo; + applicationInfo.bundleName = TEST_BUNDLE_NAME; + applicationInfo.targetBundleName = TEST_BUNDLE_NAME; + innerBundleInfo.SetBaseApplicationInfo(applicationInfo); + + OverlayModuleInfo overlayModuleInfo; + overlayModuleInfo.targetModuleName = TARGET_MODULE_NAME; + + ErrCode res = overlayDataMgr.SaveInternalOverlayModuleState(overlayModuleInfo, innerBundleInfo); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: OverlayDataMgr_4000 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of GetOverlayModuleInfoForTarget. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4000, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo innerBundleInfo; + std::vector overlayModuleInfos; + ErrCode res = overlayDataMgr.GetOverlayModuleInfoForTarget( + innerBundleInfo, overlayModuleInfos, Constants::NOT_EXIST_USERID); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: OverlayDataMgr_4100 + * @tc.name: test bundleName is empty. + * @tc.desc: 1.OverlayDataMgr with SetOverlayEnabled. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4100, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + bool isEnabled = false; + ErrCode res = overlayDataMgr.SetOverlayEnabled("", TEST_MODULE_NAME, isEnabled, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); +} + +/** + * @tc.number: OverlayDataMgr_4200 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of BuildInternalOverlayConnection. + * 2.system run normally. + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4200, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo oldInfo; + oldInfo.SetOverlayType(OVERLAY_INTERNAL_BUNDLE); + InnerModuleInfo moduleInfo; + moduleInfo.targetModuleName = TEST_MODULE_NAME; + std::map innerModuleInfos; + moduleInfo.moduleName = TEST_MODULE_NAME; + innerModuleInfos[TEST_PACK_AGE] = moduleInfo; + moduleInfo.moduleName = TEST_PACK_AGE; + moduleInfo.targetModuleName = TEST_PACK_AGE; + innerModuleInfos[TEST_MODULE_NAME] = moduleInfo; + oldInfo.AddInnerModuleInfo(innerModuleInfos); + EXPECT_EQ(oldInfo.GetOverlayType(), OVERLAY_INTERNAL_BUNDLE); + + ClearDataMgr(); + EXPECT_EQ(bundleMgrService_->dataMgr_, nullptr); + BuildInternalOverlayConnection(TEST_MODULE_NAME, oldInfo, USERID); + ResetDataMgr(); +} + +/** + * @tc.number: OverlayDataMgr_4300 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of QueryOverlayInnerBundleInfo. + * 2.system run normally. + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4300, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + overlayDataMgr.dataMgr_ = std::make_shared(); + InnerBundleInfo info; + std::map innerModuleInfos; + info.AddInnerModuleInfo(innerModuleInfos); + overlayDataMgr.dataMgr_->bundleInfos_[NO_EXIST] = info; + bool ret = overlayDataMgr.QueryOverlayInnerBundleInfo(NO_EXIST, info); + auto iterator = overlayDataMgr.dataMgr_->bundleInfos_.find(NO_EXIST); + if (iterator != overlayDataMgr.dataMgr_->bundleInfos_.end()) { + overlayDataMgr.dataMgr_->bundleInfos_.erase(iterator); + } + EXPECT_EQ(ret, true); +} + +/** + * @tc.number: OverlayDataMgr_4400 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of QueryOverlayInnerBundleInfo. + * 2.system run normally. + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4400, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + overlayDataMgr.dataMgr_ = std::make_shared(); + InnerBundleInfo info; + info.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); + std::map innerModuleInfos; + InnerModuleInfo innerModuleInfo; + innerModuleInfos[TEST_MODULE_NAME] = innerModuleInfo; + info.AddInnerModuleInfo(innerModuleInfos); + overlayDataMgr.dataMgr_->bundleInfos_[NO_EXIST] = info; + std::vector overlayModuleInfo; + auto ret = overlayDataMgr.GetAllOverlayModuleInfo(NO_EXIST, overlayModuleInfo, + Constants::NOT_EXIST_USERID); + auto iterator = overlayDataMgr.dataMgr_->bundleInfos_.find(NO_EXIST); + if (iterator != overlayDataMgr.dataMgr_->bundleInfos_.end()) { + overlayDataMgr.dataMgr_->bundleInfos_.erase(iterator); + } + EXPECT_EQ(ret, ERR_OK); +} + +/** + * @tc.number: OverlayDataMgr_4500 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of BuildInternalOverlayConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4500, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo oldInfo; + oldInfo.overlayType_ = OVERLAY_INTERNAL_BUNDLE; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.targetModuleName = "errModuleName"; + oldInfo.innerModuleInfos_.insert(pair("1", innerModuleInfo)); + overlayDataMgr.BuildInternalOverlayConnection(TARGET_MODULE_NAME, oldInfo, USERID); + EXPECT_EQ(oldInfo.FetchInnerModuleInfos().empty(), false); +} + +/** + * @tc.number: OverlayDataMgr_4600 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of BuildInternalOverlayConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4600, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo oldInfo; + oldInfo.overlayType_ = OVERLAY_INTERNAL_BUNDLE; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; + innerModuleInfo.moduleName = TEST_MODULE_NAME; + oldInfo.innerModuleInfos_.insert(pair("1", innerModuleInfo)); + overlayDataMgr.BuildInternalOverlayConnection(TARGET_MODULE_NAME, oldInfo, USERID); + EXPECT_EQ(oldInfo.FetchInnerModuleInfos().empty(), false); +} + +/** + * @tc.number: OverlayDataMgr_4700 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of BuildInternalOverlayConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4700, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo oldInfo; + oldInfo.overlayType_ = OVERLAY_INTERNAL_BUNDLE; + oldInfo.innerModuleInfos_.clear(); + overlayDataMgr.BuildInternalOverlayConnection(TARGET_MODULE_NAME, oldInfo, USERID); + EXPECT_EQ(oldInfo.FetchInnerModuleInfos().empty(), true); +} + +/** + * @tc.number: OverlayDataMgr_4800 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of BuildInternalOverlayConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4800, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo oldInfo; + oldInfo.overlayType_ = OVERLAY_INTERNAL_BUNDLE; + oldInfo.innerModuleInfos_.clear(); + overlayDataMgr.BuildInternalOverlayConnection(TARGET_MODULE_NAME, oldInfo, USERID); + EXPECT_EQ(oldInfo.FetchInnerModuleInfos().empty(), true); +} + +/** + * @tc.number: OverlayDataMgr_4900 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of QueryOverlayInnerBundleInfo. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4900, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo innerBundleInfo; + overlayDataMgr.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); + overlayDataMgr.dataMgr_->bundleInfos_.insert(pair(TEST_BUNDLE_NAME, innerBundleInfo)); + auto res = overlayDataMgr.QueryOverlayInnerBundleInfo(NO_EXIST, innerBundleInfo); + EXPECT_FALSE(res); +} + +/** + * @tc.number: OverlayDataMgr_5000 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of QueryOverlayInnerBundleInfo. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_5000, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo innerBundleInfo; + ClearDataMgr(); + auto res = overlayDataMgr.QueryOverlayInnerBundleInfo(TEST_BUNDLE_NAME, innerBundleInfo); + EXPECT_FALSE(res); + ResetDataMgr(); +} + +/** + * @tc.number: OverlayDataMgr_5100 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of SaveInternalOverlayModuleState. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_5100, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + OverlayModuleInfo overlayModuleInfo; + overlayModuleInfo.targetModuleName = TARGET_MODULE_NAME; + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + innerBundleInfo.innerModuleInfos_.insert(pair(TARGET_MODULE_NAME, innerModuleInfo)); + overlayDataMgr.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); + overlayDataMgr.dataMgr_->AddUserId(NOT_EXIST_USERID); + auto res = overlayDataMgr.SaveInternalOverlayModuleState(overlayModuleInfo, innerBundleInfo); + EXPECT_FALSE(res); +} + +/** + * @tc.number: OverlayDataMgr_5200 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of SaveInternalOverlayModuleState. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_5200, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + OverlayModuleInfo overlayModuleInfo; + overlayModuleInfo.targetModuleName = TARGET_MODULE_NAME; + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + innerBundleInfo.innerModuleInfos_.insert(pair(TEST_MODULE_NAME, innerModuleInfo)); + overlayDataMgr.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); + overlayDataMgr.dataMgr_->AddUserId(NOT_EXIST_USERID); + auto res = overlayDataMgr.SaveInternalOverlayModuleState(overlayModuleInfo, innerBundleInfo); + EXPECT_FALSE(res); +} + +/** + * @tc.number: OverlayManagerHostImpl_0100 + * @tc.name: test overlayManagerHostImpl. + * @tc.desc: 1.overlayManagerHostImpl of GetAllOverlayModuleInfo. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayManagerHostImpl_0100, Function | SmallTest | Level0) +{ + OverlayManagerHostImpl overlayManagerHostImpl; + std::vector overlayModuleInfo; + ErrCode res = overlayManagerHostImpl.GetAllOverlayModuleInfo("", overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + + res = overlayManagerHostImpl.GetAllOverlayModuleInfo( + "bundleName", overlayModuleInfo, Constants::UNSPECIFIED_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); +} + +/** + * @tc.number: GetOverlayModuleInfo_0200 + * @tc.name: test overlayManagerHostImpl. + * @tc.desc: 1.overlayManagerHostImpl of GetOverlayModuleInfo. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_0200, Function | SmallTest | Level0) +{ + OverlayManagerHostImpl overlayManagerHostImpl; + OverlayModuleInfo overlayModuleInfo; + ErrCode res = overlayManagerHostImpl.GetOverlayModuleInfo( + "", "moduleName", overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + + res = overlayManagerHostImpl.GetOverlayModuleInfo( + "bundleName", "", overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + + res = overlayManagerHostImpl.GetOverlayModuleInfo( + "", "", overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + + res = overlayManagerHostImpl.GetOverlayModuleInfo( + "bundleName", "moduleName", overlayModuleInfo, Constants::UNSPECIFIED_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); +} + +/** + * @tc.number: GetOverlayModuleInfo_0300 + * @tc.name: test overlayManagerHostImpl. + * @tc.desc: 1.overlayManagerHostImpl of GetOverlayBundleInfoForTarget. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_0300, Function | SmallTest | Level0) +{ + OverlayManagerHostImpl overlayManagerHostImpl; + std::vector overlayBundleInfo; + ErrCode res = overlayManagerHostImpl.GetOverlayBundleInfoForTarget( + "", overlayBundleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + + res = overlayManagerHostImpl.GetOverlayBundleInfoForTarget( + "targetBundleName", overlayBundleInfo, Constants::UNSPECIFIED_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_NOT_EXISTED); +} + +/** + * @tc.number: GetOverlayModuleInfo_0400 + * @tc.name: test OverlayManagerHostImpl. + * @tc.desc: 1.OverlayManagerHostImpl of GetOverlayModuleInfoForTarget. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_0400, Function | SmallTest | Level0) +{ + OverlayManagerHostImpl overlayManagerHostImpl; + std::vector overlayModuleInfo; + ErrCode res = overlayManagerHostImpl.GetOverlayModuleInfoForTarget( + "", "targetModuleName", overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + + res = overlayManagerHostImpl.GetOverlayModuleInfoForTarget( + "targetBundleName", "", overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_NOT_EXISTED); + + res = overlayManagerHostImpl.GetOverlayModuleInfoForTarget( + "", "", overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + + res = overlayManagerHostImpl.GetOverlayModuleInfoForTarget( + "targetBundleName", "targetModuleName", overlayModuleInfo, Constants::UNSPECIFIED_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_NOT_EXISTED); +} + +/** + * @tc.number: GetOverlayModuleInfo_0500 + * @tc.name: test OverlayManagerHostImpl. + * @tc.desc: 1.OverlayManagerHostImpl of SetOverlayEnabled. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_0500, Function | SmallTest | Level0) +{ + OverlayManagerHostImpl overlayManagerHostImpl; + bool isEnabled = false; + ErrCode res = overlayManagerHostImpl.SetOverlayEnabled( + "", "moduleName", isEnabled, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_SET_OVERLAY_PARAM_ERROR); + + res = overlayManagerHostImpl.SetOverlayEnabled( + "bundleName", "", isEnabled, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_SET_OVERLAY_PARAM_ERROR); + + res = overlayManagerHostImpl.SetOverlayEnabled( + "", "", isEnabled, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_SET_OVERLAY_PARAM_ERROR); + + res = overlayManagerHostImpl.SetOverlayEnabled( + "bundleName", "moduleName", isEnabled, Constants::UNSPECIFIED_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); +} + +/** + * @tc.number: GetOverlayModuleInfo_0800 + * @tc.name: test overlayManagerHostImpl. + * @tc.desc: 1.OverlayManagerHostImpl with GetOverlayBundleInfoForTarget. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_0800, Function | SmallTest | Level0) +{ + OverlayManagerHostImpl overlayManagerHostImpl; + std::vector overlayBundleInfo; + ErrCode res = overlayManagerHostImpl.GetOverlayBundleInfoForTarget(TEST_BUNDLE_NAME, + overlayBundleInfo, Constants::INVALID_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); +} + +/** + * @tc.number: OverlayIpcTest_2000 + * @tc.name: test SetOverlayEnabled interface in OverlayManagerProxy. + * @tc.desc: 1.construct OverlayManagerProxy instance. + * 2.calling SetOverlayEnabled interface by using OverlayManagerProxy instance. + * 3.bundleName is empty and set failed + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_0900, Function | SmallTest | Level0) +{ + OverlayManagerHostImpl overlayManagerHostImpl; + + std::vector overlayModuleInfos; + auto errCode = overlayManagerHostImpl.GetTargetOverlayModuleInfo("", overlayModuleInfos, + USERID); + EXPECT_EQ(errCode, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + + errCode = overlayManagerHostImpl.GetTargetOverlayModuleInfo(TEST_BUNDLE_NAME, overlayModuleInfos, + Constants::UNSPECIFIED_USERID); + EXPECT_EQ(errCode, ERR_BUNDLE_MANAGER_INTERNAL_ERROR); +} + +/** + * @tc.number: OverlayIpcTest_2000 + * @tc.name: test SetOverlayEnabled interface in OverlayManagerProxy. + * @tc.desc: 1.construct GetOverlayModuleInfoByBundleName instance. + * 2.calling SetOverlayEnabled interface by using GetOverlayModuleInfoByBundleName instance. + * 3.bundleName is empty and set failed + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_1000, Function | SmallTest | Level0) +{ + OverlayManagerHostImpl overlayManagerHostImpl; + + std::vector overlayModuleInfos; + auto errCode = overlayManagerHostImpl.GetOverlayModuleInfoByBundleName("", TEST_MODULE_NAME, + overlayModuleInfos, USERID); + EXPECT_EQ(errCode, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + + errCode = overlayManagerHostImpl.GetOverlayModuleInfoByBundleName(TEST_BUNDLE_NAME, "", + overlayModuleInfos, Constants::UNSPECIFIED_USERID); + EXPECT_EQ(errCode, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); + + errCode = overlayManagerHostImpl.GetOverlayModuleInfoByBundleName(TEST_BUNDLE_NAME, TEST_MODULE_NAME, + overlayModuleInfos, Constants::UNSPECIFIED_USERID); + EXPECT_EQ(errCode, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); +} + +/** + * @tc.number: OverlayIpcTest_2000 + * @tc.name: test SetOverlayEnabledForSelf interface in OverlayManagerProxy. + * @tc.desc: 1.construct SetOverlayEnabledForSelf instance. + * 2.calling SetOverlayEnabled interface by using SetOverlayEnabledForSelf instance. + * 3.bundleName is empty and set failed + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_1100, Function | SmallTest | Level0) +{ + OverlayManagerHostImpl overlayManagerHostImpl; + + bool isEnabled = false; + auto errCode = overlayManagerHostImpl.SetOverlayEnabledForSelf("", + isEnabled, USERID); + EXPECT_EQ(errCode, ERR_BUNDLEMANAGER_OVERLAY_SET_OVERLAY_PARAM_ERROR); + + errCode = overlayManagerHostImpl.SetOverlayEnabledForSelf(TEST_MODULE_NAME, + isEnabled, Constants::UNSPECIFIED_USERID); + EXPECT_EQ(errCode, ERR_BUNDLE_MANAGER_INTERNAL_ERROR); +} + +/** + * @tc.number: CheckTargetBundle_0100 + * @tc.name: check bundle target priority range + * @tc.desc: Test CheckTargetBundle +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckTargetBundle_0100, Function | SmallTest | Level0) +{ + BundleOverlayInstallChecker checker; + auto code = checker.CheckTargetBundle("", "", "", USERID); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_BUNDLE_NAME); + code = checker.CheckTargetBundle(TEST_BUNDLE_NAME, "", "", USERID); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_NO_SYSTEM_APPLICATION_FOR_EXTERNAL_OVERLAY); +} + +/** + * @tc.number: UpdateInnerBundleInfo_0100 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, UpdateInnerBundleInfo_0100, Function | SmallTest | Level0) +{ + InnerBundleInfo info1; + BundleInfo bundleInfo1; + bundleInfo1.name = BUNDLE_NAME; + bundleInfo1.applicationInfo.bundleName = BUNDLE_NAME; + ApplicationInfo applicationInfo1; + applicationInfo1.name = BUNDLE_NAME; + applicationInfo1.bundleName = BUNDLE_NAME; + info1.SetBaseBundleInfo(bundleInfo1); + info1.SetBaseApplicationInfo(applicationInfo1); + + InnerBundleInfo info2; + BundleInfo bundleInfo2; + bundleInfo2.name = BUNDLE_NAME; + bundleInfo2.applicationInfo.bundleName = BUNDLE_NAME; + ApplicationInfo applicationInfo2; + applicationInfo2.name = BUNDLE_NAME; + applicationInfo2.bundleName = BUNDLE_NAME; + info2.SetBaseBundleInfo(bundleInfo2); + info2.SetBaseApplicationInfo(applicationInfo2); + info2.SetIsNewVersion(true); + info2.SetOverlayType(OverlayType::NON_OVERLAY_TYPE); + + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + dataMgr->AddUserId(USERID); + + bool ret1 = dataMgr->UpdateBundleInstallState(BUNDLE_NAME, InstallState::INSTALL_START); + bool ret2 = dataMgr->AddInnerBundleInfo(BUNDLE_NAME, info1); + bool ret3 = dataMgr->UpdateBundleInstallState(BUNDLE_NAME, InstallState::UPDATING_START); + bool ret4 = dataMgr->UpdateBundleInstallState(BUNDLE_NAME, InstallState::UPDATING_SUCCESS); + bool ret5 = dataMgr->UpdateInnerBundleInfo(BUNDLE_NAME, info2, info1); + EXPECT_TRUE(ret1); + EXPECT_TRUE(ret2); + EXPECT_TRUE(ret3); + EXPECT_TRUE(ret4); + EXPECT_TRUE(ret5); + + info2.SetOverlayType(OverlayType::OVERLAY_INTERNAL_BUNDLE); + ret5 = dataMgr->UpdateInnerBundleInfo(BUNDLE_NAME, info2, info1); + EXPECT_FALSE(ret5); + + info2.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); + ret5 = dataMgr->UpdateInnerBundleInfo(BUNDLE_NAME, info2, info1); + EXPECT_TRUE(ret5); + + ret5 = dataMgr->UpdateBundleInstallState(BUNDLE_NAME, InstallState::UNINSTALL_START); + EXPECT_TRUE(ret5); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_0100 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0100, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + + ClearDataMgr(); + bool resBool = overlayDataMgr.IsExistedNonOverlayHap(TEST_BUNDLE_NAME); + EXPECT_EQ(resBool, false); + ResetDataMgr(); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_0200 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0200, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + std::map innerModuleInfos; + InnerModuleInfo moduleInfo; + moduleInfo.moduleName = TEST_PACK_AGE; + moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; + innerModuleInfos[TEST_PACK_AGE] = moduleInfo; + newInfo.AddInnerModuleInfo(innerModuleInfos); + oldInfo.AddInnerModuleInfo(innerModuleInfos); + newInfo.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); + + ClearDataMgr(); + ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); + ResetDataMgr(); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_0300 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6S6E8 + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0300, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo oldInfo; + InnerBundleInfo targetInnerBundleInfo; + std::map innerModuleInfos; + InnerModuleInfo moduleInfo; + moduleInfo.moduleName = TEST_PACK_AGE; + moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; + innerModuleInfos[TEST_PACK_AGE] = moduleInfo; + oldInfo.AddInnerModuleInfo(innerModuleInfos); + oldInfo.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); + + ClearDataMgr(); + overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); + std::map moduleInfos = oldInfo.FetchInnerModuleInfos(); + EXPECT_EQ(moduleInfos.empty(), false); + ResetDataMgr(); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_0400 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0400, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleUserInfo userInfo; + userInfo.bundleUserInfo.overlayModulesState.clear(); + std::map statesMap; + std::map res = overlayDataMgr.GetModulesStateFromUserInfo(userInfo); + EXPECT_EQ(res, statesMap); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_0500 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0500, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + OverlayModuleInfo overlayModuleInfo; + overlayModuleInfo.bundleName = NO_EXIST; + ErrCode res = overlayDataMgr.ObtainOverlayModuleState(overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_0600 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0600, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + InnerBundleInfo targetInnerBundleInfo; + + ClearDataMgr(); + auto resCode = overlayDataMgr.UpdateExternalOverlayInfo(newInfo, oldInfo, targetInnerBundleInfo); + EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); + ResetDataMgr(); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_0700 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0700, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo oldInfo; + + ClearDataMgr(); + auto resBool = overlayDataMgr.QueryOverlayInnerBundleInfo(TEST_BUNDLE_NAME, oldInfo); + EXPECT_EQ(resBool, false); + ResetDataMgr(); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_0800 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0800, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo oldInfo; + + ClearDataMgr(); + OverlayModuleInfo overlayModuleInfo; + ErrCode resCode = overlayDataMgr.SaveInternalOverlayModuleState(overlayModuleInfo, oldInfo); + EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_SERVICE_EXCEPTION); + ResetDataMgr(); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_0900 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0900, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo oldInfo; + InnerBundleInfo targetBundleInfo; + + ClearDataMgr(); + OverlayModuleInfo overlayModuleInfo; + ErrCode resCode = overlayDataMgr.SaveExternalOverlayModuleState( + overlayModuleInfo, targetBundleInfo, USERID, oldInfo); + EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); + ResetDataMgr(); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_1000 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1000, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo oldInfo; + + ClearDataMgr(); + std::vector overlayModuleInfos; + ErrCode resCode = overlayDataMgr.GetAllOverlayModuleInfo(TEST_BUNDLE_NAME, overlayModuleInfos, USERID); + EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); + ResetDataMgr(); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_1100 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1100, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo oldInfo; + + ClearDataMgr(); + OverlayModuleInfo overlayModuleInfo; + ErrCode resCode = overlayDataMgr.GetOverlayModuleInfo( + TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, USERID); + EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); + ResetDataMgr(); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_1200 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1200, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + + ClearDataMgr(); + std::vector overlayBundleInfo; + ErrCode resCode = overlayDataMgr.GetOverlayBundleInfoForTarget( + TEST_MODULE_NAME, overlayBundleInfo, USERID); + EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); + ResetDataMgr(); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_1300 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1300, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + + ClearDataMgr(); + std::vector overlayModuleInfos; + ErrCode resCode = overlayDataMgr.GetOverlayModuleInfoForTarget( + TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfos, USERID); + EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); + ResetDataMgr(); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_1400 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1400, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + + ClearDataMgr(); + OverlayModuleInfo overlayModuleInfo; + ErrCode resCode = overlayDataMgr.ObtainOverlayModuleState(overlayModuleInfo, USERID); + EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); + ResetDataMgr(); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_1500 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1500, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + + ClearDataMgr(); + bool isEnabled = false; + ErrCode resCode = overlayDataMgr.SetOverlayEnabled(TEST_BUNDLE_NAME, TEST_MODULE_NAME, isEnabled, USERID); + EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); + ResetDataMgr(); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_1600 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1600, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + + ClearDataMgr(); + std::string resString = overlayDataMgr.GetCallingBundleName(); + EXPECT_EQ(resString.empty(), true); + ResetDataMgr(); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_1700 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1700, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo oldInfo; + oldInfo.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); + EXPECT_EQ(oldInfo.GetOverlayType(), OVERLAY_EXTERNAL_BUNDLE); + + ClearDataMgr(); + EXPECT_EQ(bundleMgrService_->dataMgr_, nullptr); + BuildInternalOverlayConnection(TEST_MODULE_NAME, oldInfo, USERID); + ResetDataMgr(); + EXPECT_NE(bundleMgrService_->dataMgr_, nullptr); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_1900 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1900, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo targetInnerBundleInfo; + + ClearDataMgr(); + EXPECT_EQ(bundleMgrService_->dataMgr_, nullptr); + RemoveOverlayBundleInfo(TEST_MODULE_NAME, targetInnerBundleInfo); + ResetDataMgr(); + EXPECT_NE(bundleMgrService_->dataMgr_, nullptr); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_2300 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_2300, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo newInfo; + InnerBundleUserInfo userInfo; + + ClearDataMgr(); + EXPECT_EQ(bundleMgrService_->dataMgr_, nullptr); + AddOverlayModuleStates(newInfo, userInfo); + ResetDataMgr(); + EXPECT_NE(bundleMgrService_->dataMgr_, nullptr); +} + +/** + * @tc.number: CheckAppLabel_0010 + * @tc.name: test CheckAppLabel + * @tc.desc: 1.Test the CheckAppLabel +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckAppLabel_0010, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + InnerBundleInfo oldInfo; + InnerBundleInfo newInfo; + oldInfo.baseApplicationInfo_->targetBundleName = TEST_MODULE_NAME; + ErrCode res = installer.CheckAppLabel(oldInfo, newInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_TARGET_BUNDLE_NAME_NOT_SAME); +} + +/** + * @tc.number: CheckAppLabel_0020 + * @tc.name: test CheckAppLabel + * @tc.desc: 1.Test the CheckAppLabel +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckAppLabel_0020, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + InnerBundleInfo oldInfo; + InnerBundleInfo newInfo; + oldInfo.baseApplicationInfo_->targetPriority = FOUR; + ErrCode res = installer.CheckAppLabel(oldInfo, newInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_TARGET_PRIORITY_NOT_SAME); +} + +/** + * @tc.number: CheckOverlayInstallation_0010 + * @tc.name: test CheckOverlayInstallation + * @tc.desc: 1.Test the CheckOverlayInstallation +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayInstallation_0010, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + std::unordered_map newInfos; + InnerBundleInfo newInfo; + newInfo.SetOverlayState(NON_OVERLAY_TYPE); + newInfos.try_emplace(TEST_MODULE_NAME, newInfo); + ErrCode res = installer.CheckOverlayInstallation(newInfos, USERID); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: CheckOverlayInstallation_0020 + * @tc.name: test CheckOverlayInstallation + * @tc.desc: 1.Test the CheckOverlayInstallation +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayInstallation_0020, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + std::unordered_map newInfos; + InnerBundleInfo info1; + info1.SetOverlayType(OVERLAY_INTERNAL_BUNDLE); + newInfos.try_emplace(TEST_MODULE_NAME, info1); + ErrCode res = installer.CheckOverlayInstallation(newInfos, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_HAP_TYPE); +} + +/** + * @tc.number: CheckOverlayInstallation_0030 + * @tc.name: test CheckOverlayInstallation + * @tc.desc: 1.Test the CheckOverlayInstallation +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayInstallation_0030, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + std::unordered_map newInfos; + InnerBundleInfo info1; + info1.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); + newInfos.try_emplace(TEST_MODULE_NAME, info1); + ErrCode res = installer.CheckOverlayInstallation(newInfos, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_HAP_TYPE); +} + +/** + * @tc.number: GetNotifyType_0010 + * @tc.name: test GetNotifyType + * @tc.desc: 1.Test the GetNotifyType +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, GetNotifyType_0010, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + installer.isAppExist_ = true; + installer.hasInstalledInUser_ = true; + installer.overlayType_ = OVERLAY_EXTERNAL_BUNDLE; + NotifyType res = installer.GetNotifyType(); + EXPECT_EQ(res, NotifyType::OVERLAY_UPDATE); +} + +/** + * @tc.number: GetNotifyType_0020 + * @tc.name: test GetNotifyType + * @tc.desc: 1.Test the GetNotifyType +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, GetNotifyType_0020, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + installer.isAppExist_ = true; + installer.hasInstalledInUser_ = true; + installer.overlayType_ = NON_OVERLAY_TYPE; + NotifyType res = installer.GetNotifyType(); + EXPECT_EQ(res, NotifyType::UPDATE); +} + +/** + * @tc.number: GetNotifyType_0030 + * @tc.name: test GetNotifyType + * @tc.desc: 1.Test the GetNotifyType +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, GetNotifyType_0030, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + installer.isAppExist_ = false; + installer.hasInstalledInUser_ = true; + installer.overlayType_ = OVERLAY_EXTERNAL_BUNDLE; + NotifyType res = installer.GetNotifyType(); + EXPECT_EQ(res, NotifyType::OVERLAY_INSTALL); +} + +/** + * @tc.number: GetNotifyType_0040 + * @tc.name: test GetNotifyType + * @tc.desc: 1.Test the GetNotifyType +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, GetNotifyType_0040, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + installer.isAppExist_ = true; + installer.hasInstalledInUser_ = false; + installer.overlayType_ = NON_OVERLAY_TYPE; + NotifyType res = installer.GetNotifyType(); + EXPECT_EQ(res, NotifyType::INSTALL); +} + +/** + * @tc.number: CheckOverlayUpdate_0010 + * @tc.name: test CheckOverlayUpdate + * @tc.desc: 1.Test the CheckOverlayUpdate +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayUpdate_0010, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + InnerBundleInfo oldInfo; + InnerBundleInfo newInfo; + newInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); + oldInfo.SetOverlayType(OverlayType::OVERLAY_INTERNAL_BUNDLE); + ErrCode res = installer.CheckOverlayUpdate(oldInfo, newInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_OVERLAY_TYPE_NOT_SAME); +} + +/** + * @tc.number: CheckOverlayUpdate_0030 + * @tc.name: test CheckOverlayUpdate + * @tc.desc: 1.Test the CheckOverlayUpdate +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayUpdate_0030, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + InnerBundleInfo oldInfo; + InnerBundleInfo newInfo; + oldInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); + newInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); + newInfo.currentPackage_ = TEST_PACK_AGE; + ErrCode res = installer.CheckOverlayUpdate(oldInfo, newInfo, USERID); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: CheckOverlayUpdate_0040 + * @tc.name: test CheckOverlayUpdate + * @tc.desc: 1.Test the CheckOverlayUpdate +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayUpdate_0040, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + InnerBundleInfo oldInfo; + InnerBundleInfo newInfo; + oldInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); + newInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); + + newInfo.currentPackage_ = TEST_PACK_AGE; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.targetModuleName = ""; + oldInfo.innerModuleInfos_[TEST_PACK_AGE] = innerModuleInfo; + ErrCode res = installer.CheckOverlayUpdate(oldInfo, newInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_OVERLAY_TYPE_NOT_SAME); +} + +/** + * @tc.number: CheckOverlayUpdate_0050 + * @tc.name: test CheckOverlayUpdate + * @tc.desc: 1.Test the CheckOverlayUpdate +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayUpdate_0050, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + InnerBundleInfo oldInfo; + InnerBundleInfo newInfo; + oldInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); + newInfo.SetOverlayType(OverlayType::NON_OVERLAY_TYPE); + + newInfo.currentPackage_ = TEST_PACK_AGE; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.targetModuleName = "targetModuleName"; + oldInfo.innerModuleInfos_[TEST_PACK_AGE] = innerModuleInfo; + ErrCode res = installer.CheckOverlayUpdate(oldInfo, newInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_OVERLAY_TYPE_NOT_SAME); +} + +/** + * @tc.number: CheckOverlayUpdate_0060 + * @tc.name: test CheckOverlayUpdate + * @tc.desc: 1.Test the CheckOverlayUpdate +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayUpdate_0060, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + InnerBundleInfo oldInfo; + InnerBundleInfo newInfo; + oldInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); + newInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); + + newInfo.currentPackage_ = TEST_PACK_AGE; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.targetModuleName = "targetModuleName"; + oldInfo.innerModuleInfos_[TEST_PACK_AGE] = innerModuleInfo; + ErrCode res = installer.CheckOverlayUpdate(oldInfo, newInfo, USERID); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: CopyHapsToSecurityDir_0010 + * @tc.name: test CopyHapsToSecurityDir + * @tc.desc: 1.Test the CopyHapsToSecurityDir +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, CopyHapsToSecurityDir_0010, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + InstallParam installParam; + installParam.withCopyHaps = true; + std::vector bundlePaths; + bundlePaths.push_back("data/test/test"); + ErrCode res = installer.CopyHapsToSecurityDir(installParam, bundlePaths); + EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_DISK_MEM_INSUFFICIENT); +} + +/** + * @tc.number: CopyHapsToSecurityDir_0020 + * @tc.name: test CopyHapsToSecurityDir + * @tc.desc: 1.Test the CopyHapsToSecurityDir +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, CopyHapsToSecurityDir_0020, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + InstallParam installParam; + installParam.withCopyHaps = true; + std::vector bundlePaths; + ErrCode res = installer.CopyHapsToSecurityDir(installParam, bundlePaths); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: FindSignatureFileDir_0010 + * @tc.name: test FindSignatureFileDir + * @tc.desc: 1.Test the FindSignatureFileDir +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, FindSignatureFileDir_0010, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + std::string signatureFileDir; + + installer.verifyCodeParams_.emplace(TEST_MODULE_NAME, TEST_MODULE_NAME); + ErrCode res = installer.FindSignatureFileDir(TEST_MODULE_NAME + "1", signatureFileDir); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_INSTALL_CODE_SIGNATURE_FAILED); +} + +/** + * @tc.number: FindSignatureFileDir_0020 + * @tc.name: test FindSignatureFileDir + * @tc.desc: 1.Test the FindSignatureFileDir +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, FindSignatureFileDir_0020, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + std::string signatureFileDir; + + installer.verifyCodeParams_.emplace(TEST_MODULE_NAME, TEST_MODULE_NAME); + ErrCode res = installer.FindSignatureFileDir(TEST_MODULE_NAME, signatureFileDir); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_INSTALL_CODE_SIGNATURE_FILE_IS_INVALID); +} + +/** + * @tc.number: FindSignatureFileDir_0030 + * @tc.name: test FindSignatureFileDir + * @tc.desc: 1.Test the FindSignatureFileDir +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, FindSignatureFileDir_0030, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + std::string signatureFileDir = "testModuleName.sig"; + + installer.verifyCodeParams_.emplace(TEST_MODULE_NAME, signatureFileDir); + ErrCode res = installer.FindSignatureFileDir(TEST_MODULE_NAME, signatureFileDir); + EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_DISK_MEM_INSUFFICIENT); +} } // OHOS \ No newline at end of file diff --git a/services/bundlemgr/test/unittest/bms_bundle_permission_grant_test/bms_bundle_permission_false_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_permission_grant_test/bms_bundle_permission_false_test.cpp index 2e0701116e..ee8732d6fb 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_permission_grant_test/bms_bundle_permission_false_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_permission_grant_test/bms_bundle_permission_false_test.cpp @@ -764,21 +764,6 @@ HWTEST_F(BmsBundlePermissionFalseTest, BmsBundlePermissionFalseTest_4800, Functi EXPECT_EQ(ret, false); } -/** - * @tc.number: BmsBundlePermissionFalseTest_4900 - * @tc.name: test QueryExtensionAbilityInfos of BundleMgrHostImpl - * @tc.desc: 1. system running normally - * 2. QueryExtensionAbilityInfos false by no permission - */ -HWTEST_F(BmsBundlePermissionFalseTest, BmsBundlePermissionFalseTest_4900, Function | SmallTest | Level0) -{ - Want want; - std::vector extensionInfos; - bool ret = bundleMgrHostImpl_->QueryExtensionAbilityInfos( - want, ExtensionAbilityType::FORM, FLAGS, USERID, extensionInfos); - EXPECT_EQ(ret, false); -} - /** * @tc.number: BmsBundlePermissionFalseTest_5000 * @tc.name: test QueryExtensionAbilityInfos of BundleMgrHostImpl @@ -1435,22 +1420,6 @@ HWTEST_F(BmsBundlePermissionFalseTest, BmsBundlePermissionFalseTest_9500, Functi EXPECT_EQ(ret, false); } -/** - * @tc.number: BmsBundlePermissionFalseTest_9600 - * @tc.name: test Uninstall of BundleInstallerHost - * @tc.desc: 1. system running normally - * 2. Uninstall false by no permission - */ -HWTEST_F(BmsBundlePermissionFalseTest, BmsBundlePermissionFalseTest_9600, Function | SmallTest | Level0) -{ - InstallParam installParam; - sptr statusReceiver = new (std::nothrow) MockStatusReceiver(); - EXPECT_NE(statusReceiver, nullptr); - bundleInstallerHost_->Init(); - bool ret = bundleInstallerHost_->Uninstall(BUNDLE_NAME, installParam, statusReceiver); - EXPECT_EQ(ret, false); -} - /** * @tc.number: BmsBundlePermissionFalseTest_9700 * @tc.name: test Uninstall of BundleInstallerHost diff --git a/services/bundlemgr/test/unittest/bms_bundle_resource_manager_test/bms_bundle_resource_manager_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_resource_manager_test/bms_bundle_resource_manager_test.cpp index d414594168..1fac5204f2 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_resource_manager_test/bms_bundle_resource_manager_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_resource_manager_test/bms_bundle_resource_manager_test.cpp @@ -416,22 +416,6 @@ HWTEST_F(BmsBundleResourceManagerTest, GetIconById_009, Function | SmallTest | L EXPECT_EQ(iconBase64, ""); } -/** - * @tc.name: GetIconById_0010 - * @tc.type: FUNC - * @tc.desc: 1.install the hap - * 2.GetIconById - * @tc.require: issueI5MZ4C - */ -HWTEST_F(BmsBundleResourceManagerTest, GetIconById_0010, Function | SmallTest | Level0) -{ - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - std::string iconBase64 = - dataMgr->GetIconById(BUNDLE_NAME, MODULE_NAME, ABILITY_ICON_ID, 0, USER_ID); - EXPECT_NE(iconBase64, ""); -} - /** * @tc.name: GetIconById_0011 * @tc.type: FUNC diff --git a/services/bundlemgr/test/unittest/bms_bundle_resource_test/bms_bundle_resource_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_resource_test/bms_bundle_resource_test.cpp index 0c693ce6c9..e309c20230 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_resource_test/bms_bundle_resource_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_resource_test/bms_bundle_resource_test.cpp @@ -1645,6 +1645,7 @@ HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0074, Function | SmallTest EXPECT_TRUE(ans); std::string colorMode = "dark"; + BundleSystemState::GetInstance().SetSystemColorMode(colorMode); ans = callback.OnSystemColorModeChanged(colorMode); EXPECT_TRUE(ans); @@ -1672,7 +1673,7 @@ HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0075, Function | SmallTest ans = callback.OnSystemLanguageChange(oldLanguage); EXPECT_TRUE(ans); - BundleSystemState::GetInstance().SetSystemLanguage(oldLanguage); + BundleSystemState::GetInstance().SetSystemColorMode(oldLanguage); } /** diff --git a/services/bundlemgr/test/unittest/bms_bundle_sandbox_app_test/bms_bundle_sandbox_app_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_sandbox_app_test/bms_bundle_sandbox_app_test.cpp index e87aa9bab7..54ef7297f9 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_sandbox_app_test/bms_bundle_sandbox_app_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_sandbox_app_test/bms_bundle_sandbox_app_test.cpp @@ -393,9 +393,16 @@ void BmsSandboxAppTest::CheckPathAreNonExisted(const std::string &bundleName, in */ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppInstallTest_0100, Function | SmallTest | Level0) { + std::vector filePaths; + auto bundleFile = RESOURCE_ROOT_PATH + RIGHT_BUNDLE_FIRST; + filePaths.emplace_back(bundleFile); + auto installRes = InstallBundles(filePaths, true); + EXPECT_EQ(installRes, ERR_OK); + int32_t appIndex = 0; auto ret = InstallSandboxApp("", DLP_TYPE_1, USERID, appIndex); EXPECT_EQ(ret, ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR); + UninstallBundle(BUNDLE_NAME); } /** @@ -416,14 +423,13 @@ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppInstallTest_0200, Function | SmallTest auto ret = InstallSandboxApp(BUNDLE_NAME, INVALID_DLP_TYPE, USERID, appIndex); EXPECT_EQ(ret, ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR); - auto uninstallRes = UninstallBundle(BUNDLE_NAME); - EXPECT_EQ(uninstallRes, ERR_OK); + UninstallBundle(BUNDLE_NAME); } /** * @tc.number: BmsSandboxAppInstallTest_0300 * @tc.name: test anormal input parameters - * @tc.desc: 1.the input dlp type is anormal + * @tc.desc: 1.the input dlp type is anormal DLP_TYPE_3 * 2.the sandbox app install failed */ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppInstallTest_0300, Function | SmallTest | Level0) @@ -472,9 +478,16 @@ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppInstallTest_0400, Function | SmallTest */ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppInstallTest_0500, Function | SmallTest | Level0) { + std::vector filePaths; + auto bundleFile = RESOURCE_ROOT_PATH + RIGHT_BUNDLE_FIRST; + filePaths.emplace_back(bundleFile); + auto installRes = InstallBundles(filePaths, true); + EXPECT_EQ(installRes, ERR_OK); + int32_t appIndex = 0; auto ret = InstallSandboxApp("", INVALID_DLP_TYPE, USERID, appIndex); EXPECT_EQ(ret, ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR); + UninstallBundle(BUNDLE_NAME); } /** @@ -485,11 +498,18 @@ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppInstallTest_0500, Function | SmallTest */ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppInstallTest_0600, Function | SmallTest | Level0) { + std::vector filePaths; + auto bundleFile = RESOURCE_ROOT_PATH + RIGHT_BUNDLE_FIRST; + filePaths.emplace_back(bundleFile); + auto installRes = InstallBundles(filePaths, true); + EXPECT_EQ(installRes, ERR_OK); + int32_t appIndex = 0; auto ret = InstallSandboxApp("", DLP_TYPE_1, INVALID_USERID, appIndex); EXPECT_EQ(ret, ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR); ret = InstallSandboxApp("", DLP_TYPE_1, Constants::DEFAULT_USERID - 1, appIndex); EXPECT_EQ(ret, ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR); + UninstallBundle(BUNDLE_NAME); } /** @@ -522,9 +542,16 @@ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppInstallTest_0700, Function | SmallTest */ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppInstallTest_0800, Function | SmallTest | Level0) { + std::vector filePaths; + auto bundleFile = RESOURCE_ROOT_PATH + RIGHT_BUNDLE_FIRST; + filePaths.emplace_back(bundleFile); + auto installRes = InstallBundles(filePaths, true); + EXPECT_EQ(installRes, ERR_OK); + int32_t appIndex = 0; auto ret = InstallSandboxApp("", INVALID_DLP_TYPE, INVALID_USERID, appIndex); EXPECT_EQ(ret, ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR); + UninstallBundle(BUNDLE_NAME); } /** @@ -587,7 +614,7 @@ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppInstallTest_1100, Function | SmallTest /** * @tc.number: BmsSandboxAppInstallTest_1200 * @tc.name: test original bundle has been installed at other userId - * @tc.desc: 1. the original bundle has been installed at current userId + * @tc.desc: 1. the original bundle has been installed at current userId DLP_TYPE_1 * 2.the sandbox app install successfully */ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppInstallTest_1200, Function | SmallTest | Level1) @@ -611,7 +638,7 @@ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppInstallTest_1200, Function | SmallTest /** * @tc.number: BmsSandboxAppInstallTest_1300 * @tc.name: test original bundle has been installed at other userId - * @tc.desc: 1. the original bundle has been installed at current userId + * @tc.desc: 1. the original bundle has been installed at current userId DLP_TYPE_2 * 2.the sandbox app install successfully */ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppInstallTest_1300, Function | SmallTest | Level1) @@ -915,8 +942,21 @@ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppInstallTest_2100, Function | SmallTest */ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppUnInstallTest_0100, Function | SmallTest | Level0) { - auto ret = UninstallSandboxApp("", APP_INDEX_1, USERID); - EXPECT_EQ(ret, ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR); + std::vector filePaths; + auto bundleFile = RESOURCE_ROOT_PATH + RIGHT_BUNDLE_FIRST; + filePaths.emplace_back(bundleFile); + auto installRes = InstallBundles(filePaths, true); + EXPECT_EQ(installRes, ERR_OK); + + int32_t appIndex = 0; + auto ret = InstallSandboxApp(BUNDLE_NAME, DLP_TYPE_1, USERID, appIndex); + EXPECT_EQ(ret, ERR_OK); + EXPECT_EQ(appIndex, APP_INDEX_1); + CheckPathAreExisted(BUNDLE_NAME, APP_INDEX_1); + + auto res = UninstallSandboxApp("", APP_INDEX_1, USERID); + EXPECT_EQ(res, ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR); + UninstallBundle(BUNDLE_NAME); } /** @@ -983,8 +1023,21 @@ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppUnInstallTest_0300, Function | SmallTes */ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppUnInstallTest_0400, Function | SmallTest | Level1) { + std::vector filePaths; + auto bundleFile = RESOURCE_ROOT_PATH + RIGHT_BUNDLE_FIRST; + filePaths.emplace_back(bundleFile); + auto installRes = InstallBundles(filePaths, true); + EXPECT_EQ(installRes, ERR_OK); + + int32_t appIndex = 0; + auto ret = InstallSandboxApp(BUNDLE_NAME, DLP_TYPE_1, USERID, appIndex); + EXPECT_EQ(ret, ERR_OK); + EXPECT_EQ(appIndex, APP_INDEX_1); + CheckPathAreExisted(BUNDLE_NAME, APP_INDEX_1); + auto res = UninstallSandboxApp("", INVALID_APP_INDEX, USERID); EXPECT_EQ(res, ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR); + UninstallBundle(BUNDLE_NAME); } /** @@ -995,8 +1048,21 @@ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppUnInstallTest_0400, Function | SmallTes */ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppUnInstallTest_0500, Function | SmallTest | Level1) { + std::vector filePaths; + auto bundleFile = RESOURCE_ROOT_PATH + RIGHT_BUNDLE_FIRST; + filePaths.emplace_back(bundleFile); + auto installRes = InstallBundles(filePaths, true); + EXPECT_EQ(installRes, ERR_OK); + + int32_t appIndex = 0; + auto ret = InstallSandboxApp(BUNDLE_NAME, DLP_TYPE_1, USERID, appIndex); + EXPECT_EQ(ret, ERR_OK); + EXPECT_EQ(appIndex, APP_INDEX_1); + CheckPathAreExisted(BUNDLE_NAME, APP_INDEX_1); + auto res = UninstallSandboxApp("", APP_INDEX_1, INVALID_USERID); EXPECT_EQ(res, ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR); + UninstallBundle(BUNDLE_NAME); } /** @@ -1034,8 +1100,21 @@ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppUnInstallTest_0600, Function | SmallTes */ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppUnInstallTest_0700, Function | SmallTest | Level1) { + std::vector filePaths; + auto bundleFile = RESOURCE_ROOT_PATH + RIGHT_BUNDLE_FIRST; + filePaths.emplace_back(bundleFile); + auto installRes = InstallBundles(filePaths, true); + EXPECT_EQ(installRes, ERR_OK); + + int32_t appIndex = 0; + auto ret = InstallSandboxApp(BUNDLE_NAME, DLP_TYPE_1, USERID, appIndex); + EXPECT_EQ(ret, ERR_OK); + EXPECT_EQ(appIndex, APP_INDEX_1); + CheckPathAreExisted(BUNDLE_NAME, APP_INDEX_1); + auto res = UninstallSandboxApp("", INVALID_APP_INDEX, INVALID_USERID); EXPECT_EQ(res, ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR); + UninstallBundle(BUNDLE_NAME); } /** @@ -1046,8 +1125,21 @@ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppUnInstallTest_0700, Function | SmallTes */ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppUnInstallTest_0800, Function | SmallTest | Level1) { + std::vector filePaths; + auto bundleFile = RESOURCE_ROOT_PATH + RIGHT_BUNDLE_FIRST; + filePaths.emplace_back(bundleFile); + auto installRes = InstallBundles(filePaths, true); + EXPECT_EQ(installRes, ERR_OK); + + int32_t appIndex = 0; + auto ret = InstallSandboxApp(BUNDLE_NAME, DLP_TYPE_1, USERID, appIndex); + EXPECT_EQ(ret, ERR_OK); + EXPECT_EQ(appIndex, APP_INDEX_1); + CheckPathAreExisted(BUNDLE_NAME, APP_INDEX_1); + auto res = UninstallSandboxApp(UNINSTALLED_BUNDLE_NAME, APP_INDEX_1, USERID); EXPECT_EQ(res, ERR_APPEXECFWK_SANDBOX_INSTALL_NO_SANDBOX_APP_INFO); + UninstallBundle(BUNDLE_NAME); } /** @@ -1130,7 +1222,7 @@ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppUnInstallTest_1100, Function | SmallTes /** * @tc.number: BmsSandboxAppUnInstallTest_1200 - * @tc.name: test uninstall sandbox multiple times + * @tc.name: test uninstall sandbox multiple times -BUNDLE_NAME * @tc.desc: 1. uninstall sandbox multiple times * 2. the sandbox app will be uninstalled failed */ @@ -1171,7 +1263,7 @@ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppUnInstallTest_1200, Function | SmallTes /** * @tc.number: BmsSandboxAppUnInstallTest_1300 - * @tc.name: test uninstall sandbox multiple times + * @tc.name: test uninstall sandbox multiple times -OTHER_BUNDLE_NAME * @tc.desc: 1. uninstall sandbox multiple times * 2. the sandbox app will be uninstalled failed */ @@ -1212,7 +1304,7 @@ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppUnInstallTest_1300, Function | SmallTes /** * @tc.number: BmsSandboxAppUnInstallTest_1400 - * @tc.name: test uninstall sandbox multiple times + * @tc.name: test uninstall sandbox multiple times BUNDLE_NAME and OTHER_BUNDLE_NAME * @tc.desc: 1. uninstall sandbox multiple times * 2. the sandbox app will be uninstalled failed */ @@ -1256,7 +1348,7 @@ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppUnInstallTest_1400, Function | SmallTes /** * @tc.number: BmsSandboxAppUnInstallTest_1500 - * @tc.name: test uninstall sandbox multiple times + * @tc.name: test uninstall sandbox multiple times BUNDLE_NAME and OTHER_BUNDLE_NAME * @tc.desc: 1. uninstall sandbox multiple times * 2. the sandbox app will be uninstalled failed */ @@ -1298,35 +1390,10 @@ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppUnInstallTest_1500, Function | SmallTes UninstallBundle(OTHER_BUNDLE_NAME); } -/** - * @tc.number: BmsSandboxAppUnInstallTest_1600 - * @tc.name: InstallSandboxApp - * @tc.desc: 1.Test the interface of InstallSandboxApp - */ -HWTEST_F(BmsSandboxAppTest, BmsSandboxAppUnInstallTest_1600, Function | SmallTest | Level1) -{ - std::vector filePaths; - auto bundleFile = RESOURCE_ROOT_PATH + RIGHT_BUNDLE_FIRST; - filePaths.emplace_back(bundleFile); - auto installRes = InstallBundles(filePaths, true); - EXPECT_EQ(installRes, ERR_OK); - - auto installer = std::make_shared(); - int32_t appIndex = 0; - auto ret = installer->InstallSandboxApp("", DLP_TYPE_1, USERID, appIndex); - EXPECT_EQ(ret, ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR); - int32_t userId = Constants::DEFAULT_USERID - 1; - ret = installer->InstallSandboxApp(BUNDLE_NAME, DLP_TYPE_1, userId, appIndex); - EXPECT_EQ(ret, ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR); - - auto uninstallRes = UninstallBundle(BUNDLE_NAME); - EXPECT_EQ(uninstallRes, ERR_OK); -} - /** * @tc.number: BmsSandboxAppUnInstallTest_1700 - * @tc.name: InstallSandboxApp - * @tc.desc: 1.Test the interface of InstallSandboxApp + * @tc.name: GetSandboxDataMgr + * @tc.desc: 1.Test the interface of GetSandboxDataMgr */ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppUnInstallTest_1700, Function | SmallTest | Level1) { @@ -1362,8 +1429,8 @@ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppUnInstallTest_1700, Function | SmallTes /** * @tc.number: BmsSandboxAppUnInstallTest_1800 - * @tc.name: InstallSandboxApp - * @tc.desc: 1.Test the interface of InstallSandboxApp + * @tc.name: UninstallAllSandboxApps + * @tc.desc: 1. The main function for sandbox app uninstalling. */ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppUnInstallTest_1800, Function | SmallTest | Level1) { @@ -1743,7 +1810,7 @@ HWTEST_F(BmsSandboxAppTest, BmsGETSandboxAppMSG_1300, Function | SmallTest | Lev /** * @tc.number: GetSandboxHapModuleInfo_0100 - * @tc.name: get sandbox app bundleInfo information + * @tc.name: Install Sandbox App * @tc.desc: 1. install a hap successfully * 2. the sandbox app install successfully * 3. get sandbox app bundleInfo information failed by empty bundlename @@ -1774,7 +1841,7 @@ HWTEST_F(BmsSandboxAppTest, GetSandboxHapModuleInfo_0100, Function | SmallTest | /** * @tc.number: GetSandboxHapModuleInfo_0100 - * @tc.name: get sandbox app bundleInfo information + * @tc.name: Get Sandbox Hap Module Info * @tc.desc: 1. install a hap successfully * 2. the sandbox app install successfully * 3. get sandbox app bundleInfo information failed by empty bundlename @@ -1794,9 +1861,7 @@ HWTEST_F(BmsSandboxAppTest, GetSandboxHapModuleInfo_0200, Function | SmallTest | /** * @tc.number: GetSandboxHapModuleInfo_0100 * @tc.name: get sandbox app bundleInfo information - * @tc.desc: 1. install a hap successfully - * 2. the sandbox app install successfully - * 3. get sandbox app bundleInfo information failed by empty bundlename + * @tc.desc: By different appIndex,Get SandboxHap ModuleInfo */ HWTEST_F(BmsSandboxAppTest, GetSandboxHapModuleInfo_0300, Function | SmallTest | Level1) { @@ -1810,7 +1875,7 @@ HWTEST_F(BmsSandboxAppTest, GetSandboxHapModuleInfo_0300, Function | SmallTest | /** * @tc.number: GetSandboxHapModuleInfo_0400 - * @tc.name: get sandbox app bundleInfo information + * @tc.name: Get Bundle Sandbox App Helper * @tc.desc: 1. install a hap successfully * 2. the sandbox app install successfully * 3. get sandbox app bundleInfo information failed by empty bundlename @@ -1843,7 +1908,7 @@ HWTEST_F(BmsSandboxAppTest, GetSandboxHapModuleInfo_0400, Function | SmallTest | /** * @tc.number: GetSandboxHapModuleInfo_0500 - * @tc.name: get sandbox app bundleInfo information + * @tc.name: Get Bundle Sandbox App Helper * @tc.desc: 1. install a hap successfully * 2. the sandbox app install successfully * 3. get sandbox app bundleInfo information failed by empty bundlename @@ -1904,9 +1969,7 @@ HWTEST_F(BmsSandboxAppTest, GetInnerBundleInfoByUid_0100, Function | SmallTest | /** * @tc.number: GetInnerBundleInfoByUid_0200 * @tc.name: get sandbox app bundleInfo information - * @tc.desc: 1. install a hap successfully - * 2. the sandbox app install successfully - * 3. get sandbox app bundleInfo information failed by empty bundlename + * @tc.desc: Obtain internal package information by Uid */ HWTEST_F(BmsSandboxAppTest, GetInnerBundleInfoByUid_0200, Function | SmallTest | Level1) { @@ -2083,7 +2146,7 @@ HWTEST_F(BmsSandboxAppTest, GetSandboxAppInfo_0100, Function | SmallTest | Level } /** - * @tc.number: DeleteSandboxAppIndex_001 + * @tc.number: GetSandboxAppInfo_0200 * @tc.name: ConvertResourcePath * @tc.desc: 1.Test the interface of ConvertResourcePath */ @@ -2177,8 +2240,8 @@ HWTEST_F(BmsSandboxAppTest, GetBundleArchiveInfoBySandBoxPath_0200, Function | S /** * @tc.number: GetBundleInfoForSelf_0100 * @tc.name: get sandbox app bundleInfo information - * @tc.desc: 1. save sandbox info successfully - * 2. get sandbox app bundleInfo information failed + * @tc.desc: 1. Obtain internal package information by Uid + * 2. Obtains the BundleInfo based on a given bundle name. * @tc.require: issueI5Y75O */ HWTEST_F(BmsSandboxAppTest, GetBundleInfoForSelf_0100, Function | SmallTest | Level1) diff --git a/services/bundlemgr/test/unittest/bms_bundle_uninstaller_test/bms_bundle_uninstaller_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_uninstaller_test/bms_bundle_uninstaller_test.cpp index 34cb5c28f9..fe0dabe9fe 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_uninstaller_test/bms_bundle_uninstaller_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_uninstaller_test/bms_bundle_uninstaller_test.cpp @@ -325,8 +325,17 @@ ErrCode BmsBundleUninstallerTest::InstallMultipleBundles(const std::vector filePaths; + filePaths.emplace_back(RESOURCE_TEST_PATH); + ErrCode installRes = InstallMultipleBundles(filePaths, true); + EXPECT_EQ(installRes, ERR_OK); + CheckFileExist(); + ErrCode result = UninstallBundle("", USERID); EXPECT_EQ(result, ERR_APPEXECFWK_UNINSTALL_INVALID_NAME); + ErrCode result1 = UninstallBundle(BUNDLE_NAME, INVALID_USERID); + EXPECT_NE(result1, ERR_OK); + ClearBundleInfo(BUNDLE_NAME); } /** @@ -337,8 +346,18 @@ HWTEST_F(BmsBundleUninstallerTest, Bundle_Uninstall_0100, Function | SmallTest | */ HWTEST_F(BmsBundleUninstallerTest, Bundle_Uninstall_0200, Function | SmallTest | Level0) { + std::vector filePaths; + filePaths.emplace_back(RESOURCE_TEST_PATH); + ErrCode installRes = InstallMultipleBundles(filePaths, true); + EXPECT_EQ(installRes, ERR_OK); + CheckFileExist(); + ErrCode result = UninstallBundle(ERROR_BUNDLE_NAME, USERID); EXPECT_EQ(result, ERR_APPEXECFWK_UNINSTALL_MISSING_INSTALLED_BUNDLE); + + ErrCode result1 = UninstallBundle(BUNDLE_NAME, INVALID_USERID); + EXPECT_NE(result1, ERR_OK); + ClearBundleInfo(BUNDLE_NAME); } /** @@ -387,8 +406,17 @@ HWTEST_F(BmsBundleUninstallerTest, Bundle_Uninstall_0400, Function | SmallTest | */ HWTEST_F(BmsBundleUninstallerTest, Module_Uninstall_0100, Function | SmallTest | Level0) { + std::vector filePaths; + filePaths.emplace_back(RESOURCE_TEST_PATH); + ErrCode installRes = InstallMultipleBundles(filePaths, true); + EXPECT_EQ(installRes, ERR_OK); + CheckFileExist(); ErrCode result = UninstallModule("", MODULE_PACKAGE1, USERID); EXPECT_EQ(result, ERR_APPEXECFWK_UNINSTALL_INVALID_NAME); + + installRes = UninstallModule(BUNDLE_NAME, MODULE_PACKAGE1, USERID); + EXPECT_EQ(installRes, ERR_OK); + ClearBundleInfo(BUNDLE_NAME); } /** @@ -399,8 +427,17 @@ HWTEST_F(BmsBundleUninstallerTest, Module_Uninstall_0100, Function | SmallTest | */ HWTEST_F(BmsBundleUninstallerTest, Module_Uninstall_0200, Function | SmallTest | Level0) { + std::vector filePaths; + filePaths.emplace_back(RESOURCE_TEST_PATH); + ErrCode installRes = InstallMultipleBundles(filePaths, true); + EXPECT_EQ(installRes, ERR_OK); + CheckFileExist(); ErrCode result = UninstallModule(ERROR_BUNDLE_NAME, MODULE_PACKAGE1, USERID); EXPECT_EQ(result, ERR_APPEXECFWK_UNINSTALL_MISSING_INSTALLED_BUNDLE); + + installRes = UninstallModule(BUNDLE_NAME, MODULE_PACKAGE1, USERID); + EXPECT_EQ(installRes, ERR_OK); + ClearBundleInfo(BUNDLE_NAME); } /** @@ -411,8 +448,17 @@ HWTEST_F(BmsBundleUninstallerTest, Module_Uninstall_0200, Function | SmallTest | */ HWTEST_F(BmsBundleUninstallerTest, Module_Uninstall_0300, Function | SmallTest | Level0) { + std::vector filePaths; + filePaths.emplace_back(RESOURCE_TEST_PATH); + ErrCode installRes = InstallMultipleBundles(filePaths, true); + EXPECT_EQ(installRes, ERR_OK); + CheckFileExist(); ErrCode result = UninstallModule(BUNDLE_NAME, "", USERID); EXPECT_EQ(result, ERR_APPEXECFWK_UNINSTALL_INVALID_NAME); + + installRes = UninstallModule(BUNDLE_NAME, MODULE_PACKAGE1, USERID); + EXPECT_EQ(installRes, ERR_OK); + ClearBundleInfo(BUNDLE_NAME); } /** @@ -423,8 +469,17 @@ HWTEST_F(BmsBundleUninstallerTest, Module_Uninstall_0300, Function | SmallTest | */ HWTEST_F(BmsBundleUninstallerTest, Module_Uninstall_0400, Function | SmallTest | Level0) { + std::vector filePaths; + filePaths.emplace_back(RESOURCE_TEST_PATH); + ErrCode installRes = InstallMultipleBundles(filePaths, true); + EXPECT_EQ(installRes, ERR_OK); + CheckFileExist(); ErrCode result = UninstallModule(BUNDLE_NAME, ERROR_MODULE_PACKAGE_NAME, USERID); - EXPECT_EQ(result, ERR_APPEXECFWK_UNINSTALL_MISSING_INSTALLED_BUNDLE); + EXPECT_EQ(result, ERR_APPEXECFWK_UNINSTALL_MISSING_INSTALLED_MODULE); + + installRes = UninstallModule(BUNDLE_NAME, MODULE_PACKAGE1, USERID); + EXPECT_EQ(installRes, ERR_OK); + ClearBundleInfo(BUNDLE_NAME); } /** @@ -435,8 +490,17 @@ HWTEST_F(BmsBundleUninstallerTest, Module_Uninstall_0400, Function | SmallTest | */ HWTEST_F(BmsBundleUninstallerTest, Module_Uninstall_0500, Function | SmallTest | Level0) { + std::vector filePaths; + filePaths.emplace_back(RESOURCE_TEST_PATH); + ErrCode installRes = InstallMultipleBundles(filePaths, true); + EXPECT_EQ(installRes, ERR_OK); + CheckFileExist(); ErrCode result = UninstallModule(BUNDLE_NAME, MODULE_PACKAGE1, INVALID_USERID); EXPECT_NE(result, ERR_OK); + + installRes = UninstallModule(BUNDLE_NAME, MODULE_PACKAGE1, USERID); + EXPECT_EQ(installRes, ERR_OK); + ClearBundleInfo(BUNDLE_NAME); } /** -- Gitee From 66d13ca50f8623aa73b52100e3ace7bc86afe9b1 Mon Sep 17 00:00:00 2001 From: xinking129 Date: Tue, 16 Jan 2024 15:50:58 +0800 Subject: [PATCH 2/6] tdd Year rectification Signed-off-by: xinking129 --- .../bms_bundle_data_mgr_test.cpp | 12 ++++++------ .../bms_bundle_mgr_service_death_recipient_test.cpp | 2 +- .../bms_bundle_get_overlay_module_info_test.cpp | 2 +- .../bms_bundle_manager_overlay_ipc_test.cpp | 2 +- .../bms_bundle_overlay_checker_test.cpp | 2 +- .../bms_bundle_permission_false_test.cpp | 2 +- .../bms_bundle_resource_manager_test.cpp | 2 +- .../bms_bundle_resource_test.cpp | 5 ++++- .../bms_bundle_sandbox_app_test.cpp | 8 +++----- .../bms_bundle_uninstaller_test.cpp | 2 +- 10 files changed, 20 insertions(+), 19 deletions(-) diff --git a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test.cpp index 6a2f4168e3..6d32e936c2 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -1698,6 +1698,7 @@ HWTEST_F(BmsBundleDataMgrTest, GenerateUidAndGid_0100, Function | SmallTest | Le GetBundleDataMgr()->bundleInfos_.emplace(BUNDLE_NAME_TEST, innerBundleInfo); bool res = GetBundleDataMgr()->GenerateUidAndGid(innerBundleUserInfo); EXPECT_EQ(res, false); + GetBundleDataMgr()->bundleInfos_.clear(); } /** @@ -1710,11 +1711,11 @@ HWTEST_F(BmsBundleDataMgrTest, GetAllFormsInfo_0100, Function | SmallTest | Leve { std::vector formInfos; InnerBundleInfo innerBundleInfo; - GetBundleDataMgr()->bundleInfos_.clear(); innerBundleInfo.SetBundleStatus(InnerBundleInfo::BundleStatus::DISABLED); GetBundleDataMgr()->bundleInfos_.emplace(BUNDLE_NAME_TEST, innerBundleInfo); bool res = GetBundleDataMgr()->GetAllFormsInfo(formInfos); EXPECT_EQ(res, false); + GetBundleDataMgr()->bundleInfos_.clear(); } /** @@ -1727,11 +1728,11 @@ HWTEST_F(BmsBundleDataMgrTest, GetAllFormsInfo_0200, Function | SmallTest | Leve { std::vector formInfos; InnerBundleInfo innerBundleInfo; - GetBundleDataMgr()->bundleInfos_.clear(); innerBundleInfo.SetBundleStatus(InnerBundleInfo::BundleStatus::ENABLED); GetBundleDataMgr()->bundleInfos_.emplace(BUNDLE_NAME_TEST, innerBundleInfo); bool res = GetBundleDataMgr()->GetAllFormsInfo(formInfos); EXPECT_EQ(res, true); + GetBundleDataMgr()->bundleInfos_.clear(); } /** @@ -1748,6 +1749,7 @@ HWTEST_F(BmsBundleDataMgrTest, GetFormsInfoByModule_0100, Function | SmallTest | GetBundleDataMgr()->bundleInfos_.emplace(BUNDLE_NAME_TEST, innerBundleInfo); bool res = GetBundleDataMgr()->GetFormsInfoByModule(BUNDLE_NAME_TEST, BUNDLE_NAME_TEST, formInfos); EXPECT_EQ(res, false); + GetBundleDataMgr()->bundleInfos_.clear(); } /** @@ -1760,7 +1762,6 @@ HWTEST_F(BmsBundleDataMgrTest, GetFormsInfoByApp_0100, Function | SmallTest | Le { std::vector formInfos; InnerBundleInfo innerBundleInfo; - GetBundleDataMgr()->bundleInfos_.clear(); innerBundleInfo.SetBundleStatus(InnerBundleInfo::BundleStatus::DISABLED); GetBundleDataMgr()->bundleInfos_.emplace(BUNDLE_NAME_TEST, innerBundleInfo); bool res = GetBundleDataMgr()->GetFormsInfoByApp(BUNDLE_NAME_TEST, formInfos); @@ -1963,6 +1964,7 @@ HWTEST_F(BmsBundleDataMgrTest, ImplicitQueryCurExtensionInfos_0300, Function | S bool testRet = GetBundleDataMgr()->ImplicitQueryCurExtensionInfos( want, GET_ABILITY_INFO_DEFAULT, USERID, infos, appIndex); EXPECT_EQ(testRet, false); + GetBundleDataMgr()->bundleInfos_.clear(); } /** @@ -1973,8 +1975,6 @@ HWTEST_F(BmsBundleDataMgrTest, ImplicitQueryCurExtensionInfos_0300, Function | S */ HWTEST_F(BmsBundleDataMgrTest, ImplicitQueryCurExtensionInfos_0400, Function | SmallTest | Level1) { - GetBundleDataMgr()->bundleInfos_.clear(); - Want want; std::vector infos; int32_t appIndex = 0; diff --git a/services/bundlemgr/test/unittest/bms_bundle_mgr_service_death_recipient_test/bms_bundle_mgr_service_death_recipient_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_mgr_service_death_recipient_test/bms_bundle_mgr_service_death_recipient_test.cpp index 94468d0751..865c0b39f7 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_mgr_service_death_recipient_test/bms_bundle_mgr_service_death_recipient_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_mgr_service_death_recipient_test/bms_bundle_mgr_service_death_recipient_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_get_overlay_module_info_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_get_overlay_module_info_test.cpp index 0bf28f3e68..2d13df2a99 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_get_overlay_module_info_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_get_overlay_module_info_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_manager_overlay_ipc_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_manager_overlay_ipc_test.cpp index 0f3a537e8c..cd611ebdf5 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_manager_overlay_ipc_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_manager_overlay_ipc_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_overlay_checker_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_overlay_checker_test.cpp index 243c041d76..eff3493206 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_overlay_checker_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_overlay_checker_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/bundlemgr/test/unittest/bms_bundle_permission_grant_test/bms_bundle_permission_false_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_permission_grant_test/bms_bundle_permission_false_test.cpp index ee8732d6fb..f4825902f4 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_permission_grant_test/bms_bundle_permission_false_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_permission_grant_test/bms_bundle_permission_false_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/bundlemgr/test/unittest/bms_bundle_resource_manager_test/bms_bundle_resource_manager_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_resource_manager_test/bms_bundle_resource_manager_test.cpp index 1fac5204f2..6df4b38ce8 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_resource_manager_test/bms_bundle_resource_manager_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_resource_manager_test/bms_bundle_resource_manager_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/bundlemgr/test/unittest/bms_bundle_resource_test/bms_bundle_resource_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_resource_test/bms_bundle_resource_test.cpp index e309c20230..f577f6f498 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_resource_test/bms_bundle_resource_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_resource_test/bms_bundle_resource_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -1645,6 +1645,9 @@ HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0074, Function | SmallTest EXPECT_TRUE(ans); std::string colorMode = "dark"; + ans = callback.OnSystemColorModeChanged(colorMode); + EXPECT_TRUE(ans); + BundleSystemState::GetInstance().SetSystemColorMode(colorMode); ans = callback.OnSystemColorModeChanged(colorMode); EXPECT_TRUE(ans); diff --git a/services/bundlemgr/test/unittest/bms_bundle_sandbox_app_test/bms_bundle_sandbox_app_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_sandbox_app_test/bms_bundle_sandbox_app_test.cpp index 54ef7297f9..60c8870d52 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_sandbox_app_test/bms_bundle_sandbox_app_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_sandbox_app_test/bms_bundle_sandbox_app_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -408,7 +408,7 @@ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppInstallTest_0100, Function | SmallTest /** * @tc.number: BmsSandboxAppInstallTest_0200 * @tc.name: test anormal input parameters - * @tc.desc: 1.the input dlp type is anormal + * @tc.desc: 1.the input dlp type is anormal INVALID_DLP_TYPE * 2.the sandbox app install failed */ HWTEST_F(BmsSandboxAppTest, BmsSandboxAppInstallTest_0200, Function | SmallTest | Level0) @@ -1842,9 +1842,7 @@ HWTEST_F(BmsSandboxAppTest, GetSandboxHapModuleInfo_0100, Function | SmallTest | /** * @tc.number: GetSandboxHapModuleInfo_0100 * @tc.name: Get Sandbox Hap Module Info - * @tc.desc: 1. install a hap successfully - * 2. the sandbox app install successfully - * 3. get sandbox app bundleInfo information failed by empty bundlename + * @tc.desc: By different appIndex,Get SandboxHap ModuleInfo */ HWTEST_F(BmsSandboxAppTest, GetSandboxHapModuleInfo_0200, Function | SmallTest | Level1) { diff --git a/services/bundlemgr/test/unittest/bms_bundle_uninstaller_test/bms_bundle_uninstaller_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_uninstaller_test/bms_bundle_uninstaller_test.cpp index fe0dabe9fe..8187578795 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_uninstaller_test/bms_bundle_uninstaller_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_uninstaller_test/bms_bundle_uninstaller_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at -- Gitee From 52cf1cecfac414800047a1d32c466d8c95649546 Mon Sep 17 00:00:00 2001 From: xinking129 Date: Tue, 16 Jan 2024 15:58:35 +0800 Subject: [PATCH 3/6] Format modification Signed-off-by: xinking129 --- ...undle_mgr_service_death_recipient_test.cpp | 114 +- .../bms_bundle_manager_overlay_ipc_test.cpp | 374 +- .../bms_bundle_overlay_checker_test.cpp | 5670 ++++++++--------- 3 files changed, 3079 insertions(+), 3079 deletions(-) diff --git a/services/bundlemgr/test/unittest/bms_bundle_mgr_service_death_recipient_test/bms_bundle_mgr_service_death_recipient_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_mgr_service_death_recipient_test/bms_bundle_mgr_service_death_recipient_test.cpp index 865c0b39f7..bef26d4406 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_mgr_service_death_recipient_test/bms_bundle_mgr_service_death_recipient_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_mgr_service_death_recipient_test/bms_bundle_mgr_service_death_recipient_test.cpp @@ -1,58 +1,58 @@ -/* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "appexecfwk_errors.h" -#define private public -#include "bundle_mgr_service_death_recipient.h" -#undef private - -using namespace testing::ext; -using testing::_; -namespace OHOS { -namespace AppExecFwk { - -class BmsBundleMgrServiceDeathRecipientTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); -}; - -void BmsBundleMgrServiceDeathRecipientTest::SetUpTestCase() {} - -void BmsBundleMgrServiceDeathRecipientTest::TearDownTestCase() {} - -void BmsBundleMgrServiceDeathRecipientTest::SetUp() {} - -void BmsBundleMgrServiceDeathRecipientTest::TearDown() {} - -/** - * @tc.number: BundleMgrServiceDeathRecipient_001 - * @tc.name: OnRemoteDied - * @tc.desc: When deathCallback_ is not empty, Successful case of verifying OnRemoteDied. - */ -HWTEST_F(BmsBundleMgrServiceDeathRecipientTest, BundleMgrServiceDeathRecipient_001, TestSize.Level1) -{ - const std::function& object)> deathCallback; - const wptr object; - BundleMgrServiceDeathRecipient bundleMgrServiceDeathRecipient(deathCallback); - bundleMgrServiceDeathRecipient.OnRemoteDied(object); - EXPECT_EQ(bundleMgrServiceDeathRecipient.deathCallback_, nullptr); -} -} // namespace AppExecFwk +/* + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "appexecfwk_errors.h" +#define private public +#include "bundle_mgr_service_death_recipient.h" +#undef private + +using namespace testing::ext; +using testing::_; +namespace OHOS { +namespace AppExecFwk { + +class BmsBundleMgrServiceDeathRecipientTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void BmsBundleMgrServiceDeathRecipientTest::SetUpTestCase() {} + +void BmsBundleMgrServiceDeathRecipientTest::TearDownTestCase() {} + +void BmsBundleMgrServiceDeathRecipientTest::SetUp() {} + +void BmsBundleMgrServiceDeathRecipientTest::TearDown() {} + +/** + * @tc.number: BundleMgrServiceDeathRecipient_001 + * @tc.name: OnRemoteDied + * @tc.desc: When deathCallback_ is not empty, Successful case of verifying OnRemoteDied. + */ +HWTEST_F(BmsBundleMgrServiceDeathRecipientTest, BundleMgrServiceDeathRecipient_001, TestSize.Level1) +{ + const std::function& object)> deathCallback; + const wptr object; + BundleMgrServiceDeathRecipient bundleMgrServiceDeathRecipient(deathCallback); + bundleMgrServiceDeathRecipient.OnRemoteDied(object); + EXPECT_EQ(bundleMgrServiceDeathRecipient.deathCallback_, nullptr); +} +} // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_manager_overlay_ipc_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_manager_overlay_ipc_test.cpp index cd611ebdf5..4fcab38233 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_manager_overlay_ipc_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_manager_overlay_ipc_test.cpp @@ -1,188 +1,188 @@ -/* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "appexecfwk_errors.h" -#include "bundle_framework_core_ipc_interface_code.h" -#include "bundle_mgr_host_impl.h" -#include "bundle_mgr_proxy.h" -#include "bundle_mgr_service.h" - -using namespace testing::ext; -using namespace OHOS::AppExecFwk; - -namespace OHOS { -namespace { -const std::u16string TEST_HOST_DESCRIPTOR = u"ohos.bundleManager.test"; -const int32_t WAIT_TIME = 5; // init mocked bms -} // namespace -class BundleMgrHostImplMock : public BundleMgrHostImpl { -public: - BundleMgrHostImplMock() = default; - virtual ~BundleMgrHostImplMock() = default; - - virtual sptr GetOverlayManagerProxy() override; -}; - -sptr BundleMgrHostImplMock::GetOverlayManagerProxy() -{ - return nullptr; -} - -class BmsBundleManagerIpcTest : public testing::Test { -public: - BmsBundleManagerIpcTest(); - ~BmsBundleManagerIpcTest(); - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); -private: - static std::shared_ptr bundleMgrService_; -}; - -std::shared_ptr BmsBundleManagerIpcTest::bundleMgrService_ = - DelayedSingleton::GetInstance(); - -BmsBundleManagerIpcTest::BmsBundleManagerIpcTest() -{} - -BmsBundleManagerIpcTest::~BmsBundleManagerIpcTest() -{} - -void BmsBundleManagerIpcTest::SetUpTestCase() -{} - -void BmsBundleManagerIpcTest::TearDownTestCase() -{ - bundleMgrService_->OnStop(); -} - -void BmsBundleManagerIpcTest::SetUp() -{ - if (!bundleMgrService_->IsServiceReady()) { - bundleMgrService_->OnStart(); - std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME)); - } -} - -void BmsBundleManagerIpcTest::TearDown() -{} - -/** - * @tc.number: BundleManagerOverlayIpcTest_0100 - * @tc.name: test GetOverlayManagerProxy interface in BundleMgrProxy. - * @tc.desc: 1.construct BundleMgrProxy instance. - * 2.calling GetOverlayManagerProxy interface by using BundleMgrProxy instance. - * 3.remote object is nullptr. - * 4.return nullptr. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleManagerIpcTest, BundleManagerIpcTest_0100, Function | SmallTest | Level0) -{ - sptr bundleManagerProxy = new (std::nothrow) BundleMgrProxy(nullptr); - EXPECT_NE(bundleManagerProxy, nullptr); - - auto overlayProxy = bundleManagerProxy->GetOverlayManagerProxy(); - EXPECT_EQ(overlayProxy, nullptr); -} - -/** - * @tc.number: BundleManagerOverlayIpcTest_0200 - * @tc.name: test GetOverlayManagerProxy interface in BundleMgrProxy. - * @tc.desc: 1.construct BundleMgrProxy instance. - * 2.calling GetOverlayManagerProxy interface by using BundleMgrProxy instance. - * 3.return overlay proxy. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleManagerIpcTest, BundleManagerOverlayIpcTest_0200, Function | SmallTest | Level0) -{ - sptr bundleManagerHostImpl = new (std::nothrow) BundleMgrHostImpl(); - EXPECT_NE(bundleManagerHostImpl, nullptr); - sptr bundleManagerProxy = new (std::nothrow) BundleMgrProxy(bundleManagerHostImpl->AsObject()); - EXPECT_NE(bundleManagerProxy, nullptr); - - auto overlayProxy = bundleManagerProxy->GetOverlayManagerProxy(); - EXPECT_NE(overlayProxy, nullptr); -} - -/** - * @tc.number: BundleManagerOverlayIpcTest_0400 - * @tc.name: test HandleGetOverlayManagerProxy interface in BundleMgrHost. - * @tc.desc: 1.construct BundleMgrHost instance. - * 2.calling HandleGetOverlayManagerProxy interface by using BundleMgrHost instance. - * 3.return failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleManagerIpcTest, BundleManagerOverlayIpcTest_0400, Function | SmallTest | Level0) -{ - sptr bundleManagerHostImplMock = new (std::nothrow) BundleMgrHostImplMock(); - EXPECT_NE(bundleManagerHostImplMock, nullptr); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - data.WriteInterfaceToken(BundleMgrHost::GetDescriptor()); - auto errCode = bundleManagerHostImplMock->OnRemoteRequest( - static_cast(BundleMgrInterfaceCode::GET_OVERLAY_MANAGER_PROXY), data, reply, option); - EXPECT_EQ(errCode, UNKNOWN_ERROR); -} - -/** - * @tc.number: BundleManagerOverlayIpcTest_0500 - * @tc.name: test HandleGetOverlayManagerProxy interface in BundleMgrHost. - * @tc.desc: 1.construct BundleMgrHost instance. - * 2.calling HandleGetOverlayManagerProxy interface by using BundleMgrHost instance. - * 3.error interface descriptor - * 3.return failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleManagerIpcTest, BundleManagerOverlayIpcTest_0500, Function | SmallTest | Level0) -{ - sptr bundleManagerHostImplMock = new (std::nothrow) BundleMgrHostImplMock(); - EXPECT_NE(bundleManagerHostImplMock, nullptr); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - data.WriteInterfaceToken(TEST_HOST_DESCRIPTOR); - auto errCode = bundleManagerHostImplMock->OnRemoteRequest( - static_cast(BundleMgrInterfaceCode::GET_OVERLAY_MANAGER_PROXY), data, reply, option); - EXPECT_EQ(errCode, OBJECT_NULL); -} - -/** - * @tc.number: BundleManagerOverlayIpcTest_0600 - * @tc.name: test HandleGetOverlayManagerProxy interface in BundleMgrHost. - * @tc.desc: 1.construct BundleMgrHost instance. - * 2.calling HandleGetOverlayManagerProxy interface by using BundleMgrHost instance. - * 3.return ERR_OK. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleManagerIpcTest, BundleManagerOverlayIpcTest_0600, Function | SmallTest | Level0) -{ - sptr bundleManagerHostImpl = new (std::nothrow) BundleMgrHostImpl(); - EXPECT_NE(bundleManagerHostImpl, nullptr); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - data.WriteInterfaceToken(BundleMgrHost::GetDescriptor()); - auto errCode = bundleManagerHostImpl->OnRemoteRequest( - static_cast(BundleMgrInterfaceCode::GET_OVERLAY_MANAGER_PROXY), data, reply, option); - EXPECT_EQ(errCode, ERR_OK); -} +/* + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "appexecfwk_errors.h" +#include "bundle_framework_core_ipc_interface_code.h" +#include "bundle_mgr_host_impl.h" +#include "bundle_mgr_proxy.h" +#include "bundle_mgr_service.h" + +using namespace testing::ext; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace { +const std::u16string TEST_HOST_DESCRIPTOR = u"ohos.bundleManager.test"; +const int32_t WAIT_TIME = 5; // init mocked bms +} // namespace +class BundleMgrHostImplMock : public BundleMgrHostImpl { +public: + BundleMgrHostImplMock() = default; + virtual ~BundleMgrHostImplMock() = default; + + virtual sptr GetOverlayManagerProxy() override; +}; + +sptr BundleMgrHostImplMock::GetOverlayManagerProxy() +{ + return nullptr; +} + +class BmsBundleManagerIpcTest : public testing::Test { +public: + BmsBundleManagerIpcTest(); + ~BmsBundleManagerIpcTest(); + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +private: + static std::shared_ptr bundleMgrService_; +}; + +std::shared_ptr BmsBundleManagerIpcTest::bundleMgrService_ = + DelayedSingleton::GetInstance(); + +BmsBundleManagerIpcTest::BmsBundleManagerIpcTest() +{} + +BmsBundleManagerIpcTest::~BmsBundleManagerIpcTest() +{} + +void BmsBundleManagerIpcTest::SetUpTestCase() +{} + +void BmsBundleManagerIpcTest::TearDownTestCase() +{ + bundleMgrService_->OnStop(); +} + +void BmsBundleManagerIpcTest::SetUp() +{ + if (!bundleMgrService_->IsServiceReady()) { + bundleMgrService_->OnStart(); + std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME)); + } +} + +void BmsBundleManagerIpcTest::TearDown() +{} + +/** + * @tc.number: BundleManagerOverlayIpcTest_0100 + * @tc.name: test GetOverlayManagerProxy interface in BundleMgrProxy. + * @tc.desc: 1.construct BundleMgrProxy instance. + * 2.calling GetOverlayManagerProxy interface by using BundleMgrProxy instance. + * 3.remote object is nullptr. + * 4.return nullptr. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleManagerIpcTest, BundleManagerIpcTest_0100, Function | SmallTest | Level0) +{ + sptr bundleManagerProxy = new (std::nothrow) BundleMgrProxy(nullptr); + EXPECT_NE(bundleManagerProxy, nullptr); + + auto overlayProxy = bundleManagerProxy->GetOverlayManagerProxy(); + EXPECT_EQ(overlayProxy, nullptr); +} + +/** + * @tc.number: BundleManagerOverlayIpcTest_0200 + * @tc.name: test GetOverlayManagerProxy interface in BundleMgrProxy. + * @tc.desc: 1.construct BundleMgrProxy instance. + * 2.calling GetOverlayManagerProxy interface by using BundleMgrProxy instance. + * 3.return overlay proxy. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleManagerIpcTest, BundleManagerOverlayIpcTest_0200, Function | SmallTest | Level0) +{ + sptr bundleManagerHostImpl = new (std::nothrow) BundleMgrHostImpl(); + EXPECT_NE(bundleManagerHostImpl, nullptr); + sptr bundleManagerProxy = new (std::nothrow) BundleMgrProxy(bundleManagerHostImpl->AsObject()); + EXPECT_NE(bundleManagerProxy, nullptr); + + auto overlayProxy = bundleManagerProxy->GetOverlayManagerProxy(); + EXPECT_NE(overlayProxy, nullptr); +} + +/** + * @tc.number: BundleManagerOverlayIpcTest_0400 + * @tc.name: test HandleGetOverlayManagerProxy interface in BundleMgrHost. + * @tc.desc: 1.construct BundleMgrHost instance. + * 2.calling HandleGetOverlayManagerProxy interface by using BundleMgrHost instance. + * 3.return failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleManagerIpcTest, BundleManagerOverlayIpcTest_0400, Function | SmallTest | Level0) +{ + sptr bundleManagerHostImplMock = new (std::nothrow) BundleMgrHostImplMock(); + EXPECT_NE(bundleManagerHostImplMock, nullptr); + + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteInterfaceToken(BundleMgrHost::GetDescriptor()); + auto errCode = bundleManagerHostImplMock->OnRemoteRequest( + static_cast(BundleMgrInterfaceCode::GET_OVERLAY_MANAGER_PROXY), data, reply, option); + EXPECT_EQ(errCode, UNKNOWN_ERROR); +} + +/** + * @tc.number: BundleManagerOverlayIpcTest_0500 + * @tc.name: test HandleGetOverlayManagerProxy interface in BundleMgrHost. + * @tc.desc: 1.construct BundleMgrHost instance. + * 2.calling HandleGetOverlayManagerProxy interface by using BundleMgrHost instance. + * 3.error interface descriptor + * 3.return failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleManagerIpcTest, BundleManagerOverlayIpcTest_0500, Function | SmallTest | Level0) +{ + sptr bundleManagerHostImplMock = new (std::nothrow) BundleMgrHostImplMock(); + EXPECT_NE(bundleManagerHostImplMock, nullptr); + + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteInterfaceToken(TEST_HOST_DESCRIPTOR); + auto errCode = bundleManagerHostImplMock->OnRemoteRequest( + static_cast(BundleMgrInterfaceCode::GET_OVERLAY_MANAGER_PROXY), data, reply, option); + EXPECT_EQ(errCode, OBJECT_NULL); +} + +/** + * @tc.number: BundleManagerOverlayIpcTest_0600 + * @tc.name: test HandleGetOverlayManagerProxy interface in BundleMgrHost. + * @tc.desc: 1.construct BundleMgrHost instance. + * 2.calling HandleGetOverlayManagerProxy interface by using BundleMgrHost instance. + * 3.return ERR_OK. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleManagerIpcTest, BundleManagerOverlayIpcTest_0600, Function | SmallTest | Level0) +{ + sptr bundleManagerHostImpl = new (std::nothrow) BundleMgrHostImpl(); + EXPECT_NE(bundleManagerHostImpl, nullptr); + + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteInterfaceToken(BundleMgrHost::GetDescriptor()); + auto errCode = bundleManagerHostImpl->OnRemoteRequest( + static_cast(BundleMgrInterfaceCode::GET_OVERLAY_MANAGER_PROXY), data, reply, option); + EXPECT_EQ(errCode, ERR_OK); +} } // OHOS \ No newline at end of file diff --git a/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_overlay_checker_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_overlay_checker_test.cpp index eff3493206..f610b2acfc 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_overlay_checker_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_overlay_checker_test.cpp @@ -1,2836 +1,2836 @@ -/* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#define private public - -#include - -#include "appexecfwk_errors.h" -#include "bundle_overlay_data_manager.h" -#include "bundle_overlay_install_checker.h" -#include "bundle_overlay_manager.h" -#include "bundle_mgr_service.h" - -#include - -using namespace testing::ext; -using namespace OHOS::AppExecFwk; -using OHOS::DelayedSingleton; - -namespace OHOS { -namespace { -const std::string TEST_MODULE_NAME = "testModuleName"; -const std::string TEST_MODULE_NAME_SECOND = "testModuleNameSecond"; -const std::string TARGET_MODULE_NAME = "targetModuleName"; -const std::string OTHER_TARGET_MODULE_NAME = "targetModuleNameTest"; -const std::string TARGET_BUNDLE_NAME = "targetBundleName"; -const std::string TEST_BUNDLE_NAME = "testBundleName"; -const std::string TEST_BUNDLE_NAME2 = "testBundleName2"; -const std::string TEST_PATH_FIRST = "testPath1"; -const std::string TEST_PATH_SECOND = "testPath2"; -const std::string TEST_PACK_AGE = "modulePackage"; -const std::string NO_EXIST = "noExist"; -const std::string BUNDLE_NAME = "oho.test.bundleName"; -const std::string SHARED_HAP_TYPE = "shared"; -const std::string FEATURE_HAP_TYPE = "feature"; -const std::string SHARED_TYPE = "shared"; -const int32_t INVALID_TARGET_PRIORITY_FIRST = 0; -const int32_t INVALID_TARGET_PRIORITY_SECOND = 101; -const int32_t DEFAULT_TARGET_PRIORITY_SECOND = 1; -const int32_t TEST_VERSION_CODE = 1000000; -const int32_t LOWER_TEST_VERSION_CODE = 999999; -const int32_t HIGHER_TEST_VERSION_CODE = 1000001; -const int32_t USERID = 100; -const int32_t NOT_EXIST_USERID = -5; -const int32_t FOUR = 4; -const int32_t DEFAULT_OVERLAY_BUNDLE_INFO = 0; -const int32_t WAIT_TIME = 5; // init mocked bms -} // namespace - -class BmsBundleOverlayCheckerTest : public testing::Test { -public: - BmsBundleOverlayCheckerTest(); - ~BmsBundleOverlayCheckerTest(); - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); - void AddInnerBundleInfo(); - void UninstallBundleInfo(); - void BuildInternalOverlayConnection(const std::string &moduleName, InnerBundleInfo &oldInfo, int32_t userId); - void RemoveOverlayBundleInfo(const std::string &targetBundleName, InnerBundleInfo &targetInnerBundleInfo); - void AddOverlayModuleStates(const InnerBundleInfo &innerBundleInfo, InnerBundleUserInfo &userInfo); - void ClearDataMgr(); - void ResetDataMgr(); - - const std::shared_ptr GetBundleDataMgr() const; - const std::shared_ptr GetBundleOverlayChecker() const; - -private: - std::shared_ptr overlayChecker_ = std::make_shared(); - static std::shared_ptr bundleMgrService_; -}; - -std::shared_ptr BmsBundleOverlayCheckerTest::bundleMgrService_ = - DelayedSingleton::GetInstance(); - -BmsBundleOverlayCheckerTest::BmsBundleOverlayCheckerTest() -{} - -BmsBundleOverlayCheckerTest::~BmsBundleOverlayCheckerTest() -{} - -void BmsBundleOverlayCheckerTest::SetUpTestCase() -{} - -void BmsBundleOverlayCheckerTest::TearDownTestCase() -{ - bundleMgrService_->OnStop(); -} - -void BmsBundleOverlayCheckerTest::SetUp() -{ - if (!bundleMgrService_->IsServiceReady()) { - bundleMgrService_->OnStart(); - std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME)); - } -} - -void BmsBundleOverlayCheckerTest::BuildInternalOverlayConnection( - const std::string &moduleName, InnerBundleInfo &oldInfo, int32_t userId) -{ - OverlayDataMgr overlayDataMgr; - return overlayDataMgr.BuildInternalOverlayConnection(TEST_MODULE_NAME, oldInfo, USERID); -} - -void BmsBundleOverlayCheckerTest::RemoveOverlayBundleInfo( - const std::string &targetBundleName, InnerBundleInfo &targetInnerBundleInfo) -{ - OverlayDataMgr overlayDataMgr; - return overlayDataMgr.RemoveOverlayBundleInfo(TEST_MODULE_NAME, targetInnerBundleInfo); -} - -void BmsBundleOverlayCheckerTest::AddOverlayModuleStates( - const InnerBundleInfo &innerBundleInfo, InnerBundleUserInfo &userInfo) -{ - OverlayDataMgr overlayDataMgr; - return overlayDataMgr.AddOverlayModuleStates(innerBundleInfo, userInfo); -} - -void BmsBundleOverlayCheckerTest::ClearDataMgr() -{ - bundleMgrService_->dataMgr_ = nullptr; -} - -void BmsBundleOverlayCheckerTest::ResetDataMgr() -{ - bundleMgrService_->dataMgr_ = std::make_shared(); - EXPECT_NE(bundleMgrService_->dataMgr_, nullptr); -} - -void BmsBundleOverlayCheckerTest::TearDown() -{} - -void BmsBundleOverlayCheckerTest::AddInnerBundleInfo() -{ - // construct innerBundleInfo - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.name = TEST_MODULE_NAME; - innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; - innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - ApplicationInfo applicationInfo; - applicationInfo.bundleName = TEST_BUNDLE_NAME; - applicationInfo.targetBundleName = TEST_BUNDLE_NAME; - innerBundleInfo.SetBaseApplicationInfo(applicationInfo); - - // construct target module - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - InnerBundleInfo oldInfo; - InnerModuleInfo targetModuleInfo; - targetModuleInfo.name = TARGET_MODULE_NAME; - targetModuleInfo.targetModuleName = OTHER_TARGET_MODULE_NAME; - targetModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; - ApplicationInfo targetApplicationInfo; - targetApplicationInfo.bundleName = TEST_BUNDLE_NAME; - - oldInfo.InsertInnerModuleInfo(TARGET_MODULE_NAME, targetModuleInfo); - oldInfo.SetBaseApplicationInfo(targetApplicationInfo); - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); - dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, oldInfo); -} - -void BmsBundleOverlayCheckerTest::UninstallBundleInfo() -{ - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - bool startRet = dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_START); - bool finishRet = dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_SUCCESS); - - EXPECT_TRUE(startRet); - EXPECT_TRUE(finishRet); -} - -const std::shared_ptr BmsBundleOverlayCheckerTest::GetBundleDataMgr() const -{ - return bundleMgrService_->GetDataMgr(); -} - -const std::shared_ptr BmsBundleOverlayCheckerTest::GetBundleOverlayChecker() const -{ - return overlayChecker_; -} - -/** - * @tc.number: OverlayCheckerTest_0100 - * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. - * @tc.desc: 1.the internal overlay hap is entry type. - * 2.check failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0100, Function | SmallTest | Level0) -{ - // construct innerBundleInfo - InnerModuleInfo innerModuleInfo; - Distro distro; - distro.moduleType = FEATURE_HAP_TYPE; - innerModuleInfo.distro = distro; - innerModuleInfo.name = TEST_MODULE_NAME; - InnerBundleInfo innerBundleInfo; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - std::unordered_map newInfos; - - auto overlayChecker = GetBundleOverlayChecker(); - EXPECT_NE(overlayChecker, nullptr); - auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_HAP_TYPE); -} - -/** - * @tc.number: OverlayCheckerTest_0200 - * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. - * @tc.desc: 1.the internal overlay bundle is service. - * 2.check failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0200, Function | SmallTest | Level0) -{ - // construct innerBundleInfo - InnerModuleInfo innerModuleInfo; - innerModuleInfo.name = TEST_MODULE_NAME; - Distro distro; - distro.moduleType = SHARED_HAP_TYPE; - innerModuleInfo.distro = distro; - InnerBundleInfo innerBundleInfo; - innerBundleInfo.SetEntryInstallationFree(true); - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - std::unordered_map newInfos; - - auto overlayChecker = GetBundleOverlayChecker(); - EXPECT_NE(overlayChecker, nullptr); - auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_BUNDLE_TYPE); -} - -/** - * @tc.number: OverlayCheckerTest_0400 - * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. - * @tc.desc: 1.target priority of internal overlay hap is invalid. - * 2.check failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0400, Function | SmallTest | Level0) -{ - // construct innerBundleInfo - InnerModuleInfo innerModuleInfo; - innerModuleInfo.name = TEST_MODULE_NAME; - Distro distro; - distro.moduleType = SHARED_HAP_TYPE; - innerModuleInfo.distro = distro; - innerModuleInfo.targetPriority = INVALID_TARGET_PRIORITY_FIRST; - InnerBundleInfo innerBundleInfo; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - std::unordered_map newInfos; - - auto overlayChecker = GetBundleOverlayChecker(); - EXPECT_NE(overlayChecker, nullptr); - auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_PRIORITY); -} - -/** - * @tc.number: OverlayCheckerTest_0500 - * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. - * @tc.desc: 1.target priority of internal overlay hap is invalid. - * 2.check failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0500, Function | SmallTest | Level0) -{ - // construct innerBundleInfo - InnerModuleInfo innerModuleInfo; - innerModuleInfo.name = TEST_MODULE_NAME; - Distro distro; - distro.moduleType = SHARED_HAP_TYPE; - innerModuleInfo.distro = distro; - innerModuleInfo.targetPriority = INVALID_TARGET_PRIORITY_SECOND; - InnerBundleInfo innerBundleInfo; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - std::unordered_map newInfos; - auto overlayChecker = GetBundleOverlayChecker(); - EXPECT_NE(overlayChecker, nullptr); - auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_PRIORITY); -} - -/** - * @tc.number: OverlayCheckerTest_0600 - * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. - * @tc.desc: 1.target module name of the internal overlay is same as the module name. - * 2.check failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0600, Function | SmallTest | Level0) -{ - // construct innerBundleInfo - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.name = TEST_MODULE_NAME; - innerModuleInfo.targetModuleName = TEST_MODULE_NAME; - innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; - Distro distro; - distro.moduleType = SHARED_HAP_TYPE; - innerModuleInfo.distro = distro; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - std::unordered_map newInfos; - - auto overlayChecker = GetBundleOverlayChecker(); - EXPECT_NE(overlayChecker, nullptr); - auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_MODULE_NAME); -} - -/** - * @tc.number: OverlayCheckerTest_0700 - * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. - * @tc.desc: 1.target module is overlay module. - * 2.check failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0700, Function | SmallTest | Level0) -{ - // construct innerBundleInfo - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.name = TEST_MODULE_NAME; - innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; - innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; - Distro distro; - distro.moduleType = SHARED_HAP_TYPE; - innerModuleInfo.distro = distro; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - ApplicationInfo applicationInfo; - applicationInfo.bundleName = TEST_BUNDLE_NAME; - innerBundleInfo.SetBaseApplicationInfo(applicationInfo); - - // construct target module - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - InnerBundleInfo oldInfo; - InnerModuleInfo targetModuleInfo; - targetModuleInfo.name = TARGET_MODULE_NAME; - targetModuleInfo.targetModuleName = OTHER_TARGET_MODULE_NAME; - targetModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; - Distro targetDistro; - targetDistro.moduleType = SHARED_HAP_TYPE; - innerModuleInfo.distro = targetDistro; - ApplicationInfo targetApplicationInfo; - targetApplicationInfo.bundleName = TEST_BUNDLE_NAME; - - oldInfo.InsertInnerModuleInfo(TARGET_MODULE_NAME, targetModuleInfo); - oldInfo.SetBaseApplicationInfo(targetApplicationInfo); - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); - dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, oldInfo); - std::unordered_map newInfos; - - auto overlayChecker = GetBundleOverlayChecker(); - EXPECT_NE(overlayChecker, nullptr); - auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_TARGET_MODULE_IS_OVERLAY_MODULE); - - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_START); - bool ret = dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_SUCCESS); - EXPECT_TRUE(ret); -} - -/** - * @tc.number: OverlayCheckerTest_0800 - * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. - * @tc.desc: 1.install overlay hap and non-overlay hap simultaneously. - * 2.check successfully. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0800, Function | SmallTest | Level0) -{ - // construct overlay innerBundleInfo - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.name = TEST_MODULE_NAME; - innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; - innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; - Distro distro; - distro.moduleType = SHARED_HAP_TYPE; - innerModuleInfo.distro = distro; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - - // construct non-overlay innerBundleInfo - InnerBundleInfo nonOverlayBundleInfo; - InnerModuleInfo nonInnerModuleInfo; - nonInnerModuleInfo.name = TEST_MODULE_NAME_SECOND; - nonOverlayBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME_SECOND); - nonOverlayBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME_SECOND, nonInnerModuleInfo); - - std::unordered_map newInfos; - newInfos.emplace(TEST_PATH_FIRST, innerBundleInfo); - newInfos.emplace(TEST_PATH_SECOND, nonOverlayBundleInfo); - - auto overlayChecker = GetBundleOverlayChecker(); - EXPECT_NE(overlayChecker, nullptr); - auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: OverlayCheckerTest_0900 - * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. - * @tc.desc: 1.install internal overlay hap. - * 2.the version code of overlay hap is larger than non-overlay module. - * 3.check failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0900, Function | SmallTest | Level0) -{ - // construct overlay innerBundleInfo - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.name = TEST_MODULE_NAME; - innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; - innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; - Distro distro; - distro.moduleType = SHARED_HAP_TYPE; - innerModuleInfo.distro = distro; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - BundleInfo bundleInfo; - bundleInfo.versionCode = HIGHER_TEST_VERSION_CODE; - innerBundleInfo.SetBaseBundleInfo(bundleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - ApplicationInfo applicationInfo; - applicationInfo.bundleName = TEST_BUNDLE_NAME; - innerBundleInfo.SetBaseApplicationInfo(applicationInfo); - std::unordered_map newInfos; - - // construct old innerBundleInfo - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - InnerBundleInfo oldInfo; - InnerModuleInfo oldInnerModuleInfo; - oldInnerModuleInfo.name = TEST_MODULE_NAME_SECOND; - oldInfo.InsertInnerModuleInfo(TEST_MODULE_NAME_SECOND, oldInnerModuleInfo); - BundleInfo oldBundleInfo; - oldBundleInfo.versionCode = TEST_VERSION_CODE; - oldInfo.SetBaseBundleInfo(oldBundleInfo); - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); - dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, oldInfo); - - auto overlayChecker = GetBundleOverlayChecker(); - EXPECT_NE(overlayChecker, nullptr); - auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INCONSISTENT_VERSION_CODE); - - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_START); - bool ret = dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_SUCCESS); - EXPECT_TRUE(ret); -} - -/** - * @tc.number: BundleOverlayManagerTest_0100 - * @tc.name: check param is empty - * @tc.desc: 1.Test BundleOverlayManager - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, BundleOverlayManagerTest_0100, Function | SmallTest | Level0) -{ - BundleOverlayManager manager; - std::string bundleName = ""; - bool ret = manager.IsExistedNonOverlayHap(bundleName); - EXPECT_EQ(ret, false); - InnerBundleInfo innerBundleInfo; - ret = manager.GetInnerBundleInfo(bundleName, innerBundleInfo); - EXPECT_EQ(ret, false); - - int32_t userId = Constants::INVALID_USERID; - std::vector overlayModuleInfos; - auto code = manager.GetAllOverlayModuleInfo(bundleName, overlayModuleInfos, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - code = manager.GetAllOverlayModuleInfo("com.ohos.test", overlayModuleInfos, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - - std::string moduleName = ""; - OverlayModuleInfo overlayModuleInfo; - code = manager.GetOverlayModuleInfo(bundleName, moduleName, overlayModuleInfo, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - code = manager.GetOverlayModuleInfo("com.ohos.test", moduleName, overlayModuleInfo, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - code = manager.GetOverlayModuleInfo("com.ohos.test", "entry", overlayModuleInfo, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - - std::string targetBundleName = ""; - std::vector overlayBundleInfo; - code = manager.GetOverlayBundleInfoForTarget(targetBundleName, overlayBundleInfo, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - code = manager.GetOverlayBundleInfoForTarget("target", overlayBundleInfo, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - - code = manager.GetOverlayModuleInfoForTarget(targetBundleName, "", overlayModuleInfos, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - code = manager.GetOverlayModuleInfoForTarget("target", "", overlayModuleInfos, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - - userId = Constants::DEFAULT_USERID; - code = manager.GetAllOverlayModuleInfo("com.ohos.test", overlayModuleInfos, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); - code = manager.GetOverlayModuleInfo("com.ohos.test", "entry", overlayModuleInfo, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); -} - -/** - * @tc.number: CheckInternalBundle_0100 - * @tc.name: check hap type failed - * @tc.desc: 1.Test CheckInternalBundle - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckInternalBundle_0100, Function | SmallTest | Level0) -{ - BundleOverlayInstallChecker checker; - std::unordered_map newInfos; - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.isEntry = true; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - auto code = checker.CheckInternalBundle(newInfos, innerBundleInfo); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_HAP_TYPE); - innerModuleInfo.isEntry = false; - code = checker.CheckInternalBundle(newInfos, innerBundleInfo); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_HAP_TYPE); - - innerBundleInfo.SetEntryInstallationFree(true); - code = checker.CheckInternalBundle(newInfos, innerBundleInfo); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_HAP_TYPE); -} - -/** - * @tc.number: CheckInternalBundle_0200 - * @tc.name: check module target priority range - * @tc.desc: 1.Test CheckInternalBundle - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckInternalBundle_0200, Function | SmallTest | Level0) -{ - BundleOverlayInstallChecker checker; - std::unordered_map newInfos; - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - Distro distro; - distro.moduleType = SHARED_HAP_TYPE; - innerModuleInfo.distro = distro; - innerModuleInfo.targetPriority = Constants::OVERLAY_MINIMUM_PRIORITY - 1; - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - auto code = checker.CheckInternalBundle(newInfos, innerBundleInfo); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_PRIORITY); -} - -/** - * @tc.number: CheckInternalBundle_0300 - * @tc.name: check module target priority range - * @tc.desc: 1.Test CheckInternalBundle - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckInternalBundle_0300, Function | SmallTest | Level0) -{ - BundleOverlayInstallChecker checker; - std::unordered_map newInfos; - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - Distro distro; - distro.moduleType = SHARED_HAP_TYPE; - innerModuleInfo.distro = distro; - innerModuleInfo.targetPriority = Constants::OVERLAY_MINIMUM_PRIORITY + 1; - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - innerModuleInfo.targetModuleName = TEST_MODULE_NAME; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - - auto code = checker.CheckInternalBundle(newInfos, innerBundleInfo); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_MODULE_NAME); -} - -/** - * @tc.number: CheckExternalBundle_0100 - * @tc.name: check bundle priority - * @tc.desc: 1.Test CheckExternalBundle - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckExternalBundle_0100, Function | SmallTest | Level0) -{ - BundleOverlayInstallChecker checker; - InnerBundleInfo innerBundleInfo; - int32_t userId = Constants::INVALID_USERID; - BundleInfo bundleInfo; - bundleInfo.entryInstallationFree = true; - innerBundleInfo.SetBaseBundleInfo(bundleInfo); - auto code = checker.CheckExternalBundle(innerBundleInfo, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_BUNDLE_TYPE); - - bundleInfo.entryInstallationFree = false; - innerBundleInfo.SetBaseBundleInfo(bundleInfo); - ApplicationInfo applicationInfo; - applicationInfo.targetPriority = Constants::OVERLAY_MINIMUM_PRIORITY - 1; - innerBundleInfo.SetBaseApplicationInfo(applicationInfo); - InnerModuleInfo innerModuleInfo; - Distro distro; - distro.moduleType = SHARED_HAP_TYPE; - innerModuleInfo.distro = distro; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - code = checker.CheckExternalBundle(innerBundleInfo, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_PRIORITY); - - applicationInfo.targetPriority = Constants::OVERLAY_MAXIMUM_PRIORITY + 1; - innerBundleInfo.SetBaseApplicationInfo(applicationInfo); - code = checker.CheckExternalBundle(innerBundleInfo, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_PRIORITY); -} - -/** - * @tc.number: CheckExternalBundle_0200 - * @tc.name: check bundle priority - * @tc.desc: 1.Test CheckExternalBundle - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckExternalBundle_0200, Function | SmallTest | Level0) -{ - BundleOverlayInstallChecker checker; - InnerBundleInfo innerBundleInfo; - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - int32_t userId = Constants::INVALID_USERID; - ApplicationInfo applicationInfo; - applicationInfo.bundleName = TEST_BUNDLE_NAME; - applicationInfo.targetBundleName = TEST_BUNDLE_NAME; - applicationInfo.targetPriority = Constants::OVERLAY_MINIMUM_PRIORITY + 1; - innerBundleInfo.SetBaseApplicationInfo(applicationInfo); - InnerModuleInfo innerModuleInfo; - innerModuleInfo.targetPriority = Constants::OVERLAY_MINIMUM_PRIORITY + 1; - Distro distro; - distro.moduleType = SHARED_HAP_TYPE; - innerModuleInfo.distro = distro; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - auto code = checker.CheckExternalBundle(innerBundleInfo, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_BUNDLE_NAME_SAME_WITH_TARGET_BUNDLE_NAME); - applicationInfo.bundleName = ""; - innerBundleInfo.SetBaseApplicationInfo(applicationInfo); - code = checker.CheckExternalBundle(innerBundleInfo, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_NO_SYSTEM_APPLICATION_FOR_EXTERNAL_OVERLAY); - - innerBundleInfo.SetIsPreInstallApp(true); - code = checker.CheckExternalBundle(innerBundleInfo, userId); - EXPECT_EQ(code, ERR_OK); - - innerBundleInfo.SetCurrentModulePackage(SHARED_TYPE); - code = checker.CheckExternalBundle(innerBundleInfo, userId); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_HAP_TYPE); -} - -/** - * @tc.number: OverlayDataMgr_0100 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of UpdateOverlayInfo. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0100, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - InnerBundleInfo targetInnerBundleInfo; - - newInfo.SetOverlayType(OverlayType::OVERLAY_INTERNAL_BUNDLE); - ErrCode res = overlayDataMgr.UpdateOverlayInfo(newInfo, oldInfo, targetInnerBundleInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); - newInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); - res = overlayDataMgr.UpdateOverlayInfo(newInfo, oldInfo, targetInnerBundleInfo); - EXPECT_EQ(res, ERR_OK); - newInfo.SetOverlayType(OverlayType::NON_OVERLAY_TYPE); - res = overlayDataMgr.UpdateOverlayInfo(newInfo, oldInfo, targetInnerBundleInfo); - EXPECT_EQ(res, ERR_OK); - - newInfo.SetOverlayType(FOUR); - res = overlayDataMgr.UpdateOverlayInfo(newInfo, oldInfo, targetInnerBundleInfo); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: OverlayDataMgr_0200 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of IsExistedNonOverlayHap. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0200, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - bool res = overlayDataMgr.IsExistedNonOverlayHap(""); - EXPECT_EQ(res, false); - res = overlayDataMgr.IsExistedNonOverlayHap("wrong"); - EXPECT_EQ(res, false); -} - -/** - * @tc.number: OverlayDataMgr_0300 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of UpdateInternalOverlayInfo. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0300, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - ErrCode res = overlayDataMgr.UpdateInternalOverlayInfo(newInfo, oldInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); - std::map innerModuleInfos; - InnerModuleInfo moduleInfo; - moduleInfo.moduleName = TEST_PACK_AGE; - moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; - innerModuleInfos[TEST_PACK_AGE] = moduleInfo; - newInfo.AddInnerModuleInfo(innerModuleInfos); - res = overlayDataMgr.UpdateInternalOverlayInfo(newInfo, oldInfo); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: OverlayDataMgr_0400 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of UpdateExternalOverlayInfo. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0400, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo innerBundleInfo; - InnerBundleInfo oldInfo; - InnerBundleInfo targetInnerBundleInfo; - - ErrCode res = overlayDataMgr.UpdateExternalOverlayInfo(innerBundleInfo, oldInfo, targetInnerBundleInfo); - EXPECT_EQ(res, ERR_OK); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - ApplicationInfo applicationInfo; - applicationInfo.bundleName = TEST_BUNDLE_NAME; - innerBundleInfo.SetBaseApplicationInfo(applicationInfo); - - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - ApplicationInfo targetApplicationInfo; - targetApplicationInfo.bundleName = TEST_BUNDLE_NAME; - - oldInfo.SetBaseApplicationInfo(targetApplicationInfo); - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); - dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, oldInfo); - innerBundleInfo.SetTargetBundleName(TEST_BUNDLE_NAME); - res = overlayDataMgr.UpdateExternalOverlayInfo(innerBundleInfo, oldInfo, oldInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); - - InnerModuleInfo moduleInfo; - std::map innerModuleInfos; - moduleInfo.moduleName = "moduleName"; - moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; - innerModuleInfos[TEST_PACK_AGE] = moduleInfo; - innerBundleInfo.AddInnerModuleInfo(innerModuleInfos); - res = overlayDataMgr.UpdateExternalOverlayInfo(innerBundleInfo, oldInfo, oldInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); - - innerBundleInfo.SetUserId(Constants::NOT_EXIST_USERID); - res = overlayDataMgr.UpdateExternalOverlayInfo(innerBundleInfo, oldInfo, oldInfo); - EXPECT_EQ(res, ERR_OK); - UninstallBundleInfo(); -} - -/** - * @tc.number: OverlayDataMgr_0500 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of UpdateExternalOverlayInfo. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0500, Function | SmallTest | Level0) -{ - AddInnerBundleInfo(); - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - InnerBundleInfo targetInnerBundleInfo; - - OverlayDataMgr overlayDataMgr; - ErrCode res = overlayDataMgr.UpdateExternalOverlayInfo(newInfo, oldInfo, targetInnerBundleInfo); - EXPECT_EQ(res, ERR_OK); - UninstallBundleInfo(); -} - -#ifdef BUNDLE_FRAMEWORK_OVERLAY_INSTALLATION -/** - * @tc.number: OverlayDataMgr_0600 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of BuildOverlayConnection and BuildOverlayConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0600, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - const auto &moduleInfos = newInfo.GetInnerModuleInfos(); - std::string moduleName = (moduleInfos.begin()->second).moduleName; - overlayDataMgr.BuildInternalOverlayConnection(moduleName, oldInfo, newInfo.GetUserId()); - EXPECT_EQ(oldInfo.FetchInnerModuleInfos().empty(), true); - - oldInfo.SetOverlayState(OverlayType::OVERLAY_INTERNAL_BUNDLE); - overlayDataMgr.BuildInternalOverlayConnection(moduleName, oldInfo, newInfo.GetUserId()); - EXPECT_EQ(oldInfo.FetchInnerModuleInfos().empty(), true); -} - -/** - * @tc.number: OverlayDataMgr_0700 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of BuildOverlayConnection and BuildOverlayConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0700, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo oldInfo; - oldInfo.SetIsPreInstallApp(false); - ApplicationInfo applicationInfo; - applicationInfo.bundleName = NO_EXIST; - oldInfo.SetBaseApplicationInfo(applicationInfo); - EXPECT_EQ(oldInfo.baseApplicationInfo_->bundleName, NO_EXIST); -} - -/** - * @tc.number: OverlayDataMgr_0900 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of BuildOverlayConnection and BuildOverlayConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0900, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo oldInfo; - oldInfo.SetIsPreInstallApp(true); - oldInfo.SetCertificateFingerprint(NO_EXIST); - EXPECT_EQ(oldInfo.baseApplicationInfo_->fingerprint, NO_EXIST); -} -#endif - -/** - * @tc.number: OverlayDataMgr_1200 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of GetBundleDir. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1200, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - std::string moduleHapPath = "xxx/"; - std::string bundleDir; - ErrCode res = overlayDataMgr.GetBundleDir(moduleHapPath, bundleDir); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_BUNDLE_DIR); - moduleHapPath = "//"; - res = overlayDataMgr.GetBundleDir(moduleHapPath, bundleDir); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: OverlayDataMgr_1300 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1300, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); - std::map innerModuleInfos; - InnerModuleInfo moduleInfo; - moduleInfo.moduleName = TEST_PACK_AGE; - moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; - innerModuleInfos[TEST_PACK_AGE] = moduleInfo; - newInfo.AddInnerModuleInfo(innerModuleInfos); - oldInfo.AddInnerModuleInfo(innerModuleInfos); - res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: OverlayDataMgr_1400 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1400, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - std::map innerModuleInfos; - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); - dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, newInfo); - ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); - UninstallBundleInfo(); -} - -/** - * @tc.number: OverlayDataMgr_1500 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1500, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - std::map innerModuleInfos; - InnerModuleInfo moduleInfo; - moduleInfo.moduleName = TEST_PACK_AGE; - moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; - innerModuleInfos[TEST_PACK_AGE] = moduleInfo; - newInfo.AddInnerModuleInfo(innerModuleInfos); - oldInfo.AddInnerModuleInfo(innerModuleInfos); - newInfo.SetOverlayType(OVERLAY_INTERNAL_BUNDLE); - - ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: OverlayDataMgr_1600 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of QueryOverlayInnerBundleInfo. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1600, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo info; - bool res = overlayDataMgr.QueryOverlayInnerBundleInfo("", info); - EXPECT_EQ(res, false); -} - -/** - * @tc.number: OverlayDataMgr_1700 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of GetAllOverlayModuleInfo. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1700, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - std::vector overlayModuleInfos; - ErrCode res = overlayDataMgr.GetAllOverlayModuleInfo("", overlayModuleInfos, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); - - AddInnerBundleInfo(); - res = overlayDataMgr.GetAllOverlayModuleInfo( - TEST_BUNDLE_NAME, overlayModuleInfos, Constants::NOT_EXIST_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_NON_OVERLAY_BUNDLE); - - res = overlayDataMgr.GetAllOverlayModuleInfo( - TEST_BUNDLE_NAME, overlayModuleInfos, Constants::INVALID_USERID); - EXPECT_EQ(res, - ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); - - OverlayModuleInfo overlayModuleInfo; - overlayModuleInfos.push_back(overlayModuleInfo); - res = overlayDataMgr.GetAllOverlayModuleInfo( - TEST_BUNDLE_NAME, overlayModuleInfos, Constants::NOT_EXIST_USERID); - - EXPECT_EQ(res, - ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_NON_OVERLAY_BUNDLE); - UninstallBundleInfo(); -} - -/** - * @tc.number: OverlayDataMgr_1800 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of GetOverlayModuleInfo. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1800, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - OverlayModuleInfo overlayModuleInfos; - ErrCode res = overlayDataMgr.GetOverlayModuleInfo("", "", overlayModuleInfos, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); - - AddInnerBundleInfo(); - res = overlayDataMgr.GetOverlayModuleInfo( - TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfos, Constants::INVALID_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); - - res = overlayDataMgr.GetOverlayModuleInfo( - TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfos, Constants::NOT_EXIST_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_NON_OVERLAY_BUNDLE); -} - -/** - * @tc.number: OverlayDataMgr_1900 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of GetOverlayBundleInfoForTarget. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1900, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - std::vector overlayBundleInfo; - ErrCode res = overlayDataMgr.GetOverlayBundleInfoForTarget("", overlayBundleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_NOT_EXISTED); - - AddInnerBundleInfo(); - res = overlayDataMgr.GetOverlayBundleInfoForTarget( - TEST_BUNDLE_NAME, overlayBundleInfo, Constants::NOT_EXIST_USERID); - EXPECT_EQ(res, ERR_OK); - EXPECT_EQ(overlayBundleInfo.size(), DEFAULT_OVERLAY_BUNDLE_INFO); - - res = overlayDataMgr.GetOverlayBundleInfoForTarget( - TEST_BUNDLE_NAME, overlayBundleInfo, Constants::INVALID_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); - - UninstallBundleInfo(); -} - -/** - * @tc.number: OverlayDataMgr_2000 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of GetOverlayModuleInfoForTarget. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2000, Function | SmallTest | Level0) -{ - AddInnerBundleInfo(); - OverlayDataMgr overlayDataMgr; - std::vector overlayModuleInfos; - ErrCode res = overlayDataMgr.GetOverlayModuleInfoForTarget( - TEST_BUNDLE_NAME, TARGET_MODULE_NAME, overlayModuleInfos, Constants::NOT_EXIST_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_MODULE_IS_OVERLAY_MODULE); - - res = overlayDataMgr.GetOverlayModuleInfoForTarget( - TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfos, Constants::NOT_EXIST_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_MODULE_NOT_EXISTED); - - res = overlayDataMgr.GetOverlayModuleInfoForTarget( - TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfos, Constants::INVALID_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); - - res = overlayDataMgr.GetOverlayModuleInfoForTarget( - TEST_BUNDLE_NAME, "", overlayModuleInfos, Constants::NOT_EXIST_USERID); - EXPECT_EQ(res, ERR_OK); - - res = overlayDataMgr.GetOverlayModuleInfoForTarget( - "", "", overlayModuleInfos, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_NOT_EXISTED); - - UninstallBundleInfo(); -} - -/** - * @tc.number: OverlayDataMgr_2100 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of SetOverlayEnabled. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2100, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - bool isEnabled = false; - ErrCode res = overlayDataMgr.SetOverlayEnabled(TEST_BUNDLE_NAME, "", isEnabled, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); - - AddInnerBundleInfo(); - res = overlayDataMgr.SetOverlayEnabled( - TEST_BUNDLE_NAME, TEST_MODULE_NAME, isEnabled, Constants::INVALID_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); - - res = overlayDataMgr.SetOverlayEnabled(TEST_BUNDLE_NAME, TEST_MODULE_NAME, isEnabled, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); - - UninstallBundleInfo(); -} - -/** - * @tc.number: OverlayDataMgr_2200 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of GetCallingBundleName. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2200, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - std::string res = overlayDataMgr.GetCallingBundleName(); - EXPECT_EQ(res, ""); -} - -/** - * @tc.number: OverlayDataMgr_2300 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of AddOverlayModuleStates. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2300, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo innerBundleInfo; - InnerBundleUserInfo userInfo; - overlayDataMgr.AddOverlayModuleStates(innerBundleInfo, userInfo); - EXPECT_EQ(userInfo.bundleUserInfo.userId, Constants::INVALID_USERID); - - userInfo.bundleUserInfo.userId = USERID; - innerBundleInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); - overlayDataMgr.AddOverlayModuleStates(innerBundleInfo, userInfo); - EXPECT_EQ(userInfo.bundleUserInfo.userId, USERID); -} - -/** - * @tc.number: OverlayDataMgr_2400 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of AddOverlayModuleStates. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2400, Function | SmallTest | Level0) -{ - AddInnerBundleInfo(); - OverlayDataMgr overlayDataMgr; - InnerBundleInfo innerBundleInfo; - InnerBundleUserInfo userInfo; - userInfo.bundleUserInfo.userId = USERID; - innerBundleInfo.SetOverlayType(OverlayType::OVERLAY_INTERNAL_BUNDLE); - innerBundleInfo.SetTargetBundleName(TEST_BUNDLE_NAME); - overlayDataMgr.AddOverlayModuleStates(innerBundleInfo, userInfo); - EXPECT_EQ(userInfo.bundleUserInfo.userId, USERID); - UninstallBundleInfo(); -} - -/** - * @tc.number: OverlayDataMgr_2500 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2500, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - std::map innerModuleInfos; - InnerModuleInfo moduleInfo; - moduleInfo.moduleName = TEST_PACK_AGE; - moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; - innerModuleInfos[TEST_PACK_AGE] = moduleInfo; - newInfo.AddInnerModuleInfo(innerModuleInfos); - oldInfo.AddInnerModuleInfo(innerModuleInfos); - newInfo.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); - - ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); - EXPECT_EQ(res, ERR_OK); - - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - ApplicationInfo applicationInfo; - applicationInfo.bundleName = TEST_BUNDLE_NAME; - applicationInfo.targetBundleName = TEST_BUNDLE_NAME; - oldInfo.SetBaseApplicationInfo(applicationInfo); - dataMgr->bundleInfos_.insert( - pair(TEST_BUNDLE_NAME, oldInfo)); - res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: OverlayDataMgr_2600 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2600, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - std::map innerModuleInfos; - InnerModuleInfo moduleInfo; - moduleInfo.moduleName = TEST_PACK_AGE; - moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; - innerModuleInfos[TEST_PACK_AGE] = moduleInfo; - newInfo.AddInnerModuleInfo(innerModuleInfos); - oldInfo.AddInnerModuleInfo(innerModuleInfos); - newInfo.SetOverlayType(NON_OVERLAY_TYPE); - - ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: OverlayDataMgr_2700 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2700, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - InnerBundleInfo targetInnerBundleInfo; - std::map innerModuleInfos; - - overlayDataMgr.RemoveOverlayBundleInfo(TEST_BUNDLE_NAME, targetInnerBundleInfo); - overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); - InnerModuleInfo moduleInfo; - moduleInfo.moduleName = TEST_PACK_AGE; - moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; - innerModuleInfos[TEST_PACK_AGE] = moduleInfo; - newInfo.AddInnerModuleInfo(innerModuleInfos); - oldInfo.AddInnerModuleInfo(innerModuleInfos); - newInfo.SetOverlayType(OVERLAY_INTERNAL_BUNDLE); - - ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: OverlayDataMgr_2800 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2800, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - std::map innerModuleInfos; - InnerModuleInfo moduleInfo; - moduleInfo.moduleName = TEST_PACK_AGE; - moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; - innerModuleInfos[TEST_PACK_AGE] = moduleInfo; - newInfo.AddInnerModuleInfo(innerModuleInfos); - oldInfo.AddInnerModuleInfo(innerModuleInfos); - newInfo.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); - - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - ApplicationInfo applicationInfo; - applicationInfo.bundleName = TEST_BUNDLE_NAME; - applicationInfo.targetBundleName = TEST_BUNDLE_NAME; - oldInfo.SetBaseApplicationInfo(applicationInfo); - newInfo.SetTargetBundleName(NO_EXIST); - dataMgr->bundleInfos_.insert( - pair(TEST_BUNDLE_NAME, oldInfo)); - ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: OverlayDataMgr_2900 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleInfo. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2900, Function | SmallTest | Level0) -{ - AddInnerBundleInfo(); - - OverlayDataMgr overlayDataMgr; - InnerBundleInfo oldInfo; - InnerBundleInfo targetInnerBundleInfo; - std::map innerModuleInfos; - InnerModuleInfo moduleInfo; - moduleInfo.moduleName = TEST_PACK_AGE; - moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; - innerModuleInfos[TEST_PACK_AGE] = moduleInfo; - oldInfo.AddInnerModuleInfo(innerModuleInfos); - - overlayDataMgr.RemoveOverlayBundleInfo(TEST_BUNDLE_NAME, targetInnerBundleInfo); - overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); - - oldInfo.SetOverlayType(OVERLAY_INTERNAL_BUNDLE); - overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); - EXPECT_EQ(oldInfo.GetOverlayType(), OVERLAY_INTERNAL_BUNDLE); - - oldInfo.SetTargetBundleName(TARGET_MODULE_NAME); - overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); - EXPECT_EQ(oldInfo.GetTargetBundleName(), TARGET_MODULE_NAME); - - oldInfo.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); - overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); - EXPECT_EQ(oldInfo.GetOverlayType(), OVERLAY_EXTERNAL_BUNDLE); - - oldInfo.SetTargetBundleName(TARGET_MODULE_NAME); - overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); - EXPECT_EQ(oldInfo.GetTargetBundleName(), TARGET_MODULE_NAME); - - oldInfo.SetOverlayType(NON_OVERLAY_TYPE); - overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); - overlayDataMgr.RemoveOverlayModuleInfo("noExits", TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); - EXPECT_EQ(oldInfo.GetOverlayType(), NON_OVERLAY_TYPE); - UninstallBundleInfo(); -} - -/** - * @tc.number: OverlayDataMgr_3000 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3000, Function | SmallTest | Level0) -{ - InnerBundleInfo info; - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); - - info.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); - bool res = dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, info); - EXPECT_EQ(res, true); - - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME2, InstallState::INSTALL_START); - info.SetOverlayType(OverlayType::NON_OVERLAY_TYPE); - res = dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME2, info); - EXPECT_EQ(res, true); - - UninstallBundleInfo(); -} - -/** - * @tc.number: OverlayDataMgr_3100 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3100, Function | SmallTest | Level0) -{ - InnerBundleInfo info; - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); - - info.SetOverlayType(OverlayType::OVERLAY_INTERNAL_BUNDLE); - bool res = dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, info); - EXPECT_EQ(res, true); - - UninstallBundleInfo(); -} - -/** - * @tc.number: OverlayDataMgr_3200 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3200, Function | SmallTest | Level0) -{ - AddInnerBundleInfo(); - - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - std::map innerModuleInfos; - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - bool res = dataMgr->AddNewModuleInfo(TEST_BUNDLE_NAME, newInfo, oldInfo); - EXPECT_EQ(res, false); - - UninstallBundleInfo(); -} - -/** - * @tc.number: OverlayDataMgr_3300 - * @tc.name: AddBundleInfo - * @tc.desc: 1. add module info to the data manager - * 2. query data then verify - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3300, Function | SmallTest | Level0) -{ - InnerBundleInfo info1; - BundleInfo bundleInfo1; - bundleInfo1.name = TEST_BUNDLE_NAME; - bundleInfo1.applicationInfo.bundleName = TEST_BUNDLE_NAME; - ApplicationInfo applicationInfo1; - applicationInfo1.name = TEST_BUNDLE_NAME; - applicationInfo1.bundleName = TEST_BUNDLE_NAME; - info1.SetBaseBundleInfo(bundleInfo1); - info1.SetBaseApplicationInfo(applicationInfo1); - - InnerBundleInfo info2; - BundleInfo bundleInfo2; - bundleInfo2.name = TEST_BUNDLE_NAME; - bundleInfo2.applicationInfo.bundleName = TEST_BUNDLE_NAME; - ApplicationInfo applicationInfo2; - applicationInfo2.name = TEST_BUNDLE_NAME; - applicationInfo2.bundleName = TEST_BUNDLE_NAME; - info2.SetBaseBundleInfo(bundleInfo2); - info2.SetBaseApplicationInfo(applicationInfo2); - - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); - dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, info1); - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UPDATING_START); - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UPDATING_SUCCESS); - info1.SetOverlayType(OverlayType::NON_OVERLAY_TYPE); - info2.SetOverlayType(OverlayType::OVERLAY_INTERNAL_BUNDLE); - bool ret = dataMgr->AddNewModuleInfo(TEST_BUNDLE_NAME, info2, info1); - EXPECT_FALSE(ret); - - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_START); - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_SUCCESS); -} - - -/** - * @tc.number: OverlayDataMgr_3400 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of IsExistedNonOverlayHap. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3400, Function | SmallTest | Level0) -{ - AddInnerBundleInfo(); - OverlayDataMgr overlayDataMgr; - bool res = overlayDataMgr.IsExistedNonOverlayHap(TEST_BUNDLE_NAME); - EXPECT_EQ(res, false); - - UninstallBundleInfo(); -} - -/** - * @tc.number: OverlayDataMgr_3500 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of BuildInternalOverlayConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3500, Function | SmallTest | Level0) -{ - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.name = TEST_MODULE_NAME; - innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; - innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - ApplicationInfo applicationInfo; - applicationInfo.bundleName = TEST_BUNDLE_NAME; - applicationInfo.targetBundleName = TEST_BUNDLE_NAME; - innerBundleInfo.SetBaseApplicationInfo(applicationInfo); - - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); - dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, innerBundleInfo); - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UPDATING_START); - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UPDATING_SUCCESS); - OverlayDataMgr overlayDataMgr; - overlayDataMgr.BuildInternalOverlayConnection(TARGET_MODULE_NAME, innerBundleInfo, USERID); - EXPECT_EQ(innerBundleInfo.FetchInnerModuleInfos().empty(), false); - UninstallBundleInfo(); -} - -/** - * @tc.number: OverlayDataMgr_3600 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3600, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - std::map innerModuleInfos; - InnerModuleInfo moduleInfo; - moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; - innerModuleInfos[TEST_PACK_AGE] = moduleInfo; - newInfo.AddInnerModuleInfo(innerModuleInfos); - oldInfo.AddInnerModuleInfo(innerModuleInfos); - newInfo.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); - - ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); -} - -/** - * @tc.number: OverlayDataMgr_3800 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleInfo. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3800, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo targetInnerBundleInfo; - std::map innerModuleInfos; - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.name = TEST_MODULE_NAME; - innerModuleInfo.moduleName = TEST_PACK_AGE; - innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; - innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; - innerModuleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; - innerModuleInfos[TEST_PACK_AGE] = innerModuleInfo; - innerBundleInfo.AddInnerModuleInfo(innerModuleInfos); - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - ApplicationInfo applicationInfo; - applicationInfo.bundleName = TEST_BUNDLE_NAME; - applicationInfo.targetBundleName = TEST_BUNDLE_NAME; - innerBundleInfo.SetBaseApplicationInfo(applicationInfo); - - innerBundleInfo.SetOverlayType(OverlayType::OVERLAY_INTERNAL_BUNDLE); - overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, innerBundleInfo, targetInnerBundleInfo); - overlayDataMgr.ResetInternalOverlayModuleState(innerModuleInfos, TARGET_MODULE_NAME, innerBundleInfo); - EXPECT_EQ(innerModuleInfos.at(TEST_PACK_AGE).targetModuleName, TARGET_MODULE_NAME); -} - -/** - * @tc.number: OverlayDataMgr_3900 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of SaveInternalOverlayModuleState. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3900, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - std::map innerModuleInfos; - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.name = TEST_MODULE_NAME; - innerModuleInfo.moduleName = TEST_PACK_AGE; - innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; - innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; - innerModuleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; - innerModuleInfos[TEST_PACK_AGE] = innerModuleInfo; - innerBundleInfo.AddInnerModuleInfo(innerModuleInfos); - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - ApplicationInfo applicationInfo; - applicationInfo.bundleName = TEST_BUNDLE_NAME; - applicationInfo.targetBundleName = TEST_BUNDLE_NAME; - innerBundleInfo.SetBaseApplicationInfo(applicationInfo); - - OverlayModuleInfo overlayModuleInfo; - overlayModuleInfo.targetModuleName = TARGET_MODULE_NAME; - - ErrCode res = overlayDataMgr.SaveInternalOverlayModuleState(overlayModuleInfo, innerBundleInfo); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: OverlayDataMgr_4000 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of GetOverlayModuleInfoForTarget. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4000, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo innerBundleInfo; - std::vector overlayModuleInfos; - ErrCode res = overlayDataMgr.GetOverlayModuleInfoForTarget( - innerBundleInfo, overlayModuleInfos, Constants::NOT_EXIST_USERID); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: OverlayDataMgr_4100 - * @tc.name: test bundleName is empty. - * @tc.desc: 1.OverlayDataMgr with SetOverlayEnabled. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4100, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - bool isEnabled = false; - ErrCode res = overlayDataMgr.SetOverlayEnabled("", TEST_MODULE_NAME, isEnabled, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); -} - -/** - * @tc.number: OverlayDataMgr_4200 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of BuildInternalOverlayConnection. - * 2.system run normally. - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4200, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo oldInfo; - oldInfo.SetOverlayType(OVERLAY_INTERNAL_BUNDLE); - InnerModuleInfo moduleInfo; - moduleInfo.targetModuleName = TEST_MODULE_NAME; - std::map innerModuleInfos; - moduleInfo.moduleName = TEST_MODULE_NAME; - innerModuleInfos[TEST_PACK_AGE] = moduleInfo; - moduleInfo.moduleName = TEST_PACK_AGE; - moduleInfo.targetModuleName = TEST_PACK_AGE; - innerModuleInfos[TEST_MODULE_NAME] = moduleInfo; - oldInfo.AddInnerModuleInfo(innerModuleInfos); - EXPECT_EQ(oldInfo.GetOverlayType(), OVERLAY_INTERNAL_BUNDLE); - - ClearDataMgr(); - EXPECT_EQ(bundleMgrService_->dataMgr_, nullptr); - BuildInternalOverlayConnection(TEST_MODULE_NAME, oldInfo, USERID); - ResetDataMgr(); -} - -/** - * @tc.number: OverlayDataMgr_4300 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of QueryOverlayInnerBundleInfo. - * 2.system run normally. - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4300, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - overlayDataMgr.dataMgr_ = std::make_shared(); - InnerBundleInfo info; - std::map innerModuleInfos; - info.AddInnerModuleInfo(innerModuleInfos); - overlayDataMgr.dataMgr_->bundleInfos_[NO_EXIST] = info; - bool ret = overlayDataMgr.QueryOverlayInnerBundleInfo(NO_EXIST, info); - auto iterator = overlayDataMgr.dataMgr_->bundleInfos_.find(NO_EXIST); - if (iterator != overlayDataMgr.dataMgr_->bundleInfos_.end()) { - overlayDataMgr.dataMgr_->bundleInfos_.erase(iterator); - } - EXPECT_EQ(ret, true); -} - -/** - * @tc.number: OverlayDataMgr_4400 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of QueryOverlayInnerBundleInfo. - * 2.system run normally. - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4400, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - overlayDataMgr.dataMgr_ = std::make_shared(); - InnerBundleInfo info; - info.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); - std::map innerModuleInfos; - InnerModuleInfo innerModuleInfo; - innerModuleInfos[TEST_MODULE_NAME] = innerModuleInfo; - info.AddInnerModuleInfo(innerModuleInfos); - overlayDataMgr.dataMgr_->bundleInfos_[NO_EXIST] = info; - std::vector overlayModuleInfo; - auto ret = overlayDataMgr.GetAllOverlayModuleInfo(NO_EXIST, overlayModuleInfo, - Constants::NOT_EXIST_USERID); - auto iterator = overlayDataMgr.dataMgr_->bundleInfos_.find(NO_EXIST); - if (iterator != overlayDataMgr.dataMgr_->bundleInfos_.end()) { - overlayDataMgr.dataMgr_->bundleInfos_.erase(iterator); - } - EXPECT_EQ(ret, ERR_OK); -} - -/** - * @tc.number: OverlayDataMgr_4500 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of BuildInternalOverlayConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4500, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo oldInfo; - oldInfo.overlayType_ = OVERLAY_INTERNAL_BUNDLE; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.targetModuleName = "errModuleName"; - oldInfo.innerModuleInfos_.insert(pair("1", innerModuleInfo)); - overlayDataMgr.BuildInternalOverlayConnection(TARGET_MODULE_NAME, oldInfo, USERID); - EXPECT_EQ(oldInfo.FetchInnerModuleInfos().empty(), false); -} - -/** - * @tc.number: OverlayDataMgr_4600 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of BuildInternalOverlayConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4600, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo oldInfo; - oldInfo.overlayType_ = OVERLAY_INTERNAL_BUNDLE; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; - innerModuleInfo.moduleName = TEST_MODULE_NAME; - oldInfo.innerModuleInfos_.insert(pair("1", innerModuleInfo)); - overlayDataMgr.BuildInternalOverlayConnection(TARGET_MODULE_NAME, oldInfo, USERID); - EXPECT_EQ(oldInfo.FetchInnerModuleInfos().empty(), false); -} - -/** - * @tc.number: OverlayDataMgr_4700 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of BuildInternalOverlayConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4700, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo oldInfo; - oldInfo.overlayType_ = OVERLAY_INTERNAL_BUNDLE; - oldInfo.innerModuleInfos_.clear(); - overlayDataMgr.BuildInternalOverlayConnection(TARGET_MODULE_NAME, oldInfo, USERID); - EXPECT_EQ(oldInfo.FetchInnerModuleInfos().empty(), true); -} - -/** - * @tc.number: OverlayDataMgr_4800 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of BuildInternalOverlayConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4800, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo oldInfo; - oldInfo.overlayType_ = OVERLAY_INTERNAL_BUNDLE; - oldInfo.innerModuleInfos_.clear(); - overlayDataMgr.BuildInternalOverlayConnection(TARGET_MODULE_NAME, oldInfo, USERID); - EXPECT_EQ(oldInfo.FetchInnerModuleInfos().empty(), true); -} - -/** - * @tc.number: OverlayDataMgr_4900 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of QueryOverlayInnerBundleInfo. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4900, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo innerBundleInfo; - overlayDataMgr.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); - overlayDataMgr.dataMgr_->bundleInfos_.insert(pair(TEST_BUNDLE_NAME, innerBundleInfo)); - auto res = overlayDataMgr.QueryOverlayInnerBundleInfo(NO_EXIST, innerBundleInfo); - EXPECT_FALSE(res); -} - -/** - * @tc.number: OverlayDataMgr_5000 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of QueryOverlayInnerBundleInfo. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_5000, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo innerBundleInfo; - ClearDataMgr(); - auto res = overlayDataMgr.QueryOverlayInnerBundleInfo(TEST_BUNDLE_NAME, innerBundleInfo); - EXPECT_FALSE(res); - ResetDataMgr(); -} - -/** - * @tc.number: OverlayDataMgr_5100 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of SaveInternalOverlayModuleState. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_5100, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - OverlayModuleInfo overlayModuleInfo; - overlayModuleInfo.targetModuleName = TARGET_MODULE_NAME; - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - innerBundleInfo.innerModuleInfos_.insert(pair(TARGET_MODULE_NAME, innerModuleInfo)); - overlayDataMgr.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); - overlayDataMgr.dataMgr_->AddUserId(NOT_EXIST_USERID); - auto res = overlayDataMgr.SaveInternalOverlayModuleState(overlayModuleInfo, innerBundleInfo); - EXPECT_FALSE(res); -} - -/** - * @tc.number: OverlayDataMgr_5200 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of SaveInternalOverlayModuleState. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_5200, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - OverlayModuleInfo overlayModuleInfo; - overlayModuleInfo.targetModuleName = TARGET_MODULE_NAME; - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - innerBundleInfo.innerModuleInfos_.insert(pair(TEST_MODULE_NAME, innerModuleInfo)); - overlayDataMgr.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); - overlayDataMgr.dataMgr_->AddUserId(NOT_EXIST_USERID); - auto res = overlayDataMgr.SaveInternalOverlayModuleState(overlayModuleInfo, innerBundleInfo); - EXPECT_FALSE(res); -} - -/** - * @tc.number: OverlayManagerHostImpl_0100 - * @tc.name: test overlayManagerHostImpl. - * @tc.desc: 1.overlayManagerHostImpl of GetAllOverlayModuleInfo. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, OverlayManagerHostImpl_0100, Function | SmallTest | Level0) -{ - OverlayManagerHostImpl overlayManagerHostImpl; - std::vector overlayModuleInfo; - ErrCode res = overlayManagerHostImpl.GetAllOverlayModuleInfo("", overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - - res = overlayManagerHostImpl.GetAllOverlayModuleInfo( - "bundleName", overlayModuleInfo, Constants::UNSPECIFIED_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); -} - -/** - * @tc.number: GetOverlayModuleInfo_0200 - * @tc.name: test overlayManagerHostImpl. - * @tc.desc: 1.overlayManagerHostImpl of GetOverlayModuleInfo. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_0200, Function | SmallTest | Level0) -{ - OverlayManagerHostImpl overlayManagerHostImpl; - OverlayModuleInfo overlayModuleInfo; - ErrCode res = overlayManagerHostImpl.GetOverlayModuleInfo( - "", "moduleName", overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - - res = overlayManagerHostImpl.GetOverlayModuleInfo( - "bundleName", "", overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - - res = overlayManagerHostImpl.GetOverlayModuleInfo( - "", "", overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - - res = overlayManagerHostImpl.GetOverlayModuleInfo( - "bundleName", "moduleName", overlayModuleInfo, Constants::UNSPECIFIED_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); -} - -/** - * @tc.number: GetOverlayModuleInfo_0300 - * @tc.name: test overlayManagerHostImpl. - * @tc.desc: 1.overlayManagerHostImpl of GetOverlayBundleInfoForTarget. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_0300, Function | SmallTest | Level0) -{ - OverlayManagerHostImpl overlayManagerHostImpl; - std::vector overlayBundleInfo; - ErrCode res = overlayManagerHostImpl.GetOverlayBundleInfoForTarget( - "", overlayBundleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - - res = overlayManagerHostImpl.GetOverlayBundleInfoForTarget( - "targetBundleName", overlayBundleInfo, Constants::UNSPECIFIED_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_NOT_EXISTED); -} - -/** - * @tc.number: GetOverlayModuleInfo_0400 - * @tc.name: test OverlayManagerHostImpl. - * @tc.desc: 1.OverlayManagerHostImpl of GetOverlayModuleInfoForTarget. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_0400, Function | SmallTest | Level0) -{ - OverlayManagerHostImpl overlayManagerHostImpl; - std::vector overlayModuleInfo; - ErrCode res = overlayManagerHostImpl.GetOverlayModuleInfoForTarget( - "", "targetModuleName", overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - - res = overlayManagerHostImpl.GetOverlayModuleInfoForTarget( - "targetBundleName", "", overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_NOT_EXISTED); - - res = overlayManagerHostImpl.GetOverlayModuleInfoForTarget( - "", "", overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - - res = overlayManagerHostImpl.GetOverlayModuleInfoForTarget( - "targetBundleName", "targetModuleName", overlayModuleInfo, Constants::UNSPECIFIED_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_NOT_EXISTED); -} - -/** - * @tc.number: GetOverlayModuleInfo_0500 - * @tc.name: test OverlayManagerHostImpl. - * @tc.desc: 1.OverlayManagerHostImpl of SetOverlayEnabled. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_0500, Function | SmallTest | Level0) -{ - OverlayManagerHostImpl overlayManagerHostImpl; - bool isEnabled = false; - ErrCode res = overlayManagerHostImpl.SetOverlayEnabled( - "", "moduleName", isEnabled, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_SET_OVERLAY_PARAM_ERROR); - - res = overlayManagerHostImpl.SetOverlayEnabled( - "bundleName", "", isEnabled, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_SET_OVERLAY_PARAM_ERROR); - - res = overlayManagerHostImpl.SetOverlayEnabled( - "", "", isEnabled, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_SET_OVERLAY_PARAM_ERROR); - - res = overlayManagerHostImpl.SetOverlayEnabled( - "bundleName", "moduleName", isEnabled, Constants::UNSPECIFIED_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); -} - -/** - * @tc.number: GetOverlayModuleInfo_0800 - * @tc.name: test overlayManagerHostImpl. - * @tc.desc: 1.OverlayManagerHostImpl with GetOverlayBundleInfoForTarget. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_0800, Function | SmallTest | Level0) -{ - OverlayManagerHostImpl overlayManagerHostImpl; - std::vector overlayBundleInfo; - ErrCode res = overlayManagerHostImpl.GetOverlayBundleInfoForTarget(TEST_BUNDLE_NAME, - overlayBundleInfo, Constants::INVALID_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); -} - -/** - * @tc.number: OverlayIpcTest_2000 - * @tc.name: test SetOverlayEnabled interface in OverlayManagerProxy. - * @tc.desc: 1.construct OverlayManagerProxy instance. - * 2.calling SetOverlayEnabled interface by using OverlayManagerProxy instance. - * 3.bundleName is empty and set failed - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_0900, Function | SmallTest | Level0) -{ - OverlayManagerHostImpl overlayManagerHostImpl; - - std::vector overlayModuleInfos; - auto errCode = overlayManagerHostImpl.GetTargetOverlayModuleInfo("", overlayModuleInfos, - USERID); - EXPECT_EQ(errCode, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - - errCode = overlayManagerHostImpl.GetTargetOverlayModuleInfo(TEST_BUNDLE_NAME, overlayModuleInfos, - Constants::UNSPECIFIED_USERID); - EXPECT_EQ(errCode, ERR_BUNDLE_MANAGER_INTERNAL_ERROR); -} - -/** - * @tc.number: OverlayIpcTest_2000 - * @tc.name: test SetOverlayEnabled interface in OverlayManagerProxy. - * @tc.desc: 1.construct GetOverlayModuleInfoByBundleName instance. - * 2.calling SetOverlayEnabled interface by using GetOverlayModuleInfoByBundleName instance. - * 3.bundleName is empty and set failed - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_1000, Function | SmallTest | Level0) -{ - OverlayManagerHostImpl overlayManagerHostImpl; - - std::vector overlayModuleInfos; - auto errCode = overlayManagerHostImpl.GetOverlayModuleInfoByBundleName("", TEST_MODULE_NAME, - overlayModuleInfos, USERID); - EXPECT_EQ(errCode, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - - errCode = overlayManagerHostImpl.GetOverlayModuleInfoByBundleName(TEST_BUNDLE_NAME, "", - overlayModuleInfos, Constants::UNSPECIFIED_USERID); - EXPECT_EQ(errCode, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); - - errCode = overlayManagerHostImpl.GetOverlayModuleInfoByBundleName(TEST_BUNDLE_NAME, TEST_MODULE_NAME, - overlayModuleInfos, Constants::UNSPECIFIED_USERID); - EXPECT_EQ(errCode, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); -} - -/** - * @tc.number: OverlayIpcTest_2000 - * @tc.name: test SetOverlayEnabledForSelf interface in OverlayManagerProxy. - * @tc.desc: 1.construct SetOverlayEnabledForSelf instance. - * 2.calling SetOverlayEnabled interface by using SetOverlayEnabledForSelf instance. - * 3.bundleName is empty and set failed - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_1100, Function | SmallTest | Level0) -{ - OverlayManagerHostImpl overlayManagerHostImpl; - - bool isEnabled = false; - auto errCode = overlayManagerHostImpl.SetOverlayEnabledForSelf("", - isEnabled, USERID); - EXPECT_EQ(errCode, ERR_BUNDLEMANAGER_OVERLAY_SET_OVERLAY_PARAM_ERROR); - - errCode = overlayManagerHostImpl.SetOverlayEnabledForSelf(TEST_MODULE_NAME, - isEnabled, Constants::UNSPECIFIED_USERID); - EXPECT_EQ(errCode, ERR_BUNDLE_MANAGER_INTERNAL_ERROR); -} - -/** - * @tc.number: CheckTargetBundle_0100 - * @tc.name: check bundle target priority range - * @tc.desc: Test CheckTargetBundle -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckTargetBundle_0100, Function | SmallTest | Level0) -{ - BundleOverlayInstallChecker checker; - auto code = checker.CheckTargetBundle("", "", "", USERID); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_BUNDLE_NAME); - code = checker.CheckTargetBundle(TEST_BUNDLE_NAME, "", "", USERID); - EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_NO_SYSTEM_APPLICATION_FOR_EXTERNAL_OVERLAY); -} - -/** - * @tc.number: UpdateInnerBundleInfo_0100 - * @tc.name: test OverlayDataMgr. - * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, UpdateInnerBundleInfo_0100, Function | SmallTest | Level0) -{ - InnerBundleInfo info1; - BundleInfo bundleInfo1; - bundleInfo1.name = BUNDLE_NAME; - bundleInfo1.applicationInfo.bundleName = BUNDLE_NAME; - ApplicationInfo applicationInfo1; - applicationInfo1.name = BUNDLE_NAME; - applicationInfo1.bundleName = BUNDLE_NAME; - info1.SetBaseBundleInfo(bundleInfo1); - info1.SetBaseApplicationInfo(applicationInfo1); - - InnerBundleInfo info2; - BundleInfo bundleInfo2; - bundleInfo2.name = BUNDLE_NAME; - bundleInfo2.applicationInfo.bundleName = BUNDLE_NAME; - ApplicationInfo applicationInfo2; - applicationInfo2.name = BUNDLE_NAME; - applicationInfo2.bundleName = BUNDLE_NAME; - info2.SetBaseBundleInfo(bundleInfo2); - info2.SetBaseApplicationInfo(applicationInfo2); - info2.SetIsNewVersion(true); - info2.SetOverlayType(OverlayType::NON_OVERLAY_TYPE); - - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - dataMgr->AddUserId(USERID); - - bool ret1 = dataMgr->UpdateBundleInstallState(BUNDLE_NAME, InstallState::INSTALL_START); - bool ret2 = dataMgr->AddInnerBundleInfo(BUNDLE_NAME, info1); - bool ret3 = dataMgr->UpdateBundleInstallState(BUNDLE_NAME, InstallState::UPDATING_START); - bool ret4 = dataMgr->UpdateBundleInstallState(BUNDLE_NAME, InstallState::UPDATING_SUCCESS); - bool ret5 = dataMgr->UpdateInnerBundleInfo(BUNDLE_NAME, info2, info1); - EXPECT_TRUE(ret1); - EXPECT_TRUE(ret2); - EXPECT_TRUE(ret3); - EXPECT_TRUE(ret4); - EXPECT_TRUE(ret5); - - info2.SetOverlayType(OverlayType::OVERLAY_INTERNAL_BUNDLE); - ret5 = dataMgr->UpdateInnerBundleInfo(BUNDLE_NAME, info2, info1); - EXPECT_FALSE(ret5); - - info2.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); - ret5 = dataMgr->UpdateInnerBundleInfo(BUNDLE_NAME, info2, info1); - EXPECT_TRUE(ret5); - - ret5 = dataMgr->UpdateBundleInstallState(BUNDLE_NAME, InstallState::UNINSTALL_START); - EXPECT_TRUE(ret5); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_0100 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0100, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - - ClearDataMgr(); - bool resBool = overlayDataMgr.IsExistedNonOverlayHap(TEST_BUNDLE_NAME); - EXPECT_EQ(resBool, false); - ResetDataMgr(); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_0200 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0200, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - std::map innerModuleInfos; - InnerModuleInfo moduleInfo; - moduleInfo.moduleName = TEST_PACK_AGE; - moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; - innerModuleInfos[TEST_PACK_AGE] = moduleInfo; - newInfo.AddInnerModuleInfo(innerModuleInfos); - oldInfo.AddInnerModuleInfo(innerModuleInfos); - newInfo.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); - - ClearDataMgr(); - ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); - ResetDataMgr(); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_0300 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6S6E8 - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0300, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo oldInfo; - InnerBundleInfo targetInnerBundleInfo; - std::map innerModuleInfos; - InnerModuleInfo moduleInfo; - moduleInfo.moduleName = TEST_PACK_AGE; - moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; - innerModuleInfos[TEST_PACK_AGE] = moduleInfo; - oldInfo.AddInnerModuleInfo(innerModuleInfos); - oldInfo.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); - - ClearDataMgr(); - overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); - std::map moduleInfos = oldInfo.FetchInnerModuleInfos(); - EXPECT_EQ(moduleInfos.empty(), false); - ResetDataMgr(); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_0400 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0400, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleUserInfo userInfo; - userInfo.bundleUserInfo.overlayModulesState.clear(); - std::map statesMap; - std::map res = overlayDataMgr.GetModulesStateFromUserInfo(userInfo); - EXPECT_EQ(res, statesMap); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_0500 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0500, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - OverlayModuleInfo overlayModuleInfo; - overlayModuleInfo.bundleName = NO_EXIST; - ErrCode res = overlayDataMgr.ObtainOverlayModuleState(overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_0600 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0600, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo newInfo; - InnerBundleInfo oldInfo; - InnerBundleInfo targetInnerBundleInfo; - - ClearDataMgr(); - auto resCode = overlayDataMgr.UpdateExternalOverlayInfo(newInfo, oldInfo, targetInnerBundleInfo); - EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); - ResetDataMgr(); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_0700 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0700, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo oldInfo; - - ClearDataMgr(); - auto resBool = overlayDataMgr.QueryOverlayInnerBundleInfo(TEST_BUNDLE_NAME, oldInfo); - EXPECT_EQ(resBool, false); - ResetDataMgr(); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_0800 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0800, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo oldInfo; - - ClearDataMgr(); - OverlayModuleInfo overlayModuleInfo; - ErrCode resCode = overlayDataMgr.SaveInternalOverlayModuleState(overlayModuleInfo, oldInfo); - EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_SERVICE_EXCEPTION); - ResetDataMgr(); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_0900 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0900, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo oldInfo; - InnerBundleInfo targetBundleInfo; - - ClearDataMgr(); - OverlayModuleInfo overlayModuleInfo; - ErrCode resCode = overlayDataMgr.SaveExternalOverlayModuleState( - overlayModuleInfo, targetBundleInfo, USERID, oldInfo); - EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); - ResetDataMgr(); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_1000 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1000, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo oldInfo; - - ClearDataMgr(); - std::vector overlayModuleInfos; - ErrCode resCode = overlayDataMgr.GetAllOverlayModuleInfo(TEST_BUNDLE_NAME, overlayModuleInfos, USERID); - EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); - ResetDataMgr(); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_1100 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1100, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo oldInfo; - - ClearDataMgr(); - OverlayModuleInfo overlayModuleInfo; - ErrCode resCode = overlayDataMgr.GetOverlayModuleInfo( - TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, USERID); - EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); - ResetDataMgr(); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_1200 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1200, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - - ClearDataMgr(); - std::vector overlayBundleInfo; - ErrCode resCode = overlayDataMgr.GetOverlayBundleInfoForTarget( - TEST_MODULE_NAME, overlayBundleInfo, USERID); - EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); - ResetDataMgr(); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_1300 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1300, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - - ClearDataMgr(); - std::vector overlayModuleInfos; - ErrCode resCode = overlayDataMgr.GetOverlayModuleInfoForTarget( - TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfos, USERID); - EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); - ResetDataMgr(); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_1400 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1400, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - - ClearDataMgr(); - OverlayModuleInfo overlayModuleInfo; - ErrCode resCode = overlayDataMgr.ObtainOverlayModuleState(overlayModuleInfo, USERID); - EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); - ResetDataMgr(); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_1500 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1500, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - - ClearDataMgr(); - bool isEnabled = false; - ErrCode resCode = overlayDataMgr.SetOverlayEnabled(TEST_BUNDLE_NAME, TEST_MODULE_NAME, isEnabled, USERID); - EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); - ResetDataMgr(); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_1600 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1600, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - - ClearDataMgr(); - std::string resString = overlayDataMgr.GetCallingBundleName(); - EXPECT_EQ(resString.empty(), true); - ResetDataMgr(); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_1700 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1700, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo oldInfo; - oldInfo.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); - EXPECT_EQ(oldInfo.GetOverlayType(), OVERLAY_EXTERNAL_BUNDLE); - - ClearDataMgr(); - EXPECT_EQ(bundleMgrService_->dataMgr_, nullptr); - BuildInternalOverlayConnection(TEST_MODULE_NAME, oldInfo, USERID); - ResetDataMgr(); - EXPECT_NE(bundleMgrService_->dataMgr_, nullptr); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_1900 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1900, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo targetInnerBundleInfo; - - ClearDataMgr(); - EXPECT_EQ(bundleMgrService_->dataMgr_, nullptr); - RemoveOverlayBundleInfo(TEST_MODULE_NAME, targetInnerBundleInfo); - ResetDataMgr(); - EXPECT_NE(bundleMgrService_->dataMgr_, nullptr); -} - -/** - * @tc.number: TestOverlayByDataMgrFalse_2300 - * @tc.name: test TestOverlayByDataMgrFalse. - * @tc.desc: 1.test overlay by dataMgr is nullptr. - * 2.system run normally. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_2300, Function | SmallTest | Level0) -{ - OverlayDataMgr overlayDataMgr; - InnerBundleInfo newInfo; - InnerBundleUserInfo userInfo; - - ClearDataMgr(); - EXPECT_EQ(bundleMgrService_->dataMgr_, nullptr); - AddOverlayModuleStates(newInfo, userInfo); - ResetDataMgr(); - EXPECT_NE(bundleMgrService_->dataMgr_, nullptr); -} - -/** - * @tc.number: CheckAppLabel_0010 - * @tc.name: test CheckAppLabel - * @tc.desc: 1.Test the CheckAppLabel -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckAppLabel_0010, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - InnerBundleInfo oldInfo; - InnerBundleInfo newInfo; - oldInfo.baseApplicationInfo_->targetBundleName = TEST_MODULE_NAME; - ErrCode res = installer.CheckAppLabel(oldInfo, newInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_TARGET_BUNDLE_NAME_NOT_SAME); -} - -/** - * @tc.number: CheckAppLabel_0020 - * @tc.name: test CheckAppLabel - * @tc.desc: 1.Test the CheckAppLabel -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckAppLabel_0020, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - InnerBundleInfo oldInfo; - InnerBundleInfo newInfo; - oldInfo.baseApplicationInfo_->targetPriority = FOUR; - ErrCode res = installer.CheckAppLabel(oldInfo, newInfo); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_TARGET_PRIORITY_NOT_SAME); -} - -/** - * @tc.number: CheckOverlayInstallation_0010 - * @tc.name: test CheckOverlayInstallation - * @tc.desc: 1.Test the CheckOverlayInstallation -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayInstallation_0010, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - std::unordered_map newInfos; - InnerBundleInfo newInfo; - newInfo.SetOverlayState(NON_OVERLAY_TYPE); - newInfos.try_emplace(TEST_MODULE_NAME, newInfo); - ErrCode res = installer.CheckOverlayInstallation(newInfos, USERID); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: CheckOverlayInstallation_0020 - * @tc.name: test CheckOverlayInstallation - * @tc.desc: 1.Test the CheckOverlayInstallation -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayInstallation_0020, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - std::unordered_map newInfos; - InnerBundleInfo info1; - info1.SetOverlayType(OVERLAY_INTERNAL_BUNDLE); - newInfos.try_emplace(TEST_MODULE_NAME, info1); - ErrCode res = installer.CheckOverlayInstallation(newInfos, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_HAP_TYPE); -} - -/** - * @tc.number: CheckOverlayInstallation_0030 - * @tc.name: test CheckOverlayInstallation - * @tc.desc: 1.Test the CheckOverlayInstallation -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayInstallation_0030, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - std::unordered_map newInfos; - InnerBundleInfo info1; - info1.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); - newInfos.try_emplace(TEST_MODULE_NAME, info1); - ErrCode res = installer.CheckOverlayInstallation(newInfos, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_HAP_TYPE); -} - -/** - * @tc.number: GetNotifyType_0010 - * @tc.name: test GetNotifyType - * @tc.desc: 1.Test the GetNotifyType -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, GetNotifyType_0010, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - installer.isAppExist_ = true; - installer.hasInstalledInUser_ = true; - installer.overlayType_ = OVERLAY_EXTERNAL_BUNDLE; - NotifyType res = installer.GetNotifyType(); - EXPECT_EQ(res, NotifyType::OVERLAY_UPDATE); -} - -/** - * @tc.number: GetNotifyType_0020 - * @tc.name: test GetNotifyType - * @tc.desc: 1.Test the GetNotifyType -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, GetNotifyType_0020, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - installer.isAppExist_ = true; - installer.hasInstalledInUser_ = true; - installer.overlayType_ = NON_OVERLAY_TYPE; - NotifyType res = installer.GetNotifyType(); - EXPECT_EQ(res, NotifyType::UPDATE); -} - -/** - * @tc.number: GetNotifyType_0030 - * @tc.name: test GetNotifyType - * @tc.desc: 1.Test the GetNotifyType -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, GetNotifyType_0030, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - installer.isAppExist_ = false; - installer.hasInstalledInUser_ = true; - installer.overlayType_ = OVERLAY_EXTERNAL_BUNDLE; - NotifyType res = installer.GetNotifyType(); - EXPECT_EQ(res, NotifyType::OVERLAY_INSTALL); -} - -/** - * @tc.number: GetNotifyType_0040 - * @tc.name: test GetNotifyType - * @tc.desc: 1.Test the GetNotifyType -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, GetNotifyType_0040, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - installer.isAppExist_ = true; - installer.hasInstalledInUser_ = false; - installer.overlayType_ = NON_OVERLAY_TYPE; - NotifyType res = installer.GetNotifyType(); - EXPECT_EQ(res, NotifyType::INSTALL); -} - -/** - * @tc.number: CheckOverlayUpdate_0010 - * @tc.name: test CheckOverlayUpdate - * @tc.desc: 1.Test the CheckOverlayUpdate -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayUpdate_0010, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - InnerBundleInfo oldInfo; - InnerBundleInfo newInfo; - newInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); - oldInfo.SetOverlayType(OverlayType::OVERLAY_INTERNAL_BUNDLE); - ErrCode res = installer.CheckOverlayUpdate(oldInfo, newInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_OVERLAY_TYPE_NOT_SAME); -} - -/** - * @tc.number: CheckOverlayUpdate_0030 - * @tc.name: test CheckOverlayUpdate - * @tc.desc: 1.Test the CheckOverlayUpdate -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayUpdate_0030, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - InnerBundleInfo oldInfo; - InnerBundleInfo newInfo; - oldInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); - newInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); - newInfo.currentPackage_ = TEST_PACK_AGE; - ErrCode res = installer.CheckOverlayUpdate(oldInfo, newInfo, USERID); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: CheckOverlayUpdate_0040 - * @tc.name: test CheckOverlayUpdate - * @tc.desc: 1.Test the CheckOverlayUpdate -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayUpdate_0040, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - InnerBundleInfo oldInfo; - InnerBundleInfo newInfo; - oldInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); - newInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); - - newInfo.currentPackage_ = TEST_PACK_AGE; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.targetModuleName = ""; - oldInfo.innerModuleInfos_[TEST_PACK_AGE] = innerModuleInfo; - ErrCode res = installer.CheckOverlayUpdate(oldInfo, newInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_OVERLAY_TYPE_NOT_SAME); -} - -/** - * @tc.number: CheckOverlayUpdate_0050 - * @tc.name: test CheckOverlayUpdate - * @tc.desc: 1.Test the CheckOverlayUpdate -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayUpdate_0050, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - InnerBundleInfo oldInfo; - InnerBundleInfo newInfo; - oldInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); - newInfo.SetOverlayType(OverlayType::NON_OVERLAY_TYPE); - - newInfo.currentPackage_ = TEST_PACK_AGE; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.targetModuleName = "targetModuleName"; - oldInfo.innerModuleInfos_[TEST_PACK_AGE] = innerModuleInfo; - ErrCode res = installer.CheckOverlayUpdate(oldInfo, newInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_OVERLAY_TYPE_NOT_SAME); -} - -/** - * @tc.number: CheckOverlayUpdate_0060 - * @tc.name: test CheckOverlayUpdate - * @tc.desc: 1.Test the CheckOverlayUpdate -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayUpdate_0060, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - InnerBundleInfo oldInfo; - InnerBundleInfo newInfo; - oldInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); - newInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); - - newInfo.currentPackage_ = TEST_PACK_AGE; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.targetModuleName = "targetModuleName"; - oldInfo.innerModuleInfos_[TEST_PACK_AGE] = innerModuleInfo; - ErrCode res = installer.CheckOverlayUpdate(oldInfo, newInfo, USERID); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: CopyHapsToSecurityDir_0010 - * @tc.name: test CopyHapsToSecurityDir - * @tc.desc: 1.Test the CopyHapsToSecurityDir -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, CopyHapsToSecurityDir_0010, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - InstallParam installParam; - installParam.withCopyHaps = true; - std::vector bundlePaths; - bundlePaths.push_back("data/test/test"); - ErrCode res = installer.CopyHapsToSecurityDir(installParam, bundlePaths); - EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_DISK_MEM_INSUFFICIENT); -} - -/** - * @tc.number: CopyHapsToSecurityDir_0020 - * @tc.name: test CopyHapsToSecurityDir - * @tc.desc: 1.Test the CopyHapsToSecurityDir -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, CopyHapsToSecurityDir_0020, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - InstallParam installParam; - installParam.withCopyHaps = true; - std::vector bundlePaths; - ErrCode res = installer.CopyHapsToSecurityDir(installParam, bundlePaths); - EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: FindSignatureFileDir_0010 - * @tc.name: test FindSignatureFileDir - * @tc.desc: 1.Test the FindSignatureFileDir -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, FindSignatureFileDir_0010, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - std::string signatureFileDir; - - installer.verifyCodeParams_.emplace(TEST_MODULE_NAME, TEST_MODULE_NAME); - ErrCode res = installer.FindSignatureFileDir(TEST_MODULE_NAME + "1", signatureFileDir); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_INSTALL_CODE_SIGNATURE_FAILED); -} - -/** - * @tc.number: FindSignatureFileDir_0020 - * @tc.name: test FindSignatureFileDir - * @tc.desc: 1.Test the FindSignatureFileDir -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, FindSignatureFileDir_0020, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - std::string signatureFileDir; - - installer.verifyCodeParams_.emplace(TEST_MODULE_NAME, TEST_MODULE_NAME); - ErrCode res = installer.FindSignatureFileDir(TEST_MODULE_NAME, signatureFileDir); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_INSTALL_CODE_SIGNATURE_FILE_IS_INVALID); -} - -/** - * @tc.number: FindSignatureFileDir_0030 - * @tc.name: test FindSignatureFileDir - * @tc.desc: 1.Test the FindSignatureFileDir -*/ -HWTEST_F(BmsBundleOverlayCheckerTest, FindSignatureFileDir_0030, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - std::string signatureFileDir = "testModuleName.sig"; - - installer.verifyCodeParams_.emplace(TEST_MODULE_NAME, signatureFileDir); - ErrCode res = installer.FindSignatureFileDir(TEST_MODULE_NAME, signatureFileDir); - EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_DISK_MEM_INSUFFICIENT); -} +/* + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#define private public + +#include + +#include "appexecfwk_errors.h" +#include "bundle_overlay_data_manager.h" +#include "bundle_overlay_install_checker.h" +#include "bundle_overlay_manager.h" +#include "bundle_mgr_service.h" + +#include + +using namespace testing::ext; +using namespace OHOS::AppExecFwk; +using OHOS::DelayedSingleton; + +namespace OHOS { +namespace { +const std::string TEST_MODULE_NAME = "testModuleName"; +const std::string TEST_MODULE_NAME_SECOND = "testModuleNameSecond"; +const std::string TARGET_MODULE_NAME = "targetModuleName"; +const std::string OTHER_TARGET_MODULE_NAME = "targetModuleNameTest"; +const std::string TARGET_BUNDLE_NAME = "targetBundleName"; +const std::string TEST_BUNDLE_NAME = "testBundleName"; +const std::string TEST_BUNDLE_NAME2 = "testBundleName2"; +const std::string TEST_PATH_FIRST = "testPath1"; +const std::string TEST_PATH_SECOND = "testPath2"; +const std::string TEST_PACK_AGE = "modulePackage"; +const std::string NO_EXIST = "noExist"; +const std::string BUNDLE_NAME = "oho.test.bundleName"; +const std::string SHARED_HAP_TYPE = "shared"; +const std::string FEATURE_HAP_TYPE = "feature"; +const std::string SHARED_TYPE = "shared"; +const int32_t INVALID_TARGET_PRIORITY_FIRST = 0; +const int32_t INVALID_TARGET_PRIORITY_SECOND = 101; +const int32_t DEFAULT_TARGET_PRIORITY_SECOND = 1; +const int32_t TEST_VERSION_CODE = 1000000; +const int32_t LOWER_TEST_VERSION_CODE = 999999; +const int32_t HIGHER_TEST_VERSION_CODE = 1000001; +const int32_t USERID = 100; +const int32_t NOT_EXIST_USERID = -5; +const int32_t FOUR = 4; +const int32_t DEFAULT_OVERLAY_BUNDLE_INFO = 0; +const int32_t WAIT_TIME = 5; // init mocked bms +} // namespace + +class BmsBundleOverlayCheckerTest : public testing::Test { +public: + BmsBundleOverlayCheckerTest(); + ~BmsBundleOverlayCheckerTest(); + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); + void AddInnerBundleInfo(); + void UninstallBundleInfo(); + void BuildInternalOverlayConnection(const std::string &moduleName, InnerBundleInfo &oldInfo, int32_t userId); + void RemoveOverlayBundleInfo(const std::string &targetBundleName, InnerBundleInfo &targetInnerBundleInfo); + void AddOverlayModuleStates(const InnerBundleInfo &innerBundleInfo, InnerBundleUserInfo &userInfo); + void ClearDataMgr(); + void ResetDataMgr(); + + const std::shared_ptr GetBundleDataMgr() const; + const std::shared_ptr GetBundleOverlayChecker() const; + +private: + std::shared_ptr overlayChecker_ = std::make_shared(); + static std::shared_ptr bundleMgrService_; +}; + +std::shared_ptr BmsBundleOverlayCheckerTest::bundleMgrService_ = + DelayedSingleton::GetInstance(); + +BmsBundleOverlayCheckerTest::BmsBundleOverlayCheckerTest() +{} + +BmsBundleOverlayCheckerTest::~BmsBundleOverlayCheckerTest() +{} + +void BmsBundleOverlayCheckerTest::SetUpTestCase() +{} + +void BmsBundleOverlayCheckerTest::TearDownTestCase() +{ + bundleMgrService_->OnStop(); +} + +void BmsBundleOverlayCheckerTest::SetUp() +{ + if (!bundleMgrService_->IsServiceReady()) { + bundleMgrService_->OnStart(); + std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME)); + } +} + +void BmsBundleOverlayCheckerTest::BuildInternalOverlayConnection( + const std::string &moduleName, InnerBundleInfo &oldInfo, int32_t userId) +{ + OverlayDataMgr overlayDataMgr; + return overlayDataMgr.BuildInternalOverlayConnection(TEST_MODULE_NAME, oldInfo, USERID); +} + +void BmsBundleOverlayCheckerTest::RemoveOverlayBundleInfo( + const std::string &targetBundleName, InnerBundleInfo &targetInnerBundleInfo) +{ + OverlayDataMgr overlayDataMgr; + return overlayDataMgr.RemoveOverlayBundleInfo(TEST_MODULE_NAME, targetInnerBundleInfo); +} + +void BmsBundleOverlayCheckerTest::AddOverlayModuleStates( + const InnerBundleInfo &innerBundleInfo, InnerBundleUserInfo &userInfo) +{ + OverlayDataMgr overlayDataMgr; + return overlayDataMgr.AddOverlayModuleStates(innerBundleInfo, userInfo); +} + +void BmsBundleOverlayCheckerTest::ClearDataMgr() +{ + bundleMgrService_->dataMgr_ = nullptr; +} + +void BmsBundleOverlayCheckerTest::ResetDataMgr() +{ + bundleMgrService_->dataMgr_ = std::make_shared(); + EXPECT_NE(bundleMgrService_->dataMgr_, nullptr); +} + +void BmsBundleOverlayCheckerTest::TearDown() +{} + +void BmsBundleOverlayCheckerTest::AddInnerBundleInfo() +{ + // construct innerBundleInfo + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.name = TEST_MODULE_NAME; + innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; + innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + ApplicationInfo applicationInfo; + applicationInfo.bundleName = TEST_BUNDLE_NAME; + applicationInfo.targetBundleName = TEST_BUNDLE_NAME; + innerBundleInfo.SetBaseApplicationInfo(applicationInfo); + + // construct target module + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + + InnerBundleInfo oldInfo; + InnerModuleInfo targetModuleInfo; + targetModuleInfo.name = TARGET_MODULE_NAME; + targetModuleInfo.targetModuleName = OTHER_TARGET_MODULE_NAME; + targetModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; + ApplicationInfo targetApplicationInfo; + targetApplicationInfo.bundleName = TEST_BUNDLE_NAME; + + oldInfo.InsertInnerModuleInfo(TARGET_MODULE_NAME, targetModuleInfo); + oldInfo.SetBaseApplicationInfo(targetApplicationInfo); + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); + dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, oldInfo); +} + +void BmsBundleOverlayCheckerTest::UninstallBundleInfo() +{ + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + bool startRet = dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_START); + bool finishRet = dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_SUCCESS); + + EXPECT_TRUE(startRet); + EXPECT_TRUE(finishRet); +} + +const std::shared_ptr BmsBundleOverlayCheckerTest::GetBundleDataMgr() const +{ + return bundleMgrService_->GetDataMgr(); +} + +const std::shared_ptr BmsBundleOverlayCheckerTest::GetBundleOverlayChecker() const +{ + return overlayChecker_; +} + +/** + * @tc.number: OverlayCheckerTest_0100 + * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. + * @tc.desc: 1.the internal overlay hap is entry type. + * 2.check failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0100, Function | SmallTest | Level0) +{ + // construct innerBundleInfo + InnerModuleInfo innerModuleInfo; + Distro distro; + distro.moduleType = FEATURE_HAP_TYPE; + innerModuleInfo.distro = distro; + innerModuleInfo.name = TEST_MODULE_NAME; + InnerBundleInfo innerBundleInfo; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + std::unordered_map newInfos; + + auto overlayChecker = GetBundleOverlayChecker(); + EXPECT_NE(overlayChecker, nullptr); + auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_HAP_TYPE); +} + +/** + * @tc.number: OverlayCheckerTest_0200 + * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. + * @tc.desc: 1.the internal overlay bundle is service. + * 2.check failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0200, Function | SmallTest | Level0) +{ + // construct innerBundleInfo + InnerModuleInfo innerModuleInfo; + innerModuleInfo.name = TEST_MODULE_NAME; + Distro distro; + distro.moduleType = SHARED_HAP_TYPE; + innerModuleInfo.distro = distro; + InnerBundleInfo innerBundleInfo; + innerBundleInfo.SetEntryInstallationFree(true); + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + std::unordered_map newInfos; + + auto overlayChecker = GetBundleOverlayChecker(); + EXPECT_NE(overlayChecker, nullptr); + auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_BUNDLE_TYPE); +} + +/** + * @tc.number: OverlayCheckerTest_0400 + * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. + * @tc.desc: 1.target priority of internal overlay hap is invalid. + * 2.check failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0400, Function | SmallTest | Level0) +{ + // construct innerBundleInfo + InnerModuleInfo innerModuleInfo; + innerModuleInfo.name = TEST_MODULE_NAME; + Distro distro; + distro.moduleType = SHARED_HAP_TYPE; + innerModuleInfo.distro = distro; + innerModuleInfo.targetPriority = INVALID_TARGET_PRIORITY_FIRST; + InnerBundleInfo innerBundleInfo; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + std::unordered_map newInfos; + + auto overlayChecker = GetBundleOverlayChecker(); + EXPECT_NE(overlayChecker, nullptr); + auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_PRIORITY); +} + +/** + * @tc.number: OverlayCheckerTest_0500 + * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. + * @tc.desc: 1.target priority of internal overlay hap is invalid. + * 2.check failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0500, Function | SmallTest | Level0) +{ + // construct innerBundleInfo + InnerModuleInfo innerModuleInfo; + innerModuleInfo.name = TEST_MODULE_NAME; + Distro distro; + distro.moduleType = SHARED_HAP_TYPE; + innerModuleInfo.distro = distro; + innerModuleInfo.targetPriority = INVALID_TARGET_PRIORITY_SECOND; + InnerBundleInfo innerBundleInfo; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + std::unordered_map newInfos; + auto overlayChecker = GetBundleOverlayChecker(); + EXPECT_NE(overlayChecker, nullptr); + auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_PRIORITY); +} + +/** + * @tc.number: OverlayCheckerTest_0600 + * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. + * @tc.desc: 1.target module name of the internal overlay is same as the module name. + * 2.check failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0600, Function | SmallTest | Level0) +{ + // construct innerBundleInfo + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.name = TEST_MODULE_NAME; + innerModuleInfo.targetModuleName = TEST_MODULE_NAME; + innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; + Distro distro; + distro.moduleType = SHARED_HAP_TYPE; + innerModuleInfo.distro = distro; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + std::unordered_map newInfos; + + auto overlayChecker = GetBundleOverlayChecker(); + EXPECT_NE(overlayChecker, nullptr); + auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_MODULE_NAME); +} + +/** + * @tc.number: OverlayCheckerTest_0700 + * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. + * @tc.desc: 1.target module is overlay module. + * 2.check failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0700, Function | SmallTest | Level0) +{ + // construct innerBundleInfo + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.name = TEST_MODULE_NAME; + innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; + innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; + Distro distro; + distro.moduleType = SHARED_HAP_TYPE; + innerModuleInfo.distro = distro; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + ApplicationInfo applicationInfo; + applicationInfo.bundleName = TEST_BUNDLE_NAME; + innerBundleInfo.SetBaseApplicationInfo(applicationInfo); + + // construct target module + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + + InnerBundleInfo oldInfo; + InnerModuleInfo targetModuleInfo; + targetModuleInfo.name = TARGET_MODULE_NAME; + targetModuleInfo.targetModuleName = OTHER_TARGET_MODULE_NAME; + targetModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; + Distro targetDistro; + targetDistro.moduleType = SHARED_HAP_TYPE; + innerModuleInfo.distro = targetDistro; + ApplicationInfo targetApplicationInfo; + targetApplicationInfo.bundleName = TEST_BUNDLE_NAME; + + oldInfo.InsertInnerModuleInfo(TARGET_MODULE_NAME, targetModuleInfo); + oldInfo.SetBaseApplicationInfo(targetApplicationInfo); + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); + dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, oldInfo); + std::unordered_map newInfos; + + auto overlayChecker = GetBundleOverlayChecker(); + EXPECT_NE(overlayChecker, nullptr); + auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_TARGET_MODULE_IS_OVERLAY_MODULE); + + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_START); + bool ret = dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_SUCCESS); + EXPECT_TRUE(ret); +} + +/** + * @tc.number: OverlayCheckerTest_0800 + * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. + * @tc.desc: 1.install overlay hap and non-overlay hap simultaneously. + * 2.check successfully. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0800, Function | SmallTest | Level0) +{ + // construct overlay innerBundleInfo + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.name = TEST_MODULE_NAME; + innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; + innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; + Distro distro; + distro.moduleType = SHARED_HAP_TYPE; + innerModuleInfo.distro = distro; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + + // construct non-overlay innerBundleInfo + InnerBundleInfo nonOverlayBundleInfo; + InnerModuleInfo nonInnerModuleInfo; + nonInnerModuleInfo.name = TEST_MODULE_NAME_SECOND; + nonOverlayBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME_SECOND); + nonOverlayBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME_SECOND, nonInnerModuleInfo); + + std::unordered_map newInfos; + newInfos.emplace(TEST_PATH_FIRST, innerBundleInfo); + newInfos.emplace(TEST_PATH_SECOND, nonOverlayBundleInfo); + + auto overlayChecker = GetBundleOverlayChecker(); + EXPECT_NE(overlayChecker, nullptr); + auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: OverlayCheckerTest_0900 + * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. + * @tc.desc: 1.install internal overlay hap. + * 2.the version code of overlay hap is larger than non-overlay module. + * 3.check failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0900, Function | SmallTest | Level0) +{ + // construct overlay innerBundleInfo + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.name = TEST_MODULE_NAME; + innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; + innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; + Distro distro; + distro.moduleType = SHARED_HAP_TYPE; + innerModuleInfo.distro = distro; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + BundleInfo bundleInfo; + bundleInfo.versionCode = HIGHER_TEST_VERSION_CODE; + innerBundleInfo.SetBaseBundleInfo(bundleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + ApplicationInfo applicationInfo; + applicationInfo.bundleName = TEST_BUNDLE_NAME; + innerBundleInfo.SetBaseApplicationInfo(applicationInfo); + std::unordered_map newInfos; + + // construct old innerBundleInfo + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + + InnerBundleInfo oldInfo; + InnerModuleInfo oldInnerModuleInfo; + oldInnerModuleInfo.name = TEST_MODULE_NAME_SECOND; + oldInfo.InsertInnerModuleInfo(TEST_MODULE_NAME_SECOND, oldInnerModuleInfo); + BundleInfo oldBundleInfo; + oldBundleInfo.versionCode = TEST_VERSION_CODE; + oldInfo.SetBaseBundleInfo(oldBundleInfo); + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); + dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, oldInfo); + + auto overlayChecker = GetBundleOverlayChecker(); + EXPECT_NE(overlayChecker, nullptr); + auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INCONSISTENT_VERSION_CODE); + + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_START); + bool ret = dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_SUCCESS); + EXPECT_TRUE(ret); +} + +/** + * @tc.number: BundleOverlayManagerTest_0100 + * @tc.name: check param is empty + * @tc.desc: 1.Test BundleOverlayManager + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, BundleOverlayManagerTest_0100, Function | SmallTest | Level0) +{ + BundleOverlayManager manager; + std::string bundleName = ""; + bool ret = manager.IsExistedNonOverlayHap(bundleName); + EXPECT_EQ(ret, false); + InnerBundleInfo innerBundleInfo; + ret = manager.GetInnerBundleInfo(bundleName, innerBundleInfo); + EXPECT_EQ(ret, false); + + int32_t userId = Constants::INVALID_USERID; + std::vector overlayModuleInfos; + auto code = manager.GetAllOverlayModuleInfo(bundleName, overlayModuleInfos, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + code = manager.GetAllOverlayModuleInfo("com.ohos.test", overlayModuleInfos, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + + std::string moduleName = ""; + OverlayModuleInfo overlayModuleInfo; + code = manager.GetOverlayModuleInfo(bundleName, moduleName, overlayModuleInfo, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + code = manager.GetOverlayModuleInfo("com.ohos.test", moduleName, overlayModuleInfo, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + code = manager.GetOverlayModuleInfo("com.ohos.test", "entry", overlayModuleInfo, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + + std::string targetBundleName = ""; + std::vector overlayBundleInfo; + code = manager.GetOverlayBundleInfoForTarget(targetBundleName, overlayBundleInfo, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + code = manager.GetOverlayBundleInfoForTarget("target", overlayBundleInfo, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + + code = manager.GetOverlayModuleInfoForTarget(targetBundleName, "", overlayModuleInfos, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + code = manager.GetOverlayModuleInfoForTarget("target", "", overlayModuleInfos, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + + userId = Constants::DEFAULT_USERID; + code = manager.GetAllOverlayModuleInfo("com.ohos.test", overlayModuleInfos, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); + code = manager.GetOverlayModuleInfo("com.ohos.test", "entry", overlayModuleInfo, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); +} + +/** + * @tc.number: CheckInternalBundle_0100 + * @tc.name: check hap type failed + * @tc.desc: 1.Test CheckInternalBundle + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckInternalBundle_0100, Function | SmallTest | Level0) +{ + BundleOverlayInstallChecker checker; + std::unordered_map newInfos; + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.isEntry = true; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + auto code = checker.CheckInternalBundle(newInfos, innerBundleInfo); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_HAP_TYPE); + innerModuleInfo.isEntry = false; + code = checker.CheckInternalBundle(newInfos, innerBundleInfo); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_HAP_TYPE); + + innerBundleInfo.SetEntryInstallationFree(true); + code = checker.CheckInternalBundle(newInfos, innerBundleInfo); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_HAP_TYPE); +} + +/** + * @tc.number: CheckInternalBundle_0200 + * @tc.name: check module target priority range + * @tc.desc: 1.Test CheckInternalBundle + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckInternalBundle_0200, Function | SmallTest | Level0) +{ + BundleOverlayInstallChecker checker; + std::unordered_map newInfos; + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + Distro distro; + distro.moduleType = SHARED_HAP_TYPE; + innerModuleInfo.distro = distro; + innerModuleInfo.targetPriority = Constants::OVERLAY_MINIMUM_PRIORITY - 1; + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + auto code = checker.CheckInternalBundle(newInfos, innerBundleInfo); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_PRIORITY); +} + +/** + * @tc.number: CheckInternalBundle_0300 + * @tc.name: check module target priority range + * @tc.desc: 1.Test CheckInternalBundle + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckInternalBundle_0300, Function | SmallTest | Level0) +{ + BundleOverlayInstallChecker checker; + std::unordered_map newInfos; + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + Distro distro; + distro.moduleType = SHARED_HAP_TYPE; + innerModuleInfo.distro = distro; + innerModuleInfo.targetPriority = Constants::OVERLAY_MINIMUM_PRIORITY + 1; + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + innerModuleInfo.targetModuleName = TEST_MODULE_NAME; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + + auto code = checker.CheckInternalBundle(newInfos, innerBundleInfo); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_MODULE_NAME); +} + +/** + * @tc.number: CheckExternalBundle_0100 + * @tc.name: check bundle priority + * @tc.desc: 1.Test CheckExternalBundle + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckExternalBundle_0100, Function | SmallTest | Level0) +{ + BundleOverlayInstallChecker checker; + InnerBundleInfo innerBundleInfo; + int32_t userId = Constants::INVALID_USERID; + BundleInfo bundleInfo; + bundleInfo.entryInstallationFree = true; + innerBundleInfo.SetBaseBundleInfo(bundleInfo); + auto code = checker.CheckExternalBundle(innerBundleInfo, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_BUNDLE_TYPE); + + bundleInfo.entryInstallationFree = false; + innerBundleInfo.SetBaseBundleInfo(bundleInfo); + ApplicationInfo applicationInfo; + applicationInfo.targetPriority = Constants::OVERLAY_MINIMUM_PRIORITY - 1; + innerBundleInfo.SetBaseApplicationInfo(applicationInfo); + InnerModuleInfo innerModuleInfo; + Distro distro; + distro.moduleType = SHARED_HAP_TYPE; + innerModuleInfo.distro = distro; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + code = checker.CheckExternalBundle(innerBundleInfo, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_PRIORITY); + + applicationInfo.targetPriority = Constants::OVERLAY_MAXIMUM_PRIORITY + 1; + innerBundleInfo.SetBaseApplicationInfo(applicationInfo); + code = checker.CheckExternalBundle(innerBundleInfo, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_PRIORITY); +} + +/** + * @tc.number: CheckExternalBundle_0200 + * @tc.name: check bundle priority + * @tc.desc: 1.Test CheckExternalBundle + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckExternalBundle_0200, Function | SmallTest | Level0) +{ + BundleOverlayInstallChecker checker; + InnerBundleInfo innerBundleInfo; + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + int32_t userId = Constants::INVALID_USERID; + ApplicationInfo applicationInfo; + applicationInfo.bundleName = TEST_BUNDLE_NAME; + applicationInfo.targetBundleName = TEST_BUNDLE_NAME; + applicationInfo.targetPriority = Constants::OVERLAY_MINIMUM_PRIORITY + 1; + innerBundleInfo.SetBaseApplicationInfo(applicationInfo); + InnerModuleInfo innerModuleInfo; + innerModuleInfo.targetPriority = Constants::OVERLAY_MINIMUM_PRIORITY + 1; + Distro distro; + distro.moduleType = SHARED_HAP_TYPE; + innerModuleInfo.distro = distro; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + auto code = checker.CheckExternalBundle(innerBundleInfo, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_BUNDLE_NAME_SAME_WITH_TARGET_BUNDLE_NAME); + applicationInfo.bundleName = ""; + innerBundleInfo.SetBaseApplicationInfo(applicationInfo); + code = checker.CheckExternalBundle(innerBundleInfo, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_NO_SYSTEM_APPLICATION_FOR_EXTERNAL_OVERLAY); + + innerBundleInfo.SetIsPreInstallApp(true); + code = checker.CheckExternalBundle(innerBundleInfo, userId); + EXPECT_EQ(code, ERR_OK); + + innerBundleInfo.SetCurrentModulePackage(SHARED_TYPE); + code = checker.CheckExternalBundle(innerBundleInfo, userId); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_HAP_TYPE); +} + +/** + * @tc.number: OverlayDataMgr_0100 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of UpdateOverlayInfo. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0100, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + InnerBundleInfo targetInnerBundleInfo; + + newInfo.SetOverlayType(OverlayType::OVERLAY_INTERNAL_BUNDLE); + ErrCode res = overlayDataMgr.UpdateOverlayInfo(newInfo, oldInfo, targetInnerBundleInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); + newInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); + res = overlayDataMgr.UpdateOverlayInfo(newInfo, oldInfo, targetInnerBundleInfo); + EXPECT_EQ(res, ERR_OK); + newInfo.SetOverlayType(OverlayType::NON_OVERLAY_TYPE); + res = overlayDataMgr.UpdateOverlayInfo(newInfo, oldInfo, targetInnerBundleInfo); + EXPECT_EQ(res, ERR_OK); + + newInfo.SetOverlayType(FOUR); + res = overlayDataMgr.UpdateOverlayInfo(newInfo, oldInfo, targetInnerBundleInfo); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: OverlayDataMgr_0200 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of IsExistedNonOverlayHap. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0200, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + bool res = overlayDataMgr.IsExistedNonOverlayHap(""); + EXPECT_EQ(res, false); + res = overlayDataMgr.IsExistedNonOverlayHap("wrong"); + EXPECT_EQ(res, false); +} + +/** + * @tc.number: OverlayDataMgr_0300 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of UpdateInternalOverlayInfo. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0300, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + ErrCode res = overlayDataMgr.UpdateInternalOverlayInfo(newInfo, oldInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); + std::map innerModuleInfos; + InnerModuleInfo moduleInfo; + moduleInfo.moduleName = TEST_PACK_AGE; + moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; + innerModuleInfos[TEST_PACK_AGE] = moduleInfo; + newInfo.AddInnerModuleInfo(innerModuleInfos); + res = overlayDataMgr.UpdateInternalOverlayInfo(newInfo, oldInfo); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: OverlayDataMgr_0400 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of UpdateExternalOverlayInfo. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0400, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo innerBundleInfo; + InnerBundleInfo oldInfo; + InnerBundleInfo targetInnerBundleInfo; + + ErrCode res = overlayDataMgr.UpdateExternalOverlayInfo(innerBundleInfo, oldInfo, targetInnerBundleInfo); + EXPECT_EQ(res, ERR_OK); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + ApplicationInfo applicationInfo; + applicationInfo.bundleName = TEST_BUNDLE_NAME; + innerBundleInfo.SetBaseApplicationInfo(applicationInfo); + + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + + ApplicationInfo targetApplicationInfo; + targetApplicationInfo.bundleName = TEST_BUNDLE_NAME; + + oldInfo.SetBaseApplicationInfo(targetApplicationInfo); + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); + dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, oldInfo); + innerBundleInfo.SetTargetBundleName(TEST_BUNDLE_NAME); + res = overlayDataMgr.UpdateExternalOverlayInfo(innerBundleInfo, oldInfo, oldInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); + + InnerModuleInfo moduleInfo; + std::map innerModuleInfos; + moduleInfo.moduleName = "moduleName"; + moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; + innerModuleInfos[TEST_PACK_AGE] = moduleInfo; + innerBundleInfo.AddInnerModuleInfo(innerModuleInfos); + res = overlayDataMgr.UpdateExternalOverlayInfo(innerBundleInfo, oldInfo, oldInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); + + innerBundleInfo.SetUserId(Constants::NOT_EXIST_USERID); + res = overlayDataMgr.UpdateExternalOverlayInfo(innerBundleInfo, oldInfo, oldInfo); + EXPECT_EQ(res, ERR_OK); + UninstallBundleInfo(); +} + +/** + * @tc.number: OverlayDataMgr_0500 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of UpdateExternalOverlayInfo. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0500, Function | SmallTest | Level0) +{ + AddInnerBundleInfo(); + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + InnerBundleInfo targetInnerBundleInfo; + + OverlayDataMgr overlayDataMgr; + ErrCode res = overlayDataMgr.UpdateExternalOverlayInfo(newInfo, oldInfo, targetInnerBundleInfo); + EXPECT_EQ(res, ERR_OK); + UninstallBundleInfo(); +} + +#ifdef BUNDLE_FRAMEWORK_OVERLAY_INSTALLATION +/** + * @tc.number: OverlayDataMgr_0600 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of BuildOverlayConnection and BuildOverlayConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0600, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + const auto &moduleInfos = newInfo.GetInnerModuleInfos(); + std::string moduleName = (moduleInfos.begin()->second).moduleName; + overlayDataMgr.BuildInternalOverlayConnection(moduleName, oldInfo, newInfo.GetUserId()); + EXPECT_EQ(oldInfo.FetchInnerModuleInfos().empty(), true); + + oldInfo.SetOverlayState(OverlayType::OVERLAY_INTERNAL_BUNDLE); + overlayDataMgr.BuildInternalOverlayConnection(moduleName, oldInfo, newInfo.GetUserId()); + EXPECT_EQ(oldInfo.FetchInnerModuleInfos().empty(), true); +} + +/** + * @tc.number: OverlayDataMgr_0700 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of BuildOverlayConnection and BuildOverlayConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0700, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo oldInfo; + oldInfo.SetIsPreInstallApp(false); + ApplicationInfo applicationInfo; + applicationInfo.bundleName = NO_EXIST; + oldInfo.SetBaseApplicationInfo(applicationInfo); + EXPECT_EQ(oldInfo.baseApplicationInfo_->bundleName, NO_EXIST); +} + +/** + * @tc.number: OverlayDataMgr_0900 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of BuildOverlayConnection and BuildOverlayConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_0900, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo oldInfo; + oldInfo.SetIsPreInstallApp(true); + oldInfo.SetCertificateFingerprint(NO_EXIST); + EXPECT_EQ(oldInfo.baseApplicationInfo_->fingerprint, NO_EXIST); +} +#endif + +/** + * @tc.number: OverlayDataMgr_1200 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of GetBundleDir. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1200, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + std::string moduleHapPath = "xxx/"; + std::string bundleDir; + ErrCode res = overlayDataMgr.GetBundleDir(moduleHapPath, bundleDir); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_BUNDLE_DIR); + moduleHapPath = "//"; + res = overlayDataMgr.GetBundleDir(moduleHapPath, bundleDir); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: OverlayDataMgr_1300 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1300, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); + std::map innerModuleInfos; + InnerModuleInfo moduleInfo; + moduleInfo.moduleName = TEST_PACK_AGE; + moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; + innerModuleInfos[TEST_PACK_AGE] = moduleInfo; + newInfo.AddInnerModuleInfo(innerModuleInfos); + oldInfo.AddInnerModuleInfo(innerModuleInfos); + res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: OverlayDataMgr_1400 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1400, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + std::map innerModuleInfos; + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); + dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, newInfo); + ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); + UninstallBundleInfo(); +} + +/** + * @tc.number: OverlayDataMgr_1500 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1500, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + std::map innerModuleInfos; + InnerModuleInfo moduleInfo; + moduleInfo.moduleName = TEST_PACK_AGE; + moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; + innerModuleInfos[TEST_PACK_AGE] = moduleInfo; + newInfo.AddInnerModuleInfo(innerModuleInfos); + oldInfo.AddInnerModuleInfo(innerModuleInfos); + newInfo.SetOverlayType(OVERLAY_INTERNAL_BUNDLE); + + ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: OverlayDataMgr_1600 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of QueryOverlayInnerBundleInfo. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1600, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo info; + bool res = overlayDataMgr.QueryOverlayInnerBundleInfo("", info); + EXPECT_EQ(res, false); +} + +/** + * @tc.number: OverlayDataMgr_1700 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of GetAllOverlayModuleInfo. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1700, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + std::vector overlayModuleInfos; + ErrCode res = overlayDataMgr.GetAllOverlayModuleInfo("", overlayModuleInfos, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); + + AddInnerBundleInfo(); + res = overlayDataMgr.GetAllOverlayModuleInfo( + TEST_BUNDLE_NAME, overlayModuleInfos, Constants::NOT_EXIST_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_NON_OVERLAY_BUNDLE); + + res = overlayDataMgr.GetAllOverlayModuleInfo( + TEST_BUNDLE_NAME, overlayModuleInfos, Constants::INVALID_USERID); + EXPECT_EQ(res, + ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); + + OverlayModuleInfo overlayModuleInfo; + overlayModuleInfos.push_back(overlayModuleInfo); + res = overlayDataMgr.GetAllOverlayModuleInfo( + TEST_BUNDLE_NAME, overlayModuleInfos, Constants::NOT_EXIST_USERID); + + EXPECT_EQ(res, + ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_NON_OVERLAY_BUNDLE); + UninstallBundleInfo(); +} + +/** + * @tc.number: OverlayDataMgr_1800 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of GetOverlayModuleInfo. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1800, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + OverlayModuleInfo overlayModuleInfos; + ErrCode res = overlayDataMgr.GetOverlayModuleInfo("", "", overlayModuleInfos, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); + + AddInnerBundleInfo(); + res = overlayDataMgr.GetOverlayModuleInfo( + TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfos, Constants::INVALID_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); + + res = overlayDataMgr.GetOverlayModuleInfo( + TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfos, Constants::NOT_EXIST_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_NON_OVERLAY_BUNDLE); +} + +/** + * @tc.number: OverlayDataMgr_1900 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of GetOverlayBundleInfoForTarget. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_1900, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + std::vector overlayBundleInfo; + ErrCode res = overlayDataMgr.GetOverlayBundleInfoForTarget("", overlayBundleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_NOT_EXISTED); + + AddInnerBundleInfo(); + res = overlayDataMgr.GetOverlayBundleInfoForTarget( + TEST_BUNDLE_NAME, overlayBundleInfo, Constants::NOT_EXIST_USERID); + EXPECT_EQ(res, ERR_OK); + EXPECT_EQ(overlayBundleInfo.size(), DEFAULT_OVERLAY_BUNDLE_INFO); + + res = overlayDataMgr.GetOverlayBundleInfoForTarget( + TEST_BUNDLE_NAME, overlayBundleInfo, Constants::INVALID_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); + + UninstallBundleInfo(); +} + +/** + * @tc.number: OverlayDataMgr_2000 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of GetOverlayModuleInfoForTarget. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2000, Function | SmallTest | Level0) +{ + AddInnerBundleInfo(); + OverlayDataMgr overlayDataMgr; + std::vector overlayModuleInfos; + ErrCode res = overlayDataMgr.GetOverlayModuleInfoForTarget( + TEST_BUNDLE_NAME, TARGET_MODULE_NAME, overlayModuleInfos, Constants::NOT_EXIST_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_MODULE_IS_OVERLAY_MODULE); + + res = overlayDataMgr.GetOverlayModuleInfoForTarget( + TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfos, Constants::NOT_EXIST_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_MODULE_NOT_EXISTED); + + res = overlayDataMgr.GetOverlayModuleInfoForTarget( + TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfos, Constants::INVALID_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); + + res = overlayDataMgr.GetOverlayModuleInfoForTarget( + TEST_BUNDLE_NAME, "", overlayModuleInfos, Constants::NOT_EXIST_USERID); + EXPECT_EQ(res, ERR_OK); + + res = overlayDataMgr.GetOverlayModuleInfoForTarget( + "", "", overlayModuleInfos, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_NOT_EXISTED); + + UninstallBundleInfo(); +} + +/** + * @tc.number: OverlayDataMgr_2100 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of SetOverlayEnabled. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2100, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + bool isEnabled = false; + ErrCode res = overlayDataMgr.SetOverlayEnabled(TEST_BUNDLE_NAME, "", isEnabled, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); + + AddInnerBundleInfo(); + res = overlayDataMgr.SetOverlayEnabled( + TEST_BUNDLE_NAME, TEST_MODULE_NAME, isEnabled, Constants::INVALID_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); + + res = overlayDataMgr.SetOverlayEnabled(TEST_BUNDLE_NAME, TEST_MODULE_NAME, isEnabled, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); + + UninstallBundleInfo(); +} + +/** + * @tc.number: OverlayDataMgr_2200 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of GetCallingBundleName. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2200, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + std::string res = overlayDataMgr.GetCallingBundleName(); + EXPECT_EQ(res, ""); +} + +/** + * @tc.number: OverlayDataMgr_2300 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of AddOverlayModuleStates. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2300, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo innerBundleInfo; + InnerBundleUserInfo userInfo; + overlayDataMgr.AddOverlayModuleStates(innerBundleInfo, userInfo); + EXPECT_EQ(userInfo.bundleUserInfo.userId, Constants::INVALID_USERID); + + userInfo.bundleUserInfo.userId = USERID; + innerBundleInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); + overlayDataMgr.AddOverlayModuleStates(innerBundleInfo, userInfo); + EXPECT_EQ(userInfo.bundleUserInfo.userId, USERID); +} + +/** + * @tc.number: OverlayDataMgr_2400 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of AddOverlayModuleStates. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2400, Function | SmallTest | Level0) +{ + AddInnerBundleInfo(); + OverlayDataMgr overlayDataMgr; + InnerBundleInfo innerBundleInfo; + InnerBundleUserInfo userInfo; + userInfo.bundleUserInfo.userId = USERID; + innerBundleInfo.SetOverlayType(OverlayType::OVERLAY_INTERNAL_BUNDLE); + innerBundleInfo.SetTargetBundleName(TEST_BUNDLE_NAME); + overlayDataMgr.AddOverlayModuleStates(innerBundleInfo, userInfo); + EXPECT_EQ(userInfo.bundleUserInfo.userId, USERID); + UninstallBundleInfo(); +} + +/** + * @tc.number: OverlayDataMgr_2500 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2500, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + std::map innerModuleInfos; + InnerModuleInfo moduleInfo; + moduleInfo.moduleName = TEST_PACK_AGE; + moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; + innerModuleInfos[TEST_PACK_AGE] = moduleInfo; + newInfo.AddInnerModuleInfo(innerModuleInfos); + oldInfo.AddInnerModuleInfo(innerModuleInfos); + newInfo.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); + + ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); + EXPECT_EQ(res, ERR_OK); + + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + + ApplicationInfo applicationInfo; + applicationInfo.bundleName = TEST_BUNDLE_NAME; + applicationInfo.targetBundleName = TEST_BUNDLE_NAME; + oldInfo.SetBaseApplicationInfo(applicationInfo); + dataMgr->bundleInfos_.insert( + pair(TEST_BUNDLE_NAME, oldInfo)); + res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: OverlayDataMgr_2600 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2600, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + std::map innerModuleInfos; + InnerModuleInfo moduleInfo; + moduleInfo.moduleName = TEST_PACK_AGE; + moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; + innerModuleInfos[TEST_PACK_AGE] = moduleInfo; + newInfo.AddInnerModuleInfo(innerModuleInfos); + oldInfo.AddInnerModuleInfo(innerModuleInfos); + newInfo.SetOverlayType(NON_OVERLAY_TYPE); + + ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: OverlayDataMgr_2700 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2700, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + InnerBundleInfo targetInnerBundleInfo; + std::map innerModuleInfos; + + overlayDataMgr.RemoveOverlayBundleInfo(TEST_BUNDLE_NAME, targetInnerBundleInfo); + overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); + InnerModuleInfo moduleInfo; + moduleInfo.moduleName = TEST_PACK_AGE; + moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; + innerModuleInfos[TEST_PACK_AGE] = moduleInfo; + newInfo.AddInnerModuleInfo(innerModuleInfos); + oldInfo.AddInnerModuleInfo(innerModuleInfos); + newInfo.SetOverlayType(OVERLAY_INTERNAL_BUNDLE); + + ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: OverlayDataMgr_2800 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2800, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + std::map innerModuleInfos; + InnerModuleInfo moduleInfo; + moduleInfo.moduleName = TEST_PACK_AGE; + moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; + innerModuleInfos[TEST_PACK_AGE] = moduleInfo; + newInfo.AddInnerModuleInfo(innerModuleInfos); + oldInfo.AddInnerModuleInfo(innerModuleInfos); + newInfo.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); + + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + + ApplicationInfo applicationInfo; + applicationInfo.bundleName = TEST_BUNDLE_NAME; + applicationInfo.targetBundleName = TEST_BUNDLE_NAME; + oldInfo.SetBaseApplicationInfo(applicationInfo); + newInfo.SetTargetBundleName(NO_EXIST); + dataMgr->bundleInfos_.insert( + pair(TEST_BUNDLE_NAME, oldInfo)); + ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: OverlayDataMgr_2900 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleInfo. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_2900, Function | SmallTest | Level0) +{ + AddInnerBundleInfo(); + + OverlayDataMgr overlayDataMgr; + InnerBundleInfo oldInfo; + InnerBundleInfo targetInnerBundleInfo; + std::map innerModuleInfos; + InnerModuleInfo moduleInfo; + moduleInfo.moduleName = TEST_PACK_AGE; + moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; + innerModuleInfos[TEST_PACK_AGE] = moduleInfo; + oldInfo.AddInnerModuleInfo(innerModuleInfos); + + overlayDataMgr.RemoveOverlayBundleInfo(TEST_BUNDLE_NAME, targetInnerBundleInfo); + overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); + + oldInfo.SetOverlayType(OVERLAY_INTERNAL_BUNDLE); + overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); + EXPECT_EQ(oldInfo.GetOverlayType(), OVERLAY_INTERNAL_BUNDLE); + + oldInfo.SetTargetBundleName(TARGET_MODULE_NAME); + overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); + EXPECT_EQ(oldInfo.GetTargetBundleName(), TARGET_MODULE_NAME); + + oldInfo.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); + overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); + EXPECT_EQ(oldInfo.GetOverlayType(), OVERLAY_EXTERNAL_BUNDLE); + + oldInfo.SetTargetBundleName(TARGET_MODULE_NAME); + overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); + EXPECT_EQ(oldInfo.GetTargetBundleName(), TARGET_MODULE_NAME); + + oldInfo.SetOverlayType(NON_OVERLAY_TYPE); + overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); + overlayDataMgr.RemoveOverlayModuleInfo("noExits", TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); + EXPECT_EQ(oldInfo.GetOverlayType(), NON_OVERLAY_TYPE); + UninstallBundleInfo(); +} + +/** + * @tc.number: OverlayDataMgr_3000 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3000, Function | SmallTest | Level0) +{ + InnerBundleInfo info; + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); + + info.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); + bool res = dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, info); + EXPECT_EQ(res, true); + + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME2, InstallState::INSTALL_START); + info.SetOverlayType(OverlayType::NON_OVERLAY_TYPE); + res = dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME2, info); + EXPECT_EQ(res, true); + + UninstallBundleInfo(); +} + +/** + * @tc.number: OverlayDataMgr_3100 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3100, Function | SmallTest | Level0) +{ + InnerBundleInfo info; + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); + + info.SetOverlayType(OverlayType::OVERLAY_INTERNAL_BUNDLE); + bool res = dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, info); + EXPECT_EQ(res, true); + + UninstallBundleInfo(); +} + +/** + * @tc.number: OverlayDataMgr_3200 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3200, Function | SmallTest | Level0) +{ + AddInnerBundleInfo(); + + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + std::map innerModuleInfos; + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + + bool res = dataMgr->AddNewModuleInfo(TEST_BUNDLE_NAME, newInfo, oldInfo); + EXPECT_EQ(res, false); + + UninstallBundleInfo(); +} + +/** + * @tc.number: OverlayDataMgr_3300 + * @tc.name: AddBundleInfo + * @tc.desc: 1. add module info to the data manager + * 2. query data then verify + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3300, Function | SmallTest | Level0) +{ + InnerBundleInfo info1; + BundleInfo bundleInfo1; + bundleInfo1.name = TEST_BUNDLE_NAME; + bundleInfo1.applicationInfo.bundleName = TEST_BUNDLE_NAME; + ApplicationInfo applicationInfo1; + applicationInfo1.name = TEST_BUNDLE_NAME; + applicationInfo1.bundleName = TEST_BUNDLE_NAME; + info1.SetBaseBundleInfo(bundleInfo1); + info1.SetBaseApplicationInfo(applicationInfo1); + + InnerBundleInfo info2; + BundleInfo bundleInfo2; + bundleInfo2.name = TEST_BUNDLE_NAME; + bundleInfo2.applicationInfo.bundleName = TEST_BUNDLE_NAME; + ApplicationInfo applicationInfo2; + applicationInfo2.name = TEST_BUNDLE_NAME; + applicationInfo2.bundleName = TEST_BUNDLE_NAME; + info2.SetBaseBundleInfo(bundleInfo2); + info2.SetBaseApplicationInfo(applicationInfo2); + + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); + dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, info1); + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UPDATING_START); + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UPDATING_SUCCESS); + info1.SetOverlayType(OverlayType::NON_OVERLAY_TYPE); + info2.SetOverlayType(OverlayType::OVERLAY_INTERNAL_BUNDLE); + bool ret = dataMgr->AddNewModuleInfo(TEST_BUNDLE_NAME, info2, info1); + EXPECT_FALSE(ret); + + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_START); + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_SUCCESS); +} + + +/** + * @tc.number: OverlayDataMgr_3400 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of IsExistedNonOverlayHap. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3400, Function | SmallTest | Level0) +{ + AddInnerBundleInfo(); + OverlayDataMgr overlayDataMgr; + bool res = overlayDataMgr.IsExistedNonOverlayHap(TEST_BUNDLE_NAME); + EXPECT_EQ(res, false); + + UninstallBundleInfo(); +} + +/** + * @tc.number: OverlayDataMgr_3500 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of BuildInternalOverlayConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3500, Function | SmallTest | Level0) +{ + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.name = TEST_MODULE_NAME; + innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; + innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + ApplicationInfo applicationInfo; + applicationInfo.bundleName = TEST_BUNDLE_NAME; + applicationInfo.targetBundleName = TEST_BUNDLE_NAME; + innerBundleInfo.SetBaseApplicationInfo(applicationInfo); + + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); + dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, innerBundleInfo); + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UPDATING_START); + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UPDATING_SUCCESS); + OverlayDataMgr overlayDataMgr; + overlayDataMgr.BuildInternalOverlayConnection(TARGET_MODULE_NAME, innerBundleInfo, USERID); + EXPECT_EQ(innerBundleInfo.FetchInnerModuleInfos().empty(), false); + UninstallBundleInfo(); +} + +/** + * @tc.number: OverlayDataMgr_3600 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3600, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + std::map innerModuleInfos; + InnerModuleInfo moduleInfo; + moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; + innerModuleInfos[TEST_PACK_AGE] = moduleInfo; + newInfo.AddInnerModuleInfo(innerModuleInfos); + oldInfo.AddInnerModuleInfo(innerModuleInfos); + newInfo.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); + + ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); +} + +/** + * @tc.number: OverlayDataMgr_3800 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleInfo. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3800, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo targetInnerBundleInfo; + std::map innerModuleInfos; + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.name = TEST_MODULE_NAME; + innerModuleInfo.moduleName = TEST_PACK_AGE; + innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; + innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; + innerModuleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; + innerModuleInfos[TEST_PACK_AGE] = innerModuleInfo; + innerBundleInfo.AddInnerModuleInfo(innerModuleInfos); + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + ApplicationInfo applicationInfo; + applicationInfo.bundleName = TEST_BUNDLE_NAME; + applicationInfo.targetBundleName = TEST_BUNDLE_NAME; + innerBundleInfo.SetBaseApplicationInfo(applicationInfo); + + innerBundleInfo.SetOverlayType(OverlayType::OVERLAY_INTERNAL_BUNDLE); + overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, innerBundleInfo, targetInnerBundleInfo); + overlayDataMgr.ResetInternalOverlayModuleState(innerModuleInfos, TARGET_MODULE_NAME, innerBundleInfo); + EXPECT_EQ(innerModuleInfos.at(TEST_PACK_AGE).targetModuleName, TARGET_MODULE_NAME); +} + +/** + * @tc.number: OverlayDataMgr_3900 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of SaveInternalOverlayModuleState. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3900, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + std::map innerModuleInfos; + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.name = TEST_MODULE_NAME; + innerModuleInfo.moduleName = TEST_PACK_AGE; + innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; + innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; + innerModuleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; + innerModuleInfos[TEST_PACK_AGE] = innerModuleInfo; + innerBundleInfo.AddInnerModuleInfo(innerModuleInfos); + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + ApplicationInfo applicationInfo; + applicationInfo.bundleName = TEST_BUNDLE_NAME; + applicationInfo.targetBundleName = TEST_BUNDLE_NAME; + innerBundleInfo.SetBaseApplicationInfo(applicationInfo); + + OverlayModuleInfo overlayModuleInfo; + overlayModuleInfo.targetModuleName = TARGET_MODULE_NAME; + + ErrCode res = overlayDataMgr.SaveInternalOverlayModuleState(overlayModuleInfo, innerBundleInfo); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: OverlayDataMgr_4000 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of GetOverlayModuleInfoForTarget. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4000, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo innerBundleInfo; + std::vector overlayModuleInfos; + ErrCode res = overlayDataMgr.GetOverlayModuleInfoForTarget( + innerBundleInfo, overlayModuleInfos, Constants::NOT_EXIST_USERID); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: OverlayDataMgr_4100 + * @tc.name: test bundleName is empty. + * @tc.desc: 1.OverlayDataMgr with SetOverlayEnabled. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4100, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + bool isEnabled = false; + ErrCode res = overlayDataMgr.SetOverlayEnabled("", TEST_MODULE_NAME, isEnabled, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); +} + +/** + * @tc.number: OverlayDataMgr_4200 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of BuildInternalOverlayConnection. + * 2.system run normally. + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4200, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo oldInfo; + oldInfo.SetOverlayType(OVERLAY_INTERNAL_BUNDLE); + InnerModuleInfo moduleInfo; + moduleInfo.targetModuleName = TEST_MODULE_NAME; + std::map innerModuleInfos; + moduleInfo.moduleName = TEST_MODULE_NAME; + innerModuleInfos[TEST_PACK_AGE] = moduleInfo; + moduleInfo.moduleName = TEST_PACK_AGE; + moduleInfo.targetModuleName = TEST_PACK_AGE; + innerModuleInfos[TEST_MODULE_NAME] = moduleInfo; + oldInfo.AddInnerModuleInfo(innerModuleInfos); + EXPECT_EQ(oldInfo.GetOverlayType(), OVERLAY_INTERNAL_BUNDLE); + + ClearDataMgr(); + EXPECT_EQ(bundleMgrService_->dataMgr_, nullptr); + BuildInternalOverlayConnection(TEST_MODULE_NAME, oldInfo, USERID); + ResetDataMgr(); +} + +/** + * @tc.number: OverlayDataMgr_4300 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of QueryOverlayInnerBundleInfo. + * 2.system run normally. + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4300, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + overlayDataMgr.dataMgr_ = std::make_shared(); + InnerBundleInfo info; + std::map innerModuleInfos; + info.AddInnerModuleInfo(innerModuleInfos); + overlayDataMgr.dataMgr_->bundleInfos_[NO_EXIST] = info; + bool ret = overlayDataMgr.QueryOverlayInnerBundleInfo(NO_EXIST, info); + auto iterator = overlayDataMgr.dataMgr_->bundleInfos_.find(NO_EXIST); + if (iterator != overlayDataMgr.dataMgr_->bundleInfos_.end()) { + overlayDataMgr.dataMgr_->bundleInfos_.erase(iterator); + } + EXPECT_EQ(ret, true); +} + +/** + * @tc.number: OverlayDataMgr_4400 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of QueryOverlayInnerBundleInfo. + * 2.system run normally. + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4400, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + overlayDataMgr.dataMgr_ = std::make_shared(); + InnerBundleInfo info; + info.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); + std::map innerModuleInfos; + InnerModuleInfo innerModuleInfo; + innerModuleInfos[TEST_MODULE_NAME] = innerModuleInfo; + info.AddInnerModuleInfo(innerModuleInfos); + overlayDataMgr.dataMgr_->bundleInfos_[NO_EXIST] = info; + std::vector overlayModuleInfo; + auto ret = overlayDataMgr.GetAllOverlayModuleInfo(NO_EXIST, overlayModuleInfo, + Constants::NOT_EXIST_USERID); + auto iterator = overlayDataMgr.dataMgr_->bundleInfos_.find(NO_EXIST); + if (iterator != overlayDataMgr.dataMgr_->bundleInfos_.end()) { + overlayDataMgr.dataMgr_->bundleInfos_.erase(iterator); + } + EXPECT_EQ(ret, ERR_OK); +} + +/** + * @tc.number: OverlayDataMgr_4500 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of BuildInternalOverlayConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4500, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo oldInfo; + oldInfo.overlayType_ = OVERLAY_INTERNAL_BUNDLE; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.targetModuleName = "errModuleName"; + oldInfo.innerModuleInfos_.insert(pair("1", innerModuleInfo)); + overlayDataMgr.BuildInternalOverlayConnection(TARGET_MODULE_NAME, oldInfo, USERID); + EXPECT_EQ(oldInfo.FetchInnerModuleInfos().empty(), false); +} + +/** + * @tc.number: OverlayDataMgr_4600 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of BuildInternalOverlayConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4600, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo oldInfo; + oldInfo.overlayType_ = OVERLAY_INTERNAL_BUNDLE; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; + innerModuleInfo.moduleName = TEST_MODULE_NAME; + oldInfo.innerModuleInfos_.insert(pair("1", innerModuleInfo)); + overlayDataMgr.BuildInternalOverlayConnection(TARGET_MODULE_NAME, oldInfo, USERID); + EXPECT_EQ(oldInfo.FetchInnerModuleInfos().empty(), false); +} + +/** + * @tc.number: OverlayDataMgr_4700 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of BuildInternalOverlayConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4700, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo oldInfo; + oldInfo.overlayType_ = OVERLAY_INTERNAL_BUNDLE; + oldInfo.innerModuleInfos_.clear(); + overlayDataMgr.BuildInternalOverlayConnection(TARGET_MODULE_NAME, oldInfo, USERID); + EXPECT_EQ(oldInfo.FetchInnerModuleInfos().empty(), true); +} + +/** + * @tc.number: OverlayDataMgr_4800 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of BuildInternalOverlayConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4800, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo oldInfo; + oldInfo.overlayType_ = OVERLAY_INTERNAL_BUNDLE; + oldInfo.innerModuleInfos_.clear(); + overlayDataMgr.BuildInternalOverlayConnection(TARGET_MODULE_NAME, oldInfo, USERID); + EXPECT_EQ(oldInfo.FetchInnerModuleInfos().empty(), true); +} + +/** + * @tc.number: OverlayDataMgr_4900 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of QueryOverlayInnerBundleInfo. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_4900, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo innerBundleInfo; + overlayDataMgr.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); + overlayDataMgr.dataMgr_->bundleInfos_.insert(pair(TEST_BUNDLE_NAME, innerBundleInfo)); + auto res = overlayDataMgr.QueryOverlayInnerBundleInfo(NO_EXIST, innerBundleInfo); + EXPECT_FALSE(res); +} + +/** + * @tc.number: OverlayDataMgr_5000 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of QueryOverlayInnerBundleInfo. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_5000, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo innerBundleInfo; + ClearDataMgr(); + auto res = overlayDataMgr.QueryOverlayInnerBundleInfo(TEST_BUNDLE_NAME, innerBundleInfo); + EXPECT_FALSE(res); + ResetDataMgr(); +} + +/** + * @tc.number: OverlayDataMgr_5100 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of SaveInternalOverlayModuleState. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_5100, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + OverlayModuleInfo overlayModuleInfo; + overlayModuleInfo.targetModuleName = TARGET_MODULE_NAME; + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + innerBundleInfo.innerModuleInfos_.insert(pair(TARGET_MODULE_NAME, innerModuleInfo)); + overlayDataMgr.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); + overlayDataMgr.dataMgr_->AddUserId(NOT_EXIST_USERID); + auto res = overlayDataMgr.SaveInternalOverlayModuleState(overlayModuleInfo, innerBundleInfo); + EXPECT_FALSE(res); +} + +/** + * @tc.number: OverlayDataMgr_5200 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of SaveInternalOverlayModuleState. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_5200, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + OverlayModuleInfo overlayModuleInfo; + overlayModuleInfo.targetModuleName = TARGET_MODULE_NAME; + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + innerBundleInfo.innerModuleInfos_.insert(pair(TEST_MODULE_NAME, innerModuleInfo)); + overlayDataMgr.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); + overlayDataMgr.dataMgr_->AddUserId(NOT_EXIST_USERID); + auto res = overlayDataMgr.SaveInternalOverlayModuleState(overlayModuleInfo, innerBundleInfo); + EXPECT_FALSE(res); +} + +/** + * @tc.number: OverlayManagerHostImpl_0100 + * @tc.name: test overlayManagerHostImpl. + * @tc.desc: 1.overlayManagerHostImpl of GetAllOverlayModuleInfo. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayManagerHostImpl_0100, Function | SmallTest | Level0) +{ + OverlayManagerHostImpl overlayManagerHostImpl; + std::vector overlayModuleInfo; + ErrCode res = overlayManagerHostImpl.GetAllOverlayModuleInfo("", overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + + res = overlayManagerHostImpl.GetAllOverlayModuleInfo( + "bundleName", overlayModuleInfo, Constants::UNSPECIFIED_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); +} + +/** + * @tc.number: GetOverlayModuleInfo_0200 + * @tc.name: test overlayManagerHostImpl. + * @tc.desc: 1.overlayManagerHostImpl of GetOverlayModuleInfo. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_0200, Function | SmallTest | Level0) +{ + OverlayManagerHostImpl overlayManagerHostImpl; + OverlayModuleInfo overlayModuleInfo; + ErrCode res = overlayManagerHostImpl.GetOverlayModuleInfo( + "", "moduleName", overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + + res = overlayManagerHostImpl.GetOverlayModuleInfo( + "bundleName", "", overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + + res = overlayManagerHostImpl.GetOverlayModuleInfo( + "", "", overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + + res = overlayManagerHostImpl.GetOverlayModuleInfo( + "bundleName", "moduleName", overlayModuleInfo, Constants::UNSPECIFIED_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); +} + +/** + * @tc.number: GetOverlayModuleInfo_0300 + * @tc.name: test overlayManagerHostImpl. + * @tc.desc: 1.overlayManagerHostImpl of GetOverlayBundleInfoForTarget. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_0300, Function | SmallTest | Level0) +{ + OverlayManagerHostImpl overlayManagerHostImpl; + std::vector overlayBundleInfo; + ErrCode res = overlayManagerHostImpl.GetOverlayBundleInfoForTarget( + "", overlayBundleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + + res = overlayManagerHostImpl.GetOverlayBundleInfoForTarget( + "targetBundleName", overlayBundleInfo, Constants::UNSPECIFIED_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_NOT_EXISTED); +} + +/** + * @tc.number: GetOverlayModuleInfo_0400 + * @tc.name: test OverlayManagerHostImpl. + * @tc.desc: 1.OverlayManagerHostImpl of GetOverlayModuleInfoForTarget. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_0400, Function | SmallTest | Level0) +{ + OverlayManagerHostImpl overlayManagerHostImpl; + std::vector overlayModuleInfo; + ErrCode res = overlayManagerHostImpl.GetOverlayModuleInfoForTarget( + "", "targetModuleName", overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + + res = overlayManagerHostImpl.GetOverlayModuleInfoForTarget( + "targetBundleName", "", overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_NOT_EXISTED); + + res = overlayManagerHostImpl.GetOverlayModuleInfoForTarget( + "", "", overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + + res = overlayManagerHostImpl.GetOverlayModuleInfoForTarget( + "targetBundleName", "targetModuleName", overlayModuleInfo, Constants::UNSPECIFIED_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_NOT_EXISTED); +} + +/** + * @tc.number: GetOverlayModuleInfo_0500 + * @tc.name: test OverlayManagerHostImpl. + * @tc.desc: 1.OverlayManagerHostImpl of SetOverlayEnabled. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_0500, Function | SmallTest | Level0) +{ + OverlayManagerHostImpl overlayManagerHostImpl; + bool isEnabled = false; + ErrCode res = overlayManagerHostImpl.SetOverlayEnabled( + "", "moduleName", isEnabled, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_SET_OVERLAY_PARAM_ERROR); + + res = overlayManagerHostImpl.SetOverlayEnabled( + "bundleName", "", isEnabled, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_SET_OVERLAY_PARAM_ERROR); + + res = overlayManagerHostImpl.SetOverlayEnabled( + "", "", isEnabled, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_SET_OVERLAY_PARAM_ERROR); + + res = overlayManagerHostImpl.SetOverlayEnabled( + "bundleName", "moduleName", isEnabled, Constants::UNSPECIFIED_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); +} + +/** + * @tc.number: GetOverlayModuleInfo_0800 + * @tc.name: test overlayManagerHostImpl. + * @tc.desc: 1.OverlayManagerHostImpl with GetOverlayBundleInfoForTarget. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_0800, Function | SmallTest | Level0) +{ + OverlayManagerHostImpl overlayManagerHostImpl; + std::vector overlayBundleInfo; + ErrCode res = overlayManagerHostImpl.GetOverlayBundleInfoForTarget(TEST_BUNDLE_NAME, + overlayBundleInfo, Constants::INVALID_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); +} + +/** + * @tc.number: OverlayIpcTest_2000 + * @tc.name: test SetOverlayEnabled interface in OverlayManagerProxy. + * @tc.desc: 1.construct OverlayManagerProxy instance. + * 2.calling SetOverlayEnabled interface by using OverlayManagerProxy instance. + * 3.bundleName is empty and set failed + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_0900, Function | SmallTest | Level0) +{ + OverlayManagerHostImpl overlayManagerHostImpl; + + std::vector overlayModuleInfos; + auto errCode = overlayManagerHostImpl.GetTargetOverlayModuleInfo("", overlayModuleInfos, + USERID); + EXPECT_EQ(errCode, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + + errCode = overlayManagerHostImpl.GetTargetOverlayModuleInfo(TEST_BUNDLE_NAME, overlayModuleInfos, + Constants::UNSPECIFIED_USERID); + EXPECT_EQ(errCode, ERR_BUNDLE_MANAGER_INTERNAL_ERROR); +} + +/** + * @tc.number: OverlayIpcTest_2000 + * @tc.name: test SetOverlayEnabled interface in OverlayManagerProxy. + * @tc.desc: 1.construct GetOverlayModuleInfoByBundleName instance. + * 2.calling SetOverlayEnabled interface by using GetOverlayModuleInfoByBundleName instance. + * 3.bundleName is empty and set failed + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_1000, Function | SmallTest | Level0) +{ + OverlayManagerHostImpl overlayManagerHostImpl; + + std::vector overlayModuleInfos; + auto errCode = overlayManagerHostImpl.GetOverlayModuleInfoByBundleName("", TEST_MODULE_NAME, + overlayModuleInfos, USERID); + EXPECT_EQ(errCode, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + + errCode = overlayManagerHostImpl.GetOverlayModuleInfoByBundleName(TEST_BUNDLE_NAME, "", + overlayModuleInfos, Constants::UNSPECIFIED_USERID); + EXPECT_EQ(errCode, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); + + errCode = overlayManagerHostImpl.GetOverlayModuleInfoByBundleName(TEST_BUNDLE_NAME, TEST_MODULE_NAME, + overlayModuleInfos, Constants::UNSPECIFIED_USERID); + EXPECT_EQ(errCode, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); +} + +/** + * @tc.number: OverlayIpcTest_2000 + * @tc.name: test SetOverlayEnabledForSelf interface in OverlayManagerProxy. + * @tc.desc: 1.construct SetOverlayEnabledForSelf instance. + * 2.calling SetOverlayEnabled interface by using SetOverlayEnabledForSelf instance. + * 3.bundleName is empty and set failed + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, GetOverlayModuleInfo_1100, Function | SmallTest | Level0) +{ + OverlayManagerHostImpl overlayManagerHostImpl; + + bool isEnabled = false; + auto errCode = overlayManagerHostImpl.SetOverlayEnabledForSelf("", + isEnabled, USERID); + EXPECT_EQ(errCode, ERR_BUNDLEMANAGER_OVERLAY_SET_OVERLAY_PARAM_ERROR); + + errCode = overlayManagerHostImpl.SetOverlayEnabledForSelf(TEST_MODULE_NAME, + isEnabled, Constants::UNSPECIFIED_USERID); + EXPECT_EQ(errCode, ERR_BUNDLE_MANAGER_INTERNAL_ERROR); +} + +/** + * @tc.number: CheckTargetBundle_0100 + * @tc.name: check bundle target priority range + * @tc.desc: Test CheckTargetBundle +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckTargetBundle_0100, Function | SmallTest | Level0) +{ + BundleOverlayInstallChecker checker; + auto code = checker.CheckTargetBundle("", "", "", USERID); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INVALID_BUNDLE_NAME); + code = checker.CheckTargetBundle(TEST_BUNDLE_NAME, "", "", USERID); + EXPECT_EQ(code, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_NO_SYSTEM_APPLICATION_FOR_EXTERNAL_OVERLAY); +} + +/** + * @tc.number: UpdateInnerBundleInfo_0100 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, UpdateInnerBundleInfo_0100, Function | SmallTest | Level0) +{ + InnerBundleInfo info1; + BundleInfo bundleInfo1; + bundleInfo1.name = BUNDLE_NAME; + bundleInfo1.applicationInfo.bundleName = BUNDLE_NAME; + ApplicationInfo applicationInfo1; + applicationInfo1.name = BUNDLE_NAME; + applicationInfo1.bundleName = BUNDLE_NAME; + info1.SetBaseBundleInfo(bundleInfo1); + info1.SetBaseApplicationInfo(applicationInfo1); + + InnerBundleInfo info2; + BundleInfo bundleInfo2; + bundleInfo2.name = BUNDLE_NAME; + bundleInfo2.applicationInfo.bundleName = BUNDLE_NAME; + ApplicationInfo applicationInfo2; + applicationInfo2.name = BUNDLE_NAME; + applicationInfo2.bundleName = BUNDLE_NAME; + info2.SetBaseBundleInfo(bundleInfo2); + info2.SetBaseApplicationInfo(applicationInfo2); + info2.SetIsNewVersion(true); + info2.SetOverlayType(OverlayType::NON_OVERLAY_TYPE); + + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + dataMgr->AddUserId(USERID); + + bool ret1 = dataMgr->UpdateBundleInstallState(BUNDLE_NAME, InstallState::INSTALL_START); + bool ret2 = dataMgr->AddInnerBundleInfo(BUNDLE_NAME, info1); + bool ret3 = dataMgr->UpdateBundleInstallState(BUNDLE_NAME, InstallState::UPDATING_START); + bool ret4 = dataMgr->UpdateBundleInstallState(BUNDLE_NAME, InstallState::UPDATING_SUCCESS); + bool ret5 = dataMgr->UpdateInnerBundleInfo(BUNDLE_NAME, info2, info1); + EXPECT_TRUE(ret1); + EXPECT_TRUE(ret2); + EXPECT_TRUE(ret3); + EXPECT_TRUE(ret4); + EXPECT_TRUE(ret5); + + info2.SetOverlayType(OverlayType::OVERLAY_INTERNAL_BUNDLE); + ret5 = dataMgr->UpdateInnerBundleInfo(BUNDLE_NAME, info2, info1); + EXPECT_FALSE(ret5); + + info2.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); + ret5 = dataMgr->UpdateInnerBundleInfo(BUNDLE_NAME, info2, info1); + EXPECT_TRUE(ret5); + + ret5 = dataMgr->UpdateBundleInstallState(BUNDLE_NAME, InstallState::UNINSTALL_START); + EXPECT_TRUE(ret5); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_0100 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0100, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + + ClearDataMgr(); + bool resBool = overlayDataMgr.IsExistedNonOverlayHap(TEST_BUNDLE_NAME); + EXPECT_EQ(resBool, false); + ResetDataMgr(); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_0200 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0200, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + std::map innerModuleInfos; + InnerModuleInfo moduleInfo; + moduleInfo.moduleName = TEST_PACK_AGE; + moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; + innerModuleInfos[TEST_PACK_AGE] = moduleInfo; + newInfo.AddInnerModuleInfo(innerModuleInfos); + oldInfo.AddInnerModuleInfo(innerModuleInfos); + newInfo.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); + + ClearDataMgr(); + ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); + ResetDataMgr(); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_0300 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6S6E8 + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0300, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo oldInfo; + InnerBundleInfo targetInnerBundleInfo; + std::map innerModuleInfos; + InnerModuleInfo moduleInfo; + moduleInfo.moduleName = TEST_PACK_AGE; + moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; + innerModuleInfos[TEST_PACK_AGE] = moduleInfo; + oldInfo.AddInnerModuleInfo(innerModuleInfos); + oldInfo.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); + + ClearDataMgr(); + overlayDataMgr.RemoveOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_PACK_AGE, oldInfo, targetInnerBundleInfo); + std::map moduleInfos = oldInfo.FetchInnerModuleInfos(); + EXPECT_EQ(moduleInfos.empty(), false); + ResetDataMgr(); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_0400 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0400, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleUserInfo userInfo; + userInfo.bundleUserInfo.overlayModulesState.clear(); + std::map statesMap; + std::map res = overlayDataMgr.GetModulesStateFromUserInfo(userInfo); + EXPECT_EQ(res, statesMap); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_0500 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0500, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + OverlayModuleInfo overlayModuleInfo; + overlayModuleInfo.bundleName = NO_EXIST; + ErrCode res = overlayDataMgr.ObtainOverlayModuleState(overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_0600 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0600, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + InnerBundleInfo targetInnerBundleInfo; + + ClearDataMgr(); + auto resCode = overlayDataMgr.UpdateExternalOverlayInfo(newInfo, oldInfo, targetInnerBundleInfo); + EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); + ResetDataMgr(); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_0700 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0700, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo oldInfo; + + ClearDataMgr(); + auto resBool = overlayDataMgr.QueryOverlayInnerBundleInfo(TEST_BUNDLE_NAME, oldInfo); + EXPECT_EQ(resBool, false); + ResetDataMgr(); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_0800 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0800, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo oldInfo; + + ClearDataMgr(); + OverlayModuleInfo overlayModuleInfo; + ErrCode resCode = overlayDataMgr.SaveInternalOverlayModuleState(overlayModuleInfo, oldInfo); + EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_SERVICE_EXCEPTION); + ResetDataMgr(); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_0900 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_0900, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo oldInfo; + InnerBundleInfo targetBundleInfo; + + ClearDataMgr(); + OverlayModuleInfo overlayModuleInfo; + ErrCode resCode = overlayDataMgr.SaveExternalOverlayModuleState( + overlayModuleInfo, targetBundleInfo, USERID, oldInfo); + EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); + ResetDataMgr(); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_1000 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1000, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo oldInfo; + + ClearDataMgr(); + std::vector overlayModuleInfos; + ErrCode resCode = overlayDataMgr.GetAllOverlayModuleInfo(TEST_BUNDLE_NAME, overlayModuleInfos, USERID); + EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); + ResetDataMgr(); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_1100 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1100, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo oldInfo; + + ClearDataMgr(); + OverlayModuleInfo overlayModuleInfo; + ErrCode resCode = overlayDataMgr.GetOverlayModuleInfo( + TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, USERID); + EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); + ResetDataMgr(); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_1200 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1200, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + + ClearDataMgr(); + std::vector overlayBundleInfo; + ErrCode resCode = overlayDataMgr.GetOverlayBundleInfoForTarget( + TEST_MODULE_NAME, overlayBundleInfo, USERID); + EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); + ResetDataMgr(); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_1300 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1300, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + + ClearDataMgr(); + std::vector overlayModuleInfos; + ErrCode resCode = overlayDataMgr.GetOverlayModuleInfoForTarget( + TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfos, USERID); + EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); + ResetDataMgr(); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_1400 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1400, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + + ClearDataMgr(); + OverlayModuleInfo overlayModuleInfo; + ErrCode resCode = overlayDataMgr.ObtainOverlayModuleState(overlayModuleInfo, USERID); + EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); + ResetDataMgr(); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_1500 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1500, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + + ClearDataMgr(); + bool isEnabled = false; + ErrCode resCode = overlayDataMgr.SetOverlayEnabled(TEST_BUNDLE_NAME, TEST_MODULE_NAME, isEnabled, USERID); + EXPECT_EQ(resCode, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); + ResetDataMgr(); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_1600 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1600, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + + ClearDataMgr(); + std::string resString = overlayDataMgr.GetCallingBundleName(); + EXPECT_EQ(resString.empty(), true); + ResetDataMgr(); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_1700 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1700, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo oldInfo; + oldInfo.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); + EXPECT_EQ(oldInfo.GetOverlayType(), OVERLAY_EXTERNAL_BUNDLE); + + ClearDataMgr(); + EXPECT_EQ(bundleMgrService_->dataMgr_, nullptr); + BuildInternalOverlayConnection(TEST_MODULE_NAME, oldInfo, USERID); + ResetDataMgr(); + EXPECT_NE(bundleMgrService_->dataMgr_, nullptr); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_1900 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_1900, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo targetInnerBundleInfo; + + ClearDataMgr(); + EXPECT_EQ(bundleMgrService_->dataMgr_, nullptr); + RemoveOverlayBundleInfo(TEST_MODULE_NAME, targetInnerBundleInfo); + ResetDataMgr(); + EXPECT_NE(bundleMgrService_->dataMgr_, nullptr); +} + +/** + * @tc.number: TestOverlayByDataMgrFalse_2300 + * @tc.name: test TestOverlayByDataMgrFalse. + * @tc.desc: 1.test overlay by dataMgr is nullptr. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, TestOverlayByDataMgrFalse_2300, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo newInfo; + InnerBundleUserInfo userInfo; + + ClearDataMgr(); + EXPECT_EQ(bundleMgrService_->dataMgr_, nullptr); + AddOverlayModuleStates(newInfo, userInfo); + ResetDataMgr(); + EXPECT_NE(bundleMgrService_->dataMgr_, nullptr); +} + +/** + * @tc.number: CheckAppLabel_0010 + * @tc.name: test CheckAppLabel + * @tc.desc: 1.Test the CheckAppLabel +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckAppLabel_0010, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + InnerBundleInfo oldInfo; + InnerBundleInfo newInfo; + oldInfo.baseApplicationInfo_->targetBundleName = TEST_MODULE_NAME; + ErrCode res = installer.CheckAppLabel(oldInfo, newInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_TARGET_BUNDLE_NAME_NOT_SAME); +} + +/** + * @tc.number: CheckAppLabel_0020 + * @tc.name: test CheckAppLabel + * @tc.desc: 1.Test the CheckAppLabel +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckAppLabel_0020, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + InnerBundleInfo oldInfo; + InnerBundleInfo newInfo; + oldInfo.baseApplicationInfo_->targetPriority = FOUR; + ErrCode res = installer.CheckAppLabel(oldInfo, newInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_TARGET_PRIORITY_NOT_SAME); +} + +/** + * @tc.number: CheckOverlayInstallation_0010 + * @tc.name: test CheckOverlayInstallation + * @tc.desc: 1.Test the CheckOverlayInstallation +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayInstallation_0010, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + std::unordered_map newInfos; + InnerBundleInfo newInfo; + newInfo.SetOverlayState(NON_OVERLAY_TYPE); + newInfos.try_emplace(TEST_MODULE_NAME, newInfo); + ErrCode res = installer.CheckOverlayInstallation(newInfos, USERID); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: CheckOverlayInstallation_0020 + * @tc.name: test CheckOverlayInstallation + * @tc.desc: 1.Test the CheckOverlayInstallation +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayInstallation_0020, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + std::unordered_map newInfos; + InnerBundleInfo info1; + info1.SetOverlayType(OVERLAY_INTERNAL_BUNDLE); + newInfos.try_emplace(TEST_MODULE_NAME, info1); + ErrCode res = installer.CheckOverlayInstallation(newInfos, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_HAP_TYPE); +} + +/** + * @tc.number: CheckOverlayInstallation_0030 + * @tc.name: test CheckOverlayInstallation + * @tc.desc: 1.Test the CheckOverlayInstallation +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayInstallation_0030, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + std::unordered_map newInfos; + InnerBundleInfo info1; + info1.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); + newInfos.try_emplace(TEST_MODULE_NAME, info1); + ErrCode res = installer.CheckOverlayInstallation(newInfos, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_ERROR_HAP_TYPE); +} + +/** + * @tc.number: GetNotifyType_0010 + * @tc.name: test GetNotifyType + * @tc.desc: 1.Test the GetNotifyType +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, GetNotifyType_0010, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + installer.isAppExist_ = true; + installer.hasInstalledInUser_ = true; + installer.overlayType_ = OVERLAY_EXTERNAL_BUNDLE; + NotifyType res = installer.GetNotifyType(); + EXPECT_EQ(res, NotifyType::OVERLAY_UPDATE); +} + +/** + * @tc.number: GetNotifyType_0020 + * @tc.name: test GetNotifyType + * @tc.desc: 1.Test the GetNotifyType +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, GetNotifyType_0020, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + installer.isAppExist_ = true; + installer.hasInstalledInUser_ = true; + installer.overlayType_ = NON_OVERLAY_TYPE; + NotifyType res = installer.GetNotifyType(); + EXPECT_EQ(res, NotifyType::UPDATE); +} + +/** + * @tc.number: GetNotifyType_0030 + * @tc.name: test GetNotifyType + * @tc.desc: 1.Test the GetNotifyType +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, GetNotifyType_0030, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + installer.isAppExist_ = false; + installer.hasInstalledInUser_ = true; + installer.overlayType_ = OVERLAY_EXTERNAL_BUNDLE; + NotifyType res = installer.GetNotifyType(); + EXPECT_EQ(res, NotifyType::OVERLAY_INSTALL); +} + +/** + * @tc.number: GetNotifyType_0040 + * @tc.name: test GetNotifyType + * @tc.desc: 1.Test the GetNotifyType +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, GetNotifyType_0040, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + installer.isAppExist_ = true; + installer.hasInstalledInUser_ = false; + installer.overlayType_ = NON_OVERLAY_TYPE; + NotifyType res = installer.GetNotifyType(); + EXPECT_EQ(res, NotifyType::INSTALL); +} + +/** + * @tc.number: CheckOverlayUpdate_0010 + * @tc.name: test CheckOverlayUpdate + * @tc.desc: 1.Test the CheckOverlayUpdate +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayUpdate_0010, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + InnerBundleInfo oldInfo; + InnerBundleInfo newInfo; + newInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); + oldInfo.SetOverlayType(OverlayType::OVERLAY_INTERNAL_BUNDLE); + ErrCode res = installer.CheckOverlayUpdate(oldInfo, newInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_OVERLAY_TYPE_NOT_SAME); +} + +/** + * @tc.number: CheckOverlayUpdate_0030 + * @tc.name: test CheckOverlayUpdate + * @tc.desc: 1.Test the CheckOverlayUpdate +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayUpdate_0030, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + InnerBundleInfo oldInfo; + InnerBundleInfo newInfo; + oldInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); + newInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); + newInfo.currentPackage_ = TEST_PACK_AGE; + ErrCode res = installer.CheckOverlayUpdate(oldInfo, newInfo, USERID); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: CheckOverlayUpdate_0040 + * @tc.name: test CheckOverlayUpdate + * @tc.desc: 1.Test the CheckOverlayUpdate +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayUpdate_0040, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + InnerBundleInfo oldInfo; + InnerBundleInfo newInfo; + oldInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); + newInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); + + newInfo.currentPackage_ = TEST_PACK_AGE; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.targetModuleName = ""; + oldInfo.innerModuleInfos_[TEST_PACK_AGE] = innerModuleInfo; + ErrCode res = installer.CheckOverlayUpdate(oldInfo, newInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_OVERLAY_TYPE_NOT_SAME); +} + +/** + * @tc.number: CheckOverlayUpdate_0050 + * @tc.name: test CheckOverlayUpdate + * @tc.desc: 1.Test the CheckOverlayUpdate +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayUpdate_0050, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + InnerBundleInfo oldInfo; + InnerBundleInfo newInfo; + oldInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); + newInfo.SetOverlayType(OverlayType::NON_OVERLAY_TYPE); + + newInfo.currentPackage_ = TEST_PACK_AGE; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.targetModuleName = "targetModuleName"; + oldInfo.innerModuleInfos_[TEST_PACK_AGE] = innerModuleInfo; + ErrCode res = installer.CheckOverlayUpdate(oldInfo, newInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_OVERLAY_TYPE_NOT_SAME); +} + +/** + * @tc.number: CheckOverlayUpdate_0060 + * @tc.name: test CheckOverlayUpdate + * @tc.desc: 1.Test the CheckOverlayUpdate +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayUpdate_0060, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + InnerBundleInfo oldInfo; + InnerBundleInfo newInfo; + oldInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); + newInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); + + newInfo.currentPackage_ = TEST_PACK_AGE; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.targetModuleName = "targetModuleName"; + oldInfo.innerModuleInfos_[TEST_PACK_AGE] = innerModuleInfo; + ErrCode res = installer.CheckOverlayUpdate(oldInfo, newInfo, USERID); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: CopyHapsToSecurityDir_0010 + * @tc.name: test CopyHapsToSecurityDir + * @tc.desc: 1.Test the CopyHapsToSecurityDir +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, CopyHapsToSecurityDir_0010, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + InstallParam installParam; + installParam.withCopyHaps = true; + std::vector bundlePaths; + bundlePaths.push_back("data/test/test"); + ErrCode res = installer.CopyHapsToSecurityDir(installParam, bundlePaths); + EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_DISK_MEM_INSUFFICIENT); +} + +/** + * @tc.number: CopyHapsToSecurityDir_0020 + * @tc.name: test CopyHapsToSecurityDir + * @tc.desc: 1.Test the CopyHapsToSecurityDir +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, CopyHapsToSecurityDir_0020, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + InstallParam installParam; + installParam.withCopyHaps = true; + std::vector bundlePaths; + ErrCode res = installer.CopyHapsToSecurityDir(installParam, bundlePaths); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: FindSignatureFileDir_0010 + * @tc.name: test FindSignatureFileDir + * @tc.desc: 1.Test the FindSignatureFileDir +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, FindSignatureFileDir_0010, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + std::string signatureFileDir; + + installer.verifyCodeParams_.emplace(TEST_MODULE_NAME, TEST_MODULE_NAME); + ErrCode res = installer.FindSignatureFileDir(TEST_MODULE_NAME + "1", signatureFileDir); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_INSTALL_CODE_SIGNATURE_FAILED); +} + +/** + * @tc.number: FindSignatureFileDir_0020 + * @tc.name: test FindSignatureFileDir + * @tc.desc: 1.Test the FindSignatureFileDir +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, FindSignatureFileDir_0020, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + std::string signatureFileDir; + + installer.verifyCodeParams_.emplace(TEST_MODULE_NAME, TEST_MODULE_NAME); + ErrCode res = installer.FindSignatureFileDir(TEST_MODULE_NAME, signatureFileDir); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_INSTALL_CODE_SIGNATURE_FILE_IS_INVALID); +} + +/** + * @tc.number: FindSignatureFileDir_0030 + * @tc.name: test FindSignatureFileDir + * @tc.desc: 1.Test the FindSignatureFileDir +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, FindSignatureFileDir_0030, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + std::string signatureFileDir = "testModuleName.sig"; + + installer.verifyCodeParams_.emplace(TEST_MODULE_NAME, signatureFileDir); + ErrCode res = installer.FindSignatureFileDir(TEST_MODULE_NAME, signatureFileDir); + EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_DISK_MEM_INSUFFICIENT); +} } // OHOS \ No newline at end of file -- Gitee From adca41c9f1ceb302c14ad90f4e62fc2a08ef85f1 Mon Sep 17 00:00:00 2001 From: xinking129 Date: Tue, 16 Jan 2024 16:01:59 +0800 Subject: [PATCH 4/6] Format modification Signed-off-by: xinking129 --- ...ms_bundle_get_overlay_module_info_test.cpp | 1476 ++++++++--------- 1 file changed, 738 insertions(+), 738 deletions(-) diff --git a/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_get_overlay_module_info_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_get_overlay_module_info_test.cpp index 2d13df2a99..83a8a373b6 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_get_overlay_module_info_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_get_overlay_module_info_test.cpp @@ -1,738 +1,738 @@ -/* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define private public - -#include - -#include "appexecfwk_errors.h" -#include "bundle_overlay_data_manager.h" -#include "bundle_overlay_install_checker.h" -#include "bundle_overlay_manager.h" -#include "bundle_mgr_service.h" - -using namespace testing::ext; -using namespace OHOS::AppExecFwk; -using OHOS::DelayedSingleton; - -namespace OHOS { -namespace { -const std::string TEST_MODULE_NAME = "testModuleName"; -const std::string TEST_MODULE_NAME_SECOND = "testModuleNameSecond"; -const std::string TEST_MODULE_NAME_THIRD = "testModuleNameThird"; -const std::string TARGET_MODULE_NAME = "targetModuleName"; -const std::string TEST_BUNDLE_NAME = "testBundleName"; -const std::string TEST_HAP_PATH = "testHapPath"; -const std::string TEST_TARGET_BUNDLE_NAME = "testTargetBundleName"; -const std::string TEST_OVERLAY_BUNDLE_DIR = "testBundleDir"; -const int32_t DEFAULT_TARGET_PRIORITY_SECOND = 1; -const int32_t USERID = 100; -const int32_t UNSPECIFIED_USERID = -2; -const int32_t TEST_USERID = 101; -const int32_t OVERLAY_MODULE_INFO_SIZE = 1; -const int32_t DEFAULT_OVERLAY_MODULE_INFO_SIZE = 0; -const int32_t WAIT_TIME = 5; // init mocked bms -} // namespace - -class BmsBundleGetOverlayModuleInfoTest : public testing::Test { -public: - BmsBundleGetOverlayModuleInfoTest(); - ~BmsBundleGetOverlayModuleInfoTest(); - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); - - void AddOverlayInnerBundleInfo(int32_t overlayType); - void AddNonOverlayInnerBundleInfo(); - void AddOverlayBundleInfo(); - void RemoveBundleInfo(const std::string &bundleName); - void CheckEnabledState(int32_t state); - void CheckOverlayModuleInfo(const OverlayModuleInfo &info); - void CheckOverlayBundleInfo(const OverlayBundleInfo &info); - - const std::shared_ptr GetBundleDataMgr() const; - -private: - static std::shared_ptr bundleMgrService_; -}; - -std::shared_ptr BmsBundleGetOverlayModuleInfoTest::bundleMgrService_ = - DelayedSingleton::GetInstance(); - -BmsBundleGetOverlayModuleInfoTest::BmsBundleGetOverlayModuleInfoTest() -{} - -BmsBundleGetOverlayModuleInfoTest::~BmsBundleGetOverlayModuleInfoTest() -{} - -void BmsBundleGetOverlayModuleInfoTest::SetUpTestCase() -{} - -void BmsBundleGetOverlayModuleInfoTest::TearDownTestCase() -{ - bundleMgrService_->OnStop(); -} -void BmsBundleGetOverlayModuleInfoTest::SetUp() -{ - if (!bundleMgrService_->IsServiceReady()) { - bundleMgrService_->OnStart(); - std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME)); - } -} - -void BmsBundleGetOverlayModuleInfoTest::TearDown() -{} - -void BmsBundleGetOverlayModuleInfoTest::AddOverlayInnerBundleInfo(int32_t overlayType) -{ - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.name = TEST_MODULE_NAME; - innerModuleInfo.moduleName = TEST_MODULE_NAME; - innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; - innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; - innerModuleInfo.hapPath = TEST_HAP_PATH; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - ApplicationInfo applicationInfo; - applicationInfo.bundleName = TEST_BUNDLE_NAME; - innerBundleInfo.SetBaseApplicationInfo(applicationInfo); - innerBundleInfo.SetOverlayType(overlayType); - - InnerModuleInfo secondInnerModuleInfo; - secondInnerModuleInfo.name = TEST_MODULE_NAME_SECOND; - secondInnerModuleInfo.moduleName = TEST_MODULE_NAME_SECOND; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME_SECOND, secondInnerModuleInfo); - - InnerModuleInfo targetModuleInfo; - targetModuleInfo.name = TARGET_MODULE_NAME; - targetModuleInfo.moduleName = TARGET_MODULE_NAME; - OverlayModuleInfo overlayModuleInfo; - overlayModuleInfo.bundleName = TEST_BUNDLE_NAME; - overlayModuleInfo.moduleName = TEST_MODULE_NAME; - overlayModuleInfo.targetModuleName = TARGET_MODULE_NAME; - overlayModuleInfo.hapPath = TEST_HAP_PATH; - overlayModuleInfo.priority = DEFAULT_TARGET_PRIORITY_SECOND; - targetModuleInfo.overlayModuleInfo.emplace_back(overlayModuleInfo); - innerBundleInfo.InsertInnerModuleInfo(TARGET_MODULE_NAME, targetModuleInfo); - - InnerBundleUserInfo userInfo; - userInfo.bundleUserInfo.userId = USERID; - std::string state = TEST_MODULE_NAME + Constants::FILE_UNDERLINE + std::to_string(OVERLAY_ENABLE); - userInfo.bundleUserInfo.overlayModulesState.emplace_back(state); - innerBundleInfo.AddInnerBundleUserInfo(userInfo); - - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); - dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, innerBundleInfo); -} - -void BmsBundleGetOverlayModuleInfoTest::AddNonOverlayInnerBundleInfo() -{ - InnerBundleInfo innerBundleInfo; - InnerModuleInfo innerModuleInfo; - innerModuleInfo.name = TEST_MODULE_NAME; - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); - ApplicationInfo applicationInfo; - applicationInfo.bundleName = TEST_BUNDLE_NAME; - innerBundleInfo.SetBaseApplicationInfo(applicationInfo); - - InnerBundleUserInfo userInfo; - userInfo.bundleUserInfo.userId = USERID; - innerBundleInfo.AddInnerBundleUserInfo(userInfo); - - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); - innerBundleInfo.SetBaseApplicationInfo(applicationInfo); - dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); - dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, innerBundleInfo); -} - -void BmsBundleGetOverlayModuleInfoTest::RemoveBundleInfo(const std::string &bundleName) -{ - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - bool startRet = dataMgr->UpdateBundleInstallState(bundleName, InstallState::UNINSTALL_START); - bool finishRet = dataMgr->UpdateBundleInstallState(bundleName, InstallState::UNINSTALL_SUCCESS); - - EXPECT_TRUE(startRet); - EXPECT_TRUE(finishRet); -} - -void BmsBundleGetOverlayModuleInfoTest::CheckOverlayModuleInfo(const OverlayModuleInfo &info) -{ - EXPECT_EQ(info.bundleName, TEST_BUNDLE_NAME); - EXPECT_EQ(info.moduleName, TEST_MODULE_NAME); - EXPECT_EQ(info.hapPath, TEST_HAP_PATH); - EXPECT_EQ(info.targetModuleName, TARGET_MODULE_NAME); - EXPECT_EQ(info.state, OVERLAY_ENABLE); - EXPECT_EQ(info.priority, DEFAULT_TARGET_PRIORITY_SECOND); -} - -void BmsBundleGetOverlayModuleInfoTest::CheckOverlayBundleInfo(const OverlayBundleInfo &info) -{ - EXPECT_EQ(info.bundleName, TEST_BUNDLE_NAME); - EXPECT_EQ(info.bundleDir, TEST_OVERLAY_BUNDLE_DIR); - EXPECT_EQ(info.state, OVERLAY_ENABLE); - EXPECT_EQ(info.priority, DEFAULT_TARGET_PRIORITY_SECOND); -} - -void BmsBundleGetOverlayModuleInfoTest::AddOverlayBundleInfo() -{ - InnerBundleInfo innerBundleInfo; - OverlayBundleInfo info; - info.bundleName = TEST_BUNDLE_NAME; - info.bundleDir = TEST_OVERLAY_BUNDLE_DIR; - info.state = OVERLAY_ENABLE; - info.priority = DEFAULT_TARGET_PRIORITY_SECOND; - innerBundleInfo.AddOverlayBundleInfo(info); - - InnerBundleUserInfo userInfo; - userInfo.bundleUserInfo.userId = USERID; - innerBundleInfo.AddInnerBundleUserInfo(userInfo); - - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - dataMgr->UpdateBundleInstallState(TEST_TARGET_BUNDLE_NAME, InstallState::INSTALL_START); - dataMgr->AddInnerBundleInfo(TEST_TARGET_BUNDLE_NAME, innerBundleInfo); -} - -const std::shared_ptr BmsBundleGetOverlayModuleInfoTest::GetBundleDataMgr() const -{ - return bundleMgrService_->GetDataMgr(); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_0100 - * @tc.name: test GetAllOverlayModuleInfo interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified bundleName is not existed. - * 2.get failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0100, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - std::vector vec; - auto res = hostImpl->GetAllOverlayModuleInfo(TEST_BUNDLE_NAME, vec); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_0200 - * @tc.name: test GetAllOverlayModuleInfo interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified bundle is not installed at specified user. - * 2.get failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0200, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); - - std::vector vec; - auto res = hostImpl->GetAllOverlayModuleInfo(TEST_BUNDLE_NAME, vec, TEST_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_0300 - * @tc.name: test GetAllOverlayModuleInfo interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified bundle does not contain any overlay module. - * 2.get failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0300, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddNonOverlayInnerBundleInfo(); - - std::vector vec; - auto res = hostImpl->GetAllOverlayModuleInfo(TEST_BUNDLE_NAME, vec, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_NON_OVERLAY_BUNDLE); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_0400 - * @tc.name: test GetAllOverlayModuleInfo interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified bundle is valid bundle - * 2.get successfully. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0400, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); - - std::vector vec; - auto res = hostImpl->GetAllOverlayModuleInfo(TEST_BUNDLE_NAME, vec, USERID); - EXPECT_EQ(res, ERR_OK); - - EXPECT_EQ(vec.size(), OVERLAY_MODULE_INFO_SIZE); - CheckOverlayModuleInfo(vec[0]); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_0500 - * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified bundleName is not existed. - * 2.get failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0500, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - OverlayModuleInfo overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_0600 - * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified bundle is not installed at specified user. - * 2.get failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0600, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); - - OverlayModuleInfo overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, TEST_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_0700 - * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified bundle is not overlay bundle - * 2.get failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0700, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddNonOverlayInnerBundleInfo(); - - OverlayModuleInfo overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_NON_OVERLAY_BUNDLE); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_0800 - * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified module is not existed. - * 2.get failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0800, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); - - OverlayModuleInfo overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_MODULE_NAME_THIRD, overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_MODULE); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_0900 - * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified bundle is not overlay bundle - * 2.get failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0900, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); - - OverlayModuleInfo overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_MODULE_NAME_SECOND, overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_NON_OVERLAY_MODULE); - auto res1 = hostImpl->GetOverlayModuleInfo("", TEST_MODULE_NAME_SECOND, overlayModuleInfo, USERID); - EXPECT_EQ(res1, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - auto res2 = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, "", overlayModuleInfo, USERID); - EXPECT_EQ(res2, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_1100 - * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified bundle and module are valid - * 2.get successfully. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1100, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); - - OverlayModuleInfo overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_OK); - - CheckOverlayModuleInfo(overlayModuleInfo); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_1200 - * @tc.name: test GetOverlayBundleInfoForTarget interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified target bundle name is not existed. - * 2.get failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1200, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - std::vector overlayBundleInfo; - auto res = hostImpl->GetOverlayBundleInfoForTarget(TEST_BUNDLE_NAME, overlayBundleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_NOT_EXISTED); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_1300 - * @tc.name: test GetOverlayBundleInfoForTarget interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified target bundle does not installed at specified user. - * 2.get failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1300, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddOverlayBundleInfo(); - - std::vector overlayBundleInfo; - auto res = hostImpl->GetOverlayBundleInfoForTarget(TEST_TARGET_BUNDLE_NAME, overlayBundleInfo, TEST_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); - RemoveBundleInfo(TEST_TARGET_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_1400 - * @tc.name: test GetOverlayBundleInfoForTarget interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified target bundle is valid. - * 2.get successfully. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1400, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddOverlayBundleInfo(); - - std::vector overlayBundleInfo; - auto res = hostImpl->GetOverlayBundleInfoForTarget(TEST_TARGET_BUNDLE_NAME, overlayBundleInfo, USERID); - EXPECT_EQ(res, ERR_OK); - - EXPECT_EQ(overlayBundleInfo.size(), OVERLAY_MODULE_INFO_SIZE); - CheckOverlayBundleInfo(overlayBundleInfo[0]); - RemoveBundleInfo(TEST_TARGET_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_1500 - * @tc.name: test GetOverlayBundleInfoForTarget interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified target bundle is valid. - * 2.get successfully. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1500, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddNonOverlayInnerBundleInfo(); - - std::vector overlayBundleInfo; - auto res = hostImpl->GetOverlayBundleInfoForTarget(TEST_BUNDLE_NAME, overlayBundleInfo, USERID); - EXPECT_EQ(res, ERR_OK); - EXPECT_EQ(overlayBundleInfo.size(), DEFAULT_OVERLAY_MODULE_INFO_SIZE); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_1600 - * @tc.name: test GetOverlayModuleInfoForTarget interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified target bundle is not existed. - * 2.get successfully. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1600, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - std::vector overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfoForTarget(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_NOT_EXISTED); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_1700 - * @tc.name: test GetOverlayModuleInfoForTarget interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified target bundle is external overlay bundle. - * 2.get successfully. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1700, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddOverlayInnerBundleInfo(OverlayType::OVERLAY_EXTERNAL_BUNDLE); - - std::vector overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfoForTarget(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_IS_OVERLAY_BUNDLE); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_1800 - * @tc.name: test GetOverlayModuleInfoForTarget interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified target bundle is not installed at specified user. - * 2.get failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1800, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); - - std::vector overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfoForTarget(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, - TEST_USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_1900 - * @tc.name: test GetOverlayModuleInfoForTarget interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified target module is not existed. - * 2.get failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1900, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); - - std::vector overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfoForTarget(TEST_BUNDLE_NAME, TEST_MODULE_NAME_THIRD, overlayModuleInfo, - USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_MODULE_NOT_EXISTED); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_2000 - * @tc.name: test GetOverlayModuleInfoForTarget interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified target module is overlay module. - * 2.get failed. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_2000, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); - - std::vector overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfoForTarget(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_MODULE_IS_OVERLAY_MODULE); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_2100 - * @tc.name: test GetOverlayModuleInfoForTarget interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified target bundle is valid. - * 2.get successfully. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_2100, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); - - std::vector overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfoForTarget(TEST_BUNDLE_NAME, TEST_MODULE_NAME_SECOND, overlayModuleInfo, - USERID); - EXPECT_EQ(res, ERR_OK); - EXPECT_EQ(overlayModuleInfo.size(), DEFAULT_OVERLAY_MODULE_INFO_SIZE); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_2200 - * @tc.name: test GetOverlayModuleInfoForTarget interface in OverlayManagerHostImpl. - * @tc.desc: 1.the specified target bundle is valid. - * 2.get successfully. - * @tc.require: issueI6F3H9 - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_2200, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); - - std::vector overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfoForTarget(TEST_BUNDLE_NAME, TARGET_MODULE_NAME, overlayModuleInfo, - USERID); - EXPECT_EQ(res, ERR_OK); - EXPECT_EQ(overlayModuleInfo.size(), OVERLAY_MODULE_INFO_SIZE); - - CheckOverlayModuleInfo(overlayModuleInfo[0]); - RemoveBundleInfo(TEST_BUNDLE_NAME); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_2300 - * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl - * @tc.desc: 1.the specified bundle is valid bundle - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_2300, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - OverlayModuleInfo overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfo("", overlayModuleInfo, USERID); - EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_2400 - * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl - * @tc.desc: 1.the specified bundle is valid bundle - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_2400, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - OverlayModuleInfo overlayModuleInfo; - auto res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, overlayModuleInfo, UNSPECIFIED_USERID); - EXPECT_NE(res, ERR_OK); - - res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, overlayModuleInfo, USERID); - EXPECT_NE(res, ERR_OK); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_2500 - * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl - * @tc.desc: 1.the specified bundle is valid bundle - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_2500, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - std::vector overlayModuleInfos; - auto res = hostImpl->GetTargetOverlayModuleInfo(TARGET_MODULE_NAME, overlayModuleInfos, UNSPECIFIED_USERID); - EXPECT_NE(res, ERR_OK); -} - -/** - * @tc.number: GetOverlayModuleInfoTest_2600 - * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl - * @tc.desc: 1.the specified bundle is valid bundle - */ -HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_2600, Function | SmallTest | Level0) -{ - // get OverlayManagerHostImpl instance - auto hostImpl = std::make_shared(); - EXPECT_NE(hostImpl, nullptr); - - auto res = hostImpl->SetOverlayEnabledForSelf(TARGET_MODULE_NAME, false, UNSPECIFIED_USERID); - EXPECT_NE(res, ERR_OK); -} -} // OHOS +/* + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public + +#include + +#include "appexecfwk_errors.h" +#include "bundle_overlay_data_manager.h" +#include "bundle_overlay_install_checker.h" +#include "bundle_overlay_manager.h" +#include "bundle_mgr_service.h" + +using namespace testing::ext; +using namespace OHOS::AppExecFwk; +using OHOS::DelayedSingleton; + +namespace OHOS { +namespace { +const std::string TEST_MODULE_NAME = "testModuleName"; +const std::string TEST_MODULE_NAME_SECOND = "testModuleNameSecond"; +const std::string TEST_MODULE_NAME_THIRD = "testModuleNameThird"; +const std::string TARGET_MODULE_NAME = "targetModuleName"; +const std::string TEST_BUNDLE_NAME = "testBundleName"; +const std::string TEST_HAP_PATH = "testHapPath"; +const std::string TEST_TARGET_BUNDLE_NAME = "testTargetBundleName"; +const std::string TEST_OVERLAY_BUNDLE_DIR = "testBundleDir"; +const int32_t DEFAULT_TARGET_PRIORITY_SECOND = 1; +const int32_t USERID = 100; +const int32_t UNSPECIFIED_USERID = -2; +const int32_t TEST_USERID = 101; +const int32_t OVERLAY_MODULE_INFO_SIZE = 1; +const int32_t DEFAULT_OVERLAY_MODULE_INFO_SIZE = 0; +const int32_t WAIT_TIME = 5; // init mocked bms +} // namespace + +class BmsBundleGetOverlayModuleInfoTest : public testing::Test { +public: + BmsBundleGetOverlayModuleInfoTest(); + ~BmsBundleGetOverlayModuleInfoTest(); + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); + + void AddOverlayInnerBundleInfo(int32_t overlayType); + void AddNonOverlayInnerBundleInfo(); + void AddOverlayBundleInfo(); + void RemoveBundleInfo(const std::string &bundleName); + void CheckEnabledState(int32_t state); + void CheckOverlayModuleInfo(const OverlayModuleInfo &info); + void CheckOverlayBundleInfo(const OverlayBundleInfo &info); + + const std::shared_ptr GetBundleDataMgr() const; + +private: + static std::shared_ptr bundleMgrService_; +}; + +std::shared_ptr BmsBundleGetOverlayModuleInfoTest::bundleMgrService_ = + DelayedSingleton::GetInstance(); + +BmsBundleGetOverlayModuleInfoTest::BmsBundleGetOverlayModuleInfoTest() +{} + +BmsBundleGetOverlayModuleInfoTest::~BmsBundleGetOverlayModuleInfoTest() +{} + +void BmsBundleGetOverlayModuleInfoTest::SetUpTestCase() +{} + +void BmsBundleGetOverlayModuleInfoTest::TearDownTestCase() +{ + bundleMgrService_->OnStop(); +} +void BmsBundleGetOverlayModuleInfoTest::SetUp() +{ + if (!bundleMgrService_->IsServiceReady()) { + bundleMgrService_->OnStart(); + std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME)); + } +} + +void BmsBundleGetOverlayModuleInfoTest::TearDown() +{} + +void BmsBundleGetOverlayModuleInfoTest::AddOverlayInnerBundleInfo(int32_t overlayType) +{ + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.name = TEST_MODULE_NAME; + innerModuleInfo.moduleName = TEST_MODULE_NAME; + innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; + innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; + innerModuleInfo.hapPath = TEST_HAP_PATH; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + ApplicationInfo applicationInfo; + applicationInfo.bundleName = TEST_BUNDLE_NAME; + innerBundleInfo.SetBaseApplicationInfo(applicationInfo); + innerBundleInfo.SetOverlayType(overlayType); + + InnerModuleInfo secondInnerModuleInfo; + secondInnerModuleInfo.name = TEST_MODULE_NAME_SECOND; + secondInnerModuleInfo.moduleName = TEST_MODULE_NAME_SECOND; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME_SECOND, secondInnerModuleInfo); + + InnerModuleInfo targetModuleInfo; + targetModuleInfo.name = TARGET_MODULE_NAME; + targetModuleInfo.moduleName = TARGET_MODULE_NAME; + OverlayModuleInfo overlayModuleInfo; + overlayModuleInfo.bundleName = TEST_BUNDLE_NAME; + overlayModuleInfo.moduleName = TEST_MODULE_NAME; + overlayModuleInfo.targetModuleName = TARGET_MODULE_NAME; + overlayModuleInfo.hapPath = TEST_HAP_PATH; + overlayModuleInfo.priority = DEFAULT_TARGET_PRIORITY_SECOND; + targetModuleInfo.overlayModuleInfo.emplace_back(overlayModuleInfo); + innerBundleInfo.InsertInnerModuleInfo(TARGET_MODULE_NAME, targetModuleInfo); + + InnerBundleUserInfo userInfo; + userInfo.bundleUserInfo.userId = USERID; + std::string state = TEST_MODULE_NAME + Constants::FILE_UNDERLINE + std::to_string(OVERLAY_ENABLE); + userInfo.bundleUserInfo.overlayModulesState.emplace_back(state); + innerBundleInfo.AddInnerBundleUserInfo(userInfo); + + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); + dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, innerBundleInfo); +} + +void BmsBundleGetOverlayModuleInfoTest::AddNonOverlayInnerBundleInfo() +{ + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.name = TEST_MODULE_NAME; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + ApplicationInfo applicationInfo; + applicationInfo.bundleName = TEST_BUNDLE_NAME; + innerBundleInfo.SetBaseApplicationInfo(applicationInfo); + + InnerBundleUserInfo userInfo; + userInfo.bundleUserInfo.userId = USERID; + innerBundleInfo.AddInnerBundleUserInfo(userInfo); + + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + innerBundleInfo.SetBaseApplicationInfo(applicationInfo); + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); + dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, innerBundleInfo); +} + +void BmsBundleGetOverlayModuleInfoTest::RemoveBundleInfo(const std::string &bundleName) +{ + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + bool startRet = dataMgr->UpdateBundleInstallState(bundleName, InstallState::UNINSTALL_START); + bool finishRet = dataMgr->UpdateBundleInstallState(bundleName, InstallState::UNINSTALL_SUCCESS); + + EXPECT_TRUE(startRet); + EXPECT_TRUE(finishRet); +} + +void BmsBundleGetOverlayModuleInfoTest::CheckOverlayModuleInfo(const OverlayModuleInfo &info) +{ + EXPECT_EQ(info.bundleName, TEST_BUNDLE_NAME); + EXPECT_EQ(info.moduleName, TEST_MODULE_NAME); + EXPECT_EQ(info.hapPath, TEST_HAP_PATH); + EXPECT_EQ(info.targetModuleName, TARGET_MODULE_NAME); + EXPECT_EQ(info.state, OVERLAY_ENABLE); + EXPECT_EQ(info.priority, DEFAULT_TARGET_PRIORITY_SECOND); +} + +void BmsBundleGetOverlayModuleInfoTest::CheckOverlayBundleInfo(const OverlayBundleInfo &info) +{ + EXPECT_EQ(info.bundleName, TEST_BUNDLE_NAME); + EXPECT_EQ(info.bundleDir, TEST_OVERLAY_BUNDLE_DIR); + EXPECT_EQ(info.state, OVERLAY_ENABLE); + EXPECT_EQ(info.priority, DEFAULT_TARGET_PRIORITY_SECOND); +} + +void BmsBundleGetOverlayModuleInfoTest::AddOverlayBundleInfo() +{ + InnerBundleInfo innerBundleInfo; + OverlayBundleInfo info; + info.bundleName = TEST_BUNDLE_NAME; + info.bundleDir = TEST_OVERLAY_BUNDLE_DIR; + info.state = OVERLAY_ENABLE; + info.priority = DEFAULT_TARGET_PRIORITY_SECOND; + innerBundleInfo.AddOverlayBundleInfo(info); + + InnerBundleUserInfo userInfo; + userInfo.bundleUserInfo.userId = USERID; + innerBundleInfo.AddInnerBundleUserInfo(userInfo); + + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + dataMgr->UpdateBundleInstallState(TEST_TARGET_BUNDLE_NAME, InstallState::INSTALL_START); + dataMgr->AddInnerBundleInfo(TEST_TARGET_BUNDLE_NAME, innerBundleInfo); +} + +const std::shared_ptr BmsBundleGetOverlayModuleInfoTest::GetBundleDataMgr() const +{ + return bundleMgrService_->GetDataMgr(); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_0100 + * @tc.name: test GetAllOverlayModuleInfo interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified bundleName is not existed. + * 2.get failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0100, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + std::vector vec; + auto res = hostImpl->GetAllOverlayModuleInfo(TEST_BUNDLE_NAME, vec); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_0200 + * @tc.name: test GetAllOverlayModuleInfo interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified bundle is not installed at specified user. + * 2.get failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0200, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); + + std::vector vec; + auto res = hostImpl->GetAllOverlayModuleInfo(TEST_BUNDLE_NAME, vec, TEST_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); + RemoveBundleInfo(TEST_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_0300 + * @tc.name: test GetAllOverlayModuleInfo interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified bundle does not contain any overlay module. + * 2.get failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0300, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddNonOverlayInnerBundleInfo(); + + std::vector vec; + auto res = hostImpl->GetAllOverlayModuleInfo(TEST_BUNDLE_NAME, vec, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_NON_OVERLAY_BUNDLE); + RemoveBundleInfo(TEST_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_0400 + * @tc.name: test GetAllOverlayModuleInfo interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified bundle is valid bundle + * 2.get successfully. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0400, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); + + std::vector vec; + auto res = hostImpl->GetAllOverlayModuleInfo(TEST_BUNDLE_NAME, vec, USERID); + EXPECT_EQ(res, ERR_OK); + + EXPECT_EQ(vec.size(), OVERLAY_MODULE_INFO_SIZE); + CheckOverlayModuleInfo(vec[0]); + RemoveBundleInfo(TEST_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_0500 + * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified bundleName is not existed. + * 2.get failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0500, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + OverlayModuleInfo overlayModuleInfo; + auto res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_BUNDLE); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_0600 + * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified bundle is not installed at specified user. + * 2.get failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0600, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); + + OverlayModuleInfo overlayModuleInfo; + auto res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, TEST_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); + RemoveBundleInfo(TEST_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_0700 + * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified bundle is not overlay bundle + * 2.get failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0700, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddNonOverlayInnerBundleInfo(); + + OverlayModuleInfo overlayModuleInfo; + auto res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_NON_OVERLAY_BUNDLE); + RemoveBundleInfo(TEST_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_0800 + * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified module is not existed. + * 2.get failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0800, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); + + OverlayModuleInfo overlayModuleInfo; + auto res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_MODULE_NAME_THIRD, overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_MISSING_OVERLAY_MODULE); + RemoveBundleInfo(TEST_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_0900 + * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified bundle is not overlay bundle + * 2.get failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_0900, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); + + OverlayModuleInfo overlayModuleInfo; + auto res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_MODULE_NAME_SECOND, overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_NON_OVERLAY_MODULE); + auto res1 = hostImpl->GetOverlayModuleInfo("", TEST_MODULE_NAME_SECOND, overlayModuleInfo, USERID); + EXPECT_EQ(res1, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + auto res2 = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, "", overlayModuleInfo, USERID); + EXPECT_EQ(res2, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); + RemoveBundleInfo(TEST_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_1100 + * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified bundle and module are valid + * 2.get successfully. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1100, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); + + OverlayModuleInfo overlayModuleInfo; + auto res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_OK); + + CheckOverlayModuleInfo(overlayModuleInfo); + RemoveBundleInfo(TEST_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_1200 + * @tc.name: test GetOverlayBundleInfoForTarget interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified target bundle name is not existed. + * 2.get failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1200, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + std::vector overlayBundleInfo; + auto res = hostImpl->GetOverlayBundleInfoForTarget(TEST_BUNDLE_NAME, overlayBundleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_NOT_EXISTED); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_1300 + * @tc.name: test GetOverlayBundleInfoForTarget interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified target bundle does not installed at specified user. + * 2.get failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1300, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddOverlayBundleInfo(); + + std::vector overlayBundleInfo; + auto res = hostImpl->GetOverlayBundleInfoForTarget(TEST_TARGET_BUNDLE_NAME, overlayBundleInfo, TEST_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); + RemoveBundleInfo(TEST_TARGET_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_1400 + * @tc.name: test GetOverlayBundleInfoForTarget interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified target bundle is valid. + * 2.get successfully. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1400, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddOverlayBundleInfo(); + + std::vector overlayBundleInfo; + auto res = hostImpl->GetOverlayBundleInfoForTarget(TEST_TARGET_BUNDLE_NAME, overlayBundleInfo, USERID); + EXPECT_EQ(res, ERR_OK); + + EXPECT_EQ(overlayBundleInfo.size(), OVERLAY_MODULE_INFO_SIZE); + CheckOverlayBundleInfo(overlayBundleInfo[0]); + RemoveBundleInfo(TEST_TARGET_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_1500 + * @tc.name: test GetOverlayBundleInfoForTarget interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified target bundle is valid. + * 2.get successfully. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1500, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddNonOverlayInnerBundleInfo(); + + std::vector overlayBundleInfo; + auto res = hostImpl->GetOverlayBundleInfoForTarget(TEST_BUNDLE_NAME, overlayBundleInfo, USERID); + EXPECT_EQ(res, ERR_OK); + EXPECT_EQ(overlayBundleInfo.size(), DEFAULT_OVERLAY_MODULE_INFO_SIZE); + RemoveBundleInfo(TEST_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_1600 + * @tc.name: test GetOverlayModuleInfoForTarget interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified target bundle is not existed. + * 2.get successfully. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1600, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + std::vector overlayModuleInfo; + auto res = hostImpl->GetOverlayModuleInfoForTarget(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_NOT_EXISTED); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_1700 + * @tc.name: test GetOverlayModuleInfoForTarget interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified target bundle is external overlay bundle. + * 2.get successfully. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1700, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddOverlayInnerBundleInfo(OverlayType::OVERLAY_EXTERNAL_BUNDLE); + + std::vector overlayModuleInfo; + auto res = hostImpl->GetOverlayModuleInfoForTarget(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_BUNDLE_IS_OVERLAY_BUNDLE); + RemoveBundleInfo(TEST_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_1800 + * @tc.name: test GetOverlayModuleInfoForTarget interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified target bundle is not installed at specified user. + * 2.get failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1800, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); + + std::vector overlayModuleInfo; + auto res = hostImpl->GetOverlayModuleInfoForTarget(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, + TEST_USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_BUNDLE_NOT_INSTALLED_AT_SPECIFIED_USERID); + RemoveBundleInfo(TEST_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_1900 + * @tc.name: test GetOverlayModuleInfoForTarget interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified target module is not existed. + * 2.get failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_1900, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); + + std::vector overlayModuleInfo; + auto res = hostImpl->GetOverlayModuleInfoForTarget(TEST_BUNDLE_NAME, TEST_MODULE_NAME_THIRD, overlayModuleInfo, + USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_MODULE_NOT_EXISTED); + RemoveBundleInfo(TEST_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_2000 + * @tc.name: test GetOverlayModuleInfoForTarget interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified target module is overlay module. + * 2.get failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_2000, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); + + std::vector overlayModuleInfo; + auto res = hostImpl->GetOverlayModuleInfoForTarget(TEST_BUNDLE_NAME, TEST_MODULE_NAME, overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_TARGET_MODULE_IS_OVERLAY_MODULE); + RemoveBundleInfo(TEST_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_2100 + * @tc.name: test GetOverlayModuleInfoForTarget interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified target bundle is valid. + * 2.get successfully. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_2100, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); + + std::vector overlayModuleInfo; + auto res = hostImpl->GetOverlayModuleInfoForTarget(TEST_BUNDLE_NAME, TEST_MODULE_NAME_SECOND, overlayModuleInfo, + USERID); + EXPECT_EQ(res, ERR_OK); + EXPECT_EQ(overlayModuleInfo.size(), DEFAULT_OVERLAY_MODULE_INFO_SIZE); + RemoveBundleInfo(TEST_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_2200 + * @tc.name: test GetOverlayModuleInfoForTarget interface in OverlayManagerHostImpl. + * @tc.desc: 1.the specified target bundle is valid. + * 2.get successfully. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_2200, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + AddOverlayInnerBundleInfo(OverlayType::OVERLAY_INTERNAL_BUNDLE); + + std::vector overlayModuleInfo; + auto res = hostImpl->GetOverlayModuleInfoForTarget(TEST_BUNDLE_NAME, TARGET_MODULE_NAME, overlayModuleInfo, + USERID); + EXPECT_EQ(res, ERR_OK); + EXPECT_EQ(overlayModuleInfo.size(), OVERLAY_MODULE_INFO_SIZE); + + CheckOverlayModuleInfo(overlayModuleInfo[0]); + RemoveBundleInfo(TEST_BUNDLE_NAME); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_2300 + * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl + * @tc.desc: 1.the specified bundle is valid bundle + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_2300, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + OverlayModuleInfo overlayModuleInfo; + auto res = hostImpl->GetOverlayModuleInfo("", overlayModuleInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_2400 + * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl + * @tc.desc: 1.the specified bundle is valid bundle + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_2400, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + OverlayModuleInfo overlayModuleInfo; + auto res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, overlayModuleInfo, UNSPECIFIED_USERID); + EXPECT_NE(res, ERR_OK); + + res = hostImpl->GetOverlayModuleInfo(TEST_BUNDLE_NAME, overlayModuleInfo, USERID); + EXPECT_NE(res, ERR_OK); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_2500 + * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl + * @tc.desc: 1.the specified bundle is valid bundle + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_2500, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + std::vector overlayModuleInfos; + auto res = hostImpl->GetTargetOverlayModuleInfo(TARGET_MODULE_NAME, overlayModuleInfos, UNSPECIFIED_USERID); + EXPECT_NE(res, ERR_OK); +} + +/** + * @tc.number: GetOverlayModuleInfoTest_2600 + * @tc.name: test GetOverlayModuleInfo interface in OverlayManagerHostImpl + * @tc.desc: 1.the specified bundle is valid bundle + */ +HWTEST_F(BmsBundleGetOverlayModuleInfoTest, GetOverlayModuleInfoTest_2600, Function | SmallTest | Level0) +{ + // get OverlayManagerHostImpl instance + auto hostImpl = std::make_shared(); + EXPECT_NE(hostImpl, nullptr); + + auto res = hostImpl->SetOverlayEnabledForSelf(TARGET_MODULE_NAME, false, UNSPECIFIED_USERID); + EXPECT_NE(res, ERR_OK); +} +} // OHOS -- Gitee From c552c5a7e4924a29fb71a0d37f7ea53a2cc61700 Mon Sep 17 00:00:00 2001 From: xinking129 Date: Fri, 19 Jan 2024 17:39:16 +0800 Subject: [PATCH 5/6] recover Signed-off-by: xinking129 --- .../bms_bundle_overlay_checker_test.cpp | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_overlay_checker_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_overlay_checker_test.cpp index f610b2acfc..78859a028a 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_overlay_checker_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_overlay_test/bms_bundle_overlay_checker_test.cpp @@ -476,6 +476,59 @@ HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_0900, Function | SmallT EXPECT_TRUE(ret); } +/** + * @tc.number: OverlayCheckerTest_1000 + * @tc.name: test CheckInternalBundle interface in BundleOverlayInstallChecker. + * @tc.desc: 1.install internal overlay hap. + * 2.the version code of overlay hap is lower than non-overlay module. + * 3.check failed. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayCheckerTest_1000, Function | SmallTest | Level0) +{ + // construct overlay innerBundleInfo + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.name = TEST_MODULE_NAME; + innerModuleInfo.targetModuleName = TARGET_MODULE_NAME; + innerModuleInfo.targetPriority = DEFAULT_TARGET_PRIORITY_SECOND; + Distro distro; + distro.moduleType = SHARED_HAP_TYPE; + innerModuleInfo.distro = distro; + innerBundleInfo.InsertInnerModuleInfo(TEST_MODULE_NAME, innerModuleInfo); + BundleInfo bundleInfo; + bundleInfo.versionCode = LOWER_TEST_VERSION_CODE; + innerBundleInfo.SetBaseBundleInfo(bundleInfo); + innerBundleInfo.SetCurrentModulePackage(TEST_MODULE_NAME); + ApplicationInfo applicationInfo; + applicationInfo.bundleName = TEST_BUNDLE_NAME; + innerBundleInfo.SetBaseApplicationInfo(applicationInfo); + std::unordered_map newInfos; + + // construct old innerBundleInfo + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + + InnerBundleInfo oldInfo; + InnerModuleInfo oldInnerModuleInfo; + oldInnerModuleInfo.name = TEST_MODULE_NAME_SECOND; + oldInfo.InsertInnerModuleInfo(TEST_MODULE_NAME_SECOND, oldInnerModuleInfo); + BundleInfo oldBundleInfo; + oldBundleInfo.versionCode = TEST_VERSION_CODE; + oldInfo.SetBaseBundleInfo(oldBundleInfo); + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::INSTALL_START); + dataMgr->AddInnerBundleInfo(TEST_BUNDLE_NAME, oldInfo); + + auto overlayChecker = GetBundleOverlayChecker(); + EXPECT_NE(overlayChecker, nullptr); + auto res = overlayChecker->CheckInternalBundle(newInfos, innerBundleInfo); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INCONSISTENT_VERSION_CODE); + + dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_START); + bool ret = dataMgr->UpdateBundleInstallState(TEST_BUNDLE_NAME, InstallState::UNINSTALL_SUCCESS); + EXPECT_TRUE(ret); +} + /** * @tc.number: BundleOverlayManagerTest_0100 * @tc.name: check param is empty @@ -1544,6 +1597,41 @@ HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3600, Function | SmallTest EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR); } +/** + * @tc.number: OverlayDataMgr_3700 + * @tc.name: test OverlayDataMgr. + * @tc.desc: 1.OverlayDataMgr of RemoveOverlayModuleConnection. + * 2.system run normally. + * @tc.require: issueI6F3H9 + */ +HWTEST_F(BmsBundleOverlayCheckerTest, OverlayDataMgr_3700, Function | SmallTest | Level0) +{ + OverlayDataMgr overlayDataMgr; + InnerBundleInfo newInfo; + InnerBundleInfo oldInfo; + std::map innerModuleInfos; + InnerModuleInfo moduleInfo; + moduleInfo.moduleName = TEST_PACK_AGE; + moduleInfo.distro.moduleType = Profile::MODULE_TYPE_ENTRY; + innerModuleInfos[TEST_PACK_AGE] = moduleInfo; + newInfo.AddInnerModuleInfo(innerModuleInfos); + oldInfo.AddInnerModuleInfo(innerModuleInfos); + newInfo.SetOverlayType(OVERLAY_EXTERNAL_BUNDLE); + + auto dataMgr = GetBundleDataMgr(); + EXPECT_NE(dataMgr, nullptr); + + ApplicationInfo applicationInfo; + applicationInfo.bundleName = TEST_BUNDLE_NAME; + oldInfo.SetBaseApplicationInfo(applicationInfo); + newInfo.SetTargetBundleName(NO_EXIST); + oldInfo.SetTargetBundleName(TEST_BUNDLE_NAME); + dataMgr->bundleInfos_.insert( + pair(TEST_BUNDLE_NAME, oldInfo)); + ErrCode res = overlayDataMgr.RemoveOverlayModuleConnection(newInfo, oldInfo); + EXPECT_EQ(res, ERR_OK); +} + /** * @tc.number: OverlayDataMgr_3800 * @tc.name: test OverlayDataMgr. @@ -2678,6 +2766,22 @@ HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayUpdate_0010, Function | SmallT EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_OVERLAY_TYPE_NOT_SAME); } +/** + * @tc.number: CheckOverlayUpdate_0020 + * @tc.name: test CheckOverlayUpdate + * @tc.desc: 1.Test the CheckOverlayUpdate +*/ +HWTEST_F(BmsBundleOverlayCheckerTest, CheckOverlayUpdate_0020, Function | SmallTest | Level0) +{ + BaseBundleInstaller installer; + InnerBundleInfo oldInfo; + InnerBundleInfo newInfo; + oldInfo.SetOverlayType(OverlayType::OVERLAY_EXTERNAL_BUNDLE); + newInfo.SetOverlayType(OverlayType::OVERLAY_INTERNAL_BUNDLE); + ErrCode res = installer.CheckOverlayUpdate(oldInfo, newInfo, USERID); + EXPECT_EQ(res, ERR_BUNDLEMANAGER_OVERLAY_INSTALLATION_FAILED_OVERLAY_TYPE_NOT_SAME); +} + /** * @tc.number: CheckOverlayUpdate_0030 * @tc.name: test CheckOverlayUpdate -- Gitee From b363fbf65d56f9cbbfe69f73324efdbed3a07426 Mon Sep 17 00:00:00 2001 From: xinking129 Date: Mon, 22 Jan 2024 09:36:23 +0800 Subject: [PATCH 6/6] Code text formatting fixed Signed-off-by: xinking129 --- ...undle_mgr_service_death_recipient_test.cpp | 114 +++++++++--------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/services/bundlemgr/test/unittest/bms_bundle_mgr_service_death_recipient_test/bms_bundle_mgr_service_death_recipient_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_mgr_service_death_recipient_test/bms_bundle_mgr_service_death_recipient_test.cpp index bef26d4406..865c0b39f7 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_mgr_service_death_recipient_test/bms_bundle_mgr_service_death_recipient_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_mgr_service_death_recipient_test/bms_bundle_mgr_service_death_recipient_test.cpp @@ -1,58 +1,58 @@ -/* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "appexecfwk_errors.h" -#define private public -#include "bundle_mgr_service_death_recipient.h" -#undef private - -using namespace testing::ext; -using testing::_; -namespace OHOS { -namespace AppExecFwk { - -class BmsBundleMgrServiceDeathRecipientTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); -}; - -void BmsBundleMgrServiceDeathRecipientTest::SetUpTestCase() {} - -void BmsBundleMgrServiceDeathRecipientTest::TearDownTestCase() {} - -void BmsBundleMgrServiceDeathRecipientTest::SetUp() {} - -void BmsBundleMgrServiceDeathRecipientTest::TearDown() {} - -/** - * @tc.number: BundleMgrServiceDeathRecipient_001 - * @tc.name: OnRemoteDied - * @tc.desc: When deathCallback_ is not empty, Successful case of verifying OnRemoteDied. - */ -HWTEST_F(BmsBundleMgrServiceDeathRecipientTest, BundleMgrServiceDeathRecipient_001, TestSize.Level1) -{ - const std::function& object)> deathCallback; - const wptr object; - BundleMgrServiceDeathRecipient bundleMgrServiceDeathRecipient(deathCallback); - bundleMgrServiceDeathRecipient.OnRemoteDied(object); - EXPECT_EQ(bundleMgrServiceDeathRecipient.deathCallback_, nullptr); -} -} // namespace AppExecFwk +/* + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "appexecfwk_errors.h" +#define private public +#include "bundle_mgr_service_death_recipient.h" +#undef private + +using namespace testing::ext; +using testing::_; +namespace OHOS { +namespace AppExecFwk { + +class BmsBundleMgrServiceDeathRecipientTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void BmsBundleMgrServiceDeathRecipientTest::SetUpTestCase() {} + +void BmsBundleMgrServiceDeathRecipientTest::TearDownTestCase() {} + +void BmsBundleMgrServiceDeathRecipientTest::SetUp() {} + +void BmsBundleMgrServiceDeathRecipientTest::TearDown() {} + +/** + * @tc.number: BundleMgrServiceDeathRecipient_001 + * @tc.name: OnRemoteDied + * @tc.desc: When deathCallback_ is not empty, Successful case of verifying OnRemoteDied. + */ +HWTEST_F(BmsBundleMgrServiceDeathRecipientTest, BundleMgrServiceDeathRecipient_001, TestSize.Level1) +{ + const std::function& object)> deathCallback; + const wptr object; + BundleMgrServiceDeathRecipient bundleMgrServiceDeathRecipient(deathCallback); + bundleMgrServiceDeathRecipient.OnRemoteDied(object); + EXPECT_EQ(bundleMgrServiceDeathRecipient.deathCallback_, nullptr); +} +} // namespace AppExecFwk } // namespace OHOS \ No newline at end of file -- Gitee