aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/test_str_token.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/test_str_token.c')
-rw-r--r--src/microhttpd/test_str_token.c127
1 files changed, 65 insertions, 62 deletions
diff --git a/src/microhttpd/test_str_token.c b/src/microhttpd/test_str_token.c
index 15f3f406..0baca53d 100644
--- a/src/microhttpd/test_str_token.c
+++ b/src/microhttpd/test_str_token.c
@@ -29,90 +29,93 @@
29 29
30 30
31static int 31static int
32expect_found_n(const char *str, const char *token, size_t token_len) 32expect_found_n (const char *str, const char *token, size_t token_len)
33{ 33{
34 if (!MHD_str_has_token_caseless_(str, token, token_len)) 34 if (! MHD_str_has_token_caseless_ (str, token, token_len))
35 { 35 {
36 fprintf(stderr, "MHD_str_has_token_caseless_() FAILED:\n\tMHD_str_has_token_caseless_(%s, %s, %lu) return false\n", 36 fprintf (stderr,
37 str, token, (unsigned long) token_len); 37 "MHD_str_has_token_caseless_() FAILED:\n\tMHD_str_has_token_caseless_(%s, %s, %lu) return false\n",
38 return 1; 38 str, token, (unsigned long) token_len);
39 } 39 return 1;
40 }
40 return 0; 41 return 0;
41} 42}
42 43
43#define expect_found(s,t) expect_found_n((s),(t),MHD_STATICSTR_LEN_(t)) 44#define expect_found(s,t) expect_found_n ((s),(t),MHD_STATICSTR_LEN_ (t))
44 45
45static int 46static int
46expect_not_found_n(const char *str, const char *token, size_t token_len) 47expect_not_found_n (const char *str, const char *token, size_t token_len)
47{ 48{
48 if (MHD_str_has_token_caseless_(str, token, token_len)) 49 if (MHD_str_has_token_caseless_ (str, token, token_len))
49 { 50 {
50 fprintf(stderr, "MHD_str_has_token_caseless_() FAILED:\n\tMHD_str_has_token_caseless_(%s, %s, %lu) return true\n", 51 fprintf (stderr,
51 str, token, (unsigned long) token_len); 52 "MHD_str_has_token_caseless_() FAILED:\n\tMHD_str_has_token_caseless_(%s, %s, %lu) return true\n",
52 return 1; 53 str, token, (unsigned long) token_len);
53 } 54 return 1;
55 }
54 return 0; 56 return 0;
55} 57}
56 58
57#define expect_not_found(s,t) expect_not_found_n((s),(t),MHD_STATICSTR_LEN_(t)) 59#define expect_not_found(s,t) expect_not_found_n ((s),(t),MHD_STATICSTR_LEN_ ( \
60 t))
58 61
59int check_match(void) 62int check_match (void)
60{ 63{
61 int errcount = 0; 64 int errcount = 0;
62 errcount += expect_found("string", "string"); 65 errcount += expect_found ("string", "string");
63 errcount += expect_found("String", "string"); 66 errcount += expect_found ("String", "string");
64 errcount += expect_found("string", "String"); 67 errcount += expect_found ("string", "String");
65 errcount += expect_found("strinG", "String"); 68 errcount += expect_found ("strinG", "String");
66 errcount += expect_found("\t strinG", "String"); 69 errcount += expect_found ("\t strinG", "String");
67 errcount += expect_found("strinG\t ", "String"); 70 errcount += expect_found ("strinG\t ", "String");
68 errcount += expect_found(" \t tOkEn ", "toKEN"); 71 errcount += expect_found (" \t tOkEn ", "toKEN");
69 errcount += expect_found("not token\t, tOkEn ", "toKEN"); 72 errcount += expect_found ("not token\t, tOkEn ", "toKEN");
70 errcount += expect_found("not token,\t tOkEn, more token", "toKEN"); 73 errcount += expect_found ("not token,\t tOkEn, more token", "toKEN");
71 errcount += expect_found("not token,\t tOkEn\t, more token", "toKEN"); 74 errcount += expect_found ("not token,\t tOkEn\t, more token", "toKEN");
72 errcount += expect_found(",,,,,,test,,,,", "TESt"); 75 errcount += expect_found (",,,,,,test,,,,", "TESt");
73 errcount += expect_found(",,,,,\t,test,,,,", "TESt"); 76 errcount += expect_found (",,,,,\t,test,,,,", "TESt");
74 errcount += expect_found(",,,,,,test, ,,,", "TESt"); 77 errcount += expect_found (",,,,,,test, ,,,", "TESt");
75 errcount += expect_found(",,,,,, test,,,,", "TESt"); 78 errcount += expect_found (",,,,,, test,,,,", "TESt");
76 errcount += expect_found(",,,,,, test not,test,,", "TESt"); 79 errcount += expect_found (",,,,,, test not,test,,", "TESt");
77 errcount += expect_found(",,,,,, test not,,test,,", "TESt"); 80 errcount += expect_found (",,,,,, test not,,test,,", "TESt");
78 errcount += expect_found(",,,,,, test not ,test,,", "TESt"); 81 errcount += expect_found (",,,,,, test not ,test,,", "TESt");
79 errcount += expect_found(",,,,,, test", "TESt"); 82 errcount += expect_found (",,,,,, test", "TESt");
80 errcount += expect_found(",,,,,, test ", "TESt"); 83 errcount += expect_found (",,,,,, test ", "TESt");
81 errcount += expect_found("no test,,,,,, test ", "TESt"); 84 errcount += expect_found ("no test,,,,,, test ", "TESt");
82 return errcount; 85 return errcount;
83} 86}
84 87
85int check_not_match(void) 88int check_not_match (void)
86{ 89{
87 int errcount = 0; 90 int errcount = 0;
88 errcount += expect_not_found("strin", "string"); 91 errcount += expect_not_found ("strin", "string");
89 errcount += expect_not_found("Stringer", "string"); 92 errcount += expect_not_found ("Stringer", "string");
90 errcount += expect_not_found("sstring", "String"); 93 errcount += expect_not_found ("sstring", "String");
91 errcount += expect_not_found("string", "Strin"); 94 errcount += expect_not_found ("string", "Strin");
92 errcount += expect_not_found("\t( strinG", "String"); 95 errcount += expect_not_found ("\t( strinG", "String");
93 errcount += expect_not_found(")strinG\t ", "String"); 96 errcount += expect_not_found (")strinG\t ", "String");
94 errcount += expect_not_found(" \t tOkEn t ", "toKEN"); 97 errcount += expect_not_found (" \t tOkEn t ", "toKEN");
95 errcount += expect_not_found("not token\t, tOkEner ", "toKEN"); 98 errcount += expect_not_found ("not token\t, tOkEner ", "toKEN");
96 errcount += expect_not_found("not token,\t tOkEns, more token", "toKEN"); 99 errcount += expect_not_found ("not token,\t tOkEns, more token", "toKEN");
97 errcount += expect_not_found("not token,\t tOkEns\t, more token", "toKEN"); 100 errcount += expect_not_found ("not token,\t tOkEns\t, more token", "toKEN");
98 errcount += expect_not_found(",,,,,,testing,,,,", "TESt"); 101 errcount += expect_not_found (",,,,,,testing,,,,", "TESt");
99 errcount += expect_not_found(",,,,,\t,test,,,,", "TESting"); 102 errcount += expect_not_found (",,,,,\t,test,,,,", "TESting");
100 errcount += expect_not_found("tests,,,,,,quest, ,,,", "TESt"); 103 errcount += expect_not_found ("tests,,,,,,quest, ,,,", "TESt");
101 errcount += expect_not_found(",,,,,, testы,,,,", "TESt"); 104 errcount += expect_not_found (",,,,,, testы,,,,", "TESt");
102 errcount += expect_not_found(",,,,,, test not,хtest,,", "TESt"); 105 errcount += expect_not_found (",,,,,, test not,хtest,,", "TESt");
103 errcount += expect_not_found("testing,,,,,, test not,,test2,,", "TESt"); 106 errcount += expect_not_found ("testing,,,,,, test not,,test2,,", "TESt");
104 errcount += expect_not_found(",testi,,,,, test not ,test,,", "TESting"); 107 errcount += expect_not_found (",testi,,,,, test not ,test,,", "TESting");
105 errcount += expect_not_found(",,,,,,2 test", "TESt"); 108 errcount += expect_not_found (",,,,,,2 test", "TESt");
106 errcount += expect_not_found(",,,,,,test test ", "test"); 109 errcount += expect_not_found (",,,,,,test test ", "test");
107 errcount += expect_not_found("no test,,,,,, test test", "test"); 110 errcount += expect_not_found ("no test,,,,,, test test", "test");
108 return errcount; 111 return errcount;
109} 112}
110 113
111int main(int argc, char * argv[]) 114int main (int argc, char *argv[])
112{ 115{
113 int errcount = 0; 116 int errcount = 0;
114 (void)argc; (void)argv; /* Unused. Silent compiler warning. */ 117 (void) argc; (void) argv; /* Unused. Silent compiler warning. */
115 errcount += check_match(); 118 errcount += check_match ();
116 errcount += check_not_match(); 119 errcount += check_not_match ();
117 return errcount == 0 ? 0 : 1; 120 return errcount == 0 ? 0 : 1;
118} 121}