atl: Fix formatting of generated class name for 64-bit.
[wine/multimedia.git] / programs / winetest / main.c
blob3eabf5f675c45d6b078b986fc7e85d574891863f
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 static struct wine_test *wine_tests;
53 static int nr_of_files, nr_of_tests;
54 static int nr_native_dlls;
55 static const char whitespace[] = " \t\r\n";
56 static const char testexe[] = "_test.exe";
57 static char build_id[64];
59 /* filters for running only specific tests */
60 static char *filters[64];
61 static unsigned int nb_filters = 0;
63 /* Needed to check for .NET dlls */
64 static HMODULE hmscoree;
65 static HRESULT (WINAPI *pLoadLibraryShim)(LPCWSTR, LPCWSTR, LPVOID, HMODULE *);
67 /* To store the current PATH setting (related to .NET only provided dlls) */
68 static char *curpath;
70 /* check if test is being filtered out */
71 static BOOL test_filtered_out( LPCSTR module, LPCSTR testname )
73 char *p, dllname[MAX_PATH];
74 unsigned int i, len;
76 strcpy( dllname, module );
77 CharLowerA( dllname );
78 p = strstr( dllname, testexe );
79 if (p) *p = 0;
80 len = strlen(dllname);
82 if (!nb_filters) return FALSE;
83 for (i = 0; i < nb_filters; i++)
85 if (!strncmp( dllname, filters[i], len ))
87 if (!filters[i][len]) return FALSE;
88 if (filters[i][len] != ':') continue;
89 if (!testname || !strcmp( testname, &filters[i][len+1] )) return FALSE;
92 return TRUE;
95 static char * get_file_version(char * file_name)
97 static char version[32];
98 DWORD size;
99 DWORD handle;
101 size = GetFileVersionInfoSizeA(file_name, &handle);
102 if (size) {
103 char * data = heap_alloc(size);
104 if (data) {
105 if (GetFileVersionInfoA(file_name, handle, size, data)) {
106 static char backslash[] = "\\";
107 VS_FIXEDFILEINFO *pFixedVersionInfo;
108 UINT len;
109 if (VerQueryValueA(data, backslash, (LPVOID *)&pFixedVersionInfo, &len)) {
110 sprintf(version, "%d.%d.%d.%d",
111 pFixedVersionInfo->dwFileVersionMS >> 16,
112 pFixedVersionInfo->dwFileVersionMS & 0xffff,
113 pFixedVersionInfo->dwFileVersionLS >> 16,
114 pFixedVersionInfo->dwFileVersionLS & 0xffff);
115 } else
116 sprintf(version, "version not available");
117 } else
118 sprintf(version, "unknown");
119 heap_free(data);
120 } else
121 sprintf(version, "failed");
122 } else
123 sprintf(version, "version not available");
125 return version;
128 static int running_under_wine (void)
130 HMODULE module = GetModuleHandleA("ntdll.dll");
132 if (!module) return 0;
133 return (GetProcAddress(module, "wine_server_call") != NULL);
136 static int check_mount_mgr(void)
138 if (running_under_wine())
140 HANDLE handle = CreateFileA( "\\\\.\\MountPointManager", GENERIC_READ,
141 FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
142 if (handle == INVALID_HANDLE_VALUE) return FALSE;
143 CloseHandle( handle );
145 return TRUE;
148 static int check_display_driver(void)
150 if (running_under_wine())
152 HWND hwnd = CreateWindowA( "STATIC", "", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
153 0, 0, GetModuleHandleA(0), 0 );
154 if (!hwnd) return FALSE;
155 DestroyWindow( hwnd );
157 return TRUE;
160 static int running_on_visible_desktop (void)
162 HWND desktop;
163 HMODULE huser32 = GetModuleHandle("user32.dll");
164 HWINSTA (WINAPI *pGetProcessWindowStation)(void);
165 BOOL (WINAPI *pGetUserObjectInformationA)(HANDLE,INT,LPVOID,DWORD,LPDWORD);
167 pGetProcessWindowStation = (void *)GetProcAddress(huser32, "GetProcessWindowStation");
168 pGetUserObjectInformationA = (void *)GetProcAddress(huser32, "GetUserObjectInformationA");
170 desktop = GetDesktopWindow();
171 if (!GetWindowLongPtrW(desktop, GWLP_WNDPROC)) /* Win9x */
172 return IsWindowVisible(desktop);
174 if (pGetProcessWindowStation && pGetUserObjectInformationA)
176 DWORD len;
177 HWINSTA wstation;
178 USEROBJECTFLAGS uoflags;
180 wstation = (HWINSTA)pGetProcessWindowStation();
181 assert(pGetUserObjectInformationA(wstation, UOI_FLAGS, &uoflags, sizeof(uoflags), &len));
182 return (uoflags.dwFlags & WSF_VISIBLE) != 0;
184 return IsWindowVisible(desktop);
187 /* check for native dll when running under wine */
188 static BOOL is_native_dll( HMODULE module )
190 static const char fakedll_signature[] = "Wine placeholder DLL";
191 const IMAGE_DOS_HEADER *dos;
193 if (!running_under_wine()) return FALSE;
194 if (!((ULONG_PTR)module & 1)) return FALSE; /* not loaded as datafile */
195 /* builtin dlls can't be loaded as datafile, so we must have native or fake dll */
196 dos = (const IMAGE_DOS_HEADER *)((const char *)module - 1);
197 if (dos->e_magic != IMAGE_DOS_SIGNATURE) return FALSE;
198 if (dos->e_lfanew >= sizeof(*dos) + sizeof(fakedll_signature) &&
199 !memcmp( dos + 1, fakedll_signature, sizeof(fakedll_signature) )) return FALSE;
200 return TRUE;
203 static void print_version (void)
205 #ifdef __i386__
206 static const char platform[] = "i386";
207 #elif defined(__x86_64__)
208 static const char platform[] = "x86_64";
209 #elif defined(__sparc__)
210 static const char platform[] = "sparc";
211 #elif defined(__ALPHA__)
212 static const char platform[] = "alpha";
213 #elif defined(__powerpc__)
214 static const char platform[] = "powerpc";
215 #endif
216 OSVERSIONINFOEX ver;
217 BOOL ext, wow64;
218 int is_win2k3_r2;
219 const char *(CDECL *wine_get_build_id)(void);
220 void (CDECL *wine_get_host_version)( const char **sysname, const char **release );
221 BOOL (WINAPI *pIsWow64Process)(HANDLE hProcess, PBOOL Wow64Process);
222 BOOL (WINAPI *pGetProductInfo)(DWORD, DWORD, DWORD, DWORD, DWORD *);
224 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
225 if (!(ext = GetVersionEx ((OSVERSIONINFO *) &ver)))
227 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
228 if (!GetVersionEx ((OSVERSIONINFO *) &ver))
229 report (R_FATAL, "Can't get OS version.");
231 pIsWow64Process = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
232 if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &wow64 )) wow64 = FALSE;
234 xprintf (" Platform=%s%s\n", platform, wow64 ? " (WOW64)" : "");
235 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
236 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
237 xprintf (" Submitter=%s\n", email );
238 xprintf (" dwMajorVersion=%u\n dwMinorVersion=%u\n"
239 " dwBuildNumber=%u\n PlatformId=%u\n szCSDVersion=%s\n",
240 ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber,
241 ver.dwPlatformId, ver.szCSDVersion);
243 wine_get_build_id = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_build_id");
244 wine_get_host_version = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_host_version");
245 if (wine_get_build_id) xprintf( " WineBuild=%s\n", wine_get_build_id() );
246 if (wine_get_host_version)
248 const char *sysname, *release;
249 wine_get_host_version( &sysname, &release );
250 xprintf( " Host system=%s\n Host version=%s\n", sysname, release );
252 is_win2k3_r2 = GetSystemMetrics(SM_SERVERR2);
253 if(is_win2k3_r2)
254 xprintf(" R2 build number=%d\n", is_win2k3_r2);
256 if (!ext) return;
258 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
259 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
260 ver.wServicePackMajor, ver.wServicePackMinor, ver.wSuiteMask,
261 ver.wProductType, ver.wReserved);
263 pGetProductInfo = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"GetProductInfo");
264 if (pGetProductInfo && !running_under_wine())
266 DWORD prodtype = 0;
268 pGetProductInfo(ver.dwMajorVersion, ver.dwMinorVersion, ver.wServicePackMajor, ver.wServicePackMinor, &prodtype);
269 xprintf(" dwProductInfo=%u\n", prodtype);
273 static inline int is_dot_dir(const char* x)
275 return ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))));
278 static void remove_dir (const char *dir)
280 HANDLE hFind;
281 WIN32_FIND_DATA wfd;
282 char path[MAX_PATH];
283 size_t dirlen = strlen (dir);
285 /* Make sure the directory exists before going further */
286 memcpy (path, dir, dirlen);
287 strcpy (path + dirlen++, "\\*");
288 hFind = FindFirstFile (path, &wfd);
289 if (hFind == INVALID_HANDLE_VALUE) return;
291 do {
292 char *lp = wfd.cFileName;
294 if (!lp[0]) lp = wfd.cAlternateFileName; /* ? FIXME not (!lp) ? */
295 if (is_dot_dir (lp)) continue;
296 strcpy (path + dirlen, lp);
297 if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
298 remove_dir(path);
299 else if (!DeleteFile (path))
300 report (R_WARNING, "Can't delete file %s: error %d",
301 path, GetLastError ());
302 } while (FindNextFile (hFind, &wfd));
303 FindClose (hFind);
304 if (!RemoveDirectory (dir))
305 report (R_WARNING, "Can't remove directory %s: error %d",
306 dir, GetLastError ());
309 static const char* get_test_source_file(const char* test, const char* subtest)
311 static const char* special_dirs[][2] = {
312 { 0, 0 }
314 static char buffer[MAX_PATH];
315 int i, len = strlen(test);
317 if (len > 4 && !strcmp( test + len - 4, ".exe" ))
319 len = sprintf(buffer, "programs/%s", test) - 4;
320 buffer[len] = 0;
322 else len = sprintf(buffer, "dlls/%s", test);
324 for (i = 0; special_dirs[i][0]; i++) {
325 if (strcmp(test, special_dirs[i][0]) == 0) {
326 strcpy( buffer, special_dirs[i][1] );
327 len = strlen(buffer);
328 break;
332 sprintf(buffer + len, "/tests/%s.c", subtest);
333 return buffer;
336 static void* extract_rcdata (LPCTSTR name, LPCTSTR type, DWORD* size)
338 HRSRC rsrc;
339 HGLOBAL hdl;
340 LPVOID addr;
342 if (!(rsrc = FindResource (NULL, name, type)) ||
343 !(*size = SizeofResource (0, rsrc)) ||
344 !(hdl = LoadResource (0, rsrc)) ||
345 !(addr = LockResource (hdl)))
346 return NULL;
347 return addr;
350 /* Fills in the name and exename fields */
351 static void
352 extract_test (struct wine_test *test, const char *dir, LPTSTR res_name)
354 BYTE* code;
355 DWORD size;
356 char *exepos;
357 HANDLE hfile;
358 DWORD written;
360 code = extract_rcdata (res_name, "TESTRES", &size);
361 if (!code) report (R_FATAL, "Can't find test resource %s: %d",
362 res_name, GetLastError ());
363 test->name = heap_strdup( res_name );
364 test->exename = strmake (NULL, "%s\\%s", dir, test->name);
365 exepos = strstr (test->name, testexe);
366 if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name);
367 *exepos = 0;
368 test->name = heap_realloc (test->name, exepos - test->name + 1);
369 report (R_STEP, "Extracting: %s", test->name);
371 hfile = CreateFileA(test->exename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
372 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
373 if (hfile == INVALID_HANDLE_VALUE)
374 report (R_FATAL, "Failed to open file %s.", test->exename);
376 if (!WriteFile(hfile, code, size, &written, NULL))
377 report (R_FATAL, "Failed to write file %s.", test->exename);
379 CloseHandle(hfile);
382 static DWORD wait_process( HANDLE process, DWORD timeout )
384 DWORD wait, diff = 0, start = GetTickCount();
385 MSG msg;
387 while (diff < timeout)
389 wait = MsgWaitForMultipleObjects( 1, &process, FALSE, timeout - diff, QS_ALLINPUT );
390 if (wait != WAIT_OBJECT_0 + 1) return wait;
391 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
392 diff = GetTickCount() - start;
394 return WAIT_TIMEOUT;
397 static void append_path( const char *path)
399 char *newpath;
401 newpath = heap_alloc(strlen(curpath) + 1 + strlen(path) + 1);
402 strcpy(newpath, curpath);
403 strcat(newpath, ";");
404 strcat(newpath, path);
405 SetEnvironmentVariableA("PATH", newpath);
407 heap_free(newpath);
410 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
411 stdout to there.
413 Return the exit status, -2 if can't create process or the return
414 value of WaitForSingleObject.
416 static int
417 run_ex (char *cmd, HANDLE out_file, const char *tempdir, DWORD ms)
419 STARTUPINFO si;
420 PROCESS_INFORMATION pi;
421 DWORD wait, status;
423 GetStartupInfo (&si);
424 si.dwFlags = STARTF_USESTDHANDLES;
425 si.hStdInput = GetStdHandle( STD_INPUT_HANDLE );
426 si.hStdOutput = out_file ? out_file : GetStdHandle( STD_OUTPUT_HANDLE );
427 si.hStdError = out_file ? out_file : GetStdHandle( STD_ERROR_HANDLE );
429 if (!CreateProcessA (NULL, cmd, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE,
430 NULL, tempdir, &si, &pi))
431 return -2;
433 CloseHandle (pi.hThread);
434 status = wait_process( pi.hProcess, ms );
435 switch (status)
437 case WAIT_OBJECT_0:
438 GetExitCodeProcess (pi.hProcess, &status);
439 CloseHandle (pi.hProcess);
440 return status;
441 case WAIT_FAILED:
442 report (R_ERROR, "Wait for '%s' failed: %d", cmd, GetLastError ());
443 break;
444 case WAIT_TIMEOUT:
445 break;
446 default:
447 report (R_ERROR, "Wait returned %d", status);
448 break;
450 if (!TerminateProcess (pi.hProcess, 257))
451 report (R_ERROR, "TerminateProcess failed: %d", GetLastError ());
452 wait = wait_process( pi.hProcess, 5000 );
453 switch (wait)
455 case WAIT_OBJECT_0:
456 break;
457 case WAIT_FAILED:
458 report (R_ERROR, "Wait for termination of '%s' failed: %d", cmd, GetLastError ());
459 break;
460 case WAIT_TIMEOUT:
461 report (R_ERROR, "Can't kill process '%s'", cmd);
462 break;
463 default:
464 report (R_ERROR, "Waiting for termination: %d", wait);
465 break;
467 CloseHandle (pi.hProcess);
468 return status;
471 static DWORD
472 get_subtests (const char *tempdir, struct wine_test *test, LPTSTR res_name)
474 char *cmd;
475 HANDLE subfile;
476 DWORD err, total;
477 char buffer[8192], *index;
478 static const char header[] = "Valid test names:";
479 int status, allocated;
480 char tmpdir[MAX_PATH], subname[MAX_PATH];
481 SECURITY_ATTRIBUTES sa;
483 test->subtest_count = 0;
485 if (!GetTempPathA( MAX_PATH, tmpdir ) ||
486 !GetTempFileNameA( tmpdir, "sub", 0, subname ))
487 report (R_FATAL, "Can't name subtests file.");
489 /* make handle inheritable */
490 sa.nLength = sizeof(sa);
491 sa.lpSecurityDescriptor = NULL;
492 sa.bInheritHandle = TRUE;
494 subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
495 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
496 &sa, CREATE_ALWAYS, 0, NULL );
498 if ((subfile == INVALID_HANDLE_VALUE) &&
499 (GetLastError() == ERROR_INVALID_PARAMETER)) {
500 /* FILE_SHARE_DELETE not supported on win9x */
501 subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
502 FILE_SHARE_READ | FILE_SHARE_WRITE,
503 &sa, CREATE_ALWAYS, 0, NULL );
505 if (subfile == INVALID_HANDLE_VALUE) {
506 err = GetLastError();
507 report (R_ERROR, "Can't open subtests output of %s: %u",
508 test->name, GetLastError());
509 goto quit;
512 extract_test (test, tempdir, res_name);
513 cmd = strmake (NULL, "%s --list", test->exename);
514 if (test->maindllpath) {
515 /* We need to add the path (to the main dll) to PATH */
516 append_path(test->maindllpath);
518 status = run_ex (cmd, subfile, tempdir, 5000);
519 err = GetLastError();
520 if (test->maindllpath) {
521 /* Restore PATH again */
522 SetEnvironmentVariableA("PATH", curpath);
524 heap_free (cmd);
526 if (status == -2)
528 report (R_ERROR, "Cannot run %s error %u", test->exename, err);
529 goto quit;
532 SetFilePointer( subfile, 0, NULL, FILE_BEGIN );
533 ReadFile( subfile, buffer, sizeof(buffer), &total, NULL );
534 CloseHandle( subfile );
535 if (sizeof buffer == total) {
536 report (R_ERROR, "Subtest list of %s too big.",
537 test->name, sizeof buffer);
538 err = ERROR_OUTOFMEMORY;
539 goto quit;
541 buffer[total] = 0;
543 index = strstr (buffer, header);
544 if (!index) {
545 report (R_ERROR, "Can't parse subtests output of %s",
546 test->name);
547 err = ERROR_INTERNAL_ERROR;
548 goto quit;
550 index += sizeof header;
552 allocated = 10;
553 test->subtests = heap_alloc (allocated * sizeof(char*));
554 index = strtok (index, whitespace);
555 while (index) {
556 if (test->subtest_count == allocated) {
557 allocated *= 2;
558 test->subtests = heap_realloc (test->subtests,
559 allocated * sizeof(char*));
561 if (!test_filtered_out( test->name, index ))
562 test->subtests[test->subtest_count++] = heap_strdup(index);
563 index = strtok (NULL, whitespace);
565 test->subtests = heap_realloc (test->subtests,
566 test->subtest_count * sizeof(char*));
567 err = 0;
569 quit:
570 if (!DeleteFileA (subname))
571 report (R_WARNING, "Can't delete file '%s': %u", subname, GetLastError());
572 return err;
575 static void
576 run_test (struct wine_test* test, const char* subtest, HANDLE out_file, const char *tempdir)
578 int status;
579 const char* file = get_test_source_file(test->name, subtest);
580 char *cmd = strmake (NULL, "%s %s", test->exename, subtest);
582 xprintf ("%s:%s start %s -\n", test->name, subtest, file);
583 status = run_ex (cmd, out_file, tempdir, 120000);
584 heap_free (cmd);
585 xprintf ("%s:%s done (%d)\n", test->name, subtest, status);
588 static BOOL CALLBACK
589 EnumTestFileProc (HMODULE hModule, LPCTSTR lpszType,
590 LPTSTR lpszName, LONG_PTR lParam)
592 if (!test_filtered_out( lpszName, NULL )) (*(int*)lParam)++;
593 return TRUE;
596 static const struct clsid_mapping
598 const char *name;
599 CLSID clsid;
600 } clsid_list[] =
602 {"oledb32", {0xc8b522d1, 0x5cf3, 0x11ce, {0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d}}},
603 {NULL, {0, 0, 0, {0,0,0,0,0,0,0,0}}}
607 static BOOL get_main_clsid(const char *name, CLSID *clsid)
609 const struct clsid_mapping *mapping;
611 for(mapping = clsid_list; mapping->name; mapping++)
613 if(!strcasecmp(name, mapping->name))
615 *clsid = mapping->clsid;
616 return TRUE;
619 return FALSE;
622 static HMODULE load_com_dll(const char *name, char **path, char *filename)
624 HMODULE dll = NULL;
625 HKEY hkey;
626 char keyname[100];
627 char dllname[MAX_PATH];
628 char *p;
629 CLSID clsid;
631 if(!get_main_clsid(name, &clsid)) return NULL;
633 sprintf(keyname, "CLSID\\{%08x-%04x-%04x-%02x%2x-%02x%2x%02x%2x%02x%2x}\\InprocServer32",
634 clsid.Data1, clsid.Data2, clsid.Data3, clsid.Data4[0], clsid.Data4[1],
635 clsid.Data4[2], clsid.Data4[3], clsid.Data4[4], clsid.Data4[5],
636 clsid.Data4[6], clsid.Data4[7]);
638 if(RegOpenKeyA(HKEY_CLASSES_ROOT, keyname, &hkey) == ERROR_SUCCESS)
640 LONG size = sizeof(dllname);
641 if(RegQueryValueA(hkey, NULL, dllname, &size) == ERROR_SUCCESS)
643 if ((dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE)))
645 strcpy( filename, dllname );
646 p = strrchr(dllname, '\\');
647 if (p) *p = 0;
648 *path = heap_strdup( dllname );
651 RegCloseKey(hkey);
654 return dll;
657 static void get_dll_path(HMODULE dll, char **path, char *filename)
659 char dllpath[MAX_PATH];
661 GetModuleFileNameA(dll, dllpath, MAX_PATH);
662 strcpy(filename, dllpath);
663 *strrchr(dllpath, '\\') = '\0';
664 *path = heap_strdup( dllpath );
667 static BOOL CALLBACK
668 extract_test_proc (HMODULE hModule, LPCTSTR lpszType,
669 LPTSTR lpszName, LONG_PTR lParam)
671 const char *tempdir = (const char *)lParam;
672 char dllname[MAX_PATH];
673 char filename[MAX_PATH];
674 WCHAR dllnameW[MAX_PATH];
675 HMODULE dll;
676 DWORD err;
678 if (test_filtered_out( lpszName, NULL )) return TRUE;
680 /* Check if the main dll is present on this system */
681 CharLowerA(lpszName);
682 strcpy(dllname, lpszName);
683 *strstr(dllname, testexe) = 0;
685 wine_tests[nr_of_files].maindllpath = NULL;
686 strcpy(filename, dllname);
687 dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE);
689 if (!dll) dll = load_com_dll(dllname, &wine_tests[nr_of_files].maindllpath, filename);
691 if (!dll && pLoadLibraryShim)
693 MultiByteToWideChar(CP_ACP, 0, dllname, -1, dllnameW, MAX_PATH);
694 if (SUCCEEDED( pLoadLibraryShim(dllnameW, NULL, NULL, &dll) ) && dll)
696 get_dll_path(dll, &wine_tests[nr_of_files].maindllpath, filename);
697 FreeLibrary(dll);
698 dll = LoadLibraryExA(filename, NULL, LOAD_LIBRARY_AS_DATAFILE);
700 else dll = 0;
703 if (!dll)
705 xprintf (" %s=dll is missing\n", dllname);
706 return TRUE;
708 if (is_native_dll(dll))
710 FreeLibrary(dll);
711 xprintf (" %s=load error Configured as native\n", dllname);
712 nr_native_dlls++;
713 return TRUE;
715 FreeLibrary(dll);
717 if (!(err = get_subtests( tempdir, &wine_tests[nr_of_files], lpszName )))
719 xprintf (" %s=%s\n", dllname, get_file_version(filename));
720 nr_of_tests += wine_tests[nr_of_files].subtest_count;
721 nr_of_files++;
723 else
725 xprintf (" %s=load error %u\n", dllname, err);
727 return TRUE;
730 static char *
731 run_tests (char *logname, char *outdir)
733 int i;
734 char *strres, *eol, *nextline;
735 DWORD strsize;
736 SECURITY_ATTRIBUTES sa;
737 char tmppath[MAX_PATH], tempdir[MAX_PATH+4];
738 DWORD needed;
740 /* Get the current PATH only once */
741 needed = GetEnvironmentVariableA("PATH", NULL, 0);
742 curpath = heap_alloc(needed);
743 GetEnvironmentVariableA("PATH", curpath, needed);
745 SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
747 if (!GetTempPathA( MAX_PATH, tmppath ))
748 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
750 if (!logname) {
751 static char tmpname[MAX_PATH];
752 if (!GetTempFileNameA( tmppath, "res", 0, tmpname ))
753 report (R_FATAL, "Can't name logfile.");
754 logname = tmpname;
756 report (R_OUT, logname);
758 /* make handle inheritable */
759 sa.nLength = sizeof(sa);
760 sa.lpSecurityDescriptor = NULL;
761 sa.bInheritHandle = TRUE;
763 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
764 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
765 &sa, CREATE_ALWAYS, 0, NULL );
767 if ((logfile == INVALID_HANDLE_VALUE) &&
768 (GetLastError() == ERROR_INVALID_PARAMETER)) {
769 /* FILE_SHARE_DELETE not supported on win9x */
770 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
771 FILE_SHARE_READ | FILE_SHARE_WRITE,
772 &sa, CREATE_ALWAYS, 0, NULL );
774 if (logfile == INVALID_HANDLE_VALUE)
775 report (R_FATAL, "Could not open logfile: %u", GetLastError());
777 /* try stable path for ZoneAlarm */
778 if (!outdir) {
779 strcpy( tempdir, tmppath );
780 strcat( tempdir, "wct" );
782 if (!CreateDirectoryA( tempdir, NULL ))
784 if (!GetTempFileNameA( tmppath, "wct", 0, tempdir ))
785 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
786 DeleteFileA( tempdir );
787 if (!CreateDirectoryA( tempdir, NULL ))
788 report (R_FATAL, "Could not create directory: %s", tempdir);
791 else
792 strcpy( tempdir, outdir);
794 report (R_DIR, tempdir);
796 xprintf ("Version 4\n");
797 xprintf ("Tests from build %s\n", build_id[0] ? build_id : "-" );
798 xprintf ("Archive: -\n"); /* no longer used */
799 xprintf ("Tag: %s\n", tag);
800 xprintf ("Build info:\n");
801 strres = extract_rcdata ("BUILD_INFO", "STRINGRES", &strsize);
802 while (strres) {
803 eol = memchr (strres, '\n', strsize);
804 if (!eol) {
805 nextline = NULL;
806 eol = strres + strsize;
807 } else {
808 strsize -= eol - strres + 1;
809 nextline = strsize?eol+1:NULL;
810 if (eol > strres && *(eol-1) == '\r') eol--;
812 xprintf (" %.*s\n", eol-strres, strres);
813 strres = nextline;
815 xprintf ("Operating system version:\n");
816 print_version ();
817 xprintf ("Dll info:\n" );
819 report (R_STATUS, "Counting tests");
820 if (!EnumResourceNames (NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
821 report (R_FATAL, "Can't enumerate test files: %d",
822 GetLastError ());
823 wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0]);
825 /* Do this only once during extraction (and version checking) */
826 hmscoree = LoadLibraryA("mscoree.dll");
827 pLoadLibraryShim = NULL;
828 if (hmscoree)
829 pLoadLibraryShim = (void *)GetProcAddress(hmscoree, "LoadLibraryShim");
831 report (R_STATUS, "Extracting tests");
832 report (R_PROGRESS, 0, nr_of_files);
833 nr_of_files = 0;
834 nr_of_tests = 0;
835 if (!EnumResourceNames (NULL, "TESTRES", extract_test_proc, (LPARAM)tempdir))
836 report (R_FATAL, "Can't enumerate test files: %d",
837 GetLastError ());
839 FreeLibrary(hmscoree);
841 xprintf ("Test output:\n" );
843 report (R_DELTA, 0, "Extracting: Done");
845 if (nr_native_dlls)
846 report( R_WARNING, "Some dlls are configured as native, you won't be able to submit results." );
848 report (R_STATUS, "Running tests");
849 report (R_PROGRESS, 1, nr_of_tests);
850 for (i = 0; i < nr_of_files; i++) {
851 struct wine_test *test = wine_tests + i;
852 int j;
854 if (test->maindllpath) {
855 /* We need to add the path (to the main dll) to PATH */
856 append_path(test->maindllpath);
859 for (j = 0; j < test->subtest_count; j++) {
860 report (R_STEP, "Running: %s:%s", test->name,
861 test->subtests[j]);
862 run_test (test, test->subtests[j], logfile, tempdir);
865 if (test->maindllpath) {
866 /* Restore PATH again */
867 SetEnvironmentVariableA("PATH", curpath);
870 report (R_DELTA, 0, "Running: Done");
872 report (R_STATUS, "Cleaning up");
873 CloseHandle( logfile );
874 logfile = 0;
875 if (!outdir)
876 remove_dir (tempdir);
877 heap_free(wine_tests);
878 heap_free(curpath);
880 return logname;
883 static BOOL WINAPI ctrl_handler(DWORD ctrl_type)
885 if (ctrl_type == CTRL_C_EVENT) {
886 printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
887 return TRUE;
890 return FALSE;
894 static BOOL CALLBACK
895 extract_only_proc (HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG_PTR lParam)
897 const char *target_dir = (const char *)lParam;
898 char filename[MAX_PATH];
900 if (test_filtered_out( lpszName, NULL )) return TRUE;
902 strcpy(filename, lpszName);
903 CharLowerA(filename);
905 extract_test( &wine_tests[nr_of_files], target_dir, filename );
906 nr_of_files++;
907 return TRUE;
910 static void extract_only (const char *target_dir)
912 BOOL res;
914 report (R_DIR, target_dir);
915 res = CreateDirectoryA( target_dir, NULL );
916 if (!res && GetLastError() != ERROR_ALREADY_EXISTS)
917 report (R_FATAL, "Could not create directory: %s (%d)", target_dir, GetLastError ());
919 nr_of_files = 0;
920 report (R_STATUS, "Counting tests");
921 if (!EnumResourceNames (NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
922 report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
924 wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0] );
926 report (R_STATUS, "Extracting tests");
927 report (R_PROGRESS, 0, nr_of_files);
928 nr_of_files = 0;
929 if (!EnumResourceNames (NULL, "TESTRES", extract_only_proc, (LPARAM)target_dir))
930 report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
932 report (R_DELTA, 0, "Extracting: Done");
935 static void
936 usage (void)
938 fprintf (stderr,
939 "Usage: winetest [OPTION]... [TESTS]\n\n"
940 " --help print this message and exit\n"
941 " --version print the build version and exit\n"
942 " -c console mode, no GUI\n"
943 " -d DIR Use DIR as temp directory (default: %%TEMP%%\\wct)\n"
944 " -e preserve the environment\n"
945 " -h print this message and exit\n"
946 " -m MAIL an email address to enable developers to contact you\n"
947 " -p shutdown when the tests are done\n"
948 " -q quiet mode, no output at all\n"
949 " -o FILE put report into FILE, do not submit\n"
950 " -s FILE submit FILE, do not run tests\n"
951 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n"
952 " -x DIR Extract tests to DIR (default: .\\wct) and exit\n");
955 int main( int argc, char *argv[] )
957 char *logname = NULL, *outdir = NULL;
958 const char *extract = NULL;
959 const char *cp, *submit = NULL;
960 int reset_env = 1;
961 int poweroff = 0;
962 int interactive = 1;
963 int i;
965 if (!LoadStringA( 0, IDS_BUILD_ID, build_id, sizeof(build_id) )) build_id[0] = 0;
967 for (i = 1; i < argc && argv[i]; i++)
969 if (!strcmp(argv[i], "--help")) {
970 usage ();
971 exit (0);
973 else if (!strcmp(argv[i], "--version")) {
974 printf("%-12.12s\n", build_id[0] ? build_id : "unknown");
975 exit (0);
977 else if ((argv[i][0] != '-' && argv[i][0] != '/') || argv[i][2]) {
978 if (nb_filters == sizeof(filters)/sizeof(filters[0]))
980 report (R_ERROR, "Too many test filters specified");
981 exit (2);
983 filters[nb_filters++] = argv[i];
985 else switch (argv[i][1]) {
986 case 'c':
987 report (R_TEXTMODE);
988 interactive = 0;
989 break;
990 case 'e':
991 reset_env = 0;
992 break;
993 case 'h':
994 case '?':
995 usage ();
996 exit (0);
997 case 'm':
998 if (!(email = argv[++i]))
1000 usage();
1001 exit( 2 );
1003 break;
1004 case 'p':
1005 poweroff = 1;
1006 break;
1007 case 'q':
1008 report (R_QUIET);
1009 interactive = 0;
1010 break;
1011 case 's':
1012 if (!(submit = argv[++i]))
1014 usage();
1015 exit( 2 );
1017 if (tag)
1018 report (R_WARNING, "ignoring tag for submission");
1019 send_file (submit);
1020 break;
1021 case 'o':
1022 if (!(logname = argv[++i]))
1024 usage();
1025 exit( 2 );
1027 break;
1028 case 't':
1029 if (!(tag = argv[++i]))
1031 usage();
1032 exit( 2 );
1034 if (strlen (tag) > MAXTAGLEN)
1035 report (R_FATAL, "tag is too long (maximum %d characters)",
1036 MAXTAGLEN);
1037 cp = findbadtagchar (tag);
1038 if (cp) {
1039 report (R_ERROR, "invalid char in tag: %c", *cp);
1040 usage ();
1041 exit (2);
1043 break;
1044 case 'x':
1045 report (R_TEXTMODE);
1046 if (!(extract = argv[++i]))
1047 extract = ".\\wct";
1049 extract_only (extract);
1050 break;
1051 case 'd':
1052 outdir = argv[++i];
1053 break;
1054 default:
1055 report (R_ERROR, "invalid option: -%c", argv[i][1]);
1056 usage ();
1057 exit (2);
1060 if (!submit && !extract) {
1061 report (R_STATUS, "Starting up");
1063 if (!running_on_visible_desktop ())
1064 report (R_FATAL, "Tests must be run on a visible desktop");
1066 if (!check_mount_mgr())
1067 report (R_FATAL, "Mount manager not running, most likely your WINEPREFIX wasn't created correctly.");
1069 if (!check_display_driver())
1070 report (R_FATAL, "Unable to create a window, the display driver is not working.");
1072 SetConsoleCtrlHandler(ctrl_handler, TRUE);
1074 if (reset_env)
1076 SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
1077 SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
1078 SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
1079 SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
1082 if (!nb_filters) /* don't submit results when filtering */
1084 while (!tag) {
1085 if (!interactive)
1086 report (R_FATAL, "Please specify a tag (-t option) if "
1087 "running noninteractive!");
1088 if (guiAskTag () == IDABORT) exit (1);
1090 report (R_TAG);
1092 while (!email) {
1093 if (!interactive)
1094 report (R_FATAL, "Please specify an email address (-m option) to enable developers\n"
1095 " to contact you about your report if necessary.");
1096 if (guiAskEmail () == IDABORT) exit (1);
1099 if (!build_id[0])
1100 report( R_WARNING, "You won't be able to submit results without a valid build id.\n"
1101 "To submit results, winetest needs to be built from a git checkout." );
1104 if (!logname) {
1105 logname = run_tests (NULL, outdir);
1106 if (build_id[0] && !nb_filters && !nr_native_dlls &&
1107 report (R_ASK, MB_YESNO, "Do you want to submit the test results?") == IDYES)
1108 if (!send_file (logname) && !DeleteFileA(logname))
1109 report (R_WARNING, "Can't remove logfile: %u", GetLastError());
1110 } else run_tests (logname, outdir);
1111 report (R_STATUS, "Finished");
1113 if (poweroff)
1115 HANDLE hToken;
1116 TOKEN_PRIVILEGES npr;
1118 /* enable the shutdown privilege for the current process */
1119 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
1121 LookupPrivilegeValueA(0, SE_SHUTDOWN_NAME, &npr.Privileges[0].Luid);
1122 npr.PrivilegeCount = 1;
1123 npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1124 AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
1125 CloseHandle(hToken);
1127 ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);
1129 exit (0);