summaryrefslogtreecommitdiff
path: root/tests/test-limits-h.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2022-01-08 11:53:52 +0100
committerJörg Frings-Fürst <debian@jff.email>2022-01-08 11:53:52 +0100
commitfa838e76139763f902c7d27cb9e1d393ed6a15e4 (patch)
tree7d0ae09775ea950056193eaa2ca93844299d46f1 /tests/test-limits-h.c
parentc78359d9542c86b972aac373efcf7bc7a8a560e5 (diff)
parent2959e59fab3bab834368adefd90bd4b1b094366b (diff)
Merge branch 'feature/upstream' into develop
Diffstat (limited to 'tests/test-limits-h.c')
-rw-r--r--tests/test-limits-h.c78
1 files changed, 75 insertions, 3 deletions
diff --git a/tests/test-limits-h.c b/tests/test-limits-h.c
index 29b51273..b1b16154 100644
--- a/tests/test-limits-h.c
+++ b/tests/test-limits-h.c
@@ -1,5 +1,5 @@
/* Test of <limits.h> substitute.
- Copyright 2016-2018 Free Software Foundation, Inc.
+ Copyright 2016-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -26,11 +26,78 @@
# pragma GCC diagnostic ignored "-Woverlength-strings"
#endif
-/* Macros specified by ISO/IEC TS 18661-1:2014. */
-
#define verify_width(width, min, max) \
verify ((max) >> ((width) - 1 - ((min) < 0)) == 1)
+/* Macros borrowed from intprops.h. */
+#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
+#define TYPE_WIDTH(t) (sizeof (t) * CHAR_BIT)
+#define TYPE_MINIMUM(t) ((t) ~ TYPE_MAXIMUM (t))
+#define TYPE_MAXIMUM(t) \
+ ((t) (! TYPE_SIGNED (t) \
+ ? (t) -1 \
+ : ((((t) 1 << (TYPE_WIDTH (t) - 2)) - 1) * 2 + 1)))
+
+/* Type width macros. */
+
+int type_bits[] =
+ {
+ CHAR_BIT,
+ WORD_BIT,
+ LONG_BIT
+ };
+verify_width (CHAR_BIT, CHAR_MIN, CHAR_MAX);
+verify_width (WORD_BIT, INT_MIN, INT_MAX);
+verify_width (LONG_BIT, LONG_MIN, LONG_MAX);
+
+/* Numerical limit macros. */
+
+char limits1[] = { CHAR_MIN, CHAR_MAX };
+verify (TYPE_MINIMUM (char) == CHAR_MIN);
+verify (TYPE_MAXIMUM (char) == CHAR_MAX);
+
+signed char limits2[] = { SCHAR_MIN, SCHAR_MAX };
+verify (TYPE_MINIMUM (signed char) == SCHAR_MIN);
+verify (TYPE_MAXIMUM (signed char) == SCHAR_MAX);
+
+unsigned char limits3[] = { UCHAR_MAX };
+verify (TYPE_MINIMUM (unsigned char) == 0);
+verify (TYPE_MAXIMUM (unsigned char) == UCHAR_MAX);
+
+short limits4[] = { SHRT_MIN, SHRT_MAX };
+verify (TYPE_MINIMUM (short int) == SHRT_MIN);
+verify (TYPE_MAXIMUM (short int) == SHRT_MAX);
+
+unsigned short limits5[] = { USHRT_MAX };
+verify (TYPE_MINIMUM (unsigned short int) == 0);
+verify (TYPE_MAXIMUM (unsigned short int) == USHRT_MAX);
+
+int limits6[] = { INT_MIN, INT_MAX };
+verify (TYPE_MINIMUM (int) == INT_MIN);
+verify (TYPE_MAXIMUM (int) == INT_MAX);
+
+unsigned int limits7[] = { UINT_MAX };
+verify (TYPE_MINIMUM (unsigned int) == 0);
+verify (TYPE_MAXIMUM (unsigned int) == UINT_MAX);
+
+long limits8[] = { LONG_MIN, LONG_MAX };
+verify (TYPE_MINIMUM (long int) == LONG_MIN);
+verify (TYPE_MAXIMUM (long int) == LONG_MAX);
+
+unsigned long limits9[] = { ULONG_MAX };
+verify (TYPE_MINIMUM (unsigned long int) == 0);
+verify (TYPE_MAXIMUM (unsigned long int) == ULONG_MAX);
+
+long long limits10[] = { LLONG_MIN, LLONG_MAX };
+verify (TYPE_MINIMUM (long long int) == LLONG_MIN);
+verify (TYPE_MAXIMUM (long long int) == LLONG_MAX);
+
+unsigned long long limits11[] = { ULLONG_MAX };
+verify (TYPE_MINIMUM (unsigned long long int) == 0);
+verify (TYPE_MAXIMUM (unsigned long long int) == ULLONG_MAX);
+
+/* Macros specified by ISO/IEC TS 18661-1:2014. */
+
verify_width (CHAR_WIDTH, CHAR_MIN, CHAR_MAX);
verify_width (SCHAR_WIDTH, SCHAR_MIN, SCHAR_MAX);
verify_width (UCHAR_WIDTH, 0, UCHAR_MAX);
@@ -43,6 +110,11 @@ verify_width (ULONG_WIDTH, 0, ULONG_MAX);
verify_width (LLONG_WIDTH, LLONG_MIN, LLONG_MAX);
verify_width (ULLONG_WIDTH, 0, ULLONG_MAX);
+/* Macros specified by C2x. */
+
+int bool_attrs[] = { BOOL_MAX, BOOL_WIDTH };
+verify (BOOL_MAX == (((1U << (BOOL_WIDTH - 1)) - 1) * 2) + 1);
+
int
main (void)
{