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