ddraw/tests: Port test_lockrect_invalid to other versions.

Signed-off-by: Stefan Dösinger <stefandoesinger@gmx.at>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Stefan Dösinger 2016-01-21 16:40:13 +01:00 committed by Alexandre Julliard
parent e5132e5a91
commit 4fac292ee8
5 changed files with 616 additions and 121 deletions

View File

@ -8010,6 +8010,153 @@ static void test_shademode(void)
DestroyWindow(window);
}
static void test_lockrect_invalid(void)
{
unsigned int i, r;
IDirectDraw *ddraw;
IDirectDrawSurface *surface;
HWND window;
HRESULT hr;
DDSURFACEDESC surface_desc;
DDCAPS hal_caps;
DWORD needed_caps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
static RECT valid[] =
{
{60, 60, 68, 68},
{60, 60, 60, 68},
{60, 60, 68, 60},
{120, 60, 128, 68},
{60, 120, 68, 128},
};
static RECT invalid[] =
{
{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 */
};
static const struct
{
DWORD caps;
const char *name;
HRESULT hr;
}
resources[] =
{
{DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, "sysmem offscreenplain", DDERR_INVALIDPARAMS},
{DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, "vidmem offscreenplain", DDERR_INVALIDPARAMS},
{DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, "sysmem texture", DDERR_INVALIDPARAMS},
{DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, "vidmem texture", DDERR_INVALIDPARAMS},
};
window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
0, 0, 640, 480, 0, 0, 0, 0);
ddraw = create_ddraw();
ok(!!ddraw, "Failed to create a ddraw object.\n");
hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
memset(&hal_caps, 0, sizeof(hal_caps));
hal_caps.dwSize = sizeof(hal_caps);
hr = IDirectDraw_GetCaps(ddraw, &hal_caps, NULL);
ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
if ((hal_caps.ddsCaps.dwCaps & needed_caps) != needed_caps)
{
skip("Required surface types not supported, skipping test.\n");
goto done;
}
for (r = 0; r < sizeof(resources) / sizeof(*resources); ++r)
{
memset(&surface_desc, 0, sizeof(surface_desc));
surface_desc.dwSize = sizeof(surface_desc);
surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
surface_desc.ddsCaps.dwCaps = resources[r].caps;
surface_desc.dwWidth = 128;
surface_desc.dwHeight = 128;
surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0xff0000;
U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x00ff00;
U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x0000ff;
hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, type %s.\n", hr, resources[r].name);
hr = IDirectDrawSurface_Lock(surface, NULL, NULL, DDLOCK_WAIT, NULL);
ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
for (i = 0; i < sizeof(valid) / sizeof(*valid); ++i)
{
RECT *rect = &valid[i];
memset(&surface_desc, 0, sizeof(surface_desc));
surface_desc.dwSize = sizeof(surface_desc);
hr = IDirectDrawSurface_Lock(surface, rect, &surface_desc, DDLOCK_WAIT, NULL);
ok(SUCCEEDED(hr), "Lock failed (%#x) for rect [%d, %d]->[%d, %d], type %s.\n",
hr, rect->left, rect->top, rect->right, rect->bottom, resources[r].name);
hr = IDirectDrawSurface_Unlock(surface, NULL);
ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
}
for (i = 0; i < sizeof(invalid) / sizeof(*invalid); ++i)
{
RECT *rect = &invalid[i];
memset(&surface_desc, 1, sizeof(surface_desc));
surface_desc.dwSize = sizeof(surface_desc);
hr = IDirectDrawSurface_Lock(surface, rect, &surface_desc, DDLOCK_WAIT, NULL);
ok(hr == resources[r].hr, "Lock returned %#x for rect [%d, %d]->[%d, %d], type %s.\n",
hr, rect->left, rect->top, rect->right, rect->bottom, resources[r].name);
if (SUCCEEDED(hr))
{
hr = IDirectDrawSurface_Unlock(surface, NULL);
ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
}
else
ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
}
hr = IDirectDrawSurface_Lock(surface, NULL, &surface_desc, DDLOCK_WAIT, NULL);
ok(SUCCEEDED(hr), "Lock(rect = NULL) failed, hr %#x, type %s.\n",
hr, resources[r].name);
hr = IDirectDrawSurface_Lock(surface, NULL, &surface_desc, DDLOCK_WAIT, NULL);
ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = NULL) returned %#x, type %s.\n",
hr, resources[r].name);
hr = IDirectDrawSurface_Unlock(surface, NULL);
ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
hr = IDirectDrawSurface_Lock(surface, &valid[0], &surface_desc, DDLOCK_WAIT, NULL);
ok(SUCCEEDED(hr), "Lock(rect = [%d, %d]->[%d, %d]) failed (%#x).\n",
valid[0].left, valid[0].top, valid[0].right, valid[0].bottom, hr);
hr = IDirectDrawSurface_Lock(surface, &valid[0], &surface_desc, DDLOCK_WAIT, NULL);
ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = [%d, %d]->[%d, %d]) failed (%#x).\n",
valid[0].left, valid[0].top, valid[0].right, valid[0].bottom, hr);
/* Locking a different rectangle returns DD_OK, but it seems to break the surface.
* Afterwards unlocking the surface fails(NULL rectangle or both locked rectangles) */
hr = IDirectDrawSurface_Unlock(surface, NULL);
ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
IDirectDrawSurface_Release(surface);
}
done:
IDirectDraw_Release(ddraw);
DestroyWindow(window);
}
START_TEST(ddraw1)
{
IDirectDraw *ddraw;
@ -8082,4 +8229,5 @@ START_TEST(ddraw1)
test_colorkey_precision();
test_range_colorkey();
test_shademode();
test_lockrect_invalid();
}

