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