Implement asn.1 encoding/decoding of times, with tests.
[wine] / dlls / ddraw / tests / d3d.c
1 /*
2  * Some unit tests for d3d functions
3  *
4  * Copyright (C) 2005 Antoine Chavasse
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include <assert.h>
22 #include "wine/test.h"
23 #include "ddraw.h"
24 #include "d3d.h"
25
26 #ifdef NONAMELESSUNION
27 # define U(x)  (x).u
28 # define U1(x) (x).u1
29 # define U2(x) (x).u2
30 # define U3(x) (x).u3
31 #else
32 # define U(x)  (x)
33 # define U1(x) (x)
34 # define U2(x) (x)
35 # define U3(x) (x)
36 #endif
37
38 static LPDIRECTDRAW7        lpDD = NULL;
39 static LPDIRECT3D7          lpD3D = NULL;
40 static LPDIRECTDRAWSURFACE7 lpDDS = NULL;
41 static LPDIRECT3DDEVICE7    lpD3DDevice = NULL;
42
43 static void CreateDirect3D()
44 {
45     HRESULT rc;
46     DDSURFACEDESC2 ddsd;
47
48     rc = DirectDrawCreateEx(NULL, (void**)&lpDD,
49         &IID_IDirectDraw7, NULL);
50     ok(rc==DD_OK, "DirectDrawCreateEx returned: %lx\n", rc);
51
52     rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
53     ok(rc==DD_OK, "SetCooperativeLevel returned: %lx\n", rc);
54
55     rc = IDirectDraw7_QueryInterface(lpDD, &IID_IDirect3D7, (void**) &lpD3D);
56     ok(rc==DD_OK, "QueryInterface returned: %lx\n", rc);
57
58     memset(&ddsd, 0, sizeof(ddsd));
59     ddsd.dwSize = sizeof(ddsd);
60     ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
61     ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
62     ddsd.dwWidth = 256;
63     ddsd.dwHeight = 256;
64     rc = IDirectDraw7_CreateSurface(lpDD, &ddsd, &lpDDS, NULL);
65     ok(rc==DD_OK, "CreateSurface returned: %lx\n", rc);
66
67     rc = IDirect3D7_CreateDevice(lpD3D, &IID_IDirect3DTnLHalDevice, lpDDS,
68         &lpD3DDevice);
69     ok(rc==D3D_OK, "CreateDevice returned: %lx\n", rc);
70 }
71
72 static void ReleaseDirect3D()
73 {
74     if (lpD3DDevice != NULL)
75     {
76         IDirect3DDevice7_Release(lpD3DDevice);
77         lpD3DDevice = NULL;
78     }
79
80     if (lpDDS != NULL)
81     {
82         IDirectDrawSurface_Release(lpDDS);
83         lpDDS = NULL;
84     }
85
86     if (lpD3D != NULL)
87     {
88         IDirect3D7_Release(lpD3D);
89         lpD3D = NULL;
90     }
91
92     if (lpDD != NULL)
93     {
94         IDirectDraw_Release(lpDD);
95         lpDD = NULL;
96     }
97 }
98
99 static void LightTest()
100 {
101     HRESULT rc;
102     D3DLIGHT7 light;
103     D3DLIGHT7 defaultlight;
104     BOOL bEnabled = FALSE;
105
106     /* Set a few lights with funky indices. */
107     memset(&light, 0, sizeof(light));
108     light.dltType = D3DLIGHT_DIRECTIONAL;
109     U1(light.dcvDiffuse).r = 0.5f;
110     U2(light.dcvDiffuse).g = 0.6f;
111     U3(light.dcvDiffuse).b = 0.7f;
112     U2(light.dvDirection).y = 1.f;
113
114     rc = IDirect3DDevice7_SetLight(lpD3DDevice, 5, &light);
115     ok(rc==D3D_OK, "SetLight returned: %lx\n", rc);
116     rc = IDirect3DDevice7_SetLight(lpD3DDevice, 10, &light);
117     ok(rc==D3D_OK, "SetLight returned: %lx\n", rc);
118     rc = IDirect3DDevice7_SetLight(lpD3DDevice, 45, &light);
119     ok(rc==D3D_OK, "SetLight returned: %lx\n", rc);
120
121
122     /* Try to retrieve a light beyond the indices of the lights that have
123        been set. */
124     rc = IDirect3DDevice7_GetLight(lpD3DDevice, 50, &light);
125     ok(rc==DDERR_INVALIDPARAMS, "GetLight returned: %lx\n", rc);
126     rc = IDirect3DDevice7_GetLight(lpD3DDevice, 2, &light);
127     ok(rc==DDERR_INVALIDPARAMS, "GetLight returned: %lx\n", rc);
128
129
130     /* Try to retrieve one of the lights that have been set */
131     rc = IDirect3DDevice7_GetLight(lpD3DDevice, 10, &light);
132     ok(rc==D3D_OK, "GetLight returned: %lx\n", rc);
133
134
135     /* Enable a light that have been previously set. */
136     rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 10, TRUE);
137     ok(rc==D3D_OK, "LightEnable returned: %lx\n", rc);
138
139
140     /* Enable some lights that have not been previously set, and verify that
141        they have been initialized with proper default values. */
142     memset(&defaultlight, 0, sizeof(D3DLIGHT7));
143     defaultlight.dltType = D3DLIGHT_DIRECTIONAL;
144     U1(defaultlight.dcvDiffuse).r = 1.f;
145     U2(defaultlight.dcvDiffuse).g = 1.f;
146     U3(defaultlight.dcvDiffuse).b = 1.f;
147     U3(defaultlight.dvDirection).z = 1.f;
148
149     rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 20, TRUE);
150     ok(rc==D3D_OK, "LightEnable returned: %lx\n", rc);
151     memset(&light, 0, sizeof(D3DLIGHT7));
152     rc = IDirect3DDevice7_GetLight(lpD3DDevice, 20, &light);
153     ok(rc==D3D_OK, "GetLight returned: %lx\n", rc);
154     ok(!memcmp(&light, &defaultlight, sizeof(D3DLIGHT7)),
155         "light data doesn't match expected default values\n" );
156
157     rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 50, TRUE);
158     ok(rc==D3D_OK, "LightEnable returned: %lx\n", rc);
159     memset(&light, 0, sizeof(D3DLIGHT7));
160     rc = IDirect3DDevice7_GetLight(lpD3DDevice, 50, &light);
161     ok(rc==D3D_OK, "GetLight returned: %lx\n", rc);
162     ok(!memcmp(&light, &defaultlight, sizeof(D3DLIGHT7)),
163         "light data doesn't match expected default values\n" );
164
165
166     /* Disable one of the light that have been previously enabled. */
167     rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 20, FALSE);
168     ok(rc==D3D_OK, "LightEnable returned: %lx\n", rc);
169
170     /* Try to retrieve the enable status of some lights */
171     /* Light 20 is supposed to be disabled */
172     rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 20, &bEnabled );
173     ok(rc==D3D_OK, "GetLightEnable returned: %lx\n", rc);
174     ok(!bEnabled, "GetLightEnable says the light is enabled\n");
175
176     /* Light 10 is supposed to be enabled */
177     bEnabled = FALSE;
178     rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 10, &bEnabled );
179     ok(rc==D3D_OK, "GetLightEnable returned: %lx\n", rc);
180     ok(bEnabled, "GetLightEnable says the light is disabled\n");
181
182     /* Light 80 has not been set */
183     rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 80, &bEnabled );
184     ok(rc==DDERR_INVALIDPARAMS, "GetLightEnable returned: %lx\n", rc);
185
186     /* Light 23 has not been set */
187     rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 23, &bEnabled );
188     ok(rc==DDERR_INVALIDPARAMS, "GetLightEnable returned: %lx\n", rc);
189 }
190
191 START_TEST(d3d)
192 {
193     CreateDirect3D();
194     LightTest();
195     ReleaseDirect3D();
196 }