View File

@ -9112,6 +9112,157 @@ static void test_shademode(void)
DestroyWindow(window);
}
static void test_lockrect_invalid(void)
{
unsigned int i, r;
IDirectDraw2 *ddraw;
IDirectDrawSurface *surface1;
IDirectDrawSurface2 *surface;
HWND window;
HRESULT hr;
DDSURFACEDESC surface_desc;
DDCAPS hal_caps;
DWORD needed_caps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
static RECT valid[] =
{
{60, 60, 68, 68},
{60, 60, 60, 68},
{60, 60, 68, 60},
{120, 60, 128, 68},
{60, 120, 68, 128},
};
static RECT invalid[] =
{
{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 */
};
static const struct
{
DWORD caps;
const char *name;
HRESULT hr;
}
resources[] =
{
{DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, "sysmem offscreenplain", DDERR_INVALIDPARAMS},
{DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, "vidmem offscreenplain", DDERR_INVALIDPARAMS},
{DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, "sysmem texture", DDERR_INVALIDPARAMS},
{DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, "vidmem texture", DDERR_INVALIDPARAMS},
};
window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
0, 0, 640, 480, 0, 0, 0, 0);
ddraw = create_ddraw();
ok(!!ddraw, "Failed to create a ddraw object.\n");
hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
memset(&hal_caps, 0, sizeof(hal_caps));
hal_caps.dwSize = sizeof(hal_caps);
hr = IDirectDraw2_GetCaps(ddraw, &hal_caps, NULL);
ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
if ((hal_caps.ddsCaps.dwCaps & needed_caps) != needed_caps)
{
skip("Required surface types not supported, skipping test.\n");
goto done;
}
for (r = 0; r < sizeof(resources) / sizeof(*resources); ++r)
{
memset(&surface_desc, 0, sizeof(surface_desc));
surface_desc.dwSize = sizeof(surface_desc);
surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
surface_desc.ddsCaps.dwCaps = resources[r].caps;
surface_desc.dwWidth = 128;
surface_desc.dwHeight = 128;
surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0xff0000;
U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x00ff00;
U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x0000ff;
hr = IDirectDraw2_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, type %s.\n", hr, resources[r].name);
hr = IDirectDrawSurface_QueryInterface(surface1, &IID_IDirectDrawSurface2, (void **)&surface);
ok(SUCCEEDED(hr), "Failed to QI IDirectDrawSurface2 interface, hr %#x.\n", hr);
IDirectDrawSurface_Release(surface1);
hr = IDirectDrawSurface2_Lock(surface, NULL, NULL, DDLOCK_WAIT, NULL);
ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
for (i = 0; i < sizeof(valid) / sizeof(*valid); ++i)
{
RECT *rect = &valid[i];
memset(&surface_desc, 0, sizeof(surface_desc));
surface_desc.dwSize = sizeof(surface_desc);
hr = IDirectDrawSurface2_Lock(surface, rect, &surface_desc, DDLOCK_WAIT, NULL);
ok(SUCCEEDED(hr), "Lock failed (%#x) for rect [%d, %d]->[%d, %d], type %s.\n",
hr, rect->left, rect->top, rect->right, rect->bottom, resources[r].name);
hr = IDirectDrawSurface2_Unlock(surface, NULL);
ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
}
for (i = 0; i < sizeof(invalid) / sizeof(*invalid); ++i)
{
RECT *rect = &invalid[i];
memset(&surface_desc, 1, sizeof(surface_desc));
surface_desc.dwSize = sizeof(surface_desc);
hr = IDirectDrawSurface2_Lock(surface, rect, &surface_desc, DDLOCK_WAIT, NULL);
ok(hr == resources[r].hr, "Lock returned %#x for rect [%d, %d]->[%d, %d], type %s.\n",
hr, rect->left, rect->top, rect->right, rect->bottom, resources[r].name);
if (SUCCEEDED(hr))
{
hr = IDirectDrawSurface2_Unlock(surface, NULL);
ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
}
else
ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
}
hr = IDirectDrawSurface2_Lock(surface, NULL, &surface_desc, DDLOCK_WAIT, NULL);
ok(SUCCEEDED(hr), "Lock(rect = NULL) failed, hr %#x, type %s.\n",
hr, resources[r].name);
hr = IDirectDrawSurface2_Lock(surface, NULL, &surface_desc, DDLOCK_WAIT, NULL);
ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = NULL) returned %#x, type %s.\n",
hr, resources[r].name);
hr = IDirectDrawSurface2_Unlock(surface, NULL);
ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
hr = IDirectDrawSurface2_Lock(surface, &valid[0], &surface_desc, DDLOCK_WAIT, NULL);
ok(SUCCEEDED(hr), "Lock(rect = [%d, %d]->[%d, %d]) failed (%#x).\n",
valid[0].left, valid[0].top, valid[0].right, valid[0].bottom, hr);
hr = IDirectDrawSurface2_Lock(surface, &valid[0], &surface_desc, DDLOCK_WAIT, NULL);
ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = [%d, %d]->[%d, %d]) failed (%#x).\n",
valid[0].left, valid[0].top, valid[0].right, valid[0].bottom, hr);
/* Locking a different rectangle returns DD_OK, but it seems to break the surface.
* Afterwards unlocking the surface fails(NULL rectangle or both locked rectangles) */
hr = IDirectDrawSurface2_Unlock(surface, NULL);
ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
IDirectDrawSurface2_Release(surface);
}
done:
IDirectDraw2_Release(ddraw);
DestroyWindow(window);
}
START_TEST(ddraw2)
{
IDirectDraw2 *ddraw;
@ -9191,4 +9342,5 @@ START_TEST(ddraw2)
test_colorkey_precision();
test_range_colorkey();
test_shademode();
test_lockrect_invalid();
}

