• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "utils/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(), "null");
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(), "null");
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(), "null");
227     ASSERT_STREQ(uri.GetHost().c_str(), "null");
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(), "null");
255     ASSERT_STREQ(uri.GetHost().c_str(), "null");
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(), "null");
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(), "null");
309     ASSERT_STREQ(uri.GetSsp().c_str(), "/username:password@www.baidu.com:99/path/pathquery");
310     ASSERT_STREQ(uri.GetUserinfo().c_str(), "null");
311     ASSERT_STREQ(uri.GetHost().c_str(), "null");
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(), "null");
323     ASSERT_STREQ(uri.GetSsp().c_str(), "/&username:password@[1080::8:800:200C:417A]:99/path/66path1query");
324     ASSERT_STREQ(uri.GetUserinfo().c_str(), "null");
325     ASSERT_STREQ(uri.GetHost().c_str(), "null");
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(), "null");
337     ASSERT_STREQ(uri.GetSsp().c_str(), "/[username:password@[::FFFF:129.144.52.38]:99/path/pathquery");
338     ASSERT_STREQ(uri.GetUserinfo().c_str(), "null");
339     ASSERT_STREQ(uri.GetHost().c_str(), "null");
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(), "null");
351     ASSERT_STREQ(uri.GetSsp().c_str(), "username:password@[1080::8:800:200C:417A]:99/path/66path1query");
352     ASSERT_STREQ(uri.GetUserinfo().c_str(), "null");
353     ASSERT_STREQ(uri.GetHost().c_str(), "null");
354     ASSERT_STREQ(uri.GetPort().c_str(), "-1");
355     ASSERT_STREQ(uri.GetPath().c_str(), "null");
356     ASSERT_STREQ(uri.GetQuery().c_str(), "null");
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(), "null");
365     ASSERT_STREQ(uri.GetSsp().c_str(), "^$username:password@[::192.9.5.5]:99/path/pathquery");
366     ASSERT_STREQ(uri.GetUserinfo().c_str(), "null");
367     ASSERT_STREQ(uri.GetHost().c_str(), "null");
368     ASSERT_STREQ(uri.GetPort().c_str(), "-1");
369     ASSERT_STREQ(uri.GetPath().c_str(), "null");
370     ASSERT_STREQ(uri.GetQuery().c_str(), "null");
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(), "null");
379     ASSERT_STREQ(uri.GetSsp().c_str(), "[]username:password@[fe80::0001:0000]:99/path/path?query");
380     ASSERT_STREQ(uri.GetUserinfo().c_str(), "null");
381     ASSERT_STREQ(uri.GetHost().c_str(), "null");
382     ASSERT_STREQ(uri.GetPort().c_str(), "-1");
383     ASSERT_STREQ(uri.GetPath().c_str(), "null");
384     ASSERT_STREQ(uri.GetQuery().c_str(), "null");
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(), "null");
392     ASSERT_STREQ(uri.GetSsp().c_str(), "null");
393     ASSERT_STREQ(uri.GetFragment().c_str(), "null");
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.IsFailed().c_str(), "scheme does not conform to the rule");
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, EqualsTest001, testing::ext::TestSize.Level0)
482 {
483     OHOS::Uri::Uri uri("http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment");
484     OHOS::Uri::Uri uri1 = uri;
485     ASSERT_TRUE(uri.Equals(uri1));
486 }
487 
488 HWTEST_F(NativeEngineTest, EqualsTest002, testing::ext::TestSize.Level0)
489 {
490     OHOS::Uri::Uri uri("http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment");
491     OHOS::Uri::Uri uri1("http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment");
492     ASSERT_TRUE(uri.Equals(uri1));
493 }
494 
495 HWTEST_F(NativeEngineTest, EqualsTest003, testing::ext::TestSize.Level0)
496 {
497     OHOS::Uri::Uri uri("http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment");
498     OHOS::Uri::Uri uri1("http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment123");
499     ASSERT_FALSE(uri.Equals(uri1));
500 }
501 
502 HWTEST_F(NativeEngineTest, EqualsTest004, testing::ext::TestSize.Level0)
503 {
504     OHOS::Uri::Uri uri("http://username:password@www.baidu.com:99/path/path?query#fagment");
505     OHOS::Uri::Uri uri1("http://username:password@www.baidu.com:29/path/path?query#fagment");
506     ASSERT_FALSE(uri.Equals(uri1));
507 }
508 
509 HWTEST_F(NativeEngineTest, EqualsTest005, testing::ext::TestSize.Level0)
510 {
511     OHOS::Uri::Uri uri("http://username:password@www.baidu.com:99/path/path?query#fagment");
512     OHOS::Uri::Uri uri1("http://user1name:password@www.baidu.com:99/path/path?query#fagment");
513     ASSERT_FALSE(uri.Equals(uri1));
514 }
515 
516 HWTEST_F(NativeEngineTest, EqualsTest006, testing::ext::TestSize.Level0)
517 {
518     OHOS::Uri::Uri uri("http://username:password@www.baidu.com:99/path/path?query#fagment");
519     OHOS::Uri::Uri uri1("http://username:password@w2ww.baidu.com:99/path/path?query#fagment");
520     ASSERT_FALSE(uri.Equals(uri1));
521 }
522 
523 HWTEST_F(NativeEngineTest, EqualsTest007, testing::ext::TestSize.Level0)
524 {
525     OHOS::Uri::Uri uri("http://username:password@www.baidu.com:99/path/path?query#fagment");
526     OHOS::Uri::Uri uri1("http://username:password@www.baidu.com:99/pa4th/path?query#fagment");
527     ASSERT_FALSE(uri.Equals(uri1));
528 }
529 
530 HWTEST_F(NativeEngineTest, EqualsTest008, testing::ext::TestSize.Level0)
531 {
532     OHOS::Uri::Uri uri("http://username:password@www.baidu.com:99/path/path?qu4ery#fagment");
533     OHOS::Uri::Uri uri1("http://username:password@www.baidu.com:99/path/path?query#fagment");
534     ASSERT_FALSE(uri.Equals(uri1));
535 }
536 
537 HWTEST_F(NativeEngineTest, EqualsTest009, testing::ext::TestSize.Level0)
538 {
539     OHOS::Uri::Uri uri("http://username:password@www.baidu.com:99/path/path?query#fagment");
540     OHOS::Uri::Uri uri1("h4ttp://username:password@www.baidu.com:99/path/path?query#fagment");
541     ASSERT_FALSE(uri.Equals(uri1));
542 }
543 
544 HWTEST_F(NativeEngineTest, NormalizeTest001, testing::ext::TestSize.Level0)
545 {
546     OHOS::Uri::Uri uri("http://user@[1:0:0:1:2:1:2:1]:99/path/66./../././mm/.././path1?query#fagment");
547     std::string normalize = uri.Normalize();
548     ASSERT_STREQ(normalize.c_str(), "http://user@[1:0:0:1:2:1:2:1]:99/path/path1?query#fagment");
549 }
550 
551 HWTEST_F(NativeEngineTest, NormalizeTest002, testing::ext::TestSize.Level0)
552 {
553     OHOS::Uri::Uri uri("http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../path?query#fagment");
554     std::string normalize = uri.Normalize();
555     ASSERT_STREQ(normalize.c_str(), "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../path?query#fagment");
556 }
557 
558 HWTEST_F(NativeEngineTest, NormalizeTest003, testing::ext::TestSize.Level0)
559 {
560     OHOS::Uri::Uri uri("http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../path/.././../aa/bb/cc?query#fagment");
561     std::string normalize = uri.Normalize();
562     ASSERT_STREQ(normalize.c_str(), "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../../aa/bb/cc?query#fagment");
563 }
564 
565 HWTEST_F(NativeEngineTest, NormalizeTest004, testing::ext::TestSize.Level0)
566 {
567     OHOS::Uri::Uri uri("http://gg:gaogao@[1:0:0:1:2:1:2:1]:99?query#fagment");
568     std::string normalize = uri.Normalize();
569     ASSERT_STREQ(normalize.c_str(), "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99?query#fagment");
570 }
571 
572 HWTEST_F(NativeEngineTest, ToStringTest001, testing::ext::TestSize.Level0)
573 {
574     OHOS::Uri::Uri uri("http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/aa/bb/cc?query#fagment");
575     ASSERT_STREQ(uri.ToString().c_str(), "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/aa/bb/cc?query#fagment");
576 }
577 
578 HWTEST_F(NativeEngineTest, ToStringTest002, testing::ext::TestSize.Level0)
579 {
580     OHOS::Uri::Uri uri("htt1p://gg:gaogao@[::192.9.5.5]:99/path/66path1?query#fagment");
581     ASSERT_STREQ(uri.ToString().c_str(), "htt1p://gg:gaogao@[::192.9.5.5]:99/path/66path1?query#fagment");
582 }
583 
584 HWTEST_F(NativeEngineTest, ToStringTest003, testing::ext::TestSize.Level0)
585 {
586     OHOS::Uri::Uri uri("ftp://username:www.baidu.com/path?query#fagment");
587     ASSERT_STREQ(uri.ToString().c_str(), "ftp://username:www.baidu.com/path?query#fagment");
588 }
589 
590 HWTEST_F(NativeEngineTest, IsAbsoluteTest001, testing::ext::TestSize.Level0)
591 {
592     OHOS::Uri::Uri uri("f/tp://username:password@www.baidu.com:88/path?query#fagment");
593     bool res = uri.IsAbsolute();
594     ASSERT_FALSE(res);
595 }
596 
597 HWTEST_F(NativeEngineTest, IsAbsoluteTest002, testing::ext::TestSize.Level0)
598 {
599     OHOS::Uri::Uri uri("ftp://username:password@www.baidu.com:88/path?query#fagment");
600     bool res = uri.IsAbsolute();
601     ASSERT_TRUE(res);
602 }
603 
604 HWTEST_F(NativeEngineTest, IsAbsoluteTest003, testing::ext::TestSize.Level0)
605 {
606     OHOS::Uri::Uri uri("htt/p://username:password@www.baidu.com:88/path?query#fagment");
607     bool res = uri.IsAbsolute();
608     ASSERT_FALSE(res);
609 }
610 
GetStringUtf8(napi_env env,napi_value str)611 std::string GetStringUtf8(napi_env env, napi_value str) {
612     std::string buffer = "";
613     size_t bufferSize = 0;
614     if (napi_get_value_string_utf8(env, str, nullptr, 0, &bufferSize) != napi_ok) {
615         HILOG_ERROR("can not get src size");
616         return buffer;
617     }
618     buffer.resize(bufferSize);
619     if (napi_get_value_string_utf8(env, str, buffer.data(), bufferSize + 1, &bufferSize) != napi_ok) {
620         HILOG_ERROR("can not get src value");
621         return buffer;
622     }
623     return buffer;
624 }
625 
626 HWTEST_F(NativeEngineTest, ModuleTest001, testing::ext::TestSize.Level0)
627 {
628     napi_env env = (napi_env)engine_;
629     napi_value exports = nullptr;
630     napi_create_object(env, &exports);
631     OHOS::Uri::UriInit(env, exports);
632     napi_value uriClass = nullptr;
633     napi_value constructorArgs[1] =  { 0 };
634     std::string input = "http://username:password@www.baidu.com:99/path/path?query#fagment";
635     napi_create_string_utf8(env, input.c_str(), input.size(), &constructorArgs[0]);
636     napi_status status = napi_get_named_property(env, exports, "Uri", &uriClass);
637     napi_value instance = nullptr;
638     status = napi_new_instance(env, uriClass, 1, constructorArgs, &instance);
639     napi_value getTemp = nullptr;
640     napi_get_named_property(env, instance, "scheme", &getTemp);
641     std::string res = GetStringUtf8(env, getTemp);
642     ASSERT_STREQ(res.c_str(), "http");
643 
644     napi_get_named_property(env, instance, "authority", &getTemp);
645     res = GetStringUtf8(env, getTemp);
646     ASSERT_STREQ(res.c_str(), "username:password@www.baidu.com:99");
647 
648     napi_get_named_property(env, instance, "ssp", &getTemp);
649     res = GetStringUtf8(env, getTemp);
650     ASSERT_STREQ(res.c_str(), "//username:password@www.baidu.com:99/path/path?query");
651 
652     napi_get_named_property(env, instance, "userInfo", &getTemp);
653     res = GetStringUtf8(env, getTemp);
654     ASSERT_STREQ(res.c_str(), "username:password");
655 
656     napi_get_named_property(env, instance, "host", &getTemp);
657     res = GetStringUtf8(env, getTemp);
658     ASSERT_STREQ(res.c_str(), "www.baidu.com");
659 
660     napi_get_named_property(env, instance, "port", &getTemp);
661     res = GetStringUtf8(env, getTemp);
662     ASSERT_STREQ(res.c_str(), "99");
663 
664     napi_get_named_property(env, instance, "path", &getTemp);
665     res = GetStringUtf8(env, getTemp);
666     ASSERT_STREQ(res.c_str(), "/path/path");
667 
668     napi_get_named_property(env, instance, "query", &getTemp);
669     res = GetStringUtf8(env, getTemp);
670     ASSERT_STREQ(res.c_str(), "query");
671 
672     napi_get_named_property(env, instance, "fragment", &getTemp);
673     res = GetStringUtf8(env, getTemp);
674     ASSERT_STREQ(res.c_str(), "fagment");
675 
676     napi_get_named_property(env, instance, "isFailed", &getTemp);
677     res = GetStringUtf8(env, getTemp);
678     ASSERT_STREQ(res.c_str(), "");
679 }
680 
681 HWTEST_F(NativeEngineTest, ModuleTest002, testing::ext::TestSize.Level0)
682 {
683     napi_env env = (napi_env)engine_;
684     napi_value exports = nullptr;
685     napi_create_object(env, &exports);
686     OHOS::Uri::UriInit(env, exports);
687     napi_value uriClass = nullptr;
688     napi_value constructorArgs[1] =  { 0 };
689     std::string input = "http://username:password@www.baidu.com:99/path/path?query#fagment";
690     napi_create_string_utf8(env, input.c_str(), input.size(), &constructorArgs[0]);
691     napi_get_named_property(env, exports, "Uri", &uriClass);
692     napi_value instance = nullptr;
693     napi_new_instance(env, uriClass, 1, constructorArgs, &instance);
694     napi_value tempFn = nullptr;
695     napi_get_named_property(env, instance, "checkIsAbsolute", &tempFn);
696     napi_value result = nullptr;
697     napi_call_function(env, instance, tempFn, 0, nullptr, &result);
698     ASSERT_TRUE(result);
699 
700     napi_get_named_property(env, instance, "toString", &tempFn);
701     napi_call_function(env, instance, tempFn, 0, nullptr, &result);
702     std::string res = GetStringUtf8(env, result);
703     ASSERT_STREQ(res.c_str(), "http://username:password@www.baidu.com:99/path/path?query#fagment");
704 
705     napi_get_named_property(env, instance, "normalize", &tempFn);
706     napi_call_function(env, instance, tempFn, 0, nullptr, &result);
707     res = GetStringUtf8(env, result);
708     ASSERT_STREQ(res.c_str(), "http://username:password@www.baidu.com:99/path/path?query#fagment");
709 
710     napi_value equalsFn = nullptr;
711     napi_get_named_property(env, instance, "equals", &equalsFn);
712     napi_value constructorArgs1[1] = { 0 };
713     std::string input2 = "http://username:password@www.baidu.com:88/path?query1#fagment";
714     napi_create_string_utf8(env, input2.c_str(), input2.size(), &constructorArgs1[0]);
715     napi_value otherInstance = nullptr;
716     napi_new_instance(env, uriClass, 1, constructorArgs1, &otherInstance);
717     napi_value args[1] = { otherInstance };
718     napi_value result1 = nullptr;
719     napi_call_function(env, instance, equalsFn, 1, args, &result1);
720     bool res1 = true;
721     napi_get_value_bool(env, result1, &res1);
722     ASSERT_FALSE(res1);
723 }