2 * Unit tests for dc functions
4 * Copyright (c) 2005 Huw Davies
5 * Copyright (c) 2005 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define WINVER 0x0501 /* request latest DEVMODE */
27 #include "wine/test.h"
33 static void dump_region(HRGN hrgn)
41 printf( "(null) region\n" );
44 if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
45 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
46 GetRegionData( hrgn, size, data );
47 printf( "%d rects:", data->rdh.nCount );
48 for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
49 printf( " (%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
51 HeapFree( GetProcessHeap(), 0, data );
54 static void test_savedc_2(void)
62 hwnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,
65 ShowWindow(hwnd, SW_SHOW);
68 hrgn = CreateRectRgn(0, 0, 0, 0);
72 ok(hdc != NULL, "CreateDC rets %p\n", hdc);
74 ret = GetClipBox(hdc, &rc_clip);
75 ok(ret == SIMPLEREGION, "GetClipBox returned %d instead of SIMPLEREGION\n", ret);
76 ret = GetClipRgn(hdc, hrgn);
77 ok(ret == 0, "GetClipRgn returned %d instead of 0\n", ret);
78 ret = GetRgnBox(hrgn, &rc);
79 ok(ret == NULLREGION, "GetRgnBox returned %d (%d,%d-%d,%d) instead of NULLREGION\n",
80 ret, rc.left, rc.top, rc.right, rc.bottom);
81 /*dump_region(hrgn);*/
82 SetRect(&rc, 0, 0, 100, 100);
83 ok(EqualRect(&rc, &rc_clip),
84 "rects are not equal: (%d,%d-%d,%d) - (%d,%d-%d,%d)\n",
85 rc.left, rc.top, rc.right, rc.bottom,
86 rc_clip.left, rc_clip.top, rc_clip.right, rc_clip.bottom);
91 ok(ret == 1, "ret = %d\n", ret);
94 ret = IntersectClipRect(hdc, 0, 0, 50, 50);
95 if (ret == COMPLEXREGION)
97 /* XP returns COMPLEXREGION although dump_region reports only 1 rect */
98 trace("Windows BUG: IntersectClipRect returned %d instead of SIMPLEREGION\n", ret);
99 /* let's make sure that it's a simple region */
100 ret = GetClipRgn(hdc, hrgn);
101 ok(ret == 1, "GetClipRgn returned %d instead of 1\n", ret);
105 ok(ret == SIMPLEREGION, "IntersectClipRect returned %d instead of SIMPLEREGION\n", ret);
107 ret = GetClipBox(hdc, &rc_clip);
108 ok(ret == SIMPLEREGION, "GetClipBox returned %d instead of SIMPLEREGION\n", ret);
109 SetRect(&rc, 0, 0, 50, 50);
110 ok(EqualRect(&rc, &rc_clip), "rects are not equal\n");
112 ret = RestoreDC(hdc, 1);
113 ok(ret, "ret = %d\n", ret);
115 ret = GetClipBox(hdc, &rc_clip);
116 ok(ret == SIMPLEREGION, "GetClipBox returned %d instead of SIMPLEREGION\n", ret);
117 SetRect(&rc, 0, 0, 100, 100);
118 ok(EqualRect(&rc, &rc_clip), "rects are not equal\n");
121 ReleaseDC(hwnd, hdc);
125 static void test_savedc(void)
127 HDC hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
130 ok(hdc != NULL, "CreateDC rets %p\n", hdc);
133 ok(ret == 1, "ret = %d\n", ret);
135 ok(ret == 2, "ret = %d\n", ret);
137 ok(ret == 3, "ret = %d\n", ret);
138 ret = RestoreDC(hdc, -1);
139 ok(ret, "ret = %d\n", ret);
141 ok(ret == 3, "ret = %d\n", ret);
142 ret = RestoreDC(hdc, 1);
143 ok(ret, "ret = %d\n", ret);
145 ok(ret == 1, "ret = %d\n", ret);
147 ok(ret == 2, "ret = %d\n", ret);
149 ok(ret == 3, "ret = %d\n", ret);
150 ret = RestoreDC(hdc, -2);
151 ok(ret, "ret = %d\n", ret);
153 ok(ret == 2, "ret = %d\n", ret);
154 ret = RestoreDC(hdc, -2);
155 ok(ret, "ret = %d\n", ret);
157 ok(ret == 1, "ret = %d\n", ret);
159 ok(ret == 2, "ret = %d\n", ret);
160 ret = RestoreDC(hdc, -4);
161 ok(!ret, "ret = %d\n", ret);
162 ret = RestoreDC(hdc, 3);
163 ok(!ret, "ret = %d\n", ret);
165 /* Under win98 the following two succeed and both clear the save stack
166 ret = RestoreDC(hdc, -3);
167 ok(!ret, "ret = %d\n", ret);
168 ret = RestoreDC(hdc, 0);
169 ok(!ret, "ret = %d\n", ret);
172 ret = RestoreDC(hdc, 1);
173 ok(ret, "ret = %d\n", ret);
178 static void test_GdiConvertToDevmodeW(void)
180 DEVMODEW * (WINAPI *pGdiConvertToDevmodeW)(const DEVMODEA *);
185 pGdiConvertToDevmodeW = (void *)GetProcAddress(GetModuleHandleA("gdi32.dll"), "GdiConvertToDevmodeW");
186 if (!pGdiConvertToDevmodeW)
188 skip("GdiConvertToDevmodeW is not available on this platform\n");
192 ret = EnumDisplaySettingsA(NULL, ENUM_CURRENT_SETTINGS, &dmA);
193 ok(ret, "EnumDisplaySettingsExA error %u\n", GetLastError());
194 ok(dmA.dmSize >= FIELD_OFFSET(DEVMODEA, dmICMMethod), "dmSize is too small: %04x\n", dmA.dmSize);
195 ok(dmA.dmSize <= sizeof(DEVMODEA), "dmSize is too large: %04x\n", dmA.dmSize);
197 dmW = pGdiConvertToDevmodeW(&dmA);
198 ok(dmW->dmSize >= FIELD_OFFSET(DEVMODEW, dmICMMethod), "dmSize is too small: %04x\n", dmW->dmSize);
199 ok(dmW->dmSize <= sizeof(DEVMODEW), "dmSize is too large: %04x\n", dmW->dmSize);
200 HeapFree(GetProcessHeap(), 0, dmW);
202 dmA.dmSize = FIELD_OFFSET(DEVMODEA, dmFields) + sizeof(dmA.dmFields);
203 dmW = pGdiConvertToDevmodeW(&dmA);
204 ok(dmW->dmSize == FIELD_OFFSET(DEVMODEW, dmFields) + sizeof(dmW->dmFields),
205 "wrong size %u\n", dmW->dmSize);
206 HeapFree(GetProcessHeap(), 0, dmW);
208 dmA.dmICMMethod = DMICMMETHOD_NONE;
209 dmA.dmSize = FIELD_OFFSET(DEVMODEA, dmICMMethod) + sizeof(dmA.dmICMMethod);
210 dmW = pGdiConvertToDevmodeW(&dmA);
211 ok(dmW->dmSize == FIELD_OFFSET(DEVMODEW, dmICMMethod) + sizeof(dmW->dmICMMethod),
212 "wrong size %u\n", dmW->dmSize);
213 ok(dmW->dmICMMethod == DMICMMETHOD_NONE,
214 "expected DMICMMETHOD_NONE, got %u\n", dmW->dmICMMethod);
215 HeapFree(GetProcessHeap(), 0, dmW);
218 dmW = pGdiConvertToDevmodeW(&dmA);
219 ok(dmW->dmSize == FIELD_OFFSET(DEVMODEW, dmPanningHeight) + sizeof(dmW->dmPanningHeight),
220 "wrong size %u\n", dmW->dmSize);
221 HeapFree(GetProcessHeap(), 0, dmW);
223 SetLastError(0xdeadbeef);
225 dmW = pGdiConvertToDevmodeW(&dmA);
226 ok(!dmW, "GdiConvertToDevmodeW should fail\n");
227 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %u\n", GetLastError());
229 /* this is the minimal dmSize that XP accepts */
230 dmA.dmSize = FIELD_OFFSET(DEVMODEA, dmFields);
231 dmW = pGdiConvertToDevmodeW(&dmA);
232 ok(dmW->dmSize == FIELD_OFFSET(DEVMODEW, dmFields),
233 "expected %04x, got %04x\n", FIELD_OFFSET(DEVMODEW, dmFields), dmW->dmSize);
234 HeapFree(GetProcessHeap(), 0, dmW);
237 static void test_CreateCompatibleDC(void)
243 /* Create a DC compatible with the screen */
244 hDC = CreateCompatibleDC(NULL);
245 ok(hDC != NULL, "CreateCompatibleDC returned %p\n", hDC);
247 /* Delete this DC, this should succeed */
248 bRet = DeleteDC(hDC);
249 ok(bRet == TRUE, "DeleteDC returned %u\n", bRet);
251 /* Try to create a DC compatible to the deleted DC. This has to fail */
252 hNewDC = CreateCompatibleDC(hDC);
253 ok(hNewDC == NULL, "CreateCompatibleDC returned %p\n", hNewDC);
260 test_GdiConvertToDevmodeW();
261 test_CreateCompatibleDC();