View File

@ -10281,6 +10281,156 @@ static void test_shademode(void)
DestroyWindow(window);
}
static void test_lockrect_invalid(void)
{
unsigned int i, r;
IDirectDraw4 *ddraw;
IDirectDrawSurface4 *surface;
HWND window;
HRESULT hr;
DDSURFACEDESC2 surface_desc;
DDCAPS hal_caps;
DWORD needed_caps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
static RECT valid[] =
{
{60, 60, 68, 68},
{60, 60, 60, 68},
{60, 60, 68, 60},
{120, 60, 128, 68},
{60, 120, 68, 128},
};
static RECT invalid[] =
{
{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 */
};
static const struct
{
DWORD caps, caps2;
const char *name;
HRESULT hr;
}
resources[] =
{
{DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0, "sysmem offscreenplain", DDERR_INVALIDPARAMS},
{DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0, "vidmem offscreenplain", DDERR_INVALIDPARAMS},
{DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, "sysmem texture", DDERR_INVALIDPARAMS},
{DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0, "vidmem texture", DDERR_INVALIDPARAMS},
{DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, "managed texture", DDERR_INVALIDPARAMS},
};
window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
0, 0, 640, 480, 0, 0, 0, 0);
ddraw = create_ddraw();
ok(!!ddraw, "Failed to create a ddraw object.\n");
hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
memset(&hal_caps, 0, sizeof(hal_caps));
hal_caps.dwSize = sizeof(hal_caps);
hr = IDirectDraw4_GetCaps(ddraw, &hal_caps, NULL);
ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
if ((hal_caps.ddsCaps.dwCaps & needed_caps) != needed_caps
|| !(hal_caps.ddsCaps.dwCaps & DDSCAPS2_TEXTUREMANAGE))
{
skip("Required surface types not supported, skipping test.\n");
goto done;
}
for (r = 0; r < sizeof(resources) / sizeof(*resources); ++r)
{
memset(&surface_desc, 0, sizeof(surface_desc));
surface_desc.dwSize = sizeof(surface_desc);
surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
surface_desc.ddsCaps.dwCaps = resources[r].caps;
surface_desc.ddsCaps.dwCaps2 = resources[r].caps2;
surface_desc.dwWidth = 128;
surface_desc.dwHeight = 128;
U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0xff0000;
U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x00ff00;
U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x0000ff;
hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, type %s.\n", hr, resources[r].name);
hr = IDirectDrawSurface4_Lock(surface, NULL, NULL, DDLOCK_WAIT, NULL);
ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
for (i = 0; i < sizeof(valid) / sizeof(*valid); ++i)
{
RECT *rect = &valid[i];
memset(&surface_desc, 0, sizeof(surface_desc));
surface_desc.dwSize = sizeof(surface_desc);
hr = IDirectDrawSurface4_Lock(surface, rect, &surface_desc, DDLOCK_WAIT, NULL);
ok(SUCCEEDED(hr), "Lock failed (%#x) for rect [%d, %d]->[%d, %d], type %s.\n",
hr, rect->left, rect->top, rect->right, rect->bottom, resources[r].name);
hr = IDirectDrawSurface4_Unlock(surface, NULL);
ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
}
for (i = 0; i < sizeof(invalid) / sizeof(*invalid); ++i)
{
RECT *rect = &invalid[i];
memset(&surface_desc, 1, sizeof(surface_desc));
surface_desc.dwSize = sizeof(surface_desc);
hr = IDirectDrawSurface4_Lock(surface, rect, &surface_desc, DDLOCK_WAIT, NULL);
ok(hr == resources[r].hr, "Lock returned %#x for rect [%d, %d]->[%d, %d], type %s.\n",
hr, rect->left, rect->top, rect->right, rect->bottom, resources[r].name);
if (SUCCEEDED(hr))
{
hr = IDirectDrawSurface4_Unlock(surface, NULL);
ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
}
else
ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
}
hr = IDirectDrawSurface4_Lock(surface, NULL, &surface_desc, DDLOCK_WAIT, NULL);
ok(SUCCEEDED(hr), "Lock(rect = NULL) failed, hr %#x, type %s.\n",
hr, resources[r].name);
hr = IDirectDrawSurface4_Lock(surface, NULL, &surface_desc, DDLOCK_WAIT, NULL);
ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = NULL) returned %#x, type %s.\n",
hr, resources[r].name);
hr = IDirectDrawSurface4_Unlock(surface, NULL);
ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
hr = IDirectDrawSurface4_Lock(surface, &valid[0], &surface_desc, DDLOCK_WAIT, NULL);
ok(SUCCEEDED(hr), "Lock(rect = [%d, %d]->[%d, %d]) failed (%#x).\n",
valid[0].left, valid[0].top, valid[0].right, valid[0].bottom, hr);
hr = IDirectDrawSurface4_Lock(surface, &valid[0], &surface_desc, DDLOCK_WAIT, NULL);
ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = [%d, %d]->[%d, %d]) failed (%#x).\n",
valid[0].left, valid[0].top, valid[0].right, valid[0].bottom, hr);
/* Locking a different rectangle returns DD_OK, but it seems to break the surface.
* Afterwards unlocking the surface fails(NULL rectangle or both locked rectangles) */
hr = IDirectDrawSurface4_Unlock(surface, NULL);
ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
IDirectDrawSurface4_Release(surface);
}
done:
IDirectDraw4_Release(ddraw);
DestroyWindow(window);
}
START_TEST(ddraw4)
{
IDirectDraw4 *ddraw;
@ -10367,4 +10517,5 @@ START_TEST(ddraw4)
test_colorkey_precision();
test_range_colorkey();
test_shademode();
test_lockrect_invalid();
}

