d3d9/tests: Test GetAdapterDisplayModeEx with D3DDISPLAYROTATION null-pointer.
[wine/multimedia.git] / dlls / d3d9 / tests / d3d9ex.c
blob6e111169b0394204e310ad3b2326250f8050c9c2
1 /*
2 * Copyright (C) 2008 Stefan Dösinger(for CodeWeavers)
3 * Copyright (C) 2010 Louis Lenders
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 /* This file contains tests specific to IDirect3D9Ex and IDirect3DDevice9Ex, like
21 * how to obtain them. For testing rendering with extended functions use visual.c
24 #define COBJMACROS
25 #include "wine/test.h"
26 #include "winuser.h"
27 #include "wingdi.h"
28 #include <initguid.h>
29 #include <d3d9.h>
31 static HMODULE d3d9_handle = 0;
33 static BOOL (WINAPI *pEnumDisplaySettingsExA)(LPCSTR, DWORD, DEVMODEA *, DWORD);
34 static LONG (WINAPI *pChangeDisplaySettingsExA)(LPCSTR, LPDEVMODE, HWND, DWORD, LPVOID);
36 static IDirect3D9 * (WINAPI *pDirect3DCreate9)(UINT SDKVersion);
37 static HRESULT (WINAPI *pDirect3DCreate9Ex)(UINT SDKVersion, IDirect3D9Ex **d3d9ex);
39 static HWND create_window(void)
41 WNDCLASS wc = {0};
42 HWND ret;
43 wc.lpfnWndProc = DefWindowProc;
44 wc.lpszClassName = "d3d9_test_wc";
45 RegisterClass(&wc);
47 ret = CreateWindow("d3d9_test_wc", "d3d9_test",
48 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
49 return ret;
52 static ULONG getref(IUnknown *obj) {
53 IUnknown_AddRef(obj);
54 return IUnknown_Release(obj);
57 static void test_qi_base_to_ex(void)
59 IDirect3D9 *d3d9 = pDirect3DCreate9(D3D_SDK_VERSION);
60 IDirect3D9Ex *d3d9ex = (void *) 0xdeadbeef;
61 IDirect3DDevice9 *device;
62 IDirect3DDevice9Ex *deviceEx = (void *) 0xdeadbeef;
63 HRESULT hr;
64 HWND window = create_window();
65 D3DPRESENT_PARAMETERS present_parameters;
67 if (!d3d9)
69 skip("Direct3D9 is not available\n");
70 return;
73 hr = IDirect3D9_QueryInterface(d3d9, &IID_IDirect3D9Ex, (void **) &d3d9ex);
74 ok(hr == E_NOINTERFACE,
75 "IDirect3D9::QueryInterface for IID_IDirect3D9Ex returned %08x, expected E_NOINTERFACE\n",
76 hr);
77 ok(d3d9ex == NULL, "QueryInterface returned interface %p, expected NULL\n", d3d9ex);
78 if(d3d9ex) IDirect3D9Ex_Release(d3d9ex);
80 memset(&present_parameters, 0, sizeof(present_parameters));
81 present_parameters.Windowed = TRUE;
82 present_parameters.hDeviceWindow = window;
83 present_parameters.SwapEffect = D3DSWAPEFFECT_COPY;
84 present_parameters.BackBufferWidth = 640;
85 present_parameters.BackBufferHeight = 480;
86 present_parameters.EnableAutoDepthStencil = FALSE;
87 present_parameters.AutoDepthStencilFormat = D3DFMT_D16;
88 hr = IDirect3D9_CreateDevice(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
89 if(FAILED(hr)) {
90 skip("Failed to create a regular Direct3DDevice9, skipping QI tests\n");
91 goto out;
94 hr = IDirect3DDevice9_QueryInterface(device, &IID_IDirect3DDevice9Ex, (void **) &deviceEx);
95 ok(hr == E_NOINTERFACE,
96 "IDirect3D9Device::QueryInterface for IID_IDirect3DDevice9Ex returned %08x, expected E_NOINTERFACE\n",
97 hr);
98 ok(deviceEx == NULL, "QueryInterface returned interface %p, expected NULL\n", deviceEx);
99 if(deviceEx) IDirect3DDevice9Ex_Release(deviceEx);
101 IDirect3DDevice9_Release(device);
103 out:
104 IDirect3D9_Release(d3d9);
105 DestroyWindow(window);
108 static void test_qi_ex_to_base(void)
110 IDirect3D9 *d3d9 = (void *) 0xdeadbeef;
111 IDirect3D9Ex *d3d9ex;
112 IDirect3DDevice9 *device;
113 IDirect3DDevice9Ex *deviceEx = (void *) 0xdeadbeef;
114 HRESULT hr;
115 HWND window = create_window();
116 D3DPRESENT_PARAMETERS present_parameters;
117 ULONG ref;
119 hr = pDirect3DCreate9Ex(D3D_SDK_VERSION, &d3d9ex);
120 ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE, "Direct3DCreate9Ex returned %08x\n", hr);
121 if(FAILED(hr)) {
122 skip("Direct3D9Ex is not available\n");
123 goto out;
126 hr = IDirect3D9Ex_QueryInterface(d3d9ex, &IID_IDirect3D9, (void **) &d3d9);
127 ok(hr == D3D_OK,
128 "IDirect3D9Ex::QueryInterface for IID_IDirect3D9 returned %08x, expected D3D_OK\n",
129 hr);
130 ok(d3d9 != NULL && d3d9 != (void *) 0xdeadbeef,
131 "QueryInterface returned interface %p, expected != NULL && != 0xdeadbeef\n", d3d9);
132 ref = getref((IUnknown *) d3d9ex);
133 ok(ref == 2, "IDirect3D9Ex refcount is %d, expected 2\n", ref);
134 ref = getref((IUnknown *) d3d9);
135 ok(ref == 2, "IDirect3D9 refcount is %d, expected 2\n", ref);
137 memset(&present_parameters, 0, sizeof(present_parameters));
138 present_parameters.Windowed = TRUE;
139 present_parameters.hDeviceWindow = window;
140 present_parameters.SwapEffect = D3DSWAPEFFECT_COPY;
141 present_parameters.BackBufferWidth = 640;
142 present_parameters.BackBufferHeight = 480;
143 present_parameters.EnableAutoDepthStencil = FALSE;
144 present_parameters.AutoDepthStencilFormat = D3DFMT_D16;
146 /* First, try to create a normal device with IDirect3D9Ex::CreateDevice and QI it for IDirect3DDevice9Ex */
147 hr = IDirect3D9Ex_CreateDevice(d3d9ex, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
148 if(FAILED(hr)) {
149 skip("Failed to create a regular Direct3DDevice9, skipping QI tests\n");
150 goto out;
153 hr = IDirect3DDevice9_QueryInterface(device, &IID_IDirect3DDevice9Ex, (void **) &deviceEx);
154 ok(hr == D3D_OK,
155 "IDirect3D9Device::QueryInterface for IID_IDirect3DDevice9Ex returned %08x, expected D3D_OK\n",
156 hr);
157 ok(deviceEx != NULL && deviceEx != (void *) 0xdeadbeef,
158 "QueryInterface returned interface %p, expected != NULL && != 0xdeadbeef\n", deviceEx);
159 ref = getref((IUnknown *) device);
160 ok(ref == 2, "IDirect3DDevice9 refcount is %d, expected 2\n", ref);
161 ref = getref((IUnknown *) deviceEx);
162 ok(ref == 2, "IDirect3DDevice9Ex refcount is %d, expected 2\n", ref);
163 if(deviceEx) IDirect3DDevice9Ex_Release(deviceEx);
164 IDirect3DDevice9_Release(device);
166 /* Next, try to create a normal device with IDirect3D9::CreateDevice(non-ex) and QI it */
167 hr = IDirect3D9_CreateDevice(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
168 if(FAILED(hr)) {
169 skip("Failed to create a regular Direct3DDevice9, skipping QI tests\n");
170 goto out;
173 hr = IDirect3DDevice9_QueryInterface(device, &IID_IDirect3DDevice9Ex, (void **) &deviceEx);
174 ok(hr == D3D_OK,
175 "IDirect3D9Device::QueryInterface for IID_IDirect3DDevice9Ex returned %08x, expected D3D_OK\n",
176 hr);
177 ok(deviceEx != NULL && deviceEx != (void *) 0xdeadbeef,
178 "QueryInterface returned interface %p, expected != NULL && != 0xdeadbeef\n", deviceEx);
179 ref = getref((IUnknown *) device);
180 ok(ref == 2, "IDirect3DDevice9 refcount is %d, expected 2\n", ref);
181 ref = getref((IUnknown *) deviceEx);
182 ok(ref == 2, "IDirect3DDevice9Ex refcount is %d, expected 2\n", ref);
183 if(deviceEx) IDirect3DDevice9Ex_Release(deviceEx);
184 IDirect3DDevice9_Release(device);
186 IDirect3D9_Release(d3d9);
187 IDirect3D9Ex_Release(d3d9ex);
189 out:
190 DestroyWindow(window);
193 static void test_get_adapter_luid(void)
195 HWND window = create_window();
196 IDirect3D9Ex *d3d9ex;
197 UINT count;
198 HRESULT hr;
199 LUID luid;
201 hr = pDirect3DCreate9Ex(D3D_SDK_VERSION, &d3d9ex);
202 if (FAILED(hr))
204 skip("Direct3D9Ex is not available.\n");
205 DestroyWindow(window);
206 return;
209 count = IDirect3D9Ex_GetAdapterCount(d3d9ex);
210 if (!count)
212 skip("No adapters available.\n");
213 IDirect3D9Ex_Release(d3d9ex);
214 DestroyWindow(window);
215 return;
218 hr = IDirect3D9Ex_GetAdapterLUID(d3d9ex, D3DADAPTER_DEFAULT, &luid);
219 ok(SUCCEEDED(hr), "GetAdapterLUID failed, hr %#x.\n", hr);
220 trace("adapter luid: %08x:%08x.\n", luid.HighPart, luid.LowPart);
222 IDirect3D9Ex_Release(d3d9ex);
225 static void test_get_adapter_displaymode_ex(void)
227 HWND window = create_window();
228 IDirect3D9 *d3d9 = (void *) 0xdeadbeef;
229 IDirect3D9Ex *d3d9ex;
230 UINT count;
231 HRESULT hr;
232 D3DDISPLAYMODE mode;
233 D3DDISPLAYMODEEX mode_ex;
234 D3DDISPLAYROTATION rotation;
235 HANDLE hdll;
236 DEVMODEA startmode;
237 LONG retval;
239 hr = pDirect3DCreate9Ex(D3D_SDK_VERSION, &d3d9ex);
240 if (FAILED(hr))
242 skip("Direct3D9Ex is not available (%#x)\n", hr);
243 DestroyWindow(window);
244 return;
247 count = IDirect3D9Ex_GetAdapterCount(d3d9ex);
248 if (!count)
250 skip("No adapters available.\n");
251 IDirect3D9Ex_Release(d3d9ex);
252 DestroyWindow(window);
253 return;
256 hr = IDirect3D9Ex_QueryInterface(d3d9ex, &IID_IDirect3D9, (void **) &d3d9);
257 ok(hr == D3D_OK,
258 "IDirect3D9Ex::QueryInterface for IID_IDirect3D9 returned %08x, expected D3D_OK\n",
259 hr);
260 ok(d3d9 != NULL && d3d9 != (void *) 0xdeadbeef,
261 "QueryInterface returned interface %p, expected != NULL && != 0xdeadbeef\n", d3d9);
262 /* change displayorientation*/
263 hdll = GetModuleHandleA("user32.dll");
264 pEnumDisplaySettingsExA = (void*)GetProcAddress(hdll, "EnumDisplaySettingsExA");
265 pChangeDisplaySettingsExA = (void*)GetProcAddress(hdll, "ChangeDisplaySettingsExA");
267 if (!pEnumDisplaySettingsExA || !pChangeDisplaySettingsExA) goto out;
269 memset(&startmode, 0, sizeof(startmode));
270 startmode.dmSize = sizeof(startmode);
271 startmode.dmFields = DM_DISPLAYORIENTATION;
272 startmode.dmDisplayOrientation = DMDO_180;
274 retval = pChangeDisplaySettingsExA(NULL, &startmode, NULL, 0, NULL);
276 if(retval == DISP_CHANGE_BADMODE)
278 trace(" Test skipped: graphics mode is not supported\n");
279 goto out;
282 ok(retval == DISP_CHANGE_SUCCESSFUL,"ChangeDisplaySettingsEx failed with %d\n", retval);
283 /* try retrieve orientation info with EnumDisplaySettingsEx*/
284 startmode.dmFields = 0;
285 startmode.dmDisplayOrientation = 0;
286 ok(pEnumDisplaySettingsExA(NULL, ENUM_CURRENT_SETTINGS, &startmode, EDS_ROTATEDMODE), "EnumDisplaySettingsEx failed\n");
288 /*now that orientation has changed start tests for GetAdapterDisplayModeEx: invalid Size*/
289 memset(&mode_ex, 0, sizeof(mode_ex));
290 hr = IDirect3D9Ex_GetAdapterDisplayModeEx(d3d9ex, D3DADAPTER_DEFAULT, &mode_ex, &rotation);
291 todo_wine ok(hr == D3DERR_INVALIDCALL, "GetAdapterDisplayModeEx returned %#x instead of D3DERR_INVALIDCALL\n", hr);
293 mode_ex.Size = sizeof(D3DDISPLAYMODEEX);
294 /* invalid count*/
295 hr = IDirect3D9Ex_GetAdapterDisplayModeEx(d3d9ex, count + 1, &mode_ex, &rotation);
296 todo_wine ok(hr == D3DERR_INVALIDCALL, "GetAdapterDisplayModeEx returned %#x instead of D3DERR_INVALIDCALL\n", hr);
297 /*valid count and valid Size*/
298 hr = IDirect3D9Ex_GetAdapterDisplayModeEx(d3d9ex, D3DADAPTER_DEFAULT, &mode_ex, &rotation);
299 todo_wine ok(SUCCEEDED(hr), "GetAdapterDisplayModeEx failed, hr %#x.\n", hr);
301 /* Compare what GetAdapterDisplayMode returns with what GetAdapterDisplayModeEx returns*/
302 hr = IDirect3D9_GetAdapterDisplayMode(d3d9, D3DADAPTER_DEFAULT, &mode);
303 ok(SUCCEEDED(hr), "GetAdapterDisplayMode failed, hr %#x.\n", hr);
305 ok(mode_ex.Size == sizeof(D3DDISPLAYMODEEX), "size is %d\n", mode_ex.Size);
306 todo_wine ok(mode_ex.Width == mode.Width, "width is %d instead of %d\n", mode_ex.Width, mode.Width);
307 todo_wine ok(mode_ex.Height == mode.Height, "height is %d instead of %d\n", mode_ex.Height, mode.Height);
308 todo_wine ok(mode_ex.RefreshRate == mode.RefreshRate, "RefreshRate is %d instead of %d\n", mode_ex.RefreshRate, mode.RefreshRate);
309 todo_wine ok(mode_ex.Format == mode.Format, "format is %x instead of %x\n", mode_ex.Format, mode.Format);
310 /* don't know yet how to test for ScanLineOrdering, just testing that it is set to a value by GetAdapterDisplayModeEx*/
311 todo_wine ok(mode_ex.ScanLineOrdering != 0, "ScanLineOrdering returned 0\n");
312 /* check that orientation is returned correctly by GetAdapterDisplayModeEx and EnumDisplaySettingsEx*/
313 todo_wine ok(startmode.dmDisplayOrientation == DMDO_180 && rotation == D3DDISPLAYROTATION_180, "rotation is %d instead of %d\n", rotation, startmode.dmDisplayOrientation);
315 trace("GetAdapterDisplayModeEx returned Width = %d,Height = %d, RefreshRate = %d, Format = %x, ScanLineOrdering = %x, rotation = %d\n",
316 mode_ex.Width, mode_ex.Height, mode_ex.RefreshRate, mode_ex.Format, mode_ex.ScanLineOrdering, rotation);
318 /* test GetAdapterDisplayModeEx with null pointer for D3DDISPLAYROTATION */
319 memset(&mode_ex, 0, sizeof(mode_ex));
320 mode_ex.Size = sizeof(D3DDISPLAYMODEEX);
322 hr = IDirect3D9Ex_GetAdapterDisplayModeEx(d3d9ex, D3DADAPTER_DEFAULT, &mode_ex, NULL);
323 todo_wine ok(SUCCEEDED(hr), "GetAdapterDisplayModeEx failed, hr %#x.\n", hr);
325 ok(mode_ex.Size == sizeof(D3DDISPLAYMODEEX), "size is %d\n", mode_ex.Size);
326 todo_wine ok(mode_ex.Width == mode.Width, "width is %d instead of %d\n", mode_ex.Width, mode.Width);
327 todo_wine ok(mode_ex.Height == mode.Height, "height is %d instead of %d\n", mode_ex.Height, mode.Height);
328 todo_wine ok(mode_ex.RefreshRate == mode.RefreshRate, "RefreshRate is %d instead of %d\n", mode_ex.RefreshRate, mode.RefreshRate);
329 todo_wine ok(mode_ex.Format == mode.Format, "format is %x instead of %x\n", mode_ex.Format, mode.Format);
330 /* don't know yet how to test for ScanLineOrdering, just testing that it is set to a value by GetAdapterDisplayModeEx*/
331 todo_wine ok(mode_ex.ScanLineOrdering != 0, "ScanLineOrdering returned 0\n");
333 /* return to the default mode */
334 pChangeDisplaySettingsExA(NULL, NULL, NULL, 0, NULL);
335 out:
336 IDirect3D9_Release(d3d9);
337 IDirect3D9Ex_Release(d3d9ex);
340 START_TEST(d3d9ex)
342 d3d9_handle = LoadLibraryA("d3d9.dll");
343 if (!d3d9_handle)
345 skip("Could not load d3d9.dll\n");
346 return;
348 pDirect3DCreate9 = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9");
349 ok(pDirect3DCreate9 != NULL, "Failed to get address of Direct3DCreate9\n");
350 if(!pDirect3DCreate9) {
351 return;
354 pDirect3DCreate9Ex = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9Ex");
355 if (!pDirect3DCreate9Ex) {
356 win_skip("Failed to get address of Direct3DCreate9Ex\n");
357 return;
360 test_qi_base_to_ex();
361 test_qi_ex_to_base();
362 test_get_adapter_luid();
363 test_get_adapter_displaymode_ex();