diff --git a/dlls/ddraw/tests/ddraw1.c b/dlls/ddraw/tests/ddraw1.c index ee03ee94b68..d2765657634 100644 --- a/dlls/ddraw/tests/ddraw1.c +++ b/dlls/ddraw/tests/ddraw1.c @@ -11146,6 +11146,81 @@ static void test_clear(void) DestroyWindow(window); } +struct enum_surfaces_param +{ + IDirectDrawSurface *surfaces[8]; + unsigned int count; +}; + +static HRESULT WINAPI enum_surfaces_cb(IDirectDrawSurface *surface, DDSURFACEDESC *desc, void *context) +{ + struct enum_surfaces_param *param = context; + BOOL found = FALSE; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(param->surfaces); ++i) + { + if (param->surfaces[i] == surface) + { + found = TRUE; + break; + } + } + + ok(found, "Unexpected surface %p enumerated.\n", surface); + IDirectDrawSurface_Release(surface); + ++param->count; + + return DDENUMRET_OK; +} + +static void test_enum_surfaces(void) +{ + struct enum_surfaces_param param = {{0}}; + IDirectDraw *ddraw; + DDSURFACEDESC desc; + HRESULT hr; + + ddraw = create_ddraw(); + ok(!!ddraw, "Failed to create a ddraw object.\n"); + + hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL); + ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr); + + desc.dwSize = sizeof(desc); + desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT; + desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP; + U2(desc).dwMipMapCount = 3; + desc.dwWidth = 32; + desc.dwHeight = 32; + hr = IDirectDraw_CreateSurface(ddraw, &desc, ¶m.surfaces[0], NULL); + ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr); + + hr = IDirectDrawSurface_GetAttachedSurface(param.surfaces[0], &desc.ddsCaps, ¶m.surfaces[1]); + ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr); + hr = IDirectDrawSurface_GetAttachedSurface(param.surfaces[1], &desc.ddsCaps, ¶m.surfaces[2]); + ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr); + hr = IDirectDrawSurface_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]); + + hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, + &desc, ¶m, enum_surfaces_cb); + 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); + + param.count = 0; + hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, + NULL, ¶m, enum_surfaces_cb); + 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); + + IDirectDrawSurface_Release(param.surfaces[2]); + IDirectDrawSurface_Release(param.surfaces[1]); + IDirectDrawSurface_Release(param.surfaces[0]); + IDirectDraw_Release(ddraw); +} + START_TEST(ddraw1) { DDDEVICEIDENTIFIER identifier; @@ -11246,4 +11321,5 @@ START_TEST(ddraw1) test_ck_operation(); test_depth_readback(); test_clear(); + test_enum_surfaces(); } diff --git a/dlls/ddraw/tests/ddraw2.c b/dlls/ddraw/tests/ddraw2.c index 42dc3f262d0..8b23c01b072 100644 --- a/dlls/ddraw/tests/ddraw2.c +++ b/dlls/ddraw/tests/ddraw2.c @@ -12502,6 +12502,81 @@ static void test_clear(void) DestroyWindow(window); } +struct enum_surfaces_param +{ + IDirectDrawSurface *surfaces[8]; + unsigned int count; +}; + +static HRESULT WINAPI enum_surfaces_cb(IDirectDrawSurface *surface, DDSURFACEDESC *desc, void *context) +{ + struct enum_surfaces_param *param = context; + BOOL found = FALSE; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(param->surfaces); ++i) + { + if (param->surfaces[i] == surface) + { + found = TRUE; + break; + } + } + + ok(found, "Unexpected surface %p enumerated.\n", surface); + IDirectDrawSurface_Release(surface); + ++param->count; + + return DDENUMRET_OK; +} + +static void test_enum_surfaces(void) +{ + struct enum_surfaces_param param = {{0}}; + IDirectDraw2 *ddraw; + DDSURFACEDESC desc; + HRESULT hr; + + ddraw = create_ddraw(); + ok(!!ddraw, "Failed to create a ddraw object.\n"); + + hr = IDirectDraw2_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL); + ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr); + + desc.dwSize = sizeof(desc); + desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT; + desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP; + U2(desc).dwMipMapCount = 3; + desc.dwWidth = 32; + desc.dwHeight = 32; + hr = IDirectDraw2_CreateSurface(ddraw, &desc, ¶m.surfaces[0], NULL); + ok(SUCCEEDED(hr), "Failed to create a surface, hr %#x.\n", hr); + + hr = IDirectDrawSurface_GetAttachedSurface(param.surfaces[0], &desc.ddsCaps, ¶m.surfaces[1]); + ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr); + hr = IDirectDrawSurface_GetAttachedSurface(param.surfaces[1], &desc.ddsCaps, ¶m.surfaces[2]); + ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr); + hr = IDirectDrawSurface_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]); + + hr = IDirectDraw2_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, + &desc, ¶m, enum_surfaces_cb); + 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); + + param.count = 0; + hr = IDirectDraw2_EnumSurfaces(ddraw, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, + NULL, ¶m, enum_surfaces_cb); + 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); + + IDirectDrawSurface_Release(param.surfaces[2]); + IDirectDrawSurface_Release(param.surfaces[1]); + IDirectDrawSurface_Release(param.surfaces[0]); + IDirectDraw2_Release(ddraw); +} + START_TEST(ddraw2) { DDDEVICEIDENTIFIER identifier; @@ -12610,4 +12685,5 @@ START_TEST(ddraw2) test_ck_operation(); test_depth_readback(); test_clear(); + test_enum_surfaces(); } diff --git a/dlls/ddraw/tests/ddraw4.c b/dlls/ddraw/tests/ddraw4.c index dab1e6d0f97..5eb391abd94 100644 --- a/dlls/ddraw/tests/ddraw4.c +++ b/dlls/ddraw/tests/ddraw4.c @@ -14556,6 +14556,81 @@ static void test_clear(void) DestroyWindow(window); } +struct enum_surfaces_param +{ + IDirectDrawSurface4 *surfaces[8]; + unsigned int count; +}; + +static HRESULT WINAPI enum_surfaces_cb(IDirectDrawSurface4 *surface, DDSURFACEDESC2 *desc, void *context) +{ + struct enum_surfaces_param *param = context; + BOOL found = FALSE; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(param->surfaces); ++i) + { + if (param->surfaces[i] == surface) + { + found = TRUE; + break; + } + } + + ok(found, "Unexpected surface %p enumerated.\n", surface); + IDirectDrawSurface4_Release(surface); + ++param->count; + + return DDENUMRET_OK; +} + +static void test_enum_surfaces(void) +{ + struct enum_surfaces_param param = {{0}}; + DDSURFACEDESC2 desc; + IDirectDraw4 *ddraw; + HRESULT hr; + + ddraw = create_ddraw(); + ok(!!ddraw, "Failed to create a ddraw object.\n"); + + hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL); + ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr); + + desc.dwSize = sizeof(desc); + desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT; + desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP; + U2(desc).dwMipMapCount = 3; + 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); + + hr = IDirectDrawSurface4_GetAttachedSurface(param.surfaces[0], &desc.ddsCaps, ¶m.surfaces[1]); + ok(SUCCEEDED(hr), "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); + 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]); + + 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(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(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]); + IDirectDraw4_Release(ddraw); +} + START_TEST(ddraw4) { DDDEVICEIDENTIFIER identifier; @@ -14677,4 +14752,5 @@ START_TEST(ddraw4) test_map_synchronisation(); test_depth_readback(); test_clear(); + test_enum_surfaces(); } diff --git a/dlls/ddraw/tests/ddraw7.c b/dlls/ddraw/tests/ddraw7.c index cebe0ecbf50..d5969ab9492 100644 --- a/dlls/ddraw/tests/ddraw7.c +++ b/dlls/ddraw/tests/ddraw7.c @@ -13884,6 +13884,86 @@ static void test_clear(void) DestroyWindow(window); } +struct enum_surfaces_param +{ + IDirectDrawSurface7 *surfaces[8]; + unsigned int count; +}; + +static HRESULT WINAPI enum_surfaces_cb(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *desc, void *context) +{ + struct enum_surfaces_param *param = context; + BOOL found = FALSE; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(param->surfaces); ++i) + { + if (param->surfaces[i] == surface) + { + found = TRUE; + break; + } + } + + ok(found, "Unexpected surface %p enumerated.\n", surface); + IDirectDrawSurface7_Release(surface); + ++param->count; + + return DDENUMRET_OK; +} + +static void test_enum_surfaces(void) +{ + struct enum_surfaces_param param = {{0}}; + DDSURFACEDESC2 desc; + IDirectDraw7 *ddraw; + HRESULT hr; + + ddraw = create_ddraw(); + ok(!!ddraw, "Failed to create a ddraw object.\n"); + + hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL); + ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr); + + memset(&desc, 0, sizeof(desc)); + desc.dwSize = sizeof(desc); + desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT; + desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP; + U2(desc).dwMipMapCount = 3; + desc.dwWidth = 32; + desc.dwHeight = 32; + if (FAILED(IDirectDraw7_CreateSurface(ddraw, &desc, ¶m.surfaces[0], NULL))) + { + win_skip("Failed to create a texture, skipping tests.\n"); + IDirectDraw7_Release(ddraw); + return; + } + + hr = IDirectDrawSurface7_GetAttachedSurface(param.surfaces[0], &desc.ddsCaps, ¶m.surfaces[1]); + ok(SUCCEEDED(hr), "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); + 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]); + + 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(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(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]); + IDirectDraw7_Release(ddraw); +} + START_TEST(ddraw7) { DDDEVICEIDENTIFIER2 identifier; @@ -14015,4 +14095,5 @@ START_TEST(ddraw7) test_map_synchronisation(); test_depth_readback(); test_clear(); + test_enum_surfaces(); } diff --git a/dlls/ddraw/tests/dsurface.c b/dlls/ddraw/tests/dsurface.c index 90e7fcf781b..0f775a00625 100644 --- a/dlls/ddraw/tests/dsurface.c +++ b/dlls/ddraw/tests/dsurface.c @@ -368,47 +368,6 @@ static HRESULT WINAPI enumCB(IDirectDrawSurface *surf, DDSURFACEDESC *desc, void return DDENUMRET_OK; } -static void EnumTest(void) -{ - HRESULT rc; - DDSURFACEDESC ddsd; - IDirectDrawSurface *surface; - struct enumstruct ctx; - - ddsd.dwSize = sizeof(ddsd); - ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT; - ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP; - U2(ddsd).dwMipMapCount = 3; - ddsd.dwWidth = 32; - ddsd.dwHeight = 32; - rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface, NULL); - ok(rc==DD_OK,"CreateSurface returned: %x\n",rc); - - memset(&ctx, 0, sizeof(ctx)); - ctx.expected[0] = surface; - rc = IDirectDrawSurface_GetAttachedSurface(ctx.expected[0], &ddsd.ddsCaps, &ctx.expected[1]); - ok(rc == DD_OK, "GetAttachedSurface returned %08x\n", rc); - rc = IDirectDrawSurface_GetAttachedSurface(ctx.expected[1], &ddsd.ddsCaps, &ctx.expected[2]); - ok(rc == DD_OK, "GetAttachedSurface returned %08x\n", rc); - rc = IDirectDrawSurface_GetAttachedSurface(ctx.expected[2], &ddsd.ddsCaps, &ctx.expected[3]); - ok(rc == DDERR_NOTFOUND, "GetAttachedSurface returned %08x\n", rc); - ok(!ctx.expected[3], "expected NULL pointer\n"); - ctx.count = 0; - - rc = IDirectDraw_EnumSurfaces(lpDD, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, &ddsd, &ctx, enumCB); - ok(rc == DD_OK, "IDirectDraw_EnumSurfaces returned %08x\n", rc); - ok(ctx.count == 3, "%d surfaces enumerated, expected 3\n", ctx.count); - - ctx.count = 0; - rc = IDirectDraw_EnumSurfaces(lpDD, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, NULL, &ctx, enumCB); - ok(rc == DD_OK, "IDirectDraw_EnumSurfaces returned %08x\n", rc); - ok(ctx.count == 3, "%d surfaces enumerated, expected 3\n", ctx.count); - - IDirectDrawSurface_Release(ctx.expected[2]); - IDirectDrawSurface_Release(ctx.expected[1]); - IDirectDrawSurface_Release(surface); -} - struct compare { DWORD width, height; @@ -2609,7 +2568,6 @@ START_TEST(dsurface) GetDDInterface_2(); GetDDInterface_4(); GetDDInterface_7(); - EnumTest(); CubeMapTest(); CompressedTest(); SizeTest();