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
27 int winetest_debug = 1;
29 /* current platform */
30 const char *winetest_platform = "windows";
38 extern const struct test winetest_testlist[];
39 static const struct test *current_test; /* test currently being run */
41 static int successes; /* number of successful tests */
42 static int failures; /* number of failures */
43 static int todo_successes; /* number of successful tests inside todo block */
44 static int todo_failures; /* number of failures inside todo block */
45 static int todo_level; /* current todo nesting level */
50 * - condition - condition to check;
51 * - msg test description;
52 * - file - test application source code file name of the check
53 * - line - test application source code file line number of the check
55 void winetest_ok( int condition, const char *msg, const char *file, int line )
61 fprintf( stderr, "%s:%d: Test succeeded inside todo block", file, line );
62 if (msg && msg[0]) fprintf( stderr, ": %s", msg );
63 fputc( '\n', stderr );
66 else todo_successes++;
72 fprintf( stderr, "%s:%d: Test failed", file, line );
73 if (msg && msg[0]) fprintf( stderr, ": %s", msg );
74 fputc( '\n', stderr );
82 /* Find a test by name */
83 static const struct test *find_test( const char *name )
85 const struct test *test;
89 if ((p = strrchr( name, '/' ))) name = p + 1;
90 if ((p = strrchr( name, '\\' ))) name = p + 1;
92 if (len > 2 && !strcmp( name + len - 2, ".c" )) len -= 2;
94 for (test = winetest_testlist; test->name; test++)
96 if (!strncmp( test->name, name, len ) && !test->name[len]) break;
98 return test->name ? test : NULL;
102 /* Run a named test, and return exit status */
103 static int run_test( const char *name )
105 const struct test *test;
108 if (!(test = find_test( name )))
110 fprintf( stderr, "Fatal: test '%s' does not exist.\n", name );
113 successes = failures = todo_successes = todo_failures = 0;
120 fprintf( stderr, "%s: %d tests executed, %d marked as todo, %d %s.\n",
121 name, successes + failures + todo_successes + todo_failures,
122 todo_successes, failures + todo_failures,
123 (failures + todo_failures != 1) ? "failures" : "failure" );
125 status = (failures + todo_failures < 255) ? failures + todo_failures : 255;
131 int main( int argc, char **argv )
135 if ((p = getenv( "WINETEST_PLATFORM" ))) winetest_platform = p;
136 if ((p = getenv( "WINETEST_DEBUG" ))) winetest_debug = atoi(p);
139 fprintf( stderr, "Usage: %s test_name\n", argv[0] );
142 exit( run_test(argv[1]) );