1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
3 /* test-mime.c - Test program for the GNOME Virtual File System.
5 Copyright (C) 1999 Free Software Foundation
6 Copyright (C) 2000, 2001 Eazel, Inc.
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.
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.
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.
24 Darin Adler <darin@eazel.com>
25 Ian McKellar <yakk@yakk.net.au>
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>
38 #define TEST_ASSERT(expression, message) \
39 G_STMT_START { if (!(expression)) test_failed message; } G_STMT_END
42 stop_after_log (const char *domain, GLogLevelFlags level,
43 const char *message, gpointer data)
45 void (* saved_handler) (int);
47 g_log_default_handler (domain, level, message, data);
49 saved_handler = signal (SIGINT, SIG_IGN);
51 signal (SIGINT, saved_handler);
55 make_asserts_break (const char *domain)
59 (GLogLevelFlags) (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING),
60 stop_after_log, NULL);
63 static gboolean at_least_one_test_failed = FALSE;
66 test_failed (const char *format, ...)
71 va_start (arguments, format);
72 message = g_strdup_vprintf (format, arguments);
75 g_message ("test failed: %s", message);
76 at_least_one_test_failed = TRUE;
80 test_make_canonical_path (const char *input,
81 const char *expected_output)
85 output = gnome_vfs_make_path_name_canonical (input);
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);
95 const char* test_uris[][2] =
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"},
108 test_make_full_from_relative (const gchar* base, const gchar* relative,
109 const gchar* expected_result)
111 GnomeVFSURI *base_uri;
112 GnomeVFSURI *vfs_uri;
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);
123 gnome_vfs_uri_unref (base_uri);
124 gnome_vfs_uri_unref (vfs_uri);
130 test_uri_to_string (const char *input,
131 const char *expected_output,
132 GnomeVFSURIHideOptions hide_options)
137 uri = gnome_vfs_uri_new (input);
139 output = g_strdup ("NULL");
141 output = gnome_vfs_uri_to_string (uri, hide_options);
142 gnome_vfs_uri_unref (uri);
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);
154 test_make_canonical (const char *input,
155 const char *expected_output)
159 output = gnome_vfs_make_uri_canonical (input);
160 if (output == NULL) {
161 output = g_strdup ("NULL");
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);
173 test_uri_match (const char *uri_string_1, const char *uri_string_2, gboolean expected_result)
178 uri1 = gnome_vfs_uri_new (uri_string_1);
179 uri2 = gnome_vfs_uri_new (uri_string_2);
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");
188 gnome_vfs_uri_unref (uri2);
189 gnome_vfs_uri_unref (uri1);
193 test_file_path_to_uri_string (const char *input,
194 const char *expected_output,
195 GnomeVFSURIHideOptions hide_options)
197 GnomeVFSURI *uri, *resulting_uri;
199 char *unescaped_output;
201 uri = gnome_vfs_uri_new ("file:/");
202 resulting_uri = gnome_vfs_uri_append_path (uri, input);
203 gnome_vfs_uri_unref (uri);
205 output = gnome_vfs_uri_to_string (resulting_uri, hide_options);
206 gnome_vfs_uri_unref (resulting_uri);
208 unescaped_output = gnome_vfs_unescape_string (output, "/");
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);
216 g_free (unescaped_output);
220 test_uri_has_fragment_id (const char *input,
221 const char *expected_output)
226 uri = gnome_vfs_uri_new (input);
228 output = g_strdup ("NULL");
230 output = g_strdup (gnome_vfs_uri_get_fragment_identifier (uri));
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);
239 gnome_vfs_uri_unref (uri);
243 test_uri_extract_dirname (const char *input,
244 const char *expected_output)
249 uri = gnome_vfs_uri_new (input);
251 output = g_strdup ("NULL");
253 output = gnome_vfs_uri_extract_dirname (uri);
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);
262 gnome_vfs_uri_unref (uri);
266 test_uri_parent (const char *input,
267 const char *expected_output)
269 GnomeVFSURI *uri, *parent;
272 uri = gnome_vfs_uri_new (input);
274 output = g_strdup ("URI NULL");
276 parent = gnome_vfs_uri_get_parent (uri);
277 gnome_vfs_uri_unref (uri);
278 if (parent == NULL) {
279 output = g_strdup ("NULL");
281 output = gnome_vfs_uri_to_string (parent, GNOME_VFS_URI_HIDE_NONE);
282 gnome_vfs_uri_unref (parent);
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);
295 test_uri_has_parent (const char *input,
296 const char *expected_output)
302 uri = gnome_vfs_uri_new (input);
306 has = gnome_vfs_uri_has_parent (uri);
307 gnome_vfs_uri_unref (uri);
308 output = has ? "TRUE" : "FALSE";
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);
318 * Ensure that gnome_vfs_uri_{get_host_name,get_scheme,get_user_name,get_password}
319 * return expected results
322 test_uri_part (const char *input,
323 const char *expected_output,
324 const char *(*func_gnome_vfs_uri)(const GnomeVFSURI *)
330 uri = gnome_vfs_uri_new (input);
334 output = func_gnome_vfs_uri(uri);
335 if ( NULL == output ) {
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);
346 gnome_vfs_uri_unref (uri);
352 * Ensure that gnome_vfs_uri_get_host_port
353 * return expected results
356 test_uri_host_port (const char *input,
360 gboolean success = FALSE;
364 uri = gnome_vfs_uri_new (input);
366 port = gnome_vfs_uri_get_host_port(uri);
367 if (expected_port == port) {
369 gnome_vfs_uri_unref (uri);
374 test_failed ("gnome_vfs_uri_get_host_port (%s) resulted in %u instead of %u",
375 input, port, expected_port);
380 test_uri_is_parent_common (const char *parent, const char *item, gboolean deep, gboolean expected_result)
382 GnomeVFSURI *item_uri;
383 GnomeVFSURI *parent_uri;
386 item_uri = gnome_vfs_uri_new (item);
387 parent_uri = gnome_vfs_uri_new (parent);
389 result = gnome_vfs_uri_is_parent (parent_uri, item_uri, deep);
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");
396 gnome_vfs_uri_unref (item_uri);
397 gnome_vfs_uri_unref (parent_uri);
401 test_uri_is_parent_deep (const char *parent, const char *item, gboolean expected_result)
403 test_uri_is_parent_common (parent, item, TRUE, expected_result);
407 test_uri_is_parent_shallow (const char *parent, const char *item, gboolean expected_result)
409 test_uri_is_parent_common (parent, item, FALSE, expected_result);
412 #define VERIFY_STRING_RESULT(function, expected) \
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); \
423 main (int argc, char **argv)
427 make_asserts_break ("GLib");
428 make_asserts_break ("GnomeVFS");
430 /* Initialize the libraries we use. */
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 ("\\", "\\");
476 test_uri_to_string ("", "NULL", GNOME_VFS_URI_HIDE_NONE);
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);
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);
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);
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);
498 test_uri_host_port ("http://www.eazel.com/", 0);
499 test_uri_host_port ("http://www.eazel.com:80/", 80);
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);
508 test_uri_host_port ("http://www.eazel.com", 0);
509 test_uri_host_port ("http://www.eazel.com:80", 80);
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 );
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);
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");
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);
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);
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);
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");
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);
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");
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");
615 test_make_canonical ("http://www.eazel.com/query?email=email@eazel.com", "http://www.eazel.com/query?email=email@eazel.com");
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);
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);
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);
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);
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#");
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");
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);
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);
663 /* FIXME bugzilla.eazel.com 3829: illegal */
664 test_uri_to_string ("foo", "file:foo", GNOME_VFS_URI_HIDE_NONE);
666 /* FIXME bugzilla.eazel.com 4102: illegal? */
667 test_uri_to_string ("file:foo", "file:foo", GNOME_VFS_URI_HIDE_NONE);
669 /* FIXME bugzilla.eazel.com 3830: This turns a good path with
670 * a redundant "/" in it into a completely different one.
672 test_uri_to_string ("//foo", "file://foo", GNOME_VFS_URI_HIDE_NONE);
674 /* FIXME bugzilla.eazel.com 7774: Are any of these right?
675 * Perhaps they should all return NULL?
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);
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
687 test_uri_to_string ("glorp:", "NULL", GNOME_VFS_URI_HIDE_NONE);
688 test_uri_parent ("glorp:", "URI NULL");
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);
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.
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");
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);
715 /* Testing gnome_vfs_uri_make_full_from_relative */
716 /* (not an extensive testing, but a regression test */
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");
725 /* Report to "make check" on whether it all worked or not. */
726 return at_least_one_test_failed ? EXIT_FAILURE : EXIT_SUCCESS;