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