diff --git a/BUILD.gn b/BUILD.gn index 80864d9a332b25a05a58f1e6f430234c00a798de..a1f6008b9095c1595b06124d16ead3deda6934f2 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022-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 @@ -44,5 +44,6 @@ group("test_target") { "test/resource/bmssystemtestability/abilitySrc:bms_system_test_app", "test/sceneProject:test_hap", "test/systemtest/common/bms:systemtest_bms", + "test/unittest/bundle_mgr_client_test:unittest", ] } diff --git a/test/unittest/bundle_mgr_client_test/BUILD.gn b/test/unittest/bundle_mgr_client_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..4a38a964d617706c7a13a482fc3abdd4a2527bd8 --- /dev/null +++ b/test/unittest/bundle_mgr_client_test/BUILD.gn @@ -0,0 +1,47 @@ +# 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. + +import("//build/test.gni") +import("../../../appexecfwk.gni") + +module_output_path = "bundle_framework/common" + +ohos_unittest("BundleMgrClientTest") { + module_out_path = module_output_path + + sources = [ "bundle_mgr_client_test.cpp" ] + + configs = [ + "${common_path}:appexecfwk_common_config", + "${common_path}/test:common_test_config", + ] + + deps = [ + "${base_path}:appexecfwk_base", + "${core_path}:appexecfwk_core", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_core", + ] +} + +group("unittest") { + testonly = true + + deps = [ ":BundleMgrClientTest" ] +} diff --git a/test/unittest/bundle_mgr_client_test/bundle_mgr_client_test.cpp b/test/unittest/bundle_mgr_client_test/bundle_mgr_client_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f3f00f85198cd4acedf2fbde90550ce3ffd1decc --- /dev/null +++ b/test/unittest/bundle_mgr_client_test/bundle_mgr_client_test.cpp @@ -0,0 +1,542 @@ +/* + * 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 + +#define private public +#include "bundle_mgr_client.h" +#include "bundle_mgr_client_impl.h" +#undef private + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace AppExecFwk { +class BundleMgrClientTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; + +void BundleMgrClientTest::SetUpTestCase(void) +{} + +void BundleMgrClientTest::TearDownTestCase(void) +{} + +void BundleMgrClientTest::SetUp() +{} + +void BundleMgrClientTest::TearDown() +{} + +/** + * @tc.name: BundleMgrClientTest_GetBundleInfo_001 + * @tc.desc: GetBundleInfo + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_GetBundleInfo_001, TestSize.Level1) +{ + BundleMgrClient client; + std::string bundleName = "ohos.global.systemres"; + int32_t flags = 0; + BundleInfo bundleInfo; + int32_t userId = 100; + auto ret = client.GetBundleInfo(bundleName, flags, bundleInfo, userId); + EXPECT_EQ(ret, true); +} + +/** + * @tc.name: BundleMgrClientTest_GetHapModuleInfo_001 + * @tc.desc: GetHapModuleInfo + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_GetHapModuleInfo_001, TestSize.Level1) +{ + BundleMgrClient client; + AbilityInfo abilityInfo; + HapModuleInfo hapModuleInfo; + auto ret = client.GetHapModuleInfo(abilityInfo, hapModuleInfo); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: BundleMgrClientTest_GetAbilityLabel_001 + * @tc.desc: GetAbilityLabel + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_GetAbilityLabel_001, TestSize.Level1) +{ + BundleMgrClient client; + std::string bundleName; + std::string abilityName; + auto ret = client.GetAbilityLabel(bundleName, abilityName); + EXPECT_EQ(ret, ""); +} + +/** + * @tc.name: BundleMgrClientTest_GetAppType_001 + * @tc.desc: GetAppType + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_GetAppType_001, TestSize.Level1) +{ + BundleMgrClient client; + std::string bundleName; + auto ret = client.GetAppType(bundleName); + EXPECT_EQ(ret, ""); +} + +/** + * @tc.name: BundleMgrClientTest_GetBaseSharedBundleInfos_001 + * @tc.desc: GetBaseSharedBundleInfos + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_GetBaseSharedBundleInfos_001, TestSize.Level1) +{ + BundleMgrClient client; + std::string bundleName; + std::vector baseSharedBundleInfos; + auto ret = client.GetBaseSharedBundleInfos(bundleName, baseSharedBundleInfos); + EXPECT_NE(ret, ERR_OK); +} + +/** + * @tc.name: BundleMgrClientTest_GetBundleInfoForSelf_001 + * @tc.desc: GetBundleInfoForSelf + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_GetBundleInfoForSelf_001, TestSize.Level1) +{ + BundleMgrClient client; + int32_t flags = 0; + BundleInfo bundleInfo; + auto ret = client.GetBundleInfoForSelf(flags, bundleInfo); + EXPECT_NE(ret, ERR_OK); +} + +/** + * @tc.name: BundleMgrClientTest_GetDependentBundleInfo_001 + * @tc.desc: GetDependentBundleInfo + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_GetDependentBundleInfo_001, TestSize.Level1) +{ + BundleMgrClient client; + std::string sharedBundleName; + BundleInfo sharedBundleInfo; + auto ret = client.GetDependentBundleInfo(sharedBundleName, sharedBundleInfo); + EXPECT_NE(ret, ERR_OK); +} + +/** + * @tc.name: BundleMgrClientTest_GetGroupDir_001 + * @tc.desc: GetGroupDir + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_GetGroupDir_001, TestSize.Level1) +{ + BundleMgrClient client; + std::string dataGroupId; + std::string dir; + auto ret = client.GetGroupDir(dataGroupId, dir); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: BundleMgrClientTest_GetOverlayManagerProxy_001 + * @tc.desc: GetOverlayManagerProxy + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_GetOverlayManagerProxy_001, TestSize.Level1) +{ + BundleMgrClient client; + auto ret = client.GetOverlayManagerProxy(); + EXPECT_NE(ret, nullptr); +} + +/** + * @tc.name: BundleMgrClientTest_QueryAbilityInfo_002 + * @tc.desc: QueryAbilityInfo + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_QueryAbilityInfo_002, TestSize.Level1) +{ + BundleMgrClient client; + Want want; + AbilityInfo abilityInfo; + auto ret = client.QueryAbilityInfo(want, abilityInfo); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: BundleMgrClientTest_QueryAbilityInfo_001 + * @tc.desc: QueryAbilityInfo + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_QueryAbilityInfo_001, TestSize.Level1) +{ + BundleMgrClient client; + Want want; + int32_t flags = 0; + int32_t userId = 100; + AbilityInfo abilityInfo; + const sptr callBack = nullptr; + auto ret = client.QueryAbilityInfo(want, flags, userId, abilityInfo, callBack); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: BundleMgrClientTest_GetBundleInfos_001 + * @tc.desc: GetBundleInfos + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_GetBundleInfos_001, TestSize.Level1) +{ + BundleMgrClient client; + BundleFlag flag = BundleFlag::GET_BUNDLE_WITH_ABILITIES; + std::vector bundleInfos; + int32_t userId = 100; + auto ret = client.GetBundleInfos(flag, bundleInfos, userId); + EXPECT_EQ(ret, true); +} + +/** + * @tc.name: BundleMgrClientTest_ImplicitQueryInfos_001 + * @tc.desc: ImplicitQueryInfos + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_ImplicitQueryInfos_001, TestSize.Level1) +{ + BundleMgrClient client; + Want want; + int32_t flags = 0; + int32_t userId = 100; + bool withDefault = false; + std::vector abilityInfos; + std::vector extensionInfos; + auto ret = client.ImplicitQueryInfos(want, flags, userId, withDefault, abilityInfos, extensionInfos); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: BundleMgrClientTest_CleanBundleDataFiles_001 + * @tc.desc: CleanBundleDataFiles + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_CleanBundleDataFiles_001, TestSize.Level1) +{ + BundleMgrClient client; + std::string bundleName; + int32_t userId = 100; + auto ret = client.CleanBundleDataFiles(bundleName, userId); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: BundleMgrClientTest_QueryDataGroupInfos_001 + * @tc.desc: QueryDataGroupInfos + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_QueryDataGroupInfos_001, TestSize.Level1) +{ + BundleMgrClient client; + std::string bundleName; + int32_t userId = 100; + std::vector infos; + auto ret = client.QueryDataGroupInfos(bundleName, userId, infos); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: BundleMgrClientTest_GetBundleGidsByUid_001 + * @tc.desc: GetBundleGidsByUid + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_GetBundleGidsByUid_001, TestSize.Level1) +{ + BundleMgrClient client; + std::string bundleName; + int32_t uid = 100; + std::vector gids; + auto ret = client.GetBundleGidsByUid(bundleName, uid, gids); + EXPECT_EQ(ret, true); +} + +/** + * @tc.name: BundleMgrClientTest_RegisterBundleEventCallback_001 + * @tc.desc: RegisterBundleEventCallback + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_RegisterBundleEventCallback_001, TestSize.Level1) +{ + BundleMgrClient client; + const sptr bundleEventCallback = nullptr; + auto ret = client.RegisterBundleEventCallback(bundleEventCallback); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: BundleMgrClientTest_GetQuickFixManagerProxy_001 + * @tc.desc: GetQuickFixManagerProxy + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_GetQuickFixManagerProxy_001, TestSize.Level1) +{ + BundleMgrClient client; + auto ret = client.GetQuickFixManagerProxy(); + EXPECT_NE(ret, nullptr); +} + +/** + * @tc.name: BundleMgrClientTest_QueryExtensionAbilityInfos_002 + * @tc.desc: QueryExtensionAbilityInfos + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_QueryExtensionAbilityInfos_002, TestSize.Level1) +{ + BundleMgrClient client; + Want want; + ExtensionAbilityType extensionType = ExtensionAbilityType::ACCESSIBILITY; + int32_t flag = 0; + int32_t userId = 100; + std::vector extensionInfos; + auto ret = client.QueryExtensionAbilityInfos(want, extensionType, flag, userId, extensionInfos); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: BundleMgrClientTest_GetAppControlProxy_001 + * @tc.desc: GetAppControlProxy + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_GetAppControlProxy_001, TestSize.Level1) +{ + BundleMgrClient client; + auto ret = client.GetAppControlProxy(); + EXPECT_NE(ret, nullptr); +} + +/** + * @tc.name: BundleMgrClientTest_QueryExtensionAbilityInfos_001 + * @tc.desc: QueryExtensionAbilityInfos + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_QueryExtensionAbilityInfos_001, TestSize.Level1) +{ + BundleMgrClient client; + Want want; + int32_t flag = 0; + int32_t userId = 100; + std::vector extensionInfos; + auto ret = client.QueryExtensionAbilityInfos(want, flag, userId, extensionInfos); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: BundleMgrClientTest_GetApplicationInfo_001 + * @tc.desc: GetApplicationInfo + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_GetApplicationInfo_001, TestSize.Level1) +{ + BundleMgrClient client; + std::string appName; + ApplicationFlag flag = ApplicationFlag::GET_ALL_APPLICATION_INFO; + int userId = 100; + ApplicationInfo appInfo; + auto ret = client.GetApplicationInfo(appName, flag, userId, appInfo); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: BundleMgrClientTest_UnregisterBundleEventCallback_001 + * @tc.desc: UnregisterBundleEventCallback + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_UnregisterBundleEventCallback_001, TestSize.Level1) +{ + BundleMgrClient client; + sptr bundleEventCallback = nullptr; + auto ret = client.UnregisterBundleEventCallback(bundleEventCallback); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: BundleMgrClientTest_QueryExtensionAbilityInfoByUri_001 + * @tc.desc: QueryExtensionAbilityInfoByUri + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_QueryExtensionAbilityInfoByUri_001, TestSize.Level1) +{ + BundleMgrClient client; + std::string uri; + int32_t userId = 100; + ExtensionAbilityInfo extensionAbilityInfo; + auto ret = client.QueryExtensionAbilityInfoByUri(uri, userId, extensionAbilityInfo); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: BundleMgrClientTest_QueryAbilityInfoByUri_001 + * @tc.desc: QueryAbilityInfoByUri + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_QueryAbilityInfoByUri_001, TestSize.Level1) +{ + BundleMgrClient client; + std::string abilityUri; + int32_t userId = 100; + AbilityInfo abilityInfo; + auto ret = client.QueryAbilityInfoByUri(abilityUri, userId, abilityInfo); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: BundleMgrClientTest_ImplicitQueryInfoByPriority_001 + * @tc.desc: ImplicitQueryInfoByPriority + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_ImplicitQueryInfoByPriority_001, TestSize.Level1) +{ + BundleMgrClient client; + Want want; + int32_t flags = 0; + int32_t userId = 100; + AbilityInfo abilityInfo; + ExtensionAbilityInfo extensionInfo; + auto ret = client.ImplicitQueryInfoByPriority(want, flags, userId, abilityInfo, extensionInfo); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: BundleMgrClientTest_GetBundleInfos_002 + * @tc.desc: GetBundleInfos + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_GetBundleInfos_002, TestSize.Level1) +{ + BundleMgrClient client; + int32_t flags = 0; + std::vector bundleInfos; + int32_t userId = 100; + auto ret = client.GetBundleInfos(flags, bundleInfos, userId); + EXPECT_EQ(ret, true); +} + +/** + * @tc.name: BundleMgrClientTest_GetHapModuleInfo_002 + * @tc.desc: GetHapModuleInfo + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_GetHapModuleInfo_002, TestSize.Level1) +{ + BundleMgrClient client; + AbilityInfo abilityInfo; + int32_t userId = 100; + HapModuleInfo hapModuleInfo; + auto ret = client.GetHapModuleInfo(abilityInfo, userId, hapModuleInfo); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: BundleMgrClientTest_GetUidByBundleName_001 + * @tc.desc: GetUidByBundleName + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_GetUidByBundleName_001, TestSize.Level1) +{ + BundleMgrClient client; + std::string bundleName; + int32_t userId = 100; + auto ret = client.GetUidByBundleName(bundleName, userId); + EXPECT_EQ(ret, Constants::INVALID_UID); +} + +/** + * @tc.name: BundleMgrClientTest_GetApplicationInfo_002 + * @tc.desc: GetApplicationInfo + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_GetApplicationInfo_002, TestSize.Level1) +{ + BundleMgrClient client; + std::string appName; + int32_t flags = 0; + int32_t userId =100; + ApplicationInfo appInfo; + auto ret = client.GetApplicationInfo(appName, flags, userId, appInfo); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: BundleMgrClientTest_ProcessPreload_001 + * @tc.desc: ProcessPreload + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_ProcessPreload_001, TestSize.Level1) +{ + BundleMgrClient client; + Want want; + auto ret = client.ProcessPreload(want); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: BundleMgrClientTest_UpgradeAtomicService_001 + * @tc.desc: UpgradeAtomicService + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_UpgradeAtomicService_001, TestSize.Level1) +{ + BundleMgrClient client; + Want want; + int32_t userId = 100; + client.UpgradeAtomicService(want, userId); + EXPECT_NE(client.impl_->bundleMgr_, nullptr); +} + +/** + * @tc.name: BundleMgrClientTest_QueryAbilityInfo_003 + * @tc.desc: QueryAbilityInfo + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_QueryAbilityInfo_003, TestSize.Level1) +{ + BundleMgrClient client; + Want want; + int32_t flags = 100; + int32_t userId = 100; + AbilityInfo abilityInfo; + auto ret = client.QueryAbilityInfo(want, flags, userId, abilityInfo); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: BundleMgrClientTest_GetDefaultAppProxy_001 + * @tc.desc: GetDefaultAppProxy + * @tc.type: FUNC + */ +HWTEST_F(BundleMgrClientTest, BundleMgrClientTest_GetDefaultAppProxy_001, TestSize.Level1) +{ + BundleMgrClient client; + auto ret = client.GetDefaultAppProxy(); + EXPECT_NE(ret, nullptr); +} +} // namespace AppExecFwk +} // namespace OHOS