2 * Unit test suite for clipping
4 * Copyright 2005 Huw Davies
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 "wine/test.h"
26 static void test_GetRandomRgn(void)
28 HWND hwnd = CreateWindowExA(0,"BUTTON","test",WS_VISIBLE|WS_POPUP,0,0,100,100,GetDesktopWindow(),0,0,0);
30 HRGN hrgn = CreateRectRgn(0, 0, 0, 0);
33 RECT ret_rc, window_rc;
35 ok( hwnd != 0, "CreateWindow failed\n" );
37 SetRect(&window_rc, 400, 300, 500, 400);
38 MoveWindow(hwnd, window_rc.left, window_rc.top, window_rc.right - window_rc.left, window_rc.bottom - window_rc.top, FALSE);
41 ret = GetRandomRgn(hdc, hrgn, 1);
42 ok(ret == 0, "GetRandomRgn rets %d\n", ret);
43 ret = GetRandomRgn(hdc, hrgn, 2);
44 ok(ret == 0, "GetRandomRgn rets %d\n", ret);
45 ret = GetRandomRgn(hdc, hrgn, 3);
46 ok(ret == 0, "GetRandomRgn rets %d\n", ret);
48 /* Set a clip region */
49 SetRect(&rc, 20, 20, 80, 80);
50 IntersectClipRect(hdc, rc.left, rc.top, rc.right, rc.bottom);
52 ret = GetRandomRgn(hdc, hrgn, 1);
53 ok(ret != 0, "GetRandomRgn rets %d\n", ret);
54 GetRgnBox(hrgn, &ret_rc);
55 ok(EqualRect(&rc, &ret_rc), "GetRandomRgn %d,%d - %d,%d\n",
56 ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom);
58 ret = GetRandomRgn(hdc, hrgn, 2);
59 ok(ret == 0, "GetRandomRgn rets %d\n", ret);
61 ret = GetRandomRgn(hdc, hrgn, 3);
62 ok(ret != 0, "GetRandomRgn rets %d\n", ret);
63 GetRgnBox(hrgn, &ret_rc);
64 ok(EqualRect(&rc, &ret_rc), "GetRandomRgn %d,%d - %d,%d\n",
65 ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom);
67 /* Move the clip to the meta and clear the clip */
70 ret = GetRandomRgn(hdc, hrgn, 1);
71 ok(ret == 0, "GetRandomRgn rets %d\n", ret);
72 ret = GetRandomRgn(hdc, hrgn, 2);
73 ok(ret != 0, "GetRandomRgn rets %d\n", ret);
74 GetRgnBox(hrgn, &ret_rc);
75 ok(EqualRect(&rc, &ret_rc), "GetRandomRgn %d,%d - %d,%d\n",
76 ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom);
78 ret = GetRandomRgn(hdc, hrgn, 3);
79 ok(ret != 0, "GetRandomRgn rets %d\n", ret);
80 GetRgnBox(hrgn, &ret_rc);
81 ok(EqualRect(&rc, &ret_rc), "GetRandomRgn %d,%d - %d,%d\n",
82 ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom);
84 /* Set a new clip (still got the meta) */
85 SetRect(&rc2, 10, 30, 70, 90);
86 IntersectClipRect(hdc, rc2.left, rc2.top, rc2.right, rc2.bottom);
88 ret = GetRandomRgn(hdc, hrgn, 1);
89 ok(ret != 0, "GetRandomRgn rets %d\n", ret);
90 GetRgnBox(hrgn, &ret_rc);
91 ok(EqualRect(&rc2, &ret_rc), "GetRandomRgn %d,%d - %d,%d\n",
92 ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom);
94 ret = GetRandomRgn(hdc, hrgn, 2);
95 ok(ret != 0, "GetRandomRgn rets %d\n", ret);
96 GetRgnBox(hrgn, &ret_rc);
97 ok(EqualRect(&rc, &ret_rc), "GetRandomRgn %d,%d - %d,%d\n",
98 ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom);
100 IntersectRect(&rc2, &rc, &rc2);
102 ret = GetRandomRgn(hdc, hrgn, 3);
103 ok(ret != 0, "GetRandomRgn rets %d\n", ret);
104 GetRgnBox(hrgn, &ret_rc);
105 ok(EqualRect(&rc2, &ret_rc), "GetRandomRgn %d,%d - %d,%d\n",
106 ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom);
109 ret = GetRandomRgn(hdc, hrgn, SYSRGN);
110 ok(ret != 0, "GetRandomRgn rets %d\n", ret);
111 GetRgnBox(hrgn, &ret_rc);
112 if(GetVersion() & 0x80000000)
113 OffsetRect(&window_rc, -window_rc.left, -window_rc.top);
114 ok(EqualRect(&window_rc, &ret_rc), "GetRandomRgn %d,%d - %d,%d\n",
115 ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom);
118 ReleaseDC(hwnd, hdc);
122 static void verify_region(HRGN hrgn, const RECT *rc)
127 char buf[sizeof(RGNDATAHEADER) + sizeof(RECT)];
132 ret = GetRegionData(hrgn, 0, NULL);
134 ok(ret == sizeof(rgn.data.rdh), "expected sizeof(rdh), got %u\n", ret);
136 ok(ret == sizeof(rgn.data.rdh) + sizeof(RECT), "expected sizeof(rgn), got %u\n", ret);
140 ret = GetRegionData(hrgn, sizeof(rgn), &rgn.data);
142 ok(ret == sizeof(rgn.data.rdh), "expected sizeof(rdh), got %u\n", ret);
144 ok(ret == sizeof(rgn.data.rdh) + sizeof(RECT), "expected sizeof(rgn), got %u\n", ret);
146 trace("size %u, type %u, count %u, rgn size %u, bound (%d,%d-%d,%d)\n",
147 rgn.data.rdh.dwSize, rgn.data.rdh.iType,
148 rgn.data.rdh.nCount, rgn.data.rdh.nRgnSize,
149 rgn.data.rdh.rcBound.left, rgn.data.rdh.rcBound.top,
150 rgn.data.rdh.rcBound.right, rgn.data.rdh.rcBound.bottom);
151 if (rgn.data.rdh.nCount != 0)
153 rect = (const RECT *)rgn.data.Buffer;
154 trace("rect (%d,%d-%d,%d)\n", rect->left, rect->top, rect->right, rect->bottom);
155 ok(EqualRect(rect, rc), "rects don't match\n");
158 ok(rgn.data.rdh.dwSize == sizeof(rgn.data.rdh), "expected sizeof(rdh), got %u", rgn.data.rdh.dwSize);
159 ok(rgn.data.rdh.iType == RDH_RECTANGLES, "expected RDH_RECTANGLES, got %u\n", rgn.data.rdh.iType);
162 ok(rgn.data.rdh.nCount == 0, "expected 0, got %u\n", rgn.data.rdh.nCount);
163 ok(rgn.data.rdh.nRgnSize == 0, "expected 0, got %u\n", rgn.data.rdh.nRgnSize);
167 ok(rgn.data.rdh.nCount == 1, "expected 1, got %u\n", rgn.data.rdh.nCount);
168 ok(rgn.data.rdh.nRgnSize == sizeof(RECT), "expected sizeof(RECT), got %u\n", rgn.data.rdh.nRgnSize);
170 ok(EqualRect(&rgn.data.rdh.rcBound, rc), "rects don't match\n");
173 static void test_ExtCreateRegion(void)
175 static const RECT empty_rect;
176 static const RECT rc = { 111, 222, 333, 444 };
177 static const RECT rc_xformed = { 76, 151, 187, 262 };
181 char buf[sizeof(RGNDATAHEADER) + sizeof(RECT)];
186 if (0) /* crashes under Win9x */
188 SetLastError(0xdeadbeef);
189 hrgn = ExtCreateRegion(NULL, 0, NULL);
190 ok(!hrgn, "ExtCreateRegion should fail\n");
191 ok(GetLastError() == ERROR_INVALID_PARAMETER, "ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
194 rgn.data.rdh.dwSize = 0;
195 rgn.data.rdh.iType = 0;
196 rgn.data.rdh.nCount = 0;
197 rgn.data.rdh.nRgnSize = 0;
198 SetRectEmpty(&rgn.data.rdh.rcBound);
199 memcpy(rgn.data.Buffer, &rc, sizeof(rc));
201 SetLastError(0xdeadbeef);
202 hrgn = ExtCreateRegion(NULL, sizeof(rgn), &rgn.data);
203 ok(!hrgn, "ExtCreateRegion should fail\n");
204 ok(GetLastError() == 0xdeadbeef, "0xdeadbeef, got %u\n", GetLastError());
206 rgn.data.rdh.dwSize = sizeof(rgn.data.rdh) - 1;
208 SetLastError(0xdeadbeef);
209 hrgn = ExtCreateRegion(NULL, sizeof(rgn), &rgn.data);
210 ok(!hrgn, "ExtCreateRegion should fail\n");
211 ok(GetLastError() == 0xdeadbeef, "0xdeadbeef, got %u\n", GetLastError());
213 /* although XP doesn't care about the type Win9x does */
214 rgn.data.rdh.iType = RDH_RECTANGLES;
215 rgn.data.rdh.dwSize = sizeof(rgn.data.rdh);
217 SetLastError(0xdeadbeef);
218 hrgn = ExtCreateRegion(NULL, sizeof(rgn), &rgn.data);
219 ok(hrgn != 0, "ExtCreateRegion error %u\n", GetLastError());
220 verify_region(hrgn, &empty_rect);
223 rgn.data.rdh.nCount = 1;
224 SetRectEmpty(&rgn.data.rdh.rcBound);
225 memcpy(rgn.data.Buffer, &rc, sizeof(rc));
227 SetLastError(0xdeadbeef);
228 hrgn = ExtCreateRegion(NULL, sizeof(rgn), &rgn.data);
229 ok(hrgn != 0, "ExtCreateRegion error %u\n", GetLastError());
230 verify_region(hrgn, &rc);
233 rgn.data.rdh.dwSize = sizeof(rgn.data.rdh) + 1;
235 SetLastError(0xdeadbeef);
236 hrgn = ExtCreateRegion(NULL, 1, &rgn.data);
237 ok(hrgn != 0, "ExtCreateRegion error %u\n", GetLastError());
238 verify_region(hrgn, &rc);
241 xform.eM11 = 0.5; /* 50% width */
244 xform.eM22 = 0.5; /* 50% height */
248 rgn.data.rdh.dwSize = sizeof(rgn.data.rdh);
250 SetLastError(0xdeadbeef);
251 hrgn = ExtCreateRegion(&xform, sizeof(rgn), &rgn.data);
252 ok(hrgn != 0, "ExtCreateRegion error %u/%x\n", GetLastError(), GetLastError());
253 verify_region(hrgn, &rc_xformed);
260 test_ExtCreateRegion();