Updated test program.

Successfully reads and writes short test buffer using stream I/O, both A and W versions.
Tests for correct handling of /r/n in text modes however nothing as yet for multi-bytes.
If you rebuild me watch out for the dependacy _tfileio.c which doesn't have an entry in the makefile.

svn path=/trunk/; revision=3874
This commit is contained in:
Robert Dickenson 2002-12-14 14:42:01 +00:00
parent 4e2f492dc0
commit 218703bf94
5 changed files with 15 additions and 141 deletions

View file

@ -49,7 +49,6 @@
extern BOOL verbose_flagged; extern BOOL verbose_flagged;
extern BOOL status_flagged; extern BOOL status_flagged;
//extern TCHAR test_buffer[TEST_BUFFER_SIZE];
static TCHAR test_buffer[TEST_BUFFER_SIZE]; static TCHAR test_buffer[TEST_BUFFER_SIZE];
@ -76,22 +75,17 @@ static TCHAR nix_data[] = _T("line1: this is a bunch of readable text.\n")\
#endif /*UNICODE*/ #endif /*UNICODE*/
static BOOL create_output_file(TCHAR* file_name, TCHAR* file_mode, TCHAR* file_data) static BOOL create_output_file(TCHAR* file_name, TCHAR* file_mode, TCHAR* file_data)
{ {
BOOL result = FALSE; BOOL result = FALSE;
FILE *file = _tfopen(file_name, file_mode); FILE *file = _tfopen(file_name, file_mode);
if (file != NULL) { if (file != NULL) {
#ifndef _NO_NEW_DEPENDS_
if (_fputts(file_data, file) != _TEOF) { if (_fputts(file_data, file) != _TEOF) {
result = TRUE; result = TRUE;
} else { } else {
_tprintf(_T("ERROR: failed to write data to file \"%s\"\n"), file_name); _tprintf(_T("ERROR: failed to write data to file \"%s\"\n"), file_name);
_tprintf(_T("ERROR: ferror returned %d\n"), ferror(file)); _tprintf(_T("ERROR: ferror returned %d\n"), ferror(file));
} }
#endif
fclose(file); fclose(file);
} else { } else {
_tprintf(_T("ERROR: failed to open/create file \"%s\" for output\n"), file_name); _tprintf(_T("ERROR: failed to open/create file \"%s\" for output\n"), file_name);
@ -115,7 +109,6 @@ static BOOL verify_output_file(TCHAR* file_name, TCHAR* file_mode, TCHAR* file_d
} else if (status_flagged) { } else if (status_flagged) {
_tprintf(_T("STATUS: (%s) opened file for reading\n"), file_name); _tprintf(_T("STATUS: (%s) opened file for reading\n"), file_name);
} }
#ifndef _NO_NEW_DEPENDS_
while (_fgetts(test_buffer, TEST_BUFFER_SIZE, file)) { while (_fgetts(test_buffer, TEST_BUFFER_SIZE, file)) {
int length = _tcslen(test_buffer); int length = _tcslen(test_buffer);
int req_len = _tcschr(file_data+offset, _T('\n')) - (file_data+offset) + 1; int req_len = _tcschr(file_data+offset, _T('\n')) - (file_data+offset) + 1;
@ -126,6 +119,11 @@ static BOOL verify_output_file(TCHAR* file_name, TCHAR* file_mode, TCHAR* file_d
error_flagged = TRUE; error_flagged = TRUE;
break; break;
} }
if (length < req_len) {
_tprintf(_T("ERROR: read to few bytes from line %d, length %d, but expected %d\n"), line_num, length, req_len);
error_flagged = TRUE;
break;
}
if (status_flagged) { if (status_flagged) {
_tprintf(_T("STATUS: Verifying %d bytes read from line %d\n"), length, line_num); _tprintf(_T("STATUS: Verifying %d bytes read from line %d\n"), length, line_num);
} }
@ -159,7 +157,6 @@ static BOOL verify_output_file(TCHAR* file_name, TCHAR* file_mode, TCHAR* file_d
_tprintf(_T("ERROR: (%s) failed to verify file\n"), file_name); _tprintf(_T("ERROR: (%s) failed to verify file\n"), file_name);
result = FALSE; result = FALSE;
} }
#endif
fclose(file); fclose(file);
return result; return result;
} }
@ -232,12 +229,10 @@ static int check_file_size(TCHAR* file_name, TCHAR* file_mode, int expected)
static int test_console_io(void) static int test_console_io(void)
{ {
#ifndef _NO_NEW_DEPENDS_
TCHAR buffer[81]; TCHAR buffer[81];
TCHAR ch; TCHAR ch;
int i, j; int i, j;
//printf("Enter a line for echoing:\n");
_tprintf(_T("Enter a line for echoing:\n")); _tprintf(_T("Enter a line for echoing:\n"));
//for (i = 0; (i < 80) && ((ch = _gettchar()) != _TEOF) && (ch != _T('\n')); i++) { //for (i = 0; (i < 80) && ((ch = _gettchar()) != _TEOF) && (ch != _T('\n')); i++) {
@ -250,17 +245,14 @@ static int test_console_io(void)
} }
_puttc(_T('\n'), stdout); _puttc(_T('\n'), stdout);
_tprintf(_T("%s\n"), buffer); _tprintf(_T("%s\n"), buffer);
#endif
return 0; return 0;
} }
static int test_console_getchar(void) static int test_console_getchar(void)
{ {
int result = 0; int result = 0;
#ifndef _NO_NEW_DEPENDS_
TCHAR ch; TCHAR ch;
//printf("Enter lines for dumping or <ctrl-z><nl> to finish:\n");
_tprintf(_T("Enter lines for dumping or <ctrl-z><nl> to finish:\n")); _tprintf(_T("Enter lines for dumping or <ctrl-z><nl> to finish:\n"));
//while ((ch = _gettchar()) != _TEOF) { //while ((ch = _gettchar()) != _TEOF) {
@ -268,14 +260,12 @@ static int test_console_getchar(void)
_tprintf(_THEX_FORMAT, ch); _tprintf(_THEX_FORMAT, ch);
//printf("0x%04x ", ch); //printf("0x%04x ", ch);
} }
#endif
return result; return result;
} }
static int test_console_putch(void) static int test_console_putch(void)
{ {
int result = 0; int result = 0;
//TCHAR ch;
_putch('1'); _putch('1');
_putch('@'); _putch('@');
@ -287,8 +277,6 @@ static int test_console_putch(void)
_putch('c'); _putch('c');
_putch(':'); _putch(':');
_putch('\n'); _putch('\n');
return result; return result;
} }
@ -363,62 +351,3 @@ static int test_files(int test_num, char* type)
} }
return result; return result;
} }
#if 1
#else
static int test_files(int test_num, char* type)
{
int result = 0;
printf("performing test: %d (%s)\n", test_num, type);
switch (test_num) {
case 1:
result = create_test_file(_T("text.dos"), _T("w"), _T("r"), dos_data);
break;
case 2:
result = create_test_file(_T("binary.dos"), _T("wb"), _T("rb"), dos_data);
break;
case 3:
result = create_test_file(_T("text.nix"), _T("w"), _T("r"), nix_data);
break;
case 4:
result = create_test_file(_T("binary.nix"), _T("wb"), _T("rb"), nix_data);
break;
case 5:
result = check_file_size(_T("text.dos"), _T("r"), 166);
result = check_file_size(_T("text.dos"), _T("rb"), TEST_B1_FILE_SIZE);
break;
case 6:
result = check_file_size(_T("binary.dos"), _T("r"), TEST_B2_FILE_SIZE);
result = check_file_size(_T("binary.dos"), _T("rb"), 166);
break;
case 7:
result = check_file_size(_T("text.nix"), _T("r"), 162);
result = check_file_size(_T("text.nix"), _T("rb"), TEST_B3_FILE_SIZE);
break;
case 8:
result = check_file_size(_T("binary.nix"), _T("r"), TEST_B4_FILE_SIZE);
result = check_file_size(_T("binary.nix"), _T("rb"), 162);
break;
case 9:
result = test_console_io();
break;
case 0:
result = test_console_getchar();
break;
case -1:
result = test_unlink_files();
break;
default:
_tprintf(_T("no test number selected\n"));
break;
}
return result;
}
#endif

