From 218703bf94bedcbc0fca4223d29ef6612b8c409d Mon Sep 17 00:00:00 2001 From: Robert Dickenson Date: Sat, 14 Dec 2002 14:42:01 +0000 Subject: [PATCH] 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 --- .../apps/testsets/msvcrt/fileio/_tfileio.c | 81 ++----------------- reactos/apps/testsets/msvcrt/fileio/fileio.c | 2 +- reactos/apps/testsets/msvcrt/fileio/main.c | 65 +-------------- reactos/apps/testsets/msvcrt/fileio/makefile | 6 +- reactos/apps/testsets/msvcrt/fileio/wfileio.c | 2 +- 5 files changed, 15 insertions(+), 141 deletions(-) diff --git a/reactos/apps/testsets/msvcrt/fileio/_tfileio.c b/reactos/apps/testsets/msvcrt/fileio/_tfileio.c index 1de03040438..68700356d59 100644 --- a/reactos/apps/testsets/msvcrt/fileio/_tfileio.c +++ b/reactos/apps/testsets/msvcrt/fileio/_tfileio.c @@ -49,7 +49,6 @@ extern BOOL verbose_flagged; extern BOOL status_flagged; -//extern 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*/ - - - static BOOL create_output_file(TCHAR* file_name, TCHAR* file_mode, TCHAR* file_data) { BOOL result = FALSE; FILE *file = _tfopen(file_name, file_mode); if (file != NULL) { -#ifndef _NO_NEW_DEPENDS_ if (_fputts(file_data, file) != _TEOF) { result = TRUE; } else { _tprintf(_T("ERROR: failed to write data to file \"%s\"\n"), file_name); _tprintf(_T("ERROR: ferror returned %d\n"), ferror(file)); } -#endif fclose(file); } else { _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) { _tprintf(_T("STATUS: (%s) opened file for reading\n"), file_name); } -#ifndef _NO_NEW_DEPENDS_ while (_fgetts(test_buffer, TEST_BUFFER_SIZE, file)) { int length = _tcslen(test_buffer); 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; 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) { _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); result = FALSE; } -#endif fclose(file); 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) { -#ifndef _NO_NEW_DEPENDS_ TCHAR buffer[81]; TCHAR ch; int i, j; - //printf("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++) { @@ -250,17 +245,14 @@ static int test_console_io(void) } _puttc(_T('\n'), stdout); _tprintf(_T("%s\n"), buffer); -#endif return 0; } static int test_console_getchar(void) { int result = 0; -#ifndef _NO_NEW_DEPENDS_ TCHAR ch; - //printf("Enter lines for dumping or to finish:\n"); _tprintf(_T("Enter lines for dumping or to finish:\n")); //while ((ch = _gettchar()) != _TEOF) { @@ -268,14 +260,12 @@ static int test_console_getchar(void) _tprintf(_THEX_FORMAT, ch); //printf("0x%04x ", ch); } -#endif return result; } static int test_console_putch(void) { int result = 0; - //TCHAR ch; _putch('1'); _putch('@'); @@ -287,8 +277,6 @@ static int test_console_putch(void) _putch('c'); _putch(':'); _putch('\n'); - - return result; } @@ -363,62 +351,3 @@ static int test_files(int test_num, char* type) } 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 diff --git a/reactos/apps/testsets/msvcrt/fileio/fileio.c b/reactos/apps/testsets/msvcrt/fileio/fileio.c index 743d98861e2..ab29300e05e 100644 --- a/reactos/apps/testsets/msvcrt/fileio/fileio.c +++ b/reactos/apps/testsets/msvcrt/fileio/fileio.c @@ -25,7 +25,7 @@ #include "_tfileio.c" -int test_ansi_files(int test_num) +int run_ansi_tests(int test_num) { return test_files(test_num, "ANSI"); } diff --git a/reactos/apps/testsets/msvcrt/fileio/main.c b/reactos/apps/testsets/msvcrt/fileio/main.c index 50022dfb762..64f5476d859 100644 --- a/reactos/apps/testsets/msvcrt/fileio/main.c +++ b/reactos/apps/testsets/msvcrt/fileio/main.c @@ -89,7 +89,6 @@ int __cdecl main(int argc, char* argv[]) //if (test_num < 0 } } -#if 1 for (i = test_num; i <= test_num; i++) { if (!test_num) { test_num = 4; @@ -97,84 +96,28 @@ int __cdecl main(int argc, char* argv[]) } switch (version) { case 1: - result = test_ansi_files(i); + result = run_ansi_tests(i); break; case 2: - result = test_unicode_files(i); + result = run_unicode_tests(i); break; default: - result = test_ansi_files(i); - result = test_unicode_files(i); + result = run_ansi_tests(i); + result = run_unicode_tests(i); 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"); 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__ 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) { 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; } diff --git a/reactos/apps/testsets/msvcrt/fileio/makefile b/reactos/apps/testsets/msvcrt/fileio/makefile index f8eb88674a9..e0a22da9ebc 100644 --- a/reactos/apps/testsets/msvcrt/fileio/makefile +++ b/reactos/apps/testsets/msvcrt/fileio/makefile @@ -3,6 +3,8 @@ PATH_TO_TOP = ../../../.. +TEST_ROOT = $(PATH_TO_TOP)/apps/testsets/test + TARGET_NORC = yes TARGET_TYPE = program @@ -11,8 +13,8 @@ TARGET_APPTYPE = console TARGET_NAME = fileio -#TARGET_CFLAGS = -DDBG -DUNICODE -D_UNICODE -TARGET_CFLAGS = -DDBG +#TARGET_CFLAGS = -I$(TEST_ROOT) -DDBG -DUNICODE -D_UNICODE +TARGET_CFLAGS = -I$(TEST_ROOT) -DDBG TARGET_SDKLIBS = ntdll.a kernel32.a diff --git a/reactos/apps/testsets/msvcrt/fileio/wfileio.c b/reactos/apps/testsets/msvcrt/fileio/wfileio.c index 3b7ca4a9d56..5985a8aa238 100644 --- a/reactos/apps/testsets/msvcrt/fileio/wfileio.c +++ b/reactos/apps/testsets/msvcrt/fileio/wfileio.c @@ -25,7 +25,7 @@ #include "_tfileio.c" -int test_unicode_files(int test_num) +int run_unicode_tests(int test_num) { return test_files(test_num, "UNICODE"); }