From 9dd7b9e5ca4ffe247d7a88b680483ed8c90f15d4 Mon Sep 17 00:00:00 2001 From: Mark Jansen Date: Sat, 14 Jan 2017 00:56:33 +0100 Subject: [PATCH] tests: Allow tests to specify a 'context', which shows up in the failure message. Signed-off-by: Mark Jansen --- include/wine/test.h | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/include/wine/test.h b/include/wine/test.h index 3341743..754cf8f 100644 --- a/include/wine/test.h +++ b/include/wine/test.h @@ -56,6 +56,8 @@ extern int winetest_interactive; extern const char *winetest_platform; extern void winetest_set_location( const char* file, int line ); +extern void winetest_set_context(const char* context, ...); +extern void winetest_end_context(void); extern void winetest_start_todo( int is_todo ); extern int winetest_loop_todo(void); extern void winetest_end_todo(void); @@ -232,6 +234,7 @@ typedef struct int todo_do_loop; char *str_pos; /* position in debug buffer */ char strings[2000]; /* buffer for debug strings */ + char context[100]; } tls_data; static DWORD tls_index; @@ -290,6 +293,22 @@ void winetest_set_location( const char* file, int line ) data->current_line=line; } +void winetest_set_context(const char* context, ...) +{ + __winetest_va_list valist; + + tls_data *data = get_tls_data(); + __winetest_va_start(valist, context); + vsprintf(data->context, context, valist); + __winetest_va_end(valist); +} + +void winetest_end_context(void) +{ + tls_data *data = get_tls_data(); + data->context[0] = '\0'; +} + int broken( int condition ) { return (strcmp(winetest_platform, "windows") == 0) && condition; @@ -313,8 +332,8 @@ int winetest_vok( int condition, const char *msg, __winetest_va_list args ) { if (condition) { - printf( "%s:%d: Test succeeded inside todo block: ", - data->current_file, data->current_line ); + printf( "%s:%d%s: Test succeeded inside todo block: ", + data->current_file, data->current_line, data->context ); vprintf(msg, args); InterlockedIncrement(&todo_failures); return 0; @@ -323,8 +342,8 @@ int winetest_vok( int condition, const char *msg, __winetest_va_list args ) { if (winetest_debug > 0) { - printf( "%s:%d: Test marked todo: ", - data->current_file, data->current_line ); + printf( "%s:%d%s: Test marked todo: ", + data->current_file, data->current_line, data->context ); vprintf(msg, args); } InterlockedIncrement(&todo_successes); @@ -335,8 +354,8 @@ int winetest_vok( int condition, const char *msg, __winetest_va_list args ) { if (!condition) { - printf( "%s:%d: Test failed: ", - data->current_file, data->current_line ); + printf( "%s:%d%s: Test failed: ", + data->current_file, data->current_line, data->context ); vprintf(msg, args); InterlockedIncrement(&failures); return 0; @@ -344,8 +363,8 @@ int winetest_vok( int condition, const char *msg, __winetest_va_list args ) else { if (report_success) - printf( "%s:%d: Test succeeded\n", - data->current_file, data->current_line); + printf( "%s:%d%s: Test succeeded\n", + data->current_file, data->current_line, data->context ); InterlockedIncrement(&successes); return 1; } @@ -368,7 +387,7 @@ void __winetest_cdecl winetest_trace( const char *msg, ... ) if (winetest_debug > 0) { - printf( "%s:%d: ", data->current_file, data->current_line ); + printf( "%s:%d%s: ", data->current_file, data->current_line, data->context ); __winetest_va_start(valist, msg); vprintf(msg, valist); __winetest_va_end(valist); @@ -379,7 +398,7 @@ void winetest_vskip( const char *msg, __winetest_va_list args ) { tls_data* data=get_tls_data(); - printf( "%s:%d: Tests skipped: ", data->current_file, data->current_line ); + printf( "%s:%d%s: Tests skipped: ", data->current_file, data->current_line, data->context ); vprintf(msg, args); skipped++; } -- 2.7.0.windows.2