ddraw/tests: Probe the supported display modes and skip tests based on the result.

Francois Gouget fgouget at codeweavers.com
Wed Feb 26 19:24:36 CST 2014


---

We have a number of systems that don't support the display modes we use 
for testing:
 * HD4000 : Intel they decided that 256 color modes are obsolete (they 
   are) and not worth supporting.
 * QEmu can emulate an old Cirrus 5446 graphics card that tops out at 
   24bpp and thus does not support the 32bpp modes we want. For Windows 
   2000 that's all that works.

The problem is our tests just assume these modes are supported. But in 
fact it's a pretty simple matter to check beforehand and skip tests that 
depend on unsupported modes. I feel that's simpler and cleaner than my 
previous approach of handling SetDisplayMode() errors.

So that takes care of the 0x80004001 errors. The next step would be 
taking care of the CreateSurface() failures so they don't cause crashes, 
and then the color test failures.


 dlls/ddraw/tests/ddraw1.c | 68 +++++++++++++++++++++++++++++++++++++++
 dlls/ddraw/tests/ddraw2.c | 81 +++++++++++++++++++++++++++++++++++++++++++----
 dlls/ddraw/tests/ddraw4.c | 81 +++++++++++++++++++++++++++++++++++++++++++----
 dlls/ddraw/tests/ddraw7.c | 74 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 290 insertions(+), 14 deletions(-)

diff --git a/dlls/ddraw/tests/ddraw1.c b/dlls/ddraw/tests/ddraw1.c
index 8200e46..6ccd49a 100644
--- a/dlls/ddraw/tests/ddraw1.c
+++ b/dlls/ddraw/tests/ddraw1.c
@@ -439,6 +439,49 @@ static HRESULT restore_surfaces(IDirectDraw *ddraw)
             NULL, NULL, restore_callback);
 }
 
+static int has_640x480x8 = 0;
+static int has_640x480x32 = 0;
+static int has_800x600x32 = 0;
+
+static HRESULT WINAPI display_mode_callback(DDSURFACEDESC *lpddsd, void *lpContext)
+{
+    if (lpddsd->dwWidth == 640 && lpddsd->dwHeight == 480)
+    {
+        if (U1(lpddsd->ddpfPixelFormat).dwRGBBitCount == 8)
+            has_640x480x8 = 1;
+        else if (U1(lpddsd->ddpfPixelFormat).dwRGBBitCount == 32)
+            has_640x480x32 = 1;
+    }
+    else if (lpddsd->dwWidth == 800 && lpddsd->dwHeight == 600)
+    {
+        if (U1(lpddsd->ddpfPixelFormat).dwRGBBitCount == 32)
+            has_800x600x32 = 1;
+    }
+    return DDENUMRET_OK;
+}
+
+static void probe_display_modes(void)
+{
+    IDirectDraw *ddraw;
+    DDSURFACEDESC ddsd;
+    HRESULT hr;
+
+    if (!(ddraw = create_ddraw()))
+    {
+        skip("Failed to create a ddraw object, skipping the display modes probe.\n");
+        return;
+    }
+
+    ZeroMemory(&ddsd, sizeof(ddsd));
+    ddsd.dwSize = sizeof(ddsd);
+    ddsd.dwFlags = DDSD_CAPS;
+    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
+    hr = IDirectDraw_EnumDisplayModes(ddraw, 0, &ddsd, NULL, display_mode_callback);
+    ok(hr == DD_OK, "EnumDisplayModes returned: %x\n",hr);
+
+    IDirectDraw_Release(ddraw);
+}
+
 static void test_coop_level_create_device_window(void)
 {
     HWND focus_window, device_window;
@@ -2143,6 +2186,12 @@ static void test_coop_level_mode_set(void)
         0,
     };
 
