1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 
18 #include "edm_bundle_manager_impl.h"
19 
20 using namespace testing::ext;
21 
22 namespace OHOS {
23 namespace EDM {
24 namespace TEST {
25 const int32_t TEST_UID = 0;
26 const int32_t ILLEGAL_UID = -11;
27 const int32_t ILLEGAL_UID2 = 65536;
28 const int32_t FLAGS = 1;
29 const int32_t USER_ID = 1;
30 const std::string EMPTY_BUNDLE_NAME = "";
31 const std::string INVALID_BUNDLE_NAME = "testbundlename";
32 const std::string BUNDLE_NAME = "com.ohos.launcher";
33 class EdmBundleManagerImplTest : public testing::Test {};
34 /**
35  * @tc.name: TestGetNameForUid01
36  * @tc.desc: Test GetNameForUid function.
37  * @tc.type: FUNC
38  */
39 HWTEST_F(EdmBundleManagerImplTest, TestGetNameForUid01, TestSize.Level1)
40 {
41     EdmBundleManagerImpl edmBundleManagerImpl;
42     std::string bundleName;
43     int ret = edmBundleManagerImpl.GetNameForUid(ILLEGAL_UID, bundleName);
44     ASSERT_TRUE(ret == ERR_BUNDLE_SERVICE_ABNORMALLY);
45 
46     ret = edmBundleManagerImpl.GetNameForUid(ILLEGAL_UID2, bundleName);
47     ASSERT_TRUE(ret == ERR_BUNDLE_SERVICE_ABNORMALLY);
48 }
49 
50 /**
51  * @tc.name: TestGetNameForUid02
52  * @tc.desc: Test GetNameForUid function.
53  * @tc.type: FUNC
54  */
55 HWTEST_F(EdmBundleManagerImplTest, TestGetNameForUid02, TestSize.Level1)
56 {
57     EdmBundleManagerImpl edmBundleManagerImpl;
58     std::string bundleName;
59     int ret = edmBundleManagerImpl.GetNameForUid(TEST_UID, bundleName);
60     ASSERT_TRUE(ret == ERR_BUNDLE_SERVICE_ABNORMALLY);
61 }
62 
63 /**
64  * @tc.name: TestQueryExtensionAbilityInfos01
65  * @tc.desc: Test QueryExtensionAbilityInfos function.
66  * @tc.type: FUNC
67  */
68 HWTEST_F(EdmBundleManagerImplTest, TestQueryExtensionAbilityInfos01, TestSize.Level1)
69 {
70     EdmBundleManagerImpl edmBundleManagerImpl;
71     AAFwk::Want want;
72     std::vector<AppExecFwk::ExtensionAbilityInfo> extensionInfos;
73     EXPECT_EQ(edmBundleManagerImpl.QueryExtensionAbilityInfos(
74         want, AppExecFwk::ExtensionAbilityType::BACKUP, FLAGS, USER_ID, extensionInfos), false);
75 }
76 
77 /**
78  * @tc.name: TestGetBundleInfo01
79  * @tc.desc: Test GetBundleInfo function.
80  * @tc.type: FUNC
81  */
82 HWTEST_F(EdmBundleManagerImplTest, TestGetBundleInfo01, TestSize.Level1)
83 {
84     EdmBundleManagerImpl edmBundleManagerImpl;
85     AppExecFwk::BundleInfo bundleInfo;
86     bool ret = edmBundleManagerImpl.GetBundleInfo(
87         EMPTY_BUNDLE_NAME, AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES, bundleInfo, USER_ID);
88     EXPECT_EQ(ret, false);
89 
90     ret = edmBundleManagerImpl.GetBundleInfo(
91         INVALID_BUNDLE_NAME, AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES, bundleInfo, USER_ID);
92     EXPECT_EQ(ret, false);
93 }
94 
95 /**
96  * @tc.name: TestGetBundleInfo02
97  * @tc.desc: Test GetBundleInfo function.
98  * @tc.type: FUNC
99  */
100 HWTEST_F(EdmBundleManagerImplTest, TestGetBundleInfo02, TestSize.Level1)
101 {
102     EdmBundleManagerImpl edmBundleManagerImpl;
103     AppExecFwk::BundleInfo bundleInfo;
104     bool ret = edmBundleManagerImpl.GetBundleInfo(
105         BUNDLE_NAME, AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES, bundleInfo, USER_ID);
106     EXPECT_EQ(ret, false);
107 }
108 } // namespace TEST
109 } // namespace EDM
110 } // namespace OHOS