aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/test_str_token.c
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2017-05-15 20:35:15 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2017-05-15 20:37:14 +0300
commit9e191bf65f498e56330c1d7f1213ef6c7b23e07d (patch)
tree1fb54be70825642c849d4890d6682eb3978680dd /src/microhttpd/test_str_token.c
parent64b53a4e7c904a7dd9ce03e38bae75edd06902b5 (diff)
downloadlibmicrohttpd-9e191bf65f498e56330c1d7f1213ef6c7b23e07d.tar.gz
libmicrohttpd-9e191bf65f498e56330c1d7f1213ef6c7b23e07d.zip
Added file missing in e93439da71e027cafe5b2788a997cbfc85d193c8
Diffstat (limited to 'src/microhttpd/test_str_token.c')
-rw-r--r--src/microhttpd/test_str_token.c117
1 files changed, 117 insertions, 0 deletions
diff --git a/src/microhttpd/test_str_token.c b/src/microhttpd/test_str_token.c
new file mode 100644
index 00000000..464cc7a5
--- /dev/null
+++ b/src/microhttpd/test_str_token.c
@@ -0,0 +1,117 @@
1/*
2 This file is part of libmicrohttpd
3 Copyright (C) 2017 Karlson2k (Evgeny Grin)
4
5 This test tool is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2, or
8 (at your option) any later version.
9
10 This test tool is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*/
19
20/**
21 * @file microhttpd/test_str_token.c
22 * @brief Unit tests for some mhd_str functions
23 * @author Karlson2k (Evgeny Grin)
24 */
25
26#include "mhd_options.h"
27#include <stdio.h>
28#include "mhd_str.h"
29
30
31static int
32expect_found_n(const char *str, const char *token, size_t token_len)
33{
34 if (!MHD_str_has_token_caseless_(str, token, token_len))
35 {
36 fprintf(stderr, "MHD_str_has_token_caseless_() FAILED:\n\tMHD_str_has_token_caseless_(%s, %s, %lu) return false\n",
37 str, token, (unsigned long) token_len);
38 return 1;
39 }
40 return 0;
41}
42
43#define expect_found(s,t) expect_found_n((s),(t),MHD_STATICSTR_LEN_(t))
44
45static int
46expect_not_found_n(const char *str, const char *token, size_t token_len)
47{
48 if (MHD_str_has_token_caseless_(str, token, token_len))
49 {
50 fprintf(stderr, "MHD_str_has_token_caseless_() FAILED:\n\tMHD_str_has_token_caseless_(%s, %s, %lu) return true\n",
51 str, token, (unsigned long) token_len);
52 return 1;
53 }
54 return 0;
55}
56
57#define expect_not_found(s,t) expect_not_found_n((s),(t),MHD_STATICSTR_LEN_(t))
58
59int check_match(void)
60{
61 int errcount = 0;
62 errcount += expect_found("string", "string");
63 errcount += expect_found("String", "string");
64 errcount += expect_found("string", "String");
65 errcount += expect_found("strinG", "String");
66 errcount += expect_found("\t strinG", "String");
67 errcount += expect_found("strinG\t ", "String");
68 errcount += expect_found(" \t tOkEn ", "toKEN");
69 errcount += expect_found("not token\t, tOkEn ", "toKEN");
70 errcount += expect_found("not token,\t tOkEn, more token", "toKEN");
71 errcount += expect_found("not token,\t tOkEn\t, more token", "toKEN");
72 errcount += expect_found(",,,,,,test,,,,", "TESt");
73 errcount += expect_found(",,,,,\t,test,,,,", "TESt");
74 errcount += expect_found(",,,,,,test, ,,,", "TESt");
75 errcount += expect_found(",,,,,, test,,,,", "TESt");
76 errcount += expect_found(",,,,,, test not,test,,", "TESt");
77 errcount += expect_found(",,,,,, test not,,test,,", "TESt");
78 errcount += expect_found(",,,,,, test not ,test,,", "TESt");
79 errcount += expect_found(",,,,,, test", "TESt");
80 errcount += expect_found(",,,,,, test ", "TESt");
81 errcount += expect_found("no test,,,,,, test ", "TESt");
82 return errcount;
83}
84
85int check_not_match(void)
86{
87 int errcount = 0;
88 errcount += expect_not_found("strin", "string");
89 errcount += expect_not_found("Stringer", "string");
90 errcount += expect_not_found("sstring", "String");
91 errcount += expect_not_found("string", "Strin");
92 errcount += expect_not_found("\t( strinG", "String");
93 errcount += expect_not_found(")strinG\t ", "String");
94 errcount += expect_not_found(" \t tOkEn t ", "toKEN");
95 errcount += expect_not_found("not token\t, tOkEner ", "toKEN");
96 errcount += expect_not_found("not token,\t tOkEns, more token", "toKEN");
97 errcount += expect_not_found("not token,\t tOkEns\t, more token", "toKEN");
98 errcount += expect_not_found(",,,,,,testing,,,,", "TESt");
99 errcount += expect_not_found(",,,,,\t,test,,,,", "TESting");
100 errcount += expect_not_found("tests,,,,,,quest, ,,,", "TESt");
101 errcount += expect_not_found(",,,,,, testы,,,,", "TESt");
102 errcount += expect_not_found(",,,,,, test not,хtest,,", "TESt");
103 errcount += expect_not_found("testing,,,,,, test not,,test2,,", "TESt");
104 errcount += expect_not_found(",testi,,,,, test not ,test,,", "TESting");
105 errcount += expect_not_found(",,,,,,2 test", "TESt");
106 errcount += expect_not_found(",,,,,,test test ", "test");
107 errcount += expect_not_found("no test,,,,,, test test", "test");
108 return errcount;
109}
110
111int main(int argc, char * argv[])
112{
113 int errcount = 0;
114 errcount += check_match();
115 errcount += check_not_match();
116 return errcount == 0 ? 0 : 1;
117}