1 | /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ |
---|
2 | |
---|
3 | /* test-mime.c - Test program for the GNOME Virtual File System. |
---|
4 | |
---|
5 | Copyright (C) 1999 Free Software Foundation |
---|
6 | Copyright (C) 2000, 2001 Eazel, Inc. |
---|
7 | |
---|
8 | The Gnome Library is free software; you can redistribute it and/or |
---|
9 | modify it under the terms of the GNU Library General Public License as |
---|
10 | published by the Free Software Foundation; either version 2 of the |
---|
11 | License, or (at your option) any later version. |
---|
12 | |
---|
13 | The Gnome Library is distributed in the hope that it will be useful, |
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | Library General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU Library General Public |
---|
19 | License along with the Gnome Library; see the file COPYING.LIB. If not, |
---|
20 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
21 | Boston, MA 02111-1307, USA. |
---|
22 | |
---|
23 | Authors: |
---|
24 | Darin Adler <darin@eazel.com> |
---|
25 | Ian McKellar <yakk@yakk.net.au> |
---|
26 | */ |
---|
27 | |
---|
28 | #include <config.h> |
---|
29 | |
---|
30 | #include <stdlib.h> |
---|
31 | #include <string.h> |
---|
32 | #include "gnome-vfs.h" |
---|
33 | #include "gnome-vfs-private-utils.h" |
---|
34 | |
---|
35 | #define TEST_ASSERT(expression, message) \ |
---|
36 | G_STMT_START { if (!(expression)) test_failed message; } G_STMT_END |
---|
37 | |
---|
38 | static void |
---|
39 | stop_after_log (const char *domain, GLogLevelFlags level, |
---|
40 | const char *message, gpointer data) |
---|
41 | { |
---|
42 | void (* saved_handler) (int); |
---|
43 | |
---|
44 | g_log_default_handler (domain, level, message, data); |
---|
45 | |
---|
46 | saved_handler = signal (SIGINT, SIG_IGN); |
---|
47 | raise (SIGINT); |
---|
48 | signal (SIGINT, saved_handler); |
---|
49 | } |
---|
50 | |
---|
51 | static void |
---|
52 | make_asserts_break (const char *domain) |
---|
53 | { |
---|
54 | g_log_set_handler |
---|
55 | (domain, |
---|
56 | (GLogLevelFlags) (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING), |
---|
57 | stop_after_log, NULL); |
---|
58 | } |
---|
59 | |
---|
60 | static gboolean at_least_one_test_failed = FALSE; |
---|
61 | |
---|
62 | static void |
---|
63 | test_failed (const char *format, ...) |
---|
64 | { |
---|
65 | va_list arguments; |
---|
66 | char *message; |
---|
67 | |
---|
68 | va_start (arguments, format); |
---|
69 | message = g_strdup_vprintf (format, arguments); |
---|
70 | va_end (arguments); |
---|
71 | |
---|
72 | g_message ("test failed: %s", message); |
---|
73 | at_least_one_test_failed = TRUE; |
---|
74 | } |
---|
75 | |
---|
76 | static void |
---|
77 | test_make_canonical_path (const char *input, |
---|
78 | const char *expected_output) |
---|
79 | { |
---|
80 | char *output; |
---|
81 | |
---|
82 | output = gnome_vfs_make_path_name_canonical (input); |
---|
83 | |
---|
84 | if (strcmp (output, expected_output) != 0) { |
---|
85 | test_failed ("test_make_canonical_path (%s) resulted in %s instead of %s", |
---|
86 | input, output, expected_output); |
---|
87 | } |
---|
88 | |
---|
89 | g_free (output); |
---|
90 | } |
---|
91 | |
---|
92 | static void |
---|
93 | test_uri_to_string (const char *input, |
---|
94 | const char *expected_output, |
---|
95 | GnomeVFSURIHideOptions hide_options) |
---|
96 | { |
---|
97 | GnomeVFSURI *uri; |
---|
98 | char *output; |
---|
99 | |
---|
100 | uri = gnome_vfs_uri_new (input); |
---|
101 | if (uri == NULL) { |
---|
102 | output = g_strdup ("NULL"); |
---|
103 | } else { |
---|
104 | output = gnome_vfs_uri_to_string (uri, hide_options); |
---|
105 | gnome_vfs_uri_unref (uri); |
---|
106 | } |
---|
107 | |
---|
108 | if (strcmp (output, expected_output) != 0) { |
---|
109 | test_failed ("gnome_vfs_uri_to_string (%s, %d) resulted in %s instead of %s", |
---|
110 | input, hide_options, output, expected_output); |
---|
111 | } |
---|
112 | |
---|
113 | g_free (output); |
---|
114 | } |
---|
115 | |
---|
116 | static void |
---|
117 | test_make_canonical (const char *input, |
---|
118 | const char *expected_output) |
---|
119 | { |
---|
120 | char *output; |
---|
121 | |
---|
122 | output = gnome_vfs_make_uri_canonical (input); |
---|
123 | if (output == NULL) { |
---|
124 | output = g_strdup ("NULL"); |
---|
125 | } |
---|
126 | |
---|
127 | if (strcmp (output, expected_output) != 0) { |
---|
128 | test_failed ("test_make_canonical (%s) resulted in %s instead of %s", |
---|
129 | input, output, expected_output); |
---|
130 | } |
---|
131 | |
---|
132 | g_free (output); |
---|
133 | } |
---|
134 | |
---|
135 | static void |
---|
136 | test_uri_match (const char *uri_string_1, const char *uri_string_2, gboolean expected_result) |
---|
137 | { |
---|
138 | GnomeVFSURI *uri1; |
---|
139 | GnomeVFSURI *uri2; |
---|
140 | |
---|
141 | uri1 = gnome_vfs_uri_new (uri_string_1); |
---|
142 | uri2 = gnome_vfs_uri_new (uri_string_2); |
---|
143 | |
---|
144 | if (gnome_vfs_uri_equal (uri1, uri2) != expected_result) { |
---|
145 | test_failed ("test_uri_match (%s, %s) resulted in a %s instead of %s", |
---|
146 | uri_string_1, uri_string_2, |
---|
147 | expected_result ? "mismatch" : "match", |
---|
148 | expected_result ? "match" : "mismatch"); |
---|
149 | } |
---|
150 | |
---|
151 | gnome_vfs_uri_unref (uri2); |
---|
152 | gnome_vfs_uri_unref (uri1); |
---|
153 | } |
---|
154 | |
---|
155 | static void |
---|
156 | test_file_path_to_uri_string (const char *input, |
---|
157 | const char *expected_output, |
---|
158 | GnomeVFSURIHideOptions hide_options) |
---|
159 | { |
---|
160 | GnomeVFSURI *uri, *resulting_uri; |
---|
161 | char *output; |
---|
162 | char *unescaped_output; |
---|
163 | |
---|
164 | uri = gnome_vfs_uri_new ("file:/"); |
---|
165 | resulting_uri = gnome_vfs_uri_append_path (uri, input); |
---|
166 | gnome_vfs_uri_unref (uri); |
---|
167 | |
---|
168 | output = gnome_vfs_uri_to_string (resulting_uri, hide_options); |
---|
169 | gnome_vfs_uri_unref (resulting_uri); |
---|
170 | |
---|
171 | unescaped_output = gnome_vfs_unescape_string (output, "/"); |
---|
172 | g_free (output); |
---|
173 | |
---|
174 | if (strcmp (unescaped_output, expected_output) != 0) { |
---|
175 | test_failed ("gnome_vfs_uri_to_string (%s, %d) resulted in %s instead of %s", |
---|
176 | input, hide_options, unescaped_output, expected_output); |
---|
177 | } |
---|
178 | |
---|
179 | g_free (unescaped_output); |
---|
180 | } |
---|
181 | |
---|
182 | static void |
---|
183 | test_uri_has_fragment_id (const char *input, |
---|
184 | const char *expected_output) |
---|
185 | { |
---|
186 | GnomeVFSURI *uri; |
---|
187 | char *output; |
---|
188 | |
---|
189 | uri = gnome_vfs_uri_new (input); |
---|
190 | if (uri == NULL) { |
---|
191 | output = g_strdup ("NULL"); |
---|
192 | } else { |
---|
193 | output = g_strdup (gnome_vfs_uri_get_fragment_identifier (uri)); |
---|
194 | } |
---|
195 | |
---|
196 | if (strcmp (output, expected_output) != 0) { |
---|
197 | test_failed ("test_uri_has_fragment_id (%s) resulted in %s instead of %s", |
---|
198 | input, output, expected_output); |
---|
199 | } |
---|
200 | |
---|
201 | g_free (output); |
---|
202 | gnome_vfs_uri_unref (uri); |
---|
203 | } |
---|
204 | |
---|
205 | static void |
---|
206 | test_uri_parent (const char *input, |
---|
207 | const char *expected_output) |
---|
208 | { |
---|
209 | GnomeVFSURI *uri, *parent; |
---|
210 | char *output; |
---|
211 | |
---|
212 | uri = gnome_vfs_uri_new (input); |
---|
213 | if (uri == NULL) { |
---|
214 | output = g_strdup ("URI NULL"); |
---|
215 | } else { |
---|
216 | parent = gnome_vfs_uri_get_parent (uri); |
---|
217 | gnome_vfs_uri_unref (uri); |
---|
218 | if (parent == NULL) { |
---|
219 | output = g_strdup ("NULL"); |
---|
220 | } else { |
---|
221 | output = gnome_vfs_uri_to_string (parent, GNOME_VFS_URI_HIDE_NONE); |
---|
222 | gnome_vfs_uri_unref (parent); |
---|
223 | } |
---|
224 | } |
---|
225 | |
---|
226 | if (strcmp (output, expected_output) != 0) { |
---|
227 | test_failed ("gnome_vfs_uri_parent (%s) resulted in %s instead of %s", |
---|
228 | input, output, expected_output); |
---|
229 | } |
---|
230 | |
---|
231 | g_free (output); |
---|
232 | } |
---|
233 | |
---|
234 | static void |
---|
235 | test_uri_has_parent (const char *input, |
---|
236 | const char *expected_output) |
---|
237 | { |
---|
238 | GnomeVFSURI *uri; |
---|
239 | const char *output; |
---|
240 | gboolean has; |
---|
241 | |
---|
242 | uri = gnome_vfs_uri_new (input); |
---|
243 | if (uri == NULL) { |
---|
244 | output = "URI NULL"; |
---|
245 | } else { |
---|
246 | has = gnome_vfs_uri_has_parent (uri); |
---|
247 | gnome_vfs_uri_unref (uri); |
---|
248 | output = has ? "TRUE" : "FALSE"; |
---|
249 | } |
---|
250 | |
---|
251 | if (strcmp (output, expected_output) != 0) { |
---|
252 | test_failed ("gnome_vfs_uri_has_parent (%s) resulted in %s instead of %s", |
---|
253 | input, output, expected_output); |
---|
254 | } |
---|
255 | } |
---|
256 | |
---|
257 | /* |
---|
258 | * Ensure that gnome_vfs_uri_{get_host_name,get_scheme,get_user_name,get_password} |
---|
259 | * return expected results |
---|
260 | */ |
---|
261 | static void |
---|
262 | test_uri_part (const char *input, |
---|
263 | const char *expected_output, |
---|
264 | const char *(*func_gnome_vfs_uri)(const GnomeVFSURI *) |
---|
265 | ) |
---|
266 | { |
---|
267 | GnomeVFSURI *uri; |
---|
268 | const char *output; |
---|
269 | |
---|
270 | uri = gnome_vfs_uri_new (input); |
---|
271 | if (NULL == uri) { |
---|
272 | output = "URI NULL"; |
---|
273 | } else { |
---|
274 | output = func_gnome_vfs_uri(uri); |
---|
275 | if ( NULL == output ) { |
---|
276 | output = "NULL"; |
---|
277 | } |
---|
278 | } |
---|
279 | |
---|
280 | if (strcmp (output, expected_output) != 0) { |
---|
281 | test_failed ("gnome_vfs_uri_{?} (%s) resulted in %s instead of %s", |
---|
282 | input, output, expected_output); |
---|
283 | } |
---|
284 | |
---|
285 | if ( NULL != uri ) { |
---|
286 | gnome_vfs_uri_unref (uri); |
---|
287 | } |
---|
288 | |
---|
289 | } |
---|
290 | |
---|
291 | /* |
---|
292 | * Ensure that gnome_vfs_uri_get_host_port |
---|
293 | * return expected results |
---|
294 | */ |
---|
295 | static void |
---|
296 | test_uri_host_port (const char *input, |
---|
297 | guint expected_port) |
---|
298 | { |
---|
299 | GnomeVFSURI *uri; |
---|
300 | gboolean success = FALSE; |
---|
301 | guint port; |
---|
302 | |
---|
303 | port = 0; |
---|
304 | uri = gnome_vfs_uri_new (input); |
---|
305 | if (NULL != uri) { |
---|
306 | port = gnome_vfs_uri_get_host_port(uri); |
---|
307 | if (expected_port == port) { |
---|
308 | success = TRUE; |
---|
309 | gnome_vfs_uri_unref (uri); |
---|
310 | } |
---|
311 | } |
---|
312 | |
---|
313 | if (!success) { |
---|
314 | test_failed ("gnome_vfs_uri_get_host_port (%s) resulted in %u instead of %u", |
---|
315 | input, port, expected_port); |
---|
316 | } |
---|
317 | } |
---|
318 | |
---|
319 | static void |
---|
320 | test_uri_is_parent_common (const char *parent, const char *item, gboolean deep, gboolean expected_result) |
---|
321 | { |
---|
322 | GnomeVFSURI *item_uri; |
---|
323 | GnomeVFSURI *parent_uri; |
---|
324 | gboolean result; |
---|
325 | |
---|
326 | item_uri = gnome_vfs_uri_new (item); |
---|
327 | parent_uri = gnome_vfs_uri_new (parent); |
---|
328 | |
---|
329 | result = gnome_vfs_uri_is_parent (parent_uri, item_uri, deep); |
---|
330 | |
---|
331 | if (result != expected_result) { |
---|
332 | test_failed ("gnome_vfs_uri_is_parent (%s, %s) resulted in \"%s\" instead of \"%s\"", |
---|
333 | parent, item, result ? "TRUE" : "FALSE", expected_result ? "TRUE" : "FALSE"); |
---|
334 | } |
---|
335 | } |
---|
336 | |
---|
337 | static void |
---|
338 | test_uri_is_parent_deep (const char *parent, const char *item, gboolean expected_result) |
---|
339 | { |
---|
340 | test_uri_is_parent_common (parent, item, TRUE, expected_result); |
---|
341 | } |
---|
342 | |
---|
343 | static void |
---|
344 | test_uri_is_parent_shallow (const char *parent, const char *item, gboolean expected_result) |
---|
345 | { |
---|
346 | test_uri_is_parent_common (parent, item, FALSE, expected_result); |
---|
347 | } |
---|
348 | |
---|
349 | #define VERIFY_STRING_RESULT(function, expected) \ |
---|
350 | G_STMT_START { \ |
---|
351 | char *result = function; \ |
---|
352 | if (!((result == NULL && expected == NULL) \ |
---|
353 | || (result != NULL && expected != NULL && strcmp (result, (char *)expected) == 0))) { \ |
---|
354 | test_failed ("%s: returned '%s' expected '%s'", #function, result, expected); \ |
---|
355 | } \ |
---|
356 | } G_STMT_END |
---|
357 | |
---|
358 | int |
---|
359 | main (int argc, char **argv) |
---|
360 | { |
---|
361 | make_asserts_break ("GLib"); |
---|
362 | make_asserts_break ("GnomeVFS"); |
---|
363 | |
---|
364 | /* Initialize the libraries we use. */ |
---|
365 | g_thread_init (NULL); |
---|
366 | gnome_vfs_init (); |
---|
367 | |
---|
368 | /* Test the "make canonical" call for pathnames. */ |
---|
369 | test_make_canonical_path ("", ""); |
---|
370 | test_make_canonical_path ("/", "/"); |
---|
371 | test_make_canonical_path ("/.", "/"); |
---|
372 | test_make_canonical_path ("/./.", "/"); |
---|
373 | test_make_canonical_path ("/.//.", "/"); |
---|
374 | test_make_canonical_path ("/.///.", "/"); |
---|
375 | test_make_canonical_path ("a", "a"); |
---|
376 | test_make_canonical_path ("/a/b/..", "/a"); |
---|
377 | test_make_canonical_path ("a///", "a/"); |
---|
378 | test_make_canonical_path ("./a", "a"); |
---|
379 | test_make_canonical_path ("../a", "../a"); |
---|
380 | test_make_canonical_path ("..//a", "../a"); |
---|
381 | test_make_canonical_path ("a/.", "a"); |
---|
382 | test_make_canonical_path ("/a/.", "/a"); |
---|
383 | test_make_canonical_path ("/a/..", "/"); |
---|
384 | test_make_canonical_path ("a//.", "a"); |
---|
385 | test_make_canonical_path ("./a/.", "a"); |
---|
386 | test_make_canonical_path (".//a/.", "a"); |
---|
387 | test_make_canonical_path ("./a//.", "a"); |
---|
388 | test_make_canonical_path ("a/..", ""); |
---|
389 | test_make_canonical_path ("a//..", ""); |
---|
390 | test_make_canonical_path ("./a/..", ""); |
---|
391 | test_make_canonical_path (".//a/..", ""); |
---|
392 | test_make_canonical_path ("./a//..", ""); |
---|
393 | test_make_canonical_path (".//a//..", ""); |
---|
394 | test_make_canonical_path ("a/b/..", "a"); |
---|
395 | test_make_canonical_path ("./a/b/..", "a"); |
---|
396 | test_make_canonical_path ("/./a/b/..", "/a"); |
---|
397 | test_make_canonical_path ("/a/./b/..", "/a"); |
---|
398 | test_make_canonical_path ("/a/b/./..", "/a"); |
---|
399 | test_make_canonical_path ("/a/b/../.", "/a"); |
---|
400 | test_make_canonical_path ("a/b/../..", ""); |
---|
401 | test_make_canonical_path ("./a/b/../..", ""); |
---|
402 | test_make_canonical_path ("././a/b/../..", ""); |
---|
403 | test_make_canonical_path ("a/b/c/../..", "a"); |
---|
404 | test_make_canonical_path ("a/b/c/../../d", "a/d"); |
---|
405 | test_make_canonical_path ("a/b/../../d", "d"); |
---|
406 | test_make_canonical_path ("a/../../d", "../d"); |
---|
407 | test_make_canonical_path ("a/b/.././.././c", "c"); |
---|
408 | test_make_canonical_path ("a/.././.././b/c", "../b/c"); |
---|
409 | test_make_canonical_path ("\\", "\\"); |
---|
410 | |
---|
411 | test_uri_to_string ("", "NULL", GNOME_VFS_URI_HIDE_NONE); |
---|
412 | |
---|
413 | test_uri_to_string ("http://www.eazel.com", "http://www.eazel.com", GNOME_VFS_URI_HIDE_NONE); |
---|
414 | test_uri_to_string ("http://www.eazel.com/", "http://www.eazel.com/", GNOME_VFS_URI_HIDE_NONE); |
---|
415 | test_uri_to_string ("http://www.eazel.com/dir", "http://www.eazel.com/dir", GNOME_VFS_URI_HIDE_NONE); |
---|
416 | test_uri_to_string ("http://www.eazel.com/dir/", "http://www.eazel.com/dir/", GNOME_VFS_URI_HIDE_NONE); |
---|
417 | test_uri_to_string ("http://yakk:womble@www.eazel.com:42/blah/", "http://yakk:womble@www.eazel.com:42/blah/", GNOME_VFS_URI_HIDE_NONE); |
---|
418 | |
---|
419 | test_uri_to_string ("http://yakk:womble@www.eazel.com:42/blah/", "http://:womble@www.eazel.com:42/blah/", GNOME_VFS_URI_HIDE_USER_NAME); |
---|
420 | test_uri_to_string ("FILE://", "file:", GNOME_VFS_URI_HIDE_NONE); |
---|
421 | |
---|
422 | test_uri_to_string ("file:///trash", "file:///trash", GNOME_VFS_URI_HIDE_NONE); |
---|
423 | test_uri_to_string ("file:///Users/mikef", "file:///Users/mikef", GNOME_VFS_URI_HIDE_NONE); |
---|
424 | test_uri_to_string ("/trash", "file:///trash", GNOME_VFS_URI_HIDE_NONE); |
---|
425 | |
---|
426 | /* test URI parts */ |
---|
427 | test_uri_part ("http://www.eazel.com:80/", "http", gnome_vfs_uri_get_scheme); |
---|
428 | test_uri_part ("http://www.eazel.com:80/", "www.eazel.com", gnome_vfs_uri_get_host_name); |
---|
429 | test_uri_part ("http://www.eazel.com:80/", "NULL", gnome_vfs_uri_get_user_name); |
---|
430 | test_uri_part ("http://www.eazel.com:80/", "NULL", gnome_vfs_uri_get_password); |
---|
431 | test_uri_part ("http://www.eazel.com:80/", "/", gnome_vfs_uri_get_path); |
---|
432 | |
---|
433 | test_uri_host_port ("http://www.eazel.com/", 0); |
---|
434 | test_uri_host_port ("http://www.eazel.com:80/", 80); |
---|
435 | |
---|
436 | /* Now--same thing w/o trailing / */ |
---|
437 | test_uri_part ("http://www.eazel.com:80", "http", gnome_vfs_uri_get_scheme); |
---|
438 | test_uri_part ("http://www.eazel.com:80", "www.eazel.com", gnome_vfs_uri_get_host_name); |
---|
439 | test_uri_part ("http://www.eazel.com:80", "NULL", gnome_vfs_uri_get_user_name); |
---|
440 | test_uri_part ("http://www.eazel.com:80", "NULL", gnome_vfs_uri_get_password); |
---|
441 | test_uri_part ("http://www.eazel.com:80", "/", gnome_vfs_uri_get_path); |
---|
442 | |
---|
443 | test_uri_host_port ("http://www.eazel.com", 0); |
---|
444 | test_uri_host_port ("http://www.eazel.com:80", 80); |
---|
445 | |
---|
446 | /* now same thing with all the parts */ |
---|
447 | test_uri_part ("http://yakk:womble@www.eazel.com:42/blah/", "http", gnome_vfs_uri_get_scheme ); |
---|
448 | test_uri_part ("http://yakk:womble@www.eazel.com:42/blah/", "www.eazel.com", gnome_vfs_uri_get_host_name ); |
---|
449 | test_uri_part ("http://yakk:womble@www.eazel.com:42/blah/", "yakk", gnome_vfs_uri_get_user_name ); |
---|
450 | test_uri_part ("http://yakk:womble@www.eazel.com:42/blah/", "womble", gnome_vfs_uri_get_password ); |
---|
451 | test_uri_host_port ("http://yakk:womble@www.eazel.com:42/blah/", 42); |
---|
452 | test_uri_part ("http://yakk:womble@www.eazel.com:42/blah/", "/blah/", gnome_vfs_uri_get_path ); |
---|
453 | |
---|
454 | test_uri_part ("http://foo.com/query?email=user@host", "/query?email=user@host", gnome_vfs_uri_get_path); |
---|
455 | test_uri_part ("http://user@host:42/query?email=user@host", "host", gnome_vfs_uri_get_host_name); |
---|
456 | test_uri_part ("http://@:/path", "NULL", gnome_vfs_uri_get_host_name); |
---|
457 | test_uri_part ("http://@::/path", "NULL", gnome_vfs_uri_get_host_name); |
---|
458 | test_uri_part ("http://::/path", "NULL", gnome_vfs_uri_get_host_name); |
---|
459 | test_uri_part ("http://@pass/path", "pass", gnome_vfs_uri_get_host_name); |
---|
460 | |
---|
461 | test_uri_parent ("", "URI NULL"); |
---|
462 | test_uri_parent ("http://www.eazel.com", "NULL"); |
---|
463 | test_uri_parent ("http://www.eazel.com/", "NULL"); |
---|
464 | test_uri_parent ("http://www.eazel.com/dir", "http://www.eazel.com/"); |
---|
465 | test_uri_parent ("http://www.eazel.com/dir/", "http://www.eazel.com/"); |
---|
466 | test_uri_parent ("http://yakk:womble@www.eazel.com:42/blah/", "http://yakk:womble@www.eazel.com:42/"); |
---|
467 | test_uri_parent ("file:", "NULL"); |
---|
468 | test_uri_parent ("http:", "NULL"); |
---|
469 | test_uri_parent ("file:/", "NULL"); |
---|
470 | test_uri_parent ("FILE://", "NULL"); |
---|
471 | test_uri_parent ("pipe:gnome-info2html2 as", "URI NULL"); |
---|
472 | test_uri_parent ("file:///my/document.html#fragment", "file:///my"); |
---|
473 | |
---|
474 | test_uri_is_parent_shallow ("file:///path", "file:///path/child", TRUE); |
---|
475 | test_uri_is_parent_shallow ("file:///bla", "file:///path/child", FALSE); |
---|
476 | test_uri_is_parent_shallow ("file:///path1/path2", "file:///path1/path2/child", TRUE); |
---|
477 | test_uri_is_parent_shallow ("ftp://foobar.com", "ftp://foobar.com/child", TRUE); |
---|
478 | test_uri_is_parent_shallow ("ftp://foobar.com/", "ftp://foobar.com/child", TRUE); |
---|
479 | test_uri_is_parent_shallow ("ftp://foobar.com/path", "ftp://foobar.com/path/child", TRUE); |
---|
480 | test_uri_is_parent_shallow ("file:///path1/path2", "file:///path1/path2/path3/path4/path5/child", FALSE); |
---|
481 | |
---|
482 | test_uri_is_parent_deep ("file:///path", "file:///path/child", TRUE); |
---|
483 | test_uri_is_parent_deep ("file:///path1/path2", "file:///path1/path2/child", TRUE); |
---|
484 | test_uri_is_parent_deep ("ftp://foobar.com", "ftp://foobar.com/child", TRUE); |
---|
485 | test_uri_is_parent_deep ("ftp://foobar.com/", "ftp://foobar.com/child", TRUE); |
---|
486 | test_uri_is_parent_deep ("ftp://foobar.com/path", "ftp://foobar.com/path/child", TRUE); |
---|
487 | |
---|
488 | test_uri_is_parent_deep ("file:///path", "file:///path/path1/child", TRUE); |
---|
489 | test_uri_is_parent_deep ("file:///path1/path2", "file:///path1/path2/path3/child", TRUE); |
---|
490 | test_uri_is_parent_deep ("file:///path1/path2", "file:///path1/path2/path3/path4/path5/child", TRUE); |
---|
491 | test_uri_is_parent_deep ("ftp://foobar.com", "ftp://foobar.com/path1/child", TRUE); |
---|
492 | test_uri_is_parent_deep ("ftp://foobar.com/", "ftp://foobar.com/path1/child", TRUE); |
---|
493 | test_uri_is_parent_deep ("ftp://foobar.com/path1", "ftp://foobar.com/path1/path2/child", TRUE); |
---|
494 | |
---|
495 | test_uri_has_parent ("", "URI NULL"); |
---|
496 | test_uri_has_parent ("http://www.eazel.com", "FALSE"); |
---|
497 | test_uri_has_parent ("http://www.eazel.com/", "FALSE"); |
---|
498 | test_uri_has_parent ("http://www.eazel.com/dir", "TRUE"); |
---|
499 | test_uri_has_parent ("http://www.eazel.com/dir/", "TRUE"); |
---|
500 | test_uri_has_parent ("http://yakk:womble@www.eazel.com:42/blah/", "TRUE"); |
---|
501 | test_uri_has_parent ("file:", "FALSE"); |
---|
502 | test_uri_has_parent ("http:", "FALSE"); |
---|
503 | test_uri_has_parent ("file:/", "FALSE"); |
---|
504 | test_uri_has_parent ("FILE://", "FALSE"); |
---|
505 | test_uri_has_parent ("pipe:gnome-info2html2 as", "URI NULL"); |
---|
506 | |
---|
507 | /* Test uri canonicalization */ |
---|
508 | test_uri_to_string ("/////", "file:///", GNOME_VFS_URI_HIDE_NONE); |
---|
509 | test_uri_to_string ("/.", "file:///", GNOME_VFS_URI_HIDE_NONE); |
---|
510 | test_uri_to_string ("/./.", "file:///", GNOME_VFS_URI_HIDE_NONE); |
---|
511 | test_uri_to_string ("/.///.", "file:///", GNOME_VFS_URI_HIDE_NONE); |
---|
512 | test_uri_to_string ("/a/..", "file:///", GNOME_VFS_URI_HIDE_NONE); |
---|
513 | test_uri_to_string ("/a/b/..", "file:///a", GNOME_VFS_URI_HIDE_NONE); |
---|
514 | test_uri_to_string ("/a/b//..", "file:///a", GNOME_VFS_URI_HIDE_NONE); |
---|
515 | test_uri_to_string ("/./a/b/..", "file:///a", GNOME_VFS_URI_HIDE_NONE); |
---|
516 | test_uri_to_string ("/a/./b/..", "file:///a", GNOME_VFS_URI_HIDE_NONE); |
---|
517 | test_uri_to_string ("/a/b/./..", "file:///a", GNOME_VFS_URI_HIDE_NONE); |
---|
518 | test_uri_to_string ("/a///b//..", "file:///a", GNOME_VFS_URI_HIDE_NONE); |
---|
519 | test_uri_to_string ("/a/b/../..", "file:///", GNOME_VFS_URI_HIDE_NONE); |
---|
520 | test_uri_to_string ("/a/b/c/../..", "file:///a", GNOME_VFS_URI_HIDE_NONE); |
---|
521 | test_uri_to_string ("/a/../b/..", "file:///", GNOME_VFS_URI_HIDE_NONE); |
---|
522 | test_uri_to_string ("/a/../b/../c", "file:///c", GNOME_VFS_URI_HIDE_NONE); |
---|
523 | test_uri_to_string ("/a/../b/../c", "file:///c", GNOME_VFS_URI_HIDE_NONE); |
---|
524 | |
---|
525 | test_make_canonical ("file:///%3F", "file:///%3F"); |
---|
526 | test_make_canonical ("file:///%78", "file:///x"); |
---|
527 | test_make_canonical ("file:///?", "file:///%3F"); |
---|
528 | test_make_canonical ("file:///&", "file:///%26"); |
---|
529 | test_make_canonical ("file:///x", "file:///x"); |
---|
530 | test_make_canonical ("glorb:///%3F", "glorb:///%3F"); |
---|
531 | test_make_canonical ("glorb:///%78", "glorb:///x"); |
---|
532 | test_make_canonical ("glorb:///?", "glorb:///%3F"); |
---|
533 | test_make_canonical ("glorb:///&", "glorb:///%26"); |
---|
534 | test_make_canonical ("glorb:///x", "glorb:///x"); |
---|
535 | test_make_canonical ("http:///%3F", "http:///%3F"); |
---|
536 | test_make_canonical ("http:///%78", "http:///x"); |
---|
537 | test_make_canonical ("http:///?", "http:///?"); |
---|
538 | test_make_canonical ("http:///&", "http:///&"); |
---|
539 | test_make_canonical ("http:///x", "http:///x"); |
---|
540 | test_make_canonical ("pipe:foo", "pipe:foo"); |
---|
541 | test_make_canonical ("eazel-services:///%3F", "eazel-services:///%3F"); |
---|
542 | test_make_canonical ("eazel-services:///%78", "eazel-services:///x"); |
---|
543 | test_make_canonical ("eazel-services:///?", "eazel-services:///?"); |
---|
544 | test_make_canonical ("eazel-services:///&", "eazel-services:///&"); |
---|
545 | test_make_canonical ("eazel-services:///x", "eazel-services:///x"); |
---|
546 | |
---|
547 | test_make_canonical ("eazel-install://anonymous@/product_name=gnucash", "eazel-install://anonymous@/product_name%3Dgnucash"); |
---|
548 | test_make_canonical ("eazel-install://:password@/product_name=gnucash", "eazel-install://:password@/product_name%3Dgnucash"); |
---|
549 | |
---|
550 | test_make_canonical ("http://www.eazel.com/query?email=email@eazel.com", "http://www.eazel.com/query?email=email@eazel.com"); |
---|
551 | |
---|
552 | /* test proper case-sensitivity handling */ |
---|
553 | test_make_canonical ("HTTP://WWW.ZOO.COM", "http://www.zoo.com"); |
---|
554 | test_make_canonical ("HTTP://WWW.ZOO.COM/", "http://www.zoo.com/"); |
---|
555 | test_make_canonical ("HTTP://WWW.ZOO.COM/ED", "http://www.zoo.com/ED"); |
---|
556 | test_uri_match ("http://www.zoo.com/ed", "HTTP://WWW.ZOO.COM/ed", TRUE); |
---|
557 | test_uri_match ("http://www.zoo.com/ed", "http://www.zoo.com/ED", FALSE); |
---|
558 | |
---|
559 | test_uri_match ("http://ed:ed@www.zoo.com/ed", "http://ed:ed@www.zoo.com/ed", TRUE); |
---|
560 | test_uri_match ("http://ed:ed@www.zoo.com/ed", "HTTP://ed:ed@www.zoo.com/ed", TRUE); |
---|
561 | test_uri_match ("http://ed:ed@www.zoo.com/ed", "http://ED:ed@www.zoo.com/ed", FALSE); |
---|
562 | test_uri_match ("http://ed:ed@www.zoo.com/ed", "http://ed:ED@www.zoo.com/ed", FALSE); |
---|
563 | test_uri_match ("http://ed:ed@www.zoo.com/ed", "http://ed:ed@WWW.zoo.com/ed", TRUE); |
---|
564 | test_uri_match ("http://ed:ed@www.zoo.com/ed", "http://ed:ed@www.ZOO.com/ed", TRUE); |
---|
565 | test_uri_match ("http://ed:ed@www.zoo.com/ed", "http://ed:ed@www.zoo.COM/ed", TRUE); |
---|
566 | test_uri_match ("http://ed:ed@www.zoo.com/ed", "http://ed:ed@www.zoo.com/ED", FALSE); |
---|
567 | |
---|
568 | test_uri_match ("/tmp/foo", "/tmp/foo", TRUE); |
---|
569 | test_uri_match ("file:/tmp/foo", "file:/TMP/foo", FALSE); |
---|
570 | test_uri_match ("/tmp/foo", "/TMP/foo", FALSE); |
---|
571 | |
---|
572 | /* Test chained uris */ |
---|
573 | test_uri_to_string ("/tmp/t.efs#http:///foobar/", "file:///tmp/t.efs#http:/foobar/", GNOME_VFS_URI_HIDE_NONE); |
---|
574 | test_uri_parent ("/tmp/t.efs#http:/", "file:///tmp/t.efs"); |
---|
575 | test_uri_to_string ("/tmp/t.efs#zip:/", "file:///tmp/t.efs#zip:/", GNOME_VFS_URI_HIDE_NONE); |
---|
576 | test_uri_parent ("/tmp/t.efs#zip:/", "file:///tmp/t.efs"); |
---|
577 | test_uri_to_string ("/tmp/t.efs#unknownmethod:/", "file:///tmp/t.efs", GNOME_VFS_URI_HIDE_NONE); |
---|
578 | |
---|
579 | /* Test fragment identifiers. */ |
---|
580 | test_uri_to_string ("/tmp/#junk", "file:///tmp/#junk", GNOME_VFS_URI_HIDE_NONE); |
---|
581 | test_uri_to_string ("/tmp/#junk", "file:///tmp/", GNOME_VFS_URI_HIDE_FRAGMENT_IDENTIFIER); |
---|
582 | test_uri_to_string ("/tmp/#junk#", "file:///tmp/#junk#", GNOME_VFS_URI_HIDE_NONE); |
---|
583 | test_uri_has_fragment_id ("/tmp/#junk", "junk"); |
---|
584 | test_uri_has_fragment_id ("/tmp/#junk#", "junk#"); |
---|
585 | |
---|
586 | /* test a escaping->unescaping round trip for funny characters */ |
---|
587 | test_file_path_to_uri_string ("/tmp/#backup_file#", "file:///tmp/#backup_file#", GNOME_VFS_URI_HIDE_NONE); |
---|
588 | test_file_path_to_uri_string ("/tmp/percent%percent", "file:///tmp/percent%percent", GNOME_VFS_URI_HIDE_NONE); |
---|
589 | |
---|
590 | /* FIXME bugzilla.eazel.com 4101: Why append a slash in this case, but not in the http://www.eazel.com case? */ |
---|
591 | test_uri_to_string ("http://www.eazel.com:80", "http://www.eazel.com:80/", GNOME_VFS_URI_HIDE_NONE); |
---|
592 | |
---|
593 | /* FIXME bugzilla.eazel.com 3829: illegal */ |
---|
594 | test_uri_to_string ("foo", "file:foo", GNOME_VFS_URI_HIDE_NONE); |
---|
595 | |
---|
596 | /* FIXME bugzilla.eazel.com 4102: illegal? */ |
---|
597 | test_uri_to_string ("file:foo", "file:foo", GNOME_VFS_URI_HIDE_NONE); |
---|
598 | |
---|
599 | /* FIXME bugzilla.eazel.com 3830: This turns a good path with |
---|
600 | * a redundant "/" in it into a completely different one. |
---|
601 | */ |
---|
602 | test_uri_to_string ("//foo", "file://foo", GNOME_VFS_URI_HIDE_NONE); |
---|
603 | |
---|
604 | /* FIXME bugzilla.eazel.com 7774: Are any of these right? |
---|
605 | * Perhaps they should all return NULL? |
---|
606 | */ |
---|
607 | test_uri_to_string (".", "file:", GNOME_VFS_URI_HIDE_NONE); |
---|
608 | test_uri_to_string ("./a", "file:a", GNOME_VFS_URI_HIDE_NONE); |
---|
609 | test_uri_to_string ("../a", "file:../a", GNOME_VFS_URI_HIDE_NONE); |
---|
610 | test_uri_to_string ("../a", "file:../a", GNOME_VFS_URI_HIDE_NONE); |
---|
611 | test_uri_to_string ("../../a", "file:a", GNOME_VFS_URI_HIDE_NONE); |
---|
612 | |
---|
613 | /* FIXME bugzilla.eazel.com 2801: Do we want GnomeVFSURI to |
---|
614 | * just refuse to deal with URIs that we don't have a module |
---|
615 | * for? |
---|
616 | */ |
---|
617 | test_uri_to_string ("glorp:", "NULL", GNOME_VFS_URI_HIDE_NONE); |
---|
618 | test_uri_parent ("glorp:", "URI NULL"); |
---|
619 | |
---|
620 | test_uri_to_string ("file:", "file:", GNOME_VFS_URI_HIDE_NONE); |
---|
621 | test_uri_to_string ("http:", "http:", GNOME_VFS_URI_HIDE_NONE); |
---|
622 | test_uri_to_string ("file:/", "file:///", GNOME_VFS_URI_HIDE_NONE); |
---|
623 | |
---|
624 | /* FIXME bugzilla.eazel.com 6022: At least for http, we don't |
---|
625 | * want to do canonicalizing after the ?. All these results |
---|
626 | * are presumably wrong because of that. |
---|
627 | */ |
---|
628 | test_uri_to_string ("http://www.eazel.com?///xxx", "http://www.eazel.com?/xxx", GNOME_VFS_URI_HIDE_NONE); |
---|
629 | test_uri_parent ("http://www.eazel.com?///xxx", "http://www.eazel.com?/"); |
---|
630 | test_uri_parent ("http://www.eazel.com/dir?xxx/yyy", "http://www.eazel.com/dir?xxx"); |
---|
631 | |
---|
632 | VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri (""), NULL); |
---|
633 | VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("/#"), NULL); |
---|
634 | VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("file:/path"), "/path"); |
---|
635 | VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("file://path"), NULL); |
---|
636 | VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("file:///path"), "/path"); |
---|
637 | VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("file:////path"), "//path"); |
---|
638 | VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("file:///my/document.html"), "/my/document.html"); |
---|
639 | VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("file:///my/document.html#fragment"), NULL); |
---|
640 | VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("file:///my/docu%20ment%23/path"), "/my/docu ment#/path"); |
---|
641 | VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("file:///my/docu%20ment%23/path/foo.html.gz#gunzip:///#fragment"), NULL); |
---|
642 | VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("/my/document.html"), NULL); |
---|
643 | VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("http://my/document.html"), NULL); |
---|
644 | |
---|
645 | /* Report to "make check" on whether it all worked or not. */ |
---|
646 | return at_least_one_test_failed ? EXIT_FAILURE : EXIT_SUCCESS; |
---|
647 | } |
---|