[WINE]
[reactos.git] / reactos / include / reactos / wine / test.h
index 97d1d11..e0253f7 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
@@ -234,10 +255,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);
     }
@@ -314,7 +335,8 @@ int winetest_vok( int condition, const char *msg, __winetest_va_list args )
         }
         else
         {
-            if (winetest_debug > 0)
+            /* show todos even if traces are disabled*/
+            /*if (winetest_debug > 0)*/
             {
                 fprintf( stdout, "%s:%d: Test marked todo: ",
                          data->current_file, data->current_line );
@@ -389,7 +411,7 @@ 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) || (strcmp(winetest_platform, "reactos") == 0))
         winetest_vskip(msg, valist);
     else
         winetest_vok(0, msg, valist);
@@ -427,6 +449,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;
@@ -453,7 +486,7 @@ void winetest_wait_child_process( HANDLE process )
     }
 }
 
-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;
@@ -509,6 +542,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 )
 {
@@ -538,6 +584,11 @@ static void list_tests(void)
     for (test = winetest_testlist; test->name; test++) fprintf( stdout, "    %s\n", test->name );
 }
 
+/* Disable false-positive claiming "test" would be NULL-dereferenced */
+#if defined(_MSC_VER)
+#pragma warning(push)
+#pragma warning(disable:28182)
+#endif
 
 /* Run a named test, and return exit status */
 static int run_test( const char *name )
@@ -555,7 +606,8 @@ static int run_test( const char *name )
     current_test = test;
     test->func();
 
-    if (winetest_debug)
+    /* 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,
@@ -567,6 +619,9 @@ static int run_test( const char *name )
     return status;
 }
 
+#if defined(_MSC_VER)
+#pragma warning(pop)
+#endif
 
 /* Display usage and exit */
 static void usage( const char *argv0 )
@@ -610,4 +665,57 @@ int main( int argc, char **argv )
 
 #endif  /* STANDALONE */
 
+// hack for ntdll winetest (this is defined in excpt.h)
+#undef exception_info
+
+// Some helpful definitions
+
+#define ok_hex(expression, result) \
+    do { \
+        int _value = (expression); \
+        ok(_value == (result), "Wrong value for '%s', expected: " #result " (0x%x), got: 0x%x\n", \
+           #expression, (int)(result), _value); \
+    } while (0)
+
+#define ok_dec(expression, result) \
+    do { \
+        int _value = (expression); \
+        ok(_value == (result), "Wrong value for '%s', expected: " #result " (%d), got: %d\n", \
+           #expression, (int)(result), _value); \
+    } while (0)
+
+#define ok_ptr(expression, result) \
+    do { \
+        void *_value = (expression); \
+        ok(_value == (result), "Wrong value for '%s', expected: " #result " (%p), got: %p\n", \
+           #expression, (void*)(result), _value); \
+    } while (0)
+
+#define ok_size_t(expression, result) \
+    do { \
+        size_t _value = (expression); \
+        ok(_value == (result), "Wrong value for '%s', expected: " #result " (%Ix), got: %Ix\n", \
+           #expression, (size_t)(result), _value); \
+    } while (0)
+
+#define ok_char(expression, result) ok_hex(expression, result)
+
+#define ok_err(error) \
+    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)
+
+#define ok_wstr(x, y) \
+    ok(wcscmp(x, y) == 0, "Wrong string. Expected '%S', got '%S'\n", y, x)
+
+#define ok_long(expression, result) ok_hex(expression, result)
+#define ok_int(expression, result) ok_dec(expression, result)
+#define ok_ntstatus(status, expected) ok_hex(status, expected)
+#define ok_hdl ok_ptr
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
 #endif  /* __WINE_WINE_TEST_H */