[PATCH] ddraw/tests: Add some color key tests for complex surfaces.

Henri Verbeet hverbeet at codeweavers.com
Thu Jan 9 06:49:32 CST 2014


This patch supersedes patch 101573.
---
 dlls/ddraw/tests/ddraw1.c |  141 +++++++++++++++++++++++++++++++++++++++++++++
 dlls/ddraw/tests/ddraw2.c |  141 +++++++++++++++++++++++++++++++++++++++++++++
 dlls/ddraw/tests/ddraw4.c |  140 ++++++++++++++++++++++++++++++++++++++++++++
 dlls/ddraw/tests/ddraw7.c |  125 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 547 insertions(+)

diff --git a/dlls/ddraw/tests/ddraw1.c b/dlls/ddraw/tests/ddraw1.c
index b295766..c7c227b 100644
--- a/dlls/ddraw/tests/ddraw1.c
+++ b/dlls/ddraw/tests/ddraw1.c
@@ -1519,6 +1519,146 @@ static void test_ck_default(void)
     DestroyWindow(window);
 }
 
+static void test_ck_complex(void)
+{
+    IDirectDrawSurface *surface, *mipmap, *tmp;
+    DDSCAPS caps = {DDSCAPS_COMPLEX};
+    DDSURFACEDESC surface_desc;
+    IDirect3DDevice *device;
+    DDCOLORKEY color_key;
+    IDirectDraw *ddraw;
+    unsigned int i;
+    ULONG refcount;
+    HWND window;
+    HRESULT hr;
+
+    if (!(ddraw = create_ddraw()))
+    {
+        skip("Failed to create a ddraw object, skipping test.\n");
+        return;
+    }
+
+    window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
+            0, 0, 640, 480, 0, 0, 0, 0);
+    if (!(device = create_device(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN)))
+    {
+        skip("Failed to create a 3D device, skipping test.\n");
+        DestroyWindow(window);
+        IDirectDraw2_Release(ddraw);
+        return;
+    }
+    IDirect3DDevice_Release(device);
+
+    memset(&surface_desc, 0, sizeof(surface_desc));
+    surface_desc.dwSize = sizeof(surface_desc);
+    surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
+    surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
+    surface_desc.dwWidth = 128;
+    surface_desc.dwHeight = 128;
+    hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
+    ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
+
+    hr = IDirectDrawSurface_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
+    ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
+    color_key.dwColorSpaceLowValue = 0x0000ff00;
+    color_key.dwColorSpaceHighValue = 0x0000ff00;
+    hr = IDirectDrawSurface_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
+    ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
+    memset(&color_key, 0, sizeof(color_key));
+    hr = IDirectDrawSurface_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
+    ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
+    ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
+            color_key.dwColorSpaceLowValue);
+    ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
+            color_key.dwColorSpaceHighValue);
+
+    mipmap = surface;
+    IDirectDrawSurface_AddRef(mipmap);
+    for (i = 0; i < 7; ++i)
+    {
+        hr = IDirectDrawSurface_GetAttachedSurface(mipmap, &caps, &tmp);
+        ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
+
+        hr = IDirectDrawSurface_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
+        ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
+        color_key.dwColorSpaceLowValue = 0x000000ff;
+        color_key.dwColorSpaceHighValue = 0x000000ff;
+        hr = IDirectDrawSurface_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
+        ok(SUCCEEDED(hr), "Failed to set color key, hr %#x, i %u.\n", hr, i);
+        memset(&color_key, 0, sizeof(color_key));
+        hr = IDirectDrawSurface_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
+        ok(SUCCEEDED(hr), "Failed to get color key, hr %#x, i %u.\n", hr, i);
+        ok(color_key.dwColorSpaceLowValue == 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
+                color_key.dwColorSpaceLowValue, i);
+        ok(color_key.dwColorSpaceHighValue == 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
+                color_key.dwColorSpaceHighValue, i);
+
+        IDirectDrawSurface_Release(mipmap);
+        mipmap = tmp;
+    }
+
+    memset(&color_key, 0, sizeof(color_key));
+    hr = IDirectDrawSurface_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
+    ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
+    ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
+            color_key.dwColorSpaceLowValue);
+    ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
+            color_key.dwColorSpaceHighValue);
+
+    hr = IDirectDrawSurface_GetAttachedSurface(mipmap, &caps, &tmp);
+    ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
+    IDirectDrawSurface_Release(mipmap);
+    refcount = IDirectDrawSurface_Release(surface);
+    ok(!refcount, "Got unexpected refcount %u.\n", refcount);
+
+    memset(&surface_desc, 0, sizeof(surface_desc));
+    surface_desc.dwSize = sizeof(surface_desc);
+    surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
+    surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
+    surface_desc.dwBackBufferCount = 1;
+    hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
+    ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
+
+    hr = IDirectDrawSurface_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
+    ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
+    color_key.dwColorSpaceLowValue = 0x0000ff00;
+    color_key.dwColorSpaceHighValue = 0x0000ff00;
+    hr = IDirectDrawSurface_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
+    ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
+    memset(&color_key, 0, sizeof(color_key));
+    hr = IDirectDrawSurface_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
+    ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
+    ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
+            color_key.dwColorSpaceLowValue);
+    ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
+            color_key.dwColorSpaceHighValue);
+
+    hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &tmp);
+    ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
+
+    hr = IDirectDrawSurface_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
+    ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
+    color_key.dwColorSpaceLowValue = 0x0000ff00;
+    color_key.dwColorSpaceHighValue = 0x0000ff00;
+    hr = IDirectDrawSurface_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
+    ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
+    memset(&color_key, 0, sizeof(color_key));
+    hr = IDirectDrawSurface_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
+    ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
+    ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
+            color_key.dwColorSpaceLowValue);
+    ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
+            color_key.dwColorSpaceHighValue);
+
+    IDirectDrawSurface_Release(tmp);
+
+    refcount = IDirectDrawSurface_Release(surface);
+    ok(!refcount, "Got unexpected refcount %u.\n", refcount);
+    refcount = IDirectDraw_Release(ddraw);
+    ok(!refcount, "Got unexpected refcount %u.\n", refcount);
+    DestroyWindow(window);
+}
+
 struct qi_test
 {
     REFIID iid;
@@ -4021,6 +4161,7 @@ START_TEST(ddraw1)
     test_zenable();
     test_ck_rgba();
     test_ck_default();
+    test_ck_complex();
     test_surface_qi();
     test_device_qi();
     test_wndproc();
diff --git a/dlls/ddraw/tests/ddraw2.c b/dlls/ddraw/tests/ddraw2.c
index 30c5b81..2a7b64f 100644
--- a/dlls/ddraw/tests/ddraw2.c
+++ b/dlls/ddraw/tests/ddraw2.c
@@ -1716,6 +1716,146 @@ static void test_ck_default(void)
     DestroyWindow(window);
 }
 
