Any problems with patch?

A+

David

---------- Forwarded message ----------
From: David Adam <david.adam.c...@gmail.com>
Date: 2010/10/24
Subject: ddraw: Add tests for the foreground window set by
SetCooperativeLevel
To: wine-patches <wine-patc...@winehq.org>
From e929b17027bebd7eb466d7e8b71efd270889e713 Mon Sep 17 00:00:00 2001
From: David Adam <david.adam.c...@gmail.com>
Date: Sun, 24 Oct 2010 08:44:51 +0200
Subject: Add tests for the foreground window set by SetCooperativeLevel

---
 dlls/ddraw/tests/ddrawmodes.c |  178 +++++++++++++++++++++++++++++++++++------
 1 files changed, 154 insertions(+), 24 deletions(-)

diff --git a/dlls/ddraw/tests/ddrawmodes.c b/dlls/ddraw/tests/ddrawmodes.c
index b6491f3..c41302a 100644
--- a/dlls/ddraw/tests/ddrawmodes.c
+++ b/dlls/ddraw/tests/ddrawmodes.c
@@ -33,8 +33,9 @@ static LPDIRECTDRAW lpDD = NULL;
 static LPDIRECTDRAWSURFACE lpDDSPrimary = NULL;
 static LPDIRECTDRAWSURFACE lpDDSBack = NULL;
 static WNDCLASS wc;
-static HWND hwnd;
+static HWND hwnd, hwnd2;
 static int modes_cnt;
+static BOOL success;
 static int modes_size;
 static LPDDSURFACEDESC modes;
 static RECT rect_before_create;
@@ -54,31 +55,19 @@ static void init_function_pointers(void)
     pDirectDrawEnumerateExW = (void*)GetProcAddress(hmod, "DirectDrawEnumerateExW");
 }
 
-static void createwindow(void)
+static BOOL createwindow(HWND *hwnd)
 {
-    wc.style = CS_HREDRAW | CS_VREDRAW;
-    wc.lpfnWndProc = DefWindowProcA;
-    wc.cbClsExtra = 0;
-    wc.cbWndExtra = 0;
-    wc.hInstance = GetModuleHandleA(0);
-    wc.hIcon = LoadIconA(wc.hInstance, IDI_APPLICATION);
-    wc.hCursor = LoadCursorA(NULL, IDC_ARROW);
-    wc.hbrBackground = GetStockObject(BLACK_BRUSH);
-    wc.lpszMenuName = NULL;
-    wc.lpszClassName = "TestWindowClass";
-    if(!RegisterClassA(&wc))
-        assert(0);
-
-    hwnd = CreateWindowExA(0, "TestWindowClass", "TestWindowClass",
+    *hwnd = CreateWindowExA(0, "TestWindowClass", "TestWindowClass",
         WS_POPUP, 0, 0,
         GetSystemMetrics(SM_CXSCREEN),
         GetSystemMetrics(SM_CYSCREEN),
         NULL, NULL, GetModuleHandleA(0), NULL);
-    assert(hwnd != NULL);
 
-    ShowWindow(hwnd, SW_HIDE);
-    UpdateWindow(hwnd);
-    SetFocus(hwnd);
+    ShowWindow(*hwnd, SW_HIDE);
+    UpdateWindow(*hwnd);
+    SetFocus(*hwnd);
+
+    return (*hwnd != NULL);
 }
 
 static BOOL createdirectdraw(void)
@@ -546,6 +535,7 @@ static void testdisplaymodes(void)
 
 static void testcooperativelevels_normal(void)
 {
+    BOOL sfw;
     HRESULT rc;
     DDSURFACEDESC surfacedesc;
     IDirectDrawSurface *surface = (IDirectDrawSurface *) 0xdeadbeef;
@@ -561,11 +551,34 @@ static void testcooperativelevels_normal(void)
     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW) returned: %x\n",rc);
 
     /* Do some tests with DDSCL_NORMAL mode */
+
     /* Fullscreen mode + normal mode + exclusive mode */
+    sfw=FALSE;
+
+    if(success)
+    {
+        sfw=SetForegroundWindow(hwnd2);
+    }
+    else
+    {
+        skip("Failed to create the second window\n");
+    }
+
     rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NORMAL);
     todo_wine ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NORMAL) returned: %x\n",rc);
+
+    if(sfw)
+    {
+        todo_wine ok(GetForegroundWindow()==hwnd,"Expected the main windows (%p) for foreground, received the second one (%p)\n",hwnd, hwnd2);
+    }
+    else
+    {
+        skip("Failed to set the second window for foreground\n");
+    }
+
     /* Try creating a double buffered primary in fullscreen + exclusive + normal mode */
     rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
+
     if (rc == DDERR_UNSUPPORTEDMODE)
         skip("Unsupported mode\n");
     else
@@ -574,12 +587,35 @@ static void testcooperativelevels_normal(void)
         todo_wine ok(surface!=NULL, "Returned NULL surface pointer \n");
     }
     if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
+
     /* Exclusive mode + normal mode */
     rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_EXCLUSIVE | DDSCL_NORMAL);
     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_NORMAL) returned: %x\n",rc);
+
     /* Fullscreen mode + normal mode */
+    sfw=FALSE;
+
+    if(success)
+    {
+        sfw=SetForegroundWindow(hwnd2);
+    }
+    else
+    {
+        skip("Failed to create the second window\n");
+    }
+
     rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_FULLSCREEN | DDSCL_NORMAL);
     todo_wine ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_FULLSCREEN | DDSCL_NORMAL) returned: %x\n",rc);
