t_wcstod.c revision 1.3 1 1.2 christos /* $NetBSD: t_wcstod.c,v 1.3 2011/10/01 17:56:11 christos Exp $ */
2 1.1 pgoyette
3 1.1 pgoyette /*-
4 1.1 pgoyette * Copyright (c) 2011 The NetBSD Foundation, Inc.
5 1.1 pgoyette * All rights reserved.
6 1.1 pgoyette *
7 1.1 pgoyette * Redistribution and use in source and binary forms, with or without
8 1.1 pgoyette * modification, are permitted provided that the following conditions
9 1.1 pgoyette * are met:
10 1.1 pgoyette * 1. Redistributions of source code must retain the above copyright
11 1.1 pgoyette * notice, this list of conditions and the following disclaimer.
12 1.1 pgoyette * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 pgoyette * notice, this list of conditions and the following disclaimer in the
14 1.1 pgoyette * documentation and/or other materials provided with the distribution.
15 1.1 pgoyette *
16 1.1 pgoyette * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 1.1 pgoyette * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 1.1 pgoyette * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.1 pgoyette * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 1.1 pgoyette * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.1 pgoyette * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.1 pgoyette * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.1 pgoyette * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.1 pgoyette * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.1 pgoyette * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.1 pgoyette * POSSIBILITY OF SUCH DAMAGE.
27 1.1 pgoyette */
28 1.1 pgoyette
29 1.1 pgoyette /*-
30 1.1 pgoyette * Copyright (c)2005 Citrus Project,
31 1.1 pgoyette * All rights reserved.
32 1.1 pgoyette *
33 1.1 pgoyette * Redistribution and use in source and binary forms, with or without
34 1.1 pgoyette * modification, are permitted provided that the following conditions
35 1.1 pgoyette * are met:
36 1.1 pgoyette * 1. Redistributions of source code must retain the above copyright
37 1.1 pgoyette * notice, this list of conditions and the following disclaimer.
38 1.1 pgoyette * 2. Redistributions in binary form must reproduce the above copyright
39 1.1 pgoyette * notice, this list of conditions and the following disclaimer in the
40 1.1 pgoyette * documentation and/or other materials provided with the distribution.
41 1.1 pgoyette *
42 1.1 pgoyette * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
43 1.1 pgoyette * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 1.1 pgoyette * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 1.1 pgoyette * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
46 1.1 pgoyette * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 1.1 pgoyette * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48 1.1 pgoyette * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49 1.1 pgoyette * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50 1.1 pgoyette * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51 1.1 pgoyette * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52 1.1 pgoyette * SUCH DAMAGE.
53 1.1 pgoyette *
54 1.1 pgoyette */
55 1.1 pgoyette
56 1.1 pgoyette #include <sys/cdefs.h>
57 1.1 pgoyette __COPYRIGHT("@(#) Copyright (c) 2011\
58 1.1 pgoyette The NetBSD Foundation, inc. All rights reserved.");
59 1.2 christos __RCSID("$NetBSD: t_wcstod.c,v 1.3 2011/10/01 17:56:11 christos Exp $");
60 1.1 pgoyette
61 1.1 pgoyette #include <errno.h>
62 1.1 pgoyette #include <math.h>
63 1.1 pgoyette #include <stdlib.h>
64 1.1 pgoyette #include <string.h>
65 1.1 pgoyette #include <wchar.h>
66 1.1 pgoyette
67 1.1 pgoyette #include <atf-c.h>
68 1.1 pgoyette
69 1.1 pgoyette #define ALT_HUGE_VAL -1
70 1.1 pgoyette #define ALT_MINUS_HUGE_VAL -2
71 1.1 pgoyette #define ALT_NAN -3
72 1.1 pgoyette
73 1.3 christos #if !defined(__vax__)
74 1.1 pgoyette static struct test {
75 1.1 pgoyette const wchar_t *wcs;
76 1.1 pgoyette size_t len;
77 1.1 pgoyette double val;
78 1.1 pgoyette int err;
79 1.1 pgoyette } tests[] = {
80 1.1 pgoyette { L"IN", 0, 0, 0 },
81 1.1 pgoyette { L"+IN", 0, 0, 0 },
82 1.1 pgoyette { L"-IN", 0, 0, 0 },
83 1.1 pgoyette { L"INX", 0, 0, 0 },
84 1.1 pgoyette { L"+INX", 0, 0, 0 },
85 1.1 pgoyette { L"-INX", 0, 0, 0 },
86 1.1 pgoyette { L"INF", 3, ALT_HUGE_VAL, 0 },
87 1.1 pgoyette { L"+INF", 4, ALT_HUGE_VAL, 0 },
88 1.1 pgoyette { L"-INF", 4, ALT_MINUS_HUGE_VAL, 0 },
89 1.1 pgoyette { L"INFX", 3, ALT_HUGE_VAL, 0 },
90 1.1 pgoyette { L"+INFX", 4, ALT_HUGE_VAL, 0 },
91 1.1 pgoyette { L"-INFX", 4, ALT_MINUS_HUGE_VAL, 0 },
92 1.1 pgoyette { L" IN", 0, 0, 0 },
93 1.1 pgoyette { L" +IN", 0, 0, 0 },
94 1.1 pgoyette { L" -IN", 0, 0, 0 },
95 1.1 pgoyette { L" INX", 0, 0, 0 },
96 1.1 pgoyette { L" +INX", 0, 0, 0 },
97 1.1 pgoyette { L" -INX", 0, 0, 0 },
98 1.1 pgoyette { L"+ INF", 0, 0, 0 },
99 1.1 pgoyette { L"- INF", 0, 0, 0 },
100 1.1 pgoyette { L" INF", 8, ALT_HUGE_VAL, 0 },
101 1.1 pgoyette { L" +INF", 9, ALT_HUGE_VAL, 0 },
102 1.1 pgoyette { L" -INF", 9, ALT_MINUS_HUGE_VAL, 0 },
103 1.1 pgoyette { L" INFX", 8, ALT_HUGE_VAL, 0 },
104 1.1 pgoyette { L" +INFX", 9, ALT_HUGE_VAL, 0 },
105 1.1 pgoyette { L" -INFX", 9, ALT_MINUS_HUGE_VAL, 0 },
106 1.1 pgoyette { L" INFINIT", 8, ALT_HUGE_VAL, 0 },
107 1.1 pgoyette { L" +INFINIT", 9, ALT_HUGE_VAL, 0 },
108 1.1 pgoyette { L" -INFINIT", 9, ALT_MINUS_HUGE_VAL, 0 },
109 1.1 pgoyette { L" INFINITY", 13, ALT_HUGE_VAL, 0 },
110 1.1 pgoyette { L" +INFINITY", 14, ALT_HUGE_VAL, 0 },
111 1.1 pgoyette { L" -INFINITY", 14, ALT_MINUS_HUGE_VAL, 0 },
112 1.1 pgoyette { L" INFINITYX", 13, ALT_HUGE_VAL, 0 },
113 1.1 pgoyette { L" +INFINITYX", 14, ALT_HUGE_VAL, 0 },
114 1.1 pgoyette { L" -INFINITYX", 14, ALT_MINUS_HUGE_VAL, 0 },
115 1.1 pgoyette
116 1.1 pgoyette /* NAN */
117 1.1 pgoyette { L"NA", 0, 0, 0 },
118 1.1 pgoyette { L"+NA", 0, 0, 0 },
119 1.1 pgoyette { L"-NA", 0, 0, 0 },
120 1.1 pgoyette { L"NAX", 0, 0, 0 },
121 1.1 pgoyette { L"+NAX", 0, 0, 0 },
122 1.1 pgoyette { L"-NAX", 0, 0, 0 },
123 1.1 pgoyette { L"NAN", 3, ALT_NAN, 0 },
124 1.1 pgoyette { L"+NAN", 4, ALT_NAN, 0 },
125 1.1 pgoyette { L"-NAN", 4, ALT_NAN, 0 },
126 1.1 pgoyette { L"NANX", 3, ALT_NAN, 0 },
127 1.1 pgoyette { L"+NANX", 4, ALT_NAN, 0 },
128 1.1 pgoyette { L"-NANX", 4, ALT_NAN, 0 },
129 1.1 pgoyette { L" NA", 0, 0, 0 },
130 1.1 pgoyette { L" +NA", 0, 0, 0 },
131 1.1 pgoyette { L" -NA", 0, 0, 0 },
132 1.1 pgoyette { L" NAX", 0, 0, 0 },
133 1.1 pgoyette { L" +NAX", 0, 0, 0 },
134 1.1 pgoyette { L" -NAX", 0, 0, 0 },
135 1.1 pgoyette { L"+ NAN", 0, 0, 0 },
136 1.1 pgoyette { L"- NAN", 0, 0, 0 },
137 1.1 pgoyette { L" NAN", 8, ALT_NAN, 0 },
138 1.1 pgoyette { L" +NAN", 9, ALT_NAN, 0 },
139 1.1 pgoyette { L" -NAN", 9, ALT_NAN, 0 },
140 1.1 pgoyette { L" NANX", 8, ALT_NAN, 0 },
141 1.1 pgoyette { L" +NANX", 9, ALT_NAN, 0 },
142 1.1 pgoyette { L" -NANX", 9, ALT_NAN, 0 },
143 1.1 pgoyette
144 1.1 pgoyette { L"0", 1, 0, 0 },
145 1.1 pgoyette { L"+0", 2, 0, 0 },
146 1.1 pgoyette { L"-0", 2, 0, 0 },
147 1.1 pgoyette { L" 0", 11, 0, 0 },
148 1.1 pgoyette { L" +0", 12, 0, 0 },
149 1.1 pgoyette { L" -0", 12, 0, 0 },
150 1.1 pgoyette { L"+ 0", 0, 0, 0 },
151 1.1 pgoyette { L"- 0", 0, 0, 0 },
152 1.1 pgoyette
153 1.1 pgoyette { L".", 0, 0, 0 },
154 1.1 pgoyette { L".0", 2, 0, 0 },
155 1.1 pgoyette { L".00", 3, 0, 0 },
156 1.1 pgoyette { L".000", 4, 0, 0 },
157 1.1 pgoyette
158 1.1 pgoyette { L"0.", 2, 0, 0 },
159 1.1 pgoyette { L"+0.", 3, 0, 0 },
160 1.1 pgoyette { L"-0.", 3, 0, 0 },
161 1.1 pgoyette { L" 0.", 12, 0, 0 },
162 1.1 pgoyette { L" +0.", 13, 0, 0 },
163 1.1 pgoyette { L" -0.", 13, 0, 0 },
164 1.1 pgoyette
165 1.1 pgoyette { L"0.0", 3, 0, 0 },
166 1.1 pgoyette { L"+0.0", 4, 0, 0 },
167 1.1 pgoyette { L"-0.0", 4, 0, 0 },
168 1.1 pgoyette { L" 0.0", 13, 0, 0 },
169 1.1 pgoyette { L" +0.0", 14, 0, 0 },
170 1.1 pgoyette { L" -0.0", 14, 0, 0 },
171 1.1 pgoyette
172 1.1 pgoyette { L"000", 3, 0, 0 },
173 1.1 pgoyette { L"+000", 4, 0, 0 },
174 1.1 pgoyette { L"-000", 4, 0, 0 },
175 1.1 pgoyette { L" 000", 13, 0, 0 },
176 1.1 pgoyette { L" +000", 14, 0, 0 },
177 1.1 pgoyette { L" -000", 14, 0, 0 },
178 1.1 pgoyette
179 1.1 pgoyette { L"000.", 4, 0, 0 },
180 1.1 pgoyette { L"+000.", 5, 0, 0 },
181 1.1 pgoyette { L"-000.", 5, 0, 0 },
182 1.1 pgoyette { L" 000.", 14, 0, 0 },
183 1.1 pgoyette { L" +000.", 15, 0, 0 },
184 1.1 pgoyette { L" -000.", 15, 0, 0 },
185 1.1 pgoyette
186 1.1 pgoyette { L"000.0", 5, 0, 0 },
187 1.1 pgoyette { L"+000.0", 6, 0, 0 },
188 1.1 pgoyette { L"-000.0", 6, 0, 0 },
189 1.1 pgoyette { L" 000.0", 15, 0, 0 },
190 1.1 pgoyette { L" +000.0", 16, 0, 0 },
191 1.1 pgoyette { L" -000.0", 16, 0, 0 },
192 1.1 pgoyette
193 1.1 pgoyette
194 1.1 pgoyette { L"0.0.", 3, 0, 0 },
195 1.1 pgoyette { L"+0.0.", 4, 0, 0 },
196 1.1 pgoyette { L"-0.0.", 4, 0, 0 },
197 1.1 pgoyette { L" 0.0.", 13, 0, 0 },
198 1.1 pgoyette { L" +0.0.", 14, 0, 0 },
199 1.1 pgoyette { L" -0.0.", 14, 0, 0 },
200 1.1 pgoyette
201 1.1 pgoyette { L"0.0.0", 3, 0, 0 },
202 1.1 pgoyette { L"+0.0.0", 4, 0, 0 },
203 1.1 pgoyette { L"-0.0.0", 4, 0, 0 },
204 1.1 pgoyette { L" 0.0.0", 13, 0, 0 },
205 1.1 pgoyette { L" +0.0.0", 14, 0, 0 },
206 1.1 pgoyette { L" -0.0.0", 14, 0, 0 },
207 1.1 pgoyette
208 1.1 pgoyette /* XXX: FIXME */
209 1.1 pgoyette #if defined(__linux__)
210 1.1 pgoyette { L"0X", 2, 0, 0 },
211 1.1 pgoyette { L"+0X", 3, 0, 0 },
212 1.1 pgoyette { L"-0X", 3, 0, 0 },
213 1.1 pgoyette #else
214 1.1 pgoyette { L"0X", 1, 0, 0 },
215 1.1 pgoyette { L"+0X", 2, 0, 0 },
216 1.1 pgoyette { L"-0X", 2, 0, 0 },
217 1.1 pgoyette #endif
218 1.1 pgoyette
219 1.1 pgoyette /* XXX: SunOS 5.8's wcstod(3) doesn't accept hex */
220 1.1 pgoyette #if !defined(__SunOS__)
221 1.1 pgoyette #if defined(__linux__)
222 1.1 pgoyette { L"0X.", 3, 0, 0 },
223 1.1 pgoyette { L"+0X.", 4, 0, 0 },
224 1.1 pgoyette { L"-0X.", 4, 0, 0 },
225 1.1 pgoyette { L" 0X.", 13, 0, 0 },
226 1.1 pgoyette { L" +0X.", 14, 0, 0 },
227 1.1 pgoyette { L" -0X.", 14, 0, 0 },
228 1.1 pgoyette #else
229 1.1 pgoyette { L"0X.", 1, 0, 0 },
230 1.1 pgoyette { L"+0X.", 2, 0, 0 },
231 1.1 pgoyette { L"-0X.", 2, 0, 0 },
232 1.1 pgoyette { L" 0X.", 11, 0, 0 },
233 1.1 pgoyette { L" +0X.", 12, 0, 0 },
234 1.1 pgoyette { L" -0X.", 12, 0, 0 },
235 1.1 pgoyette #endif
236 1.1 pgoyette /* XXX: FIXME */
237 1.1 pgoyette #if defined(__NetBSD__) || defined(__linux__)
238 1.1 pgoyette { L"0X.0", 4, 0, 0 },
239 1.1 pgoyette { L"+0X.0", 5, 0, 0 },
240 1.1 pgoyette { L"-0X.0", 5, 0, 0 },
241 1.1 pgoyette { L" 0X.0", 14, 0, 0 },
242 1.1 pgoyette { L" +0X.0", 15, 0, 0 },
243 1.1 pgoyette { L" -0X.0", 15, 0, 0 },
244 1.1 pgoyette
245 1.1 pgoyette { L"0X.0P", 4, 0, 0 },
246 1.1 pgoyette { L"+0X.0P", 5, 0, 0 },
247 1.1 pgoyette { L"-0X.0P", 5, 0, 0 },
248 1.1 pgoyette { L" 0X.0P", 14, 0, 0 },
249 1.1 pgoyette { L" +0X.0P", 15, 0, 0 },
250 1.1 pgoyette { L" -0X.0P", 15, 0, 0 },
251 1.1 pgoyette #else
252 1.1 pgoyette { L"0X.0", 1, 0, 0 },
253 1.1 pgoyette { L"+0X.0", 2, 0, 0 },
254 1.1 pgoyette { L"-0X.0", 2, 0, 0 },
255 1.1 pgoyette { L" 0X.0", 11, 0, 0 },
256 1.1 pgoyette { L" +0X.0", 12, 0, 0 },
257 1.1 pgoyette { L" -0X.0", 12, 0, 0 },
258 1.1 pgoyette
259 1.1 pgoyette { L"0X.0P", 1, 0, 0 },
260 1.1 pgoyette { L"+0X.0P", 2, 0, 0 },
261 1.1 pgoyette { L"-0X.0P", 2, 0, 0 },
262 1.1 pgoyette { L" 0X.0P", 11, 0, 0 },
263 1.1 pgoyette { L" +0X.0P", 12, 0, 0 },
264 1.1 pgoyette { L" -0X.0P", 12, 0, 0 },
265 1.1 pgoyette #endif
266 1.1 pgoyette
267 1.1 pgoyette { L"0X0", 3, 0, 0 },
268 1.1 pgoyette { L"+0X0", 4, 0, 0 },
269 1.1 pgoyette { L"-0X0", 4, 0, 0 },
270 1.1 pgoyette { L" 0X0", 13, 0, 0 },
271 1.1 pgoyette { L" +0X0", 14, 0, 0 },
272 1.1 pgoyette { L" -0X0", 14, 0, 0 },
273 1.1 pgoyette
274 1.1 pgoyette { L"00X0.0", 2, 0, 0 },
275 1.1 pgoyette { L"+00X0.0", 3, 0, 0 },
276 1.1 pgoyette { L"-00X0.0", 3, 0, 0 },
277 1.1 pgoyette { L" 00X0.0", 12, 0, 0 },
278 1.1 pgoyette { L" +00X0.0", 13, 0, 0 },
279 1.1 pgoyette { L" -00X0.0", 13, 0, 0 },
280 1.1 pgoyette
281 1.1 pgoyette { L"0X0P", 3, 0, 0 },
282 1.1 pgoyette { L"+0X0P", 4, 0, 0 },
283 1.1 pgoyette { L"-0X0P", 4, 0, 0 },
284 1.1 pgoyette { L" 0X0P", 13, 0, 0 },
285 1.1 pgoyette { L" +0X0P", 14, 0, 0 },
286 1.1 pgoyette { L" -0X0P", 14, 0, 0 },
287 1.1 pgoyette
288 1.1 pgoyette { L"0X0.", 4, 0, 0 },
289 1.1 pgoyette { L"+0X0.", 5, 0, 0 },
290 1.1 pgoyette { L"-0X0.", 5, 0, 0 },
291 1.1 pgoyette { L" 0X0.", 14, 0, 0 },
292 1.1 pgoyette { L" +0X0.", 15, 0, 0 },
293 1.1 pgoyette { L" -0X0.", 15, 0, 0 },
294 1.1 pgoyette
295 1.1 pgoyette { L"0X0.0", 5, 0, 0 },
296 1.1 pgoyette { L"+0X0.0", 6, 0, 0 },
297 1.1 pgoyette { L"-0X0.0", 6, 0, 0 },
298 1.1 pgoyette { L" 0X0.0", 15, 0, 0 },
299 1.1 pgoyette { L" +0X0.0", 16, 0, 0 },
300 1.1 pgoyette { L" -0X0.0", 16, 0, 0 },
301 1.1 pgoyette
302 1.1 pgoyette { L"0X0.P", 4, 0, 0 },
303 1.1 pgoyette { L"+0X0.P", 5, 0, 0 },
304 1.1 pgoyette { L"-0X0.P", 5, 0, 0 },
305 1.1 pgoyette { L" 0X0.P", 14, 0, 0 },
306 1.1 pgoyette { L" +0X0.P", 15, 0, 0 },
307 1.1 pgoyette { L" -0X0.P", 15, 0, 0 },
308 1.1 pgoyette
309 1.1 pgoyette { L"0X0.P", 4, 0, 0 },
310 1.1 pgoyette { L"+0X0.P", 5, 0, 0 },
311 1.1 pgoyette { L"-0X0.P", 5, 0, 0 },
312 1.1 pgoyette { L" 0X0.P", 14, 0, 0 },
313 1.1 pgoyette { L" +0X0.P", 15, 0, 0 },
314 1.1 pgoyette { L" -0X0.P", 15, 0, 0 },
315 1.1 pgoyette
316 1.1 pgoyette #endif
317 1.1 pgoyette { L"0.12345678", 10, 0.12345678, 0 },
318 1.1 pgoyette { L"+0.12345678", 11, +0.12345678, 0 },
319 1.1 pgoyette { L"-0.12345678", 11, -0.12345678, 0 },
320 1.1 pgoyette { L" 0.12345678", 15, 0.12345678, 0 },
321 1.1 pgoyette { L" +0.12345678", 16, +0.12345678, 0 },
322 1.1 pgoyette { L" -0.12345678", 16, -0.12345678, 0 },
323 1.1 pgoyette
324 1.1 pgoyette { L"0.12345E67", 10, 0.12345E67, 0 },
325 1.1 pgoyette { L"+0.12345E67", 11, +0.12345E67, 0 },
326 1.1 pgoyette { L"-0.12345E67", 11, -0.12345E67, 0 },
327 1.1 pgoyette { L" 0.12345E67", 15, 0.12345E67, 0 },
328 1.1 pgoyette { L" +0.12345E67", 16, +0.12345E67, 0 },
329 1.1 pgoyette { L" -0.12345E67", 16, -0.12345E67, 0 },
330 1.1 pgoyette
331 1.1 pgoyette { L"0.12345E+6", 10, 0.12345E+6, 0 },
332 1.1 pgoyette { L"+0.12345E+6", 11, +0.12345E+6, 0 },
333 1.1 pgoyette { L"-0.12345E+6", 11, -0.12345E+6, 0 },
334 1.1 pgoyette { L" 0.12345E+6", 15, 0.12345E+6, 0 },
335 1.1 pgoyette { L" +0.12345E+6", 16, +0.12345E+6, 0 },
336 1.1 pgoyette { L" -0.12345E+6", 16, -0.12345E+6, 0 },
337 1.1 pgoyette
338 1.1 pgoyette { L"0.98765E-4", 10, 0.98765E-4, 0 },
339 1.1 pgoyette { L"+0.98765E-4", 11, +0.98765E-4, 0 },
340 1.1 pgoyette { L"-0.98765E-4", 11, -0.98765E-4, 0 },
341 1.1 pgoyette { L" 0.98765E-4", 15, 0.98765E-4, 0 },
342 1.1 pgoyette { L" +0.98765E-4", 16, +0.98765E-4, 0 },
343 1.1 pgoyette { L" -0.98765E-4", 16, -0.98765E-4, 0 },
344 1.1 pgoyette
345 1.1 pgoyette { L"12345678E9", 10, 12345678E9, 0 },
346 1.1 pgoyette { L"+12345678E9", 11, +12345678E9, 0 },
347 1.1 pgoyette { L"-12345678E9", 11, -12345678E9, 0 },
348 1.1 pgoyette { L" 12345678E9", 15, 12345678E9, 0 },
349 1.1 pgoyette { L" +12345678E9", 16, +12345678E9, 0 },
350 1.1 pgoyette { L" -12345678E9", 16, -12345678E9, 0 },
351 1.1 pgoyette
352 1.1 pgoyette /* XXX: SunOS 5.8's wcstod(3) doesn't accept hex */
353 1.1 pgoyette #if !defined(__SunOS__)
354 1.1 pgoyette { L"0x1P+2", 6, 4, 0 },
355 1.1 pgoyette { L"+0x1P+2", 7, +4, 0 },
356 1.1 pgoyette { L"-0x1P+2", 7, -4, 0 },
357 1.1 pgoyette { L" 0x1P+2", 11, 4, 0 },
358 1.1 pgoyette { L" +0x1P+2", 12, +4, 0 },
359 1.1 pgoyette { L" -0x1P+2", 12, -4, 0 },
360 1.1 pgoyette
361 1.1 pgoyette { L"0x1.0P+2", 8, 4, 0 },
362 1.1 pgoyette { L"+0x1.0P+2", 9, +4, 0 },
363 1.1 pgoyette { L"-0x1.0P+2", 9, -4, 0 },
364 1.1 pgoyette { L" 0x1.0P+2", 13, 4, 0 },
365 1.1 pgoyette { L" +0x1.0P+2", 14, +4, 0 },
366 1.1 pgoyette { L" -0x1.0P+2", 14, -4, 0 },
367 1.1 pgoyette
368 1.1 pgoyette { L"0x1P-2", 6, 0.25, 0 },
369 1.1 pgoyette { L"+0x1P-2", 7, +0.25, 0 },
370 1.1 pgoyette { L"-0x1P-2", 7, -0.25, 0 },
371 1.1 pgoyette { L" 0x1P-2", 11, 0.25, 0 },
372 1.1 pgoyette { L" +0x1P-2", 12, +0.25, 0 },
373 1.1 pgoyette { L" -0x1P-2", 12, -0.25, 0 },
374 1.1 pgoyette
375 1.1 pgoyette { L"0x1.0P-2", 8, 0.25, 0 },
376 1.1 pgoyette { L"+0x1.0P-2", 9, +0.25, 0 },
377 1.1 pgoyette { L"-0x1.0P-2", 9, -0.25, 0 },
378 1.1 pgoyette { L" 0x1.0P-2", 13, 0.25, 0 },
379 1.1 pgoyette { L" +0x1.0P-2", 14, +0.25, 0 },
380 1.1 pgoyette { L" -0x1.0P-2", 14, -0.25, 0 },
381 1.1 pgoyette #endif
382 1.1 pgoyette
383 1.1 pgoyette { NULL, 0, 0, 0 }
384 1.1 pgoyette };
385 1.3 christos #endif /* !defined(__vax__) */
386 1.1 pgoyette
387 1.1 pgoyette ATF_TC(wcstod);
388 1.1 pgoyette ATF_TC_HEAD(wcstod, tc)
389 1.1 pgoyette {
390 1.1 pgoyette atf_tc_set_md_var(tc, "descr", "Checks wcstod(3)");
391 1.1 pgoyette }
392 1.1 pgoyette ATF_TC_BODY(wcstod, tc)
393 1.1 pgoyette {
394 1.3 christos #if defined(__vax__)
395 1.3 christos #else
396 1.1 pgoyette struct test *t;
397 1.3 christos #endif
398 1.1 pgoyette
399 1.3 christos #if !defined(__vax__)
400 1.1 pgoyette for (t = &tests[0]; t->wcs != NULL; ++t) {
401 1.1 pgoyette double d;
402 1.1 pgoyette size_t n;
403 1.1 pgoyette wchar_t *tail;
404 1.1 pgoyette char *buf;
405 1.1 pgoyette
406 1.1 pgoyette /* we do not supported %ls nor %S yet. */
407 1.1 pgoyette n = wcstombs(NULL, t->wcs, 0);
408 1.1 pgoyette ATF_REQUIRE((buf = (void *)malloc(n + 1)) != NULL);
409 1.1 pgoyette (void)wcstombs(buf, t->wcs, n + 1);
410 1.1 pgoyette (void)printf("Checking wcstod(\"%s\", &tail):\n", buf);
411 1.1 pgoyette free(buf);
412 1.1 pgoyette
413 1.1 pgoyette errno = 0;
414 1.1 pgoyette d = wcstod(t->wcs, &tail);
415 1.1 pgoyette (void)printf("[errno]\n");
416 1.1 pgoyette (void)printf(" got : %s\n", strerror(errno));
417 1.1 pgoyette (void)printf(" expected: %s\n", strerror(t->err));
418 1.1 pgoyette ATF_REQUIRE_EQ(errno, t->err);
419 1.1 pgoyette
420 1.1 pgoyette n = (size_t)(tail - t->wcs);
421 1.1 pgoyette (void)printf("[endptr - nptr]\n");
422 1.1 pgoyette (void)printf(" got : %zd\n", n);
423 1.1 pgoyette (void)printf(" expected: %zd\n", t->len);
424 1.1 pgoyette ATF_REQUIRE_EQ(n, t->len);
425 1.1 pgoyette
426 1.1 pgoyette (void)printf("[result]\n");
427 1.1 pgoyette (void)printf(" real: %F\n", d);
428 1.1 pgoyette if (t->val == ALT_HUGE_VAL) {
429 1.1 pgoyette (void)printf(" expected: %F\n", HUGE_VAL);
430 1.1 pgoyette ATF_REQUIRE(isinf(d));
431 1.1 pgoyette ATF_REQUIRE_EQ(d, HUGE_VAL);
432 1.1 pgoyette } else if (t->val == ALT_MINUS_HUGE_VAL) {
433 1.1 pgoyette (void)printf(" expected: %F\n", -HUGE_VAL);
434 1.1 pgoyette ATF_REQUIRE(isinf(d));
435 1.1 pgoyette ATF_REQUIRE_EQ(d, -HUGE_VAL);
436 1.1 pgoyette } else if (t->val == ALT_NAN) {
437 1.1 pgoyette (void)printf(" expected: %F\n", NAN);
438 1.1 pgoyette ATF_REQUIRE(isnan(d));
439 1.1 pgoyette } else {
440 1.1 pgoyette (void)printf(" expected: %F\n", t->val);
441 1.1 pgoyette ATF_REQUIRE_EQ(d, t->val);
442 1.1 pgoyette }
443 1.1 pgoyette
444 1.1 pgoyette (void)printf("\n");
445 1.1 pgoyette }
446 1.3 christos #else /* !defined(__vax__) */
447 1.3 christos atf_tc_skip("Test is unavailable on vax.");
448 1.3 christos #endif /* !defined(__vax__) */
449 1.1 pgoyette }
450 1.1 pgoyette
451 1.1 pgoyette ATF_TP_ADD_TCS(tp)
452 1.1 pgoyette {
453 1.1 pgoyette ATF_TP_ADD_TC(tp, wcstod);
454 1.1 pgoyette
455 1.1 pgoyette return atf_no_error();
456 1.1 pgoyette }
457