d3d10core: Implement d3d10_device_OMGetRenderTargets().
[wine.git] / dlls / ddraw / tests / ddrawmodes.c
blob39b35558006ade7beec940af3ab721efb5756b63
1 /*
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
28 #include <assert.h>
29 #include "wine/test.h"
30 #include "ddraw.h"
32 static IDirectDrawSurface *lpDDSPrimary;
33 static IDirectDrawSurface *lpDDSBack;
34 static IDirectDraw *lpDD;
35 static WNDCLASSA wc;
36 static HWND hwnd, hwnd2;
37 static int modes_cnt;
38 static int modes_size;
39 static DDSURFACEDESC *modes;
40 static RECT rect_before_create;
41 static RECT rect_after_delete;
42 static int modes16bpp_cnt;
43 static int refresh_rate;
44 static int refresh_rate_cnt;
46 static HRESULT (WINAPI *pDirectDrawEnumerateA)(LPDDENUMCALLBACKA cb, void *ctx);
47 static HRESULT (WINAPI *pDirectDrawEnumerateW)(LPDDENUMCALLBACKW cb, void *ctx);
48 static HRESULT (WINAPI *pDirectDrawEnumerateExA)(LPDDENUMCALLBACKEXA cb, void *ctx, DWORD flags);
49 static HRESULT (WINAPI *pDirectDrawEnumerateExW)(LPDDENUMCALLBACKEXW cb, void *ctx, DWORD flags);
51 static void init_function_pointers(void)
53 HMODULE hmod = GetModuleHandleA("ddraw.dll");
54 pDirectDrawEnumerateA = (void*)GetProcAddress(hmod, "DirectDrawEnumerateA");
55 pDirectDrawEnumerateW = (void*)GetProcAddress(hmod, "DirectDrawEnumerateW");
56 pDirectDrawEnumerateExA = (void*)GetProcAddress(hmod, "DirectDrawEnumerateExA");
57 pDirectDrawEnumerateExW = (void*)GetProcAddress(hmod, "DirectDrawEnumerateExW");
60 static HWND createwindow(void)
62 HWND hwnd;
64 hwnd = CreateWindowExA(0, "TestWindowClass", "TestWindowClass",
65 WS_POPUP, 0, 0,
66 GetSystemMetrics(SM_CXSCREEN),
67 GetSystemMetrics(SM_CYSCREEN),
68 NULL, NULL, GetModuleHandleA(0), NULL);
70 ShowWindow(hwnd, SW_HIDE);
71 UpdateWindow(hwnd);
72 SetFocus(hwnd);
74 return hwnd;
77 static BOOL createdirectdraw(void)
79 HRESULT rc;
81 SetRect(&rect_before_create, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
83 rc = DirectDrawCreate(NULL, &lpDD, NULL);
84 ok(rc==DD_OK || rc==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", rc);
85 if (!lpDD) {
86 trace("DirectDrawCreateEx() failed with an error %x\n", rc);
87 return FALSE;
89 return TRUE;
93 static void releasedirectdraw(void)
95 if( lpDD != NULL )
97 IDirectDraw_Release(lpDD);
98 lpDD = NULL;
99 SetRect(&rect_after_delete, 0, 0,
100 GetSystemMetrics(SM_CXSCREEN),
101 GetSystemMetrics(SM_CYSCREEN));
102 ok(EqualRect(&rect_before_create, &rect_after_delete) != 0,
103 "Original display mode was not restored\n");
107 static BOOL WINAPI test_nullcontext_callbackA(GUID *lpGUID,
108 char *lpDriverDescription, char *lpDriverName, void *lpContext)
110 trace("test_nullcontext_callbackA: %p %s %s %p\n",
111 lpGUID, lpDriverDescription, lpDriverName, lpContext);
113 ok(!lpContext, "Expected NULL lpContext\n");
115 return TRUE;
118 static BOOL WINAPI test_context_callbackA(GUID *lpGUID,
119 char *lpDriverDescription, char *lpDriverName, void *lpContext)
121 trace("test_context_callbackA: %p %s %s %p\n",
122 lpGUID, lpDriverDescription, lpDriverName, lpContext);
124 ok(lpContext == (void *)0xdeadbeef, "Expected non-NULL lpContext\n");
126 return TRUE;
129 static void test_DirectDrawEnumerateA(void)
131 HRESULT ret;
133 if (!pDirectDrawEnumerateA)
135 win_skip("DirectDrawEnumerateA is not available\n");
136 return;
139 /* Test with NULL callback parameter. */
140 ret = pDirectDrawEnumerateA(NULL, NULL);
141 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
143 /* Test with valid callback parameter and NULL context parameter. */
144 trace("Calling DirectDrawEnumerateA with test_nullcontext_callbackA callback and NULL context.\n");
145 ret = pDirectDrawEnumerateA(test_nullcontext_callbackA, NULL);
146 ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
148 /* Test with valid callback parameter and valid context parameter. */
149 trace("Calling DirectDrawEnumerateA with test_context_callbackA callback and non-NULL context.\n");
150 ret = pDirectDrawEnumerateA(test_context_callbackA, (void *)0xdeadbeef);
151 ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
154 static BOOL WINAPI test_callbackW(GUID *lpGUID, WCHAR *lpDriverDescription,
155 WCHAR *lpDriverName, void *lpContext)
157 ok(0, "The callback should not be invoked by DirectDrawEnumerateW\n");
158 return TRUE;
161 static void test_DirectDrawEnumerateW(void)
163 HRESULT ret;
165 if (!pDirectDrawEnumerateW)
167 win_skip("DirectDrawEnumerateW is not available\n");
168 return;
171 /* DirectDrawEnumerateW is not implemented on Windows. */
173 /* Test with NULL callback parameter. */
174 ret = pDirectDrawEnumerateW(NULL, NULL);
175 ok(ret == DDERR_INVALIDPARAMS ||
176 ret == DDERR_UNSUPPORTED, /* Older ddraw */
177 "Expected DDERR_INVALIDPARAMS or DDERR_UNSUPPORTED, got %d\n", ret);
179 /* Test with invalid callback parameter. */
180 ret = pDirectDrawEnumerateW((LPDDENUMCALLBACKW)0xdeadbeef, NULL);
181 ok(ret == DDERR_INVALIDPARAMS /* XP */ ||
182 ret == DDERR_UNSUPPORTED /* Win7 */,
183 "Expected DDERR_INVALIDPARAMS or DDERR_UNSUPPORTED, got %d\n", ret);
185 /* Test with valid callback parameter and NULL context parameter. */
186 ret = pDirectDrawEnumerateW(test_callbackW, NULL);
187 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
190 static BOOL WINAPI test_nullcontext_callbackExA(GUID *lpGUID, char *lpDriverDescription,
191 char *lpDriverName, void *lpContext, HMONITOR hm)
193 trace("test_nullcontext_callbackExA: %p %s %s %p %p\n", lpGUID,
194 lpDriverDescription, lpDriverName, lpContext, hm);
196 ok(!lpContext, "Expected NULL lpContext\n");
198 return TRUE;
201 static BOOL WINAPI test_context_callbackExA(GUID *lpGUID, char *lpDriverDescription,
202 char *lpDriverName, void *lpContext, HMONITOR hm)
204 trace("test_context_callbackExA: %p %s %s %p %p\n", lpGUID,
205 lpDriverDescription, lpDriverName, lpContext, hm);
207 ok(lpContext == (void *)0xdeadbeef, "Expected non-NULL lpContext\n");
209 return TRUE;
212 static BOOL WINAPI test_count_callbackExA(GUID *lpGUID, char *lpDriverDescription,
213 char *lpDriverName, void *lpContext, HMONITOR hm)
215 DWORD *count = (DWORD *)lpContext;
217 trace("test_count_callbackExA: %p %s %s %p %p\n", lpGUID,
218 lpDriverDescription, lpDriverName, lpContext, hm);
220 (*count)++;
222 return TRUE;
225 static void test_DirectDrawEnumerateExA(void)
227 DWORD callbackCount;
228 HRESULT ret;
230 if (!pDirectDrawEnumerateExA)
232 win_skip("DirectDrawEnumerateExA is not available\n");
233 return;
236 /* Test with NULL callback parameter. */
237 ret = pDirectDrawEnumerateExA(NULL, NULL, 0);
238 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
240 /* Test with valid callback parameter and invalid flags */
241 ret = pDirectDrawEnumerateExA(test_nullcontext_callbackExA, NULL, ~0);
242 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
244 /* Test with valid callback parameter and NULL context parameter. */
245 trace("Calling DirectDrawEnumerateExA with empty flags and NULL context.\n");
246 ret = pDirectDrawEnumerateExA(test_nullcontext_callbackExA, NULL, 0);
247 ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
249 /* Test with valid callback parameter and non-NULL context parameter. */
250 trace("Calling DirectDrawEnumerateExA with empty flags and non-NULL context.\n");
251 ret = pDirectDrawEnumerateExA(test_context_callbackExA, (void *)0xdeadbeef, 0);
252 ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
254 /* Test with valid callback parameter and count the number of primary devices */
255 callbackCount = 0;
256 ret = pDirectDrawEnumerateExA(test_count_callbackExA, &callbackCount, 0);
257 ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
258 ok(callbackCount == 1, "Expected 1 primary device, got %d\n", callbackCount);
260 /* Test with valid callback parameter and count the number of secondary devices */
261 callbackCount = 0;
262 ret = pDirectDrawEnumerateExA(test_count_callbackExA, &callbackCount,
263 DDENUM_ATTACHEDSECONDARYDEVICES);
264 ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
265 /* Note: this list includes the primary devices as well and some systems (such as the TestBot)
266 do not include any secondary devices */
267 ok(callbackCount >= 1, "Expected at least one device, got %d\n", callbackCount);
269 /* Test with valid callback parameter, NULL context parameter, and all flags set. */
270 trace("Calling DirectDrawEnumerateExA with all flags set and NULL context.\n");
271 ret = pDirectDrawEnumerateExA(test_nullcontext_callbackExA, NULL,
272 DDENUM_ATTACHEDSECONDARYDEVICES |
273 DDENUM_DETACHEDSECONDARYDEVICES |
274 DDENUM_NONDISPLAYDEVICES);
275 ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
278 static BOOL WINAPI test_callbackExW(GUID *lpGUID, WCHAR *lpDriverDescription,
279 WCHAR *lpDriverName, void *lpContext, HMONITOR hm)
281 ok(0, "The callback should not be invoked by DirectDrawEnumerateExW.\n");
282 return TRUE;
285 static void test_DirectDrawEnumerateExW(void)
287 HRESULT ret;
289 if (!pDirectDrawEnumerateExW)
291 win_skip("DirectDrawEnumerateExW is not available\n");
292 return;
295 /* DirectDrawEnumerateExW is not implemented on Windows. */
297 /* Test with NULL callback parameter. */
298 ret = pDirectDrawEnumerateExW(NULL, NULL, 0);
299 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
301 /* Test with invalid callback parameter. */
302 ret = pDirectDrawEnumerateExW((LPDDENUMCALLBACKEXW)0xdeadbeef, NULL, 0);
303 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
305 /* Test with valid callback parameter and invalid flags */
306 ret = pDirectDrawEnumerateExW(test_callbackExW, NULL, ~0);
307 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
309 /* Test with valid callback parameter and NULL context parameter. */
310 ret = pDirectDrawEnumerateExW(test_callbackExW, NULL, 0);
311 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
313 /* Test with valid callback parameter, NULL context parameter, and all flags set. */
314 ret = pDirectDrawEnumerateExW(test_callbackExW, NULL,
315 DDENUM_ATTACHEDSECONDARYDEVICES |
316 DDENUM_DETACHEDSECONDARYDEVICES |
317 DDENUM_NONDISPLAYDEVICES);
318 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
321 static void adddisplaymode(DDSURFACEDESC *lpddsd)
323 if (!modes)
324 modes = HeapAlloc(GetProcessHeap(), 0, (modes_size = 2) * sizeof(DDSURFACEDESC));
325 if (modes_cnt == modes_size)
326 modes = HeapReAlloc(GetProcessHeap(), 0, modes, (modes_size *= 2) * sizeof(DDSURFACEDESC));
327 assert(modes);
328 modes[modes_cnt++] = *lpddsd;
331 static void flushdisplaymodes(void)
333 HeapFree(GetProcessHeap(), 0, modes);
334 modes = 0;
335 modes_cnt = modes_size = 0;
338 static HRESULT WINAPI enummodescallback(DDSURFACEDESC *lpddsd, void *lpContext)
340 trace("Width = %i, Height = %i, bpp = %i, Refresh Rate = %i, Pitch = %i, flags =%02X\n",
341 lpddsd->dwWidth, lpddsd->dwHeight, U1(lpddsd->ddpfPixelFormat).dwRGBBitCount,
342 U2(*lpddsd).dwRefreshRate, U1(*lpddsd).lPitch, lpddsd->dwFlags);
344 /* Check that the pitch is valid if applicable */
345 if(lpddsd->dwFlags & DDSD_PITCH)
347 ok(U1(*lpddsd).lPitch != 0, "EnumDisplayModes callback with bad pitch\n");
350 /* Check that frequency is valid if applicable
352 * This fails on some Windows drivers or Windows versions, so it isn't important
353 * apparently
354 if(lpddsd->dwFlags & DDSD_REFRESHRATE)
356 ok(U2(*lpddsd).dwRefreshRate != 0, "EnumDisplayModes callback with bad refresh rate\n");
360 adddisplaymode(lpddsd);
361 if(U1(lpddsd->ddpfPixelFormat).dwRGBBitCount == 16)
362 modes16bpp_cnt++;
364 return DDENUMRET_OK;
367 static HRESULT WINAPI enummodescallback_16bit(DDSURFACEDESC *lpddsd, void *lpContext)
369 trace("Width = %i, Height = %i, bpp = %i, Refresh Rate = %i, Pitch = %i, flags =%02X\n",
370 lpddsd->dwWidth, lpddsd->dwHeight, U1(lpddsd->ddpfPixelFormat).dwRGBBitCount,
371 U2(*lpddsd).dwRefreshRate, U1(*lpddsd).lPitch, lpddsd->dwFlags);
373 ok(lpddsd->dwFlags == (DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT|DDSD_PITCH|DDSD_REFRESHRATE),
374 "Wrong surface description flags %02X\n", lpddsd->dwFlags);
375 ok(lpddsd->ddpfPixelFormat.dwFlags == DDPF_RGB, "Wrong pixel format flag %02X\n",
376 lpddsd->ddpfPixelFormat.dwFlags);
377 ok(U1(lpddsd->ddpfPixelFormat).dwRGBBitCount == 16, "Expected 16 bpp got %i\n",
378 U1(lpddsd->ddpfPixelFormat).dwRGBBitCount);
380 /* Check that the pitch is valid if applicable */
381 if(lpddsd->dwFlags & DDSD_PITCH)
383 ok(U1(*lpddsd).lPitch != 0, "EnumDisplayModes callback with bad pitch\n");
386 if(!refresh_rate)
388 if(U2(*lpddsd).dwRefreshRate )
390 refresh_rate = U2(*lpddsd).dwRefreshRate;
391 refresh_rate_cnt++;
394 else
396 if(refresh_rate == U2(*lpddsd).dwRefreshRate)
397 refresh_rate_cnt++;
400 modes16bpp_cnt++;
402 return DDENUMRET_OK;
405 static HRESULT WINAPI enummodescallback_count(DDSURFACEDESC *lpddsd, void *lpContext)
407 ok(lpddsd->dwFlags == (DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT|DDSD_PITCH|DDSD_REFRESHRATE),
408 "Wrong surface description flags %02X\n", lpddsd->dwFlags);
410 modes16bpp_cnt++;
412 return DDENUMRET_OK;
415 static void enumdisplaymodes(void)
417 DDSURFACEDESC ddsd;
418 HRESULT rc;
419 int count, refresh_count;
421 ZeroMemory(&ddsd, sizeof(DDSURFACEDESC));
422 ddsd.dwSize = sizeof(DDSURFACEDESC);
423 ddsd.dwFlags = DDSD_CAPS;
424 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
426 /* Flags parameter is reserved in very old ddraw versions (3 and older?) and must be 0 */
427 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback);
428 ok(rc==DD_OK, "EnumDisplayModes returned: %x\n",rc);
430 count = modes16bpp_cnt;
432 modes16bpp_cnt = 0;
433 ddsd.dwFlags = DDSD_PIXELFORMAT;
434 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
435 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 16;
436 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0xf800;
437 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x07e0;
438 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x001F;
440 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
441 ok(rc==DD_OK, "EnumDisplayModes returned: %x\n",rc);
442 ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
444 modes16bpp_cnt = 0;
445 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0x0000;
446 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x0000;
447 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x0000;
449 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
450 ok(rc==DD_OK, "EnumDisplayModes returned: %x\n",rc);
451 ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
453 modes16bpp_cnt = 0;
454 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0xF0F0;
455 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x0F00;
456 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x000F;
458 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
459 ok(rc==DD_OK, "EnumDisplayModes returned: %x\n",rc);
460 ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
463 modes16bpp_cnt = 0;
464 ddsd.ddpfPixelFormat.dwFlags = DDPF_YUV;
466 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
467 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
468 ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
470 modes16bpp_cnt = 0;
471 ddsd.ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8;
473 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
474 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
475 ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
477 modes16bpp_cnt = 0;
478 ddsd.dwFlags = DDSD_PIXELFORMAT;
479 ddsd.ddpfPixelFormat.dwFlags = 0;
481 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
482 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
483 ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
485 modes16bpp_cnt = 0;
486 ddsd.dwFlags = 0;
488 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_count);
489 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
490 ok(modes16bpp_cnt == modes_cnt, "Expected %d modes got %d\n", modes_cnt, modes16bpp_cnt);
492 modes16bpp_cnt = 0;
493 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_PITCH;
494 U1(ddsd).lPitch = 123;
496 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
497 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
498 ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
500 modes16bpp_cnt = 0;
501 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_REFRESHRATE;
502 /* Ask for a refresh rate that could not possibly be used. But note that
503 * the Windows 'Standard VGA' driver claims to run the display at 1Hz!
505 U2(ddsd).dwRefreshRate = 2;
507 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
508 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
509 ok(modes16bpp_cnt == 0, "Expected 0 modes got %d\n", modes16bpp_cnt);
511 modes16bpp_cnt = 0;
512 ddsd.dwFlags = DDSD_PIXELFORMAT;
514 rc = IDirectDraw_EnumDisplayModes(lpDD, DDEDM_REFRESHRATES, &ddsd, 0, enummodescallback_16bit);
515 if(rc == DDERR_INVALIDPARAMS)
517 skip("Ddraw version too old. Skipping.\n");
518 return;
520 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
521 refresh_count = refresh_rate_cnt;
523 if(refresh_rate)
525 modes16bpp_cnt = 0;
526 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_REFRESHRATE;
527 U2(ddsd).dwRefreshRate = refresh_rate;
529 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
530 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
531 ok(modes16bpp_cnt == refresh_count, "Expected %d modes got %d\n", refresh_count, modes16bpp_cnt);
534 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, NULL, 0, enummodescallback);
535 ok(rc==DD_OK, "EnumDisplayModes returned: %x\n",rc);
539 static void setdisplaymode(int i)
541 HRESULT rc;
542 RECT orig_rect;
544 SetRect(&orig_rect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
546 rc = IDirectDraw_SetCooperativeLevel(lpDD,
547 hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
548 ok(rc==DD_OK,"SetCooperativeLevel returned: %x\n",rc);
549 if (modes[i].dwFlags & DDSD_PIXELFORMAT)
551 if (modes[i].ddpfPixelFormat.dwFlags & DDPF_RGB)
553 rc = IDirectDraw_SetDisplayMode(lpDD,
554 modes[i].dwWidth, modes[i].dwHeight,
555 U1(modes[i].ddpfPixelFormat).dwRGBBitCount);
556 ok(DD_OK==rc || DDERR_UNSUPPORTED==rc,"SetDisplayMode returned: %x\n",rc);
557 if (rc == DD_OK)
559 RECT r, scrn, test, virt;
561 SetRect(&virt, 0, 0, GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN));
562 OffsetRect(&virt, GetSystemMetrics(SM_XVIRTUALSCREEN), GetSystemMetrics(SM_YVIRTUALSCREEN));
563 SetRect(&scrn, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
564 trace("Mode (%dx%d) [%dx%d] (%d %d)x(%d %d)\n", modes[i].dwWidth, modes[i].dwHeight,
565 scrn.right, scrn.bottom, virt.left, virt.top, virt.right, virt.bottom);
566 if (!EqualRect(&scrn, &orig_rect))
568 HRESULT rect_result;
570 /* Check that the client rect was resized */
571 rc = GetClientRect(hwnd, &test);
572 ok(rc!=0, "GetClientRect returned %x\n", rc);
573 rc = EqualRect(&scrn, &test);
574 todo_wine ok(rc!=0, "Fullscreen window has wrong size\n");
576 /* Check that switching to normal cooperative level
577 does not restore the display mode */
578 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_NORMAL);
579 ok(rc==DD_OK, "SetCooperativeLevel returned %x\n", rc);
580 SetRect(&test, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
581 rect_result = EqualRect(&scrn, &test);
582 ok(rect_result!=0, "Setting cooperative level to DDSCL_NORMAL changed the display mode\n");
584 /* Go back to fullscreen */
585 rc = IDirectDraw_SetCooperativeLevel(lpDD,
586 hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
587 ok(rc==DD_OK, "SetCooperativeLevel returned: %x\n",rc);
589 /* If the display mode was changed, set the correct mode
590 to avoid irrelevant failures */
591 if (rect_result == 0)
593 rc = IDirectDraw_SetDisplayMode(lpDD,
594 modes[i].dwWidth, modes[i].dwHeight,
595 U1(modes[i].ddpfPixelFormat).dwRGBBitCount);
596 ok(DD_OK==rc, "SetDisplayMode returned: %x\n",rc);
599 ok(GetClipCursor(&r), "GetClipCursor() failed\n");
600 /* ddraw sets clip rect here to the screen size, even for
601 multiple monitors */
602 ok(EqualRect(&r, &scrn), "Invalid clip rect: (%d %d) x (%d %d)\n",
603 r.left, r.top, r.right, r.bottom);
605 ok(ClipCursor(NULL), "ClipCursor() failed\n");
606 ok(GetClipCursor(&r), "GetClipCursor() failed\n");
607 ok(EqualRect(&r, &virt), "Invalid clip rect: (%d %d) x (%d %d)\n",
608 r.left, r.top, r.right, r.bottom);
610 rc = IDirectDraw_RestoreDisplayMode(lpDD);
611 ok(DD_OK==rc,"RestoreDisplayMode returned: %x\n",rc);
617 static void createsurface(void)
619 DDSURFACEDESC ddsd;
620 DDSCAPS ddscaps;
621 HRESULT rc;
623 ddsd.dwSize = sizeof(ddsd);
624 ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
625 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
626 DDSCAPS_FLIP |
627 DDSCAPS_COMPLEX;
628 ddsd.dwBackBufferCount = 1;
629 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSPrimary, NULL );
630 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
631 ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
632 rc = IDirectDrawSurface_GetAttachedSurface(lpDDSPrimary, &ddscaps, &lpDDSBack);
633 ok(rc==DD_OK,"GetAttachedSurface returned: %x\n",rc);
636 static void destroysurface(void)
638 if( lpDDSPrimary != NULL )
640 IDirectDrawSurface_Release(lpDDSPrimary);
641 lpDDSPrimary = NULL;
645 static void testsurface(void)
647 const char* testMsg = "ddraw device context test";
648 HDC hdc;
649 HRESULT rc;
651 rc = IDirectDrawSurface_GetDC(lpDDSBack, &hdc);
652 ok(rc==DD_OK, "IDirectDrawSurface_GetDC returned: %x\n",rc);
653 SetBkColor(hdc, RGB(0, 0, 255));
654 SetTextColor(hdc, RGB(255, 255, 0));
655 TextOutA(hdc, 0, 0, testMsg, strlen(testMsg));
656 rc = IDirectDrawSurface_ReleaseDC(lpDDSBack, hdc);
657 ok(rc==DD_OK, "IDirectDrawSurface_ReleaseDC returned: %x\n",rc);
659 while (1)
661 rc = IDirectDrawSurface_Flip(lpDDSPrimary, NULL, DDFLIP_WAIT);
662 ok(rc==DD_OK || rc==DDERR_SURFACELOST, "IDirectDrawSurface_BltFast returned: %x\n",rc);
664 if (rc == DD_OK)
666 break;
668 else if (rc == DDERR_SURFACELOST)
670 rc = IDirectDrawSurface_Restore(lpDDSPrimary);
671 ok(rc==DD_OK, "IDirectDrawSurface_Restore returned: %x\n",rc);
676 static void testdisplaymodes(void)
678 int i;
680 for (i = 0; i < modes_cnt; ++i)
682 setdisplaymode(i);
683 createsurface();
684 testsurface();
685 destroysurface();
689 static void testcooperativelevels_normal(void)
691 BOOL sfw;
692 HRESULT rc;
693 DDSURFACEDESC surfacedesc;
694 IDirectDrawSurface *surface = (IDirectDrawSurface *) 0xdeadbeef;
696 memset(&surfacedesc, 0, sizeof(surfacedesc));
697 surfacedesc.dwSize = sizeof(surfacedesc);
698 surfacedesc.ddpfPixelFormat.dwSize = sizeof(surfacedesc.ddpfPixelFormat);
699 surfacedesc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
700 surfacedesc.dwBackBufferCount = 1;
701 surfacedesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
703 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW);
704 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW) returned: %x\n",rc);
706 /* Do some tests with DDSCL_NORMAL mode */
708 /* Fullscreen mode + normal mode + exclusive mode */
710 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NORMAL);
711 ok(rc==DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, received: %x\n", rc);
713 sfw=FALSE;
714 if(hwnd2)
715 sfw=SetForegroundWindow(hwnd2);
716 else
717 skip("Failed to create the second window\n");
719 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NORMAL);
720 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NORMAL) returned: %x\n",rc);
722 if(sfw)
723 ok(GetForegroundWindow()==hwnd,"Expected the main windows (%p) for foreground, received the second one (%p)\n",hwnd, hwnd2);
725 /* Try creating a double buffered primary in fullscreen + exclusive + normal mode */
726 rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
728 if (rc == DDERR_UNSUPPORTEDMODE)
729 skip("Unsupported mode\n");
730 else
732 ok(rc == DD_OK, "IDirectDraw_CreateSurface returned %08x\n", rc);
733 ok(surface!=NULL, "Returned NULL surface pointer\n");
735 if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
737 /* Exclusive mode + normal mode */
738 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_EXCLUSIVE | DDSCL_NORMAL);
739 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_NORMAL) returned: %x\n",rc);
741 /* Fullscreen mode + normal mode */
743 sfw=FALSE;
744 if(hwnd2) sfw=SetForegroundWindow(hwnd2);
746 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_FULLSCREEN | DDSCL_NORMAL);
747 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_FULLSCREEN | DDSCL_NORMAL) returned: %x\n",rc);
749 if(sfw)
750 ok(GetForegroundWindow()==hwnd2,"Expected the second windows (%p) for foreground, received the main one (%p)\n",hwnd2, hwnd);
752 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_FULLSCREEN | DDSCL_NORMAL);
753 ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
755 /* Try creating a double buffered primary in fullscreen + normal mode */
756 rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
757 if (rc == DDERR_UNSUPPORTEDMODE)
758 skip("Unsupported mode\n");
759 else
761 ok(rc == DDERR_NOEXCLUSIVEMODE, "IDirectDraw_CreateSurface returned %08x\n", rc);
762 ok(surface == NULL, "Returned surface pointer is %p\n", surface);
765 if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
767 /* switching from Fullscreen mode to Normal mode */
769 sfw=FALSE;
770 if(hwnd2) sfw=SetForegroundWindow(hwnd2);
772 rc = IDirectDraw_SetCooperativeLevel(lpDD,
773 hwnd, DDSCL_NORMAL);
774 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL) returned: %x\n",rc);
776 if(sfw)
777 ok(GetForegroundWindow()==hwnd2,"Expected the second windows (%p) for foreground, received the main one (%p)\n",hwnd2, hwnd);
779 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
780 ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
782 /* Try creating a double buffered primary in normal mode */
783 rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
784 if (rc == DDERR_UNSUPPORTEDMODE)
785 skip("Unsupported mode\n");
786 else
788 ok(rc == DDERR_NOEXCLUSIVEMODE, "IDirectDraw_CreateSurface returned %08x\n", rc);
789 ok(surface == NULL, "Returned surface pointer is %p\n", surface);
791 if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
793 /* switching from Normal mode to Fullscreen + Normal mode */
795 sfw=FALSE;
796 if(hwnd2) sfw=SetForegroundWindow(hwnd2);
798 rc = IDirectDraw_SetCooperativeLevel(lpDD,
799 hwnd, DDSCL_NORMAL | DDSCL_FULLSCREEN);
800 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL | FULLSCREEN) returned: %x\n",rc);
802 if(sfw)
803 ok(GetForegroundWindow()==hwnd2,"Expected the second windows (%p) for foreground, received the main one (%p)\n",hwnd2, hwnd);
805 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL | DDSCL_FULLSCREEN);
806 ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
808 /* Set the focus window */
810 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW);
811 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW) returned: %x\n",rc);
813 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_SETFOCUSWINDOW);
815 if (rc == DDERR_INVALIDPARAMS)
817 win_skip("NT4/Win95 do not support cooperative levels DDSCL_SETDEVICEWINDOW and DDSCL_SETFOCUSWINDOW\n");
818 return;
821 ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
823 rc = IDirectDraw_SetCooperativeLevel(lpDD,
824 hwnd, DDSCL_SETFOCUSWINDOW);
826 if (rc == DDERR_INVALIDPARAMS)
828 win_skip("NT4/Win95 do not support cooperative levels DDSCL_SETDEVICEWINDOW and DDSCL_SETFOCUSWINDOW\n");
829 return;
832 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
834 /* Set the focus window a second time*/
835 rc = IDirectDraw_SetCooperativeLevel(lpDD,
836 hwnd, DDSCL_SETFOCUSWINDOW);
837 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) the second time returned: %x\n",rc);
839 /* Test DDSCL_SETFOCUSWINDOW with the other flags. They should all fail, except of DDSCL_NOWINDOWCHANGES */
840 rc = IDirectDraw_SetCooperativeLevel(lpDD,
841 hwnd, DDSCL_NORMAL | DDSCL_SETFOCUSWINDOW);
842 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
844 rc = IDirectDraw_SetCooperativeLevel(lpDD,
845 hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETFOCUSWINDOW);
846 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
848 /* This one succeeds */
849 rc = IDirectDraw_SetCooperativeLevel(lpDD,
850 hwnd, DDSCL_NOWINDOWCHANGES | DDSCL_SETFOCUSWINDOW);
851 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NOWINDOWCHANGES | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
853 rc = IDirectDraw_SetCooperativeLevel(lpDD,
854 hwnd, DDSCL_MULTITHREADED | DDSCL_SETFOCUSWINDOW);
855 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_MULTITHREADED | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
857 rc = IDirectDraw_SetCooperativeLevel(lpDD,
858 hwnd, DDSCL_FPUSETUP | DDSCL_SETFOCUSWINDOW);
859 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FPUSETUP | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
861 rc = IDirectDraw_SetCooperativeLevel(lpDD,
862 hwnd, DDSCL_FPUPRESERVE | DDSCL_SETFOCUSWINDOW);
863 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FPUPRESERVE | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
865 rc = IDirectDraw_SetCooperativeLevel(lpDD,
866 hwnd, DDSCL_ALLOWREBOOT | DDSCL_SETFOCUSWINDOW);
867 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_ALLOWREBOOT | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
869 rc = IDirectDraw_SetCooperativeLevel(lpDD,
870 hwnd, DDSCL_ALLOWMODEX | DDSCL_SETFOCUSWINDOW);
871 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_ALLOWMODEX | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
873 /* Set the device window without any other flags. Should give an error */
874 rc = IDirectDraw_SetCooperativeLevel(lpDD,
875 hwnd, DDSCL_SETDEVICEWINDOW);
876 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_SETDEVICEWINDOW) returned: %x\n",rc);
878 /* Set device window with DDSCL_NORMAL */
879 rc = IDirectDraw_SetCooperativeLevel(lpDD,
880 hwnd, DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW);
881 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW) returned: %x\n",rc);
883 /* Also set the focus window. Should give an error */
884 rc = IDirectDraw_SetCooperativeLevel(lpDD,
885 hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETDEVICEWINDOW | DDSCL_SETFOCUSWINDOW);
886 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
888 /* All done */
891 static void testcooperativelevels_exclusive(void)
893 BOOL sfw, success;
894 HRESULT rc;
895 RECT window_rect;
897 /* Do some tests with DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN mode */
899 /* First, resize the window so it is not the same size as any screen */
900 success = SetWindowPos(hwnd, 0, 0, 0, 281, 92, 0);
901 ok(success, "SetWindowPos failed\n");
903 /* Try to set exclusive mode only */
904 rc = IDirectDraw_SetCooperativeLevel(lpDD,
905 hwnd, DDSCL_EXCLUSIVE);
906 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_EXCLUSIVE) returned: %x\n",rc);
908 /* Full screen mode only */
909 rc = IDirectDraw_SetCooperativeLevel(lpDD,
910 hwnd, DDSCL_FULLSCREEN);
911 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FULLSCREEN) returned: %x\n",rc);
913 /* Full screen mode + exclusive mode */
915 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
916 ok(rc==DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, received %x\n", rc);
918 sfw=FALSE;
919 if(hwnd2)
920 sfw=SetForegroundWindow(hwnd2);
921 else
922 skip("Failed to create the second window\n");
924 rc = IDirectDraw_SetCooperativeLevel(lpDD,
925 hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
926 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN) returned: %x\n",rc);
928 if(sfw)
929 ok(GetForegroundWindow()==hwnd,"Expected the main windows (%p) for foreground, received the second one (%p)\n",hwnd, hwnd2);
931 /* rect_before_create is assumed to hold the screen rect */
932 GetClientRect(hwnd, &window_rect);
933 rc = EqualRect(&rect_before_create, &window_rect);
934 ok(rc, "Fullscreen window has wrong size.\n");
936 /* Set the focus window. Should fail */
937 rc = IDirectDraw_SetCooperativeLevel(lpDD,
938 hwnd, DDSCL_SETFOCUSWINDOW);
939 ok(rc==DDERR_HWNDALREADYSET ||
940 broken(rc==DDERR_INVALIDPARAMS) /* NT4/Win95 */,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
943 /* All done */
946 static void testddraw3(void)
948 const GUID My_IID_IDirectDraw3 = {
949 0x618f8ad4,
950 0x8b7a,
951 0x11d0,
952 { 0x8f,0xcc,0x0,0xc0,0x4f,0xd9,0x18,0x9d }
954 IDirectDraw3 *dd3;
955 HRESULT hr;
956 hr = IDirectDraw_QueryInterface(lpDD, &My_IID_IDirectDraw3, (void **) &dd3);
957 ok(hr == E_NOINTERFACE, "QueryInterface for IID_IDirectDraw3 returned 0x%08x, expected E_NOINTERFACE\n", hr);
958 if(SUCCEEDED(hr) && dd3) IDirectDraw3_Release(dd3);
961 static void testddraw7(void)
963 IDirectDraw7 *dd7;
964 HRESULT hr;
965 DDDEVICEIDENTIFIER2 *pdddi2;
966 DWORD dddi2Bytes;
967 DWORD *pend;
969 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
970 if (hr==E_NOINTERFACE)
972 win_skip("DirectDraw7 is not supported\n");
973 return;
975 ok(hr==DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);
977 if (hr==DD_OK)
979 dddi2Bytes = FIELD_OFFSET(DDDEVICEIDENTIFIER2, dwWHQLLevel) + sizeof(DWORD);
981 pdddi2 = HeapAlloc( GetProcessHeap(), 0, dddi2Bytes + 2*sizeof(DWORD) );
982 pend = (DWORD *)((char *)pdddi2 + dddi2Bytes);
983 pend[0] = 0xdeadbeef;
984 pend[1] = 0xdeadbeef;
986 hr = IDirectDraw7_GetDeviceIdentifier(dd7, pdddi2, 0);
987 ok(hr==DD_OK, "get device identifier failed with %08x\n", hr);
989 if (hr==DD_OK)
991 /* szDriver contains the name of the driver DLL */
992 ok(strstr(pdddi2->szDriver, ".dll")!=NULL, "szDriver does not contain DLL name\n");
993 /* check how strings are copied into the structure */
994 ok(pdddi2->szDriver[MAX_DDDEVICEID_STRING - 1]==0, "szDriver not cleared\n");
995 ok(pdddi2->szDescription[MAX_DDDEVICEID_STRING - 1]==0, "szDescription not cleared\n");
996 /* verify that 8 byte structure size alignment will not overwrite memory */
997 ok(pend[0]==0xdeadbeef || broken(pend[0] != 0xdeadbeef), /* win2k */
998 "memory beyond DDDEVICEIDENTIFIER2 overwritten\n");
999 ok(pend[1]==0xdeadbeef, "memory beyond DDDEVICEIDENTIFIER2 overwritten\n");
1002 /* recheck with the DDGDI_GETHOSTIDENTIFIER flag */
1003 pend[0] = 0xdeadbeef;
1004 pend[1] = 0xdeadbeef;
1005 hr = IDirectDraw7_GetDeviceIdentifier(dd7, pdddi2, DDGDI_GETHOSTIDENTIFIER);
1006 ok(hr==DD_OK, "get device identifier failed with %08x\n", hr);
1007 if (hr==DD_OK)
1009 /* szDriver contains the name of the driver DLL */
1010 ok(strstr(pdddi2->szDriver, ".dll")!=NULL, "szDriver does not contain DLL name\n");
1011 /* check how strings are copied into the structure */
1012 ok(pdddi2->szDriver[MAX_DDDEVICEID_STRING - 1]==0, "szDriver not cleared\n");
1013 ok(pdddi2->szDescription[MAX_DDDEVICEID_STRING - 1]==0, "szDescription not cleared\n");
1014 /* verify that 8 byte structure size alignment will not overwrite memory */
1015 ok(pend[0]==0xdeadbeef || broken(pend[0] != 0xdeadbeef), /* win2k */
1016 "memory beyond DDDEVICEIDENTIFIER2 overwritten\n");
1017 ok(pend[1]==0xdeadbeef, "memory beyond DDDEVICEIDENTIFIER2 overwritten\n");
1020 IDirectDraw_Release(dd7);
1021 HeapFree( GetProcessHeap(), 0, pdddi2 );
1025 START_TEST(ddrawmodes)
1027 init_function_pointers();
1029 wc.style = CS_HREDRAW | CS_VREDRAW;
1030 wc.lpfnWndProc = DefWindowProcA;
1031 wc.hInstance = GetModuleHandleA(0);
1032 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
1033 wc.lpszClassName = "TestWindowClass";
1034 if (!RegisterClassA(&wc))
1036 skip("RegisterClassA failed\n");
1037 return;
1040 hwnd2=createwindow();
1041 hwnd=createwindow();
1043 if (!hwnd)
1045 skip("Failed to create the main window\n");
1046 return;
1049 if (!createdirectdraw())
1051 skip("Failed to create the direct draw object\n");
1052 return;
1055 test_DirectDrawEnumerateA();
1056 test_DirectDrawEnumerateW();
1057 test_DirectDrawEnumerateExA();
1058 test_DirectDrawEnumerateExW();
1060 enumdisplaymodes();
1061 if (winetest_interactive)
1062 testdisplaymodes();
1063 flushdisplaymodes();
1064 testddraw3();
1065 testddraw7();
1066 releasedirectdraw();
1068 createdirectdraw();
1069 testcooperativelevels_normal();
1070 releasedirectdraw();
1072 createdirectdraw();
1073 testcooperativelevels_exclusive();
1074 releasedirectdraw();