[PATCH 1/2] tests: Return the condition value from ok() & co.
Francois Gouget
fgouget at codeweavers.com
Thu Jul 8 10:44:39 CDT 2021
This allows writing things like:
ret = GetComplexStructure(&out);
if (ok(ret, "GetComplexStructure failed le=%u\n", GetLastError()))
{
/* We know out was successfully filled so its content can be tested */
ok(strcmp(out.field1, val1) == 0, "bad field1\n");
...
}
Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---
This should avoid duplication between the ok() call and the
following if () condition.
---
include/wine/test.h | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/include/wine/test.h b/include/wine/test.h
index 8073071d262..6d90c13fe7a 100644
--- a/include/wine/test.h
+++ b/include/wine/test.h
@@ -91,7 +91,7 @@ extern int broken( int condition );
extern int winetest_vok( int condition, const char *msg, __winetest_va_list ap );
extern void winetest_vskip( const char *msg, __winetest_va_list ap );
-extern void __winetest_cdecl winetest_ok( int condition, const char *msg, ... ) __WINE_PRINTF_ATTR(2,3);
+extern int __winetest_cdecl winetest_ok( int condition, const char *msg, ... ) __WINE_PRINTF_ATTR(2,3);
extern void __winetest_cdecl winetest_skip( const char *msg, ... ) __WINE_PRINTF_ATTR(1,2);
extern void __winetest_cdecl winetest_win_skip( const char *msg, ... ) __WINE_PRINTF_ATTR(1,2);
extern void __winetest_cdecl winetest_trace( const char *msg, ... ) __WINE_PRINTF_ATTR(1,2);
@@ -102,7 +102,7 @@ extern void winetest_pop_context(void);
#ifdef WINETEST_NO_LINE_NUMBERS
# define subtest_(file, line) (winetest_set_location(file, 0), 0) ? (void)0 : winetest_subtest
# define ignore_exceptions_(file, line) (winetest_set_location(file, 0), 0) ? (void)0 : winetest_ignore_exceptions
-# define ok_(file, line) (winetest_set_location(file, 0), 0) ? (void)0 : winetest_ok
+# define ok_(file, line) (winetest_set_location(file, 0), 0) ? 0 : winetest_ok
# define skip_(file, line) (winetest_set_location(file, 0), 0) ? (void)0 : winetest_skip
# define win_skip_(file, line) (winetest_set_location(file, 0), 0) ? (void)0 : winetest_win_skip
# define trace_(file, line) (winetest_set_location(file, 0), 0) ? (void)0 : winetest_trace
@@ -110,7 +110,7 @@ extern void winetest_pop_context(void);
#else
# define subtest_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_subtest
# define ignore_exceptions_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_ignore_exceptions
-# define ok_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_ok
+# define ok_(file, line) (winetest_set_location(file, line), 0) ? 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
@@ -361,7 +361,7 @@ static LONG winetest_add_line( void )
* - file - test application source code file name of the check
* - line - test application source code file line number of the check
* Return:
- * 0 if condition does not have the expected value, 1 otherwise
+ * The condition value
*/
int winetest_vok( int condition, const char *msg, __winetest_va_list args )
{
@@ -374,7 +374,6 @@ int winetest_vok( int condition, const char *msg, __winetest_va_list args )
winetest_print_context( "Test succeeded inside todo block: " );
vprintf(msg, args);
InterlockedIncrement(&todo_failures);
- return 0;
}
else
{
@@ -390,7 +389,6 @@ int winetest_vok( int condition, const char *msg, __winetest_va_list args )
}
else
InterlockedIncrement(&muted_todo_successes);
- return 1;
}
}
else
@@ -400,7 +398,6 @@ int winetest_vok( int condition, const char *msg, __winetest_va_list args )
winetest_print_context( "Test failed: " );
vprintf(msg, args);
InterlockedIncrement(&failures);
- return 0;
}
else
{
@@ -410,18 +407,19 @@ int winetest_vok( int condition, const char *msg, __winetest_va_list args )
winetest_printf("Test succeeded\n");
}
InterlockedIncrement(&successes);
- return 1;
}
}
+ return condition;
}
-void __winetest_cdecl winetest_ok( int condition, const char *msg, ... )
+int __winetest_cdecl winetest_ok( int condition, const char *msg, ... )
{
__winetest_va_list valist;
__winetest_va_start(valist, msg);
winetest_vok(condition, msg, valist);
__winetest_va_end(valist);
+ return condition;
}
void __winetest_cdecl winetest_trace( const char *msg, ... )
--
2.20.1
More information about the wine-devel
mailing list