Merge branch 'master' of git+ssh://repo.or.cz/srv/git/wine/winequartzdrv
[wine/winequartzdrv.git] / dlls / gdi32 / tests / dc.c
blob79b6ef7d8eec88b3a8ef5097becb31d5585cda1b
1 /*
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 */
24 #include <assert.h>
25 #include <stdio.h>
27 #include "wine/test.h"
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "winerror.h"
33 static void dump_region(HRGN hrgn)
35 DWORD i, size;
36 RGNDATA *data = NULL;
37 RECT *rect;
39 if (!hrgn)
41 printf( "(null) region\n" );
42 return;
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 );
50 printf( "\n" );
51 HeapFree( GetProcessHeap(), 0, data );
54 static void test_savedc_2(void)
56 HWND hwnd;
57 HDC hdc;
58 HRGN hrgn;
59 RECT rc, rc_clip;
60 int ret;
62 hwnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,
63 0, 0, 0, NULL);
64 assert(hwnd != 0);
65 ShowWindow(hwnd, SW_SHOW);
66 UpdateWindow(hwnd);
68 hrgn = CreateRectRgn(0, 0, 0, 0);
69 assert(hrgn != 0);
71 hdc = GetDC(hwnd);
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);
88 ret = SaveDC(hdc);
89 todo_wine
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);
102 dump_region(hrgn);
104 else
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");
120 DeleteObject(hrgn);
121 ReleaseDC(hwnd, hdc);
122 DestroyWindow(hwnd);
125 static void test_savedc(void)
127 HDC hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
128 int ret;
130 ok(hdc != NULL, "CreateDC rets %p\n", hdc);
132 ret = SaveDC(hdc);
133 ok(ret == 1, "ret = %d\n", ret);
134 ret = SaveDC(hdc);
135 ok(ret == 2, "ret = %d\n", ret);
136 ret = SaveDC(hdc);
137 ok(ret == 3, "ret = %d\n", ret);
138 ret = RestoreDC(hdc, -1);
139 ok(ret, "ret = %d\n", ret);
140 ret = SaveDC(hdc);
141 ok(ret == 3, "ret = %d\n", ret);
142 ret = RestoreDC(hdc, 1);
143 ok(ret, "ret = %d\n", ret);
144 ret = SaveDC(hdc);
145 ok(ret == 1, "ret = %d\n", ret);
146 ret = SaveDC(hdc);
147 ok(ret == 2, "ret = %d\n", ret);
148 ret = SaveDC(hdc);
149 ok(ret == 3, "ret = %d\n", ret);
150 ret = RestoreDC(hdc, -2);
151 ok(ret, "ret = %d\n", ret);
152 ret = SaveDC(hdc);
153 ok(ret == 2, "ret = %d\n", ret);
154 ret = RestoreDC(hdc, -2);
155 ok(ret, "ret = %d\n", ret);
156 ret = SaveDC(hdc);
157 ok(ret == 1, "ret = %d\n", ret);
158 ret = SaveDC(hdc);
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);
175 DeleteDC(hdc);
178 static void test_GdiConvertToDevmodeW(void)
180 DEVMODEW * (WINAPI *pGdiConvertToDevmodeW)(const DEVMODEA *);
181 DEVMODEA dmA;
182 DEVMODEW *dmW;
183 BOOL ret;
185 pGdiConvertToDevmodeW = (void *)GetProcAddress(GetModuleHandleA("gdi32.dll"), "GdiConvertToDevmodeW");
186 if (!pGdiConvertToDevmodeW)
188 skip("GdiConvertToDevmodeW is not available on this platform\n");
189 return;
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);
217 dmA.dmSize = 1024;
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);
224 dmA.dmSize = 0;
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 START_TEST(dc)
239 test_savedc();
240 test_savedc_2();
241 test_GdiConvertToDevmodeW();