kernel32: Immediately return on failing to start wineboot
[wine/wine64.git] / dlls / gdi32 / tests / clipping.c
blob0ae3eb6ff5675f3ef4c3ef749988fc5363e3c442
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, "expected 0, got %u\n", rgn.data.rdh.nRgnSize);
167 else
169 ok(rgn.data.rdh.nCount == 1, "expected 1, got %u\n", rgn.data.rdh.nCount);
170 ok(rgn.data.rdh.nRgnSize == sizeof(RECT), "expected sizeof(RECT), got %u\n", rgn.data.rdh.nRgnSize);
172 ok(EqualRect(&rgn.data.rdh.rcBound, rc), "rects don't match\n");
175 static void test_ExtCreateRegion(void)
177 static const RECT empty_rect;
178 static const RECT rc = { 111, 222, 333, 444 };
179 static const RECT rc_xformed = { 76, 151, 187, 262 };
180 union
182 RGNDATA data;
183 char buf[sizeof(RGNDATAHEADER) + sizeof(RECT)];
184 } rgn;
185 HRGN hrgn;
186 XFORM xform;
188 if (0) /* crashes under Win9x */
190 SetLastError(0xdeadbeef);
191 hrgn = ExtCreateRegion(NULL, 0, NULL);
192 ok(!hrgn, "ExtCreateRegion should fail\n");
193 ok(GetLastError() == ERROR_INVALID_PARAMETER, "ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
196 rgn.data.rdh.dwSize = 0;
197 rgn.data.rdh.iType = 0;
198 rgn.data.rdh.nCount = 0;
199 rgn.data.rdh.nRgnSize = 0;
200 SetRectEmpty(&rgn.data.rdh.rcBound);
201 memcpy(rgn.data.Buffer, &rc, sizeof(rc));
203 SetLastError(0xdeadbeef);
204 hrgn = ExtCreateRegion(NULL, sizeof(rgn), &rgn.data);
205 ok(!hrgn, "ExtCreateRegion should fail\n");
206 ok(GetLastError() == 0xdeadbeef, "0xdeadbeef, got %u\n", GetLastError());
208 rgn.data.rdh.dwSize = sizeof(rgn.data.rdh) - 1;
210 SetLastError(0xdeadbeef);
211 hrgn = ExtCreateRegion(NULL, sizeof(rgn), &rgn.data);
212 ok(!hrgn, "ExtCreateRegion should fail\n");
213 ok(GetLastError() == 0xdeadbeef, "0xdeadbeef, got %u\n", GetLastError());
215 /* although XP doesn't care about the type Win9x does */
216 rgn.data.rdh.iType = RDH_RECTANGLES;
217 rgn.data.rdh.dwSize = sizeof(rgn.data.rdh);
219 SetLastError(0xdeadbeef);
220 hrgn = ExtCreateRegion(NULL, sizeof(rgn), &rgn.data);
221 ok(hrgn != 0, "ExtCreateRegion error %u\n", GetLastError());
222 verify_region(hrgn, &empty_rect);
223 DeleteObject(hrgn);
225 rgn.data.rdh.nCount = 1;
226 SetRectEmpty(&rgn.data.rdh.rcBound);
227 memcpy(rgn.data.Buffer, &rc, sizeof(rc));
229 SetLastError(0xdeadbeef);
230 hrgn = ExtCreateRegion(NULL, sizeof(rgn), &rgn.data);
231 ok(hrgn != 0, "ExtCreateRegion error %u\n", GetLastError());
232 verify_region(hrgn, &rc);
233 DeleteObject(hrgn);
235 rgn.data.rdh.dwSize = sizeof(rgn.data.rdh) + 1;
237 SetLastError(0xdeadbeef);
238 hrgn = ExtCreateRegion(NULL, 1, &rgn.data);
239 ok(hrgn != 0, "ExtCreateRegion error %u\n", GetLastError());
240 verify_region(hrgn, &rc);
241 DeleteObject(hrgn);
243 xform.eM11 = 0.5; /* 50% width */
244 xform.eM12 = 0.0;
245 xform.eM21 = 0.0;
246 xform.eM22 = 0.5; /* 50% height */
247 xform.eDx = 20.0;
248 xform.eDy = 40.0;
250 rgn.data.rdh.dwSize = sizeof(rgn.data.rdh);
252 SetLastError(0xdeadbeef);
253 hrgn = ExtCreateRegion(&xform, sizeof(rgn), &rgn.data);
254 ok(hrgn != 0, "ExtCreateRegion error %u/%x\n", GetLastError(), GetLastError());
255 verify_region(hrgn, &rc_xformed);
256 DeleteObject(hrgn);
259 START_TEST(clipping)
261 test_GetRandomRgn();
262 test_ExtCreateRegion();