Improved unicode fileio support.
[reactos.git] / reactos / apps / testsets / msvcrt / fileio / main.c
1 /*
2 * ReactOS test program -
3 *
4 * main.c
5 *
6 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
7 *
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.
12 *
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.
17 *
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.
21 */
22
23 #define WIN32_LEAN_AND_MEAN
24 #include <windows.h>
25 #include <tchar.h>
26 #include <wchar.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29
30 #include "main.h"
31
32
33 #define VERSION 1
34
35 #ifdef UNICODE
36 #define TARGET "UNICODE"
37 #else
38 #define TARGET "MBCS"
39 #endif
40
41 BOOL verbose_flagged = 0;
42 BOOL status_flagged = 0;
43
44 int usage(char* argv0)
45 {
46 printf("USAGE: %s test_id [unicode]|[ansi] [clean]|[status][verbose]\n", argv0);
47 printf("\tWhere test_id is one of:\n");
48 printf("\t0 - (default) regression mode, run tests 1-4 displaying failures only\n");
49 printf("\t1 - Write DOS style eol data to file in text mode (text.dos)\n");
50 printf("\t2 - Write NIX style eol data to file in binary mode (binary.dos)\n");
51 printf("\t3 - Write DOS style eol data to file in text mode (text.nix)\n");
52 printf("\t4 - Write NIX style eol data to file in binary mode (binary.nix)\n");
53 printf("\t5 - Echo console line input\n");
54 printf("\t6 - Dump console line input in hex format\n");
55 printf("\t7 - The source code is your friend\n");
56 printf("\t[unicode] - perform tests using UNICODE versions of library functions\n");
57 printf("\t[ansi] - perform tests using ANSI versions of library functions\n");
58 printf("\t If neither unicode or ansi is specified build default is used\n");
59 printf("\t[clean] - delete all temporary test output files\n");
60 printf("\t[status] - enable extra status display while running\n");
61 printf("\t[verbose] - enable verbose output when running\n");
62 return 0;
63 }
64
65 int __cdecl main(int argc, char* argv[])
66 {
67 int test_num = 0;
68 int version = 0;
69 int result = 0;
70 int i = 0;
71
72 printf("%s test application - build %03d (default: %s)\n", argv[0], VERSION, TARGET);
73 if (argc < 2) {
74 return usage(argv[0]);
75 }
76 for (i = 1; i < argc; i++) {
77 if (strstr(argv[i], "ansi") || strstr(argv[i], "ANSI")) {
78 version = 1;
79 } else if (strstr(argv[i], "unicode") || strstr(argv[i], "UNICODE")) {
80 version = 2;
81 } else if (strstr(argv[i], "clean") || strstr(argv[i], "CLEAN")) {
82 test_num = -1;
83 } else if (strstr(argv[i], "verbose") || strstr(argv[i], "VERBOSE")) {
84 verbose_flagged = 1;
85 } else if (strstr(argv[i], "status") || strstr(argv[i], "STATUS")) {
86 status_flagged = 1;
87 } else {
88 test_num = atoi(argv[1]);
89 //if (test_num < 0
90 }
91 }
92 #if 1
93 for (i = test_num; i <= test_num; i++) {
94 if (!test_num) {
95 test_num = 4;
96 i = 1;
97 }
98 switch (version) {
99 case 1:
100 result = test_ansi_files(i);
101 break;
102 case 2:
103 result = test_unicode_files(i);
104 break;
105 default:
106 result = test_ansi_files(i);
107 result = test_unicode_files(i);
108 break;
109 }
110 }
111 #else
112 if (test_num == 0) {
113 for (i = 1; i <= 4; i++) {
114 result = test_ansi_files(i);
115 result = test_unicode_files(i);
116 }
117 } else {
118 switch (version) {
119 case 1:
120 //result = test_ansi_files(test_num);
121 while (i <= test_num) {
122 result = test_ansi_files(i);
123 }
124 break;
125 case 2:
126 //result = test_unicode_files(test_num);
127 while (i <= test_num) {
128 result = test_unicode_files(i);
129 }
130 break;
131 default:
132 while (i <= test_num) {
133 result = test_ansi_files(i);
134 result = test_unicode_files(i);
135 ++i;
136 }
137 break;
138 }
139 }
140 #endif
141 printf("finished\n");
142 return result;
143 }
144 /*
145 ANSI:
146 all tests passing
147
148 UNICODE:
149 writing binary files short one byte. ie. odd number file lengths.
150 reading text files returns one extra byte.
151
152 */
153 #ifndef __GNUC__
154
155 char* args[] = { "fileio.exe", "0", "unicode", "verbose"};
156
157 char* args1[] = { "fileio.exe", "1", "unicode" };
158 char* args2[] = { "fileio.exe", "2", "unicode" };
159 char* args3[] = { "fileio.exe", "3", "unicode" };
160 char* args4[] = { "fileio.exe", "4", "unicode" };
161
162 int __cdecl mainCRTStartup(void)
163 {
164 main(2, args);
165 #if 0
166 //#if 1
167 main(2, args1);
168 main(2, args2);
169 main(2, args3);
170 main(2, args4);
171 //#else
172 main(3, args1);
173 main(3, args2);
174 main(3, args3);
175 main(3, args4);
176 //#endif
177 #endif
178 return 0;
179 }
180
181 #endif /*__GNUC__*/