ddraw/tests: Rewrite FindDevice().

Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Henri Verbeet 2018-09-11 18:39:25 +04:30 committed by Alexandre Julliard
parent 453e47d910
commit 8a66164f89
4 changed files with 316 additions and 138 deletions

View File

@ -1612,143 +1612,6 @@ static void VertexBufferLockRest(void)
IDirect3DVertexBuffer7_Release(buffer);
}
static void FindDevice(void)
{
static const struct
{
const GUID *guid;
BOOL todo;
} deviceGUIDs[] =
{
{&IID_IDirect3DRampDevice, TRUE},
{&IID_IDirect3DRGBDevice, FALSE},
};
static const GUID *nonexistent_deviceGUIDs[] = {&IID_IDirect3DMMXDevice,
&IID_IDirect3DRefDevice,
&IID_IDirect3DTnLHalDevice,
&IID_IDirect3DNullDevice};
D3DFINDDEVICESEARCH search = {0};
D3DFINDDEVICERESULT result = {0};
IDirect3DDevice *d3dhal;
HRESULT hr;
int i;
/* Test invalid parameters. */
hr = IDirect3D_FindDevice(Direct3D1, NULL, NULL);
ok(hr == DDERR_INVALIDPARAMS,
"Expected IDirect3D1::FindDevice to return DDERR_INVALIDPARAMS, got 0x%08x\n", hr);
hr = IDirect3D_FindDevice(Direct3D1, NULL, &result);
ok(hr == DDERR_INVALIDPARAMS,
"Expected IDirect3D1::FindDevice to return DDERR_INVALIDPARAMS, got 0x%08x\n", hr);
hr = IDirect3D_FindDevice(Direct3D1, &search, NULL);
ok(hr == DDERR_INVALIDPARAMS,
"Expected IDirect3D1::FindDevice to return DDERR_INVALIDPARAMS, got 0x%08x\n", hr);
search.dwSize = 0;
result.dwSize = 0;
hr = IDirect3D_FindDevice(Direct3D1, &search, &result);
ok(hr == DDERR_INVALIDPARAMS,
"Expected IDirect3D1::FindDevice to return DDERR_INVALIDPARAMS, got 0x%08x\n", hr);
search.dwSize = sizeof(search) + 1;
result.dwSize = sizeof(result) + 1;
hr = IDirect3D_FindDevice(Direct3D1, &search, &result);
ok(hr == DDERR_INVALIDPARAMS,
"Expected IDirect3D1::FindDevice to return DDERR_INVALIDPARAMS, got 0x%08x\n", hr);
/* Specifying no flags is permitted. */
search.dwSize = sizeof(search);
search.dwFlags = 0;
result.dwSize = sizeof(result);
hr = IDirect3D_FindDevice(Direct3D1, &search, &result);
ok(hr == D3D_OK,
"Expected IDirect3D1::FindDevice to return D3D_OK, got 0x%08x\n", hr);
/* Try an arbitrary non-device GUID. */
search.dwSize = sizeof(search);
search.dwFlags = D3DFDS_GUID;
search.guid = IID_IDirect3D;
result.dwSize = sizeof(result);
hr = IDirect3D_FindDevice(Direct3D1, &search, &result);
ok(hr == DDERR_NOTFOUND,
"Expected IDirect3D1::FindDevice to return DDERR_NOTFOUND, got 0x%08x\n", hr);
/* These GUIDs appear to be never present. */
for (i = 0; i < sizeof(nonexistent_deviceGUIDs)/sizeof(nonexistent_deviceGUIDs[0]); i++)
{
search.dwSize = sizeof(search);
search.dwFlags = D3DFDS_GUID;
search.guid = *nonexistent_deviceGUIDs[i];
result.dwSize = sizeof(result);
hr = IDirect3D_FindDevice(Direct3D1, &search, &result);
ok(hr == DDERR_NOTFOUND,
"[%d] Expected IDirect3D1::FindDevice to return DDERR_NOTFOUND, got 0x%08x\n", i, hr);
}
/* The HAL device can only be enumerated if hardware acceleration is present. */
search.dwSize = sizeof(search);
search.dwFlags = D3DFDS_GUID;
search.guid = IID_IDirect3DHALDevice;
result.dwSize = sizeof(result);
hr = IDirect3D_FindDevice(Direct3D1, &search, &result);
trace("IDirect3D::FindDevice returned 0x%08x for the HAL device GUID\n", hr);
if (SUCCEEDED(hr))
{
hr = IDirectDrawSurface_QueryInterface(Surface1, &IID_IDirect3DHALDevice, (void **)&d3dhal);
/* Currently Wine only supports the creation of one Direct3D device
* for a given DirectDraw instance. */
ok(SUCCEEDED(hr) || broken(hr == DDERR_INVALIDPIXELFORMAT) /* XP/Win2003 Wow64 on VMware */,
"Expected IDirectDrawSurface::QueryInterface to succeed, got 0x%08x\n", hr);
if (SUCCEEDED(hr))
IDirect3DDevice_Release(d3dhal);
}
else
{
hr = IDirectDrawSurface_QueryInterface(Surface1, &IID_IDirect3DHALDevice, (void **)&d3dhal);
ok(FAILED(hr), "Expected IDirectDrawSurface::QueryInterface to fail, got 0x%08x\n", hr);
if (SUCCEEDED(hr))
IDirect3DDevice_Release(d3dhal);
}
/* These GUIDs appear to be always present. */
for (i = 0; i < sizeof(deviceGUIDs)/sizeof(deviceGUIDs[0]); i++)
{
search.dwSize = sizeof(search);
search.dwFlags = D3DFDS_GUID;
search.guid = *deviceGUIDs[i].guid;
result.dwSize = sizeof(result);
hr = IDirect3D_FindDevice(Direct3D1, &search, &result);
todo_wine_if (deviceGUIDs[i].todo)
ok(hr == D3D_OK,
"[%d] Expected IDirect3D1::FindDevice to return D3D_OK, got 0x%08x\n", i, hr);
}
/* Curiously the color model criteria seem to be ignored. */
search.dwSize = sizeof(search);
search.dwFlags = D3DFDS_COLORMODEL;
search.dcmColorModel = 0xdeadbeef;
result.dwSize = sizeof(result);
hr = IDirect3D_FindDevice(Direct3D1, &search, &result);
todo_wine
ok(hr == D3D_OK,
"Expected IDirect3D1::FindDevice to return D3D_OK, got 0x%08x\n", hr);
}
static void BackBuffer3DCreateSurfaceTest(void)
{
DDSURFACEDESC ddsd;
@ -2390,7 +2253,6 @@ START_TEST(d3d)
Direct3D1Test();
TextureLoadTest();
ViewportTest();
FindDevice();
BackBuffer3DCreateSurfaceTest();
BackBuffer3DAttachmentTest();
test_get_caps1();

View File

@ -11713,6 +11713,111 @@ static void test_viewport(void)
DestroyWindow(window);
}
static void test_find_device(void)
{
D3DFINDDEVICESEARCH search = {0};
D3DFINDDEVICERESULT result = {0};
IDirect3DDevice *device;
IDirectDraw *ddraw;
IDirect3D *d3d;
unsigned int i;
HWND window;
HRESULT hr;
static const struct
{
const GUID *guid;
HRESULT hr;
BOOL todo;
}
tests[] =
{
{&IID_IDirect3D, DDERR_NOTFOUND},
{&IID_IDirect3DRampDevice, D3D_OK, TRUE},
{&IID_IDirect3DRGBDevice, D3D_OK},
{&IID_IDirect3DMMXDevice, DDERR_NOTFOUND},
{&IID_IDirect3DRefDevice, DDERR_NOTFOUND},
{&IID_IDirect3DTnLHalDevice, DDERR_NOTFOUND},
{&IID_IDirect3DNullDevice, DDERR_NOTFOUND},
};
ddraw = create_ddraw();
ok(!!ddraw, "Failed to create a ddraw object.\n");
if (FAILED(IDirectDraw_QueryInterface(ddraw, &IID_IDirect3D, (void **)&d3d)))
{
skip("D3D interface is not available, skipping test.\n");
IDirectDraw_Release(ddraw);
return;
}
result.dwSize = sizeof(result);
search.dwSize = sizeof(search);
hr = IDirect3D_FindDevice(d3d, NULL, NULL);
ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
hr = IDirect3D_FindDevice(d3d, NULL, &result);
ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
hr = IDirect3D_FindDevice(d3d, &search, NULL);
ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
hr = IDirect3D_FindDevice(d3d, &search, &result);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
ok(result.dwSize == sizeof(result), "Got unexpected result size %u.\n", result.dwSize);
memset(&search, 0, sizeof(search));
memset(&result, 0, sizeof(result));
hr = IDirect3D_FindDevice(d3d, &search, &result);
ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
search.dwSize = sizeof(search) + 1;
result.dwSize = sizeof(result) + 1;
hr = IDirect3D_FindDevice(d3d, &search, &result);
ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
for (i = 0; i < ARRAY_SIZE(tests); ++i)
{
memset(&search, 0, sizeof(search));
search.dwSize = sizeof(search);
search.dwFlags = D3DFDS_GUID;
search.guid = *tests[i].guid;
memset(&result, 0, sizeof(result));
result.dwSize = sizeof(result);
hr = IDirect3D_FindDevice(d3d, &search, &result);
todo_wine_if(tests[i].todo)
ok(hr == tests[i].hr, "Test %u: Got unexpected hr %#x.\n", i, hr);
ok(result.dwSize == sizeof(result), "Test %u: Got unexpected result size %u.\n", i, result.dwSize);
}
/* The HAL device can only be enumerated if hardware acceleration is present. */
search.dwSize = sizeof(search);
search.dwFlags = D3DFDS_GUID;
search.guid = IID_IDirect3DHALDevice;
result.dwSize = sizeof(result);
hr = IDirect3D_FindDevice(d3d, &search, &result);
window = create_window();
device = create_device(ddraw, window, DDSCL_NORMAL);
if (hr == D3D_OK)
ok(!!device, "Failed to create a 3D device.\n");
else
ok(!device, "Succeeded to create a 3D device.\n");
if (device)
IDirect3DDevice_Release(device);
DestroyWindow(window);
/* Curiously the colour model criteria seem to be ignored. */
search.dwSize = sizeof(search);
search.dwFlags = D3DFDS_COLORMODEL;
search.dcmColorModel = 0xdeadbeef;
result.dwSize = sizeof(result);
hr = IDirect3D_FindDevice(d3d, &search, &result);
todo_wine ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
IDirect3D_Release(d3d);
IDirectDraw_Release(ddraw);
}
START_TEST(ddraw1)
{
DDDEVICEIDENTIFIER identifier;
@ -11817,4 +11922,5 @@ START_TEST(ddraw1)
test_enum_surfaces();
test_execute_data();
test_viewport();
test_find_device();
}

