ddraw/tests: Test matrices in TransformVertices.
[wine.git] / dlls / ddraw / tests / ddrawmodes.c
blobf5b0666cfbe5e811b04d35a052eb1d1a3f79ab4f
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 r, 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 ok(GetClipCursor(&r), "GetClipCursor() failed\n");
602 /* ddraw sets clip rect here to the screen size, even for
603 multiple monitors */
604 ok(EqualRect(&r, &scrn), "Invalid clip rect: (%d %d) x (%d %d)\n",
605 r.left, r.top, r.right, r.bottom);
607 ok(ClipCursor(NULL), "ClipCursor() failed\n");
608 ok(GetClipCursor(&r), "GetClipCursor() failed\n");
609 ok(EqualRect(&r, &virt), "Invalid clip rect: (%d %d) x (%d %d)\n",
610 r.left, r.top, r.right, r.bottom);
612 rc = IDirectDraw_RestoreDisplayMode(lpDD);
613 ok(DD_OK==rc,"RestoreDisplayMode returned: %x\n",rc);
619 static void createsurface(void)
621 DDSURFACEDESC ddsd;
622 DDSCAPS ddscaps;
623 HRESULT rc;
625 ddsd.dwSize = sizeof(ddsd);
626 ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
627 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
628 DDSCAPS_FLIP |
629 DDSCAPS_COMPLEX;
630 ddsd.dwBackBufferCount = 1;
631 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSPrimary, NULL );
632 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
633 ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
634 rc = IDirectDrawSurface_GetAttachedSurface(lpDDSPrimary, &ddscaps, &lpDDSBack);
635 ok(rc==DD_OK,"GetAttachedSurface returned: %x\n",rc);
638 static void destroysurface(void)
640 if( lpDDSPrimary != NULL )
642 IDirectDrawSurface_Release(lpDDSPrimary);
643 lpDDSPrimary = NULL;
647 static void testsurface(void)
649 const char* testMsg = "ddraw device context test";
650 HDC hdc;
651 HRESULT rc;
653 rc = IDirectDrawSurface_GetDC(lpDDSBack, &hdc);
654 ok(rc==DD_OK, "IDirectDrawSurface_GetDC returned: %x\n",rc);
655 SetBkColor(hdc, RGB(0, 0, 255));
656 SetTextColor(hdc, RGB(255, 255, 0));
657 TextOutA(hdc, 0, 0, testMsg, strlen(testMsg));
658 rc = IDirectDrawSurface_ReleaseDC(lpDDSBack, hdc);
659 ok(rc==DD_OK, "IDirectDrawSurface_ReleaseDC returned: %x\n",rc);
661 while (1)
663 rc = IDirectDrawSurface_Flip(lpDDSPrimary, NULL, DDFLIP_WAIT);
664 ok(rc==DD_OK || rc==DDERR_SURFACELOST, "IDirectDrawSurface_BltFast returned: %x\n",rc);
666 if (rc == DD_OK)
668 break;
670 else if (rc == DDERR_SURFACELOST)
672 rc = IDirectDrawSurface_Restore(lpDDSPrimary);
673 ok(rc==DD_OK, "IDirectDrawSurface_Restore returned: %x\n",rc);
678 static void testdisplaymodes(void)
680 int i;
682 for (i = 0; i < modes_cnt; ++i)
684 setdisplaymode(i);
685 createsurface();
686 testsurface();
687 destroysurface();
691 static void testcooperativelevels_normal(void)
693 BOOL sfw;
694 HRESULT rc;
695 DDSURFACEDESC surfacedesc;
696 IDirectDrawSurface *surface = (IDirectDrawSurface *) 0xdeadbeef;
698 memset(&surfacedesc, 0, sizeof(surfacedesc));
699 surfacedesc.dwSize = sizeof(surfacedesc);
700 surfacedesc.ddpfPixelFormat.dwSize = sizeof(surfacedesc.ddpfPixelFormat);
701 surfacedesc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
702 surfacedesc.dwBackBufferCount = 1;
703 surfacedesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
705 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW);
706 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW) returned: %x\n",rc);
708 /* Do some tests with DDSCL_NORMAL mode */
710 /* Fullscreen mode + normal mode + exclusive mode */
712 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NORMAL);
713 ok(rc==DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, received: %x\n", rc);
715 sfw=FALSE;
716 if(hwnd2)
717 sfw=SetForegroundWindow(hwnd2);
718 else
719 skip("Failed to create the second window\n");
721 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NORMAL);
722 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NORMAL) returned: %x\n",rc);
724 if(sfw)
725 ok(GetForegroundWindow()==hwnd,"Expected the main windows (%p) for foreground, received the second one (%p)\n",hwnd, hwnd2);
727 /* Try creating a double buffered primary in fullscreen + exclusive + normal mode */
728 rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
730 if (rc == DDERR_UNSUPPORTEDMODE)
731 skip("Unsupported mode\n");
732 else
734 ok(rc == DD_OK, "IDirectDraw_CreateSurface returned %08x\n", rc);
735 ok(surface!=NULL, "Returned NULL surface pointer\n");
737 if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
739 /* Exclusive mode + normal mode */
740 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_EXCLUSIVE | DDSCL_NORMAL);
741 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_NORMAL) returned: %x\n",rc);
743 /* Fullscreen mode + normal mode */
745 sfw=FALSE;
746 if(hwnd2) sfw=SetForegroundWindow(hwnd2);
748 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_FULLSCREEN | DDSCL_NORMAL);
749 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_FULLSCREEN | DDSCL_NORMAL) returned: %x\n",rc);
751 if(sfw)
752 ok(GetForegroundWindow()==hwnd2,"Expected the second windows (%p) for foreground, received the main one (%p)\n",hwnd2, hwnd);
754 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_FULLSCREEN | DDSCL_NORMAL);
755 ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
757 /* Try creating a double buffered primary in fullscreen + normal mode */
758 rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
759 if (rc == DDERR_UNSUPPORTEDMODE)
760 skip("Unsupported mode\n");
761 else
763 ok(rc == DDERR_NOEXCLUSIVEMODE, "IDirectDraw_CreateSurface returned %08x\n", rc);
764 ok(surface == NULL, "Returned surface pointer is %p\n", surface);
767 if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
769 /* switching from Fullscreen mode to Normal mode */
771 sfw=FALSE;
772 if(hwnd2) sfw=SetForegroundWindow(hwnd2);
774 rc = IDirectDraw_SetCooperativeLevel(lpDD,
775 hwnd, DDSCL_NORMAL);
776 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL) returned: %x\n",rc);
778 if(sfw)
779 ok(GetForegroundWindow()==hwnd2,"Expected the second windows (%p) for foreground, received the main one (%p)\n",hwnd2, hwnd);
781 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
782 ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
784 /* Try creating a double buffered primary in normal mode */
785 rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
786 if (rc == DDERR_UNSUPPORTEDMODE)
787 skip("Unsupported mode\n");
788 else
790 ok(rc == DDERR_NOEXCLUSIVEMODE, "IDirectDraw_CreateSurface returned %08x\n", rc);
791 ok(surface == NULL, "Returned surface pointer is %p\n", surface);
793 if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
795 /* switching from Normal mode to Fullscreen + Normal mode */
797 sfw=FALSE;
798 if(hwnd2) sfw=SetForegroundWindow(hwnd2);
800 rc = IDirectDraw_SetCooperativeLevel(lpDD,
801 hwnd, DDSCL_NORMAL | DDSCL_FULLSCREEN);
802 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL | FULLSCREEN) returned: %x\n",rc);
804 if(sfw)
805 ok(GetForegroundWindow()==hwnd2,"Expected the second windows (%p) for foreground, received the main one (%p)\n",hwnd2, hwnd);
807 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL | DDSCL_FULLSCREEN);
808 ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
810 /* Set the focus window */
812 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW);
813 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW) returned: %x\n",rc);
815 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, 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, "Expected DD_OK, received %x\n", rc);
825 rc = IDirectDraw_SetCooperativeLevel(lpDD,
826 hwnd, DDSCL_SETFOCUSWINDOW);
828 if (rc == DDERR_INVALIDPARAMS)
830 win_skip("NT4/Win95 do not support cooperative levels DDSCL_SETDEVICEWINDOW and DDSCL_SETFOCUSWINDOW\n");
831 return;
834 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
836 /* Set the focus window a second time*/
837 rc = IDirectDraw_SetCooperativeLevel(lpDD,
838 hwnd, DDSCL_SETFOCUSWINDOW);
839 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) the second time returned: %x\n",rc);
841 /* Test DDSCL_SETFOCUSWINDOW with the other flags. They should all fail, except of DDSCL_NOWINDOWCHANGES */
842 rc = IDirectDraw_SetCooperativeLevel(lpDD,
843 hwnd, DDSCL_NORMAL | DDSCL_SETFOCUSWINDOW);
844 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
846 rc = IDirectDraw_SetCooperativeLevel(lpDD,
847 hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETFOCUSWINDOW);
848 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
850 /* This one succeeds */
851 rc = IDirectDraw_SetCooperativeLevel(lpDD,
852 hwnd, DDSCL_NOWINDOWCHANGES | DDSCL_SETFOCUSWINDOW);
853 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NOWINDOWCHANGES | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
855 rc = IDirectDraw_SetCooperativeLevel(lpDD,
856 hwnd, DDSCL_MULTITHREADED | DDSCL_SETFOCUSWINDOW);
857 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_MULTITHREADED | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
859 rc = IDirectDraw_SetCooperativeLevel(lpDD,
860 hwnd, DDSCL_FPUSETUP | DDSCL_SETFOCUSWINDOW);
861 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FPUSETUP | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
863 rc = IDirectDraw_SetCooperativeLevel(lpDD,
864 hwnd, DDSCL_FPUPRESERVE | DDSCL_SETFOCUSWINDOW);
865 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FPUPRESERVE | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
867 rc = IDirectDraw_SetCooperativeLevel(lpDD,
868 hwnd, DDSCL_ALLOWREBOOT | DDSCL_SETFOCUSWINDOW);
869 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_ALLOWREBOOT | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
871 rc = IDirectDraw_SetCooperativeLevel(lpDD,
872 hwnd, DDSCL_ALLOWMODEX | DDSCL_SETFOCUSWINDOW);
873 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_ALLOWMODEX | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
875 /* Set the device window without any other flags. Should give an error */
876 rc = IDirectDraw_SetCooperativeLevel(lpDD,
877 hwnd, DDSCL_SETDEVICEWINDOW);
878 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_SETDEVICEWINDOW) returned: %x\n",rc);
880 /* Set device window with DDSCL_NORMAL */
881 rc = IDirectDraw_SetCooperativeLevel(lpDD,
882 hwnd, DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW);
883 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW) returned: %x\n",rc);
885 /* Also set the focus window. Should give an error */
886 rc = IDirectDraw_SetCooperativeLevel(lpDD,
887 hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETDEVICEWINDOW | DDSCL_SETFOCUSWINDOW);
888 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
890 /* All done */
893 static void testcooperativelevels_exclusive(void)
895 BOOL sfw, success;
896 HRESULT rc;
897 RECT window_rect;
899 /* Do some tests with DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN mode */
901 /* First, resize the window so it is not the same size as any screen */
902 success = SetWindowPos(hwnd, 0, 0, 0, 281, 92, 0);
903 ok(success, "SetWindowPos failed\n");
905 /* Try to set exclusive mode only */
906 rc = IDirectDraw_SetCooperativeLevel(lpDD,
907 hwnd, DDSCL_EXCLUSIVE);
908 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_EXCLUSIVE) returned: %x\n",rc);
910 /* Full screen mode only */
911 rc = IDirectDraw_SetCooperativeLevel(lpDD,
912 hwnd, DDSCL_FULLSCREEN);
913 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FULLSCREEN) returned: %x\n",rc);
915 /* Full screen mode + exclusive mode */
917 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
918 ok(rc==DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, received %x\n", rc);
920 sfw=FALSE;
921 if(hwnd2)
922 sfw=SetForegroundWindow(hwnd2);
923 else
924 skip("Failed to create the second window\n");
926 rc = IDirectDraw_SetCooperativeLevel(lpDD,
927 hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
928 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN) returned: %x\n",rc);
930 if(sfw)
931 ok(GetForegroundWindow()==hwnd,"Expected the main windows (%p) for foreground, received the second one (%p)\n",hwnd, hwnd2);
933 /* rect_before_create is assumed to hold the screen rect */
934 GetClientRect(hwnd, &window_rect);
935 success = EqualRect(&rect_before_create, &window_rect);
936 ok(success, "Fullscreen window has wrong size.\n");
938 /* Set the focus window. Should fail */
939 rc = IDirectDraw_SetCooperativeLevel(lpDD,
940 hwnd, DDSCL_SETFOCUSWINDOW);
941 ok(rc==DDERR_HWNDALREADYSET ||
942 broken(rc==DDERR_INVALIDPARAMS) /* NT4/Win95 */,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
945 /* All done */
948 static void testddraw3(void)
950 const GUID My_IID_IDirectDraw3 = {
951 0x618f8ad4,
952 0x8b7a,
953 0x11d0,
954 { 0x8f,0xcc,0x0,0xc0,0x4f,0xd9,0x18,0x9d }
956 IDirectDraw3 *dd3;
957 HRESULT hr;
958 hr = IDirectDraw_QueryInterface(lpDD, &My_IID_IDirectDraw3, (void **) &dd3);
959 ok(hr == E_NOINTERFACE, "QueryInterface for IID_IDirectDraw3 returned 0x%08x, expected E_NOINTERFACE\n", hr);
960 if(SUCCEEDED(hr) && dd3) IDirectDraw3_Release(dd3);
963 static void testddraw7(void)
965 IDirectDraw7 *dd7;
966 HRESULT hr;
967 DDDEVICEIDENTIFIER2 *pdddi2;
968 DWORD dddi2Bytes;
969 DWORD *pend;
971 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
972 if (hr==E_NOINTERFACE)
974 win_skip("DirectDraw7 is not supported\n");
975 return;
977 ok(hr==DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);
979 if (hr==DD_OK)
981 dddi2Bytes = FIELD_OFFSET(DDDEVICEIDENTIFIER2, dwWHQLLevel) + sizeof(DWORD);
983 pdddi2 = HeapAlloc( GetProcessHeap(), 0, dddi2Bytes + 2*sizeof(DWORD) );
984 pend = (DWORD *)((char *)pdddi2 + dddi2Bytes);
985 pend[0] = 0xdeadbeef;
986 pend[1] = 0xdeadbeef;
988 hr = IDirectDraw7_GetDeviceIdentifier(dd7, pdddi2, 0);
989 ok(hr==DD_OK, "get device identifier failed with %08x\n", hr);
991 if (hr==DD_OK)
993 /* szDriver contains the name of the driver DLL */
994 ok(strstr(pdddi2->szDriver, ".dll")!=NULL, "szDriver does not contain DLL name\n");
995 /* check how strings are copied into the structure */
996 ok(pdddi2->szDriver[MAX_DDDEVICEID_STRING - 1]==0, "szDriver not cleared\n");
997 ok(pdddi2->szDescription[MAX_DDDEVICEID_STRING - 1]==0, "szDescription not cleared\n");
998 /* verify that 8 byte structure size alignment will not overwrite memory */
999 ok(pend[0]==0xdeadbeef || broken(pend[0] != 0xdeadbeef), /* win2k */
1000 "memory beyond DDDEVICEIDENTIFIER2 overwritten\n");
1001 ok(pend[1]==0xdeadbeef, "memory beyond DDDEVICEIDENTIFIER2 overwritten\n");
1004 /* recheck with the DDGDI_GETHOSTIDENTIFIER flag */
1005 pend[0] = 0xdeadbeef;
1006 pend[1] = 0xdeadbeef;
1007 hr = IDirectDraw7_GetDeviceIdentifier(dd7, pdddi2, DDGDI_GETHOSTIDENTIFIER);
1008 ok(hr==DD_OK, "get device identifier failed with %08x\n", hr);
1009 if (hr==DD_OK)
1011 /* szDriver contains the name of the driver DLL */
1012 ok(strstr(pdddi2->szDriver, ".dll")!=NULL, "szDriver does not contain DLL name\n");
1013 /* check how strings are copied into the structure */
1014 ok(pdddi2->szDriver[MAX_DDDEVICEID_STRING - 1]==0, "szDriver not cleared\n");
1015 ok(pdddi2->szDescription[MAX_DDDEVICEID_STRING - 1]==0, "szDescription not cleared\n");
1016 /* verify that 8 byte structure size alignment will not overwrite memory */
1017 ok(pend[0]==0xdeadbeef || broken(pend[0] != 0xdeadbeef), /* win2k */
1018 "memory beyond DDDEVICEIDENTIFIER2 overwritten\n");
1019 ok(pend[1]==0xdeadbeef, "memory beyond DDDEVICEIDENTIFIER2 overwritten\n");
1022 IDirectDraw_Release(dd7);
1023 HeapFree( GetProcessHeap(), 0, pdddi2 );
1027 START_TEST(ddrawmodes)
1029 init_function_pointers();
1031 wc.style = CS_HREDRAW | CS_VREDRAW;
1032 wc.lpfnWndProc = DefWindowProcA;
1033 wc.hInstance = GetModuleHandleA(0);
1034 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
1035 wc.lpszClassName = "TestWindowClass";
1036 if (!RegisterClassA(&wc))
1038 skip("RegisterClassA failed\n");
1039 return;
1042 hwnd2=createwindow();
1043 hwnd=createwindow();
1045 if (!hwnd)
1047 skip("Failed to create the main window\n");
1048 return;
1051 if (!createdirectdraw())
1053 skip("Failed to create the direct draw object\n");
1054 return;
1057 test_DirectDrawEnumerateA();
1058 test_DirectDrawEnumerateW();
1059 test_DirectDrawEnumerateExA();
1060 test_DirectDrawEnumerateExW();
1062 enumdisplaymodes();
1063 if (winetest_interactive)
1064 testdisplaymodes();
1065 flushdisplaymodes();
1066 testddraw3();
1067 testddraw7();
1068 releasedirectdraw();
1070 createdirectdraw();
1071 testcooperativelevels_normal();
1072 releasedirectdraw();
1074 createdirectdraw();
1075 testcooperativelevels_exclusive();
1076 releasedirectdraw();