From e0a64fd8bf6da4f7bd1c1285b4f51b7eb6279f7d Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Sun, 15 Nov 2009 13:54:31 -0600 Subject: [PATCH] ddraw/tests: Add test for refcounts of surface objects. --- dlls/ddraw/tests/refcount.c | 100 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 100 insertions(+), 0 deletions(-) diff --git a/dlls/ddraw/tests/refcount.c b/dlls/ddraw/tests/refcount.c index 9ad560b..62709d4 100644 --- a/dlls/ddraw/tests/refcount.c +++ b/dlls/ddraw/tests/refcount.c @@ -325,6 +325,105 @@ static void test_iface_refcnt(void) IDirect3D7_Release(D3D7); } +static void test_surface_refcnt(void) +{ + HRESULT hr; + IDirectDraw7 *DDraw7; + IDirectDrawSurface7 *surface7 = NULL; + IDirectDrawSurface4 *surface4; + IDirectDrawSurface3 *surface3; + IDirectDrawSurface2 *surface2; + IDirectDrawSurface *surface1; + IDirectDrawGammaControl *surface_gamma; + DDSURFACEDESC2 ddsd; + long ref; + + hr = pDirectDrawCreateEx(NULL, (void **) &DDraw7, &IID_IDirectDraw7, NULL); + ok(hr == DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", hr); + if(!DDraw7) + { + trace("Couldn't create DDraw interface, skipping tests\n"); + return; + } + + hr = IDirectDraw7_SetCooperativeLevel(DDraw7, 0, DDSCL_NORMAL); + ok(hr == DD_OK, "SetCooperativeLevel failed with %08x\n", hr); + + 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; + U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat); + U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB; + U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 8; + + hr = IDirectDraw7_CreateSurface(DDraw7, &ddsd, &surface7, NULL); + if (!surface7) + { + win_skip("Could not create surface : %08x\n", hr); + IDirectDraw7_Release(DDraw7); + return; + } + ok(hr == DD_OK, "CreateSurface failed with %08x\n", hr); + + ref = getRefcount( (IUnknown *) surface7); + ok(ref == 1, "Initial IDirectDrawSurface7 reference count is %ld\n", ref); + + hr = IDirectDrawSurface7_QueryInterface(surface7, &IID_IDirectDrawSurface4, (void **) &surface4); + ok(hr == DD_OK, "IDirectDrawSurface7_QueryInterface returned %08x\n", hr); + hr = IDirectDrawSurface7_QueryInterface(surface7, &IID_IDirectDrawSurface3, (void **) &surface3); + ok(hr == DD_OK, "IDirectDrawSurface7_QueryInterface returned %08x\n", hr); + hr = IDirectDrawSurface7_QueryInterface(surface7, &IID_IDirectDrawSurface2, (void **) &surface2); + ok(hr == DD_OK, "IDirectDrawSurface7_QueryInterface returned %08x\n", hr); + hr = IDirectDrawSurface7_QueryInterface(surface7, &IID_IDirectDrawSurface, (void **) &surface1); + ok(hr == DD_OK, "IDirectDrawSurface7_QueryInterface returned %08x\n", hr); + hr = IDirectDrawSurface7_QueryInterface(surface7, &IID_IDirectDrawGammaControl, (void **) &surface_gamma); + ok(hr == DD_OK, "IDirectDrawSurface7_QueryInterface returned %08x\n", hr); + +todo_wine { + /* All interfaces now have refcount 1! */ + ref = getRefcount( (IUnknown *) surface7); + ok(ref == 1, "IDirectDraw7 reference count is %ld\n", ref); + ref = getRefcount( (IUnknown *) surface4); + ok(ref == 1, "IDirectDraw4 reference count is %ld\n", ref); + ref = getRefcount( (IUnknown *) surface3); + ok(ref == 1, "IDirectDraw3 reference count is %ld\n", ref); + ref = getRefcount( (IUnknown *) surface2); + ok(ref == 1, "IDirectDraw2 reference count is %ld\n", ref); + ref = getRefcount( (IUnknown *) surface1); + ok(ref == 1, "IDirectDraw reference count is %ld\n", ref); + ref = getRefcount( (IUnknown *) surface_gamma); + ok(ref == 1, "IDirectDrawGammaControl reference count is %ld\n", ref); +} + +todo_wine { + /* Try an AddRef, it only affects the AddRefed interface */ + IDirectDrawSurface4_AddRef(surface4); + ref = getRefcount( (IUnknown *) surface7); + ok(ref == 1, "IDirectDraw7 reference count is %ld\n", ref); + ref = getRefcount( (IUnknown *) surface4); + ok(ref == 2, "IDirectDraw4 reference count is %ld\n", ref); + ref = getRefcount( (IUnknown *) surface3); + ok(ref == 1, "IDirectDraw3 reference count is %ld\n", ref); + ref = getRefcount( (IUnknown *) surface2); + ok(ref == 1, "IDirectDraw2 reference count is %ld\n", ref); + ref = getRefcount( (IUnknown *) surface1); + ok(ref == 1, "IDirectDraw reference count is %ld\n", ref); + ref = getRefcount( (IUnknown *) surface_gamma); + ok(ref == 1, "IDirectDrawGammaControl reference count is %ld\n", ref); +} + + /* All done, release all interfaces */ + IDirectDrawSurface7_Release(surface7); + IDirectDrawSurface4_Release(surface4); + IDirectDrawSurface3_Release(surface3); + IDirectDrawSurface2_Release(surface2); + IDirectDrawSurface_Release(surface1); + IDirectDrawGammaControl_Release(surface_gamma); +} + static void test_d3d_ifaces(void) { IDirectDraw *DDraw1; @@ -463,5 +562,6 @@ START_TEST(refcount) } test_ddraw_objects(); test_iface_refcnt(); + test_surface_refcnt(); test_d3d_ifaces(); } -- 1.6.3.3