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;
41 static HRESULT (WINAPI *pDirectDrawEnumerateA)(LPDDENUMCALLBACKA,LPVOID);
42 static HRESULT (WINAPI *pDirectDrawEnumerateW)(LPDDENUMCALLBACKW,LPVOID);
43 static HRESULT (WINAPI *pDirectDrawEnumerateExA)(LPDDENUMCALLBACKEXA,LPVOID,DWORD);
44 static HRESULT (WINAPI *pDirectDrawEnumerateExW)(LPDDENUMCALLBACKEXW,LPVOID,DWORD);
46 static void init_function_pointers(void)
48 HMODULE hmod = GetModuleHandleA("ddraw.dll");
49 pDirectDrawEnumerateA = (void*)GetProcAddress(hmod, "DirectDrawEnumerateA");
50 pDirectDrawEnumerateW = (void*)GetProcAddress(hmod, "DirectDrawEnumerateW");
51 pDirectDrawEnumerateExA = (void*)GetProcAddress(hmod, "DirectDrawEnumerateExA");
52 pDirectDrawEnumerateExW = (void*)GetProcAddress(hmod, "DirectDrawEnumerateExW");
55 static void createwindow(void)
57 wc.style = CS_HREDRAW | CS_VREDRAW;
58 wc.lpfnWndProc = DefWindowProcA;
61 wc.hInstance = GetModuleHandleA(0);
62 wc.hIcon = LoadIconA(wc.hInstance, IDI_APPLICATION);
63 wc.hCursor = LoadCursorA(NULL, IDC_ARROW);
64 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
65 wc.lpszMenuName = NULL;
66 wc.lpszClassName = "TestWindowClass";
67 if(!RegisterClassA(&wc))
70 hwnd = CreateWindowExA(0, "TestWindowClass", "TestWindowClass",
72 GetSystemMetrics(SM_CXSCREEN),
73 GetSystemMetrics(SM_CYSCREEN),
74 NULL, NULL, GetModuleHandleA(0), NULL);
77 ShowWindow(hwnd, SW_HIDE);
82 static BOOL createdirectdraw(void)
86 rc = DirectDrawCreate(NULL, &lpDD, NULL);
87 ok(rc==DD_OK || rc==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", rc);
89 trace("DirectDrawCreateEx() failed with an error %x\n", rc);
96 static void releasedirectdraw(void)
100 IDirectDraw_Release(lpDD);
105 static BOOL WINAPI crash_callbackA(GUID *lpGUID, LPSTR lpDriverDescription,
106 LPSTR lpDriverName, LPVOID lpContext)
108 *(volatile char*)0 = 2;
112 static BOOL WINAPI test_nullcontext_callbackA(GUID *lpGUID, LPSTR lpDriverDescription,
113 LPSTR lpDriverName, LPVOID lpContext)
115 trace("test_nullcontext_callbackA: %p %s %s %p\n",
116 lpGUID, lpDriverDescription, lpDriverName, lpContext);
118 ok(!lpContext, "Expected NULL lpContext\n");
123 static BOOL WINAPI test_context_callbackA(GUID *lpGUID, LPSTR lpDriverDescription,
124 LPSTR lpDriverName, LPVOID lpContext)
126 trace("test_context_callbackA: %p %s %s %p\n",
127 lpGUID, lpDriverDescription, lpDriverName, lpContext);
129 ok(lpContext == (LPVOID)0xdeadbeef, "Expected non-NULL lpContext\n");
134 static void test_DirectDrawEnumerateA(void)
138 if (!pDirectDrawEnumerateA)
140 win_skip("DirectDrawEnumerateA is not available\n");
144 /* Test with NULL callback parameter. */
145 ret = pDirectDrawEnumerateA(NULL, NULL);
146 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
148 /* Test with invalid callback parameter. */
149 ret = pDirectDrawEnumerateA((LPDDENUMCALLBACKA)0xdeadbeef, NULL);
150 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
152 if (pDirectDrawEnumerateExA)
154 /* Test with callback that crashes. */
155 ret = pDirectDrawEnumerateA(crash_callbackA, NULL);
156 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
159 win_skip("Test would crash on older ddraw\n");
161 /* Test with valid callback parameter and NULL context parameter. */
162 trace("Calling DirectDrawEnumerateA with test_nullcontext_callbackA callback and NULL context.\n");
163 ret = pDirectDrawEnumerateA(test_nullcontext_callbackA, NULL);
164 ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
166 /* Test with valid callback parameter and valid context parameter. */
167 trace("Calling DirectDrawEnumerateA with test_context_callbackA callback and non-NULL context.\n");
168 ret = pDirectDrawEnumerateA(test_context_callbackA, (LPVOID)0xdeadbeef);
169 ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
172 static BOOL WINAPI test_callbackW(GUID *lpGUID, LPWSTR lpDriverDescription,
173 LPWSTR lpDriverName, LPVOID lpContext)
175 ok(0, "The callback should not be invoked by DirectDrawEnumerateW\n");
179 static void test_DirectDrawEnumerateW(void)
183 if (!pDirectDrawEnumerateW)
185 win_skip("DirectDrawEnumerateW is not available\n");
189 /* DirectDrawEnumerateW is not implemented on Windows. */
191 /* Test with NULL callback parameter. */
192 ret = pDirectDrawEnumerateW(NULL, NULL);
193 ok(ret == DDERR_INVALIDPARAMS ||
194 ret == DDERR_UNSUPPORTED, /* Older ddraw */
195 "Expected DDERR_INVALIDPARAMS or DDERR_UNSUPPORTED, got %d\n", ret);
197 /* Test with invalid callback parameter. */
198 ret = pDirectDrawEnumerateW((LPDDENUMCALLBACKW)0xdeadbeef, NULL);
199 ok(ret == DDERR_INVALIDPARAMS /* XP */ ||
200 ret == DDERR_UNSUPPORTED /* Win7 */,
201 "Expected DDERR_INVALIDPARAMS or DDERR_UNSUPPORTED, got %d\n", ret);
203 /* Test with valid callback parameter and NULL context parameter. */
204 ret = pDirectDrawEnumerateW(test_callbackW, NULL);
205 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
208 static BOOL WINAPI crash_callbackExA(GUID *lpGUID, LPSTR lpDriverDescription,
209 LPSTR lpDriverName, LPVOID lpContext,
212 *(volatile char*)0 = 2;
216 static BOOL WINAPI test_nullcontext_callbackExA(GUID *lpGUID, LPSTR lpDriverDescription,
217 LPSTR lpDriverName, LPVOID lpContext,
220 trace("test_nullcontext_callbackExA: %p %s %s %p %p\n", lpGUID,
221 lpDriverDescription, lpDriverName, lpContext, hm);
223 ok(!lpContext, "Expected NULL lpContext\n");
228 static BOOL WINAPI test_context_callbackExA(GUID *lpGUID, LPSTR lpDriverDescription,
229 LPSTR lpDriverName, LPVOID lpContext,
232 trace("test_context_callbackExA: %p %s %s %p %p\n", lpGUID,
233 lpDriverDescription, lpDriverName, lpContext, hm);
235 ok(lpContext == (LPVOID)0xdeadbeef, "Expected non-NULL lpContext\n");
240 static void test_DirectDrawEnumerateExA(void)
244 if (!pDirectDrawEnumerateExA)
246 win_skip("DirectDrawEnumerateExA is not available\n");
250 /* Test with NULL callback parameter. */
251 ret = pDirectDrawEnumerateExA(NULL, NULL, 0);
252 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
254 /* Test with invalid callback parameter. */
255 ret = pDirectDrawEnumerateExA((LPDDENUMCALLBACKEXA)0xdeadbeef, NULL, 0);
256 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
258 /* Test with callback that crashes. */
259 ret = pDirectDrawEnumerateExA(crash_callbackExA, NULL, 0);
260 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
262 /* Test with valid callback parameter and invalid flags */
263 ret = pDirectDrawEnumerateExA(test_nullcontext_callbackExA, NULL, ~0);
264 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
266 /* Test with valid callback parameter and NULL context parameter. */
267 trace("Calling DirectDrawEnumerateExA with empty flags and NULL context.\n");
268 ret = pDirectDrawEnumerateExA(test_nullcontext_callbackExA, NULL, 0);
269 ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
271 /* Test with valid callback parameter and non-NULL context parameter. */
272 trace("Calling DirectDrawEnumerateExA with empty flags and non-NULL context.\n");
273 ret = pDirectDrawEnumerateExA(test_context_callbackExA, (LPVOID)0xdeadbeef, 0);
274 ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
276 /* Test with valid callback parameter, NULL context parameter, and all flags set. */
277 trace("Calling DirectDrawEnumerateExA with all flags set and NULL context.\n");
278 ret = pDirectDrawEnumerateExA(test_nullcontext_callbackExA, NULL,
279 DDENUM_ATTACHEDSECONDARYDEVICES |
280 DDENUM_DETACHEDSECONDARYDEVICES |
281 DDENUM_NONDISPLAYDEVICES);
282 ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
285 static BOOL WINAPI test_callbackExW(GUID *lpGUID, LPWSTR lpDriverDescription,
286 LPWSTR lpDriverName, LPVOID lpContext,
289 ok(0, "The callback should not be invoked by DirectDrawEnumerateExW.\n");
293 static void test_DirectDrawEnumerateExW(void)
297 if (!pDirectDrawEnumerateExW)
299 win_skip("DirectDrawEnumerateExW is not available\n");
303 /* DirectDrawEnumerateExW is not implemented on Windows. */
305 /* Test with NULL callback parameter. */
306 ret = pDirectDrawEnumerateExW(NULL, NULL, 0);
307 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
309 /* Test with invalid callback parameter. */
310 ret = pDirectDrawEnumerateExW((LPDDENUMCALLBACKEXW)0xdeadbeef, NULL, 0);
311 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
313 /* Test with valid callback parameter and invalid flags */
314 ret = pDirectDrawEnumerateExW(test_callbackExW, NULL, ~0);
315 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
317 /* Test with valid callback parameter and NULL context parameter. */
318 ret = pDirectDrawEnumerateExW(test_callbackExW, NULL, 0);
319 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
321 /* Test with valid callback parameter, NULL context parameter, and all flags set. */
322 ret = pDirectDrawEnumerateExW(test_callbackExW, NULL,
323 DDENUM_ATTACHEDSECONDARYDEVICES |
324 DDENUM_DETACHEDSECONDARYDEVICES |
325 DDENUM_NONDISPLAYDEVICES);
326 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
329 static void adddisplaymode(LPDDSURFACEDESC lpddsd)
332 modes = HeapAlloc(GetProcessHeap(), 0, (modes_size = 2) * sizeof(DDSURFACEDESC));
333 if (modes_cnt == modes_size)
334 modes = HeapReAlloc(GetProcessHeap(), 0, modes, (modes_size *= 2) * sizeof(DDSURFACEDESC));
336 modes[modes_cnt++] = *lpddsd;
339 static void flushdisplaymodes(void)
341 HeapFree(GetProcessHeap(), 0, modes);
343 modes_cnt = modes_size = 0;
346 static HRESULT WINAPI enummodescallback(LPDDSURFACEDESC lpddsd, LPVOID lpContext)
348 trace("Width = %i, Height = %i, Refresh Rate = %i, Pitch = %i, flags =%02X\n",
349 lpddsd->dwWidth, lpddsd->dwHeight,
350 U2(*lpddsd).dwRefreshRate, U1(*lpddsd).lPitch, lpddsd->dwFlags);
352 /* Check that the pitch is valid if applicable */
353 if(lpddsd->dwFlags & DDSD_PITCH)
355 ok(U1(*lpddsd).lPitch != 0, "EnumDisplayModes callback with bad pitch\n");
358 /* Check that frequency is valid if applicable
360 * This fails on some Windows drivers or Windows versions, so it isn't important
362 if(lpddsd->dwFlags & DDSD_REFRESHRATE)
364 ok(U2(*lpddsd).dwRefreshRate != 0, "EnumDisplayModes callback with bad refresh rate\n");
368 adddisplaymode(lpddsd);
373 static void enumdisplaymodes(void)
378 ZeroMemory(&ddsd, sizeof(DDSURFACEDESC));
379 ddsd.dwSize = sizeof(DDSURFACEDESC);
380 ddsd.dwFlags = DDSD_CAPS;
381 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
383 rc = IDirectDraw_EnumDisplayModes(lpDD,
384 DDEDM_STANDARDVGAMODES, &ddsd, 0, enummodescallback);
385 ok(rc==DD_OK || rc==E_INVALIDARG,"EnumDisplayModes returned: %x\n",rc);
388 static void setdisplaymode(int i)
392 rc = IDirectDraw_SetCooperativeLevel(lpDD,
393 hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
394 ok(rc==DD_OK,"SetCooperativeLevel returned: %x\n",rc);
395 if (modes[i].dwFlags & DDSD_PIXELFORMAT)
397 if (modes[i].ddpfPixelFormat.dwFlags & DDPF_RGB)
399 rc = IDirectDraw_SetDisplayMode(lpDD,
400 modes[i].dwWidth, modes[i].dwHeight,
401 U1(modes[i].ddpfPixelFormat).dwRGBBitCount);
402 ok(DD_OK==rc || DDERR_UNSUPPORTED==rc,"SetDisplayMode returned: %x\n",rc);
407 SetRect(&virt, 0, 0, GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN));
408 OffsetRect(&virt, GetSystemMetrics(SM_XVIRTUALSCREEN), GetSystemMetrics(SM_YVIRTUALSCREEN));
409 SetRect(&scrn, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
410 trace("Mode (%dx%d) [%dx%d] (%d %d)x(%d %d)\n", modes[i].dwWidth, modes[i].dwHeight,
411 scrn.right, scrn.bottom, virt.left, virt.top, virt.right, virt.bottom);
413 ok(GetClipCursor(&r), "GetClipCursor() failed\n");
414 /* ddraw sets clip rect here to the screen size, even for
416 ok(EqualRect(&r, &scrn), "Invalid clip rect: (%d %d) x (%d %d)\n",
417 r.left, r.top, r.right, r.bottom);
419 ok(ClipCursor(NULL), "ClipCursor() failed\n");
420 ok(GetClipCursor(&r), "GetClipCursor() failed\n");
421 ok(EqualRect(&r, &virt), "Invalid clip rect: (%d %d) x (%d %d)\n",
422 r.left, r.top, r.right, r.bottom);
424 rc = IDirectDraw_RestoreDisplayMode(lpDD);
425 ok(DD_OK==rc,"RestoreDisplayMode returned: %x\n",rc);
431 static void createsurface(void)
437 ddsd.dwSize = sizeof(ddsd);
438 ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
439 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
442 ddsd.dwBackBufferCount = 1;
443 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSPrimary, NULL );
444 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
445 ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
446 rc = IDirectDrawSurface_GetAttachedSurface(lpDDSPrimary, &ddscaps, &lpDDSBack);
447 ok(rc==DD_OK,"GetAttachedSurface returned: %x\n",rc);
450 static void destroysurface(void)
452 if( lpDDSPrimary != NULL )
454 IDirectDrawSurface_Release(lpDDSPrimary);
459 static void testsurface(void)
461 const char* testMsg = "ddraw device context test";
465 rc = IDirectDrawSurface_GetDC(lpDDSBack, &hdc);
466 ok(rc==DD_OK, "IDirectDrawSurface_GetDC returned: %x\n",rc);
467 SetBkColor(hdc, RGB(0, 0, 255));
468 SetTextColor(hdc, RGB(255, 255, 0));
469 TextOut(hdc, 0, 0, testMsg, lstrlen(testMsg));
470 IDirectDrawSurface_ReleaseDC(lpDDSBack, hdc);
471 ok(rc==DD_OK, "IDirectDrawSurface_ReleaseDC returned: %x\n",rc);
475 rc = IDirectDrawSurface_Flip(lpDDSPrimary, NULL, DDFLIP_WAIT);
476 ok(rc==DD_OK || rc==DDERR_SURFACELOST, "IDirectDrawSurface_BltFast returned: %x\n",rc);
482 else if (rc == DDERR_SURFACELOST)
484 rc = IDirectDrawSurface_Restore(lpDDSPrimary);
485 ok(rc==DD_OK, "IDirectDrawSurface_Restore returned: %x\n",rc);
490 static void testdisplaymodes(void)
494 for (i = 0; i < modes_cnt; ++i)
503 static void testcooperativelevels_normal(void)
506 DDSURFACEDESC surfacedesc;
507 IDirectDrawSurface *surface = (IDirectDrawSurface *) 0xdeadbeef;
509 memset(&surfacedesc, 0, sizeof(surfacedesc));
510 surfacedesc.dwSize = sizeof(surfacedesc);
511 surfacedesc.ddpfPixelFormat.dwSize = sizeof(surfacedesc.ddpfPixelFormat);
512 surfacedesc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
513 surfacedesc.dwBackBufferCount = 1;
514 surfacedesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
516 /* Do some tests with DDSCL_NORMAL mode */
518 rc = IDirectDraw_SetCooperativeLevel(lpDD,
520 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL) returned: %x\n",rc);
522 /* Try creating a double buffered primary in normal mode */
523 rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
524 if (rc == DDERR_UNSUPPORTEDMODE)
525 skip("Unsupported mode\n");
528 ok(rc == DDERR_NOEXCLUSIVEMODE, "IDirectDraw_CreateSurface returned %08x\n", rc);
529 ok(surface == NULL, "Returned surface pointer is %p\n", surface);
531 if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
533 /* Set the focus window */
534 rc = IDirectDraw_SetCooperativeLevel(lpDD,
535 hwnd, DDSCL_SETFOCUSWINDOW);
537 if (rc == DDERR_INVALIDPARAMS)
539 win_skip("NT4/Win95 do not support cooperative levels DDSCL_SETDEVICEWINDOW and DDSCL_SETFOCUSWINDOW\n");
543 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
545 /* Set the focus window a second time*/
546 rc = IDirectDraw_SetCooperativeLevel(lpDD,
547 hwnd, DDSCL_SETFOCUSWINDOW);
548 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) the second time returned: %x\n",rc);
550 /* Test DDSCL_SETFOCUSWINDOW with the other flags. They should all fail, except of DDSCL_NOWINDOWCHANGES */
551 rc = IDirectDraw_SetCooperativeLevel(lpDD,
552 hwnd, DDSCL_NORMAL | DDSCL_SETFOCUSWINDOW);
553 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
555 rc = IDirectDraw_SetCooperativeLevel(lpDD,
556 hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETFOCUSWINDOW);
557 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
559 /* This one succeeds */
560 rc = IDirectDraw_SetCooperativeLevel(lpDD,
561 hwnd, DDSCL_NOWINDOWCHANGES | DDSCL_SETFOCUSWINDOW);
562 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NOWINDOWCHANGES | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
564 rc = IDirectDraw_SetCooperativeLevel(lpDD,
565 hwnd, DDSCL_MULTITHREADED | DDSCL_SETFOCUSWINDOW);
566 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_MULTITHREADED | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
568 rc = IDirectDraw_SetCooperativeLevel(lpDD,
569 hwnd, DDSCL_FPUSETUP | DDSCL_SETFOCUSWINDOW);
570 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FPUSETUP | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
572 rc = IDirectDraw_SetCooperativeLevel(lpDD,
573 hwnd, DDSCL_FPUPRESERVE | DDSCL_SETFOCUSWINDOW);
574 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FPUPRESERVE | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
576 rc = IDirectDraw_SetCooperativeLevel(lpDD,
577 hwnd, DDSCL_ALLOWREBOOT | DDSCL_SETFOCUSWINDOW);
578 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_ALLOWREBOOT | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
580 rc = IDirectDraw_SetCooperativeLevel(lpDD,
581 hwnd, DDSCL_ALLOWMODEX | DDSCL_SETFOCUSWINDOW);
582 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_ALLOWMODEX | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
584 /* Set the device window without any other flags. Should give an error */
585 rc = IDirectDraw_SetCooperativeLevel(lpDD,
586 hwnd, DDSCL_SETDEVICEWINDOW);
587 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_SETDEVICEWINDOW) returned: %x\n",rc);
589 /* Set device window with DDSCL_NORMAL */
590 rc = IDirectDraw_SetCooperativeLevel(lpDD,
591 hwnd, DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW);
592 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW) returned: %x\n",rc);
594 /* Also set the focus window. Should give an error */
595 rc = IDirectDraw_SetCooperativeLevel(lpDD,
596 hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETDEVICEWINDOW | DDSCL_SETFOCUSWINDOW);
597 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
602 static void testcooperativelevels_exclusive(void)
606 /* Do some tests with DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN mode */
608 /* Try to set exclusive mode only */
609 rc = IDirectDraw_SetCooperativeLevel(lpDD,
610 hwnd, DDSCL_EXCLUSIVE);
611 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_EXCLUSIVE) returned: %x\n",rc);
613 /* Full screen mode only */
614 rc = IDirectDraw_SetCooperativeLevel(lpDD,
615 hwnd, DDSCL_FULLSCREEN);
616 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FULLSCREEN) returned: %x\n",rc);
618 /* Full screen mode + exclusive mode */
619 rc = IDirectDraw_SetCooperativeLevel(lpDD,
620 hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
621 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN) returned: %x\n",rc);
623 /* Set the focus window. Should fail */
624 rc = IDirectDraw_SetCooperativeLevel(lpDD,
625 hwnd, DDSCL_SETFOCUSWINDOW);
626 ok(rc==DDERR_HWNDALREADYSET ||
627 broken(rc==DDERR_INVALIDPARAMS) /* NT4/Win95 */,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
633 static void testddraw3(void)
635 const GUID My_IID_IDirectDraw3 = {
639 { 0x8f,0xcc,0x0,0xc0,0x4f,0xd9,0x18,0x9d }
643 hr = IDirectDraw_QueryInterface(lpDD, &My_IID_IDirectDraw3, (void **) &dd3);
644 ok(hr == E_NOINTERFACE, "QueryInterface for IID_IDirectDraw3 returned 0x%08x, expected E_NOINTERFACE\n", hr);
645 if(SUCCEEDED(hr) && dd3) IDirectDraw3_Release(dd3);
648 static void testddraw7(void)
652 DDDEVICEIDENTIFIER2 *pdddi2;
656 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
657 if (hr==E_NOINTERFACE)
659 win_skip("DirectDraw7 is not supported\n");
662 ok(hr==DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);
666 dddi2Bytes = FIELD_OFFSET(DDDEVICEIDENTIFIER2, dwWHQLLevel) + sizeof(DWORD);
668 pdddi2 = HeapAlloc( GetProcessHeap(), 0, dddi2Bytes + sizeof(DWORD) );
669 pend = (DWORD *)((char *)pdddi2 + dddi2Bytes);
672 hr = IDirectDraw7_GetDeviceIdentifier(dd7, pdddi2, 0);
673 ok(hr==DD_OK, "get device identifier failed with %08x\n", hr);
677 /* check how strings are copied into the structure */
678 ok(pdddi2->szDriver[MAX_DDDEVICEID_STRING - 1]==0, "szDriver not cleared\n");
679 ok(pdddi2->szDescription[MAX_DDDEVICEID_STRING - 1]==0, "szDescription not cleared\n");
680 /* verify that 8 byte structure size alignment will not overwrite memory */
681 ok(*pend==0xdeadbeef, "memory beyond DDDEVICEIDENTIFIER2 overwritten\n");
684 IDirectDraw_Release(dd7);
685 HeapFree( GetProcessHeap(), 0, pdddi2 );
689 START_TEST(ddrawmodes)
691 init_function_pointers();
694 if (!createdirectdraw())
697 test_DirectDrawEnumerateA();
698 test_DirectDrawEnumerateW();
699 test_DirectDrawEnumerateExA();
700 test_DirectDrawEnumerateExW();
703 if (winetest_interactive)
711 testcooperativelevels_normal();
715 testcooperativelevels_exclusive();