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