From 7c156b86aba6bfb8b2ae35f73acb7c1232c2e82e Mon Sep 17 00:00:00 2001 From: xinking129 Date: Tue, 16 Jan 2024 14:09:20 +0800 Subject: [PATCH 1/3] tdd rectify and improve Signed-off-by: xinking129 --- .../bms_bundle_app_control_test/BUILD.gn | 4 +- .../bms_bundle_app_control_test.cpp | 18 +- .../bms_bundle_mock_app_control.cpp | 12 +- .../parameters.cpp | 35 ++ .../bms_bundle_app_control_test/parameters.h | 36 ++ .../bms_bundle_app_provision_info_test.cpp | 193 +--------- .../bms_bundle_common_test.cpp | 3 +- .../bms_bundle_data_storage_database_test.cpp | 12 +- .../bms_bundle_default_app_test.cpp | 214 +---------- .../bms_bundle_exception_handler_test.cpp | 20 +- .../bms_bundle_free_install_base_test.cpp | 23 +- .../bms_bundle_free_install_test.cpp | 47 ++- .../bms_bundle_installer_ipc_test.cpp | 19 - .../bms_bundle_installer_test.cpp | 20 +- .../bms_system_bundle_installer_test.cpp | 337 +++++++++++++++++- 15 files changed, 496 insertions(+), 497 deletions(-) create mode 100644 services/bundlemgr/test/unittest/bms_bundle_app_control_test/parameters.cpp create mode 100644 services/bundlemgr/test/unittest/bms_bundle_app_control_test/parameters.h diff --git a/services/bundlemgr/test/unittest/bms_bundle_app_control_test/BUILD.gn b/services/bundlemgr/test/unittest/bms_bundle_app_control_test/BUILD.gn index a2430ea56e..80cead099d 100755 --- a/services/bundlemgr/test/unittest/bms_bundle_app_control_test/BUILD.gn +++ b/services/bundlemgr/test/unittest/bms_bundle_app_control_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023 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 @@ -158,6 +158,7 @@ ohos_unittest("BmsBundleMockAppControlTest") { "//third_party/jsoncpp/include", "//third_party/json/include", "${services_path}/bundlemgr/include/app_control", + "parameters.h", ] sources = bundle_mgr_source sources -= [ "${services_path}/bundlemgr/src/bms_param.cpp" ] @@ -171,6 +172,7 @@ ohos_unittest("BmsBundleMockAppControlTest") { "${services_path}/bundlemgr/src/installd/installd_host_impl.cpp", "${services_path}/bundlemgr/src/installd/installd_operator.cpp", "${services_path}/bundlemgr/test/mock/src/installd_service.cpp", + "parameters.cpp", ] sources += [ diff --git a/services/bundlemgr/test/unittest/bms_bundle_app_control_test/bms_bundle_app_control_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_app_control_test/bms_bundle_app_control_test.cpp index 6a77cc88bc..e010fa4021 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_app_control_test/bms_bundle_app_control_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_app_control_test/bms_bundle_app_control_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 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 @@ -630,18 +630,8 @@ HWTEST_F(BmsBundleAppControlTest, DisposedStatus_0100, Function | SmallTest | Le want.SetAction("action.system.home"); auto res = appControlManagerDb_->SetDisposedStatus(CALLING_NAME, APPID, want, 100); EXPECT_EQ(res, ERR_OK); -} - -/** - * @tc.number: DisposedStatus_0200 - * @tc.name: test deleting disposed status - * @tc.require: issueI5MZ8C - * @tc.desc: 1.DeleteDisposedStatus test - */ -HWTEST_F(BmsBundleAppControlTest, DisposedStatus_0200, Function | SmallTest | Level1) -{ - auto res = appControlManagerDb_->DeleteDisposedStatus(CALLING_NAME, APPID, USERID); - EXPECT_EQ(res, ERR_OK); + auto delRes = appControlManagerDb_->DeleteDisposedStatus(CALLING_NAME, APPID, USERID); + EXPECT_EQ(delRes, ERR_OK); } /** @@ -659,6 +649,8 @@ HWTEST_F(BmsBundleAppControlTest, DisposedStatus_0300, Function | SmallTest | Le res = appControlManagerDb_->GetDisposedStatus(CALLING_NAME, APPID, want, USERID); EXPECT_EQ(res, ERR_OK); EXPECT_EQ(want.GetAction(), "action.system.home"); + auto delRes = appControlManagerDb_->DeleteDisposedStatus(CALLING_NAME, APPID, USERID); + EXPECT_EQ(delRes, ERR_OK); } /** diff --git a/services/bundlemgr/test/unittest/bms_bundle_app_control_test/bms_bundle_mock_app_control.cpp b/services/bundlemgr/test/unittest/bms_bundle_app_control_test/bms_bundle_mock_app_control.cpp index 10e27e2605..208863f2bc 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_app_control_test/bms_bundle_mock_app_control.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_app_control_test/bms_bundle_mock_app_control.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 @@ -394,7 +394,7 @@ HWTEST_F(BmsBundleMockAppControlTest, AppControlManagerHostImpl_0020, Function | setuid(AppControlConstants::FOUNDATION_UID); auto res = impl.ConfirmAppJumpControlRule("", "", USERID); - EXPECT_EQ(res, ERR_BUNDLE_MANAGER_INTERNAL_ERROR); + EXPECT_EQ(res, ERR_BUNDLE_MANAGER_APP_CONTROL_INTERNAL_ERROR); } /** @@ -409,7 +409,7 @@ HWTEST_F(BmsBundleMockAppControlTest, AppControlManagerHostImpl_0030, Function | setuid(AppControlConstants::FOUNDATION_UID); auto res = impl.AddAppJumpControlRule(controlRules, USERID); - EXPECT_EQ(res, ERR_BUNDLE_MANAGER_INTERNAL_ERROR); + EXPECT_EQ(res, ERR_BUNDLE_MANAGER_APP_CONTROL_INTERNAL_ERROR); } /** @@ -424,7 +424,7 @@ HWTEST_F(BmsBundleMockAppControlTest, AppControlManagerHostImpl_0040, Function | setuid(AppControlConstants::FOUNDATION_UID); auto res = impl.DeleteAppJumpControlRule(controlRules, USERID); - EXPECT_EQ(res, ERR_BUNDLE_MANAGER_INTERNAL_ERROR); + EXPECT_EQ(res, ERR_OK); } /** @@ -438,7 +438,7 @@ HWTEST_F(BmsBundleMockAppControlTest, AppControlManagerHostImpl_0050, Function | setuid(AppControlConstants::FOUNDATION_UID); auto res = impl.DeleteRuleByCallerBundleName("", USERID); - EXPECT_EQ(res, ERR_BUNDLE_MANAGER_INTERNAL_ERROR); + EXPECT_EQ(res, ERR_BUNDLE_MANAGER_APP_CONTROL_INTERNAL_ERROR); } /** @@ -452,7 +452,7 @@ HWTEST_F(BmsBundleMockAppControlTest, AppControlManagerHostImpl_0060, Function | setuid(AppControlConstants::FOUNDATION_UID); auto res = impl.DeleteRuleByTargetBundleName("", USERID); - EXPECT_EQ(res, ERR_BUNDLE_MANAGER_INTERNAL_ERROR); + EXPECT_EQ(res, ERR_BUNDLE_MANAGER_APP_CONTROL_INTERNAL_ERROR); } /** diff --git a/services/bundlemgr/test/unittest/bms_bundle_app_control_test/parameters.cpp b/services/bundlemgr/test/unittest/bms_bundle_app_control_test/parameters.cpp new file mode 100644 index 0000000000..35847897c9 --- /dev/null +++ b/services/bundlemgr/test/unittest/bms_bundle_app_control_test/parameters.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 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 "parameters.h" + +namespace OHOS { +namespace system { +bool GetBoolParameter(const std::string& key, bool def) +{ + return true; +} + +std::string GetParameter(const std::string& key, const std::string& def) +{ + return ""; +} + +std::string GetDeviceType() +{ + return "default"; +} +} // system +} // OHOS \ No newline at end of file diff --git a/services/bundlemgr/test/unittest/bms_bundle_app_control_test/parameters.h b/services/bundlemgr/test/unittest/bms_bundle_app_control_test/parameters.h new file mode 100644 index 0000000000..e392010a4a --- /dev/null +++ b/services/bundlemgr/test/unittest/bms_bundle_app_control_test/parameters.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 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. + */ + +#ifndef FOUNDATION_APPEXECFWK_SERVICES_PARAMETERS_H +#define FOUNDATION_APPEXECFWK_SERVICES_PARAMETERS_H + +#include + +namespace OHOS { +namespace system { +bool GetBoolParameter(const std::string& key, bool def); + +template +T GetIntParameter(const std::string& key, T def) +{ + return def; +} + +std::string GetParameter(const std::string& key, const std::string& def); + +std::string GetDeviceType(); +} // namespace system +} // namespace OHOS +#endif // FOUNDATION_APPEXECFWK_SERVICES_PARAMETERS_H \ No newline at end of file diff --git a/services/bundlemgr/test/unittest/bms_bundle_app_provision_info_test/bms_bundle_app_provision_info_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_app_provision_info_test/bms_bundle_app_provision_info_test.cpp index dc96651b5a..e67d32e849 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_app_provision_info_test/bms_bundle_app_provision_info_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_app_provision_info_test/bms_bundle_app_provision_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 @@ -264,52 +264,6 @@ HWTEST_F(BmsBundleAppProvisionInfoTest, BmsGetAppProvisionInfoTest_0002, Functio EXPECT_EQ(unInstallResult, ERR_OK); } -/** - * @tc.number: BmsGetAppProvisionInfoTest_0003 - * Function: GetAppProvisionInfo - * @tc.name: test GetAppProvisionInfo - * @tc.desc: 1. system running normally - * 2. GetAppProvisionInfo, bundleName exist, userId not exist - */ -HWTEST_F(BmsBundleAppProvisionInfoTest, BmsGetAppProvisionInfoTest_0003, Function | SmallTest | Level0) -{ - ErrCode installResult = InstallBundle(HAP_FILE_PATH1); - EXPECT_EQ(installResult, ERR_OK); - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - AppProvisionInfo appProvisionInfo; - ErrCode result = dataMgr->GetAppProvisionInfo(BUNDLE_NAME, WAIT_TIME, appProvisionInfo); - EXPECT_EQ(result, ERR_BUNDLE_MANAGER_INVALID_USER_ID); - EXPECT_TRUE(appProvisionInfo.type.empty()); - - ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); - EXPECT_EQ(unInstallResult, ERR_OK); -} - -/** - * @tc.number: BmsGetAppProvisionInfoTest_0004 - * Function: GetAppProvisionInfo - * @tc.name: test GetAppProvisionInfo - * @tc.desc: 1. system running normally - * 2. GetAppProvisionInfo, bundleName exist, userId exist - */ -HWTEST_F(BmsBundleAppProvisionInfoTest, BmsGetAppProvisionInfoTest_0004, Function | SmallTest | Level0) -{ - ErrCode installResult = InstallBundle(HAP_FILE_PATH1); - EXPECT_EQ(installResult, ERR_OK); - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - AppProvisionInfo appProvisionInfo; - ErrCode result = dataMgr->GetAppProvisionInfo(BUNDLE_NAME, USERID, appProvisionInfo); - EXPECT_EQ(result, ERR_OK); - EXPECT_EQ(appProvisionInfo.type, "release"); - - ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); - EXPECT_EQ(unInstallResult, ERR_OK); -} - /** * @tc.number: BmsGetAppProvisionInfoTest_0005 * Function: GetAppProvisionInfo @@ -1115,39 +1069,6 @@ HWTEST_F(BmsBundleAppProvisionInfoTest, ProcessBundleProvisionInfo_0002, Functio } } -/** - * @tc.number: ProcessBundleProvisionInfo_0003 - * @tc.name: test the start function of ProcessBundleProvisionInfo - * @tc.desc: 1. install hap - * 2. call ProcessBundleProvisionInfo - */ -HWTEST_F(BmsBundleAppProvisionInfoTest, ProcessBundleProvisionInfo_0003, Function | SmallTest | Level0) -{ - std::shared_ptr handler = std::make_shared(); - if (!handler) { - EXPECT_NE(handler, nullptr); - } else { - ErrCode installResult = InstallBundle(HAP_FILE_PATH1); - EXPECT_EQ(installResult, ERR_OK); - - std::unordered_set allBundleNames; - bool ret = - DelayedSingleton::GetInstance()->GetAllAppProvisionInfoBundleName(allBundleNames); - EXPECT_TRUE(ret); - EXPECT_FALSE(allBundleNames.empty()); - - handler->ProcessBundleProvisionInfo(allBundleNames); - AppProvisionInfo appProvisionInfo; - ret = DelayedSingleton::GetInstance()->GetAppProvisionInfo(BUNDLE_NAME, - appProvisionInfo); - EXPECT_TRUE(ret); - EXPECT_FALSE(appProvisionInfo.apl.empty()); - - ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); - EXPECT_EQ(unInstallResult, ERR_OK); - } -} - /** * @tc.number: ProcessBundleProvisionInfo_0004 * @tc.name: test the start function of ProcessBundleProvisionInfo @@ -1254,44 +1175,6 @@ HWTEST_F(BmsBundleAppProvisionInfoTest, ProcessSharedBundleProvisionInfo_0002, F } } -/** - * @tc.number: ProcessSharedBundleProvisionInfo_0003 - * @tc.name: test the start function of ProcessSharedBundleProvisionInfo - * @tc.desc: 1. install hap - * 2. call ProcessSharedBundleProvisionInfo - */ -HWTEST_F(BmsBundleAppProvisionInfoTest, ProcessSharedBundleProvisionInfo_0003, Function | SmallTest | Level0) -{ - std::shared_ptr handler = std::make_shared(); - if (!handler) { - EXPECT_NE(handler, nullptr); - } else { - std::vector bundlePath; - InstallParam installParam; - installParam.userId = USERID; - installParam.installFlag = InstallFlag::NORMAL; - installParam.sharedBundleDirPaths = std::vector{HSP_FILE_PATH1}; - ErrCode installResult = InstallBundle(bundlePath, installParam); - EXPECT_EQ(installResult, ERR_OK); - - std::unordered_set allBundleNames; - bool ret = - DelayedSingleton::GetInstance()->GetAllAppProvisionInfoBundleName(allBundleNames); - EXPECT_TRUE(ret); - EXPECT_FALSE(allBundleNames.empty()); - - handler->ProcessSharedBundleProvisionInfo(allBundleNames); - AppProvisionInfo appProvisionInfo; - ret = DelayedSingleton::GetInstance()->GetAppProvisionInfo(HSP_BUNDLE_NAME, - appProvisionInfo); - EXPECT_TRUE(ret); - EXPECT_FALSE(appProvisionInfo.apl.empty()); - - ErrCode unInstallResult = UninstallSharedBundle(HSP_BUNDLE_NAME); - EXPECT_EQ(unInstallResult, ERR_OK); - } -} - /** * @tc.number: ProcessSharedBundleProvisionInfo_0004 * @tc.name: test the start function of ProcessSharedBundleProvisionInfo @@ -1445,78 +1328,4 @@ HWTEST_F(BmsBundleAppProvisionInfoTest, ProcessRebootQuickFixBundleInstall_0002, EXPECT_EQ(unInstallResult, ERR_OK); } } - -/** - * @tc.number: ProcessRebootQuickFixBundleInstall_0003 - * @tc.name: test the start function of ProcessRebootQuickFixBundleInstall - * @tc.desc: 1. test ProcessRebootQuickFixBundleInstall - * 2. path exist, bundle exist, update failed - */ -HWTEST_F(BmsBundleAppProvisionInfoTest, ProcessRebootQuickFixBundleInstall_0003, Function | SmallTest | Level0) -{ - std::shared_ptr handler = std::make_shared(); - ASSERT_NE(handler, nullptr); - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - if ((handler != nullptr) && (dataMgr != nullptr)) { - ErrCode installResult = InstallBundle(HAP_FILE_PATH2); - EXPECT_EQ(installResult, ERR_OK); - - BundleInfo info; - bool result = dataMgr->GetBundleInfo(BUNDLE_NAME, 0, info, USERID); - EXPECT_TRUE(result); - EXPECT_EQ(info.name, BUNDLE_NAME); - - handler->ProcessRebootQuickFixBundleInstall(EXIST_PATH, false); - BundleInfo newInfo; - result = dataMgr->GetBundleInfo(BUNDLE_NAME, 0, newInfo, USERID); - EXPECT_TRUE(result); - EXPECT_EQ(info.versionCode, newInfo.versionCode); // update failed, versionCode is same - EXPECT_EQ(info.installTime, newInfo.updateTime); - - ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); - EXPECT_EQ(unInstallResult, ERR_OK); - } -} - -/** - * @tc.number: ProcessRebootQuickFixBundleInstall_0004 - * @tc.name: test the start function of ProcessRebootQuickFixBundleInstall - * @tc.desc: 1. test ProcessRebootQuickFixBundleInstall - * 2. path exist, bundle not exist, update failed - */ -HWTEST_F(BmsBundleAppProvisionInfoTest, ProcessRebootQuickFixBundleInstall_0004, Function | SmallTest | Level0) -{ - std::shared_ptr handler = std::make_shared(); - ASSERT_NE(handler, nullptr); - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - if ((handler != nullptr) && (dataMgr != nullptr)) { - handler->ProcessRebootQuickFixBundleInstall(EXIST_PATH, true); - BundleInfo newInfo; - bool result = dataMgr->GetBundleInfo(BUNDLE_NAME, 0, newInfo, USERID); - EXPECT_FALSE(result); - } -} - -/** - * @tc.number: ProcessRebootQuickFixBundleInstall_0005 - * @tc.name: test the start function of ProcessRebootQuickFixBundleInstall - * @tc.desc: 1. test ProcessRebootQuickFixBundleInstall - * 2. path exist, parse filed - */ -HWTEST_F(BmsBundleAppProvisionInfoTest, ProcessRebootQuickFixBundleInstall_0005, Function | SmallTest | Level0) -{ - std::shared_ptr handler = std::make_shared(); - ASSERT_NE(handler, nullptr); - auto dataMgr = GetBundleDataMgr(); - EXPECT_NE(dataMgr, nullptr); - if ((handler != nullptr) && (dataMgr != nullptr)) { - handler->ProcessRebootQuickFixBundleInstall(EXIST_PATH2, false); - BundleInfo newInfo; - bool result = dataMgr->GetBundleInfo(BUNDLE_NAME, 0, newInfo, USERID); - EXPECT_FALSE(result); - } -} - } // OHOS \ No newline at end of file diff --git a/services/bundlemgr/test/unittest/bms_bundle_common_test/bms_bundle_common_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_common_test/bms_bundle_common_test.cpp index f11dde80e2..16b08ce96e 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_common_test/bms_bundle_common_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_common_test/bms_bundle_common_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 @@ -98,6 +98,7 @@ HWTEST_F(BmsBundleCommonTest, CancelDelayTask_0200, Function | SmallTest | Level }; std::string taskName = "task"; serialQueue.ScheduleDelayTask(taskName, DISCONNECT_DELAY, registerEventListenerFunc); + EXPECT_NE(serialQueue.taskMap_.size(), 0); serialQueue.CancelDelayTask(taskName); EXPECT_EQ(serialQueue.taskMap_.size(), 0); diff --git a/services/bundlemgr/test/unittest/bms_bundle_data_storage_test/bms_bundle_data_storage_database_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_data_storage_test/bms_bundle_data_storage_database_test.cpp index 901b954ff5..fece1f9dff 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_data_storage_test/bms_bundle_data_storage_database_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_data_storage_test/bms_bundle_data_storage_database_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 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 @@ -1850,13 +1850,17 @@ HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_0400, Function | Smal { InnerBundleInfo info; BundleInfo bundleInfo; + bundleInfo.name = NAME; + info.SetBaseBundleInfo(bundleInfo); + EXPECT_EQ(info.baseBundleInfo_->name, NAME); ApplicationInfo applicationInfo; applicationInfo.bundleName = NAME; - info.SetBaseBundleInfo(bundleInfo); info.SetBaseApplicationInfo(applicationInfo); + EXPECT_EQ(info.baseApplicationInfo_->bundleName, NAME); nlohmann::json jsonObject; - info.FromJson(jsonObject); + auto ret = info.FromJson(jsonObject); EXPECT_EQ(applicationInfo.bundleName, NAME); + EXPECT_TRUE(ret); } /** @@ -1953,7 +1957,7 @@ HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_0900, Function | Smal hapModuleInfo.name = NAME; const int32_t flags = 0; info.GetModuleWithHashValue(flags, "", hapModuleInfo); - EXPECT_EQ(hapModuleInfo.name, NAME); + EXPECT_EQ(hapModuleInfo.hashValue.size(), 0); } /** diff --git a/services/bundlemgr/test/unittest/bms_bundle_default_app_test/bms_bundle_default_app_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_default_app_test/bms_bundle_default_app_test.cpp index 06a01637d1..b74130f86a 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_default_app_test/bms_bundle_default_app_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_default_app_test/bms_bundle_default_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 @@ -405,193 +405,6 @@ HWTEST_F(BmsBundleDefaultAppTest, BmsBundleDefaultApp_0600, Function | SmallTest EXPECT_NE(result, ERR_OK); } -/** - * @tc.number: BmsBundleDefaultApp_0700 - * @tc.name: test ResetDefaultApplication, file type test - * @tc.desc: 1. call SetDefaultApplication then call GetDefaultApplication, return not empty - * 2. call ResetDefaultApplication then call GetDefaultApplication, return empty - */ -HWTEST_F(BmsBundleDefaultAppTest, BmsBundleDefaultApp_0700, Function | SmallTest | Level1) -{ - auto defaultAppProxy = GetDefaultAppProxy(); - EXPECT_NE(defaultAppProxy, nullptr); - AAFwk::Want want; - ErrCode result = defaultAppProxy->SetDefaultApplication(USER_ID, DEFAULT_APP_WORD, want); - EXPECT_EQ(result, ERR_OK); - result = SetDefaultApplicationWrap(defaultAppProxy, DEFAULT_FILE_TYPE_WORD, DEFAULT_APP_WORD); - EXPECT_EQ(result, ERR_OK); - BundleInfo bundleInfo; - result = defaultAppProxy->GetDefaultApplication(USER_ID, DEFAULT_FILE_TYPE_WORD, bundleInfo); - EXPECT_EQ(result, ERR_OK); - EXPECT_EQ(bundleInfo.name, BUNDLE_NAME); - - result = defaultAppProxy->ResetDefaultApplication(USER_ID, DEFAULT_FILE_TYPE_WORD); - EXPECT_EQ(result, ERR_OK); - result = defaultAppProxy->GetDefaultApplication(USER_ID, DEFAULT_FILE_TYPE_WORD, bundleInfo); - EXPECT_NE(result, ERR_OK); -} - -/** - * @tc.number: BmsBundleDefaultApp_0800 - * @tc.name: test SetDefaultApplication, app type IMAGE - * @tc.desc: 1. call SetDefaultApplication, return true - * 2. call GetDefaultApplication, return true and the ability is same with SetDefaultApplication's ability - */ -HWTEST_F(BmsBundleDefaultAppTest, BmsBundleDefaultApp_0800, Function | SmallTest | Level1) -{ - auto defaultAppProxy = GetDefaultAppProxy(); - EXPECT_NE(defaultAppProxy, nullptr); - ErrCode result = SetDefaultApplicationWrap(defaultAppProxy, DEFAULT_APP_IMAGE, ABILITY_IMAGE); - EXPECT_EQ(result, ERR_OK); - - BundleInfo bundleInfo; - result = defaultAppProxy->GetDefaultApplication(USER_ID, DEFAULT_APP_IMAGE, bundleInfo); - EXPECT_EQ(result, ERR_OK); - EXPECT_EQ(bundleInfo.abilityInfos.size(), 1); - if (bundleInfo.abilityInfos.size() == 1) { - auto abilityInfo = bundleInfo.abilityInfos[0]; - EXPECT_EQ(abilityInfo.name, ABILITY_IMAGE); - } -} - -/** - * @tc.number: BmsBundleDefaultApp_0900 - * @tc.name: test SetDefaultApplication, app type BROWSER - * @tc.desc: 1. call SetDefaultApplication, return true - * 2. call GetDefaultApplication, return true and the ability is same with SetDefaultApplication's ability - */ -HWTEST_F(BmsBundleDefaultAppTest, BmsBundleDefaultApp_0900, Function | SmallTest | Level1) -{ - auto defaultAppProxy = GetDefaultAppProxy(); - EXPECT_NE(defaultAppProxy, nullptr); - ErrCode result = SetDefaultApplicationWrap(defaultAppProxy, DEFAULT_APP_BROWSER, ABILITY_BROWSER); - EXPECT_EQ(result, ERR_OK); - - BundleInfo bundleInfo; - result = defaultAppProxy->GetDefaultApplication(USER_ID, DEFAULT_APP_BROWSER, bundleInfo); - EXPECT_EQ(result, ERR_OK); - EXPECT_EQ(bundleInfo.abilityInfos.size(), 1); - if (bundleInfo.abilityInfos.size() == 1) { - auto abilityInfo = bundleInfo.abilityInfos[0]; - EXPECT_EQ(abilityInfo.name, ABILITY_BROWSER); - } -} - -/** - * @tc.number: BmsBundleDefaultApp_1000 - * @tc.name: test SetDefaultApplication, app type AUDIO - * @tc.desc: 1. call SetDefaultApplication, return true - * 2. call GetDefaultApplication, return true and the ability is same with SetDefaultApplication's ability - */ -HWTEST_F(BmsBundleDefaultAppTest, BmsBundleDefaultApp_1000, Function | SmallTest | Level1) -{ - auto defaultAppProxy = GetDefaultAppProxy(); - EXPECT_NE(defaultAppProxy, nullptr); - ErrCode result = SetDefaultApplicationWrap(defaultAppProxy, DEFAULT_APP_AUDIO, ABILITY_AUDIO); - EXPECT_EQ(result, ERR_OK); - - BundleInfo bundleInfo; - result = defaultAppProxy->GetDefaultApplication(USER_ID, DEFAULT_APP_AUDIO, bundleInfo); - EXPECT_EQ(result, ERR_OK); - EXPECT_EQ(bundleInfo.abilityInfos.size(), 1); - if (bundleInfo.abilityInfos.size() == 1) { - auto abilityInfo = bundleInfo.abilityInfos[0]; - EXPECT_EQ(abilityInfo.name, ABILITY_AUDIO); - } -} - -/** - * @tc.number: BmsBundleDefaultApp_1100 - * @tc.name: test SetDefaultApplication, app type PDF - * @tc.desc: 1. call SetDefaultApplication, return true - * 2. call GetDefaultApplication, return true and the ability is same with SetDefaultApplication's ability - */ -HWTEST_F(BmsBundleDefaultAppTest, BmsBundleDefaultApp_1100, Function | SmallTest | Level1) -{ - auto defaultAppProxy = GetDefaultAppProxy(); - EXPECT_NE(defaultAppProxy, nullptr); - ErrCode result = SetDefaultApplicationWrap(defaultAppProxy, DEFAULT_APP_PDF, ABILITY_PDF); - EXPECT_EQ(result, ERR_OK); - - BundleInfo bundleInfo; - result = defaultAppProxy->GetDefaultApplication(USER_ID, DEFAULT_APP_PDF, bundleInfo); - EXPECT_EQ(result, ERR_OK); - EXPECT_EQ(bundleInfo.abilityInfos.size(), 1); - if (bundleInfo.abilityInfos.size() == 1) { - auto abilityInfo = bundleInfo.abilityInfos[0]; - EXPECT_EQ(abilityInfo.name, ABILITY_PDF); - } -} - -/** - * @tc.number: BmsBundleDefaultApp_1200 - * @tc.name: test SetDefaultApplication, app type WORD - * @tc.desc: 1. call SetDefaultApplication, return true - * 2. call GetDefaultApplication, return true and the ability is same with SetDefaultApplication's ability - */ -HWTEST_F(BmsBundleDefaultAppTest, BmsBundleDefaultApp_1200, Function | SmallTest | Level1) -{ - auto defaultAppProxy = GetDefaultAppProxy(); - EXPECT_NE(defaultAppProxy, nullptr); - ErrCode result = SetDefaultApplicationWrap(defaultAppProxy, DEFAULT_APP_WORD, ABILITY_WORD); - EXPECT_EQ(result, ERR_OK); - - BundleInfo bundleInfo; - result = defaultAppProxy->GetDefaultApplication(USER_ID, DEFAULT_APP_WORD, bundleInfo); - EXPECT_EQ(result, ERR_OK); - EXPECT_EQ(bundleInfo.abilityInfos.size(), 1); - if (bundleInfo.abilityInfos.size() == 1) { - auto abilityInfo = bundleInfo.abilityInfos[0]; - EXPECT_EQ(abilityInfo.name, ABILITY_WORD); - } -} - -/** - * @tc.number: BmsBundleDefaultApp_1300 - * @tc.name: test SetDefaultApplication, app type EXCEL - * @tc.desc: 1. call SetDefaultApplication, return true - * 2. call GetDefaultApplication, return true and the ability is same with SetDefaultApplication's ability - */ -HWTEST_F(BmsBundleDefaultAppTest, BmsBundleDefaultApp_1300, Function | SmallTest | Level1) -{ - auto defaultAppProxy = GetDefaultAppProxy(); - EXPECT_NE(defaultAppProxy, nullptr); - ErrCode result = SetDefaultApplicationWrap(defaultAppProxy, DEFAULT_APP_EXCEL, ABILITY_EXCEL); - EXPECT_EQ(result, ERR_OK); - - BundleInfo bundleInfo; - result = defaultAppProxy->GetDefaultApplication(USER_ID, DEFAULT_APP_EXCEL, bundleInfo); - EXPECT_EQ(result, ERR_OK); - EXPECT_EQ(bundleInfo.abilityInfos.size(), 1); - if (bundleInfo.abilityInfos.size() == 1) { - auto abilityInfo = bundleInfo.abilityInfos[0]; - EXPECT_EQ(abilityInfo.name, ABILITY_EXCEL); - } -} - -/** - * @tc.number: BmsBundleDefaultApp_1400 - * @tc.name: test SetDefaultApplication, app type PPT - * @tc.desc: 1. call SetDefaultApplication, return true - * 2. call GetDefaultApplication, return true and the ability is same with SetDefaultApplication's ability - */ -HWTEST_F(BmsBundleDefaultAppTest, BmsBundleDefaultApp_1400, Function | SmallTest | Level1) -{ - auto defaultAppProxy = GetDefaultAppProxy(); - EXPECT_NE(defaultAppProxy, nullptr); - ErrCode result = SetDefaultApplicationWrap(defaultAppProxy, DEFAULT_APP_PPT, ABILITY_PPT); - EXPECT_EQ(result, ERR_OK); - - BundleInfo bundleInfo; - result = defaultAppProxy->GetDefaultApplication(USER_ID, DEFAULT_APP_PPT, bundleInfo); - EXPECT_EQ(result, ERR_OK); - EXPECT_EQ(bundleInfo.abilityInfos.size(), 1); - if (bundleInfo.abilityInfos.size() == 1) { - auto abilityInfo = bundleInfo.abilityInfos[0]; - EXPECT_EQ(abilityInfo.name, ABILITY_PPT); - } -} - /** * @tc.number: BmsBundleDefaultApp_1500 * @tc.name: test IsDefaultApplication, invalid type @@ -1160,28 +973,6 @@ HWTEST_F(BmsBundleDefaultAppTest, BmsBundleDefaultApp_5200, Function | SmallTest EXPECT_EQ(ret, false); } -/** - * @tc.number: BmsBundleDefaultApp_5300 - * @tc.name: test QueryInfoAndSkillsByElement - * @tc.desc: 1. test QueryInfoAndSkillsByElement false - */ -HWTEST_F(BmsBundleDefaultAppTest, BmsBundleDefaultApp_5300, Function | SmallTest | Level1) -{ - auto dataMgr = bundleMgrService_->GetDataMgr(); - EXPECT_NE(dataMgr, nullptr); - - Element element; - element.bundleName = BUNDLE_NAME; - element.moduleName = MODULE_NAME; - element.abilityName= ABILITY_NAME; - element.extensionName= ""; - - AbilityInfo abilityInfo; - ExtensionAbilityInfo extensionInfo; - std::vector skills; - auto ret = dataMgr->QueryInfoAndSkillsByElement(USER_ID, element, abilityInfo, extensionInfo, skills); - EXPECT_EQ(ret, true); -} /** * @tc.number: BmsBundleDefaultApp_5400 @@ -1368,11 +1159,10 @@ HWTEST_F(BmsBundleDefaultAppTest, BmsBundleDefaultApp_6400, Function | SmallTest { DefaultAppData defaultAppData; Element element; - defaultAppData.infos.insert(std::pair("1", element)); nlohmann::json jsonObject; defaultAppData.ToJson(jsonObject); defaultAppData.ParseDefaultApplicationConfig(jsonObject); - EXPECT_EQ(0, ERR_OK); + EXPECT_EQ(defaultAppData.infos.size(), 0); } /** diff --git a/services/bundlemgr/test/unittest/bms_bundle_exception_handler_test/bms_bundle_exception_handler_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_exception_handler_test/bms_bundle_exception_handler_test.cpp index 74b40edd89..4c0f07662b 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_exception_handler_test/bms_bundle_exception_handler_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_exception_handler_test/bms_bundle_exception_handler_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 @@ -101,8 +101,8 @@ HWTEST_F(BmsBundleExceptionHandlerTest, RemoveBundleAndDataDirTest_0300, TestSiz { GTEST_LOG_(INFO) << "RemoveBundleAndDataDirTest_0300 start"; int32_t userId = 0; - bool result = bundleExceptionHandler_->RemoveBundleAndDataDir(EMPTY_STRING, BUNDLE_OR_MOUDLE_DIR, userId); - EXPECT_EQ(result, false); + bool result = bundleExceptionHandler_->RemoveBundleAndDataDir(BUNDLE_DIR_NAME, BUNDLE_OR_MOUDLE_DIR, userId); + EXPECT_EQ(result, true); GTEST_LOG_(INFO) << "RemoveBundleAndDataDirTest_0300 end"; } @@ -114,8 +114,8 @@ HWTEST_F(BmsBundleExceptionHandlerTest, RemoveBundleAndDataDirTest_0300, TestSiz HWTEST_F(BmsBundleExceptionHandlerTest, RemoveBundleAndDataDirTest_0400, TestSize.Level1) { GTEST_LOG_(INFO) << "RemoveBundleAndDataDirTest_0400 start"; - int32_t userId = 100; - bool result = bundleExceptionHandler_->RemoveBundleAndDataDir(EMPTY_STRING, EMPTY_STRING, userId); + int32_t userId = 0; + bool result = bundleExceptionHandler_->RemoveBundleAndDataDir(EMPTY_STRING, BUNDLE_OR_MOUDLE_DIR, userId); EXPECT_EQ(result, false); GTEST_LOG_(INFO) << "RemoveBundleAndDataDirTest_0400 end"; } @@ -137,6 +137,7 @@ HWTEST_F(BmsBundleExceptionHandlerTest, HandleInvalidBundleTest_0100, TestSize.L bundleExceptionHandler_->HandleInvalidBundle(info, isBundleValid); auto data = info.GetInstallMark(); EXPECT_EQ(isBundleValid, true); + EXPECT_EQ(data.bundleName, "com.ohos.launcher"); GTEST_LOG_(INFO) << "HandleInvalidBundleTest_0100 end"; } @@ -154,6 +155,11 @@ HWTEST_F(BmsBundleExceptionHandlerTest, HandleInvalidBundleTest_0200, TestSize.L info.SetBundleStatus(data); bundleExceptionHandler_->HandleInvalidBundle(info, isBundleValid); EXPECT_EQ(info.GetBundleStatus(), InnerBundleInfo::BundleStatus::ENABLED); + InnerBundleInfo info1; + const InnerBundleInfo::BundleStatus data1 = InnerBundleInfo::BundleStatus::DISABLED; + info1.SetBundleStatus(data1); + bundleExceptionHandler_->HandleInvalidBundle(info1, isBundleValid); + EXPECT_EQ(info1.GetBundleStatus(), InnerBundleInfo::BundleStatus::DISABLED); GTEST_LOG_(INFO) << "HandleInvalidBundleTest_0200 end"; } @@ -187,7 +193,7 @@ HWTEST_F(BmsBundleExceptionHandlerTest, HandleInvalidBundleTest_0400, TestSize.L info.SetInstallMark(BUNDLE_NAME, Package_NAME, InstallExceptionStatus::INSTALL_START); bundleExceptionHandler_->HandleInvalidBundle(info, isBundleValid); auto data = info.GetInstallMark(); - EXPECT_EQ(isBundleValid, true); + EXPECT_EQ(data.bundleName, "com.ohos.launcher"); GTEST_LOG_(INFO) << "HandleInvalidBundleTest_0400 end"; } @@ -247,6 +253,8 @@ HWTEST_F(BmsBundleExceptionHandlerTest, HandleInvalidBundleTest_0700, TestSize.L info.SetInstallMark(BUNDLE_NAME, Package_NAME, InstallExceptionStatus::UNINSTALL_BUNDLE_START); bundleExceptionHandler_->HandleInvalidBundle(info, isBundleValid); EXPECT_EQ(isBundleValid, true); + auto data = info.GetInstallMark(); + EXPECT_EQ(data.bundleName, "com.ohos.launcher"); GTEST_LOG_(INFO) << "HandleInvalidBundleTest_0700 end"; } diff --git a/services/bundlemgr/test/unittest/bms_bundle_free_install_test/bms_bundle_free_install_base_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_free_install_test/bms_bundle_free_install_base_test.cpp index 7e53f2e070..30c87e84bb 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_free_install_test/bms_bundle_free_install_base_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_free_install_test/bms_bundle_free_install_base_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 @@ -212,27 +212,6 @@ HWTEST_F(BmsBundleFreeInstallBaseTest, BmsBundleFreeInstallBaseTest_0006, Functi EXPECT_TRUE(ret); } -/** - * @tc.number: BmsBundleFreeInstallBaseTest_0007 - * Function: InstallResultMarshalling - * @tc.name: test InstallResultMarshalling - * @tc.desc: InstallResultMarshalling - */ -HWTEST_F(BmsBundleFreeInstallBaseTest, BmsBundleFreeInstallBaseTest_0007, Function | SmallTest | Level0) -{ - Result installResult; - installResult.transactId = TRANSACT_ID; - installResult.resultMsg = RESULT_MSG; - installResult.retCode = VERSIONID; - Parcel parcel; - auto ret = installResult.Marshalling(parcel); - EXPECT_TRUE(ret); - auto unmarshalledResult = Result::Unmarshalling(parcel); - EXPECT_EQ(unmarshalledResult->transactId, TRANSACT_ID); - ret = unmarshalledResult->ReadFromParcel(parcel); - EXPECT_TRUE(ret); -} - /** * @tc.number: BmsBundleFreeInstallBaseTest_0008 * Function: TargetInfo diff --git a/services/bundlemgr/test/unittest/bms_bundle_free_install_test/bms_bundle_free_install_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_free_install_test/bms_bundle_free_install_test.cpp index 99f8873a72..d63e2cd2eb 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_free_install_test/bms_bundle_free_install_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_free_install_test/bms_bundle_free_install_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 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 @@ -771,10 +771,13 @@ HWTEST_F(BmsBundleFreeInstallTest, BmsBundleFreeInstallTest_0024, Function | Sma { auto connectAbilityMgr = GetBundleConnectAbilityMgr(); FreeInstallParams freeInstallParams; + connectAbilityMgr->serialQueue_->ScheduleDelayTask("1", 0, []{}); connectAbilityMgr->freeInstallParamsMap_.insert(pair("1", freeInstallParams)); std::string installResult = "{\"version\":\"1.0.0\", \"result\":{\"transactId\":\"1\"," "\"resultMsg\":\"free install success\", \"retCode\":0}}"; connectAbilityMgr->OnServiceCenterCall(installResult); + auto iter = connectAbilityMgr->serialQueue_->taskMap_.find("1"); + EXPECT_EQ(iter, connectAbilityMgr->serialQueue_->taskMap_.end()); EXPECT_NE(installResult, ""); if (connectAbilityMgr->freeInstallParamsMap_.find("1") != connectAbilityMgr->freeInstallParamsMap_.end()) { connectAbilityMgr->freeInstallParamsMap_.erase("1"); @@ -791,10 +794,13 @@ HWTEST_F(BmsBundleFreeInstallTest, BmsBundleFreeInstallTest_0026, Function | Sma { auto connectAbilityMgr = GetBundleConnectAbilityMgr(); FreeInstallParams freeInstallParams; + connectAbilityMgr->serialQueue_->ScheduleDelayTask("1", 0, []{}); connectAbilityMgr->freeInstallParamsMap_.insert(pair("1", freeInstallParams)); std::string installResult = "{\"version\":\"1.0.0\", \"result\":{\"transactId\":\"1\"," "\"resultMsg\":\"free install success\", \"retCode\":1}}"; connectAbilityMgr->OnServiceCenterCall(installResult); + auto iter = connectAbilityMgr->serialQueue_->taskMap_.find("1"); + EXPECT_EQ(iter, connectAbilityMgr->serialQueue_->taskMap_.end()); if (connectAbilityMgr->freeInstallParamsMap_.find("1") != connectAbilityMgr->freeInstallParamsMap_.end()) { connectAbilityMgr->freeInstallParamsMap_.erase("1"); } @@ -811,11 +817,14 @@ HWTEST_F(BmsBundleFreeInstallTest, BmsBundleFreeInstallTest_0027, Function | Sma { auto connectAbilityMgr = GetBundleConnectAbilityMgr(); FreeInstallParams freeInstallParams; + connectAbilityMgr->serialQueue_->ScheduleDelayTask("1", 0, []{}); freeInstallParams.serviceCenterFunction = ServiceCenterFunction::CONNECT_UPGRADE_INSTALL; connectAbilityMgr->freeInstallParamsMap_.insert(pair("1", freeInstallParams)); std::string installResult = "{\"version\":\"1.0.0\", \"result\":{\"transactId\":\"1\"," "\"resultMsg\":\"free install success\", \"retCode\":-1}}"; connectAbilityMgr->OnServiceCenterCall(installResult); + auto iter = connectAbilityMgr->serialQueue_->taskMap_.find("1"); + EXPECT_EQ(iter, connectAbilityMgr->serialQueue_->taskMap_.end()); EXPECT_NE(installResult, ""); if (connectAbilityMgr->freeInstallParamsMap_.find("1") != connectAbilityMgr->freeInstallParamsMap_.end()) { connectAbilityMgr->freeInstallParamsMap_.erase("1"); @@ -860,7 +869,7 @@ HWTEST_F(BmsBundleFreeInstallTest, BmsBundleFreeInstallTest_0029, Function | Sma int32_t userId = USERID; std::string transactId = "1"; connectAbilityMgr->SendCallBack(resultCode, want, userId, transactId); - EXPECT_EQ(transactId, "1"); + EXPECT_EQ(resultCode, 0); if (connectAbilityMgr->freeInstallParamsMap_.find(transactId) != connectAbilityMgr->freeInstallParamsMap_.end()) { connectAbilityMgr->freeInstallParamsMap_.erase(transactId); } @@ -886,7 +895,7 @@ HWTEST_F(BmsBundleFreeInstallTest, BmsBundleFreeInstallTest_0030, Function | Sma int32_t userId = USERID; std::string transactId = "1"; connectAbilityMgr->SendCallBack(resultCode, want, userId, transactId); - EXPECT_EQ(transactId, "1"); + EXPECT_EQ(resultCode, 1); if (connectAbilityMgr->freeInstallParamsMap_.find("1") != connectAbilityMgr->freeInstallParamsMap_.end()) { connectAbilityMgr->freeInstallParamsMap_.erase("1"); } @@ -1147,12 +1156,16 @@ HWTEST_F(BmsBundleFreeInstallTest, BundleConnectAbilityMgr_0006, Function | Smal if (bundleMgr != nullptr) { std::string transactId; Want want; + FreeInstallParams params; + bundleMgr->freeInstallParamsMap_.emplace(transactId, params); ElementName name; name.SetAbilityName(ABILITY_NAME_TEST); name.SetBundleName(BUNDLE_NAME); want.SetElement(name); - bundleMgr->SendCallBack(0, want, 100, transactId); - EXPECT_EQ(transactId, ""); + int32_t resultCode = 0; + bundleMgr->SendCallBack(resultCode, want, 100, transactId); + EXPECT_EQ(resultCode, 0); + EXPECT_FALSE(bundleMgr->freeInstallParamsMap_.empty()); } UninstallBundleInfo(BUNDLE_NAME); @@ -1178,11 +1191,13 @@ HWTEST_F(BmsBundleFreeInstallTest, BundleConnectAbilityMgr_0009, Function | Smal want.SetElement(name); TargetAbilityInfo targetAbilityInfo; FreeInstallParams freeInstallParams; + bundleMgr->freeInstallParamsMap_.emplace("", freeInstallParams); freeInstallParams.callback = nullptr; bundleMgr->SendRequest( 0, targetAbilityInfo, want, USERID, freeInstallParams); bundleMgr->SendCallBack( targetAbilityInfo.targetInfo.transactId, freeInstallParams); + EXPECT_FALSE(bundleMgr->freeInstallParamsMap_.empty()); EXPECT_EQ(freeInstallParams.callback, nullptr); EXPECT_EQ(targetAbilityInfo.targetInfo.transactId, ""); } @@ -1229,7 +1244,9 @@ HWTEST_F(BmsBundleFreeInstallTest, BundleConnectAbilityMgr_0015, Function | Smal connectAbilityMgr->freeInstallParamsMap_.insert(pair("1", freeInstallParams)); std::string transactId = "1"; connectAbilityMgr->OutTimeMonitor(transactId); - EXPECT_EQ(transactId, "1"); + + auto iter = connectAbilityMgr->serialQueue_->taskMap_.find(transactId); + EXPECT_NE(iter, connectAbilityMgr->serialQueue_->taskMap_.end()); if (connectAbilityMgr->freeInstallParamsMap_.find("1") != connectAbilityMgr->freeInstallParamsMap_.end()) { connectAbilityMgr->freeInstallParamsMap_.erase("1"); } @@ -1310,6 +1327,7 @@ HWTEST_F(BmsBundleFreeInstallTest, BundleConnectAbilityMgr_0020, Function | Smal std::vector callingAppIds; connectAbilityMgr->GetCallingInfo(USERID, OTHER_USERID, bundleNames, callingAppIds); EXPECT_EQ(bundleNames.size(), 1); + EXPECT_EQ(callingAppIds.size(), 0); UninstallBundleInfo(BUNDLE_NAME); } @@ -1426,7 +1444,7 @@ HWTEST_F(BmsBundleFreeInstallTest, OnAbilityConnectDone_0001, Function | SmallTe sptr remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); int32_t resultCode = 1; connection.OnAbilityConnectDone(element, remoteObject, resultCode); - EXPECT_TRUE(resultCode); + EXPECT_EQ(connection.connectState_, ServiceCenterConnectState::DISCONNECTED); } /** @@ -1447,7 +1465,7 @@ HWTEST_F(BmsBundleFreeInstallTest, OnAbilityConnectDone_0002, Function | SmallTe sptr remoteObject = nullptr; int32_t resultCode = 0; connection.OnAbilityConnectDone(element, remoteObject, resultCode); - EXPECT_FALSE(resultCode); + EXPECT_EQ(connection.connectState_, ServiceCenterConnectState::DISCONNECTED); } /** @@ -1468,7 +1486,7 @@ HWTEST_F(BmsBundleFreeInstallTest, OnAbilityConnectDone_0003, Function | SmallTe sptr remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); int32_t resultCode = 0; connection.OnAbilityConnectDone(element, remoteObject, resultCode); - EXPECT_FALSE(resultCode); + EXPECT_EQ(connection.connectState_, ServiceCenterConnectState::CONNECTED); } /** @@ -1489,11 +1507,12 @@ HWTEST_F(BmsBundleFreeInstallTest, OnRemoteRequest_0001, Function | SmallTest | MessageParcel data; MessageParcel reply; MessageOption option; - callbackStub.OnRemoteRequest(code, data, reply, option); + auto ret = callbackStub.OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, -1); std::string installResult = ""; - callbackStub.OnInstallFinished(installResult); - EXPECT_FALSE(code); + auto result = callbackStub.OnInstallFinished(installResult); + EXPECT_EQ(result, ERR_INVALID_VALUE); } /** @@ -1885,6 +1904,7 @@ HWTEST_F(BmsBundleFreeInstallTest, GetEcologicalCallerInfo_0001, Function | Smal setuid(1); connectAbilityMgr->GetEcologicalCallerInfo(want, callerInfo, USERID); + EXPECT_TRUE(callerInfo.packageName.empty()); auto bundleDataMgr_ = DelayedSingleton::GetInstance()->dataMgr_; bool result = bundleDataMgr_->GetNameForUid(IPCSkeleton::GetCallingUid(), callerBundleName); EXPECT_EQ(result, true); @@ -1905,7 +1925,8 @@ HWTEST_F(BmsBundleFreeInstallTest, GetEcologicalCallerInfo_0002, Function | Smal auto bundleDataMgr_ = DelayedSingleton::GetInstance()->dataMgr_; DelayedSingleton::GetInstance()->dataMgr_ = nullptr; connectAbilityMgr->GetEcologicalCallerInfo(want, callerInfo, USERID); - ASSERT_NE(bundleDataMgr_, nullptr); + EXPECT_TRUE(callerInfo.packageName.empty()); + EXPECT_NE(bundleDataMgr_, nullptr); DelayedSingleton::GetInstance()->dataMgr_ = bundleDataMgr_; } } // OHOS \ No newline at end of file diff --git a/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_installer_ipc_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_installer_ipc_test.cpp index 3fd0253cdb..5290c4802f 100755 --- a/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_installer_ipc_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_installer_ipc_test.cpp @@ -250,25 +250,6 @@ HWTEST_F(BmsBundleInstallerIPCTest, StreamInstall_0100, Function | SmallTest | L EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_PARAM_ERROR); } -/** - * @tc.number: CreateStream_0100 - * @tc.name: test CreateStream function of BundleInstallerProxy - * @tc.desc: 1. Obtain CreateStream - * 2. Calling function CreateStream - * @tc.require: issueI5XD60 -*/ -HWTEST_F(BmsBundleInstallerIPCTest, StreamInstall_0200, Function | SmallTest | Level0) -{ - auto proxy = GetInstallerProxy(); - EXPECT_NE(proxy, nullptr); - - std::vector bundleFilePaths; - InstallParam installParam; - sptr statusReceiver; - auto ret = proxy->StreamInstall(bundleFilePaths, installParam, statusReceiver); - EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_PARAM_ERROR); -} - /** * @tc.number: CreateStream_0100 * @tc.name: test CreateStream function of BundleStreamInstallerProxy diff --git a/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_installer_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_installer_test.cpp index 098734e57d..6062e3a559 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_installer_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_installer_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 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 @@ -1261,10 +1261,10 @@ HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_0900, Function | SmallTest BundleUtil bundleUtil; long long offset = 0; auto ret = bundleUtil.CreateFileDescriptorForReadOnly(bundlePath, offset); - EXPECT_NE(ret, ERR_OK); + EXPECT_EQ(ret, 30); bundlePath.append(std::string(256, '/')); ret = bundleUtil.CreateFileDescriptorForReadOnly(bundlePath, offset); - EXPECT_NE(ret, ERR_OK); + EXPECT_EQ(ret, -1); UnInstallBundle(BUNDLE_BACKUP_NAME); } @@ -1643,6 +1643,7 @@ HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_1000, Function | SmallTest EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_PARAM_ERROR); } +#ifdef BUNDLE_FRAMEWORK_QUICK_FIX /** * @tc.number: baseBundleInstaller_1100 * @tc.name: test ProcessDeployedHqfInfo @@ -1747,6 +1748,7 @@ HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_1500, Function | SmallTest appQfInfo, nativeLibraryPath, cpuAbi); EXPECT_EQ(ret, ERR_BUNDLEMANAGER_QUICK_FIX_BUNDLE_NAME_NOT_EXIST); } +#endif /** * @tc.number: baseBundleInstaller_1600 @@ -2071,6 +2073,7 @@ HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_2900, Function | SmallTest installer.ProcessHqfInfo(oldInfo, newInfo); } +#ifdef BUNDLE_FRAMEWORK_QUICK_FIX /** * @tc.number: baseBundleInstaller_3000 * @tc.name: test ProcessDeployedHqfInfo @@ -2116,7 +2119,9 @@ HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_3100, Function | SmallTest auto res = installer.UpdateLibAttrs(newInfo, cpuAbi, nativeLibraryPath, appQfInfo); EXPECT_EQ(res, ERR_OK); } +#endif +#ifdef BUNDLE_FRAMEWORK_APP_CONTROL /** * @tc.number: baseBundleInstaller_3200 * @tc.name: test InstallAppControl @@ -2130,7 +2135,9 @@ HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_3200, Function | SmallTest OHOS::ErrCode ret = installer.InstallNormalAppControl(installAppId, userId); EXPECT_EQ(ret, OHOS::ERR_OK); } +#endif +#ifdef BUNDLE_FRAMEWORK_QUICK_FIX /** * @tc.number: BundleInstaller_3300 * @tc.name: test InstallAppControl @@ -2144,6 +2151,7 @@ HWTEST_F(BmsBundleInstallerTest, BundleInstaller_3300, Function | SmallTest | Le UnInstallBundle(BUNDLE_MODULEJSON_NAME); } +#endif /** * @tc.number: baseBundleInstaller_3600 @@ -3023,11 +3031,9 @@ HWTEST_F(BmsBundleInstallerTest, InstallChecker_1600, Function | SmallTest | Lev InstallParam installParam; installParam.isCallByShell = true; std::vector hapVerifyRes; - Security::Verify::HapVerifyResult result; Security::Verify::ProvisionInfo info; info.distributionType = Security::Verify::AppDistType::ENTERPRISE; info.type = Security::Verify::ProvisionType::DEBUG; - result.SetProvisionInfo(info); bool ret = installChecker.VaildInstallPermission(installParam, hapVerifyRes); EXPECT_EQ(ret, true); } @@ -3729,8 +3735,8 @@ HWTEST_F(BmsBundleInstallerTest, appControlManagerHostImpl_0200, Function | Smal /** * @tc.number: baseBundleInstaller_5400 - * @tc.name: test checkAsanEnabled when asanEnabled is set to be ture - * @tc.desc: 1.Test checkAsanEnabled + * @tc.name: test UpdateBundleInstallState + * @tc.desc: 1.Test UpdateBundleInstallState running normal */ HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_5400, Function | SmallTest | Level0) { diff --git a/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_system_bundle_installer_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_system_bundle_installer_test.cpp index 85febf305c..05d23ac498 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_system_bundle_installer_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_system_bundle_installer_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 @@ -34,6 +34,7 @@ const std::string BUNDLE_NAME = "com.example.test"; const std::string MODULE_NAME = "entry"; const int32_t WAIT_TIME = 5; const std::string EMPTY_STRING = ""; +const int32_t USERID = 100; } // namespace class BmsSystemBundleInstallerTest : public testing::Test { @@ -47,6 +48,8 @@ public: bool UninstallSystemBundle(const std::string &bundleName) const; bool UninstallSystemBundle(const std::string &bundleName, bool isKeepData) const; bool UninstallSystemBundle(const std::string &bundleName, const std::string &modulePackage) const; + void StartBundleService(); + void ClearDataMgr(); private: static std::shared_ptr bundleMgrService_; }; @@ -93,6 +96,20 @@ void BmsSystemBundleInstallerTest::SetUp() void BmsSystemBundleInstallerTest::TearDown() {} +void BmsSystemBundleInstallerTest::StartBundleService() +{ + if (!bundleMgrService_->IsServiceReady()) { + bundleMgrService_->OnStart(); + bundleMgrService_->GetDataMgr()->AddUserId(USERID); + std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME)); + } +} + +void BmsSystemBundleInstallerTest::ClearDataMgr() +{ + bundleMgrService_->dataMgr_ = nullptr; +} + /** * @tc.number: UninstallSystemBundle_0100 * @tc.name: UninstallSystemBundle @@ -389,4 +406,322 @@ HWTEST_F(BmsSystemBundleInstallerTest, UninstallSystemBundle_2000, Function | Sm bool result = UninstallSystemBundle(bundleName, modulePackage); EXPECT_EQ(result, true); } + + +/** + * @tc.number: UninstallSystemBundle_2100 + * @tc.name: UninstallSystemBundle + * @tc.desc: Pass in the correct bundlename to get the return false + */ +HWTEST_F(BmsSystemBundleInstallerTest, UninstallSystemBundle_2100, Function | SmallTest | Level0) +{ + std::string bundleName = BUNDLE_NAME; + ClearDataMgr(); + bool result = UninstallSystemBundle(bundleName); + EXPECT_EQ(result, false); +} + +/** + * @tc.number: UninstallSystemBundle_2200 + * @tc.name: UninstallSystemBundle + * @tc.desc: Pass in an empty bundleName to get the return false + */ +HWTEST_F(BmsSystemBundleInstallerTest, UninstallSystemBundle_2200, Function | SmallTest | Level0) +{ + std::string bundleName = EMPTY_STRING; + ClearDataMgr(); + bool result = UninstallSystemBundle(bundleName); + EXPECT_EQ(result, false); +} + +/** + * @tc.number: UninstallSystemBundle_2300 + * @tc.name: UninstallSystemBundle + * @tc.desc: Pass in the correct bundlename and isKeepData is true to get the return false + */ +HWTEST_F(BmsSystemBundleInstallerTest, UninstallSystemBundle_2300, Function | SmallTest | Level0) +{ + std::string bundleName = BUNDLE_NAME; + bool isKeepData = true; + ClearDataMgr(); + bool result = UninstallSystemBundle(bundleName, isKeepData); + EXPECT_EQ(result, false); +} + +/** + * @tc.number: UninstallSystemBundle_2400 + * @tc.name: UninstallSystemBundle + * @tc.desc: Pass in an empty bundleName and isKeepData is true to get the return false + */ +HWTEST_F(BmsSystemBundleInstallerTest, UninstallSystemBundle_2400, Function | SmallTest | Level0) +{ + std::string bundleName = EMPTY_STRING; + bool isKeepData = true; + ClearDataMgr(); + bool result = UninstallSystemBundle(bundleName, isKeepData); + EXPECT_EQ(result, false); +} + +/** + * @tc.number: UninstallSystemBundle_2500 + * @tc.name: UninstallSystemBundle + * @tc.desc: Pass in the correct bundlename and isKeepData is false to get the return false + */ +HWTEST_F(BmsSystemBundleInstallerTest, UninstallSystemBundle_2500, Function | SmallTest | Level0) +{ + std::string bundleName = BUNDLE_NAME; + bool isKeepData = false; + ClearDataMgr(); + bool result = UninstallSystemBundle(bundleName, isKeepData); + EXPECT_EQ(result, false); +} + +/** + * @tc.number: UninstallSystemBundle_2600 + * @tc.name: UninstallSystemBundle + * @tc.desc: Pass in an empty bundleName and isKeepData is false to get the return false + */ +HWTEST_F(BmsSystemBundleInstallerTest, UninstallSystemBundle_2600, Function | SmallTest | Level0) +{ + std::string bundleName = EMPTY_STRING; + bool isKeepData = false; + ClearDataMgr(); + bool result = UninstallSystemBundle(bundleName, isKeepData); + EXPECT_EQ(result, false); +} + +/** + * @tc.number: UninstallSystemBundle_2700 + * @tc.name: UninstallSystemBundle + * @tc.desc: Pass in the correct bundlename and the correct modulePackage to get the return false + */ +HWTEST_F(BmsSystemBundleInstallerTest, UninstallSystemBundle_2700, Function | SmallTest | Level0) +{ + std::string bundleName = BUNDLE_NAME; + std::string modulePackage = MODULE_NAME; + ClearDataMgr(); + bool result = UninstallSystemBundle(bundleName, modulePackage); + EXPECT_EQ(result, false); +} + +/** + * @tc.number: UninstallSystemBundle_2800 + * @tc.name: UninstallSystemBundle + * @tc.desc: Pass in an empty bundleName and the correct modulePackage to get the return false + */ +HWTEST_F(BmsSystemBundleInstallerTest, UninstallSystemBundle_2800, Function | SmallTest | Level0) +{ + std::string bundleName = EMPTY_STRING; + std::string modulePackage = MODULE_NAME; + ClearDataMgr(); + bool result = UninstallSystemBundle(bundleName, modulePackage); + EXPECT_EQ(result, false); +} + +/** + * @tc.number: UninstallSystemBundle_2900 + * @tc.name: UninstallSystemBundle + * @tc.desc: Pass in an empty bundleName and an empty modulePackage to get the return false + */ +HWTEST_F(BmsSystemBundleInstallerTest, UninstallSystemBundle_2900, Function | SmallTest | Level0) +{ + std::string bundleName = EMPTY_STRING; + std::string modulePackage = EMPTY_STRING; + ClearDataMgr(); + bool result = UninstallSystemBundle(bundleName, modulePackage); + EXPECT_EQ(result, false); +} + +/** + * @tc.number: UninstallSystemBundle_3000 + * @tc.name: UninstallSystemBundle + * @tc.desc: Pass in the correct bundlename and an empty modulePackage to get the return false + */ +HWTEST_F(BmsSystemBundleInstallerTest, UninstallSystemBundle_3000, Function | SmallTest | Level0) +{ + std::string bundleName = BUNDLE_NAME; + std::string modulePackage = EMPTY_STRING; + ClearDataMgr(); + bool result = UninstallSystemBundle(bundleName, modulePackage); + EXPECT_EQ(result, false); +} + + +/** + * @tc.number: UninstallSystemBundle_3100 + * @tc.name: UninstallSystemBundle + * @tc.desc: Pass in the correct bundlename to get the return true + */ +HWTEST_F(BmsSystemBundleInstallerTest, UninstallSystemBundle_3100, Function | SmallTest | Level0) +{ + if (!bundleMgrService_->IsServiceReady()) { + bundleMgrService_->OnStart(); + std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME)); + } + std::string bundleName = BUNDLE_NAME; + ClearDataMgr(); + bool result = UninstallSystemBundle(bundleName); + EXPECT_EQ(result, false); +} + +/** + * @tc.number: UninstallSystemBundle_3200 + * @tc.name: UninstallSystemBundle + * @tc.desc: Pass in an empty bundleName to get the return true + */ +HWTEST_F(BmsSystemBundleInstallerTest, UninstallSystemBundle_3200, Function | SmallTest | Level0) +{ + if (!bundleMgrService_->IsServiceReady()) { + bundleMgrService_->OnStart(); + std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME)); + } + std::string bundleName = EMPTY_STRING; + ClearDataMgr(); + bool result = UninstallSystemBundle(bundleName); + EXPECT_EQ(result, false); +} + +/** + * @tc.number: UninstallSystemBundle_3300 + * @tc.name: UninstallSystemBundle + * @tc.desc: Pass in the correct bundlename and isKeepData is true to get the return true + */ +HWTEST_F(BmsSystemBundleInstallerTest, UninstallSystemBundle_3300, Function | SmallTest | Level0) +{ + if (!bundleMgrService_->IsServiceReady()) { + bundleMgrService_->OnStart(); + std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME)); + } + std::string bundleName = BUNDLE_NAME; + bool isKeepData = true; + ClearDataMgr(); + bool result = UninstallSystemBundle(bundleName, isKeepData); + EXPECT_EQ(result, false); +} + +/** + * @tc.number: UninstallSystemBundle_3400 + * @tc.name: UninstallSystemBundle + * @tc.desc: Pass in an empty bundleName and isKeepData is true to get the return true + */ +HWTEST_F(BmsSystemBundleInstallerTest, UninstallSystemBundle_3400, Function | SmallTest | Level0) +{ + if (!bundleMgrService_->IsServiceReady()) { + bundleMgrService_->OnStart(); + std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME)); + } + std::string bundleName = EMPTY_STRING; + bool isKeepData = true; + ClearDataMgr(); + bool result = UninstallSystemBundle(bundleName, isKeepData); + EXPECT_EQ(result, false); +} + +/** + * @tc.number: UninstallSystemBundle_3500 + * @tc.name: UninstallSystemBundle + * @tc.desc: Pass in the correct bundlename and isKeepData is false to get the return true + */ +HWTEST_F(BmsSystemBundleInstallerTest, UninstallSystemBundle_3500, Function | SmallTest | Level0) +{ + if (!bundleMgrService_->IsServiceReady()) { + bundleMgrService_->OnStart(); + std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME)); + } + std::string bundleName = BUNDLE_NAME; + bool isKeepData = false; + ClearDataMgr(); + bool result = UninstallSystemBundle(bundleName, isKeepData); + EXPECT_EQ(result, false); +} + +/** + * @tc.number: UninstallSystemBundle_3600 + * @tc.name: UninstallSystemBundle + * @tc.desc: Pass in an empty bundleName and isKeepData is false to get the return true + */ +HWTEST_F(BmsSystemBundleInstallerTest, UninstallSystemBundle_3600, Function | SmallTest | Level0) +{ + if (!bundleMgrService_->IsServiceReady()) { + bundleMgrService_->OnStart(); + std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME)); + } + std::string bundleName = EMPTY_STRING; + bool isKeepData = false; + ClearDataMgr(); + bool result = UninstallSystemBundle(bundleName, isKeepData); + EXPECT_EQ(result, false); +} + +/** + * @tc.number: UninstallSystemBundle_3700 + * @tc.name: UninstallSystemBundle + * @tc.desc: Pass in the correct bundlename and the correct modulePackage to get the return true + */ +HWTEST_F(BmsSystemBundleInstallerTest, UninstallSystemBundle_3700, Function | SmallTest | Level0) +{ + if (!bundleMgrService_->IsServiceReady()) { + bundleMgrService_->OnStart(); + std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME)); + } + std::string bundleName = BUNDLE_NAME; + std::string modulePackage = MODULE_NAME; + ClearDataMgr(); + bool result = UninstallSystemBundle(bundleName, modulePackage); + EXPECT_EQ(result, false); +} + +/** + * @tc.number: UninstallSystemBundle_3800 + * @tc.name: UninstallSystemBundle + * @tc.desc: Pass in an empty bundleName and the correct modulePackage to get the return true + */ +HWTEST_F(BmsSystemBundleInstallerTest, UninstallSystemBundle_3800, Function | SmallTest | Level0) +{ + if (!bundleMgrService_->IsServiceReady()) { + bundleMgrService_->OnStart(); + std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME)); + } + std::string bundleName = EMPTY_STRING; + std::string modulePackage = MODULE_NAME; + ClearDataMgr(); + bool result = UninstallSystemBundle(bundleName, modulePackage); + EXPECT_EQ(result, false); +} + +/** + * @tc.number: UninstallSystemBundle_3900 + * @tc.name: UninstallSystemBundle + * @tc.desc: Pass in an empty bundleName and an empty modulePackage to get the return true + */ +HWTEST_F(BmsSystemBundleInstallerTest, UninstallSystemBundle_3900, Function | SmallTest | Level0) +{ + if (!bundleMgrService_->IsServiceReady()) { + bundleMgrService_->OnStart(); + std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME)); + } + std::string bundleName = EMPTY_STRING; + std::string modulePackage = EMPTY_STRING; + ClearDataMgr(); + bool result = UninstallSystemBundle(bundleName, modulePackage); + EXPECT_EQ(result, false); +} + +/** + * @tc.number: UninstallSystemBundle_4000 + * @tc.name: UninstallSystemBundle + * @tc.desc: Pass in the correct bundlename and an empty modulePackage to get the return true + */ +HWTEST_F(BmsSystemBundleInstallerTest, UninstallSystemBundle_4000, Function | SmallTest | Level0) +{ + if (!bundleMgrService_->IsServiceReady()) { + bundleMgrService_->OnStart(); + std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME)); + } + std::string bundleName = BUNDLE_NAME; + std::string modulePackage = EMPTY_STRING; + ClearDataMgr(); + bool result = UninstallSystemBundle(bundleName, modulePackage); + EXPECT_EQ(result, false); +} } // OHOS -- Gitee From 67d7ad8826946eadb93fed6677bff2ed17d178e2 Mon Sep 17 00:00:00 2001 From: xinking129 Date: Mon, 22 Jan 2024 17:19:12 +0800 Subject: [PATCH 2/3] change tdd code Signed-off-by: xinking129 --- .../bms_bundle_installer_test/bms_bundle_installer_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_installer_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_installer_test.cpp index 6062e3a559..e3dd1ea76c 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_installer_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_installer_test.cpp @@ -1261,10 +1261,10 @@ HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_0900, Function | SmallTest BundleUtil bundleUtil; long long offset = 0; auto ret = bundleUtil.CreateFileDescriptorForReadOnly(bundlePath, offset); - EXPECT_EQ(ret, 30); + EXPECT_NE(ret, -1); bundlePath.append(std::string(256, '/')); ret = bundleUtil.CreateFileDescriptorForReadOnly(bundlePath, offset); - EXPECT_EQ(ret, -1); + EXPECT_NE(ret, -1); UnInstallBundle(BUNDLE_BACKUP_NAME); } -- Gitee From 8595bc6fd15e32581c7fa6a8f06e8853ec6b47e6 Mon Sep 17 00:00:00 2001 From: xinking129 Date: Tue, 23 Jan 2024 14:00:53 +0800 Subject: [PATCH 3/3] change tdd Signed-off-by: xinking129 --- .../bms_bundle_installer_test/bms_bundle_installer_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_installer_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_installer_test.cpp index e3dd1ea76c..78520bd057 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_installer_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_installer_test.cpp @@ -1264,7 +1264,7 @@ HWTEST_F(BmsBundleInstallerTest, CreateInstallTempDir_0900, Function | SmallTest EXPECT_NE(ret, -1); bundlePath.append(std::string(256, '/')); ret = bundleUtil.CreateFileDescriptorForReadOnly(bundlePath, offset); - EXPECT_NE(ret, -1); + EXPECT_EQ(ret, -1); UnInstallBundle(BUNDLE_BACKUP_NAME); } -- Gitee