#include <stdlib.h>
#include <windef.h>
#include <winbase.h>
-#include <wingdi.h>
-#include <winreg.h>
+#ifdef __WINE_CONFIG_H
+#error config.h should not be used in Wine tests
+#endif
#ifdef __WINE_WINE_LIBRARY_H
#error wine/library.h should not be used in Wine tests
#endif
#endif
#ifndef INVALID_FILE_ATTRIBUTES
-#define INVALID_FILE_ATTRIBUTES ((DWORD)~0UL)
+#define INVALID_FILE_ATTRIBUTES (~0u)
#endif
#ifndef INVALID_SET_FILE_POINTER
-#define INVALID_SET_FILE_POINTER ((DWORD)~0UL)
+#define INVALID_SET_FILE_POINTER (~0u)
#endif
/* debug level */
extern int winetest_get_mainargs( char*** pargv );
extern void winetest_wait_child_process( HANDLE process );
+extern const char *wine_dbgstr_wn( const WCHAR *str, int n );
+static inline const char *wine_dbgstr_w( const WCHAR *s ) { return wine_dbgstr_wn( s, -1 ); }
+
+/* strcmpW is avaiable for tests compiled under Wine, but not in standalone
+ * 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;
+}
+
#ifdef STANDALONE
#define START_TEST(name) \
static void func_##name(void); \
#define START_TEST(name) void func_##name(void)
#endif
+#if defined(__x86_64__) && defined(__GNUC__) && defined(__WINE_USE_MSVCRT)
+#define __winetest_cdecl __cdecl
+#define __winetest_va_list __builtin_ms_va_list
+#else
+#define __winetest_cdecl
+#define __winetest_va_list va_list
+#endif
+
extern int broken( int condition );
-extern int winetest_vok( int condition, const char *msg, va_list ap );
-extern void winetest_vskip( const char *msg, va_list ap );
+extern int winetest_vok( int condition, const char *msg, __winetest_va_list ap );
+extern void winetest_vskip( const char *msg, __winetest_va_list ap );
#ifdef __GNUC__
-extern int winetest_ok( int condition, const char *msg, ... ) __attribute__((format (printf,2,3) ));
-extern void winetest_skip( const char *msg, ... ) __attribute__((format (printf,1,2)));
-extern void winetest_win_skip( const char *msg, ... ) __attribute__((format (printf,1,2)));
-extern void winetest_trace( const char *msg, ... ) __attribute__((format (printf,1,2)));
+extern void __winetest_cdecl winetest_ok( int condition, const char *msg, ... ) __attribute__((format (printf,2,3) ));
+extern void __winetest_cdecl winetest_skip( const char *msg, ... ) __attribute__((format (printf,1,2)));
+extern void __winetest_cdecl winetest_win_skip( const char *msg, ... ) __attribute__((format (printf,1,2)));
+extern void __winetest_cdecl winetest_trace( const char *msg, ... ) __attribute__((format (printf,1,2)));
#else /* __GNUC__ */
-extern int winetest_ok( int condition, const char *msg, ... );
-extern void winetest_skip( const char *msg, ... );
-extern void winetest_win_skip( const char *msg, ... );
-extern void winetest_trace( const char *msg, ... );
+extern void __winetest_cdecl winetest_ok( int condition, const char *msg, ... );
+extern void __winetest_cdecl winetest_skip( const char *msg, ... );
+extern void __winetest_cdecl winetest_win_skip( const char *msg, ... );
+extern void __winetest_cdecl winetest_trace( const char *msg, ... );
#endif /* __GNUC__ */
-#define ok_(file, line) (winetest_set_location(file, line), 0) ? 0 : winetest_ok
+#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
#include <stdio.h>
+#if defined(__x86_64__) && defined(__GNUC__) && defined(__WINE_USE_MSVCRT)
+# 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
+
struct test
{
const char *name;
int current_line; /* line of current check */
int todo_level; /* current todo nesting level */
int todo_do_loop;
+ char *str_pos; /* position in debug buffer */
+ char strings[2000]; /* buffer for debug strings */
} tls_data;
static DWORD tls_index;
data=TlsGetValue(tls_index);
if (!data)
{
- data=HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(tls_data));
+ data=HeapAlloc(GetProcessHeap(), 0, sizeof(tls_data));
+ data->todo_level = 0;
+ data->str_pos = data->strings;
TlsSetValue(tls_index,data);
}
SetLastError(last_error);
return data;
}
+/* allocate some tmp space for a string */
+static char *get_temp_buffer( size_t n )
+{
+ tls_data *data = get_tls_data();
+ char *res = data->str_pos;
+
+ if (res + n >= &data->strings[sizeof(data->strings)]) res = data->strings;
+ data->str_pos = res + n;
+ return res;
+}
+
+/* release extra space that we requested in gimme1() */
+static void release_temp_buffer( char *ptr, size_t size )
+{
+ tls_data *data = get_tls_data();
+ data->str_pos = ptr + size;
+}
+
static void exit_process( int code )
{
fflush( stdout );
* Return:
* 0 if condition does not have the expected value, 1 otherwise
*/
-int winetest_vok( int condition, const char *msg, va_list args )
+int winetest_vok( int condition, const char *msg, __winetest_va_list args )
{
tls_data* data=get_tls_data();
{
if (condition)
{
- fprintf( stdout, "%s:%d: Test succeeded inside todo block",
+ fprintf( stdout, "%s:%d: Test succeeded inside todo block: ",
data->current_file, data->current_line );
- if (msg[0])
+ vfprintf(stdout, msg, args);
+ InterlockedIncrement(&todo_failures);
+ return 0;
+ }
+ else
+ {
+ if (winetest_debug > 0)
{
- fprintf(stdout,": ");
+ fprintf( stdout, "%s:%d: Test marked todo: ",
+ data->current_file, data->current_line );
vfprintf(stdout, msg, args);
}
- InterlockedIncrement(&todo_failures);
- return 0;
+ InterlockedIncrement(&todo_successes);
+ return 1;
}
- else InterlockedIncrement(&todo_successes);
}
else
{
if (!condition)
{
- fprintf( stdout, "%s:%d: Test failed",
+ fprintf( stdout, "%s:%d: Test failed: ",
data->current_file, data->current_line );
- if (msg[0])
- {
- fprintf( stdout,": ");
- vfprintf(stdout, msg, args);
- }
+ vfprintf(stdout, msg, args);
InterlockedIncrement(&failures);
return 0;
}
fprintf( stdout, "%s:%d: Test succeeded\n",
data->current_file, data->current_line);
InterlockedIncrement(&successes);
+ return 1;
}
}
- return 1;
}
-int winetest_ok( int condition, const char *msg, ... )
+void __winetest_cdecl winetest_ok( int condition, const char *msg, ... )
{
- va_list valist;
- int rc;
+ __winetest_va_list valist;
- va_start(valist, msg);
- rc=winetest_vok(condition, msg, valist);
- va_end(valist);
- return rc;
+ __winetest_va_start(valist, msg);
+ winetest_vok(condition, msg, valist);
+ __winetest_va_end(valist);
}
-void winetest_trace( const char *msg, ... )
+void __winetest_cdecl winetest_trace( const char *msg, ... )
{
- va_list valist;
+ __winetest_va_list valist;
tls_data* data=get_tls_data();
if (winetest_debug > 0)
{
fprintf( stdout, "%s:%d: ", data->current_file, data->current_line );
- va_start(valist, msg);
+ __winetest_va_start(valist, msg);
vfprintf(stdout, msg, valist);
- va_end(valist);
+ __winetest_va_end(valist);
}
}
-void winetest_vskip( const char *msg, va_list args )
+void winetest_vskip( const char *msg, __winetest_va_list args )
{
tls_data* data=get_tls_data();
skipped++;
}
-void winetest_skip( const char *msg, ... )
+void __winetest_cdecl winetest_skip( const char *msg, ... )
{
- va_list valist;
- va_start(valist, msg);
+ __winetest_va_list valist;
+ __winetest_va_start(valist, msg);
winetest_vskip(msg, valist);
- va_end(valist);
+ __winetest_va_end(valist);
}
-void winetest_win_skip( const char *msg, ... )
+void __winetest_cdecl winetest_win_skip( const char *msg, ... )
{
- va_list valist;
- va_start(valist, msg);
+ __winetest_va_list valist;
+ __winetest_va_start(valist, msg);
if (strcmp(winetest_platform, "windows") == 0)
winetest_vskip(msg, valist);
else
winetest_vok(0, msg, valist);
- va_end(valist);
+ __winetest_va_end(valist);
}
void winetest_start_todo( const char* platform )
}
}
+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;
+}
+
/* Find a test by name */
static const struct test *find_test( const char *name )
{
/* main function */
int main( int argc, char **argv )
{
- char *p;
+ char p[128];
setvbuf (stdout, NULL, _IONBF, 0);
winetest_argc = argc;
winetest_argv = argv;
- if ((p = getenv( "WINETEST_PLATFORM" ))) winetest_platform = strdup(p);
- if ((p = getenv( "WINETEST_DEBUG" ))) winetest_debug = atoi(p);
- if ((p = getenv( "WINETEST_INTERACTIVE" ))) winetest_interactive = atoi(p);
- if ((p = getenv( "WINETEST_REPORT_SUCCESS"))) report_success = atoi(p);
+ if (GetEnvironmentVariableA( "WINETEST_PLATFORM", p, sizeof(p) )) winetest_platform = _strdup(p);
+ if (GetEnvironmentVariableA( "WINETEST_DEBUG", p, sizeof(p) )) winetest_debug = atoi(p);
+ if (GetEnvironmentVariableA( "WINETEST_INTERACTIVE", p, sizeof(p) )) winetest_interactive = atoi(p);
+ if (GetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", p, sizeof(p) )) report_success = atoi(p);
+
if (!argv[1])
{
if (winetest_testlist[0].name && !winetest_testlist[1].name) /* only one test */