VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/test.h@ 20636

Last change on this file since 20636 was 19678, checked in by vboxsync, 16 years ago

opengl: update wine to 1.1.21, add d3d9.dll to build list

  • Property svn:eol-style set to native
File size: 14.0 KB
Line 
1/*
2 * Definitions for Wine C unit tests.
3 *
4 * Copyright (C) 2002 Alexandre Julliard
5 *
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.
10 *
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.
15 *
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
19 */
20
21/*
22 * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
23 * other than GPL or LGPL is available it will apply instead, Sun elects to use only
24 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
25 * a choice of LGPL license versions is made available with the language indicating
26 * that LGPLv2 or any later version may be used, or where a choice of which version
27 * of the LGPL is applied is otherwise unspecified.
28 */
29
30#ifndef __WINE_WINE_TEST_H
31#define __WINE_WINE_TEST_H
32
33#include <stdarg.h>
34#include <stdlib.h>
35#include <windef.h>
36#include <winbase.h>
37
38#ifdef __WINE_CONFIG_H
39#error config.h should not be used in Wine tests
40#endif
41#ifdef __WINE_WINE_LIBRARY_H
42#error wine/library.h should not be used in Wine tests
43#endif
44#ifdef __WINE_WINE_UNICODE_H
45#error wine/unicode.h should not be used in Wine tests
46#endif
47#ifdef __WINE_WINE_DEBUG_H
48#error wine/debug.h should not be used in Wine tests
49#endif
50
51#ifndef INVALID_FILE_ATTRIBUTES
52#define INVALID_FILE_ATTRIBUTES (~0u)
53#endif
54#ifndef INVALID_SET_FILE_POINTER
55#define INVALID_SET_FILE_POINTER (~0u)
56#endif
57
58/* debug level */
59extern int winetest_debug;
60
61/* running in interactive mode? */
62extern int winetest_interactive;
63
64/* current platform */
65extern const char *winetest_platform;
66
67extern void winetest_set_location( const char* file, int line );
68extern void winetest_start_todo( const char* platform );
69extern int winetest_loop_todo(void);
70extern void winetest_end_todo( const char* platform );
71extern int winetest_get_mainargs( char*** pargv );
72extern void winetest_wait_child_process( HANDLE process );
73
74#ifdef STANDALONE
75#define START_TEST(name) \
76 static void func_##name(void); \
77 const struct test winetest_testlist[] = { { #name, func_##name }, { 0, 0 } }; \
78 static void func_##name(void)
79#else
80#define START_TEST(name) void func_##name(void)
81#endif
82
83extern int broken( int condition );
84extern int winetest_vok( int condition, const char *msg, va_list ap );
85extern void winetest_vskip( const char *msg, va_list ap );
86
87#ifdef __GNUC__
88
89extern int winetest_ok( int condition, const char *msg, ... ) __attribute__((format (printf,2,3) ));
90extern void winetest_skip( const char *msg, ... ) __attribute__((format (printf,1,2)));
91extern void winetest_win_skip( const char *msg, ... ) __attribute__((format (printf,1,2)));
92extern void winetest_trace( const char *msg, ... ) __attribute__((format (printf,1,2)));
93
94#else /* __GNUC__ */
95
96extern int winetest_ok( int condition, const char *msg, ... );
97extern void winetest_skip( const char *msg, ... );
98extern void winetest_win_skip( const char *msg, ... );
99extern void winetest_trace( const char *msg, ... );
100
101#endif /* __GNUC__ */
102
103#define ok_(file, line) (winetest_set_location(file, line), 0) ? 0 : winetest_ok
104#define skip_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_skip
105#define win_skip_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_win_skip
106#define trace_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_trace
107
108#define ok ok_(__FILE__, __LINE__)
109#define skip skip_(__FILE__, __LINE__)
110#define win_skip win_skip_(__FILE__, __LINE__)
111#define trace trace_(__FILE__, __LINE__)
112
113#define todo(platform) for (winetest_start_todo(platform); \
114 winetest_loop_todo(); \
115 winetest_end_todo(platform))
116#define todo_wine todo("wine")
117
118
119#ifdef NONAMELESSUNION
120# define U(x) (x).u
121# define U1(x) (x).u1
122# define U2(x) (x).u2
123# define U3(x) (x).u3
124# define U4(x) (x).u4
125# define U5(x) (x).u5
126# define U6(x) (x).u6
127# define U7(x) (x).u7
128# define U8(x) (x).u8
129#else
130# define U(x) (x)
131# define U1(x) (x)
132# define U2(x) (x)
133# define U3(x) (x)
134# define U4(x) (x)
135# define U5(x) (x)
136# define U6(x) (x)
137# define U7(x) (x)
138# define U8(x) (x)
139#endif
140
141#ifdef NONAMELESSSTRUCT
142# define S(x) (x).s
143# define S1(x) (x).s1
144# define S2(x) (x).s2
145# define S3(x) (x).s3
146# define S4(x) (x).s4
147# define S5(x) (x).s5
148#else
149# define S(x) (x)
150# define S1(x) (x)
151# define S2(x) (x)
152# define S3(x) (x)
153# define S4(x) (x)
154# define S5(x) (x)
155#endif
156
157
158/************************************************************************/
159/* Below is the implementation of the various functions, to be included
160 * directly into the generated testlist.c file.
161 * It is done that way so that the dlls can build the test routines with
162 * different includes or flags if needed.
163 */
164
165#ifdef STANDALONE
166
167#include <stdio.h>
168
169struct test
170{
171 const char *name;
172 void (*func)(void);
173};
174
175extern const struct test winetest_testlist[];
176
177/* debug level */
178int winetest_debug = 1;
179
180/* interactive mode? */
181int winetest_interactive = 0;
182
183/* current platform */
184const char *winetest_platform = "windows";
185
186/* report successful tests (BOOL) */
187static int report_success = 0;
188
189/* passing arguments around */
190static int winetest_argc;
191static char** winetest_argv;
192
193static const struct test *current_test; /* test currently being run */
194
195static LONG successes; /* number of successful tests */
196static LONG failures; /* number of failures */
197static LONG skipped; /* number of skipped test chunks */
198static LONG todo_successes; /* number of successful tests inside todo block */
199static LONG todo_failures; /* number of failures inside todo block */
200
201/* The following data must be kept track of on a per-thread basis */
202typedef struct
203{
204 const char* current_file; /* file of current check */
205 int current_line; /* line of current check */
206 int todo_level; /* current todo nesting level */
207 int todo_do_loop;
208} tls_data;
209static DWORD tls_index;
210
211static tls_data* get_tls_data(void)
212{
213 tls_data* data;
214 DWORD last_error;
215
216 last_error=GetLastError();
217 data=TlsGetValue(tls_index);
218 if (!data)
219 {
220 data=HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(tls_data));
221 TlsSetValue(tls_index,data);
222 }
223 SetLastError(last_error);
224 return data;
225}
226
227static void exit_process( int code )
228{
229 fflush( stdout );
230 ExitProcess( code );
231}
232
233
234void winetest_set_location( const char* file, int line )
235{
236 tls_data* data=get_tls_data();
237 data->current_file=strrchr(file,'/');
238 if (data->current_file==NULL)
239 data->current_file=strrchr(file,'\\');
240 if (data->current_file==NULL)
241 data->current_file=file;
242 else
243 data->current_file++;
244 data->current_line=line;
245}
246
247int broken( int condition )
248{
249 return (strcmp(winetest_platform, "windows") == 0) && condition;
250}
251
252/*
253 * Checks condition.
254 * Parameters:
255 * - condition - condition to check;
256 * - msg test description;
257 * - file - test application source code file name of the check
258 * - line - test application source code file line number of the check
259 * Return:
260 * 0 if condition does not have the expected value, 1 otherwise
261 */
262int winetest_vok( int condition, const char *msg, va_list args )
263{
264 tls_data* data=get_tls_data();
265
266 if (data->todo_level)
267 {
268 if (condition)
269 {
270 fprintf( stdout, "%s:%d: Test succeeded inside todo block: ",
271 data->current_file, data->current_line );
272 vfprintf(stdout, msg, args);
273 InterlockedIncrement(&todo_failures);
274 return 0;
275 }
276 else
277 {
278 if (winetest_debug > 0)
279 {
280 fprintf( stdout, "%s:%d: Test marked todo: ",
281 data->current_file, data->current_line );
282 vfprintf(stdout, msg, args);
283 }
284 InterlockedIncrement(&todo_successes);
285 return 1;
286 }
287 }
288 else
289 {
290 if (!condition)
291 {
292 fprintf( stdout, "%s:%d: Test failed: ",
293 data->current_file, data->current_line );
294 vfprintf(stdout, msg, args);
295 InterlockedIncrement(&failures);
296 return 0;
297 }
298 else
299 {
300 if (report_success)
301 fprintf( stdout, "%s:%d: Test succeeded\n",
302 data->current_file, data->current_line);
303 InterlockedIncrement(&successes);
304 return 1;
305 }
306 }
307}
308
309int winetest_ok( int condition, const char *msg, ... )
310{
311 va_list valist;
312 int rc;
313
314 va_start(valist, msg);
315 rc=winetest_vok(condition, msg, valist);
316 va_end(valist);
317 return rc;
318}
319
320void winetest_trace( const char *msg, ... )
321{
322 va_list valist;
323 tls_data* data=get_tls_data();
324
325 if (winetest_debug > 0)
326 {
327 fprintf( stdout, "%s:%d: ", data->current_file, data->current_line );
328 va_start(valist, msg);
329 vfprintf(stdout, msg, valist);
330 va_end(valist);
331 }
332}
333
334void winetest_vskip( const char *msg, va_list args )
335{
336 tls_data* data=get_tls_data();
337
338 fprintf( stdout, "%s:%d: Tests skipped: ", data->current_file, data->current_line );
339 vfprintf(stdout, msg, args);
340 skipped++;
341}
342
343void winetest_skip( const char *msg, ... )
344{
345 va_list valist;
346 va_start(valist, msg);
347 winetest_vskip(msg, valist);
348 va_end(valist);
349}
350
351void winetest_win_skip( const char *msg, ... )
352{
353 va_list valist;
354 va_start(valist, msg);
355 if (strcmp(winetest_platform, "windows") == 0)
356 winetest_vskip(msg, valist);
357 else
358 winetest_vok(0, msg, valist);
359 va_end(valist);
360}
361
362void winetest_start_todo( const char* platform )
363{
364 tls_data* data=get_tls_data();
365 if (strcmp(winetest_platform,platform)==0)
366 data->todo_level++;
367 data->todo_do_loop=1;
368}
369
370int winetest_loop_todo(void)
371{
372 tls_data* data=get_tls_data();
373 int do_loop=data->todo_do_loop;
374 data->todo_do_loop=0;
375 return do_loop;
376}
377
378void winetest_end_todo( const char* platform )
379{
380 if (strcmp(winetest_platform,platform)==0)
381 {
382 tls_data* data=get_tls_data();
383 data->todo_level--;
384 }
385}
386
387int winetest_get_mainargs( char*** pargv )
388{
389 *pargv = winetest_argv;
390 return winetest_argc;
391}
392
393void winetest_wait_child_process( HANDLE process )
394{
395 DWORD exit_code = 1;
396
397 if (WaitForSingleObject( process, 30000 ))
398 fprintf( stdout, "%s: child process wait failed\n", current_test->name );
399 else
400 GetExitCodeProcess( process, &exit_code );
401
402 if (exit_code)
403 {
404 if (exit_code > 255)
405 {
406 fprintf( stdout, "%s: exception 0x%08x in child process\n", current_test->name, exit_code );
407 InterlockedIncrement( &failures );
408 }
409 else
410 {
411 fprintf( stdout, "%s: %u failures in child process\n",
412 current_test->name, exit_code );
413 while (exit_code-- > 0)
414 InterlockedIncrement(&failures);
415 }
416 }
417}
418
419/* Find a test by name */
420static const struct test *find_test( const char *name )
421{
422 const struct test *test;
423 const char *p;
424 size_t len;
425
426 if ((p = strrchr( name, '/' ))) name = p + 1;
427 if ((p = strrchr( name, '\\' ))) name = p + 1;
428 len = strlen(name);
429 if (len > 2 && !strcmp( name + len - 2, ".c" )) len -= 2;
430
431 for (test = winetest_testlist; test->name; test++)
432 {
433 if (!strncmp( test->name, name, len ) && !test->name[len]) break;
434 }
435 return test->name ? test : NULL;
436}
437
438
439/* Display list of valid tests */
440static void list_tests(void)
441{
442 const struct test *test;
443
444 fprintf( stdout, "Valid test names:\n" );
445 for (test = winetest_testlist; test->name; test++) fprintf( stdout, " %s\n", test->name );
446}
447
448
449/* Run a named test, and return exit status */
450static int run_test( const char *name )
451{
452 const struct test *test;
453 int status;
454
455 if (!(test = find_test( name )))
456 {
457 fprintf( stdout, "Fatal: test '%s' does not exist.\n", name );
458 exit_process(1);
459 }
460 successes = failures = todo_successes = todo_failures = 0;
461 tls_index=TlsAlloc();
462 current_test = test;
463 test->func();
464
465 if (winetest_debug)
466 {
467 fprintf( stdout, "%s: %d tests executed (%d marked as todo, %d %s), %d skipped.\n",
468 test->name, successes + failures + todo_successes + todo_failures,
469 todo_successes, failures + todo_failures,
470 (failures + todo_failures != 1) ? "failures" : "failure",
471 skipped );
472 }
473 status = (failures + todo_failures < 255) ? failures + todo_failures : 255;
474 return status;
475}
476
477
478/* Display usage and exit */
479static void usage( const char *argv0 )
480{
481 fprintf( stdout, "Usage: %s test_name\n\n", argv0 );
482 list_tests();
483 exit_process(1);
484}
485
486
487/* main function */
488int main( int argc, char **argv )
489{
490 char p[128];
491
492 setvbuf (stdout, NULL, _IONBF, 0);
493
494 winetest_argc = argc;
495 winetest_argv = argv;
496
497 if (GetEnvironmentVariableA( "WINETEST_PLATFORM", p, sizeof(p) )) winetest_platform = strdup(p);
498 if (GetEnvironmentVariableA( "WINETEST_DEBUG", p, sizeof(p) )) winetest_debug = atoi(p);
499 if (GetEnvironmentVariableA( "WINETEST_INTERACTIVE", p, sizeof(p) )) winetest_interactive = atoi(p);
500 if (GetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", p, sizeof(p) )) report_success = atoi(p);
501
502 if (!argv[1])
503 {
504 if (winetest_testlist[0].name && !winetest_testlist[1].name) /* only one test */
505 return run_test( winetest_testlist[0].name );
506 usage( argv[0] );
507 }
508 if (!strcmp( argv[1], "--list" ))
509 {
510 list_tests();
511 return 0;
512 }
513 return run_test(argv[1]);
514}
515
516#endif /* STANDALONE */
517
518#endif /* __WINE_WINE_TEST_H */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette