File: url.c

package info (click to toggle)
evolution-data-server 1.6.3-5etch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 59,384 kB
  • ctags: 43,218
  • sloc: ansic: 319,315; tcl: 30,499; xml: 19,166; sh: 18,776; perl: 11,529; cpp: 8,259; java: 7,653; makefile: 6,448; awk: 1,338; yacc: 1,103; sed: 772; cs: 505; lex: 134; asm: 14
file content (123 lines) | stat: -rw-r--r-- 3,450 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <config.h>

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <camel/camel-url.h>
#include <camel/camel-exception.h>

#include "camel-test.h"

char *base = "http://a/b/c/d;p?q#f";

struct {
	char *url_string, *result;
} tests[] = {
	{ "g:h", "g:h" },
	{ "g", "http://a/b/c/g" },
	{ "./g", "http://a/b/c/g" },
	{ "g/", "http://a/b/c/g/" },
	{ "/g", "http://a/g" },
	{ "//g", "http://g" },
	{ "?y", "http://a/b/c/d;p?y" },
	{ "g?y", "http://a/b/c/g?y" },
	{ "g?y/./x", "http://a/b/c/g?y/./x" },
	{ "#s", "http://a/b/c/d;p?q#s" },
	{ "g#s", "http://a/b/c/g#s" },
	{ "g#s/./x", "http://a/b/c/g#s/./x" },
	{ "g?y#s", "http://a/b/c/g?y#s" },
	{ ";x", "http://a/b/c/d;x" },
	{ "g;x", "http://a/b/c/g;x" },
	{ "g;x?y#s", "http://a/b/c/g;x?y#s" },
	{ ".", "http://a/b/c/" },
	{ "./", "http://a/b/c/" },
	{ "..", "http://a/b/" },
	{ "../", "http://a/b/" },
	{ "../g", "http://a/b/g" },
	{ "../..", "http://a/" },
	{ "../../", "http://a/" },
	{ "../../g", "http://a/g" },
	{ "", "http://a/b/c/d;p?q#f" },
	{ "../../../g", "http://a/../g" },
	{ "../../../../g", "http://a/../../g" },
	{ "/./g", "http://a/./g" },
	{ "/../g", "http://a/../g" },
	{ "g.", "http://a/b/c/g." },
	{ ".g", "http://a/b/c/.g" },
	{ "g..", "http://a/b/c/g.." },
	{ "..g", "http://a/b/c/..g" },
	{ "./../g", "http://a/b/g" },
	{ "./g/.", "http://a/b/c/g/" },
	{ "g/./h", "http://a/b/c/g/h" },
	{ "g/../h", "http://a/b/c/h" },
	{ "http:g", "http:g" },
	{ "http:", "http:" },

	/* (not from rfc 1808) */
	{ "sendmail:", "sendmail:" },
	{ "mbox:/var/mail/user", "mbox:/var/mail/user" },
	{ "pop://user@host", "pop://user@host" },
	{ "pop://user@host:99", "pop://user@host:99" },
	{ "pop://user:password@host", "pop://user:password@host" },
	{ "pop://user:password@host:99", "pop://user:password@host:99" },
	{ "pop://user;auth=APOP@host", "pop://user;auth=APOP@host" },
	{ "pop://user@host/;keep_on_server", "pop://user@host/;keep_on_server" },
	{ "pop://user@host/;keep_on_server=1", "pop://user@host/;keep_on_server=1" },
	{ "pop://us%65r@host", "pop://user@host" },
	{ "pop://us%40r@host", "pop://us%40r@host" },
	{ "pop://us%3ar@host", "pop://us%3ar@host" },
	{ "pop://us%2fr@host", "pop://us%2fr@host" }
};
int num_tests = sizeof (tests) / sizeof (tests[0]);

int
main (int argc, char **argv)
{
	CamelURL *base_url, *url;
	CamelException ex;
	char *url_string;
	int i;

	camel_test_init (argc, argv);

	camel_test_start ("URL parsing");

	camel_test_push ("base URL parsing");
	camel_exception_init (&ex);
	base_url = camel_url_new (base, &ex);
	if (!base_url) {
		camel_test_fail ("Could not parse %s: %s\n", base,
				 camel_exception_get_description (&ex));
	}
	camel_test_pull ();

	camel_test_push ("base URL unparsing");
	url_string = camel_url_to_string (base_url, 0);
	if (strcmp (url_string, base) != 0) {
		camel_test_fail ("URL <%s> unparses to <%s>\n",
				 base, url_string);
	}
	camel_test_pull ();
	g_free (url_string);

	for (i = 0; i < num_tests; i++) {
		camel_test_push ("<%s> + <%s> = <%s>?", base, tests[i].url_string, tests[i].result);
		url = camel_url_new_with_base (base_url, tests[i].url_string);
		if (!url) {
			camel_test_fail ("could not parse");
			camel_test_pull ();
			continue;
		}

		url_string = camel_url_to_string (url, 0);
		if (strcmp (url_string, tests[i].result) != 0)
			camel_test_fail ("got <%s>!", url_string);
		g_free (url_string);
		camel_test_pull ();
	}

	camel_test_end ();

	return 0;
}