d3d9: Convert source files to utf-8.
[wine/multimedia.git] / dlls / d3d9 / tests / d3d9ex.c
blob9b2fd0699158853e187d86b256d6089b39d28f3d
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 unsigned long 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 ok( d3d9 != NULL, "Failed to create D3D9 object\n" );
62 if (!d3d9) return;
64 hr = IDirect3D9_QueryInterface(d3d9, &IID_IDirect3D9Ex, (void **) &d3d9ex);
65 ok(hr == E_NOINTERFACE,
66 "IDirect3D9::QueryInterface for IID_IDirect3D9Ex returned %08x, expected E_NOINTERFACE\n",
67 hr);
68 ok(d3d9ex == NULL, "QueryInterface returned interface %p, expected NULL\n", d3d9ex);
69 if(d3d9ex) IDirect3D9Ex_Release(d3d9ex);
71 memset(&present_parameters, 0, sizeof(present_parameters));
72 present_parameters.Windowed = TRUE;
73 present_parameters.hDeviceWindow = window;
74 present_parameters.SwapEffect = D3DSWAPEFFECT_COPY;
75 present_parameters.BackBufferWidth = 640;
76 present_parameters.BackBufferHeight = 480;
77 present_parameters.EnableAutoDepthStencil = FALSE;
78 present_parameters.AutoDepthStencilFormat = D3DFMT_D16;
79 hr = IDirect3D9_CreateDevice(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
80 if(FAILED(hr)) {
81 skip("Failed to create a regular Direct3DDevice9, skipping QI tests\n");
82 goto out;
85 hr = IDirect3DDevice9_QueryInterface(device, &IID_IDirect3DDevice9Ex, (void **) &deviceEx);
86 ok(hr == E_NOINTERFACE,
87 "IDirect3D9Device::QueryInterface for IID_IDirect3DDevice9Ex returned %08x, expected E_NOINTERFACE\n",
88 hr);
89 ok(deviceEx == NULL, "QueryInterface returned interface %p, expected NULL\n", deviceEx);
90 if(deviceEx) IDirect3DDevice9Ex_Release(deviceEx);
92 IDirect3DDevice9_Release(device);
94 out:
95 IDirect3D9_Release(d3d9);
96 DestroyWindow(window);
99 static void test_qi_ex_to_base(void)
101 IDirect3D9 *d3d9 = (void *) 0xdeadbeef;
102 IDirect3D9Ex *d3d9ex;
103 IDirect3DDevice9 *device;
104 IDirect3DDevice9Ex *deviceEx = (void *) 0xdeadbeef;
105 HRESULT hr;
106 HWND window = create_window();
107 D3DPRESENT_PARAMETERS present_parameters;
108 unsigned long ref;
110 hr = pDirect3DCreate9Ex(D3D_SDK_VERSION, &d3d9ex);
111 ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE, "Direct3DCreate9Ex returned %08x\n", hr);
112 if(FAILED(hr)) {
113 skip("Direct3D9Ex is not available\n");
114 goto out;
117 hr = IDirect3D9Ex_QueryInterface(d3d9ex, &IID_IDirect3D9, (void **) &d3d9);
118 ok(hr == D3D_OK,
119 "IDirect3D9Ex::QueryInterface for IID_IDirect3D9 returned %08x, expected D3D_OK\n",
120 hr);
121 ok(d3d9 != NULL && d3d9 != (void *) 0xdeadbeef,
122 "QueryInterface returned interface %p, expected != NULL && != 0xdeadbeef\n", d3d9);
123 ref = getref((IUnknown *) d3d9ex);
124 ok(ref == 2, "IDirect3D9Ex refcount is %ld, expected 2\n", ref);
125 ref = getref((IUnknown *) d3d9);
126 ok(ref == 2, "IDirect3D9 refcount is %ld, expected 2\n", ref);
128 memset(&present_parameters, 0, sizeof(present_parameters));
129 present_parameters.Windowed = TRUE;
130 present_parameters.hDeviceWindow = window;
131 present_parameters.SwapEffect = D3DSWAPEFFECT_COPY;
132 present_parameters.BackBufferWidth = 640;
133 present_parameters.BackBufferHeight = 480;
134 present_parameters.EnableAutoDepthStencil = FALSE;
135 present_parameters.AutoDepthStencilFormat = D3DFMT_D16;
137 /* First, try to create a normal device with IDirect3D9Ex::CreateDevice and QI it for IDirect3DDevice9Ex */
138 hr = IDirect3D9Ex_CreateDevice(d3d9ex, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
139 if(FAILED(hr)) {
140 skip("Failed to create a regular Direct3DDevice9, skipping QI tests\n");
141 goto out;
144 hr = IDirect3DDevice9_QueryInterface(device, &IID_IDirect3DDevice9Ex, (void **) &deviceEx);
145 ok(hr == D3D_OK,
146 "IDirect3D9Device::QueryInterface for IID_IDirect3DDevice9Ex returned %08x, expected D3D_OK\n",
147 hr);
148 ok(deviceEx != NULL && deviceEx != (void *) 0xdeadbeef,
149 "QueryInterface returned interface %p, expected != NULL && != 0xdeadbeef\n", deviceEx);
150 ref = getref((IUnknown *) device);
151 ok(ref == 2, "IDirect3DDevice9 refcount is %ld, expected 2\n", ref);
152 ref = getref((IUnknown *) deviceEx);
153 ok(ref == 2, "IDirect3DDevice9Ex refcount is %ld, expected 2\n", ref);
154 if(deviceEx) IDirect3DDevice9Ex_Release(deviceEx);
155 IDirect3DDevice9_Release(device);
157 /* Next, try to create a normal device with IDirect3D9::CreateDevice(non-ex) and QI it */
158 hr = IDirect3D9_CreateDevice(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
159 if(FAILED(hr)) {
160 skip("Failed to create a regular Direct3DDevice9, skipping QI tests\n");
161 goto out;
164 hr = IDirect3DDevice9_QueryInterface(device, &IID_IDirect3DDevice9Ex, (void **) &deviceEx);
165 ok(hr == D3D_OK,
166 "IDirect3D9Device::QueryInterface for IID_IDirect3DDevice9Ex returned %08x, expected D3D_OK\n",
167 hr);
168 ok(deviceEx != NULL && deviceEx != (void *) 0xdeadbeef,
169 "QueryInterface returned interface %p, expected != NULL && != 0xdeadbeef\n", deviceEx);
170 ref = getref((IUnknown *) device);
171 ok(ref == 2, "IDirect3DDevice9 refcount is %ld, expected 2\n", ref);
172 ref = getref((IUnknown *) deviceEx);
173 ok(ref == 2, "IDirect3DDevice9Ex refcount is %ld, expected 2\n", ref);
174 if(deviceEx) IDirect3DDevice9Ex_Release(deviceEx);
175 IDirect3DDevice9_Release(device);
177 IDirect3D9_Release(d3d9);
179 out:
180 DestroyWindow(window);
183 START_TEST(d3d9ex)
185 d3d9_handle = LoadLibraryA("d3d9.dll");
186 if (!d3d9_handle)
188 skip("Could not load d3d9.dll\n");
189 return;
191 pDirect3DCreate9 = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9");
192 ok(pDirect3DCreate9 != NULL, "Failed to get address of Direct3DCreate9\n");
193 if(!pDirect3DCreate9) {
194 return;
197 pDirect3DCreate9Ex = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9Ex");
198 if (!pDirect3DCreate9Ex) {
199 skip("Failed to get address of Direct3DCreate9Ex\n");
200 return;
203 test_qi_base_to_ex();
204 test_qi_ex_to_base();