Release 1.4.1.
[wine] / dlls / ddraw / tests / ddrawmodes.c
1 /*
2  * Unit tests for ddraw functions
3  *
4  *
5  * Part of this test involves changing the screen resolution. But this is
6  * really disrupting if the user is doing something else and is not very nice
7  * to CRT screens. Plus, ideally it needs someone watching it to check that
8  * each mode displays correctly.
9  * So this is only done if the test is being run in interactive mode.
10  *
11  * Copyright (C) 2003 Sami Aario
12  *
13  * This library is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU Lesser General Public
15  * License as published by the Free Software Foundation; either
16  * version 2.1 of the License, or (at your option) any later version.
17  *
18  * This library is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21  * Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public
24  * License along with this library; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26  */
27
28 #include <assert.h>
29 #include "wine/test.h"
30 #include "ddraw.h"
31
32 static LPDIRECTDRAW lpDD = NULL;
33 static LPDIRECTDRAWSURFACE lpDDSPrimary = NULL;
34 static LPDIRECTDRAWSURFACE lpDDSBack = NULL;
35 static WNDCLASS wc;
36 static HWND hwnd, hwnd2;
37 static int modes_cnt;
38 static int modes_size;
39 static LPDDSURFACEDESC 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;
45
46 static HRESULT (WINAPI *pDirectDrawEnumerateA)(LPDDENUMCALLBACKA,LPVOID);
47 static HRESULT (WINAPI *pDirectDrawEnumerateW)(LPDDENUMCALLBACKW,LPVOID);
48 static HRESULT (WINAPI *pDirectDrawEnumerateExA)(LPDDENUMCALLBACKEXA,LPVOID,DWORD);
49 static HRESULT (WINAPI *pDirectDrawEnumerateExW)(LPDDENUMCALLBACKEXW,LPVOID,DWORD);
50
51 static void init_function_pointers(void)
52 {
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");
58 }
59
60 static HWND createwindow(void)
61 {
62     HWND hwnd;
63
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);
69
70     ShowWindow(hwnd, SW_HIDE);
71     UpdateWindow(hwnd);
72     SetFocus(hwnd);
73
74     return hwnd;
75 }
76
77 static BOOL createdirectdraw(void)
78 {
79     HRESULT rc;
80
81     SetRect(&rect_before_create, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
82
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;
88     }
89     return TRUE;
90 }
91
92
93 static void releasedirectdraw(void)
94 {
95     if( lpDD != NULL )
96     {
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");
104     }
105 }
106
107 static BOOL WINAPI test_nullcontext_callbackA(GUID *lpGUID, LPSTR lpDriverDescription,
108                                               LPSTR lpDriverName, LPVOID lpContext)
109 {
110     trace("test_nullcontext_callbackA: %p %s %s %p\n",
111           lpGUID, lpDriverDescription, lpDriverName, lpContext);
112
113     ok(!lpContext, "Expected NULL lpContext\n");
114
115     return TRUE;
116 }
117
118 static BOOL WINAPI test_context_callbackA(GUID *lpGUID, LPSTR lpDriverDescription,
119                                           LPSTR lpDriverName, LPVOID lpContext)
120 {
121     trace("test_context_callbackA: %p %s %s %p\n",
122           lpGUID, lpDriverDescription, lpDriverName, lpContext);
123
124     ok(lpContext == (LPVOID)0xdeadbeef, "Expected non-NULL lpContext\n");
125
126     return TRUE;
127 }
128
129 static void test_DirectDrawEnumerateA(void)
130 {
131     HRESULT ret;
132
133     if (!pDirectDrawEnumerateA)
134     {
135         win_skip("DirectDrawEnumerateA is not available\n");
136         return;
137     }
138
139     /* Test with NULL callback parameter. */
140     ret = pDirectDrawEnumerateA(NULL, NULL);
141     ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
142
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);
147
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, (LPVOID)0xdeadbeef);
151     ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
152 }
153
154 static BOOL WINAPI test_callbackW(GUID *lpGUID, LPWSTR lpDriverDescription,
155                                   LPWSTR lpDriverName, LPVOID lpContext)
156 {
157     ok(0, "The callback should not be invoked by DirectDrawEnumerateW\n");
158     return TRUE;
159 }
160
161 static void test_DirectDrawEnumerateW(void)
162 {
163     HRESULT ret;
164
165     if (!pDirectDrawEnumerateW)
166     {
167         win_skip("DirectDrawEnumerateW is not available\n");
168         return;
169     }
170
171     /* DirectDrawEnumerateW is not implemented on Windows. */
172
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);
178
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);
184
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);
188 }
189
190 static BOOL WINAPI test_nullcontext_callbackExA(GUID *lpGUID, LPSTR lpDriverDescription,
191                                                 LPSTR lpDriverName, LPVOID lpContext,
192                                                 HMONITOR hm)
193 {
194     trace("test_nullcontext_callbackExA: %p %s %s %p %p\n", lpGUID,
195           lpDriverDescription, lpDriverName, lpContext, hm);
196
197     ok(!lpContext, "Expected NULL lpContext\n");
198
199     return TRUE;
200 }
201
202 static BOOL WINAPI test_context_callbackExA(GUID *lpGUID, LPSTR lpDriverDescription,
203                                             LPSTR lpDriverName, LPVOID lpContext,
204                                             HMONITOR hm)
205 {
206     trace("test_context_callbackExA: %p %s %s %p %p\n", lpGUID,
207           lpDriverDescription, lpDriverName, lpContext, hm);
208
209     ok(lpContext == (LPVOID)0xdeadbeef, "Expected non-NULL lpContext\n");
210
211     return TRUE;
212 }
213
214 static void test_DirectDrawEnumerateExA(void)
215 {
216     HRESULT ret;
217
218     if (!pDirectDrawEnumerateExA)
219     {
220         win_skip("DirectDrawEnumerateExA is not available\n");
221         return;
222     }
223
224     /* Test with NULL callback parameter. */
225     ret = pDirectDrawEnumerateExA(NULL, NULL, 0);
226     ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
227
228     /* Test with valid callback parameter and invalid flags */
229     ret = pDirectDrawEnumerateExA(test_nullcontext_callbackExA, NULL, ~0);
230     ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
231
232     /* Test with valid callback parameter and NULL context parameter. */
233     trace("Calling DirectDrawEnumerateExA with empty flags and NULL context.\n");
234     ret = pDirectDrawEnumerateExA(test_nullcontext_callbackExA, NULL, 0);
235     ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
236
237     /* Test with valid callback parameter and non-NULL context parameter. */
238     trace("Calling DirectDrawEnumerateExA with empty flags and non-NULL context.\n");
239     ret = pDirectDrawEnumerateExA(test_context_callbackExA, (LPVOID)0xdeadbeef, 0);
240     ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
241
242     /* Test with valid callback parameter, NULL context parameter, and all flags set. */
243     trace("Calling DirectDrawEnumerateExA with all flags set and NULL context.\n");
244     ret = pDirectDrawEnumerateExA(test_nullcontext_callbackExA, NULL,
245                                   DDENUM_ATTACHEDSECONDARYDEVICES |
246                                   DDENUM_DETACHEDSECONDARYDEVICES |
247                                   DDENUM_NONDISPLAYDEVICES);
248     ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
249 }
250
251 static BOOL WINAPI test_callbackExW(GUID *lpGUID, LPWSTR lpDriverDescription,
252                                     LPWSTR lpDriverName, LPVOID lpContext,
253                                     HMONITOR hm)
254 {
255     ok(0, "The callback should not be invoked by DirectDrawEnumerateExW.\n");
256     return TRUE;
257 }
258
259 static void test_DirectDrawEnumerateExW(void)
260 {
261     HRESULT ret;
262
263     if (!pDirectDrawEnumerateExW)
264     {
265         win_skip("DirectDrawEnumerateExW is not available\n");
266         return;
267     }
268
269     /* DirectDrawEnumerateExW is not implemented on Windows. */
270
271     /* Test with NULL callback parameter. */
272     ret = pDirectDrawEnumerateExW(NULL, NULL, 0);
273     ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
274
275     /* Test with invalid callback parameter. */
276     ret = pDirectDrawEnumerateExW((LPDDENUMCALLBACKEXW)0xdeadbeef, NULL, 0);
277     ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
278
279     /* Test with valid callback parameter and invalid flags */
280     ret = pDirectDrawEnumerateExW(test_callbackExW, NULL, ~0);
281     ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
282
283     /* Test with valid callback parameter and NULL context parameter. */
284     ret = pDirectDrawEnumerateExW(test_callbackExW, NULL, 0);
285     ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
286
287     /* Test with valid callback parameter, NULL context parameter, and all flags set. */
288     ret = pDirectDrawEnumerateExW(test_callbackExW, NULL,
289                                   DDENUM_ATTACHEDSECONDARYDEVICES |
290                                   DDENUM_DETACHEDSECONDARYDEVICES |
291                                   DDENUM_NONDISPLAYDEVICES);
292     ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
293 }
294
295 static void adddisplaymode(LPDDSURFACEDESC lpddsd)
296 {
297     if (!modes)
298         modes = HeapAlloc(GetProcessHeap(), 0, (modes_size = 2) * sizeof(DDSURFACEDESC));
299     if (modes_cnt == modes_size)
300         modes = HeapReAlloc(GetProcessHeap(), 0, modes, (modes_size *= 2) * sizeof(DDSURFACEDESC));
301     assert(modes);
302     modes[modes_cnt++] = *lpddsd;
303 }
304
305 static void flushdisplaymodes(void)
306 {
307     HeapFree(GetProcessHeap(), 0, modes);
308     modes = 0;
309     modes_cnt = modes_size = 0;
310 }
311
312 static HRESULT WINAPI enummodescallback(LPDDSURFACEDESC lpddsd, LPVOID lpContext)
313 {
314     trace("Width = %i, Height = %i, bpp = %i, Refresh Rate = %i, Pitch = %i, flags =%02X\n",
315         lpddsd->dwWidth, lpddsd->dwHeight, U1(lpddsd->ddpfPixelFormat).dwRGBBitCount,
316           U2(*lpddsd).dwRefreshRate, U1(*lpddsd).lPitch, lpddsd->dwFlags);
317
318     /* Check that the pitch is valid if applicable */
319     if(lpddsd->dwFlags & DDSD_PITCH)
320     {
321         ok(U1(*lpddsd).lPitch != 0, "EnumDisplayModes callback with bad pitch\n");
322     }
323
324     /* Check that frequency is valid if applicable
325      *
326      * This fails on some Windows drivers or Windows versions, so it isn't important
327      * apparently
328     if(lpddsd->dwFlags & DDSD_REFRESHRATE)
329     {
330         ok(U2(*lpddsd).dwRefreshRate != 0, "EnumDisplayModes callback with bad refresh rate\n");
331     }
332      */
333
334     adddisplaymode(lpddsd);
335     if(U1(lpddsd->ddpfPixelFormat).dwRGBBitCount == 16)
336         modes16bpp_cnt++;
337
338     return DDENUMRET_OK;
339 }
340
341 static HRESULT WINAPI enummodescallback_16bit(LPDDSURFACEDESC lpddsd, LPVOID lpContext)
342 {
343     trace("Width = %i, Height = %i, bpp = %i, Refresh Rate = %i, Pitch = %i, flags =%02X\n",
344         lpddsd->dwWidth, lpddsd->dwHeight, U1(lpddsd->ddpfPixelFormat).dwRGBBitCount,
345           U2(*lpddsd).dwRefreshRate, U1(*lpddsd).lPitch, lpddsd->dwFlags);
346
347     ok(lpddsd->dwFlags == (DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT|DDSD_PITCH|DDSD_REFRESHRATE),
348             "Wrong surface description flags %02X\n", lpddsd->dwFlags);
349     ok(lpddsd->ddpfPixelFormat.dwFlags == DDPF_RGB, "Wrong pixel format flag %02X\n",
350             lpddsd->ddpfPixelFormat.dwFlags);
351     ok(U1(lpddsd->ddpfPixelFormat).dwRGBBitCount == 16, "Expected 16 bpp got %i\n",
352             U1(lpddsd->ddpfPixelFormat).dwRGBBitCount);
353
354     /* Check that the pitch is valid if applicable */
355     if(lpddsd->dwFlags & DDSD_PITCH)
356     {
357         ok(U1(*lpddsd).lPitch != 0, "EnumDisplayModes callback with bad pitch\n");
358     }
359
360     if(!refresh_rate)
361     {
362         if(U2(*lpddsd).dwRefreshRate )
363         {
364             refresh_rate = U2(*lpddsd).dwRefreshRate;
365             refresh_rate_cnt++;
366         }
367     }
368     else
369     {
370         if(refresh_rate == U2(*lpddsd).dwRefreshRate)
371             refresh_rate_cnt++;
372     }
373
374     modes16bpp_cnt++;
375
376     return DDENUMRET_OK;
377 }
378
379 static HRESULT WINAPI enummodescallback_count(LPDDSURFACEDESC lpddsd, LPVOID lpContext)
380 {
381     ok(lpddsd->dwFlags == (DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT|DDSD_PITCH|DDSD_REFRESHRATE),
382             "Wrong surface description flags %02X\n", lpddsd->dwFlags);
383
384     modes16bpp_cnt++;
385
386     return DDENUMRET_OK;
387 }
388
389 static void enumdisplaymodes(void)
390 {
391     DDSURFACEDESC ddsd;
392     HRESULT rc;
393     int count, refresh_count;
394
395     ZeroMemory(&ddsd, sizeof(DDSURFACEDESC));
396     ddsd.dwSize = sizeof(DDSURFACEDESC);
397     ddsd.dwFlags = DDSD_CAPS;
398     ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
399
400     /* Flags parameter is reserved in very old ddraw versions (3 and older?) and must be 0 */
401     rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback);
402     ok(rc==DD_OK, "EnumDisplayModes returned: %x\n",rc);
403
404     count = modes16bpp_cnt;
405
406     modes16bpp_cnt = 0;
407     ddsd.dwFlags = DDSD_PIXELFORMAT;
408     ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
409     U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 16;
410     U2(ddsd.ddpfPixelFormat).dwRBitMask = 0xf800;
411     U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x07e0;
412     U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x001F;
413
414     rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
415     ok(rc==DD_OK, "EnumDisplayModes returned: %x\n",rc);
416     ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
417
418     modes16bpp_cnt = 0;
419     U2(ddsd.ddpfPixelFormat).dwRBitMask = 0x0000;
420     U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x0000;
421     U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x0000;
422
423     rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
424     ok(rc==DD_OK, "EnumDisplayModes returned: %x\n",rc);
425     ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
426
427     modes16bpp_cnt = 0;
428     U2(ddsd.ddpfPixelFormat).dwRBitMask = 0xF0F0;
429     U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x0F00;
430     U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x000F;
431
432     rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
433     ok(rc==DD_OK, "EnumDisplayModes returned: %x\n",rc);
434     ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
435
436
437     modes16bpp_cnt = 0;
438     ddsd.ddpfPixelFormat.dwFlags = DDPF_YUV;
439
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);
443
444     modes16bpp_cnt = 0;
445     ddsd.ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8;
446
447     rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
448     ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
449     ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
450
451     modes16bpp_cnt = 0;
452     ddsd.dwFlags = DDSD_PIXELFORMAT;
453     ddsd.ddpfPixelFormat.dwFlags = 0;
454
455     rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
456     ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
457     ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
458
459     modes16bpp_cnt = 0;
460     ddsd.dwFlags = 0;
461
462     rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_count);
463     ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
464     ok(modes16bpp_cnt == modes_cnt, "Expected %d modes got %d\n", modes_cnt, modes16bpp_cnt);
465
466     modes16bpp_cnt = 0;
467     ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_PITCH;
468     U1(ddsd).lPitch = 123;
469
470     rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
471     ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
472     ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
473
474     modes16bpp_cnt = 0;
475     ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_REFRESHRATE;
476     U2(ddsd).dwRefreshRate = 1;
477
478     rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
479     ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
480     ok(modes16bpp_cnt == 0, "Expected 0 modes got %d\n", modes16bpp_cnt);
481
482     modes16bpp_cnt = 0;
483     ddsd.dwFlags = DDSD_PIXELFORMAT;
484
485     rc = IDirectDraw_EnumDisplayModes(lpDD, DDEDM_REFRESHRATES, &ddsd, 0, enummodescallback_16bit);
486     if(rc == DDERR_INVALIDPARAMS)
487     {
488         skip("Ddraw version too old. Skipping.\n");
489         return;
490     }
491     ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
492     refresh_count = refresh_rate_cnt;
493
494     if(refresh_rate)
495     {
496         modes16bpp_cnt = 0;
497         ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_REFRESHRATE;
498         U2(ddsd).dwRefreshRate = refresh_rate;
499
500         rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
501         ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
502         ok(modes16bpp_cnt == refresh_count, "Expected %d modes got %d\n", refresh_count, modes16bpp_cnt);
503     }
504
505     rc = IDirectDraw_EnumDisplayModes(lpDD, 0, NULL, 0, enummodescallback);
506     ok(rc==DD_OK, "EnumDisplayModes returned: %x\n",rc);
507 }
508
509
510 static void setdisplaymode(int i)
511 {
512     HRESULT rc;
513     RECT orig_rect;
514
515     SetRect(&orig_rect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
516
517     rc = IDirectDraw_SetCooperativeLevel(lpDD,
518         hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
519     ok(rc==DD_OK,"SetCooperativeLevel returned: %x\n",rc);
520     if (modes[i].dwFlags & DDSD_PIXELFORMAT)
521     {
522         if (modes[i].ddpfPixelFormat.dwFlags & DDPF_RGB)
523         {
524             rc = IDirectDraw_SetDisplayMode(lpDD,
525                 modes[i].dwWidth, modes[i].dwHeight,
526                 U1(modes[i].ddpfPixelFormat).dwRGBBitCount);
527             ok(DD_OK==rc || DDERR_UNSUPPORTED==rc,"SetDisplayMode returned: %x\n",rc);
528             if (rc == DD_OK)
529             {
530                 RECT r, scrn, test, virt;
531
532                 SetRect(&virt, 0, 0, GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN));
533                 OffsetRect(&virt, GetSystemMetrics(SM_XVIRTUALSCREEN), GetSystemMetrics(SM_YVIRTUALSCREEN));
534                 SetRect(&scrn, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
535                 trace("Mode (%dx%d) [%dx%d] (%d %d)x(%d %d)\n", modes[i].dwWidth, modes[i].dwHeight,
536                       scrn.right, scrn.bottom, virt.left, virt.top, virt.right, virt.bottom);
537                 if (!EqualRect(&scrn, &orig_rect))
538                 {
539                     HRESULT rect_result;
540
541                     /* Check that the client rect was resized */
542                     rc = GetClientRect(hwnd, &test);
543                     ok(rc!=0, "GetClientRect returned %x\n", rc);
544                     rc = EqualRect(&scrn, &test);
545                     todo_wine ok(rc!=0, "Fullscreen window has wrong size\n");
546
547                     /* Check that switching to normal cooperative level
548                        does not restore the display mode */
549                     rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_NORMAL);
550                     ok(rc==DD_OK, "SetCooperativeLevel returned %x\n", rc);
551                     SetRect(&test, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
552                     rect_result = EqualRect(&scrn, &test);
553                     ok(rect_result!=0, "Setting cooperative level to DDSCL_NORMAL changed the display mode\n");
554
555                     /* Go back to fullscreen */
556                     rc = IDirectDraw_SetCooperativeLevel(lpDD,
557                         hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
558                     ok(rc==DD_OK, "SetCooperativeLevel returned: %x\n",rc);
559
560                     /* If the display mode was changed, set the correct mode
561                        to avoid irrelevant failures */
562                     if (rect_result == 0)
563                     {
564                         rc = IDirectDraw_SetDisplayMode(lpDD,
565                             modes[i].dwWidth, modes[i].dwHeight,
566                             U1(modes[i].ddpfPixelFormat).dwRGBBitCount);
567                         ok(DD_OK==rc, "SetDisplayMode returned: %x\n",rc);
568                     }
569                 }
570                 ok(GetClipCursor(&r), "GetClipCursor() failed\n");
571                 /* ddraw sets clip rect here to the screen size, even for
572                    multiple monitors */
573                 ok(EqualRect(&r, &scrn), "Invalid clip rect: (%d %d) x (%d %d)\n",
574                    r.left, r.top, r.right, r.bottom);
575
576                 ok(ClipCursor(NULL), "ClipCursor() failed\n");
577                 ok(GetClipCursor(&r), "GetClipCursor() failed\n");
578                 ok(EqualRect(&r, &virt), "Invalid clip rect: (%d %d) x (%d %d)\n",
579                    r.left, r.top, r.right, r.bottom);
580
581                 rc = IDirectDraw_RestoreDisplayMode(lpDD);
582                 ok(DD_OK==rc,"RestoreDisplayMode returned: %x\n",rc);
583             }
584         }
585     }
586 }
587
588 static void createsurface(void)
589 {
590     DDSURFACEDESC ddsd;
591     DDSCAPS ddscaps;
592     HRESULT rc;
593
594     ddsd.dwSize = sizeof(ddsd);
595     ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
596     ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
597         DDSCAPS_FLIP |
598         DDSCAPS_COMPLEX;
599     ddsd.dwBackBufferCount = 1;
600     rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSPrimary, NULL );
601     ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
602     ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
603     rc = IDirectDrawSurface_GetAttachedSurface(lpDDSPrimary, &ddscaps, &lpDDSBack);
604     ok(rc==DD_OK,"GetAttachedSurface returned: %x\n",rc);
605 }
606
607 static void destroysurface(void)
608 {
609     if( lpDDSPrimary != NULL )
610     {
611         IDirectDrawSurface_Release(lpDDSPrimary);
612         lpDDSPrimary = NULL;
613     }
614 }
615
616 static void testsurface(void)
617 {
618     const char* testMsg = "ddraw device context test";
619     HDC hdc;
620     HRESULT rc;
621
622     rc = IDirectDrawSurface_GetDC(lpDDSBack, &hdc);
623     ok(rc==DD_OK, "IDirectDrawSurface_GetDC returned: %x\n",rc);
624     SetBkColor(hdc, RGB(0, 0, 255));
625     SetTextColor(hdc, RGB(255, 255, 0));
626     TextOut(hdc, 0, 0, testMsg, lstrlen(testMsg));
627     IDirectDrawSurface_ReleaseDC(lpDDSBack, hdc);
628     ok(rc==DD_OK, "IDirectDrawSurface_ReleaseDC returned: %x\n",rc);
629
630     while (1)
631     {
632         rc = IDirectDrawSurface_Flip(lpDDSPrimary, NULL, DDFLIP_WAIT);
633         ok(rc==DD_OK || rc==DDERR_SURFACELOST, "IDirectDrawSurface_BltFast returned: %x\n",rc);
634
635         if (rc == DD_OK)
636         {
637             break;
638         }
639         else if (rc == DDERR_SURFACELOST)
640         {
641             rc = IDirectDrawSurface_Restore(lpDDSPrimary);
642             ok(rc==DD_OK, "IDirectDrawSurface_Restore returned: %x\n",rc);
643         }
644     }
645 }
646
647 static void testdisplaymodes(void)
648 {
649     int i;
650
651     for (i = 0; i < modes_cnt; ++i)
652     {
653         setdisplaymode(i);
654         createsurface();
655         testsurface();
656         destroysurface();
657     }
658 }
659
660 static void testcooperativelevels_normal(void)
661 {
662     BOOL sfw;
663     HRESULT rc;
664     DDSURFACEDESC surfacedesc;
665     IDirectDrawSurface *surface = (IDirectDrawSurface *) 0xdeadbeef;
666
667     memset(&surfacedesc, 0, sizeof(surfacedesc));
668     surfacedesc.dwSize = sizeof(surfacedesc);
669     surfacedesc.ddpfPixelFormat.dwSize = sizeof(surfacedesc.ddpfPixelFormat);
670     surfacedesc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
671     surfacedesc.dwBackBufferCount = 1;
672     surfacedesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
673
674     rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW);
675     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW) returned: %x\n",rc);
676
677     /* Do some tests with DDSCL_NORMAL mode */
678
679     /* Fullscreen mode + normal mode + exclusive mode */
680
681     rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NORMAL);
682     ok(rc==DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, received: %x\n", rc);
683
684     sfw=FALSE;
685     if(hwnd2)
686         sfw=SetForegroundWindow(hwnd2);
687     else
688         skip("Failed to create the second window\n");
689
690     rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NORMAL);
691     ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NORMAL) returned: %x\n",rc);
692
693     if(sfw)
694         ok(GetForegroundWindow()==hwnd,"Expected the main windows (%p) for foreground, received the second one (%p)\n",hwnd, hwnd2);
695
696     /* Try creating a double buffered primary in fullscreen + exclusive + normal mode */
697     rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
698
699     if (rc == DDERR_UNSUPPORTEDMODE)
700         skip("Unsupported mode\n");
701     else
702     {
703         ok(rc == DD_OK, "IDirectDraw_CreateSurface returned %08x\n", rc);
704         ok(surface!=NULL, "Returned NULL surface pointer\n");
705     }
706     if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
707
708     /* Exclusive mode + normal mode */
709     rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_EXCLUSIVE | DDSCL_NORMAL);
710     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_NORMAL) returned: %x\n",rc);
711
712     /* Fullscreen mode + normal mode */
713
714     sfw=FALSE;
715     if(hwnd2) sfw=SetForegroundWindow(hwnd2);
716
717     rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_FULLSCREEN | DDSCL_NORMAL);
718     ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_FULLSCREEN | DDSCL_NORMAL) returned: %x\n",rc);
719
720     if(sfw)
721         ok(GetForegroundWindow()==hwnd2,"Expected the second windows (%p) for foreground, received the main one (%p)\n",hwnd2, hwnd);
722
723     rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_FULLSCREEN | DDSCL_NORMAL);
724     ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
725
726     /* Try creating a double buffered primary in fullscreen + normal mode */
727     rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
728     if (rc == DDERR_UNSUPPORTEDMODE)
729         skip("Unsupported mode\n");
730     else
731     {
732         ok(rc == DDERR_NOEXCLUSIVEMODE, "IDirectDraw_CreateSurface returned %08x\n", rc);
733         ok(surface == NULL, "Returned surface pointer is %p\n", surface);
734     }
735
736     if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
737
738     /* switching from Fullscreen mode to Normal mode */
739
740     sfw=FALSE;
741     if(hwnd2) sfw=SetForegroundWindow(hwnd2);
742
743     rc = IDirectDraw_SetCooperativeLevel(lpDD,
744         hwnd, DDSCL_NORMAL);
745     ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL) returned: %x\n",rc);
746
747     if(sfw)
748         ok(GetForegroundWindow()==hwnd2,"Expected the second windows (%p) for foreground, received the main one (%p)\n",hwnd2, hwnd);
749
750     rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
751     ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
752
753     /* Try creating a double buffered primary in normal mode */
754     rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
755     if (rc == DDERR_UNSUPPORTEDMODE)
756         skip("Unsupported mode\n");
757     else
758     {
759         ok(rc == DDERR_NOEXCLUSIVEMODE, "IDirectDraw_CreateSurface returned %08x\n", rc);
760         ok(surface == NULL, "Returned surface pointer is %p\n", surface);
761     }
762     if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
763
764     /* switching from Normal mode to Fullscreen + Normal mode */
765
766     sfw=FALSE;
767     if(hwnd2) sfw=SetForegroundWindow(hwnd2);
768
769     rc = IDirectDraw_SetCooperativeLevel(lpDD,
770         hwnd, DDSCL_NORMAL | DDSCL_FULLSCREEN);
771     ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL | FULLSCREEN) returned: %x\n",rc);
772
773     if(sfw)
774         ok(GetForegroundWindow()==hwnd2,"Expected the second windows (%p) for foreground, received the main one (%p)\n",hwnd2, hwnd);
775
776     rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL | DDSCL_FULLSCREEN);
777     ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
778
779     /* Set the focus window */
780
781     rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW);
782     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW) returned: %x\n",rc);
783
784     rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_SETFOCUSWINDOW);
785
786     if (rc == DDERR_INVALIDPARAMS)
787     {
788         win_skip("NT4/Win95 do not support cooperative levels DDSCL_SETDEVICEWINDOW and DDSCL_SETFOCUSWINDOW\n");
789         return;
790     }
791
792     ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
793
794     rc = IDirectDraw_SetCooperativeLevel(lpDD,
795         hwnd, DDSCL_SETFOCUSWINDOW);
796
797     if (rc == DDERR_INVALIDPARAMS)
798     {
799         win_skip("NT4/Win95 do not support cooperative levels DDSCL_SETDEVICEWINDOW and DDSCL_SETFOCUSWINDOW\n");
800         return;
801     }
802
803     ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
804
805     /* Set the focus window a second time*/
806     rc = IDirectDraw_SetCooperativeLevel(lpDD,
807         hwnd, DDSCL_SETFOCUSWINDOW);
808     ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) the second time returned: %x\n",rc);
809
810     /* Test DDSCL_SETFOCUSWINDOW with the other flags. They should all fail, except of DDSCL_NOWINDOWCHANGES */
811     rc = IDirectDraw_SetCooperativeLevel(lpDD,
812         hwnd, DDSCL_NORMAL | DDSCL_SETFOCUSWINDOW);
813     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
814
815     rc = IDirectDraw_SetCooperativeLevel(lpDD,
816         hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETFOCUSWINDOW);
817     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
818
819     /* This one succeeds */
820     rc = IDirectDraw_SetCooperativeLevel(lpDD,
821         hwnd, DDSCL_NOWINDOWCHANGES | DDSCL_SETFOCUSWINDOW);
822     ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NOWINDOWCHANGES | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
823
824     rc = IDirectDraw_SetCooperativeLevel(lpDD,
825         hwnd, DDSCL_MULTITHREADED | DDSCL_SETFOCUSWINDOW);
826     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_MULTITHREADED | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
827
828     rc = IDirectDraw_SetCooperativeLevel(lpDD,
829         hwnd, DDSCL_FPUSETUP | DDSCL_SETFOCUSWINDOW);
830     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FPUSETUP | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
831
832     rc = IDirectDraw_SetCooperativeLevel(lpDD,
833         hwnd, DDSCL_FPUPRESERVE | DDSCL_SETFOCUSWINDOW);
834     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FPUPRESERVE | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
835
836     rc = IDirectDraw_SetCooperativeLevel(lpDD,
837         hwnd, DDSCL_ALLOWREBOOT | DDSCL_SETFOCUSWINDOW);
838     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_ALLOWREBOOT | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
839
840     rc = IDirectDraw_SetCooperativeLevel(lpDD,
841         hwnd, DDSCL_ALLOWMODEX | DDSCL_SETFOCUSWINDOW);
842     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_ALLOWMODEX | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
843
844     /* Set the device window without any other flags. Should give an error */
845     rc = IDirectDraw_SetCooperativeLevel(lpDD,
846         hwnd, DDSCL_SETDEVICEWINDOW);
847     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_SETDEVICEWINDOW) returned: %x\n",rc);
848
849     /* Set device window with DDSCL_NORMAL */
850     rc = IDirectDraw_SetCooperativeLevel(lpDD,
851         hwnd, DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW);
852     ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW) returned: %x\n",rc);
853
854     /* Also set the focus window. Should give an error */
855     rc = IDirectDraw_SetCooperativeLevel(lpDD,
856         hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETDEVICEWINDOW | DDSCL_SETFOCUSWINDOW);
857     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
858
859     /* All done */
860 }
861
862 static void testcooperativelevels_exclusive(void)
863 {
864     BOOL sfw, success;
865     HRESULT rc;
866     RECT window_rect;
867
868     /* Do some tests with DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN mode */
869
870     /* First, resize the window so it is not the same size as any screen */
871     success = SetWindowPos(hwnd, 0, 0, 0, 281, 92, 0);
872     ok(success, "SetWindowPos failed\n");
873
874     /* Try to set exclusive mode only */
875     rc = IDirectDraw_SetCooperativeLevel(lpDD,
876         hwnd, DDSCL_EXCLUSIVE);
877     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_EXCLUSIVE) returned: %x\n",rc);
878
879     /* Full screen mode only */
880     rc = IDirectDraw_SetCooperativeLevel(lpDD,
881         hwnd, DDSCL_FULLSCREEN);
882     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FULLSCREEN) returned: %x\n",rc);
883
884     /* Full screen mode + exclusive mode */
885
886     rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
887     ok(rc==DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, received %x\n", rc);
888
889     sfw=FALSE;
890     if(hwnd2)
891         sfw=SetForegroundWindow(hwnd2);
892     else
893         skip("Failed to create the second window\n");
894
895     rc = IDirectDraw_SetCooperativeLevel(lpDD,
896         hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
897     ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN) returned: %x\n",rc);
898
899     if(sfw)
900         ok(GetForegroundWindow()==hwnd,"Expected the main windows (%p) for foreground, received the second one (%p)\n",hwnd, hwnd2);
901
902     /* rect_before_create is assumed to hold the screen rect */
903     GetClientRect(hwnd, &window_rect);
904     rc = EqualRect(&rect_before_create, &window_rect);
905     ok(rc, "Fullscreen window has wrong size.\n");
906
907     /* Set the focus window. Should fail */
908     rc = IDirectDraw_SetCooperativeLevel(lpDD,
909         hwnd, DDSCL_SETFOCUSWINDOW);
910     ok(rc==DDERR_HWNDALREADYSET ||
911        broken(rc==DDERR_INVALIDPARAMS) /* NT4/Win95 */,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
912
913
914     /* All done */
915 }
916
917 static void testddraw3(void)
918 {
919     const GUID My_IID_IDirectDraw3 = {
920         0x618f8ad4,
921         0x8b7a,
922         0x11d0,
923         { 0x8f,0xcc,0x0,0xc0,0x4f,0xd9,0x18,0x9d }
924     };
925     IDirectDraw3 *dd3;
926     HRESULT hr;
927     hr = IDirectDraw_QueryInterface(lpDD, &My_IID_IDirectDraw3, (void **) &dd3);
928     ok(hr == E_NOINTERFACE, "QueryInterface for IID_IDirectDraw3 returned 0x%08x, expected E_NOINTERFACE\n", hr);
929     if(SUCCEEDED(hr) && dd3) IDirectDraw3_Release(dd3);
930 }
931
932 static void testddraw7(void)
933 {
934     IDirectDraw7 *dd7;
935     HRESULT hr;
936     DDDEVICEIDENTIFIER2 *pdddi2;
937     DWORD dddi2Bytes;
938     DWORD *pend;
939
940     hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
941     if (hr==E_NOINTERFACE)
942     {
943         win_skip("DirectDraw7 is not supported\n");
944         return;
945     }
946     ok(hr==DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);
947
948     if (hr==DD_OK)
949     {
950          dddi2Bytes = FIELD_OFFSET(DDDEVICEIDENTIFIER2, dwWHQLLevel) + sizeof(DWORD);
951
952          pdddi2 = HeapAlloc( GetProcessHeap(), 0, dddi2Bytes + 2*sizeof(DWORD) );
953          pend = (DWORD *)((char *)pdddi2 + dddi2Bytes);
954          pend[0] = 0xdeadbeef;
955          pend[1] = 0xdeadbeef;
956
957          hr = IDirectDraw7_GetDeviceIdentifier(dd7, pdddi2, 0);
958          ok(hr==DD_OK, "get device identifier failed with %08x\n", hr);
959
960          if (hr==DD_OK)
961          {
962              /* check how strings are copied into the structure */
963              ok(pdddi2->szDriver[MAX_DDDEVICEID_STRING - 1]==0, "szDriver not cleared\n");
964              ok(pdddi2->szDescription[MAX_DDDEVICEID_STRING - 1]==0, "szDescription not cleared\n");
965              /* verify that 8 byte structure size alignment will not overwrite memory */
966              ok(pend[0]==0xdeadbeef || broken(pend[0] != 0xdeadbeef), /* win2k */
967                 "memory beyond DDDEVICEIDENTIFIER2 overwritten\n");
968              ok(pend[1]==0xdeadbeef, "memory beyond DDDEVICEIDENTIFIER2 overwritten\n");
969          }
970
971          IDirectDraw_Release(dd7);
972          HeapFree( GetProcessHeap(), 0, pdddi2 );
973     }
974 }
975
976 START_TEST(ddrawmodes)
977 {
978     init_function_pointers();
979
980     wc.style = CS_HREDRAW | CS_VREDRAW;
981     wc.lpfnWndProc = DefWindowProcA;
982     wc.cbClsExtra = 0;
983     wc.cbWndExtra = 0;
984     wc.hInstance = GetModuleHandleA(0);
985     wc.hIcon = LoadIconA(wc.hInstance, IDI_APPLICATION);
986     wc.hCursor = LoadCursorA(NULL, IDC_ARROW);
987     wc.hbrBackground = GetStockObject(BLACK_BRUSH);
988     wc.lpszMenuName = NULL;
989     wc.lpszClassName = "TestWindowClass";
990     if (!RegisterClassA(&wc))
991     {
992         skip("RegisterClassA failed\n");
993         return;
994     }
995
996     hwnd2=createwindow();
997     hwnd=createwindow();
998
999     if (!hwnd)
1000     {
1001         skip("Failed to create the main window\n");
1002         return;
1003     }
1004
1005     if (!createdirectdraw())
1006     {
1007         skip("Failed to create the direct draw object\n");
1008         return;
1009     }
1010
1011     test_DirectDrawEnumerateA();
1012     test_DirectDrawEnumerateW();
1013     test_DirectDrawEnumerateExA();
1014     test_DirectDrawEnumerateExW();
1015
1016     enumdisplaymodes();
1017     if (winetest_interactive)
1018         testdisplaymodes();
1019     flushdisplaymodes();
1020     testddraw3();
1021     testddraw7();
1022     releasedirectdraw();
1023
1024     createdirectdraw();
1025     testcooperativelevels_normal();
1026     releasedirectdraw();
1027
1028     createdirectdraw();
1029     testcooperativelevels_exclusive();
1030     releasedirectdraw();
1031 }