d3d9: Reorganise the vertexdeclaration tests.
[wine/multimedia.git] / dlls / d3d9 / tests / vertexdeclaration.c
blob1d8b0ece43d06d3f94b6abfa02ae6a99f941db28
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #define COBJMACROS
20 #include <d3d9.h>
21 #include "wine/test.h"
23 static HMODULE d3d9_handle = 0;
25 static IDirect3DDevice9 *init_d3d9(void)
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;
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;
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;
41 ZeroMemory(&present_parameters, sizeof(present_parameters));
42 present_parameters.Windowed = TRUE;
43 present_parameters.hDeviceWindow = GetDesktopWindow();
44 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
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);
49 return device_ptr;
52 static int get_refcount(IUnknown *object)
54 IUnknown_AddRef(object);
55 return IUnknown_Release(object);
58 static IDirect3DVertexDeclaration9 *test_create_vertex_declaration(IDirect3DDevice9 *device_ptr, D3DVERTEXELEMENT9 *vertex_decl)
60 IDirect3DVertexDeclaration9 *decl_ptr = 0;
61 HRESULT hret = 0;
63 hret = IDirect3DDevice9_CreateVertexDeclaration(device_ptr, vertex_decl, &decl_ptr);
64 ok(hret == D3D_OK && decl_ptr != NULL, "CreateVertexDeclaration returned: hret 0x%lx, decl_ptr %p. "
65 "Expected hret 0x%lx, decl_ptr != %p. Aborting.\n", hret, decl_ptr, D3D_OK, NULL);
67 return decl_ptr;
70 static void test_get_set_vertex_declaration(IDirect3DDevice9 *device_ptr, IDirect3DVertexDeclaration9 *decl_ptr)
72 IDirect3DVertexDeclaration9 *current_decl_ptr = 0;
73 HRESULT hret = 0;
74 int decl_refcount = 0;
75 int i = 0;
77 /* SetVertexDeclaration should not touch the declaration's refcount. */
78 i = get_refcount((IUnknown *)decl_ptr);
79 hret = IDirect3DDevice9_SetVertexDeclaration(device_ptr, decl_ptr);
80 decl_refcount = get_refcount((IUnknown *)decl_ptr);
81 ok(hret == D3D_OK && decl_refcount == i, "SetVertexDeclaration returned: hret 0x%lx, refcount %d. "
82 "Expected hret 0x%lx, refcount %d.\n", hret, decl_refcount, D3D_OK, i);
84 /* GetVertexDeclaration should increase the declaration's refcount by one. */
85 i = decl_refcount+1;
86 hret = IDirect3DDevice9_GetVertexDeclaration(device_ptr, &current_decl_ptr);
87 decl_refcount = get_refcount((IUnknown *)decl_ptr);
88 ok(hret == D3D_OK && decl_refcount == i && current_decl_ptr == decl_ptr,
89 "GetVertexDeclaration returned: hret 0x%lx, current_decl_ptr %p refcount %d. "
90 "Expected hret 0x%lx, current_decl_ptr %p, refcount %d.\n", hret, current_decl_ptr, decl_refcount, D3D_OK, decl_ptr, i);
93 START_TEST(vertexdeclaration)
95 static D3DVERTEXELEMENT9 simple_decl[] = {
96 { 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
97 D3DDECL_END()};
98 IDirect3DDevice9 *device_ptr = 0;
99 IDirect3DVertexDeclaration9 *decl_ptr = 0;
101 d3d9_handle = LoadLibraryA("d3d9.dll");
102 if (!d3d9_handle)
104 trace("Could not load d3d9.dll, skipping tests\n");
105 return;
108 device_ptr = init_d3d9();
109 if (!device_ptr)
111 trace("Failed to initialise d3d9, aborting test.\n");
112 return;
115 decl_ptr = test_create_vertex_declaration(device_ptr, simple_decl);
116 if (!decl_ptr)
118 trace("Failed to create a vertex declaration, aborting test.\n");
119 return;
122 test_get_set_vertex_declaration(device_ptr, decl_ptr);