View File

@ -12995,6 +12995,111 @@ static void test_viewport(void)
DestroyWindow(window);
}
static void test_find_device(void)
{
D3DFINDDEVICESEARCH search = {0};
D3DFINDDEVICERESULT result = {0};
IDirect3DDevice2 *device;
IDirectDraw2 *ddraw;
IDirect3D2 *d3d;
unsigned int i;
HWND window;
HRESULT hr;
static const struct
{
const GUID *guid;
HRESULT hr;
BOOL todo;
}
tests[] =
{
{&IID_IDirect3D, DDERR_NOTFOUND},
{&IID_IDirect3DRampDevice, D3D_OK, TRUE},
{&IID_IDirect3DRGBDevice, D3D_OK},
{&IID_IDirect3DMMXDevice, D3D_OK, TRUE},
{&IID_IDirect3DRefDevice, DDERR_NOTFOUND},
{&IID_IDirect3DTnLHalDevice, DDERR_NOTFOUND},
{&IID_IDirect3DNullDevice, DDERR_NOTFOUND},
};
ddraw = create_ddraw();
ok(!!ddraw, "Failed to create a ddraw object.\n");
if (FAILED(IDirectDraw2_QueryInterface(ddraw, &IID_IDirect3D2, (void **)&d3d)))
{
skip("D3D interface is not available, skipping test.\n");
IDirectDraw2_Release(ddraw);
return;
}
result.dwSize = sizeof(result);
search.dwSize = sizeof(search);
hr = IDirect3D2_FindDevice(d3d, NULL, NULL);
ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
hr = IDirect3D2_FindDevice(d3d, NULL, &result);
ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
hr = IDirect3D2_FindDevice(d3d, &search, NULL);
ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
hr = IDirect3D2_FindDevice(d3d, &search, &result);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
ok(result.dwSize == sizeof(result), "Got unexpected result size %u.\n", result.dwSize);
memset(&search, 0, sizeof(search));
memset(&result, 0, sizeof(result));
hr = IDirect3D2_FindDevice(d3d, &search, &result);
ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
search.dwSize = sizeof(search) + 1;
result.dwSize = sizeof(result) + 1;
hr = IDirect3D2_FindDevice(d3d, &search, &result);
ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
for (i = 0; i < ARRAY_SIZE(tests); ++i)
{
memset(&search, 0, sizeof(search));
search.dwSize = sizeof(search);
search.dwFlags = D3DFDS_GUID;
search.guid = *tests[i].guid;
memset(&result, 0, sizeof(result));
result.dwSize = sizeof(result);
hr = IDirect3D2_FindDevice(d3d, &search, &result);
todo_wine_if(tests[i].todo)
ok(hr == tests[i].hr, "Test %u: Got unexpected hr %#x.\n", i, hr);
ok(result.dwSize == sizeof(result), "Test %u: Got unexpected result size %u.\n", i, result.dwSize);
}
/* The HAL device can only be enumerated if hardware acceleration is present. */
search.dwSize = sizeof(search);
search.dwFlags = D3DFDS_GUID;
search.guid = IID_IDirect3DHALDevice;
result.dwSize = sizeof(result);
hr = IDirect3D2_FindDevice(d3d, &search, &result);
window = create_window();
device = create_device(ddraw, window, DDSCL_NORMAL);
if (hr == D3D_OK)
ok(!!device, "Failed to create a 3D device.\n");
else
ok(!device, "Succeeded to create a 3D device.\n");
if (device)
IDirect3DDevice2_Release(device);
DestroyWindow(window);
/* Curiously the colour model criteria seem to be ignored. */
search.dwSize = sizeof(search);
search.dwFlags = D3DFDS_COLORMODEL;
search.dcmColorModel = 0xdeadbeef;
result.dwSize = sizeof(result);
hr = IDirect3D2_FindDevice(d3d, &search, &result);
todo_wine ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
IDirect3D2_Release(d3d);
IDirectDraw2_Release(ddraw);
}
START_TEST(ddraw2)
{
DDDEVICEIDENTIFIER identifier;
@ -13107,4 +13212,5 @@ START_TEST(ddraw2)
test_clear();
test_enum_surfaces();
test_viewport();
test_find_device();
}

