mshtml: Store client site in HTMLDocumentObj as soon as possible in SetClientSite.
[wine/multimedia.git] / programs / winetest / main.c
blobf5bf8d48115d31a8817d4df8715e683d0a9400b3
1 /*
2 * Wine Conformance Test EXE
4 * Copyright 2003, 2004 Jakob Eriksson (for Solid Form Sweden AB)
5 * Copyright 2003 Dimitrie O. Paun
6 * Copyright 2003 Ferenc Wagner
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.
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.
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 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * This program is dedicated to Anna Lindh,
23 * Swedish Minister of Foreign Affairs.
24 * Anna was murdered September 11, 2003.
28 #include "config.h"
29 #include "wine/port.h"
31 #define COBJMACROS
32 #include <stdio.h>
33 #include <assert.h>
34 #include <windows.h>
35 #include <mshtml.h>
37 #include "winetest.h"
38 #include "resource.h"
40 struct wine_test
42 char *name;
43 int resource;
44 int subtest_count;
45 char **subtests;
46 char *exename;
47 char *maindllpath;
50 char *tag = NULL;
51 char *email = NULL;
52 BOOL aborting = FALSE;
53 static struct wine_test *wine_tests;
54 static int nr_of_files, nr_of_tests;
55 static int nr_native_dlls;
56 static const char whitespace[] = " \t\r\n";
57 static const char testexe[] = "_test.exe";
58 static char build_id[64];
60 /* filters for running only specific tests */
61 static char *filters[64];
62 static unsigned int nb_filters = 0;
64 /* Needed to check for .NET dlls */
65 static HMODULE hmscoree;
66 static HRESULT (WINAPI *pLoadLibraryShim)(LPCWSTR, LPCWSTR, LPVOID, HMODULE *);
68 /* To store the current PATH setting (related to .NET only provided dlls) */
69 static char *curpath;
71 /* check if test is being filtered out */
72 static BOOL test_filtered_out( LPCSTR module, LPCSTR testname )
74 char *p, dllname[MAX_PATH];
75 unsigned int i, len;
77 strcpy( dllname, module );
78 CharLowerA( dllname );
79 p = strstr( dllname, testexe );
80 if (p) *p = 0;
81 len = strlen(dllname);
83 if (!nb_filters) return FALSE;
84 for (i = 0; i < nb_filters; i++)
86 if (!strncmp( dllname, filters[i], len ))
88 if (!filters[i][len]) return FALSE;
89 if (filters[i][len] != ':') continue;
90 if (!testname || !strcmp( testname, &filters[i][len+1] )) return FALSE;
93 return TRUE;
96 static char * get_file_version(char * file_name)
98 static char version[32];
99 DWORD size;
100 DWORD handle;
102 size = GetFileVersionInfoSizeA(file_name, &handle);
103 if (size) {
104 char * data = heap_alloc(size);
105 if (data) {
106 if (GetFileVersionInfoA(file_name, handle, size, data)) {
107 static char backslash[] = "\\";
108 VS_FIXEDFILEINFO *pFixedVersionInfo;
109 UINT len;
110 if (VerQueryValueA(data, backslash, (LPVOID *)&pFixedVersionInfo, &len)) {
111 sprintf(version, "%d.%d.%d.%d",
112 pFixedVersionInfo->dwFileVersionMS >> 16,
113 pFixedVersionInfo->dwFileVersionMS & 0xffff,
114 pFixedVersionInfo->dwFileVersionLS >> 16,
115 pFixedVersionInfo->dwFileVersionLS & 0xffff);
116 } else
117 sprintf(version, "version not available");
118 } else
119 sprintf(version, "unknown");
120 heap_free(data);
121 } else
122 sprintf(version, "failed");
123 } else
124 sprintf(version, "version not available");
126 return version;
129 static int running_under_wine (void)
131 HMODULE module = GetModuleHandleA("ntdll.dll");
133 if (!module) return 0;
134 return (GetProcAddress(module, "wine_server_call") != NULL);
137 static int check_mount_mgr(void)
139 if (running_under_wine())
141 HANDLE handle = CreateFileA( "\\\\.\\MountPointManager", GENERIC_READ,
142 FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
143 if (handle == INVALID_HANDLE_VALUE) return FALSE;
144 CloseHandle( handle );
146 return TRUE;
149 static int check_display_driver(void)
151 if (running_under_wine())
153 HWND hwnd = CreateWindowA( "STATIC", "", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
154 0, 0, GetModuleHandleA(0), 0 );
155 if (!hwnd) return FALSE;
156 DestroyWindow( hwnd );
158 return TRUE;
161 static int running_on_visible_desktop (void)
163 HWND desktop;
164 HMODULE huser32 = GetModuleHandle("user32.dll");
165 HWINSTA (WINAPI *pGetProcessWindowStation)(void);
166 BOOL (WINAPI *pGetUserObjectInformationA)(HANDLE,INT,LPVOID,DWORD,LPDWORD);
168 pGetProcessWindowStation = (void *)GetProcAddress(huser32, "GetProcessWindowStation");
169 pGetUserObjectInformationA = (void *)GetProcAddress(huser32, "GetUserObjectInformationA");
171 desktop = GetDesktopWindow();
172 if (!GetWindowLongPtrW(desktop, GWLP_WNDPROC)) /* Win9x */
173 return IsWindowVisible(desktop);
175 if (pGetProcessWindowStation && pGetUserObjectInformationA)
177 DWORD len;
178 HWINSTA wstation;
179 USEROBJECTFLAGS uoflags;
181 wstation = (HWINSTA)pGetProcessWindowStation();
182 assert(pGetUserObjectInformationA(wstation, UOI_FLAGS, &uoflags, sizeof(uoflags), &len));
183 return (uoflags.dwFlags & WSF_VISIBLE) != 0;
185 return IsWindowVisible(desktop);
188 /* check for native dll when running under wine */
189 static BOOL is_native_dll( HMODULE module )
191 static const char fakedll_signature[] = "Wine placeholder DLL";
192 const IMAGE_DOS_HEADER *dos;
194 if (!running_under_wine()) return FALSE;
195 if (!((ULONG_PTR)module & 1)) return FALSE; /* not loaded as datafile */
196 /* builtin dlls can't be loaded as datafile, so we must have native or fake dll */
197 dos = (const IMAGE_DOS_HEADER *)((const char *)module - 1);
198 if (dos->e_magic != IMAGE_DOS_SIGNATURE) return FALSE;
199 if (dos->e_lfanew >= sizeof(*dos) + sizeof(fakedll_signature) &&
200 !memcmp( dos + 1, fakedll_signature, sizeof(fakedll_signature) )) return FALSE;
201 return TRUE;
204 static void print_version (void)
206 #ifdef __i386__
207 static const char platform[] = "i386";
208 #elif defined(__x86_64__)
209 static const char platform[] = "x86_64";
210 #elif defined(__sparc__)
211 static const char platform[] = "sparc";
212 #elif defined(__ALPHA__)
213 static const char platform[] = "alpha";
214 #elif defined(__powerpc__)
215 static const char platform[] = "powerpc";
216 #else
217 # error CPU unknown
218 #endif
219 OSVERSIONINFOEX ver;
220 BOOL ext, wow64;
221 int is_win2k3_r2;
222 const char *(CDECL *wine_get_build_id)(void);
223 void (CDECL *wine_get_host_version)( const char **sysname, const char **release );
224 BOOL (WINAPI *pIsWow64Process)(HANDLE hProcess, PBOOL Wow64Process);
225 BOOL (WINAPI *pGetProductInfo)(DWORD, DWORD, DWORD, DWORD, DWORD *);
227 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
228 if (!(ext = GetVersionEx ((OSVERSIONINFO *) &ver)))
230 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
231 if (!GetVersionEx ((OSVERSIONINFO *) &ver))
232 report (R_FATAL, "Can't get OS version.");
234 pIsWow64Process = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
235 if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &wow64 )) wow64 = FALSE;
237 xprintf (" Platform=%s%s\n", platform, wow64 ? " (WOW64)" : "");
238 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
239 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
240 xprintf (" Submitter=%s\n", email );
241 xprintf (" dwMajorVersion=%u\n dwMinorVersion=%u\n"
242 " dwBuildNumber=%u\n PlatformId=%u\n szCSDVersion=%s\n",
243 ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber,
244 ver.dwPlatformId, ver.szCSDVersion);
246 wine_get_build_id = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_build_id");
247 wine_get_host_version = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_host_version");
248 if (wine_get_build_id) xprintf( " WineBuild=%s\n", wine_get_build_id() );
249 if (wine_get_host_version)
251 const char *sysname, *release;
252 wine_get_host_version( &sysname, &release );
253 xprintf( " Host system=%s\n Host version=%s\n", sysname, release );
255 is_win2k3_r2 = GetSystemMetrics(SM_SERVERR2);
256 if(is_win2k3_r2)
257 xprintf(" R2 build number=%d\n", is_win2k3_r2);
259 if (!ext) return;
261 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
262 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
263 ver.wServicePackMajor, ver.wServicePackMinor, ver.wSuiteMask,
264 ver.wProductType, ver.wReserved);
266 pGetProductInfo = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"GetProductInfo");
267 if (pGetProductInfo && !running_under_wine())
269 DWORD prodtype = 0;
271 pGetProductInfo(ver.dwMajorVersion, ver.dwMinorVersion, ver.wServicePackMajor, ver.wServicePackMinor, &prodtype);
272 xprintf(" dwProductInfo=%u\n", prodtype);
276 static inline int is_dot_dir(const char* x)
278 return ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))));
281 static void remove_dir (const char *dir)
283 HANDLE hFind;
284 WIN32_FIND_DATA wfd;
285 char path[MAX_PATH];
286 size_t dirlen = strlen (dir);
288 /* Make sure the directory exists before going further */
289 memcpy (path, dir, dirlen);
290 strcpy (path + dirlen++, "\\*");
291 hFind = FindFirstFile (path, &wfd);
292 if (hFind == INVALID_HANDLE_VALUE) return;
294 do {
295 char *lp = wfd.cFileName;
297 if (!lp[0]) lp = wfd.cAlternateFileName; /* ? FIXME not (!lp) ? */
298 if (is_dot_dir (lp)) continue;
299 strcpy (path + dirlen, lp);
300 if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
301 remove_dir(path);
302 else if (!DeleteFile (path))
303 report (R_WARNING, "Can't delete file %s: error %d",
304 path, GetLastError ());
305 } while (FindNextFile (hFind, &wfd));
306 FindClose (hFind);
307 if (!RemoveDirectory (dir))
308 report (R_WARNING, "Can't remove directory %s: error %d",
309 dir, GetLastError ());
312 static const char* get_test_source_file(const char* test, const char* subtest)
314 static const char* special_dirs[][2] = {
315 { 0, 0 }
317 static char buffer[MAX_PATH];
318 int i, len = strlen(test);
320 if (len > 4 && !strcmp( test + len - 4, ".exe" ))
322 len = sprintf(buffer, "programs/%s", test) - 4;
323 buffer[len] = 0;
325 else len = sprintf(buffer, "dlls/%s", test);
327 for (i = 0; special_dirs[i][0]; i++) {
328 if (strcmp(test, special_dirs[i][0]) == 0) {
329 strcpy( buffer, special_dirs[i][1] );
330 len = strlen(buffer);
331 break;
335 sprintf(buffer + len, "/tests/%s.c", subtest);
336 return buffer;
339 static void* extract_rcdata (LPCTSTR name, LPCTSTR type, DWORD* size)
341 HRSRC rsrc;
342 HGLOBAL hdl;
343 LPVOID addr;
345 if (!(rsrc = FindResource (NULL, name, type)) ||
346 !(*size = SizeofResource (0, rsrc)) ||
347 !(hdl = LoadResource (0, rsrc)) ||
348 !(addr = LockResource (hdl)))
349 return NULL;
350 return addr;
353 /* Fills in the name and exename fields */
354 static void
355 extract_test (struct wine_test *test, const char *dir, LPTSTR res_name)
357 BYTE* code;
358 DWORD size;
359 char *exepos;
360 HANDLE hfile;
361 DWORD written;
363 code = extract_rcdata (res_name, "TESTRES", &size);
364 if (!code) report (R_FATAL, "Can't find test resource %s: %d",
365 res_name, GetLastError ());
366 test->name = heap_strdup( res_name );
367 test->exename = strmake (NULL, "%s\\%s", dir, test->name);
368 exepos = strstr (test->name, testexe);
369 if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name);
370 *exepos = 0;
371 test->name = heap_realloc (test->name, exepos - test->name + 1);
372 report (R_STEP, "Extracting: %s", test->name);
374 hfile = CreateFileA(test->exename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
375 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
376 if (hfile == INVALID_HANDLE_VALUE)
377 report (R_FATAL, "Failed to open file %s.", test->exename);
379 if (!WriteFile(hfile, code, size, &written, NULL))
380 report (R_FATAL, "Failed to write file %s.", test->exename);
382 CloseHandle(hfile);
385 static DWORD wait_process( HANDLE process, DWORD timeout )
387 DWORD wait, diff = 0, start = GetTickCount();
388 MSG msg;
390 while (diff < timeout)
392 wait = MsgWaitForMultipleObjects( 1, &process, FALSE, timeout - diff, QS_ALLINPUT );
393 if (wait != WAIT_OBJECT_0 + 1) return wait;
394 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
395 diff = GetTickCount() - start;
397 return WAIT_TIMEOUT;
400 static void append_path( const char *path)
402 char *newpath;
404 newpath = heap_alloc(strlen(curpath) + 1 + strlen(path) + 1);
405 strcpy(newpath, curpath);
406 strcat(newpath, ";");
407 strcat(newpath, path);
408 SetEnvironmentVariableA("PATH", newpath);
410 heap_free(newpath);
413 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
414 stdout to there.
416 Return the exit status, -2 if can't create process or the return
417 value of WaitForSingleObject.
419 static int
420 run_ex (char *cmd, HANDLE out_file, const char *tempdir, DWORD ms)
422 STARTUPINFO si;
423 PROCESS_INFORMATION pi;
424 DWORD wait, status;
426 GetStartupInfo (&si);
427 si.dwFlags = STARTF_USESTDHANDLES;
428 si.hStdInput = GetStdHandle( STD_INPUT_HANDLE );
429 si.hStdOutput = out_file ? out_file : GetStdHandle( STD_OUTPUT_HANDLE );
430 si.hStdError = out_file ? out_file : GetStdHandle( STD_ERROR_HANDLE );
432 if (!CreateProcessA (NULL, cmd, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE,
433 NULL, tempdir, &si, &pi))
434 return -2;
436 CloseHandle (pi.hThread);
437 status = wait_process( pi.hProcess, ms );
438 switch (status)
440 case WAIT_OBJECT_0:
441 GetExitCodeProcess (pi.hProcess, &status);
442 CloseHandle (pi.hProcess);
443 return status;
444 case WAIT_FAILED:
445 report (R_ERROR, "Wait for '%s' failed: %d", cmd, GetLastError ());
446 break;
447 case WAIT_TIMEOUT:
448 break;
449 default:
450 report (R_ERROR, "Wait returned %d", status);
451 break;
453 if (!TerminateProcess (pi.hProcess, 257))
454 report (R_ERROR, "TerminateProcess failed: %d", GetLastError ());
455 wait = wait_process( pi.hProcess, 5000 );
456 switch (wait)
458 case WAIT_OBJECT_0:
459 break;
460 case WAIT_FAILED:
461 report (R_ERROR, "Wait for termination of '%s' failed: %d", cmd, GetLastError ());
462 break;
463 case WAIT_TIMEOUT:
464 report (R_ERROR, "Can't kill process '%s'", cmd);
465 break;
466 default:
467 report (R_ERROR, "Waiting for termination: %d", wait);
468 break;
470 CloseHandle (pi.hProcess);
471 return status;
474 static DWORD
475 get_subtests (const char *tempdir, struct wine_test *test, LPTSTR res_name)
477 char *cmd;
478 HANDLE subfile;
479 DWORD err, total;
480 char buffer[8192], *index;
481 static const char header[] = "Valid test names:";
482 int status, allocated;
483 char tmpdir[MAX_PATH], subname[MAX_PATH];
484 SECURITY_ATTRIBUTES sa;
486 test->subtest_count = 0;
488 if (!GetTempPathA( MAX_PATH, tmpdir ) ||
489 !GetTempFileNameA( tmpdir, "sub", 0, subname ))
490 report (R_FATAL, "Can't name subtests file.");
492 /* make handle inheritable */
493 sa.nLength = sizeof(sa);
494 sa.lpSecurityDescriptor = NULL;
495 sa.bInheritHandle = TRUE;
497 subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
498 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
499 &sa, CREATE_ALWAYS, 0, NULL );
501 if ((subfile == INVALID_HANDLE_VALUE) &&
502 (GetLastError() == ERROR_INVALID_PARAMETER)) {
503 /* FILE_SHARE_DELETE not supported on win9x */
504 subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
505 FILE_SHARE_READ | FILE_SHARE_WRITE,
506 &sa, CREATE_ALWAYS, 0, NULL );
508 if (subfile == INVALID_HANDLE_VALUE) {
509 err = GetLastError();
510 report (R_ERROR, "Can't open subtests output of %s: %u",
511 test->name, GetLastError());
512 goto quit;
515 extract_test (test, tempdir, res_name);
516 cmd = strmake (NULL, "%s --list", test->exename);
517 if (test->maindllpath) {
518 /* We need to add the path (to the main dll) to PATH */
519 append_path(test->maindllpath);
521 status = run_ex (cmd, subfile, tempdir, 5000);
522 err = GetLastError();
523 if (test->maindllpath) {
524 /* Restore PATH again */
525 SetEnvironmentVariableA("PATH", curpath);
527 heap_free (cmd);
529 if (status == -2)
531 report (R_ERROR, "Cannot run %s error %u", test->exename, err);
532 goto quit;
535 SetFilePointer( subfile, 0, NULL, FILE_BEGIN );
536 ReadFile( subfile, buffer, sizeof(buffer), &total, NULL );
537 CloseHandle( subfile );
538 if (sizeof buffer == total) {
539 report (R_ERROR, "Subtest list of %s too big.",
540 test->name, sizeof buffer);
541 err = ERROR_OUTOFMEMORY;
542 goto quit;
544 buffer[total] = 0;
546 index = strstr (buffer, header);
547 if (!index) {
548 report (R_ERROR, "Can't parse subtests output of %s",
549 test->name);
550 err = ERROR_INTERNAL_ERROR;
551 goto quit;
553 index += sizeof header;
555 allocated = 10;
556 test->subtests = heap_alloc (allocated * sizeof(char*));
557 index = strtok (index, whitespace);
558 while (index) {
559 if (test->subtest_count == allocated) {
560 allocated *= 2;
561 test->subtests = heap_realloc (test->subtests,
562 allocated * sizeof(char*));
564 if (!test_filtered_out( test->name, index ))
565 test->subtests[test->subtest_count++] = heap_strdup(index);
566 index = strtok (NULL, whitespace);
568 test->subtests = heap_realloc (test->subtests,
569 test->subtest_count * sizeof(char*));
570 err = 0;
572 quit:
573 if (!DeleteFileA (subname))
574 report (R_WARNING, "Can't delete file '%s': %u", subname, GetLastError());
575 return err;
578 static void
579 run_test (struct wine_test* test, const char* subtest, HANDLE out_file, const char *tempdir)
581 int status;
582 const char* file = get_test_source_file(test->name, subtest);
583 char *cmd = strmake (NULL, "%s %s", test->exename, subtest);
585 xprintf ("%s:%s start %s -\n", test->name, subtest, file);
586 status = run_ex (cmd, out_file, tempdir, 120000);
587 heap_free (cmd);
588 xprintf ("%s:%s done (%d)\n", test->name, subtest, status);
591 static BOOL CALLBACK
592 EnumTestFileProc (HMODULE hModule, LPCTSTR lpszType,
593 LPTSTR lpszName, LONG_PTR lParam)
595 if (!test_filtered_out( lpszName, NULL )) (*(int*)lParam)++;
596 return TRUE;
599 static const struct clsid_mapping
601 const char *name;
602 CLSID clsid;
603 } clsid_list[] =
605 {"oledb32", {0xc8b522d1, 0x5cf3, 0x11ce, {0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d}}},
606 {NULL, {0, 0, 0, {0,0,0,0,0,0,0,0}}}
610 static BOOL get_main_clsid(const char *name, CLSID *clsid)
612 const struct clsid_mapping *mapping;
614 for(mapping = clsid_list; mapping->name; mapping++)
616 if(!strcasecmp(name, mapping->name))
618 *clsid = mapping->clsid;
619 return TRUE;
622 return FALSE;
625 static HMODULE load_com_dll(const char *name, char **path, char *filename)
627 HMODULE dll = NULL;
628 HKEY hkey;
629 char keyname[100];
630 char dllname[MAX_PATH];
631 char *p;
632 CLSID clsid;
634 if(!get_main_clsid(name, &clsid)) return NULL;
636 sprintf(keyname, "CLSID\\{%08x-%04x-%04x-%02x%2x-%02x%2x%02x%2x%02x%2x}\\InprocServer32",
637 clsid.Data1, clsid.Data2, clsid.Data3, clsid.Data4[0], clsid.Data4[1],
638 clsid.Data4[2], clsid.Data4[3], clsid.Data4[4], clsid.Data4[5],
639 clsid.Data4[6], clsid.Data4[7]);
641 if(RegOpenKeyA(HKEY_CLASSES_ROOT, keyname, &hkey) == ERROR_SUCCESS)
643 LONG size = sizeof(dllname);
644 if(RegQueryValueA(hkey, NULL, dllname, &size) == ERROR_SUCCESS)
646 if ((dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE)))
648 strcpy( filename, dllname );
649 p = strrchr(dllname, '\\');
650 if (p) *p = 0;
651 *path = heap_strdup( dllname );
654 RegCloseKey(hkey);
657 return dll;
660 static void get_dll_path(HMODULE dll, char **path, char *filename)
662 char dllpath[MAX_PATH];
664 GetModuleFileNameA(dll, dllpath, MAX_PATH);
665 strcpy(filename, dllpath);
666 *strrchr(dllpath, '\\') = '\0';
667 *path = heap_strdup( dllpath );
670 static BOOL CALLBACK
671 extract_test_proc (HMODULE hModule, LPCTSTR lpszType,
672 LPTSTR lpszName, LONG_PTR lParam)
674 const char *tempdir = (const char *)lParam;
675 char dllname[MAX_PATH];
676 char filename[MAX_PATH];
677 WCHAR dllnameW[MAX_PATH];
678 HMODULE dll;
679 DWORD err;
681 if (aborting) return TRUE;
682 if (test_filtered_out( lpszName, NULL )) return TRUE;
684 /* Check if the main dll is present on this system */
685 CharLowerA(lpszName);
686 strcpy(dllname, lpszName);
687 *strstr(dllname, testexe) = 0;
689 wine_tests[nr_of_files].maindllpath = NULL;
690 strcpy(filename, dllname);
691 dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE);
693 if (!dll) dll = load_com_dll(dllname, &wine_tests[nr_of_files].maindllpath, filename);
695 if (!dll && pLoadLibraryShim)
697 MultiByteToWideChar(CP_ACP, 0, dllname, -1, dllnameW, MAX_PATH);
698 if (SUCCEEDED( pLoadLibraryShim(dllnameW, NULL, NULL, &dll) ) && dll)
700 get_dll_path(dll, &wine_tests[nr_of_files].maindllpath, filename);
701 FreeLibrary(dll);
702 dll = LoadLibraryExA(filename, NULL, LOAD_LIBRARY_AS_DATAFILE);
704 else dll = 0;
707 if (!dll)
709 xprintf (" %s=dll is missing\n", dllname);
710 return TRUE;
712 if (is_native_dll(dll))
714 FreeLibrary(dll);
715 xprintf (" %s=load error Configured as native\n", dllname);
716 nr_native_dlls++;
717 return TRUE;
719 FreeLibrary(dll);
721 if (!(err = get_subtests( tempdir, &wine_tests[nr_of_files], lpszName )))
723 xprintf (" %s=%s\n", dllname, get_file_version(filename));
724 nr_of_tests += wine_tests[nr_of_files].subtest_count;
725 nr_of_files++;
727 else
729 xprintf (" %s=load error %u\n", dllname, err);
731 return TRUE;
734 static char *
735 run_tests (char *logname, char *outdir)
737 int i;
738 char *strres, *eol, *nextline;
739 DWORD strsize;
740 SECURITY_ATTRIBUTES sa;
741 char tmppath[MAX_PATH], tempdir[MAX_PATH+4];
742 DWORD needed;
744 /* Get the current PATH only once */
745 needed = GetEnvironmentVariableA("PATH", NULL, 0);
746 curpath = heap_alloc(needed);
747 GetEnvironmentVariableA("PATH", curpath, needed);
749 SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
751 if (!GetTempPathA( MAX_PATH, tmppath ))
752 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
754 if (!logname) {
755 static char tmpname[MAX_PATH];
756 if (!GetTempFileNameA( tmppath, "res", 0, tmpname ))
757 report (R_FATAL, "Can't name logfile.");
758 logname = tmpname;
760 report (R_OUT, logname);
762 /* make handle inheritable */
763 sa.nLength = sizeof(sa);
764 sa.lpSecurityDescriptor = NULL;
765 sa.bInheritHandle = TRUE;
767 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
768 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
769 &sa, CREATE_ALWAYS, 0, NULL );
771 if ((logfile == INVALID_HANDLE_VALUE) &&
772 (GetLastError() == ERROR_INVALID_PARAMETER)) {
773 /* FILE_SHARE_DELETE not supported on win9x */
774 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
775 FILE_SHARE_READ | FILE_SHARE_WRITE,
776 &sa, CREATE_ALWAYS, 0, NULL );
778 if (logfile == INVALID_HANDLE_VALUE)
779 report (R_FATAL, "Could not open logfile: %u", GetLastError());
781 /* try stable path for ZoneAlarm */
782 if (!outdir) {
783 strcpy( tempdir, tmppath );
784 strcat( tempdir, "wct" );
786 if (!CreateDirectoryA( tempdir, NULL ))
788 if (!GetTempFileNameA( tmppath, "wct", 0, tempdir ))
789 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
790 DeleteFileA( tempdir );
791 if (!CreateDirectoryA( tempdir, NULL ))
792 report (R_FATAL, "Could not create directory: %s", tempdir);
795 else
796 strcpy( tempdir, outdir);
798 report (R_DIR, tempdir);
800 xprintf ("Version 4\n");
801 xprintf ("Tests from build %s\n", build_id[0] ? build_id : "-" );
802 xprintf ("Archive: -\n"); /* no longer used */
803 xprintf ("Tag: %s\n", tag);
804 xprintf ("Build info:\n");
805 strres = extract_rcdata ("BUILD_INFO", "STRINGRES", &strsize);
806 while (strres) {
807 eol = memchr (strres, '\n', strsize);
808 if (!eol) {
809 nextline = NULL;
810 eol = strres + strsize;
811 } else {
812 strsize -= eol - strres + 1;
813 nextline = strsize?eol+1:NULL;
814 if (eol > strres && *(eol-1) == '\r') eol--;
816 xprintf (" %.*s\n", eol-strres, strres);
817 strres = nextline;
819 xprintf ("Operating system version:\n");
820 print_version ();
821 xprintf ("Dll info:\n" );
823 report (R_STATUS, "Counting tests");
824 if (!EnumResourceNames (NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
825 report (R_FATAL, "Can't enumerate test files: %d",
826 GetLastError ());
827 wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0]);
829 /* Do this only once during extraction (and version checking) */
830 hmscoree = LoadLibraryA("mscoree.dll");
831 pLoadLibraryShim = NULL;
832 if (hmscoree)
833 pLoadLibraryShim = (void *)GetProcAddress(hmscoree, "LoadLibraryShim");
835 report (R_STATUS, "Extracting tests");
836 report (R_PROGRESS, 0, nr_of_files);
837 nr_of_files = 0;
838 nr_of_tests = 0;
839 if (!EnumResourceNames (NULL, "TESTRES", extract_test_proc, (LPARAM)tempdir))
840 report (R_FATAL, "Can't enumerate test files: %d",
841 GetLastError ());
843 FreeLibrary(hmscoree);
845 if (aborting) return logname;
847 xprintf ("Test output:\n" );
849 report (R_DELTA, 0, "Extracting: Done");
851 if (nr_native_dlls)
852 report( R_WARNING, "Some dlls are configured as native, you won't be able to submit results." );
854 report (R_STATUS, "Running tests");
855 report (R_PROGRESS, 1, nr_of_tests);
856 for (i = 0; i < nr_of_files; i++) {
857 struct wine_test *test = wine_tests + i;
858 int j;
860 if (aborting) break;
862 if (test->maindllpath) {
863 /* We need to add the path (to the main dll) to PATH */
864 append_path(test->maindllpath);
867 for (j = 0; j < test->subtest_count; j++) {
868 if (aborting) break;
869 report (R_STEP, "Running: %s:%s", test->name,
870 test->subtests[j]);
871 run_test (test, test->subtests[j], logfile, tempdir);
874 if (test->maindllpath) {
875 /* Restore PATH again */
876 SetEnvironmentVariableA("PATH", curpath);
879 report (R_DELTA, 0, "Running: Done");
881 report (R_STATUS, "Cleaning up");
882 CloseHandle( logfile );
883 logfile = 0;
884 if (!outdir)
885 remove_dir (tempdir);
886 heap_free(wine_tests);
887 heap_free(curpath);
889 return logname;
892 static BOOL WINAPI ctrl_handler(DWORD ctrl_type)
894 if (ctrl_type == CTRL_C_EVENT) {
895 printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
896 return TRUE;
899 return FALSE;
903 static BOOL CALLBACK
904 extract_only_proc (HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG_PTR lParam)
906 const char *target_dir = (const char *)lParam;
907 char filename[MAX_PATH];
909 if (test_filtered_out( lpszName, NULL )) return TRUE;
911 strcpy(filename, lpszName);
912 CharLowerA(filename);
914 extract_test( &wine_tests[nr_of_files], target_dir, filename );
915 nr_of_files++;
916 return TRUE;
919 static void extract_only (const char *target_dir)
921 BOOL res;
923 report (R_DIR, target_dir);
924 res = CreateDirectoryA( target_dir, NULL );
925 if (!res && GetLastError() != ERROR_ALREADY_EXISTS)
926 report (R_FATAL, "Could not create directory: %s (%d)", target_dir, GetLastError ());
928 nr_of_files = 0;
929 report (R_STATUS, "Counting tests");
930 if (!EnumResourceNames (NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
931 report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
933 wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0] );
935 report (R_STATUS, "Extracting tests");
936 report (R_PROGRESS, 0, nr_of_files);
937 nr_of_files = 0;
938 if (!EnumResourceNames (NULL, "TESTRES", extract_only_proc, (LPARAM)target_dir))
939 report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
941 report (R_DELTA, 0, "Extracting: Done");
944 static void
945 usage (void)
947 fprintf (stderr,
948 "Usage: winetest [OPTION]... [TESTS]\n\n"
949 " --help print this message and exit\n"
950 " --version print the build version and exit\n"
951 " -c console mode, no GUI\n"
952 " -d DIR Use DIR as temp directory (default: %%TEMP%%\\wct)\n"
953 " -e preserve the environment\n"
954 " -h print this message and exit\n"
955 " -m MAIL an email address to enable developers to contact you\n"
956 " -p shutdown when the tests are done\n"
957 " -q quiet mode, no output at all\n"
958 " -o FILE put report into FILE, do not submit\n"
959 " -s FILE submit FILE, do not run tests\n"
960 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n"
961 " -x DIR Extract tests to DIR (default: .\\wct) and exit\n");
964 int main( int argc, char *argv[] )
966 char *logname = NULL, *outdir = NULL;
967 const char *extract = NULL;
968 const char *cp, *submit = NULL;
969 int reset_env = 1;
970 int poweroff = 0;
971 int interactive = 1;
972 int i;
974 if (!LoadStringA( 0, IDS_BUILD_ID, build_id, sizeof(build_id) )) build_id[0] = 0;
976 for (i = 1; i < argc && argv[i]; i++)
978 if (!strcmp(argv[i], "--help")) {
979 usage ();
980 exit (0);
982 else if (!strcmp(argv[i], "--version")) {
983 printf("%-12.12s\n", build_id[0] ? build_id : "unknown");
984 exit (0);
986 else if ((argv[i][0] != '-' && argv[i][0] != '/') || argv[i][2]) {
987 if (nb_filters == sizeof(filters)/sizeof(filters[0]))
989 report (R_ERROR, "Too many test filters specified");
990 exit (2);
992 filters[nb_filters++] = argv[i];
994 else switch (argv[i][1]) {
995 case 'c':
996 report (R_TEXTMODE);
997 interactive = 0;
998 break;
999 case 'e':
1000 reset_env = 0;
1001 break;
1002 case 'h':
1003 case '?':
1004 usage ();
1005 exit (0);
1006 case 'm':
1007 if (!(email = argv[++i]))
1009 usage();
1010 exit( 2 );
1012 break;
1013 case 'p':
1014 poweroff = 1;
1015 break;
1016 case 'q':
1017 report (R_QUIET);
1018 interactive = 0;
1019 break;
1020 case 's':
1021 if (!(submit = argv[++i]))
1023 usage();
1024 exit( 2 );
1026 if (tag)
1027 report (R_WARNING, "ignoring tag for submission");
1028 send_file (submit);
1029 break;
1030 case 'o':
1031 if (!(logname = argv[++i]))
1033 usage();
1034 exit( 2 );
1036 break;
1037 case 't':
1038 if (!(tag = argv[++i]))
1040 usage();
1041 exit( 2 );
1043 if (strlen (tag) > MAXTAGLEN)
1044 report (R_FATAL, "tag is too long (maximum %d characters)",
1045 MAXTAGLEN);
1046 cp = findbadtagchar (tag);
1047 if (cp) {
1048 report (R_ERROR, "invalid char in tag: %c", *cp);
1049 usage ();
1050 exit (2);
1052 break;
1053 case 'x':
1054 report (R_TEXTMODE);
1055 if (!(extract = argv[++i]))
1056 extract = ".\\wct";
1058 extract_only (extract);
1059 break;
1060 case 'd':
1061 outdir = argv[++i];
1062 break;
1063 default:
1064 report (R_ERROR, "invalid option: -%c", argv[i][1]);
1065 usage ();
1066 exit (2);
1069 if (!submit && !extract) {
1070 report (R_STATUS, "Starting up");
1072 if (!running_on_visible_desktop ())
1073 report (R_FATAL, "Tests must be run on a visible desktop");
1075 if (!check_mount_mgr())
1076 report (R_FATAL, "Mount manager not running, most likely your WINEPREFIX wasn't created correctly.");
1078 if (!check_display_driver())
1079 report (R_FATAL, "Unable to create a window, the display driver is not working.");
1081 SetConsoleCtrlHandler(ctrl_handler, TRUE);
1083 if (reset_env)
1085 SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
1086 SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
1087 SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
1088 SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
1091 if (!nb_filters) /* don't submit results when filtering */
1093 while (!tag) {
1094 if (!interactive)
1095 report (R_FATAL, "Please specify a tag (-t option) if "
1096 "running noninteractive!");
1097 if (guiAskTag () == IDABORT) exit (1);
1099 report (R_TAG);
1101 while (!email) {
1102 if (!interactive)
1103 report (R_FATAL, "Please specify an email address (-m option) to enable developers\n"
1104 " to contact you about your report if necessary.");
1105 if (guiAskEmail () == IDABORT) exit (1);
1108 if (!build_id[0])
1109 report( R_WARNING, "You won't be able to submit results without a valid build id.\n"
1110 "To submit results, winetest needs to be built from a git checkout." );
1113 if (!logname) {
1114 logname = run_tests (NULL, outdir);
1115 if (aborting) {
1116 DeleteFileA(logname);
1117 exit (0);
1119 if (build_id[0] && !nb_filters && !nr_native_dlls &&
1120 report (R_ASK, MB_YESNO, "Do you want to submit the test results?") == IDYES)
1121 if (!send_file (logname) && !DeleteFileA(logname))
1122 report (R_WARNING, "Can't remove logfile: %u", GetLastError());
1123 } else run_tests (logname, outdir);
1124 report (R_STATUS, "Finished");
1126 if (poweroff)
1128 HANDLE hToken;
1129 TOKEN_PRIVILEGES npr;
1131 /* enable the shutdown privilege for the current process */
1132 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
1134 LookupPrivilegeValueA(0, SE_SHUTDOWN_NAME, &npr.Privileges[0].Luid);
1135 npr.PrivilegeCount = 1;
1136 npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1137 AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
1138 CloseHandle(hToken);
1140 ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);
1142 exit (0);