summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2016-07-23 18:55:15 +0000
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2016-07-23 18:55:15 +0000
commit8433e1cbbf289b67a540a728796e901b65e58a88 (patch)
tree60a161c4eff611883f39a1886943528f674a839d
parent13498fcdb606819b00c28de10f8c7688b698ef74 (diff)
Added unit tests for number in string to value conversions.
-rw-r--r--configure.ac2
-rw-r--r--src/microhttpd/Makefile.am4
-rw-r--r--src/microhttpd/unit_str_test.c2718
-rw-r--r--w32/common/MHD_config.h5
4 files changed, 2726 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac
index 26c2cfa7..e5ea2590 100644
--- a/configure.ac
+++ b/configure.ac
@@ -421,7 +421,7 @@ fi
AC_CHECK_HEADERS([fcntl.h math.h errno.h limits.h stdio.h locale.h sys/stat.h sys/types.h pthread.h],,AC_MSG_ERROR([Compiling libmicrohttpd requires standard UNIX headers files]))
# Check for optional headers
-AC_CHECK_HEADERS([sys/types.h sys/time.h sys/msg.h netdb.h netinet/in.h netinet/tcp.h time.h sys/socket.h sys/mman.h arpa/inet.h sys/select.h search.h endian.h machine/endian.h sys/endian.h sys/param.h sys/machine.h sys/byteorder.h machine/param.h sys/isa_defs.h])
+AC_CHECK_HEADERS([sys/types.h sys/time.h sys/msg.h netdb.h netinet/in.h netinet/tcp.h time.h sys/socket.h sys/mman.h arpa/inet.h sys/select.h search.h endian.h machine/endian.h sys/endian.h sys/param.h sys/machine.h sys/byteorder.h machine/param.h sys/isa_defs.h inttypes.h])
AM_CONDITIONAL([HAVE_TSEARCH], [test "x$ac_cv_header_search_h" = "xyes"])
AC_CHECK_MEMBER([struct sockaddr_in.sin_len],
diff --git a/src/microhttpd/Makefile.am b/src/microhttpd/Makefile.am
index 680201af..86c8879a 100644
--- a/src/microhttpd/Makefile.am
+++ b/src/microhttpd/Makefile.am
@@ -142,6 +142,7 @@ endif
check_PROGRAMS = \
unit_str_compare \
+ unit_str_to_value \
test_shutdown_select \
test_shutdown_poll \
test_daemon
@@ -209,3 +210,6 @@ endif
unit_str_compare_SOURCES = \
unit_str_test.c test_helpers.h mhd_str.c
+
+unit_str_to_value_SOURCES = \
+ unit_str_test.c test_helpers.h mhd_str.c
diff --git a/src/microhttpd/unit_str_test.c b/src/microhttpd/unit_str_test.c
index ec2cbbe6..c6ba1690 100644
--- a/src/microhttpd/unit_str_test.c
+++ b/src/microhttpd/unit_str_test.c
@@ -27,6 +27,13 @@
#include <locale.h>
#include <string.h>
#include "mhd_options.h"
+#ifdef HAVE_INTTYPES_H
+#include <inttypes.h>
+#else /* ! HAVE_INTTYPES_H */
+#define PRIu64 "llu"
+#define PRIuPTR "u"
+#define PRIX64 "llX"
+#endif /* ! HAVE_INTTYPES_H */
#include <stdint.h>
#include "mhd_limits.h"
#include "mhd_str.h"
@@ -107,7 +114,10 @@ static const char * const locale_names[] = {
"Russian_Russia.1251",
"Russian_Russia.20866",
"Russian_Russia.28595",
- "Russian_Russia.65001"
+ "Russian_Russia.65001",
+ "zh-Hans",
+ "zh-Hans.936",
+ "chinese-simplified"
#else /* ! _WIN32 || __CYGWIN__ */
"C.UTF-8",
"POSIX",
@@ -183,7 +193,10 @@ static const char * const locale_names[] = {
"ru_RU.ISO_8859-5",
"ru_RU.ISO8859-5",
"ru_RU.iso88595",
- "ru_RU.UTF-8"
+ "ru_RU.UTF-8",
+ "zh_CN",
+ "zh_CN.GB2312",
+ "zh_CN.UTF-8",
#endif /* ! _WIN32 || __CYGWIN__ */
};
@@ -773,6 +786,2704 @@ int run_eq_neq_str_tests(void)
return 0;
}
+/*
+ * Digits in string -> value tests
+ */
+
+struct str_with_value {
+ const struct str_with_len str;
+ const size_t num_of_digt;
+ const uint64_t val;
+};
+
+/* valid string for conversion to unsigned integer value */
+static const struct str_with_value dstrs_w_values[] = {
+ /* simplest strings */
+ {D_STR_W_LEN("1"), 1, 1},
+ {D_STR_W_LEN("0"), 1, 0},
+ {D_STR_W_LEN("10000"), 5, 10000},
+
+ /* all digits */
+ {D_STR_W_LEN("1234"), 4, 1234},
+ {D_STR_W_LEN("4567"), 4, 4567},
+ {D_STR_W_LEN("7890"), 4, 7890},
+ {D_STR_W_LEN("8021"), 4, 8021},
+ {D_STR_W_LEN("9754"), 4, 9754},
+ {D_STR_W_LEN("6392"), 4, 6392},
+
+ /* various prefixes */
+ {D_STR_W_LEN("00000000"), 8, 0},
+ {D_STR_W_LEN("0755"), 4, 755}, /* not to be interpreted as octal value! */
+ {D_STR_W_LEN("002"), 3, 2},
+ {D_STR_W_LEN("0001"), 4, 1},
+ {D_STR_W_LEN("00000000000000000000000031295483"), 32, 31295483},
+
+ /* numbers below and above limits */
+ {D_STR_W_LEN("127"), 3, 127}, /* 0x7F, SCHAR_MAX */
+ {D_STR_W_LEN("128"), 3, 128}, /* 0x80, SCHAR_MAX+1 */
+ {D_STR_W_LEN("255"), 3, 255}, /* 0xFF, UCHAR_MAX */
+ {D_STR_W_LEN("256"), 3, 256}, /* 0x100, UCHAR_MAX+1 */
+ {D_STR_W_LEN("32767"), 5, 32767}, /* 0x7FFF, INT16_MAX */
+ {D_STR_W_LEN("32768"), 5, 32768}, /* 0x8000, INT16_MAX+1 */
+ {D_STR_W_LEN("65535"), 5, 65535}, /* 0xFFFF, UINT16_MAX */
+ {D_STR_W_LEN("65536"), 5, 65536}, /* 0x10000, UINT16_MAX+1 */
+ {D_STR_W_LEN("2147483647"), 10, 2147483647}, /* 0x7FFFFFFF, INT32_MAX */
+ {D_STR_W_LEN("2147483648"), 10, UINT64_C(2147483648)}, /* 0x80000000, INT32_MAX+1 */
+ {D_STR_W_LEN("4294967295"), 10, UINT64_C(4294967295)}, /* 0xFFFFFFFF, UINT32_MAX */
+ {D_STR_W_LEN("4294967296"), 10, UINT64_C(4294967296)}, /* 0x100000000, UINT32_MAX+1 */
+ {D_STR_W_LEN("9223372036854775807"), 19, UINT64_C(9223372036854775807)}, /* 0x7FFFFFFFFFFFFFFF, INT64_MAX */
+ {D_STR_W_LEN("9223372036854775808"), 19, UINT64_C(9223372036854775808)}, /* 0x8000000000000000, INT64_MAX+1 */
+ {D_STR_W_LEN("18446744073709551615"), 20, UINT64_C(18446744073709551615)}, /* 0xFFFFFFFFFFFFFFFF, UINT64_MAX */
+
+ /* random numbers */
+ {D_STR_W_LEN("10186753"), 8, 10186753},
+ {D_STR_W_LEN("144402566"), 9, 144402566},
+ {D_STR_W_LEN("151903144"), 9, 151903144},
+ {D_STR_W_LEN("139264621"), 9, 139264621},
+ {D_STR_W_LEN("730348"), 6, 730348},
+ {D_STR_W_LEN("21584377"), 8, 21584377},
+ {D_STR_W_LEN("709"), 3, 709},
+ {D_STR_W_LEN("54"), 2, 54},
+ {D_STR_W_LEN("8452"), 4, 8452},
+ {D_STR_W_LEN("17745098750013624977"), 20, UINT64_C(17745098750013624977)},
+ {D_STR_W_LEN("06786878769931678000"), 20, UINT64_C(6786878769931678000)},
+
+ /* non-digit suffixes */
+ {D_STR_W_LEN("1234oa"), 4, 1234},
+ {D_STR_W_LEN("20h"), 2, 20}, /* not to be interpreted as hex value! */
+ {D_STR_W_LEN("0x1F"), 1, 0}, /* not to be interpreted as hex value! */
+ {D_STR_W_LEN("0564`~}"), 4, 564},
+ {D_STR_W_LEN("7240146.724"), 7, 7240146},
+ {D_STR_W_LEN("2,9"), 1, 2},
+ {D_STR_W_LEN("200+1"), 3, 200},
+ {D_STR_W_LEN("1a"), 1, 1},
+ {D_STR_W_LEN("2E"), 1, 2},
+ {D_STR_W_LEN("6c"), 1, 6},
+ {D_STR_W_LEN("8F"), 1, 8},
+ {D_STR_W_LEN("287416997! And the not too long string."), 9, 287416997}
+};
+
+/* strings that should overflow uint64_t */
+const struct str_with_len str_ovflw[] = {
+ D_STR_W_LEN("18446744073709551616"), /* 0x10000000000000000, UINT64_MAX+1 */
+ D_STR_W_LEN("18446744073709551620"),
+ D_STR_W_LEN("18446744083709551615"),
+ D_STR_W_LEN("19234761020556472143"),
+ D_STR_W_LEN("184467440737095516150"),
+ D_STR_W_LEN("1844674407370955161500"),
+ D_STR_W_LEN("000018446744073709551616"), /* 0x10000000000000000, UINT64_MAX+1 */
+ D_STR_W_LEN("20000000000000000000"),
+ D_STR_W_LEN("020000000000000000000"),
+ D_STR_W_LEN("0020000000000000000000"),
+ D_STR_W_LEN("100000000000000000000"),
+ D_STR_W_LEN("434532891232591226417"),
+ D_STR_W_LEN("99999999999999999999"),
+ D_STR_W_LEN("18446744073709551616abcd"), /* 0x10000000000000000, UINT64_MAX+1 */
+ D_STR_W_LEN("20000000000000000000 suffix"),
+ D_STR_W_LEN("020000000000000000000x")
+};
+
+/* strings that should not be convertible to numeric value */
+const struct str_with_len str_no_num[] = {
+ D_STR_W_LEN("zero"),
+ D_STR_W_LEN("one"),
+ D_STR_W_LEN("\xb9\xb2\xb3"), /* superscript "123" in ISO-8859-1/CP1252 */
+ D_STR_W_LEN("\xc2\xb9\xc2\xb2\xc2\xb3"), /* superscript "123" in UTF-8 */
+ D_STR_W_LEN("\xd9\xa1\xd9\xa2\xd9\xa3"), /* Arabic-Indic "١٢٣" in UTF-8 */
+ D_STR_W_LEN("\xdb\xb1\xdb\xb2\xdb\xb3"), /* Ext Arabic-Indic "۱۲۳" in UTF-8 */
+ D_STR_W_LEN("\xe0\xa5\xa7\xe0\xa5\xa8\xe0\xa5\xa9"), /* Devanagari "१२३" in UTF-8 */
+ D_STR_W_LEN("\xe4\xb8\x80\xe4\xba\x8c\xe4\xb8\x89"), /* Chinese "一二三" in UTF-8 */
+ D_STR_W_LEN("\xd2\xbb\xb6\xfe\xc8\xfd"), /* Chinese "一二三" in GB2312/CP936 */
+ D_STR_W_LEN("\x1B\x24\x29\x41\x0E\x52\x3B\x36\x7E\x48\x7D\x0F") /* Chinese "一二三" in ISO-2022-CN */
+};
+
+/* valid hex string for conversion to unsigned integer value */
+static const struct str_with_value xdstrs_w_values[] = {
+ /* simplest strings */
+ {D_STR_W_LEN("1"), 1, 0x1},
+ {D_STR_W_LEN("0"), 1, 0x0},
+ {D_STR_W_LEN("10000"), 5, 0x10000},
+
+ /* all digits */
+ {D_STR_W_LEN("1234"), 4, 0x1234},
+ {D_STR_W_LEN("4567"), 4, 0x4567},
+ {D_STR_W_LEN("7890"), 4, 0x7890},
+ {D_STR_W_LEN("8021"), 4, 0x8021},
+ {D_STR_W_LEN("9754"), 4, 0x9754},
+ {D_STR_W_LEN("6392"), 4, 0x6392},
+ {D_STR_W_LEN("abcd"), 4, 0xABCD},
+ {D_STR_W_LEN("cdef"), 4, 0xCDEF},
+ {D_STR_W_LEN("FEAB"), 4, 0xFEAB},
+ {D_STR_W_LEN("BCED"), 4, 0xBCED},
+ {D_STR_W_LEN("bCeD"), 4, 0xBCED},
+ {D_STR_W_LEN("1A5F"), 4, 0x1A5F},
+ {D_STR_W_LEN("12AB"), 4, 0x12AB},
+ {D_STR_W_LEN("CD34"), 4, 0xCD34},
+ {D_STR_W_LEN("56EF"), 4, 0x56EF},
+ {D_STR_W_LEN("7a9f"), 4, 0x7A9F},
+
+ /* various prefixes */
+ {D_STR_W_LEN("00000000"), 8, 0x0},
+ {D_STR_W_LEN("0755"), 4, 0x755}, /* not to be interpreted as octal value! */
+ {D_STR_W_LEN("002"), 3, 0x2},
+ {D_STR_W_LEN("0001"), 4, 0x1},
+ {D_STR_W_LEN("00a"), 3, 0xA},
+ {D_STR_W_LEN("0F"), 2, 0xF},
+ {D_STR_W_LEN("0000000000000000000000003A29e4C3"), 32, 0x3A29E4C3},
+
+ /* numbers below and above limits */
+ {D_STR_W_LEN("7F"), 2, 127}, /* 0x7F, SCHAR_MAX */
+ {D_STR_W_LEN("7f"), 2, 127}, /* 0x7F, SCHAR_MAX */
+ {D_STR_W_LEN("80"), 2, 128}, /* 0x80, SCHAR_MAX+1 */
+ {D_STR_W_LEN("fF"), 2, 255}, /* 0xFF, UCHAR_MAX */
+ {D_STR_W_LEN("Ff"), 2, 255}, /* 0xFF, UCHAR_MAX */
+ {D_STR_W_LEN("FF"), 2, 255}, /* 0xFF, UCHAR_MAX */
+ {D_STR_W_LEN("ff"), 2, 255}, /* 0xFF, UCHAR_MAX */
+ {D_STR_W_LEN("100"), 3, 256}, /* 0x100, UCHAR_MAX+1 */
+ {D_STR_W_LEN("7fff"), 4, 32767}, /* 0x7FFF, INT16_MAX */
+ {D_STR_W_LEN("7FFF"), 4, 32767}, /* 0x7FFF, INT16_MAX */
+ {D_STR_W_LEN("7Fff"), 4, 32767}, /* 0x7FFF, INT16_MAX */
+ {D_STR_W_LEN("8000"), 4, 32768}, /* 0x8000, INT16_MAX+1 */
+ {D_STR_W_LEN("ffff"), 4, 65535}, /* 0xFFFF, UINT16_MAX */
+ {D_STR_W_LEN("FFFF"), 4, 65535}, /* 0xFFFF, UINT16_MAX */
+ {D_STR_W_LEN("FffF"), 4, 65535}, /* 0xFFFF, UINT16_MAX */
+ {D_STR_W_LEN("10000"), 5, 65536}, /* 0x10000, UINT16_MAX+1 */
+ {D_STR_W_LEN("7FFFFFFF"), 8, 2147483647}, /* 0x7FFFFFFF, INT32_MAX */
+ {D_STR_W_LEN("7fffffff"), 8, 2147483647}, /* 0x7FFFFFFF, INT32_MAX */
+ {D_STR_W_LEN("7FFffFff"), 8, 2147483647}, /* 0x7FFFFFFF, INT32_MAX */
+ {D_STR_W_LEN("80000000"), 8, UINT64_C(2147483648)}, /* 0x80000000, INT32_MAX+1 */
+ {D_STR_W_LEN("FFFFFFFF"), 8, UINT64_C(4294967295)}, /* 0xFFFFFFFF, UINT32_MAX */
+ {D_STR_W_LEN("ffffffff"), 8, UINT64_C(4294967295)}, /* 0xFFFFFFFF, UINT32_MAX */
+ {D_STR_W_LEN("FfFfFfFf"), 8, UINT64_C(4294967295)}, /* 0xFFFFFFFF, UINT32_MAX */
+ {D_STR_W_LEN("100000000"), 9, UINT64_C(4294967296)}, /* 0x100000000, UINT32_MAX+1 */
+ {D_STR_W_LEN("7fffffffffffffff"), 16, UINT64_C(9223372036854775807)}, /* 0x7FFFFFFFFFFFFFFF, INT64_MAX */
+ {D_STR_W_LEN("7FFFFFFFFFFFFFFF"), 16, UINT64_C(9223372036854775807)}, /* 0x7FFFFFFFFFFFFFFF, INT64_MAX */
+ {D_STR_W_LEN("7FfffFFFFffFFffF"), 16, UINT64_C(9223372036854775807)}, /* 0x7FFFFFFFFFFFFFFF, INT64_MAX */
+ {D_STR_W_LEN("8000000000000000"), 16, UINT64_C(9223372036854775808)}, /* 0x8000000000000000, INT64_MAX+1 */
+ {D_STR_W_LEN("ffffffffffffffff"), 16, UINT64_C(18446744073709551615)}, /* 0xFFFFFFFFFFFFFFFF, UINT64_MAX */
+ {D_STR_W_LEN("FFFFFFFFFFFFFFFF"), 16, UINT64_C(18446744073709551615)}, /* 0xFFFFFFFFFFFFFFFF, UINT64_MAX */
+ {D_STR_W_LEN("FffFffFFffFFfFFF"), 16, UINT64_C(18446744073709551615)}, /* 0xFFFFFFFFFFFFFFFF, UINT64_MAX */
+
+ /* random numbers */
+ {D_STR_W_LEN("10186753"), 8, 0x10186753},
+ {D_STR_W_LEN("144402566"), 9, 0x144402566},
+ {D_STR_W_LEN("151903144"), 9, 0x151903144},
+ {D_STR_W_LEN("139264621"), 9, 0x139264621},
+ {D_STR_W_LEN("730348"), 6, 0x730348},
+ {D_STR_W_LEN("21584377"), 8, 0x21584377},
+ {D_STR_W_LEN("709"), 3, 0x709},
+ {D_STR_W_LEN("54"), 2, 0x54},
+ {D_STR_W_LEN("8452"), 4, 0x8452},
+ {D_STR_W_LEN("22353EC6"), 8, 0x22353EC6},
+ {D_STR_W_LEN("307F1655"), 8, 0x307F1655},
+ {D_STR_W_LEN("1FCB7226"), 8, 0x1FCB7226},
+ {D_STR_W_LEN("82480560"), 8, 0x82480560},
+ {D_STR_W_LEN("7386D95"), 7, 0x7386D95},
+ {D_STR_W_LEN("EC3AB"), 5, 0xEC3AB},
+ {D_STR_W_LEN("6DD05"), 5, 0x6DD05},
+ {D_STR_W_LEN("C5DF"), 4, 0xC5DF},
+ {D_STR_W_LEN("6CE"), 3, 0x6CE},
+ {D_STR_W_LEN("CE6"), 3, 0xCE6},
+ {D_STR_W_LEN("ce6"), 3, 0xCE6},
+ {D_STR_W_LEN("F27"), 3, 0xF27},
+ {D_STR_W_LEN("8497D54277D7E1"), 14, UINT64_C(37321639124785121)},
+ {D_STR_W_LEN("8497d54277d7e1"), 14, UINT64_C(37321639124785121)},
+ {D_STR_W_LEN("8497d54277d7E1"), 14, UINT64_C(37321639124785121)},
+ {D_STR_W_LEN("8C8112D0A06"), 11, UINT64_C(9655374645766)},
+ {D_STR_W_LEN("8c8112d0a06"), 11, UINT64_C(9655374645766)},
+ {D_STR_W_LEN("8c8112d0A06"), 11, UINT64_C(9655374645766)},
+ {D_STR_W_LEN("1774509875001362"), 16, UINT64_C(1690064375898968930)},
+ {D_STR_W_LEN("0678687876998000"), 16, UINT64_C(466237428027981824)},
+
+ /* non-digit suffixes */
+ {D_STR_W_LEN("1234oa"), 4, 0x1234},
+ {D_STR_W_LEN("20h"), 2, 0x20},
+ {D_STR_W_LEN("2CH"), 2, 0x2C},
+ {D_STR_W_LEN("2ch"), 2, 0x2C},
+ {D_STR_W_LEN("0x1F"), 1, 0x0}, /* not to be interpreted as hex prefix! */
+ {D_STR_W_LEN("0564`~}"), 4, 0x564},
+ {D_STR_W_LEN("0A64`~}"), 4, 0xA64},
+ {D_STR_W_LEN("056c`~}"), 4, 0X56C},
+ {D_STR_W_LEN("7240146.724"), 7, 0x7240146},
+ {D_STR_W_LEN("7E4c1AB.724"), 7, 0X7E4C1AB},
+ {D_STR_W_LEN("F24B1B6.724"), 7, 0xF24B1B6},
+ {D_STR_W_LEN("2,9"), 1, 0x2},
+ {D_STR_W_LEN("a,9"), 1, 0xA},
+ {D_STR_W_LEN("200+1"), 3, 0x200},
+ {D_STR_W_LEN("2cc+1"), 3, 0x2CC},
+ {D_STR_W_LEN("2cC+1"), 3, 0x2CC},
+ {D_STR_W_LEN("27416997! And the not too long string."), 8, 0x27416997},
+ {D_STR_W_LEN("27555416997! And the not too long string."), 11, 0x27555416997},
+ {D_STR_W_LEN("416997And the not too long string."), 7, 0x416997A},
+ {D_STR_W_LEN("0F4C3Dabstract addition to make string even longer"), 8, 0xF4C3DAB}
+};
+
+/* hex strings that should overflow uint64_t */
+const struct str_with_len strx_ovflw[] = {
+ D_STR_W_LEN("10000000000000000"), /* 0x10000000000000000, UINT64_MAX+1 */
+ D_STR_W_LEN("10000000000000001"),
+ D_STR_W_LEN("10000000000000002"),
+ D_STR_W_LEN("1000000000000000A"),
+ D_STR_W_LEN("11000000000000000"),
+ D_STR_W_LEN("010000000000000000"), /* 0x10000000000000000, UINT64_MAX+1 */
+ D_STR_W_LEN("000010000000000000000"), /* 0x10000000000000000, UINT64_MAX+1 */
+ D_STR_W_LEN("20000000000000000000"),
+ D_STR_W_LEN("020000000000000000000"),
+ D_STR_W_LEN("0020000000000000000000"),
+ D_STR_W_LEN("20000000000000000"),
+ D_STR_W_LEN("A0000000000000000"),
+ D_STR_W_LEN("F0000000000000000"),
+ D_STR_W_LEN("a0000000000000000"),
+ D_STR_W_LEN("11111111111111111"),
+ D_STR_W_LEN("CcCcCCccCCccCCccC"),
+ D_STR_W_LEN("f0000000000000000"),
+ D_STR_W_LEN("100000000000000000000"),
+ D_STR_W_LEN("434532891232591226417"),
+ D_STR_W_LEN("10000000000000000a"),
+ D_STR_W_LEN("10000000000000000E"),
+ D_STR_W_LEN("100000000000000000 and nothing"), /* 0x10000000000000000, UINT64_MAX+1 */
+ D_STR_W_LEN("100000000000000000xx"), /* 0x10000000000000000, UINT64_MAX+1 */
+ D_STR_W_LEN("99999999999999999999"),
+ D_STR_W_LEN("18446744073709551616abcd"),
+ D_STR_W_LEN("20000000000000000000 suffix"),
+ D_STR_W_LEN("020000000000000000000x")
+};
+
+
+int check_str_to_uint64_valid(void)
+{
+ size_t t_failed = 0;
+ size_t i, j;
+ static const size_t n_checks = sizeof(dstrs_w_values) / sizeof(dstrs_w_values[0]);
+ int c_failed[n_checks];
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(i = 0; i < n_checks; i++)
+ {
+ uint64_t rv;
+ size_t rs;
+ const struct str_with_value * const t = dstrs_w_values + i;
+
+ if (c_failed[i])
+ continue; /* skip already failed checks */
+
+ if (t->str.len < t->num_of_digt)
+ {
+ fprintf(stderr, "ERROR: dstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected"
+ " to be less or equal to str.len (%u).\n",
+ (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned int) t->str.len);
+ return -1;
+ }
+ rv = 9435223; /* some random value */
+ rs = MHD_str_to_uint64_(t->str.str, &rv);
+ if (rs != t->num_of_digt)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_str_to_uint64_(\"%s\", ->%" PRIu64 ") returned %" PRIuPTR ", while expecting %d."
+ " Locale: %s\n", n_prnt(t->str.str), rv, (intptr_t)rs, (int)t->num_of_digt, get_current_locale_str());
+ }
+ if (rv != t->val)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_str_to_uint64_(\"%s\", ->%" PRIu64 ") converted string to value %" PRIu64 ","
+ " while expecting result %" PRIu64 ". Locale: %s\n", n_prnt(t->str.str), rv, rv,
+ t->val, get_current_locale_str());
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
+ printf("PASSED: MHD_str_to_uint64_(\"%s\", ->%" PRIu64 ") == %" PRIuPTR "\n",
+ n_prnt(t->str.str), rv, rs);
+ }
+ }
+ return t_failed;
+}
+
+
+int check_str_to_uint64_all_chars(void)
+{
+ static const size_t n_checks = 256; /* from 0 to 255 */
+ int c_failed[n_checks];
+ size_t t_failed = 0;
+ size_t j;
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ unsigned int c;
+ uint64_t test_val;
+
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(c = 0; c < n_checks; c++)
+ {
+ static const uint64_t rnd_val = 24941852;
+ size_t rs;
+ if (c >= '0' && c <= '9')
+ continue; /* skip digits */
+ for(test_val = 0; test_val <= rnd_val&& !c_failed[c]; test_val += rnd_val)
+ {
+ char test_str[] = "0123";
+ uint64_t rv = test_val;
+
+ test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */
+ rs = MHD_str_to_uint64_(test_str, &rv);
+ if (rs != 0)
+ {
+ t_failed++;
+ c_failed[c] = !0;
+ fprintf(stderr, "FAILED: MHD_str_to_uint64_(\"%s\", ->%" PRIu64 ") returned %" PRIuPTR ", while expecting zero."
+ " Locale: %s\n", n_prnt(test_str), rv, (uintptr_t)rs, get_current_locale_str());
+ }
+ else if (rv != test_val)
+ {
+ t_failed++;
+ c_failed[c] = !0;
+ fprintf(stderr, "FAILED: MHD_str_to_uint64_(\"%s\", &ret_val) modified value of ret_val"
+ " (before call: %" PRIu64 ", after call %" PRIu64 "). Locale: %s\n",
+ n_prnt(test_str), test_val, rv, get_current_locale_str());
+ }
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[c])
+ {
+ char test_str[] = "0123";
+ test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */
+
+ printf("PASSED: MHD_str_to_uint64_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
+ n_prnt(test_str));
+ }
+ }
+ }
+ return t_failed;
+}
+
+
+int check_str_to_uint64_overflow(void)
+{
+ size_t t_failed = 0;
+ size_t i, j;
+ static const size_t n_checks = sizeof(str_ovflw) / sizeof(str_ovflw[0]);
+ int c_failed[n_checks];
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(i = 0; i < n_checks; i++)
+ {
+ size_t rs;
+ const struct str_with_len * const t = str_ovflw + i;
+ static const uint64_t rnd_val = 2;
+ uint64_t test_val;
+
+ for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val)
+ {
+ uint64_t rv = test_val;
+
+ rs = MHD_str_to_uint64_(t->str, &rv);
+ if (rs != 0)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_str_to_uint64_(\"%s\", ->%" PRIu64 ") returned %" PRIuPTR ", while expecting zero."
+ " Locale: %s\n", n_prnt(t->str), rv, (uintptr_t)rs, get_current_locale_str());
+ }
+ else if (rv != test_val)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_str_to_uint64_(\"%s\", &ret_val) modified value of ret_val"
+ " (before call: %" PRIu64 ", after call %" PRIu64 "). Locale: %s\n",
+ n_prnt(t->str), test_val, rv, get_current_locale_str());
+ }
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
+ printf("PASSED: MHD_str_to_uint64_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
+ n_prnt(t->str));
+ }
+ }
+ return t_failed;
+}
+
+
+int check_str_to_uint64_no_val(void)
+{
+ size_t t_failed = 0;
+ size_t i, j;
+ static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]);
+ int c_failed[n_checks];
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(i = 0; i < n_checks; i++)
+ {
+ size_t rs;
+ const struct str_with_len * const t = str_no_num + i;
+ static const uint64_t rnd_val = 74218431;
+ uint64_t test_val;
+
+ for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val)
+ {
+ uint64_t rv = test_val;
+
+ rs = MHD_str_to_uint64_(t->str, &rv);
+ if (rs != 0)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_str_to_uint64_(\"%s\", ->%" PRIu64 ") returned %" PRIuPTR ", while expecting zero."
+ " Locale: %s\n", n_prnt(t->str), rv, (uintptr_t)rs, get_current_locale_str());
+ }
+ else if (rv != test_val)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_str_to_uint64_(\"%s\", &ret_val) modified value of ret_val"
+ " (before call: %" PRIu64 ", after call %" PRIu64 "). Locale: %s\n",
+ n_prnt(t->str), test_val, rv, get_current_locale_str());
+ }
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
+ printf("PASSED: MHD_str_to_uint64_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
+ n_prnt(t->str));
+ }
+ }
+ return t_failed;
+}
+
+
+int check_str_to_uint64_n_valid(void)
+{
+ size_t t_failed = 0;
+ size_t i, j;
+ static const size_t n_checks = sizeof(dstrs_w_values) / sizeof(dstrs_w_values[0]);
+ int c_failed[n_checks];
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(i = 0; i < n_checks; i++)
+ {
+ uint64_t rv;
+ size_t rs = 0;
+ size_t len;
+ const struct str_with_value * const t = dstrs_w_values + i;
+
+ if (t->str.len < t->num_of_digt)
+ {
+ fprintf(stderr, "ERROR: dstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected"
+ " to be less or equal to str.len (%u).\n",
+ (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned int) t->str.len);
+ return -1;
+ }
+ for (len = t->num_of_digt; len <= t->str.len + 1 && !c_failed[i]; len++)
+ {
+ rv = 1235572; /* some random value */
+ rs = MHD_str_to_uint64_n_(t->str.str, len, &rv);
+ if (rs != t->num_of_digt)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", ->%" PRIu64 ")"
+ " returned %" PRIuPTR ", while expecting %d. Locale: %s\n",
+ n_prnt(t->str.str), (intptr_t)len, rv, (intptr_t)rs,
+ (int)t->num_of_digt, get_current_locale_str());
+ }
+ if (rv != t->val)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", ->%" PRIu64 ")"
+ " converted string to value %" PRIu64 ", while expecting result %" PRIu64
+ ". Locale: %s\n", n_prnt(t->str.str), (intptr_t)len, rv, rv,
+ t->val, get_current_locale_str());
+ }
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
+ printf("PASSED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR ", ->%" PRIu64 ")"
+ " == %" PRIuPTR "\n", n_prnt(t->str.str), (intptr_t)t->num_of_digt,
+ (intptr_t)t->str.len + 1, rv, rs);
+ }
+ }
+ return t_failed;
+}
+
+
+int check_str_to_uint64_n_all_chars(void)
+{
+ static const size_t n_checks = 256; /* from 0 to 255 */
+ int c_failed[n_checks];
+ size_t t_failed = 0;
+ size_t j;
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ unsigned int c;
+ uint64_t test_val;
+
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(c = 0; c < n_checks; c++)
+ {
+ static const uint64_t rnd_val = 98372558;
+ size_t rs;
+ size_t len;
+
+ if (c >= '0' && c <= '9')
+ continue; /* skip digits */
+
+ for (len = 0; len <= 5; len++)
+ {
+ for(test_val = 0; test_val <= rnd_val&& !c_failed[c]; test_val += rnd_val)
+ {
+ char test_str[] = "0123";
+ uint64_t rv = test_val;
+
+ test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */
+ rs = MHD_str_to_uint64_n_(test_str, len, &rv);
+ if (rs != 0)
+ {
+ t_failed++;
+ c_failed[c] = !0;
+ fprintf(stderr, "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", ->%" PRIu64 ")"
+ " returned %" PRIuPTR ", while expecting zero. Locale: %s\n",
+ n_prnt(test_str), (uintptr_t)len, rv, (uintptr_t)rs, get_current_locale_str());
+ }
+ else if (rv != test_val)
+ {
+ t_failed++;
+ c_failed[c] = !0;
+ fprintf(stderr, "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", &ret_val)"
+ " modified value of ret_val (before call: %" PRIu64 ", after call %" PRIu64 ")."
+ " Locale: %s\n",
+ n_prnt(test_str), (uintptr_t)len, test_val, rv, get_current_locale_str());
+ }
+ }
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[c])
+ {
+ char test_str[] = "0123";
+ test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */
+
+ printf("PASSED: MHD_str_to_uint64_n_(\"%s\", 0..5, &ret_val) == 0, value of ret_val is unmodified\n",
+ n_prnt(test_str));
+ }
+ }
+ }
+ return t_failed;
+}
+
+
+int check_str_to_uint64_n_overflow(void)
+{
+ size_t t_failed = 0;
+ size_t i, j;
+ static const size_t n_checks = sizeof(str_ovflw) / sizeof(str_ovflw[0]);
+ int c_failed[n_checks];
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(i = 0; i < n_checks; i++)
+ {
+ size_t rs;
+ const struct str_with_len * const t = str_ovflw + i;
+ static const uint64_t rnd_val = 3;
+ size_t len;
+
+ for (len = t->len; len <= t->len + 1; len++)
+ {
+ uint64_t test_val;
+ for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val)
+ {
+ uint64_t rv = test_val;
+
+ rs = MHD_str_to_uint64_n_(t->str, len, &rv);
+ if (rs != 0)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", ->%" PRIu64 ")"
+ " returned %" PRIuPTR ", while expecting zero. Locale: %s\n",
+ n_prnt(t->str), (uintptr_t)len, rv, (uintptr_t)rs, get_current_locale_str());
+ }
+ else if (rv != test_val)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", &ret_val)"
+ " modified value of ret_val (before call: %" PRIu64 ", after call %" PRIu64 ")."
+ " Locale: %s\n", n_prnt(t->str), (uintptr_t)len, test_val, rv,
+ get_current_locale_str());
+ }
+ }
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
+ printf("PASSED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR ", &ret_val) == 0,"
+ " value of ret_val is unmodified\n", n_prnt(t->str), (uintptr_t)t->len,
+ (uintptr_t)t->len + 1);
+ }
+ }
+ return t_failed;
+}
+
+
+int check_str_to_uint64_n_no_val(void)
+{
+ size_t t_failed = 0;
+ size_t i, j;
+ static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]);
+ int c_failed[n_checks];
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(i = 0; i < n_checks; i++)
+ {
+ size_t rs;
+ const struct str_with_len * const t = str_no_num + i;
+ static const uint64_t rnd_val = 43255654342;
+ size_t len;
+
+ for (len = 0; len <= t->len + 1; len++)
+ {
+ uint64_t test_val;
+ for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val)
+ {
+ uint64_t rv = test_val;
+
+ rs = MHD_str_to_uint64_n_(t->str, len, &rv);
+ if (rs != 0)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", ->%" PRIu64 ")"
+ " returned %" PRIuPTR ", while expecting zero. Locale: %s\n",
+ n_prnt(t->str), (uintptr_t)len, rv, (uintptr_t)rs, get_current_locale_str());
+ }
+ else if (rv != test_val)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_str_to_uint64_n_(\"%s\", %" PRIuPTR ", &ret_val)"
+ " modified value of ret_val (before call: %" PRIu64 ", after call %" PRIu64 ")."
+ " Locale: %s\n", n_prnt(t->str), (uintptr_t)len, test_val, rv,
+ get_current_locale_str());
+ }
+ }
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
+ printf("PASSED: MHD_str_to_uint64_n_(\"%s\", 0..%" PRIuPTR ", &ret_val) == 0,"
+ " value of ret_val is unmodified\n", n_prnt(t->str),
+ (uintptr_t)t->len + 1);
+ }
+ }
+ return t_failed;
+}
+
+
+int check_strx_to_sizet_valid(void)
+{
+ size_t t_failed = 0;
+ size_t i, j;
+ static const size_t n_checks = sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]);
+ int c_failed[n_checks];
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(i = 0; i < n_checks; i++)
+ {
+ size_t rv;
+ size_t rs;
+ const struct str_with_value * const t = xdstrs_w_values + i;
+
+#if SIZE_MAX != UINT64_MAX
+ if (t->val > SIZE_MAX)
+ continue; /* number is too high for this function */
+#endif /* SIZE_MAX != UINT64_MAX */
+
+ if (c_failed[i])
+ continue; /* skip already failed checks */
+
+ if (t->str.len < t->num_of_digt)
+ {
+ fprintf(stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected"
+ " to be less or equal to str.len (%u).\n",
+ (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned int) t->str.len);
+ return -1;
+ }
+ rv = 1458532; /* some random value */
+ rs = MHD_strx_to_sizet_(t->str.str, &rv);
+ if (rs != t->num_of_digt)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting %d."
+ " Locale: %s\n", n_prnt(t->str.str), (uint64_t)rv, (intptr_t)rs, (int)t->num_of_digt, get_current_locale_str());
+ }
+ if (rv != t->val)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", ->0x%" PRIX64 ") converted string to value 0x%" PRIX64 ","
+ " while expecting result 0x%" PRIX64 ". Locale: %s\n", n_prnt(t->str.str), (uint64_t)rv, (uint64_t)rv,
+ t->val, get_current_locale_str());
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
+ printf("PASSED: MHD_strx_to_sizet_(\"%s\", ->0x%" PRIX64 ") == %" PRIuPTR "\n",
+ n_prnt(t->str.str), (uint64_t)rv, rs);
+ }
+ }
+ return t_failed;
+}
+
+
+int check_strx_to_sizet_all_chars(void)
+{
+ static const size_t n_checks = 256; /* from 0 to 255 */
+ int c_failed[n_checks];
+ size_t t_failed = 0;
+ size_t j;
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ unsigned int c;
+ size_t test_val;
+
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(c = 0; c < n_checks; c++)
+ {
+ static const size_t rnd_val = 234234;
+ size_t rs;
+ if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') ||(c >= 'a' && c <= 'f'))
+ continue; /* skip xdigits */
+ for(test_val = 0; test_val <= rnd_val&& !c_failed[c]; test_val += rnd_val)
+ {
+ char test_str[] = "0123";
+ size_t rv = test_val;
+
+ test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */
+ rs = MHD_strx_to_sizet_(test_str, &rv);
+ if (rs != 0)
+ {
+ t_failed++;
+ c_failed[c] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting zero."
+ " Locale: %s\n", n_prnt(test_str), (uint64_t)rv, (uintptr_t)rs, get_current_locale_str());
+ }
+ else if (rv != test_val)
+ {
+ t_failed++;
+ c_failed[c] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", &ret_val) modified value of ret_val"
+ " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 "). Locale: %s\n",
+ n_prnt(test_str), (uint64_t)test_val, (uint64_t)rv, get_current_locale_str());
+ }
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[c])
+ {
+ char test_str[] = "0123";
+ test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */
+
+ printf("PASSED: MHD_strx_to_sizet_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
+ n_prnt(test_str));
+ }
+ }
+ }
+ return t_failed;
+}
+
+
+int check_strx_to_sizet_overflow(void)
+{
+ size_t t_failed = 0;
+ size_t i, j;
+ static const size_t n_checks1 = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]);
+#if SIZE_MAX != UINT64_MAX
+ static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]) +
+ sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]);
+#else /* SIZE_MAX == UINT64_MAX */
+ static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]);
+#endif /* SIZE_MAX == UINT64_MAX */
+ int c_failed[n_checks];
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(i = 0; i < n_checks; i++)
+ {
+ size_t rs;
+ static const size_t rnd_val = 74218431;
+ size_t test_val;
+ const char * str;
+ if (i < n_checks1)
+ {
+ const struct str_with_len * const t = strx_ovflw + i;
+ str = t->str;
+ }
+#if SIZE_MAX != UINT64_MAX
+ else
+ {
+ const struct str_with_value * const t = xdstrs_w_values + (i - n_checks1);
+ if (t->val <= SIZE_MAX)
+ continue; /* check only strings that should overflow size_t */
+ str = t->str.str;
+ }
+#else /* SIZE_MAX == UINT64_MAX */
+ else
+ continue; /* silent compiler warning */
+#endif /* SIZE_MAX == UINT64_MAX */
+
+
+ for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val)
+ {
+ size_t rv = test_val;
+
+ rs = MHD_strx_to_sizet_(str, &rv);
+ if (rs != 0)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting zero."
+ " Locale: %s\n", n_prnt(str), (uint64_t)rv, (uintptr_t)rs, get_current_locale_str());
+ }
+ else if (rv != test_val)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", &ret_val) modified value of ret_val"
+ " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 "). Locale: %s\n",
+ n_prnt(str), (uint64_t)test_val, (uint64_t)rv, get_current_locale_str());
+ }
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
+ printf("PASSED: MHD_strx_to_sizet_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
+ n_prnt(str));
+ }
+ }
+ return t_failed;
+}
+
+
+int check_strx_to_sizet_no_val(void)
+{
+ size_t t_failed = 0;
+ size_t i, j;
+ static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]);
+ int c_failed[n_checks];
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(i = 0; i < n_checks; i++)
+ {
+ size_t rs;
+ const struct str_with_len * const t = str_no_num + i;
+ static const size_t rnd_val = 74218431;
+ size_t test_val;
+
+ for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val)
+ {
+ size_t rv = test_val;
+
+ rs = MHD_strx_to_sizet_(t->str, &rv);
+ if (rs != 0)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting zero."
+ " Locale: %s\n", n_prnt(t->str), (uint64_t)rv, (uintptr_t)rs, get_current_locale_str());
+ }
+ else if (rv != test_val)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", &ret_val) modified value of ret_val"
+ " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 "). Locale: %s\n",
+ n_prnt(t->str), (uint64_t)test_val, (uint64_t)rv, get_current_locale_str());
+ }
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
+ printf("PASSED: MHD_strx_to_sizet_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
+ n_prnt(t->str));
+ }
+ }
+ return t_failed;
+}
+
+
+int check_strx_to_sizet_n_valid(void)
+{
+ size_t t_failed = 0;
+ size_t i, j;
+ static const size_t n_checks = sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]);
+ int c_failed[n_checks];
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(i = 0; i < n_checks; i++)
+ {
+ size_t rv;
+ size_t rs = 0;
+ size_t len;
+ const struct str_with_value * const t = xdstrs_w_values + i;
+
+#if SIZE_MAX != UINT64_MAX
+ if (t->val > SIZE_MAX)
+ continue; /* number is too high for this function */
+#endif /* SIZE_MAX != UINT64_MAX */
+
+ if (t->str.len < t->num_of_digt)
+ {
+ fprintf(stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected"
+ " to be less or equal to str.len (%u).\n",
+ (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned int) t->str.len);
+ return -1;
+ }
+ for (len = t->num_of_digt; len <= t->str.len + 1 && !c_failed[i]; len++)
+ {
+ rv = 2352932; /* some random value */
+ rs = MHD_strx_to_sizet_n_(t->str.str, len, &rv);
+ if (rs != t->num_of_digt)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")"
+ " returned %" PRIuPTR ", while expecting %d. Locale: %s\n",
+ n_prnt(t->str.str), (intptr_t)len, (uint64_t)rv, (intptr_t)rs,
+ (int)t->num_of_digt, get_current_locale_str());
+ }
+ if (rv != t->val)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")"
+ " converted string to value 0x%" PRIX64 ", while expecting result 0x%" PRIX64
+ ". Locale: %s\n", n_prnt(t->str.str), (intptr_t)len, (uint64_t)rv, (uint64_t)rv,
+ t->val, get_current_locale_str());
+ }
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
+ printf("PASSED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR ", ->0x%" PRIX64 ")"
+ " == %" PRIuPTR "\n", n_prnt(t->str.str), (intptr_t)t->num_of_digt,
+ (intptr_t)t->str.len + 1, (uint64_t)rv, rs);
+ }
+ }
+ return t_failed;
+}
+
+
+int check_strx_to_sizet_n_all_chars(void)
+{
+ static const size_t n_checks = 256; /* from 0 to 255 */
+ int c_failed[n_checks];
+ size_t t_failed = 0;
+ size_t j;
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ unsigned int c;
+ size_t test_val;
+
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(c = 0; c < n_checks; c++)
+ {
+ static const size_t rnd_val = 98372558;
+ size_t rs;
+ size_t len;
+
+ if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'))
+ continue; /* skip xdigits */
+
+ for (len = 0; len <= 5; len++)
+ {
+ for(test_val = 0; test_val <= rnd_val&& !c_failed[c]; test_val += rnd_val)
+ {
+ char test_str[] = "0123";
+ size_t rv = test_val;
+
+ test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */
+ rs = MHD_strx_to_sizet_n_(test_str, len, &rv);
+ if (rs != 0)
+ {
+ t_failed++;
+ c_failed[c] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")"
+ " returned %" PRIuPTR ", while expecting zero. Locale: %s\n",
+ n_prnt(test_str), (uintptr_t)len, (uint64_t)rv, (uintptr_t)rs, get_current_locale_str());
+ }
+ else if (rv != test_val)
+ {
+ t_failed++;
+ c_failed[c] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", &ret_val)"
+ " modified value of ret_val (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 ")."
+ " Locale: %s\n",
+ n_prnt(test_str), (uintptr_t)len, (uint64_t)test_val, (uint64_t)rv, get_current_locale_str());
+ }
+ }
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[c])
+ {
+ char test_str[] = "0123";
+ test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */
+
+ printf("PASSED: MHD_strx_to_sizet_n_(\"%s\", 0..5, &ret_val) == 0, value of ret_val is unmodified\n",
+ n_prnt(test_str));
+ }
+ }
+ }
+ return t_failed;
+}
+
+
+int check_strx_to_sizet_n_overflow(void)
+{
+ size_t t_failed = 0;
+ size_t i, j;
+ static const size_t n_checks1 = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]);
+#if SIZE_MAX != UINT64_MAX
+ static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]) +
+ sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]);
+#else /* SIZE_MAX == UINT64_MAX */
+ static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]);
+#endif /* SIZE_MAX == UINT64_MAX */
+ int c_failed[n_checks];
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(i = 0; i < n_checks; i++)
+ {
+ size_t rs;
+ static const size_t rnd_val = 4;
+ size_t len;
+ const char * str;
+ size_t min_len, max_len;
+ if (i < n_checks1)
+ {
+ const struct str_with_len * const t = strx_ovflw + i;
+ str = t->str;
+ min_len = t->len;
+ max_len = t->len + 1;
+ }
+#if SIZE_MAX != UINT64_MAX
+ else
+ {
+ const struct str_with_value * const t = xdstrs_w_values + (i - n_checks1);
+ if (t->val <= SIZE_MAX)
+ continue; /* check only strings that should overflow size_t */
+
+ if (t->str.len < t->num_of_digt)
+ {
+ fprintf(stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected"
+ " to be less or equal to str.len (%u).\n",
+ (unsigned int) (i - n_checks1), (unsigned int) t->num_of_digt,
+ (unsigned int) t->str.len);
+ return -1;
+ }
+ str = t->str.str;
+ min_len = t->num_of_digt;
+ max_len = t->str.len + 1;
+ }
+#else /* SIZE_MAX == UINT64_MAX */
+ else
+ continue; /* silent compiler warning */
+#endif /* SIZE_MAX == UINT64_MAX */
+
+ for (len = min_len; len <= max_len; len++)
+ {
+ size_t test_val;
+ for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val)
+ {
+ size_t rv = test_val;
+
+ rs = MHD_strx_to_sizet_n_(str, len, &rv);
+ if (rs != 0)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")"
+ " returned %" PRIuPTR ", while expecting zero. Locale: %s\n",
+ n_prnt(str), (uintptr_t)len, (uint64_t)rv, (uintptr_t)rs, get_current_locale_str());
+ }
+ else if (rv != test_val)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", &ret_val)"
+ " modified value of ret_val (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 ")."
+ " Locale: %s\n", n_prnt(str), (uintptr_t)len, (uint64_t)test_val, (uint64_t)rv,
+ get_current_locale_str());
+ }
+ }
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
+ printf("PASSED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR ", &ret_val) == 0,"
+ " value of ret_val is unmodified\n", n_prnt(str), (uintptr_t)min_len,
+ (uintptr_t)max_len);
+ }
+ }
+ return t_failed;
+}
+
+
+int check_strx_to_sizet_n_no_val(void)
+{
+ size_t t_failed = 0;
+ size_t i, j;
+ static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]);
+ int c_failed[n_checks];
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(i = 0; i < n_checks; i++)
+ {
+ size_t rs;
+ const struct str_with_len * const t = str_no_num + i;
+ static const size_t rnd_val = 3214314212;
+ size_t len;
+
+ for (len = 0; len <= t->len + 1; len++)
+ {
+ size_t test_val;
+ for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val)
+ {
+ size_t rv = test_val;
+
+ rs = MHD_strx_to_sizet_n_(t->str, len, &rv);
+ if (rs != 0)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")"
+ " returned %" PRIuPTR ", while expecting zero. Locale: %s\n",
+ n_prnt(t->str), (uintptr_t)len, (uint64_t)rv, (uintptr_t)rs, get_current_locale_str());
+ }
+ else if (rv != test_val)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", &ret_val)"
+ " modified value of ret_val (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 ")."
+ " Locale: %s\n", n_prnt(t->str), (uintptr_t)len, (uint64_t)test_val, (uint64_t)rv,
+ get_current_locale_str());
+ }
+ }
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
+ printf("PASSED: MHD_strx_to_sizet_n_(\"%s\", 0..%" PRIuPTR ", &ret_val) == 0,"
+ " value of ret_val is unmodified\n", n_prnt(t->str),
+ (uintptr_t)t->len + 1);
+ }
+ }
+ return t_failed;
+}
+
+
+int check_strx_to_uint32_valid(void)
+{
+ size_t t_failed = 0;
+ size_t i, j;
+ static const size_t n_checks = sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]);
+ int c_failed[n_checks];
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(i = 0; i < n_checks; i++)
+ {
+ uint32_t rv;
+ size_t rs;
+ const struct str_with_value * const t = xdstrs_w_values + i;
+
+ if (t->val > UINT32_MAX)
+ continue; /* number is too high for this function */
+
+ if (c_failed[i])
+ continue; /* skip already failed checks */
+
+ if (t->str.len < t->num_of_digt)
+ {
+ fprintf(stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected"
+ " to be less or equal to str.len (%u).\n",
+ (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned int) t->str.len);
+ return -1;
+ }
+ rv = 1458532; /* some random value */
+ rs = MHD_strx_to_uint32_(t->str.str, &rv);
+ if (rs != t->num_of_digt)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint32_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting %d."
+ " Locale: %s\n", n_prnt(t->str.str), (uint64_t)rv, (intptr_t)rs, (int)t->num_of_digt, get_current_locale_str());
+ }
+ if (rv != t->val)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint32_(\"%s\", ->0x%" PRIX64 ") converted string to value 0x%" PRIX64 ","
+ " while expecting result 0x%" PRIX64 ". Locale: %s\n", n_prnt(t->str.str), (uint64_t)rv, (uint64_t)rv,
+ t->val, get_current_locale_str());
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
+ printf("PASSED: MHD_strx_to_uint32_(\"%s\", ->0x%" PRIX64 ") == %" PRIuPTR "\n",
+ n_prnt(t->str.str), (uint64_t)rv, rs);
+ }
+ }
+ return t_failed;
+}
+
+
+int check_strx_to_uint32_all_chars(void)
+{
+ static const size_t n_checks = 256; /* from 0 to 255 */
+ int c_failed[n_checks];
+ size_t t_failed = 0;
+ size_t j;
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ unsigned int c;
+ uint32_t test_val;
+
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(c = 0; c < n_checks; c++)
+ {
+ static const uint32_t rnd_val = 234234;
+ size_t rs;
+ if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') ||(c >= 'a' && c <= 'f'))
+ continue; /* skip xdigits */
+ for(test_val = 0; test_val <= rnd_val&& !c_failed[c]; test_val += rnd_val)
+ {
+ char test_str[] = "0123";
+ uint32_t rv = test_val;
+
+ test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */
+ rs = MHD_strx_to_uint32_(test_str, &rv);
+ if (rs != 0)
+ {
+ t_failed++;
+ c_failed[c] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint32_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting zero."
+ " Locale: %s\n", n_prnt(test_str), (uint64_t)rv, (uintptr_t)rs, get_current_locale_str());
+ }
+ else if (rv != test_val)
+ {
+ t_failed++;
+ c_failed[c] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint32_(\"%s\", &ret_val) modified value of ret_val"
+ " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 "). Locale: %s\n",
+ n_prnt(test_str), (uint64_t)test_val, (uint64_t)rv, get_current_locale_str());
+ }
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[c])
+ {
+ char test_str[] = "0123";
+ test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */
+
+ printf("PASSED: MHD_strx_to_uint32_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
+ n_prnt(test_str));
+ }
+ }
+ }
+ return t_failed;
+}
+
+
+int check_strx_to_uint32_overflow(void)
+{
+ size_t t_failed = 0;
+ size_t i, j;
+ static const size_t n_checks1 = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]);
+ static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]) +
+ sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]);
+ int c_failed[n_checks];
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(i = 0; i < n_checks; i++)
+ {
+ size_t rs;
+ static const uint32_t rnd_val = 74218431;
+ uint32_t test_val;
+ const char * str;
+ if (i < n_checks1)
+ {
+ const struct str_with_len * const t = strx_ovflw + i;
+ str = t->str;
+ }
+ else
+ {
+ const struct str_with_value * const t = xdstrs_w_values + (i - n_checks1);
+ if (t->val <= UINT32_MAX)
+ continue; /* check only strings that should overflow uint32_t */
+ str = t->str.str;
+ }
+
+
+ for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val)
+ {
+ uint32_t rv = test_val;
+
+ rs = MHD_strx_to_uint32_(str, &rv);
+ if (rs != 0)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint32_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting zero."
+ " Locale: %s\n", n_prnt(str), (uint64_t)rv, (uintptr_t)rs, get_current_locale_str());
+ }
+ else if (rv != test_val)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint32_(\"%s\", &ret_val) modified value of ret_val"
+ " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 "). Locale: %s\n",
+ n_prnt(str), (uint64_t)test_val, (uint64_t)rv, get_current_locale_str());
+ }
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
+ printf("PASSED: MHD_strx_to_uint32_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
+ n_prnt(str));
+ }
+ }
+ return t_failed;
+}
+
+
+int check_strx_to_uint32_no_val(void)
+{
+ size_t t_failed = 0;
+ size_t i, j;
+ static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]);
+ int c_failed[n_checks];
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(i = 0; i < n_checks; i++)
+ {
+ size_t rs;
+ const struct str_with_len * const t = str_no_num + i;
+ static const uint32_t rnd_val = 74218431;
+ uint32_t test_val;
+
+ for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val)
+ {
+ uint32_t rv = test_val;
+
+ rs = MHD_strx_to_uint32_(t->str, &rv);
+ if (rs != 0)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint32_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting zero."
+ " Locale: %s\n", n_prnt(t->str), (uint64_t)rv, (uintptr_t)rs, get_current_locale_str());
+ }
+ else if (rv != test_val)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint32_(\"%s\", &ret_val) modified value of ret_val"
+ " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 "). Locale: %s\n",
+ n_prnt(t->str), (uint64_t)test_val, (uint64_t)rv, get_current_locale_str());
+ }
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
+ printf("PASSED: MHD_strx_to_uint32_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
+ n_prnt(t->str));
+ }
+ }
+ return t_failed;
+}
+
+
+int check_strx_to_uint32_n_valid(void)
+{
+ size_t t_failed = 0;
+ size_t i, j;
+ static const size_t n_checks = sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]);
+ int c_failed[n_checks];
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(i = 0; i < n_checks; i++)
+ {
+ uint32_t rv;
+ size_t rs = 0;
+ size_t len;
+ const struct str_with_value * const t = xdstrs_w_values + i;
+
+ if (t->val > UINT32_MAX)
+ continue; /* number is too high for this function */
+
+ if (t->str.len < t->num_of_digt)
+ {
+ fprintf(stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected"
+ " to be less or equal to str.len (%u).\n",
+ (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned int) t->str.len);
+ return -1;
+ }
+ for (len = t->num_of_digt; len <= t->str.len + 1 && !c_failed[i]; len++)
+ {
+ rv = 2352932; /* some random value */
+ rs = MHD_strx_to_uint32_n_(t->str.str, len, &rv);
+ if (rs != t->num_of_digt)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")"
+ " returned %" PRIuPTR ", while expecting %d. Locale: %s\n",
+ n_prnt(t->str.str), (intptr_t)len, (uint64_t)rv, (intptr_t)rs,
+ (int)t->num_of_digt, get_current_locale_str());
+ }
+ if (rv != t->val)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")"
+ " converted string to value 0x%" PRIX64 ", while expecting result 0x%" PRIX64
+ ". Locale: %s\n", n_prnt(t->str.str), (intptr_t)len, (uint64_t)rv, (uint64_t)rv,
+ t->val, get_current_locale_str());
+ }
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
+ printf("PASSED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR ", ->0x%" PRIX64 ")"
+ " == %" PRIuPTR "\n", n_prnt(t->str.str), (intptr_t)t->num_of_digt,
+ (intptr_t)t->str.len + 1, (uint64_t)rv, rs);
+ }
+ }
+ return t_failed;
+}
+
+
+int check_strx_to_uint32_n_all_chars(void)
+{
+ static const size_t n_checks = 256; /* from 0 to 255 */
+ int c_failed[n_checks];
+ size_t t_failed = 0;
+ size_t j;
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ unsigned int c;
+ uint32_t test_val;
+
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(c = 0; c < n_checks; c++)
+ {
+ static const uint32_t rnd_val = 98372558;
+ size_t rs;
+ size_t len;
+
+ if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'))
+ continue; /* skip xdigits */
+
+ for (len = 0; len <= 5; len++)
+ {
+ for(test_val = 0; test_val <= rnd_val&& !c_failed[c]; test_val += rnd_val)
+ {
+ char test_str[] = "0123";
+ uint32_t rv = test_val;
+
+ test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */
+ rs = MHD_strx_to_uint32_n_(test_str, len, &rv);
+ if (rs != 0)
+ {
+ t_failed++;
+ c_failed[c] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")"
+ " returned %" PRIuPTR ", while expecting zero. Locale: %s\n",
+ n_prnt(test_str), (uintptr_t)len, (uint64_t)rv, (uintptr_t)rs, get_current_locale_str());
+ }
+ else if (rv != test_val)
+ {
+ t_failed++;
+ c_failed[c] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", &ret_val)"
+ " modified value of ret_val (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 ")."
+ " Locale: %s\n",
+ n_prnt(test_str), (uintptr_t)len, (uint64_t)test_val, (uint64_t)rv, get_current_locale_str());
+ }
+ }
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[c])
+ {
+ char test_str[] = "0123";
+ test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */
+
+ printf("PASSED: MHD_strx_to_uint32_n_(\"%s\", 0..5, &ret_val) == 0, value of ret_val is unmodified\n",
+ n_prnt(test_str));
+ }
+ }
+ }
+ return t_failed;
+}
+
+
+int check_strx_to_uint32_n_overflow(void)
+{
+ size_t t_failed = 0;
+ size_t i, j;
+ static const size_t n_checks1 = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]);
+ static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]) +
+ sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]);
+ int c_failed[n_checks];
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(i = 0; i < n_checks; i++)
+ {
+ size_t rs;
+ static const uint32_t rnd_val = 4;
+ size_t len;
+ const char * str;
+ size_t min_len, max_len;
+ if (i < n_checks1)
+ {
+ const struct str_with_len * const t = strx_ovflw + i;
+ str = t->str;
+ min_len = t->len;
+ max_len = t->len + 1;
+ }
+ else
+ {
+ const struct str_with_value * const t = xdstrs_w_values + (i - n_checks1);
+ if (t->val <= UINT32_MAX)
+ continue; /* check only strings that should overflow uint32_t */
+
+ if (t->str.len < t->num_of_digt)
+ {
+ fprintf(stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected"
+ " to be less or equal to str.len (%u).\n",
+ (unsigned int) (i - n_checks1), (unsigned int) t->num_of_digt,
+ (unsigned int) t->str.len);
+ return -1;
+ }
+ str = t->str.str;
+ min_len = t->num_of_digt;
+ max_len = t->str.len + 1;
+ }
+
+ for (len = min_len; len <= max_len; len++)
+ {
+ uint32_t test_val;
+ for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val)
+ {
+ uint32_t rv = test_val;
+
+ rs = MHD_strx_to_uint32_n_(str, len, &rv);
+ if (rs != 0)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")"
+ " returned %" PRIuPTR ", while expecting zero. Locale: %s\n",
+ n_prnt(str), (uintptr_t)len, (uint64_t)rv, (uintptr_t)rs, get_current_locale_str());
+ }
+ else if (rv != test_val)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", &ret_val)"
+ " modified value of ret_val (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 ")."
+ " Locale: %s\n", n_prnt(str), (uintptr_t)len, (uint64_t)test_val, (uint64_t)rv,
+ get_current_locale_str());
+ }
+ }
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
+ printf("PASSED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR ", &ret_val) == 0,"
+ " value of ret_val is unmodified\n", n_prnt(str), (uintptr_t)min_len,
+ (uintptr_t)max_len);
+ }
+ }
+ return t_failed;
+}
+
+
+int check_strx_to_uint32_n_no_val(void)
+{
+ size_t t_failed = 0;
+ size_t i, j;
+ static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]);
+ int c_failed[n_checks];
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(i = 0; i < n_checks; i++)
+ {
+ size_t rs;
+ const struct str_with_len * const t = str_no_num + i;
+ static const uint32_t rnd_val = 3214314212;
+ size_t len;
+
+ for (len = 0; len <= t->len + 1; len++)
+ {
+ uint32_t test_val;
+ for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val)
+ {
+ uint32_t rv = test_val;
+
+ rs = MHD_strx_to_uint32_n_(t->str, len, &rv);
+ if (rs != 0)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")"
+ " returned %" PRIuPTR ", while expecting zero. Locale: %s\n",
+ n_prnt(t->str), (uintptr_t)len, (uint64_t)rv, (uintptr_t)rs, get_current_locale_str());
+ }
+ else if (rv != test_val)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint32_n_(\"%s\", %" PRIuPTR ", &ret_val)"
+ " modified value of ret_val (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 ")."
+ " Locale: %s\n", n_prnt(t->str), (uintptr_t)len, (uint64_t)test_val, (uint64_t)rv,
+ get_current_locale_str());
+ }
+ }
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
+ printf("PASSED: MHD_strx_to_uint32_n_(\"%s\", 0..%" PRIuPTR ", &ret_val) == 0,"
+ " value of ret_val is unmodified\n", n_prnt(t->str),
+ (uintptr_t)t->len + 1);
+ }
+ }
+ return t_failed;
+}
+
+
+int check_strx_to_uint64_valid(void)
+{
+ size_t t_failed = 0;
+ size_t i, j;
+ static const size_t n_checks = sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]);
+ int c_failed[n_checks];
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(i = 0; i < n_checks; i++)
+ {
+ uint64_t rv;
+ size_t rs;
+ const struct str_with_value * const t = xdstrs_w_values + i;
+
+ if (c_failed[i])
+ continue; /* skip already failed checks */
+
+ if (t->str.len < t->num_of_digt)
+ {
+ fprintf(stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected"
+ " to be less or equal to str.len (%u).\n",
+ (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned int) t->str.len);
+ return -1;
+ }
+ rv = 1458532; /* some random value */
+ rs = MHD_strx_to_uint64_(t->str.str, &rv);
+ if (rs != t->num_of_digt)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint64_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting %d."
+ " Locale: %s\n", n_prnt(t->str.str), rv, (intptr_t)rs, (int)t->num_of_digt, get_current_locale_str());
+ }
+ if (rv != t->val)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint64_(\"%s\", ->0x%" PRIX64 ") converted string to value 0x%" PRIX64 ","
+ " while expecting result 0x%" PRIX64 ". Locale: %s\n", n_prnt(t->str.str), rv, rv,
+ t->val, get_current_locale_str());
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
+ printf("PASSED: MHD_strx_to_uint64_(\"%s\", ->0x%" PRIX64 ") == %" PRIuPTR "\n",
+ n_prnt(t->str.str), rv, rs);
+ }
+ }
+ return t_failed;
+}
+
+
+int check_strx_to_uint64_all_chars(void)
+{
+ static const size_t n_checks = 256; /* from 0 to 255 */
+ int c_failed[n_checks];
+ size_t t_failed = 0;
+ size_t j;
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ unsigned int c;
+ uint64_t test_val;
+
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(c = 0; c < n_checks; c++)
+ {
+ static const uint64_t rnd_val = 234234;
+ size_t rs;
+ if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'))
+ continue; /* skip xdigits */
+ for(test_val = 0; test_val <= rnd_val&& !c_failed[c]; test_val += rnd_val)
+ {
+ char test_str[] = "0123";
+ uint64_t rv = test_val;
+
+ test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */
+ rs = MHD_strx_to_uint64_(test_str, &rv);
+ if (rs != 0)
+ {
+ t_failed++;
+ c_failed[c] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint64_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting zero."
+ " Locale: %s\n", n_prnt(test_str), rv, (uintptr_t)rs, get_current_locale_str());
+ }
+ else if (rv != test_val)
+ {
+ t_failed++;
+ c_failed[c] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint64_(\"%s\", &ret_val) modified value of ret_val"
+ " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 "). Locale: %s\n",
+ n_prnt(test_str), test_val, rv, get_current_locale_str());
+ }
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[c])
+ {
+ char test_str[] = "0123";
+ test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */
+
+ printf("PASSED: MHD_strx_to_uint64_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
+ n_prnt(test_str));
+ }
+ }
+ }
+ return t_failed;
+}
+
+
+int check_strx_to_uint64_overflow(void)
+{
+ size_t t_failed = 0;
+ size_t i, j;
+ static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]);
+ int c_failed[n_checks];
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(i = 0; i < n_checks; i++)
+ {
+ size_t rs;
+ const struct str_with_len * const t = strx_ovflw + i;
+ static const uint64_t rnd_val = 74218431;
+ uint64_t test_val;
+
+ for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val)
+ {
+ uint64_t rv = test_val;
+
+ rs = MHD_strx_to_uint64_(t->str, &rv);
+ if (rs != 0)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint64_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting zero."
+ " Locale: %s\n", n_prnt(t->str), rv, (uintptr_t)rs, get_current_locale_str());
+ }
+ else if (rv != test_val)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint64_(\"%s\", &ret_val) modified value of ret_val"
+ " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 "). Locale: %s\n",
+ n_prnt(t->str), test_val, rv, get_current_locale_str());
+ }
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
+ printf("PASSED: MHD_strx_to_uint64_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
+ n_prnt(t->str));
+ }
+ }
+ return t_failed;
+}
+
+
+int check_strx_to_uint64_no_val(void)
+{
+ size_t t_failed = 0;
+ size_t i, j;
+ static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]);
+ int c_failed[n_checks];
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(i = 0; i < n_checks; i++)
+ {
+ size_t rs;
+ const struct str_with_len * const t = str_no_num + i;
+ static const uint64_t rnd_val = 74218431;
+ uint64_t test_val;
+
+ for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val)
+ {
+ uint64_t rv = test_val;
+
+ rs = MHD_strx_to_uint64_(t->str, &rv);
+ if (rs != 0)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint64_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting zero."
+ " Locale: %s\n", n_prnt(t->str), rv, (uintptr_t)rs, get_current_locale_str());
+ }
+ else if (rv != test_val)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint64_(\"%s\", &ret_val) modified value of ret_val"
+ " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 "). Locale: %s\n",
+ n_prnt(t->str), test_val, rv, get_current_locale_str());
+ }
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
+ printf("PASSED: MHD_strx_to_uint64_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
+ n_prnt(t->str));
+ }
+ }
+ return t_failed;
+}
+
+
+int check_strx_to_uint64_n_valid(void)
+{
+ size_t t_failed = 0;
+ size_t i, j;
+ static const size_t n_checks = sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]);
+ int c_failed[n_checks];
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(i = 0; i < n_checks; i++)
+ {
+ uint64_t rv;
+ size_t rs = 0;
+ size_t len;
+ const struct str_with_value * const t = xdstrs_w_values + i;
+
+ if (t->str.len < t->num_of_digt)
+ {
+ fprintf(stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected"
+ " to be less or equal to str.len (%u).\n",
+ (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned int) t->str.len);
+ return -1;
+ }
+ for (len = t->num_of_digt; len <= t->str.len + 1 && !c_failed[i]; len++)
+ {
+ rv = 2352932; /* some random value */
+ rs = MHD_strx_to_uint64_n_(t->str.str, len, &rv);
+ if (rs != t->num_of_digt)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")"
+ " returned %" PRIuPTR ", while expecting %d. Locale: %s\n",
+ n_prnt(t->str.str), (intptr_t)len, rv, (intptr_t)rs,
+ (int)t->num_of_digt, get_current_locale_str());
+ }
+ if (rv != t->val)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")"
+ " converted string to value 0x%" PRIX64 ", while expecting result 0x%" PRIX64
+ ". Locale: %s\n", n_prnt(t->str.str), (intptr_t)len, rv, rv,
+ t->val, get_current_locale_str());
+ }
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
+ printf("PASSED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR ", ->0x%" PRIX64 ")"
+ " == %" PRIuPTR "\n", n_prnt(t->str.str), (intptr_t)t->num_of_digt,
+ (intptr_t)t->str.len + 1, rv, rs);
+ }
+ }
+ return t_failed;
+}
+
+
+int check_strx_to_uint64_n_all_chars(void)
+{
+ static const size_t n_checks = 256; /* from 0 to 255 */
+ int c_failed[n_checks];
+ size_t t_failed = 0;
+ size_t j;
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ unsigned int c;
+ uint64_t test_val;
+
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(c = 0; c < n_checks; c++)
+ {
+ static const uint64_t rnd_val = 98372558;
+ size_t rs;
+ size_t len;
+
+ if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'))
+ continue; /* skip xdigits */
+
+ for (len = 0; len <= 5; len++)
+ {
+ for(test_val = 0; test_val <= rnd_val&& !c_failed[c]; test_val += rnd_val)
+ {
+ char test_str[] = "0123";
+ uint64_t rv = test_val;
+
+ test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */
+ rs = MHD_strx_to_uint64_n_(test_str, len, &rv);
+ if (rs != 0)
+ {
+ t_failed++;
+ c_failed[c] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")"
+ " returned %" PRIuPTR ", while expecting zero. Locale: %s\n",
+ n_prnt(test_str), (uintptr_t)len, rv, (uintptr_t)rs, get_current_locale_str());
+ }
+ else if (rv != test_val)
+ {
+ t_failed++;
+ c_failed[c] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", &ret_val)"
+ " modified value of ret_val (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 ")."
+ " Locale: %s\n",
+ n_prnt(test_str), (uintptr_t)len, test_val, rv, get_current_locale_str());
+ }
+ }
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[c])
+ {
+ char test_str[] = "0123";
+ test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */
+
+ printf("PASSED: MHD_strx_to_uint64_n_(\"%s\", 0..5, &ret_val) == 0, value of ret_val is unmodified\n",
+ n_prnt(test_str));
+ }
+ }
+ }
+ return t_failed;
+}
+
+
+int check_strx_to_uint64_n_overflow(void)
+{
+ size_t t_failed = 0;
+ size_t i, j;
+ static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]);
+ int c_failed[n_checks];
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(i = 0; i < n_checks; i++)
+ {
+ size_t rs;
+ const struct str_with_len * const t = strx_ovflw + i;
+ static const uint64_t rnd_val = 4;
+ size_t len;
+
+ for (len = t->len; len <= t->len + 1; len++)
+ {
+ uint64_t test_val;
+ for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val)
+ {
+ uint64_t rv = test_val;
+
+ rs = MHD_strx_to_uint64_n_(t->str, len, &rv);
+ if (rs != 0)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")"
+ " returned %" PRIuPTR ", while expecting zero. Locale: %s\n",
+ n_prnt(t->str), (uintptr_t)len, rv, (uintptr_t)rs, get_current_locale_str());
+ }
+ else if (rv != test_val)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", &ret_val)"
+ " modified value of ret_val (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 ")."
+ " Locale: %s\n", n_prnt(t->str), (uintptr_t)len, test_val, rv,
+ get_current_locale_str());
+ }
+ }
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
+ printf("PASSED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR ", &ret_val) == 0,"
+ " value of ret_val is unmodified\n", n_prnt(t->str), (uintptr_t)t->len,
+ (uintptr_t)t->len + 1);
+ }
+ }
+ return t_failed;
+}
+
+
+int check_strx_to_uint64_n_no_val(void)
+{
+ size_t t_failed = 0;
+ size_t i, j;
+ static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]);
+ int c_failed[n_checks];
+
+ memset(c_failed, 0, sizeof(c_failed));
+
+ for(j = 0; j < locale_name_count; j++)
+ {
+ set_test_locale(j); /* setlocale() can be slow! */
+ for(i = 0; i < n_checks; i++)
+ {
+ size_t rs;
+ const struct str_with_len * const t = str_no_num + i;
+ static const uint64_t rnd_val = 3214314212;
+ size_t len;
+
+ for (len = 0; len <= t->len + 1; len++)
+ {
+ uint64_t test_val;
+ for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val)
+ {
+ uint64_t rv = test_val;
+
+ rs = MHD_strx_to_uint64_n_(t->str, len, &rv);
+ if (rs != 0)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")"
+ " returned %" PRIuPTR ", while expecting zero. Locale: %s\n",
+ n_prnt(t->str), (uintptr_t)len, rv, (uintptr_t)rs, get_current_locale_str());
+ }
+ else if (rv != test_val)
+ {
+ t_failed++;
+ c_failed[i] = !0;
+ fprintf(stderr, "FAILED: MHD_strx_to_uint64_n_(\"%s\", %" PRIuPTR ", &ret_val)"
+ " modified value of ret_val (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 ")."
+ " Locale: %s\n", n_prnt(t->str), (uintptr_t)len, test_val, rv,
+ get_current_locale_str());
+ }
+ }
+ }
+ if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
+ printf("PASSED: MHD_strx_to_uint64_n_(\"%s\", 0..%" PRIuPTR ", &ret_val) == 0,"
+ " value of ret_val is unmodified\n", n_prnt(t->str),
+ (uintptr_t)t->len + 1);
+ }
+ }
+ return t_failed;
+}
+
+
+int run_str_to_X_tests(void)
+{
+ int str_to_uint64_fails = 0;
+ int str_to_uint64_n_fails = 0;
+ int strx_to_sizet_fails = 0;
+ int strx_to_sizet_n_fails = 0;
+ int strx_to_uint32_fails = 0;
+ int strx_to_uint32_n_fails = 0;
+ int strx_to_uint64_fails = 0;
+ int strx_to_uint64_n_fails = 0;
+ int res;
+
+ res = check_str_to_uint64_valid();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_str_to_uint64_valid().\n");
+ return 99;
+ }
+ str_to_uint64_fails += res;
+ fprintf(stderr, "FAILED: testcase check_str_to_uint64_valid() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_str_to_uint64_valid() successfully passed.\n\n");
+
+ res = check_str_to_uint64_all_chars();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_str_to_uint64_all_chars().\n");
+ return 99;
+ }
+ str_to_uint64_fails += res;
+ fprintf(stderr, "FAILED: testcase check_str_to_uint64_all_chars() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_str_to_uint64_all_chars() successfully passed.\n\n");
+
+ res = check_str_to_uint64_overflow();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_str_to_uint64_overflow().\n");
+ return 99;
+ }
+ str_to_uint64_fails += res;
+ fprintf(stderr, "FAILED: testcase check_str_to_uint64_overflow() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_str_to_uint64_overflow() successfully passed.\n\n");
+
+ res = check_str_to_uint64_no_val();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_str_to_uint64_no_val().\n");
+ return 99;
+ }
+ str_to_uint64_fails += res;
+ fprintf(stderr, "FAILED: testcase check_str_to_uint64_no_val() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_str_to_uint64_no_val() successfully passed.\n\n");
+
+ if (str_to_uint64_fails)
+ fprintf(stderr, "FAILED: function MHD_str_to_uint64_() failed %d time%s.\n\n",
+ str_to_uint64_fails, str_to_uint64_fails == 1 ? "" : "s");
+ else if (verbose > 0)
+ printf("PASSED: function MHD_str_to_uint64_() successfully passed all checks.\n\n");
+
+ res = check_str_to_uint64_n_valid();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_str_to_uint64_n_valid().\n");
+ return 99;
+ }
+ str_to_uint64_n_fails += res;
+ fprintf(stderr, "FAILED: testcase check_str_to_uint64_n_valid() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_str_to_uint64_n_valid() successfully passed.\n\n");
+
+ res = check_str_to_uint64_n_all_chars();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_str_to_uint64_n_all_chars().\n");
+ return 99;
+ }
+ str_to_uint64_n_fails += res;
+ fprintf(stderr, "FAILED: testcase check_str_to_uint64_n_all_chars() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_str_to_uint64_n_all_chars() successfully passed.\n\n");
+
+ res = check_str_to_uint64_n_overflow();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_str_to_uint64_n_overflow().\n");
+ return 99;
+ }
+ str_to_uint64_n_fails += res;
+ fprintf(stderr, "FAILED: testcase check_str_to_uint64_n_overflow() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_str_to_uint64_n_overflow() successfully passed.\n\n");
+
+ res = check_str_to_uint64_n_no_val();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_str_to_uint64_n_no_val().\n");
+ return 99;
+ }
+ str_to_uint64_n_fails += res;
+ fprintf(stderr, "FAILED: testcase check_str_to_uint64_n_no_val() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_str_to_uint64_n_no_val() successfully passed.\n\n");
+
+ if (str_to_uint64_n_fails)
+ fprintf(stderr, "FAILED: function MHD_str_to_uint64_n_() failed %d time%s.\n\n",
+ str_to_uint64_n_fails, str_to_uint64_n_fails == 1 ? "" : "s");
+ else if (verbose > 0)
+ printf("PASSED: function MHD_str_to_uint64_n_() successfully passed all checks.\n\n");
+
+ res = check_strx_to_sizet_valid();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_valid().\n");
+ return 99;
+ }
+ strx_to_sizet_fails += res;
+ fprintf(stderr, "FAILED: testcase check_strx_to_sizet_valid() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_strx_to_sizet_valid() successfully passed.\n\n");
+
+ res = check_strx_to_sizet_all_chars();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_all_chars().\n");
+ return 99;
+ }
+ strx_to_sizet_fails += res;
+ fprintf(stderr, "FAILED: testcase check_strx_to_sizet_all_chars() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_strx_to_sizet_all_chars() successfully passed.\n\n");
+
+ res = check_strx_to_sizet_overflow();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_overflow().\n");
+ return 99;
+ }
+ strx_to_sizet_fails += res;
+ fprintf(stderr, "FAILED: testcase check_strx_to_sizet_overflow() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_strx_to_sizet_overflow() successfully passed.\n\n");
+
+ res = check_strx_to_sizet_no_val();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_no_val().\n");
+ return 99;
+ }
+ strx_to_sizet_fails += res;
+ fprintf(stderr, "FAILED: testcase check_strx_to_sizet_no_val() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_strx_to_sizet_no_val() successfully passed.\n\n");
+
+ if (strx_to_sizet_fails)
+ fprintf(stderr, "FAILED: function MHD_strx_to_sizet_() failed %d time%s.\n\n",
+ strx_to_sizet_fails, strx_to_sizet_fails == 1 ? "" : "s");
+ else if (verbose > 0)
+ printf("PASSED: function MHD_strx_to_sizet_() successfully passed all checks.\n\n");
+
+ res = check_strx_to_sizet_n_valid();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_n_valid().\n");
+ return 99;
+ }
+ strx_to_sizet_n_fails += res;
+ fprintf(stderr, "FAILED: testcase check_strx_to_sizet_n_valid() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_strx_to_sizet_n_valid() successfully passed.\n\n");
+
+ res = check_strx_to_sizet_n_all_chars();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_n_all_chars().\n");
+ return 99;
+ }
+ strx_to_sizet_n_fails += res;
+ fprintf(stderr, "FAILED: testcase check_strx_to_sizet_n_all_chars() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_strx_to_sizet_n_all_chars() successfully passed.\n\n");
+
+ res = check_strx_to_sizet_n_overflow();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_n_overflow().\n");
+ return 99;
+ }
+ strx_to_sizet_n_fails += res;
+ fprintf(stderr, "FAILED: testcase check_strx_to_sizet_n_overflow() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_strx_to_sizet_n_overflow() successfully passed.\n\n");
+
+ res = check_strx_to_sizet_n_no_val();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_n_no_val().\n");
+ return 99;
+ }
+ strx_to_sizet_n_fails += res;
+ fprintf(stderr, "FAILED: testcase check_strx_to_sizet_n_no_val() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_strx_to_sizet_n_no_val() successfully passed.\n\n");
+
+ if (strx_to_sizet_n_fails)
+ fprintf(stderr, "FAILED: function MHD_strx_to_sizet_n_() failed %d time%s.\n\n",
+ strx_to_sizet_n_fails, strx_to_sizet_n_fails == 1 ? "" : "s");
+ else if (verbose > 0)
+ printf("PASSED: function MHD_strx_to_sizet_n_() successfully passed all checks.\n\n");
+
+ res = check_strx_to_uint32_valid();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_strx_to_uint32_valid().\n");
+ return 99;
+ }
+ strx_to_uint32_fails += res;
+ fprintf(stderr, "FAILED: testcase check_strx_to_uint32_valid() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_strx_to_uint32_valid() successfully passed.\n\n");
+
+ res = check_strx_to_uint32_all_chars();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_strx_to_uint32_all_chars().\n");
+ return 99;
+ }
+ strx_to_uint32_fails += res;
+ fprintf(stderr, "FAILED: testcase check_strx_to_uint32_all_chars() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_strx_to_uint32_all_chars() successfully passed.\n\n");
+
+ res = check_strx_to_uint32_overflow();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_strx_to_uint32_overflow().\n");
+ return 99;
+ }
+ strx_to_uint32_fails += res;
+ fprintf(stderr, "FAILED: testcase check_strx_to_uint32_overflow() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_strx_to_uint32_overflow() successfully passed.\n\n");
+
+ res = check_strx_to_uint32_no_val();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_strx_to_uint32_no_val().\n");
+ return 99;
+ }
+ strx_to_uint32_fails += res;
+ fprintf(stderr, "FAILED: testcase check_strx_to_uint32_no_val() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_strx_to_uint32_no_val() successfully passed.\n\n");
+
+ if (strx_to_uint32_fails)
+ fprintf(stderr, "FAILED: function MHD_strx_to_uint32_() failed %d time%s.\n\n",
+ strx_to_uint32_fails, strx_to_uint32_fails == 1 ? "" : "s");
+ else if (verbose > 0)
+ printf("PASSED: function MHD_strx_to_uint32_() successfully passed all checks.\n\n");
+
+ res = check_strx_to_uint32_n_valid();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_strx_to_uint32_n_valid().\n");
+ return 99;
+ }
+ strx_to_uint32_n_fails += res;
+ fprintf(stderr, "FAILED: testcase check_strx_to_uint32_n_valid() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_strx_to_uint32_n_valid() successfully passed.\n\n");
+
+ res = check_strx_to_uint32_n_all_chars();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_strx_to_uint32_n_all_chars().\n");
+ return 99;
+ }
+ strx_to_uint32_n_fails += res;
+ fprintf(stderr, "FAILED: testcase check_strx_to_uint32_n_all_chars() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_strx_to_uint32_n_all_chars() successfully passed.\n\n");
+
+ res = check_strx_to_uint32_n_overflow();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_strx_to_uint32_n_overflow().\n");
+ return 99;
+ }
+ strx_to_uint32_n_fails += res;
+ fprintf(stderr, "FAILED: testcase check_strx_to_uint32_n_overflow() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_strx_to_uint32_n_overflow() successfully passed.\n\n");
+
+ res = check_strx_to_uint32_n_no_val();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_strx_to_uint32_n_no_val().\n");
+ return 99;
+ }
+ strx_to_uint32_n_fails += res;
+ fprintf(stderr, "FAILED: testcase check_strx_to_uint32_n_no_val() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_strx_to_uint32_n_no_val() successfully passed.\n\n");
+
+ if (strx_to_uint32_n_fails)
+ fprintf(stderr, "FAILED: function MHD_strx_to_uint32_n_() failed %d time%s.\n\n",
+ strx_to_uint32_n_fails, strx_to_uint32_n_fails == 1 ? "" : "s");
+ else if (verbose > 0)
+ printf("PASSED: function MHD_strx_to_uint32_n_() successfully passed all checks.\n\n");
+
+ res = check_strx_to_uint64_valid();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_strx_to_uint64_valid().\n");
+ return 99;
+ }
+ strx_to_uint64_fails += res;
+ fprintf(stderr, "FAILED: testcase check_strx_to_uint64_valid() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_strx_to_uint64_valid() successfully passed.\n\n");
+
+ res = check_strx_to_uint64_all_chars();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_strx_to_uint64_all_chars().\n");
+ return 99;
+ }
+ strx_to_uint64_fails += res;
+ fprintf(stderr, "FAILED: testcase check_strx_to_uint64_all_chars() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_strx_to_uint64_all_chars() successfully passed.\n\n");
+
+ res = check_strx_to_uint64_overflow();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_strx_to_uint64_overflow().\n");
+ return 99;
+ }
+ strx_to_uint64_fails += res;
+ fprintf(stderr, "FAILED: testcase check_strx_to_uint64_overflow() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_strx_to_uint64_overflow() successfully passed.\n\n");
+
+ res = check_strx_to_uint64_no_val();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_strx_to_uint64_no_val().\n");
+ return 99;
+ }
+ strx_to_uint64_fails += res;
+ fprintf(stderr, "FAILED: testcase check_strx_to_uint64_no_val() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_strx_to_uint64_no_val() successfully passed.\n\n");
+
+ if (strx_to_uint64_fails)
+ fprintf(stderr, "FAILED: function MHD_strx_to_uint64_() failed %d time%s.\n\n",
+ strx_to_uint64_fails, strx_to_uint64_fails == 1 ? "" : "s");
+ else if (verbose > 0)
+ printf("PASSED: function MHD_strx_to_uint64_() successfully passed all checks.\n\n");
+
+ res = check_strx_to_uint64_n_valid();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_strx_to_uint64_n_valid().\n");
+ return 99;
+ }
+ strx_to_uint64_n_fails += res;
+ fprintf(stderr, "FAILED: testcase check_strx_to_uint64_n_valid() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_strx_to_uint64_n_valid() successfully passed.\n\n");
+
+ res = check_strx_to_uint64_n_all_chars();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_strx_to_uint64_n_all_chars().\n");
+ return 99;
+ }
+ strx_to_uint64_n_fails += res;
+ fprintf(stderr, "FAILED: testcase check_strx_to_uint64_n_all_chars() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_strx_to_uint64_n_all_chars() successfully passed.\n\n");
+
+ res = check_strx_to_uint64_n_overflow();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_strx_to_uint64_n_overflow().\n");
+ return 99;
+ }
+ strx_to_uint64_n_fails += res;
+ fprintf(stderr, "FAILED: testcase check_strx_to_uint64_n_overflow() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_strx_to_uint64_n_overflow() successfully passed.\n\n");
+
+ res = check_strx_to_uint64_n_no_val();
+ if (res != 0)
+ {
+ if (res < 0)
+ {
+ fprintf(stderr, "ERROR: test internal error in check_strx_to_uint64_n_no_val().\n");
+ return 99;
+ }
+ strx_to_uint64_n_fails += res;
+ fprintf(stderr, "FAILED: testcase check_strx_to_uint64_n_no_val() failed.\n\n");
+ }
+ else if (verbose > 1)
+ printf("PASSED: testcase check_strx_to_uint64_n_no_val() successfully passed.\n\n");
+
+ if (strx_to_uint64_n_fails)
+ fprintf(stderr, "FAILED: function MHD_strx_to_uint64_n_() failed %d time%s.\n\n",
+ strx_to_uint64_n_fails, strx_to_uint64_n_fails == 1 ? "" : "s");
+ else if (verbose > 0)
+ printf("PASSED: function MHD_strx_to_uint64_n_() successfully passed all checks.\n\n");
+
+ if (str_to_uint64_fails || str_to_uint64_n_fails ||
+ strx_to_sizet_fails || strx_to_sizet_n_fails ||
+ strx_to_uint32_fails || strx_to_uint32_n_fails ||
+ strx_to_uint64_fails || strx_to_uint64_n_fails)
+ {
+ if (verbose > 0)
+ printf("At least one test failed.\n");
+
+ return 1;
+ }
+
+ if (verbose > 0)
+ printf("All tests passed successfully.\n");
+
+ return 0;
+}
+
+
int main(int argc, char * argv[])
{
if (has_param(argc, argv, "-v") || has_param(argc, argv, "--verbose") || has_param(argc, argv, "--verbose1"))
@@ -782,5 +3493,8 @@ int main(int argc, char * argv[])
if (has_param(argc, argv, "-vvv") || has_param(argc, argv, "--verbose3"))
verbose = 3;
+ if (has_in_name(argv[0], "_to_value"))
+ return run_str_to_X_tests();
+
return run_eq_neq_str_tests();
}
diff --git a/w32/common/MHD_config.h b/w32/common/MHD_config.h
index 9844c8bb..d147e984 100644
--- a/w32/common/MHD_config.h
+++ b/w32/common/MHD_config.h
@@ -87,6 +87,11 @@
#define HAVE_SNPRINTF 1
#endif
+#if _MSC_VER >= 1800
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+#endif
+
/* *** Headers information *** */
/* Not really important as not used by code currently */