Fixes for -Wmissing-declaration and -Wwrite-string warnings.
[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 static LPDIRECTDRAW7        lpDD = NULL;
27 static LPDIRECT3D7          lpD3D = NULL;
28 static LPDIRECTDRAWSURFACE7 lpDDS = NULL;
29 static LPDIRECT3DDEVICE7    lpD3DDevice = NULL;
30
31 static HRESULT (WINAPI *pDirectDrawCreateEx)(LPGUID,LPVOID*,REFIID,LPUNKNOWN);
32
33 static void init_function_pointers(void)
34 {
35     HMODULE hmod = GetModuleHandleA("ddraw.dll");
36
37     if(hmod)
38     {
39         pDirectDrawCreateEx = (void*)GetProcAddress(hmod, "DirectDrawCreateEx");
40     }
41 }
42
43
44 static void CreateDirect3D()
45 {
46     HRESULT rc;
47     DDSURFACEDESC2 ddsd;
48
49     rc = pDirectDrawCreateEx(NULL, (void**)&lpDD,
50         &IID_IDirectDraw7, NULL);
51     ok(rc==DD_OK, "DirectDrawCreateEx returned: %lx\n", rc);
52
53     rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
54     ok(rc==DD_OK, "SetCooperativeLevel returned: %lx\n", rc);
55
56     rc = IDirectDraw7_QueryInterface(lpDD, &IID_IDirect3D7, (void**) &lpD3D);
57     ok(rc==DD_OK, "QueryInterface returned: %lx\n", rc);
58
59     memset(&ddsd, 0, sizeof(ddsd));
60     ddsd.dwSize = sizeof(ddsd);
61     ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
62     ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
63     ddsd.dwWidth = 256;
64     ddsd.dwHeight = 256;
65     rc = IDirectDraw7_CreateSurface(lpDD, &ddsd, &lpDDS, NULL);
66     ok(rc==DD_OK, "CreateSurface returned: %lx\n", rc);
67
68     rc = IDirect3D7_CreateDevice(lpD3D, &IID_IDirect3DTnLHalDevice, lpDDS,
69         &lpD3DDevice);
70     ok(rc==D3D_OK, "CreateDevice returned: %lx\n", rc);
71 }
72
73 static void ReleaseDirect3D()
74 {
75     if (lpD3DDevice != NULL)
76     {
77         IDirect3DDevice7_Release(lpD3DDevice);
78         lpD3DDevice = NULL;
79     }
80
81     if (lpDDS != NULL)
82     {
83         IDirectDrawSurface_Release(lpDDS);
84         lpDDS = NULL;
85     }
86
87     if (lpD3D != NULL)
88     {
89         IDirect3D7_Release(lpD3D);
90         lpD3D = NULL;
91     }
92
93     if (lpDD != NULL)
94     {
95         IDirectDraw_Release(lpDD);
96         lpDD = NULL;
97     }
98 }
99
100 static void LightTest()
101 {
102     HRESULT rc;
103     D3DLIGHT7 light;
104     D3DLIGHT7 defaultlight;
105     BOOL bEnabled = FALSE;
106
107     /* Set a few lights with funky indices. */
108     memset(&light, 0, sizeof(light));
109     light.dltType = D3DLIGHT_DIRECTIONAL;
110     U1(light.dcvDiffuse).r = 0.5f;
111     U2(light.dcvDiffuse).g = 0.6f;
112     U3(light.dcvDiffuse).b = 0.7f;
113     U2(light.dvDirection).y = 1.f;
114
115     rc = IDirect3DDevice7_SetLight(lpD3DDevice, 5, &light);
116     ok(rc==D3D_OK, "SetLight returned: %lx\n", rc);
117     rc = IDirect3DDevice7_SetLight(lpD3DDevice, 10, &light);
118     ok(rc==D3D_OK, "SetLight returned: %lx\n", rc);
119     rc = IDirect3DDevice7_SetLight(lpD3DDevice, 45, &light);
120     ok(rc==D3D_OK, "SetLight returned: %lx\n", rc);
121
122
123     /* Try to retrieve a light beyond the indices of the lights that have
124        been set. */
125     rc = IDirect3DDevice7_GetLight(lpD3DDevice, 50, &light);
126     ok(rc==DDERR_INVALIDPARAMS, "GetLight returned: %lx\n", rc);
127     rc = IDirect3DDevice7_GetLight(lpD3DDevice, 2, &light);
128     ok(rc==DDERR_INVALIDPARAMS, "GetLight returned: %lx\n", rc);
129
130
131     /* Try to retrieve one of the lights that have been set */
132     rc = IDirect3DDevice7_GetLight(lpD3DDevice, 10, &light);
133     ok(rc==D3D_OK, "GetLight returned: %lx\n", rc);
134
135
136     /* Enable a light that have been previously set. */
137     rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 10, TRUE);
138     ok(rc==D3D_OK, "LightEnable returned: %lx\n", rc);
139
140
141     /* Enable some lights that have not been previously set, and verify that
142        they have been initialized with proper default values. */
143     memset(&defaultlight, 0, sizeof(D3DLIGHT7));
144     defaultlight.dltType = D3DLIGHT_DIRECTIONAL;
145     U1(defaultlight.dcvDiffuse).r = 1.f;
146     U2(defaultlight.dcvDiffuse).g = 1.f;
147     U3(defaultlight.dcvDiffuse).b = 1.f;
148     U3(defaultlight.dvDirection).z = 1.f;
149
150     rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 20, TRUE);
151     ok(rc==D3D_OK, "LightEnable returned: %lx\n", rc);
152     memset(&light, 0, sizeof(D3DLIGHT7));
153     rc = IDirect3DDevice7_GetLight(lpD3DDevice, 20, &light);
154     ok(rc==D3D_OK, "GetLight returned: %lx\n", rc);
155     ok(!memcmp(&light, &defaultlight, sizeof(D3DLIGHT7)),
156         "light data doesn't match expected default values\n" );
157
158     rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 50, TRUE);
159     ok(rc==D3D_OK, "LightEnable returned: %lx\n", rc);
160     memset(&light, 0, sizeof(D3DLIGHT7));
161     rc = IDirect3DDevice7_GetLight(lpD3DDevice, 50, &light);
162     ok(rc==D3D_OK, "GetLight returned: %lx\n", rc);
163     ok(!memcmp(&light, &defaultlight, sizeof(D3DLIGHT7)),
164         "light data doesn't match expected default values\n" );
165
166
167     /* Disable one of the light that have been previously enabled. */
168     rc = IDirect3DDevice7_LightEnable(lpD3DDevice, 20, FALSE);
169     ok(rc==D3D_OK, "LightEnable returned: %lx\n", rc);
170
171     /* Try to retrieve the enable status of some lights */
172     /* Light 20 is supposed to be disabled */
173     rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 20, &bEnabled );
174     ok(rc==D3D_OK, "GetLightEnable returned: %lx\n", rc);
175     ok(!bEnabled, "GetLightEnable says the light is enabled\n");
176
177     /* Light 10 is supposed to be enabled */
178     bEnabled = FALSE;
179     rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 10, &bEnabled );
180     ok(rc==D3D_OK, "GetLightEnable returned: %lx\n", rc);
181     ok(bEnabled, "GetLightEnable says the light is disabled\n");
182
183     /* Light 80 has not been set */
184     rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 80, &bEnabled );
185     ok(rc==DDERR_INVALIDPARAMS, "GetLightEnable returned: %lx\n", rc);
186
187     /* Light 23 has not been set */
188     rc = IDirect3DDevice7_GetLightEnable(lpD3DDevice, 23, &bEnabled );
189     ok(rc==DDERR_INVALIDPARAMS, "GetLightEnable returned: %lx\n", rc);
190 }
191
192 START_TEST(d3d)
193 {
194     init_function_pointers();
195     if(!pDirectDrawCreateEx) {
196         trace("function DirectDrawCreateEx not available, skipping tests\n");
197         return;
198     }
199
200     CreateDirect3D();
201     LightTest();
202     ReleaseDirect3D();
203 }