libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

test_str.c (156948B)


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