clock: Update Korean resource.
[wine/multimedia.git] / programs / winetest / main.c
blob5a7109a40d7b9b5aa44dc5f52c7da60b630f5cd0
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 /* Don't submit the results if more than SKIP_LIMIT tests have been skipped */
41 #define SKIP_LIMIT 10
43 struct wine_test
45 char *name;
46 int resource;
47 int subtest_count;
48 char **subtests;
49 char *exename;
50 char *maindllpath;
53 char *tag = NULL;
54 char *description = NULL;
55 char *url = NULL;
56 char *email = NULL;
57 BOOL aborting = FALSE;
58 static struct wine_test *wine_tests;
59 static int nr_of_files, nr_of_tests, nr_of_skips;
60 static int nr_native_dlls;
61 static const char whitespace[] = " \t\r\n";
62 static const char testexe[] = "_test.exe";
63 static char build_id[64];
65 /* filters for running only specific tests */
66 static char *filters[64];
67 static unsigned int nb_filters = 0;
68 static BOOL exclude_tests = FALSE;
70 /* Needed to check for .NET dlls */
71 static HMODULE hmscoree;
72 static HRESULT (WINAPI *pLoadLibraryShim)(LPCWSTR, LPCWSTR, LPVOID, HMODULE *);
74 /* For SxS DLLs e.g. msvcr90 */
75 static HANDLE (WINAPI *pCreateActCtxA)(PACTCTXA);
76 static BOOL (WINAPI *pActivateActCtx)(HANDLE, ULONG_PTR *);
77 static BOOL (WINAPI *pDeactivateActCtx)(DWORD, ULONG_PTR);
78 static void (WINAPI *pReleaseActCtx)(HANDLE);
80 /* To store the current PATH setting (related to .NET only provided dlls) */
81 static char *curpath;
83 /* check if test is being filtered out */
84 static BOOL test_filtered_out( LPCSTR module, LPCSTR testname )
86 char *p, dllname[MAX_PATH];
87 unsigned int i, len;
89 strcpy( dllname, module );
90 CharLowerA( dllname );
91 p = strstr( dllname, testexe );
92 if (p) *p = 0;
93 len = strlen(dllname);
95 if (!nb_filters) return exclude_tests;
96 for (i = 0; i < nb_filters; i++)
98 if (!strncmp( dllname, filters[i], len ))
100 if (!filters[i][len]) return exclude_tests;
101 if (filters[i][len] != ':') continue;
102 if (testname && !strcmp( testname, &filters[i][len+1] )) return exclude_tests;
103 if (!testname && !exclude_tests) return FALSE;
106 return !exclude_tests;
109 static char * get_file_version(char * file_name)
111 static char version[32];
112 DWORD size;
113 DWORD handle;
115 size = GetFileVersionInfoSizeA(file_name, &handle);
116 if (size) {
117 char * data = heap_alloc(size);
118 if (data) {
119 if (GetFileVersionInfoA(file_name, handle, size, data)) {
120 static char backslash[] = "\\";
121 VS_FIXEDFILEINFO *pFixedVersionInfo;
122 UINT len;
123 if (VerQueryValueA(data, backslash, (LPVOID *)&pFixedVersionInfo, &len)) {
124 sprintf(version, "%d.%d.%d.%d",
125 pFixedVersionInfo->dwFileVersionMS >> 16,
126 pFixedVersionInfo->dwFileVersionMS & 0xffff,
127 pFixedVersionInfo->dwFileVersionLS >> 16,
128 pFixedVersionInfo->dwFileVersionLS & 0xffff);
129 } else
130 sprintf(version, "version not available");
131 } else
132 sprintf(version, "unknown");
133 heap_free(data);
134 } else
135 sprintf(version, "failed");
136 } else
137 sprintf(version, "version not available");
139 return version;
142 static int running_under_wine (void)
144 HMODULE module = GetModuleHandleA("ntdll.dll");
146 if (!module) return 0;
147 return (GetProcAddress(module, "wine_server_call") != NULL);
150 static int check_mount_mgr(void)
152 if (running_under_wine())
154 HANDLE handle = CreateFileA( "\\\\.\\MountPointManager", GENERIC_READ,
155 FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
156 if (handle == INVALID_HANDLE_VALUE) return FALSE;
157 CloseHandle( handle );
159 return TRUE;
162 static int check_display_driver(void)
164 if (running_under_wine())
166 HWND hwnd = CreateWindowA( "STATIC", "", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
167 0, 0, GetModuleHandleA(0), 0 );
168 if (!hwnd) return FALSE;
169 DestroyWindow( hwnd );
171 return TRUE;
174 static int running_on_visible_desktop (void)
176 HWND desktop;
177 HMODULE huser32 = GetModuleHandle("user32.dll");
178 HWINSTA (WINAPI *pGetProcessWindowStation)(void);
179 BOOL (WINAPI *pGetUserObjectInformationA)(HANDLE,INT,LPVOID,DWORD,LPDWORD);
181 pGetProcessWindowStation = (void *)GetProcAddress(huser32, "GetProcessWindowStation");
182 pGetUserObjectInformationA = (void *)GetProcAddress(huser32, "GetUserObjectInformationA");
184 desktop = GetDesktopWindow();
185 if (!GetWindowLongPtrW(desktop, GWLP_WNDPROC)) /* Win9x */
186 return IsWindowVisible(desktop);
188 if (pGetProcessWindowStation && pGetUserObjectInformationA)
190 DWORD len;
191 HWINSTA wstation;
192 USEROBJECTFLAGS uoflags;
194 wstation = (HWINSTA)pGetProcessWindowStation();
195 assert(pGetUserObjectInformationA(wstation, UOI_FLAGS, &uoflags, sizeof(uoflags), &len));
196 return (uoflags.dwFlags & WSF_VISIBLE) != 0;
198 return IsWindowVisible(desktop);
201 /* check for native dll when running under wine */
202 static BOOL is_native_dll( HMODULE module )
204 static const char fakedll_signature[] = "Wine placeholder DLL";
205 const IMAGE_DOS_HEADER *dos;
207 if (!running_under_wine()) return FALSE;
208 if (!((ULONG_PTR)module & 1)) return FALSE; /* not loaded as datafile */
209 /* builtin dlls can't be loaded as datafile, so we must have native or fake dll */
210 dos = (const IMAGE_DOS_HEADER *)((const char *)module - 1);
211 if (dos->e_magic != IMAGE_DOS_SIGNATURE) return FALSE;
212 if (dos->e_lfanew >= sizeof(*dos) + sizeof(fakedll_signature) &&
213 !memcmp( dos + 1, fakedll_signature, sizeof(fakedll_signature) )) return FALSE;
214 return TRUE;
217 static void print_version (void)
219 #ifdef __i386__
220 static const char platform[] = "i386";
221 #elif defined(__x86_64__)
222 static const char platform[] = "x86_64";
223 #elif defined(__sparc__)
224 static const char platform[] = "sparc";
225 #elif defined(__ALPHA__)
226 static const char platform[] = "alpha";
227 #elif defined(__powerpc__)
228 static const char platform[] = "powerpc";
229 #elif defined(__arm__)
230 static const char platform[] = "arm";
231 #else
232 # error CPU unknown
233 #endif
234 OSVERSIONINFOEX ver;
235 BOOL ext, wow64;
236 int is_win2k3_r2;
237 const char *(CDECL *wine_get_build_id)(void);
238 void (CDECL *wine_get_host_version)( const char **sysname, const char **release );
239 BOOL (WINAPI *pIsWow64Process)(HANDLE hProcess, PBOOL Wow64Process);
240 BOOL (WINAPI *pGetProductInfo)(DWORD, DWORD, DWORD, DWORD, DWORD *);
242 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
243 if (!(ext = GetVersionEx ((OSVERSIONINFO *) &ver)))
245 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
246 if (!GetVersionEx ((OSVERSIONINFO *) &ver))
247 report (R_FATAL, "Can't get OS version.");
249 pIsWow64Process = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
250 if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &wow64 )) wow64 = FALSE;
252 xprintf (" Platform=%s%s\n", platform, wow64 ? " (WOW64)" : "");
253 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
254 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
255 xprintf (" Submitter=%s\n", email );
256 if (description)
257 xprintf (" Description=%s\n", description );
258 if (url)
259 xprintf (" URL=%s\n", url );
260 xprintf (" dwMajorVersion=%u\n dwMinorVersion=%u\n"
261 " dwBuildNumber=%u\n PlatformId=%u\n szCSDVersion=%s\n",
262 ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber,
263 ver.dwPlatformId, ver.szCSDVersion);
265 wine_get_build_id = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_build_id");
266 wine_get_host_version = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_host_version");
267 if (wine_get_build_id) xprintf( " WineBuild=%s\n", wine_get_build_id() );
268 if (wine_get_host_version)
270 const char *sysname, *release;
271 wine_get_host_version( &sysname, &release );
272 xprintf( " Host system=%s\n Host version=%s\n", sysname, release );
274 is_win2k3_r2 = GetSystemMetrics(SM_SERVERR2);
275 if(is_win2k3_r2)
276 xprintf(" R2 build number=%d\n", is_win2k3_r2);
278 if (!ext) return;
280 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
281 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
282 ver.wServicePackMajor, ver.wServicePackMinor, ver.wSuiteMask,
283 ver.wProductType, ver.wReserved);
285 pGetProductInfo = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"GetProductInfo");
286 if (pGetProductInfo && !running_under_wine())
288 DWORD prodtype = 0;
290 pGetProductInfo(ver.dwMajorVersion, ver.dwMinorVersion, ver.wServicePackMajor, ver.wServicePackMinor, &prodtype);
291 xprintf(" dwProductInfo=%u\n", prodtype);
295 static inline int is_dot_dir(const char* x)
297 return ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))));
300 static void remove_dir (const char *dir)
302 HANDLE hFind;
303 WIN32_FIND_DATA wfd;
304 char path[MAX_PATH];
305 size_t dirlen = strlen (dir);
307 /* Make sure the directory exists before going further */
308 memcpy (path, dir, dirlen);
309 strcpy (path + dirlen++, "\\*");
310 hFind = FindFirstFile (path, &wfd);
311 if (hFind == INVALID_HANDLE_VALUE) return;
313 do {
314 char *lp = wfd.cFileName;
316 if (!lp[0]) lp = wfd.cAlternateFileName; /* ? FIXME not (!lp) ? */
317 if (is_dot_dir (lp)) continue;
318 strcpy (path + dirlen, lp);
319 if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
320 remove_dir(path);
321 else if (!DeleteFile (path))
322 report (R_WARNING, "Can't delete file %s: error %d",
323 path, GetLastError ());
324 } while (FindNextFile (hFind, &wfd));
325 FindClose (hFind);
326 if (!RemoveDirectory (dir))
327 report (R_WARNING, "Can't remove directory %s: error %d",
328 dir, GetLastError ());
331 static const char* get_test_source_file(const char* test, const char* subtest)
333 static const char* special_dirs[][2] = {
334 { 0, 0 }
336 static char buffer[MAX_PATH];
337 int i, len = strlen(test);
339 if (len > 4 && !strcmp( test + len - 4, ".exe" ))
341 len = sprintf(buffer, "programs/%s", test) - 4;
342 buffer[len] = 0;
344 else len = sprintf(buffer, "dlls/%s", test);
346 for (i = 0; special_dirs[i][0]; i++) {
347 if (strcmp(test, special_dirs[i][0]) == 0) {
348 strcpy( buffer, special_dirs[i][1] );
349 len = strlen(buffer);
350 break;
354 sprintf(buffer + len, "/tests/%s.c", subtest);
355 return buffer;
358 static void* extract_rcdata (LPCTSTR name, LPCTSTR type, DWORD* size)
360 HRSRC rsrc;
361 HGLOBAL hdl;
362 LPVOID addr;
364 if (!(rsrc = FindResource (NULL, name, type)) ||
365 !(*size = SizeofResource (0, rsrc)) ||
366 !(hdl = LoadResource (0, rsrc)) ||
367 !(addr = LockResource (hdl)))
368 return NULL;
369 return addr;
372 /* Fills in the name and exename fields */
373 static void
374 extract_test (struct wine_test *test, const char *dir, LPTSTR res_name)
376 BYTE* code;
377 DWORD size;
378 char *exepos;
379 HANDLE hfile;
380 DWORD written;
382 code = extract_rcdata (res_name, "TESTRES", &size);
383 if (!code) report (R_FATAL, "Can't find test resource %s: %d",
384 res_name, GetLastError ());
385 test->name = heap_strdup( res_name );
386 test->exename = strmake (NULL, "%s\\%s", dir, test->name);
387 exepos = strstr (test->name, testexe);
388 if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name);
389 *exepos = 0;
390 test->name = heap_realloc (test->name, exepos - test->name + 1);
391 report (R_STEP, "Extracting: %s", test->name);
393 hfile = CreateFileA(test->exename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
394 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
395 if (hfile == INVALID_HANDLE_VALUE)
396 report (R_FATAL, "Failed to open file %s.", test->exename);
398 if (!WriteFile(hfile, code, size, &written, NULL))
399 report (R_FATAL, "Failed to write file %s.", test->exename);
401 CloseHandle(hfile);
404 static DWORD wait_process( HANDLE process, DWORD timeout )
406 DWORD wait, diff = 0, start = GetTickCount();
407 MSG msg;
409 while (diff < timeout)
411 wait = MsgWaitForMultipleObjects( 1, &process, FALSE, timeout - diff, QS_ALLINPUT );
412 if (wait != WAIT_OBJECT_0 + 1) return wait;
413 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
414 diff = GetTickCount() - start;
416 return WAIT_TIMEOUT;
419 static void append_path( const char *path)
421 char *newpath;
423 newpath = heap_alloc(strlen(curpath) + 1 + strlen(path) + 1);
424 strcpy(newpath, curpath);
425 strcat(newpath, ";");
426 strcat(newpath, path);
427 SetEnvironmentVariableA("PATH", newpath);
429 heap_free(newpath);
432 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
433 stdout to there.
435 Return the exit status, -2 if can't create process or the return
436 value of WaitForSingleObject.
438 static int
439 run_ex (char *cmd, HANDLE out_file, const char *tempdir, DWORD ms)
441 STARTUPINFO si;
442 PROCESS_INFORMATION pi;
443 DWORD wait, status;
445 GetStartupInfo (&si);
446 si.dwFlags = STARTF_USESTDHANDLES;
447 si.hStdInput = GetStdHandle( STD_INPUT_HANDLE );
448 si.hStdOutput = out_file ? out_file : GetStdHandle( STD_OUTPUT_HANDLE );
449 si.hStdError = out_file ? out_file : GetStdHandle( STD_ERROR_HANDLE );
451 if (!CreateProcessA (NULL, cmd, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE,
452 NULL, tempdir, &si, &pi))
453 return -2;
455 CloseHandle (pi.hThread);
456 status = wait_process( pi.hProcess, ms );
457 switch (status)
459 case WAIT_OBJECT_0:
460 GetExitCodeProcess (pi.hProcess, &status);
461 CloseHandle (pi.hProcess);
462 return status;
463 case WAIT_FAILED:
464 report (R_ERROR, "Wait for '%s' failed: %d", cmd, GetLastError ());
465 break;
466 case WAIT_TIMEOUT:
467 break;
468 default:
469 report (R_ERROR, "Wait returned %d", status);
470 break;
472 if (!TerminateProcess (pi.hProcess, 257))
473 report (R_ERROR, "TerminateProcess failed: %d", GetLastError ());
474 wait = wait_process( pi.hProcess, 5000 );
475 switch (wait)
477 case WAIT_OBJECT_0:
478 break;
479 case WAIT_FAILED:
480 report (R_ERROR, "Wait for termination of '%s' failed: %d", cmd, GetLastError ());
481 break;
482 case WAIT_TIMEOUT:
483 report (R_ERROR, "Can't kill process '%s'", cmd);
484 break;
485 default:
486 report (R_ERROR, "Waiting for termination: %d", wait);
487 break;
489 CloseHandle (pi.hProcess);
490 return status;
493 static DWORD
494 get_subtests (const char *tempdir, struct wine_test *test, LPTSTR res_name)
496 char *cmd;
497 HANDLE subfile;
498 DWORD err, total;
499 char buffer[8192], *index;
500 static const char header[] = "Valid test names:";
501 int status, allocated;
502 char tmpdir[MAX_PATH], subname[MAX_PATH];
503 SECURITY_ATTRIBUTES sa;
505 test->subtest_count = 0;
507 if (!GetTempPathA( MAX_PATH, tmpdir ) ||
508 !GetTempFileNameA( tmpdir, "sub", 0, subname ))
509 report (R_FATAL, "Can't name subtests file.");
511 /* make handle inheritable */
512 sa.nLength = sizeof(sa);
513 sa.lpSecurityDescriptor = NULL;
514 sa.bInheritHandle = TRUE;
516 subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
517 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
518 &sa, CREATE_ALWAYS, 0, NULL );
520 if ((subfile == INVALID_HANDLE_VALUE) &&
521 (GetLastError() == ERROR_INVALID_PARAMETER)) {
522 /* FILE_SHARE_DELETE not supported on win9x */
523 subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
524 FILE_SHARE_READ | FILE_SHARE_WRITE,
525 &sa, CREATE_ALWAYS, 0, NULL );
527 if (subfile == INVALID_HANDLE_VALUE) {
528 err = GetLastError();
529 report (R_ERROR, "Can't open subtests output of %s: %u",
530 test->name, GetLastError());
531 goto quit;
534 cmd = strmake (NULL, "%s --list", test->exename);
535 if (test->maindllpath) {
536 /* We need to add the path (to the main dll) to PATH */
537 append_path(test->maindllpath);
539 status = run_ex (cmd, subfile, tempdir, 5000);
540 err = GetLastError();
541 if (test->maindllpath) {
542 /* Restore PATH again */
543 SetEnvironmentVariableA("PATH", curpath);
545 heap_free (cmd);
547 if (status == -2)
549 report (R_ERROR, "Cannot run %s error %u", test->exename, err);
550 goto quit;
553 SetFilePointer( subfile, 0, NULL, FILE_BEGIN );
554 ReadFile( subfile, buffer, sizeof(buffer), &total, NULL );
555 CloseHandle( subfile );
556 if (sizeof buffer == total) {
557 report (R_ERROR, "Subtest list of %s too big.",
558 test->name, sizeof buffer);
559 err = ERROR_OUTOFMEMORY;
560 goto quit;
562 buffer[total] = 0;
564 index = strstr (buffer, header);
565 if (!index) {
566 report (R_ERROR, "Can't parse subtests output of %s",
567 test->name);
568 err = ERROR_INTERNAL_ERROR;
569 goto quit;
571 index += sizeof header;
573 allocated = 10;
574 test->subtests = heap_alloc (allocated * sizeof(char*));
575 index = strtok (index, whitespace);
576 while (index) {
577 if (test->subtest_count == allocated) {
578 allocated *= 2;
579 test->subtests = heap_realloc (test->subtests,
580 allocated * sizeof(char*));
582 test->subtests[test->subtest_count++] = heap_strdup(index);
583 index = strtok (NULL, whitespace);
585 test->subtests = heap_realloc (test->subtests,
586 test->subtest_count * sizeof(char*));
587 err = 0;
589 quit:
590 if (!DeleteFileA (subname))
591 report (R_WARNING, "Can't delete file '%s': %u", subname, GetLastError());
592 return err;
595 static void
596 run_test (struct wine_test* test, const char* subtest, HANDLE out_file, const char *tempdir)
598 const char* file = get_test_source_file(test->name, subtest);
600 if (test_filtered_out( test->name, subtest ))
602 report (R_STEP, "Skipping: %s:%s", test->name, subtest);
603 xprintf ("%s:%s skipped %s -\n", test->name, subtest, file);
604 nr_of_skips++;
606 else
608 int status;
609 char *cmd = strmake (NULL, "%s %s", test->exename, subtest);
610 report (R_STEP, "Running: %s:%s", test->name, subtest);
611 xprintf ("%s:%s start %s -\n", test->name, subtest, file);
612 status = run_ex (cmd, out_file, tempdir, 120000);
613 heap_free (cmd);
614 xprintf ("%s:%s done (%d)\n", test->name, subtest, status);
618 static BOOL CALLBACK
619 EnumTestFileProc (HMODULE hModule, LPCTSTR lpszType,
620 LPTSTR lpszName, LONG_PTR lParam)
622 if (!test_filtered_out( lpszName, NULL )) (*(int*)lParam)++;
623 return TRUE;
626 static const struct clsid_mapping
628 const char *name;
629 CLSID clsid;
630 } clsid_list[] =
632 {"oledb32", {0xc8b522d1, 0x5cf3, 0x11ce, {0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d}}},
633 {NULL, {0, 0, 0, {0,0,0,0,0,0,0,0}}}
637 static BOOL get_main_clsid(const char *name, CLSID *clsid)
639 const struct clsid_mapping *mapping;
641 for(mapping = clsid_list; mapping->name; mapping++)
643 if(!strcasecmp(name, mapping->name))
645 *clsid = mapping->clsid;
646 return TRUE;
649 return FALSE;
652 static HMODULE load_com_dll(const char *name, char **path, char *filename)
654 HMODULE dll = NULL;
655 HKEY hkey;
656 char keyname[100];
657 char dllname[MAX_PATH];
658 char *p;
659 CLSID clsid;
661 if(!get_main_clsid(name, &clsid)) return NULL;
663 sprintf(keyname, "CLSID\\{%08x-%04x-%04x-%02x%2x-%02x%2x%02x%2x%02x%2x}\\InprocServer32",
664 clsid.Data1, clsid.Data2, clsid.Data3, clsid.Data4[0], clsid.Data4[1],
665 clsid.Data4[2], clsid.Data4[3], clsid.Data4[4], clsid.Data4[5],
666 clsid.Data4[6], clsid.Data4[7]);
668 if(RegOpenKeyA(HKEY_CLASSES_ROOT, keyname, &hkey) == ERROR_SUCCESS)
670 LONG size = sizeof(dllname);
671 if(RegQueryValueA(hkey, NULL, dllname, &size) == ERROR_SUCCESS)
673 if ((dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE)))
675 strcpy( filename, dllname );
676 p = strrchr(dllname, '\\');
677 if (p) *p = 0;
678 *path = heap_strdup( dllname );
681 RegCloseKey(hkey);
684 return dll;
687 static void get_dll_path(HMODULE dll, char **path, char *filename)
689 char dllpath[MAX_PATH];
691 GetModuleFileNameA(dll, dllpath, MAX_PATH);
692 strcpy(filename, dllpath);
693 *strrchr(dllpath, '\\') = '\0';
694 *path = heap_strdup( dllpath );
697 static BOOL CALLBACK
698 extract_test_proc (HMODULE hModule, LPCTSTR lpszType,
699 LPTSTR lpszName, LONG_PTR lParam)
701 const char *tempdir = (const char *)lParam;
702 char dllname[MAX_PATH];
703 char filename[MAX_PATH];
704 WCHAR dllnameW[MAX_PATH];
705 HMODULE dll;
706 DWORD err;
707 HANDLE actctx;
708 ULONG_PTR cookie;
710 if (aborting) return TRUE;
712 /* Check if the main dll is present on this system */
713 CharLowerA(lpszName);
714 strcpy(dllname, lpszName);
715 *strstr(dllname, testexe) = 0;
717 if (test_filtered_out( lpszName, NULL ))
719 nr_of_skips++;
720 xprintf (" %s=skipped\n", dllname);
721 return TRUE;
723 extract_test (&wine_tests[nr_of_files], tempdir, lpszName);
725 if (pCreateActCtxA != NULL && pActivateActCtx != NULL &&
726 pDeactivateActCtx != NULL && pReleaseActCtx != NULL)
728 ACTCTXA actctxinfo;
729 memset(&actctxinfo, 0, sizeof(ACTCTXA));
730 actctxinfo.cbSize = sizeof(ACTCTXA);
731 actctxinfo.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID;
732 actctxinfo.lpSource = wine_tests[nr_of_files].exename;
733 actctxinfo.lpResourceName = CREATEPROCESS_MANIFEST_RESOURCE_ID;
734 actctx = pCreateActCtxA(&actctxinfo);
735 if (actctx != INVALID_HANDLE_VALUE &&
736 ! pActivateActCtx(actctx, &cookie))
738 pReleaseActCtx(actctx);
739 actctx = INVALID_HANDLE_VALUE;
741 } else actctx = INVALID_HANDLE_VALUE;
743 wine_tests[nr_of_files].maindllpath = NULL;
744 strcpy(filename, dllname);
745 dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE);
747 if (!dll) dll = load_com_dll(dllname, &wine_tests[nr_of_files].maindllpath, filename);
749 if (!dll && pLoadLibraryShim)
751 MultiByteToWideChar(CP_ACP, 0, dllname, -1, dllnameW, MAX_PATH);
752 if (SUCCEEDED( pLoadLibraryShim(dllnameW, NULL, NULL, &dll) ) && dll)
754 get_dll_path(dll, &wine_tests[nr_of_files].maindllpath, filename);
755 FreeLibrary(dll);
756 dll = LoadLibraryExA(filename, NULL, LOAD_LIBRARY_AS_DATAFILE);
758 else dll = 0;
761 if (!dll)
763 xprintf (" %s=dll is missing\n", dllname);
764 if (actctx != INVALID_HANDLE_VALUE)
766 pDeactivateActCtx(0, cookie);
767 pReleaseActCtx(actctx);
769 return TRUE;
771 if (is_native_dll(dll))
773 FreeLibrary(dll);
774 xprintf (" %s=load error Configured as native\n", dllname);
775 nr_native_dlls++;
776 if (actctx != INVALID_HANDLE_VALUE)
778 pDeactivateActCtx(0, cookie);
779 pReleaseActCtx(actctx);
781 return TRUE;
783 FreeLibrary(dll);
785 if (!(err = get_subtests( tempdir, &wine_tests[nr_of_files], lpszName )))
787 xprintf (" %s=%s\n", dllname, get_file_version(filename));
788 nr_of_tests += wine_tests[nr_of_files].subtest_count;
789 nr_of_files++;
791 else
793 xprintf (" %s=load error %u\n", dllname, err);
796 if (actctx != INVALID_HANDLE_VALUE)
798 pDeactivateActCtx(0, cookie);
799 pReleaseActCtx(actctx);
801 return TRUE;
804 static char *
805 run_tests (char *logname, char *outdir)
807 int i;
808 char *strres, *eol, *nextline;
809 DWORD strsize;
810 SECURITY_ATTRIBUTES sa;
811 char tmppath[MAX_PATH], tempdir[MAX_PATH+4];
812 DWORD needed;
813 HMODULE kernel32;
815 /* Get the current PATH only once */
816 needed = GetEnvironmentVariableA("PATH", NULL, 0);
817 curpath = heap_alloc(needed);
818 GetEnvironmentVariableA("PATH", curpath, needed);
820 SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
822 if (!GetTempPathA( MAX_PATH, tmppath ))
823 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
825 if (!logname) {
826 static char tmpname[MAX_PATH];
827 if (!GetTempFileNameA( tmppath, "res", 0, tmpname ))
828 report (R_FATAL, "Can't name logfile.");
829 logname = tmpname;
831 report (R_OUT, logname);
833 /* make handle inheritable */
834 sa.nLength = sizeof(sa);
835 sa.lpSecurityDescriptor = NULL;
836 sa.bInheritHandle = TRUE;
838 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
839 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
840 &sa, CREATE_ALWAYS, 0, NULL );
842 if ((logfile == INVALID_HANDLE_VALUE) &&
843 (GetLastError() == ERROR_INVALID_PARAMETER)) {
844 /* FILE_SHARE_DELETE not supported on win9x */
845 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
846 FILE_SHARE_READ | FILE_SHARE_WRITE,
847 &sa, CREATE_ALWAYS, 0, NULL );
849 if (logfile == INVALID_HANDLE_VALUE)
850 report (R_FATAL, "Could not open logfile: %u", GetLastError());
852 /* try stable path for ZoneAlarm */
853 if (!outdir) {
854 strcpy( tempdir, tmppath );
855 strcat( tempdir, "wct" );
857 if (!CreateDirectoryA( tempdir, NULL ))
859 if (!GetTempFileNameA( tmppath, "wct", 0, tempdir ))
860 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
861 DeleteFileA( tempdir );
862 if (!CreateDirectoryA( tempdir, NULL ))
863 report (R_FATAL, "Could not create directory: %s", tempdir);
866 else
867 strcpy( tempdir, outdir);
869 report (R_DIR, tempdir);
871 xprintf ("Version 4\n");
872 xprintf ("Tests from build %s\n", build_id[0] ? build_id : "-" );
873 xprintf ("Archive: -\n"); /* no longer used */
874 xprintf ("Tag: %s\n", tag);
875 xprintf ("Build info:\n");
876 strres = extract_rcdata ("BUILD_INFO", "STRINGRES", &strsize);
877 while (strres) {
878 eol = memchr (strres, '\n', strsize);
879 if (!eol) {
880 nextline = NULL;
881 eol = strres + strsize;
882 } else {
883 strsize -= eol - strres + 1;
884 nextline = strsize?eol+1:NULL;
885 if (eol > strres && *(eol-1) == '\r') eol--;
887 xprintf (" %.*s\n", eol-strres, strres);
888 strres = nextline;
890 xprintf ("Operating system version:\n");
891 print_version ();
892 xprintf ("Dll info:\n" );
894 report (R_STATUS, "Counting tests");
895 if (!EnumResourceNames (NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
896 report (R_FATAL, "Can't enumerate test files: %d",
897 GetLastError ());
898 wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0]);
900 /* Do this only once during extraction (and version checking) */
901 hmscoree = LoadLibraryA("mscoree.dll");
902 pLoadLibraryShim = NULL;
903 if (hmscoree)
904 pLoadLibraryShim = (void *)GetProcAddress(hmscoree, "LoadLibraryShim");
905 kernel32 = GetModuleHandleA("kernel32.dll");
906 pCreateActCtxA = (void *)GetProcAddress(kernel32, "CreateActCtxA");
907 pActivateActCtx = (void *)GetProcAddress(kernel32, "ActivateActCtx");
908 pDeactivateActCtx = (void *)GetProcAddress(kernel32, "DeactivateActCtx");
909 pReleaseActCtx = (void *)GetProcAddress(kernel32, "ReleaseActCtx");
911 report (R_STATUS, "Extracting tests");
912 report (R_PROGRESS, 0, nr_of_files);
913 nr_of_files = 0;
914 nr_of_tests = 0;
915 nr_of_skips = 0;
916 if (!EnumResourceNames (NULL, "TESTRES", extract_test_proc, (LPARAM)tempdir))
917 report (R_FATAL, "Can't enumerate test files: %d",
918 GetLastError ());
920 FreeLibrary(hmscoree);
922 if (aborting) return logname;
924 xprintf ("Test output:\n" );
926 report (R_DELTA, 0, "Extracting: Done");
928 if (nr_native_dlls)
929 report( R_WARNING, "Some dlls are configured as native, you won't be able to submit results." );
931 report (R_STATUS, "Running tests");
932 report (R_PROGRESS, 1, nr_of_tests);
933 for (i = 0; i < nr_of_files; i++) {
934 struct wine_test *test = wine_tests + i;
935 int j;
937 if (aborting) break;
939 if (test->maindllpath) {
940 /* We need to add the path (to the main dll) to PATH */
941 append_path(test->maindllpath);
944 for (j = 0; j < test->subtest_count; j++) {
945 if (aborting) break;
946 run_test (test, test->subtests[j], logfile, tempdir);
949 if (test->maindllpath) {
950 /* Restore PATH again */
951 SetEnvironmentVariableA("PATH", curpath);
954 report (R_DELTA, 0, "Running: Done");
956 report (R_STATUS, "Cleaning up");
957 CloseHandle( logfile );
958 logfile = 0;
959 if (!outdir)
960 remove_dir (tempdir);
961 heap_free(wine_tests);
962 heap_free(curpath);
964 return logname;
967 static BOOL WINAPI ctrl_handler(DWORD ctrl_type)
969 if (ctrl_type == CTRL_C_EVENT) {
970 printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
971 return TRUE;
974 return FALSE;
978 static BOOL CALLBACK
979 extract_only_proc (HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG_PTR lParam)
981 const char *target_dir = (const char *)lParam;
982 char filename[MAX_PATH];
984 if (test_filtered_out( lpszName, NULL )) return TRUE;
986 strcpy(filename, lpszName);
987 CharLowerA(filename);
989 extract_test( &wine_tests[nr_of_files], target_dir, filename );
990 nr_of_files++;
991 return TRUE;
994 static void extract_only (const char *target_dir)
996 BOOL res;
998 report (R_DIR, target_dir);
999 res = CreateDirectoryA( target_dir, NULL );
1000 if (!res && GetLastError() != ERROR_ALREADY_EXISTS)
1001 report (R_FATAL, "Could not create directory: %s (%d)", target_dir, GetLastError ());
1003 nr_of_files = 0;
1004 report (R_STATUS, "Counting tests");
1005 if (!EnumResourceNames (NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
1006 report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
1008 wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0] );
1010 report (R_STATUS, "Extracting tests");
1011 report (R_PROGRESS, 0, nr_of_files);
1012 nr_of_files = 0;
1013 if (!EnumResourceNames (NULL, "TESTRES", extract_only_proc, (LPARAM)target_dir))
1014 report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
1016 report (R_DELTA, 0, "Extracting: Done");
1019 static void
1020 usage (void)
1022 fprintf (stderr,
1023 "Usage: winetest [OPTION]... [TESTS]\n\n"
1024 " --help print this message and exit\n"
1025 " --version print the build version and exit\n"
1026 " -c console mode, no GUI\n"
1027 " -d DIR Use DIR as temp directory (default: %%TEMP%%\\wct)\n"
1028 " -e preserve the environment\n"
1029 " -h print this message and exit\n"
1030 " -i INFO an optional description of the test platform\n"
1031 " -m MAIL an email address to enable developers to contact you\n"
1032 " -n exclude the specified tests\n"
1033 " -p shutdown when the tests are done\n"
1034 " -q quiet mode, no output at all\n"
1035 " -o FILE put report into FILE, do not submit\n"
1036 " -s FILE submit FILE, do not run tests\n"
1037 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n"
1038 " -u URL include TestBot URL in the report\n"
1039 " -x DIR Extract tests to DIR (default: .\\wct) and exit\n");
1042 int main( int argc, char *argv[] )
1044 char *logname = NULL, *outdir = NULL;
1045 const char *extract = NULL;
1046 const char *cp, *submit = NULL;
1047 int reset_env = 1;
1048 int poweroff = 0;
1049 int interactive = 1;
1050 int i;
1052 if (!LoadStringA( 0, IDS_BUILD_ID, build_id, sizeof(build_id) )) build_id[0] = 0;
1054 for (i = 1; i < argc && argv[i]; i++)
1056 if (!strcmp(argv[i], "--help")) {
1057 usage ();
1058 exit (0);
1060 else if (!strcmp(argv[i], "--version")) {
1061 printf("%-12.12s\n", build_id[0] ? build_id : "unknown");
1062 exit (0);
1064 else if ((argv[i][0] != '-' && argv[i][0] != '/') || argv[i][2]) {
1065 if (nb_filters == sizeof(filters)/sizeof(filters[0]))
1067 report (R_ERROR, "Too many test filters specified");
1068 exit (2);
1070 filters[nb_filters++] = argv[i];
1072 else switch (argv[i][1]) {
1073 case 'c':
1074 report (R_TEXTMODE);
1075 interactive = 0;
1076 break;
1077 case 'e':
1078 reset_env = 0;
1079 break;
1080 case 'h':
1081 case '?':
1082 usage ();
1083 exit (0);
1084 case 'i':
1085 if (!(description = argv[++i]))
1087 usage();
1088 exit( 2 );
1090 break;
1091 case 'm':
1092 if (!(email = argv[++i]))
1094 usage();
1095 exit( 2 );
1097 break;
1098 case 'n':
1099 exclude_tests = TRUE;
1100 break;
1101 case 'p':
1102 poweroff = 1;
1103 break;
1104 case 'q':
1105 report (R_QUIET);
1106 interactive = 0;
1107 break;
1108 case 's':
1109 if (!(submit = argv[++i]))
1111 usage();
1112 exit( 2 );
1114 if (tag)
1115 report (R_WARNING, "ignoring tag for submission");
1116 send_file (submit);
1117 break;
1118 case 'o':
1119 if (!(logname = argv[++i]))
1121 usage();
1122 exit( 2 );
1124 break;
1125 case 't':
1126 if (!(tag = argv[++i]))
1128 usage();
1129 exit( 2 );
1131 if (strlen (tag) > MAXTAGLEN)
1132 report (R_FATAL, "tag is too long (maximum %d characters)",
1133 MAXTAGLEN);
1134 cp = findbadtagchar (tag);
1135 if (cp) {
1136 report (R_ERROR, "invalid char in tag: %c", *cp);
1137 usage ();
1138 exit (2);
1140 break;
1141 case 'u':
1142 if (!(url = argv[++i]))
1144 usage();
1145 exit( 2 );
1147 break;
1148 case 'x':
1149 report (R_TEXTMODE);
1150 if (!(extract = argv[++i]))
1151 extract = ".\\wct";
1153 extract_only (extract);
1154 break;
1155 case 'd':
1156 outdir = argv[++i];
1157 break;
1158 default:
1159 report (R_ERROR, "invalid option: -%c", argv[i][1]);
1160 usage ();
1161 exit (2);
1164 if (!submit && !extract) {
1165 int is_win9x = (GetVersion() & 0x80000000) != 0;
1167 report (R_STATUS, "Starting up");
1169 if (is_win9x)
1170 report (R_WARNING, "Running on win9x is not supported. You won't be able to submit results.");
1172 if (!running_on_visible_desktop ())
1173 report (R_FATAL, "Tests must be run on a visible desktop");
1175 if (!check_mount_mgr())
1176 report (R_FATAL, "Mount manager not running, most likely your WINEPREFIX wasn't created correctly.");
1178 if (!check_display_driver())
1179 report (R_FATAL, "Unable to create a window, the display driver is not working.");
1181 SetConsoleCtrlHandler(ctrl_handler, TRUE);
1183 if (reset_env)
1185 SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
1186 SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
1187 SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
1188 SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
1191 while (!tag) {
1192 if (!interactive)
1193 report (R_FATAL, "Please specify a tag (-t option) if "
1194 "running noninteractive!");
1195 if (guiAskTag () == IDABORT) exit (1);
1197 report (R_TAG);
1199 while (!email) {
1200 if (!interactive)
1201 report (R_FATAL, "Please specify an email address (-m option) to enable developers\n"
1202 " to contact you about your report if necessary.");
1203 if (guiAskEmail () == IDABORT) exit (1);
1206 if (!build_id[0])
1207 report( R_WARNING, "You won't be able to submit results without a valid build id.\n"
1208 "To submit results, winetest needs to be built from a git checkout." );
1210 if (!logname) {
1211 logname = run_tests (NULL, outdir);
1212 if (aborting) {
1213 DeleteFileA(logname);
1214 exit (0);
1216 if (build_id[0] && nr_of_skips <= SKIP_LIMIT && !nr_native_dlls && !is_win9x &&
1217 report (R_ASK, MB_YESNO, "Do you want to submit the test results?") == IDYES)
1218 if (!send_file (logname) && !DeleteFileA(logname))
1219 report (R_WARNING, "Can't remove logfile: %u", GetLastError());
1220 } else run_tests (logname, outdir);
1221 report (R_STATUS, "Finished");
1223 if (poweroff)
1225 HANDLE hToken;
1226 TOKEN_PRIVILEGES npr;
1228 /* enable the shutdown privilege for the current process */
1229 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
1231 LookupPrivilegeValueA(0, SE_SHUTDOWN_NAME, &npr.Privileges[0].Luid);
1232 npr.PrivilegeCount = 1;
1233 npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1234 AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
1235 CloseHandle(hToken);
1237 ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);
1239 exit (0);