2 * Main routine for Wine C unit tests.
4 * Copyright 2002 Alexandre Julliard
5 * Copyright 2002 Andriy Palamarchuk
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "wine/test.h"
29 int winetest_debug = 1;
31 /* current platform */
32 const char *winetest_platform = "windows";
40 extern const struct test winetest_testlist[];
41 static const struct test *current_test; /* test currently being run */
42 /* FIXME: Access to all the following variables must be protected in a
43 * multithread test. Either via thread local storage or via critical sections
45 static const char* current_file; /* file of current check */
46 static int current_line; /* line of current check */
48 static int successes; /* number of successful tests */
49 static int failures; /* number of failures */
50 static int todo_successes; /* number of successful tests inside todo block */
51 static int todo_failures; /* number of failures inside todo block */
52 static int todo_level; /* current todo nesting level */
53 static int todo_do_loop;
58 * - condition - condition to check;
59 * - msg test description;
60 * - file - test application source code file name of the check
61 * - line - test application source code file line number of the check
63 * 0 if condition does not have the expected value, 1 otherwise
65 int winetest_ok( int condition, const char *msg, ... )
73 fprintf( stderr, "%s:%d: Test succeeded inside todo block",
74 current_file, current_line );
77 va_start(valist, msg);
79 vfprintf(stderr, msg, valist);
82 fputc( '\n', stderr );
86 else todo_successes++;
92 fprintf( stderr, "%s:%d: Test failed",
93 current_file, current_line );
96 va_start(valist, msg);
97 fprintf( stderr,": ");
98 vfprintf(stderr, msg, valist);
101 fputc( '\n', stderr );
110 winetest_ok_funcptr winetest_set_ok_location( const char* file, int line )
117 void winetest_trace( const char *msg, ... )
121 if (winetest_debug > 0)
123 va_start(valist, msg);
124 vfprintf(stderr, msg, valist);
129 winetest_trace_funcptr winetest_set_trace_location( const char* file, int line )
133 return &winetest_trace;
136 void winetest_start_todo( const char* platform )
138 if (strcmp(winetest_platform,platform)==0)
143 int winetest_loop_todo(void)
145 int do_loop=todo_do_loop;
150 void winetest_end_todo( const char* platform )
152 if (strcmp(winetest_platform,platform)==0)
156 /* Find a test by name */
157 static const struct test *find_test( const char *name )
159 const struct test *test;
163 if ((p = strrchr( name, '/' ))) name = p + 1;
164 if ((p = strrchr( name, '\\' ))) name = p + 1;
166 if (len > 2 && !strcmp( name + len - 2, ".c" )) len -= 2;
168 for (test = winetest_testlist; test->name; test++)
170 if (!strncmp( test->name, name, len ) && !test->name[len]) break;
172 return test->name ? test : NULL;
176 /* Run a named test, and return exit status */
177 static int run_test( const char *name )
179 const struct test *test;
182 if (!(test = find_test( name )))
184 fprintf( stderr, "Fatal: test '%s' does not exist.\n", name );
187 successes = failures = todo_successes = todo_failures = 0;
194 fprintf( stderr, "%s: %d tests executed, %d marked as todo, %d %s.\n",
195 name, successes + failures + todo_successes + todo_failures,
196 todo_successes, failures + todo_failures,
197 (failures + todo_failures != 1) ? "failures" : "failure" );
199 status = (failures + todo_failures < 255) ? failures + todo_failures : 255;
205 int main( int argc, char **argv )
209 if ((p = getenv( "WINETEST_PLATFORM" ))) winetest_platform = p;
210 if ((p = getenv( "WINETEST_DEBUG" ))) winetest_debug = atoi(p);
213 fprintf( stderr, "Usage: %s test_name\n", argv[0] );
216 exit( run_test(argv[1]) );