This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #include <config.h>
18
19 #include <inttypes.h>
20
21 #include "signature.h"
22 #ifndef strtoimax
23 SIGNATURE_CHECK (strtoimax, intmax_t, (const char *, char **, int));
24 #endif
25
26 #include <errno.h>
27
28 #include "macros.h"
29
30 int
31 main (void)
32 {
33
34 {
35 const char input[] = "";
36 char *ptr;
37 intmax_t result;
38 errno = 0;
39 result = strtoimax (input, &ptr, 10);
40 ASSERT (result == 0);
41 ASSERT (ptr == input);
42 ASSERT (errno == 0 || errno == EINVAL);
43 }
44 {
45 const char input[] = " ";
46 char *ptr;
47 intmax_t result;
48 errno = 0;
49 result = strtoimax (input, &ptr, 10);
50 ASSERT (result == 0);
51 ASSERT (ptr == input);
52 ASSERT (errno == 0 || errno == EINVAL);
53 }
54 {
55 const char input[] = " +";
56 char *ptr;
57 intmax_t result;
58 errno = 0;
59 result = strtoimax (input, &ptr, 10);
60 ASSERT (result == 0);
61 ASSERT (ptr == input);
62 ASSERT (errno == 0 || errno == EINVAL);
63 }
64 {
65 const char input[] = " -";
66 char *ptr;
67 intmax_t result;
68 errno = 0;
69 result = strtoimax (input, &ptr, 10);
70 ASSERT (result == 0);
71 ASSERT (ptr == input);
72 ASSERT (errno == 0 || errno == EINVAL);
73 }
74
75
76 {
77 const char input[] = "0";
78 char *ptr;
79 intmax_t result;
80 errno = 0;
81 result = strtoimax (input, &ptr, 10);
82 ASSERT (result == 0);
83 ASSERT (ptr == input + 1);
84 ASSERT (errno == 0);
85 }
86 {
87 const char input[] = "+0";
88 char *ptr;
89 intmax_t result;
90 errno = 0;
91 result = strtoimax (input, &ptr, 10);
92 ASSERT (result == 0);
93 ASSERT (ptr == input + 2);
94 ASSERT (errno == 0);
95 }
96 {
97 const char input[] = "-0";
98 char *ptr;
99 intmax_t result;
100 errno = 0;
101 result = strtoimax (input, &ptr, 10);
102 ASSERT (result == 0);
103 ASSERT (ptr == input + 2);
104 ASSERT (errno == 0);
105 }
106 {
107 const char input[] = "23";
108 char *ptr;
109 intmax_t result;
110 errno = 0;
111 result = strtoimax (input, &ptr, 10);
112 ASSERT (result == 23);
113 ASSERT (ptr == input + 2);
114 ASSERT (errno == 0);
115 }
116 {
117 const char input[] = " 23";
118 char *ptr;
119 intmax_t result;
120 errno = 0;
121 result = strtoimax (input, &ptr, 10);
122 ASSERT (result == 23);
123 ASSERT (ptr == input + 3);
124 ASSERT (errno == 0);
125 }
126 {
127 const char input[] = "+23";
128 char *ptr;
129 intmax_t result;
130 errno = 0;
131 result = strtoimax (input, &ptr, 10);
132 ASSERT (result == 23);
133 ASSERT (ptr == input + 3);
134 ASSERT (errno == 0);
135 }
136 {
137 const char input[] = "-23";
138 char *ptr;
139 intmax_t result;
140 errno = 0;
141 result = strtoimax (input, &ptr, 10);
142 ASSERT (result == -23);
143 ASSERT (ptr == input + 3);
144 ASSERT (errno == 0);
145 }
146
147
148 {
149 const char input[] = "2147483647";
150 char *ptr;
151 intmax_t result;
152 errno = 0;
153 result = strtoimax (input, &ptr, 10);
154 ASSERT (result == 2147483647);
155 ASSERT (ptr == input + 10);
156 ASSERT (errno == 0);
157 }
158 {
159 const char input[] = "-2147483648";
160 char *ptr;
161 intmax_t result;
162 errno = 0;
163 result = strtoimax (input, &ptr, 10);
164 ASSERT (result == -2147483647 - 1);
165 ASSERT (ptr == input + 11);
166 ASSERT (errno == 0);
167 }
168 if (sizeof (intmax_t) > sizeof (int))
169 {
170 const char input[] = "4294967295";
171 char *ptr;
172 intmax_t result;
173 errno = 0;
174 result = strtoimax (input, &ptr, 10);
175 ASSERT (result == (intmax_t) 65535 * (intmax_t) 65537);
176 ASSERT (ptr == input + 10);
177 ASSERT (errno == 0);
178 }
179
180 return 0;
181 }