ReactOS  0.4.13-dev-257-gfabbd7c
GetRandomRgn.c
Go to the documentation of this file.
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 
18 
20 {
21  HDC hdc;
22  HRGN hrgn;
23  INT ret;
24 
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);
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);
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);
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);
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 
105  DeleteDC(hdc);
106 }
107 
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);
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);
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 
175 {
176 }
177 
179 {
180 }
181 
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);
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 
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);
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);
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 
265 {
266  HDC hdc;
267  HRGN hrgn1, hrgn2;
268  INT ret;
269  RECT rect, rect2;
270  HBITMAP hbmp;
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);
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 
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);
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);
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 
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);
353  if (!ghdcWindow)
354  {
355  printf("No window dc\n");
356  return;
357  }
358 
365 
366 }
367 
RECT rect2
Definition: edittest.c:51
void Test_GetRandomRgn_SYSRGN()
Definition: GetRandomRgn.c:182
int WINAPI SelectClipRgn(_In_ HDC, _In_opt_ HRGN)
HDC WINAPI GetDC(_In_opt_ HWND)
HBITMAP WINAPI CreateCompatibleBitmap(_In_ HDC hdc, _In_ INT cx, _In_ INT cy)
#define ok_int(x, y)
Definition: sprintf.c:21
static HRGN hrgn2
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
static HDC
Definition: imagelist.c:92
LONG top
Definition: windef.h:292
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
LONG left
Definition: windef.h:291
#define ok_err(error)
Definition: FindFiles.c:39
LONG right
Definition: windef.h:293
BOOL WINAPI DPtoLP(_In_ HDC hdc, _Inout_updates_(c) LPPOINT lppt, _In_ int c)
#define CreateWindowW(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4185
int32_t INT
Definition: typedefs.h:56
& rect
Definition: startmenu.cpp:1413
void Test_GetRandomRgn_CLIPRGN()
Definition: GetRandomRgn.c:108
void Test_GetRandomRgn_METARGN()
Definition: GetRandomRgn.c:174
#define ok(value,...)
START_TEST(GetRandomRgn)
Definition: GetRandomRgn.c:346
HWND ghwnd
Definition: GetRandomRgn.c:16
smooth NULL
Definition: ftsmooth.c:416
void Test_GetRandomRgn_APIRGN()
Definition: GetRandomRgn.c:178
HRGN WINAPI CreateRectRgn(_In_ int, _In_ int, _In_ int, _In_ int)
HBITMAP hbmp
#define DBG_UNREFERENCED_LOCAL_VARIABLE(L)
Definition: ntbasedef.h:326
#define CLIPRGN
Definition: precomp.h:18
#define SetLastError(x)
Definition: compat.h:409
int ret
static const WCHAR L[]
Definition: oid.c:1250
HDC hdc
Definition: main.c:9
static HRGN hrgn
Definition: win.c:55
BOOL WINAPI MoveWindow(_In_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ BOOL)
int WINAPI GetRgnBox(_In_ HRGN, _Out_ LPRECT)
BOOL WINAPI DeleteDC(_In_ HDC)
HDC ghdcWindow
Definition: GetRandomRgn.c:17
void Test_GetRandomRgn_RGN5()
Definition: GetRandomRgn.c:264
#define ok_long(expression, result)
Definition: test.h:798
int WINAPI GetRandomRgn(_In_ HDC, _In_ HRGN, _In_ INT)
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
LONG bottom
Definition: windef.h:294
static HBITMAP
Definition: button.c:44
#define SYSRGN
Definition: GetRandomRgn.c:13
#define RGN5
Definition: GetRandomRgn.c:14
void Test_GetRandomRgn_Params()
Definition: GetRandomRgn.c:19
#define WS_VISIBLE
Definition: pedump.c:620
#define printf
Definition: config.h:203