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 | static int |
---|
413 | strcmp_allow_nulls (const char *s1, const char *s2) |
---|
414 | { |
---|
415 | const char *t1, *t2; |
---|
416 | |
---|
417 | t1 = (s1 == NULL ? "" : s1); |
---|
418 | t2 = (s2 == NULL ? "" : s2); |
---|
419 | |
---|
420 | return strcmp (t1, t2); |
---|
421 | } |
---|
422 | |
---|
423 | #define VERIFY_STRING_RESULT(function, expected) \ |
---|
424 | G_STMT_START { \ |
---|
425 | char *result = function; \ |
---|
426 | if (!((result == NULL && expected == NULL) \ |
---|
427 | || (strcmp_allow_nulls (result, (char *)expected) == 0))) { \ |
---|
428 | test_failed ("%s: returned '%s' expected '%s'", #function, result, expected); \ |
---|
429 | } \ |
---|
430 | g_free (result); \ |
---|
431 | } G_STMT_END |
---|
432 | |
---|
433 | int |
---|
434 | main (int argc, char **argv) |
---|
435 | { |
---|
436 | int i; |
---|
437 | |
---|
438 | make_asserts_break ("GLib"); |
---|
439 | make_asserts_break ("GnomeVFS"); |
---|
440 | |
---|
441 | /* Initialize the libraries we use. */ |
---|
442 | gnome_vfs_init (); |
---|
443 | |
---|
444 | /* Test the "make canonical" call for pathnames. */ |
---|
445 | test_make_canonical_path ("", ""); |
---|
446 | test_make_canonical_path ("/", "/"); |
---|
447 | test_make_canonical_path ("/.", "/"); |
---|
448 | test_make_canonical_path ("/./.", "/"); |
---|
449 | test_make_canonical_path ("/.//.", "/"); |
---|
450 | test_make_canonical_path ("/.///.", "/"); |
---|
451 | test_make_canonical_path ("a", "a"); |
---|
452 | test_make_canonical_path ("/a/b/..", "/a"); |
---|
453 | test_make_canonical_path ("a///", "a/"); |
---|
454 | test_make_canonical_path ("./a", "a"); |
---|
455 | test_make_canonical_path ("../a", "../a"); |
---|
456 | test_make_canonical_path ("..//a", "../a"); |
---|
457 | test_make_canonical_path ("a/.", "a"); |
---|
458 | test_make_canonical_path ("/a/.", "/a"); |
---|
459 | test_make_canonical_path ("/a/..", "/"); |
---|
460 | test_make_canonical_path ("a//.", "a"); |
---|
461 | test_make_canonical_path ("./a/.", "a"); |
---|
462 | test_make_canonical_path (".//a/.", "a"); |
---|
463 | test_make_canonical_path ("./a//.", "a"); |
---|
464 | test_make_canonical_path ("a/..", ""); |
---|
465 | test_make_canonical_path ("a//..", ""); |
---|
466 | test_make_canonical_path ("./a/..", ""); |
---|
467 | test_make_canonical_path (".//a/..", ""); |
---|
468 | test_make_canonical_path ("./a//..", ""); |
---|
469 | test_make_canonical_path (".//a//..", ""); |
---|
470 | test_make_canonical_path ("a/b/..", "a"); |
---|
471 | test_make_canonical_path ("./a/b/..", "a"); |
---|
472 | test_make_canonical_path ("/./a/b/..", "/a"); |
---|
473 | test_make_canonical_path ("/a/./b/..", "/a"); |
---|
474 | test_make_canonical_path ("/a/b/./..", "/a"); |
---|
475 | test_make_canonical_path ("/a/b/../.", "/a"); |
---|
476 | test_make_canonical_path ("a/b/../..", ""); |
---|
477 | test_make_canonical_path ("./a/b/../..", ""); |
---|
478 | test_make_canonical_path ("././a/b/../..", ""); |
---|
479 | test_make_canonical_path ("a/b/c/../..", "a"); |
---|
480 | test_make_canonical_path ("a/b/c/../../d", "a/d"); |
---|
481 | test_make_canonical_path ("a/b/../../d", "d"); |
---|
482 | test_make_canonical_path ("a/../../d", "../d"); |
---|
483 | test_make_canonical_path ("a/b/.././.././c", "c"); |
---|
484 | test_make_canonical_path ("a/.././.././b/c", "../b/c"); |
---|
485 | test_make_canonical_path ("\\", "\\"); |
---|
486 | |
---|
487 | test_uri_to_string ("", "NULL", GNOME_VFS_URI_HIDE_NONE); |
---|
488 | |
---|
489 | test_uri_to_string ("http://www.eazel.com", "http://www.eazel.com", GNOME_VFS_URI_HIDE_NONE); |
---|
490 | test_uri_to_string ("http://www.eazel.com/", "http://www.eazel.com/", GNOME_VFS_URI_HIDE_NONE); |
---|
491 | test_uri_to_string ("http://www.eazel.com/dir", "http://www.eazel.com/dir", GNOME_VFS_URI_HIDE_NONE); |
---|
492 | test_uri_to_string ("http://www.eazel.com/dir/", "http://www.eazel.com/dir/", GNOME_VFS_URI_HIDE_NONE); |
---|
493 | 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); |
---|
494 | |
---|
495 | 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); |
---|
496 | test_uri_to_string ("FILE://", "file:", GNOME_VFS_URI_HIDE_NONE); |
---|
497 | |
---|
498 | test_uri_to_string ("file:///trash", "file:///trash", GNOME_VFS_URI_HIDE_NONE); |
---|
499 | test_uri_to_string ("file:///Users/mikef", "file:///Users/mikef", GNOME_VFS_URI_HIDE_NONE); |
---|
500 | test_uri_to_string ("/trash", "file:///trash", GNOME_VFS_URI_HIDE_NONE); |
---|
501 | |
---|
502 | /* test URI parts */ |
---|
503 | test_uri_part ("http://www.eazel.com:80/", "http", gnome_vfs_uri_get_scheme); |
---|
504 | test_uri_part ("http://www.eazel.com:80/", "www.eazel.com", gnome_vfs_uri_get_host_name); |
---|
505 | test_uri_part ("http://www.eazel.com:80/", "NULL", gnome_vfs_uri_get_user_name); |
---|
506 | test_uri_part ("http://www.eazel.com:80/", "NULL", gnome_vfs_uri_get_password); |
---|
507 | test_uri_part ("http://www.eazel.com:80/", "/", gnome_vfs_uri_get_path); |
---|
508 | |
---|
509 | test_uri_host_port ("http://www.eazel.com/", 0); |
---|
510 | test_uri_host_port ("http://www.eazel.com:80/", 80); |
---|
511 | |
---|
512 | /* Now--same thing w/o trailing / */ |
---|
513 | test_uri_part ("http://www.eazel.com:80", "http", gnome_vfs_uri_get_scheme); |
---|
514 | test_uri_part ("http://www.eazel.com:80", "www.eazel.com", gnome_vfs_uri_get_host_name); |
---|
515 | test_uri_part ("http://www.eazel.com:80", "NULL", gnome_vfs_uri_get_user_name); |
---|
516 | test_uri_part ("http://www.eazel.com:80", "NULL", gnome_vfs_uri_get_password); |
---|
517 | test_uri_part ("http://www.eazel.com:80", "/", gnome_vfs_uri_get_path); |
---|
518 | |
---|
519 | test_uri_host_port ("http://www.eazel.com", 0); |
---|
520 | test_uri_host_port ("http://www.eazel.com:80", 80); |
---|
521 | |
---|
522 | /* now same thing with all the parts */ |
---|
523 | test_uri_part ("http://yakk:womble@www.eazel.com:42/blah/", "http", gnome_vfs_uri_get_scheme ); |
---|
524 | test_uri_part ("http://yakk:womble@www.eazel.com:42/blah/", "www.eazel.com", gnome_vfs_uri_get_host_name ); |
---|
525 | test_uri_part ("http://yakk:womble@www.eazel.com:42/blah/", "yakk", gnome_vfs_uri_get_user_name ); |
---|
526 | test_uri_part ("http://yakk:womble@www.eazel.com:42/blah/", "womble", gnome_vfs_uri_get_password ); |
---|
527 | test_uri_host_port ("http://yakk:womble@www.eazel.com:42/blah/", 42); |
---|
528 | test_uri_part ("http://yakk:womble@www.eazel.com:42/blah/", "/blah/", gnome_vfs_uri_get_path ); |
---|
529 | |
---|
530 | test_uri_part ("http://foo.com/query?email=user@host", "/query?email=user@host", gnome_vfs_uri_get_path); |
---|
531 | test_uri_part ("http://user@host:42/query?email=user@host", "host", gnome_vfs_uri_get_host_name); |
---|
532 | test_uri_part ("http://@:/path", "NULL", gnome_vfs_uri_get_host_name); |
---|
533 | test_uri_part ("http://@::/path", "NULL", gnome_vfs_uri_get_host_name); |
---|
534 | test_uri_part ("http://::/path", "NULL", gnome_vfs_uri_get_host_name); |
---|
535 | test_uri_part ("http://@pass/path", "pass", gnome_vfs_uri_get_host_name); |
---|
536 | |
---|
537 | test_uri_parent ("", "URI NULL"); |
---|
538 | test_uri_parent ("http://www.eazel.com", "NULL"); |
---|
539 | test_uri_parent ("http://www.eazel.com/", "NULL"); |
---|
540 | test_uri_parent ("http://www.eazel.com/dir", "http://www.eazel.com/"); |
---|
541 | test_uri_parent ("http://www.eazel.com/dir/", "http://www.eazel.com/"); |
---|
542 | test_uri_parent ("http://yakk:womble@www.eazel.com:42/blah/", "http://yakk:womble@www.eazel.com:42/"); |
---|
543 | test_uri_parent ("file:", "NULL"); |
---|
544 | test_uri_parent ("http:", "NULL"); |
---|
545 | test_uri_parent ("file:/", "NULL"); |
---|
546 | test_uri_parent ("FILE://", "NULL"); |
---|
547 | test_uri_parent ("pipe:gnome-info2html2 as", "URI NULL"); |
---|
548 | test_uri_parent ("file:///my/document.html#fragment", "file:///my"); |
---|
549 | |
---|
550 | test_uri_is_parent_shallow ("file:///path", "file:///path/child", TRUE); |
---|
551 | test_uri_is_parent_shallow ("file:///bla", "file:///path/child", FALSE); |
---|
552 | test_uri_is_parent_shallow ("file:///path1/path2", "file:///path1/path2/child", TRUE); |
---|
553 | test_uri_is_parent_shallow ("ftp://foobar.com", "ftp://foobar.com/child", TRUE); |
---|
554 | test_uri_is_parent_shallow ("ftp://foobar.com/", "ftp://foobar.com/child", TRUE); |
---|
555 | test_uri_is_parent_shallow ("ftp://foobar.com/path", "ftp://foobar.com/path/child", TRUE); |
---|
556 | test_uri_is_parent_shallow ("file:///path1/path2", "file:///path1/path2/path3/path4/path5/child", FALSE); |
---|
557 | |
---|
558 | test_uri_is_parent_deep ("file:///path", "file:///path/child", TRUE); |
---|
559 | test_uri_is_parent_deep ("file:///path1/path2", "file:///path1/path2/child", TRUE); |
---|
560 | test_uri_is_parent_deep ("ftp://foobar.com", "ftp://foobar.com/child", TRUE); |
---|
561 | test_uri_is_parent_deep ("ftp://foobar.com/", "ftp://foobar.com/child", TRUE); |
---|
562 | test_uri_is_parent_deep ("ftp://foobar.com/path", "ftp://foobar.com/path/child", TRUE); |
---|
563 | |
---|
564 | test_uri_is_parent_deep ("file:///path", "file:///path/path1/child", TRUE); |
---|
565 | test_uri_is_parent_deep ("file:///path1/path2", "file:///path1/path2/path3/child", TRUE); |
---|
566 | test_uri_is_parent_deep ("file:///path1/path2", "file:///path1/path2/path3/path4/path5/child", TRUE); |
---|
567 | test_uri_is_parent_deep ("ftp://foobar.com", "ftp://foobar.com/path1/child", TRUE); |
---|
568 | test_uri_is_parent_deep ("ftp://foobar.com/", "ftp://foobar.com/path1/child", TRUE); |
---|
569 | test_uri_is_parent_deep ("ftp://foobar.com/path1", "ftp://foobar.com/path1/path2/child", TRUE); |
---|
570 | |
---|
571 | test_uri_has_parent ("", "URI NULL"); |
---|
572 | test_uri_has_parent ("http://www.eazel.com", "FALSE"); |
---|
573 | test_uri_has_parent ("http://www.eazel.com/", "FALSE"); |
---|
574 | test_uri_has_parent ("http://www.eazel.com/dir", "TRUE"); |
---|
575 | test_uri_has_parent ("http://www.eazel.com/dir/", "TRUE"); |
---|
576 | test_uri_has_parent ("http://yakk:womble@www.eazel.com:42/blah/", "TRUE"); |
---|
577 | test_uri_has_parent ("file:", "FALSE"); |
---|
578 | test_uri_has_parent ("http:", "FALSE"); |
---|
579 | test_uri_has_parent ("file:/", "FALSE"); |
---|
580 | test_uri_has_parent ("FILE://", "FALSE"); |
---|
581 | test_uri_has_parent ("pipe:gnome-info2html2 as", "URI NULL"); |
---|
582 | |
---|
583 | /* Test uri canonicalization */ |
---|
584 | test_uri_to_string ("/////", "file:///", GNOME_VFS_URI_HIDE_NONE); |
---|
585 | test_uri_to_string ("/.", "file:///", GNOME_VFS_URI_HIDE_NONE); |
---|
586 | test_uri_to_string ("/./.", "file:///", GNOME_VFS_URI_HIDE_NONE); |
---|
587 | test_uri_to_string ("/.///.", "file:///", GNOME_VFS_URI_HIDE_NONE); |
---|
588 | test_uri_to_string ("/a/..", "file:///", GNOME_VFS_URI_HIDE_NONE); |
---|
589 | test_uri_to_string ("/a/b/..", "file:///a", GNOME_VFS_URI_HIDE_NONE); |
---|
590 | test_uri_to_string ("/a/b//..", "file:///a", GNOME_VFS_URI_HIDE_NONE); |
---|
591 | test_uri_to_string ("/./a/b/..", "file:///a", GNOME_VFS_URI_HIDE_NONE); |
---|
592 | test_uri_to_string ("/a/./b/..", "file:///a", GNOME_VFS_URI_HIDE_NONE); |
---|
593 | test_uri_to_string ("/a/b/./..", "file:///a", GNOME_VFS_URI_HIDE_NONE); |
---|
594 | test_uri_to_string ("/a///b//..", "file:///a", GNOME_VFS_URI_HIDE_NONE); |
---|
595 | test_uri_to_string ("/a/b/../..", "file:///", GNOME_VFS_URI_HIDE_NONE); |
---|
596 | test_uri_to_string ("/a/b/c/../..", "file:///a", GNOME_VFS_URI_HIDE_NONE); |
---|
597 | test_uri_to_string ("/a/../b/..", "file:///", GNOME_VFS_URI_HIDE_NONE); |
---|
598 | test_uri_to_string ("/a/../b/../c", "file:///c", GNOME_VFS_URI_HIDE_NONE); |
---|
599 | test_uri_to_string ("/a/../b/../c", "file:///c", GNOME_VFS_URI_HIDE_NONE); |
---|
600 | |
---|
601 | test_make_canonical ("file:///%3F", "file:///%3F"); |
---|
602 | test_make_canonical ("file:///%78", "file:///x"); |
---|
603 | test_make_canonical ("file:///?", "file:///%3F"); |
---|
604 | test_make_canonical ("file:///&", "file:///%26"); |
---|
605 | test_make_canonical ("file:///x", "file:///x"); |
---|
606 | test_make_canonical ("glorb:///%3F", "glorb:///%3F"); |
---|
607 | test_make_canonical ("glorb:///%78", "glorb:///x"); |
---|
608 | test_make_canonical ("glorb:///?", "glorb:///%3F"); |
---|
609 | test_make_canonical ("glorb:///&", "glorb:///%26"); |
---|
610 | test_make_canonical ("glorb:///x", "glorb:///x"); |
---|
611 | test_make_canonical ("http:///%3F", "http:///%3F"); |
---|
612 | test_make_canonical ("http:///%78", "http:///x"); |
---|
613 | test_make_canonical ("http:///?", "http:///?"); |
---|
614 | test_make_canonical ("http:///&", "http:///&"); |
---|
615 | test_make_canonical ("http:///x", "http:///x"); |
---|
616 | test_make_canonical ("pipe:foo", "pipe:foo"); |
---|
617 | test_make_canonical ("eazel-services:///%3F", "eazel-services:///%3F"); |
---|
618 | test_make_canonical ("eazel-services:///%78", "eazel-services:///x"); |
---|
619 | test_make_canonical ("eazel-services:///?", "eazel-services:///?"); |
---|
620 | test_make_canonical ("eazel-services:///&", "eazel-services:///&"); |
---|
621 | test_make_canonical ("eazel-services:///x", "eazel-services:///x"); |
---|
622 | |
---|
623 | test_make_canonical ("eazel-install://anonymous@/product_name=gnucash", "eazel-install://anonymous@/product_name%3Dgnucash"); |
---|
624 | test_make_canonical ("eazel-install://:password@/product_name=gnucash", "eazel-install://:password@/product_name%3Dgnucash"); |
---|
625 | |
---|
626 | test_make_canonical ("http://www.eazel.com/query?email=email@eazel.com", "http://www.eazel.com/query?email=email@eazel.com"); |
---|
627 | |
---|
628 | /* test proper case-sensitivity handling */ |
---|
629 | test_make_canonical ("HTTP://WWW.ZOO.COM", "http://www.zoo.com"); |
---|
630 | test_make_canonical ("HTTP://WWW.ZOO.COM/", "http://www.zoo.com/"); |
---|
631 | test_make_canonical ("HTTP://WWW.ZOO.COM/ED", "http://www.zoo.com/ED"); |
---|
632 | test_uri_match ("http://www.zoo.com/ed", "HTTP://WWW.ZOO.COM/ed", TRUE); |
---|
633 | test_uri_match ("http://www.zoo.com/ed", "http://www.zoo.com/ED", FALSE); |
---|
634 | |
---|
635 | test_uri_match ("http://ed:ed@www.zoo.com/ed", "http://ed:ed@www.zoo.com/ed", TRUE); |
---|
636 | test_uri_match ("http://ed:ed@www.zoo.com/ed", "HTTP://ed:ed@www.zoo.com/ed", TRUE); |
---|
637 | test_uri_match ("http://ed:ed@www.zoo.com/ed", "http://ED:ed@www.zoo.com/ed", FALSE); |
---|
638 | test_uri_match ("http://ed:ed@www.zoo.com/ed", "http://ed:ED@www.zoo.com/ed", FALSE); |
---|
639 | test_uri_match ("http://ed:ed@www.zoo.com/ed", "http://ed:ed@WWW.zoo.com/ed", TRUE); |
---|
640 | test_uri_match ("http://ed:ed@www.zoo.com/ed", "http://ed:ed@www.ZOO.com/ed", TRUE); |
---|
641 | test_uri_match ("http://ed:ed@www.zoo.com/ed", "http://ed:ed@www.zoo.COM/ed", TRUE); |
---|
642 | test_uri_match ("http://ed:ed@www.zoo.com/ed", "http://ed:ed@www.zoo.com/ED", FALSE); |
---|
643 | |
---|
644 | test_uri_match ("/tmp/foo", "/tmp/foo", TRUE); |
---|
645 | test_uri_match ("file:/tmp/foo", "file:/TMP/foo", FALSE); |
---|
646 | test_uri_match ("/tmp/foo", "/TMP/foo", FALSE); |
---|
647 | |
---|
648 | /* Test chained uris */ |
---|
649 | test_uri_to_string ("/tmp/t.efs#http:///foobar/", "file:///tmp/t.efs#http:/foobar/", GNOME_VFS_URI_HIDE_NONE); |
---|
650 | test_uri_parent ("/tmp/t.efs#http:/", "file:///tmp/t.efs"); |
---|
651 | test_uri_to_string ("/tmp/t.efs#gzip:/", "file:///tmp/t.efs#gzip:/", GNOME_VFS_URI_HIDE_NONE); |
---|
652 | test_uri_parent ("/tmp/t.efs#gzip:/", "file:///tmp/t.efs"); |
---|
653 | test_uri_to_string ("/tmp/t.efs#unknownmethod:/", "file:///tmp/t.efs", GNOME_VFS_URI_HIDE_NONE); |
---|
654 | |
---|
655 | /* Test fragment identifiers. */ |
---|
656 | test_uri_to_string ("/tmp/#junk", "file:///tmp/#junk", GNOME_VFS_URI_HIDE_NONE); |
---|
657 | test_uri_to_string ("/tmp/#junk", "file:///tmp/", GNOME_VFS_URI_HIDE_FRAGMENT_IDENTIFIER); |
---|
658 | test_uri_to_string ("/tmp/#junk#", "file:///tmp/#junk#", GNOME_VFS_URI_HIDE_NONE); |
---|
659 | test_uri_has_fragment_id ("/tmp/#junk", "junk"); |
---|
660 | test_uri_has_fragment_id ("/tmp/#junk#", "junk#"); |
---|
661 | |
---|
662 | /* Test gnome_vfs_uri_extract_dirname (). */ |
---|
663 | test_uri_extract_dirname ("/", "/"); |
---|
664 | test_uri_extract_dirname ("/usr", "/"); |
---|
665 | test_uri_extract_dirname ("/usr/bin", "/usr"); |
---|
666 | |
---|
667 | /* test a escaping->unescaping round trip for funny characters */ |
---|
668 | test_file_path_to_uri_string ("/tmp/#backup_file#", "file:///tmp/#backup_file#", GNOME_VFS_URI_HIDE_NONE); |
---|
669 | test_file_path_to_uri_string ("/tmp/percent%percent", "file:///tmp/percent%percent", GNOME_VFS_URI_HIDE_NONE); |
---|
670 | |
---|
671 | /* FIXME bugzilla.eazel.com 4101: Why append a slash in this case, but not in the http://www.eazel.com case? */ |
---|
672 | test_uri_to_string ("http://www.eazel.com:80", "http://www.eazel.com:80/", GNOME_VFS_URI_HIDE_NONE); |
---|
673 | |
---|
674 | /* FIXME bugzilla.eazel.com 3829: illegal */ |
---|
675 | test_uri_to_string ("foo", "file:foo", GNOME_VFS_URI_HIDE_NONE); |
---|
676 | |
---|
677 | /* FIXME bugzilla.eazel.com 4102: illegal? */ |
---|
678 | test_uri_to_string ("file:foo", "file:foo", GNOME_VFS_URI_HIDE_NONE); |
---|
679 | |
---|
680 | /* FIXME bugzilla.eazel.com 3830: This turns a good path with |
---|
681 | * a redundant "/" in it into a completely different one. |
---|
682 | */ |
---|
683 | test_uri_to_string ("//foo", "file://foo", GNOME_VFS_URI_HIDE_NONE); |
---|
684 | |
---|
685 | /* FIXME bugzilla.eazel.com 7774: Are any of these right? |
---|
686 | * Perhaps they should all return NULL? |
---|
687 | */ |
---|
688 | test_uri_to_string (".", "file:", GNOME_VFS_URI_HIDE_NONE); |
---|
689 | test_uri_to_string ("./a", "file:a", GNOME_VFS_URI_HIDE_NONE); |
---|
690 | test_uri_to_string ("../a", "file:../a", GNOME_VFS_URI_HIDE_NONE); |
---|
691 | test_uri_to_string ("../a", "file:../a", GNOME_VFS_URI_HIDE_NONE); |
---|
692 | test_uri_to_string ("../../a", "file:a", GNOME_VFS_URI_HIDE_NONE); |
---|
693 | |
---|
694 | /* FIXME bugzilla.eazel.com 2801: Do we want GnomeVFSURI to |
---|
695 | * just refuse to deal with URIs that we don't have a module |
---|
696 | * for? |
---|
697 | */ |
---|
698 | test_uri_to_string ("glorp:", "NULL", GNOME_VFS_URI_HIDE_NONE); |
---|
699 | test_uri_parent ("glorp:", "URI NULL"); |
---|
700 | |
---|
701 | test_uri_to_string ("file:", "file:///", GNOME_VFS_URI_HIDE_NONE); |
---|
702 | test_uri_to_string ("http:", "http:///", GNOME_VFS_URI_HIDE_NONE); |
---|
703 | test_uri_to_string ("file:/", "file:///", GNOME_VFS_URI_HIDE_NONE); |
---|
704 | |
---|
705 | /* FIXME bugzilla.eazel.com 6022: At least for http, we don't |
---|
706 | * want to do canonicalizing after the ?. All these results |
---|
707 | * are presumably wrong because of that. |
---|
708 | */ |
---|
709 | test_uri_to_string ("http://www.eazel.com?///xxx", "http://www.eazel.com?/xxx", GNOME_VFS_URI_HIDE_NONE); |
---|
710 | test_uri_parent ("http://www.eazel.com?///xxx", "http://www.eazel.com?/"); |
---|
711 | test_uri_parent ("http://www.eazel.com/dir?xxx/yyy", "http://www.eazel.com/dir?xxx"); |
---|
712 | |
---|
713 | VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri (""), NULL); |
---|
714 | VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("/#"), NULL); |
---|
715 | VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("file:/path"), "/path"); |
---|
716 | VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("file://path"), NULL); |
---|
717 | VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("file:///path"), "/path"); |
---|
718 | VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("file:////path"), "//path"); |
---|
719 | VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("file:///my/document.html"), "/my/document.html"); |
---|
720 | VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("file:///my/document.html#fragment"), NULL); |
---|
721 | VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("file:///my/docu%20ment%23/path"), "/my/docu ment#/path"); |
---|
722 | VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("file:///my/docu%20ment%23/path/foo.html.gz#gunzip:///#fragment"), NULL); |
---|
723 | VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("/my/document.html"), NULL); |
---|
724 | VERIFY_STRING_RESULT (gnome_vfs_get_local_path_from_uri ("http://my/document.html"), NULL); |
---|
725 | |
---|
726 | /* Testing gnome_vfs_uri_make_full_from_relative */ |
---|
727 | /* (not an extensive testing, but a regression test */ |
---|
728 | i = 0; |
---|
729 | while (test_uris[i][0] != NULL) { |
---|
730 | test_make_full_from_relative (test_uris[i][0], test_uris[i][1], |
---|
731 | "http://www.gnome.org/index.html"); |
---|
732 | i++; |
---|
733 | } |
---|
734 | |
---|
735 | |
---|
736 | /* Report to "make check" on whether it all worked or not. */ |
---|
737 | return at_least_one_test_failed ? EXIT_FAILURE : EXIT_SUCCESS; |
---|
738 | } |
---|