ReactOS 0.4.15-dev-7788-g1ad9096
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
43extern "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 */
54extern int winetest_debug;
55
56extern int report_success;
57
58/* running in interactive mode? */
59extern int winetest_interactive;
60
61/* current platform */
62extern const char *winetest_platform;
63
64extern void winetest_set_location( const char* file, int line );
65extern void winetest_subtest(const char* name);
66extern void winetest_start_todo( int is_todo );
67extern int winetest_loop_todo(void);
68extern void winetest_end_todo(void);
69extern void winetest_start_nocount(unsigned int flags);
70extern int winetest_loop_nocount(void);
71extern void winetest_end_nocount(void);
72extern int winetest_get_mainargs( char*** pargv );
75extern void winetest_add_failures( LONG new_failures );
77
78extern const char *wine_dbgstr_wn( const WCHAR *str, intptr_t n );
79extern const char *wine_dbgstr_an( const CHAR *str, intptr_t n );
80extern const char *wine_dbgstr_guid( const GUID *guid );
81extern const char *wine_dbgstr_point( const POINT *guid );
82extern const char *wine_dbgstr_size( const SIZE *guid );
83extern const char *wine_dbgstr_rect( const RECT *rect );
84#ifdef WINETEST_USE_DBGSTR_LONGLONG
85extern const char *wine_dbgstr_longlong( ULONGLONG ll );
86#endif
87static inline const char *debugstr_a( const char *s ) { return wine_dbgstr_an( s, -1 ); }
88static inline const char *debugstr_an( const CHAR *s, intptr_t n ) { return wine_dbgstr_an( s, n ); }
89static inline const char *wine_dbgstr_a( const char *s ) { return wine_dbgstr_an( s, -1 ); }
90static 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. */
94static 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
125extern int broken( int condition );
126extern int winetest_vok( int condition, const char *msg, __winetest_va_list ap );
127extern 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)))
131extern void __winetest_cdecl winetest_ok( int condition, const char *msg, ... ) __attribute__((format (printf,2,3) ));
132extern void __winetest_cdecl winetest_skip( const char *msg, ... ) __attribute__((format (printf,1,2)));
133extern void __winetest_cdecl winetest_win_skip( const char *msg, ... ) __attribute__((format (printf,1,2)));
134extern void __winetest_cdecl winetest_trace( const char *msg, ... ) __attribute__((format (printf,1,2)));
135extern void __winetest_cdecl winetest_print(const char* msg, ...) __attribute__((format(printf, 1, 2)));
136extern void __winetest_cdecl winetest_push_context( const char *fmt, ... ) __attribute__((format(printf, 1, 2)));
137extern void winetest_pop_context(void);
138
139#else /* __GNUC__ */
140# define WINETEST_PRINTF_ATTR(fmt,args)
141extern void __winetest_cdecl winetest_ok( int condition, const char *msg, ... );
142extern void __winetest_cdecl winetest_skip( const char *msg, ... );
143extern void __winetest_cdecl winetest_win_skip( const char *msg, ... );
144extern void __winetest_cdecl winetest_trace( const char *msg, ... );
145extern void __winetest_cdecl winetest_print(const char* msg, ...);
146extern void __winetest_cdecl winetest_push_context( const char *fmt, ... );
147extern 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
253struct test
254{
255 const char *name;
256 void (*func)(void);
257};
258
259extern const struct test winetest_testlist[];
260
261/* debug level */
262int winetest_debug = 1;
263
264/* interactive mode? */
266
267/* current platform */
268const char *winetest_platform = "windows";
269
270/* report successful tests (BOOL) */
271int report_success = 0;
272
273/* passing arguments around */
274static int winetest_argc;
275static char** winetest_argv;
276
277static const struct test *current_test; /* test currently being run */
278
279static LONG successes; /* number of successful tests */
280static LONG failures; /* number of failures */
281static LONG skipped; /* number of skipped test chunks */
282static LONG todo_successes; /* number of successful tests inside todo block */
283static LONG todo_failures; /* number of failures inside todo block */
284
285/* The following data must be kept track of on a per-thread basis */
286typedef 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;
298static DWORD tls_index;
299
300static 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 */
318static 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() */
329static 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
335static void exit_process( int code )
336{
337 fflush( stdout );
338 ExitProcess( code );
339}
340
341
342void 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__
360static void __winetest_cdecl winetest_printf( const char *msg, ... ) __attribute__((format(printf,1,2)));
361#else
362static void __winetest_cdecl winetest_printf(const char* msg, ...);
363#endif
364static 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 );
372 __winetest_va_end( valist );
373}
374
375static 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
385void 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
392int 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 */
411int 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: " );
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: " );
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: " );
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
461void __winetest_cdecl winetest_ok( int condition, const char *msg, ... )
462{
464
465 __winetest_va_start(valist, msg);
467 __winetest_va_end(valist);
468}
469
470void __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
483void __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
494void winetest_vskip( const char *msg, __winetest_va_list args )
495{
496 winetest_print_context( "Tests skipped: " );
498 skipped++;
499}
500
501void __winetest_cdecl winetest_skip( const char *msg, ... )
502{
504 __winetest_va_start(valist, msg);
506 __winetest_va_end(valist);
507}
508
509void __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
521 __winetest_va_end(valist);
522}
523
524void 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
531int 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
539void winetest_end_todo(void)
540{
541 tls_data* data=get_tls_data();
542 data->todo_level >>= 1;
543}
544
545void 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
559int 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
567void winetest_end_nocount(void)
568{
569 tls_data* data = get_tls_data();
570 data->nocount_level >>= 2;
571}
572
573void __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
588void winetest_pop_context(void)
589{
590 tls_data* data = get_tls_data();
591
592 if (data->context_count)
593 --data->context_count;
594}
595
596int 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
612void 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
644const 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 );
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
699const 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
752const 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
765const 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
780const 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
795const 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
811const 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 */
826static 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 */
846static 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 */
861static 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 */
894static 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 */
903int 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 */
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:93
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 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:6
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:185
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:94
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:121
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:89
#define __winetest_va_list
Definition: test.h:122
static const char * debugstr_an(const CHAR *s, intptr_t n)
Definition: test.h:88
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