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