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