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
25 #include "wine/test.h"
31 static void dump_region(HRGN hrgn
)
39 printf( "(null) region\n" );
42 if (!(size
= GetRegionData( hrgn
, 0, NULL
))) return;
43 if (!(data
= HeapAlloc( GetProcessHeap(), 0, size
))) return;
44 GetRegionData( hrgn
, size
, data
);
45 printf( "%d rects:", data
->rdh
.nCount
);
46 for (i
= 0, rect
= (RECT
*)data
->Buffer
; i
< data
->rdh
.nCount
; i
++, rect
++)
47 printf( " (%d,%d)-(%d,%d)", rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
49 HeapFree( GetProcessHeap(), 0, data
);
52 static void test_savedc_2(void)
60 hwnd
= CreateWindowExA(0, "static", "", WS_POPUP
, 0,0,100,100,
63 ShowWindow(hwnd
, SW_SHOW
);
66 hrgn
= CreateRectRgn(0, 0, 0, 0);
70 ok(hdc
!= NULL
, "CreateDC rets %p\n", hdc
);
72 ret
= GetClipBox(hdc
, &rc_clip
);
73 ok(ret
== SIMPLEREGION
, "GetClipBox returned %d instead of SIMPLEREGION\n", ret
);
74 ret
= GetClipRgn(hdc
, hrgn
);
75 ok(ret
== 0, "GetClipRgn returned %d instead of 0\n", ret
);
76 ret
= GetRgnBox(hrgn
, &rc
);
77 ok(ret
== NULLREGION
, "GetRgnBox returned %d (%d,%d-%d,%d) instead of NULLREGION\n",
78 ret
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
79 /*dump_region(hrgn);*/
80 SetRect(&rc
, 0, 0, 100, 100);
81 ok(EqualRect(&rc
, &rc_clip
),
82 "rects are not equal: (%d,%d-%d,%d) - (%d,%d-%d,%d)\n",
83 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
84 rc_clip
.left
, rc_clip
.top
, rc_clip
.right
, rc_clip
.bottom
);
89 ok(ret
== 1, "ret = %d\n", ret
);
92 ret
= IntersectClipRect(hdc
, 0, 0, 50, 50);
93 #if 0 /* XP returns COMPLEXREGION although dump_region reports only 1 rect */
94 ok(ret
== SIMPLEREGION
, "IntersectClipRect returned %d instead of SIMPLEREGION\n", ret
);
96 if (ret
!= SIMPLEREGION
)
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 ret
= GetClipBox(hdc
, &rc_clip
);
106 ok(ret
== SIMPLEREGION
, "GetClipBox returned %d instead of SIMPLEREGION\n", ret
);
107 SetRect(&rc
, 0, 0, 50, 50);
108 ok(EqualRect(&rc
, &rc_clip
), "rects are not equal\n");
110 ret
= RestoreDC(hdc
, 1);
111 ok(ret
, "ret = %d\n", ret
);
113 ret
= GetClipBox(hdc
, &rc_clip
);
114 ok(ret
== SIMPLEREGION
, "GetClipBox returned %d instead of SIMPLEREGION\n", ret
);
115 SetRect(&rc
, 0, 0, 100, 100);
116 ok(EqualRect(&rc
, &rc_clip
), "rects are not equal\n");
119 ReleaseDC(hwnd
, hdc
);
123 static void test_savedc(void)
125 HDC hdc
= CreateDCA("DISPLAY", NULL
, NULL
, NULL
);
128 ok(hdc
!= NULL
, "CreateDC rets %p\n", hdc
);
131 ok(ret
== 1, "ret = %d\n", ret
);
133 ok(ret
== 2, "ret = %d\n", ret
);
135 ok(ret
== 3, "ret = %d\n", ret
);
136 ret
= RestoreDC(hdc
, -1);
137 ok(ret
, "ret = %d\n", ret
);
139 ok(ret
== 3, "ret = %d\n", ret
);
140 ret
= RestoreDC(hdc
, 1);
141 ok(ret
, "ret = %d\n", ret
);
143 ok(ret
== 1, "ret = %d\n", ret
);
145 ok(ret
== 2, "ret = %d\n", ret
);
147 ok(ret
== 3, "ret = %d\n", ret
);
148 ret
= RestoreDC(hdc
, -2);
149 ok(ret
, "ret = %d\n", ret
);
151 ok(ret
== 2, "ret = %d\n", ret
);
152 ret
= RestoreDC(hdc
, -2);
153 ok(ret
, "ret = %d\n", ret
);
155 ok(ret
== 1, "ret = %d\n", ret
);
157 ok(ret
== 2, "ret = %d\n", ret
);
158 ret
= RestoreDC(hdc
, -4);
159 ok(!ret
, "ret = %d\n", ret
);
160 ret
= RestoreDC(hdc
, 3);
161 ok(!ret
, "ret = %d\n", ret
);
163 /* Under win98 the following two succeed and both clear the save stack
164 ret = RestoreDC(hdc, -3);
165 ok(!ret, "ret = %d\n", ret);
166 ret = RestoreDC(hdc, 0);
167 ok(!ret, "ret = %d\n", ret);
170 ret
= RestoreDC(hdc
, 1);
171 ok(ret
, "ret = %d\n", ret
);