dplayx: Code to forward player creation
[wine/gsoc_dplay.git] / dlls / gdi32 / tests / clipping.c
blob06cb22a03c599816e0036871e89bd21d8e5f4393
1 /*
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"
22 #include "winbase.h"
23 #include "wingdi.h"
24 #include "winuser.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);
29 HDC hdc;
30 HRGN hrgn = CreateRectRgn(0, 0, 0, 0);
31 int ret;
32 RECT rc, rc2;
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);
39 hdc = GetDC(hwnd);
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 */
68 SetMetaRgn(hdc);
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) ||
115 broken(IsRectEmpty(&ret_rc)), /* win95 */
116 "GetRandomRgn %d,%d - %d,%d\n",
117 ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom);
119 DeleteObject(hrgn);
120 ReleaseDC(hwnd, hdc);
121 DestroyWindow(hwnd);
124 static void verify_region(HRGN hrgn, const RECT *rc)
126 union
128 RGNDATA data;
129 char buf[sizeof(RGNDATAHEADER) + sizeof(RECT)];
130 } rgn;
131 const RECT *rect;
132 DWORD ret;
134 ret = GetRegionData(hrgn, 0, NULL);
135 if (IsRectEmpty(rc))
136 ok(ret == sizeof(rgn.data.rdh), "expected sizeof(rdh), got %u\n", ret);
137 else
138 ok(ret == sizeof(rgn.data.rdh) + sizeof(RECT), "expected sizeof(rgn), got %u\n", ret);
140 if (!ret) return;
142 ret = GetRegionData(hrgn, sizeof(rgn), &rgn.data);
143 if (IsRectEmpty(rc))
144 ok(ret == sizeof(rgn.data.rdh), "expected sizeof(rdh), got %u\n", ret);
145 else
146 ok(ret == sizeof(rgn.data.rdh) + sizeof(RECT), "expected sizeof(rgn), got %u\n", ret);
148 trace("size %u, type %u, count %u, rgn size %u, bound (%d,%d-%d,%d)\n",
149 rgn.data.rdh.dwSize, rgn.data.rdh.iType,
150 rgn.data.rdh.nCount, rgn.data.rdh.nRgnSize,
151 rgn.data.rdh.rcBound.left, rgn.data.rdh.rcBound.top,
152 rgn.data.rdh.rcBound.right, rgn.data.rdh.rcBound.bottom);
153 if (rgn.data.rdh.nCount != 0)
155 rect = (const RECT *)rgn.data.Buffer;
156 trace("rect (%d,%d-%d,%d)\n", rect->left, rect->top, rect->right, rect->bottom);
157 ok(EqualRect(rect, rc), "rects don't match\n");
160 ok(rgn.data.rdh.dwSize == sizeof(rgn.data.rdh), "expected sizeof(rdh), got %u\n", rgn.data.rdh.dwSize);
161 ok(rgn.data.rdh.iType == RDH_RECTANGLES, "expected RDH_RECTANGLES, got %u\n", rgn.data.rdh.iType);
162 if (IsRectEmpty(rc))
164 ok(rgn.data.rdh.nCount == 0, "expected 0, got %u\n", rgn.data.rdh.nCount);
165 ok(rgn.data.rdh.nRgnSize == 0 ||
166 broken(rgn.data.rdh.nRgnSize == 168), /* NT4 */
167 "expected 0, got %u\n", rgn.data.rdh.nRgnSize);
169 else
171 ok(rgn.data.rdh.nCount == 1, "expected 1, got %u\n", rgn.data.rdh.nCount);
172 ok(rgn.data.rdh.nRgnSize == sizeof(RECT) ||
173 broken(rgn.data.rdh.nRgnSize == 168), /* NT4 */
174 "expected sizeof(RECT), got %u\n", rgn.data.rdh.nRgnSize);
176 ok(EqualRect(&rgn.data.rdh.rcBound, rc), "rects don't match\n");
179 static void test_ExtCreateRegion(void)
181 static const RECT empty_rect;
182 static const RECT rc = { 111, 222, 333, 444 };
183 static const RECT rc_xformed = { 76, 151, 187, 262 };
184 union
186 RGNDATA data;
187 char buf[sizeof(RGNDATAHEADER) + sizeof(RECT)];
188 } rgn;
189 HRGN hrgn;
190 XFORM xform;
192 if (0) /* crashes under Win9x */
194 SetLastError(0xdeadbeef);
195 hrgn = ExtCreateRegion(NULL, 0, NULL);
196 ok(!hrgn, "ExtCreateRegion should fail\n");
197 ok(GetLastError() == ERROR_INVALID_PARAMETER, "ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
200 rgn.data.rdh.dwSize = 0;
201 rgn.data.rdh.iType = 0;
202 rgn.data.rdh.nCount = 0;
203 rgn.data.rdh.nRgnSize = 0;
204 SetRectEmpty(&rgn.data.rdh.rcBound);
205 memcpy(rgn.data.Buffer, &rc, sizeof(rc));
207 SetLastError(0xdeadbeef);
208 hrgn = ExtCreateRegion(NULL, sizeof(rgn), &rgn.data);
209 ok(!hrgn, "ExtCreateRegion should fail\n");
210 ok(GetLastError() == 0xdeadbeef, "0xdeadbeef, got %u\n", GetLastError());
212 rgn.data.rdh.dwSize = sizeof(rgn.data.rdh) - 1;
214 SetLastError(0xdeadbeef);
215 hrgn = ExtCreateRegion(NULL, sizeof(rgn), &rgn.data);
216 ok(!hrgn, "ExtCreateRegion should fail\n");
217 ok(GetLastError() == 0xdeadbeef, "0xdeadbeef, got %u\n", GetLastError());
219 /* although XP doesn't care about the type Win9x does */
220 rgn.data.rdh.iType = RDH_RECTANGLES;
221 rgn.data.rdh.dwSize = sizeof(rgn.data.rdh);
223 SetLastError(0xdeadbeef);
224 hrgn = ExtCreateRegion(NULL, sizeof(rgn), &rgn.data);
225 ok(hrgn != 0, "ExtCreateRegion error %u\n", GetLastError());
226 verify_region(hrgn, &empty_rect);
227 DeleteObject(hrgn);
229 rgn.data.rdh.nCount = 1;
230 SetRectEmpty(&rgn.data.rdh.rcBound);
231 memcpy(rgn.data.Buffer, &rc, sizeof(rc));
233 SetLastError(0xdeadbeef);
234 hrgn = ExtCreateRegion(NULL, sizeof(rgn), &rgn.data);
235 ok(hrgn != 0, "ExtCreateRegion error %u\n", GetLastError());
236 verify_region(hrgn, &rc);
237 DeleteObject(hrgn);
239 rgn.data.rdh.dwSize = sizeof(rgn.data.rdh) + 1;
241 SetLastError(0xdeadbeef);
242 hrgn = ExtCreateRegion(NULL, 1, &rgn.data);
243 ok(hrgn != 0 ||
244 broken(GetLastError() == 0xdeadbeef), /* NT4 */
245 "ExtCreateRegion error %u\n", GetLastError());
246 if(hrgn)
248 verify_region(hrgn, &rc);
249 DeleteObject(hrgn);
252 xform.eM11 = 0.5; /* 50% width */
253 xform.eM12 = 0.0;
254 xform.eM21 = 0.0;
255 xform.eM22 = 0.5; /* 50% height */
256 xform.eDx = 20.0;
257 xform.eDy = 40.0;
259 rgn.data.rdh.dwSize = sizeof(rgn.data.rdh);
261 SetLastError(0xdeadbeef);
262 hrgn = ExtCreateRegion(&xform, sizeof(rgn), &rgn.data);
263 ok(hrgn != 0, "ExtCreateRegion error %u/%x\n", GetLastError(), GetLastError());
264 verify_region(hrgn, &rc_xformed);
265 DeleteObject(hrgn);
268 START_TEST(clipping)
270 test_GetRandomRgn();
271 test_ExtCreateRegion();