>From 7f17f29050ec5d96ef0316f9663af6f944b3c1c4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20D=C3=B6singer?= <stefan@codeweavers.com>
Date: Tue, 23 Sep 2014 21:19:57 +0200
Subject: [PATCH 8/8] d3d9/tests: Test messages on focus loss.
Reply-To: wine-devel <wine-devel@winehq.org>

---
 dlls/d3d9/device.c       |  2 +-
 dlls/d3d9/tests/device.c | 62 +++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 52 insertions(+), 12 deletions(-)

diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c
index c6bab8f..ab38e31 100644
--- a/dlls/d3d9/device.c
+++ b/dlls/d3d9/device.c
@@ -3472,7 +3472,7 @@ static void CDECL device_parent_activate(struct wined3d_device_parent *device_pa
             {
                 swapchain = wined3d_device_get_swapchain(device->wined3d_device, i);
                 wined3d_swapchain_get_desc(swapchain, &desc);
-                ShowWindow(desc.device_window, SW_MINIMIZE);
+                ShowWindow(desc.device_window, SW_SHOWMINIMIZED);
             }
         }
     }
diff --git a/dlls/d3d9/tests/device.c b/dlls/d3d9/tests/device.c
index 0dbef33..675c1b4 100644
--- a/dlls/d3d9/tests/device.c
+++ b/dlls/d3d9/tests/device.c
@@ -3058,6 +3058,8 @@ struct message
 {
     UINT message;
     enum message_window window;
+    BOOL check_wparam;
+    WPARAM expect_wparam1, expect_wparam2;
 };
 
 static const struct message *expect_messages;
@@ -3098,7 +3100,15 @@ static LRESULT CALLBACK test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM
                 break;
         };
 
-        if (hwnd == w && expect_messages->message == message) ++expect_messages;
+
+        if (hwnd == w && expect_messages->message == message)
+        {
+            if (expect_messages->check_wparam)
+                ok(wparam == expect_messages->expect_wparam1 || wparam == expect_messages->expect_wparam2,
+                        "Got unexpected wparam %lx for message %x.\n", wparam, message);
+
+            ++expect_messages;
+        }
     }
 
     return DefWindowProcA(hwnd, message, wparam, lparam);
@@ -3148,12 +3158,23 @@ static void test_wndproc(void)
     DWORD res, tid;
     HWND tmp;
 
-    static const struct message messages[] =
+    static const struct message create_messages[] =
     {
-        {WM_WINDOWPOSCHANGING,  FOCUS_WINDOW},
-        {WM_ACTIVATE,           FOCUS_WINDOW},
-        {WM_SETFOCUS,           FOCUS_WINDOW},
-        {0,                     0},
+        {WM_WINDOWPOSCHANGING,  FOCUS_WINDOW,   FALSE,  0,                      0},
+        {WM_ACTIVATE,           FOCUS_WINDOW,   FALSE,  0,                      0},
+        {WM_SETFOCUS,           FOCUS_WINDOW,   FALSE,  0,                      0},
+        {0,                     0,              FALSE,  0,                      0},
+    };
+    static const struct message focus_loss_messages[] =
+    {
+        {WM_ACTIVATE,           FOCUS_WINDOW,   TRUE,   0,                      0},
+        {WM_ACTIVATEAPP,        DEVICE_WINDOW,  TRUE,   0,                      0},
+        {WM_WINDOWPOSCHANGING,  DEVICE_WINDOW,  FALSE,  0,                      0},
+        {WM_ACTIVATE,           DEVICE_WINDOW,  TRUE,   0x200000 | WA_ACTIVE,   0x10000 | WA_ACTIVE},
+        {WM_WINDOWPOSCHANGED,   DEVICE_WINDOW,  FALSE,  0,                      0},
+        {WM_SIZE,               DEVICE_WINDOW,  TRUE,   SIZE_MINIMIZED,         SIZE_MINIMIZED},
+        {WM_ACTIVATEAPP,        FOCUS_WINDOW,   TRUE,   0,                      0},
+        {0,                     0,              FALSE,  0,                      0},
     };
 
     d3d9 = Direct3DCreate9(D3D_SDK_VERSION);
@@ -3201,7 +3222,7 @@ static void test_wndproc(void)
 
     flush_events();
 
-    expect_messages = messages;
+    expect_messages = create_messages;
 
     device = create_device(d3d9, device_window, focus_window, FALSE);
     if (!device)
@@ -3224,8 +3245,6 @@ static void test_wndproc(void)
     SetForegroundWindow(focus_window);
     flush_events();
 
-    filter_messages = focus_window;
-
     proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
     ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
             (LONG_PTR)test_proc, proc);
@@ -3234,6 +3253,27 @@ static void test_wndproc(void)
     ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
             (LONG_PTR)test_proc, proc);
 
+    filter_messages = NULL;
+    expect_messages = focus_loss_messages;
+    SetForegroundWindow(GetDesktopWindow());
+    ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
+            expect_messages->message, expect_messages->window);
+    expect_messages = NULL;
+
+    proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
+    ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
+        (LONG_PTR)test_proc, proc);
+
+    proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
+    ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
+        (LONG_PTR)test_proc, proc);
+
+    SetForegroundWindow(focus_window);
+    flush_events();
+
+    filter_messages = focus_window;
+    reset_device(device, device_window, FALSE);
+
     ref = IDirect3DDevice9_Release(device);
     ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
 
@@ -3489,8 +3529,8 @@ static void test_reset_fullscreen(void)
     ATOM atom;
     static const struct message messages[] =
     {
-        {WM_ACTIVATEAPP,    FOCUS_WINDOW},
-        {0,                     0},
+        {WM_ACTIVATEAPP,    FOCUS_WINDOW,   FALSE,  0,  0},
+        {0,                 0               FALSE,  0,  0},
     };
 
     d3d = Direct3DCreate9(D3D_SDK_VERSION);
-- 
1.8.5.5

