From 6219b2de00aedf24a9b8d12000ecb91b1b5aa602 Mon Sep 17 00:00:00 2001 From: Christian Jullien Date: Fri, 11 Nov 2022 07:12:49 +0100 Subject: [PATCH] Add tests on Windows for strtoll and strtoull. Tests can probably be used on all systems. --- tests/tests2/119_random_stuff.c | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/tests2/119_random_stuff.c b/tests/tests2/119_random_stuff.c index 95097b82..cbeeaa86 100644 --- a/tests/tests2/119_random_stuff.c +++ b/tests/tests2/119_random_stuff.c @@ -1,4 +1,15 @@ +#if defined(_WIN32) +/* + * strtoll and strtoull require the following define. + * Not really needed in our case + */ + #if !defined(_ISOC99_SOURCE) + #define _ISOC99_SOURCE 1 + #endif +#endif + #include +#include struct big_struct { char a[262144]; }; @@ -88,6 +99,33 @@ void tst_cast(void) printf ("schar to ushort cast: %x\n", r); } +void tst_strtoll_strtoull(void) +{ + /* + * It probably makes sense to run this test on all systems, + * not just on Windows. + */ +#if defined(_WIN32) + const unsigned int shift = 32; + + { + long long x = strtoll("0x100000000", NULL, 0); + x = (x >> shift); + if (x != 1LL) { + printf("Windows: strtoll error\n"); + } + } + + { + unsigned long long x = strtoll("0x100000000", NULL, 0); + x = (x >> shift); + if (x != 1) { + printf ("Windows: strtoull error\n"); + } + } +#endif +} + int main (void) { @@ -105,4 +143,5 @@ main (void) tst_compare(); tst_pack(); tst_cast(); + tst_strtoll_strtoull(); }