[USER32_APITEST:WNDPROC] Improve failure handling
authorSerge Gautherie <reactos-git_serge_171003@gautherie.fr>
Mon, 24 Sep 2018 14:46:46 +0000 (16:46 +0200)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Sun, 2 Jun 2019 17:08:17 +0000 (19:08 +0200)
ROSTESTS-316

modules/rostests/apitests/user32/WndProc.c

index fddbd0f..8c30491 100644 (file)
@@ -9,6 +9,8 @@
 
 /* Used wine Redraw test for proof in principle. */
 
 
 /* Used wine Redraw test for proof in principle. */
 
+#define WMPAINT_COUNT_THRESHOLD 10
+
 /* Global variables to trigger exit from loop */
 static int redrawComplete, WMPAINT_count;
 
 /* Global variables to trigger exit from loop */
 static int redrawComplete, WMPAINT_count;
 
@@ -32,13 +34,14 @@ static LRESULT WINAPI redraw_window_procA(
     switch (msg)
     {
         case WM_PAINT:
     switch (msg)
     {
         case WM_PAINT:
-            trace("doing WM_PAINT %d\n", WMPAINT_count);
             WMPAINT_count++;
             WMPAINT_count++;
+            trace("Doing WM_PAINT %d/%d\n", WMPAINT_count, WMPAINT_COUNT_THRESHOLD);
 
 
-            if (WMPAINT_count > 10 && redrawComplete == 0)
+            if (WMPAINT_count > WMPAINT_COUNT_THRESHOLD && redrawComplete == 0)
             {
                 PAINTSTRUCT ps;
 
             {
                 PAINTSTRUCT ps;
 
+                trace("Calling *Paint()\n");
                 BeginPaint(hwnd, &ps);
                 EndPaint(hwnd, &ps);
                 return 1;
                 BeginPaint(hwnd, &ps);
                 EndPaint(hwnd, &ps);
                 return 1;
@@ -47,11 +50,13 @@ static LRESULT WINAPI redraw_window_procA(
             // This will force one stack corruption "ret" fault with normal window
             // procedure callback.
 #ifdef __MINGW32__
             // This will force one stack corruption "ret" fault with normal window
             // procedure callback.
 #ifdef __MINGW32__
+            trace("Executing __MINGW32__ stack corruption code\n");
             asm ("movl $0, %eax\n\t"
                  "leave\n\t"
                  "ret");
 #elif defined(_M_IX86)
 //#ifdef _MSC_VER
             asm ("movl $0, %eax\n\t"
                  "leave\n\t"
                  "ret");
 #elif defined(_M_IX86)
 //#ifdef _MSC_VER
+            trace("Executing MSVC x86 stack corruption code\n");
             __asm
               {
                  mov eax, 0
             __asm
               {
                  mov eax, 0
@@ -59,16 +64,22 @@ static LRESULT WINAPI redraw_window_procA(
                  ret
               }
 #else
                  ret
               }
 #else
-            trace("unimplemented\n");
+            ok(FALSE, "FIXME: stack corruption code is unimplemented\n");
 #endif
 #endif
+
+            break;
+        default:
+            trace("Doing empty default: msg = %u\n", msg);
     }
 
     }
 
+    trace("Calling DefWindowProc()\n");
     return DefWindowProc(hwnd, msg, wparam, lparam);
 }
 
 static void test_wndproc(void)
 {
     WNDCLASSA cls;
     return DefWindowProc(hwnd, msg, wparam, lparam);
 }
 
 static void test_wndproc(void)
 {
     WNDCLASSA cls;
+    ATOM clsAtom;
     HWND hwndMain;
 
     cls.style = CS_DBLCLKS;
     HWND hwndMain;
 
     cls.style = CS_DBLCLKS;
@@ -82,32 +93,54 @@ static void test_wndproc(void)
     cls.lpszMenuName = NULL;
     cls.lpszClassName = "RedrawWindowClass";
 
     cls.lpszMenuName = NULL;
     cls.lpszClassName = "RedrawWindowClass";
 
-    if (!RegisterClassA(&cls))
+    clsAtom = RegisterClassA(&cls);
+    ok(clsAtom != 0, "RegisterClassA() failed: LastError = %lu\n", GetLastError());
+
+    if (clsAtom == 0)
     {
     {
-        trace("Register failed %d\n", (int)GetLastError());
+        skip("No Class atom\n");
         return;
     }
 
         return;
     }
 
-    hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
+    hwndMain = CreateWindowA(cls.lpszClassName, "Main Window", WS_OVERLAPPEDWINDOW,
                              CW_USEDEFAULT, 0, 100, 100, NULL, NULL, NULL, NULL);
                              CW_USEDEFAULT, 0, 100, 100, NULL, NULL, NULL, NULL);
+    ok(hwndMain != NULL, "CreateWindowA() failed: LastError = %lu\n", GetLastError());
+
+    ok(WMPAINT_count == 0,
+       "Multiple unexpected WM_PAINT calls = %d\n", WMPAINT_count);
+
+    if (hwndMain == NULL)
+    {
+        skip("No Window\n");
+        ok(UnregisterClassA(cls.lpszClassName, cls.hInstance) != 0,
+           "UnregisterClassA() failed: LastError = %lu\n", GetLastError());
+        return;
+    }
 
 
-    ok(WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
     ShowWindow(hwndMain, SW_SHOW);
     ShowWindow(hwndMain, SW_SHOW);
-    ok(WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
+    ok(WMPAINT_count == 0,
+       "Multiple unexpected WM_PAINT calls = %d\n", WMPAINT_count);
+
     RedrawWindow(hwndMain, NULL, NULL, RDW_UPDATENOW | RDW_ALLCHILDREN);
     ok(WMPAINT_count == 1 || broken(WMPAINT_count == 0), /* sometimes on win9x */
     RedrawWindow(hwndMain, NULL, NULL, RDW_UPDATENOW | RDW_ALLCHILDREN);
     ok(WMPAINT_count == 1 || broken(WMPAINT_count == 0), /* sometimes on win9x */
-       "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
+       "Multiple unexpected WM_PAINT calls = %d\n", WMPAINT_count);
+
     redrawComplete = TRUE;
     redrawComplete = TRUE;
-    ok(WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
+    ok(WMPAINT_count < WMPAINT_COUNT_THRESHOLD,
+       "RedrawWindow (RDW_UPDATENOW) never completed (%d/%d)\n",
+       WMPAINT_count, WMPAINT_COUNT_THRESHOLD);
+
+    ok(DestroyWindow(hwndMain) != 0,
+       "DestroyWindow() failed: LastError = %lu\n", GetLastError());
 
 
-    /* clean up */
-    DestroyWindow(hwndMain);
+    ok(UnregisterClassA(cls.lpszClassName, cls.hInstance) != 0,
+       "UnregisterClassA() failed: LastError = %lu\n", GetLastError());
 }
 
 START_TEST(WndProc)
 {
 #ifdef __RUNTIME_CHECKS__
 }
 
 START_TEST(WndProc)
 {
 #ifdef __RUNTIME_CHECKS__
-    skip("This test breaks MSVC runtime checks!");
+    skip("This test breaks MSVC runtime checks!\n");
     return;
 #endif /* __RUNTIME_CHECKS__ */
 
     return;
 #endif /* __RUNTIME_CHECKS__ */