View File

@ -15089,6 +15089,109 @@ static void test_viewport(void)
DestroyWindow(window);
}
static void test_find_device(void)
{
D3DFINDDEVICESEARCH search = {0};
D3DFINDDEVICERESULT result = {0};
IDirect3DDevice3 *device;
IDirectDraw4 *ddraw;
IDirect3D3 *d3d;
unsigned int i;
HWND window;
HRESULT hr;
static const struct
{
const GUID *guid;
HRESULT hr;
}
tests[] =
{
{&IID_IDirect3D, DDERR_NOTFOUND},
{&IID_IDirect3DRampDevice, DDERR_NOTFOUND},
{&IID_IDirect3DRGBDevice, D3D_OK},
{&IID_IDirect3DMMXDevice, DDERR_NOTFOUND},
{&IID_IDirect3DRefDevice, DDERR_NOTFOUND},
{&IID_IDirect3DTnLHalDevice, DDERR_NOTFOUND},
{&IID_IDirect3DNullDevice, DDERR_NOTFOUND},
};
ddraw = create_ddraw();
ok(!!ddraw, "Failed to create a ddraw object.\n");
if (FAILED(IDirectDraw4_QueryInterface(ddraw, &IID_IDirect3D3, (void **)&d3d)))
{
skip("D3D interface is not available, skipping test.\n");
IDirectDraw4_Release(ddraw);
return;
}
result.dwSize = sizeof(result);
search.dwSize = sizeof(search);
hr = IDirect3D3_FindDevice(d3d, NULL, NULL);
ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
hr = IDirect3D3_FindDevice(d3d, NULL, &result);
ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
hr = IDirect3D3_FindDevice(d3d, &search, NULL);
ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
hr = IDirect3D3_FindDevice(d3d, &search, &result);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
ok(result.dwSize == sizeof(result), "Got unexpected result size %u.\n", result.dwSize);
memset(&search, 0, sizeof(search));
memset(&result, 0, sizeof(result));
hr = IDirect3D3_FindDevice(d3d, &search, &result);
ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
search.dwSize = sizeof(search) + 1;
result.dwSize = sizeof(result) + 1;
hr = IDirect3D3_FindDevice(d3d, &search, &result);
ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
for (i = 0; i < ARRAY_SIZE(tests); ++i)
{
memset(&search, 0, sizeof(search));
search.dwSize = sizeof(search);
search.dwFlags = D3DFDS_GUID;
search.guid = *tests[i].guid;
memset(&result, 0, sizeof(result));
result.dwSize = sizeof(result);
hr = IDirect3D3_FindDevice(d3d, &search, &result);
ok(hr == tests[i].hr, "Test %u: Got unexpected hr %#x.\n", i, hr);
ok(result.dwSize == sizeof(result), "Test %u: Got unexpected result size %u.\n", i, result.dwSize);
}
/* The HAL device can only be enumerated if hardware acceleration is present. */
search.dwSize = sizeof(search);
search.dwFlags = D3DFDS_GUID;
search.guid = IID_IDirect3DHALDevice;
result.dwSize = sizeof(result);
hr = IDirect3D3_FindDevice(d3d, &search, &result);
window = create_window();
device = create_device(window, DDSCL_NORMAL);
if (hr == D3D_OK)
ok(!!device, "Failed to create a 3D device.\n");
else
ok(!device, "Succeeded to create a 3D device.\n");
if (device)
IDirect3DDevice3_Release(device);
DestroyWindow(window);
/* Curiously the colour model criteria seem to be ignored. */
search.dwSize = sizeof(search);
search.dwFlags = D3DFDS_COLORMODEL;
search.dcmColorModel = 0xdeadbeef;
result.dwSize = sizeof(result);
hr = IDirect3D3_FindDevice(d3d, &search, &result);
todo_wine ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
IDirect3D3_Release(d3d);
IDirectDraw4_Release(ddraw);
}
START_TEST(ddraw4)
{
DDDEVICEIDENTIFIER identifier;
@ -15215,4 +15318,5 @@ START_TEST(ddraw4)
test_clear();
test_enum_surfaces();
test_viewport();
test_find_device();
}