ReactOS  0.4.12-dev-919-gfc3b8d5
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  */
7 
8 #include "precomp.h"
9 
10 #define METARGN 2
11 #define APIRGN 3
12 #define SYSRGN 4
13 #define RGN5 5
14 
17 
19 {
20  HDC hdc;
21  HRGN hrgn;
22  INT ret;
23 
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);
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);
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);
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);
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 
104  DeleteDC(hdc);
105 }
106 
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);
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);
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 
174 {
175 }
176 
178 {
179 }
180 
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);
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 
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);
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);
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 
264 {
265  HDC hdc;
266  HRGN hrgn1, hrgn2;
267  INT ret;
268  RECT rect, rect2;
269  HBITMAP hbmp;
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);
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 
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);
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);
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 
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);
352  if (!ghdcWindow)
353  {
354  printf("No window dc\n");
355  return;
356  }
357 
364 
365 }
366 
RECT rect2
Definition: edittest.c:51
void Test_GetRandomRgn_SYSRGN()
Definition: GetRandomRgn.c:181
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
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:107
void Test_GetRandomRgn_METARGN()
Definition: GetRandomRgn.c:173
START_TEST(GetRandomRgn)
Definition: GetRandomRgn.c:345
HWND ghwnd
Definition: GetRandomRgn.c:15
smooth NULL
Definition: ftsmooth.c:416
void Test_GetRandomRgn_APIRGN()
Definition: GetRandomRgn.c:177
#define ok(value,...)
Definition: CComObject.cpp:34
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:16
void Test_GetRandomRgn_RGN5()
Definition: GetRandomRgn.c:263
#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:12
#define RGN5
Definition: GetRandomRgn.c:13
void Test_GetRandomRgn_Params()
Definition: GetRandomRgn.c:18
#define WS_VISIBLE
Definition: pedump.c:620
#define printf
Definition: config.h:203