OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [io/] [fileio/] [v2_0/] [tests/] [stdio.c] - Blame information for rev 174

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.