From: David Adam Subject: patch [4/5] ddraw: Port Enumdevices to ddraw4 Message-Id: Date: Tue, 2 Apr 2019 20:40:12 -1000

From 209234a17ec82b0620e1ca80dcfcaaecb52d2f94 Mon Sep 17 00:00:00 2001 From: David Adam Date: Tue, 2 Apr 2019 20:22:00 -1000 Subject: [PATCH 4/4] Port Enumdevices tests to ddraw4 Signed-off-by: David Adam --- dlls/ddraw/tests/ddraw4.c | 284 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 284 insertions(+) diff --git a/dlls/ddraw/tests/ddraw4.c b/dlls/ddraw/tests/ddraw4.c index 0116106faa..cb48a3e01d 100644 --- a/dlls/ddraw/tests/ddraw4.c +++ b/dlls/ddraw/tests/ddraw4.c @@ -15998,6 +15998,288 @@ static void test_clipper_refcount(void) DestroyWindow(window); } +static HRESULT WINAPI enumDevicesCallback(GUID *Guid, char *DeviceDescription, + char *DeviceName, D3DDEVICEDESC *hal, D3DDEVICEDESC *hel, void *ctx) +{ + if(IsEqualGUID(&IID_IDirect3DRGBDevice, Guid)) + { + ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0, + "RGB Device 3 hal line caps has D3DPTEXTURECAPS_POW2 flag set\n"); + ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0, + "RGB Device 3 hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n"); + ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2, + "RGB Device 3 hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n"); + ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2, + "RGB Device 3 hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n"); + + ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0, + "RGB Device 3 hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n"); + ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0, + "RGB Device 3 hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n"); + ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE, + "RGB Device 3 hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n"); + ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE, + "RGB Device 3 hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n"); + + ok(hal->dcmColorModel == 0, "RGB Device 3 hal caps has colormodel %u\n", hal->dcmColorModel); + ok(hel->dcmColorModel == D3DCOLOR_RGB, "RGB Device 3 hel caps has colormodel %u\n", hel->dcmColorModel); + + ok(hal->dwFlags == 0, "RGB Device 3 hal caps has hardware flags %x\n", hal->dwFlags); + ok(hel->dwFlags != 0, "RGB Device 3 hel caps has hardware flags %x\n", hel->dwFlags); + } + else if(IsEqualGUID(&IID_IDirect3DHALDevice, Guid)) + { + trace("HAL Device 3\n"); + ok(hal->dcmColorModel == D3DCOLOR_RGB, "HAL Device 3 hal caps has colormodel %u\n", hel->dcmColorModel); + ok(hel->dcmColorModel == 0, "HAL Device 3 hel caps has colormodel %u\n", hel->dcmColorModel); + + ok(hal->dwFlags != 0, "HAL Device 3 hal caps has hardware flags %x\n", hal->dwFlags); + ok(hel->dwFlags != 0, "HAL Device 3 hel caps has hardware flags %x\n", hel->dwFlags); + } + else if(IsEqualGUID(&IID_IDirect3DRefDevice, Guid)) + { + ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0, + "REF Device 3 hal line caps has D3DPTEXTURECAPS_POW2 flag set\n"); + ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0, + "REF Device 3 hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n"); + ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2, + "REF Device 3 hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n"); + ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2, + "REF Device 3 hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n"); + + ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0, + "REF Device 3 hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n"); + ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0, + "REF Device 3 hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n"); + ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE, + "REF Device 3 hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n"); + ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE, + "REF Device 3 hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n"); + } + else if(IsEqualGUID(&IID_IDirect3DRampDevice, Guid)) + { + ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0, + "Ramp Device 3 hal line caps has D3DPTEXTURECAPS_POW2 flag set\n"); + ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0, + "Ramp Device 3 hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n"); + ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2, + "Ramp Device 3 hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n"); + ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2, + "Ramp Device 3 hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n"); + + ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0, + "Ramp Device 3 hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n"); + ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0, + "Ramp Device 3 hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n"); + ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE, + "Ramp Device 3 hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n"); + ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE, + "Ramp Device 3 hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n"); + + ok(hal->dcmColorModel == 0, "Ramp Device 3 hal caps has colormodel %u\n", hal->dcmColorModel); + ok(hel->dcmColorModel == D3DCOLOR_MONO, "Ramp Device 3 hel caps has colormodel %u\n", + hel->dcmColorModel); + + ok(hal->dwFlags == 0, "Ramp Device 3 hal caps has hardware flags %x\n", hal->dwFlags); + ok(hel->dwFlags != 0, "Ramp Device 3 hel caps has hardware flags %x\n", hel->dwFlags); + } + else if(IsEqualGUID(&IID_IDirect3DMMXDevice, Guid)) + { + ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0, + "MMX Device 3 hal line caps has D3DPTEXTURECAPS_POW2 flag set\n"); + ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0, + "MMX Device 3 hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n"); + ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2, + "MMX Device 3 hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n"); + ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2, + "MMX Device 3 hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n"); + + ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0, + "MMX Device 3 hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n"); + ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0, + "MMX Device 3 hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n"); + ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE, + "MMX Device 3 hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n"); + ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE, + "MMX Device 3 hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n"); + + ok(hal->dcmColorModel == 0, "MMX Device 3 hal caps has colormodel %u\n", hal->dcmColorModel); + ok(hel->dcmColorModel == D3DCOLOR_RGB, "MMX Device 3 hel caps has colormodel %u\n", hel->dcmColorModel); + + ok(hal->dwFlags == 0, "MMX Device 3 hal caps has hardware flags %x\n", hal->dwFlags); + ok(hel->dwFlags != 0, "MMX Device 3 hel caps has hardware flags %x\n", hel->dwFlags); + } + else + { + ok(FALSE, "Unexpected device enumerated: \"%s\" \"%s\"\n", DeviceDescription, DeviceName); + if(hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hal line has pow2 set\n"); + else trace("hal line does NOT have pow2 set\n"); + if(hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hal tri has pow2 set\n"); + else trace("hal tri does NOT have pow2 set\n"); + if(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hel line has pow2 set\n"); + else trace("hel line does NOT have pow2 set\n"); + if(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) trace("hel tri has pow2 set\n"); + else trace("hel tri does NOT have pow2 set\n"); + } + return DDENUMRET_OK; +} + +/* Check the deviceGUID of devices enumerated by + IDirect3D_EnumDevices. */ +static void test_enum_devices(void) +{ + IDirectDraw4 *ddraw; + IDirect3D3 *d3d3; + HRESULT hr; + + if (!(ddraw = create_ddraw())) + return; + + hr = IDirectDraw_QueryInterface(ddraw, &IID_IDirect3D3, (void **)&d3d3); + IDirectDraw_Release(ddraw); + if (FAILED(hr)) + { + return; + } + + hr = IDirect3D3_EnumDevices(d3d3, NULL, NULL); + ok(hr == DDERR_INVALIDPARAMS, "IDirect3D3_EnumDevices returned 0x%08x\n", hr); + + hr = IDirect3D3_EnumDevices(d3d3, enumDevicesCallback, NULL); + ok(hr == D3D_OK, "IDirect3D3_EnumDevices returned 0x%08x\n", hr); + + IDirect3D3_Release(d3d3); +} + +typedef struct { + HRESULT desired_ret; + int total; +} D3D3ECancelTest; + +#define MAX_ENUMERATION_COUNT 10 + +typedef struct +{ + unsigned int count; + char *callback_description_ptrs[MAX_ENUMERATION_COUNT]; + char callback_description_strings[MAX_ENUMERATION_COUNT][100]; + char *callback_name_ptrs[MAX_ENUMERATION_COUNT]; + char callback_name_strings[MAX_ENUMERATION_COUNT][100]; +} D3D3ELifetimeTest; + +static HRESULT WINAPI enumDevicesCancelTest(GUID *guid, char *DeviceDescription, char *DeviceName, + D3DDEVICEDESC *lpdd1, D3DDEVICEDESC *lpdd2, void *Context) +{ + D3D3ECancelTest *d3d3et = Context; + + d3d3et->total++; + + return d3d3et->desired_ret; +} + +static HRESULT WINAPI enumDevicesLifetimeTest(GUID *guid, char *DeviceDescription, char *DeviceName, + D3DDEVICEDESC *lpdd1, D3DDEVICEDESC *lpdd2, void *Context) +{ + D3D3ELifetimeTest *ctx = Context; + + if (ctx->count == MAX_ENUMERATION_COUNT) + { + ok(0, "Enumerated too many devices for context in callback\n"); + return DDENUMRET_CANCEL; + } + + ctx->callback_description_ptrs[ctx->count] = DeviceDescription; + strcpy(ctx->callback_description_strings[ctx->count], DeviceDescription); + ctx->callback_name_ptrs[ctx->count] = DeviceName; + strcpy(ctx->callback_name_strings[ctx->count], DeviceName); + + ctx->count++; + return DDENUMRET_OK; +} + +static void test_enum_devices_life_time(void) +{ + IDirectDraw4 *ddraw; + IDirect3D3 *d3d3; + HRESULT hr; + D3D3ELifetimeTest ctx, ctx2; + unsigned int i; + + if (!(ddraw = create_ddraw())) + return; + + hr = IDirectDraw_QueryInterface(ddraw, &IID_IDirect3D3, (void **)&d3d3); + IDirectDraw_Release(ddraw); + if (FAILED(hr)) + { + return; + } + + ctx.count = 0; + hr = IDirect3D3_EnumDevices(d3d3, enumDevicesLifetimeTest, &ctx); + ok(hr == D3D_OK, "IDirect3D3_EnumDevices returned 0x%08x\n", hr); + + /* The enumeration strings remain valid even after IDirect3D3_EnumDevices finishes. */ + for (i = 0; i < ctx.count; i++) + { + ok(!strcmp(ctx.callback_description_ptrs[i], ctx.callback_description_strings[i]), + "Got '%s' and '%s'\n", ctx.callback_description_ptrs[i], ctx.callback_description_strings[i]); + todo_wine ok(!strcmp(ctx.callback_name_ptrs[i], ctx.callback_name_strings[i]), + "Got '%s' and '%s'\n", ctx.callback_name_ptrs[i], ctx.callback_name_strings[i]); + } + + ctx2.count = 0; + hr = IDirect3D3_EnumDevices(d3d3, enumDevicesLifetimeTest, &ctx2); + ok(hr == D3D_OK, "IDirect3D3_EnumDevices returned 0x%08x\n", hr); + + /* The enumeration strings and their order are identical across enumerations. */ + ok(ctx.count == ctx2.count, "Enumerated %u and %u devices\n", ctx.count, ctx2.count); + if (ctx.count == ctx2.count) + { + for (i = 0; i < ctx.count; i++) + { + ok(ctx.callback_description_ptrs[i] == ctx2.callback_description_ptrs[i], + "Unequal description pointers %p and %p\n", ctx.callback_description_ptrs[i], ctx2.callback_description_ptrs[i]); + ok(!strcmp(ctx.callback_description_strings[i], ctx2.callback_description_strings[i]), + "Got '%s' and '%s'\n", ctx.callback_description_strings[i], ctx2.callback_description_strings[i]); + ok(ctx.callback_name_ptrs[i] == ctx2.callback_name_ptrs[i], + "Unequal name pointers %p and %p\n", ctx.callback_name_ptrs[i], ctx2.callback_name_ptrs[i]); + ok(!strcmp(ctx.callback_name_strings[i], ctx2.callback_name_strings[i]), + "Got '%s' and '%s'\n", ctx.callback_name_strings[i], ctx2.callback_name_strings[i]); + } + } + + /* Try altering the contents of the enumeration strings. */ + for (i = 0; i < ctx2.count; i++) + { + strcpy(ctx2.callback_description_ptrs[i], "Fake Description"); + strcpy(ctx2.callback_name_ptrs[i], "Fake Device"); + } + + ctx2.count = 0; + hr = IDirect3D3_EnumDevices(d3d3, enumDevicesLifetimeTest, &ctx2); + ok(hr == D3D_OK, "IDirect3D3_EnumDevices returned 0x%08x\n", hr); + + /* The original contents of the enumeration strings are restored. */ + ok(ctx.count == ctx2.count, "Enumerated %u and %u devices\n", ctx.count, ctx2.count); + if (ctx.count == ctx2.count) + { + for (i = 0; i < ctx.count; i++) + { + ok(ctx.callback_description_ptrs[i] == ctx2.callback_description_ptrs[i], + "Unequal description pointers %p and %p\n", ctx.callback_description_ptrs[i], ctx2.callback_description_ptrs[i]); + ok(strcmp(ctx.callback_description_strings[i], ctx2.callback_description_strings[i]) != 0, + "Got '%s' and '%s'\n", ctx.callback_description_strings[i], ctx2.callback_description_strings[i]); + ok(ctx.callback_name_ptrs[i] == ctx2.callback_name_ptrs[i], + "Unequal name pointers %p and %p\n", ctx.callback_name_ptrs[i], ctx2.callback_name_ptrs[i]); + ok(strcmp(ctx.callback_name_strings[i], ctx2.callback_name_strings[i]) == 0, + "Got '%s' and '%s'\n", ctx.callback_name_strings[i], ctx2.callback_name_strings[i]); + } + } + + IDirect3D3_Release(d3d3); +} + START_TEST(ddraw4) { DDDEVICEIDENTIFIER identifier; @@ -16130,4 +16412,6 @@ START_TEST(ddraw4) test_gdi_surface(); test_alphatest(); test_clipper_refcount(); + test_enum_devices(); + test_enum_devices_life_time(); } -- 2.19.1