1 | /* $Id: tstRTUri.cpp 57982 2015-10-01 11:23:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT Testcase - URI parsing and creation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-2015 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 |
|
---|
28 | /*********************************************************************************************************************************
|
---|
29 | * Header Files *
|
---|
30 | *********************************************************************************************************************************/
|
---|
31 | #include <iprt/uri.h>
|
---|
32 |
|
---|
33 | #include <iprt/string.h>
|
---|
34 | #include <iprt/err.h>
|
---|
35 | #include <iprt/mem.h>
|
---|
36 | #include <iprt/test.h>
|
---|
37 |
|
---|
38 | #ifdef _DEBUG
|
---|
39 | # ifdef RT_OS_WINDOWS
|
---|
40 | # include <Shlwapi.h> /* For generating the PathCreateFromUrl/UrlCreateFromPath reference on Windows. */
|
---|
41 | # endif
|
---|
42 | #endif
|
---|
43 |
|
---|
44 | /*********************************************************************************************************************************
|
---|
45 | * Test data *
|
---|
46 | *********************************************************************************************************************************/
|
---|
47 |
|
---|
48 | static struct
|
---|
49 | {
|
---|
50 | const char *pszUri;
|
---|
51 | const char *pszScheme;
|
---|
52 | const char *pszAuthority;
|
---|
53 | const char *pszPath;
|
---|
54 | const char *pszQuery;
|
---|
55 | const char *pszFragment;
|
---|
56 |
|
---|
57 | const char *pszUsername;
|
---|
58 | const char *pszPassword;
|
---|
59 | const char *pszHost;
|
---|
60 | uint32_t uPort;
|
---|
61 |
|
---|
62 | const char *pszCreated;
|
---|
63 | } g_aTests[] =
|
---|
64 | {
|
---|
65 | { /* #0 */
|
---|
66 | "foo://tt:[email protected]:8042/over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there?name=%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60ferret#nose%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60",
|
---|
67 | /*.pszScheme =*/ "foo",
|
---|
68 | /*.pszAuthority =*/ "tt:[email protected]:8042",
|
---|
69 | /*.pszPath =*/ "/over/ <>#%\"{}|^[]`/there",
|
---|
70 | /*.pszQuery =*/ "name= <>#%\"{}|^[]`ferret",
|
---|
71 | /*.pszFragment =*/ "nose <>#%\"{}|^[]`",
|
---|
72 | /*.pszUsername =*/ "tt",
|
---|
73 | /*.pszPassword =*/ "yt",
|
---|
74 | /*.pszHost =*/ "example.com",
|
---|
75 | /*.uPort =*/ 8042,
|
---|
76 | /*.pszCreated =*/ NULL /* same as pszUri*/,
|
---|
77 | },
|
---|
78 | { /* #1 */
|
---|
79 | "foo://tt:[email protected]:8042/over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there?name=%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60ferret",
|
---|
80 | /*.pszScheme =*/ "foo",
|
---|
81 | /*.pszAuthority =*/ "tt:[email protected]:8042",
|
---|
82 | /*.pszPath =*/ "/over/ <>#%\"{}|^[]`/there",
|
---|
83 | /*.pszQuery =*/ "name= <>#%\"{}|^[]`ferret",
|
---|
84 | /*.pszFragment =*/ NULL,
|
---|
85 | /*.pszUsername =*/ "tt",
|
---|
86 | /*.pszPassword =*/ "yt",
|
---|
87 | /*.pszHost =*/ "example.com",
|
---|
88 | /*.uPort =*/ 8042,
|
---|
89 | /*.pszCreated =*/ NULL /* same as pszUri*/,
|
---|
90 | },
|
---|
91 | { /* #2 */
|
---|
92 | "foo://tt:[email protected]:8042/over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there",
|
---|
93 | /*.pszScheme =*/ "foo",
|
---|
94 | /*.pszAuthority =*/ "tt:[email protected]:8042",
|
---|
95 | /*.pszPath =*/ "/over/ <>#%\"{}|^[]`/there",
|
---|
96 | /*.pszQuery =*/ NULL,
|
---|
97 | /*.pszFragment =*/ NULL,
|
---|
98 | /*.pszUsername =*/ "tt",
|
---|
99 | /*.pszPassword =*/ "yt",
|
---|
100 | /*.pszHost =*/ "example.com",
|
---|
101 | /*.uPort =*/ 8042,
|
---|
102 | /*.pszCreated =*/ NULL /* same as pszUri*/,
|
---|
103 | },
|
---|
104 | { /* #3 */
|
---|
105 | "foo:[email protected]",
|
---|
106 | /*.pszScheme =*/ "foo",
|
---|
107 | /*.pszAuthority =*/ NULL,
|
---|
108 | /*.pszPath =*/ "[email protected]",
|
---|
109 | /*.pszQuery =*/ NULL,
|
---|
110 | /*.pszFragment =*/ NULL,
|
---|
111 | /*.pszUsername =*/ NULL,
|
---|
112 | /*.pszPassword =*/ NULL,
|
---|
113 | /*.pszHost =*/ NULL,
|
---|
114 | /*.uPort =*/ UINT32_MAX,
|
---|
115 | /*.pszCreated =*/ NULL /* same as pszUri*/,
|
---|
116 | },
|
---|
117 | { /* #4 */
|
---|
118 | "foo:/over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there?name=%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60ferret#nose%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60",
|
---|
119 | /*.pszScheme =*/ "foo",
|
---|
120 | /*.pszAuthority =*/ NULL,
|
---|
121 | /*.pszPath =*/ "/over/ <>#%\"{}|^[]`/there",
|
---|
122 | /*.pszQuery =*/ "name= <>#%\"{}|^[]`ferret",
|
---|
123 | /*.pszFragment =*/ "nose <>#%\"{}|^[]`",
|
---|
124 | /*.pszUsername =*/ NULL,
|
---|
125 | /*.pszPassword =*/ NULL,
|
---|
126 | /*.pszHost =*/ NULL,
|
---|
127 | /*.uPort =*/ UINT32_MAX,
|
---|
128 | /*.pszCreated =*/ NULL /* same as pszUri*/,
|
---|
129 | },
|
---|
130 | { /* #5 */
|
---|
131 | "foo:/over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there#nose%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60",
|
---|
132 | /*.pszScheme =*/ "foo",
|
---|
133 | /*.pszAuthority =*/ NULL,
|
---|
134 | /*.pszPath =*/ "/over/ <>#%\"{}|^[]`/there",
|
---|
135 | /*.pszQuery =*/ NULL,
|
---|
136 | /*.pszFragment =*/ "nose <>#%\"{}|^[]`",
|
---|
137 | /*.pszUsername =*/ NULL,
|
---|
138 | /*.pszPassword =*/ NULL,
|
---|
139 | /*.pszHost =*/ NULL,
|
---|
140 | /*.uPort =*/ UINT32_MAX,
|
---|
141 | /*.pszCreated =*/ NULL /* same as pszUri*/,
|
---|
142 | },
|
---|
143 | { /* #6 */
|
---|
144 | "urn:example:animal:ferret:nose",
|
---|
145 | /*.pszScheme =*/ "urn",
|
---|
146 | /*.pszAuthority =*/ NULL,
|
---|
147 | /*.pszPath =*/ "example:animal:ferret:nose",
|
---|
148 | /*.pszQuery =*/ NULL,
|
---|
149 | /*.pszFragment =*/ NULL,
|
---|
150 | /*.pszUsername =*/ NULL,
|
---|
151 | /*.pszPassword =*/ NULL,
|
---|
152 | /*.pszHost =*/ NULL,
|
---|
153 | /*.uPort =*/ UINT32_MAX,
|
---|
154 | /*.pszCreated =*/ NULL /* same as pszUri*/,
|
---|
155 | },
|
---|
156 | { /* #7 */
|
---|
157 | "foo:?name=%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60ferret#nose%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60",
|
---|
158 | /*.pszScheme =*/ "foo",
|
---|
159 | /*.pszAuthority =*/ NULL,
|
---|
160 | /*.pszPath =*/ NULL,
|
---|
161 | /*.pszQuery =*/ "name= <>#%\"{}|^[]`ferret",
|
---|
162 | /*.pszFragment =*/ "nose <>#%\"{}|^[]`",
|
---|
163 | /*.pszUsername =*/ NULL,
|
---|
164 | /*.pszPassword =*/ NULL,
|
---|
165 | /*.pszHost =*/ NULL,
|
---|
166 | /*.uPort =*/ UINT32_MAX,
|
---|
167 | /*.pszCreated =*/ NULL /* same as pszUri*/,
|
---|
168 | },
|
---|
169 | { /* #8 */
|
---|
170 | "foo:#nose%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60",
|
---|
171 | /*.pszScheme =*/ "foo",
|
---|
172 | /*.pszAuthority =*/ NULL,
|
---|
173 | /*.pszPath =*/ NULL,
|
---|
174 | /*.pszQuery =*/ NULL,
|
---|
175 | /*.pszFragment =*/ "nose <>#%\"{}|^[]`",
|
---|
176 | /*.pszUsername =*/ NULL,
|
---|
177 | /*.pszPassword =*/ NULL,
|
---|
178 | /*.pszHost =*/ NULL,
|
---|
179 | /*.uPort =*/ UINT32_MAX,
|
---|
180 | /*.pszCreated =*/ NULL /* same as pszUri*/,
|
---|
181 | },
|
---|
182 | { /* #9 */
|
---|
183 | "foo://tt:[email protected]:8042/?name=%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60ferret#nose%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60",
|
---|
184 | /*.pszScheme =*/ "foo",
|
---|
185 | /*.pszAuthority =*/ "tt:[email protected]:8042",
|
---|
186 | /*.pszPath =*/ "/",
|
---|
187 | /*.pszQuery =*/ "name= <>#%\"{}|^[]`ferret",
|
---|
188 | /*.pszFragment =*/ "nose <>#%\"{}|^[]`",
|
---|
189 | /*.pszUsername =*/ "tt",
|
---|
190 | /*.pszPassword =*/ "yt",
|
---|
191 | /*.pszHost =*/ "example.com",
|
---|
192 | /*.uPort =*/ 8042,
|
---|
193 | /*.pszCreated =*/ NULL /* same as pszUri*/,
|
---|
194 | },
|
---|
195 | { /* #10 */
|
---|
196 | "foo://tt:[email protected]:8042/",
|
---|
197 | /*.pszScheme =*/ "foo",
|
---|
198 | /*.pszAuthority =*/ "tt:[email protected]:8042",
|
---|
199 | /*.pszPath =*/ "/",
|
---|
200 | /*.pszQuery =*/ NULL,
|
---|
201 | /*.pszFragment =*/ NULL,
|
---|
202 | /*.pszUsername =*/ "tt",
|
---|
203 | /*.pszPassword =*/ "yt",
|
---|
204 | /*.pszHost =*/ "example.com",
|
---|
205 | /*.uPort =*/ 8042,
|
---|
206 | /*.pszCreated =*/ NULL /* same as pszUri*/,
|
---|
207 | },
|
---|
208 | { /* #11 */
|
---|
209 | "foo://tt:[email protected]:8042?name=%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60ferret#nose%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60",
|
---|
210 | /*.pszScheme =*/ "foo",
|
---|
211 | /*.pszAuthority =*/ "tt:[email protected]:8042",
|
---|
212 | /*.pszPath =*/ NULL,
|
---|
213 | /*.pszQuery =*/ "name= <>#%\"{}|^[]`ferret",
|
---|
214 | /*.pszFragment =*/ "nose <>#%\"{}|^[]`",
|
---|
215 | /*.pszUsername =*/ "tt",
|
---|
216 | /*.pszPassword =*/ "yt",
|
---|
217 | /*.pszHost =*/ "example.com",
|
---|
218 | /*.uPort =*/ 8042,
|
---|
219 | /*.pszCreated =*/ NULL /* same as pszUri*/,
|
---|
220 | },
|
---|
221 | { /* #12 */
|
---|
222 | "foo://tt:[email protected]:8042#nose%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60",
|
---|
223 | /*.pszScheme =*/ "foo",
|
---|
224 | /*.pszAuthority =*/ "tt:[email protected]:8042",
|
---|
225 | /*.pszPath =*/ NULL,
|
---|
226 | /*.pszQuery =*/ NULL,
|
---|
227 | /*.pszFragment =*/ "nose <>#%\"{}|^[]`",
|
---|
228 | /*.pszUsername =*/ "tt",
|
---|
229 | /*.pszPassword =*/ "yt",
|
---|
230 | /*.pszHost =*/ "example.com",
|
---|
231 | /*.uPort =*/ 8042,
|
---|
232 | /*.pszCreated =*/ NULL /* same as pszUri*/,
|
---|
233 | },
|
---|
234 | { /* #13 */
|
---|
235 | "foo://tt:[email protected]:8042",
|
---|
236 | /*.pszScheme =*/ "foo",
|
---|
237 | /*.pszAuthority =*/ "tt:[email protected]:8042",
|
---|
238 | /*.pszPath =*/ NULL,
|
---|
239 | /*.pszQuery =*/ NULL,
|
---|
240 | /*.pszFragment =*/ NULL,
|
---|
241 | /*.pszUsername =*/ "tt",
|
---|
242 | /*.pszPassword =*/ "yt",
|
---|
243 | /*.pszHost =*/ "example.com",
|
---|
244 | /*.uPort =*/ 8042,
|
---|
245 | /*.pszCreated =*/ NULL /* same as pszUri*/,
|
---|
246 | },
|
---|
247 | { /* #14 */
|
---|
248 | "file:///dir/dir/file",
|
---|
249 | /*.pszScheme =*/ "file",
|
---|
250 | /*.pszAuthority =*/ "",
|
---|
251 | /*.pszPath =*/ "/dir/dir/file",
|
---|
252 | /*.pszQuery =*/ NULL,
|
---|
253 | /*.pszFragment =*/ NULL,
|
---|
254 | /*.pszUsername =*/ NULL,
|
---|
255 | /*.pszPassword =*/ NULL,
|
---|
256 | /*.pszHost =*/ NULL,
|
---|
257 | /*.uPort =*/ UINT32_MAX,
|
---|
258 | /*.pszCreated =*/ NULL /* same as pszUri*/,
|
---|
259 | },
|
---|
260 | { /* #15 */
|
---|
261 | "foo:///",
|
---|
262 | /*.pszScheme =*/ "foo",
|
---|
263 | /*.pszAuthority =*/ "",
|
---|
264 | /*.pszPath =*/ "/",
|
---|
265 | /*.pszQuery =*/ NULL,
|
---|
266 | /*.pszFragment =*/ NULL,
|
---|
267 | /*.pszUsername =*/ NULL,
|
---|
268 | /*.pszPassword =*/ NULL,
|
---|
269 | /*.pszHost =*/ NULL,
|
---|
270 | /*.uPort =*/ UINT32_MAX,
|
---|
271 | /*.pszCreated =*/ NULL /* same as pszUri*/,
|
---|
272 | },
|
---|
273 | { /* #16 */
|
---|
274 | "foo://",
|
---|
275 | /*.pszScheme =*/ "foo",
|
---|
276 | /*.pszAuthority =*/ "",
|
---|
277 | /*.pszPath =*/ NULL,
|
---|
278 | /*.pszQuery =*/ NULL,
|
---|
279 | /*.pszFragment =*/ NULL,
|
---|
280 | /*.pszUsername =*/ NULL,
|
---|
281 | /*.pszPassword =*/ NULL,
|
---|
282 | /*.pszHost =*/ NULL,
|
---|
283 | /*.uPort =*/ UINT32_MAX,
|
---|
284 | /*.pszCreated =*/ NULL /* same as pszUri*/,
|
---|
285 | },
|
---|
286 | { /* #17 - UTF-8 escape sequences. */
|
---|
287 | "http://example.com/%ce%b3%ce%bb%cf%83%ce%b1%20%e0%a4%95\xe0\xa4\x95",
|
---|
288 | /*.pszScheme =*/ "http",
|
---|
289 | /*.pszAuthority =*/ "example.com",
|
---|
290 | /*.pszPath =*/ "/\xce\xb3\xce\xbb\xcf\x83\xce\xb1 \xe0\xa4\x95\xe0\xa4\x95",
|
---|
291 | /*.pszQuery =*/ NULL,
|
---|
292 | /*.pszFragment =*/ NULL,
|
---|
293 | /*.pszUsername =*/ NULL,
|
---|
294 | /*.pszPassword =*/ NULL,
|
---|
295 | /*.pszHost =*/ "example.com",
|
---|
296 | /*.uPort =*/ UINT32_MAX,
|
---|
297 | /*.pszCreated =*/ "http://example.com/\xce\xb3\xce\xbb\xcf\x83\xce\xb1%20\xe0\xa4\x95\xe0\xa4\x95",
|
---|
298 | },
|
---|
299 | };
|
---|
300 |
|
---|
301 |
|
---|
302 | struct URIFILETEST
|
---|
303 | {
|
---|
304 | const char *pcszPath;
|
---|
305 | const char *pcszUri;
|
---|
306 | uint32_t uFormat;
|
---|
307 | }
|
---|
308 | g_apCreateFileURIs[] =
|
---|
309 | {
|
---|
310 | {
|
---|
311 | "C:\\over\\ <>#%\"{}|^[]`\\there",
|
---|
312 | "file:///C:%5Cover%5C%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60%5Cthere",
|
---|
313 | URI_FILE_FORMAT_WIN
|
---|
314 | },
|
---|
315 | {
|
---|
316 | "/over/ <>#%\"{}|^[]`/there",
|
---|
317 | "file:///over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there",
|
---|
318 | URI_FILE_FORMAT_UNIX
|
---|
319 | },
|
---|
320 | {
|
---|
321 | NULL,
|
---|
322 | "file://",
|
---|
323 | URI_FILE_FORMAT_UNIX
|
---|
324 | },
|
---|
325 | {
|
---|
326 | NULL,
|
---|
327 | "file://",
|
---|
328 | URI_FILE_FORMAT_WIN
|
---|
329 | },
|
---|
330 | {
|
---|
331 | "/",
|
---|
332 | "file:///",
|
---|
333 | URI_FILE_FORMAT_UNIX
|
---|
334 | },
|
---|
335 | {
|
---|
336 | "\\",
|
---|
337 | "file:///",
|
---|
338 | URI_FILE_FORMAT_WIN
|
---|
339 | },
|
---|
340 | {
|
---|
341 | "/foo/bar",
|
---|
342 | "file:///foo/bar",
|
---|
343 | URI_FILE_FORMAT_UNIX
|
---|
344 | },
|
---|
345 | {
|
---|
346 | "\\foo\\bar",
|
---|
347 | "file:///foo%5Cbar",
|
---|
348 | URI_FILE_FORMAT_WIN
|
---|
349 | },
|
---|
350 | {
|
---|
351 | "C:/over/ <>#%\"{}|^[]`/there",
|
---|
352 | "file:///C:/over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there",
|
---|
353 | URI_FILE_FORMAT_UNIX
|
---|
354 | },
|
---|
355 | {
|
---|
356 | "\\over\\ <>#%\"{}|^[]`\\there",
|
---|
357 | "file:///over%5C%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60%5Cthere",
|
---|
358 | URI_FILE_FORMAT_WIN
|
---|
359 | },
|
---|
360 | {
|
---|
361 | "/usr/bin/grep",
|
---|
362 | "file:///usr/bin/grep",
|
---|
363 | URI_FILE_FORMAT_UNIX
|
---|
364 | },
|
---|
365 | {
|
---|
366 | "\\usr\\bin\\grep",
|
---|
367 | "file:///usr%5Cbin%5Cgrep",
|
---|
368 | URI_FILE_FORMAT_WIN
|
---|
369 | },
|
---|
370 | {
|
---|
371 | "/unixserver/isos/files.lst",
|
---|
372 | "file:///unixserver/isos/files.lst",
|
---|
373 | URI_FILE_FORMAT_UNIX
|
---|
374 | },
|
---|
375 | {
|
---|
376 | "\\winserver\\isos\\files.lst",
|
---|
377 | "file:///winserver%5Cisos%5Cfiles.lst",
|
---|
378 | URI_FILE_FORMAT_WIN
|
---|
379 | },
|
---|
380 | {
|
---|
381 | "/myserver/isos/files.lst",
|
---|
382 | "file:///myserver/isos/files.lst",
|
---|
383 | URI_FILE_FORMAT_UNIX
|
---|
384 | },
|
---|
385 | {
|
---|
386 | "\\myserver\\isos\\files.lst",
|
---|
387 | "file:///myserver%5Cisos%5Cfiles.lst",
|
---|
388 | URI_FILE_FORMAT_WIN
|
---|
389 | }
|
---|
390 | };
|
---|
391 |
|
---|
392 | /**
|
---|
393 | * For reference, taken from output of PathCreateFromUrl/UrlCreateFromPath on Windows:
|
---|
394 | *
|
---|
395 | * #0: Path=C:\over\ <>#%"{}|^[]`\there, URL=file:///C:%5Cover%5C%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60%5Cthere
|
---|
396 | * PathCreateFromUrl: file:///C:%5Cover%5C%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60%5Cthere -> C:\over\ <>#%"{}|^[]`\there
|
---|
397 | * UrlCreateFromPath: C:\over\ <>#%"{}|^[]`\there -> file:%2F%2F%2FC:%2Fover%2F%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60%2Fthere
|
---|
398 | * #1: Path=/over/ <>#%"{}|^[]`/there, URL=file:///over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there
|
---|
399 | * PathCreateFromUrl: file:///over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there -> \over\ <>#%"{}|^[]`\there
|
---|
400 | * UrlCreateFromPath: /over/ <>#%"{}|^[]`/there -> file:%2F%2F%2Fover%2F%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60%2Fthere
|
---|
401 | * #2: Path=<NULL>, URL=file://
|
---|
402 | * PathCreateFromUrl: file:// ->
|
---|
403 | * UrlCreateFromPath: <NULL> ->
|
---|
404 | * #3: Path=<NULL>, URL=file://
|
---|
405 | * PathCreateFromUrl: file:// ->
|
---|
406 | * UrlCreateFromPath: <NULL> ->
|
---|
407 | * #4: Path=/, URL=file:///
|
---|
408 | * PathCreateFromUrl: file:/// ->
|
---|
409 | * UrlCreateFromPath: / -> file:%2F%2F%2F
|
---|
410 | * #5: Path=/foo/bar, URL=file:///foo/bar
|
---|
411 | * PathCreateFromUrl: file:///foo/bar -> \foo\bar
|
---|
412 | * UrlCreateFromPath: /foo/bar -> file:%2F%2F%2Ffoo%2Fbar
|
---|
413 | * #6: Path=\foo\bar, URL=file:///foo%5Cbar
|
---|
414 | * PathCreateFromUrl: file:///foo%5Cbar -> \foo\bar
|
---|
415 | * UrlCreateFromPath: \foo\bar -> file:%2F%2F%2Ffoo%2Fbar
|
---|
416 | * #7: Path=C:/over/ <>#%"{}|^[]`/there, URL=file:///C:/over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there
|
---|
417 | * PathCreateFromUrl: file:///C:/over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there -> C:\over\ <>#%"{}|^[]`\there
|
---|
418 | * UrlCreateFromPath: C:/over/ <>#%"{}|^[]`/there -> file:%2F%2F%2FC:%2Fover%2F%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60%2Fthere
|
---|
419 | * #8: Path=\over\ <>#%"{}|^[]`\there, URL=file:///over%5C%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60%5Cthere
|
---|
420 | * PathCreateFromUrl: file:///over%5C%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60%5Cthere -> \over\ <>#%"{}|^[]`\there
|
---|
421 | * UrlCreateFromPath: \over\ <>#%"{}|^[]`\there -> file:%2F%2F%2Fover%2F%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60%2Fthere
|
---|
422 | * #9: Path=/usr/bin/grep, URL=file:///usr/bin/grep
|
---|
423 | * PathCreateFromUrl: file:///usr/bin/grep -> \usr\bin\grep
|
---|
424 | * UrlCreateFromPath: /usr/bin/grep -> file:%2F%2F%2Fusr%2Fbin%2Fgrep
|
---|
425 | * #10: Path=\usr\bin\grep, URL=file:///usr%5Cbin%5Cgrep
|
---|
426 | * PathCreateFromUrl: file:///usr%5Cbin%5Cgrep -> \usr\bin\grep
|
---|
427 | * UrlCreateFromPath: \usr\bin\grep -> file:%2F%2F%2Fusr%2Fbin%2Fgrep
|
---|
428 | * #11: Path=/unixserver/isos/files.lst, URL=file:///unixserver/isos/files.lst
|
---|
429 | * PathCreateFromUrl: file:///unixserver/isos/files.lst -> \unixserver\isos\files.lst
|
---|
430 | * UrlCreateFromPath: /unixserver/isos/files.lst -> file:%2F%2F%2Funixserver%2Fisos%2Ffiles.lst
|
---|
431 | * #12: Path=\winserver\isos\files.lst, URL=file:///winserver%5Cisos%5Cfiles.lst
|
---|
432 | * PathCreateFromUrl: file:///winserver%5Cisos%5Cfiles.lst -> \winserver\isos\files.lst
|
---|
433 | * UrlCreateFromPath: \winserver\isos\files.lst -> file:%2F%2F%2Fwinserver%2Fisos%2Ffiles.lst
|
---|
434 | * #13: Path=/myserver/isos/files.lst, URL=file:///myserver/isos/files.lst
|
---|
435 | * PathCreateFromUrl: file:///myserver/isos/files.lst -> \myserver\isos\files.lst
|
---|
436 | * UrlCreateFromPath: /myserver/isos/files.lst -> file:%2F%2F%2Fmyserver%2Fisos%2Ffiles.lst
|
---|
437 | * #14: Path=\myserver\isos\files.lst, URL=file:///myserver%5Cisos%5Cfiles.lst
|
---|
438 | * PathCreateFromUrl: file:///myserver%5Cisos%5Cfiles.lst -> \myserver\isos\files.lst
|
---|
439 | * UrlCreateFromPath: \myserver\isos\files.lst -> file:%2F%2F%2Fmyserver%2Fisos%2Ffiles.lst
|
---|
440 | */
|
---|
441 |
|
---|
442 | static void tstCreate(size_t idxTest, const char *pszScheme, const char *pszAuthority, const char *pszPath, const char *pszQuery, const char *pszFragment, const char *pszTest)
|
---|
443 | {
|
---|
444 | char *pszResult = RTUriCreate(pszScheme, pszAuthority, pszPath, pszQuery, pszFragment);
|
---|
445 | if (pszTest)
|
---|
446 | {
|
---|
447 | RTTESTI_CHECK_MSG_RETV(pszResult, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
448 | RTTESTI_CHECK_MSG(RTStrCmp(pszResult, pszTest) == 0, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
449 | }
|
---|
450 | else
|
---|
451 | RTTESTI_CHECK_MSG(!pszResult, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
452 |
|
---|
453 | if (pszResult)
|
---|
454 | RTStrFree(pszResult);
|
---|
455 | return;
|
---|
456 | }
|
---|
457 |
|
---|
458 | static void tstFileCreate(size_t idxTest, const char *pszPath, const char *pszTest)
|
---|
459 | {
|
---|
460 | char *pszResult = RTUriFileCreate(pszPath);
|
---|
461 | if (pszTest)
|
---|
462 | {
|
---|
463 | RTTESTI_CHECK_MSG_RETV(pszResult, ("#%u: Result '%s' != '%s'\n", idxTest, pszResult, pszTest));
|
---|
464 | RTTESTI_CHECK_MSG(RTStrCmp(pszResult, pszTest) == 0, ("#%u: Result '%s' != '%s'\n", idxTest, pszResult, pszTest));
|
---|
465 | }
|
---|
466 | else
|
---|
467 | RTTESTI_CHECK_MSG(!pszResult, ("#%u: Result '%s' != '%s'\n", idxTest, pszResult, pszTest));
|
---|
468 |
|
---|
469 | if (pszResult)
|
---|
470 | RTStrFree(pszResult);
|
---|
471 | return;
|
---|
472 | }
|
---|
473 |
|
---|
474 | static void tstFilePath(size_t idxTest, const char *pszUri, const char *pszTest, uint32_t uFormat)
|
---|
475 | {
|
---|
476 | char *pszResult = RTUriFilePath(pszUri, uFormat);
|
---|
477 | if (pszTest)
|
---|
478 | {
|
---|
479 | RTTESTI_CHECK_MSG_RETV(pszResult, ("#%u: Result '%s' != '%s'\n", idxTest, pszResult, pszTest));
|
---|
480 | RTTESTI_CHECK_MSG(RTStrCmp(pszResult, pszTest) == 0, ("#%u: Result '%s' != '%s'\n", idxTest, pszResult, pszTest));
|
---|
481 | }
|
---|
482 | else
|
---|
483 | RTTESTI_CHECK_MSG(!pszResult, ("#%u: Result '%s' != '%s'\n", idxTest, pszResult, pszTest));
|
---|
484 |
|
---|
485 | if (pszResult)
|
---|
486 | RTStrFree(pszResult);
|
---|
487 | return;
|
---|
488 | }
|
---|
489 |
|
---|
490 | int main()
|
---|
491 | {
|
---|
492 | RTTEST hTest;
|
---|
493 | int rc = RTTestInitAndCreate("tstRTUri", &hTest);
|
---|
494 | if (rc)
|
---|
495 | return rc;
|
---|
496 | RTTestBanner(hTest);
|
---|
497 |
|
---|
498 | #define CHECK_STR_API(a_Call, a_pszExpected) \
|
---|
499 | do { \
|
---|
500 | char *pszTmp = a_Call; \
|
---|
501 | if (a_pszExpected) \
|
---|
502 | { \
|
---|
503 | if (!pszTmp) \
|
---|
504 | RTTestIFailed("#%u: %s returns NULL, expected '%s'", i, #a_Call, a_pszExpected); \
|
---|
505 | else if (strcmp(pszTmp, a_pszExpected)) \
|
---|
506 | RTTestIFailed("#%u: %s returns '%s', expected '%s'", i, #a_Call, pszTmp, a_pszExpected); \
|
---|
507 | } \
|
---|
508 | else if (pszTmp) \
|
---|
509 | RTTestIFailed("#%u: %s returns '%s', expected NULL", i, #a_Call, pszTmp); \
|
---|
510 | RTStrFree(pszTmp); \
|
---|
511 | } while (0)
|
---|
512 |
|
---|
513 | RTTestISub("RTUriParse & RTUriParsed*");
|
---|
514 | for (uint32_t i = 0; i < RT_ELEMENTS(g_aTests); i++)
|
---|
515 | {
|
---|
516 | RTURIPARSED Parsed;
|
---|
517 | RTTESTI_CHECK_RC(rc = RTUriParse(g_aTests[i].pszUri, &Parsed), VINF_SUCCESS);
|
---|
518 | if (RT_SUCCESS(rc))
|
---|
519 | {
|
---|
520 | CHECK_STR_API(RTUriParsedScheme(g_aTests[i].pszUri, &Parsed), g_aTests[i].pszScheme);
|
---|
521 | CHECK_STR_API(RTUriParsedAuthority(g_aTests[i].pszUri, &Parsed), g_aTests[i].pszAuthority);
|
---|
522 | CHECK_STR_API(RTUriParsedAuthorityUsername(g_aTests[i].pszUri, &Parsed), g_aTests[i].pszUsername);
|
---|
523 | CHECK_STR_API(RTUriParsedAuthorityPassword(g_aTests[i].pszUri, &Parsed), g_aTests[i].pszPassword);
|
---|
524 | CHECK_STR_API(RTUriParsedAuthorityHost(g_aTests[i].pszUri, &Parsed), g_aTests[i].pszHost);
|
---|
525 | CHECK_STR_API(RTUriParsedPath(g_aTests[i].pszUri, &Parsed), g_aTests[i].pszPath);
|
---|
526 | CHECK_STR_API(RTUriParsedQuery(g_aTests[i].pszUri, &Parsed), g_aTests[i].pszQuery);
|
---|
527 | CHECK_STR_API(RTUriParsedFragment(g_aTests[i].pszUri, &Parsed), g_aTests[i].pszFragment);
|
---|
528 | uint32_t uPort = RTUriParsedAuthorityPort(g_aTests[i].pszUri, &Parsed);
|
---|
529 | if (uPort != g_aTests[i].uPort)
|
---|
530 | RTTestIFailed("#%u: RTUriParsedAuthorityPort returns %#x, expected %#x", i, uPort, g_aTests[i].uPort);
|
---|
531 | }
|
---|
532 | }
|
---|
533 |
|
---|
534 | /* Creation */
|
---|
535 | RTTestISub("RTUriCreate");
|
---|
536 | for (uint32_t i = 0; i < RT_ELEMENTS(g_aTests); i++)
|
---|
537 | CHECK_STR_API(RTUriCreate(g_aTests[i].pszScheme, g_aTests[i].pszAuthority, g_aTests[i].pszPath,
|
---|
538 | g_aTests[i].pszQuery, g_aTests[i].pszFragment),
|
---|
539 | g_aTests[i].pszCreated ? g_aTests[i].pszCreated : g_aTests[i].pszUri);
|
---|
540 |
|
---|
541 | #ifdef _DEBUG
|
---|
542 | # ifdef RT_OS_WINDOWS
|
---|
543 | /* To generate the PathCreateFromUrl/UrlCreateFromPath reference on Windows. */
|
---|
544 | for (size_t i = 0; i < RT_ELEMENTS(g_apCreateFileURIs); ++i)
|
---|
545 | {
|
---|
546 | RTTestPrintf(hTest, RTTESTLVL_DEBUG, "#%u: Path=%s, URL=%s\n", i, g_apCreateFileURIs[i].pcszPath, g_apCreateFileURIs[i].pcszUri);
|
---|
547 | char szPath[255] = { 0 };
|
---|
548 | DWORD dw = 255;
|
---|
549 | PathCreateFromUrl(g_apCreateFileURIs[i].pcszUri, szPath, &dw, NULL);
|
---|
550 | RTTestPrintf(hTest, RTTESTLVL_DEBUG, "\tPathCreateFromUrl: %s -> %s\n", g_apCreateFileURIs[i].pcszUri, szPath);
|
---|
551 | char szURL[255] = { 0 };
|
---|
552 | dw = 255;
|
---|
553 | UrlCreateFromPath(g_apCreateFileURIs[i].pcszPath, szURL, &dw, NULL);
|
---|
554 | char szURLEsc[255] = { 0 };
|
---|
555 | dw = 255;
|
---|
556 | UrlEscape(szURL, szURLEsc, &dw, URL_ESCAPE_SEGMENT_ONLY);
|
---|
557 | RTTestPrintf(hTest, RTTESTLVL_DEBUG, "\tUrlCreateFromPath: %s -> %s\n", g_apCreateFileURIs[i].pcszPath, szURLEsc);
|
---|
558 | }
|
---|
559 | # endif
|
---|
560 | #endif
|
---|
561 |
|
---|
562 | /* File Uri path */
|
---|
563 | RTTestISub("RTUriFilePath");
|
---|
564 | for (size_t i = 0; i < RT_ELEMENTS(g_apCreateFileURIs); ++i)
|
---|
565 | tstFilePath(i, g_apCreateFileURIs[i].pcszUri, g_apCreateFileURIs[i].pcszPath, g_apCreateFileURIs[i].uFormat);
|
---|
566 |
|
---|
567 | /* File Uri creation */
|
---|
568 | RTTestISub("RTUriFileCreate");
|
---|
569 | for (size_t i = 0; i < RT_ELEMENTS(g_apCreateFileURIs); ++i)
|
---|
570 | tstFileCreate(i, g_apCreateFileURIs[i].pcszPath, g_apCreateFileURIs[i].pcszUri);
|
---|
571 |
|
---|
572 | return RTTestSummaryAndDestroy(hTest);
|
---|
573 | }
|
---|
574 |
|
---|