wined3d: Correctly destroy the adapter on format initialization failure in no3d mode.
[wine/zf.git] / dlls / user32 / tests / dce.c
blobb76f8fac45bc682dc441746c6933ff6984600b74
1 /*
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
21 #include <stdlib.h>
22 #include <stdarg.h>
23 #include <stdio.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "winuser.h"
30 #include "wine/test.h"
32 #ifndef DCX_USESTYLE
33 #define DCX_USESTYLE 0x00010000
34 #endif
36 static HWND hwnd_cache, hwnd_owndc, hwnd_classdc, hwnd_classdc2, hwnd_parent, hwnd_parentdc;
38 /* test behavior of DC attributes with various GetDC/ReleaseDC combinations */
39 static void test_dc_attributes(void)
41 HDC hdc, old_hdc;
42 HDC hdcs[20];
43 INT i, rop, def_rop, caps;
44 BOOL found_dc;
46 /* test cache DC */
48 hdc = GetDC( hwnd_cache );
49 def_rop = GetROP2( hdc );
51 SetROP2( hdc, R2_WHITE );
52 rop = GetROP2( hdc );
53 ok( rop == R2_WHITE, "wrong ROP2 %d\n", rop );
55 ok( WindowFromDC( hdc ) == hwnd_cache, "wrong window\n" );
56 ReleaseDC( hwnd_cache, hdc );
57 ok( WindowFromDC( hdc ) != hwnd_cache, "wrong window\n" );
58 hdc = GetDC( hwnd_cache );
59 rop = GetROP2( hdc );
60 ok( rop == def_rop, "wrong ROP2 %d after release\n", rop );
61 SetROP2( hdc, R2_WHITE );
62 ok( WindowFromDC( hdc ) == hwnd_cache, "wrong window\n" );
63 ReleaseDC( hwnd_cache, hdc );
64 old_hdc = hdc;
66 found_dc = FALSE;
67 for (i = 0; i < 20; i++)
69 hdc = hdcs[i] = GetDCEx( hwnd_cache, 0, DCX_USESTYLE | DCX_NORESETATTRS );
70 if (!hdc) break;
71 rop = GetROP2( hdc );
72 ok( rop == def_rop, "wrong ROP2 %d after release %p/%p\n", rop, old_hdc, hdc );
73 if (hdc == old_hdc)
75 found_dc = TRUE;
76 SetROP2( hdc, R2_WHITE );
79 if (!found_dc)
81 trace( "hdc %p not found in cache using %p\n", old_hdc, hdcs[0] );
82 old_hdc = hdcs[0];
83 SetROP2( old_hdc, R2_WHITE );
85 while (i > 0) ReleaseDC( hwnd_cache, hdcs[--i] );
87 for (i = 0; i < 20; i++)
89 hdc = hdcs[i] = GetDCEx( hwnd_cache, 0, DCX_USESTYLE | DCX_NORESETATTRS );
90 if (!hdc) break;
91 rop = GetROP2( hdc );
92 if (hdc == old_hdc)
93 ok( rop == R2_WHITE || broken( rop == def_rop), /* win9x doesn't support DCX_NORESETATTRS */
94 "wrong ROP2 %d after release %p/%p\n", rop, old_hdc, hdc );
95 else
96 ok( rop == def_rop, "wrong ROP2 %d after release %p/%p\n", rop, old_hdc, hdc );
98 while (i > 0) ReleaseDC( hwnd_cache, hdcs[--i] );
100 for (i = 0; i < 20; i++)
102 hdc = hdcs[i] = GetDCEx( hwnd_cache, 0, DCX_USESTYLE );
103 if (!hdc) break;
104 rop = GetROP2( hdc );
105 if (hdc == old_hdc)
107 ok( rop == R2_WHITE || broken( rop == def_rop),
108 "wrong ROP2 %d after release %p/%p\n", rop, old_hdc, hdc );
109 SetROP2( old_hdc, def_rop );
111 else
112 ok( rop == def_rop, "wrong ROP2 %d after release %p/%p\n", rop, old_hdc, hdc );
114 while (i > 0) ReleaseDC( hwnd_cache, hdcs[--i] );
116 /* Released cache DCs are 'disabled' */
117 rop = SetROP2( old_hdc, R2_BLACK );
118 ok( rop == 0, "got %d\n", rop );
119 rop = GetROP2( old_hdc );
120 ok( rop == 0, "got %d\n", rop );
121 caps = GetDeviceCaps( old_hdc, HORZRES );
122 ok( caps == 0, "got %d\n", caps );
123 caps = GetDeviceCaps( old_hdc, VERTRES );
124 ok( caps == 0, "got %d\n", caps );
125 caps = GetDeviceCaps( old_hdc, NUMCOLORS );
126 ok( caps == 0, "got %d\n", caps );
127 ok( WindowFromDC( old_hdc ) != hwnd_cache, "wrong window\n" );
129 hdc = GetDC(0);
130 caps = GetDeviceCaps( hdc, HORZRES );
131 ok( caps != 0, "got %d\n", caps );
132 caps = GetDeviceCaps( hdc, VERTRES );
133 ok( caps != 0, "got %d\n", caps );
134 caps = GetDeviceCaps( hdc, NUMCOLORS );
135 ok( caps != 0, "got %d\n", caps );
136 ReleaseDC( 0, hdc );
137 caps = GetDeviceCaps( hdc, HORZRES );
138 ok( caps == 0, "got %d\n", caps );
139 caps = GetDeviceCaps( hdc, VERTRES );
140 ok( caps == 0, "got %d\n", caps );
141 caps = GetDeviceCaps( hdc, NUMCOLORS );
142 ok( caps == 0, "got %d\n", caps );
144 /* test own DC */
146 hdc = GetDC( hwnd_owndc );
147 SetROP2( hdc, R2_WHITE );
148 rop = GetROP2( hdc );
149 ok( rop == R2_WHITE, "wrong ROP2 %d\n", rop );
151 old_hdc = hdc;
152 ok( WindowFromDC( hdc ) == hwnd_owndc, "wrong window\n" );
153 ReleaseDC( hwnd_owndc, hdc );
154 ok( WindowFromDC( hdc ) == hwnd_owndc, "wrong window\n" );
155 hdc = GetDC( hwnd_owndc );
156 ok( old_hdc == hdc, "didn't get same DC %p/%p\n", old_hdc, hdc );
157 rop = GetROP2( hdc );
158 ok( rop == R2_WHITE, "wrong ROP2 %d after release\n", rop );
159 ok( WindowFromDC( hdc ) == hwnd_owndc, "wrong window\n" );
160 ReleaseDC( hwnd_owndc, hdc );
161 rop = GetROP2( hdc );
162 ok( rop == R2_WHITE, "wrong ROP2 %d after second release\n", rop );
164 /* test class DC */
166 hdc = GetDC( hwnd_classdc );
167 SetROP2( hdc, R2_WHITE );
168 rop = GetROP2( hdc );
169 ok( rop == R2_WHITE, "wrong ROP2 %d\n", rop );
171 old_hdc = hdc;
172 ok( WindowFromDC( hdc ) == hwnd_classdc, "wrong window\n" );
173 ReleaseDC( hwnd_classdc, hdc );
174 ok( WindowFromDC( hdc ) == hwnd_classdc, "wrong window\n" );
175 hdc = GetDC( hwnd_classdc );
176 ok( old_hdc == hdc, "didn't get same DC %p/%p\n", old_hdc, hdc );
177 rop = GetROP2( hdc );
178 ok( rop == R2_WHITE, "wrong ROP2 %d after release\n", rop );
179 ok( WindowFromDC( hdc ) == hwnd_classdc, "wrong window\n" );
180 ReleaseDC( hwnd_classdc, hdc );
181 rop = GetROP2( hdc );
182 ok( rop == R2_WHITE, "wrong ROP2 %d after second release\n", rop );
184 /* test class DC with 2 windows */
186 old_hdc = GetDC( hwnd_classdc );
187 SetROP2( old_hdc, R2_BLACK );
188 ok( WindowFromDC( old_hdc ) == hwnd_classdc, "wrong window\n" );
189 hdc = GetDC( hwnd_classdc2 );
190 ok( old_hdc == hdc, "didn't get same DC %p/%p\n", old_hdc, hdc );
191 rop = GetROP2( hdc );
192 ok( rop == R2_BLACK, "wrong ROP2 %d for other window\n", rop );
193 ok( WindowFromDC( hdc ) == hwnd_classdc2, "wrong window\n" );
194 ReleaseDC( hwnd_classdc, old_hdc );
195 ReleaseDC( hwnd_classdc, hdc );
196 ok( WindowFromDC( hdc ) == hwnd_classdc2, "wrong window\n" );
197 rop = GetROP2( hdc );
198 ok( rop == R2_BLACK, "wrong ROP2 %d after release\n", rop );
202 /* test behavior with various invalid parameters */
203 static void test_parameters(void)
205 HDC hdc;
207 hdc = GetDC( hwnd_cache );
208 ok( ReleaseDC( hwnd_owndc, hdc ), "ReleaseDC with wrong window should succeed\n" );
210 hdc = GetDC( hwnd_cache );
211 ok( !ReleaseDC( hwnd_cache, 0 ), "ReleaseDC with wrong HDC should fail\n" );
212 ok( ReleaseDC( hwnd_cache, hdc ), "correct ReleaseDC should succeed\n" );
213 ok( !ReleaseDC( hwnd_cache, hdc ), "second ReleaseDC should fail\n" );
215 hdc = GetDC( hwnd_owndc );
216 ok( ReleaseDC( hwnd_cache, hdc ), "ReleaseDC with wrong window should succeed\n" );
217 hdc = GetDC( hwnd_owndc );
218 ok( ReleaseDC( hwnd_owndc, hdc ), "correct ReleaseDC should succeed\n" );
219 ok( ReleaseDC( hwnd_owndc, hdc ), "second ReleaseDC should succeed\n" );
221 hdc = GetDC( hwnd_classdc );
222 ok( ReleaseDC( hwnd_cache, hdc ), "ReleaseDC with wrong window should succeed\n" );
223 hdc = GetDC( hwnd_classdc );
224 ok( ReleaseDC( hwnd_classdc, hdc ), "correct ReleaseDC should succeed\n" );
225 ok( ReleaseDC( hwnd_classdc, hdc ), "second ReleaseDC should succeed\n" );
229 static void test_dc_visrgn(void)
231 HDC old_hdc, hdc;
232 HRGN hrgn, hrgn2;
233 RECT rect, parent_rect;
235 /* cache DC */
237 SetRect( &rect, 10, 10, 20, 20 );
238 MapWindowPoints( hwnd_cache, 0, (POINT *)&rect, 2 );
239 hrgn = CreateRectRgnIndirect( &rect );
240 hdc = GetDCEx( hwnd_cache, hrgn, DCX_INTERSECTRGN | DCX_USESTYLE );
241 SetRectEmpty( &rect );
242 GetClipBox( hdc, &rect );
243 ok( rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20,
244 "invalid clip box %s\n", wine_dbgstr_rect( &rect ));
245 ok( GetRgnBox( hrgn, &rect ) != ERROR, "region must still be valid\n" );
246 ReleaseDC( hwnd_cache, hdc );
247 ok( GetRgnBox( hrgn, &rect ) == ERROR, "region must no longer be valid\n" );
249 /* cache DC with NORESETATTRS */
251 SetRect( &rect, 10, 10, 20, 20 );
252 MapWindowPoints( hwnd_cache, 0, (POINT *)&rect, 2 );
253 hrgn = CreateRectRgnIndirect( &rect );
254 hdc = GetDCEx( hwnd_cache, hrgn, DCX_INTERSECTRGN | DCX_USESTYLE | DCX_NORESETATTRS );
255 SetRectEmpty( &rect );
256 GetClipBox( hdc, &rect );
257 ok( rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20,
258 "invalid clip box %s\n", wine_dbgstr_rect( &rect ));
259 ok( GetRgnBox( hrgn, &rect ) != ERROR, "region must still be valid\n" );
260 ReleaseDC( hwnd_cache, hdc );
261 ok( GetRgnBox( hrgn, &rect ) == ERROR, "region must no longer be valid\n" );
262 hdc = GetDCEx( hwnd_cache, 0, DCX_USESTYLE | DCX_NORESETATTRS );
263 SetRectEmpty( &rect );
264 GetClipBox( hdc, &rect );
265 ok( !(rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20),
266 "clip box should have been reset %s\n", wine_dbgstr_rect( &rect ));
267 ReleaseDC( hwnd_cache, hdc );
269 /* window DC */
271 SetRect( &rect, 10, 10, 20, 20 );
272 MapWindowPoints( hwnd_owndc, 0, (POINT *)&rect, 2 );
273 hrgn = CreateRectRgnIndirect( &rect );
274 hdc = GetDCEx( hwnd_owndc, hrgn, DCX_INTERSECTRGN | DCX_USESTYLE );
275 SetRectEmpty( &rect );
276 GetClipBox( hdc, &rect );
277 ok( rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20,
278 "invalid clip box %s\n", wine_dbgstr_rect( &rect ));
279 ok( GetRgnBox( hrgn, &rect ) != ERROR, "region must still be valid\n" );
280 ReleaseDC( hwnd_owndc, hdc );
281 ok( GetRgnBox( hrgn, &rect ) != ERROR, "region must still be valid\n" );
282 SetRectEmpty( &rect );
283 GetClipBox( hdc, &rect );
284 ok( rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20,
285 "invalid clip box %s\n", wine_dbgstr_rect( &rect ));
286 hdc = GetDCEx( hwnd_owndc, 0, DCX_USESTYLE );
287 SetRectEmpty( &rect );
288 GetClipBox( hdc, &rect );
289 ok( rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20,
290 "invalid clip box %s\n", wine_dbgstr_rect( &rect ));
291 ok( GetRgnBox( hrgn, &rect ) != ERROR, "region must still be valid\n" );
292 ReleaseDC( hwnd_owndc, hdc );
293 ok( GetRgnBox( hrgn, &rect ) != ERROR, "region must still be valid\n" );
295 SetRect( &rect, 20, 20, 30, 30 );
296 MapWindowPoints( hwnd_owndc, 0, (POINT *)&rect, 2 );
297 hrgn2 = CreateRectRgnIndirect( &rect );
298 hdc = GetDCEx( hwnd_owndc, hrgn2, DCX_INTERSECTRGN | DCX_USESTYLE );
299 ok( GetRgnBox( hrgn, &rect ) == ERROR, "region must no longer be valid\n" );
300 SetRectEmpty( &rect );
301 GetClipBox( hdc, &rect );
302 ok( rect.left >= 20 && rect.top >= 20 && rect.right <= 30 && rect.bottom <= 30,
303 "invalid clip box %s\n", wine_dbgstr_rect( &rect ));
304 ok( GetRgnBox( hrgn2, &rect ) != ERROR, "region2 must still be valid\n" );
305 ReleaseDC( hwnd_owndc, hdc );
306 ok( GetRgnBox( hrgn2, &rect ) != ERROR, "region2 must still be valid\n" );
307 hdc = GetDCEx( hwnd_owndc, 0, DCX_EXCLUDERGN | DCX_USESTYLE );
308 ok( GetRgnBox( hrgn2, &rect ) == ERROR, "region must no longer be valid\n" );
309 SetRectEmpty( &rect );
310 GetClipBox( hdc, &rect );
311 ok( !(rect.left >= 20 && rect.top >= 20 && rect.right <= 30 && rect.bottom <= 30),
312 "clip box should have been reset %s\n", wine_dbgstr_rect( &rect ));
313 ReleaseDC( hwnd_owndc, hdc );
315 /* class DC */
317 SetRect( &rect, 10, 10, 20, 20 );
318 MapWindowPoints( hwnd_classdc, 0, (POINT *)&rect, 2 );
319 hrgn = CreateRectRgnIndirect( &rect );
320 hdc = GetDCEx( hwnd_classdc, hrgn, DCX_INTERSECTRGN | DCX_USESTYLE );
321 SetRectEmpty( &rect );
322 GetClipBox( hdc, &rect );
323 ok( rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20,
324 "invalid clip box %s\n", wine_dbgstr_rect( &rect ));
325 ok( GetRgnBox( hrgn, &rect ) != ERROR, "region must still be valid\n" );
326 ReleaseDC( hwnd_classdc, hdc );
327 ok( GetRgnBox( hrgn, &rect ) != ERROR, "region must still be valid\n" );
328 SetRectEmpty( &rect );
329 GetClipBox( hdc, &rect );
330 ok( rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20,
331 "invalid clip box %s\n", wine_dbgstr_rect( &rect ));
333 hdc = GetDCEx( hwnd_classdc, 0, DCX_USESTYLE );
334 SetRectEmpty( &rect );
335 GetClipBox( hdc, &rect );
336 ok( rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20,
337 "invalid clip box %s\n", wine_dbgstr_rect( &rect ));
338 ok( GetRgnBox( hrgn, &rect ) != ERROR, "region must still be valid\n" );
339 ReleaseDC( hwnd_classdc, hdc );
340 ok( GetRgnBox( hrgn, &rect ) != ERROR, "region must still be valid\n" );
342 SetRect( &rect, 20, 20, 30, 30 );
343 MapWindowPoints( hwnd_classdc, 0, (POINT *)&rect, 2 );
344 hrgn2 = CreateRectRgnIndirect( &rect );
345 hdc = GetDCEx( hwnd_classdc, hrgn2, DCX_INTERSECTRGN | DCX_USESTYLE );
346 ok( GetRgnBox( hrgn, &rect ) == ERROR, "region must no longer be valid\n" );
347 SetRectEmpty( &rect );
348 GetClipBox( hdc, &rect );
349 ok( rect.left >= 20 && rect.top >= 20 && rect.right <= 30 && rect.bottom <= 30,
350 "invalid clip box %s\n", wine_dbgstr_rect( &rect ));
351 ok( GetRgnBox( hrgn2, &rect ) != ERROR, "region2 must still be valid\n" );
353 old_hdc = hdc;
354 hdc = GetDCEx( hwnd_classdc2, 0, DCX_USESTYLE );
355 ok( old_hdc == hdc, "did not get the same hdc %p/%p\n", old_hdc, hdc );
356 ok( GetRgnBox( hrgn2, &rect ) != ERROR, "region2 must still be valid\n" );
357 SetRectEmpty( &rect );
358 GetClipBox( hdc, &rect );
359 ok( !(rect.left >= 20 && rect.top >= 20 && rect.right <= 30 && rect.bottom <= 30),
360 "clip box should have been reset %s\n", wine_dbgstr_rect( &rect ));
361 ReleaseDC( hwnd_classdc2, hdc );
362 ok( GetRgnBox( hrgn2, &rect ) != ERROR, "region2 must still be valid\n" );
363 hdc = GetDCEx( hwnd_classdc2, 0, DCX_EXCLUDERGN | DCX_USESTYLE );
364 ok( GetRgnBox( hrgn2, &rect ) != ERROR, "region2 must still be valid\n" );
365 ok( !(rect.left >= 20 && rect.top >= 20 && rect.right <= 30 && rect.bottom <= 30),
366 "clip box must have been reset %s\n", wine_dbgstr_rect( &rect ));
367 ReleaseDC( hwnd_classdc2, hdc );
369 /* parent DC */
370 hdc = GetDC( hwnd_parentdc );
371 GetClipBox( hdc, &rect );
372 ReleaseDC( hwnd_parentdc, hdc );
374 hdc = GetDC( hwnd_parent );
375 GetClipBox( hdc, &parent_rect );
376 ReleaseDC( hwnd_parent, hdc );
378 ok( EqualRect( &rect, &parent_rect ), "rect = %s, expected %s\n", wine_dbgstr_rect( &rect ),
379 wine_dbgstr_rect( &parent_rect ));
383 /* test various BeginPaint/EndPaint behaviors */
384 static void test_begin_paint(void)
386 HDC old_hdc, hdc;
387 RECT rect, parent_rect;
388 PAINTSTRUCT ps;
389 COLORREF cr;
391 /* cache DC */
393 /* clear update region */
394 RedrawWindow( hwnd_cache, NULL, 0, RDW_VALIDATE|RDW_NOFRAME|RDW_NOERASE );
395 SetRect( &rect, 10, 10, 20, 20 );
396 RedrawWindow( hwnd_cache, &rect, 0, RDW_INVALIDATE );
397 hdc = BeginPaint( hwnd_cache, &ps );
398 SetRectEmpty( &rect );
399 GetClipBox( hdc, &rect );
400 ok( rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20,
401 "invalid clip box %s\n", wine_dbgstr_rect( &rect ));
402 EndPaint( hwnd_cache, &ps );
404 /* window DC */
406 RedrawWindow( hwnd_owndc, NULL, 0, RDW_VALIDATE|RDW_NOFRAME|RDW_NOERASE );
407 SetRect( &rect, 10, 10, 20, 20 );
408 RedrawWindow( hwnd_owndc, &rect, 0, RDW_INVALIDATE );
409 hdc = BeginPaint( hwnd_owndc, &ps );
410 SetRectEmpty( &rect );
411 GetClipBox( hdc, &rect );
412 ok( rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20,
413 "invalid clip box %s\n", wine_dbgstr_rect( &rect ));
414 ReleaseDC( hwnd_owndc, hdc );
415 SetRectEmpty( &rect );
416 GetClipBox( hdc, &rect );
417 ok( rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20,
418 "invalid clip box %s\n", wine_dbgstr_rect( &rect ));
419 ok( GetDC( hwnd_owndc ) == hdc, "got different hdc\n" );
420 SetRectEmpty( &rect );
421 GetClipBox( hdc, &rect );
422 ok( rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20,
423 "invalid clip box %s\n", wine_dbgstr_rect( &rect ));
424 EndPaint( hwnd_owndc, &ps );
425 SetRectEmpty( &rect );
426 GetClipBox( hdc, &rect );
427 ok( !(rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20),
428 "clip box should have been reset %s\n", wine_dbgstr_rect( &rect ));
429 RedrawWindow( hwnd_owndc, NULL, 0, RDW_VALIDATE|RDW_NOFRAME|RDW_NOERASE );
430 SetRect( &rect, 10, 10, 20, 20 );
431 RedrawWindow( hwnd_owndc, &rect, 0, RDW_INVALIDATE|RDW_ERASE );
432 ok( GetDC( hwnd_owndc ) == hdc, "got different hdc\n" );
433 SetRectEmpty( &rect );
434 GetClipBox( hdc, &rect );
435 ok( !(rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20),
436 "clip box should be the whole window %s\n", wine_dbgstr_rect( &rect ));
437 RedrawWindow( hwnd_owndc, NULL, 0, RDW_ERASENOW );
438 SetRectEmpty( &rect );
439 GetClipBox( hdc, &rect );
440 ok( !(rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20),
441 "clip box should still be the whole window %s\n", wine_dbgstr_rect( &rect ));
443 /* class DC */
445 RedrawWindow( hwnd_classdc, NULL, 0, RDW_VALIDATE|RDW_NOFRAME|RDW_NOERASE );
446 SetRect( &rect, 10, 10, 20, 20 );
447 RedrawWindow( hwnd_classdc, &rect, 0, RDW_INVALIDATE );
448 hdc = BeginPaint( hwnd_classdc, &ps );
449 SetRectEmpty( &rect );
450 GetClipBox( hdc, &rect );
451 ok( rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20,
452 "invalid clip box %s\n", wine_dbgstr_rect( &rect ));
454 old_hdc = hdc;
455 hdc = GetDC( hwnd_classdc2 );
456 ok( old_hdc == hdc, "did not get the same hdc %p/%p\n", old_hdc, hdc );
457 SetRectEmpty( &rect );
458 GetClipBox( hdc, &rect );
459 ok( !(rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20),
460 "clip box should have been reset %s\n", wine_dbgstr_rect( &rect ));
461 ReleaseDC( hwnd_classdc2, hdc );
462 EndPaint( hwnd_classdc, &ps );
464 /* parent DC */
465 RedrawWindow( hwnd_parent, NULL, 0, RDW_VALIDATE|RDW_NOFRAME|RDW_NOERASE );
466 RedrawWindow( hwnd_parentdc, NULL, 0, RDW_INVALIDATE );
467 hdc = BeginPaint( hwnd_parentdc, &ps );
468 GetClipBox( hdc, &rect );
469 cr = SetPixel( hdc, 10, 10, RGB(255, 0, 0) );
470 ok( cr != -1, "error drawing outside of window client area\n" );
471 EndPaint( hwnd_parentdc, &ps );
472 GetClientRect( hwnd_parent, &parent_rect );
474 ok( rect.left == parent_rect.left, "rect.left = %d, expected %d\n", rect.left, parent_rect.left );
475 ok( rect.top == parent_rect.top, "rect.top = %d, expected %d\n", rect.top, parent_rect.top );
476 todo_wine ok( rect.right == parent_rect.right, "rect.right = %d, expected %d\n", rect.right, parent_rect.right );
477 todo_wine ok( rect.bottom == parent_rect.bottom, "rect.bottom = %d, expected %d\n", rect.bottom, parent_rect.bottom );
479 hdc = GetDC( hwnd_parent );
480 todo_wine ok( GetPixel( hdc, 10, 10 ) == cr, "error drawing outside of window client area\n" );
481 ReleaseDC( hwnd_parent, hdc );
484 /* test ScrollWindow with window DCs */
485 static void test_scroll_window(void)
487 PAINTSTRUCT ps;
488 HDC hdc;
489 RECT clip, rect;
491 /* ScrollWindow uses the window DC, ScrollWindowEx doesn't */
493 UpdateWindow( hwnd_owndc );
494 SetRect( &clip, 25, 25, 50, 50 );
495 ScrollWindow( hwnd_owndc, -5, -10, NULL, &clip );
496 hdc = BeginPaint( hwnd_owndc, &ps );
497 SetRectEmpty( &rect );
498 GetClipBox( hdc, &rect );
499 ok( rect.left >= 25 && rect.top >= 25 && rect.right <= 50 && rect.bottom <= 50,
500 "invalid clip box %s\n", wine_dbgstr_rect( &rect ));
501 EndPaint( hwnd_owndc, &ps );
503 SetViewportExtEx( hdc, 2, 3, NULL );
504 SetViewportOrgEx( hdc, 30, 20, NULL );
506 ScrollWindow( hwnd_owndc, -5, -10, NULL, &clip );
507 hdc = BeginPaint( hwnd_owndc, &ps );
508 SetRectEmpty( &rect );
509 GetClipBox( hdc, &rect );
510 ok( rect.left >= 25 && rect.top >= 25 && rect.right <= 50 && rect.bottom <= 50,
511 "invalid clip box %s\n", wine_dbgstr_rect( &rect ));
512 EndPaint( hwnd_owndc, &ps );
514 ScrollWindowEx( hwnd_owndc, -5, -10, NULL, &clip, 0, NULL, SW_INVALIDATE | SW_ERASE );
515 hdc = BeginPaint( hwnd_owndc, &ps );
516 SetRectEmpty( &rect );
517 GetClipBox( hdc, &rect );
518 ok( rect.left >= -5 && rect.top >= 5 && rect.right <= 20 && rect.bottom <= 30,
519 "invalid clip box %s\n", wine_dbgstr_rect( &rect ));
520 EndPaint( hwnd_owndc, &ps );
522 SetViewportExtEx( hdc, 1, 1, NULL );
523 SetViewportOrgEx( hdc, 0, 0, NULL );
525 ScrollWindowEx( hwnd_owndc, -5, -10, NULL, &clip, 0, NULL, SW_INVALIDATE | SW_ERASE );
526 hdc = BeginPaint( hwnd_owndc, &ps );
527 SetRectEmpty( &rect );
528 GetClipBox( hdc, &rect );
529 ok( rect.left >= 25 && rect.top >= 25 && rect.right <= 50 && rect.bottom <= 50,
530 "invalid clip box %s\n", wine_dbgstr_rect( &rect ));
531 EndPaint( hwnd_owndc, &ps );
534 static void test_invisible_create(void)
536 HWND hwnd_owndc = CreateWindowA("owndc_class", NULL, WS_OVERLAPPED,
537 0, 200, 100, 100,
538 0, 0, GetModuleHandleA(0), NULL );
539 HDC dc1, dc2;
541 dc1 = GetDC(hwnd_owndc);
542 dc2 = GetDC(hwnd_owndc);
544 ok(dc1 == dc2, "expected owndc dcs to match\n");
546 ReleaseDC(hwnd_owndc, dc2);
547 ReleaseDC(hwnd_owndc, dc1);
548 DestroyWindow(hwnd_owndc);
551 static void test_dc_layout(void)
553 HWND hwnd_cache_rtl, hwnd_owndc_rtl, hwnd_classdc_rtl, hwnd_classdc2_rtl;
554 HDC hdc;
555 DWORD layout;
557 hdc = GetDC( hwnd_cache );
558 SetLayout( hdc, LAYOUT_RTL );
559 layout = GetLayout( hdc );
560 ReleaseDC( hwnd_cache, hdc );
561 if (!layout)
563 win_skip( "SetLayout not supported\n" );
564 return;
567 hwnd_cache_rtl = CreateWindowExA(WS_EX_LAYOUTRTL, "cache_class", NULL, WS_OVERLAPPED | WS_VISIBLE,
568 0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL );
569 hwnd_owndc_rtl = CreateWindowExA(WS_EX_LAYOUTRTL, "owndc_class", NULL, WS_OVERLAPPED | WS_VISIBLE,
570 0, 200, 100, 100, 0, 0, GetModuleHandleA(0), NULL );
571 hwnd_classdc_rtl = CreateWindowExA(WS_EX_LAYOUTRTL, "classdc_class", NULL, WS_OVERLAPPED | WS_VISIBLE,
572 200, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL );
573 hwnd_classdc2_rtl = CreateWindowExA(WS_EX_LAYOUTRTL, "classdc_class", NULL, WS_OVERLAPPED | WS_VISIBLE,
574 200, 200, 100, 100, 0, 0, GetModuleHandleA(0), NULL );
575 hdc = GetDC( hwnd_cache_rtl );
576 layout = GetLayout( hdc );
578 ok( layout == LAYOUT_RTL, "wrong layout %x\n", layout );
579 SetLayout( hdc, 0 );
580 ReleaseDC( hwnd_cache_rtl, hdc );
581 hdc = GetDC( hwnd_owndc_rtl );
582 layout = GetLayout( hdc );
583 ok( layout == LAYOUT_RTL, "wrong layout %x\n", layout );
584 ReleaseDC( hwnd_cache_rtl, hdc );
586 hdc = GetDC( hwnd_cache );
587 layout = GetLayout( hdc );
588 ok( layout == 0, "wrong layout %x\n", layout );
589 ReleaseDC( hwnd_cache, hdc );
591 hdc = GetDC( hwnd_owndc_rtl );
592 layout = GetLayout( hdc );
593 ok( layout == LAYOUT_RTL, "wrong layout %x\n", layout );
594 SetLayout( hdc, 0 );
595 ReleaseDC( hwnd_owndc_rtl, hdc );
596 hdc = GetDC( hwnd_owndc_rtl );
597 layout = GetLayout( hdc );
598 ok( layout == LAYOUT_RTL, "wrong layout %x\n", layout );
599 ReleaseDC( hwnd_owndc_rtl, hdc );
601 hdc = GetDC( hwnd_classdc_rtl );
602 layout = GetLayout( hdc );
603 ok( layout == LAYOUT_RTL, "wrong layout %x\n", layout );
604 SetLayout( hdc, 0 );
605 ReleaseDC( hwnd_classdc_rtl, hdc );
606 hdc = GetDC( hwnd_classdc2_rtl );
607 layout = GetLayout( hdc );
608 ok( layout == LAYOUT_RTL, "wrong layout %x\n", layout );
609 ReleaseDC( hwnd_classdc2_rtl, hdc );
610 hdc = GetDC( hwnd_classdc );
611 layout = GetLayout( hdc );
612 ok( layout == LAYOUT_RTL, "wrong layout %x\n", layout );
613 ReleaseDC( hwnd_classdc_rtl, hdc );
615 DestroyWindow(hwnd_classdc2_rtl);
616 DestroyWindow(hwnd_classdc_rtl);
617 DestroyWindow(hwnd_owndc_rtl);
618 DestroyWindow(hwnd_cache_rtl);
621 static void test_destroyed_window(void)
623 HDC dc, old_dc;
624 int rop;
626 dc = GetDC( hwnd_cache );
627 SetROP2( dc, R2_WHITE );
628 rop = GetROP2( dc );
629 ok( rop == R2_WHITE, "wrong ROP2 %d\n", rop );
630 ok( WindowFromDC( dc ) == hwnd_cache, "wrong window\n" );
631 old_dc = dc;
633 DestroyWindow( hwnd_cache );
634 rop = GetROP2( dc );
635 ok( rop == 0, "wrong ROP2 %d\n", rop );
636 ok( WindowFromDC( dc ) != hwnd_cache, "wrong window\n" );
637 ok( !ReleaseDC( hwnd_cache, dc ), "ReleaseDC succeeded\n" );
638 dc = GetDC( hwnd_cache );
639 ok( !dc, "Got a non-NULL DC (%p) for a destroyed window\n", dc );
641 dc = GetDC( hwnd_classdc );
642 SetROP2( dc, R2_WHITE );
643 rop = GetROP2( dc );
644 ok( rop == R2_WHITE, "wrong ROP2 %d\n", rop );
645 ok( WindowFromDC( dc ) == hwnd_classdc, "wrong window\n" );
646 old_dc = dc;
648 dc = GetDC( hwnd_classdc2 );
649 ok( old_dc == dc, "wrong DC\n" );
650 rop = GetROP2( dc );
651 ok( rop == R2_WHITE, "wrong ROP2 %d\n", rop );
652 ok( WindowFromDC( dc ) == hwnd_classdc2, "wrong window\n" );
653 DestroyWindow( hwnd_classdc2 );
655 rop = GetROP2( dc );
656 ok( rop == R2_WHITE, "wrong ROP2 %d\n", rop );
657 ok( WindowFromDC( dc ) != hwnd_classdc2, "wrong window\n" );
658 ok( !ReleaseDC( hwnd_classdc2, dc ), "ReleaseDC succeeded\n" );
659 dc = GetDC( hwnd_classdc2 );
660 ok( !dc, "Got a non-NULL DC (%p) for a destroyed window\n", dc );
662 dc = GetDC( hwnd_classdc );
663 ok( dc != 0, "Got NULL DC\n" );
664 rop = GetROP2( dc );
665 ok( rop == R2_WHITE, "wrong ROP2 %d\n", rop );
666 ok( WindowFromDC( dc ) == hwnd_classdc, "wrong window\n" );
667 DestroyWindow( hwnd_classdc );
669 rop = GetROP2( dc );
670 ok( rop == R2_WHITE, "wrong ROP2 %d\n", rop );
671 ok( WindowFromDC( dc ) != hwnd_classdc, "wrong window\n" );
672 ok( !ReleaseDC( hwnd_classdc, dc ), "ReleaseDC succeeded\n" );
673 dc = GetDC( hwnd_classdc );
674 ok( !dc, "Got a non-NULL DC (%p) for a destroyed window\n", dc );
676 dc = GetDC( hwnd_owndc );
677 ok( dc != 0, "Got NULL DC\n" );
678 rop = GetROP2( dc );
679 ok( rop == R2_WHITE, "wrong ROP2 %d\n", rop );
680 ok( WindowFromDC( dc ) == hwnd_owndc, "wrong window\n" );
681 DestroyWindow( hwnd_owndc );
683 rop = GetROP2( dc );
684 ok( rop == 0, "wrong ROP2 %d\n", rop );
685 ok( WindowFromDC( dc ) != hwnd_owndc, "wrong window\n" );
686 ok( !ReleaseDC( hwnd_owndc, dc ), "ReleaseDC succeeded\n" );
687 dc = GetDC( hwnd_owndc );
688 ok( !dc, "Got a non-NULL DC (%p) for a destroyed window\n", dc );
690 DestroyWindow( hwnd_parent );
693 START_TEST(dce)
695 WNDCLASSA cls;
697 cls.style = CS_DBLCLKS;
698 cls.lpfnWndProc = DefWindowProcA;
699 cls.cbClsExtra = 0;
700 cls.cbWndExtra = 0;
701 cls.hInstance = GetModuleHandleA(0);
702 cls.hIcon = 0;
703 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
704 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
705 cls.lpszMenuName = NULL;
706 cls.lpszClassName = "cache_class";
707 RegisterClassA(&cls);
708 cls.style = CS_DBLCLKS | CS_OWNDC;
709 cls.lpszClassName = "owndc_class";
710 RegisterClassA(&cls);
711 cls.style = CS_DBLCLKS | CS_CLASSDC;
712 cls.lpszClassName = "classdc_class";
713 RegisterClassA(&cls);
714 cls.style = CS_PARENTDC;
715 cls.lpszClassName = "parentdc_class";
716 RegisterClassA(&cls);
718 hwnd_cache = CreateWindowA("cache_class", NULL, WS_OVERLAPPED | WS_VISIBLE,
719 0, 0, 100, 100,
720 0, 0, GetModuleHandleA(0), NULL );
721 hwnd_owndc = CreateWindowA("owndc_class", NULL, WS_OVERLAPPED | WS_VISIBLE,
722 0, 200, 100, 100,
723 0, 0, GetModuleHandleA(0), NULL );
724 hwnd_classdc = CreateWindowA("classdc_class", NULL, WS_OVERLAPPED | WS_VISIBLE,
725 200, 0, 100, 100,
726 0, 0, GetModuleHandleA(0), NULL );
727 hwnd_classdc2 = CreateWindowA("classdc_class", NULL, WS_OVERLAPPED | WS_VISIBLE,
728 200, 200, 100, 100,
729 0, 0, GetModuleHandleA(0), NULL );
730 hwnd_parent = CreateWindowA("static", NULL, WS_OVERLAPPED | WS_VISIBLE,
731 400, 0, 100, 100, 0, 0, 0, NULL );
732 hwnd_parentdc = CreateWindowA("parentdc_class", NULL, WS_CHILD | WS_VISIBLE,
733 0, 0, 1, 1, hwnd_parent, 0, 0, NULL );
735 test_dc_attributes();
736 test_parameters();
737 test_dc_visrgn();
738 test_begin_paint();
739 test_scroll_window();
740 test_invisible_create();
741 test_dc_layout();
742 /* this should be last */
743 test_destroyed_window();