From e7163c802d3e13f434bcb58afe04f40d35221a03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20D=C3=B6singer?= Date: Tue, 3 Jun 2014 09:41:43 +0200 Subject: [PATCH] ddraw/tests: Test D3DVBCAPS_WRITEONLY. --- dlls/ddraw/tests/ddraw4.c | 70 +++++++++++++++++++++++++++++++++++++++ dlls/ddraw/tests/ddraw7.c | 70 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+) diff --git a/dlls/ddraw/tests/ddraw4.c b/dlls/ddraw/tests/ddraw4.c index 3d0bfe5334b..464d95597d2 100644 --- a/dlls/ddraw/tests/ddraw4.c +++ b/dlls/ddraw/tests/ddraw4.c @@ -7438,6 +7438,75 @@ static void test_palette_alpha(void) DestroyWindow(window); } +static void test_vb_writeonly(void) +{ + IDirect3DDevice3 *device; + IDirect3D3 *d3d; + IDirect3DVertexBuffer *buffer; + HWND window; + HRESULT hr; + D3DVERTEXBUFFERDESC desc; + void *ptr; + static const struct vec4 quad[] = + { + { 0.0f, 480.0f, 0.0f, 1.0f}, + { 0.0f, 0.0f, 0.0f, 1.0f}, + {640.0f, 480.0f, 0.0f, 1.0f}, + {640.0f, 0.0f, 0.0f, 1.0f}, + }; + + window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW, + 0, 0, 640, 480, 0, 0, 0, 0); + + if (!(device = create_device(window, DDSCL_NORMAL))) + { + skip("Failed to create a 3D device, skipping test.\n"); + DestroyWindow(window); + return; + } + + hr = IDirect3DDevice3_GetDirect3D(device, &d3d); + ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr); + + memset(&desc, 0, sizeof(desc)); + desc.dwSize = sizeof(desc); + desc.dwCaps = D3DVBCAPS_WRITEONLY; + desc.dwFVF = D3DFVF_XYZRHW; + desc.dwNumVertices = sizeof(quad) / sizeof(*quad); + hr = IDirect3D3_CreateVertexBuffer(d3d, &desc, &buffer, 0, NULL); + ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr); + + hr = IDirect3DVertexBuffer_Lock(buffer, DDLOCK_DISCARDCONTENTS, &ptr, NULL); + ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr); + memcpy(ptr, quad, sizeof(quad)); + hr = IDirect3DVertexBuffer_Unlock(buffer); + ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr); + + hr = IDirect3DDevice3_BeginScene(device); + ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr); + hr = IDirect3DDevice3_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, 4, 0); + ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr); + hr = IDirect3DDevice3_EndScene(device); + ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr); + + hr = IDirect3DVertexBuffer_Lock(buffer, 0, &ptr, NULL); + ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr); + ok (!memcmp(ptr, quad, sizeof(quad)), "Got unexpected vertex buffer data.\n"); + hr = IDirect3DVertexBuffer_Unlock(buffer); + ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr); + + hr = IDirect3DVertexBuffer_Lock(buffer, DDLOCK_READONLY, &ptr, NULL); + ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr); + ok (!memcmp(ptr, quad, sizeof(quad)), "Got unexpected vertex buffer data.\n"); + hr = IDirect3DVertexBuffer_Unlock(buffer); + ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr); + + IDirect3DVertexBuffer_Release(buffer); + IDirect3D3_Release(d3d); + IDirect3DDevice3_Release(device); + DestroyWindow(window); +} + START_TEST(ddraw4) { IDirectDraw4 *ddraw; @@ -7500,4 +7569,5 @@ START_TEST(ddraw4) test_material(); test_palette_gdi(); test_palette_alpha(); + test_vb_writeonly(); } diff --git a/dlls/ddraw/tests/ddraw7.c b/dlls/ddraw/tests/ddraw7.c index 97a6a19f85a..1c5bc1d64b9 100644 --- a/dlls/ddraw/tests/ddraw7.c +++ b/dlls/ddraw/tests/ddraw7.c @@ -7160,6 +7160,75 @@ static void test_palette_alpha(void) DestroyWindow(window); } +static void test_vb_writeonly(void) +{ + IDirect3DDevice7 *device; + IDirect3D7 *d3d; + IDirect3DVertexBuffer7 *buffer; + HWND window; + HRESULT hr; + D3DVERTEXBUFFERDESC desc; + void *ptr; + static const struct vec4 quad[] = + { + { 0.0f, 480.0f, 0.0f, 1.0f}, + { 0.0f, 0.0f, 0.0f, 1.0f}, + {640.0f, 480.0f, 0.0f, 1.0f}, + {640.0f, 0.0f, 0.0f, 1.0f}, + }; + + window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW, + 0, 0, 640, 480, 0, 0, 0, 0); + + if (!(device = create_device(window, DDSCL_NORMAL))) + { + skip("Failed to create a 3D device, skipping test.\n"); + DestroyWindow(window); + return; + } + + hr = IDirect3DDevice7_GetDirect3D(device, &d3d); + ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr); + + memset(&desc, 0, sizeof(desc)); + desc.dwSize = sizeof(desc); + desc.dwCaps = D3DVBCAPS_WRITEONLY; + desc.dwFVF = D3DFVF_XYZRHW; + desc.dwNumVertices = sizeof(quad) / sizeof(*quad); + hr = IDirect3D7_CreateVertexBuffer(d3d, &desc, &buffer, 0); + ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr); + + hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, &ptr, NULL); + ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr); + memcpy(ptr, quad, sizeof(quad)); + hr = IDirect3DVertexBuffer7_Unlock(buffer); + ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr); + + hr = IDirect3DDevice7_BeginScene(device); + ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr); + hr = IDirect3DDevice7_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, 4, 0); + ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr); + hr = IDirect3DDevice7_EndScene(device); + ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr); + + hr = IDirect3DVertexBuffer7_Lock(buffer, 0, &ptr, NULL); + ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr); + ok (!memcmp(ptr, quad, sizeof(quad)), "Got unexpected vertex buffer data.\n"); + hr = IDirect3DVertexBuffer7_Unlock(buffer); + ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr); + + hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_READONLY, &ptr, NULL); + ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr); + ok (!memcmp(ptr, quad, sizeof(quad)), "Got unexpected vertex buffer data.\n"); + hr = IDirect3DVertexBuffer7_Unlock(buffer); + ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr); + + IDirect3DVertexBuffer7_Release(buffer); + IDirect3D7_Release(d3d); + IDirect3DDevice7_Release(device); + DestroyWindow(window); +} + START_TEST(ddraw7) { HMODULE module = GetModuleHandleA("ddraw.dll"); @@ -7229,4 +7298,5 @@ START_TEST(ddraw7) test_material(); test_palette_gdi(); test_palette_alpha(); + test_vb_writeonly(); }