2002-02-20 20:03:59 +01:00
|
|
|
/*
|
|
|
|
* Definitions for Wine C unit tests.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Alexandre Julliard
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-02-20 20:03:59 +01:00
|
|
|
*/
|
|
|
|
|
2006-05-25 20:07:57 +02:00
|
|
|
#ifndef __WINE_WINE_TEST_H
|
|
|
|
#define __WINE_WINE_TEST_H
|
2002-02-20 20:03:59 +01:00
|
|
|
|
2005-06-30 23:13:00 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <windef.h>
|
|
|
|
#include <winbase.h>
|
2002-03-22 01:58:00 +01:00
|
|
|
|
2008-07-08 21:29:28 +02:00
|
|
|
#ifdef __WINE_CONFIG_H
|
|
|
|
#error config.h should not be used in Wine tests
|
|
|
|
#endif
|
2006-05-25 20:07:57 +02:00
|
|
|
#ifdef __WINE_WINE_LIBRARY_H
|
|
|
|
#error wine/library.h should not be used in Wine tests
|
|
|
|
#endif
|
|
|
|
#ifdef __WINE_WINE_UNICODE_H
|
|
|
|
#error wine/unicode.h should not be used in Wine tests
|
|
|
|
#endif
|
|
|
|
#ifdef __WINE_WINE_DEBUG_H
|
|
|
|
#error wine/debug.h should not be used in Wine tests
|
|
|
|
#endif
|
|
|
|
|
2006-09-13 11:01:39 +02:00
|
|
|
#ifndef INVALID_FILE_ATTRIBUTES
|
2008-12-08 15:51:22 +01:00
|
|
|
#define INVALID_FILE_ATTRIBUTES (~0u)
|
2006-09-13 11:01:39 +02:00
|
|
|
#endif
|
|
|
|
#ifndef INVALID_SET_FILE_POINTER
|
2008-12-08 15:51:22 +01:00
|
|
|
#define INVALID_SET_FILE_POINTER (~0u)
|
2006-09-13 11:01:39 +02:00
|
|
|
#endif
|
|
|
|
|
2002-02-20 20:03:59 +01:00
|
|
|
/* debug level */
|
|
|
|
extern int winetest_debug;
|
|
|
|
|
2003-01-02 18:52:05 +01:00
|
|
|
/* running in interactive mode? */
|
|
|
|
extern int winetest_interactive;
|
|
|
|
|
2018-05-02 01:38:03 +02:00
|
|
|
/* report successful tests (BOOL) */
|
|
|
|
extern int winetest_report_success;
|
|
|
|
|
2002-02-20 20:03:59 +01:00
|
|
|
/* current platform */
|
|
|
|
extern const char *winetest_platform;
|
|
|
|
|
2002-12-11 01:17:42 +01:00
|
|
|
extern void winetest_set_location( const char* file, int line );
|
2016-02-09 10:40:01 +01:00
|
|
|
extern void winetest_start_todo( int is_todo );
|
2002-03-22 01:58:00 +01:00
|
|
|
extern int winetest_loop_todo(void);
|
2016-02-09 10:40:01 +01:00
|
|
|
extern void winetest_end_todo(void);
|
2002-04-20 22:51:11 +02:00
|
|
|
extern int winetest_get_mainargs( char*** pargv );
|
2013-04-12 11:00:58 +02:00
|
|
|
extern LONG winetest_get_failures(void);
|
2013-04-18 10:44:43 +02:00
|
|
|
extern void winetest_add_failures( LONG new_failures );
|
2008-02-07 12:56:00 +01:00
|
|
|
extern void winetest_wait_child_process( HANDLE process );
|
2002-02-20 20:03:59 +01:00
|
|
|
|
2009-08-19 13:19:31 +02:00
|
|
|
extern const char *wine_dbgstr_wn( const WCHAR *str, int n );
|
2014-01-25 15:24:22 +01:00
|
|
|
extern const char *wine_dbgstr_guid( const GUID *guid );
|
2016-06-07 09:45:40 +02:00
|
|
|
extern const char *wine_dbgstr_rect( const RECT *rect );
|
2009-08-19 13:19:31 +02:00
|
|
|
static inline const char *wine_dbgstr_w( const WCHAR *s ) { return wine_dbgstr_wn( s, -1 ); }
|
2017-06-30 01:08:09 +02:00
|
|
|
extern const char *wine_dbgstr_longlong( ULONGLONG ll );
|
2009-08-19 13:19:31 +02:00
|
|
|
|
2011-07-28 01:09:36 +02:00
|
|
|
/* strcmpW is available for tests compiled under Wine, but not in standalone
|
2010-02-20 22:41:31 +01:00
|
|
|
* builds under Windows, so we reimplement it under a different name. */
|
|
|
|
static inline int winetest_strcmpW( const WCHAR *str1, const WCHAR *str2 )
|
|
|
|
{
|
|
|
|
while (*str1 && (*str1 == *str2)) { str1++; str2++; }
|
|
|
|
return *str1 - *str2;
|
|
|
|
}
|
|
|
|
|
2005-05-25 11:57:07 +02:00
|
|
|
#ifdef STANDALONE
|
|
|
|
#define START_TEST(name) \
|
|
|
|
static void func_##name(void); \
|
2005-06-15 12:22:59 +02:00
|
|
|
const struct test winetest_testlist[] = { { #name, func_##name }, { 0, 0 } }; \
|
2005-05-25 11:57:07 +02:00
|
|
|
static void func_##name(void)
|
|
|
|
#else
|
2002-02-20 20:03:59 +01:00
|
|
|
#define START_TEST(name) void func_##name(void)
|
2005-05-25 11:57:07 +02:00
|
|
|
#endif
|
2002-02-20 20:03:59 +01:00
|
|
|
|
2018-05-09 22:34:57 +02:00
|
|
|
#if (defined(__x86_64__) || defined(__aarch64__)) && defined(__GNUC__) && defined(__WINE_USE_MSVCRT)
|
2010-04-09 15:48:05 +02:00
|
|
|
#define __winetest_cdecl __cdecl
|
|
|
|
#define __winetest_va_list __builtin_ms_va_list
|
|
|
|
#else
|
|
|
|
#define __winetest_cdecl
|
|
|
|
#define __winetest_va_list va_list
|
|
|
|
#endif
|
|
|
|
|
2008-05-29 18:30:04 +02:00
|
|
|
extern int broken( int condition );
|
2010-04-09 15:48:05 +02:00
|
|
|
extern int winetest_vok( int condition, const char *msg, __winetest_va_list ap );
|
|
|
|
extern void winetest_vskip( const char *msg, __winetest_va_list ap );
|
2008-05-29 18:30:04 +02:00
|
|
|
|
2002-06-22 02:08:10 +02:00
|
|
|
#ifdef __GNUC__
|
2016-01-13 12:42:54 +01:00
|
|
|
# define WINETEST_PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
|
|
|
|
#else
|
|
|
|
# define WINETEST_PRINTF_ATTR(fmt,args)
|
|
|
|
#endif
|
2002-06-22 02:08:10 +02:00
|
|
|
|
2016-01-13 12:42:54 +01:00
|
|
|
extern void __winetest_cdecl winetest_ok( int condition, const char *msg, ... ) WINETEST_PRINTF_ATTR(2,3);
|
|
|
|
extern void __winetest_cdecl winetest_skip( const char *msg, ... ) WINETEST_PRINTF_ATTR(1,2);
|
|
|
|
extern void __winetest_cdecl winetest_win_skip( const char *msg, ... ) WINETEST_PRINTF_ATTR(1,2);
|
|
|
|
extern void __winetest_cdecl winetest_trace( const char *msg, ... ) WINETEST_PRINTF_ATTR(1,2);
|
2002-03-22 01:58:00 +01:00
|
|
|
|
2018-06-06 20:36:14 +02:00
|
|
|
#ifdef WINETEST_NO_LINE_NUMBERS
|
|
|
|
# define ok_(file, line) (winetest_set_location(file, 0), 0) ? (void)0 : winetest_ok
|
|
|
|
# define skip_(file, line) (winetest_set_location(file, 0), 0) ? (void)0 : winetest_skip
|
|
|
|
# define win_skip_(file, line) (winetest_set_location(file, 0), 0) ? (void)0 : winetest_win_skip
|
|
|
|
# define trace_(file, line) (winetest_set_location(file, 0), 0) ? (void)0 : winetest_trace
|
|
|
|
#else
|
|
|
|
# define ok_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_ok
|
|
|
|
# define skip_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_skip
|
|
|
|
# define win_skip_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_win_skip
|
|
|
|
# define trace_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_trace
|
|
|
|
#endif
|
2002-10-30 00:07:58 +01:00
|
|
|
|
2008-06-10 18:29:46 +02:00
|
|
|
#define ok ok_(__FILE__, __LINE__)
|
|
|
|
#define skip skip_(__FILE__, __LINE__)
|
|
|
|
#define win_skip win_skip_(__FILE__, __LINE__)
|
|
|
|
#define trace trace_(__FILE__, __LINE__)
|
2002-10-30 00:07:58 +01:00
|
|
|
|
2016-02-09 10:40:01 +01:00
|
|
|
#define todo_if(is_todo) for (winetest_start_todo(is_todo); \
|
|
|
|
winetest_loop_todo(); \
|
|
|
|
winetest_end_todo())
|
|
|
|
#define todo_wine todo_if(!strcmp(winetest_platform, "wine"))
|
|
|
|
#define todo_wine_if(is_todo) todo_if((is_todo) && !strcmp(winetest_platform, "wine"))
|
2002-02-20 20:03:59 +01:00
|
|
|
|
2002-10-30 21:36:21 +01:00
|
|
|
|
2018-07-04 01:10:37 +02:00
|
|
|
#ifndef ARRAY_SIZE
|
|
|
|
# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
|
|
|
#endif
|
2018-05-24 23:46:27 +02:00
|
|
|
|
2005-06-13 14:10:54 +02:00
|
|
|
#ifdef NONAMELESSUNION
|
|
|
|
# define U(x) (x).u
|
|
|
|
# define U1(x) (x).u1
|
|
|
|
# define U2(x) (x).u2
|
|
|
|
# define U3(x) (x).u3
|
|
|
|
# define U4(x) (x).u4
|
|
|
|
# define U5(x) (x).u5
|
|
|
|
# define U6(x) (x).u6
|
|
|
|
# define U7(x) (x).u7
|
|
|
|
# define U8(x) (x).u8
|
|
|
|
#else
|
|
|
|
# define U(x) (x)
|
|
|
|
# define U1(x) (x)
|
|
|
|
# define U2(x) (x)
|
|
|
|
# define U3(x) (x)
|
|
|
|
# define U4(x) (x)
|
|
|
|
# define U5(x) (x)
|
|
|
|
# define U6(x) (x)
|
|
|
|
# define U7(x) (x)
|
|
|
|
# define U8(x) (x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NONAMELESSSTRUCT
|
|
|
|
# define S(x) (x).s
|
|
|
|
# define S1(x) (x).s1
|
|
|
|
# define S2(x) (x).s2
|
|
|
|
# define S3(x) (x).s3
|
|
|
|
# define S4(x) (x).s4
|
|
|
|
# define S5(x) (x).s5
|
|
|
|
#else
|
|
|
|
# define S(x) (x)
|
|
|
|
# define S1(x) (x)
|
|
|
|
# define S2(x) (x)
|
|
|
|
# define S3(x) (x)
|
|
|
|
# define S4(x) (x)
|
|
|
|
# define S5(x) (x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2002-10-30 21:36:21 +01:00
|
|
|
/************************************************************************/
|
|
|
|
/* Below is the implementation of the various functions, to be included
|
|
|
|
* directly into the generated testlist.c file.
|
|
|
|
* It is done that way so that the dlls can build the test routines with
|
|
|
|
* different includes or flags if needed.
|
|
|
|
*/
|
|
|
|
|
2005-05-25 11:57:07 +02:00
|
|
|
#ifdef STANDALONE
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2012-06-21 14:01:29 +02:00
|
|
|
#include <excpt.h>
|
2005-05-25 11:57:07 +02:00
|
|
|
|
2018-05-09 22:34:57 +02:00
|
|
|
#if (defined(__x86_64__) || defined(__aarch64__)) && defined(__GNUC__) && defined(__WINE_USE_MSVCRT)
|
2010-04-09 15:48:05 +02:00
|
|
|
# define __winetest_va_start(list,arg) __builtin_ms_va_start(list,arg)
|
|
|
|
# define __winetest_va_end(list) __builtin_ms_va_end(list)
|
|
|
|
#else
|
|
|
|
# define __winetest_va_start(list,arg) va_start(list,arg)
|
|
|
|
# define __winetest_va_end(list) va_end(list)
|
|
|
|
#endif
|
|
|
|
|
2005-05-25 11:57:07 +02:00
|
|
|
struct test
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
void (*func)(void);
|
|
|
|
};
|
|
|
|
|
2005-06-15 12:22:59 +02:00
|
|
|
extern const struct test winetest_testlist[];
|
2002-10-30 21:36:21 +01:00
|
|
|
|
|
|
|
/* debug level */
|
|
|
|
int winetest_debug = 1;
|
|
|
|
|
2003-01-02 18:52:05 +01:00
|
|
|
/* interactive mode? */
|
|
|
|
int winetest_interactive = 0;
|
|
|
|
|
2002-10-30 21:36:21 +01:00
|
|
|
/* current platform */
|
|
|
|
const char *winetest_platform = "windows";
|
|
|
|
|
|
|
|
/* report successful tests (BOOL) */
|
2018-05-02 01:38:03 +02:00
|
|
|
int winetest_report_success = 0;
|
2002-10-30 21:36:21 +01:00
|
|
|
|
|
|
|
/* passing arguments around */
|
|
|
|
static int winetest_argc;
|
|
|
|
static char** winetest_argv;
|
|
|
|
|
|
|
|
static const struct test *current_test; /* test currently being run */
|
|
|
|
|
|
|
|
static LONG successes; /* number of successful tests */
|
|
|
|
static LONG failures; /* number of failures */
|
2007-01-11 15:37:19 +01:00
|
|
|
static LONG skipped; /* number of skipped test chunks */
|
2002-10-30 21:36:21 +01:00
|
|
|
static LONG todo_successes; /* number of successful tests inside todo block */
|
|
|
|
static LONG todo_failures; /* number of failures inside todo block */
|
|
|
|
|
|
|
|
/* The following data must be kept track of on a per-thread basis */
|
2017-03-07 18:29:32 +01:00
|
|
|
struct tls_data
|
2002-10-30 21:36:21 +01:00
|
|
|
{
|
|
|
|
const char* current_file; /* file of current check */
|
|
|
|
int current_line; /* line of current check */
|
2016-02-09 10:40:01 +01:00
|
|
|
unsigned int todo_level; /* current todo nesting level */
|
2002-10-30 21:36:21 +01:00
|
|
|
int todo_do_loop;
|
2009-08-19 13:19:31 +02:00
|
|
|
char *str_pos; /* position in debug buffer */
|
|
|
|
char strings[2000]; /* buffer for debug strings */
|
2017-03-07 18:29:32 +01:00
|
|
|
};
|
2002-10-30 21:36:21 +01:00
|
|
|
static DWORD tls_index;
|
|
|
|
|
2017-03-07 18:29:32 +01:00
|
|
|
static struct tls_data *get_tls_data(void)
|
2002-10-30 21:36:21 +01:00
|
|
|
{
|
2017-03-07 18:29:32 +01:00
|
|
|
struct tls_data *data;
|
2002-10-30 21:36:21 +01:00
|
|
|
DWORD last_error;
|
|
|
|
|
|
|
|
last_error=GetLastError();
|
|
|
|
data=TlsGetValue(tls_index);
|
|
|
|
if (!data)
|
|
|
|
{
|
2017-03-07 18:29:32 +01:00
|
|
|
data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data));
|
2009-08-19 13:19:31 +02:00
|
|
|
data->str_pos = data->strings;
|
2002-10-30 21:36:21 +01:00
|
|
|
TlsSetValue(tls_index,data);
|
|
|
|
}
|
|
|
|
SetLastError(last_error);
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2009-08-19 13:19:31 +02:00
|
|
|
/* allocate some tmp space for a string */
|
|
|
|
static char *get_temp_buffer( size_t n )
|
|
|
|
{
|
2017-03-07 18:29:32 +01:00
|
|
|
struct tls_data *data = get_tls_data();
|
2009-08-19 13:19:31 +02:00
|
|
|
char *res = data->str_pos;
|
|
|
|
|
|
|
|
if (res + n >= &data->strings[sizeof(data->strings)]) res = data->strings;
|
|
|
|
data->str_pos = res + n;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-01-17 02:05:36 +01:00
|
|
|
/* release extra space that we requested in get_temp_buffer() */
|
2009-08-19 13:19:31 +02:00
|
|
|
static void release_temp_buffer( char *ptr, size_t size )
|
|
|
|
{
|
2017-03-07 18:29:32 +01:00
|
|
|
struct tls_data *data = get_tls_data();
|
2009-08-19 13:19:31 +02:00
|
|
|
data->str_pos = ptr + size;
|
|
|
|
}
|
|
|
|
|
2002-10-30 21:36:21 +01:00
|
|
|
static void exit_process( int code )
|
|
|
|
{
|
2002-12-17 02:47:04 +01:00
|
|
|
fflush( stdout );
|
2002-10-30 21:36:21 +01:00
|
|
|
ExitProcess( code );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-11 01:17:42 +01:00
|
|
|
void winetest_set_location( const char* file, int line )
|
|
|
|
{
|
2017-03-07 18:29:32 +01:00
|
|
|
struct tls_data *data = get_tls_data();
|
2002-12-11 01:17:42 +01:00
|
|
|
data->current_file=strrchr(file,'/');
|
|
|
|
if (data->current_file==NULL)
|
|
|
|
data->current_file=strrchr(file,'\\');
|
|
|
|
if (data->current_file==NULL)
|
|
|
|
data->current_file=file;
|
|
|
|
else
|
|
|
|
data->current_file++;
|
|
|
|
data->current_line=line;
|
|
|
|
}
|
|
|
|
|
2008-05-29 18:30:04 +02:00
|
|
|
int broken( int condition )
|
|
|
|
{
|
|
|
|
return (strcmp(winetest_platform, "windows") == 0) && condition;
|
|
|
|
}
|
|
|
|
|
2002-10-30 21:36:21 +01:00
|
|
|
/*
|
|
|
|
* Checks condition.
|
|
|
|
* Parameters:
|
|
|
|
* - condition - condition to check;
|
|
|
|
* - msg test description;
|
|
|
|
* - file - test application source code file name of the check
|
|
|
|
* - line - test application source code file line number of the check
|
|
|
|
* Return:
|
|
|
|
* 0 if condition does not have the expected value, 1 otherwise
|
|
|
|
*/
|
2010-04-09 15:48:05 +02:00
|
|
|
int winetest_vok( int condition, const char *msg, __winetest_va_list args )
|
2002-10-30 21:36:21 +01:00
|
|
|
{
|
2017-03-07 18:29:32 +01:00
|
|
|
struct tls_data *data = get_tls_data();
|
2002-10-30 21:36:21 +01:00
|
|
|
|
|
|
|
if (data->todo_level)
|
|
|
|
{
|
|
|
|
if (condition)
|
|
|
|
{
|
2016-01-13 12:41:42 +01:00
|
|
|
printf( "%s:%d: Test succeeded inside todo block: ",
|
|
|
|
data->current_file, data->current_line );
|
|
|
|
vprintf(msg, args);
|
2009-02-19 14:56:34 +01:00
|
|
|
InterlockedIncrement(&todo_failures);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (winetest_debug > 0)
|
2002-10-30 21:36:21 +01:00
|
|
|
{
|
2016-01-13 12:41:42 +01:00
|
|
|
printf( "%s:%d: Test marked todo: ",
|
|
|
|
data->current_file, data->current_line );
|
|
|
|
vprintf(msg, args);
|
2002-10-30 21:36:21 +01:00
|
|
|
}
|
2009-02-19 14:56:34 +01:00
|
|
|
InterlockedIncrement(&todo_successes);
|
|
|
|
return 1;
|
2002-10-30 21:36:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!condition)
|
|
|
|
{
|
2016-01-13 12:41:42 +01:00
|
|
|
printf( "%s:%d: Test failed: ",
|
|
|
|
data->current_file, data->current_line );
|
|
|
|
vprintf(msg, args);
|
2002-10-30 21:36:21 +01:00
|
|
|
InterlockedIncrement(&failures);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-05-02 01:38:03 +02:00
|
|
|
if (winetest_report_success)
|
2016-01-13 12:41:42 +01:00
|
|
|
printf( "%s:%d: Test succeeded\n",
|
|
|
|
data->current_file, data->current_line);
|
2002-10-30 21:36:21 +01:00
|
|
|
InterlockedIncrement(&successes);
|
2009-02-19 14:56:34 +01:00
|
|
|
return 1;
|
2002-10-30 21:36:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-09 15:48:05 +02:00
|
|
|
void __winetest_cdecl winetest_ok( int condition, const char *msg, ... )
|
2008-06-10 18:29:46 +02:00
|
|
|
{
|
2010-04-09 15:48:05 +02:00
|
|
|
__winetest_va_list valist;
|
2008-06-10 18:29:46 +02:00
|
|
|
|
2010-04-09 15:48:05 +02:00
|
|
|
__winetest_va_start(valist, msg);
|
2010-02-24 16:48:07 +01:00
|
|
|
winetest_vok(condition, msg, valist);
|
2010-04-09 15:48:05 +02:00
|
|
|
__winetest_va_end(valist);
|
2008-06-10 18:29:46 +02:00
|
|
|
}
|
|
|
|
|
2010-04-09 15:48:05 +02:00
|
|
|
void __winetest_cdecl winetest_trace( const char *msg, ... )
|
2002-10-30 21:36:21 +01:00
|
|
|
{
|
2010-04-09 15:48:05 +02:00
|
|
|
__winetest_va_list valist;
|
2017-03-07 18:29:32 +01:00
|
|
|
struct tls_data *data = get_tls_data();
|
2002-10-30 21:36:21 +01:00
|
|
|
|
|
|
|
if (winetest_debug > 0)
|
|
|
|
{
|
2016-01-13 12:41:42 +01:00
|
|
|
printf( "%s:%d: ", data->current_file, data->current_line );
|
2010-04-09 15:48:05 +02:00
|
|
|
__winetest_va_start(valist, msg);
|
2016-01-13 12:41:42 +01:00
|
|
|
vprintf(msg, valist);
|
2010-04-09 15:48:05 +02:00
|
|
|
__winetest_va_end(valist);
|
2002-10-30 21:36:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-09 15:48:05 +02:00
|
|
|
void winetest_vskip( const char *msg, __winetest_va_list args )
|
2007-01-11 15:37:19 +01:00
|
|
|
{
|
2017-03-07 18:29:32 +01:00
|
|
|
struct tls_data *data = get_tls_data();
|
2007-01-11 15:37:19 +01:00
|
|
|
|
2016-01-13 12:41:42 +01:00
|
|
|
printf( "%s:%d: Tests skipped: ", data->current_file, data->current_line );
|
|
|
|
vprintf(msg, args);
|
2008-06-10 18:29:46 +02:00
|
|
|
skipped++;
|
|
|
|
}
|
|
|
|
|
2010-04-09 15:48:05 +02:00
|
|
|
void __winetest_cdecl winetest_skip( const char *msg, ... )
|
2008-06-10 18:29:46 +02:00
|
|
|
{
|
2010-04-09 15:48:05 +02:00
|
|
|
__winetest_va_list valist;
|
|
|
|
__winetest_va_start(valist, msg);
|
2008-06-10 18:29:46 +02:00
|
|
|
winetest_vskip(msg, valist);
|
2010-04-09 15:48:05 +02:00
|
|
|
__winetest_va_end(valist);
|
2008-06-10 18:29:46 +02:00
|
|
|
}
|
|
|
|
|
2010-04-09 15:48:05 +02:00
|
|
|
void __winetest_cdecl winetest_win_skip( const char *msg, ... )
|
2008-06-10 18:29:46 +02:00
|
|
|
{
|
2010-04-09 15:48:05 +02:00
|
|
|
__winetest_va_list valist;
|
|
|
|
__winetest_va_start(valist, msg);
|
2008-06-10 18:29:46 +02:00
|
|
|
if (strcmp(winetest_platform, "windows") == 0)
|
|
|
|
winetest_vskip(msg, valist);
|
|
|
|
else
|
|
|
|
winetest_vok(0, msg, valist);
|
2010-04-09 15:48:05 +02:00
|
|
|
__winetest_va_end(valist);
|
2007-01-11 15:37:19 +01:00
|
|
|
}
|
|
|
|
|
2016-02-09 10:40:01 +01:00
|
|
|
void winetest_start_todo( int is_todo )
|
2002-10-30 21:36:21 +01:00
|
|
|
{
|
2017-03-07 18:29:32 +01:00
|
|
|
struct tls_data *data = get_tls_data();
|
2016-02-09 10:40:01 +01:00
|
|
|
data->todo_level = (data->todo_level << 1) | (is_todo != 0);
|
2002-10-30 21:36:21 +01:00
|
|
|
data->todo_do_loop=1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int winetest_loop_todo(void)
|
|
|
|
{
|
2017-03-07 18:29:32 +01:00
|
|
|
struct tls_data *data = get_tls_data();
|
2002-10-30 21:36:21 +01:00
|
|
|
int do_loop=data->todo_do_loop;
|
|
|
|
data->todo_do_loop=0;
|
|
|
|
return do_loop;
|
|
|
|
}
|
|
|
|
|
2016-02-09 10:40:01 +01:00
|
|
|
void winetest_end_todo(void)
|
2002-10-30 21:36:21 +01:00
|
|
|
{
|
2017-03-07 18:29:32 +01:00
|
|
|
struct tls_data *data = get_tls_data();
|
2016-02-09 10:40:01 +01:00
|
|
|
data->todo_level >>= 1;
|
2002-10-30 21:36:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int winetest_get_mainargs( char*** pargv )
|
|
|
|
{
|
|
|
|
*pargv = winetest_argv;
|
|
|
|
return winetest_argc;
|
|
|
|
}
|
|
|
|
|
2013-04-12 11:00:58 +02:00
|
|
|
LONG winetest_get_failures(void)
|
|
|
|
{
|
|
|
|
return failures;
|
|
|
|
}
|
|
|
|
|
2013-04-18 10:44:43 +02:00
|
|
|
void winetest_add_failures( LONG new_failures )
|
|
|
|
{
|
|
|
|
while (new_failures-- > 0)
|
|
|
|
InterlockedIncrement( &failures );
|
|
|
|
}
|
|
|
|
|
2008-02-07 12:56:00 +01:00
|
|
|
void winetest_wait_child_process( HANDLE process )
|
|
|
|
{
|
|
|
|
DWORD exit_code = 1;
|
|
|
|
|
|
|
|
if (WaitForSingleObject( process, 30000 ))
|
2016-01-13 12:41:42 +01:00
|
|
|
printf( "%s: child process wait failed\n", current_test->name );
|
2008-02-07 12:56:00 +01:00
|
|
|
else
|
|
|
|
GetExitCodeProcess( process, &exit_code );
|
|
|
|
|
|
|
|
if (exit_code)
|
|
|
|
{
|
2008-05-07 12:10:51 +02:00
|
|
|
if (exit_code > 255)
|
|
|
|
{
|
2016-01-13 12:41:42 +01:00
|
|
|
printf( "%s: exception 0x%08x in child process\n", current_test->name, exit_code );
|
2008-05-07 12:10:51 +02:00
|
|
|
InterlockedIncrement( &failures );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-01-13 12:41:42 +01:00
|
|
|
printf( "%s: %u failures in child process\n",
|
|
|
|
current_test->name, exit_code );
|
2008-05-07 12:10:51 +02:00
|
|
|
while (exit_code-- > 0)
|
|
|
|
InterlockedIncrement(&failures);
|
|
|
|
}
|
2008-02-07 12:56:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-19 13:19:31 +02:00
|
|
|
const char *wine_dbgstr_wn( const WCHAR *str, int n )
|
|
|
|
{
|
|
|
|
char *dst, *res;
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
if (!((ULONG_PTR)str >> 16))
|
|
|
|
{
|
|
|
|
if (!str) return "(null)";
|
|
|
|
res = get_temp_buffer( 6 );
|
|
|
|
sprintf( res, "#%04x", LOWORD(str) );
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
if (n == -1)
|
|
|
|
{
|
|
|
|
const WCHAR *end = str;
|
|
|
|
while (*end) end++;
|
|
|
|
n = end - str;
|
|
|
|
}
|
|
|
|
if (n < 0) n = 0;
|
|
|
|
size = 12 + min( 300, n * 5 );
|
|
|
|
dst = res = get_temp_buffer( size );
|
|
|
|
*dst++ = 'L';
|
|
|
|
*dst++ = '"';
|
|
|
|
while (n-- > 0 && dst <= res + size - 10)
|
|
|
|
{
|
|
|
|
WCHAR c = *str++;
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
|
|
|
|
case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
|
|
|
|
case '\t': *dst++ = '\\'; *dst++ = 't'; break;
|
|
|
|
case '"': *dst++ = '\\'; *dst++ = '"'; break;
|
|
|
|
case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
|
|
|
|
default:
|
|
|
|
if (c >= ' ' && c <= 126)
|
|
|
|
*dst++ = c;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*dst++ = '\\';
|
|
|
|
sprintf(dst,"%04x",c);
|
|
|
|
dst+=4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*dst++ = '"';
|
|
|
|
if (n > 0)
|
|
|
|
{
|
|
|
|
*dst++ = '.';
|
|
|
|
*dst++ = '.';
|
|
|
|
*dst++ = '.';
|
|
|
|
}
|
|
|
|
*dst++ = 0;
|
|
|
|
release_temp_buffer( res, dst - res );
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-01-25 15:24:22 +01:00
|
|
|
const char *wine_dbgstr_guid( const GUID *guid )
|
|
|
|
{
|
|
|
|
char *res;
|
|
|
|
|
|
|
|
if (!guid) return "(null)";
|
|
|
|
res = get_temp_buffer( 39 ); /* CHARS_IN_GUID */
|
|
|
|
sprintf( res, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
|
|
|
|
guid->Data1, guid->Data2, guid->Data3, guid->Data4[0],
|
|
|
|
guid->Data4[1], guid->Data4[2], guid->Data4[3], guid->Data4[4],
|
|
|
|
guid->Data4[5], guid->Data4[6], guid->Data4[7] );
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2016-06-07 09:45:40 +02:00
|
|
|
const char *wine_dbgstr_rect( const RECT *rect )
|
|
|
|
{
|
|
|
|
char *res;
|
|
|
|
|
|
|
|
if (!rect) return "(null)";
|
|
|
|
res = get_temp_buffer( 60 );
|
|
|
|
sprintf( res, "(%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
|
|
|
|
release_temp_buffer( res, strlen(res) + 1 );
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2017-06-30 01:08:09 +02:00
|
|
|
const char *wine_dbgstr_longlong( ULONGLONG ll )
|
|
|
|
{
|
|
|
|
char *res;
|
|
|
|
|
|
|
|
res = get_temp_buffer( 17 );
|
|
|
|
if (sizeof(ll) > sizeof(unsigned long) && ll >> 32)
|
|
|
|
sprintf( res, "%lx%08lx", (unsigned long)(ll >> 32), (unsigned long)ll );
|
|
|
|
else
|
|
|
|
sprintf( res, "%lx", (unsigned long)ll );
|
|
|
|
release_temp_buffer( res, strlen(res) + 1 );
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2002-10-30 21:36:21 +01:00
|
|
|
/* Find a test by name */
|
|
|
|
static const struct test *find_test( const char *name )
|
|
|
|
{
|
|
|
|
const struct test *test;
|
|
|
|
const char *p;
|
2007-08-22 10:01:55 +02:00
|
|
|
size_t len;
|
2002-10-30 21:36:21 +01:00
|
|
|
|
|
|
|
if ((p = strrchr( name, '/' ))) name = p + 1;
|
|
|
|
if ((p = strrchr( name, '\\' ))) name = p + 1;
|
|
|
|
len = strlen(name);
|
|
|
|
if (len > 2 && !strcmp( name + len - 2, ".c" )) len -= 2;
|
|
|
|
|
|
|
|
for (test = winetest_testlist; test->name; test++)
|
|
|
|
{
|
|
|
|
if (!strncmp( test->name, name, len ) && !test->name[len]) break;
|
|
|
|
}
|
|
|
|
return test->name ? test : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-27 22:10:59 +02:00
|
|
|
/* Display list of valid tests */
|
|
|
|
static void list_tests(void)
|
|
|
|
{
|
|
|
|
const struct test *test;
|
|
|
|
|
2016-01-13 12:41:42 +01:00
|
|
|
printf( "Valid test names:\n" );
|
|
|
|
for (test = winetest_testlist; test->name; test++)
|
|
|
|
printf( " %s\n", test->name );
|
2005-05-27 22:10:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-30 21:36:21 +01:00
|
|
|
/* Run a named test, and return exit status */
|
|
|
|
static int run_test( const char *name )
|
|
|
|
{
|
|
|
|
const struct test *test;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
if (!(test = find_test( name )))
|
|
|
|
{
|
2016-01-13 12:41:42 +01:00
|
|
|
printf( "Fatal: test '%s' does not exist.\n", name );
|
2002-10-30 21:36:21 +01:00
|
|
|
exit_process(1);
|
|
|
|
}
|
|
|
|
successes = failures = todo_successes = todo_failures = 0;
|
|
|
|
tls_index=TlsAlloc();
|
|
|
|
current_test = test;
|
|
|
|
test->func();
|
|
|
|
|
|
|
|
if (winetest_debug)
|
|
|
|
{
|
2017-02-22 15:33:21 +01:00
|
|
|
printf( "%04x:%s: %d tests executed (%d marked as todo, %d %s), %d skipped.\n",
|
|
|
|
GetCurrentProcessId(), test->name,
|
|
|
|
successes + failures + todo_successes + todo_failures,
|
2016-01-13 12:41:42 +01:00
|
|
|
todo_successes, failures + todo_failures,
|
|
|
|
(failures + todo_failures != 1) ? "failures" : "failure",
|
|
|
|
skipped );
|
2002-10-30 21:36:21 +01:00
|
|
|
}
|
|
|
|
status = (failures + todo_failures < 255) ? failures + todo_failures : 255;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Display usage and exit */
|
|
|
|
static void usage( const char *argv0 )
|
|
|
|
{
|
2016-01-13 12:41:42 +01:00
|
|
|
printf( "Usage: %s test_name\n\n", argv0 );
|
2005-05-27 22:10:59 +02:00
|
|
|
list_tests();
|
2002-10-30 21:36:21 +01:00
|
|
|
exit_process(1);
|
|
|
|
}
|
|
|
|
|
2010-07-19 23:46:18 +02:00
|
|
|
/* trap unhandled exceptions */
|
|
|
|
static LONG CALLBACK exc_filter( EXCEPTION_POINTERS *ptrs )
|
|
|
|
{
|
2017-03-07 18:29:32 +01:00
|
|
|
struct tls_data *data = get_tls_data();
|
2010-07-19 23:46:18 +02:00
|
|
|
|
|
|
|
if (data->current_file)
|
2016-01-13 12:41:42 +01:00
|
|
|
printf( "%s:%d: this is the last test seen before the exception\n",
|
|
|
|
data->current_file, data->current_line );
|
2017-02-22 15:33:21 +01:00
|
|
|
printf( "%04x:%s: unhandled exception %08x at %p\n",
|
|
|
|
GetCurrentProcessId(), current_test->name,
|
2016-01-13 12:41:42 +01:00
|
|
|
ptrs->ExceptionRecord->ExceptionCode, ptrs->ExceptionRecord->ExceptionAddress );
|
2010-07-19 23:46:18 +02:00
|
|
|
fflush( stdout );
|
|
|
|
return EXCEPTION_EXECUTE_HANDLER;
|
|
|
|
}
|
2002-10-30 21:36:21 +01:00
|
|
|
|
2014-11-23 22:50:34 +01:00
|
|
|
/* check if we're running under wine */
|
|
|
|
static BOOL running_under_wine(void)
|
|
|
|
{
|
|
|
|
HMODULE module = GetModuleHandleA( "ntdll.dll" );
|
|
|
|
if (!module) return FALSE;
|
|
|
|
return (GetProcAddress( module, "wine_server_call" ) != NULL);
|
|
|
|
}
|
|
|
|
|
2012-04-20 09:14:45 +02:00
|
|
|
#ifdef __GNUC__
|
2010-07-20 11:41:05 +02:00
|
|
|
void _fpreset(void) {} /* override the mingw fpu init code */
|
2012-04-20 09:14:45 +02:00
|
|
|
#endif
|
2010-07-20 11:41:05 +02:00
|
|
|
|
2002-10-30 21:36:21 +01:00
|
|
|
/* main function */
|
|
|
|
int main( int argc, char **argv )
|
|
|
|
{
|
2008-08-01 10:48:45 +02:00
|
|
|
char p[128];
|
2002-10-30 21:36:21 +01:00
|
|
|
|
2004-05-03 22:19:13 +02:00
|
|
|
setvbuf (stdout, NULL, _IONBF, 0);
|
|
|
|
|
2002-10-30 21:36:21 +01:00
|
|
|
winetest_argc = argc;
|
|
|
|
winetest_argv = argv;
|
|
|
|
|
2014-11-23 22:50:34 +01:00
|
|
|
if (GetEnvironmentVariableA( "WINETEST_PLATFORM", p, sizeof(p) ))
|
|
|
|
winetest_platform = strdup(p);
|
|
|
|
else if (running_under_wine())
|
|
|
|
winetest_platform = "wine";
|
|
|
|
|
2008-08-01 10:48:45 +02:00
|
|
|
if (GetEnvironmentVariableA( "WINETEST_DEBUG", p, sizeof(p) )) winetest_debug = atoi(p);
|
|
|
|
if (GetEnvironmentVariableA( "WINETEST_INTERACTIVE", p, sizeof(p) )) winetest_interactive = atoi(p);
|
2018-05-02 01:38:03 +02:00
|
|
|
if (GetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", p, sizeof(p) )) winetest_report_success = atoi(p);
|
2008-08-01 10:48:45 +02:00
|
|
|
|
2010-07-19 23:46:18 +02:00
|
|
|
if (!strcmp( winetest_platform, "windows" )) SetUnhandledExceptionFilter( exc_filter );
|
2010-07-19 23:45:28 +02:00
|
|
|
if (!winetest_interactive) SetErrorMode( SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX );
|
|
|
|
|
2005-05-25 11:57:07 +02:00
|
|
|
if (!argv[1])
|
|
|
|
{
|
|
|
|
if (winetest_testlist[0].name && !winetest_testlist[1].name) /* only one test */
|
|
|
|
return run_test( winetest_testlist[0].name );
|
|
|
|
usage( argv[0] );
|
|
|
|
}
|
2005-05-27 22:10:59 +02:00
|
|
|
if (!strcmp( argv[1], "--list" ))
|
|
|
|
{
|
|
|
|
list_tests();
|
|
|
|
return 0;
|
|
|
|
}
|
2002-10-30 21:36:21 +01:00
|
|
|
return run_test(argv[1]);
|
|
|
|
}
|
|
|
|
|
2005-05-25 11:57:07 +02:00
|
|
|
#endif /* STANDALONE */
|
2002-10-30 21:36:21 +01:00
|
|
|
|
2006-05-25 20:07:57 +02:00
|
|
|
#endif /* __WINE_WINE_TEST_H */
|