2 * Unit tests for DCE support
4 * Copyright 2005 Alexandre Julliard
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include "wine/test.h"
34 #define DCX_USESTYLE 0x00010000
37 static HWND hwnd_cache, hwnd_owndc, hwnd_classdc, hwnd_classdc2;
39 /* test behavior of DC attributes with various GetDC/ReleaseDC combinations */
40 static void test_dc_attributes(void)
47 hdc = GetDC( hwnd_cache );
48 def_rop = GetROP2( hdc );
50 SetROP2( hdc, R2_WHITE );
52 ok( rop == R2_WHITE, "wrong ROP2 %d\n", rop );
54 ReleaseDC( hwnd_cache, hdc );
55 hdc = GetDC( hwnd_cache );
57 ok( rop == def_rop, "wrong ROP2 %d after release\n", rop );
58 SetROP2( hdc, R2_WHITE );
59 ReleaseDC( hwnd_cache, hdc );
61 hdc = GetDCEx( hwnd_cache, 0, DCX_USESTYLE | DCX_NORESETATTRS );
63 /* Win9x seems to silently ignore DCX_NORESETATTRS */
64 ok( rop == def_rop || rop == R2_WHITE, "wrong ROP2 %d\n", rop );
66 SetROP2( hdc, R2_WHITE );
68 ok( rop == R2_WHITE, "wrong ROP2 %d\n", rop );
70 ReleaseDC( hwnd_cache, hdc );
71 hdc = GetDCEx( hwnd_cache, 0, DCX_USESTYLE | DCX_NORESETATTRS );
73 ok( rop == def_rop || rop == R2_WHITE, "wrong ROP2 %d after release\n", rop );
74 ReleaseDC( hwnd_cache, hdc );
76 hdc = GetDCEx( hwnd_cache, 0, DCX_USESTYLE );
78 ok( rop == def_rop, "wrong ROP2 %d after release\n", rop );
79 ReleaseDC( hwnd_cache, hdc );
83 hdc = GetDC( hwnd_owndc );
84 SetROP2( hdc, R2_WHITE );
86 ok( rop == R2_WHITE, "wrong ROP2 %d\n", rop );
89 ReleaseDC( hwnd_owndc, hdc );
90 hdc = GetDC( hwnd_owndc );
91 ok( old_hdc == hdc, "didn't get same DC %p/%p\n", old_hdc, hdc );
93 ok( rop == R2_WHITE, "wrong ROP2 %d after release\n", rop );
94 ReleaseDC( hwnd_owndc, hdc );
96 ok( rop == R2_WHITE, "wrong ROP2 %d after second release\n", rop );
100 hdc = GetDC( hwnd_classdc );
101 SetROP2( hdc, R2_WHITE );
102 rop = GetROP2( hdc );
103 ok( rop == R2_WHITE, "wrong ROP2 %d\n", rop );
106 ReleaseDC( hwnd_classdc, hdc );
107 hdc = GetDC( hwnd_classdc );
108 ok( old_hdc == hdc, "didn't get same DC %p/%p\n", old_hdc, hdc );
109 rop = GetROP2( hdc );
110 ok( rop == R2_WHITE, "wrong ROP2 %d after release\n", rop );
111 ReleaseDC( hwnd_classdc, hdc );
112 rop = GetROP2( hdc );
113 ok( rop == R2_WHITE, "wrong ROP2 %d after second release\n", rop );
115 /* test class DC with 2 windows */
117 old_hdc = GetDC( hwnd_classdc );
118 SetROP2( old_hdc, R2_BLACK );
119 hdc = GetDC( hwnd_classdc2 );
120 ok( old_hdc == hdc, "didn't get same DC %p/%p\n", old_hdc, hdc );
121 rop = GetROP2( hdc );
122 ok( rop == R2_BLACK, "wrong ROP2 %d for other window\n", rop );
123 ReleaseDC( hwnd_classdc, old_hdc );
124 ReleaseDC( hwnd_classdc, hdc );
125 rop = GetROP2( hdc );
126 ok( rop == R2_BLACK, "wrong ROP2 %d after release\n", rop );
130 /* test behavior with various invalid parameters */
131 static void test_parameters(void)
135 hdc = GetDC( hwnd_cache );
136 ok( ReleaseDC( hwnd_owndc, hdc ), "ReleaseDC with wrong window should succeed\n" );
138 hdc = GetDC( hwnd_cache );
139 ok( !ReleaseDC( hwnd_cache, 0 ), "ReleaseDC with wrong HDC should fail\n" );
140 ok( ReleaseDC( hwnd_cache, hdc ), "correct ReleaseDC should succeed\n" );
141 ok( !ReleaseDC( hwnd_cache, hdc ), "second ReleaseDC should fail\n" );
143 hdc = GetDC( hwnd_owndc );
144 ok( ReleaseDC( hwnd_cache, hdc ), "ReleaseDC with wrong window should succeed\n" );
145 hdc = GetDC( hwnd_owndc );
146 ok( ReleaseDC( hwnd_owndc, hdc ), "correct ReleaseDC should succeed\n" );
147 ok( ReleaseDC( hwnd_owndc, hdc ), "second ReleaseDC should succeed\n" );
149 hdc = GetDC( hwnd_classdc );
150 ok( ReleaseDC( hwnd_cache, hdc ), "ReleaseDC with wrong window should succeed\n" );
151 hdc = GetDC( hwnd_classdc );
152 ok( ReleaseDC( hwnd_classdc, hdc ), "correct ReleaseDC should succeed\n" );
153 ok( ReleaseDC( hwnd_classdc, hdc ), "second ReleaseDC should succeed\n" );
157 static void test_dc_visrgn(void)
165 SetRect( &rect, 10, 10, 20, 20 );
166 MapWindowPoints( hwnd_cache, 0, (POINT *)&rect, 2 );
167 hrgn = CreateRectRgnIndirect( &rect );
168 hdc = GetDCEx( hwnd_cache, hrgn, DCX_INTERSECTRGN | DCX_USESTYLE );
169 SetRectEmpty( &rect );
170 GetClipBox( hdc, &rect );
171 ok( rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20,
172 "invalid clip box %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
173 ok( GetRgnBox( hrgn, &rect ) != ERROR, "region must still be valid\n" );
174 ReleaseDC( hwnd_cache, hdc );
175 ok( GetRgnBox( hrgn, &rect ) == ERROR, "region must no longer be valid\n" );
177 /* cache DC with NORESETATTRS */
179 SetRect( &rect, 10, 10, 20, 20 );
180 MapWindowPoints( hwnd_cache, 0, (POINT *)&rect, 2 );
181 hrgn = CreateRectRgnIndirect( &rect );
182 hdc = GetDCEx( hwnd_cache, hrgn, DCX_INTERSECTRGN | DCX_USESTYLE | DCX_NORESETATTRS );
183 SetRectEmpty( &rect );
184 GetClipBox( hdc, &rect );
185 ok( rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20,
186 "invalid clip box %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
187 ok( GetRgnBox( hrgn, &rect ) != ERROR, "region must still be valid\n" );
188 ReleaseDC( hwnd_cache, hdc );
189 ok( GetRgnBox( hrgn, &rect ) == ERROR, "region must no longer be valid\n" );
190 hdc = GetDCEx( hwnd_cache, 0, DCX_USESTYLE | DCX_NORESETATTRS );
191 SetRectEmpty( &rect );
192 GetClipBox( hdc, &rect );
193 ok( !(rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20),
194 "clip box sould have been reset %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
195 ReleaseDC( hwnd_cache, hdc );
199 SetRect( &rect, 10, 10, 20, 20 );
200 MapWindowPoints( hwnd_owndc, 0, (POINT *)&rect, 2 );
201 hrgn = CreateRectRgnIndirect( &rect );
202 hdc = GetDCEx( hwnd_owndc, hrgn, DCX_INTERSECTRGN | DCX_USESTYLE );
203 SetRectEmpty( &rect );
204 GetClipBox( hdc, &rect );
205 ok( rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20,
206 "invalid clip box %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
207 ok( GetRgnBox( hrgn, &rect ) != ERROR, "region must still be valid\n" );
208 ReleaseDC( hwnd_owndc, hdc );
209 ok( GetRgnBox( hrgn, &rect ) != ERROR, "region must still be valid\n" );
210 SetRectEmpty( &rect );
211 GetClipBox( hdc, &rect );
212 ok( rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20,
213 "invalid clip box %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
214 hdc = GetDCEx( hwnd_owndc, 0, DCX_USESTYLE );
215 SetRectEmpty( &rect );
216 GetClipBox( hdc, &rect );
217 ok( rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20,
218 "invalid clip box %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
219 ok( GetRgnBox( hrgn, &rect ) != ERROR, "region must still be valid\n" );
220 ReleaseDC( hwnd_owndc, hdc );
221 ok( GetRgnBox( hrgn, &rect ) != ERROR, "region must still be valid\n" );
223 SetRect( &rect, 20, 20, 30, 30 );
224 MapWindowPoints( hwnd_owndc, 0, (POINT *)&rect, 2 );
225 hrgn2 = CreateRectRgnIndirect( &rect );
226 hdc = GetDCEx( hwnd_owndc, hrgn2, DCX_INTERSECTRGN | DCX_USESTYLE );
227 ok( GetRgnBox( hrgn, &rect ) == ERROR, "region must no longer be valid\n" );
228 SetRectEmpty( &rect );
229 GetClipBox( hdc, &rect );
230 ok( rect.left >= 20 && rect.top >= 20 && rect.right <= 30 && rect.bottom <= 30,
231 "invalid clip box %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
232 ok( GetRgnBox( hrgn2, &rect ) != ERROR, "region2 must still be valid\n" );
233 ReleaseDC( hwnd_owndc, hdc );
234 ok( GetRgnBox( hrgn2, &rect ) != ERROR, "region2 must still be valid\n" );
235 hdc = GetDCEx( hwnd_owndc, 0, DCX_EXCLUDERGN | DCX_USESTYLE );
236 ok( GetRgnBox( hrgn2, &rect ) == ERROR, "region must no longer be valid\n" );
237 SetRectEmpty( &rect );
238 GetClipBox( hdc, &rect );
239 ok( !(rect.left >= 20 && rect.top >= 20 && rect.right <= 30 && rect.bottom <= 30),
240 "clip box should have been reset %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
241 ReleaseDC( hwnd_owndc, hdc );
245 SetRect( &rect, 10, 10, 20, 20 );
246 MapWindowPoints( hwnd_classdc, 0, (POINT *)&rect, 2 );
247 hrgn = CreateRectRgnIndirect( &rect );
248 hdc = GetDCEx( hwnd_classdc, hrgn, DCX_INTERSECTRGN | DCX_USESTYLE );
249 SetRectEmpty( &rect );
250 GetClipBox( hdc, &rect );
251 ok( rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20,
252 "invalid clip box %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
253 ok( GetRgnBox( hrgn, &rect ) != ERROR, "region must still be valid\n" );
254 ReleaseDC( hwnd_classdc, hdc );
255 ok( GetRgnBox( hrgn, &rect ) != ERROR, "region must still be valid\n" );
256 SetRectEmpty( &rect );
257 GetClipBox( hdc, &rect );
258 ok( rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20,
259 "invalid clip box %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
261 hdc = GetDCEx( hwnd_classdc, 0, DCX_USESTYLE );
262 SetRectEmpty( &rect );
263 GetClipBox( hdc, &rect );
264 ok( rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20,
265 "invalid clip box %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
266 ok( GetRgnBox( hrgn, &rect ) != ERROR, "region must still be valid\n" );
267 ReleaseDC( hwnd_classdc, hdc );
268 ok( GetRgnBox( hrgn, &rect ) != ERROR, "region must still be valid\n" );
270 SetRect( &rect, 20, 20, 30, 30 );
271 MapWindowPoints( hwnd_classdc, 0, (POINT *)&rect, 2 );
272 hrgn2 = CreateRectRgnIndirect( &rect );
273 hdc = GetDCEx( hwnd_classdc, hrgn2, DCX_INTERSECTRGN | DCX_USESTYLE );
274 ok( GetRgnBox( hrgn, &rect ) == ERROR, "region must no longer be valid\n" );
275 SetRectEmpty( &rect );
276 GetClipBox( hdc, &rect );
277 ok( rect.left >= 20 && rect.top >= 20 && rect.right <= 30 && rect.bottom <= 30,
278 "invalid clip box %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
279 ok( GetRgnBox( hrgn2, &rect ) != ERROR, "region2 must still be valid\n" );
282 hdc = GetDCEx( hwnd_classdc2, 0, DCX_USESTYLE );
283 ok( old_hdc == hdc, "did not get the same hdc %p/%p\n", old_hdc, hdc );
284 ok( GetRgnBox( hrgn2, &rect ) != ERROR, "region2 must still be valid\n" );
285 SetRectEmpty( &rect );
286 GetClipBox( hdc, &rect );
287 ok( !(rect.left >= 20 && rect.top >= 20 && rect.right <= 30 && rect.bottom <= 30),
288 "clip box should have been reset %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
289 ReleaseDC( hwnd_classdc2, hdc );
290 ok( GetRgnBox( hrgn2, &rect ) != ERROR, "region2 must still be valid\n" );
291 hdc = GetDCEx( hwnd_classdc2, 0, DCX_EXCLUDERGN | DCX_USESTYLE );
292 ok( GetRgnBox( hrgn2, &rect ) != ERROR, "region2 must still be valid\n" );
293 ok( !(rect.left >= 20 && rect.top >= 20 && rect.right <= 30 && rect.bottom <= 30),
294 "clip box must have been reset %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
295 ReleaseDC( hwnd_classdc2, hdc );
299 /* test various BeginPaint/EndPaint behaviors */
300 static void test_begin_paint(void)
308 /* clear update region */
309 RedrawWindow( hwnd_cache, NULL, 0, RDW_VALIDATE|RDW_NOFRAME|RDW_NOERASE );
310 SetRect( &rect, 10, 10, 20, 20 );
311 RedrawWindow( hwnd_cache, &rect, 0, RDW_INVALIDATE );
312 hdc = BeginPaint( hwnd_cache, &ps );
313 SetRectEmpty( &rect );
314 GetClipBox( hdc, &rect );
315 ok( rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20,
316 "invalid clip box %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
317 EndPaint( hwnd_cache, &ps );
321 RedrawWindow( hwnd_owndc, NULL, 0, RDW_VALIDATE|RDW_NOFRAME|RDW_NOERASE );
322 SetRect( &rect, 10, 10, 20, 20 );
323 RedrawWindow( hwnd_owndc, &rect, 0, RDW_INVALIDATE );
324 hdc = BeginPaint( hwnd_owndc, &ps );
325 SetRectEmpty( &rect );
326 GetClipBox( hdc, &rect );
327 ok( rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20,
328 "invalid clip box %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
329 ReleaseDC( hwnd_owndc, hdc );
330 SetRectEmpty( &rect );
331 GetClipBox( hdc, &rect );
332 ok( rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20,
333 "invalid clip box %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
334 ok( GetDC( hwnd_owndc ) == hdc, "got different hdc\n" );
335 SetRectEmpty( &rect );
336 GetClipBox( hdc, &rect );
337 ok( rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20,
338 "invalid clip box %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
339 EndPaint( hwnd_owndc, &ps );
340 SetRectEmpty( &rect );
341 GetClipBox( hdc, &rect );
342 ok( !(rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20),
343 "clip box should have been reset %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
344 RedrawWindow( hwnd_owndc, NULL, 0, RDW_VALIDATE|RDW_NOFRAME|RDW_NOERASE );
345 SetRect( &rect, 10, 10, 20, 20 );
346 RedrawWindow( hwnd_owndc, &rect, 0, RDW_INVALIDATE|RDW_ERASE );
347 ok( GetDC( hwnd_owndc ) == hdc, "got different hdc\n" );
348 SetRectEmpty( &rect );
349 GetClipBox( hdc, &rect );
350 ok( !(rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20),
351 "clip box should be the whole window %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
352 RedrawWindow( hwnd_owndc, NULL, 0, RDW_ERASENOW );
353 SetRectEmpty( &rect );
354 GetClipBox( hdc, &rect );
355 ok( !(rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20),
356 "clip box should still be the whole window %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
360 RedrawWindow( hwnd_classdc, NULL, 0, RDW_VALIDATE|RDW_NOFRAME|RDW_NOERASE );
361 SetRect( &rect, 10, 10, 20, 20 );
362 RedrawWindow( hwnd_classdc, &rect, 0, RDW_INVALIDATE );
363 hdc = BeginPaint( hwnd_classdc, &ps );
364 SetRectEmpty( &rect );
365 GetClipBox( hdc, &rect );
366 ok( rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20,
367 "invalid clip box %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
370 hdc = GetDC( hwnd_classdc2 );
371 ok( old_hdc == hdc, "did not get the same hdc %p/%p\n", old_hdc, hdc );
372 SetRectEmpty( &rect );
373 GetClipBox( hdc, &rect );
374 ok( !(rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20),
375 "clip box should have been reset %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
383 cls.style = CS_DBLCLKS;
384 cls.lpfnWndProc = DefWindowProcA;
387 cls.hInstance = GetModuleHandleA(0);
389 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
390 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
391 cls.lpszMenuName = NULL;
392 cls.lpszClassName = "cache_class";
393 RegisterClassA(&cls);
394 cls.style = CS_DBLCLKS | CS_OWNDC;
395 cls.lpszClassName = "owndc_class";
396 RegisterClassA(&cls);
397 cls.style = CS_DBLCLKS | CS_CLASSDC;
398 cls.lpszClassName = "classdc_class";
399 RegisterClassA(&cls);
401 hwnd_cache = CreateWindowA("cache_class", NULL, WS_OVERLAPPED | WS_VISIBLE,
403 0, 0, GetModuleHandleA(0), NULL );
404 hwnd_owndc = CreateWindowA("owndc_class", NULL, WS_OVERLAPPED | WS_VISIBLE,
406 0, 0, GetModuleHandleA(0), NULL );
407 hwnd_classdc = CreateWindowA("classdc_class", NULL, WS_OVERLAPPED | WS_VISIBLE,
409 0, 0, GetModuleHandleA(0), NULL );
410 hwnd_classdc2 = CreateWindowA("classdc_class", NULL, WS_OVERLAPPED | WS_VISIBLE,
412 0, 0, GetModuleHandleA(0), NULL );
413 test_dc_attributes();