kernel32: FindFirstChangeNotification needs a static IO_STATUS_BLOCK.
[wine] / dlls / d3d9 / tests / vertexdeclaration.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 #define COBJMACROS
20 #include <d3d9.h>
21 #include "wine/test.h"
22
23 static HMODULE d3d9_handle = 0;
24
25 static IDirect3DDevice9 *init_d3d9(void)
26 {
27     IDirect3D9 * (__stdcall * d3d9_create)(UINT SDKVersion) = 0;
28     IDirect3D9 *d3d9_ptr = 0;
29     IDirect3DDevice9 *device_ptr = 0;
30     D3DPRESENT_PARAMETERS present_parameters;
31     HRESULT hres;
32
33     d3d9_create = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9");
34     ok(d3d9_create != NULL, "Failed to get address of Direct3DCreate9\n");
35     if (!d3d9_create) return NULL;
36     
37     d3d9_ptr = d3d9_create(D3D_SDK_VERSION);
38     ok(d3d9_ptr != NULL, "Failed to create IDirect3D9 object\n");
39     if (!d3d9_ptr) return NULL;
40
41     ZeroMemory(&present_parameters, sizeof(present_parameters));
42     present_parameters.Windowed = TRUE;
43     present_parameters.hDeviceWindow = GetDesktopWindow();
44     present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
45
46     hres = IDirect3D9_CreateDevice(d3d9_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device_ptr);
47     ok(hres == D3D_OK, "IDirect3D_CreateDevice returned: 0x%lx\n", hres);
48
49     return device_ptr;
50 }
51
52 static int get_refcount(IUnknown *object)
53 {
54     IUnknown_AddRef(object);
55     return IUnknown_Release(object);
56 }
57
58 static void test_get_set_vertex_declaration(IDirect3DDevice9 *device_ptr)
59 {
60     static D3DVERTEXELEMENT9 simple_decl[] = {
61         { 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
62         D3DDECL_END()};
63     
64     IDirect3DVertexDeclaration9 *decl_ptr = 0;
65     IDirect3DVertexDeclaration9 *current_decl_ptr = 0;
66     HRESULT hret = 0;
67     int decl_refcount = 0;
68     int i = 0;
69     
70     hret = IDirect3DDevice9_CreateVertexDeclaration(device_ptr, simple_decl, &decl_ptr);
71     ok(hret == D3D_OK && decl_ptr != NULL, "CreateVertexDeclaration returned: hret 0x%lx, decl_ptr %p. "
72         "Expected hret 0x%lx, decl_ptr != %p. Aborting.\n", hret, decl_ptr, D3D_OK, NULL);
73     if (hret != D3D_OK || decl_ptr == NULL) return;
74     
75     /* SetVertexDeclaration should not touch the declaration's refcount. */
76     i = get_refcount((IUnknown *)decl_ptr);
77     hret = IDirect3DDevice9_SetVertexDeclaration(device_ptr, decl_ptr);
78     decl_refcount = get_refcount((IUnknown *)decl_ptr);
79     ok(hret == D3D_OK && decl_refcount == i, "SetVertexDeclaration returned: hret 0x%lx, refcount %d. "
80         "Expected hret 0x%lx, refcount %d.\n", hret, decl_refcount, D3D_OK, i);
81     
82     /* GetVertexDeclaration should increase the declaration's refcount by one. */
83     i = decl_refcount+1;
84     hret = IDirect3DDevice9_GetVertexDeclaration(device_ptr, &current_decl_ptr);
85     decl_refcount = get_refcount((IUnknown *)decl_ptr);
86     ok(hret == D3D_OK && decl_refcount == i && current_decl_ptr == decl_ptr, 
87         "GetVertexDeclaration returned: hret 0x%lx, current_decl_ptr %p refcount %d. "
88         "Expected hret 0x%lx, current_decl_ptr %p, refcount %d.\n", hret, current_decl_ptr, decl_refcount, D3D_OK, decl_ptr, i);
89 }
90
91 START_TEST(vertexdeclaration)
92 {
93     IDirect3DDevice9 *device_ptr;
94
95     d3d9_handle = LoadLibraryA("d3d9.dll");
96     if (!d3d9_handle)
97     {
98         trace("Could not load d3d9.dll, skipping tests\n");
99         return;
100     }
101
102     device_ptr = init_d3d9();
103     if (!device_ptr) return;
104     
105     test_get_set_vertex_declaration(device_ptr);
106 }