1 /*
2 * Copyright (c) 2023 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 #include <libxml/globals.h>
18 #include <libxml/xmlstring.h>
19 #include "window_scene_config.h"
20 #include "window_manager_hilog.h"
21 #include "common/include/session_permission.h"
22
23 using namespace testing;
24 using namespace testing::ext;
25
26 namespace OHOS {
27 namespace Rosen {
28 class SessionPermissionTest : public testing::Test {
29 public:
30 static void SetUpTestCase();
31 static void TearDownTestCase();
32 void SetUp() override;
33 void TearDown() override;
34 };
35
SetUpTestCase()36 void SessionPermissionTest::SetUpTestCase()
37 {
38 }
39
TearDownTestCase()40 void SessionPermissionTest::TearDownTestCase()
41 {
42 }
43
SetUp()44 void SessionPermissionTest::SetUp()
45 {
46 }
47
TearDown()48 void SessionPermissionTest::TearDown()
49 {
50 }
51 namespace {
52
53 /**
54 * @tc.name: IsSystemServiceCalling
55 * @tc.desc: test function : IsSystemServiceCalling
56 * @tc.type: FUNC
57 */
58 HWTEST_F(SessionPermissionTest, IsSystemServiceCalling, Function | SmallTest | Level1)
59 {
60 bool needPrintLog = true;
61 bool result = SessionPermission::IsSystemServiceCalling(needPrintLog);
62 ASSERT_EQ(true, result);
63 }
64
65 /**
66 * @tc.name: IsSACalling
67 * @tc.desc: test function : IsSACalling
68 * @tc.type: FUNC
69 */
70 HWTEST_F(SessionPermissionTest, IsSACalling, Function | SmallTest | Level1)
71 {
72 bool result = SessionPermission::IsSACalling();
73 ASSERT_EQ(false, result);
74 }
75
76 /**
77 * @tc.name: VerifyCallingPermission
78 * @tc.desc: test function : VerifyCallingPermission1
79 * @tc.type: FUNC
80 */
81 HWTEST_F(SessionPermissionTest, VerifyCallingPermission, Function | SmallTest | Level1)
82 {
83 const std::string *permissionNode = new string;
84 bool result = SessionPermission::VerifyCallingPermission(*permissionNode);
85 ASSERT_EQ(false, result);
86 }
87
88 /**
89 * @tc.name: VerifyPermissionByCallerToken
90 * @tc.desc: test function : VerifyPermissionByCallerToken
91 * @tc.type: FUNC
92 */
93 HWTEST_F(SessionPermissionTest, VerifyPermissionByCallerToken, Function | SmallTest | Level1)
94 {
95 const uint32_t callerToken = 1000;
96 const std::string *permissionNode = new string;
97 bool result = SessionPermission::VerifyPermissionByCallerToken(callerToken, *permissionNode);
98 ASSERT_EQ(false, result);
99 }
100
101 /**
102 * @tc.name: IsSameBundleNameAsCalling
103 * @tc.desc: test function : IsSameBundleNameAsCalling1
104 * @tc.type: FUNC
105 */
106 HWTEST_F(SessionPermissionTest, IsSameBundleNameAsCalling, Function | SmallTest | Level1)
107 {
108 const std::string *bundleName = new string;
109 bool result = SessionPermission::IsSameBundleNameAsCalling(*bundleName);
110 ASSERT_EQ(false, result);
111
112 const std::string *bundleName2 = new string("test");
113 bool result2 = SessionPermission::IsSameBundleNameAsCalling(*bundleName2);
114 ASSERT_EQ(false, result2);
115 }
116
117 /**
118 * @tc.name: IsSameAppAsCalling
119 * @tc.desc: test function : IsSameAppAsCalling
120 * @tc.type: FUNC
121 */
122 HWTEST_F(SessionPermissionTest, IsSameAppAsCalling, Function | SmallTest | Level1)
123 {
124 const std::string appIdentifier = "123";
125 const std::string bundleName = "";
126 bool result = SessionPermission::IsSameAppAsCalling(bundleName, appIdentifier);
127 ASSERT_EQ(false, result);
128
129 const std::string bundleName2 = "test";
130 bool result2 = SessionPermission::IsSameAppAsCalling(bundleName2, appIdentifier);
131 ASSERT_EQ(false, result2);
132 }
133
134 /**
135 * @tc.name: VerifySessionPermission
136 * @tc.desc: test function : VerifySessionPermission
137 * @tc.type: FUNC
138 */
139 HWTEST_F(SessionPermissionTest, VerifySessionPermission, Function | SmallTest | Level1)
140 {
141 bool result = SessionPermission::VerifySessionPermission();
142 ASSERT_EQ(false, result);
143 }
144
145 /**
146 * @tc.name: JudgeCallerIsAllowedToUseSystemAPI
147 * @tc.desc: test function : JudgeCallerIsAllowedToUseSystemAPI
148 * @tc.type: FUNC
149 */
150 HWTEST_F(SessionPermissionTest, JudgeCallerIsAllowedToUseSystemAPI, Function | SmallTest | Level1)
151 {
152 bool result = SessionPermission::JudgeCallerIsAllowedToUseSystemAPI();
153 ASSERT_EQ(true, result);
154 }
155
156 /**
157 * @tc.name: IsShellCall
158 * @tc.desc: test function : IsShellCall
159 * @tc.type: FUNC
160 */
161 HWTEST_F(SessionPermissionTest, IsShellCall, Function | SmallTest | Level1)
162 {
163 bool result = SessionPermission::IsShellCall();
164 ASSERT_EQ(true, result);
165 }
166
167 /**
168 * @tc.name: IsStartByHdcd
169 * @tc.desc: test function : IsStartByHdcd
170 * @tc.type: FUNC
171 */
172 HWTEST_F(SessionPermissionTest, IsStartByHdcd, Function | SmallTest | Level1)
173 {
174 bool result = SessionPermission::IsStartByHdcd();
175 ASSERT_EQ(true, result);
176 }
177
178 /**
179 * @tc.name: IsStartedByInputMethod
180 * @tc.desc: test function : IsStartedByInputMethod
181 * @tc.type: FUNC
182 */
183 HWTEST_F(SessionPermissionTest, IsStartedByInputMethod, Function | SmallTest | Level1)
184 {
185 bool result = SessionPermission::IsStartedByInputMethod();
186 ASSERT_EQ(false, result);
187 }
188
189 /**
190 * @tc.name: session_permission_test001
191 * @tc.desc: test function : session_permission_test001
192 * @tc.type: FUNC
193 */
194 HWTEST_F(SessionPermissionTest, session_permission_test001, Function | SmallTest | Level1)
195 {
196 GTEST_LOG_(INFO) << "SessionPermissionTest: session_permission_test001 start";
197 bool result = SessionPermission::IsStartByHdcd();
198 ASSERT_EQ(result, true);
199 GTEST_LOG_(INFO) << "SessionPermissionTest: session_permission_test001 end";
200 }
201
202 /**
203 * @tc.name: session_permission_test002
204 * @tc.desc: test function : session_permission_test002
205 * @tc.type: FUNC
206 */
207 HWTEST_F(SessionPermissionTest, session_permission_test002, Function | SmallTest | Level1)
208 {
209 GTEST_LOG_(INFO) << "SessionPermissionTest: session_permission_test002 start";
210 bool result = SessionPermission::IsStartedByInputMethod();
211 ASSERT_EQ(result, false);
212 GTEST_LOG_(INFO) << "SessionPermissionTest: session_permission_test002 end";
213 }
214
215 /**
216 * @tc.name: IsStartedByUIExtension
217 * @tc.desc: test function : IsStartedByUIExtension
218 * @tc.type: FUNC
219 */
220 HWTEST_F(SessionPermissionTest, IsStartedByUIExtension, Function | SmallTest | Level1)
221 {
222 bool result = SessionPermission::IsStartedByUIExtension();
223 ASSERT_EQ(result, false);
224 }
225
226 /**
227 * @tc.name: IsFoundationCall
228 * @tc.desc: test function : IsFoundationCall
229 * @tc.type: FUNC
230 */
231 HWTEST_F(SessionPermissionTest, IsFoundationCall, Function | SmallTest | Level1)
232 {
233 bool result = SessionPermission::IsFoundationCall();
234 ASSERT_EQ(false, result);
235 }
236
237 } // namespacecd
238 } // namespace Rosen
239 } // namespace OHOS