tests: Don't depend on the static uuid libraries in the tests.
[wine] / dlls / d3d9 / tests / d3d9ex.c
1 /*
2  * Copyright (C) 2008 Stefan Dösinger(for CodeWeavers)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 /* This file contains tests specific to IDirect3D9Ex and IDirect3DDevice9Ex, like
20  * how to obtain them. For testing rendering with extended functions use visual.c
21  */
22
23 #define COBJMACROS
24 #include <initguid.h>
25 #include <d3d9.h>
26 #include <dxerr9.h>
27 #include "wine/test.h"
28
29 static HMODULE d3d9_handle = 0;
30
31 static IDirect3D9 * (WINAPI *pDirect3DCreate9)(UINT SDKVersion);
32 static HRESULT (WINAPI *pDirect3DCreate9Ex)(UINT SDKVersion, IDirect3D9Ex **d3d9ex);
33
34 static HWND create_window(void)
35 {
36     WNDCLASS wc = {0};
37     HWND ret;
38     wc.lpfnWndProc = DefWindowProc;
39     wc.lpszClassName = "d3d9_test_wc";
40     RegisterClass(&wc);
41
42     ret = CreateWindow("d3d9_test_wc", "d3d9_test",
43                         WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
44     return ret;
45 }
46
47 static unsigned long getref(IUnknown *obj) {
48     IUnknown_AddRef(obj);
49     return IUnknown_Release(obj);
50 }
51
52 static void test_qi_base_to_ex(void)
53 {
54     IDirect3D9 *d3d9 = pDirect3DCreate9(D3D_SDK_VERSION);
55     IDirect3D9Ex *d3d9ex = (void *) 0xdeadbeef;
56     IDirect3DDevice9 *device;
57     IDirect3DDevice9Ex *deviceEx = (void *) 0xdeadbeef;
58     HRESULT hr;
59     HWND window = create_window();
60     D3DPRESENT_PARAMETERS present_parameters;
61
62     ok( d3d9 != NULL, "Failed to create D3D9 object\n" );
63     if (!d3d9) return;
64
65     hr = IDirect3D9_QueryInterface(d3d9, &IID_IDirect3D9Ex, (void **) &d3d9ex);
66     ok(hr == E_NOINTERFACE,
67        "IDirect3D9::QueryInterface for IID_IDirect3D9Ex returned %s, expected E_NOINTERFACE\n",
68        DXGetErrorString9(hr));
69     ok(d3d9ex == NULL, "QueryInterface returned interface %p, expected NULL\n", d3d9ex);
70     if(d3d9ex) IDirect3D9Ex_Release(d3d9ex);
71
72     memset(&present_parameters, 0, sizeof(present_parameters));
73     present_parameters.Windowed = TRUE;
74     present_parameters.hDeviceWindow = window;
75     present_parameters.SwapEffect = D3DSWAPEFFECT_COPY;
76     present_parameters.BackBufferWidth = 640;
77     present_parameters.BackBufferHeight = 480;
78     present_parameters.EnableAutoDepthStencil = FALSE;
79     present_parameters.AutoDepthStencilFormat = D3DFMT_D16;
80     hr = IDirect3D9_CreateDevice(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
81     if(FAILED(hr)) {
82         skip("Failed to create a regular Direct3DDevice9, skipping QI tests\n");
83         goto out;
84     }
85
86     hr = IDirect3DDevice9_QueryInterface(device, &IID_IDirect3DDevice9Ex, (void **) &deviceEx);
87     ok(hr == E_NOINTERFACE,
88        "IDirect3D9Device::QueryInterface for IID_IDirect3DDevice9Ex returned %s, expected E_NOINTERFACE\n",
89        DXGetErrorString9(hr));
90     ok(deviceEx == NULL, "QueryInterface returned interface %p, expected NULL\n", deviceEx);
91     if(deviceEx) IDirect3DDevice9Ex_Release(deviceEx);
92
93     IDirect3DDevice9_Release(device);
94
95 out:
96     IDirect3D9_Release(d3d9);
97     DestroyWindow(window);
98 }
99
100 static void test_qi_ex_to_base(void)
101 {
102     IDirect3D9 *d3d9 = (void *) 0xdeadbeef;
103     IDirect3D9Ex *d3d9ex;
104     IDirect3DDevice9 *device;
105     IDirect3DDevice9Ex *deviceEx = (void *) 0xdeadbeef;
106     HRESULT hr;
107     HWND window = create_window();
108     D3DPRESENT_PARAMETERS present_parameters;
109     unsigned long ref;
110
111     hr = pDirect3DCreate9Ex(D3D_SDK_VERSION, &d3d9ex);
112     ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE, "Direct3DCreate9Ex returned %s\n", DXGetErrorString9(hr));
113     if(FAILED(hr)) {
114         skip("Direct3D9Ex is not available\n");
115         goto out;
116     }
117
118     hr = IDirect3D9Ex_QueryInterface(d3d9ex, &IID_IDirect3D9, (void **) &d3d9);
119     ok(hr == D3D_OK,
120        "IDirect3D9Ex::QueryInterface for IID_IDirect3D9 returned %s, expected D3D_OK\n",
121        DXGetErrorString9(hr));
122     ok(d3d9 != NULL && d3d9 != (void *) 0xdeadbeef,
123        "QueryInterface returned interface %p, expected != NULL && != 0xdeadbeef\n", d3d9);
124     ref = getref((IUnknown *) d3d9ex);
125     ok(ref == 2, "IDirect3D9Ex refcount is %ld, expected 2\n", ref);
126     ref = getref((IUnknown *) d3d9);
127     ok(ref == 2, "IDirect3D9 refcount is %ld, expected 2\n", ref);
128
129     memset(&present_parameters, 0, sizeof(present_parameters));
130     present_parameters.Windowed = TRUE;
131     present_parameters.hDeviceWindow = window;
132     present_parameters.SwapEffect = D3DSWAPEFFECT_COPY;
133     present_parameters.BackBufferWidth = 640;
134     present_parameters.BackBufferHeight = 480;
135     present_parameters.EnableAutoDepthStencil = FALSE;
136     present_parameters.AutoDepthStencilFormat = D3DFMT_D16;
137
138     /* First, try to create a normal device with IDirect3D9Ex::CreateDevice and QI it for IDirect3DDevice9Ex */
139     hr = IDirect3D9Ex_CreateDevice(d3d9ex, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
140     if(FAILED(hr)) {
141         skip("Failed to create a regular Direct3DDevice9, skipping QI tests\n");
142         goto out;
143     }
144
145     hr = IDirect3DDevice9_QueryInterface(device, &IID_IDirect3DDevice9Ex, (void **) &deviceEx);
146     ok(hr == D3D_OK,
147        "IDirect3D9Device::QueryInterface for IID_IDirect3DDevice9Ex returned %s, expected D3D_OK\n",
148        DXGetErrorString9(hr));
149     ok(deviceEx != NULL && deviceEx != (void *) 0xdeadbeef,
150        "QueryInterface returned interface %p, expected != NULL && != 0xdeadbeef\n", deviceEx);
151     ref = getref((IUnknown *) device);
152     ok(ref == 2, "IDirect3DDevice9 refcount is %ld, expected 2\n", ref);
153     ref = getref((IUnknown *) deviceEx);
154     ok(ref == 2, "IDirect3DDevice9Ex refcount is %ld, expected 2\n", ref);
155     if(deviceEx) IDirect3DDevice9Ex_Release(deviceEx);
156     IDirect3DDevice9_Release(device);
157
158     /* Next, try to create a normal device with IDirect3D9::CreateDevice(non-ex) and QI it */
159     hr = IDirect3D9_CreateDevice(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
160     if(FAILED(hr)) {
161         skip("Failed to create a regular Direct3DDevice9, skipping QI tests\n");
162         goto out;
163     }
164
165     hr = IDirect3DDevice9_QueryInterface(device, &IID_IDirect3DDevice9Ex, (void **) &deviceEx);
166     ok(hr == D3D_OK,
167        "IDirect3D9Device::QueryInterface for IID_IDirect3DDevice9Ex returned %s, expected D3D_OK\n",
168        DXGetErrorString9(hr));
169     ok(deviceEx != NULL && deviceEx != (void *) 0xdeadbeef,
170        "QueryInterface returned interface %p, expected != NULL && != 0xdeadbeef\n", deviceEx);
171     ref = getref((IUnknown *) device);
172     ok(ref == 2, "IDirect3DDevice9 refcount is %ld, expected 2\n", ref);
173     ref = getref((IUnknown *) deviceEx);
174     ok(ref == 2, "IDirect3DDevice9Ex refcount is %ld, expected 2\n", ref);
175     if(deviceEx) IDirect3DDevice9Ex_Release(deviceEx);
176     IDirect3DDevice9_Release(device);
177
178     IDirect3D9_Release(d3d9);
179
180 out:
181     DestroyWindow(window);
182 }
183
184 START_TEST(d3d9ex)
185 {
186     d3d9_handle = LoadLibraryA("d3d9.dll");
187     if (!d3d9_handle)
188     {
189         skip("Could not load d3d9.dll\n");
190         return;
191     }
192     pDirect3DCreate9 = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9");
193     ok(pDirect3DCreate9 != NULL, "Failed to get address of Direct3DCreate9\n");
194     if(!pDirect3DCreate9) {
195         return;
196     }
197
198     pDirect3DCreate9Ex = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9Ex");
199     if (!pDirect3DCreate9Ex) {
200         skip("Failed to get address of Direct3DCreate9Ex\n");
201         return;
202     }
203
204     test_qi_base_to_ex();
205     test_qi_ex_to_base();
206 }