+static void test_ck_complex(void)
+{
+    IDirectDrawSurface *surface, *mipmap, *tmp;
+    DDSCAPS caps = {DDSCAPS_COMPLEX};
+    DDSURFACEDESC surface_desc;
+    IDirect3DDevice2 *device;
+    DDCOLORKEY color_key;
+    IDirectDraw2 *ddraw;
+    unsigned int i;
+    ULONG refcount;
+    HWND window;
+    HRESULT hr;
+
+    if (!(ddraw = create_ddraw()))
+    {
+        skip("Failed to create a ddraw object, skipping test.\n");
+        return;
+    }
+
+    window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
+            0, 0, 640, 480, 0, 0, 0, 0);
+    if (!(device = create_device(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN)))
+    {
+        skip("Failed to create a 3D device, skipping test.\n");
+        DestroyWindow(window);
+        IDirectDraw2_Release(ddraw);
+        return;
+    }
+    IDirect3DDevice2_Release(device);
+
+    memset(&surface_desc, 0, sizeof(surface_desc));
+    surface_desc.dwSize = sizeof(surface_desc);
+    surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
+    surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
+    surface_desc.dwWidth = 128;
+    surface_desc.dwHeight = 128;
+    hr = IDirectDraw2_CreateSurface(ddraw, &surface_desc, &surface, NULL);
+    ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
+
+    hr = IDirectDrawSurface_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
+    ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
+    color_key.dwColorSpaceLowValue = 0x0000ff00;
+    color_key.dwColorSpaceHighValue = 0x0000ff00;
+    hr = IDirectDrawSurface_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
+    ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
+    memset(&color_key, 0, sizeof(color_key));
+    hr = IDirectDrawSurface_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
+    ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
+    ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
+            color_key.dwColorSpaceLowValue);
+    ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
+            color_key.dwColorSpaceHighValue);
+
+    mipmap = surface;
+    IDirectDrawSurface_AddRef(mipmap);
+    for (i = 0; i < 7; ++i)
+    {
+        hr = IDirectDrawSurface_GetAttachedSurface(mipmap, &caps, &tmp);
+        ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
+
+        hr = IDirectDrawSurface_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
+        ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
+        color_key.dwColorSpaceLowValue = 0x000000ff;
+        color_key.dwColorSpaceHighValue = 0x000000ff;
+        hr = IDirectDrawSurface_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
+        ok(SUCCEEDED(hr), "Failed to set color key, hr %#x, i %u.\n", hr, i);
+        memset(&color_key, 0, sizeof(color_key));
+        hr = IDirectDrawSurface_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
+        ok(SUCCEEDED(hr), "Failed to get color key, hr %#x, i %u.\n", hr, i);
+        ok(color_key.dwColorSpaceLowValue == 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
+                color_key.dwColorSpaceLowValue, i);
+        ok(color_key.dwColorSpaceHighValue == 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
+                color_key.dwColorSpaceHighValue, i);
+
+        IDirectDrawSurface_Release(mipmap);
+        mipmap = tmp;
+    }
+
+    memset(&color_key, 0, sizeof(color_key));
+    hr = IDirectDrawSurface_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
+    ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
+    ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
+            color_key.dwColorSpaceLowValue);
+    ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
+            color_key.dwColorSpaceHighValue);
+
+    hr = IDirectDrawSurface_GetAttachedSurface(mipmap, &caps, &tmp);
+    ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
+    IDirectDrawSurface_Release(mipmap);
+    refcount = IDirectDrawSurface_Release(surface);
+    ok(!refcount, "Got unexpected refcount %u.\n", refcount);
+
+    memset(&surface_desc, 0, sizeof(surface_desc));
+    surface_desc.dwSize = sizeof(surface_desc);
+    surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
+    surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
+    surface_desc.dwBackBufferCount = 1;
+    hr = IDirectDraw2_CreateSurface(ddraw, &surface_desc, &surface, NULL);
+    ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
+
+    hr = IDirectDrawSurface_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
+    ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
+    color_key.dwColorSpaceLowValue = 0x0000ff00;
+    color_key.dwColorSpaceHighValue = 0x0000ff00;
+    hr = IDirectDrawSurface_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
+    ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
+    memset(&color_key, 0, sizeof(color_key));
+    hr = IDirectDrawSurface_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
+    ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
+    ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
+            color_key.dwColorSpaceLowValue);
+    ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
+            color_key.dwColorSpaceHighValue);
+
+    hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &tmp);
+    ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
+
+    hr = IDirectDrawSurface_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
+    ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
+    color_key.dwColorSpaceLowValue = 0x0000ff00;
+    color_key.dwColorSpaceHighValue = 0x0000ff00;
+    hr = IDirectDrawSurface_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
+    ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
+    memset(&color_key, 0, sizeof(color_key));
+    hr = IDirectDrawSurface_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
+    ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
+    ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
+            color_key.dwColorSpaceLowValue);
+    ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
+            color_key.dwColorSpaceHighValue);
+
+    IDirectDrawSurface_Release(tmp);
+
+    refcount = IDirectDrawSurface_Release(surface);
+    ok(!refcount, "Got unexpected refcount %u.\n", refcount);
+    refcount = IDirectDraw2_Release(ddraw);
+    ok(!refcount, "Got unexpected refcount %u.\n", refcount);
+    DestroyWindow(window);
+}
+
 struct qi_test
 {
     REFIID iid;
@@ -5120,6 +5260,7 @@ START_TEST(ddraw2)
     test_zenable();
     test_ck_rgba();
     test_ck_default();
+    test_ck_complex();
     test_surface_qi();
     test_device_qi();
     test_wndproc();
diff --git a/dlls/ddraw/tests/ddraw4.c b/dlls/ddraw/tests/ddraw4.c
index e737b42..589ff55 100644
--- a/dlls/ddraw/tests/ddraw4.c
+++ b/dlls/ddraw/tests/ddraw4.c
@@ -1848,6 +1848,145 @@ static void test_ck_default(void)
     DestroyWindow(window);
 }
 
