1*3d39ee5eSjoerg /* $NetBSD: t_wcstod.c,v 1.5 2017/07/14 14:09:53 joerg Exp $ */
2324074b9Spgoyette
3324074b9Spgoyette /*-
4324074b9Spgoyette * Copyright (c) 2011 The NetBSD Foundation, Inc.
5324074b9Spgoyette * All rights reserved.
6324074b9Spgoyette *
7324074b9Spgoyette * Redistribution and use in source and binary forms, with or without
8324074b9Spgoyette * modification, are permitted provided that the following conditions
9324074b9Spgoyette * are met:
10324074b9Spgoyette * 1. Redistributions of source code must retain the above copyright
11324074b9Spgoyette * notice, this list of conditions and the following disclaimer.
12324074b9Spgoyette * 2. Redistributions in binary form must reproduce the above copyright
13324074b9Spgoyette * notice, this list of conditions and the following disclaimer in the
14324074b9Spgoyette * documentation and/or other materials provided with the distribution.
15324074b9Spgoyette *
16324074b9Spgoyette * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17324074b9Spgoyette * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18324074b9Spgoyette * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19324074b9Spgoyette * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20324074b9Spgoyette * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21324074b9Spgoyette * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22324074b9Spgoyette * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23324074b9Spgoyette * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24324074b9Spgoyette * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25324074b9Spgoyette * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26324074b9Spgoyette * POSSIBILITY OF SUCH DAMAGE.
27324074b9Spgoyette */
28324074b9Spgoyette
29324074b9Spgoyette /*-
30324074b9Spgoyette * Copyright (c)2005 Citrus Project,
31324074b9Spgoyette * All rights reserved.
32324074b9Spgoyette *
33324074b9Spgoyette * Redistribution and use in source and binary forms, with or without
34324074b9Spgoyette * modification, are permitted provided that the following conditions
35324074b9Spgoyette * are met:
36324074b9Spgoyette * 1. Redistributions of source code must retain the above copyright
37324074b9Spgoyette * notice, this list of conditions and the following disclaimer.
38324074b9Spgoyette * 2. Redistributions in binary form must reproduce the above copyright
39324074b9Spgoyette * notice, this list of conditions and the following disclaimer in the
40324074b9Spgoyette * documentation and/or other materials provided with the distribution.
41324074b9Spgoyette *
42324074b9Spgoyette * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
43324074b9Spgoyette * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44324074b9Spgoyette * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45324074b9Spgoyette * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
46324074b9Spgoyette * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47324074b9Spgoyette * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48324074b9Spgoyette * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49324074b9Spgoyette * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50324074b9Spgoyette * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51324074b9Spgoyette * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52324074b9Spgoyette * SUCH DAMAGE.
53324074b9Spgoyette *
54324074b9Spgoyette */
55324074b9Spgoyette
56324074b9Spgoyette #include <sys/cdefs.h>
57324074b9Spgoyette __COPYRIGHT("@(#) Copyright (c) 2011\
58324074b9Spgoyette The NetBSD Foundation, inc. All rights reserved.");
59*3d39ee5eSjoerg __RCSID("$NetBSD: t_wcstod.c,v 1.5 2017/07/14 14:09:53 joerg Exp $");
60324074b9Spgoyette
61324074b9Spgoyette #include <errno.h>
62324074b9Spgoyette #include <math.h>
63324074b9Spgoyette #include <stdlib.h>
64324074b9Spgoyette #include <string.h>
65324074b9Spgoyette #include <wchar.h>
66324074b9Spgoyette
67324074b9Spgoyette #include <atf-c.h>
68324074b9Spgoyette
69324074b9Spgoyette #define ALT_HUGE_VAL -1
70324074b9Spgoyette #define ALT_MINUS_HUGE_VAL -2
71324074b9Spgoyette #define ALT_NAN -3
72324074b9Spgoyette
731ef7da4fSchristos #if !defined(__vax__)
74324074b9Spgoyette static struct test {
75324074b9Spgoyette const wchar_t *wcs;
76324074b9Spgoyette size_t len;
77324074b9Spgoyette double val;
78324074b9Spgoyette int err;
79324074b9Spgoyette } tests[] = {
80324074b9Spgoyette { L"IN", 0, 0, 0 },
81324074b9Spgoyette { L"+IN", 0, 0, 0 },
82324074b9Spgoyette { L"-IN", 0, 0, 0 },
83324074b9Spgoyette { L"INX", 0, 0, 0 },
84324074b9Spgoyette { L"+INX", 0, 0, 0 },
85324074b9Spgoyette { L"-INX", 0, 0, 0 },
86324074b9Spgoyette { L"INF", 3, ALT_HUGE_VAL, 0 },
87324074b9Spgoyette { L"+INF", 4, ALT_HUGE_VAL, 0 },
88324074b9Spgoyette { L"-INF", 4, ALT_MINUS_HUGE_VAL, 0 },
89324074b9Spgoyette { L"INFX", 3, ALT_HUGE_VAL, 0 },
90324074b9Spgoyette { L"+INFX", 4, ALT_HUGE_VAL, 0 },
91324074b9Spgoyette { L"-INFX", 4, ALT_MINUS_HUGE_VAL, 0 },
92324074b9Spgoyette { L" IN", 0, 0, 0 },
93324074b9Spgoyette { L" +IN", 0, 0, 0 },
94324074b9Spgoyette { L" -IN", 0, 0, 0 },
95324074b9Spgoyette { L" INX", 0, 0, 0 },
96324074b9Spgoyette { L" +INX", 0, 0, 0 },
97324074b9Spgoyette { L" -INX", 0, 0, 0 },
98324074b9Spgoyette { L"+ INF", 0, 0, 0 },
99324074b9Spgoyette { L"- INF", 0, 0, 0 },
100324074b9Spgoyette { L" INF", 8, ALT_HUGE_VAL, 0 },
101324074b9Spgoyette { L" +INF", 9, ALT_HUGE_VAL, 0 },
102324074b9Spgoyette { L" -INF", 9, ALT_MINUS_HUGE_VAL, 0 },
103324074b9Spgoyette { L" INFX", 8, ALT_HUGE_VAL, 0 },
104324074b9Spgoyette { L" +INFX", 9, ALT_HUGE_VAL, 0 },
105324074b9Spgoyette { L" -INFX", 9, ALT_MINUS_HUGE_VAL, 0 },
106324074b9Spgoyette { L" INFINIT", 8, ALT_HUGE_VAL, 0 },
107324074b9Spgoyette { L" +INFINIT", 9, ALT_HUGE_VAL, 0 },
108324074b9Spgoyette { L" -INFINIT", 9, ALT_MINUS_HUGE_VAL, 0 },
109324074b9Spgoyette { L" INFINITY", 13, ALT_HUGE_VAL, 0 },
110324074b9Spgoyette { L" +INFINITY", 14, ALT_HUGE_VAL, 0 },
111324074b9Spgoyette { L" -INFINITY", 14, ALT_MINUS_HUGE_VAL, 0 },
112324074b9Spgoyette { L" INFINITYX", 13, ALT_HUGE_VAL, 0 },
113324074b9Spgoyette { L" +INFINITYX", 14, ALT_HUGE_VAL, 0 },
114324074b9Spgoyette { L" -INFINITYX", 14, ALT_MINUS_HUGE_VAL, 0 },
115324074b9Spgoyette
116324074b9Spgoyette /* NAN */
117324074b9Spgoyette { L"NA", 0, 0, 0 },
118324074b9Spgoyette { L"+NA", 0, 0, 0 },
119324074b9Spgoyette { L"-NA", 0, 0, 0 },
120324074b9Spgoyette { L"NAX", 0, 0, 0 },
121324074b9Spgoyette { L"+NAX", 0, 0, 0 },
122324074b9Spgoyette { L"-NAX", 0, 0, 0 },
123324074b9Spgoyette { L"NAN", 3, ALT_NAN, 0 },
124324074b9Spgoyette { L"+NAN", 4, ALT_NAN, 0 },
125324074b9Spgoyette { L"-NAN", 4, ALT_NAN, 0 },
126324074b9Spgoyette { L"NANX", 3, ALT_NAN, 0 },
127324074b9Spgoyette { L"+NANX", 4, ALT_NAN, 0 },
128324074b9Spgoyette { L"-NANX", 4, ALT_NAN, 0 },
129324074b9Spgoyette { L" NA", 0, 0, 0 },
130324074b9Spgoyette { L" +NA", 0, 0, 0 },
131324074b9Spgoyette { L" -NA", 0, 0, 0 },
132324074b9Spgoyette { L" NAX", 0, 0, 0 },
133324074b9Spgoyette { L" +NAX", 0, 0, 0 },
134324074b9Spgoyette { L" -NAX", 0, 0, 0 },
135324074b9Spgoyette { L"+ NAN", 0, 0, 0 },
136324074b9Spgoyette { L"- NAN", 0, 0, 0 },
137324074b9Spgoyette { L" NAN", 8, ALT_NAN, 0 },
138324074b9Spgoyette { L" +NAN", 9, ALT_NAN, 0 },
139324074b9Spgoyette { L" -NAN", 9, ALT_NAN, 0 },
140324074b9Spgoyette { L" NANX", 8, ALT_NAN, 0 },
141324074b9Spgoyette { L" +NANX", 9, ALT_NAN, 0 },
142324074b9Spgoyette { L" -NANX", 9, ALT_NAN, 0 },
143324074b9Spgoyette
144324074b9Spgoyette { L"0", 1, 0, 0 },
145324074b9Spgoyette { L"+0", 2, 0, 0 },
146324074b9Spgoyette { L"-0", 2, 0, 0 },
147324074b9Spgoyette { L" 0", 11, 0, 0 },
148324074b9Spgoyette { L" +0", 12, 0, 0 },
149324074b9Spgoyette { L" -0", 12, 0, 0 },
150324074b9Spgoyette { L"+ 0", 0, 0, 0 },
151324074b9Spgoyette { L"- 0", 0, 0, 0 },
152324074b9Spgoyette
153324074b9Spgoyette { L".", 0, 0, 0 },
154324074b9Spgoyette { L".0", 2, 0, 0 },
155324074b9Spgoyette { L".00", 3, 0, 0 },
156324074b9Spgoyette { L".000", 4, 0, 0 },
157324074b9Spgoyette
158324074b9Spgoyette { L"0.", 2, 0, 0 },
159324074b9Spgoyette { L"+0.", 3, 0, 0 },
160324074b9Spgoyette { L"-0.", 3, 0, 0 },
161324074b9Spgoyette { L" 0.", 12, 0, 0 },
162324074b9Spgoyette { L" +0.", 13, 0, 0 },
163324074b9Spgoyette { L" -0.", 13, 0, 0 },
164324074b9Spgoyette
165324074b9Spgoyette { L"0.0", 3, 0, 0 },
166324074b9Spgoyette { L"+0.0", 4, 0, 0 },
167324074b9Spgoyette { L"-0.0", 4, 0, 0 },
168324074b9Spgoyette { L" 0.0", 13, 0, 0 },
169324074b9Spgoyette { L" +0.0", 14, 0, 0 },
170324074b9Spgoyette { L" -0.0", 14, 0, 0 },
171324074b9Spgoyette
172324074b9Spgoyette { L"000", 3, 0, 0 },
173324074b9Spgoyette { L"+000", 4, 0, 0 },
174324074b9Spgoyette { L"-000", 4, 0, 0 },
175324074b9Spgoyette { L" 000", 13, 0, 0 },
176324074b9Spgoyette { L" +000", 14, 0, 0 },
177324074b9Spgoyette { L" -000", 14, 0, 0 },
178324074b9Spgoyette
179324074b9Spgoyette { L"000.", 4, 0, 0 },
180324074b9Spgoyette { L"+000.", 5, 0, 0 },
181324074b9Spgoyette { L"-000.", 5, 0, 0 },
182324074b9Spgoyette { L" 000.", 14, 0, 0 },
183324074b9Spgoyette { L" +000.", 15, 0, 0 },
184324074b9Spgoyette { L" -000.", 15, 0, 0 },
185324074b9Spgoyette
186324074b9Spgoyette { L"000.0", 5, 0, 0 },
187324074b9Spgoyette { L"+000.0", 6, 0, 0 },
188324074b9Spgoyette { L"-000.0", 6, 0, 0 },
189324074b9Spgoyette { L" 000.0", 15, 0, 0 },
190324074b9Spgoyette { L" +000.0", 16, 0, 0 },
191324074b9Spgoyette { L" -000.0", 16, 0, 0 },
192324074b9Spgoyette
193324074b9Spgoyette
194324074b9Spgoyette { L"0.0.", 3, 0, 0 },
195324074b9Spgoyette { L"+0.0.", 4, 0, 0 },
196324074b9Spgoyette { L"-0.0.", 4, 0, 0 },
197324074b9Spgoyette { L" 0.0.", 13, 0, 0 },
198324074b9Spgoyette { L" +0.0.", 14, 0, 0 },
199324074b9Spgoyette { L" -0.0.", 14, 0, 0 },
200324074b9Spgoyette
201324074b9Spgoyette { L"0.0.0", 3, 0, 0 },
202324074b9Spgoyette { L"+0.0.0", 4, 0, 0 },
203324074b9Spgoyette { L"-0.0.0", 4, 0, 0 },
204324074b9Spgoyette { L" 0.0.0", 13, 0, 0 },
205324074b9Spgoyette { L" +0.0.0", 14, 0, 0 },
206324074b9Spgoyette { L" -0.0.0", 14, 0, 0 },
207324074b9Spgoyette
208324074b9Spgoyette /* XXX: FIXME */
209324074b9Spgoyette #if defined(__linux__)
210324074b9Spgoyette { L"0X", 2, 0, 0 },
211324074b9Spgoyette { L"+0X", 3, 0, 0 },
212324074b9Spgoyette { L"-0X", 3, 0, 0 },
213324074b9Spgoyette #else
214324074b9Spgoyette { L"0X", 1, 0, 0 },
215324074b9Spgoyette { L"+0X", 2, 0, 0 },
216324074b9Spgoyette { L"-0X", 2, 0, 0 },
217324074b9Spgoyette #endif
218324074b9Spgoyette
219324074b9Spgoyette /* XXX: SunOS 5.8's wcstod(3) doesn't accept hex */
220324074b9Spgoyette #if !defined(__SunOS__)
221324074b9Spgoyette #if defined(__linux__)
222324074b9Spgoyette { L"0X.", 3, 0, 0 },
223324074b9Spgoyette { L"+0X.", 4, 0, 0 },
224324074b9Spgoyette { L"-0X.", 4, 0, 0 },
225324074b9Spgoyette { L" 0X.", 13, 0, 0 },
226324074b9Spgoyette { L" +0X.", 14, 0, 0 },
227324074b9Spgoyette { L" -0X.", 14, 0, 0 },
228324074b9Spgoyette #else
229324074b9Spgoyette { L"0X.", 1, 0, 0 },
230324074b9Spgoyette { L"+0X.", 2, 0, 0 },
231324074b9Spgoyette { L"-0X.", 2, 0, 0 },
232324074b9Spgoyette { L" 0X.", 11, 0, 0 },
233324074b9Spgoyette { L" +0X.", 12, 0, 0 },
234324074b9Spgoyette { L" -0X.", 12, 0, 0 },
235324074b9Spgoyette #endif
236324074b9Spgoyette /* XXX: FIXME */
237324074b9Spgoyette #if defined(__NetBSD__) || defined(__linux__)
238324074b9Spgoyette { L"0X.0", 4, 0, 0 },
239324074b9Spgoyette { L"+0X.0", 5, 0, 0 },
240324074b9Spgoyette { L"-0X.0", 5, 0, 0 },
241324074b9Spgoyette { L" 0X.0", 14, 0, 0 },
242324074b9Spgoyette { L" +0X.0", 15, 0, 0 },
243324074b9Spgoyette { L" -0X.0", 15, 0, 0 },
244324074b9Spgoyette
245324074b9Spgoyette { L"0X.0P", 4, 0, 0 },
246324074b9Spgoyette { L"+0X.0P", 5, 0, 0 },
247324074b9Spgoyette { L"-0X.0P", 5, 0, 0 },
248324074b9Spgoyette { L" 0X.0P", 14, 0, 0 },
249324074b9Spgoyette { L" +0X.0P", 15, 0, 0 },
250324074b9Spgoyette { L" -0X.0P", 15, 0, 0 },
251324074b9Spgoyette #else
252324074b9Spgoyette { L"0X.0", 1, 0, 0 },
253324074b9Spgoyette { L"+0X.0", 2, 0, 0 },
254324074b9Spgoyette { L"-0X.0", 2, 0, 0 },
255324074b9Spgoyette { L" 0X.0", 11, 0, 0 },
256324074b9Spgoyette { L" +0X.0", 12, 0, 0 },
257324074b9Spgoyette { L" -0X.0", 12, 0, 0 },
258324074b9Spgoyette
259324074b9Spgoyette { L"0X.0P", 1, 0, 0 },
260324074b9Spgoyette { L"+0X.0P", 2, 0, 0 },
261324074b9Spgoyette { L"-0X.0P", 2, 0, 0 },
262324074b9Spgoyette { L" 0X.0P", 11, 0, 0 },
263324074b9Spgoyette { L" +0X.0P", 12, 0, 0 },
264324074b9Spgoyette { L" -0X.0P", 12, 0, 0 },
265324074b9Spgoyette #endif
266324074b9Spgoyette
267324074b9Spgoyette { L"0X0", 3, 0, 0 },
268324074b9Spgoyette { L"+0X0", 4, 0, 0 },
269324074b9Spgoyette { L"-0X0", 4, 0, 0 },
270324074b9Spgoyette { L" 0X0", 13, 0, 0 },
271324074b9Spgoyette { L" +0X0", 14, 0, 0 },
272324074b9Spgoyette { L" -0X0", 14, 0, 0 },
273324074b9Spgoyette
274324074b9Spgoyette { L"00X0.0", 2, 0, 0 },
275324074b9Spgoyette { L"+00X0.0", 3, 0, 0 },
276324074b9Spgoyette { L"-00X0.0", 3, 0, 0 },
277324074b9Spgoyette { L" 00X0.0", 12, 0, 0 },
278324074b9Spgoyette { L" +00X0.0", 13, 0, 0 },
279324074b9Spgoyette { L" -00X0.0", 13, 0, 0 },
280324074b9Spgoyette
281324074b9Spgoyette { L"0X0P", 3, 0, 0 },
282324074b9Spgoyette { L"+0X0P", 4, 0, 0 },
283324074b9Spgoyette { L"-0X0P", 4, 0, 0 },
284324074b9Spgoyette { L" 0X0P", 13, 0, 0 },
285324074b9Spgoyette { L" +0X0P", 14, 0, 0 },
286324074b9Spgoyette { L" -0X0P", 14, 0, 0 },
287324074b9Spgoyette
288324074b9Spgoyette { L"0X0.", 4, 0, 0 },
289324074b9Spgoyette { L"+0X0.", 5, 0, 0 },
290324074b9Spgoyette { L"-0X0.", 5, 0, 0 },
291324074b9Spgoyette { L" 0X0.", 14, 0, 0 },
292324074b9Spgoyette { L" +0X0.", 15, 0, 0 },
293324074b9Spgoyette { L" -0X0.", 15, 0, 0 },
294324074b9Spgoyette
295324074b9Spgoyette { L"0X0.0", 5, 0, 0 },
296324074b9Spgoyette { L"+0X0.0", 6, 0, 0 },
297324074b9Spgoyette { L"-0X0.0", 6, 0, 0 },
298324074b9Spgoyette { L" 0X0.0", 15, 0, 0 },
299324074b9Spgoyette { L" +0X0.0", 16, 0, 0 },
300324074b9Spgoyette { L" -0X0.0", 16, 0, 0 },
301324074b9Spgoyette
302324074b9Spgoyette { L"0X0.P", 4, 0, 0 },
303324074b9Spgoyette { L"+0X0.P", 5, 0, 0 },
304324074b9Spgoyette { L"-0X0.P", 5, 0, 0 },
305324074b9Spgoyette { L" 0X0.P", 14, 0, 0 },
306324074b9Spgoyette { L" +0X0.P", 15, 0, 0 },
307324074b9Spgoyette { L" -0X0.P", 15, 0, 0 },
308324074b9Spgoyette
309324074b9Spgoyette { L"0X0.P", 4, 0, 0 },
310324074b9Spgoyette { L"+0X0.P", 5, 0, 0 },
311324074b9Spgoyette { L"-0X0.P", 5, 0, 0 },
312324074b9Spgoyette { L" 0X0.P", 14, 0, 0 },
313324074b9Spgoyette { L" +0X0.P", 15, 0, 0 },
314324074b9Spgoyette { L" -0X0.P", 15, 0, 0 },
315324074b9Spgoyette
316324074b9Spgoyette #endif
317324074b9Spgoyette { L"0.12345678", 10, 0.12345678, 0 },
318324074b9Spgoyette { L"+0.12345678", 11, +0.12345678, 0 },
319324074b9Spgoyette { L"-0.12345678", 11, -0.12345678, 0 },
320324074b9Spgoyette { L" 0.12345678", 15, 0.12345678, 0 },
321324074b9Spgoyette { L" +0.12345678", 16, +0.12345678, 0 },
322324074b9Spgoyette { L" -0.12345678", 16, -0.12345678, 0 },
323324074b9Spgoyette
324324074b9Spgoyette { L"0.12345E67", 10, 0.12345E67, 0 },
325324074b9Spgoyette { L"+0.12345E67", 11, +0.12345E67, 0 },
326324074b9Spgoyette { L"-0.12345E67", 11, -0.12345E67, 0 },
327324074b9Spgoyette { L" 0.12345E67", 15, 0.12345E67, 0 },
328324074b9Spgoyette { L" +0.12345E67", 16, +0.12345E67, 0 },
329324074b9Spgoyette { L" -0.12345E67", 16, -0.12345E67, 0 },
330324074b9Spgoyette
331324074b9Spgoyette { L"0.12345E+6", 10, 0.12345E+6, 0 },
332324074b9Spgoyette { L"+0.12345E+6", 11, +0.12345E+6, 0 },
333324074b9Spgoyette { L"-0.12345E+6", 11, -0.12345E+6, 0 },
334324074b9Spgoyette { L" 0.12345E+6", 15, 0.12345E+6, 0 },
335324074b9Spgoyette { L" +0.12345E+6", 16, +0.12345E+6, 0 },
336324074b9Spgoyette { L" -0.12345E+6", 16, -0.12345E+6, 0 },
337324074b9Spgoyette
338324074b9Spgoyette { L"0.98765E-4", 10, 0.98765E-4, 0 },
339324074b9Spgoyette { L"+0.98765E-4", 11, +0.98765E-4, 0 },
340324074b9Spgoyette { L"-0.98765E-4", 11, -0.98765E-4, 0 },
341324074b9Spgoyette { L" 0.98765E-4", 15, 0.98765E-4, 0 },
342324074b9Spgoyette { L" +0.98765E-4", 16, +0.98765E-4, 0 },
343324074b9Spgoyette { L" -0.98765E-4", 16, -0.98765E-4, 0 },
344324074b9Spgoyette
345324074b9Spgoyette { L"12345678E9", 10, 12345678E9, 0 },
346324074b9Spgoyette { L"+12345678E9", 11, +12345678E9, 0 },
347324074b9Spgoyette { L"-12345678E9", 11, -12345678E9, 0 },
348324074b9Spgoyette { L" 12345678E9", 15, 12345678E9, 0 },
349324074b9Spgoyette { L" +12345678E9", 16, +12345678E9, 0 },
350324074b9Spgoyette { L" -12345678E9", 16, -12345678E9, 0 },
351324074b9Spgoyette
352324074b9Spgoyette /* XXX: SunOS 5.8's wcstod(3) doesn't accept hex */
353324074b9Spgoyette #if !defined(__SunOS__)
354324074b9Spgoyette { L"0x1P+2", 6, 4, 0 },
355324074b9Spgoyette { L"+0x1P+2", 7, +4, 0 },
356324074b9Spgoyette { L"-0x1P+2", 7, -4, 0 },
357324074b9Spgoyette { L" 0x1P+2", 11, 4, 0 },
358324074b9Spgoyette { L" +0x1P+2", 12, +4, 0 },
359324074b9Spgoyette { L" -0x1P+2", 12, -4, 0 },
360324074b9Spgoyette
361324074b9Spgoyette { L"0x1.0P+2", 8, 4, 0 },
362324074b9Spgoyette { L"+0x1.0P+2", 9, +4, 0 },
363324074b9Spgoyette { L"-0x1.0P+2", 9, -4, 0 },
364324074b9Spgoyette { L" 0x1.0P+2", 13, 4, 0 },
365324074b9Spgoyette { L" +0x1.0P+2", 14, +4, 0 },
366324074b9Spgoyette { L" -0x1.0P+2", 14, -4, 0 },
367324074b9Spgoyette
368324074b9Spgoyette { L"0x1P-2", 6, 0.25, 0 },
369324074b9Spgoyette { L"+0x1P-2", 7, +0.25, 0 },
370324074b9Spgoyette { L"-0x1P-2", 7, -0.25, 0 },
371324074b9Spgoyette { L" 0x1P-2", 11, 0.25, 0 },
372324074b9Spgoyette { L" +0x1P-2", 12, +0.25, 0 },
373324074b9Spgoyette { L" -0x1P-2", 12, -0.25, 0 },
374324074b9Spgoyette
375324074b9Spgoyette { L"0x1.0P-2", 8, 0.25, 0 },
376324074b9Spgoyette { L"+0x1.0P-2", 9, +0.25, 0 },
377324074b9Spgoyette { L"-0x1.0P-2", 9, -0.25, 0 },
378324074b9Spgoyette { L" 0x1.0P-2", 13, 0.25, 0 },
379324074b9Spgoyette { L" +0x1.0P-2", 14, +0.25, 0 },
380324074b9Spgoyette { L" -0x1.0P-2", 14, -0.25, 0 },
381324074b9Spgoyette #endif
382324074b9Spgoyette
383324074b9Spgoyette { NULL, 0, 0, 0 }
384324074b9Spgoyette };
3851ef7da4fSchristos #endif /* !defined(__vax__) */
386324074b9Spgoyette
387adbde1f9Sperseant
388adbde1f9Sperseant ATF_TC(wcstombs);
ATF_TC_HEAD(wcstombs,tc)389adbde1f9Sperseant ATF_TC_HEAD(wcstombs, tc)
390adbde1f9Sperseant {
391adbde1f9Sperseant atf_tc_set_md_var(tc, "descr", "Checks wcstombs(3) on the inputs to the wcstod test");
392adbde1f9Sperseant }
ATF_TC_BODY(wcstombs,tc)393adbde1f9Sperseant ATF_TC_BODY(wcstombs, tc)
394adbde1f9Sperseant {
395*3d39ee5eSjoerg #if !defined(__vax__)
396adbde1f9Sperseant struct test *t;
397adbde1f9Sperseant size_t n;
398adbde1f9Sperseant char *buf;
399adbde1f9Sperseant
400adbde1f9Sperseant /*
401adbde1f9Sperseant * Previously this was part of the wcstod test.
402adbde1f9Sperseant */
403adbde1f9Sperseant for (t = &tests[0]; t->wcs != NULL; ++t) {
404adbde1f9Sperseant printf("wcslen(\"%S\") = %zu\n", t->wcs, wcslen(t->wcs));
405adbde1f9Sperseant n = wcstombs(NULL, t->wcs, 0);
406adbde1f9Sperseant printf("wcstombs(NULL, \"%S\", 0) = %d\n", t->wcs, (int)n);
407adbde1f9Sperseant ATF_REQUIRE((buf = (void *)calloc(1, n + 1)) != NULL);
408adbde1f9Sperseant (void)wcstombs(buf, t->wcs, n + 1);
409adbde1f9Sperseant printf("wcstombs(buf, \"%S\", %d) = \"%s\"\n", t->wcs,
410adbde1f9Sperseant (int)(n + 1), buf);
411adbde1f9Sperseant ATF_REQUIRE_EQ(strlen(buf), wcslen(t->wcs));
412adbde1f9Sperseant
413adbde1f9Sperseant free(buf);
414adbde1f9Sperseant }
415*3d39ee5eSjoerg #endif
416adbde1f9Sperseant }
417adbde1f9Sperseant
418324074b9Spgoyette ATF_TC(wcstod);
ATF_TC_HEAD(wcstod,tc)419324074b9Spgoyette ATF_TC_HEAD(wcstod, tc)
420324074b9Spgoyette {
421324074b9Spgoyette atf_tc_set_md_var(tc, "descr", "Checks wcstod(3)");
422324074b9Spgoyette }
ATF_TC_BODY(wcstod,tc)423324074b9Spgoyette ATF_TC_BODY(wcstod, tc)
424324074b9Spgoyette {
4251ef7da4fSchristos #if defined(__vax__)
4261ef7da4fSchristos #else
427324074b9Spgoyette struct test *t;
4281ef7da4fSchristos #endif
429324074b9Spgoyette
4301ef7da4fSchristos #if !defined(__vax__)
431324074b9Spgoyette for (t = &tests[0]; t->wcs != NULL; ++t) {
432324074b9Spgoyette size_t n;
433adbde1f9Sperseant double d;
434324074b9Spgoyette wchar_t *tail;
435324074b9Spgoyette
436adbde1f9Sperseant (void)printf("Checking wcstod(\"%S\", &tail):\n", t->wcs);
437324074b9Spgoyette
438324074b9Spgoyette errno = 0;
439324074b9Spgoyette d = wcstod(t->wcs, &tail);
440324074b9Spgoyette (void)printf("[errno]\n");
441324074b9Spgoyette (void)printf(" got : %s\n", strerror(errno));
442324074b9Spgoyette (void)printf(" expected: %s\n", strerror(t->err));
443324074b9Spgoyette ATF_REQUIRE_EQ(errno, t->err);
444324074b9Spgoyette
445324074b9Spgoyette n = (size_t)(tail - t->wcs);
446324074b9Spgoyette (void)printf("[endptr - nptr]\n");
447324074b9Spgoyette (void)printf(" got : %zd\n", n);
448324074b9Spgoyette (void)printf(" expected: %zd\n", t->len);
449324074b9Spgoyette ATF_REQUIRE_EQ(n, t->len);
450324074b9Spgoyette
451324074b9Spgoyette (void)printf("[result]\n");
452324074b9Spgoyette (void)printf(" real: %F\n", d);
453324074b9Spgoyette if (t->val == ALT_HUGE_VAL) {
454324074b9Spgoyette (void)printf(" expected: %F\n", HUGE_VAL);
455324074b9Spgoyette ATF_REQUIRE(isinf(d));
456324074b9Spgoyette ATF_REQUIRE_EQ(d, HUGE_VAL);
457324074b9Spgoyette } else if (t->val == ALT_MINUS_HUGE_VAL) {
458324074b9Spgoyette (void)printf(" expected: %F\n", -HUGE_VAL);
459324074b9Spgoyette ATF_REQUIRE(isinf(d));
460324074b9Spgoyette ATF_REQUIRE_EQ(d, -HUGE_VAL);
461324074b9Spgoyette } else if (t->val == ALT_NAN) {
462324074b9Spgoyette (void)printf(" expected: %F\n", NAN);
463324074b9Spgoyette ATF_REQUIRE(isnan(d));
464324074b9Spgoyette } else {
465324074b9Spgoyette (void)printf(" expected: %F\n", t->val);
466324074b9Spgoyette ATF_REQUIRE_EQ(d, t->val);
467324074b9Spgoyette }
468324074b9Spgoyette
469324074b9Spgoyette (void)printf("\n");
470324074b9Spgoyette }
4711ef7da4fSchristos #else /* !defined(__vax__) */
4721ef7da4fSchristos atf_tc_skip("Test is unavailable on vax.");
4731ef7da4fSchristos #endif /* !defined(__vax__) */
474324074b9Spgoyette }
475324074b9Spgoyette
ATF_TP_ADD_TCS(tp)476324074b9Spgoyette ATF_TP_ADD_TCS(tp)
477324074b9Spgoyette {
478324074b9Spgoyette ATF_TP_ADD_TC(tp, wcstod);
479adbde1f9Sperseant ATF_TP_ADD_TC(tp, wcstombs);
480324074b9Spgoyette
481324074b9Spgoyette return atf_no_error();
482324074b9Spgoyette }
483