View file

@ -25,7 +25,7 @@
#include "_tfileio.c" #include "_tfileio.c"
int test_ansi_files(int test_num) int run_ansi_tests(int test_num)
{ {
return test_files(test_num, "ANSI"); return test_files(test_num, "ANSI");
} }

View file

@ -89,7 +89,6 @@ int __cdecl main(int argc, char* argv[])
//if (test_num < 0 //if (test_num < 0
} }
} }
#if 1
for (i = test_num; i <= test_num; i++) { for (i = test_num; i <= test_num; i++) {
if (!test_num) { if (!test_num) {
test_num = 4; test_num = 4;
@ -97,84 +96,28 @@ int __cdecl main(int argc, char* argv[])
} }
switch (version) { switch (version) {
case 1: case 1:
result = test_ansi_files(i); result = run_ansi_tests(i);
break; break;
case 2: case 2:
result = test_unicode_files(i); result = run_unicode_tests(i);
break; break;
default: default:
result = test_ansi_files(i); result = run_ansi_tests(i);
result = test_unicode_files(i); result = run_unicode_tests(i);
break; break;
} }
} }
#else
if (test_num == 0) {
for (i = 1; i <= 4; i++) {
result = test_ansi_files(i);
result = test_unicode_files(i);
}
} else {
switch (version) {
case 1:
//result = test_ansi_files(test_num);
while (i <= test_num) {
result = test_ansi_files(i);
}
break;
case 2:
//result = test_unicode_files(test_num);
while (i <= test_num) {
result = test_unicode_files(i);
}
break;
default:
while (i <= test_num) {
result = test_ansi_files(i);
result = test_unicode_files(i);
++i;
}
break;
}
}
#endif
printf("finished\n"); printf("finished\n");
return result; return result;
} }
/*
ANSI:
all tests passing
UNICODE:
writing binary files short one byte. ie. odd number file lengths.
reading text files returns one extra byte.
*/
#ifndef __GNUC__ #ifndef __GNUC__
char* args[] = { "fileio.exe", "0", "unicode", "verbose"}; char* args[] = { "fileio.exe", "0", "unicode", "verbose"};
char* args1[] = { "fileio.exe", "1", "unicode" };
char* args2[] = { "fileio.exe", "2", "unicode" };
char* args3[] = { "fileio.exe", "3", "unicode" };
char* args4[] = { "fileio.exe", "4", "unicode" };
int __cdecl mainCRTStartup(void) int __cdecl mainCRTStartup(void)
{ {
main(2, args); main(2, args);
#if 0
//#if 1
main(2, args1);
main(2, args2);
main(2, args3);
main(2, args4);
//#else
main(3, args1);
main(3, args2);
main(3, args3);
main(3, args4);
//#endif
#endif
return 0; return 0;
} }

View file

@ -3,6 +3,8 @@
PATH_TO_TOP = ../../../.. PATH_TO_TOP = ../../../..
TEST_ROOT = $(PATH_TO_TOP)/apps/testsets/test
TARGET_NORC = yes TARGET_NORC = yes
TARGET_TYPE = program TARGET_TYPE = program
@ -11,8 +13,8 @@ TARGET_APPTYPE = console
TARGET_NAME = fileio TARGET_NAME = fileio
#TARGET_CFLAGS = -DDBG -DUNICODE -D_UNICODE #TARGET_CFLAGS = -I$(TEST_ROOT) -DDBG -DUNICODE -D_UNICODE
TARGET_CFLAGS = -DDBG TARGET_CFLAGS = -I$(TEST_ROOT) -DDBG
TARGET_SDKLIBS = ntdll.a kernel32.a TARGET_SDKLIBS = ntdll.a kernel32.a

View file

@ -25,7 +25,7 @@
#include "_tfileio.c" #include "_tfileio.c"
int test_unicode_files(int test_num) int run_unicode_tests(int test_num)
{ {
return test_files(test_num, "UNICODE"); return test_files(test_num, "UNICODE");
} }