advapi32: Remove an unused variable.
[wine/multimedia.git] / dlls / d3d8 / tests / buffer.c
bloba4082c5cddd97b87e6d07a70394bc019187f9747
1 /*
2 * Copyright (C) 2010 Stefan Dösinger(for CodeWeavers)
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 <d3d8.h>
21 #include "wine/test.h"
23 static HWND create_window(void)
25 WNDCLASS wc = {0};
26 wc.lpfnWndProc = DefWindowProc;
27 wc.lpszClassName = "d3d8_test_wc";
28 RegisterClass(&wc);
30 return CreateWindow("d3d8_test_wc", "d3d8_test",
31 0, 0, 0, 0, 0, 0, 0, 0, 0);
34 static IDirect3DDevice8 *init_d3d8(HMODULE d3d8_handle)
36 IDirect3D8 * (__stdcall * d3d8_create)(UINT SDKVersion) = 0;
37 IDirect3D8 *d3d8_ptr = 0;
38 IDirect3DDevice8 *device_ptr = 0;
39 D3DPRESENT_PARAMETERS present_parameters;
40 D3DDISPLAYMODE d3ddm;
41 HRESULT hr;
43 d3d8_create = (void *)GetProcAddress(d3d8_handle, "Direct3DCreate8");
44 ok(d3d8_create != NULL, "Failed to get address of Direct3DCreate8\n");
45 if (!d3d8_create) return NULL;
47 d3d8_ptr = d3d8_create(D3D_SDK_VERSION);
48 if (!d3d8_ptr)
50 skip("could not create D3D8\n");
51 return NULL;
54 IDirect3D8_GetAdapterDisplayMode(d3d8_ptr, D3DADAPTER_DEFAULT, &d3ddm );
55 ZeroMemory(&present_parameters, sizeof(present_parameters));
56 present_parameters.Windowed = TRUE;
57 present_parameters.hDeviceWindow = create_window();
58 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
59 present_parameters.BackBufferFormat = d3ddm.Format;
61 hr = IDirect3D8_CreateDevice(d3d8_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device_ptr);
63 if(FAILED(hr))
65 skip("could not create device, IDirect3D8_CreateDevice returned %#x\n", hr);
66 return NULL;
69 return device_ptr;
72 static void lock_flag_test(IDirect3DDevice8 *device)
74 HRESULT hr;
75 IDirect3DVertexBuffer8 *buffer;
76 unsigned int i;
77 BYTE *data;
78 const struct
80 DWORD flags;
81 const char *debug_string;
82 HRESULT result;
84 test_data[] =
86 {D3DLOCK_READONLY, "D3DLOCK_READONLY", D3D_OK },
87 {D3DLOCK_DISCARD, "D3DLOCK_DISCARD", D3D_OK },
88 {D3DLOCK_NOOVERWRITE, "D3DLOCK_NOOVERWRITE", D3D_OK },
89 {D3DLOCK_NOOVERWRITE | D3DLOCK_DISCARD, "D3DLOCK_NOOVERWRITE | D3DLOCK_DISCARD", D3D_OK },
90 {D3DLOCK_NOOVERWRITE | D3DLOCK_READONLY, "D3DLOCK_NOOVERWRITE | D3DLOCK_READONLY", D3D_OK },
91 {D3DLOCK_READONLY | D3DLOCK_DISCARD, "D3DLOCK_READONLY | D3DLOCK_DISCARD", D3D_OK },
92 /* Completely bogous flags aren't an error */
93 {0xdeadbeef, "0xdeadbeef", D3D_OK },
96 hr = IDirect3DDevice8_CreateVertexBuffer(device, 1024, D3DUSAGE_DYNAMIC, 0, D3DPOOL_DEFAULT, &buffer);
97 ok(hr == D3D_OK, "IDirect3DDevice8_CreateBuffer failed, 0x%08x\n", hr);
99 for(i = 0; i < (sizeof(test_data) / sizeof(*test_data)); i++)
101 hr = IDirect3DVertexBuffer8_Lock(buffer, 0, 0, &data, test_data[i].flags);
102 ok(hr == test_data[i].result, "Lock flags %s returned 0x%08x, expected 0x%08x\n",
103 test_data[i].debug_string, hr, test_data[i].result);
105 if(SUCCEEDED(hr))
107 ok(data != NULL, "The data pointer returned by Lock is NULL\n");
108 hr = IDirect3DVertexBuffer8_Unlock(buffer);
109 ok(hr == D3D_OK, "IDirect3DVertexBuffer8_Unlock failed, 0x%08x\n", hr);
113 IDirect3DVertexBuffer8_Release(buffer);
116 START_TEST(buffer)
118 IDirect3DDevice8 *device_ptr;
119 ULONG refcount;
120 HMODULE d3d8_handle = 0;
122 d3d8_handle = LoadLibraryA("d3d8.dll");
123 if (!d3d8_handle)
125 skip("Could not load d3d8.dll\n");
126 return;
129 device_ptr = init_d3d8(d3d8_handle);
130 if (!device_ptr) return;
132 lock_flag_test(device_ptr);
134 refcount = IDirect3DDevice8_Release(device_ptr);
135 ok(!refcount, "Device has %u references left\n", refcount);