d3d9: Don't treat missing d3d9.dll as a failure.
[wine] / dlls / d3d9 / tests / stateblock.c
1 /*
2  * Copyright (C) 2005 Henri Verbeet
3  *
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.
8  *
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.
13  *
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #include <d3d9.h>
20 #include "wine/test.h"
21
22 static HMODULE d3d9_handle = 0;
23
24 static IDirect3DDevice9 *init_d3d9(void)
25 {
26     IDirect3D9 * (__stdcall * d3d9_create)(UINT SDKVersion) = 0;
27     IDirect3D9 *d3d9_ptr = 0;
28     IDirect3DDevice9 *device_ptr = 0;
29     D3DPRESENT_PARAMETERS present_parameters;
30     HRESULT hres;
31
32     d3d9_create = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9");
33     ok(d3d9_create != NULL, "Failed to get address of Direct3DCreate9\n");
34     if (!d3d9_create) return NULL;
35     
36     d3d9_ptr = d3d9_create(D3D_SDK_VERSION);
37     ok(d3d9_ptr != NULL, "Failed to create IDirect3D9 object\n");
38     if (!d3d9_ptr) return NULL;
39
40     ZeroMemory(&present_parameters, sizeof(present_parameters));
41     present_parameters.Windowed = TRUE;
42     present_parameters.hDeviceWindow = GetDesktopWindow();
43     present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
44
45     hres = IDirect3D9_CreateDevice(d3d9_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device_ptr);
46     ok(hres == D3D_OK, "IDirect3D_CreateDevice returned: 0x%lx\n", hres);
47
48     return device_ptr;
49 }
50
51 static void test_begin_end_state_block(IDirect3DDevice9 *device_ptr)
52 {
53     HRESULT hret = 0;
54     IDirect3DStateBlock9 *state_block_ptr = 0;
55
56     /* Should succeed */
57     hret = IDirect3DDevice9_BeginStateBlock(device_ptr);
58     ok(hret == D3D_OK, "BeginStateBlock returned: hret 0x%lx. Expected hret 0x%lx. Aborting.\n", hret, D3D_OK);
59     if (hret != D3D_OK) return;
60
61     /* Calling BeginStateBlock while recording should return D3DERR_INVALIDCALL */
62     hret = IDirect3DDevice9_BeginStateBlock(device_ptr);
63     ok(hret == D3DERR_INVALIDCALL, "BeginStateBlock returned: hret 0x%lx. Expected hret 0x%lx. Aborting.\n", hret, D3DERR_INVALIDCALL);
64     if (hret != D3DERR_INVALIDCALL) return;
65
66     /* Should succeed */
67     state_block_ptr = (IDirect3DStateBlock9 *)0xdeadbeef;
68     hret = IDirect3DDevice9_EndStateBlock(device_ptr, &state_block_ptr);
69     ok(hret == D3D_OK && state_block_ptr != 0 && state_block_ptr != (IDirect3DStateBlock9 *)0xdeadbeef, 
70         "EndStateBlock returned: hret 0x%lx, state_block_ptr %p. "
71         "Expected hret 0x%lx, state_block_ptr != %p, state_block_ptr != 0xdeadbeef.\n", hret, state_block_ptr, D3D_OK, NULL);
72
73     /* Calling EndStateBlock while not recording should return D3DERR_INVALIDCALL. state_block_ptr should not be touched. */
74     state_block_ptr = (IDirect3DStateBlock9 *)0xdeadbeef;
75     hret = IDirect3DDevice9_EndStateBlock(device_ptr, &state_block_ptr);
76     ok(hret == D3DERR_INVALIDCALL && state_block_ptr == (IDirect3DStateBlock9 *)0xdeadbeef, 
77         "EndStateBlock returned: hret 0x%lx, state_block_ptr %p. "
78         "Expected hret 0x%lx, state_block_ptr 0xdeadbeef.\n", hret, state_block_ptr, D3DERR_INVALIDCALL);
79 }
80
81 START_TEST(stateblock)
82 {
83     IDirect3DDevice9 *device_ptr;
84
85     d3d9_handle = LoadLibraryA("d3d9.dll");
86     if (!d3d9_handle)
87     {
88         trace("Could not load d3d9.dll, skipping tests\n");
89         return;
90     }
91
92     device_ptr = init_d3d9();
93     test_begin_end_state_block(device_ptr);
94 }