msdaps: Add a stub rowset proxy object.
[wine/hramrach.git] / programs / winetest / main.c
blob69b7da69cb10f1d740194675c1fae0d5c9214082
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 static struct wine_test *wine_tests;
52 static int nr_of_files, nr_of_tests;
53 static int nr_native_dlls;
54 static const char whitespace[] = " \t\r\n";
55 static const char testexe[] = "_test.exe";
56 static char build_id[64];
58 /* filters for running only specific tests */
59 static char *filters[64];
60 static unsigned int nb_filters = 0;
62 /* Needed to check for .NET dlls */
63 static HMODULE hmscoree;
64 static HRESULT (WINAPI *pLoadLibraryShim)(LPCWSTR, LPCWSTR, LPVOID, HMODULE *);
66 /* To store the current PATH setting (related to .NET only provided dlls) */
67 static char *curpath;
69 /* check if test is being filtered out */
70 static BOOL test_filtered_out( LPCSTR module, LPCSTR testname )
72 char *p, dllname[MAX_PATH];
73 unsigned int i, len;
75 strcpy( dllname, module );
76 CharLowerA( dllname );
77 p = strstr( dllname, testexe );
78 if (p) *p = 0;
79 len = strlen(dllname);
81 if (!nb_filters) return FALSE;
82 for (i = 0; i < nb_filters; i++)
84 if (!strncmp( dllname, filters[i], len ))
86 if (!filters[i][len]) return FALSE;
87 if (filters[i][len] != ':') continue;
88 if (!testname || !strcmp( testname, &filters[i][len+1] )) return FALSE;
91 return TRUE;
94 static char * get_file_version(char * file_name)
96 static char version[32];
97 DWORD size;
98 DWORD handle;
100 size = GetFileVersionInfoSizeA(file_name, &handle);
101 if (size) {
102 char * data = heap_alloc(size);
103 if (data) {
104 if (GetFileVersionInfoA(file_name, handle, size, data)) {
105 static char backslash[] = "\\";
106 VS_FIXEDFILEINFO *pFixedVersionInfo;
107 UINT len;
108 if (VerQueryValueA(data, backslash, (LPVOID *)&pFixedVersionInfo, &len)) {
109 sprintf(version, "%d.%d.%d.%d",
110 pFixedVersionInfo->dwFileVersionMS >> 16,
111 pFixedVersionInfo->dwFileVersionMS & 0xffff,
112 pFixedVersionInfo->dwFileVersionLS >> 16,
113 pFixedVersionInfo->dwFileVersionLS & 0xffff);
114 } else
115 sprintf(version, "version not available");
116 } else
117 sprintf(version, "unknown");
118 heap_free(data);
119 } else
120 sprintf(version, "failed");
121 } else
122 sprintf(version, "version not available");
124 return version;
127 static int running_under_wine (void)
129 HMODULE module = GetModuleHandleA("ntdll.dll");
131 if (!module) return 0;
132 return (GetProcAddress(module, "wine_server_call") != NULL);
135 static int check_mount_mgr(void)
137 if (running_under_wine())
139 HANDLE handle = CreateFileA( "\\\\.\\MountPointManager", GENERIC_READ,
140 FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
141 if (handle == INVALID_HANDLE_VALUE) return FALSE;
142 CloseHandle( handle );
144 return TRUE;
147 static int running_on_visible_desktop (void)
149 HWND desktop;
150 HMODULE huser32 = GetModuleHandle("user32.dll");
151 HWINSTA (WINAPI *pGetProcessWindowStation)(void);
152 BOOL (WINAPI *pGetUserObjectInformationA)(HANDLE,INT,LPVOID,DWORD,LPDWORD);
154 pGetProcessWindowStation = (void *)GetProcAddress(huser32, "GetProcessWindowStation");
155 pGetUserObjectInformationA = (void *)GetProcAddress(huser32, "GetUserObjectInformationA");
157 desktop = GetDesktopWindow();
158 if (!GetWindowLongPtrW(desktop, GWLP_WNDPROC)) /* Win9x */
159 return IsWindowVisible(desktop);
161 if (pGetProcessWindowStation && pGetUserObjectInformationA)
163 DWORD len;
164 HWINSTA wstation;
165 USEROBJECTFLAGS uoflags;
167 wstation = (HWINSTA)pGetProcessWindowStation();
168 assert(pGetUserObjectInformationA(wstation, UOI_FLAGS, &uoflags, sizeof(uoflags), &len));
169 return (uoflags.dwFlags & WSF_VISIBLE) != 0;
171 return IsWindowVisible(desktop);
174 /* check for native dll when running under wine */
175 static BOOL is_native_dll( HMODULE module )
177 static const char fakedll_signature[] = "Wine placeholder DLL";
178 const IMAGE_DOS_HEADER *dos;
180 if (!running_under_wine()) return FALSE;
181 if (!((ULONG_PTR)module & 1)) return FALSE; /* not loaded as datafile */
182 /* builtin dlls can't be loaded as datafile, so we must have native or fake dll */
183 dos = (const IMAGE_DOS_HEADER *)((const char *)module - 1);
184 if (dos->e_magic != IMAGE_DOS_SIGNATURE) return FALSE;
185 if (dos->e_lfanew >= sizeof(*dos) + sizeof(fakedll_signature) &&
186 !memcmp( dos + 1, fakedll_signature, sizeof(fakedll_signature) )) return FALSE;
187 return TRUE;
190 static void print_version (void)
192 #ifdef __i386__
193 static const char platform[] = "i386";
194 #elif defined(__x86_64__)
195 static const char platform[] = "x86_64";
196 #elif defined(__sparc__)
197 static const char platform[] = "sparc";
198 #elif defined(__ALPHA__)
199 static const char platform[] = "alpha";
200 #elif defined(__powerpc__)
201 static const char platform[] = "powerpc";
202 #endif
203 OSVERSIONINFOEX ver;
204 BOOL ext, wow64;
205 int is_win2k3_r2;
206 const char *(CDECL *wine_get_build_id)(void);
207 void (CDECL *wine_get_host_version)( const char **sysname, const char **release );
208 BOOL (WINAPI *pIsWow64Process)(HANDLE hProcess, PBOOL Wow64Process);
209 BOOL (WINAPI *pGetProductInfo)(DWORD, DWORD, DWORD, DWORD, DWORD *);
211 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
212 if (!(ext = GetVersionEx ((OSVERSIONINFO *) &ver)))
214 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
215 if (!GetVersionEx ((OSVERSIONINFO *) &ver))
216 report (R_FATAL, "Can't get OS version.");
218 pIsWow64Process = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
219 if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &wow64 )) wow64 = FALSE;
221 xprintf (" Platform=%s%s\n", platform, wow64 ? " (WOW64)" : "");
222 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
223 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
224 xprintf (" dwMajorVersion=%u\n dwMinorVersion=%u\n"
225 " dwBuildNumber=%u\n PlatformId=%u\n szCSDVersion=%s\n",
226 ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber,
227 ver.dwPlatformId, ver.szCSDVersion);
229 wine_get_build_id = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_build_id");
230 wine_get_host_version = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_host_version");
231 if (wine_get_build_id) xprintf( " WineBuild=%s\n", wine_get_build_id() );
232 if (wine_get_host_version)
234 const char *sysname, *release;
235 wine_get_host_version( &sysname, &release );
236 xprintf( " Host system=%s\n Host version=%s\n", sysname, release );
238 is_win2k3_r2 = GetSystemMetrics(SM_SERVERR2);
239 if(is_win2k3_r2)
240 xprintf(" R2 build number=%d\n", is_win2k3_r2);
242 if (!ext) return;
244 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
245 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
246 ver.wServicePackMajor, ver.wServicePackMinor, ver.wSuiteMask,
247 ver.wProductType, ver.wReserved);
249 pGetProductInfo = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"GetProductInfo");
250 if (pGetProductInfo && !running_under_wine())
252 DWORD prodtype = 0;
254 pGetProductInfo(ver.dwMajorVersion, ver.dwMinorVersion, ver.wServicePackMajor, ver.wServicePackMinor, &prodtype);
255 xprintf(" dwProductInfo=%u\n", prodtype);
259 static inline int is_dot_dir(const char* x)
261 return ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))));
264 static void remove_dir (const char *dir)
266 HANDLE hFind;
267 WIN32_FIND_DATA wfd;
268 char path[MAX_PATH];
269 size_t dirlen = strlen (dir);
271 /* Make sure the directory exists before going further */
272 memcpy (path, dir, dirlen);
273 strcpy (path + dirlen++, "\\*");
274 hFind = FindFirstFile (path, &wfd);
275 if (hFind == INVALID_HANDLE_VALUE) return;
277 do {
278 char *lp = wfd.cFileName;
280 if (!lp[0]) lp = wfd.cAlternateFileName; /* ? FIXME not (!lp) ? */
281 if (is_dot_dir (lp)) continue;
282 strcpy (path + dirlen, lp);
283 if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
284 remove_dir(path);
285 else if (!DeleteFile (path))
286 report (R_WARNING, "Can't delete file %s: error %d",
287 path, GetLastError ());
288 } while (FindNextFile (hFind, &wfd));
289 FindClose (hFind);
290 if (!RemoveDirectory (dir))
291 report (R_WARNING, "Can't remove directory %s: error %d",
292 dir, GetLastError ());
295 static const char* get_test_source_file(const char* test, const char* subtest)
297 static const char* special_dirs[][2] = {
298 { 0, 0 }
300 static char buffer[MAX_PATH];
301 int i;
303 for (i = 0; special_dirs[i][0]; i++) {
304 if (strcmp(test, special_dirs[i][0]) == 0) {
305 test = special_dirs[i][1];
306 break;
310 snprintf(buffer, sizeof(buffer), "dlls/%s/tests/%s.c", test, subtest);
311 return buffer;
314 static void* extract_rcdata (LPCTSTR name, LPCTSTR type, DWORD* size)
316 HRSRC rsrc;
317 HGLOBAL hdl;
318 LPVOID addr;
320 if (!(rsrc = FindResource (NULL, name, type)) ||
321 !(*size = SizeofResource (0, rsrc)) ||
322 !(hdl = LoadResource (0, rsrc)) ||
323 !(addr = LockResource (hdl)))
324 return NULL;
325 return addr;
328 /* Fills in the name and exename fields */
329 static void
330 extract_test (struct wine_test *test, const char *dir, LPTSTR res_name)
332 BYTE* code;
333 DWORD size;
334 char *exepos;
335 HANDLE hfile;
336 DWORD written;
338 code = extract_rcdata (res_name, "TESTRES", &size);
339 if (!code) report (R_FATAL, "Can't find test resource %s: %d",
340 res_name, GetLastError ());
341 test->name = heap_strdup( res_name );
342 test->exename = strmake (NULL, "%s\\%s", dir, test->name);
343 exepos = strstr (test->name, testexe);
344 if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name);
345 *exepos = 0;
346 test->name = heap_realloc (test->name, exepos - test->name + 1);
347 report (R_STEP, "Extracting: %s", test->name);
349 hfile = CreateFileA(test->exename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
350 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
351 if (hfile == INVALID_HANDLE_VALUE)
352 report (R_FATAL, "Failed to open file %s.", test->exename);
354 if (!WriteFile(hfile, code, size, &written, NULL))
355 report (R_FATAL, "Failed to write file %s.", test->exename);
357 CloseHandle(hfile);
360 static DWORD wait_process( HANDLE process, DWORD timeout )
362 DWORD wait, diff = 0, start = GetTickCount();
363 MSG msg;
365 while (diff < timeout)
367 wait = MsgWaitForMultipleObjects( 1, &process, FALSE, timeout - diff, QS_ALLINPUT );
368 if (wait != WAIT_OBJECT_0 + 1) return wait;
369 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
370 diff = GetTickCount() - start;
372 return WAIT_TIMEOUT;
375 static void append_path( const char *path)
377 char *newpath;
379 newpath = heap_alloc(strlen(curpath) + 1 + strlen(path) + 1);
380 strcpy(newpath, curpath);
381 strcat(newpath, ";");
382 strcat(newpath, path);
383 SetEnvironmentVariableA("PATH", newpath);
385 heap_free(newpath);
388 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
389 stdout to there.
391 Return the exit status, -2 if can't create process or the return
392 value of WaitForSingleObject.
394 static int
395 run_ex (char *cmd, HANDLE out_file, const char *tempdir, DWORD ms)
397 STARTUPINFO si;
398 PROCESS_INFORMATION pi;
399 DWORD wait, status;
401 GetStartupInfo (&si);
402 si.dwFlags = STARTF_USESTDHANDLES;
403 si.hStdInput = GetStdHandle( STD_INPUT_HANDLE );
404 si.hStdOutput = out_file ? out_file : GetStdHandle( STD_OUTPUT_HANDLE );
405 si.hStdError = out_file ? out_file : GetStdHandle( STD_ERROR_HANDLE );
407 if (!CreateProcessA (NULL, cmd, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE,
408 NULL, tempdir, &si, &pi))
409 return -2;
411 CloseHandle (pi.hThread);
412 status = wait_process( pi.hProcess, ms );
413 switch (status)
415 case WAIT_OBJECT_0:
416 GetExitCodeProcess (pi.hProcess, &status);
417 CloseHandle (pi.hProcess);
418 return status;
419 case WAIT_FAILED:
420 report (R_ERROR, "Wait for '%s' failed: %d", cmd, GetLastError ());
421 break;
422 case WAIT_TIMEOUT:
423 break;
424 default:
425 report (R_ERROR, "Wait returned %d", status);
426 break;
428 if (!TerminateProcess (pi.hProcess, 257))
429 report (R_ERROR, "TerminateProcess failed: %d", GetLastError ());
430 wait = wait_process( pi.hProcess, 5000 );
431 switch (wait)
433 case WAIT_OBJECT_0:
434 break;
435 case WAIT_FAILED:
436 report (R_ERROR, "Wait for termination of '%s' failed: %d", cmd, GetLastError ());
437 break;
438 case WAIT_TIMEOUT:
439 report (R_ERROR, "Can't kill process '%s'", cmd);
440 break;
441 default:
442 report (R_ERROR, "Waiting for termination: %d", wait);
443 break;
445 CloseHandle (pi.hProcess);
446 return status;
449 static DWORD
450 get_subtests (const char *tempdir, struct wine_test *test, LPTSTR res_name)
452 char *cmd;
453 HANDLE subfile;
454 DWORD err, total;
455 char buffer[8192], *index;
456 static const char header[] = "Valid test names:";
457 int status, allocated;
458 char tmpdir[MAX_PATH], subname[MAX_PATH];
459 SECURITY_ATTRIBUTES sa;
461 test->subtest_count = 0;
463 if (!GetTempPathA( MAX_PATH, tmpdir ) ||
464 !GetTempFileNameA( tmpdir, "sub", 0, subname ))
465 report (R_FATAL, "Can't name subtests file.");
467 /* make handle inheritable */
468 sa.nLength = sizeof(sa);
469 sa.lpSecurityDescriptor = NULL;
470 sa.bInheritHandle = TRUE;
472 subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
473 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
474 &sa, CREATE_ALWAYS, 0, NULL );
476 if ((subfile == INVALID_HANDLE_VALUE) &&
477 (GetLastError() == ERROR_INVALID_PARAMETER)) {
478 /* FILE_SHARE_DELETE not supported on win9x */
479 subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
480 FILE_SHARE_READ | FILE_SHARE_WRITE,
481 &sa, CREATE_ALWAYS, 0, NULL );
483 if (subfile == INVALID_HANDLE_VALUE) {
484 err = GetLastError();
485 report (R_ERROR, "Can't open subtests output of %s: %u",
486 test->name, GetLastError());
487 goto quit;
490 extract_test (test, tempdir, res_name);
491 cmd = strmake (NULL, "%s --list", test->exename);
492 if (test->maindllpath) {
493 /* We need to add the path (to the main dll) to PATH */
494 append_path(test->maindllpath);
496 status = run_ex (cmd, subfile, tempdir, 5000);
497 err = GetLastError();
498 if (test->maindllpath) {
499 /* Restore PATH again */
500 SetEnvironmentVariableA("PATH", curpath);
502 heap_free (cmd);
504 if (status == -2)
506 report (R_ERROR, "Cannot run %s error %u", test->exename, err);
507 goto quit;
510 SetFilePointer( subfile, 0, NULL, FILE_BEGIN );
511 ReadFile( subfile, buffer, sizeof(buffer), &total, NULL );
512 CloseHandle( subfile );
513 if (sizeof buffer == total) {
514 report (R_ERROR, "Subtest list of %s too big.",
515 test->name, sizeof buffer);
516 err = ERROR_OUTOFMEMORY;
517 goto quit;
519 buffer[total] = 0;
521 index = strstr (buffer, header);
522 if (!index) {
523 report (R_ERROR, "Can't parse subtests output of %s",
524 test->name);
525 err = ERROR_INTERNAL_ERROR;
526 goto quit;
528 index += sizeof header;
530 allocated = 10;
531 test->subtests = heap_alloc (allocated * sizeof(char*));
532 index = strtok (index, whitespace);
533 while (index) {
534 if (test->subtest_count == allocated) {
535 allocated *= 2;
536 test->subtests = heap_realloc (test->subtests,
537 allocated * sizeof(char*));
539 if (!test_filtered_out( test->name, index ))
540 test->subtests[test->subtest_count++] = heap_strdup(index);
541 index = strtok (NULL, whitespace);
543 test->subtests = heap_realloc (test->subtests,
544 test->subtest_count * sizeof(char*));
545 err = 0;
547 quit:
548 if (!DeleteFileA (subname))
549 report (R_WARNING, "Can't delete file '%s': %u", subname, GetLastError());
550 return err;
553 static void
554 run_test (struct wine_test* test, const char* subtest, HANDLE out_file, const char *tempdir)
556 int status;
557 const char* file = get_test_source_file(test->name, subtest);
558 char *cmd = strmake (NULL, "%s %s", test->exename, subtest);
560 xprintf ("%s:%s start %s -\n", test->name, subtest, file);
561 status = run_ex (cmd, out_file, tempdir, 120000);
562 heap_free (cmd);
563 xprintf ("%s:%s done (%d)\n", test->name, subtest, status);
566 static BOOL CALLBACK
567 EnumTestFileProc (HMODULE hModule, LPCTSTR lpszType,
568 LPTSTR lpszName, LONG_PTR lParam)
570 if (!test_filtered_out( lpszName, NULL )) (*(int*)lParam)++;
571 return TRUE;
574 static const struct clsid_mapping
576 const char *name;
577 CLSID clsid;
578 } clsid_list[] =
580 {"oledb32", {0xc8b522d1, 0x5cf3, 0x11ce, {0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d}}},
581 {NULL, {0, 0, 0, {0,0,0,0,0,0,0,0}}}
585 static BOOL get_main_clsid(const char *name, CLSID *clsid)
587 const struct clsid_mapping *mapping;
589 for(mapping = clsid_list; mapping->name; mapping++)
591 if(!strcasecmp(name, mapping->name))
593 *clsid = mapping->clsid;
594 return TRUE;
597 return FALSE;
600 static HMODULE load_com_dll(const char *name, char **path, char *filename)
602 HMODULE dll = NULL;
603 HKEY hkey;
604 char keyname[100];
605 char dllname[MAX_PATH];
606 char *p;
607 CLSID clsid;
609 if(!get_main_clsid(name, &clsid)) return NULL;
611 sprintf(keyname, "CLSID\\{%08x-%04x-%04x-%02x%2x-%02x%2x%02x%2x%02x%2x}\\InprocServer32",
612 clsid.Data1, clsid.Data2, clsid.Data3, clsid.Data4[0], clsid.Data4[1],
613 clsid.Data4[2], clsid.Data4[3], clsid.Data4[4], clsid.Data4[5],
614 clsid.Data4[6], clsid.Data4[7]);
616 if(RegOpenKeyA(HKEY_CLASSES_ROOT, keyname, &hkey) == ERROR_SUCCESS)
618 LONG size = sizeof(dllname);
619 if(RegQueryValueA(hkey, NULL, dllname, &size) == ERROR_SUCCESS)
621 if ((dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE)))
623 strcpy( filename, dllname );
624 p = strrchr(dllname, '\\');
625 if (p) *p = 0;
626 *path = heap_strdup( dllname );
629 RegCloseKey(hkey);
632 return dll;
635 static void get_dll_path(HMODULE dll, char **path, char *filename)
637 char dllpath[MAX_PATH];
639 GetModuleFileNameA(dll, dllpath, MAX_PATH);
640 strcpy(filename, dllpath);
641 *strrchr(dllpath, '\\') = '\0';
642 *path = heap_strdup( dllpath );
645 static BOOL CALLBACK
646 extract_test_proc (HMODULE hModule, LPCTSTR lpszType,
647 LPTSTR lpszName, LONG_PTR lParam)
649 const char *tempdir = (const char *)lParam;
650 char dllname[MAX_PATH];
651 char filename[MAX_PATH];
652 WCHAR dllnameW[MAX_PATH];
653 HMODULE dll;
654 DWORD err;
656 if (test_filtered_out( lpszName, NULL )) return TRUE;
658 /* Check if the main dll is present on this system */
659 CharLowerA(lpszName);
660 strcpy(dllname, lpszName);
661 *strstr(dllname, testexe) = 0;
663 wine_tests[nr_of_files].maindllpath = NULL;
664 strcpy(filename, dllname);
665 dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE);
667 if (!dll) dll = load_com_dll(dllname, &wine_tests[nr_of_files].maindllpath, filename);
669 if (!dll && pLoadLibraryShim)
671 MultiByteToWideChar(CP_ACP, 0, dllname, -1, dllnameW, MAX_PATH);
672 if (SUCCEEDED( pLoadLibraryShim(dllnameW, NULL, NULL, &dll) ) && dll)
674 get_dll_path(dll, &wine_tests[nr_of_files].maindllpath, filename);
675 FreeLibrary(dll);
676 dll = LoadLibraryExA(filename, NULL, LOAD_LIBRARY_AS_DATAFILE);
678 else dll = 0;
681 if (!dll)
683 xprintf (" %s=dll is missing\n", dllname);
684 return TRUE;
686 if (is_native_dll(dll))
688 FreeLibrary(dll);
689 xprintf (" %s=load error Configured as native\n", dllname);
690 nr_native_dlls++;
691 return TRUE;
693 FreeLibrary(dll);
695 if (!(err = get_subtests( tempdir, &wine_tests[nr_of_files], lpszName )))
697 xprintf (" %s=%s\n", dllname, get_file_version(filename));
698 nr_of_tests += wine_tests[nr_of_files].subtest_count;
699 nr_of_files++;
701 else
703 xprintf (" %s=load error %u\n", dllname, err);
705 return TRUE;
708 static char *
709 run_tests (char *logname, char *outdir)
711 int i;
712 char *strres, *eol, *nextline;
713 DWORD strsize;
714 SECURITY_ATTRIBUTES sa;
715 char tmppath[MAX_PATH], tempdir[MAX_PATH+4];
716 DWORD needed;
718 /* Get the current PATH only once */
719 needed = GetEnvironmentVariableA("PATH", NULL, 0);
720 curpath = heap_alloc(needed);
721 GetEnvironmentVariableA("PATH", curpath, needed);
723 SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
725 if (!GetTempPathA( MAX_PATH, tmppath ))
726 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
728 if (!logname) {
729 static char tmpname[MAX_PATH];
730 if (!GetTempFileNameA( tmppath, "res", 0, tmpname ))
731 report (R_FATAL, "Can't name logfile.");
732 logname = tmpname;
734 report (R_OUT, logname);
736 /* make handle inheritable */
737 sa.nLength = sizeof(sa);
738 sa.lpSecurityDescriptor = NULL;
739 sa.bInheritHandle = TRUE;
741 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
742 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
743 &sa, CREATE_ALWAYS, 0, NULL );
745 if ((logfile == INVALID_HANDLE_VALUE) &&
746 (GetLastError() == ERROR_INVALID_PARAMETER)) {
747 /* FILE_SHARE_DELETE not supported on win9x */
748 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
749 FILE_SHARE_READ | FILE_SHARE_WRITE,
750 &sa, CREATE_ALWAYS, 0, NULL );
752 if (logfile == INVALID_HANDLE_VALUE)
753 report (R_FATAL, "Could not open logfile: %u", GetLastError());
755 /* try stable path for ZoneAlarm */
756 if (!outdir) {
757 strcpy( tempdir, tmppath );
758 strcat( tempdir, "wct" );
760 if (!CreateDirectoryA( tempdir, NULL ))
762 if (!GetTempFileNameA( tmppath, "wct", 0, tempdir ))
763 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
764 DeleteFileA( tempdir );
765 if (!CreateDirectoryA( tempdir, NULL ))
766 report (R_FATAL, "Could not create directory: %s", tempdir);
769 else
770 strcpy( tempdir, outdir);
772 report (R_DIR, tempdir);
774 xprintf ("Version 4\n");
775 xprintf ("Tests from build %s\n", build_id[0] ? build_id : "-" );
776 xprintf ("Archive: -\n"); /* no longer used */
777 xprintf ("Tag: %s\n", tag);
778 xprintf ("Build info:\n");
779 strres = extract_rcdata ("BUILD_INFO", "STRINGRES", &strsize);
780 while (strres) {
781 eol = memchr (strres, '\n', strsize);
782 if (!eol) {
783 nextline = NULL;
784 eol = strres + strsize;
785 } else {
786 strsize -= eol - strres + 1;
787 nextline = strsize?eol+1:NULL;
788 if (eol > strres && *(eol-1) == '\r') eol--;
790 xprintf (" %.*s\n", eol-strres, strres);
791 strres = nextline;
793 xprintf ("Operating system version:\n");
794 print_version ();
795 xprintf ("Dll info:\n" );
797 report (R_STATUS, "Counting tests");
798 if (!EnumResourceNames (NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
799 report (R_FATAL, "Can't enumerate test files: %d",
800 GetLastError ());
801 wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0]);
803 /* Do this only once during extraction (and version checking) */
804 hmscoree = LoadLibraryA("mscoree.dll");
805 pLoadLibraryShim = NULL;
806 if (hmscoree)
807 pLoadLibraryShim = (void *)GetProcAddress(hmscoree, "LoadLibraryShim");
809 report (R_STATUS, "Extracting tests");
810 report (R_PROGRESS, 0, nr_of_files);
811 nr_of_files = 0;
812 nr_of_tests = 0;
813 if (!EnumResourceNames (NULL, "TESTRES", extract_test_proc, (LPARAM)tempdir))
814 report (R_FATAL, "Can't enumerate test files: %d",
815 GetLastError ());
817 FreeLibrary(hmscoree);
819 xprintf ("Test output:\n" );
821 report (R_DELTA, 0, "Extracting: Done");
823 if (nr_native_dlls)
824 report( R_WARNING, "Some dlls are configured as native, you won't be able to submit results." );
826 report (R_STATUS, "Running tests");
827 report (R_PROGRESS, 1, nr_of_tests);
828 for (i = 0; i < nr_of_files; i++) {
829 struct wine_test *test = wine_tests + i;
830 int j;
832 if (test->maindllpath) {
833 /* We need to add the path (to the main dll) to PATH */
834 append_path(test->maindllpath);
837 for (j = 0; j < test->subtest_count; j++) {
838 report (R_STEP, "Running: %s:%s", test->name,
839 test->subtests[j]);
840 run_test (test, test->subtests[j], logfile, tempdir);
843 if (test->maindllpath) {
844 /* Restore PATH again */
845 SetEnvironmentVariableA("PATH", curpath);
848 report (R_DELTA, 0, "Running: Done");
850 report (R_STATUS, "Cleaning up");
851 CloseHandle( logfile );
852 logfile = 0;
853 if (!outdir)
854 remove_dir (tempdir);
855 heap_free(wine_tests);
856 heap_free(curpath);
858 return logname;
861 static BOOL WINAPI ctrl_handler(DWORD ctrl_type)
863 if (ctrl_type == CTRL_C_EVENT) {
864 printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
865 return TRUE;
868 return FALSE;
872 static BOOL CALLBACK
873 extract_only_proc (HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG_PTR lParam)
875 const char *target_dir = (const char *)lParam;
876 char filename[MAX_PATH];
878 if (test_filtered_out( lpszName, NULL )) return TRUE;
880 strcpy(filename, lpszName);
881 CharLowerA(filename);
883 extract_test( &wine_tests[nr_of_files], target_dir, filename );
884 nr_of_files++;
885 return TRUE;
888 static void extract_only (const char *target_dir)
890 BOOL res;
892 report (R_DIR, target_dir);
893 res = CreateDirectoryA( target_dir, NULL );
894 if (!res && GetLastError() != ERROR_ALREADY_EXISTS)
895 report (R_FATAL, "Could not create directory: %s (%d)", target_dir, GetLastError ());
897 nr_of_files = 0;
898 report (R_STATUS, "Counting tests");
899 if (!EnumResourceNames (NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
900 report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
902 wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0] );
904 report (R_STATUS, "Extracting tests");
905 report (R_PROGRESS, 0, nr_of_files);
906 nr_of_files = 0;
907 if (!EnumResourceNames (NULL, "TESTRES", extract_only_proc, (LPARAM)target_dir))
908 report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
910 report (R_DELTA, 0, "Extracting: Done");
913 static void
914 usage (void)
916 fprintf (stderr,
917 "Usage: winetest [OPTION]... [TESTS]\n\n"
918 " --help print this message and exit\n"
919 " --version print the build version and exit\n"
920 " -c console mode, no GUI\n"
921 " -d DIR Use DIR as temp directory (default: %%TEMP%%\\wct)\n"
922 " -e preserve the environment\n"
923 " -h print this message and exit\n"
924 " -p shutdown when the tests are done\n"
925 " -q quiet mode, no output at all\n"
926 " -o FILE put report into FILE, do not submit\n"
927 " -s FILE submit FILE, do not run tests\n"
928 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n"
929 " -x DIR Extract tests to DIR (default: .\\wct) and exit\n");
932 int main( int argc, char *argv[] )
934 char *logname = NULL, *outdir = NULL;
935 const char *extract = NULL;
936 const char *cp, *submit = NULL;
937 int reset_env = 1;
938 int poweroff = 0;
939 int interactive = 1;
940 int i;
942 if (!LoadStringA( 0, IDS_BUILD_ID, build_id, sizeof(build_id) )) build_id[0] = 0;
944 for (i = 1; i < argc && argv[i]; i++)
946 if (!strcmp(argv[i], "--help")) {
947 usage ();
948 exit (0);
950 else if (!strcmp(argv[i], "--version")) {
951 printf("%-12.12s\n", build_id[0] ? build_id : "unknown");
952 exit (0);
954 else if ((argv[i][0] != '-' && argv[i][0] != '/') || argv[i][2]) {
955 if (nb_filters == sizeof(filters)/sizeof(filters[0]))
957 report (R_ERROR, "Too many test filters specified");
958 exit (2);
960 filters[nb_filters++] = argv[i];
962 else switch (argv[i][1]) {
963 case 'c':
964 report (R_TEXTMODE);
965 interactive = 0;
966 break;
967 case 'e':
968 reset_env = 0;
969 break;
970 case 'h':
971 case '?':
972 usage ();
973 exit (0);
974 case 'p':
975 poweroff = 1;
976 break;
977 case 'q':
978 report (R_QUIET);
979 interactive = 0;
980 break;
981 case 's':
982 if (!(submit = argv[++i]))
984 usage();
985 exit( 2 );
987 if (tag)
988 report (R_WARNING, "ignoring tag for submission");
989 send_file (submit);
990 break;
991 case 'o':
992 if (!(logname = argv[++i]))
994 usage();
995 exit( 2 );
997 break;
998 case 't':
999 if (!(tag = argv[++i]))
1001 usage();
1002 exit( 2 );
1004 if (strlen (tag) > MAXTAGLEN)
1005 report (R_FATAL, "tag is too long (maximum %d characters)",
1006 MAXTAGLEN);
1007 cp = findbadtagchar (tag);
1008 if (cp) {
1009 report (R_ERROR, "invalid char in tag: %c", *cp);
1010 usage ();
1011 exit (2);
1013 break;
1014 case 'x':
1015 report (R_TEXTMODE);
1016 if (!(extract = argv[++i]))
1017 extract = ".\\wct";
1019 extract_only (extract);
1020 break;
1021 case 'd':
1022 outdir = argv[++i];
1023 break;
1024 default:
1025 report (R_ERROR, "invalid option: -%c", argv[i][1]);
1026 usage ();
1027 exit (2);
1030 if (!submit && !extract) {
1031 report (R_STATUS, "Starting up");
1033 if (!running_on_visible_desktop ())
1034 report (R_FATAL, "Tests must be run on a visible desktop");
1036 if (!check_mount_mgr())
1037 report (R_FATAL, "Mount manager not running, most likely your WINEPREFIX wasn't created correctly");
1039 SetConsoleCtrlHandler(ctrl_handler, TRUE);
1041 if (reset_env)
1043 SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
1044 SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
1045 SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
1046 SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
1049 if (!nb_filters) /* don't submit results when filtering */
1051 while (!tag) {
1052 if (!interactive)
1053 report (R_FATAL, "Please specify a tag (-t option) if "
1054 "running noninteractive!");
1055 if (guiAskTag () == IDABORT) exit (1);
1057 report (R_TAG);
1059 if (!build_id[0])
1060 report( R_WARNING, "You won't be able to submit results without a valid build id.\n"
1061 "To submit results, winetest needs to be built from a git checkout." );
1064 if (!logname) {
1065 logname = run_tests (NULL, outdir);
1066 if (build_id[0] && !nb_filters && !nr_native_dlls &&
1067 report (R_ASK, MB_YESNO, "Do you want to submit the test results?") == IDYES)
1068 if (!send_file (logname) && !DeleteFileA(logname))
1069 report (R_WARNING, "Can't remove logfile: %u", GetLastError());
1070 } else run_tests (logname, outdir);
1071 report (R_STATUS, "Finished");
1073 if (poweroff)
1075 HANDLE hToken;
1076 TOKEN_PRIVILEGES npr;
1078 /* enable the shutdown privilege for the current process */
1079 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
1081 LookupPrivilegeValueA(0, SE_SHUTDOWN_NAME, &npr.Privileges[0].Luid);
1082 npr.PrivilegeCount = 1;
1083 npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1084 AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
1085 CloseHandle(hToken);
1087 ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);
1089 exit (0);