Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/ddraw/tests/ddraw1.c | 153 ++++++++++++++++++++++++++++++++++- dlls/ddraw/tests/ddraw2.c | 153 ++++++++++++++++++++++++++++++++++- dlls/ddraw/tests/ddraw4.c | 163 +++++++++++++++++++++++++++++++++++-- dlls/ddraw/tests/ddraw7.c | 164 ++++++++++++++++++++++++++++++++++++-- 4 files changed, 620 insertions(+), 13 deletions(-)
diff --git a/dlls/ddraw/tests/ddraw1.c b/dlls/ddraw/tests/ddraw1.c index 4e27ecfb796..34ebfab1b7b 100644 --- a/dlls/ddraw/tests/ddraw1.c +++ b/dlls/ddraw/tests/ddraw1.c @@ -12091,9 +12091,27 @@ static void test_clear(void) DestroyWindow(window); }
+struct display_mode_list +{ + DDSURFACEDESC modes[20]; + unsigned int count; +}; + +static HRESULT CALLBACK build_mode_list_cb(DDSURFACEDESC *desc, void *context) +{ + struct display_mode_list *modes = context; + + if (modes->count < ARRAY_SIZE(modes->modes)) + modes->modes[modes->count] = *desc; + ++modes->count; + + return DDENUMRET_OK; +} + struct enum_surfaces_param { IDirectDrawSurface *surfaces[8]; + struct display_mode_list modes; unsigned int count; };
@@ -12119,9 +12137,31 @@ static HRESULT WINAPI enum_surfaces_cb(IDirectDrawSurface *surface, DDSURFACEDES return DDENUMRET_OK; }
+static HRESULT WINAPI enum_surfaces_create_cb(IDirectDrawSurface *surface, DDSURFACEDESC *desc, void *context) +{ + static const DWORD expect_flags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH | DDSD_PIXELFORMAT; + struct enum_surfaces_param *param = context; + + ok(!surface, "Unexpected surface %p.\n", surface); + ok((desc->dwFlags & expect_flags) == expect_flags, "Got unexpected flags %#x.\n", desc->dwFlags); + if (param->count < ARRAY_SIZE(param->modes.modes)) + { + const DDSURFACEDESC *expect = ¶m->modes.modes[param->count]; + ok(desc->dwWidth == expect->dwWidth, "Expected width %u, got %u.\n", expect->dwWidth, desc->dwWidth); + ok(desc->dwHeight == expect->dwHeight, "Expected height %u, got %u.\n", expect->dwHeight, desc->dwHeight); + ok(!memcmp(&desc->ddpfPixelFormat, &expect->ddpfPixelFormat, sizeof(desc->ddpfPixelFormat)), + "Pixel formats didn't match.\n"); + } + + ++param->count; + + return DDENUMRET_OK; +} + static void test_enum_surfaces(void) { struct enum_surfaces_param param = {{0}}; + DDPIXELFORMAT current_format; IDirectDraw *ddraw; DDSURFACEDESC desc; HRESULT hr; @@ -12129,8 +12169,21 @@ static void test_enum_surfaces(void) ddraw = create_ddraw(); ok(!!ddraw, "Failed to create a ddraw object.\n");
+ memset(&desc, 0, sizeof(desc)); + desc.dwSize = sizeof(desc); + hr = IDirectDraw_GetDisplayMode(ddraw, &desc); + ok(hr == DD_OK, "Failed to get display mode, hr %#x.\n", hr); + current_format = desc.ddpfPixelFormat; + hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL); - ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr); + ok(hr == DD_OK, "Failed to set cooperative level, hr %#x.\n", hr); + + hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL, NULL, NULL, enum_surfaces_cb); + todo_wine ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr); + + hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_ALL, + NULL, NULL, enum_surfaces_cb); + todo_wine ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
memset(&desc, 0, sizeof(desc)); desc.dwSize = sizeof(desc); @@ -12150,6 +12203,7 @@ static void test_enum_surfaces(void) ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr); ok(!param.surfaces[3], "Got unexpected pointer %p.\n", param.surfaces[3]);
+ param.count = 0; hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, &desc, ¶m, enum_surfaces_cb); ok(SUCCEEDED(hr), "Failed to enumerate surfaces, hr %#x.\n", hr); @@ -12161,9 +12215,106 @@ static void test_enum_surfaces(void) ok(SUCCEEDED(hr), "Failed to enumerate surfaces, hr %#x.\n", hr); ok(param.count == 3, "Got unexpected number of enumerated surfaces %u.\n", param.count);
+ desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT; + param.count = 0; + hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_MATCH, + &desc, ¶m, enum_surfaces_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + ok(param.count == 1, "Got unexpected number of enumerated surfaces %u.\n", param.count); + + param.count = 0; + hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_NOMATCH, + &desc, ¶m, enum_surfaces_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + todo_wine ok(param.count == 2, "Got unexpected number of enumerated surfaces %u.\n", param.count); + + desc.dwFlags = 0; + param.count = 0; + hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_MATCH, + &desc, ¶m, enum_surfaces_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + ok(param.count == 3, "Got unexpected number of enumerated surfaces %u.\n", param.count); + + desc.dwFlags = 0; + param.count = 0; + hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST, &desc, ¶m, enum_surfaces_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + ok(param.count == 3, "Got unexpected number of enumerated surfaces %u.\n", param.count); + IDirectDrawSurface_Release(param.surfaces[2]); IDirectDrawSurface_Release(param.surfaces[1]); IDirectDrawSurface_Release(param.surfaces[0]); + + param.count = 0; + hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, + NULL, ¶m, enum_surfaces_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + ok(!param.count, "Got unexpected number of enumerated surfaces %u.\n", param.count); + + memset(&desc, 0, sizeof(desc)); + desc.dwSize = sizeof(desc); + desc.dwFlags = DDSD_CAPS; + desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE; + + hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_ALL, + &desc, ¶m, enum_surfaces_create_cb); + todo_wine ok(hr == DDERR_INVALIDPARAMS, "Failed to enumerate surfaces, hr %#x.\n", hr); + + hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_NOMATCH, + &desc, ¶m, enum_surfaces_create_cb); + todo_wine ok(hr == DDERR_INVALIDPARAMS, "Failed to enumerate surfaces, hr %#x.\n", hr); + + hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED, + &desc, ¶m, enum_surfaces_create_cb); + todo_wine ok(hr == DDERR_INVALIDPARAMS, "Failed to enumerate surfaces, hr %#x.\n", hr); + + /* When not passed width and height, the callback is called with every + * available display resolution. */ + + param.modes.count = 0; + desc.dwFlags |= DDSD_PIXELFORMAT; + U4(desc).ddpfPixelFormat = current_format; + hr = IDirectDraw_EnumDisplayModes(ddraw, 0, &desc, ¶m.modes, build_mode_list_cb); + ok(hr == DD_OK, "Failed to build mode list, hr %#x.\n", hr); + + param.count = 0; + desc.dwFlags &= ~DDSD_PIXELFORMAT; + hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_MATCH, + &desc, ¶m, enum_surfaces_create_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + todo_wine ok(param.count == param.modes.count, "Expected %u surfaces, got %u.\n", param.modes.count, param.count); + + desc.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT; + desc.dwWidth = desc.dwHeight = 32; + + param.modes.modes[0].dwWidth = param.modes.modes[0].dwHeight = 32; + + param.count = 0; + hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_MATCH, + &desc, ¶m, enum_surfaces_create_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + todo_wine ok(param.count == 1, "Got unexpected number of enumerated surfaces %u.\n", param.count); + + hr = IDirectDraw_CreateSurface(ddraw, &desc, ¶m.surfaces[0], NULL); + ok(hr == DD_OK, "Failed to create surface, hr %#x.\n", hr); + param.count = 0; + hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_MATCH, + &desc, ¶m, enum_surfaces_create_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + todo_wine ok(param.count == 1, "Got unexpected number of enumerated surfaces %u.\n", param.count); + IDirectDrawSurface_Release(param.surfaces[0]); + + desc.dwFlags |= DDSD_PIXELFORMAT; + desc.ddpfPixelFormat.dwSize = sizeof(desc.ddpfPixelFormat); + desc.ddpfPixelFormat.dwFlags = DDPF_FOURCC; + desc.ddpfPixelFormat.dwFourCC = 0xdeadbeef; + + param.count = 0; + hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_MATCH, + &desc, ¶m, enum_surfaces_create_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + ok(!param.count, "Got unexpected number of enumerated surfaces %u.\n", param.count); + IDirectDraw_Release(ddraw); }
diff --git a/dlls/ddraw/tests/ddraw2.c b/dlls/ddraw/tests/ddraw2.c index 7c25b2be557..90f7b77c839 100644 --- a/dlls/ddraw/tests/ddraw2.c +++ b/dlls/ddraw/tests/ddraw2.c @@ -13067,9 +13067,27 @@ static void test_clear(void) DestroyWindow(window); }
+struct display_mode_list +{ + DDSURFACEDESC modes[20]; + unsigned int count; +}; + +static HRESULT CALLBACK build_mode_list_cb(DDSURFACEDESC *desc, void *context) +{ + struct display_mode_list *modes = context; + + if (modes->count < ARRAY_SIZE(modes->modes)) + modes->modes[modes->count] = *desc; + ++modes->count; + + return DDENUMRET_OK; +} + struct enum_surfaces_param { IDirectDrawSurface *surfaces[8]; + struct display_mode_list modes; unsigned int count; };
@@ -13095,9 +13113,31 @@ static HRESULT WINAPI enum_surfaces_cb(IDirectDrawSurface *surface, DDSURFACEDES return DDENUMRET_OK; }
+static HRESULT WINAPI enum_surfaces_create_cb(IDirectDrawSurface *surface, DDSURFACEDESC *desc, void *context) +{ + static const DWORD expect_flags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH | DDSD_PIXELFORMAT; + struct enum_surfaces_param *param = context; + + ok(!surface, "Unexpected surface %p.\n", surface); + ok((desc->dwFlags & expect_flags) == expect_flags, "Got unexpected flags %#x.\n", desc->dwFlags); + if (param->count < ARRAY_SIZE(param->modes.modes)) + { + const DDSURFACEDESC *expect = ¶m->modes.modes[param->count]; + ok(desc->dwWidth == expect->dwWidth, "Expected width %u, got %u.\n", expect->dwWidth, desc->dwWidth); + ok(desc->dwHeight == expect->dwHeight, "Expected height %u, got %u.\n", expect->dwHeight, desc->dwHeight); + ok(!memcmp(&desc->ddpfPixelFormat, &expect->ddpfPixelFormat, sizeof(desc->ddpfPixelFormat)), + "Pixel formats didn't match.\n"); + } + + ++param->count; + + return DDENUMRET_OK; +} + static void test_enum_surfaces(void) { struct enum_surfaces_param param = {{0}}; + DDPIXELFORMAT current_format; IDirectDraw2 *ddraw; DDSURFACEDESC desc; HRESULT hr; @@ -13105,8 +13145,21 @@ static void test_enum_surfaces(void) ddraw = create_ddraw(); ok(!!ddraw, "Failed to create a ddraw object.\n");
+ memset(&desc, 0, sizeof(desc)); + desc.dwSize = sizeof(desc); + hr = IDirectDraw2_GetDisplayMode(ddraw, &desc); + ok(hr == DD_OK, "Failed to get display mode, hr %#x.\n", hr); + current_format = desc.ddpfPixelFormat; + hr = IDirectDraw2_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL); - ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr); + ok(hr == DD_OK, "Failed to set cooperative level, hr %#x.\n", hr); + + hr = IDirectDraw2_EnumSurfaces(ddraw, DDENUMSURFACES_ALL, NULL, NULL, enum_surfaces_cb); + todo_wine ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr); + + hr = IDirectDraw2_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_ALL, + NULL, NULL, enum_surfaces_cb); + todo_wine ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
memset(&desc, 0, sizeof(desc)); desc.dwSize = sizeof(desc); @@ -13126,6 +13179,7 @@ static void test_enum_surfaces(void) ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr); ok(!param.surfaces[3], "Got unexpected pointer %p.\n", param.surfaces[3]);
+ param.count = 0; hr = IDirectDraw2_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, &desc, ¶m, enum_surfaces_cb); ok(SUCCEEDED(hr), "Failed to enumerate surfaces, hr %#x.\n", hr); @@ -13137,9 +13191,106 @@ static void test_enum_surfaces(void) ok(SUCCEEDED(hr), "Failed to enumerate surfaces, hr %#x.\n", hr); ok(param.count == 3, "Got unexpected number of enumerated surfaces %u.\n", param.count);
+ desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT; + param.count = 0; + hr = IDirectDraw2_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_MATCH, + &desc, ¶m, enum_surfaces_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + ok(param.count == 1, "Got unexpected number of enumerated surfaces %u.\n", param.count); + + param.count = 0; + hr = IDirectDraw2_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_NOMATCH, + &desc, ¶m, enum_surfaces_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + todo_wine ok(param.count == 2, "Got unexpected number of enumerated surfaces %u.\n", param.count); + + desc.dwFlags = 0; + param.count = 0; + hr = IDirectDraw2_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_MATCH, + &desc, ¶m, enum_surfaces_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + ok(param.count == 3, "Got unexpected number of enumerated surfaces %u.\n", param.count); + + desc.dwFlags = 0; + param.count = 0; + hr = IDirectDraw2_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST, &desc, ¶m, enum_surfaces_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + ok(param.count == 3, "Got unexpected number of enumerated surfaces %u.\n", param.count); + IDirectDrawSurface_Release(param.surfaces[2]); IDirectDrawSurface_Release(param.surfaces[1]); IDirectDrawSurface_Release(param.surfaces[0]); + + param.count = 0; + hr = IDirectDraw2_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, + NULL, ¶m, enum_surfaces_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + ok(!param.count, "Got unexpected number of enumerated surfaces %u.\n", param.count); + + memset(&desc, 0, sizeof(desc)); + desc.dwSize = sizeof(desc); + desc.dwFlags = DDSD_CAPS; + desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE; + + hr = IDirectDraw2_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_ALL, + &desc, ¶m, enum_surfaces_create_cb); + todo_wine ok(hr == DDERR_INVALIDPARAMS, "Failed to enumerate surfaces, hr %#x.\n", hr); + + hr = IDirectDraw2_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_NOMATCH, + &desc, ¶m, enum_surfaces_create_cb); + todo_wine ok(hr == DDERR_INVALIDPARAMS, "Failed to enumerate surfaces, hr %#x.\n", hr); + + hr = IDirectDraw2_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED, + &desc, ¶m, enum_surfaces_create_cb); + todo_wine ok(hr == DDERR_INVALIDPARAMS, "Failed to enumerate surfaces, hr %#x.\n", hr); + + /* When not passed width and height, the callback is called with every + * available display resolution. */ + + param.modes.count = 0; + desc.dwFlags |= DDSD_PIXELFORMAT; + U4(desc).ddpfPixelFormat = current_format; + hr = IDirectDraw2_EnumDisplayModes(ddraw, 0, &desc, ¶m.modes, build_mode_list_cb); + ok(hr == DD_OK, "Failed to build mode list, hr %#x.\n", hr); + + param.count = 0; + desc.dwFlags &= ~DDSD_PIXELFORMAT; + hr = IDirectDraw2_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_MATCH, + &desc, ¶m, enum_surfaces_create_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + todo_wine ok(param.count == param.modes.count, "Expected %u surfaces, got %u.\n", param.modes.count, param.count); + + desc.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT; + desc.dwWidth = desc.dwHeight = 32; + + param.modes.modes[0].dwWidth = param.modes.modes[0].dwHeight = 32; + + param.count = 0; + hr = IDirectDraw2_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_MATCH, + &desc, ¶m, enum_surfaces_create_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + todo_wine ok(param.count == 1, "Got unexpected number of enumerated surfaces %u.\n", param.count); + + hr = IDirectDraw2_CreateSurface(ddraw, &desc, ¶m.surfaces[0], NULL); + ok(hr == DD_OK, "Failed to create surface, hr %#x.\n", hr); + param.count = 0; + hr = IDirectDraw2_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_MATCH, + &desc, ¶m, enum_surfaces_create_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + todo_wine ok(param.count == 1, "Got unexpected number of enumerated surfaces %u.\n", param.count); + IDirectDrawSurface2_Release(param.surfaces[0]); + + desc.dwFlags |= DDSD_PIXELFORMAT; + desc.ddpfPixelFormat.dwSize = sizeof(desc.ddpfPixelFormat); + desc.ddpfPixelFormat.dwFlags = DDPF_FOURCC; + desc.ddpfPixelFormat.dwFourCC = 0xdeadbeef; + + param.count = 0; + hr = IDirectDraw2_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_MATCH, + &desc, ¶m, enum_surfaces_create_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + ok(!param.count, "Got unexpected number of enumerated surfaces %u.\n", param.count); + IDirectDraw2_Release(ddraw); }
diff --git a/dlls/ddraw/tests/ddraw4.c b/dlls/ddraw/tests/ddraw4.c index c38c0b3ce5a..8012e10a19c 100644 --- a/dlls/ddraw/tests/ddraw4.c +++ b/dlls/ddraw/tests/ddraw4.c @@ -15655,9 +15655,27 @@ static void test_clear(void) DestroyWindow(window); }
+struct display_mode_list +{ + DDSURFACEDESC2 modes[20]; + unsigned int count; +}; + +static HRESULT CALLBACK build_mode_list_cb(DDSURFACEDESC2 *desc, void *context) +{ + struct display_mode_list *modes = context; + + if (modes->count < ARRAY_SIZE(modes->modes)) + modes->modes[modes->count] = *desc; + ++modes->count; + + return DDENUMRET_OK; +} + struct enum_surfaces_param { IDirectDrawSurface4 *surfaces[8]; + struct display_mode_list modes; unsigned int count; };
@@ -15683,9 +15701,31 @@ static HRESULT WINAPI enum_surfaces_cb(IDirectDrawSurface4 *surface, DDSURFACEDE return DDENUMRET_OK; }
+static HRESULT WINAPI enum_surfaces_create_cb(IDirectDrawSurface4 *surface, DDSURFACEDESC2 *desc, void *context) +{ + static const DWORD expect_flags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH | DDSD_PIXELFORMAT; + struct enum_surfaces_param *param = context; + + ok(!surface, "Unexpected surface %p.\n", surface); + ok((desc->dwFlags & expect_flags) == expect_flags, "Got unexpected flags %#x.\n", desc->dwFlags); + if (param->count < ARRAY_SIZE(param->modes.modes)) + { + const DDSURFACEDESC2 *expect = ¶m->modes.modes[param->count]; + ok(desc->dwWidth == expect->dwWidth, "Expected width %u, got %u.\n", expect->dwWidth, desc->dwWidth); + ok(desc->dwHeight == expect->dwHeight, "Expected height %u, got %u.\n", expect->dwHeight, desc->dwHeight); + ok(!memcmp(&U4(*desc).ddpfPixelFormat, &U4(*expect).ddpfPixelFormat, sizeof(U4(*desc).ddpfPixelFormat)), + "Pixel formats didn't match.\n"); + } + + ++param->count; + + return DDENUMRET_OK; +} + static void test_enum_surfaces(void) { struct enum_surfaces_param param = {{0}}; + DDPIXELFORMAT current_format; DDSURFACEDESC2 desc; IDirectDraw4 *ddraw; HRESULT hr; @@ -15693,8 +15733,21 @@ static void test_enum_surfaces(void) ddraw = create_ddraw(); ok(!!ddraw, "Failed to create a ddraw object.\n");
+ memset(&desc, 0, sizeof(desc)); + desc.dwSize = sizeof(desc); + hr = IDirectDraw4_GetDisplayMode(ddraw, &desc); + ok(hr == DD_OK, "Failed to get display mode, hr %#x.\n", hr); + current_format = U4(desc).ddpfPixelFormat; + hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL); - ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr); + ok(hr == DD_OK, "Failed to set cooperative level, hr %#x.\n", hr); + + hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_ALL, NULL, NULL, enum_surfaces_cb); + todo_wine ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr); + + hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_ALL, + NULL, NULL, enum_surfaces_cb); + todo_wine ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
memset(&desc, 0, sizeof(desc)); desc.dwSize = sizeof(desc); @@ -15704,30 +15757,128 @@ static void test_enum_surfaces(void) desc.dwWidth = 32; desc.dwHeight = 32; hr = IDirectDraw4_CreateSurface(ddraw, &desc, ¶m.surfaces[0], NULL); - ok(SUCCEEDED(hr), "Failed to create a surface, hr %#x.\n", hr); + ok(hr == DD_OK, "Failed to create a surface, hr %#x.\n", hr);
hr = IDirectDrawSurface4_GetAttachedSurface(param.surfaces[0], &desc.ddsCaps, ¶m.surfaces[1]); - ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr); + ok(hr == DD_OK, "Failed to get attached surface, hr %#x.\n", hr); hr = IDirectDrawSurface4_GetAttachedSurface(param.surfaces[1], &desc.ddsCaps, ¶m.surfaces[2]); - ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr); + ok(hr == DD_OK, "Failed to get attached surface, hr %#x.\n", hr); hr = IDirectDrawSurface4_GetAttachedSurface(param.surfaces[2], &desc.ddsCaps, ¶m.surfaces[3]); ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr); ok(!param.surfaces[3], "Got unexpected pointer %p.\n", param.surfaces[3]);
+ param.count = 0; hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, &desc, ¶m, enum_surfaces_cb); - ok(SUCCEEDED(hr), "Failed to enumerate surfaces, hr %#x.\n", hr); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); ok(param.count == 3, "Got unexpected number of enumerated surfaces %u.\n", param.count);
param.count = 0; hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, NULL, ¶m, enum_surfaces_cb); - ok(SUCCEEDED(hr), "Failed to enumerate surfaces, hr %#x.\n", hr); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + ok(param.count == 3, "Got unexpected number of enumerated surfaces %u.\n", param.count); + + desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT; + param.count = 0; + hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_MATCH, + &desc, ¶m, enum_surfaces_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + ok(param.count == 1, "Got unexpected number of enumerated surfaces %u.\n", param.count); + + param.count = 0; + hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_NOMATCH, + &desc, ¶m, enum_surfaces_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + todo_wine ok(param.count == 2, "Got unexpected number of enumerated surfaces %u.\n", param.count); + + desc.dwFlags = 0; + param.count = 0; + hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_MATCH, + &desc, ¶m, enum_surfaces_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + ok(param.count == 3, "Got unexpected number of enumerated surfaces %u.\n", param.count); + + desc.dwFlags = 0; + param.count = 0; + hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST, &desc, ¶m, enum_surfaces_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); ok(param.count == 3, "Got unexpected number of enumerated surfaces %u.\n", param.count);
IDirectDrawSurface4_Release(param.surfaces[2]); IDirectDrawSurface4_Release(param.surfaces[1]); IDirectDrawSurface4_Release(param.surfaces[0]); + + param.count = 0; + hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, + NULL, ¶m, enum_surfaces_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + ok(!param.count, "Got unexpected number of enumerated surfaces %u.\n", param.count); + + memset(&desc, 0, sizeof(desc)); + desc.dwSize = sizeof(desc); + desc.dwFlags = DDSD_CAPS; + desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE; + + hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_ALL, + &desc, ¶m, enum_surfaces_create_cb); + todo_wine ok(hr == DDERR_INVALIDPARAMS, "Failed to enumerate surfaces, hr %#x.\n", hr); + + hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_NOMATCH, + &desc, ¶m, enum_surfaces_create_cb); + todo_wine ok(hr == DDERR_INVALIDPARAMS, "Failed to enumerate surfaces, hr %#x.\n", hr); + + hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED, + &desc, ¶m, enum_surfaces_create_cb); + todo_wine ok(hr == DDERR_INVALIDPARAMS, "Failed to enumerate surfaces, hr %#x.\n", hr); + + /* When not passed width and height, the callback is called with every + * available display resolution. */ + + param.modes.count = 0; + desc.dwFlags |= DDSD_PIXELFORMAT; + U4(desc).ddpfPixelFormat = current_format; + hr = IDirectDraw4_EnumDisplayModes(ddraw, 0, &desc, ¶m.modes, build_mode_list_cb); + ok(hr == DD_OK, "Failed to build mode list, hr %#x.\n", hr); + + param.count = 0; + desc.dwFlags &= ~DDSD_PIXELFORMAT; + hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_MATCH, + &desc, ¶m, enum_surfaces_create_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + todo_wine ok(param.count == param.modes.count, "Expected %u surfaces, got %u.\n", param.modes.count, param.count); + + desc.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT; + desc.dwWidth = desc.dwHeight = 32; + + param.modes.modes[0].dwWidth = param.modes.modes[0].dwHeight = 32; + + param.count = 0; + hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_MATCH, + &desc, ¶m, enum_surfaces_create_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + todo_wine ok(param.count == 1, "Got unexpected number of enumerated surfaces %u.\n", param.count); + + hr = IDirectDraw4_CreateSurface(ddraw, &desc, ¶m.surfaces[0], NULL); + ok(hr == DD_OK, "Failed to create surface, hr %#x.\n", hr); + param.count = 0; + hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_MATCH, + &desc, ¶m, enum_surfaces_create_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + todo_wine ok(param.count == 1, "Got unexpected number of enumerated surfaces %u.\n", param.count); + IDirectDrawSurface4_Release(param.surfaces[0]); + + desc.dwFlags |= DDSD_PIXELFORMAT; + U4(desc).ddpfPixelFormat.dwSize = sizeof(U4(desc).ddpfPixelFormat); + U4(desc).ddpfPixelFormat.dwFlags = DDPF_FOURCC; + U4(desc).ddpfPixelFormat.dwFourCC = 0xdeadbeef; + + param.count = 0; + hr = IDirectDraw4_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_MATCH, + &desc, ¶m, enum_surfaces_create_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + ok(!param.count, "Got unexpected number of enumerated surfaces %u.\n", param.count); + IDirectDraw4_Release(ddraw); }
diff --git a/dlls/ddraw/tests/ddraw7.c b/dlls/ddraw/tests/ddraw7.c index d3ea36e9808..d94676ba5e6 100644 --- a/dlls/ddraw/tests/ddraw7.c +++ b/dlls/ddraw/tests/ddraw7.c @@ -15058,9 +15058,27 @@ static void test_clear(void) DestroyWindow(window); }
+struct display_mode_list +{ + DDSURFACEDESC2 modes[20]; + unsigned int count; +}; + +static HRESULT CALLBACK build_mode_list_cb(DDSURFACEDESC2 *desc, void *context) +{ + struct display_mode_list *modes = context; + + if (modes->count < ARRAY_SIZE(modes->modes)) + modes->modes[modes->count] = *desc; + ++modes->count; + + return DDENUMRET_OK; +} + struct enum_surfaces_param { IDirectDrawSurface7 *surfaces[8]; + struct display_mode_list modes; unsigned int count; };
@@ -15086,9 +15104,31 @@ static HRESULT WINAPI enum_surfaces_cb(IDirectDrawSurface7 *surface, DDSURFACEDE return DDENUMRET_OK; }
+static HRESULT WINAPI enum_surfaces_create_cb(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *desc, void *context) +{ + static const DWORD expect_flags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH | DDSD_PIXELFORMAT; + struct enum_surfaces_param *param = context; + + ok(!surface, "Unexpected surface %p.\n", surface); + ok((desc->dwFlags & expect_flags) == expect_flags, "Got unexpected flags %#x.\n", desc->dwFlags); + if (param->count < ARRAY_SIZE(param->modes.modes)) + { + const DDSURFACEDESC2 *expect = ¶m->modes.modes[param->count]; + ok(desc->dwWidth == expect->dwWidth, "Expected width %u, got %u.\n", expect->dwWidth, desc->dwWidth); + ok(desc->dwHeight == expect->dwHeight, "Expected height %u, got %u.\n", expect->dwHeight, desc->dwHeight); + ok(!memcmp(&U4(*desc).ddpfPixelFormat, &U4(*expect).ddpfPixelFormat, sizeof(U4(*desc).ddpfPixelFormat)), + "Pixel formats didn't match.\n"); + } + + ++param->count; + + return DDENUMRET_OK; +} + static void test_enum_surfaces(void) { struct enum_surfaces_param param = {{0}}; + DDPIXELFORMAT current_format; DDSURFACEDESC2 desc; IDirectDraw7 *ddraw; HRESULT hr; @@ -15096,8 +15136,24 @@ static void test_enum_surfaces(void) ddraw = create_ddraw(); ok(!!ddraw, "Failed to create a ddraw object.\n");
+ memset(&desc, 0, sizeof(desc)); + desc.dwSize = sizeof(desc); + hr = IDirectDraw7_GetDisplayMode(ddraw, &desc); + ok(hr == DD_OK, "Failed to get display mode, hr %#x.\n", hr); + current_format = U4(desc).ddpfPixelFormat; + hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL); - ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr); + ok(hr == DD_OK, "Failed to set cooperative level, hr %#x.\n", hr); + + hr = IDirectDraw7_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, NULL, NULL, NULL); + ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr); + + hr = IDirectDraw7_EnumSurfaces(ddraw, DDENUMSURFACES_ALL, NULL, NULL, enum_surfaces_cb); + todo_wine ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr); + + hr = IDirectDraw7_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_ALL, + NULL, NULL, enum_surfaces_cb); + todo_wine ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
memset(&desc, 0, sizeof(desc)); desc.dwSize = sizeof(desc); @@ -15114,27 +15170,125 @@ static void test_enum_surfaces(void) }
hr = IDirectDrawSurface7_GetAttachedSurface(param.surfaces[0], &desc.ddsCaps, ¶m.surfaces[1]); - ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr); + ok(hr == DD_OK, "Failed to get attached surface, hr %#x.\n", hr); hr = IDirectDrawSurface7_GetAttachedSurface(param.surfaces[1], &desc.ddsCaps, ¶m.surfaces[2]); - ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr); + ok(hr == DD_OK, "Failed to get attached surface, hr %#x.\n", hr); hr = IDirectDrawSurface7_GetAttachedSurface(param.surfaces[2], &desc.ddsCaps, ¶m.surfaces[3]); ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr); ok(!param.surfaces[3], "Got unexpected pointer %p.\n", param.surfaces[3]);
+ param.count = 0; hr = IDirectDraw7_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, &desc, ¶m, enum_surfaces_cb); - ok(SUCCEEDED(hr), "Failed to enumerate surfaces, hr %#x.\n", hr); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); ok(param.count == 3, "Got unexpected number of enumerated surfaces %u.\n", param.count);
param.count = 0; hr = IDirectDraw7_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, NULL, ¶m, enum_surfaces_cb); - ok(SUCCEEDED(hr), "Failed to enumerate surfaces, hr %#x.\n", hr); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + ok(param.count == 3, "Got unexpected number of enumerated surfaces %u.\n", param.count); + + desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT; + param.count = 0; + hr = IDirectDraw7_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_MATCH, + &desc, ¶m, enum_surfaces_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + ok(param.count == 1, "Got unexpected number of enumerated surfaces %u.\n", param.count); + + param.count = 0; + hr = IDirectDraw7_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_NOMATCH, + &desc, ¶m, enum_surfaces_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + todo_wine ok(param.count == 2, "Got unexpected number of enumerated surfaces %u.\n", param.count); + + desc.dwFlags = 0; + param.count = 0; + hr = IDirectDraw7_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_MATCH, + &desc, ¶m, enum_surfaces_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + ok(param.count == 3, "Got unexpected number of enumerated surfaces %u.\n", param.count); + + desc.dwFlags = 0; + param.count = 0; + hr = IDirectDraw7_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST, &desc, ¶m, enum_surfaces_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); ok(param.count == 3, "Got unexpected number of enumerated surfaces %u.\n", param.count);
IDirectDrawSurface7_Release(param.surfaces[2]); IDirectDrawSurface7_Release(param.surfaces[1]); IDirectDrawSurface7_Release(param.surfaces[0]); + + param.count = 0; + hr = IDirectDraw7_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, + NULL, ¶m, enum_surfaces_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + ok(!param.count, "Got unexpected number of enumerated surfaces %u.\n", param.count); + + memset(&desc, 0, sizeof(desc)); + desc.dwSize = sizeof(desc); + desc.dwFlags = DDSD_CAPS; + desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE; + + hr = IDirectDraw7_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_ALL, + &desc, ¶m, enum_surfaces_create_cb); + todo_wine ok(hr == DDERR_INVALIDPARAMS, "Failed to enumerate surfaces, hr %#x.\n", hr); + + hr = IDirectDraw7_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_NOMATCH, + &desc, ¶m, enum_surfaces_create_cb); + todo_wine ok(hr == DDERR_INVALIDPARAMS, "Failed to enumerate surfaces, hr %#x.\n", hr); + + hr = IDirectDraw7_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED, + &desc, ¶m, enum_surfaces_create_cb); + todo_wine ok(hr == DDERR_INVALIDPARAMS, "Failed to enumerate surfaces, hr %#x.\n", hr); + + /* When not passed width and height, the callback is called with every + * available display resolution. */ + + param.modes.count = 0; + desc.dwFlags |= DDSD_PIXELFORMAT; + U4(desc).ddpfPixelFormat = current_format; + hr = IDirectDraw7_EnumDisplayModes(ddraw, 0, &desc, ¶m.modes, build_mode_list_cb); + ok(hr == DD_OK, "Failed to build mode list, hr %#x.\n", hr); + + param.count = 0; + desc.dwFlags &= ~DDSD_PIXELFORMAT; + hr = IDirectDraw7_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_MATCH, + &desc, ¶m, enum_surfaces_create_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + todo_wine ok(param.count == param.modes.count, "Expected %u surfaces, got %u.\n", param.modes.count, param.count); + + desc.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT; + desc.dwWidth = desc.dwHeight = 32; + + param.modes.modes[0].dwWidth = param.modes.modes[0].dwHeight = 32; + + param.count = 0; + hr = IDirectDraw7_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_MATCH, + &desc, ¶m, enum_surfaces_create_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + todo_wine ok(param.count == 1, "Got unexpected number of enumerated surfaces %u.\n", param.count); + + hr = IDirectDraw7_CreateSurface(ddraw, &desc, ¶m.surfaces[0], NULL); + ok(hr == DD_OK, "Failed to create surface, hr %#x.\n", hr); + param.count = 0; + hr = IDirectDraw7_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_MATCH, + &desc, ¶m, enum_surfaces_create_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + todo_wine ok(param.count == 1, "Got unexpected number of enumerated surfaces %u.\n", param.count); + IDirectDrawSurface7_Release(param.surfaces[0]); + + desc.dwFlags |= DDSD_PIXELFORMAT; + U4(desc).ddpfPixelFormat.dwSize = sizeof(U4(desc).ddpfPixelFormat); + U4(desc).ddpfPixelFormat.dwFlags = DDPF_FOURCC; + U4(desc).ddpfPixelFormat.dwFourCC = 0xdeadbeef; + + param.count = 0; + hr = IDirectDraw7_EnumSurfaces(ddraw, DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_MATCH, + &desc, ¶m, enum_surfaces_create_cb); + ok(hr == DD_OK, "Failed to enumerate surfaces, hr %#x.\n", hr); + ok(!param.count, "Got unexpected number of enumerated surfaces %u.\n", param.count); + IDirectDraw7_Release(ddraw); }