~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/include/wine/test.h

Version: ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.