unit_str_to_value.c (86535B)
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 src/tests/unit/unit_str_test.h 22 * @brief Unit tests for mhd_str functions 23 * @author Karlson2k (Evgeny Grin) 24 */ 25 26 #include "mhd_sys_options.h" 27 28 #include <stdio.h> 29 #include <locale.h> 30 #include <string.h> 31 #ifdef HAVE_INTTYPES_H 32 # include <inttypes.h> 33 #else /* ! HAVE_INTTYPES_H */ 34 # define PRIuFAST64 "llu" 35 # define PRIuPTR "llu" 36 # define PRIXFAST64 "llX" 37 #endif /* ! HAVE_INTTYPES_H */ 38 #include <stdint.h> 39 #ifdef HAVE_STDLIB_H 40 # include <stdlib.h> 41 #endif /* HAVE_STDLIB_H */ 42 43 #include "mhd_str.h" 44 #include "mhd_str.c" 45 46 #include "mhdt_checks.h" 47 #include "mhdt_has_param.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 * Digits in string -> value tests 313 */ 314 315 struct str_with_value 316 { 317 const struct str_with_len str; 318 const size_t num_of_digt; 319 const uint_fast64_t val; 320 }; 321 322 /* valid string for conversion to unsigned integer value */ 323 static const struct str_with_value dstrs_w_values[] = { 324 /* simplest strings */ 325 {D_STR_W_LEN ("1"), 1, 1}, 326 {D_STR_W_LEN ("0"), 1, 0}, 327 {D_STR_W_LEN ("10000"), 5, 10000}, 328 329 /* all digits */ 330 {D_STR_W_LEN ("1234"), 4, 1234}, 331 {D_STR_W_LEN ("4567"), 4, 4567}, 332 {D_STR_W_LEN ("7890"), 4, 7890}, 333 {D_STR_W_LEN ("8021"), 4, 8021}, 334 {D_STR_W_LEN ("9754"), 4, 9754}, 335 {D_STR_W_LEN ("6392"), 4, 6392}, 336 337 /* various prefixes */ 338 {D_STR_W_LEN ("00000000"), 8, 0}, 339 {D_STR_W_LEN ("0755"), 4, 755}, /* not to be interpreted as octal value! */ 340 {D_STR_W_LEN ("002"), 3, 2}, 341 {D_STR_W_LEN ("0001"), 4, 1}, 342 {D_STR_W_LEN ("00000000000000000000000031295483"), 32, 31295483}, 343 344 /* numbers below and above limits */ 345 {D_STR_W_LEN ("127"), 3, 127}, /* 0x7F, SCHAR_MAX */ 346 {D_STR_W_LEN ("128"), 3, 128}, /* 0x80, SCHAR_MAX+1 */ 347 {D_STR_W_LEN ("255"), 3, 255}, /* 0xFF, UCHAR_MAX */ 348 {D_STR_W_LEN ("256"), 3, 256}, /* 0x100, UCHAR_MAX+1 */ 349 {D_STR_W_LEN ("32767"), 5, 32767}, /* 0x7FFF, INT16_MAX */ 350 {D_STR_W_LEN ("32768"), 5, 32768}, /* 0x8000, INT16_MAX+1 */ 351 {D_STR_W_LEN ("65535"), 5, 65535}, /* 0xFFFF, UINT16_MAX */ 352 {D_STR_W_LEN ("65536"), 5, 65536}, /* 0x10000, UINT16_MAX+1 */ 353 {D_STR_W_LEN ("2147483647"), 10, 2147483647}, /* 0x7FFFFFFF, INT32_MAX */ 354 {D_STR_W_LEN ("2147483648"), 10, UINT64_C (2147483648)}, /* 0x80000000, INT32_MAX+1 */ 355 {D_STR_W_LEN ("4294967295"), 10, UINT64_C (4294967295)}, /* 0xFFFFFFFF, UINT32_MAX */ 356 {D_STR_W_LEN ("4294967296"), 10, UINT64_C (4294967296)}, /* 0x100000000, UINT32_MAX+1 */ 357 {D_STR_W_LEN ("9223372036854775807"), 19, UINT64_C (9223372036854775807)}, /* 0x7FFFFFFFFFFFFFFF, INT64_MAX */ 358 {D_STR_W_LEN ("9223372036854775808"), 19, UINT64_C (9223372036854775808)}, /* 0x8000000000000000, INT64_MAX+1 */ 359 {D_STR_W_LEN ("18446744073709551615"), 20, UINT64_C (18446744073709551615)}, /* 0xFFFFFFFFFFFFFFFF, UINT64_MAX */ 360 361 /* random numbers */ 362 {D_STR_W_LEN ("10186753"), 8, 10186753}, 363 {D_STR_W_LEN ("144402566"), 9, 144402566}, 364 {D_STR_W_LEN ("151903144"), 9, 151903144}, 365 {D_STR_W_LEN ("139264621"), 9, 139264621}, 366 {D_STR_W_LEN ("730348"), 6, 730348}, 367 {D_STR_W_LEN ("21584377"), 8, 21584377}, 368 {D_STR_W_LEN ("709"), 3, 709}, 369 {D_STR_W_LEN ("54"), 2, 54}, 370 {D_STR_W_LEN ("8452"), 4, 8452}, 371 {D_STR_W_LEN ("17745098750013624977"), 20, UINT64_C (17745098750013624977)}, 372 {D_STR_W_LEN ("06786878769931678000"), 20, UINT64_C (6786878769931678000)}, 373 374 /* non-digit suffixes */ 375 {D_STR_W_LEN ("1234oa"), 4, 1234}, 376 {D_STR_W_LEN ("20h"), 2, 20}, /* not to be interpreted as hex value! */ 377 {D_STR_W_LEN ("0x1F"), 1, 0}, /* not to be interpreted as hex value! */ 378 {D_STR_W_LEN ("0564`~}"), 4, 564}, 379 {D_STR_W_LEN ("7240146.724"), 7, 7240146}, 380 {D_STR_W_LEN ("2,9"), 1, 2}, 381 {D_STR_W_LEN ("200+1"), 3, 200}, 382 {D_STR_W_LEN ("1a"), 1, 1}, 383 {D_STR_W_LEN ("2E"), 1, 2}, 384 {D_STR_W_LEN ("6c"), 1, 6}, 385 {D_STR_W_LEN ("8F"), 1, 8}, 386 {D_STR_W_LEN ("287416997! And the not too long string."), 9, 287416997} 387 }; 388 389 /* strings that should overflow uint64_t */ 390 static const struct str_with_len str_ovflw[] = { 391 D_STR_W_LEN ("18446744073709551616"), /* 0x10000000000000000, UINT64_MAX+1 */ 392 D_STR_W_LEN ("18446744073709551620"), 393 D_STR_W_LEN ("18446744083709551615"), 394 D_STR_W_LEN ("19234761020556472143"), 395 D_STR_W_LEN ("184467440737095516150"), 396 D_STR_W_LEN ("1844674407370955161500"), 397 D_STR_W_LEN ("000018446744073709551616"), /* 0x10000000000000000, UINT64_MAX+1 */ 398 D_STR_W_LEN ("20000000000000000000"), 399 D_STR_W_LEN ("020000000000000000000"), 400 D_STR_W_LEN ("0020000000000000000000"), 401 D_STR_W_LEN ("100000000000000000000"), 402 D_STR_W_LEN ("434532891232591226417"), 403 D_STR_W_LEN ("99999999999999999999"), 404 D_STR_W_LEN ("18446744073709551616abcd"), /* 0x10000000000000000, UINT64_MAX+1 */ 405 D_STR_W_LEN ("20000000000000000000 suffix"), 406 D_STR_W_LEN ("020000000000000000000x") 407 }; 408 409 /* strings that should not be convertible to numeric value */ 410 static const struct str_with_len str_no_num[] = { 411 D_STR_W_LEN ("zero"), 412 D_STR_W_LEN ("one"), 413 D_STR_W_LEN ("\xb9\xb2\xb3"), /* superscript "123" in ISO-8859-1/CP1252 */ 414 D_STR_W_LEN ("\xc2\xb9\xc2\xb2\xc2\xb3"), /* superscript "123" in UTF-8 */ 415 D_STR_W_LEN ("\xd9\xa1\xd9\xa2\xd9\xa3"), /* Arabic-Indic "١٢٣" in UTF-8 */ 416 D_STR_W_LEN ("\xdb\xb1\xdb\xb2\xdb\xb3"), /* Ext Arabic-Indic "۱۲۳" in UTF-8 */ 417 D_STR_W_LEN ("\xe0\xa5\xa7\xe0\xa5\xa8\xe0\xa5\xa9"), /* Devanagari "१२३" in UTF-8 */ 418 D_STR_W_LEN ("\xe4\xb8\x80\xe4\xba\x8c\xe4\xb8\x89"), /* Chinese "一二三" in UTF-8 */ 419 D_STR_W_LEN ("\xd2\xbb\xb6\xfe\xc8\xfd"), /* Chinese "一二三" in GB2312/CP936 */ 420 D_STR_W_LEN ("\x1B\x24\x29\x41\x0E\x52\x3B\x36\x7E\x48\x7D\x0F") /* Chinese "一二三" in ISO-2022-CN */ 421 }; 422 423 /* valid hex string for conversion to unsigned integer value */ 424 static const struct str_with_value xdstrs_w_values[] = { 425 /* simplest strings */ 426 {D_STR_W_LEN ("1"), 1, 0x1}, 427 {D_STR_W_LEN ("0"), 1, 0x0}, 428 {D_STR_W_LEN ("10000"), 5, 0x10000}, 429 430 /* all digits */ 431 {D_STR_W_LEN ("1234"), 4, 0x1234}, 432 {D_STR_W_LEN ("4567"), 4, 0x4567}, 433 {D_STR_W_LEN ("7890"), 4, 0x7890}, 434 {D_STR_W_LEN ("8021"), 4, 0x8021}, 435 {D_STR_W_LEN ("9754"), 4, 0x9754}, 436 {D_STR_W_LEN ("6392"), 4, 0x6392}, 437 {D_STR_W_LEN ("abcd"), 4, 0xABCD}, 438 {D_STR_W_LEN ("cdef"), 4, 0xCDEF}, 439 {D_STR_W_LEN ("FEAB"), 4, 0xFEAB}, 440 {D_STR_W_LEN ("BCED"), 4, 0xBCED}, 441 {D_STR_W_LEN ("bCeD"), 4, 0xBCED}, 442 {D_STR_W_LEN ("1A5F"), 4, 0x1A5F}, 443 {D_STR_W_LEN ("12AB"), 4, 0x12AB}, 444 {D_STR_W_LEN ("CD34"), 4, 0xCD34}, 445 {D_STR_W_LEN ("56EF"), 4, 0x56EF}, 446 {D_STR_W_LEN ("7a9f"), 4, 0x7A9F}, 447 448 /* various prefixes */ 449 {D_STR_W_LEN ("00000000"), 8, 0x0}, 450 {D_STR_W_LEN ("0755"), 4, 0x755}, /* not to be interpreted as octal value! */ 451 {D_STR_W_LEN ("002"), 3, 0x2}, 452 {D_STR_W_LEN ("0001"), 4, 0x1}, 453 {D_STR_W_LEN ("00a"), 3, 0xA}, 454 {D_STR_W_LEN ("0F"), 2, 0xF}, 455 {D_STR_W_LEN ("0000000000000000000000003A29e4C3"), 32, 0x3A29E4C3}, 456 457 /* numbers below and above limits */ 458 {D_STR_W_LEN ("7F"), 2, 127}, /* 0x7F, SCHAR_MAX */ 459 {D_STR_W_LEN ("7f"), 2, 127}, /* 0x7F, SCHAR_MAX */ 460 {D_STR_W_LEN ("80"), 2, 128}, /* 0x80, SCHAR_MAX+1 */ 461 {D_STR_W_LEN ("fF"), 2, 255}, /* 0xFF, UCHAR_MAX */ 462 {D_STR_W_LEN ("Ff"), 2, 255}, /* 0xFF, UCHAR_MAX */ 463 {D_STR_W_LEN ("FF"), 2, 255}, /* 0xFF, UCHAR_MAX */ 464 {D_STR_W_LEN ("ff"), 2, 255}, /* 0xFF, UCHAR_MAX */ 465 {D_STR_W_LEN ("100"), 3, 256}, /* 0x100, UCHAR_MAX+1 */ 466 {D_STR_W_LEN ("7fff"), 4, 32767}, /* 0x7FFF, INT16_MAX */ 467 {D_STR_W_LEN ("7FFF"), 4, 32767}, /* 0x7FFF, INT16_MAX */ 468 {D_STR_W_LEN ("7Fff"), 4, 32767}, /* 0x7FFF, INT16_MAX */ 469 {D_STR_W_LEN ("8000"), 4, 32768}, /* 0x8000, INT16_MAX+1 */ 470 {D_STR_W_LEN ("ffff"), 4, 65535}, /* 0xFFFF, UINT16_MAX */ 471 {D_STR_W_LEN ("FFFF"), 4, 65535}, /* 0xFFFF, UINT16_MAX */ 472 {D_STR_W_LEN ("FffF"), 4, 65535}, /* 0xFFFF, UINT16_MAX */ 473 {D_STR_W_LEN ("10000"), 5, 65536}, /* 0x10000, UINT16_MAX+1 */ 474 {D_STR_W_LEN ("7FFFFFFF"), 8, 2147483647}, /* 0x7FFFFFFF, INT32_MAX */ 475 {D_STR_W_LEN ("7fffffff"), 8, 2147483647}, /* 0x7FFFFFFF, INT32_MAX */ 476 {D_STR_W_LEN ("7FFffFff"), 8, 2147483647}, /* 0x7FFFFFFF, INT32_MAX */ 477 {D_STR_W_LEN ("80000000"), 8, UINT64_C (2147483648)}, /* 0x80000000, INT32_MAX+1 */ 478 {D_STR_W_LEN ("FFFFFFFF"), 8, UINT64_C (4294967295)}, /* 0xFFFFFFFF, UINT32_MAX */ 479 {D_STR_W_LEN ("ffffffff"), 8, UINT64_C (4294967295)}, /* 0xFFFFFFFF, UINT32_MAX */ 480 {D_STR_W_LEN ("FfFfFfFf"), 8, UINT64_C (4294967295)}, /* 0xFFFFFFFF, UINT32_MAX */ 481 {D_STR_W_LEN ("100000000"), 9, UINT64_C (4294967296)}, /* 0x100000000, UINT32_MAX+1 */ 482 {D_STR_W_LEN ("7fffffffffffffff"), 16, UINT64_C (9223372036854775807)}, /* 0x7FFFFFFFFFFFFFFF, INT64_MAX */ 483 {D_STR_W_LEN ("7FFFFFFFFFFFFFFF"), 16, UINT64_C (9223372036854775807)}, /* 0x7FFFFFFFFFFFFFFF, INT64_MAX */ 484 {D_STR_W_LEN ("7FfffFFFFffFFffF"), 16, UINT64_C (9223372036854775807)}, /* 0x7FFFFFFFFFFFFFFF, INT64_MAX */ 485 {D_STR_W_LEN ("8000000000000000"), 16, UINT64_C (9223372036854775808)}, /* 0x8000000000000000, INT64_MAX+1 */ 486 {D_STR_W_LEN ("ffffffffffffffff"), 16, UINT64_C (18446744073709551615)}, /* 0xFFFFFFFFFFFFFFFF, UINT64_MAX */ 487 {D_STR_W_LEN ("FFFFFFFFFFFFFFFF"), 16, UINT64_C (18446744073709551615)}, /* 0xFFFFFFFFFFFFFFFF, UINT64_MAX */ 488 {D_STR_W_LEN ("FffFffFFffFFfFFF"), 16, UINT64_C (18446744073709551615)}, /* 0xFFFFFFFFFFFFFFFF, UINT64_MAX */ 489 490 /* random numbers */ 491 {D_STR_W_LEN ("10186753"), 8, 0x10186753}, 492 {D_STR_W_LEN ("144402566"), 9, 0x144402566}, 493 {D_STR_W_LEN ("151903144"), 9, 0x151903144}, 494 {D_STR_W_LEN ("139264621"), 9, 0x139264621}, 495 {D_STR_W_LEN ("730348"), 6, 0x730348}, 496 {D_STR_W_LEN ("21584377"), 8, 0x21584377}, 497 {D_STR_W_LEN ("709"), 3, 0x709}, 498 {D_STR_W_LEN ("54"), 2, 0x54}, 499 {D_STR_W_LEN ("8452"), 4, 0x8452}, 500 {D_STR_W_LEN ("22353EC6"), 8, 0x22353EC6}, 501 {D_STR_W_LEN ("307F1655"), 8, 0x307F1655}, 502 {D_STR_W_LEN ("1FCB7226"), 8, 0x1FCB7226}, 503 {D_STR_W_LEN ("82480560"), 8, 0x82480560}, 504 {D_STR_W_LEN ("7386D95"), 7, 0x7386D95}, 505 {D_STR_W_LEN ("EC3AB"), 5, 0xEC3AB}, 506 {D_STR_W_LEN ("6DD05"), 5, 0x6DD05}, 507 {D_STR_W_LEN ("C5DF"), 4, 0xC5DF}, 508 {D_STR_W_LEN ("6CE"), 3, 0x6CE}, 509 {D_STR_W_LEN ("CE6"), 3, 0xCE6}, 510 {D_STR_W_LEN ("ce6"), 3, 0xCE6}, 511 {D_STR_W_LEN ("F27"), 3, 0xF27}, 512 {D_STR_W_LEN ("8497D54277D7E1"), 14, UINT64_C (37321639124785121)}, 513 {D_STR_W_LEN ("8497d54277d7e1"), 14, UINT64_C (37321639124785121)}, 514 {D_STR_W_LEN ("8497d54277d7E1"), 14, UINT64_C (37321639124785121)}, 515 {D_STR_W_LEN ("8C8112D0A06"), 11, UINT64_C (9655374645766)}, 516 {D_STR_W_LEN ("8c8112d0a06"), 11, UINT64_C (9655374645766)}, 517 {D_STR_W_LEN ("8c8112d0A06"), 11, UINT64_C (9655374645766)}, 518 {D_STR_W_LEN ("1774509875001362"), 16, UINT64_C (1690064375898968930)}, 519 {D_STR_W_LEN ("0678687876998000"), 16, UINT64_C (466237428027981824)}, 520 521 /* non-digit suffixes */ 522 {D_STR_W_LEN ("1234oa"), 4, 0x1234}, 523 {D_STR_W_LEN ("20h"), 2, 0x20}, 524 {D_STR_W_LEN ("2CH"), 2, 0x2C}, 525 {D_STR_W_LEN ("2ch"), 2, 0x2C}, 526 {D_STR_W_LEN ("0x1F"), 1, 0x0}, /* not to be interpreted as hex prefix! */ 527 {D_STR_W_LEN ("0564`~}"), 4, 0x564}, 528 {D_STR_W_LEN ("0A64`~}"), 4, 0xA64}, 529 {D_STR_W_LEN ("056c`~}"), 4, 0X56C}, 530 {D_STR_W_LEN ("7240146.724"), 7, 0x7240146}, 531 {D_STR_W_LEN ("7E4c1AB.724"), 7, 0X7E4C1AB}, 532 {D_STR_W_LEN ("F24B1B6.724"), 7, 0xF24B1B6}, 533 {D_STR_W_LEN ("2,9"), 1, 0x2}, 534 {D_STR_W_LEN ("a,9"), 1, 0xA}, 535 {D_STR_W_LEN ("200+1"), 3, 0x200}, 536 {D_STR_W_LEN ("2cc+1"), 3, 0x2CC}, 537 {D_STR_W_LEN ("2cC+1"), 3, 0x2CC}, 538 {D_STR_W_LEN ("27416997! And the not too long string."), 8, 0x27416997}, 539 {D_STR_W_LEN ("27555416997! And the not too long string."), 11, 540 0x27555416997}, 541 {D_STR_W_LEN ("416997And the not too long string."), 7, 0x416997A}, 542 {D_STR_W_LEN ("0F4C3Dabstract addition to make string even longer"), 8, 543 0xF4C3DAB} 544 }; 545 546 /* hex strings that should overflow uint64_t */ 547 static const struct str_with_len strx_ovflw[] = { 548 D_STR_W_LEN ("10000000000000000"), /* 0x10000000000000000, UINT64_MAX+1 */ 549 D_STR_W_LEN ("10000000000000001"), 550 D_STR_W_LEN ("10000000000000002"), 551 D_STR_W_LEN ("1000000000000000A"), 552 D_STR_W_LEN ("11000000000000000"), 553 D_STR_W_LEN ("010000000000000000"), /* 0x10000000000000000, UINT64_MAX+1 */ 554 D_STR_W_LEN ("000010000000000000000"), /* 0x10000000000000000, UINT64_MAX+1 */ 555 D_STR_W_LEN ("20000000000000000000"), 556 D_STR_W_LEN ("020000000000000000000"), 557 D_STR_W_LEN ("0020000000000000000000"), 558 D_STR_W_LEN ("20000000000000000"), 559 D_STR_W_LEN ("A0000000000000000"), 560 D_STR_W_LEN ("F0000000000000000"), 561 D_STR_W_LEN ("a0000000000000000"), 562 D_STR_W_LEN ("11111111111111111"), 563 D_STR_W_LEN ("CcCcCCccCCccCCccC"), 564 D_STR_W_LEN ("f0000000000000000"), 565 D_STR_W_LEN ("100000000000000000000"), 566 D_STR_W_LEN ("434532891232591226417"), 567 D_STR_W_LEN ("10000000000000000a"), 568 D_STR_W_LEN ("10000000000000000E"), 569 D_STR_W_LEN ("100000000000000000 and nothing"), /* 0x10000000000000000, UINT64_MAX+1 */ 570 D_STR_W_LEN ("100000000000000000xx"), /* 0x10000000000000000, UINT64_MAX+1 */ 571 D_STR_W_LEN ("99999999999999999999"), 572 D_STR_W_LEN ("18446744073709551616abcd"), 573 D_STR_W_LEN ("20000000000000000000 suffix"), 574 D_STR_W_LEN ("020000000000000000000x") 575 }; 576 577 578 static size_t 579 check_str_to_uint64_valid (void) 580 { 581 size_t t_failed = 0; 582 size_t i, j; 583 int c_failed[sizeof(dstrs_w_values) 584 / sizeof(dstrs_w_values[0])]; 585 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 586 587 memset (c_failed, 0, sizeof(c_failed)); 588 589 for (j = 0; j < locale_name_count; j++) 590 { 591 set_test_locale (j); /* setlocale() can be slow! */ 592 for (i = 0; i < n_checks; i++) 593 { 594 uint_fast64_t rv; 595 size_t rs; 596 const struct str_with_value *const t = dstrs_w_values + i; 597 598 if (c_failed[i]) 599 continue; /* skip already failed checks */ 600 601 if (t->str.len < t->num_of_digt) 602 { 603 fprintf (stderr, 604 "ERROR: dstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" 605 " to be less or equal to str.len (%u).\n", 606 (unsigned int)i, 607 (unsigned int)t->num_of_digt, 608 (unsigned 609 int)t->str. 610 len); 611 exit (99); 612 } 613 rv = 9435223; /* some random value */ 614 rs = mhd_str_to_uint64 (t->str.str, &rv); 615 if (rs != t->num_of_digt) 616 { 617 t_failed++; 618 c_failed[i] = !0; 619 fprintf (stderr, 620 "FAILED: mhd_str_to_uint64(\"%s\", ->%" PRIuFAST64 621 ") returned %" 622 PRIuPTR 623 ", while expecting %d." 624 " Locale: %s\n", n_prnt (t->str.str), rv, (uintptr_t)rs, 625 (int)t->num_of_digt, get_current_locale_str ()); 626 } 627 if (rv != t->val) 628 { 629 t_failed++; 630 c_failed[i] = !0; 631 fprintf (stderr, 632 "FAILED: mhd_str_to_uint64(\"%s\", ->%" PRIuFAST64 633 ") converted string to value %" 634 PRIuFAST64 "," 635 " while expecting result %" PRIuFAST64 ". Locale: %s\n", 636 n_prnt (t->str.str), rv, rv, 637 t->val, get_current_locale_str ()); 638 } 639 if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) 640 printf ("PASSED: mhd_str_to_uint64(\"%s\", ->%" PRIuFAST64 ") == %" \ 641 PRIuPTR "\n", 642 n_prnt (t->str.str), rv, rs); 643 } 644 } 645 return t_failed; 646 } 647 648 649 static size_t 650 check_str_to_uint64_all_chars (void) 651 { 652 int c_failed[256]; /* from 0 to 255 */ 653 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 654 size_t t_failed = 0; 655 size_t j; 656 657 memset (c_failed, 0, sizeof(c_failed)); 658 659 for (j = 0; j < locale_name_count; j++) 660 { 661 unsigned int c; 662 uint_fast64_t test_val; 663 664 set_test_locale (j); /* setlocale() can be slow! */ 665 for (c = 0; c < n_checks; c++) 666 { 667 static const uint_fast64_t rnd_val = 24941852; 668 size_t rs; 669 if ((c >= '0') && (c <= '9')) 670 continue; /* skip digits */ 671 for (test_val = 0; test_val <= rnd_val && !c_failed[c]; test_val += 672 rnd_val) 673 { 674 char test_str[] = "0123"; 675 uint_fast64_t rv = test_val; 676 677 test_str[0] = (char)(unsigned char)c; /* replace first char with non-digit char */ 678 rs = mhd_str_to_uint64 (test_str, &rv); 679 if (rs != 0) 680 { 681 t_failed++; 682 c_failed[c] = !0; 683 fprintf (stderr, 684 "FAILED: mhd_str_to_uint64(\"%s\", ->%" PRIuFAST64 685 ") returned %" PRIuPTR 686 ", while expecting zero." 687 " Locale: %s\n", n_prnt (test_str), rv, (uintptr_t)rs, 688 get_current_locale_str ()); 689 } 690 else if (rv != test_val) 691 { 692 t_failed++; 693 c_failed[c] = !0; 694 fprintf (stderr, 695 "FAILED: mhd_str_to_uint64(\"%s\", &ret_val) modified value of ret_val" 696 " (before call: %" PRIuFAST64 ", after call %" PRIuFAST64 697 "). Locale: %s\n", 698 n_prnt (test_str), 699 test_val, 700 rv, 701 get_current_locale_str ()); 702 } 703 } 704 if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[c]) 705 { 706 char test_str[] = "0123"; 707 test_str[0] = (char)(unsigned char)c; /* replace first char with non-digit char */ 708 709 printf ("PASSED: mhd_str_to_uint64(\"%s\", &ret_val) == 0, " 710 "value of ret_val is unmodified\n", 711 n_prnt (test_str)); 712 } 713 } 714 } 715 return t_failed; 716 } 717 718 719 static size_t 720 check_str_to_uint64_overflow (void) 721 { 722 size_t t_failed = 0; 723 size_t i, j; 724 int c_failed[sizeof(str_ovflw) / sizeof(str_ovflw[0])]; 725 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 726 727 memset (c_failed, 0, sizeof(c_failed)); 728 729 for (j = 0; j < locale_name_count; j++) 730 { 731 set_test_locale (j); /* setlocale() can be slow! */ 732 for (i = 0; i < n_checks; i++) 733 { 734 size_t rs; 735 const struct str_with_len *const t = str_ovflw + i; 736 static const uint_fast64_t rnd_val = 2; 737 uint_fast64_t test_val; 738 739 for (test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += 740 rnd_val) 741 { 742 uint_fast64_t rv = test_val; 743 744 rs = mhd_str_to_uint64 (t->str, &rv); 745 if (rs != 0) 746 { 747 t_failed++; 748 c_failed[i] = !0; 749 fprintf (stderr, 750 "FAILED: mhd_str_to_uint64(\"%s\", ->%" PRIuFAST64 751 ") returned %" PRIuPTR 752 ", while expecting zero." 753 " Locale: %s\n", n_prnt (t->str), rv, (uintptr_t)rs, 754 get_current_locale_str ()); 755 } 756 else if (rv != test_val) 757 { 758 t_failed++; 759 c_failed[i] = !0; 760 fprintf (stderr, 761 "FAILED: mhd_str_to_uint64(\"%s\", &ret_val) modified value of ret_val" 762 " (before call: %" PRIuFAST64 ", after call %" PRIuFAST64 763 "). Locale: %s\n", 764 n_prnt (t->str), 765 test_val, 766 rv, 767 get_current_locale_str ()); 768 } 769 } 770 if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) 771 printf ("PASSED: mhd_str_to_uint64(\"%s\", &ret_val) == 0, " 772 "value of ret_val is unmodified\n", 773 n_prnt (t->str)); 774 } 775 } 776 return t_failed; 777 } 778 779 780 static size_t 781 check_str_to_uint64_no_val (void) 782 { 783 size_t t_failed = 0; 784 size_t i, j; 785 int c_failed[sizeof(str_no_num) / sizeof(str_no_num[0])]; 786 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 787 788 memset (c_failed, 0, sizeof(c_failed)); 789 790 for (j = 0; j < locale_name_count; j++) 791 { 792 set_test_locale (j); /* setlocale() can be slow! */ 793 for (i = 0; i < n_checks; i++) 794 { 795 size_t rs; 796 const struct str_with_len *const t = str_no_num + i; 797 static const uint_fast64_t rnd_val = 74218431; 798 uint_fast64_t test_val; 799 800 for (test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += 801 rnd_val) 802 { 803 uint_fast64_t rv = test_val; 804 805 rs = mhd_str_to_uint64 (t->str, &rv); 806 if (rs != 0) 807 { 808 t_failed++; 809 c_failed[i] = !0; 810 fprintf (stderr, 811 "FAILED: mhd_str_to_uint64(\"%s\", ->%" PRIuFAST64 812 ") returned %" PRIuPTR 813 ", while expecting zero." 814 " Locale: %s\n", n_prnt (t->str), rv, (uintptr_t)rs, 815 get_current_locale_str ()); 816 } 817 else if (rv != test_val) 818 { 819 t_failed++; 820 c_failed[i] = !0; 821 fprintf (stderr, 822 "FAILED: mhd_str_to_uint64(\"%s\", &ret_val) modified value of ret_val" 823 " (before call: %" PRIuFAST64 ", after call %" PRIuFAST64 824 "). Locale: %s\n", 825 n_prnt (t->str), 826 test_val, 827 rv, 828 get_current_locale_str ()); 829 } 830 } 831 if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) 832 printf ("PASSED: mhd_str_to_uint64(\"%s\", &ret_val) == 0, " 833 "value of ret_val is unmodified\n", 834 n_prnt (t->str)); 835 } 836 } 837 return t_failed; 838 } 839 840 841 static size_t 842 check_str_to_uint64_n_valid (void) 843 { 844 size_t t_failed = 0; 845 size_t i, j; 846 int c_failed[sizeof(dstrs_w_values) 847 / sizeof(dstrs_w_values[0])]; 848 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 849 850 memset (c_failed, 0, sizeof(c_failed)); 851 852 for (j = 0; j < locale_name_count; j++) 853 { 854 set_test_locale (j); /* setlocale() can be slow! */ 855 for (i = 0; i < n_checks; i++) 856 { 857 uint_fast64_t rv = 1235572; /* some random value */ 858 size_t rs = 0; 859 size_t len; 860 const struct str_with_value *const t = dstrs_w_values + i; 861 862 if (t->str.len < t->num_of_digt) 863 { 864 fprintf (stderr, 865 "ERROR: dstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" 866 " to be less or equal to str.len (%u).\n", 867 (unsigned int)i, 868 (unsigned int)t->num_of_digt, 869 (unsigned 870 int)t->str. 871 len); 872 exit (99); 873 } 874 for (len = t->num_of_digt; len <= t->str.len + 1 && !c_failed[i]; len++) 875 { 876 rs = mhd_str_to_uint64_n (t->str.str, len, &rv); 877 if (rs != t->num_of_digt) 878 { 879 t_failed++; 880 c_failed[i] = !0; 881 fprintf (stderr, 882 "FAILED: mhd_str_to_uint64_n(\"%s\", %" PRIuPTR ", ->%" 883 PRIuFAST64 ")" 884 " returned %" PRIuPTR ", while expecting %d. Locale: %s\n", 885 n_prnt (t->str.str), (uintptr_t)len, rv, (uintptr_t)rs, 886 (int)t->num_of_digt, get_current_locale_str ()); 887 } 888 if (rv != t->val) 889 { 890 t_failed++; 891 c_failed[i] = !0; 892 fprintf (stderr, 893 "FAILED: mhd_str_to_uint64_n(\"%s\", %" PRIuPTR ", ->%" 894 PRIuFAST64 ")" 895 " converted string to value %" PRIuFAST64 896 ", while expecting result %" PRIuFAST64 897 ". Locale: %s\n", n_prnt (t->str.str), (uintptr_t)len, rv, 898 rv, 899 t->val, get_current_locale_str ()); 900 } 901 } 902 if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) 903 printf ("PASSED: mhd_str_to_uint64_n(\"%s\", %" PRIuPTR "..%" 904 PRIuPTR ", ->%" PRIuFAST64 ")" " == %" PRIuPTR "\n", 905 n_prnt (t->str.str), 906 (uintptr_t)t->num_of_digt, 907 (uintptr_t)t->str.len + 1, rv, rs); 908 } 909 } 910 return t_failed; 911 } 912 913 914 static size_t 915 check_str_to_uint64_n_all_chars (void) 916 { 917 int c_failed[256]; /* from 0 to 255 */ 918 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 919 size_t t_failed = 0; 920 size_t j; 921 922 memset (c_failed, 0, sizeof(c_failed)); 923 924 for (j = 0; j < locale_name_count; j++) 925 { 926 unsigned int c; 927 uint_fast64_t test_val; 928 929 set_test_locale (j); /* setlocale() can be slow! */ 930 for (c = 0; c < n_checks; c++) 931 { 932 static const uint_fast64_t rnd_val = 98372558; 933 size_t rs; 934 size_t len; 935 936 if ((c >= '0') && (c <= '9')) 937 continue; /* skip digits */ 938 939 for (len = 0; len <= 5; len++) 940 { 941 for (test_val = 0; test_val <= rnd_val && !c_failed[c]; test_val += 942 rnd_val) 943 { 944 char test_str[] = "0123"; 945 uint_fast64_t rv = test_val; 946 947 test_str[0] = (char)(unsigned char)c; /* replace first char with non-digit char */ 948 rs = mhd_str_to_uint64_n (test_str, len, &rv); 949 if (rs != 0) 950 { 951 t_failed++; 952 c_failed[c] = !0; 953 fprintf (stderr, 954 "FAILED: mhd_str_to_uint64_n(\"%s\", %" PRIuPTR ", ->%" 955 PRIuFAST64 ")" 956 " returned %" PRIuPTR 957 ", while expecting zero. Locale: %s\n", 958 n_prnt (test_str), (uintptr_t)len, rv, (uintptr_t)rs, 959 get_current_locale_str ()); 960 } 961 else if (rv != test_val) 962 { 963 t_failed++; 964 c_failed[c] = !0; 965 fprintf (stderr, 966 "FAILED: mhd_str_to_uint64_n(\"%s\", %" PRIuPTR 967 ", &ret_val)" 968 " modified value of ret_val (before call: %" PRIuFAST64 969 ", after call %" PRIuFAST64 ")." 970 " Locale: %s\n", 971 n_prnt (test_str), (uintptr_t)len, test_val, rv, 972 get_current_locale_str ()); 973 } 974 } 975 } 976 if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[c]) 977 { 978 char test_str[] = "0123"; 979 test_str[0] = (char)(unsigned char)c; /* replace first char with non-digit char */ 980 981 printf ("PASSED: mhd_str_to_uint64_n(\"%s\", 0..5, &ret_val) == 0, " 982 "value of ret_val is unmodified\n", 983 n_prnt (test_str)); 984 } 985 } 986 } 987 return t_failed; 988 } 989 990 991 static size_t 992 check_str_to_uint64_n_overflow (void) 993 { 994 size_t t_failed = 0; 995 size_t i, j; 996 int c_failed[sizeof(str_ovflw) / sizeof(str_ovflw[0])]; 997 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 998 999 memset (c_failed, 0, sizeof(c_failed)); 1000 1001 for (j = 0; j < locale_name_count; j++) 1002 { 1003 set_test_locale (j); /* setlocale() can be slow! */ 1004 for (i = 0; i < n_checks; i++) 1005 { 1006 size_t rs; 1007 const struct str_with_len *const t = str_ovflw + i; 1008 static const uint_fast64_t rnd_val = 3; 1009 size_t len; 1010 1011 for (len = t->len; len <= t->len + 1; len++) 1012 { 1013 uint_fast64_t test_val; 1014 for (test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += 1015 rnd_val) 1016 { 1017 uint_fast64_t rv = test_val; 1018 1019 rs = mhd_str_to_uint64_n (t->str, len, &rv); 1020 if (rs != 0) 1021 { 1022 t_failed++; 1023 c_failed[i] = !0; 1024 fprintf (stderr, 1025 "FAILED: mhd_str_to_uint64_n(\"%s\", %" PRIuPTR ", ->%" 1026 PRIuFAST64 ")" 1027 " returned %" PRIuPTR 1028 ", while expecting zero. Locale: %s\n", 1029 n_prnt (t->str), (uintptr_t)len, rv, (uintptr_t)rs, 1030 get_current_locale_str ()); 1031 } 1032 else if (rv != test_val) 1033 { 1034 t_failed++; 1035 c_failed[i] = !0; 1036 fprintf (stderr, 1037 "FAILED: mhd_str_to_uint64_n(\"%s\", %" PRIuPTR 1038 ", &ret_val)" 1039 " modified value of ret_val (before call: %" PRIuFAST64 1040 ", after call %" PRIuFAST64 ")." 1041 " Locale: %s\n", n_prnt (t->str), (uintptr_t)len, 1042 test_val, rv, 1043 get_current_locale_str ()); 1044 } 1045 } 1046 } 1047 if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) 1048 printf ("PASSED: mhd_str_to_uint64_n(\"%s\", %" PRIuPTR "..%" PRIuPTR 1049 ", &ret_val) == 0," 1050 " value of ret_val is unmodified\n", n_prnt (t->str), 1051 (uintptr_t)t->len, 1052 (uintptr_t)t->len + 1); 1053 } 1054 } 1055 return t_failed; 1056 } 1057 1058 1059 static size_t 1060 check_str_to_uint64_n_no_val (void) 1061 { 1062 size_t t_failed = 0; 1063 size_t i, j; 1064 int c_failed[sizeof(str_no_num) / sizeof(str_no_num[0])]; 1065 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 1066 1067 memset (c_failed, 0, sizeof(c_failed)); 1068 1069 for (j = 0; j < locale_name_count; j++) 1070 { 1071 set_test_locale (j); /* setlocale() can be slow! */ 1072 for (i = 0; i < n_checks; i++) 1073 { 1074 size_t rs; 1075 const struct str_with_len *const t = str_no_num + i; 1076 static const uint_fast64_t rnd_val = 43255654342; 1077 size_t len; 1078 1079 for (len = 0; len <= t->len + 1; len++) 1080 { 1081 uint_fast64_t test_val; 1082 for (test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += 1083 rnd_val) 1084 { 1085 uint_fast64_t rv = test_val; 1086 1087 rs = mhd_str_to_uint64_n (t->str, len, &rv); 1088 if (rs != 0) 1089 { 1090 t_failed++; 1091 c_failed[i] = !0; 1092 fprintf (stderr, 1093 "FAILED: mhd_str_to_uint64_n(\"%s\", %" PRIuPTR ", ->%" 1094 PRIuFAST64 ")" 1095 " returned %" PRIuPTR 1096 ", while expecting zero. Locale: %s\n", 1097 n_prnt (t->str), (uintptr_t)len, rv, (uintptr_t)rs, 1098 get_current_locale_str ()); 1099 } 1100 else if (rv != test_val) 1101 { 1102 t_failed++; 1103 c_failed[i] = !0; 1104 fprintf (stderr, 1105 "FAILED: mhd_str_to_uint64_n(\"%s\", %" PRIuPTR 1106 ", &ret_val)" 1107 " modified value of ret_val (before call: %" PRIuFAST64 1108 ", after call %" PRIuFAST64 ")." 1109 " Locale: %s\n", n_prnt (t->str), (uintptr_t)len, 1110 test_val, rv, 1111 get_current_locale_str ()); 1112 } 1113 } 1114 } 1115 if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) 1116 printf ("PASSED: mhd_str_to_uint64_n(\"%s\", 0..%" PRIuPTR 1117 ", &ret_val) == 0," 1118 " value of ret_val is unmodified\n", n_prnt (t->str), 1119 (uintptr_t)t->len + 1); 1120 } 1121 } 1122 return t_failed; 1123 } 1124 1125 1126 static size_t 1127 check_strx_to_uint32_valid (void) 1128 { 1129 size_t t_failed = 0; 1130 size_t i, j; 1131 int c_failed[sizeof(xdstrs_w_values) 1132 / sizeof(xdstrs_w_values[0])]; 1133 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 1134 1135 memset (c_failed, 0, sizeof(c_failed)); 1136 1137 for (j = 0; j < locale_name_count; j++) 1138 { 1139 set_test_locale (j); /* setlocale() can be slow! */ 1140 for (i = 0; i < n_checks; i++) 1141 { 1142 uint_fast32_t rv; 1143 size_t rs; 1144 const struct str_with_value *const t = xdstrs_w_values + i; 1145 1146 if (t->val != (uint_fast32_t)t->val) 1147 continue; /* number is too high for this function */ 1148 1149 if (c_failed[i]) 1150 continue; /* skip already failed checks */ 1151 1152 if (t->str.len < t->num_of_digt) 1153 { 1154 fprintf (stderr, 1155 "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" 1156 " to be less or equal to str.len (%u).\n", 1157 (unsigned int)i, 1158 (unsigned int)t->num_of_digt, 1159 (unsigned 1160 int)t->str. 1161 len); 1162 exit (99); 1163 } 1164 rv = 1458532; /* some random value */ 1165 rs = mhd_strx_to_uint32 (t->str.str, &rv); 1166 if (rs != t->num_of_digt) 1167 { 1168 t_failed++; 1169 c_failed[i] = !0; 1170 fprintf (stderr, 1171 "FAILED: mhd_strx_to_uint32(\"%s\", ->0x%" PRIXFAST64 1172 ") returned %" 1173 PRIuPTR " digits, while expecting %d." 1174 " Locale: %s\n", 1175 n_prnt (t->str.str), (uint_fast64_t)rv, 1176 (uintptr_t)rs, 1177 (int)t->num_of_digt, 1178 get_current_locale_str ()); 1179 } 1180 if (rv != t->val) 1181 { 1182 t_failed++; 1183 c_failed[i] = !0; 1184 fprintf (stderr, 1185 "FAILED: mhd_strx_to_uint32(\"%s\", ->0x%" PRIXFAST64 1186 ") converted string to value 0x%" 1187 PRIXFAST64 "," 1188 " while expecting result 0x%" PRIXFAST64 ". Locale: %s\n", 1189 n_prnt (t->str.str), (uint_fast64_t)rv, (uint_fast64_t)rv, 1190 t->val, get_current_locale_str ()); 1191 } 1192 if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) 1193 printf ("PASSED: mhd_strx_to_uint32(\"%s\", ->0x%" PRIXFAST64 ") == %" 1194 PRIuPTR "\n", 1195 n_prnt (t->str.str), (uint_fast64_t)rv, rs); 1196 } 1197 } 1198 return t_failed; 1199 } 1200 1201 1202 static size_t 1203 check_strx_to_uint32_all_chars (void) 1204 { 1205 int c_failed[256]; /* from 0 to 255 */ 1206 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 1207 size_t t_failed = 0; 1208 size_t j; 1209 1210 memset (c_failed, 0, sizeof(c_failed)); 1211 1212 for (j = 0; j < locale_name_count; j++) 1213 { 1214 unsigned int c; 1215 uint_fast32_t test_val; 1216 1217 set_test_locale (j); /* setlocale() can be slow! */ 1218 for (c = 0; c < n_checks; c++) 1219 { 1220 static const uint_fast32_t rnd_val = 234234; 1221 size_t rs; 1222 if (((c >= '0') && (c <= '9')) 1223 || ((c >= 'A') && (c <= 'F')) 1224 || ((c >= 'a') && (c <= 'f'))) 1225 continue; /* skip xdigits */ 1226 for (test_val = 0; test_val <= rnd_val && !c_failed[c]; test_val += 1227 rnd_val) 1228 { 1229 char test_str[] = "0123"; 1230 uint_fast32_t rv = test_val; 1231 1232 test_str[0] = (char)(unsigned char)c; /* replace first char with non-digit char */ 1233 rs = mhd_strx_to_uint32 (test_str, &rv); 1234 if (rs != 0) 1235 { 1236 t_failed++; 1237 c_failed[c] = !0; 1238 fprintf (stderr, 1239 "FAILED: mhd_strx_to_uint32(\"%s\", ->0x%" PRIXFAST64 1240 ") returned %" 1241 PRIuPTR " digits, while expecting zero." 1242 " Locale: %s\n", n_prnt (test_str), (uint_fast64_t)rv, 1243 (uintptr_t)rs, get_current_locale_str ()); 1244 } 1245 else if (rv != test_val) 1246 { 1247 t_failed++; 1248 c_failed[c] = !0; 1249 fprintf (stderr, 1250 "FAILED: mhd_strx_to_uint32(\"%s\", &ret_val) modified value of ret_val" 1251 " (before call: 0x%" PRIXFAST64 ", after call 0x%" PRIXFAST64 1252 "). Locale: %s\n", 1253 n_prnt (test_str), 1254 (uint_fast64_t)test_val, 1255 (uint_fast64_t)rv, 1256 get_current_locale_str ()); 1257 } 1258 } 1259 if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[c]) 1260 { 1261 char test_str[] = "0123"; 1262 test_str[0] = (char)(unsigned char)c; /* replace first char with non-digit char */ 1263 1264 printf ("PASSED: mhd_strx_to_uint32(\"%s\", &ret_val) == 0, " 1265 "value of ret_val is unmodified\n", 1266 n_prnt (test_str)); 1267 } 1268 } 1269 } 1270 return t_failed; 1271 } 1272 1273 1274 static size_t 1275 check_strx_to_uint32_overflow (void) 1276 { 1277 size_t t_failed = 0; 1278 size_t i, j; 1279 static const size_t n_checks1 = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]); 1280 int c_failed[(sizeof(strx_ovflw) / sizeof(strx_ovflw[0])) 1281 + (sizeof(xdstrs_w_values) 1282 / sizeof(xdstrs_w_values[0]))]; 1283 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 1284 1285 memset (c_failed, 0, sizeof(c_failed)); 1286 1287 for (j = 0; j < locale_name_count; j++) 1288 { 1289 set_test_locale (j); /* setlocale() can be slow! */ 1290 for (i = 0; i < n_checks; i++) 1291 { 1292 size_t rs; 1293 static const uint_fast32_t rnd_val = 74218431; 1294 uint_fast32_t test_val; 1295 const char *str; 1296 if (i < n_checks1) 1297 { 1298 const struct str_with_len *const t = strx_ovflw + i; 1299 str = t->str; 1300 } 1301 else 1302 { 1303 const struct str_with_value *const t = xdstrs_w_values + (i 1304 - n_checks1); 1305 if (t->val == (uint_fast32_t)t->val) 1306 continue; /* check only strings that should overflow uint_fast32_t */ 1307 str = t->str.str; 1308 } 1309 1310 1311 for (test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += 1312 rnd_val) 1313 { 1314 uint_fast32_t rv = test_val; 1315 1316 rs = mhd_strx_to_uint32 (str, &rv); 1317 if (rs != 0) 1318 { 1319 t_failed++; 1320 c_failed[i] = !0; 1321 fprintf (stderr, 1322 "FAILED: mhd_strx_to_uint32(\"%s\", ->0x%" PRIXFAST64 1323 ") returned %" 1324 PRIuPTR ", while expecting zero." 1325 " Locale: %s\n", n_prnt (str), (uint_fast64_t)rv, 1326 (uintptr_t)rs, 1327 get_current_locale_str ()); 1328 } 1329 else if (rv != test_val) 1330 { 1331 t_failed++; 1332 c_failed[i] = !0; 1333 fprintf (stderr, 1334 "FAILED: mhd_strx_to_uint32(\"%s\", &ret_val) modified value of ret_val" 1335 " (before call: 0x%" PRIXFAST64 ", after call 0x%" PRIXFAST64 1336 "). Locale: %s\n", 1337 n_prnt (str), 1338 (uint_fast64_t)test_val, 1339 (uint_fast64_t)rv, 1340 get_current_locale_str ()); 1341 } 1342 } 1343 if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) 1344 printf ("PASSED: mhd_strx_to_uint32(\"%s\", &ret_val) == 0, " 1345 "value of ret_val is unmodified\n", 1346 n_prnt (str)); 1347 } 1348 } 1349 return t_failed; 1350 } 1351 1352 1353 static size_t 1354 check_strx_to_uint32_no_val (void) 1355 { 1356 size_t t_failed = 0; 1357 size_t i, j; 1358 int c_failed[sizeof(str_no_num) / sizeof(str_no_num[0])]; 1359 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 1360 1361 memset (c_failed, 0, sizeof(c_failed)); 1362 1363 for (j = 0; j < locale_name_count; j++) 1364 { 1365 set_test_locale (j); /* setlocale() can be slow! */ 1366 for (i = 0; i < n_checks; i++) 1367 { 1368 size_t rs; 1369 const struct str_with_len *const t = str_no_num + i; 1370 static const uint_fast32_t rnd_val = 74218431; 1371 uint_fast32_t test_val; 1372 1373 for (test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += 1374 rnd_val) 1375 { 1376 uint_fast32_t rv = test_val; 1377 1378 rs = mhd_strx_to_uint32 (t->str, &rv); 1379 if (rs != 0) 1380 { 1381 t_failed++; 1382 c_failed[i] = !0; 1383 fprintf (stderr, 1384 "FAILED: mhd_strx_to_uint32(\"%s\", ->0x%" PRIXFAST64 1385 ") returned %" 1386 PRIuPTR ", while expecting zero." 1387 " Locale: %s\n", n_prnt (t->str), (uint_fast64_t)rv, 1388 (uintptr_t)rs, get_current_locale_str ()); 1389 } 1390 else if (rv != test_val) 1391 { 1392 t_failed++; 1393 c_failed[i] = !0; 1394 fprintf (stderr, 1395 "FAILED: mhd_strx_to_uint32(\"%s\", &ret_val) modified value of ret_val" 1396 " (before call: 0x%" PRIXFAST64 ", after call 0x%" PRIXFAST64 1397 "). Locale: %s\n", 1398 n_prnt (t->str), 1399 (uint_fast64_t)test_val, 1400 (uint_fast64_t)rv, 1401 get_current_locale_str ()); 1402 } 1403 } 1404 if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) 1405 printf ("PASSED: mhd_strx_to_uint32(\"%s\", &ret_val) == 0, " 1406 "value of ret_val is unmodified\n", 1407 n_prnt (t->str)); 1408 } 1409 } 1410 return t_failed; 1411 } 1412 1413 1414 static size_t 1415 check_strx_to_uint32_n_valid (void) 1416 { 1417 size_t t_failed = 0; 1418 size_t i, j; 1419 int c_failed[sizeof(xdstrs_w_values) 1420 / sizeof(xdstrs_w_values[0])]; 1421 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 1422 1423 memset (c_failed, 0, sizeof(c_failed)); 1424 1425 for (j = 0; j < locale_name_count; j++) 1426 { 1427 set_test_locale (j); /* setlocale() can be slow! */ 1428 for (i = 0; i < n_checks; i++) 1429 { 1430 uint_fast32_t rv = 2352932; /* some random value */ 1431 size_t rs = 0; 1432 size_t len; 1433 const struct str_with_value *const t = xdstrs_w_values + i; 1434 1435 if (t->val != (uint_fast32_t)t->val) 1436 continue; /* number is too high for this function */ 1437 1438 if (t->str.len < t->num_of_digt) 1439 { 1440 fprintf (stderr, 1441 "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" 1442 " to be less or equal to str.len (%u).\n", 1443 (unsigned int)i, 1444 (unsigned int)t->num_of_digt, 1445 (unsigned 1446 int)t->str. 1447 len); 1448 exit (99); 1449 } 1450 for (len = t->num_of_digt; len <= t->str.len + 1 && !c_failed[i]; len++) 1451 { 1452 rs = mhd_strx_to_uint32_n (t->str.str, len, &rv); 1453 if (rs != t->num_of_digt) 1454 { 1455 t_failed++; 1456 c_failed[i] = !0; 1457 fprintf (stderr, 1458 "FAILED: mhd_strx_to_uint32_n(\"%s\", %" PRIuPTR ", ->0x%" 1459 PRIXFAST64 ")" 1460 " returned %" PRIuPTR ", while expecting %d. Locale: %s\n", 1461 n_prnt (t->str.str), (uintptr_t)len, (uint_fast64_t)rv, 1462 (uintptr_t)rs, 1463 (int)t->num_of_digt, get_current_locale_str ()); 1464 } 1465 if (rv != t->val) 1466 { 1467 t_failed++; 1468 c_failed[i] = !0; 1469 fprintf (stderr, 1470 "FAILED: mhd_strx_to_uint32_n(\"%s\", %" PRIuPTR ", ->0x%" 1471 PRIXFAST64 ")" 1472 " converted string to value 0x%" PRIXFAST64 1473 ", while expecting result 0x%" PRIXFAST64 1474 ". Locale: %s\n", n_prnt (t->str.str), (uintptr_t)len, 1475 (uint_fast64_t)rv, (uint_fast64_t)rv, 1476 t->val, get_current_locale_str ()); 1477 } 1478 } 1479 if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) 1480 printf ( 1481 "PASSED: mhd_strx_to_uint32_n(\"%s\", %" PRIuPTR "..%" PRIuPTR 1482 ", ->0x%" 1483 PRIXFAST64 ")" 1484 " == %" PRIuPTR "\n", n_prnt (t->str.str), 1485 (uintptr_t)t->num_of_digt, 1486 (uintptr_t)t->str.len + 1, (uint_fast64_t)rv, rs); 1487 } 1488 } 1489 return t_failed; 1490 } 1491 1492 1493 static size_t 1494 check_strx_to_uint32_n_all_chars (void) 1495 { 1496 int c_failed[256]; /* from 0 to 255 */ 1497 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 1498 size_t t_failed = 0; 1499 size_t j; 1500 1501 memset (c_failed, 0, sizeof(c_failed)); 1502 1503 for (j = 0; j < locale_name_count; j++) 1504 { 1505 unsigned int c; 1506 uint_fast32_t test_val; 1507 1508 set_test_locale (j); /* setlocale() can be slow! */ 1509 for (c = 0; c < n_checks; c++) 1510 { 1511 static const uint_fast32_t rnd_val = 98372558; 1512 size_t rs; 1513 size_t len; 1514 1515 if (((c >= '0') && (c <= '9')) 1516 || ((c >= 'A') && (c <= 'F')) 1517 || ((c >= 'a') && (c <= 'f'))) 1518 continue; /* skip xdigits */ 1519 1520 for (len = 0; len <= 5; len++) 1521 { 1522 for (test_val = 0; test_val <= rnd_val && !c_failed[c]; test_val += 1523 rnd_val) 1524 { 1525 char test_str[] = "0123"; 1526 uint_fast32_t rv = test_val; 1527 1528 test_str[0] = (char)(unsigned char)c; /* replace first char with non-digit char */ 1529 rs = mhd_strx_to_uint32_n (test_str, len, &rv); 1530 if (rs != 0) 1531 { 1532 t_failed++; 1533 c_failed[c] = !0; 1534 fprintf (stderr, 1535 "FAILED: mhd_strx_to_uint32_n(\"%s\", %" PRIuPTR ", ->0x%" 1536 PRIXFAST64 1537 ")" 1538 " returned %" PRIuPTR 1539 ", while expecting zero. Locale: %s\n", 1540 n_prnt (test_str), (uintptr_t)len, (uint_fast64_t)rv, 1541 (uintptr_t)rs, get_current_locale_str ()); 1542 } 1543 else if (rv != test_val) 1544 { 1545 t_failed++; 1546 c_failed[c] = !0; 1547 fprintf (stderr, 1548 "FAILED: mhd_strx_to_uint32_n(\"%s\", %" PRIuPTR 1549 ", &ret_val)" 1550 " modified value of ret_val (before call: 0x%" PRIXFAST64 1551 ", after call 0x%" PRIXFAST64 ")." 1552 " Locale: %s\n", 1553 n_prnt (test_str), (uintptr_t)len, 1554 (uint_fast64_t)test_val, 1555 (uint_fast64_t)rv, get_current_locale_str ()); 1556 } 1557 } 1558 } 1559 if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[c]) 1560 { 1561 char test_str[] = "0123"; 1562 test_str[0] = (char)(unsigned char)c; /* replace first char with non-digit char */ 1563 1564 printf ("PASSED: mhd_strx_to_uint32_n(\"%s\", 0..5, &ret_val) == 0, " 1565 "value of ret_val is unmodified\n", 1566 n_prnt (test_str)); 1567 } 1568 } 1569 } 1570 return t_failed; 1571 } 1572 1573 1574 static size_t 1575 check_strx_to_uint32_n_overflow (void) 1576 { 1577 size_t t_failed = 0; 1578 size_t i, j; 1579 static const size_t n_checks1 = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]); 1580 int c_failed[(sizeof(strx_ovflw) / sizeof(strx_ovflw[0])) 1581 + (sizeof(xdstrs_w_values) 1582 / sizeof(xdstrs_w_values[0]))]; 1583 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 1584 1585 memset (c_failed, 0, sizeof(c_failed)); 1586 1587 for (j = 0; j < locale_name_count; j++) 1588 { 1589 set_test_locale (j); /* setlocale() can be slow! */ 1590 for (i = 0; i < n_checks; i++) 1591 { 1592 size_t rs; 1593 static const uint_fast32_t rnd_val = 4; 1594 size_t len; 1595 const char *str; 1596 size_t min_len, max_len; 1597 if (i < n_checks1) 1598 { 1599 const struct str_with_len *const t = strx_ovflw + i; 1600 str = t->str; 1601 min_len = t->len; 1602 max_len = t->len + 1; 1603 } 1604 else 1605 { 1606 const struct str_with_value *const t = xdstrs_w_values + (i 1607 - n_checks1); 1608 if (t->val == (uint_fast32_t)t->val) 1609 continue; /* check only strings that should overflow uint_fast32_t */ 1610 1611 if (t->str.len < t->num_of_digt) 1612 { 1613 fprintf (stderr, 1614 "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" 1615 " to be less or equal to str.len (%u).\n", 1616 (unsigned int)(i - n_checks1), 1617 (unsigned 1618 int)t->num_of_digt, 1619 (unsigned int)t->str.len); 1620 exit (99); 1621 } 1622 str = t->str.str; 1623 min_len = t->num_of_digt; 1624 max_len = t->str.len + 1; 1625 } 1626 1627 for (len = min_len; len <= max_len; len++) 1628 { 1629 uint_fast32_t test_val; 1630 for (test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += 1631 rnd_val) 1632 { 1633 uint_fast32_t rv = test_val; 1634 1635 rs = mhd_strx_to_uint32_n (str, len, &rv); 1636 if (rs != 0) 1637 { 1638 t_failed++; 1639 c_failed[i] = !0; 1640 fprintf (stderr, 1641 "FAILED: mhd_strx_to_uint32_n(\"%s\", %" PRIuPTR ", ->0x%" 1642 PRIXFAST64 1643 ")" 1644 " returned %" PRIuPTR 1645 ", while expecting zero. Locale: %s\n", 1646 n_prnt (str), (uintptr_t)len, (uint_fast64_t)rv, 1647 (uintptr_t)rs, get_current_locale_str ()); 1648 } 1649 else if (rv != test_val) 1650 { 1651 t_failed++; 1652 c_failed[i] = !0; 1653 fprintf (stderr, 1654 "FAILED: mhd_strx_to_uint32_n(\"%s\", %" PRIuPTR 1655 ", &ret_val)" 1656 " modified value of ret_val (before call: 0x%" PRIXFAST64 1657 ", after call 0x%" PRIXFAST64 ")." 1658 " Locale: %s\n", n_prnt (str), (uintptr_t)len, 1659 (uint_fast64_t)test_val, (uint_fast64_t)rv, 1660 get_current_locale_str ()); 1661 } 1662 } 1663 } 1664 if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) 1665 printf ("PASSED: mhd_strx_to_uint32_n(\"%s\", %" PRIuPTR "..%" PRIuPTR 1666 ", &ret_val) == 0," 1667 " value of ret_val is unmodified\n", n_prnt (str), 1668 (uintptr_t)min_len, 1669 (uintptr_t)max_len); 1670 } 1671 } 1672 return t_failed; 1673 } 1674 1675 1676 static size_t 1677 check_strx_to_uint32_n_no_val (void) 1678 { 1679 size_t t_failed = 0; 1680 size_t i, j; 1681 int c_failed[sizeof(str_no_num) / sizeof(str_no_num[0])]; 1682 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 1683 1684 memset (c_failed, 0, sizeof(c_failed)); 1685 1686 for (j = 0; j < locale_name_count; j++) 1687 { 1688 set_test_locale (j); /* setlocale() can be slow! */ 1689 for (i = 0; i < n_checks; i++) 1690 { 1691 size_t rs; 1692 const struct str_with_len *const t = str_no_num + i; 1693 static const uint_fast32_t rnd_val = 3214314212UL; 1694 size_t len; 1695 1696 for (len = 0; len <= t->len + 1; len++) 1697 { 1698 uint_fast32_t test_val; 1699 for (test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += 1700 rnd_val) 1701 { 1702 uint_fast32_t rv = test_val; 1703 1704 rs = mhd_strx_to_uint32_n (t->str, len, &rv); 1705 if (rs != 0) 1706 { 1707 t_failed++; 1708 c_failed[i] = !0; 1709 fprintf (stderr, 1710 "FAILED: mhd_strx_to_uint32_n(\"%s\", %" PRIuPTR ", ->0x%" 1711 PRIXFAST64 1712 ")" 1713 " returned %" PRIuPTR 1714 ", while expecting zero. Locale: %s\n", 1715 n_prnt (t->str), (uintptr_t)len, (uint_fast64_t)rv, 1716 (uintptr_t)rs, get_current_locale_str ()); 1717 } 1718 else if (rv != test_val) 1719 { 1720 t_failed++; 1721 c_failed[i] = !0; 1722 fprintf (stderr, 1723 "FAILED: mhd_strx_to_uint32_n(\"%s\", %" PRIuPTR 1724 ", &ret_val)" 1725 " modified value of ret_val (before call: 0x%" PRIXFAST64 1726 ", after call 0x%" PRIXFAST64 ")." 1727 " Locale: %s\n", n_prnt (t->str), (uintptr_t)len, 1728 (uint_fast64_t)test_val, (uint_fast64_t)rv, 1729 get_current_locale_str ()); 1730 } 1731 } 1732 } 1733 if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) 1734 printf ("PASSED: mhd_strx_to_uint32_n(\"%s\", 0..%" PRIuPTR 1735 ", &ret_val) == 0," 1736 " value of ret_val is unmodified\n", n_prnt (t->str), 1737 (uintptr_t)t->len + 1); 1738 } 1739 } 1740 return t_failed; 1741 } 1742 1743 1744 static size_t 1745 check_strx_to_uint64_valid (void) 1746 { 1747 size_t t_failed = 0; 1748 size_t i, j; 1749 int c_failed[sizeof(xdstrs_w_values) 1750 / sizeof(xdstrs_w_values[0])]; 1751 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 1752 1753 memset (c_failed, 0, sizeof(c_failed)); 1754 1755 for (j = 0; j < locale_name_count; j++) 1756 { 1757 set_test_locale (j); /* setlocale() can be slow! */ 1758 for (i = 0; i < n_checks; i++) 1759 { 1760 uint_fast64_t rv; 1761 size_t rs; 1762 const struct str_with_value *const t = xdstrs_w_values + i; 1763 1764 if (c_failed[i]) 1765 continue; /* skip already failed checks */ 1766 1767 if (t->str.len < t->num_of_digt) 1768 { 1769 fprintf (stderr, 1770 "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" 1771 " to be less or equal to str.len (%u).\n", 1772 (unsigned int)i, 1773 (unsigned int)t->num_of_digt, 1774 (unsigned 1775 int)t->str. 1776 len); 1777 exit (99); 1778 } 1779 rv = 1458532; /* some random value */ 1780 rs = mhd_strx_to_uint64 (t->str.str, &rv); 1781 if (rs != t->num_of_digt) 1782 { 1783 t_failed++; 1784 c_failed[i] = !0; 1785 fprintf (stderr, 1786 "FAILED: mhd_strx_to_uint64(\"%s\", ->0x%" PRIXFAST64 1787 ") returned %" 1788 PRIuPTR ", while expecting %d." 1789 " Locale: %s\n", n_prnt (t->str.str), rv, (uintptr_t)rs, 1790 (int)t->num_of_digt, get_current_locale_str ()); 1791 } 1792 if (rv != t->val) 1793 { 1794 t_failed++; 1795 c_failed[i] = !0; 1796 fprintf (stderr, 1797 "FAILED: mhd_strx_to_uint64(\"%s\", ->0x%" PRIXFAST64 1798 ") converted string to value 0x%" 1799 PRIXFAST64 "," 1800 " while expecting result 0x%" PRIXFAST64 ". Locale: %s\n", 1801 n_prnt (t->str.str), rv, rv, 1802 t->val, get_current_locale_str ()); 1803 } 1804 if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) 1805 printf ("PASSED: mhd_strx_to_uint64(\"%s\", ->0x%" PRIXFAST64 ") == %" 1806 PRIuPTR "\n", 1807 n_prnt (t->str.str), rv, rs); 1808 } 1809 } 1810 return t_failed; 1811 } 1812 1813 1814 static size_t 1815 check_strx_to_uint64_all_chars (void) 1816 { 1817 int c_failed[256]; /* from 0 to 255 */ 1818 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 1819 size_t t_failed = 0; 1820 size_t j; 1821 1822 memset (c_failed, 0, sizeof(c_failed)); 1823 1824 for (j = 0; j < locale_name_count; j++) 1825 { 1826 unsigned int c; 1827 uint_fast64_t test_val; 1828 1829 set_test_locale (j); /* setlocale() can be slow! */ 1830 for (c = 0; c < n_checks; c++) 1831 { 1832 static const uint_fast64_t rnd_val = 234234; 1833 size_t rs; 1834 if (((c >= '0') && (c <= '9')) 1835 || ((c >= 'A') && (c <= 'F')) 1836 || ((c >= 'a') && (c <= 'f'))) 1837 continue; /* skip xdigits */ 1838 for (test_val = 0; test_val <= rnd_val && !c_failed[c]; test_val += 1839 rnd_val) 1840 { 1841 char test_str[] = "0123"; 1842 uint_fast64_t rv = test_val; 1843 1844 test_str[0] = (char)(unsigned char)c; /* replace first char with non-digit char */ 1845 rs = mhd_strx_to_uint64 (test_str, &rv); 1846 if (rs != 0) 1847 { 1848 t_failed++; 1849 c_failed[c] = !0; 1850 fprintf (stderr, 1851 "FAILED: mhd_strx_to_uint64(\"%s\", ->0x%" PRIXFAST64 1852 ") returned %" 1853 PRIuPTR ", while expecting zero." 1854 " Locale: %s\n", n_prnt (test_str), rv, (uintptr_t)rs, 1855 get_current_locale_str ()); 1856 } 1857 else if (rv != test_val) 1858 { 1859 t_failed++; 1860 c_failed[c] = !0; 1861 fprintf (stderr, 1862 "FAILED: mhd_strx_to_uint64(\"%s\", &ret_val) modified value of ret_val" 1863 " (before call: 0x%" PRIXFAST64 ", after call 0x%" PRIXFAST64 1864 "). Locale: %s\n", 1865 n_prnt (test_str), 1866 test_val, 1867 rv, 1868 get_current_locale_str ()); 1869 } 1870 } 1871 if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[c]) 1872 { 1873 char test_str[] = "0123"; 1874 test_str[0] = (char)(unsigned char)c; /* replace first char with non-digit char */ 1875 1876 printf ("PASSED: mhd_strx_to_uint64(\"%s\", &ret_val) == 0, " 1877 "value of ret_val is unmodified\n", 1878 n_prnt (test_str)); 1879 } 1880 } 1881 } 1882 return t_failed; 1883 } 1884 1885 1886 static size_t 1887 check_strx_to_uint64_overflow (void) 1888 { 1889 size_t t_failed = 0; 1890 size_t i, j; 1891 int c_failed[sizeof(strx_ovflw) / sizeof(strx_ovflw[0])]; 1892 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 1893 1894 memset (c_failed, 0, sizeof(c_failed)); 1895 1896 for (j = 0; j < locale_name_count; j++) 1897 { 1898 set_test_locale (j); /* setlocale() can be slow! */ 1899 for (i = 0; i < n_checks; i++) 1900 { 1901 size_t rs; 1902 const struct str_with_len *const t = strx_ovflw + i; 1903 static const uint_fast64_t rnd_val = 74218431; 1904 uint_fast64_t test_val; 1905 1906 for (test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += 1907 rnd_val) 1908 { 1909 uint_fast64_t rv = test_val; 1910 1911 rs = mhd_strx_to_uint64 (t->str, &rv); 1912 if (rs != 0) 1913 { 1914 t_failed++; 1915 c_failed[i] = !0; 1916 fprintf (stderr, 1917 "FAILED: mhd_strx_to_uint64(\"%s\", ->0x%" PRIXFAST64 1918 ") returned %" 1919 PRIuPTR ", while expecting zero." 1920 " Locale: %s\n", n_prnt (t->str), rv, (uintptr_t)rs, 1921 get_current_locale_str ()); 1922 } 1923 else if (rv != test_val) 1924 { 1925 t_failed++; 1926 c_failed[i] = !0; 1927 fprintf (stderr, 1928 "FAILED: mhd_strx_to_uint64(\"%s\", &ret_val) modified value of ret_val" 1929 " (before call: 0x%" PRIXFAST64 ", after call 0x%" PRIXFAST64 1930 "). Locale: %s\n", 1931 n_prnt (t->str), 1932 test_val, 1933 rv, 1934 get_current_locale_str ()); 1935 } 1936 } 1937 if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) 1938 printf ("PASSED: mhd_strx_to_uint64(\"%s\", &ret_val) == 0, " 1939 "value of ret_val is unmodified\n", 1940 n_prnt (t->str)); 1941 } 1942 } 1943 return t_failed; 1944 } 1945 1946 1947 static size_t 1948 check_strx_to_uint64_no_val (void) 1949 { 1950 size_t t_failed = 0; 1951 size_t i, j; 1952 int c_failed[sizeof(str_no_num) / sizeof(str_no_num[0])]; 1953 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 1954 1955 memset (c_failed, 0, sizeof(c_failed)); 1956 1957 for (j = 0; j < locale_name_count; j++) 1958 { 1959 set_test_locale (j); /* setlocale() can be slow! */ 1960 for (i = 0; i < n_checks; i++) 1961 { 1962 size_t rs; 1963 const struct str_with_len *const t = str_no_num + i; 1964 static const uint_fast64_t rnd_val = 74218431; 1965 uint_fast64_t test_val; 1966 1967 for (test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += 1968 rnd_val) 1969 { 1970 uint_fast64_t rv = test_val; 1971 1972 rs = mhd_strx_to_uint64 (t->str, &rv); 1973 if (rs != 0) 1974 { 1975 t_failed++; 1976 c_failed[i] = !0; 1977 fprintf (stderr, 1978 "FAILED: mhd_strx_to_uint64(\"%s\", ->0x%" PRIXFAST64 1979 ") returned %" 1980 PRIuPTR ", while expecting zero." 1981 " Locale: %s\n", n_prnt (t->str), rv, (uintptr_t)rs, 1982 get_current_locale_str ()); 1983 } 1984 else if (rv != test_val) 1985 { 1986 t_failed++; 1987 c_failed[i] = !0; 1988 fprintf (stderr, 1989 "FAILED: mhd_strx_to_uint64(\"%s\", &ret_val) modified value of ret_val" 1990 " (before call: 0x%" PRIXFAST64 ", after call 0x%" PRIXFAST64 1991 "). Locale: %s\n", 1992 n_prnt (t->str), 1993 test_val, 1994 rv, 1995 get_current_locale_str ()); 1996 } 1997 } 1998 if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) 1999 printf ("PASSED: mhd_strx_to_uint64(\"%s\", &ret_val) == 0, " 2000 "value of ret_val is unmodified\n", 2001 n_prnt (t->str)); 2002 } 2003 } 2004 return t_failed; 2005 } 2006 2007 2008 static size_t 2009 check_strx_to_uint64_n_valid (void) 2010 { 2011 size_t t_failed = 0; 2012 size_t i, j; 2013 int c_failed[sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0])]; 2014 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 2015 2016 memset (c_failed, 0, sizeof(c_failed)); 2017 2018 for (j = 0; j < locale_name_count; j++) 2019 { 2020 set_test_locale (j); /* setlocale() can be slow! */ 2021 for (i = 0; i < n_checks; i++) 2022 { 2023 uint_fast64_t rv = 2352932; /* some random value */ 2024 size_t rs = 0; 2025 size_t len; 2026 const struct str_with_value *const t = xdstrs_w_values + i; 2027 2028 if (t->str.len < t->num_of_digt) 2029 { 2030 fprintf (stderr, 2031 "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" 2032 " to be less or equal to str.len (%u).\n", 2033 (unsigned int)i, 2034 (unsigned int)t->num_of_digt, 2035 (unsigned 2036 int)t->str. 2037 len); 2038 exit (99); 2039 } 2040 for (len = t->num_of_digt; len <= t->str.len + 1 && !c_failed[i]; len++) 2041 { 2042 rs = mhd_strx_to_uint64_n (t->str.str, len, &rv); 2043 if (rs != t->num_of_digt) 2044 { 2045 t_failed++; 2046 c_failed[i] = !0; 2047 fprintf (stderr, 2048 "FAILED: mhd_strx_to_uint64_n(\"%s\", %" PRIuPTR ", ->0x%" 2049 PRIXFAST64 ")" 2050 " returned %" PRIuPTR ", while expecting %d. Locale: %s\n", 2051 n_prnt (t->str.str), (uintptr_t)len, rv, (uintptr_t)rs, 2052 (int)t->num_of_digt, get_current_locale_str ()); 2053 } 2054 if (rv != t->val) 2055 { 2056 t_failed++; 2057 c_failed[i] = !0; 2058 fprintf (stderr, 2059 "FAILED: mhd_strx_to_uint64_n(\"%s\", %" PRIuPTR ", ->0x%" 2060 PRIXFAST64 ")" 2061 " converted string to value 0x%" PRIXFAST64 2062 ", while expecting result 0x%" PRIXFAST64 2063 ". Locale: %s\n", n_prnt (t->str.str), (uintptr_t)len, rv, 2064 rv, 2065 t->val, get_current_locale_str ()); 2066 } 2067 } 2068 if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) 2069 printf ("PASSED: mhd_strx_to_uint64_n(\"%s\", %" PRIuPTR "..%" PRIuPTR 2070 ", ->0x%" 2071 PRIXFAST64 ")" 2072 " == %" PRIuPTR "\n", n_prnt (t->str.str), 2073 (uintptr_t)t->num_of_digt, 2074 (uintptr_t)t->str.len + 1, rv, rs); 2075 } 2076 } 2077 return t_failed; 2078 } 2079 2080 2081 static size_t 2082 check_strx_to_uint64_n_all_chars (void) 2083 { 2084 int c_failed[256]; /* from 0 to 255 */ 2085 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 2086 size_t t_failed = 0; 2087 size_t j; 2088 2089 memset (c_failed, 0, sizeof(c_failed)); 2090 2091 for (j = 0; j < locale_name_count; j++) 2092 { 2093 unsigned int c; 2094 uint_fast64_t test_val; 2095 2096 set_test_locale (j); /* setlocale() can be slow! */ 2097 for (c = 0; c < n_checks; c++) 2098 { 2099 static const uint_fast64_t rnd_val = 98372558; 2100 size_t rs; 2101 size_t len; 2102 2103 if (((c >= '0') && (c <= '9')) 2104 || ((c >= 'A') && (c <= 'F')) 2105 || ((c >= 'a') && (c <= 'f'))) 2106 continue; /* skip xdigits */ 2107 2108 for (len = 0; len <= 5; len++) 2109 { 2110 for (test_val = 0; test_val <= rnd_val && !c_failed[c]; test_val += 2111 rnd_val) 2112 { 2113 char test_str[] = "0123"; 2114 uint_fast64_t rv = test_val; 2115 2116 test_str[0] = (char)(unsigned char)c; /* replace first char with non-digit char */ 2117 rs = mhd_strx_to_uint64_n (test_str, len, &rv); 2118 if (rs != 0) 2119 { 2120 t_failed++; 2121 c_failed[c] = !0; 2122 fprintf (stderr, 2123 "FAILED: mhd_strx_to_uint64_n(\"%s\", %" PRIuPTR ", ->0x%" 2124 PRIXFAST64 2125 ")" 2126 " returned %" PRIuPTR 2127 ", while expecting zero. Locale: %s\n", 2128 n_prnt (test_str), (uintptr_t)len, rv, (uintptr_t)rs, 2129 get_current_locale_str ()); 2130 } 2131 else if (rv != test_val) 2132 { 2133 t_failed++; 2134 c_failed[c] = !0; 2135 fprintf (stderr, 2136 "FAILED: mhd_strx_to_uint64_n(\"%s\", %" PRIuPTR 2137 ", &ret_val)" 2138 " modified value of ret_val (before call: 0x%" PRIXFAST64 2139 ", after call 0x%" PRIXFAST64 ")." 2140 " Locale: %s\n", 2141 n_prnt (test_str), (uintptr_t)len, test_val, rv, 2142 get_current_locale_str ()); 2143 } 2144 } 2145 } 2146 if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[c]) 2147 { 2148 char test_str[] = "0123"; 2149 test_str[0] = (char)(unsigned char)c; /* replace first char with non-digit char */ 2150 2151 printf ("PASSED: mhd_strx_to_uint64_n(\"%s\", 0..5, &ret_val) == 0, " 2152 "value of ret_val is unmodified\n", 2153 n_prnt (test_str)); 2154 } 2155 } 2156 } 2157 return t_failed; 2158 } 2159 2160 2161 static size_t 2162 check_strx_to_uint64_n_overflow (void) 2163 { 2164 size_t t_failed = 0; 2165 size_t i, j; 2166 int c_failed[sizeof(strx_ovflw) / sizeof(strx_ovflw[0])]; 2167 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 2168 2169 memset (c_failed, 0, sizeof(c_failed)); 2170 2171 for (j = 0; j < locale_name_count; j++) 2172 { 2173 set_test_locale (j); /* setlocale() can be slow! */ 2174 for (i = 0; i < n_checks; i++) 2175 { 2176 size_t rs; 2177 const struct str_with_len *const t = strx_ovflw + i; 2178 static const uint_fast64_t rnd_val = 4; 2179 size_t len; 2180 2181 for (len = t->len; len <= t->len + 1; len++) 2182 { 2183 uint_fast64_t test_val; 2184 for (test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += 2185 rnd_val) 2186 { 2187 uint_fast64_t rv = test_val; 2188 2189 rs = mhd_strx_to_uint64_n (t->str, len, &rv); 2190 if (rs != 0) 2191 { 2192 t_failed++; 2193 c_failed[i] = !0; 2194 fprintf (stderr, 2195 "FAILED: mhd_strx_to_uint64_n(\"%s\", %" PRIuPTR ", ->0x%" 2196 PRIXFAST64 2197 ")" 2198 " returned %" PRIuPTR 2199 ", while expecting zero. Locale: %s\n", 2200 n_prnt (t->str), (uintptr_t)len, rv, (uintptr_t)rs, 2201 get_current_locale_str ()); 2202 } 2203 else if (rv != test_val) 2204 { 2205 t_failed++; 2206 c_failed[i] = !0; 2207 fprintf (stderr, 2208 "FAILED: mhd_strx_to_uint64_n(\"%s\", %" PRIuPTR 2209 ", &ret_val)" 2210 " modified value of ret_val (before call: 0x%" PRIXFAST64 2211 ", after call 0x%" PRIXFAST64 ")." 2212 " Locale: %s\n", n_prnt (t->str), (uintptr_t)len, 2213 test_val, rv, 2214 get_current_locale_str ()); 2215 } 2216 } 2217 } 2218 if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) 2219 printf ("PASSED: mhd_strx_to_uint64_n(\"%s\", %" PRIuPTR "..%" PRIuPTR 2220 ", &ret_val) == 0," 2221 " value of ret_val is unmodified\n", n_prnt (t->str), 2222 (uintptr_t)t->len, 2223 (uintptr_t)t->len + 1); 2224 } 2225 } 2226 return t_failed; 2227 } 2228 2229 2230 static size_t 2231 check_strx_to_uint64_n_no_val (void) 2232 { 2233 size_t t_failed = 0; 2234 size_t i, j; 2235 int c_failed[sizeof(str_no_num) / sizeof(str_no_num[0])]; 2236 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 2237 2238 memset (c_failed, 0, sizeof(c_failed)); 2239 2240 for (j = 0; j < locale_name_count; j++) 2241 { 2242 set_test_locale (j); /* setlocale() can be slow! */ 2243 for (i = 0; i < n_checks; i++) 2244 { 2245 size_t rs; 2246 const struct str_with_len *const t = str_no_num + i; 2247 static const uint_fast64_t rnd_val = 3214314212UL; 2248 size_t len; 2249 2250 for (len = 0; len <= t->len + 1; len++) 2251 { 2252 uint_fast64_t test_val; 2253 for (test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += 2254 rnd_val) 2255 { 2256 uint_fast64_t rv = test_val; 2257 2258 rs = mhd_strx_to_uint64_n (t->str, len, &rv); 2259 if (rs != 0) 2260 { 2261 t_failed++; 2262 c_failed[i] = !0; 2263 fprintf (stderr, 2264 "FAILED: mhd_strx_to_uint64_n(\"%s\", %" PRIuPTR ", ->0x%" 2265 PRIXFAST64 2266 ")" 2267 " returned %" PRIuPTR 2268 ", while expecting zero. Locale: %s\n", 2269 n_prnt (t->str), (uintptr_t)len, rv, (uintptr_t)rs, 2270 get_current_locale_str ()); 2271 } 2272 else if (rv != test_val) 2273 { 2274 t_failed++; 2275 c_failed[i] = !0; 2276 fprintf (stderr, 2277 "FAILED: mhd_strx_to_uint64_n(\"%s\", %" PRIuPTR 2278 ", &ret_val)" 2279 " modified value of ret_val (before call: 0x%" PRIXFAST64 2280 ", after call 0x%" PRIXFAST64 ")." 2281 " Locale: %s\n", n_prnt (t->str), (uintptr_t)len, 2282 test_val, rv, 2283 get_current_locale_str ()); 2284 } 2285 } 2286 } 2287 if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) 2288 printf ("PASSED: mhd_strx_to_uint64_n(\"%s\", 0..%" PRIuPTR 2289 ", &ret_val) == 0," 2290 " value of ret_val is unmodified\n", n_prnt (t->str), 2291 (uintptr_t)t->len + 1); 2292 } 2293 } 2294 return t_failed; 2295 } 2296 2297 2298 static int 2299 run_str_to_X_tests (void) 2300 { 2301 size_t str_to_uint64_fails = 0; 2302 size_t str_to_uint64_n_fails = 0; 2303 size_t strx_to_uint32_fails = 0; 2304 size_t strx_to_uint32_n_fails = 0; 2305 size_t strx_to_uint64_fails = 0; 2306 size_t strx_to_uint64_n_fails = 0; 2307 size_t res; 2308 2309 res = check_str_to_uint64_valid (); 2310 if (res != 0) 2311 { 2312 str_to_uint64_fails += res; 2313 fprintf (stderr, 2314 "FAILED: testcase check_str_to_uint64_valid() failed.\n\n"); 2315 } 2316 else if (verbose > 1) 2317 printf ( 2318 "PASSED: testcase check_str_to_uint64_valid() successfully passed.\n\n"); 2319 2320 res = check_str_to_uint64_all_chars (); 2321 if (res != 0) 2322 { 2323 str_to_uint64_fails += res; 2324 fprintf (stderr, 2325 "FAILED: testcase check_str_to_uint64_all_chars() failed.\n\n"); 2326 } 2327 else if (verbose > 1) 2328 printf ("PASSED: testcase check_str_to_uint64_all_chars() " 2329 "successfully passed.\n\n"); 2330 2331 res = check_str_to_uint64_overflow (); 2332 if (res != 0) 2333 { 2334 str_to_uint64_fails += res; 2335 fprintf (stderr, 2336 "FAILED: testcase check_str_to_uint64_overflow() failed.\n\n"); 2337 } 2338 else if (verbose > 1) 2339 printf ("PASSED: testcase check_str_to_uint64_overflow() " 2340 "successfully passed.\n\n"); 2341 2342 res = check_str_to_uint64_no_val (); 2343 if (res != 0) 2344 { 2345 str_to_uint64_fails += res; 2346 fprintf (stderr, 2347 "FAILED: testcase check_str_to_uint64_no_val() failed.\n\n"); 2348 } 2349 else if (verbose > 1) 2350 printf ("PASSED: testcase check_str_to_uint64_no_val() " 2351 "successfully passed.\n\n"); 2352 2353 if (str_to_uint64_fails) 2354 fprintf (stderr, 2355 "FAILED: function mhd_str_to_uint64() failed %lu time%s.\n\n", 2356 (unsigned long)str_to_uint64_fails, 2357 str_to_uint64_fails == 1 ? "" : "s"); 2358 else if (verbose > 0) 2359 printf ("PASSED: function mhd_str_to_uint64() successfully " 2360 "passed all checks.\n\n"); 2361 2362 res = check_str_to_uint64_n_valid (); 2363 if (res != 0) 2364 { 2365 str_to_uint64_n_fails += res; 2366 fprintf (stderr, 2367 "FAILED: testcase check_str_to_uint64_n_valid() failed.\n\n"); 2368 } 2369 else if (verbose > 1) 2370 printf ("PASSED: testcase check_str_to_uint64_n_valid() " 2371 "successfully passed.\n\n"); 2372 2373 res = check_str_to_uint64_n_all_chars (); 2374 if (res != 0) 2375 { 2376 str_to_uint64_n_fails += res; 2377 fprintf (stderr, 2378 "FAILED: testcase check_str_to_uint64_n_all_chars() failed.\n\n"); 2379 } 2380 else if (verbose > 1) 2381 printf ("PASSED: testcase check_str_to_uint64_n_all_chars() " 2382 "successfully passed.\n\n"); 2383 2384 res = check_str_to_uint64_n_overflow (); 2385 if (res != 0) 2386 { 2387 str_to_uint64_n_fails += res; 2388 fprintf (stderr, 2389 "FAILED: testcase check_str_to_uint64_n_overflow() failed.\n\n"); 2390 } 2391 else if (verbose > 1) 2392 printf ("PASSED: testcase check_str_to_uint64_n_overflow() " 2393 "successfully passed.\n\n"); 2394 2395 res = check_str_to_uint64_n_no_val (); 2396 if (res != 0) 2397 { 2398 str_to_uint64_n_fails += res; 2399 fprintf (stderr, 2400 "FAILED: testcase check_str_to_uint64_n_no_val() failed.\n\n"); 2401 } 2402 else if (verbose > 1) 2403 printf ("PASSED: testcase check_str_to_uint64_n_no_val() " 2404 "successfully passed.\n\n"); 2405 2406 if (str_to_uint64_n_fails) 2407 fprintf (stderr, 2408 "FAILED: function mhd_str_to_uint64_n() failed %lu time%s.\n\n", 2409 (unsigned long)str_to_uint64_n_fails, 2410 str_to_uint64_n_fails == 1 ? "" : "s"); 2411 else if (verbose > 0) 2412 printf ("PASSED: function mhd_str_to_uint64_n() successfully " 2413 "passed all checks.\n\n"); 2414 2415 res = check_strx_to_uint32_valid (); 2416 if (res != 0) 2417 { 2418 strx_to_uint32_fails += res; 2419 fprintf (stderr, 2420 "FAILED: testcase check_strx_to_uint32_valid() failed.\n\n"); 2421 } 2422 else if (verbose > 1) 2423 printf ("PASSED: testcase check_strx_to_uint32_valid() " 2424 "successfully passed.\n\n"); 2425 2426 res = check_strx_to_uint32_all_chars (); 2427 if (res != 0) 2428 { 2429 strx_to_uint32_fails += res; 2430 fprintf (stderr, 2431 "FAILED: testcase check_strx_to_uint32_all_chars() failed.\n\n"); 2432 } 2433 else if (verbose > 1) 2434 printf ("PASSED: testcase check_strx_to_uint32_all_chars() " 2435 "successfully passed.\n\n"); 2436 2437 res = check_strx_to_uint32_overflow (); 2438 if (res != 0) 2439 { 2440 strx_to_uint32_fails += res; 2441 fprintf (stderr, 2442 "FAILED: testcase check_strx_to_uint32_overflow() failed.\n\n"); 2443 } 2444 else if (verbose > 1) 2445 printf ("PASSED: testcase check_strx_to_uint32_overflow() " 2446 "successfully passed.\n\n"); 2447 2448 res = check_strx_to_uint32_no_val (); 2449 if (res != 0) 2450 { 2451 strx_to_uint32_fails += res; 2452 fprintf (stderr, 2453 "FAILED: testcase check_strx_to_uint32_no_val() failed.\n\n"); 2454 } 2455 else if (verbose > 1) 2456 printf ("PASSED: testcase check_strx_to_uint32_no_val() " 2457 "successfully passed.\n\n"); 2458 2459 if (strx_to_uint32_fails) 2460 fprintf (stderr, 2461 "FAILED: function mhd_strx_to_uint32() failed %lu time%s.\n\n", 2462 (unsigned long)strx_to_uint32_fails, 2463 strx_to_uint32_fails == 1 ? "" : "s"); 2464 else if (verbose > 0) 2465 printf ("PASSED: function mhd_strx_to_uint32() successfully " 2466 "passed all checks.\n\n"); 2467 2468 res = check_strx_to_uint32_n_valid (); 2469 if (res != 0) 2470 { 2471 strx_to_uint32_n_fails += res; 2472 fprintf (stderr, 2473 "FAILED: testcase check_strx_to_uint32_n_valid() failed.\n\n"); 2474 } 2475 else if (verbose > 1) 2476 printf ("PASSED: testcase check_strx_to_uint32_n_valid() " 2477 "successfully passed.\n\n"); 2478 2479 res = check_strx_to_uint32_n_all_chars (); 2480 if (res != 0) 2481 { 2482 strx_to_uint32_n_fails += res; 2483 fprintf (stderr, 2484 "FAILED: testcase check_strx_to_uint32_n_all_chars() failed.\n\n"); 2485 } 2486 else if (verbose > 1) 2487 printf ("PASSED: testcase check_strx_to_uint32_n_all_chars() " 2488 "successfully passed.\n\n"); 2489 2490 res = check_strx_to_uint32_n_overflow (); 2491 if (res != 0) 2492 { 2493 strx_to_uint32_n_fails += res; 2494 fprintf (stderr, 2495 "FAILED: testcase check_strx_to_uint32_n_overflow() failed.\n\n"); 2496 } 2497 else if (verbose > 1) 2498 printf ("PASSED: testcase check_strx_to_uint32_n_overflow() " 2499 "successfully passed.\n\n"); 2500 2501 res = check_strx_to_uint32_n_no_val (); 2502 if (res != 0) 2503 { 2504 strx_to_uint32_n_fails += res; 2505 fprintf (stderr, 2506 "FAILED: testcase check_strx_to_uint32_n_no_val() failed.\n\n"); 2507 } 2508 else if (verbose > 1) 2509 printf ("PASSED: testcase check_strx_to_uint32_n_no_val() " 2510 "successfully passed.\n\n"); 2511 2512 if (strx_to_uint32_n_fails) 2513 fprintf (stderr, 2514 "FAILED: function mhd_strx_to_uint32_n() failed %lu time%s.\n\n", 2515 (unsigned long)strx_to_uint32_n_fails, 2516 strx_to_uint32_n_fails == 1 ? "" : "s"); 2517 else if (verbose > 0) 2518 printf ("PASSED: function mhd_strx_to_uint32_n() successfully " 2519 "passed all checks.\n\n"); 2520 2521 res = check_strx_to_uint64_valid (); 2522 if (res != 0) 2523 { 2524 strx_to_uint64_fails += res; 2525 fprintf (stderr, 2526 "FAILED: testcase check_strx_to_uint64_valid() failed.\n\n"); 2527 } 2528 else if (verbose > 1) 2529 printf ("PASSED: testcase check_strx_to_uint64_valid() " 2530 "successfully passed.\n\n"); 2531 2532 res = check_strx_to_uint64_all_chars (); 2533 if (res != 0) 2534 { 2535 strx_to_uint64_fails += res; 2536 fprintf (stderr, 2537 "FAILED: testcase check_strx_to_uint64_all_chars() failed.\n\n"); 2538 } 2539 else if (verbose > 1) 2540 printf ("PASSED: testcase check_strx_to_uint64_all_chars() " 2541 "successfully passed.\n\n"); 2542 2543 res = check_strx_to_uint64_overflow (); 2544 if (res != 0) 2545 { 2546 strx_to_uint64_fails += res; 2547 fprintf (stderr, 2548 "FAILED: testcase check_strx_to_uint64_overflow() failed.\n\n"); 2549 } 2550 else if (verbose > 1) 2551 printf ("PASSED: testcase check_strx_to_uint64_overflow() " 2552 "successfully passed.\n\n"); 2553 2554 res = check_strx_to_uint64_no_val (); 2555 if (res != 0) 2556 { 2557 strx_to_uint64_fails += res; 2558 fprintf (stderr, 2559 "FAILED: testcase check_strx_to_uint64_no_val() failed.\n\n"); 2560 } 2561 else if (verbose > 1) 2562 printf ("PASSED: testcase check_strx_to_uint64_no_val() " 2563 "successfully passed.\n\n"); 2564 2565 if (strx_to_uint64_fails) 2566 fprintf (stderr, 2567 "FAILED: function mhd_strx_to_uint64() failed %lu time%s.\n\n", 2568 (unsigned long)strx_to_uint64_fails, 2569 strx_to_uint64_fails == 1 ? "" : "s"); 2570 else if (verbose > 0) 2571 printf ("PASSED: function mhd_strx_to_uint64() successfully " 2572 "passed all checks.\n\n"); 2573 2574 res = check_strx_to_uint64_n_valid (); 2575 if (res != 0) 2576 { 2577 strx_to_uint64_n_fails += res; 2578 fprintf (stderr, 2579 "FAILED: testcase check_strx_to_uint64_n_valid() failed.\n\n"); 2580 } 2581 else if (verbose > 1) 2582 printf ("PASSED: testcase check_strx_to_uint64_n_valid() " 2583 "successfully passed.\n\n"); 2584 2585 res = check_strx_to_uint64_n_all_chars (); 2586 if (res != 0) 2587 { 2588 strx_to_uint64_n_fails += res; 2589 fprintf (stderr, 2590 "FAILED: testcase check_strx_to_uint64_n_all_chars() failed.\n\n"); 2591 } 2592 else if (verbose > 1) 2593 printf ("PASSED: testcase check_strx_to_uint64_n_all_chars() " 2594 "successfully passed.\n\n"); 2595 2596 res = check_strx_to_uint64_n_overflow (); 2597 if (res != 0) 2598 { 2599 strx_to_uint64_n_fails += res; 2600 fprintf (stderr, 2601 "FAILED: testcase check_strx_to_uint64_n_overflow() failed.\n\n"); 2602 } 2603 else if (verbose > 1) 2604 printf ("PASSED: testcase check_strx_to_uint64_n_overflow() " 2605 "successfully passed.\n\n"); 2606 2607 res = check_strx_to_uint64_n_no_val (); 2608 if (res != 0) 2609 { 2610 strx_to_uint64_n_fails += res; 2611 fprintf (stderr, 2612 "FAILED: testcase check_strx_to_uint64_n_no_val() failed.\n\n"); 2613 } 2614 else if (verbose > 1) 2615 printf ("PASSED: testcase check_strx_to_uint64_n_no_val() " 2616 "successfully passed.\n\n"); 2617 2618 if (strx_to_uint64_n_fails) 2619 fprintf (stderr, 2620 "FAILED: function mhd_strx_to_uint64_n() failed %lu time%s.\n\n", 2621 (unsigned long)strx_to_uint64_n_fails, 2622 strx_to_uint64_n_fails == 1 ? "" : "s"); 2623 else if (verbose > 0) 2624 printf ("PASSED: function mhd_strx_to_uint64_n() successfully " 2625 "passed all checks.\n\n"); 2626 2627 if (str_to_uint64_fails || str_to_uint64_n_fails 2628 || strx_to_uint32_fails || strx_to_uint32_n_fails 2629 || strx_to_uint64_fails || strx_to_uint64_n_fails) 2630 { 2631 if (verbose > 0) 2632 printf ("At least one test failed.\n"); 2633 2634 return 1; 2635 } 2636 2637 if (verbose > 0) 2638 printf ("All tests passed successfully.\n"); 2639 2640 return 0; 2641 } 2642 2643 2644 int 2645 main (int argc, char *argv[]) 2646 { 2647 if (mhdt_has_param (argc, argv, "-v") 2648 || mhdt_has_param (argc, argv, "--verbose") 2649 || mhdt_has_param (argc, argv, "--verbose1")) 2650 MHDT_set_verbosity (MHDT_VERB_LVL_BASIC); 2651 if (mhdt_has_param (argc, argv, "-vv") 2652 || mhdt_has_param (argc, argv, "--verbose2")) 2653 MHDT_set_verbosity (MHDT_VERB_LVL_VERBOSE); 2654 2655 return run_str_to_X_tests (); 2656 }