ReactOS  0.4.14-dev-833-g5f692ed
test.h
Go to the documentation of this file.
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_CONFIG_H
30 #error config.h should not be used in Wine tests
31 #endif
32 #ifdef __WINE_WINE_LIBRARY_H
33 #error wine/library.h should not be used in Wine tests
34 #endif
35 #ifdef __WINE_WINE_UNICODE_H
36 #error wine/unicode.h should not be used in Wine tests
37 #endif
38 #ifdef __WINE_WINE_DEBUG_H
39 #error wine/debug.h should not be used in Wine tests
40 #endif
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 #ifndef INVALID_FILE_ATTRIBUTES
47 #define INVALID_FILE_ATTRIBUTES (~0u)
48 #endif
49 #ifndef INVALID_SET_FILE_POINTER
50 #define INVALID_SET_FILE_POINTER (~0u)
51 #endif
52 
53 /* debug level */
54 extern int winetest_debug;
55 
56 extern int report_success;
57 
58 /* running in interactive mode? */
59 extern int winetest_interactive;
60 
61 /* current platform */
62 extern const char *winetest_platform;
63 
64 extern void winetest_set_location( const char* file, int line );
65 extern void winetest_start_todo( int is_todo );
66 extern int winetest_loop_todo(void);
67 extern void winetest_end_todo(void);
68 extern void winetest_start_nocount(unsigned int flags);
69 extern int winetest_loop_nocount(void);
70 extern void winetest_end_nocount(void);
71 extern int winetest_get_mainargs( char*** pargv );
72 extern LONG winetest_get_failures(void);
73 extern LONG winetest_get_successes(void);
74 extern void winetest_add_failures( LONG new_failures );
76 
77 extern const char *wine_dbgstr_wn( const WCHAR *str, intptr_t n );
78 extern const char *wine_dbgstr_guid( const GUID *guid );
79 extern const char *wine_dbgstr_point( const POINT *guid );
80 extern const char *wine_dbgstr_size( const SIZE *guid );
81 extern const char *wine_dbgstr_rect( const RECT *rect );
82 #ifdef WINETEST_USE_DBGSTR_LONGLONG
83 extern const char *wine_dbgstr_longlong( ULONGLONG ll );
84 #endif
85 static inline const char *wine_dbgstr_w( const WCHAR *s ) { return wine_dbgstr_wn( s, -1 ); }
86 
87 /* strcmpW is available for tests compiled under Wine, but not in standalone
88  * builds under Windows, so we reimplement it under a different name. */
89 static inline int winetest_strcmpW( const WCHAR *str1, const WCHAR *str2 )
90 {
91  while (*str1 && (*str1 == *str2)) { str1++; str2++; }
92  return *str1 - *str2;
93 }
94 
95 #ifdef STANDALONE
96 
97 #define START_TEST(name) \
98  static void func_##name(void); \
99  const struct test winetest_testlist[] = { { #name, func_##name }, { 0, 0 } }; \
100  static void func_##name(void)
101 
102 #else /* STANDALONE */
103 
104 #ifdef __cplusplus
105 #define START_TEST(name) extern "C" void func_##name(void)
106 #else
107 #define START_TEST(name) void func_##name(void)
108 #endif
109 
110 #endif /* STANDALONE */
111 
112 #if defined(__x86_64__) && defined(__GNUC__) && defined(__WINE_USE_MSVCRT)
113 #define __winetest_cdecl __cdecl
114 #define __winetest_va_list __builtin_ms_va_list
115 #else
116 #define __winetest_cdecl
117 #define __winetest_va_list va_list
118 #endif
119 
120 extern int broken( int condition );
121 extern int winetest_vok( int condition, const char *msg, __winetest_va_list ap );
122 extern void winetest_vskip( const char *msg, __winetest_va_list ap );
123 
124 #ifdef __GNUC__
125 # define WINETEST_PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
126 extern void __winetest_cdecl winetest_ok( int condition, const char *msg, ... ) __attribute__((format (printf,2,3) ));
127 extern void __winetest_cdecl winetest_skip( const char *msg, ... ) __attribute__((format (printf,1,2)));
128 extern void __winetest_cdecl winetest_win_skip( const char *msg, ... ) __attribute__((format (printf,1,2)));
129 extern void __winetest_cdecl winetest_trace( const char *msg, ... ) __attribute__((format (printf,1,2)));
130 extern void __winetest_cdecl winetest_print(const char* msg, ...) __attribute__((format(printf, 1, 2)));
131 
132 #else /* __GNUC__ */
133 # define WINETEST_PRINTF_ATTR(fmt,args)
134 extern void __winetest_cdecl winetest_ok( int condition, const char *msg, ... );
135 extern void __winetest_cdecl winetest_skip( const char *msg, ... );
136 extern void __winetest_cdecl winetest_win_skip( const char *msg, ... );
137 extern void __winetest_cdecl winetest_trace( const char *msg, ... );
138 extern void __winetest_cdecl winetest_print(const char* msg, ...);
139 
140 #endif /* __GNUC__ */
141 
142 #define ok_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_ok
143 #define skip_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_skip
144 #define win_skip_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_win_skip
145 #define trace_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_trace
146 
147 #define ok ok_(__FILE__, __LINE__)
148 #define skip skip_(__FILE__, __LINE__)
149 #define win_skip win_skip_(__FILE__, __LINE__)
150 #define trace trace_(__FILE__, __LINE__)
151 
152 #define todo_if(is_todo) for (winetest_start_todo(is_todo); \
153  winetest_loop_todo(); \
154  winetest_end_todo())
155 
156 #define todo_ros todo_if(!strcmp(winetest_platform, "reactos"))
157 #define todo_ros_if(is_todo) todo_if((is_todo) && !strcmp(winetest_platform, "reactos"))
158 #ifdef USE_WINE_TODOS
159 #define todo_wine todo_ros
160 #define todo_wine_if todo_ros_if
161 #else
162 #define todo_wine todo_if(!strcmp(winetest_platform, "wine"))
163 #define todo_wine_if(is_todo) todo_if((is_todo) && !strcmp(winetest_platform, "wine"))
164 #endif
165 
166 #define ros_skip_flaky for (winetest_start_nocount(3); \
167  winetest_loop_nocount(); \
168  winetest_end_nocount())
169 
170 #define disable_success_count for (winetest_start_nocount(1); \
171  winetest_loop_nocount(); \
172  winetest_end_nocount())
173 
174 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
175 
176 #ifdef NONAMELESSUNION
177 # define U(x) (x).u
178 # define U1(x) (x).u1
179 # define U2(x) (x).u2
180 # define U3(x) (x).u3
181 # define U4(x) (x).u4
182 # define U5(x) (x).u5
183 # define U6(x) (x).u6
184 # define U7(x) (x).u7
185 # define U8(x) (x).u8
186 #else
187 # define U(x) (x)
188 # define U1(x) (x)
189 # define U2(x) (x)
190 # define U3(x) (x)
191 # define U4(x) (x)
192 # define U5(x) (x)
193 # define U6(x) (x)
194 # define U7(x) (x)
195 # define U8(x) (x)
196 #endif
197 
198 #ifdef NONAMELESSSTRUCT
199 # define S(x) (x).s
200 # define S1(x) (x).s1
201 # define S2(x) (x).s2
202 # define S3(x) (x).s3
203 # define S4(x) (x).s4
204 # define S5(x) (x).s5
205 #else
206 # define S(x) (x)
207 # define S1(x) (x)
208 # define S2(x) (x)
209 # define S3(x) (x)
210 # define S4(x) (x)
211 # define S5(x) (x)
212 #endif
213 
214 
215 /************************************************************************/
216 /* Below is the implementation of the various functions, to be included
217  * directly into the generated testlist.c file.
218  * It is done that way so that the dlls can build the test routines with
219  * different includes or flags if needed.
220  */
221 
222 #ifdef STANDALONE
223 
224 #include <stdio.h>
225 
226 #if defined(__x86_64__) && defined(__GNUC__) && defined(__WINE_USE_MSVCRT)
227 # define __winetest_va_start(list,arg) __builtin_ms_va_start(list,arg)
228 # define __winetest_va_end(list) __builtin_ms_va_end(list)
229 #else
230 # define __winetest_va_start(list,arg) va_start(list,arg)
231 # define __winetest_va_end(list) va_end(list)
232 #endif
233 
234 /* Define WINETEST_MSVC_IDE_FORMATTING to alter the output format winetest will use for file/line numbers.
235  This alternate format makes the file/line numbers clickable in visual studio, to directly jump to them. */
236 #if defined(WINETEST_MSVC_IDE_FORMATTING)
237 # define __winetest_file_line_prefix "%s(%d)"
238 #else
239 # define __winetest_file_line_prefix "%s:%d"
240 #endif
241 
242 struct test
243 {
244  const char *name;
245  void (*func)(void);
246 };
247 
248 extern const struct test winetest_testlist[];
249 
250 /* debug level */
251 int winetest_debug = 1;
252 
253 /* interactive mode? */
254 int winetest_interactive = 0;
255 
256 /* current platform */
257 const char *winetest_platform = "windows";
258 
259 /* report successful tests (BOOL) */
260 int report_success = 0;
261 
262 /* passing arguments around */
263 static int winetest_argc;
264 static char** winetest_argv;
265 
266 static const struct test *current_test; /* test currently being run */
267 
268 static LONG successes; /* number of successful tests */
269 static LONG failures; /* number of failures */
270 static LONG skipped; /* number of skipped test chunks */
271 static LONG todo_successes; /* number of successful tests inside todo block */
272 static LONG todo_failures; /* number of failures inside todo block */
273 
274 /* The following data must be kept track of on a per-thread basis */
275 typedef struct
276 {
277  const char* current_file; /* file of current check */
278  int current_line; /* line of current check */
279  unsigned int todo_level; /* current todo nesting level */
280  unsigned int nocount_level;
281  int todo_do_loop;
282  char *str_pos; /* position in debug buffer */
283  char strings[2000]; /* buffer for debug strings */
284 } tls_data;
285 static DWORD tls_index;
286 
287 static tls_data* get_tls_data(void)
288 {
289  tls_data* data;
291 
293  data=(tls_data*)TlsGetValue(tls_index);
294  if (!data)
295  {
296  data=(tls_data*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(tls_data));
297  data->str_pos = data->strings;
299  }
301  return data;
302 }
303 
304 /* allocate some tmp space for a string */
305 static char *get_temp_buffer( size_t n )
306 {
307  tls_data *data = get_tls_data();
308  char *res = data->str_pos;
309 
310  if (res + n >= &data->strings[sizeof(data->strings)]) res = data->strings;
311  data->str_pos = res + n;
312  return res;
313 }
314 
315 /* release extra space that we requested in gimme1() */
316 static void release_temp_buffer( char *ptr, size_t size )
317 {
318  tls_data *data = get_tls_data();
319  data->str_pos = ptr + size;
320 }
321 
322 static void exit_process( int code )
323 {
324  fflush( stdout );
325  ExitProcess( code );
326 }
327 
328 
329 void winetest_set_location( const char* file, int line )
330 {
331  tls_data* data=get_tls_data();
332 #if defined(WINETEST_MSVC_IDE_FORMATTING)
333  data->current_file = file;
334 #else
335  data->current_file=strrchr(file,'/');
336  if (data->current_file==NULL)
337  data->current_file=strrchr(file,'\\');
338  if (data->current_file==NULL)
339  data->current_file=file;
340  else
341  data->current_file++;
342 #endif
343  data->current_line=line;
344 }
345 
346 int broken( int condition )
347 {
348  return ((strcmp(winetest_platform, "windows") == 0)
349 #ifndef USE_WINE_TODOS
350  || (strcmp(winetest_platform, "reactos") == 0)
351 #endif
352  ) && condition;
353 }
354 
355 /*
356  * Checks condition.
357  * Parameters:
358  * - condition - condition to check;
359  * - msg test description;
360  * - file - test application source code file name of the check
361  * - line - test application source code file line number of the check
362  * Return:
363  * 0 if condition does not have the expected value, 1 otherwise
364  */
365 int winetest_vok( int condition, const char *msg, __winetest_va_list args )
366 {
367  tls_data* data=get_tls_data();
368 
369  if (data->todo_level)
370  {
371  if (condition)
372  {
373  fprintf( stdout, __winetest_file_line_prefix ": Test succeeded inside todo block: ",
374  data->current_file, data->current_line );
375  vfprintf(stdout, msg, args);
376  if ((data->nocount_level & 2) == 0)
377  InterlockedIncrement(&todo_failures);
378  return 0;
379  }
380  else
381  {
382  /* show todos even if traces are disabled*/
383  /*if (winetest_debug > 0)*/
384  {
385  fprintf( stdout, __winetest_file_line_prefix ": Test marked todo: ",
386  data->current_file, data->current_line );
387  vfprintf(stdout, msg, args);
388  }
389  if ((data->nocount_level & 1) == 0)
390  InterlockedIncrement(&todo_successes);
391  return 1;
392  }
393  }
394  else
395  {
396  if (!condition)
397  {
398  fprintf( stdout, __winetest_file_line_prefix ": Test failed: ",
399  data->current_file, data->current_line );
400  vfprintf(stdout, msg, args);
401  if ((data->nocount_level & 2) == 0)
402  InterlockedIncrement(&failures);
403  return 0;
404  }
405  else
406  {
407  if (report_success && (data->nocount_level & 1) == 0)
408  fprintf( stdout, __winetest_file_line_prefix ": Test succeeded\n",
409  data->current_file, data->current_line);
410  if ((data->nocount_level & 1) == 0)
411  InterlockedIncrement(&successes);
412  return 1;
413  }
414  }
415 }
416 
417 void __winetest_cdecl winetest_ok( int condition, const char *msg, ... )
418 {
420 
421  __winetest_va_start(valist, msg);
423  __winetest_va_end(valist);
424 }
425 
426 void __winetest_cdecl winetest_trace( const char *msg, ... )
427 {
429  tls_data* data=get_tls_data();
430 
431  if (winetest_debug > 0)
432  {
433  fprintf( stdout, __winetest_file_line_prefix ": ", data->current_file, data->current_line );
434  __winetest_va_start(valist, msg);
436  __winetest_va_end(valist);
437  }
438 }
439 
440 void __winetest_cdecl winetest_print(const char* msg, ...)
441 {
443  tls_data* data = get_tls_data();
444 
445  fprintf(stdout, __winetest_file_line_prefix ": ", data->current_file, data->current_line);
446  __winetest_va_start(valist, msg);
448  __winetest_va_end(valist);
449 }
450 
451 void winetest_vskip( const char *msg, __winetest_va_list args )
452 {
453  tls_data* data=get_tls_data();
454 
455  fprintf( stdout, __winetest_file_line_prefix ": Tests skipped: ", data->current_file, data->current_line );
456  vfprintf(stdout, msg, args);
457  skipped++;
458 }
459 
460 void __winetest_cdecl winetest_skip( const char *msg, ... )
461 {
463  __winetest_va_start(valist, msg);
465  __winetest_va_end(valist);
466 }
467 
468 void __winetest_cdecl winetest_win_skip( const char *msg, ... )
469 {
471  __winetest_va_start(valist, msg);
472  if ((strcmp(winetest_platform, "windows") == 0)
473 #ifndef USE_WINE_TODOS
474  || (strcmp(winetest_platform, "reactos") == 0)
475 #endif
476  )
478  else
479  winetest_vok(0, msg, valist);
480  __winetest_va_end(valist);
481 }
482 
483 void winetest_start_todo( int is_todo )
484 {
485  tls_data* data=get_tls_data();
486  data->todo_level = (data->todo_level << 1) | (is_todo != 0);
487  data->todo_do_loop=1;
488 }
489 
490 int winetest_loop_todo(void)
491 {
492  tls_data* data=get_tls_data();
493  int do_loop=data->todo_do_loop;
494  data->todo_do_loop=0;
495  return do_loop;
496 }
497 
498 void winetest_end_todo(void)
499 {
500  tls_data* data=get_tls_data();
501  data->todo_level >>= 1;
502 }
503 
504 void winetest_start_nocount(unsigned int flags)
505 {
506  tls_data* data = get_tls_data();
507 
508  /* The lowest 2 bits of nocount_level specify whether counting of successes
509  and/or failures is disabled. For each nested level the bits are shifted
510  left, the new lowest 2 bits are copied from the previous state and ored
511  with the new mask. This allows nested handling of both states up tp a
512  level of 16. */
513  flags |= data->nocount_level & 3;
514  data->nocount_level = (data->nocount_level << 2) | flags;
515  data->todo_do_loop = 1;
516 }
517 
518 int winetest_loop_nocount(void)
519 {
520  tls_data* data = get_tls_data();
521  int do_loop = data->todo_do_loop;
522  data->todo_do_loop = 0;
523  return do_loop;
524 }
525 
526 void winetest_end_nocount(void)
527 {
528  tls_data* data = get_tls_data();
529  data->nocount_level >>= 2;
530 }
531 
532 int winetest_get_mainargs( char*** pargv )
533 {
534  *pargv = winetest_argv;
535  return winetest_argc;
536 }
537 
539 {
540  return failures;
541 }
542 
544 {
545  return successes;
546 }
547 
548 void winetest_add_failures( LONG new_failures )
549 {
550  while (new_failures-- > 0)
551  InterlockedIncrement( &failures );
552 }
553 
555 {
556  DWORD exit_code = 1;
557 
558  if (WaitForSingleObject( process, 30000 ))
559  fprintf( stdout, "%s: child process wait failed\n", current_test->name );
560  else
562 
563  if (exit_code)
564  {
565  if (exit_code > 255)
566  {
567  fprintf( stdout, "%s: exception 0x%08x in child process\n", current_test->name, (unsigned)exit_code );
568  InterlockedIncrement( &failures );
569  }
570  else
571  {
572  fprintf( stdout, "%s: %u failures in child process\n",
573  current_test->name, (unsigned)exit_code );
574  while (exit_code-- > 0)
575  InterlockedIncrement(&failures);
576  }
577  }
578 }
579 
580 const char *wine_dbgstr_wn( const WCHAR *str, intptr_t n )
581 {
582  char *dst, *res;
583  size_t size;
584 
585  if (!((ULONG_PTR)str >> 16))
586  {
587  if (!str) return "(null)";
588  res = get_temp_buffer( 6 );
589  sprintf( res, "#%04x", LOWORD(str) );
590  return res;
591  }
592  if (n == -1)
593  {
594  const WCHAR *end = str;
595  while (*end) end++;
596  n = end - str;
597  }
598  if (n < 0) n = 0;
599  size = 12 + min( 300, n * 5 );
600  dst = res = get_temp_buffer( size );
601  *dst++ = 'L';
602  *dst++ = '"';
603  while (n-- > 0 && dst <= res + size - 10)
604  {
605  WCHAR c = *str++;
606  switch (c)
607  {
608  case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
609  case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
610  case '\t': *dst++ = '\\'; *dst++ = 't'; break;
611  case '"': *dst++ = '\\'; *dst++ = '"'; break;
612  case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
613  default:
614  if (c >= ' ' && c <= 126)
615  *dst++ = (char)c;
616  else
617  {
618  *dst++ = '\\';
619  sprintf(dst,"%04x",c);
620  dst+=4;
621  }
622  }
623  }
624  *dst++ = '"';
625  if (n > 0)
626  {
627  *dst++ = '.';
628  *dst++ = '.';
629  *dst++ = '.';
630  }
631  *dst++ = 0;
633  return res;
634 }
635 
636 const char *wine_dbgstr_guid( const GUID *guid )
637 {
638  char *res;
639 
640  if (!guid) return "(null)";
641  res = get_temp_buffer( 39 ); /* CHARS_IN_GUID */
642  sprintf( res, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
643  guid->Data1, guid->Data2, guid->Data3, guid->Data4[0],
644  guid->Data4[1], guid->Data4[2], guid->Data4[3], guid->Data4[4],
645  guid->Data4[5], guid->Data4[6], guid->Data4[7] );
646  return res;
647 }
648 
649 const char *wine_dbgstr_point( const POINT *point )
650 {
651  char *res;
652 
653  if (!point) return "(null)";
654  res = get_temp_buffer( 60 );
655 #ifdef __ROS_LONG64__
656  sprintf( res, "(%d,%d)", point->x, point->y );
657 #else
658  sprintf( res, "(%ld,%ld)", point->x, point->y );
659 #endif
661  return res;
662 }
663 
664 const char *wine_dbgstr_size( const SIZE *size )
665 {
666  char *res;
667 
668  if (!size) return "(null)";
669  res = get_temp_buffer( 60 );
670 #ifdef __ROS_LONG64__
671  sprintf( res, "(%d,%d)", size->cx, size->cy );
672 #else
673  sprintf( res, "(%ld,%ld)", size->cx, size->cy );
674 #endif
676  return res;
677 }
678 
679 const char *wine_dbgstr_rect( const RECT *rect )
680 {
681  char *res;
682 
683  if (!rect) return "(null)";
684  res = get_temp_buffer( 60 );
685 #ifdef __ROS_LONG64__
686  sprintf( res, "(%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
687 #else
688  sprintf( res, "(%ld,%ld)-(%ld,%ld)", rect->left, rect->top, rect->right, rect->bottom );
689 #endif
691  return res;
692 }
693 
694 #ifdef WINETEST_USE_DBGSTR_LONGLONG
695 const char *wine_dbgstr_longlong( ULONGLONG ll )
696 {
697  char *res;
698 
699  res = get_temp_buffer( 20 );
700  if (/*sizeof(ll) > sizeof(unsigned long) &&*/ ll >> 32) /* ULONGLONG is always > long in ReactOS */
701  sprintf( res, "%lx%08lx", (unsigned long)(ll >> 32), (unsigned long)ll );
702  else
703  sprintf( res, "%lx", (unsigned long)ll );
705  return res;
706 }
707 #endif
708 
709 /* Find a test by name */
710 static const struct test *find_test( const char *name )
711 {
712  const struct test *test;
713  const char *p;
714  size_t len;
715 
716  if ((p = strrchr( name, '/' ))) name = p + 1;
717  if ((p = strrchr( name, '\\' ))) name = p + 1;
718  len = strlen(name);
719  if (len > 2 && !strcmp( name + len - 2, ".c" )) len -= 2;
720 
721  for (test = winetest_testlist; test->name; test++)
722  {
723  if (!strncmp( test->name, name, len ) && !test->name[len]) break;
724  }
725  return test->name ? test : NULL;
726 }
727 
728 
729 /* Display list of valid tests */
730 static void list_tests(void)
731 {
732  const struct test *test;
733 
734  fprintf( stdout, "Valid test names:\n" );
735  for (test = winetest_testlist; test->name; test++) fprintf( stdout, " %s\n", test->name );
736 }
737 
738 /* Disable false-positive claiming "test" would be NULL-dereferenced */
739 #if defined(_MSC_VER)
740 #pragma warning(push)
741 #pragma warning(disable:28182)
742 #endif
743 
744 /* Run a named test, and return exit status */
745 static int run_test( const char *name )
746 {
747  const struct test *test;
748  int status;
749 
750  if (!(test = find_test( name )))
751  {
752  fprintf( stdout, "Fatal: test '%s' does not exist.\n", name );
753  exit_process(1);
754  }
755  successes = failures = todo_successes = todo_failures = 0;
757  current_test = test;
758  test->func();
759 
760  /* show test results even if traces are disabled */
761  /*if (winetest_debug)*/
762  {
763  fprintf( stdout, "\n%s: %d tests executed (%d marked as todo, %d %s), %d skipped.\n",
764  test->name, (int)(successes + failures + todo_successes + todo_failures),
765  (int)todo_successes, (int)(failures + todo_failures),
766  (failures + todo_failures != 1) ? "failures" : "failure",
767  (int)skipped );
768  }
769  status = (failures + todo_failures < 255) ? failures + todo_failures : 255;
770  return status;
771 }
772 
773 #if defined(_MSC_VER)
774 #pragma warning(pop)
775 #endif
776 
777 /* Display usage and exit */
778 static void usage( const char *argv0 )
779 {
780  fprintf( stdout, "Usage: %s test_name\n\n", argv0 );
781  list_tests();
782  exit_process(1);
783 }
784 
785 
786 /* main function */
787 int main( int argc, char **argv )
788 {
789  char p[128];
790 
791  setvbuf (stdout, NULL, _IONBF, 0);
792 
793  winetest_argc = argc;
794  winetest_argv = argv;
795 
796  if (GetEnvironmentVariableA( "WINETEST_PLATFORM", p, sizeof(p) )) winetest_platform = _strdup(p);
797  if (GetEnvironmentVariableA( "WINETEST_DEBUG", p, sizeof(p) )) winetest_debug = atoi(p);
798  if (GetEnvironmentVariableA( "WINETEST_INTERACTIVE", p, sizeof(p) )) winetest_interactive = atoi(p);
799  if (GetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", p, sizeof(p) )) report_success = atoi(p);
800 
802 
803  if (!argv[1])
804  {
805  if (winetest_testlist[0].name && !winetest_testlist[1].name) /* only one test */
806  return run_test( winetest_testlist[0].name );
807  usage( argv[0] );
808  }
809  if (!strcmp( argv[1], "--list" ))
810  {
811  list_tests();
812  return 0;
813  }
814  return run_test(argv[1]);
815 }
816 
817 #endif /* STANDALONE */
818 
819 // hack for ntdll winetest (this is defined in excpt.h)
820 #undef exception_info
821 
822 // Some helpful definitions
823 
824 #define ok_hex(expression, result) \
825  do { \
826  int _value = (expression); \
827  ok(_value == (result), "Wrong value for '%s', expected: " #result " (0x%x), got: 0x%x\n", \
828  #expression, (int)(result), _value); \
829  } while (0)
830 
831 #define ok_dec(expression, result) \
832  do { \
833  int _value = (expression); \
834  ok(_value == (result), "Wrong value for '%s', expected: " #result " (%d), got: %d\n", \
835  #expression, (int)(result), _value); \
836  } while (0)
837 
838 #define ok_ptr(expression, result) \
839  do { \
840  void *_value = (expression); \
841  ok(_value == (result), "Wrong value for '%s', expected: " #result " (%p), got: %p\n", \
842  #expression, (void*)(result), _value); \
843  } while (0)
844 
845 #define ok_size_t(expression, result) \
846  do { \
847  size_t _value = (expression); \
848  ok(_value == (result), "Wrong value for '%s', expected: " #result " (%Ix), got: %Ix\n", \
849  #expression, (size_t)(result), _value); \
850  } while (0)
851 
852 #define ok_char(expression, result) ok_hex(expression, result)
853 
854 #define ok_err(error) \
855  ok(GetLastError() == (error), "Wrong last error. Expected " #error ", got 0x%lx\n", GetLastError())
856 
857 #define ok_str(x, y) \
858  ok(strcmp(x, y) == 0, "Wrong string. Expected '%s', got '%s'\n", y, x)
859 
860 #define ok_wstr(x, y) \
861  ok(wcscmp(x, y) == 0, "Wrong string. Expected '%S', got '%S'\n", y, x)
862 
863 #define ok_long(expression, result) ok_hex(expression, result)
864 #define ok_int(expression, result) ok_dec(expression, result)
865 #define ok_ntstatus(status, expected) ok_hex(status, expected)
866 #define ok_hdl ok_ptr
867 
868 #ifdef __cplusplus
869 } /* extern "C" */
870 #endif
871 
872 #endif /* __WINE_WINE_TEST_H */
GLenum func
Definition: glext.h:6028
UINT WINAPI SetErrorMode(IN UINT uMode)
Definition: except.c:753
static int argc
Definition: ServiceArgs.c:12
LONG winetest_get_failures(void)
void winetest_add_failures(LONG new_failures)
int winetest_vok(int condition, const char *msg, __winetest_va_list ap)
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define SEM_FAILCRITICALERRORS
Definition: rtltypes.h:69
void __winetest_cdecl winetest_print(const char *msg,...)
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
BOOL WINAPI TlsSetValue(IN DWORD Index, IN LPVOID Value)
Definition: thread.c:1264
BOOL WINAPI GetExitCodeProcess(IN HANDLE hProcess, IN LPDWORD lpExitCode)
Definition: proc.c:1168
int main(int argc, char *argv[])
Definition: atactl.cpp:1685
GLdouble n
Definition: glext.h:7729
static char * get_temp_buffer(int size)
Definition: registry.c:62
const char * wine_dbgstr_guid(const GUID *guid)
VOID WINAPI ExitProcess(IN UINT uExitCode)
Definition: proc.c:1487
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define test
Definition: rosglue.h:37
GLuint GLuint end
Definition: gl.h:1545
int winetest_interactive
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
#define argv
Definition: mplay32.c:18
#define _strdup
Definition: debug_ros.c:7
Definition: match.c:390
#define __winetest_va_list
Definition: test.h:117
int winetest_debug
POINTL point
Definition: edittest.c:50
& rect
Definition: startmenu.cpp:1413
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
FILE * stdout
LONG y
Definition: windef.h:330
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define sprintf(buf, format,...)
Definition: sprintf.c:55
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
int report_success
const GUID * guid
long LONG
Definition: pedump.c:60
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
int winetest_loop_todo(void)
static PVOID ptr
Definition: dispmode.c:27
void winetest_start_todo(int is_todo)
const struct test winetest_testlist[]
Definition: testlist.c:24
GLenum condition
Definition: glext.h:9255
const WCHAR * str
void winetest_end_todo(void)
smooth NULL
Definition: ftsmooth.c:416
unsigned char
Definition: typeof.h:29
void winetest_vskip(const char *msg, __winetest_va_list ap)
static int winetest_strcmpW(const WCHAR *str1, const WCHAR *str2)
Definition: test.h:89
#define run_test(info, expect_button, expect_radio_button, verification_checked, seq, context)
Definition: taskdialog.c:395
Definition: parser.c:48
TCHAR str_pos[MAX_LOADSTRING]
Definition: sndrec32.cpp:58
const char * winetest_platform
static UINT exit_code
Definition: process.c:78
void __winetest_cdecl winetest_trace(const char *msg,...)
#define __winetest_cdecl
Definition: test.h:116
const char * wine_dbgstr_point(const POINT *guid)
int winetest_loop_nocount(void)
GLsizeiptr size
Definition: glext.h:5919
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define GetEnvironmentVariableA(x, y, z)
Definition: compat.h:419
static const char * wine_dbgstr_w(const WCHAR *s)
Definition: test.h:85
int intptr_t
Definition: crtdefs.h:283
__wchar_t WCHAR
Definition: xmlstorage.h:180
void __winetest_cdecl winetest_ok(int condition, const char *msg,...)
uint64_t ULONGLONG
Definition: typedefs.h:65
const char file[]
Definition: icontest.c:11
const GLubyte * c
Definition: glext.h:8905
const char * wine_dbgstr_rect(const RECT *rect)
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
char * name
Definition: compiler.c:66
unsigned long DWORD
Definition: ntddk_ex.h:95
LONG x
Definition: windef.h:329
#define SetLastError(x)
Definition: compat.h:417
void winetest_end_nocount(void)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
int winetest_get_mainargs(char ***pargv)
GLbitfield flags
Definition: glext.h:7161
GLsizei const GLchar *const * strings
Definition: glext.h:7622
char line[200]
Definition: main.c:97
GLsizeiptr const GLvoid GLenum usage
Definition: glext.h:5919
GLenum GLsizei len
Definition: glext.h:6722
static char argv0[MAX_PATH]
Definition: shlexec.c:56
GLdouble s
Definition: gl.h:2039
DWORD WINAPI TlsAlloc(VOID)
Definition: thread.c:1088
static INT do_loop(const PropSheetInfo *psInfo)
Definition: propsheet.c:2790
#define SEM_NOGPFAULTERRORBOX
Definition: rtltypes.h:70
static void release_temp_buffer(char *buffer, size_t size)
Definition: debug.c:350
void winetest_wait_child_process(HANDLE process)
#define InterlockedIncrement
Definition: armddk.h:53
_Check_return_opt_ _CRTIMP int __cdecl fflush(_Inout_opt_ FILE *_File)
GLenum GLenum dst
Definition: glext.h:6340
const char * wine_dbgstr_size(const SIZE *guid)
w ll
Definition: byte_order.h:166
#define min(a, b)
Definition: monoChain.cc:55
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
LPVOID WINAPI TlsGetValue(IN DWORD Index)
Definition: thread.c:1228
#define msg(x)
Definition: auth_time.c:54
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
LONG winetest_get_successes(void)
Definition: name.c:38
void int int ULONGLONG int va_list * ap
Definition: winesup.h:32
GLuint res
Definition: glext.h:9613
void __winetest_cdecl winetest_skip(const char *msg,...)
#define const
Definition: zconf.h:230
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:41
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
void __winetest_cdecl winetest_win_skip(const char *msg,...)
_Check_return_opt_ _CRTIMP int __cdecl setvbuf(_Inout_ FILE *_File, _Inout_updates_opt_z_(_Size) char *_Buf, _In_ int _Mode, _In_ size_t _Size)
static __ms_va_list valist
Definition: printf.c:64
#define _IONBF
Definition: stdio.h:130
const char * wine_dbgstr_wn(const WCHAR *str, intptr_t n)
Definition: compat.c:342
int broken(int condition)
GLfloat GLfloat p
Definition: glext.h:8902
tls_data_t * get_tls_data(void)
Definition: urlmon_main.c:62
_Check_return_opt_ _CRTIMP int __cdecl vfprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format, va_list _ArgList)
static SERVICE_STATUS status
Definition: service.c:31
#define LOWORD(l)
Definition: pedump.c:82
DWORD tls_index
void winetest_start_nocount(unsigned int flags)
#define printf
Definition: config.h:203
void winetest_set_location(const char *file, int line)
Definition: fci.c:126
Definition: ps.c:97
GLuint const GLchar * name
Definition: glext.h:6031