test_str.c (157115B)
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 "mhd_options.h" 27 #include <stdio.h> 28 #include <locale.h> 29 #include <string.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 #ifdef HAVE_STDLIB_H 39 #include <stdlib.h> 40 #endif /* HAVE_STDLIB_H */ 41 #include "mhd_limits.h" 42 #include "mhd_str.h" 43 #include "test_helpers.h" 44 45 /* Turn any MHD_PANIC() or failing mhd_assert() reached from this 46 test into a marked, classifiable test error (TESTING.md, P5). */ 47 #include "mhd_panic_tripwire.h" 48 49 50 static int verbose = 0; /* verbose level (0-3)*/ 51 52 /* Locale names to test. 53 * Functions must not depend of current current locale, 54 * so result must be the same in any locale. 55 */ 56 static const char *const locale_names[] = { 57 "C", 58 "", /* System default locale */ 59 #if defined(_WIN32) && ! defined(__CYGWIN__) 60 ".OCP", /* W32 system default OEM code page */ 61 ".ACP", /* W32 system default ANSI code page */ 62 ".65001", /* UTF-8 */ 63 ".437", 64 ".850", 65 ".857", 66 ".866", 67 ".1250", 68 ".1251", 69 ".1252", 70 "en", 71 "english", 72 "French_France", 73 "Turkish_Turkey.1254", 74 "de", 75 "zh-Hans", 76 "ru-RU.1251" 77 #if 0 /* Disabled extra checks */ 78 , 79 ".1254", 80 ".20866", /* number for KOI8-R */ 81 ".28591", /* number for ISO-8859-1 */ 82 ".28595", /* number for ISO-8859-5 */ 83 ".28599", /* number for ISO-8859-9 */ 84 ".28605", /* number for ISO-8859-15 */ 85 "en-US", 86 "English-US", 87 "en-US.437", 88 "English_United States.437", 89 "en-US.1252", 90 "English_United States.1252", 91 "English_United States.28591", 92 "English_United States.65001", 93 "fra", 94 "french", 95 "fr-FR", 96 "fr-FR.850", 97 "french_france.850", 98 "fr-FR.1252", 99 "French_france.1252", 100 "French_france.28605", 101 "French_France.65001", 102 "de-DE", 103 "de-DE.850", 104 "German_Germany.850", 105 "German_Germany.1250", 106 "de-DE.1252", 107 "German_Germany.1252", 108 "German_Germany.28605", 109 "German_Germany.65001", 110 "tr", 111 "trk", 112 "turkish", 113 "tr-TR", 114 "tr-TR.1254", 115 "tr-TR.857", 116 "Turkish_Turkey.857", 117 "Turkish_Turkey.28599", 118 "Turkish_Turkey.65001", 119 "ru", 120 "ru-RU", 121 "Russian", 122 "ru-RU.866", 123 "Russian_Russia.866", 124 "Russian_Russia.1251", 125 "Russian_Russia.20866", 126 "Russian_Russia.28595", 127 "Russian_Russia.65001", 128 "zh-Hans.936", 129 "chinese-simplified" 130 #endif /* Disabled extra checks */ 131 #else /* ! _WIN32 || __CYGWIN__ */ 132 "C.UTF-8", 133 "POSIX", 134 "en", 135 "en_US", 136 "en_US.ISO-8859-1", 137 "en_US.ISO_8859-1", 138 "en_US.ISO8859-1", 139 "en_US.iso88591", 140 "en_US.ISO-8859-15", 141 "en_US.DIS_8859-15", 142 "en_US.ISO8859-15", 143 "en_US.iso885915", 144 "en_US.1252", 145 "en_US.CP1252", 146 "en_US.UTF-8", 147 "en_US.utf8", 148 "fr", 149 "fr_FR", 150 "fr_FR.850", 151 "fr_FR.IBM850", 152 "fr_FR.1252", 153 "fr_FR.CP1252", 154 "fr_FR.ISO-8859-1", 155 "fr_FR.ISO_8859-1", 156 "fr_FR.ISO8859-1", 157 "fr_FR.iso88591", 158 "fr_FR.ISO-8859-15", 159 "fr_FR.DIS_8859-15", 160 "fr_FR.ISO8859-15", 161 "fr_FR.iso8859-15", 162 "fr_FR.UTF-8", 163 "fr_FR.utf8", 164 "de", 165 "de_DE", 166 "de_DE.850", 167 "de_DE.IBM850", 168 "de_DE.1250", 169 "de_DE.CP1250", 170 "de_DE.1252", 171 "de_DE.CP1252", 172 "de_DE.ISO-8859-1", 173 "de_DE.ISO_8859-1", 174 "de_DE.ISO8859-1", 175 "de_DE.iso88591", 176 "de_DE.ISO-8859-15", 177 "de_DE.DIS_8859-15", 178 "de_DE.ISO8859-15", 179 "de_DE.iso885915", 180 "de_DE.UTF-8", 181 "de_DE.utf8", 182 "tr", 183 "tr_TR", 184 "tr_TR.1254", 185 "tr_TR.CP1254", 186 "tr_TR.857", 187 "tr_TR.IBM857", 188 "tr_TR.ISO-8859-9", 189 "tr_TR.ISO8859-9", 190 "tr_TR.iso88599", 191 "tr_TR.UTF-8", 192 "tr_TR.utf8", 193 "ru", 194 "ru_RU", 195 "ru_RU.1251", 196 "ru_RU.CP1251", 197 "ru_RU.866", 198 "ru_RU.IBM866", 199 "ru_RU.KOI8-R", 200 "ru_RU.koi8-r", 201 "ru_RU.KOI8-RU", 202 "ru_RU.ISO-8859-5", 203 "ru_RU.ISO_8859-5", 204 "ru_RU.ISO8859-5", 205 "ru_RU.iso88595", 206 "ru_RU.UTF-8", 207 "zh_CN", 208 "zh_CN.GB2312", 209 "zh_CN.UTF-8", 210 #endif /* ! _WIN32 || __CYGWIN__ */ 211 }; 212 213 static const unsigned int locale_name_count = sizeof(locale_names) 214 / sizeof(locale_names[0]); 215 216 217 /* 218 * Helper functions 219 */ 220 221 static int 222 set_test_locale (size_t num) 223 { 224 if (num >= locale_name_count) 225 { 226 fprintf (stderr, "Unexpected number of locale.\n"); 227 exit (99); 228 } 229 if (verbose > 2) 230 printf ("Setting locale \"%s\":", locale_names[num]); 231 if (setlocale (LC_ALL, locale_names[num])) 232 { 233 if (verbose > 2) 234 printf (" succeed.\n"); 235 return 1; 236 } 237 if (verbose > 2) 238 printf (" failed.\n"); 239 return 0; 240 } 241 242 243 static const char * 244 get_current_locale_str (void) 245 { 246 char const *loc_str = setlocale (LC_ALL, NULL); 247 return loc_str ? loc_str : "unknown"; 248 } 249 250 251 static char tmp_bufs[4][4 * 1024]; /* should be enough for testing */ 252 static size_t buf_idx = 0; 253 254 /* print non-printable chars as char codes */ 255 static char * 256 n_prnt (const char *str) 257 { 258 static char *buf; /* should be enough for testing */ 259 static const size_t buf_size = sizeof(tmp_bufs[0]); 260 const unsigned char *p = (const unsigned char *) str; 261 size_t w_pos = 0; 262 if (++buf_idx > 3) 263 buf_idx = 0; 264 buf = tmp_bufs[buf_idx]; 265 266 while (*p && w_pos + 1 < buf_size) 267 { 268 const unsigned char c = *p; 269 if ((c == '\\') || (c == '"') ) 270 { 271 if (w_pos + 2 >= buf_size) 272 break; 273 buf[w_pos++] = '\\'; 274 buf[w_pos++] = (char) c; 275 } 276 else if ((c >= 0x20) && (c <= 0x7E) ) 277 buf[w_pos++] = (char) c; 278 else 279 { 280 if (w_pos + 4 >= buf_size) 281 break; 282 if (snprintf (buf + w_pos, buf_size - w_pos, "\\x%02hX", (short unsigned 283 int) c) != 4) 284 break; 285 w_pos += 4; 286 } 287 p++; 288 } 289 if (*p) 290 { /* not full string is printed */ 291 /* enough space for "..." ? */ 292 if (w_pos + 3 > buf_size) 293 w_pos = buf_size - 4; 294 buf[w_pos++] = '.'; 295 buf[w_pos++] = '.'; 296 buf[w_pos++] = '.'; 297 } 298 buf[w_pos] = 0; 299 return buf; 300 } 301 302 303 struct str_with_len 304 { 305 const char *const str; 306 const size_t len; 307 }; 308 309 #define D_STR_W_LEN(s) {(s), (sizeof((s)) / sizeof(char)) - 1} 310 311 /* 312 * String caseless equality functions tests 313 */ 314 315 struct two_eq_strs 316 { 317 const struct str_with_len s1; 318 const struct str_with_len s2; 319 }; 320 321 static const struct two_eq_strs eq_strings[] = { 322 {D_STR_W_LEN ("1234567890!@~%&$@#{}[]\\/!?`."), 323 D_STR_W_LEN ("1234567890!@~%&$@#{}[]\\/!?`.")}, 324 {D_STR_W_LEN ("Simple string."), D_STR_W_LEN ("Simple string.")}, 325 {D_STR_W_LEN ("SIMPLE STRING."), D_STR_W_LEN ("SIMPLE STRING.")}, 326 {D_STR_W_LEN ("simple string."), D_STR_W_LEN ("simple string.")}, 327 {D_STR_W_LEN ("simple string."), D_STR_W_LEN ("Simple String.")}, 328 {D_STR_W_LEN ("sImPlE StRiNg."), D_STR_W_LEN ("SiMpLe sTrInG.")}, 329 {D_STR_W_LEN ("SIMPLE STRING."), D_STR_W_LEN ("simple string.")}, 330 {D_STR_W_LEN ("abcdefghijklmnopqrstuvwxyz"), 331 D_STR_W_LEN ("abcdefghijklmnopqrstuvwxyz")}, 332 {D_STR_W_LEN ("ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 333 D_STR_W_LEN ("ABCDEFGHIJKLMNOPQRSTUVWXYZ")}, 334 {D_STR_W_LEN ("abcdefghijklmnopqrstuvwxyz"), 335 D_STR_W_LEN ("ABCDEFGHIJKLMNOPQRSTUVWXYZ")}, 336 {D_STR_W_LEN ("zyxwvutsrqponMLKJIHGFEDCBA"), 337 D_STR_W_LEN ("ZYXWVUTSRQPONmlkjihgfedcba")}, 338 339 {D_STR_W_LEN ("Cha\x8cne pour le test."), 340 D_STR_W_LEN ("Cha\x8cne pour le test.")}, /* "Chaîne pour le test." in CP850 */ 341 {D_STR_W_LEN ("cha\x8cne pOur Le TEst."), 342 D_STR_W_LEN ("Cha\x8cne poUr Le teST.")}, 343 {D_STR_W_LEN ("Cha\xeene pour le test."), 344 D_STR_W_LEN ("Cha\xeene pour le test.")}, /* "Chaîne pour le test." in CP1252/ISO-8859-1/ISO-8859-15 */ 345 {D_STR_W_LEN ("CHa\xeene POUR le test."), 346 D_STR_W_LEN ("Cha\xeeNe pour lE TEST.")}, 347 {D_STR_W_LEN ("Cha\xc3\xaene pour le Test."), 348 D_STR_W_LEN ("Cha\xc3\xaene pour le Test.")}, /* "Chaîne pour le test." in UTF-8 */ 349 {D_STR_W_LEN ("ChA\xc3\xaene pouR lE TesT."), 350 D_STR_W_LEN ("Cha\xc3\xaeNe Pour le teSt.")}, 351 352 {D_STR_W_LEN (".Beispiel Zeichenfolge"), 353 D_STR_W_LEN (".Beispiel Zeichenfolge")}, 354 {D_STR_W_LEN (".bEisPiel ZEIchenfoLgE"), 355 D_STR_W_LEN (".BEiSpiEl zeIcheNfolge")}, 356 357 {D_STR_W_LEN ("Do\xa7rulama \x87izgi!"), 358 D_STR_W_LEN ("Do\xa7rulama \x87izgi!")}, /* "Doğrulama çizgi!" in CP857 */ 359 {D_STR_W_LEN ("Do\xa7rulama \x87IzgI!"), /* Spelling intentionally incorrect here */ 360 D_STR_W_LEN ("Do\xa7rulama \x87izgi!")}, /* Note: 'i' is not caseless equal to 'I' in Turkish */ 361 {D_STR_W_LEN ("Do\xf0rulama \xe7izgi!"), 362 D_STR_W_LEN ("Do\xf0rulama \xe7izgi!")}, /* "Doğrulama çizgi!" in CP1254/ISO-8859-9 */ 363 {D_STR_W_LEN ("Do\xf0rulamA \xe7Izgi!"), 364 D_STR_W_LEN ("do\xf0rulama \xe7izgi!")}, 365 {D_STR_W_LEN ("Do\xc4\x9frulama \xc3\xa7izgi!"), 366 D_STR_W_LEN ("Do\xc4\x9frulama \xc3\xa7izgi!")}, /* "Doğrulama çizgi!" in UTF-8 */ 367 {D_STR_W_LEN ("do\xc4\x9fruLAMA \xc3\xa7Izgi!"), /* Spelling intentionally incorrect here */ 368 D_STR_W_LEN ("DO\xc4\x9frulama \xc3\xa7izgI!")}, /* Spelling intentionally incorrect here */ 369 370 {D_STR_W_LEN ("\x92\xa5\xe1\xe2\xae\xa2\xa0\xef \x91\xe2\xe0\xae\xaa\xa0."), 371 D_STR_W_LEN ("\x92\xa5\xe1\xe2\xae\xa2\xa0\xef \x91\xe2\xe0\xae\xaa\xa0.")}, /* "Тестовая Строка." in CP866 */ 372 {D_STR_W_LEN ("\xd2\xe5\xf1\xf2\xee\xe2\xe0\xff \xd1\xf2\xf0\xee\xea\xe0."), 373 D_STR_W_LEN ("\xd2\xe5\xf1\xf2\xee\xe2\xe0\xff \xd1\xf2\xf0\xee\xea\xe0.")}, /* "Тестовая Строка." in CP1251 */ 374 {D_STR_W_LEN ("\xf4\xc5\xd3\xd4\xcf\xd7\xc1\xd1 \xf3\xd4\xd2\xcf\xcb\xc1."), 375 D_STR_W_LEN ("\xf4\xc5\xd3\xd4\xcf\xd7\xc1\xd1 \xf3\xd4\xd2\xcf\xcb\xc1.")}, /* "Тестовая Строка." in KOI8-R */ 376 {D_STR_W_LEN ("\xc2\xd5\xe1\xe2\xde\xd2\xd0\xef \xc1\xe2\xe0\xde\xda\xd0."), 377 D_STR_W_LEN ("\xc2\xd5\xe1\xe2\xde\xd2\xd0\xef \xc1\xe2\xe0\xde\xda\xd0.")}, /* "Тестовая Строка." in ISO-8859-5 */ 378 {D_STR_W_LEN ("\xd0\xa2\xd0\xb5\xd1\x81\xd1\x82\xd0\xbe\xd0\xb2\xd0\xb0\xd1" 379 "\x8f \xd0\xa1\xd1\x82\xd1\x80\xd0\xbe\xd0\xba\xd0\xb0."), 380 D_STR_W_LEN ("\xd0\xa2\xd0\xb5\xd1\x81\xd1\x82\xd0\xbe\xd0\xb2\xd0\xb0\xd1" 381 "\x8f \xd0\xa1\xd1\x82\xd1\x80\xd0\xbe\xd0\xba\xd0\xb0.")}, /* "Тестовая Строка." in UTF-8 */ 382 383 {D_STR_W_LEN ( 384 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" 385 "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@[\\]" 386 "^_`{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90" 387 "\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4" 388 "\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8" 389 "\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc" 390 "\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0" 391 "\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4" 392 "\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"), 393 D_STR_W_LEN ( 394 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" 395 "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@[\\]" 396 "^_`{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90" 397 "\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4" 398 "\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8" 399 "\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc" 400 "\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0" 401 "\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4" 402 "\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff")}, /* Full sequence without a-z */ 403 {D_STR_W_LEN ( 404 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" 405 "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@AB" 406 "CDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83" 407 "\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97" 408 "\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab" 409 "\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf" 410 "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3" 411 "\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7" 412 "\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb" 413 "\xfc\xfd\xfe\xff"), 414 D_STR_W_LEN ( 415 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" 416 "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@AB" 417 "CDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83" 418 "\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97" 419 "\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab" 420 "\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf" 421 "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3" 422 "\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7" 423 "\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb" 424 "\xfc\xfd\xfe\xff")}, /* Full sequence */ 425 {D_STR_W_LEN ( 426 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" 427 "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@AB" 428 "CDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89" 429 "\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d" 430 "\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1" 431 "\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5" 432 "\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9" 433 "\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed" 434 "\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff") 435 , 436 D_STR_W_LEN ( 437 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" 438 "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@ab" 439 "cdefghijklmnopqrstuvwxyz[\\]^_`{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89" 440 "\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d" 441 "\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1" 442 "\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5" 443 "\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9" 444 "\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed" 445 "\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff") 446 } /* Full with A/a match */ 447 }; 448 449 struct two_neq_strs 450 { 451 const struct str_with_len s1; 452 const struct str_with_len s2; 453 const size_t dif_pos; 454 }; 455 456 static const struct two_neq_strs neq_strings[] = { 457 {D_STR_W_LEN ("1234567890!@~%&$@#{}[]\\/!?`."), 458 D_STR_W_LEN ("1234567890!@~%&$@#{}[]\\/!?`"), 27}, 459 {D_STR_W_LEN (".1234567890!@~%&$@#{}[]\\/!?`."), 460 D_STR_W_LEN ("1234567890!@~%&$@#{}[]\\/!?`"), 0}, 461 {D_STR_W_LEN ("Simple string."), D_STR_W_LEN ("Simple ctring."), 7}, 462 {D_STR_W_LEN ("simple string."), D_STR_W_LEN ("simple string"), 13}, 463 {D_STR_W_LEN ("simple strings"), D_STR_W_LEN ("Simple String."), 13}, 464 {D_STR_W_LEN ("sImPlE StRiNg."), D_STR_W_LEN ("SYMpLe sTrInG."), 1}, 465 {D_STR_W_LEN ("SIMPLE STRING."), D_STR_W_LEN ("simple string.2"), 14}, 466 {D_STR_W_LEN ("abcdefghijklmnopqrstuvwxyz,"), 467 D_STR_W_LEN ("abcdefghijklmnopqrstuvwxyz."), 26}, 468 {D_STR_W_LEN ("abcdefghijklmnopqrstuvwxyz!"), 469 D_STR_W_LEN ("ABCDEFGHIJKLMNOPQRSTUVWXYZ?"), 26}, 470 {D_STR_W_LEN ("zyxwvutsrqponwMLKJIHGFEDCBA"), 471 D_STR_W_LEN ("ZYXWVUTSRQPON%mlkjihgfedcba"), 13}, 472 473 {D_STR_W_LEN ("S\xbdur veulent plus d'\xbdufs."), /* "Sœur veulent plus d'œufs." in ISO-8859-15 */ 474 D_STR_W_LEN ("S\xbcUR VEULENT PLUS D'\xbcUFS."), 1}, /* "SŒUR VEULENT PLUS D'ŒUFS." in ISO-8859-15 */ 475 {D_STR_W_LEN ("S\x9cur veulent plus d'\x9cufs."), /* "Sœur veulent plus d'œufs." in CP1252 */ 476 D_STR_W_LEN ("S\x8cUR VEULENT PLUS D'\x8cUFS."), 1}, /* "SŒUR VEULENT PLUS D'ŒUFS." in CP1252 */ 477 {D_STR_W_LEN ("S\xc5\x93ur veulent plus d'\xc5\x93ufs."), /* "Sœur veulent plus d'œufs." in UTF-8 */ 478 D_STR_W_LEN ("S\xc5\x92UR VEULENT PLUS D'\xc5\x92UFS."), 2}, /* "SŒUR VEULENT PLUS D'ŒUFS." in UTF-8 */ 479 480 {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 */ 481 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 */ 482 {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 */ 483 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 */ 484 {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 */ 485 D_STR_W_LEN ("UM EIN SCH\xc3\x96NES M\xc3\x84" "DCHEN ZU K\xc3\x9cSSEN."), 486 11}, /* "UM EIN SCHÖNES MÄDCHEN ZU KÜSSEN." in UTF-8 */ 487 488 {D_STR_W_LEN ("\x98stanbul"), /* "İstanbul" in CP857 */ 489 D_STR_W_LEN ("istanbul"), 0}, /* "istanbul" in CP857 */ 490 {D_STR_W_LEN ("\xddstanbul"), /* "İstanbul" in ISO-8859-9/CP1254 */ 491 D_STR_W_LEN ("istanbul"), 0}, /* "istanbul" in ISO-8859-9/CP1254 */ 492 {D_STR_W_LEN ("\xc4\xb0stanbul"), /* "İstanbul" in UTF-8 */ 493 D_STR_W_LEN ("istanbul"), 0}, /* "istanbul" in UTF-8 */ 494 {D_STR_W_LEN ("Diyarbak\x8dr"), /* "Diyarbakır" in CP857 */ 495 D_STR_W_LEN ("DiyarbakIR"), 8}, /* "DiyarbakIR" in CP857 */ 496 {D_STR_W_LEN ("Diyarbak\xfdr"), /* "Diyarbakır" in ISO-8859-9/CP1254 */ 497 D_STR_W_LEN ("DiyarbakIR"), 8}, /* "DiyarbakIR" in ISO-8859-9/CP1254 */ 498 {D_STR_W_LEN ("Diyarbak\xc4\xb1r"), /* "Diyarbakır" in UTF-8 */ 499 D_STR_W_LEN ("DiyarbakIR"), 8}, /* "DiyarbakIR" in UTF-8 */ 500 501 {D_STR_W_LEN ("\x92\xa5\xe1\xe2\xae\xa2\xa0\xef \x91\xe2\xe0\xae\xaa\xa0."), /* "Тестовая Строка." in CP866 */ 502 D_STR_W_LEN ("\x92\x85\x91\x92\x8e\x82\x80\x9f \x91\x92\x90\x8e\x8a\x80."), 503 1}, /* "ТЕСТОВАЯ СТРОКА." in CP866 */ 504 {D_STR_W_LEN ("\xd2\xe5\xf1\xf2\xee\xe2\xe0\xff \xd1\xf2\xf0\xee\xea\xe0."), /* "Тестовая Строка." in CP1251 */ 505 D_STR_W_LEN ("\xd2\xc5\xd1\xd2\xce\xc2\xc0\xdf \xd1\xd2\xd0\xce\xca\xc0."), 506 1}, /* "ТЕСТОВАЯ СТРОКА." in CP1251 */ 507 {D_STR_W_LEN ("\xf4\xc5\xd3\xd4\xcf\xd7\xc1\xd1 \xf3\xd4\xd2\xcf\xcb\xc1."), /* "Тестовая Строка." in KOI8-R */ 508 D_STR_W_LEN ("\xf4\xe5\xf3\xf4\xef\xf7\xe1\xf1 \xf3\xf4\xf2\xef\xeb\xe1."), 509 1}, /* "ТЕСТОВАЯ СТРОКА." in KOI8-R */ 510 {D_STR_W_LEN ("\xc2\xd5\xe1\xe2\xde\xd2\xd0\xef \xc1\xe2\xe0\xde\xda\xd0."), /* "Тестовая Строка." in ISO-8859-5 */ 511 D_STR_W_LEN ("\xc2\xb5\xc1\xc2\xbe\xb2\xb0\xcf \xc1\xc2\xc0\xbe\xba\xb0."), 512 1}, /* "ТЕСТОВАЯ СТРОКА." in ISO-8859-5 */ 513 {D_STR_W_LEN ("\xd0\xa2\xd0\xb5\xd1\x81\xd1\x82\xd0\xbe\xd0\xb2\xd0\xb0\xd1" 514 "\x8f \xd0\xa1\xd1\x82\xd1\x80\xd0\xbe\xd0\xba\xd0\xb0."), /* "Тестовая Строка." in UTF-8 */ 515 D_STR_W_LEN ("\xd0\xa2\xd0\x95\xd0\xa1\xd0\xa2\xd0\x9e\xd0\x92\xd0\x90\xd0" 516 "\xaf \xd0\xa1\xd0\xa2\xd0\xa0\xd0\x9e\xd0\x9a\xd0\x90."), 3} /* "ТЕСТОВАЯ СТРОКА." in UTF-8 */ 517 }; 518 519 520 static size_t 521 check_eq_strings (void) 522 { 523 size_t t_failed = 0; 524 size_t i, j; 525 int c_failed[sizeof(eq_strings) / sizeof(eq_strings[0])]; 526 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 527 528 memset (c_failed, 0, sizeof(c_failed)); 529 530 for (j = 0; j < locale_name_count; j++) 531 { 532 set_test_locale (j); /* setlocale() can be slow! */ 533 for (i = 0; i < n_checks; i++) 534 { 535 const struct two_eq_strs *const t = eq_strings + i; 536 if (c_failed[i]) 537 continue; /* skip already failed checks */ 538 if (! MHD_str_equal_caseless_ (t->s1.str, t->s2.str)) 539 { 540 t_failed++; 541 c_failed[i] = ! 0; 542 fprintf (stderr, 543 "FAILED: MHD_str_equal_caseless_(\"%s\", \"%s\") returned zero, while expected non-zero." 544 " Locale: %s\n", n_prnt (t->s1.str), n_prnt (t->s2.str), 545 get_current_locale_str ()); 546 } 547 else if (! MHD_str_equal_caseless_ (t->s2.str, t->s1.str)) 548 { 549 t_failed++; 550 c_failed[i] = ! 0; 551 fprintf (stderr, 552 "FAILED: MHD_str_equal_caseless_(\"%s\", \"%s\") returned zero, while expected non-zero." 553 " Locale: %s\n", n_prnt (t->s2.str), n_prnt (t->s1.str), 554 get_current_locale_str ()); 555 } 556 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) 557 printf ("PASSED: MHD_str_equal_caseless_(\"%s\", \"%s\") != 0 && \\\n" 558 " MHD_str_equal_caseless_(\"%s\", \"%s\") != 0\n", 559 n_prnt (t->s1.str), n_prnt (t->s2.str), 560 n_prnt (t->s2.str), n_prnt (t->s1.str)); 561 } 562 } 563 return t_failed; 564 } 565 566 567 static size_t 568 check_neq_strings (void) 569 { 570 size_t t_failed = 0; 571 size_t i, j; 572 int c_failed[sizeof(neq_strings) / sizeof(neq_strings[0])]; 573 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 574 575 memset (c_failed, 0, sizeof(c_failed)); 576 577 for (j = 0; j < locale_name_count; j++) 578 { 579 set_test_locale (j); /* setlocale() can be slow! */ 580 for (i = 0; i < n_checks; i++) 581 { 582 const struct two_neq_strs *const t = neq_strings + i; 583 if (c_failed[i]) 584 continue; /* skip already failed checks */ 585 if (MHD_str_equal_caseless_ (t->s1.str, t->s2.str)) 586 { 587 t_failed++; 588 c_failed[i] = ! 0; 589 fprintf (stderr, 590 "FAILED: MHD_str_equal_caseless_(\"%s\", \"%s\") returned non-zero, while expected zero." 591 " Locale: %s\n", n_prnt (t->s1.str), n_prnt (t->s2.str), 592 get_current_locale_str ()); 593 } 594 else if (MHD_str_equal_caseless_ (t->s2.str, t->s1.str)) 595 { 596 t_failed++; 597 c_failed[i] = ! 0; 598 fprintf (stderr, 599 "FAILED: MHD_str_equal_caseless_(\"%s\", \"%s\") returned non-zero, while expected zero." 600 " Locale: %s\n", n_prnt (t->s2.str), n_prnt (t->s1.str), 601 get_current_locale_str ()); 602 } 603 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) 604 printf ("PASSED: MHD_str_equal_caseless_(\"%s\", \"%s\") == 0 && \\\n" 605 " MHD_str_equal_caseless_(\"%s\", \"%s\") == 0\n", 606 n_prnt (t->s1.str), n_prnt (t->s2.str), 607 n_prnt (t->s2.str), n_prnt (t->s1.str)); 608 } 609 } 610 return t_failed; 611 } 612 613 614 static size_t 615 check_eq_strings_n (void) 616 { 617 size_t t_failed = 0; 618 size_t i, j, k; 619 int c_failed[sizeof(eq_strings) / sizeof(eq_strings[0])]; 620 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 621 622 memset (c_failed, 0, sizeof(c_failed)); 623 624 for (j = 0; j < locale_name_count; j++) 625 { 626 set_test_locale (j); /* setlocale() can be slow! */ 627 for (i = 0; i < n_checks; i++) 628 { 629 size_t m_len; 630 const struct two_eq_strs *const t = eq_strings + i; 631 m_len = (t->s1.len > t->s2.len) ? t->s1.len : t->s2.len; 632 for (k = 0; k <= m_len + 1 && ! c_failed[i]; k++) 633 { 634 if (! MHD_str_equal_caseless_n_ (t->s1.str, t->s2.str, k)) 635 { 636 t_failed++; 637 c_failed[i] = ! 0; 638 fprintf (stderr, 639 "FAILED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", %u) returned zero," 640 " while expected non-zero. Locale: %s\n", 641 n_prnt (t->s1.str), n_prnt (t->s2.str), (unsigned int) k, 642 get_current_locale_str ()); 643 } 644 else if (! MHD_str_equal_caseless_n_ (t->s2.str, t->s1.str, k)) 645 { 646 t_failed++; 647 c_failed[i] = ! 0; 648 fprintf (stderr, 649 "FAILED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", %u) returned zero," 650 " while expected non-zero. Locale: %s\n", 651 n_prnt (t->s2.str), n_prnt (t->s1.str), (unsigned int) k, 652 get_current_locale_str ()); 653 } 654 } 655 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) 656 printf ("PASSED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", N) " \ 657 "!= 0 && \\\n" \ 658 " MHD_str_equal_caseless_n_(\"%s\", \"%s\", N) " \ 659 "!= 0, where N is 0..%u\n", 660 n_prnt (t->s1.str), n_prnt (t->s2.str), n_prnt (t->s2.str), 661 n_prnt (t->s1.str), (unsigned int) m_len + 1); 662 } 663 } 664 return t_failed; 665 } 666 667 668 static size_t 669 check_neq_strings_n (void) 670 { 671 size_t t_failed = 0; 672 size_t i, j, k; 673 int c_failed[sizeof(neq_strings) / sizeof(neq_strings[0])]; 674 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 675 676 memset (c_failed, 0, sizeof(c_failed)); 677 678 for (j = 0; j < locale_name_count; j++) 679 { 680 set_test_locale (j); /* setlocale() can be slow! */ 681 for (i = 0; i < n_checks; i++) 682 { 683 size_t m_len; 684 const struct two_neq_strs *const t = neq_strings + i; 685 m_len = t->s1.len > t->s2.len ? t->s1.len : t->s2.len; 686 if (t->dif_pos >= m_len) 687 { 688 fprintf (stderr, 689 "ERROR: neq_strings[%u] has wrong dif_pos (%u): dif_pos is expected to be less than " 690 "s1.len (%u) or s2.len (%u).\n", (unsigned int) i, (unsigned 691 int) t-> 692 dif_pos, 693 (unsigned int) t->s1.len, (unsigned int) t->s2.len); 694 exit (99); 695 } 696 if (t->dif_pos > t->s1.len) 697 { 698 fprintf (stderr, 699 "ERROR: neq_strings[%u] has wrong dif_pos (%u): dif_pos is expected to be less or " 700 "equal to s1.len (%u).\n", (unsigned int) i, (unsigned 701 int) t->dif_pos, 702 (unsigned int) t->s1.len); 703 exit (99); 704 } 705 if (t->dif_pos > t->s2.len) 706 { 707 fprintf (stderr, 708 "ERROR: neq_strings[%u] has wrong dif_pos (%u): dif_pos is expected to be less or " 709 "equal to s2.len (%u).\n", (unsigned int) i, (unsigned 710 int) t->dif_pos, 711 (unsigned int) t->s2.len); 712 exit (99); 713 } 714 for (k = 0; k <= m_len + 1 && ! c_failed[i]; k++) 715 { 716 if (k <= t->dif_pos) 717 { 718 if (! MHD_str_equal_caseless_n_ (t->s1.str, t->s2.str, k)) 719 { 720 t_failed++; 721 c_failed[i] = ! 0; 722 fprintf (stderr, 723 "FAILED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", %u) returned zero," 724 " while expected non-zero. Locale: %s\n", 725 n_prnt (t->s1.str), n_prnt (t->s2.str), (unsigned int) k, 726 get_current_locale_str ()); 727 } 728 else if (! MHD_str_equal_caseless_n_ (t->s2.str, t->s1.str, k)) 729 { 730 t_failed++; 731 c_failed[i] = ! 0; 732 fprintf (stderr, 733 "FAILED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", %u) returned zero," 734 " while expected non-zero. Locale: %s\n", 735 n_prnt (t->s2.str), n_prnt (t->s1.str), (unsigned int) k, 736 get_current_locale_str ()); 737 } 738 } 739 else 740 { 741 if (MHD_str_equal_caseless_n_ (t->s1.str, t->s2.str, k)) 742 { 743 t_failed++; 744 c_failed[i] = ! 0; 745 fprintf (stderr, 746 "FAILED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", %u) returned non-zero," 747 " while expected zero. Locale: %s\n", 748 n_prnt (t->s1.str), n_prnt (t->s2.str), (unsigned int) k, 749 get_current_locale_str ()); 750 } 751 else if (MHD_str_equal_caseless_n_ (t->s2.str, t->s1.str, k)) 752 { 753 t_failed++; 754 c_failed[i] = ! 0; 755 fprintf (stderr, 756 "FAILED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", %u) returned non-zero," 757 " while expected zero. Locale: %s\n", 758 n_prnt (t->s2.str), n_prnt (t->s1.str), (unsigned int) k, 759 get_current_locale_str ()); 760 } 761 } 762 } 763 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) 764 { 765 printf ( 766 "PASSED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", N) != 0 && \\\n" 767 " MHD_str_equal_caseless_n_(\"%s\", \"%s\", N) != 0, where N is 0..%u\n", 768 n_prnt (t->s1.str), n_prnt (t->s2.str), n_prnt (t->s2.str), 769 n_prnt (t->s1.str), 770 (unsigned int) t->dif_pos); 771 772 printf ( 773 "PASSED: MHD_str_equal_caseless_n_(\"%s\", \"%s\", N) == 0 && \\\n" 774 " MHD_str_equal_caseless_n_(\"%s\", \"%s\", N) == 0, where N is %u..%u\n", 775 n_prnt (t->s1.str), n_prnt (t->s2.str), n_prnt (t->s2.str), 776 n_prnt (t->s1.str), 777 (unsigned int) t->dif_pos + 1, (unsigned int) m_len + 1); 778 } 779 } 780 } 781 return t_failed; 782 } 783 784 785 /* 786 * Run eq/neq strings tests 787 */ 788 static int 789 run_eq_neq_str_tests (void) 790 { 791 size_t str_equal_caseless_fails = 0; 792 size_t str_equal_caseless_n_fails = 0; 793 size_t res; 794 795 res = check_eq_strings (); 796 if (res != 0) 797 { 798 str_equal_caseless_fails += res; 799 fprintf (stderr, "FAILED: testcase check_eq_strings() failed.\n\n"); 800 } 801 else if (verbose > 1) 802 printf ("PASSED: testcase check_eq_strings() successfully passed.\n\n"); 803 804 res = check_neq_strings (); 805 if (res != 0) 806 { 807 str_equal_caseless_fails += res; 808 fprintf (stderr, "FAILED: testcase check_neq_strings() failed.\n\n"); 809 } 810 else if (verbose > 1) 811 printf ("PASSED: testcase check_neq_strings() successfully passed.\n\n"); 812 813 if (str_equal_caseless_fails) 814 fprintf (stderr, 815 "FAILED: function MHD_str_equal_caseless_() failed %lu time%s.\n\n", 816 (unsigned long) str_equal_caseless_fails, 817 str_equal_caseless_fails == 1 ? "" : 818 "s"); 819 else if (verbose > 0) 820 printf ( 821 "PASSED: function MHD_str_equal_caseless_() successfully passed all checks.\n\n"); 822 823 res = check_eq_strings_n (); 824 if (res != 0) 825 { 826 str_equal_caseless_n_fails += res; 827 fprintf (stderr, "FAILED: testcase check_eq_strings_n() failed.\n\n"); 828 } 829 else if (verbose > 1) 830 printf ("PASSED: testcase check_eq_strings_n() successfully passed.\n\n"); 831 832 res = check_neq_strings_n (); 833 if (res != 0) 834 { 835 str_equal_caseless_n_fails += res; 836 fprintf (stderr, "FAILED: testcase check_neq_strings_n() failed.\n\n"); 837 } 838 else if (verbose > 1) 839 printf ("PASSED: testcase check_neq_strings_n() successfully passed.\n\n"); 840 841 if (str_equal_caseless_n_fails) 842 fprintf (stderr, 843 "FAILED: function MHD_str_equal_caseless_n_() failed %lu time%s.\n\n", 844 (unsigned long) str_equal_caseless_n_fails, 845 str_equal_caseless_n_fails == 1 ? "" : 846 "s"); 847 else if (verbose > 0) 848 printf ( 849 "PASSED: function MHD_str_equal_caseless_n_() successfully passed all checks.\n\n"); 850 851 if (str_equal_caseless_fails || str_equal_caseless_n_fails) 852 { 853 if (verbose > 0) 854 printf ("At least one test failed.\n"); 855 856 return 1; 857 } 858 859 if (verbose > 0) 860 printf ("All tests passed successfully.\n"); 861 862 return 0; 863 } 864 865 866 /* 867 * Digits in string -> value tests 868 */ 869 870 struct str_with_value 871 { 872 const struct str_with_len str; 873 const size_t num_of_digt; 874 const uint64_t val; 875 }; 876 877 /* valid string for conversion to unsigned integer value */ 878 static const struct str_with_value dstrs_w_values[] = { 879 /* simplest strings */ 880 {D_STR_W_LEN ("1"), 1, 1}, 881 {D_STR_W_LEN ("0"), 1, 0}, 882 {D_STR_W_LEN ("10000"), 5, 10000}, 883 884 /* all digits */ 885 {D_STR_W_LEN ("1234"), 4, 1234}, 886 {D_STR_W_LEN ("4567"), 4, 4567}, 887 {D_STR_W_LEN ("7890"), 4, 7890}, 888 {D_STR_W_LEN ("8021"), 4, 8021}, 889 {D_STR_W_LEN ("9754"), 4, 9754}, 890 {D_STR_W_LEN ("6392"), 4, 6392}, 891 892 /* various prefixes */ 893 {D_STR_W_LEN ("00000000"), 8, 0}, 894 {D_STR_W_LEN ("0755"), 4, 755}, /* not to be interpreted as octal value! */ 895 {D_STR_W_LEN ("002"), 3, 2}, 896 {D_STR_W_LEN ("0001"), 4, 1}, 897 {D_STR_W_LEN ("00000000000000000000000031295483"), 32, 31295483}, 898 899 /* numbers below and above limits */ 900 {D_STR_W_LEN ("127"), 3, 127}, /* 0x7F, SCHAR_MAX */ 901 {D_STR_W_LEN ("128"), 3, 128}, /* 0x80, SCHAR_MAX+1 */ 902 {D_STR_W_LEN ("255"), 3, 255}, /* 0xFF, UCHAR_MAX */ 903 {D_STR_W_LEN ("256"), 3, 256}, /* 0x100, UCHAR_MAX+1 */ 904 {D_STR_W_LEN ("32767"), 5, 32767}, /* 0x7FFF, INT16_MAX */ 905 {D_STR_W_LEN ("32768"), 5, 32768}, /* 0x8000, INT16_MAX+1 */ 906 {D_STR_W_LEN ("65535"), 5, 65535}, /* 0xFFFF, UINT16_MAX */ 907 {D_STR_W_LEN ("65536"), 5, 65536}, /* 0x10000, UINT16_MAX+1 */ 908 {D_STR_W_LEN ("2147483647"), 10, 2147483647}, /* 0x7FFFFFFF, INT32_MAX */ 909 {D_STR_W_LEN ("2147483648"), 10, UINT64_C (2147483648)}, /* 0x80000000, INT32_MAX+1 */ 910 {D_STR_W_LEN ("4294967295"), 10, UINT64_C (4294967295)}, /* 0xFFFFFFFF, UINT32_MAX */ 911 {D_STR_W_LEN ("4294967296"), 10, UINT64_C (4294967296)}, /* 0x100000000, UINT32_MAX+1 */ 912 {D_STR_W_LEN ("9223372036854775807"), 19, UINT64_C (9223372036854775807)}, /* 0x7FFFFFFFFFFFFFFF, INT64_MAX */ 913 {D_STR_W_LEN ("9223372036854775808"), 19, UINT64_C (9223372036854775808)}, /* 0x8000000000000000, INT64_MAX+1 */ 914 {D_STR_W_LEN ("18446744073709551615"), 20, UINT64_C (18446744073709551615)}, /* 0xFFFFFFFFFFFFFFFF, UINT64_MAX */ 915 916 /* random numbers */ 917 {D_STR_W_LEN ("10186753"), 8, 10186753}, 918 {D_STR_W_LEN ("144402566"), 9, 144402566}, 919 {D_STR_W_LEN ("151903144"), 9, 151903144}, 920 {D_STR_W_LEN ("139264621"), 9, 139264621}, 921 {D_STR_W_LEN ("730348"), 6, 730348}, 922 {D_STR_W_LEN ("21584377"), 8, 21584377}, 923 {D_STR_W_LEN ("709"), 3, 709}, 924 {D_STR_W_LEN ("54"), 2, 54}, 925 {D_STR_W_LEN ("8452"), 4, 8452}, 926 {D_STR_W_LEN ("17745098750013624977"), 20, UINT64_C (17745098750013624977)}, 927 {D_STR_W_LEN ("06786878769931678000"), 20, UINT64_C (6786878769931678000)}, 928 929 /* non-digit suffixes */ 930 {D_STR_W_LEN ("1234oa"), 4, 1234}, 931 {D_STR_W_LEN ("20h"), 2, 20}, /* not to be interpreted as hex value! */ 932 {D_STR_W_LEN ("0x1F"), 1, 0}, /* not to be interpreted as hex value! */ 933 {D_STR_W_LEN ("0564`~}"), 4, 564}, 934 {D_STR_W_LEN ("7240146.724"), 7, 7240146}, 935 {D_STR_W_LEN ("2,9"), 1, 2}, 936 {D_STR_W_LEN ("200+1"), 3, 200}, 937 {D_STR_W_LEN ("1a"), 1, 1}, 938 {D_STR_W_LEN ("2E"), 1, 2}, 939 {D_STR_W_LEN ("6c"), 1, 6}, 940 {D_STR_W_LEN ("8F"), 1, 8}, 941 {D_STR_W_LEN ("287416997! And the not too long string."), 9, 287416997} 942 }; 943 944 /* strings that should overflow uint64_t */ 945 static const struct str_with_len str_ovflw[] = { 946 D_STR_W_LEN ("18446744073709551616"), /* 0x10000000000000000, UINT64_MAX+1 */ 947 D_STR_W_LEN ("18446744073709551620"), 948 D_STR_W_LEN ("18446744083709551615"), 949 D_STR_W_LEN ("19234761020556472143"), 950 D_STR_W_LEN ("184467440737095516150"), 951 D_STR_W_LEN ("1844674407370955161500"), 952 D_STR_W_LEN ("000018446744073709551616"), /* 0x10000000000000000, UINT64_MAX+1 */ 953 D_STR_W_LEN ("20000000000000000000"), 954 D_STR_W_LEN ("020000000000000000000"), 955 D_STR_W_LEN ("0020000000000000000000"), 956 D_STR_W_LEN ("100000000000000000000"), 957 D_STR_W_LEN ("434532891232591226417"), 958 D_STR_W_LEN ("99999999999999999999"), 959 D_STR_W_LEN ("18446744073709551616abcd"), /* 0x10000000000000000, UINT64_MAX+1 */ 960 D_STR_W_LEN ("20000000000000000000 suffix"), 961 D_STR_W_LEN ("020000000000000000000x") 962 }; 963 964 /* strings that should not be convertible to numeric value */ 965 static const struct str_with_len str_no_num[] = { 966 D_STR_W_LEN ("zero"), 967 D_STR_W_LEN ("one"), 968 D_STR_W_LEN ("\xb9\xb2\xb3"), /* superscript "123" in ISO-8859-1/CP1252 */ 969 D_STR_W_LEN ("\xc2\xb9\xc2\xb2\xc2\xb3"), /* superscript "123" in UTF-8 */ 970 D_STR_W_LEN ("\xd9\xa1\xd9\xa2\xd9\xa3"), /* Arabic-Indic "١٢٣" in UTF-8 */ 971 D_STR_W_LEN ("\xdb\xb1\xdb\xb2\xdb\xb3"), /* Ext Arabic-Indic "۱۲۳" in UTF-8 */ 972 D_STR_W_LEN ("\xe0\xa5\xa7\xe0\xa5\xa8\xe0\xa5\xa9"), /* Devanagari "१२३" in UTF-8 */ 973 D_STR_W_LEN ("\xe4\xb8\x80\xe4\xba\x8c\xe4\xb8\x89"), /* Chinese "一二三" in UTF-8 */ 974 D_STR_W_LEN ("\xd2\xbb\xb6\xfe\xc8\xfd"), /* Chinese "一二三" in GB2312/CP936 */ 975 D_STR_W_LEN ("\x1B\x24\x29\x41\x0E\x52\x3B\x36\x7E\x48\x7D\x0F") /* Chinese "一二三" in ISO-2022-CN */ 976 }; 977 978 /* valid hex string for conversion to unsigned integer value */ 979 static const struct str_with_value xdstrs_w_values[] = { 980 /* simplest strings */ 981 {D_STR_W_LEN ("1"), 1, 0x1}, 982 {D_STR_W_LEN ("0"), 1, 0x0}, 983 {D_STR_W_LEN ("10000"), 5, 0x10000}, 984 985 /* all digits */ 986 {D_STR_W_LEN ("1234"), 4, 0x1234}, 987 {D_STR_W_LEN ("4567"), 4, 0x4567}, 988 {D_STR_W_LEN ("7890"), 4, 0x7890}, 989 {D_STR_W_LEN ("8021"), 4, 0x8021}, 990 {D_STR_W_LEN ("9754"), 4, 0x9754}, 991 {D_STR_W_LEN ("6392"), 4, 0x6392}, 992 {D_STR_W_LEN ("abcd"), 4, 0xABCD}, 993 {D_STR_W_LEN ("cdef"), 4, 0xCDEF}, 994 {D_STR_W_LEN ("FEAB"), 4, 0xFEAB}, 995 {D_STR_W_LEN ("BCED"), 4, 0xBCED}, 996 {D_STR_W_LEN ("bCeD"), 4, 0xBCED}, 997 {D_STR_W_LEN ("1A5F"), 4, 0x1A5F}, 998 {D_STR_W_LEN ("12AB"), 4, 0x12AB}, 999 {D_STR_W_LEN ("CD34"), 4, 0xCD34}, 1000 {D_STR_W_LEN ("56EF"), 4, 0x56EF}, 1001 {D_STR_W_LEN ("7a9f"), 4, 0x7A9F}, 1002 1003 /* various prefixes */ 1004 {D_STR_W_LEN ("00000000"), 8, 0x0}, 1005 {D_STR_W_LEN ("0755"), 4, 0x755}, /* not to be interpreted as octal value! */ 1006 {D_STR_W_LEN ("002"), 3, 0x2}, 1007 {D_STR_W_LEN ("0001"), 4, 0x1}, 1008 {D_STR_W_LEN ("00a"), 3, 0xA}, 1009 {D_STR_W_LEN ("0F"), 2, 0xF}, 1010 {D_STR_W_LEN ("0000000000000000000000003A29e4C3"), 32, 0x3A29E4C3}, 1011 1012 /* numbers below and above limits */ 1013 {D_STR_W_LEN ("7F"), 2, 127}, /* 0x7F, SCHAR_MAX */ 1014 {D_STR_W_LEN ("7f"), 2, 127}, /* 0x7F, SCHAR_MAX */ 1015 {D_STR_W_LEN ("80"), 2, 128}, /* 0x80, SCHAR_MAX+1 */ 1016 {D_STR_W_LEN ("fF"), 2, 255}, /* 0xFF, UCHAR_MAX */ 1017 {D_STR_W_LEN ("Ff"), 2, 255}, /* 0xFF, UCHAR_MAX */ 1018 {D_STR_W_LEN ("FF"), 2, 255}, /* 0xFF, UCHAR_MAX */ 1019 {D_STR_W_LEN ("ff"), 2, 255}, /* 0xFF, UCHAR_MAX */ 1020 {D_STR_W_LEN ("100"), 3, 256}, /* 0x100, UCHAR_MAX+1 */ 1021 {D_STR_W_LEN ("7fff"), 4, 32767}, /* 0x7FFF, INT16_MAX */ 1022 {D_STR_W_LEN ("7FFF"), 4, 32767}, /* 0x7FFF, INT16_MAX */ 1023 {D_STR_W_LEN ("7Fff"), 4, 32767}, /* 0x7FFF, INT16_MAX */ 1024 {D_STR_W_LEN ("8000"), 4, 32768}, /* 0x8000, INT16_MAX+1 */ 1025 {D_STR_W_LEN ("ffff"), 4, 65535}, /* 0xFFFF, UINT16_MAX */ 1026 {D_STR_W_LEN ("FFFF"), 4, 65535}, /* 0xFFFF, UINT16_MAX */ 1027 {D_STR_W_LEN ("FffF"), 4, 65535}, /* 0xFFFF, UINT16_MAX */ 1028 {D_STR_W_LEN ("10000"), 5, 65536}, /* 0x10000, UINT16_MAX+1 */ 1029 {D_STR_W_LEN ("7FFFFFFF"), 8, 2147483647}, /* 0x7FFFFFFF, INT32_MAX */ 1030 {D_STR_W_LEN ("7fffffff"), 8, 2147483647}, /* 0x7FFFFFFF, INT32_MAX */ 1031 {D_STR_W_LEN ("7FFffFff"), 8, 2147483647}, /* 0x7FFFFFFF, INT32_MAX */ 1032 {D_STR_W_LEN ("80000000"), 8, UINT64_C (2147483648)}, /* 0x80000000, INT32_MAX+1 */ 1033 {D_STR_W_LEN ("FFFFFFFF"), 8, UINT64_C (4294967295)}, /* 0xFFFFFFFF, UINT32_MAX */ 1034 {D_STR_W_LEN ("ffffffff"), 8, UINT64_C (4294967295)}, /* 0xFFFFFFFF, UINT32_MAX */ 1035 {D_STR_W_LEN ("FfFfFfFf"), 8, UINT64_C (4294967295)}, /* 0xFFFFFFFF, UINT32_MAX */ 1036 {D_STR_W_LEN ("100000000"), 9, UINT64_C (4294967296)}, /* 0x100000000, UINT32_MAX+1 */ 1037 {D_STR_W_LEN ("7fffffffffffffff"), 16, UINT64_C (9223372036854775807)}, /* 0x7FFFFFFFFFFFFFFF, INT64_MAX */ 1038 {D_STR_W_LEN ("7FFFFFFFFFFFFFFF"), 16, UINT64_C (9223372036854775807)}, /* 0x7FFFFFFFFFFFFFFF, INT64_MAX */ 1039 {D_STR_W_LEN ("7FfffFFFFffFFffF"), 16, UINT64_C (9223372036854775807)}, /* 0x7FFFFFFFFFFFFFFF, INT64_MAX */ 1040 {D_STR_W_LEN ("8000000000000000"), 16, UINT64_C (9223372036854775808)}, /* 0x8000000000000000, INT64_MAX+1 */ 1041 {D_STR_W_LEN ("ffffffffffffffff"), 16, UINT64_C (18446744073709551615)}, /* 0xFFFFFFFFFFFFFFFF, UINT64_MAX */ 1042 {D_STR_W_LEN ("FFFFFFFFFFFFFFFF"), 16, UINT64_C (18446744073709551615)}, /* 0xFFFFFFFFFFFFFFFF, UINT64_MAX */ 1043 {D_STR_W_LEN ("FffFffFFffFFfFFF"), 16, UINT64_C (18446744073709551615)}, /* 0xFFFFFFFFFFFFFFFF, UINT64_MAX */ 1044 1045 /* random numbers */ 1046 {D_STR_W_LEN ("10186753"), 8, 0x10186753}, 1047 {D_STR_W_LEN ("144402566"), 9, 0x144402566}, 1048 {D_STR_W_LEN ("151903144"), 9, 0x151903144}, 1049 {D_STR_W_LEN ("139264621"), 9, 0x139264621}, 1050 {D_STR_W_LEN ("730348"), 6, 0x730348}, 1051 {D_STR_W_LEN ("21584377"), 8, 0x21584377}, 1052 {D_STR_W_LEN ("709"), 3, 0x709}, 1053 {D_STR_W_LEN ("54"), 2, 0x54}, 1054 {D_STR_W_LEN ("8452"), 4, 0x8452}, 1055 {D_STR_W_LEN ("22353EC6"), 8, 0x22353EC6}, 1056 {D_STR_W_LEN ("307F1655"), 8, 0x307F1655}, 1057 {D_STR_W_LEN ("1FCB7226"), 8, 0x1FCB7226}, 1058 {D_STR_W_LEN ("82480560"), 8, 0x82480560}, 1059 {D_STR_W_LEN ("7386D95"), 7, 0x7386D95}, 1060 {D_STR_W_LEN ("EC3AB"), 5, 0xEC3AB}, 1061 {D_STR_W_LEN ("6DD05"), 5, 0x6DD05}, 1062 {D_STR_W_LEN ("C5DF"), 4, 0xC5DF}, 1063 {D_STR_W_LEN ("6CE"), 3, 0x6CE}, 1064 {D_STR_W_LEN ("CE6"), 3, 0xCE6}, 1065 {D_STR_W_LEN ("ce6"), 3, 0xCE6}, 1066 {D_STR_W_LEN ("F27"), 3, 0xF27}, 1067 {D_STR_W_LEN ("8497D54277D7E1"), 14, UINT64_C (37321639124785121)}, 1068 {D_STR_W_LEN ("8497d54277d7e1"), 14, UINT64_C (37321639124785121)}, 1069 {D_STR_W_LEN ("8497d54277d7E1"), 14, UINT64_C (37321639124785121)}, 1070 {D_STR_W_LEN ("8C8112D0A06"), 11, UINT64_C (9655374645766)}, 1071 {D_STR_W_LEN ("8c8112d0a06"), 11, UINT64_C (9655374645766)}, 1072 {D_STR_W_LEN ("8c8112d0A06"), 11, UINT64_C (9655374645766)}, 1073 {D_STR_W_LEN ("1774509875001362"), 16, UINT64_C (1690064375898968930)}, 1074 {D_STR_W_LEN ("0678687876998000"), 16, UINT64_C (466237428027981824)}, 1075 1076 /* non-digit suffixes */ 1077 {D_STR_W_LEN ("1234oa"), 4, 0x1234}, 1078 {D_STR_W_LEN ("20h"), 2, 0x20}, 1079 {D_STR_W_LEN ("2CH"), 2, 0x2C}, 1080 {D_STR_W_LEN ("2ch"), 2, 0x2C}, 1081 {D_STR_W_LEN ("0x1F"), 1, 0x0}, /* not to be interpreted as hex prefix! */ 1082 {D_STR_W_LEN ("0564`~}"), 4, 0x564}, 1083 {D_STR_W_LEN ("0A64`~}"), 4, 0xA64}, 1084 {D_STR_W_LEN ("056c`~}"), 4, 0X56C}, 1085 {D_STR_W_LEN ("7240146.724"), 7, 0x7240146}, 1086 {D_STR_W_LEN ("7E4c1AB.724"), 7, 0X7E4C1AB}, 1087 {D_STR_W_LEN ("F24B1B6.724"), 7, 0xF24B1B6}, 1088 {D_STR_W_LEN ("2,9"), 1, 0x2}, 1089 {D_STR_W_LEN ("a,9"), 1, 0xA}, 1090 {D_STR_W_LEN ("200+1"), 3, 0x200}, 1091 {D_STR_W_LEN ("2cc+1"), 3, 0x2CC}, 1092 {D_STR_W_LEN ("2cC+1"), 3, 0x2CC}, 1093 {D_STR_W_LEN ("27416997! And the not too long string."), 8, 0x27416997}, 1094 {D_STR_W_LEN ("27555416997! And the not too long string."), 11, 1095 0x27555416997}, 1096 {D_STR_W_LEN ("416997And the not too long string."), 7, 0x416997A}, 1097 {D_STR_W_LEN ("0F4C3Dabstract addition to make string even longer"), 8, 1098 0xF4C3DAB} 1099 }; 1100 1101 /* hex strings that should overflow uint64_t */ 1102 static const struct str_with_len strx_ovflw[] = { 1103 D_STR_W_LEN ("10000000000000000"), /* 0x10000000000000000, UINT64_MAX+1 */ 1104 D_STR_W_LEN ("10000000000000001"), 1105 D_STR_W_LEN ("10000000000000002"), 1106 D_STR_W_LEN ("1000000000000000A"), 1107 D_STR_W_LEN ("11000000000000000"), 1108 D_STR_W_LEN ("010000000000000000"), /* 0x10000000000000000, UINT64_MAX+1 */ 1109 D_STR_W_LEN ("000010000000000000000"), /* 0x10000000000000000, UINT64_MAX+1 */ 1110 D_STR_W_LEN ("20000000000000000000"), 1111 D_STR_W_LEN ("020000000000000000000"), 1112 D_STR_W_LEN ("0020000000000000000000"), 1113 D_STR_W_LEN ("20000000000000000"), 1114 D_STR_W_LEN ("A0000000000000000"), 1115 D_STR_W_LEN ("F0000000000000000"), 1116 D_STR_W_LEN ("a0000000000000000"), 1117 D_STR_W_LEN ("11111111111111111"), 1118 D_STR_W_LEN ("CcCcCCccCCccCCccC"), 1119 D_STR_W_LEN ("f0000000000000000"), 1120 D_STR_W_LEN ("100000000000000000000"), 1121 D_STR_W_LEN ("434532891232591226417"), 1122 D_STR_W_LEN ("10000000000000000a"), 1123 D_STR_W_LEN ("10000000000000000E"), 1124 D_STR_W_LEN ("100000000000000000 and nothing"), /* 0x10000000000000000, UINT64_MAX+1 */ 1125 D_STR_W_LEN ("100000000000000000xx"), /* 0x10000000000000000, UINT64_MAX+1 */ 1126 D_STR_W_LEN ("99999999999999999999"), 1127 D_STR_W_LEN ("18446744073709551616abcd"), 1128 D_STR_W_LEN ("20000000000000000000 suffix"), 1129 D_STR_W_LEN ("020000000000000000000x") 1130 }; 1131 1132 1133 static size_t 1134 check_str_to_uint64_valid (void) 1135 { 1136 size_t t_failed = 0; 1137 size_t i, j; 1138 int c_failed[sizeof(dstrs_w_values) 1139 / sizeof(dstrs_w_values[0])]; 1140 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 1141 1142 memset (c_failed, 0, sizeof(c_failed)); 1143 1144 for (j = 0; j < locale_name_count; j++) 1145 { 1146 set_test_locale (j); /* setlocale() can be slow! */ 1147 for (i = 0; i < n_checks; i++) 1148 { 1149 uint64_t rv; 1150 size_t rs; 1151 const struct str_with_value *const t = dstrs_w_values + i; 1152 1153 if (c_failed[i]) 1154 continue; /* skip already failed checks */ 1155 1156 if (t->str.len < t->num_of_digt) 1157 { 1158 fprintf (stderr, 1159 "ERROR: dstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" 1160 " to be less or equal to str.len (%u).\n", 1161 (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned 1162 int) t->str. 1163 len); 1164 exit (99); 1165 } 1166 rv = 9435223; /* some random value */ 1167 rs = MHD_str_to_uint64_ (t->str.str, &rv); 1168 if (rs != t->num_of_digt) 1169 { 1170 t_failed++; 1171 c_failed[i] = ! 0; 1172 fprintf (stderr, 1173 "FAILED: MHD_str_to_uint64_(\"%s\", ->%" PRIu64 ") returned %" 1174 PRIuPTR 1175 ", while expecting %d." 1176 " Locale: %s\n", n_prnt (t->str.str), rv, (uintptr_t) rs, 1177 (int) t->num_of_digt, get_current_locale_str ()); 1178 } 1179 if (rv != t->val) 1180 { 1181 t_failed++; 1182 c_failed[i] = ! 0; 1183 fprintf (stderr, 1184 "FAILED: MHD_str_to_uint64_(\"%s\", ->%" PRIu64 1185 ") converted string to value %" 1186 PRIu64 "," 1187 " while expecting result %" PRIu64 ". Locale: %s\n", 1188 n_prnt (t->str.str), rv, rv, 1189 t->val, get_current_locale_str ()); 1190 } 1191 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) 1192 printf ("PASSED: MHD_str_to_uint64_(\"%s\", ->%" PRIu64 ") == %" \ 1193 PRIuPTR "\n", 1194 n_prnt (t->str.str), rv, rs); 1195 } 1196 } 1197 return t_failed; 1198 } 1199 1200 1201 static size_t 1202 check_str_to_uint64_all_chars (void) 1203 { 1204 int c_failed[256]; /* from 0 to 255 */ 1205 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 1206 size_t t_failed = 0; 1207 size_t j; 1208 1209 memset (c_failed, 0, sizeof(c_failed)); 1210 1211 for (j = 0; j < locale_name_count; j++) 1212 { 1213 unsigned int c; 1214 uint64_t test_val; 1215 1216 set_test_locale (j); /* setlocale() can be slow! */ 1217 for (c = 0; c < n_checks; c++) 1218 { 1219 static const uint64_t rnd_val = 24941852; 1220 size_t rs; 1221 if ((c >= '0') && (c <= '9') ) 1222 continue; /* skip digits */ 1223 for (test_val = 0; test_val <= rnd_val && ! c_failed[c]; test_val += 1224 rnd_val) 1225 { 1226 char test_str[] = "0123"; 1227 uint64_t rv = test_val; 1228 1229 test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */ 1230 rs = MHD_str_to_uint64_ (test_str, &rv); 1231 if (rs != 0) 1232 { 1233 t_failed++; 1234 c_failed[c] = ! 0; 1235 fprintf (stderr, 1236 "FAILED: MHD_str_to_uint64_(\"%s\", ->%" PRIu64 1237 ") returned %" PRIuPTR 1238 ", while expecting zero." 1239 " Locale: %s\n", n_prnt (test_str), rv, (uintptr_t) rs, 1240 get_current_locale_str ()); 1241 } 1242 else if (rv != test_val) 1243 { 1244 t_failed++; 1245 c_failed[c] = ! 0; 1246 fprintf (stderr, 1247 "FAILED: MHD_str_to_uint64_(\"%s\", &ret_val) modified value of ret_val" 1248 " (before call: %" PRIu64 ", after call %" PRIu64 1249 "). Locale: %s\n", 1250 n_prnt (test_str), test_val, rv, get_current_locale_str ()); 1251 } 1252 } 1253 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[c]) 1254 { 1255 char test_str[] = "0123"; 1256 test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */ 1257 1258 printf ("PASSED: MHD_str_to_uint64_(\"%s\", &ret_val) == 0, " 1259 "value of ret_val is unmodified\n", 1260 n_prnt (test_str)); 1261 } 1262 } 1263 } 1264 return t_failed; 1265 } 1266 1267 1268 static size_t 1269 check_str_to_uint64_overflow (void) 1270 { 1271 size_t t_failed = 0; 1272 size_t i, j; 1273 int c_failed[sizeof(str_ovflw) / sizeof(str_ovflw[0])]; 1274 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 1275 1276 memset (c_failed, 0, sizeof(c_failed)); 1277 1278 for (j = 0; j < locale_name_count; j++) 1279 { 1280 set_test_locale (j); /* setlocale() can be slow! */ 1281 for (i = 0; i < n_checks; i++) 1282 { 1283 size_t rs; 1284 const struct str_with_len *const t = str_ovflw + i; 1285 static const uint64_t rnd_val = 2; 1286 uint64_t test_val; 1287 1288 for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val += 1289 rnd_val) 1290 { 1291 uint64_t rv = test_val; 1292 1293 rs = MHD_str_to_uint64_ (t->str, &rv); 1294 if (rs != 0) 1295 { 1296 t_failed++; 1297 c_failed[i] = ! 0; 1298 fprintf (stderr, 1299 "FAILED: MHD_str_to_uint64_(\"%s\", ->%" PRIu64 1300 ") returned %" PRIuPTR 1301 ", while expecting zero." 1302 " Locale: %s\n", n_prnt (t->str), rv, (uintptr_t) rs, 1303 get_current_locale_str ()); 1304 } 1305 else if (rv != test_val) 1306 { 1307 t_failed++; 1308 c_failed[i] = ! 0; 1309 fprintf (stderr, 1310 "FAILED: MHD_str_to_uint64_(\"%s\", &ret_val) modified value of ret_val" 1311 " (before call: %" PRIu64 ", after call %" PRIu64 1312 "). Locale: %s\n", 1313 n_prnt (t->str), test_val, rv, get_current_locale_str ()); 1314 } 1315 } 1316 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) 1317 printf ("PASSED: MHD_str_to_uint64_(\"%s\", &ret_val) == 0, " 1318 "value of ret_val is unmodified\n", 1319 n_prnt (t->str)); 1320 } 1321 } 1322 return t_failed; 1323 } 1324 1325 1326 static size_t 1327 check_str_to_uint64_no_val (void) 1328 { 1329 size_t t_failed = 0; 1330 size_t i, j; 1331 int c_failed[sizeof(str_no_num) / sizeof(str_no_num[0])]; 1332 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 1333 1334 memset (c_failed, 0, sizeof(c_failed)); 1335 1336 for (j = 0; j < locale_name_count; j++) 1337 { 1338 set_test_locale (j); /* setlocale() can be slow! */ 1339 for (i = 0; i < n_checks; i++) 1340 { 1341 size_t rs; 1342 const struct str_with_len *const t = str_no_num + i; 1343 static const uint64_t rnd_val = 74218431; 1344 uint64_t test_val; 1345 1346 for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val += 1347 rnd_val) 1348 { 1349 uint64_t rv = test_val; 1350 1351 rs = MHD_str_to_uint64_ (t->str, &rv); 1352 if (rs != 0) 1353 { 1354 t_failed++; 1355 c_failed[i] = ! 0; 1356 fprintf (stderr, 1357 "FAILED: MHD_str_to_uint64_(\"%s\", ->%" PRIu64 1358 ") returned %" PRIuPTR 1359 ", while expecting zero." 1360 " Locale: %s\n", n_prnt (t->str), rv, (uintptr_t) rs, 1361 get_current_locale_str ()); 1362 } 1363 else if (rv != test_val) 1364 { 1365 t_failed++; 1366 c_failed[i] = ! 0; 1367 fprintf (stderr, 1368 "FAILED: MHD_str_to_uint64_(\"%s\", &ret_val) modified value of ret_val" 1369 " (before call: %" PRIu64 ", after call %" PRIu64 1370 "). Locale: %s\n", 1371 n_prnt (t->str), test_val, rv, get_current_locale_str ()); 1372 } 1373 } 1374 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) 1375 printf ("PASSED: MHD_str_to_uint64_(\"%s\", &ret_val) == 0, " 1376 "value of ret_val is unmodified\n", 1377 n_prnt (t->str)); 1378 } 1379 } 1380 return t_failed; 1381 } 1382 1383 1384 static size_t 1385 check_str_to_uint64_n_valid (void) 1386 { 1387 size_t t_failed = 0; 1388 size_t i, j; 1389 int c_failed[sizeof(dstrs_w_values) 1390 / sizeof(dstrs_w_values[0])]; 1391 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 1392 1393 memset (c_failed, 0, sizeof(c_failed)); 1394 1395 for (j = 0; j < locale_name_count; j++) 1396 { 1397 set_test_locale (j); /* setlocale() can be slow! */ 1398 for (i = 0; i < n_checks; i++) 1399 { 1400 uint64_t rv = 1235572; /* some random value */ 1401 size_t rs = 0; 1402 size_t len; 1403 const struct str_with_value *const t = dstrs_w_values + i; 1404 1405 if (t->str.len < t->num_of_digt) 1406 { 1407 fprintf (stderr, 1408 "ERROR: dstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" 1409 " to be less or equal to str.len (%u).\n", 1410 (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned 1411 int) t->str. 1412 len); 1413 exit (99); 1414 } 1415 for (len = t->num_of_digt; len <= t->str.len + 1 && ! c_failed[i]; len++) 1416 { 1417 rs = MHD_str_to_uint64_n_ (t->str.str, len, &rv); 1418 if (rs != t->num_of_digt) 1419 { 1420 t_failed++; 1421 c_failed[i] = ! 0; 1422 fprintf (stderr, 1423 "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", ->%" 1424 PRIu64 ")" 1425 " returned %" PRIuPTR ", while expecting %d. Locale: %s\n", 1426 n_prnt (t->str.str), (uintptr_t) len, rv, (uintptr_t) rs, 1427 (int) t->num_of_digt, get_current_locale_str ()); 1428 } 1429 if (rv != t->val) 1430 { 1431 t_failed++; 1432 c_failed[i] = ! 0; 1433 fprintf (stderr, 1434 "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", ->%" 1435 PRIu64 ")" 1436 " converted string to value %" PRIu64 1437 ", while expecting result %" PRIu64 1438 ". Locale: %s\n", n_prnt (t->str.str), (uintptr_t) len, rv, 1439 rv, 1440 t->val, get_current_locale_str ()); 1441 } 1442 } 1443 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) 1444 printf ("PASSED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR "..%" 1445 PRIuPTR ", ->%" PRIu64 ")" " == %" PRIuPTR "\n", 1446 n_prnt (t->str.str), 1447 (uintptr_t) t->num_of_digt, 1448 (uintptr_t) t->str.len + 1, rv, rs); 1449 } 1450 } 1451 return t_failed; 1452 } 1453 1454 1455 static size_t 1456 check_str_to_uint64_n_all_chars (void) 1457 { 1458 int c_failed[256]; /* from 0 to 255 */ 1459 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 1460 size_t t_failed = 0; 1461 size_t j; 1462 1463 memset (c_failed, 0, sizeof(c_failed)); 1464 1465 for (j = 0; j < locale_name_count; j++) 1466 { 1467 unsigned int c; 1468 uint64_t test_val; 1469 1470 set_test_locale (j); /* setlocale() can be slow! */ 1471 for (c = 0; c < n_checks; c++) 1472 { 1473 static const uint64_t rnd_val = 98372558; 1474 size_t rs; 1475 size_t len; 1476 1477 if ((c >= '0') && (c <= '9') ) 1478 continue; /* skip digits */ 1479 1480 for (len = 0; len <= 5; len++) 1481 { 1482 for (test_val = 0; test_val <= rnd_val && ! c_failed[c]; test_val += 1483 rnd_val) 1484 { 1485 char test_str[] = "0123"; 1486 uint64_t rv = test_val; 1487 1488 test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */ 1489 rs = MHD_str_to_uint64_n_ (test_str, len, &rv); 1490 if (rs != 0) 1491 { 1492 t_failed++; 1493 c_failed[c] = ! 0; 1494 fprintf (stderr, 1495 "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", ->%" 1496 PRIu64 ")" 1497 " returned %" PRIuPTR 1498 ", while expecting zero. Locale: %s\n", 1499 n_prnt (test_str), (uintptr_t) len, rv, (uintptr_t) rs, 1500 get_current_locale_str ()); 1501 } 1502 else if (rv != test_val) 1503 { 1504 t_failed++; 1505 c_failed[c] = ! 0; 1506 fprintf (stderr, 1507 "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR 1508 ", &ret_val)" 1509 " modified value of ret_val (before call: %" PRIu64 1510 ", after call %" PRIu64 ")." 1511 " Locale: %s\n", 1512 n_prnt (test_str), (uintptr_t) len, test_val, rv, 1513 get_current_locale_str ()); 1514 } 1515 } 1516 } 1517 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[c]) 1518 { 1519 char test_str[] = "0123"; 1520 test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */ 1521 1522 printf ("PASSED: MHD_str_to_uint64_n_(\"%s\", 0..5, &ret_val) == 0, " 1523 "value of ret_val is unmodified\n", 1524 n_prnt (test_str)); 1525 } 1526 } 1527 } 1528 return t_failed; 1529 } 1530 1531 1532 static size_t 1533 check_str_to_uint64_n_overflow (void) 1534 { 1535 size_t t_failed = 0; 1536 size_t i, j; 1537 int c_failed[sizeof(str_ovflw) / sizeof(str_ovflw[0])]; 1538 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 1539 1540 memset (c_failed, 0, sizeof(c_failed)); 1541 1542 for (j = 0; j < locale_name_count; j++) 1543 { 1544 set_test_locale (j); /* setlocale() can be slow! */ 1545 for (i = 0; i < n_checks; i++) 1546 { 1547 size_t rs; 1548 const struct str_with_len *const t = str_ovflw + i; 1549 static const uint64_t rnd_val = 3; 1550 size_t len; 1551 1552 for (len = t->len; len <= t->len + 1; len++) 1553 { 1554 uint64_t test_val; 1555 for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val += 1556 rnd_val) 1557 { 1558 uint64_t rv = test_val; 1559 1560 rs = MHD_str_to_uint64_n_ (t->str, len, &rv); 1561 if (rs != 0) 1562 { 1563 t_failed++; 1564 c_failed[i] = ! 0; 1565 fprintf (stderr, 1566 "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", ->%" 1567 PRIu64 ")" 1568 " returned %" PRIuPTR 1569 ", while expecting zero. Locale: %s\n", 1570 n_prnt (t->str), (uintptr_t) len, rv, (uintptr_t) rs, 1571 get_current_locale_str ()); 1572 } 1573 else if (rv != test_val) 1574 { 1575 t_failed++; 1576 c_failed[i] = ! 0; 1577 fprintf (stderr, 1578 "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR 1579 ", &ret_val)" 1580 " modified value of ret_val (before call: %" PRIu64 1581 ", after call %" PRIu64 ")." 1582 " Locale: %s\n", n_prnt (t->str), (uintptr_t) len, 1583 test_val, rv, 1584 get_current_locale_str ()); 1585 } 1586 } 1587 } 1588 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) 1589 printf ("PASSED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR 1590 ", &ret_val) == 0," 1591 " value of ret_val is unmodified\n", n_prnt (t->str), 1592 (uintptr_t) t->len, 1593 (uintptr_t) t->len + 1); 1594 } 1595 } 1596 return t_failed; 1597 } 1598 1599 1600 static size_t 1601 check_str_to_uint64_n_no_val (void) 1602 { 1603 size_t t_failed = 0; 1604 size_t i, j; 1605 int c_failed[sizeof(str_no_num) / sizeof(str_no_num[0])]; 1606 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 1607 1608 memset (c_failed, 0, sizeof(c_failed)); 1609 1610 for (j = 0; j < locale_name_count; j++) 1611 { 1612 set_test_locale (j); /* setlocale() can be slow! */ 1613 for (i = 0; i < n_checks; i++) 1614 { 1615 size_t rs; 1616 const struct str_with_len *const t = str_no_num + i; 1617 static const uint64_t rnd_val = 43255654342; 1618 size_t len; 1619 1620 for (len = 0; len <= t->len + 1; len++) 1621 { 1622 uint64_t test_val; 1623 for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val += 1624 rnd_val) 1625 { 1626 uint64_t rv = test_val; 1627 1628 rs = MHD_str_to_uint64_n_ (t->str, len, &rv); 1629 if (rs != 0) 1630 { 1631 t_failed++; 1632 c_failed[i] = ! 0; 1633 fprintf (stderr, 1634 "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", ->%" 1635 PRIu64 ")" 1636 " returned %" PRIuPTR 1637 ", while expecting zero. Locale: %s\n", 1638 n_prnt (t->str), (uintptr_t) len, rv, (uintptr_t) rs, 1639 get_current_locale_str ()); 1640 } 1641 else if (rv != test_val) 1642 { 1643 t_failed++; 1644 c_failed[i] = ! 0; 1645 fprintf (stderr, 1646 "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR 1647 ", &ret_val)" 1648 " modified value of ret_val (before call: %" PRIu64 1649 ", after call %" PRIu64 ")." 1650 " Locale: %s\n", n_prnt (t->str), (uintptr_t) len, 1651 test_val, rv, 1652 get_current_locale_str ()); 1653 } 1654 } 1655 } 1656 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) 1657 printf ("PASSED: MHD_str_to_uint64_n_(\"%s\", 0..%" PRIuPTR 1658 ", &ret_val) == 0," 1659 " value of ret_val is unmodified\n", n_prnt (t->str), 1660 (uintptr_t) t->len + 1); 1661 } 1662 } 1663 return t_failed; 1664 } 1665 1666 1667 static size_t 1668 check_strx_to_uint32_valid (void) 1669 { 1670 size_t t_failed = 0; 1671 size_t i, j; 1672 int c_failed[sizeof(xdstrs_w_values) 1673 / sizeof(xdstrs_w_values[0])]; 1674 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 1675 1676 memset (c_failed, 0, sizeof(c_failed)); 1677 1678 for (j = 0; j < locale_name_count; j++) 1679 { 1680 set_test_locale (j); /* setlocale() can be slow! */ 1681 for (i = 0; i < n_checks; i++) 1682 { 1683 uint32_t rv; 1684 size_t rs; 1685 const struct str_with_value *const t = xdstrs_w_values + i; 1686 1687 if (t->val > UINT32_MAX) 1688 continue; /* number is too high for this function */ 1689 1690 if (c_failed[i]) 1691 continue; /* skip already failed checks */ 1692 1693 if (t->str.len < t->num_of_digt) 1694 { 1695 fprintf (stderr, 1696 "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" 1697 " to be less or equal to str.len (%u).\n", 1698 (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned 1699 int) t->str. 1700 len); 1701 exit (99); 1702 } 1703 rv = 1458532; /* some random value */ 1704 rs = MHD_strx_to_uint32_ (t->str.str, &rv); 1705 if (rs != t->num_of_digt) 1706 { 1707 t_failed++; 1708 c_failed[i] = ! 0; 1709 fprintf (stderr, 1710 "FAILED: MHD_strx_to_uint32_(\"%s\", ->0x%" PRIX64 1711 ") returned %" 1712 PRIuPTR ", while expecting %d." 1713 " Locale: %s\n", n_prnt (t->str.str), (uint64_t) rv, 1714 (uintptr_t) rs, (int) t->num_of_digt, 1715 get_current_locale_str ()); 1716 } 1717 if (rv != t->val) 1718 { 1719 t_failed++; 1720 c_failed[i] = ! 0; 1721 fprintf (stderr, 1722 "FAILED: MHD_strx_to_uint32_(\"%s\", ->0x%" PRIX64 1723 ") converted string to value 0x%" 1724 PRIX64 "," 1725 " while expecting result 0x%" PRIX64 ". Locale: %s\n", 1726 n_prnt (t->str.str), (uint64_t) rv, (uint64_t) rv, 1727 t->val, get_current_locale_str ()); 1728 } 1729 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) 1730 printf ("PASSED: MHD_strx_to_uint32_(\"%s\", ->0x%" PRIX64 ") == %" 1731 PRIuPTR "\n", 1732 n_prnt (t->str.str), (uint64_t) rv, rs); 1733 } 1734 } 1735 return t_failed; 1736 } 1737 1738 1739 static size_t 1740 check_strx_to_uint32_all_chars (void) 1741 { 1742 int c_failed[256]; /* from 0 to 255 */ 1743 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 1744 size_t t_failed = 0; 1745 size_t j; 1746 1747 memset (c_failed, 0, sizeof(c_failed)); 1748 1749 for (j = 0; j < locale_name_count; j++) 1750 { 1751 unsigned int c; 1752 uint32_t test_val; 1753 1754 set_test_locale (j); /* setlocale() can be slow! */ 1755 for (c = 0; c < n_checks; c++) 1756 { 1757 static const uint32_t rnd_val = 234234; 1758 size_t rs; 1759 if (( (c >= '0') && (c <= '9') ) 1760 || ( (c >= 'A') && (c <= 'F') ) 1761 || ( (c >= 'a') && (c <= 'f') )) 1762 continue; /* skip xdigits */ 1763 for (test_val = 0; test_val <= rnd_val && ! c_failed[c]; test_val += 1764 rnd_val) 1765 { 1766 char test_str[] = "0123"; 1767 uint32_t rv = test_val; 1768 1769 test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */ 1770 rs = MHD_strx_to_uint32_ (test_str, &rv); 1771 if (rs != 0) 1772 { 1773 t_failed++; 1774 c_failed[c] = ! 0; 1775 fprintf (stderr, 1776 "FAILED: MHD_strx_to_uint32_(\"%s\", ->0x%" PRIX64 1777 ") returned %" 1778 PRIuPTR ", while expecting zero." 1779 " Locale: %s\n", n_prnt (test_str), (uint64_t) rv, 1780 (uintptr_t) rs, get_current_locale_str ()); 1781 } 1782 else if (rv != test_val) 1783 { 1784 t_failed++; 1785 c_failed[c] = ! 0; 1786 fprintf (stderr, 1787 "FAILED: MHD_strx_to_uint32_(\"%s\", &ret_val) modified value of ret_val" 1788 " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 1789 "). Locale: %s\n", 1790 n_prnt (test_str), (uint64_t) test_val, (uint64_t) rv, 1791 get_current_locale_str ()); 1792 } 1793 } 1794 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[c]) 1795 { 1796 char test_str[] = "0123"; 1797 test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */ 1798 1799 printf ("PASSED: MHD_strx_to_uint32_(\"%s\", &ret_val) == 0, " 1800 "value of ret_val is unmodified\n", 1801 n_prnt (test_str)); 1802 } 1803 } 1804 } 1805 return t_failed; 1806 } 1807 1808 1809 static size_t 1810 check_strx_to_uint32_overflow (void) 1811 { 1812 size_t t_failed = 0; 1813 size_t i, j; 1814 static const size_t n_checks1 = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]); 1815 int c_failed[(sizeof(strx_ovflw) / sizeof(strx_ovflw[0])) 1816 + (sizeof(xdstrs_w_values) 1817 / sizeof(xdstrs_w_values[0]))]; 1818 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 1819 1820 memset (c_failed, 0, sizeof(c_failed)); 1821 1822 for (j = 0; j < locale_name_count; j++) 1823 { 1824 set_test_locale (j); /* setlocale() can be slow! */ 1825 for (i = 0; i < n_checks; i++) 1826 { 1827 size_t rs; 1828 static const uint32_t rnd_val = 74218431; 1829 uint32_t test_val; 1830 const char *str; 1831 if (i < n_checks1) 1832 { 1833 const struct str_with_len *const t = strx_ovflw + i; 1834 str = t->str; 1835 } 1836 else 1837 { 1838 const struct str_with_value *const t = xdstrs_w_values + (i 1839 - n_checks1); 1840 if (t->val <= UINT32_MAX) 1841 continue; /* check only strings that should overflow uint32_t */ 1842 str = t->str.str; 1843 } 1844 1845 1846 for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val += 1847 rnd_val) 1848 { 1849 uint32_t rv = test_val; 1850 1851 rs = MHD_strx_to_uint32_ (str, &rv); 1852 if (rs != 0) 1853 { 1854 t_failed++; 1855 c_failed[i] = ! 0; 1856 fprintf (stderr, 1857 "FAILED: MHD_strx_to_uint32_(\"%s\", ->0x%" PRIX64 1858 ") returned %" 1859 PRIuPTR ", while expecting zero." 1860 " Locale: %s\n", n_prnt (str), (uint64_t) rv, (uintptr_t) rs, 1861 get_current_locale_str ()); 1862 } 1863 else if (rv != test_val) 1864 { 1865 t_failed++; 1866 c_failed[i] = ! 0; 1867 fprintf (stderr, 1868 "FAILED: MHD_strx_to_uint32_(\"%s\", &ret_val) modified value of ret_val" 1869 " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 1870 "). Locale: %s\n", 1871 n_prnt (str), (uint64_t) test_val, (uint64_t) rv, 1872 get_current_locale_str ()); 1873 } 1874 } 1875 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) 1876 printf ("PASSED: MHD_strx_to_uint32_(\"%s\", &ret_val) == 0, " 1877 "value of ret_val is unmodified\n", 1878 n_prnt (str)); 1879 } 1880 } 1881 return t_failed; 1882 } 1883 1884 1885 static size_t 1886 check_strx_to_uint32_no_val (void) 1887 { 1888 size_t t_failed = 0; 1889 size_t i, j; 1890 int c_failed[sizeof(str_no_num) / sizeof(str_no_num[0])]; 1891 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 1892 1893 memset (c_failed, 0, sizeof(c_failed)); 1894 1895 for (j = 0; j < locale_name_count; j++) 1896 { 1897 set_test_locale (j); /* setlocale() can be slow! */ 1898 for (i = 0; i < n_checks; i++) 1899 { 1900 size_t rs; 1901 const struct str_with_len *const t = str_no_num + i; 1902 static const uint32_t rnd_val = 74218431; 1903 uint32_t test_val; 1904 1905 for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val += 1906 rnd_val) 1907 { 1908 uint32_t rv = test_val; 1909 1910 rs = MHD_strx_to_uint32_ (t->str, &rv); 1911 if (rs != 0) 1912 { 1913 t_failed++; 1914 c_failed[i] = ! 0; 1915 fprintf (stderr, 1916 "FAILED: MHD_strx_to_uint32_(\"%s\", ->0x%" PRIX64 1917 ") returned %" 1918 PRIuPTR ", while expecting zero." 1919 " Locale: %s\n", n_prnt (t->str), (uint64_t) rv, 1920 (uintptr_t) rs, get_current_locale_str ()); 1921 } 1922 else if (rv != test_val) 1923 { 1924 t_failed++; 1925 c_failed[i] = ! 0; 1926 fprintf (stderr, 1927 "FAILED: MHD_strx_to_uint32_(\"%s\", &ret_val) modified value of ret_val" 1928 " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 1929 "). Locale: %s\n", 1930 n_prnt (t->str), (uint64_t) test_val, (uint64_t) rv, 1931 get_current_locale_str ()); 1932 } 1933 } 1934 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) 1935 printf ("PASSED: MHD_strx_to_uint32_(\"%s\", &ret_val) == 0, " 1936 "value of ret_val is unmodified\n", 1937 n_prnt (t->str)); 1938 } 1939 } 1940 return t_failed; 1941 } 1942 1943 1944 static size_t 1945 check_strx_to_uint32_n_valid (void) 1946 { 1947 size_t t_failed = 0; 1948 size_t i, j; 1949 int c_failed[sizeof(xdstrs_w_values) 1950 / sizeof(xdstrs_w_values[0])]; 1951 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 1952 1953 memset (c_failed, 0, sizeof(c_failed)); 1954 1955 for (j = 0; j < locale_name_count; j++) 1956 { 1957 set_test_locale (j); /* setlocale() can be slow! */ 1958 for (i = 0; i < n_checks; i++) 1959 { 1960 uint32_t rv = 2352932; /* some random value */ 1961 size_t rs = 0; 1962 size_t len; 1963 const struct str_with_value *const t = xdstrs_w_values + i; 1964 1965 if (t->val > UINT32_MAX) 1966 continue; /* number is too high for this function */ 1967 1968 if (t->str.len < t->num_of_digt) 1969 { 1970 fprintf (stderr, 1971 "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" 1972 " to be less or equal to str.len (%u).\n", 1973 (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned 1974 int) t->str. 1975 len); 1976 exit (99); 1977 } 1978 for (len = t->num_of_digt; len <= t->str.len + 1 && ! c_failed[i]; len++) 1979 { 1980 rs = MHD_strx_to_uint32_n_ (t->str.str, len, &rv); 1981 if (rs != t->num_of_digt) 1982 { 1983 t_failed++; 1984 c_failed[i] = ! 0; 1985 fprintf (stderr, 1986 "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", ->0x%" 1987 PRIX64 ")" 1988 " returned %" PRIuPTR ", while expecting %d. Locale: %s\n", 1989 n_prnt (t->str.str), (uintptr_t) len, (uint64_t) rv, 1990 (uintptr_t) rs, 1991 (int) t->num_of_digt, get_current_locale_str ()); 1992 } 1993 if (rv != t->val) 1994 { 1995 t_failed++; 1996 c_failed[i] = ! 0; 1997 fprintf (stderr, 1998 "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", ->0x%" 1999 PRIX64 ")" 2000 " converted string to value 0x%" PRIX64 2001 ", while expecting result 0x%" PRIX64 2002 ". Locale: %s\n", n_prnt (t->str.str), (uintptr_t) len, 2003 (uint64_t) rv, (uint64_t) rv, 2004 t->val, get_current_locale_str ()); 2005 } 2006 } 2007 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) 2008 printf ( 2009 "PASSED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR 2010 ", ->0x%" 2011 PRIX64 ")" 2012 " == %" PRIuPTR "\n", n_prnt (t->str.str), 2013 (uintptr_t) t->num_of_digt, 2014 (uintptr_t) t->str.len + 1, (uint64_t) rv, rs); 2015 } 2016 } 2017 return t_failed; 2018 } 2019 2020 2021 static size_t 2022 check_strx_to_uint32_n_all_chars (void) 2023 { 2024 int c_failed[256]; /* from 0 to 255 */ 2025 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 2026 size_t t_failed = 0; 2027 size_t j; 2028 2029 memset (c_failed, 0, sizeof(c_failed)); 2030 2031 for (j = 0; j < locale_name_count; j++) 2032 { 2033 unsigned int c; 2034 uint32_t test_val; 2035 2036 set_test_locale (j); /* setlocale() can be slow! */ 2037 for (c = 0; c < n_checks; c++) 2038 { 2039 static const uint32_t rnd_val = 98372558; 2040 size_t rs; 2041 size_t len; 2042 2043 if (( (c >= '0') && (c <= '9') ) 2044 || ( (c >= 'A') && (c <= 'F') ) 2045 || ( (c >= 'a') && (c <= 'f') )) 2046 continue; /* skip xdigits */ 2047 2048 for (len = 0; len <= 5; len++) 2049 { 2050 for (test_val = 0; test_val <= rnd_val && ! c_failed[c]; test_val += 2051 rnd_val) 2052 { 2053 char test_str[] = "0123"; 2054 uint32_t rv = test_val; 2055 2056 test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */ 2057 rs = MHD_strx_to_uint32_n_ (test_str, len, &rv); 2058 if (rs != 0) 2059 { 2060 t_failed++; 2061 c_failed[c] = ! 0; 2062 fprintf (stderr, 2063 "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", ->0x%" 2064 PRIX64 2065 ")" 2066 " returned %" PRIuPTR 2067 ", while expecting zero. Locale: %s\n", 2068 n_prnt (test_str), (uintptr_t) len, (uint64_t) rv, 2069 (uintptr_t) rs, get_current_locale_str ()); 2070 } 2071 else if (rv != test_val) 2072 { 2073 t_failed++; 2074 c_failed[c] = ! 0; 2075 fprintf (stderr, 2076 "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR 2077 ", &ret_val)" 2078 " modified value of ret_val (before call: 0x%" PRIX64 2079 ", after call 0x%" PRIX64 ")." 2080 " Locale: %s\n", 2081 n_prnt (test_str), (uintptr_t) len, (uint64_t) test_val, 2082 (uint64_t) rv, get_current_locale_str ()); 2083 } 2084 } 2085 } 2086 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[c]) 2087 { 2088 char test_str[] = "0123"; 2089 test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */ 2090 2091 printf ("PASSED: MHD_strx_to_uint32_n_(\"%s\", 0..5, &ret_val) == 0, " 2092 "value of ret_val is unmodified\n", 2093 n_prnt (test_str)); 2094 } 2095 } 2096 } 2097 return t_failed; 2098 } 2099 2100 2101 static size_t 2102 check_strx_to_uint32_n_overflow (void) 2103 { 2104 size_t t_failed = 0; 2105 size_t i, j; 2106 static const size_t n_checks1 = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]); 2107 int c_failed[(sizeof(strx_ovflw) / sizeof(strx_ovflw[0])) 2108 + (sizeof(xdstrs_w_values) 2109 / sizeof(xdstrs_w_values[0]))]; 2110 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 2111 2112 memset (c_failed, 0, sizeof(c_failed)); 2113 2114 for (j = 0; j < locale_name_count; j++) 2115 { 2116 set_test_locale (j); /* setlocale() can be slow! */ 2117 for (i = 0; i < n_checks; i++) 2118 { 2119 size_t rs; 2120 static const uint32_t rnd_val = 4; 2121 size_t len; 2122 const char *str; 2123 size_t min_len, max_len; 2124 if (i < n_checks1) 2125 { 2126 const struct str_with_len *const t = strx_ovflw + i; 2127 str = t->str; 2128 min_len = t->len; 2129 max_len = t->len + 1; 2130 } 2131 else 2132 { 2133 const struct str_with_value *const t = xdstrs_w_values + (i 2134 - n_checks1); 2135 if (t->val <= UINT32_MAX) 2136 continue; /* check only strings that should overflow uint32_t */ 2137 2138 if (t->str.len < t->num_of_digt) 2139 { 2140 fprintf (stderr, 2141 "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" 2142 " to be less or equal to str.len (%u).\n", 2143 (unsigned int) (i - n_checks1), (unsigned 2144 int) t->num_of_digt, 2145 (unsigned int) t->str.len); 2146 exit (99); 2147 } 2148 str = t->str.str; 2149 min_len = t->num_of_digt; 2150 max_len = t->str.len + 1; 2151 } 2152 2153 for (len = min_len; len <= max_len; len++) 2154 { 2155 uint32_t test_val; 2156 for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val += 2157 rnd_val) 2158 { 2159 uint32_t rv = test_val; 2160 2161 rs = MHD_strx_to_uint32_n_ (str, len, &rv); 2162 if (rs != 0) 2163 { 2164 t_failed++; 2165 c_failed[i] = ! 0; 2166 fprintf (stderr, 2167 "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", ->0x%" 2168 PRIX64 2169 ")" 2170 " returned %" PRIuPTR 2171 ", while expecting zero. Locale: %s\n", 2172 n_prnt (str), (uintptr_t) len, (uint64_t) rv, 2173 (uintptr_t) rs, get_current_locale_str ()); 2174 } 2175 else if (rv != test_val) 2176 { 2177 t_failed++; 2178 c_failed[i] = ! 0; 2179 fprintf (stderr, 2180 "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR 2181 ", &ret_val)" 2182 " modified value of ret_val (before call: 0x%" PRIX64 2183 ", after call 0x%" PRIX64 ")." 2184 " Locale: %s\n", n_prnt (str), (uintptr_t) len, 2185 (uint64_t) test_val, (uint64_t) rv, 2186 get_current_locale_str ()); 2187 } 2188 } 2189 } 2190 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) 2191 printf ("PASSED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR 2192 ", &ret_val) == 0," 2193 " value of ret_val is unmodified\n", n_prnt (str), 2194 (uintptr_t) min_len, 2195 (uintptr_t) max_len); 2196 } 2197 } 2198 return t_failed; 2199 } 2200 2201 2202 static size_t 2203 check_strx_to_uint32_n_no_val (void) 2204 { 2205 size_t t_failed = 0; 2206 size_t i, j; 2207 int c_failed[sizeof(str_no_num) / sizeof(str_no_num[0])]; 2208 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 2209 2210 memset (c_failed, 0, sizeof(c_failed)); 2211 2212 for (j = 0; j < locale_name_count; j++) 2213 { 2214 set_test_locale (j); /* setlocale() can be slow! */ 2215 for (i = 0; i < n_checks; i++) 2216 { 2217 size_t rs; 2218 const struct str_with_len *const t = str_no_num + i; 2219 static const uint32_t rnd_val = 3214314212UL; 2220 size_t len; 2221 2222 for (len = 0; len <= t->len + 1; len++) 2223 { 2224 uint32_t test_val; 2225 for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val += 2226 rnd_val) 2227 { 2228 uint32_t rv = test_val; 2229 2230 rs = MHD_strx_to_uint32_n_ (t->str, len, &rv); 2231 if (rs != 0) 2232 { 2233 t_failed++; 2234 c_failed[i] = ! 0; 2235 fprintf (stderr, 2236 "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", ->0x%" 2237 PRIX64 2238 ")" 2239 " returned %" PRIuPTR 2240 ", while expecting zero. Locale: %s\n", 2241 n_prnt (t->str), (uintptr_t) len, (uint64_t) rv, 2242 (uintptr_t) rs, get_current_locale_str ()); 2243 } 2244 else if (rv != test_val) 2245 { 2246 t_failed++; 2247 c_failed[i] = ! 0; 2248 fprintf (stderr, 2249 "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR 2250 ", &ret_val)" 2251 " modified value of ret_val (before call: 0x%" PRIX64 2252 ", after call 0x%" PRIX64 ")." 2253 " Locale: %s\n", n_prnt (t->str), (uintptr_t) len, 2254 (uint64_t) test_val, (uint64_t) rv, 2255 get_current_locale_str ()); 2256 } 2257 } 2258 } 2259 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) 2260 printf ("PASSED: MHD_strx_to_uint32_n_(\"%s\", 0..%" PRIuPTR 2261 ", &ret_val) == 0," 2262 " value of ret_val is unmodified\n", n_prnt (t->str), 2263 (uintptr_t) t->len + 1); 2264 } 2265 } 2266 return t_failed; 2267 } 2268 2269 2270 static size_t 2271 check_strx_to_uint64_valid (void) 2272 { 2273 size_t t_failed = 0; 2274 size_t i, j; 2275 int c_failed[sizeof(xdstrs_w_values) 2276 / sizeof(xdstrs_w_values[0])]; 2277 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 2278 2279 memset (c_failed, 0, sizeof(c_failed)); 2280 2281 for (j = 0; j < locale_name_count; j++) 2282 { 2283 set_test_locale (j); /* setlocale() can be slow! */ 2284 for (i = 0; i < n_checks; i++) 2285 { 2286 uint64_t rv; 2287 size_t rs; 2288 const struct str_with_value *const t = xdstrs_w_values + i; 2289 2290 if (c_failed[i]) 2291 continue; /* skip already failed checks */ 2292 2293 if (t->str.len < t->num_of_digt) 2294 { 2295 fprintf (stderr, 2296 "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" 2297 " to be less or equal to str.len (%u).\n", 2298 (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned 2299 int) t->str. 2300 len); 2301 exit (99); 2302 } 2303 rv = 1458532; /* some random value */ 2304 rs = MHD_strx_to_uint64_ (t->str.str, &rv); 2305 if (rs != t->num_of_digt) 2306 { 2307 t_failed++; 2308 c_failed[i] = ! 0; 2309 fprintf (stderr, 2310 "FAILED: MHD_strx_to_uint64_(\"%s\", ->0x%" PRIX64 2311 ") returned %" 2312 PRIuPTR ", while expecting %d." 2313 " Locale: %s\n", n_prnt (t->str.str), rv, (uintptr_t) rs, 2314 (int) t->num_of_digt, get_current_locale_str ()); 2315 } 2316 if (rv != t->val) 2317 { 2318 t_failed++; 2319 c_failed[i] = ! 0; 2320 fprintf (stderr, 2321 "FAILED: MHD_strx_to_uint64_(\"%s\", ->0x%" PRIX64 2322 ") converted string to value 0x%" 2323 PRIX64 "," 2324 " while expecting result 0x%" PRIX64 ". Locale: %s\n", 2325 n_prnt (t->str.str), rv, rv, 2326 t->val, get_current_locale_str ()); 2327 } 2328 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) 2329 printf ("PASSED: MHD_strx_to_uint64_(\"%s\", ->0x%" PRIX64 ") == %" 2330 PRIuPTR "\n", 2331 n_prnt (t->str.str), rv, rs); 2332 } 2333 } 2334 return t_failed; 2335 } 2336 2337 2338 static size_t 2339 check_strx_to_uint64_all_chars (void) 2340 { 2341 int c_failed[256]; /* from 0 to 255 */ 2342 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 2343 size_t t_failed = 0; 2344 size_t j; 2345 2346 memset (c_failed, 0, sizeof(c_failed)); 2347 2348 for (j = 0; j < locale_name_count; j++) 2349 { 2350 unsigned int c; 2351 uint64_t test_val; 2352 2353 set_test_locale (j); /* setlocale() can be slow! */ 2354 for (c = 0; c < n_checks; c++) 2355 { 2356 static const uint64_t rnd_val = 234234; 2357 size_t rs; 2358 if (( (c >= '0') && (c <= '9') ) 2359 || ( (c >= 'A') && (c <= 'F') ) 2360 || ( (c >= 'a') && (c <= 'f') )) 2361 continue; /* skip xdigits */ 2362 for (test_val = 0; test_val <= rnd_val && ! c_failed[c]; test_val += 2363 rnd_val) 2364 { 2365 char test_str[] = "0123"; 2366 uint64_t rv = test_val; 2367 2368 test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */ 2369 rs = MHD_strx_to_uint64_ (test_str, &rv); 2370 if (rs != 0) 2371 { 2372 t_failed++; 2373 c_failed[c] = ! 0; 2374 fprintf (stderr, 2375 "FAILED: MHD_strx_to_uint64_(\"%s\", ->0x%" PRIX64 2376 ") returned %" 2377 PRIuPTR ", while expecting zero." 2378 " Locale: %s\n", n_prnt (test_str), rv, (uintptr_t) rs, 2379 get_current_locale_str ()); 2380 } 2381 else if (rv != test_val) 2382 { 2383 t_failed++; 2384 c_failed[c] = ! 0; 2385 fprintf (stderr, 2386 "FAILED: MHD_strx_to_uint64_(\"%s\", &ret_val) modified value of ret_val" 2387 " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 2388 "). Locale: %s\n", 2389 n_prnt (test_str), test_val, rv, get_current_locale_str ()); 2390 } 2391 } 2392 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[c]) 2393 { 2394 char test_str[] = "0123"; 2395 test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */ 2396 2397 printf ("PASSED: MHD_strx_to_uint64_(\"%s\", &ret_val) == 0, " 2398 "value of ret_val is unmodified\n", 2399 n_prnt (test_str)); 2400 } 2401 } 2402 } 2403 return t_failed; 2404 } 2405 2406 2407 static size_t 2408 check_strx_to_uint64_overflow (void) 2409 { 2410 size_t t_failed = 0; 2411 size_t i, j; 2412 int c_failed[sizeof(strx_ovflw) / sizeof(strx_ovflw[0])]; 2413 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 2414 2415 memset (c_failed, 0, sizeof(c_failed)); 2416 2417 for (j = 0; j < locale_name_count; j++) 2418 { 2419 set_test_locale (j); /* setlocale() can be slow! */ 2420 for (i = 0; i < n_checks; i++) 2421 { 2422 size_t rs; 2423 const struct str_with_len *const t = strx_ovflw + i; 2424 static const uint64_t rnd_val = 74218431; 2425 uint64_t test_val; 2426 2427 for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val += 2428 rnd_val) 2429 { 2430 uint64_t rv = test_val; 2431 2432 rs = MHD_strx_to_uint64_ (t->str, &rv); 2433 if (rs != 0) 2434 { 2435 t_failed++; 2436 c_failed[i] = ! 0; 2437 fprintf (stderr, 2438 "FAILED: MHD_strx_to_uint64_(\"%s\", ->0x%" PRIX64 2439 ") returned %" 2440 PRIuPTR ", while expecting zero." 2441 " Locale: %s\n", n_prnt (t->str), rv, (uintptr_t) rs, 2442 get_current_locale_str ()); 2443 } 2444 else if (rv != test_val) 2445 { 2446 t_failed++; 2447 c_failed[i] = ! 0; 2448 fprintf (stderr, 2449 "FAILED: MHD_strx_to_uint64_(\"%s\", &ret_val) modified value of ret_val" 2450 " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 2451 "). Locale: %s\n", 2452 n_prnt (t->str), test_val, rv, get_current_locale_str ()); 2453 } 2454 } 2455 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) 2456 printf ("PASSED: MHD_strx_to_uint64_(\"%s\", &ret_val) == 0, " 2457 "value of ret_val is unmodified\n", 2458 n_prnt (t->str)); 2459 } 2460 } 2461 return t_failed; 2462 } 2463 2464 2465 static size_t 2466 check_strx_to_uint64_no_val (void) 2467 { 2468 size_t t_failed = 0; 2469 size_t i, j; 2470 int c_failed[sizeof(str_no_num) / sizeof(str_no_num[0])]; 2471 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 2472 2473 memset (c_failed, 0, sizeof(c_failed)); 2474 2475 for (j = 0; j < locale_name_count; j++) 2476 { 2477 set_test_locale (j); /* setlocale() can be slow! */ 2478 for (i = 0; i < n_checks; i++) 2479 { 2480 size_t rs; 2481 const struct str_with_len *const t = str_no_num + i; 2482 static const uint64_t rnd_val = 74218431; 2483 uint64_t test_val; 2484 2485 for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val += 2486 rnd_val) 2487 { 2488 uint64_t rv = test_val; 2489 2490 rs = MHD_strx_to_uint64_ (t->str, &rv); 2491 if (rs != 0) 2492 { 2493 t_failed++; 2494 c_failed[i] = ! 0; 2495 fprintf (stderr, 2496 "FAILED: MHD_strx_to_uint64_(\"%s\", ->0x%" PRIX64 2497 ") returned %" 2498 PRIuPTR ", while expecting zero." 2499 " Locale: %s\n", n_prnt (t->str), rv, (uintptr_t) rs, 2500 get_current_locale_str ()); 2501 } 2502 else if (rv != test_val) 2503 { 2504 t_failed++; 2505 c_failed[i] = ! 0; 2506 fprintf (stderr, 2507 "FAILED: MHD_strx_to_uint64_(\"%s\", &ret_val) modified value of ret_val" 2508 " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 2509 "). Locale: %s\n", 2510 n_prnt (t->str), test_val, rv, get_current_locale_str ()); 2511 } 2512 } 2513 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) 2514 printf ("PASSED: MHD_strx_to_uint64_(\"%s\", &ret_val) == 0, " 2515 "value of ret_val is unmodified\n", 2516 n_prnt (t->str)); 2517 } 2518 } 2519 return t_failed; 2520 } 2521 2522 2523 static size_t 2524 check_strx_to_uint64_n_valid (void) 2525 { 2526 size_t t_failed = 0; 2527 size_t i, j; 2528 int c_failed[sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0])]; 2529 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 2530 2531 memset (c_failed, 0, sizeof(c_failed)); 2532 2533 for (j = 0; j < locale_name_count; j++) 2534 { 2535 set_test_locale (j); /* setlocale() can be slow! */ 2536 for (i = 0; i < n_checks; i++) 2537 { 2538 uint64_t rv = 2352932; /* some random value */ 2539 size_t rs = 0; 2540 size_t len; 2541 const struct str_with_value *const t = xdstrs_w_values + i; 2542 2543 if (t->str.len < t->num_of_digt) 2544 { 2545 fprintf (stderr, 2546 "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" 2547 " to be less or equal to str.len (%u).\n", 2548 (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned 2549 int) t->str. 2550 len); 2551 exit (99); 2552 } 2553 for (len = t->num_of_digt; len <= t->str.len + 1 && ! c_failed[i]; len++) 2554 { 2555 rs = MHD_strx_to_uint64_n_ (t->str.str, len, &rv); 2556 if (rs != t->num_of_digt) 2557 { 2558 t_failed++; 2559 c_failed[i] = ! 0; 2560 fprintf (stderr, 2561 "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", ->0x%" 2562 PRIX64 ")" 2563 " returned %" PRIuPTR ", while expecting %d. Locale: %s\n", 2564 n_prnt (t->str.str), (uintptr_t) len, rv, (uintptr_t) rs, 2565 (int) t->num_of_digt, get_current_locale_str ()); 2566 } 2567 if (rv != t->val) 2568 { 2569 t_failed++; 2570 c_failed[i] = ! 0; 2571 fprintf (stderr, 2572 "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", ->0x%" 2573 PRIX64 ")" 2574 " converted string to value 0x%" PRIX64 2575 ", while expecting result 0x%" PRIX64 2576 ". Locale: %s\n", n_prnt (t->str.str), (uintptr_t) len, rv, 2577 rv, 2578 t->val, get_current_locale_str ()); 2579 } 2580 } 2581 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) 2582 printf ("PASSED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR 2583 ", ->0x%" 2584 PRIX64 ")" 2585 " == %" PRIuPTR "\n", n_prnt (t->str.str), 2586 (uintptr_t) t->num_of_digt, 2587 (uintptr_t) t->str.len + 1, rv, rs); 2588 } 2589 } 2590 return t_failed; 2591 } 2592 2593 2594 static size_t 2595 check_strx_to_uint64_n_all_chars (void) 2596 { 2597 int c_failed[256]; /* from 0 to 255 */ 2598 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 2599 size_t t_failed = 0; 2600 size_t j; 2601 2602 memset (c_failed, 0, sizeof(c_failed)); 2603 2604 for (j = 0; j < locale_name_count; j++) 2605 { 2606 unsigned int c; 2607 uint64_t test_val; 2608 2609 set_test_locale (j); /* setlocale() can be slow! */ 2610 for (c = 0; c < n_checks; c++) 2611 { 2612 static const uint64_t rnd_val = 98372558; 2613 size_t rs; 2614 size_t len; 2615 2616 if (( (c >= '0') && (c <= '9') ) 2617 || ( (c >= 'A') && (c <= 'F') ) 2618 || ( (c >= 'a') && (c <= 'f') )) 2619 continue; /* skip xdigits */ 2620 2621 for (len = 0; len <= 5; len++) 2622 { 2623 for (test_val = 0; test_val <= rnd_val && ! c_failed[c]; test_val += 2624 rnd_val) 2625 { 2626 char test_str[] = "0123"; 2627 uint64_t rv = test_val; 2628 2629 test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */ 2630 rs = MHD_strx_to_uint64_n_ (test_str, len, &rv); 2631 if (rs != 0) 2632 { 2633 t_failed++; 2634 c_failed[c] = ! 0; 2635 fprintf (stderr, 2636 "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", ->0x%" 2637 PRIX64 2638 ")" 2639 " returned %" PRIuPTR 2640 ", while expecting zero. Locale: %s\n", 2641 n_prnt (test_str), (uintptr_t) len, rv, (uintptr_t) rs, 2642 get_current_locale_str ()); 2643 } 2644 else if (rv != test_val) 2645 { 2646 t_failed++; 2647 c_failed[c] = ! 0; 2648 fprintf (stderr, 2649 "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR 2650 ", &ret_val)" 2651 " modified value of ret_val (before call: 0x%" PRIX64 2652 ", after call 0x%" PRIX64 ")." 2653 " Locale: %s\n", 2654 n_prnt (test_str), (uintptr_t) len, test_val, rv, 2655 get_current_locale_str ()); 2656 } 2657 } 2658 } 2659 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[c]) 2660 { 2661 char test_str[] = "0123"; 2662 test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */ 2663 2664 printf ("PASSED: MHD_strx_to_uint64_n_(\"%s\", 0..5, &ret_val) == 0, " 2665 "value of ret_val is unmodified\n", 2666 n_prnt (test_str)); 2667 } 2668 } 2669 } 2670 return t_failed; 2671 } 2672 2673 2674 static size_t 2675 check_strx_to_uint64_n_overflow (void) 2676 { 2677 size_t t_failed = 0; 2678 size_t i, j; 2679 int c_failed[sizeof(strx_ovflw) / sizeof(strx_ovflw[0])]; 2680 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 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 = strx_ovflw + i; 2691 static const uint64_t rnd_val = 4; 2692 size_t len; 2693 2694 for (len = t->len; len <= t->len + 1; len++) 2695 { 2696 uint64_t test_val; 2697 for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val += 2698 rnd_val) 2699 { 2700 uint64_t rv = test_val; 2701 2702 rs = MHD_strx_to_uint64_n_ (t->str, len, &rv); 2703 if (rs != 0) 2704 { 2705 t_failed++; 2706 c_failed[i] = ! 0; 2707 fprintf (stderr, 2708 "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", ->0x%" 2709 PRIX64 2710 ")" 2711 " returned %" PRIuPTR 2712 ", while expecting zero. Locale: %s\n", 2713 n_prnt (t->str), (uintptr_t) len, rv, (uintptr_t) rs, 2714 get_current_locale_str ()); 2715 } 2716 else if (rv != test_val) 2717 { 2718 t_failed++; 2719 c_failed[i] = ! 0; 2720 fprintf (stderr, 2721 "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR 2722 ", &ret_val)" 2723 " modified value of ret_val (before call: 0x%" PRIX64 2724 ", after call 0x%" PRIX64 ")." 2725 " Locale: %s\n", n_prnt (t->str), (uintptr_t) len, 2726 test_val, rv, 2727 get_current_locale_str ()); 2728 } 2729 } 2730 } 2731 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) 2732 printf ("PASSED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR 2733 ", &ret_val) == 0," 2734 " value of ret_val is unmodified\n", n_prnt (t->str), 2735 (uintptr_t) t->len, 2736 (uintptr_t) t->len + 1); 2737 } 2738 } 2739 return t_failed; 2740 } 2741 2742 2743 static size_t 2744 check_strx_to_uint64_n_no_val (void) 2745 { 2746 size_t t_failed = 0; 2747 size_t i, j; 2748 int c_failed[sizeof(str_no_num) / sizeof(str_no_num[0])]; 2749 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 2750 2751 memset (c_failed, 0, sizeof(c_failed)); 2752 2753 for (j = 0; j < locale_name_count; j++) 2754 { 2755 set_test_locale (j); /* setlocale() can be slow! */ 2756 for (i = 0; i < n_checks; i++) 2757 { 2758 size_t rs; 2759 const struct str_with_len *const t = str_no_num + i; 2760 static const uint64_t rnd_val = 3214314212UL; 2761 size_t len; 2762 2763 for (len = 0; len <= t->len + 1; len++) 2764 { 2765 uint64_t test_val; 2766 for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val += 2767 rnd_val) 2768 { 2769 uint64_t rv = test_val; 2770 2771 rs = MHD_strx_to_uint64_n_ (t->str, len, &rv); 2772 if (rs != 0) 2773 { 2774 t_failed++; 2775 c_failed[i] = ! 0; 2776 fprintf (stderr, 2777 "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", ->0x%" 2778 PRIX64 2779 ")" 2780 " returned %" PRIuPTR 2781 ", while expecting zero. Locale: %s\n", 2782 n_prnt (t->str), (uintptr_t) len, rv, (uintptr_t) rs, 2783 get_current_locale_str ()); 2784 } 2785 else if (rv != test_val) 2786 { 2787 t_failed++; 2788 c_failed[i] = ! 0; 2789 fprintf (stderr, 2790 "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR 2791 ", &ret_val)" 2792 " modified value of ret_val (before call: 0x%" PRIX64 2793 ", after call 0x%" PRIX64 ")." 2794 " Locale: %s\n", n_prnt (t->str), (uintptr_t) len, 2795 test_val, rv, 2796 get_current_locale_str ()); 2797 } 2798 } 2799 } 2800 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) 2801 printf ("PASSED: MHD_strx_to_uint64_n_(\"%s\", 0..%" PRIuPTR 2802 ", &ret_val) == 0," 2803 " value of ret_val is unmodified\n", n_prnt (t->str), 2804 (uintptr_t) t->len + 1); 2805 } 2806 } 2807 return t_failed; 2808 } 2809 2810 2811 static int 2812 run_str_to_X_tests (void) 2813 { 2814 size_t str_to_uint64_fails = 0; 2815 size_t str_to_uint64_n_fails = 0; 2816 size_t strx_to_uint32_fails = 0; 2817 size_t strx_to_uint32_n_fails = 0; 2818 size_t strx_to_uint64_fails = 0; 2819 size_t strx_to_uint64_n_fails = 0; 2820 size_t res; 2821 2822 res = check_str_to_uint64_valid (); 2823 if (res != 0) 2824 { 2825 str_to_uint64_fails += res; 2826 fprintf (stderr, 2827 "FAILED: testcase check_str_to_uint64_valid() failed.\n\n"); 2828 } 2829 else if (verbose > 1) 2830 printf ( 2831 "PASSED: testcase check_str_to_uint64_valid() successfully passed.\n\n"); 2832 2833 res = check_str_to_uint64_all_chars (); 2834 if (res != 0) 2835 { 2836 str_to_uint64_fails += res; 2837 fprintf (stderr, 2838 "FAILED: testcase check_str_to_uint64_all_chars() failed.\n\n"); 2839 } 2840 else if (verbose > 1) 2841 printf ("PASSED: testcase check_str_to_uint64_all_chars() " 2842 "successfully passed.\n\n"); 2843 2844 res = check_str_to_uint64_overflow (); 2845 if (res != 0) 2846 { 2847 str_to_uint64_fails += res; 2848 fprintf (stderr, 2849 "FAILED: testcase check_str_to_uint64_overflow() failed.\n\n"); 2850 } 2851 else if (verbose > 1) 2852 printf ("PASSED: testcase check_str_to_uint64_overflow() " 2853 "successfully passed.\n\n"); 2854 2855 res = check_str_to_uint64_no_val (); 2856 if (res != 0) 2857 { 2858 str_to_uint64_fails += res; 2859 fprintf (stderr, 2860 "FAILED: testcase check_str_to_uint64_no_val() failed.\n\n"); 2861 } 2862 else if (verbose > 1) 2863 printf ("PASSED: testcase check_str_to_uint64_no_val() " 2864 "successfully passed.\n\n"); 2865 2866 if (str_to_uint64_fails) 2867 fprintf (stderr, 2868 "FAILED: function MHD_str_to_uint64_() failed %lu time%s.\n\n", 2869 (unsigned long) str_to_uint64_fails, 2870 str_to_uint64_fails == 1 ? "" : "s"); 2871 else if (verbose > 0) 2872 printf ("PASSED: function MHD_str_to_uint64_() successfully " 2873 "passed all checks.\n\n"); 2874 2875 res = check_str_to_uint64_n_valid (); 2876 if (res != 0) 2877 { 2878 str_to_uint64_n_fails += res; 2879 fprintf (stderr, 2880 "FAILED: testcase check_str_to_uint64_n_valid() failed.\n\n"); 2881 } 2882 else if (verbose > 1) 2883 printf ("PASSED: testcase check_str_to_uint64_n_valid() " 2884 "successfully passed.\n\n"); 2885 2886 res = check_str_to_uint64_n_all_chars (); 2887 if (res != 0) 2888 { 2889 str_to_uint64_n_fails += res; 2890 fprintf (stderr, 2891 "FAILED: testcase check_str_to_uint64_n_all_chars() failed.\n\n"); 2892 } 2893 else if (verbose > 1) 2894 printf ("PASSED: testcase check_str_to_uint64_n_all_chars() " 2895 "successfully passed.\n\n"); 2896 2897 res = check_str_to_uint64_n_overflow (); 2898 if (res != 0) 2899 { 2900 str_to_uint64_n_fails += res; 2901 fprintf (stderr, 2902 "FAILED: testcase check_str_to_uint64_n_overflow() failed.\n\n"); 2903 } 2904 else if (verbose > 1) 2905 printf ("PASSED: testcase check_str_to_uint64_n_overflow() " 2906 "successfully passed.\n\n"); 2907 2908 res = check_str_to_uint64_n_no_val (); 2909 if (res != 0) 2910 { 2911 str_to_uint64_n_fails += res; 2912 fprintf (stderr, 2913 "FAILED: testcase check_str_to_uint64_n_no_val() failed.\n\n"); 2914 } 2915 else if (verbose > 1) 2916 printf ("PASSED: testcase check_str_to_uint64_n_no_val() " 2917 "successfully passed.\n\n"); 2918 2919 if (str_to_uint64_n_fails) 2920 fprintf (stderr, 2921 "FAILED: function MHD_str_to_uint64_n_() failed %lu time%s.\n\n", 2922 (unsigned long) str_to_uint64_n_fails, 2923 str_to_uint64_n_fails == 1 ? "" : "s"); 2924 else if (verbose > 0) 2925 printf ("PASSED: function MHD_str_to_uint64_n_() successfully " 2926 "passed all checks.\n\n"); 2927 2928 res = check_strx_to_uint32_valid (); 2929 if (res != 0) 2930 { 2931 strx_to_uint32_fails += res; 2932 fprintf (stderr, 2933 "FAILED: testcase check_strx_to_uint32_valid() failed.\n\n"); 2934 } 2935 else if (verbose > 1) 2936 printf ("PASSED: testcase check_strx_to_uint32_valid() " 2937 "successfully passed.\n\n"); 2938 2939 res = check_strx_to_uint32_all_chars (); 2940 if (res != 0) 2941 { 2942 strx_to_uint32_fails += res; 2943 fprintf (stderr, 2944 "FAILED: testcase check_strx_to_uint32_all_chars() failed.\n\n"); 2945 } 2946 else if (verbose > 1) 2947 printf ("PASSED: testcase check_strx_to_uint32_all_chars() " 2948 "successfully passed.\n\n"); 2949 2950 res = check_strx_to_uint32_overflow (); 2951 if (res != 0) 2952 { 2953 strx_to_uint32_fails += res; 2954 fprintf (stderr, 2955 "FAILED: testcase check_strx_to_uint32_overflow() failed.\n\n"); 2956 } 2957 else if (verbose > 1) 2958 printf ("PASSED: testcase check_strx_to_uint32_overflow() " 2959 "successfully passed.\n\n"); 2960 2961 res = check_strx_to_uint32_no_val (); 2962 if (res != 0) 2963 { 2964 strx_to_uint32_fails += res; 2965 fprintf (stderr, 2966 "FAILED: testcase check_strx_to_uint32_no_val() failed.\n\n"); 2967 } 2968 else if (verbose > 1) 2969 printf ("PASSED: testcase check_strx_to_uint32_no_val() " 2970 "successfully passed.\n\n"); 2971 2972 if (strx_to_uint32_fails) 2973 fprintf (stderr, 2974 "FAILED: function MHD_strx_to_uint32_() failed %lu time%s.\n\n", 2975 (unsigned long) strx_to_uint32_fails, 2976 strx_to_uint32_fails == 1 ? "" : "s"); 2977 else if (verbose > 0) 2978 printf ("PASSED: function MHD_strx_to_uint32_() successfully " 2979 "passed all checks.\n\n"); 2980 2981 res = check_strx_to_uint32_n_valid (); 2982 if (res != 0) 2983 { 2984 strx_to_uint32_n_fails += res; 2985 fprintf (stderr, 2986 "FAILED: testcase check_strx_to_uint32_n_valid() failed.\n\n"); 2987 } 2988 else if (verbose > 1) 2989 printf ("PASSED: testcase check_strx_to_uint32_n_valid() " 2990 "successfully passed.\n\n"); 2991 2992 res = check_strx_to_uint32_n_all_chars (); 2993 if (res != 0) 2994 { 2995 strx_to_uint32_n_fails += res; 2996 fprintf (stderr, 2997 "FAILED: testcase check_strx_to_uint32_n_all_chars() failed.\n\n"); 2998 } 2999 else if (verbose > 1) 3000 printf ("PASSED: testcase check_strx_to_uint32_n_all_chars() " 3001 "successfully passed.\n\n"); 3002 3003 res = check_strx_to_uint32_n_overflow (); 3004 if (res != 0) 3005 { 3006 strx_to_uint32_n_fails += res; 3007 fprintf (stderr, 3008 "FAILED: testcase check_strx_to_uint32_n_overflow() failed.\n\n"); 3009 } 3010 else if (verbose > 1) 3011 printf ("PASSED: testcase check_strx_to_uint32_n_overflow() " 3012 "successfully passed.\n\n"); 3013 3014 res = check_strx_to_uint32_n_no_val (); 3015 if (res != 0) 3016 { 3017 strx_to_uint32_n_fails += res; 3018 fprintf (stderr, 3019 "FAILED: testcase check_strx_to_uint32_n_no_val() failed.\n\n"); 3020 } 3021 else if (verbose > 1) 3022 printf ("PASSED: testcase check_strx_to_uint32_n_no_val() " 3023 "successfully passed.\n\n"); 3024 3025 if (strx_to_uint32_n_fails) 3026 fprintf (stderr, 3027 "FAILED: function MHD_strx_to_uint32_n_() failed %lu time%s.\n\n", 3028 (unsigned long) strx_to_uint32_n_fails, 3029 strx_to_uint32_n_fails == 1 ? "" : "s"); 3030 else if (verbose > 0) 3031 printf ("PASSED: function MHD_strx_to_uint32_n_() successfully " 3032 "passed all checks.\n\n"); 3033 3034 res = check_strx_to_uint64_valid (); 3035 if (res != 0) 3036 { 3037 strx_to_uint64_fails += res; 3038 fprintf (stderr, 3039 "FAILED: testcase check_strx_to_uint64_valid() failed.\n\n"); 3040 } 3041 else if (verbose > 1) 3042 printf ("PASSED: testcase check_strx_to_uint64_valid() " 3043 "successfully passed.\n\n"); 3044 3045 res = check_strx_to_uint64_all_chars (); 3046 if (res != 0) 3047 { 3048 strx_to_uint64_fails += res; 3049 fprintf (stderr, 3050 "FAILED: testcase check_strx_to_uint64_all_chars() failed.\n\n"); 3051 } 3052 else if (verbose > 1) 3053 printf ("PASSED: testcase check_strx_to_uint64_all_chars() " 3054 "successfully passed.\n\n"); 3055 3056 res = check_strx_to_uint64_overflow (); 3057 if (res != 0) 3058 { 3059 strx_to_uint64_fails += res; 3060 fprintf (stderr, 3061 "FAILED: testcase check_strx_to_uint64_overflow() failed.\n\n"); 3062 } 3063 else if (verbose > 1) 3064 printf ("PASSED: testcase check_strx_to_uint64_overflow() " 3065 "successfully passed.\n\n"); 3066 3067 res = check_strx_to_uint64_no_val (); 3068 if (res != 0) 3069 { 3070 strx_to_uint64_fails += res; 3071 fprintf (stderr, 3072 "FAILED: testcase check_strx_to_uint64_no_val() failed.\n\n"); 3073 } 3074 else if (verbose > 1) 3075 printf ("PASSED: testcase check_strx_to_uint64_no_val() " 3076 "successfully passed.\n\n"); 3077 3078 if (strx_to_uint64_fails) 3079 fprintf (stderr, 3080 "FAILED: function MHD_strx_to_uint64_() failed %lu time%s.\n\n", 3081 (unsigned long) strx_to_uint64_fails, 3082 strx_to_uint64_fails == 1 ? "" : "s"); 3083 else if (verbose > 0) 3084 printf ("PASSED: function MHD_strx_to_uint64_() successfully " 3085 "passed all checks.\n\n"); 3086 3087 res = check_strx_to_uint64_n_valid (); 3088 if (res != 0) 3089 { 3090 strx_to_uint64_n_fails += res; 3091 fprintf (stderr, 3092 "FAILED: testcase check_strx_to_uint64_n_valid() failed.\n\n"); 3093 } 3094 else if (verbose > 1) 3095 printf ("PASSED: testcase check_strx_to_uint64_n_valid() " 3096 "successfully passed.\n\n"); 3097 3098 res = check_strx_to_uint64_n_all_chars (); 3099 if (res != 0) 3100 { 3101 strx_to_uint64_n_fails += res; 3102 fprintf (stderr, 3103 "FAILED: testcase check_strx_to_uint64_n_all_chars() failed.\n\n"); 3104 } 3105 else if (verbose > 1) 3106 printf ("PASSED: testcase check_strx_to_uint64_n_all_chars() " 3107 "successfully passed.\n\n"); 3108 3109 res = check_strx_to_uint64_n_overflow (); 3110 if (res != 0) 3111 { 3112 strx_to_uint64_n_fails += res; 3113 fprintf (stderr, 3114 "FAILED: testcase check_strx_to_uint64_n_overflow() failed.\n\n"); 3115 } 3116 else if (verbose > 1) 3117 printf ("PASSED: testcase check_strx_to_uint64_n_overflow() " 3118 "successfully passed.\n\n"); 3119 3120 res = check_strx_to_uint64_n_no_val (); 3121 if (res != 0) 3122 { 3123 strx_to_uint64_n_fails += res; 3124 fprintf (stderr, 3125 "FAILED: testcase check_strx_to_uint64_n_no_val() failed.\n\n"); 3126 } 3127 else if (verbose > 1) 3128 printf ("PASSED: testcase check_strx_to_uint64_n_no_val() " 3129 "successfully passed.\n\n"); 3130 3131 if (strx_to_uint64_n_fails) 3132 fprintf (stderr, 3133 "FAILED: function MHD_strx_to_uint64_n_() failed %lu time%s.\n\n", 3134 (unsigned long) strx_to_uint64_n_fails, 3135 strx_to_uint64_n_fails == 1 ? "" : "s"); 3136 else if (verbose > 0) 3137 printf ("PASSED: function MHD_strx_to_uint64_n_() successfully " 3138 "passed all checks.\n\n"); 3139 3140 if (str_to_uint64_fails || str_to_uint64_n_fails || 3141 strx_to_uint32_fails || strx_to_uint32_n_fails || 3142 strx_to_uint64_fails || strx_to_uint64_n_fails) 3143 { 3144 if (verbose > 0) 3145 printf ("At least one test failed.\n"); 3146 3147 return 1; 3148 } 3149 3150 if (verbose > 0) 3151 printf ("All tests passed successfully.\n"); 3152 3153 return 0; 3154 } 3155 3156 3157 static size_t 3158 check_str_from_uint16 (void) 3159 { 3160 size_t t_failed = 0; 3161 size_t i, j; 3162 char buf[70]; 3163 const char *erase = 3164 "-@=sd#+&(pdiren456qwe#@C3S!DAS45AOIPUQWESAdFzxcv1s*()&#$%34`" 3165 "32452d098poiden45SADFFDA3S4D3SDFdfgsdfgsSADFzxdvs$*()द`" 3166 "adsf##$$@&*^%*^&56qwe#3C@S!DAScFAOIP$#%#$Ad1zs3v1$*()ӌ`"; 3167 int c_failed[sizeof(dstrs_w_values) 3168 / sizeof(dstrs_w_values[0])]; 3169 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 3170 3171 memset (c_failed, 0, sizeof(c_failed)); 3172 3173 for (j = 0; j < locale_name_count; j++) 3174 { 3175 set_test_locale (j); /* setlocale() can be slow! */ 3176 for (i = 0; i < n_checks; i++) 3177 { 3178 const struct str_with_value *const t = dstrs_w_values + i; 3179 size_t b_size; 3180 size_t rs; 3181 3182 if (c_failed[i]) 3183 continue; /* skip already failed checks */ 3184 3185 if (t->str.len < t->num_of_digt) 3186 { 3187 fprintf (stderr, 3188 "ERROR: dstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" 3189 " to be less or equal to str.len (%u).\n", 3190 (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned 3191 int) t->str. 3192 len); 3193 exit (99); 3194 } 3195 if ('0' == t->str.str[0]) 3196 continue; /* Skip strings prefixed with zeros */ 3197 if (t->num_of_digt != t->str.len) 3198 continue; /* Skip strings with suffixes */ 3199 if (UINT16_MAX < t->val) 3200 continue; /* Too large value to convert */ 3201 if (sizeof(buf) < t->str.len + 1) 3202 { 3203 fprintf (stderr, 3204 "ERROR: dstrs_w_values[%u] has too long (%u) string, " 3205 "size of 'buf' should be increased.\n", 3206 (unsigned int) i, (unsigned int) t->str.len); 3207 exit (99); 3208 } 3209 rs = 0; /* Only to mute compiler warning */ 3210 for (b_size = 0; b_size <= t->str.len + 1; ++b_size) 3211 { 3212 /* fill buffer with pseudo-random values */ 3213 memcpy (buf, erase, sizeof(buf)); 3214 3215 rs = MHD_uint16_to_str ((uint16_t) t->val, buf, b_size); 3216 3217 if (t->num_of_digt > b_size) 3218 { 3219 /* Must fail, buffer is too small for result */ 3220 if (0 != rs) 3221 { 3222 if (0 == c_failed[i]) 3223 t_failed++; 3224 c_failed[i] = ! 0; 3225 fprintf (stderr, 3226 "FAILED: MHD_uint16_to_str(%" PRIu64 ", -> buf," 3227 " %d) returned %" PRIuPTR 3228 ", while expecting 0." 3229 " Locale: %s\n", t->val, (int) b_size, (uintptr_t) rs, 3230 get_current_locale_str ()); 3231 } 3232 } 3233 else 3234 { 3235 if (t->num_of_digt != rs) 3236 { 3237 if (0 == c_failed[i]) 3238 t_failed++; 3239 c_failed[i] = ! 0; 3240 fprintf (stderr, 3241 "FAILED: MHD_uint16_to_str(%" PRIu64 ", -> buf," 3242 " %d) returned %" PRIuPTR 3243 ", while expecting %d." 3244 " Locale: %s\n", t->val, (int) b_size, (uintptr_t) rs, 3245 (int) t->num_of_digt, get_current_locale_str ()); 3246 } 3247 else if (0 != memcmp (buf, t->str.str, t->num_of_digt)) 3248 { 3249 if (0 == c_failed[i]) 3250 t_failed++; 3251 c_failed[i] = ! 0; 3252 fprintf (stderr, 3253 "FAILED: MHD_uint16_to_str(%" PRIu64 ", -> \"%.*s\"," 3254 " %d) returned %" PRIuPTR "." 3255 " Locale: %s\n", t->val, (int) rs, buf, (int) b_size, 3256 (uintptr_t) rs, get_current_locale_str ()); 3257 } 3258 else if (0 != memcmp (buf + rs, erase + rs, sizeof(buf) - rs)) 3259 { 3260 if (0 == c_failed[i]) 3261 t_failed++; 3262 c_failed[i] = ! 0; 3263 fprintf (stderr, 3264 "FAILED: MHD_uint16_to_str(%" PRIu64 ", -> \"%.*s\"," 3265 " %d) returned %" PRIuPTR 3266 " and touched data after the resulting string." 3267 " Locale: %s\n", t->val, (int) rs, buf, (int) b_size, 3268 (uintptr_t) rs, get_current_locale_str ()); 3269 } 3270 } 3271 } 3272 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) 3273 printf ("PASSED: MHD_uint16_to_str(%" PRIu64 ", -> \"%.*s\", %d) " 3274 "== %" PRIuPTR "\n", 3275 t->val, (int) rs, buf, (int) b_size - 1, (uintptr_t) rs); 3276 } 3277 } 3278 return t_failed; 3279 } 3280 3281 3282 static size_t 3283 check_str_from_uint64 (void) 3284 { 3285 size_t t_failed = 0; 3286 size_t i, j; 3287 char buf[70]; 3288 const char *erase = 3289 "-@=sd#+&(pdirenDSFGSe#@C&S!DAS*!AOIPUQWESAdFzxcvSs*()&#$%KH`" 3290 "32452d098poiden45SADFFDA3S4D3SDFdfgsdfgsSADFzxdvs$*()द`" 3291 "adsf##$$@&*^%*^&56qwe#3C@S!DAScFAOIP$#%#$Ad1zs3v1$*()ӌ`"; 3292 int c_failed[sizeof(dstrs_w_values) 3293 / sizeof(dstrs_w_values[0])]; 3294 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 3295 3296 memset (c_failed, 0, sizeof(c_failed)); 3297 3298 for (j = 0; j < locale_name_count; j++) 3299 { 3300 set_test_locale (j); /* setlocale() can be slow! */ 3301 for (i = 0; i < n_checks; i++) 3302 { 3303 const struct str_with_value *const t = dstrs_w_values + i; 3304 size_t b_size; 3305 size_t rs; 3306 3307 if (c_failed[i]) 3308 continue; /* skip already failed checks */ 3309 3310 if (t->str.len < t->num_of_digt) 3311 { 3312 fprintf (stderr, 3313 "ERROR: dstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" 3314 " to be less or equal to str.len (%u).\n", 3315 (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned 3316 int) t->str. 3317 len); 3318 exit (99); 3319 } 3320 if ('0' == t->str.str[0]) 3321 continue; /* Skip strings prefixed with zeros */ 3322 if (t->num_of_digt != t->str.len) 3323 continue; /* Skip strings with suffixes */ 3324 if (sizeof(buf) < t->str.len + 1) 3325 { 3326 fprintf (stderr, 3327 "ERROR: dstrs_w_values[%u] has too long (%u) string, " 3328 "size of 'buf' should be increased.\n", 3329 (unsigned int) i, (unsigned int) t->str.len); 3330 exit (99); 3331 } 3332 rs = 0; /* Only to mute compiler warning */ 3333 for (b_size = 0; b_size <= t->str.len + 1; ++b_size) 3334 { 3335 /* fill buffer with pseudo-random values */ 3336 memcpy (buf, erase, sizeof(buf)); 3337 3338 rs = MHD_uint64_to_str (t->val, buf, b_size); 3339 3340 if (t->num_of_digt > b_size) 3341 { 3342 /* Must fail, buffer is too small for result */ 3343 if (0 != rs) 3344 { 3345 if (0 == c_failed[i]) 3346 t_failed++; 3347 c_failed[i] = ! 0; 3348 fprintf (stderr, 3349 "FAILED: MHD_uint64_to_str(%" PRIu64 ", -> buf," 3350 " %d) returned %" PRIuPTR 3351 ", while expecting 0." 3352 " Locale: %s\n", t->val, (int) b_size, (uintptr_t) rs, 3353 get_current_locale_str ()); 3354 } 3355 } 3356 else 3357 { 3358 if (t->num_of_digt != rs) 3359 { 3360 if (0 == c_failed[i]) 3361 t_failed++; 3362 c_failed[i] = ! 0; 3363 fprintf (stderr, 3364 "FAILED: MHD_uint64_to_str(%" PRIu64 ", -> buf," 3365 " %d) returned %" PRIuPTR 3366 ", while expecting %d." 3367 " Locale: %s\n", t->val, (int) b_size, (uintptr_t) rs, 3368 (int) t->num_of_digt, get_current_locale_str ()); 3369 } 3370 else if (0 != memcmp (buf, t->str.str, t->num_of_digt)) 3371 { 3372 if (0 == c_failed[i]) 3373 t_failed++; 3374 c_failed[i] = ! 0; 3375 fprintf (stderr, 3376 "FAILED: MHD_uint64_to_str(%" PRIu64 ", -> \"%.*s\"," 3377 " %d) returned %" PRIuPTR "." 3378 " Locale: %s\n", t->val, (int) rs, buf, (int) b_size, 3379 (uintptr_t) rs, get_current_locale_str ()); 3380 } 3381 else if (0 != memcmp (buf + rs, erase + rs, sizeof(buf) - rs)) 3382 { 3383 if (0 == c_failed[i]) 3384 t_failed++; 3385 c_failed[i] = ! 0; 3386 fprintf (stderr, 3387 "FAILED: MHD_uint64_to_str(%" PRIu64 ", -> \"%.*s\"," 3388 " %d) returned %" PRIuPTR 3389 " and touched data after the resulting string." 3390 " Locale: %s\n", t->val, (int) rs, buf, (int) b_size, 3391 (uintptr_t) rs, get_current_locale_str ()); 3392 } 3393 } 3394 } 3395 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) 3396 printf ("PASSED: MHD_uint64_to_str(%" PRIu64 ", -> \"%.*s\", %d) " 3397 "== %" PRIuPTR "\n", 3398 t->val, (int) rs, buf, (int) b_size - 1, (uintptr_t) rs); 3399 } 3400 } 3401 return t_failed; 3402 } 3403 3404 3405 static size_t 3406 check_strx_from_uint32 (void) 3407 { 3408 size_t t_failed = 0; 3409 size_t i, j; 3410 char buf[70]; 3411 const char *erase = 3412 "jrlkjssfhjfvrjntJHLJ$@%$#adsfdkj;k$##$%#$%FGDF%$#^FDFG%$#$D`" 3413 ";skjdhjflsdkjhdjfalskdjhdfalkjdhf$%##%$$#%FSDGFSDDGDFSSDSDF`" 3414 "#5#$%#$#$DFSFDDFSGSDFSDF354FDDSGFDFfdssfddfswqemn,.zxih,.sx`"; 3415 int c_failed[sizeof(xdstrs_w_values) 3416 / sizeof(xdstrs_w_values[0])]; 3417 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 3418 3419 memset (c_failed, 0, sizeof(c_failed)); 3420 3421 for (j = 0; j < locale_name_count; j++) 3422 { 3423 set_test_locale (j); /* setlocale() can be slow! */ 3424 for (i = 0; i < n_checks; i++) 3425 { 3426 const struct str_with_value *const t = xdstrs_w_values + i; 3427 size_t b_size; 3428 size_t rs; 3429 3430 if (c_failed[i]) 3431 continue; /* skip already failed checks */ 3432 3433 if (t->str.len < t->num_of_digt) 3434 { 3435 fprintf (stderr, 3436 "ERROR: dstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" 3437 " to be less or equal to str.len (%u).\n", 3438 (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned 3439 int) t->str. 3440 len); 3441 exit (99); 3442 } 3443 if ('0' == t->str.str[0]) 3444 continue; /* Skip strings prefixed with zeros */ 3445 if (t->num_of_digt != t->str.len) 3446 continue; /* Skip strings with suffixes */ 3447 if (UINT32_MAX < t->val) 3448 continue; /* Too large value to convert */ 3449 if (sizeof(buf) < t->str.len + 1) 3450 { 3451 fprintf (stderr, 3452 "ERROR: dstrs_w_values[%u] has too long (%u) string, " 3453 "size of 'buf' should be increased.\n", 3454 (unsigned int) i, (unsigned int) t->str.len); 3455 exit (99); 3456 } 3457 rs = 0; /* Only to mute compiler warning */ 3458 for (b_size = 0; b_size <= t->str.len + 1; ++b_size) 3459 { 3460 /* fill buffer with pseudo-random values */ 3461 memcpy (buf, erase, sizeof(buf)); 3462 3463 rs = MHD_uint32_to_strx ((uint32_t) t->val, buf, b_size); 3464 3465 if (t->num_of_digt > b_size) 3466 { 3467 /* Must fail, buffer is too small for result */ 3468 if (0 != rs) 3469 { 3470 if (0 == c_failed[i]) 3471 t_failed++; 3472 c_failed[i] = ! 0; 3473 fprintf (stderr, 3474 "FAILED: MHD_uint32_to_strx(0x%" PRIX64 ", -> buf," 3475 " %d) returned %" PRIuPTR 3476 ", while expecting 0." 3477 " Locale: %s\n", t->val, (int) b_size, (uintptr_t) rs, 3478 get_current_locale_str ()); 3479 } 3480 } 3481 else 3482 { 3483 if (t->num_of_digt != rs) 3484 { 3485 if (0 == c_failed[i]) 3486 t_failed++; 3487 c_failed[i] = ! 0; 3488 fprintf (stderr, 3489 "FAILED: MHD_uint32_to_strx(0x%" PRIX64 ", -> buf," 3490 " %d) returned %" PRIuPTR 3491 ", while expecting %d." 3492 " Locale: %s\n", t->val, (int) b_size, (uintptr_t) rs, 3493 (int) t->num_of_digt, get_current_locale_str ()); 3494 } 3495 else if (0 == MHD_str_equal_caseless_bin_n_ (buf, t->str.str, 3496 t->num_of_digt)) 3497 { 3498 if (0 == c_failed[i]) 3499 t_failed++; 3500 c_failed[i] = ! 0; 3501 fprintf (stderr, 3502 "FAILED: MHD_uint32_to_strx(0x%" PRIX64 ", -> \"%.*s\"," 3503 " %d) returned %" PRIuPTR "." 3504 " Locale: %s\n", t->val, (int) rs, buf, (int) b_size, 3505 (uintptr_t) rs, get_current_locale_str ()); 3506 } 3507 else if (sizeof(buf) <= rs) 3508 { 3509 fprintf (stderr, 3510 "ERROR: dstrs_w_values[%u] has string with too many" 3511 "(%u) digits, size of 'buf' should be increased.\n", 3512 (unsigned int) i, (unsigned int) rs); 3513 exit (99); 3514 } 3515 else if (0 != memcmp (buf + rs, erase + rs, sizeof(buf) - rs)) 3516 { 3517 if (0 == c_failed[i]) 3518 t_failed++; 3519 c_failed[i] = ! 0; 3520 fprintf (stderr, 3521 "FAILED: MHD_uint32_to_strx(0x%" PRIX64 ", -> \"%.*s\"," 3522 " %d) returned %" PRIuPTR 3523 " and touched data after the resulting string." 3524 " Locale: %s\n", t->val, (int) rs, buf, (int) b_size, 3525 (uintptr_t) rs, get_current_locale_str ()); 3526 } 3527 } 3528 } 3529 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) 3530 printf ("PASSED: MHD_uint32_to_strx(0x%" PRIX64 ", -> \"%.*s\", %d) " 3531 "== %" PRIuPTR "\n", 3532 t->val, (int) rs, buf, (int) b_size - 1, (uintptr_t) rs); 3533 } 3534 } 3535 return t_failed; 3536 } 3537 3538 3539 static const struct str_with_value duint8_w_values_p1[] = { 3540 {D_STR_W_LEN ("0"), 1, 0}, 3541 {D_STR_W_LEN ("1"), 1, 1}, 3542 {D_STR_W_LEN ("2"), 1, 2}, 3543 {D_STR_W_LEN ("3"), 1, 3}, 3544 {D_STR_W_LEN ("4"), 1, 4}, 3545 {D_STR_W_LEN ("5"), 1, 5}, 3546 {D_STR_W_LEN ("6"), 1, 6}, 3547 {D_STR_W_LEN ("7"), 1, 7}, 3548 {D_STR_W_LEN ("8"), 1, 8}, 3549 {D_STR_W_LEN ("9"), 1, 9}, 3550 {D_STR_W_LEN ("10"), 2, 10}, 3551 {D_STR_W_LEN ("11"), 2, 11}, 3552 {D_STR_W_LEN ("12"), 2, 12}, 3553 {D_STR_W_LEN ("13"), 2, 13}, 3554 {D_STR_W_LEN ("14"), 2, 14}, 3555 {D_STR_W_LEN ("15"), 2, 15}, 3556 {D_STR_W_LEN ("16"), 2, 16}, 3557 {D_STR_W_LEN ("17"), 2, 17}, 3558 {D_STR_W_LEN ("18"), 2, 18}, 3559 {D_STR_W_LEN ("19"), 2, 19}, 3560 {D_STR_W_LEN ("20"), 2, 20}, 3561 {D_STR_W_LEN ("21"), 2, 21}, 3562 {D_STR_W_LEN ("22"), 2, 22}, 3563 {D_STR_W_LEN ("23"), 2, 23}, 3564 {D_STR_W_LEN ("24"), 2, 24}, 3565 {D_STR_W_LEN ("25"), 2, 25}, 3566 {D_STR_W_LEN ("26"), 2, 26}, 3567 {D_STR_W_LEN ("27"), 2, 27}, 3568 {D_STR_W_LEN ("28"), 2, 28}, 3569 {D_STR_W_LEN ("29"), 2, 29}, 3570 {D_STR_W_LEN ("30"), 2, 30}, 3571 {D_STR_W_LEN ("31"), 2, 31}, 3572 {D_STR_W_LEN ("32"), 2, 32}, 3573 {D_STR_W_LEN ("33"), 2, 33}, 3574 {D_STR_W_LEN ("34"), 2, 34}, 3575 {D_STR_W_LEN ("35"), 2, 35}, 3576 {D_STR_W_LEN ("36"), 2, 36}, 3577 {D_STR_W_LEN ("37"), 2, 37}, 3578 {D_STR_W_LEN ("38"), 2, 38}, 3579 {D_STR_W_LEN ("39"), 2, 39}, 3580 {D_STR_W_LEN ("40"), 2, 40}, 3581 {D_STR_W_LEN ("41"), 2, 41}, 3582 {D_STR_W_LEN ("42"), 2, 42}, 3583 {D_STR_W_LEN ("43"), 2, 43}, 3584 {D_STR_W_LEN ("44"), 2, 44}, 3585 {D_STR_W_LEN ("45"), 2, 45}, 3586 {D_STR_W_LEN ("46"), 2, 46}, 3587 {D_STR_W_LEN ("47"), 2, 47}, 3588 {D_STR_W_LEN ("48"), 2, 48}, 3589 {D_STR_W_LEN ("49"), 2, 49}, 3590 {D_STR_W_LEN ("50"), 2, 50}, 3591 {D_STR_W_LEN ("51"), 2, 51}, 3592 {D_STR_W_LEN ("52"), 2, 52}, 3593 {D_STR_W_LEN ("53"), 2, 53}, 3594 {D_STR_W_LEN ("54"), 2, 54}, 3595 {D_STR_W_LEN ("55"), 2, 55}, 3596 {D_STR_W_LEN ("56"), 2, 56}, 3597 {D_STR_W_LEN ("57"), 2, 57}, 3598 {D_STR_W_LEN ("58"), 2, 58}, 3599 {D_STR_W_LEN ("59"), 2, 59}, 3600 {D_STR_W_LEN ("60"), 2, 60}, 3601 {D_STR_W_LEN ("61"), 2, 61}, 3602 {D_STR_W_LEN ("62"), 2, 62}, 3603 {D_STR_W_LEN ("63"), 2, 63}, 3604 {D_STR_W_LEN ("64"), 2, 64}, 3605 {D_STR_W_LEN ("65"), 2, 65}, 3606 {D_STR_W_LEN ("66"), 2, 66}, 3607 {D_STR_W_LEN ("67"), 2, 67}, 3608 {D_STR_W_LEN ("68"), 2, 68}, 3609 {D_STR_W_LEN ("69"), 2, 69}, 3610 {D_STR_W_LEN ("70"), 2, 70}, 3611 {D_STR_W_LEN ("71"), 2, 71}, 3612 {D_STR_W_LEN ("72"), 2, 72}, 3613 {D_STR_W_LEN ("73"), 2, 73}, 3614 {D_STR_W_LEN ("74"), 2, 74}, 3615 {D_STR_W_LEN ("75"), 2, 75}, 3616 {D_STR_W_LEN ("76"), 2, 76}, 3617 {D_STR_W_LEN ("77"), 2, 77}, 3618 {D_STR_W_LEN ("78"), 2, 78}, 3619 {D_STR_W_LEN ("79"), 2, 79}, 3620 {D_STR_W_LEN ("80"), 2, 80}, 3621 {D_STR_W_LEN ("81"), 2, 81}, 3622 {D_STR_W_LEN ("82"), 2, 82}, 3623 {D_STR_W_LEN ("83"), 2, 83}, 3624 {D_STR_W_LEN ("84"), 2, 84}, 3625 {D_STR_W_LEN ("85"), 2, 85}, 3626 {D_STR_W_LEN ("86"), 2, 86}, 3627 {D_STR_W_LEN ("87"), 2, 87}, 3628 {D_STR_W_LEN ("88"), 2, 88}, 3629 {D_STR_W_LEN ("89"), 2, 89}, 3630 {D_STR_W_LEN ("90"), 2, 90}, 3631 {D_STR_W_LEN ("91"), 2, 91}, 3632 {D_STR_W_LEN ("92"), 2, 92}, 3633 {D_STR_W_LEN ("93"), 2, 93}, 3634 {D_STR_W_LEN ("94"), 2, 94}, 3635 {D_STR_W_LEN ("95"), 2, 95}, 3636 {D_STR_W_LEN ("96"), 2, 96}, 3637 {D_STR_W_LEN ("97"), 2, 97}, 3638 {D_STR_W_LEN ("98"), 2, 98}, 3639 {D_STR_W_LEN ("99"), 2, 99}, 3640 {D_STR_W_LEN ("100"), 3, 100}, 3641 {D_STR_W_LEN ("101"), 3, 101}, 3642 {D_STR_W_LEN ("102"), 3, 102}, 3643 {D_STR_W_LEN ("103"), 3, 103}, 3644 {D_STR_W_LEN ("104"), 3, 104}, 3645 {D_STR_W_LEN ("105"), 3, 105}, 3646 {D_STR_W_LEN ("106"), 3, 106}, 3647 {D_STR_W_LEN ("107"), 3, 107}, 3648 {D_STR_W_LEN ("108"), 3, 108}, 3649 {D_STR_W_LEN ("109"), 3, 109}, 3650 {D_STR_W_LEN ("110"), 3, 110}, 3651 {D_STR_W_LEN ("111"), 3, 111}, 3652 {D_STR_W_LEN ("112"), 3, 112}, 3653 {D_STR_W_LEN ("113"), 3, 113}, 3654 {D_STR_W_LEN ("114"), 3, 114}, 3655 {D_STR_W_LEN ("115"), 3, 115}, 3656 {D_STR_W_LEN ("116"), 3, 116}, 3657 {D_STR_W_LEN ("117"), 3, 117}, 3658 {D_STR_W_LEN ("118"), 3, 118}, 3659 {D_STR_W_LEN ("119"), 3, 119}, 3660 {D_STR_W_LEN ("120"), 3, 120}, 3661 {D_STR_W_LEN ("121"), 3, 121}, 3662 {D_STR_W_LEN ("122"), 3, 122}, 3663 {D_STR_W_LEN ("123"), 3, 123}, 3664 {D_STR_W_LEN ("124"), 3, 124}, 3665 {D_STR_W_LEN ("125"), 3, 125}, 3666 {D_STR_W_LEN ("126"), 3, 126}, 3667 {D_STR_W_LEN ("127"), 3, 127}, 3668 {D_STR_W_LEN ("128"), 3, 128}, 3669 {D_STR_W_LEN ("129"), 3, 129}, 3670 {D_STR_W_LEN ("130"), 3, 130}, 3671 {D_STR_W_LEN ("131"), 3, 131}, 3672 {D_STR_W_LEN ("132"), 3, 132}, 3673 {D_STR_W_LEN ("133"), 3, 133}, 3674 {D_STR_W_LEN ("134"), 3, 134}, 3675 {D_STR_W_LEN ("135"), 3, 135}, 3676 {D_STR_W_LEN ("136"), 3, 136}, 3677 {D_STR_W_LEN ("137"), 3, 137}, 3678 {D_STR_W_LEN ("138"), 3, 138}, 3679 {D_STR_W_LEN ("139"), 3, 139}, 3680 {D_STR_W_LEN ("140"), 3, 140}, 3681 {D_STR_W_LEN ("141"), 3, 141}, 3682 {D_STR_W_LEN ("142"), 3, 142}, 3683 {D_STR_W_LEN ("143"), 3, 143}, 3684 {D_STR_W_LEN ("144"), 3, 144}, 3685 {D_STR_W_LEN ("145"), 3, 145}, 3686 {D_STR_W_LEN ("146"), 3, 146}, 3687 {D_STR_W_LEN ("147"), 3, 147}, 3688 {D_STR_W_LEN ("148"), 3, 148}, 3689 {D_STR_W_LEN ("149"), 3, 149}, 3690 {D_STR_W_LEN ("150"), 3, 150}, 3691 {D_STR_W_LEN ("151"), 3, 151}, 3692 {D_STR_W_LEN ("152"), 3, 152}, 3693 {D_STR_W_LEN ("153"), 3, 153}, 3694 {D_STR_W_LEN ("154"), 3, 154}, 3695 {D_STR_W_LEN ("155"), 3, 155}, 3696 {D_STR_W_LEN ("156"), 3, 156}, 3697 {D_STR_W_LEN ("157"), 3, 157}, 3698 {D_STR_W_LEN ("158"), 3, 158}, 3699 {D_STR_W_LEN ("159"), 3, 159}, 3700 {D_STR_W_LEN ("160"), 3, 160}, 3701 {D_STR_W_LEN ("161"), 3, 161}, 3702 {D_STR_W_LEN ("162"), 3, 162}, 3703 {D_STR_W_LEN ("163"), 3, 163}, 3704 {D_STR_W_LEN ("164"), 3, 164}, 3705 {D_STR_W_LEN ("165"), 3, 165}, 3706 {D_STR_W_LEN ("166"), 3, 166}, 3707 {D_STR_W_LEN ("167"), 3, 167}, 3708 {D_STR_W_LEN ("168"), 3, 168}, 3709 {D_STR_W_LEN ("169"), 3, 169}, 3710 {D_STR_W_LEN ("170"), 3, 170}, 3711 {D_STR_W_LEN ("171"), 3, 171}, 3712 {D_STR_W_LEN ("172"), 3, 172}, 3713 {D_STR_W_LEN ("173"), 3, 173}, 3714 {D_STR_W_LEN ("174"), 3, 174}, 3715 {D_STR_W_LEN ("175"), 3, 175}, 3716 {D_STR_W_LEN ("176"), 3, 176}, 3717 {D_STR_W_LEN ("177"), 3, 177}, 3718 {D_STR_W_LEN ("178"), 3, 178}, 3719 {D_STR_W_LEN ("179"), 3, 179}, 3720 {D_STR_W_LEN ("180"), 3, 180}, 3721 {D_STR_W_LEN ("181"), 3, 181}, 3722 {D_STR_W_LEN ("182"), 3, 182}, 3723 {D_STR_W_LEN ("183"), 3, 183}, 3724 {D_STR_W_LEN ("184"), 3, 184}, 3725 {D_STR_W_LEN ("185"), 3, 185}, 3726 {D_STR_W_LEN ("186"), 3, 186}, 3727 {D_STR_W_LEN ("187"), 3, 187}, 3728 {D_STR_W_LEN ("188"), 3, 188}, 3729 {D_STR_W_LEN ("189"), 3, 189}, 3730 {D_STR_W_LEN ("190"), 3, 190}, 3731 {D_STR_W_LEN ("191"), 3, 191}, 3732 {D_STR_W_LEN ("192"), 3, 192}, 3733 {D_STR_W_LEN ("193"), 3, 193}, 3734 {D_STR_W_LEN ("194"), 3, 194}, 3735 {D_STR_W_LEN ("195"), 3, 195}, 3736 {D_STR_W_LEN ("196"), 3, 196}, 3737 {D_STR_W_LEN ("197"), 3, 197}, 3738 {D_STR_W_LEN ("198"), 3, 198}, 3739 {D_STR_W_LEN ("199"), 3, 199}, 3740 {D_STR_W_LEN ("200"), 3, 200}, 3741 {D_STR_W_LEN ("201"), 3, 201}, 3742 {D_STR_W_LEN ("202"), 3, 202}, 3743 {D_STR_W_LEN ("203"), 3, 203}, 3744 {D_STR_W_LEN ("204"), 3, 204}, 3745 {D_STR_W_LEN ("205"), 3, 205}, 3746 {D_STR_W_LEN ("206"), 3, 206}, 3747 {D_STR_W_LEN ("207"), 3, 207}, 3748 {D_STR_W_LEN ("208"), 3, 208}, 3749 {D_STR_W_LEN ("209"), 3, 209}, 3750 {D_STR_W_LEN ("210"), 3, 210}, 3751 {D_STR_W_LEN ("211"), 3, 211}, 3752 {D_STR_W_LEN ("212"), 3, 212}, 3753 {D_STR_W_LEN ("213"), 3, 213}, 3754 {D_STR_W_LEN ("214"), 3, 214}, 3755 {D_STR_W_LEN ("215"), 3, 215}, 3756 {D_STR_W_LEN ("216"), 3, 216}, 3757 {D_STR_W_LEN ("217"), 3, 217}, 3758 {D_STR_W_LEN ("218"), 3, 218}, 3759 {D_STR_W_LEN ("219"), 3, 219}, 3760 {D_STR_W_LEN ("220"), 3, 220}, 3761 {D_STR_W_LEN ("221"), 3, 221}, 3762 {D_STR_W_LEN ("222"), 3, 222}, 3763 {D_STR_W_LEN ("223"), 3, 223}, 3764 {D_STR_W_LEN ("224"), 3, 224}, 3765 {D_STR_W_LEN ("225"), 3, 225}, 3766 {D_STR_W_LEN ("226"), 3, 226}, 3767 {D_STR_W_LEN ("227"), 3, 227}, 3768 {D_STR_W_LEN ("228"), 3, 228}, 3769 {D_STR_W_LEN ("229"), 3, 229}, 3770 {D_STR_W_LEN ("230"), 3, 230}, 3771 {D_STR_W_LEN ("231"), 3, 231}, 3772 {D_STR_W_LEN ("232"), 3, 232}, 3773 {D_STR_W_LEN ("233"), 3, 233}, 3774 {D_STR_W_LEN ("234"), 3, 234}, 3775 {D_STR_W_LEN ("235"), 3, 235}, 3776 {D_STR_W_LEN ("236"), 3, 236}, 3777 {D_STR_W_LEN ("237"), 3, 237}, 3778 {D_STR_W_LEN ("238"), 3, 238}, 3779 {D_STR_W_LEN ("239"), 3, 239}, 3780 {D_STR_W_LEN ("240"), 3, 240}, 3781 {D_STR_W_LEN ("241"), 3, 241}, 3782 {D_STR_W_LEN ("242"), 3, 242}, 3783 {D_STR_W_LEN ("243"), 3, 243}, 3784 {D_STR_W_LEN ("244"), 3, 244}, 3785 {D_STR_W_LEN ("245"), 3, 245}, 3786 {D_STR_W_LEN ("246"), 3, 246}, 3787 {D_STR_W_LEN ("247"), 3, 247}, 3788 {D_STR_W_LEN ("248"), 3, 248}, 3789 {D_STR_W_LEN ("249"), 3, 249}, 3790 {D_STR_W_LEN ("250"), 3, 250}, 3791 {D_STR_W_LEN ("251"), 3, 251}, 3792 {D_STR_W_LEN ("252"), 3, 252}, 3793 {D_STR_W_LEN ("253"), 3, 253}, 3794 {D_STR_W_LEN ("254"), 3, 254}, 3795 {D_STR_W_LEN ("255"), 3, 255}, 3796 }; 3797 3798 static const struct str_with_value duint8_w_values_p2[] = { 3799 {D_STR_W_LEN ("00"), 2, 0}, 3800 {D_STR_W_LEN ("01"), 2, 1}, 3801 {D_STR_W_LEN ("02"), 2, 2}, 3802 {D_STR_W_LEN ("03"), 2, 3}, 3803 {D_STR_W_LEN ("04"), 2, 4}, 3804 {D_STR_W_LEN ("05"), 2, 5}, 3805 {D_STR_W_LEN ("06"), 2, 6}, 3806 {D_STR_W_LEN ("07"), 2, 7}, 3807 {D_STR_W_LEN ("08"), 2, 8}, 3808 {D_STR_W_LEN ("09"), 2, 9}, 3809 {D_STR_W_LEN ("10"), 2, 10}, 3810 {D_STR_W_LEN ("11"), 2, 11}, 3811 {D_STR_W_LEN ("12"), 2, 12}, 3812 {D_STR_W_LEN ("13"), 2, 13}, 3813 {D_STR_W_LEN ("14"), 2, 14}, 3814 {D_STR_W_LEN ("15"), 2, 15}, 3815 {D_STR_W_LEN ("16"), 2, 16}, 3816 {D_STR_W_LEN ("17"), 2, 17}, 3817 {D_STR_W_LEN ("18"), 2, 18}, 3818 {D_STR_W_LEN ("19"), 2, 19}, 3819 {D_STR_W_LEN ("20"), 2, 20}, 3820 {D_STR_W_LEN ("21"), 2, 21}, 3821 {D_STR_W_LEN ("22"), 2, 22}, 3822 {D_STR_W_LEN ("23"), 2, 23}, 3823 {D_STR_W_LEN ("24"), 2, 24}, 3824 {D_STR_W_LEN ("25"), 2, 25}, 3825 {D_STR_W_LEN ("26"), 2, 26}, 3826 {D_STR_W_LEN ("27"), 2, 27}, 3827 {D_STR_W_LEN ("28"), 2, 28}, 3828 {D_STR_W_LEN ("29"), 2, 29}, 3829 {D_STR_W_LEN ("30"), 2, 30}, 3830 {D_STR_W_LEN ("31"), 2, 31}, 3831 {D_STR_W_LEN ("32"), 2, 32}, 3832 {D_STR_W_LEN ("33"), 2, 33}, 3833 {D_STR_W_LEN ("34"), 2, 34}, 3834 {D_STR_W_LEN ("35"), 2, 35}, 3835 {D_STR_W_LEN ("36"), 2, 36}, 3836 {D_STR_W_LEN ("37"), 2, 37}, 3837 {D_STR_W_LEN ("38"), 2, 38}, 3838 {D_STR_W_LEN ("39"), 2, 39}, 3839 {D_STR_W_LEN ("40"), 2, 40}, 3840 {D_STR_W_LEN ("41"), 2, 41}, 3841 {D_STR_W_LEN ("42"), 2, 42}, 3842 {D_STR_W_LEN ("43"), 2, 43}, 3843 {D_STR_W_LEN ("44"), 2, 44}, 3844 {D_STR_W_LEN ("45"), 2, 45}, 3845 {D_STR_W_LEN ("46"), 2, 46}, 3846 {D_STR_W_LEN ("47"), 2, 47}, 3847 {D_STR_W_LEN ("48"), 2, 48}, 3848 {D_STR_W_LEN ("49"), 2, 49}, 3849 {D_STR_W_LEN ("50"), 2, 50}, 3850 {D_STR_W_LEN ("51"), 2, 51}, 3851 {D_STR_W_LEN ("52"), 2, 52}, 3852 {D_STR_W_LEN ("53"), 2, 53}, 3853 {D_STR_W_LEN ("54"), 2, 54}, 3854 {D_STR_W_LEN ("55"), 2, 55}, 3855 {D_STR_W_LEN ("56"), 2, 56}, 3856 {D_STR_W_LEN ("57"), 2, 57}, 3857 {D_STR_W_LEN ("58"), 2, 58}, 3858 {D_STR_W_LEN ("59"), 2, 59}, 3859 {D_STR_W_LEN ("60"), 2, 60}, 3860 {D_STR_W_LEN ("61"), 2, 61}, 3861 {D_STR_W_LEN ("62"), 2, 62}, 3862 {D_STR_W_LEN ("63"), 2, 63}, 3863 {D_STR_W_LEN ("64"), 2, 64}, 3864 {D_STR_W_LEN ("65"), 2, 65}, 3865 {D_STR_W_LEN ("66"), 2, 66}, 3866 {D_STR_W_LEN ("67"), 2, 67}, 3867 {D_STR_W_LEN ("68"), 2, 68}, 3868 {D_STR_W_LEN ("69"), 2, 69}, 3869 {D_STR_W_LEN ("70"), 2, 70}, 3870 {D_STR_W_LEN ("71"), 2, 71}, 3871 {D_STR_W_LEN ("72"), 2, 72}, 3872 {D_STR_W_LEN ("73"), 2, 73}, 3873 {D_STR_W_LEN ("74"), 2, 74}, 3874 {D_STR_W_LEN ("75"), 2, 75}, 3875 {D_STR_W_LEN ("76"), 2, 76}, 3876 {D_STR_W_LEN ("77"), 2, 77}, 3877 {D_STR_W_LEN ("78"), 2, 78}, 3878 {D_STR_W_LEN ("79"), 2, 79}, 3879 {D_STR_W_LEN ("80"), 2, 80}, 3880 {D_STR_W_LEN ("81"), 2, 81}, 3881 {D_STR_W_LEN ("82"), 2, 82}, 3882 {D_STR_W_LEN ("83"), 2, 83}, 3883 {D_STR_W_LEN ("84"), 2, 84}, 3884 {D_STR_W_LEN ("85"), 2, 85}, 3885 {D_STR_W_LEN ("86"), 2, 86}, 3886 {D_STR_W_LEN ("87"), 2, 87}, 3887 {D_STR_W_LEN ("88"), 2, 88}, 3888 {D_STR_W_LEN ("89"), 2, 89}, 3889 {D_STR_W_LEN ("90"), 2, 90}, 3890 {D_STR_W_LEN ("91"), 2, 91}, 3891 {D_STR_W_LEN ("92"), 2, 92}, 3892 {D_STR_W_LEN ("93"), 2, 93}, 3893 {D_STR_W_LEN ("94"), 2, 94}, 3894 {D_STR_W_LEN ("95"), 2, 95}, 3895 {D_STR_W_LEN ("96"), 2, 96}, 3896 {D_STR_W_LEN ("97"), 2, 97}, 3897 {D_STR_W_LEN ("98"), 2, 98}, 3898 {D_STR_W_LEN ("99"), 2, 99}, 3899 {D_STR_W_LEN ("100"), 3, 100}, 3900 {D_STR_W_LEN ("101"), 3, 101}, 3901 {D_STR_W_LEN ("102"), 3, 102}, 3902 {D_STR_W_LEN ("103"), 3, 103}, 3903 {D_STR_W_LEN ("104"), 3, 104}, 3904 {D_STR_W_LEN ("105"), 3, 105}, 3905 {D_STR_W_LEN ("106"), 3, 106}, 3906 {D_STR_W_LEN ("107"), 3, 107}, 3907 {D_STR_W_LEN ("108"), 3, 108}, 3908 {D_STR_W_LEN ("109"), 3, 109}, 3909 {D_STR_W_LEN ("110"), 3, 110}, 3910 {D_STR_W_LEN ("111"), 3, 111}, 3911 {D_STR_W_LEN ("112"), 3, 112}, 3912 {D_STR_W_LEN ("113"), 3, 113}, 3913 {D_STR_W_LEN ("114"), 3, 114}, 3914 {D_STR_W_LEN ("115"), 3, 115}, 3915 {D_STR_W_LEN ("116"), 3, 116}, 3916 {D_STR_W_LEN ("117"), 3, 117}, 3917 {D_STR_W_LEN ("118"), 3, 118}, 3918 {D_STR_W_LEN ("119"), 3, 119}, 3919 {D_STR_W_LEN ("120"), 3, 120}, 3920 {D_STR_W_LEN ("121"), 3, 121}, 3921 {D_STR_W_LEN ("122"), 3, 122}, 3922 {D_STR_W_LEN ("123"), 3, 123}, 3923 {D_STR_W_LEN ("124"), 3, 124}, 3924 {D_STR_W_LEN ("125"), 3, 125}, 3925 {D_STR_W_LEN ("126"), 3, 126}, 3926 {D_STR_W_LEN ("127"), 3, 127}, 3927 {D_STR_W_LEN ("128"), 3, 128}, 3928 {D_STR_W_LEN ("129"), 3, 129}, 3929 {D_STR_W_LEN ("130"), 3, 130}, 3930 {D_STR_W_LEN ("131"), 3, 131}, 3931 {D_STR_W_LEN ("132"), 3, 132}, 3932 {D_STR_W_LEN ("133"), 3, 133}, 3933 {D_STR_W_LEN ("134"), 3, 134}, 3934 {D_STR_W_LEN ("135"), 3, 135}, 3935 {D_STR_W_LEN ("136"), 3, 136}, 3936 {D_STR_W_LEN ("137"), 3, 137}, 3937 {D_STR_W_LEN ("138"), 3, 138}, 3938 {D_STR_W_LEN ("139"), 3, 139}, 3939 {D_STR_W_LEN ("140"), 3, 140}, 3940 {D_STR_W_LEN ("141"), 3, 141}, 3941 {D_STR_W_LEN ("142"), 3, 142}, 3942 {D_STR_W_LEN ("143"), 3, 143}, 3943 {D_STR_W_LEN ("144"), 3, 144}, 3944 {D_STR_W_LEN ("145"), 3, 145}, 3945 {D_STR_W_LEN ("146"), 3, 146}, 3946 {D_STR_W_LEN ("147"), 3, 147}, 3947 {D_STR_W_LEN ("148"), 3, 148}, 3948 {D_STR_W_LEN ("149"), 3, 149}, 3949 {D_STR_W_LEN ("150"), 3, 150}, 3950 {D_STR_W_LEN ("151"), 3, 151}, 3951 {D_STR_W_LEN ("152"), 3, 152}, 3952 {D_STR_W_LEN ("153"), 3, 153}, 3953 {D_STR_W_LEN ("154"), 3, 154}, 3954 {D_STR_W_LEN ("155"), 3, 155}, 3955 {D_STR_W_LEN ("156"), 3, 156}, 3956 {D_STR_W_LEN ("157"), 3, 157}, 3957 {D_STR_W_LEN ("158"), 3, 158}, 3958 {D_STR_W_LEN ("159"), 3, 159}, 3959 {D_STR_W_LEN ("160"), 3, 160}, 3960 {D_STR_W_LEN ("161"), 3, 161}, 3961 {D_STR_W_LEN ("162"), 3, 162}, 3962 {D_STR_W_LEN ("163"), 3, 163}, 3963 {D_STR_W_LEN ("164"), 3, 164}, 3964 {D_STR_W_LEN ("165"), 3, 165}, 3965 {D_STR_W_LEN ("166"), 3, 166}, 3966 {D_STR_W_LEN ("167"), 3, 167}, 3967 {D_STR_W_LEN ("168"), 3, 168}, 3968 {D_STR_W_LEN ("169"), 3, 169}, 3969 {D_STR_W_LEN ("170"), 3, 170}, 3970 {D_STR_W_LEN ("171"), 3, 171}, 3971 {D_STR_W_LEN ("172"), 3, 172}, 3972 {D_STR_W_LEN ("173"), 3, 173}, 3973 {D_STR_W_LEN ("174"), 3, 174}, 3974 {D_STR_W_LEN ("175"), 3, 175}, 3975 {D_STR_W_LEN ("176"), 3, 176}, 3976 {D_STR_W_LEN ("177"), 3, 177}, 3977 {D_STR_W_LEN ("178"), 3, 178}, 3978 {D_STR_W_LEN ("179"), 3, 179}, 3979 {D_STR_W_LEN ("180"), 3, 180}, 3980 {D_STR_W_LEN ("181"), 3, 181}, 3981 {D_STR_W_LEN ("182"), 3, 182}, 3982 {D_STR_W_LEN ("183"), 3, 183}, 3983 {D_STR_W_LEN ("184"), 3, 184}, 3984 {D_STR_W_LEN ("185"), 3, 185}, 3985 {D_STR_W_LEN ("186"), 3, 186}, 3986 {D_STR_W_LEN ("187"), 3, 187}, 3987 {D_STR_W_LEN ("188"), 3, 188}, 3988 {D_STR_W_LEN ("189"), 3, 189}, 3989 {D_STR_W_LEN ("190"), 3, 190}, 3990 {D_STR_W_LEN ("191"), 3, 191}, 3991 {D_STR_W_LEN ("192"), 3, 192}, 3992 {D_STR_W_LEN ("193"), 3, 193}, 3993 {D_STR_W_LEN ("194"), 3, 194}, 3994 {D_STR_W_LEN ("195"), 3, 195}, 3995 {D_STR_W_LEN ("196"), 3, 196}, 3996 {D_STR_W_LEN ("197"), 3, 197}, 3997 {D_STR_W_LEN ("198"), 3, 198}, 3998 {D_STR_W_LEN ("199"), 3, 199}, 3999 {D_STR_W_LEN ("200"), 3, 200}, 4000 {D_STR_W_LEN ("201"), 3, 201}, 4001 {D_STR_W_LEN ("202"), 3, 202}, 4002 {D_STR_W_LEN ("203"), 3, 203}, 4003 {D_STR_W_LEN ("204"), 3, 204}, 4004 {D_STR_W_LEN ("205"), 3, 205}, 4005 {D_STR_W_LEN ("206"), 3, 206}, 4006 {D_STR_W_LEN ("207"), 3, 207}, 4007 {D_STR_W_LEN ("208"), 3, 208}, 4008 {D_STR_W_LEN ("209"), 3, 209}, 4009 {D_STR_W_LEN ("210"), 3, 210}, 4010 {D_STR_W_LEN ("211"), 3, 211}, 4011 {D_STR_W_LEN ("212"), 3, 212}, 4012 {D_STR_W_LEN ("213"), 3, 213}, 4013 {D_STR_W_LEN ("214"), 3, 214}, 4014 {D_STR_W_LEN ("215"), 3, 215}, 4015 {D_STR_W_LEN ("216"), 3, 216}, 4016 {D_STR_W_LEN ("217"), 3, 217}, 4017 {D_STR_W_LEN ("218"), 3, 218}, 4018 {D_STR_W_LEN ("219"), 3, 219}, 4019 {D_STR_W_LEN ("220"), 3, 220}, 4020 {D_STR_W_LEN ("221"), 3, 221}, 4021 {D_STR_W_LEN ("222"), 3, 222}, 4022 {D_STR_W_LEN ("223"), 3, 223}, 4023 {D_STR_W_LEN ("224"), 3, 224}, 4024 {D_STR_W_LEN ("225"), 3, 225}, 4025 {D_STR_W_LEN ("226"), 3, 226}, 4026 {D_STR_W_LEN ("227"), 3, 227}, 4027 {D_STR_W_LEN ("228"), 3, 228}, 4028 {D_STR_W_LEN ("229"), 3, 229}, 4029 {D_STR_W_LEN ("230"), 3, 230}, 4030 {D_STR_W_LEN ("231"), 3, 231}, 4031 {D_STR_W_LEN ("232"), 3, 232}, 4032 {D_STR_W_LEN ("233"), 3, 233}, 4033 {D_STR_W_LEN ("234"), 3, 234}, 4034 {D_STR_W_LEN ("235"), 3, 235}, 4035 {D_STR_W_LEN ("236"), 3, 236}, 4036 {D_STR_W_LEN ("237"), 3, 237}, 4037 {D_STR_W_LEN ("238"), 3, 238}, 4038 {D_STR_W_LEN ("239"), 3, 239}, 4039 {D_STR_W_LEN ("240"), 3, 240}, 4040 {D_STR_W_LEN ("241"), 3, 241}, 4041 {D_STR_W_LEN ("242"), 3, 242}, 4042 {D_STR_W_LEN ("243"), 3, 243}, 4043 {D_STR_W_LEN ("244"), 3, 244}, 4044 {D_STR_W_LEN ("245"), 3, 245}, 4045 {D_STR_W_LEN ("246"), 3, 246}, 4046 {D_STR_W_LEN ("247"), 3, 247}, 4047 {D_STR_W_LEN ("248"), 3, 248}, 4048 {D_STR_W_LEN ("249"), 3, 249}, 4049 {D_STR_W_LEN ("250"), 3, 250}, 4050 {D_STR_W_LEN ("251"), 3, 251}, 4051 {D_STR_W_LEN ("252"), 3, 252}, 4052 {D_STR_W_LEN ("253"), 3, 253}, 4053 {D_STR_W_LEN ("254"), 3, 254}, 4054 {D_STR_W_LEN ("255"), 3, 255} 4055 }; 4056 4057 static const struct str_with_value duint8_w_values_p3[] = { 4058 {D_STR_W_LEN ("000"), 3, 0}, 4059 {D_STR_W_LEN ("001"), 3, 1}, 4060 {D_STR_W_LEN ("002"), 3, 2}, 4061 {D_STR_W_LEN ("003"), 3, 3}, 4062 {D_STR_W_LEN ("004"), 3, 4}, 4063 {D_STR_W_LEN ("005"), 3, 5}, 4064 {D_STR_W_LEN ("006"), 3, 6}, 4065 {D_STR_W_LEN ("007"), 3, 7}, 4066 {D_STR_W_LEN ("008"), 3, 8}, 4067 {D_STR_W_LEN ("009"), 3, 9}, 4068 {D_STR_W_LEN ("010"), 3, 10}, 4069 {D_STR_W_LEN ("011"), 3, 11}, 4070 {D_STR_W_LEN ("012"), 3, 12}, 4071 {D_STR_W_LEN ("013"), 3, 13}, 4072 {D_STR_W_LEN ("014"), 3, 14}, 4073 {D_STR_W_LEN ("015"), 3, 15}, 4074 {D_STR_W_LEN ("016"), 3, 16}, 4075 {D_STR_W_LEN ("017"), 3, 17}, 4076 {D_STR_W_LEN ("018"), 3, 18}, 4077 {D_STR_W_LEN ("019"), 3, 19}, 4078 {D_STR_W_LEN ("020"), 3, 20}, 4079 {D_STR_W_LEN ("021"), 3, 21}, 4080 {D_STR_W_LEN ("022"), 3, 22}, 4081 {D_STR_W_LEN ("023"), 3, 23}, 4082 {D_STR_W_LEN ("024"), 3, 24}, 4083 {D_STR_W_LEN ("025"), 3, 25}, 4084 {D_STR_W_LEN ("026"), 3, 26}, 4085 {D_STR_W_LEN ("027"), 3, 27}, 4086 {D_STR_W_LEN ("028"), 3, 28}, 4087 {D_STR_W_LEN ("029"), 3, 29}, 4088 {D_STR_W_LEN ("030"), 3, 30}, 4089 {D_STR_W_LEN ("031"), 3, 31}, 4090 {D_STR_W_LEN ("032"), 3, 32}, 4091 {D_STR_W_LEN ("033"), 3, 33}, 4092 {D_STR_W_LEN ("034"), 3, 34}, 4093 {D_STR_W_LEN ("035"), 3, 35}, 4094 {D_STR_W_LEN ("036"), 3, 36}, 4095 {D_STR_W_LEN ("037"), 3, 37}, 4096 {D_STR_W_LEN ("038"), 3, 38}, 4097 {D_STR_W_LEN ("039"), 3, 39}, 4098 {D_STR_W_LEN ("040"), 3, 40}, 4099 {D_STR_W_LEN ("041"), 3, 41}, 4100 {D_STR_W_LEN ("042"), 3, 42}, 4101 {D_STR_W_LEN ("043"), 3, 43}, 4102 {D_STR_W_LEN ("044"), 3, 44}, 4103 {D_STR_W_LEN ("045"), 3, 45}, 4104 {D_STR_W_LEN ("046"), 3, 46}, 4105 {D_STR_W_LEN ("047"), 3, 47}, 4106 {D_STR_W_LEN ("048"), 3, 48}, 4107 {D_STR_W_LEN ("049"), 3, 49}, 4108 {D_STR_W_LEN ("050"), 3, 50}, 4109 {D_STR_W_LEN ("051"), 3, 51}, 4110 {D_STR_W_LEN ("052"), 3, 52}, 4111 {D_STR_W_LEN ("053"), 3, 53}, 4112 {D_STR_W_LEN ("054"), 3, 54}, 4113 {D_STR_W_LEN ("055"), 3, 55}, 4114 {D_STR_W_LEN ("056"), 3, 56}, 4115 {D_STR_W_LEN ("057"), 3, 57}, 4116 {D_STR_W_LEN ("058"), 3, 58}, 4117 {D_STR_W_LEN ("059"), 3, 59}, 4118 {D_STR_W_LEN ("060"), 3, 60}, 4119 {D_STR_W_LEN ("061"), 3, 61}, 4120 {D_STR_W_LEN ("062"), 3, 62}, 4121 {D_STR_W_LEN ("063"), 3, 63}, 4122 {D_STR_W_LEN ("064"), 3, 64}, 4123 {D_STR_W_LEN ("065"), 3, 65}, 4124 {D_STR_W_LEN ("066"), 3, 66}, 4125 {D_STR_W_LEN ("067"), 3, 67}, 4126 {D_STR_W_LEN ("068"), 3, 68}, 4127 {D_STR_W_LEN ("069"), 3, 69}, 4128 {D_STR_W_LEN ("070"), 3, 70}, 4129 {D_STR_W_LEN ("071"), 3, 71}, 4130 {D_STR_W_LEN ("072"), 3, 72}, 4131 {D_STR_W_LEN ("073"), 3, 73}, 4132 {D_STR_W_LEN ("074"), 3, 74}, 4133 {D_STR_W_LEN ("075"), 3, 75}, 4134 {D_STR_W_LEN ("076"), 3, 76}, 4135 {D_STR_W_LEN ("077"), 3, 77}, 4136 {D_STR_W_LEN ("078"), 3, 78}, 4137 {D_STR_W_LEN ("079"), 3, 79}, 4138 {D_STR_W_LEN ("080"), 3, 80}, 4139 {D_STR_W_LEN ("081"), 3, 81}, 4140 {D_STR_W_LEN ("082"), 3, 82}, 4141 {D_STR_W_LEN ("083"), 3, 83}, 4142 {D_STR_W_LEN ("084"), 3, 84}, 4143 {D_STR_W_LEN ("085"), 3, 85}, 4144 {D_STR_W_LEN ("086"), 3, 86}, 4145 {D_STR_W_LEN ("087"), 3, 87}, 4146 {D_STR_W_LEN ("088"), 3, 88}, 4147 {D_STR_W_LEN ("089"), 3, 89}, 4148 {D_STR_W_LEN ("090"), 3, 90}, 4149 {D_STR_W_LEN ("091"), 3, 91}, 4150 {D_STR_W_LEN ("092"), 3, 92}, 4151 {D_STR_W_LEN ("093"), 3, 93}, 4152 {D_STR_W_LEN ("094"), 3, 94}, 4153 {D_STR_W_LEN ("095"), 3, 95}, 4154 {D_STR_W_LEN ("096"), 3, 96}, 4155 {D_STR_W_LEN ("097"), 3, 97}, 4156 {D_STR_W_LEN ("098"), 3, 98}, 4157 {D_STR_W_LEN ("099"), 3, 99}, 4158 {D_STR_W_LEN ("100"), 3, 100}, 4159 {D_STR_W_LEN ("101"), 3, 101}, 4160 {D_STR_W_LEN ("102"), 3, 102}, 4161 {D_STR_W_LEN ("103"), 3, 103}, 4162 {D_STR_W_LEN ("104"), 3, 104}, 4163 {D_STR_W_LEN ("105"), 3, 105}, 4164 {D_STR_W_LEN ("106"), 3, 106}, 4165 {D_STR_W_LEN ("107"), 3, 107}, 4166 {D_STR_W_LEN ("108"), 3, 108}, 4167 {D_STR_W_LEN ("109"), 3, 109}, 4168 {D_STR_W_LEN ("110"), 3, 110}, 4169 {D_STR_W_LEN ("111"), 3, 111}, 4170 {D_STR_W_LEN ("112"), 3, 112}, 4171 {D_STR_W_LEN ("113"), 3, 113}, 4172 {D_STR_W_LEN ("114"), 3, 114}, 4173 {D_STR_W_LEN ("115"), 3, 115}, 4174 {D_STR_W_LEN ("116"), 3, 116}, 4175 {D_STR_W_LEN ("117"), 3, 117}, 4176 {D_STR_W_LEN ("118"), 3, 118}, 4177 {D_STR_W_LEN ("119"), 3, 119}, 4178 {D_STR_W_LEN ("120"), 3, 120}, 4179 {D_STR_W_LEN ("121"), 3, 121}, 4180 {D_STR_W_LEN ("122"), 3, 122}, 4181 {D_STR_W_LEN ("123"), 3, 123}, 4182 {D_STR_W_LEN ("124"), 3, 124}, 4183 {D_STR_W_LEN ("125"), 3, 125}, 4184 {D_STR_W_LEN ("126"), 3, 126}, 4185 {D_STR_W_LEN ("127"), 3, 127}, 4186 {D_STR_W_LEN ("128"), 3, 128}, 4187 {D_STR_W_LEN ("129"), 3, 129}, 4188 {D_STR_W_LEN ("130"), 3, 130}, 4189 {D_STR_W_LEN ("131"), 3, 131}, 4190 {D_STR_W_LEN ("132"), 3, 132}, 4191 {D_STR_W_LEN ("133"), 3, 133}, 4192 {D_STR_W_LEN ("134"), 3, 134}, 4193 {D_STR_W_LEN ("135"), 3, 135}, 4194 {D_STR_W_LEN ("136"), 3, 136}, 4195 {D_STR_W_LEN ("137"), 3, 137}, 4196 {D_STR_W_LEN ("138"), 3, 138}, 4197 {D_STR_W_LEN ("139"), 3, 139}, 4198 {D_STR_W_LEN ("140"), 3, 140}, 4199 {D_STR_W_LEN ("141"), 3, 141}, 4200 {D_STR_W_LEN ("142"), 3, 142}, 4201 {D_STR_W_LEN ("143"), 3, 143}, 4202 {D_STR_W_LEN ("144"), 3, 144}, 4203 {D_STR_W_LEN ("145"), 3, 145}, 4204 {D_STR_W_LEN ("146"), 3, 146}, 4205 {D_STR_W_LEN ("147"), 3, 147}, 4206 {D_STR_W_LEN ("148"), 3, 148}, 4207 {D_STR_W_LEN ("149"), 3, 149}, 4208 {D_STR_W_LEN ("150"), 3, 150}, 4209 {D_STR_W_LEN ("151"), 3, 151}, 4210 {D_STR_W_LEN ("152"), 3, 152}, 4211 {D_STR_W_LEN ("153"), 3, 153}, 4212 {D_STR_W_LEN ("154"), 3, 154}, 4213 {D_STR_W_LEN ("155"), 3, 155}, 4214 {D_STR_W_LEN ("156"), 3, 156}, 4215 {D_STR_W_LEN ("157"), 3, 157}, 4216 {D_STR_W_LEN ("158"), 3, 158}, 4217 {D_STR_W_LEN ("159"), 3, 159}, 4218 {D_STR_W_LEN ("160"), 3, 160}, 4219 {D_STR_W_LEN ("161"), 3, 161}, 4220 {D_STR_W_LEN ("162"), 3, 162}, 4221 {D_STR_W_LEN ("163"), 3, 163}, 4222 {D_STR_W_LEN ("164"), 3, 164}, 4223 {D_STR_W_LEN ("165"), 3, 165}, 4224 {D_STR_W_LEN ("166"), 3, 166}, 4225 {D_STR_W_LEN ("167"), 3, 167}, 4226 {D_STR_W_LEN ("168"), 3, 168}, 4227 {D_STR_W_LEN ("169"), 3, 169}, 4228 {D_STR_W_LEN ("170"), 3, 170}, 4229 {D_STR_W_LEN ("171"), 3, 171}, 4230 {D_STR_W_LEN ("172"), 3, 172}, 4231 {D_STR_W_LEN ("173"), 3, 173}, 4232 {D_STR_W_LEN ("174"), 3, 174}, 4233 {D_STR_W_LEN ("175"), 3, 175}, 4234 {D_STR_W_LEN ("176"), 3, 176}, 4235 {D_STR_W_LEN ("177"), 3, 177}, 4236 {D_STR_W_LEN ("178"), 3, 178}, 4237 {D_STR_W_LEN ("179"), 3, 179}, 4238 {D_STR_W_LEN ("180"), 3, 180}, 4239 {D_STR_W_LEN ("181"), 3, 181}, 4240 {D_STR_W_LEN ("182"), 3, 182}, 4241 {D_STR_W_LEN ("183"), 3, 183}, 4242 {D_STR_W_LEN ("184"), 3, 184}, 4243 {D_STR_W_LEN ("185"), 3, 185}, 4244 {D_STR_W_LEN ("186"), 3, 186}, 4245 {D_STR_W_LEN ("187"), 3, 187}, 4246 {D_STR_W_LEN ("188"), 3, 188}, 4247 {D_STR_W_LEN ("189"), 3, 189}, 4248 {D_STR_W_LEN ("190"), 3, 190}, 4249 {D_STR_W_LEN ("191"), 3, 191}, 4250 {D_STR_W_LEN ("192"), 3, 192}, 4251 {D_STR_W_LEN ("193"), 3, 193}, 4252 {D_STR_W_LEN ("194"), 3, 194}, 4253 {D_STR_W_LEN ("195"), 3, 195}, 4254 {D_STR_W_LEN ("196"), 3, 196}, 4255 {D_STR_W_LEN ("197"), 3, 197}, 4256 {D_STR_W_LEN ("198"), 3, 198}, 4257 {D_STR_W_LEN ("199"), 3, 199}, 4258 {D_STR_W_LEN ("200"), 3, 200}, 4259 {D_STR_W_LEN ("201"), 3, 201}, 4260 {D_STR_W_LEN ("202"), 3, 202}, 4261 {D_STR_W_LEN ("203"), 3, 203}, 4262 {D_STR_W_LEN ("204"), 3, 204}, 4263 {D_STR_W_LEN ("205"), 3, 205}, 4264 {D_STR_W_LEN ("206"), 3, 206}, 4265 {D_STR_W_LEN ("207"), 3, 207}, 4266 {D_STR_W_LEN ("208"), 3, 208}, 4267 {D_STR_W_LEN ("209"), 3, 209}, 4268 {D_STR_W_LEN ("210"), 3, 210}, 4269 {D_STR_W_LEN ("211"), 3, 211}, 4270 {D_STR_W_LEN ("212"), 3, 212}, 4271 {D_STR_W_LEN ("213"), 3, 213}, 4272 {D_STR_W_LEN ("214"), 3, 214}, 4273 {D_STR_W_LEN ("215"), 3, 215}, 4274 {D_STR_W_LEN ("216"), 3, 216}, 4275 {D_STR_W_LEN ("217"), 3, 217}, 4276 {D_STR_W_LEN ("218"), 3, 218}, 4277 {D_STR_W_LEN ("219"), 3, 219}, 4278 {D_STR_W_LEN ("220"), 3, 220}, 4279 {D_STR_W_LEN ("221"), 3, 221}, 4280 {D_STR_W_LEN ("222"), 3, 222}, 4281 {D_STR_W_LEN ("223"), 3, 223}, 4282 {D_STR_W_LEN ("224"), 3, 224}, 4283 {D_STR_W_LEN ("225"), 3, 225}, 4284 {D_STR_W_LEN ("226"), 3, 226}, 4285 {D_STR_W_LEN ("227"), 3, 227}, 4286 {D_STR_W_LEN ("228"), 3, 228}, 4287 {D_STR_W_LEN ("229"), 3, 229}, 4288 {D_STR_W_LEN ("230"), 3, 230}, 4289 {D_STR_W_LEN ("231"), 3, 231}, 4290 {D_STR_W_LEN ("232"), 3, 232}, 4291 {D_STR_W_LEN ("233"), 3, 233}, 4292 {D_STR_W_LEN ("234"), 3, 234}, 4293 {D_STR_W_LEN ("235"), 3, 235}, 4294 {D_STR_W_LEN ("236"), 3, 236}, 4295 {D_STR_W_LEN ("237"), 3, 237}, 4296 {D_STR_W_LEN ("238"), 3, 238}, 4297 {D_STR_W_LEN ("239"), 3, 239}, 4298 {D_STR_W_LEN ("240"), 3, 240}, 4299 {D_STR_W_LEN ("241"), 3, 241}, 4300 {D_STR_W_LEN ("242"), 3, 242}, 4301 {D_STR_W_LEN ("243"), 3, 243}, 4302 {D_STR_W_LEN ("244"), 3, 244}, 4303 {D_STR_W_LEN ("245"), 3, 245}, 4304 {D_STR_W_LEN ("246"), 3, 246}, 4305 {D_STR_W_LEN ("247"), 3, 247}, 4306 {D_STR_W_LEN ("248"), 3, 248}, 4307 {D_STR_W_LEN ("249"), 3, 249}, 4308 {D_STR_W_LEN ("250"), 3, 250}, 4309 {D_STR_W_LEN ("251"), 3, 251}, 4310 {D_STR_W_LEN ("252"), 3, 252}, 4311 {D_STR_W_LEN ("253"), 3, 253}, 4312 {D_STR_W_LEN ("254"), 3, 254}, 4313 {D_STR_W_LEN ("255"), 3, 255} 4314 }; 4315 4316 4317 static const struct str_with_value *duint8_w_values_p[3] = 4318 {duint8_w_values_p1, duint8_w_values_p2, duint8_w_values_p3}; 4319 4320 static size_t 4321 check_str_from_uint8_pad (void) 4322 { 4323 int i; 4324 uint8_t pad; 4325 size_t t_failed = 0; 4326 4327 if ((256 != sizeof(duint8_w_values_p1) / sizeof(duint8_w_values_p1[0])) || 4328 (256 != sizeof(duint8_w_values_p2) / sizeof(duint8_w_values_p2[0])) || 4329 (256 != sizeof(duint8_w_values_p3) / sizeof(duint8_w_values_p3[0]))) 4330 { 4331 fprintf (stderr, 4332 "ERROR: wrong number of items in duint8_w_values_p*.\n"); 4333 exit (99); 4334 } 4335 for (pad = 0; pad <= 3; pad++) 4336 { 4337 size_t table_num; 4338 if (0 != pad) 4339 table_num = pad - 1; 4340 else 4341 table_num = 0; 4342 4343 for (i = 0; i <= 255; i++) 4344 { 4345 const struct str_with_value *const t = duint8_w_values_p[table_num] + i; 4346 size_t b_size; 4347 size_t rs; 4348 char buf[8]; 4349 4350 if (t->str.len < t->num_of_digt) 4351 { 4352 fprintf (stderr, 4353 "ERROR: dstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" 4354 " to be less or equal to str.len (%u).\n", 4355 (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned 4356 int) t->str. 4357 len); 4358 exit (99); 4359 } 4360 if (sizeof(buf) < t->str.len + 1) 4361 { 4362 fprintf (stderr, 4363 "ERROR: dstrs_w_values[%u] has too long (%u) string, " 4364 "size of 'buf' should be increased.\n", 4365 (unsigned int) i, (unsigned int) t->str.len); 4366 exit (99); 4367 } 4368 for (b_size = 0; b_size <= t->str.len + 1; ++b_size) 4369 { 4370 /* fill buffer with pseudo-random values */ 4371 memset (buf, '#', sizeof(buf)); 4372 4373 rs = MHD_uint8_to_str_pad ((uint8_t) t->val, pad, buf, b_size); 4374 4375 if (t->num_of_digt > b_size) 4376 { 4377 /* Must fail, buffer is too small for result */ 4378 if (0 != rs) 4379 { 4380 t_failed++; 4381 fprintf (stderr, 4382 "FAILED: MHD_uint8_to_str_pad(%" PRIu64 ", %d, -> buf," 4383 " %d) returned %" PRIuPTR 4384 ", while expecting 0.\n", t->val, (int) pad, (int) b_size, 4385 (uintptr_t) rs); 4386 } 4387 } 4388 else 4389 { 4390 if (t->num_of_digt != rs) 4391 { 4392 t_failed++; 4393 fprintf (stderr, 4394 "FAILED: MHD_uint8_to_str_pad(%" PRIu64 ", %d, -> buf," 4395 " %d) returned %" PRIuPTR 4396 ", while expecting %d.\n", t->val, (int) pad, 4397 (int) b_size, (uintptr_t) rs, (int) t->num_of_digt); 4398 } 4399 else if (0 != memcmp (buf, t->str.str, t->num_of_digt)) 4400 { 4401 t_failed++; 4402 fprintf (stderr, 4403 "FAILED: MHD_uint8_to_str_pad(%" PRIu64 ", %d, " 4404 "-> \"%.*s\", %d) returned %" PRIuPTR ".\n", 4405 t->val, (int) pad, (int) rs, buf, 4406 (int) b_size, (uintptr_t) rs); 4407 } 4408 else if (0 != memcmp (buf + rs, "########", sizeof(buf) - rs)) 4409 { 4410 t_failed++; 4411 fprintf (stderr, 4412 "FAILED: MHD_uint8_to_str_pad(%" PRIu64 ", %d," 4413 " -> \"%.*s\", %d) returned %" PRIuPTR 4414 " and touched data after the resulting string.\n", 4415 t->val, (int) pad, (int) rs, buf, (int) b_size, 4416 (uintptr_t) rs); 4417 } 4418 } 4419 } 4420 } 4421 } 4422 if ((verbose > 1) && (0 == t_failed)) 4423 printf ("PASSED: MHD_uint8_to_str_pad.\n"); 4424 4425 return t_failed; 4426 } 4427 4428 4429 static int 4430 run_str_from_X_tests (void) 4431 { 4432 size_t str_from_uint16; 4433 size_t str_from_uint64; 4434 size_t strx_from_uint32; 4435 size_t str_from_uint8_pad; 4436 size_t failures; 4437 4438 failures = 0; 4439 4440 str_from_uint16 = check_str_from_uint16 (); 4441 if (str_from_uint16 != 0) 4442 { 4443 fprintf (stderr, 4444 "FAILED: testcase check_str_from_uint16() failed.\n\n"); 4445 failures += str_from_uint16; 4446 } 4447 else if (verbose > 1) 4448 printf ("PASSED: testcase check_str_from_uint16() successfully " 4449 "passed.\n\n"); 4450 4451 str_from_uint64 = check_str_from_uint64 (); 4452 if (str_from_uint64 != 0) 4453 { 4454 fprintf (stderr, 4455 "FAILED: testcase check_str_from_uint16() failed.\n\n"); 4456 failures += str_from_uint64; 4457 } 4458 else if (verbose > 1) 4459 printf ("PASSED: testcase check_str_from_uint16() successfully " 4460 "passed.\n\n"); 4461 strx_from_uint32 = check_strx_from_uint32 (); 4462 if (strx_from_uint32 != 0) 4463 { 4464 fprintf (stderr, 4465 "FAILED: testcase check_strx_from_uint32() failed.\n\n"); 4466 failures += strx_from_uint32; 4467 } 4468 else if (verbose > 1) 4469 printf ("PASSED: testcase check_strx_from_uint32() successfully " 4470 "passed.\n\n"); 4471 4472 str_from_uint8_pad = check_str_from_uint8_pad (); 4473 if (str_from_uint8_pad != 0) 4474 { 4475 fprintf (stderr, 4476 "FAILED: testcase check_str_from_uint8_pad() failed.\n\n"); 4477 failures += str_from_uint8_pad; 4478 } 4479 else if (verbose > 1) 4480 printf ("PASSED: testcase check_str_from_uint8_pad() successfully " 4481 "passed.\n\n"); 4482 4483 if (failures) 4484 { 4485 if (verbose > 0) 4486 printf ("At least one test failed.\n"); 4487 4488 return 1; 4489 } 4490 4491 if (verbose > 0) 4492 printf ("All tests passed successfully.\n"); 4493 4494 return 0; 4495 } 4496 4497 4498 int 4499 main (int argc, char *argv[]) 4500 { 4501 if (has_param (argc, argv, "-v") || has_param (argc, argv, "--verbose") || 4502 has_param (argc, argv, "--verbose1")) 4503 verbose = 1; 4504 if (has_param (argc, argv, "-vv") || has_param (argc, argv, "--verbose2")) 4505 verbose = 2; 4506 if (has_param (argc, argv, "-vvv") || has_param (argc, argv, "--verbose3")) 4507 verbose = 3; 4508 4509 if (has_in_name (argv[0], "_to_value")) 4510 return run_str_to_X_tests (); 4511 4512 if (has_in_name (argv[0], "_from_value")) 4513 return run_str_from_X_tests (); 4514 4515 return run_eq_neq_str_tests (); 4516 }