diff options
Diffstat (limited to 'src/microhttpd/test_str.c')
-rw-r--r-- | src/microhttpd/test_str.c | 3500 |
1 files changed, 3500 insertions, 0 deletions
diff --git a/src/microhttpd/test_str.c b/src/microhttpd/test_str.c new file mode 100644 index 00000000..c6ba1690 --- /dev/null +++ b/src/microhttpd/test_str.c | |||
@@ -0,0 +1,3500 @@ | |||
1 | /* | ||
2 | This file is part of libmicrohttpd | ||
3 | Copyright (C) 2016 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/unit_str_test.h | ||
22 | * @brief Unit tests for mhd_str functions | ||
23 | * @author Karlson2k (Evgeny Grin) | ||
24 | */ | ||
25 | |||
26 | #include <stdio.h> | ||
27 | #include <locale.h> | ||
28 | #include <string.h> | ||
29 | #include "mhd_options.h" | ||
30 | #ifdef HAVE_INTTYPES_H | ||
31 | #include <inttypes.h> | ||
32 | #else /* ! HAVE_INTTYPES_H */ | ||
33 | #define PRIu64 "llu" | ||
34 | #define PRIuPTR "u" | ||
35 | #define PRIX64 "llX" | ||
36 | #endif /* ! HAVE_INTTYPES_H */ | ||
37 | #include <stdint.h> | ||
38 | #include "mhd_limits.h" | ||
39 | #include "mhd_str.h" | ||
40 | #include "test_helpers.h" | ||
41 | |||
42 | |||
43 | static int verbose = 0; /* verbose level (0-3)*/ | ||
44 | |||
45 | /* Locale names to test. | ||
46 | * Functions must not depend of current current locale, | ||
47 | * so result must be the same in any locale. | ||
48 | */ | ||
49 | static const char * const locale_names[] = { | ||
50 | "C", | ||
51 | "", /* System default locale */ | ||
52 | #if defined(_WIN32) && !defined(__CYGWIN__) | ||
53 | ".OCP", /* W32 system default OEM code page */ | ||
54 | ".ACP", /* W32 system default ANSI code page */ | ||
55 | ".65001", /* UTF-8 */ | ||
56 | ".437", | ||
57 | ".850", | ||
58 | ".857", | ||
59 | ".866", | ||
60 | ".1250", | ||
61 | ".1251", | ||
62 | ".1252", | ||
63 | ".1254", | ||
64 | ".20866", /* number for KOI8-R */ | ||
65 | ".28591", /* number for ISO-8859-1 */ | ||
66 | ".28595", /* number for ISO-8859-5 */ | ||
67 | ".28599", /* number for ISO-8859-9 */ | ||
68 | ".28605", /* number for ISO-8859-15 */ | ||
69 | "en", | ||
70 | "english", | ||
71 | "en-US", | ||
72 | "English-US", | ||
73 | "en-US.437", | ||
74 | "English_United States.437", | ||
75 | "en-US.1252", | ||
76 | "English_United States.1252", | ||
77 | "English_United States.28591", | ||
78 | "English_United States.65001", | ||
79 | "fra", | ||
80 | "french", | ||
81 | "fr-FR", | ||
82 | "French_France", | ||
83 | "fr-FR.850", | ||
84 | "french_france.850", | ||
85 | "fr-FR.1252", | ||
86 | "French_france.1252", | ||
87 | "French_france.28605", | ||
88 | "French_France.65001", | ||
89 | "de", | ||
90 | "de-DE", | ||
91 | "de-DE.850", | ||
92 | "German_Germany.850", | ||
93 | "German_Germany.1250", | ||
94 | "de-DE.1252", | ||
95 | "German_Germany.1252", | ||
96 | "German_Germany.28605", | ||
97 | "German_Germany.65001", | ||
98 | "tr", | ||
99 | "trk", | ||
100 | "turkish", | ||
101 | "tr-TR", | ||
102 | "tr-TR.1254", | ||
103 | "Turkish_Turkey.1254", | ||
104 | "tr-TR.857", | ||
105 | "Turkish_Turkey.857", | ||
106 | "Turkish_Turkey.28599", | ||
107 | "Turkish_Turkey.65001", | ||
108 | "ru", | ||
109 | "ru-RU", | ||
110 | "Russian", | ||
111 | "ru-RU.866", | ||
112 | "Russian_Russia.866", | ||
113 | "ru-RU.1251", | ||
114 | "Russian_Russia.1251", | ||
115 | "Russian_Russia.20866", | ||
116 | "Russian_Russia.28595", | ||
117 | "Russian_Russia.65001", | ||
118 | "zh-Hans", | ||
119 | "zh-Hans.936", | ||
120 | "chinese-simplified" | ||
121 | #else /* ! _WIN32 || __CYGWIN__ */ | ||
122 | "C.UTF-8", | ||
123 | "POSIX", | ||
124 | "en", | ||
125 | "en_US", | ||
126 | "en_US.ISO-8859-1", | ||
127 | "en_US.ISO_8859-1", | ||
128 | "en_US.ISO8859-1", | ||
129 | "en_US.iso88591", | ||
130 | "en_US.ISO-8859-15", | ||
131 | "en_US.DIS_8859-15", | ||
132 | "en_US.ISO8859-15", | ||
133 | "en_US.iso885915", | ||
134 | "en_US.1252", | ||
135 | "en_US.CP1252", | ||
136 | "en_US.UTF-8", | ||
137 | "en_US.utf8", | ||
138 | "fr", | ||
139 | "fr_FR", | ||
140 | "fr_FR.850", | ||
141 | "fr_FR.IBM850", | ||
142 | "fr_FR.1252", | ||
143 | "fr_FR.CP1252", | ||
144 | "fr_FR.ISO-8859-1", | ||
145 | "fr_FR.ISO_8859-1", | ||
146 | "fr_FR.ISO8859-1", | ||
147 | "fr_FR.iso88591", | ||
148 | "fr_FR.ISO-8859-15", | ||
149 | "fr_FR.DIS_8859-15", | ||
150 | "fr_FR.ISO8859-15", | ||
151 | "fr_FR.iso8859-15", | ||
152 | "fr_FR.UTF-8", | ||
153 | "fr_FR.utf8", | ||
154 | "de", | ||
155 | "de_DE", | ||
156 | "de_DE.850", | ||
157 | "de_DE.IBM850", | ||
158 | "de_DE.1250", | ||
159 | "de_DE.CP1250", | ||
160 | "de_DE.1252", | ||
161 | "de_DE.CP1252", | ||
162 | "de_DE.ISO-8859-1", | ||
163 | "de_DE.ISO_8859-1", | ||
164 | "de_DE.ISO8859-1", | ||
165 | "de_DE.iso88591", | ||
166 | "de_DE.ISO-8859-15", | ||
167 | "de_DE.DIS_8859-15", | ||
168 | "de_DE.ISO8859-15", | ||
169 | "de_DE.iso885915", | ||
170 | "de_DE.UTF-8", | ||
171 | "de_DE.utf8", | ||
172 | "tr", | ||
173 | "tr_TR", | ||
174 | "tr_TR.1254", | ||
175 | "tr_TR.CP1254", | ||
176 | "tr_TR.857", | ||
177 | "tr_TR.IBM857", | ||
178 | "tr_TR.ISO-8859-9", | ||
179 | "tr_TR.ISO8859-9", | ||
180 | "tr_TR.iso88599", | ||
181 | "tr_TR.UTF-8", | ||
182 | "tr_TR.utf8", | ||
183 | "ru", | ||
184 | "ru_RU", | ||
185 | "ru_RU.1251", | ||
186 | "ru_RU.CP1251", | ||
187 | "ru_RU.866", | ||
188 | "ru_RU.IBM866", | ||
189 | "ru_RU.KOI8-R", | ||
190 | "ru_RU.koi8-r", | ||
191 | "ru_RU.KOI8-RU", | ||
192 | "ru_RU.ISO-8859-5", | ||
193 | "ru_RU.ISO_8859-5", | ||
194 | "ru_RU.ISO8859-5", | ||
195 | "ru_RU.iso88595", | ||
196 | "ru_RU.UTF-8", | ||
197 | "zh_CN", | ||
198 | "zh_CN.GB2312", | ||
199 | "zh_CN.UTF-8", | ||
200 | #endif /* ! _WIN32 || __CYGWIN__ */ | ||
201 | }; | ||
202 | |||
203 | static const unsigned int locale_name_count = sizeof(locale_names) / sizeof(locale_names[0]); | ||
204 | |||
205 | |||
206 | /* | ||
207 | * Helper functions | ||
208 | */ | ||
209 | |||
210 | int set_test_locale(unsigned int num) | ||
211 | { | ||
212 | if (num >= locale_name_count) | ||
213 | return -1; | ||
214 | if (verbose > 2) | ||
215 | printf("Setting locale \"%s\":", locale_names[num]); | ||
216 | if (setlocale(LC_ALL, locale_names[num])) | ||
217 | { | ||
218 | if (verbose > 2) | ||
219 | printf(" succeed.\n"); | ||
220 | return 1; | ||
221 | } | ||
222 | if (verbose > 2) | ||
223 | printf(" failed.\n"); | ||
224 | return 0; | ||
225 | } | ||
226 | |||
227 | const char * get_current_locale_str(void) | ||
228 | { | ||
229 | char const * loc_str = setlocale(LC_ALL, NULL); | ||
230 | return loc_str ? loc_str : "unknown"; | ||
231 | } | ||
232 | |||
233 | static char tmp_bufs[4][4*1024]; /* should be enough for testing */ | ||
234 | static size_t buf_idx = 0; | ||
235 | |||
236 | /* print non-printable chars as char codes */ | ||
237 | char * n_prnt(const char * str) | ||
238 | { | ||
239 | static char * buf; /* should be enough for testing */ | ||
240 | static const size_t buf_size = sizeof(tmp_bufs[0]); | ||
241 | const unsigned char * p = (const unsigned char*)str; | ||
242 | size_t w_pos = 0; | ||
243 | if (++buf_idx > 3) | ||
244 | buf_idx = 0; | ||
245 | buf = tmp_bufs[buf_idx]; | ||
246 | |||
247 | while(*p && w_pos + 1 < buf_size) | ||
248 | { | ||
249 | const unsigned char c = *p; | ||
250 | if (c == '\\' || c == '"') | ||
251 | { | ||
252 | if (w_pos + 2 >= buf_size) | ||
253 | break; | ||
254 | buf[w_pos++] = '\\'; | ||
255 | buf[w_pos++] = c; | ||
256 | } | ||
257 | else if (c >= 0x20 && c <= 0x7E) | ||
258 | buf[w_pos++] = c; | ||
259 | else | ||
260 | { | ||
261 | if (w_pos + 4 >= buf_size) | ||
262 | break; | ||
263 | if (snprintf(buf + w_pos, buf_size - w_pos, "\\x%02hX", (short unsigned int)c) != 4) | ||
264 | break; | ||
265 | w_pos += 4; | ||
266 | } | ||
267 | p++; | ||
268 | } | ||
269 | if (*p) | ||
270 | { /* not full string is printed */ | ||
271 | /* enough space for "..." ? */ | ||
272 | if (w_pos + 3 > buf_size) | ||
273 | w_pos = buf_size - 4; | ||
274 | buf[w_pos++] = '.'; | ||
275 | buf[w_pos++] = '.'; | ||
276 | buf[w_pos++] = '.'; | ||
277 | } | ||
278 | buf[w_pos] = 0; | ||
279 | return buf; | ||
280 | } | ||
281 | |||
282 | |||
283 | struct str_with_len | ||
284 | { | ||
285 | const char * const str; | ||
286 | const size_t len; | ||
287 | }; | ||
288 | |||
289 | #define D_STR_W_LEN(s) {(s), (sizeof((s)) / sizeof(char)) - 1} | ||
290 | |||
291 | /* | ||
292 | * String caseless equality functions tests | ||
293 | */ | ||
294 | |||
295 | struct two_eq_strs | ||
296 | { | ||
297 | const struct str_with_len s1; | ||
298 | const struct str_with_len s2; | ||
299 | }; | ||
300 | |||
301 | static const struct two_eq_strs eq_strings[] = { | ||
302 | {D_STR_W_LEN("1234567890!@~%&$@#{}[]\\/!?`."), D_STR_W_LEN("1234567890!@~%&$@#{}[]\\/!?`.")}, | ||
303 | {D_STR_W_LEN("Simple string."), D_STR_W_LEN("Simple string.")}, | ||
304 | {D_STR_W_LEN("SIMPLE STRING."), D_STR_W_LEN("SIMPLE STRING.")}, | ||
305 | {D_STR_W_LEN("simple string."), D_STR_W_LEN("simple string.")}, | ||
306 | {D_STR_W_LEN("simple string."), D_STR_W_LEN("Simple String.")}, | ||
307 | {D_STR_W_LEN("sImPlE StRiNg."), D_STR_W_LEN("SiMpLe sTrInG.")}, | ||
308 | {D_STR_W_LEN("SIMPLE STRING."), D_STR_W_LEN("simple string.")}, | ||
309 | {D_STR_W_LEN("abcdefghijklmnopqrstuvwxyz"), D_STR_W_LEN("abcdefghijklmnopqrstuvwxyz")}, | ||
310 | {D_STR_W_LEN("ABCDEFGHIJKLMNOPQRSTUVWXYZ"), D_STR_W_LEN("ABCDEFGHIJKLMNOPQRSTUVWXYZ")}, | ||
311 | {D_STR_W_LEN("abcdefghijklmnopqrstuvwxyz"), D_STR_W_LEN("ABCDEFGHIJKLMNOPQRSTUVWXYZ")}, | ||
312 | {D_STR_W_LEN("zyxwvutsrqponMLKJIHGFEDCBA"), D_STR_W_LEN("ZYXWVUTSRQPONmlkjihgfedcba")}, | ||
313 | |||
314 | {D_STR_W_LEN("Cha\x8cne pour le test."), | ||
315 | D_STR_W_LEN("Cha\x8cne pour le test.")}, /* "Chaîne pour le test." in CP850 */ | ||
316 | {D_STR_W_LEN("cha\x8cne pOur Le TEst."), | ||
317 | D_STR_W_LEN("Cha\x8cne poUr Le teST.")}, | ||
318 | {D_STR_W_LEN("Cha\xeene pour le test."), | ||
319 | D_STR_W_LEN("Cha\xeene pour le test.")}, /* "Chaîne pour le test." in CP1252/ISO-8859-1/ISO-8859-15 */ | ||
320 | {D_STR_W_LEN("CHa\xeene POUR le test."), | ||
321 | D_STR_W_LEN("Cha\xeeNe pour lE TEST.")}, | ||
322 | {D_STR_W_LEN("Cha\xc3\xaene pour le Test."), | ||
323 | D_STR_W_LEN("Cha\xc3\xaene pour le Test.")}, /* "Chaîne pour le test." in UTF-8 */ | ||
324 | {D_STR_W_LEN("ChA\xc3\xaene pouR lE TesT."), | ||
325 | D_STR_W_LEN("Cha\xc3\xaeNe Pour le teSt.")}, | ||
326 | |||
327 | {D_STR_W_LEN(".Beispiel Zeichenfolge"), | ||
328 | D_STR_W_LEN(".Beispiel Zeichenfolge")}, | ||
329 | {D_STR_W_LEN(".bEisPiel ZEIchenfoLgE"), | ||
330 | D_STR_W_LEN(".BEiSpiEl zeIcheNfolge")}, | ||
331 | |||
332 | {D_STR_W_LEN("Do\xa7rulama \x87izgi!"), | ||
333 | D_STR_W_LEN("Do\xa7rulama \x87izgi!")}, /* "Doğrulama çizgi!" in CP857 */ | ||
334 | {D_STR_W_LEN("Do\xa7rulama \x87IzgI!"), /* Spelling intentionally incorrect here */ | ||
335 | D_STR_W_LEN("Do\xa7rulama \x87izgi!")}, /* Note: 'i' is not caseless equal to 'I' in Turkish */ | ||
336 | {D_STR_W_LEN("Do\xf0rulama \xe7izgi!"), | ||
337 | D_STR_W_LEN("Do\xf0rulama \xe7izgi!")}, /* "Doğrulama çizgi!" in CP1254/ISO-8859-9 */ | ||
338 | {D_STR_W_LEN("Do\xf0rulamA \xe7Izgi!"), | ||
339 | D_STR_W_LEN("do\xf0rulama \xe7izgi!")}, | ||
340 | {D_STR_W_LEN("Do\xc4\x9frulama \xc3\xa7izgi!"), | ||
341 | D_STR_W_LEN("Do\xc4\x9frulama \xc3\xa7izgi!")}, /* "Doğrulama çizgi!" in UTF-8 */ | ||
342 | {D_STR_W_LEN("do\xc4\x9fruLAMA \xc3\xa7Izgi!"), /* Spelling intentionally incorrect here */ | ||
343 | D_STR_W_LEN("DO\xc4\x9frulama \xc3\xa7izgI!")}, /* Spelling intentionally incorrect here */ | ||
344 | |||
345 | {D_STR_W_LEN("\x92\xa5\xe1\xe2\xae\xa2\xa0\xef \x91\xe2\xe0\xae\xaa\xa0."), | ||
346 | D_STR_W_LEN("\x92\xa5\xe1\xe2\xae\xa2\xa0\xef \x91\xe2\xe0\xae\xaa\xa0.")}, /* "Тестовая Строка." in CP866 */ | ||
347 | {D_STR_W_LEN("\xd2\xe5\xf1\xf2\xee\xe2\xe0\xff \xd1\xf2\xf0\xee\xea\xe0."), | ||
348 | D_STR_W_LEN("\xd2\xe5\xf1\xf2\xee\xe2\xe0\xff \xd1\xf2\xf0\xee\xea\xe0.")}, /* "Тестовая Строка." in CP1251 */ | ||
349 | {D_STR_W_LEN("\xf4\xc5\xd3\xd4\xcf\xd7\xc1\xd1 \xf3\xd4\xd2\xcf\xcb\xc1."), | ||
350 | D_STR_W_LEN("\xf4\xc5\xd3\xd4\xcf\xd7\xc1\xd1 \xf3\xd4\xd2\xcf\xcb\xc1.")}, /* "Тестовая Строка." in KOI8-R */ | ||
351 | {D_STR_W_LEN("\xc2\xd5\xe1\xe2\xde\xd2\xd0\xef \xc1\xe2\xe0\xde\xda\xd0."), | ||
352 | D_STR_W_LEN("\xc2\xd5\xe1\xe2\xde\xd2\xd0\xef \xc1\xe2\xe0\xde\xda\xd0.")}, /* "Тестовая Строка." in ISO-8859-5 */ | ||
353 | {D_STR_W_LEN("\xd0\xa2\xd0\xb5\xd1\x81\xd1\x82\xd0\xbe\xd0\xb2\xd0\xb0\xd1" | ||
354 | "\x8f \xd0\xa1\xd1\x82\xd1\x80\xd0\xbe\xd0\xba\xd0\xb0."), | ||
355 | D_STR_W_LEN("\xd0\xa2\xd0\xb5\xd1\x81\xd1\x82\xd0\xbe\xd0\xb2\xd0\xb0\xd1" | ||
356 | "\x8f \xd0\xa1\xd1\x82\xd1\x80\xd0\xbe\xd0\xba\xd0\xb0.")}, /* "Тестовая Строка." in UTF-8 */ | ||
357 | |||
358 | {D_STR_W_LEN("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" | ||
359 | "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@[\\]" | ||
360 | "^_`{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90" | ||
361 | "\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4" | ||
362 | "\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8" | ||
363 | "\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc" | ||
364 | "\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0" | ||
365 | "\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4" | ||
366 | "\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"), | ||
367 | D_STR_W_LEN("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" | ||
368 | "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@[\\]" | ||
369 | "^_`{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90" | ||
370 | "\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4" | ||
371 | "\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8" | ||
372 | "\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc" | ||
373 | "\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0" | ||
374 | "\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4" | ||
375 | "\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff")}, /* Full sequence without a-z */ | ||
376 | {D_STR_W_LEN("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" | ||
377 | "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@AB" | ||
378 | "CDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83" | ||
379 | "\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97" | ||
380 | "\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab" | ||
381 | "\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf" | ||
382 | "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3" | ||
383 | "\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7" | ||
384 | "\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb" | ||
385 | "\xfc\xfd\xfe\xff"), | ||
386 | D_STR_W_LEN("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" | ||
387 | "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@AB" | ||
388 | "CDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83" | ||
389 | "\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97" | ||
390 | "\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab" | ||
391 | "\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf" | ||
392 | "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3" | ||
393 | "\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7" | ||
394 | "\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb" | ||
395 | "\xfc\xfd\xfe\xff")}, /* Full sequence */ | ||
396 | {D_STR_W_LEN("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" | ||
397 | "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@AB" | ||
398 | "CDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89" | ||
399 | "\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d" | ||
400 | "\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1" | ||
401 | "\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5" | ||
402 | "\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9" | ||
403 | "\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed" | ||
404 | "\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"), | ||
405 | D_STR_W_LEN("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" | ||
406 | "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@ab" | ||
407 | "cdefghijklmnopqrstuvwxyz[\\]^_`{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89" | ||
408 | "\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d" | ||
409 | "\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1" | ||
410 | "\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5" | ||
411 | "\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9" | ||
412 | "\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed" | ||
413 | "\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff")} /* Full with A/a match */ | ||
414 | }; | ||
415 | |||
416 | struct two_neq_strs | ||
417 | { | ||
418 | const struct str_with_len s1; | ||
419 | const struct str_with_len s2; | ||
420 | const size_t dif_pos; | ||
421 | }; | ||
422 | |||
423 | static const struct two_neq_strs neq_strings[] = { | ||
424 | {D_STR_W_LEN("1234567890!@~%&$@#{}[]\\/!?`."), D_STR_W_LEN("1234567890!@~%&$@#{}[]\\/!?`"), 27}, | ||
425 | {D_STR_W_LEN(".1234567890!@~%&$@#{}[]\\/!?`."), D_STR_W_LEN("1234567890!@~%&$@#{}[]\\/!?`"), 0}, | ||
426 | {D_STR_W_LEN("Simple string."), D_STR_W_LEN("Simple ctring."), 7}, | ||
427 | {D_STR_W_LEN("simple string."), D_STR_W_LEN("simple string"), 13}, | ||
428 | {D_STR_W_LEN("simple strings"), D_STR_W_LEN("Simple String."), 13}, | ||
429 | {D_STR_W_LEN("sImPlE StRiNg."), D_STR_W_LEN("SYMpLe sTrInG."), 1}, | ||
430 | {D_STR_W_LEN("SIMPLE STRING."), D_STR_W_LEN("simple string.2"), 14}, | ||
431 | {D_STR_W_LEN("abcdefghijklmnopqrstuvwxyz,"), D_STR_W_LEN("abcdefghijklmnopqrstuvwxyz."), 26}, | ||
432 | {D_STR_W_LEN("abcdefghijklmnopqrstuvwxyz!"), D_STR_W_LEN("ABCDEFGHIJKLMNOPQRSTUVWXYZ?"), 26}, | ||
433 | {D_STR_W_LEN("zyxwvutsrqponwMLKJIHGFEDCBA"), D_STR_W_LEN("ZYXWVUTSRQPON%mlkjihgfedcba"), 13}, | ||
434 | |||
435 | {D_STR_W_LEN("S\xbdur veulent plus d'\xbdufs."), /* "Sœur veulent plus d'œufs." in ISO-8859-15 */ | ||
436 | D_STR_W_LEN("S\xbcUR VEULENT PLUS D'\xbcUFS."), 1},/* "SŒUR VEULENT PLUS D'ŒUFS." in ISO-8859-15 */ | ||
437 | {D_STR_W_LEN("S\x9cur veulent plus d'\x9cufs."), /* "Sœur veulent plus d'œufs." in CP1252 */ | ||
438 | D_STR_W_LEN("S\x8cUR VEULENT PLUS D'\x8cUFS."), 1},/* "SŒUR VEULENT PLUS D'ŒUFS." in CP1252 */ | ||
439 | {D_STR_W_LEN("S\xc5\x93ur veulent plus d'\xc5\x93ufs."), /* "Sœur veulent plus d'œufs." in UTF-8 */ | ||
440 | D_STR_W_LEN("S\xc5\x92UR VEULENT PLUS D'\xc5\x92UFS."), 2},/* "SŒUR VEULENT PLUS D'ŒUFS." in UTF-8 */ | ||
441 | |||
442 | {D_STR_W_LEN("Um ein sch\x94nes M\x84" "dchen zu k\x81ssen."), /* "Um ein schönes Mädchen zu küssen." in CP850 */ | ||
443 | D_STR_W_LEN("UM EIN SCH\x99NES M\x8e" "DCHEN ZU K\x9aSSEN."), 10},/* "UM EIN SCHÖNES MÄDCHEN ZU KÜSSEN." in CP850 */ | ||
444 | {D_STR_W_LEN("Um ein sch\xf6nes M\xe4" "dchen zu k\xfcssen."), /* "Um ein schönes Mädchen zu küssen." in ISO-8859-1/ISO-8859-15/CP1250/CP1252 */ | ||
445 | D_STR_W_LEN("UM EIN SCH\xd6NES M\xc4" "DCHEN ZU K\xdcSSEN."), 10},/* "UM EIN SCHÖNES MÄDCHEN ZU KÜSSEN." in ISO-8859-1/ISO-8859-15/CP1250/CP1252 */ | ||
446 | {D_STR_W_LEN("Um ein sch\xc3\xb6nes M\xc3\xa4" "dchen zu k\xc3\xbcssen."), /* "Um ein schönes Mädchen zu küssen." in UTF-8 */ | ||
447 | D_STR_W_LEN("UM EIN SCH\xc3\x96NES M\xc3\x84" "DCHEN ZU K\xc3\x9cSSEN."), 11},/* "UM EIN SCHÖNES MÄDCHEN ZU KÜSSEN." in UTF-8 */ | ||
448 | |||
449 | {D_STR_W_LEN("\x98stanbul"), /* "İstanbul" in CP857 */ | ||
450 | D_STR_W_LEN("istanbul"), 0}, /* "istanbul" in CP857 */ | ||
451 | {D_STR_W_LEN("\xddstanbul"), /* "İstanbul" in ISO-8859-9/CP1254 */ | ||
452 | D_STR_W_LEN("istanbul"), 0}, /* "istanbul" in ISO-8859-9/CP1254 */ | ||
453 | {D_STR_W_LEN("\xc4\xb0stanbul"), /* "İstanbul" in UTF-8 */ | ||
454 | D_STR_W_LEN("istanbul"), 0}, /* "istanbul" in UTF-8 */ | ||
455 | {D_STR_W_LEN("Diyarbak\x8dr"), /* "Diyarbakır" in CP857 */ | ||
456 | D_STR_W_LEN("DiyarbakIR"), 8}, /* "DiyarbakIR" in CP857 */ | ||
457 | {D_STR_W_LEN("Diyarbak\xfdr"), /* "Diyarbakır" in ISO-8859-9/CP1254 */ | ||
458 | D_STR_W_LEN("DiyarbakIR"), 8}, /* "DiyarbakIR" in ISO-8859-9/CP1254 */ | ||
459 | {D_STR_W_LEN("Diyarbak\xc4\xb1r"), /* "Diyarbakır" in UTF-8 */ | ||
460 | D_STR_W_LEN("DiyarbakIR"), 8}, /* "DiyarbakIR" in UTF-8 */ | ||
461 | |||
462 | {D_STR_W_LEN("\x92\xa5\xe1\xe2\xae\xa2\xa0\xef \x91\xe2\xe0\xae\xaa\xa0."), /* "Тестовая Строка." in CP866 */ | ||
463 | D_STR_W_LEN("\x92\x85\x91\x92\x8e\x82\x80\x9f \x91\x92\x90\x8e\x8a\x80."), 1}, /* "ТЕСТОВАЯ СТРОКА." in CP866 */ | ||
464 | {D_STR_W_LEN("\xd2\xe5\xf1\xf2\xee\xe2\xe0\xff \xd1\xf2\xf0\xee\xea\xe0."), /* "Тестовая Строка." in CP1251 */ | ||
465 | D_STR_W_LEN("\xd2\xc5\xd1\xd2\xce\xc2\xc0\xdf \xd1\xd2\xd0\xce\xca\xc0."), 1}, /* "ТЕСТОВАЯ СТРОКА." in CP1251 */ | ||
466 | {D_STR_W_LEN("\xf4\xc5\xd3\xd4\xcf\xd7\xc1\xd1 \xf3\xd4\xd2\xcf\xcb\xc1."), /* "Тестовая Строка." in KOI8-R */ | ||
467 | D_STR_W_LEN("\xf4\xe5\xf3\xf4\xef\xf7\xe1\xf1 \xf3\xf4\xf2\xef\xeb\xe1."), 1}, /* "ТЕСТОВАЯ СТРОКА." in KOI8-R */ | ||
468 | {D_STR_W_LEN("\xc2\xd5\xe1\xe2\xde\xd2\xd0\xef \xc1\xe2\xe0\xde\xda\xd0."), /* "Тестовая Строка." in ISO-8859-5 */ | ||
469 | D_STR_W_LEN("\xc2\xb5\xc1\xc2\xbe\xb2\xb0\xcf \xc1\xc2\xc0\xbe\xba\xb0."), 1}, /* "ТЕСТОВАЯ СТРОКА." in ISO-8859-5 */ | ||
470 | {D_STR_W_LEN("\xd0\xa2\xd0\xb5\xd1\x81\xd1\x82\xd0\xbe\xd0\xb2\xd0\xb0\xd1" | ||
471 | "\x8f \xd0\xa1\xd1\x82\xd1\x80\xd0\xbe\xd0\xba\xd0\xb0."), /* "Тестовая Строка." in UTF-8 */ | ||
472 | D_STR_W_LEN("\xd0\xa2\xd0\x95\xd0\xa1\xd0\xa2\xd0\x9e\xd0\x92\xd0\x90\xd0" | ||
473 | "\xaf \xd0\xa1\xd0\xa2\xd0\xa0\xd0\x9e\xd0\x9a\xd0\x90."), 3} /* "ТЕСТОВАЯ СТРОКА." in UTF-8 */ | ||
474 | }; | ||
475 | |||
476 | |||
477 | int check_eq_strings(void) | ||
478 | { | ||
479 | size_t t_failed = 0; | ||
480 | size_t i, j; | ||
481 | static const size_t n_checks = sizeof(eq_strings) / sizeof(eq_strings[0]); | ||
482 | int c_failed[n_checks]; | ||
483 | |||
484 | memset(c_failed, 0, sizeof(c_failed)); | ||
485 | |||
486 | for(j = 0; j < locale_name_count; j++) | ||
487 | { | ||
488 | set_test_locale(j); /* setlocale() can be slow! */ | ||
489 | for(i = 0; i < n_checks; i++) | ||
490 | { | ||
491 | const struct two_eq_strs * const t = eq_strings + i; | ||
492 | if (c_failed[i]) | ||
493 | continue; /* skip already failed checks */ | ||
494 | if (!MHD_str_equal_caseless_(t->s1.str, t->s2.str)) | ||
495 | { | ||
496 | t_failed++; | ||
497 | c_failed[i] = !0; | ||
498 | fprintf(stderr, "FAILED: MHD_str_equal_caseless_(\"%s\", \"%s\") returned zero, while expected non-zero." | ||
499 | " Locale: %s\n", n_prnt(t->s1.str), n_prnt(t->s2.str), get_current_locale_str()); | ||
500 | } | ||
501 | else if (!MHD_str_equal_caseless_(t->s2.str, t->s1.str)) | ||
502 | { | ||
503 | t_failed++; | ||
504 | c_failed[i] = !0; | ||
505 | fprintf(stderr, "FAILED: MHD_str_equal_caseless_(\"%s\", \"%s\") returned zero, while expected non-zero." | ||
506 | " Locale: %s\n", n_prnt(t->s2.str), n_prnt(t->s1.str), get_current_locale_str()); | ||
507 | } | ||
508 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
509 | printf("PASSED: MHD_str_equal_caseless_(\"%s\", \"%s\") != 0 && \\\n" | ||
510 | " MHD_str_equal_caseless_(\"%s\", \"%s\") != 0\n", n_prnt(t->s1.str), n_prnt(t->s2.str), | ||
511 | n_prnt(t->s2.str), n_prnt(t->s1.str)); | ||
512 | } | ||
513 | } | ||
514 | return t_failed; | ||
515 | } | ||
516 | |||
517 | int check_neq_strings(void) | ||
518 | { | ||
519 | size_t t_failed = 0; | ||
520 | size_t i, j; | ||
521 | static const size_t n_checks = sizeof(neq_strings) / sizeof(neq_strings[0]); | ||
522 | int c_failed[n_checks]; | ||
523 | |||
524 | memset(c_failed, 0, sizeof(c_failed)); | ||
525 | |||
526 | for(j = 0; j < locale_name_count; j++) | ||
527 | { | ||
528 | set_test_locale(j); /* setlocale() can be slow! */ | ||
529 | for(i = 0; i < n_checks; i++) | ||
530 | { | ||
531 | const struct two_neq_strs * const t = neq_strings + i; | ||
532 | if (c_failed[i]) | ||
533 | continue; /* skip already failed checks */ | ||
534 | if (MHD_str_equal_caseless_(t->s1.str, t->s2.str)) | ||
535 | { | ||
536 | t_failed++; | ||
537 | c_failed[i] = !0; | ||
538 | fprintf(stderr, "FAILED: MHD_str_equal_caseless_(\"%s\", \"%s\") returned non-zero, while expected zero." | ||
539 | " Locale: %s\n", n_prnt(t->s1.str), n_prnt(t->s2.str), get_current_locale_str()); | ||
540 | } | ||
541 | else if (MHD_str_equal_caseless_(t->s2.str, t->s1.str)) | ||
542 | { | ||
543 | t_failed++; | ||
544 | c_failed[i] = !0; | ||
545 | fprintf(stderr, "FAILED: MHD_str_equal_caseless_(\"%s\", \"%s\") returned non-zero, while expected zero." | ||
546 | " Locale: %s\n", n_prnt(t->s2.str), n_prnt(t->s1.str), get_current_locale_str()); | ||
547 | } | ||
548 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
549 | printf("PASSED: MHD_str_equal_caseless_(\"%s\", \"%s\") == 0 && \\\n" | ||
550 | " MHD_str_equal_caseless_(\"%s\", \"%s\") == 0\n", n_prnt(t->s1.str), n_prnt(t->s2.str), | ||
551 | n_prnt(t->s2.str), n_prnt(t->s1.str)); | ||
552 | } | ||
553 | } | ||
554 | return t_failed; | ||
555 | } | ||
556 | |||
557 | int check_eq_strings_n(void) | ||
558 | { | ||
559 | size_t t_failed = 0; | ||
560 | size_t i, j, k; | ||
561 | static const size_t n_checks = sizeof(eq_strings) / sizeof(eq_strings[0]); | ||
562 | int c_failed[n_checks]; | ||
563 | |||
564 | memset(c_failed, 0, sizeof(c_failed)); | ||
565 | |||
566 | for(j = 0; j < locale_name_count; j++) | ||
567 | { | ||
568 | set_test_locale(j); /* setlocale() can be slow! */ | ||
569 | for(i = 0; i < n_checks; i++) | ||
570 | { | ||
571 | size_t m_len; | ||
572 | const struct two_eq_strs * const t = eq_strings + i; | ||
573 | m_len = (t->s1.len > t->s2.len) ? t->s1.len : t->s2.len; | ||
574 | for(k = 0; k <= m_len + 1 && !c_failed[i]; k++) | ||
575 | { | ||
576 | if (!MHD_str_equal_caseless_n_(t->s1.str, t->s2.str, k)) | ||
577 | { | ||
578 | t_failed++; | ||
579 | c_failed[i] = !0; | ||
580 | fprintf(stderr, "FAILED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", %u) returned zero," | ||
581 | " while expected non-zero. Locale: %s\n", | ||
582 | n_prnt(t->s1.str), n_prnt(t->s2.str), (unsigned int) k, get_current_locale_str()); | ||
583 | } | ||
584 | else if (!MHD_str_equal_caseless_n_(t->s2.str, t->s1.str, k)) | ||
585 | { | ||
586 | t_failed++; | ||
587 | c_failed[i] = !0; | ||
588 | fprintf(stderr, "FAILED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", %u) returned zero," | ||
589 | " while expected non-zero. Locale: %s\n", | ||
590 | n_prnt(t->s2.str), n_prnt(t->s1.str), (unsigned int) k, get_current_locale_str()); | ||
591 | } | ||
592 | } | ||
593 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
594 | printf("PASSED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", N) != 0 && \\\n" | ||
595 | " MHD_str_equal_caseless_n_(\"%s\", \"%s\", N) != 0, where N is 0..%u\n", | ||
596 | n_prnt(t->s1.str), n_prnt(t->s2.str), n_prnt(t->s2.str), n_prnt(t->s1.str), (unsigned int) m_len + 1); | ||
597 | } | ||
598 | } | ||
599 | return t_failed; | ||
600 | } | ||
601 | |||
602 | int check_neq_strings_n(void) | ||
603 | { | ||
604 | size_t t_failed = 0; | ||
605 | size_t i, j, k; | ||
606 | static const size_t n_checks = sizeof(neq_strings) / sizeof(neq_strings[0]); | ||
607 | int c_failed[n_checks]; | ||
608 | |||
609 | memset(c_failed, 0, sizeof(c_failed)); | ||
610 | |||
611 | for(j = 0; j < locale_name_count; j++) | ||
612 | { | ||
613 | set_test_locale(j); /* setlocale() can be slow! */ | ||
614 | for(i = 0; i < n_checks; i++) | ||
615 | { | ||
616 | size_t m_len; | ||
617 | const struct two_neq_strs * const t = neq_strings + i; | ||
618 | m_len = t->s1.len > t->s2.len ? t->s1.len : t->s2.len; | ||
619 | if (t->dif_pos >= m_len) | ||
620 | { | ||
621 | fprintf(stderr, "ERROR: neq_strings[%u] has wrong dif_pos (%u): dif_pos is expected to be less than " | ||
622 | "s1.len (%u) or s2.len (%u).\n", (unsigned int) i, (unsigned int) t->dif_pos, | ||
623 | (unsigned int) t->s1.len, (unsigned int) t->s2.len); | ||
624 | return -1; | ||
625 | } | ||
626 | if (t->dif_pos > t->s1.len) | ||
627 | { | ||
628 | fprintf(stderr, "ERROR: neq_strings[%u] has wrong dif_pos (%u): dif_pos is expected to be less or " | ||
629 | "equal to s1.len (%u).\n", (unsigned int) i, (unsigned int) t->dif_pos, | ||
630 | (unsigned int) t->s1.len); | ||
631 | return -1; | ||
632 | } | ||
633 | if (t->dif_pos > t->s2.len) | ||
634 | { | ||
635 | fprintf(stderr, "ERROR: neq_strings[%u] has wrong dif_pos (%u): dif_pos is expected to be less or " | ||
636 | "equal to s2.len (%u).\n", (unsigned int) i, (unsigned int) t->dif_pos, | ||
637 | (unsigned int) t->s2.len); | ||
638 | return -1; | ||
639 | } | ||
640 | for(k = 0; k <= m_len + 1 && !c_failed[i]; k++) | ||
641 | { | ||
642 | if (k <= t->dif_pos) | ||
643 | { | ||
644 | if (!MHD_str_equal_caseless_n_(t->s1.str, t->s2.str, k)) | ||
645 | { | ||
646 | t_failed++; | ||
647 | c_failed[i] = !0; | ||
648 | fprintf(stderr, "FAILED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", %u) returned zero," | ||
649 | " while expected non-zero. Locale: %s\n", | ||
650 | n_prnt(t->s1.str), n_prnt(t->s2.str), (unsigned int) k, get_current_locale_str()); | ||
651 | } | ||
652 | else if (!MHD_str_equal_caseless_n_(t->s2.str, t->s1.str, k)) | ||
653 | { | ||
654 | t_failed++; | ||
655 | c_failed[i] = !0; | ||
656 | fprintf(stderr, "FAILED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", %u) returned zero," | ||
657 | " while expected non-zero. Locale: %s\n", | ||
658 | n_prnt(t->s2.str), n_prnt(t->s1.str), (unsigned int) k, get_current_locale_str()); | ||
659 | } | ||
660 | } | ||
661 | else | ||
662 | { | ||
663 | if (MHD_str_equal_caseless_n_(t->s1.str, t->s2.str, k)) | ||
664 | { | ||
665 | t_failed++; | ||
666 | c_failed[i] = !0; | ||
667 | fprintf(stderr, "FAILED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", %u) returned non-zero," | ||
668 | " while expected zero. Locale: %s\n", | ||
669 | n_prnt(t->s1.str), n_prnt(t->s2.str), (unsigned int) k, get_current_locale_str()); | ||
670 | } | ||
671 | else if (MHD_str_equal_caseless_n_(t->s2.str, t->s1.str, k)) | ||
672 | { | ||
673 | t_failed++; | ||
674 | c_failed[i] = !0; | ||
675 | fprintf(stderr, "FAILED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", %u) returned non-zero," | ||
676 | " while expected zero. Locale: %s\n", | ||
677 | n_prnt(t->s2.str), n_prnt(t->s1.str), (unsigned int) k, get_current_locale_str()); | ||
678 | } | ||
679 | } | ||
680 | } | ||
681 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
682 | { | ||
683 | printf("PASSED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", N) != 0 && \\\n" | ||
684 | " MHD_str_equal_caseless_n_(\"%s\", \"%s\", N) != 0, where N is 0..%u\n", | ||
685 | n_prnt(t->s1.str), n_prnt(t->s2.str), n_prnt(t->s2.str), n_prnt(t->s1.str), | ||
686 | (unsigned int) t->dif_pos); | ||
687 | |||
688 | printf("PASSED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", N) == 0 && \\\n" | ||
689 | " MHD_str_equal_caseless_n_(\"%s\", \"%s\", N) == 0, where N is %u..%u\n", | ||
690 | n_prnt(t->s1.str), n_prnt(t->s2.str), n_prnt(t->s2.str), n_prnt(t->s1.str), | ||
691 | (unsigned int) t->dif_pos + 1, (unsigned int) m_len + 1); | ||
692 | } | ||
693 | } | ||
694 | } | ||
695 | return t_failed; | ||
696 | } | ||
697 | |||
698 | /* | ||
699 | * Run eq/neq strings tests | ||
700 | */ | ||
701 | int run_eq_neq_str_tests(void) | ||
702 | { | ||
703 | int str_equal_caseless_fails = 0; | ||
704 | int str_equal_caseless_n_fails = 0; | ||
705 | int res; | ||
706 | |||
707 | res = check_eq_strings(); | ||
708 | if (res != 0) | ||
709 | { | ||
710 | if (res < 0) | ||
711 | { | ||
712 | fprintf(stderr, "ERROR: test internal error in check_eq_strings().\n"); | ||
713 | return 99; | ||
714 | } | ||
715 | str_equal_caseless_fails += res; | ||
716 | fprintf(stderr, "FAILED: testcase check_eq_strings() failed.\n\n"); | ||
717 | } | ||
718 | else if (verbose > 1) | ||
719 | printf("PASSED: testcase check_eq_strings() successfully passed.\n\n"); | ||
720 | |||
721 | res = check_neq_strings(); | ||
722 | if (res != 0) | ||
723 | { | ||
724 | if (res < 0) | ||
725 | { | ||
726 | fprintf(stderr, "ERROR: test internal error in check_neq_strings().\n"); | ||
727 | return 99; | ||
728 | } | ||
729 | str_equal_caseless_fails += res; | ||
730 | fprintf(stderr, "FAILED: testcase check_neq_strings() failed.\n\n"); | ||
731 | } | ||
732 | else if (verbose > 1) | ||
733 | printf("PASSED: testcase check_neq_strings() successfully passed.\n\n"); | ||
734 | |||
735 | if (str_equal_caseless_fails) | ||
736 | fprintf(stderr, "FAILED: function MHD_str_equal_caseless_() failed %d time%s.\n\n", | ||
737 | str_equal_caseless_fails, str_equal_caseless_fails == 1 ? "" : "s"); | ||
738 | else if (verbose > 0) | ||
739 | printf("PASSED: function MHD_str_equal_caseless_() successfully passed all checks.\n\n"); | ||
740 | |||
741 | res = check_eq_strings_n(); | ||
742 | if (res != 0) | ||
743 | { | ||
744 | if (res < 0) | ||
745 | { | ||
746 | fprintf(stderr, "ERROR: test internal error in check_eq_strings_n().\n"); | ||
747 | return 99; | ||
748 | } | ||
749 | str_equal_caseless_n_fails += res; | ||
750 | fprintf(stderr, "FAILED: testcase check_eq_strings_n() failed.\n\n"); | ||
751 | } | ||
752 | else if (verbose > 1) | ||
753 | printf("PASSED: testcase check_eq_strings_n() successfully passed.\n\n"); | ||
754 | |||
755 | res = check_neq_strings_n(); | ||
756 | if (res != 0) | ||
757 | { | ||
758 | if (res < 0) | ||
759 | { | ||
760 | fprintf(stderr, "ERROR: test internal error in check_neq_strings_n().\n"); | ||
761 | return 99; | ||
762 | } | ||
763 | str_equal_caseless_n_fails += res; | ||
764 | fprintf(stderr, "FAILED: testcase check_neq_strings_n() failed.\n\n"); | ||
765 | } | ||
766 | else if (verbose > 1) | ||
767 | printf("PASSED: testcase check_neq_strings_n() successfully passed.\n\n"); | ||
768 | |||
769 | if (str_equal_caseless_n_fails) | ||
770 | fprintf(stderr, "FAILED: function MHD_str_equal_caseless_n_() failed %d time%s.\n\n", | ||
771 | str_equal_caseless_n_fails, str_equal_caseless_n_fails == 1 ? "" : "s"); | ||
772 | else if (verbose > 0) | ||
773 | printf("PASSED: function MHD_str_equal_caseless_n_() successfully passed all checks.\n\n"); | ||
774 | |||
775 | if (str_equal_caseless_fails || str_equal_caseless_n_fails) | ||
776 | { | ||
777 | if (verbose > 0) | ||
778 | printf("At least one test failed.\n"); | ||
779 | |||
780 | return 1; | ||
781 | } | ||
782 | |||
783 | if (verbose > 0) | ||
784 | printf("All tests passed successfully.\n"); | ||
785 | |||
786 | return 0; | ||
787 | } | ||
788 | |||
789 | /* | ||
790 | * Digits in string -> value tests | ||
791 | */ | ||
792 | |||
793 | struct str_with_value { | ||
794 | const struct str_with_len str; | ||
795 | const size_t num_of_digt; | ||
796 | const uint64_t val; | ||
797 | }; | ||
798 | |||
799 | /* valid string for conversion to unsigned integer value */ | ||
800 | static const struct str_with_value dstrs_w_values[] = { | ||
801 | /* simplest strings */ | ||
802 | {D_STR_W_LEN("1"), 1, 1}, | ||
803 | {D_STR_W_LEN("0"), 1, 0}, | ||
804 | {D_STR_W_LEN("10000"), 5, 10000}, | ||
805 | |||
806 | /* all digits */ | ||
807 | {D_STR_W_LEN("1234"), 4, 1234}, | ||
808 | {D_STR_W_LEN("4567"), 4, 4567}, | ||
809 | {D_STR_W_LEN("7890"), 4, 7890}, | ||
810 | {D_STR_W_LEN("8021"), 4, 8021}, | ||
811 | {D_STR_W_LEN("9754"), 4, 9754}, | ||
812 | {D_STR_W_LEN("6392"), 4, 6392}, | ||
813 | |||
814 | /* various prefixes */ | ||
815 | {D_STR_W_LEN("00000000"), 8, 0}, | ||
816 | {D_STR_W_LEN("0755"), 4, 755}, /* not to be interpreted as octal value! */ | ||
817 | {D_STR_W_LEN("002"), 3, 2}, | ||
818 | {D_STR_W_LEN("0001"), 4, 1}, | ||
819 | {D_STR_W_LEN("00000000000000000000000031295483"), 32, 31295483}, | ||
820 | |||
821 | /* numbers below and above limits */ | ||
822 | {D_STR_W_LEN("127"), 3, 127}, /* 0x7F, SCHAR_MAX */ | ||
823 | {D_STR_W_LEN("128"), 3, 128}, /* 0x80, SCHAR_MAX+1 */ | ||
824 | {D_STR_W_LEN("255"), 3, 255}, /* 0xFF, UCHAR_MAX */ | ||
825 | {D_STR_W_LEN("256"), 3, 256}, /* 0x100, UCHAR_MAX+1 */ | ||
826 | {D_STR_W_LEN("32767"), 5, 32767}, /* 0x7FFF, INT16_MAX */ | ||
827 | {D_STR_W_LEN("32768"), 5, 32768}, /* 0x8000, INT16_MAX+1 */ | ||
828 | {D_STR_W_LEN("65535"), 5, 65535}, /* 0xFFFF, UINT16_MAX */ | ||
829 | {D_STR_W_LEN("65536"), 5, 65536}, /* 0x10000, UINT16_MAX+1 */ | ||
830 | {D_STR_W_LEN("2147483647"), 10, 2147483647}, /* 0x7FFFFFFF, INT32_MAX */ | ||
831 | {D_STR_W_LEN("2147483648"), 10, UINT64_C(2147483648)}, /* 0x80000000, INT32_MAX+1 */ | ||
832 | {D_STR_W_LEN("4294967295"), 10, UINT64_C(4294967295)}, /* 0xFFFFFFFF, UINT32_MAX */ | ||
833 | {D_STR_W_LEN("4294967296"), 10, UINT64_C(4294967296)}, /* 0x100000000, UINT32_MAX+1 */ | ||
834 | {D_STR_W_LEN("9223372036854775807"), 19, UINT64_C(9223372036854775807)}, /* 0x7FFFFFFFFFFFFFFF, INT64_MAX */ | ||
835 | {D_STR_W_LEN("9223372036854775808"), 19, UINT64_C(9223372036854775808)}, /* 0x8000000000000000, INT64_MAX+1 */ | ||
836 | {D_STR_W_LEN("18446744073709551615"), 20, UINT64_C(18446744073709551615)}, /* 0xFFFFFFFFFFFFFFFF, UINT64_MAX */ | ||
837 | |||
838 | /* random numbers */ | ||
839 | {D_STR_W_LEN("10186753"), 8, 10186753}, | ||
840 | {D_STR_W_LEN("144402566"), 9, 144402566}, | ||
841 | {D_STR_W_LEN("151903144"), 9, 151903144}, | ||
842 | {D_STR_W_LEN("139264621"), 9, 139264621}, | ||
843 | {D_STR_W_LEN("730348"), 6, 730348}, | ||
844 | {D_STR_W_LEN("21584377"), 8, 21584377}, | ||
845 | {D_STR_W_LEN("709"), 3, 709}, | ||
846 | {D_STR_W_LEN("54"), 2, 54}, | ||
847 | {D_STR_W_LEN("8452"), 4, 8452}, | ||
848 | {D_STR_W_LEN("17745098750013624977"), 20, UINT64_C(17745098750013624977)}, | ||
849 | {D_STR_W_LEN("06786878769931678000"), 20, UINT64_C(6786878769931678000)}, | ||
850 | |||
851 | /* non-digit suffixes */ | ||
852 | {D_STR_W_LEN("1234oa"), 4, 1234}, | ||
853 | {D_STR_W_LEN("20h"), 2, 20}, /* not to be interpreted as hex value! */ | ||
854 | {D_STR_W_LEN("0x1F"), 1, 0}, /* not to be interpreted as hex value! */ | ||
855 | {D_STR_W_LEN("0564`~}"), 4, 564}, | ||
856 | {D_STR_W_LEN("7240146.724"), 7, 7240146}, | ||
857 | {D_STR_W_LEN("2,9"), 1, 2}, | ||
858 | {D_STR_W_LEN("200+1"), 3, 200}, | ||
859 | {D_STR_W_LEN("1a"), 1, 1}, | ||
860 | {D_STR_W_LEN("2E"), 1, 2}, | ||
861 | {D_STR_W_LEN("6c"), 1, 6}, | ||
862 | {D_STR_W_LEN("8F"), 1, 8}, | ||
863 | {D_STR_W_LEN("287416997! And the not too long string."), 9, 287416997} | ||
864 | }; | ||
865 | |||
866 | /* strings that should overflow uint64_t */ | ||
867 | const struct str_with_len str_ovflw[] = { | ||
868 | D_STR_W_LEN("18446744073709551616"), /* 0x10000000000000000, UINT64_MAX+1 */ | ||
869 | D_STR_W_LEN("18446744073709551620"), | ||
870 | D_STR_W_LEN("18446744083709551615"), | ||
871 | D_STR_W_LEN("19234761020556472143"), | ||
872 | D_STR_W_LEN("184467440737095516150"), | ||
873 | D_STR_W_LEN("1844674407370955161500"), | ||
874 | D_STR_W_LEN("000018446744073709551616"), /* 0x10000000000000000, UINT64_MAX+1 */ | ||
875 | D_STR_W_LEN("20000000000000000000"), | ||
876 | D_STR_W_LEN("020000000000000000000"), | ||
877 | D_STR_W_LEN("0020000000000000000000"), | ||
878 | D_STR_W_LEN("100000000000000000000"), | ||
879 | D_STR_W_LEN("434532891232591226417"), | ||
880 | D_STR_W_LEN("99999999999999999999"), | ||
881 | D_STR_W_LEN("18446744073709551616abcd"), /* 0x10000000000000000, UINT64_MAX+1 */ | ||
882 | D_STR_W_LEN("20000000000000000000 suffix"), | ||
883 | D_STR_W_LEN("020000000000000000000x") | ||
884 | }; | ||
885 | |||
886 | /* strings that should not be convertible to numeric value */ | ||
887 | const struct str_with_len str_no_num[] = { | ||
888 | D_STR_W_LEN("zero"), | ||
889 | D_STR_W_LEN("one"), | ||
890 | D_STR_W_LEN("\xb9\xb2\xb3"), /* superscript "123" in ISO-8859-1/CP1252 */ | ||
891 | D_STR_W_LEN("\xc2\xb9\xc2\xb2\xc2\xb3"), /* superscript "123" in UTF-8 */ | ||
892 | D_STR_W_LEN("\xd9\xa1\xd9\xa2\xd9\xa3"), /* Arabic-Indic "١٢٣" in UTF-8 */ | ||
893 | D_STR_W_LEN("\xdb\xb1\xdb\xb2\xdb\xb3"), /* Ext Arabic-Indic "۱۲۳" in UTF-8 */ | ||
894 | D_STR_W_LEN("\xe0\xa5\xa7\xe0\xa5\xa8\xe0\xa5\xa9"), /* Devanagari "१२३" in UTF-8 */ | ||
895 | D_STR_W_LEN("\xe4\xb8\x80\xe4\xba\x8c\xe4\xb8\x89"), /* Chinese "一二三" in UTF-8 */ | ||
896 | D_STR_W_LEN("\xd2\xbb\xb6\xfe\xc8\xfd"), /* Chinese "一二三" in GB2312/CP936 */ | ||
897 | D_STR_W_LEN("\x1B\x24\x29\x41\x0E\x52\x3B\x36\x7E\x48\x7D\x0F") /* Chinese "一二三" in ISO-2022-CN */ | ||
898 | }; | ||
899 | |||
900 | /* valid hex string for conversion to unsigned integer value */ | ||
901 | static const struct str_with_value xdstrs_w_values[] = { | ||
902 | /* simplest strings */ | ||
903 | {D_STR_W_LEN("1"), 1, 0x1}, | ||
904 | {D_STR_W_LEN("0"), 1, 0x0}, | ||
905 | {D_STR_W_LEN("10000"), 5, 0x10000}, | ||
906 | |||
907 | /* all digits */ | ||
908 | {D_STR_W_LEN("1234"), 4, 0x1234}, | ||
909 | {D_STR_W_LEN("4567"), 4, 0x4567}, | ||
910 | {D_STR_W_LEN("7890"), 4, 0x7890}, | ||
911 | {D_STR_W_LEN("8021"), 4, 0x8021}, | ||
912 | {D_STR_W_LEN("9754"), 4, 0x9754}, | ||
913 | {D_STR_W_LEN("6392"), 4, 0x6392}, | ||
914 | {D_STR_W_LEN("abcd"), 4, 0xABCD}, | ||
915 | {D_STR_W_LEN("cdef"), 4, 0xCDEF}, | ||
916 | {D_STR_W_LEN("FEAB"), 4, 0xFEAB}, | ||
917 | {D_STR_W_LEN("BCED"), 4, 0xBCED}, | ||
918 | {D_STR_W_LEN("bCeD"), 4, 0xBCED}, | ||
919 | {D_STR_W_LEN("1A5F"), 4, 0x1A5F}, | ||
920 | {D_STR_W_LEN("12AB"), 4, 0x12AB}, | ||
921 | {D_STR_W_LEN("CD34"), 4, 0xCD34}, | ||
922 | {D_STR_W_LEN("56EF"), 4, 0x56EF}, | ||
923 | {D_STR_W_LEN("7a9f"), 4, 0x7A9F}, | ||
924 | |||
925 | /* various prefixes */ | ||
926 | {D_STR_W_LEN("00000000"), 8, 0x0}, | ||
927 | {D_STR_W_LEN("0755"), 4, 0x755}, /* not to be interpreted as octal value! */ | ||
928 | {D_STR_W_LEN("002"), 3, 0x2}, | ||
929 | {D_STR_W_LEN("0001"), 4, 0x1}, | ||
930 | {D_STR_W_LEN("00a"), 3, 0xA}, | ||
931 | {D_STR_W_LEN("0F"), 2, 0xF}, | ||
932 | {D_STR_W_LEN("0000000000000000000000003A29e4C3"), 32, 0x3A29E4C3}, | ||
933 | |||
934 | /* numbers below and above limits */ | ||
935 | {D_STR_W_LEN("7F"), 2, 127}, /* 0x7F, SCHAR_MAX */ | ||
936 | {D_STR_W_LEN("7f"), 2, 127}, /* 0x7F, SCHAR_MAX */ | ||
937 | {D_STR_W_LEN("80"), 2, 128}, /* 0x80, SCHAR_MAX+1 */ | ||
938 | {D_STR_W_LEN("fF"), 2, 255}, /* 0xFF, UCHAR_MAX */ | ||
939 | {D_STR_W_LEN("Ff"), 2, 255}, /* 0xFF, UCHAR_MAX */ | ||
940 | {D_STR_W_LEN("FF"), 2, 255}, /* 0xFF, UCHAR_MAX */ | ||
941 | {D_STR_W_LEN("ff"), 2, 255}, /* 0xFF, UCHAR_MAX */ | ||
942 | {D_STR_W_LEN("100"), 3, 256}, /* 0x100, UCHAR_MAX+1 */ | ||
943 | {D_STR_W_LEN("7fff"), 4, 32767}, /* 0x7FFF, INT16_MAX */ | ||
944 | {D_STR_W_LEN("7FFF"), 4, 32767}, /* 0x7FFF, INT16_MAX */ | ||
945 | {D_STR_W_LEN("7Fff"), 4, 32767}, /* 0x7FFF, INT16_MAX */ | ||
946 | {D_STR_W_LEN("8000"), 4, 32768}, /* 0x8000, INT16_MAX+1 */ | ||
947 | {D_STR_W_LEN("ffff"), 4, 65535}, /* 0xFFFF, UINT16_MAX */ | ||
948 | {D_STR_W_LEN("FFFF"), 4, 65535}, /* 0xFFFF, UINT16_MAX */ | ||
949 | {D_STR_W_LEN("FffF"), 4, 65535}, /* 0xFFFF, UINT16_MAX */ | ||
950 | {D_STR_W_LEN("10000"), 5, 65536}, /* 0x10000, UINT16_MAX+1 */ | ||
951 | {D_STR_W_LEN("7FFFFFFF"), 8, 2147483647}, /* 0x7FFFFFFF, INT32_MAX */ | ||
952 | {D_STR_W_LEN("7fffffff"), 8, 2147483647}, /* 0x7FFFFFFF, INT32_MAX */ | ||
953 | {D_STR_W_LEN("7FFffFff"), 8, 2147483647}, /* 0x7FFFFFFF, INT32_MAX */ | ||
954 | {D_STR_W_LEN("80000000"), 8, UINT64_C(2147483648)}, /* 0x80000000, INT32_MAX+1 */ | ||
955 | {D_STR_W_LEN("FFFFFFFF"), 8, UINT64_C(4294967295)}, /* 0xFFFFFFFF, UINT32_MAX */ | ||
956 | {D_STR_W_LEN("ffffffff"), 8, UINT64_C(4294967295)}, /* 0xFFFFFFFF, UINT32_MAX */ | ||
957 | {D_STR_W_LEN("FfFfFfFf"), 8, UINT64_C(4294967295)}, /* 0xFFFFFFFF, UINT32_MAX */ | ||
958 | {D_STR_W_LEN("100000000"), 9, UINT64_C(4294967296)}, /* 0x100000000, UINT32_MAX+1 */ | ||
959 | {D_STR_W_LEN("7fffffffffffffff"), 16, UINT64_C(9223372036854775807)}, /* 0x7FFFFFFFFFFFFFFF, INT64_MAX */ | ||
960 | {D_STR_W_LEN("7FFFFFFFFFFFFFFF"), 16, UINT64_C(9223372036854775807)}, /* 0x7FFFFFFFFFFFFFFF, INT64_MAX */ | ||
961 | {D_STR_W_LEN("7FfffFFFFffFFffF"), 16, UINT64_C(9223372036854775807)}, /* 0x7FFFFFFFFFFFFFFF, INT64_MAX */ | ||
962 | {D_STR_W_LEN("8000000000000000"), 16, UINT64_C(9223372036854775808)}, /* 0x8000000000000000, INT64_MAX+1 */ | ||
963 | {D_STR_W_LEN("ffffffffffffffff"), 16, UINT64_C(18446744073709551615)}, /* 0xFFFFFFFFFFFFFFFF, UINT64_MAX */ | ||
964 | {D_STR_W_LEN("FFFFFFFFFFFFFFFF"), 16, UINT64_C(18446744073709551615)}, /* 0xFFFFFFFFFFFFFFFF, UINT64_MAX */ | ||
965 | {D_STR_W_LEN("FffFffFFffFFfFFF"), 16, UINT64_C(18446744073709551615)}, /* 0xFFFFFFFFFFFFFFFF, UINT64_MAX */ | ||
966 | |||
967 | /* random numbers */ | ||
968 | {D_STR_W_LEN("10186753"), 8, 0x10186753}, | ||
969 | {D_STR_W_LEN("144402566"), 9, 0x144402566}, | ||
970 | {D_STR_W_LEN("151903144"), 9, 0x151903144}, | ||
971 | {D_STR_W_LEN("139264621"), 9, 0x139264621}, | ||
972 | {D_STR_W_LEN("730348"), 6, 0x730348}, | ||
973 | {D_STR_W_LEN("21584377"), 8, 0x21584377}, | ||
974 | {D_STR_W_LEN("709"), 3, 0x709}, | ||
975 | {D_STR_W_LEN("54"), 2, 0x54}, | ||
976 | {D_STR_W_LEN("8452"), 4, 0x8452}, | ||
977 | {D_STR_W_LEN("22353EC6"), 8, 0x22353EC6}, | ||
978 | {D_STR_W_LEN("307F1655"), 8, 0x307F1655}, | ||
979 | {D_STR_W_LEN("1FCB7226"), 8, 0x1FCB7226}, | ||
980 | {D_STR_W_LEN("82480560"), 8, 0x82480560}, | ||
981 | {D_STR_W_LEN("7386D95"), 7, 0x7386D95}, | ||
982 | {D_STR_W_LEN("EC3AB"), 5, 0xEC3AB}, | ||
983 | {D_STR_W_LEN("6DD05"), 5, 0x6DD05}, | ||
984 | {D_STR_W_LEN("C5DF"), 4, 0xC5DF}, | ||
985 | {D_STR_W_LEN("6CE"), 3, 0x6CE}, | ||
986 | {D_STR_W_LEN("CE6"), 3, 0xCE6}, | ||
987 | {D_STR_W_LEN("ce6"), 3, 0xCE6}, | ||
988 | {D_STR_W_LEN("F27"), 3, 0xF27}, | ||
989 | {D_STR_W_LEN("8497D54277D7E1"), 14, UINT64_C(37321639124785121)}, | ||
990 | {D_STR_W_LEN("8497d54277d7e1"), 14, UINT64_C(37321639124785121)}, | ||
991 | {D_STR_W_LEN("8497d54277d7E1"), 14, UINT64_C(37321639124785121)}, | ||
992 | {D_STR_W_LEN("8C8112D0A06"), 11, UINT64_C(9655374645766)}, | ||
993 | {D_STR_W_LEN("8c8112d0a06"), 11, UINT64_C(9655374645766)}, | ||
994 | {D_STR_W_LEN("8c8112d0A06"), 11, UINT64_C(9655374645766)}, | ||
995 | {D_STR_W_LEN("1774509875001362"), 16, UINT64_C(1690064375898968930)}, | ||
996 | {D_STR_W_LEN("0678687876998000"), 16, UINT64_C(466237428027981824)}, | ||
997 | |||
998 | /* non-digit suffixes */ | ||
999 | {D_STR_W_LEN("1234oa"), 4, 0x1234}, | ||
1000 | {D_STR_W_LEN("20h"), 2, 0x20}, | ||
1001 | {D_STR_W_LEN("2CH"), 2, 0x2C}, | ||
1002 | {D_STR_W_LEN("2ch"), 2, 0x2C}, | ||
1003 | {D_STR_W_LEN("0x1F"), 1, 0x0}, /* not to be interpreted as hex prefix! */ | ||
1004 | {D_STR_W_LEN("0564`~}"), 4, 0x564}, | ||
1005 | {D_STR_W_LEN("0A64`~}"), 4, 0xA64}, | ||
1006 | {D_STR_W_LEN("056c`~}"), 4, 0X56C}, | ||
1007 | {D_STR_W_LEN("7240146.724"), 7, 0x7240146}, | ||
1008 | {D_STR_W_LEN("7E4c1AB.724"), 7, 0X7E4C1AB}, | ||
1009 | {D_STR_W_LEN("F24B1B6.724"), 7, 0xF24B1B6}, | ||
1010 | {D_STR_W_LEN("2,9"), 1, 0x2}, | ||
1011 | {D_STR_W_LEN("a,9"), 1, 0xA}, | ||
1012 | {D_STR_W_LEN("200+1"), 3, 0x200}, | ||
1013 | {D_STR_W_LEN("2cc+1"), 3, 0x2CC}, | ||
1014 | {D_STR_W_LEN("2cC+1"), 3, 0x2CC}, | ||
1015 | {D_STR_W_LEN("27416997! And the not too long string."), 8, 0x27416997}, | ||
1016 | {D_STR_W_LEN("27555416997! And the not too long string."), 11, 0x27555416997}, | ||
1017 | {D_STR_W_LEN("416997And the not too long string."), 7, 0x416997A}, | ||
1018 | {D_STR_W_LEN("0F4C3Dabstract addition to make string even longer"), 8, 0xF4C3DAB} | ||
1019 | }; | ||
1020 | |||
1021 | /* hex strings that should overflow uint64_t */ | ||
1022 | const struct str_with_len strx_ovflw[] = { | ||
1023 | D_STR_W_LEN("10000000000000000"), /* 0x10000000000000000, UINT64_MAX+1 */ | ||
1024 | D_STR_W_LEN("10000000000000001"), | ||
1025 | D_STR_W_LEN("10000000000000002"), | ||
1026 | D_STR_W_LEN("1000000000000000A"), | ||
1027 | D_STR_W_LEN("11000000000000000"), | ||
1028 | D_STR_W_LEN("010000000000000000"), /* 0x10000000000000000, UINT64_MAX+1 */ | ||
1029 | D_STR_W_LEN("000010000000000000000"), /* 0x10000000000000000, UINT64_MAX+1 */ | ||
1030 | D_STR_W_LEN("20000000000000000000"), | ||
1031 | D_STR_W_LEN("020000000000000000000"), | ||
1032 | D_STR_W_LEN("0020000000000000000000"), | ||
1033 | D_STR_W_LEN("20000000000000000"), | ||
1034 | D_STR_W_LEN("A0000000000000000"), | ||
1035 | D_STR_W_LEN("F0000000000000000"), | ||
1036 | D_STR_W_LEN("a0000000000000000"), | ||
1037 | D_STR_W_LEN("11111111111111111"), | ||
1038 | D_STR_W_LEN("CcCcCCccCCccCCccC"), | ||
1039 | D_STR_W_LEN("f0000000000000000"), | ||
1040 | D_STR_W_LEN("100000000000000000000"), | ||
1041 | D_STR_W_LEN("434532891232591226417"), | ||
1042 | D_STR_W_LEN("10000000000000000a"), | ||
1043 | D_STR_W_LEN("10000000000000000E"), | ||
1044 | D_STR_W_LEN("100000000000000000 and nothing"), /* 0x10000000000000000, UINT64_MAX+1 */ | ||
1045 | D_STR_W_LEN("100000000000000000xx"), /* 0x10000000000000000, UINT64_MAX+1 */ | ||
1046 | D_STR_W_LEN("99999999999999999999"), | ||
1047 | D_STR_W_LEN("18446744073709551616abcd"), | ||
1048 | D_STR_W_LEN("20000000000000000000 suffix"), | ||
1049 | D_STR_W_LEN("020000000000000000000x") | ||
1050 | }; | ||
1051 | |||
1052 | |||
1053 | int check_str_to_uint64_valid(void) | ||
1054 | { | ||
1055 | size_t t_failed = 0; | ||
1056 | size_t i, j; | ||
1057 | static const size_t n_checks = sizeof(dstrs_w_values) / sizeof(dstrs_w_values[0]); | ||
1058 | int c_failed[n_checks]; | ||
1059 | |||
1060 | memset(c_failed, 0, sizeof(c_failed)); | ||
1061 | |||
1062 | for(j = 0; j < locale_name_count; j++) | ||
1063 | { | ||
1064 | set_test_locale(j); /* setlocale() can be slow! */ | ||
1065 | for(i = 0; i < n_checks; i++) | ||
1066 | { | ||
1067 | uint64_t rv; | ||
1068 | size_t rs; | ||
1069 | const struct str_with_value * const t = dstrs_w_values + i; | ||
1070 | |||
1071 | if (c_failed[i]) | ||
1072 | continue; /* skip already failed checks */ | ||
1073 | |||
1074 | if (t->str.len < t->num_of_digt) | ||
1075 | { | ||
1076 | fprintf(stderr, "ERROR: dstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" | ||
1077 | " to be less or equal to str.len (%u).\n", | ||
1078 | (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned int) t->str.len); | ||
1079 | return -1; | ||
1080 | } | ||
1081 | rv = 9435223; /* some random value */ | ||
1082 | rs = MHD_str_to_uint64_(t->str.str, &rv); | ||
1083 | if (rs != t->num_of_digt) | ||
1084 | { | ||
1085 | t_failed++; | ||
1086 | c_failed[i] = !0; | ||
1087 | fprintf(stderr, "FAILED: MHD_str_to_uint64_(\"%s\", ->%" PRIu64 ") returned %" PRIuPTR ", while expecting %d." | ||
1088 | " Locale: %s\n", n_prnt(t->str.str), rv, (intptr_t)rs, (int)t->num_of_digt, get_current_locale_str()); | ||
1089 | } | ||
1090 | if (rv != t->val) | ||
1091 | { | ||
1092 | t_failed++; | ||
1093 | c_failed[i] = !0; | ||
1094 | fprintf(stderr, "FAILED: MHD_str_to_uint64_(\"%s\", ->%" PRIu64 ") converted string to value %" PRIu64 "," | ||
1095 | " while expecting result %" PRIu64 ". Locale: %s\n", n_prnt(t->str.str), rv, rv, | ||
1096 | t->val, get_current_locale_str()); | ||
1097 | } | ||
1098 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
1099 | printf("PASSED: MHD_str_to_uint64_(\"%s\", ->%" PRIu64 ") == %" PRIuPTR "\n", | ||
1100 | n_prnt(t->str.str), rv, rs); | ||
1101 | } | ||
1102 | } | ||
1103 | return t_failed; | ||
1104 | } | ||
1105 | |||
1106 | |||
1107 | int check_str_to_uint64_all_chars(void) | ||
1108 | { | ||
1109 | static const size_t n_checks = 256; /* from 0 to 255 */ | ||
1110 | int c_failed[n_checks]; | ||
1111 | size_t t_failed = 0; | ||
1112 | size_t j; | ||
1113 | |||
1114 | memset(c_failed, 0, sizeof(c_failed)); | ||
1115 | |||
1116 | for(j = 0; j < locale_name_count; j++) | ||
1117 | { | ||
1118 | unsigned int c; | ||
1119 | uint64_t test_val; | ||
1120 | |||
1121 | set_test_locale(j); /* setlocale() can be slow! */ | ||
1122 | for(c = 0; c < n_checks; c++) | ||
1123 | { | ||
1124 | static const uint64_t rnd_val = 24941852; | ||
1125 | size_t rs; | ||
1126 | if (c >= '0' && c <= '9') | ||
1127 | continue; /* skip digits */ | ||
1128 | for(test_val = 0; test_val <= rnd_val&& !c_failed[c]; test_val += rnd_val) | ||
1129 | { | ||
1130 | char test_str[] = "0123"; | ||
1131 | uint64_t rv = test_val; | ||
1132 | |||
1133 | test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */ | ||
1134 | rs = MHD_str_to_uint64_(test_str, &rv); | ||
1135 | if (rs != 0) | ||
1136 | { | ||
1137 | t_failed++; | ||
1138 | c_failed[c] = !0; | ||
1139 | fprintf(stderr, "FAILED: MHD_str_to_uint64_(\"%s\", ->%" PRIu64 ") returned %" PRIuPTR ", while expecting zero." | ||
1140 | " Locale: %s\n", n_prnt(test_str), rv, (uintptr_t)rs, get_current_locale_str()); | ||
1141 | } | ||
1142 | else if (rv != test_val) | ||
1143 | { | ||
1144 | t_failed++; | ||
1145 | c_failed[c] = !0; | ||
1146 | fprintf(stderr, "FAILED: MHD_str_to_uint64_(\"%s\", &ret_val) modified value of ret_val" | ||
1147 | " (before call: %" PRIu64 ", after call %" PRIu64 "). Locale: %s\n", | ||
1148 | n_prnt(test_str), test_val, rv, get_current_locale_str()); | ||
1149 | } | ||
1150 | } | ||
1151 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[c]) | ||
1152 | { | ||
1153 | char test_str[] = "0123"; | ||
1154 | test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */ | ||
1155 | |||
1156 | printf("PASSED: MHD_str_to_uint64_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n", | ||
1157 | n_prnt(test_str)); | ||
1158 | } | ||
1159 | } | ||
1160 | } | ||
1161 | return t_failed; | ||
1162 | } | ||
1163 | |||
1164 | |||
1165 | int check_str_to_uint64_overflow(void) | ||
1166 | { | ||
1167 | size_t t_failed = 0; | ||
1168 | size_t i, j; | ||
1169 | static const size_t n_checks = sizeof(str_ovflw) / sizeof(str_ovflw[0]); | ||
1170 | int c_failed[n_checks]; | ||
1171 | |||
1172 | memset(c_failed, 0, sizeof(c_failed)); | ||
1173 | |||
1174 | for(j = 0; j < locale_name_count; j++) | ||
1175 | { | ||
1176 | set_test_locale(j); /* setlocale() can be slow! */ | ||
1177 | for(i = 0; i < n_checks; i++) | ||
1178 | { | ||
1179 | size_t rs; | ||
1180 | const struct str_with_len * const t = str_ovflw + i; | ||
1181 | static const uint64_t rnd_val = 2; | ||
1182 | uint64_t test_val; | ||
1183 | |||
1184 | for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) | ||
1185 | { | ||
1186 | uint64_t rv = test_val; | ||
1187 | |||
1188 | rs = MHD_str_to_uint64_(t->str, &rv); | ||
1189 | if (rs != 0) | ||
1190 | { | ||
1191 | t_failed++; | ||
1192 | c_failed[i] = !0; | ||
1193 | fprintf(stderr, "FAILED: MHD_str_to_uint64_(\"%s\", ->%" PRIu64 ") returned %" PRIuPTR ", while expecting zero." | ||
1194 | " Locale: %s\n", n_prnt(t->str), rv, (uintptr_t)rs, get_current_locale_str()); | ||
1195 | } | ||
1196 | else if (rv != test_val) | ||
1197 | { | ||
1198 | t_failed++; | ||
1199 | c_failed[i] = !0; | ||
1200 | fprintf(stderr, "FAILED: MHD_str_to_uint64_(\"%s\", &ret_val) modified value of ret_val" | ||
1201 | " (before call: %" PRIu64 ", after call %" PRIu64 "). Locale: %s\n", | ||
1202 | n_prnt(t->str), test_val, rv, get_current_locale_str()); | ||
1203 | } | ||
1204 | } | ||
1205 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
1206 | printf("PASSED: MHD_str_to_uint64_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n", | ||
1207 | n_prnt(t->str)); | ||
1208 | } | ||
1209 | } | ||
1210 | return t_failed; | ||
1211 | } | ||
1212 | |||
1213 | |||
1214 | int check_str_to_uint64_no_val(void) | ||
1215 | { | ||
1216 | size_t t_failed = 0; | ||
1217 | size_t i, j; | ||
1218 | static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]); | ||
1219 | int c_failed[n_checks]; | ||
1220 | |||
1221 | memset(c_failed, 0, sizeof(c_failed)); | ||
1222 | |||
1223 | for(j = 0; j < locale_name_count; j++) | ||
1224 | { | ||
1225 | set_test_locale(j); /* setlocale() can be slow! */ | ||
1226 | for(i = 0; i < n_checks; i++) | ||
1227 | { | ||
1228 | size_t rs; | ||
1229 | const struct str_with_len * const t = str_no_num + i; | ||
1230 | static const uint64_t rnd_val = 74218431; | ||
1231 | uint64_t test_val; | ||
1232 | |||
1233 | for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) | ||
1234 | { | ||
1235 | uint64_t rv = test_val; | ||
1236 | |||
1237 | rs = MHD_str_to_uint64_(t->str, &rv); | ||
1238 | if (rs != 0) | ||
1239 | { | ||
1240 | t_failed++; | ||
1241 | c_failed[i] = !0; | ||
1242 | fprintf(stderr, "FAILED: MHD_str_to_uint64_(\"%s\", ->%" PRIu64 ") returned %" PRIuPTR ", while expecting zero." | ||
1243 | " Locale: %s\n", n_prnt(t->str), rv, (uintptr_t)rs, get_current_locale_str()); | ||
1244 | } | ||
1245 | else if (rv != test_val) | ||
1246 | { | ||
1247 | t_failed++; | ||
1248 | c_failed[i] = !0; | ||
1249 | fprintf(stderr, "FAILED: MHD_str_to_uint64_(\"%s\", &ret_val) modified value of ret_val" | ||
1250 | " (before call: %" PRIu64 ", after call %" PRIu64 "). Locale: %s\n", | ||
1251 | n_prnt(t->str), test_val, rv, get_current_locale_str()); | ||
1252 | } | ||
1253 | } | ||
1254 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
1255 | printf("PASSED: MHD_str_to_uint64_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n", | ||
1256 | n_prnt(t->str)); | ||
1257 | } | ||
1258 | } | ||
1259 | return t_failed; | ||
1260 | } | ||
1261 | |||
1262 | |||
1263 | int check_str_to_uint64_n_valid(void) | ||
1264 | { | ||
1265 | size_t t_failed = 0; | ||
1266 | size_t i, j; | ||
1267 | static const size_t n_checks = sizeof(dstrs_w_values) / sizeof(dstrs_w_values[0]); | ||
1268 | int c_failed[n_checks]; | ||
1269 | |||
1270 | memset(c_failed, 0, sizeof(c_failed)); | ||
1271 | |||
1272 | for(j = 0; j < locale_name_count; j++) | ||
1273 | { | ||
1274 | set_test_locale(j); /* setlocale() can be slow! */ | ||
1275 | for(i = 0; i < n_checks; i++) | ||
1276 | { | ||
1277 | uint64_t rv; | ||
1278 | size_t rs = 0; | ||
1279 | size_t len; | ||
1280 | const struct str_with_value * const t = dstrs_w_values + i; | ||
1281 | |||
1282 | if (t->str.len < t->num_of_digt) | ||
1283 | { | ||
1284 | fprintf(stderr, "ERROR: dstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" | ||
1285 | " to be less or equal to str.len (%u).\n", | ||
1286 | (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned int) t->str.len); | ||
1287 | return -1; | ||
1288 | } | ||
1289 | for (len = t->num_of_digt; len <= t->str.len + 1 && !c_failed[i]; len++) | ||
1290 | { | ||
1291 | rv = 1235572; /* some random value */ | ||
1292 | rs = MHD_str_to_uint64_n_(t->str.str, len, &rv); | ||
1293 | if (rs != t->num_of_digt) | ||
1294 | { | ||
1295 | t_failed++; | ||
1296 | c_failed[i] = !0; | ||
1297 | fprintf(stderr, "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", ->%" PRIu64 ")" | ||
1298 | " returned %" PRIuPTR ", while expecting %d. Locale: %s\n", | ||
1299 | n_prnt(t->str.str), (intptr_t)len, rv, (intptr_t)rs, | ||
1300 | (int)t->num_of_digt, get_current_locale_str()); | ||
1301 | } | ||
1302 | if (rv != t->val) | ||
1303 | { | ||
1304 | t_failed++; | ||
1305 | c_failed[i] = !0; | ||
1306 | fprintf(stderr, "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", ->%" PRIu64 ")" | ||
1307 | " converted string to value %" PRIu64 ", while expecting result %" PRIu64 | ||
1308 | ". Locale: %s\n", n_prnt(t->str.str), (intptr_t)len, rv, rv, | ||
1309 | t->val, get_current_locale_str()); | ||
1310 | } | ||
1311 | } | ||
1312 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
1313 | printf("PASSED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR ", ->%" PRIu64 ")" | ||
1314 | " == %" PRIuPTR "\n", n_prnt(t->str.str), (intptr_t)t->num_of_digt, | ||
1315 | (intptr_t)t->str.len + 1, rv, rs); | ||
1316 | } | ||
1317 | } | ||
1318 | return t_failed; | ||
1319 | } | ||
1320 | |||
1321 | |||
1322 | int check_str_to_uint64_n_all_chars(void) | ||
1323 | { | ||
1324 | static const size_t n_checks = 256; /* from 0 to 255 */ | ||
1325 | int c_failed[n_checks]; | ||
1326 | size_t t_failed = 0; | ||
1327 | size_t j; | ||
1328 | |||
1329 | memset(c_failed, 0, sizeof(c_failed)); | ||
1330 | |||
1331 | for(j = 0; j < locale_name_count; j++) | ||
1332 | { | ||
1333 | unsigned int c; | ||
1334 | uint64_t test_val; | ||
1335 | |||
1336 | set_test_locale(j); /* setlocale() can be slow! */ | ||
1337 | for(c = 0; c < n_checks; c++) | ||
1338 | { | ||
1339 | static const uint64_t rnd_val = 98372558; | ||
1340 | size_t rs; | ||
1341 | size_t len; | ||
1342 | |||
1343 | if (c >= '0' && c <= '9') | ||
1344 | continue; /* skip digits */ | ||
1345 | |||
1346 | for (len = 0; len <= 5; len++) | ||
1347 | { | ||
1348 | for(test_val = 0; test_val <= rnd_val&& !c_failed[c]; test_val += rnd_val) | ||
1349 | { | ||
1350 | char test_str[] = "0123"; | ||
1351 | uint64_t rv = test_val; | ||
1352 | |||
1353 | test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */ | ||
1354 | rs = MHD_str_to_uint64_n_(test_str, len, &rv); | ||
1355 | if (rs != 0) | ||
1356 | { | ||
1357 | t_failed++; | ||
1358 | c_failed[c] = !0; | ||
1359 | fprintf(stderr, "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", ->%" PRIu64 ")" | ||
1360 | " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", | ||
1361 | n_prnt(test_str), (uintptr_t)len, rv, (uintptr_t)rs, get_current_locale_str()); | ||
1362 | } | ||
1363 | else if (rv != test_val) | ||
1364 | { | ||
1365 | t_failed++; | ||
1366 | c_failed[c] = !0; | ||
1367 | fprintf(stderr, "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", &ret_val)" | ||
1368 | " modified value of ret_val (before call: %" PRIu64 ", after call %" PRIu64 ")." | ||
1369 | " Locale: %s\n", | ||
1370 | n_prnt(test_str), (uintptr_t)len, test_val, rv, get_current_locale_str()); | ||
1371 | } | ||
1372 | } | ||
1373 | } | ||
1374 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[c]) | ||
1375 | { | ||
1376 | char test_str[] = "0123"; | ||
1377 | test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */ | ||
1378 | |||
1379 | printf("PASSED: MHD_str_to_uint64_n_(\"%s\", 0..5, &ret_val) == 0, value of ret_val is unmodified\n", | ||
1380 | n_prnt(test_str)); | ||
1381 | } | ||
1382 | } | ||
1383 | } | ||
1384 | return t_failed; | ||
1385 | } | ||
1386 | |||
1387 | |||
1388 | int check_str_to_uint64_n_overflow(void) | ||
1389 | { | ||
1390 | size_t t_failed = 0; | ||
1391 | size_t i, j; | ||
1392 | static const size_t n_checks = sizeof(str_ovflw) / sizeof(str_ovflw[0]); | ||
1393 | int c_failed[n_checks]; | ||
1394 | |||
1395 | memset(c_failed, 0, sizeof(c_failed)); | ||
1396 | |||
1397 | for(j = 0; j < locale_name_count; j++) | ||
1398 | { | ||
1399 | set_test_locale(j); /* setlocale() can be slow! */ | ||
1400 | for(i = 0; i < n_checks; i++) | ||
1401 | { | ||
1402 | size_t rs; | ||
1403 | const struct str_with_len * const t = str_ovflw + i; | ||
1404 | static const uint64_t rnd_val = 3; | ||
1405 | size_t len; | ||
1406 | |||
1407 | for (len = t->len; len <= t->len + 1; len++) | ||
1408 | { | ||
1409 | uint64_t test_val; | ||
1410 | for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) | ||
1411 | { | ||
1412 | uint64_t rv = test_val; | ||
1413 | |||
1414 | rs = MHD_str_to_uint64_n_(t->str, len, &rv); | ||
1415 | if (rs != 0) | ||
1416 | { | ||
1417 | t_failed++; | ||
1418 | c_failed[i] = !0; | ||
1419 | fprintf(stderr, "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", ->%" PRIu64 ")" | ||
1420 | " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", | ||
1421 | n_prnt(t->str), (uintptr_t)len, rv, (uintptr_t)rs, get_current_locale_str()); | ||
1422 | } | ||
1423 | else if (rv != test_val) | ||
1424 | { | ||
1425 | t_failed++; | ||
1426 | c_failed[i] = !0; | ||
1427 | fprintf(stderr, "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", &ret_val)" | ||
1428 | " modified value of ret_val (before call: %" PRIu64 ", after call %" PRIu64 ")." | ||
1429 | " Locale: %s\n", n_prnt(t->str), (uintptr_t)len, test_val, rv, | ||
1430 | get_current_locale_str()); | ||
1431 | } | ||
1432 | } | ||
1433 | } | ||
1434 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
1435 | printf("PASSED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR ", &ret_val) == 0," | ||
1436 | " value of ret_val is unmodified\n", n_prnt(t->str), (uintptr_t)t->len, | ||
1437 | (uintptr_t)t->len + 1); | ||
1438 | } | ||
1439 | } | ||
1440 | return t_failed; | ||
1441 | } | ||
1442 | |||
1443 | |||
1444 | int check_str_to_uint64_n_no_val(void) | ||
1445 | { | ||
1446 | size_t t_failed = 0; | ||
1447 | size_t i, j; | ||
1448 | static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]); | ||
1449 | int c_failed[n_checks]; | ||
1450 | |||
1451 | memset(c_failed, 0, sizeof(c_failed)); | ||
1452 | |||
1453 | for(j = 0; j < locale_name_count; j++) | ||
1454 | { | ||
1455 | set_test_locale(j); /* setlocale() can be slow! */ | ||
1456 | for(i = 0; i < n_checks; i++) | ||
1457 | { | ||
1458 | size_t rs; | ||
1459 | const struct str_with_len * const t = str_no_num + i; | ||
1460 | static const uint64_t rnd_val = 43255654342; | ||
1461 | size_t len; | ||
1462 | |||
1463 | for (len = 0; len <= t->len + 1; len++) | ||
1464 | { | ||
1465 | uint64_t test_val; | ||
1466 | for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) | ||
1467 | { | ||
1468 | uint64_t rv = test_val; | ||
1469 | |||
1470 | rs = MHD_str_to_uint64_n_(t->str, len, &rv); | ||
1471 | if (rs != 0) | ||
1472 | { | ||
1473 | t_failed++; | ||
1474 | c_failed[i] = !0; | ||
1475 | fprintf(stderr, "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", ->%" PRIu64 ")" | ||
1476 | " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", | ||
1477 | n_prnt(t->str), (uintptr_t)len, rv, (uintptr_t)rs, get_current_locale_str()); | ||
1478 | } | ||
1479 | else if (rv != test_val) | ||
1480 | { | ||
1481 | t_failed++; | ||
1482 | c_failed[i] = !0; | ||
1483 | fprintf(stderr, "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", &ret_val)" | ||
1484 | " modified value of ret_val (before call: %" PRIu64 ", after call %" PRIu64 ")." | ||
1485 | " Locale: %s\n", n_prnt(t->str), (uintptr_t)len, test_val, rv, | ||
1486 | get_current_locale_str()); | ||
1487 | } | ||
1488 | } | ||
1489 | } | ||
1490 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
1491 | printf("PASSED: MHD_str_to_uint64_n_(\"%s\", 0..%" PRIuPTR ", &ret_val) == 0," | ||
1492 | " value of ret_val is unmodified\n", n_prnt(t->str), | ||
1493 | (uintptr_t)t->len + 1); | ||
1494 | } | ||
1495 | } | ||
1496 | return t_failed; | ||
1497 | } | ||
1498 | |||
1499 | |||
1500 | int check_strx_to_sizet_valid(void) | ||
1501 | { | ||
1502 | size_t t_failed = 0; | ||
1503 | size_t i, j; | ||
1504 | static const size_t n_checks = sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]); | ||
1505 | int c_failed[n_checks]; | ||
1506 | |||
1507 | memset(c_failed, 0, sizeof(c_failed)); | ||
1508 | |||
1509 | for(j = 0; j < locale_name_count; j++) | ||
1510 | { | ||
1511 | set_test_locale(j); /* setlocale() can be slow! */ | ||
1512 | for(i = 0; i < n_checks; i++) | ||
1513 | { | ||
1514 | size_t rv; | ||
1515 | size_t rs; | ||
1516 | const struct str_with_value * const t = xdstrs_w_values + i; | ||
1517 | |||
1518 | #if SIZE_MAX != UINT64_MAX | ||
1519 | if (t->val > SIZE_MAX) | ||
1520 | continue; /* number is too high for this function */ | ||
1521 | #endif /* SIZE_MAX != UINT64_MAX */ | ||
1522 | |||
1523 | if (c_failed[i]) | ||
1524 | continue; /* skip already failed checks */ | ||
1525 | |||
1526 | if (t->str.len < t->num_of_digt) | ||
1527 | { | ||
1528 | fprintf(stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" | ||
1529 | " to be less or equal to str.len (%u).\n", | ||
1530 | (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned int) t->str.len); | ||
1531 | return -1; | ||
1532 | } | ||
1533 | rv = 1458532; /* some random value */ | ||
1534 | rs = MHD_strx_to_sizet_(t->str.str, &rv); | ||
1535 | if (rs != t->num_of_digt) | ||
1536 | { | ||
1537 | t_failed++; | ||
1538 | c_failed[i] = !0; | ||
1539 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting %d." | ||
1540 | " Locale: %s\n", n_prnt(t->str.str), (uint64_t)rv, (intptr_t)rs, (int)t->num_of_digt, get_current_locale_str()); | ||
1541 | } | ||
1542 | if (rv != t->val) | ||
1543 | { | ||
1544 | t_failed++; | ||
1545 | c_failed[i] = !0; | ||
1546 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", ->0x%" PRIX64 ") converted string to value 0x%" PRIX64 "," | ||
1547 | " while expecting result 0x%" PRIX64 ". Locale: %s\n", n_prnt(t->str.str), (uint64_t)rv, (uint64_t)rv, | ||
1548 | t->val, get_current_locale_str()); | ||
1549 | } | ||
1550 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
1551 | printf("PASSED: MHD_strx_to_sizet_(\"%s\", ->0x%" PRIX64 ") == %" PRIuPTR "\n", | ||
1552 | n_prnt(t->str.str), (uint64_t)rv, rs); | ||
1553 | } | ||
1554 | } | ||
1555 | return t_failed; | ||
1556 | } | ||
1557 | |||
1558 | |||
1559 | int check_strx_to_sizet_all_chars(void) | ||
1560 | { | ||
1561 | static const size_t n_checks = 256; /* from 0 to 255 */ | ||
1562 | int c_failed[n_checks]; | ||
1563 | size_t t_failed = 0; | ||
1564 | size_t j; | ||
1565 | |||
1566 | memset(c_failed, 0, sizeof(c_failed)); | ||
1567 | |||
1568 | for(j = 0; j < locale_name_count; j++) | ||
1569 | { | ||
1570 | unsigned int c; | ||
1571 | size_t test_val; | ||
1572 | |||
1573 | set_test_locale(j); /* setlocale() can be slow! */ | ||
1574 | for(c = 0; c < n_checks; c++) | ||
1575 | { | ||
1576 | static const size_t rnd_val = 234234; | ||
1577 | size_t rs; | ||
1578 | if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') ||(c >= 'a' && c <= 'f')) | ||
1579 | continue; /* skip xdigits */ | ||
1580 | for(test_val = 0; test_val <= rnd_val&& !c_failed[c]; test_val += rnd_val) | ||
1581 | { | ||
1582 | char test_str[] = "0123"; | ||
1583 | size_t rv = test_val; | ||
1584 | |||
1585 | test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */ | ||
1586 | rs = MHD_strx_to_sizet_(test_str, &rv); | ||
1587 | if (rs != 0) | ||
1588 | { | ||
1589 | t_failed++; | ||
1590 | c_failed[c] = !0; | ||
1591 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting zero." | ||
1592 | " Locale: %s\n", n_prnt(test_str), (uint64_t)rv, (uintptr_t)rs, get_current_locale_str()); | ||
1593 | } | ||
1594 | else if (rv != test_val) | ||
1595 | { | ||
1596 | t_failed++; | ||
1597 | c_failed[c] = !0; | ||
1598 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", &ret_val) modified value of ret_val" | ||
1599 | " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 "). Locale: %s\n", | ||
1600 | n_prnt(test_str), (uint64_t)test_val, (uint64_t)rv, get_current_locale_str()); | ||
1601 | } | ||
1602 | } | ||
1603 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[c]) | ||
1604 | { | ||
1605 | char test_str[] = "0123"; | ||
1606 | test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */ | ||
1607 | |||
1608 | printf("PASSED: MHD_strx_to_sizet_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n", | ||
1609 | n_prnt(test_str)); | ||
1610 | } | ||
1611 | } | ||
1612 | } | ||
1613 | return t_failed; | ||
1614 | } | ||
1615 | |||
1616 | |||
1617 | int check_strx_to_sizet_overflow(void) | ||
1618 | { | ||
1619 | size_t t_failed = 0; | ||
1620 | size_t i, j; | ||
1621 | static const size_t n_checks1 = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]); | ||
1622 | #if SIZE_MAX != UINT64_MAX | ||
1623 | static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]) + | ||
1624 | sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]); | ||
1625 | #else /* SIZE_MAX == UINT64_MAX */ | ||
1626 | static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]); | ||
1627 | #endif /* SIZE_MAX == UINT64_MAX */ | ||
1628 | int c_failed[n_checks]; | ||
1629 | |||
1630 | memset(c_failed, 0, sizeof(c_failed)); | ||
1631 | |||
1632 | for(j = 0; j < locale_name_count; j++) | ||
1633 | { | ||
1634 | set_test_locale(j); /* setlocale() can be slow! */ | ||
1635 | for(i = 0; i < n_checks; i++) | ||
1636 | { | ||
1637 | size_t rs; | ||
1638 | static const size_t rnd_val = 74218431; | ||
1639 | size_t test_val; | ||
1640 | const char * str; | ||
1641 | if (i < n_checks1) | ||
1642 | { | ||
1643 | const struct str_with_len * const t = strx_ovflw + i; | ||
1644 | str = t->str; | ||
1645 | } | ||
1646 | #if SIZE_MAX != UINT64_MAX | ||
1647 | else | ||
1648 | { | ||
1649 | const struct str_with_value * const t = xdstrs_w_values + (i - n_checks1); | ||
1650 | if (t->val <= SIZE_MAX) | ||
1651 | continue; /* check only strings that should overflow size_t */ | ||
1652 | str = t->str.str; | ||
1653 | } | ||
1654 | #else /* SIZE_MAX == UINT64_MAX */ | ||
1655 | else | ||
1656 | continue; /* silent compiler warning */ | ||
1657 | #endif /* SIZE_MAX == UINT64_MAX */ | ||
1658 | |||
1659 | |||
1660 | for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) | ||
1661 | { | ||
1662 | size_t rv = test_val; | ||
1663 | |||
1664 | rs = MHD_strx_to_sizet_(str, &rv); | ||
1665 | if (rs != 0) | ||
1666 | { | ||
1667 | t_failed++; | ||
1668 | c_failed[i] = !0; | ||
1669 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting zero." | ||
1670 | " Locale: %s\n", n_prnt(str), (uint64_t)rv, (uintptr_t)rs, get_current_locale_str()); | ||
1671 | } | ||
1672 | else if (rv != test_val) | ||
1673 | { | ||
1674 | t_failed++; | ||
1675 | c_failed[i] = !0; | ||
1676 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", &ret_val) modified value of ret_val" | ||
1677 | " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 "). Locale: %s\n", | ||
1678 | n_prnt(str), (uint64_t)test_val, (uint64_t)rv, get_current_locale_str()); | ||
1679 | } | ||
1680 | } | ||
1681 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
1682 | printf("PASSED: MHD_strx_to_sizet_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n", | ||
1683 | n_prnt(str)); | ||
1684 | } | ||
1685 | } | ||
1686 | return t_failed; | ||
1687 | } | ||
1688 | |||
1689 | |||
1690 | int check_strx_to_sizet_no_val(void) | ||
1691 | { | ||
1692 | size_t t_failed = 0; | ||
1693 | size_t i, j; | ||
1694 | static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]); | ||
1695 | int c_failed[n_checks]; | ||
1696 | |||
1697 | memset(c_failed, 0, sizeof(c_failed)); | ||
1698 | |||
1699 | for(j = 0; j < locale_name_count; j++) | ||
1700 | { | ||
1701 | set_test_locale(j); /* setlocale() can be slow! */ | ||
1702 | for(i = 0; i < n_checks; i++) | ||
1703 | { | ||
1704 | size_t rs; | ||
1705 | const struct str_with_len * const t = str_no_num + i; | ||
1706 | static const size_t rnd_val = 74218431; | ||
1707 | size_t test_val; | ||
1708 | |||
1709 | for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) | ||
1710 | { | ||
1711 | size_t rv = test_val; | ||
1712 | |||
1713 | rs = MHD_strx_to_sizet_(t->str, &rv); | ||
1714 | if (rs != 0) | ||
1715 | { | ||
1716 | t_failed++; | ||
1717 | c_failed[i] = !0; | ||
1718 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting zero." | ||
1719 | " Locale: %s\n", n_prnt(t->str), (uint64_t)rv, (uintptr_t)rs, get_current_locale_str()); | ||
1720 | } | ||
1721 | else if (rv != test_val) | ||
1722 | { | ||
1723 | t_failed++; | ||
1724 | c_failed[i] = !0; | ||
1725 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", &ret_val) modified value of ret_val" | ||
1726 | " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 "). Locale: %s\n", | ||
1727 | n_prnt(t->str), (uint64_t)test_val, (uint64_t)rv, get_current_locale_str()); | ||
1728 | } | ||
1729 | } | ||
1730 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
1731 | printf("PASSED: MHD_strx_to_sizet_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n", | ||
1732 | n_prnt(t->str)); | ||
1733 | } | ||
1734 | } | ||
1735 | return t_failed; | ||
1736 | } | ||
1737 | |||
1738 | |||
1739 | int check_strx_to_sizet_n_valid(void) | ||
1740 | { | ||
1741 | size_t t_failed = 0; | ||
1742 | size_t i, j; | ||
1743 | static const size_t n_checks = sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]); | ||
1744 | int c_failed[n_checks]; | ||
1745 | |||
1746 | memset(c_failed, 0, sizeof(c_failed)); | ||
1747 | |||
1748 | for(j = 0; j < locale_name_count; j++) | ||
1749 | { | ||
1750 | set_test_locale(j); /* setlocale() can be slow! */ | ||
1751 | for(i = 0; i < n_checks; i++) | ||
1752 | { | ||
1753 | size_t rv; | ||
1754 | size_t rs = 0; | ||
1755 | size_t len; | ||
1756 | const struct str_with_value * const t = xdstrs_w_values + i; | ||
1757 | |||
1758 | #if SIZE_MAX != UINT64_MAX | ||
1759 | if (t->val > SIZE_MAX) | ||
1760 | continue; /* number is too high for this function */ | ||
1761 | #endif /* SIZE_MAX != UINT64_MAX */ | ||
1762 | |||
1763 | if (t->str.len < t->num_of_digt) | ||
1764 | { | ||
1765 | fprintf(stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" | ||
1766 | " to be less or equal to str.len (%u).\n", | ||
1767 | (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned int) t->str.len); | ||
1768 | return -1; | ||
1769 | } | ||
1770 | for (len = t->num_of_digt; len <= t->str.len + 1 && !c_failed[i]; len++) | ||
1771 | { | ||
1772 | rv = 2352932; /* some random value */ | ||
1773 | rs = MHD_strx_to_sizet_n_(t->str.str, len, &rv); | ||
1774 | if (rs != t->num_of_digt) | ||
1775 | { | ||
1776 | t_failed++; | ||
1777 | c_failed[i] = !0; | ||
1778 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")" | ||
1779 | " returned %" PRIuPTR ", while expecting %d. Locale: %s\n", | ||
1780 | n_prnt(t->str.str), (intptr_t)len, (uint64_t)rv, (intptr_t)rs, | ||
1781 | (int)t->num_of_digt, get_current_locale_str()); | ||
1782 | } | ||
1783 | if (rv != t->val) | ||
1784 | { | ||
1785 | t_failed++; | ||
1786 | c_failed[i] = !0; | ||
1787 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")" | ||
1788 | " converted string to value 0x%" PRIX64 ", while expecting result 0x%" PRIX64 | ||
1789 | ". Locale: %s\n", n_prnt(t->str.str), (intptr_t)len, (uint64_t)rv, (uint64_t)rv, | ||
1790 | t->val, get_current_locale_str()); | ||
1791 | } | ||
1792 | } | ||
1793 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
1794 | printf("PASSED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR ", ->0x%" PRIX64 ")" | ||
1795 | " == %" PRIuPTR "\n", n_prnt(t->str.str), (intptr_t)t->num_of_digt, | ||
1796 | (intptr_t)t->str.len + 1, (uint64_t)rv, rs); | ||
1797 | } | ||
1798 | } | ||
1799 | return t_failed; | ||
1800 | } | ||
1801 | |||
1802 | |||
1803 | int check_strx_to_sizet_n_all_chars(void) | ||
1804 | { | ||
1805 | static const size_t n_checks = 256; /* from 0 to 255 */ | ||
1806 | int c_failed[n_checks]; | ||
1807 | size_t t_failed = 0; | ||
1808 | size_t j; | ||
1809 | |||
1810 | memset(c_failed, 0, sizeof(c_failed)); | ||
1811 | |||
1812 | for(j = 0; j < locale_name_count; j++) | ||
1813 | { | ||
1814 | unsigned int c; | ||
1815 | size_t test_val; | ||
1816 | |||
1817 | set_test_locale(j); /* setlocale() can be slow! */ | ||
1818 | for(c = 0; c < n_checks; c++) | ||
1819 | { | ||
1820 | static const size_t rnd_val = 98372558; | ||
1821 | size_t rs; | ||
1822 | size_t len; | ||
1823 | |||
1824 | if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')) | ||
1825 | continue; /* skip xdigits */ | ||
1826 | |||
1827 | for (len = 0; len <= 5; len++) | ||
1828 | { | ||
1829 | for(test_val = 0; test_val <= rnd_val&& !c_failed[c]; test_val += rnd_val) | ||
1830 | { | ||
1831 | char test_str[] = "0123"; | ||
1832 | size_t rv = test_val; | ||
1833 | |||
1834 | test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */ | ||
1835 | rs = MHD_strx_to_sizet_n_(test_str, len, &rv); | ||
1836 | if (rs != 0) | ||
1837 | { | ||
1838 | t_failed++; | ||
1839 | c_failed[c] = !0; | ||
1840 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")" | ||
1841 | " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", | ||
1842 | n_prnt(test_str), (uintptr_t)len, (uint64_t)rv, (uintptr_t)rs, get_current_locale_str()); | ||
1843 | } | ||
1844 | else if (rv != test_val) | ||
1845 | { | ||
1846 | t_failed++; | ||
1847 | c_failed[c] = !0; | ||
1848 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", &ret_val)" | ||
1849 | " modified value of ret_val (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 ")." | ||
1850 | " Locale: %s\n", | ||
1851 | n_prnt(test_str), (uintptr_t)len, (uint64_t)test_val, (uint64_t)rv, get_current_locale_str()); | ||
1852 | } | ||
1853 | } | ||
1854 | } | ||
1855 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[c]) | ||
1856 | { | ||
1857 | char test_str[] = "0123"; | ||
1858 | test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */ | ||
1859 | |||
1860 | printf("PASSED: MHD_strx_to_sizet_n_(\"%s\", 0..5, &ret_val) == 0, value of ret_val is unmodified\n", | ||
1861 | n_prnt(test_str)); | ||
1862 | } | ||
1863 | } | ||
1864 | } | ||
1865 | return t_failed; | ||
1866 | } | ||
1867 | |||
1868 | |||
1869 | int check_strx_to_sizet_n_overflow(void) | ||
1870 | { | ||
1871 | size_t t_failed = 0; | ||
1872 | size_t i, j; | ||
1873 | static const size_t n_checks1 = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]); | ||
1874 | #if SIZE_MAX != UINT64_MAX | ||
1875 | static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]) + | ||
1876 | sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]); | ||
1877 | #else /* SIZE_MAX == UINT64_MAX */ | ||
1878 | static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]); | ||
1879 | #endif /* SIZE_MAX == UINT64_MAX */ | ||
1880 | int c_failed[n_checks]; | ||
1881 | |||
1882 | memset(c_failed, 0, sizeof(c_failed)); | ||
1883 | |||
1884 | for(j = 0; j < locale_name_count; j++) | ||
1885 | { | ||
1886 | set_test_locale(j); /* setlocale() can be slow! */ | ||
1887 | for(i = 0; i < n_checks; i++) | ||
1888 | { | ||
1889 | size_t rs; | ||
1890 | static const size_t rnd_val = 4; | ||
1891 | size_t len; | ||
1892 | const char * str; | ||
1893 | size_t min_len, max_len; | ||
1894 | if (i < n_checks1) | ||
1895 | { | ||
1896 | const struct str_with_len * const t = strx_ovflw + i; | ||
1897 | str = t->str; | ||
1898 | min_len = t->len; | ||
1899 | max_len = t->len + 1; | ||
1900 | } | ||
1901 | #if SIZE_MAX != UINT64_MAX | ||
1902 | else | ||
1903 | { | ||
1904 | const struct str_with_value * const t = xdstrs_w_values + (i - n_checks1); | ||
1905 | if (t->val <= SIZE_MAX) | ||
1906 | continue; /* check only strings that should overflow size_t */ | ||
1907 | |||
1908 | if (t->str.len < t->num_of_digt) | ||
1909 | { | ||
1910 | fprintf(stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" | ||
1911 | " to be less or equal to str.len (%u).\n", | ||
1912 | (unsigned int) (i - n_checks1), (unsigned int) t->num_of_digt, | ||
1913 | (unsigned int) t->str.len); | ||
1914 | return -1; | ||
1915 | } | ||
1916 | str = t->str.str; | ||
1917 | min_len = t->num_of_digt; | ||
1918 | max_len = t->str.len + 1; | ||
1919 | } | ||
1920 | #else /* SIZE_MAX == UINT64_MAX */ | ||
1921 | else | ||
1922 | continue; /* silent compiler warning */ | ||
1923 | #endif /* SIZE_MAX == UINT64_MAX */ | ||
1924 | |||
1925 | for (len = min_len; len <= max_len; len++) | ||
1926 | { | ||
1927 | size_t test_val; | ||
1928 | for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) | ||
1929 | { | ||
1930 | size_t rv = test_val; | ||
1931 | |||
1932 | rs = MHD_strx_to_sizet_n_(str, len, &rv); | ||
1933 | if (rs != 0) | ||
1934 | { | ||
1935 | t_failed++; | ||
1936 | c_failed[i] = !0; | ||
1937 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")" | ||
1938 | " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", | ||
1939 | n_prnt(str), (uintptr_t)len, (uint64_t)rv, (uintptr_t)rs, get_current_locale_str()); | ||
1940 | } | ||
1941 | else if (rv != test_val) | ||
1942 | { | ||
1943 | t_failed++; | ||
1944 | c_failed[i] = !0; | ||
1945 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", &ret_val)" | ||
1946 | " modified value of ret_val (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 ")." | ||
1947 | " Locale: %s\n", n_prnt(str), (uintptr_t)len, (uint64_t)test_val, (uint64_t)rv, | ||
1948 | get_current_locale_str()); | ||
1949 | } | ||
1950 | } | ||
1951 | } | ||
1952 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
1953 | printf("PASSED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR ", &ret_val) == 0," | ||
1954 | " value of ret_val is unmodified\n", n_prnt(str), (uintptr_t)min_len, | ||
1955 | (uintptr_t)max_len); | ||
1956 | } | ||
1957 | } | ||
1958 | return t_failed; | ||
1959 | } | ||
1960 | |||
1961 | |||
1962 | int check_strx_to_sizet_n_no_val(void) | ||
1963 | { | ||
1964 | size_t t_failed = 0; | ||
1965 | size_t i, j; | ||
1966 | static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]); | ||
1967 | int c_failed[n_checks]; | ||
1968 | |||
1969 | memset(c_failed, 0, sizeof(c_failed)); | ||
1970 | |||
1971 | for(j = 0; j < locale_name_count; j++) | ||
1972 | { | ||
1973 | set_test_locale(j); /* setlocale() can be slow! */ | ||
1974 | for(i = 0; i < n_checks; i++) | ||
1975 | { | ||
1976 | size_t rs; | ||
1977 | const struct str_with_len * const t = str_no_num + i; | ||
1978 | static const size_t rnd_val = 3214314212; | ||
1979 | size_t len; | ||
1980 | |||
1981 | for (len = 0; len <= t->len + 1; len++) | ||
1982 | { | ||
1983 | size_t test_val; | ||
1984 | for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) | ||
1985 | { | ||
1986 | size_t rv = test_val; | ||
1987 | |||
1988 | rs = MHD_strx_to_sizet_n_(t->str, len, &rv); | ||
1989 | if (rs != 0) | ||
1990 | { | ||
1991 | t_failed++; | ||
1992 | c_failed[i] = !0; | ||
1993 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")" | ||
1994 | " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", | ||
1995 | n_prnt(t->str), (uintptr_t)len, (uint64_t)rv, (uintptr_t)rs, get_current_locale_str()); | ||
1996 | } | ||
1997 | else if (rv != test_val) | ||
1998 | { | ||
1999 | t_failed++; | ||
2000 | c_failed[i] = !0; | ||
2001 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", &ret_val)" | ||
2002 | " modified value of ret_val (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 ")." | ||
2003 | " Locale: %s\n", n_prnt(t->str), (uintptr_t)len, (uint64_t)test_val, (uint64_t)rv, | ||
2004 | get_current_locale_str()); | ||
2005 | } | ||
2006 | } | ||
2007 | } | ||
2008 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
2009 | printf("PASSED: MHD_strx_to_sizet_n_(\"%s\", 0..%" PRIuPTR ", &ret_val) == 0," | ||
2010 | " value of ret_val is unmodified\n", n_prnt(t->str), | ||
2011 | (uintptr_t)t->len + 1); | ||
2012 | } | ||
2013 | } | ||
2014 | return t_failed; | ||
2015 | } | ||
2016 | |||
2017 | |||
2018 | int check_strx_to_uint32_valid(void) | ||
2019 | { | ||
2020 | size_t t_failed = 0; | ||
2021 | size_t i, j; | ||
2022 | static const size_t n_checks = sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]); | ||
2023 | int c_failed[n_checks]; | ||
2024 | |||
2025 | memset(c_failed, 0, sizeof(c_failed)); | ||
2026 | |||
2027 | for(j = 0; j < locale_name_count; j++) | ||
2028 | { | ||
2029 | set_test_locale(j); /* setlocale() can be slow! */ | ||
2030 | for(i = 0; i < n_checks; i++) | ||
2031 | { | ||
2032 | uint32_t rv; | ||
2033 | size_t rs; | ||
2034 | const struct str_with_value * const t = xdstrs_w_values + i; | ||
2035 | |||
2036 | if (t->val > UINT32_MAX) | ||
2037 | continue; /* number is too high for this function */ | ||
2038 | |||
2039 | if (c_failed[i]) | ||
2040 | continue; /* skip already failed checks */ | ||
2041 | |||
2042 | if (t->str.len < t->num_of_digt) | ||
2043 | { | ||
2044 | fprintf(stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" | ||
2045 | " to be less or equal to str.len (%u).\n", | ||
2046 | (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned int) t->str.len); | ||
2047 | return -1; | ||
2048 | } | ||
2049 | rv = 1458532; /* some random value */ | ||
2050 | rs = MHD_strx_to_uint32_(t->str.str, &rv); | ||
2051 | if (rs != t->num_of_digt) | ||
2052 | { | ||
2053 | t_failed++; | ||
2054 | c_failed[i] = !0; | ||
2055 | fprintf(stderr, "FAILED: MHD_strx_to_uint32_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting %d." | ||
2056 | " Locale: %s\n", n_prnt(t->str.str), (uint64_t)rv, (intptr_t)rs, (int)t->num_of_digt, get_current_locale_str()); | ||
2057 | } | ||
2058 | if (rv != t->val) | ||
2059 | { | ||
2060 | t_failed++; | ||
2061 | c_failed[i] = !0; | ||
2062 | fprintf(stderr, "FAILED: MHD_strx_to_uint32_(\"%s\", ->0x%" PRIX64 ") converted string to value 0x%" PRIX64 "," | ||
2063 | " while expecting result 0x%" PRIX64 ". Locale: %s\n", n_prnt(t->str.str), (uint64_t)rv, (uint64_t)rv, | ||
2064 | t->val, get_current_locale_str()); | ||
2065 | } | ||
2066 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
2067 | printf("PASSED: MHD_strx_to_uint32_(\"%s\", ->0x%" PRIX64 ") == %" PRIuPTR "\n", | ||
2068 | n_prnt(t->str.str), (uint64_t)rv, rs); | ||
2069 | } | ||
2070 | } | ||
2071 | return t_failed; | ||
2072 | } | ||
2073 | |||
2074 | |||
2075 | int check_strx_to_uint32_all_chars(void) | ||
2076 | { | ||
2077 | static const size_t n_checks = 256; /* from 0 to 255 */ | ||
2078 | int c_failed[n_checks]; | ||
2079 | size_t t_failed = 0; | ||
2080 | size_t j; | ||
2081 | |||
2082 | memset(c_failed, 0, sizeof(c_failed)); | ||
2083 | |||
2084 | for(j = 0; j < locale_name_count; j++) | ||
2085 | { | ||
2086 | unsigned int c; | ||
2087 | uint32_t test_val; | ||
2088 | |||
2089 | set_test_locale(j); /* setlocale() can be slow! */ | ||
2090 | for(c = 0; c < n_checks; c++) | ||
2091 | { | ||
2092 | static const uint32_t rnd_val = 234234; | ||
2093 | size_t rs; | ||
2094 | if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') ||(c >= 'a' && c <= 'f')) | ||
2095 | continue; /* skip xdigits */ | ||
2096 | for(test_val = 0; test_val <= rnd_val&& !c_failed[c]; test_val += rnd_val) | ||
2097 | { | ||
2098 | char test_str[] = "0123"; | ||
2099 | uint32_t rv = test_val; | ||
2100 | |||
2101 | test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */ | ||
2102 | rs = MHD_strx_to_uint32_(test_str, &rv); | ||
2103 | if (rs != 0) | ||
2104 | { | ||
2105 | t_failed++; | ||
2106 | c_failed[c] = !0; | ||
2107 | fprintf(stderr, "FAILED: MHD_strx_to_uint32_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting zero." | ||
2108 | " Locale: %s\n", n_prnt(test_str), (uint64_t)rv, (uintptr_t)rs, get_current_locale_str()); | ||
2109 | } | ||
2110 | else if (rv != test_val) | ||
2111 | { | ||
2112 | t_failed++; | ||
2113 | c_failed[c] = !0; | ||
2114 | fprintf(stderr, "FAILED: MHD_strx_to_uint32_(\"%s\", &ret_val) modified value of ret_val" | ||
2115 | " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 "). Locale: %s\n", | ||
2116 | n_prnt(test_str), (uint64_t)test_val, (uint64_t)rv, get_current_locale_str()); | ||
2117 | } | ||
2118 | } | ||
2119 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[c]) | ||
2120 | { | ||
2121 | char test_str[] = "0123"; | ||
2122 | test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */ | ||
2123 | |||
2124 | printf("PASSED: MHD_strx_to_uint32_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n", | ||
2125 | n_prnt(test_str)); | ||
2126 | } | ||
2127 | } | ||
2128 | } | ||
2129 | return t_failed; | ||
2130 | } | ||
2131 | |||
2132 | |||
2133 | int check_strx_to_uint32_overflow(void) | ||
2134 | { | ||
2135 | size_t t_failed = 0; | ||
2136 | size_t i, j; | ||
2137 | static const size_t n_checks1 = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]); | ||
2138 | static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]) + | ||
2139 | sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]); | ||
2140 | int c_failed[n_checks]; | ||
2141 | |||
2142 | memset(c_failed, 0, sizeof(c_failed)); | ||
2143 | |||
2144 | for(j = 0; j < locale_name_count; j++) | ||
2145 | { | ||
2146 | set_test_locale(j); /* setlocale() can be slow! */ | ||
2147 | for(i = 0; i < n_checks; i++) | ||
2148 | { | ||
2149 | size_t rs; | ||
2150 | static const uint32_t rnd_val = 74218431; | ||
2151 | uint32_t test_val; | ||
2152 | const char * str; | ||
2153 | if (i < n_checks1) | ||
2154 | { | ||
2155 | const struct str_with_len * const t = strx_ovflw + i; | ||
2156 | str = t->str; | ||
2157 | } | ||
2158 | else | ||
2159 | { | ||
2160 | const struct str_with_value * const t = xdstrs_w_values + (i - n_checks1); | ||
2161 | if (t->val <= UINT32_MAX) | ||
2162 | continue; /* check only strings that should overflow uint32_t */ | ||
2163 | str = t->str.str; | ||
2164 | } | ||
2165 | |||
2166 | |||
2167 | for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) | ||
2168 | { | ||
2169 | uint32_t rv = test_val; | ||
2170 | |||
2171 | rs = MHD_strx_to_uint32_(str, &rv); | ||
2172 | if (rs != 0) | ||
2173 | { | ||
2174 | t_failed++; | ||
2175 | c_failed[i] = !0; | ||
2176 | fprintf(stderr, "FAILED: MHD_strx_to_uint32_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting zero." | ||
2177 | " Locale: %s\n", n_prnt(str), (uint64_t)rv, (uintptr_t)rs, get_current_locale_str()); | ||
2178 | } | ||
2179 | else if (rv != test_val) | ||
2180 | { | ||
2181 | t_failed++; | ||
2182 | c_failed[i] = !0; | ||
2183 | fprintf(stderr, "FAILED: MHD_strx_to_uint32_(\"%s\", &ret_val) modified value of ret_val" | ||
2184 | " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 "). Locale: %s\n", | ||
2185 | n_prnt(str), (uint64_t)test_val, (uint64_t)rv, get_current_locale_str()); | ||
2186 | } | ||
2187 | } | ||
2188 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
2189 | printf("PASSED: MHD_strx_to_uint32_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n", | ||
2190 | n_prnt(str)); | ||
2191 | } | ||
2192 | } | ||
2193 | return t_failed; | ||
2194 | } | ||
2195 | |||
2196 | |||
2197 | int check_strx_to_uint32_no_val(void) | ||
2198 | { | ||
2199 | size_t t_failed = 0; | ||
2200 | size_t i, j; | ||
2201 | static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]); | ||
2202 | int c_failed[n_checks]; | ||
2203 | |||
2204 | memset(c_failed, 0, sizeof(c_failed)); | ||
2205 | |||
2206 | for(j = 0; j < locale_name_count; j++) | ||
2207 | { | ||
2208 | set_test_locale(j); /* setlocale() can be slow! */ | ||
2209 | for(i = 0; i < n_checks; i++) | ||
2210 | { | ||
2211 | size_t rs; | ||
2212 | const struct str_with_len * const t = str_no_num + i; | ||
2213 | static const uint32_t rnd_val = 74218431; | ||
2214 | uint32_t test_val; | ||
2215 | |||
2216 | for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) | ||
2217 | { | ||
2218 | uint32_t rv = test_val; | ||
2219 | |||
2220 | rs = MHD_strx_to_uint32_(t->str, &rv); | ||
2221 | if (rs != 0) | ||
2222 | { | ||
2223 | t_failed++; | ||
2224 | c_failed[i] = !0; | ||
2225 | fprintf(stderr, "FAILED: MHD_strx_to_uint32_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting zero." | ||
2226 | " Locale: %s\n", n_prnt(t->str), (uint64_t)rv, (uintptr_t)rs, get_current_locale_str()); | ||
2227 | } | ||
2228 | else if (rv != test_val) | ||
2229 | { | ||
2230 | t_failed++; | ||
2231 | c_failed[i] = !0; | ||
2232 | fprintf(stderr, "FAILED: MHD_strx_to_uint32_(\"%s\", &ret_val) modified value of ret_val" | ||
2233 | " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 "). Locale: %s\n", | ||
2234 | n_prnt(t->str), (uint64_t)test_val, (uint64_t)rv, get_current_locale_str()); | ||
2235 | } | ||
2236 | } | ||
2237 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
2238 | printf("PASSED: MHD_strx_to_uint32_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n", | ||
2239 | n_prnt(t->str)); | ||
2240 | } | ||
2241 | } | ||
2242 | return t_failed; | ||
2243 | } | ||
2244 | |||
2245 | |||
2246 | int check_strx_to_uint32_n_valid(void) | ||
2247 | { | ||
2248 | size_t t_failed = 0; | ||
2249 | size_t i, j; | ||
2250 | static const size_t n_checks = sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]); | ||
2251 | int c_failed[n_checks]; | ||
2252 | |||
2253 | memset(c_failed, 0, sizeof(c_failed)); | ||
2254 | |||
2255 | for(j = 0; j < locale_name_count; j++) | ||
2256 | { | ||
2257 | set_test_locale(j); /* setlocale() can be slow! */ | ||
2258 | for(i = 0; i < n_checks; i++) | ||
2259 | { | ||
2260 | uint32_t rv; | ||
2261 | size_t rs = 0; | ||
2262 | size_t len; | ||
2263 | const struct str_with_value * const t = xdstrs_w_values + i; | ||
2264 | |||
2265 | if (t->val > UINT32_MAX) | ||
2266 | continue; /* number is too high for this function */ | ||
2267 | |||
2268 | if (t->str.len < t->num_of_digt) | ||
2269 | { | ||
2270 | fprintf(stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" | ||
2271 | " to be less or equal to str.len (%u).\n", | ||
2272 | (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned int) t->str.len); | ||
2273 | return -1; | ||
2274 | } | ||
2275 | for (len = t->num_of_digt; len <= t->str.len + 1 && !c_failed[i]; len++) | ||
2276 | { | ||
2277 | rv = 2352932; /* some random value */ | ||
2278 | rs = MHD_strx_to_uint32_n_(t->str.str, len, &rv); | ||
2279 | if (rs != t->num_of_digt) | ||
2280 | { | ||
2281 | t_failed++; | ||
2282 | c_failed[i] = !0; | ||
2283 | fprintf(stderr, "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")" | ||
2284 | " returned %" PRIuPTR ", while expecting %d. Locale: %s\n", | ||
2285 | n_prnt(t->str.str), (intptr_t)len, (uint64_t)rv, (intptr_t)rs, | ||
2286 | (int)t->num_of_digt, get_current_locale_str()); | ||
2287 | } | ||
2288 | if (rv != t->val) | ||
2289 | { | ||
2290 | t_failed++; | ||
2291 | c_failed[i] = !0; | ||
2292 | fprintf(stderr, "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")" | ||
2293 | " converted string to value 0x%" PRIX64 ", while expecting result 0x%" PRIX64 | ||
2294 | ". Locale: %s\n", n_prnt(t->str.str), (intptr_t)len, (uint64_t)rv, (uint64_t)rv, | ||
2295 | t->val, get_current_locale_str()); | ||
2296 | } | ||
2297 | } | ||
2298 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
2299 | printf("PASSED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR ", ->0x%" PRIX64 ")" | ||
2300 | " == %" PRIuPTR "\n", n_prnt(t->str.str), (intptr_t)t->num_of_digt, | ||
2301 | (intptr_t)t->str.len + 1, (uint64_t)rv, rs); | ||
2302 | } | ||
2303 | } | ||
2304 | return t_failed; | ||
2305 | } | ||
2306 | |||
2307 | |||
2308 | int check_strx_to_uint32_n_all_chars(void) | ||
2309 | { | ||
2310 | static const size_t n_checks = 256; /* from 0 to 255 */ | ||
2311 | int c_failed[n_checks]; | ||
2312 | size_t t_failed = 0; | ||
2313 | size_t j; | ||
2314 | |||
2315 | memset(c_failed, 0, sizeof(c_failed)); | ||
2316 | |||
2317 | for(j = 0; j < locale_name_count; j++) | ||
2318 | { | ||
2319 | unsigned int c; | ||
2320 | uint32_t test_val; | ||
2321 | |||
2322 | set_test_locale(j); /* setlocale() can be slow! */ | ||
2323 | for(c = 0; c < n_checks; c++) | ||
2324 | { | ||
2325 | static const uint32_t rnd_val = 98372558; | ||
2326 | size_t rs; | ||
2327 | size_t len; | ||
2328 | |||
2329 | if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')) | ||
2330 | continue; /* skip xdigits */ | ||
2331 | |||
2332 | for (len = 0; len <= 5; len++) | ||
2333 | { | ||
2334 | for(test_val = 0; test_val <= rnd_val&& !c_failed[c]; test_val += rnd_val) | ||
2335 | { | ||
2336 | char test_str[] = "0123"; | ||
2337 | uint32_t rv = test_val; | ||
2338 | |||
2339 | test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */ | ||
2340 | rs = MHD_strx_to_uint32_n_(test_str, len, &rv); | ||
2341 | if (rs != 0) | ||
2342 | { | ||
2343 | t_failed++; | ||
2344 | c_failed[c] = !0; | ||
2345 | fprintf(stderr, "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")" | ||
2346 | " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", | ||
2347 | n_prnt(test_str), (uintptr_t)len, (uint64_t)rv, (uintptr_t)rs, get_current_locale_str()); | ||
2348 | } | ||
2349 | else if (rv != test_val) | ||
2350 | { | ||
2351 | t_failed++; | ||
2352 | c_failed[c] = !0; | ||
2353 | fprintf(stderr, "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", &ret_val)" | ||
2354 | " modified value of ret_val (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 ")." | ||
2355 | " Locale: %s\n", | ||
2356 | n_prnt(test_str), (uintptr_t)len, (uint64_t)test_val, (uint64_t)rv, get_current_locale_str()); | ||
2357 | } | ||
2358 | } | ||
2359 | } | ||
2360 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[c]) | ||
2361 | { | ||
2362 | char test_str[] = "0123"; | ||
2363 | test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */ | ||
2364 | |||
2365 | printf("PASSED: MHD_strx_to_uint32_n_(\"%s\", 0..5, &ret_val) == 0, value of ret_val is unmodified\n", | ||
2366 | n_prnt(test_str)); | ||
2367 | } | ||
2368 | } | ||
2369 | } | ||
2370 | return t_failed; | ||
2371 | } | ||
2372 | |||
2373 | |||
2374 | int check_strx_to_uint32_n_overflow(void) | ||
2375 | { | ||
2376 | size_t t_failed = 0; | ||
2377 | size_t i, j; | ||
2378 | static const size_t n_checks1 = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]); | ||
2379 | static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]) + | ||
2380 | sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]); | ||
2381 | int c_failed[n_checks]; | ||
2382 | |||
2383 | memset(c_failed, 0, sizeof(c_failed)); | ||
2384 | |||
2385 | for(j = 0; j < locale_name_count; j++) | ||
2386 | { | ||
2387 | set_test_locale(j); /* setlocale() can be slow! */ | ||
2388 | for(i = 0; i < n_checks; i++) | ||
2389 | { | ||
2390 | size_t rs; | ||
2391 | static const uint32_t rnd_val = 4; | ||
2392 | size_t len; | ||
2393 | const char * str; | ||
2394 | size_t min_len, max_len; | ||
2395 | if (i < n_checks1) | ||
2396 | { | ||
2397 | const struct str_with_len * const t = strx_ovflw + i; | ||
2398 | str = t->str; | ||
2399 | min_len = t->len; | ||
2400 | max_len = t->len + 1; | ||
2401 | } | ||
2402 | else | ||
2403 | { | ||
2404 | const struct str_with_value * const t = xdstrs_w_values + (i - n_checks1); | ||
2405 | if (t->val <= UINT32_MAX) | ||
2406 | continue; /* check only strings that should overflow uint32_t */ | ||
2407 | |||
2408 | if (t->str.len < t->num_of_digt) | ||
2409 | { | ||
2410 | fprintf(stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" | ||
2411 | " to be less or equal to str.len (%u).\n", | ||
2412 | (unsigned int) (i - n_checks1), (unsigned int) t->num_of_digt, | ||
2413 | (unsigned int) t->str.len); | ||
2414 | return -1; | ||
2415 | } | ||
2416 | str = t->str.str; | ||
2417 | min_len = t->num_of_digt; | ||
2418 | max_len = t->str.len + 1; | ||
2419 | } | ||
2420 | |||
2421 | for (len = min_len; len <= max_len; len++) | ||
2422 | { | ||
2423 | uint32_t test_val; | ||
2424 | for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) | ||
2425 | { | ||
2426 | uint32_t rv = test_val; | ||
2427 | |||
2428 | rs = MHD_strx_to_uint32_n_(str, len, &rv); | ||
2429 | if (rs != 0) | ||
2430 | { | ||
2431 | t_failed++; | ||
2432 | c_failed[i] = !0; | ||
2433 | fprintf(stderr, "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")" | ||
2434 | " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", | ||
2435 | n_prnt(str), (uintptr_t)len, (uint64_t)rv, (uintptr_t)rs, get_current_locale_str()); | ||
2436 | } | ||
2437 | else if (rv != test_val) | ||
2438 | { | ||
2439 | t_failed++; | ||
2440 | c_failed[i] = !0; | ||
2441 | fprintf(stderr, "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", &ret_val)" | ||
2442 | " modified value of ret_val (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 ")." | ||
2443 | " Locale: %s\n", n_prnt(str), (uintptr_t)len, (uint64_t)test_val, (uint64_t)rv, | ||
2444 | get_current_locale_str()); | ||
2445 | } | ||
2446 | } | ||
2447 | } | ||
2448 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
2449 | printf("PASSED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR ", &ret_val) == 0," | ||
2450 | " value of ret_val is unmodified\n", n_prnt(str), (uintptr_t)min_len, | ||
2451 | (uintptr_t)max_len); | ||
2452 | } | ||
2453 | } | ||
2454 | return t_failed; | ||
2455 | } | ||
2456 | |||
2457 | |||
2458 | int check_strx_to_uint32_n_no_val(void) | ||
2459 | { | ||
2460 | size_t t_failed = 0; | ||
2461 | size_t i, j; | ||
2462 | static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]); | ||
2463 | int c_failed[n_checks]; | ||
2464 | |||
2465 | memset(c_failed, 0, sizeof(c_failed)); | ||
2466 | |||
2467 | for(j = 0; j < locale_name_count; j++) | ||
2468 | { | ||
2469 | set_test_locale(j); /* setlocale() can be slow! */ | ||
2470 | for(i = 0; i < n_checks; i++) | ||
2471 | { | ||
2472 | size_t rs; | ||
2473 | const struct str_with_len * const t = str_no_num + i; | ||
2474 | static const uint32_t rnd_val = 3214314212; | ||
2475 | size_t len; | ||
2476 | |||
2477 | for (len = 0; len <= t->len + 1; len++) | ||
2478 | { | ||
2479 | uint32_t test_val; | ||
2480 | for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) | ||
2481 | { | ||
2482 | uint32_t rv = test_val; | ||
2483 | |||
2484 | rs = MHD_strx_to_uint32_n_(t->str, len, &rv); | ||
2485 | if (rs != 0) | ||
2486 | { | ||
2487 | t_failed++; | ||
2488 | c_failed[i] = !0; | ||
2489 | fprintf(stderr, "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")" | ||
2490 | " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", | ||
2491 | n_prnt(t->str), (uintptr_t)len, (uint64_t)rv, (uintptr_t)rs, get_current_locale_str()); | ||
2492 | } | ||
2493 | else if (rv != test_val) | ||
2494 | { | ||
2495 | t_failed++; | ||
2496 | c_failed[i] = !0; | ||
2497 | fprintf(stderr, "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", &ret_val)" | ||
2498 | " modified value of ret_val (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 ")." | ||
2499 | " Locale: %s\n", n_prnt(t->str), (uintptr_t)len, (uint64_t)test_val, (uint64_t)rv, | ||
2500 | get_current_locale_str()); | ||
2501 | } | ||
2502 | } | ||
2503 | } | ||
2504 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
2505 | printf("PASSED: MHD_strx_to_uint32_n_(\"%s\", 0..%" PRIuPTR ", &ret_val) == 0," | ||
2506 | " value of ret_val is unmodified\n", n_prnt(t->str), | ||
2507 | (uintptr_t)t->len + 1); | ||
2508 | } | ||
2509 | } | ||
2510 | return t_failed; | ||
2511 | } | ||
2512 | |||
2513 | |||
2514 | int check_strx_to_uint64_valid(void) | ||
2515 | { | ||
2516 | size_t t_failed = 0; | ||
2517 | size_t i, j; | ||
2518 | static const size_t n_checks = sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]); | ||
2519 | int c_failed[n_checks]; | ||
2520 | |||
2521 | memset(c_failed, 0, sizeof(c_failed)); | ||
2522 | |||
2523 | for(j = 0; j < locale_name_count; j++) | ||
2524 | { | ||
2525 | set_test_locale(j); /* setlocale() can be slow! */ | ||
2526 | for(i = 0; i < n_checks; i++) | ||
2527 | { | ||
2528 | uint64_t rv; | ||
2529 | size_t rs; | ||
2530 | const struct str_with_value * const t = xdstrs_w_values + i; | ||
2531 | |||
2532 | if (c_failed[i]) | ||
2533 | continue; /* skip already failed checks */ | ||
2534 | |||
2535 | if (t->str.len < t->num_of_digt) | ||
2536 | { | ||
2537 | fprintf(stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" | ||
2538 | " to be less or equal to str.len (%u).\n", | ||
2539 | (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned int) t->str.len); | ||
2540 | return -1; | ||
2541 | } | ||
2542 | rv = 1458532; /* some random value */ | ||
2543 | rs = MHD_strx_to_uint64_(t->str.str, &rv); | ||
2544 | if (rs != t->num_of_digt) | ||
2545 | { | ||
2546 | t_failed++; | ||
2547 | c_failed[i] = !0; | ||
2548 | fprintf(stderr, "FAILED: MHD_strx_to_uint64_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting %d." | ||
2549 | " Locale: %s\n", n_prnt(t->str.str), rv, (intptr_t)rs, (int)t->num_of_digt, get_current_locale_str()); | ||
2550 | } | ||
2551 | if (rv != t->val) | ||
2552 | { | ||
2553 | t_failed++; | ||
2554 | c_failed[i] = !0; | ||
2555 | fprintf(stderr, "FAILED: MHD_strx_to_uint64_(\"%s\", ->0x%" PRIX64 ") converted string to value 0x%" PRIX64 "," | ||
2556 | " while expecting result 0x%" PRIX64 ". Locale: %s\n", n_prnt(t->str.str), rv, rv, | ||
2557 | t->val, get_current_locale_str()); | ||
2558 | } | ||
2559 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
2560 | printf("PASSED: MHD_strx_to_uint64_(\"%s\", ->0x%" PRIX64 ") == %" PRIuPTR "\n", | ||
2561 | n_prnt(t->str.str), rv, rs); | ||
2562 | } | ||
2563 | } | ||
2564 | return t_failed; | ||
2565 | } | ||
2566 | |||
2567 | |||
2568 | int check_strx_to_uint64_all_chars(void) | ||
2569 | { | ||
2570 | static const size_t n_checks = 256; /* from 0 to 255 */ | ||
2571 | int c_failed[n_checks]; | ||
2572 | size_t t_failed = 0; | ||
2573 | size_t j; | ||
2574 | |||
2575 | memset(c_failed, 0, sizeof(c_failed)); | ||
2576 | |||
2577 | for(j = 0; j < locale_name_count; j++) | ||
2578 | { | ||
2579 | unsigned int c; | ||
2580 | uint64_t test_val; | ||
2581 | |||
2582 | set_test_locale(j); /* setlocale() can be slow! */ | ||
2583 | for(c = 0; c < n_checks; c++) | ||
2584 | { | ||
2585 | static const uint64_t rnd_val = 234234; | ||
2586 | size_t rs; | ||
2587 | if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')) | ||
2588 | continue; /* skip xdigits */ | ||
2589 | for(test_val = 0; test_val <= rnd_val&& !c_failed[c]; test_val += rnd_val) | ||
2590 | { | ||
2591 | char test_str[] = "0123"; | ||
2592 | uint64_t rv = test_val; | ||
2593 | |||
2594 | test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */ | ||
2595 | rs = MHD_strx_to_uint64_(test_str, &rv); | ||
2596 | if (rs != 0) | ||
2597 | { | ||
2598 | t_failed++; | ||
2599 | c_failed[c] = !0; | ||
2600 | fprintf(stderr, "FAILED: MHD_strx_to_uint64_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting zero." | ||
2601 | " Locale: %s\n", n_prnt(test_str), rv, (uintptr_t)rs, get_current_locale_str()); | ||
2602 | } | ||
2603 | else if (rv != test_val) | ||
2604 | { | ||
2605 | t_failed++; | ||
2606 | c_failed[c] = !0; | ||
2607 | fprintf(stderr, "FAILED: MHD_strx_to_uint64_(\"%s\", &ret_val) modified value of ret_val" | ||
2608 | " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 "). Locale: %s\n", | ||
2609 | n_prnt(test_str), test_val, rv, get_current_locale_str()); | ||
2610 | } | ||
2611 | } | ||
2612 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[c]) | ||
2613 | { | ||
2614 | char test_str[] = "0123"; | ||
2615 | test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */ | ||
2616 | |||
2617 | printf("PASSED: MHD_strx_to_uint64_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n", | ||
2618 | n_prnt(test_str)); | ||
2619 | } | ||
2620 | } | ||
2621 | } | ||
2622 | return t_failed; | ||
2623 | } | ||
2624 | |||
2625 | |||
2626 | int check_strx_to_uint64_overflow(void) | ||
2627 | { | ||
2628 | size_t t_failed = 0; | ||
2629 | size_t i, j; | ||
2630 | static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]); | ||
2631 | int c_failed[n_checks]; | ||
2632 | |||
2633 | memset(c_failed, 0, sizeof(c_failed)); | ||
2634 | |||
2635 | for(j = 0; j < locale_name_count; j++) | ||
2636 | { | ||
2637 | set_test_locale(j); /* setlocale() can be slow! */ | ||
2638 | for(i = 0; i < n_checks; i++) | ||
2639 | { | ||
2640 | size_t rs; | ||
2641 | const struct str_with_len * const t = strx_ovflw + i; | ||
2642 | static const uint64_t rnd_val = 74218431; | ||
2643 | uint64_t test_val; | ||
2644 | |||
2645 | for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) | ||
2646 | { | ||
2647 | uint64_t rv = test_val; | ||
2648 | |||
2649 | rs = MHD_strx_to_uint64_(t->str, &rv); | ||
2650 | if (rs != 0) | ||
2651 | { | ||
2652 | t_failed++; | ||
2653 | c_failed[i] = !0; | ||
2654 | fprintf(stderr, "FAILED: MHD_strx_to_uint64_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting zero." | ||
2655 | " Locale: %s\n", n_prnt(t->str), rv, (uintptr_t)rs, get_current_locale_str()); | ||
2656 | } | ||
2657 | else if (rv != test_val) | ||
2658 | { | ||
2659 | t_failed++; | ||
2660 | c_failed[i] = !0; | ||
2661 | fprintf(stderr, "FAILED: MHD_strx_to_uint64_(\"%s\", &ret_val) modified value of ret_val" | ||
2662 | " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 "). Locale: %s\n", | ||
2663 | n_prnt(t->str), test_val, rv, get_current_locale_str()); | ||
2664 | } | ||
2665 | } | ||
2666 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
2667 | printf("PASSED: MHD_strx_to_uint64_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n", | ||
2668 | n_prnt(t->str)); | ||
2669 | } | ||
2670 | } | ||
2671 | return t_failed; | ||
2672 | } | ||
2673 | |||
2674 | |||
2675 | int check_strx_to_uint64_no_val(void) | ||
2676 | { | ||
2677 | size_t t_failed = 0; | ||
2678 | size_t i, j; | ||
2679 | static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]); | ||
2680 | int c_failed[n_checks]; | ||
2681 | |||
2682 | memset(c_failed, 0, sizeof(c_failed)); | ||
2683 | |||
2684 | for(j = 0; j < locale_name_count; j++) | ||
2685 | { | ||
2686 | set_test_locale(j); /* setlocale() can be slow! */ | ||
2687 | for(i = 0; i < n_checks; i++) | ||
2688 | { | ||
2689 | size_t rs; | ||
2690 | const struct str_with_len * const t = str_no_num + i; | ||
2691 | static const uint64_t rnd_val = 74218431; | ||
2692 | uint64_t test_val; | ||
2693 | |||
2694 | for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) | ||
2695 | { | ||
2696 | uint64_t rv = test_val; | ||
2697 | |||
2698 | rs = MHD_strx_to_uint64_(t->str, &rv); | ||
2699 | if (rs != 0) | ||
2700 | { | ||
2701 | t_failed++; | ||
2702 | c_failed[i] = !0; | ||
2703 | fprintf(stderr, "FAILED: MHD_strx_to_uint64_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting zero." | ||
2704 | " Locale: %s\n", n_prnt(t->str), rv, (uintptr_t)rs, get_current_locale_str()); | ||
2705 | } | ||
2706 | else if (rv != test_val) | ||
2707 | { | ||
2708 | t_failed++; | ||
2709 | c_failed[i] = !0; | ||
2710 | fprintf(stderr, "FAILED: MHD_strx_to_uint64_(\"%s\", &ret_val) modified value of ret_val" | ||
2711 | " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 "). Locale: %s\n", | ||
2712 | n_prnt(t->str), test_val, rv, get_current_locale_str()); | ||
2713 | } | ||
2714 | } | ||
2715 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
2716 | printf("PASSED: MHD_strx_to_uint64_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n", | ||
2717 | n_prnt(t->str)); | ||
2718 | } | ||
2719 | } | ||
2720 | return t_failed; | ||
2721 | } | ||
2722 | |||
2723 | |||
2724 | int check_strx_to_uint64_n_valid(void) | ||
2725 | { | ||
2726 | size_t t_failed = 0; | ||
2727 | size_t i, j; | ||
2728 | static const size_t n_checks = sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]); | ||
2729 | int c_failed[n_checks]; | ||
2730 | |||
2731 | memset(c_failed, 0, sizeof(c_failed)); | ||
2732 | |||
2733 | for(j = 0; j < locale_name_count; j++) | ||
2734 | { | ||
2735 | set_test_locale(j); /* setlocale() can be slow! */ | ||
2736 | for(i = 0; i < n_checks; i++) | ||
2737 | { | ||
2738 | uint64_t rv; | ||
2739 | size_t rs = 0; | ||
2740 | size_t len; | ||
2741 | const struct str_with_value * const t = xdstrs_w_values + i; | ||
2742 | |||
2743 | if (t->str.len < t->num_of_digt) | ||
2744 | { | ||
2745 | fprintf(stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" | ||
2746 | " to be less or equal to str.len (%u).\n", | ||
2747 | (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned int) t->str.len); | ||
2748 | return -1; | ||
2749 | } | ||
2750 | for (len = t->num_of_digt; len <= t->str.len + 1 && !c_failed[i]; len++) | ||
2751 | { | ||
2752 | rv = 2352932; /* some random value */ | ||
2753 | rs = MHD_strx_to_uint64_n_(t->str.str, len, &rv); | ||
2754 | if (rs != t->num_of_digt) | ||
2755 | { | ||
2756 | t_failed++; | ||
2757 | c_failed[i] = !0; | ||
2758 | fprintf(stderr, "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")" | ||
2759 | " returned %" PRIuPTR ", while expecting %d. Locale: %s\n", | ||
2760 | n_prnt(t->str.str), (intptr_t)len, rv, (intptr_t)rs, | ||
2761 | (int)t->num_of_digt, get_current_locale_str()); | ||
2762 | } | ||
2763 | if (rv != t->val) | ||
2764 | { | ||
2765 | t_failed++; | ||
2766 | c_failed[i] = !0; | ||
2767 | fprintf(stderr, "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")" | ||
2768 | " converted string to value 0x%" PRIX64 ", while expecting result 0x%" PRIX64 | ||
2769 | ". Locale: %s\n", n_prnt(t->str.str), (intptr_t)len, rv, rv, | ||
2770 | t->val, get_current_locale_str()); | ||
2771 | } | ||
2772 | } | ||
2773 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
2774 | printf("PASSED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR ", ->0x%" PRIX64 ")" | ||
2775 | " == %" PRIuPTR "\n", n_prnt(t->str.str), (intptr_t)t->num_of_digt, | ||
2776 | (intptr_t)t->str.len + 1, rv, rs); | ||
2777 | } | ||
2778 | } | ||
2779 | return t_failed; | ||
2780 | } | ||
2781 | |||
2782 | |||
2783 | int check_strx_to_uint64_n_all_chars(void) | ||
2784 | { | ||
2785 | static const size_t n_checks = 256; /* from 0 to 255 */ | ||
2786 | int c_failed[n_checks]; | ||
2787 | size_t t_failed = 0; | ||
2788 | size_t j; | ||
2789 | |||
2790 | memset(c_failed, 0, sizeof(c_failed)); | ||
2791 | |||
2792 | for(j = 0; j < locale_name_count; j++) | ||
2793 | { | ||
2794 | unsigned int c; | ||
2795 | uint64_t test_val; | ||
2796 | |||
2797 | set_test_locale(j); /* setlocale() can be slow! */ | ||
2798 | for(c = 0; c < n_checks; c++) | ||
2799 | { | ||
2800 | static const uint64_t rnd_val = 98372558; | ||
2801 | size_t rs; | ||
2802 | size_t len; | ||
2803 | |||
2804 | if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')) | ||
2805 | continue; /* skip xdigits */ | ||
2806 | |||
2807 | for (len = 0; len <= 5; len++) | ||
2808 | { | ||
2809 | for(test_val = 0; test_val <= rnd_val&& !c_failed[c]; test_val += rnd_val) | ||
2810 | { | ||
2811 | char test_str[] = "0123"; | ||
2812 | uint64_t rv = test_val; | ||
2813 | |||
2814 | test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */ | ||
2815 | rs = MHD_strx_to_uint64_n_(test_str, len, &rv); | ||
2816 | if (rs != 0) | ||
2817 | { | ||
2818 | t_failed++; | ||
2819 | c_failed[c] = !0; | ||
2820 | fprintf(stderr, "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")" | ||
2821 | " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", | ||
2822 | n_prnt(test_str), (uintptr_t)len, rv, (uintptr_t)rs, get_current_locale_str()); | ||
2823 | } | ||
2824 | else if (rv != test_val) | ||
2825 | { | ||
2826 | t_failed++; | ||
2827 | c_failed[c] = !0; | ||
2828 | fprintf(stderr, "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", &ret_val)" | ||
2829 | " modified value of ret_val (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 ")." | ||
2830 | " Locale: %s\n", | ||
2831 | n_prnt(test_str), (uintptr_t)len, test_val, rv, get_current_locale_str()); | ||
2832 | } | ||
2833 | } | ||
2834 | } | ||
2835 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[c]) | ||
2836 | { | ||
2837 | char test_str[] = "0123"; | ||
2838 | test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */ | ||
2839 | |||
2840 | printf("PASSED: MHD_strx_to_uint64_n_(\"%s\", 0..5, &ret_val) == 0, value of ret_val is unmodified\n", | ||
2841 | n_prnt(test_str)); | ||
2842 | } | ||
2843 | } | ||
2844 | } | ||
2845 | return t_failed; | ||
2846 | } | ||
2847 | |||
2848 | |||
2849 | int check_strx_to_uint64_n_overflow(void) | ||
2850 | { | ||
2851 | size_t t_failed = 0; | ||
2852 | size_t i, j; | ||
2853 | static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]); | ||
2854 | int c_failed[n_checks]; | ||
2855 | |||
2856 | memset(c_failed, 0, sizeof(c_failed)); | ||
2857 | |||
2858 | for(j = 0; j < locale_name_count; j++) | ||
2859 | { | ||
2860 | set_test_locale(j); /* setlocale() can be slow! */ | ||
2861 | for(i = 0; i < n_checks; i++) | ||
2862 | { | ||
2863 | size_t rs; | ||
2864 | const struct str_with_len * const t = strx_ovflw + i; | ||
2865 | static const uint64_t rnd_val = 4; | ||
2866 | size_t len; | ||
2867 | |||
2868 | for (len = t->len; len <= t->len + 1; len++) | ||
2869 | { | ||
2870 | uint64_t test_val; | ||
2871 | for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) | ||
2872 | { | ||
2873 | uint64_t rv = test_val; | ||
2874 | |||
2875 | rs = MHD_strx_to_uint64_n_(t->str, len, &rv); | ||
2876 | if (rs != 0) | ||
2877 | { | ||
2878 | t_failed++; | ||
2879 | c_failed[i] = !0; | ||
2880 | fprintf(stderr, "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")" | ||
2881 | " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", | ||
2882 | n_prnt(t->str), (uintptr_t)len, rv, (uintptr_t)rs, get_current_locale_str()); | ||
2883 | } | ||
2884 | else if (rv != test_val) | ||
2885 | { | ||
2886 | t_failed++; | ||
2887 | c_failed[i] = !0; | ||
2888 | fprintf(stderr, "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", &ret_val)" | ||
2889 | " modified value of ret_val (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 ")." | ||
2890 | " Locale: %s\n", n_prnt(t->str), (uintptr_t)len, test_val, rv, | ||
2891 | get_current_locale_str()); | ||
2892 | } | ||
2893 | } | ||
2894 | } | ||
2895 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
2896 | printf("PASSED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR ", &ret_val) == 0," | ||
2897 | " value of ret_val is unmodified\n", n_prnt(t->str), (uintptr_t)t->len, | ||
2898 | (uintptr_t)t->len + 1); | ||
2899 | } | ||
2900 | } | ||
2901 | return t_failed; | ||
2902 | } | ||
2903 | |||
2904 | |||
2905 | int check_strx_to_uint64_n_no_val(void) | ||
2906 | { | ||
2907 | size_t t_failed = 0; | ||
2908 | size_t i, j; | ||
2909 | static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]); | ||
2910 | int c_failed[n_checks]; | ||
2911 | |||
2912 | memset(c_failed, 0, sizeof(c_failed)); | ||
2913 | |||
2914 | for(j = 0; j < locale_name_count; j++) | ||
2915 | { | ||
2916 | set_test_locale(j); /* setlocale() can be slow! */ | ||
2917 | for(i = 0; i < n_checks; i++) | ||
2918 | { | ||
2919 | size_t rs; | ||
2920 | const struct str_with_len * const t = str_no_num + i; | ||
2921 | static const uint64_t rnd_val = 3214314212; | ||
2922 | size_t len; | ||
2923 | |||
2924 | for (len = 0; len <= t->len + 1; len++) | ||
2925 | { | ||
2926 | uint64_t test_val; | ||
2927 | for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) | ||
2928 | { | ||
2929 | uint64_t rv = test_val; | ||
2930 | |||
2931 | rs = MHD_strx_to_uint64_n_(t->str, len, &rv); | ||
2932 | if (rs != 0) | ||
2933 | { | ||
2934 | t_failed++; | ||
2935 | c_failed[i] = !0; | ||
2936 | fprintf(stderr, "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")" | ||
2937 | " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", | ||
2938 | n_prnt(t->str), (uintptr_t)len, rv, (uintptr_t)rs, get_current_locale_str()); | ||
2939 | } | ||
2940 | else if (rv != test_val) | ||
2941 | { | ||
2942 | t_failed++; | ||
2943 | c_failed[i] = !0; | ||
2944 | fprintf(stderr, "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", &ret_val)" | ||
2945 | " modified value of ret_val (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 ")." | ||
2946 | " Locale: %s\n", n_prnt(t->str), (uintptr_t)len, test_val, rv, | ||
2947 | get_current_locale_str()); | ||
2948 | } | ||
2949 | } | ||
2950 | } | ||
2951 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
2952 | printf("PASSED: MHD_strx_to_uint64_n_(\"%s\", 0..%" PRIuPTR ", &ret_val) == 0," | ||
2953 | " value of ret_val is unmodified\n", n_prnt(t->str), | ||
2954 | (uintptr_t)t->len + 1); | ||
2955 | } | ||
2956 | } | ||
2957 | return t_failed; | ||
2958 | } | ||
2959 | |||
2960 | |||
2961 | int run_str_to_X_tests(void) | ||
2962 | { | ||
2963 | int str_to_uint64_fails = 0; | ||
2964 | int str_to_uint64_n_fails = 0; | ||
2965 | int strx_to_sizet_fails = 0; | ||
2966 | int strx_to_sizet_n_fails = 0; | ||
2967 | int strx_to_uint32_fails = 0; | ||
2968 | int strx_to_uint32_n_fails = 0; | ||
2969 | int strx_to_uint64_fails = 0; | ||
2970 | int strx_to_uint64_n_fails = 0; | ||
2971 | int res; | ||
2972 | |||
2973 | res = check_str_to_uint64_valid(); | ||
2974 | if (res != 0) | ||
2975 | { | ||
2976 | if (res < 0) | ||
2977 | { | ||
2978 | fprintf(stderr, "ERROR: test internal error in check_str_to_uint64_valid().\n"); | ||
2979 | return 99; | ||
2980 | } | ||
2981 | str_to_uint64_fails += res; | ||
2982 | fprintf(stderr, "FAILED: testcase check_str_to_uint64_valid() failed.\n\n"); | ||
2983 | } | ||
2984 | else if (verbose > 1) | ||
2985 | printf("PASSED: testcase check_str_to_uint64_valid() successfully passed.\n\n"); | ||
2986 | |||
2987 | res = check_str_to_uint64_all_chars(); | ||
2988 | if (res != 0) | ||
2989 | { | ||
2990 | if (res < 0) | ||
2991 | { | ||
2992 | fprintf(stderr, "ERROR: test internal error in check_str_to_uint64_all_chars().\n"); | ||
2993 | return 99; | ||
2994 | } | ||
2995 | str_to_uint64_fails += res; | ||
2996 | fprintf(stderr, "FAILED: testcase check_str_to_uint64_all_chars() failed.\n\n"); | ||
2997 | } | ||
2998 | else if (verbose > 1) | ||
2999 | printf("PASSED: testcase check_str_to_uint64_all_chars() successfully passed.\n\n"); | ||
3000 | |||
3001 | res = check_str_to_uint64_overflow(); | ||
3002 | if (res != 0) | ||
3003 | { | ||
3004 | if (res < 0) | ||
3005 | { | ||
3006 | fprintf(stderr, "ERROR: test internal error in check_str_to_uint64_overflow().\n"); | ||
3007 | return 99; | ||
3008 | } | ||
3009 | str_to_uint64_fails += res; | ||
3010 | fprintf(stderr, "FAILED: testcase check_str_to_uint64_overflow() failed.\n\n"); | ||
3011 | } | ||
3012 | else if (verbose > 1) | ||
3013 | printf("PASSED: testcase check_str_to_uint64_overflow() successfully passed.\n\n"); | ||
3014 | |||
3015 | res = check_str_to_uint64_no_val(); | ||
3016 | if (res != 0) | ||
3017 | { | ||
3018 | if (res < 0) | ||
3019 | { | ||
3020 | fprintf(stderr, "ERROR: test internal error in check_str_to_uint64_no_val().\n"); | ||
3021 | return 99; | ||
3022 | } | ||
3023 | str_to_uint64_fails += res; | ||
3024 | fprintf(stderr, "FAILED: testcase check_str_to_uint64_no_val() failed.\n\n"); | ||
3025 | } | ||
3026 | else if (verbose > 1) | ||
3027 | printf("PASSED: testcase check_str_to_uint64_no_val() successfully passed.\n\n"); | ||
3028 | |||
3029 | if (str_to_uint64_fails) | ||
3030 | fprintf(stderr, "FAILED: function MHD_str_to_uint64_() failed %d time%s.\n\n", | ||
3031 | str_to_uint64_fails, str_to_uint64_fails == 1 ? "" : "s"); | ||
3032 | else if (verbose > 0) | ||
3033 | printf("PASSED: function MHD_str_to_uint64_() successfully passed all checks.\n\n"); | ||
3034 | |||
3035 | res = check_str_to_uint64_n_valid(); | ||
3036 | if (res != 0) | ||
3037 | { | ||
3038 | if (res < 0) | ||
3039 | { | ||
3040 | fprintf(stderr, "ERROR: test internal error in check_str_to_uint64_n_valid().\n"); | ||
3041 | return 99; | ||
3042 | } | ||
3043 | str_to_uint64_n_fails += res; | ||
3044 | fprintf(stderr, "FAILED: testcase check_str_to_uint64_n_valid() failed.\n\n"); | ||
3045 | } | ||
3046 | else if (verbose > 1) | ||
3047 | printf("PASSED: testcase check_str_to_uint64_n_valid() successfully passed.\n\n"); | ||
3048 | |||
3049 | res = check_str_to_uint64_n_all_chars(); | ||
3050 | if (res != 0) | ||
3051 | { | ||
3052 | if (res < 0) | ||
3053 | { | ||
3054 | fprintf(stderr, "ERROR: test internal error in check_str_to_uint64_n_all_chars().\n"); | ||
3055 | return 99; | ||
3056 | } | ||
3057 | str_to_uint64_n_fails += res; | ||
3058 | fprintf(stderr, "FAILED: testcase check_str_to_uint64_n_all_chars() failed.\n\n"); | ||
3059 | } | ||
3060 | else if (verbose > 1) | ||
3061 | printf("PASSED: testcase check_str_to_uint64_n_all_chars() successfully passed.\n\n"); | ||
3062 | |||
3063 | res = check_str_to_uint64_n_overflow(); | ||
3064 | if (res != 0) | ||
3065 | { | ||
3066 | if (res < 0) | ||
3067 | { | ||
3068 | fprintf(stderr, "ERROR: test internal error in check_str_to_uint64_n_overflow().\n"); | ||
3069 | return 99; | ||
3070 | } | ||
3071 | str_to_uint64_n_fails += res; | ||
3072 | fprintf(stderr, "FAILED: testcase check_str_to_uint64_n_overflow() failed.\n\n"); | ||
3073 | } | ||
3074 | else if (verbose > 1) | ||
3075 | printf("PASSED: testcase check_str_to_uint64_n_overflow() successfully passed.\n\n"); | ||
3076 | |||
3077 | res = check_str_to_uint64_n_no_val(); | ||
3078 | if (res != 0) | ||
3079 | { | ||
3080 | if (res < 0) | ||
3081 | { | ||
3082 | fprintf(stderr, "ERROR: test internal error in check_str_to_uint64_n_no_val().\n"); | ||
3083 | return 99; | ||
3084 | } | ||
3085 | str_to_uint64_n_fails += res; | ||
3086 | fprintf(stderr, "FAILED: testcase check_str_to_uint64_n_no_val() failed.\n\n"); | ||
3087 | } | ||
3088 | else if (verbose > 1) | ||
3089 | printf("PASSED: testcase check_str_to_uint64_n_no_val() successfully passed.\n\n"); | ||
3090 | |||
3091 | if (str_to_uint64_n_fails) | ||
3092 | fprintf(stderr, "FAILED: function MHD_str_to_uint64_n_() failed %d time%s.\n\n", | ||
3093 | str_to_uint64_n_fails, str_to_uint64_n_fails == 1 ? "" : "s"); | ||
3094 | else if (verbose > 0) | ||
3095 | printf("PASSED: function MHD_str_to_uint64_n_() successfully passed all checks.\n\n"); | ||
3096 | |||
3097 | res = check_strx_to_sizet_valid(); | ||
3098 | if (res != 0) | ||
3099 | { | ||
3100 | if (res < 0) | ||
3101 | { | ||
3102 | fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_valid().\n"); | ||
3103 | return 99; | ||
3104 | } | ||
3105 | strx_to_sizet_fails += res; | ||
3106 | fprintf(stderr, "FAILED: testcase check_strx_to_sizet_valid() failed.\n\n"); | ||
3107 | } | ||
3108 | else if (verbose > 1) | ||
3109 | printf("PASSED: testcase check_strx_to_sizet_valid() successfully passed.\n\n"); | ||
3110 | |||
3111 | res = check_strx_to_sizet_all_chars(); | ||
3112 | if (res != 0) | ||
3113 | { | ||
3114 | if (res < 0) | ||
3115 | { | ||
3116 | fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_all_chars().\n"); | ||
3117 | return 99; | ||
3118 | } | ||
3119 | strx_to_sizet_fails += res; | ||
3120 | fprintf(stderr, "FAILED: testcase check_strx_to_sizet_all_chars() failed.\n\n"); | ||
3121 | } | ||
3122 | else if (verbose > 1) | ||
3123 | printf("PASSED: testcase check_strx_to_sizet_all_chars() successfully passed.\n\n"); | ||
3124 | |||
3125 | res = check_strx_to_sizet_overflow(); | ||
3126 | if (res != 0) | ||
3127 | { | ||
3128 | if (res < 0) | ||
3129 | { | ||
3130 | fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_overflow().\n"); | ||
3131 | return 99; | ||
3132 | } | ||
3133 | strx_to_sizet_fails += res; | ||
3134 | fprintf(stderr, "FAILED: testcase check_strx_to_sizet_overflow() failed.\n\n"); | ||
3135 | } | ||
3136 | else if (verbose > 1) | ||
3137 | printf("PASSED: testcase check_strx_to_sizet_overflow() successfully passed.\n\n"); | ||
3138 | |||
3139 | res = check_strx_to_sizet_no_val(); | ||
3140 | if (res != 0) | ||
3141 | { | ||
3142 | if (res < 0) | ||
3143 | { | ||
3144 | fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_no_val().\n"); | ||
3145 | return 99; | ||
3146 | } | ||
3147 | strx_to_sizet_fails += res; | ||
3148 | fprintf(stderr, "FAILED: testcase check_strx_to_sizet_no_val() failed.\n\n"); | ||
3149 | } | ||
3150 | else if (verbose > 1) | ||
3151 | printf("PASSED: testcase check_strx_to_sizet_no_val() successfully passed.\n\n"); | ||
3152 | |||
3153 | if (strx_to_sizet_fails) | ||
3154 | fprintf(stderr, "FAILED: function MHD_strx_to_sizet_() failed %d time%s.\n\n", | ||
3155 | strx_to_sizet_fails, strx_to_sizet_fails == 1 ? "" : "s"); | ||
3156 | else if (verbose > 0) | ||
3157 | printf("PASSED: function MHD_strx_to_sizet_() successfully passed all checks.\n\n"); | ||
3158 | |||
3159 | res = check_strx_to_sizet_n_valid(); | ||
3160 | if (res != 0) | ||
3161 | { | ||
3162 | if (res < 0) | ||
3163 | { | ||
3164 | fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_n_valid().\n"); | ||
3165 | return 99; | ||
3166 | } | ||
3167 | strx_to_sizet_n_fails += res; | ||
3168 | fprintf(stderr, "FAILED: testcase check_strx_to_sizet_n_valid() failed.\n\n"); | ||
3169 | } | ||
3170 | else if (verbose > 1) | ||
3171 | printf("PASSED: testcase check_strx_to_sizet_n_valid() successfully passed.\n\n"); | ||
3172 | |||
3173 | res = check_strx_to_sizet_n_all_chars(); | ||
3174 | if (res != 0) | ||
3175 | { | ||
3176 | if (res < 0) | ||
3177 | { | ||
3178 | fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_n_all_chars().\n"); | ||
3179 | return 99; | ||
3180 | } | ||
3181 | strx_to_sizet_n_fails += res; | ||
3182 | fprintf(stderr, "FAILED: testcase check_strx_to_sizet_n_all_chars() failed.\n\n"); | ||
3183 | } | ||
3184 | else if (verbose > 1) | ||
3185 | printf("PASSED: testcase check_strx_to_sizet_n_all_chars() successfully passed.\n\n"); | ||
3186 | |||
3187 | res = check_strx_to_sizet_n_overflow(); | ||
3188 | if (res != 0) | ||
3189 | { | ||
3190 | if (res < 0) | ||
3191 | { | ||
3192 | fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_n_overflow().\n"); | ||
3193 | return 99; | ||
3194 | } | ||
3195 | strx_to_sizet_n_fails += res; | ||
3196 | fprintf(stderr, "FAILED: testcase check_strx_to_sizet_n_overflow() failed.\n\n"); | ||
3197 | } | ||
3198 | else if (verbose > 1) | ||
3199 | printf("PASSED: testcase check_strx_to_sizet_n_overflow() successfully passed.\n\n"); | ||
3200 | |||
3201 | res = check_strx_to_sizet_n_no_val(); | ||
3202 | if (res != 0) | ||
3203 | { | ||
3204 | if (res < 0) | ||
3205 | { | ||
3206 | fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_n_no_val().\n"); | ||
3207 | return 99; | ||
3208 | } | ||
3209 | strx_to_sizet_n_fails += res; | ||
3210 | fprintf(stderr, "FAILED: testcase check_strx_to_sizet_n_no_val() failed.\n\n"); | ||
3211 | } | ||
3212 | else if (verbose > 1) | ||
3213 | printf("PASSED: testcase check_strx_to_sizet_n_no_val() successfully passed.\n\n"); | ||
3214 | |||
3215 | if (strx_to_sizet_n_fails) | ||
3216 | fprintf(stderr, "FAILED: function MHD_strx_to_sizet_n_() failed %d time%s.\n\n", | ||
3217 | strx_to_sizet_n_fails, strx_to_sizet_n_fails == 1 ? "" : "s"); | ||
3218 | else if (verbose > 0) | ||
3219 | printf("PASSED: function MHD_strx_to_sizet_n_() successfully passed all checks.\n\n"); | ||
3220 | |||
3221 | res = check_strx_to_uint32_valid(); | ||
3222 | if (res != 0) | ||
3223 | { | ||
3224 | if (res < 0) | ||
3225 | { | ||
3226 | fprintf(stderr, "ERROR: test internal error in check_strx_to_uint32_valid().\n"); | ||
3227 | return 99; | ||
3228 | } | ||
3229 | strx_to_uint32_fails += res; | ||
3230 | fprintf(stderr, "FAILED: testcase check_strx_to_uint32_valid() failed.\n\n"); | ||
3231 | } | ||
3232 | else if (verbose > 1) | ||
3233 | printf("PASSED: testcase check_strx_to_uint32_valid() successfully passed.\n\n"); | ||
3234 | |||
3235 | res = check_strx_to_uint32_all_chars(); | ||
3236 | if (res != 0) | ||
3237 | { | ||
3238 | if (res < 0) | ||
3239 | { | ||
3240 | fprintf(stderr, "ERROR: test internal error in check_strx_to_uint32_all_chars().\n"); | ||
3241 | return 99; | ||
3242 | } | ||
3243 | strx_to_uint32_fails += res; | ||
3244 | fprintf(stderr, "FAILED: testcase check_strx_to_uint32_all_chars() failed.\n\n"); | ||
3245 | } | ||
3246 | else if (verbose > 1) | ||
3247 | printf("PASSED: testcase check_strx_to_uint32_all_chars() successfully passed.\n\n"); | ||
3248 | |||
3249 | res = check_strx_to_uint32_overflow(); | ||
3250 | if (res != 0) | ||
3251 | { | ||
3252 | if (res < 0) | ||
3253 | { | ||
3254 | fprintf(stderr, "ERROR: test internal error in check_strx_to_uint32_overflow().\n"); | ||
3255 | return 99; | ||
3256 | } | ||
3257 | strx_to_uint32_fails += res; | ||
3258 | fprintf(stderr, "FAILED: testcase check_strx_to_uint32_overflow() failed.\n\n"); | ||
3259 | } | ||
3260 | else if (verbose > 1) | ||
3261 | printf("PASSED: testcase check_strx_to_uint32_overflow() successfully passed.\n\n"); | ||
3262 | |||
3263 | res = check_strx_to_uint32_no_val(); | ||
3264 | if (res != 0) | ||
3265 | { | ||
3266 | if (res < 0) | ||
3267 | { | ||
3268 | fprintf(stderr, "ERROR: test internal error in check_strx_to_uint32_no_val().\n"); | ||
3269 | return 99; | ||
3270 | } | ||
3271 | strx_to_uint32_fails += res; | ||
3272 | fprintf(stderr, "FAILED: testcase check_strx_to_uint32_no_val() failed.\n\n"); | ||
3273 | } | ||
3274 | else if (verbose > 1) | ||
3275 | printf("PASSED: testcase check_strx_to_uint32_no_val() successfully passed.\n\n"); | ||
3276 | |||
3277 | if (strx_to_uint32_fails) | ||
3278 | fprintf(stderr, "FAILED: function MHD_strx_to_uint32_() failed %d time%s.\n\n", | ||
3279 | strx_to_uint32_fails, strx_to_uint32_fails == 1 ? "" : "s"); | ||
3280 | else if (verbose > 0) | ||
3281 | printf("PASSED: function MHD_strx_to_uint32_() successfully passed all checks.\n\n"); | ||
3282 | |||
3283 | res = check_strx_to_uint32_n_valid(); | ||
3284 | if (res != 0) | ||
3285 | { | ||
3286 | if (res < 0) | ||
3287 | { | ||
3288 | fprintf(stderr, "ERROR: test internal error in check_strx_to_uint32_n_valid().\n"); | ||
3289 | return 99; | ||
3290 | } | ||
3291 | strx_to_uint32_n_fails += res; | ||
3292 | fprintf(stderr, "FAILED: testcase check_strx_to_uint32_n_valid() failed.\n\n"); | ||
3293 | } | ||
3294 | else if (verbose > 1) | ||
3295 | printf("PASSED: testcase check_strx_to_uint32_n_valid() successfully passed.\n\n"); | ||
3296 | |||
3297 | res = check_strx_to_uint32_n_all_chars(); | ||
3298 | if (res != 0) | ||
3299 | { | ||
3300 | if (res < 0) | ||
3301 | { | ||
3302 | fprintf(stderr, "ERROR: test internal error in check_strx_to_uint32_n_all_chars().\n"); | ||
3303 | return 99; | ||
3304 | } | ||
3305 | strx_to_uint32_n_fails += res; | ||
3306 | fprintf(stderr, "FAILED: testcase check_strx_to_uint32_n_all_chars() failed.\n\n"); | ||
3307 | } | ||
3308 | else if (verbose > 1) | ||
3309 | printf("PASSED: testcase check_strx_to_uint32_n_all_chars() successfully passed.\n\n"); | ||
3310 | |||
3311 | res = check_strx_to_uint32_n_overflow(); | ||
3312 | if (res != 0) | ||
3313 | { | ||
3314 | if (res < 0) | ||
3315 | { | ||
3316 | fprintf(stderr, "ERROR: test internal error in check_strx_to_uint32_n_overflow().\n"); | ||
3317 | return 99; | ||
3318 | } | ||
3319 | strx_to_uint32_n_fails += res; | ||
3320 | fprintf(stderr, "FAILED: testcase check_strx_to_uint32_n_overflow() failed.\n\n"); | ||
3321 | } | ||
3322 | else if (verbose > 1) | ||
3323 | printf("PASSED: testcase check_strx_to_uint32_n_overflow() successfully passed.\n\n"); | ||
3324 | |||
3325 | res = check_strx_to_uint32_n_no_val(); | ||
3326 | if (res != 0) | ||
3327 | { | ||
3328 | if (res < 0) | ||
3329 | { | ||
3330 | fprintf(stderr, "ERROR: test internal error in check_strx_to_uint32_n_no_val().\n"); | ||
3331 | return 99; | ||
3332 | } | ||
3333 | strx_to_uint32_n_fails += res; | ||
3334 | fprintf(stderr, "FAILED: testcase check_strx_to_uint32_n_no_val() failed.\n\n"); | ||
3335 | } | ||
3336 | else if (verbose > 1) | ||
3337 | printf("PASSED: testcase check_strx_to_uint32_n_no_val() successfully passed.\n\n"); | ||
3338 | |||
3339 | if (strx_to_uint32_n_fails) | ||
3340 | fprintf(stderr, "FAILED: function MHD_strx_to_uint32_n_() failed %d time%s.\n\n", | ||
3341 | strx_to_uint32_n_fails, strx_to_uint32_n_fails == 1 ? "" : "s"); | ||
3342 | else if (verbose > 0) | ||
3343 | printf("PASSED: function MHD_strx_to_uint32_n_() successfully passed all checks.\n\n"); | ||
3344 | |||
3345 | res = check_strx_to_uint64_valid(); | ||
3346 | if (res != 0) | ||
3347 | { | ||
3348 | if (res < 0) | ||
3349 | { | ||
3350 | fprintf(stderr, "ERROR: test internal error in check_strx_to_uint64_valid().\n"); | ||
3351 | return 99; | ||
3352 | } | ||
3353 | strx_to_uint64_fails += res; | ||
3354 | fprintf(stderr, "FAILED: testcase check_strx_to_uint64_valid() failed.\n\n"); | ||
3355 | } | ||
3356 | else if (verbose > 1) | ||
3357 | printf("PASSED: testcase check_strx_to_uint64_valid() successfully passed.\n\n"); | ||
3358 | |||
3359 | res = check_strx_to_uint64_all_chars(); | ||
3360 | if (res != 0) | ||
3361 | { | ||
3362 | if (res < 0) | ||
3363 | { | ||
3364 | fprintf(stderr, "ERROR: test internal error in check_strx_to_uint64_all_chars().\n"); | ||
3365 | return 99; | ||
3366 | } | ||
3367 | strx_to_uint64_fails += res; | ||
3368 | fprintf(stderr, "FAILED: testcase check_strx_to_uint64_all_chars() failed.\n\n"); | ||
3369 | } | ||
3370 | else if (verbose > 1) | ||
3371 | printf("PASSED: testcase check_strx_to_uint64_all_chars() successfully passed.\n\n"); | ||
3372 | |||
3373 | res = check_strx_to_uint64_overflow(); | ||
3374 | if (res != 0) | ||
3375 | { | ||
3376 | if (res < 0) | ||
3377 | { | ||
3378 | fprintf(stderr, "ERROR: test internal error in check_strx_to_uint64_overflow().\n"); | ||
3379 | return 99; | ||
3380 | } | ||
3381 | strx_to_uint64_fails += res; | ||
3382 | fprintf(stderr, "FAILED: testcase check_strx_to_uint64_overflow() failed.\n\n"); | ||
3383 | } | ||
3384 | else if (verbose > 1) | ||
3385 | printf("PASSED: testcase check_strx_to_uint64_overflow() successfully passed.\n\n"); | ||
3386 | |||
3387 | res = check_strx_to_uint64_no_val(); | ||
3388 | if (res != 0) | ||
3389 | { | ||
3390 | if (res < 0) | ||
3391 | { | ||
3392 | fprintf(stderr, "ERROR: test internal error in check_strx_to_uint64_no_val().\n"); | ||
3393 | return 99; | ||
3394 | } | ||
3395 | strx_to_uint64_fails += res; | ||
3396 | fprintf(stderr, "FAILED: testcase check_strx_to_uint64_no_val() failed.\n\n"); | ||
3397 | } | ||
3398 | else if (verbose > 1) | ||
3399 | printf("PASSED: testcase check_strx_to_uint64_no_val() successfully passed.\n\n"); | ||
3400 | |||
3401 | if (strx_to_uint64_fails) | ||
3402 | fprintf(stderr, "FAILED: function MHD_strx_to_uint64_() failed %d time%s.\n\n", | ||
3403 | strx_to_uint64_fails, strx_to_uint64_fails == 1 ? "" : "s"); | ||
3404 | else if (verbose > 0) | ||
3405 | printf("PASSED: function MHD_strx_to_uint64_() successfully passed all checks.\n\n"); | ||
3406 | |||
3407 | res = check_strx_to_uint64_n_valid(); | ||
3408 | if (res != 0) | ||
3409 | { | ||
3410 | if (res < 0) | ||
3411 | { | ||
3412 | fprintf(stderr, "ERROR: test internal error in check_strx_to_uint64_n_valid().\n"); | ||
3413 | return 99; | ||
3414 | } | ||
3415 | strx_to_uint64_n_fails += res; | ||
3416 | fprintf(stderr, "FAILED: testcase check_strx_to_uint64_n_valid() failed.\n\n"); | ||
3417 | } | ||
3418 | else if (verbose > 1) | ||
3419 | printf("PASSED: testcase check_strx_to_uint64_n_valid() successfully passed.\n\n"); | ||
3420 | |||
3421 | res = check_strx_to_uint64_n_all_chars(); | ||
3422 | if (res != 0) | ||
3423 | { | ||
3424 | if (res < 0) | ||
3425 | { | ||
3426 | fprintf(stderr, "ERROR: test internal error in check_strx_to_uint64_n_all_chars().\n"); | ||
3427 | return 99; | ||
3428 | } | ||
3429 | strx_to_uint64_n_fails += res; | ||
3430 | fprintf(stderr, "FAILED: testcase check_strx_to_uint64_n_all_chars() failed.\n\n"); | ||
3431 | } | ||
3432 | else if (verbose > 1) | ||
3433 | printf("PASSED: testcase check_strx_to_uint64_n_all_chars() successfully passed.\n\n"); | ||
3434 | |||
3435 | res = check_strx_to_uint64_n_overflow(); | ||
3436 | if (res != 0) | ||
3437 | { | ||
3438 | if (res < 0) | ||
3439 | { | ||
3440 | fprintf(stderr, "ERROR: test internal error in check_strx_to_uint64_n_overflow().\n"); | ||
3441 | return 99; | ||
3442 | } | ||
3443 | strx_to_uint64_n_fails += res; | ||
3444 | fprintf(stderr, "FAILED: testcase check_strx_to_uint64_n_overflow() failed.\n\n"); | ||
3445 | } | ||
3446 | else if (verbose > 1) | ||
3447 | printf("PASSED: testcase check_strx_to_uint64_n_overflow() successfully passed.\n\n"); | ||
3448 | |||
3449 | res = check_strx_to_uint64_n_no_val(); | ||
3450 | if (res != 0) | ||
3451 | { | ||
3452 | if (res < 0) | ||
3453 | { | ||
3454 | fprintf(stderr, "ERROR: test internal error in check_strx_to_uint64_n_no_val().\n"); | ||
3455 | return 99; | ||
3456 | } | ||
3457 | strx_to_uint64_n_fails += res; | ||
3458 | fprintf(stderr, "FAILED: testcase check_strx_to_uint64_n_no_val() failed.\n\n"); | ||
3459 | } | ||
3460 | else if (verbose > 1) | ||
3461 | printf("PASSED: testcase check_strx_to_uint64_n_no_val() successfully passed.\n\n"); | ||
3462 | |||
3463 | if (strx_to_uint64_n_fails) | ||
3464 | fprintf(stderr, "FAILED: function MHD_strx_to_uint64_n_() failed %d time%s.\n\n", | ||
3465 | strx_to_uint64_n_fails, strx_to_uint64_n_fails == 1 ? "" : "s"); | ||
3466 | else if (verbose > 0) | ||
3467 | printf("PASSED: function MHD_strx_to_uint64_n_() successfully passed all checks.\n\n"); | ||
3468 | |||
3469 | if (str_to_uint64_fails || str_to_uint64_n_fails || | ||
3470 | strx_to_sizet_fails || strx_to_sizet_n_fails || | ||
3471 | strx_to_uint32_fails || strx_to_uint32_n_fails || | ||
3472 | strx_to_uint64_fails || strx_to_uint64_n_fails) | ||
3473 | { | ||
3474 | if (verbose > 0) | ||
3475 | printf("At least one test failed.\n"); | ||
3476 | |||
3477 | return 1; | ||
3478 | } | ||
3479 | |||
3480 | if (verbose > 0) | ||
3481 | printf("All tests passed successfully.\n"); | ||
3482 | |||
3483 | return 0; | ||
3484 | } | ||
3485 | |||
3486 | |||
3487 | int main(int argc, char * argv[]) | ||
3488 | { | ||
3489 | if (has_param(argc, argv, "-v") || has_param(argc, argv, "--verbose") || has_param(argc, argv, "--verbose1")) | ||
3490 | verbose = 1; | ||
3491 | if (has_param(argc, argv, "-vv") || has_param(argc, argv, "--verbose2")) | ||
3492 | verbose = 2; | ||
3493 | if (has_param(argc, argv, "-vvv") || has_param(argc, argv, "--verbose3")) | ||
3494 | verbose = 3; | ||
3495 | |||
3496 | if (has_in_name(argv[0], "_to_value")) | ||
3497 | return run_str_to_X_tests(); | ||
3498 | |||
3499 | return run_eq_neq_str_tests(); | ||
3500 | } | ||