Commit 6e7bb649 authored by Octavian Voicu's avatar Octavian Voicu Committed by Alexandre Julliard

ddraw/tests: Move surface attachment tests from refcount.c to dsurface.c.

parent 8c41a3bd
......@@ -1239,7 +1239,9 @@ static void AttachmentTest7(void)
HRESULT hr;
IDirectDraw7 *dd7;
IDirectDrawSurface7 *surface1, *surface2, *surface3, *surface4;
IDirectDrawSurface *surface1v1, *surface2v1;
DDSURFACEDESC2 ddsd, ddsd2;
DWORD ref;
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 );
......@@ -1417,6 +1419,73 @@ static void AttachmentTest7(void)
IDirectDrawSurface7_Release(surface2);
IDirectDrawSurface7_Release(surface1);
/* Test DeleteAttachedSurface and automatic detachment of attached surfaces on release */
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_PALETTEINDEXED8 | DDPF_RGB;
U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 8;
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_3DDEVICE | 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))
{
/* DeleteAttachedSurface */
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);
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);
hr = IDirectDrawSurface_DeleteAttachedSurface(surface1v1, 0, surface2v1);
ok(hr == DDERR_SURFACENOTATTACHED, "DeleteAttachedSurface returned %08x\n", hr);
if (surface2v1 != NULL) IDirectDrawSurface_Release(surface2v1);
if (surface1v1 != NULL) IDirectDrawSurface_Release(surface1v1);
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 1\n", ref);
}
/* Automatic detachment on release */
hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
ok(hr == DD_OK, "AddAttachedSurface returned %08x\n", hr);
ref = getRefcount((IUnknown *)surface2);
ok(ref == 2, "Got refcount %d, expected 2\n", ref);
ref = IDirectDrawSurface7_Release(surface1);
ok(!ref, "Got refcount %d, expected 0\n", ref);
ref = getRefcount((IUnknown *)surface2);
ok(ref == 1, "Got refcount %d, expected 1\n", ref);
ref = IDirectDrawSurface7_Release(surface2);
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);
......@@ -1426,7 +1495,8 @@ static void AttachmentTest(void)
{
HRESULT hr;
IDirectDrawSurface *surface1, *surface2, *surface3, *surface4;
DDSURFACEDESC ddsd;
DDSURFACEDESC ddsd, ddsd2;
DWORD ref;
DDSCAPS caps = {DDSCAPS_TEXTURE};
BOOL refrast = FALSE;
HWND window = CreateWindow( "static", "ddraw_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
......@@ -1623,6 +1693,65 @@ static void AttachmentTest(void)
IDirectDrawSurface_Release(surface2);
IDirectDrawSurface_Release(surface1);
/* Test DeleteAttachedSurface and automatic detachment of attached surfaces on release */
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_PALETTEINDEXED8 | DDPF_RGB;
U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 8;
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_3DDEVICE | 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 = IDirectDraw_CreateSurface(lpDD, (DDSURFACEDESC *)&ddsd, &surface1, NULL);
ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
if (SUCCEEDED(hr))
{
hr = IDirectDraw_CreateSurface(lpDD, (DDSURFACEDESC *)&ddsd2, &surface2, NULL);
ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
if (SUCCEEDED(hr))
{
/* DeleteAttachedSurface */
hr = IDirectDrawSurface_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);
hr = IDirectDrawSurface_DeleteAttachedSurface(surface1, 0, surface2);
ok(hr == DD_OK, "DeleteAttachedSurface returned %08x\n", hr);
ref = getRefcount((IUnknown *)surface2);
ok(ref == 1, "Got refcount %d, expected 1\n", ref);
}
/* Automatic detachment on release */
hr = IDirectDrawSurface_AddAttachedSurface(surface1, surface2);
ok(hr == DD_OK, "AddAttachedSurface returned %08x\n", hr);
ref = getRefcount((IUnknown *)surface2);
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 *)surface2);
ok(ref == 1, "Got refcount %d, expected 1\n", ref);
ref = IDirectDrawSurface_Release(surface2);
ok(!ref, "Got refcount %d, expected 0\n", ref);
}
else
IDirectDrawSurface_Release(surface1);
}
hr =IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
ok(hr == DD_OK, "SetCooperativeLevel returned %08x\n", hr);
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment