From 7e5407dd53a6bf894dd62a920a6f94cc9935f7a1 Mon Sep 17 00:00:00 2001
From: Jim Cameron <jim_24601@btinternet.com>
Date: Thu, 9 Oct 2008 22:11:41 +0100
Subject: Test for depth-stencil surface deletion

---
 dlls/d3d9/tests/device.c |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/dlls/d3d9/tests/device.c b/dlls/d3d9/tests/device.c
index d28da88..6d47306 100644
--- a/dlls/d3d9/tests/device.c
+++ b/dlls/d3d9/tests/device.c
@@ -1493,6 +1493,21 @@ static void test_depthstenciltest(void)
     ok(hr == D3D_OK, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr);
     ok(state == D3DZB_FALSE, "D3DRS_ZENABLE is %s\n", state == D3DZB_FALSE ? "D3DZB_FALSE" : (state == D3DZB_TRUE ? "D3DZB_TRUE" : "D3DZB_USEW"));
 
+    /* Test if a user-supplied depth-stencil surface survives being selected and then released. */
+    hr = IDirect3DDevice9_CreateDepthStencilSurface
+        (pDevice, d3dpp.BackBufferWidth, d3dpp.BackBufferHeight,
+         d3dpp.AutoDepthStencilFormat, D3DMULTISAMPLE_NONE, 0, FALSE,
+         &pDepthStencil, NULL);
+    ok(hr == D3D_OK && pDepthStencil != NULL, "IDirect3DDevice9_CreateDepthStencilSurface failed with %08x\n", hr);
+    hr = IDirect3DDevice9_SetDepthStencilSurface(pDevice, pDepthStencil);
+    ok(hr == D3D_OK, "IDirect3DDevice9_SetDepthStencilSurface failed with %08x\n", hr);
+    /* Surface should remain valid, but with refcount of zero */
+    CHECK_RELEASE_REFCOUNT(pDepthStencil, 0);
+    CHECK_ADDREF_REFCOUNT(pDepthStencil, 1);
+    /* Select it back out so it's deleted cleanly */
+    hr = IDirect3DDevice9_SetDepthStencilSurface(pDevice, NULL);
+    ok(hr == D3D_OK, "IDirect3DDevice9_SetDepthStencilSurface failed with %08x\n", hr);
+
 cleanup:
     if(pDepthStencil) IDirect3DSurface9_Release(pDepthStencil);
     if(pD3d) IDirect3D9_Release(pD3d);
-- 
1.5.4.3

