FreeRDP
TestGdiRegion.c
1 
2 #include <freerdp/gdi/gdi.h>
3 
4 #include <freerdp/gdi/dc.h>
5 #include <freerdp/gdi/pen.h>
6 #include <freerdp/gdi/region.h>
7 #include <freerdp/gdi/bitmap.h>
8 
9 #include <winpr/crt.h>
10 #include <winpr/print.h>
11 
12 #include "helpers.h"
13 
14 int TestGdiRegion(int argc, char* argv[])
15 {
16  int rc = -1;
17  INT32 x = 0;
18  INT32 y = 0;
19  INT32 w = 0;
20  INT32 h = 0;
21  INT32 l = 0;
22  INT32 r = 0;
23  INT32 t = 0;
24  INT32 b = 0;
25  HGDI_RGN rgn1 = NULL;
26  HGDI_RGN rgn2 = NULL;
27  HGDI_RECT rect1 = NULL;
28  HGDI_RECT rect2 = NULL;
29 
30  WINPR_UNUSED(argc);
31  WINPR_UNUSED(argv);
32 
33  rgn1 = gdi_CreateRectRgn(111, 2, 65, 77);
34  rect1 = gdi_CreateRect(2311, 11, 42, 17);
35  if (rgn1 || rect1)
36  goto fail;
37  rgn1 = gdi_CreateRectRgn(1, 2, 65, 77);
38  rgn2 = gdi_CreateRectRgn(11, 2, 65, 77);
39  rect1 = gdi_CreateRect(23, 11, 42, 17);
40  rect2 = gdi_CreateRect(23, 11, 42, 17);
41  if (!rgn1 || !rgn2 || !rect1 || !rect2)
42  goto fail;
43 
44  if (!gdi_RectToRgn(rect1, rgn1))
45  goto fail;
46  if (rgn1->x != rect1->left)
47  goto fail;
48  if (rgn1->y != rect1->top)
49  goto fail;
50  if (rgn1->w != (rect1->right - rect1->left + 1))
51  goto fail;
52  if (rgn1->h != (rect1->bottom - rect1->top + 1))
53  goto fail;
54 
55  if (gdi_CRectToRgn(1123, 111, 333, 444, rgn2))
56  goto fail;
57  if (gdi_CRectToRgn(123, 1111, 333, 444, rgn2))
58  goto fail;
59  if (!gdi_CRectToRgn(123, 111, 333, 444, rgn2))
60  goto fail;
61  if (rgn2->x != 123)
62  goto fail;
63  if (rgn2->y != 111)
64  goto fail;
65  if (rgn2->w != (333 - 123 + 1))
66  goto fail;
67  if (rgn2->h != (444 - 111 + 1))
68  goto fail;
69 
70  if (!gdi_RectToCRgn(rect1, &x, &y, &w, &h))
71  goto fail;
72  if (rect1->left != x)
73  goto fail;
74  if (rect1->top != y)
75  goto fail;
76  if (rect1->right != (x + w - 1))
77  goto fail;
78  if (rect1->bottom != (y + h - 1))
79  goto fail;
80 
81  w = 23;
82  h = 42;
83  if (gdi_CRectToCRgn(1, 2, 0, 4, &x, &y, &w, &h))
84  goto fail;
85  if ((w != 0) || (h != 0))
86  goto fail;
87  w = 23;
88  h = 42;
89  if (gdi_CRectToCRgn(1, 2, 3, 1, &x, &y, &w, &h))
90  goto fail;
91  if ((w != 0) || (h != 0))
92  goto fail;
93  w = 23;
94  h = 42;
95  if (!gdi_CRectToCRgn(1, 2, 3, 4, &x, &y, &w, &h))
96  goto fail;
97  if (x != 1)
98  goto fail;
99  if (y != 2)
100  goto fail;
101  if (w != (3 - 1 + 1))
102  goto fail;
103  if (h != (4 - 2 + 1))
104  goto fail;
105 
106  if (!gdi_RgnToRect(rgn1, rect2))
107  goto fail;
108 
109  if (rgn1->x != rect2->left)
110  goto fail;
111  if (rgn1->y != rect2->top)
112  goto fail;
113  if (rgn1->w != (rect2->right - rect2->left + 1))
114  goto fail;
115  if (rgn1->h != (rect2->bottom - rect2->top + 1))
116  goto fail;
117 
118  if (gdi_CRgnToRect(1, 2, 0, 4, rect2))
119  goto fail;
120  if (gdi_CRgnToRect(1, 2, -1, 4, rect2))
121  goto fail;
122  if (gdi_CRgnToRect(1, 2, 3, 0, rect2))
123  goto fail;
124  if (gdi_CRgnToRect(1, 2, 3, -1, rect2))
125  goto fail;
126  if (!gdi_CRgnToRect(1, 2, 3, 4, rect2))
127  goto fail;
128  if (rect2->left != 1)
129  goto fail;
130  if (rect2->right != (1 + 3 - 1))
131  goto fail;
132  if (rect2->top != 2)
133  goto fail;
134  if (rect2->bottom != (2 + 4 - 1))
135  goto fail;
136 
137  if (!gdi_RgnToCRect(rgn1, &l, &t, &r, &b))
138  goto fail;
139  if (rgn1->x != l)
140  goto fail;
141  if (rgn1->y != t)
142  goto fail;
143  if (rgn1->w != (r - l + 1))
144  goto fail;
145  if (rgn1->h != (b - t + 1))
146  goto fail;
147 
148  if (gdi_CRgnToCRect(1, 2, -1, 4, &l, &t, &r, &b))
149  goto fail;
150  if (gdi_CRgnToCRect(1, 2, 0, 4, &l, &t, &r, &b))
151  goto fail;
152  if (gdi_CRgnToCRect(1, 2, 3, -1, &l, &t, &r, &b))
153  goto fail;
154  if (gdi_CRgnToCRect(1, 2, 3, -0, &l, &t, &r, &b))
155  goto fail;
156  if (!gdi_CRgnToCRect(1, 2, 3, 4, &l, &t, &r, &b))
157  goto fail;
158  if (l != 1)
159  goto fail;
160  if (t != 2)
161  goto fail;
162  if (r != (1 + 3 - 1))
163  goto fail;
164  if (b != 2 + 4 - 1)
165  goto fail;
166 
167  if (gdi_CopyOverlap(1, 2, 5, 3, -5, 3))
168  goto fail;
169  if (gdi_CopyOverlap(1, 2, 5, 3, 3, -2))
170  goto fail;
171  if (!gdi_CopyOverlap(1, 2, 5, 3, 2, 3))
172  goto fail;
173 
174  if (gdi_SetRect(rect2, -4, 500, 66, -5))
175  goto fail;
176  if (gdi_SetRect(rect2, -4, -500, -66, -5))
177  goto fail;
178  if (!gdi_SetRect(rect2, -4, 500, 66, 754))
179  goto fail;
180 
181  if (gdi_SetRgn(NULL, -23, -42, 33, 99))
182  goto fail;
183  if (gdi_SetRgn(rgn2, -23, -42, -33, 99))
184  goto fail;
185  if (gdi_SetRgn(rgn2, -23, -42, 33, -99))
186  goto fail;
187  if (!gdi_SetRgn(rgn2, -23, -42, 33, 99))
188  goto fail;
189  if (rgn2->x != -23)
190  goto fail;
191  if (rgn2->y != -42)
192  goto fail;
193  if (rgn2->w != 33)
194  goto fail;
195  if (rgn2->h != 99)
196  goto fail;
197  if (rgn2->null)
198  goto fail;
199 
200  if (gdi_SetRectRgn(NULL, 33, 22, 44, 33))
201  goto fail;
202  if (gdi_SetRectRgn(rgn1, 331, 22, 44, 33))
203  goto fail;
204  if (gdi_SetRectRgn(rgn1, 33, 122, 44, 33))
205  goto fail;
206  if (!gdi_SetRectRgn(rgn1, 33, 22, 44, 33))
207  goto fail;
208  if (rgn1->x != 33)
209  goto fail;
210  if (rgn1->y != 22)
211  goto fail;
212  if (rgn1->w != (44 - 33 + 1))
213  goto fail;
214  if (rgn1->h != (33 - 22 + 1))
215  goto fail;
216 
217  if (gdi_EqualRgn(rgn1, rgn2))
218  goto fail;
219  if (!gdi_EqualRgn(rgn1, rgn1))
220  goto fail;
221 
222  if (gdi_CopyRect(rect1, NULL))
223  goto fail;
224  if (gdi_CopyRect(NULL, rect1))
225  goto fail;
226  if (gdi_CopyRect(NULL, NULL))
227  goto fail;
228  if (!gdi_CopyRect(rect1, rect2))
229  goto fail;
230 
231  if (rect1->left != rect2->left)
232  goto fail;
233  if (rect1->top != rect2->top)
234  goto fail;
235  if (rect1->right != rect2->right)
236  goto fail;
237  if (rect1->bottom != rect2->bottom)
238  goto fail;
239 
240  if (gdi_PtInRect(rect1, -23, 550))
241  goto fail;
242  if (gdi_PtInRect(rect1, 2, 3))
243  goto fail;
244  if (!gdi_PtInRect(rect1, 2, 550))
245  goto fail;
246 
247  // BOOL gdi_InvalidateRegion(HGDI_DC hdc, INT32 x, INT32 y, INT32 w, INT32 h);
248 
249  rc = 0;
250 fail:
251  free(rgn1);
252  free(rgn2);
253  free(rect1);
254  free(rect2);
255  return rc;
256 }