e2f4d74e5cca94ccfda85208e5ee0f59e3706f8a
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);
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 ok_long(rect
.left
, 104);
244 ok_long(rect
.top
, 124);
245 ok_long(rect
.right
, 209);
246 ok_long(rect
.bottom
, 196);
248 MoveWindow(ghwnd
, 200, 400, 200, 200, 0);
250 ret
= GetRandomRgn(ghdcWindow
, hrgn1
, SYSRGN
);
252 GetRgnBox(hrgn1
, &rect2
);
253 DPtoLP(ghdcWindow
, (LPPOINT
)&rect2
, 2);
254 ok_long(rect2
.left
, rect
.left
+ 100);
255 ok_long(rect2
.top
, rect
.top
+ 300);
256 ok_long(rect2
.right
, rect
.right
+ 200 - 13);
257 ok_long(rect2
.bottom
, rect
.bottom
+ 400);
265 void Test_GetRandomRgn_RGN5()
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");
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);
306 hbmp
= CreateCompatibleBitmap(hdc
, 4, 7);
307 SelectObject(hdc
, hbmp
);
308 ret
= GetRandomRgn(hdc
, hrgn1
, SYSRGN
);
310 GetRgnBox(hrgn1
, &rect
);
311 ok_long(rect
.left
, 0);
312 ok_long(rect
.top
, 0);
313 ok_long(rect
.right
, 4);
314 ok_long(rect
.bottom
, 7);
317 MoveWindow(ghwnd
, 100, 100, 100, 100, 0);
318 ret
= GetRandomRgn(ghdcWindow
, hrgn1
, RGN5
);
320 GetRgnBox(hrgn1
, &rect
);
321 DPtoLP(ghdcWindow
, (LPPOINT
)&rect
, 2);
322 ok_long(rect
.left
, 104);
323 ok_long(rect
.top
, 124);
324 ok_long(rect
.right
, 209);
325 ok_long(rect
.bottom
, 196);
327 MoveWindow(ghwnd
, 200, 400, 200, 200, 0);
329 ret
= GetRandomRgn(ghdcWindow
, hrgn1
, RGN5
);
331 GetRgnBox(hrgn1
, &rect2
);
332 DPtoLP(ghdcWindow
, (LPPOINT
)&rect2
, 2);
333 ok_long(rect2
.left
, rect
.left
+ 100);
334 ok_long(rect2
.top
, rect
.top
+ 300);
335 ok_long(rect2
.right
, rect
.right
+ 200 - 13);
336 ok_long(rect2
.bottom
, rect
.bottom
+ 400);
343 START_TEST(GetRandomRgn
)
346 /* Create a window */
347 ghwnd
= CreateWindowW(L
"BUTTON", L
"TestWindow", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
348 100, 100, 100, 100, NULL
, NULL
, 0, 0);
349 ghdcWindow
= GetDC(ghwnd
);
352 printf("No window dc\n");
356 Test_GetRandomRgn_Params();
357 Test_GetRandomRgn_CLIPRGN();
358 Test_GetRandomRgn_METARGN();
359 Test_GetRandomRgn_APIRGN();
360 Test_GetRandomRgn_SYSRGN();
361 Test_GetRandomRgn_RGN5();