msvcrt: Use EnumSystemLocalesEx instead of directly accessing kernel32 resources.
[wine.git] / dlls / ddraw / tests / ddrawmodes.c
blob638ff3740129b7c1a89dd59c62f05bf9ccf8cdda
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 if (winetest_debug > 1)
341 trace("Width = %i, Height = %i, bpp = %i, Refresh Rate = %i, Pitch = %i, flags =%02X\n",
342 lpddsd->dwWidth, lpddsd->dwHeight, U1(lpddsd->ddpfPixelFormat).dwRGBBitCount,
343 U2(*lpddsd).dwRefreshRate, U1(*lpddsd).lPitch, lpddsd->dwFlags);
345 /* Check that the pitch is valid if applicable */
346 if(lpddsd->dwFlags & DDSD_PITCH)
348 ok(U1(*lpddsd).lPitch != 0, "EnumDisplayModes callback with bad pitch\n");
351 /* Check that frequency is valid if applicable
353 * This fails on some Windows drivers or Windows versions, so it isn't important
354 * apparently
355 if(lpddsd->dwFlags & DDSD_REFRESHRATE)
357 ok(U2(*lpddsd).dwRefreshRate != 0, "EnumDisplayModes callback with bad refresh rate\n");
361 adddisplaymode(lpddsd);
362 if(U1(lpddsd->ddpfPixelFormat).dwRGBBitCount == 16)
363 modes16bpp_cnt++;
365 return DDENUMRET_OK;
368 static HRESULT WINAPI enummodescallback_16bit(DDSURFACEDESC *lpddsd, void *lpContext)
370 if (winetest_debug > 1)
371 trace("Width = %i, Height = %i, bpp = %i, Refresh Rate = %i, Pitch = %i, flags =%02X\n",
372 lpddsd->dwWidth, lpddsd->dwHeight, U1(lpddsd->ddpfPixelFormat).dwRGBBitCount,
373 U2(*lpddsd).dwRefreshRate, U1(*lpddsd).lPitch, lpddsd->dwFlags);
375 ok(lpddsd->dwFlags == (DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT|DDSD_PITCH|DDSD_REFRESHRATE),
376 "Wrong surface description flags %02X\n", lpddsd->dwFlags);
377 ok(lpddsd->ddpfPixelFormat.dwFlags == DDPF_RGB, "Wrong pixel format flag %02X\n",
378 lpddsd->ddpfPixelFormat.dwFlags);
379 ok(U1(lpddsd->ddpfPixelFormat).dwRGBBitCount == 16, "Expected 16 bpp got %i\n",
380 U1(lpddsd->ddpfPixelFormat).dwRGBBitCount);
382 /* Check that the pitch is valid if applicable */
383 if(lpddsd->dwFlags & DDSD_PITCH)
385 ok(U1(*lpddsd).lPitch != 0, "EnumDisplayModes callback with bad pitch\n");
388 if(!refresh_rate)
390 if(U2(*lpddsd).dwRefreshRate )
392 refresh_rate = U2(*lpddsd).dwRefreshRate;
393 refresh_rate_cnt++;
396 else
398 if(refresh_rate == U2(*lpddsd).dwRefreshRate)
399 refresh_rate_cnt++;
402 modes16bpp_cnt++;
404 return DDENUMRET_OK;
407 static HRESULT WINAPI enummodescallback_count(DDSURFACEDESC *lpddsd, void *lpContext)
409 ok(lpddsd->dwFlags == (DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT|DDSD_PITCH|DDSD_REFRESHRATE),
410 "Wrong surface description flags %02X\n", lpddsd->dwFlags);
412 modes16bpp_cnt++;
414 return DDENUMRET_OK;
417 static void enumdisplaymodes(void)
419 DDSURFACEDESC ddsd;
420 HRESULT rc;
421 int count, refresh_count;
423 ZeroMemory(&ddsd, sizeof(DDSURFACEDESC));
424 ddsd.dwSize = sizeof(DDSURFACEDESC);
425 ddsd.dwFlags = DDSD_CAPS;
426 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
428 /* Flags parameter is reserved in very old ddraw versions (3 and older?) and must be 0 */
429 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback);
430 ok(rc==DD_OK, "EnumDisplayModes returned: %x\n",rc);
432 count = modes16bpp_cnt;
434 modes16bpp_cnt = 0;
435 ddsd.dwFlags = DDSD_PIXELFORMAT;
436 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
437 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 16;
438 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0xf800;
439 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x07e0;
440 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x001F;
442 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
443 ok(rc==DD_OK, "EnumDisplayModes returned: %x\n",rc);
444 ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
446 modes16bpp_cnt = 0;
447 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0x0000;
448 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x0000;
449 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x0000;
451 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
452 ok(rc==DD_OK, "EnumDisplayModes returned: %x\n",rc);
453 ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
455 modes16bpp_cnt = 0;
456 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0xF0F0;
457 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x0F00;
458 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x000F;
460 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
461 ok(rc==DD_OK, "EnumDisplayModes returned: %x\n",rc);
462 ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
465 modes16bpp_cnt = 0;
466 ddsd.ddpfPixelFormat.dwFlags = DDPF_YUV;
468 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
469 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
470 ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
472 modes16bpp_cnt = 0;
473 ddsd.ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8;
475 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
476 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
477 ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
479 modes16bpp_cnt = 0;
480 ddsd.dwFlags = DDSD_PIXELFORMAT;
481 ddsd.ddpfPixelFormat.dwFlags = 0;
483 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
484 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
485 ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
487 modes16bpp_cnt = 0;
488 ddsd.dwFlags = 0;
490 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_count);
491 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
492 ok(modes16bpp_cnt == modes_cnt, "Expected %d modes got %d\n", modes_cnt, modes16bpp_cnt);
494 modes16bpp_cnt = 0;
495 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_PITCH;
496 U1(ddsd).lPitch = 123;
498 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
499 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
500 ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
502 modes16bpp_cnt = 0;
503 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_REFRESHRATE;
504 /* Ask for a refresh rate that could not possibly be used. But note that
505 * the Windows 'Standard VGA' driver claims to run the display at 1Hz!
507 U2(ddsd).dwRefreshRate = 2;
509 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
510 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
511 ok(modes16bpp_cnt == 0, "Expected 0 modes got %d\n", modes16bpp_cnt);
513 modes16bpp_cnt = 0;
514 ddsd.dwFlags = DDSD_PIXELFORMAT;
516 rc = IDirectDraw_EnumDisplayModes(lpDD, DDEDM_REFRESHRATES, &ddsd, 0, enummodescallback_16bit);
517 if(rc == DDERR_INVALIDPARAMS)
519 skip("Ddraw version too old. Skipping.\n");
520 return;
522 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
523 refresh_count = refresh_rate_cnt;
525 if(refresh_rate)
527 modes16bpp_cnt = 0;
528 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_REFRESHRATE;
529 U2(ddsd).dwRefreshRate = refresh_rate;
531 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
532 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
533 ok(modes16bpp_cnt == refresh_count, "Expected %d modes got %d\n", refresh_count, modes16bpp_cnt);
536 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, NULL, 0, enummodescallback);
537 ok(rc==DD_OK, "EnumDisplayModes returned: %x\n",rc);
541 static void setdisplaymode(int i)
543 HRESULT rc;
544 RECT orig_rect;
546 SetRect(&orig_rect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
548 rc = IDirectDraw_SetCooperativeLevel(lpDD,
549 hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
550 ok(rc==DD_OK,"SetCooperativeLevel returned: %x\n",rc);
551 if (modes[i].dwFlags & DDSD_PIXELFORMAT)
553 if (modes[i].ddpfPixelFormat.dwFlags & DDPF_RGB)
555 rc = IDirectDraw_SetDisplayMode(lpDD,
556 modes[i].dwWidth, modes[i].dwHeight,
557 U1(modes[i].ddpfPixelFormat).dwRGBBitCount);
558 ok(DD_OK==rc || DDERR_UNSUPPORTED==rc,"SetDisplayMode returned: %x\n",rc);
559 if (rc == DD_OK)
561 RECT scrn, test, virt;
563 SetRect(&virt, 0, 0, GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN));
564 OffsetRect(&virt, GetSystemMetrics(SM_XVIRTUALSCREEN), GetSystemMetrics(SM_YVIRTUALSCREEN));
565 SetRect(&scrn, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
566 trace("Mode (%dx%d) [%dx%d] (%d %d)x(%d %d)\n", modes[i].dwWidth, modes[i].dwHeight,
567 scrn.right, scrn.bottom, virt.left, virt.top, virt.right, virt.bottom);
568 if (!EqualRect(&scrn, &orig_rect))
570 BOOL rect_result, ret;
572 /* Check that the client rect was resized */
573 ret = GetClientRect(hwnd, &test);
574 ok(ret, "GetClientRect returned %d\n", ret);
575 ret = EqualRect(&scrn, &test);
576 todo_wine ok(ret, "Fullscreen window has wrong size\n");
578 /* Check that switching to normal cooperative level
579 does not restore the display mode */
580 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_NORMAL);
581 ok(rc==DD_OK, "SetCooperativeLevel returned %x\n", rc);
582 SetRect(&test, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
583 rect_result = EqualRect(&scrn, &test);
584 ok(rect_result!=0, "Setting cooperative level to DDSCL_NORMAL changed the display mode\n");
586 /* Go back to fullscreen */
587 rc = IDirectDraw_SetCooperativeLevel(lpDD,
588 hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
589 ok(rc==DD_OK, "SetCooperativeLevel returned: %x\n",rc);
591 /* If the display mode was changed, set the correct mode
592 to avoid irrelevant failures */
593 if (rect_result == 0)
595 rc = IDirectDraw_SetDisplayMode(lpDD,
596 modes[i].dwWidth, modes[i].dwHeight,
597 U1(modes[i].ddpfPixelFormat).dwRGBBitCount);
598 ok(DD_OK==rc, "SetDisplayMode returned: %x\n",rc);
601 rc = IDirectDraw_RestoreDisplayMode(lpDD);
602 ok(DD_OK==rc,"RestoreDisplayMode returned: %x\n",rc);
608 static void createsurface(void)
610 DDSURFACEDESC ddsd;
611 DDSCAPS ddscaps;
612 HRESULT rc;
614 ddsd.dwSize = sizeof(ddsd);
615 ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
616 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
617 DDSCAPS_FLIP |
618 DDSCAPS_COMPLEX;
619 ddsd.dwBackBufferCount = 1;
620 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSPrimary, NULL );
621 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
622 ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
623 rc = IDirectDrawSurface_GetAttachedSurface(lpDDSPrimary, &ddscaps, &lpDDSBack);
624 ok(rc==DD_OK,"GetAttachedSurface returned: %x\n",rc);
627 static void destroysurface(void)
629 if( lpDDSPrimary != NULL )
631 IDirectDrawSurface_Release(lpDDSPrimary);
632 lpDDSPrimary = NULL;
636 static void testsurface(void)
638 const char* testMsg = "ddraw device context test";
639 HDC hdc;
640 HRESULT rc;
642 rc = IDirectDrawSurface_GetDC(lpDDSBack, &hdc);
643 ok(rc==DD_OK, "IDirectDrawSurface_GetDC returned: %x\n",rc);
644 SetBkColor(hdc, RGB(0, 0, 255));
645 SetTextColor(hdc, RGB(255, 255, 0));
646 TextOutA(hdc, 0, 0, testMsg, strlen(testMsg));
647 rc = IDirectDrawSurface_ReleaseDC(lpDDSBack, hdc);
648 ok(rc==DD_OK, "IDirectDrawSurface_ReleaseDC returned: %x\n",rc);
650 while (1)
652 rc = IDirectDrawSurface_Flip(lpDDSPrimary, NULL, DDFLIP_WAIT);
653 ok(rc==DD_OK || rc==DDERR_SURFACELOST, "IDirectDrawSurface_BltFast returned: %x\n",rc);
655 if (rc == DD_OK)
657 break;
659 else if (rc == DDERR_SURFACELOST)
661 rc = IDirectDrawSurface_Restore(lpDDSPrimary);
662 ok(rc==DD_OK, "IDirectDrawSurface_Restore returned: %x\n",rc);
667 static void testdisplaymodes(void)
669 int i;
671 for (i = 0; i < modes_cnt; ++i)
673 setdisplaymode(i);
674 createsurface();
675 testsurface();
676 destroysurface();
680 static void testcooperativelevels_normal(void)
682 BOOL sfw;
683 HRESULT rc;
684 DDSURFACEDESC surfacedesc;
685 IDirectDrawSurface *surface = (IDirectDrawSurface *) 0xdeadbeef;
687 memset(&surfacedesc, 0, sizeof(surfacedesc));
688 surfacedesc.dwSize = sizeof(surfacedesc);
689 surfacedesc.ddpfPixelFormat.dwSize = sizeof(surfacedesc.ddpfPixelFormat);
690 surfacedesc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
691 surfacedesc.dwBackBufferCount = 1;
692 surfacedesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
694 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW);
695 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW) returned: %x\n",rc);
697 /* Do some tests with DDSCL_NORMAL mode */
699 /* Fullscreen mode + normal mode + exclusive mode */
701 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NORMAL);
702 ok(rc==DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, received: %x\n", rc);
704 sfw=FALSE;
705 if(hwnd2)
706 sfw=SetForegroundWindow(hwnd2);
707 else
708 skip("Failed to create the second window\n");
710 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NORMAL);
711 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NORMAL) returned: %x\n",rc);
713 if(sfw)
714 ok(GetForegroundWindow()==hwnd,"Expected the main windows (%p) for foreground, received the second one (%p)\n",hwnd, hwnd2);
716 /* Try creating a double buffered primary in fullscreen + exclusive + normal mode */
717 rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
719 if (rc == DDERR_UNSUPPORTEDMODE)
720 skip("Unsupported mode\n");
721 else
723 ok(rc == DD_OK, "IDirectDraw_CreateSurface returned %08x\n", rc);
724 ok(surface!=NULL, "Returned NULL surface pointer\n");
726 if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
728 /* Exclusive mode + normal mode */
729 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_EXCLUSIVE | DDSCL_NORMAL);
730 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_NORMAL) returned: %x\n",rc);
732 /* Fullscreen mode + normal mode */
734 sfw=FALSE;
735 if(hwnd2) sfw=SetForegroundWindow(hwnd2);
737 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_FULLSCREEN | DDSCL_NORMAL);
738 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_FULLSCREEN | DDSCL_NORMAL) returned: %x\n",rc);
740 if(sfw)
741 ok(GetForegroundWindow()==hwnd2,"Expected the second windows (%p) for foreground, received the main one (%p)\n",hwnd2, hwnd);
743 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_FULLSCREEN | DDSCL_NORMAL);
744 ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
746 /* Try creating a double buffered primary in fullscreen + normal mode */
747 rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
748 if (rc == DDERR_UNSUPPORTEDMODE)
749 skip("Unsupported mode\n");
750 else
752 ok(rc == DDERR_NOEXCLUSIVEMODE, "IDirectDraw_CreateSurface returned %08x\n", rc);
753 ok(surface == NULL, "Returned surface pointer is %p\n", surface);
756 if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
758 /* switching from Fullscreen mode to Normal mode */
760 sfw=FALSE;
761 if(hwnd2) sfw=SetForegroundWindow(hwnd2);
763 rc = IDirectDraw_SetCooperativeLevel(lpDD,
764 hwnd, DDSCL_NORMAL);
765 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL) returned: %x\n",rc);
767 if(sfw)
768 ok(GetForegroundWindow()==hwnd2,"Expected the second windows (%p) for foreground, received the main one (%p)\n",hwnd2, hwnd);
770 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
771 ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
773 /* Try creating a double buffered primary in normal mode */
774 rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
775 if (rc == DDERR_UNSUPPORTEDMODE)
776 skip("Unsupported mode\n");
777 else
779 ok(rc == DDERR_NOEXCLUSIVEMODE, "IDirectDraw_CreateSurface returned %08x\n", rc);
780 ok(surface == NULL, "Returned surface pointer is %p\n", surface);
782 if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
784 /* switching from Normal mode to Fullscreen + Normal mode */
786 sfw=FALSE;
787 if(hwnd2) sfw=SetForegroundWindow(hwnd2);
789 rc = IDirectDraw_SetCooperativeLevel(lpDD,
790 hwnd, DDSCL_NORMAL | DDSCL_FULLSCREEN);
791 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL | FULLSCREEN) returned: %x\n",rc);
793 if(sfw)
794 ok(GetForegroundWindow()==hwnd2,"Expected the second windows (%p) for foreground, received the main one (%p)\n",hwnd2, hwnd);
796 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL | DDSCL_FULLSCREEN);
797 ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
799 /* Set the focus window */
801 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW);
802 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW) returned: %x\n",rc);
804 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_SETFOCUSWINDOW);
806 if (rc == DDERR_INVALIDPARAMS)
808 win_skip("NT4/Win95 do not support cooperative levels DDSCL_SETDEVICEWINDOW and DDSCL_SETFOCUSWINDOW\n");
809 return;
812 ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
814 rc = IDirectDraw_SetCooperativeLevel(lpDD,
815 hwnd, DDSCL_SETFOCUSWINDOW);
817 if (rc == DDERR_INVALIDPARAMS)
819 win_skip("NT4/Win95 do not support cooperative levels DDSCL_SETDEVICEWINDOW and DDSCL_SETFOCUSWINDOW\n");
820 return;
823 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
825 /* Set the focus window a second time*/
826 rc = IDirectDraw_SetCooperativeLevel(lpDD,
827 hwnd, DDSCL_SETFOCUSWINDOW);
828 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) the second time returned: %x\n",rc);
830 /* Test DDSCL_SETFOCUSWINDOW with the other flags. They should all fail, except of DDSCL_NOWINDOWCHANGES */
831 rc = IDirectDraw_SetCooperativeLevel(lpDD,
832 hwnd, DDSCL_NORMAL | DDSCL_SETFOCUSWINDOW);
833 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
835 rc = IDirectDraw_SetCooperativeLevel(lpDD,
836 hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETFOCUSWINDOW);
837 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
839 /* This one succeeds */
840 rc = IDirectDraw_SetCooperativeLevel(lpDD,
841 hwnd, DDSCL_NOWINDOWCHANGES | DDSCL_SETFOCUSWINDOW);
842 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NOWINDOWCHANGES | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
844 rc = IDirectDraw_SetCooperativeLevel(lpDD,
845 hwnd, DDSCL_MULTITHREADED | DDSCL_SETFOCUSWINDOW);
846 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_MULTITHREADED | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
848 rc = IDirectDraw_SetCooperativeLevel(lpDD,
849 hwnd, DDSCL_FPUSETUP | DDSCL_SETFOCUSWINDOW);
850 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FPUSETUP | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
852 rc = IDirectDraw_SetCooperativeLevel(lpDD,
853 hwnd, DDSCL_FPUPRESERVE | DDSCL_SETFOCUSWINDOW);
854 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FPUPRESERVE | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
856 rc = IDirectDraw_SetCooperativeLevel(lpDD,
857 hwnd, DDSCL_ALLOWREBOOT | DDSCL_SETFOCUSWINDOW);
858 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_ALLOWREBOOT | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
860 rc = IDirectDraw_SetCooperativeLevel(lpDD,
861 hwnd, DDSCL_ALLOWMODEX | DDSCL_SETFOCUSWINDOW);
862 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_ALLOWMODEX | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
864 /* Set the device window without any other flags. Should give an error */
865 rc = IDirectDraw_SetCooperativeLevel(lpDD,
866 hwnd, DDSCL_SETDEVICEWINDOW);
867 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_SETDEVICEWINDOW) returned: %x\n",rc);
869 /* Set device window with DDSCL_NORMAL */
870 rc = IDirectDraw_SetCooperativeLevel(lpDD,
871 hwnd, DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW);
872 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW) returned: %x\n",rc);
874 /* Also set the focus window. Should give an error */
875 rc = IDirectDraw_SetCooperativeLevel(lpDD,
876 hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETDEVICEWINDOW | DDSCL_SETFOCUSWINDOW);
877 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
879 /* All done */
882 static void testcooperativelevels_exclusive(void)
884 BOOL sfw, success;
885 HRESULT rc;
886 RECT window_rect;
888 /* Do some tests with DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN mode */
890 /* First, resize the window so it is not the same size as any screen */
891 success = SetWindowPos(hwnd, 0, 0, 0, 281, 92, 0);
892 ok(success, "SetWindowPos failed\n");
894 /* Try to set exclusive mode only */
895 rc = IDirectDraw_SetCooperativeLevel(lpDD,
896 hwnd, DDSCL_EXCLUSIVE);
897 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_EXCLUSIVE) returned: %x\n",rc);
899 /* Full screen mode only */
900 rc = IDirectDraw_SetCooperativeLevel(lpDD,
901 hwnd, DDSCL_FULLSCREEN);
902 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FULLSCREEN) returned: %x\n",rc);
904 /* Full screen mode + exclusive mode */
906 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
907 ok(rc==DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, received %x\n", rc);
909 sfw=FALSE;
910 if(hwnd2)
911 sfw=SetForegroundWindow(hwnd2);
912 else
913 skip("Failed to create the second window\n");
915 rc = IDirectDraw_SetCooperativeLevel(lpDD,
916 hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
917 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN) returned: %x\n",rc);
919 if(sfw)
920 ok(GetForegroundWindow()==hwnd,"Expected the main windows (%p) for foreground, received the second one (%p)\n",hwnd, hwnd2);
922 /* rect_before_create is assumed to hold the screen rect */
923 GetClientRect(hwnd, &window_rect);
924 success = EqualRect(&rect_before_create, &window_rect);
925 ok(success, "Fullscreen window has wrong size.\n");
927 /* Set the focus window. Should fail */
928 rc = IDirectDraw_SetCooperativeLevel(lpDD,
929 hwnd, DDSCL_SETFOCUSWINDOW);
930 ok(rc==DDERR_HWNDALREADYSET ||
931 broken(rc==DDERR_INVALIDPARAMS) /* NT4/Win95 */,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
934 /* All done */
937 static void testddraw3(void)
939 const GUID My_IID_IDirectDraw3 = {
940 0x618f8ad4,
941 0x8b7a,
942 0x11d0,
943 { 0x8f,0xcc,0x0,0xc0,0x4f,0xd9,0x18,0x9d }
945 IDirectDraw3 *dd3;
946 HRESULT hr;
947 hr = IDirectDraw_QueryInterface(lpDD, &My_IID_IDirectDraw3, (void **) &dd3);
948 ok(hr == E_NOINTERFACE, "QueryInterface for IID_IDirectDraw3 returned 0x%08x, expected E_NOINTERFACE\n", hr);
949 if(SUCCEEDED(hr) && dd3) IDirectDraw3_Release(dd3);
952 static void testddraw7(void)
954 IDirectDraw7 *dd7;
955 HRESULT hr;
956 DDDEVICEIDENTIFIER2 *pdddi2;
957 DWORD dddi2Bytes;
958 DWORD *pend;
960 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
961 if (hr==E_NOINTERFACE)
963 win_skip("DirectDraw7 is not supported\n");
964 return;
966 ok(hr==DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);
968 if (hr==DD_OK)
970 dddi2Bytes = FIELD_OFFSET(DDDEVICEIDENTIFIER2, dwWHQLLevel) + sizeof(DWORD);
972 pdddi2 = HeapAlloc( GetProcessHeap(), 0, dddi2Bytes + 2*sizeof(DWORD) );
973 pend = (DWORD *)((char *)pdddi2 + dddi2Bytes);
974 pend[0] = 0xdeadbeef;
975 pend[1] = 0xdeadbeef;
977 hr = IDirectDraw7_GetDeviceIdentifier(dd7, pdddi2, 0);
978 ok(hr==DD_OK, "get device identifier failed with %08x\n", hr);
980 if (hr==DD_OK)
982 /* szDriver contains the name of the driver DLL */
983 ok(strstr(pdddi2->szDriver, ".dll")!=NULL, "szDriver does not contain DLL name\n");
984 /* check how strings are copied into the structure */
985 ok(pdddi2->szDriver[MAX_DDDEVICEID_STRING - 1]==0, "szDriver not cleared\n");
986 ok(pdddi2->szDescription[MAX_DDDEVICEID_STRING - 1]==0, "szDescription not cleared\n");
987 /* verify that 8 byte structure size alignment will not overwrite memory */
988 ok(pend[0]==0xdeadbeef || broken(pend[0] != 0xdeadbeef), /* win2k */
989 "memory beyond DDDEVICEIDENTIFIER2 overwritten\n");
990 ok(pend[1]==0xdeadbeef, "memory beyond DDDEVICEIDENTIFIER2 overwritten\n");
993 /* recheck with the DDGDI_GETHOSTIDENTIFIER flag */
994 pend[0] = 0xdeadbeef;
995 pend[1] = 0xdeadbeef;
996 hr = IDirectDraw7_GetDeviceIdentifier(dd7, pdddi2, DDGDI_GETHOSTIDENTIFIER);
997 ok(hr==DD_OK, "get device identifier failed with %08x\n", hr);
998 if (hr==DD_OK)
1000 /* szDriver contains the name of the driver DLL */
1001 ok(strstr(pdddi2->szDriver, ".dll")!=NULL, "szDriver does not contain DLL name\n");
1002 /* check how strings are copied into the structure */
1003 ok(pdddi2->szDriver[MAX_DDDEVICEID_STRING - 1]==0, "szDriver not cleared\n");
1004 ok(pdddi2->szDescription[MAX_DDDEVICEID_STRING - 1]==0, "szDescription not cleared\n");
1005 /* verify that 8 byte structure size alignment will not overwrite memory */
1006 ok(pend[0]==0xdeadbeef || broken(pend[0] != 0xdeadbeef), /* win2k */
1007 "memory beyond DDDEVICEIDENTIFIER2 overwritten\n");
1008 ok(pend[1]==0xdeadbeef, "memory beyond DDDEVICEIDENTIFIER2 overwritten\n");
1011 IDirectDraw_Release(dd7);
1012 HeapFree( GetProcessHeap(), 0, pdddi2 );
1016 START_TEST(ddrawmodes)
1018 init_function_pointers();
1020 wc.style = CS_HREDRAW | CS_VREDRAW;
1021 wc.lpfnWndProc = DefWindowProcA;
1022 wc.hInstance = GetModuleHandleA(0);
1023 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
1024 wc.lpszClassName = "TestWindowClass";
1025 if (!RegisterClassA(&wc))
1027 skip("RegisterClassA failed\n");
1028 return;
1031 hwnd2=createwindow();
1032 hwnd=createwindow();
1034 if (!hwnd)
1036 skip("Failed to create the main window\n");
1037 return;
1040 if (!createdirectdraw())
1042 skip("Failed to create the direct draw object\n");
1043 return;
1046 test_DirectDrawEnumerateA();
1047 test_DirectDrawEnumerateW();
1048 test_DirectDrawEnumerateExA();
1049 test_DirectDrawEnumerateExW();
1051 enumdisplaymodes();
1052 if (winetest_interactive)
1053 testdisplaymodes();
1054 flushdisplaymodes();
1055 testddraw3();
1056 testddraw7();
1057 releasedirectdraw();
1059 createdirectdraw();
1060 testcooperativelevels_normal();
1061 releasedirectdraw();
1063 createdirectdraw();
1064 testcooperativelevels_exclusive();
1065 releasedirectdraw();