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