1 /* Test strtol functions with C2X binary integers.
2 Copyright (C) 2022-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
26 #include <support/check.h>
28 # include <support/support.h>
31 #define CONCAT_(X, Y) X ## Y
32 #define CONCAT(X, Y) CONCAT_ (X, Y)
33 #define FNX(FN) CONCAT (FNPFX, FN)
35 #define CHECK_RES(ARG, RES, EP, EXPECTED) \
40 TEST_COMPARE ((RES), EXPECTED); \
41 TEST_COMPARE (*(EP), 0); \
45 TEST_COMPARE ((RES), 0); \
46 TEST_VERIFY ((EP) == ((ARG)[0] == L_('-') \
54 one_check (const CHAR
*s
, long int expected_l
, unsigned long int expected_ul
,
55 long long int expected_ll
, unsigned long long int expected_ull
)
59 unsigned long int ret_ul
;
61 unsigned long long int ret_ull
;
62 ret_l
= FNX (l
) (s
, &ep
, 0);
63 CHECK_RES (s
, ret_l
, ep
, expected_l
);
64 ret_l
= FNX (l
) (s
, &ep
, 2);
65 CHECK_RES (s
, ret_l
, ep
, expected_l
);
66 ret_ul
= FNX (ul
) (s
, &ep
, 0);
67 CHECK_RES (s
, ret_ul
, ep
, expected_ul
);
68 ret_ul
= FNX (ul
) (s
, &ep
, 2);
69 CHECK_RES (s
, ret_ul
, ep
, expected_ul
);
70 ret_ll
= FNX (ll
) (s
, &ep
, 0);
71 CHECK_RES (s
, ret_ll
, ep
, expected_ll
);
72 ret_ll
= FNX (ll
) (s
, &ep
, 2);
73 CHECK_RES (s
, ret_ll
, ep
, expected_ll
);
74 ret_ull
= FNX (ull
) (s
, &ep
, 0);
75 CHECK_RES (s
, ret_ull
, ep
, expected_ull
);
76 ret_ull
= FNX (ull
) (s
, &ep
, 2);
77 CHECK_RES (s
, ret_ull
, ep
, expected_ull
);
78 ret_ll
= FNX (imax
) (s
, &ep
, 0);
79 CHECK_RES (s
, ret_ll
, ep
, expected_ll
);
80 ret_ll
= FNX (imax
) (s
, &ep
, 2);
81 CHECK_RES (s
, ret_ll
, ep
, expected_ll
);
82 ret_ull
= FNX (umax
) (s
, &ep
, 0);
83 CHECK_RES (s
, ret_ull
, ep
, expected_ull
);
84 ret_ull
= FNX (umax
) (s
, &ep
, 2);
85 CHECK_RES (s
, ret_ull
, ep
, expected_ull
);
87 ret_ll
= FNX (q
) (s
, &ep
, 0);
88 CHECK_RES (s
, ret_ll
, ep
, expected_ll
);
89 ret_ll
= FNX (q
) (s
, &ep
, 2);
90 CHECK_RES (s
, ret_ll
, ep
, expected_ll
);
91 ret_ull
= FNX (uq
) (s
, &ep
, 0);
92 CHECK_RES (s
, ret_ull
, ep
, expected_ull
);
93 ret_ull
= FNX (uq
) (s
, &ep
, 2);
94 CHECK_RES (s
, ret_ull
, ep
, expected_ull
);
97 locale_t loc
= xnewlocale (LC_NUMERIC_MASK
, "C", (locale_t
) 0);
98 ret_l
= FNX (l_l
) (s
, &ep
, 0, loc
);
99 CHECK_RES (s
, ret_l
, ep
, expected_l
);
100 ret_l
= FNX (l_l
) (s
, &ep
, 2, loc
);
101 CHECK_RES (s
, ret_l
, ep
, expected_l
);
102 ret_ul
= FNX (ul_l
) (s
, &ep
, 0, loc
);
103 CHECK_RES (s
, ret_ul
, ep
, expected_ul
);
104 ret_ul
= FNX (ul_l
) (s
, &ep
, 2, loc
);
105 CHECK_RES (s
, ret_ul
, ep
, expected_ul
);
106 ret_ll
= FNX (ll_l
) (s
, &ep
, 0, loc
);
107 CHECK_RES (s
, ret_ll
, ep
, expected_ll
);
108 ret_ll
= FNX (ll_l
) (s
, &ep
, 2, loc
);
109 CHECK_RES (s
, ret_ll
, ep
, expected_ll
);
110 ret_ull
= FNX (ull_l
) (s
, &ep
, 0, loc
);
111 CHECK_RES (s
, ret_ull
, ep
, expected_ull
);
112 ret_ull
= FNX (ull_l
) (s
, &ep
, 2, loc
);
113 CHECK_RES (s
, ret_ull
, ep
, expected_ull
);
120 one_check (L_("0b101"), 5, 5, 5, 5);
121 one_check (L_("0B101"), 5, 5, 5, 5);
122 one_check (L_("-0b11111"), -31, -31, -31, -31);
123 one_check (L_("-0B11111"), -31, -31, -31, -31);
124 one_check (L_("0b111111111111111111111111111111111"),
125 LONG_MAX
>= 0x1ffffffffLL
? (long int) 0x1ffffffffLL
: LONG_MAX
,
126 (ULONG_MAX
>= 0x1ffffffffULL
127 ? (unsigned long int) 0x1ffffffffULL
129 0x1ffffffffLL
, 0x1ffffffffULL
);
130 one_check (L_("0B111111111111111111111111111111111"),
131 LONG_MAX
>= 0x1ffffffffLL
? (long int) 0x1ffffffffLL
: LONG_MAX
,
132 (ULONG_MAX
>= 0x1ffffffffULL
133 ? (unsigned long int) 0x1ffffffffULL
135 0x1ffffffffLL
, 0x1ffffffffULL
);
136 one_check (L_("-0b111111111111111111111111111111111"),
137 LONG_MIN
<= -0x1ffffffffLL
? (long int) -0x1ffffffffLL
: LONG_MIN
,
138 (ULONG_MAX
>= 0x1ffffffffULL
139 ? (unsigned long int) -0x1ffffffffULL
141 -0x1ffffffffLL
, -0x1ffffffffULL
);
142 one_check (L_("-0B111111111111111111111111111111111"),
143 LONG_MIN
<= -0x1ffffffffLL
? (long int) -0x1ffffffffLL
: LONG_MIN
,
144 (ULONG_MAX
>= 0x1ffffffffULL
145 ? (unsigned long int) -0x1ffffffffULL
147 -0x1ffffffffLL
, -0x1ffffffffULL
);
151 #include <support/test-driver.c>