• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #define private public
18 #define protected public
19 #include "batch_uri.h"
20 #undef private
21 #undef protected
22 using namespace testing::ext;
23 namespace OHOS {
24 namespace AAFwk {
25 class BatchUriTest : public testing::Test {
26 public:
27     static void SetUpTestCase();
28     static void TearDownTestCase();
29     void SetUp();
30     void TearDown();
31 };
32 
SetUpTestCase()33 void BatchUriTest::SetUpTestCase()
34 {}
35 
TearDownTestCase()36 void BatchUriTest::TearDownTestCase()
37 {}
38 
SetUp()39 void BatchUriTest::SetUp()
40 {}
41 
TearDown()42 void BatchUriTest::TearDown()
43 {}
44 
45 /**
46  * @tc.number: Init_0100
47  * @tc.name: Init
48  * @tc.desc: Test Init.
49  */
50 HWTEST_F(BatchUriTest, Init_0100, TestSize.Level2)
51 {
52     auto batchUri = std::make_shared<BatchUri>();
53     ASSERT_NE(batchUri, nullptr);
54     std::vector<std::string> uriVec;
55     uint32_t mode = 0;
56     std::string callerAlterBundleName = "callerBundleName";
57     std::string targetAlterBundleName = "targetBundleName";
58     auto ret = batchUri->Init(uriVec, mode, callerAlterBundleName, targetAlterBundleName);
59     EXPECT_EQ(ret, 0);
60 }
61 
62 /**
63  * @tc.number: Init_0200
64  * @tc.name: Init
65  * @tc.desc: Test Init.
66  */
67 HWTEST_F(BatchUriTest, Init_0200, TestSize.Level2)
68 {
69     auto batchUri = std::make_shared<BatchUri>();
70     ASSERT_NE(batchUri, nullptr);
71     std::vector<std::string> uriVec;
72     uriVec.push_back("file://com.example.insertdata/data/storage/el2/base/haps/entry/files/temp1.txt");
73     uriVec.push_back("testUri");
74     uint32_t mode = 0;
75     std::string callerAlterBundleName = "callerBundleName";
76     std::string targetAlterBundleName = "targetBundleName";
77     auto ret = batchUri->Init(uriVec, mode, callerAlterBundleName, targetAlterBundleName);
78     EXPECT_EQ(ret, 1);
79 }
80 
81 /**
82  * @tc.number: GetUriToGrantByPolicy_0100
83  * @tc.name: GetUriToGrantByPolicy
84  * @tc.desc: Test GetUriToGrantByPolicy.
85  */
86 HWTEST_F(BatchUriTest, GetUriToGrantByPolicy_0100, TestSize.Level2)
87 {
88     auto batchUri = std::make_shared<BatchUri>();
89     ASSERT_NE(batchUri, nullptr);
90     PolicyInfo policyInfo;
91     policyInfo.path = "testPath";
92     policyInfo.mode = 0;
93     batchUri->selfBundlePolicyInfos.push_back(policyInfo);
94     batchUri->otherPolicyInfos.push_back(policyInfo);
95     batchUri->otherIndexes.push_back(0);
96     batchUri->checkResult.push_back(false);
97     std::vector<PolicyInfo> policys;
98     auto ret = batchUri->GetUriToGrantByPolicy(policys);
99     EXPECT_FALSE(ret);
100 }
101 
102 /**
103  * @tc.number: GetUriToGrantByPolicy_0200
104  * @tc.name: GetUriToGrantByPolicy
105  * @tc.desc: Test GetUriToGrantByPolicy.
106  */
107 HWTEST_F(BatchUriTest, GetUriToGrantByPolicy_0200, TestSize.Level2)
108 {
109     auto batchUri = std::make_shared<BatchUri>();
110     ASSERT_NE(batchUri, nullptr);
111     PolicyInfo policyInfo;
112     policyInfo.path = "testPath";
113     policyInfo.mode = 0;
114     batchUri->selfBundlePolicyInfos.push_back(policyInfo);
115     batchUri->otherPolicyInfos.push_back(policyInfo);
116     batchUri->otherIndexes.push_back(0);
117     batchUri->checkResult.push_back(true);
118     batchUri->isTargetBundleUri.push_back(true);
119     std::vector<PolicyInfo> policys;
120     auto ret = batchUri->GetUriToGrantByPolicy(policys);
121     EXPECT_TRUE(ret);
122 }
123 
124 /**
125  * @tc.number: GetUriToGrantByPolicy_0300
126  * @tc.name: GetUriToGrantByPolicy
127  * @tc.desc: Test GetUriToGrantByPolicy.
128  */
129 HWTEST_F(BatchUriTest, GetUriToGrantByPolicy_0300, TestSize.Level2)
130 {
131     auto batchUri = std::make_shared<BatchUri>();
132     ASSERT_NE(batchUri, nullptr);
133     PolicyInfo policyInfo;
134     policyInfo.path = "testPath";
135     policyInfo.mode = 0;
136     batchUri->selfBundlePolicyInfos.push_back(policyInfo);
137     batchUri->otherPolicyInfos.push_back(policyInfo);
138     batchUri->otherIndexes.push_back(0);
139     batchUri->checkResult.push_back(true);
140     batchUri->isTargetBundleUri.push_back(false);
141     std::vector<PolicyInfo> policys;
142     auto ret = batchUri->GetUriToGrantByPolicy(policys);
143     EXPECT_TRUE(ret);
144 }
145 
146 /**
147  * @tc.number: IsAllUriValid_0100
148  * @tc.name: IsAllUriValid
149  * @tc.desc: Test IsAllUriValid.
150  */
151 HWTEST_F(BatchUriTest, IsAllUriValid_0100, TestSize.Level2)
152 {
153     auto batchUri = std::make_shared<BatchUri>();
154     ASSERT_NE(batchUri, nullptr);
155     batchUri->validUriCount = 0;
156     batchUri->totalUriCount = 0;
157     auto ret = batchUri->IsAllUriValid();
158     EXPECT_TRUE(ret);
159 
160     batchUri->totalUriCount = 1;
161     ret = batchUri->IsAllUriValid();
162     EXPECT_FALSE(ret);
163 }
164 
165 /**
166  * @tc.number: IsAllUriPermissioned_0100
167  * @tc.name: IsAllUriPermissioned
168  * @tc.desc: Test IsAllUriPermissioned.
169  */
170 HWTEST_F(BatchUriTest, IsAllUriPermissioned_0100, TestSize.Level2)
171 {
172     auto batchUri = std::make_shared<BatchUri>();
173     ASSERT_NE(batchUri, nullptr);
174     batchUri->checkResult.push_back(false);
175     auto ret = batchUri->IsAllUriPermissioned();
176     EXPECT_FALSE(ret);
177 }
178 
179 /**
180  * @tc.number: IsAllUriPermissioned_0200
181  * @tc.name: IsAllUriPermissioned
182  * @tc.desc: Test IsAllUriPermissioned.
183  */
184 HWTEST_F(BatchUriTest, IsAllUriPermissioned_0200, TestSize.Level2)
185 {
186     auto batchUri = std::make_shared<BatchUri>();
187     ASSERT_NE(batchUri, nullptr);
188     auto ret = batchUri->IsAllUriPermissioned();
189     EXPECT_TRUE(ret);
190     batchUri->checkResult.push_back(true);
191     ret = batchUri->IsAllUriPermissioned();
192     EXPECT_TRUE(ret);
193 }
194 }
195 }