2 * ReactOS test program -
6 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #define WIN32_LEAN_AND_MEAN
32 #define _tfopen _wfopen
33 #define _tunlink _wunlink
35 #define _gettchar getwchar
36 #define _puttchar putwchar
37 #define _THEX_FORMAT _T("0x%04x ")
38 #define TEST_B1_FILE_SIZE 85
39 #define TEST_B2_FILE_SIZE 332
40 #define TEST_B3_FILE_SIZE 83
41 #define TEST_B4_FILE_SIZE 324
46 #define _tunlink _unlink
48 #define _gettchar getchar
49 #define _puttchar putchar
50 #define _THEX_FORMAT "0x%02x "
51 #define TEST_B1_FILE_SIZE 170
52 #define TEST_B2_FILE_SIZE 162
53 #define TEST_B3_FILE_SIZE 166
54 #define TEST_B4_FILE_SIZE 162
59 #define TEST_BUFFER_SIZE 200
61 extern BOOL verbose_flagged
;
62 extern TCHAR test_buffer
[TEST_BUFFER_SIZE
];
65 static TCHAR dos_data
[] = _T("line1: this is a bunch of readable text.\r\n")\
66 _T("line2: some more printable text and punctuation !@#$%^&*()\r\n")\
67 _T("line3: followed up with some numerals 1234567890\r\n")\
68 _T("line4: done.\r\n");
70 static TCHAR nix_data
[] = _T("line1: this is a bunch of readable text.\n")\
71 _T("line2: some more printable text and punctuation !@#$%^&*()\n")\
72 _T("line3: followed up with some numerals 1234567890\n")\
76 static BOOL
create_output_file(TCHAR
* file_name
, TCHAR
* file_mode
, TCHAR
* file_data
)
79 FILE *file
= _tfopen(file_name
, file_mode
);
81 _tprintf(_T("ERROR: Can't open file \"%s\" for writing\n"), file_name
);
84 if (_fputts(file_data
, file
) != _TEOF
) {
87 _tprintf(_T("ERROR: failed to write to file \"%s\"\n"), file_name
);
93 static BOOL
verify_output_file(TCHAR
* file_name
, TCHAR
* file_mode
, TCHAR
* file_data
)
98 FILE* file
= _tfopen(file_name
, file_mode
);
100 _tprintf(_T("ERROR: Can't open file \"%s\" for reading\n"), file_name
);
103 while (_fgetts(test_buffer
, TEST_BUFFER_SIZE
, file
)) {
104 int length
= _tcslen(test_buffer
);
105 _tprintf(_T("STATUS: Verifying %d bytes read from line %d\n"), length
, ++line_num
);
106 if (_tcsncmp(test_buffer
, file_data
+offset
, length
) == 0) {
109 _tprintf(_T("WARNING: failed to verify data from file \"%s\"\n"), file_name
);
114 _tprintf(_T("ERROR: failed to read from file \"%s\"\n"), file_name
);
120 static int test_A(TCHAR
* file_name
, TCHAR
* write_mode
, TCHAR
* read_mode
, TCHAR
* file_data
)
122 _tprintf(_T("STATUS: Attempting to create output file %s\n"), file_name
);
123 if (create_output_file(file_name
, write_mode
, file_data
)) {
124 _tprintf(_T("STATUS: Attempting to verify output file %s\n"), file_name
);
125 if (verify_output_file(file_name
, read_mode
, file_data
)) {
126 _tprintf(_T("SUCCESS: %s verified ok\n"), file_name
);
128 _tprintf(_T("ERROR: Can't verify output file %s\n"), file_name
);
132 _tprintf(_T("ERROR: Can't create output file %s\n"), file_name
);
138 static int test_B(TCHAR
* file_name
, TCHAR
* file_mode
, int expected
)
144 _tprintf(_T("STATUS: checking %s in %s mode\n"), file_name
, _tcschr(file_mode
, _T('b')) ? _T("binary") : _T("text"));
146 file
= _tfopen(file_name
, file_mode
);
148 _tprintf(_T("ERROR: Can't open file \"%s\" for reading\n"), file_name
);
151 while ((ch
= _fgettc(file
)) != _TEOF
) {
152 if (verbose_flagged
) {
153 _tprintf(_THEX_FORMAT
, ch
);
157 if (verbose_flagged
) {
161 if (count
== expected
) {
162 _tprintf(_T("PASSED: read %d bytes from %s as expected\n"), count
, file_name
);
164 _tprintf(_T("ERROR: read %d bytes from %s, expected %d\n"), count
, file_name
, expected
);
169 static int test_C(void)
175 _tprintf(_T("Enter a line: "));
176 for (i
= 0; (i
< 80) && ((ch
= _gettchar()) != _TEOF
) && (ch
!= _T('\n')); i
++) {
177 buffer
[i
] = (TCHAR
)ch
;
179 buffer
[i
] = _T('\0');
180 _tprintf(_T("%s\n"), buffer
);
184 static int test_D(void)
189 while ((ch
= _gettchar()) != _TEOF
) {
190 _tprintf(_THEX_FORMAT
, ch
);
195 static int clean_files(void)
199 result
|= _tunlink(_T("binary.dos"));
200 result
|= _tunlink(_T("binary.nix"));
201 result
|= _tunlink(_T("text.dos"));
202 result
|= _tunlink(_T("text.nix"));
206 static int test_files(int test_num
, char* type
)
210 printf("performing test: %d (%s)\n", test_num
, type
);
214 result
= test_A(_T("text.dos"), _T("w"), _T("r"), dos_data
);
217 result
= test_A(_T("binary.dos"), _T("wb"), _T("rb"), dos_data
);
220 result
= test_A(_T("text.nix"), _T("w"), _T("r"), nix_data
);
223 result
= test_A(_T("binary.nix"), _T("wb"), _T("rb"), nix_data
);
227 result
= test_B(_T("text.dos"), _T("r"), 166);
228 result
= test_B(_T("text.dos"), _T("rb"), TEST_B1_FILE_SIZE
);
231 result
= test_B(_T("binary.dos"), _T("r"), TEST_B2_FILE_SIZE
);
232 result
= test_B(_T("binary.dos"), _T("rb"), 166);
235 result
= test_B(_T("text.nix"), _T("r"), 162);
236 result
= test_B(_T("text.nix"), _T("rb"), TEST_B3_FILE_SIZE
);
239 result
= test_B(_T("binary.nix"), _T("r"), TEST_B4_FILE_SIZE
);
240 result
= test_B(_T("binary.nix"), _T("rb"), 162);
250 result
= clean_files();
253 _tprintf(_T("no test number selected\n"));