[WINE]
[reactos.git] / reactos / include / reactos / wine / test.h
index 8af2673..cbe394d 100644 (file)
 #error wine/debug.h should not be used in Wine tests
 #endif
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #ifndef INVALID_FILE_ATTRIBUTES
 #define INVALID_FILE_ATTRIBUTES  (~0u)
 #endif
@@ -60,12 +64,15 @@ extern void winetest_start_todo( const char* platform );
 extern int winetest_loop_todo(void);
 extern void winetest_end_todo( const char* platform );
 extern int winetest_get_mainargs( char*** pargv );
+extern LONG winetest_get_failures(void);
+extern void winetest_add_failures( LONG new_failures );
 extern void winetest_wait_child_process( HANDLE process );
 
-extern const char *wine_dbgstr_wn( const WCHAR *str, int n );
+extern const char *wine_dbgstr_wn( const WCHAR *str, intptr_t n );
+extern const char *wine_dbgstr_guid( const GUID *guid );
 static inline const char *wine_dbgstr_w( const WCHAR *s ) { return wine_dbgstr_wn( s, -1 ); }
 
-/* strcmpW is avaiable for tests compiled under Wine, but not in standalone
+/* strcmpW is available for tests compiled under Wine, but not in standalone
  * builds under Windows, so we reimplement it under a different name. */
 static inline int winetest_strcmpW( const WCHAR *str1, const WCHAR *str2 )
 {
@@ -74,14 +81,22 @@ static inline int winetest_strcmpW( const WCHAR *str1, const WCHAR *str2 )
 }
 
 #ifdef STANDALONE
