1*c2c66affSColin Finck /*
2*c2c66affSColin Finck  *  ReactOS test program -
3*c2c66affSColin Finck  *
4*c2c66affSColin Finck  *  _tfileio.c
5*c2c66affSColin Finck  *
6*c2c66affSColin Finck  *  Copyright (C) 2002  Robert Dickenson <robd@reactos.org>
7*c2c66affSColin Finck  *
8*c2c66affSColin Finck  *  This program is free software; you can redistribute it and/or modify
9*c2c66affSColin Finck  *  it under the terms of the GNU General Public License as published by
10*c2c66affSColin Finck  *  the Free Software Foundation; either version 2 of the License, or
11*c2c66affSColin Finck  *  (at your option) any later version.
12*c2c66affSColin Finck  *
13*c2c66affSColin Finck  *  This program is distributed in the hope that it will be useful,
14*c2c66affSColin Finck  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15*c2c66affSColin Finck  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16*c2c66affSColin Finck  *  GNU General Public License for more details.
17*c2c66affSColin Finck  *
18*c2c66affSColin Finck  *  You should have received a copy of the GNU General Public License
19*c2c66affSColin Finck  *  along with this program; if not, write to the Free Software
20*c2c66affSColin Finck  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21*c2c66affSColin Finck  */
22*c2c66affSColin Finck 
23*c2c66affSColin Finck #define WIN32_LEAN_AND_MEAN
24*c2c66affSColin Finck #include <windows.h>
25*c2c66affSColin Finck #include <tchar.h>
26*c2c66affSColin Finck #include <wchar.h>
27*c2c66affSColin Finck #include <stdio.h>
28*c2c66affSColin Finck 
29*c2c66affSColin Finck 
30*c2c66affSColin Finck #ifdef UNICODE
31*c2c66affSColin Finck #define _tfopen      _wfopen
32*c2c66affSColin Finck #define _tunlink     _wunlink
33*c2c66affSColin Finck #define _TEOF        WEOF
34*c2c66affSColin Finck #define _gettchar    getwchar
35*c2c66affSColin Finck #define _puttchar    putwchar
36*c2c66affSColin Finck #define _THEX_FORMAT _T("0x%04x ")
37*c2c66affSColin Finck #else /*UNICODE*/
38*c2c66affSColin Finck #define _tfopen      fopen
39*c2c66affSColin Finck #define _tunlink     _unlink
40*c2c66affSColin Finck #define _TEOF        EOF
41*c2c66affSColin Finck #define _gettchar    getchar
42*c2c66affSColin Finck #define _puttchar    putchar
43*c2c66affSColin Finck #define _THEX_FORMAT "0x%02x "
44*c2c66affSColin Finck #endif /*UNICODE*/
45*c2c66affSColin Finck 
46*c2c66affSColin Finck 
47*c2c66affSColin Finck #define TEST_BUFFER_SIZE 200
48*c2c66affSColin Finck #define TEST_FILE_LINES  4
49*c2c66affSColin Finck 
50*c2c66affSColin Finck extern BOOL verbose_flagged;
51*c2c66affSColin Finck extern BOOL status_flagged;
52*c2c66affSColin Finck 
53*c2c66affSColin Finck static TCHAR test_buffer[TEST_BUFFER_SIZE];
54*c2c66affSColin Finck 
55*c2c66affSColin Finck static TCHAR dos_data[] = _T("line1: this is a bunch of readable text.\r\n")\
56*c2c66affSColin Finck                    _T("line2: some more printable text and punctuation !@#$%^&*()\r\n")\
57*c2c66affSColin Finck                    _T("line3: followed up with some numerals 1234567890\r\n")\
58*c2c66affSColin Finck                    _T("line4: done.\r\n");
59*c2c66affSColin Finck 
60*c2c66affSColin Finck static TCHAR nix_data[] = _T("line1: this is a bunch of readable text.\n")\
61*c2c66affSColin Finck                    _T("line2: some more printable text and punctuation !@#$%^&*()\n")\
62*c2c66affSColin Finck                    _T("line3: followed up with some numerals 1234567890\n")\
63*c2c66affSColin Finck                    _T("line4: done.\n");
64*c2c66affSColin Finck 
65*c2c66affSColin Finck #ifdef UNICODE
66*c2c66affSColin Finck #define TEST_B1_FILE_SIZE ((((sizeof(dos_data)/2)-1)+TEST_FILE_LINES)/2) // (166+4)/2=85
67*c2c66affSColin Finck #define TEST_B2_FILE_SIZE (((sizeof(dos_data)/2)-1)*2)                   // (166*2)  =332
68*c2c66affSColin Finck #define TEST_B3_FILE_SIZE ((((sizeof(nix_data)/2)-1)+TEST_FILE_LINES)/2) // (162+4)/2=83
69*c2c66affSColin Finck #define TEST_B4_FILE_SIZE (((sizeof(nix_data)/2)-1)*2)                   // (162*2)  =324
70*c2c66affSColin Finck #else /*UNICODE*/
71*c2c66affSColin Finck #define TEST_B1_FILE_SIZE (sizeof(dos_data)-1+TEST_FILE_LINES) // (166+4)=170
72*c2c66affSColin Finck #define TEST_B2_FILE_SIZE (sizeof(dos_data)-1-TEST_FILE_LINES) // (166-4)=162
73*c2c66affSColin Finck #define TEST_B3_FILE_SIZE (sizeof(nix_data)-1+TEST_FILE_LINES) // (162+4)=166
74*c2c66affSColin Finck #define TEST_B4_FILE_SIZE (sizeof(nix_data)-1)                 // (162)  =162
75*c2c66affSColin Finck #endif /*UNICODE*/
76*c2c66affSColin Finck 
77*c2c66affSColin Finck 
78*c2c66affSColin Finck //    result = create_test_file(file_name, _T("wb"), _T("rb"), file_data);
79*c2c66affSColin Finck 
test_file_truncate(TCHAR * file_name)80*c2c66affSColin Finck static BOOL test_file_truncate(TCHAR* file_name)
81*c2c66affSColin Finck {
82*c2c66affSColin Finck     BOOL result = FALSE;
83*c2c66affSColin Finck     int count = -1;
84*c2c66affSColin Finck     int error_code;
85*c2c66affSColin Finck     TCHAR ch;
86*c2c66affSColin Finck     TCHAR* file_data = _T("this file should have been truncated to zero bytes...");
87*c2c66affSColin Finck     FILE *file = _tfopen(file_name, _T("wb"));
88*c2c66affSColin Finck 
89*c2c66affSColin Finck     if (verbose_flagged) {
90*c2c66affSColin Finck         _tprintf(_T("test_file_truncate(\"%s\")\n"), file_name);
91*c2c66affSColin Finck     }
92*c2c66affSColin Finck 
93*c2c66affSColin Finck     if (file != NULL) {
94*c2c66affSColin Finck         if (_fputts(file_data, file) != _TEOF) {
95*c2c66affSColin Finck         } else {
96*c2c66affSColin Finck             _tprintf(_T("ERROR: failed to write data to file \"%s\"\n"), file_name);
97*c2c66affSColin Finck             _tprintf(_T("ERROR: ferror returned %d\n"), ferror(file));
98*c2c66affSColin Finck         }
99*c2c66affSColin Finck         fclose(file);
100*c2c66affSColin Finck     } else {
101*c2c66affSColin Finck         _tprintf(_T("ERROR: failed to open/create file \"%s\" for output\n"), file_name);
102*c2c66affSColin Finck         _tprintf(_T("ERROR: ferror returned %d\n"), ferror(file));
103*c2c66affSColin Finck     }
104*c2c66affSColin Finck 
105*c2c66affSColin Finck     file = _tfopen(file_name, _T("wb"));
106*c2c66affSColin Finck     if (file != NULL) {
107*c2c66affSColin Finck         error_code = ferror(file);
108*c2c66affSColin Finck         if (error_code) {
109*c2c66affSColin Finck              _tprintf(_T("ERROR: (%s) ferror returned %d\n"), file_name, error_code);
110*c2c66affSColin Finck         }
111*c2c66affSColin Finck         fclose(file);
112*c2c66affSColin Finck     } else {
113*c2c66affSColin Finck         _tprintf(_T("ERROR: (%s) failed to open file for truncating\n"), file_name);
114*c2c66affSColin Finck     }
115*c2c66affSColin Finck 
116*c2c66affSColin Finck     file = _tfopen(file_name, _T("rb"));
117*c2c66affSColin Finck     if (file != NULL) {
118*c2c66affSColin Finck         count = 0;
119*c2c66affSColin Finck         while ((ch = _fgettc(file)) != _TEOF) {
120*c2c66affSColin Finck             if (verbose_flagged) {
121*c2c66affSColin Finck                 _tprintf(_THEX_FORMAT, ch);
122*c2c66affSColin Finck             }
123*c2c66affSColin Finck             ++count;
124*c2c66affSColin Finck         }
125*c2c66affSColin Finck         error_code = ferror(file);
126*c2c66affSColin Finck         if (error_code) {
127*c2c66affSColin Finck              _tprintf(_T("ERROR: (%s) ferror returned %d after reading\n"), file_name, error_code);
128*c2c66affSColin Finck              perror("Read error");
129*c2c66affSColin Finck         }
130*c2c66affSColin Finck         fclose(file);
131*c2c66affSColin Finck     } else {
132*c2c66affSColin Finck         _tprintf(_T("ERROR: (%s) failed to open file for reading\n"), file_name);
133*c2c66affSColin Finck     }
134*c2c66affSColin Finck     if (count) {
135*c2c66affSColin Finck         result = TRUE;
136*c2c66affSColin Finck     }
137*c2c66affSColin Finck     return result;
138*c2c66affSColin Finck }
139*c2c66affSColin Finck 
create_output_file(TCHAR * file_name,TCHAR * file_mode,TCHAR * file_data)140*c2c66affSColin Finck static BOOL create_output_file(TCHAR* file_name, TCHAR* file_mode, TCHAR* file_data)
141*c2c66affSColin Finck {
142*c2c66affSColin Finck     BOOL result = FALSE;
143*c2c66affSColin Finck     FILE *file = _tfopen(file_name, file_mode);
144*c2c66affSColin Finck     if (file != NULL) {
145*c2c66affSColin Finck         if (_fputts(file_data, file) != _TEOF) {
146*c2c66affSColin Finck             result = TRUE;
147*c2c66affSColin Finck         } else {
148*c2c66affSColin Finck             _tprintf(_T("ERROR: failed to write data to file \"%s\"\n"), file_name);
149*c2c66affSColin Finck             _tprintf(_T("ERROR: ferror returned %d\n"), ferror(file));
150*c2c66affSColin Finck         }
151*c2c66affSColin Finck         fclose(file);
152*c2c66affSColin Finck     } else {
153*c2c66affSColin Finck         _tprintf(_T("ERROR: failed to open/create file \"%s\" for output\n"), file_name);
154*c2c66affSColin Finck         _tprintf(_T("ERROR: ferror returned %d\n"), ferror(file));
155*c2c66affSColin Finck     }
156*c2c66affSColin Finck     return result;
157*c2c66affSColin Finck }
158*c2c66affSColin Finck 
verify_output_file(TCHAR * file_name,TCHAR * file_mode,TCHAR * file_data)159*c2c66affSColin Finck static BOOL verify_output_file(TCHAR* file_name, TCHAR* file_mode, TCHAR* file_data)
160*c2c66affSColin Finck {
161*c2c66affSColin Finck     int error_code;
162*c2c66affSColin Finck     int offset = 0;
163*c2c66affSColin Finck     int line_num = 0;
164*c2c66affSColin Finck     BOOL result = FALSE;
165*c2c66affSColin Finck     BOOL error_flagged = FALSE;
166*c2c66affSColin Finck     FILE* file = _tfopen(file_name, file_mode);
167*c2c66affSColin Finck     if (file == NULL) {
168*c2c66affSColin Finck         _tprintf(_T("ERROR: (%s) Can't open file for reading\n"), file_name);
169*c2c66affSColin Finck         _tprintf(_T("ERROR: ferror returned %d\n"), ferror(file));
170*c2c66affSColin Finck         return FALSE;
171*c2c66affSColin Finck     } else if (status_flagged) {
172*c2c66affSColin Finck         _tprintf(_T("STATUS: (%s) opened file for reading\n"), file_name);
173*c2c66affSColin Finck     }
174*c2c66affSColin Finck     while (_fgetts(test_buffer, TEST_BUFFER_SIZE, file)) {
175*c2c66affSColin Finck         int length = _tcslen(test_buffer);
176*c2c66affSColin Finck         int req_len = _tcschr(file_data+offset, _T('\n')) - (file_data+offset) + 1;
177*c2c66affSColin Finck 
178*c2c66affSColin Finck         ++line_num;
179*c2c66affSColin Finck         if (length > req_len) {
180*c2c66affSColin Finck             _tprintf(_T("ERROR: read excess bytes from line %d, length %d, but expected %d\n"), line_num, length, req_len);
181*c2c66affSColin Finck             error_flagged = TRUE;
182*c2c66affSColin Finck             break;
183*c2c66affSColin Finck         }
184*c2c66affSColin Finck         if (length < req_len) {
185*c2c66affSColin Finck             _tprintf(_T("ERROR: read to few bytes from line %d, length %d, but expected %d\n"), line_num, length, req_len);
186*c2c66affSColin Finck             error_flagged = TRUE;
187*c2c66affSColin Finck             break;
188*c2c66affSColin Finck         }
189*c2c66affSColin Finck         if (status_flagged) {
190*c2c66affSColin Finck             _tprintf(_T("STATUS: Verifying %d bytes read from line %d\n"), length, line_num);
191*c2c66affSColin Finck         }
192*c2c66affSColin Finck         if (_tcsncmp(test_buffer, file_data+offset, length - 1) == 0) {
193*c2c66affSColin Finck             result = TRUE;
194*c2c66affSColin Finck         } else {
195*c2c66affSColin Finck             if (status_flagged) {
196*c2c66affSColin Finck                 int i;
197*c2c66affSColin Finck                 _tprintf(_T("WARNING: (%s) failed to verify file\n"), file_name);
198*c2c66affSColin Finck                 for (i = 0; i < length; i++) {
199*c2c66affSColin Finck                     if (file_data[offset+i] != test_buffer[i]) {
200*c2c66affSColin Finck                         _tprintf(_T("line %d, offset %d expected: 0x%04x found: 0x%04x\n"), line_num, i, (int)file_data[offset+i], (int)test_buffer[i]);
201*c2c66affSColin Finck                     }
202*c2c66affSColin Finck                 }
203*c2c66affSColin Finck                 _tprintf(_T("\n"));
204*c2c66affSColin Finck             } else {
205*c2c66affSColin Finck                 error_flagged = TRUE;
206*c2c66affSColin Finck             }
207*c2c66affSColin Finck         }
208*c2c66affSColin Finck         offset += length;
209*c2c66affSColin Finck     }
210*c2c66affSColin Finck     error_code = ferror(file);
211*c2c66affSColin Finck     if (error_code) {
212*c2c66affSColin Finck          _tprintf(_T("ERROR: (%s) ferror returned %d after reading\n"), file_name, error_code);
213*c2c66affSColin Finck          perror("Read error");
214*c2c66affSColin Finck     }
215*c2c66affSColin Finck     if (!line_num) {
216*c2c66affSColin Finck         _tprintf(_T("ERROR: (%s) failed to read from file\n"), file_name);
217*c2c66affSColin Finck     }
218*c2c66affSColin Finck     if (error_flagged == TRUE) {
219*c2c66affSColin Finck         _tprintf(_T("ERROR: (%s) failed to verify file\n"), file_name);
220*c2c66affSColin Finck         result = FALSE;
221*c2c66affSColin Finck     }
222*c2c66affSColin Finck     fclose(file);
223*c2c66affSColin Finck     return result;
224*c2c66affSColin Finck }
225*c2c66affSColin Finck 
create_test_file(TCHAR * file_name,TCHAR * write_mode,TCHAR * read_mode,TCHAR * file_data)226*c2c66affSColin Finck static int create_test_file(TCHAR* file_name, TCHAR* write_mode, TCHAR* read_mode, TCHAR* file_data)
227*c2c66affSColin Finck {
228*c2c66affSColin Finck     if (status_flagged) {
229*c2c66affSColin Finck         _tprintf(_T("STATUS: Attempting to create output file %s\n"), file_name);
230*c2c66affSColin Finck     }
231*c2c66affSColin Finck     if (create_output_file(file_name, write_mode, file_data)) {
232*c2c66affSColin Finck         if (status_flagged) {
233*c2c66affSColin Finck             _tprintf(_T("STATUS: Attempting to verify output file %s\n"), file_name);
234*c2c66affSColin Finck         }
235*c2c66affSColin Finck         if (verify_output_file(file_name, read_mode, file_data)) {
236*c2c66affSColin Finck             if (status_flagged) {
237*c2c66affSColin Finck                 _tprintf(_T("SUCCESS: %s verified ok\n"), file_name);
238*c2c66affSColin Finck             }
239*c2c66affSColin Finck         } else {
240*c2c66affSColin Finck             //_tprintf(_T("ERROR: failed to verify file %s\n"), file_name);
241*c2c66affSColin Finck             return 2;
242*c2c66affSColin Finck         }
243*c2c66affSColin Finck     } else {
244*c2c66affSColin Finck         _tprintf(_T("ERROR: failed to create file %s\n"), file_name);
245*c2c66affSColin Finck         return 1;
246*c2c66affSColin Finck     }
247*c2c66affSColin Finck     return 0;
248*c2c66affSColin Finck }
249*c2c66affSColin Finck 
check_file_size(TCHAR * file_name,TCHAR * file_mode,int expected)250*c2c66affSColin Finck static int check_file_size(TCHAR* file_name, TCHAR* file_mode, int expected)
251*c2c66affSColin Finck {
252*c2c66affSColin Finck     int count = 0;
253*c2c66affSColin Finck     FILE* file;
254*c2c66affSColin Finck     TCHAR ch;
255*c2c66affSColin Finck     int error_code;
256*c2c66affSColin Finck 
257*c2c66affSColin Finck     if (status_flagged) {
258*c2c66affSColin Finck         //_tprintf(_T("STATUS: (%s) checking for %d bytes in %s mode\n"), file_name, expected, _tcschr(file_mode, _T('b')) ? _T("binary") : _T("text"));
259*c2c66affSColin Finck         _tprintf(_T("STATUS: (%s) checking for %d bytes with mode %s\n"), file_name, expected, file_mode);
260*c2c66affSColin Finck     }
261*c2c66affSColin Finck     file = _tfopen(file_name, file_mode);
262*c2c66affSColin Finck     if (file == NULL) {
263*c2c66affSColin Finck         _tprintf(_T("ERROR: (%s) failed to open file for reading\n"), file_name);
264*c2c66affSColin Finck         return 1;
265*c2c66affSColin Finck     }
266*c2c66affSColin Finck     while ((ch = _fgettc(file)) != _TEOF) {
267*c2c66affSColin Finck         if (verbose_flagged) {
268*c2c66affSColin Finck             _tprintf(_THEX_FORMAT, ch);
269*c2c66affSColin Finck         }
270*c2c66affSColin Finck         ++count;
271*c2c66affSColin Finck     }
272*c2c66affSColin Finck     error_code = ferror(file);
273*c2c66affSColin Finck     if (error_code) {
274*c2c66affSColin Finck          _tprintf(_T("ERROR: (%s) ferror returned %d after reading\n"), file_name, error_code);
275*c2c66affSColin Finck          perror("Read error");
276*c2c66affSColin Finck     }
277*c2c66affSColin Finck 
278*c2c66affSColin Finck     if (verbose_flagged) {
279*c2c66affSColin Finck //        _puttc(_T('\n'), stdout);
280*c2c66affSColin Finck     }
281*c2c66affSColin Finck     fclose(file);
282*c2c66affSColin Finck     if (count == expected) {
283*c2c66affSColin Finck         if (status_flagged) {
284*c2c66affSColin Finck             _tprintf(_T("PASSED: (%s) read %d bytes\n"), file_name, count);
285*c2c66affSColin Finck         }
286*c2c66affSColin Finck     } else {
287*c2c66affSColin Finck         _tprintf(_T("FAILED: (%s) read %d bytes but expected %d using mode \"%s\"\n"), file_name, count, expected, file_mode);
288*c2c66affSColin Finck     }
289*c2c66affSColin Finck     return (count == expected) ? 0 : -1;
290*c2c66affSColin Finck }
291*c2c66affSColin Finck 
test_console_io(void)292*c2c66affSColin Finck static int test_console_io(void)
293*c2c66affSColin Finck {
294*c2c66affSColin Finck     TCHAR buffer[81];
295*c2c66affSColin Finck     TCHAR ch;
296*c2c66affSColin Finck     int i, j;
297*c2c66affSColin Finck 
298*c2c66affSColin Finck     _tprintf(_T("Enter a line for echoing:\n"));
299*c2c66affSColin Finck 
300*c2c66affSColin Finck     //for (i = 0; (i < 80) && ((ch = _gettchar()) != _TEOF) && (ch != _T('\n')); i++) {
301*c2c66affSColin Finck     for (i = 0; (i < 80) && ((ch = _gettc(stdin)) != _TEOF) && (ch != _T('\n')); i++) {
302*c2c66affSColin Finck         buffer[i] = (TCHAR)ch;
303*c2c66affSColin Finck     }
304*c2c66affSColin Finck     buffer[i] = _T('\0');
305*c2c66affSColin Finck     for (j = 0; j < i; j++) {
306*c2c66affSColin Finck         _puttc(buffer[j], stdout);
307*c2c66affSColin Finck     }
308*c2c66affSColin Finck     _puttc(_T('\n'), stdout);
309*c2c66affSColin Finck     _tprintf(_T("%s\n"), buffer);
310*c2c66affSColin Finck     return 0;
311*c2c66affSColin Finck }
312*c2c66affSColin Finck 
test_console_getchar(void)313*c2c66affSColin Finck static int test_console_getchar(void)
314*c2c66affSColin Finck {
315*c2c66affSColin Finck     int result = 0;
316*c2c66affSColin Finck     TCHAR ch;
317*c2c66affSColin Finck 
318*c2c66affSColin Finck     _tprintf(_T("Enter lines for dumping or <ctrl-z><nl> to finish:\n"));
319*c2c66affSColin Finck 
320*c2c66affSColin Finck     //while ((ch = _gettchar()) != _TEOF) {
321*c2c66affSColin Finck     while ((ch = _gettc(stdin)) != _TEOF) {
322*c2c66affSColin Finck         _tprintf(_THEX_FORMAT, ch);
323*c2c66affSColin Finck         //printf("0x%04x ", ch);
324*c2c66affSColin Finck     }
325*c2c66affSColin Finck     return result;
326*c2c66affSColin Finck }
327*c2c66affSColin Finck 
test_console_putch(void)328*c2c66affSColin Finck static int test_console_putch(void)
329*c2c66affSColin Finck {
330*c2c66affSColin Finck     int result = 0;
331*c2c66affSColin Finck 
332*c2c66affSColin Finck     _putch('1');
333*c2c66affSColin Finck     _putch('@');
334*c2c66affSColin Finck     _putch('3');
335*c2c66affSColin Finck     _putch(':');
336*c2c66affSColin Finck     _putch('\n');
337*c2c66affSColin Finck     _putch('a');
338*c2c66affSColin Finck     _putch('B');
339*c2c66affSColin Finck     _putch('c');
340*c2c66affSColin Finck     _putch(':');
341*c2c66affSColin Finck     _putch('\n');
342*c2c66affSColin Finck     return result;
343*c2c66affSColin Finck }
344*c2c66affSColin Finck 
test_unlink_files(void)345*c2c66affSColin Finck static int test_unlink_files(void)
346*c2c66affSColin Finck {
347*c2c66affSColin Finck     int result = 0;
348*c2c66affSColin Finck 
349*c2c66affSColin Finck     //printf("sizeof dos_data: %d\n", sizeof(dos_data));
350*c2c66affSColin Finck     //printf("sizeof nix_data: %d\n", sizeof(nix_data));
351*c2c66affSColin Finck 
352*c2c66affSColin Finck     result |= _tunlink(_T("binary.dos"));
353*c2c66affSColin Finck     result |= _tunlink(_T("binary.nix"));
354*c2c66affSColin Finck     result |= _tunlink(_T("text.dos"));
355*c2c66affSColin Finck     result |= _tunlink(_T("text.nix"));
356*c2c66affSColin Finck     return result;
357*c2c66affSColin Finck }
358*c2c66affSColin Finck 
test_text_fileio(TCHAR * file_name,TCHAR * file_data,int tsize,int bsize)359*c2c66affSColin Finck static int test_text_fileio(TCHAR* file_name, TCHAR* file_data, int tsize, int bsize)
360*c2c66affSColin Finck {
361*c2c66affSColin Finck     int result = 0;
362*c2c66affSColin Finck 
363*c2c66affSColin Finck     result = create_test_file(file_name, _T("w"), _T("r"), file_data);
364*c2c66affSColin Finck     result = check_file_size(file_name, _T("r"), tsize);
365*c2c66affSColin Finck     result = check_file_size(file_name, _T("rb"), bsize);
366*c2c66affSColin Finck     return result;
367*c2c66affSColin Finck }
368*c2c66affSColin Finck 
test_binary_fileio(TCHAR * file_name,TCHAR * file_data,int tsize,int bsize)369*c2c66affSColin Finck static int test_binary_fileio(TCHAR* file_name, TCHAR* file_data, int tsize, int bsize)
370*c2c66affSColin Finck {
371*c2c66affSColin Finck     int result = 0;
372*c2c66affSColin Finck 
373*c2c66affSColin Finck     result = create_test_file(file_name, _T("wb"), _T("rb"), file_data);
374*c2c66affSColin Finck     result = check_file_size(file_name, _T("r"), tsize);
375*c2c66affSColin Finck     result = check_file_size(file_name, _T("rb"), bsize);
376*c2c66affSColin Finck     return result;
377*c2c66affSColin Finck }
378*c2c66affSColin Finck 
test_files(int test_num,char * type)379*c2c66affSColin Finck static int test_files(int test_num, char* type)
380*c2c66affSColin Finck {
381*c2c66affSColin Finck     int result = 0;
382*c2c66affSColin Finck 
383*c2c66affSColin Finck     printf("performing test: %d (%s)\n", test_num, type);
384*c2c66affSColin Finck 
385*c2c66affSColin Finck 
386*c2c66affSColin Finck     if (test_file_truncate(_T("zerosize.foo"))) {
387*c2c66affSColin Finck         printf("System unable to truncate files yet, unlinking:\n");
388*c2c66affSColin Finck         test_unlink_files();
389*c2c66affSColin Finck     }
390*c2c66affSColin Finck 
391*c2c66affSColin Finck     switch (test_num) {
392*c2c66affSColin Finck     case 1:
393*c2c66affSColin Finck         result = test_text_fileio(_T("text.dos"), dos_data, 166, TEST_B1_FILE_SIZE);
394*c2c66affSColin Finck         break;
395*c2c66affSColin Finck     case 2:
396*c2c66affSColin Finck         result = test_binary_fileio(_T("binary.dos"), dos_data, TEST_B2_FILE_SIZE, 166);
397*c2c66affSColin Finck         break;
398*c2c66affSColin Finck     case 3:
399*c2c66affSColin Finck         result = test_text_fileio(_T("text.nix"), nix_data, 162, TEST_B3_FILE_SIZE);
400*c2c66affSColin Finck         break;
401*c2c66affSColin Finck     case 4:
402*c2c66affSColin Finck         result = test_binary_fileio(_T("binary.nix"), nix_data, TEST_B4_FILE_SIZE, 162);
403*c2c66affSColin Finck         break;
404*c2c66affSColin Finck     case 5:
405*c2c66affSColin Finck         result = test_console_io();
406*c2c66affSColin Finck         break;
407*c2c66affSColin Finck     case 6:
408*c2c66affSColin Finck         result = test_console_getchar();
409*c2c66affSColin Finck         break;
410*c2c66affSColin Finck     case 7:
411*c2c66affSColin Finck         result = test_console_putch();
412*c2c66affSColin Finck         break;
413*c2c66affSColin Finck     case -1:
414*c2c66affSColin Finck         result = test_unlink_files();
415*c2c66affSColin Finck         break;
416*c2c66affSColin Finck     default:
417*c2c66affSColin Finck         _tprintf(_T("no test number selected\n"));
418*c2c66affSColin Finck         break;
419*c2c66affSColin Finck     }
420*c2c66affSColin Finck     return result;
421*c2c66affSColin Finck }
422