[d3d] Light management API test cases

Antoine Chavasse a.chavasse at gmail.com
Sun Jun 5 13:09:17 CDT 2005


ChangeLog
 - Test cases for the direct3d7 light api.

Index: dlls/ddraw/tests/.cvsignore
===================================================================
RCS file: /home/wine/wine/dlls/ddraw/tests/.cvsignore,v
retrieving revision 1.3
diff -u -p -r1.3 .cvsignore
--- dlls/ddraw/tests/.cvsignore	30 May 2005 11:11:34 -0000	1.3
+++ dlls/ddraw/tests/.cvsignore	5 Jun 2005 17:38:39 -0000
@@ -1,4 +1,5 @@
 Makefile
 ddrawmodes.ok
 dsurface.ok
+d3d7light.ok
 testlist.c
Index: dlls/ddraw/tests/Makefile.in
===================================================================
RCS file: /home/wine/wine/dlls/ddraw/tests/Makefile.in,v
retrieving revision 1.4
diff -u -p -r1.4 Makefile.in
--- dlls/ddraw/tests/Makefile.in	30 May 2005 11:11:34 -0000	1.4
+++ dlls/ddraw/tests/Makefile.in	5 Jun 2005 17:38:39 -0000
@@ -3,11 +3,12 @@ TOPOBJDIR = ../../..
 SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 TESTDLL   = ddraw.dll
-IMPORTS   = ddraw user32 gdi32 kernel32
+IMPORTS   = ddraw dxguid user32 gdi32 kernel32
 
 CTESTS = \
 	ddrawmodes.c \
-	dsurface.c
+	dsurface.c \
+	d3d7light.c
 
 @MAKE_TEST_RULES@
 
