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