Remove unneeded checks on the GetModuleHandle() return value for cases where we are...
[wine] / dlls / ddraw / tests / refcount.c
1 /*
2  * Some unit tests for ddraw reference counting
3  *
4  * Copyright (C) 2006 Stefan Dösinger
5  *
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.
10  *
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.
15  *
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
19  */
20 #define COBJMACROS
21
22 #include <assert.h>
23 #include "wine/test.h"
24 #include "ddraw.h"
25 #include "d3d.h"
26 #include "unknwn.h"
27
28 static HRESULT (WINAPI *pDirectDrawCreateEx)(LPGUID,LPVOID*,REFIID,LPUNKNOWN);
29
30 static void init_function_pointers(void)
31 {
32     HMODULE hmod = GetModuleHandleA("ddraw.dll");
33     pDirectDrawCreateEx = (void*)GetProcAddress(hmod, "DirectDrawCreateEx");
34 }
35
36 static unsigned long getRefcount(IUnknown *iface)
37 {
38     IUnknown_AddRef(iface);
39     return IUnknown_Release(iface);
40 }
41
42 static void test_ddraw_objects(void)
43 {
44     HRESULT hr;
45     unsigned long ref;
46     IDirectDraw7 *DDraw7;
47     IDirectDraw4 *DDraw4;
48     IDirectDraw2 *DDraw2;
49     IDirectDraw  *DDraw1;
50     IDirectDrawPalette *palette;
51     IDirectDrawSurface7 *surface;
52     IDirectDrawSurface *surface1;
53     IDirectDrawSurface4 *surface4;
54     PALETTEENTRY Table[256];
55     DDSURFACEDESC2 ddsd;
56
57     hr = pDirectDrawCreateEx(NULL, (void **) &DDraw7, &IID_IDirectDraw7, NULL);
58     ok(hr == DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", hr);
59     if(!DDraw7)
60     {
61         trace("Couldn't create DDraw interface, skipping tests\n");
62         return;
63     }
64
65     hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirectDraw4, (void **) &DDraw4);
66     ok(hr == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);
67     hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirectDraw2, (void **) &DDraw2);
68     ok(hr == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);
69     hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirectDraw, (void **) &DDraw1);
70     ok(hr == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);
71
72     ref = getRefcount( (IUnknown *) DDraw7);
73     ok(ref == 1, "Got refcount %ld, expected 1\n", ref);
74
75     /* Fails without a cooplevel */
76     hr = IDirectDraw7_CreatePalette(DDraw7, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
77     ok(hr == DDERR_NOCOOPERATIVELEVELSET, "CreatePalette returned %08x\n", hr);
78
79     /* This check is before the cooplevel check */
80     hr = IDirectDraw7_CreatePalette(DDraw7, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, (void *) 0xdeadbeef);
81     ok(hr == CLASS_E_NOAGGREGATION, "CreatePalette returned %08x\n", hr);
82
83     hr = IDirectDraw7_SetCooperativeLevel(DDraw7, 0, DDSCL_NORMAL);
84     ok(hr == DD_OK, "SetCooperativeLevel failed with %08x\n", hr);
85
86     memset(&ddsd, 0, sizeof(ddsd));
87     ddsd.dwSize = sizeof(ddsd);
88     ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
89     ddsd.dwWidth = 64;
90     ddsd.dwHeight = 64;
91     ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
92     U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
93     U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
94     U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 8;
95
96     hr = IDirectDraw7_CreateSurface(DDraw7, &ddsd, &surface, NULL);
97     ok(hr == DD_OK, "CreateSurface failed with %08x\n", hr);
98
99     /* DDraw refcount increased by 1 */
100     ref = getRefcount( (IUnknown *) DDraw7);
101     ok(ref == 2, "Got refcount %ld, expected 2\n", ref);
102
103     /* Surface refcount starts with 1 */
104     ref = getRefcount( (IUnknown *) surface);
105     ok(ref == 1, "Got refcount %ld, expected 1\n", ref);
106
107     hr = IDirectDraw7_CreatePalette(DDraw7, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
108     ok(hr == DD_OK, "CreatePalette returned %08x\n", hr);
109
110     /* DDraw refcount increased by 1 */
111     ref = getRefcount( (IUnknown *) DDraw7);
112     ok(ref == 3, "Got refcount %ld, expected 3\n", ref);
113
114     /* Palette starts with 1 */
115     ref = getRefcount( (IUnknown *) palette);
116     ok(ref == 1, "Got refcount %ld, expected 1\n", ref);
117
118     /* Test attaching a palette to a surface */
119     hr = IDirectDrawSurface7_SetPalette(surface, palette);
120     ok(hr == DD_OK, "IDirectDrawSurface_SetPalette failed with %08x\n", hr);
121
122     /* Palette refcount increased, surface stays the same */
123     ref = getRefcount( (IUnknown *) palette);
124     ok(ref == 2, "Got refcount %ld, expected 2\n", ref);
125     ref = getRefcount( (IUnknown *) surface);
126     ok(ref == 1, "Got refcount %ld, expected 1\n", ref);
127
128     IDirectDrawSurface7_Release(surface);
129     /* Increased before - decrease now */
130     ref = getRefcount( (IUnknown *) DDraw7);
131     ok(ref == 2, "Got refcount %ld, expected 2\n", ref);
132
133     /* Releasing the surface detaches the palette */
134     ref = getRefcount( (IUnknown *) palette);
135     ok(ref == 1, "Got refcount %ld, expected 1\n", ref);
136
137     IDirectDrawPalette_Release(palette);
138
139     /* Increased before - decrease now */
140     ref = getRefcount( (IUnknown *) DDraw7);
141     ok(ref == 1, "Got refcount %ld, expected 1\n", ref);
142
143     /* Not all interfaces are AddRefed when a palette is created */
144     hr = IDirectDraw4_CreatePalette(DDraw4, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
145     ok(hr == DD_OK, "CreatePalette returned %08x\n", hr);
146     ref = getRefcount( (IUnknown *) DDraw4);
147     ok(ref == 2, "Got refcount %ld, expected 2\n", ref);
148     IDirectDrawPalette_Release(palette);
149
150     /* No addref here */
151     hr = IDirectDraw2_CreatePalette(DDraw2, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
152     ok(hr == DD_OK, "CreatePalette returned %08x\n", hr);
153     ref = getRefcount( (IUnknown *) DDraw2);
154     ok(ref == 1, "Got refcount %ld, expected 1\n", ref);
155     IDirectDrawPalette_Release(palette);
156
157     /* No addref here */
158     hr = IDirectDraw_CreatePalette(DDraw1, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
159     ok(hr == DD_OK, "CreatePalette returned %08x\n", hr);
160     ref = getRefcount( (IUnknown *) DDraw1);
161     ok(ref == 1, "Got refcount %ld, expected 1\n", ref);
162     IDirectDrawPalette_Release(palette);
163
164     /* Similar for surfaces */
165     hr = IDirectDraw4_CreateSurface(DDraw4, &ddsd, &surface4, NULL);
166     ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
167     ref = getRefcount( (IUnknown *) DDraw4);
168     ok(ref == 2, "Got refcount %ld, expected 2\n", ref);
169     IDirectDrawSurface4_Release(surface4);
170
171     ddsd.dwSize = sizeof(DDSURFACEDESC);
172     hr = IDirectDraw2_CreateSurface(DDraw2, (DDSURFACEDESC *) &ddsd, &surface1, NULL);
173     ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
174     ref = getRefcount( (IUnknown *) DDraw2);
175     ok(ref == 1, "Got refcount %ld, expected 1\n", ref);
176     IDirectDrawSurface_Release(surface1);
177
178     hr = IDirectDraw_CreateSurface(DDraw1, (DDSURFACEDESC *) &ddsd, &surface1, NULL);
179     ok(hr == DD_OK, "CreateSurface returned %08x\n", hr);
180     ref = getRefcount( (IUnknown *) DDraw1);
181     ok(ref == 1, "Got refcount %ld, expected 1\n", ref);
182     IDirectDrawSurface_Release(surface1);
183
184     IDirectDraw7_Release(DDraw7);
185     IDirectDraw4_Release(DDraw4);
186     IDirectDraw2_Release(DDraw2);
187     IDirectDraw_Release(DDraw1);
188 }
189
190 static void test_iface_refcnt(void)
191 {
192     HRESULT hr;
193     IDirectDraw  *DDraw1;
194     IDirectDraw2 *DDraw2;
195     IDirectDraw4 *DDraw4;
196     IDirectDraw7 *DDraw7;
197     IDirect3D7   *D3D7;
198     IDirect3D3   *D3D3;
199     IDirect3D2   *D3D2;
200     IDirect3D    *D3D1;
201     long ref;
202
203     hr = pDirectDrawCreateEx(NULL, (void **) &DDraw7, &IID_IDirectDraw7, NULL);
204     ok(hr == DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", hr);
205     if(!DDraw7)
206     {
207         trace("Couldn't create DDraw interface, skipping tests\n");
208         return;
209     }
210
211     ref = getRefcount( (IUnknown *) DDraw7);
212     ok(ref == 1, "Initial IDirectDraw7 reference count is %ld\n", ref);
213
214     hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirectDraw4, (void **) &DDraw4);
215     ok(hr == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);
216     hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirectDraw2, (void **) &DDraw2);
217     ok(hr == DD_OK, "IDirectDraw7_QueryInterf&ace returned %08x\n", hr);
218     hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirectDraw, (void **) &DDraw1);
219     ok(hr == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);
220
221     /* All interfaces now have refcount 1! */
222     ref = getRefcount( (IUnknown *) DDraw7);
223     ok(ref == 1, "IDirectDraw7 reference count is %ld\n", ref);
224     ref = getRefcount( (IUnknown *) DDraw7);
225     ok(ref == 1, "IDirectDraw7 reference count is %ld\n", ref);
226     ref = getRefcount( (IUnknown *) DDraw4);
227     ok(ref == 1, "IDirectDraw4 reference count is %ld\n", ref);
228     ref = getRefcount( (IUnknown *) DDraw2);
229     ok(ref == 1, "IDirectDraw2 reference count is %ld\n", ref);
230     ref = getRefcount( (IUnknown *) DDraw1);
231     ok(ref == 1, "IDirectDraw reference count is %ld\n", ref);
232
233     hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirect3D7, (void **) &D3D7);
234     ok(hr == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);
235
236     /* Apparently IDirectDrawX and IDirect3DX are linked together */
237     ref = getRefcount( (IUnknown *) D3D7);
238     ok(ref == 2, "IDirect3D7 reference count is %ld\n", ref);
239     ref = getRefcount( (IUnknown *) DDraw7);
240     ok(ref == 2, "IDirectDraw7 reference count is %ld\n", ref);
241
242     IDirectDraw7_AddRef(DDraw7);
243     ref = getRefcount( (IUnknown *) D3D7);
244     ok(ref == 3, "IDirect3D7 reference count is %ld\n", ref);
245     ref = getRefcount( (IUnknown *) DDraw7);
246     ok(ref == 3, "IDirectDraw7 reference count is %ld\n", ref);
247
248     IDirect3D7_Release(D3D7);
249     ref = getRefcount( (IUnknown *) D3D7);
250     ok(ref == 2, "IDirect3D7 reference count is %ld\n", ref);
251     ref = getRefcount( (IUnknown *) DDraw7);
252     ok(ref == 2, "IDirectDraw7 reference count is %ld\n", ref);
253
254     /* Can't get older d3d interfaces. WHY????? */
255     hr = IDirectDraw7_QueryInterface(DDraw4, &IID_IDirect3D3, (void **) &D3D3);
256     todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw7_QueryInterface returned %08x\n", hr);
257     if(hr == DD_OK && D3D3) IDirect3D3_Release(D3D3);
258
259     hr = IDirectDraw4_QueryInterface(DDraw4, &IID_IDirect3D3, (void **) &D3D3);
260     todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw4_QueryInterface returned %08x\n", hr);
261     if(hr == DD_OK && D3D3) IDirect3D3_Release(D3D3);
262
263     hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirect3D2, (void **) &D3D2);
264     todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw7_QueryInterface returned %08x\n", hr);
265     if(hr == DD_OK && D3D2) IDirect3D2_Release(D3D2);
266
267     hr = IDirectDraw2_QueryInterface(DDraw2, &IID_IDirect3D2, (void **) &D3D2);
268     todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw2_QueryInterface returned %08x\n", hr);
269     if(hr == DD_OK && D3D2) IDirect3D2_Release(D3D2);
270
271     hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirect3D, (void **) &D3D1);
272     todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw7_QueryInterface returned %08x\n", hr);
273     if(hr == DD_OK && D3D1) IDirect3D_Release(D3D1);
274
275     hr = IDirectDraw_QueryInterface(DDraw1, &IID_IDirect3D, (void **) &D3D1);
276     todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw_QueryInterface returned %08x\n", hr);
277     if(hr == DD_OK && D3D1) IDirect3D_Release(D3D1);
278
279     hr = IDirect3D7_QueryInterface(D3D7, &IID_IDirect3D, (void **) &D3D1);
280     todo_wine ok(hr == E_NOINTERFACE, "IDirect3D7_QueryInterface returned %08x\n", hr);
281     if(hr == DD_OK && D3D1) IDirect3D_Release(D3D1);
282
283     /* Try an AddRef, it only affects the AddRefed interface */
284     IDirectDraw4_AddRef(DDraw4);
285     ref = getRefcount( (IUnknown *) DDraw7);
286     ok(ref == 2, "IDirectDraw7 reference count is %ld\n", ref); /* <-- From the d3d query */
287     ref = getRefcount( (IUnknown *) DDraw4);
288     ok(ref == 2, "IDirectDraw4 reference count is %ld\n", ref); /* <-- The AddRef call */
289     ref = getRefcount( (IUnknown *) DDraw2);
290     ok(ref == 1, "IDirectDraw2 reference count is %ld\n", ref);
291     ref = getRefcount( (IUnknown *) DDraw1);
292     ok(ref == 1, "IDirectDraw reference count is %ld\n", ref);
293     ref = getRefcount( (IUnknown *) D3D7);
294     ok(ref == 2, "IDirect3D7 reference count is %ld\n", ref); /* <-- From the d3d query */
295     IDirectDraw4_Release(DDraw4);
296
297     /* Make sure that they are one object, not different ones */
298     hr = IDirectDraw4_SetCooperativeLevel(DDraw4, GetDesktopWindow(), DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
299     ok(hr == DD_OK, "IDirectDraw4::SetCooperativeLevel returned %08x\n", hr);
300     /* After an window has been set, DDSCL_SETFOCUSWINDOW should return DDERR_HWNDALREADYSET, see the mode test */
301     hr = IDirectDraw7_SetCooperativeLevel(DDraw7, NULL, DDSCL_SETFOCUSWINDOW);
302     ok(hr == DDERR_HWNDALREADYSET, "IDirectDraw7::SetCooperativeLevel returned %08x\n", hr);
303
304     /* All done, release all interfaces */
305     IDirectDraw7_Release(DDraw7);
306     IDirectDraw4_Release(DDraw4);
307     IDirectDraw2_Release(DDraw2);
308     IDirectDraw_Release(DDraw1);
309     IDirect3D7_Release(D3D7);
310 }
311
312 static void test_d3d_ifaces(void)
313 {
314     IDirectDraw *DDraw1;
315     IDirectDraw2 *DDraw2;
316     IDirectDraw4 *DDraw4;
317     IDirect3D *D3D1;
318     IDirect3D2 *D3D2;
319     IDirect3D3 *D3D3;
320     IDirect3D7 *D3D7;
321     HRESULT hr;
322     long ref;
323
324     hr = DirectDrawCreate(NULL, &DDraw1, NULL);
325     ok(hr == DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", hr);
326     if(!DDraw1)
327     {
328         trace("DirectDrawCreate failed with %08x\n", hr);
329         return;
330     }
331
332     hr = IDirectDraw_QueryInterface(DDraw1, &IID_IDirectDraw2, (void **) &DDraw2);
333     ok(hr == DD_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
334     hr = IDirectDraw_QueryInterface(DDraw1, &IID_IDirectDraw4, (void **) &DDraw4);
335     ok(hr == DD_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
336
337     ref = getRefcount( (IUnknown *) DDraw4);
338     ok(ref == 1, "IDirectDraw4 reference count is %ld\n", ref);
339     ref = getRefcount( (IUnknown *) DDraw2);
340     ok(ref == 1, "IDirectDraw2 reference count is %ld\n", ref);
341     ref = getRefcount( (IUnknown *) DDraw1);
342     ok(ref == 1, "IDirectDraw reference count is %ld\n", ref);
343
344     hr = IDirectDraw_QueryInterface(DDraw1, &IID_IDirect3D, (void **) &D3D1);
345     ok(hr == DD_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
346     ref = getRefcount( (IUnknown *) DDraw4);
347     ok(ref == 1, "IDirectDraw4 reference count is %ld\n", ref);
348     ref = getRefcount( (IUnknown *) DDraw2);
349     ok(ref == 1, "IDirectDraw2 reference count is %ld\n", ref);
350     ref = getRefcount( (IUnknown *) DDraw1);
351     ok(ref == 2, "IDirectDraw reference count is %ld\n", ref);
352     IDirect3D_Release(D3D1);
353
354     hr = IDirectDraw2_QueryInterface(DDraw2, &IID_IDirect3D2, (void **) &D3D2);
355     ok(hr == DD_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
356     ref = getRefcount( (IUnknown *) DDraw4);
357     ok(ref == 1, "IDirectDraw4 reference count is %ld\n", ref);
358     ref = getRefcount( (IUnknown *) DDraw2);
359     ok(ref == 1, "IDirectDraw2 reference count is %ld\n", ref);
360     ref = getRefcount( (IUnknown *) DDraw1);
361     ok(ref == 2, "IDirectDraw reference count is %ld\n", ref);
362     IDirect3D2_Release(D3D2);
363
364     hr = IDirectDraw4_QueryInterface(DDraw4, &IID_IDirect3D3, (void **) &D3D3);
365     ok(hr == DD_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
366     ref = getRefcount( (IUnknown *) DDraw4);
367     ok(ref == 1, "IDirectDraw4 reference count is %ld\n", ref);
368     ref = getRefcount( (IUnknown *) DDraw2);
369     ok(ref == 1, "IDirectDraw2 reference count is %ld\n", ref);
370     ref = getRefcount( (IUnknown *) DDraw1);
371     ok(ref == 2, "IDirectDraw reference count is %ld\n", ref);
372     IDirect3D3_Release(D3D3);
373
374     /* Try to AddRef the D3D3 interface that has been released already */
375     IDirect3D3_AddRef(D3D3);
376     ref = getRefcount( (IUnknown *) DDraw1);
377     ok(ref == 2, "IDirectDraw reference count is %ld\n", ref);
378     ref = getRefcount( (IUnknown *) D3D3);
379     ok(ref == 2, "IDirect3D3 reference count is %ld\n", ref);
380     /* The newer interfaces remain untouched */
381     ref = getRefcount( (IUnknown *) DDraw4);
382     ok(ref == 1, "IDirectDraw4 reference count is %ld\n", ref);
383     ref = getRefcount( (IUnknown *) DDraw2);
384     ok(ref == 1, "IDirectDraw2 reference count is %ld\n", ref);
385     IDirect3D3_Release(D3D3);
386     ref = getRefcount( (IUnknown *) DDraw1);
387     ok(ref == 1, "IDirectDraw reference count is %ld\n", ref);
388     ref = getRefcount( (IUnknown *) DDraw1);
389     ok(ref == 1, "IDirectDraw reference count is %ld\n", ref);
390
391     /* It is possible to query any IDirect3D interfaces from any IDirectDraw interface,
392      * Except IDirect3D7, it can only be returned by IDirectDraw7(which can't return older ifaces)
393      */
394     hr = IDirectDraw_QueryInterface(DDraw2, &IID_IDirect3D, (void **) &D3D1);
395     ok(hr == DD_OK, "IDirectDraw2_QueryInterface returned %08x\n", hr);
396     IDirect3D_Release(D3D1);
397     hr = IDirectDraw4_QueryInterface(DDraw4, &IID_IDirect3D, (void **) &D3D1);
398     ok(hr == DD_OK, "IDirectDraw4_QueryInterface returned %08x\n", hr);
399     IDirect3D_Release(D3D1);
400
401     hr = IDirectDraw_QueryInterface(DDraw1, &IID_IDirect3D2, (void **) &D3D2);
402     ok(hr == DD_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
403     IDirect3D_Release(D3D2);
404     hr = IDirectDraw4_QueryInterface(DDraw4, &IID_IDirect3D2, (void **) &D3D2);
405     ok(hr == DD_OK, "IDirectDraw4_QueryInterface returned %08x\n", hr);
406     IDirect3D_Release(D3D2);
407
408     hr = IDirectDraw_QueryInterface(DDraw1, &IID_IDirect3D3, (void **) &D3D3);
409     ok(hr == DD_OK, "IDirectDraw_QueryInterface returned %08x\n", hr);
410     IDirect3D_Release(D3D3);
411     hr = IDirectDraw2_QueryInterface(DDraw2, &IID_IDirect3D3, (void **) &D3D3);
412     ok(hr == DD_OK, "IDirectDraw2_QueryInterface returned %08x\n", hr);
413     IDirect3D_Release(D3D3);
414
415     /* This does NOT work */
416     hr = IDirectDraw_QueryInterface(DDraw1, &IID_IDirect3D7, (void **) &D3D7);
417     todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw_QueryInterface returned %08x\n", hr);
418     if(D3D7) IDirect3D_Release(D3D7);
419     hr = IDirectDraw2_QueryInterface(DDraw2, &IID_IDirect3D7, (void **) &D3D7);
420     todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw2_QueryInterface returned %08x\n", hr);
421     if(D3D7) IDirect3D_Release(D3D7);
422     hr = IDirectDraw4_QueryInterface(DDraw4, &IID_IDirect3D7, (void **) &D3D7);
423     todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw4_QueryInterface returned %08x\n", hr);
424     if(D3D7) IDirect3D_Release(D3D7);
425
426     /* Release the interfaces */
427     IDirectDraw4_Release(DDraw4);
428     IDirectDraw2_Release(DDraw2);
429     IDirectDraw_Release(DDraw1);
430 }
431
432 START_TEST(refcount)
433 {
434     init_function_pointers();
435     if(!pDirectDrawCreateEx)
436     {
437         trace("function DirectDrawCreateEx not available, skipping tests\n");
438         return;
439     }
440     test_ddraw_objects();
441     test_iface_refcnt();
442     test_d3d_ifaces();
443 }