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 22 #define ASSERT_CHECK_CALL(call) \ 23 { \ 24 ASSERT_EQ(call, napi_ok); \ 25 } 26 27 #define ASSERT_CHECK_VALUE_TYPE(env, value, type) \ 28 { \ 29 napi_valuetype valueType = napi_undefined; \ 30 ASSERT_TRUE(value != nullptr); \ 31 ASSERT_CHECK_CALL(napi_typeof(env, value, &valueType)); \ 32 ASSERT_EQ(valueType, type); \ 33 } 34 35 HWTEST_F(NativeEngineTest, ConstructorTest001, testing::ext::TestSize.Level0) 36 { 37 OHOS::Uri::Uri uri("http://username:password@www.baidu.com:99/path/path?query#fagment"); 38 ASSERT_STREQ(uri.GetScheme().c_str(), "http"); 39 ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@www.baidu.com:99"); 40 ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@www.baidu.com:99/path/path?query"); 41 ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); 42 ASSERT_STREQ(uri.GetHost().c_str(), "www.baidu.com"); 43 ASSERT_STREQ(uri.GetPort().c_str(), "99"); 44 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); 45 ASSERT_STREQ(uri.GetQuery().c_str(), "query"); 46 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); 47 } 48 49 HWTEST_F(NativeEngineTest, ConstructorTest002, testing::ext::TestSize.Level0) 50 { 51 OHOS::Uri::Uri uri("http://username:password@[1080::8:800:200C:417A]:99/path/66path1?query#fagment"); 52 ASSERT_STREQ(uri.GetScheme().c_str(), "http"); 53 ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[1080::8:800:200C:417A]:99"); 54 ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[1080::8:800:200C:417A]:99/path/66path1?query"); 55 ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); 56 ASSERT_STREQ(uri.GetHost().c_str(), "[1080::8:800:200C:417A]"); 57 ASSERT_STREQ(uri.GetPort().c_str(), "99"); 58 ASSERT_STREQ(uri.GetPath().c_str(), "/path/66path1"); 59 ASSERT_STREQ(uri.GetQuery().c_str(), "query"); 60 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); 61 } 62 63 HWTEST_F(NativeEngineTest, ConstructorTest003, testing::ext::TestSize.Level0) 64 { 65 OHOS::Uri::Uri uri("http://username:password@[::]:88/path/path66?foooo#gaogao"); 66 ASSERT_STREQ(uri.GetScheme().c_str(), "http"); 67 ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[::]:88"); 68 ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[::]:88/path/path66?foooo"); 69 ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); 70 ASSERT_STREQ(uri.GetHost().c_str(), "[::]"); 71 ASSERT_STREQ(uri.GetPort().c_str(), "88"); 72 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path66"); 73 ASSERT_STREQ(uri.GetQuery().c_str(), "foooo"); 74 ASSERT_STREQ(uri.GetFragment().c_str(), "gaogao"); 75 } 76 77 HWTEST_F(NativeEngineTest, ConstructorTest004, testing::ext::TestSize.Level0) 78 { 79 OHOS::Uri::Uri uri("http://username:password@[1:0:0:1:2:1:2:1]:99/path/66path1?query#fagment"); 80 ASSERT_STREQ(uri.GetScheme().c_str(), "http"); 81 ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[1:0:0:1:2:1:2:1]:99"); 82 ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[1:0:0:1:2:1:2:1]:99/path/66path1?query"); 83 ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); 84 ASSERT_STREQ(uri.GetHost().c_str(), "[1:0:0:1:2:1:2:1]"); 85 ASSERT_STREQ(uri.GetPort().c_str(), "99"); 86 ASSERT_STREQ(uri.GetPath().c_str(), "/path/66path1"); 87 ASSERT_STREQ(uri.GetQuery().c_str(), "query"); 88 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); 89 } 90 91 HWTEST_F(NativeEngineTest, ConstructorTest005, testing::ext::TestSize.Level0) 92 { 93 OHOS::Uri::Uri uri("http://username:password@[::FFFF:129.144.52.38]:99/path/path?query#fagment"); 94 ASSERT_STREQ(uri.GetScheme().c_str(), "http"); 95 ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[::FFFF:129.144.52.38]:99"); 96 ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[::FFFF:129.144.52.38]:99/path/path?query"); 97 ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); 98 ASSERT_STREQ(uri.GetHost().c_str(), "[::FFFF:129.144.52.38]"); 99 ASSERT_STREQ(uri.GetPort().c_str(), "99"); 100 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); 101 ASSERT_STREQ(uri.GetQuery().c_str(), "query"); 102 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); 103 } 104 105 HWTEST_F(NativeEngineTest, ConstructorTest006, testing::ext::TestSize.Level0) 106 { 107 OHOS::Uri::Uri uri("http://username:password@[::192.9.5.5]:99/path/path?query#fagment"); 108 ASSERT_STREQ(uri.GetScheme().c_str(), "http"); 109 ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[::192.9.5.5]:99"); 110 ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[::192.9.5.5]:99/path/path?query"); 111 ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); 112 ASSERT_STREQ(uri.GetHost().c_str(), "[::192.9.5.5]"); 113 ASSERT_STREQ(uri.GetPort().c_str(), "99"); 114 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); 115 ASSERT_STREQ(uri.GetQuery().c_str(), "query"); 116 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); 117 } 118 119 HWTEST_F(NativeEngineTest, ConstructorTest007, testing::ext::TestSize.Level0) 120 { 121 OHOS::Uri::Uri uri("http://username:password@[22::22:2:2%ss]:99/path/path?query#fagment"); 122 ASSERT_STREQ(uri.GetScheme().c_str(), "http"); 123 ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[22::22:2:2%ss]:99"); 124 ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[22::22:2:2%ss]:99/path/path?query"); 125 ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); 126 ASSERT_STREQ(uri.GetHost().c_str(), "[22::22:2:2%ss]"); 127 ASSERT_STREQ(uri.GetPort().c_str(), "99"); 128 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); 129 ASSERT_STREQ(uri.GetQuery().c_str(), "query"); 130 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); 131 } 132 133 HWTEST_F(NativeEngineTest, ConstructorTest008, testing::ext::TestSize.Level0) 134 { 135 OHOS::Uri::Uri uri("http://username:password@[fe80:0000:0001:0000:0440:44ff:1233:5678]" 136 ":99/path/path?query#fagment"); 137 ASSERT_STREQ(uri.GetScheme().c_str(), "http"); 138 ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[fe80:0000:0001:0000:0440:44ff:1233:5678]:99"); 139 ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[fe80:0000:0001:0000:0440:44ff:1233:5678]" 140 ":99/path/path?query"); 141 ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); 142 ASSERT_STREQ(uri.GetHost().c_str(), "[fe80:0000:0001:0000:0440:44ff:1233:5678]"); 143 ASSERT_STREQ(uri.GetPort().c_str(), "99"); 144 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); 145 ASSERT_STREQ(uri.GetQuery().c_str(), "query"); 146 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); 147 } 148 149 HWTEST_F(NativeEngineTest, ConstructorTest009, testing::ext::TestSize.Level0) 150 { 151 OHOS::Uri::Uri uri("http://username:password@[fe80::0001:0000]:99/path/path?query#fagment"); 152 ASSERT_STREQ(uri.GetScheme().c_str(), "http"); 153 ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[fe80::0001:0000]:99"); 154 ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[fe80::0001:0000]:99/path/path?query"); 155 ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); 156 ASSERT_STREQ(uri.GetHost().c_str(), "[fe80::0001:0000]"); 157 ASSERT_STREQ(uri.GetPort().c_str(), "99"); 158 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); 159 ASSERT_STREQ(uri.GetQuery().c_str(), "query"); 160 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); 161 } 162 163 HWTEST_F(NativeEngineTest, ConstructorTest010, testing::ext::TestSize.Level0) 164 { 165 OHOS::Uri::Uri uri("http://username:password@www.baidu.com:99/path/path?query#fagment"); 166 ASSERT_STREQ(uri.GetScheme().c_str(), "http"); 167 ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@www.baidu.com:99"); 168 ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@www.baidu.com:99/path/path?query"); 169 ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); 170 ASSERT_STREQ(uri.GetHost().c_str(), "www.baidu.com"); 171 ASSERT_STREQ(uri.GetPort().c_str(), "99"); 172 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); 173 ASSERT_STREQ(uri.GetQuery().c_str(), "query"); 174 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); 175 } 176 177 HWTEST_F(NativeEngineTest, ConstructorTest011, testing::ext::TestSize.Level0) 178 { 179 OHOS::Uri::Uri uri("http://username:password@199.98.55.44:99/path/path?query#fagment"); 180 ASSERT_STREQ(uri.GetScheme().c_str(), "http"); 181 ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@199.98.55.44:99"); 182 ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@199.98.55.44:99/path/path?query"); 183 ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); 184 ASSERT_STREQ(uri.GetHost().c_str(), "199.98.55.44"); 185 ASSERT_STREQ(uri.GetPort().c_str(), "99"); 186 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); 187 ASSERT_STREQ(uri.GetQuery().c_str(), "query"); 188 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); 189 } 190 191 HWTEST_F(NativeEngineTest, ConstructorTest012, testing::ext::TestSize.Level0) 192 { 193 OHOS::Uri::Uri uri("http://16.9.5.4:99/path/path?query#fagment"); 194 ASSERT_STREQ(uri.GetScheme().c_str(), "http"); 195 ASSERT_STREQ(uri.GetAuthority().c_str(), "16.9.5.4:99"); 196 ASSERT_STREQ(uri.GetSsp().c_str(), "//16.9.5.4:99/path/path?query"); 197 ASSERT_STREQ(uri.GetUserinfo().c_str(), "null"); 198 ASSERT_STREQ(uri.GetHost().c_str(), "16.9.5.4"); 199 ASSERT_STREQ(uri.GetPort().c_str(), "99"); 200 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); 201 ASSERT_STREQ(uri.GetQuery().c_str(), "query"); 202 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); 203 } 204 205 HWTEST_F(NativeEngineTest, ConstructorTest013, testing::ext::TestSize.Level0) 206 { 207 OHOS::Uri::Uri uri("http://[::168:169:333]:99/path/path?query#fagment"); 208 ASSERT_STREQ(uri.GetScheme().c_str(), "http"); 209 ASSERT_STREQ(uri.GetAuthority().c_str(), "[::168:169:333]:99"); 210 ASSERT_STREQ(uri.GetSsp().c_str(), "//[::168:169:333]:99/path/path?query"); 211 ASSERT_STREQ(uri.GetUserinfo().c_str(), "null"); 212 ASSERT_STREQ(uri.GetHost().c_str(), "[::168:169:333]"); 213 ASSERT_STREQ(uri.GetPort().c_str(), "99"); 214 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); 215 ASSERT_STREQ(uri.GetQuery().c_str(), "query"); 216 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); 217 } 218 219 HWTEST_F(NativeEngineTest, ConstructorTest014, testing::ext::TestSize.Level0) 220 { 221 OHOS::Uri::Uri uri("http://user@49.10hh8.54.12:80/path/path?query#qwer"); 222 ASSERT_STREQ(uri.GetScheme().c_str(), "http"); 223 ASSERT_STREQ(uri.GetAuthority().c_str(), "user@49.10hh8.54.12:80"); 224 ASSERT_STREQ(uri.GetSsp().c_str(), "//user@49.10hh8.54.12:80/path/path?query"); 225 ASSERT_STREQ(uri.GetUserinfo().c_str(), "null"); 226 ASSERT_STREQ(uri.GetHost().c_str(), "null"); 227 ASSERT_STREQ(uri.GetPort().c_str(), "-1"); 228 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); 229 ASSERT_STREQ(uri.GetQuery().c_str(), "query"); 230 ASSERT_STREQ(uri.GetFragment().c_str(), "qwer"); 231 } 232 233 HWTEST_F(NativeEngineTest, ConstructorTest015, testing::ext::TestSize.Level0) 234 { 235 OHOS::Uri::Uri uri("http://user@www.baidu.com/path/path?query#qwer"); 236 ASSERT_STREQ(uri.GetScheme().c_str(), "http"); 237 ASSERT_STREQ(uri.GetAuthority().c_str(), "user@www.baidu.com"); 238 ASSERT_STREQ(uri.GetSsp().c_str(), "//user@www.baidu.com/path/path?query"); 239 ASSERT_STREQ(uri.GetUserinfo().c_str(), "user"); 240 ASSERT_STREQ(uri.GetHost().c_str(), "www.baidu.com"); 241 ASSERT_STREQ(uri.GetPort().c_str(), "-1"); 242 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); 243 ASSERT_STREQ(uri.GetQuery().c_str(), "query"); 244 ASSERT_STREQ(uri.GetFragment().c_str(), "qwer"); 245 } 246 247 HWTEST_F(NativeEngineTest, ConstructorTest016, testing::ext::TestSize.Level0) 248 { 249 OHOS::Uri::Uri uri("ftp://user@www.1hw.1com:77/path/path?query#qwer"); 250 ASSERT_STREQ(uri.GetScheme().c_str(), "ftp"); 251 ASSERT_STREQ(uri.GetAuthority().c_str(), "user@www.1hw.1com:77"); 252 ASSERT_STREQ(uri.GetSsp().c_str(), "//user@www.1hw.1com:77/path/path?query"); 253 ASSERT_STREQ(uri.GetUserinfo().c_str(), "null"); 254 ASSERT_STREQ(uri.GetHost().c_str(), "null"); 255 ASSERT_STREQ(uri.GetPort().c_str(), "-1"); 256 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); 257 ASSERT_STREQ(uri.GetQuery().c_str(), "query"); 258 ASSERT_STREQ(uri.GetFragment().c_str(), "qwer"); 259 } 260 261 HWTEST_F(NativeEngineTest, ConstructorTest017, testing::ext::TestSize.Level0) 262 { 263 OHOS::Uri::Uri uri("http://user@hosthost/path/path?query#qwer"); 264 ASSERT_STREQ(uri.GetScheme().c_str(), "http"); 265 ASSERT_STREQ(uri.GetAuthority().c_str(), "user@hosthost"); 266 ASSERT_STREQ(uri.GetSsp().c_str(), "//user@hosthost/path/path?query"); 267 ASSERT_STREQ(uri.GetUserinfo().c_str(), "user"); 268 ASSERT_STREQ(uri.GetHost().c_str(), "hosthost"); 269 ASSERT_STREQ(uri.GetPort().c_str(), "-1"); 270 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); 271 ASSERT_STREQ(uri.GetQuery().c_str(), "query"); 272 ASSERT_STREQ(uri.GetFragment().c_str(), "qwer"); 273 } 274 275 HWTEST_F(NativeEngineTest, ConstructorTest018, testing::ext::TestSize.Level0) 276 { 277 OHOS::Uri::Uri uri("http://user@[::]/path/path?query#qwer"); 278 ASSERT_STREQ(uri.GetScheme().c_str(), "http"); 279 ASSERT_STREQ(uri.GetAuthority().c_str(), "user@[::]"); 280 ASSERT_STREQ(uri.GetSsp().c_str(), "//user@[::]/path/path?query"); 281 ASSERT_STREQ(uri.GetUserinfo().c_str(), "user"); 282 ASSERT_STREQ(uri.GetHost().c_str(), "[::]"); 283 ASSERT_STREQ(uri.GetPort().c_str(), "-1"); 284 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); 285 ASSERT_STREQ(uri.GetQuery().c_str(), "query"); 286 ASSERT_STREQ(uri.GetFragment().c_str(), "qwer"); 287 } 288 289 HWTEST_F(NativeEngineTest, ConstructorTest019, testing::ext::TestSize.Level0) 290 { 291 OHOS::Uri::Uri uri("http://[::192:0:5]/path/path?query#qwer"); 292 ASSERT_STREQ(uri.GetScheme().c_str(), "http"); 293 ASSERT_STREQ(uri.GetAuthority().c_str(), "[::192:0:5]"); 294 ASSERT_STREQ(uri.GetSsp().c_str(), "//[::192:0:5]/path/path?query"); 295 ASSERT_STREQ(uri.GetUserinfo().c_str(), "null"); 296 ASSERT_STREQ(uri.GetHost().c_str(), "[::192:0:5]"); 297 ASSERT_STREQ(uri.GetPort().c_str(), "-1"); 298 ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); 299 ASSERT_STREQ(uri.GetQuery().c_str(), "query"); 300 ASSERT_STREQ(uri.GetFragment().c_str(), "qwer"); 301 } 302 303 HWTEST_F(NativeEngineTest, ConstructorTest020, testing::ext::TestSize.Level0) 304 { 305 OHOS::Uri::Uri uri("http:/username:password@www.baidu.com:99/path/path?query#fagment"); 306 ASSERT_STREQ(uri.GetScheme().c_str(), "http"); 307 ASSERT_STREQ(uri.GetAuthority().c_str(), "null"); 308 ASSERT_STREQ(uri.GetSsp().c_str(), "/username:password@www.baidu.com:99/path/pathquery"); 309 ASSERT_STREQ(uri.GetUserinfo().c_str(), "null"); 310 ASSERT_STREQ(uri.GetHost().c_str(), "null"); 311 ASSERT_STREQ(uri.GetPort().c_str(), "-1"); 312 ASSERT_STREQ(uri.GetPath().c_str(), "/username:password@www.baidu.com:99/path/path"); 313 ASSERT_STREQ(uri.GetQuery().c_str(), "query"); 314 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); 315 } 316 317 HWTEST_F(NativeEngineTest, ConstructorTest021, testing::ext::TestSize.Level0) 318 { 319 OHOS::Uri::Uri uri("http:/&username:password@[1080::8:800:200C:417A]:99/path/66path1?query#fagment"); 320 ASSERT_STREQ(uri.GetScheme().c_str(), "http"); 321 ASSERT_STREQ(uri.GetAuthority().c_str(), "null"); 322 ASSERT_STREQ(uri.GetSsp().c_str(), "/&username:password@[1080::8:800:200C:417A]:99/path/66path1query"); 323 ASSERT_STREQ(uri.GetUserinfo().c_str(), "null"); 324 ASSERT_STREQ(uri.GetHost().c_str(), "null"); 325 ASSERT_STREQ(uri.GetPort().c_str(), "-1"); 326 ASSERT_STREQ(uri.GetPath().c_str(), "/&username:password@[1080::8:800:200C:417A]:99/path/66path1"); 327 ASSERT_STREQ(uri.GetQuery().c_str(), "query"); 328 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); 329 } 330 331 HWTEST_F(NativeEngineTest, ConstructorTest022, testing::ext::TestSize.Level0) 332 { 333 OHOS::Uri::Uri uri("http:/[username:password@[::FFFF:129.144.52.38]:99/path/path?query#fagment"); 334 ASSERT_STREQ(uri.GetScheme().c_str(), "http"); 335 ASSERT_STREQ(uri.GetAuthority().c_str(), "null"); 336 ASSERT_STREQ(uri.GetSsp().c_str(), "/[username:password@[::FFFF:129.144.52.38]:99/path/pathquery"); 337 ASSERT_STREQ(uri.GetUserinfo().c_str(), "null"); 338 ASSERT_STREQ(uri.GetHost().c_str(), "null"); 339 ASSERT_STREQ(uri.GetPort().c_str(), "-1"); 340 ASSERT_STREQ(uri.GetPath().c_str(), "/[username:password@[::FFFF:129.144.52.38]:99/path/path"); 341 ASSERT_STREQ(uri.GetQuery().c_str(), "query"); 342 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); 343 } 344 345 HWTEST_F(NativeEngineTest, ConstructorTest023, testing::ext::TestSize.Level0) 346 { 347 OHOS::Uri::Uri uri("http:username:password@[1080::8:800:200C:417A]:99/path/66path1?query#fagment"); 348 ASSERT_STREQ(uri.GetScheme().c_str(), "http"); 349 ASSERT_STREQ(uri.GetAuthority().c_str(), "null"); 350 ASSERT_STREQ(uri.GetSsp().c_str(), "username:password@[1080::8:800:200C:417A]:99/path/66path1query"); 351 ASSERT_STREQ(uri.GetUserinfo().c_str(), "null"); 352 ASSERT_STREQ(uri.GetHost().c_str(), "null"); 353 ASSERT_STREQ(uri.GetPort().c_str(), "-1"); 354 ASSERT_STREQ(uri.GetPath().c_str(), "null"); 355 ASSERT_STREQ(uri.GetQuery().c_str(), "null"); 356 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); 357 } 358 359 HWTEST_F(NativeEngineTest, ConstructorTest024, testing::ext::TestSize.Level0) 360 { 361 OHOS::Uri::Uri uri("http:^$username:password@[::192.9.5.5]:99/path/path?query#fagment"); 362 ASSERT_STREQ(uri.GetScheme().c_str(), "http"); 363 ASSERT_STREQ(uri.GetAuthority().c_str(), "null"); 364 ASSERT_STREQ(uri.GetSsp().c_str(), "^$username:password@[::192.9.5.5]:99/path/pathquery"); 365 ASSERT_STREQ(uri.GetUserinfo().c_str(), "null"); 366 ASSERT_STREQ(uri.GetHost().c_str(), "null"); 367 ASSERT_STREQ(uri.GetPort().c_str(), "-1"); 368 ASSERT_STREQ(uri.GetPath().c_str(), "null"); 369 ASSERT_STREQ(uri.GetQuery().c_str(), "null"); 370 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); 371 } 372 373 HWTEST_F(NativeEngineTest, ConstructorTest025, testing::ext::TestSize.Level0) 374 { 375 OHOS::Uri::Uri uri("http:[?]username:password@[fe80::0001:0000]:99/path/path?query#fagment"); 376 ASSERT_STREQ(uri.GetScheme().c_str(), "http"); 377 ASSERT_STREQ(uri.GetAuthority().c_str(), "null"); 378 ASSERT_STREQ(uri.GetSsp().c_str(), "[]username:password@[fe80::0001:0000]:99/path/path?query"); 379 ASSERT_STREQ(uri.GetUserinfo().c_str(), "null"); 380 ASSERT_STREQ(uri.GetHost().c_str(), "null"); 381 ASSERT_STREQ(uri.GetPort().c_str(), "-1"); 382 ASSERT_STREQ(uri.GetPath().c_str(), "null"); 383 ASSERT_STREQ(uri.GetQuery().c_str(), "null"); 384 ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); 385 } 386 387 HWTEST_F(NativeEngineTest, EqualsTest001, testing::ext::TestSize.Level0) 388 { 389 OHOS::Uri::Uri uri("http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment"); 390 OHOS::Uri::Uri uri1 = uri; 391 ASSERT_TRUE(uri.Equals(uri1)); 392 } 393 394 HWTEST_F(NativeEngineTest, EqualsTest002, testing::ext::TestSize.Level0) 395 { 396 OHOS::Uri::Uri uri("http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment"); 397 OHOS::Uri::Uri uri1("http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment"); 398 ASSERT_TRUE(uri.Equals(uri1)); 399 } 400 401 HWTEST_F(NativeEngineTest, EqualsTest003, testing::ext::TestSize.Level0) 402 { 403 OHOS::Uri::Uri uri("http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment"); 404 OHOS::Uri::Uri uri1("http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment123"); 405 ASSERT_FALSE(uri.Equals(uri1)); 406 } 407 408 HWTEST_F(NativeEngineTest, NormalizeTest001, testing::ext::TestSize.Level0) 409 { 410 OHOS::Uri::Uri uri("http://user@[1:0:0:1:2:1:2:1]:99/path/66./../././mm/.././path1?query#fagment"); 411 std::string normalize = uri.Normalize(); 412 ASSERT_STREQ(normalize.c_str(), "http://user@[1:0:0:1:2:1:2:1]:99/path/path1?query#fagment"); 413 } 414 415 HWTEST_F(NativeEngineTest, NormalizeTest002, testing::ext::TestSize.Level0) 416 { 417 OHOS::Uri::Uri uri("http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../path?query#fagment"); 418 std::string normalize = uri.Normalize(); 419 ASSERT_STREQ(normalize.c_str(), "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../path?query#fagment"); 420 } 421 422 HWTEST_F(NativeEngineTest, NormalizeTest003, testing::ext::TestSize.Level0) 423 { 424 OHOS::Uri::Uri uri("http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../path/.././../aa/bb/cc?query#fagment"); 425 std::string normalize = uri.Normalize(); 426 ASSERT_STREQ(normalize.c_str(), "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../../aa/bb/cc?query#fagment"); 427 } 428 429 HWTEST_F(NativeEngineTest, ToStringTest001, testing::ext::TestSize.Level0) 430 { 431 OHOS::Uri::Uri uri("http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/aa/bb/cc?query#fagment"); 432 ASSERT_STREQ(uri.ToString().c_str(), "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/aa/bb/cc?query#fagment"); 433 } 434 435 HWTEST_F(NativeEngineTest, ToStringTest002, testing::ext::TestSize.Level0) 436 { 437 OHOS::Uri::Uri uri("htt1p://gg:gaogao@[::192.9.5.5]:99/path/66path1?query#fagment"); 438 ASSERT_STREQ(uri.ToString().c_str(), "htt1p://gg:gaogao@[::192.9.5.5]:99/path/66path1?query#fagment"); 439 } 440 441 HWTEST_F(NativeEngineTest, ToStringTest003, testing::ext::TestSize.Level0) 442 { 443 OHOS::Uri::Uri uri("ftp://username:www.baidu.com/path?query#fagment"); 444 ASSERT_STREQ(uri.ToString().c_str(), "ftp://username:www.baidu.com/path?query#fagment"); 445 } 446 447 HWTEST_F(NativeEngineTest, IsAbsoluteTest001, testing::ext::TestSize.Level0) 448 { 449 OHOS::Uri::Uri uri("f/tp://username:password@www.baidu.com:88/path?query#fagment"); 450 bool res = uri.IsAbsolute(); 451 ASSERT_FALSE(res); 452 } 453 454 HWTEST_F(NativeEngineTest, IsAbsoluteTest002, testing::ext::TestSize.Level0) 455 { 456 OHOS::Uri::Uri uri("ftp://username:password@www.baidu.com:88/path?query#fagment"); 457 bool res = uri.IsAbsolute(); 458 ASSERT_TRUE(res); 459 } 460 461 HWTEST_F(NativeEngineTest, IsAbsoluteTest003, testing::ext::TestSize.Level0) 462 { 463 OHOS::Uri::Uri uri("htt/p://username:password@www.baidu.com:88/path?query#fagment"); 464 bool res = uri.IsAbsolute(); 465 ASSERT_FALSE(res); 466 } 467