commit a2b9612afb2687078ac1707e0d1896e690a49abb
parent 455e8ba49c7e238122730612097f3ca4d84c2356
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date: Thu, 25 Dec 2025 17:25:56 +0100
test_str_from_value.c: adapted to the new internal API
Diffstat:
1 file changed, 30 insertions(+), 27 deletions(-)
diff --git a/src/tests/unit/test_str_from_value.c b/src/tests/unit/test_str_from_value.c
@@ -31,9 +31,9 @@
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#else /* ! HAVE_INTTYPES_H */
-#define PRIu64 "llu"
-#define PRIuPTR "u"
-#define PRIX64 "llX"
+#define PRIuFAST64 "llu"
+#define PRIuPTR "llu"
+#define PRIXFAST64 "llX"
#endif /* ! HAVE_INTTYPES_H */
#include <stdint.h>
#ifdef HAVE_STDLIB_H
@@ -265,7 +265,7 @@ struct str_with_value
{
const struct str_with_len str;
const size_t num_of_digt;
- const uint64_t val;
+ const uint_fast64_t val;
};
/* valid string for conversion to unsigned integer value */
@@ -502,7 +502,7 @@ check_str_from_uint16 (void)
continue; /* Skip strings prefixed with zeros */
if (t->num_of_digt != t->str.len)
continue; /* Skip strings with suffixes */
- if (UINT16_MAX < t->val)
+ if ((t->val & 0xFFFFu) != t->val)
continue; /* Too large value to convert */
if (sizeof(buf) < t->str.len + 1)
{
@@ -518,7 +518,7 @@ check_str_from_uint16 (void)
/* fill buffer with pseudo-random values */
memcpy (buf, erase, sizeof(buf));
- rs = mhd_uint16_to_str ((uint16_t) t->val, buf, b_size);
+ rs = mhd_uint16_to_str ((uint_least16_t) t->val, buf, b_size);
if (t->num_of_digt > b_size)
{
@@ -529,7 +529,7 @@ check_str_from_uint16 (void)
t_failed++;
c_failed[i] = ! 0;
fprintf (stderr,
- "FAILED: mhd_uint16_to_str(%" PRIu64 ", -> buf,"
+ "FAILED: mhd_uint16_to_str(%" PRIuFAST64 ", -> buf,"
" %d) returned %" PRIuPTR
", while expecting 0."
" Locale: %s\n", t->val, (int) b_size, (uintptr_t) rs,
@@ -544,7 +544,7 @@ check_str_from_uint16 (void)
t_failed++;
c_failed[i] = ! 0;
fprintf (stderr,
- "FAILED: mhd_uint16_to_str(%" PRIu64 ", -> buf,"
+ "FAILED: mhd_uint16_to_str(%" PRIuFAST64 ", -> buf,"
" %d) returned %" PRIuPTR
", while expecting %d."
" Locale: %s\n", t->val, (int) b_size, (uintptr_t) rs,
@@ -556,7 +556,7 @@ check_str_from_uint16 (void)
t_failed++;
c_failed[i] = ! 0;
fprintf (stderr,
- "FAILED: mhd_uint16_to_str(%" PRIu64 ", -> \"%.*s\","
+ "FAILED: mhd_uint16_to_str(%" PRIuFAST64 ", -> \"%.*s\","
" %d) returned %" PRIuPTR "."
" Locale: %s\n", t->val, (int) rs, buf, (int) b_size,
(uintptr_t) rs, get_current_locale_str ());
@@ -567,7 +567,7 @@ check_str_from_uint16 (void)
t_failed++;
c_failed[i] = ! 0;
fprintf (stderr,
- "FAILED: mhd_uint16_to_str(%" PRIu64 ", -> \"%.*s\","
+ "FAILED: mhd_uint16_to_str(%" PRIuFAST64 ", -> \"%.*s\","
" %d) returned %" PRIuPTR
" and touched data after the resulting string."
" Locale: %s\n", t->val, (int) rs, buf, (int) b_size,
@@ -576,7 +576,7 @@ check_str_from_uint16 (void)
}
}
if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i])
- printf ("PASSED: mhd_uint16_to_str(%" PRIu64 ", -> \"%.*s\", %d) "
+ printf ("PASSED: mhd_uint16_to_str(%" PRIuFAST64 ", -> \"%.*s\", %d) "
"== %" PRIuPTR "\n",
t->val, (int) rs, buf, (int) b_size - 1, (uintptr_t) rs);
}
@@ -652,7 +652,7 @@ check_str_from_uint64 (void)
t_failed++;
c_failed[i] = ! 0;
fprintf (stderr,
- "FAILED: mhd_uint64_to_str(%" PRIu64 ", -> buf,"
+ "FAILED: mhd_uint64_to_str(%" PRIuFAST64 ", -> buf,"
" %d) returned %" PRIuPTR
", while expecting 0."
" Locale: %s\n", t->val, (int) b_size, (uintptr_t) rs,
@@ -667,7 +667,7 @@ check_str_from_uint64 (void)
t_failed++;
c_failed[i] = ! 0;
fprintf (stderr,
- "FAILED: mhd_uint64_to_str(%" PRIu64 ", -> buf,"
+ "FAILED: mhd_uint64_to_str(%" PRIuFAST64 ", -> buf,"
" %d) returned %" PRIuPTR
", while expecting %d."
" Locale: %s\n", t->val, (int) b_size, (uintptr_t) rs,
@@ -679,7 +679,7 @@ check_str_from_uint64 (void)
t_failed++;
c_failed[i] = ! 0;
fprintf (stderr,
- "FAILED: mhd_uint64_to_str(%" PRIu64 ", -> \"%.*s\","
+ "FAILED: mhd_uint64_to_str(%" PRIuFAST64 ", -> \"%.*s\","
" %d) returned %" PRIuPTR "."
" Locale: %s\n", t->val, (int) rs, buf, (int) b_size,
(uintptr_t) rs, get_current_locale_str ());
@@ -690,7 +690,7 @@ check_str_from_uint64 (void)
t_failed++;
c_failed[i] = ! 0;
fprintf (stderr,
- "FAILED: mhd_uint64_to_str(%" PRIu64 ", -> \"%.*s\","
+ "FAILED: mhd_uint64_to_str(%" PRIuFAST64 ", -> \"%.*s\","
" %d) returned %" PRIuPTR
" and touched data after the resulting string."
" Locale: %s\n", t->val, (int) rs, buf, (int) b_size,
@@ -699,7 +699,7 @@ check_str_from_uint64 (void)
}
}
if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i])
- printf ("PASSED: mhd_uint64_to_str(%" PRIu64 ", -> \"%.*s\", %d) "
+ printf ("PASSED: mhd_uint64_to_str(%" PRIuFAST64 ", -> \"%.*s\", %d) "
"== %" PRIuPTR "\n",
t->val, (int) rs, buf, (int) b_size - 1, (uintptr_t) rs);
}
@@ -750,7 +750,7 @@ check_strx_from_uint32 (void)
continue; /* Skip strings prefixed with zeros */
if (t->num_of_digt != t->str.len)
continue; /* Skip strings with suffixes */
- if (UINT32_MAX < t->val)
+ if ((t->val & 0xFFFFFFFFu) != t->val)
continue; /* Too large value to convert */
if (sizeof(buf) < t->str.len + 1)
{
@@ -766,7 +766,7 @@ check_strx_from_uint32 (void)
/* fill buffer with pseudo-random values */
memcpy (buf, erase, sizeof(buf));
- rs = mhd_uint32_to_strx ((uint32_t) t->val, buf, b_size);
+ rs = mhd_uint32_to_strx ((uint_fast32_t) t->val, buf, b_size);
if (t->num_of_digt > b_size)
{
@@ -777,7 +777,7 @@ check_strx_from_uint32 (void)
t_failed++;
c_failed[i] = ! 0;
fprintf (stderr,
- "FAILED: mhd_uint32_to_strx(0x%" PRIX64 ", -> buf,"
+ "FAILED: mhd_uint32_to_strx(0x%" PRIXFAST64 ", -> buf,"
" %d) returned %" PRIuPTR
", while expecting 0."
" Locale: %s\n", t->val, (int) b_size, (uintptr_t) rs,
@@ -792,7 +792,7 @@ check_strx_from_uint32 (void)
t_failed++;
c_failed[i] = ! 0;
fprintf (stderr,
- "FAILED: mhd_uint32_to_strx(0x%" PRIX64 ", -> buf,"
+ "FAILED: mhd_uint32_to_strx(0x%" PRIXFAST64 ", -> buf,"
" %d) returned %" PRIuPTR
", while expecting %d."
" Locale: %s\n", t->val, (int) b_size, (uintptr_t) rs,
@@ -805,7 +805,8 @@ check_strx_from_uint32 (void)
t_failed++;
c_failed[i] = ! 0;
fprintf (stderr,
- "FAILED: mhd_uint32_to_strx(0x%" PRIX64 ", -> \"%.*s\","
+ "FAILED: mhd_uint32_to_strx(0x%" PRIXFAST64
+ ", -> \"%.*s\","
" %d) returned %" PRIuPTR "."
" Locale: %s\n", t->val, (int) rs, buf, (int) b_size,
(uintptr_t) rs, get_current_locale_str ());
@@ -824,7 +825,8 @@ check_strx_from_uint32 (void)
t_failed++;
c_failed[i] = ! 0;
fprintf (stderr,
- "FAILED: mhd_uint32_to_strx(0x%" PRIX64 ", -> \"%.*s\","
+ "FAILED: mhd_uint32_to_strx(0x%" PRIXFAST64
+ ", -> \"%.*s\","
" %d) returned %" PRIuPTR
" and touched data after the resulting string."
" Locale: %s\n", t->val, (int) rs, buf, (int) b_size,
@@ -833,7 +835,8 @@ check_strx_from_uint32 (void)
}
}
if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i])
- printf ("PASSED: mhd_uint32_to_strx(0x%" PRIX64 ", -> \"%.*s\", %d) "
+ printf ("PASSED: mhd_uint32_to_strx(0x%" PRIXFAST64
+ ", -> \"%.*s\", %d) "
"== %" PRIuPTR "\n",
t->val, (int) rs, buf, (int) b_size - 1, (uintptr_t) rs);
}
@@ -1685,7 +1688,7 @@ check_str_from_uint8_pad (void)
{
t_failed++;
fprintf (stderr,
- "FAILED: mhd_uint8_to_str_pad(%" PRIu64 ", %d, -> buf,"
+ "FAILED: mhd_uint8_to_str_pad(%" PRIuFAST64 ", %d, -> buf,"
" %d) returned %" PRIuPTR
", while expecting 0.\n", t->val, (int) pad, (int) b_size,
(uintptr_t) rs);
@@ -1697,7 +1700,7 @@ check_str_from_uint8_pad (void)
{
t_failed++;
fprintf (stderr,
- "FAILED: mhd_uint8_to_str_pad(%" PRIu64 ", %d, -> buf,"
+ "FAILED: mhd_uint8_to_str_pad(%" PRIuFAST64 ", %d, -> buf,"
" %d) returned %" PRIuPTR
", while expecting %d.\n", t->val, (int) pad,
(int) b_size, (uintptr_t) rs, (int) t->num_of_digt);
@@ -1706,7 +1709,7 @@ check_str_from_uint8_pad (void)
{
t_failed++;
fprintf (stderr,
- "FAILED: mhd_uint8_to_str_pad(%" PRIu64 ", %d, "
+ "FAILED: mhd_uint8_to_str_pad(%" PRIuFAST64 ", %d, "
"-> \"%.*s\", %d) returned %" PRIuPTR ".\n",
t->val, (int) pad, (int) rs, buf,
(int) b_size, (uintptr_t) rs);
@@ -1715,7 +1718,7 @@ check_str_from_uint8_pad (void)
{
t_failed++;
fprintf (stderr,
- "FAILED: mhd_uint8_to_str_pad(%" PRIu64 ", %d,"
+ "FAILED: mhd_uint8_to_str_pad(%" PRIuFAST64 ", %d,"
" -> \"%.*s\", %d) returned %" PRIuPTR
" and touched data after the resulting string.\n",
t->val, (int) pad, (int) rs, buf, (int) b_size,