Proposal: winetest 'context'

Mark Jansen learn0more+wine at gmail.com
Tue Feb 14 10:04:19 CST 2017


Hello,

Often when testing something, helper functions are introduced that are
called with different data (for example when iterating over tables).

Attached patch (winetest_set_context.diff) is a proposal that allows
tests to specify a 'context', that will be printed in the failure
message.
This way, the actual test code does not have to prefix every case with
a trace, or include the data in every test macro.
The patch is written so that tests do not have to use this mechanism,
so there is no need to convert all tests at once.
Second attachment (winetest_ctx_example.diff) shows how an existing
test could be converted to use this new technique.

Regards,

Mark Jansen
-------------- next part --------------
From 06179cb2b763918e3414c5fa789accf1bf47e965 Mon Sep 17 00:00:00 2001
From: Mark Jansen <learn0more+wine at gmail.com>
Date: Sat, 14 Jan 2017 00:57:03 +0100
Subject: [PATCH] kernel32/tests: example usage for winetest_set_context.

Signed-off-by: Mark Jansen <learn0more+wine at gmail.com>
---
 dlls/kernel32/tests/actctx.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/dlls/kernel32/tests/actctx.c b/dlls/kernel32/tests/actctx.c
index b68c895..23ab247 100644
--- a/dlls/kernel32/tests/actctx.c
+++ b/dlls/kernel32/tests/actctx.c
@@ -821,28 +821,29 @@ static void test_create_fail(void)
     ok(handle == INVALID_HANDLE_VALUE, "handle != INVALID_HANDLE_VALUE\n");
     ok(GetLastError() == ERROR_FILE_NOT_FOUND, "GetLastError == %u\n", GetLastError());
 
-    trace("wrong_manifest1\n");
+    winetest_set_context(" wrong_manifest1");
     test_create_and_fail(wrong_manifest1, NULL, 0 );
-    trace("wrong_manifest2\n");
+    winetest_set_context(" wrong_manifest2");
     test_create_and_fail(wrong_manifest2, NULL, 0 );
-    trace("wrong_manifest3\n");
+    winetest_set_context(" wrong_manifest3");
     test_create_and_fail(wrong_manifest3, NULL, 1 );
-    trace("wrong_manifest4\n");
+    winetest_set_context(" wrong_manifest4");
     test_create_and_fail(wrong_manifest4, NULL, 1 );
-    trace("wrong_manifest5\n");
+    winetest_set_context(" wrong_manifest5");
     test_create_and_fail(wrong_manifest5, NULL, 0 );
-    trace("wrong_manifest6\n");
+    winetest_set_context(" wrong_manifest6");
     test_create_and_fail(wrong_manifest6, NULL, 0 );
-    trace("wrong_manifest7\n");
+    winetest_set_context(" wrong_manifest7");
     test_create_and_fail(wrong_manifest7, NULL, 1 );
-    trace("wrong_manifest8\n");
+    winetest_set_context(" wrong_manifest8");
     test_create_and_fail(wrong_manifest8, NULL, 0 );
-    trace("UTF-16 manifest1 without BOM\n");
+    winetest_set_context(" UTF-16 manifest1 without BOM");
     test_create_wide_and_fail(manifest1, FALSE );
-    trace("manifest2\n");
+    winetest_set_context(" manifest2");
     test_create_and_fail(manifest2, NULL, 0 );
-    trace("manifest2+depmanifest1\n");
+    winetest_set_context(" manifest2+depmanifest1");
     test_create_and_fail(manifest2, wrong_depmanifest1, 0 );
+    winetest_end_context();
 }
 
 struct strsection_header
-- 
2.7.0.windows.2

-------------- next part --------------
From 9dd7b9e5ca4ffe247d7a88b680483ed8c90f15d4 Mon Sep 17 00:00:00 2001
From: Mark Jansen <learn0more+wine at gmail.com>
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 <learn0more+wine at gmail.com>
---
 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



More information about the wine-devel mailing list