+static void test_ck_complex(void)
+{
+    IDirectDrawSurface4 *surface, *mipmap, *tmp;
+    DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, 0};
+    DDSURFACEDESC2 surface_desc;
+    IDirect3DDevice3 *device;
+    DDCOLORKEY color_key;
+    IDirectDraw4 *ddraw;
+    IDirect3D3 *d3d;
+    unsigned int i;
+    ULONG refcount;
+    HWND window;
+    HRESULT hr;
+
+    window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
+            0, 0, 640, 480, 0, 0, 0, 0);
+    if (!(device = create_device(window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN)))
+    {
+        skip("Failed to create a 3D device, skipping test.\n");
+        DestroyWindow(window);
+        return;
+    }
+    hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
+    ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
+    hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
+    ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
+    IDirect3D3_Release(d3d);
+
+    memset(&surface_desc, 0, sizeof(surface_desc));
+    surface_desc.dwSize = sizeof(surface_desc);
+    surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
+    surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
+    surface_desc.dwWidth = 128;
+    surface_desc.dwHeight = 128;
+    hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
+    ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
+
+    hr = IDirectDrawSurface4_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
+    ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
+    color_key.dwColorSpaceLowValue = 0x0000ff00;
+    color_key.dwColorSpaceHighValue = 0x0000ff00;
+    hr = IDirectDrawSurface4_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
+    ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
+    memset(&color_key, 0, sizeof(color_key));
+    hr = IDirectDrawSurface4_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
+    ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
+    ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
+            color_key.dwColorSpaceLowValue);
+    ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
+            color_key.dwColorSpaceHighValue);
+
+    mipmap = surface;
+    IDirectDrawSurface_AddRef(mipmap);
+    for (i = 0; i < 7; ++i)
+    {
+        hr = IDirectDrawSurface4_GetAttachedSurface(mipmap, &caps, &tmp);
+        ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
+
+        hr = IDirectDrawSurface4_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
+        ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
+        color_key.dwColorSpaceLowValue = 0x000000ff;
+        color_key.dwColorSpaceHighValue = 0x000000ff;
+        hr = IDirectDrawSurface4_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
+        ok(SUCCEEDED(hr), "Failed to set color key, hr %#x, i %u.\n", hr, i);
+        memset(&color_key, 0, sizeof(color_key));
+        hr = IDirectDrawSurface4_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
+        ok(SUCCEEDED(hr), "Failed to get color key, hr %#x, i %u.\n", hr, i);
+        ok(color_key.dwColorSpaceLowValue == 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
+                color_key.dwColorSpaceLowValue, i);
+        ok(color_key.dwColorSpaceHighValue == 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
+                color_key.dwColorSpaceHighValue, i);
+
+        IDirectDrawSurface_Release(mipmap);
+        mipmap = tmp;
+    }
+
+    memset(&color_key, 0, sizeof(color_key));
+    hr = IDirectDrawSurface4_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
+    ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
+    ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
+            color_key.dwColorSpaceLowValue);
+    ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
+            color_key.dwColorSpaceHighValue);
+
+    hr = IDirectDrawSurface4_GetAttachedSurface(mipmap, &caps, &tmp);
+    ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
+    IDirectDrawSurface_Release(mipmap);
+    refcount = IDirectDrawSurface4_Release(surface);
+    ok(!refcount, "Got unexpected refcount %u.\n", refcount);
+
+    memset(&surface_desc, 0, sizeof(surface_desc));
+    surface_desc.dwSize = sizeof(surface_desc);
+    surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
+    surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
+    surface_desc.dwBackBufferCount = 1;
+    hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
+    ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
+
+    hr = IDirectDrawSurface4_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
+    ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
+    color_key.dwColorSpaceLowValue = 0x0000ff00;
+    color_key.dwColorSpaceHighValue = 0x0000ff00;
+    hr = IDirectDrawSurface4_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
+    ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
+    memset(&color_key, 0, sizeof(color_key));
+    hr = IDirectDrawSurface4_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
+    ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
+    ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
+            color_key.dwColorSpaceLowValue);
+    ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
+            color_key.dwColorSpaceHighValue);
+
+    hr = IDirectDrawSurface4_GetAttachedSurface(surface, &caps, &tmp);
+    ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
+
+    hr = IDirectDrawSurface4_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
+    ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
+    color_key.dwColorSpaceLowValue = 0x0000ff00;
+    color_key.dwColorSpaceHighValue = 0x0000ff00;
+    hr = IDirectDrawSurface4_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
+    ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
+    memset(&color_key, 0, sizeof(color_key));
+    hr = IDirectDrawSurface4_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
+    ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
+    ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
+            color_key.dwColorSpaceLowValue);
+    ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
+            color_key.dwColorSpaceHighValue);
+
+    IDirectDrawSurface_Release(tmp);
+
+    refcount = IDirectDrawSurface4_Release(surface);
+    ok(!refcount, "Got unexpected refcount %u.\n", refcount);
+    IDirectDraw4_Release(ddraw);
+    refcount = IDirect3DDevice3_Release(device);
+    ok(!refcount, "Got unexpected refcount %u.\n", refcount);
+    DestroyWindow(window);
+}
+
 struct qi_test
 {
     REFIID iid;
@@ -5718,6 +5857,7 @@ START_TEST(ddraw4)
     test_zenable();
     test_ck_rgba();
     test_ck_default();
+    test_ck_complex();
     test_surface_qi();
     test_device_qi();
     test_wndproc();
diff --git a/dlls/ddraw/tests/ddraw7.c b/dlls/ddraw/tests/ddraw7.c
index f8fa70f..bcec1fd 100644
--- a/dlls/ddraw/tests/ddraw7.c
+++ b/dlls/ddraw/tests/ddraw7.c
@@ -1588,6 +1588,130 @@ static void test_ck_default(void)
     DestroyWindow(window);
 }
 
