1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for GetRandomRgn
5 * PROGRAMMERS: Timo Kreuzer
6 * Katayama Hirofumi MZ
7 */
8
9 #include "precomp.h"
10
11 #define METARGN 2
12 #define APIRGN 3
13 #define SYSRGN 4
14 #define RGN5 5
15
16 HWND ghwnd;
17 HDC ghdcWindow;
18
Test_GetRandomRgn_Params()19 void Test_GetRandomRgn_Params()
20 {
21 HDC hdc;
22 HRGN hrgn;
23 INT ret;
24
25 hdc = CreateCompatibleDC(0);
26 if (!hdc)
27 {
28 printf("Coun't create a dc\n");
29 return;
30 }
31
32 hrgn = CreateRectRgn(11, 17, 23, 42);
33 if (!hrgn)
34 {
35 printf("Coun't create a region\n");
36 return;
37 }
38
39 SetLastError(0xbadbad00);
40 ret = GetRandomRgn(NULL, NULL, 0);
41 ok_int(ret, -1);
42 ok((GetLastError() == 0xbadbad00) || (GetLastError() == ERROR_INVALID_HANDLE), "wrong error: %ld\n", GetLastError());
43
44 SetLastError(0xbadbad00);
45 ret = GetRandomRgn(NULL, NULL, CLIPRGN);
46 ok_int(ret, -1);
47 ok((GetLastError() == 0xbadbad00) || (GetLastError() == ERROR_INVALID_HANDLE), "wrong error: %ld\n", GetLastError());
48
49 SetLastError(0xbadbad00);
50 ret = GetRandomRgn(NULL, hrgn, 0);
51 ok_int(ret, -1);
52 ok((GetLastError() == 0xbadbad00) || (GetLastError() == ERROR_INVALID_HANDLE), "wrong error: %ld\n", GetLastError());
53
54 SetLastError(0xbadbad00);
55 ret = GetRandomRgn(NULL, hrgn, CLIPRGN);
56 ok_int(ret, -1);
57 ok((GetLastError() == 0xbadbad00) || (GetLastError() == ERROR_INVALID_HANDLE), "wrong error: %ld\n", GetLastError());
58
59 SetLastError(0xbadbad00);
60 ret = GetRandomRgn(hdc, NULL, 0);
61 ok_int(ret, 0);
62 ok_err(0xbadbad00);
63
64 SetLastError(0xbadbad00);
65 ret = GetRandomRgn(hdc, NULL, CLIPRGN);
66 ok_int(ret, 0);
67 ok_err(0xbadbad00);
68
69 SetLastError(0xbadbad00);
70 ret = GetRandomRgn(hdc, hrgn, 0);
71 ok_int(ret, 0);
72 ok_err(0xbadbad00);
73 #if 0 // this is vista+
74 SetLastError(0xbadbad00);
75 ret = GetRandomRgn(hdc, hrgn, 5);
76 ok_int(ret, 1);
77 ok_err(0xbadbad00);
78 #endif
79 SetLastError(0xbadbad00);
80 ret = GetRandomRgn(hdc, hrgn, 6);
81 ok_int(ret, 0);
82 ok_err(0xbadbad00);
83
84 SetLastError(0xbadbad00);
85 ret = GetRandomRgn(hdc, hrgn, 27);
86 ok_int(ret, 0);
87 ok_err(0xbadbad00);
88
89 SetLastError(0xbadbad00);
90 ret = GetRandomRgn(hdc, hrgn, -1);
91 ok_int(ret, 0);
92 ok_err(0xbadbad00);
93
94 SetLastError(0xbadbad00);
95 ret = GetRandomRgn(hdc, hrgn, CLIPRGN);
96 ok_int(ret, 0);
97 ok_err(0xbadbad00);
98
99 SetLastError(0xbadbad00);
100 ret = GetRandomRgn((HDC)0x123, hrgn, CLIPRGN);
101 ok_int(ret, -1);
102 ok((GetLastError() == 0xbadbad00) || (GetLastError() == ERROR_INVALID_HANDLE), "wrong error: %ld\n", GetLastError());
103
104 DeleteObject(hrgn);
105 DeleteDC(hdc);
106 }
107
Test_GetRandomRgn_CLIPRGN()108 void Test_GetRandomRgn_CLIPRGN()
109 {
110 HDC hdc;
111 HRGN hrgn1, hrgn2;
112 INT ret;
113 RECT rect;
114
115 hrgn1 = CreateRectRgn(11, 17, 23, 42);
116 if (!hrgn1)
117 {
118 printf("Coun't create a region\n");
119 return;
120 }
121
122 hdc = CreateCompatibleDC(0);
123 if (!hdc)
124 {
125 printf("Coun't create a dc\n");
126 return;
127 }
128
129 ret = GetRandomRgn(hdc, hrgn1, CLIPRGN);
130 ok_int(ret, 0);
131 GetRgnBox(hrgn1, &rect);
132 ok_long(rect.left, 11);
133 ok_long(rect.top, 17);
134 ok_long(rect.right, 23);
135 ok_long(rect.bottom, 42);
136
137 hrgn2 = CreateRectRgn(1, 2, 3, 4);
138 SelectClipRgn(hdc, hrgn2);
139 DeleteObject(hrgn2);
140 ret = GetRandomRgn(hdc, hrgn1, CLIPRGN);
141 ok_int(ret, 1);
142 GetRgnBox(hrgn1, &rect);
143 ok_long(rect.left, 1);
144 ok_long(rect.top, 2);
145 ok_long(rect.right, 3);
146 ok_long(rect.bottom, 4);
147
148 hrgn2 = CreateRectRgn(2, 3, 4, 5);
149 SelectClipRgn(ghdcWindow, hrgn2);
150 DeleteObject(hrgn2);
151 ret = GetRandomRgn(ghdcWindow, hrgn1, CLIPRGN);
152 ok_int(ret, 1);
153 GetRgnBox(hrgn1, &rect);
154 ok_long(rect.left, 2);
155 ok_long(rect.top, 3);
156 ok_long(rect.right, 4);
157 ok_long(rect.bottom, 5);
158
159 MoveWindow(ghwnd, 200, 400, 100, 100, 0);
160
161 ret = GetRandomRgn(ghdcWindow, hrgn1, CLIPRGN);
162 ok_int(ret, 1);
163 GetRgnBox(hrgn1, &rect);
164 ok_long(rect.left, 2);
165 ok_long(rect.top, 3);
166 ok_long(rect.right, 4);
167 ok_long(rect.bottom, 5);
168
169
170 DeleteObject(hrgn1);
171 DeleteDC(hdc);
172 }
173
Test_GetRandomRgn_METARGN()174 void Test_GetRandomRgn_METARGN()
175 {
176 }
177
Test_GetRandomRgn_APIRGN()178 void Test_GetRandomRgn_APIRGN()
179 {
180 }
181
Test_GetRandomRgn_SYSRGN()182 void Test_GetRandomRgn_SYSRGN()
183 {
184 HDC hdc;
185 HRGN hrgn1, hrgn2;
186 INT ret;
187 RECT rect, rect2;
188 HBITMAP hbmp;
189
190 hrgn1 = CreateRectRgn(11, 17, 23, 42);
191 if (!hrgn1)
192 {
193 printf("Coun't create a region\n");
194 return;
195 }
196
197 hdc = CreateCompatibleDC(0);
198 if (!hdc)
199 {
200 printf("Coun't create a dc\n");
201 return;
202 }
203
204 ret = GetRandomRgn(hdc, hrgn1, SYSRGN);
205 ok_int(ret, 1);
206 GetRgnBox(hrgn1, &rect);
207 ok_long(rect.left, 0);
208 ok_long(rect.top, 0);
209 ok_long(rect.right, 1);
210 ok_long(rect.bottom, 1);
211
212 hrgn2 = CreateRectRgn(1, 2, 3, 4);
213 SelectClipRgn(hdc, hrgn2);
214 DeleteObject(hrgn2);
215 ret = GetRandomRgn(hdc, hrgn1, SYSRGN);
216 ok_int(ret, 1);
217 GetRgnBox(hrgn1, &rect);
218 ok_long(rect.left, 0);
219 ok_long(rect.top, 0);
220 ok_long(rect.right, 1);
221 ok_long(rect.bottom, 1);
222
223 hbmp = CreateCompatibleBitmap(hdc, 4, 7);
224 SelectObject(hdc, hbmp);
225 ret = GetRandomRgn(hdc, hrgn1, SYSRGN);
226 ok_int(ret, 1);
227 GetRgnBox(hrgn1, &rect);
228 ok_long(rect.left, 0);
229 ok_long(rect.top, 0);
230 ok_long(rect.right, 4);
231 ok_long(rect.bottom, 7);
232 DeleteObject(hbmp);
233
234 MoveWindow(ghwnd, 100, 100, 100, 100, 0);
235 ret = GetRandomRgn(ghdcWindow, hrgn1, SYSRGN);
236 ok_int(ret, 1);
237 GetRgnBox(hrgn1, &rect);
238 DPtoLP(ghdcWindow, (LPPOINT)&rect, 2);
239 #if 0 // FIXME: this needs calculation
240 ok_long(rect.left, 104);
241 ok_long(rect.top, 124);
242 ok_long(rect.right, 209);
243 ok_long(rect.bottom, 196);
244 #endif
245
246 MoveWindow(ghwnd, 200, 400, 200, 200, 0);
247
248 ret = GetRandomRgn(ghdcWindow, hrgn1, SYSRGN);
249 ok_int(ret, 1);
250 GetRgnBox(hrgn1, &rect2);
251 DPtoLP(ghdcWindow, (LPPOINT)&rect2, 2);
252 #if 0 // FIXME: this needs calculation
253 ok_long(rect2.left, rect.left + 100);
254 ok_long(rect2.top, rect.top + 300);
255 ok_long(rect2.right, rect.right + 200 - 13);
256 ok_long(rect2.bottom, rect.bottom + 400);
257 #endif
258
259 DeleteObject(hrgn1);
260 DeleteDC(hdc);
261
262 }
263
Test_GetRandomRgn_RGN5()264 void Test_GetRandomRgn_RGN5()
265 {
266 HDC hdc;
267 HRGN hrgn1, hrgn2;
268 INT ret;
269 RECT rect, rect2;
270 HBITMAP hbmp;
271 DBG_UNREFERENCED_LOCAL_VARIABLE(hrgn2);
272 DBG_UNREFERENCED_LOCAL_VARIABLE(rect2);
273
274 hrgn1 = CreateRectRgn(11, 17, 23, 42);
275 if (!hrgn1)
276 {
277 printf("Coun't create a region\n");
278 return;
279 }
280
281 hdc = CreateCompatibleDC(0);
282 if (!hdc)
283 {
284 printf("Coun't create a dc\n");
285 return;
286 }
287 #if 0 // this is vista+
288 ret = GetRandomRgn(hdc, hrgn1, RGN5);
289 ok_int(ret, 1);
290 GetRgnBox(hrgn1, &rect);
291 ok_long(rect.left, 0);
292 ok_long(rect.top, 0);
293 ok_long(rect.right, 1);
294 ok_long(rect.bottom, 1);
295
296 hrgn2 = CreateRectRgn(1, 2, 3, 4);
297 SelectClipRgn(hdc, hrgn2);
298 DeleteObject(hrgn2);
299 ret = GetRandomRgn(hdc, hrgn1, RGN5);
300 ok_int(ret, 1);
301 GetRgnBox(hrgn1, &rect);
302 ok_long(rect.left, 0);
303 ok_long(rect.top, 0);
304 ok_long(rect.right, 1);
305 ok_long(rect.bottom, 1);
306 #endif
307
308 hbmp = CreateCompatibleBitmap(hdc, 4, 7);
309 SelectObject(hdc, hbmp);
310 ret = GetRandomRgn(hdc, hrgn1, SYSRGN);
311 ok_int(ret, 1);
312 GetRgnBox(hrgn1, &rect);
313 ok_long(rect.left, 0);
314 ok_long(rect.top, 0);
315 ok_long(rect.right, 4);
316 ok_long(rect.bottom, 7);
317 DeleteObject(hbmp);
318
319 #if 0 // this is vista+
320 MoveWindow(ghwnd, 100, 100, 100, 100, 0);
321 ret = GetRandomRgn(ghdcWindow, hrgn1, RGN5);
322 ok_int(ret, 1);
323 GetRgnBox(hrgn1, &rect);
324 DPtoLP(ghdcWindow, (LPPOINT)&rect, 2);
325 ok_long(rect.left, 104);
326 ok_long(rect.top, 124);
327 ok_long(rect.right, 209);
328 ok_long(rect.bottom, 196);
329
330 MoveWindow(ghwnd, 200, 400, 200, 200, 0);
331
332 ret = GetRandomRgn(ghdcWindow, hrgn1, RGN5);
333 ok_int(ret, 1);
334 GetRgnBox(hrgn1, &rect2);
335 DPtoLP(ghdcWindow, (LPPOINT)&rect2, 2);
336 ok_long(rect2.left, rect.left + 100);
337 ok_long(rect2.top, rect.top + 300);
338 ok_long(rect2.right, rect.right + 200 - 13);
339 ok_long(rect2.bottom, rect.bottom + 400);
340 #endif
341
342 DeleteObject(hrgn1);
343 DeleteDC(hdc);
344 }
345
START_TEST(GetRandomRgn)346 START_TEST(GetRandomRgn)
347 {
348
349 /* Create a window */
350 ghwnd = CreateWindowW(L"BUTTON", L"TestWindow", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
351 100, 100, 100, 100, NULL, NULL, 0, 0);
352 ghdcWindow = GetDC(ghwnd);
353 if (!ghdcWindow)
354 {
355 printf("No window dc\n");
356 return;
357 }
358
359 Test_GetRandomRgn_Params();
360 Test_GetRandomRgn_CLIPRGN();
361 Test_GetRandomRgn_METARGN();
362 Test_GetRandomRgn_APIRGN();
363 Test_GetRandomRgn_SYSRGN();
364 Test_GetRandomRgn_RGN5();
365
366 }
367
368