2 * Unit tests for ddraw functions
4 * Copyright (C) 2003 Sami Aario
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/test.h"
25 #ifdef NONAMELESSUNION
26 #define UNION_MEMBER(x, y) DUMMYUNIONNAME##x.y
28 #define UNION_MEMBER(x, y) y
31 static LPDIRECTDRAW lpDD = NULL;
32 static LPDIRECTDRAWSURFACE lpDDSPrimary = NULL;
33 static LPDIRECTDRAWSURFACE lpDDSBack = NULL;
37 static int modes_size;
38 static LPDDSURFACEDESC modes;
40 static void createdirectdraw()
44 wc.style = CS_HREDRAW | CS_VREDRAW;
45 wc.lpfnWndProc = DefWindowProcA;
48 wc.hInstance = GetModuleHandleA(0);
49 wc.hIcon = LoadIconA(wc.hInstance, IDI_APPLICATION);
50 wc.hCursor = LoadCursorA(NULL, IDC_ARROW);
51 wc.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
52 wc.lpszMenuName = NULL;
53 wc.lpszClassName = "TestWindowClass";
54 if(!RegisterClassA(&wc))
57 hwnd = CreateWindowExA(0, "TestWindowClass", "TestWindowClass",
59 GetSystemMetrics(SM_CXSCREEN),
60 GetSystemMetrics(SM_CYSCREEN),
61 NULL, NULL, GetModuleHandleA(0), NULL);
64 ShowWindow(hwnd, SW_HIDE);
68 rc = DirectDrawCreate(NULL, &lpDD, NULL);
69 ok(rc==DD_OK,"DirectDrawCreate returned: %lx\n",rc);
73 static void releasedirectdraw()
77 IDirectDraw_Release(lpDD);
82 static void adddisplaymode(LPDDSURFACEDESC lpddsd)
85 modes = malloc((modes_size = 2) * sizeof(DDSURFACEDESC));
86 if (modes_cnt == modes_size)
87 modes = realloc(modes, (modes_size *= 2) * sizeof(DDSURFACEDESC));
89 modes[modes_cnt++] = *lpddsd;
92 static void flushdisplaymodes()
96 modes_cnt = modes_size = 0;
99 HRESULT WINAPI enummodescallback(LPDDSURFACEDESC lpddsd, LPVOID lpContext)
101 trace("Width = %li, Height = %li, Refresh Rate = %li\r\n",
102 lpddsd->dwWidth, lpddsd->dwHeight,
103 lpddsd->UNION_MEMBER(2, dwRefreshRate));
104 adddisplaymode(lpddsd);
109 void enumdisplaymodes()
114 ZeroMemory(&ddsd, sizeof(DDSURFACEDESC));
115 ddsd.dwSize = sizeof(DDSURFACEDESC);
116 ddsd.dwFlags = DDSD_CAPS;
117 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
119 rc = IDirectDraw_EnumDisplayModes(lpDD,
120 DDEDM_STANDARDVGAMODES, &ddsd, 0, enummodescallback);
121 ok(rc==DD_OK,"EnumDisplayModes returned: %lx\n",rc);
124 static void setdisplaymode(int i)
128 rc = IDirectDraw_SetCooperativeLevel(lpDD,
129 hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
130 ok(rc==DD_OK,"SetCooperativeLevel returned: %lx\n",rc);
131 if (modes[i].dwFlags & DDSD_PIXELFORMAT)
133 if (modes[i].ddpfPixelFormat.dwFlags & DDPF_RGB)
135 rc = IDirectDraw_SetDisplayMode(lpDD,
136 modes[i].dwWidth, modes[i].dwHeight,
137 modes[i].ddpfPixelFormat.UNION_MEMBER(1, dwRGBBitCount));
138 ok(rc==DD_OK,"SetDisplayMode returned: %lx\n",rc);
139 rc = IDirectDraw_RestoreDisplayMode(lpDD);
140 ok(rc==DD_OK,"RestoreDisplayMode returned: %lx\n",rc);
146 static void createsurface()
152 ddsd.dwSize = sizeof(ddsd);
153 ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
154 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
157 ddsd.dwBackBufferCount = 1;
158 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSPrimary, NULL );
159 ok(rc==DD_OK,"CreateSurface returned: %lx\n",rc);
160 ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
161 rc = IDirectDrawSurface_GetAttachedSurface(lpDDSPrimary, &ddscaps, &lpDDSBack);
162 ok(rc==DD_OK,"GetAttachedSurface returned: %lx\n",rc);
165 static void destroysurface()
167 if( lpDDSPrimary != NULL )
169 IDirectDrawSurface_Release(lpDDSPrimary);
174 static void testsurface()
176 const char* testMsg = "ddraw device context test";
180 rc = IDirectDrawSurface_GetDC(lpDDSBack, &hdc);
181 ok(rc==DD_OK, "IDirectDrawSurface_GetDC returned: %lx\n",rc);
182 SetBkColor(hdc, RGB(0, 0, 255));
183 SetTextColor(hdc, RGB(255, 255, 0));
184 TextOut(hdc, 0, 0, testMsg, lstrlen(testMsg));
185 IDirectDrawSurface_ReleaseDC(lpDDSBack, hdc);
186 ok(rc==DD_OK, "IDirectDrawSurface_ReleaseDC returned: %lx\n",rc);
190 rc = IDirectDrawSurface_Flip(lpDDSPrimary, NULL, DDFLIP_WAIT);
191 ok(rc==DD_OK || rc==DDERR_SURFACELOST, "IDirectDrawSurface_BltFast returned: %lx\n",rc);
197 else if (rc == DDERR_SURFACELOST)
199 rc = IDirectDrawSurface_Restore(lpDDSPrimary);
200 ok(rc==DD_OK, "IDirectDrawSurface_Restore returned: %lx\n",rc);
205 static void testdisplaymodes()
209 for (i = 0; i < modes_cnt; ++i)
218 START_TEST(ddrawmodes)