2006-06-17 15:47:52 +02:00
|
|
|
/*
|
|
|
|
* Some unit tests for ddraw reference counting
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Stefan Dösinger
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
#include "ddraw.h"
|
|
|
|
#include "d3d.h"
|
|
|
|
#include "unknwn.h"
|
|
|
|
|
|
|
|
static HRESULT (WINAPI *pDirectDrawCreateEx)(LPGUID,LPVOID*,REFIID,LPUNKNOWN);
|
|
|
|
|
|
|
|
static void init_function_pointers(void)
|
|
|
|
{
|
|
|
|
HMODULE hmod = GetModuleHandleA("ddraw.dll");
|
2007-03-28 10:00:28 +02:00
|
|
|
pDirectDrawCreateEx = (void*)GetProcAddress(hmod, "DirectDrawCreateEx");
|
2006-06-17 15:47:52 +02:00
|
|
|
}
|
|
|
|
|
2009-03-19 11:22:15 +01:00
|
|
|
static ULONG getRefcount(IUnknown *iface)
|
2006-06-17 15:47:52 +02:00
|
|
|
{
|
|
|
|
IUnknown_AddRef(iface);
|
|
|
|
return IUnknown_Release(iface);
|
|
|
|
}
|
|
|
|
|
2006-07-10 16:06:33 +02:00
|
|
|
static void test_ddraw_objects(void)
|
2006-06-17 15:47:52 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
2009-03-19 11:22:15 +01:00
|
|
|
ULONG ref;
|
2006-07-10 10:53:11 +02:00
|
|
|
IDirectDraw7 *DDraw7;
|
|
|
|
IDirectDraw4 *DDraw4;
|
2007-02-16 19:08:09 +01:00
|
|
|
IDirectDraw2 *DDraw2;
|
|
|
|
IDirectDraw *DDraw1;
|
2006-06-17 15:47:52 +02:00
|
|
|
IDirectDrawPalette *palette;
|
2011-11-03 12:32:09 +01:00
|
|
|
IDirectDrawSurface7 *surface = NULL;
|
|
|
|
IDirectDrawSurface *surface1;
|
2007-02-16 19:08:09 +01:00
|
|
|
IDirectDrawSurface4 *surface4;
|
2006-06-17 15:47:52 +02:00
|
|
|
PALETTEENTRY Table[256];
|
2011-11-03 12:32:09 +01:00
|
|
|
DDSURFACEDESC2 ddsd;
|
2006-06-17 15:47:52 +02:00
|
|
|
|
2006-07-10 10:53:11 +02:00
|
|
|
hr = pDirectDrawCreateEx(NULL, (void **) &DDraw7, &IID_IDirectDraw7, NULL);
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", hr);
|
2006-07-10 10:53:11 +02:00
|
|
|
if(!DDraw7)
|
2006-06-17 15:47:52 +02:00
|
|
|
{
|
|
|
|
trace("Couldn't create DDraw interface, skipping tests\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-07-10 10:53:11 +02:00
|
|
|
hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirectDraw4, (void **) &DDraw4);
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);
|
2006-07-10 10:53:11 +02:00
|
|
|
hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirectDraw2, (void **) &DDraw2);
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);
|
2006-07-10 10:53:11 +02:00
|
|
|
hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirectDraw, (void **) &DDraw1);
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);
|
2006-07-10 10:53:11 +02:00
|
|
|
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw7);
|
2009-03-19 11:22:15 +01:00
|
|
|
ok(ref == 1, "Got refcount %d, expected 1\n", ref);
|
2006-06-17 15:47:52 +02:00
|
|
|
|
|
|
|
/* Fails without a cooplevel */
|
2006-07-10 10:53:11 +02:00
|
|
|
hr = IDirectDraw7_CreatePalette(DDraw7, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == DDERR_NOCOOPERATIVELEVELSET, "CreatePalette returned %08x\n", hr);
|
2006-06-17 15:47:52 +02:00
|
|
|
|
|
|
|
/* This check is before the cooplevel check */
|
2006-07-10 10:53:11 +02:00
|
|
|
hr = IDirectDraw7_CreatePalette(DDraw7, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, (void *) 0xdeadbeef);
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == CLASS_E_NOAGGREGATION, "CreatePalette returned %08x\n", hr);
|
2006-06-17 15:47:52 +02:00
|
|
|
|
2006-07-10 10:53:11 +02:00
|
|
|
hr = IDirectDraw7_SetCooperativeLevel(DDraw7, 0, DDSCL_NORMAL);
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == DD_OK, "SetCooperativeLevel failed with %08x\n", hr);
|
2006-06-17 15:47:52 +02:00
|
|
|
|
|
|
|
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;
|
2006-06-23 18:25:41 +02:00
|
|
|
U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
|
|
|
|
U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
|
|
|
|
U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 8;
|
2006-06-17 15:47:52 +02:00
|
|
|
|
2006-07-10 10:53:11 +02:00
|
|
|
hr = IDirectDraw7_CreateSurface(DDraw7, &ddsd, &surface, NULL);
|
2008-12-11 17:07:44 +01:00
|
|
|
if (!surface)
|
|
|
|
{
|
|
|
|
win_skip("Could not create surface : %08x\n", hr);
|
|
|
|
IDirectDraw7_Release(DDraw7);
|
|
|
|
return;
|
|
|
|
}
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == DD_OK, "CreateSurface failed with %08x\n", hr);
|
2006-06-17 15:47:52 +02:00
|
|
|
|
|
|
|
/* DDraw refcount increased by 1 */
|
2006-07-10 10:53:11 +02:00
|
|
|
ref = getRefcount( (IUnknown *) DDraw7);
|
2009-03-19 11:22:15 +01:00
|
|
|
ok(ref == 2, "Got refcount %d, expected 2\n", ref);
|
2006-06-17 15:47:52 +02:00
|
|
|
|
|
|
|
/* Surface refcount starts with 1 */
|
|
|
|
ref = getRefcount( (IUnknown *) surface);
|
2009-03-19 11:22:15 +01:00
|
|
|
ok(ref == 1, "Got refcount %d, expected 1\n", ref);
|
2006-06-17 15:47:52 +02:00
|
|
|
|
2006-07-10 10:53:11 +02:00
|
|
|
hr = IDirectDraw7_CreatePalette(DDraw7, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == DD_OK, "CreatePalette returned %08x\n", hr);
|
2006-06-17 15:47:52 +02:00
|
|
|
|
|
|
|
/* DDraw refcount increased by 1 */
|
2006-07-10 10:53:11 +02:00
|
|
|
ref = getRefcount( (IUnknown *) DDraw7);
|
2009-03-19 11:22:15 +01:00
|
|
|
ok(ref == 3, "Got refcount %d, expected 3\n", ref);
|
2006-06-17 15:47:52 +02:00
|
|
|
|
|
|
|
/* Palette starts with 1 */
|
|
|
|
ref = getRefcount( (IUnknown *) palette);
|
2009-03-19 11:22:15 +01:00
|
|
|
ok(ref == 1, "Got refcount %d, expected 1\n", ref);
|
2006-06-17 15:47:52 +02:00
|
|
|
|
|
|
|
/* Test attaching a palette to a surface */
|
|
|
|
hr = IDirectDrawSurface7_SetPalette(surface, palette);
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == DD_OK, "IDirectDrawSurface_SetPalette failed with %08x\n", hr);
|
2006-06-17 15:47:52 +02:00
|
|
|
|
|
|
|
/* Palette refcount increased, surface stays the same */
|
|
|
|
ref = getRefcount( (IUnknown *) palette);
|
2009-03-19 11:22:15 +01:00
|
|
|
ok(ref == 2, "Got refcount %d, expected 2\n", ref);
|
2006-06-17 15:47:52 +02:00
|
|
|
ref = getRefcount( (IUnknown *) surface);
|
2009-03-19 11:22:15 +01:00
|
|
|
ok(ref == 1, "Got refcount %d, expected 1\n", ref);
|
2006-06-17 15:47:52 +02:00
|
|
|
|
|
|
|
IDirectDrawSurface7_Release(surface);
|
2006-08-06 12:28:32 +02:00
|
|
|
/* Increased before - decrease now */
|
2006-07-10 10:53:11 +02:00
|
|
|
ref = getRefcount( (IUnknown *) DDraw7);
|
2009-03-19 11:22:15 +01:00
|
|
|
ok(ref == 2, "Got refcount %d, expected 2\n", ref);
|
2006-06-17 15:47:52 +02:00
|
|
|
|
|
|
|
/* Releasing the surface detaches the palette */
|
|
|
|
ref = getRefcount( (IUnknown *) palette);
|
2009-03-19 11:22:15 +01:00
|
|
|
ok(ref == 1, "Got refcount %d, expected 1\n", ref);
|
2006-06-17 15:47:52 +02:00
|
|
|
|
|
|
|
IDirectDrawPalette_Release(palette);
|
|
|
|
|
2006-08-06 12:28:32 +02:00
|
|
|
/* Increased before - decrease now */
|
2006-07-10 10:53:11 +02:00
|
|
|
ref = getRefcount( (IUnknown *) DDraw7);
|
2009-03-19 11:22:15 +01:00
|
|
|
ok(ref == 1, "Got refcount %d, expected 1\n", ref);
|
2006-07-10 10:53:11 +02:00
|
|
|
|
|
|
|
/* Not all interfaces are AddRefed when a palette is created */
|
|
|
|
hr = IDirectDraw4_CreatePalette(DDraw4, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == DD_OK, "CreatePalette returned %08x\n", hr);
|
2006-07-10 10:53:11 +02:00
|
|
|
ref = getRefcount( (IUnknown *) DDraw4);
|
2009-03-19 11:22:15 +01:00
|
|
|
ok(ref == 2, "Got refcount %d, expected 2\n", ref);
|
2006-07-10 10:53:11 +02:00
|
|
|
IDirectDrawPalette_Release(palette);
|
|
|
|
|
|
|
|
/* No addref here */
|
|
|
|
hr = IDirectDraw2_CreatePalette(DDraw2, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == DD_OK, "CreatePalette returned %08x\n", hr);
|
2006-07-10 10:53:11 +02:00
|
|
|
ref = getRefcount( (IUnknown *) DDraw2);
|
2009-03-19 11:22:15 +01:00
|
|
|
ok(ref == 1, "Got refcount %d, expected 1\n", ref);
|
2006-07-10 10:53:11 +02:00
|
|
|
IDirectDrawPalette_Release(palette);
|
|
|
|
|
|
|
|
/* No addref here */
|
|
|
|
hr = IDirectDraw_CreatePalette(DDraw1, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == DD_OK, "CreatePalette returned %08x\n", hr);
|
2006-07-10 10:53:11 +02:00
|
|
|
ref = getRefcount( (IUnknown *) DDraw1);
|
2009-03-19 11:22:15 +01:00
|
|
|
ok(ref == 1, "Got refcount %d, expected 1\n", ref);
|
2006-07-10 10:53:11 +02:00
|
|
|
IDirectDrawPalette_Release(palette);
|
2006-06-17 15:47:52 +02:00
|
|
|
|
2007-02-20 15:57:10 +01:00
|
|
|
/* Similar for surfaces */
|
2007-02-16 19:08:09 +01:00
|
|
|
hr = IDirectDraw4_CreateSurface(DDraw4, &ddsd, &surface4, NULL);
|
|
|
|
ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw4);
|
2009-03-19 11:22:15 +01:00
|
|
|
ok(ref == 2, "Got refcount %d, expected 2\n", ref);
|
2007-02-16 19:08:09 +01:00
|
|
|
IDirectDrawSurface4_Release(surface4);
|
|
|
|
|
|
|
|
ddsd.dwSize = sizeof(DDSURFACEDESC);
|
|
|
|
hr = IDirectDraw2_CreateSurface(DDraw2, (DDSURFACEDESC *) &ddsd, &surface1, NULL);
|
|
|
|
ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw2);
|
2009-03-19 11:22:15 +01:00
|
|
|
ok(ref == 1, "Got refcount %d, expected 1\n", ref);
|
2007-02-16 19:08:09 +01:00
|
|
|
IDirectDrawSurface_Release(surface1);
|
|
|
|
|
|
|
|
hr = IDirectDraw_CreateSurface(DDraw1, (DDSURFACEDESC *) &ddsd, &surface1, NULL);
|
|
|
|
ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw1);
|
2009-03-19 11:22:15 +01:00
|
|
|
ok(ref == 1, "Got refcount %d, expected 1\n", ref);
|
2007-02-16 19:08:09 +01:00
|
|
|
IDirectDrawSurface_Release(surface1);
|
|
|
|
|
2006-07-10 10:53:11 +02:00
|
|
|
IDirectDraw7_Release(DDraw7);
|
|
|
|
IDirectDraw4_Release(DDraw4);
|
|
|
|
IDirectDraw2_Release(DDraw2);
|
|
|
|
IDirectDraw_Release(DDraw1);
|
2006-06-17 15:47:52 +02:00
|
|
|
}
|
|
|
|
|
2006-07-10 16:06:33 +02:00
|
|
|
static void test_iface_refcnt(void)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IDirectDraw *DDraw1;
|
|
|
|
IDirectDraw2 *DDraw2;
|
|
|
|
IDirectDraw4 *DDraw4;
|
|
|
|
IDirectDraw7 *DDraw7;
|
|
|
|
IDirect3D7 *D3D7;
|
|
|
|
IDirect3D3 *D3D3;
|
|
|
|
IDirect3D2 *D3D2;
|
|
|
|
IDirect3D *D3D1;
|
|
|
|
long ref;
|
|
|
|
|
|
|
|
hr = pDirectDrawCreateEx(NULL, (void **) &DDraw7, &IID_IDirectDraw7, NULL);
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", hr);
|
2006-07-10 16:06:33 +02:00
|
|
|
if(!DDraw7)
|
|
|
|
{
|
|
|
|
trace("Couldn't create DDraw interface, skipping tests\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw7);
|
|
|
|
ok(ref == 1, "Initial IDirectDraw7 reference count is %ld\n", ref);
|
|
|
|
|
|
|
|
hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirectDraw4, (void **) &DDraw4);
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);
|
2006-07-10 16:06:33 +02:00
|
|
|
hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirectDraw2, (void **) &DDraw2);
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == DD_OK, "IDirectDraw7_QueryInterf&ace returned %08x\n", hr);
|
2006-07-10 16:06:33 +02:00
|
|
|
hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirectDraw, (void **) &DDraw1);
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);
|
2006-07-10 16:06:33 +02:00
|
|
|
|
|
|
|
/* All interfaces now have refcount 1! */
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw7);
|
|
|
|
ok(ref == 1, "IDirectDraw7 reference count is %ld\n", ref);
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw7);
|
|
|
|
ok(ref == 1, "IDirectDraw7 reference count is %ld\n", ref);
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw4);
|
|
|
|
ok(ref == 1, "IDirectDraw4 reference count is %ld\n", ref);
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw2);
|
|
|
|
ok(ref == 1, "IDirectDraw2 reference count is %ld\n", ref);
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw1);
|
|
|
|
ok(ref == 1, "IDirectDraw reference count is %ld\n", ref);
|
|
|
|
|
|
|
|
hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirect3D7, (void **) &D3D7);
|
2009-07-10 20:52:33 +02:00
|
|
|
ok(hr == DD_OK || hr == E_NOINTERFACE, /* win64 */
|
|
|
|
"IDirectDraw7_QueryInterface returned %08x\n", hr);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
IDirectDraw7_Release(DDraw7);
|
|
|
|
IDirectDraw4_Release(DDraw4);
|
|
|
|
IDirectDraw2_Release(DDraw2);
|
|
|
|
IDirectDraw_Release(DDraw1);
|
|
|
|
skip( "no IDirect3D7 support\n" );
|
|
|
|
return;
|
|
|
|
}
|
2006-07-10 16:06:33 +02:00
|
|
|
|
|
|
|
/* Apparently IDirectDrawX and IDirect3DX are linked together */
|
|
|
|
ref = getRefcount( (IUnknown *) D3D7);
|
|
|
|
ok(ref == 2, "IDirect3D7 reference count is %ld\n", ref);
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw7);
|
|
|
|
ok(ref == 2, "IDirectDraw7 reference count is %ld\n", ref);
|
|
|
|
|
|
|
|
IDirectDraw7_AddRef(DDraw7);
|
|
|
|
ref = getRefcount( (IUnknown *) D3D7);
|
|
|
|
ok(ref == 3, "IDirect3D7 reference count is %ld\n", ref);
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw7);
|
|
|
|
ok(ref == 3, "IDirectDraw7 reference count is %ld\n", ref);
|
|
|
|
|
|
|
|
IDirect3D7_Release(D3D7);
|
|
|
|
ref = getRefcount( (IUnknown *) D3D7);
|
|
|
|
ok(ref == 2, "IDirect3D7 reference count is %ld\n", ref);
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw7);
|
|
|
|
ok(ref == 2, "IDirectDraw7 reference count is %ld\n", ref);
|
|
|
|
|
|
|
|
/* Can't get older d3d interfaces. WHY????? */
|
2009-12-17 20:00:44 +01:00
|
|
|
hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirect3D3, (void **) &D3D3);
|
2006-10-10 19:23:33 +02:00
|
|
|
todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw7_QueryInterface returned %08x\n", hr);
|
2006-07-10 16:06:33 +02:00
|
|
|
if(hr == DD_OK && D3D3) IDirect3D3_Release(D3D3);
|
|
|
|
|
|
|
|
hr = IDirectDraw4_QueryInterface(DDraw4, &IID_IDirect3D3, (void **) &D3D3);
|
2006-10-10 19:23:33 +02:00
|
|
|
todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw4_QueryInterface returned %08x\n", hr);
|
2006-07-10 16:06:33 +02:00
|
|
|
if(hr == DD_OK && D3D3) IDirect3D3_Release(D3D3);
|
|
|
|
|
|
|
|
hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirect3D2, (void **) &D3D2);
|
2006-10-10 19:23:33 +02:00
|
|
|
todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw7_QueryInterface returned %08x\n", hr);
|
2006-07-10 16:06:33 +02:00
|
|
|
if(hr == DD_OK && D3D2) IDirect3D2_Release(D3D2);
|
|
|
|
|
|
|
|
hr = IDirectDraw2_QueryInterface(DDraw2, &IID_IDirect3D2, (void **) &D3D2);
|
2006-10-10 19:23:33 +02:00
|
|
|
todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw2_QueryInterface returned %08x\n", hr);
|
2006-07-10 16:06:33 +02:00
|
|
|
if(hr == DD_OK && D3D2) IDirect3D2_Release(D3D2);
|
|
|
|
|
|
|
|
hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirect3D, (void **) &D3D1);
|
2006-10-10 19:23:33 +02:00
|
|
|
todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw7_QueryInterface returned %08x\n", hr);
|
2006-07-10 16:06:33 +02:00
|
|
|
if(hr == DD_OK && D3D1) IDirect3D_Release(D3D1);
|
|
|
|
|
|
|
|
hr = IDirectDraw_QueryInterface(DDraw1, &IID_IDirect3D, (void **) &D3D1);
|
2006-10-10 19:23:33 +02:00
|
|
|
todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw_QueryInterface returned %08x\n", hr);
|
2006-07-10 16:06:33 +02:00
|
|
|
if(hr == DD_OK && D3D1) IDirect3D_Release(D3D1);
|
|
|
|
|
|
|
|
hr = IDirect3D7_QueryInterface(D3D7, &IID_IDirect3D, (void **) &D3D1);
|
2006-10-10 19:23:33 +02:00
|
|
|
todo_wine ok(hr == E_NOINTERFACE, "IDirect3D7_QueryInterface returned %08x\n", hr);
|
2006-07-10 16:06:33 +02:00
|
|
|
if(hr == DD_OK && D3D1) IDirect3D_Release(D3D1);
|
|
|
|
|
|
|
|
/* Try an AddRef, it only affects the AddRefed interface */
|
|
|
|
IDirectDraw4_AddRef(DDraw4);
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw7);
|
|
|
|
ok(ref == 2, "IDirectDraw7 reference count is %ld\n", ref); /* <-- From the d3d query */
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw4);
|
|
|
|
ok(ref == 2, "IDirectDraw4 reference count is %ld\n", ref); /* <-- The AddRef call */
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw2);
|
|
|
|
ok(ref == 1, "IDirectDraw2 reference count is %ld\n", ref);
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw1);
|
|
|
|
ok(ref == 1, "IDirectDraw reference count is %ld\n", ref);
|
|
|
|
ref = getRefcount( (IUnknown *) D3D7);
|
|
|
|
ok(ref == 2, "IDirect3D7 reference count is %ld\n", ref); /* <-- From the d3d query */
|
|
|
|
IDirectDraw4_Release(DDraw4);
|
|
|
|
|
|
|
|
/* Make sure that they are one object, not different ones */
|
|
|
|
hr = IDirectDraw4_SetCooperativeLevel(DDraw4, GetDesktopWindow(), DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == DD_OK, "IDirectDraw4::SetCooperativeLevel returned %08x\n", hr);
|
2006-07-10 16:06:33 +02:00
|
|
|
/* After an window has been set, DDSCL_SETFOCUSWINDOW should return DDERR_HWNDALREADYSET, see the mode test */
|
|
|
|
hr = IDirectDraw7_SetCooperativeLevel(DDraw7, NULL, DDSCL_SETFOCUSWINDOW);
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == DDERR_HWNDALREADYSET, "IDirectDraw7::SetCooperativeLevel returned %08x\n", hr);
|
2006-07-10 16:06:33 +02:00
|
|
|
|
|
|
|
/* All done, release all interfaces */
|
|
|
|
IDirectDraw7_Release(DDraw7);
|
|
|
|
IDirectDraw4_Release(DDraw4);
|
|
|
|
IDirectDraw2_Release(DDraw2);
|
|
|
|
IDirectDraw_Release(DDraw1);
|
|
|
|
IDirect3D7_Release(D3D7);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_d3d_ifaces(void)
|
|
|
|
{
|
|
|
|
IDirectDraw *DDraw1;
|
|
|
|
IDirectDraw2 *DDraw2;
|
|
|
|
IDirectDraw4 *DDraw4;
|
|
|
|
IDirect3D *D3D1;
|
|
|
|
IDirect3D2 *D3D2;
|
|
|
|
IDirect3D3 *D3D3;
|
|
|
|
IDirect3D7 *D3D7;
|
|
|
|
HRESULT hr;
|
|
|
|
long ref;
|
|
|
|
|
|
|
|
hr = DirectDrawCreate(NULL, &DDraw1, NULL);
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", hr);
|
2006-07-10 16:06:33 +02:00
|
|
|
if(!DDraw1)
|
|
|
|
{
|
2006-10-10 19:23:33 +02:00
|
|
|
trace("DirectDrawCreate failed with %08x\n", hr);
|
2006-07-10 16:06:33 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IDirectDraw_QueryInterface(DDraw1, &IID_IDirectDraw2, (void **) &DDraw2);
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == DD_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
|
2006-07-10 16:06:33 +02:00
|
|
|
hr = IDirectDraw_QueryInterface(DDraw1, &IID_IDirectDraw4, (void **) &DDraw4);
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == DD_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
|
2006-07-10 16:06:33 +02:00
|
|
|
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw4);
|
|
|
|
ok(ref == 1, "IDirectDraw4 reference count is %ld\n", ref);
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw2);
|
|
|
|
ok(ref == 1, "IDirectDraw2 reference count is %ld\n", ref);
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw1);
|
|
|
|
ok(ref == 1, "IDirectDraw reference count is %ld\n", ref);
|
|
|
|
|
2012-02-02 12:56:00 +01:00
|
|
|
/* FIXME: This test suggests that IDirect3D, IDirect3D2 and IDirect3D3 are linked
|
|
|
|
* to IDirectDraw. However, they are linked to whatever interface is used to QI the
|
|
|
|
* first IDirect3D? interface. If DDraw1 is replaced with DDraw4 here the tests break */
|
2006-07-10 16:06:33 +02:00
|
|
|
hr = IDirectDraw_QueryInterface(DDraw1, &IID_IDirect3D, (void **) &D3D1);
|
2009-07-14 11:28:37 +02:00
|
|
|
if (hr == E_NOINTERFACE) /* win64 */
|
|
|
|
{
|
|
|
|
IDirectDraw4_Release(DDraw4);
|
|
|
|
IDirectDraw2_Release(DDraw2);
|
|
|
|
IDirectDraw_Release(DDraw1);
|
|
|
|
skip( "no IDirect3D support\n" );
|
|
|
|
return;
|
|
|
|
}
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == DD_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
|
2006-07-10 16:06:33 +02:00
|
|
|
ref = getRefcount( (IUnknown *) DDraw4);
|
|
|
|
ok(ref == 1, "IDirectDraw4 reference count is %ld\n", ref);
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw2);
|
|
|
|
ok(ref == 1, "IDirectDraw2 reference count is %ld\n", ref);
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw1);
|
|
|
|
ok(ref == 2, "IDirectDraw reference count is %ld\n", ref);
|
|
|
|
IDirect3D_Release(D3D1);
|
|
|
|
|
|
|
|
hr = IDirectDraw2_QueryInterface(DDraw2, &IID_IDirect3D2, (void **) &D3D2);
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == DD_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
|
2006-07-10 16:06:33 +02:00
|
|
|
ref = getRefcount( (IUnknown *) DDraw4);
|
|
|
|
ok(ref == 1, "IDirectDraw4 reference count is %ld\n", ref);
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw2);
|
|
|
|
ok(ref == 1, "IDirectDraw2 reference count is %ld\n", ref);
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw1);
|
|
|
|
ok(ref == 2, "IDirectDraw reference count is %ld\n", ref);
|
|
|
|
IDirect3D2_Release(D3D2);
|
|
|
|
|
|
|
|
hr = IDirectDraw4_QueryInterface(DDraw4, &IID_IDirect3D3, (void **) &D3D3);
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == DD_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
|
2006-07-10 16:06:33 +02:00
|
|
|
ref = getRefcount( (IUnknown *) DDraw4);
|
|
|
|
ok(ref == 1, "IDirectDraw4 reference count is %ld\n", ref);
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw2);
|
|
|
|
ok(ref == 1, "IDirectDraw2 reference count is %ld\n", ref);
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw1);
|
|
|
|
ok(ref == 2, "IDirectDraw reference count is %ld\n", ref);
|
|
|
|
IDirect3D3_Release(D3D3);
|
|
|
|
|
|
|
|
/* Try to AddRef the D3D3 interface that has been released already */
|
|
|
|
IDirect3D3_AddRef(D3D3);
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw1);
|
|
|
|
ok(ref == 2, "IDirectDraw reference count is %ld\n", ref);
|
|
|
|
ref = getRefcount( (IUnknown *) D3D3);
|
|
|
|
ok(ref == 2, "IDirect3D3 reference count is %ld\n", ref);
|
|
|
|
/* The newer interfaces remain untouched */
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw4);
|
|
|
|
ok(ref == 1, "IDirectDraw4 reference count is %ld\n", ref);
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw2);
|
|
|
|
ok(ref == 1, "IDirectDraw2 reference count is %ld\n", ref);
|
|
|
|
IDirect3D3_Release(D3D3);
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw1);
|
|
|
|
ok(ref == 1, "IDirectDraw reference count is %ld\n", ref);
|
|
|
|
ref = getRefcount( (IUnknown *) DDraw1);
|
|
|
|
ok(ref == 1, "IDirectDraw reference count is %ld\n", ref);
|
|
|
|
|
|
|
|
/* It is possible to query any IDirect3D interfaces from any IDirectDraw interface,
|
|
|
|
* Except IDirect3D7, it can only be returned by IDirectDraw7(which can't return older ifaces)
|
|
|
|
*/
|
|
|
|
hr = IDirectDraw_QueryInterface(DDraw2, &IID_IDirect3D, (void **) &D3D1);
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == DD_OK, "IDirectDraw2_QueryInterface returned %08x\n", hr);
|
2006-07-10 16:06:33 +02:00
|
|
|
IDirect3D_Release(D3D1);
|
|
|
|
hr = IDirectDraw4_QueryInterface(DDraw4, &IID_IDirect3D, (void **) &D3D1);
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == DD_OK, "IDirectDraw4_QueryInterface returned %08x\n", hr);
|
2006-07-10 16:06:33 +02:00
|
|
|
IDirect3D_Release(D3D1);
|
|
|
|
|
|
|
|
hr = IDirectDraw_QueryInterface(DDraw1, &IID_IDirect3D2, (void **) &D3D2);
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == DD_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
|
2006-07-10 16:06:33 +02:00
|
|
|
IDirect3D_Release(D3D2);
|
|
|
|
hr = IDirectDraw4_QueryInterface(DDraw4, &IID_IDirect3D2, (void **) &D3D2);
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == DD_OK, "IDirectDraw4_QueryInterface returned %08x\n", hr);
|
2006-07-10 16:06:33 +02:00
|
|
|
IDirect3D_Release(D3D2);
|
|
|
|
|
|
|
|
hr = IDirectDraw_QueryInterface(DDraw1, &IID_IDirect3D3, (void **) &D3D3);
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == DD_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
|
2006-07-10 16:06:33 +02:00
|
|
|
IDirect3D_Release(D3D3);
|
|
|
|
hr = IDirectDraw2_QueryInterface(DDraw2, &IID_IDirect3D3, (void **) &D3D3);
|
2006-10-10 19:23:33 +02:00
|
|
|
ok(hr == DD_OK, "IDirectDraw2_QueryInterface returned %08x\n", hr);
|
2006-07-10 16:06:33 +02:00
|
|
|
IDirect3D_Release(D3D3);
|
|
|
|
|
|
|
|
/* This does NOT work */
|
|
|
|
hr = IDirectDraw_QueryInterface(DDraw1, &IID_IDirect3D7, (void **) &D3D7);
|
2006-10-10 19:23:33 +02:00
|
|
|
todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw_QueryInterface returned %08x\n", hr);
|
2006-07-10 16:06:33 +02:00
|
|
|
if(D3D7) IDirect3D_Release(D3D7);
|
|
|
|
hr = IDirectDraw2_QueryInterface(DDraw2, &IID_IDirect3D7, (void **) &D3D7);
|
2006-10-10 19:23:33 +02:00
|
|
|
todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw2_QueryInterface returned %08x\n", hr);
|
2006-07-10 16:06:33 +02:00
|
|
|
if(D3D7) IDirect3D_Release(D3D7);
|
|
|
|
hr = IDirectDraw4_QueryInterface(DDraw4, &IID_IDirect3D7, (void **) &D3D7);
|
2006-10-10 19:23:33 +02:00
|
|
|
todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw4_QueryInterface returned %08x\n", hr);
|
2006-07-10 16:06:33 +02:00
|
|
|
if(D3D7) IDirect3D_Release(D3D7);
|
|
|
|
|
|
|
|
/* Release the interfaces */
|
|
|
|
IDirectDraw4_Release(DDraw4);
|
|
|
|
IDirectDraw2_Release(DDraw2);
|
|
|
|
IDirectDraw_Release(DDraw1);
|
|
|
|
}
|
|
|
|
|
2006-06-17 15:47:52 +02:00
|
|
|
START_TEST(refcount)
|
|
|
|
{
|
|
|
|
init_function_pointers();
|
|
|
|
if(!pDirectDrawCreateEx)
|
|
|
|
{
|
2008-12-11 17:07:44 +01:00
|
|
|
win_skip("function DirectDrawCreateEx not available\n");
|
2006-06-17 15:47:52 +02:00
|
|
|
return;
|
|
|
|
}
|
2006-07-10 16:06:33 +02:00
|
|
|
test_ddraw_objects();
|
|
|
|
test_iface_refcnt();
|
|
|
|
test_d3d_ifaces();
|
2006-06-17 15:47:52 +02:00
|
|
|
}
|