- define additional shell paths for CSIDL_... constants
[wine] / dlls / ddraw / tests / ddrawmodes.c
1 /*
2  * Unit tests for ddraw functions
3  *
4  * Copyright (C) 2003 Sami Aario
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <assert.h>
22 #include "wine/test.h"
23 #include "ddraw.h"
24
25 #ifdef NONAMELESSUNION
26 #define UNION_MEMBER(x, y) DUMMYUNIONNAME##x.y
27 #else
28 #define UNION_MEMBER(x, y) y
29 #endif
30
31 static LPDIRECTDRAW lpDD;
32 static WNDCLASS wc;
33 static HWND hwnd;
34 static int modes_cnt;
35 static int modes_size;
36 static LPDDSURFACEDESC modes;
37
38 static void createdirectdraw()
39 {
40     HRESULT rc;
41     
42     wc.style = CS_HREDRAW | CS_VREDRAW;
43     wc.lpfnWndProc = DefWindowProcA;
44     wc.cbClsExtra = 0;
45     wc.cbWndExtra = 0;
46     wc.hInstance = GetModuleHandleA(0);
47     wc.hIcon = LoadIconA(wc.hInstance, IDI_APPLICATION);
48     wc.hCursor = LoadCursorA(NULL, IDC_ARROW);
49     wc.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
50     wc.lpszMenuName = NULL;
51     wc.lpszClassName = "TestWindowClass";
52     if(!RegisterClassA(&wc))
53         assert(0);
54     
55     hwnd = CreateWindowExA(0, "TestWindowClass", "TestWindowClass",
56         WS_POPUP, 0, 0,
57         GetSystemMetrics(SM_CXSCREEN),
58         GetSystemMetrics(SM_CYSCREEN),
59         NULL, NULL, GetModuleHandleA(0), NULL);
60     if (hwnd == NULL)
61         assert(0);
62     
63     ShowWindow(hwnd, SW_HIDE);
64     UpdateWindow(hwnd);
65     SetFocus(hwnd);
66     
67     rc = DirectDrawCreate(NULL, &lpDD, NULL);
68     ok(rc==DD_OK,"DirectDrawCreate returned: %lx\n",rc);
69 }
70
71 static void add_mode(LPDDSURFACEDESC lpddsd)
72 {
73     if (!modes) 
74         modes = malloc((modes_size = 2) * sizeof(DDSURFACEDESC));
75     if (modes_cnt == modes_size) 
76             modes = realloc(modes, (modes_size *= 2) * sizeof(DDSURFACEDESC));
77     assert(modes);
78     modes[modes_cnt++] = *lpddsd;
79 }
80
81 static void flush_modes()
82 {
83     free(modes);
84     modes = 0;
85     modes_cnt = modes_size = 0;
86 }
87
88 HRESULT WINAPI enummodes_callback(LPDDSURFACEDESC lpddsd, LPVOID lpContext)
89 {
90     trace("Width = %lx, Height = %lx, Refresh Rate = %lx\r\n",
91         lpddsd->dwWidth, lpddsd->dwHeight,
92         lpddsd->UNION_MEMBER(2, dwRefreshRate));
93     add_mode(lpddsd);
94
95     return DDENUMRET_OK;
96 }
97
98 void enumdisplaymodes()
99 {
100     DDSURFACEDESC ddsd;
101     HRESULT rc;
102
103     ZeroMemory(&ddsd, sizeof(DDSURFACEDESC));
104     ddsd.dwSize = sizeof(DDSURFACEDESC);
105     ddsd.dwFlags = DDSD_CAPS;
106     ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
107
108     rc = IDirectDraw_EnumDisplayModes(lpDD,
109         DDEDM_STANDARDVGAMODES, &ddsd, 0, enummodes_callback);
110     ok(rc==DD_OK,"EnumDisplayModes returned: %lx\n",rc);
111 }
112
113 static void setdisplaymode_tests()
114 {
115     HRESULT rc;
116     int i;
117     
118     createdirectdraw();
119     enumdisplaymodes();
120     for (i = 0; i < modes_cnt; ++i)
121     {
122         rc = IDirectDraw_SetCooperativeLevel(lpDD,
123             hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
124         ok(rc==DD_OK,"SetCooperativeLevel returned: %lx\n",rc);
125         if (modes[i].dwFlags & DDSD_PIXELFORMAT)
126         {
127             if (modes[i].ddpfPixelFormat.dwFlags & DDPF_RGB)
128             {
129                 rc = IDirectDraw_SetDisplayMode(lpDD,
130                     modes[i].dwWidth, modes[i].dwHeight,
131                     modes[i].ddpfPixelFormat.UNION_MEMBER(1, dwRGBBitCount));
132                 ok(rc==DD_OK,"SetDisplayMode returned: %lx\n",rc);
133                 rc = IDirectDraw_RestoreDisplayMode(lpDD);
134                 ok(rc==DD_OK,"RestoreDisplayMode returned: %lx\n",rc);
135             }
136         }
137     }
138     flush_modes();
139 }
140
141 START_TEST(ddrawmodes)
142 {
143     setdisplaymode_tests();
144 }