1 /* $NetBSD: t_wcstod.c,v 1.3 2011/10/01 17:56:11 christos Exp $ */
4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
30 * Copyright (c)2005 Citrus Project,
31 * All rights reserved.
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
42 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
43 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
46 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 #include <sys/cdefs.h>
57 __COPYRIGHT("@(#) Copyright (c) 2011\
58 The NetBSD Foundation, inc. All rights reserved.");
59 __RCSID("$NetBSD: t_wcstod.c,v 1.3 2011/10/01 17:56:11 christos Exp $");
69 #define ALT_HUGE_VAL -1
70 #define ALT_MINUS_HUGE_VAL -2
86 { L
"INF", 3, ALT_HUGE_VAL
, 0 },
87 { L
"+INF", 4, ALT_HUGE_VAL
, 0 },
88 { L
"-INF", 4, ALT_MINUS_HUGE_VAL
, 0 },
89 { L
"INFX", 3, ALT_HUGE_VAL
, 0 },
90 { L
"+INFX", 4, ALT_HUGE_VAL
, 0 },
91 { L
"-INFX", 4, ALT_MINUS_HUGE_VAL
, 0 },
96 { L
" +INX", 0, 0, 0 },
97 { L
" -INX", 0, 0, 0 },
98 { L
"+ INF", 0, 0, 0 },
99 { L
"- INF", 0, 0, 0 },
100 { L
" INF", 8, ALT_HUGE_VAL
, 0 },
101 { L
" +INF", 9, ALT_HUGE_VAL
, 0 },
102 { L
" -INF", 9, ALT_MINUS_HUGE_VAL
, 0 },
103 { L
" INFX", 8, ALT_HUGE_VAL
, 0 },
104 { L
" +INFX", 9, ALT_HUGE_VAL
, 0 },
105 { L
" -INFX", 9, ALT_MINUS_HUGE_VAL
, 0 },
106 { L
" INFINIT", 8, ALT_HUGE_VAL
, 0 },
107 { L
" +INFINIT", 9, ALT_HUGE_VAL
, 0 },
108 { L
" -INFINIT", 9, ALT_MINUS_HUGE_VAL
, 0 },
109 { L
" INFINITY", 13, ALT_HUGE_VAL
, 0 },
110 { L
" +INFINITY", 14, ALT_HUGE_VAL
, 0 },
111 { L
" -INFINITY", 14, ALT_MINUS_HUGE_VAL
, 0 },
112 { L
" INFINITYX", 13, ALT_HUGE_VAL
, 0 },
113 { L
" +INFINITYX", 14, ALT_HUGE_VAL
, 0 },
114 { L
" -INFINITYX", 14, ALT_MINUS_HUGE_VAL
, 0 },
121 { L
"+NAX", 0, 0, 0 },
122 { L
"-NAX", 0, 0, 0 },
123 { L
"NAN", 3, ALT_NAN
, 0 },
124 { L
"+NAN", 4, ALT_NAN
, 0 },
125 { L
"-NAN", 4, ALT_NAN
, 0 },
126 { L
"NANX", 3, ALT_NAN
, 0 },
127 { L
"+NANX", 4, ALT_NAN
, 0 },
128 { L
"-NANX", 4, ALT_NAN
, 0 },
130 { L
" +NA", 0, 0, 0 },
131 { L
" -NA", 0, 0, 0 },
132 { L
" NAX", 0, 0, 0 },
133 { L
" +NAX", 0, 0, 0 },
134 { L
" -NAX", 0, 0, 0 },
135 { L
"+ NAN", 0, 0, 0 },
136 { L
"- NAN", 0, 0, 0 },
137 { L
" NAN", 8, ALT_NAN
, 0 },
138 { L
" +NAN", 9, ALT_NAN
, 0 },
139 { L
" -NAN", 9, ALT_NAN
, 0 },
140 { L
" NANX", 8, ALT_NAN
, 0 },
141 { L
" +NANX", 9, ALT_NAN
, 0 },
142 { L
" -NANX", 9, ALT_NAN
, 0 },
148 { L
" +0", 12, 0, 0 },
149 { L
" -0", 12, 0, 0 },
156 { L
".000", 4, 0, 0 },
161 { L
" 0.", 12, 0, 0 },
162 { L
" +0.", 13, 0, 0 },
163 { L
" -0.", 13, 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 },
173 { L
"+000", 4, 0, 0 },
174 { L
"-000", 4, 0, 0 },
175 { L
" 000", 13, 0, 0 },
176 { L
" +000", 14, 0, 0 },
177 { L
" -000", 14, 0, 0 },
179 { L
"000.", 4, 0, 0 },
180 { L
"+000.", 5, 0, 0 },
181 { L
"-000.", 5, 0, 0 },
182 { L
" 000.", 14, 0, 0 },
183 { L
" +000.", 15, 0, 0 },
184 { L
" -000.", 15, 0, 0 },
186 { L
"000.0", 5, 0, 0 },
187 { L
"+000.0", 6, 0, 0 },
188 { L
"-000.0", 6, 0, 0 },
189 { L
" 000.0", 15, 0, 0 },
190 { L
" +000.0", 16, 0, 0 },
191 { L
" -000.0", 16, 0, 0 },
194 { L
"0.0.", 3, 0, 0 },
195 { L
"+0.0.", 4, 0, 0 },
196 { L
"-0.0.", 4, 0, 0 },
197 { L
" 0.0.", 13, 0, 0 },
198 { L
" +0.0.", 14, 0, 0 },
199 { L
" -0.0.", 14, 0, 0 },
201 { L
"0.0.0", 3, 0, 0 },
202 { L
"+0.0.0", 4, 0, 0 },
203 { L
"-0.0.0", 4, 0, 0 },
204 { L
" 0.0.0", 13, 0, 0 },
205 { L
" +0.0.0", 14, 0, 0 },
206 { L
" -0.0.0", 14, 0, 0 },
209 #if defined(__linux__)
219 /* XXX: SunOS 5.8's wcstod(3) doesn't accept hex */
220 #if !defined(__SunOS__)
221 #if defined(__linux__)
223 { L
"+0X.", 4, 0, 0 },
224 { L
"-0X.", 4, 0, 0 },
225 { L
" 0X.", 13, 0, 0 },
226 { L
" +0X.", 14, 0, 0 },
227 { L
" -0X.", 14, 0, 0 },
230 { L
"+0X.", 2, 0, 0 },
231 { L
"-0X.", 2, 0, 0 },
232 { L
" 0X.", 11, 0, 0 },
233 { L
" +0X.", 12, 0, 0 },
234 { L
" -0X.", 12, 0, 0 },
237 #if defined(__NetBSD__) || defined(__linux__)
238 { L
"0X.0", 4, 0, 0 },
239 { L
"+0X.0", 5, 0, 0 },
240 { L
"-0X.0", 5, 0, 0 },
241 { L
" 0X.0", 14, 0, 0 },
242 { L
" +0X.0", 15, 0, 0 },
243 { L
" -0X.0", 15, 0, 0 },
245 { L
"0X.0P", 4, 0, 0 },
246 { L
"+0X.0P", 5, 0, 0 },
247 { L
"-0X.0P", 5, 0, 0 },
248 { L
" 0X.0P", 14, 0, 0 },
249 { L
" +0X.0P", 15, 0, 0 },
250 { L
" -0X.0P", 15, 0, 0 },
252 { L
"0X.0", 1, 0, 0 },
253 { L
"+0X.0", 2, 0, 0 },
254 { L
"-0X.0", 2, 0, 0 },
255 { L
" 0X.0", 11, 0, 0 },
256 { L
" +0X.0", 12, 0, 0 },
257 { L
" -0X.0", 12, 0, 0 },
259 { L
"0X.0P", 1, 0, 0 },
260 { L
"+0X.0P", 2, 0, 0 },
261 { L
"-0X.0P", 2, 0, 0 },
262 { L
" 0X.0P", 11, 0, 0 },
263 { L
" +0X.0P", 12, 0, 0 },
264 { L
" -0X.0P", 12, 0, 0 },
268 { L
"+0X0", 4, 0, 0 },
269 { L
"-0X0", 4, 0, 0 },
270 { L
" 0X0", 13, 0, 0 },
271 { L
" +0X0", 14, 0, 0 },
272 { L
" -0X0", 14, 0, 0 },
274 { L
"00X0.0", 2, 0, 0 },
275 { L
"+00X0.0", 3, 0, 0 },
276 { L
"-00X0.0", 3, 0, 0 },
277 { L
" 00X0.0", 12, 0, 0 },
278 { L
" +00X0.0", 13, 0, 0 },
279 { L
" -00X0.0", 13, 0, 0 },
281 { L
"0X0P", 3, 0, 0 },
282 { L
"+0X0P", 4, 0, 0 },
283 { L
"-0X0P", 4, 0, 0 },
284 { L
" 0X0P", 13, 0, 0 },
285 { L
" +0X0P", 14, 0, 0 },
286 { L
" -0X0P", 14, 0, 0 },
288 { L
"0X0.", 4, 0, 0 },
289 { L
"+0X0.", 5, 0, 0 },
290 { L
"-0X0.", 5, 0, 0 },
291 { L
" 0X0.", 14, 0, 0 },
292 { L
" +0X0.", 15, 0, 0 },
293 { L
" -0X0.", 15, 0, 0 },
295 { L
"0X0.0", 5, 0, 0 },
296 { L
"+0X0.0", 6, 0, 0 },
297 { L
"-0X0.0", 6, 0, 0 },
298 { L
" 0X0.0", 15, 0, 0 },
299 { L
" +0X0.0", 16, 0, 0 },
300 { L
" -0X0.0", 16, 0, 0 },
302 { L
"0X0.P", 4, 0, 0 },
303 { L
"+0X0.P", 5, 0, 0 },
304 { L
"-0X0.P", 5, 0, 0 },
305 { L
" 0X0.P", 14, 0, 0 },
306 { L
" +0X0.P", 15, 0, 0 },
307 { L
" -0X0.P", 15, 0, 0 },
309 { L
"0X0.P", 4, 0, 0 },
310 { L
"+0X0.P", 5, 0, 0 },
311 { L
"-0X0.P", 5, 0, 0 },
312 { L
" 0X0.P", 14, 0, 0 },
313 { L
" +0X0.P", 15, 0, 0 },
314 { L
" -0X0.P", 15, 0, 0 },
317 { L
"0.12345678", 10, 0.12345678, 0 },
318 { L
"+0.12345678", 11, +0.12345678, 0 },
319 { L
"-0.12345678", 11, -0.12345678, 0 },
320 { L
" 0.12345678", 15, 0.12345678, 0 },
321 { L
" +0.12345678", 16, +0.12345678, 0 },
322 { L
" -0.12345678", 16, -0.12345678, 0 },
324 { L
"0.12345E67", 10, 0.12345E67
, 0 },
325 { L
"+0.12345E67", 11, +0.12345E67
, 0 },
326 { L
"-0.12345E67", 11, -0.12345E67
, 0 },
327 { L
" 0.12345E67", 15, 0.12345E67
, 0 },
328 { L
" +0.12345E67", 16, +0.12345E67
, 0 },
329 { L
" -0.12345E67", 16, -0.12345E67
, 0 },
331 { L
"0.12345E+6", 10, 0.12345E+6, 0 },
332 { L
"+0.12345E+6", 11, +0.12345E+6, 0 },
333 { L
"-0.12345E+6", 11, -0.12345E+6, 0 },
334 { L
" 0.12345E+6", 15, 0.12345E+6, 0 },
335 { L
" +0.12345E+6", 16, +0.12345E+6, 0 },
336 { L
" -0.12345E+6", 16, -0.12345E+6, 0 },
338 { L
"0.98765E-4", 10, 0.98765E-4, 0 },
339 { L
"+0.98765E-4", 11, +0.98765E-4, 0 },
340 { L
"-0.98765E-4", 11, -0.98765E-4, 0 },
341 { L
" 0.98765E-4", 15, 0.98765E-4, 0 },
342 { L
" +0.98765E-4", 16, +0.98765E-4, 0 },
343 { L
" -0.98765E-4", 16, -0.98765E-4, 0 },
345 { L
"12345678E9", 10, 12345678E9
, 0 },
346 { L
"+12345678E9", 11, +12345678E9
, 0 },
347 { L
"-12345678E9", 11, -12345678E9
, 0 },
348 { L
" 12345678E9", 15, 12345678E9
, 0 },
349 { L
" +12345678E9", 16, +12345678E9
, 0 },
350 { L
" -12345678E9", 16, -12345678E9
, 0 },
352 /* XXX: SunOS 5.8's wcstod(3) doesn't accept hex */
353 #if !defined(__SunOS__)
354 { L
"0x1P+2", 6, 4, 0 },
355 { L
"+0x1P+2", 7, +4, 0 },
356 { L
"-0x1P+2", 7, -4, 0 },
357 { L
" 0x1P+2", 11, 4, 0 },
358 { L
" +0x1P+2", 12, +4, 0 },
359 { L
" -0x1P+2", 12, -4, 0 },
361 { L
"0x1.0P+2", 8, 4, 0 },
362 { L
"+0x1.0P+2", 9, +4, 0 },
363 { L
"-0x1.0P+2", 9, -4, 0 },
364 { L
" 0x1.0P+2", 13, 4, 0 },
365 { L
" +0x1.0P+2", 14, +4, 0 },
366 { L
" -0x1.0P+2", 14, -4, 0 },
368 { L
"0x1P-2", 6, 0.25, 0 },
369 { L
"+0x1P-2", 7, +0.25, 0 },
370 { L
"-0x1P-2", 7, -0.25, 0 },
371 { L
" 0x1P-2", 11, 0.25, 0 },
372 { L
" +0x1P-2", 12, +0.25, 0 },
373 { L
" -0x1P-2", 12, -0.25, 0 },
375 { L
"0x1.0P-2", 8, 0.25, 0 },
376 { L
"+0x1.0P-2", 9, +0.25, 0 },
377 { L
"-0x1.0P-2", 9, -0.25, 0 },
378 { L
" 0x1.0P-2", 13, 0.25, 0 },
379 { L
" +0x1.0P-2", 14, +0.25, 0 },
380 { L
" -0x1.0P-2", 14, -0.25, 0 },
385 #endif /* !defined(__vax__) */
388 ATF_TC_HEAD(wcstod
, tc
)
390 atf_tc_set_md_var(tc
, "descr", "Checks wcstod(3)");
392 ATF_TC_BODY(wcstod
, tc
)
399 #if !defined(__vax__)
400 for (t
= &tests
[0]; t
->wcs
!= NULL
; ++t
) {
406 /* we do not supported %ls nor %S yet. */
407 n
= wcstombs(NULL
, t
->wcs
, 0);
408 ATF_REQUIRE((buf
= (void *)malloc(n
+ 1)) != NULL
);
409 (void)wcstombs(buf
, t
->wcs
, n
+ 1);
410 (void)printf("Checking wcstod(\"%s\", &tail):\n", buf
);
414 d
= wcstod(t
->wcs
, &tail
);
415 (void)printf("[errno]\n");
416 (void)printf(" got : %s\n", strerror(errno
));
417 (void)printf(" expected: %s\n", strerror(t
->err
));
418 ATF_REQUIRE_EQ(errno
, t
->err
);
420 n
= (size_t)(tail
- t
->wcs
);
421 (void)printf("[endptr - nptr]\n");
422 (void)printf(" got : %zd\n", n
);
423 (void)printf(" expected: %zd\n", t
->len
);
424 ATF_REQUIRE_EQ(n
, t
->len
);
426 (void)printf("[result]\n");
427 (void)printf(" real: %F\n", d
);
428 if (t
->val
== ALT_HUGE_VAL
) {
429 (void)printf(" expected: %F\n", HUGE_VAL
);
430 ATF_REQUIRE(isinf(d
));
431 ATF_REQUIRE_EQ(d
, HUGE_VAL
);
432 } else if (t
->val
== ALT_MINUS_HUGE_VAL
) {
433 (void)printf(" expected: %F\n", -HUGE_VAL
);
434 ATF_REQUIRE(isinf(d
));
435 ATF_REQUIRE_EQ(d
, -HUGE_VAL
);
436 } else if (t
->val
== ALT_NAN
) {
437 (void)printf(" expected: %F\n", NAN
);
438 ATF_REQUIRE(isnan(d
));
440 (void)printf(" expected: %F\n", t
->val
);
441 ATF_REQUIRE_EQ(d
, t
->val
);
446 #else /* !defined(__vax__) */
447 atf_tc_skip("Test is unavailable on vax.");
448 #endif /* !defined(__vax__) */
453 ATF_TP_ADD_TC(tp
, wcstod
);
455 return atf_no_error();