Mercurial > ecos
annotate packages/language/c/libc/current/tests/stdio/sprintf2.c @ 28:18ee5a9c102e ecos-sw-1999-08-09
Merge from eCos master repository on 1999-08-09-17:04:48-BST
| author | jlarmour |
|---|---|
| date | Mon, 09 Aug 1999 16:37:19 +0000 |
| parents | 443894e2e912 |
| children | c38311975d4f |
| rev | line source |
|---|---|
| 0 | 1 //================================================================= |
| 2 // | |
| 3 // sprintf2.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 | |
| 2 | 25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
| 0 | 26 // ------------------------------------------- |
| 27 // | |
| 28 //####COPYRIGHTEND#### | |
| 29 //================================================================= | |
| 30 //#####DESCRIPTIONBEGIN#### | |
| 31 // | |
| 2 | 32 // Author(s): ctarpy, jlarmour |
| 33 // Contributors: jlarmour | |
| 0 | 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 // CONFIGURATION | |
| 45 | |
| 46 #include <pkgconf/libc.h> // Configuration header | |
| 47 | |
| 48 // INCLUDES | |
| 49 | |
| 50 #include <stdio.h> | |
| 51 #include <cyg/infra/testcase.h> | |
| 52 #include <sys/cstartup.h> // C library initialisation | |
| 53 | |
| 54 // HOW TO START TESTS | |
| 55 | |
| 56 #if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_STDIO) | |
| 57 | |
| 58 # define START_TEST( test ) test(0) | |
| 59 | |
| 60 #else | |
| 61 | |
| 62 # define START_TEST( test ) CYG_EMPTY_STATEMENT | |
| 63 | |
| 64 #endif | |
| 65 | |
| 66 | |
| 67 // FUNCTIONS | |
| 68 | |
| 69 externC void | |
| 70 cyg_package_start( void ) | |
| 71 { | |
| 72 #ifdef CYGPKG_LIBC | |
| 73 cyg_iso_c_start(); | |
| 74 #else | |
| 75 (void)main(0, NULL); | |
| 76 #endif | |
| 77 } // cyg_package_start() | |
| 78 | |
| 79 | |
| 80 #if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_STDIO) | |
| 81 | |
| 82 // Functions to avoid having to use libc strings | |
| 83 | |
| 84 static int | |
| 85 my_strlen(const char *s) | |
| 86 { | |
| 87 const char *ptr; | |
| 88 | |
| 89 ptr = s; | |
| 90 for ( ptr=s ; *ptr != '\0' ; ptr++ ) | |
| 91 ; | |
| 92 | |
| 93 return (int)(ptr-s); | |
| 94 } // my_strlen() | |
| 95 | |
| 96 | |
| 97 static int | |
| 98 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 * | |
| 111 my_strcpy(char *s1, const char *s2) | |
| 112 { | |
| 113 while (*s2 != '\0') { | |
| 114 *(s1++) = *(s2++); | |
| 115 } | |
| 116 *s1 = '\0'; | |
| 117 | |
| 118 return s1; | |
| 119 } // my_strcpy() | |
| 120 | |
| 121 | |
| 122 | |
| 123 static void | |
| 124 test( CYG_ADDRWORD data ) | |
| 125 { | |
| 126 static char x[200]; | |
| 127 static char y[200]; | |
| 128 static char z[200]; | |
| 129 int ret; | |
| 130 int tmp; | |
| 131 int *ptr; | |
| 132 | |
| 133 // Check 1 | |
| 134 my_strcpy(x, "I'm afraid the shield generator"); | |
| 135 ptr = &tmp; | |
| 136 ret = sprintf(y, "%s%n will be quite operational - %5d%%%c%05X", x, | |
| 137 ptr, 13, '5', 0x89ab); | |
| 138 my_strcpy( z, "I'm afraid the shield generator will be " | |
| 139 "quite operational - 13%5089AB" ); | |
| 140 CYG_TEST_PASS_FAIL(my_strcmp(y,z) == 0, "%s%n%d%%%c%0X test"); | |
| 141 | |
| 142 CYG_TEST_PASS_FAIL(ret == my_strlen(z), | |
| 143 "%s%n%d%%%c%0X test return code" ); | |
| 144 | |
| 145 CYG_TEST_PASS_FAIL(tmp==31, "%n test"); | |
| 146 | |
| 147 // Check 2 | |
| 148 ret = sprintf(y, "|%5d|%10s|%03d|%c|%o|", 2, "times", 6, '=', 10 ); | |
| 149 my_strcpy(z, "| 2| times|006|=|12|"); | |
| 150 | |
| 151 CYG_TEST_PASS_FAIL(my_strcmp(y,z) == 0, "|%5d|%10s|%03d|%c|%o| test"); | |
| 152 | |
| 153 CYG_TEST_PASS_FAIL(ret == my_strlen(z), | |
| 154 "|%5d|%10s|%03d|%c|%o| test return code" ); | |
| 155 | |
| 156 #ifdef CYGSEM_LIBC_STDIO_PRINTF_FLOATING_POINT | |
| 157 | |
| 158 CYG_TEST_INFO("Starting floating point specific tests"); | |
| 159 | |
| 160 // Check 3 | |
| 161 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
|
162 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
|
163 my_strcpy(z, "|2.000000| times|006|=|+12 |-02.35E-06|"); |
| 0 | 164 |
| 165 CYG_TEST_PASS_FAIL(my_strcmp(y,z) == 0, | |
| 166 "|%5f|%10s|%03d|%c|%+-5.2G|%010.3G| test"); | |
| 167 | |
| 168 CYG_TEST_PASS_FAIL(ret == my_strlen(z), | |
| 169 "|%5f|%10s|%03d|%c|%+-5.2G|%010.3G| test " | |
| 170 "return code" ); | |
| 171 | |
| 172 #endif // ifdef CYGSEM_LIBC_STDIO_PRINTF_FLOATING_POINT | |
| 173 | |
| 174 CYG_TEST_FINISH("Finished tests from testcase " __FILE__ | |
| 175 " for C library sprintf() function"); | |
| 176 | |
| 177 } // test() | |
| 178 | |
| 179 #endif // if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_STDIO) | |
| 180 | |
| 181 int | |
| 182 main(int argc, char *argv[]) | |
| 183 { | |
| 184 CYG_TEST_INIT(); | |
| 185 | |
| 186 CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C " | |
| 187 "library sprintf() function"); | |
| 188 CYG_TEST_INFO("These test combinations of sprintf() features"); | |
| 189 | |
| 190 START_TEST( test ); | |
| 191 | |
| 2 | 192 CYG_TEST_NA("Testing is not applicable to this configuration"); |
| 0 | 193 |
| 194 } // main() | |
| 195 | |
| 196 // EOF sprintf2.c |
