3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Definitions for Wine C unit tests.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Copyright (C) 2002 Alexandre Julliard
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * This library is free software; you can redistribute it and/or
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * modify it under the terms of the GNU Lesser General Public
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * License as published by the Free Software Foundation; either
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * version 2.1 of the License, or (at your option) any later version.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * This library is distributed in the hope that it will be useful,
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * but WITHOUT ANY WARRANTY; without even the implied warranty of
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Lesser General Public License for more details.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * You should have received a copy of the GNU Lesser General Public
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * License along with this library; if not, write to the Free Software
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * a choice of LGPL license versions is made available with the language indicating
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * that LGPLv2 or any later version may be used, or where a choice of which version
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * of the LGPL is applied is otherwise unspecified.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#error wine/library.h should not be used in Wine tests
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#error wine/unicode.h should not be used in Wine tests
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#error wine/debug.h should not be used in Wine tests
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/* debug level */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/* running in interactive mode? */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/* current platform */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncextern const char *winetest_platform;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncextern void winetest_set_location( const char* file, int line );
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncextern void winetest_start_todo( const char* platform );
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncextern int winetest_loop_todo(void);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncextern void winetest_end_todo( const char* platform );
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncextern void winetest_add_failures( LONG new_failures );
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncextern void winetest_wait_child_process( HANDLE process );
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncextern const char *wine_dbgstr_wn( const WCHAR *str, int n );
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncstatic inline const char *wine_dbgstr_w( const WCHAR *s ) { return wine_dbgstr_wn( s, -1 ); }
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/* strcmpW is available for tests compiled under Wine, but not in standalone
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * builds under Windows, so we reimplement it under a different name. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncstatic inline int winetest_strcmpW( const WCHAR *str1, const WCHAR *str2 )
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync while (*str1 && (*str1 == *str2)) { str1++; str2++; }
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync const struct test winetest_testlist[] = { { #name, func_##name }, { 0, 0 } }; \
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#if defined(__x86_64__) && defined(__GNUC__) && defined(__WINE_USE_MSVCRT)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncextern int winetest_vok( int condition, const char *msg, __winetest_va_list ap );
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncextern void winetest_vskip( const char *msg, __winetest_va_list ap );
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncextern void __winetest_cdecl winetest_ok( int condition, const char *msg, ... ) __attribute__((format (printf,2,3) ));
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncextern void __winetest_cdecl winetest_skip( const char *msg, ... ) __attribute__((format (printf,1,2)));
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncextern void __winetest_cdecl winetest_win_skip( const char *msg, ... ) __attribute__((format (printf,1,2)));
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncextern void __winetest_cdecl winetest_trace( const char *msg, ... ) __attribute__((format (printf,1,2)));
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#else /* __GNUC__ */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncextern void __winetest_cdecl winetest_ok( int condition, const char *msg, ... );
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncextern void __winetest_cdecl winetest_skip( const char *msg, ... );
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncextern void __winetest_cdecl winetest_win_skip( const char *msg, ... );
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncextern void __winetest_cdecl winetest_trace( const char *msg, ... );
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#endif /* __GNUC__ */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#define ok_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_ok
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#define skip_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_skip
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#define win_skip_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_win_skip
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#define trace_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_trace
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#define todo(platform) for (winetest_start_todo(platform); \
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync# define U(x) (x).u
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync# define U(x) (x)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync# define S(x) (x).s
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync# define S(x) (x)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/************************************************************************/
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/* Below is the implementation of the various functions, to be included
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * directly into the generated testlist.c file.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * It is done that way so that the dlls can build the test routines with
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * different includes or flags if needed.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#if defined(__x86_64__) && defined(__GNUC__) && defined(__WINE_USE_MSVCRT)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync# define __winetest_va_start(list,arg) __builtin_ms_va_start(list,arg)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync# define __winetest_va_end(list) __builtin_ms_va_end(list)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync# define __winetest_va_start(list,arg) va_start(list,arg)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/* debug level */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/* interactive mode? */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/* current platform */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/* report successful tests (BOOL) */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/* passing arguments around */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncstatic const struct test *current_test; /* test currently being run */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncstatic LONG successes; /* number of successful tests */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncstatic LONG skipped; /* number of skipped test chunks */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncstatic LONG todo_successes; /* number of successful tests inside todo block */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncstatic LONG todo_failures; /* number of failures inside todo block */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/* The following data must be kept track of on a per-thread basis */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsynctypedef struct
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync const char* current_file; /* file of current check */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync data=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(tls_data));
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/* allocate some tmp space for a string */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync if (res + n >= &data->strings[sizeof(data->strings)]) res = data->strings;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/* release extra space that we requested in gimme1() */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncstatic void release_temp_buffer( char *ptr, size_t size )
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncvoid winetest_set_location( const char* file, int line )
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync return (strcmp(winetest_platform, "windows") == 0) && condition;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Checks condition.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Parameters:
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * - condition - condition to check;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * - msg test description;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * - file - test application source code file name of the check
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * - line - test application source code file line number of the check
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * 0 if condition does not have the expected value, 1 otherwise
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncint winetest_vok( int condition, const char *msg, __winetest_va_list args )
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync fprintf( stdout, "%s:%d: Test succeeded inside todo block: ",
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncvoid __winetest_cdecl winetest_ok( int condition, const char *msg, ... )
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncvoid __winetest_cdecl winetest_trace( const char *msg, ... )
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync fprintf( stdout, "%s:%d: ", data->current_file, data->current_line );
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncvoid winetest_vskip( const char *msg, __winetest_va_list args )
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync fprintf( stdout, "%s:%d: Tests skipped: ", data->current_file, data->current_line );
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncvoid __winetest_cdecl winetest_skip( const char *msg, ... )
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncvoid __winetest_cdecl winetest_win_skip( const char *msg, ... )
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync while (new_failures-- > 0)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync fprintf( stdout, "%s: child process wait failed\n", current_test->name );
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync fprintf( stdout, "%s: exception 0x%08x in child process\n", current_test->name, exit_code );
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync fprintf( stdout, "%s: %u failures in child process\n",
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync while (exit_code-- > 0)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncconst char *wine_dbgstr_wn( const WCHAR *str, int n )
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync if (n == -1)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync if (n < 0) n = 0;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/* Find a test by name */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncstatic const struct test *find_test( const char *name )
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync const char *p;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync if (len > 2 && !strcmp( name + len - 2, ".c" )) len -= 2;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync if (!strncmp( test->name, name, len ) && !test->name[len]) break;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/* Display list of valid tests */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync for (test = winetest_testlist; test->name; test++) fprintf( stdout, " %s\n", test->name );
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/* Run a named test, and return exit status */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync fprintf( stdout, "Fatal: test '%s' does not exist.\n", name );
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync successes = failures = todo_successes = todo_failures = 0;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync fprintf( stdout, "%s: %d tests executed (%d marked as todo, %d %s), %d skipped.\n",
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync test->name, successes + failures + todo_successes + todo_failures,
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync (failures + todo_failures != 1) ? "failures" : "failure",
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync status = (failures + todo_failures < 255) ? failures + todo_failures : 255;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/* Display usage and exit */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync fprintf( stdout, "Usage: %s test_name\n\n", argv0 );
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/* trap unhandled exceptions */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncstatic LONG CALLBACK exc_filter( EXCEPTION_POINTERS *ptrs )
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync fprintf( stdout, "%s:%d: this is the last test seen before the exception\n",
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync fprintf( stdout, "%s: unhandled exception %08x at %p\n", current_test->name,
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync ptrs->ExceptionRecord->ExceptionCode, ptrs->ExceptionRecord->ExceptionAddress );
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncvoid _fpreset(void) {} /* override the mingw fpu init code */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/* main function */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync char p[128];
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync if (GetEnvironmentVariableA( "WINETEST_PLATFORM", p, sizeof(p) )) winetest_platform = strdup(p);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync if (GetEnvironmentVariableA( "WINETEST_DEBUG", p, sizeof(p) )) winetest_debug = atoi(p);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync if (GetEnvironmentVariableA( "WINETEST_INTERACTIVE", p, sizeof(p) )) winetest_interactive = atoi(p);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync if (GetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", p, sizeof(p) )) report_success = atoi(p);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync if (!strcmp( winetest_platform, "windows" )) SetUnhandledExceptionFilter( exc_filter );
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync if (!winetest_interactive) SetErrorMode( SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX );
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync if (winetest_testlist[0].name && !winetest_testlist[1].name) /* only one test */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#endif /* STANDALONE */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#endif /* __WINE_WINE_TEST_H */