Release 1.5.29.
[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 IDirectDrawSurface *lpDDSPrimary;
33 static IDirectDrawSurface *lpDDSBack;
34 static IDirectDraw *lpDD;
35 static WNDCLASS 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;
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(DDSURFACEDESC *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(DDSURFACEDESC *lpddsd, void *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(DDSURFACEDESC *lpddsd, void *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(DDSURFACEDESC *lpddsd, void *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     /* Ask for a refresh rate that could not possibly be used. But note that
477      * the Windows 'Standard VGA' driver claims to run the display at 1Hz!
478      */
479     U2(ddsd).dwRefreshRate = 2;
480
481     rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
482     ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
483     ok(modes16bpp_cnt == 0, "Expected 0 modes got %d\n", modes16bpp_cnt);
484
485     modes16bpp_cnt = 0;
486     ddsd.dwFlags = DDSD_PIXELFORMAT;
487
488     rc = IDirectDraw_EnumDisplayModes(lpDD, DDEDM_REFRESHRATES, &ddsd, 0, enummodescallback_16bit);
489     if(rc == DDERR_INVALIDPARAMS)
490     {
491         skip("Ddraw version too old. Skipping.\n");
492         return;
493     }
494     ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
495     refresh_count = refresh_rate_cnt;
496
497     if(refresh_rate)
498     {
499         modes16bpp_cnt = 0;
500         ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_REFRESHRATE;
501         U2(ddsd).dwRefreshRate = refresh_rate;
502
503         rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
504         ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
505         ok(modes16bpp_cnt == refresh_count, "Expected %d modes got %d\n", refresh_count, modes16bpp_cnt);
506     }
507
508     rc = IDirectDraw_EnumDisplayModes(lpDD, 0, NULL, 0, enummodescallback);
509     ok(rc==DD_OK, "EnumDisplayModes returned: %x\n",rc);
510 }
511
512
513 static void setdisplaymode(int i)
514 {
515     HRESULT rc;
516     RECT orig_rect;
517
518     SetRect(&orig_rect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
519
520     rc = IDirectDraw_SetCooperativeLevel(lpDD,
521         hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
522     ok(rc==DD_OK,"SetCooperativeLevel returned: %x\n",rc);
523     if (modes[i].dwFlags & DDSD_PIXELFORMAT)
524     {
525         if (modes[i].ddpfPixelFormat.dwFlags & DDPF_RGB)
526         {
527             rc = IDirectDraw_SetDisplayMode(lpDD,
528                 modes[i].dwWidth, modes[i].dwHeight,
529                 U1(modes[i].ddpfPixelFormat).dwRGBBitCount);
530             ok(DD_OK==rc || DDERR_UNSUPPORTED==rc,"SetDisplayMode returned: %x\n",rc);
531             if (rc == DD_OK)
532             {
533                 RECT r, scrn, test, virt;
534
535                 SetRect(&virt, 0, 0, GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN));
536                 OffsetRect(&virt, GetSystemMetrics(SM_XVIRTUALSCREEN), GetSystemMetrics(SM_YVIRTUALSCREEN));
537                 SetRect(&scrn, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
538                 trace("Mode (%dx%d) [%dx%d] (%d %d)x(%d %d)\n", modes[i].dwWidth, modes[i].dwHeight,
539                       scrn.right, scrn.bottom, virt.left, virt.top, virt.right, virt.bottom);
540                 if (!EqualRect(&scrn, &orig_rect))
541                 {
542                     HRESULT rect_result;
543
544                     /* Check that the client rect was resized */
545                     rc = GetClientRect(hwnd, &test);
546                     ok(rc!=0, "GetClientRect returned %x\n", rc);
547                     rc = EqualRect(&scrn, &test);
548                     todo_wine ok(rc!=0, "Fullscreen window has wrong size\n");
549
550                     /* Check that switching to normal cooperative level
551                        does not restore the display mode */
552                     rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_NORMAL);
553                     ok(rc==DD_OK, "SetCooperativeLevel returned %x\n", rc);
554                     SetRect(&test, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
555                     rect_result = EqualRect(&scrn, &test);
556                     ok(rect_result!=0, "Setting cooperative level to DDSCL_NORMAL changed the display mode\n");
557
558                     /* Go back to fullscreen */
559                     rc = IDirectDraw_SetCooperativeLevel(lpDD,
560                         hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
561                     ok(rc==DD_OK, "SetCooperativeLevel returned: %x\n",rc);
562
563                     /* If the display mode was changed, set the correct mode
564                        to avoid irrelevant failures */
565                     if (rect_result == 0)
566                     {
567                         rc = IDirectDraw_SetDisplayMode(lpDD,
568                             modes[i].dwWidth, modes[i].dwHeight,
569                             U1(modes[i].ddpfPixelFormat).dwRGBBitCount);
570                         ok(DD_OK==rc, "SetDisplayMode returned: %x\n",rc);
571                     }
572                 }
573                 ok(GetClipCursor(&r), "GetClipCursor() failed\n");
574                 /* ddraw sets clip rect here to the screen size, even for
575                    multiple monitors */
576                 ok(EqualRect(&r, &scrn), "Invalid clip rect: (%d %d) x (%d %d)\n",
577                    r.left, r.top, r.right, r.bottom);
578
579                 ok(ClipCursor(NULL), "ClipCursor() failed\n");
580                 ok(GetClipCursor(&r), "GetClipCursor() failed\n");
581                 ok(EqualRect(&r, &virt), "Invalid clip rect: (%d %d) x (%d %d)\n",
582                    r.left, r.top, r.right, r.bottom);
583
584                 rc = IDirectDraw_RestoreDisplayMode(lpDD);
585                 ok(DD_OK==rc,"RestoreDisplayMode returned: %x\n",rc);
586             }
587         }
588     }
589 }
590
591 static void createsurface(void)
592 {
593     DDSURFACEDESC ddsd;
594     DDSCAPS ddscaps;
595     HRESULT rc;
596
597     ddsd.dwSize = sizeof(ddsd);
598     ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
599     ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
600         DDSCAPS_FLIP |
601         DDSCAPS_COMPLEX;
602     ddsd.dwBackBufferCount = 1;
603     rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSPrimary, NULL );
604     ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
605     ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
606     rc = IDirectDrawSurface_GetAttachedSurface(lpDDSPrimary, &ddscaps, &lpDDSBack);
607     ok(rc==DD_OK,"GetAttachedSurface returned: %x\n",rc);
608 }
609
610 static void destroysurface(void)
611 {
612     if( lpDDSPrimary != NULL )
613     {
614         IDirectDrawSurface_Release(lpDDSPrimary);
615         lpDDSPrimary = NULL;
616     }
617 }
618
619 static void testsurface(void)
620 {
621     const char* testMsg = "ddraw device context test";
622     HDC hdc;
623     HRESULT rc;
624
625     rc = IDirectDrawSurface_GetDC(lpDDSBack, &hdc);
626     ok(rc==DD_OK, "IDirectDrawSurface_GetDC returned: %x\n",rc);
627     SetBkColor(hdc, RGB(0, 0, 255));
628     SetTextColor(hdc, RGB(255, 255, 0));
629     TextOut(hdc, 0, 0, testMsg, lstrlen(testMsg));
630     rc = IDirectDrawSurface_ReleaseDC(lpDDSBack, hdc);
631     ok(rc==DD_OK, "IDirectDrawSurface_ReleaseDC returned: %x\n",rc);
632
633     while (1)
634     {
635         rc = IDirectDrawSurface_Flip(lpDDSPrimary, NULL, DDFLIP_WAIT);
636         ok(rc==DD_OK || rc==DDERR_SURFACELOST, "IDirectDrawSurface_BltFast returned: %x\n",rc);
637
638         if (rc == DD_OK)
639         {
640             break;
641         }
642         else if (rc == DDERR_SURFACELOST)
643         {
644             rc = IDirectDrawSurface_Restore(lpDDSPrimary);
645             ok(rc==DD_OK, "IDirectDrawSurface_Restore returned: %x\n",rc);
646         }
647     }
648 }
649
650 static void testdisplaymodes(void)
651 {
652     int i;
653
654     for (i = 0; i < modes_cnt; ++i)
655     {
656         setdisplaymode(i);
657         createsurface();
658         testsurface();
659         destroysurface();
660     }
661 }
662
663 static void testcooperativelevels_normal(void)
664 {
665     BOOL sfw;
666     HRESULT rc;
667     DDSURFACEDESC surfacedesc;
668     IDirectDrawSurface *surface = (IDirectDrawSurface *) 0xdeadbeef;
669
670     memset(&surfacedesc, 0, sizeof(surfacedesc));
671     surfacedesc.dwSize = sizeof(surfacedesc);
672     surfacedesc.ddpfPixelFormat.dwSize = sizeof(surfacedesc.ddpfPixelFormat);
673     surfacedesc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
674     surfacedesc.dwBackBufferCount = 1;
675     surfacedesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
676
677     rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW);
678     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW) returned: %x\n",rc);
679
680     /* Do some tests with DDSCL_NORMAL mode */
681
682     /* Fullscreen mode + normal mode + exclusive mode */
683
684     rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NORMAL);
685     ok(rc==DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, received: %x\n", rc);
686
687     sfw=FALSE;
688     if(hwnd2)
689         sfw=SetForegroundWindow(hwnd2);
690     else
691         skip("Failed to create the second window\n");
692
693     rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NORMAL);
694     ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NORMAL) returned: %x\n",rc);
695
696     if(sfw)
697         ok(GetForegroundWindow()==hwnd,"Expected the main windows (%p) for foreground, received the second one (%p)\n",hwnd, hwnd2);
698
699     /* Try creating a double buffered primary in fullscreen + exclusive + normal mode */
700     rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
701
702     if (rc == DDERR_UNSUPPORTEDMODE)
703         skip("Unsupported mode\n");
704     else
705     {
706         ok(rc == DD_OK, "IDirectDraw_CreateSurface returned %08x\n", rc);
707         ok(surface!=NULL, "Returned NULL surface pointer\n");
708     }
709     if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
710
711     /* Exclusive mode + normal mode */
712     rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_EXCLUSIVE | DDSCL_NORMAL);
713     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_NORMAL) returned: %x\n",rc);
714
715     /* Fullscreen mode + normal mode */
716
717     sfw=FALSE;
718     if(hwnd2) sfw=SetForegroundWindow(hwnd2);
719
720     rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_FULLSCREEN | DDSCL_NORMAL);
721     ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_FULLSCREEN | DDSCL_NORMAL) returned: %x\n",rc);
722
723     if(sfw)
724         ok(GetForegroundWindow()==hwnd2,"Expected the second windows (%p) for foreground, received the main one (%p)\n",hwnd2, hwnd);
725
726     rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_FULLSCREEN | DDSCL_NORMAL);
727     ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
728
729     /* Try creating a double buffered primary in fullscreen + normal mode */
730     rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
731     if (rc == DDERR_UNSUPPORTEDMODE)
732         skip("Unsupported mode\n");
733     else
734     {
735         ok(rc == DDERR_NOEXCLUSIVEMODE, "IDirectDraw_CreateSurface returned %08x\n", rc);
736         ok(surface == NULL, "Returned surface pointer is %p\n", surface);
737     }
738
739     if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
740
741     /* switching from Fullscreen mode to Normal mode */
742
743     sfw=FALSE;
744     if(hwnd2) sfw=SetForegroundWindow(hwnd2);
745
746     rc = IDirectDraw_SetCooperativeLevel(lpDD,
747         hwnd, DDSCL_NORMAL);
748     ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL) returned: %x\n",rc);
749
750     if(sfw)
751         ok(GetForegroundWindow()==hwnd2,"Expected the second windows (%p) for foreground, received the main one (%p)\n",hwnd2, hwnd);
752
753     rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
754     ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
755
756     /* Try creating a double buffered primary in normal mode */
757     rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
758     if (rc == DDERR_UNSUPPORTEDMODE)
759         skip("Unsupported mode\n");
760     else
761     {
762         ok(rc == DDERR_NOEXCLUSIVEMODE, "IDirectDraw_CreateSurface returned %08x\n", rc);
763         ok(surface == NULL, "Returned surface pointer is %p\n", surface);
764     }
765     if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
766
767     /* switching from Normal mode to Fullscreen + Normal mode */
768
769     sfw=FALSE;
770     if(hwnd2) sfw=SetForegroundWindow(hwnd2);
771
772     rc = IDirectDraw_SetCooperativeLevel(lpDD,
773         hwnd, DDSCL_NORMAL | DDSCL_FULLSCREEN);
774     ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL | FULLSCREEN) returned: %x\n",rc);
775
776     if(sfw)
777         ok(GetForegroundWindow()==hwnd2,"Expected the second windows (%p) for foreground, received the main one (%p)\n",hwnd2, hwnd);
778
779     rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL | DDSCL_FULLSCREEN);
780     ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
781
782     /* Set the focus window */
783
784     rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW);
785     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW) returned: %x\n",rc);
786
787     rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_SETFOCUSWINDOW);
788
789     if (rc == DDERR_INVALIDPARAMS)
790     {
791         win_skip("NT4/Win95 do not support cooperative levels DDSCL_SETDEVICEWINDOW and DDSCL_SETFOCUSWINDOW\n");
792         return;
793     }
794
795     ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
796
797     rc = IDirectDraw_SetCooperativeLevel(lpDD,
798         hwnd, DDSCL_SETFOCUSWINDOW);
799
800     if (rc == DDERR_INVALIDPARAMS)
801     {
802         win_skip("NT4/Win95 do not support cooperative levels DDSCL_SETDEVICEWINDOW and DDSCL_SETFOCUSWINDOW\n");
803         return;
804     }
805
806     ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
807
808     /* Set the focus window a second time*/
809     rc = IDirectDraw_SetCooperativeLevel(lpDD,
810         hwnd, DDSCL_SETFOCUSWINDOW);
811     ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) the second time returned: %x\n",rc);
812
813     /* Test DDSCL_SETFOCUSWINDOW with the other flags. They should all fail, except of DDSCL_NOWINDOWCHANGES */
814     rc = IDirectDraw_SetCooperativeLevel(lpDD,
815         hwnd, DDSCL_NORMAL | DDSCL_SETFOCUSWINDOW);
816     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
817
818     rc = IDirectDraw_SetCooperativeLevel(lpDD,
819         hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETFOCUSWINDOW);
820     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
821
822     /* This one succeeds */
823     rc = IDirectDraw_SetCooperativeLevel(lpDD,
824         hwnd, DDSCL_NOWINDOWCHANGES | DDSCL_SETFOCUSWINDOW);
825     ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NOWINDOWCHANGES | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
826
827     rc = IDirectDraw_SetCooperativeLevel(lpDD,
828         hwnd, DDSCL_MULTITHREADED | DDSCL_SETFOCUSWINDOW);
829     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_MULTITHREADED | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
830
831     rc = IDirectDraw_SetCooperativeLevel(lpDD,
832         hwnd, DDSCL_FPUSETUP | DDSCL_SETFOCUSWINDOW);
833     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FPUSETUP | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
834
835     rc = IDirectDraw_SetCooperativeLevel(lpDD,
836         hwnd, DDSCL_FPUPRESERVE | DDSCL_SETFOCUSWINDOW);
837     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FPUPRESERVE | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
838
839     rc = IDirectDraw_SetCooperativeLevel(lpDD,
840         hwnd, DDSCL_ALLOWREBOOT | DDSCL_SETFOCUSWINDOW);
841     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_ALLOWREBOOT | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
842
843     rc = IDirectDraw_SetCooperativeLevel(lpDD,
844         hwnd, DDSCL_ALLOWMODEX | DDSCL_SETFOCUSWINDOW);
845     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_ALLOWMODEX | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
846
847     /* Set the device window without any other flags. Should give an error */
848     rc = IDirectDraw_SetCooperativeLevel(lpDD,
849         hwnd, DDSCL_SETDEVICEWINDOW);
850     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_SETDEVICEWINDOW) returned: %x\n",rc);
851
852     /* Set device window with DDSCL_NORMAL */
853     rc = IDirectDraw_SetCooperativeLevel(lpDD,
854         hwnd, DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW);
855     ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW) returned: %x\n",rc);
856
857     /* Also set the focus window. Should give an error */
858     rc = IDirectDraw_SetCooperativeLevel(lpDD,
859         hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETDEVICEWINDOW | DDSCL_SETFOCUSWINDOW);
860     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
861
862     /* All done */
863 }
864
865 static void testcooperativelevels_exclusive(void)
866 {
867     BOOL sfw, success;
868     HRESULT rc;
869     RECT window_rect;
870
871     /* Do some tests with DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN mode */
872
873     /* First, resize the window so it is not the same size as any screen */
874     success = SetWindowPos(hwnd, 0, 0, 0, 281, 92, 0);
875     ok(success, "SetWindowPos failed\n");
876
877     /* Try to set exclusive mode only */
878     rc = IDirectDraw_SetCooperativeLevel(lpDD,
879         hwnd, DDSCL_EXCLUSIVE);
880     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_EXCLUSIVE) returned: %x\n",rc);
881
882     /* Full screen mode only */
883     rc = IDirectDraw_SetCooperativeLevel(lpDD,
884         hwnd, DDSCL_FULLSCREEN);
885     ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FULLSCREEN) returned: %x\n",rc);
886
887     /* Full screen mode + exclusive mode */
888
889     rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
890     ok(rc==DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, received %x\n", rc);
891
892     sfw=FALSE;
893     if(hwnd2)
894         sfw=SetForegroundWindow(hwnd2);
895     else
896         skip("Failed to create the second window\n");
897
898     rc = IDirectDraw_SetCooperativeLevel(lpDD,
899         hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
900     ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN) returned: %x\n",rc);
901
902     if(sfw)
903         ok(GetForegroundWindow()==hwnd,"Expected the main windows (%p) for foreground, received the second one (%p)\n",hwnd, hwnd2);
904
905     /* rect_before_create is assumed to hold the screen rect */
906     GetClientRect(hwnd, &window_rect);
907     rc = EqualRect(&rect_before_create, &window_rect);
908     ok(rc, "Fullscreen window has wrong size.\n");
909
910     /* Set the focus window. Should fail */
911     rc = IDirectDraw_SetCooperativeLevel(lpDD,
912         hwnd, DDSCL_SETFOCUSWINDOW);
913     ok(rc==DDERR_HWNDALREADYSET ||
914        broken(rc==DDERR_INVALIDPARAMS) /* NT4/Win95 */,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
915
916
917     /* All done */
918 }
919
920 static void testddraw3(void)
921 {
922     const GUID My_IID_IDirectDraw3 = {
923         0x618f8ad4,
924         0x8b7a,
925         0x11d0,
926         { 0x8f,0xcc,0x0,0xc0,0x4f,0xd9,0x18,0x9d }
927     };
928     IDirectDraw3 *dd3;
929     HRESULT hr;
930     hr = IDirectDraw_QueryInterface(lpDD, &My_IID_IDirectDraw3, (void **) &dd3);
931     ok(hr == E_NOINTERFACE, "QueryInterface for IID_IDirectDraw3 returned 0x%08x, expected E_NOINTERFACE\n", hr);
932     if(SUCCEEDED(hr) && dd3) IDirectDraw3_Release(dd3);
933 }
934
935 static void testddraw7(void)
936 {
937     IDirectDraw7 *dd7;
938     HRESULT hr;
939     DDDEVICEIDENTIFIER2 *pdddi2;
940     DWORD dddi2Bytes;
941     DWORD *pend;
942
943     hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
944     if (hr==E_NOINTERFACE)
945     {
946         win_skip("DirectDraw7 is not supported\n");
947         return;
948     }
949     ok(hr==DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);
950
951     if (hr==DD_OK)
952     {
953          dddi2Bytes = FIELD_OFFSET(DDDEVICEIDENTIFIER2, dwWHQLLevel) + sizeof(DWORD);
954
955          pdddi2 = HeapAlloc( GetProcessHeap(), 0, dddi2Bytes + 2*sizeof(DWORD) );
956          pend = (DWORD *)((char *)pdddi2 + dddi2Bytes);
957          pend[0] = 0xdeadbeef;
958          pend[1] = 0xdeadbeef;
959
960          hr = IDirectDraw7_GetDeviceIdentifier(dd7, pdddi2, 0);
961          ok(hr==DD_OK, "get device identifier failed with %08x\n", hr);
962
963          if (hr==DD_OK)
964          {
965              /* check how strings are copied into the structure */
966              ok(pdddi2->szDriver[MAX_DDDEVICEID_STRING - 1]==0, "szDriver not cleared\n");
967              ok(pdddi2->szDescription[MAX_DDDEVICEID_STRING - 1]==0, "szDescription not cleared\n");
968              /* verify that 8 byte structure size alignment will not overwrite memory */
969              ok(pend[0]==0xdeadbeef || broken(pend[0] != 0xdeadbeef), /* win2k */
970                 "memory beyond DDDEVICEIDENTIFIER2 overwritten\n");
971              ok(pend[1]==0xdeadbeef, "memory beyond DDDEVICEIDENTIFIER2 overwritten\n");
972          }
973
974          IDirectDraw_Release(dd7);
975          HeapFree( GetProcessHeap(), 0, pdddi2 );
976     }
977 }
978
979 START_TEST(ddrawmodes)
980 {
981     init_function_pointers();
982
983     wc.style = CS_HREDRAW | CS_VREDRAW;
984     wc.lpfnWndProc = DefWindowProcA;
985     wc.cbClsExtra = 0;
986     wc.cbWndExtra = 0;
987     wc.hInstance = GetModuleHandleA(0);
988     wc.hIcon = LoadIconA(wc.hInstance, IDI_APPLICATION);
989     wc.hCursor = LoadCursorA(NULL, IDC_ARROW);
990     wc.hbrBackground = GetStockObject(BLACK_BRUSH);
991     wc.lpszMenuName = NULL;
992     wc.lpszClassName = "TestWindowClass";
993     if (!RegisterClassA(&wc))
994     {
995         skip("RegisterClassA failed\n");
996         return;
997     }
998
999     hwnd2=createwindow();
1000     hwnd=createwindow();
1001
1002     if (!hwnd)
1003     {
1004         skip("Failed to create the main window\n");
1005         return;
1006     }
1007
1008     if (!createdirectdraw())
1009     {
1010         skip("Failed to create the direct draw object\n");
1011         return;
1012     }
1013
1014     test_DirectDrawEnumerateA();
1015     test_DirectDrawEnumerateW();
1016     test_DirectDrawEnumerateExA();
1017     test_DirectDrawEnumerateExW();
1018
1019     enumdisplaymodes();
1020     if (winetest_interactive)
1021         testdisplaymodes();
1022     flushdisplaymodes();
1023     testddraw3();
1024     testddraw7();
1025     releasedirectdraw();
1026
1027     createdirectdraw();
1028     testcooperativelevels_normal();
1029     releasedirectdraw();
1030
1031     createdirectdraw();
1032     testcooperativelevels_exclusive();
1033     releasedirectdraw();
1034 }