2 * Unit tests for ddraw functions
5 * Part of this test involves changing the screen resolution. But this is
6 * really disrupting if the user is doing something else and is not very nice
7 * to CRT screens. Plus, ideally it needs someone watching it to check that
8 * each mode displays correctly.
9 * So this is only done if the test is being run in interactive mode.
11 * Copyright (C) 2003 Sami Aario
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "wine/test.h"
32 static LPDIRECTDRAW lpDD
= NULL
;
33 static LPDIRECTDRAWSURFACE lpDDSPrimary
= NULL
;
34 static LPDIRECTDRAWSURFACE lpDDSBack
= NULL
;
38 static int modes_size
;
39 static LPDDSURFACEDESC modes
;
40 static RECT rect_before_create
;
41 static RECT rect_after_delete
;
43 static HRESULT (WINAPI
*pDirectDrawEnumerateA
)(LPDDENUMCALLBACKA
,LPVOID
);
44 static HRESULT (WINAPI
*pDirectDrawEnumerateW
)(LPDDENUMCALLBACKW
,LPVOID
);
45 static HRESULT (WINAPI
*pDirectDrawEnumerateExA
)(LPDDENUMCALLBACKEXA
,LPVOID
,DWORD
);
46 static HRESULT (WINAPI
*pDirectDrawEnumerateExW
)(LPDDENUMCALLBACKEXW
,LPVOID
,DWORD
);
48 static void init_function_pointers(void)
50 HMODULE hmod
= GetModuleHandleA("ddraw.dll");
51 pDirectDrawEnumerateA
= (void*)GetProcAddress(hmod
, "DirectDrawEnumerateA");
52 pDirectDrawEnumerateW
= (void*)GetProcAddress(hmod
, "DirectDrawEnumerateW");
53 pDirectDrawEnumerateExA
= (void*)GetProcAddress(hmod
, "DirectDrawEnumerateExA");
54 pDirectDrawEnumerateExW
= (void*)GetProcAddress(hmod
, "DirectDrawEnumerateExW");
57 static void createwindow(void)
59 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
60 wc
.lpfnWndProc
= DefWindowProcA
;
63 wc
.hInstance
= GetModuleHandleA(0);
64 wc
.hIcon
= LoadIconA(wc
.hInstance
, IDI_APPLICATION
);
65 wc
.hCursor
= LoadCursorA(NULL
, IDC_ARROW
);
66 wc
.hbrBackground
= GetStockObject(BLACK_BRUSH
);
67 wc
.lpszMenuName
= NULL
;
68 wc
.lpszClassName
= "TestWindowClass";
69 if(!RegisterClassA(&wc
))
72 hwnd
= CreateWindowExA(0, "TestWindowClass", "TestWindowClass",
74 GetSystemMetrics(SM_CXSCREEN
),
75 GetSystemMetrics(SM_CYSCREEN
),
76 NULL
, NULL
, GetModuleHandleA(0), NULL
);
79 ShowWindow(hwnd
, SW_HIDE
);
84 static BOOL
createdirectdraw(void)
88 SetRect(&rect_before_create
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
));
90 rc
= DirectDrawCreate(NULL
, &lpDD
, NULL
);
91 ok(rc
==DD_OK
|| rc
==DDERR_NODIRECTDRAWSUPPORT
, "DirectDrawCreateEx returned: %x\n", rc
);
93 trace("DirectDrawCreateEx() failed with an error %x\n", rc
);
100 static void releasedirectdraw(void)
104 IDirectDraw_Release(lpDD
);
106 SetRect(&rect_after_delete
, 0, 0,
107 GetSystemMetrics(SM_CXSCREEN
),
108 GetSystemMetrics(SM_CYSCREEN
));
109 ok(EqualRect(&rect_before_create
, &rect_after_delete
) != 0,
110 "Original display mode was not restored\n");
114 static BOOL WINAPI
crash_callbackA(GUID
*lpGUID
, LPSTR lpDriverDescription
,
115 LPSTR lpDriverName
, LPVOID lpContext
)
117 *(volatile char*)0 = 2;
121 static BOOL WINAPI
test_nullcontext_callbackA(GUID
*lpGUID
, LPSTR lpDriverDescription
,
122 LPSTR lpDriverName
, LPVOID lpContext
)
124 trace("test_nullcontext_callbackA: %p %s %s %p\n",
125 lpGUID
, lpDriverDescription
, lpDriverName
, lpContext
);
127 ok(!lpContext
, "Expected NULL lpContext\n");
132 static BOOL WINAPI
test_context_callbackA(GUID
*lpGUID
, LPSTR lpDriverDescription
,
133 LPSTR lpDriverName
, LPVOID lpContext
)
135 trace("test_context_callbackA: %p %s %s %p\n",
136 lpGUID
, lpDriverDescription
, lpDriverName
, lpContext
);
138 ok(lpContext
== (LPVOID
)0xdeadbeef, "Expected non-NULL lpContext\n");
143 static void test_DirectDrawEnumerateA(void)
147 if (!pDirectDrawEnumerateA
)
149 win_skip("DirectDrawEnumerateA is not available\n");
153 /* Test with NULL callback parameter. */
154 ret
= pDirectDrawEnumerateA(NULL
, NULL
);
155 ok(ret
== DDERR_INVALIDPARAMS
, "Expected DDERR_INVALIDPARAMS, got %d\n", ret
);
157 /* Test with invalid callback parameter. */
158 ret
= pDirectDrawEnumerateA((LPDDENUMCALLBACKA
)0xdeadbeef, NULL
);
159 ok(ret
== DDERR_INVALIDPARAMS
, "Expected DDERR_INVALIDPARAMS, got %d\n", ret
);
161 if (pDirectDrawEnumerateExA
)
163 /* Test with callback that crashes. */
164 ret
= pDirectDrawEnumerateA(crash_callbackA
, NULL
);
165 ok(ret
== DDERR_INVALIDPARAMS
, "Expected DDERR_INVALIDPARAMS, got %d\n", ret
);
168 win_skip("Test would crash on older ddraw\n");
170 /* Test with valid callback parameter and NULL context parameter. */
171 trace("Calling DirectDrawEnumerateA with test_nullcontext_callbackA callback and NULL context.\n");
172 ret
= pDirectDrawEnumerateA(test_nullcontext_callbackA
, NULL
);
173 ok(ret
== DD_OK
, "Expected DD_OK, got %d\n", ret
);
175 /* Test with valid callback parameter and valid context parameter. */
176 trace("Calling DirectDrawEnumerateA with test_context_callbackA callback and non-NULL context.\n");
177 ret
= pDirectDrawEnumerateA(test_context_callbackA
, (LPVOID
)0xdeadbeef);
178 ok(ret
== DD_OK
, "Expected DD_OK, got %d\n", ret
);
181 static BOOL WINAPI
test_callbackW(GUID
*lpGUID
, LPWSTR lpDriverDescription
,
182 LPWSTR lpDriverName
, LPVOID lpContext
)
184 ok(0, "The callback should not be invoked by DirectDrawEnumerateW\n");
188 static void test_DirectDrawEnumerateW(void)
192 if (!pDirectDrawEnumerateW
)
194 win_skip("DirectDrawEnumerateW is not available\n");
198 /* DirectDrawEnumerateW is not implemented on Windows. */
200 /* Test with NULL callback parameter. */
201 ret
= pDirectDrawEnumerateW(NULL
, NULL
);
202 ok(ret
== DDERR_INVALIDPARAMS
||
203 ret
== DDERR_UNSUPPORTED
, /* Older ddraw */
204 "Expected DDERR_INVALIDPARAMS or DDERR_UNSUPPORTED, got %d\n", ret
);
206 /* Test with invalid callback parameter. */
207 ret
= pDirectDrawEnumerateW((LPDDENUMCALLBACKW
)0xdeadbeef, NULL
);
208 ok(ret
== DDERR_INVALIDPARAMS
/* XP */ ||
209 ret
== DDERR_UNSUPPORTED
/* Win7 */,
210 "Expected DDERR_INVALIDPARAMS or DDERR_UNSUPPORTED, got %d\n", ret
);
212 /* Test with valid callback parameter and NULL context parameter. */
213 ret
= pDirectDrawEnumerateW(test_callbackW
, NULL
);
214 ok(ret
== DDERR_UNSUPPORTED
, "Expected DDERR_UNSUPPORTED, got %d\n", ret
);
217 static BOOL WINAPI
crash_callbackExA(GUID
*lpGUID
, LPSTR lpDriverDescription
,
218 LPSTR lpDriverName
, LPVOID lpContext
,
221 *(volatile char*)0 = 2;
225 static BOOL WINAPI
test_nullcontext_callbackExA(GUID
*lpGUID
, LPSTR lpDriverDescription
,
226 LPSTR lpDriverName
, LPVOID lpContext
,
229 trace("test_nullcontext_callbackExA: %p %s %s %p %p\n", lpGUID
,
230 lpDriverDescription
, lpDriverName
, lpContext
, hm
);
232 ok(!lpContext
, "Expected NULL lpContext\n");
237 static BOOL WINAPI
test_context_callbackExA(GUID
*lpGUID
, LPSTR lpDriverDescription
,
238 LPSTR lpDriverName
, LPVOID lpContext
,
241 trace("test_context_callbackExA: %p %s %s %p %p\n", lpGUID
,
242 lpDriverDescription
, lpDriverName
, lpContext
, hm
);
244 ok(lpContext
== (LPVOID
)0xdeadbeef, "Expected non-NULL lpContext\n");
249 static void test_DirectDrawEnumerateExA(void)
253 if (!pDirectDrawEnumerateExA
)
255 win_skip("DirectDrawEnumerateExA is not available\n");
259 /* Test with NULL callback parameter. */
260 ret
= pDirectDrawEnumerateExA(NULL
, NULL
, 0);
261 ok(ret
== DDERR_INVALIDPARAMS
, "Expected DDERR_INVALIDPARAMS, got %d\n", ret
);
263 /* Test with invalid callback parameter. */
264 ret
= pDirectDrawEnumerateExA((LPDDENUMCALLBACKEXA
)0xdeadbeef, NULL
, 0);
265 ok(ret
== DDERR_INVALIDPARAMS
, "Expected DDERR_INVALIDPARAMS, got %d\n", ret
);
267 /* Test with callback that crashes. */
268 ret
= pDirectDrawEnumerateExA(crash_callbackExA
, NULL
, 0);
269 ok(ret
== DDERR_INVALIDPARAMS
, "Expected DDERR_INVALIDPARAMS, got %d\n", ret
);
271 /* Test with valid callback parameter and invalid flags */
272 ret
= pDirectDrawEnumerateExA(test_nullcontext_callbackExA
, NULL
, ~0);
273 ok(ret
== DDERR_INVALIDPARAMS
, "Expected DDERR_INVALIDPARAMS, got %d\n", ret
);
275 /* Test with valid callback parameter and NULL context parameter. */
276 trace("Calling DirectDrawEnumerateExA with empty flags and NULL context.\n");
277 ret
= pDirectDrawEnumerateExA(test_nullcontext_callbackExA
, NULL
, 0);
278 ok(ret
== DD_OK
, "Expected DD_OK, got %d\n", ret
);
280 /* Test with valid callback parameter and non-NULL context parameter. */
281 trace("Calling DirectDrawEnumerateExA with empty flags and non-NULL context.\n");
282 ret
= pDirectDrawEnumerateExA(test_context_callbackExA
, (LPVOID
)0xdeadbeef, 0);
283 ok(ret
== DD_OK
, "Expected DD_OK, got %d\n", ret
);
285 /* Test with valid callback parameter, NULL context parameter, and all flags set. */
286 trace("Calling DirectDrawEnumerateExA with all flags set and NULL context.\n");
287 ret
= pDirectDrawEnumerateExA(test_nullcontext_callbackExA
, NULL
,
288 DDENUM_ATTACHEDSECONDARYDEVICES
|
289 DDENUM_DETACHEDSECONDARYDEVICES
|
290 DDENUM_NONDISPLAYDEVICES
);
291 ok(ret
== DD_OK
, "Expected DD_OK, got %d\n", ret
);
294 static BOOL WINAPI
test_callbackExW(GUID
*lpGUID
, LPWSTR lpDriverDescription
,
295 LPWSTR lpDriverName
, LPVOID lpContext
,
298 ok(0, "The callback should not be invoked by DirectDrawEnumerateExW.\n");
302 static void test_DirectDrawEnumerateExW(void)
306 if (!pDirectDrawEnumerateExW
)
308 win_skip("DirectDrawEnumerateExW is not available\n");
312 /* DirectDrawEnumerateExW is not implemented on Windows. */
314 /* Test with NULL callback parameter. */
315 ret
= pDirectDrawEnumerateExW(NULL
, NULL
, 0);
316 ok(ret
== DDERR_UNSUPPORTED
, "Expected DDERR_UNSUPPORTED, got %d\n", ret
);
318 /* Test with invalid callback parameter. */
319 ret
= pDirectDrawEnumerateExW((LPDDENUMCALLBACKEXW
)0xdeadbeef, NULL
, 0);
320 ok(ret
== DDERR_UNSUPPORTED
, "Expected DDERR_UNSUPPORTED, got %d\n", ret
);
322 /* Test with valid callback parameter and invalid flags */
323 ret
= pDirectDrawEnumerateExW(test_callbackExW
, NULL
, ~0);
324 ok(ret
== DDERR_UNSUPPORTED
, "Expected DDERR_UNSUPPORTED, got %d\n", ret
);
326 /* Test with valid callback parameter and NULL context parameter. */
327 ret
= pDirectDrawEnumerateExW(test_callbackExW
, NULL
, 0);
328 ok(ret
== DDERR_UNSUPPORTED
, "Expected DDERR_UNSUPPORTED, got %d\n", ret
);
330 /* Test with valid callback parameter, NULL context parameter, and all flags set. */
331 ret
= pDirectDrawEnumerateExW(test_callbackExW
, NULL
,
332 DDENUM_ATTACHEDSECONDARYDEVICES
|
333 DDENUM_DETACHEDSECONDARYDEVICES
|
334 DDENUM_NONDISPLAYDEVICES
);
335 ok(ret
== DDERR_UNSUPPORTED
, "Expected DDERR_UNSUPPORTED, got %d\n", ret
);
338 static void adddisplaymode(LPDDSURFACEDESC lpddsd
)
341 modes
= HeapAlloc(GetProcessHeap(), 0, (modes_size
= 2) * sizeof(DDSURFACEDESC
));
342 if (modes_cnt
== modes_size
)
343 modes
= HeapReAlloc(GetProcessHeap(), 0, modes
, (modes_size
*= 2) * sizeof(DDSURFACEDESC
));
345 modes
[modes_cnt
++] = *lpddsd
;
348 static void flushdisplaymodes(void)
350 HeapFree(GetProcessHeap(), 0, modes
);
352 modes_cnt
= modes_size
= 0;
355 static HRESULT WINAPI
enummodescallback(LPDDSURFACEDESC lpddsd
, LPVOID lpContext
)
357 trace("Width = %i, Height = %i, Refresh Rate = %i, Pitch = %i, flags =%02X\n",
358 lpddsd
->dwWidth
, lpddsd
->dwHeight
,
359 U2(*lpddsd
).dwRefreshRate
, U1(*lpddsd
).lPitch
, lpddsd
->dwFlags
);
361 /* Check that the pitch is valid if applicable */
362 if(lpddsd
->dwFlags
& DDSD_PITCH
)
364 ok(U1(*lpddsd
).lPitch
!= 0, "EnumDisplayModes callback with bad pitch\n");
367 /* Check that frequency is valid if applicable
369 * This fails on some Windows drivers or Windows versions, so it isn't important
371 if(lpddsd->dwFlags & DDSD_REFRESHRATE)
373 ok(U2(*lpddsd).dwRefreshRate != 0, "EnumDisplayModes callback with bad refresh rate\n");
377 adddisplaymode(lpddsd
);
382 static void enumdisplaymodes(void)
387 ZeroMemory(&ddsd
, sizeof(DDSURFACEDESC
));
388 ddsd
.dwSize
= sizeof(DDSURFACEDESC
);
389 ddsd
.dwFlags
= DDSD_CAPS
;
390 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
392 rc
= IDirectDraw_EnumDisplayModes(lpDD
,
393 DDEDM_STANDARDVGAMODES
, &ddsd
, 0, enummodescallback
);
394 ok(rc
==DD_OK
|| rc
==E_INVALIDARG
,"EnumDisplayModes returned: %x\n",rc
);
397 static void setdisplaymode(int i
)
402 SetRect(&orig_rect
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
));
404 rc
= IDirectDraw_SetCooperativeLevel(lpDD
,
405 hwnd
, DDSCL_ALLOWMODEX
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
406 ok(rc
==DD_OK
,"SetCooperativeLevel returned: %x\n",rc
);
407 if (modes
[i
].dwFlags
& DDSD_PIXELFORMAT
)
409 if (modes
[i
].ddpfPixelFormat
.dwFlags
& DDPF_RGB
)
411 rc
= IDirectDraw_SetDisplayMode(lpDD
,
412 modes
[i
].dwWidth
, modes
[i
].dwHeight
,
413 U1(modes
[i
].ddpfPixelFormat
).dwRGBBitCount
);
414 ok(DD_OK
==rc
|| DDERR_UNSUPPORTED
==rc
,"SetDisplayMode returned: %x\n",rc
);
417 RECT r
, scrn
, test
, virt
;
419 SetRect(&virt
, 0, 0, GetSystemMetrics(SM_CXVIRTUALSCREEN
), GetSystemMetrics(SM_CYVIRTUALSCREEN
));
420 OffsetRect(&virt
, GetSystemMetrics(SM_XVIRTUALSCREEN
), GetSystemMetrics(SM_YVIRTUALSCREEN
));
421 SetRect(&scrn
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
));
422 trace("Mode (%dx%d) [%dx%d] (%d %d)x(%d %d)\n", modes
[i
].dwWidth
, modes
[i
].dwHeight
,
423 scrn
.right
, scrn
.bottom
, virt
.left
, virt
.top
, virt
.right
, virt
.bottom
);
424 if (!EqualRect(&scrn
, &orig_rect
))
428 /* Check that the client rect was resized */
429 rc
= GetClientRect(hwnd
, &test
);
430 ok(rc
!=0, "GetClientRect returned %x\n", rc
);
431 rc
= EqualRect(&scrn
, &test
);
432 todo_wine
ok(rc
!=0, "Fullscreen window has wrong size\n");
434 /* Check that switching to normal cooperative level
435 does not restore the display mode */
436 rc
= IDirectDraw_SetCooperativeLevel(lpDD
, hwnd
, DDSCL_NORMAL
);
437 ok(rc
==DD_OK
, "SetCooperativeLevel returned %x\n", rc
);
438 SetRect(&test
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
));
439 rect_result
= EqualRect(&scrn
, &test
);
440 ok(rect_result
!=0, "Setting cooperative level to DDSCL_NORMAL changed the display mode\n");
442 /* Go back to fullscreen */
443 rc
= IDirectDraw_SetCooperativeLevel(lpDD
,
444 hwnd
, DDSCL_ALLOWMODEX
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
445 ok(rc
==DD_OK
, "SetCooperativeLevel returned: %x\n",rc
);
447 /* If the display mode was changed, set the correct mode
448 to avoid irrelevant failures */
449 if (rect_result
== 0)
451 rc
= IDirectDraw_SetDisplayMode(lpDD
,
452 modes
[i
].dwWidth
, modes
[i
].dwHeight
,
453 U1(modes
[i
].ddpfPixelFormat
).dwRGBBitCount
);
454 ok(DD_OK
==rc
, "SetDisplayMode returned: %x\n",rc
);
457 ok(GetClipCursor(&r
), "GetClipCursor() failed\n");
458 /* ddraw sets clip rect here to the screen size, even for
460 ok(EqualRect(&r
, &scrn
), "Invalid clip rect: (%d %d) x (%d %d)\n",
461 r
.left
, r
.top
, r
.right
, r
.bottom
);
463 ok(ClipCursor(NULL
), "ClipCursor() failed\n");
464 ok(GetClipCursor(&r
), "GetClipCursor() failed\n");
465 ok(EqualRect(&r
, &virt
), "Invalid clip rect: (%d %d) x (%d %d)\n",
466 r
.left
, r
.top
, r
.right
, r
.bottom
);
468 rc
= IDirectDraw_RestoreDisplayMode(lpDD
);
469 ok(DD_OK
==rc
,"RestoreDisplayMode returned: %x\n",rc
);
475 static void createsurface(void)
481 ddsd
.dwSize
= sizeof(ddsd
);
482 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
483 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
|
486 ddsd
.dwBackBufferCount
= 1;
487 rc
= IDirectDraw_CreateSurface(lpDD
, &ddsd
, &lpDDSPrimary
, NULL
);
488 ok(rc
==DD_OK
,"CreateSurface returned: %x\n",rc
);
489 ddscaps
.dwCaps
= DDSCAPS_BACKBUFFER
;
490 rc
= IDirectDrawSurface_GetAttachedSurface(lpDDSPrimary
, &ddscaps
, &lpDDSBack
);
491 ok(rc
==DD_OK
,"GetAttachedSurface returned: %x\n",rc
);
494 static void destroysurface(void)
496 if( lpDDSPrimary
!= NULL
)
498 IDirectDrawSurface_Release(lpDDSPrimary
);
503 static void testsurface(void)
505 const char* testMsg
= "ddraw device context test";
509 rc
= IDirectDrawSurface_GetDC(lpDDSBack
, &hdc
);
510 ok(rc
==DD_OK
, "IDirectDrawSurface_GetDC returned: %x\n",rc
);
511 SetBkColor(hdc
, RGB(0, 0, 255));
512 SetTextColor(hdc
, RGB(255, 255, 0));
513 TextOut(hdc
, 0, 0, testMsg
, lstrlen(testMsg
));
514 IDirectDrawSurface_ReleaseDC(lpDDSBack
, hdc
);
515 ok(rc
==DD_OK
, "IDirectDrawSurface_ReleaseDC returned: %x\n",rc
);
519 rc
= IDirectDrawSurface_Flip(lpDDSPrimary
, NULL
, DDFLIP_WAIT
);
520 ok(rc
==DD_OK
|| rc
==DDERR_SURFACELOST
, "IDirectDrawSurface_BltFast returned: %x\n",rc
);
526 else if (rc
== DDERR_SURFACELOST
)
528 rc
= IDirectDrawSurface_Restore(lpDDSPrimary
);
529 ok(rc
==DD_OK
, "IDirectDrawSurface_Restore returned: %x\n",rc
);
534 static void testdisplaymodes(void)
538 for (i
= 0; i
< modes_cnt
; ++i
)
547 static void testcooperativelevels_normal(void)
550 DDSURFACEDESC surfacedesc
;
551 IDirectDrawSurface
*surface
= (IDirectDrawSurface
*) 0xdeadbeef;
553 memset(&surfacedesc
, 0, sizeof(surfacedesc
));
554 surfacedesc
.dwSize
= sizeof(surfacedesc
);
555 surfacedesc
.ddpfPixelFormat
.dwSize
= sizeof(surfacedesc
.ddpfPixelFormat
);
556 surfacedesc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
557 surfacedesc
.dwBackBufferCount
= 1;
558 surfacedesc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
560 /* Do some tests with DDSCL_NORMAL mode */
562 rc
= IDirectDraw_SetCooperativeLevel(lpDD
,
564 ok(rc
==DD_OK
,"SetCooperativeLevel(DDSCL_NORMAL) returned: %x\n",rc
);
566 /* Try creating a double buffered primary in normal mode */
567 rc
= IDirectDraw_CreateSurface(lpDD
, &surfacedesc
, &surface
, NULL
);
568 if (rc
== DDERR_UNSUPPORTEDMODE
)
569 skip("Unsupported mode\n");
572 ok(rc
== DDERR_NOEXCLUSIVEMODE
, "IDirectDraw_CreateSurface returned %08x\n", rc
);
573 ok(surface
== NULL
, "Returned surface pointer is %p\n", surface
);
575 if(surface
&& surface
!= (IDirectDrawSurface
*)0xdeadbeef) IDirectDrawSurface_Release(surface
);
577 /* Set the focus window */
578 rc
= IDirectDraw_SetCooperativeLevel(lpDD
,
579 hwnd
, DDSCL_SETFOCUSWINDOW
);
581 if (rc
== DDERR_INVALIDPARAMS
)
583 win_skip("NT4/Win95 do not support cooperative levels DDSCL_SETDEVICEWINDOW and DDSCL_SETFOCUSWINDOW\n");
587 ok(rc
==DD_OK
,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) returned: %x\n",rc
);
589 /* Set the focus window a second time*/
590 rc
= IDirectDraw_SetCooperativeLevel(lpDD
,
591 hwnd
, DDSCL_SETFOCUSWINDOW
);
592 ok(rc
==DD_OK
,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) the second time returned: %x\n",rc
);
594 /* Test DDSCL_SETFOCUSWINDOW with the other flags. They should all fail, except of DDSCL_NOWINDOWCHANGES */
595 rc
= IDirectDraw_SetCooperativeLevel(lpDD
,
596 hwnd
, DDSCL_NORMAL
| DDSCL_SETFOCUSWINDOW
);
597 ok(rc
==DDERR_INVALIDPARAMS
,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc
);
599 rc
= IDirectDraw_SetCooperativeLevel(lpDD
,
600 hwnd
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
| DDSCL_SETFOCUSWINDOW
);
601 ok(rc
==DDERR_INVALIDPARAMS
,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc
);
603 /* This one succeeds */
604 rc
= IDirectDraw_SetCooperativeLevel(lpDD
,
605 hwnd
, DDSCL_NOWINDOWCHANGES
| DDSCL_SETFOCUSWINDOW
);
606 ok(rc
==DD_OK
,"SetCooperativeLevel(DDSCL_NOWINDOWCHANGES | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc
);
608 rc
= IDirectDraw_SetCooperativeLevel(lpDD
,
609 hwnd
, DDSCL_MULTITHREADED
| DDSCL_SETFOCUSWINDOW
);
610 ok(rc
==DDERR_INVALIDPARAMS
,"SetCooperativeLevel(DDSCL_MULTITHREADED | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc
);
612 rc
= IDirectDraw_SetCooperativeLevel(lpDD
,
613 hwnd
, DDSCL_FPUSETUP
| DDSCL_SETFOCUSWINDOW
);
614 ok(rc
==DDERR_INVALIDPARAMS
,"SetCooperativeLevel(DDSCL_FPUSETUP | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc
);
616 rc
= IDirectDraw_SetCooperativeLevel(lpDD
,
617 hwnd
, DDSCL_FPUPRESERVE
| DDSCL_SETFOCUSWINDOW
);
618 ok(rc
==DDERR_INVALIDPARAMS
,"SetCooperativeLevel(DDSCL_FPUPRESERVE | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc
);
620 rc
= IDirectDraw_SetCooperativeLevel(lpDD
,
621 hwnd
, DDSCL_ALLOWREBOOT
| DDSCL_SETFOCUSWINDOW
);
622 ok(rc
==DDERR_INVALIDPARAMS
,"SetCooperativeLevel(DDSCL_ALLOWREBOOT | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc
);
624 rc
= IDirectDraw_SetCooperativeLevel(lpDD
,
625 hwnd
, DDSCL_ALLOWMODEX
| DDSCL_SETFOCUSWINDOW
);
626 ok(rc
==DDERR_INVALIDPARAMS
,"SetCooperativeLevel(DDSCL_ALLOWMODEX | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc
);
628 /* Set the device window without any other flags. Should give an error */
629 rc
= IDirectDraw_SetCooperativeLevel(lpDD
,
630 hwnd
, DDSCL_SETDEVICEWINDOW
);
631 ok(rc
==DDERR_INVALIDPARAMS
,"SetCooperativeLevel(DDSCL_SETDEVICEWINDOW) returned: %x\n",rc
);
633 /* Set device window with DDSCL_NORMAL */
634 rc
= IDirectDraw_SetCooperativeLevel(lpDD
,
635 hwnd
, DDSCL_NORMAL
| DDSCL_SETDEVICEWINDOW
);
636 ok(rc
==DD_OK
,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW) returned: %x\n",rc
);
638 /* Also set the focus window. Should give an error */
639 rc
= IDirectDraw_SetCooperativeLevel(lpDD
,
640 hwnd
, DDSCL_ALLOWMODEX
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
| DDSCL_SETDEVICEWINDOW
| DDSCL_SETFOCUSWINDOW
);
641 ok(rc
==DDERR_INVALIDPARAMS
,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc
);
646 static void testcooperativelevels_exclusive(void)
650 /* Do some tests with DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN mode */
652 /* Try to set exclusive mode only */
653 rc
= IDirectDraw_SetCooperativeLevel(lpDD
,
654 hwnd
, DDSCL_EXCLUSIVE
);
655 ok(rc
==DDERR_INVALIDPARAMS
,"SetCooperativeLevel(DDSCL_EXCLUSIVE) returned: %x\n",rc
);
657 /* Full screen mode only */
658 rc
= IDirectDraw_SetCooperativeLevel(lpDD
,
659 hwnd
, DDSCL_FULLSCREEN
);
660 ok(rc
==DDERR_INVALIDPARAMS
,"SetCooperativeLevel(DDSCL_FULLSCREEN) returned: %x\n",rc
);
662 /* Full screen mode + exclusive mode */
663 rc
= IDirectDraw_SetCooperativeLevel(lpDD
,
664 hwnd
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
665 ok(rc
==DD_OK
,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN) returned: %x\n",rc
);
667 /* Set the focus window. Should fail */
668 rc
= IDirectDraw_SetCooperativeLevel(lpDD
,
669 hwnd
, DDSCL_SETFOCUSWINDOW
);
670 ok(rc
==DDERR_HWNDALREADYSET
||
671 broken(rc
==DDERR_INVALIDPARAMS
) /* NT4/Win95 */,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) returned: %x\n",rc
);
677 static void testddraw3(void)
679 const GUID My_IID_IDirectDraw3
= {
683 { 0x8f,0xcc,0x0,0xc0,0x4f,0xd9,0x18,0x9d }
687 hr
= IDirectDraw_QueryInterface(lpDD
, &My_IID_IDirectDraw3
, (void **) &dd3
);
688 ok(hr
== E_NOINTERFACE
, "QueryInterface for IID_IDirectDraw3 returned 0x%08x, expected E_NOINTERFACE\n", hr
);
689 if(SUCCEEDED(hr
) && dd3
) IDirectDraw3_Release(dd3
);
692 static void testddraw7(void)
696 DDDEVICEIDENTIFIER2
*pdddi2
;
700 hr
= IDirectDraw_QueryInterface(lpDD
, &IID_IDirectDraw7
, (void **) &dd7
);
701 if (hr
==E_NOINTERFACE
)
703 win_skip("DirectDraw7 is not supported\n");
706 ok(hr
==DD_OK
, "IDirectDraw7_QueryInterface returned %08x\n", hr
);
710 dddi2Bytes
= FIELD_OFFSET(DDDEVICEIDENTIFIER2
, dwWHQLLevel
) + sizeof(DWORD
);
712 pdddi2
= HeapAlloc( GetProcessHeap(), 0, dddi2Bytes
+ 2*sizeof(DWORD
) );
713 pend
= (DWORD
*)((char *)pdddi2
+ dddi2Bytes
);
714 pend
[0] = 0xdeadbeef;
715 pend
[1] = 0xdeadbeef;
717 hr
= IDirectDraw7_GetDeviceIdentifier(dd7
, pdddi2
, 0);
718 ok(hr
==DD_OK
, "get device identifier failed with %08x\n", hr
);
722 /* check how strings are copied into the structure */
723 ok(pdddi2
->szDriver
[MAX_DDDEVICEID_STRING
- 1]==0, "szDriver not cleared\n");
724 ok(pdddi2
->szDescription
[MAX_DDDEVICEID_STRING
- 1]==0, "szDescription not cleared\n");
725 /* verify that 8 byte structure size alignment will not overwrite memory */
726 ok(pend
[0]==0xdeadbeef || broken(pend
[0] != 0xdeadbeef), /* win2k */
727 "memory beyond DDDEVICEIDENTIFIER2 overwritten\n");
728 ok(pend
[1]==0xdeadbeef, "memory beyond DDDEVICEIDENTIFIER2 overwritten\n");
731 IDirectDraw_Release(dd7
);
732 HeapFree( GetProcessHeap(), 0, pdddi2
);
736 START_TEST(ddrawmodes
)
738 init_function_pointers();
741 if (!createdirectdraw())
744 test_DirectDrawEnumerateA();
745 test_DirectDrawEnumerateW();
746 test_DirectDrawEnumerateExA();
747 test_DirectDrawEnumerateExW();
750 if (winetest_interactive
)
758 testcooperativelevels_normal();
762 testcooperativelevels_exclusive();