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;
36 static HWND hwnd, hwnd2;
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 HWND createwindow(void)
61 hwnd = CreateWindowExA(0, "TestWindowClass", "TestWindowClass",
63 GetSystemMetrics(SM_CXSCREEN),
64 GetSystemMetrics(SM_CYSCREEN),
65 NULL, NULL, GetModuleHandleA(0), NULL);
67 ShowWindow(hwnd, SW_HIDE);
74 static BOOL createdirectdraw(void)
78 SetRect(&rect_before_create, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
80 rc = DirectDrawCreate(NULL, &lpDD, NULL);
81 ok(rc==DD_OK || rc==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", rc);
83 trace("DirectDrawCreateEx() failed with an error %x\n", rc);
90 static void releasedirectdraw(void)
94 IDirectDraw_Release(lpDD);
96 SetRect(&rect_after_delete, 0, 0,
97 GetSystemMetrics(SM_CXSCREEN),
98 GetSystemMetrics(SM_CYSCREEN));
99 ok(EqualRect(&rect_before_create, &rect_after_delete) != 0,
100 "Original display mode was not restored\n");
104 static BOOL WINAPI crash_callbackA(GUID *lpGUID, LPSTR lpDriverDescription,
105 LPSTR lpDriverName, LPVOID lpContext)
107 *(volatile char*)0 = 2;
111 static BOOL WINAPI test_nullcontext_callbackA(GUID *lpGUID, LPSTR lpDriverDescription,
112 LPSTR lpDriverName, LPVOID lpContext)
114 trace("test_nullcontext_callbackA: %p %s %s %p\n",
115 lpGUID, lpDriverDescription, lpDriverName, lpContext);
117 ok(!lpContext, "Expected NULL lpContext\n");
122 static BOOL WINAPI test_context_callbackA(GUID *lpGUID, LPSTR lpDriverDescription,
123 LPSTR lpDriverName, LPVOID lpContext)
125 trace("test_context_callbackA: %p %s %s %p\n",
126 lpGUID, lpDriverDescription, lpDriverName, lpContext);
128 ok(lpContext == (LPVOID)0xdeadbeef, "Expected non-NULL lpContext\n");
133 static void test_DirectDrawEnumerateA(void)
137 if (!pDirectDrawEnumerateA)
139 win_skip("DirectDrawEnumerateA is not available\n");
143 /* Test with NULL callback parameter. */
144 ret = pDirectDrawEnumerateA(NULL, NULL);
145 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
147 /* Test with invalid callback parameter. */
148 ret = pDirectDrawEnumerateA((LPDDENUMCALLBACKA)0xdeadbeef, NULL);
149 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
151 if (pDirectDrawEnumerateExA)
153 /* Test with callback that crashes. */
154 ret = pDirectDrawEnumerateA(crash_callbackA, NULL);
155 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
158 win_skip("Test would crash on older ddraw\n");
160 /* Test with valid callback parameter and NULL context parameter. */
161 trace("Calling DirectDrawEnumerateA with test_nullcontext_callbackA callback and NULL context.\n");
162 ret = pDirectDrawEnumerateA(test_nullcontext_callbackA, NULL);
163 ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
165 /* Test with valid callback parameter and valid context parameter. */
166 trace("Calling DirectDrawEnumerateA with test_context_callbackA callback and non-NULL context.\n");
167 ret = pDirectDrawEnumerateA(test_context_callbackA, (LPVOID)0xdeadbeef);
168 ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
171 static BOOL WINAPI test_callbackW(GUID *lpGUID, LPWSTR lpDriverDescription,
172 LPWSTR lpDriverName, LPVOID lpContext)
174 ok(0, "The callback should not be invoked by DirectDrawEnumerateW\n");
178 static void test_DirectDrawEnumerateW(void)
182 if (!pDirectDrawEnumerateW)
184 win_skip("DirectDrawEnumerateW is not available\n");
188 /* DirectDrawEnumerateW is not implemented on Windows. */
190 /* Test with NULL callback parameter. */
191 ret = pDirectDrawEnumerateW(NULL, NULL);
192 ok(ret == DDERR_INVALIDPARAMS ||
193 ret == DDERR_UNSUPPORTED, /* Older ddraw */
194 "Expected DDERR_INVALIDPARAMS or DDERR_UNSUPPORTED, got %d\n", ret);
196 /* Test with invalid callback parameter. */
197 ret = pDirectDrawEnumerateW((LPDDENUMCALLBACKW)0xdeadbeef, NULL);
198 ok(ret == DDERR_INVALIDPARAMS /* XP */ ||
199 ret == DDERR_UNSUPPORTED /* Win7 */,
200 "Expected DDERR_INVALIDPARAMS or DDERR_UNSUPPORTED, got %d\n", ret);
202 /* Test with valid callback parameter and NULL context parameter. */
203 ret = pDirectDrawEnumerateW(test_callbackW, NULL);
204 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
207 static BOOL WINAPI crash_callbackExA(GUID *lpGUID, LPSTR lpDriverDescription,
208 LPSTR lpDriverName, LPVOID lpContext,
211 *(volatile char*)0 = 2;
215 static BOOL WINAPI test_nullcontext_callbackExA(GUID *lpGUID, LPSTR lpDriverDescription,
216 LPSTR lpDriverName, LPVOID lpContext,
219 trace("test_nullcontext_callbackExA: %p %s %s %p %p\n", lpGUID,
220 lpDriverDescription, lpDriverName, lpContext, hm);
222 ok(!lpContext, "Expected NULL lpContext\n");
227 static BOOL WINAPI test_context_callbackExA(GUID *lpGUID, LPSTR lpDriverDescription,
228 LPSTR lpDriverName, LPVOID lpContext,
231 trace("test_context_callbackExA: %p %s %s %p %p\n", lpGUID,
232 lpDriverDescription, lpDriverName, lpContext, hm);
234 ok(lpContext == (LPVOID)0xdeadbeef, "Expected non-NULL lpContext\n");
239 static void test_DirectDrawEnumerateExA(void)
243 if (!pDirectDrawEnumerateExA)
245 win_skip("DirectDrawEnumerateExA is not available\n");
249 /* Test with NULL callback parameter. */
250 ret = pDirectDrawEnumerateExA(NULL, NULL, 0);
251 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
253 /* Test with invalid callback parameter. */
254 ret = pDirectDrawEnumerateExA((LPDDENUMCALLBACKEXA)0xdeadbeef, NULL, 0);
255 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
257 /* Test with callback that crashes. */
258 ret = pDirectDrawEnumerateExA(crash_callbackExA, NULL, 0);
259 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
261 /* Test with valid callback parameter and invalid flags */
262 ret = pDirectDrawEnumerateExA(test_nullcontext_callbackExA, NULL, ~0);
263 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
265 /* Test with valid callback parameter and NULL context parameter. */
266 trace("Calling DirectDrawEnumerateExA with empty flags and NULL context.\n");
267 ret = pDirectDrawEnumerateExA(test_nullcontext_callbackExA, NULL, 0);
268 ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
270 /* Test with valid callback parameter and non-NULL context parameter. */
271 trace("Calling DirectDrawEnumerateExA with empty flags and non-NULL context.\n");
272 ret = pDirectDrawEnumerateExA(test_context_callbackExA, (LPVOID)0xdeadbeef, 0);
273 ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
275 /* Test with valid callback parameter, NULL context parameter, and all flags set. */
276 trace("Calling DirectDrawEnumerateExA with all flags set and NULL context.\n");
277 ret = pDirectDrawEnumerateExA(test_nullcontext_callbackExA, NULL,
278 DDENUM_ATTACHEDSECONDARYDEVICES |
279 DDENUM_DETACHEDSECONDARYDEVICES |
280 DDENUM_NONDISPLAYDEVICES);
281 ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
284 static BOOL WINAPI test_callbackExW(GUID *lpGUID, LPWSTR lpDriverDescription,
285 LPWSTR lpDriverName, LPVOID lpContext,
288 ok(0, "The callback should not be invoked by DirectDrawEnumerateExW.\n");
292 static void test_DirectDrawEnumerateExW(void)
296 if (!pDirectDrawEnumerateExW)
298 win_skip("DirectDrawEnumerateExW is not available\n");
302 /* DirectDrawEnumerateExW is not implemented on Windows. */
304 /* Test with NULL callback parameter. */
305 ret = pDirectDrawEnumerateExW(NULL, NULL, 0);
306 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
308 /* Test with invalid callback parameter. */
309 ret = pDirectDrawEnumerateExW((LPDDENUMCALLBACKEXW)0xdeadbeef, NULL, 0);
310 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
312 /* Test with valid callback parameter and invalid flags */
313 ret = pDirectDrawEnumerateExW(test_callbackExW, NULL, ~0);
314 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
316 /* Test with valid callback parameter and NULL context parameter. */
317 ret = pDirectDrawEnumerateExW(test_callbackExW, NULL, 0);
318 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
320 /* Test with valid callback parameter, NULL context parameter, and all flags set. */
321 ret = pDirectDrawEnumerateExW(test_callbackExW, NULL,
322 DDENUM_ATTACHEDSECONDARYDEVICES |
323 DDENUM_DETACHEDSECONDARYDEVICES |
324 DDENUM_NONDISPLAYDEVICES);
325 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
328 static void adddisplaymode(LPDDSURFACEDESC lpddsd)
331 modes = HeapAlloc(GetProcessHeap(), 0, (modes_size = 2) * sizeof(DDSURFACEDESC));
332 if (modes_cnt == modes_size)
333 modes = HeapReAlloc(GetProcessHeap(), 0, modes, (modes_size *= 2) * sizeof(DDSURFACEDESC));
335 modes[modes_cnt++] = *lpddsd;
338 static void flushdisplaymodes(void)
340 HeapFree(GetProcessHeap(), 0, modes);
342 modes_cnt = modes_size = 0;
345 static HRESULT WINAPI enummodescallback(LPDDSURFACEDESC lpddsd, LPVOID lpContext)
347 trace("Width = %i, Height = %i, Refresh Rate = %i, Pitch = %i, flags =%02X\n",
348 lpddsd->dwWidth, lpddsd->dwHeight,
349 U2(*lpddsd).dwRefreshRate, U1(*lpddsd).lPitch, lpddsd->dwFlags);
351 /* Check that the pitch is valid if applicable */
352 if(lpddsd->dwFlags & DDSD_PITCH)
354 ok(U1(*lpddsd).lPitch != 0, "EnumDisplayModes callback with bad pitch\n");
357 /* Check that frequency is valid if applicable
359 * This fails on some Windows drivers or Windows versions, so it isn't important
361 if(lpddsd->dwFlags & DDSD_REFRESHRATE)
363 ok(U2(*lpddsd).dwRefreshRate != 0, "EnumDisplayModes callback with bad refresh rate\n");
367 adddisplaymode(lpddsd);
372 static void enumdisplaymodes(void)
377 ZeroMemory(&ddsd, sizeof(DDSURFACEDESC));
378 ddsd.dwSize = sizeof(DDSURFACEDESC);
379 ddsd.dwFlags = DDSD_CAPS;
380 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
382 rc = IDirectDraw_EnumDisplayModes(lpDD,
383 DDEDM_STANDARDVGAMODES, &ddsd, 0, enummodescallback);
384 ok(rc==DD_OK || rc==E_INVALIDARG,"EnumDisplayModes returned: %x\n",rc);
387 static void setdisplaymode(int i)
392 SetRect(&orig_rect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
394 rc = IDirectDraw_SetCooperativeLevel(lpDD,
395 hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
396 ok(rc==DD_OK,"SetCooperativeLevel returned: %x\n",rc);
397 if (modes[i].dwFlags & DDSD_PIXELFORMAT)
399 if (modes[i].ddpfPixelFormat.dwFlags & DDPF_RGB)
401 rc = IDirectDraw_SetDisplayMode(lpDD,
402 modes[i].dwWidth, modes[i].dwHeight,
403 U1(modes[i].ddpfPixelFormat).dwRGBBitCount);
404 ok(DD_OK==rc || DDERR_UNSUPPORTED==rc,"SetDisplayMode returned: %x\n",rc);
407 RECT r, scrn, test, virt;
409 SetRect(&virt, 0, 0, GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN));
410 OffsetRect(&virt, GetSystemMetrics(SM_XVIRTUALSCREEN), GetSystemMetrics(SM_YVIRTUALSCREEN));
411 SetRect(&scrn, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
412 trace("Mode (%dx%d) [%dx%d] (%d %d)x(%d %d)\n", modes[i].dwWidth, modes[i].dwHeight,
413 scrn.right, scrn.bottom, virt.left, virt.top, virt.right, virt.bottom);
414 if (!EqualRect(&scrn, &orig_rect))
418 /* Check that the client rect was resized */
419 rc = GetClientRect(hwnd, &test);
420 ok(rc!=0, "GetClientRect returned %x\n", rc);
421 rc = EqualRect(&scrn, &test);
422 todo_wine ok(rc!=0, "Fullscreen window has wrong size\n");
424 /* Check that switching to normal cooperative level
425 does not restore the display mode */
426 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_NORMAL);
427 ok(rc==DD_OK, "SetCooperativeLevel returned %x\n", rc);
428 SetRect(&test, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
429 rect_result = EqualRect(&scrn, &test);
430 ok(rect_result!=0, "Setting cooperative level to DDSCL_NORMAL changed the display mode\n");
432 /* Go back to fullscreen */
433 rc = IDirectDraw_SetCooperativeLevel(lpDD,
434 hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
435 ok(rc==DD_OK, "SetCooperativeLevel returned: %x\n",rc);
437 /* If the display mode was changed, set the correct mode
438 to avoid irrelevant failures */
439 if (rect_result == 0)
441 rc = IDirectDraw_SetDisplayMode(lpDD,
442 modes[i].dwWidth, modes[i].dwHeight,
443 U1(modes[i].ddpfPixelFormat).dwRGBBitCount);
444 ok(DD_OK==rc, "SetDisplayMode returned: %x\n",rc);
447 ok(GetClipCursor(&r), "GetClipCursor() failed\n");
448 /* ddraw sets clip rect here to the screen size, even for
450 ok(EqualRect(&r, &scrn), "Invalid clip rect: (%d %d) x (%d %d)\n",
451 r.left, r.top, r.right, r.bottom);
453 ok(ClipCursor(NULL), "ClipCursor() failed\n");
454 ok(GetClipCursor(&r), "GetClipCursor() failed\n");
455 ok(EqualRect(&r, &virt), "Invalid clip rect: (%d %d) x (%d %d)\n",
456 r.left, r.top, r.right, r.bottom);
458 rc = IDirectDraw_RestoreDisplayMode(lpDD);
459 ok(DD_OK==rc,"RestoreDisplayMode returned: %x\n",rc);
465 static void createsurface(void)
471 ddsd.dwSize = sizeof(ddsd);
472 ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
473 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
476 ddsd.dwBackBufferCount = 1;
477 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSPrimary, NULL );
478 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
479 ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
480 rc = IDirectDrawSurface_GetAttachedSurface(lpDDSPrimary, &ddscaps, &lpDDSBack);
481 ok(rc==DD_OK,"GetAttachedSurface returned: %x\n",rc);
484 static void destroysurface(void)
486 if( lpDDSPrimary != NULL )
488 IDirectDrawSurface_Release(lpDDSPrimary);
493 static void testsurface(void)
495 const char* testMsg = "ddraw device context test";
499 rc = IDirectDrawSurface_GetDC(lpDDSBack, &hdc);
500 ok(rc==DD_OK, "IDirectDrawSurface_GetDC returned: %x\n",rc);
501 SetBkColor(hdc, RGB(0, 0, 255));
502 SetTextColor(hdc, RGB(255, 255, 0));
503 TextOut(hdc, 0, 0, testMsg, lstrlen(testMsg));
504 IDirectDrawSurface_ReleaseDC(lpDDSBack, hdc);
505 ok(rc==DD_OK, "IDirectDrawSurface_ReleaseDC returned: %x\n",rc);
509 rc = IDirectDrawSurface_Flip(lpDDSPrimary, NULL, DDFLIP_WAIT);
510 ok(rc==DD_OK || rc==DDERR_SURFACELOST, "IDirectDrawSurface_BltFast returned: %x\n",rc);
516 else if (rc == DDERR_SURFACELOST)
518 rc = IDirectDrawSurface_Restore(lpDDSPrimary);
519 ok(rc==DD_OK, "IDirectDrawSurface_Restore returned: %x\n",rc);
524 static void testdisplaymodes(void)
528 for (i = 0; i < modes_cnt; ++i)
537 static void testcooperativelevels_normal(void)
541 DDSURFACEDESC surfacedesc;
542 IDirectDrawSurface *surface = (IDirectDrawSurface *) 0xdeadbeef;
544 memset(&surfacedesc, 0, sizeof(surfacedesc));
545 surfacedesc.dwSize = sizeof(surfacedesc);
546 surfacedesc.ddpfPixelFormat.dwSize = sizeof(surfacedesc.ddpfPixelFormat);
547 surfacedesc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
548 surfacedesc.dwBackBufferCount = 1;
549 surfacedesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
551 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW);
552 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW) returned: %x\n",rc);
554 /* Do some tests with DDSCL_NORMAL mode */
556 /* Fullscreen mode + normal mode + exclusive mode */
558 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NORMAL);
559 ok(rc==DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, received: %x\n", rc);
563 sfw=SetForegroundWindow(hwnd2);
565 skip("Failed to create the second window\n");
567 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NORMAL);
568 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NORMAL) returned: %x\n",rc);
571 ok(GetForegroundWindow()==hwnd,"Expected the main windows (%p) for foreground, received the second one (%p)\n",hwnd, hwnd2);
573 /* Try creating a double buffered primary in fullscreen + exclusive + normal mode */
574 rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
576 if (rc == DDERR_UNSUPPORTEDMODE)
577 skip("Unsupported mode\n");
580 ok(rc == DD_OK, "IDirectDraw_CreateSurface returned %08x\n", rc);
581 ok(surface!=NULL, "Returned NULL surface pointer\n");
583 if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
585 /* Exclusive mode + normal mode */
586 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_EXCLUSIVE | DDSCL_NORMAL);
587 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_NORMAL) returned: %x\n",rc);
589 /* Fullscreen mode + normal mode */
592 if(hwnd2) sfw=SetForegroundWindow(hwnd2);
594 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_FULLSCREEN | DDSCL_NORMAL);
595 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_FULLSCREEN | DDSCL_NORMAL) returned: %x\n",rc);
598 ok(GetForegroundWindow()==hwnd2,"Expected the second windows (%p) for foreground, received the main one (%p)\n",hwnd2, hwnd);
600 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_FULLSCREEN | DDSCL_NORMAL);
601 ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
603 /* Try creating a double buffered primary in fullscreen + normal mode */
604 rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
605 if (rc == DDERR_UNSUPPORTEDMODE)
606 skip("Unsupported mode\n");
609 ok(rc == DDERR_NOEXCLUSIVEMODE, "IDirectDraw_CreateSurface returned %08x\n", rc);
610 ok(surface == NULL, "Returned surface pointer is %p\n", surface);
613 if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
615 /* switching from Fullscreen mode to Normal mode */
618 if(hwnd2) sfw=SetForegroundWindow(hwnd2);
620 rc = IDirectDraw_SetCooperativeLevel(lpDD,
622 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL) returned: %x\n",rc);
625 ok(GetForegroundWindow()==hwnd2,"Expected the second windows (%p) for foreground, received the main one (%p)\n",hwnd2, hwnd);
627 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
628 ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
630 /* Try creating a double buffered primary in normal mode */
631 rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
632 if (rc == DDERR_UNSUPPORTEDMODE)
633 skip("Unsupported mode\n");
636 ok(rc == DDERR_NOEXCLUSIVEMODE, "IDirectDraw_CreateSurface returned %08x\n", rc);
637 ok(surface == NULL, "Returned surface pointer is %p\n", surface);
639 if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
641 /* switching from Normal mode to Fullscreen + Normal mode */
644 if(hwnd2) sfw=SetForegroundWindow(hwnd2);
646 rc = IDirectDraw_SetCooperativeLevel(lpDD,
647 hwnd, DDSCL_NORMAL | DDSCL_FULLSCREEN);
648 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL | FULLSCREEN) returned: %x\n",rc);
651 ok(GetForegroundWindow()==hwnd2,"Expected the second windows (%p) for foreground, received the main one (%p)\n",hwnd2, hwnd);
653 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL | DDSCL_FULLSCREEN);
654 ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
656 /* Set the focus window */
658 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW);
659 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW) returned: %x\n",rc);
661 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_SETFOCUSWINDOW);
663 if (rc == DDERR_INVALIDPARAMS)
665 win_skip("NT4/Win95 do not support cooperative levels DDSCL_SETDEVICEWINDOW and DDSCL_SETFOCUSWINDOW\n");
669 ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
671 rc = IDirectDraw_SetCooperativeLevel(lpDD,
672 hwnd, DDSCL_SETFOCUSWINDOW);
674 if (rc == DDERR_INVALIDPARAMS)
676 win_skip("NT4/Win95 do not support cooperative levels DDSCL_SETDEVICEWINDOW and DDSCL_SETFOCUSWINDOW\n");
680 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
682 /* Set the focus window a second time*/
683 rc = IDirectDraw_SetCooperativeLevel(lpDD,
684 hwnd, DDSCL_SETFOCUSWINDOW);
685 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) the second time returned: %x\n",rc);
687 /* Test DDSCL_SETFOCUSWINDOW with the other flags. They should all fail, except of DDSCL_NOWINDOWCHANGES */
688 rc = IDirectDraw_SetCooperativeLevel(lpDD,
689 hwnd, DDSCL_NORMAL | DDSCL_SETFOCUSWINDOW);
690 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
692 rc = IDirectDraw_SetCooperativeLevel(lpDD,
693 hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETFOCUSWINDOW);
694 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
696 /* This one succeeds */
697 rc = IDirectDraw_SetCooperativeLevel(lpDD,
698 hwnd, DDSCL_NOWINDOWCHANGES | DDSCL_SETFOCUSWINDOW);
699 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NOWINDOWCHANGES | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
701 rc = IDirectDraw_SetCooperativeLevel(lpDD,
702 hwnd, DDSCL_MULTITHREADED | DDSCL_SETFOCUSWINDOW);
703 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_MULTITHREADED | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
705 rc = IDirectDraw_SetCooperativeLevel(lpDD,
706 hwnd, DDSCL_FPUSETUP | DDSCL_SETFOCUSWINDOW);
707 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FPUSETUP | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
709 rc = IDirectDraw_SetCooperativeLevel(lpDD,
710 hwnd, DDSCL_FPUPRESERVE | DDSCL_SETFOCUSWINDOW);
711 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FPUPRESERVE | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
713 rc = IDirectDraw_SetCooperativeLevel(lpDD,
714 hwnd, DDSCL_ALLOWREBOOT | DDSCL_SETFOCUSWINDOW);
715 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_ALLOWREBOOT | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
717 rc = IDirectDraw_SetCooperativeLevel(lpDD,
718 hwnd, DDSCL_ALLOWMODEX | DDSCL_SETFOCUSWINDOW);
719 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_ALLOWMODEX | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
721 /* Set the device window without any other flags. Should give an error */
722 rc = IDirectDraw_SetCooperativeLevel(lpDD,
723 hwnd, DDSCL_SETDEVICEWINDOW);
724 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_SETDEVICEWINDOW) returned: %x\n",rc);
726 /* Set device window with DDSCL_NORMAL */
727 rc = IDirectDraw_SetCooperativeLevel(lpDD,
728 hwnd, DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW);
729 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW) returned: %x\n",rc);
731 /* Also set the focus window. Should give an error */
732 rc = IDirectDraw_SetCooperativeLevel(lpDD,
733 hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETDEVICEWINDOW | DDSCL_SETFOCUSWINDOW);
734 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
739 static void testcooperativelevels_exclusive(void)
745 /* Do some tests with DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN mode */
747 /* First, resize the window so it is not the same size as any screen */
748 success = SetWindowPos(hwnd, 0, 0, 0, 281, 92, 0);
749 ok(success, "SetWindowPos failed\n");
751 /* Try to set exclusive mode only */
752 rc = IDirectDraw_SetCooperativeLevel(lpDD,
753 hwnd, DDSCL_EXCLUSIVE);
754 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_EXCLUSIVE) returned: %x\n",rc);
756 /* Full screen mode only */
757 rc = IDirectDraw_SetCooperativeLevel(lpDD,
758 hwnd, DDSCL_FULLSCREEN);
759 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FULLSCREEN) returned: %x\n",rc);
761 /* Full screen mode + exclusive mode */
763 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
764 ok(rc==DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, received %x\n", rc);
768 sfw=SetForegroundWindow(hwnd2);
770 skip("Failed to create the second window\n");
772 rc = IDirectDraw_SetCooperativeLevel(lpDD,
773 hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
774 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN) returned: %x\n",rc);
777 ok(GetForegroundWindow()==hwnd,"Expected the main windows (%p) for foreground, received the second one (%p)\n",hwnd, hwnd2);
779 /* rect_before_create is assumed to hold the screen rect */
780 GetClientRect(hwnd, &window_rect);
781 rc = EqualRect(&rect_before_create, &window_rect);
782 ok(rc, "Fullscreen window has wrong size.\n");
784 /* Set the focus window. Should fail */
785 rc = IDirectDraw_SetCooperativeLevel(lpDD,
786 hwnd, DDSCL_SETFOCUSWINDOW);
787 ok(rc==DDERR_HWNDALREADYSET ||
788 broken(rc==DDERR_INVALIDPARAMS) /* NT4/Win95 */,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
794 static void testddraw3(void)
796 const GUID My_IID_IDirectDraw3 = {
800 { 0x8f,0xcc,0x0,0xc0,0x4f,0xd9,0x18,0x9d }
804 hr = IDirectDraw_QueryInterface(lpDD, &My_IID_IDirectDraw3, (void **) &dd3);
805 ok(hr == E_NOINTERFACE, "QueryInterface for IID_IDirectDraw3 returned 0x%08x, expected E_NOINTERFACE\n", hr);
806 if(SUCCEEDED(hr) && dd3) IDirectDraw3_Release(dd3);
809 static void testddraw7(void)
813 DDDEVICEIDENTIFIER2 *pdddi2;
817 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
818 if (hr==E_NOINTERFACE)
820 win_skip("DirectDraw7 is not supported\n");
823 ok(hr==DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);
827 dddi2Bytes = FIELD_OFFSET(DDDEVICEIDENTIFIER2, dwWHQLLevel) + sizeof(DWORD);
829 pdddi2 = HeapAlloc( GetProcessHeap(), 0, dddi2Bytes + 2*sizeof(DWORD) );
830 pend = (DWORD *)((char *)pdddi2 + dddi2Bytes);
831 pend[0] = 0xdeadbeef;
832 pend[1] = 0xdeadbeef;
834 hr = IDirectDraw7_GetDeviceIdentifier(dd7, pdddi2, 0);
835 ok(hr==DD_OK, "get device identifier failed with %08x\n", hr);
839 /* check how strings are copied into the structure */
840 ok(pdddi2->szDriver[MAX_DDDEVICEID_STRING - 1]==0, "szDriver not cleared\n");
841 ok(pdddi2->szDescription[MAX_DDDEVICEID_STRING - 1]==0, "szDescription not cleared\n");
842 /* verify that 8 byte structure size alignment will not overwrite memory */
843 ok(pend[0]==0xdeadbeef || broken(pend[0] != 0xdeadbeef), /* win2k */
844 "memory beyond DDDEVICEIDENTIFIER2 overwritten\n");
845 ok(pend[1]==0xdeadbeef, "memory beyond DDDEVICEIDENTIFIER2 overwritten\n");
848 IDirectDraw_Release(dd7);
849 HeapFree( GetProcessHeap(), 0, pdddi2 );
853 START_TEST(ddrawmodes)
855 init_function_pointers();
857 wc.style = CS_HREDRAW | CS_VREDRAW;
858 wc.lpfnWndProc = DefWindowProcA;
861 wc.hInstance = GetModuleHandleA(0);
862 wc.hIcon = LoadIconA(wc.hInstance, IDI_APPLICATION);
863 wc.hCursor = LoadCursorA(NULL, IDC_ARROW);
864 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
865 wc.lpszMenuName = NULL;
866 wc.lpszClassName = "TestWindowClass";
867 if (!RegisterClassA(&wc))
869 skip("RegisterClassA failed\n");
873 hwnd2=createwindow();
878 skip("Failed to create the main window\n");
882 if (!createdirectdraw())
884 skip("Failed to create the direct draw object\n");
888 test_DirectDrawEnumerateA();
889 test_DirectDrawEnumerateW();
890 test_DirectDrawEnumerateExA();
891 test_DirectDrawEnumerateExW();
894 if (winetest_interactive)
902 testcooperativelevels_normal();
906 testcooperativelevels_exclusive();