[PATCH 2/2] ddraw/tests: Test WM_ACTIVATEAPP messages generated by SetCooperativeLevel
Stefan Dösinger
stefan at codeweavers.com
Thu Aug 29 04:14:06 CDT 2013
---
dlls/ddraw/tests/ddraw1.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++
dlls/ddraw/tests/ddraw2.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++
dlls/ddraw/tests/ddraw4.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++
dlls/ddraw/tests/ddraw7.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 544 insertions(+)
diff --git a/dlls/ddraw/tests/ddraw1.c b/dlls/ddraw/tests/ddraw1.c
index 22d71c6..a088d64 100644
--- a/dlls/ddraw/tests/ddraw1.c
+++ b/dlls/ddraw/tests/ddraw1.c
@@ -2791,6 +2791,141 @@ static void test_clear_rect_count(void)
DestroyWindow(window);
}
+BOOL activateapp_received;
+IDirectDraw *activateapp_ddraw;
+HWND activateapp_window;
+DWORD activateapp_coop_level;
+
+static LRESULT CALLBACK activateapp_test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
+{
+ if (message == WM_ACTIVATEAPP)
+ {
+ if (activateapp_ddraw)
+ {
+ HRESULT hr;
+ activateapp_received = FALSE;
+ hr = IDirectDraw7_SetCooperativeLevel(activateapp_ddraw,
+ activateapp_window, activateapp_coop_level);
+ ok(SUCCEEDED(hr), "Recursive SetCooperativeLevel call failed, hr %#x.\n", hr);
+ ok(!activateapp_received, "Received WM_ACTIVATEAPP during recursive SetCooperativeLevel call\n");
+ }
+ activateapp_received = TRUE;
+ }
+
+ return DefWindowProcA(hwnd, message, wparam, lparam);
+}
+
+static void test_coop_level_activateapp(void)
+{
+ IDirectDraw *ddraw;
+ HRESULT hr;
+ HWND window;
+ WNDCLASSA wc = {0};
+ DDSURFACEDESC ddsd;
+ IDirectDrawSurface *surface;
+
+ if (!(ddraw = create_ddraw()))
+ {
+ skip("Failed to create IDirectDraw object, skipping tests.\n");
+ return;
+ }
+
+ wc.lpfnWndProc = activateapp_test_proc;
+ wc.lpszClassName = "ddraw_test_wndproc_wc";
+ ok(RegisterClassA(&wc), "Failed to register window class.\n");
+
+ window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
+ WS_MAXIMIZE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
+
+ /* Exclusive with window already active */
+ SetActiveWindow(window);
+ activateapp_received = FALSE;
+ hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ ok(!activateapp_received, "Received WM_ACTIVATEAPP although window was already active\n");
+ hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+ /* Exclusive with window not active */
+ SetActiveWindow(NULL);
+ activateapp_received = FALSE;
+ hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ ok(activateapp_received, "Expected WM_ACTIVATEAPP, but did not receive it\n");
+ hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+ /* Normal with window not active, then exclusive with the same window */
+ SetActiveWindow(NULL);
+ activateapp_received = FALSE;
+ hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ ok(!activateapp_received, "Received WM_ACTIVATEAPP when setting DDSCL_NORMAL\n");
+ hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ /* Except in the first SetCooperativeLevel call, Windows XP randomly does not send
+ * WM_ACTIVATEAPP. Windows 7 sends the message reliably. Mark the XP behavior broken */
+ ok(activateapp_received || broken(!activateapp_received),
+ "Expected WM_ACTIVATEAPP, but did not receive it\n");
+ hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+ /* Recursive set of DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN */
+ SetActiveWindow(NULL);
+ activateapp_received = FALSE;
+ activateapp_ddraw = ddraw;
+ activateapp_window = window;
+ activateapp_coop_level = DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN;
+ hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ ok(activateapp_received || broken(!activateapp_received),
+ "Expected WM_ACTIVATEAPP, but did not receive it\n");
+ hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+ /* The recursive call seems to have some bad effect on native ddraw, despite (apparently)
+ * succeeding. Another switch to exclusive and back to normal is needed to release the
+ * window properly. Without doing this, SetCooperativeLevel(EXCLUSIVE) will not send
+ * WM_ACTIVATEAPP messages. */
+ activateapp_ddraw = NULL;
+ hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+ /* Setting DDSCL_NORMAL with recursive invocation */
+ SetActiveWindow(NULL);
+ activateapp_received = FALSE;
+ activateapp_ddraw = ddraw;
+ activateapp_window = window;
+ activateapp_coop_level = DDSCL_NORMAL;
+ hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ ok(activateapp_received || broken(!activateapp_received),
+ "Expected WM_ACTIVATEAPP, but did not receive it\n");
+
+ /* DDraw is in exlusive mode now */
+ memset(&ddsd, 0, sizeof(ddsd));
+ ddsd.dwSize = sizeof(ddsd);
+ ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
+ ddsd.dwBackBufferCount = 1;
+ ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
+ hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
+ ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
+ IDirectDrawSurface_Release(surface);
+
+ /* Recover again, just to be sure */
+ activateapp_ddraw = NULL;
+ hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+ DestroyWindow(window);
+ UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
+ IDirectDraw_Release(ddraw);
+}
+
START_TEST(ddraw1)
{
test_coop_level_create_device_window();
@@ -2813,4 +2948,5 @@ START_TEST(ddraw1)
test_coop_level_surf_create();
test_coop_level_multi_window();
test_clear_rect_count();
+ test_coop_level_activateapp();
}
diff --git a/dlls/ddraw/tests/ddraw2.c b/dlls/ddraw/tests/ddraw2.c
index 1220b65..36a3ead 100644
--- a/dlls/ddraw/tests/ddraw2.c
+++ b/dlls/ddraw/tests/ddraw2.c
@@ -3375,6 +3375,141 @@ static void test_lighting_interface_versions(void)
ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
}
+BOOL activateapp_received;
+IDirectDraw2 *activateapp_ddraw;
+HWND activateapp_window;
+DWORD activateapp_coop_level;
+
+static LRESULT CALLBACK activateapp_test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
+{
+ if (message == WM_ACTIVATEAPP)
+ {
+ if (activateapp_ddraw)
+ {
+ HRESULT hr;
+ activateapp_received = FALSE;
+ hr = IDirectDraw7_SetCooperativeLevel(activateapp_ddraw,
+ activateapp_window, activateapp_coop_level);
+ ok(SUCCEEDED(hr), "Recursive SetCooperativeLevel call failed, hr %#x.\n", hr);
+ ok(!activateapp_received, "Received WM_ACTIVATEAPP during recursive SetCooperativeLevel call\n");
+ }
+ activateapp_received = TRUE;
+ }
+
+ return DefWindowProcA(hwnd, message, wparam, lparam);
+}
+
+static void test_coop_level_activateapp(void)
+{
+ IDirectDraw2 *ddraw;
+ HRESULT hr;
+ HWND window;
+ WNDCLASSA wc = {0};
+ DDSURFACEDESC ddsd;
+ IDirectDrawSurface *surface;
+
+ if (!(ddraw = create_ddraw()))
+ {
+ skip("Failed to create IDirectDraw2 object, skipping tests.\n");
+ return;
+ }
+
+ wc.lpfnWndProc = activateapp_test_proc;
+ wc.lpszClassName = "ddraw_test_wndproc_wc";
+ ok(RegisterClassA(&wc), "Failed to register window class.\n");
+
+ window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
+ WS_MAXIMIZE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
+
+ /* Exclusive with window already active */
+ SetActiveWindow(window);
+ activateapp_received = FALSE;
+ hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ ok(!activateapp_received, "Received WM_ACTIVATEAPP although window was already active\n");
+ hr = IDirectDraw2_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+ /* Exclusive with window not active */
+ SetActiveWindow(NULL);
+ activateapp_received = FALSE;
+ hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ ok(activateapp_received, "Expected WM_ACTIVATEAPP, but did not receive it\n");
+ hr = IDirectDraw2_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+ /* Normal with window not active, then exclusive with the same window */
+ SetActiveWindow(NULL);
+ activateapp_received = FALSE;
+ hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ ok(!activateapp_received, "Received WM_ACTIVATEAPP when setting DDSCL_NORMAL\n");
+ hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ /* Except in the first SetCooperativeLevel call, Windows XP randomly does not send
+ * WM_ACTIVATEAPP. Windows 7 sends the message reliably. Mark the XP behavior broken */
+ ok(activateapp_received || broken(!activateapp_received),
+ "Expected WM_ACTIVATEAPP, but did not receive it\n");
+ hr = IDirectDraw2_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+ /* Recursive set of DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN */
+ SetActiveWindow(NULL);
+ activateapp_received = FALSE;
+ activateapp_ddraw = ddraw;
+ activateapp_window = window;
+ activateapp_coop_level = DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN;
+ hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ ok(activateapp_received || broken(!activateapp_received),
+ "Expected WM_ACTIVATEAPP, but did not receive it\n");
+ hr = IDirectDraw2_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+ /* The recursive call seems to have some bad effect on native ddraw, despite (apparently)
+ * succeeding. Another switch to exclusive and back to normal is needed to release the
+ * window properly. Without doing this, SetCooperativeLevel(EXCLUSIVE) will not send
+ * WM_ACTIVATEAPP messages. */
+ activateapp_ddraw = NULL;
+ hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ hr = IDirectDraw2_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+ /* Setting DDSCL_NORMAL with recursive invocation */
+ SetActiveWindow(NULL);
+ activateapp_received = FALSE;
+ activateapp_ddraw = ddraw;
+ activateapp_window = window;
+ activateapp_coop_level = DDSCL_NORMAL;
+ hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ ok(activateapp_received || broken(!activateapp_received),
+ "Expected WM_ACTIVATEAPP, but did not receive it\n");
+
+ /* DDraw is in exlusive mode now */
+ memset(&ddsd, 0, sizeof(ddsd));
+ ddsd.dwSize = sizeof(ddsd);
+ ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
+ ddsd.dwBackBufferCount = 1;
+ ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
+ hr = IDirectDraw2_CreateSurface(ddraw, &ddsd, &surface, NULL);
+ ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
+ IDirectDrawSurface_Release(surface);
+
+ /* Recover again, just to be sure */
+ activateapp_ddraw = NULL;
+ hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ hr = IDirectDraw2_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+ DestroyWindow(window);
+ UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
+ IDirectDraw2_Release(ddraw);
+}
+
START_TEST(ddraw2)
{
test_coop_level_create_device_window();
@@ -3401,4 +3536,5 @@ START_TEST(ddraw2)
test_clear_rect_count();
test_coop_level_versions();
test_lighting_interface_versions();
+ test_coop_level_activateapp();
}
diff --git a/dlls/ddraw/tests/ddraw4.c b/dlls/ddraw/tests/ddraw4.c
index 9597c8b..11eb724 100644
--- a/dlls/ddraw/tests/ddraw4.c
+++ b/dlls/ddraw/tests/ddraw4.c
@@ -3681,6 +3681,141 @@ static void test_lighting_interface_versions(void)
ok(ref == 0, "D3d not properly released, refcount %u.\n", ref);
}
+BOOL activateapp_received;
+IDirectDraw4 *activateapp_ddraw;
+HWND activateapp_window;
+DWORD activateapp_coop_level;
+
+static LRESULT CALLBACK activateapp_test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
+{
+ if (message == WM_ACTIVATEAPP)
+ {
+ if (activateapp_ddraw)
+ {
+ HRESULT hr;
+ activateapp_received = FALSE;
+ hr = IDirectDraw7_SetCooperativeLevel(activateapp_ddraw,
+ activateapp_window, activateapp_coop_level);
+ ok(SUCCEEDED(hr), "Recursive SetCooperativeLevel call failed, hr %#x.\n", hr);
+ ok(!activateapp_received, "Received WM_ACTIVATEAPP during recursive SetCooperativeLevel call\n");
+ }
+ activateapp_received = TRUE;
+ }
+
+ return DefWindowProcA(hwnd, message, wparam, lparam);
+}
+
+static void test_coop_level_activateapp(void)
+{
+ IDirectDraw4 *ddraw;
+ HRESULT hr;
+ HWND window;
+ WNDCLASSA wc = {0};
+ DDSURFACEDESC2 ddsd;
+ IDirectDrawSurface4 *surface;
+
+ if (!(ddraw = create_ddraw()))
+ {
+ skip("Failed to create IDirectDraw4 object, skipping tests.\n");
+ return;
+ }
+
+ wc.lpfnWndProc = activateapp_test_proc;
+ wc.lpszClassName = "ddraw_test_wndproc_wc";
+ ok(RegisterClassA(&wc), "Failed to register window class.\n");
+
+ window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
+ WS_MAXIMIZE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
+
+ /* Exclusive with window already active */
+ SetActiveWindow(window);
+ activateapp_received = FALSE;
+ hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ ok(!activateapp_received, "Received WM_ACTIVATEAPP although window was already active\n");
+ hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+ /* Exclusive with window not active */
+ SetActiveWindow(NULL);
+ activateapp_received = FALSE;
+ hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ ok(activateapp_received, "Expected WM_ACTIVATEAPP, but did not receive it\n");
+ hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+ /* Normal with window not active, then exclusive with the same window */
+ SetActiveWindow(NULL);
+ activateapp_received = FALSE;
+ hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ ok(!activateapp_received, "Received WM_ACTIVATEAPP when setting DDSCL_NORMAL\n");
+ hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ /* Except in the first SetCooperativeLevel call, Windows XP randomly does not send
+ * WM_ACTIVATEAPP. Windows 7 sends the message reliably. Mark the XP behavior broken */
+ ok(activateapp_received || broken(!activateapp_received),
+ "Expected WM_ACTIVATEAPP, but did not receive it\n");
+ hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+ /* Recursive set of DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN */
+ SetActiveWindow(NULL);
+ activateapp_received = FALSE;
+ activateapp_ddraw = ddraw;
+ activateapp_window = window;
+ activateapp_coop_level = DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN;
+ hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ ok(activateapp_received || broken(!activateapp_received),
+ "Expected WM_ACTIVATEAPP, but did not receive it\n");
+ hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+ /* The recursive call seems to have some bad effect on native ddraw, despite (apparently)
+ * succeeding. Another switch to exclusive and back to normal is needed to release the
+ * window properly. Without doing this, SetCooperativeLevel(EXCLUSIVE) will not send
+ * WM_ACTIVATEAPP messages. */
+ activateapp_ddraw = NULL;
+ hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+ /* Setting DDSCL_NORMAL with recursive invocation */
+ SetActiveWindow(NULL);
+ activateapp_received = FALSE;
+ activateapp_ddraw = ddraw;
+ activateapp_window = window;
+ activateapp_coop_level = DDSCL_NORMAL;
+ hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ ok(activateapp_received || broken(!activateapp_received),
+ "Expected WM_ACTIVATEAPP, but did not receive it\n");
+
+ /* DDraw is in exlusive mode now */
+ memset(&ddsd, 0, sizeof(ddsd));
+ ddsd.dwSize = sizeof(ddsd);
+ ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
+ ddsd.dwBackBufferCount = 1;
+ ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
+ hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
+ ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
+ IDirectDrawSurface4_Release(surface);
+
+ /* Recover again, just to be sure */
+ activateapp_ddraw = NULL;
+ hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+ DestroyWindow(window);
+ UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
+ IDirectDraw4_Release(ddraw);
+}
+
START_TEST(ddraw4)
{
test_process_vertices();
@@ -3710,4 +3845,5 @@ START_TEST(ddraw4)
test_clear_rect_count();
test_coop_level_versions();
test_lighting_interface_versions();
+ test_coop_level_activateapp();
}
diff --git a/dlls/ddraw/tests/ddraw7.c b/dlls/ddraw/tests/ddraw7.c
index 45017f2..5f41dac 100644
--- a/dlls/ddraw/tests/ddraw7.c
+++ b/dlls/ddraw/tests/ddraw7.c
@@ -3495,6 +3495,141 @@ static void test_lighting_interface_versions(void)
ok(ref == 0, "Device not properly released, refcount %u.\n", ref);
}
+BOOL activateapp_received;
+IDirectDraw7 *activateapp_ddraw;
+HWND activateapp_window;
+DWORD activateapp_coop_level;
+
+static LRESULT CALLBACK activateapp_test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
+{
+ if (message == WM_ACTIVATEAPP)
+ {
+ if (activateapp_ddraw)
+ {
+ HRESULT hr;
+ activateapp_received = FALSE;
+ hr = IDirectDraw7_SetCooperativeLevel(activateapp_ddraw,
+ activateapp_window, activateapp_coop_level);
+ ok(SUCCEEDED(hr), "Recursive SetCooperativeLevel call failed, hr %#x.\n", hr);
+ ok(!activateapp_received, "Received WM_ACTIVATEAPP during recursive SetCooperativeLevel call\n");
+ }
+ activateapp_received = TRUE;
+ }
+
+ return DefWindowProcA(hwnd, message, wparam, lparam);
+}
+
+static void test_coop_level_activateapp(void)
+{
+ IDirectDraw7 *ddraw;
+ HRESULT hr;
+ HWND window;
+ WNDCLASSA wc = {0};
+ DDSURFACEDESC2 ddsd;
+ IDirectDrawSurface7 *surface;
+
+ if (!(ddraw = create_ddraw()))
+ {
+ skip("Failed to create IDirectDraw7 object, skipping tests.\n");
+ return;
+ }
+
+ wc.lpfnWndProc = activateapp_test_proc;
+ wc.lpszClassName = "ddraw_test_wndproc_wc";
+ ok(RegisterClassA(&wc), "Failed to register window class.\n");
+
+ window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
+ WS_MAXIMIZE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
+
+ /* Exclusive with window already active */
+ SetActiveWindow(window);
+ activateapp_received = FALSE;
+ hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ ok(!activateapp_received, "Received WM_ACTIVATEAPP although window was already active\n");
+ hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+ /* Exclusive with window not active */
+ SetActiveWindow(NULL);
+ activateapp_received = FALSE;
+ hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ ok(activateapp_received, "Expected WM_ACTIVATEAPP, but did not receive it\n");
+ hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+ /* Normal with window not active, then exclusive with the same window */
+ SetActiveWindow(NULL);
+ activateapp_received = FALSE;
+ hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ ok(!activateapp_received, "Received WM_ACTIVATEAPP when setting DDSCL_NORMAL\n");
+ hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ /* Except in the first SetCooperativeLevel call, Windows XP randomly does not send
+ * WM_ACTIVATEAPP. Windows 7 sends the message reliably. Mark the XP behavior broken */
+ ok(activateapp_received || broken(!activateapp_received),
+ "Expected WM_ACTIVATEAPP, but did not receive it\n");
+ hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+ /* Recursive set of DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN */
+ SetActiveWindow(NULL);
+ activateapp_received = FALSE;
+ activateapp_ddraw = ddraw;
+ activateapp_window = window;
+ activateapp_coop_level = DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN;
+ hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ ok(activateapp_received || broken(!activateapp_received),
+ "Expected WM_ACTIVATEAPP, but did not receive it\n");
+ hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+ /* The recursive call seems to have some bad effect on native ddraw, despite (apparently)
+ * succeeding. Another switch to exclusive and back to normal is needed to release the
+ * window properly. Without doing this, SetCooperativeLevel(EXCLUSIVE) will not send
+ * WM_ACTIVATEAPP messages. */
+ activateapp_ddraw = NULL;
+ hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+ /* Setting DDSCL_NORMAL with recursive invocation */
+ SetActiveWindow(NULL);
+ activateapp_received = FALSE;
+ activateapp_ddraw = ddraw;
+ activateapp_window = window;
+ activateapp_coop_level = DDSCL_NORMAL;
+ hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ ok(activateapp_received || broken(!activateapp_received),
+ "Expected WM_ACTIVATEAPP, but did not receive it\n");
+
+ /* DDraw is in exlusive mode now */
+ memset(&ddsd, 0, sizeof(ddsd));
+ ddsd.dwSize = sizeof(ddsd);
+ ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
+ ddsd.dwBackBufferCount = 1;
+ ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
+ hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
+ ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
+ IDirectDrawSurface7_Release(surface);
+
+ /* Recover again, just to be sure */
+ activateapp_ddraw = NULL;
+ hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+ DestroyWindow(window);
+ UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
+ IDirectDraw7_Release(ddraw);
+}
+
START_TEST(ddraw7)
{
HMODULE module = GetModuleHandleA("ddraw.dll");
@@ -3532,4 +3667,5 @@ START_TEST(ddraw7)
test_coop_level_versions();
test_fog_special();
test_lighting_interface_versions();
+ test_coop_level_activateapp();
}
--
1.8.1.5
More information about the wine-patches
mailing list