+
+    if(sfw)
+    {
+        ok(GetForegroundWindow()==hwnd2,"Expected the second windows (%p) for foreground, received the main one (%p)\n",hwnd2, hwnd);
+    }
+    else
+    {
+        skip("Failed to set the second window for foreground\n");
+    }
+
     /* Try creating a double buffered primary in fullscreen + normal mode */
     rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
     if (rc == DDERR_UNSUPPORTEDMODE)
@@ -589,12 +625,34 @@ static void testcooperativelevels_normal(void)
         ok(rc == DDERR_NOEXCLUSIVEMODE, "IDirectDraw_CreateSurface returned %08x\n", rc);
         ok(surface == NULL, "Returned surface pointer is %p\n", surface);
     }
+
     if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
-    /* Normal mode */
+
+    /* switching from Fullscreen mode to Normal mode */
+    sfw=FALSE;
+
+    if(success)
+    {
+        sfw=SetForegroundWindow(hwnd2);
+    }
+    else
+    {
+        skip("Failed to create the second window\n");
+    }
+
     rc = IDirectDraw_SetCooperativeLevel(lpDD,
         hwnd, DDSCL_NORMAL);
     ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL) returned: %x\n",rc);
 
+    if(sfw)
+    {
+        ok(GetForegroundWindow()==hwnd2,"Expected the second windows (%p) for foreground, received the main one (%p)\n",hwnd2, hwnd);
+    }
+    else
+    {
+        skip("Failed to set the second window for foreground\n");
+    }
+
     /* Try creating a double buffered primary in normal mode */
     rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
     if (rc == DDERR_UNSUPPORTEDMODE)
@@ -606,6 +664,31 @@ static void testcooperativelevels_normal(void)
     }
     if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
 
+    /* switching from Normal mode to Fullscreen + Normal mode */
+    sfw=FALSE;
+
+    if(success)
+    {
+        sfw=SetForegroundWindow(hwnd2);
+    }
+    else
+    {
+        skip("Failed to create the second window\n");
+    }
+
+    rc = IDirectDraw_SetCooperativeLevel(lpDD,
+        hwnd, DDSCL_NORMAL | DDSCL_FULLSCREEN);
+    todo_wine ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL | FULLSCREEN) returned: %x\n",rc);
+
+    if(sfw)
+    {
+        ok(GetForegroundWindow()==hwnd2,"Expected the second windows (%p) for foreground, received the main one (%p)\n",hwnd2, hwnd);
+    }
+    else
+    {
+        skip("Failed to set the second window for foreground\n");
+    }
+
     /* Set the focus window */
 
     rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW);
@@ -681,7 +764,7 @@ static void testcooperativelevels_normal(void)
 
 static void testcooperativelevels_exclusive(void)
 {
-    BOOL success;
+    BOOL sfw;
     HRESULT rc;
     RECT window_rect;
 
@@ -702,11 +785,32 @@ static void testcooperativelevels_exclusive(void)
     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FULLSCREEN) returned: %x\n",rc);
 
     /* Full screen mode + exclusive mode */
+    sfw=FALSE;
+
+    if(success)
+    {
+        sfw=SetForegroundWindow(hwnd2);
+    }
+    else
+    {
+        skip("Failed to create the second window\n");
+    }
+
     rc = IDirectDraw_SetCooperativeLevel(lpDD,
         hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
     ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN) returned: %x\n",rc);
-    GetClientRect(hwnd, &window_rect);
+
+    if(sfw)
+    {
+        ok(GetForegroundWindow()==hwnd,"Expected the main windows (%p) for foreground, received the second one (%p)\n",hwnd, hwnd2);
+    }
+    else
+    {
+        skip("Failed to set the second window for foreground\n");
+    }
+
     /* rect_before_create is assumed to hold the screen rect */
+    GetClientRect(hwnd, &window_rect);
     rc = EqualRect(&rect_before_create, &window_rect);
     todo_wine ok(rc!=0, "Fullscreen window has wrong size\n");
 
@@ -783,9 +887,35 @@ START_TEST(ddrawmodes)
 {
     init_function_pointers();
 
-    createwindow();
+    wc.style = CS_HREDRAW | CS_VREDRAW;
+    wc.lpfnWndProc = DefWindowProcA;
+    wc.cbClsExtra = 0;
+    wc.cbWndExtra = 0;
+    wc.hInstance = GetModuleHandleA(0);
+    wc.hIcon = LoadIconA(wc.hInstance, IDI_APPLICATION);
+    wc.hCursor = LoadCursorA(NULL, IDC_ARROW);
+    wc.hbrBackground = GetStockObject(BLACK_BRUSH);
+    wc.lpszMenuName = NULL;
+    wc.lpszClassName = "TestWindowClass";
+    if (!RegisterClassA(&wc))
+    {
+        skip("RegisterClassA failed\n");
+        return;
+    }
+
+    if (!createwindow(&hwnd))
+    {
+        skip("Failed to create the main window\n");
+        return;
+    }
+
+    success=createwindow(&hwnd2);
+
     if (!createdirectdraw())
+    {
+        skip("Failed to create the direct draw object\n");
         return;
+    }
 
     test_DirectDrawEnumerateA();
     test_DirectDrawEnumerateW();
-- 
1.7.1



Reply via email to