wineps: Fix a couple of typos in the path painting function.
[wine/testsucceed.git] / dlls / ddraw / tests / refcount.c
blobcf949861f266411fdd1568dafb2ce347eff36e6e
1 /*
2 * Some unit tests for ddraw reference counting
4 * Copyright (C) 2006 Stefan Dösinger
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #define COBJMACROS
22 #include "wine/test.h"
23 #include "ddraw.h"
24 #include "d3d.h"
25 #include "unknwn.h"
27 static HRESULT (WINAPI *pDirectDrawCreateEx)(LPGUID,LPVOID*,REFIID,LPUNKNOWN);
29 static void init_function_pointers(void)
31 HMODULE hmod = GetModuleHandleA("ddraw.dll");
32 pDirectDrawCreateEx = (void*)GetProcAddress(hmod, "DirectDrawCreateEx");
35 static ULONG getRefcount(IUnknown *iface)
37 IUnknown_AddRef(iface);
38 return IUnknown_Release(iface);
41 static void test_ddraw_objects(void)
43 HRESULT hr;
44 ULONG ref;
45 IDirectDraw7 *DDraw7;
46 IDirectDraw4 *DDraw4;
47 IDirectDraw2 *DDraw2;
48 IDirectDraw *DDraw1;
49 IDirectDrawPalette *palette;
50 IDirectDrawSurface7 *surface = NULL, *stencil;
51 IDirectDrawSurface *surface1, *stencil1;
52 IDirectDrawSurface4 *surface4;
53 PALETTEENTRY Table[256];
54 DDSURFACEDESC2 ddsd, ddsd_stencil;
56 hr = pDirectDrawCreateEx(NULL, (void **) &DDraw7, &IID_IDirectDraw7, NULL);
57 ok(hr == DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", hr);
58 if(!DDraw7)
60 trace("Couldn't create DDraw interface, skipping tests\n");
61 return;
64 hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirectDraw4, (void **) &DDraw4);
65 ok(hr == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);
66 hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirectDraw2, (void **) &DDraw2);
67 ok(hr == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);
68 hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirectDraw, (void **) &DDraw1);
69 ok(hr == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);
71 ref = getRefcount( (IUnknown *) DDraw7);
72 ok(ref == 1, "Got refcount %d, expected 1\n", ref);
74 /* Fails without a cooplevel */
75 hr = IDirectDraw7_CreatePalette(DDraw7, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
76 ok(hr == DDERR_NOCOOPERATIVELEVELSET, "CreatePalette returned %08x\n", hr);
78 /* This check is before the cooplevel check */
79 hr = IDirectDraw7_CreatePalette(DDraw7, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, (void *) 0xdeadbeef);
80 ok(hr == CLASS_E_NOAGGREGATION, "CreatePalette returned %08x\n", hr);
82 hr = IDirectDraw7_SetCooperativeLevel(DDraw7, 0, DDSCL_NORMAL);
83 ok(hr == DD_OK, "SetCooperativeLevel failed with %08x\n", hr);
85 memset(&ddsd, 0, sizeof(ddsd));
86 ddsd.dwSize = sizeof(ddsd);
87 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
88 ddsd.dwWidth = 64;
89 ddsd.dwHeight = 64;
90 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
91 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
92 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
93 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 8;
95 memset(&ddsd_stencil, 0, sizeof(ddsd_stencil));
96 ddsd_stencil.dwSize = sizeof(ddsd_stencil);
97 ddsd_stencil.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
98 ddsd_stencil.dwWidth = ddsd.dwWidth;
99 ddsd_stencil.dwHeight = ddsd.dwHeight;
100 ddsd_stencil.ddsCaps.dwCaps = DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER;
101 U4(ddsd_stencil).ddpfPixelFormat.dwSize = sizeof(U4(ddsd_stencil).ddpfPixelFormat);
102 U4(ddsd_stencil).ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
103 U1(U4(ddsd_stencil).ddpfPixelFormat).dwZBufferBitDepth = 16;
104 U3(U4(ddsd_stencil).ddpfPixelFormat).dwZBitMask = 0x0000FFFF;
106 hr = IDirectDraw7_CreateSurface(DDraw7, &ddsd, &surface, NULL);
107 if (!surface)
109 win_skip("Could not create surface : %08x\n", hr);
110 IDirectDraw7_Release(DDraw7);
111 return;
113 ok(hr == DD_OK, "CreateSurface failed with %08x\n", hr);
115 /* DDraw refcount increased by 1 */
116 ref = getRefcount( (IUnknown *) DDraw7);
117 ok(ref == 2, "Got refcount %d, expected 2\n", ref);
119 /* Surface refcount starts with 1 */
120 ref = getRefcount( (IUnknown *) surface);
121 ok(ref == 1, "Got refcount %d, expected 1\n", ref);
123 hr = IDirectDraw7_CreatePalette(DDraw7, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
124 ok(hr == DD_OK, "CreatePalette returned %08x\n", hr);
126 /* DDraw refcount increased by 1 */
127 ref = getRefcount( (IUnknown *) DDraw7);
128 ok(ref == 3, "Got refcount %d, expected 3\n", ref);
130 /* Palette starts with 1 */
131 ref = getRefcount( (IUnknown *) palette);
132 ok(ref == 1, "Got refcount %d, expected 1\n", ref);
134 /* Test attaching a palette to a surface */
135 hr = IDirectDrawSurface7_SetPalette(surface, palette);
136 ok(hr == DD_OK, "IDirectDrawSurface_SetPalette failed with %08x\n", hr);
138 /* Palette refcount increased, surface stays the same */
139 ref = getRefcount( (IUnknown *) palette);
140 ok(ref == 2, "Got refcount %d, expected 2\n", ref);
141 ref = getRefcount( (IUnknown *) surface);
142 ok(ref == 1, "Got refcount %d, expected 1\n", ref);
144 IDirectDrawSurface7_Release(surface);
145 /* Increased before - decrease now */
146 ref = getRefcount( (IUnknown *) DDraw7);
147 ok(ref == 2, "Got refcount %d, expected 2\n", ref);
149 /* Releasing the surface detaches the palette */
150 ref = getRefcount( (IUnknown *) palette);
151 ok(ref == 1, "Got refcount %d, expected 1\n", ref);
153 IDirectDrawPalette_Release(palette);
155 /* Increased before - decrease now */
156 ref = getRefcount( (IUnknown *) DDraw7);
157 ok(ref == 1, "Got refcount %d, expected 1\n", ref);
159 /* Not all interfaces are AddRefed when a palette is created */
160 hr = IDirectDraw4_CreatePalette(DDraw4, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
161 ok(hr == DD_OK, "CreatePalette returned %08x\n", hr);
162 ref = getRefcount( (IUnknown *) DDraw4);
163 ok(ref == 2, "Got refcount %d, expected 2\n", ref);
164 IDirectDrawPalette_Release(palette);
166 /* No addref here */
167 hr = IDirectDraw2_CreatePalette(DDraw2, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
168 ok(hr == DD_OK, "CreatePalette returned %08x\n", hr);
169 ref = getRefcount( (IUnknown *) DDraw2);
170 ok(ref == 1, "Got refcount %d, expected 1\n", ref);
171 IDirectDrawPalette_Release(palette);
173 /* No addref here */
174 hr = IDirectDraw_CreatePalette(DDraw1, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
175 ok(hr == DD_OK, "CreatePalette returned %08x\n", hr);
176 ref = getRefcount( (IUnknown *) DDraw1);
177 ok(ref == 1, "Got refcount %d, expected 1\n", ref);
178 IDirectDrawPalette_Release(palette);
180 /* Similar for surfaces */
181 hr = IDirectDraw4_CreateSurface(DDraw4, &ddsd, &surface4, NULL);
182 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
183 ref = getRefcount( (IUnknown *) DDraw4);
184 ok(ref == 2, "Got refcount %d, expected 2\n", ref);
185 IDirectDrawSurface4_Release(surface4);
187 ddsd.dwSize = sizeof(DDSURFACEDESC);
188 hr = IDirectDraw2_CreateSurface(DDraw2, (DDSURFACEDESC *) &ddsd, &surface1, NULL);
189 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
190 ref = getRefcount( (IUnknown *) DDraw2);
191 ok(ref == 1, "Got refcount %d, expected 1\n", ref);
192 IDirectDrawSurface_Release(surface1);
194 hr = IDirectDraw_CreateSurface(DDraw1, (DDSURFACEDESC *) &ddsd, &surface1, NULL);
195 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
196 ref = getRefcount( (IUnknown *) DDraw1);
197 ok(ref == 1, "Got refcount %d, expected 1\n", ref);
198 IDirectDrawSurface_Release(surface1);
200 /* AddAttachedSurface with IDirectDrawSurface7 */
201 ddsd.dwSize = sizeof(DDSURFACEDESC2);
202 ddsd.ddsCaps.dwCaps |= DDSCAPS_3DDEVICE;
203 hr = IDirectDraw7_CreateSurface(DDraw7, &ddsd, &surface, NULL);
204 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
205 if (SUCCEEDED(hr))
207 ddsd_stencil.dwSize = sizeof(DDSURFACEDESC2);
208 hr = IDirectDraw7_CreateSurface(DDraw7, &ddsd_stencil, &stencil, NULL);
209 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
210 if (SUCCEEDED(hr))
212 /* AddAttachedSurface with DeleteAttachedSurface */
213 hr = IDirectDrawSurface7_AddAttachedSurface(surface, stencil);
214 ok(hr == DD_OK, "AddAttachedSurface returned %08x\n", hr);
215 if (SUCCEEDED(hr))
217 ref = getRefcount( (IUnknown *) stencil);
218 ok(ref == 2, "Got refcount %d, expected 2\n", ref);
219 hr = IDirectDrawSurface7_QueryInterface(surface, &IID_IDirectDrawSurface, (void **) &surface1);
220 ok(hr == DD_OK, "IDirectDrawSurface7_QueryInterface returned %08x\n", hr);
221 hr = IDirectDrawSurface7_QueryInterface(stencil, &IID_IDirectDrawSurface, (void **) &stencil1);
222 ok(hr == DD_OK, "IDirectDrawSurface7_QueryInterface returned %08x\n", hr);
223 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1, 0, stencil1);
224 ok(hr == DDERR_SURFACENOTATTACHED, "DeleteAttachedSurface returned %08x\n", hr);
225 if (stencil1 != NULL) IDirectDrawSurface_Release(stencil1);
226 if (surface1 != NULL) IDirectDrawSurface_Release(surface1);
227 hr = IDirectDrawSurface7_DeleteAttachedSurface(surface, 0, stencil);
228 ok(hr == DD_OK, "DeleteAttachedSurface returned %08x\n", hr);
229 ref = getRefcount( (IUnknown *) stencil);
230 ok(ref == 1, "Got refcount %d, expected 1\n", ref);
233 /* Releasing a surface should detach any attached surfaces */
234 hr = IDirectDrawSurface7_AddAttachedSurface(surface, stencil);
235 ok(hr == DD_OK, "AddAttachedSurface returned %08x\n", hr);
236 ref = getRefcount( (IUnknown *) stencil);
237 ok(ref == 2, "Got refcount %d, expected 2\n", ref);
238 ref = IDirectDrawSurface7_Release(surface);
239 ok(!ref, "Got refcount %d, expected 0\n", ref);
240 ref = getRefcount( (IUnknown *) stencil);
241 ok(ref == 1, "Got refcount %d, expected 1\n", ref);
242 ref = IDirectDrawSurface7_Release(stencil);
243 ok(!ref, "Got refcount %d, expected 0\n", ref);
245 else
246 IDirectDrawSurface7_Release(surface);
249 /* AddAttachedSurface with IDirectDrawSurface */
250 ddsd.dwSize = sizeof(DDSURFACEDESC);
251 hr = IDirectDraw_CreateSurface(DDraw1, (DDSURFACEDESC *) &ddsd, &surface1, NULL);
252 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
253 if (SUCCEEDED(hr))
255 ddsd_stencil.dwSize = sizeof(DDSURFACEDESC);
256 hr = IDirectDraw_CreateSurface(DDraw1, (DDSURFACEDESC *) &ddsd_stencil, &stencil1, NULL);
257 ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
258 if (SUCCEEDED(hr))
260 /* AddAttachedSurface with DeleteAttachedSurface */
261 hr = IDirectDrawSurface_AddAttachedSurface(surface1, stencil1);
262 ok(hr == DD_OK, "AddAttachedSurface returned %08x\n", hr);
263 if (SUCCEEDED(hr))
265 ref = getRefcount( (IUnknown *) stencil1);
266 ok(ref == 2, "Got refcount %d, expected 2\n", ref);
267 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1, 0, stencil1);
268 ok(hr == DD_OK, "DeleteAttachedSurface returned %08x\n", hr);
269 ref = getRefcount( (IUnknown *) stencil1);
270 ok(ref == 1, "Got refcount %d, expected 1\n", ref);
273 /* Releasing a surface should detach any attached surfaces */
274 hr = IDirectDrawSurface_AddAttachedSurface(surface1, stencil1);
275 ok(hr == DD_OK, "AddAttachedSurface returned %08x\n", hr);
276 ref = getRefcount( (IUnknown *) stencil1);
277 ok(ref == 2, "Got refcount %d, expected 2\n", ref);
278 ref = IDirectDrawSurface_Release(surface1);
279 ok(!ref, "Got refcount %d, expected 0\n", ref);
280 ref = getRefcount( (IUnknown *) stencil1);
281 ok(ref == 1, "Got refcount %d, expected 1\n", ref);
282 ref = IDirectDrawSurface_Release(stencil1);
283 ok(!ref, "Got refcount %d, expected 0\n", ref);
285 else
286 IDirectDrawSurface_Release(surface1);
289 IDirectDraw7_Release(DDraw7);
290 IDirectDraw4_Release(DDraw4);
291 IDirectDraw2_Release(DDraw2);
292 IDirectDraw_Release(DDraw1);
295 static void test_iface_refcnt(void)
297 HRESULT hr;
298 IDirectDraw *DDraw1;
299 IDirectDraw2 *DDraw2;
300 IDirectDraw4 *DDraw4;
301 IDirectDraw7 *DDraw7;
302 IDirect3D7 *D3D7;
303 IDirect3D3 *D3D3;
304 IDirect3D2 *D3D2;
305 IDirect3D *D3D1;
306 long ref;
308 hr = pDirectDrawCreateEx(NULL, (void **) &DDraw7, &IID_IDirectDraw7, NULL);
309 ok(hr == DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", hr);
310 if(!DDraw7)
312 trace("Couldn't create DDraw interface, skipping tests\n");
313 return;
316 ref = getRefcount( (IUnknown *) DDraw7);
317 ok(ref == 1, "Initial IDirectDraw7 reference count is %ld\n", ref);
319 hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirectDraw4, (void **) &DDraw4);
320 ok(hr == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);
321 hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirectDraw2, (void **) &DDraw2);
322 ok(hr == DD_OK, "IDirectDraw7_QueryInterf&ace returned %08x\n", hr);
323 hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirectDraw, (void **) &DDraw1);
324 ok(hr == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);
326 /* All interfaces now have refcount 1! */
327 ref = getRefcount( (IUnknown *) DDraw7);
328 ok(ref == 1, "IDirectDraw7 reference count is %ld\n", ref);
329 ref = getRefcount( (IUnknown *) DDraw7);
330 ok(ref == 1, "IDirectDraw7 reference count is %ld\n", ref);
331 ref = getRefcount( (IUnknown *) DDraw4);
332 ok(ref == 1, "IDirectDraw4 reference count is %ld\n", ref);
333 ref = getRefcount( (IUnknown *) DDraw2);
334 ok(ref == 1, "IDirectDraw2 reference count is %ld\n", ref);
335 ref = getRefcount( (IUnknown *) DDraw1);
336 ok(ref == 1, "IDirectDraw reference count is %ld\n", ref);
338 hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirect3D7, (void **) &D3D7);
339 ok(hr == DD_OK || hr == E_NOINTERFACE, /* win64 */
340 "IDirectDraw7_QueryInterface returned %08x\n", hr);
341 if (FAILED(hr))
343 IDirectDraw7_Release(DDraw7);
344 IDirectDraw4_Release(DDraw4);
345 IDirectDraw2_Release(DDraw2);
346 IDirectDraw_Release(DDraw1);
347 skip( "no IDirect3D7 support\n" );
348 return;
351 /* Apparently IDirectDrawX and IDirect3DX are linked together */
352 ref = getRefcount( (IUnknown *) D3D7);
353 ok(ref == 2, "IDirect3D7 reference count is %ld\n", ref);
354 ref = getRefcount( (IUnknown *) DDraw7);
355 ok(ref == 2, "IDirectDraw7 reference count is %ld\n", ref);
357 IDirectDraw7_AddRef(DDraw7);
358 ref = getRefcount( (IUnknown *) D3D7);
359 ok(ref == 3, "IDirect3D7 reference count is %ld\n", ref);
360 ref = getRefcount( (IUnknown *) DDraw7);
361 ok(ref == 3, "IDirectDraw7 reference count is %ld\n", ref);
363 IDirect3D7_Release(D3D7);
364 ref = getRefcount( (IUnknown *) D3D7);
365 ok(ref == 2, "IDirect3D7 reference count is %ld\n", ref);
366 ref = getRefcount( (IUnknown *) DDraw7);
367 ok(ref == 2, "IDirectDraw7 reference count is %ld\n", ref);
369 /* Can't get older d3d interfaces. WHY????? */
370 hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirect3D3, (void **) &D3D3);
371 todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw7_QueryInterface returned %08x\n", hr);
372 if(hr == DD_OK && D3D3) IDirect3D3_Release(D3D3);
374 hr = IDirectDraw4_QueryInterface(DDraw4, &IID_IDirect3D3, (void **) &D3D3);
375 todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw4_QueryInterface returned %08x\n", hr);
376 if(hr == DD_OK && D3D3) IDirect3D3_Release(D3D3);
378 hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirect3D2, (void **) &D3D2);
379 todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw7_QueryInterface returned %08x\n", hr);
380 if(hr == DD_OK && D3D2) IDirect3D2_Release(D3D2);
382 hr = IDirectDraw2_QueryInterface(DDraw2, &IID_IDirect3D2, (void **) &D3D2);
383 todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw2_QueryInterface returned %08x\n", hr);
384 if(hr == DD_OK && D3D2) IDirect3D2_Release(D3D2);
386 hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirect3D, (void **) &D3D1);
387 todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw7_QueryInterface returned %08x\n", hr);
388 if(hr == DD_OK && D3D1) IDirect3D_Release(D3D1);
390 hr = IDirectDraw_QueryInterface(DDraw1, &IID_IDirect3D, (void **) &D3D1);
391 todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw_QueryInterface returned %08x\n", hr);
392 if(hr == DD_OK && D3D1) IDirect3D_Release(D3D1);
394 hr = IDirect3D7_QueryInterface(D3D7, &IID_IDirect3D, (void **) &D3D1);
395 todo_wine ok(hr == E_NOINTERFACE, "IDirect3D7_QueryInterface returned %08x\n", hr);
396 if(hr == DD_OK && D3D1) IDirect3D_Release(D3D1);
398 /* Try an AddRef, it only affects the AddRefed interface */
399 IDirectDraw4_AddRef(DDraw4);
400 ref = getRefcount( (IUnknown *) DDraw7);
401 ok(ref == 2, "IDirectDraw7 reference count is %ld\n", ref); /* <-- From the d3d query */
402 ref = getRefcount( (IUnknown *) DDraw4);
403 ok(ref == 2, "IDirectDraw4 reference count is %ld\n", ref); /* <-- The AddRef call */
404 ref = getRefcount( (IUnknown *) DDraw2);
405 ok(ref == 1, "IDirectDraw2 reference count is %ld\n", ref);
406 ref = getRefcount( (IUnknown *) DDraw1);
407 ok(ref == 1, "IDirectDraw reference count is %ld\n", ref);
408 ref = getRefcount( (IUnknown *) D3D7);
409 ok(ref == 2, "IDirect3D7 reference count is %ld\n", ref); /* <-- From the d3d query */
410 IDirectDraw4_Release(DDraw4);
412 /* Make sure that they are one object, not different ones */
413 hr = IDirectDraw4_SetCooperativeLevel(DDraw4, GetDesktopWindow(), DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
414 ok(hr == DD_OK, "IDirectDraw4::SetCooperativeLevel returned %08x\n", hr);
415 /* After an window has been set, DDSCL_SETFOCUSWINDOW should return DDERR_HWNDALREADYSET, see the mode test */
416 hr = IDirectDraw7_SetCooperativeLevel(DDraw7, NULL, DDSCL_SETFOCUSWINDOW);
417 ok(hr == DDERR_HWNDALREADYSET, "IDirectDraw7::SetCooperativeLevel returned %08x\n", hr);
419 /* All done, release all interfaces */
420 IDirectDraw7_Release(DDraw7);
421 IDirectDraw4_Release(DDraw4);
422 IDirectDraw2_Release(DDraw2);
423 IDirectDraw_Release(DDraw1);
424 IDirect3D7_Release(D3D7);
427 static void test_d3d_ifaces(void)
429 IDirectDraw *DDraw1;
430 IDirectDraw2 *DDraw2;
431 IDirectDraw4 *DDraw4;
432 IDirect3D *D3D1;
433 IDirect3D2 *D3D2;
434 IDirect3D3 *D3D3;
435 IDirect3D7 *D3D7;
436 HRESULT hr;
437 long ref;
439 hr = DirectDrawCreate(NULL, &DDraw1, NULL);
440 ok(hr == DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", hr);
441 if(!DDraw1)
443 trace("DirectDrawCreate failed with %08x\n", hr);
444 return;
447 hr = IDirectDraw_QueryInterface(DDraw1, &IID_IDirectDraw2, (void **) &DDraw2);
448 ok(hr == DD_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
449 hr = IDirectDraw_QueryInterface(DDraw1, &IID_IDirectDraw4, (void **) &DDraw4);
450 ok(hr == DD_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
452 ref = getRefcount( (IUnknown *) DDraw4);
453 ok(ref == 1, "IDirectDraw4 reference count is %ld\n", ref);
454 ref = getRefcount( (IUnknown *) DDraw2);
455 ok(ref == 1, "IDirectDraw2 reference count is %ld\n", ref);
456 ref = getRefcount( (IUnknown *) DDraw1);
457 ok(ref == 1, "IDirectDraw reference count is %ld\n", ref);
459 hr = IDirectDraw_QueryInterface(DDraw1, &IID_IDirect3D, (void **) &D3D1);
460 if (hr == E_NOINTERFACE) /* win64 */
462 IDirectDraw4_Release(DDraw4);
463 IDirectDraw2_Release(DDraw2);
464 IDirectDraw_Release(DDraw1);
465 skip( "no IDirect3D support\n" );
466 return;
468 ok(hr == DD_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
469 ref = getRefcount( (IUnknown *) DDraw4);
470 ok(ref == 1, "IDirectDraw4 reference count is %ld\n", ref);
471 ref = getRefcount( (IUnknown *) DDraw2);
472 ok(ref == 1, "IDirectDraw2 reference count is %ld\n", ref);
473 ref = getRefcount( (IUnknown *) DDraw1);
474 ok(ref == 2, "IDirectDraw reference count is %ld\n", ref);
475 IDirect3D_Release(D3D1);
477 hr = IDirectDraw2_QueryInterface(DDraw2, &IID_IDirect3D2, (void **) &D3D2);
478 ok(hr == DD_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
479 ref = getRefcount( (IUnknown *) DDraw4);
480 ok(ref == 1, "IDirectDraw4 reference count is %ld\n", ref);
481 ref = getRefcount( (IUnknown *) DDraw2);
482 ok(ref == 1, "IDirectDraw2 reference count is %ld\n", ref);
483 ref = getRefcount( (IUnknown *) DDraw1);
484 ok(ref == 2, "IDirectDraw reference count is %ld\n", ref);
485 IDirect3D2_Release(D3D2);
487 hr = IDirectDraw4_QueryInterface(DDraw4, &IID_IDirect3D3, (void **) &D3D3);
488 ok(hr == DD_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
489 ref = getRefcount( (IUnknown *) DDraw4);
490 ok(ref == 1, "IDirectDraw4 reference count is %ld\n", ref);
491 ref = getRefcount( (IUnknown *) DDraw2);
492 ok(ref == 1, "IDirectDraw2 reference count is %ld\n", ref);
493 ref = getRefcount( (IUnknown *) DDraw1);
494 ok(ref == 2, "IDirectDraw reference count is %ld\n", ref);
495 IDirect3D3_Release(D3D3);
497 /* Try to AddRef the D3D3 interface that has been released already */
498 IDirect3D3_AddRef(D3D3);
499 ref = getRefcount( (IUnknown *) DDraw1);
500 ok(ref == 2, "IDirectDraw reference count is %ld\n", ref);
501 ref = getRefcount( (IUnknown *) D3D3);
502 ok(ref == 2, "IDirect3D3 reference count is %ld\n", ref);
503 /* The newer interfaces remain untouched */
504 ref = getRefcount( (IUnknown *) DDraw4);
505 ok(ref == 1, "IDirectDraw4 reference count is %ld\n", ref);
506 ref = getRefcount( (IUnknown *) DDraw2);
507 ok(ref == 1, "IDirectDraw2 reference count is %ld\n", ref);
508 IDirect3D3_Release(D3D3);
509 ref = getRefcount( (IUnknown *) DDraw1);
510 ok(ref == 1, "IDirectDraw reference count is %ld\n", ref);
511 ref = getRefcount( (IUnknown *) DDraw1);
512 ok(ref == 1, "IDirectDraw reference count is %ld\n", ref);
514 /* It is possible to query any IDirect3D interfaces from any IDirectDraw interface,
515 * Except IDirect3D7, it can only be returned by IDirectDraw7(which can't return older ifaces)
517 hr = IDirectDraw_QueryInterface(DDraw2, &IID_IDirect3D, (void **) &D3D1);
518 ok(hr == DD_OK, "IDirectDraw2_QueryInterface returned %08x\n", hr);
519 IDirect3D_Release(D3D1);
520 hr = IDirectDraw4_QueryInterface(DDraw4, &IID_IDirect3D, (void **) &D3D1);
521 ok(hr == DD_OK, "IDirectDraw4_QueryInterface returned %08x\n", hr);
522 IDirect3D_Release(D3D1);
524 hr = IDirectDraw_QueryInterface(DDraw1, &IID_IDirect3D2, (void **) &D3D2);
525 ok(hr == DD_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
526 IDirect3D_Release(D3D2);
527 hr = IDirectDraw4_QueryInterface(DDraw4, &IID_IDirect3D2, (void **) &D3D2);
528 ok(hr == DD_OK, "IDirectDraw4_QueryInterface returned %08x\n", hr);
529 IDirect3D_Release(D3D2);
531 hr = IDirectDraw_QueryInterface(DDraw1, &IID_IDirect3D3, (void **) &D3D3);
532 ok(hr == DD_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
533 IDirect3D_Release(D3D3);
534 hr = IDirectDraw2_QueryInterface(DDraw2, &IID_IDirect3D3, (void **) &D3D3);
535 ok(hr == DD_OK, "IDirectDraw2_QueryInterface returned %08x\n", hr);
536 IDirect3D_Release(D3D3);
538 /* This does NOT work */
539 hr = IDirectDraw_QueryInterface(DDraw1, &IID_IDirect3D7, (void **) &D3D7);
540 todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw_QueryInterface returned %08x\n", hr);
541 if(D3D7) IDirect3D_Release(D3D7);
542 hr = IDirectDraw2_QueryInterface(DDraw2, &IID_IDirect3D7, (void **) &D3D7);
543 todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw2_QueryInterface returned %08x\n", hr);
544 if(D3D7) IDirect3D_Release(D3D7);
545 hr = IDirectDraw4_QueryInterface(DDraw4, &IID_IDirect3D7, (void **) &D3D7);
546 todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw4_QueryInterface returned %08x\n", hr);
547 if(D3D7) IDirect3D_Release(D3D7);
549 /* Release the interfaces */
550 IDirectDraw4_Release(DDraw4);
551 IDirectDraw2_Release(DDraw2);
552 IDirectDraw_Release(DDraw1);
555 START_TEST(refcount)
557 init_function_pointers();
558 if(!pDirectDrawCreateEx)
560 win_skip("function DirectDrawCreateEx not available\n");
561 return;
563 test_ddraw_objects();
564 test_iface_refcnt();
565 test_d3d_ifaces();