VirtualBox

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

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

LGPL disclaimer by filemuncher

  • Property svn:eol-style set to native
File size: 13.9 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 ((DWORD)~0UL)
53#endif
54#ifndef INVALID_SET_FILE_POINTER
55#define INVALID_SET_FILE_POINTER ((DWORD)~0UL)
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 if (msg[0])
273 {
274 fprintf(stdout,": ");
275 vfprintf(stdout, msg, args);
276 }
277 InterlockedIncrement(&todo_failures);
278 return 0;
279 }
280 else InterlockedIncrement(&todo_successes);
281 }
282 else
283 {
284 if (!condition)
285 {
286 fprintf( stdout, "%s:%d: Test failed",
287 data->current_file, data->current_line );
288 if (msg[0])
289 {
290 fprintf( stdout,": ");
291 vfprintf(stdout, msg, args);
292 }
293 InterlockedIncrement(&failures);
294 return 0;
295 }
296 else
297 {
298 if (report_success)
299 fprintf( stdout, "%s:%d: Test succeeded\n",
300 data->current_file, data->current_line);
301 InterlockedIncrement(&successes);
302 }
303 }
304 return 1;
305}
306
307int winetest_ok( int condition, const char *msg, ... )
308{
309 va_list valist;
310 int rc;
311
312 va_start(valist, msg);
313 rc=winetest_vok(condition, msg, valist);
314 va_end(valist);
315 return rc;
316}
317
318void winetest_trace( const char *msg, ... )
319{
320 va_list valist;
321 tls_data* data=get_tls_data();
322
323 if (winetest_debug > 0)
324 {
325 fprintf( stdout, "%s:%d: ", data->current_file, data->current_line );
326 va_start(valist, msg);
327 vfprintf(stdout, msg, valist);
328 va_end(valist);
329 }
330}
331
332void winetest_vskip( const char *msg, va_list args )
333{
334 tls_data* data=get_tls_data();
335
336 fprintf( stdout, "%s:%d: Tests skipped: ", data->current_file, data->current_line );
337 vfprintf(stdout, msg, args);
338 skipped++;
339}
340
341void winetest_skip( const char *msg, ... )
342{
343 va_list valist;
344 va_start(valist, msg);
345 winetest_vskip(msg, valist);
346 va_end(valist);
347}
348
349void winetest_win_skip( const char *msg, ... )
350{
351 va_list valist;
352 va_start(valist, msg);
353 if (strcmp(winetest_platform, "windows") == 0)
354 winetest_vskip(msg, valist);
355 else
356 winetest_vok(0, msg, valist);
357 va_end(valist);
358}
359
360void winetest_start_todo( const char* platform )
361{
362 tls_data* data=get_tls_data();
363 if (strcmp(winetest_platform,platform)==0)
364 data->todo_level++;
365 data->todo_do_loop=1;
366}
367
368int winetest_loop_todo(void)
369{
370 tls_data* data=get_tls_data();
371 int do_loop=data->todo_do_loop;
372 data->todo_do_loop=0;
373 return do_loop;
374}
375
376void winetest_end_todo( const char* platform )
377{
378 if (strcmp(winetest_platform,platform)==0)
379 {
380 tls_data* data=get_tls_data();
381 data->todo_level--;
382 }
383}
384
385int winetest_get_mainargs( char*** pargv )
386{
387 *pargv = winetest_argv;
388 return winetest_argc;
389}
390
391void winetest_wait_child_process( HANDLE process )
392{
393 DWORD exit_code = 1;
394
395 if (WaitForSingleObject( process, 30000 ))
396 fprintf( stdout, "%s: child process wait failed\n", current_test->name );
397 else
398 GetExitCodeProcess( process, &exit_code );
399
400 if (exit_code)
401 {
402 if (exit_code > 255)
403 {
404 fprintf( stdout, "%s: exception 0x%08x in child process\n", current_test->name, exit_code );
405 InterlockedIncrement( &failures );
406 }
407 else
408 {
409 fprintf( stdout, "%s: %u failures in child process\n",
410 current_test->name, exit_code );
411 while (exit_code-- > 0)
412 InterlockedIncrement(&failures);
413 }
414 }
415}
416
417/* Find a test by name */
418static const struct test *find_test( const char *name )
419{
420 const struct test *test;
421 const char *p;
422 size_t len;
423
424 if ((p = strrchr( name, '/' ))) name = p + 1;
425 if ((p = strrchr( name, '\\' ))) name = p + 1;
426 len = strlen(name);
427 if (len > 2 && !strcmp( name + len - 2, ".c" )) len -= 2;
428
429 for (test = winetest_testlist; test->name; test++)
430 {
431 if (!strncmp( test->name, name, len ) && !test->name[len]) break;
432 }
433 return test->name ? test : NULL;
434}
435
436
437/* Display list of valid tests */
438static void list_tests(void)
439{
440 const struct test *test;
441
442 fprintf( stdout, "Valid test names:\n" );
443 for (test = winetest_testlist; test->name; test++) fprintf( stdout, " %s\n", test->name );
444}
445
446
447/* Run a named test, and return exit status */
448static int run_test( const char *name )
449{
450 const struct test *test;
451 int status;
452
453 if (!(test = find_test( name )))
454 {
455 fprintf( stdout, "Fatal: test '%s' does not exist.\n", name );
456 exit_process(1);
457 }
458 successes = failures = todo_successes = todo_failures = 0;
459 tls_index=TlsAlloc();
460 current_test = test;
461 test->func();
462
463 if (winetest_debug)
464 {
465 fprintf( stdout, "%s: %d tests executed (%d marked as todo, %d %s), %d skipped.\n",
466 test->name, successes + failures + todo_successes + todo_failures,
467 todo_successes, failures + todo_failures,
468 (failures + todo_failures != 1) ? "failures" : "failure",
469 skipped );
470 }
471 status = (failures + todo_failures < 255) ? failures + todo_failures : 255;
472 return status;
473}
474
475
476/* Display usage and exit */
477static void usage( const char *argv0 )
478{
479 fprintf( stdout, "Usage: %s test_name\n\n", argv0 );
480 list_tests();
481 exit_process(1);
482}
483
484
485/* main function */
486int main( int argc, char **argv )
487{
488 char p[128];
489
490 setvbuf (stdout, NULL, _IONBF, 0);
491
492 winetest_argc = argc;
493 winetest_argv = argv;
494
495 if (GetEnvironmentVariableA( "WINETEST_PLATFORM", p, sizeof(p) )) winetest_platform = strdup(p);
496 if (GetEnvironmentVariableA( "WINETEST_DEBUG", p, sizeof(p) )) winetest_debug = atoi(p);
497 if (GetEnvironmentVariableA( "WINETEST_INTERACTIVE", p, sizeof(p) )) winetest_interactive = atoi(p);
498 if (GetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", p, sizeof(p) )) report_success = atoi(p);
499
500 if (!argv[1])
501 {
502 if (winetest_testlist[0].name && !winetest_testlist[1].name) /* only one test */
503 return run_test( winetest_testlist[0].name );
504 usage( argv[0] );
505 }
506 if (!strcmp( argv[1], "--list" ))
507 {
508 list_tests();
509 return 0;
510 }
511 return run_test(argv[1]);
512}
513
514#endif /* STANDALONE */
515
516#endif /* __WINE_WINE_TEST_H */
Note: See TracBrowser for help on using the repository browser.

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