[security] encode quoting chars in HTML and XML
[lighttpd.git] / src / test_buffer.c
blobd565bd070a205e00af4001cb75c35cf9cf07ec8a
1 #include "first.h"
3 #include "buffer.h"
5 static void run_buffer_path_simplify(buffer *psrc, buffer *pdest, const char *in, size_t in_len, const char *out, size_t out_len) {
6 buffer_copy_string_len(psrc, in, in_len);
8 buffer_path_simplify(pdest, psrc);
10 if (!buffer_is_equal_string(pdest, out, out_len)) {
11 fprintf(stderr,
12 "%s.%d: buffer_path_simplify('%s') failed: expected '%s', got '%s'\n",
13 __FILE__,
14 __LINE__,
15 in,
16 out,
17 pdest->ptr ? pdest->ptr : "");
18 fflush(stderr);
19 abort();
20 } else {
21 fprintf(stdout,
22 "%s.%d: buffer_path_simplify('%s') succeeded: got '%s'\n",
23 __FILE__,
24 __LINE__,
25 in,
26 out);
28 if (psrc != pdest) buffer_copy_buffer(psrc, pdest);
29 buffer_path_simplify(pdest, psrc);
31 if (!buffer_is_equal_string(pdest, out, out_len)) {
32 fprintf(stderr,
33 "%s.%d: buffer_path_simplify('%s') failed - not idempotent: expected '%s', got '%s'\n",
34 __FILE__,
35 __LINE__,
36 out,
37 out,
38 pdest->ptr ? pdest->ptr : "");
39 fflush(stderr);
40 abort();
45 static void test_buffer_path_simplify_with(buffer *psrc, buffer *pdest) {
46 run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN(""), CONST_STR_LEN(""));
47 run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN(" "), CONST_STR_LEN("/"));
48 run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("/"), CONST_STR_LEN("/"));
49 run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("//"), CONST_STR_LEN("/"));
50 run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("abc"), CONST_STR_LEN("/abc"));
51 run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("abc//"), CONST_STR_LEN("/abc/"));
52 run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("abc/./xyz"), CONST_STR_LEN("/abc/xyz"));
53 run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("abc/.//xyz"), CONST_STR_LEN("/abc/xyz"));
54 run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("abc/../xyz"), CONST_STR_LEN("/xyz"));
55 run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("/abc/./xyz"), CONST_STR_LEN("/abc/xyz"));
56 run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("/abc//./xyz"), CONST_STR_LEN("/abc/xyz"));
57 run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("/abc/../xyz"), CONST_STR_LEN("/xyz"));
58 run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("abc/../xyz/."), CONST_STR_LEN("/xyz/"));
59 run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("/abc/../xyz/."), CONST_STR_LEN("/xyz/"));
60 run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("abc/./xyz/.."), CONST_STR_LEN("/abc/"));
61 run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("/abc/./xyz/.."), CONST_STR_LEN("/abc/"));
62 run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("./xyz/.."), CONST_STR_LEN("/"));
63 run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN(".//xyz/.."), CONST_STR_LEN("/"));
64 run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("/./xyz/.."), CONST_STR_LEN("/"));
65 run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN(".././xyz/.."), CONST_STR_LEN("/"));
66 run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("/.././xyz/.."), CONST_STR_LEN("/"));
69 static void test_buffer_path_simplify() {
70 buffer *psrc = buffer_init();
71 buffer *pdest = buffer_init();
73 /* test with using the same buffer and with using different buffers */
74 test_buffer_path_simplify_with(psrc, psrc);
75 test_buffer_path_simplify_with(pdest, psrc);
77 buffer_free(psrc);
78 buffer_free(pdest);
81 int main() {
82 test_buffer_path_simplify();
84 return 0;