2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for GetRandomRgn
5 * PROGRAMMERS: Timo Kreuzer
23 void Test_GetRandomRgn_Params()
29 hdc
= CreateCompatibleDC(0);
32 printf("Coun't create a dc\n");
36 hrgn
= CreateRectRgn(11, 17, 23, 42);
39 printf("Coun't create a region\n");
43 SetLastError(0xbadbad00);
44 ret
= GetRandomRgn(NULL
, NULL
, 0);
46 ok((GetLastError() == 0xbadbad00) || (GetLastError() == ERROR_INVALID_HANDLE
), "wrong error: %ld\n", GetLastError());
48 SetLastError(0xbadbad00);
49 ret
= GetRandomRgn(NULL
, NULL
, CLIPRGN
);
51 ok((GetLastError() == 0xbadbad00) || (GetLastError() == ERROR_INVALID_HANDLE
), "wrong error: %ld\n", GetLastError());
53 SetLastError(0xbadbad00);
54 ret
= GetRandomRgn(NULL
, hrgn
, 0);
56 ok((GetLastError() == 0xbadbad00) || (GetLastError() == ERROR_INVALID_HANDLE
), "wrong error: %ld\n", GetLastError());
58 SetLastError(0xbadbad00);
59 ret
= GetRandomRgn(NULL
, hrgn
, CLIPRGN
);
61 ok((GetLastError() == 0xbadbad00) || (GetLastError() == ERROR_INVALID_HANDLE
), "wrong error: %ld\n", GetLastError());
63 SetLastError(0xbadbad00);
64 ret
= GetRandomRgn(hdc
, NULL
, 0);
66 ok_long(GetLastError(), 0xbadbad00);
68 SetLastError(0xbadbad00);
69 ret
= GetRandomRgn(hdc
, NULL
, CLIPRGN
);
71 ok_long(GetLastError(), 0xbadbad00);
73 SetLastError(0xbadbad00);
74 ret
= GetRandomRgn(hdc
, hrgn
, 0);
76 ok_long(GetLastError(), 0xbadbad00);
77 #if 0 // this is vista+
78 SetLastError(0xbadbad00);
79 ret
= GetRandomRgn(hdc
, hrgn
, 5);
81 ok_long(GetLastError(), 0xbadbad00);
83 SetLastError(0xbadbad00);
84 ret
= GetRandomRgn(hdc
, hrgn
, 6);
86 ok_long(GetLastError(), 0xbadbad00);
88 SetLastError(0xbadbad00);
89 ret
= GetRandomRgn(hdc
, hrgn
, 27);
91 ok_long(GetLastError(), 0xbadbad00);
93 SetLastError(0xbadbad00);
94 ret
= GetRandomRgn(hdc
, hrgn
, -1);
96 ok_long(GetLastError(), 0xbadbad00);
98 SetLastError(0xbadbad00);
99 ret
= GetRandomRgn(hdc
, hrgn
, CLIPRGN
);
101 ok_long(GetLastError(), 0xbadbad00);
103 SetLastError(0xbadbad00);
104 ret
= GetRandomRgn((HDC
)0x123, hrgn
, CLIPRGN
);
106 ok((GetLastError() == 0xbadbad00) || (GetLastError() == ERROR_INVALID_HANDLE
), "wrong error: %ld\n", GetLastError());
112 void Test_GetRandomRgn_CLIPRGN()
119 hrgn1
= CreateRectRgn(11, 17, 23, 42);
122 printf("Coun't create a region\n");
126 hdc
= CreateCompatibleDC(0);
129 printf("Coun't create a dc\n");
133 ret
= GetRandomRgn(hdc
, hrgn1
, CLIPRGN
);
135 GetRgnBox(hrgn1
, &rect
);
136 ok_long(rect
.left
, 11);
137 ok_long(rect
.top
, 17);
138 ok_long(rect
.right
, 23);
139 ok_long(rect
.bottom
, 42);
141 hrgn2
= CreateRectRgn(1, 2, 3, 4);
142 SelectClipRgn(hdc
, hrgn2
);
144 ret
= GetRandomRgn(hdc
, hrgn1
, CLIPRGN
);
146 GetRgnBox(hrgn1
, &rect
);
147 ok_long(rect
.left
, 1);
148 ok_long(rect
.top
, 2);
149 ok_long(rect
.right
, 3);
150 ok_long(rect
.bottom
, 4);
152 hrgn2
= CreateRectRgn(2, 3, 4, 5);
153 SelectClipRgn(ghdcWindow
, hrgn2
);
155 ret
= GetRandomRgn(ghdcWindow
, hrgn1
, CLIPRGN
);
157 GetRgnBox(hrgn1
, &rect
);
158 ok_long(rect
.left
, 2);
159 ok_long(rect
.top
, 3);
160 ok_long(rect
.right
, 4);
161 ok_long(rect
.bottom
, 5);
163 MoveWindow(ghwnd
, 200, 400, 100, 100, 0);
165 ret
= GetRandomRgn(ghdcWindow
, hrgn1
, CLIPRGN
);
167 GetRgnBox(hrgn1
, &rect
);
168 ok_long(rect
.left
, 2);
169 ok_long(rect
.top
, 3);
170 ok_long(rect
.right
, 4);
171 ok_long(rect
.bottom
, 5);
178 void Test_GetRandomRgn_METARGN()
182 void Test_GetRandomRgn_APIRGN()
186 void Test_GetRandomRgn_SYSRGN()
194 hrgn1
= CreateRectRgn(11, 17, 23, 42);
197 printf("Coun't create a region\n");
201 hdc
= CreateCompatibleDC(0);
204 printf("Coun't create a dc\n");
208 ret
= GetRandomRgn(hdc
, hrgn1
, SYSRGN
);
210 GetRgnBox(hrgn1
, &rect
);
211 ok_long(rect
.left
, 0);
212 ok_long(rect
.top
, 0);
213 ok_long(rect
.right
, 1);
214 ok_long(rect
.bottom
, 1);
216 hrgn2
= CreateRectRgn(1, 2, 3, 4);
217 SelectClipRgn(hdc
, hrgn2
);
219 ret
= GetRandomRgn(hdc
, hrgn1
, SYSRGN
);
221 GetRgnBox(hrgn1
, &rect
);
222 ok_long(rect
.left
, 0);
223 ok_long(rect
.top
, 0);
224 ok_long(rect
.right
, 1);
225 ok_long(rect
.bottom
, 1);
227 hbmp
= CreateCompatibleBitmap(hdc
, 4, 7);
228 SelectObject(hdc
, hbmp
);
229 ret
= GetRandomRgn(hdc
, hrgn1
, SYSRGN
);
231 GetRgnBox(hrgn1
, &rect
);
232 ok_long(rect
.left
, 0);
233 ok_long(rect
.top
, 0);
234 ok_long(rect
.right
, 4);
235 ok_long(rect
.bottom
, 7);
238 MoveWindow(ghwnd
, 100, 100, 100, 100, 0);
239 ret
= GetRandomRgn(ghdcWindow
, hrgn1
, SYSRGN
);
241 GetRgnBox(hrgn1
, &rect
);
242 DPtoLP(ghdcWindow
, (LPPOINT
)&rect
, 2);
243 #if 0 // FIXME: this needs calculation
244 ok_long(rect
.left
, 104);
245 ok_long(rect
.top
, 124);
246 ok_long(rect
.right
, 209);
247 ok_long(rect
.bottom
, 196);
250 MoveWindow(ghwnd
, 200, 400, 200, 200, 0);
252 ret
= GetRandomRgn(ghdcWindow
, hrgn1
, SYSRGN
);
254 GetRgnBox(hrgn1
, &rect2
);
255 DPtoLP(ghdcWindow
, (LPPOINT
)&rect2
, 2);
256 #if 0 // FIXME: this needs calculation
257 ok_long(rect2
.left
, rect
.left
+ 100);
258 ok_long(rect2
.top
, rect
.top
+ 300);
259 ok_long(rect2
.right
, rect
.right
+ 200 - 13);
260 ok_long(rect2
.bottom
, rect
.bottom
+ 400);
268 void Test_GetRandomRgn_RGN5()
275 DBG_UNREFERENCED_LOCAL_VARIABLE(hrgn2
);
276 DBG_UNREFERENCED_LOCAL_VARIABLE(rect2
);
278 hrgn1
= CreateRectRgn(11, 17, 23, 42);
281 printf("Coun't create a region\n");
285 hdc
= CreateCompatibleDC(0);
288 printf("Coun't create a dc\n");
291 #if 0 // this is vista+
292 ret
= GetRandomRgn(hdc
, hrgn1
, RGN5
);
294 GetRgnBox(hrgn1
, &rect
);
295 ok_long(rect
.left
, 0);
296 ok_long(rect
.top
, 0);
297 ok_long(rect
.right
, 1);
298 ok_long(rect
.bottom
, 1);
300 hrgn2
= CreateRectRgn(1, 2, 3, 4);
301 SelectClipRgn(hdc
, hrgn2
);
303 ret
= GetRandomRgn(hdc
, hrgn1
, RGN5
);
305 GetRgnBox(hrgn1
, &rect
);
306 ok_long(rect
.left
, 0);
307 ok_long(rect
.top
, 0);
308 ok_long(rect
.right
, 1);
309 ok_long(rect
.bottom
, 1);
312 hbmp
= CreateCompatibleBitmap(hdc
, 4, 7);
313 SelectObject(hdc
, hbmp
);
314 ret
= GetRandomRgn(hdc
, hrgn1
, SYSRGN
);
316 GetRgnBox(hrgn1
, &rect
);
317 ok_long(rect
.left
, 0);
318 ok_long(rect
.top
, 0);
319 ok_long(rect
.right
, 4);
320 ok_long(rect
.bottom
, 7);
323 #if 0 // this is vista+
324 MoveWindow(ghwnd
, 100, 100, 100, 100, 0);
325 ret
= GetRandomRgn(ghdcWindow
, hrgn1
, RGN5
);
327 GetRgnBox(hrgn1
, &rect
);
328 DPtoLP(ghdcWindow
, (LPPOINT
)&rect
, 2);
329 ok_long(rect
.left
, 104);
330 ok_long(rect
.top
, 124);
331 ok_long(rect
.right
, 209);
332 ok_long(rect
.bottom
, 196);
334 MoveWindow(ghwnd
, 200, 400, 200, 200, 0);
336 ret
= GetRandomRgn(ghdcWindow
, hrgn1
, RGN5
);
338 GetRgnBox(hrgn1
, &rect2
);
339 DPtoLP(ghdcWindow
, (LPPOINT
)&rect2
, 2);
340 ok_long(rect2
.left
, rect
.left
+ 100);
341 ok_long(rect2
.top
, rect
.top
+ 300);
342 ok_long(rect2
.right
, rect
.right
+ 200 - 13);
343 ok_long(rect2
.bottom
, rect
.bottom
+ 400);
350 START_TEST(GetRandomRgn
)
353 /* Create a window */
354 ghwnd
= CreateWindowW(L
"BUTTON", L
"TestWindow", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
355 100, 100, 100, 100, NULL
, NULL
, 0, 0);
356 ghdcWindow
= GetDC(ghwnd
);
359 printf("No window dc\n");
363 Test_GetRandomRgn_Params();
364 Test_GetRandomRgn_CLIPRGN();
365 Test_GetRandomRgn_METARGN();
366 Test_GetRandomRgn_APIRGN();
367 Test_GetRandomRgn_SYSRGN();
368 Test_GetRandomRgn_RGN5();