• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 "ability_manager_errors.h"
19 #include "event_report.h"
20 #include "system_ability_definition.h"
21 #include "tokenid_kit.h"
22 #define private public
23 #include "uri_permission_utils.h"
24 #undef private
25 
26 using namespace testing;
27 using namespace testing::ext;
28 
29 namespace OHOS {
30 namespace AAFwk {
31 class UriPermissionUtilsTest : public testing::Test {
32 public:
33     static void SetUpTestCase();
34     static void TearDownTestCase();
35     void SetUp() override;
36     void TearDown() override;
37 };
38 
SetUpTestCase()39 void UriPermissionUtilsTest::SetUpTestCase() {}
40 
TearDownTestCase()41 void UriPermissionUtilsTest::TearDownTestCase() {}
42 
SetUp()43 void UriPermissionUtilsTest::SetUp() {}
44 
TearDown()45 void UriPermissionUtilsTest::TearDown() {}
46 
47 /*
48  * Feature: UPMSUtils
49  * Function: ConnectManager
50  * SubFunction: NA
51  * FunctionPoints: UPMSUtils SendSystemAppGrantUriPermissionEvent
52  */
53 HWTEST_F(UriPermissionUtilsTest, Upms_SendSystemAppGrantUriPermissionEvent_001, TestSize.Level1)
54 {
55     std::vector<Uri> uriVec = { Uri("file://com.example.test/data/storage/el2/base/haps/entry/files/test_A.txt") };
56     const std::vector<bool> resVec = { true };
57     auto ret = UPMSUtils::SendSystemAppGrantUriPermissionEvent(1001, 1002, uriVec, resVec);
58     ASSERT_EQ(ret, false);
59 }
60 
61 /*
62  * Feature: UPMSUtils
63  * Function: SendShareUnPrivilegeUriEvent
64  * SubFunction: NA
65  * FunctionPoints: URIPermissionManagerService SendShareUnPrivilegeUriEvent
66  */
67 HWTEST_F(UriPermissionUtilsTest, Upms_SendShareUnPrivilegeUriEvent_001, TestSize.Level1)
68 {
69     auto ret = UPMSUtils::SendShareUnPrivilegeUriEvent(1001, 1002);
70     EXPECT_EQ(ret, false);
71 }
72 
73 /*
74  * Feature: UPMSUtils
75  * Function: GetCurrentAccountId
76  * SubFunction: NA
77  * FunctionPoints: UPMSUtils GetCurrentAccountId
78  */
79 HWTEST_F(UriPermissionUtilsTest, Upms_GetCurrentAccountId_001, TestSize.Level1)
80 {
81     auto testCurrentAccountId = UPMSUtils::GetCurrentAccountId();
82     EXPECT_EQ(testCurrentAccountId, 100);
83 }
84 
85 /*
86  * Feature: UPMSUtils
87  * Function: IsFoundationCall
88  * SubFunction: NA
89  * FunctionPoints: UPMSUtils IsFoundationCall
90  */
91 HWTEST_F(UriPermissionUtilsTest, Upms_IsFoundationCall_001, TestSize.Level1)
92 {
93     auto testIsFoundationCall = UPMSUtils::IsFoundationCall();
94     EXPECT_EQ(testIsFoundationCall, false);
95 }
96 
97 /*
98  * Feature: UPMSUtils
99  * Function: IsSAOrSystemAppCall
100  * SubFunction: NA
101  * FunctionPoints: UPMSUtils IsSAOrSystemAppCall
102  */
103 HWTEST_F(UriPermissionUtilsTest, Upms_IsSAOrSystemAppCall_001, TestSize.Level1)
104 {
105     auto testIsSAOrSystemAppCall = UPMSUtils::IsSAOrSystemAppCall();
106     EXPECT_EQ(testIsSAOrSystemAppCall, false);
107 }
108 
109 /*
110  * Feature: UPMSUtils
111  * Function: IsSystemAppCall
112  * SubFunction: NA
113  * FunctionPoints: UPMSUtils IsSystemAppCall
114  */
115 HWTEST_F(UriPermissionUtilsTest, Upms_IsSystemAppCall_001, TestSize.Level1)
116 {
117     auto testIsSystemAppCall = UPMSUtils::IsSystemAppCall();
118     EXPECT_EQ(testIsSystemAppCall, false);
119 }
120 
121 /*
122  * Feature: UPMSUtils
123  * Function: CheckIsSystemAppByBundleName
124  * SubFunction: NA
125  * FunctionPoints: UPMSUtils CheckIsSystemAppByBundleName
126  */
127 HWTEST_F(UriPermissionUtilsTest, Upms_CheckIsSystemAppByBundleName_001, TestSize.Level1)
128 {
129     std::string bundleName = "";
130     auto testIsSystemApp = UPMSUtils::CheckIsSystemAppByBundleName(bundleName);
131     EXPECT_EQ(testIsSystemApp, false);
132 }
133 
134 /*
135  * Feature: UPMSUtils
136  * Function: CheckIsSystemAppByTokenId
137  * SubFunction: NA
138  * FunctionPoints: UPMSUtils CheckIsSystemAppByTokenId
139  */
140 HWTEST_F(UriPermissionUtilsTest, Upms_CheckIsSystemAppByTokenId_001, TestSize.Level1)
141 {
142     uint32_t tokenId = 1001;
143     auto testIsSystemApp = UPMSUtils::CheckIsSystemAppByTokenId(tokenId);
144     EXPECT_EQ(testIsSystemApp, false);
145 }
146 
147 /*
148  * Feature: UPMSUtils
149  * Function: GetBundleNameByTokenId
150  * SubFunction: NA
151  * FunctionPoints: UPMSUtils GetBundleNameByTokenId
152  */
153 HWTEST_F(UriPermissionUtilsTest, Upms_GetBundleNameByTokenId_001, TestSize.Level1)
154 {
155     uint32_t tokenId = 1001;
156     std::string bundleName = "";
157     auto testGetBundleNameByTokenIdFlag = UPMSUtils::GetBundleNameByTokenId(tokenId, bundleName);
158     EXPECT_EQ (testGetBundleNameByTokenIdFlag, false);
159 }
160 
161 /*
162  * Feature: UPMSUtils
163  * Function: GetTokenIdByBundleName
164  * SubFunction: NA
165  * FunctionPoints: UPMSUtils GetTokenIdByBundleName
166  */
167 HWTEST_F(UriPermissionUtilsTest, Upms_GetTokenIdByBundleName_001, TestSize.Level1)
168 {
169     std::string bundleName = "com.example.test";
170     int32_t appIndex = 10;
171     uint32_t tokenId;
172     auto testTokenId = UPMSUtils::GetTokenIdByBundleName(bundleName, appIndex, tokenId);
173     EXPECT_EQ(testTokenId, ERR_GET_TARGET_BUNDLE_INFO_FAILED);
174 }
175 
176 }  // namespace AAFwk
177 }  // namespace OHOS