D3D9: Add a test for IDirect3DDevice9_CreateOffscreenPlainSurface & IDirect3DSurface9_GetContainer

H. Verbeet hverbeet at gmail.com
Tue Dec 20 15:22:38 CST 2005


Verified on win2k, DirectX 9.0c.

Changelog:
  - Add a test for IDirect3DDevice9_CreateOffscreenPlainSurface &
IDirect3DSurface9_GetContainer.
-------------- next part --------------
diff --git a/dlls/d3d9/tests/Makefile.in b/dlls/d3d9/tests/Makefile.in
index d27d091..b56055d 100644
--- a/dlls/d3d9/tests/Makefile.in
+++ b/dlls/d3d9/tests/Makefile.in
@@ -3,11 +3,12 @@ TOPOBJDIR = ../../..
 SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 TESTDLL   = d3d9.dll
-IMPORTS   = user32 kernel32
+IMPORTS   = user32 uuid kernel32
 
 CTESTS = \
 	shader.c \
 	stateblock.c \
+	surface.c \
 	vertexdeclaration.c
 
 @MAKE_TEST_RULES@
diff --git a/dlls/d3d9/tests/surface.c b/dlls/d3d9/tests/surface.c
new file mode 100644
index 0000000..da89575
--- /dev/null
+++ b/dlls/d3d9/tests/surface.c
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2005 Henri Verbeet
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#define COBJMACROS
+#include <d3d9.h>
+#include "wine/test.h"
+
+static IDirect3DDevice9 *init_d3d9(HMODULE d3d9_handle)
+{
+    IDirect3D9 * (__stdcall * d3d9_create)(UINT SDKVersion) = 0;
+    IDirect3D9 *d3d9_ptr = 0;
+    IDirect3DDevice9 *device_ptr = 0;
+    D3DPRESENT_PARAMETERS present_parameters;
+    HRESULT hres;
+
+    d3d9_create = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9");
+    ok(d3d9_create != NULL, "Failed to get address of Direct3DCreate9\n");
+    if (!d3d9_create) return NULL;
+    
+    d3d9_ptr = d3d9_create(D3D_SDK_VERSION);
+    ok(d3d9_ptr != NULL, "Failed to create IDirect3D9 object\n");
+    if (!d3d9_ptr) return NULL;
+
+    ZeroMemory(&present_parameters, sizeof(present_parameters));
+    present_parameters.Windowed = TRUE;
+    present_parameters.hDeviceWindow = GetDesktopWindow();
+    present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
+
+    hres = IDirect3D9_CreateDevice(d3d9_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device_ptr);
+    ok(hres == D3D_OK, "IDirect3D_CreateDevice returned: 0x%lx\n", hres);
+
+    return device_ptr;
+}
+
+static int get_refcount(IUnknown *object)
+{
+    IUnknown_AddRef(object);
+    return IUnknown_Release(object);
+}
+
+static IDirect3DSurface9 *test_surface_create(IDirect3DDevice9 *device_ptr)
+{
+    IDirect3DSurface9 *surface_ptr = 0;
+    HRESULT hret;
+    int device_refcount = 0;
+    int i = 0;
+    
+    i = get_refcount((IUnknown *)device_ptr) + 1;
+    hret = IDirect3DDevice9_CreateOffscreenPlainSurface(device_ptr, 128, 128, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surface_ptr, NULL);
+    device_refcount = get_refcount((IUnknown *)device_ptr);
+    ok(hret == D3D_OK && surface_ptr != NULL && device_refcount == i, "CreateOffscreenPlainSurface returned: hret 0x%lx, surface_ptr %p, device_refcount %d. "
+        "Expected: hret 0x%lx, surface_ptr != %p, device_refcount %d.\n", hret, surface_ptr, device_refcount, D3D_OK, NULL, i);
+    
+    return surface_ptr;
+}
+
+static void test_surface_get_container(IDirect3DDevice9 *device_ptr, IDirect3DSurface9 *surface_ptr)
+{
+    void *container_ptr = 0;
+    HRESULT hret;
+    int device_refcount = 0, surface_refcount = 0;
+    int i = 0, j = 0;
+    
+    i = get_refcount((IUnknown *)device_ptr) + 1;
+    j = get_refcount((IUnknown *)surface_ptr);
+    hret = IDirect3DSurface9_GetContainer(surface_ptr, &IID_IUnknown, &container_ptr);
+    device_refcount = get_refcount((IUnknown *)device_ptr);
+    surface_refcount = get_refcount((IUnknown *)surface_ptr);
+    ok(hret == D3D_OK && container_ptr == device_ptr && device_refcount == i && surface_refcount == j,
+        "GetContainer returned: hret 0x%lx, surface_ptr %p, device_refcount %d, surface_refcount %d. "
+        "Expected: hret 0x%lx, surface_ptr %p, device_refcount %d, surface_refcount %d.\n", 
+        hret, surface_ptr, device_refcount, surface_refcount, D3D_OK, device_ptr, i, j);
+}
+
+START_TEST(surface)
+{
+    HMODULE d3d9_handle = 0;
+    IDirect3DDevice9 *device_ptr = 0;
+    IDirect3DSurface9 *surface_ptr = 0;
+
+    d3d9_handle = LoadLibraryA("d3d9.dll");
+    if (!d3d9_handle)
+    {
+        trace("Could not load d3d9.dll, skipping tests\n");
+        return;
+    }
+
+    device_ptr = init_d3d9(d3d9_handle);
+    if (!device_ptr) return;
+    
+    surface_ptr = test_surface_create(device_ptr);
+    if (!surface_ptr) return;
+    
+    test_surface_get_container(device_ptr, surface_ptr);
+}
+


More information about the wine-patches mailing list