winemac.drv: Use nameless unions/structs.
[wine.git] / include / wine / test.h
blobc28128d9f0ce78712552bebf15eea7543ad351eb
1 /*
2 * Definitions for Wine C unit tests.
4 * Copyright (C) 2002 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #ifndef __WINE_WINE_TEST_H
22 #define __WINE_WINE_TEST_H
24 #include <stdarg.h>
25 #include <stdlib.h>
26 #include <io.h>
27 #include <windef.h>
28 #include <winbase.h>
29 #include <wine/debug.h>
31 #ifndef INVALID_FILE_ATTRIBUTES
32 #define INVALID_FILE_ATTRIBUTES (~0u)
33 #endif
34 #ifndef INVALID_SET_FILE_POINTER
35 #define INVALID_SET_FILE_POINTER (~0u)
36 #endif
38 /* debug level */
39 extern int winetest_debug;
41 /* trace timing information */
42 extern int winetest_time;
44 /* running in interactive mode? */
45 extern int winetest_interactive;
47 /* report failed flaky tests as failures (BOOL) */
48 extern int winetest_report_flaky;
50 /* report successful tests (BOOL) */
51 extern int winetest_report_success;
53 /* silence todos and skips above this threshold */
54 extern int winetest_mute_threshold;
56 /* current platform */
57 extern const char *winetest_platform;
59 extern void winetest_set_location( const char* file, int line );
60 extern void winetest_subtest( const char* name );
61 extern void winetest_ignore_exceptions( BOOL ignore );
62 extern void winetest_start_todo( int is_todo );
63 extern int winetest_loop_todo(void);
64 extern void winetest_end_todo(void);
65 extern void winetest_start_flaky( int is_flaky );
66 extern int winetest_loop_flaky(void);
67 extern void winetest_end_flaky(void);
68 extern int winetest_get_mainargs( char*** pargv );
69 extern LONG winetest_get_failures(void);
70 extern void winetest_add_failures( LONG new_failures );
71 extern void winetest_wait_child_process( HANDLE process );
73 #ifdef STANDALONE
74 #define START_TEST(name) \
75 static void func_##name(void); \
76 const struct test winetest_testlist[] = { { #name, func_##name }, { 0, 0 } }; \
77 static void func_##name(void)
78 #else
79 #define START_TEST(name) void func_##name(void)
80 #endif
82 extern int broken( int condition );
83 extern int winetest_vok( int condition, const char *msg, va_list ap );
84 extern void winetest_vskip( const char *msg, va_list ap );
86 extern void winetest_ok( int condition, const char *msg, ... ) __WINE_PRINTF_ATTR(2,3);
87 extern void winetest_skip( const char *msg, ... ) __WINE_PRINTF_ATTR(1,2);
88 extern void winetest_win_skip( const char *msg, ... ) __WINE_PRINTF_ATTR(1,2);
89 extern void winetest_trace( const char *msg, ... ) __WINE_PRINTF_ATTR(1,2);
91 extern void winetest_push_context( const char *fmt, ... ) __WINE_PRINTF_ATTR(1, 2);
92 extern void winetest_pop_context(void);
94 #ifdef WINETEST_NO_LINE_NUMBERS
95 # define subtest_(file, line) (winetest_set_location(file, 0), 0) ? (void)0 : winetest_subtest
96 # define ignore_exceptions_(file, line) (winetest_set_location(file, 0), 0) ? (void)0 : winetest_ignore_exceptions
97 # define ok_(file, line) (winetest_set_location(file, 0), 0) ? (void)0 : winetest_ok
98 # define skip_(file, line) (winetest_set_location(file, 0), 0) ? (void)0 : winetest_skip
99 # define win_skip_(file, line) (winetest_set_location(file, 0), 0) ? (void)0 : winetest_win_skip
100 # define trace_(file, line) (winetest_set_location(file, 0), 0) ? (void)0 : winetest_trace
101 # define wait_child_process_(file, line) (winetest_set_location(file, 0), 0) ? (void)0 : winetest_wait_child_process
102 #else
103 # define subtest_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_subtest
104 # define ignore_exceptions_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_ignore_exceptions
105 # define ok_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_ok
106 # define skip_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_skip
107 # define win_skip_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_win_skip
108 # define trace_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_trace
109 # define wait_child_process_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_wait_child_process
110 #endif
112 #define subtest subtest_(__FILE__, __LINE__)
113 #define ignore_exceptions ignore_exceptions_(__FILE__, __LINE__)
114 #define ok ok_(__FILE__, __LINE__)
115 #define skip skip_(__FILE__, __LINE__)
116 #define win_skip win_skip_(__FILE__, __LINE__)
117 #define trace trace_(__FILE__, __LINE__)
118 #define wait_child_process wait_child_process_(__FILE__, __LINE__)
120 #define flaky_if(is_flaky) for (winetest_start_flaky(is_flaky); \
121 winetest_loop_flaky(); \
122 winetest_end_flaky())
123 #define flaky flaky_if(TRUE)
124 #define flaky_wine flaky_if(!strcmp(winetest_platform, "wine"))
125 #define flaky_wine_if(is_flaky) flaky_if((is_flaky) && !strcmp(winetest_platform, "wine"))
127 #define todo_if(is_todo) for (winetest_start_todo(is_todo); \
128 winetest_loop_todo(); \
129 winetest_end_todo())
130 #define todo_wine todo_if(!strcmp(winetest_platform, "wine"))
131 #define todo_wine_if(is_todo) todo_if((is_todo) && !strcmp(winetest_platform, "wine"))
134 #ifndef ARRAY_SIZE
135 # define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
136 #endif
138 #ifdef NONAMELESSUNION
139 # define U(x) (x).u
140 # define U1(x) (x).u1
141 # define U2(x) (x).u2
142 # define U3(x) (x).u3
143 # define U4(x) (x).u4
144 # define U5(x) (x).u5
145 # define U6(x) (x).u6
146 # define U7(x) (x).u7
147 # define U8(x) (x).u8
148 #else
149 # define U(x) (x)
150 # define U1(x) (x)
151 # define U2(x) (x)
152 # define U3(x) (x)
153 # define U4(x) (x)
154 # define U5(x) (x)
155 # define U6(x) (x)
156 # define U7(x) (x)
157 # define U8(x) (x)
158 #endif
160 #ifdef NONAMELESSSTRUCT
161 # define S(x) (x).s
162 # define S1(x) (x).s1
163 # define S2(x) (x).s2
164 # define S3(x) (x).s3
165 # define S4(x) (x).s4
166 # define S5(x) (x).s5
167 #else
168 # define S(x) (x)
169 # define S1(x) (x)
170 # define S2(x) (x)
171 # define S3(x) (x)
172 # define S4(x) (x)
173 # define S5(x) (x)
174 #endif
177 /************************************************************************/
178 /* Below is the implementation of the various functions, to be included
179 * directly into the generated testlist.c file.
180 * It is done that way so that the dlls can build the test routines with
181 * different includes or flags if needed.
184 #ifdef STANDALONE
186 #include <stdio.h>
187 #include <excpt.h>
189 struct test
191 const char *name;
192 void (*func)(void);
195 extern const struct test winetest_testlist[];
197 /* debug level */
198 int winetest_debug = 1;
200 /* trace timing information */
201 int winetest_time = 0;
202 DWORD winetest_start_time, winetest_last_time;
204 /* interactive mode? */
205 int winetest_interactive = 0;
207 /* current platform */
208 const char *winetest_platform = "windows";
210 /* report failed flaky tests as failures (BOOL) */
211 int winetest_report_flaky = 0;
213 /* report successful tests (BOOL) */
214 int winetest_report_success = 0;
216 /* silence todos and skips above this threshold */
217 int winetest_mute_threshold = 42;
219 /* use ANSI escape codes for output coloring */
220 static int winetest_color;
222 static HANDLE winetest_mutex;
224 /* passing arguments around */
225 static int winetest_argc;
226 static char** winetest_argv;
228 static const struct test *current_test; /* test currently being run */
230 static LONG successes; /* number of successful tests */
231 static LONG failures; /* number of failures */
232 static LONG flaky_failures; /* number of failures inside flaky block */
233 static LONG skipped; /* number of skipped test chunks */
234 static LONG todo_successes; /* number of successful tests inside todo block */
235 static LONG todo_failures; /* number of failures inside todo block */
236 static LONG muted_traces; /* number of silenced traces */
237 static LONG muted_skipped; /* same as skipped but silent */
238 static LONG muted_todo_successes; /* same as todo_successes but silent */
240 /* counts how many times a given line printed a message */
241 static LONG line_counters[16384];
243 /* The following data must be kept track of on a per-thread basis */
244 struct tls_data
246 const char* current_file; /* file of current check */
247 int current_line; /* line of current check */
248 unsigned int flaky_level; /* current flaky nesting level */
249 int flaky_do_loop;
250 unsigned int todo_level; /* current todo nesting level */
251 int todo_do_loop;
252 char *str_pos; /* position in debug buffer */
253 char strings[2000]; /* buffer for debug strings */
254 char context[8][128]; /* data to print before messages */
255 unsigned int context_count; /* number of context prefixes */
257 static DWORD tls_index;
259 static struct tls_data *get_tls_data(void)
261 struct tls_data *data;
262 DWORD last_error;
264 last_error=GetLastError();
265 data=TlsGetValue(tls_index);
266 if (!data)
268 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data));
269 data->str_pos = data->strings;
270 TlsSetValue(tls_index,data);
272 SetLastError(last_error);
273 return data;
276 static void exit_process( int code )
278 fflush( stdout );
279 ExitProcess( code );
283 void winetest_set_location( const char* file, int line )
285 struct tls_data *data = get_tls_data();
286 data->current_file=strrchr(file,'/');
287 if (data->current_file==NULL)
288 data->current_file=strrchr(file,'\\');
289 if (data->current_file==NULL)
290 data->current_file=file;
291 else
292 data->current_file++;
293 data->current_line=line;
296 const char *winetest_elapsed(void)
298 DWORD now;
300 if (!winetest_time) return "";
301 winetest_last_time = now = GetTickCount();
302 return wine_dbg_sprintf( "%.3f", (now - winetest_start_time) / 1000.0);
305 static const char color_reset[] = "\x1b[0m";
306 static const char color_dark_red[] = "\x1b[31m";
307 static const char color_dark_purple[] = "\x1b[35m";
308 static const char color_green[] = "\x1b[32m";
309 static const char color_yellow[] = "\x1b[33m";
310 static const char color_blue[] = "\x1b[34m";
311 static const char color_bright_red[] = "\x1b[1;91m";
312 static const char color_bright_purple[] = "\x1b[1;95m";
314 static void winetest_printf( const char *msg, ... ) __WINE_PRINTF_ATTR(1,2);
315 static void winetest_printf( const char *msg, ... )
317 struct tls_data *data = get_tls_data();
318 va_list valist;
320 printf( "%s:%d:%s ", data->current_file, data->current_line, winetest_elapsed() );
321 va_start( valist, msg );
322 vprintf( msg, valist );
323 va_end( valist );
325 static void winetest_print_context( const char *msgtype )
327 struct tls_data *data = get_tls_data();
328 unsigned int i;
330 winetest_printf( "%s", msgtype );
331 for (i = 0; i < data->context_count; ++i)
332 printf( "%s: ", data->context[i] );
335 static void winetest_print_lock(void)
337 UINT ret;
339 if (!winetest_mutex) return;
340 ret = WaitForSingleObject(winetest_mutex, 30000);
341 if (ret != WAIT_OBJECT_0 && ret != WAIT_ABANDONED)
343 winetest_printf("could not get the print lock: %u\n", ret);
344 winetest_mutex = 0;
348 static void winetest_print_unlock(void)
350 if (winetest_mutex) ReleaseMutex(winetest_mutex);
353 void winetest_subtest( const char* name )
355 winetest_print_lock();
356 winetest_printf( "Subtest %s\n", name );
357 winetest_print_unlock();
360 void winetest_ignore_exceptions( BOOL ignore )
362 winetest_print_lock();
363 winetest_printf( "IgnoreExceptions=%d\n", ignore ? 1 : 0 );
364 winetest_print_unlock();
367 int broken( int condition )
369 return (strcmp(winetest_platform, "windows") == 0) && condition;
372 static LONG winetest_add_line( void )
374 struct tls_data *data;
375 int index, count;
377 if (winetest_debug > 1)
378 return 0;
380 data = get_tls_data();
381 index = data->current_line % ARRAY_SIZE(line_counters);
382 count = InterlockedIncrement(line_counters + index) - 1;
383 if (count == winetest_mute_threshold)
385 winetest_print_lock();
386 winetest_printf( "Line has been silenced after %d occurrences\n", winetest_mute_threshold );
387 winetest_print_unlock();
390 return count;
394 * Checks condition.
395 * Parameters:
396 * - condition - condition to check;
397 * - msg test description;
398 * - file - test application source code file name of the check
399 * - line - test application source code file line number of the check
400 * Return:
401 * 0 if condition does not have the expected value, 1 otherwise
403 int winetest_vok( int condition, const char *msg, va_list args )
405 struct tls_data *data = get_tls_data();
407 if (data->todo_level)
409 if (condition)
411 winetest_print_lock();
412 if (data->flaky_level)
414 if (winetest_color) printf( color_dark_purple );
415 winetest_print_context( "Test succeeded inside flaky todo block: " );
416 vprintf(msg, args);
417 InterlockedIncrement(&flaky_failures);
419 else
421 if (winetest_color) printf( color_dark_red );
422 winetest_print_context( "Test succeeded inside todo block: " );
423 vprintf(msg, args);
424 InterlockedIncrement(&todo_failures);
426 if (winetest_color) printf( color_reset );
427 winetest_print_unlock();
428 return 0;
430 else
432 if (!winetest_debug ||
433 winetest_add_line() < winetest_mute_threshold)
435 if (winetest_debug > 0)
437 winetest_print_lock();
438 if (winetest_color) printf( color_yellow );
439 winetest_print_context( "Test marked todo: " );
440 vprintf(msg, args);
441 if (winetest_color) printf( color_reset );
442 winetest_print_unlock();
444 InterlockedIncrement(&todo_successes);
446 else
447 InterlockedIncrement(&muted_todo_successes);
448 return 1;
451 else
453 if (!condition)
455 winetest_print_lock();
456 if (data->flaky_level)
458 if (winetest_color) printf( color_bright_purple );
459 winetest_print_context( "Test marked flaky: " );
460 vprintf(msg, args);
461 InterlockedIncrement(&flaky_failures);
463 else
465 if (winetest_color) printf( color_bright_red );
466 winetest_print_context( "Test failed: " );
467 vprintf(msg, args);
468 InterlockedIncrement(&failures);
470 if (winetest_color) printf( color_reset );
471 winetest_print_unlock();
472 return 0;
474 else
476 if (winetest_report_success ||
477 (winetest_time && GetTickCount() >= winetest_last_time + 1000))
479 winetest_print_lock();
480 if (winetest_color) printf( color_green );
481 winetest_printf("Test succeeded\n");
482 if (winetest_color) printf( color_reset );
483 winetest_print_unlock();
485 InterlockedIncrement(&successes);
486 return 1;
491 void winetest_ok( int condition, const char *msg, ... )
493 va_list valist;
495 va_start(valist, msg);
496 winetest_vok(condition, msg, valist);
497 va_end(valist);
500 void winetest_trace( const char *msg, ... )
502 va_list valist;
504 if (!winetest_debug)
505 return;
506 if (winetest_add_line() < winetest_mute_threshold)
508 winetest_print_lock();
509 winetest_print_context( "" );
510 va_start(valist, msg);
511 vprintf( msg, valist );
512 va_end(valist);
513 winetest_print_unlock();
515 else
516 InterlockedIncrement(&muted_traces);
519 void winetest_vskip( const char *msg, va_list args )
521 if (winetest_add_line() < winetest_mute_threshold)
523 winetest_print_lock();
524 if (winetest_color) printf( color_blue );
525 winetest_print_context( "Tests skipped: " );
526 vprintf(msg, args);
527 if (winetest_color) printf( color_reset );
528 winetest_print_unlock();
529 InterlockedIncrement(&skipped);
531 else
532 InterlockedIncrement(&muted_skipped);
535 void winetest_skip( const char *msg, ... )
537 va_list valist;
538 va_start(valist, msg);
539 winetest_vskip(msg, valist);
540 va_end(valist);
543 void winetest_win_skip( const char *msg, ... )
545 va_list valist;
546 va_start(valist, msg);
547 if (strcmp(winetest_platform, "windows") == 0)
548 winetest_vskip(msg, valist);
549 else
550 winetest_vok(0, msg, valist);
551 va_end(valist);
554 void winetest_start_flaky( int is_flaky )
556 struct tls_data *data = get_tls_data();
557 data->flaky_level = (data->flaky_level << 1) | (is_flaky != 0);
558 data->flaky_do_loop = 1;
561 int winetest_loop_flaky(void)
563 struct tls_data *data = get_tls_data();
564 int do_flaky = data->flaky_do_loop;
565 data->flaky_do_loop = 0;
566 return do_flaky;
569 void winetest_end_flaky(void)
571 struct tls_data *data = get_tls_data();
572 data->flaky_level >>= 1;
575 void winetest_start_todo( int is_todo )
577 struct tls_data *data = get_tls_data();
578 data->todo_level = (data->todo_level << 1) | (is_todo != 0);
579 data->todo_do_loop=1;
582 int winetest_loop_todo(void)
584 struct tls_data *data = get_tls_data();
585 int do_loop=data->todo_do_loop;
586 data->todo_do_loop=0;
587 return do_loop;
590 void winetest_end_todo(void)
592 struct tls_data *data = get_tls_data();
593 data->todo_level >>= 1;
596 void winetest_push_context( const char *fmt, ... )
598 struct tls_data *data = get_tls_data();
599 va_list valist;
601 if (data->context_count < ARRAY_SIZE(data->context))
603 va_start(valist, fmt);
604 vsnprintf( data->context[data->context_count], sizeof(data->context[data->context_count]), fmt, valist );
605 va_end(valist);
606 data->context[data->context_count][sizeof(data->context[data->context_count]) - 1] = 0;
608 ++data->context_count;
611 void winetest_pop_context(void)
613 struct tls_data *data = get_tls_data();
615 if (data->context_count)
616 --data->context_count;
619 int winetest_get_mainargs( char*** pargv )
621 *pargv = winetest_argv;
622 return winetest_argc;
625 LONG winetest_get_failures(void)
627 return failures;
630 void winetest_add_failures( LONG new_failures )
632 while (new_failures-- > 0)
633 InterlockedIncrement( &failures );
636 void winetest_wait_child_process( HANDLE process )
638 DWORD ret;
640 winetest_ok( process != NULL, "No child process handle (CreateProcess failed?)\n" );
641 if (!process) return;
643 ret = WaitForSingleObject( process, 30000 );
644 if (ret == WAIT_TIMEOUT)
645 winetest_ok( 0, "Timed out waiting for the child process\n" );
646 else if (ret != WAIT_OBJECT_0)
647 winetest_ok( 0, "Could not wait for the child process: %d le=%u\n",
648 (UINT)ret, (UINT)GetLastError() );
649 else
651 DWORD exit_code;
652 GetExitCodeProcess( process, &exit_code );
653 if (exit_code > 255)
655 DWORD pid = GetProcessId( process );
656 winetest_print_lock();
657 if (winetest_color) printf( color_bright_red );
658 winetest_printf( "unhandled exception %08x in child process %04x\n", (UINT)exit_code, (UINT)pid );
659 if (winetest_color) printf( color_reset );
660 winetest_print_unlock();
661 InterlockedIncrement( &failures );
663 else if (exit_code)
665 winetest_print_lock();
666 winetest_printf( "%u failures in child process\n", (UINT)exit_code );
667 winetest_print_unlock();
668 while (exit_code-- > 0)
669 InterlockedIncrement(&failures);
674 /* Find a test by name */
675 static const struct test *find_test( const char *name )
677 const struct test *test;
678 const char *p;
679 size_t len;
681 if ((p = strrchr( name, '/' ))) name = p + 1;
682 if ((p = strrchr( name, '\\' ))) name = p + 1;
683 len = strlen(name);
684 if (len > 2 && !strcmp( name + len - 2, ".c" )) len -= 2;
686 for (test = winetest_testlist; test->name; test++)
688 if (!strncmp( test->name, name, len ) && !test->name[len]) break;
690 return test->name ? test : NULL;
694 /* Display list of valid tests */
695 static void list_tests(void)
697 const struct test *test;
699 printf( "Valid test names:\n" );
700 for (test = winetest_testlist; test->name; test++)
701 printf( " %s\n", test->name );
705 /* Run a named test, and return exit status */
706 static int run_test( const char *name )
708 const struct test *test;
709 int status;
711 if (!(test = find_test( name )))
713 printf( "Fatal: test '%s' does not exist.\n", name );
714 exit_process(1);
716 tls_index=TlsAlloc();
717 current_test = test;
718 test->func();
720 if (winetest_debug)
722 winetest_print_lock();
723 if (muted_todo_successes || muted_skipped || muted_traces)
724 printf( "%04x:%s:%s Silenced %d todos, %d skips and %d traces.\n",
725 (UINT)GetCurrentProcessId(), test->name, winetest_elapsed(),
726 (UINT)muted_todo_successes, (UINT)muted_skipped, (UINT)muted_traces);
727 printf( "%04x:%s:%s %d tests executed (%d marked as todo, %d as flaky, %d %s), %d skipped.\n",
728 (UINT)GetCurrentProcessId(), test->name, winetest_elapsed(),
729 (UINT)(successes + failures + flaky_failures + todo_successes + todo_failures),
730 (UINT)todo_successes, (UINT)flaky_failures, (UINT)(failures + todo_failures),
731 (failures + todo_failures != 1) ? "failures" : "failure",
732 (UINT)skipped );
733 winetest_print_unlock();
735 status = failures + todo_failures;
736 if (winetest_report_flaky) status += flaky_failures;
737 if (status > 255) status = 255;
738 return status;
742 /* Display usage and exit */
743 static void usage( const char *argv0 )
745 printf( "Usage: %s test_name\n\n", argv0 );
746 list_tests();
747 exit_process(1);
750 /* trap unhandled exceptions */
751 static LONG CALLBACK exc_filter( EXCEPTION_POINTERS *ptrs )
753 struct tls_data *data = get_tls_data();
755 winetest_print_lock();
756 if (data->current_file)
757 printf( "%s:%d: this is the last test seen before the exception\n",
758 data->current_file, data->current_line );
759 if (winetest_color) printf( color_bright_red );
760 printf( "%04x:%s:%s unhandled exception %08x at %p\n",
761 (UINT)GetCurrentProcessId(), current_test->name, winetest_elapsed(),
762 (UINT)ptrs->ExceptionRecord->ExceptionCode, ptrs->ExceptionRecord->ExceptionAddress );
763 if (winetest_color) printf( color_reset );
764 fflush( stdout );
765 winetest_print_unlock();
766 return EXCEPTION_EXECUTE_HANDLER;
769 /* check if we're running under wine */
770 static BOOL running_under_wine(void)
772 HMODULE module = GetModuleHandleA( "ntdll.dll" );
773 if (!module) return FALSE;
774 return (GetProcAddress( module, "wine_server_call" ) != NULL);
777 #ifdef __GNUC__
778 void _fpreset(void) {} /* override the mingw fpu init code */
779 #endif
781 /* main function */
782 int main( int argc, char **argv )
784 char p[128];
786 setvbuf (stdout, NULL, _IONBF, 0);
787 winetest_mutex = CreateMutexA(NULL, FALSE, "winetest_print_mutex");
789 winetest_argc = argc;
790 winetest_argv = argv;
792 if (GetEnvironmentVariableA( "WINETEST_PLATFORM", p, sizeof(p) ))
793 winetest_platform = strdup(p);
794 else if (running_under_wine())
795 winetest_platform = "wine";
797 if (GetEnvironmentVariableA( "WINETEST_COLOR", p, sizeof(p) ))
799 BOOL automode = !strcmp(p, "auto");
800 winetest_color = automode ? isatty( fileno( stdout ) ) : atoi(p);
801 /* enable ANSI support for Windows console */
802 if (winetest_color)
804 HANDLE hOutput = (HANDLE)_get_osfhandle( fileno( stdout ) );
805 DWORD mode;
806 if (GetConsoleMode( hOutput, &mode ) &&
807 !SetConsoleMode( hOutput, mode | ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING ) &&
808 automode)
809 winetest_color = 0;
812 if (GetEnvironmentVariableA( "WINETEST_DEBUG", p, sizeof(p) )) winetest_debug = atoi(p);
813 if (GetEnvironmentVariableA( "WINETEST_INTERACTIVE", p, sizeof(p) )) winetest_interactive = atoi(p);
814 if (GetEnvironmentVariableA( "WINETEST_REPORT_FLAKY", p, sizeof(p) )) winetest_report_flaky = atoi(p);
815 if (GetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", p, sizeof(p) )) winetest_report_success = atoi(p);
816 if (GetEnvironmentVariableA( "WINETEST_TIME", p, sizeof(p) )) winetest_time = atoi(p);
817 winetest_last_time = winetest_start_time = GetTickCount();
819 if (!strcmp( winetest_platform, "windows" )) SetUnhandledExceptionFilter( exc_filter );
820 if (!winetest_interactive) SetErrorMode( SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX );
822 if (!argv[1])
824 if (winetest_testlist[0].name && !winetest_testlist[1].name) /* only one test */
825 return run_test( winetest_testlist[0].name );
826 usage( argv[0] );
828 if (!strcmp( argv[1], "--list" ))
830 list_tests();
831 return 0;
833 return run_test(argv[1]);
836 #endif /* STANDALONE */
838 #endif /* __WINE_WINE_TEST_H */