ddraw/tests: Move some surface attachment tests from refcount to dsurface and enhance them.

Octavian Voicu octavian.voicu at gmail.com
Mon Oct 31 12:50:33 CDT 2011


Fix failures on some video cards by using more common formats for the two
surfaces used in the attachment tests (offscreen + zbuffer).

Add a few extra tests to uncover some problems in Wine's attachment
implementation and mark them with todos.
---
 dlls/ddraw/tests/dsurface.c |   92 +++++++++++++++++++++++++++++++++++++
 dlls/ddraw/tests/refcount.c |  106 +-----------------------------------------
 2 files changed, 95 insertions(+), 103 deletions(-)

diff --git a/dlls/ddraw/tests/dsurface.c b/dlls/ddraw/tests/dsurface.c
index 3aefe52..202ca3b 100644
--- a/dlls/ddraw/tests/dsurface.c
+++ b/dlls/ddraw/tests/dsurface.c
@@ -1239,10 +1239,12 @@ static void AttachmentTest7(void)
     HRESULT hr;
     IDirectDraw7 *dd7;
     IDirectDrawSurface7 *surface1, *surface2, *surface3, *surface4;
+    IDirectDrawSurface *surface1v1, *surface2v1;
     DDSURFACEDESC2 ddsd, ddsd2;
     UINT num;
     DDSCAPS2 caps = {DDSCAPS_TEXTURE, 0, 0, 0}, caps2 = {DDSCAPS_BACKBUFFER,0,0,0};
     HWND window = CreateWindow( "static", "ddraw_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
+    DWORD ref;
 
     hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
     ok(hr == DD_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
@@ -1417,6 +1419,96 @@ static void AttachmentTest7(void)
     IDirectDrawSurface7_Release(surface2);
     IDirectDrawSurface7_Release(surface1);
 
+    /* AddAttachedSurface/DeleteAttachedSurface on multiple interfaces and automatic detachment */
+    memset(&ddsd, 0, sizeof(ddsd));
+    ddsd.dwSize = sizeof(ddsd);
+    ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
+    ddsd.dwWidth = 64;
+    ddsd.dwHeight = 64;
+    ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
+    U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
+    U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB; /* D3DFMT_R5G6B5 */
+    U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 16;
+    U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0xF800;
+    U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x07E0;
+    U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x001F;
+
+    memset(&ddsd2, 0, sizeof(ddsd2));
+    ddsd2.dwSize = sizeof(ddsd2);
+    ddsd2.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
+    ddsd2.dwWidth = ddsd.dwWidth;
+    ddsd2.dwHeight = ddsd.dwHeight;
+    ddsd2.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
+    U4(ddsd2).ddpfPixelFormat.dwSize = sizeof(U4(ddsd2).ddpfPixelFormat);
+    U4(ddsd2).ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
+    U1(U4(ddsd2).ddpfPixelFormat).dwZBufferBitDepth = 16;
+    U3(U4(ddsd2).ddpfPixelFormat).dwZBitMask = 0x0000FFFF;
+
+    hr = IDirectDraw7_CreateSurface(dd7, &ddsd, &surface1, NULL);
+    ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
+    if (SUCCEEDED(hr))
+    {
+        hr = IDirectDraw7_CreateSurface(dd7, &ddsd2, &surface2, NULL);
+        ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
+        if (SUCCEEDED(hr))
+        {
+            hr = IDirectDrawSurface7_QueryInterface(surface1, &IID_IDirectDrawSurface, (void **)&surface1v1);
+            ok(hr == DD_OK, "IDirectDrawSurface7_QueryInterface returned %08x\n", hr);
+            hr = IDirectDrawSurface7_QueryInterface(surface2, &IID_IDirectDrawSurface, (void **)&surface2v1);
+            ok(hr == DD_OK, "IDirectDrawSurface7_QueryInterface returned %08x\n", hr);
+
+            /* Attaching via IDirectDrawSurface7 */
+            hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
+            ok(hr == DD_OK, "AddAttachedSurface returned %08x\n", hr);
+            if (SUCCEEDED(hr))
+            {
+                ref = getRefcount((IUnknown *)surface2);
+                ok(ref == 2, "Got refcount %d, expected 2\n", ref);
+                ref = getRefcount((IUnknown *)surface2v1);
+                ok(ref == 1, "Got refcount %d, expected 1\n", ref);
+                hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
+                ok(hr == DDERR_SURFACEALREADYATTACHED, "AddAttachedSurface returned %08x\n", hr);
+                hr = IDirectDrawSurface_DeleteAttachedSurface(surface1v1, 0, surface2v1);
+                ok(hr == DDERR_SURFACENOTATTACHED, "DeleteAttachedSurface returned %08x\n", hr);
+                hr = IDirectDrawSurface7_DeleteAttachedSurface(surface1, 0, surface2);
+                ok(hr == DD_OK, "DeleteAttachedSurface returned %08x\n", hr);
+                ref = getRefcount((IUnknown *)surface2);
+                ok(ref == 1, "Got refcount %d, expected 2\n", ref);
+                ref = getRefcount((IUnknown *)surface2v1);
+                ok(ref == 1, "Got refcount %d, expected 1\n", ref);
+            }
+
+            /* Attaching via IDirectDrawSurface */
+            hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
+            ok(hr == DD_OK, "AddAttachedSurface returned %08x\n", hr);
+            if (SUCCEEDED(hr))
+            {
+                hr = IDirectDrawSurface7_DeleteAttachedSurface(surface1, 0, surface2);
+                ok(hr == DDERR_SURFACENOTATTACHED, "DeleteAttachedSurface returned %08x\n", hr);
+                hr = IDirectDrawSurface_DeleteAttachedSurface(surface1v1, 0, surface2v1);
+                ok(hr == DD_OK, "DeleteAttachedSurface returned %08x\n", hr);
+            }
+            ref = IDirectDrawSurface7_Release(surface2);
+            ok(!ref, "Got refcount %d, expected 0\n", ref);
+            ref = IDirectDrawSurface7_Release(surface1);
+            ok(!ref, "Got refcount %d, expected 0\n", ref);
+
+            /* Attaching via IDirectDrawSurface and automatic detachment on Release */
+            hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
+            ok(hr == DD_OK, "AddAttachedSurface returned %08x\n", hr);
+            ref = getRefcount((IUnknown *)surface2v1);
+            ok(ref == 2, "Got refcount %d, expected 2\n", ref);
+            ref = IDirectDrawSurface_Release(surface1v1);
+            ok(!ref, "Got refcount %d, expected 0\n", ref);
+            ref = getRefcount((IUnknown *)surface2v1);
+            ok(ref == 1, "Got refcount %d, expected 1\n", ref);
+            ref = IDirectDrawSurface_Release(surface2v1);
+            ok(!ref, "Got refcount %d, expected 0\n", ref);
+        }
+        else
+            IDirectDrawSurface7_Release(surface1);
+    }
+
     hr =IDirectDraw7_SetCooperativeLevel(dd7, NULL, DDSCL_NORMAL);
     ok(hr == DD_OK, "SetCooperativeLevel returned %08x\n", hr);
     IDirectDraw7_Release(dd7);
diff --git a/dlls/ddraw/tests/refcount.c b/dlls/ddraw/tests/refcount.c
index cf94986..970865e 100644
--- a/dlls/ddraw/tests/refcount.c
+++ b/dlls/ddraw/tests/refcount.c
@@ -47,11 +47,11 @@ static void test_ddraw_objects(void)
     IDirectDraw2 *DDraw2;
     IDirectDraw  *DDraw1;
     IDirectDrawPalette *palette;
-    IDirectDrawSurface7 *surface = NULL, *stencil;
-    IDirectDrawSurface *surface1, *stencil1;
+    IDirectDrawSurface7 *surface = NULL;
+    IDirectDrawSurface *surface1;
     IDirectDrawSurface4 *surface4;
     PALETTEENTRY Table[256];
-    DDSURFACEDESC2 ddsd, ddsd_stencil;
+    DDSURFACEDESC2 ddsd;
 
     hr = pDirectDrawCreateEx(NULL, (void **) &DDraw7, &IID_IDirectDraw7, NULL);
     ok(hr == DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", hr);
@@ -92,17 +92,6 @@ static void test_ddraw_objects(void)
     U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
     U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 8;
 
-    memset(&ddsd_stencil, 0, sizeof(ddsd_stencil));
-    ddsd_stencil.dwSize = sizeof(ddsd_stencil);
-    ddsd_stencil.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
-    ddsd_stencil.dwWidth = ddsd.dwWidth;
-    ddsd_stencil.dwHeight = ddsd.dwHeight;
-    ddsd_stencil.ddsCaps.dwCaps = DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER;
-    U4(ddsd_stencil).ddpfPixelFormat.dwSize = sizeof(U4(ddsd_stencil).ddpfPixelFormat);
-    U4(ddsd_stencil).ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
-    U1(U4(ddsd_stencil).ddpfPixelFormat).dwZBufferBitDepth = 16;
-    U3(U4(ddsd_stencil).ddpfPixelFormat).dwZBitMask = 0x0000FFFF;
-
     hr = IDirectDraw7_CreateSurface(DDraw7, &ddsd, &surface, NULL);
     if (!surface)
     {
@@ -197,95 +186,6 @@ static void test_ddraw_objects(void)
     ok(ref == 1, "Got refcount %d, expected 1\n", ref);
     IDirectDrawSurface_Release(surface1);
 
-    /* AddAttachedSurface with IDirectDrawSurface7 */
-    ddsd.dwSize = sizeof(DDSURFACEDESC2);
-    ddsd.ddsCaps.dwCaps |= DDSCAPS_3DDEVICE;
-    hr = IDirectDraw7_CreateSurface(DDraw7, &ddsd, &surface, NULL);
-    ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
-    if (SUCCEEDED(hr))
-    {
-        ddsd_stencil.dwSize = sizeof(DDSURFACEDESC2);
-        hr = IDirectDraw7_CreateSurface(DDraw7, &ddsd_stencil, &stencil, NULL);
-        ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
-        if (SUCCEEDED(hr))
-        {
-            /* AddAttachedSurface with DeleteAttachedSurface */
-            hr = IDirectDrawSurface7_AddAttachedSurface(surface, stencil);
-            ok(hr == DD_OK, "AddAttachedSurface returned %08x\n", hr);
-            if (SUCCEEDED(hr))
-            {
-                ref = getRefcount( (IUnknown *) stencil);
-                ok(ref == 2, "Got refcount %d, expected 2\n", ref);
-                hr = IDirectDrawSurface7_QueryInterface(surface, &IID_IDirectDrawSurface, (void **) &surface1);
-                ok(hr == DD_OK, "IDirectDrawSurface7_QueryInterface returned %08x\n", hr);
-                hr = IDirectDrawSurface7_QueryInterface(stencil, &IID_IDirectDrawSurface, (void **) &stencil1);
-                ok(hr == DD_OK, "IDirectDrawSurface7_QueryInterface returned %08x\n", hr);
-                hr = IDirectDrawSurface_DeleteAttachedSurface(surface1, 0, stencil1);
-                ok(hr == DDERR_SURFACENOTATTACHED, "DeleteAttachedSurface returned %08x\n", hr);
-                if (stencil1 != NULL) IDirectDrawSurface_Release(stencil1);
-                if (surface1 != NULL) IDirectDrawSurface_Release(surface1);
-                hr = IDirectDrawSurface7_DeleteAttachedSurface(surface, 0, stencil);
-                ok(hr == DD_OK, "DeleteAttachedSurface returned %08x\n", hr);
-                ref = getRefcount( (IUnknown *) stencil);
-                ok(ref == 1, "Got refcount %d, expected 1\n", ref);
-            }
-
-            /* Releasing a surface should detach any attached surfaces */
-            hr = IDirectDrawSurface7_AddAttachedSurface(surface, stencil);
-            ok(hr == DD_OK, "AddAttachedSurface returned %08x\n", hr);
-            ref = getRefcount( (IUnknown *) stencil);
-            ok(ref == 2, "Got refcount %d, expected 2\n", ref);
-            ref = IDirectDrawSurface7_Release(surface);
-            ok(!ref, "Got refcount %d, expected 0\n", ref);
-            ref = getRefcount( (IUnknown *) stencil);
-            ok(ref == 1, "Got refcount %d, expected 1\n", ref);
-            ref = IDirectDrawSurface7_Release(stencil);
-            ok(!ref, "Got refcount %d, expected 0\n", ref);
-        }
-        else
-            IDirectDrawSurface7_Release(surface);
-    }
-
-    /* AddAttachedSurface with IDirectDrawSurface */
-    ddsd.dwSize = sizeof(DDSURFACEDESC);
-    hr = IDirectDraw_CreateSurface(DDraw1, (DDSURFACEDESC *) &ddsd, &surface1, NULL);
-    ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
-    if (SUCCEEDED(hr))
-    {
-        ddsd_stencil.dwSize = sizeof(DDSURFACEDESC);
-        hr = IDirectDraw_CreateSurface(DDraw1, (DDSURFACEDESC *) &ddsd_stencil, &stencil1, NULL);
-        ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
-        if (SUCCEEDED(hr))
-        {
-            /* AddAttachedSurface with DeleteAttachedSurface */
-            hr = IDirectDrawSurface_AddAttachedSurface(surface1, stencil1);
-            ok(hr == DD_OK, "AddAttachedSurface returned %08x\n", hr);
-            if (SUCCEEDED(hr))
-            {
-                ref = getRefcount( (IUnknown *) stencil1);
-                ok(ref == 2, "Got refcount %d, expected 2\n", ref);
-                hr = IDirectDrawSurface_DeleteAttachedSurface(surface1, 0, stencil1);
-                ok(hr == DD_OK, "DeleteAttachedSurface returned %08x\n", hr);
-                ref = getRefcount( (IUnknown *) stencil1);
-                ok(ref == 1, "Got refcount %d, expected 1\n", ref);
-            }
-
-            /* Releasing a surface should detach any attached surfaces */
-            hr = IDirectDrawSurface_AddAttachedSurface(surface1, stencil1);
-            ok(hr == DD_OK, "AddAttachedSurface returned %08x\n", hr);
-            ref = getRefcount( (IUnknown *) stencil1);
-            ok(ref == 2, "Got refcount %d, expected 2\n", ref);
-            ref = IDirectDrawSurface_Release(surface1);
-            ok(!ref, "Got refcount %d, expected 0\n", ref);
-            ref = getRefcount( (IUnknown *) stencil1);
-            ok(ref == 1, "Got refcount %d, expected 1\n", ref);
-            ref = IDirectDrawSurface_Release(stencil1);
-            ok(!ref, "Got refcount %d, expected 0\n", ref);
-        }
-        else
-            IDirectDrawSurface_Release(surface1);
-    }
-
     IDirectDraw7_Release(DDraw7);
     IDirectDraw4_Release(DDraw4);
     IDirectDraw2_Release(DDraw2);
-- 
1.7.4.1




More information about the wine-patches mailing list