2 * Unit tests for ddrawex surfaces
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 /* For IID_IDirectDraw3 - it is not in dxguid.dll */
23 #include "wine/test.h"
30 static IDirectDrawFactory
*factory
;
31 static HRESULT (WINAPI
*pDllGetClassObject
)(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
);
33 static IDirectDraw
*createDD(void)
38 hr
= IDirectDrawFactory_CreateDirectDraw(factory
, NULL
, NULL
, DDSCL_NORMAL
, 0,
40 ok(hr
== DD_OK
, "Failed to create an IDirectDraw interface, hr = 0x%08x\n", hr
);
41 return SUCCEEDED(hr
) ? dd
: NULL
;
44 static void dctest_surf(IDirectDrawSurface
*surf
, int ddsdver
) {
46 HDC dc
, dc2
= (HDC
) 0x1234;
50 memset(&ddsd
, 0, sizeof(ddsd
));
51 ddsd
.dwSize
= sizeof(ddsd
);
52 memset(&ddsd2
, 0, sizeof(ddsd2
));
53 ddsd2
.dwSize
= sizeof(ddsd2
);
55 hr
= IDirectDrawSurface_GetDC(surf
, &dc
);
56 ok(hr
== DD_OK
, "IDirectDrawSurface_GetDC failed: 0x%08x\n", hr
);
58 hr
= IDirectDrawSurface_GetDC(surf
, &dc
);
59 ok(hr
== DDERR_DCALREADYCREATED
, "IDirectDrawSurface_GetDC failed: 0x%08x\n", hr
);
60 ok(dc2
== (HDC
) 0x1234, "The failed GetDC call changed the dc: %p\n", dc2
);
62 hr
= IDirectDrawSurface_Lock(surf
, NULL
, ddsdver
== 1 ? &ddsd
: ((DDSURFACEDESC
*) &ddsd2
), 0, NULL
);
63 ok(hr
== DDERR_SURFACEBUSY
, "IDirectDrawSurface_Lock returned 0x%08x, expected DDERR_SURFACEBUSY\n", hr
);
65 hr
= IDirectDrawSurface_ReleaseDC(surf
, dc
);
66 ok(hr
== DD_OK
, "IDirectDrawSurface_ReleaseDC failed: 0x%08x\n", hr
);
67 hr
= IDirectDrawSurface_ReleaseDC(surf
, dc
);
68 ok(hr
== DDERR_NODC
, "IDirectDrawSurface_ReleaseDC returned 0x%08x, expected DDERR_NODC\n", hr
);
71 static void GetDCTest_main(DDSURFACEDESC
*ddsd
, DDSURFACEDESC2
*ddsd2
, void (*testfunc
)(IDirectDrawSurface
*surf
, int ddsdver
))
73 IDirectDrawSurface
*surf
;
74 IDirectDrawSurface2
*surf2
;
75 IDirectDrawSurface2
*surf3
;
76 IDirectDrawSurface4
*surf4
;
78 IDirectDraw
*dd1
= createDD();
83 hr
= IDirectDraw_CreateSurface(dd1
, ddsd
, &surf
, NULL
);
84 if (hr
== DDERR_UNSUPPORTEDMODE
) {
85 win_skip("Unsupported mode\n");
88 ok(hr
== DD_OK
, "IDirectDraw_CreateSurface failed: 0x%08x\n", hr
);
90 IDirectDrawSurface_Release(surf
);
92 hr
= IDirectDraw_QueryInterface(dd1
, &IID_IDirectDraw2
, (void **) &dd2
);
93 ok(hr
== DD_OK
, "IDirectDraw_QueryInterface failed: 0x%08x\n", hr
);
95 hr
= IDirectDraw2_CreateSurface(dd2
, ddsd
, &surf
, NULL
);
96 ok(hr
== DD_OK
, "IDirectDraw2_CreateSurface failed: 0x%08x\n", hr
);
99 hr
= IDirectDrawSurface_QueryInterface(surf
, &IID_IDirectDrawSurface2
, (void **) &surf2
);
100 ok(hr
== DD_OK
, "IDirectDrawSurface_QueryInterface failed: 0x%08x\n", hr
);
101 testfunc((IDirectDrawSurface
*) surf2
, 1);
103 IDirectDrawSurface2_Release(surf2
);
104 IDirectDrawSurface_Release(surf
);
105 IDirectDraw2_Release(dd2
);
107 hr
= IDirectDraw_QueryInterface(dd1
, &IID_IDirectDraw3
, (void **) &dd3
);
108 ok(hr
== DD_OK
, "IDirectDraw_QueryInterface failed: 0x%08x\n", hr
);
110 hr
= IDirectDraw3_CreateSurface(dd3
, ddsd
, &surf
, NULL
);
111 ok(hr
== DD_OK
, "IDirectDraw3_CreateSurface failed: 0x%08x\n", hr
);
114 hr
= IDirectDrawSurface_QueryInterface(surf
, &IID_IDirectDrawSurface3
, (void **) &surf3
);
115 ok(hr
== DD_OK
, "IDirectDrawSurface_QueryInterface failed: 0x%08x\n", hr
);
116 testfunc((IDirectDrawSurface
*) surf3
, 1);
118 IDirectDrawSurface3_Release(surf3
);
119 IDirectDrawSurface_Release(surf
);
120 IDirectDraw3_Release(dd3
);
122 hr
= IDirectDraw_QueryInterface(dd1
, &IID_IDirectDraw4
, (void **) &dd4
);
123 ok(hr
== DD_OK
, "IDirectDraw_QueryInterface failed: 0x%08x\n", hr
);
126 hr
= IDirectDraw4_CreateSurface(dd4
, ddsd2
, &surf4
, NULL
);
127 ok(hr
== DD_OK
, "IDirectDraw4_CreateSurface failed: 0x%08x\n", hr
);
128 testfunc((IDirectDrawSurface
*) surf4
, 2);
130 IDirectDrawSurface4_Release(surf4
);
131 IDirectDraw4_Release(dd4
);
133 IDirectDraw_Release(dd1
);
136 static void GetDCTest(void)
139 DDSURFACEDESC2 ddsd2
;
141 memset(&ddsd
, 0, sizeof(ddsd
));
142 ddsd
.dwSize
= sizeof(ddsd
);
143 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
146 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
147 memset(&ddsd2
, 0, sizeof(ddsd2
));
148 ddsd2
.dwSize
= sizeof(ddsd2
);
149 ddsd2
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
152 ddsd2
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
154 GetDCTest_main(&ddsd
, &ddsd2
, dctest_surf
);
157 static void CapsTest(void)
160 IDirectDraw
*dd1
= createDD();
161 IDirectDrawSurface
*surf
;
164 memset(&ddsd
, 0, sizeof(ddsd
));
165 ddsd
.dwSize
= sizeof(ddsd
);
166 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
167 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_VIDEOMEMORY
;
170 hr
= IDirectDraw_CreateSurface(dd1
, &ddsd
, &surf
, NULL
);
171 if (hr
== DDERR_UNSUPPORTEDMODE
) {
172 win_skip("Unsupported mode\n");
175 ok(hr
== DD_OK
, "Creating a SYSMEM | VIDMEM surface returned 0x%08x, expected DD_OK\n", hr
);
176 if(surf
) IDirectDrawSurface_Release(surf
);
178 IDirectDraw_Release(dd1
);
181 static void dctest_sysvidmem(IDirectDrawSurface
*surf
, int ddsdver
) {
183 HDC dc
, dc2
= (HDC
) 0x1234;
185 DDSURFACEDESC2 ddsd2
;
187 memset(&ddsd
, 0, sizeof(ddsd
));
188 ddsd
.dwSize
= sizeof(ddsd
);
189 memset(&ddsd2
, 0, sizeof(ddsd2
));
190 ddsd2
.dwSize
= sizeof(ddsd2
);
192 hr
= IDirectDrawSurface_GetDC(surf
, &dc
);
193 ok(hr
== DD_OK
, "IDirectDrawSurface_GetDC failed: 0x%08x\n", hr
);
195 hr
= IDirectDrawSurface_GetDC(surf
, &dc2
);
196 ok(hr
== DD_OK
, "IDirectDrawSurface_GetDC failed: 0x%08x\n", hr
);
197 ok(dc
== dc2
, "Got two different DCs\n");
199 hr
= IDirectDrawSurface_Lock(surf
, NULL
, ddsdver
== 1 ? &ddsd
: ((DDSURFACEDESC
*) &ddsd2
), 0, NULL
);
200 ok(hr
== DD_OK
, "IDirectDrawSurface_Lock returned 0x%08x, expected DD_OK\n", hr
);
202 hr
= IDirectDrawSurface_Lock(surf
, NULL
, ddsdver
== 1 ? &ddsd
: ((DDSURFACEDESC
*) &ddsd2
), 0, NULL
);
203 ok(hr
== DDERR_SURFACEBUSY
, "IDirectDrawSurface_Lock returned 0x%08x, expected DDERR_SURFACEBUSY\n", hr
);
205 hr
= IDirectDrawSurface_Unlock(surf
, NULL
);
206 ok(hr
== DD_OK
, "IDirectDrawSurface_Unlock returned 0x%08x, expected DD_OK\n", hr
);
207 hr
= IDirectDrawSurface_Unlock(surf
, NULL
);
208 ok(hr
== DDERR_NOTLOCKED
, "IDirectDrawSurface_Unlock returned 0x%08x, expected DDERR_NOTLOCKED\n", hr
);
210 hr
= IDirectDrawSurface_ReleaseDC(surf
, dc
);
211 ok(hr
== DD_OK
, "IDirectDrawSurface_ReleaseDC failed: 0x%08x\n", hr
);
212 hr
= IDirectDrawSurface_ReleaseDC(surf
, dc
);
213 ok(hr
== DD_OK
, "IDirectDrawSurface_ReleaseDC failed: 0x%08x\n", hr
);
214 /* That works any number of times... */
215 hr
= IDirectDrawSurface_ReleaseDC(surf
, dc
);
216 ok(hr
== DD_OK
, "IDirectDrawSurface_ReleaseDC failed: 0x%08x\n", hr
);
219 static void SysVidMemTest(void)
222 DDSURFACEDESC2 ddsd2
;
224 memset(&ddsd
, 0, sizeof(ddsd
));
225 ddsd
.dwSize
= sizeof(ddsd
);
226 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
229 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_VIDEOMEMORY
;
230 memset(&ddsd2
, 0, sizeof(ddsd2
));
231 ddsd2
.dwSize
= sizeof(ddsd2
);
232 ddsd2
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
235 ddsd2
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_VIDEOMEMORY
;
237 GetDCTest_main(&ddsd
, &ddsd2
, dctest_sysvidmem
);
242 IClassFactory
*classfactory
= NULL
;
245 HMODULE hmod
= LoadLibrary("ddrawex.dll");
247 skip("Failed to load ddrawex.dll\n");
250 pDllGetClassObject
= (void*)GetProcAddress(hmod
, "DllGetClassObject");
251 if(pDllGetClassObject
== NULL
) {
252 skip("Failed to get DllGetClassObject\n");
256 hr
= pDllGetClassObject(&CLSID_DirectDrawFactory
, &IID_IClassFactory
, (void **) &classfactory
);
257 ok(hr
== S_OK
, "Failed to create a IClassFactory\n");
258 hr
= IClassFactory_CreateInstance(classfactory
, NULL
, &IID_IDirectDrawFactory
, (void **) &factory
);
259 ok(hr
== S_OK
, "Failed to create a IDirectDrawFactory\n");
266 ref
= IDirectDrawFactory_Release(factory
);
267 ok(ref
== 0, "IDirectDrawFactory not cleanly released\n");
270 ref
= IClassFactory_Release(classfactory
);
271 todo_wine
ok(ref
== 1, "IClassFactory refcount wrong, ref = %u\n", ref
);