1 |
786 |
skrzyp |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// stdio.c
|
4 |
|
|
//
|
5 |
|
|
// Test stdio integration of fileio system
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
16 |
|
|
// version.
|
17 |
|
|
//
|
18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
19 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
20 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
21 |
|
|
// for more details.
|
22 |
|
|
//
|
23 |
|
|
// You should have received a copy of the GNU General Public License
|
24 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
|
|
//
|
27 |
|
|
// As a special exception, if other files instantiate templates or use
|
28 |
|
|
// macros or inline functions from this file, or you compile this file
|
29 |
|
|
// and link it with other works to produce a work based on this file,
|
30 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
31 |
|
|
// the GNU General Public License. However the source code for this file
|
32 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
33 |
|
|
// General Public License v2.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based
|
36 |
|
|
// on this file might be covered by the GNU General Public License.
|
37 |
|
|
// -------------------------------------------
|
38 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
39 |
|
|
//==========================================================================
|
40 |
|
|
//#####DESCRIPTIONBEGIN####
|
41 |
|
|
//
|
42 |
|
|
// Author(s): nickg
|
43 |
|
|
// Contributors: nickg
|
44 |
|
|
// Date: 2000-05-25
|
45 |
|
|
// Purpose: Test stdio integration of fileio system
|
46 |
|
|
// Description: This test uses the testfs to check that the options
|
47 |
|
|
// in the STDIO package that enable use of the fileio
|
48 |
|
|
// API work correctly.
|
49 |
|
|
//
|
50 |
|
|
//
|
51 |
|
|
//
|
52 |
|
|
//
|
53 |
|
|
//
|
54 |
|
|
//####DESCRIPTIONEND####
|
55 |
|
|
//
|
56 |
|
|
//==========================================================================
|
57 |
|
|
|
58 |
|
|
#include <stdio.h>
|
59 |
|
|
#include <string.h>
|
60 |
|
|
|
61 |
|
|
#include <cyg/infra/testcase.h>
|
62 |
|
|
#include <cyg/infra/diag.h> // HAL polled output
|
63 |
|
|
|
64 |
|
|
//==========================================================================
|
65 |
|
|
// Include the test filesystem.
|
66 |
|
|
// If we could make tests out of multiple files, then we could just link
|
67 |
|
|
// against the object file for this rather than including it.
|
68 |
|
|
|
69 |
|
|
#include "testfs.c"
|
70 |
|
|
|
71 |
|
|
//==========================================================================
|
72 |
|
|
|
73 |
|
|
#define SHOW_RESULT( _fn, _res ) \
|
74 |
|
|
diag_printf("<INFO>: " #_fn "() returned %d %s\n", _res, _res<0?strerror(errno):"");
|
75 |
|
|
|
76 |
|
|
|
77 |
|
|
#ifdef CYGPKG_LIBC_STDIO
|
78 |
|
|
|
79 |
|
|
//==========================================================================
|
80 |
|
|
// main
|
81 |
|
|
|
82 |
|
|
int main( int argc, char **argv )
|
83 |
|
|
{
|
84 |
|
|
int err;
|
85 |
|
|
FILE *f;
|
86 |
|
|
fpos_t fpos;
|
87 |
|
|
|
88 |
|
|
int flibble = 4567;
|
89 |
|
|
char *wibble = "abcdefghijk";
|
90 |
|
|
|
91 |
|
|
int flibble1;
|
92 |
|
|
char wibble1[20];
|
93 |
|
|
|
94 |
|
|
CYG_TEST_INIT();
|
95 |
|
|
|
96 |
|
|
|
97 |
|
|
f = fopen("/foo", "w" );
|
98 |
|
|
if( f == NULL ) SHOW_RESULT( fopen, -1 );
|
99 |
|
|
|
100 |
|
|
err = fprintf(f, "flibble %d wibble %s\n", flibble, wibble );
|
101 |
|
|
if( err < 0 ) SHOW_RESULT( fprintf, err );
|
102 |
|
|
|
103 |
|
|
err = fprintf(f, "another flibble %d another wibble %s\n", flibble, wibble );
|
104 |
|
|
if( err < 0 ) SHOW_RESULT( fprintf, err );
|
105 |
|
|
|
106 |
|
|
err = fclose( f );
|
107 |
|
|
if( err == EOF ) SHOW_RESULT( fclose, -1 );
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
|
111 |
|
|
f = fopen("/foo", "r" );
|
112 |
|
|
if( f == NULL ) SHOW_RESULT( fopen, -1 );
|
113 |
|
|
|
114 |
|
|
err = fscanf(f, "flibble %d wibble %s\n", &flibble1, wibble1 );
|
115 |
|
|
if( err < 0 ) SHOW_RESULT( fscanf, err );
|
116 |
|
|
|
117 |
|
|
diag_printf("<INFO>: flibble1 %d wibble1 %s\n",flibble1,wibble1);
|
118 |
|
|
|
119 |
|
|
CYG_TEST_CHECK( flibble1 == flibble , "Bad flibble result from fscanf");
|
120 |
|
|
CYG_TEST_CHECK( strcmp(wibble,wibble1) == 0, "Bad wibble result from fscanf");
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
err = fgetpos( f, &fpos );
|
124 |
|
|
if( err < 0 ) SHOW_RESULT( fgetpos, err );
|
125 |
|
|
|
126 |
|
|
err = fseek( f, 0, SEEK_SET );
|
127 |
|
|
if( err < 0 ) SHOW_RESULT( fseek, err );
|
128 |
|
|
|
129 |
|
|
err = fscanf(f, "flibble %d wibble %s\n", &flibble1, wibble1 );
|
130 |
|
|
if( err < 0 ) SHOW_RESULT( fscanf, err );
|
131 |
|
|
|
132 |
|
|
diag_printf("<INFO>: flibble1 %d wibble1 %s\n",flibble1,wibble1);
|
133 |
|
|
|
134 |
|
|
CYG_TEST_CHECK( flibble1 == flibble , "Bad flibble result from fscanf");
|
135 |
|
|
CYG_TEST_CHECK( strcmp(wibble,wibble1) == 0, "Bad wibble result from fscanf");
|
136 |
|
|
|
137 |
|
|
|
138 |
|
|
err = fseek( f, 0, SEEK_END );
|
139 |
|
|
if( err < 0 ) SHOW_RESULT( fseek, err );
|
140 |
|
|
|
141 |
|
|
err = fsetpos( f, &fpos );
|
142 |
|
|
if( err < 0 ) SHOW_RESULT( fsetpos, err );
|
143 |
|
|
|
144 |
|
|
err = fscanf(f, "another flibble %d another wibble %s\n", &flibble1, wibble1 );
|
145 |
|
|
if( err < 0 ) SHOW_RESULT( fscanf, err );
|
146 |
|
|
|
147 |
|
|
diag_printf("<INFO>: flibble1 %d wibble1 %s\n",flibble1,wibble1);
|
148 |
|
|
|
149 |
|
|
CYG_TEST_CHECK( flibble1 == flibble , "Bad flibble result from fscanf");
|
150 |
|
|
CYG_TEST_CHECK( strcmp(wibble,wibble1) == 0, "Bad wibble result from fscanf");
|
151 |
|
|
|
152 |
|
|
|
153 |
|
|
|
154 |
|
|
err = fclose( f );
|
155 |
|
|
|
156 |
|
|
|
157 |
|
|
|
158 |
|
|
CYG_TEST_PASS_FINISH("stdio");
|
159 |
|
|
|
160 |
|
|
return 0;
|
161 |
|
|
}
|
162 |
|
|
|
163 |
|
|
#else
|
164 |
|
|
|
165 |
|
|
// -------------------------------------------------------------------------
|
166 |
|
|
|
167 |
|
|
int main( int argc, char **argv )
|
168 |
|
|
{
|
169 |
|
|
|
170 |
|
|
CYG_TEST_INIT();
|
171 |
|
|
|
172 |
|
|
CYG_TEST_NA("stdio");
|
173 |
|
|
}
|
174 |
|
|
|
175 |
|
|
#endif
|
176 |
|
|
|
177 |
|
|
// -------------------------------------------------------------------------
|
178 |
|
|
// EOF stdio.c
|