2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for GetRandomRgn
5 * PROGRAMMERS: Timo Kreuzer
18 void Test_GetRandomRgn_Params()
24 hdc
= CreateCompatibleDC(0);
27 printf("Coun't create a dc\n");
31 hrgn
= CreateRectRgn(11, 17, 23, 42);
34 printf("Coun't create a region\n");
38 SetLastError(0xbadbad00);
39 ret
= GetRandomRgn(NULL
, NULL
, 0);
41 ok((GetLastError() == 0xbadbad00) || (GetLastError() == ERROR_INVALID_HANDLE
), "wrong error: %ld\n", GetLastError());
43 SetLastError(0xbadbad00);
44 ret
= GetRandomRgn(NULL
, NULL
, CLIPRGN
);
46 ok((GetLastError() == 0xbadbad00) || (GetLastError() == ERROR_INVALID_HANDLE
), "wrong error: %ld\n", GetLastError());
48 SetLastError(0xbadbad00);
49 ret
= GetRandomRgn(NULL
, hrgn
, 0);
51 ok((GetLastError() == 0xbadbad00) || (GetLastError() == ERROR_INVALID_HANDLE
), "wrong error: %ld\n", GetLastError());
53 SetLastError(0xbadbad00);
54 ret
= GetRandomRgn(NULL
, hrgn
, CLIPRGN
);
56 ok((GetLastError() == 0xbadbad00) || (GetLastError() == ERROR_INVALID_HANDLE
), "wrong error: %ld\n", GetLastError());
58 SetLastError(0xbadbad00);
59 ret
= GetRandomRgn(hdc
, NULL
, 0);
61 ok_long(GetLastError(), 0xbadbad00);
63 SetLastError(0xbadbad00);
64 ret
= GetRandomRgn(hdc
, NULL
, CLIPRGN
);
66 ok_long(GetLastError(), 0xbadbad00);
68 SetLastError(0xbadbad00);
69 ret
= GetRandomRgn(hdc
, hrgn
, 0);
71 ok_long(GetLastError(), 0xbadbad00);
72 #if 0 // this is vista+
73 SetLastError(0xbadbad00);
74 ret
= GetRandomRgn(hdc
, hrgn
, 5);
76 ok_long(GetLastError(), 0xbadbad00);
78 SetLastError(0xbadbad00);
79 ret
= GetRandomRgn(hdc
, hrgn
, 6);
81 ok_long(GetLastError(), 0xbadbad00);
83 SetLastError(0xbadbad00);
84 ret
= GetRandomRgn(hdc
, hrgn
, 27);
86 ok_long(GetLastError(), 0xbadbad00);
88 SetLastError(0xbadbad00);
89 ret
= GetRandomRgn(hdc
, hrgn
, -1);
91 ok_long(GetLastError(), 0xbadbad00);
93 SetLastError(0xbadbad00);
94 ret
= GetRandomRgn(hdc
, hrgn
, CLIPRGN
);
96 ok_long(GetLastError(), 0xbadbad00);
98 SetLastError(0xbadbad00);
99 ret
= GetRandomRgn((HDC
)0x123, hrgn
, CLIPRGN
);
101 ok((GetLastError() == 0xbadbad00) || (GetLastError() == ERROR_INVALID_HANDLE
), "wrong error: %ld\n", GetLastError());
107 void Test_GetRandomRgn_CLIPRGN()
114 hrgn1
= CreateRectRgn(11, 17, 23, 42);
117 printf("Coun't create a region\n");
121 hdc
= CreateCompatibleDC(0);
124 printf("Coun't create a dc\n");
128 ret
= GetRandomRgn(hdc
, hrgn1
, CLIPRGN
);
130 GetRgnBox(hrgn1
, &rect
);
131 ok_long(rect
.left
, 11);
132 ok_long(rect
.top
, 17);
133 ok_long(rect
.right
, 23);
134 ok_long(rect
.bottom
, 42);
136 hrgn2
= CreateRectRgn(1, 2, 3, 4);
137 SelectClipRgn(hdc
, hrgn2
);
139 ret
= GetRandomRgn(hdc
, hrgn1
, CLIPRGN
);
141 GetRgnBox(hrgn1
, &rect
);
142 ok_long(rect
.left
, 1);
143 ok_long(rect
.top
, 2);
144 ok_long(rect
.right
, 3);
145 ok_long(rect
.bottom
, 4);
147 hrgn2
= CreateRectRgn(2, 3, 4, 5);
148 SelectClipRgn(ghdcWindow
, hrgn2
);
150 ret
= GetRandomRgn(ghdcWindow
, hrgn1
, CLIPRGN
);
152 GetRgnBox(hrgn1
, &rect
);
153 ok_long(rect
.left
, 2);
154 ok_long(rect
.top
, 3);
155 ok_long(rect
.right
, 4);
156 ok_long(rect
.bottom
, 5);
158 MoveWindow(ghwnd
, 200, 400, 100, 100, 0);
160 ret
= GetRandomRgn(ghdcWindow
, hrgn1
, CLIPRGN
);
162 GetRgnBox(hrgn1
, &rect
);
163 ok_long(rect
.left
, 2);
164 ok_long(rect
.top
, 3);
165 ok_long(rect
.right
, 4);
166 ok_long(rect
.bottom
, 5);
173 void Test_GetRandomRgn_METARGN()
177 void Test_GetRandomRgn_APIRGN()
181 void Test_GetRandomRgn_SYSRGN()
189 hrgn1
= CreateRectRgn(11, 17, 23, 42);
192 printf("Coun't create a region\n");
196 hdc
= CreateCompatibleDC(0);
199 printf("Coun't create a dc\n");
203 ret
= GetRandomRgn(hdc
, hrgn1
, SYSRGN
);
205 GetRgnBox(hrgn1
, &rect
);
206 ok_long(rect
.left
, 0);
207 ok_long(rect
.top
, 0);
208 ok_long(rect
.right
, 1);
209 ok_long(rect
.bottom
, 1);
211 hrgn2
= CreateRectRgn(1, 2, 3, 4);
212 SelectClipRgn(hdc
, hrgn2
);
214 ret
= GetRandomRgn(hdc
, hrgn1
, SYSRGN
);
216 GetRgnBox(hrgn1
, &rect
);
217 ok_long(rect
.left
, 0);
218 ok_long(rect
.top
, 0);
219 ok_long(rect
.right
, 1);
220 ok_long(rect
.bottom
, 1);
222 hbmp
= CreateCompatibleBitmap(hdc
, 4, 7);
223 SelectObject(hdc
, hbmp
);
224 ret
= GetRandomRgn(hdc
, hrgn1
, SYSRGN
);
226 GetRgnBox(hrgn1
, &rect
);
227 ok_long(rect
.left
, 0);
228 ok_long(rect
.top
, 0);
229 ok_long(rect
.right
, 4);
230 ok_long(rect
.bottom
, 7);
233 MoveWindow(ghwnd
, 100, 100, 100, 100, 0);
234 ret
= GetRandomRgn(ghdcWindow
, hrgn1
, SYSRGN
);
236 GetRgnBox(hrgn1
, &rect
);
237 DPtoLP(ghdcWindow
, (LPPOINT
)&rect
, 2);
238 #if 0 // FIXME: this needs calculation
239 ok_long(rect
.left
, 104);
240 ok_long(rect
.top
, 124);
241 ok_long(rect
.right
, 209);
242 ok_long(rect
.bottom
, 196);
245 MoveWindow(ghwnd
, 200, 400, 200, 200, 0);
247 ret
= GetRandomRgn(ghdcWindow
, hrgn1
, SYSRGN
);
249 GetRgnBox(hrgn1
, &rect2
);
250 DPtoLP(ghdcWindow
, (LPPOINT
)&rect2
, 2);
251 #if 0 // FIXME: this needs calculation
252 ok_long(rect2
.left
, rect
.left
+ 100);
253 ok_long(rect2
.top
, rect
.top
+ 300);
254 ok_long(rect2
.right
, rect
.right
+ 200 - 13);
255 ok_long(rect2
.bottom
, rect
.bottom
+ 400);
263 void Test_GetRandomRgn_RGN5()
270 DBG_UNREFERENCED_LOCAL_VARIABLE(hrgn2
);
271 DBG_UNREFERENCED_LOCAL_VARIABLE(rect2
);
273 hrgn1
= CreateRectRgn(11, 17, 23, 42);
276 printf("Coun't create a region\n");
280 hdc
= CreateCompatibleDC(0);
283 printf("Coun't create a dc\n");
286 #if 0 // this is vista+
287 ret
= GetRandomRgn(hdc
, hrgn1
, RGN5
);
289 GetRgnBox(hrgn1
, &rect
);
290 ok_long(rect
.left
, 0);
291 ok_long(rect
.top
, 0);
292 ok_long(rect
.right
, 1);
293 ok_long(rect
.bottom
, 1);
295 hrgn2
= CreateRectRgn(1, 2, 3, 4);
296 SelectClipRgn(hdc
, hrgn2
);
298 ret
= GetRandomRgn(hdc
, hrgn1
, RGN5
);
300 GetRgnBox(hrgn1
, &rect
);
301 ok_long(rect
.left
, 0);
302 ok_long(rect
.top
, 0);
303 ok_long(rect
.right
, 1);
304 ok_long(rect
.bottom
, 1);
307 hbmp
= CreateCompatibleBitmap(hdc
, 4, 7);
308 SelectObject(hdc
, hbmp
);
309 ret
= GetRandomRgn(hdc
, hrgn1
, SYSRGN
);
311 GetRgnBox(hrgn1
, &rect
);
312 ok_long(rect
.left
, 0);
313 ok_long(rect
.top
, 0);
314 ok_long(rect
.right
, 4);
315 ok_long(rect
.bottom
, 7);
318 #if 0 // this is vista+
319 MoveWindow(ghwnd
, 100, 100, 100, 100, 0);
320 ret
= GetRandomRgn(ghdcWindow
, hrgn1
, RGN5
);
322 GetRgnBox(hrgn1
, &rect
);
323 DPtoLP(ghdcWindow
, (LPPOINT
)&rect
, 2);
324 ok_long(rect
.left
, 104);
325 ok_long(rect
.top
, 124);
326 ok_long(rect
.right
, 209);
327 ok_long(rect
.bottom
, 196);
329 MoveWindow(ghwnd
, 200, 400, 200, 200, 0);
331 ret
= GetRandomRgn(ghdcWindow
, hrgn1
, RGN5
);
333 GetRgnBox(hrgn1
, &rect2
);
334 DPtoLP(ghdcWindow
, (LPPOINT
)&rect2
, 2);
335 ok_long(rect2
.left
, rect
.left
+ 100);
336 ok_long(rect2
.top
, rect
.top
+ 300);
337 ok_long(rect2
.right
, rect
.right
+ 200 - 13);
338 ok_long(rect2
.bottom
, rect
.bottom
+ 400);
345 START_TEST(GetRandomRgn
)
348 /* Create a window */
349 ghwnd
= CreateWindowW(L
"BUTTON", L
"TestWindow", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
350 100, 100, 100, 100, NULL
, NULL
, 0, 0);
351 ghdcWindow
= GetDC(ghwnd
);
354 printf("No window dc\n");
358 Test_GetRandomRgn_Params();
359 Test_GetRandomRgn_CLIPRGN();
360 Test_GetRandomRgn_METARGN();
361 Test_GetRandomRgn_APIRGN();
362 Test_GetRandomRgn_SYSRGN();
363 Test_GetRandomRgn_RGN5();