[PATCH 5/5] ddraw/tests: Port test_private_data to ddraw4.

Stefan Dösinger stefan at codeweavers.com
Thu Feb 13 16:10:07 CST 2014


---
 dlls/ddraw/tests/ddraw4.c   | 86 +++++++++++++++++++++++++++++++++++++++++++++
 dlls/ddraw/tests/ddraw7.c   | 86 +++++++++++++++++++++++++++++++++++++++++++++
 dlls/ddraw/tests/dsurface.c | 73 --------------------------------------
 3 files changed, 172 insertions(+), 73 deletions(-)

diff --git a/dlls/ddraw/tests/ddraw4.c b/dlls/ddraw/tests/ddraw4.c
index a189dcb..c768a95 100644
--- a/dlls/ddraw/tests/ddraw4.c
+++ b/dlls/ddraw/tests/ddraw4.c
@@ -6124,6 +6124,91 @@ static void test_surface_attachment(void)
     DestroyWindow(window);
 }
 
+static void test_private_data(void)
+{
+    IDirectDraw4 *ddraw;
+    IDirectDrawSurface4 *surface;
+    DDSURFACEDESC2 surface_desc;
+    ULONG refcount, refcount2, refcount3;
+    IUnknown *ptr;
+    DWORD size = sizeof(ptr);
+    HRESULT hr;
+    HWND window;
+
+    if (!(ddraw = create_ddraw()))
+    {
+        skip("Failed to create a ddraw object, skipping test.\n");
+        return;
+    }
+
+    window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
+            0, 0, 640, 480, 0, 0, 0, 0);
+    hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
+    ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+    reset_ddsd(&surface_desc);
+    surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
+    surface_desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
+    surface_desc.dwHeight = 4;
+    surface_desc.dwWidth = 4;
+    hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
+    ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
+
+    /* DDSPD_IUNKNOWNPOINTER needs sizeof(IUnknown *) bytes of data. */
+    hr = IDirectDrawSurface4_SetPrivateData(surface, &IID_IDirect3D, ddraw,
+            0, DDSPD_IUNKNOWNPOINTER);
+    ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
+    hr = IDirectDrawSurface4_SetPrivateData(surface, &IID_IDirect3D, ddraw,
+            5, DDSPD_IUNKNOWNPOINTER);
+    ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
+    hr = IDirectDrawSurface4_SetPrivateData(surface, &IID_IDirect3D, ddraw,
+            sizeof(ddraw) * 2, DDSPD_IUNKNOWNPOINTER);
+    ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
+
+    refcount = get_refcount((IUnknown *)ddraw);
+    hr = IDirectDrawSurface4_SetPrivateData(surface, &IID_IDirect3D, ddraw,
+            sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
+    ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
+    refcount2 = get_refcount((IUnknown *)ddraw);
+    ok(refcount2 == refcount + 1, "Got unexpected refcount %u.\n", refcount2);
+
+    hr = IDirectDrawSurface4_FreePrivateData(surface, &IID_IDirect3D);
+    ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
+    refcount2 = get_refcount((IUnknown *)ddraw);
+    ok(refcount2 == refcount, "Got unexpected refcount %u.\n", refcount2);
+
+    hr = IDirectDrawSurface4_SetPrivateData(surface, &IID_IDirect3D, ddraw,
+            sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
+    ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
+    hr = IDirectDrawSurface4_SetPrivateData(surface, &IID_IDirect3D, surface,
+            sizeof(surface), DDSPD_IUNKNOWNPOINTER);
+    ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
+    refcount2 = get_refcount((IUnknown *)ddraw);
+    ok(refcount2 == refcount, "Got unexpected refcount %u.\n", refcount2);
+
+    hr = IDirectDrawSurface4_SetPrivateData(surface, &IID_IDirect3D, ddraw,
+            sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
+    ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
+    hr = IDirectDrawSurface4_GetPrivateData(surface, &IID_IDirect3D, &ptr, &size);
+    ok(SUCCEEDED(hr), "Failed to get private data, hr %#x.\n", hr);
+    refcount2 = get_refcount(ptr);
+    /* Object is NOT addref'ed by the getter. */
+    ok(ptr == (IUnknown *)ddraw, "Returned interface pointer is %p, expected %p.\n", ptr, ddraw);
+    ok(refcount2 == refcount + 1, "Got unexpected refcount %u.\n", refcount2);
+
+    refcount3 = IDirectDrawSurface4_Release(surface);
+    ok(!refcount3, "Got unexpected refcount %u.\n", refcount3);
+
+    /* Destroying the surface frees the reference held on the private data. It also frees
+     * the reference the surface is holding on its creating object. */
+    refcount2 = get_refcount((IUnknown *)ddraw);
+    ok(refcount2 == refcount - 1, "Got unexpected refcount %u.\n", refcount2);
+
+    refcount = IDirectDraw4_Release(ddraw);
+    ok(!refcount, "Got unexpected refcount %u.\n", refcount);
+    DestroyWindow(window);
+}
+
 START_TEST(ddraw4)
 {
     test_process_vertices();
@@ -6168,4 +6253,5 @@ START_TEST(ddraw4)
     test_sysmem_overlay();
     test_primary_palette();
     test_surface_attachment();
+    test_private_data();
 }
diff --git a/dlls/ddraw/tests/ddraw7.c b/dlls/ddraw/tests/ddraw7.c
index 2a681f1..2d00284 100644
--- a/dlls/ddraw/tests/ddraw7.c
+++ b/dlls/ddraw/tests/ddraw7.c
@@ -5979,6 +5979,91 @@ static void test_surface_attachment(void)
     DestroyWindow(window);
 }
 
+static void test_private_data(void)
+{
+    IDirectDraw7 *ddraw;
+    IDirectDrawSurface7 *surface;
+    DDSURFACEDESC2 surface_desc;
+    ULONG refcount, refcount2, refcount3;
+    IUnknown *ptr;
+    DWORD size = sizeof(ptr);
+    HRESULT hr;
+    HWND window;
+
+    if (!(ddraw = create_ddraw()))
+    {
+        skip("Failed to create a ddraw object, skipping test.\n");
+        return;
+    }
+
+    window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
+            0, 0, 640, 480, 0, 0, 0, 0);
+    hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
+    ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+    reset_ddsd(&surface_desc);
+    surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
+    surface_desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
+    surface_desc.dwHeight = 4;
+    surface_desc.dwWidth = 4;
+    hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
+    ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
+
+    /* DDSPD_IUNKNOWNPOINTER needs sizeof(IUnknown *) bytes of data. */
+    hr = IDirectDrawSurface7_SetPrivateData(surface, &IID_IDirect3D, ddraw,
+            0, DDSPD_IUNKNOWNPOINTER);
+    ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
+    hr = IDirectDrawSurface7_SetPrivateData(surface, &IID_IDirect3D, ddraw,
+            5, DDSPD_IUNKNOWNPOINTER);
+    ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
+    hr = IDirectDrawSurface7_SetPrivateData(surface, &IID_IDirect3D, ddraw,
+            sizeof(ddraw) * 2, DDSPD_IUNKNOWNPOINTER);
+    ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
+
+    refcount = get_refcount((IUnknown *)ddraw);
+    hr = IDirectDrawSurface7_SetPrivateData(surface, &IID_IDirect3D, ddraw,
+            sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
+    ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
+    refcount2 = get_refcount((IUnknown *)ddraw);
+    ok(refcount2 == refcount + 1, "Got unexpected refcount %u.\n", refcount2);
+
+    hr = IDirectDrawSurface7_FreePrivateData(surface, &IID_IDirect3D);
+    ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
+    refcount2 = get_refcount((IUnknown *)ddraw);
+    ok(refcount2 == refcount, "Got unexpected refcount %u.\n", refcount2);
+
+    hr = IDirectDrawSurface7_SetPrivateData(surface, &IID_IDirect3D, ddraw,
+            sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
+    ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
+    hr = IDirectDrawSurface7_SetPrivateData(surface, &IID_IDirect3D, surface,
+            sizeof(surface), DDSPD_IUNKNOWNPOINTER);
+    ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
+    refcount2 = get_refcount((IUnknown *)ddraw);
+    ok(refcount2 == refcount, "Got unexpected refcount %u.\n", refcount2);
+
+    hr = IDirectDrawSurface7_SetPrivateData(surface, &IID_IDirect3D, ddraw,
+            sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
+    ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
+    hr = IDirectDrawSurface7_GetPrivateData(surface, &IID_IDirect3D, &ptr, &size);
+    ok(SUCCEEDED(hr), "Failed to get private data, hr %#x.\n", hr);
+    refcount2 = get_refcount(ptr);
+    /* Object is NOT addref'ed by the getter. */
+    ok(ptr == (IUnknown *)ddraw, "Returned interface pointer is %p, expected %p.\n", ptr, ddraw);
+    ok(refcount2 == refcount + 1, "Got unexpected refcount %u.\n", refcount2);
+
+    refcount3 = IDirectDrawSurface7_Release(surface);
+    ok(!refcount3, "Got unexpected refcount %u.\n", refcount3);
+
+    /* Destroying the surface frees the reference held on the private data. It also frees
+     * the reference the surface is holding on its creating object. */
+    refcount2 = get_refcount((IUnknown *)ddraw);
+    ok(refcount2 == refcount - 1, "Got unexpected refcount %u.\n", refcount2);
+
+    refcount = IDirectDraw7_Release(ddraw);
+    ok(!refcount, "Got unexpected refcount %u.\n", refcount);
+    DestroyWindow(window);
+}
+
 START_TEST(ddraw7)
 {
     HMODULE module = GetModuleHandleA("ddraw.dll");
@@ -6031,4 +6116,5 @@ START_TEST(ddraw7)
     test_sysmem_overlay();
     test_primary_palette();
     test_surface_attachment();
+    test_private_data();
 }
diff --git a/dlls/ddraw/tests/dsurface.c b/dlls/ddraw/tests/dsurface.c
index 3494f82..e8a9c1e 100644
--- a/dlls/ddraw/tests/dsurface.c
+++ b/dlls/ddraw/tests/dsurface.c
@@ -2020,78 +2020,6 @@ static void SizeTest(void)
     ok(ret == DD_OK, "SetCooperativeLevel failed with %08x\n", ret);
 }
 
-static void PrivateDataTest(void)
-{
-    HRESULT hr;
-    IDirectDrawSurface7 *surface7 = NULL;
-    IDirectDrawSurface *surface = NULL;
-    DDSURFACEDESC desc;
-    ULONG ref, ref2;
-    IUnknown *ptr;
-    DWORD size = sizeof(IUnknown *);
-
-    ZeroMemory(&desc, sizeof(desc));
-    desc.dwSize = sizeof(desc);
-    desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
-    desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
-    desc.dwHeight = 128;
-    desc.dwWidth = 128;
-    hr = IDirectDraw_CreateSurface(lpDD, &desc, &surface, NULL);
-    ok(hr == DD_OK, "Creating an offscreen plain surface failed with %08x\n", hr);
-    if(!surface)
-    {
-        return;
-    }
-    hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface7, (void **) &surface7);
-    ok(hr == DD_OK, "IDirectDrawSurface_QueryInterface failed with %08x\n", hr);
-    if(!surface7)
-    {
-        IDirectDrawSurface_Release(surface);
-        return;
-    }
-
-    /* This fails */
-    hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7 /* Abuse this tag */, lpDD, 0, DDSPD_IUNKNOWNPOINTER);
-    ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
-    hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7 /* Abuse this tag */, lpDD, 5, DDSPD_IUNKNOWNPOINTER);
-    ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
-    hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7 /* Abuse this tag */, lpDD, sizeof(IUnknown *) * 2, DDSPD_IUNKNOWNPOINTER);
-    ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
-
-    ref = getref((IUnknown *) lpDD);
-    hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7 /* Abuse this tag */, lpDD, sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
-    ok(hr == DD_OK, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
-    ref2 = getref((IUnknown *) lpDD);
-    ok(ref2 == ref + 1, "Object reference is %d, expected %d\n", ref2, ref + 1);
-    hr = IDirectDrawSurface7_FreePrivateData(surface7, &IID_IDirectDrawSurface7);
-    ok(SUCCEEDED(hr), "IDirectDrawSurface7_FreePrivateData returned %#x.\n", hr);
-    ref2 = getref((IUnknown *) lpDD);
-    ok(ref2 == ref, "Object reference is %d, expected %d\n", ref2, ref);
-
-    hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7, lpDD, sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
-    ok(hr == DD_OK, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
-    hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7, surface7, sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
-    ok(hr == DD_OK, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
-    ref2 = getref((IUnknown *) lpDD);
-    ok(ref2 == ref, "Object reference is %d, expected %d\n", ref2, ref);
-
-    hr = IDirectDrawSurface7_SetPrivateData(surface7, &IID_IDirectDrawSurface7, lpDD, sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
-    ok(hr == DD_OK, "IDirectDrawSurface7_SetPrivateData failed with %08x\n", hr);
-    hr = IDirectDrawSurface7_GetPrivateData(surface7, &IID_IDirectDrawSurface7, &ptr, &size);
-    ok(hr == DD_OK, "IDirectDrawSurface7_GetPrivateData failed with %08x\n", hr);
-    ref2 = getref((IUnknown *) lpDD);
-    /* Object is NOT being addrefed */
-    ok(ptr == (IUnknown *) lpDD, "Returned interface pointer is %p, expected %p\n", ptr, lpDD);
-    ok(ref2 == ref + 1, "Object reference is %d, expected %d. ptr at %p, orig at %p\n", ref2, ref + 1, ptr, lpDD);
-
-    IDirectDrawSurface_Release(surface);
-    IDirectDrawSurface7_Release(surface7);
-
-    /* Destroying the surface frees the held reference */
-    ref2 = getref((IUnknown *) lpDD);
-    ok(ref2 == ref, "Object reference is %d, expected %d\n", ref2, ref);
-}
-
 static void BltParamTest(void)
 {
     IDirectDrawSurface *surface1 = NULL, *surface2 = NULL;
@@ -4029,7 +3957,6 @@ START_TEST(dsurface)
     test_lockrect_invalid();
     CompressedTest();
     SizeTest();
-    PrivateDataTest();
     BltParamTest();
     StructSizeTest();
     PaletteTest();
-- 
1.8.3.2




More information about the wine-patches mailing list