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