From: Francois Gouget Subject: [1/2] tests: Add winetest_status() which indicates what to do with a test result. Message-Id: Date: Fri, 5 Feb 2016 15:31:11 +0100 (CET) winetest_status() takes into account not just the condition but also the todo level, debug level, whether to report successful tests; and returns the test status and whether to trace its result. This allows individual tests to do their own logging taking into account all these flags. Signed-off-by: Francois Gouget --- include/wine/test.h | 87 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 31 deletions(-) diff --git a/include/wine/test.h b/include/wine/test.h index bed44f9..cb412ed 100644 --- a/include/wine/test.h +++ b/include/wine/test.h @@ -85,6 +85,15 @@ static inline int winetest_strcmpW( const WCHAR *str1, const WCHAR *str2 ) #define START_TEST(name) void func_##name(void) #endif +#define WINETEST_SUCCESS 0x0 /* the test succeeded */ +#define WINETEST_FAILURE 0x1 /* the test failed */ +#define WINETEST_TODO 0x2 /* the test failed inside a todo */ +#define WINETEST_TODO_SUCCESS 0x3 /* the test succeeded inside a todo */ +#define WINETEST_RESULT_MASK 0x3 +#define WINETEST_REPORT 0x4 /* trace the result */ + +extern int winetest_status( int condition ); + #if defined(__x86_64__) && defined(__GNUC__) && defined(__WINE_USE_MSVCRT) #define __winetest_cdecl __cdecl #define __winetest_va_list __builtin_ms_va_list @@ -287,6 +296,20 @@ int broken( int condition ) return (strcmp(winetest_platform, "windows") == 0) && condition; } +int winetest_status( int condition ) +{ + tls_data* data=get_tls_data(); + + if (data->todo_level) + return condition ? + (WINETEST_TODO_SUCCESS | WINETEST_REPORT) : + (WINETEST_TODO | (winetest_debug > 0 ? WINETEST_REPORT : 0)); + else + return condition ? + (WINETEST_SUCCESS | (report_success ? WINETEST_REPORT : 0)) : + (WINETEST_FAILURE | WINETEST_REPORT); +} + /* * Checks condition. * Parameters: @@ -300,47 +323,49 @@ int broken( int condition ) int winetest_vok( int condition, const char *msg, __winetest_va_list args ) { tls_data* data=get_tls_data(); + int result = winetest_status(condition); - if (data->todo_level) + switch (result & WINETEST_RESULT_MASK) { - if (condition) + case WINETEST_SUCCESS: + if (result & WINETEST_REPORT) + printf( "%s:%d: Test succeeded\n", + data->current_file, data->current_line); + InterlockedIncrement(&successes); + return 1; + + case WINETEST_FAILURE: + if (result & WINETEST_REPORT) { - printf( "%s:%d: Test succeeded inside todo block: ", + printf( "%s:%d: Test failed: ", data->current_file, data->current_line ); vprintf(msg, args); - InterlockedIncrement(&todo_failures); - return 0; } - else - { - if (winetest_debug > 0) - { - printf( "%s:%d: Test marked todo: ", - data->current_file, data->current_line ); - vprintf(msg, args); - } - InterlockedIncrement(&todo_successes); - return 1; - } - } - else - { - if (!condition) + InterlockedIncrement(&failures); + return 0; + + case WINETEST_TODO: + if (result & WINETEST_REPORT) { - printf( "%s:%d: Test failed: ", + printf( "%s:%d: Test marked todo: ", data->current_file, data->current_line ); vprintf(msg, args); - InterlockedIncrement(&failures); - return 0; - } - else - { - if (report_success) - printf( "%s:%d: Test succeeded\n", - data->current_file, data->current_line); - InterlockedIncrement(&successes); - return 1; } + InterlockedIncrement(&todo_successes); + return 1; + + case WINETEST_TODO_SUCCESS: + if (result & WINETEST_REPORT) + printf( "%s:%d: Test succeeded inside todo block: ", + data->current_file, data->current_line ); + vprintf(msg, args); + InterlockedIncrement(&todo_failures); + return 0; + + default: + printf( "%s:%d: Unknown test result %d\n", + data->current_file, data->current_line, result); + return 1; } } -- 2.7.0