From: Patrick Rudolph Subject: [2/2] ddraw: add dsurface dimension tests, try 11 Message-Id: Date: Mon, 30 Jun 2014 17:42:55 +0200 Add some test for DirectDraw offscreen surface dimensions. Metal Gear Solid 1 tries to create a surface with dimensions 15728640 x 20971520 while detecting 3D-capable hardware. try 2: handle VMs without DDSCAPS_VIDEOMEMORY try 3: add more tests remove todo_wine on some parts use memset instead of ZeroMemory try 4: remove test from dsurface.c, add separate tests to ddraw{1,2,4,7}.c destroy window after test try 5: rebase against current git try 6: use array for tests use different pixel formats try 7: fix tests on 64bit try 8: remove 64bit specific tests code style changes try 9: remove one surface test constify array add patch for wine to prevent test failures prevent possible surface leak try 10: style changes remove SetCooperativeLevel call correct IDirectDrawSurface function in ddraw2 test for enough vidmem first in wined3d/resource.c try 11: more style changes Please review. From 7b6613ba697e7c06c91beac647c501b0cbfa62c1 Mon Sep 17 00:00:00 2001 From: Patrick Rudolph Date: Mon, 30 Jun 2014 17:38:53 +0200 Subject: ddraw: add dsurface dimension tests --- dlls/ddraw/tests/ddraw1.c | 137 ++++++++++++++++++++++++++++++++++++++++++++ dlls/ddraw/tests/ddraw2.c | 137 ++++++++++++++++++++++++++++++++++++++++++++ dlls/ddraw/tests/ddraw4.c | 137 ++++++++++++++++++++++++++++++++++++++++++++ dlls/ddraw/tests/ddraw7.c | 137 ++++++++++++++++++++++++++++++++++++++++++++ dlls/ddraw/tests/dsurface.c | 119 -------------------------------------- 5 files changed, 548 insertions(+), 119 deletions(-) diff --git a/dlls/ddraw/tests/ddraw1.c b/dlls/ddraw/tests/ddraw1.c index 094d0a1..092f330 100644 --- a/dlls/ddraw/tests/ddraw1.c +++ b/dlls/ddraw/tests/ddraw1.c @@ -5575,6 +5575,142 @@ static void test_lost_device(void) DestroyWindow(window); } +static void test_surface_size(void) +{ + IDirectDrawSurface *surface = NULL; + IDirectDraw *ddraw; + DDSURFACEDESC surfacedesc; + HRESULT hr; + DDCAPS ddcaps; + HWND window; + DWORD i,j; + + const static struct + { + const char *name; + DDPIXELFORMAT fmt; + } + formats[] = + { + { + "D3DFMT_A8R8G8B8", + { + sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0, + {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000} + } + }, + { + "D3DFMT_R5G6B5", + { + sizeof(DDPIXELFORMAT), DDPF_RGB, 0, + {16}, {0x0000F800}, {0x000007E0}, {0x0000001F}, {0x00000000} + } + }, + { + "D3DFMT_P8", + { + sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0, + {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000} + } + }, + }; + + static struct + { + DWORD dwFlags; + DWORD dwCaps; + DWORD dwWidth; + DWORD dwHeight; + HRESULT hr; + } + tests[] = + { + /* 0: Create an offscreen surface surface without a size */ + {DDSD_CAPS, DDSCAPS_OFFSCREENPLAIN, 0, 0, DDERR_INVALIDPARAMS}, + /* 1: Create an offscreen surface surface with only a width parameter */ + {DDSD_CAPS | DDSD_WIDTH, DDSCAPS_OFFSCREENPLAIN, 128, 0, DDERR_INVALIDPARAMS}, + /* 2: Create an offscreen surface surface with only a height parameter */ + {DDSD_CAPS | DDSD_HEIGHT, DDSCAPS_OFFSCREENPLAIN, 0, 128, DDERR_INVALIDPARAMS}, + /* 3: Test 0 height */ + {DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT, DDSCAPS_OFFSCREENPLAIN, 1, 0, DDERR_INVALIDPARAMS}, + /* 4: Test 0 width */ + {DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT, DDSCAPS_OFFSCREENPLAIN, 0, 1, DDERR_INVALIDPARAMS}, + /* 5: Sanity check */ + {DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT, DDSCAPS_OFFSCREENPLAIN, 128, 128, DD_OK}, + /* 6: Test maximum surface height */ + {DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT, DDSCAPS_OFFSCREENPLAIN, 1, 0x10000, DDERR_INVALIDPARAMS}, + /* 7: Test maximum surface width */ + {DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT, DDSCAPS_OFFSCREENPLAIN, 0x10000, 1, DDERR_INVALIDPARAMS}, + /* 8: Test OUTOFVIDEOMEMORY */ + {DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT, DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, + 0xffff, 0xffff, DDERR_OUTOFVIDEOMEMORY}, + }; + + window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW, + 100, 100, 160, 160, NULL, NULL, NULL, NULL); + ddraw = create_ddraw(); + ok(!!ddraw, "Failed to create a ddraw object.\n"); + hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL); + ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr); + + ddcaps.dwSize = sizeof(DDCAPS); + hr = IDirectDraw_GetCaps(ddraw, &ddcaps, NULL); + ok(SUCCEEDED(hr), "IDirectDraw_GetCaps failed, hr %#x.\n", hr); + + /* expect an error if the hardware doesn't support videomemory */ + if (!(ddcaps.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)) + tests[8].hr = DDERR_NODIRECTDRAWHW; + + for (j = 0; j < sizeof(formats) / sizeof(*formats); j++) + { + for (i = 0; i < sizeof(tests) / sizeof(*tests); i++) + { + memset(&surfacedesc, 0, sizeof(surfacedesc)); + surfacedesc.dwSize = sizeof(surfacedesc); + surfacedesc.dwFlags = tests[i].dwFlags | DDSD_PIXELFORMAT; + surfacedesc.ddsCaps.dwCaps = tests[i].dwCaps; + surfacedesc.dwWidth = tests[i].dwWidth; + surfacedesc.dwHeight = tests[i].dwHeight; + surfacedesc.ddpfPixelFormat = formats[j].fmt; + + hr = IDirectDraw_CreateSurface(ddraw, &surfacedesc, &surface, NULL); + ok(hr == tests[i].hr, "Pixelformat %s, test %d returned %08x\n", formats[j].name, i, hr); + + if (surface) + { + IDirectDrawSurface_Release(surface); + surface = NULL; + } + } + } + + /* Test a primary surface size */ + memset(&surfacedesc, 0, sizeof(surfacedesc)); + surfacedesc.dwSize = sizeof(surfacedesc); + surfacedesc.dwFlags = DDSD_CAPS; + surfacedesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; + surfacedesc.dwWidth = 128; + surfacedesc.dwHeight = 128; + hr = IDirectDraw_CreateSurface(ddraw, &surfacedesc, &surface, NULL); + ok(SUCCEEDED(hr), "CreateSurface returned %08x\n", hr); + if (surface) + { + hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surfacedesc); + ok(SUCCEEDED(hr), "GetSurfaceDesc returned %x\n", hr); + + ok(surfacedesc.dwFlags & DDSD_WIDTH, "Primary surface doesn't have width set\n"); + ok(surfacedesc.dwFlags & DDSD_HEIGHT, "Primary surface doesn't have height set\n"); + ok(surfacedesc.dwWidth == GetSystemMetrics(SM_CXSCREEN), "Surface width differs from screen width\n"); + ok(surfacedesc.dwHeight == GetSystemMetrics(SM_CYSCREEN), "Surface height differs from screen height\n"); + + IDirectDrawSurface_Release(surface); + surface = NULL; + } + + IDirectDraw_Release(ddraw); + DestroyWindow(window); +} + START_TEST(ddraw1) { IDirectDraw *ddraw; @@ -5626,4 +5762,5 @@ START_TEST(ddraw1) test_palette_gdi(); test_palette_alpha(); test_lost_device(); + test_surface_size(); } diff --git a/dlls/ddraw/tests/ddraw2.c b/dlls/ddraw/tests/ddraw2.c index 9704ce9..024d212 100644 --- a/dlls/ddraw/tests/ddraw2.c +++ b/dlls/ddraw/tests/ddraw2.c @@ -6651,6 +6651,142 @@ static void test_lost_device(void) DestroyWindow(window); } +static void test_surface_size(void) +{ + IDirectDrawSurface *surface = NULL; + IDirectDraw2 *ddraw; + DDSURFACEDESC surfacedesc; + HRESULT hr; + DDCAPS ddcaps; + HWND window; + DWORD i,j; + + const static struct + { + const char *name; + DDPIXELFORMAT fmt; + } + formats[] = + { + { + "D3DFMT_A8R8G8B8", + { + sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0, + {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000} + } + }, + { + "D3DFMT_R5G6B5", + { + sizeof(DDPIXELFORMAT), DDPF_RGB, 0, + {16}, {0x0000F800}, {0x000007E0}, {0x0000001F}, {0x00000000} + } + }, + { + "D3DFMT_P8", + { + sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0, + {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000} + } + }, + }; + + static struct + { + DWORD dwFlags; + DWORD dwCaps; + DWORD dwWidth; + DWORD dwHeight; + HRESULT hr; + } + tests[] = + { + /* 0: Create an offscreen surface surface without a size */ + {DDSD_CAPS, DDSCAPS_OFFSCREENPLAIN, 0, 0, DDERR_INVALIDPARAMS}, + /* 1: Create an offscreen surface surface with only a width parameter */ + {DDSD_CAPS | DDSD_WIDTH, DDSCAPS_OFFSCREENPLAIN, 128, 0, DDERR_INVALIDPARAMS}, + /* 2: Create an offscreen surface surface with only a height parameter */ + {DDSD_CAPS | DDSD_HEIGHT, DDSCAPS_OFFSCREENPLAIN, 0, 128, DDERR_INVALIDPARAMS}, + /* 3: Test 0 height */ + {DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT, DDSCAPS_OFFSCREENPLAIN, 1, 0, DDERR_INVALIDPARAMS}, + /* 4: Test 0 width */ + {DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT, DDSCAPS_OFFSCREENPLAIN, 0, 1, DDERR_INVALIDPARAMS}, + /* 5: Sanity check */ + {DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT, DDSCAPS_OFFSCREENPLAIN, 128, 128, DD_OK}, + /* 6: Test maximum surface height */ + {DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT, DDSCAPS_OFFSCREENPLAIN, 1, 0x10000, DDERR_INVALIDPARAMS}, + /* 7: Test maximum surface width */ + {DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT, DDSCAPS_OFFSCREENPLAIN, 0x10000, 1, DDERR_INVALIDPARAMS}, + /* 8: Test OUTOFVIDEOMEMORY */ + {DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT, DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, + 0xffff, 0xffff, DDERR_OUTOFVIDEOMEMORY}, + }; + + window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW, + 100, 100, 160, 160, NULL, NULL, NULL, NULL); + ddraw = create_ddraw(); + ok(!!ddraw, "Failed to create a ddraw object.\n"); + hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL); + ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr); + + ddcaps.dwSize = sizeof(DDCAPS); + hr = IDirectDraw2_GetCaps(ddraw, &ddcaps, NULL); + ok(SUCCEEDED(hr), "IDirectDraw_GetCaps failed, hr %#x.\n", hr); + + /* expect an error if the hardware doesn't support videomemory */ + if (!(ddcaps.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)) + tests[8].hr = DDERR_NODIRECTDRAWHW; + + for (j = 0; j < sizeof(formats) / sizeof(*formats); j++) + { + for (i = 0; i < sizeof(tests) / sizeof(*tests); i++) + { + memset(&surfacedesc, 0, sizeof(surfacedesc)); + surfacedesc.dwSize = sizeof(surfacedesc); + surfacedesc.dwFlags = tests[i].dwFlags | DDSD_PIXELFORMAT; + surfacedesc.ddsCaps.dwCaps = tests[i].dwCaps; + surfacedesc.dwWidth = tests[i].dwWidth; + surfacedesc.dwHeight = tests[i].dwHeight; + surfacedesc.ddpfPixelFormat = formats[j].fmt; + + hr = IDirectDraw2_CreateSurface(ddraw, &surfacedesc, &surface, NULL); + ok(hr == tests[i].hr, "Pixelformat %s, test %d returned %08x\n", formats[j].name, i, hr); + + if (surface) + { + IDirectDrawSurface_Release(surface); + surface = NULL; + } + } + } + + /* Test a primary surface size */ + memset(&surfacedesc, 0, sizeof(surfacedesc)); + surfacedesc.dwSize = sizeof(surfacedesc); + surfacedesc.dwFlags = DDSD_CAPS; + surfacedesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; + surfacedesc.dwWidth = 128; + surfacedesc.dwHeight = 128; + hr = IDirectDraw2_CreateSurface(ddraw, &surfacedesc, &surface, NULL); + ok(SUCCEEDED(hr), "CreateSurface returned %08x\n", hr); + if (surface) + { + hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surfacedesc); + ok(SUCCEEDED(hr), "GetSurfaceDesc returned %x\n", hr); + + ok(surfacedesc.dwFlags & DDSD_WIDTH, "Primary surface doesn't have width set\n"); + ok(surfacedesc.dwFlags & DDSD_HEIGHT, "Primary surface doesn't have height set\n"); + ok(surfacedesc.dwWidth == GetSystemMetrics(SM_CXSCREEN), "Surface width differs from screen width\n"); + ok(surfacedesc.dwHeight == GetSystemMetrics(SM_CYSCREEN), "Surface height differs from screen height\n"); + + IDirectDrawSurface_Release(surface); + surface = NULL; + } + + IDirectDraw2_Release(ddraw); + DestroyWindow(window); +} + START_TEST(ddraw2) { IDirectDraw2 *ddraw; @@ -6708,4 +6844,5 @@ START_TEST(ddraw2) test_palette_gdi(); test_palette_alpha(); test_lost_device(); + test_surface_size(); } diff --git a/dlls/ddraw/tests/ddraw4.c b/dlls/ddraw/tests/ddraw4.c index 28f41bb..856e523 100644 --- a/dlls/ddraw/tests/ddraw4.c +++ b/dlls/ddraw/tests/ddraw4.c @@ -7726,6 +7726,142 @@ static void test_lost_device(void) DestroyWindow(window); } +static void test_surface_size(void) +{ + IDirectDrawSurface4 *surface = NULL; + IDirectDraw4 *ddraw; + DDSURFACEDESC2 surfacedesc; + HRESULT hr; + DDCAPS ddcaps; + HWND window; + DWORD i,j; + + const static struct + { + const char *name; + DDPIXELFORMAT fmt; + } + formats[] = + { + { + "D3DFMT_A8R8G8B8", + { + sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0, + {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000} + } + }, + { + "D3DFMT_R5G6B5", + { + sizeof(DDPIXELFORMAT), DDPF_RGB, 0, + {16}, {0x0000F800}, {0x000007E0}, {0x0000001F}, {0x00000000} + } + }, + { + "D3DFMT_P8", + { + sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0, + {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000} + } + }, + }; + + static struct + { + DWORD dwFlags; + DWORD dwCaps; + DWORD dwWidth; + DWORD dwHeight; + HRESULT hr; + } + tests[] = + { + /* 0: Create an offscreen surface surface without a size */ + {DDSD_CAPS, DDSCAPS_OFFSCREENPLAIN, 0, 0, DDERR_INVALIDPARAMS}, + /* 1: Create an offscreen surface surface with only a width parameter */ + {DDSD_CAPS | DDSD_WIDTH, DDSCAPS_OFFSCREENPLAIN, 128, 0, DDERR_INVALIDPARAMS}, + /* 2: Create an offscreen surface surface with only a height parameter */ + {DDSD_CAPS | DDSD_HEIGHT, DDSCAPS_OFFSCREENPLAIN, 0, 128, DDERR_INVALIDPARAMS}, + /* 3: Test 0 height */ + {DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT, DDSCAPS_OFFSCREENPLAIN, 1, 0, DDERR_INVALIDPARAMS}, + /* 4: Test 0 width */ + {DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT, DDSCAPS_OFFSCREENPLAIN, 0, 1, DDERR_INVALIDPARAMS}, + /* 5: Sanity check */ + {DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT, DDSCAPS_OFFSCREENPLAIN, 128, 128, DD_OK}, + /* 6: Test maximum surface height */ + {DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT, DDSCAPS_OFFSCREENPLAIN, 1, 0x10000, DDERR_INVALIDPARAMS}, + /* 7: Test maximum surface width */ + {DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT, DDSCAPS_OFFSCREENPLAIN, 0x10000, 1, DDERR_INVALIDPARAMS}, + /* 8: Test OUTOFVIDEOMEMORY */ + {DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT, DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, + 0xffff, 0xffff, DDERR_OUTOFVIDEOMEMORY}, + }; + + window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW, + 100, 100, 160, 160, NULL, NULL, NULL, NULL); + ddraw = create_ddraw(); + ok(!!ddraw, "Failed to create a ddraw object.\n"); + hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL); + ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr); + + ddcaps.dwSize = sizeof(DDCAPS); + hr = IDirectDraw4_GetCaps(ddraw, &ddcaps, NULL); + ok(SUCCEEDED(hr), "IDirectDraw_GetCaps failed, hr %#x.\n", hr); + + /* expect an error if the hardware doesn't support videomemory */ + if (!(ddcaps.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)) + tests[8].hr = DDERR_NODIRECTDRAWHW; + + for (j = 0; j < sizeof(formats) / sizeof(*formats); j++) + { + for (i = 0; i < sizeof(tests) / sizeof(*tests); i++) + { + memset(&surfacedesc, 0, sizeof(surfacedesc)); + surfacedesc.dwSize = sizeof(surfacedesc); + surfacedesc.dwFlags = tests[i].dwFlags | DDSD_PIXELFORMAT; + surfacedesc.ddsCaps.dwCaps = tests[i].dwCaps; + surfacedesc.dwWidth = tests[i].dwWidth; + surfacedesc.dwHeight = tests[i].dwHeight; + surfacedesc.ddpfPixelFormat = formats[j].fmt; + + hr = IDirectDraw4_CreateSurface(ddraw, &surfacedesc, &surface, NULL); + ok(hr == tests[i].hr, "Pixelformat %s, test %d returned %08x\n", formats[j].name, i, hr); + + if (surface) + { + IDirectDrawSurface4_Release(surface); + surface = NULL; + } + } + } + + /* Test a primary surface size */ + memset(&surfacedesc, 0, sizeof(surfacedesc)); + surfacedesc.dwSize = sizeof(surfacedesc); + surfacedesc.dwFlags = DDSD_CAPS; + surfacedesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; + surfacedesc.dwWidth = 128; + surfacedesc.dwHeight = 128; + hr = IDirectDraw4_CreateSurface(ddraw, &surfacedesc, &surface, NULL); + ok(SUCCEEDED(hr), "CreateSurface returned %08x\n", hr); + if (surface) + { + hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &surfacedesc); + ok(SUCCEEDED(hr), "GetSurfaceDesc returned %x\n", hr); + + ok(surfacedesc.dwFlags & DDSD_WIDTH, "Primary surface doesn't have width set\n"); + ok(surfacedesc.dwFlags & DDSD_HEIGHT, "Primary surface doesn't have height set\n"); + ok(surfacedesc.dwWidth == GetSystemMetrics(SM_CXSCREEN), "Surface width differs from screen width\n"); + ok(surfacedesc.dwHeight == GetSystemMetrics(SM_CYSCREEN), "Surface height differs from screen height\n"); + + IDirectDrawSurface4_Release(surface); + surface = NULL; + } + + IDirectDraw4_Release(ddraw); + DestroyWindow(window); +} + START_TEST(ddraw4) { IDirectDraw4 *ddraw; @@ -7790,4 +7926,5 @@ START_TEST(ddraw4) test_palette_alpha(); test_vb_writeonly(); test_lost_device(); + test_surface_size(); } diff --git a/dlls/ddraw/tests/ddraw7.c b/dlls/ddraw/tests/ddraw7.c index 3b1553e..912f2c9 100644 --- a/dlls/ddraw/tests/ddraw7.c +++ b/dlls/ddraw/tests/ddraw7.c @@ -7448,6 +7448,142 @@ static void test_lost_device(void) DestroyWindow(window); } +static void test_surface_size(void) +{ + IDirectDrawSurface7 *surface = NULL; + IDirectDraw7 *ddraw; + DDSURFACEDESC2 surfacedesc; + HRESULT hr; + DDCAPS ddcaps; + HWND window; + DWORD i,j; + + const static struct + { + const char *name; + DDPIXELFORMAT fmt; + } + formats[] = + { + { + "D3DFMT_A8R8G8B8", + { + sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0, + {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000} + } + }, + { + "D3DFMT_R5G6B5", + { + sizeof(DDPIXELFORMAT), DDPF_RGB, 0, + {16}, {0x0000F800}, {0x000007E0}, {0x0000001F}, {0x00000000} + } + }, + { + "D3DFMT_P8", + { + sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0, + {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000} + } + }, + }; + + static struct + { + DWORD dwFlags; + DWORD dwCaps; + DWORD dwWidth; + DWORD dwHeight; + HRESULT hr; + } + tests[] = + { + /* 0: Create an offscreen surface surface without a size */ + {DDSD_CAPS, DDSCAPS_OFFSCREENPLAIN, 0, 0, DDERR_INVALIDPARAMS}, + /* 1: Create an offscreen surface surface with only a width parameter */ + {DDSD_CAPS | DDSD_WIDTH, DDSCAPS_OFFSCREENPLAIN, 128, 0, DDERR_INVALIDPARAMS}, + /* 2: Create an offscreen surface surface with only a height parameter */ + {DDSD_CAPS | DDSD_HEIGHT, DDSCAPS_OFFSCREENPLAIN, 0, 128, DDERR_INVALIDPARAMS}, + /* 3: Test 0 height */ + {DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT, DDSCAPS_OFFSCREENPLAIN, 1, 0, DDERR_INVALIDPARAMS}, + /* 4: Test 0 width */ + {DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT, DDSCAPS_OFFSCREENPLAIN, 0, 1, DDERR_INVALIDPARAMS}, + /* 5: Sanity check */ + {DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT, DDSCAPS_OFFSCREENPLAIN, 128, 128, DD_OK}, + /* 6: Test maximum surface height */ + {DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT, DDSCAPS_OFFSCREENPLAIN, 1, 0x10000, DDERR_INVALIDPARAMS}, + /* 7: Test maximum surface width */ + {DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT, DDSCAPS_OFFSCREENPLAIN, 0x10000, 1, DDERR_INVALIDPARAMS}, + /* 8: Test OUTOFVIDEOMEMORY */ + {DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT, DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, + 0xffff, 0xffff, DDERR_OUTOFVIDEOMEMORY}, + }; + + window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW, + 100, 100, 160, 160, NULL, NULL, NULL, NULL); + ddraw = create_ddraw(); + ok(!!ddraw, "Failed to create a ddraw object.\n"); + hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL); + ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr); + + ddcaps.dwSize = sizeof(DDCAPS); + hr = IDirectDraw7_GetCaps(ddraw, &ddcaps, NULL); + ok(SUCCEEDED(hr), "IDirectDraw_GetCaps failed, hr %#x.\n", hr); + + /* expect an error if the hardware doesn't support videomemory */ + if (!(ddcaps.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)) + tests[8].hr = DDERR_NODIRECTDRAWHW; + + for (j = 0; j < sizeof(formats) / sizeof(*formats); j++) + { + for (i = 0; i < sizeof(tests) / sizeof(*tests); i++) + { + memset(&surfacedesc, 0, sizeof(surfacedesc)); + surfacedesc.dwSize = sizeof(surfacedesc); + surfacedesc.dwFlags = tests[i].dwFlags | DDSD_PIXELFORMAT; + surfacedesc.ddsCaps.dwCaps = tests[i].dwCaps; + surfacedesc.dwWidth = tests[i].dwWidth; + surfacedesc.dwHeight = tests[i].dwHeight; + surfacedesc.ddpfPixelFormat = formats[j].fmt; + + hr = IDirectDraw7_CreateSurface(ddraw, &surfacedesc, &surface, NULL); + ok(hr == tests[i].hr, "Pixelformat %s, test %d returned %08x\n", formats[j].name, i, hr); + + if (surface) + { + IDirectDrawSurface7_Release(surface); + surface = NULL; + } + } + } + + /* Test a primary surface size */ + memset(&surfacedesc, 0, sizeof(surfacedesc)); + surfacedesc.dwSize = sizeof(surfacedesc); + surfacedesc.dwFlags = DDSD_CAPS; + surfacedesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; + surfacedesc.dwWidth = 128; + surfacedesc.dwHeight = 128; + hr = IDirectDraw7_CreateSurface(ddraw, &surfacedesc, &surface, NULL); + ok(SUCCEEDED(hr), "CreateSurface returned %08x\n", hr); + if (surface) + { + hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surfacedesc); + ok(SUCCEEDED(hr), "GetSurfaceDesc returned %x\n", hr); + + ok(surfacedesc.dwFlags & DDSD_WIDTH, "Primary surface doesn't have width set\n"); + ok(surfacedesc.dwFlags & DDSD_HEIGHT, "Primary surface doesn't have height set\n"); + ok(surfacedesc.dwWidth == GetSystemMetrics(SM_CXSCREEN), "Surface width differs from screen width\n"); + ok(surfacedesc.dwHeight == GetSystemMetrics(SM_CYSCREEN), "Surface height differs from screen height\n"); + + IDirectDrawSurface7_Release(surface); + surface = NULL; + } + + IDirectDraw7_Release(ddraw); + DestroyWindow(window); +} + START_TEST(ddraw7) { HMODULE module = GetModuleHandleA("ddraw.dll"); @@ -7519,4 +7655,5 @@ START_TEST(ddraw7) test_palette_alpha(); test_vb_writeonly(); test_lost_device(); + test_surface_size(); } diff --git a/dlls/ddraw/tests/dsurface.c b/dlls/ddraw/tests/dsurface.c index e8a9c1e..0fcba43 100644 --- a/dlls/ddraw/tests/dsurface.c +++ b/dlls/ddraw/tests/dsurface.c @@ -1902,124 +1902,6 @@ static void CompressedTest(void) IDirectDraw7_Release(dd7); } -static void SizeTest(void) -{ - IDirectDrawSurface *dsurface = NULL; - DDSURFACEDESC desc; - HRESULT ret; - HWND window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW, - 100, 100, 160, 160, NULL, NULL, NULL, NULL); - - /* Create an offscreen surface surface without a size */ - ZeroMemory(&desc, sizeof(desc)); - desc.dwSize = sizeof(desc); - desc.dwFlags = DDSD_CAPS; - desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN; - ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL); - ok(ret == DDERR_INVALIDPARAMS, "Creating an offscreen plain surface without a size info returned %08x (dsurface=%p)\n", ret, dsurface); - if(dsurface) - { - trace("Surface at %p\n", dsurface); - IDirectDrawSurface_Release(dsurface); - dsurface = NULL; - } - - /* Create an offscreen surface surface with only a width parameter */ - ZeroMemory(&desc, sizeof(desc)); - desc.dwSize = sizeof(desc); - desc.dwFlags = DDSD_CAPS | DDSD_WIDTH; - desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN; - desc.dwWidth = 128; - ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL); - ok(ret == DDERR_INVALIDPARAMS, "Creating an offscreen plain surface without height info returned %08x\n", ret); - if(dsurface) - { - IDirectDrawSurface_Release(dsurface); - dsurface = NULL; - } - - /* Create an offscreen surface surface with only a height parameter */ - ZeroMemory(&desc, sizeof(desc)); - desc.dwSize = sizeof(desc); - desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT; - desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN; - desc.dwHeight = 128; - ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL); - ok(ret == DDERR_INVALIDPARAMS, "Creating an offscreen plain surface without width info returned %08x\n", ret); - if(dsurface) - { - IDirectDrawSurface_Release(dsurface); - dsurface = NULL; - } - - /* Test 0 height. */ - memset(&desc, 0, sizeof(desc)); - desc.dwSize = sizeof(desc); - desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; - desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; - desc.dwWidth = 1; - desc.dwHeight = 0; - ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL); - ok(ret == DDERR_INVALIDPARAMS, "Creating a 0 height surface returned %#x, expected DDERR_INVALIDPARAMS.\n", ret); - if (SUCCEEDED(ret)) IDirectDrawSurface_Release(dsurface); - dsurface = NULL; - - /* Test 0 width. */ - memset(&desc, 0, sizeof(desc)); - desc.dwSize = sizeof(desc); - desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; - desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; - desc.dwWidth = 0; - desc.dwHeight = 1; - ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL); - ok(ret == DDERR_INVALIDPARAMS, "Creating a 0 width surface returned %#x, expected DDERR_INVALIDPARAMS.\n", ret); - if (SUCCEEDED(ret)) IDirectDrawSurface_Release(dsurface); - dsurface = NULL; - - /* Sanity check */ - ZeroMemory(&desc, sizeof(desc)); - desc.dwSize = sizeof(desc); - desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; - desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN; - desc.dwHeight = 128; - desc.dwWidth = 128; - ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL); - ok(ret == DD_OK, "Creating an offscreen plain surface with width and height info returned %08x\n", ret); - if(dsurface) - { - IDirectDrawSurface_Release(dsurface); - dsurface = NULL; - } - - /* Test a primary surface size */ - ret = IDirectDraw_SetCooperativeLevel(lpDD, window, DDSCL_NORMAL); - ok(ret == DD_OK, "SetCooperativeLevel failed with %08x\n", ret); - - ZeroMemory(&desc, sizeof(desc)); - desc.dwSize = sizeof(desc); - desc.dwFlags = DDSD_CAPS; - desc.ddsCaps.dwCaps |= DDSCAPS_PRIMARYSURFACE; - desc.dwHeight = 128; /* Keep them set to check what happens */ - desc.dwWidth = 128; /* Keep them set to check what happens */ - ret = IDirectDraw_CreateSurface(lpDD, &desc, &dsurface, NULL); - ok(ret == DD_OK, "Creating a primary surface without width and height info returned %08x\n", ret); - if(dsurface) - { - ret = IDirectDrawSurface_GetSurfaceDesc(dsurface, &desc); - ok(ret == DD_OK, "GetSurfaceDesc returned %x\n", ret); - - IDirectDrawSurface_Release(dsurface); - dsurface = NULL; - - ok(desc.dwFlags & DDSD_WIDTH, "Primary surface doesn't have width set\n"); - ok(desc.dwFlags & DDSD_HEIGHT, "Primary surface doesn't have height set\n"); - ok(desc.dwWidth == GetSystemMetrics(SM_CXSCREEN), "Surface width differs from screen width\n"); - ok(desc.dwHeight == GetSystemMetrics(SM_CYSCREEN), "Surface height differs from screen height\n"); - } - ret = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL); - ok(ret == DD_OK, "SetCooperativeLevel failed with %08x\n", ret); -} - static void BltParamTest(void) { IDirectDrawSurface *surface1 = NULL, *surface2 = NULL; @@ -3956,7 +3838,6 @@ START_TEST(dsurface) CubeMapTest(); test_lockrect_invalid(); CompressedTest(); - SizeTest(); BltParamTest(); StructSizeTest(); PaletteTest(); -- 1.9.3