[GDI32_APITEST] Remove broken EngDeleteSemaphore.c (#655)
[reactos.git] / modules / rostests / apitests / gdi32 / GetRandomRgn.c
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 */
7
8 #include "precomp.h"
9
10 #define METARGN 2
11 #define APIRGN 3
12 #define SYSRGN 4
13 #define RGN5 5
14
15 HWND ghwnd;
16 HDC ghdcWindow;
17
18 void Test_GetRandomRgn_Params()
19 {
20 HDC hdc;
21 HRGN hrgn;
22 INT ret;
23
24 hdc = CreateCompatibleDC(0);
25 if (!hdc)
26 {
27 printf("Coun't create a dc\n");
28 return;
29 }
30
31 hrgn = CreateRectRgn(11, 17, 23, 42);
32 if (!hrgn)
33 {
34 printf("Coun't create a region\n");
35 return;
36 }
37
38 SetLastError(0xbadbad00);
39 ret = GetRandomRgn(NULL, NULL, 0);
40 ok_int(ret, -1);
41 ok((GetLastError() == 0xbadbad00) || (GetLastError() == ERROR_INVALID_HANDLE), "wrong error: %ld\n", GetLastError());
42
43 SetLastError(0xbadbad00);
44 ret = GetRandomRgn(NULL, NULL, CLIPRGN);
45 ok_int(ret, -1);
46 ok((GetLastError() == 0xbadbad00) || (GetLastError() == ERROR_INVALID_HANDLE), "wrong error: %ld\n", GetLastError());
47
48 SetLastError(0xbadbad00);
49 ret = GetRandomRgn(NULL, hrgn, 0);
50 ok_int(ret, -1);
51 ok((GetLastError() == 0xbadbad00) || (GetLastError() == ERROR_INVALID_HANDLE), "wrong error: %ld\n", GetLastError());
52
53 SetLastError(0xbadbad00);
54 ret = GetRandomRgn(NULL, hrgn, CLIPRGN);
55 ok_int(ret, -1);
56 ok((GetLastError() == 0xbadbad00) || (GetLastError() == ERROR_INVALID_HANDLE), "wrong error: %ld\n", GetLastError());
57
58 SetLastError(0xbadbad00);
59 ret = GetRandomRgn(hdc, NULL, 0);
60 ok_int(ret, 0);
61 ok_long(GetLastError(), 0xbadbad00);
62
63 SetLastError(0xbadbad00);
64 ret = GetRandomRgn(hdc, NULL, CLIPRGN);
65 ok_int(ret, 0);
66 ok_long(GetLastError(), 0xbadbad00);
67
68 SetLastError(0xbadbad00);
69 ret = GetRandomRgn(hdc, hrgn, 0);
70 ok_int(ret, 0);
71 ok_long(GetLastError(), 0xbadbad00);
72 #if 0 // this is vista+
73 SetLastError(0xbadbad00);
74 ret = GetRandomRgn(hdc, hrgn, 5);
75 ok_int(ret, 1);
76 ok_long(GetLastError(), 0xbadbad00);
77 #endif
78 SetLastError(0xbadbad00);
79 ret = GetRandomRgn(hdc, hrgn, 6);
80 ok_int(ret, 0);
81 ok_long(GetLastError(), 0xbadbad00);
82
83 SetLastError(0xbadbad00);
84 ret = GetRandomRgn(hdc, hrgn, 27);
85 ok_int(ret, 0);
86 ok_long(GetLastError(), 0xbadbad00);
87
88 SetLastError(0xbadbad00);
89 ret = GetRandomRgn(hdc, hrgn, -1);
90 ok_int(ret, 0);
91 ok_long(GetLastError(), 0xbadbad00);
92
93 SetLastError(0xbadbad00);
94 ret = GetRandomRgn(hdc, hrgn, CLIPRGN);
95 ok_int(ret, 0);
96 ok_long(GetLastError(), 0xbadbad00);
97
98 SetLastError(0xbadbad00);
99 ret = GetRandomRgn((HDC)0x123, hrgn, CLIPRGN);
100 ok_int(ret, -1);
101 ok((GetLastError() == 0xbadbad00) || (GetLastError() == ERROR_INVALID_HANDLE), "wrong error: %ld\n", GetLastError());
102
103 DeleteObject(hrgn);
104 DeleteDC(hdc);
105 }
106
107 void Test_GetRandomRgn_CLIPRGN()
108 {
109 HDC hdc;
110 HRGN hrgn1, hrgn2;
111 INT ret;
112 RECT rect;
113
114 hrgn1 = CreateRectRgn(11, 17, 23, 42);
115 if (!hrgn1)
116 {
117 printf("Coun't create a region\n");
118 return;
119 }
120
121 hdc = CreateCompatibleDC(0);
122 if (!hdc)
123 {
124 printf("Coun't create a dc\n");
125 return;
126 }
127
128 ret = GetRandomRgn(hdc, hrgn1, CLIPRGN);
129 ok_int(ret, 0);
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);
135
136 hrgn2 = CreateRectRgn(1, 2, 3, 4);
137 SelectClipRgn(hdc, hrgn2);
138 DeleteObject(hrgn2);
139 ret = GetRandomRgn(hdc, hrgn1, CLIPRGN);
140 ok_int(ret, 1);
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);
146
147 hrgn2 = CreateRectRgn(2, 3, 4, 5);
148 SelectClipRgn(ghdcWindow, hrgn2);
149 DeleteObject(hrgn2);
150 ret = GetRandomRgn(ghdcWindow, hrgn1, CLIPRGN);
151 ok_int(ret, 1);
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);
157
158 MoveWindow(ghwnd, 200, 400, 100, 100, 0);
159
160 ret = GetRandomRgn(ghdcWindow, hrgn1, CLIPRGN);
161 ok_int(ret, 1);
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);
167
168
169 DeleteObject(hrgn1);
170 DeleteDC(hdc);
171 }
172
173 void Test_GetRandomRgn_METARGN()
174 {
175 }
176
177 void Test_GetRandomRgn_APIRGN()
178 {
179 }
180
181 void Test_GetRandomRgn_SYSRGN()
182 {
183 HDC hdc;
184 HRGN hrgn1, hrgn2;
185 INT ret;
186 RECT rect, rect2;
187 HBITMAP hbmp;
188
189 hrgn1 = CreateRectRgn(11, 17, 23, 42);
190 if (!hrgn1)
191 {
192 printf("Coun't create a region\n");
193 return;
194 }
195
196 hdc = CreateCompatibleDC(0);
197 if (!hdc)
198 {
199 printf("Coun't create a dc\n");
200 return;
201 }
202
203 ret = GetRandomRgn(hdc, hrgn1, SYSRGN);
204 ok_int(ret, 1);
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);
210
211 hrgn2 = CreateRectRgn(1, 2, 3, 4);
212 SelectClipRgn(hdc, hrgn2);
213 DeleteObject(hrgn2);
214 ret = GetRandomRgn(hdc, hrgn1, SYSRGN);
215 ok_int(ret, 1);
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);
221
222 hbmp = CreateCompatibleBitmap(hdc, 4, 7);
223 SelectObject(hdc, hbmp);
224 ret = GetRandomRgn(hdc, hrgn1, SYSRGN);
225 ok_int(ret, 1);
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);
231 DeleteObject(hbmp);
232
233 MoveWindow(ghwnd, 100, 100, 100, 100, 0);
234 ret = GetRandomRgn(ghdcWindow, hrgn1, SYSRGN);
235 ok_int(ret, 1);
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);
243 #endif
244
245 MoveWindow(ghwnd, 200, 400, 200, 200, 0);
246
247 ret = GetRandomRgn(ghdcWindow, hrgn1, SYSRGN);
248 ok_int(ret, 1);
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);
256 #endif
257
258 DeleteObject(hrgn1);
259 DeleteDC(hdc);
260
261 }
262
263 void Test_GetRandomRgn_RGN5()
264 {
265 HDC hdc;
266 HRGN hrgn1, hrgn2;
267 INT ret;
268 RECT rect, rect2;
269 HBITMAP hbmp;
270 DBG_UNREFERENCED_LOCAL_VARIABLE(hrgn2);
271 DBG_UNREFERENCED_LOCAL_VARIABLE(rect2);
272
273 hrgn1 = CreateRectRgn(11, 17, 23, 42);
274 if (!hrgn1)
275 {
276 printf("Coun't create a region\n");
277 return;
278 }
279
280 hdc = CreateCompatibleDC(0);
281 if (!hdc)
282 {
283 printf("Coun't create a dc\n");
284 return;
285 }
286 #if 0 // this is vista+
287 ret = GetRandomRgn(hdc, hrgn1, RGN5);
288 ok_int(ret, 1);
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);
294
295 hrgn2 = CreateRectRgn(1, 2, 3, 4);
296 SelectClipRgn(hdc, hrgn2);
297 DeleteObject(hrgn2);
298 ret = GetRandomRgn(hdc, hrgn1, RGN5);
299 ok_int(ret, 1);
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);
305 #endif
306
307 hbmp = CreateCompatibleBitmap(hdc, 4, 7);
308 SelectObject(hdc, hbmp);
309 ret = GetRandomRgn(hdc, hrgn1, SYSRGN);
310 ok_int(ret, 1);
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);
316 DeleteObject(hbmp);
317
318 #if 0 // this is vista+
319 MoveWindow(ghwnd, 100, 100, 100, 100, 0);
320 ret = GetRandomRgn(ghdcWindow, hrgn1, RGN5);
321 ok_int(ret, 1);
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);
328
329 MoveWindow(ghwnd, 200, 400, 200, 200, 0);
330
331 ret = GetRandomRgn(ghdcWindow, hrgn1, RGN5);
332 ok_int(ret, 1);
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);
339 #endif
340
341 DeleteObject(hrgn1);
342 DeleteDC(hdc);
343 }
344
345 START_TEST(GetRandomRgn)
346 {
347
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);
352 if (!ghdcWindow)
353 {
354 printf("No window dc\n");
355 return;
356 }
357
358 Test_GetRandomRgn_Params();
359 Test_GetRandomRgn_CLIPRGN();
360 Test_GetRandomRgn_METARGN();
361 Test_GetRandomRgn_APIRGN();
362 Test_GetRandomRgn_SYSRGN();
363 Test_GetRandomRgn_RGN5();
364
365 }
366