2 * Copyright (C) 2011-2024 Free Software Foundation, Inc.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>. */
21 #include "signature.h"
23 SIGNATURE_CHECK (strtol
, long, (const char *, char **, int));
33 /* Subject sequence empty or invalid. */
35 const char input
[] = "";
39 result
= strtol (input
, &ptr
, 10);
41 ASSERT (ptr
== input
);
42 ASSERT (errno
== 0 || errno
== EINVAL
);
45 const char input
[] = " ";
49 result
= strtol (input
, &ptr
, 10);
51 ASSERT (ptr
== input
);
52 ASSERT (errno
== 0 || errno
== EINVAL
);
55 const char input
[] = " +";
59 result
= strtol (input
, &ptr
, 10);
61 ASSERT (ptr
== input
);
62 ASSERT (errno
== 0 || errno
== EINVAL
);
65 const char input
[] = " -";
69 result
= strtol (input
, &ptr
, 10);
71 ASSERT (ptr
== input
);
72 ASSERT (errno
== 0 || errno
== EINVAL
);
75 /* Simple integer values. */
77 const char input
[] = "0";
81 result
= strtol (input
, &ptr
, 10);
83 ASSERT (ptr
== input
+ 1);
87 const char input
[] = "+0";
91 result
= strtol (input
, &ptr
, 10);
93 ASSERT (ptr
== input
+ 2);
97 const char input
[] = "-0";
101 result
= strtol (input
, &ptr
, 10);
102 ASSERT (result
== 0);
103 ASSERT (ptr
== input
+ 2);
107 const char input
[] = "23";
111 result
= strtol (input
, &ptr
, 10);
112 ASSERT (result
== 23);
113 ASSERT (ptr
== input
+ 2);
117 const char input
[] = " 23";
121 result
= strtol (input
, &ptr
, 10);
122 ASSERT (result
== 23);
123 ASSERT (ptr
== input
+ 3);
127 const char input
[] = "+23";
131 result
= strtol (input
, &ptr
, 10);
132 ASSERT (result
== 23);
133 ASSERT (ptr
== input
+ 3);
137 const char input
[] = "-23";
141 result
= strtol (input
, &ptr
, 10);
142 ASSERT (result
== -23);
143 ASSERT (ptr
== input
+ 3);
147 /* Large integer values. */
149 const char input
[] = "2147483647";
153 result
= strtol (input
, &ptr
, 10);
154 ASSERT (result
== 2147483647);
155 ASSERT (ptr
== input
+ 10);
159 const char input
[] = "-2147483648";
163 result
= strtol (input
, &ptr
, 10);
164 ASSERT (result
== -2147483647 - 1);
165 ASSERT (ptr
== input
+ 11);
168 if (sizeof (long) > sizeof (int))
170 const char input
[] = "4294967295";
174 result
= strtol (input
, &ptr
, 10);
175 ASSERT (result
== (long) 4294967295UL);
176 ASSERT (ptr
== input
+ 10);
180 /* Hexadecimal integer syntax. */
182 const char input
[] = "0x2A";
186 result
= strtol (input
, &ptr
, 10);
187 ASSERT (result
== 0L);
188 ASSERT (ptr
== input
+ 1);
192 const char input
[] = "0x2A";
196 result
= strtol (input
, &ptr
, 16);
197 ASSERT (result
== 42L);
198 ASSERT (ptr
== input
+ 4);
202 const char input
[] = "0x2A";
206 result
= strtol (input
, &ptr
, 0);
207 ASSERT (result
== 42L);
208 ASSERT (ptr
== input
+ 4);
212 const char input
[] = "0x";
216 result
= strtol (input
, &ptr
, 10);
217 ASSERT (result
== 0L);
218 ASSERT (ptr
== input
+ 1);
222 const char input
[] = "0x";
226 result
= strtol (input
, &ptr
, 16);
227 ASSERT (result
== 0L);
228 ASSERT (ptr
== input
+ 1);
232 const char input
[] = "0x";
236 result
= strtol (input
, &ptr
, 0);
237 ASSERT (result
== 0L);
238 ASSERT (ptr
== input
+ 1);
242 /* Binary integer syntax. */
244 const char input
[] = "0b111010";
248 result
= strtol (input
, &ptr
, 10);
249 ASSERT (result
== 0L);
250 ASSERT (ptr
== input
+ 1);
254 const char input
[] = "0b111010";
258 result
= strtol (input
, &ptr
, 2);
259 ASSERT (result
== 58L);
260 ASSERT (ptr
== input
+ 8);
264 const char input
[] = "0b111010";
268 result
= strtol (input
, &ptr
, 0);
269 ASSERT (result
== 58L);
270 ASSERT (ptr
== input
+ 8);
274 const char input
[] = "0b";
278 result
= strtol (input
, &ptr
, 10);
279 ASSERT (result
== 0L);
280 ASSERT (ptr
== input
+ 1);
284 const char input
[] = "0b";
288 result
= strtol (input
, &ptr
, 2);
289 ASSERT (result
== 0L);
290 ASSERT (ptr
== input
+ 1);
294 const char input
[] = "0b";
298 result
= strtol (input
, &ptr
, 0);
299 ASSERT (result
== 0L);
300 ASSERT (ptr
== input
+ 1);
304 return test_exit_status
;