--- /dev/null	1970-01-01 01:00:00.000000000 +0100
+++ dlls/ddraw/tests/d3d7light.c	2005-06-05 16:08:56.526165080 +0200
@@ -0,0 +1,185 @@
+/*
+ * Some unit tests for direct3d7 light functions
+ *
+ * Copyright (C) 2005 Antoine Chavasse (a.chavasse at gmail.com)
+ *
+ * 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
+ */
+
+#include <assert.h>
+#include "wine/test.h"
+#include "ddraw.h"
+#include "d3d.h"
+
+static LPDIRECTDRAW7        lpDD = NULL;
+static LPDIRECT3D7          lpD3D = NULL;
+static LPDIRECTDRAWSURFACE7 lpDDS = NULL;
+static LPDIRECT3DDEVICE7    lpD3DDevice = NULL;
+
+static void CreateDirect3D()
+{
+    HRESULT rc;
+    DDSURFACEDESC2 ddsd;
+
+    rc = DirectDrawCreateEx(NULL, (void**)&lpDD,
+        &IID_IDirectDraw7, NULL);
+    ok(rc==DD_OK, "DirectDrawCreateEx returned: %lx\n", rc);
+
+    rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
+    ok(rc==DD_OK, "SetCooperativeLevel returned: %lx\n", rc);
+
+    rc = IDirectDraw7_QueryInterface(lpDD, &IID_IDirect3D7, (void**) &lpD3D);
+    ok(rc==DD_OK, "QueryInterface returned: %lx\n", rc);
+
+    memset(&ddsd, 0, sizeof(ddsd));
+    ddsd.dwSize = sizeof(ddsd);
+    ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
+    ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
+    ddsd.dwWidth = 256;
+    ddsd.dwHeight = 256;
+    rc = IDirectDraw7_CreateSurface(lpDD, &ddsd, &lpDDS, NULL);
+    ok(rc==DD_OK, "CreateSurface returned: %lx\n", rc);
+
+    rc = IDirect3D7_CreateDevice(lpD3D, &IID_IDirect3DTnLHalDevice, lpDDS,
+        &lpD3DDevice);
+    ok(rc==D3D_OK, "CreateDevice returned: %lx\n", rc);
+}
+
+static void ReleaseDirect3D()
+{
+    if (lpD3DDevice != NULL)
+    {
+        IDirect3DDevice7_Release(lpD3DDevice);
+        lpD3DDevice = NULL;
+    }
+
+    if (lpDDS != NULL)
+    {
+        IDirectDrawSurface_Release(lpDDS);
+        lpDDS = NULL;
+    }
+
+    if (lpD3D != NULL)
+    {
+        IDirect3D7_Release(lpD3D);
+        lpD3D = NULL;
+    }
+
+    if (lpDD != NULL)
+    {
+        IDirectDraw_Release(lpDD);
+        lpDD = NULL;
+    }
+}
+
+static void LightTest()
+{
+    HRESULT rc;
+    D3DLIGHT7 light;
+    D3DLIGHT7 defaultlight;
+    BOOL bEnabled = FALSE;
+
+
+    /* Set a few lights with funky indices. */
+    memset(&light, 0, sizeof(light));
+    light.dltType = D3DLIGHT_DIRECTIONAL;
+    light.dcvDiffuse.r = 0.5f;
+    light.dcvDiffuse.g = 0.6f;
+    light.dcvDiffuse.b = 0.7f;
+    light.dvDirection.y = 1.f;
+
+    rc = IDirect3DDevice7_SetLight(lpD3DDevice, 5, &light);
+    ok(rc==D3D_OK, "SetLight returned: %lx\n", rc);
+    rc = IDirect3DDevice7_SetLight(lpD3DDevice, 10, &light);
+    ok(rc==D3D_OK, "SetLight returned: %lx\n", rc);
+    rc = IDirect3DDevice7_SetLight(lpD3DDevice, 45, &light);
+    ok(rc==D3D_OK, "SetLight returned: %lx\n", rc);
+
+
+    /* Try to retrieve a light beyond the indices of the lights that have
+       been set. */
+    rc = IDirect3DDevice7_GetLight(lpD3DDevice, 50, &light);
+    ok(rc==DDERR_INVALIDPARAMS, "GetLight returned: %lx\n", rc);
+    rc = IDirect3DDevice7_GetLight(lpD3DDevice, 2, &light);
+    ok(rc==DDERR_INVALIDPARAMS, "GetLight returned: %lx\n", rc);
+
+
+    /* Try to retrieve one of the lights that have been set */
+    rc = IDirect3DDevice7_GetLight(lpD3DDevice, 10, &light);
+    ok(rc==D3D_OK, "GetLight returned: %lx\n", rc);
+
+
+    /* Enable a light that have been previously set. */
+    rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 10, TRUE);
+    ok(rc==D3D_OK, "LightEnable returned: %lx\n", rc);
+
+
+    /* Enable some lights that have not been previously set, and verify that
+       they have been initialized with proper default values. */
+    memset(&defaultlight, 0, sizeof(D3DLIGHT7));
+    defaultlight.dltType = D3DLIGHT_DIRECTIONAL;
+    defaultlight.dcvDiffuse.r = 1.f;
+    defaultlight.dcvDiffuse.g = 1.f;
+    defaultlight.dcvDiffuse.b = 1.f;
+    defaultlight.dvDirection.z = 1.f;
+
+    rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 20, TRUE);
+    ok(rc==D3D_OK, "LightEnable returned: %lx\n", rc);
+    memset(&light, 0, sizeof(D3DLIGHT7));
+    rc = IDirect3DDevice7_GetLight(lpD3DDevice, 20, &light);
+    ok(rc==D3D_OK, "GetLight returned: %lx\n", rc);
+    ok(!memcmp(&light, &defaultlight, sizeof(D3DLIGHT7)),
+        "light data doesn't match expected default values\n" );
+
+    rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 50, TRUE);
+    ok(rc==D3D_OK, "LightEnable returned: %lx\n", rc);
+    memset(&light, 0, sizeof(D3DLIGHT7));
+    rc = IDirect3DDevice7_GetLight(lpD3DDevice, 50, &light);
+    ok(rc==D3D_OK, "GetLight returned: %lx\n", rc);
+    ok(!memcmp(&light, &defaultlight, sizeof(D3DLIGHT7)),
+        "light data doesn't match expected default values\n" );
+
+
+    /* Disable one of the light that have been previously enabled. */
+    rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 20, FALSE);
+    ok(rc==D3D_OK, "LightEnable returned: %lx\n", rc);
+
+    /* Try to retrieve the enable status of some lights */
+    /* Light 20 is supposed to be disabled */
+    rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 20, &bEnabled );
+    ok(rc==D3D_OK, "GetLightEnable returned: %lx\n", rc);
+    ok(!bEnabled, "GetLightEnable says the light is enabled\n");
+
+    /* Light 10 is supposed to be enabled */
+    bEnabled = FALSE;
+    rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 10, &bEnabled );
+    ok(rc==D3D_OK, "GetLightEnable returned: %lx\n", rc);
+    ok(bEnabled, "GetLightEnable says the light is disabled\n");
+
+    /* Light 80 has not been set */
+    rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 80, &bEnabled );
+    ok(rc==DDERR_INVALIDPARAMS, "GetLightEnable returned: %lx\n", rc);
+
+    /* Light 23 has not been set */
+    rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 23, &bEnabled );
+    ok(rc==DDERR_INVALIDPARAMS, "GetLightEnable returned: %lx\n", rc);
+}
+
+START_TEST(d3d7light)
+{
+    CreateDirect3D();
+    LightTest();
+    ReleaseDirect3D();
+}




More information about the wine-patches mailing list