From 2c70f90798420c81eaf4a100d0fa5c6ab5771bcb Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 17 Apr 2023 08:44:51 -0700 Subject: Slightly nicer largefile, year2038 tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * modules/largefile-tests, modules/year2038-tests (Depends-on): Add assert-h, intprops. * tests/test-largefile.c, tests/test-year2038.c: Prefer compile-time to run-time tests. Don’t assume CHAR_BIT == 8. --- ChangeLog | 9 +++++++++ modules/largefile-tests | 2 ++ modules/year2038-tests | 2 ++ tests/test-largefile.c | 27 +++++++++++---------------- tests/test-year2038.c | 9 ++++----- 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index bd17733008..3e2682aac6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2023-04-17 Paul Eggert + + Slightly nicer largefile, year2038 tests + * modules/largefile-tests, modules/year2038-tests (Depends-on): + Add assert-h, intprops. + * tests/test-largefile.c, tests/test-year2038.c: + Prefer compile-time to run-time tests. + Don’t assume CHAR_BIT == 8. + 2023-04-17 Bruno Haible MODULES.html.sh: Ensure hyperlinked files are displayable. diff --git a/modules/largefile-tests b/modules/largefile-tests index 3241cceb5d..544070259a 100644 --- a/modules/largefile-tests +++ b/modules/largefile-tests @@ -2,6 +2,8 @@ Files: tests/test-largefile.c Depends-on: +assert-h +intprops sys_types sys_stat diff --git a/modules/year2038-tests b/modules/year2038-tests index ce51559a3c..63f00ee7f8 100644 --- a/modules/year2038-tests +++ b/modules/year2038-tests @@ -2,6 +2,8 @@ Files: tests/test-year2038.c Depends-on: +assert-h +intprops configure.ac: diff --git a/tests/test-largefile.c b/tests/test-largefile.c index 71ee7e942d..ce5d8a0e2e 100644 --- a/tests/test-largefile.c +++ b/tests/test-largefile.c @@ -24,24 +24,19 @@ #include #include +#include "intprops.h" + +/* Check the range of off_t. + With MSVC, this test succeeds only thanks to the 'sys_types' module. */ +static_assert (TYPE_MAXIMUM (off_t) >> 31 >> 31 != 0); + +/* Check the size of the 'struct stat' field 'st_size'. + ,With MSVC, this test succeeds only thanks to the 'sys_stat' module. */ +static struct stat st; +static_assert (sizeof st.st_size == sizeof (off_t)); int main (void) { - int result = 0; - - /* Check the size of off_t. - With MSVC, this test succeeds only thanks to the 'sys_types' module. */ - if (sizeof (off_t) <= 4) - result |= 1; - - /* Check the size of the 'struct stat' field 'st_size'. - With MSVC, this test succeeds only thanks to the 'sys_stat' module. */ - { - struct stat st; - if (sizeof (st.st_size) <= 4) - result |= 2; - } - - return result; + return 0; } diff --git a/tests/test-year2038.c b/tests/test-year2038.c index 58c1058b13..0facf930ed 100644 --- a/tests/test-year2038.c +++ b/tests/test-year2038.c @@ -26,14 +26,13 @@ #include #include +#include "intprops.h" + +/* Check the range of time_t. */ +static_assert (TYPE_MAXIMUM (time_t) >> 31 != 0); int main (void) { - /* Check the size and sign of time_t. */ - if (sizeof (time_t) <= 4 && (time_t)-1 < 0) - /* time_t is only 32 bits wide and signed. */ - return 1; - return 0; } -- cgit v1.2.1