+static void test_ck_complex(void)
+{
+    IDirectDrawSurface7 *surface, *mipmap, *tmp;
+    DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, 0};
+    DDSURFACEDESC2 surface_desc;
+    IDirect3DDevice7 *device;
+    DDCOLORKEY color_key;
+    IDirectDraw7 *ddraw;
+    IDirect3D7 *d3d;
+    unsigned int i;
+    ULONG refcount;
+    HWND window;
+    HRESULT hr;
+
+    window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
+            0, 0, 640, 480, 0, 0, 0, 0);
+    if (!(device = create_device(window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN)))
+    {
+        skip("Failed to create a 3D device, skipping test.\n");
+        DestroyWindow(window);
+        return;
+    }
+    hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
+    ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
+    hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
+    ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
+    IDirect3D7_Release(d3d);
+
+    memset(&surface_desc, 0, sizeof(surface_desc));
+    surface_desc.dwSize = sizeof(surface_desc);
+    surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
+    surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
+    surface_desc.dwWidth = 128;
+    surface_desc.dwHeight = 128;
+    hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
+    ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
+
+    hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
+    ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
+    color_key.dwColorSpaceLowValue = 0x0000ff00;
+    color_key.dwColorSpaceHighValue = 0x0000ff00;
+    hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
+    ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
+    memset(&color_key, 0, sizeof(color_key));
+    hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
+    ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
+    ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
+            color_key.dwColorSpaceLowValue);
+    ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
+            color_key.dwColorSpaceHighValue);
+
+    mipmap = surface;
+    IDirectDrawSurface_AddRef(mipmap);
+    for (i = 0; i < 7; ++i)
+    {
+        hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
+        ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
+        hr = IDirectDrawSurface7_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
+        ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
+
+        color_key.dwColorSpaceLowValue = 0x000000ff;
+        color_key.dwColorSpaceHighValue = 0x000000ff;
+        hr = IDirectDrawSurface7_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
+        ok(hr == DDERR_NOTONMIPMAPSUBLEVEL, "Got unexpected hr %#x, i %u.\n", hr, i);
+
+        IDirectDrawSurface_Release(mipmap);
+        mipmap = tmp;
+    }
+
+    hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
+    ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
+    IDirectDrawSurface_Release(mipmap);
+    refcount = IDirectDrawSurface7_Release(surface);
+    ok(!refcount, "Got unexpected refcount %u.\n", refcount);
+
+    memset(&surface_desc, 0, sizeof(surface_desc));
+    surface_desc.dwSize = sizeof(surface_desc);
+    surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
+    surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
+    surface_desc.dwBackBufferCount = 1;
+    hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
+    ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
+
+    hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
+    ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
+    color_key.dwColorSpaceLowValue = 0x0000ff00;
+    color_key.dwColorSpaceHighValue = 0x0000ff00;
+    hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
+    ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
+    memset(&color_key, 0, sizeof(color_key));
+    hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
+    ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
+    ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
+            color_key.dwColorSpaceLowValue);
+    ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
+            color_key.dwColorSpaceHighValue);
+
+    hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &tmp);
+    ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
+
+    hr = IDirectDrawSurface7_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
+    ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
+    color_key.dwColorSpaceLowValue = 0x0000ff00;
+    color_key.dwColorSpaceHighValue = 0x0000ff00;
+    hr = IDirectDrawSurface7_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
+    ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
+    memset(&color_key, 0, sizeof(color_key));
+    hr = IDirectDrawSurface7_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
+    ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
+    ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
+            color_key.dwColorSpaceLowValue);
+    ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
+            color_key.dwColorSpaceHighValue);
+
+    IDirectDrawSurface_Release(tmp);
+
+    refcount = IDirectDrawSurface7_Release(surface);
+    ok(!refcount, "Got unexpected refcount %u.\n", refcount);
+    IDirectDraw7_Release(ddraw);
+    refcount = IDirect3DDevice7_Release(device);
+    ok(!refcount, "Got unexpected refcount %u.\n", refcount);
+    DestroyWindow(window);
+}
+
 struct qi_test
 {
     REFIID iid;
@@ -5619,6 +5743,7 @@ START_TEST(ddraw7)
     test_zenable();
     test_ck_rgba();
     test_ck_default();
+    test_ck_complex();
     test_surface_qi();
     test_device_qi();
     test_wndproc();
-- 
1.7.10.4




More information about the wine-patches mailing list