View File

@ -10544,6 +10544,170 @@ static void test_shademode(void)
DestroyWindow(window);
}
static void test_lockrect_invalid(void)
{
unsigned int i, r;
IDirectDraw7 *ddraw;
IDirectDrawSurface7 *surface;
HWND window;
HRESULT hr;
DDSURFACEDESC2 surface_desc;
DDSURFACEDESC2 locked_desc;
DDCAPS hal_caps;
DWORD needed_caps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
static RECT valid[] =
{
{60, 60, 68, 68},
{60, 60, 60, 68},
{60, 60, 68, 60},
{120, 60, 128, 68},
{60, 120, 68, 128},
};
static RECT invalid[] =
{
{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 */
};
static const struct
{
DWORD caps, caps2;
const char *name;
HRESULT hr;
}
resources[] =
{
{DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0, "sysmem offscreenplain", DDERR_INVALIDPARAMS},
{DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0, "vidmem offscreenplain", DDERR_INVALIDPARAMS},
{DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, "sysmem texture", DD_OK},
{DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0, "vidmem texture", DDERR_INVALIDPARAMS},
{DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, "managed texture", DD_OK},
};
window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
0, 0, 640, 480, 0, 0, 0, 0);
ddraw = create_ddraw();
ok(!!ddraw, "Failed to create a ddraw object.\n");
hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
memset(&hal_caps, 0, sizeof(hal_caps));
hal_caps.dwSize = sizeof(hal_caps);
hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
if ((hal_caps.ddsCaps.dwCaps & needed_caps) != needed_caps
|| !(hal_caps.ddsCaps.dwCaps & DDSCAPS2_TEXTUREMANAGE))
{
skip("Required surface types not supported, skipping test.\n");
goto done;
}
for (r = 0; r < sizeof(resources) / sizeof(*resources); ++r)
{
memset(&surface_desc, 0, sizeof(surface_desc));
surface_desc.dwSize = sizeof(surface_desc);
surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
surface_desc.ddsCaps.dwCaps = resources[r].caps;
surface_desc.ddsCaps.dwCaps2 = resources[r].caps2;
surface_desc.dwWidth = 128;
surface_desc.dwHeight = 128;
U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0xff0000;
U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x00ff00;
U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x0000ff;
hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
if (is_ddraw64 && (resources[r].caps & DDSCAPS_TEXTURE))
{
todo_wine ok(hr == E_NOINTERFACE, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
if (SUCCEEDED(hr))
IDirectDrawSurface7_Release(surface);
continue;
}
ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, type %s.\n", hr, resources[r].name);
/* Crashes in ddraw7
hr = IDirectDrawSurface7_Lock(surface, NULL, NULL, DDLOCK_WAIT, NULL);
ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
*/
for (i = 0; i < sizeof(valid) / sizeof(*valid); ++i)
{
RECT *rect = &valid[i];
memset(&locked_desc, 0, sizeof(locked_desc));
locked_desc.dwSize = sizeof(locked_desc);
hr = IDirectDrawSurface7_Lock(surface, rect, &locked_desc, DDLOCK_WAIT, NULL);
ok(SUCCEEDED(hr), "Lock failed (%#x) for rect [%d, %d]->[%d, %d], type %s.\n",
hr, rect->left, rect->top, rect->right, rect->bottom, resources[r].name);
hr = IDirectDrawSurface7_Unlock(surface, NULL);
ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
}
for (i = 0; i < sizeof(invalid) / sizeof(*invalid); ++i)
{
RECT *rect = &invalid[i];
memset(&locked_desc, 1, sizeof(locked_desc));
locked_desc.dwSize = sizeof(locked_desc);
hr = IDirectDrawSurface7_Lock(surface, rect, &locked_desc, DDLOCK_WAIT, NULL);
if (SUCCEEDED(resources[r].hr))
todo_wine ok(hr == resources[r].hr, "Lock returned %#x for rect [%d, %d]->[%d, %d], type %s.\n",
hr, rect->left, rect->top, rect->right, rect->bottom, resources[r].name);
else
ok(hr == resources[r].hr, "Lock returned %#x for rect [%d, %d]->[%d, %d], type %s.\n",
hr, rect->left, rect->top, rect->right, rect->bottom, resources[r].name);
if (SUCCEEDED(hr))
{
hr = IDirectDrawSurface7_Unlock(surface, NULL);
ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
}
else
ok(!locked_desc.lpSurface, "Got unexpected lpSurface %p.\n", locked_desc.lpSurface);
}
hr = IDirectDrawSurface7_Lock(surface, NULL, &locked_desc, DDLOCK_WAIT, NULL);
ok(SUCCEEDED(hr), "Lock(rect = NULL) failed, hr %#x, type %s.\n",
hr, resources[r].name);
hr = IDirectDrawSurface7_Lock(surface, NULL, &locked_desc, DDLOCK_WAIT, NULL);
ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = NULL) returned %#x, type %s.\n",
hr, resources[r].name);
hr = IDirectDrawSurface7_Unlock(surface, NULL);
ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
hr = IDirectDrawSurface7_Lock(surface, &valid[0], &locked_desc, DDLOCK_WAIT, NULL);
ok(SUCCEEDED(hr), "Lock(rect = [%d, %d]->[%d, %d]) failed (%#x).\n",
valid[0].left, valid[0].top, valid[0].right, valid[0].bottom, hr);
hr = IDirectDrawSurface7_Lock(surface, &valid[0], &locked_desc, DDLOCK_WAIT, NULL);
ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = [%d, %d]->[%d, %d]) failed (%#x).\n",
valid[0].left, valid[0].top, valid[0].right, valid[0].bottom, hr);
/* Locking a different rectangle returns DD_OK, but it seems to break the surface.
* Afterwards unlocking the surface fails(NULL rectangle or both locked rectangles) */
hr = IDirectDrawSurface7_Unlock(surface, NULL);
ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
IDirectDrawSurface7_Release(surface);
}
done:
IDirectDraw7_Release(ddraw);
DestroyWindow(window);
}
START_TEST(ddraw7)
{
HMODULE module = GetModuleHandleA("ddraw.dll");
@ -10641,4 +10805,5 @@ START_TEST(ddraw7)
test_colorkey_precision();
test_range_colorkey();
test_shademode();
test_lockrect_invalid();
}

