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