Enhancements for the C testing framework
Francois Gouget
fgouget at codeweavers.com
Mon Mar 18 13:56:32 CST 2002
Changelog:
* include/wine/test.h,
programs/winetest/wtmain.c
Add trace function (same as in the perl framework)
Add support for todo tests
Make it possible to specify a printf-style message in ok
Include windef.h in test.h for compiling tests on Windows
--
François Gouget
fgouget at codeweavers.com
-------------- next part --------------
Index: include/wine/test.h
===================================================================
RCS file: /home/wine/wine/include/wine/test.h,v
retrieving revision 1.2
diff -u -r1.2 test.h
--- include/wine/test.h 10 Mar 2002 00:02:38 -0000 1.2
+++ include/wine/test.h 18 Mar 2002 19:42:27 -0000
@@ -21,16 +21,34 @@
#ifndef __WINE_TEST_H
#define __WINE_TEST_H
+#include <stdarg.h>
+#ifndef __WINE__
+#include "windef.h"
+#endif
+
/* debug level */
extern int winetest_debug;
/* current platform */
extern const char *winetest_platform;
-extern void winetest_ok( int condition, const char *msg, const char *file, int line );
+typedef int (*twinetest_ok)( int condition, const char *msg, ...);
+typedef void (*twinetest_trace)( const char *msg, ...);
+
+extern twinetest_ok winetest_set_ok_location( const char* file, int line );
+extern twinetest_trace winetest_set_trace_location( const char* file, int line );
+extern int winetest_start_todo( const char* platform );
+extern int winetest_loop_todo();
+extern int winetest_end_todo( const char* platform );
#define START_TEST(name) void func_##name(void)
-#define ok(test,msg) winetest_ok( (test), (msg), __FILE__, __LINE__ )
+#define ok (*winetest_set_ok_location(__FILE__, __LINE__))
+#define trace (*winetest_set_trace_location(__FILE__, __LINE__))
+
+#define todo(platform) for (winetest_start_todo(platform); \
+ winetest_loop_todo(); \
+ winetest_end_todo(platform))
+#define todo_wine todo("wine")
#endif /* __WINE_TEST_H */
Index: programs/winetest/wtmain.c
===================================================================
RCS file: /home/wine/wine/programs/winetest/wtmain.c,v
retrieving revision 1.2
diff -u -r1.2 wtmain.c
--- programs/winetest/wtmain.c 10 Mar 2002 00:21:20 -0000 1.2
+++ programs/winetest/wtmain.c 18 Mar 2002 19:42:29 -0000
@@ -23,6 +23,8 @@
#include <stdlib.h>
#include <string.h>
+#include "wine/test.h"
+
/* debug level */
int winetest_debug = 1;
@@ -37,12 +39,18 @@
extern const struct test winetest_testlist[];
static const struct test *current_test; /* test currently being run */
+/* FIXME: Access to all the following variables must be protected in a
+ * multithread test. Either via thread local storage or via critical sections
+ */
+static const char* current_file; /* file of current check */
+static int current_line; /* line of current check */
static int successes; /* number of successful tests */
static int failures; /* number of failures */
static int todo_successes; /* number of successful tests inside todo block */
static int todo_failures; /* number of failures inside todo block */
static int todo_level; /* current todo nesting level */
+static int todo_do_loop;
/*
* Checks condition.
@@ -51,17 +59,29 @@
* - msg test description;
* - 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
*/
-void winetest_ok( int condition, const char *msg, const char *file, int line )
+int winetest_ok( int condition, const char *msg, ... )
{
+ va_list valist;
+
if (todo_level)
{
if (condition)
{
- fprintf( stderr, "%s:%d: Test succeeded inside todo block", file, line );
- if (msg && msg[0]) fprintf( stderr, ": %s", msg );
+ fprintf( stderr, "%s:%d: Test succeeded inside todo block",
+ current_file, current_line );
+ if (msg && msg[0])
+ {
+ va_start(valist, msg);
+ fprintf(stderr,": ");
+ vfprintf(stderr, msg, valist);
+ va_end(valist);
+ }
fputc( '\n', stderr );
todo_failures++;
+ return 0;
}
else todo_successes++;
}
@@ -69,15 +89,71 @@
{
if (!condition)
{
- fprintf( stderr, "%s:%d: Test failed", file, line );
- if (msg && msg[0]) fprintf( stderr, ": %s", msg );
+ fprintf( stderr, "%s:%d: Test failed",
+ current_file, current_line );
+ if (msg && msg[0])
+ {
+ va_start(valist, msg);
+ fprintf( stderr,": ");
+ vfprintf(stderr, msg, valist);
+ va_end(valist);
+ }
fputc( '\n', stderr );
failures++;
+ return 0;
}
else successes++;
}
+ return 1;
+}
+
+twinetest_ok winetest_set_ok_location( const char* file, int line )
+{
+ current_file=file;
+ current_line=line;
+ return &winetest_ok;
+}
+
+void winetest_trace( const char *msg, ... )
+{
+ va_list valist;
+
+ if (winetest_debug > 0)
+ {
+ va_start(valist, msg);
+ vfprintf(stderr, msg, valist);
+ va_end(valist);
+ }
}
+twinetest_trace winetest_set_trace_location( const char* file, int line )
+{
+ current_file=file;
+ current_line=line;
+ return &winetest_trace;
+}
+
+int winetest_start_todo( const char* platform )
+{
+ if (strcmp(winetest_platform,platform)==0)
+ todo_level++;
+ todo_do_loop=1;
+ return 0;
+}
+
+int winetest_loop_todo()
+{
+ int do_loop=todo_do_loop;
+ todo_do_loop=0;
+ return do_loop;
+}
+
+int winetest_end_todo( const char* platform )
+{
+ if (strcmp(winetest_platform,platform)==0)
+ todo_level--;
+ return 0;
+}
/* Find a test by name */
static const struct test *find_test( const char *name )
More information about the wine-patches
mailing list