push 149f0a5527ac85057a8ef03858d34d91c36f97e8
[wine/hacks.git] / dlls / d3d9 / tests / d3d9ex.c
blob1a052acc290b6836013052b9042df21805b95005
1 /*
2 * Copyright (C) 2008 Stefan Dösinger(for CodeWeavers)
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.
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.
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
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
23 #define COBJMACROS
24 #include <initguid.h>
25 #include <d3d9.h>
26 #include "wine/test.h"
28 static HMODULE d3d9_handle = 0;
30 static IDirect3D9 * (WINAPI *pDirect3DCreate9)(UINT SDKVersion);
31 static HRESULT (WINAPI *pDirect3DCreate9Ex)(UINT SDKVersion, IDirect3D9Ex **d3d9ex);
33 static HWND create_window(void)
35 WNDCLASS wc = {0};
36 HWND ret;
37 wc.lpfnWndProc = DefWindowProc;
38 wc.lpszClassName = "d3d9_test_wc";
39 RegisterClass(&wc);
41 ret = CreateWindow("d3d9_test_wc", "d3d9_test",
42 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
43 return ret;
46 static ULONG getref(IUnknown *obj) {
47 IUnknown_AddRef(obj);
48 return IUnknown_Release(obj);
51 static void test_qi_base_to_ex(void)
53 IDirect3D9 *d3d9 = pDirect3DCreate9(D3D_SDK_VERSION);
54 IDirect3D9Ex *d3d9ex = (void *) 0xdeadbeef;
55 IDirect3DDevice9 *device;
56 IDirect3DDevice9Ex *deviceEx = (void *) 0xdeadbeef;
57 HRESULT hr;
58 HWND window = create_window();
59 D3DPRESENT_PARAMETERS present_parameters;
61 if (!d3d9)
63 skip("Direct3D9 is not available\n");
64 return;
67 hr = IDirect3D9_QueryInterface(d3d9, &IID_IDirect3D9Ex, (void **) &d3d9ex);
68 ok(hr == E_NOINTERFACE,
69 "IDirect3D9::QueryInterface for IID_IDirect3D9Ex returned %08x, expected E_NOINTERFACE\n",
70 hr);
71 ok(d3d9ex == NULL, "QueryInterface returned interface %p, expected NULL\n", d3d9ex);
72 if(d3d9ex) IDirect3D9Ex_Release(d3d9ex);
74 memset(&present_parameters, 0, sizeof(present_parameters));
75 present_parameters.Windowed = TRUE;
76 present_parameters.hDeviceWindow = window;
77 present_parameters.SwapEffect = D3DSWAPEFFECT_COPY;
78 present_parameters.BackBufferWidth = 640;
79 present_parameters.BackBufferHeight = 480;
80 present_parameters.EnableAutoDepthStencil = FALSE;
81 present_parameters.AutoDepthStencilFormat = D3DFMT_D16;
82 hr = IDirect3D9_CreateDevice(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
83 if(FAILED(hr)) {
84 skip("Failed to create a regular Direct3DDevice9, skipping QI tests\n");
85 goto out;
88 hr = IDirect3DDevice9_QueryInterface(device, &IID_IDirect3DDevice9Ex, (void **) &deviceEx);
89 ok(hr == E_NOINTERFACE,
90 "IDirect3D9Device::QueryInterface for IID_IDirect3DDevice9Ex returned %08x, expected E_NOINTERFACE\n",
91 hr);
92 ok(deviceEx == NULL, "QueryInterface returned interface %p, expected NULL\n", deviceEx);
93 if(deviceEx) IDirect3DDevice9Ex_Release(deviceEx);
95 IDirect3DDevice9_Release(device);
97 out:
98 IDirect3D9_Release(d3d9);
99 DestroyWindow(window);
102 static void test_qi_ex_to_base(void)
104 IDirect3D9 *d3d9 = (void *) 0xdeadbeef;
105 IDirect3D9Ex *d3d9ex;
106 IDirect3DDevice9 *device;
107 IDirect3DDevice9Ex *deviceEx = (void *) 0xdeadbeef;
108 HRESULT hr;
109 HWND window = create_window();
110 D3DPRESENT_PARAMETERS present_parameters;
111 ULONG ref;
113 hr = pDirect3DCreate9Ex(D3D_SDK_VERSION, &d3d9ex);
114 ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE, "Direct3DCreate9Ex returned %08x\n", hr);
115 if(FAILED(hr)) {
116 skip("Direct3D9Ex is not available\n");
117 goto out;
120 hr = IDirect3D9Ex_QueryInterface(d3d9ex, &IID_IDirect3D9, (void **) &d3d9);
121 ok(hr == D3D_OK,
122 "IDirect3D9Ex::QueryInterface for IID_IDirect3D9 returned %08x, expected D3D_OK\n",
123 hr);
124 ok(d3d9 != NULL && d3d9 != (void *) 0xdeadbeef,
125 "QueryInterface returned interface %p, expected != NULL && != 0xdeadbeef\n", d3d9);
126 ref = getref((IUnknown *) d3d9ex);
127 ok(ref == 2, "IDirect3D9Ex refcount is %d, expected 2\n", ref);
128 ref = getref((IUnknown *) d3d9);
129 ok(ref == 2, "IDirect3D9 refcount is %d, expected 2\n", ref);
131 memset(&present_parameters, 0, sizeof(present_parameters));
132 present_parameters.Windowed = TRUE;
133 present_parameters.hDeviceWindow = window;
134 present_parameters.SwapEffect = D3DSWAPEFFECT_COPY;
135 present_parameters.BackBufferWidth = 640;
136 present_parameters.BackBufferHeight = 480;
137 present_parameters.EnableAutoDepthStencil = FALSE;
138 present_parameters.AutoDepthStencilFormat = D3DFMT_D16;
140 /* First, try to create a normal device with IDirect3D9Ex::CreateDevice and QI it for IDirect3DDevice9Ex */
141 hr = IDirect3D9Ex_CreateDevice(d3d9ex, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
142 if(FAILED(hr)) {
143 skip("Failed to create a regular Direct3DDevice9, skipping QI tests\n");
144 goto out;
147 hr = IDirect3DDevice9_QueryInterface(device, &IID_IDirect3DDevice9Ex, (void **) &deviceEx);
148 ok(hr == D3D_OK,
149 "IDirect3D9Device::QueryInterface for IID_IDirect3DDevice9Ex returned %08x, expected D3D_OK\n",
150 hr);
151 ok(deviceEx != NULL && deviceEx != (void *) 0xdeadbeef,
152 "QueryInterface returned interface %p, expected != NULL && != 0xdeadbeef\n", deviceEx);
153 ref = getref((IUnknown *) device);
154 ok(ref == 2, "IDirect3DDevice9 refcount is %d, expected 2\n", ref);
155 ref = getref((IUnknown *) deviceEx);
156 ok(ref == 2, "IDirect3DDevice9Ex refcount is %d, expected 2\n", ref);
157 if(deviceEx) IDirect3DDevice9Ex_Release(deviceEx);
158 IDirect3DDevice9_Release(device);
160 /* Next, try to create a normal device with IDirect3D9::CreateDevice(non-ex) and QI it */
161 hr = IDirect3D9_CreateDevice(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
162 if(FAILED(hr)) {
163 skip("Failed to create a regular Direct3DDevice9, skipping QI tests\n");
164 goto out;
167 hr = IDirect3DDevice9_QueryInterface(device, &IID_IDirect3DDevice9Ex, (void **) &deviceEx);
168 ok(hr == D3D_OK,
169 "IDirect3D9Device::QueryInterface for IID_IDirect3DDevice9Ex returned %08x, expected D3D_OK\n",
170 hr);
171 ok(deviceEx != NULL && deviceEx != (void *) 0xdeadbeef,
172 "QueryInterface returned interface %p, expected != NULL && != 0xdeadbeef\n", deviceEx);
173 ref = getref((IUnknown *) device);
174 ok(ref == 2, "IDirect3DDevice9 refcount is %d, expected 2\n", ref);
175 ref = getref((IUnknown *) deviceEx);
176 ok(ref == 2, "IDirect3DDevice9Ex refcount is %d, expected 2\n", ref);
177 if(deviceEx) IDirect3DDevice9Ex_Release(deviceEx);
178 IDirect3DDevice9_Release(device);
180 IDirect3D9_Release(d3d9);
181 IDirect3D9Ex_Release(d3d9ex);
183 out:
184 DestroyWindow(window);
187 static void test_get_adapter_luid(void)
189 HWND window = create_window();
190 IDirect3D9Ex *d3d9ex;
191 UINT count;
192 HRESULT hr;
193 LUID luid;
195 hr = pDirect3DCreate9Ex(D3D_SDK_VERSION, &d3d9ex);
196 if (FAILED(hr))
198 skip("Direct3D9Ex is not available.\n");
199 DestroyWindow(window);
200 return;
203 count = IDirect3D9Ex_GetAdapterCount(d3d9ex);
204 if (!count)
206 skip("No adapters available.\n");
207 IDirect3D9Ex_Release(d3d9ex);
208 DestroyWindow(window);
209 return;
212 hr = IDirect3D9Ex_GetAdapterLUID(d3d9ex, D3DADAPTER_DEFAULT, &luid);
213 ok(SUCCEEDED(hr), "GetAdapterLUID failed, hr %#x.\n", hr);
214 trace("adapter luid: %08x:%08x.\n", luid.HighPart, luid.LowPart);
216 IDirect3D9Ex_Release(d3d9ex);
219 START_TEST(d3d9ex)
221 d3d9_handle = LoadLibraryA("d3d9.dll");
222 if (!d3d9_handle)
224 skip("Could not load d3d9.dll\n");
225 return;
227 pDirect3DCreate9 = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9");
228 ok(pDirect3DCreate9 != NULL, "Failed to get address of Direct3DCreate9\n");
229 if(!pDirect3DCreate9) {
230 return;
233 pDirect3DCreate9Ex = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9Ex");
234 if (!pDirect3DCreate9Ex) {
235 win_skip("Failed to get address of Direct3DCreate9Ex\n");
236 return;
239 test_qi_base_to_ex();
240 test_qi_ex_to_base();
241 test_get_adapter_luid();