diff options
Diffstat (limited to 'src/microhttpd/test_str.c')
-rw-r--r-- | src/microhttpd/test_str.c | 644 |
1 files changed, 0 insertions, 644 deletions
diff --git a/src/microhttpd/test_str.c b/src/microhttpd/test_str.c index 3f921303..e8581c22 100644 --- a/src/microhttpd/test_str.c +++ b/src/microhttpd/test_str.c | |||
@@ -1496,523 +1496,6 @@ int check_str_to_uint64_n_no_val(void) | |||
1496 | } | 1496 | } |
1497 | 1497 | ||
1498 | 1498 | ||
1499 | int check_strx_to_sizet_valid(void) | ||
1500 | { | ||
1501 | size_t t_failed = 0; | ||
1502 | size_t i, j; | ||
1503 | static const size_t n_checks = sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]); | ||
1504 | int c_failed[n_checks]; | ||
1505 | |||
1506 | memset(c_failed, 0, sizeof(c_failed)); | ||
1507 | |||
1508 | for(j = 0; j < locale_name_count; j++) | ||
1509 | { | ||
1510 | set_test_locale(j); /* setlocale() can be slow! */ | ||
1511 | for(i = 0; i < n_checks; i++) | ||
1512 | { | ||
1513 | size_t rv; | ||
1514 | size_t rs; | ||
1515 | const struct str_with_value * const t = xdstrs_w_values + i; | ||
1516 | |||
1517 | #if SIZE_MAX != UINT64_MAX | ||
1518 | if (t->val > SIZE_MAX) | ||
1519 | continue; /* number is too high for this function */ | ||
1520 | #endif /* SIZE_MAX != UINT64_MAX */ | ||
1521 | |||
1522 | if (c_failed[i]) | ||
1523 | continue; /* skip already failed checks */ | ||
1524 | |||
1525 | if (t->str.len < t->num_of_digt) | ||
1526 | { | ||
1527 | fprintf(stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" | ||
1528 | " to be less or equal to str.len (%u).\n", | ||
1529 | (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned int) t->str.len); | ||
1530 | return -1; | ||
1531 | } | ||
1532 | rv = 1458532; /* some random value */ | ||
1533 | rs = MHD_strx_to_sizet_(t->str.str, &rv); | ||
1534 | if (rs != t->num_of_digt) | ||
1535 | { | ||
1536 | t_failed++; | ||
1537 | c_failed[i] = !0; | ||
1538 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting %d." | ||
1539 | " Locale: %s\n", n_prnt(t->str.str), (uint64_t)rv, (intptr_t)rs, (int)t->num_of_digt, get_current_locale_str()); | ||
1540 | } | ||
1541 | if (rv != t->val) | ||
1542 | { | ||
1543 | t_failed++; | ||
1544 | c_failed[i] = !0; | ||
1545 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", ->0x%" PRIX64 ") converted string to value 0x%" PRIX64 "," | ||
1546 | " while expecting result 0x%" PRIX64 ". Locale: %s\n", n_prnt(t->str.str), (uint64_t)rv, (uint64_t)rv, | ||
1547 | t->val, get_current_locale_str()); | ||
1548 | } | ||
1549 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
1550 | printf("PASSED: MHD_strx_to_sizet_(\"%s\", ->0x%" PRIX64 ") == %" PRIuPTR "\n", | ||
1551 | n_prnt(t->str.str), (uint64_t)rv, rs); | ||
1552 | } | ||
1553 | } | ||
1554 | return t_failed; | ||
1555 | } | ||
1556 | |||
1557 | |||
1558 | int check_strx_to_sizet_all_chars(void) | ||
1559 | { | ||
1560 | static const size_t n_checks = 256; /* from 0 to 255 */ | ||
1561 | int c_failed[n_checks]; | ||
1562 | size_t t_failed = 0; | ||
1563 | size_t j; | ||
1564 | |||
1565 | memset(c_failed, 0, sizeof(c_failed)); | ||
1566 | |||
1567 | for(j = 0; j < locale_name_count; j++) | ||
1568 | { | ||
1569 | unsigned int c; | ||
1570 | size_t test_val; | ||
1571 | |||
1572 | set_test_locale(j); /* setlocale() can be slow! */ | ||
1573 | for(c = 0; c < n_checks; c++) | ||
1574 | { | ||
1575 | static const size_t rnd_val = 234234; | ||
1576 | size_t rs; | ||
1577 | if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') ||(c >= 'a' && c <= 'f')) | ||
1578 | continue; /* skip xdigits */ | ||
1579 | for(test_val = 0; test_val <= rnd_val&& !c_failed[c]; test_val += rnd_val) | ||
1580 | { | ||
1581 | char test_str[] = "0123"; | ||
1582 | size_t rv = test_val; | ||
1583 | |||
1584 | test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */ | ||
1585 | rs = MHD_strx_to_sizet_(test_str, &rv); | ||
1586 | if (rs != 0) | ||
1587 | { | ||
1588 | t_failed++; | ||
1589 | c_failed[c] = !0; | ||
1590 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting zero." | ||
1591 | " Locale: %s\n", n_prnt(test_str), (uint64_t)rv, (uintptr_t)rs, get_current_locale_str()); | ||
1592 | } | ||
1593 | else if (rv != test_val) | ||
1594 | { | ||
1595 | t_failed++; | ||
1596 | c_failed[c] = !0; | ||
1597 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", &ret_val) modified value of ret_val" | ||
1598 | " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 "). Locale: %s\n", | ||
1599 | n_prnt(test_str), (uint64_t)test_val, (uint64_t)rv, get_current_locale_str()); | ||
1600 | } | ||
1601 | } | ||
1602 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[c]) | ||
1603 | { | ||
1604 | char test_str[] = "0123"; | ||
1605 | test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */ | ||
1606 | |||
1607 | printf("PASSED: MHD_strx_to_sizet_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n", | ||
1608 | n_prnt(test_str)); | ||
1609 | } | ||
1610 | } | ||
1611 | } | ||
1612 | return t_failed; | ||
1613 | } | ||
1614 | |||
1615 | |||
1616 | int check_strx_to_sizet_overflow(void) | ||
1617 | { | ||
1618 | size_t t_failed = 0; | ||
1619 | size_t i, j; | ||
1620 | static const size_t n_checks1 = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]); | ||
1621 | #if SIZE_MAX != UINT64_MAX | ||
1622 | static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]) + | ||
1623 | sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]); | ||
1624 | #else /* SIZE_MAX == UINT64_MAX */ | ||
1625 | static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]); | ||
1626 | #endif /* SIZE_MAX == UINT64_MAX */ | ||
1627 | int c_failed[n_checks]; | ||
1628 | |||
1629 | memset(c_failed, 0, sizeof(c_failed)); | ||
1630 | |||
1631 | for(j = 0; j < locale_name_count; j++) | ||
1632 | { | ||
1633 | set_test_locale(j); /* setlocale() can be slow! */ | ||
1634 | for(i = 0; i < n_checks; i++) | ||
1635 | { | ||
1636 | size_t rs; | ||
1637 | static const size_t rnd_val = 74218431; | ||
1638 | size_t test_val; | ||
1639 | const char * str; | ||
1640 | if (i < n_checks1) | ||
1641 | { | ||
1642 | const struct str_with_len * const t = strx_ovflw + i; | ||
1643 | str = t->str; | ||
1644 | } | ||
1645 | #if SIZE_MAX != UINT64_MAX | ||
1646 | else | ||
1647 | { | ||
1648 | const struct str_with_value * const t = xdstrs_w_values + (i - n_checks1); | ||
1649 | if (t->val <= SIZE_MAX) | ||
1650 | continue; /* check only strings that should overflow size_t */ | ||
1651 | str = t->str.str; | ||
1652 | } | ||
1653 | #else /* SIZE_MAX == UINT64_MAX */ | ||
1654 | else | ||
1655 | continue; /* silent compiler warning */ | ||
1656 | #endif /* SIZE_MAX == UINT64_MAX */ | ||
1657 | |||
1658 | |||
1659 | for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) | ||
1660 | { | ||
1661 | size_t rv = test_val; | ||
1662 | |||
1663 | rs = MHD_strx_to_sizet_(str, &rv); | ||
1664 | if (rs != 0) | ||
1665 | { | ||
1666 | t_failed++; | ||
1667 | c_failed[i] = !0; | ||
1668 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting zero." | ||
1669 | " Locale: %s\n", n_prnt(str), (uint64_t)rv, (uintptr_t)rs, get_current_locale_str()); | ||
1670 | } | ||
1671 | else if (rv != test_val) | ||
1672 | { | ||
1673 | t_failed++; | ||
1674 | c_failed[i] = !0; | ||
1675 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", &ret_val) modified value of ret_val" | ||
1676 | " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 "). Locale: %s\n", | ||
1677 | n_prnt(str), (uint64_t)test_val, (uint64_t)rv, get_current_locale_str()); | ||
1678 | } | ||
1679 | } | ||
1680 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
1681 | printf("PASSED: MHD_strx_to_sizet_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n", | ||
1682 | n_prnt(str)); | ||
1683 | } | ||
1684 | } | ||
1685 | return t_failed; | ||
1686 | } | ||
1687 | |||
1688 | |||
1689 | int check_strx_to_sizet_no_val(void) | ||
1690 | { | ||
1691 | size_t t_failed = 0; | ||
1692 | size_t i, j; | ||
1693 | static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]); | ||
1694 | int c_failed[n_checks]; | ||
1695 | |||
1696 | memset(c_failed, 0, sizeof(c_failed)); | ||
1697 | |||
1698 | for(j = 0; j < locale_name_count; j++) | ||
1699 | { | ||
1700 | set_test_locale(j); /* setlocale() can be slow! */ | ||
1701 | for(i = 0; i < n_checks; i++) | ||
1702 | { | ||
1703 | size_t rs; | ||
1704 | const struct str_with_len * const t = str_no_num + i; | ||
1705 | static const size_t rnd_val = 74218431; | ||
1706 | size_t test_val; | ||
1707 | |||
1708 | for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) | ||
1709 | { | ||
1710 | size_t rv = test_val; | ||
1711 | |||
1712 | rs = MHD_strx_to_sizet_(t->str, &rv); | ||
1713 | if (rs != 0) | ||
1714 | { | ||
1715 | t_failed++; | ||
1716 | c_failed[i] = !0; | ||
1717 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting zero." | ||
1718 | " Locale: %s\n", n_prnt(t->str), (uint64_t)rv, (uintptr_t)rs, get_current_locale_str()); | ||
1719 | } | ||
1720 | else if (rv != test_val) | ||
1721 | { | ||
1722 | t_failed++; | ||
1723 | c_failed[i] = !0; | ||
1724 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", &ret_val) modified value of ret_val" | ||
1725 | " (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 "). Locale: %s\n", | ||
1726 | n_prnt(t->str), (uint64_t)test_val, (uint64_t)rv, get_current_locale_str()); | ||
1727 | } | ||
1728 | } | ||
1729 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
1730 | printf("PASSED: MHD_strx_to_sizet_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n", | ||
1731 | n_prnt(t->str)); | ||
1732 | } | ||
1733 | } | ||
1734 | return t_failed; | ||
1735 | } | ||
1736 | |||
1737 | |||
1738 | int check_strx_to_sizet_n_valid(void) | ||
1739 | { | ||
1740 | size_t t_failed = 0; | ||
1741 | size_t i, j; | ||
1742 | static const size_t n_checks = sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]); | ||
1743 | int c_failed[n_checks]; | ||
1744 | |||
1745 | memset(c_failed, 0, sizeof(c_failed)); | ||
1746 | |||
1747 | for(j = 0; j < locale_name_count; j++) | ||
1748 | { | ||
1749 | set_test_locale(j); /* setlocale() can be slow! */ | ||
1750 | for(i = 0; i < n_checks; i++) | ||
1751 | { | ||
1752 | size_t rv = 2352932; /* some random value */ | ||
1753 | size_t rs = 0; | ||
1754 | size_t len; | ||
1755 | const struct str_with_value * const t = xdstrs_w_values + i; | ||
1756 | |||
1757 | #if SIZE_MAX != UINT64_MAX | ||
1758 | if (t->val > SIZE_MAX) | ||
1759 | continue; /* number is too high for this function */ | ||
1760 | #endif /* SIZE_MAX != UINT64_MAX */ | ||
1761 | |||
1762 | if (t->str.len < t->num_of_digt) | ||
1763 | { | ||
1764 | fprintf(stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" | ||
1765 | " to be less or equal to str.len (%u).\n", | ||
1766 | (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned int) t->str.len); | ||
1767 | return -1; | ||
1768 | } | ||
1769 | for (len = t->num_of_digt; len <= t->str.len + 1 && !c_failed[i]; len++) | ||
1770 | { | ||
1771 | rs = MHD_strx_to_sizet_n_(t->str.str, len, &rv); | ||
1772 | if (rs != t->num_of_digt) | ||
1773 | { | ||
1774 | t_failed++; | ||
1775 | c_failed[i] = !0; | ||
1776 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")" | ||
1777 | " returned %" PRIuPTR ", while expecting %d. Locale: %s\n", | ||
1778 | n_prnt(t->str.str), (intptr_t)len, (uint64_t)rv, (intptr_t)rs, | ||
1779 | (int)t->num_of_digt, get_current_locale_str()); | ||
1780 | } | ||
1781 | if (rv != t->val) | ||
1782 | { | ||
1783 | t_failed++; | ||
1784 | c_failed[i] = !0; | ||
1785 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")" | ||
1786 | " converted string to value 0x%" PRIX64 ", while expecting result 0x%" PRIX64 | ||
1787 | ". Locale: %s\n", n_prnt(t->str.str), (intptr_t)len, (uint64_t)rv, (uint64_t)rv, | ||
1788 | t->val, get_current_locale_str()); | ||
1789 | } | ||
1790 | } | ||
1791 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
1792 | printf("PASSED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR ", ->0x%" PRIX64 ")" | ||
1793 | " == %" PRIuPTR "\n", n_prnt(t->str.str), (intptr_t)t->num_of_digt, | ||
1794 | (intptr_t)t->str.len + 1, (uint64_t)rv, rs); | ||
1795 | } | ||
1796 | } | ||
1797 | return t_failed; | ||
1798 | } | ||
1799 | |||
1800 | |||
1801 | int check_strx_to_sizet_n_all_chars(void) | ||
1802 | { | ||
1803 | static const size_t n_checks = 256; /* from 0 to 255 */ | ||
1804 | int c_failed[n_checks]; | ||
1805 | size_t t_failed = 0; | ||
1806 | size_t j; | ||
1807 | |||
1808 | memset(c_failed, 0, sizeof(c_failed)); | ||
1809 | |||
1810 | for(j = 0; j < locale_name_count; j++) | ||
1811 | { | ||
1812 | unsigned int c; | ||
1813 | size_t test_val; | ||
1814 | |||
1815 | set_test_locale(j); /* setlocale() can be slow! */ | ||
1816 | for(c = 0; c < n_checks; c++) | ||
1817 | { | ||
1818 | static const size_t rnd_val = 98372558; | ||
1819 | size_t rs; | ||
1820 | size_t len; | ||
1821 | |||
1822 | if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')) | ||
1823 | continue; /* skip xdigits */ | ||
1824 | |||
1825 | for (len = 0; len <= 5; len++) | ||
1826 | { | ||
1827 | for(test_val = 0; test_val <= rnd_val&& !c_failed[c]; test_val += rnd_val) | ||
1828 | { | ||
1829 | char test_str[] = "0123"; | ||
1830 | size_t rv = test_val; | ||
1831 | |||
1832 | test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */ | ||
1833 | rs = MHD_strx_to_sizet_n_(test_str, len, &rv); | ||
1834 | if (rs != 0) | ||
1835 | { | ||
1836 | t_failed++; | ||
1837 | c_failed[c] = !0; | ||
1838 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")" | ||
1839 | " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", | ||
1840 | n_prnt(test_str), (uintptr_t)len, (uint64_t)rv, (uintptr_t)rs, get_current_locale_str()); | ||
1841 | } | ||
1842 | else if (rv != test_val) | ||
1843 | { | ||
1844 | t_failed++; | ||
1845 | c_failed[c] = !0; | ||
1846 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", &ret_val)" | ||
1847 | " modified value of ret_val (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 ")." | ||
1848 | " Locale: %s\n", | ||
1849 | n_prnt(test_str), (uintptr_t)len, (uint64_t)test_val, (uint64_t)rv, get_current_locale_str()); | ||
1850 | } | ||
1851 | } | ||
1852 | } | ||
1853 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[c]) | ||
1854 | { | ||
1855 | char test_str[] = "0123"; | ||
1856 | test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */ | ||
1857 | |||
1858 | printf("PASSED: MHD_strx_to_sizet_n_(\"%s\", 0..5, &ret_val) == 0, value of ret_val is unmodified\n", | ||
1859 | n_prnt(test_str)); | ||
1860 | } | ||
1861 | } | ||
1862 | } | ||
1863 | return t_failed; | ||
1864 | } | ||
1865 | |||
1866 | |||
1867 | int check_strx_to_sizet_n_overflow(void) | ||
1868 | { | ||
1869 | size_t t_failed = 0; | ||
1870 | size_t i, j; | ||
1871 | static const size_t n_checks1 = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]); | ||
1872 | #if SIZE_MAX != UINT64_MAX | ||
1873 | static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]) + | ||
1874 | sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]); | ||
1875 | #else /* SIZE_MAX == UINT64_MAX */ | ||
1876 | static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]); | ||
1877 | #endif /* SIZE_MAX == UINT64_MAX */ | ||
1878 | int c_failed[n_checks]; | ||
1879 | |||
1880 | memset(c_failed, 0, sizeof(c_failed)); | ||
1881 | |||
1882 | for(j = 0; j < locale_name_count; j++) | ||
1883 | { | ||
1884 | set_test_locale(j); /* setlocale() can be slow! */ | ||
1885 | for(i = 0; i < n_checks; i++) | ||
1886 | { | ||
1887 | size_t rs; | ||
1888 | static const size_t rnd_val = 4; | ||
1889 | size_t len; | ||
1890 | const char * str; | ||
1891 | size_t min_len, max_len; | ||
1892 | if (i < n_checks1) | ||
1893 | { | ||
1894 | const struct str_with_len * const t = strx_ovflw + i; | ||
1895 | str = t->str; | ||
1896 | min_len = t->len; | ||
1897 | max_len = t->len + 1; | ||
1898 | } | ||
1899 | #if SIZE_MAX != UINT64_MAX | ||
1900 | else | ||
1901 | { | ||
1902 | const struct str_with_value * const t = xdstrs_w_values + (i - n_checks1); | ||
1903 | if (t->val <= SIZE_MAX) | ||
1904 | continue; /* check only strings that should overflow size_t */ | ||
1905 | |||
1906 | if (t->str.len < t->num_of_digt) | ||
1907 | { | ||
1908 | fprintf(stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" | ||
1909 | " to be less or equal to str.len (%u).\n", | ||
1910 | (unsigned int) (i - n_checks1), (unsigned int) t->num_of_digt, | ||
1911 | (unsigned int) t->str.len); | ||
1912 | return -1; | ||
1913 | } | ||
1914 | str = t->str.str; | ||
1915 | min_len = t->num_of_digt; | ||
1916 | max_len = t->str.len + 1; | ||
1917 | } | ||
1918 | #else /* SIZE_MAX == UINT64_MAX */ | ||
1919 | else | ||
1920 | continue; /* silent compiler warning */ | ||
1921 | #endif /* SIZE_MAX == UINT64_MAX */ | ||
1922 | |||
1923 | for (len = min_len; len <= max_len; len++) | ||
1924 | { | ||
1925 | size_t test_val; | ||
1926 | for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) | ||
1927 | { | ||
1928 | size_t rv = test_val; | ||
1929 | |||
1930 | rs = MHD_strx_to_sizet_n_(str, len, &rv); | ||
1931 | if (rs != 0) | ||
1932 | { | ||
1933 | t_failed++; | ||
1934 | c_failed[i] = !0; | ||
1935 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")" | ||
1936 | " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", | ||
1937 | n_prnt(str), (uintptr_t)len, (uint64_t)rv, (uintptr_t)rs, get_current_locale_str()); | ||
1938 | } | ||
1939 | else if (rv != test_val) | ||
1940 | { | ||
1941 | t_failed++; | ||
1942 | c_failed[i] = !0; | ||
1943 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", &ret_val)" | ||
1944 | " modified value of ret_val (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 ")." | ||
1945 | " Locale: %s\n", n_prnt(str), (uintptr_t)len, (uint64_t)test_val, (uint64_t)rv, | ||
1946 | get_current_locale_str()); | ||
1947 | } | ||
1948 | } | ||
1949 | } | ||
1950 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
1951 | printf("PASSED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR ", &ret_val) == 0," | ||
1952 | " value of ret_val is unmodified\n", n_prnt(str), (uintptr_t)min_len, | ||
1953 | (uintptr_t)max_len); | ||
1954 | } | ||
1955 | } | ||
1956 | return t_failed; | ||
1957 | } | ||
1958 | |||
1959 | |||
1960 | int check_strx_to_sizet_n_no_val(void) | ||
1961 | { | ||
1962 | size_t t_failed = 0; | ||
1963 | size_t i, j; | ||
1964 | static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]); | ||
1965 | int c_failed[n_checks]; | ||
1966 | |||
1967 | memset(c_failed, 0, sizeof(c_failed)); | ||
1968 | |||
1969 | for(j = 0; j < locale_name_count; j++) | ||
1970 | { | ||
1971 | set_test_locale(j); /* setlocale() can be slow! */ | ||
1972 | for(i = 0; i < n_checks; i++) | ||
1973 | { | ||
1974 | size_t rs; | ||
1975 | const struct str_with_len * const t = str_no_num + i; | ||
1976 | static const size_t rnd_val = 3214314212; | ||
1977 | size_t len; | ||
1978 | |||
1979 | for (len = 0; len <= t->len + 1; len++) | ||
1980 | { | ||
1981 | size_t test_val; | ||
1982 | for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) | ||
1983 | { | ||
1984 | size_t rv = test_val; | ||
1985 | |||
1986 | rs = MHD_strx_to_sizet_n_(t->str, len, &rv); | ||
1987 | if (rs != 0) | ||
1988 | { | ||
1989 | t_failed++; | ||
1990 | c_failed[i] = !0; | ||
1991 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")" | ||
1992 | " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", | ||
1993 | n_prnt(t->str), (uintptr_t)len, (uint64_t)rv, (uintptr_t)rs, get_current_locale_str()); | ||
1994 | } | ||
1995 | else if (rv != test_val) | ||
1996 | { | ||
1997 | t_failed++; | ||
1998 | c_failed[i] = !0; | ||
1999 | fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", &ret_val)" | ||
2000 | " modified value of ret_val (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 ")." | ||
2001 | " Locale: %s\n", n_prnt(t->str), (uintptr_t)len, (uint64_t)test_val, (uint64_t)rv, | ||
2002 | get_current_locale_str()); | ||
2003 | } | ||
2004 | } | ||
2005 | } | ||
2006 | if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i]) | ||
2007 | printf("PASSED: MHD_strx_to_sizet_n_(\"%s\", 0..%" PRIuPTR ", &ret_val) == 0," | ||
2008 | " value of ret_val is unmodified\n", n_prnt(t->str), | ||
2009 | (uintptr_t)t->len + 1); | ||
2010 | } | ||
2011 | } | ||
2012 | return t_failed; | ||
2013 | } | ||
2014 | |||
2015 | |||
2016 | int check_strx_to_uint32_valid(void) | 1499 | int check_strx_to_uint32_valid(void) |
2017 | { | 1500 | { |
2018 | size_t t_failed = 0; | 1501 | size_t t_failed = 0; |
@@ -2958,8 +2441,6 @@ int run_str_to_X_tests(void) | |||
2958 | { | 2441 | { |
2959 | int str_to_uint64_fails = 0; | 2442 | int str_to_uint64_fails = 0; |
2960 | int str_to_uint64_n_fails = 0; | 2443 | int str_to_uint64_n_fails = 0; |
2961 | int strx_to_sizet_fails = 0; | ||
2962 | int strx_to_sizet_n_fails = 0; | ||
2963 | int strx_to_uint32_fails = 0; | 2444 | int strx_to_uint32_fails = 0; |
2964 | int strx_to_uint32_n_fails = 0; | 2445 | int strx_to_uint32_n_fails = 0; |
2965 | int strx_to_uint64_fails = 0; | 2446 | int strx_to_uint64_fails = 0; |
@@ -3090,130 +2571,6 @@ int run_str_to_X_tests(void) | |||
3090 | else if (verbose > 0) | 2571 | else if (verbose > 0) |
3091 | printf("PASSED: function MHD_str_to_uint64_n_() successfully passed all checks.\n\n"); | 2572 | printf("PASSED: function MHD_str_to_uint64_n_() successfully passed all checks.\n\n"); |
3092 | 2573 | ||
3093 | res = check_strx_to_sizet_valid(); | ||
3094 | if (res != 0) | ||
3095 | { | ||
3096 | if (res < 0) | ||
3097 | { | ||
3098 | fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_valid().\n"); | ||
3099 | return 99; | ||
3100 | } | ||
3101 | strx_to_sizet_fails += res; | ||
3102 | fprintf(stderr, "FAILED: testcase check_strx_to_sizet_valid() failed.\n\n"); | ||
3103 | } | ||
3104 | else if (verbose > 1) | ||
3105 | printf("PASSED: testcase check_strx_to_sizet_valid() successfully passed.\n\n"); | ||
3106 | |||
3107 | res = check_strx_to_sizet_all_chars(); | ||
3108 | if (res != 0) | ||
3109 | { | ||
3110 | if (res < 0) | ||
3111 | { | ||
3112 | fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_all_chars().\n"); | ||
3113 | return 99; | ||
3114 | } | ||
3115 | strx_to_sizet_fails += res; | ||
3116 | fprintf(stderr, "FAILED: testcase check_strx_to_sizet_all_chars() failed.\n\n"); | ||
3117 | } | ||
3118 | else if (verbose > 1) | ||
3119 | printf("PASSED: testcase check_strx_to_sizet_all_chars() successfully passed.\n\n"); | ||
3120 | |||
3121 | res = check_strx_to_sizet_overflow(); | ||
3122 | if (res != 0) | ||
3123 | { | ||
3124 | if (res < 0) | ||
3125 | { | ||
3126 | fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_overflow().\n"); | ||
3127 | return 99; | ||
3128 | } | ||
3129 | strx_to_sizet_fails += res; | ||
3130 | fprintf(stderr, "FAILED: testcase check_strx_to_sizet_overflow() failed.\n\n"); | ||
3131 | } | ||
3132 | else if (verbose > 1) | ||
3133 | printf("PASSED: testcase check_strx_to_sizet_overflow() successfully passed.\n\n"); | ||
3134 | |||
3135 | res = check_strx_to_sizet_no_val(); | ||
3136 | if (res != 0) | ||
3137 | { | ||
3138 | if (res < 0) | ||
3139 | { | ||
3140 | fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_no_val().\n"); | ||
3141 | return 99; | ||
3142 | } | ||
3143 | strx_to_sizet_fails += res; | ||
3144 | fprintf(stderr, "FAILED: testcase check_strx_to_sizet_no_val() failed.\n\n"); | ||
3145 | } | ||
3146 | else if (verbose > 1) | ||
3147 | printf("PASSED: testcase check_strx_to_sizet_no_val() successfully passed.\n\n"); | ||
3148 | |||
3149 | if (strx_to_sizet_fails) | ||
3150 | fprintf(stderr, "FAILED: function MHD_strx_to_sizet_() failed %d time%s.\n\n", | ||
3151 | strx_to_sizet_fails, strx_to_sizet_fails == 1 ? "" : "s"); | ||
3152 | else if (verbose > 0) | ||
3153 | printf("PASSED: function MHD_strx_to_sizet_() successfully passed all checks.\n\n"); | ||
3154 | |||
3155 | res = check_strx_to_sizet_n_valid(); | ||
3156 | if (res != 0) | ||
3157 | { | ||
3158 | if (res < 0) | ||
3159 | { | ||
3160 | fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_n_valid().\n"); | ||
3161 | return 99; | ||
3162 | } | ||
3163 | strx_to_sizet_n_fails += res; | ||
3164 | fprintf(stderr, "FAILED: testcase check_strx_to_sizet_n_valid() failed.\n\n"); | ||
3165 | } | ||
3166 | else if (verbose > 1) | ||
3167 | printf("PASSED: testcase check_strx_to_sizet_n_valid() successfully passed.\n\n"); | ||
3168 | |||
3169 | res = check_strx_to_sizet_n_all_chars(); | ||
3170 | if (res != 0) | ||
3171 | { | ||
3172 | if (res < 0) | ||
3173 | { | ||
3174 | fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_n_all_chars().\n"); | ||
3175 | return 99; | ||
3176 | } | ||
3177 | strx_to_sizet_n_fails += res; | ||
3178 | fprintf(stderr, "FAILED: testcase check_strx_to_sizet_n_all_chars() failed.\n\n"); | ||
3179 | } | ||
3180 | else if (verbose > 1) | ||
3181 | printf("PASSED: testcase check_strx_to_sizet_n_all_chars() successfully passed.\n\n"); | ||
3182 | |||
3183 | res = check_strx_to_sizet_n_overflow(); | ||
3184 | if (res != 0) | ||
3185 | { | ||
3186 | if (res < 0) | ||
3187 | { | ||
3188 | fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_n_overflow().\n"); | ||
3189 | return 99; | ||
3190 | } | ||
3191 | strx_to_sizet_n_fails += res; | ||
3192 | fprintf(stderr, "FAILED: testcase check_strx_to_sizet_n_overflow() failed.\n\n"); | ||
3193 | } | ||
3194 | else if (verbose > 1) | ||
3195 | printf("PASSED: testcase check_strx_to_sizet_n_overflow() successfully passed.\n\n"); | ||
3196 | |||
3197 | res = check_strx_to_sizet_n_no_val(); | ||
3198 | if (res != 0) | ||
3199 | { | ||
3200 | if (res < 0) | ||
3201 | { | ||
3202 | fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_n_no_val().\n"); | ||
3203 | return 99; | ||
3204 | } | ||
3205 | strx_to_sizet_n_fails += res; | ||
3206 | fprintf(stderr, "FAILED: testcase check_strx_to_sizet_n_no_val() failed.\n\n"); | ||
3207 | } | ||
3208 | else if (verbose > 1) | ||
3209 | printf("PASSED: testcase check_strx_to_sizet_n_no_val() successfully passed.\n\n"); | ||
3210 | |||
3211 | if (strx_to_sizet_n_fails) | ||
3212 | fprintf(stderr, "FAILED: function MHD_strx_to_sizet_n_() failed %d time%s.\n\n", | ||
3213 | strx_to_sizet_n_fails, strx_to_sizet_n_fails == 1 ? "" : "s"); | ||
3214 | else if (verbose > 0) | ||
3215 | printf("PASSED: function MHD_strx_to_sizet_n_() successfully passed all checks.\n\n"); | ||
3216 | |||
3217 | res = check_strx_to_uint32_valid(); | 2574 | res = check_strx_to_uint32_valid(); |
3218 | if (res != 0) | 2575 | if (res != 0) |
3219 | { | 2576 | { |
@@ -3463,7 +2820,6 @@ int run_str_to_X_tests(void) | |||
3463 | printf("PASSED: function MHD_strx_to_uint64_n_() successfully passed all checks.\n\n"); | 2820 | printf("PASSED: function MHD_strx_to_uint64_n_() successfully passed all checks.\n\n"); |
3464 | 2821 | ||
3465 | if (str_to_uint64_fails || str_to_uint64_n_fails || | 2822 | if (str_to_uint64_fails || str_to_uint64_n_fails || |
3466 | strx_to_sizet_fails || strx_to_sizet_n_fails || | ||
3467 | strx_to_uint32_fails || strx_to_uint32_n_fails || | 2823 | strx_to_uint32_fails || strx_to_uint32_n_fails || |
3468 | strx_to_uint64_fails || strx_to_uint64_n_fails) | 2824 | strx_to_uint64_fails || strx_to_uint64_n_fails) |
3469 | { | 2825 | { |