jscript: Don't set constructor property to each object instance, it belongs to their...
[wine/multimedia.git] / dlls / d3d9 / tests / buffer.c
blob719ce7e96f6a5c41c09d4f7953d21712aaa26e05
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 <d3d9.h>
21 #include "wine/test.h"
23 static HMODULE d3d9_handle = 0;
25 static HWND create_window(void)
27 WNDCLASS wc = {0};
28 wc.lpfnWndProc = DefWindowProc;
29 wc.lpszClassName = "d3d9_test_wc";
30 RegisterClass(&wc);
32 return CreateWindow("d3d9_test_wc", "d3d9_test",
33 0, 0, 0, 0, 0, 0, 0, 0, 0);
36 static IDirect3DDevice9 *init_d3d9(void)
38 IDirect3D9 * (__stdcall * d3d9_create)(UINT SDKVersion) = 0;
39 IDirect3D9 *d3d9_ptr = 0;
40 IDirect3DDevice9 *device_ptr = 0;
41 D3DPRESENT_PARAMETERS present_parameters;
42 HRESULT hr;
44 d3d9_create = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9");
45 ok(d3d9_create != NULL, "Failed to get address of Direct3DCreate9\n");
46 if (!d3d9_create) return NULL;
48 d3d9_ptr = d3d9_create(D3D_SDK_VERSION);
49 if (!d3d9_ptr)
51 skip("could not create D3D9\n");
52 return NULL;
55 ZeroMemory(&present_parameters, sizeof(present_parameters));
56 present_parameters.Windowed = TRUE;
57 present_parameters.hDeviceWindow = create_window();
58 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
60 hr = IDirect3D9_CreateDevice(d3d9_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device_ptr);
62 if(FAILED(hr))
64 skip("could not create device, IDirect3D9_CreateDevice returned 0x%08x\n", hr);
65 return NULL;
68 return device_ptr;
71 static void lock_flag_test(IDirect3DDevice9 *device)
73 HRESULT hr;
74 IDirect3DVertexBuffer9 *buffer;
75 unsigned int i;
76 void *data;
77 const struct
79 DWORD flags;
80 const char *debug_string;
81 HRESULT win7_result;
83 test_data[] =
85 {D3DLOCK_READONLY, "D3DLOCK_READONLY", D3D_OK },
86 {D3DLOCK_DISCARD, "D3DLOCK_DISCARD", D3D_OK },
87 {D3DLOCK_NOOVERWRITE, "D3DLOCK_NOOVERWRITE", D3D_OK },
88 {D3DLOCK_NOOVERWRITE | D3DLOCK_DISCARD, "D3DLOCK_NOOVERWRITE | D3DLOCK_DISCARD", D3D_OK },
89 {D3DLOCK_NOOVERWRITE | D3DLOCK_READONLY, "D3DLOCK_NOOVERWRITE | D3DLOCK_READONLY", D3D_OK },
90 {D3DLOCK_READONLY | D3DLOCK_DISCARD, "D3DLOCK_READONLY | D3DLOCK_DISCARD", D3DERR_INVALIDCALL },
91 /* Completely bogous flags aren't an error */
92 {0xdeadbeef, "0xdeadbeef", D3DERR_INVALIDCALL },
95 hr = IDirect3DDevice9_CreateVertexBuffer(device, 1024, D3DUSAGE_DYNAMIC, 0, D3DPOOL_DEFAULT, &buffer, NULL);
96 ok(hr == D3D_OK, "IDirect3DDevice9_CreateBuffer failed, 0x%08x\n", hr);
98 for(i = 0; i < (sizeof(test_data) / sizeof(*test_data)); i++)
100 hr = IDirect3DVertexBuffer9_Lock(buffer, 0, 0, &data, test_data[i].flags);
101 /* Windows XP always returns D3D_OK even with flags that don't make sense. Windows 7 returns
102 * an error. At least one game(Shaiya) depends on the Windows XP result, so mark the Windows 7
103 * behavior as broken()
105 ok(hr == D3D_OK || broken(hr == test_data[i].win7_result), "Lock flags %s returned 0x%08x, expected D3D_OK\n",
106 test_data[i].debug_string, hr);
108 if(SUCCEEDED(hr))
110 ok(data != NULL, "The data pointer returned by Lock is NULL\n");
111 hr = IDirect3DVertexBuffer9_Unlock(buffer);
112 ok(hr == D3D_OK, "IDirect3DVertexBuffer9_Unlock failed, 0x%08x\n", hr);
116 IDirect3DVertexBuffer9_Release(buffer);
119 static inline const char *debug_d3dpool(D3DPOOL pool)
121 switch(pool)
123 case D3DPOOL_DEFAULT: return "D3DPOOL_DEFAULT";
124 case D3DPOOL_SYSTEMMEM: return "D3DPOOL_SYSTEMMEM";
125 case D3DPOOL_SCRATCH: return "D3DPOOL_SCRATCH";
126 case D3DPOOL_MANAGED: return "D3DPOOL_MANAGED";
127 default:
128 return "unknown pool";
132 static void test_vertex_buffer_alignment(IDirect3DDevice9 *device)
134 IDirect3DVertexBuffer9 *buffer = NULL;
135 HRESULT hr;
136 D3DPOOL pools[] = {D3DPOOL_DEFAULT, D3DPOOL_SYSTEMMEM, D3DPOOL_SCRATCH, D3DPOOL_MANAGED};
137 DWORD sizes[] = {1, 4, 16, 17, 32, 33, 64, 65, 1024, 1025, 1048576, 1048577};
138 unsigned int i, j;
139 void *data;
140 unsigned int align = 16;
142 for(i = 0; i < (sizeof(sizes) / sizeof(sizes[0])); i++)
144 for(j = 0; j < (sizeof(pools) / sizeof(pools[0])); j++)
146 hr = IDirect3DDevice9_CreateVertexBuffer(device, sizes[i], 0, 0, pools[j], &buffer, NULL);
147 if(pools[j] == D3DPOOL_SCRATCH)
149 ok(hr == D3DERR_INVALIDCALL, "Creating a D3DPOOL_SCRATCH buffer returned (0x%08x)\n", hr);
151 else
153 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateVertexBuffer failed (0x%08x). Pool = %s, size %d\n", hr,
154 debug_d3dpool(pools[j]), sizes[i]);
156 if(FAILED(hr)) continue;
158 hr = IDirect3DVertexBuffer9_Lock(buffer, 0, 0, &data, 0);
159 ok(SUCCEEDED(hr), "IDirect3DVertexBuffer9_Lock failed (0x%08x)\n", hr);
160 ok(((DWORD_PTR) data & (align - 1)) == 0, "Vertex buffer start address is not %u byte aligned(size: %d, pool: %s, data: %p)\n",
161 align, sizes[i], debug_d3dpool(pools[j]), data);
162 hr = IDirect3DVertexBuffer9_Unlock(buffer);
163 ok(SUCCEEDED(hr), "IDirect3DVertexBuffer9_Unlock failed (0x%08x)\n", hr);
165 if(buffer) IDirect3DVertexBuffer9_Release(buffer);
170 START_TEST(buffer)
172 IDirect3DDevice9 *device_ptr;
173 ULONG refcount;
175 d3d9_handle = LoadLibraryA("d3d9.dll");
176 if (!d3d9_handle)
178 skip("Could not load d3d9.dll\n");
179 return;
182 device_ptr = init_d3d9();
183 if (!device_ptr) return;
185 lock_flag_test(device_ptr);
186 test_vertex_buffer_alignment(device_ptr);
188 refcount = IDirect3DDevice9_Release(device_ptr);
189 ok(!refcount, "Device has %u references left\n", refcount);