blob: 52e1bfb121325ce782297a1a7cac150ba3fb6bbf [file] [log] [blame]
Alexandre Julliard9f71bd92003-12-04 02:01:39 +00001/*
2 * Wine Conformance Test EXE
3 *
4 * Copyright 2003 Jakob Eriksson (for Solid Form Sweden AB)
5 * Copyright 2003 Dimitrie O. Paun
6 * Copyright 2003 Ferenc Wagner
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library 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 GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 *
21 * This program is dedicated to Anna Lindh,
22 * Swedish Minister of Foreign Affairs.
23 * Anna was murdered September 11, 2003.
24 *
25 */
26
27#include "config.h"
28#include "wine/port.h"
29
30#include <stdio.h>
31#include <stdlib.h>
32#include <errno.h>
33#ifdef HAVE_UNISTD_H
34# include <unistd.h>
35#endif
36#include <windows.h>
37
38#include "winetest.h"
39
Ferenc Wagner354f6622004-01-15 01:48:05 +000040#define TESTRESOURCE "USERDATA"
41
Alexandre Julliard9f71bd92003-12-04 02:01:39 +000042struct wine_test
43{
44 char *name;
45 int resource;
46 int subtest_count;
47 char **subtests;
48 int is_elf;
49 char *exename;
50};
51
Dimitrie O. Pauncbe0e492004-03-20 19:21:39 +000052struct rev_info
53{
54 const char* file;
55 const char* rev;
56};
57
Ferenc Wagner354f6622004-01-15 01:48:05 +000058static struct wine_test *wine_tests;
Dimitrie O. Pauncbe0e492004-03-20 19:21:39 +000059static struct rev_info *rev_infos;
Alexandre Julliard9f71bd92003-12-04 02:01:39 +000060
61static const char *wineloader;
62
63void print_version ()
64{
65 OSVERSIONINFOEX ver;
66 BOOL ext;
67
68 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
69 if (!(ext = GetVersionEx ((OSVERSIONINFO *) &ver)))
70 {
71 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
72 if (!GetVersionEx ((OSVERSIONINFO *) &ver))
Ferenc Wagner354f6622004-01-15 01:48:05 +000073 report (R_FATAL, "Can't get OS version.");
Alexandre Julliard9f71bd92003-12-04 02:01:39 +000074 }
75
76 xprintf (" dwMajorVersion=%ld\n dwMinorVersion=%ld\n"
77 " dwBuildNumber=%ld\n PlatformId=%ld\n szCSDVersion=%s\n",
78 ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber,
79 ver.dwPlatformId, ver.szCSDVersion);
80
81 if (!ext) return;
82
83 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
84 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
85 ver.wServicePackMajor, ver.wServicePackMinor, ver.wSuiteMask,
86 ver.wProductType, ver.wReserved);
87}
88
89static inline int is_dot_dir(const char* x)
90{
91 return ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))));
92}
93
94void remove_dir (const char *dir)
95{
96 HANDLE hFind;
97 WIN32_FIND_DATA wfd;
98 char path[MAX_PATH];
99 size_t dirlen = strlen (dir);
100
101 /* Make sure the directory exists before going further */
102 memcpy (path, dir, dirlen);
103 strcpy (path + dirlen++, "\\*");
104 hFind = FindFirstFile (path, &wfd);
105 if (hFind == INVALID_HANDLE_VALUE) return;
106
107 do {
108 char *lp = wfd.cFileName;
109
110 if (!lp[0]) lp = wfd.cAlternateFileName; /* ? FIXME not (!lp) ? */
111 if (is_dot_dir (lp)) continue;
112 strcpy (path + dirlen, lp);
113 if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
114 remove_dir(path);
115 else if (!DeleteFile (path))
Ferenc Wagner354f6622004-01-15 01:48:05 +0000116 report (R_WARNING, "Can't delete file %s: error %d",
117 path, GetLastError ());
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000118 } while (FindNextFile (hFind, &wfd));
119 FindClose (hFind);
120 if (!RemoveDirectory (dir))
Ferenc Wagner354f6622004-01-15 01:48:05 +0000121 report (R_WARNING, "Can't remove directory %s: error %d",
122 dir, GetLastError ());
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000123}
124
Dimitrie O. Pauncbe0e492004-03-20 19:21:39 +0000125const char* get_test_source_file(const char* test, const char* subtest)
126{
127 static const char* special_dirs[][2] = {
128 { "gdi32", "gdi"}, { "kernel32", "kernel" },
129 { "user32", "user" }, { "winspool.drv", "winspool" },
130 { "ws2_32", "winsock" }, { 0, 0 }
131 };
132 static char buffer[MAX_PATH];
133 int i;
134
135 for (i = 0; special_dirs[i][0]; i++) {
136 if (strcmp(test, special_dirs[i][0]) == 0) {
137 test = special_dirs[i][1];
138 break;
139 }
140 }
141
142 snprintf(buffer, sizeof(buffer), "dlls/%s/tests/%s.c", test, subtest);
Dimitrie O. Pauncbe0e492004-03-20 19:21:39 +0000143 return buffer;
144}
145
146const char* get_file_rev(const char* file)
147{
148 const struct rev_info* rev;
149
150 for(rev = rev_infos; rev->file; rev++) {
Dimitrie O. Pauncbe0e492004-03-20 19:21:39 +0000151 if (strcmp(rev->file, file) == 0) return rev->rev;
152 }
153
Ferenc Wagnera1224992004-03-24 23:40:06 +0000154 return "-";
Dimitrie O. Pauncbe0e492004-03-20 19:21:39 +0000155}
156
157void extract_rev_infos ()
158{
159 char revinfo[256], *p;
Ferenc Wagnera1224992004-03-24 23:40:06 +0000160 int size = 0, i, len;
Dimitrie O. Pauncbe0e492004-03-20 19:21:39 +0000161 HMODULE module = GetModuleHandle (NULL);
162
163 for (i = 0; TRUE; i++) {
164 if (i >= size) {
165 size += 100;
Ferenc Wagnera1224992004-03-24 23:40:06 +0000166 rev_infos = xrealloc (rev_infos, size * sizeof (*rev_infos));
Dimitrie O. Pauncbe0e492004-03-20 19:21:39 +0000167 }
168 memset(rev_infos + i, 0, sizeof(rev_infos[i]));
169
170 len = LoadStringA (module, i + 30000, revinfo, sizeof(revinfo));
171 if (len == 0) break; /* end of revision info */
Ferenc Wagnera1224992004-03-24 23:40:06 +0000172 if (len >= sizeof(revinfo) - 1)
Dimitrie O. Pauncbe0e492004-03-20 19:21:39 +0000173 report (R_FATAL, "Revision info too long.");
174 if(!(p = strrchr(revinfo, ':')))
175 report (R_FATAL, "Revision info malformed (i=%d)", i);
176 *p = 0;
177 rev_infos[i].file = strdup(revinfo);
178 rev_infos[i].rev = strdup(p + 1);
Ferenc Wagnera1224992004-03-24 23:40:06 +0000179 }
Dimitrie O. Pauncbe0e492004-03-20 19:21:39 +0000180}
181
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000182void* extract_rcdata (int id, DWORD* size)
183{
184 HRSRC rsrc;
185 HGLOBAL hdl;
Ferenc Wagner354f6622004-01-15 01:48:05 +0000186 LPVOID addr = NULL;
187
188 if (!(rsrc = FindResource (0, (LPTSTR)id, TESTRESOURCE)) ||
189 !(*size = SizeofResource (0, rsrc)) ||
190 !(hdl = LoadResource (0, rsrc)) ||
191 !(addr = LockResource (hdl)))
192 report (R_FATAL, "Can't extract test file of id %d: %d",
193 id, GetLastError ());
194 return addr;
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000195}
196
Ferenc Wagnera1224992004-03-24 23:40:06 +0000197/* Fills in the name, is_elf and exename fields */
Ferenc Wagner354f6622004-01-15 01:48:05 +0000198void
199extract_test (struct wine_test *test, const char *dir, int id)
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000200{
201 BYTE* code;
202 DWORD size;
203 FILE* fout;
Ferenc Wagner354f6622004-01-15 01:48:05 +0000204 int strlen, bufflen = 128;
Ferenc Wagnerefc67252004-02-19 04:12:42 +0000205 char *exepos;
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000206
207 code = extract_rcdata (id, &size);
Ferenc Wagner354f6622004-01-15 01:48:05 +0000208 test->name = xmalloc (bufflen);
209 while ((strlen = LoadStringA (NULL, id, test->name, bufflen))
210 == bufflen - 1) {
211 bufflen *= 2;
212 test->name = xrealloc (test->name, bufflen);
213 }
214 if (!strlen) report (R_FATAL, "Can't read name of test %d.", id);
Ferenc Wagnerefc67252004-02-19 04:12:42 +0000215 test->exename = strmake (NULL, "%s/%s", dir, test->name);
Ferenc Wagner83877702004-03-19 01:54:10 +0000216 exepos = strstr (test->name, "_test.exe");
Ferenc Wagnerefc67252004-02-19 04:12:42 +0000217 if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name);
218 *exepos = 0;
219 test->name = xrealloc (test->name, exepos - test->name + 1);
Ferenc Wagner354f6622004-01-15 01:48:05 +0000220 report (R_STEP, "Extracting: %s", test->name);
221 test->is_elf = !memcmp (code+1, "ELF", 3);
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000222
Ferenc Wagner354f6622004-01-15 01:48:05 +0000223 if (!(fout = fopen (test->exename, "wb")) ||
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000224 (fwrite (code, size, 1, fout) != 1) ||
Ferenc Wagner354f6622004-01-15 01:48:05 +0000225 fclose (fout)) report (R_FATAL, "Failed to write file %s.",
Ferenc Wagnerefc67252004-02-19 04:12:42 +0000226 test->exename);
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000227}
228
Ferenc Wagner354f6622004-01-15 01:48:05 +0000229void
230get_subtests (const char *tempdir, struct wine_test *test, int id)
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000231{
232 char *subname;
233 FILE *subfile;
234 size_t subsize, bytes_read, total;
Ferenc Wagner354f6622004-01-15 01:48:05 +0000235 char *buffer, *index;
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000236 const char header[] = "Valid test names:", seps[] = " \r\n";
237 int oldstdout;
238 const char *argv[] = {"wine", NULL, NULL};
Ferenc Wagner354f6622004-01-15 01:48:05 +0000239 int allocated;
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000240
241 subname = tempnam (0, "sub");
Ferenc Wagner354f6622004-01-15 01:48:05 +0000242 if (!subname) report (R_FATAL, "Can't name subtests file.");
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000243 oldstdout = dup (1);
Ferenc Wagner354f6622004-01-15 01:48:05 +0000244 if (-1 == oldstdout) report (R_FATAL, "Can't preserve stdout.");
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000245 subfile = fopen (subname, "w+b");
Ferenc Wagner354f6622004-01-15 01:48:05 +0000246 if (!subfile) report (R_FATAL, "Can't open subtests file.");
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000247 if (-1 == dup2 (fileno (subfile), 1))
Ferenc Wagner354f6622004-01-15 01:48:05 +0000248 report (R_FATAL, "Can't redirect output to subtests.");
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000249 fclose (subfile);
250
Ferenc Wagner354f6622004-01-15 01:48:05 +0000251 extract_test (test, tempdir, id);
252 argv[1] = test->exename;
253 if (test->is_elf)
254 spawnvp (_P_WAIT, wineloader, argv);
255 else
256 spawnvp (_P_WAIT, test->exename, argv+1);
257 subsize = lseek (1, 0, SEEK_CUR);
258 buffer = xmalloc (subsize+1);
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000259
Ferenc Wagner354f6622004-01-15 01:48:05 +0000260 lseek (1, 0, SEEK_SET);
261 total = 0;
262 while ((bytes_read = read (1, buffer + total, subsize - total))
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000263 && (signed)bytes_read != -1)
264 total += bytes_read;
Ferenc Wagner354f6622004-01-15 01:48:05 +0000265 if (bytes_read)
266 report (R_FATAL, "Can't get subtests of %s", test->name);
267 buffer[total] = 0;
268 index = strstr (buffer, header);
269 if (!index)
270 report (R_FATAL, "Can't parse subtests output of %s",
271 test->name);
272 index += sizeof header;
273
274 allocated = 10;
275 test->subtests = xmalloc (allocated * sizeof(char*));
276 test->subtest_count = 0;
277 index = strtok (index, seps);
278 while (index) {
279 if (test->subtest_count == allocated) {
280 allocated *= 2;
281 test->subtests = xrealloc (test->subtests,
282 allocated * sizeof(char*));
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000283 }
Ferenc Wagner354f6622004-01-15 01:48:05 +0000284 test->subtests[test->subtest_count++] = strdup (index);
285 index = strtok (NULL, seps);
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000286 }
Ferenc Wagner354f6622004-01-15 01:48:05 +0000287 test->subtests = xrealloc (test->subtests,
288 test->subtest_count * sizeof(char*));
289 free (buffer);
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000290 close (1);
Ferenc Wagner354f6622004-01-15 01:48:05 +0000291 if (-1 == dup2 (oldstdout, 1))
292 report (R_FATAL, "Can't recover old stdout.");
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000293 close (oldstdout);
Ferenc Wagner354f6622004-01-15 01:48:05 +0000294 if (remove (subname))
295 report (R_FATAL, "Can't remove subtests file.");
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000296 free (subname);
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000297}
298
Ferenc Wagner354f6622004-01-15 01:48:05 +0000299/* Return number of failures, -1 if couldn't spawn process. */
300int run_test (struct wine_test* test, const char* subtest)
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000301{
302 int status;
Dimitrie O. Pauncbe0e492004-03-20 19:21:39 +0000303 const char* argv[] = {"wine", test->exename, subtest, NULL};
304 const char* file = get_test_source_file(test->name, subtest);
305 const char* rev = get_file_rev(file);
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000306
Dimitrie O. Pauncbe0e492004-03-20 19:21:39 +0000307 xprintf ("%s:%s start %s %s\n", test->name, subtest, file, rev);
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000308 if (test->is_elf)
309 status = spawnvp (_P_WAIT, wineloader, argv);
310 else
311 status = spawnvp (_P_WAIT, test->exename, argv+1);
312 if (status == -1)
Ferenc Wagner354f6622004-01-15 01:48:05 +0000313 xprintf ("Can't run: %d, errno=%d: %s\n",
314 status, errno, strerror (errno));
315 xprintf ("%s:%s done (%d)\n", test->name, subtest, status);
316 return status;
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000317}
318
Ferenc Wagner354f6622004-01-15 01:48:05 +0000319BOOL CALLBACK
320EnumTestFileProc (HMODULE hModule, LPCTSTR lpszType,
321 LPTSTR lpszName, LONG_PTR lParam)
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000322{
Ferenc Wagner354f6622004-01-15 01:48:05 +0000323 (*(int*)lParam)++;
324 return TRUE;
325}
326
Ferenc Wagner8c4a4df2004-02-20 19:56:29 +0000327char *
328run_tests (char *logname, const char *tag)
Ferenc Wagner354f6622004-01-15 01:48:05 +0000329{
330 int nr_of_files = 0, nr_of_tests = 0, i;
Ferenc Wagnerefc67252004-02-19 04:12:42 +0000331 char *tempdir;
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000332 FILE *logfile;
333 char build_tag[128];
334
335 SetErrorMode (SEM_FAILCRITICALERRORS);
336
337 if (!(wineloader = getenv("WINELOADER"))) wineloader = "wine";
Ferenc Wagner354f6622004-01-15 01:48:05 +0000338 if (setvbuf (stdout, NULL, _IONBF, 0))
339 report (R_FATAL, "Can't unbuffer output.");
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000340
341 tempdir = tempnam (0, "wct");
Ferenc Wagner354f6622004-01-15 01:48:05 +0000342 if (!tempdir)
343 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
344 report (R_DIR, tempdir);
345 if (!CreateDirectory (tempdir, NULL))
346 report (R_FATAL, "Could not create directory: %s", tempdir);
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000347
Ferenc Wagnerefc67252004-02-19 04:12:42 +0000348 if (!logname) {
349 logname = tempnam (0, "res");
350 if (!logname) report (R_FATAL, "Can't name logfile.");
351 }
Ferenc Wagner354f6622004-01-15 01:48:05 +0000352 report (R_OUT, logname);
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000353
Ferenc Wagner354f6622004-01-15 01:48:05 +0000354 logfile = fopen (logname, "a");
355 if (!logfile) report (R_FATAL, "Could not open logfile.");
356 if (-1 == dup2 (fileno (logfile), 1))
357 report (R_FATAL, "Can't redirect stdout.");
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000358 fclose (logfile);
359
Ferenc Wagnerefc67252004-02-19 04:12:42 +0000360 xprintf ("Version 2\n");
Ferenc Wagner354f6622004-01-15 01:48:05 +0000361 i = LoadStringA (GetModuleHandle (NULL), 0,
362 build_tag, sizeof build_tag);
Ferenc Wagner83877702004-03-19 01:54:10 +0000363 if (i == 0) report (R_FATAL, "Build descriptor not found: %d",
364 GetLastError ());
Ferenc Wagner354f6622004-01-15 01:48:05 +0000365 if (i >= sizeof build_tag)
366 report (R_FATAL, "Build descriptor too long.");
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000367 xprintf ("Tests from build %s\n", build_tag);
Ferenc Wagner83877702004-03-19 01:54:10 +0000368 xprintf ("Tag: %s\n", tag?tag:"");
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000369 xprintf ("Operating system version:\n");
370 print_version ();
371 xprintf ("Test output:\n" );
372
Ferenc Wagner354f6622004-01-15 01:48:05 +0000373 report (R_STATUS, "Counting tests");
374 if (!EnumResourceNames (NULL, TESTRESOURCE,
375 EnumTestFileProc, (LPARAM)&nr_of_files))
376 report (R_FATAL, "Can't enumerate test files: %d",
377 GetLastError ());
378 wine_tests = xmalloc (nr_of_files * sizeof wine_tests[0]);
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000379
Ferenc Wagner354f6622004-01-15 01:48:05 +0000380 report (R_STATUS, "Extracting tests");
Ferenc Wagnerfeaad962004-02-21 04:01:56 +0000381 report (R_PROGRESS, 0, nr_of_files);
Ferenc Wagner354f6622004-01-15 01:48:05 +0000382 for (i = 0; i < nr_of_files; i++) {
383 get_subtests (tempdir, wine_tests+i, i+1);
384 nr_of_tests += wine_tests[i].subtest_count;
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000385 }
Ferenc Wagner354f6622004-01-15 01:48:05 +0000386 report (R_DELTA, 0, "Extracting: Done");
387
388 report (R_STATUS, "Running tests");
Ferenc Wagnerfeaad962004-02-21 04:01:56 +0000389 report (R_PROGRESS, 1, nr_of_tests);
Ferenc Wagner354f6622004-01-15 01:48:05 +0000390 for (i = 0; i < nr_of_files; i++) {
391 struct wine_test *test = wine_tests + i;
392 int j;
393
394 for (j = 0; j < test->subtest_count; j++) {
Ferenc Wagner83877702004-03-19 01:54:10 +0000395 report (R_STEP, "Running: %s:%s", test->name,
Ferenc Wagner354f6622004-01-15 01:48:05 +0000396 test->subtests[j]);
397 run_test (test, test->subtests[j]);
398 }
399 }
400 report (R_DELTA, 0, "Running: Done");
401
402 report (R_STATUS, "Cleaning up");
403 close (1);
404 remove_dir (tempdir);
405 free (tempdir);
406 free (wine_tests);
407
Ferenc Wagnerefc67252004-02-19 04:12:42 +0000408 return logname;
409}
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000410
Ferenc Wagnerefc67252004-02-19 04:12:42 +0000411void
412usage ()
413{
414 fprintf (stderr, "\
415Usage: winetest [OPTION]...\n\n\
416 -c console mode, no GUI\n\
417 -h print this message and exit\n\
418 -q quiet mode, no output at all\n\
419 -o FILE put report into FILE, do not submit\n\
420 -s FILE submit FILE, do not run tests\n\
421 -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n");
Ferenc Wagner354f6622004-01-15 01:48:05 +0000422}
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000423
Ferenc Wagner83877702004-03-19 01:54:10 +0000424/* One can't nest strtok()-s, so here is a replacement. */
425char *
426mystrtok (char *newstr)
427{
428 static char *start, *end;
429 static int finish = 1;
430
431 if (newstr) {
432 start = newstr;
433 finish = 0;
434 } else start = end;
435 if (finish) return NULL;
436 while (*start == ' ') start++;
437 if (*start == 0) return NULL;
438 end = start;
439 while (*end != ' ')
440 if (*end == 0) {
441 finish = 1;
442 return start;
443 } else end++;
444 *end++ = 0;
445 return start;
446}
447
Ferenc Wagner354f6622004-01-15 01:48:05 +0000448int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst,
449 LPSTR cmdLine, int cmdShow)
450{
Ferenc Wagner8c4a4df2004-02-20 19:56:29 +0000451 char *logname = NULL;
Ferenc Wagnerefc67252004-02-19 04:12:42 +0000452 char *tag = NULL, *cp;
Ferenc Wagner8c4a4df2004-02-20 19:56:29 +0000453 const char *submit = NULL;
Ferenc Wagnerefc67252004-02-19 04:12:42 +0000454
Dimitrie O. Pauncbe0e492004-03-20 19:21:39 +0000455 /* initialize the revision information first */
456 extract_rev_infos();
457
Ferenc Wagner83877702004-03-19 01:54:10 +0000458 cmdLine = mystrtok (cmdLine);
Ferenc Wagnerefc67252004-02-19 04:12:42 +0000459 while (cmdLine) {
Ferenc Wagnera1224992004-03-24 23:40:06 +0000460 if (cmdLine[0] != '-' || cmdLine[2]) {
461 report (R_ERROR, "Not a single letter option: %s", cmdLine);
462 usage ();
463 exit (2);
464 }
465 switch (cmdLine[1]) {
466 case 'c':
467 report (R_TEXTMODE);
468 break;
469 case 'h':
470 usage ();
471 exit (0);
472 case 'q':
473 report (R_QUIET);
474 break;
475 case 's':
476 submit = mystrtok (NULL);
477 if (tag)
478 report (R_WARNING, "ignoring tag for submit");
479 send_file (submit);
480 break;
481 case 'o':
482 logname = mystrtok (NULL);
483 run_tests (logname, tag);
484 break;
485 case 't':
486 tag = mystrtok (NULL);
487 cp = badtagchar (tag);
488 if (cp) {
489 report (R_ERROR, "invalid char in tag: %c", *cp);
Ferenc Wagnerefc67252004-02-19 04:12:42 +0000490 usage ();
491 exit (2);
492 }
Ferenc Wagnera1224992004-03-24 23:40:06 +0000493 break;
494 default:
495 report (R_ERROR, "invalid option: -%c", cmdLine[1]);
496 usage ();
497 exit (2);
498 }
Ferenc Wagner83877702004-03-19 01:54:10 +0000499 cmdLine = mystrtok (NULL);
Ferenc Wagnerefc67252004-02-19 04:12:42 +0000500 }
501 if (!logname && !submit) {
502 report (R_STATUS, "Starting up");
503 logname = run_tests (NULL, tag);
Ferenc Wagnerfeaad962004-02-21 04:01:56 +0000504 if (report (R_ASK, MB_YESNO, "Do you want to submit the "
505 "test results?") == IDYES)
506 if (!send_file (logname) && remove (logname))
507 report (R_WARNING, "Can't remove logfile: %d.", errno);
Ferenc Wagner8c4a4df2004-02-20 19:56:29 +0000508 free (logname);
Ferenc Wagnerefc67252004-02-19 04:12:42 +0000509 report (R_STATUS, "Finished");
510 }
Ferenc Wagner354f6622004-01-15 01:48:05 +0000511 exit (0);
Alexandre Julliard9f71bd92003-12-04 02:01:39 +0000512}