VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTUri.cpp@ 58062

Last change on this file since 58062 was 58062, checked in by vboxsync, 10 years ago

tstRTUri: Actually, there are no UNC tests here. Paths where misleading.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 28.5 KB
Line 
1/* $Id: tstRTUri.cpp 58062 2015-10-06 17:53:47Z 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#if 0 && defined(RT_OS_WINDOWS) /* Enable for windows API reference results. */
39# define TSTRTURI_WITH_WINDOWS_REFERENCE_RESULTS
40# include <Shlwapi.h>
41# include <iprt/stream.h>
42#endif
43
44
45/*********************************************************************************************************************************
46* Test data *
47*********************************************************************************************************************************/
48
49static struct
50{
51 const char *pszUri;
52 const char *pszScheme;
53 const char *pszAuthority;
54 const char *pszPath;
55 const char *pszQuery;
56 const char *pszFragment;
57
58 const char *pszUsername;
59 const char *pszPassword;
60 const char *pszHost;
61 uint32_t uPort;
62
63 const char *pszCreated;
64} g_aTests[] =
65{
66 { /* #0 */
67 "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",
68 /*.pszScheme =*/ "foo",
69 /*.pszAuthority =*/ "tt:[email protected]:8042",
70 /*.pszPath =*/ "/over/ <>#%\"{}|^[]`/there",
71 /*.pszQuery =*/ "name= <>#%\"{}|^[]`ferret",
72 /*.pszFragment =*/ "nose <>#%\"{}|^[]`",
73 /*.pszUsername =*/ "tt",
74 /*.pszPassword =*/ "yt",
75 /*.pszHost =*/ "example.com",
76 /*.uPort =*/ 8042,
77 /*.pszCreated =*/ NULL /* same as pszUri*/,
78 },
79 { /* #1 */
80 "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",
81 /*.pszScheme =*/ "foo",
82 /*.pszAuthority =*/ "tt:[email protected]:8042",
83 /*.pszPath =*/ "/over/ <>#%\"{}|^[]`/there",
84 /*.pszQuery =*/ "name= <>#%\"{}|^[]`ferret",
85 /*.pszFragment =*/ NULL,
86 /*.pszUsername =*/ "tt",
87 /*.pszPassword =*/ "yt",
88 /*.pszHost =*/ "example.com",
89 /*.uPort =*/ 8042,
90 /*.pszCreated =*/ NULL /* same as pszUri*/,
91 },
92 { /* #2 */
93 "foo://tt:[email protected]:8042/over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there",
94 /*.pszScheme =*/ "foo",
95 /*.pszAuthority =*/ "tt:[email protected]:8042",
96 /*.pszPath =*/ "/over/ <>#%\"{}|^[]`/there",
97 /*.pszQuery =*/ NULL,
98 /*.pszFragment =*/ NULL,
99 /*.pszUsername =*/ "tt",
100 /*.pszPassword =*/ "yt",
101 /*.pszHost =*/ "example.com",
102 /*.uPort =*/ 8042,
103 /*.pszCreated =*/ NULL /* same as pszUri*/,
104 },
105 { /* #3 */
106 "foo:[email protected]",
107 /*.pszScheme =*/ "foo",
108 /*.pszAuthority =*/ NULL,
109 /*.pszPath =*/ "[email protected]",
110 /*.pszQuery =*/ NULL,
111 /*.pszFragment =*/ NULL,
112 /*.pszUsername =*/ NULL,
113 /*.pszPassword =*/ NULL,
114 /*.pszHost =*/ NULL,
115 /*.uPort =*/ UINT32_MAX,
116 /*.pszCreated =*/ NULL /* same as pszUri*/,
117 },
118 { /* #4 */
119 "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",
120 /*.pszScheme =*/ "foo",
121 /*.pszAuthority =*/ NULL,
122 /*.pszPath =*/ "/over/ <>#%\"{}|^[]`/there",
123 /*.pszQuery =*/ "name= <>#%\"{}|^[]`ferret",
124 /*.pszFragment =*/ "nose <>#%\"{}|^[]`",
125 /*.pszUsername =*/ NULL,
126 /*.pszPassword =*/ NULL,
127 /*.pszHost =*/ NULL,
128 /*.uPort =*/ UINT32_MAX,
129 /*.pszCreated =*/ NULL /* same as pszUri*/,
130 },
131 { /* #5 */
132 "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",
133 /*.pszScheme =*/ "foo",
134 /*.pszAuthority =*/ NULL,
135 /*.pszPath =*/ "/over/ <>#%\"{}|^[]`/there",
136 /*.pszQuery =*/ NULL,
137 /*.pszFragment =*/ "nose <>#%\"{}|^[]`",
138 /*.pszUsername =*/ NULL,
139 /*.pszPassword =*/ NULL,
140 /*.pszHost =*/ NULL,
141 /*.uPort =*/ UINT32_MAX,
142 /*.pszCreated =*/ NULL /* same as pszUri*/,
143 },
144 { /* #6 */
145 "urn:example:animal:ferret:nose",
146 /*.pszScheme =*/ "urn",
147 /*.pszAuthority =*/ NULL,
148 /*.pszPath =*/ "example:animal:ferret:nose",
149 /*.pszQuery =*/ NULL,
150 /*.pszFragment =*/ NULL,
151 /*.pszUsername =*/ NULL,
152 /*.pszPassword =*/ NULL,
153 /*.pszHost =*/ NULL,
154 /*.uPort =*/ UINT32_MAX,
155 /*.pszCreated =*/ NULL /* same as pszUri*/,
156 },
157 { /* #7 */
158 "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",
159 /*.pszScheme =*/ "foo",
160 /*.pszAuthority =*/ NULL,
161 /*.pszPath =*/ NULL,
162 /*.pszQuery =*/ "name= <>#%\"{}|^[]`ferret",
163 /*.pszFragment =*/ "nose <>#%\"{}|^[]`",
164 /*.pszUsername =*/ NULL,
165 /*.pszPassword =*/ NULL,
166 /*.pszHost =*/ NULL,
167 /*.uPort =*/ UINT32_MAX,
168 /*.pszCreated =*/ NULL /* same as pszUri*/,
169 },
170 { /* #8 */
171 "foo:#nose%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60",
172 /*.pszScheme =*/ "foo",
173 /*.pszAuthority =*/ NULL,
174 /*.pszPath =*/ NULL,
175 /*.pszQuery =*/ NULL,
176 /*.pszFragment =*/ "nose <>#%\"{}|^[]`",
177 /*.pszUsername =*/ NULL,
178 /*.pszPassword =*/ NULL,
179 /*.pszHost =*/ NULL,
180 /*.uPort =*/ UINT32_MAX,
181 /*.pszCreated =*/ NULL /* same as pszUri*/,
182 },
183 { /* #9 */
184 "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",
185 /*.pszScheme =*/ "foo",
186 /*.pszAuthority =*/ "tt:[email protected]:8042",
187 /*.pszPath =*/ "/",
188 /*.pszQuery =*/ "name= <>#%\"{}|^[]`ferret",
189 /*.pszFragment =*/ "nose <>#%\"{}|^[]`",
190 /*.pszUsername =*/ "tt",
191 /*.pszPassword =*/ "yt",
192 /*.pszHost =*/ "example.com",
193 /*.uPort =*/ 8042,
194 /*.pszCreated =*/ NULL /* same as pszUri*/,
195 },
196 { /* #10 */
197 "foo://tt:[email protected]:8042/",
198 /*.pszScheme =*/ "foo",
199 /*.pszAuthority =*/ "tt:[email protected]:8042",
200 /*.pszPath =*/ "/",
201 /*.pszQuery =*/ NULL,
202 /*.pszFragment =*/ NULL,
203 /*.pszUsername =*/ "tt",
204 /*.pszPassword =*/ "yt",
205 /*.pszHost =*/ "example.com",
206 /*.uPort =*/ 8042,
207 /*.pszCreated =*/ NULL /* same as pszUri*/,
208 },
209 { /* #11 */
210 "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",
211 /*.pszScheme =*/ "foo",
212 /*.pszAuthority =*/ "tt:[email protected]:8042",
213 /*.pszPath =*/ NULL,
214 /*.pszQuery =*/ "name= <>#%\"{}|^[]`ferret",
215 /*.pszFragment =*/ "nose <>#%\"{}|^[]`",
216 /*.pszUsername =*/ "tt",
217 /*.pszPassword =*/ "yt",
218 /*.pszHost =*/ "example.com",
219 /*.uPort =*/ 8042,
220 /*.pszCreated =*/ NULL /* same as pszUri*/,
221 },
222 { /* #12 */
223 "foo://tt:[email protected]:8042#nose%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60",
224 /*.pszScheme =*/ "foo",
225 /*.pszAuthority =*/ "tt:[email protected]:8042",
226 /*.pszPath =*/ NULL,
227 /*.pszQuery =*/ NULL,
228 /*.pszFragment =*/ "nose <>#%\"{}|^[]`",
229 /*.pszUsername =*/ "tt",
230 /*.pszPassword =*/ "yt",
231 /*.pszHost =*/ "example.com",
232 /*.uPort =*/ 8042,
233 /*.pszCreated =*/ NULL /* same as pszUri*/,
234 },
235 { /* #13 */
236 "foo://tt:[email protected]:8042",
237 /*.pszScheme =*/ "foo",
238 /*.pszAuthority =*/ "tt:[email protected]:8042",
239 /*.pszPath =*/ NULL,
240 /*.pszQuery =*/ NULL,
241 /*.pszFragment =*/ NULL,
242 /*.pszUsername =*/ "tt",
243 /*.pszPassword =*/ "yt",
244 /*.pszHost =*/ "example.com",
245 /*.uPort =*/ 8042,
246 /*.pszCreated =*/ NULL /* same as pszUri*/,
247 },
248 { /* #14 */
249 "file:///dir/dir/file",
250 /*.pszScheme =*/ "file",
251 /*.pszAuthority =*/ "",
252 /*.pszPath =*/ "/dir/dir/file",
253 /*.pszQuery =*/ NULL,
254 /*.pszFragment =*/ NULL,
255 /*.pszUsername =*/ NULL,
256 /*.pszPassword =*/ NULL,
257 /*.pszHost =*/ NULL,
258 /*.uPort =*/ UINT32_MAX,
259 /*.pszCreated =*/ NULL /* same as pszUri*/,
260 },
261 { /* #15 */
262 "foo:///",
263 /*.pszScheme =*/ "foo",
264 /*.pszAuthority =*/ "",
265 /*.pszPath =*/ "/",
266 /*.pszQuery =*/ NULL,
267 /*.pszFragment =*/ NULL,
268 /*.pszUsername =*/ NULL,
269 /*.pszPassword =*/ NULL,
270 /*.pszHost =*/ NULL,
271 /*.uPort =*/ UINT32_MAX,
272 /*.pszCreated =*/ NULL /* same as pszUri*/,
273 },
274 { /* #16 */
275 "foo://",
276 /*.pszScheme =*/ "foo",
277 /*.pszAuthority =*/ "",
278 /*.pszPath =*/ NULL,
279 /*.pszQuery =*/ NULL,
280 /*.pszFragment =*/ NULL,
281 /*.pszUsername =*/ NULL,
282 /*.pszPassword =*/ NULL,
283 /*.pszHost =*/ NULL,
284 /*.uPort =*/ UINT32_MAX,
285 /*.pszCreated =*/ NULL /* same as pszUri*/,
286 },
287 { /* #17 - UTF-8 escape sequences. */
288 "http://example.com/%ce%b3%ce%bb%cf%83%ce%b1%20%e0%a4%95\xe0\xa4\x95",
289 /*.pszScheme =*/ "http",
290 /*.pszAuthority =*/ "example.com",
291 /*.pszPath =*/ "/\xce\xb3\xce\xbb\xcf\x83\xce\xb1 \xe0\xa4\x95\xe0\xa4\x95",
292 /*.pszQuery =*/ NULL,
293 /*.pszFragment =*/ NULL,
294 /*.pszUsername =*/ NULL,
295 /*.pszPassword =*/ NULL,
296 /*.pszHost =*/ "example.com",
297 /*.uPort =*/ UINT32_MAX,
298 /*.pszCreated =*/ "http://example.com/\xce\xb3\xce\xbb\xcf\x83\xce\xb1%20\xe0\xa4\x95\xe0\xa4\x95",
299 },
300};
301
302
303static struct URIFILETEST
304{
305 const char *pszPath;
306 const char *pszUri;
307 uint32_t uFormat;
308 const char *pszCreatedPath;
309 const char *pszCreatedUri;
310} g_aCreateFileURIs[] =
311{
312 { /* #0: */
313 /* .pszPath =*/ "C:\\over\\ <>#%\"{}|^[]`\\there",
314 /* .pszUri =*/ "file:///C:%5Cover%5C%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60%5Cthere",
315 /* .uFormat =*/ URI_FILE_FORMAT_WIN,
316 /* .pszCreatedPath =*/ NULL, /* Same as pszPath. */
317 /* .pszCreatedUri =*/ NULL, /* Same as pszUri. */
318 /* PathCreateFromUrl = "C:\\over\\ <>#%\"{}|^[]`\\there" - same */
319 /* UrlCreateFromPath = "file:///C:/over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there" - differs */
320 },
321 { /* #1: */
322 /* .pszPath =*/ "/over/ <>#%\"{}|^[]`/there",
323 /* .pszUri =*/ "file:///over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there",
324 /* .uFormat =*/ URI_FILE_FORMAT_UNIX,
325 /* .pszCreatedPath =*/ NULL, /* Same as pszPath. */
326 /* .pszCreatedUri =*/ NULL, /* Same as pszUri. */
327 /* PathCreateFromUrl = "\\over\\ <>#%\"{}|^[]`\\there" - differs */
328 /* UrlCreateFromPath = "file:///over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there" - same */
329 },
330 { /* #2: */
331 /* .pszPath =*/ NULL,
332 /* .pszUri =*/ "file://",
333 /* .uFormat =*/ URI_FILE_FORMAT_UNIX,
334 /* .pszCreatedPath =*/ NULL, /* Same as pszPath. */
335 /* .pszCreatedUri =*/ NULL, /* Same as pszUri. */
336 /* PathCreateFromUrl = "" - differs */
337 /* UrlCreateFromPath => 0x80070057 (E_INVALIDARG) */
338 },
339 { /* #3: */
340 /* .pszPath =*/ NULL,
341 /* .pszUri =*/ "file://",
342 /* .uFormat =*/ URI_FILE_FORMAT_WIN,
343 /* .pszCreatedPath =*/ NULL, /* Same as pszPath. */
344 /* .pszCreatedUri =*/ NULL, /* Same as pszUri. */
345 /* PathCreateFromUrl = "" - differs */
346 /* UrlCreateFromPath => 0x80070057 (E_INVALIDARG) */
347 },
348 { /* #4: */
349 /* .pszPath =*/ "/",
350 /* .pszUri =*/ "file:///",
351 /* .uFormat =*/ URI_FILE_FORMAT_UNIX,
352 /* .pszCreatedPath =*/ NULL, /* Same as pszPath. */
353 /* .pszCreatedUri =*/ NULL, /* Same as pszUri. */
354 /* PathCreateFromUrl = "" - differs */
355 /* UrlCreateFromPath = "file:///" - same */
356 },
357 { /* #5: */
358 /* .pszPath =*/ "\\",
359 /* .pszUri =*/ "file:///",
360 /* .uFormat =*/ URI_FILE_FORMAT_WIN,
361 /* .pszCreatedPath =*/ NULL, /* Same as pszPath. */
362 /* .pszCreatedUri =*/ NULL, /* Same as pszUri. */
363 /* PathCreateFromUrl = "" - differs */
364 /* UrlCreateFromPath = "file:///" - same */
365 },
366 { /* #6: */
367 /* .pszPath =*/ "/foo/bar",
368 /* .pszUri =*/ "file:///foo/bar",
369 /* .uFormat =*/ URI_FILE_FORMAT_UNIX,
370 /* .pszCreatedPath =*/ NULL, /* Same as pszPath. */
371 /* .pszCreatedUri =*/ NULL, /* Same as pszUri. */
372 /* PathCreateFromUrl = "\\foo\\bar" - differs */
373 /* UrlCreateFromPath = "file:///foo/bar" - same */
374 },
375 { /* #7: */
376 /* .pszPath =*/ "\\foo\\bar",
377 /* .pszUri =*/ "file:///foo%5Cbar",
378 /* .uFormat =*/ URI_FILE_FORMAT_WIN,
379 /* .pszCreatedPath =*/ NULL, /* Same as pszPath. */
380 /* .pszCreatedUri =*/ NULL, /* Same as pszUri. */
381 /* PathCreateFromUrl = "\\foo\\bar" - same */
382 /* UrlCreateFromPath = "file:///foo/bar" - differs */
383 },
384 { /* #8: */
385 /* .pszPath =*/ "C:/over/ <>#%\"{}|^[]`/there",
386 /* .pszUri =*/ "file:///C:/over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there",
387 /* .uFormat =*/ URI_FILE_FORMAT_UNIX,
388 /* .pszCreatedPath =*/ NULL, /* Same as pszPath. */
389 /* .pszCreatedUri =*/ NULL, /* Same as pszUri. */
390 /* PathCreateFromUrl = "C:\\over\\ <>#%\"{}|^[]`\\there" - differs */
391 /* UrlCreateFromPath = "file:///C:/over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there" - same */
392 },
393 { /* #9: */
394 /* .pszPath =*/ "\\over\\ <>#%\"{}|^[]`\\there",
395 /* .pszUri =*/ "file:///over%5C%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60%5Cthere",
396 /* .uFormat =*/ URI_FILE_FORMAT_WIN,
397 /* .pszCreatedPath =*/ NULL, /* Same as pszPath. */
398 /* .pszCreatedUri =*/ NULL, /* Same as pszUri. */
399 /* PathCreateFromUrl = "\\over\\ <>#%\"{}|^[]`\\there" - same */
400 /* UrlCreateFromPath = "file:///over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there" - differs */
401 },
402 { /* #10: */
403 /* .pszPath =*/ "/usr/bin/grep",
404 /* .pszUri =*/ "file:///usr/bin/grep",
405 /* .uFormat =*/ URI_FILE_FORMAT_UNIX,
406 /* .pszCreatedPath =*/ NULL, /* Same as pszPath. */
407 /* .pszCreatedUri =*/ NULL, /* Same as pszUri. */
408 /* PathCreateFromUrl = "\\usr\\bin\\grep" - differs */
409 /* UrlCreateFromPath = "file:///usr/bin/grep" - same */
410 },
411 { /* #11: */
412 /* .pszPath =*/ "\\usr\\bin\\grep",
413 /* .pszUri =*/ "file:///usr%5Cbin%5Cgrep",
414 /* .uFormat =*/ URI_FILE_FORMAT_WIN,
415 /* .pszCreatedPath =*/ NULL, /* Same as pszPath. */
416 /* .pszCreatedUri =*/ NULL, /* Same as pszUri. */
417 /* PathCreateFromUrl = "\\usr\\bin\\grep" - same */
418 /* UrlCreateFromPath = "file:///usr/bin/grep" - differs */
419 },
420 { /* #12: */
421 /* .pszPath =*/ "/somerootsubdir/isos/files.lst",
422 /* .pszUri =*/ "file:///somerootsubdir/isos/files.lst",
423 /* .uFormat =*/ URI_FILE_FORMAT_UNIX,
424 /* .pszCreatedPath =*/ NULL, /* Same as pszPath. */
425 /* .pszCreatedUri =*/ NULL, /* Same as pszUri. */
426 /* PathCreateFromUrl = "\\somerootsubdir\\isos\\files.lst" - differs */
427 /* UrlCreateFromPath = "file:///somerootsubdir/isos/files.lst" - same */
428 },
429 { /* #13: */
430 /* .pszPath =*/ "\\not-a-cifsserver\\isos\\files.lst",
431 /* .pszUri =*/ "file:///not-a-cifsserver%5Cisos%5Cfiles.lst",
432 /* .uFormat =*/ URI_FILE_FORMAT_WIN,
433 /* .pszCreatedPath =*/ NULL, /* Same as pszPath. */
434 /* .pszCreatedUri =*/ NULL, /* Same as pszUri. */
435 /* PathCreateFromUrl = "\\not-a-cifsserver\\isos\\files.lst" - same */
436 /* UrlCreateFromPath = "file:///not-a-cifsserver/isos/files.lst" - differs */
437 },
438 { /* #14: */
439 /* .pszPath =*/ "/rootsubdir/isos/files.lst",
440 /* .pszUri =*/ "file:///rootsubdir/isos/files.lst",
441 /* .uFormat =*/ URI_FILE_FORMAT_UNIX,
442 /* .pszCreatedPath =*/ NULL, /* Same as pszPath. */
443 /* .pszCreatedUri =*/ NULL, /* Same as pszUri. */
444 /* PathCreateFromUrl = "\\rootsubdir\\isos\\files.lst" - differs */
445 /* UrlCreateFromPath = "file:///rootsubdir/isos/files.lst" - same */
446 },
447 { /* #15: */
448 /* .pszPath =*/ "\\not-a-cifsserver-either\\isos\\files.lst",
449 /* .pszUri =*/ "file:///not-a-cifsserver-either%5Cisos%5Cfiles.lst",
450 /* .uFormat =*/ URI_FILE_FORMAT_WIN,
451 /* .pszCreatedPath =*/ NULL, /* Same as pszPath. */
452 /* .pszCreatedUri =*/ NULL, /* Same as pszUri. */
453 /* PathCreateFromUrl = "\\not-a-cifsserver-either\\isos\\files.lst" - same */
454 /* UrlCreateFromPath = "file:///not-a-cifsserver-either/isos/files.lst" - differs */
455 },
456#if 0 /** @todo r=bird: this ain't working right. It's in the wikipedia article on file:// ... */
457 { /* #16: */
458 /* .pszPath =*/ "c:boot.ini",
459 /* .pszUri =*/ "file://localhost/c:boot.ini",
460 /* .uFormat =*/ URI_FILE_FORMAT_WIN,
461 /* .pszCreatedPath =*/ NULL, /* Same as pszPath. */
462 /* .pszCreatedUri =*/ "file:///c:boot.ini",
463 /* PathCreateFromUrl = "c:boot.ini" - same */
464 /* UrlCreateFromPath = "file:///c:boot.ini" - same */
465 },
466 { /* #17: */
467 /* .pszPath =*/ "c:boot.ini",
468 /* .pszUri =*/ "file:///c|boot.ini",
469 /* .uFormat =*/ URI_FILE_FORMAT_WIN,
470 /* .pszCreatedPath =*/ NULL, /* Same as pszPath. */
471 /* .pszCreatedUri =*/ "file:///c:boot.ini",
472 /* PathCreateFromUrl = "c:boot.ini" - same */
473 /* UrlCreateFromPath = "file:///c:boot.ini" - same */
474 },
475#endif
476};
477
478#ifdef TSTRTURI_WITH_WINDOWS_REFERENCE_RESULTS
479
480static void tstPrintCString(const char *pszString)
481{
482 if (pszString)
483 {
484 char ch;
485 RTPrintf("\"");
486 while ((ch = *pszString++) != '\0')
487 {
488 if (ch >= 0x20 && ch < 0x7f)
489 switch (ch)
490 {
491 default:
492 RTPrintf("%c", ch);
493 break;
494 case '\\':
495 case '"':
496 RTPrintf("\\%c", ch);
497 break;
498 }
499 else
500 RTPrintf("\\x%02X", ch); /* good enough */
501 }
502 RTPrintf("\"");
503 }
504 else
505 RTPrintf("NULL");
506}
507
508static void tstWindowsReferenceResults(void)
509{
510 /*
511 * Feed the g_aCreateFileURIs values as input to the Windows
512 * PathCreateFromUrl and URlCreateFromPath APIs and print the results.
513 *
514 * We reproduce the entire source file content of g_aCreateFileURIs here.
515 */
516 for (size_t i = 0; i < RT_ELEMENTS(g_aCreateFileURIs); ++i)
517 {
518 RTPrintf(" { /* #%u: */\n", i);
519 RTPrintf(" /* .pszPath =*/ ");
520 tstPrintCString(g_aCreateFileURIs[i].pszPath);
521 RTPrintf(",\n");
522 RTPrintf(" /* .pszUri =*/ ");
523 tstPrintCString(g_aCreateFileURIs[i].pszUri);
524 RTPrintf(",\n");
525 RTPrintf(" /* .uFormat =*/ %s,\n",
526 g_aCreateFileURIs[i].uFormat == URI_FILE_FORMAT_WIN ? "URI_FILE_FORMAT_WIN"
527 : g_aCreateFileURIs[i].uFormat == URI_FILE_FORMAT_UNIX ? "URI_FILE_FORMAT_UNIX"
528 : g_aCreateFileURIs[i].uFormat == URI_FILE_FORMAT_AUTO ? "URI_FILE_FORMAT_AUTO" : "URI_FILE_FORMAT_INVALID");
529 RTPrintf(" /* .pszCreatedPath =*/ ");
530 if (g_aCreateFileURIs[i].pszCreatedPath == NULL)
531 RTPrintf("NULL, /* Same as pszPath. */\n");
532 else
533 {
534 tstPrintCString(g_aCreateFileURIs[i].pszCreatedPath);
535 RTPrintf(",\n");
536 }
537 RTPrintf(" /* .pszCreatedUri =*/ ");
538 if (g_aCreateFileURIs[i].pszCreatedUri == NULL)
539 RTPrintf("NULL, /* Same as pszUri. */\n");
540 else
541 {
542 tstPrintCString(g_aCreateFileURIs[i].pszCreatedUri);
543 RTPrintf(",\n");
544 }
545
546 /*
547 * PathCreateFromUrl
548 */
549 PRTUTF16 pwszInput = NULL;
550 if (g_aCreateFileURIs[i].pszUri)
551 RTTESTI_CHECK_RC_OK_RETV(RTStrToUtf16(g_aCreateFileURIs[i].pszUri, &pwszInput));
552 WCHAR wszResult[_1K];
553 DWORD cwcResult = RT_ELEMENTS(wszResult);
554 RT_ZERO(wszResult);
555 HRESULT hrc = PathCreateFromUrlW(pwszInput, wszResult, &cwcResult, 0 /*dwFlags*/);
556 RTUtf16Free(pwszInput);
557
558 if (SUCCEEDED(hrc))
559 {
560 char *pszResult;
561 RTTESTI_CHECK_RC_OK_RETV(RTUtf16ToUtf8(wszResult, &pszResult));
562 RTPrintf(" /* PathCreateFromUrl = ");
563 tstPrintCString(pszResult);
564 if ( g_aCreateFileURIs[i].pszPath
565 && strcmp(pszResult, g_aCreateFileURIs[i].pszCreatedPath
566 ? g_aCreateFileURIs[i].pszCreatedPath : g_aCreateFileURIs[i].pszPath) == 0)
567 RTPrintf(" - same */\n");
568 else
569 RTPrintf(" - differs */\n");
570 RTStrFree(pszResult);
571 }
572 else
573 RTPrintf(" /* PathCreateFromUrl => %#x (%Rhrc) */\n", hrc, hrc);
574
575 /*
576 * UrlCreateFromPath + UrlEscape
577 */
578 pwszInput = NULL;
579 if (g_aCreateFileURIs[i].pszPath)
580 RTTESTI_CHECK_RC_OK_RETV(RTStrToUtf16(g_aCreateFileURIs[i].pszPath, &pwszInput));
581 RT_ZERO(wszResult);
582 cwcResult = RT_ELEMENTS(wszResult);
583 hrc = UrlCreateFromPathW(pwszInput, wszResult, &cwcResult, 0 /*dwFlags*/);
584 RTUtf16Free(pwszInput);
585
586 if (SUCCEEDED(hrc))
587 {
588 WCHAR wszResult2[_1K];
589 DWORD cwcResult2 = RT_ELEMENTS(wszResult2);
590 hrc = UrlEscapeW(wszResult, wszResult2, &cwcResult2, URL_DONT_ESCAPE_EXTRA_INFO );
591 if (SUCCEEDED(hrc))
592 {
593 char *pszResult;
594 RTTESTI_CHECK_RC_OK_RETV(RTUtf16ToUtf8(wszResult2, &pszResult));
595 RTPrintf(" /* UrlCreateFromPath = ");
596 tstPrintCString(pszResult);
597 if ( g_aCreateFileURIs[i].pszUri
598 && strcmp(pszResult, g_aCreateFileURIs[i].pszCreatedUri
599 ? g_aCreateFileURIs[i].pszCreatedUri : g_aCreateFileURIs[i].pszUri) == 0)
600 RTPrintf(" - same */\n");
601 else
602 RTPrintf(" - differs */\n");
603 RTStrFree(pszResult);
604 }
605 else
606 RTPrintf(" /* UrlEscapeW => %#x (%Rhrc) */\n", hrc, hrc);
607 }
608 else
609 RTPrintf(" /* UrlCreateFromPath => %#x (%Rhrc) */\n", hrc, hrc);
610 RTPrintf(" },\n");
611 }
612}
613
614#endif /* TSTRTURI_WITH_WINDOWS_REFERENCE_RESULTS */
615
616
617int main()
618{
619 RTTEST hTest;
620 int rc = RTTestInitAndCreate("tstRTUri", &hTest);
621 if (rc)
622 return rc;
623 RTTestBanner(hTest);
624
625#define CHECK_STR_API(a_Call, a_pszExpected) \
626 do { \
627 char *pszTmp = a_Call; \
628 if (a_pszExpected) \
629 { \
630 if (!pszTmp) \
631 RTTestIFailed("#%u: %s returns NULL, expected '%s'", i, #a_Call, a_pszExpected); \
632 else if (strcmp(pszTmp, a_pszExpected)) \
633 RTTestIFailed("#%u: %s returns '%s', expected '%s'", i, #a_Call, pszTmp, a_pszExpected); \
634 } \
635 else if (pszTmp) \
636 RTTestIFailed("#%u: %s returns '%s', expected NULL", i, #a_Call, pszTmp); \
637 RTStrFree(pszTmp); \
638 } while (0)
639
640 RTTestISub("RTUriParse & RTUriParsed*");
641 for (uint32_t i = 0; i < RT_ELEMENTS(g_aTests); i++)
642 {
643 RTURIPARSED Parsed;
644 RTTESTI_CHECK_RC(rc = RTUriParse(g_aTests[i].pszUri, &Parsed), VINF_SUCCESS);
645 if (RT_SUCCESS(rc))
646 {
647 CHECK_STR_API(RTUriParsedScheme(g_aTests[i].pszUri, &Parsed), g_aTests[i].pszScheme);
648 CHECK_STR_API(RTUriParsedAuthority(g_aTests[i].pszUri, &Parsed), g_aTests[i].pszAuthority);
649 CHECK_STR_API(RTUriParsedAuthorityUsername(g_aTests[i].pszUri, &Parsed), g_aTests[i].pszUsername);
650 CHECK_STR_API(RTUriParsedAuthorityPassword(g_aTests[i].pszUri, &Parsed), g_aTests[i].pszPassword);
651 CHECK_STR_API(RTUriParsedAuthorityHost(g_aTests[i].pszUri, &Parsed), g_aTests[i].pszHost);
652 CHECK_STR_API(RTUriParsedPath(g_aTests[i].pszUri, &Parsed), g_aTests[i].pszPath);
653 CHECK_STR_API(RTUriParsedQuery(g_aTests[i].pszUri, &Parsed), g_aTests[i].pszQuery);
654 CHECK_STR_API(RTUriParsedFragment(g_aTests[i].pszUri, &Parsed), g_aTests[i].pszFragment);
655 uint32_t uPort = RTUriParsedAuthorityPort(g_aTests[i].pszUri, &Parsed);
656 if (uPort != g_aTests[i].uPort)
657 RTTestIFailed("#%u: RTUriParsedAuthorityPort returns %#x, expected %#x", i, uPort, g_aTests[i].uPort);
658 }
659 }
660
661 /* Creation */
662 RTTestISub("RTUriCreate");
663 for (uint32_t i = 0; i < RT_ELEMENTS(g_aTests); i++)
664 CHECK_STR_API(RTUriCreate(g_aTests[i].pszScheme, g_aTests[i].pszAuthority, g_aTests[i].pszPath,
665 g_aTests[i].pszQuery, g_aTests[i].pszFragment),
666 g_aTests[i].pszCreated ? g_aTests[i].pszCreated : g_aTests[i].pszUri);
667
668#ifdef TSTRTURI_WITH_WINDOWS_REFERENCE_RESULTS
669 tstWindowsReferenceResults();
670#endif
671
672 /* File Uri path */
673 RTTestISub("RTUriFilePath");
674 for (size_t i = 0; i < RT_ELEMENTS(g_aCreateFileURIs); ++i)
675 CHECK_STR_API(RTUriFilePath(g_aCreateFileURIs[i].pszUri, g_aCreateFileURIs[i].uFormat),
676 g_aCreateFileURIs[i].pszCreatedPath ? g_aCreateFileURIs[i].pszCreatedPath : g_aCreateFileURIs[i].pszPath);
677
678 /* File Uri creation */
679 RTTestISub("RTUriFileCreate");
680 for (size_t i = 0; i < RT_ELEMENTS(g_aCreateFileURIs); ++i)
681 CHECK_STR_API(RTUriFileCreate(g_aCreateFileURIs[i].pszPath),
682 g_aCreateFileURIs[i].pszCreatedUri ? g_aCreateFileURIs[i].pszCreatedUri : g_aCreateFileURIs[i].pszUri);
683
684 return RTTestSummaryAndDestroy(hTest);
685}
686
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette