From: David Adam Subject: patch [3/5] ddraw: Port Enumdevices to ddraw2 Message-Id: Date: Tue, 2 Apr 2019 20:39:24 -1000

From 63e8f3e11f2698f621bf857503df399f54bc736a Mon Sep 17 00:00:00 2001 From: David Adam Date: Tue, 2 Apr 2019 20:25:21 -1000 Subject: [PATCH] Port Enumdevices tests to ddraw2 Signed-off-by: David Adam --- dlls/ddraw/tests/ddraw2.c | 283 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 283 insertions(+) diff --git a/dlls/ddraw/tests/ddraw2.c b/dlls/ddraw/tests/ddraw2.c index d056949326..53efd8174a 100644 --- a/dlls/ddraw/tests/ddraw2.c +++ b/dlls/ddraw/tests/ddraw2.c @@ -13750,6 +13750,287 @@ 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 2 hal line caps has D3DPTEXTURECAPS_POW2 flag set\n"); + ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0, + "RGB Device 2 hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n"); + ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2, + "RGB Device 2 hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n"); + ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2, + "RGB Device 2 hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n"); + + ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0, + "RGB Device 2 hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n"); + ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0, + "RGB Device 2 hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n"); + ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE, + "RGB Device 2 hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n"); + ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE, + "RGB Device 2 hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n"); + + ok(hal->dcmColorModel == 0, "RGB Device 2 hal caps has colormodel %u\n", hal->dcmColorModel); + ok(hel->dcmColorModel == D3DCOLOR_RGB, "RGB Device 2 hel caps has colormodel %u\n", hel->dcmColorModel); + + ok(hal->dwFlags == 0, "RGB Device 2 hal caps has hardware flags %x\n", hal->dwFlags); + ok(hel->dwFlags != 0, "RGB Device 2 hel caps has hardware flags %x\n", hel->dwFlags); + } + else if(IsEqualGUID(&IID_IDirect3DHALDevice, Guid)) + { + trace("HAL Device 2\n"); + ok(hal->dcmColorModel == D3DCOLOR_RGB, "HAL Device 2 hal caps has colormodel %u\n", hel->dcmColorModel); + ok(hel->dcmColorModel == 0, "HAL Device 2 hel caps has colormodel %u\n", hel->dcmColorModel); + + ok(hal->dwFlags != 0, "HAL Device 2 hal caps has hardware flags %x\n", hal->dwFlags); + ok(hel->dwFlags != 0, "HAL Device 2 hel caps has hardware flags %x\n", hel->dwFlags); + } + else if(IsEqualGUID(&IID_IDirect3DRefDevice, Guid)) + { + ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0, + "REF Device 2 hal line caps has D3DPTEXTURECAPS_POW2 flag set\n"); + ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0, + "REF Device 2 hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n"); + ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2, + "REF Device 2 hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n"); + ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2, + "REF Device 2 hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n"); + + ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0, + "REF Device 2 hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n"); + ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0, + "REF Device 2 hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n"); + ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE, + "REF Device 2 hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n"); + ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE, + "REF Device 2 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 2 hal line caps has D3DPTEXTURECAPS_POW2 flag set\n"); + ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0, + "Ramp Device 2 hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n"); + ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2, + "Ramp Device 2 hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n"); + ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2, + "Ramp Device 2 hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n"); + + ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0, + "Ramp Device 2 hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n"); + ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0, + "Ramp Device 2 hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n"); + ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE, + "Ramp Device 2 hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n"); + ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE, + "Ramp Device 2 hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n"); + + ok(hal->dcmColorModel == 0, "Ramp Device 2 hal caps has colormodel %u\n", hal->dcmColorModel); + ok(hel->dcmColorModel == D3DCOLOR_MONO, "Ramp Device 2 hel caps has colormodel %u\n", + hel->dcmColorModel); + + ok(hal->dwFlags == 0, "Ramp Device 2 hal caps has hardware flags %x\n", hal->dwFlags); + ok(hel->dwFlags != 0, "Ramp Device 2 hel caps has hardware flags %x\n", hel->dwFlags); + } + else if(IsEqualGUID(&IID_IDirect3DMMXDevice, Guid)) + { + ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0, + "MMX Device 2 hal line caps has D3DPTEXTURECAPS_POW2 flag set\n"); + ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2) == 0, + "MMX Device 2 hal tri caps has D3DPTEXTURECAPS_POW2 flag set\n"); + ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2, + "MMX Device 2 hel line caps does not have D3DPTEXTURECAPS_POW2 flag set\n"); + ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2, + "MMX Device 2 hel tri caps does not have D3DPTEXTURECAPS_POW2 flag set\n"); + + ok((hal->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0, + "MMX Device 2 hal line caps has D3DPTEXTURECAPS_PERSPECTIVE set\n"); + ok((hal->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) == 0, + "MMX Device 2 hal tri caps has D3DPTEXTURECAPS_PERSPECTIVE set\n"); + ok(hel->dpcLineCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE, + "MMX Device 2 hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n"); + ok(hel->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE, + "MMX Device 2 hel tri caps does not have D3DPTEXTURECAPS_PERSPECTIVE set\n"); + + ok(hal->dcmColorModel == 0, "MMX Device 2 hal caps has colormodel %u\n", hal->dcmColorModel); + ok(hel->dcmColorModel == D3DCOLOR_RGB, "MMX Device 2 hel caps has colormodel %u\n", hel->dcmColorModel); + + ok(hal->dwFlags == 0, "MMX Device 2 hal caps has hardware flags %x\n", hal->dwFlags); + ok(hel->dwFlags != 0, "MMX Device 2 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) +{ + IDirectDraw2 *ddraw; + IDirect3D2 *d3d2; + HRESULT hr; + + if (!(ddraw = create_ddraw())) + return; + + hr = IDirectDraw_QueryInterface(ddraw, &IID_IDirect3D2, (void **)&d3d2); + IDirectDraw_Release(ddraw); + if (FAILED(hr)) + { + return; + } + + hr = IDirect3D2_EnumDevices(d3d2, NULL, NULL); + ok(hr == DDERR_INVALIDPARAMS, "IDirect3D2_EnumDevices returned 0x%08x\n", hr); + + hr = IDirect3D2_EnumDevices(d3d2, enumDevicesCallback, NULL); + ok(hr == D3D_OK, "IDirect3D2_EnumDevices returned 0x%08x\n", hr); + + IDirect3D2_Release(d3d2); +} + +typedef struct { + HRESULT desired_ret; + int total; +} D3D2ECancelTest; + +#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]; +} D3D2ELifetimeTest; + +static HRESULT WINAPI enumDevicesCancelTest(GUID *guid, char *DeviceDescription, char *DeviceName, + D3DDEVICEDESC *lpdd1, D3DDEVICEDESC *lpdd2, void *Context) +{ + D3D2ECancelTest *d3d2et = Context; + + d3d2et->total++; + + return d3d2et->desired_ret; +} + +static HRESULT WINAPI enumDevicesLifetimeTest(GUID *guid, char *DeviceDescription, char *DeviceName, + D3DDEVICEDESC *lpdd1, D3DDEVICEDESC *lpdd2, void *Context) +{ + D3D2ELifetimeTest *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) +{ + IDirectDraw2 *ddraw; + IDirect3D2 *d3d2; + HRESULT hr; + D3D2ELifetimeTest ctx, ctx2; + unsigned int i; + + if (!(ddraw = create_ddraw())) + return; + + hr = IDirectDraw_QueryInterface(ddraw, &IID_IDirect3D2, (void **)&d3d2); + IDirectDraw_Release(ddraw); + if (FAILED(hr)) + { + return; + } + + ctx.count = 0; + hr = IDirect3D2_EnumDevices(d3d2, enumDevicesLifetimeTest, &ctx); + ok(hr == D3D_OK, "IDirect3D2_EnumDevices returned 0x%08x\n", hr); + + /* The enumeration strings remain valid even after IDirect3D2_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 = IDirect3D2_EnumDevices(d3d2, enumDevicesLifetimeTest, &ctx2); + ok(hr == D3D_OK, "IDirect3D2_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 = IDirect3D2_EnumDevices(d3d2, enumDevicesLifetimeTest, &ctx2); + ok(hr == D3D_OK, "IDirect3D2_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]); + } + } + + IDirect3D2_Release(d3d2); +} START_TEST(ddraw2) { @@ -13868,4 +14149,6 @@ START_TEST(ddraw2) test_gdi_surface(); test_alphatest(); test_clipper_refcount(); + test_enum_devices(); + test_enum_devices_life_time(); } -- 2.19.1