1 /*
2 * Unit tests for ddraw functions
3 *
4 *
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.
10 *
11 * Copyright (C) 2003 Sami Aario
12 *
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.
17 *
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.
22 *
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
26 */
27
28 #include <assert.h>
29 #include "wine/test.h"
30 #include "ddraw.h"
31
32 static LPDIRECTDRAW lpDD = NULL;
33 static LPDIRECTDRAWSURFACE lpDDSPrimary = NULL;
34 static LPDIRECTDRAWSURFACE lpDDSBack = NULL;
35 static WNDCLASS wc;
36 static HWND hwnd;
37 static int modes_cnt;
38 static int modes_size;
39 static LPDDSURFACEDESC modes;
40
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);
45
46 static void init_function_pointers(void)
47 {
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");
53 }
54
55 static void createwindow(void)
56 {
57 wc.style = CS_HREDRAW | CS_VREDRAW;
58 wc.lpfnWndProc = DefWindowProcA;
59 wc.cbClsExtra = 0;
60 wc.cbWndExtra = 0;
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))
68 assert(0);
69
70 hwnd = CreateWindowExA(0, "TestWindowClass", "TestWindowClass",
71 WS_POPUP, 0, 0,
72 GetSystemMetrics(SM_CXSCREEN),
73 GetSystemMetrics(SM_CYSCREEN),
74 NULL, NULL, GetModuleHandleA(0), NULL);
75 assert(hwnd != NULL);
76
77 ShowWindow(hwnd, SW_HIDE);
78 UpdateWindow(hwnd);
79 SetFocus(hwnd);
80 }
81
82 static BOOL createdirectdraw(void)
83 {
84 HRESULT rc;
85
86 rc = DirectDrawCreate(NULL, &lpDD, NULL);
87 ok(rc==DD_OK || rc==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", rc);
88 if (!lpDD) {
89 trace("DirectDrawCreateEx() failed with an error %x\n", rc);
90 return FALSE;
91 }
92 return TRUE;
93 }
94
95
96 static void releasedirectdraw(void)
97 {
98 if( lpDD != NULL )
99 {
100 IDirectDraw_Release(lpDD);
101 lpDD = NULL;
102 }
103 }
104
105 static BOOL WINAPI crash_callbackA(GUID *lpGUID, LPSTR lpDriverDescription,
106 LPSTR lpDriverName, LPVOID lpContext)
107 {
108 *(volatile char*)0 = 2;
109 return TRUE;
110 }
111
112 static BOOL WINAPI test_nullcontext_callbackA(GUID *lpGUID, LPSTR lpDriverDescription,
113 LPSTR lpDriverName, LPVOID lpContext)
114 {
115 trace("test_nullcontext_callbackA: %p %s %s %p\n",
116 lpGUID, lpDriverDescription, lpDriverName, lpContext);
117
118 ok(!lpContext, "Expected NULL lpContext\n");
119
120 return TRUE;
121 }
122
123 static BOOL WINAPI test_context_callbackA(GUID *lpGUID, LPSTR lpDriverDescription,
124 LPSTR lpDriverName, LPVOID lpContext)
125 {
126 trace("test_context_callbackA: %p %s %s %p\n",
127 lpGUID, lpDriverDescription, lpDriverName, lpContext);
128
129 ok(lpContext == (LPVOID)0xdeadbeef, "Expected non-NULL lpContext\n");
130
131 return TRUE;
132 }
133
134 static void test_DirectDrawEnumerateA(void)
135 {
136 HRESULT ret;
137
138 if (!pDirectDrawEnumerateA)
139 {
140 win_skip("DirectDrawEnumerateA is not available\n");
141 return;
142 }
143
144 /* Test with NULL callback parameter. */
145 ret = pDirectDrawEnumerateA(NULL, NULL);
146 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
147
148 /* Test with invalid callback parameter. */
149 ret = pDirectDrawEnumerateA((LPDDENUMCALLBACKA)0xdeadbeef, NULL);
150 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
151
152 if (pDirectDrawEnumerateExA)
153 {
154 /* Test with callback that crashes. */
155 ret = pDirectDrawEnumerateA(crash_callbackA, NULL);
156 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
157 }
158 else
159 win_skip("Test would crash on older ddraw\n");
160
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);
165
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);
170 }
171
172 static BOOL WINAPI test_callbackW(GUID *lpGUID, LPWSTR lpDriverDescription,
173 LPWSTR lpDriverName, LPVOID lpContext)
174 {
175 ok(0, "The callback should not be invoked by DirectDrawEnumerateW\n");
176 return TRUE;
177 }
178
179 static void test_DirectDrawEnumerateW(void)
180 {
181 HRESULT ret;
182
183 if (!pDirectDrawEnumerateW)
184 {
185 win_skip("DirectDrawEnumerateW is not available\n");
186 return;
187 }
188
189 /* DirectDrawEnumerateW is not implemented on Windows. */
190
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);
196
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);
202
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);
206 }
207
208 static BOOL WINAPI crash_callbackExA(GUID *lpGUID, LPSTR lpDriverDescription,
209 LPSTR lpDriverName, LPVOID lpContext,
210 HMONITOR hm)
211 {
212 *(volatile char*)0 = 2;
213 return TRUE;
214 }
215
216 static BOOL WINAPI test_nullcontext_callbackExA(GUID *lpGUID, LPSTR lpDriverDescription,
217 LPSTR lpDriverName, LPVOID lpContext,
218 HMONITOR hm)
219 {
220 trace("test_nullcontext_callbackExA: %p %s %s %p %p\n", lpGUID,
221 lpDriverDescription, lpDriverName, lpContext, hm);
222
223 ok(!lpContext, "Expected NULL lpContext\n");
224
225 return TRUE;
226 }
227
228 static BOOL WINAPI test_context_callbackExA(GUID *lpGUID, LPSTR lpDriverDescription,
229 LPSTR lpDriverName, LPVOID lpContext,
230 HMONITOR hm)
231 {
232 trace("test_context_callbackExA: %p %s %s %p %p\n", lpGUID,
233 lpDriverDescription, lpDriverName, lpContext, hm);
234
235 ok(lpContext == (LPVOID)0xdeadbeef, "Expected non-NULL lpContext\n");
236
237 return TRUE;
238 }
239
240 static void test_DirectDrawEnumerateExA(void)
241 {
242 HRESULT ret;
243
244 if (!pDirectDrawEnumerateExA)
245 {
246 win_skip("DirectDrawEnumerateExA is not available\n");
247 return;
248 }
249
250 /* Test with NULL callback parameter. */
251 ret = pDirectDrawEnumerateExA(NULL, NULL, 0);
252 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
253
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);
257
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);
261
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);
265
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);
270
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);
275
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);
283 }
284
285 static BOOL WINAPI test_callbackExW(GUID *lpGUID, LPWSTR lpDriverDescription,
286 LPWSTR lpDriverName, LPVOID lpContext,
287 HMONITOR hm)
288 {
289 ok(0, "The callback should not be invoked by DirectDrawEnumerateExW.\n");
290 return TRUE;
291 }
292
293 static void test_DirectDrawEnumerateExW(void)
294 {
295 HRESULT ret;
296
297 if (!pDirectDrawEnumerateExW)
298 {
299 win_skip("DirectDrawEnumerateExW is not available\n");
300 return;
301 }
302
303 /* DirectDrawEnumerateExW is not implemented on Windows. */
304
305 /* Test with NULL callback parameter. */
306 ret = pDirectDrawEnumerateExW(NULL, NULL, 0);
307 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
308
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);
312
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);
316
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);
320
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);
327 }
328
329 static void adddisplaymode(LPDDSURFACEDESC lpddsd)
330 {
331 if (!modes)
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));
335 assert(modes);
336 modes[modes_cnt++] = *lpddsd;
337 }
338
339 static void flushdisplaymodes(void)
340 {
341 HeapFree(GetProcessHeap(), 0, modes);
342 modes = 0;
343 modes_cnt = modes_size = 0;
344 }
345
346 static HRESULT WINAPI enummodescallback(LPDDSURFACEDESC lpddsd, LPVOID lpContext)
347 {
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);
351
352 /* Check that the pitch is valid if applicable */
353 if(lpddsd->dwFlags & DDSD_PITCH)
354 {
355 ok(U1(*lpddsd).lPitch != 0, "EnumDisplayModes callback with bad pitch\n");
356 }
357
358 /* Check that frequency is valid if applicable
359 *
360 * This fails on some Windows drivers or Windows versions, so it isn't important
361 * apparently
362 if(lpddsd->dwFlags & DDSD_REFRESHRATE)
363 {
364 ok(U2(*lpddsd).dwRefreshRate != 0, "EnumDisplayModes callback with bad refresh rate\n");
365 }
366 */
367
368 adddisplaymode(lpddsd);
369
370 return DDENUMRET_OK;
371 }
372
373 static void enumdisplaymodes(void)
374 {
375 DDSURFACEDESC ddsd;
376 HRESULT rc;
377
378 ZeroMemory(&ddsd, sizeof(DDSURFACEDESC));
379 ddsd.dwSize = sizeof(DDSURFACEDESC);
380 ddsd.dwFlags = DDSD_CAPS;
381 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
382
383 rc = IDirectDraw_EnumDisplayModes(lpDD,
384 DDEDM_STANDARDVGAMODES, &ddsd, 0, enummodescallback);
385 ok(rc==DD_OK || rc==E_INVALIDARG,"EnumDisplayModes returned: %x\n",rc);
386 }
387
388 static void setdisplaymode(int i)
389 {
390 HRESULT rc;
391
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)
396 {
397 if (modes[i].ddpfPixelFormat.dwFlags & DDPF_RGB)
398 {
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);
403 if (rc == DD_OK)
404 {
405 RECT r, scrn, virt;
406
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);
412
413 ok(GetClipCursor(&r), "GetClipCursor() failed\n");
414 /* ddraw sets clip rect here to the screen size, even for
415 multiple monitors */
416 ok(EqualRect(&r, &scrn), "Invalid clip rect: (%d %d) x (%d %d)\n",
417 r.left, r.top, r.right, r.bottom);
418
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);
423
424 rc = IDirectDraw_RestoreDisplayMode(lpDD);
425 ok(DD_OK==rc,"RestoreDisplayMode returned: %x\n",rc);
426 }
427 }
428 }
429 }
430
431 static void createsurface(void)
432 {
433 DDSURFACEDESC ddsd;
434 DDSCAPS ddscaps;
435 HRESULT rc;
436
437 ddsd.dwSize = sizeof(ddsd);
438 ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
439 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
440 DDSCAPS_FLIP |
441 DDSCAPS_COMPLEX;
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);
448 }
449
450 static void destroysurface(void)
451 {
452 if( lpDDSPrimary != NULL )
453 {
454 IDirectDrawSurface_Release(lpDDSPrimary);
455 lpDDSPrimary = NULL;
456 }
457 }
458
459 static void testsurface(void)
460 {
461 const char* testMsg = "ddraw device context test";
462 HDC hdc;
463 HRESULT rc;
464
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);
472
473 while (1)
474 {
475 rc = IDirectDrawSurface_Flip(lpDDSPrimary, NULL, DDFLIP_WAIT);
476 ok(rc==DD_OK || rc==DDERR_SURFACELOST, "IDirectDrawSurface_BltFast returned: %x\n",rc);
477
478 if (rc == DD_OK)
479 {
480 break;
481 }
482 else if (rc == DDERR_SURFACELOST)
483 {
484 rc = IDirectDrawSurface_Restore(lpDDSPrimary);
485 ok(rc==DD_OK, "IDirectDrawSurface_Restore returned: %x\n",rc);
486 }
487 }
488 }
489
490 static void testdisplaymodes(void)
491 {
492 int i;
493
494 for (i = 0; i < modes_cnt; ++i)
495 {
496 setdisplaymode(i);
497 createsurface();
498 testsurface();
499 destroysurface();
500 }
501 }
502
503 static void testcooperativelevels_normal(void)
504 {
505 HRESULT rc;
506 DDSURFACEDESC surfacedesc;
507 IDirectDrawSurface *surface = (IDirectDrawSurface *) 0xdeadbeef;
508
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;
515
516 /* Do some tests with DDSCL_NORMAL mode */
517
518 rc = IDirectDraw_SetCooperativeLevel(lpDD,
519 hwnd, DDSCL_NORMAL);
520 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL) returned: %x\n",rc);
521
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");
526 else
527 {
528 ok(rc == DDERR_NOEXCLUSIVEMODE, "IDirectDraw_CreateSurface returned %08x\n", rc);
529 ok(surface == NULL, "Returned surface pointer is %p\n", surface);
530 }
531 if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
532
533 /* Set the focus window */
534 rc = IDirectDraw_SetCooperativeLevel(lpDD,
535 hwnd, DDSCL_SETFOCUSWINDOW);
536
537 if (rc == DDERR_INVALIDPARAMS)
538 {
539 win_skip("NT4/Win95 do not support cooperative levels DDSCL_SETDEVICEWINDOW and DDSCL_SETFOCUSWINDOW\n");
540 return;
541 }
542
543 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
544
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);
549
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);
554
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);
558
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);
563
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);
567
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);
571
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);
575
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);
579
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);
583
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);
588
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);
593
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);
598
599 /* All done */
600 }
601
602 static void testcooperativelevels_exclusive(void)
603 {
604 HRESULT rc;
605
606 /* Do some tests with DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN mode */
607
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);
612
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);
617
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);
622
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);
628
629
630 /* All done */
631 }
632
633 static void testddraw3(void)
634 {
635 const GUID My_IID_IDirectDraw3 = {
636 0x618f8ad4,
637 0x8b7a,
638 0x11d0,
639 { 0x8f,0xcc,0x0,0xc0,0x4f,0xd9,0x18,0x9d }
640 };
641 IDirectDraw3 *dd3;
642 HRESULT hr;
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);
646 }
647
648 static void testddraw7(void)
649 {
650 IDirectDraw7 *dd7;
651 HRESULT hr;
652 DDDEVICEIDENTIFIER2 *pdddi2;
653 DWORD dddi2Bytes;
654 DWORD *pend;
655
656 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
657 if (hr==E_NOINTERFACE)
658 {
659 win_skip("DirectDraw7 is not supported\n");
660 return;
661 }
662 ok(hr==DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);
663
664 if (hr==DD_OK)
665 {
666 dddi2Bytes = FIELD_OFFSET(DDDEVICEIDENTIFIER2, dwWHQLLevel) + sizeof(DWORD);
667
668 pdddi2 = HeapAlloc( GetProcessHeap(), 0, dddi2Bytes + 2*sizeof(DWORD) );
669 pend = (DWORD *)((char *)pdddi2 + dddi2Bytes);
670 pend[0] = 0xdeadbeef;
671 pend[1] = 0xdeadbeef;
672
673 hr = IDirectDraw7_GetDeviceIdentifier(dd7, pdddi2, 0);
674 ok(hr==DD_OK, "get device identifier failed with %08x\n", hr);
675
676 if (hr==DD_OK)
677 {
678 /* check how strings are copied into the structure */
679 ok(pdddi2->szDriver[MAX_DDDEVICEID_STRING - 1]==0, "szDriver not cleared\n");
680 ok(pdddi2->szDescription[MAX_DDDEVICEID_STRING - 1]==0, "szDescription not cleared\n");
681 /* verify that 8 byte structure size alignment will not overwrite memory */
682 ok(pend[0]==0xdeadbeef || broken(pend[0] != 0xdeadbeef), /* win2k */
683 "memory beyond DDDEVICEIDENTIFIER2 overwritten\n");
684 ok(pend[1]==0xdeadbeef, "memory beyond DDDEVICEIDENTIFIER2 overwritten\n");
685 }
686
687 IDirectDraw_Release(dd7);
688 HeapFree( GetProcessHeap(), 0, pdddi2 );
689 }
690 }
691
692 START_TEST(ddrawmodes)
693 {
694 init_function_pointers();
695
696 createwindow();
697 if (!createdirectdraw())
698 return;
699
700 test_DirectDrawEnumerateA();
701 test_DirectDrawEnumerateW();
702 test_DirectDrawEnumerateExA();
703 test_DirectDrawEnumerateExW();
704
705 enumdisplaymodes();
706 if (winetest_interactive)
707 testdisplaymodes();
708 flushdisplaymodes();
709 testddraw3();
710 testddraw7();
711 releasedirectdraw();
712
713 createdirectdraw();
714 testcooperativelevels_normal();
715 releasedirectdraw();
716
717 createdirectdraw();
718 testcooperativelevels_exclusive();
719 releasedirectdraw();
720 }
721
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.