d3d8: Add a surface locking test.

This commit is contained in:
H. Verbeet 2007-05-03 20:59:25 +02:00 committed by Alexandre Julliard
parent 1316b7f5e4
commit 2c7328891b
1 changed files with 76 additions and 1 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2006 Henri Verbeet
* Copyright 2006-2007 Henri Verbeet
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -121,6 +121,80 @@ cleanup:
if (surface_ptr) IDirect3DSurface8_Release(surface_ptr);
}
static void test_lockrect_invalid(IDirect3DDevice8 *device)
{
IDirect3DSurface8 *surface = 0;
D3DLOCKED_RECT locked_rect;
unsigned int i;
BYTE *base;
HRESULT hr;
const RECT valid[] = {
{60, 60, 68, 68},
{120, 60, 128, 68},
{60, 120, 68, 128},
};
const RECT invalid[] = {
{60, 60, 60, 68}, /* 0 height */
{60, 60, 68, 60}, /* 0 width */
{68, 60, 60, 68}, /* left > right */
{60, 68, 68, 60}, /* top > bottom */
{-8, 60, 0, 68}, /* left < surface */
{60, -8, 68, 0}, /* top < surface */
{-16, 60, -8, 68}, /* right < surface */
{60, -16, 68, -8}, /* bottom < surface */
{60, 60, 136, 68}, /* right > surface */
{60, 60, 68, 136}, /* bottom > surface */
{136, 60, 144, 68}, /* left > surface */
{60, 136, 68, 144}, /* top > surface */
};
hr = IDirect3DDevice8_CreateImageSurface(device, 128, 128, D3DFMT_A8R8G8B8, &surface);
ok(SUCCEEDED(hr), "CreateImageSurface failed (0x%08x)\n", hr);
hr = IDirect3DSurface8_LockRect(surface, &locked_rect, NULL, 0);
ok(SUCCEEDED(hr), "LockRect failed (0x%08x)\n", hr);
base = locked_rect.pBits;
hr = IDirect3DSurface8_UnlockRect(surface);
ok(SUCCEEDED(hr), "UnlockRect failed (0x%08x)\n", hr);
for (i = 0; i < (sizeof(valid) / sizeof(*valid)); ++i)
{
unsigned int offset, expected_offset;
const RECT *rect = &valid[i];
locked_rect.pBits = (BYTE *)0xdeadbeef;
locked_rect.Pitch = 0xdeadbeef;
hr = IDirect3DSurface8_LockRect(surface, &locked_rect, rect, 0);
ok(SUCCEEDED(hr), "LockRect failed (0x%08x) for rect [%d, %d]->[%d, %d]\n",
hr, rect->left, rect->top, rect->right, rect->bottom);
offset = (BYTE *)locked_rect.pBits - base;
expected_offset = rect->top * locked_rect.Pitch + rect->left * 4;
ok(offset == expected_offset, "Got offset %u, expected offset %u for rect [%d, %d]->[%d, %d]\n",
offset, expected_offset, rect->left, rect->top, rect->right, rect->bottom);
hr = IDirect3DSurface8_UnlockRect(surface);
ok(SUCCEEDED(hr), "UnlockRect failed (0x%08x)\n", hr);
}
for (i = 0; i < (sizeof(invalid) / sizeof(*invalid)); ++i)
{
const RECT *rect = &invalid[i];
hr = IDirect3DSurface8_LockRect(surface, &locked_rect, rect, 0);
ok(hr == D3DERR_INVALIDCALL, "LockRect returned 0x%08x for rect [%d, %d]->[%d, %d]"
", expected D3DERR_INVALIDCALL (0x%08x)\n", hr, rect->left, rect->top,
rect->right, rect->bottom, D3DERR_INVALIDCALL);
}
IDirect3DSurface8_Release(surface);
}
START_TEST(surface)
{
HMODULE d3d8_handle;
@ -137,4 +211,5 @@ START_TEST(surface)
if (!device_ptr) return;
test_surface_get_container(device_ptr);
test_lockrect_invalid(device_ptr);
}