• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define private public
19 #define protected public
20 #include "installed_bundle_info_list_query.h"
21 #undef protected
22 #undef private
23 
24 #include "utils.h"
25 
26 using namespace testing::ext;
27 using namespace OHOS;
28 using namespace OHOS::EDM;
29 
30 namespace OHOS {
31 namespace EDM {
32 namespace TEST {
33 class InstalledBundleInfoListQueryTest : public testing::Test {
34 protected:
35     void SetUp() override;
36 
37     void TearDown() override;
38 };
39 
SetUp()40 void InstalledBundleInfoListQueryTest::SetUp() {
41 }
42 
TearDown()43 void InstalledBundleInfoListQueryTest::TearDown() {
44 }
45 
46 /**
47  * @tc.name: InstalledBundleInfoListQueryBasicInfo
48  * @tc.desc: Test InstalledBundleInfoListQuery basic info check
49  * @tc.type: FUNC
50  */
51 HWTEST_F(InstalledBundleInfoListQueryTest, InstalledBundleInfoListQueryBasicInfo, TestSize.Level1)
52 {
53     std::shared_ptr<InstalledBundleInfoListQuery> queryObj = std::make_shared<InstalledBundleInfoListQuery>();
54     std::string permissionTag;
55     ASSERT_TRUE(queryObj->GetPermission(IPlugin::PermissionType::SUPER_DEVICE_ADMIN, permissionTag)
56         == EdmPermission::PERMISSION_ENTERPRISE_GET_ALL_BUNDLE_INFO);
57     ASSERT_TRUE(queryObj->GetPolicyName() == PolicyName::POLICY_INSTALLED_BUNDLE_INFO_LIST);
58 }
59 
60 /**
61  * @tc.name: TestInstalledBundleInfoListQuery
62  * @tc.desc: Test InstalledBundleInfoListQuery::QueryPolicy func.
63  * @tc.type: FUNC
64  */
65 HWTEST_F(InstalledBundleInfoListQueryTest, TestQueryPolicy, TestSize.Level1)
66 {
67     std::shared_ptr<IPolicyQuery> queryObj = std::make_shared<InstalledBundleInfoListQuery>();
68     std::string policyValue{"InstalledBundleInfoListQuery"};
69     MessageParcel data;
70     MessageParcel reply;
71     ErrCode ret = queryObj->QueryPolicy(policyValue, data, reply, DEFAULT_USER_ID);
72     ASSERT_TRUE(ret == EdmReturnErrCode::SYSTEM_ABNORMALLY);
73 }
74 
75 /**
76  * @tc.name: TestConvertBundleInfoList
77  * @tc.desc: Test InstalledBundleInfoListQuery::ConvertBundleInfoList func.
78  * @tc.type: FUNC
79  */
80 HWTEST_F(InstalledBundleInfoListQueryTest, TestConvertBundleInfoList, TestSize.Level1)
81 {
82     OHOS::AppExecFwk::BundleInfo bundleInfo;
83     bundleInfo.name = "com.test.bundlename";
84     OHOS::AppExecFwk::ApplicationInfo appInfo;
85     appInfo.iconPath = "$media:app_icon";
86     bundleInfo.applicationInfo = appInfo;
87 
88     OHOS::EDM::EdmBundleInfo edmBundleInfo;
89     std::shared_ptr<InstalledBundleInfoListQuery> queryObj = std::make_shared<InstalledBundleInfoListQuery>();
90     queryObj->ConvertBundleInfoList(bundleInfo, edmBundleInfo);
91     ASSERT_TRUE(bundleInfo.name == edmBundleInfo.name);
92     ASSERT_TRUE(bundleInfo.applicationInfo.iconPath == edmBundleInfo.applicationInfo.icon);
93 }
94 
95 /**
96  * @tc.name: TestConvertApplicationInfo
97  * @tc.desc: Test InstalledBundleInfoListQuery::ConvertApplicationInfo func.
98  * @tc.type: FUNC
99  */
100 HWTEST_F(InstalledBundleInfoListQueryTest, TestConvertApplicationInfo, TestSize.Level1)
101 {
102     OHOS::AppExecFwk::BundleInfo bundleInfo;
103     bundleInfo.name = "com.test.bundlename";
104     OHOS::AppExecFwk::ApplicationInfo appInfo;
105     appInfo.iconPath = "$media:app_icon";
106     appInfo.isSystemApp = true;
107     bundleInfo.applicationInfo = appInfo;
108 
109     OHOS::EDM::EdmApplicationInfo edmApplicationInfo;
110     std::shared_ptr<InstalledBundleInfoListQuery> queryObj = std::make_shared<InstalledBundleInfoListQuery>();
111     queryObj->ConvertApplicationInfo(bundleInfo.applicationInfo, edmApplicationInfo);
112     ASSERT_TRUE(bundleInfo.applicationInfo.iconPath == edmApplicationInfo.icon);
113     ASSERT_TRUE(bundleInfo.applicationInfo.isSystemApp == edmApplicationInfo.isSystemApp);
114 }
115 
116 /**
117  * @tc.name: TestConvertSignatureInfo
118  * @tc.desc: Test InstalledBundleInfoListQuery::ConvertSignatureInfo func.
119  * @tc.type: FUNC
120  */
121 HWTEST_F(InstalledBundleInfoListQueryTest, TestConvertSignatureInfo, TestSize.Level1)
122 {
123     OHOS::AppExecFwk::BundleInfo bundleInfo;
124     bundleInfo.name = "com.test.bundlename";
125     OHOS::AppExecFwk::SignatureInfo signatureInfo;
126     signatureInfo.appId = "appId";
127     signatureInfo.fingerprint = "fingerprint";
128     signatureInfo.appIdentifier = "appIdentifier";
129     signatureInfo.certificate = "certificate";
130     bundleInfo.signatureInfo = signatureInfo;
131 
132     EdmSignatureInfo edmSignatureInfo;
133     std::shared_ptr<InstalledBundleInfoListQuery> queryObj = std::make_shared<InstalledBundleInfoListQuery>();
134     queryObj->ConvertSignatureInfo(bundleInfo.signatureInfo, edmSignatureInfo);
135     ASSERT_TRUE(bundleInfo.signatureInfo.appId == edmSignatureInfo.appId);
136     ASSERT_TRUE(bundleInfo.signatureInfo.fingerprint == edmSignatureInfo.fingerprint);
137     ASSERT_TRUE(bundleInfo.signatureInfo.appIdentifier == edmSignatureInfo.appIdentifier);
138     ASSERT_TRUE(bundleInfo.signatureInfo.certificate == edmSignatureInfo.certificate);
139 }
140 
141 /**
142  * @tc.name: TestConvertResourceInfo
143  * @tc.desc: Test InstalledBundleInfoListQuery::ConvertResourceInfo func.
144  * @tc.type: FUNC
145  */
146 HWTEST_F(InstalledBundleInfoListQueryTest, TestConvertResourceInfo, TestSize.Level1)
147 {
148     OHOS::AppExecFwk::Resource resource;
149     resource.id = 123;
150     resource.bundleName = "bundleName";
151     resource.moduleName = "moduleName";
152 
153     EdmResource edmResource;
154     std::shared_ptr<InstalledBundleInfoListQuery> queryObj = std::make_shared<InstalledBundleInfoListQuery>();
155     queryObj->ConvertResourceInfo(resource, edmResource);
156     ASSERT_TRUE(resource.id == edmResource.id);
157     ASSERT_TRUE(resource.bundleName == edmResource.bundleName);
158     ASSERT_TRUE(resource.moduleName == edmResource.moduleName);
159 }
160 
161 /**
162  * @tc.name: TestWriteVectorToParcelIntelligent
163  * @tc.desc: Test InstalledBundleInfoListQuery::WriteVectorToParcelIntelligent func.
164  * @tc.type: FUNC
165  */
166 HWTEST_F(InstalledBundleInfoListQueryTest, TestWriteVectorToParcelIntelligent, TestSize.Level1)
167 {
168     EdmBundleInfo edmBundleInfo;
169     edmBundleInfo.name = "name";
170     std::vector<EdmBundleInfo> edmBundleInfos;
171     edmBundleInfos.emplace_back(edmBundleInfo);
172 
173     MessageParcel reply;
174     std::shared_ptr<InstalledBundleInfoListQuery> queryObj = std::make_shared<InstalledBundleInfoListQuery>();
175     bool ret = queryObj->WriteVectorToParcelIntelligent(edmBundleInfos, reply);
176     ASSERT_TRUE(ret);
177     int32_t flag = ERR_INVALID_VALUE;
178     ASSERT_TRUE(reply.ReadInt32(flag) && (flag == ERR_OK));
179     int32_t size = 0;
180     ASSERT_TRUE(reply.ReadInt32(size) && (size != 0));
181 }
182 } // namespace TEST
183 } // namespace EDM
184 } // namespace OHOS
185