]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/language/c/libc/stdio/v2_0/tests/sprintf1.c
Initial revision
[karo-tx-redboot.git] / packages / language / c / libc / stdio / v2_0 / tests / sprintf1.c
1 //=================================================================
2 //
3 //        sprintf1.c
4 //
5 //        Testcase for C library sprintf()
6 //
7 //=================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12 //
13 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version.
16 //
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20 // for more details.
21 //
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25 //
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
32 //
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
35 //
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37 // at http://sources.redhat.com/ecos/ecos-license/
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
40 //=================================================================
41 //#####DESCRIPTIONBEGIN####
42 //
43 // Author(s):     ctarpy, jlarmour
44 // Contributors:  
45 // Date:          2000-04-20
46 // Description:   Contains testcode for C library sprintf() function
47 //
48 //
49 //####DESCRIPTIONEND####
50
51
52 // CONFIGURATION
53
54 #include <pkgconf/libc_stdio.h>   // Configuration header
55
56
57 // INCLUDES
58
59 #include <stdio.h>
60 #include <cyg/infra/testcase.h>
61
62 // FUNCTIONS
63
64 // Functions to avoid having to use libc strings
65
66 static int my_strlen(const char *s)
67 {
68     const char *ptr;
69
70     ptr = s;
71     for ( ptr=s ; *ptr != '\0' ; ptr++ )
72         ;
73
74     return (int)(ptr-s);
75 } // my_strlen()
76
77
78 static int my_strcmp(const char *s1, const char *s2)
79 {
80     for ( ; *s1 == *s2 ; s1++,s2++ )
81     {
82         if ( *s1 == '\0' )
83             break;
84     } // for
85
86     return (*s1 - *s2);
87 } // my_strcmp()
88
89
90 static char *my_strcpy(char *s1, const char *s2)
91 {
92     while (*s2 != '\0') {
93         *(s1++) = *(s2++);
94     }
95     *s1 = '\0';
96
97     return s1; 
98 } // my_strcpy()
99
100
101
102 static void test(CYG_ADDRWORD data)
103 {
104     static char x[500];
105     static char y[500];
106     int ret;
107     int tmp;
108     int *ptr;
109
110
111     // Check 1
112     ret = sprintf(x, "%d", 20);
113     CYG_TEST_PASS_FAIL(my_strcmp(x, "20")==0, "%d test");
114     CYG_TEST_PASS_FAIL(ret==my_strlen(x), "%d test return code");
115
116     // Check 2
117     my_strcpy(y, "Pigs noses. Get 'em while there 'ot");
118     ret = sprintf(x, "%s", y);
119     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%s test");
120     CYG_TEST_PASS_FAIL(ret==my_strlen(x), "%s test return code");
121
122     // Check 3
123     ret = sprintf(x, "||%7d||", 2378);
124     CYG_TEST_PASS_FAIL(my_strcmp(x, "||   2378||")==0, "padding test");
125     CYG_TEST_PASS_FAIL(ret==my_strlen(x), "padding test return code");
126
127     // Check 4
128     ret = sprintf(x, "%x", 3573);
129     CYG_TEST_PASS_FAIL(my_strcmp(x, "df5")==0, "hex conversion (lowercase)");
130     CYG_TEST_PASS_FAIL(ret==my_strlen(x), "hex conv (lowercase) return code");
131
132     // Check 5
133     ret = sprintf(x, "%X", 3573);
134     CYG_TEST_PASS_FAIL(my_strcmp(x, "DF5")==0, "hex conversion (uppercase)");
135     CYG_TEST_PASS_FAIL(ret==my_strlen(x), "hex conv (upperbase ) return code");
136
137     // Check 6
138     ret = sprintf(x, "%c", 65);
139     CYG_TEST_PASS_FAIL(my_strcmp(x, "A")==0, "%c test");
140     CYG_TEST_PASS_FAIL(ret==my_strlen(x), "%c test return code");
141
142     // Check 7
143     ret = sprintf(x, "%o",4628);
144     CYG_TEST_PASS_FAIL(my_strcmp(x, "11024")==0, "octal conversion");
145     CYG_TEST_PASS_FAIL(ret==my_strlen(x), "octal conversion return code");
146
147     // Check 8
148     ret = sprintf(x, "%u", (unsigned int) 4738);
149     CYG_TEST_PASS_FAIL(my_strcmp(x, "4738")==0, "%u test");
150     CYG_TEST_PASS_FAIL(ret==my_strlen(x), "%u test return code");
151
152     // Check 9
153     ptr = &tmp;
154     ret = sprintf(x, "1234567x%n||", ptr);
155     CYG_TEST_PASS_FAIL(tmp==8, "%n test");
156     CYG_TEST_PASS_FAIL(ret==10, "%n test return code");
157
158     // Check 10
159     ret = sprintf(x, "%%");
160     CYG_TEST_PASS_FAIL(my_strcmp(x, "%")==0, "%% test");
161     CYG_TEST_PASS_FAIL(ret==my_strlen(x), "%% test return code");
162
163     // Check 11
164     ret = sprintf(x, "%ld", (long)1<<30);
165     CYG_TEST_PASS_FAIL(my_strcmp(x, "1073741824")==0, "%ld test");
166     CYG_TEST_PASS_FAIL(ret==my_strlen(x), "%ld test return code");
167
168     // Check 12
169     ret = sprintf(x, "%lu", (unsigned long)(1<<31) + 100);
170     CYG_TEST_PASS_FAIL(my_strcmp(x, "2147483748")==0, "%lu test");
171     CYG_TEST_PASS_FAIL(ret==my_strlen(x), "%lu test return code");
172
173     // Check 13
174     ret = sprintf(x, "%x", 0x789a);
175     CYG_TEST_PASS_FAIL(my_strcmp(x, "789a")==0, "%x test");
176     CYG_TEST_PASS_FAIL(ret==my_strlen(x), "%x test return code");
177
178     // Check 14
179     ret = sprintf(x, "%X", 0x789ab2);
180     CYG_TEST_PASS_FAIL(my_strcmp(x, "789AB2")==0, "%X test");
181     CYG_TEST_PASS_FAIL(ret==my_strlen(x), "%x test return code");
182
183     // Check 15
184     ret = sprintf(x, "%08x", 0xdea2f2);
185     CYG_TEST_PASS_FAIL(my_strcmp(x, "00dea2f2")==0, "%0x test");
186     CYG_TEST_PASS_FAIL(ret==my_strlen(x), "%0x test return code");
187
188     // Check 16
189     ret = sprintf(x, "%09X", 0x12fa1c);
190     CYG_TEST_PASS_FAIL(my_strcmp(x, "00012FA1C")==0, "%0X test");
191     CYG_TEST_PASS_FAIL(ret==my_strlen(x), "%0X test return code");
192
193     // Check 17
194     ptr=&tmp;
195     ret = sprintf(x, "%p", (void *)ptr);
196     // just check _something_ was returned
197     CYG_TEST_PASS_FAIL((ret==my_strlen(x)) && (ret > 0),
198                        "%p test return code");
199
200 #ifdef CYGSEM_LIBC_STDIO_PRINTF_FLOATING_POINT
201
202     CYG_TEST_INFO("Starting floating point specific tests");
203
204     // Check 18
205     ret = sprintf(x, "%f", 2.5);
206     my_strcpy( y, "2.500000" );
207     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "simple %f test #1");
208     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "simple %f test #1 return code");
209
210     // Check 19
211     ret = sprintf(x, "hello %f world", 1.234);
212     my_strcpy( y, "hello 1.234000 world");
213     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "simple %f test #2");
214     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "simple %f test #2 return code");
215
216     // Check 20
217     ret = sprintf(x, "hello%fworld", 2.3456781);
218     my_strcpy( y, "hello2.345678world");
219     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "simple %f test #3");
220     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "simple %f test #3 return code");
221
222     // Check 21
223     ret = sprintf(x, "%s%f%d%s", "testing", -0.591, 3, "123");
224     my_strcpy( y, "testing-0.5910003123");
225     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%f mixed with others");
226     CYG_TEST_PASS_FAIL(ret == my_strlen(y),"%f mixed with others return code");
227
228     // Check 22
229     ret = sprintf(x, "%s%f%d%s", "testing", -0.591, 3, "123");
230     my_strcpy( y, "testing-0.5910003123");
231     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%f mixed with others");
232     CYG_TEST_PASS_FAIL(ret == my_strlen(y),"%f mixed with others return code");
233
234     // Check 23
235     ret = sprintf(x, "hello%fworld", 2.3456786);
236     my_strcpy( y, "hello2.345679world");
237     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "rounding test #1");
238     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "rounding test #1 return code");
239
240     // Check 24
241     ret = sprintf(x, "hello%fworld", -2.3456786);
242     my_strcpy( y, "hello-2.345679world");
243     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "rounding test #2");
244     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "rounding test #2 return code");
245
246     // Check 25
247     ret = sprintf(x, "hello%+fworld", -6.54321);
248     my_strcpy( y, "hello-6.543210world");
249     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "+ modifier #1");
250     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "+ modifier #1 return code");
251
252     // Check 26
253     ret = sprintf(x, "hello%+fworld", 6.54321);
254     my_strcpy( y, "hello+6.543210world");
255     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "+ modifier #2");
256     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "+ modifier #2 return code");
257
258     // Check 27
259     ret = sprintf(x, "hello%5fworld", 6.5);
260     my_strcpy( y, "hello6.500000world");
261     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "width modifier #1");
262     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "width modifier #1 return code");
263
264     // Check 28
265     ret = sprintf(x, "hello%2fworld", 4.3);
266     my_strcpy( y, "hello4.300000world");
267     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "width modifier #2");
268     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "width modifier #2 return code");
269
270     // Check 29
271     ret = sprintf(x, "hello%2.1fworld", 5.6);
272     my_strcpy( y, "hello5.6world");
273     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "width and precision modifier #1");
274     CYG_TEST_PASS_FAIL(ret == my_strlen(y),
275                        "width and precision modifier #1 return code");
276
277     // Check 30
278     ret = sprintf(x, "hello%5.1fworld", 6.7);
279     my_strcpy( y, "hello  6.7world");
280     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "width and precision modifier #2");
281     CYG_TEST_PASS_FAIL(ret == my_strlen(y),
282                        "width and precision modifier #2 return code");
283
284     // Check 31
285     ret = sprintf(x, "hello%3.1fworld", 7.8);
286     my_strcpy( y, "hello7.8world");
287     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "width and precision modifier #3");
288     CYG_TEST_PASS_FAIL(ret == my_strlen(y),
289                        "width and precision modifier #3 return code");
290
291     // Check 32
292     ret = sprintf(x, "hello%3.2fworld", 7.8);
293     my_strcpy( y, "hello7.80world");
294     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "width and precision modifier #4");
295     CYG_TEST_PASS_FAIL(ret == my_strlen(y),
296                        "width and precision modifier #4 return code");
297
298     // Check 33
299     ret = sprintf(x, "hello%05.1fworld", 6.5);
300     my_strcpy( y, "hello006.5world");
301     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "0 modifier #1");
302     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "0 modifier #1 return code");
303
304     // Check 34
305     ret = sprintf(x, "hello%03.0fworld", 6.2);
306     my_strcpy( y, "hello006world");
307     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "0 modifier #2");
308     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "0 modifier #2 return code");
309
310     // Check 35
311     ret = sprintf(x, "hello%05.*fworld",2, 7.5);
312     my_strcpy( y, "hello07.50world");
313     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "0 modifier plus *");
314     CYG_TEST_PASS_FAIL(ret == my_strlen(y),
315                        "0 modifier plus * return code");
316
317     // Check 36
318     ret = sprintf(x, "hello%03.1fworld",-1.232);
319     my_strcpy( y, "hello-1.2world");
320     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "-ve number with 0 modifier #1");
321     CYG_TEST_PASS_FAIL(ret == my_strlen(y),
322                        "-ve number with 0 modifier #1 return code");
323
324     // Check 37
325     ret = sprintf(x, "hello%04.1fworld",-1.232);
326     my_strcpy( y, "hello-1.2world");
327     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "-ve number with 0 modifier #2");
328     CYG_TEST_PASS_FAIL(ret == my_strlen(y),
329                        "-ve number with 0 modifier #2 return code");
330
331     // Check 38
332     ret = sprintf(x, "hello%05.1fworld",-1.232);
333     my_strcpy( y, "hello-01.2world");
334     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "-ve number with 0 modifier #3");
335     CYG_TEST_PASS_FAIL(ret == my_strlen(y),
336                        "-ve number with 0 modifier #3 return code");
337
338     // Check 39
339     ret = sprintf(x, "hello%fworld",0.0);
340     my_strcpy( y, "hello0.000000world");
341     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "0.0 test #1");
342     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "0.0 test #1 return code");
343
344     // Check 40
345     ret = sprintf(x, "hello%1.0fworld",0.0);
346     my_strcpy( y, "hello0world");
347     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "0.0 test #2");
348     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "0.0 test #2 return code");
349
350     // Check 41
351     ret = sprintf(x, "hello%1.1fworld",0.0);
352     my_strcpy( y, "hello0.0world");
353     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "0.0 test #3");
354     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "0.0 test #3 return code");
355
356     // Check 42
357     ret = sprintf(x, "hello%5.1fworld",0.0);
358     my_strcpy( y, "hello  0.0world");
359     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "0.0 test #4");
360     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "0.0 test #4 return code");
361
362     // Check 43
363     ret = sprintf(x, "hello%fworld",-0.0);
364     my_strcpy( y, "hello-0.000000world");
365     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "-0.0 test #1");
366     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "-0.0 test #1 return code");
367
368     // Check 44
369     ret = sprintf(x, "hello%fworld",0.234);
370     my_strcpy( y, "hello0.234000world");
371     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "number less than 1 #1");
372     CYG_TEST_PASS_FAIL(ret == my_strlen(y),
373                        "number less than 1 #1 return code");
374
375     // Check 45
376     ret = sprintf(x, "hello%02fworld",-0.234);
377     my_strcpy( y, "hello-0.234000world");
378     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "number less than 1 #2");
379     CYG_TEST_PASS_FAIL(ret == my_strlen(y),
380                        "number less than 1 #2 return code");
381
382     // Check 46
383     ret = sprintf(x, "hello%02.2fworld",-0.234);
384     my_strcpy( y, "hello-0.23world");
385     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "number less than 1 #3");
386     CYG_TEST_PASS_FAIL(ret == my_strlen(y),
387                        "number less than 1 #3 return code");
388
389     // Check 47
390     ret = sprintf(x, "hello%06.2fworld",-0.234);
391     my_strcpy( y, "hello-00.23world");
392     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "number less than 1 #4");
393     CYG_TEST_PASS_FAIL(ret == my_strlen(y),
394                        "number less than 1 #4 return code");
395
396     // Check 48
397     ret = sprintf(x, "hello%-6.2fworld",2.345);
398     my_strcpy( y, "hello2.35  world");
399     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "left justification #1");
400     CYG_TEST_PASS_FAIL(ret == my_strlen(y),
401                        "left justification #1 return code");
402
403     // Check 49
404     ret = sprintf(x, "hello%-6.2fworld",2.345);
405     my_strcpy( y, "hello2.35  world");
406     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "left justification #2");
407     CYG_TEST_PASS_FAIL(ret == my_strlen(y),
408                        "left justification #2 return code");
409
410     // Check 50
411     ret = sprintf(x, "hello%-3.2fworld",2.345);
412     my_strcpy( y, "hello2.35world");
413     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "left justification #3");
414     CYG_TEST_PASS_FAIL(ret == my_strlen(y),
415                        "left justification #3 return code");
416
417     // Check 51
418     ret = sprintf(x, "hello%#1.0fworld",2.12);
419     my_strcpy( y, "hello2.world");
420     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "# modifier #1");
421     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "# modifier #1 return code");
422
423     // Check 52
424     ret = sprintf(x, "hello%#1.2fworld",2.0);
425     my_strcpy( y, "hello2.00world");
426     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "# modifier #2");
427     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "# modifier #2 return code");
428
429     // Check 53
430     ret = sprintf(x, "hello%eworld",2.3456);
431     my_strcpy( y, "hello2.345600e+00world");
432     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%e #1");
433     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%e #1 return code");
434
435     // Check 54
436     ret = sprintf(x, "hello%4.3eworld",-2.3456e-1);
437     my_strcpy( y, "hello-2.346e-01world");
438     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%e #2");
439     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%e #2 return code");
440
441     // Check 55
442     ret = sprintf(x, "hello%4.2eworld",2.56e2);
443     my_strcpy( y, "hello2.56e+02world");
444     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%e #3");
445     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%e #3 return code");
446
447     // Check 56
448     ret = sprintf(x, "hello%09.2eworld",2.56e2);
449     my_strcpy( y, "hello02.56e+02world");
450     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%e #4");
451     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%e #4 return code");
452
453     // Check 57
454     ret = sprintf(x, "hello%09.2Eworld",4.23e19);
455     my_strcpy( y, "hello04.23E+19world");
456     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%e #5");
457     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%e #5 return code");
458
459     // Check 58
460     ret = sprintf(x, "hello%gworld",4.0);
461     my_strcpy( y, "hello4world");
462     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%g #1");
463     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%g #1 return code");
464
465     // Check 59
466     ret = sprintf(x, "hello%gworld",4.56);
467     my_strcpy( y, "hello4.56world");
468     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%g #2");
469     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%g #2 return code");
470
471     // Check 60
472     ret = sprintf(x, "hello%5.2gworld",4.56);
473     my_strcpy( y, "hello  4.6world");
474     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%g #3");
475     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%g #3 return code");
476
477     // Check 61
478     ret = sprintf(x, "hello%gworld",0.002);
479     my_strcpy( y, "hello0.002world");
480     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%g #4");
481     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%g #4 return code");
482
483     // Check 62
484     ret = sprintf(x, "hello%06.1gworld",0.0026);
485     my_strcpy( y, "hello00.003world");
486     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%g #5");
487     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%g #5 return code");
488
489     // Check 63
490     ret = sprintf(x, "hello%06gworld",0.000026);
491     my_strcpy( y, "hello2.6e-05world");
492     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%g #5");
493     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%g #5 return code");
494
495     // Check 64
496     ret = sprintf(x, "hello%06Gworld",0.000037);
497     my_strcpy( y, "hello3.7E-05world");
498     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%g #6");
499     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%g #6 return code");
500
501     // Check 65
502     ret = sprintf(x, "hello%08Gworld",-123456.0);
503     my_strcpy( y, "hello-0123456world");
504     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%g #7");
505     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%g #7 return code");
506
507     // Check 66
508     ret = sprintf(x, "hello%07gworld",-1234567.0);
509     my_strcpy( y, "hello-1.23457e+06world");
510     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%g #8");
511     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%g #8 return code");
512
513     // Check 67
514     ret = sprintf(x, "hello%013Gworld",-1234567.0);
515     my_strcpy( y, "hello-01.23457E+06world");
516     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%g #9");
517     CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%g #9 return code");
518
519
520 #else
521     CYG_TEST_PASS("Floating point tests skipped - not configured");
522 #endif // ifdef CYGSEM_LIBC_STDIO_PRINTF_FLOATING_POINT
523
524     // Long string tests
525     ret = sprintf(x, "This is a very long string so I hope this works as "
526                   "otherwise I would be very, very, sad. The cat sat on the "
527                   "hat, and the mat sat on the rat. Quick brown fax, etc.etc. "
528                   "blah, blah and all that jazz. Isn't he finished yet? My "
529                   "old man's a dustman, why do I have to think up this "
530                   "drivel, isn't that what summer students are for, if "
531                   "anything that seems thinking up mindless drivel seems to "
532                   "be their occupation in life. Yoof of today, eh? What, "
533                   "what? %s So there.",
534                   "And this is a middly bit.");
535     my_strcpy(y, "This is a very long string so I hope this works as "
536                   "otherwise I would be very, very, sad. The cat sat on the "
537                   "hat, and the mat sat on the rat. Quick brown fax, etc.etc. "
538                   "blah, blah and all that jazz. Isn't he finished yet? My "
539                   "old man's a dustman, why do I have to think up this "
540                   "drivel, isn't that what summer students are for, if "
541                   "anything that seems thinking up mindless drivel seems to "
542                   "be their occupation in life. Yoof of today, eh? What, "
543                   "what? And this is a middly bit. So there.");
544     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "long (480 char) string output #1");
545     CYG_TEST_PASS_FAIL(ret == my_strlen(y),
546                        "long (480 char) string output #1 return code");
547
548     ret = sprintf(x, "Boo! This %s So there.",
549                   "is a very long string so I hope this works as "
550                   "otherwise I would be very, very, sad. The cat sat on the "
551                   "hat, and the mat sat on the rat. Quick brown fax, etc.etc. "
552                   "blah, blah and all that jazz. Isn't he finished yet? My "
553                   "old man's a dustman, why do I have to think up this "
554                   "drivel, isn't that what summer students are for, if "
555                   "anything that seems thinking up mindless drivel seems to "
556                   "be their occupation in life. Yoof of today, eh? What, "
557                   "what? And this is a middly bit.");
558     my_strcpy(y, "Boo! This is a very long string so I hope this works as "
559                   "otherwise I would be very, very, sad. The cat sat on the "
560                   "hat, and the mat sat on the rat. Quick brown fax, etc.etc. "
561                   "blah, blah and all that jazz. Isn't he finished yet? My "
562                   "old man's a dustman, why do I have to think up this "
563                   "drivel, isn't that what summer students are for, if "
564                   "anything that seems thinking up mindless drivel seems to "
565                   "be their occupation in life. Yoof of today, eh? What, "
566                   "what? And this is a middly bit. So there.");
567     CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "long (485 char) string output #2");
568     CYG_TEST_PASS_FAIL(ret == my_strlen(y),
569                        "long (485 char) string output #2 return code");
570
571
572
573
574     CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
575                     "sprintf() function");
576
577 } // test()
578
579 int
580 main(int argc, char *argv[])
581 {
582     CYG_TEST_INIT();
583
584     CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library "
585                   "sprintf() function");
586     CYG_TEST_INFO("These test individual features separately");
587
588     test(0);
589
590     return 0;
591 } // main()
592
593 // EOF sprintf1.c