View File

@ -1208,126 +1208,6 @@ static void CubeMapTest(void)
if (dd7) IDirectDraw7_Release(dd7);
}
static void test_lockrect_invalid(void)
{
unsigned int i, j;
RECT valid[] = {
{60, 60, 68, 68},
{60, 60, 60, 68},
{60, 60, 68, 60},
{120, 60, 128, 68},
{60, 120, 68, 128},
};
RECT invalid[] = {
{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 */
};
const DWORD dds_caps[] = {
DDSCAPS_OFFSCREENPLAIN
};
for (j = 0; j < (sizeof(dds_caps) / sizeof(*dds_caps)); ++j)
{
IDirectDrawSurface *surface = 0;
DDSURFACEDESC surface_desc = {0};
DDSURFACEDESC locked_desc = {0};
HRESULT hr;
surface_desc.dwSize = sizeof(surface_desc);
surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
surface_desc.ddsCaps.dwCaps = dds_caps[j];
surface_desc.dwWidth = 128;
surface_desc.dwHeight = 128;
surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
U2(surface_desc.ddpfPixelFormat).dwRBitMask = 0xFF0000;
U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x00FF00;
U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x0000FF;
hr = IDirectDraw_CreateSurface(lpDD, &surface_desc, &surface, NULL);
ok(SUCCEEDED(hr), "CreateSurface failed (0x%08x)\n", hr);
if (FAILED(hr))
{
skip("failed to create surface\n");
continue;
}
hr = IDirectDrawSurface_Lock(surface, NULL, NULL, DDLOCK_WAIT, NULL);
ok(hr == DDERR_INVALIDPARAMS, "Lock returned 0x%08x for NULL DDSURFACEDESC,"
" expected DDERR_INVALIDPARAMS (0x%08x)\n", hr, DDERR_INVALIDPARAMS);
for (i = 0; i < (sizeof(valid) / sizeof(*valid)); ++i)
{
RECT *rect = &valid[i];
memset(&locked_desc, 0, sizeof(locked_desc));
locked_desc.dwSize = sizeof(locked_desc);
hr = IDirectDrawSurface_Lock(surface, rect, &locked_desc, DDLOCK_WAIT, NULL);
ok(SUCCEEDED(hr), "Lock failed (0x%08x) for rect [%d, %d]->[%d, %d]\n",
hr, rect->left, rect->top, rect->right, rect->bottom);
hr = IDirectDrawSurface_Unlock(surface, NULL);
ok(SUCCEEDED(hr), "Unlock failed (0x%08x)\n", hr);
}
for (i = 0; i < (sizeof(invalid) / sizeof(*invalid)); ++i)
{
RECT *rect = &invalid[i];
memset(&locked_desc, 1, sizeof(locked_desc));
locked_desc.dwSize = sizeof(locked_desc);
hr = IDirectDrawSurface_Lock(surface, rect, &locked_desc, DDLOCK_WAIT, NULL);
ok(hr == DDERR_INVALIDPARAMS, "Lock returned 0x%08x for rect [%d, %d]->[%d, %d]"
", expected DDERR_INVALIDPARAMS (0x%08x)\n", hr, rect->left, rect->top,
rect->right, rect->bottom, DDERR_INVALIDPARAMS);
ok(!locked_desc.lpSurface, "IDirectDrawSurface_Lock did not set lpSurface in the surface desc to zero.\n");
}
hr = IDirectDrawSurface_Lock(surface, NULL, &locked_desc, DDLOCK_WAIT, NULL);
ok(hr == DD_OK, "IDirectDrawSurface_Lock(rect = NULL) failed (0x%08x)\n", hr);
hr = IDirectDrawSurface_Lock(surface, NULL, &locked_desc, DDLOCK_WAIT, NULL);
ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = NULL) returned 0x%08x\n", hr);
if(SUCCEEDED(hr)) {
hr = IDirectDrawSurface_Unlock(surface, NULL);
ok(SUCCEEDED(hr), "Unlock failed (0x%08x)\n", hr);
}
hr = IDirectDrawSurface_Unlock(surface, NULL);
ok(SUCCEEDED(hr), "Unlock failed (0x%08x)\n", hr);
memset(&locked_desc, 0, sizeof(locked_desc));
locked_desc.dwSize = sizeof(locked_desc);
hr = IDirectDrawSurface_Lock(surface, &valid[0], &locked_desc, DDLOCK_WAIT, NULL);
ok(hr == DD_OK, "IDirectDrawSurface_Lock(rect = [%d, %d]->[%d, %d]) failed (0x%08x)\n",
valid[0].left, valid[0].top, valid[0].right, valid[0].bottom, hr);
hr = IDirectDrawSurface_Lock(surface, &valid[0], &locked_desc, DDLOCK_WAIT, NULL);
ok(hr == DDERR_SURFACEBUSY, "Double lock(rect = [%d, %d]->[%d, %d]) failed (0x%08x)\n",
valid[0].left, valid[0].top, valid[0].right, valid[0].bottom, hr);
/* Locking a different rectangle returns DD_OK, but it seems to break the surface.
* Afterwards unlocking the surface fails(NULL rectangle, and both locked rectangles
*/
hr = IDirectDrawSurface_Unlock(surface, NULL);
ok(hr == DD_OK, "Unlock returned (0x%08x)\n", hr);
IDirectDrawSurface_Release(surface);
}
}
static void CompressedTest(void)
{
HRESULT hr;
@ -3788,7 +3668,6 @@ START_TEST(dsurface)
GetDDInterface_7();
EnumTest();
CubeMapTest();
test_lockrect_invalid();
CompressedTest();
SizeTest();
BltParamTest();