1 /*
2 * Copyright (c) 2022 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 "test.h"
17 #include "napi/native_api.h"
18 #include "napi/native_node_api.h"
19 #include "tools/log.h"
20 #include "js_uri.h"
21 #include "native_module_uri.h"
22
23 #define ASSERT_CHECK_CALL(call) \
24 { \
25 ASSERT_EQ(call, napi_ok); \
26 }
27
28 #define ASSERT_CHECK_VALUE_TYPE(env, value, type) \
29 { \
30 napi_valuetype valueType = napi_undefined; \
31 ASSERT_TRUE(value != nullptr); \
32 ASSERT_CHECK_CALL(napi_typeof(env, value, &valueType)); \
33 ASSERT_EQ(valueType, type); \
34 }
35
36 HWTEST_F(NativeEngineTest, ConstructorTest001, testing::ext::TestSize.Level0)
37 {
38 OHOS::Uri::Uri uri("http://username:password@www.baidu.com:99/path/path?query#fagment");
39 ASSERT_STREQ(uri.GetScheme().c_str(), "http");
40 ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@www.baidu.com:99");
41 ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@www.baidu.com:99/path/path?query");
42 ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password");
43 ASSERT_STREQ(uri.GetHost().c_str(), "www.baidu.com");
44 ASSERT_STREQ(uri.GetPort().c_str(), "99");
45 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path");
46 ASSERT_STREQ(uri.GetQuery().c_str(), "query");
47 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment");
48 }
49
50 HWTEST_F(NativeEngineTest, ConstructorTest002, testing::ext::TestSize.Level0)
51 {
52 OHOS::Uri::Uri uri("http://username:password@[1080::8:800:200C:417A]:99/path/66path1?query#fagment");
53 ASSERT_STREQ(uri.GetScheme().c_str(), "http");
54 ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[1080::8:800:200C:417A]:99");
55 ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[1080::8:800:200C:417A]:99/path/66path1?query");
56 ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password");
57 ASSERT_STREQ(uri.GetHost().c_str(), "[1080::8:800:200C:417A]");
58 ASSERT_STREQ(uri.GetPort().c_str(), "99");
59 ASSERT_STREQ(uri.GetPath().c_str(), "/path/66path1");
60 ASSERT_STREQ(uri.GetQuery().c_str(), "query");
61 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment");
62 }
63
64 HWTEST_F(NativeEngineTest, ConstructorTest003, testing::ext::TestSize.Level0)
65 {
66 OHOS::Uri::Uri uri("http://username:password@[::]:88/path/path66?foooo#gaogao");
67 ASSERT_STREQ(uri.GetScheme().c_str(), "http");
68 ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[::]:88");
69 ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[::]:88/path/path66?foooo");
70 ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password");
71 ASSERT_STREQ(uri.GetHost().c_str(), "[::]");
72 ASSERT_STREQ(uri.GetPort().c_str(), "88");
73 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path66");
74 ASSERT_STREQ(uri.GetQuery().c_str(), "foooo");
75 ASSERT_STREQ(uri.GetFragment().c_str(), "gaogao");
76 }
77
78 HWTEST_F(NativeEngineTest, ConstructorTest004, testing::ext::TestSize.Level0)
79 {
80 OHOS::Uri::Uri uri("http://username:password@[1:0:0:1:2:1:2:1]:99/path/66path1?query#fagment");
81 ASSERT_STREQ(uri.GetScheme().c_str(), "http");
82 ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[1:0:0:1:2:1:2:1]:99");
83 ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[1:0:0:1:2:1:2:1]:99/path/66path1?query");
84 ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password");
85 ASSERT_STREQ(uri.GetHost().c_str(), "[1:0:0:1:2:1:2:1]");
86 ASSERT_STREQ(uri.GetPort().c_str(), "99");
87 ASSERT_STREQ(uri.GetPath().c_str(), "/path/66path1");
88 ASSERT_STREQ(uri.GetQuery().c_str(), "query");
89 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment");
90 }
91
92 HWTEST_F(NativeEngineTest, ConstructorTest005, testing::ext::TestSize.Level0)
93 {
94 OHOS::Uri::Uri uri("http://username:password@[::FFFF:129.144.52.38]:99/path/path?query#fagment");
95 ASSERT_STREQ(uri.GetScheme().c_str(), "http");
96 ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[::FFFF:129.144.52.38]:99");
97 ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[::FFFF:129.144.52.38]:99/path/path?query");
98 ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password");
99 ASSERT_STREQ(uri.GetHost().c_str(), "[::FFFF:129.144.52.38]");
100 ASSERT_STREQ(uri.GetPort().c_str(), "99");
101 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path");
102 ASSERT_STREQ(uri.GetQuery().c_str(), "query");
103 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment");
104 }
105
106 HWTEST_F(NativeEngineTest, ConstructorTest006, testing::ext::TestSize.Level0)
107 {
108 OHOS::Uri::Uri uri("http://username:password@[::192.9.5.5]:99/path/path?query#fagment");
109 ASSERT_STREQ(uri.GetScheme().c_str(), "http");
110 ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[::192.9.5.5]:99");
111 ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[::192.9.5.5]:99/path/path?query");
112 ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password");
113 ASSERT_STREQ(uri.GetHost().c_str(), "[::192.9.5.5]");
114 ASSERT_STREQ(uri.GetPort().c_str(), "99");
115 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path");
116 ASSERT_STREQ(uri.GetQuery().c_str(), "query");
117 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment");
118 }
119
120 HWTEST_F(NativeEngineTest, ConstructorTest007, testing::ext::TestSize.Level0)
121 {
122 OHOS::Uri::Uri uri("http://username:password@[22::22:2:2%ss]:99/path/path?query#fagment");
123 ASSERT_STREQ(uri.GetScheme().c_str(), "http");
124 ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[22::22:2:2%ss]:99");
125 ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[22::22:2:2%ss]:99/path/path?query");
126 ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password");
127 ASSERT_STREQ(uri.GetHost().c_str(), "[22::22:2:2%ss]");
128 ASSERT_STREQ(uri.GetPort().c_str(), "99");
129 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path");
130 ASSERT_STREQ(uri.GetQuery().c_str(), "query");
131 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment");
132 }
133
134 HWTEST_F(NativeEngineTest, ConstructorTest008, testing::ext::TestSize.Level0)
135 {
136 OHOS::Uri::Uri uri("http://username:password@[fe80:0000:0001:0000:0440:44ff:1233:5678]"
137 ":99/path/path?query#fagment");
138 ASSERT_STREQ(uri.GetScheme().c_str(), "http");
139 ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[fe80:0000:0001:0000:0440:44ff:1233:5678]:99");
140 ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[fe80:0000:0001:0000:0440:44ff:1233:5678]"
141 ":99/path/path?query");
142 ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password");
143 ASSERT_STREQ(uri.GetHost().c_str(), "[fe80:0000:0001:0000:0440:44ff:1233:5678]");
144 ASSERT_STREQ(uri.GetPort().c_str(), "99");
145 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path");
146 ASSERT_STREQ(uri.GetQuery().c_str(), "query");
147 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment");
148 }
149
150 HWTEST_F(NativeEngineTest, ConstructorTest009, testing::ext::TestSize.Level0)
151 {
152 OHOS::Uri::Uri uri("http://username:password@[fe80::0001:0000]:99/path/path?query#fagment");
153 ASSERT_STREQ(uri.GetScheme().c_str(), "http");
154 ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[fe80::0001:0000]:99");
155 ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[fe80::0001:0000]:99/path/path?query");
156 ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password");
157 ASSERT_STREQ(uri.GetHost().c_str(), "[fe80::0001:0000]");
158 ASSERT_STREQ(uri.GetPort().c_str(), "99");
159 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path");
160 ASSERT_STREQ(uri.GetQuery().c_str(), "query");
161 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment");
162 }
163
164 HWTEST_F(NativeEngineTest, ConstructorTest010, testing::ext::TestSize.Level0)
165 {
166 OHOS::Uri::Uri uri("http://username:password@www.baidu.com:99/path/path?query#fagment");
167 ASSERT_STREQ(uri.GetScheme().c_str(), "http");
168 ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@www.baidu.com:99");
169 ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@www.baidu.com:99/path/path?query");
170 ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password");
171 ASSERT_STREQ(uri.GetHost().c_str(), "www.baidu.com");
172 ASSERT_STREQ(uri.GetPort().c_str(), "99");
173 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path");
174 ASSERT_STREQ(uri.GetQuery().c_str(), "query");
175 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment");
176 }
177
178 HWTEST_F(NativeEngineTest, ConstructorTest011, testing::ext::TestSize.Level0)
179 {
180 OHOS::Uri::Uri uri("http://username:password@199.98.55.44:99/path/path?query#fagment");
181 ASSERT_STREQ(uri.GetScheme().c_str(), "http");
182 ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@199.98.55.44:99");
183 ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@199.98.55.44:99/path/path?query");
184 ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password");
185 ASSERT_STREQ(uri.GetHost().c_str(), "199.98.55.44");
186 ASSERT_STREQ(uri.GetPort().c_str(), "99");
187 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path");
188 ASSERT_STREQ(uri.GetQuery().c_str(), "query");
189 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment");
190 }
191
192 HWTEST_F(NativeEngineTest, ConstructorTest012, testing::ext::TestSize.Level0)
193 {
194 OHOS::Uri::Uri uri("http://16.9.5.4:99/path/path?query#fagment");
195 ASSERT_STREQ(uri.GetScheme().c_str(), "http");
196 ASSERT_STREQ(uri.GetAuthority().c_str(), "16.9.5.4:99");
197 ASSERT_STREQ(uri.GetSsp().c_str(), "//16.9.5.4:99/path/path?query");
198 ASSERT_STREQ(uri.GetUserinfo().c_str(), "");
199 ASSERT_STREQ(uri.GetHost().c_str(), "16.9.5.4");
200 ASSERT_STREQ(uri.GetPort().c_str(), "99");
201 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path");
202 ASSERT_STREQ(uri.GetQuery().c_str(), "query");
203 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment");
204 }
205
206 HWTEST_F(NativeEngineTest, ConstructorTest013, testing::ext::TestSize.Level0)
207 {
208 OHOS::Uri::Uri uri("http://[::168:169:333]:99/path/path?query#fagment");
209 ASSERT_STREQ(uri.GetScheme().c_str(), "http");
210 ASSERT_STREQ(uri.GetAuthority().c_str(), "[::168:169:333]:99");
211 ASSERT_STREQ(uri.GetSsp().c_str(), "//[::168:169:333]:99/path/path?query");
212 ASSERT_STREQ(uri.GetUserinfo().c_str(), "");
213 ASSERT_STREQ(uri.GetHost().c_str(), "[::168:169:333]");
214 ASSERT_STREQ(uri.GetPort().c_str(), "99");
215 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path");
216 ASSERT_STREQ(uri.GetQuery().c_str(), "query");
217 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment");
218 }
219
220 HWTEST_F(NativeEngineTest, ConstructorTest014, testing::ext::TestSize.Level0)
221 {
222 OHOS::Uri::Uri uri("http://user@49.10hh8.54.12:80/path/path?query#qwer");
223 ASSERT_STREQ(uri.GetScheme().c_str(), "http");
224 ASSERT_STREQ(uri.GetAuthority().c_str(), "user@49.10hh8.54.12:80");
225 ASSERT_STREQ(uri.GetSsp().c_str(), "//user@49.10hh8.54.12:80/path/path?query");
226 ASSERT_STREQ(uri.GetUserinfo().c_str(), "");
227 ASSERT_STREQ(uri.GetHost().c_str(), "");
228 ASSERT_STREQ(uri.GetPort().c_str(), "-1");
229 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path");
230 ASSERT_STREQ(uri.GetQuery().c_str(), "query");
231 ASSERT_STREQ(uri.GetFragment().c_str(), "qwer");
232 }
233
234 HWTEST_F(NativeEngineTest, ConstructorTest015, testing::ext::TestSize.Level0)
235 {
236 OHOS::Uri::Uri uri("http://user@www.baidu.com/path/path?query#qwer");
237 ASSERT_STREQ(uri.GetScheme().c_str(), "http");
238 ASSERT_STREQ(uri.GetAuthority().c_str(), "user@www.baidu.com");
239 ASSERT_STREQ(uri.GetSsp().c_str(), "//user@www.baidu.com/path/path?query");
240 ASSERT_STREQ(uri.GetUserinfo().c_str(), "user");
241 ASSERT_STREQ(uri.GetHost().c_str(), "www.baidu.com");
242 ASSERT_STREQ(uri.GetPort().c_str(), "-1");
243 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path");
244 ASSERT_STREQ(uri.GetQuery().c_str(), "query");
245 ASSERT_STREQ(uri.GetFragment().c_str(), "qwer");
246 }
247
248 HWTEST_F(NativeEngineTest, ConstructorTest016, testing::ext::TestSize.Level0)
249 {
250 OHOS::Uri::Uri uri("ftp://user@www.1hw.1com:77/path/path?query#qwer");
251 ASSERT_STREQ(uri.GetScheme().c_str(), "ftp");
252 ASSERT_STREQ(uri.GetAuthority().c_str(), "user@www.1hw.1com:77");
253 ASSERT_STREQ(uri.GetSsp().c_str(), "//user@www.1hw.1com:77/path/path?query");
254 ASSERT_STREQ(uri.GetUserinfo().c_str(), "");
255 ASSERT_STREQ(uri.GetHost().c_str(), "");
256 ASSERT_STREQ(uri.GetPort().c_str(), "-1");
257 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path");
258 ASSERT_STREQ(uri.GetQuery().c_str(), "query");
259 ASSERT_STREQ(uri.GetFragment().c_str(), "qwer");
260 }
261
262 HWTEST_F(NativeEngineTest, ConstructorTest017, testing::ext::TestSize.Level0)
263 {
264 OHOS::Uri::Uri uri("http://user@hosthost/path/path?query#qwer");
265 ASSERT_STREQ(uri.GetScheme().c_str(), "http");
266 ASSERT_STREQ(uri.GetAuthority().c_str(), "user@hosthost");
267 ASSERT_STREQ(uri.GetSsp().c_str(), "//user@hosthost/path/path?query");
268 ASSERT_STREQ(uri.GetUserinfo().c_str(), "user");
269 ASSERT_STREQ(uri.GetHost().c_str(), "hosthost");
270 ASSERT_STREQ(uri.GetPort().c_str(), "-1");
271 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path");
272 ASSERT_STREQ(uri.GetQuery().c_str(), "query");
273 ASSERT_STREQ(uri.GetFragment().c_str(), "qwer");
274 }
275
276 HWTEST_F(NativeEngineTest, ConstructorTest018, testing::ext::TestSize.Level0)
277 {
278 OHOS::Uri::Uri uri("http://user@[::]/path/path?query#qwer");
279 ASSERT_STREQ(uri.GetScheme().c_str(), "http");
280 ASSERT_STREQ(uri.GetAuthority().c_str(), "user@[::]");
281 ASSERT_STREQ(uri.GetSsp().c_str(), "//user@[::]/path/path?query");
282 ASSERT_STREQ(uri.GetUserinfo().c_str(), "user");
283 ASSERT_STREQ(uri.GetHost().c_str(), "[::]");
284 ASSERT_STREQ(uri.GetPort().c_str(), "-1");
285 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path");
286 ASSERT_STREQ(uri.GetQuery().c_str(), "query");
287 ASSERT_STREQ(uri.GetFragment().c_str(), "qwer");
288 }
289
290 HWTEST_F(NativeEngineTest, ConstructorTest019, testing::ext::TestSize.Level0)
291 {
292 OHOS::Uri::Uri uri("http://[::192:0:5]/path/path?query#qwer");
293 ASSERT_STREQ(uri.GetScheme().c_str(), "http");
294 ASSERT_STREQ(uri.GetAuthority().c_str(), "[::192:0:5]");
295 ASSERT_STREQ(uri.GetSsp().c_str(), "//[::192:0:5]/path/path?query");
296 ASSERT_STREQ(uri.GetUserinfo().c_str(), "");
297 ASSERT_STREQ(uri.GetHost().c_str(), "[::192:0:5]");
298 ASSERT_STREQ(uri.GetPort().c_str(), "-1");
299 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path");
300 ASSERT_STREQ(uri.GetQuery().c_str(), "query");
301 ASSERT_STREQ(uri.GetFragment().c_str(), "qwer");
302 }
303
304 HWTEST_F(NativeEngineTest, ConstructorTest020, testing::ext::TestSize.Level0)
305 {
306 OHOS::Uri::Uri uri("http:/username:password@www.baidu.com:99/path/path?query#fagment");
307 ASSERT_STREQ(uri.GetScheme().c_str(), "http");
308 ASSERT_STREQ(uri.GetAuthority().c_str(), "");
309 ASSERT_STREQ(uri.GetSsp().c_str(), "/username:password@www.baidu.com:99/path/path?query");
310 ASSERT_STREQ(uri.GetUserinfo().c_str(), "");
311 ASSERT_STREQ(uri.GetHost().c_str(), "");
312 ASSERT_STREQ(uri.GetPort().c_str(), "-1");
313 ASSERT_STREQ(uri.GetPath().c_str(), "/username:password@www.baidu.com:99/path/path");
314 ASSERT_STREQ(uri.GetQuery().c_str(), "query");
315 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment");
316 }
317
318 HWTEST_F(NativeEngineTest, ConstructorTest021, testing::ext::TestSize.Level0)
319 {
320 OHOS::Uri::Uri uri("http:/&username:password@[1080::8:800:200C:417A]:99/path/66path1?query#fagment");
321 ASSERT_STREQ(uri.GetScheme().c_str(), "http");
322 ASSERT_STREQ(uri.GetAuthority().c_str(), "");
323 ASSERT_STREQ(uri.GetSsp().c_str(), "/&username:password@[1080::8:800:200C:417A]:99/path/66path1?query");
324 ASSERT_STREQ(uri.GetUserinfo().c_str(), "");
325 ASSERT_STREQ(uri.GetHost().c_str(), "");
326 ASSERT_STREQ(uri.GetPort().c_str(), "-1");
327 ASSERT_STREQ(uri.GetPath().c_str(), "/&username:password@[1080::8:800:200C:417A]:99/path/66path1");
328 ASSERT_STREQ(uri.GetQuery().c_str(), "query");
329 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment");
330 }
331
332 HWTEST_F(NativeEngineTest, ConstructorTest022, testing::ext::TestSize.Level0)
333 {
334 OHOS::Uri::Uri uri("http:/[username:password@[::FFFF:129.144.52.38]:99/path/path?query#fagment");
335 ASSERT_STREQ(uri.GetScheme().c_str(), "http");
336 ASSERT_STREQ(uri.GetAuthority().c_str(), "");
337 ASSERT_STREQ(uri.GetSsp().c_str(), "/[username:password@[::FFFF:129.144.52.38]:99/path/path?query");
338 ASSERT_STREQ(uri.GetUserinfo().c_str(), "");
339 ASSERT_STREQ(uri.GetHost().c_str(), "");
340 ASSERT_STREQ(uri.GetPort().c_str(), "-1");
341 ASSERT_STREQ(uri.GetPath().c_str(), "/[username:password@[::FFFF:129.144.52.38]:99/path/path");
342 ASSERT_STREQ(uri.GetQuery().c_str(), "query");
343 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment");
344 }
345
346 HWTEST_F(NativeEngineTest, ConstructorTest023, testing::ext::TestSize.Level0)
347 {
348 OHOS::Uri::Uri uri("http:username:password@[1080::8:800:200C:417A]:99/path/66path1?query#fagment");
349 ASSERT_STREQ(uri.GetScheme().c_str(), "http");
350 ASSERT_STREQ(uri.GetAuthority().c_str(), "");
351 ASSERT_STREQ(uri.GetSsp().c_str(), "username:password@[1080::8:800:200C:417A]:99/path/66path1?query");
352 ASSERT_STREQ(uri.GetUserinfo().c_str(), "");
353 ASSERT_STREQ(uri.GetHost().c_str(), "");
354 ASSERT_STREQ(uri.GetPort().c_str(), "-1");
355 ASSERT_STREQ(uri.GetPath().c_str(), "");
356 ASSERT_STREQ(uri.GetQuery().c_str(), "");
357 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment");
358 }
359
360 HWTEST_F(NativeEngineTest, ConstructorTest024, testing::ext::TestSize.Level0)
361 {
362 OHOS::Uri::Uri uri("http:^$username:password@[::192.9.5.5]:99/path/path?query#fagment");
363 ASSERT_STREQ(uri.GetScheme().c_str(), "http");
364 ASSERT_STREQ(uri.GetAuthority().c_str(), "");
365 ASSERT_STREQ(uri.GetSsp().c_str(), "^$username:password@[::192.9.5.5]:99/path/path?query");
366 ASSERT_STREQ(uri.GetUserinfo().c_str(), "");
367 ASSERT_STREQ(uri.GetHost().c_str(), "");
368 ASSERT_STREQ(uri.GetPort().c_str(), "-1");
369 ASSERT_STREQ(uri.GetPath().c_str(), "");
370 ASSERT_STREQ(uri.GetQuery().c_str(), "");
371 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment");
372 }
373
374 HWTEST_F(NativeEngineTest, ConstructorTest025, testing::ext::TestSize.Level0)
375 {
376 OHOS::Uri::Uri uri("http:[?]username:password@[fe80::0001:0000]:99/path/path?query#fagment");
377 ASSERT_STREQ(uri.GetScheme().c_str(), "http");
378 ASSERT_STREQ(uri.GetAuthority().c_str(), "");
379 ASSERT_STREQ(uri.GetSsp().c_str(), "[?]username:password@[fe80::0001:0000]:99/path/path?query");
380 ASSERT_STREQ(uri.GetUserinfo().c_str(), "");
381 ASSERT_STREQ(uri.GetHost().c_str(), "");
382 ASSERT_STREQ(uri.GetPort().c_str(), "-1");
383 ASSERT_STREQ(uri.GetPath().c_str(), "");
384 ASSERT_STREQ(uri.GetQuery().c_str(), "");
385 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment");
386 }
387
388 HWTEST_F(NativeEngineTest, ConstructorTest026, testing::ext::TestSize.Level0)
389 {
390 OHOS::Uri::Uri uri("");
391 ASSERT_STREQ(uri.GetScheme().c_str(), "");
392 ASSERT_STREQ(uri.GetSsp().c_str(), "");
393 ASSERT_STREQ(uri.GetFragment().c_str(), "");
394 ASSERT_STREQ(uri.IsFailed().c_str(), "uri is empty");
395 }
396
397 HWTEST_F(NativeEngineTest, ConstructorTest027, testing::ext::TestSize.Level0)
398 {
399 OHOS::Uri::Uri uri("#asd;");
400 ASSERT_STREQ(uri.IsFailed().c_str(), "#It can't be the first");
401 }
402
403 HWTEST_F(NativeEngineTest, ConstructorTest028, testing::ext::TestSize.Level0)
404 {
405 OHOS::Uri::Uri uri("?sa^d:s#asd;");
406 ASSERT_STREQ(uri.IsFailed().c_str(), "Query does not conform to the rule");
407 }
408
409 HWTEST_F(NativeEngineTest, ConstructorTest029, testing::ext::TestSize.Level0)
410 {
411 OHOS::Uri::Uri uri("?sad:s#a^sd;");
412 ASSERT_STREQ(uri.IsFailed().c_str(), "Fragment does not conform to the rule");
413 }
414
415 HWTEST_F(NativeEngineTest, ConstructorTest030, testing::ext::TestSize.Level0)
416 {
417 OHOS::Uri::Uri uri("4http:/username:password@www.baidu.com:99/path/path?query#fagment");
418 ASSERT_STREQ(uri.IsFailed().c_str(), "Scheme the first character must be a letter");
419 }
420
421 HWTEST_F(NativeEngineTest, ConstructorTest031, testing::ext::TestSize.Level0)
422 {
423 OHOS::Uri::Uri uri("ht*tp:/username:password@www.baidu.com:99/path/path?query#fagment");
424 ASSERT_STREQ(uri.GetScheme().c_str(), "ht*tp");
425 }
426
427 HWTEST_F(NativeEngineTest, ConstructorTest032, testing::ext::TestSize.Level0)
428 {
429 OHOS::Uri::Uri uri("/usern]ame/path/path?query#fagment");
430 ASSERT_STREQ(uri.IsFailed().c_str(), "SpecialPath does not conform to the rule");
431 }
432
433 HWTEST_F(NativeEngineTest, ConstructorTest033, testing::ext::TestSize.Level0)
434 {
435 OHOS::Uri::Uri uri("/username/path/path?query#fagment");
436 ASSERT_STREQ(uri.IsFailed().c_str(), "");
437 }
438
439 HWTEST_F(NativeEngineTest, ConstructorTest034, testing::ext::TestSize.Level0)
440 {
441 OHOS::Uri::Uri uri("http:/userna^me:password@www.baidu.com:99/path/path?query#fagment");
442 ASSERT_STREQ(uri.IsFailed().c_str(), "");
443 }
444
445 HWTEST_F(NativeEngineTest, ConstructorTest035, testing::ext::TestSize.Level0)
446 {
447 OHOS::Uri::Uri uri("http://?query#fagment");
448 ASSERT_STREQ(uri.GetScheme().c_str(), "http");
449 }
450
451 HWTEST_F(NativeEngineTest, ConstructorTest036, testing::ext::TestSize.Level0)
452 {
453 OHOS::Uri::Uri uri("http:/username:password@www.baidu.com:99/pa^th/path?query#fagment");
454 ASSERT_STREQ(uri.IsFailed().c_str(), "");
455 }
456
457 HWTEST_F(NativeEngineTest, ConstructorTest037, testing::ext::TestSize.Level0)
458 {
459 OHOS::Uri::Uri uri("http:/username:password@www.baidu.com:9^9/path/path?query#fagment");
460 ASSERT_STREQ(uri.IsFailed().c_str(), "");
461 }
462
463 HWTEST_F(NativeEngineTest, ConstructorTest038, testing::ext::TestSize.Level0)
464 {
465 OHOS::Uri::Uri uri("http:/username:password@[1:0:0:1:2:1:2:1]:9^9/path/path?query#fagment");
466 ASSERT_STREQ(uri.IsFailed().c_str(), "");
467 }
468
469 HWTEST_F(NativeEngineTest, ConstructorTest039, testing::ext::TestSize.Level0)
470 {
471 OHOS::Uri::Uri uri("http:/username:password@[1:0:0:1:2:1:2:1/path/path?query#fagment");
472 ASSERT_STREQ(uri.IsFailed().c_str(), "");
473 }
474
475 HWTEST_F(NativeEngineTest, ConstructorTest040, testing::ext::TestSize.Level0)
476 {
477 OHOS::Uri::Uri uri("http://gg:gaogao@[1:0:0:sfvs1:2:1:2:1]:99/path1?query#fagment");
478 ASSERT_STREQ(uri.IsFailed().c_str(), "ipv6 does not conform to the rule");
479 }
480
481 HWTEST_F(NativeEngineTest, ConstructorTest041, testing::ext::TestSize.Level0)
482 {
483 OHOS::Uri::Uri uri("http、:/username:password@www.baidu.com:99/path/path?query#fagment");
484 ASSERT_STREQ(uri.IsFailed().c_str(), "scheme does not conform to the rule");
485 }
486
487 HWTEST_F(NativeEngineTest, ConstructorTest042, testing::ext::TestSize.Level0)
488 {
489 OHOS::Uri::Uri uri("http://[ffff::1]:、99/path/path?query#fagment");
490 ASSERT_STREQ(uri.IsFailed().c_str(), "Prot does not conform to the rule");
491 }
492
493 HWTEST_F(NativeEngineTest, ConstructorTest043, testing::ext::TestSize.Level0)
494 {
495 OHOS::Uri::Uri uri("http://[ffff::1:99/path/path?query#fagment");
496 ASSERT_STREQ(uri.IsFailed().c_str(), "IPv6 is missing a closing bracket");
497 }
498
499 HWTEST_F(NativeEngineTest, ConstructorTest044, testing::ext::TestSize.Level0)
500 {
501 OHOS::Uri::Uri uri("http://ffff::1]:99/path/path?query#fagment");
502 ASSERT_STREQ(uri.IsFailed().c_str(), "host does not conform to the rule");
503 }
504
505 HWTEST_F(NativeEngineTest, EqualsTest001, testing::ext::TestSize.Level0)
506 {
507 OHOS::Uri::Uri uri("http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment");
508 OHOS::Uri::Uri uri1 = uri;
509 ASSERT_TRUE(uri.Equals(uri1));
510 }
511
512 HWTEST_F(NativeEngineTest, EqualsTest002, testing::ext::TestSize.Level0)
513 {
514 OHOS::Uri::Uri uri("http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment");
515 OHOS::Uri::Uri uri1("http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment");
516 ASSERT_TRUE(uri.Equals(uri1));
517 }
518
519 HWTEST_F(NativeEngineTest, EqualsTest003, testing::ext::TestSize.Level0)
520 {
521 OHOS::Uri::Uri uri("http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment");
522 OHOS::Uri::Uri uri1("http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment123");
523 ASSERT_FALSE(uri.Equals(uri1));
524 }
525
526 HWTEST_F(NativeEngineTest, EqualsTest004, testing::ext::TestSize.Level0)
527 {
528 OHOS::Uri::Uri uri("http://username:password@www.baidu.com:99/path/path?query#fagment");
529 OHOS::Uri::Uri uri1("http://username:password@www.baidu.com:29/path/path?query#fagment");
530 ASSERT_FALSE(uri.Equals(uri1));
531 }
532
533 HWTEST_F(NativeEngineTest, EqualsTest005, testing::ext::TestSize.Level0)
534 {
535 OHOS::Uri::Uri uri("http://username:password@www.baidu.com:99/path/path?query#fagment");
536 OHOS::Uri::Uri uri1("http://user1name:password@www.baidu.com:99/path/path?query#fagment");
537 ASSERT_FALSE(uri.Equals(uri1));
538 }
539
540 HWTEST_F(NativeEngineTest, EqualsTest006, testing::ext::TestSize.Level0)
541 {
542 OHOS::Uri::Uri uri("http://username:password@www.baidu.com:99/path/path?query#fagment");
543 OHOS::Uri::Uri uri1("http://username:password@w2ww.baidu.com:99/path/path?query#fagment");
544 ASSERT_FALSE(uri.Equals(uri1));
545 }
546
547 HWTEST_F(NativeEngineTest, EqualsTest007, testing::ext::TestSize.Level0)
548 {
549 OHOS::Uri::Uri uri("http://username:password@www.baidu.com:99/path/path?query#fagment");
550 OHOS::Uri::Uri uri1("http://username:password@www.baidu.com:99/pa4th/path?query#fagment");
551 ASSERT_FALSE(uri.Equals(uri1));
552 }
553
554 HWTEST_F(NativeEngineTest, EqualsTest008, testing::ext::TestSize.Level0)
555 {
556 OHOS::Uri::Uri uri("http://username:password@www.baidu.com:99/path/path?qu4ery#fagment");
557 OHOS::Uri::Uri uri1("http://username:password@www.baidu.com:99/path/path?query#fagment");
558 ASSERT_FALSE(uri.Equals(uri1));
559 }
560
561 HWTEST_F(NativeEngineTest, EqualsTest009, testing::ext::TestSize.Level0)
562 {
563 OHOS::Uri::Uri uri("http://username:password@www.baidu.com:99/path/path?query#fagment");
564 OHOS::Uri::Uri uri1("h4ttp://username:password@www.baidu.com:99/path/path?query#fagment");
565 ASSERT_FALSE(uri.Equals(uri1));
566 }
567
568 HWTEST_F(NativeEngineTest, NormalizeTest001, testing::ext::TestSize.Level0)
569 {
570 OHOS::Uri::Uri uri("http://user@[1:0:0:1:2:1:2:1]:99/path/66./../././mm/.././path1?query#fagment");
571 std::string normalize = uri.Normalize();
572 ASSERT_STREQ(normalize.c_str(), "http://user@[1:0:0:1:2:1:2:1]:99/path/path1?query#fagment");
573 }
574
575 HWTEST_F(NativeEngineTest, NormalizeTest002, testing::ext::TestSize.Level0)
576 {
577 OHOS::Uri::Uri uri("http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../path?query#fagment");
578 std::string normalize = uri.Normalize();
579 ASSERT_STREQ(normalize.c_str(), "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../path?query#fagment");
580 }
581
582 HWTEST_F(NativeEngineTest, NormalizeTest003, testing::ext::TestSize.Level0)
583 {
584 OHOS::Uri::Uri uri("http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../path/.././../aa/bb/cc?query#fagment");
585 std::string normalize = uri.Normalize();
586 ASSERT_STREQ(normalize.c_str(), "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../../aa/bb/cc?query#fagment");
587 }
588
589 HWTEST_F(NativeEngineTest, NormalizeTest004, testing::ext::TestSize.Level0)
590 {
591 OHOS::Uri::Uri uri("http://gg:gaogao@[1:0:0:1:2:1:2:1]:99?query#fagment");
592 std::string normalize = uri.Normalize();
593 ASSERT_STREQ(normalize.c_str(), "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99?query#fagment");
594 }
595
596 HWTEST_F(NativeEngineTest, ToStringTest001, testing::ext::TestSize.Level0)
597 {
598 OHOS::Uri::Uri uri("http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/aa/bb/cc?query#fagment");
599 ASSERT_STREQ(uri.ToString().c_str(), "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/aa/bb/cc?query#fagment");
600 }
601
602 HWTEST_F(NativeEngineTest, ToStringTest002, testing::ext::TestSize.Level0)
603 {
604 OHOS::Uri::Uri uri("htt1p://gg:gaogao@[::192.9.5.5]:99/path/66path1?query#fagment");
605 ASSERT_STREQ(uri.ToString().c_str(), "htt1p://gg:gaogao@[::192.9.5.5]:99/path/66path1?query#fagment");
606 }
607
608 HWTEST_F(NativeEngineTest, ToStringTest003, testing::ext::TestSize.Level0)
609 {
610 OHOS::Uri::Uri uri("ftp://username:www.baidu.com/path?query#fagment");
611 ASSERT_STREQ(uri.ToString().c_str(), "ftp://username:www.baidu.com/path?query#fagment");
612 }
613
614 HWTEST_F(NativeEngineTest, IsAbsoluteTest001, testing::ext::TestSize.Level0)
615 {
616 OHOS::Uri::Uri uri("f/tp://username:password@www.baidu.com:88/path?query#fagment");
617 bool res = uri.IsAbsolute();
618 ASSERT_FALSE(res);
619 }
620
621 HWTEST_F(NativeEngineTest, IsAbsoluteTest002, testing::ext::TestSize.Level0)
622 {
623 OHOS::Uri::Uri uri("ftp://username:password@www.baidu.com:88/path?query#fagment");
624 bool res = uri.IsAbsolute();
625 ASSERT_TRUE(res);
626 }
627
628 HWTEST_F(NativeEngineTest, IsAbsoluteTest003, testing::ext::TestSize.Level0)
629 {
630 OHOS::Uri::Uri uri("htt/p://username:password@www.baidu.com:88/path?query#fagment");
631 bool res = uri.IsAbsolute();
632 ASSERT_FALSE(res);
633 }
634
635 HWTEST_F(NativeEngineTest, IsRelativeTest001, testing::ext::TestSize.Level0)
636 {
637 OHOS::Uri::Uri uri("https://www.example.com/aaa");
638 bool res = uri.IsRelative();
639 ASSERT_FALSE(res);
640 }
641
642 HWTEST_F(NativeEngineTest, IsRelativeTest002, testing::ext::TestSize.Level0)
643 {
644 OHOS::Uri::Uri uri("/bbb");
645 bool res = uri.IsRelative();
646 ASSERT_TRUE(res);
647 }
648
649 HWTEST_F(NativeEngineTest, IsOpaqueTest001, testing::ext::TestSize.Level0)
650 {
651 OHOS::Uri::Uri uri("aaa:user@example.com");
652 bool res = uri.IsOpaque();
653 ASSERT_TRUE(res);
654 }
655
656 HWTEST_F(NativeEngineTest, IsOpaqueTest002, testing::ext::TestSize.Level0)
657 {
658 OHOS::Uri::Uri uri("content://com.example/bbb");
659 bool res = uri.IsOpaque();
660 ASSERT_FALSE(res);
661 }
662
663 HWTEST_F(NativeEngineTest, IsHierarchicalTest001, testing::ext::TestSize.Level0)
664 {
665 OHOS::Uri::Uri uri("https://www.example.com/path/to/resource");
666 bool res = uri.IsHierarchical();
667 ASSERT_TRUE(res);
668 }
669
670 HWTEST_F(NativeEngineTest, IsHierarchicalTest002, testing::ext::TestSize.Level0)
671 {
672 OHOS::Uri::Uri uri("/path/to/resource");
673 bool res = uri.IsHierarchical();
674 ASSERT_TRUE(res);
675 }
676
677 HWTEST_F(NativeEngineTest, IsHierarchicalTest003, testing::ext::TestSize.Level0)
678 {
679 OHOS::Uri::Uri uri("tel:123456789");
680 bool res = uri.IsHierarchical();
681 ASSERT_FALSE(res);
682 }
683
684 HWTEST_F(NativeEngineTest, AddQueryValueTest001, testing::ext::TestSize.Level0)
685 {
686 OHOS::Uri::Uri uri("https://username:password@host:8080/file?aaa=1#myfragment");
687 std::string temp = uri.AddQueryValue("bbb", "2");
688 ASSERT_STREQ(temp.c_str(), "https://username:password@host:8080/file?aaa=1&bbb=2#myfragment");
689 }
690
691 HWTEST_F(NativeEngineTest, AddQueryValueTest002, testing::ext::TestSize.Level0)
692 {
693 OHOS::Uri::Uri uri("mao:user@example.com");
694 std::string temp = uri.AddQueryValue("bb", "cc");
695 ASSERT_STREQ(temp.c_str(), "mao:?bb=cc");
696 }
697
698 HWTEST_F(NativeEngineTest, ClearQueryTest001, testing::ext::TestSize.Level0)
699 {
700 OHOS::Uri::Uri uri("https://username:password@host:8080/file?aaa=1#myfragment");
701 std::string temp = uri.ClearQuery();
702 ASSERT_STREQ(temp.c_str(), "https://username:password@host:8080/file#myfragment");
703 }
704
705 HWTEST_F(NativeEngineTest, GetLastSegmentTest001, testing::ext::TestSize.Level0)
706 {
707 OHOS::Uri::Uri uri("https://username:password@host:8080/file/test1?aaa=1#myfragment");
708 std::string temp = uri.GetLastSegment();
709 ASSERT_EQ(temp.size(), 5);
710 OHOS::Uri::Uri uri1("https://username:password@host:8080?aaa=1#myfragment");
711 temp = uri1.GetLastSegment();
712 ASSERT_EQ(temp.size(), 0);
713 OHOS::Uri::Uri uri2("https://username:password@host:8080/file/test1/?aaa=1#myfragment");
714 temp = uri2.GetLastSegment();
715 ASSERT_EQ(temp.size(), 5);
716 }
717
718 HWTEST_F(NativeEngineTest, AddSegmentTest001, testing::ext::TestSize.Level0)
719 {
720 OHOS::Uri::Uri uri("https://username:password@host:8080/file?aaa=1#myfragment");
721 std::string temp = uri.AddSegment("segment");
722 ASSERT_STREQ(temp.c_str(), "https://username:password@host:8080/file/segment?aaa=1#myfragment");
723 }
724
725 HWTEST_F(NativeEngineTest, AddSegmentTest002, testing::ext::TestSize.Level0)
726 {
727 OHOS::Uri::Uri uri("mao:user@example.com");
728 std::string temp = uri.AddSegment("aaa");
729 ASSERT_STREQ(temp.c_str(), "mao:/aaa");
730 }
731
732 HWTEST_F(NativeEngineTest, GetTest001, testing::ext::TestSize.Level0)
733 {
734 OHOS::Uri::Uri uri("https://username:password@host:8080");
735 ASSERT_STREQ(uri.GetPath().c_str(), "");
736 ASSERT_STREQ(uri.GetQuery().c_str(), "");
737 ASSERT_STREQ(uri.GetFragment().c_str(), "");
738 }
739
GetStringUtf8(napi_env env,napi_value str)740 std::string GetStringUtf8(napi_env env, napi_value str)
741 {
742 std::string buffer = "";
743 size_t bufferSize = 0;
744 if (napi_get_value_string_utf8(env, str, nullptr, 0, &bufferSize) != napi_ok) {
745 HILOG_ERROR("can not get src size");
746 return buffer;
747 }
748 buffer.resize(bufferSize);
749 if (napi_get_value_string_utf8(env, str, buffer.data(), bufferSize + 1, &bufferSize) != napi_ok) {
750 HILOG_ERROR("can not get src value");
751 return buffer;
752 }
753 return buffer;
754 }
755
StrToNapiValue(napi_env env,const std::string & result)756 napi_value StrToNapiValue(napi_env env, const std::string &result)
757 {
758 napi_value output = nullptr;
759 napi_create_string_utf8(env, result.c_str(), result.size(), &output);
760 return output;
761 }
762
GetArray(napi_env env,const napi_value tempStr)763 std::vector<std::string> GetArray(napi_env env, const napi_value tempStr)
764 {
765 std::vector<std::string> strVec;
766 napi_value napiStr = nullptr;
767 uint32_t length = 0;
768 size_t strLength = 0;
769 napi_get_array_length(env, tempStr, &length);
770 for (size_t i = 0; i < length; i++) {
771 napi_get_element(env, tempStr, i, &napiStr);
772 if (napi_get_value_string_utf8(env, napiStr, nullptr, 0, &strLength) != napi_ok) {
773 HILOG_ERROR("can not get napiStr size");
774 return strVec;
775 }
776 if (strLength > 0) {
777 std::string itemStr = "";
778 itemStr.resize(strLength);
779 if (napi_get_value_string_utf8(env, napiStr, itemStr.data(), strLength + 1, &strLength) != napi_ok) {
780 HILOG_ERROR("can not get napiStr size");
781 return strVec;
782 }
783 strVec.push_back(itemStr);
784 } else {
785 strVec.push_back("");
786 }
787 }
788 return strVec;
789 }
790
791 HWTEST_F(NativeEngineTest, ModuleTest001, testing::ext::TestSize.Level0)
792 {
793 napi_env env = (napi_env)engine_;
794 napi_value exports = nullptr;
795 napi_create_object(env, &exports);
796 OHOS::Uri::UriInit(env, exports);
797 napi_value uriClass = nullptr;
798 napi_value constructorArgs[1] = { 0 };
799 std::string input = "http://username:password@www.baidu.com:99/path/path?query#fagment";
800 napi_create_string_utf8(env, input.c_str(), input.size(), &constructorArgs[0]);
801 napi_status status = napi_get_named_property(env, exports, "Uri", &uriClass);
802 napi_value instance = nullptr;
803 status = napi_new_instance(env, uriClass, 1, constructorArgs, &instance);
804 napi_value getTemp = nullptr;
805 napi_get_named_property(env, instance, "scheme", &getTemp);
806 std::string res = GetStringUtf8(env, getTemp);
807 ASSERT_STREQ(res.c_str(), "http");
808
809 napi_get_named_property(env, instance, "authority", &getTemp);
810 res = GetStringUtf8(env, getTemp);
811 ASSERT_STREQ(res.c_str(), "username:password@www.baidu.com:99");
812
813 napi_get_named_property(env, instance, "ssp", &getTemp);
814 res = GetStringUtf8(env, getTemp);
815 ASSERT_STREQ(res.c_str(), "//username:password@www.baidu.com:99/path/path?query");
816
817 napi_get_named_property(env, instance, "userInfo", &getTemp);
818 res = GetStringUtf8(env, getTemp);
819 ASSERT_STREQ(res.c_str(), "username:password");
820
821 napi_get_named_property(env, instance, "host", &getTemp);
822 res = GetStringUtf8(env, getTemp);
823 ASSERT_STREQ(res.c_str(), "www.baidu.com");
824
825 napi_get_named_property(env, instance, "port", &getTemp);
826 res = GetStringUtf8(env, getTemp);
827 ASSERT_STREQ(res.c_str(), "99");
828
829 napi_get_named_property(env, instance, "path", &getTemp);
830 res = GetStringUtf8(env, getTemp);
831 ASSERT_STREQ(res.c_str(), "/path/path");
832
833 napi_get_named_property(env, instance, "query", &getTemp);
834 res = GetStringUtf8(env, getTemp);
835 ASSERT_STREQ(res.c_str(), "query");
836
837 napi_get_named_property(env, instance, "fragment", &getTemp);
838 res = GetStringUtf8(env, getTemp);
839 ASSERT_STREQ(res.c_str(), "fagment");
840
841 napi_get_named_property(env, instance, "isFailed", &getTemp);
842 res = GetStringUtf8(env, getTemp);
843 ASSERT_STREQ(res.c_str(), "");
844 }
845
846 HWTEST_F(NativeEngineTest, ModuleTest002, testing::ext::TestSize.Level0)
847 {
848 napi_env env = (napi_env)engine_;
849 napi_value exports = nullptr;
850 napi_create_object(env, &exports);
851 OHOS::Uri::UriInit(env, exports);
852 napi_value uriClass = nullptr;
853 napi_value constructorArgs[1] = { 0 };
854 std::string input = "http://username:password@www.baidu.com:99/path/path?query#fagment";
855 napi_create_string_utf8(env, input.c_str(), input.size(), &constructorArgs[0]);
856 napi_get_named_property(env, exports, "Uri", &uriClass);
857 napi_value instance = nullptr;
858 napi_new_instance(env, uriClass, 1, constructorArgs, &instance);
859 napi_value tempFn = nullptr;
860 napi_get_named_property(env, instance, "checkIsAbsolute", &tempFn);
861 napi_value result = nullptr;
862 napi_call_function(env, instance, tempFn, 0, nullptr, &result);
863 ASSERT_TRUE(result);
864
865 napi_get_named_property(env, instance, "toString", &tempFn);
866 napi_call_function(env, instance, tempFn, 0, nullptr, &result);
867 std::string res = GetStringUtf8(env, result);
868 ASSERT_STREQ(res.c_str(), "http://username:password@www.baidu.com:99/path/path?query#fagment");
869
870 napi_get_named_property(env, instance, "normalize", &tempFn);
871 napi_call_function(env, instance, tempFn, 0, nullptr, &result);
872 res = GetStringUtf8(env, result);
873 ASSERT_STREQ(res.c_str(), "http://username:password@www.baidu.com:99/path/path?query#fagment");
874
875 napi_value equalsFn = nullptr;
876 napi_get_named_property(env, instance, "equals", &equalsFn);
877 napi_value constructorArgs1[1] = { 0 };
878 std::string input2 = "http://username:password@www.baidu.com:88/path?query1#fagment";
879 napi_create_string_utf8(env, input2.c_str(), input2.size(), &constructorArgs1[0]);
880 napi_value otherInstance = nullptr;
881 napi_new_instance(env, uriClass, 1, constructorArgs1, &otherInstance);
882 napi_value args[1] = { otherInstance };
883 napi_value result1 = nullptr;
884 napi_call_function(env, instance, equalsFn, 1, args, &result1);
885 bool res1 = true;
886 napi_get_value_bool(env, result1, &res1);
887 ASSERT_FALSE(res1);
888 }
889
890 HWTEST_F(NativeEngineTest, ModuleTest003, testing::ext::TestSize.Level0)
891 {
892 napi_env env = (napi_env)engine_;
893 napi_value exports = nullptr;
894 napi_create_object(env, &exports);
895 OHOS::Uri::UriInit(env, exports);
896 napi_value uriClass = nullptr;
897 napi_value constructorArgs[1] = { 0 };
898 std::string input = "http://name:word@www.uritest.com:99/path/abc?query#fagment";
899 napi_create_string_utf8(env, input.c_str(), input.size(), &constructorArgs[0]);
900 napi_get_named_property(env, exports, "Uri", &uriClass);
901 napi_value instance = nullptr;
902 napi_new_instance(env, uriClass, 1, constructorArgs, &instance);
903 napi_value tempFn = nullptr;
904
905 napi_get_named_property(env, instance, "checkIsRelative", &tempFn);
906 napi_value result = nullptr;
907 napi_call_function(env, instance, tempFn, 0, nullptr, &result);
908 bool flag = true;
909 napi_get_value_bool(env, result, &flag);
910 ASSERT_FALSE(flag);
911
912 napi_get_named_property(env, instance, "checkIsOpaque", &tempFn);
913 napi_call_function(env, instance, tempFn, 0, nullptr, &result);
914 napi_get_value_bool(env, result, &flag);
915 ASSERT_FALSE(flag);
916
917 napi_get_named_property(env, instance, "checkIsHierarchical", &tempFn);
918 napi_call_function(env, instance, tempFn, 0, nullptr, &result);
919 napi_get_value_bool(env, result, &flag);
920 ASSERT_TRUE(flag);
921
922 napi_value key = StrToNapiValue(env, "aaa");
923 napi_value value = StrToNapiValue(env, "bbb");
924 napi_value keyArgs[] = { key, value };
925 napi_get_named_property(env, instance, "addQueryValue", &tempFn);
926 napi_call_function(env, instance, tempFn, 2, keyArgs, &result);
927 std::string res = GetStringUtf8(env, result);
928 ASSERT_STREQ(res.c_str(), "http://name:word@www.uritest.com:99/path/abc?query&aaa=bbb#fagment");
929
930 napi_get_named_property(env, instance, "getLastSegment", &tempFn);
931 napi_call_function(env, instance, tempFn, 0, nullptr, &result);
932 std::string temp = GetStringUtf8(env, result);
933 ASSERT_STREQ(temp.c_str(), "abc");
934
935 napi_value segment = StrToNapiValue(env, "aaa");
936 napi_value segargs[] = { segment };
937 napi_get_named_property(env, instance, "addSegment", &tempFn);
938 napi_call_function(env, instance, tempFn, 1, segargs, &result);
939 res = GetStringUtf8(env, result);
940 ASSERT_STREQ(res.c_str(), "http://name:word@www.uritest.com:99/path/abc/aaa?query#fagment");
941
942 napi_get_named_property(env, instance, "clearQuery", &tempFn);
943 napi_call_function(env, instance, tempFn, 0, nullptr, &result);
944 res = GetStringUtf8(env, result);
945 ASSERT_STREQ(res.c_str(), "http://name:word@www.uritest.com:99/path/abc#fagment");
946 }
947
948 HWTEST_F(NativeEngineTest, ModuleTest004, testing::ext::TestSize.Level0)
949 {
950 napi_env env = (napi_env)engine_;
951 napi_value exports = nullptr;
952 napi_create_object(env, &exports);
953 OHOS::Uri::UriInit(env, exports);
954 napi_value uriClass = nullptr;
955 napi_value constructorArgs[1] = { 0 };
956 std::string input = "http://username:password@www.baidu.com:99/path/path?query#fagment";
957 napi_create_string_utf8(env, input.c_str(), input.size(), &constructorArgs[0]);
958 napi_get_named_property(env, exports, "Uri", &uriClass);
959 napi_value instance = nullptr;
960 napi_new_instance(env, uriClass, 1, constructorArgs, &instance);
961
962 std::string input1 = "testuserinfo";
963 napi_value newValue = nullptr;
964 napi_create_string_utf8(env, input1.c_str(), input1.size(), &newValue);
965 napi_set_named_property(env, instance, "userInfo", newValue);
966 napi_value uriProperty = nullptr;
967 napi_get_named_property(env, instance, "userInfo", &uriProperty);
968 std::string res = GetStringUtf8(env, uriProperty);
969 ASSERT_STREQ(res.c_str(), "testuserinfo");
970
971 input1 = "testuserinfo<";
972 newValue = nullptr;
973 napi_create_string_utf8(env, input1.c_str(), input1.size(), &newValue);
974 napi_set_named_property(env, instance, "userInfo", newValue);
975 uriProperty = nullptr;
976 napi_get_named_property(env, instance, "userInfo", &uriProperty);
977 res = GetStringUtf8(env, uriProperty);
978 ASSERT_STREQ(res.c_str(), "testuserinfo");
979 }
980
981 HWTEST_F(NativeEngineTest, ModuleTest005, testing::ext::TestSize.Level0)
982 {
983 napi_env env = (napi_env)engine_;
984 napi_value exports = nullptr;
985 napi_create_object(env, &exports);
986 OHOS::Uri::UriInit(env, exports);
987 napi_value uriClass = nullptr;
988 napi_value constructorArgs[1] = { 0 };
989 std::string input = "http://username:password@www.baidu.com:99/path/path?query#fagment";
990 napi_create_string_utf8(env, input.c_str(), input.size(), &constructorArgs[0]);
991 napi_get_named_property(env, exports, "Uri", &uriClass);
992 napi_value instance = nullptr;
993 napi_new_instance(env, uriClass, 1, constructorArgs, &instance);
994
995 std::string input1 = "httpstest:ss";
996 napi_value newValue = nullptr;
997 napi_create_string_utf8(env, input1.c_str(), input1.size(), &newValue);
998 napi_set_named_property(env, instance, "scheme", newValue);
999 napi_value uriProperty = nullptr;
1000 napi_get_named_property(env, instance, "scheme", &uriProperty);
1001 std::string res = GetStringUtf8(env, uriProperty);
1002 ASSERT_STREQ(res.c_str(), "httpstest");
1003
1004 input1 = "https";
1005 newValue = nullptr;
1006 napi_create_string_utf8(env, input1.c_str(), input1.size(), &newValue);
1007 napi_set_named_property(env, instance, "scheme", newValue);
1008 uriProperty = nullptr;
1009 napi_get_named_property(env, instance, "scheme", &uriProperty);
1010 res = GetStringUtf8(env, uriProperty);
1011 ASSERT_STREQ(res.c_str(), "https");
1012
1013 input1 = "2https";
1014 newValue = nullptr;
1015 napi_create_string_utf8(env, input1.c_str(), input1.size(), &newValue);
1016 napi_set_named_property(env, instance, "scheme", newValue);
1017 uriProperty = nullptr;
1018 napi_get_named_property(env, instance, "scheme", &uriProperty);
1019 res = GetStringUtf8(env, uriProperty);
1020 ASSERT_STREQ(res.c_str(), "https");
1021
1022 input1 = "htt<ps";
1023 newValue = nullptr;
1024 napi_create_string_utf8(env, input1.c_str(), input1.size(), &newValue);
1025 napi_set_named_property(env, instance, "scheme", newValue);
1026 uriProperty = nullptr;
1027 napi_get_named_property(env, instance, "scheme", &uriProperty);
1028 res = GetStringUtf8(env, uriProperty);
1029 ASSERT_STREQ(res.c_str(), "https");
1030 }
1031
1032 HWTEST_F(NativeEngineTest, ModuleTest006, testing::ext::TestSize.Level0)
1033 {
1034 napi_env env = (napi_env)engine_;
1035 napi_value exports = nullptr;
1036 napi_create_object(env, &exports);
1037 OHOS::Uri::UriInit(env, exports);
1038 napi_value uriClass = nullptr;
1039 napi_value constructorArgs[1] = { 0 };
1040 std::string input = "http://username:password@www.baidu.com:99/path/path?query#fagment";
1041 napi_create_string_utf8(env, input.c_str(), input.size(), &constructorArgs[0]);
1042 napi_get_named_property(env, exports, "Uri", &uriClass);
1043 napi_value instance = nullptr;
1044 napi_new_instance(env, uriClass, 1, constructorArgs, &instance);
1045
1046 std::string input1 = "testpath";
1047 napi_value newValue = nullptr;
1048 napi_create_string_utf8(env, input1.c_str(), input1.size(), &newValue);
1049 napi_set_named_property(env, instance, "path", newValue);
1050 napi_value uriProperty = nullptr;
1051 napi_get_named_property(env, instance, "path", &uriProperty);
1052 std::string res = GetStringUtf8(env, uriProperty);
1053 ASSERT_STREQ(res.c_str(), "testpath");
1054
1055 input1 = "testpath<";
1056 newValue = nullptr;
1057 napi_create_string_utf8(env, input1.c_str(), input1.size(), &newValue);
1058 napi_set_named_property(env, instance, "path", newValue);
1059 uriProperty = nullptr;
1060 napi_get_named_property(env, instance, "path", &uriProperty);
1061 res = GetStringUtf8(env, uriProperty);
1062 ASSERT_STREQ(res.c_str(), "testpath");
1063 }
1064
1065 HWTEST_F(NativeEngineTest, ModuleTest007, testing::ext::TestSize.Level0)
1066 {
1067 napi_env env = (napi_env)engine_;
1068 napi_value exports = nullptr;
1069 napi_create_object(env, &exports);
1070 OHOS::Uri::UriInit(env, exports);
1071 napi_value uriClass = nullptr;
1072 napi_value constructorArgs[1] = { 0 };
1073 std::string input = "http://username:password@www.baidu.com:99/path/path?query#fagment";
1074 napi_create_string_utf8(env, input.c_str(), input.size(), &constructorArgs[0]);
1075 napi_get_named_property(env, exports, "Uri", &uriClass);
1076 napi_value instance = nullptr;
1077 napi_new_instance(env, uriClass, 1, constructorArgs, &instance);
1078
1079 std::string input1 = "key=value";
1080 napi_value newValue = nullptr;
1081 napi_create_string_utf8(env, input1.c_str(), input1.size(), &newValue);
1082 napi_set_named_property(env, instance, "query", newValue);
1083 napi_value uriProperty = nullptr;
1084 napi_get_named_property(env, instance, "query", &uriProperty);
1085 std::string res = GetStringUtf8(env, uriProperty);
1086 ASSERT_STREQ(res.c_str(), "key=value");
1087
1088 input1 = "key=valu<e";
1089 newValue = nullptr;
1090 napi_create_string_utf8(env, input1.c_str(), input1.size(), &newValue);
1091 napi_set_named_property(env, instance, "query", newValue);
1092 uriProperty = nullptr;
1093 napi_get_named_property(env, instance, "query", &uriProperty);
1094 res = GetStringUtf8(env, uriProperty);
1095 ASSERT_STREQ(res.c_str(), "key=value");
1096 }
1097
1098 HWTEST_F(NativeEngineTest, ModuleTest008, testing::ext::TestSize.Level0)
1099 {
1100 napi_env env = (napi_env)engine_;
1101 napi_value exports = nullptr;
1102 napi_create_object(env, &exports);
1103 OHOS::Uri::UriInit(env, exports);
1104 napi_value uriClass = nullptr;
1105 napi_value constructorArgs[1] = { 0 };
1106 std::string input = "http://username:password@www.baidu.com:99/path/path?query#fagment";
1107 napi_create_string_utf8(env, input.c_str(), input.size(), &constructorArgs[0]);
1108 napi_get_named_property(env, exports, "Uri", &uriClass);
1109 napi_value instance = nullptr;
1110 napi_new_instance(env, uriClass, 1, constructorArgs, &instance);
1111
1112 std::string input1 = "aasdfq";
1113 napi_value newValue = nullptr;
1114 napi_create_string_utf8(env, input1.c_str(), input1.size(), &newValue);
1115 napi_set_named_property(env, instance, "fragment", newValue);
1116 napi_value uriProperty = nullptr;
1117 napi_get_named_property(env, instance, "fragment", &uriProperty);
1118 std::string res = GetStringUtf8(env, uriProperty);
1119 ASSERT_STREQ(res.c_str(), "aasdfq");
1120
1121 input1 = "#aasdfq";
1122 newValue = nullptr;
1123 napi_create_string_utf8(env, input1.c_str(), input1.size(), &newValue);
1124 napi_set_named_property(env, instance, "fragment", newValue);
1125 uriProperty = nullptr;
1126 napi_get_named_property(env, instance, "fragment", &uriProperty);
1127 res = GetStringUtf8(env, uriProperty);
1128 ASSERT_STREQ(res.c_str(), "aasdfq");
1129 }
1130
1131 HWTEST_F(NativeEngineTest, ModuleTest009, testing::ext::TestSize.Level0)
1132 {
1133 napi_env env = (napi_env)engine_;
1134 napi_value exports = nullptr;
1135 napi_create_object(env, &exports);
1136 OHOS::Uri::UriInit(env, exports);
1137 napi_value uriClass = nullptr;
1138 napi_value constructorArgs[1] = { 0 };
1139 std::string input = "http://username:password@www.baidu.com:99/path/path?query#fagment";
1140 napi_create_string_utf8(env, input.c_str(), input.size(), &constructorArgs[0]);
1141 napi_get_named_property(env, exports, "Uri", &uriClass);
1142 napi_value instance = nullptr;
1143 napi_new_instance(env, uriClass, 1, constructorArgs, &instance);
1144
1145 std::string input1 = "userinfo@www.test.cn:89";
1146 napi_value newValue = nullptr;
1147 napi_create_string_utf8(env, input1.c_str(), input1.size(), &newValue);
1148 napi_set_named_property(env, instance, "authority", newValue);
1149 napi_value uriProperty = nullptr;
1150 napi_get_named_property(env, instance, "authority", &uriProperty);
1151 std::string res = GetStringUtf8(env, uriProperty);
1152 ASSERT_STREQ(res.c_str(), "userinfo@www.test.cn:89");
1153
1154 input1 = "useri<nfo@www.test.cn:89";
1155 newValue = nullptr;
1156 napi_create_string_utf8(env, input1.c_str(), input1.size(), &newValue);
1157 napi_set_named_property(env, instance, "authority", newValue);
1158 uriProperty = nullptr;
1159 napi_get_named_property(env, instance, "authority", &uriProperty);
1160 res = GetStringUtf8(env, uriProperty);
1161 ASSERT_STREQ(res.c_str(), "useri<nfo@www.test.cn:89");
1162 }
1163
1164 HWTEST_F(NativeEngineTest, ModuleTest010, testing::ext::TestSize.Level0)
1165 {
1166 napi_env env = (napi_env)engine_;
1167 napi_value exports = nullptr;
1168 napi_create_object(env, &exports);
1169 OHOS::Uri::UriInit(env, exports);
1170 napi_value uriClass = nullptr;
1171 napi_value constructorArgs[1] = { 0 };
1172 std::string input = "http://username:password@www.baidu.com:99/path/path?query#fagment";
1173 napi_create_string_utf8(env, input.c_str(), input.size(), &constructorArgs[0]);
1174 napi_get_named_property(env, exports, "Uri", &uriClass);
1175 napi_value instance = nullptr;
1176 napi_new_instance(env, uriClass, 1, constructorArgs, &instance);
1177
1178 std::string input1 = "//usc@www.test321.cn:996?key=1";
1179 napi_value newValue = nullptr;
1180 napi_create_string_utf8(env, input1.c_str(), input1.size(), &newValue);
1181 napi_set_named_property(env, instance, "ssp", newValue);
1182 napi_value uriProperty = nullptr;
1183 napi_get_named_property(env, instance, "ssp", &uriProperty);
1184 std::string res = GetStringUtf8(env, uriProperty);
1185 ASSERT_STREQ(res.c_str(), "//usc@www.test321.cn:996?key=1");
1186
1187 input1 = "/usc@www.test321.cn:996?key=1";
1188 newValue = nullptr;
1189 napi_create_string_utf8(env, input1.c_str(), input1.size(), &newValue);
1190 napi_set_named_property(env, instance, "ssp", newValue);
1191 uriProperty = nullptr;
1192 napi_get_named_property(env, instance, "ssp", &uriProperty);
1193 res = GetStringUtf8(env, uriProperty);
1194 ASSERT_STREQ(res.c_str(), "/usc@www.test321.cn:996?key=1");
1195
1196 input1 = "usc@www.test321.cn:996?key=1";
1197 newValue = nullptr;
1198 napi_create_string_utf8(env, input1.c_str(), input1.size(), &newValue);
1199 napi_set_named_property(env, instance, "ssp", newValue);
1200 uriProperty = nullptr;
1201 napi_get_named_property(env, instance, "ssp", &uriProperty);
1202 res = GetStringUtf8(env, uriProperty);
1203 ASSERT_STREQ(res.c_str(), "usc@www.test321.cn:996?key=1");
1204 }
1205
1206 HWTEST_F(NativeEngineTest, ModuleTest011, testing::ext::TestSize.Level0)
1207 {
1208 napi_env env = (napi_env)engine_;
1209 napi_value exports = nullptr;
1210 napi_create_object(env, &exports);
1211 OHOS::Uri::UriInit(env, exports);
1212 napi_value uriClass = nullptr;
1213 napi_value constructorArgs[1] = { 0 };
1214 std::string input = "http://username:password@www.uritest.com:99/path/abc?query#fagment";
1215 napi_create_string_utf8(env, input.c_str(), input.size(), &constructorArgs[0]);
1216 napi_status status = napi_get_named_property(env, exports, "Uri", &uriClass);
1217 napi_value instance = nullptr;
1218 status = napi_new_instance(env, uriClass, 1, constructorArgs, &instance);
1219 napi_value tempFn = nullptr;
1220 napi_value result = nullptr;
1221 napi_value key = StrToNapiValue(env, "qqwwee");
1222 napi_value value = StrToNapiValue(env, "erfa");
1223 napi_value keyArgs[] = { key, value };
1224 napi_get_named_property(env, instance, "addQueryValue", &tempFn);
1225 napi_call_function(env, instance, tempFn, 2, keyArgs, &result);
1226 std::string res = GetStringUtf8(env, result);
1227 ASSERT_STREQ(res.c_str(), "http://username:password@www.uritest.com:99/path/abc?query&qqwwee=erfa#fagment");
1228 napi_value segment = StrToNapiValue(env, "wqaaas");
1229 napi_value segargs[] = { segment };
1230 napi_get_named_property(env, instance, "addSegment", &tempFn);
1231 napi_call_function(env, instance, tempFn, 1, segargs, &result);
1232 res = GetStringUtf8(env, result);
1233 ASSERT_STREQ(res.c_str(), "http://username:password@www.uritest.com:99/path/abc/wqaaas?query#fagment");
1234 value = StrToNapiValue(env, "https:");
1235 napi_set_named_property(env, instance, "scheme", value);
1236 napi_value uriProperty = nullptr;
1237 napi_get_named_property(env, instance, "scheme", &uriProperty);
1238 res = GetStringUtf8(env, uriProperty);
1239 ASSERT_STREQ(res.c_str(), "https");
1240 value = StrToNapiValue(env, "usernameinfo");
1241 napi_set_named_property(env, instance, "userInfo", value);
1242 uriProperty = nullptr;
1243 napi_get_named_property(env, instance, "userInfo", &uriProperty);
1244 res = GetStringUtf8(env, uriProperty);
1245 ASSERT_STREQ(res.c_str(), "usernameinfo");
1246 }
1247
1248 HWTEST_F(NativeEngineTest, ModuleTest012, testing::ext::TestSize.Level0)
1249 {
1250 napi_env env = (napi_env)engine_;
1251 napi_value exports = nullptr;
1252 napi_create_object(env, &exports);
1253 OHOS::Uri::UriInit(env, exports);
1254 napi_value uriClass = nullptr;
1255 napi_value constructorArgs[1] = { 0 };
1256 std::string input = "http://username:password@www.uritest.com:99/path/abc?query#fagment";
1257 napi_create_string_utf8(env, input.c_str(), input.size(), &constructorArgs[0]);
1258 napi_status status = napi_get_named_property(env, exports, "Uri", &uriClass);
1259 napi_value instance = nullptr;
1260 status = napi_new_instance(env, uriClass, 1, constructorArgs, &instance);
1261 napi_value value = StrToNapiValue(env, "/path1/path2");
1262 napi_set_named_property(env, instance, "path", value);
1263 napi_value uriProperty = nullptr;
1264 napi_get_named_property(env, instance, "path", &uriProperty);
1265 std::string res = GetStringUtf8(env, uriProperty);
1266 ASSERT_STREQ(res.c_str(), "/path1/path2");
1267 value = StrToNapiValue(env, "qwfagm");
1268 napi_set_named_property(env, instance, "fragment", value);
1269 uriProperty = nullptr;
1270 napi_get_named_property(env, instance, "fragment", &uriProperty);
1271 res = GetStringUtf8(env, uriProperty);
1272 ASSERT_STREQ(res.c_str(), "qwfagm");
1273 value = StrToNapiValue(env, "aaa=bbb");
1274 napi_set_named_property(env, instance, "query", value);
1275 uriProperty = nullptr;
1276 napi_get_named_property(env, instance, "query", &uriProperty);
1277 res = GetStringUtf8(env, uriProperty);
1278 ASSERT_STREQ(res.c_str(), "aaa=bbb");
1279 value = StrToNapiValue(env, "user@www.test112.cn:189");
1280 napi_set_named_property(env, instance, "authority", value);
1281 uriProperty = nullptr;
1282 napi_get_named_property(env, instance, "authority", &uriProperty);
1283 res = GetStringUtf8(env, uriProperty);
1284 ASSERT_STREQ(res.c_str(), "user@www.test112.cn:189");
1285 value = StrToNapiValue(env, "//uscffac@www.testut.cn:223?key=val");
1286 napi_set_named_property(env, instance, "ssp", value);
1287 uriProperty = nullptr;
1288 napi_get_named_property(env, instance, "ssp", &uriProperty);
1289 res = GetStringUtf8(env, uriProperty);
1290 ASSERT_STREQ(res.c_str(), "//uscffac@www.testut.cn:223?key=val");
1291 }