ftp://ftp.redhat.com/pub/redhat/linux/rawhide/SRPMS/SRPMS/gnome-vfs2-2.3.8-1.src.rpm
[gnome-vfs-httpcaptive.git] / test / test-uri.c
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 <glib/gmessages.h>
31 #include <glib/gstrfuncs.h>
32 #include <libgnomevfs/gnome-vfs-init.h>
33 #include <libgnomevfs/gnome-vfs-private-utils.h>
34 #include <libgnomevfs/gnome-vfs-utils.h>
35 #include <stdlib.h>
36 #include <string.h>
37
38 #define TEST_ASSERT(expression, message) \
39         G_STMT_START { if (!(expression)) test_failed message; } G_STMT_END
40
41 static void
42 stop_after_log (const char *domain, GLogLevelFlags level, 
43         const char *message, gpointer data)
44 {
45         void (* saved_handler) (int);
46         
47         g_log_default_handler (domain, level, message, data);
48
49         saved_handler = signal (SIGINT, SIG_IGN);
50         raise (SIGINT);
51         signal (SIGINT, saved_handler);
52 }
53
54 static void
55 make_asserts_break (const char *domain)
56 {
57         g_log_set_handler
58                 (domain, 
59                  (GLogLevelFlags) (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING),
60                  stop_after_log, NULL);
61 }
62
63 static gboolean at_least_one_test_failed = FALSE;
64
65 static void
66 test_failed (const char *format, ...)
67 {
68         va_list arguments;
69         char *message;
70
71         va_start (arguments, format);
72         message = g_strdup_vprintf (format, arguments);
73         va_end (arguments);
74
75         g_message ("test failed: %s", message);
76         at_least_one_test_failed = TRUE;
77 }
78
79 static void
80 test_make_canonical_path (const char *input,
81                           const char *expected_output)
82 {
83         char *output;
84
85         output = gnome_vfs_make_path_name_canonical (input);
86
87         if (strcmp (output, expected_output) != 0) {
88                 test_failed ("test_make_canonical_path (%s) resulted in %s instead of %s",
89                              input, output, expected_output);
90         }
91
92         g_free (output);
93 }
94
95 const char* test_uris[][2] = 
96 {
97         { "http://www.gnome.org/", "index.html" },
98         { "http://www.gnome.org/", "/index.html"},
99         { "http://www.gnome.org/", "/index.html"},
100         { "http://www.gnome.org", "index.html"},
101         { "http://www.gnome.org", "/index.html"},
102         { "http://www.gnome.org", "./index.html"},
103         {NULL, NULL}
104 };
105
106
107 static void
108 test_make_full_from_relative  (const gchar* base, const gchar* relative, 
109                                const gchar* expected_result)
110 {
111         GnomeVFSURI *base_uri;
112         GnomeVFSURI *vfs_uri;
113         gchar *str = NULL;
114
115         base_uri = gnome_vfs_uri_new (base);
116         vfs_uri = gnome_vfs_uri_resolve_relative (base_uri, relative);
117         str = gnome_vfs_uri_to_string (vfs_uri, GNOME_VFS_URI_HIDE_NONE);
118         if (expected_result != NULL) {
119                 if (strcmp (expected_result, str) != 0) {
120                         test_failed ("test_make_full_from_relative (%s, %s) resulted in %s instead of %s\n", base, relative, str, expected_result);
121                 }
122         }
123         gnome_vfs_uri_unref (base_uri);
124         gnome_vfs_uri_unref (vfs_uri);
125         g_free (str);
126 }
127
128
129 static void
130 test_uri_to_string (const char *input,
131                     const char *expected_output,
132                     GnomeVFSURIHideOptions hide_options)
133 {
134         GnomeVFSURI *uri;
135         char *output;
136
137         uri = gnome_vfs_uri_new (input);
138         if (uri == NULL) {
139                 output = g_strdup ("NULL");
140         } else {
141                 output = gnome_vfs_uri_to_string (uri, hide_options);
142                 gnome_vfs_uri_unref (uri);
143         }
144
145         if (strcmp (output, expected_output) != 0) {
146                 test_failed ("gnome_vfs_uri_to_string (%s, %d) resulted in %s instead of %s",
147                              input, hide_options, output, expected_output);
148         }
149
150         g_free (output);
151 }
152
153 static void
154 test_make_canonical (const char *input,
155                      const char *expected_output)
156 {
157         char *output;
158
159         output = gnome_vfs_make_uri_canonical (input);
160         if (output == NULL) {
161                 output = g_strdup ("NULL");
162         }
163
164         if (strcmp (output, expected_output) != 0) {
165                 test_failed ("test_make_canonical (%s) resulted in %s instead of %s",
166                              input, output, expected_output);
167         }
168
169         g_free (output);
170 }
171
172 static void
173 test_uri_match (const char *uri_string_1, const char *uri_string_2, gboolean expected_result)
174 {
175         GnomeVFSURI *uri1;
176         GnomeVFSURI *uri2;
177         
178         uri1 = gnome_vfs_uri_new (uri_string_1);
179         uri2 = gnome_vfs_uri_new (uri_string_2);
180         
181         if (gnome_vfs_uri_equal (uri1, uri2) != expected_result) {
182                 test_failed ("test_uri_match (%s, %s) resulted in a %s instead of %s",
183                         uri_string_1, uri_string_2,
184                         expected_result ? "mismatch" : "match",
185                         expected_result ? "match" : "mismatch");
186         }
187         
188         gnome_vfs_uri_unref (uri2);
189         gnome_vfs_uri_unref (uri1);
190 }
191
192 static void
193 test_file_path_to_uri_string (const char *input,
194                               const char *expected_output,
195                               GnomeVFSURIHideOptions hide_options)
196 {
197         GnomeVFSURI *uri, *resulting_uri;
198         char *output;
199         char *unescaped_output;
200
201         uri = gnome_vfs_uri_new ("file:/");
202         resulting_uri = gnome_vfs_uri_append_path (uri, input);
203         gnome_vfs_uri_unref (uri);
204
205         output = gnome_vfs_uri_to_string (resulting_uri, hide_options);
206         gnome_vfs_uri_unref (resulting_uri);
207
208         unescaped_output = gnome_vfs_unescape_string (output, "/");
209         g_free (output);
210
211         if (strcmp (unescaped_output, expected_output) != 0) {
212                 test_failed ("gnome_vfs_uri_to_string (%s, %d) resulted in %s instead of %s",
213                              input, hide_options, unescaped_output, expected_output);
214         }
215
216         g_free (unescaped_output);
217 }
218
219 static void
220 test_uri_has_fragment_id (const char *input,
221                           const char *expected_output)
222 {
223         GnomeVFSURI *uri;
224         char *output;
225         
226         uri = gnome_vfs_uri_new (input);
227         if (uri == NULL) {
228                 output = g_strdup ("NULL");
229         } else {
230                 output = g_strdup (gnome_vfs_uri_get_fragment_identifier (uri));
231         }
232
233         if (strcmp (output, expected_output) != 0) {
234                 test_failed ("test_uri_has_fragment_id (%s) resulted in %s instead of %s",
235                              input, output, expected_output);
236         }
237
238         g_free (output);
239         gnome_vfs_uri_unref (uri);
240 }
241
242 static void
243 test_uri_extract_dirname (const char *input,
244                           const char *expected_output)
245 {
246         GnomeVFSURI *uri;
247         char *output;
248
249         uri = gnome_vfs_uri_new (input);
250         if (uri == NULL) {
251                 output = g_strdup ("NULL");
252         } else {
253                 output = gnome_vfs_uri_extract_dirname (uri);
254         }
255
256         if (strcmp (output, expected_output) != 0) {
257                 test_failed ("test_uri_extract_dirname (%s) resulted in %s instead of %s",
258                              input, output, expected_output);
259         }
260
261         g_free (output);
262         gnome_vfs_uri_unref (uri);
263 }
264
265 static void
266 test_uri_parent (const char *input,
267                  const char *expected_output)
268 {
269         GnomeVFSURI *uri, *parent;
270         char *output;
271
272         uri = gnome_vfs_uri_new (input);
273         if (uri == NULL) {
274                 output = g_strdup ("URI NULL");
275         } else {
276                 parent = gnome_vfs_uri_get_parent (uri);
277                 gnome_vfs_uri_unref (uri);
278                 if (parent == NULL) {
279                         output = g_strdup ("NULL");
280                 } else {
281                         output = gnome_vfs_uri_to_string (parent, GNOME_VFS_URI_HIDE_NONE);
282                         gnome_vfs_uri_unref (parent);
283                 }
284         }
285
286         if (strcmp (output, expected_output) != 0) {
287                 test_failed ("gnome_vfs_uri_parent (%s) resulted in %s instead of %s",
288                              input, output, expected_output);
289         }
290
291         g_free (output);
292 }
293
294 static void
295 test_uri_has_parent (const char *input,
296                      const char *expected_output)
297 {
298         GnomeVFSURI *uri;
299         const char *output;
300         gboolean has;
301
302         uri = gnome_vfs_uri_new (input);
303         if (uri == NULL) {
304                 output = "URI NULL";
305         } else {
306                 has = gnome_vfs_uri_has_parent (uri);
307                 gnome_vfs_uri_unref (uri);
308                 output = has ? "TRUE" : "FALSE";
309         }
310
311         if (strcmp (output, expected_output) != 0) {
312                 test_failed ("gnome_vfs_uri_has_parent (%s) resulted in %s instead of %s",
313                              input, output, expected_output);
314         }
315 }
316
317 /*
318  * Ensure that gnome_vfs_uri_{get_host_name,get_scheme,get_user_name,get_password} 
319  * return expected results
320  */  
321 static void
322 test_uri_part (const char *input, 
323                const char *expected_output,
324                const char *(*func_gnome_vfs_uri)(const GnomeVFSURI *)
325                )
326 {
327         GnomeVFSURI *uri;
328         const char *output;
329
330         uri = gnome_vfs_uri_new (input);
331         if (NULL == uri) {
332                 output = "URI NULL";
333         } else {
334                 output = func_gnome_vfs_uri(uri);
335                 if ( NULL == output ) {
336                         output = "NULL";
337                 }
338         }
339
340         if (strcmp (output, expected_output) != 0) {
341                 test_failed ("gnome_vfs_uri_{?} (%s) resulted in %s instead of %s",
342                              input, output, expected_output);
343         }
344
345         if ( NULL != uri ) {
346                 gnome_vfs_uri_unref (uri);
347         }
348
349 }
350
351 /*
352  * Ensure that gnome_vfs_uri_get_host_port
353  * return expected results
354  */  
355 static void
356 test_uri_host_port (const char *input, 
357                     guint expected_port)
358 {
359         GnomeVFSURI *uri;
360         gboolean success = FALSE;
361         guint port;
362
363         port = 0;
364         uri = gnome_vfs_uri_new (input);
365         if (NULL != uri) {
366                 port = gnome_vfs_uri_get_host_port(uri);
367                 if (expected_port == port) {
368                         success = TRUE;
369                         gnome_vfs_uri_unref (uri);
370                 }
371         }
372
373         if (!success) {
374                 test_failed ("gnome_vfs_uri_get_host_port (%s) resulted in %u instead of %u",
375                              input, port, expected_port);
376         }
377 }
378
379 static void
380 test_uri_is_parent_common (const char *parent, const char *item, gboolean deep, gboolean expected_result)
381 {
382         GnomeVFSURI *item_uri;
383         GnomeVFSURI *parent_uri;
384         gboolean result;
385         
386         item_uri = gnome_vfs_uri_new (item);
387         parent_uri = gnome_vfs_uri_new (parent);
388         
389         result = gnome_vfs_uri_is_parent (parent_uri, item_uri, deep);
390         
391         if (result != expected_result) {
392                 test_failed ("gnome_vfs_uri_is_parent (%s, %s) resulted in \"%s\" instead of \"%s\"",
393                              parent, item, result ? "TRUE" : "FALSE", expected_result ? "TRUE" : "FALSE");
394         }
395
396         gnome_vfs_uri_unref (item_uri);
397         gnome_vfs_uri_unref (parent_uri);
398 }
399
400 static void
401 test_uri_is_parent_deep (const char *parent, const char *item, gboolean expected_result)
402 {
403         test_uri_is_parent_common (parent, item, TRUE, expected_result);
404 }
405
406 static void
407 test_uri_is_parent_shallow (const char *parent, const char *item, gboolean expected_result)
408 {
409         test_uri_is_parent_common (parent, item, FALSE, expected_result);
410 }
411
412 #define VERIFY_STRING_RESULT(function, expected) \
413         G_STMT_START {                                                                                  \
414                 char *result = function;                                                                \
415                 if (!((result == NULL && expected == NULL)                                              \
416                       || (result != NULL && expected != NULL && strcmp (result, (char *)expected) == 0))) {     \
417                         test_failed ("%s: returned '%s' expected '%s'", #function, result, expected);   \
418                 }                                                                                       \
419                 g_free (result);                                                                      \
420         } G_STMT_END
421
422 int
423 main (int argc, char **argv)
424 {
425         int i;
426
427         make_asserts_break ("GLib");
428         make_asserts_break ("GnomeVFS");
429
430         /* Initialize the libraries we use. */
431         gnome_vfs_init ();
432
433         /* Test the "make canonical" call for pathnames. */
434         test_make_canonical_path ("", "");
435         test_make_canonical_path ("/", "/");
436         test_make_canonical_path ("/.", "/");
437         test_make_canonical_path ("/./.", "/");
438         test_make_canonical_path ("/.//.", "/");
439         test_make_canonical_path ("/.///.", "/");
440         test_make_canonical_path ("a", "a");
441         test_make_canonical_path ("/a/b/..", "/a");
442         test_make_canonical_path ("a///", "a/");
443         test_make_canonical_path ("./a", "a");
444         test_make_canonical_path ("../a", "../a");
445         test_make_canonical_path ("..//a", "../a");
446         test_make_canonical_path ("a/.", "a");
447         test_make_canonical_path ("/a/.", "/a");
448         test_make_canonical_path ("/a/..", "/");
449         test_make_canonical_path ("a//.", "a");
450         test_make_canonical_path ("./a/.", "a");
451         test_make_canonical_path (".//a/.", "a");
452         test_make_canonical_path ("./a//.", "a");
453         test_make_canonical_path ("a/..", "");
454         test_make_canonical_path ("a//..", "");
455         test_make_canonical_path ("./a/..", "");
456         test_make_canonical_path (".//a/..", "");
457         test_make_canonical_path ("./a//..", "");
458         test_make_canonical_path (".//a//..", "");
459         test_make_canonical_path ("a/b/..", "a");
460         test_make_canonical_path ("./a/b/..", "a");
461         test_make_canonical_path ("/./a/b/..", "/a");
462         test_make_canonical_path ("/a/./b/..", "/a");
463         test_make_canonical_path ("/a/b/./..", "/a");
464         test_make_canonical_path ("/a/b/../.", "/a");
465         test_make_canonical_path ("a/b/../..", "");
466         test_make_canonical_path ("./a/b/../..", "");
467         test_make_canonical_path ("././a/b/../..", "");
468         test_make_canonical_path ("a/b/c/../..", "a");
469         test_make_canonical_path ("a/b/c/../../d", "a/d");
470         test_make_canonical_path ("a/b/../../d", "d");
471         test_make_canonical_path ("a/../../d", "../d");
472         test_make_canonical_path ("a/b/.././.././c", "c");
473         test_make_canonical_path ("a/.././.././b/c", "../b/c");
474         test_make_canonical_path ("\\", "\\");
475
476         test_uri_to_string ("", "NULL", GNOME_VFS_URI_HIDE_NONE);
477
478         test_uri_to_string ("http://www.eazel.com", "http://www.eazel.com", GNOME_VFS_URI_HIDE_NONE);
479         test_uri_to_string ("http://www.eazel.com/", "http://www.eazel.com/", GNOME_VFS_URI_HIDE_NONE);
480         test_uri_to_string ("http://www.eazel.com/dir", "http://www.eazel.com/dir", GNOME_VFS_URI_HIDE_NONE);
481         test_uri_to_string ("http://www.eazel.com/dir/", "http://www.eazel.com/dir/", GNOME_VFS_URI_HIDE_NONE);
482         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);
483
484         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);
485         test_uri_to_string ("FILE://", "file:", GNOME_VFS_URI_HIDE_NONE);
486
487         test_uri_to_string ("file:///trash", "file:///trash", GNOME_VFS_URI_HIDE_NONE);
488         test_uri_to_string ("file:///Users/mikef", "file:///Users/mikef", GNOME_VFS_URI_HIDE_NONE);
489         test_uri_to_string ("/trash", "file:///trash", GNOME_VFS_URI_HIDE_NONE);
490
491         /* test URI parts */
492         test_uri_part ("http://www.eazel.com:80/", "http", gnome_vfs_uri_get_scheme);
493         test_uri_part ("http://www.eazel.com:80/", "www.eazel.com", gnome_vfs_uri_get_host_name);
494         test_uri_part ("http://www.eazel.com:80/", "NULL", gnome_vfs_uri_get_user_name);
495         test_uri_part ("http://www.eazel.com:80/", "NULL", gnome_vfs_uri_get_password);
496         test_uri_part ("http://www.eazel.com:80/", "/", gnome_vfs_uri_get_path);
497
498         test_uri_host_port ("http://www.eazel.com/", 0);
499         test_uri_host_port ("http://www.eazel.com:80/", 80);
500
501         /* Now--same thing w/o trailing / */
502         test_uri_part ("http://www.eazel.com:80", "http", gnome_vfs_uri_get_scheme);
503         test_uri_part ("http://www.eazel.com:80", "www.eazel.com", gnome_vfs_uri_get_host_name);
504         test_uri_part ("http://www.eazel.com:80", "NULL", gnome_vfs_uri_get_user_name);
505         test_uri_part ("http://www.eazel.com:80", "NULL", gnome_vfs_uri_get_password);
506         test_uri_part ("http://www.eazel.com:80", "/", gnome_vfs_uri_get_path);
507
508         test_uri_host_port ("http://www.eazel.com", 0);
509         test_uri_host_port ("http://www.eazel.com:80", 80);
510
511         /* now same thing with all the parts */
512         test_uri_part ("http://yakk:womble@www.eazel.com:42/blah/", "http", gnome_vfs_uri_get_scheme );
513         test_uri_part ("http://yakk:womble@www.eazel.com:42/blah/", "www.eazel.com", gnome_vfs_uri_get_host_name );
514         test_uri_part ("http://yakk:womble@www.eazel.com:42/blah/", "yakk", gnome_vfs_uri_get_user_name );
515         test_uri_part ("http://yakk:womble@www.eazel.com:42/blah/", "womble", gnome_vfs_uri_get_password );
516         test_uri_host_port ("http://yakk:womble@www.eazel.com:42/blah/", 42);
517         test_uri_part ("http://yakk:womble@www.eazel.com:42/blah/", "/blah/", gnome_vfs_uri_get_path );
518
519         test_uri_part ("http://foo.com/query?email=user@host", "/query?email=user@host", gnome_vfs_uri_get_path);
520         test_uri_part ("http://user@host:42/query?email=user@host", "host", gnome_vfs_uri_get_host_name);
521         test_uri_part ("http://@:/path", "NULL", gnome_vfs_uri_get_host_name);
522         test_uri_part ("http://@::/path", "NULL", gnome_vfs_uri_get_host_name);
523         test_uri_part ("http://::/path", "NULL", gnome_vfs_uri_get_host_name);
524         test_uri_part ("http://@pass/path", "pass", gnome_vfs_uri_get_host_name);
525
526         test_uri_parent ("", "URI NULL");
527         test_uri_parent ("http://www.eazel.com", "NULL");
528         test_uri_parent ("http://www.eazel.com/", "NULL");
529         test_uri_parent ("http://www.eazel.com/dir", "http://www.eazel.com/");
530         test_uri_parent ("http://www.eazel.com/dir/", "http://www.eazel.com/");
531         test_uri_parent ("http://yakk:womble@www.eazel.com:42/blah/", "http://yakk:womble@www.eazel.com:42/");
532         test_uri_parent ("file:", "NULL");
533         test_uri_parent ("http:", "NULL");
534         test_uri_parent ("file:/", "NULL");
535         test_uri_parent ("FILE://", "NULL");
536         test_uri_parent ("pipe:gnome-info2html2 as", "URI NULL");
537         test_uri_parent ("file:///my/document.html#fragment", "file:///my");
538
539         test_uri_is_parent_shallow ("file:///path", "file:///path/child", TRUE);
540         test_uri_is_parent_shallow ("file:///bla", "file:///path/child", FALSE);
541         test_uri_is_parent_shallow ("file:///path1/path2", "file:///path1/path2/child", TRUE);
542         test_uri_is_parent_shallow ("ftp://foobar.com", "ftp://foobar.com/child", TRUE);
543         test_uri_is_parent_shallow ("ftp://foobar.com/", "ftp://foobar.com/child", TRUE);
544         test_uri_is_parent_shallow ("ftp://foobar.com/path", "ftp://foobar.com/path/child", TRUE);
545         test_uri_is_parent_shallow ("file:///path1/path2", "file:///path1/path2/path3/path4/path5/child", FALSE);
546
547         test_uri_is_parent_deep ("file:///path", "file:///path/child", TRUE);
548         test_uri_is_parent_deep ("file:///path1/path2", "file:///path1/path2/child", TRUE);
549         test_uri_is_parent_deep ("ftp://foobar.com", "ftp://foobar.com/child", TRUE);
550         test_uri_is_parent_deep ("ftp://foobar.com/", "ftp://foobar.com/child", TRUE);
551         test_uri_is_parent_deep ("ftp://foobar.com/path", "ftp://foobar.com/path/child", TRUE);
552
553         test_uri_is_parent_deep ("file:///path", "file:///path/path1/child", TRUE);
554         test_uri_is_parent_deep ("file:///path1/path2", "file:///path1/path2/path3/child", TRUE);
555         test_uri_is_parent_deep ("file:///path1/path2", "file:///path1/path2/path3/path4/path5/child", TRUE);
556         test_uri_is_parent_deep ("ftp://foobar.com", "ftp://foobar.com/path1/child", TRUE);
557         test_uri_is_parent_deep ("ftp://foobar.com/", "ftp://foobar.com/path1/child", TRUE);
558         test_uri_is_parent_deep ("ftp://foobar.com/path1", "ftp://foobar.com/path1/path2/child", TRUE);
559
560         test_uri_has_parent ("", "URI NULL");
561         test_uri_has_parent ("http://www.eazel.com", "FALSE");
562         test_uri_has_parent ("http://www.eazel.com/", "FALSE");
563         test_uri_has_parent ("http://www.eazel.com/dir", "TRUE");
564         test_uri_has_parent ("http://www.eazel.com/dir/", "TRUE");
565         test_uri_has_parent ("http://yakk:womble@www.eazel.com:42/blah/", "TRUE");
566         test_uri_has_parent ("file:", "FALSE");
567         test_uri_has_parent ("http:", "FALSE");
568         test_uri_has_parent ("file:/", "FALSE");
569         test_uri_has_parent ("FILE://", "FALSE");
570         test_uri_has_parent ("pipe:gnome-info2html2 as", "URI NULL");
571
572         /* Test uri canonicalization */
573         test_uri_to_string ("/////", "file:///", GNOME_VFS_URI_HIDE_NONE);
574         test_uri_to_string ("/.", "file:///", GNOME_VFS_URI_HIDE_NONE);
575         test_uri_to_string ("/./.", "file:///", GNOME_VFS_URI_HIDE_NONE);
576         test_uri_to_string ("/.///.", "file:///", GNOME_VFS_URI_HIDE_NONE);
577         test_uri_to_string ("/a/..", "file:///", GNOME_VFS_URI_HIDE_NONE);
578         test_uri_to_string ("/a/b/..", "file:///a", GNOME_VFS_URI_HIDE_NONE);
579         test_uri_to_string ("/a/b//..", "file:///a", GNOME_VFS_URI_HIDE_NONE);
580         test_uri_to_string ("/./a/b/..", "file:///a", GNOME_VFS_URI_HIDE_NONE);
581         test_uri_to_string ("/a/./b/..", "file:///a", GNOME_VFS_URI_HIDE_NONE);
582         test_uri_to_string ("/a/b/./..", "file:///a", GNOME_VFS_URI_HIDE_NONE);
583         test_uri_to_string ("/a///b//..", "file:///a", GNOME_VFS_URI_HIDE_NONE);
584         test_uri_to_string ("/a/b/../..", "file:///", GNOME_VFS_URI_HIDE_NONE);
585         test_uri_to_string ("/a/b/c/../..", "file:///a", GNOME_VFS_URI_HIDE_NONE);
586         test_uri_to_string ("/a/../b/..", "file:///", GNOME_VFS_URI_HIDE_NONE);
587         test_uri_to_string ("/a/../b/../c", "file:///c", GNOME_VFS_URI_HIDE_NONE);
588         test_uri_to_string ("/a/../b/../c", "file:///c", GNOME_VFS_URI_HIDE_NONE);
589
590         test_make_canonical ("file:///%3F", "file:///%3F");
591         test_make_canonical ("file:///%78", "file:///x");
592         test_make_canonical ("file:///?", "file:///%3F");
593         test_make_canonical ("file:///&", "file:///%26");
594         test_make_canonical ("file:///x", "file:///x");
595         test_make_canonical ("glorb:///%3F", "glorb:///%3F");
596         test_make_canonical ("glorb:///%78", "glorb:///x");
597         test_make_canonical ("glorb:///?", "glorb:///%3F");
598         test_make_canonical ("glorb:///&", "glorb:///%26");
599         test_make_canonical ("glorb:///x", "glorb:///x");
600         test_make_canonical ("http:///%3F", "http:///%3F");
601         test_make_canonical ("http:///%78", "http:///x");
602         test_make_canonical ("http:///?", "http:///?");
603         test_make_canonical ("http:///&", "http:///&");
604         test_make_canonical ("http:///x", "http:///x");
605         test_make_canonical ("pipe:foo", "pipe:foo");
606         test_make_canonical ("eazel-services:///%3F", "eazel-services:///%3F");
607         test_make_canonical ("eazel-services:///%78", "eazel-services:///x");
608         test_make_canonical ("eazel-services:///?", "eazel-services:///?");
609         test_make_canonical ("eazel-services:///&", "eazel-services:///&");
610         test_make_canonical ("eazel-services:///x", "eazel-services:///x");
611
612         test_make_canonical ("eazel-install://anonymous@/product_name=gnucash", "eazel-install://anonymous@/product_name%3Dgnucash");
613         test_make_canonical ("eazel-install://:password@/product_name=gnucash", "eazel-install://:password@/product_name%3Dgnucash");
614
615         test_make_canonical ("http://www.eazel.com/query?email=email@eazel.com", "http://www.eazel.com/query?email=email@eazel.com");
616
617         /* test proper case-sensitivity handling */
618         test_make_canonical ("HTTP://WWW.ZOO.COM", "http://www.zoo.com");
619         test_make_canonical ("HTTP://WWW.ZOO.COM/", "http://www.zoo.com/");
620         test_make_canonical ("HTTP://WWW.ZOO.COM/ED", "http://www.zoo.com/ED");
621         test_uri_match ("http://www.zoo.com/ed", "HTTP://WWW.ZOO.COM/ed", TRUE);
622         test_uri_match ("http://www.zoo.com/ed", "http://www.zoo.com/ED", FALSE);
623
624         test_uri_match ("http://ed:ed@www.zoo.com/ed", "http://ed:ed@www.zoo.com/ed", TRUE);
625         test_uri_match ("http://ed:ed@www.zoo.com/ed", "HTTP://ed:ed@www.zoo.com/ed", TRUE);
626         test_uri_match ("http://ed:ed@www.zoo.com/ed", "http://ED:ed@www.zoo.com/ed", FALSE);
627         test_uri_match ("http://ed:ed@www.zoo.com/ed", "http://ed:ED@www.zoo.com/ed", FALSE);
628         test_uri_match ("http://ed:ed@www.zoo.com/ed", "http://ed:ed@WWW.zoo.com/ed", TRUE);
629         test_uri_match ("http://ed:ed@www.zoo.com/ed", "http://ed:ed@www.ZOO.com/ed", TRUE);
630         test_uri_match ("http://ed:ed@www.zoo.com/ed", "http://ed:ed@www.zoo.COM/ed", TRUE);
631         test_uri_match ("http://ed:ed@www.zoo.com/ed", "http://ed:ed@www.zoo.com/ED", FALSE);
632
633         test_uri_match ("/tmp/foo", "/tmp/foo", TRUE);
634         test_uri_match ("file:/tmp/foo", "file:/TMP/foo", FALSE);
635         test_uri_match ("/tmp/foo", "/TMP/foo", FALSE);
636
637         /* Test chained uris */
638         test_uri_to_string ("/tmp/t.efs#http:///foobar/", "file:///tmp/t.efs#http:/foobar/", GNOME_VFS_URI_HIDE_NONE);
639         test_uri_parent ("/tmp/t.efs#http:/", "file:///tmp/t.efs");
640         test_uri_to_string ("/tmp/t.efs#zip:/", "file:///tmp/t.efs#zip:/", GNOME_VFS_URI_HIDE_NONE);
641         test_uri_parent ("/tmp/t.efs#zip:/", "file:///tmp/t.efs");
642         test_uri_to_string ("/tmp/t.efs#unknownmethod:/", "file:///tmp/t.efs", GNOME_VFS_URI_HIDE_NONE);
643
644         /* Test fragment identifiers. */
645         test_uri_to_string ("/tmp/#junk", "file:///tmp/#junk", GNOME_VFS_URI_HIDE_NONE);
646         test_uri_to_string ("/tmp/#junk", "file:///tmp/", GNOME_VFS_URI_HIDE_FRAGMENT_IDENTIFIER);
647         test_uri_to_string ("/tmp/#junk#", "file:///tmp/#junk#", GNOME_VFS_URI_HIDE_NONE);
648         test_uri_has_fragment_id ("/tmp/#junk", "junk");
649         test_uri_has_fragment_id ("/tmp/#junk#", "junk#");
650
651         /* Test gnome_vfs_uri_extract_dirname (). */
652         test_uri_extract_dirname ("/", "/");
653         test_uri_extract_dirname ("/usr", "/");
654         test_uri_extract_dirname ("/usr/bin", "/usr");
655
656         /* test a escaping->unescaping round trip for funny characters */
657         test_file_path_to_uri_string ("/tmp/#backup_file#", "file:///tmp/#backup_file#", GNOME_VFS_URI_HIDE_NONE);
658         test_file_path_to_uri_string ("/tmp/percent%percent", "file:///tmp/percent%percent", GNOME_VFS_URI_HIDE_NONE);
659
660         /* FIXME bugzilla.eazel.com 4101: Why append a slash in this case, but not in the http://www.eazel.com case? */
661         test_uri_to_string ("http://www.eazel.com:80", "http://www.eazel.com:80/", GNOME_VFS_URI_HIDE_NONE);
662
663         /* FIXME bugzilla.eazel.com 3829: illegal */
664         test_uri_to_string ("foo", "file:foo", GNOME_VFS_URI_HIDE_NONE);
665
666         /* FIXME bugzilla.eazel.com 4102: illegal? */
667         test_uri_to_string ("file:foo", "file:foo", GNOME_VFS_URI_HIDE_NONE);
668
669         /* FIXME bugzilla.eazel.com 3830: This turns a good path with
670          * a redundant "/" in it into a completely different one.
671          */
672         test_uri_to_string ("//foo", "file://foo", GNOME_VFS_URI_HIDE_NONE);
673
674         /* FIXME bugzilla.eazel.com 7774: Are any of these right?
675          * Perhaps they should all return NULL?
676          */
677         test_uri_to_string (".", "file:", GNOME_VFS_URI_HIDE_NONE);
678         test_uri_to_string ("./a", "file:a", GNOME_VFS_URI_HIDE_NONE);
679         test_uri_to_string ("../a", "file:../a", GNOME_VFS_URI_HIDE_NONE);
680         test_uri_to_string ("../a", "file:../a", GNOME_VFS_URI_HIDE_NONE);
681         test_uri_to_string ("../../a", "file:a", GNOME_VFS_URI_HIDE_NONE);
682
683         /* FIXME bugzilla.eazel.com 2801: Do we want GnomeVFSURI to
684          * just refuse to deal with URIs that we don't have a module
685          * for?
686          */
687         test_uri_to_string ("glorp:", "NULL", GNOME_VFS_URI_HIDE_NONE);
688         test_uri_parent ("glorp:", "URI NULL");
689
690         test_uri_to_string ("file:", "file:///", GNOME_VFS_URI_HIDE_NONE);
691         test_uri_to_string ("http:", "http:///", GNOME_VFS_URI_HIDE_NONE);
692         test_uri_to_string ("file:/", "file:///", GNOME_VFS_URI_HIDE_NONE);
693
694         /* FIXME bugzilla.eazel.com 6022: At least for http, we don't
695          * want to do canonicalizing after the ?. All these results
696          * are presumably wrong because of that.
697          */
698         test_uri_to_string ("http://www.eazel.com?///xxx", "http://www.eazel.com?/xxx", GNOME_VFS_URI_HIDE_NONE);
699         test_uri_parent ("http://www.eazel.com?///xxx", "http://www.eazel.com?/");
700         test_uri_parent ("http://www.eazel.com/dir?xxx/yyy", "http://www.eazel.com/dir?xxx");
701
702         VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri (""), NULL);
703         VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("/#"), NULL);
704         VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("file:/path"), "/path");
705         VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("file://path"), NULL);
706         VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("file:///path"), "/path");
707         VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("file:////path"), "//path");
708         VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("file:///my/document.html"), "/my/document.html");
709         VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("file:///my/document.html#fragment"), NULL);
710         VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("file:///my/docu%20ment%23/path"), "/my/docu ment#/path");
711         VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("file:///my/docu%20ment%23/path/foo.html.gz#gunzip:///#fragment"), NULL);
712         VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("/my/document.html"), NULL);
713         VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("http://my/document.html"), NULL);
714         
715         /* Testing gnome_vfs_uri_make_full_from_relative */
716         /* (not an extensive testing, but a regression test */
717         i = 0;
718         while (test_uris[i][0] != NULL) {
719                 test_make_full_from_relative (test_uris[i][0], test_uris[i][1],
720                                               "http://www.gnome.org/index.html");
721                 i++;
722         }
723
724
725         /* Report to "make check" on whether it all worked or not. */
726         return at_least_one_test_failed ? EXIT_FAILURE : EXIT_SUCCESS;
727 }