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