Mercurial > flash_v2
annotate packages/language/c/libc/current/tests/stdio/stdiooutput.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 | 443894e2e912 |
| children | bf00f99aec69 |
| rev | line source |
|---|---|
| 0 | 1 //================================================================= |
| 2 // | |
| 3 // stdiooutput.c | |
| 4 // | |
| 5 // Testcase for miscellaneous C library output functions | |
| 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 |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
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:
2
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:
2
diff
changeset
|
14 // http://sourceware.cygnus.com/ecos |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
15 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
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:
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): jlarmour |
| 35 // Contributors: jlarmour | |
| 0 | 36 // Date: 1998/9/4 |
| 37 // Description: Contains testcode for C library stdio output | |
| 38 // functions | |
| 39 // | |
| 40 // | |
| 41 //####DESCRIPTIONEND#### | |
| 42 | |
| 43 // Declarations for test system: | |
| 44 // | |
| 45 // TESTCASE_TYPE=CYG_TEST_MODULE | |
| 46 | |
| 47 // CONFIGURATION | |
| 48 | |
| 49 #include <pkgconf/libc.h> // Configuration header | |
| 50 | |
| 51 // INCLUDES | |
| 52 | |
| 53 #include <stdio.h> // All the stdio functions | |
| 54 #include <errno.h> // errno | |
| 55 #include <cyg/infra/testcase.h> // Testcase API | |
| 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 | |
| 87 static void | |
| 88 test( CYG_ADDRWORD data ) | |
| 89 { | |
| 90 int i; | |
| 91 | |
| 92 | |
| 93 // Check 1 | |
| 94 CYG_TEST_INFO("Expect: Hello printf world 42!"); | |
| 95 printf("Hello printf %s %d!\n", "world", 42); | |
| 96 | |
| 97 // Check 2 | |
| 98 CYG_TEST_INFO("Expect: This is fprintf 0x07f!"); | |
| 99 fprintf(stdout, "This is fprintf 0x%03x!\n", 0x7f); | |
| 100 | |
| 101 // Check 3 | |
| 102 CYG_TEST_INFO("Expect: char tests"); | |
| 103 fputc( 'c', stderr ); | |
| 104 putc( 'h', stdout ); | |
| 105 putchar( 'a' ); | |
| 106 fputc( 'r', stdout ); | |
| 107 putchar( ' ' ); | |
| 108 fflush(stdout); | |
| 109 putc( 't', stderr ); | |
| 110 fputc( 'e', stdout ); | |
| 111 putchar( 's' ); | |
| 112 fflush( NULL ); | |
| 113 putc( 't', stderr ); | |
| 114 fputc( 's', stderr ); | |
| 115 putchar( '\n' ); | |
| 116 | |
| 117 // Check 4 | |
| 118 CYG_TEST_INFO("Expect: puts test"); | |
| 119 puts("puts test"); | |
| 120 | |
| 121 // Check 5 | |
| 122 CYG_TEST_INFO("Expect: fputs test"); | |
| 123 fputs( "fputs test\n", stdout ); | |
| 124 | |
| 125 // Check 6 | |
| 126 CYG_TEST_INFO("Expect: fwrite test"); | |
| 127 fwrite( "fwrite test\n", 6, 2, stderr ); | |
| 128 | |
| 129 // Check 7 | |
| 130 CYG_TEST_INFO("Expect: wibble: No error"); | |
| 131 errno = ENOERR; | |
| 132 perror( "wibble" ); | |
| 133 | |
| 134 // Check 8 | |
| 135 CYG_TEST_INFO("Expect: Long string test!\nSitting on the side of the " | |
| 136 "highway waiting to catch speeding drivers, a State " | |
| 137 "Police Officer sees a car puttering along at 22 MPH. " | |
| 138 "He thinks to himself, \"This driver is just as " | |
| 139 "dangerous as a speeder!\" So he turns on his lights " | |
| 140 "and pulls the driver over. Approaching the car, " | |
| 141 "he notices that there are five old ladies-two in " | |
| 142 "the front seat and three in the back-wide eyed and " | |
| 143 "white as ghosts. The driver, obviously confused, says " | |
| 144 "to him, \"Officer, I don't understand, I was doing " | |
| 145 "exactly the speed limit! What seems to be the " | |
| 146 "problem?\" \"Ma'am,\" the officer replies, \"you " | |
| 147 "weren't speeding, but you should know that driving " | |
| 148 "slower than the speed limit can also be a danger to " | |
| 149 "other drivers.\" \"Slower than the speed limit? No " | |
| 150 "sir, I was doing the speed limit exactly...Twenty-two " | |
| 151 "miles an hour!\" the old woman says a bit proudly. " | |
| 152 "The State Police officer, trying to contain a " | |
| 153 "chuckle explains to her that \"22\" was the route " | |
| 154 "number, not the speed limit. A bit embarrassed, the " | |
| 155 "woman grinned and thanked the officer for pointing " | |
| 156 "out her error. \"But before I let you go, Ma'am, I " | |
| 157 "have to ask... Is everyone in this car OK? These " | |
| 158 "women seem awfully shaken and they haven't muttered a " | |
| 159 "single peep this whole time,\" the officer asks. \"Oh, " | |
| 160 "they'll be all right in a minute officer. We just got " | |
| 161 "off Route 119\"."); | |
| 162 | |
| 163 printf("Long string test!\nSitting on the side of the " | |
| 164 "highway waiting to catch speeding drivers, a State " | |
| 165 "Police Officer sees a car puttering along at %d MPH. " | |
| 166 "He thinks to himself, \"This driver is just as " | |
| 167 "dangerous as a speeder!\" So he turns on his lights " | |
| 168 "and pulls the driver over. Approaching the car, " | |
| 169 "he notices that there are five old ladies-two in " | |
| 170 "the front seat and three in the back-wide eyed and " | |
| 171 "white as ghosts. The driver, obviously confused, says " | |
| 172 "to him, \"Officer, I don't understand, I was doing " | |
| 173 "exactly the speed limit! What seems to be the " | |
| 174 "problem?\" \"Ma'am,\" the officer replies, \"you " | |
| 175 "weren't speeding, but you should know that driving " | |
| 176 "slower than the speed limit can also be a danger to " | |
| 177 "other drivers.\" \"Slower than the speed limit? No " | |
| 178 "sir, I was doing the speed limit exactly...Twenty-two " | |
| 179 "miles an hour!\" the old woman says a bit proudly. " | |
| 180 "The State Police officer, trying to contain a " | |
| 181 "chuckle explains to her that \"%d\" was the route " | |
| 182 "number, not the speed limit. A bit embarrassed, the " | |
| 183 "%coman grinned and thanked the officer for pointing " | |
| 184 "out her error. \"But before I let you go, Ma'am, I " | |
| 185 "have to ask... Is everyone in this car OK? These " | |
| 186 "women seem awfully shaken and they haven't muttered a " | |
| 187 "single peep this whole time,\" the officer asks. \"Oh, " | |
| 188 "they'll be all right in a minute officer. We just got " | |
| 189 "off Route %d\".\n", 22, 22, 'w', 119); | |
| 190 | |
| 191 // Check 9 | |
| 192 CYG_TEST_INFO("Expect: Another puts test, just for fun"); | |
| 193 puts("Another puts test, just for fun"); | |
| 194 | |
| 195 // Check 10 | |
| 196 CYG_TEST_INFO("Expect: more fputs testing"); | |
| 197 fputs( "more fputs testing\n", stderr ); | |
| 198 | |
| 199 // Check 11 | |
| 200 CYG_TEST_INFO("Expect all the numbers from 1 to 100 in 5 columns"); | |
| 201 for (i=1; i<101; ++i) { | |
| 202 | |
| 203 printf("%5d ", i); | |
| 204 if (i%5 == 0) | |
| 205 fputc( '\n', stdout); | |
| 206 | |
| 207 } // for | |
| 208 | |
| 209 CYG_TEST_PASS("Stdio output tests completed"); | |
| 210 CYG_TEST_FINISH("Finished tests from testcase " __FILE__ | |
| 211 " for C library stdio output functions"); | |
| 212 | |
| 213 } // test() | |
| 214 | |
| 215 #endif // if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_STDIO) | |
| 216 | |
| 217 int | |
| 218 main(int argc, char *argv[]) | |
| 219 { | |
| 220 CYG_TEST_INIT(); | |
| 221 | |
| 222 CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C " | |
| 223 "library stdio output functions"); | |
| 224 CYG_TEST_INFO("The output of these tests needs to be manually " | |
| 225 "verified."); | |
| 226 | |
| 227 START_TEST( test ); | |
| 228 | |
| 2 | 229 CYG_TEST_NA("Testing is not applicable to this configuration"); |
| 0 | 230 |
| 231 } // main() | |
| 232 | |
| 233 // EOF stdiooutput.c |
