7 static char buffer
[500];
9 extern double_type doubles
[];
13 double_type
*pd
= doubles
;
20 /* On average we'll loose 1/2 a bit, so the test is for within 1 bit */
21 v
= strtod(pd
->string
, &tail
);
22 test_mok(v
, pd
->value
, 64);
23 test_iok(tail
- pd
->string
, pd
->endscan
);
31 /* On average we'll loose 1/2 a bit, so the test is for within 1 bit */
32 v
= strtof(pd
->string
, &tail
);
33 test_mok(v
, pd
->value
, 32);
34 test_iok(tail
- pd
->string
, pd
->endscan
);
40 test_mok(atof(pd
->string
), pd
->value
, 64);
46 test_mok(atoff(pd
->string
), pd
->value
, 32);
52 iterate (void (*func
) (void),
66 extern int_type ints
[];
72 int_iterate (void (*func
)(),
87 test_strtol_base (int base
,
94 r
= strtol(string
, &ptr
, base
);
95 test_iok(r
, pi
->value
);
96 test_eok(errno
, pi
->errno_val
);
97 test_iok(ptr
- string
, pi
->end
);
103 test_strtol_base(8,&(p
->octal
), p
->string
);
104 test_strtol_base(10,&(p
->decimal
), p
->string
);
105 test_strtol_base(16, &(p
->hex
), p
->string
);
106 test_strtol_base(0, &(p
->normal
), p
->string
);
107 test_strtol_base(26, &(p
->alphabetical
), p
->string
);
113 test_iok(atoi(p
->string
), p
->decimal
.value
);
114 test_eok(errno
, p
->decimal
.errno_val
);
120 test_iok(atol(p
->string
), p
->decimal
.value
);
121 test_eok(errno
, p
->decimal
.errno_val
);
124 /* test ECVT and friends */
125 extern ddouble_type ddoubles
[];
132 s
= ecvtbuf(pdd
->value
, pdd
->e1
, &a2
, &a3
, buffer
);
134 test_sok(s
,pdd
->estring
);
135 test_iok(pdd
->e2
,a2
);
136 test_iok(pdd
->e3
,a3
);
144 s
= ecvt(pdd
->value
, pdd
->e1
, &a2
, &a3
);
146 test_sok(s
,pdd
->estring
);
147 test_iok(pdd
->e2
,a2
);
148 test_iok(pdd
->e3
,a3
);
150 s
= ecvtf(pdd
->value
, pdd
->e1
, &a2
, &a3
);
152 test_sok(s
,pdd
->estring
);
153 test_iok(pdd
->e2
,a2
);
154 test_iok(pdd
->e3
,a3
);
162 s
= fcvtbuf(pdd
->value
, pdd
->f1
, &a2
, &a3
, buffer
);
164 test_scok(s
,pdd
->fstring
,10);
165 test_iok(pdd
->f2
,a2
);
166 test_iok(pdd
->f3
,a3
);
172 char *s
= gcvt(pdd
->value
, pdd
->g1
, buffer
);
173 test_scok(s
, pdd
->gstring
, 9);
175 s
= gcvtf(pdd
->value
, pdd
->g1
, buffer
);
176 test_scok(s
, pdd
->gstring
, 9);
188 sd
= fcvt(pdd
->value
, pdd
->f1
, &a2
, &a3
);
190 test_scok(sd
,pdd
->fstring
,10);
191 test_iok(pdd
->f2
,a2
);
192 test_iok(pdd
->f3
,a3
);
194 /* Test the float version by converting and inspecting the numbers 3
195 after reconverting */
196 sf
= fcvtf(pdd
->value
, pdd
->f1
, &a2
, &a3
);
197 sscanf(sd
, "%lg", &v1
);
198 sscanf(sf
, "%lg", &v2
);
200 test_iok(pdd
->f2
,a2
);
201 test_iok(pdd
->f3
,a3
);
206 diterate (void (*func
)(),
212 while (pdd
->estring
) {
226 sprintf(buffer
,"%.2f", 9.999);
227 test_sok(buffer
,"10.00");
229 sprintf(buffer
,"%.2g", 1.0);
230 test_sok(buffer
,"1");
232 sprintf(buffer
,"%.2g", 1.2e-6);
233 test_sok(buffer
,"1.2e-06");
235 sprintf(buffer
,"%.0g", 1.0);
236 test_sok(buffer
,"1");
238 sprintf(buffer
,"%.0e",1e1
);
239 test_sok(buffer
,"1e+01");
241 sprintf(buffer
, "%f", 12.3456789);
242 test_sok(buffer
, "12.345679");
244 sprintf(buffer
, "%6.3f", 12.3456789);
245 test_sok(buffer
, "12.346");
247 sprintf(buffer
,"%.0f", 12.3456789);
248 test_sok(buffer
,"12");
251 /* Most of what sprint does is tested with the tests of
252 fcvt/ecvt/gcvt, but here are some more */
256 extern sprint_double_type sprint_doubles
[];
257 sprint_double_type
*s
= sprint_doubles
;
258 extern sprint_int_type sprint_ints
[];
259 sprint_int_type
*si
= sprint_ints
;
268 sprintf(buffer
, s
->format_string
, s
->value
);
269 test_scok(buffer
, s
->result
, 12); /* Only check the first 12 digs,
270 other stuff is random */
277 sprintf(buffer
, si
->format_string
, si
->value
);
278 test_sok(buffer
, si
->result
);
283 /* Scanf calls strtod etc tested elsewhere, but also has some pattern matching skills */
288 extern sprint_double_type sprint_doubles
[];
289 sprint_double_type
*s
= sprint_doubles
;
290 extern sprint_int_type sprint_ints
[];
291 sprint_int_type
*si
= sprint_ints
;
295 /* Test scanf by converting all the numbers in the sprint vectors
296 to and from their source and making sure nothing breaks */
303 sscanf(s
->result
, "%lg", &d0
);
304 sprintf(buffer
, "%20.17e", d0
);
305 sscanf(buffer
, "%lg", &d1
);
310 /* And integers too */
317 sscanf(si
->result
, "%d", &d0
);
318 sprintf(buffer
, "%d", d0
);
319 sscanf(buffer
, "%d", &d1
);
324 /* And the string matching */
326 sscanf(" 9","%d", &i
);
328 sscanf("foo bar 123 zap 456","foo bar %d zap %d", &i
, &j
);
332 sscanf("magicXYZZYfoobar","magic%[XYZ]", buffer
);
333 test_sok("XYZZY", buffer
);
334 sscanf("magicXYZZYfoobar","%[^XYZ]", buffer
);
335 test_sok("magic", buffer
);
343 diterate(test_fcvtbuf
,"fcvtbuf");
344 diterate(test_fcvt
,"fcvt/fcvtf");
346 diterate(test_gcvt
,"gcvt/gcvtf");
347 diterate(test_ecvtbuf
,"ecvtbuf");
348 diterate(test_ecvt
,"ecvt/ecvtf");
350 iterate(test_strtod
, "strtod");
354 iterate(test_atof
, "atof");
355 iterate(test_atoff
, "atoff");
357 iterate(test_strtof
, "strtof");
359 int_iterate(test_atoi
,"atoi");
360 int_iterate(test_atol
,"atol");
361 int_iterate(test_strtol
, "strtol");