Mercurial > flash_v2
annotate packages/language/c/libc/current/tests/stdio/sprintf2.c @ 64:c38311975d4f ecos-sw-2000-01-28
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
| author | jlarmour |
|---|---|
| date | Fri, 28 Jan 2000 04:59:39 +0000 |
| parents | 18ee5a9c102e |
| children | bf00f99aec69 |
| rev | line source |
|---|---|
| 0 | 1 //================================================================= |
| 2 // | |
| 3 // sprintf2.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:
28
diff
changeset
|
9 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
28
diff
changeset
|
10 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
28
diff
changeset
|
11 // The contents of this file are subject to the Red Hat eCos Public License |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
28
diff
changeset
|
12 // Version 1.0 (the "License"); you may not use this file except in |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
28
diff
changeset
|
13 // compliance with the License. You may obtain a copy of the License at |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
28
diff
changeset
|
14 // http://sourceware.cygnus.com/ecos |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
28
diff
changeset
|
15 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
28
diff
changeset
|
16 // Software distributed under the License is distributed on an |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
28
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:
28
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:
28
diff
changeset
|
19 // the License. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
28
diff
changeset
|
20 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
28
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:
28
diff
changeset
|
22 // released September 30, 1998. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
28
diff
changeset
|
23 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
28
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:
28
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:
28
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:
28
diff
changeset
|
27 // All Rights Reserved. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
28
diff
changeset
|
28 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
28
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 // CONFIGURATION | |
| 47 | |
| 48 #include <pkgconf/libc.h> // Configuration header | |
| 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 | |
| 87 my_strlen(const char *s) | |
| 88 { | |
| 89 const char *ptr; | |
| 90 | |
| 91 ptr = s; | |
| 92 for ( ptr=s ; *ptr != '\0' ; ptr++ ) | |
| 93 ; | |
| 94 | |
| 95 return (int)(ptr-s); | |
| 96 } // my_strlen() | |
| 97 | |
| 98 | |
| 99 static int | |
| 100 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 * | |
| 113 my_strcpy(char *s1, const char *s2) | |
| 114 { | |
| 115 while (*s2 != '\0') { | |
| 116 *(s1++) = *(s2++); | |
| 117 } | |
| 118 *s1 = '\0'; | |
| 119 | |
| 120 return s1; | |
| 121 } // my_strcpy() | |
| 122 | |
| 123 | |
| 124 | |
| 125 static void | |
| 126 test( CYG_ADDRWORD data ) | |
| 127 { | |
| 128 static char x[200]; | |
| 129 static char y[200]; | |
| 130 static char z[200]; | |
| 131 int ret; | |
| 132 int tmp; | |
| 133 int *ptr; | |
| 134 | |
| 135 // Check 1 | |
| 136 my_strcpy(x, "I'm afraid the shield generator"); | |
| 137 ptr = &tmp; | |
| 138 ret = sprintf(y, "%s%n will be quite operational - %5d%%%c%05X", x, | |
| 139 ptr, 13, '5', 0x89ab); | |
| 140 my_strcpy( z, "I'm afraid the shield generator will be " | |
| 141 "quite operational - 13%5089AB" ); | |
| 142 CYG_TEST_PASS_FAIL(my_strcmp(y,z) == 0, "%s%n%d%%%c%0X test"); | |
| 143 | |
| 144 CYG_TEST_PASS_FAIL(ret == my_strlen(z), | |
| 145 "%s%n%d%%%c%0X test return code" ); | |
| 146 | |
| 147 CYG_TEST_PASS_FAIL(tmp==31, "%n test"); | |
| 148 | |
| 149 // Check 2 | |
| 150 ret = sprintf(y, "|%5d|%10s|%03d|%c|%o|", 2, "times", 6, '=', 10 ); | |
| 151 my_strcpy(z, "| 2| times|006|=|12|"); | |
| 152 | |
| 153 CYG_TEST_PASS_FAIL(my_strcmp(y,z) == 0, "|%5d|%10s|%03d|%c|%o| test"); | |
| 154 | |
| 155 CYG_TEST_PASS_FAIL(ret == my_strlen(z), | |
| 156 "|%5d|%10s|%03d|%c|%o| test return code" ); | |
| 157 | |
| 158 #ifdef CYGSEM_LIBC_STDIO_PRINTF_FLOATING_POINT | |
| 159 | |
| 160 CYG_TEST_INFO("Starting floating point specific tests"); | |
| 161 | |
| 162 // Check 3 | |
| 163 ret = sprintf(y, "|%5f|%10s|%03d|%c|%+-5.2G|%010.3G|", | |
|
28
18ee5a9c102e
Merge from eCos master repository on 1999-08-09-17:04:48-BST
jlarmour
parents:
2
diff
changeset
|
164 2.0, "times", 6, '=', 12.0, -2.3451e-6 ); |
|
18ee5a9c102e
Merge from eCos master repository on 1999-08-09-17:04:48-BST
jlarmour
parents:
2
diff
changeset
|
165 my_strcpy(z, "|2.000000| times|006|=|+12 |-02.35E-06|"); |
| 0 | 166 |
| 167 CYG_TEST_PASS_FAIL(my_strcmp(y,z) == 0, | |
| 168 "|%5f|%10s|%03d|%c|%+-5.2G|%010.3G| test"); | |
| 169 | |
| 170 CYG_TEST_PASS_FAIL(ret == my_strlen(z), | |
| 171 "|%5f|%10s|%03d|%c|%+-5.2G|%010.3G| test " | |
| 172 "return code" ); | |
| 173 | |
| 174 #endif // ifdef CYGSEM_LIBC_STDIO_PRINTF_FLOATING_POINT | |
| 175 | |
| 176 CYG_TEST_FINISH("Finished tests from testcase " __FILE__ | |
| 177 " for C library sprintf() function"); | |
| 178 | |
| 179 } // test() | |
| 180 | |
| 181 #endif // if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_STDIO) | |
| 182 | |
| 183 int | |
| 184 main(int argc, char *argv[]) | |
| 185 { | |
| 186 CYG_TEST_INIT(); | |
| 187 | |
| 188 CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C " | |
| 189 "library sprintf() function"); | |
| 190 CYG_TEST_INFO("These test combinations of sprintf() features"); | |
| 191 | |
| 192 START_TEST( test ); | |
| 193 | |
| 2 | 194 CYG_TEST_NA("Testing is not applicable to this configuration"); |
| 0 | 195 |
| 196 } // main() | |
| 197 | |
| 198 // EOF sprintf2.c |
