No empty .Rs/.Re
[netbsd-mini2440.git] / regress / lib / libc / locale / wcstod / wcstod_test.c
blobd91dafa98fd5980f165e24c05a5d1ce23e3699d5
1 /* $NetBSD: wcstod_test.c,v 1.1 2006/04/13 01:25:13 tnozaki Exp $ */
3 /*-
4 * Copyright (c)2005 Citrus Project,
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
29 #include <assert.h>
30 #include <errno.h>
31 #include <math.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <wchar.h>
36 typedef struct {
37 const wchar_t *wcs;
38 size_t exp_len;
39 double exp_val;
40 int exp_errno;
41 } unitcase_t;
43 #define ALT_HUGE_VAL -1
44 #define ALT_MINUS_HUGE_VAL -2
45 #define ALT_NAN -3
47 static const unitcase_t unitcases[] = {
49 { L"IN", 0, 0, 0 },
50 { L"+IN", 0, 0, 0 },
51 { L"-IN", 0, 0, 0 },
52 { L"INX", 0, 0, 0 },
53 { L"+INX", 0, 0, 0 },
54 { L"-INX", 0, 0, 0 },
55 { L"INF", 3, ALT_HUGE_VAL, 0 },
56 { L"+INF", 4, ALT_HUGE_VAL, 0 },
57 { L"-INF", 4, ALT_MINUS_HUGE_VAL, 0 },
58 { L"INFX", 3, ALT_HUGE_VAL, 0 },
59 { L"+INFX", 4, ALT_HUGE_VAL, 0 },
60 { L"-INFX", 4, ALT_MINUS_HUGE_VAL, 0 },
61 { L" IN", 0, 0, 0 },
62 { L" +IN", 0, 0, 0 },
63 { L" -IN", 0, 0, 0 },
64 { L" INX", 0, 0, 0 },
65 { L" +INX", 0, 0, 0 },
66 { L" -INX", 0, 0, 0 },
67 { L"+ INF", 0, 0, 0 },
68 { L"- INF", 0, 0, 0 },
69 { L" INF", 8, ALT_HUGE_VAL, 0 },
70 { L" +INF", 9, ALT_HUGE_VAL, 0 },
71 { L" -INF", 9, ALT_MINUS_HUGE_VAL, 0 },
72 { L" INFX", 8, ALT_HUGE_VAL, 0 },
73 { L" +INFX", 9, ALT_HUGE_VAL, 0 },
74 { L" -INFX", 9, ALT_MINUS_HUGE_VAL, 0 },
75 { L" INFINIT", 8, ALT_HUGE_VAL, 0 },
76 { L" +INFINIT", 9, ALT_HUGE_VAL, 0 },
77 { L" -INFINIT", 9, ALT_MINUS_HUGE_VAL, 0 },
78 { L" INFINITY", 13, ALT_HUGE_VAL, 0 },
79 { L" +INFINITY", 14, ALT_HUGE_VAL, 0 },
80 { L" -INFINITY", 14, ALT_MINUS_HUGE_VAL, 0 },
81 { L" INFINITYX", 13, ALT_HUGE_VAL, 0 },
82 { L" +INFINITYX", 14, ALT_HUGE_VAL, 0 },
83 { L" -INFINITYX", 14, ALT_MINUS_HUGE_VAL, 0 },
85 /* NAN */
86 #if defined(__HAVE_NANF)
87 { L"NA", 0, 0, 0 },
88 { L"+NA", 0, 0, 0 },
89 { L"-NA", 0, 0, 0 },
90 { L"NAX", 0, 0, 0 },
91 { L"+NAX", 0, 0, 0 },
92 { L"-NAX", 0, 0, 0 },
93 { L"NAN", 3, ALT_NAN, 0 },
94 { L"+NAN", 4, ALT_NAN, 0 },
95 { L"-NAN", 4, ALT_NAN, 0 },
96 { L"NANX", 3, ALT_NAN, 0 },
97 { L"+NANX", 4, ALT_NAN, 0 },
98 { L"-NANX", 4, ALT_NAN, 0 },
99 { L" NA", 0, 0, 0 },
100 { L" +NA", 0, 0, 0 },
101 { L" -NA", 0, 0, 0 },
102 { L" NAX", 0, 0, 0 },
103 { L" +NAX", 0, 0, 0 },
104 { L" -NAX", 0, 0, 0 },
105 { L"+ NAN", 0, 0, 0 },
106 { L"- NAN", 0, 0, 0 },
107 { L" NAN", 8, ALT_NAN, 0 },
108 { L" +NAN", 9, ALT_NAN, 0 },
109 { L" -NAN", 9, ALT_NAN, 0 },
110 { L" NANX", 8, ALT_NAN, 0 },
111 { L" +NANX", 9, ALT_NAN, 0 },
112 { L" -NANX", 9, ALT_NAN, 0 },
113 #endif /* !__HAVE_NANF */
115 { L"0", 1, 0, 0 },
116 { L"+0", 2, 0, 0 },
117 { L"-0", 2, 0, 0 },
118 { L" 0", 11, 0, 0 },
119 { L" +0", 12, 0, 0 },
120 { L" -0", 12, 0, 0 },
121 { L"+ 0", 0, 0, 0 },
122 { L"- 0", 0, 0, 0 },
124 { L".", 0, 0, 0 },
125 { L".0", 2, 0, 0 },
126 { L".00", 3, 0, 0 },
127 { L".000", 4, 0, 0 },
129 { L"0.", 2, 0, 0 },
130 { L"+0.", 3, 0, 0 },
131 { L"-0.", 3, 0, 0 },
132 { L" 0.", 12, 0, 0 },
133 { L" +0.", 13, 0, 0 },
134 { L" -0.", 13, 0, 0 },
136 { L"0.0", 3, 0, 0 },
137 { L"+0.0", 4, 0, 0 },
138 { L"-0.0", 4, 0, 0 },
139 { L" 0.0", 13, 0, 0 },
140 { L" +0.0", 14, 0, 0 },
141 { L" -0.0", 14, 0, 0 },
143 { L"000", 3, 0, 0 },
144 { L"+000", 4, 0, 0 },
145 { L"-000", 4, 0, 0 },
146 { L" 000", 13, 0, 0 },
147 { L" +000", 14, 0, 0 },
148 { L" -000", 14, 0, 0 },
150 { L"000.", 4, 0, 0 },
151 { L"+000.", 5, 0, 0 },
152 { L"-000.", 5, 0, 0 },
153 { L" 000.", 14, 0, 0 },
154 { L" +000.", 15, 0, 0 },
155 { L" -000.", 15, 0, 0 },
157 { L"000.0", 5, 0, 0 },
158 { L"+000.0", 6, 0, 0 },
159 { L"-000.0", 6, 0, 0 },
160 { L" 000.0", 15, 0, 0 },
161 { L" +000.0", 16, 0, 0 },
162 { L" -000.0", 16, 0, 0 },
165 { L"0.0.", 3, 0, 0 },
166 { L"+0.0.", 4, 0, 0 },
167 { L"-0.0.", 4, 0, 0 },
168 { L" 0.0.", 13, 0, 0 },
169 { L" +0.0.", 14, 0, 0 },
170 { L" -0.0.", 14, 0, 0 },
172 { L"0.0.0", 3, 0, 0 },
173 { L"+0.0.0", 4, 0, 0 },
174 { L"-0.0.0", 4, 0, 0 },
175 { L" 0.0.0", 13, 0, 0 },
176 { L" +0.0.0", 14, 0, 0 },
177 { L" -0.0.0", 14, 0, 0 },
179 /* XXX: FIXME */
180 #if defined(__NetBSD__)
181 { L"0X", 0, 0, 0 },
182 { L"+0X", 0, 0, 0 },
183 { L"-0X", 0, 0, 0 },
184 #elif defined(__linux__)
185 { L"0X", 2, 0, 0 },
186 { L"+0X", 3, 0, 0 },
187 { L"-0X", 3, 0, 0 },
188 #else
189 { L"0X", 1, 0, 0 },
190 { L"+0X", 2, 0, 0 },
191 { L"-0X", 2, 0, 0 },
192 #endif
194 /* XXX: SunOS 5.8's wcstod(3) doesn't accept hex */
195 #if !defined(__SunOS__)
196 /* XXX: FIXME */
197 #if defined(__NetBSD__)
198 { L"0X.", 0, 0, 0 },
199 { L"+0X.", 0, 0, 0 },
200 { L"-0X.", 0, 0, 0 },
201 { L" 0X.", 0, 0, 0 },
202 { L" +0X.", 0, 0, 0 },
203 { L" -0X.", 0, 0, 0 },
204 #elif defined(__linux__)
205 { L"0X.", 3, 0, 0 },
206 { L"+0X.", 4, 0, 0 },
207 { L"-0X.", 4, 0, 0 },
208 { L" 0X.", 13, 0, 0 },
209 { L" +0X.", 14, 0, 0 },
210 { L" -0X.", 14, 0, 0 },
211 #else
212 { L"0X.", 1, 0, 0 },
213 { L"+0X.", 2, 0, 0 },
214 { L"-0X.", 2, 0, 0 },
215 { L" 0X.", 11, 0, 0 },
216 { L" +0X.", 12, 0, 0 },
217 { L" -0X.", 12, 0, 0 },
218 #endif
219 /* XXX: FIXME */
220 #if defined(__NetBSD__) || defined(__linux__)
221 { L"0X.0", 4, 0, 0 },
222 { L"+0X.0", 5, 0, 0 },
223 { L"-0X.0", 5, 0, 0 },
224 { L" 0X.0", 14, 0, 0 },
225 { L" +0X.0", 15, 0, 0 },
226 { L" -0X.0", 15, 0, 0 },
228 { L"0X.0P", 4, 0, 0 },
229 { L"+0X.0P", 5, 0, 0 },
230 { L"-0X.0P", 5, 0, 0 },
231 { L" 0X.0P", 14, 0, 0 },
232 { L" +0X.0P", 15, 0, 0 },
233 { L" -0X.0P", 15, 0, 0 },
234 #else
235 { L"0X.0", 1, 0, 0 },
236 { L"+0X.0", 2, 0, 0 },
237 { L"-0X.0", 2, 0, 0 },
238 { L" 0X.0", 11, 0, 0 },
239 { L" +0X.0", 12, 0, 0 },
240 { L" -0X.0", 12, 0, 0 },
242 { L"0X.0P", 1, 0, 0 },
243 { L"+0X.0P", 2, 0, 0 },
244 { L"-0X.0P", 2, 0, 0 },
245 { L" 0X.0P", 11, 0, 0 },
246 { L" +0X.0P", 12, 0, 0 },
247 { L" -0X.0P", 12, 0, 0 },
248 #endif
250 { L"0X0", 3, 0, 0 },
251 { L"+0X0", 4, 0, 0 },
252 { L"-0X0", 4, 0, 0 },
253 { L" 0X0", 13, 0, 0 },
254 { L" +0X0", 14, 0, 0 },
255 { L" -0X0", 14, 0, 0 },
257 { L"00X0.0", 2, 0, 0 },
258 { L"+00X0.0", 3, 0, 0 },
259 { L"-00X0.0", 3, 0, 0 },
260 { L" 00X0.0", 12, 0, 0 },
261 { L" +00X0.0", 13, 0, 0 },
262 { L" -00X0.0", 13, 0, 0 },
264 { L"0X0P", 3, 0, 0 },
265 { L"+0X0P", 4, 0, 0 },
266 { L"-0X0P", 4, 0, 0 },
267 { L" 0X0P", 13, 0, 0 },
268 { L" +0X0P", 14, 0, 0 },
269 { L" -0X0P", 14, 0, 0 },
271 { L"0X0.", 4, 0, 0 },
272 { L"+0X0.", 5, 0, 0 },
273 { L"-0X0.", 5, 0, 0 },
274 { L" 0X0.", 14, 0, 0 },
275 { L" +0X0.", 15, 0, 0 },
276 { L" -0X0.", 15, 0, 0 },
278 { L"0X0.0", 5, 0, 0 },
279 { L"+0X0.0", 6, 0, 0 },
280 { L"-0X0.0", 6, 0, 0 },
281 { L" 0X0.0", 15, 0, 0 },
282 { L" +0X0.0", 16, 0, 0 },
283 { L" -0X0.0", 16, 0, 0 },
285 { L"0X0.P", 4, 0, 0 },
286 { L"+0X0.P", 5, 0, 0 },
287 { L"-0X0.P", 5, 0, 0 },
288 { L" 0X0.P", 14, 0, 0 },
289 { L" +0X0.P", 15, 0, 0 },
290 { L" -0X0.P", 15, 0, 0 },
292 { L"0X0.P", 4, 0, 0 },
293 { L"+0X0.P", 5, 0, 0 },
294 { L"-0X0.P", 5, 0, 0 },
295 { L" 0X0.P", 14, 0, 0 },
296 { L" +0X0.P", 15, 0, 0 },
297 { L" -0X0.P", 15, 0, 0 },
299 #endif
300 { L"0.12345678", 10, 0.12345678, 0 },
301 { L"+0.12345678", 11, +0.12345678, 0 },
302 { L"-0.12345678", 11, -0.12345678, 0 },
303 { L" 0.12345678", 15, 0.12345678, 0 },
304 { L" +0.12345678", 16, +0.12345678, 0 },
305 { L" -0.12345678", 16, -0.12345678, 0 },
307 { L"0.12345E67", 10, 0.12345E67, 0 },
308 { L"+0.12345E67", 11, +0.12345E67, 0 },
309 { L"-0.12345E67", 11, -0.12345E67, 0 },
310 { L" 0.12345E67", 15, 0.12345E67, 0 },
311 { L" +0.12345E67", 16, +0.12345E67, 0 },
312 { L" -0.12345E67", 16, -0.12345E67, 0 },
314 { L"0.12345E+6", 10, 0.12345E+6, 0 },
315 { L"+0.12345E+6", 11, +0.12345E+6, 0 },
316 { L"-0.12345E+6", 11, -0.12345E+6, 0 },
317 { L" 0.12345E+6", 15, 0.12345E+6, 0 },
318 { L" +0.12345E+6", 16, +0.12345E+6, 0 },
319 { L" -0.12345E+6", 16, -0.12345E+6, 0 },
321 { L"0.98765E-4", 10, 0.98765E-4, 0 },
322 { L"+0.98765E-4", 11, +0.98765E-4, 0 },
323 { L"-0.98765E-4", 11, -0.98765E-4, 0 },
324 { L" 0.98765E-4", 15, 0.98765E-4, 0 },
325 { L" +0.98765E-4", 16, +0.98765E-4, 0 },
326 { L" -0.98765E-4", 16, -0.98765E-4, 0 },
328 { L"12345678E9", 10, 12345678E9, 0 },
329 { L"+12345678E9", 11, +12345678E9, 0 },
330 { L"-12345678E9", 11, -12345678E9, 0 },
331 { L" 12345678E9", 15, 12345678E9, 0 },
332 { L" +12345678E9", 16, +12345678E9, 0 },
333 { L" -12345678E9", 16, -12345678E9, 0 },
335 /* XXX: SunOS 5.8's wcstod(3) doesn't accept hex */
336 #if !defined(__SunOS__)
337 { L"0x1P+2", 6, 4, 0 },
338 { L"+0x1P+2", 7, +4, 0 },
339 { L"-0x1P+2", 7, -4, 0 },
340 { L" 0x1P+2", 11, 4, 0 },
341 { L" +0x1P+2", 12, +4, 0 },
342 { L" -0x1P+2", 12, -4, 0 },
344 { L"0x1.0P+2", 8, 4, 0 },
345 { L"+0x1.0P+2", 9, +4, 0 },
346 { L"-0x1.0P+2", 9, -4, 0 },
347 { L" 0x1.0P+2", 13, 4, 0 },
348 { L" +0x1.0P+2", 14, +4, 0 },
349 { L" -0x1.0P+2", 14, -4, 0 },
351 { L"0x1P-2", 6, 0.25, 0 },
352 { L"+0x1P-2", 7, +0.25, 0 },
353 { L"-0x1P-2", 7, -0.25, 0 },
354 { L" 0x1P-2", 11, 0.25, 0 },
355 { L" +0x1P-2", 12, +0.25, 0 },
356 { L" -0x1P-2", 12, -0.25, 0 },
358 { L"0x1.0P-2", 8, 0.25, 0 },
359 { L"+0x1.0P-2", 9, +0.25, 0 },
360 { L"-0x1.0P-2", 9, -0.25, 0 },
361 { L" 0x1.0P-2", 13, 0.25, 0 },
362 { L" +0x1.0P-2", 14, +0.25, 0 },
363 { L" -0x1.0P-2", 14, -0.25, 0 },
364 #endif
366 { NULL, 0, 0, 0 }
370 main(void)
372 const unitcase_t *ptr;
373 double d;
374 size_t n;
375 char *buf;
376 wchar_t *tail;
378 for (ptr = &unitcases[0]; ptr->wcs != NULL; ++ptr) {
379 /* we do not supported %ls nor %S yet. */
380 n = wcstombs(NULL, ptr->wcs, 0);
381 buf = (void *)malloc(n + 1);
382 if (buf == NULL)
383 abort();
384 (void)wcstombs(buf, ptr->wcs, n + 1);
385 printf("[%.*s]====================================\n",
386 (int)n, buf);
387 errno = 0;
388 d = wcstod(ptr->wcs, &tail);
389 printf("[errno]\n");
390 printf(" real: %s\n", strerror(errno));
391 printf(" expected: %s\n", strerror(ptr->exp_errno));
392 assert(errno == ptr->exp_errno);
393 n = (size_t)(tail - ptr->wcs);
394 printf("[endptr - nptr]\n");
395 printf(" real: %zd\n", n);
396 printf(" expected: %zd\n", ptr->exp_len);
397 assert(n == ptr->exp_len);
398 printf("[result]\n");
399 printf(" real: %F\n", d);
400 if (ptr->exp_val == ALT_HUGE_VAL) {
401 printf(" expected: %F\n", HUGE_VAL);
402 assert(isinf(d) && d == HUGE_VAL);
403 } else if (ptr->exp_val == ALT_MINUS_HUGE_VAL) {
404 printf(" expected: %F\n", -HUGE_VAL);
405 assert(isinf(d) && d == -HUGE_VAL);
406 #if defined(__HAVE_NANF)
407 } else if (ptr->exp_val == ALT_NAN) {
408 printf(" expected: %F\n", NAN);
409 assert(isnan(d));
410 #endif
411 } else {
412 printf(" expected: %F\n", ptr->exp_val);
413 assert(d == ptr->exp_val);
416 return 0;