1 | /* $Id: tstRTUri.cpp 57720 2015-09-11 14:49:21Z 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.215389.xyz. 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 |
|
---|
39 | /*********************************************************************************************************************************
|
---|
40 | * Test data *
|
---|
41 | *********************************************************************************************************************************/
|
---|
42 |
|
---|
43 | static struct
|
---|
44 | {
|
---|
45 | const char *pszUri;
|
---|
46 | const char *pszScheme;
|
---|
47 | const char *pszAuthority;
|
---|
48 | const char *pszPath;
|
---|
49 | const char *pszQuery;
|
---|
50 | const char *pszFragment;
|
---|
51 |
|
---|
52 | const char *pszUsername;
|
---|
53 | const char *pszPassword;
|
---|
54 | uint32_t uPort;
|
---|
55 | } g_aTests[] =
|
---|
56 | {
|
---|
57 | { /* #0 */
|
---|
58 | "foo://tt:tt@example.com: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",
|
---|
59 | /*.pszScheme =*/ "foo",
|
---|
60 | /*.pszAuthority =*/ "tt:tt@example.com:8042",
|
---|
61 | /*.pszPath =*/ "/over/ <>#%\"{}|^[]`/there",
|
---|
62 | /*.pszQuery =*/ "name= <>#%\"{}|^[]`ferret",
|
---|
63 | /*.pszFragment =*/ "nose <>#%\"{}|^[]`",
|
---|
64 | /*.pszUsername =*/ "tt",
|
---|
65 | /*.pszPassword =*/ "tt",
|
---|
66 | /*.uPort =*/ 8042,
|
---|
67 | },
|
---|
68 | { /* #1 */
|
---|
69 | "foo://tt:tt@example.com: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",
|
---|
70 | /*.pszScheme =*/ "foo",
|
---|
71 | /*.pszAuthority =*/ "tt:tt@example.com:8042",
|
---|
72 | /*.pszPath =*/ "/over/ <>#%\"{}|^[]`/there",
|
---|
73 | /*.pszQuery =*/ "name= <>#%\"{}|^[]`ferret",
|
---|
74 | /*.pszFragment =*/ NULL,
|
---|
75 | /*.pszUsername =*/ "tt",
|
---|
76 | /*.pszPassword =*/ "tt",
|
---|
77 | /*.uPort =*/ 8042,
|
---|
78 | },
|
---|
79 | { /* #2 */
|
---|
80 | "foo://tt:tt@example.com:8042/over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there",
|
---|
81 | /*.pszScheme =*/ "foo",
|
---|
82 | /*.pszAuthority =*/ "tt:tt@example.com:8042",
|
---|
83 | /*.pszPath =*/ "/over/ <>#%\"{}|^[]`/there",
|
---|
84 | /*.pszQuery =*/ NULL,
|
---|
85 | /*.pszFragment =*/ NULL,
|
---|
86 | /*.pszUsername =*/ "tt",
|
---|
87 | /*.pszPassword =*/ "tt",
|
---|
88 | /*.uPort =*/ 8042,
|
---|
89 | },
|
---|
90 | { /* #3 */
|
---|
91 | "foo:tt@example.com",
|
---|
92 | /*.pszScheme =*/ "foo",
|
---|
93 | /*.pszAuthority =*/ NULL,
|
---|
94 | /*.pszPath =*/ "tt@example.com",
|
---|
95 | /*.pszQuery =*/ NULL,
|
---|
96 | /*.pszFragment =*/ NULL,
|
---|
97 | /*.pszUsername =*/ NULL,
|
---|
98 | /*.pszPassword =*/ NULL,
|
---|
99 | /*.uPort =*/ UINT32_MAX,
|
---|
100 | },
|
---|
101 | { /* #4 */
|
---|
102 | "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",
|
---|
103 | /*.pszScheme =*/ "foo",
|
---|
104 | /*.pszAuthority =*/ NULL,
|
---|
105 | /*.pszPath =*/ "/over/ <>#%\"{}|^[]`/there",
|
---|
106 | /*.pszQuery =*/ "name= <>#%\"{}|^[]`ferret",
|
---|
107 | /*.pszFragment =*/ "nose <>#%\"{}|^[]`",
|
---|
108 | /*.pszUsername =*/ NULL,
|
---|
109 | /*.pszPassword =*/ NULL,
|
---|
110 | /*.uPort =*/ UINT32_MAX,
|
---|
111 | },
|
---|
112 | { /* #5 */
|
---|
113 | "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",
|
---|
114 | /*.pszScheme =*/ "foo",
|
---|
115 | /*.pszAuthority =*/ NULL,
|
---|
116 | /*.pszPath =*/ "/over/ <>#%\"{}|^[]`/there",
|
---|
117 | /*.pszQuery =*/ NULL,
|
---|
118 | /*.pszFragment =*/ "nose <>#%\"{}|^[]`",
|
---|
119 | /*.pszUsername =*/ NULL,
|
---|
120 | /*.pszPassword =*/ NULL,
|
---|
121 | /*.uPort =*/ UINT32_MAX,
|
---|
122 | },
|
---|
123 | { /* #6 */
|
---|
124 | "urn:example:animal:ferret:nose",
|
---|
125 | /*.pszScheme =*/ "urn",
|
---|
126 | /*.pszAuthority =*/ NULL,
|
---|
127 | /*.pszPath =*/ "example:animal:ferret:nose",
|
---|
128 | /*.pszQuery =*/ NULL,
|
---|
129 | /*.pszFragment =*/ NULL,
|
---|
130 | /*.pszUsername =*/ NULL,
|
---|
131 | /*.pszPassword =*/ NULL,
|
---|
132 | /*.uPort =*/ UINT32_MAX,
|
---|
133 | },
|
---|
134 | { /* #7 */
|
---|
135 | "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",
|
---|
136 | /*.pszScheme =*/ "foo",
|
---|
137 | /*.pszAuthority =*/ NULL,
|
---|
138 | /*.pszPath =*/ NULL,
|
---|
139 | /*.pszQuery =*/ "name= <>#%\"{}|^[]`ferret",
|
---|
140 | /*.pszFragment =*/ "nose <>#%\"{}|^[]`",
|
---|
141 | /*.pszUsername =*/ NULL,
|
---|
142 | /*.pszPassword =*/ NULL,
|
---|
143 | /*.uPort =*/ UINT32_MAX,
|
---|
144 | },
|
---|
145 | { /* #8 */
|
---|
146 | "foo:#nose%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60",
|
---|
147 | /*.pszScheme =*/ "foo",
|
---|
148 | /*.pszAuthority =*/ NULL,
|
---|
149 | /*.pszPath =*/ NULL,
|
---|
150 | /*.pszQuery =*/ NULL,
|
---|
151 | /*.pszFragment =*/ "nose <>#%\"{}|^[]`",
|
---|
152 | /*.pszUsername =*/ NULL,
|
---|
153 | /*.pszPassword =*/ NULL,
|
---|
154 | /*.uPort =*/ UINT32_MAX,
|
---|
155 | },
|
---|
156 | { /* #9 */
|
---|
157 | "foo://tt:tt@example.com: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",
|
---|
158 | /*.pszScheme =*/ "foo",
|
---|
159 | /*.pszAuthority =*/ "tt:tt@example.com:8042",
|
---|
160 | /*.pszPath =*/ "/",
|
---|
161 | /*.pszQuery =*/ "name= <>#%\"{}|^[]`ferret",
|
---|
162 | /*.pszFragment =*/ "nose <>#%\"{}|^[]`",
|
---|
163 | /*.pszUsername =*/ "tt",
|
---|
164 | /*.pszPassword =*/ "tt",
|
---|
165 | /*.uPort =*/ 8042,
|
---|
166 | },
|
---|
167 | { /* #10 */
|
---|
168 | "foo://tt:tt@example.com:8042/",
|
---|
169 | /*.pszScheme =*/ "foo",
|
---|
170 | /*.pszAuthority =*/ "tt:tt@example.com:8042",
|
---|
171 | /*.pszPath =*/ "/",
|
---|
172 | /*.pszQuery =*/ NULL,
|
---|
173 | /*.pszFragment =*/ NULL,
|
---|
174 | /*.pszUsername =*/ "tt",
|
---|
175 | /*.pszPassword =*/ "tt",
|
---|
176 | /*.uPort =*/ 8042,
|
---|
177 | },
|
---|
178 | { /* #11 */
|
---|
179 | "foo://tt:tt@example.com: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",
|
---|
180 | /*.pszScheme =*/ "foo",
|
---|
181 | /*.pszAuthority =*/ "tt:tt@example.com:8042",
|
---|
182 | /*.pszPath =*/ NULL,
|
---|
183 | /*.pszQuery =*/ "name= <>#%\"{}|^[]`ferret",
|
---|
184 | /*.pszFragment =*/ "nose <>#%\"{}|^[]`",
|
---|
185 | /*.pszUsername =*/ "tt",
|
---|
186 | /*.pszPassword =*/ "tt",
|
---|
187 | /*.uPort =*/ 8042,
|
---|
188 | },
|
---|
189 | { /* #12 */
|
---|
190 | "foo://tt:tt@example.com:8042#nose%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60",
|
---|
191 | /*.pszScheme =*/ "foo",
|
---|
192 | /*.pszAuthority =*/ "tt:tt@example.com:8042",
|
---|
193 | /*.pszPath =*/ NULL,
|
---|
194 | /*.pszQuery =*/ NULL,
|
---|
195 | /*.pszFragment =*/ "nose <>#%\"{}|^[]`",
|
---|
196 | /*.pszUsername =*/ "tt",
|
---|
197 | /*.pszPassword =*/ "tt",
|
---|
198 | /*.uPort =*/ 8042,
|
---|
199 | },
|
---|
200 | { /* #13 */
|
---|
201 | "foo://tt:tt@example.com:8042",
|
---|
202 | /*.pszScheme =*/ "foo",
|
---|
203 | /*.pszAuthority =*/ "tt:tt@example.com:8042",
|
---|
204 | /*.pszPath =*/ NULL,
|
---|
205 | /*.pszQuery =*/ NULL,
|
---|
206 | /*.pszFragment =*/ NULL,
|
---|
207 | /*.pszUsername =*/ "tt",
|
---|
208 | /*.pszPassword =*/ "tt",
|
---|
209 | /*.uPort =*/ 8042,
|
---|
210 | },
|
---|
211 | { /* #14 */
|
---|
212 | "foo:///",
|
---|
213 | /*.pszScheme =*/ "foo",
|
---|
214 | /*.pszAuthority =*/ "",
|
---|
215 | /*.pszPath =*/ "/",
|
---|
216 | /*.pszQuery =*/ NULL,
|
---|
217 | /*.pszFragment =*/ NULL,
|
---|
218 | /*.pszUsername =*/ NULL,
|
---|
219 | /*.pszPassword =*/ NULL,
|
---|
220 | /*.uPort =*/ UINT32_MAX,
|
---|
221 | },
|
---|
222 | { /* #15 */
|
---|
223 | "foo://",
|
---|
224 | /*.pszScheme =*/ "foo",
|
---|
225 | /*.pszAuthority =*/ "",
|
---|
226 | /*.pszPath =*/ NULL,
|
---|
227 | /*.pszQuery =*/ NULL,
|
---|
228 | /*.pszFragment =*/ NULL,
|
---|
229 | /*.pszUsername =*/ NULL,
|
---|
230 | /*.pszPassword =*/ NULL,
|
---|
231 | /*.uPort =*/ UINT32_MAX,
|
---|
232 | },
|
---|
233 | };
|
---|
234 |
|
---|
235 |
|
---|
236 | static const char *g_apcszTestURIs[] =
|
---|
237 | {
|
---|
238 | "foo://tt:tt@example.com: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",
|
---|
239 | "foo://tt:tt@example.com: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",
|
---|
240 | "foo://tt:tt@example.com:8042/over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there",
|
---|
241 | "foo:tt@example.com",
|
---|
242 | "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",
|
---|
243 | "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",
|
---|
244 | "urn:example:animal:ferret:nose",
|
---|
245 | "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",
|
---|
246 | "foo:#nose%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60",
|
---|
247 | "foo://tt:tt@example.com: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",
|
---|
248 | "foo://tt:tt@example.com:8042/",
|
---|
249 | "foo://tt:tt@example.com: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",
|
---|
250 | "foo://tt:tt@example.com:8042#nose%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60",
|
---|
251 | "foo://tt:tt@example.com:8042",
|
---|
252 | "foo:///",
|
---|
253 | "foo://"
|
---|
254 | };
|
---|
255 |
|
---|
256 | static const char *g_apcszCreateURIs[][5] =
|
---|
257 | {
|
---|
258 | { "foo", "tt:tt@example.com:8042", "/over/ <>#%\"{}|^[]`/there", "name= <>#%\"{}|^[]`ferret", "nose <>#%\"{}|^[]`" },
|
---|
259 | { "foo", "tt:tt@example.com:8042", "/over/ <>#%\"{}|^[]`/there", "name= <>#%\"{}|^[]`ferret", NULL },
|
---|
260 | { "foo", "tt:tt@example.com:8042", "/over/ <>#%\"{}|^[]`/there", NULL, NULL },
|
---|
261 | { "foo", NULL, "tt@example.com", NULL, NULL },
|
---|
262 | { "foo", NULL, "/over/ <>#%\"{}|^[]`/there", "name= <>#%\"{}|^[]`ferret", "nose <>#%\"{}|^[]`" },
|
---|
263 | { "foo", NULL, "/over/ <>#%\"{}|^[]`/there", NULL, "nose <>#%\"{}|^[]`" },
|
---|
264 | { "urn", NULL, "example:animal:ferret:nose", NULL, NULL },
|
---|
265 | { "foo", NULL, NULL, "name= <>#%\"{}|^[]`ferret", "nose <>#%\"{}|^[]`" },
|
---|
266 | { "foo", NULL, NULL, NULL, "nose <>#%\"{}|^[]`" },
|
---|
267 | { "foo", "tt:tt@example.com:8042", "/", "name= <>#%\"{}|^[]`ferret", "nose <>#%\"{}|^[]`" },
|
---|
268 | { "foo", "tt:tt@example.com:8042", "/", NULL, NULL },
|
---|
269 | { "foo", "tt:tt@example.com:8042", NULL, "name= <>#%\"{}|^[]`ferret", "nose <>#%\"{}|^[]`" },
|
---|
270 | { "foo", "tt:tt@example.com:8042", NULL, NULL, "nose <>#%\"{}|^[]`" },
|
---|
271 | { "foo", "tt:tt@example.com:8042", NULL, NULL, NULL },
|
---|
272 | { "foo", "", "/", NULL, NULL },
|
---|
273 | { "foo", "", NULL, NULL, NULL }
|
---|
274 | };
|
---|
275 |
|
---|
276 | struct URIFILETEST
|
---|
277 | {
|
---|
278 | const char *pcszPath;
|
---|
279 | const char *pcszUri;
|
---|
280 | uint32_t uFormat;
|
---|
281 | }
|
---|
282 | g_apCreateFileURIs[] =
|
---|
283 | {
|
---|
284 | { "C:\\over\\ <>#%\"{}|^[]`\\there", "file:///C:%5Cover%5C%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60%5Cthere", URI_FILE_FORMAT_WIN },
|
---|
285 | { "/over/ <>#%\"{}|^[]`/there", "file:///over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there", URI_FILE_FORMAT_UNIX },
|
---|
286 | { "/", "file:///", URI_FILE_FORMAT_UNIX },
|
---|
287 | { "/C:/over/ <>#%\"{}|^[]`/there", "file:///C:%5Cover%5C%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60%5Cthere", URI_FILE_FORMAT_UNIX },
|
---|
288 | { "\\over\\ <>#%\"{}|^[]`\\there", "file:///over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there", URI_FILE_FORMAT_WIN }
|
---|
289 | };
|
---|
290 |
|
---|
291 | /**
|
---|
292 | * Basic API checks.
|
---|
293 | */
|
---|
294 | static void tstScheme(size_t idxTest, const char *pszUri, const char *pszTest)
|
---|
295 | {
|
---|
296 | char *pszResult = RTUriScheme(pszUri);
|
---|
297 | if (pszTest)
|
---|
298 | {
|
---|
299 | RTTESTI_CHECK_MSG_RETV(pszResult, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
300 | RTTESTI_CHECK_MSG(RTStrCmp(pszResult, pszTest) == 0, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
301 | }
|
---|
302 | else
|
---|
303 | RTTESTI_CHECK_MSG(!pszResult, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
304 |
|
---|
305 | if (pszResult)
|
---|
306 | RTStrFree(pszResult);
|
---|
307 | }
|
---|
308 |
|
---|
309 | static void tstAuthority(size_t idxTest, const char *pszUri, const char *pszTest)
|
---|
310 | {
|
---|
311 | char *pszResult = RTUriAuthority(pszUri);
|
---|
312 | if (pszTest)
|
---|
313 | {
|
---|
314 | RTTESTI_CHECK_MSG_RETV(pszResult, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
315 | RTTESTI_CHECK_MSG(RTStrCmp(pszResult, pszTest) == 0, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
316 | }
|
---|
317 | else
|
---|
318 | RTTESTI_CHECK_MSG(!pszResult, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
319 |
|
---|
320 | if (pszResult)
|
---|
321 | RTStrFree(pszResult);
|
---|
322 | }
|
---|
323 |
|
---|
324 | static void tstAuthorityUsername(size_t idxTest, const char *pszUri, const char *pszTest)
|
---|
325 | {
|
---|
326 | char *pszResult = RTUriAuthorityUsername(pszUri);
|
---|
327 | if (pszTest)
|
---|
328 | {
|
---|
329 | RTTESTI_CHECK_MSG_RETV(pszResult, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
330 | RTTESTI_CHECK_MSG(RTStrCmp(pszResult, pszTest) == 0, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
331 | }
|
---|
332 | else
|
---|
333 | RTTESTI_CHECK_MSG(!pszResult, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
334 | RTStrFree(pszResult);
|
---|
335 | }
|
---|
336 |
|
---|
337 | static void tstAuthorityPassword(size_t idxTest, const char *pszUri, const char *pszTest)
|
---|
338 | {
|
---|
339 | char *pszResult = RTUriAuthorityPassword(pszUri);
|
---|
340 | if (pszTest)
|
---|
341 | {
|
---|
342 | RTTESTI_CHECK_MSG_RETV(pszResult, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
343 | RTTESTI_CHECK_MSG(RTStrCmp(pszResult, pszTest) == 0, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
344 | }
|
---|
345 | else
|
---|
346 | RTTESTI_CHECK_MSG(!pszResult, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
347 | RTStrFree(pszResult);
|
---|
348 | }
|
---|
349 |
|
---|
350 | static void tstAuthorityPort(size_t idxTest, const char *pszUri, uint32_t uTest)
|
---|
351 | {
|
---|
352 | uint32_t uResult = RTUriAuthorityPort(pszUri);
|
---|
353 | RTTESTI_CHECK_MSG_RETV(uResult == uTest, ("#%u: Result %#x != %#x (%s)", idxTest, uResult, uTest, pszUri));
|
---|
354 | }
|
---|
355 |
|
---|
356 | static void tstPath(size_t idxTest, const char *pszUri, const char *pszTest)
|
---|
357 | {
|
---|
358 | char *pszResult = RTUriPath(pszUri);
|
---|
359 | if (pszTest)
|
---|
360 | {
|
---|
361 | RTTESTI_CHECK_MSG_RETV(pszResult, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
362 | RTTESTI_CHECK_MSG(RTStrCmp(pszResult, pszTest) == 0, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
363 | }
|
---|
364 | else
|
---|
365 | RTTESTI_CHECK_MSG(!pszResult, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
366 |
|
---|
367 | if (pszResult)
|
---|
368 | RTStrFree(pszResult);
|
---|
369 | }
|
---|
370 |
|
---|
371 | static void tstQuery(size_t idxTest, const char *pszUri, const char *pszTest)
|
---|
372 | {
|
---|
373 | char *pszResult = RTUriQuery(pszUri);
|
---|
374 | if (pszTest)
|
---|
375 | {
|
---|
376 | RTTESTI_CHECK_MSG_RETV(pszResult, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
377 | RTTESTI_CHECK_MSG(RTStrCmp(pszResult, pszTest) == 0, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
378 | }
|
---|
379 | else
|
---|
380 | RTTESTI_CHECK_MSG(!pszResult, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
381 |
|
---|
382 | if (pszResult)
|
---|
383 | RTStrFree(pszResult);
|
---|
384 | }
|
---|
385 |
|
---|
386 | static void tstFragment(size_t idxTest, const char *pszUri, const char *pszTest)
|
---|
387 | {
|
---|
388 | char *pszResult = RTUriFragment(pszUri);
|
---|
389 | if (pszTest)
|
---|
390 | {
|
---|
391 | RTTESTI_CHECK_MSG_RETV(pszResult, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
392 | RTTESTI_CHECK_MSG(RTStrCmp(pszResult, pszTest) == 0, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
393 | }
|
---|
394 | else
|
---|
395 | RTTESTI_CHECK_MSG(!pszResult, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
396 |
|
---|
397 | if (pszResult)
|
---|
398 | RTStrFree(pszResult);
|
---|
399 | }
|
---|
400 |
|
---|
401 | static void tstCreate(size_t idxTest, const char *pszScheme, const char *pszAuthority, const char *pszPath, const char *pszQuery, const char *pszFragment, const char *pszTest)
|
---|
402 | {
|
---|
403 | char *pszResult = RTUriCreate(pszScheme, pszAuthority, pszPath, pszQuery, pszFragment);
|
---|
404 | if (pszTest)
|
---|
405 | {
|
---|
406 | RTTESTI_CHECK_MSG_RETV(pszResult, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
407 | RTTESTI_CHECK_MSG(RTStrCmp(pszResult, pszTest) == 0, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
408 | }
|
---|
409 | else
|
---|
410 | RTTESTI_CHECK_MSG(!pszResult, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
411 |
|
---|
412 | if (pszResult)
|
---|
413 | RTStrFree(pszResult);
|
---|
414 | return;
|
---|
415 | }
|
---|
416 |
|
---|
417 | static void tstFileCreate(size_t idxTest, const char *pszPath, const char *pszTest)
|
---|
418 | {
|
---|
419 | char *pszResult = RTUriFileCreate(pszPath);
|
---|
420 | if (pszTest)
|
---|
421 | {
|
---|
422 | RTTESTI_CHECK_MSG_RETV(pszResult, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
423 | RTTESTI_CHECK_MSG(RTStrCmp(pszResult, pszTest) == 0, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
424 | }
|
---|
425 | else
|
---|
426 | RTTESTI_CHECK_MSG(!pszResult, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
427 |
|
---|
428 | if (pszResult)
|
---|
429 | RTStrFree(pszResult);
|
---|
430 | return;
|
---|
431 | }
|
---|
432 |
|
---|
433 | static void tstFilePath(size_t idxTest, const char *pszUri, const char *pszTest, uint32_t uFormat)
|
---|
434 | {
|
---|
435 | char *pszResult = RTUriFilePath(pszUri, uFormat);
|
---|
436 | if (pszTest)
|
---|
437 | {
|
---|
438 | RTTESTI_CHECK_MSG_RETV(pszResult, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
439 | RTTESTI_CHECK_MSG(RTStrCmp(pszResult, pszTest) == 0, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
440 | }
|
---|
441 | else
|
---|
442 | RTTESTI_CHECK_MSG(!pszResult, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
|
---|
443 |
|
---|
444 | if (pszResult)
|
---|
445 | RTStrFree(pszResult);
|
---|
446 | return;
|
---|
447 | }
|
---|
448 |
|
---|
449 | int main()
|
---|
450 | {
|
---|
451 | RTTEST hTest;
|
---|
452 | int rc = RTTestInitAndCreate("tstRTUri", &hTest);
|
---|
453 | if (rc)
|
---|
454 | return rc;
|
---|
455 | RTTestBanner(hTest);
|
---|
456 |
|
---|
457 | /* Scheme */
|
---|
458 | RTTestISub("RTUriScheme");
|
---|
459 | for (uint32_t i = 0; i < RT_ELEMENTS(g_aTests); i++)
|
---|
460 | tstScheme(i, g_aTests[i].pszUri, g_aTests[i].pszScheme);
|
---|
461 |
|
---|
462 | /* Authority */
|
---|
463 | RTTestISub("RTUriAuthority");
|
---|
464 | for (uint32_t i = 0; i < RT_ELEMENTS(g_aTests); i++)
|
---|
465 | {
|
---|
466 | tstAuthority(i, g_aTests[i].pszUri, g_aTests[i].pszAuthority);
|
---|
467 | tstAuthorityUsername(i, g_aTests[i].pszUri, g_aTests[i].pszUsername);
|
---|
468 | tstAuthorityPassword(i, g_aTests[i].pszUri, g_aTests[i].pszPassword);
|
---|
469 | tstAuthorityPort(i, g_aTests[i].pszUri, g_aTests[i].uPort);
|
---|
470 | }
|
---|
471 |
|
---|
472 | /* Path */
|
---|
473 | RTTestISub("RTUriPath");
|
---|
474 | for (uint32_t i = 0; i < RT_ELEMENTS(g_aTests); i++)
|
---|
475 | tstPath(i, g_aTests[i].pszUri, g_aTests[i].pszPath);
|
---|
476 |
|
---|
477 | /* Query */
|
---|
478 | RTTestISub("RTUriQuery");
|
---|
479 | for (uint32_t i = 0; i < RT_ELEMENTS(g_aTests); i++)
|
---|
480 | tstQuery(i, g_aTests[i].pszUri, g_aTests[i].pszQuery);
|
---|
481 |
|
---|
482 | /* Fragment */
|
---|
483 | RTTestISub("RTUriFragment");
|
---|
484 | for (uint32_t i = 0; i < RT_ELEMENTS(g_aTests); i++)
|
---|
485 | tstFragment(i, g_aTests[i].pszUri, g_aTests[i].pszFragment);
|
---|
486 |
|
---|
487 | /* Creation */
|
---|
488 | RTTestISub("RTUriCreate");
|
---|
489 | for (uint32_t i = 0; i < RT_ELEMENTS(g_aTests); i++)
|
---|
490 | tstCreate(i, g_aTests[i].pszScheme, g_aTests[i].pszAuthority, g_aTests[i].pszPath,
|
---|
491 | g_aTests[i].pszQuery, g_aTests[i].pszFragment, g_aTests[i].pszUri);
|
---|
492 |
|
---|
493 | /* File Uri path */
|
---|
494 | RTTestISub("RTUriFilePath");
|
---|
495 | for (size_t i = 0; i < RT_ELEMENTS(g_apCreateFileURIs); ++i)
|
---|
496 | tstFilePath(i, g_apCreateFileURIs[i].pcszUri, g_apCreateFileURIs[i].pcszPath, g_apCreateFileURIs[i].uFormat);
|
---|
497 |
|
---|
498 | /* File Uri creation */
|
---|
499 | RTTestISub("RTUriFileCreate");
|
---|
500 | for (size_t i = 0; i < 3; ++i)
|
---|
501 | tstFileCreate(i, g_apCreateFileURIs[i].pcszPath, g_apCreateFileURIs[i].pcszUri);
|
---|
502 |
|
---|
503 | return RTTestSummaryAndDestroy(hTest);
|
---|
504 | }
|
---|
505 |
|
---|