D3D9: Add a refcount test for textures.

H. Verbeet hverbeet at gmail.com
Tue Dec 20 15:23:10 CST 2005


Verified on win2k, DirectX 9.0c.

Changelog:
  - Add a refcount test for textures.
-------------- next part --------------
diff --git a/dlls/d3d9/tests/Makefile.in b/dlls/d3d9/tests/Makefile.in
index b56055d..68d281d 100644
--- a/dlls/d3d9/tests/Makefile.in
+++ b/dlls/d3d9/tests/Makefile.in
@@ -9,6 +9,7 @@ CTESTS = \
 	shader.c \
 	stateblock.c \
 	surface.c \
+	texture.c \
 	vertexdeclaration.c
 
 @MAKE_TEST_RULES@
diff --git a/dlls/d3d9/tests/texture.c b/dlls/d3d9/tests/texture.c
new file mode 100644
index 0000000..8527632
--- /dev/null
+++ b/dlls/d3d9/tests/texture.c
@@ -0,0 +1,133 @@
+/*
+ * 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 IDirect3DTexture9 *test_texture_create(IDirect3DDevice9 *device_ptr)
+{
+    int i = 0;
+    int device_refcount = 0;
+    IDirect3DTexture9 *texture_ptr = 0;
+    HRESULT hret;
+    
+    i = get_refcount((IUnknown *)device_ptr) + 1;
+    hret = IDirect3DDevice9_CreateTexture(device_ptr, 128, 128, 1, 0,  D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture_ptr, NULL);
+    device_refcount = get_refcount((IUnknown *)device_ptr);
+    ok(hret == D3D_OK && texture_ptr != NULL && device_refcount == i, "CreateTexture returned: hret 0x%lx, texture_ptr %p, device_refcount %d. "
+        "Expected: hret 0x%lx, texture_ptr != %p, device_refcount %d.\n", hret, texture_ptr, device_refcount, D3D_OK, NULL, i);
+
+    return texture_ptr;
+}
+
+static IDirect3DSurface9 *test_texture_get_surface_level(IDirect3DDevice9 *device_ptr, IDirect3DTexture9 *texture_ptr)
+{
+    int i = 0, j = 0;
+    int device_refcount = 0, texture_refcount = 0;
+    IDirect3DSurface9 *surface_ptr = 0;
+    HRESULT hret;
+    
+    i = get_refcount((IUnknown *)device_ptr);
+    j = get_refcount((IUnknown *)texture_ptr) + 1;
+    hret = IDirect3DTexture9_GetSurfaceLevel(texture_ptr, 0, &surface_ptr);
+    device_refcount = get_refcount((IUnknown *)device_ptr);
+    texture_refcount = get_refcount((IUnknown *)texture_ptr);
+    ok(hret == D3D_OK && surface_ptr != NULL && device_refcount == i && texture_refcount == j, 
+        "GetSurfaceLevel returned: hret 0x%lx, surface_ptr %p, device_refcount %d, texture_refcount %d. "
+        "Expected: hret 0x%lx, surface_ptr != %p, device_refcount %d, texture_refcount %d.\n", hret, surface_ptr, device_refcount, texture_refcount, D3D_OK, NULL, i, j);
+
+    return surface_ptr;
+}
+
+static void test_texture_surface_get_container(IDirect3DDevice9 *device_ptr, IDirect3DTexture9 *texture_ptr, IDirect3DSurface9 *surface_ptr)
+{
+    int i = 0, j = 0;
+    int device_refcount = 0, texture_refcount = 0;
+    void *container_ptr = 0;
+    HRESULT hret;
+    
+    i = get_refcount((IUnknown *)device_ptr);
+    j = get_refcount((IUnknown *)texture_ptr) + 1;
+    hret = IDirect3DSurface9_GetContainer(surface_ptr, &IID_IUnknown, &container_ptr);
+    device_refcount = get_refcount((IUnknown *)device_ptr);
+    texture_refcount = get_refcount((IUnknown *)texture_ptr);
+    ok(hret == D3D_OK && container_ptr == texture_ptr && device_refcount == i && texture_refcount == j, 
+        "GetContainer returned: hret 0x%lx, container_ptr %p, device_refcount %d, texture_refcount %d. "
+        "Expected: hret 0x%lx, container_ptr %p, device_refcount %d, texture_refcount %d.\n", 
+        hret, container_ptr, device_refcount, texture_refcount, D3D_OK, texture_ptr, i, j);
+}
+
+START_TEST(texture)
+{
+    HMODULE d3d9_handle = 0;
+    IDirect3DDevice9 *device_ptr = 0;
+    IDirect3DTexture9 *texture_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;
+
+    texture_ptr = test_texture_create(device_ptr);
+    if (!texture_ptr) return;
+
+    surface_ptr = test_texture_get_surface_level(device_ptr, texture_ptr);
+    if (!surface_ptr) return;
+
+    test_texture_surface_get_container(device_ptr, texture_ptr, surface_ptr);
+}



More information about the wine-patches mailing list