1 //===-- A template class for testing strto* functions -----------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "src/__support/CPP/limits.h"
10 #include "src/__support/CPP/type_traits.h"
11 #include "src/__support/ctype_utils.h"
12 #include "src/__support/macros/properties/architectures.h"
13 #include "src/errno/libc_errno.h"
14 #include "test/UnitTest/Test.h"
18 using LIBC_NAMESPACE::cpp::is_signed_v
;
20 template <typename ReturnT
>
21 struct StrtoTest
: public LIBC_NAMESPACE::testing::Test
{
22 using FunctionT
= ReturnT (*)(const char *, char **, int);
24 static constexpr ReturnT T_MAX
=
25 LIBC_NAMESPACE::cpp::numeric_limits
<ReturnT
>::max();
26 static constexpr ReturnT T_MIN
=
27 LIBC_NAMESPACE::cpp::numeric_limits
<ReturnT
>::min();
29 void InvalidBase(FunctionT func
) {
30 const char *ten
= "10";
31 LIBC_NAMESPACE::libc_errno
= 0;
32 ASSERT_EQ(func(ten
, nullptr, -1), ReturnT(0));
33 ASSERT_ERRNO_EQ(EINVAL
);
36 void CleanBaseTenDecode(FunctionT func
) {
37 char *str_end
= nullptr;
39 // TODO: Look into collapsing these repeated segments.
40 const char *ten
= "10";
41 LIBC_NAMESPACE::libc_errno
= 0;
42 ASSERT_EQ(func(ten
, &str_end
, 10), ReturnT(10));
43 ASSERT_ERRNO_SUCCESS();
44 EXPECT_EQ(str_end
- ten
, ptrdiff_t(2));
46 LIBC_NAMESPACE::libc_errno
= 0;
47 ASSERT_EQ(func(ten
, nullptr, 10), ReturnT(10));
48 ASSERT_ERRNO_SUCCESS();
50 const char *hundred
= "100";
51 LIBC_NAMESPACE::libc_errno
= 0;
52 ASSERT_EQ(func(hundred
, &str_end
, 10), ReturnT(100));
53 ASSERT_ERRNO_SUCCESS();
54 EXPECT_EQ(str_end
- hundred
, ptrdiff_t(3));
56 const char *big_number
= "1234567890";
57 LIBC_NAMESPACE::libc_errno
= 0;
58 ASSERT_EQ(func(big_number
, &str_end
, 10), ReturnT(1234567890));
59 ASSERT_ERRNO_SUCCESS();
60 EXPECT_EQ(str_end
- big_number
, ptrdiff_t(10));
62 // This number is larger than 2^32, meaning that if long is only 32 bits
63 // wide, strtol will return LONG_MAX.
64 const char *bigger_number
= "12345678900";
65 LIBC_NAMESPACE::libc_errno
= 0;
66 if constexpr (sizeof(ReturnT
) < 8) {
67 ASSERT_EQ(func(bigger_number
, &str_end
, 10), T_MAX
);
68 ASSERT_ERRNO_EQ(ERANGE
);
70 ASSERT_EQ(func(bigger_number
, &str_end
, 10), ReturnT(12345678900));
71 ASSERT_ERRNO_SUCCESS();
73 EXPECT_EQ(str_end
- bigger_number
, ptrdiff_t(11));
75 const char *too_big_number
= "123456789012345678901";
76 LIBC_NAMESPACE::libc_errno
= 0;
77 ASSERT_EQ(func(too_big_number
, &str_end
, 10), T_MAX
);
78 ASSERT_ERRNO_EQ(ERANGE
);
79 EXPECT_EQ(str_end
- too_big_number
, ptrdiff_t(21));
81 const char *long_number_range_test
=
82 "10000000000000000000000000000000000000000000000000";
83 LIBC_NAMESPACE::libc_errno
= 0;
84 ASSERT_EQ(func(long_number_range_test
, &str_end
, 10), T_MAX
);
85 ASSERT_ERRNO_EQ(ERANGE
);
86 EXPECT_EQ(str_end
- long_number_range_test
, ptrdiff_t(50));
88 // For most negative numbers, the unsigned functions treat it the same as
89 // casting a negative variable to an unsigned type.
90 const char *negative
= "-100";
91 LIBC_NAMESPACE::libc_errno
= 0;
92 ASSERT_EQ(func(negative
, &str_end
, 10), ReturnT(-100));
93 ASSERT_ERRNO_SUCCESS();
94 EXPECT_EQ(str_end
- negative
, ptrdiff_t(4));
96 const char *big_negative_number
= "-1234567890";
97 LIBC_NAMESPACE::libc_errno
= 0;
98 ASSERT_EQ(func(big_negative_number
, &str_end
, 10), ReturnT(-1234567890));
99 ASSERT_ERRNO_SUCCESS();
100 EXPECT_EQ(str_end
- big_negative_number
, ptrdiff_t(11));
102 const char *too_big_negative_number
= "-123456789012345678901";
103 LIBC_NAMESPACE::libc_errno
= 0;
104 // If the number is signed, it should return the smallest negative number
105 // for the current type, but if it's unsigned it should max out and return
106 // the largest positive number for the current type. From the standard:
107 // "If the correct value is outside the range of representable values,
108 // LONG_MIN, LONG_MAX, LLONG_MIN, LLONG_MAX, ULONG_MAX, or ULLONG_MAX is
110 // Note that 0 is not on that list.
111 ASSERT_EQ(func(too_big_negative_number
, &str_end
, 10),
112 (is_signed_v
<ReturnT
> ? T_MIN
: T_MAX
));
113 ASSERT_ERRNO_EQ(ERANGE
);
114 EXPECT_EQ(str_end
- too_big_negative_number
, ptrdiff_t(22));
117 void MessyBaseTenDecode(FunctionT func
) {
118 char *str_end
= nullptr;
120 const char *spaces_before
= " 10";
121 LIBC_NAMESPACE::libc_errno
= 0;
122 ASSERT_EQ(func(spaces_before
, &str_end
, 10), ReturnT(10));
123 ASSERT_ERRNO_SUCCESS();
124 EXPECT_EQ(str_end
- spaces_before
, ptrdiff_t(7));
126 const char *spaces_after
= "10 ";
127 LIBC_NAMESPACE::libc_errno
= 0;
128 ASSERT_EQ(func(spaces_after
, &str_end
, 10), ReturnT(10));
129 ASSERT_ERRNO_SUCCESS();
130 EXPECT_EQ(str_end
- spaces_after
, ptrdiff_t(2));
132 const char *word_before
= "word10";
133 LIBC_NAMESPACE::libc_errno
= 0;
134 ASSERT_EQ(func(word_before
, &str_end
, 10), ReturnT(0));
135 ASSERT_ERRNO_SUCCESS();
136 EXPECT_EQ(str_end
- word_before
, ptrdiff_t(0));
138 const char *word_after
= "10word";
139 LIBC_NAMESPACE::libc_errno
= 0;
140 ASSERT_EQ(func(word_after
, &str_end
, 10), ReturnT(10));
141 ASSERT_ERRNO_SUCCESS();
142 EXPECT_EQ(str_end
- word_after
, ptrdiff_t(2));
144 const char *two_numbers
= "10 999";
145 LIBC_NAMESPACE::libc_errno
= 0;
146 ASSERT_EQ(func(two_numbers
, &str_end
, 10), ReturnT(10));
147 ASSERT_ERRNO_SUCCESS();
148 EXPECT_EQ(str_end
- two_numbers
, ptrdiff_t(2));
150 const char *two_signs
= "--10 999";
151 LIBC_NAMESPACE::libc_errno
= 0;
152 ASSERT_EQ(func(two_signs
, &str_end
, 10), ReturnT(0));
153 ASSERT_ERRNO_SUCCESS();
154 EXPECT_EQ(str_end
- two_signs
, ptrdiff_t(0));
156 const char *sign_before
= "+2=4";
157 LIBC_NAMESPACE::libc_errno
= 0;
158 ASSERT_EQ(func(sign_before
, &str_end
, 10), ReturnT(2));
159 ASSERT_ERRNO_SUCCESS();
160 EXPECT_EQ(str_end
- sign_before
, ptrdiff_t(2));
162 const char *sign_after
= "2+2=4";
163 LIBC_NAMESPACE::libc_errno
= 0;
164 ASSERT_EQ(func(sign_after
, &str_end
, 10), ReturnT(2));
165 ASSERT_ERRNO_SUCCESS();
166 EXPECT_EQ(str_end
- sign_after
, ptrdiff_t(1));
168 const char *tab_before
= "\t10";
169 LIBC_NAMESPACE::libc_errno
= 0;
170 ASSERT_EQ(func(tab_before
, &str_end
, 10), ReturnT(10));
171 ASSERT_ERRNO_SUCCESS();
172 EXPECT_EQ(str_end
- tab_before
, ptrdiff_t(3));
174 const char *all_together
= "\t -12345and+67890";
175 LIBC_NAMESPACE::libc_errno
= 0;
176 ASSERT_EQ(func(all_together
, &str_end
, 10), ReturnT(-12345));
177 ASSERT_ERRNO_SUCCESS();
178 EXPECT_EQ(str_end
- all_together
, ptrdiff_t(9));
180 const char *just_spaces
= " ";
181 LIBC_NAMESPACE::libc_errno
= 0;
182 ASSERT_EQ(func(just_spaces
, &str_end
, 10), ReturnT(0));
183 ASSERT_ERRNO_SUCCESS();
184 EXPECT_EQ(str_end
- just_spaces
, ptrdiff_t(0));
186 const char *just_space_and_sign
= " +";
187 LIBC_NAMESPACE::libc_errno
= 0;
188 ASSERT_EQ(func(just_space_and_sign
, &str_end
, 10), ReturnT(0));
189 ASSERT_ERRNO_SUCCESS();
190 EXPECT_EQ(str_end
- just_space_and_sign
, ptrdiff_t(0));
193 void DecodeInOtherBases(FunctionT func
) {
194 // This test is excessively slow on the GPU, so we limit the innermost loop.
195 #if defined(LIBC_TARGET_ARCH_IS_GPU)
196 constexpr int limit
= 0;
198 constexpr int limit
= 36;
200 char small_string
[4] = {'\0', '\0', '\0', '\0'};
201 for (int base
= 2; base
<= 36; ++base
) {
202 for (int first_digit
= 0; first_digit
<= 36; ++first_digit
) {
203 small_string
[0] = static_cast<char>(
204 LIBC_NAMESPACE::internal::int_to_b36_char(first_digit
));
205 if (first_digit
< base
) {
206 LIBC_NAMESPACE::libc_errno
= 0;
207 ASSERT_EQ(func(small_string
, nullptr, base
),
208 static_cast<ReturnT
>(first_digit
));
209 ASSERT_ERRNO_SUCCESS();
211 LIBC_NAMESPACE::libc_errno
= 0;
212 ASSERT_EQ(func(small_string
, nullptr, base
), ReturnT(0));
213 ASSERT_ERRNO_SUCCESS();
218 for (int base
= 2; base
<= 36; ++base
) {
219 for (int first_digit
= 0; first_digit
<= 36; ++first_digit
) {
220 small_string
[0] = static_cast<char>(
221 LIBC_NAMESPACE::internal::int_to_b36_char(first_digit
));
222 for (int second_digit
= 0; second_digit
<= 36; ++second_digit
) {
223 small_string
[1] = static_cast<char>(
224 LIBC_NAMESPACE::internal::int_to_b36_char(second_digit
));
225 if (first_digit
< base
&& second_digit
< base
) {
226 LIBC_NAMESPACE::libc_errno
= 0;
228 func(small_string
, nullptr, base
),
229 static_cast<ReturnT
>(second_digit
+ (first_digit
* base
)));
230 ASSERT_ERRNO_SUCCESS();
231 } else if (first_digit
< base
) {
232 LIBC_NAMESPACE::libc_errno
= 0;
233 ASSERT_EQ(func(small_string
, nullptr, base
),
234 static_cast<ReturnT
>(first_digit
));
235 ASSERT_ERRNO_SUCCESS();
237 LIBC_NAMESPACE::libc_errno
= 0;
238 ASSERT_EQ(func(small_string
, nullptr, base
), ReturnT(0));
239 ASSERT_ERRNO_SUCCESS();
245 for (int base
= 2; base
<= 36; ++base
) {
246 for (int first_digit
= 0; first_digit
<= 36; ++first_digit
) {
247 small_string
[0] = static_cast<char>(
248 LIBC_NAMESPACE::internal::int_to_b36_char(first_digit
));
249 for (int second_digit
= 0; second_digit
<= 36; ++second_digit
) {
250 small_string
[1] = static_cast<char>(
251 LIBC_NAMESPACE::internal::int_to_b36_char(second_digit
));
252 for (int third_digit
= 0; third_digit
<= limit
; ++third_digit
) {
253 small_string
[2] = static_cast<char>(
254 LIBC_NAMESPACE::internal::int_to_b36_char(third_digit
));
256 if (first_digit
< base
&& second_digit
< base
&&
257 third_digit
< base
) {
258 LIBC_NAMESPACE::libc_errno
= 0;
259 ASSERT_EQ(func(small_string
, nullptr, base
),
260 static_cast<ReturnT
>(third_digit
+
261 (second_digit
* base
) +
262 (first_digit
* base
* base
)));
263 ASSERT_ERRNO_SUCCESS();
264 } else if (first_digit
< base
&& second_digit
< base
) {
265 LIBC_NAMESPACE::libc_errno
= 0;
267 func(small_string
, nullptr, base
),
268 static_cast<ReturnT
>(second_digit
+ (first_digit
* base
)));
269 ASSERT_ERRNO_SUCCESS();
270 } else if (first_digit
< base
) {
271 // if the base is 16 there is a special case for the prefix 0X.
272 // The number is treated as a one digit hexadecimal.
273 if (base
== 16 && first_digit
== 0 && second_digit
== 33) {
274 if (third_digit
< base
) {
275 LIBC_NAMESPACE::libc_errno
= 0;
276 ASSERT_EQ(func(small_string
, nullptr, base
),
277 static_cast<ReturnT
>(third_digit
));
278 ASSERT_ERRNO_SUCCESS();
280 LIBC_NAMESPACE::libc_errno
= 0;
281 ASSERT_EQ(func(small_string
, nullptr, base
), ReturnT(0));
282 ASSERT_ERRNO_SUCCESS();
285 LIBC_NAMESPACE::libc_errno
= 0;
286 ASSERT_EQ(func(small_string
, nullptr, base
),
287 static_cast<ReturnT
>(first_digit
));
288 ASSERT_ERRNO_SUCCESS();
291 LIBC_NAMESPACE::libc_errno
= 0;
292 ASSERT_EQ(func(small_string
, nullptr, base
), ReturnT(0));
293 ASSERT_ERRNO_SUCCESS();
301 void CleanBaseSixteenDecode(FunctionT func
) {
302 char *str_end
= nullptr;
304 const char *no_prefix
= "123abc";
305 LIBC_NAMESPACE::libc_errno
= 0;
306 ASSERT_EQ(func(no_prefix
, &str_end
, 16), ReturnT(0x123abc));
307 ASSERT_ERRNO_SUCCESS();
308 EXPECT_EQ(str_end
- no_prefix
, ptrdiff_t(6));
310 const char *yes_prefix
= "0x456def";
311 LIBC_NAMESPACE::libc_errno
= 0;
312 ASSERT_EQ(func(yes_prefix
, &str_end
, 16), ReturnT(0x456def));
313 ASSERT_ERRNO_SUCCESS();
314 EXPECT_EQ(str_end
- yes_prefix
, ptrdiff_t(8));
316 const char *letter_after_prefix
= "0xabc123";
317 LIBC_NAMESPACE::libc_errno
= 0;
318 ASSERT_EQ(func(letter_after_prefix
, &str_end
, 16), ReturnT(0xabc123));
319 ASSERT_ERRNO_SUCCESS();
320 EXPECT_EQ(str_end
- letter_after_prefix
, ptrdiff_t(8));
322 // These tests check what happens when the number passed is exactly the max
323 // value for the conversion.
325 // Max size for unsigned 32 bit numbers
327 const char *max_32_bit_value
= "0xFFFFFFFF";
328 LIBC_NAMESPACE::libc_errno
= 0;
329 ASSERT_EQ(func(max_32_bit_value
, &str_end
, 0),
330 ((is_signed_v
<ReturnT
> && sizeof(ReturnT
) == 4)
332 : ReturnT(0xFFFFFFFF)));
333 ASSERT_ERRNO_EQ(is_signed_v
<ReturnT
> && sizeof(ReturnT
) == 4 ? ERANGE
: 0);
334 EXPECT_EQ(str_end
- max_32_bit_value
, ptrdiff_t(10));
336 const char *negative_max_32_bit_value
= "-0xFFFFFFFF";
337 LIBC_NAMESPACE::libc_errno
= 0;
338 ASSERT_EQ(func(negative_max_32_bit_value
, &str_end
, 0),
339 ((is_signed_v
<ReturnT
> && sizeof(ReturnT
) == 4)
341 : -ReturnT(0xFFFFFFFF)));
342 ASSERT_ERRNO_EQ(is_signed_v
<ReturnT
> && sizeof(ReturnT
) == 4 ? ERANGE
: 0);
343 EXPECT_EQ(str_end
- negative_max_32_bit_value
, ptrdiff_t(11));
345 // Max size for signed 32 bit numbers
347 const char *max_31_bit_value
= "0x7FFFFFFF";
348 LIBC_NAMESPACE::libc_errno
= 0;
349 ASSERT_EQ(func(max_31_bit_value
, &str_end
, 0), ReturnT(0x7FFFFFFF));
350 ASSERT_ERRNO_SUCCESS();
351 EXPECT_EQ(str_end
- max_31_bit_value
, ptrdiff_t(10));
353 const char *negative_max_31_bit_value
= "-0x7FFFFFFF";
354 LIBC_NAMESPACE::libc_errno
= 0;
355 ASSERT_EQ(func(negative_max_31_bit_value
, &str_end
, 0),
356 -ReturnT(0x7FFFFFFF));
357 ASSERT_ERRNO_SUCCESS();
358 EXPECT_EQ(str_end
- negative_max_31_bit_value
, ptrdiff_t(11));
360 // Max size for unsigned 64 bit numbers
362 const char *max_64_bit_value
= "0xFFFFFFFFFFFFFFFF";
363 LIBC_NAMESPACE::libc_errno
= 0;
364 ASSERT_EQ(func(max_64_bit_value
, &str_end
, 0),
365 (is_signed_v
<ReturnT
> || sizeof(ReturnT
) < 8
367 : ReturnT(0xFFFFFFFFFFFFFFFF)));
368 ASSERT_ERRNO_EQ((is_signed_v
<ReturnT
> || sizeof(ReturnT
) < 8 ? ERANGE
: 0));
369 EXPECT_EQ(str_end
- max_64_bit_value
, ptrdiff_t(18));
371 // See the end of CleanBase10Decode for an explanation of how this large
372 // negative number can end up as T_MAX.
373 const char *negative_max_64_bit_value
= "-0xFFFFFFFFFFFFFFFF";
374 LIBC_NAMESPACE::libc_errno
= 0;
376 func(negative_max_64_bit_value
, &str_end
, 0),
377 (is_signed_v
<ReturnT
>
379 : (sizeof(ReturnT
) < 8 ? T_MAX
: -ReturnT(0xFFFFFFFFFFFFFFFF))));
380 ASSERT_ERRNO_EQ((is_signed_v
<ReturnT
> || sizeof(ReturnT
) < 8 ? ERANGE
: 0));
381 EXPECT_EQ(str_end
- negative_max_64_bit_value
, ptrdiff_t(19));
383 // Max size for signed 64 bit numbers
385 const char *max_63_bit_value
= "0x7FFFFFFFFFFFFFFF";
386 LIBC_NAMESPACE::libc_errno
= 0;
387 ASSERT_EQ(func(max_63_bit_value
, &str_end
, 0),
388 (sizeof(ReturnT
) < 8 ? T_MAX
: ReturnT(0x7FFFFFFFFFFFFFFF)));
389 ASSERT_ERRNO_EQ(sizeof(ReturnT
) < 8 ? ERANGE
: 0);
390 EXPECT_EQ(str_end
- max_63_bit_value
, ptrdiff_t(18));
392 const char *negative_max_63_bit_value
= "-0x7FFFFFFFFFFFFFFF";
393 LIBC_NAMESPACE::libc_errno
= 0;
394 ASSERT_EQ(func(negative_max_63_bit_value
, &str_end
, 0),
395 (sizeof(ReturnT
) >= 8 ? -ReturnT(0x7FFFFFFFFFFFFFFF)
396 : (is_signed_v
<ReturnT
> ? T_MIN
: T_MAX
)));
397 ASSERT_ERRNO_EQ(sizeof(ReturnT
) < 8 ? ERANGE
: 0);
398 EXPECT_EQ(str_end
- negative_max_63_bit_value
, ptrdiff_t(19));
401 void MessyBaseSixteenDecode(FunctionT func
) {
402 char *str_end
= nullptr;
404 const char *just_prefix
= "0x";
405 LIBC_NAMESPACE::libc_errno
= 0;
406 ASSERT_EQ(func(just_prefix
, &str_end
, 16), ReturnT(0));
407 ASSERT_ERRNO_SUCCESS();
408 EXPECT_EQ(str_end
- just_prefix
, ptrdiff_t(1));
410 LIBC_NAMESPACE::libc_errno
= 0;
411 ASSERT_EQ(func(just_prefix
, &str_end
, 0), ReturnT(0));
412 ASSERT_ERRNO_SUCCESS();
413 EXPECT_EQ(str_end
- just_prefix
, ptrdiff_t(1));
415 const char *prefix_with_x_after
= "0xx";
416 LIBC_NAMESPACE::libc_errno
= 0;
417 ASSERT_EQ(func(prefix_with_x_after
, &str_end
, 16), ReturnT(0));
418 ASSERT_ERRNO_SUCCESS();
419 EXPECT_EQ(str_end
- prefix_with_x_after
, ptrdiff_t(1));
421 LIBC_NAMESPACE::libc_errno
= 0;
422 ASSERT_EQ(func(prefix_with_x_after
, &str_end
, 0), ReturnT(0));
423 ASSERT_ERRNO_SUCCESS();
424 EXPECT_EQ(str_end
- prefix_with_x_after
, ptrdiff_t(1));
427 void AutomaticBaseSelection(FunctionT func
) {
428 char *str_end
= nullptr;
430 const char *base_ten
= "12345";
431 LIBC_NAMESPACE::libc_errno
= 0;
432 ASSERT_EQ(func(base_ten
, &str_end
, 0), ReturnT(12345));
433 ASSERT_ERRNO_SUCCESS();
434 EXPECT_EQ(str_end
- base_ten
, ptrdiff_t(5));
436 const char *base_sixteen_no_prefix
= "123abc";
437 LIBC_NAMESPACE::libc_errno
= 0;
438 ASSERT_EQ(func(base_sixteen_no_prefix
, &str_end
, 0), ReturnT(123));
439 ASSERT_ERRNO_SUCCESS();
440 EXPECT_EQ(str_end
- base_sixteen_no_prefix
, ptrdiff_t(3));
442 const char *base_sixteen_with_prefix
= "0x456def";
443 LIBC_NAMESPACE::libc_errno
= 0;
444 ASSERT_EQ(func(base_sixteen_with_prefix
, &str_end
, 0), ReturnT(0x456def));
445 ASSERT_ERRNO_SUCCESS();
446 EXPECT_EQ(str_end
- base_sixteen_with_prefix
, ptrdiff_t(8));
448 const char *base_eight_with_prefix
= "012345";
449 LIBC_NAMESPACE::libc_errno
= 0;
450 ASSERT_EQ(func(base_eight_with_prefix
, &str_end
, 0), ReturnT(012345));
451 ASSERT_ERRNO_SUCCESS();
452 EXPECT_EQ(str_end
- base_eight_with_prefix
, ptrdiff_t(6));
454 const char *just_zero
= "0";
455 LIBC_NAMESPACE::libc_errno
= 0;
456 ASSERT_EQ(func(just_zero
, &str_end
, 0), ReturnT(0));
457 ASSERT_ERRNO_SUCCESS();
458 EXPECT_EQ(str_end
- just_zero
, ptrdiff_t(1));
460 const char *just_zero_x
= "0x";
461 LIBC_NAMESPACE::libc_errno
= 0;
462 ASSERT_EQ(func(just_zero_x
, &str_end
, 0), ReturnT(0));
463 ASSERT_ERRNO_SUCCESS();
464 EXPECT_EQ(str_end
- just_zero_x
, ptrdiff_t(1));
466 const char *just_zero_eight
= "08";
467 LIBC_NAMESPACE::libc_errno
= 0;
468 ASSERT_EQ(func(just_zero_eight
, &str_end
, 0), ReturnT(0));
469 ASSERT_ERRNO_SUCCESS();
470 EXPECT_EQ(str_end
- just_zero_eight
, ptrdiff_t(1));
474 template <typename ReturnType
>
475 StrtoTest(ReturnType (*)(const char *)) -> StrtoTest
<ReturnType
>;
477 #define STRTOL_TEST(name, func) \
478 using LlvmLibc##name##Test = StrtoTest<decltype(func("", nullptr, 0))>; \
479 TEST_F(LlvmLibc##name##Test, InvalidBase) { InvalidBase(func); } \
480 TEST_F(LlvmLibc##name##Test, CleanBaseTenDecode) { \
481 CleanBaseTenDecode(func); \
483 TEST_F(LlvmLibc##name##Test, MessyBaseTenDecode) { \
484 MessyBaseTenDecode(func); \
486 TEST_F(LlvmLibc##name##Test, DecodeInOtherBases) { \
487 DecodeInOtherBases(func); \
489 TEST_F(LlvmLibc##name##Test, CleanBaseSixteenDecode) { \
490 CleanBaseSixteenDecode(func); \
492 TEST_F(LlvmLibc##name##Test, MessyBaseSixteenDecode) { \
493 MessyBaseSixteenDecode(func); \
495 TEST_F(LlvmLibc##name##Test, AutomaticBaseSelection) { \
496 AutomaticBaseSelection(func); \