Update the address of the Free Software Foundation.
[wine.git] / dlls / d3d9 / tests / stateblock.c
blob06cc74f002f2c919269bccc59c07aa7c89d74f59
1 /*
2 * Copyright (C) 2005 Henri Verbeet
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 #include <d3d9.h>
20 #include "wine/test.h"
22 static HMODULE d3d9_handle = 0;
24 static HWND create_window(void)
26 WNDCLASS wc = {0};
27 wc.lpfnWndProc = &DefWindowProc;
28 wc.lpszClassName = "d3d9_test_wc";
29 RegisterClass(&wc);
31 return CreateWindow("d3d9_test_wc", "d3d9_test",
32 0, 0, 0, 0, 0, 0, 0, 0, 0);
35 static IDirect3DDevice9 *init_d3d9(void)
37 IDirect3D9 * (__stdcall * d3d9_create)(UINT SDKVersion) = 0;
38 IDirect3D9 *d3d9_ptr = 0;
39 IDirect3DDevice9 *device_ptr = 0;
40 D3DPRESENT_PARAMETERS present_parameters;
41 HRESULT hres;
43 d3d9_create = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9");
44 ok(d3d9_create != NULL, "Failed to get address of Direct3DCreate9\n");
45 if (!d3d9_create) return NULL;
47 d3d9_ptr = d3d9_create(D3D_SDK_VERSION);
48 ok(d3d9_ptr != NULL, "Failed to create IDirect3D9 object\n");
49 if (!d3d9_ptr) return NULL;
51 ZeroMemory(&present_parameters, sizeof(present_parameters));
52 present_parameters.Windowed = TRUE;
53 present_parameters.hDeviceWindow = create_window();
54 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
56 hres = IDirect3D9_CreateDevice(d3d9_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device_ptr);
57 ok(hres == D3D_OK, "IDirect3D_CreateDevice returned: 0x%lx\n", hres);
59 return device_ptr;
62 static void test_begin_end_state_block(IDirect3DDevice9 *device_ptr)
64 HRESULT hret = 0;
65 IDirect3DStateBlock9 *state_block_ptr = 0;
67 /* Should succeed */
68 hret = IDirect3DDevice9_BeginStateBlock(device_ptr);
69 ok(hret == D3D_OK, "BeginStateBlock returned: hret 0x%lx. Expected hret 0x%lx. Aborting.\n", hret, D3D_OK);
70 if (hret != D3D_OK) return;
72 /* Calling BeginStateBlock while recording should return D3DERR_INVALIDCALL */
73 hret = IDirect3DDevice9_BeginStateBlock(device_ptr);
74 ok(hret == D3DERR_INVALIDCALL, "BeginStateBlock returned: hret 0x%lx. Expected hret 0x%lx. Aborting.\n", hret, D3DERR_INVALIDCALL);
75 if (hret != D3DERR_INVALIDCALL) return;
77 /* Should succeed */
78 state_block_ptr = (IDirect3DStateBlock9 *)0xdeadbeef;
79 hret = IDirect3DDevice9_EndStateBlock(device_ptr, &state_block_ptr);
80 ok(hret == D3D_OK && state_block_ptr != 0 && state_block_ptr != (IDirect3DStateBlock9 *)0xdeadbeef,
81 "EndStateBlock returned: hret 0x%lx, state_block_ptr %p. "
82 "Expected hret 0x%lx, state_block_ptr != %p, state_block_ptr != 0xdeadbeef.\n", hret, state_block_ptr, D3D_OK, NULL);
84 /* Calling EndStateBlock while not recording should return D3DERR_INVALIDCALL. state_block_ptr should not be touched. */
85 state_block_ptr = (IDirect3DStateBlock9 *)0xdeadbeef;
86 hret = IDirect3DDevice9_EndStateBlock(device_ptr, &state_block_ptr);
87 ok(hret == D3DERR_INVALIDCALL && state_block_ptr == (IDirect3DStateBlock9 *)0xdeadbeef,
88 "EndStateBlock returned: hret 0x%lx, state_block_ptr %p. "
89 "Expected hret 0x%lx, state_block_ptr 0xdeadbeef.\n", hret, state_block_ptr, D3DERR_INVALIDCALL);
92 START_TEST(stateblock)
94 IDirect3DDevice9 *device_ptr;
96 d3d9_handle = LoadLibraryA("d3d9.dll");
97 if (!d3d9_handle)
99 trace("Could not load d3d9.dll, skipping tests\n");
100 return;
103 device_ptr = init_d3d9();
104 if (!device_ptr) return;
106 test_begin_end_state_block(device_ptr);