+
 #define START_TEST(name) \
   static void func_##name(void); \
   const struct test winetest_testlist[] = { { #name, func_##name }, { 0, 0 } }; \
   static void func_##name(void)
+
+#else /* STANDALONE */
+
+#ifdef __cplusplus
+#define START_TEST(name) extern "C" void func_##name(void)
 #else
 #define START_TEST(name) void func_##name(void)
 #endif
 
+#endif /* STANDALONE */
+
 #if defined(__x86_64__) && defined(__GNUC__) && defined(__WINE_USE_MSVCRT)
 #define __winetest_cdecl __cdecl
 #define __winetest_va_list __builtin_ms_va_list
@@ -123,7 +138,13 @@ extern void __winetest_cdecl winetest_trace( const char *msg, ... );
 #define todo(platform) for (winetest_start_todo(platform); \
                             winetest_loop_todo(); \
                             winetest_end_todo(platform))
+
+#define todo_ros       todo("reactos")
+#ifdef USE_WINE_TODOS
+#define todo_wine      todo_ros
+#else
 #define todo_wine      todo("wine")
+#endif
 
 
 #ifdef NONAMELESSUNION
@@ -184,6 +205,14 @@ extern void __winetest_cdecl winetest_trace( const char *msg, ... );
 # define __winetest_va_end(list) va_end(list)
 #endif
 
+/* Define WINETEST_MSVC_IDE_FORMATTING to alter the output format winetest will use for file/line numbers.
+   This alternate format makes the file/line numbers clickable in visual studio, to directly jump to them. */
+#if defined(WINETEST_MSVC_IDE_FORMATTING)
+# define __winetest_file_line_prefix "%s(%d)"
+#else
+# define __winetest_file_line_prefix "%s:%d"
+#endif
+
 struct test
 {
     const char *name;
@@ -234,10 +263,10 @@ static tls_data* get_tls_data(void)
     DWORD last_error;
 
     last_error=GetLastError();
-    data=TlsGetValue(tls_index);
+    data=(tls_data*)TlsGetValue(tls_index);
     if (!data)
     {
-        data=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(tls_data));
+        data=(tls_data*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(tls_data));
         data->str_pos = data->strings;
         TlsSetValue(tls_index,data);
     }
@@ -273,6 +302,9 @@ static void exit_process( int code )
 void winetest_set_location( const char* file, int line )
 {
     tls_data* data=get_tls_data();
+#if defined(WINETEST_MSVC_IDE_FORMATTING)
+    data->current_file = file;
+#else
     data->current_file=strrchr(file,'/');
     if (data->current_file==NULL)
         data->current_file=strrchr(file,'\\');
@@ -280,12 +312,17 @@ void winetest_set_location( const char* file, int line )
         data->current_file=file;
     else
         data->current_file++;
+#endif
     data->current_line=line;
 }
 
 int broken( int condition )
 {
-    return (strcmp(winetest_platform, "windows") == 0) && condition;
+    return ((strcmp(winetest_platform, "windows") == 0)
+#ifndef USE_WINE_TODOS
+    || (strcmp(winetest_platform, "reactos") == 0)
+#endif
+    ) && condition;
 }
 
 /*
@@ -306,7 +343,7 @@ int winetest_vok( int condition, const char *msg, __winetest_va_list args )
     {
         if (condition)
         {
-            fprintf( stdout, "%s:%d: Test succeeded inside todo block: ",
+            fprintf( stdout, __winetest_file_line_prefix ": Test succeeded inside todo block: ",
                      data->current_file, data->current_line );
             vfprintf(stdout, msg, args);
             InterlockedIncrement(&todo_failures);
@@ -317,7 +354,7 @@ int winetest_vok( int condition, const char *msg, __winetest_va_list args )
             /* show todos even if traces are disabled*/
             /*if (winetest_debug > 0)*/
             {
-                fprintf( stdout, "%s:%d: Test marked todo: ",
+                fprintf( stdout, __winetest_file_line_prefix ": Test marked todo: ",
                          data->current_file, data->current_line );
                 vfprintf(stdout, msg, args);
             }
@@ -329,7 +366,7 @@ int winetest_vok( int condition, const char *msg, __winetest_va_list args )
     {
         if (!condition)
         {
-            fprintf( stdout, "%s:%d: Test failed: ",
+            fprintf( stdout, __winetest_file_line_prefix ": Test failed: ",
                      data->current_file, data->current_line );
             vfprintf(stdout, msg, args);
             InterlockedIncrement(&failures);
@@ -338,7 +375,7 @@ int winetest_vok( int condition, const char *msg, __winetest_va_list args )
         else
         {
             if (report_success)
-                fprintf( stdout, "%s:%d: Test succeeded\n",
+                fprintf( stdout, __winetest_file_line_prefix ": Test succeeded\n",
                          data->current_file, data->current_line);
             InterlockedIncrement(&successes);
             return 1;
@@ -362,7 +399,7 @@ void __winetest_cdecl winetest_trace( const char *msg, ... )
 
     if (winetest_debug > 0)
     {
-        fprintf( stdout, "%s:%d: ", data->current_file, data->current_line );
+        fprintf( stdout, __winetest_file_line_prefix ": ", data->current_file, data->current_line );
         __winetest_va_start(valist, msg);
         vfprintf(stdout, msg, valist);
         __winetest_va_end(valist);
@@ -373,7 +410,7 @@ void winetest_vskip( const char *msg, __winetest_va_list args )
 {
     tls_data* data=get_tls_data();
 
-    fprintf( stdout, "%s:%d: Tests skipped: ", data->current_file, data->current_line );
+    fprintf( stdout, __winetest_file_line_prefix ": Tests skipped: ", data->current_file, data->current_line );
     vfprintf(stdout, msg, args);
     skipped++;
 }
@@ -390,7 +427,11 @@ void __winetest_cdecl winetest_win_skip( const char *msg, ... )
 {
     __winetest_va_list valist;
     __winetest_va_start(valist, msg);
-    if (strcmp(winetest_platform, "windows") == 0)
+    if ((strcmp(winetest_platform, "windows") == 0)
+#ifndef USE_WINE_TODOS
+    || (strcmp(winetest_platform, "reactos") == 0)
+#endif
+    )
         winetest_vskip(msg, valist);
     else
         winetest_vok(0, msg, valist);
@@ -428,6 +469,17 @@ int winetest_get_mainargs( char*** pargv )
     return winetest_argc;
 }
 
+LONG winetest_get_failures(void)
+{
+    return failures;
+}
+
+void winetest_add_failures( LONG new_failures )
+{
+    while (new_failures-- > 0)
+        InterlockedIncrement( &failures );
+}
+
 void winetest_wait_child_process( HANDLE process )
 {
     DWORD exit_code = 1;
@@ -441,20 +493,20 @@ void winetest_wait_child_process( HANDLE process )
     {
         if (exit_code > 255)
         {
-            fprintf( stdout, "%s: exception 0x%08x in child process\n", current_test->name, exit_code );
+            fprintf( stdout, "%s: exception 0x%08x in child process\n", current_test->name, (unsigned)exit_code );
             InterlockedIncrement( &failures );
         }
         else
         {
             fprintf( stdout, "%s: %u failures in child process\n",
-                     current_test->name, exit_code );
+                     current_test->name, (unsigned)exit_code );
             while (exit_code-- > 0)
                 InterlockedIncrement(&failures);
         }
     }
 }
 
-const char *wine_dbgstr_wn( const WCHAR *str, int n )
+const char *wine_dbgstr_wn( const WCHAR *str, intptr_t n )
 {
     char *dst, *res;
     size_t size;
@@ -510,6 +562,19 @@ const char *wine_dbgstr_wn( const WCHAR *str, int n )
     return res;
 }
 
+const char *wine_dbgstr_guid( const GUID *guid )
+{
+    char *res;
+
+    if (!guid) return "(null)";
+    res = get_temp_buffer( 39 ); /* CHARS_IN_GUID */
+    sprintf( res, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
+             guid->Data1, guid->Data2, guid->Data3, guid->Data4[0],
+             guid->Data4[1], guid->Data4[2], guid->Data4[3], guid->Data4[4],
+             guid->Data4[5], guid->Data4[6], guid->Data4[7] );
+    return res;
+}
+
 /* Find a test by name */
 static const struct test *find_test( const char *name )
 {
@@ -564,11 +629,11 @@ static int run_test( const char *name )
     /* show test results even if traces are disabled */
     /*if (winetest_debug)*/
     {
-        fprintf( stdout, "%s: %d tests executed (%d marked as todo, %d %s), %d skipped.\n",
-                 test->name, successes + failures + todo_successes + todo_failures,
-                 todo_successes, failures + todo_failures,
+        fprintf( stdout, "\n%s: %d tests executed (%d marked as todo, %d %s), %d skipped.\n",
+                 test->name, (int)(successes + failures + todo_successes + todo_failures),
+                 (int)todo_successes, (int)(failures + todo_failures),
                  (failures + todo_failures != 1) ? "failures" : "failure",
-                 skipped );
+                 (int)skipped );
     }
     status = (failures + todo_failures < 255) ? failures + todo_failures : 255;
     return status;
@@ -656,7 +721,7 @@ int main( int argc, char **argv )
 #define ok_char(expression, result) ok_hex(expression, result)
 
 #define ok_err(error) \
-    ok(GetLastError() == (error), "Wrong last error. Expected " #error ", got %d\n", (int)GetLastError())
+    ok(GetLastError() == (error), "Wrong last error. Expected " #error ", got 0x%lx\n", GetLastError())
 
 #define ok_str(x, y) \
     ok(strcmp(x, y) == 0, "Wrong string. Expected '%s', got '%s'\n", y, x)
@@ -669,4 +734,8 @@ int main( int argc, char **argv )
 #define ok_ntstatus(status, expected) ok_hex(status, expected)
 #define ok_hdl ok_ptr
 
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
 #endif  /* __WINE_WINE_TEST_H */