1 #include "first.h"
2
3 #undef NDEBUG
4 #include <assert.h>
5
6 #include "mod_evhost.c"
7
8 struct ttt {
9 const char *pattern;
10 size_t plen;
11 const char *expect;
12 size_t elen;
13 };
14
test_mod_evhost_build_doc_root_path_loop(struct ttt * tt,size_t nelts,buffer * authority,buffer * b,array * a)15 static void test_mod_evhost_build_doc_root_path_loop(struct ttt *tt, size_t nelts, buffer *authority, buffer *b, array *a) {
16 for (size_t i = 0; i < nelts; ++i) {
17 struct ttt *t = tt+i;
18 const buffer *path_pieces = mod_evhost_parse_pattern(t->pattern);
19 assert(NULL != path_pieces);
20 mod_evhost_build_doc_root_path(b, a, authority, path_pieces);
21 assert(buffer_eq_slen(b, t->expect, t->elen));
22 mod_evhost_free_path_pieces(path_pieces);
23 }
24 }
25
test_mod_evhost_build_doc_root_path(void)26 static void test_mod_evhost_build_doc_root_path(void) {
27 buffer *authority = buffer_init();
28 buffer *b = buffer_init();
29 array *a = array_init(0);
30 struct ttt tt1[] = { /* "host.example.org" */
31 /* correct pattern not using dot notation */
32 { CONST_STR_LEN("/web/%3/"),
33 CONST_STR_LEN("/web/host/") }
34 /* correct pattern using dot notation */
35 ,{ CONST_STR_LEN("/web/%{3.1}/%{3.2}/%3/"),
36 CONST_STR_LEN("/web/h/o/host/") }
37 /* other pattern 1 */
38 ,{ CONST_STR_LEN("/web/%{3.0}/"),
39 CONST_STR_LEN("/web/host/") }
40 /* other pattern 2 */
41 ,{ CONST_STR_LEN("/web/%3.\1/"),
42 CONST_STR_LEN("/web/host.\1/") }
43 ,{ CONST_STR_LEN("/web/%0/"),
44 CONST_STR_LEN("/web/example.org/") }
45 }, tt2[] = { /* "example" */
46 { CONST_STR_LEN("/web/%0"),
47 CONST_STR_LEN("/web/example/") }
48 }, tt3[] = { /* "[::1]:80" */
49 { CONST_STR_LEN("/web/%0"),
50 CONST_STR_LEN("/web/[::1]/") }
51 };
52
53 array_reset_data_strings(a);
54 buffer_copy_string_len(authority, CONST_STR_LEN("host.example.org"));
55 test_mod_evhost_build_doc_root_path_loop(tt1, sizeof(tt1)/sizeof(tt1[0]), authority, b, a);
56 array_reset_data_strings(a);
57 buffer_copy_string_len(authority, CONST_STR_LEN("example"));
58 test_mod_evhost_build_doc_root_path_loop(tt2, sizeof(tt2)/sizeof(tt2[0]), authority, b, a);
59 array_reset_data_strings(a);
60 buffer_copy_string_len(authority, CONST_STR_LEN("[::1]:80"));
61 test_mod_evhost_build_doc_root_path_loop(tt3, sizeof(tt3)/sizeof(tt3[0]), authority, b, a);
62
63 buffer_free(authority);
64 buffer_free(b);
65 array_free(a);
66 }
67
68 void test_mod_evhost (void);
test_mod_evhost(void)69 void test_mod_evhost (void)
70 {
71 test_mod_evhost_build_doc_root_path();
72 }
73