user32: Delete the static critical section when unloading the dll.
[wine.git] / dlls / d3dx9_36 / tests / effect.c
blob6a8f04f786e5c053650e9c61cd33affc0c08db59
1 /*
2 * Copyright 2010 Christian Costa
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 #define COBJMACROS
20 #include "initguid.h"
21 #include "wine/test.h"
22 #include "d3dx9.h"
24 static const char effect_desc[] =
25 "Technique\n"
26 "{\n"
27 "}\n";
29 static void test_create_effect_and_pool(IDirect3DDevice9 *device)
31 HRESULT hr;
32 ID3DXEffect *effect;
33 ID3DXBaseEffect *base;
34 ULONG count;
35 IDirect3DDevice9 *device2;
36 LPD3DXEFFECTSTATEMANAGER manager = (LPD3DXEFFECTSTATEMANAGER)0xdeadbeef;
37 ID3DXEffectPool *pool = (ID3DXEffectPool *)0xdeadbeef, *pool2;
39 hr = D3DXCreateEffect(NULL, effect_desc, sizeof(effect_desc), NULL, NULL, 0, NULL, NULL, NULL);
40 ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3D_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
42 hr = D3DXCreateEffect(device, NULL, 0, NULL, NULL, 0, NULL, NULL, NULL);
43 ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3DERR_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
45 hr = D3DXCreateEffect(device, effect_desc, 0, NULL, NULL, 0, NULL, NULL, NULL);
46 ok(hr == E_FAIL, "Got result %x, expected %x (D3DXERR_INVALIDDATA)\n", hr, E_FAIL);
48 hr = D3DXCreateEffect(device, effect_desc, sizeof(effect_desc), NULL, NULL, 0, NULL, NULL, NULL);
49 ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
51 hr = D3DXCreateEffect(device, effect_desc, sizeof(effect_desc), NULL, NULL, 0, NULL, &effect, NULL);
52 ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
54 hr = effect->lpVtbl->QueryInterface(effect, &IID_ID3DXBaseEffect, (void **)&base);
55 ok(hr == E_NOINTERFACE, "QueryInterface failed, got %x, expected %x (E_NOINTERFACE)\n", hr, E_NOINTERFACE);
57 hr = effect->lpVtbl->GetStateManager(effect, NULL);
58 ok(hr == D3DERR_INVALIDCALL, "GetStateManager failed, got %x, expected %x (D3DERR_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
60 hr = effect->lpVtbl->GetStateManager(effect, &manager);
61 ok(hr == D3D_OK, "GetStateManager failed, got %x, expected 0 (D3D_OK)\n", hr);
62 ok(!manager, "GetStateManager failed, got %p\n", manager);
64 /* this works, but it is not recommended! */
65 hr = effect->lpVtbl->SetStateManager(effect, (LPD3DXEFFECTSTATEMANAGER) device);
66 ok(hr == D3D_OK, "SetStateManager failed, got %x, expected 0 (D3D_OK)\n", hr);
68 hr = effect->lpVtbl->GetStateManager(effect, &manager);
69 ok(hr == D3D_OK, "GetStateManager failed, got %x, expected 0 (D3D_OK)\n", hr);
70 ok(manager != NULL, "GetStateManager failed\n");
72 IDirect3DDevice9_AddRef(device);
73 count = IDirect3DDevice9_Release(device);
74 ok(count == 4, "Release failed, got %u, expected 4\n", count);
76 count = IUnknown_Release(manager);
77 ok(count == 3, "Release failed, got %u, expected 3\n", count);
79 hr = effect->lpVtbl->SetStateManager(effect, NULL);
80 ok(hr == D3D_OK, "SetStateManager failed, got %x, expected 0 (D3D_OK)\n", hr);
82 hr = effect->lpVtbl->GetPool(effect, &pool);
83 ok(hr == D3D_OK, "GetPool failed, got %x, expected 0 (D3D_OK)\n", hr);
84 ok(!pool, "GetPool failed, got %p\n", pool);
86 hr = effect->lpVtbl->GetPool(effect, NULL);
87 ok(hr == D3DERR_INVALIDCALL, "GetPool failed, got %x, expected %x (D3DERR_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
89 hr = effect->lpVtbl->GetDevice(effect, &device2);
90 ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
92 hr = effect->lpVtbl->GetDevice(effect, NULL);
93 ok(hr == D3DERR_INVALIDCALL, "GetDevice failed, got %x, expected %x (D3DERR_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
95 count = IDirect3DDevice9_Release(device2);
96 ok(count == 2, "Release failed, got %u, expected 2\n", count);
98 count = effect->lpVtbl->Release(effect);
99 ok(count == 0, "Release failed %u\n", count);
101 hr = D3DXCreateEffectPool(NULL);
102 ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3D_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
104 hr = D3DXCreateEffectPool(&pool);
105 ok(hr == S_OK, "Got result %x, expected 0 (S_OK)\n", hr);
107 count = pool->lpVtbl->Release(pool);
108 ok(count == 0, "Release failed %u\n", count);
110 hr = D3DXCreateEffectPool(&pool);
111 ok(hr == S_OK, "Got result %x, expected 0 (S_OK)\n", hr);
113 hr = D3DXCreateEffect(device, effect_desc, sizeof(effect_desc), NULL, NULL, 0, pool, NULL, NULL);
114 ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
116 hr = pool->lpVtbl->QueryInterface(pool, &IID_ID3DXEffectPool, (void **)&pool2);
117 ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
118 ok(pool == pool2, "Release failed, got %p, expected %p\n", pool2, pool);
120 count = pool2->lpVtbl->Release(pool2);
121 ok(count == 1, "Release failed, got %u, expected 1\n", count);
123 hr = IDirect3DDevice9_QueryInterface(device, &IID_IDirect3DDevice9, (void **)&device2);
124 ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
126 count = IDirect3DDevice9_Release(device2);
127 ok(count == 1, "Release failed, got %u, expected 1\n", count);
129 hr = D3DXCreateEffect(device, effect_desc, sizeof(effect_desc), NULL, NULL, 0, pool, &effect, NULL);
130 ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
132 hr = effect->lpVtbl->GetPool(effect, &pool);
133 ok(hr == D3D_OK, "GetPool failed, got %x, expected 0 (D3D_OK)\n", hr);
134 ok(pool == pool2, "GetPool failed, got %p, expected %p\n", pool2, pool);
136 count = pool2->lpVtbl->Release(pool2);
137 ok(count == 2, "Release failed, got %u, expected 2\n", count);
139 count = effect->lpVtbl->Release(effect);
140 ok(count == 0, "Release failed %u\n", count);
142 count = pool->lpVtbl->Release(pool);
143 ok(count == 0, "Release failed %u\n", count);
146 static void test_create_effect_compiler(void)
148 HRESULT hr;
149 ID3DXEffectCompiler *compiler, *compiler2;
150 ID3DXBaseEffect *base;
151 IUnknown *unknown;
152 ULONG count;
154 hr = D3DXCreateEffectCompiler(NULL, 0, NULL, NULL, 0, &compiler, NULL);
155 ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3D_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
157 hr = D3DXCreateEffectCompiler(NULL, 0, NULL, NULL, 0, NULL, NULL);
158 ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3D_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
160 hr = D3DXCreateEffectCompiler(effect_desc, 0, NULL, NULL, 0, &compiler, NULL);
161 ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK);
163 count = compiler->lpVtbl->Release(compiler);
164 ok(count == 0, "Release failed %u\n", count);
166 hr = D3DXCreateEffectCompiler(effect_desc, 0, NULL, NULL, 0, NULL, NULL);
167 ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3D_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
169 hr = D3DXCreateEffectCompiler(NULL, sizeof(effect_desc), NULL, NULL, 0, &compiler, NULL);
170 ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3D_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
172 hr = D3DXCreateEffectCompiler(NULL, sizeof(effect_desc), NULL, NULL, 0, NULL, NULL);
173 ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3D_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
175 hr = D3DXCreateEffectCompiler(effect_desc, sizeof(effect_desc), NULL, NULL, 0, NULL, NULL);
176 ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3DERR_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
178 hr = D3DXCreateEffectCompiler(effect_desc, sizeof(effect_desc), NULL, NULL, 0, &compiler, NULL);
179 ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK);
181 hr = compiler->lpVtbl->QueryInterface(compiler, &IID_ID3DXBaseEffect, (void **)&base);
182 ok(hr == E_NOINTERFACE, "QueryInterface failed, got %x, expected %x (E_NOINTERFACE)\n", hr, E_NOINTERFACE);
184 hr = compiler->lpVtbl->QueryInterface(compiler, &IID_ID3DXEffectCompiler, (void **)&compiler2);
185 ok(hr == D3D_OK, "QueryInterface failed, got %x, expected %x (D3D_OK)\n", hr, D3D_OK);
187 hr = compiler->lpVtbl->QueryInterface(compiler, &IID_IUnknown, (void **)&unknown);
188 ok(hr == D3D_OK, "QueryInterface failed, got %x, expected %x (D3D_OK)\n", hr, D3D_OK);
190 count = unknown->lpVtbl->Release(unknown);
191 ok(count == 2, "Release failed, got %u, expected %u\n", count, 2);
193 count = compiler2->lpVtbl->Release(compiler2);
194 ok(count == 1, "Release failed, got %u, expected %u\n", count, 1);
196 count = compiler->lpVtbl->Release(compiler);
197 ok(count == 0, "Release failed %u\n", count);
200 START_TEST(effect)
202 HWND wnd;
203 IDirect3D9 *d3d;
204 IDirect3DDevice9 *device;
205 D3DPRESENT_PARAMETERS d3dpp;
206 HRESULT hr;
207 ULONG count;
209 wnd = CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
210 d3d = Direct3DCreate9(D3D_SDK_VERSION);
211 if (!wnd) {
212 skip("Couldn't create application window\n");
213 return;
215 if (!d3d) {
216 skip("Couldn't create IDirect3D9 object\n");
217 DestroyWindow(wnd);
218 return;
221 ZeroMemory(&d3dpp, sizeof(d3dpp));
222 d3dpp.Windowed = TRUE;
223 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
224 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp, &device);
225 if (FAILED(hr)) {
226 skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
227 IDirect3D9_Release(d3d);
228 DestroyWindow(wnd);
229 return;
232 test_create_effect_and_pool(device);
233 test_create_effect_compiler();
235 count = IDirect3DDevice9_Release(device);
236 ok(count == 0, "The device was not properly freed: refcount %u\n", count);
238 count = IDirect3D9_Release(d3d);
239 ok(count == 0, "Release failed %u\n", count);
241 DestroyWindow(wnd);