Implement straightforward GET test.
[darkhttpd] / devel / test_make_safe_uri.c
1 #define main _main_disabled_
2 #include "../darkhttpd.c"
3 #undef main
4
5 static void
6 test(const char *input, const char *expected)
7 {
8 char *tmp = xstrdup(input);
9 char *out = make_safe_url(tmp);
10
11 if (expected == NULL) {
12 if (out == NULL)
13 printf("PASS: \"%s\" is unsafe\n", input);
14 else
15 printf("FAIL: \"%s\" is unsafe, but got \"%s\"\n",
16 input, out);
17 }
18 else if (out == NULL)
19 printf("FAIL: \"%s\" should become \"%s\", got unsafe\n",
20 input, expected);
21 else if (strcmp(out, expected) == 0)
22 printf("PASS: \"%s\" => \"%s\"\n", input, out);
23 else
24 printf("FAIL: \"%s\" => \"%s\", expecting \"%s\"\n",
25 input, out, expected);
26 free(tmp);
27 }
28
29 static char const *tests[] = {
30 "/", "/",
31 "/.", "/",
32 "/./", "/",
33 "/../", NULL,
34 "/abc", "/abc",
35 "/abc/", "/abc/",
36 "/abc/.", "/abc",
37 "/abc/./", "/abc/",
38 "/abc/..", "/",
39 "/abc/../", "/",
40 "/abc/../def", "/def",
41 "/abc/../def/", "/def/",
42 "/abc/../def/..", "/",
43 "/abc/../def/../", "/",
44 "/abc/../def/../../", NULL,
45 "/abc/../def/.././", "/",
46 "/abc/../def/.././../", NULL,
47 "/a/b/c/../../d/", "/a/d/",
48 "/a/b/../../../c", NULL,
49 /* don't forget consolidate_slashes */
50 "//a///b////c/////", "/a/b/c/",
51 NULL
52 };
53
54 int
55 main(void)
56 {
57 const char **curr = tests;
58
59 while (curr[0] != NULL) {
60 test(curr[0], curr[1]);
61 curr += 2;
62 }
63
64 return 0;
65 }
66 /* vim:set tabstop=4 shiftwidth=4 expandtab tw=78: */