+    if (!has_640x480x32)
+    {
+        win_skip("coop_level_mode_set (missing 640x480x32 mode)\n");
+        return;
+    }
+
     if (!(ddraw = create_ddraw()))
     {
         skip("Failed to create a ddraw object, skipping test.\n");
@@ -2577,6 +2626,12 @@ static void test_coop_level_mode_set_multi(void)
     HRESULT hr;
     ULONG ref;
 
+    if (!has_640x480x32 || !has_800x600x32)
+    {
+        skip("coop_level_mode_set_multi (missing 640x480x32 or 800x600x32 mode)\n");
+        return;
+    }
+
     if (!(ddraw1 = create_ddraw()))
     {
         skip("Failed to create a ddraw object, skipping test.\n");
@@ -3840,6 +3895,12 @@ static void test_flip(void)
     DDBLTFX fx;
     HRESULT hr;
 
+    if (!has_640x480x32)
+    {
+        skip("flip (missing 640x480x32 mode)\n");
+        return;
+    }
+
     if (!(ddraw = create_ddraw()))
     {
         skip("Failed to create a ddraw object, skipping test.\n");
@@ -4067,6 +4128,12 @@ static void test_primary_palette(void)
     HWND window;
     HRESULT hr;
 
+    if (!has_640x480x8)
+    {
+        skip("primary_palette (missing 640x480x8 mode)\n");
+        return;
+    }
+
     if (!(ddraw = create_ddraw()))
     {
         skip("Failed to create a ddraw object, skipping test.\n");
@@ -4564,6 +4631,7 @@ cleanup:
 
 START_TEST(ddraw1)
 {
+    probe_display_modes();
     test_coop_level_create_device_window();
     test_clipper_blt();
     test_coop_level_d3d_state();
diff --git a/dlls/ddraw/tests/ddraw2.c b/dlls/ddraw/tests/ddraw2.c
index bfcf27f..fb3b357 100644
--- a/dlls/ddraw/tests/ddraw2.c
+++ b/dlls/ddraw/tests/ddraw2.c
@@ -381,6 +381,49 @@ static HRESULT restore_surfaces(IDirectDraw2 *ddraw)
             NULL, NULL, restore_callback);
 }
 
+static int has_640x480x8 = 0;
+static int has_640x480x32 = 0;
+static int has_800x600x32 = 0;
+
+static HRESULT WINAPI display_mode_callback(DDSURFACEDESC *lpddsd, void *lpContext)
+{
+    if (lpddsd->dwWidth == 640 && lpddsd->dwHeight == 480)
+    {
+        if (U1(lpddsd->ddpfPixelFormat).dwRGBBitCount == 8)
+            has_640x480x8 = 1;
+        else if (U1(lpddsd->ddpfPixelFormat).dwRGBBitCount == 32)
+            has_640x480x32 = 1;
+    }
+    else if (lpddsd->dwWidth == 800 && lpddsd->dwHeight == 600)
+    {
+        if (U1(lpddsd->ddpfPixelFormat).dwRGBBitCount == 32)
+            has_800x600x32 = 1;
+    }
+    return DDENUMRET_OK;
+}
+
+static void probe_display_modes(void)
+{
+    IDirectDraw2 *ddraw;
+    DDSURFACEDESC ddsd;
+    HRESULT hr;
+
+    if (!(ddraw = create_ddraw()))
+    {
+        skip("Failed to create a ddraw object, skipping the display modes probe.\n");
+        return;
+    }
+
+    ZeroMemory(&ddsd, sizeof(ddsd));
+    ddsd.dwSize = sizeof(ddsd);
+    ddsd.dwFlags = DDSD_CAPS;
+    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
+    hr = IDirectDraw2_EnumDisplayModes(ddraw, 0, &ddsd, NULL, display_mode_callback);
+    ok(hr == DD_OK, "EnumDisplayModes returned: %x\n",hr);
+
+    IDirectDraw2_Release(ddraw);
+}
+
 static void test_coop_level_create_device_window(void)
 {
     HWND focus_window, device_window;
@@ -2350,6 +2393,12 @@ static void test_coop_level_mode_set(void)
         0,
     };
 
+    if (!has_640x480x32)
+    {
+        skip("coop_level_mode_set (missing 640x480x32 mode)\n");
+        return;
+    }
+
     if (!(ddraw = create_ddraw()))
     {
         skip("Failed to create a ddraw object, skipping test.\n");
@@ -2877,6 +2926,12 @@ static void test_coop_level_mode_set_multi(void)
     HRESULT hr;
     ULONG ref;
 
+    if (!has_640x480x32 || !has_800x600x32)
+    {
+        skip("coop_level_mode_set_multi (missing 640x480x32 or 800x600x32 mode)\n");
+        return;
+    }
+
     if (!(ddraw1 = create_ddraw()))
     {
         skip("Failed to create a ddraw object, skipping test.\n");
@@ -3250,6 +3305,12 @@ static void test_coop_level_versions(void)
     IDirectDraw2 *ddraw2;
     DDSURFACEDESC ddsd;
 
+    if (!has_640x480x32) /* needed by test_mode_restored() */
+    {
+        skip("coop_level_versions (missing 640x480x32 mode)\n");
+        return;
+    }
+
     window = CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW,
             0, 0, 640, 480, 0, 0, 0, 0);
 
@@ -4521,6 +4582,12 @@ static void test_flip(void)
     DDBLTFX fx;
     HRESULT hr;
 
+    if (!has_640x480x32)
+    {
+        skip("flip (missing 640x480x32 mode)\n");
+        return;
+    }
+
     if (!(ddraw = create_ddraw()))
     {
         skip("Failed to create a ddraw object, skipping test.\n");
@@ -5164,6 +5231,12 @@ static void test_primary_palette(void)
     HWND window;
     HRESULT hr;
 
+    if (!has_640x480x8)
+    {
+        skip("primary_palette (missing 640x480x8 mode)\n");
+        return;
+    }
+
     if (!(ddraw = create_ddraw()))
     {
         skip("Failed to create a ddraw object, skipping test.\n");
@@ -5173,13 +5246,6 @@ static void test_primary_palette(void)
     window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
             0, 0, 640, 480, 0, 0, 0, 0);
     hr = IDirectDraw2_SetDisplayMode(ddraw, 640, 480, 8, 0, 0);
-    if (hr == E_NOTIMPL)
-    {
-        win_skip("changing display mode is not supported (8bpp)\n");
-        IDirectDraw2_Release(ddraw);
-        DestroyWindow(window);
-        return;
-    }
     ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
     hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
     ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
@@ -5661,6 +5727,7 @@ cleanup:
 
 START_TEST(ddraw2)
 {
+    probe_display_modes();
     test_coop_level_create_device_window();
     test_clipper_blt();
     test_coop_level_d3d_state();
diff --git a/dlls/ddraw/tests/ddraw4.c b/dlls/ddraw/tests/ddraw4.c
index b9f56d8..ec8f2c2 100644
--- a/dlls/ddraw/tests/ddraw4.c
+++ b/dlls/ddraw/tests/ddraw4.c
@@ -362,6 +362,49 @@ static void fix_wndproc(HWND window, LONG_PTR proc)
     IDirectDraw4_Release(ddraw);
 }
 
+static int has_640x480x8 = 0;
+static int has_640x480x32 = 0;
+static int has_800x600x32 = 0;
+
+static HRESULT WINAPI display_mode_callback(DDSURFACEDESC2 *lpddsd, void *lpContext)
+{
+    if (lpddsd->dwWidth == 640 && lpddsd->dwHeight == 480)
+    {
+        if (U1(lpddsd->ddpfPixelFormat).dwRGBBitCount == 8)
+            has_640x480x8 = 1;
+        else if (U1(lpddsd->ddpfPixelFormat).dwRGBBitCount == 32)
+            has_640x480x32 = 1;
+    }
+    else if (lpddsd->dwWidth == 800 && lpddsd->dwHeight == 600)
+    {
+        if (U1(lpddsd->ddpfPixelFormat).dwRGBBitCount == 32)
+            has_800x600x32 = 1;
+    }
+    return DDENUMRET_OK;
+}
+
+static void probe_display_modes(void)
+{
+    IDirectDraw4 *ddraw;
+    DDSURFACEDESC2 ddsd;
+    HRESULT hr;
+
+    if (!(ddraw = create_ddraw()))
+    {
+        skip("Failed to create a ddraw object, skipping the display modes probe.\n");
+        return;
+    }
+
+    ZeroMemory(&ddsd, sizeof(ddsd));
+    ddsd.dwSize = sizeof(ddsd);
+    ddsd.dwFlags = DDSD_CAPS;
+    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
+    hr = IDirectDraw4_EnumDisplayModes(ddraw, 0, &ddsd, NULL, display_mode_callback);
+    ok(hr == DD_OK, "EnumDisplayModes returned: %x\n",hr);
+
+    IDirectDraw4_Release(ddraw);
+}
+
 static void test_process_vertices(void)
 {
     IDirect3DVertexBuffer *src_vb, *dst_vb;
@@ -2473,6 +2516,12 @@ static void test_coop_level_mode_set(void)
         0,
     };
 
+    if (!has_640x480x32)
+    {
+        skip("coop_level_mode_set (missing 640x480x32 mode)\n");
+        return;
+    }
+
     if (!(ddraw = create_ddraw()))
     {
         skip("Failed to create a ddraw object, skipping test.\n");
@@ -2993,6 +3042,12 @@ static void test_coop_level_mode_set_multi(void)
     HRESULT hr;
     ULONG ref;
 
+    if (!has_640x480x32 || !has_800x600x32)
+    {
+        skip("coop_level_mode_set_multi (missing 640x480x32 or 800x600x32 mode)\n");
+        return;
+    }
+
     if (!(ddraw1 = create_ddraw()))
     {
         skip("Failed to create a ddraw object, skipping test.\n");
@@ -3483,6 +3538,12 @@ static void test_coop_level_versions(void)
     IDirectDraw4 *ddraw4;
     DDSURFACEDESC ddsd;
 
+    if (!has_640x480x32)
+    {
+        skip("coop_level_versions (missing 640x480x32 mode)\n");
+        return;
+    }
+
     window = CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW,
             0, 0, 640, 480, 0, 0, 0, 0);
 
@@ -5126,6 +5187,12 @@ static void test_flip(void)
     DDBLTFX fx;
     HRESULT hr;
 
+    if (!has_640x480x32)
+    {
+        skip("flip (missing 640x480x32 mode)\n");
+        return;
+    }
+
     if (!(ddraw = create_ddraw()))
     {
         skip("Failed to create a ddraw object, skipping test.\n");
@@ -5762,6 +5829,12 @@ static void test_primary_palette(void)
     HWND window;
     HRESULT hr;
 
+    if (!has_640x480x8)
+    {
+        skip("primary_palette (missing 640x480x8 mode)\n");
+        return;
+    }
+
     if (!(ddraw = create_ddraw()))
     {
         skip("Failed to create a ddraw object, skipping test.\n");
@@ -5771,13 +5844,6 @@ static void test_primary_palette(void)
     window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
             0, 0, 640, 480, 0, 0, 0, 0);
     hr = IDirectDraw4_SetDisplayMode(ddraw, 640, 480, 8, 0, 0);
-    if (hr == E_NOTIMPL)
-    {
-        win_skip("changing display mode is not supported (8bpp)\n");
-        IDirectDraw4_Release(ddraw);
-        DestroyWindow(window);
-        return;
-    }
     ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
     hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
     ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
@@ -6370,6 +6436,7 @@ cleanup:
 
 START_TEST(ddraw4)
 {
+    probe_display_modes();
     test_process_vertices();
     test_coop_level_create_device_window();
     test_clipper_blt();
diff --git a/dlls/ddraw/tests/ddraw7.c b/dlls/ddraw/tests/ddraw7.c
index cb949d1..a76102e 100644
--- a/dlls/ddraw/tests/ddraw7.c
+++ b/dlls/ddraw/tests/ddraw7.c
@@ -346,6 +346,49 @@ static void fix_wndproc(HWND window, LONG_PTR proc)
     IDirectDraw7_Release(ddraw);
 }
 
+static int has_640x480x8 = 0;
+static int has_640x480x32 = 0;
+static int has_800x600x32 = 0;
+
+static HRESULT WINAPI display_mode_callback(DDSURFACEDESC2 *lpddsd, void *lpContext)
+{
+    if (lpddsd->dwWidth == 640 && lpddsd->dwHeight == 480)
+    {
+        if (U1(lpddsd->ddpfPixelFormat).dwRGBBitCount == 8)
+            has_640x480x8 = 1;
+        else if (U1(lpddsd->ddpfPixelFormat).dwRGBBitCount == 32)
+            has_640x480x32 = 1;
+    }
+    else if (lpddsd->dwWidth == 800 && lpddsd->dwHeight == 600)
+    {
+        if (U1(lpddsd->ddpfPixelFormat).dwRGBBitCount == 32)
+            has_800x600x32 = 1;
+    }
+    return DDENUMRET_OK;
+}
+
+static void probe_display_modes(void)
+{
+    IDirectDraw7 *ddraw;
+    DDSURFACEDESC2 ddsd;
+    HRESULT hr;
+
+    if (!(ddraw = create_ddraw()))
+    {
+        skip("Failed to create a ddraw object, skipping the display modes probe.\n");
+        return;
+    }
+
+    ZeroMemory(&ddsd, sizeof(ddsd));
+    ddsd.dwSize = sizeof(ddsd);
+    ddsd.dwFlags = DDSD_CAPS;
+    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
+    hr = IDirectDraw7_EnumDisplayModes(ddraw, 0, &ddsd, NULL, display_mode_callback);
+    ok(hr == DD_OK, "EnumDisplayModes returned: %x\n",hr);
+
+    IDirectDraw7_Release(ddraw);
+}
+
 static void test_process_vertices(void)
 {
     IDirect3DVertexBuffer7 *src_vb, *dst_vb1, *dst_vb2;
@@ -2199,6 +2242,12 @@ static void test_coop_level_mode_set(void)
         0,
     };
 
+    if (!has_640x480x32)
+    {
+        skip("coop_level_mode_set (missing 640x480x32 mode)\n");
+        return;
+    }
+
     if (!(ddraw = create_ddraw()))
     {
         skip("Failed to create a ddraw object, skipping test.\n");
@@ -2719,6 +2768,12 @@ static void test_coop_level_mode_set_multi(void)
     HRESULT hr;
     ULONG ref;
 
+    if (!has_640x480x32 || !has_800x600x32)
+    {
+        skip("coop_level_mode_set_multi (missing 640x480x32 or 800x600x32 mode)\n");
+        return;
+    }
+
     if (!(ddraw1 = create_ddraw()))
     {
         skip("Failed to create a ddraw object, skipping test.\n");
@@ -3206,6 +3261,12 @@ static void test_coop_level_versions(void)
     IDirectDraw7 *ddraw7;
     DDSURFACEDESC ddsd;
 
+    if (!has_640x480x32)
+    {
+        skip("coop_level_versions (missing 640x480x32 mode)\n");
+        return;
+    }
+
     window = CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW,
             0, 0, 640, 480, 0, 0, 0, 0);
 
@@ -5004,6 +5065,12 @@ static void test_flip(void)
     DDBLTFX fx;
     HRESULT hr;
 
+    if (!has_640x480x32)
+    {
+        skip("flip (missing 640x480x32 mode)\n");
+        return;
+    }
+
     if (!(ddraw = create_ddraw()))
     {
         skip("Failed to create a ddraw object, skipping test.\n");
@@ -5641,6 +5708,12 @@ static void test_primary_palette(void)
     HWND window;
     HRESULT hr;
 
+    if (!has_640x480x8)
+    {
+        skip("primary_palette (missing 640x480x8 mode)\n");
+        return;
+    }
+
     if (!(ddraw = create_ddraw()))
     {
         skip("Failed to create a ddraw object, skipping test.\n");
@@ -6232,6 +6305,7 @@ START_TEST(ddraw7)
         return;
     }
 
+    probe_display_modes();
     test_process_vertices();
     test_coop_level_create_device_window();
     test_clipper_blt();
-- 
1.8.5.3




More information about the wine-patches mailing list