10 const char string0
[] = "-2";
11 const char string1
[] = "-9999999999999999999999";
12 const char string2
[] = "9999999999999999999999";
13 const char string3
[] = "-2test";
14 const char string4
[] = "test";
15 const char string5
[] = "023test";
16 const char string6
[] = "-0x23test";
21 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) && !defined(__SDCC_mcs51) // Lack of memory
24 ASSERT(strtoul("", 0, 10) == 0);
25 ASSERT(strtoul("2", 0, 10) == 2);
26 ASSERT(strtoul("3", 0, 10) == 3);
27 ASSERT(strtoul("23", 0, 10) == 23);
29 ASSERT(strtoul("23", 0, 0) == 23);
30 ASSERT(strtoul("023", 0, 0) == 023);
31 ASSERT(strtoul("0x23", 0, 0) == 0x23);
33 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202300L // C2X introduces binary prefix.
34 ASSERT(strtoul("0b11", 0, 0) == 0b11);
35 ASSERT(strtoul("0b11", 0, 2) == 0b11);
38 ASSERT(strtoul("+23", 0, 0) == +23);
39 ASSERT(strtoul("+023", 0, 0) == +023);
40 ASSERT(strtoul("+0x23", 0, 0) == +0x23);
42 ASSERT(strtol("-42", 0, 0) == -42);
43 ASSERT(strtol("-042", 0, 0) == -042);
44 ASSERT(strtol("-0x42", 0, 0) == -0x42);
45 ASSERT(strtol("-0x42", 0, 16) == -0x42);
47 #if ULONG_MAX == 4294967295
49 strtoul("4294967296", 0, 10);
50 ASSERT(errno
== ERANGE
);
54 ASSERT(strtol(string1
, &e
, 10) == LONG_MIN
);
55 ASSERT(errno
== ERANGE
);
56 ASSERT(e
== string1
+ strlen(string1
));
59 ASSERT(strtol(string2
, &e
, 10) == LONG_MAX
);
60 ASSERT(errno
== ERANGE
);
61 ASSERT(e
== string2
+ strlen(string2
));
64 ASSERT(strtoul(string0
, &e
, 10) == (unsigned long int)(-2));
65 ASSERT(errno
!= ERANGE
);
66 ASSERT(e
== string0
+ strlen(string0
));
69 ASSERT(strtoul(string2
, &e
, 10) == ULONG_MAX
);
70 ASSERT(errno
== ERANGE
);
71 ASSERT(e
== string2
+ strlen(string2
));
74 ASSERT(strtol(string3
, &e
, 10) == -2);
75 ASSERT(errno
!= ERANGE
);
76 ASSERT(e
== string3
+ 2);
79 ASSERT(strtol(string4
, &e
, 0) == 0);
80 ASSERT(errno
!= ERANGE
);
84 ASSERT(strtol(string5
, &e
, 0) == 023);
85 ASSERT(errno
!= ERANGE
);
86 ASSERT(e
== string5
+ 3);
89 ASSERT(strtol(string6
, &e
, 0) == -0x23);
90 ASSERT(errno
!= ERANGE
);
91 ASSERT(e
== string6
+ 5);