2 * Copyright (C) 2011-2025 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 (strtoull
, unsigned long long, (const char *, char **, int));
33 /* Subject sequence empty or invalid. */
35 const char input
[] = "";
37 unsigned long long result
;
39 result
= strtoull (input
, &ptr
, 10);
41 ASSERT (ptr
== input
);
42 ASSERT (errno
== 0 || errno
== EINVAL
);
45 const char input
[] = " ";
47 unsigned long long result
;
49 result
= strtoull (input
, &ptr
, 10);
51 ASSERT (ptr
== input
);
52 ASSERT (errno
== 0 || errno
== EINVAL
);
55 const char input
[] = " +";
57 unsigned long long result
;
59 result
= strtoull (input
, &ptr
, 10);
61 ASSERT (ptr
== input
);
62 ASSERT (errno
== 0 || errno
== EINVAL
);
65 const char input
[] = " -";
67 unsigned long long result
;
69 result
= strtoull (input
, &ptr
, 10);
71 ASSERT (ptr
== input
);
72 ASSERT (errno
== 0 || errno
== EINVAL
);
75 /* Simple integer values. */
77 const char input
[] = "0";
79 unsigned long long result
;
81 result
= strtoull (input
, &ptr
, 10);
83 ASSERT (ptr
== input
+ 1);
87 const char input
[] = "+0";
89 unsigned long long result
;
91 result
= strtoull (input
, &ptr
, 10);
93 ASSERT (ptr
== input
+ 2);
97 const char input
[] = "-0";
99 unsigned long long result
;
101 result
= strtoull (input
, &ptr
, 10);
102 ASSERT (result
== 0);
103 ASSERT (ptr
== input
+ 2);
107 const char input
[] = "23";
109 unsigned long long result
;
111 result
= strtoull (input
, &ptr
, 10);
112 ASSERT (result
== 23);
113 ASSERT (ptr
== input
+ 2);
117 const char input
[] = " 23";
119 unsigned long long result
;
121 result
= strtoull (input
, &ptr
, 10);
122 ASSERT (result
== 23);
123 ASSERT (ptr
== input
+ 3);
127 const char input
[] = "+23";
129 unsigned long long result
;
131 result
= strtoull (input
, &ptr
, 10);
132 ASSERT (result
== 23);
133 ASSERT (ptr
== input
+ 3);
137 const char input
[] = "-23";
139 unsigned long long result
;
141 result
= strtoull (input
, &ptr
, 10);
142 ASSERT (result
== - 23ULL);
143 ASSERT (ptr
== input
+ 3);
147 /* Large integer values. */
149 const char input
[] = "2147483647";
151 unsigned long long result
;
153 result
= strtoull (input
, &ptr
, 10);
154 ASSERT (result
== 2147483647);
155 ASSERT (ptr
== input
+ 10);
159 const char input
[] = "-2147483648";
161 unsigned long long result
;
163 result
= strtoull (input
, &ptr
, 10);
164 ASSERT (result
== - 2147483648ULL);
165 ASSERT (ptr
== input
+ 11);
169 const char input
[] = "4294967295";
171 unsigned long long result
;
173 result
= strtoull (input
, &ptr
, 10);
174 ASSERT (result
== 4294967295U);
175 ASSERT (ptr
== input
+ 10);
179 /* Hexadecimal integer syntax. */
181 const char input
[] = "0x2A";
183 unsigned long long result
;
185 result
= strtoull (input
, &ptr
, 10);
186 ASSERT (result
== 0ULL);
187 ASSERT (ptr
== input
+ 1);
191 const char input
[] = "0x2A";
193 unsigned long long result
;
195 result
= strtoull (input
, &ptr
, 16);
196 ASSERT (result
== 42ULL);
197 ASSERT (ptr
== input
+ 4);
201 const char input
[] = "0x2A";
203 unsigned long long result
;
205 result
= strtoull (input
, &ptr
, 0);
206 ASSERT (result
== 42ULL);
207 ASSERT (ptr
== input
+ 4);
211 const char input
[] = "0x";
213 unsigned long long result
;
215 result
= strtoull (input
, &ptr
, 10);
216 ASSERT (result
== 0ULL);
217 ASSERT (ptr
== input
+ 1);
221 const char input
[] = "0x";
223 unsigned long long result
;
225 result
= strtoull (input
, &ptr
, 16);
226 ASSERT (result
== 0ULL);
227 ASSERT (ptr
== input
+ 1);
231 const char input
[] = "0x";
233 unsigned long long result
;
235 result
= strtoull (input
, &ptr
, 0);
236 ASSERT (result
== 0ULL);
237 ASSERT (ptr
== input
+ 1);
241 /* Binary integer syntax. */
243 const char input
[] = "0b111010";
245 unsigned long long result
;
247 result
= strtoull (input
, &ptr
, 10);
248 ASSERT (result
== 0ULL);
249 ASSERT (ptr
== input
+ 1);
253 const char input
[] = "0b111010";
255 unsigned long long result
;
257 result
= strtoull (input
, &ptr
, 2);
258 ASSERT (result
== 58ULL);
259 ASSERT (ptr
== input
+ 8);
263 const char input
[] = "0b111010";
265 unsigned long long result
;
267 result
= strtoull (input
, &ptr
, 0);
268 ASSERT (result
== 58ULL);
269 ASSERT (ptr
== input
+ 8);
273 const char input
[] = "0b";
275 unsigned long long result
;
277 result
= strtoull (input
, &ptr
, 10);
278 ASSERT (result
== 0ULL);
279 ASSERT (ptr
== input
+ 1);
283 const char input
[] = "0b";
285 unsigned long long result
;
287 result
= strtoull (input
, &ptr
, 2);
288 ASSERT (result
== 0ULL);
289 ASSERT (ptr
== input
+ 1);
293 const char input
[] = "0b";
295 unsigned long long result
;
297 result
= strtoull (input
, &ptr
, 0);
298 ASSERT (result
== 0ULL);
299 ASSERT (ptr
== input
+ 1);
303 return test_exit_status
;