FreeRDP
Loading...
Searching...
No Matches
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
14int 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 = nullptr;
26 HGDI_RGN rgn2 = nullptr;
27 GDI_RECT* rect1 = nullptr;
28 GDI_RECT* rect2 = nullptr;
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 if (!gdi_CRgnToRect(0, 0, 1, 1, rect2))
137 goto fail;
138 if ((rect2->left != 0) || (rect2->right != 0) || (rect2->top != 0) || (rect2->bottom != 0))
139 goto fail;
140 if (gdi_CRgnToRect(-1, -1, 1, 1, rect2))
141 goto fail;
142
143 if (!gdi_RgnToCRect(rgn1, &l, &t, &r, &b))
144 goto fail;
145 if (rgn1->x != l)
146 goto fail;
147 if (rgn1->y != t)
148 goto fail;
149 if (rgn1->w != (r - l + 1))
150 goto fail;
151 if (rgn1->h != (b - t + 1))
152 goto fail;
153
154 if (gdi_CRgnToCRect(1, 2, -1, 4, &l, &t, &r, &b))
155 goto fail;
156 if (gdi_CRgnToCRect(1, 2, 0, 4, &l, &t, &r, &b))
157 goto fail;
158 if (gdi_CRgnToCRect(1, 2, 3, -1, &l, &t, &r, &b))
159 goto fail;
160 if (gdi_CRgnToCRect(1, 2, 3, -0, &l, &t, &r, &b))
161 goto fail;
162 if (!gdi_CRgnToCRect(1, 2, 3, 4, &l, &t, &r, &b))
163 goto fail;
164 if (l != 1)
165 goto fail;
166 if (t != 2)
167 goto fail;
168 if (r != (1 + 3 - 1))
169 goto fail;
170 if (b != 2 + 4 - 1)
171 goto fail;
172
173 if (gdi_CopyOverlap(1, 2, 5, 3, -5, 3))
174 goto fail;
175 if (gdi_CopyOverlap(1, 2, 5, 3, 3, -2))
176 goto fail;
177 if (!gdi_CopyOverlap(1, 2, 5, 3, 2, 3))
178 goto fail;
179
180 if (gdi_SetRect(rect2, -4, 500, 66, -5))
181 goto fail;
182 if (gdi_SetRect(rect2, -4, -500, -66, -5))
183 goto fail;
184 if (!gdi_SetRect(rect2, -4, 500, 66, 754))
185 goto fail;
186
187 if (gdi_SetRgn(nullptr, -23, -42, 33, 99))
188 goto fail;
189 if (gdi_SetRgn(rgn2, -23, -42, -33, 99))
190 goto fail;
191 if (gdi_SetRgn(rgn2, -23, -42, 33, -99))
192 goto fail;
193 if (!gdi_SetRgn(rgn2, -23, -42, 33, 99))
194 goto fail;
195 if (rgn2->x != -23)
196 goto fail;
197 if (rgn2->y != -42)
198 goto fail;
199 if (rgn2->w != 33)
200 goto fail;
201 if (rgn2->h != 99)
202 goto fail;
203 if (rgn2->null)
204 goto fail;
205
206 if (gdi_SetRectRgn(nullptr, 33, 22, 44, 33))
207 goto fail;
208 if (gdi_SetRectRgn(rgn1, 331, 22, 44, 33))
209 goto fail;
210 if (gdi_SetRectRgn(rgn1, 33, 122, 44, 33))
211 goto fail;
212 if (!gdi_SetRectRgn(rgn1, 33, 22, 44, 33))
213 goto fail;
214 if (rgn1->x != 33)
215 goto fail;
216 if (rgn1->y != 22)
217 goto fail;
218 if (rgn1->w != (44 - 33 + 1))
219 goto fail;
220 if (rgn1->h != (33 - 22 + 1))
221 goto fail;
222
223 if (gdi_EqualRgn(rgn1, rgn2))
224 goto fail;
225 if (!gdi_EqualRgn(rgn1, rgn1))
226 goto fail;
227
228 if (gdi_CopyRect(rect1, nullptr))
229 goto fail;
230 if (gdi_CopyRect(nullptr, rect1))
231 goto fail;
232 if (gdi_CopyRect(nullptr, nullptr))
233 goto fail;
234 if (!gdi_CopyRect(rect1, rect2))
235 goto fail;
236
237 if (rect1->left != rect2->left)
238 goto fail;
239 if (rect1->top != rect2->top)
240 goto fail;
241 if (rect1->right != rect2->right)
242 goto fail;
243 if (rect1->bottom != rect2->bottom)
244 goto fail;
245
246 if (gdi_PtInRect(rect1, -23, 550))
247 goto fail;
248 if (gdi_PtInRect(rect1, 2, 3))
249 goto fail;
250 if (!gdi_PtInRect(rect1, 2, 550))
251 goto fail;
252
253 // BOOL gdi_InvalidateRegion(HGDI_DC hdc, INT32 x, INT32 y, INT32 w, INT32 h);
254
255 rc = 0;
256fail:
257 free(rgn1);
258 free(rgn2);
259 free(rect1);
260 free(rect2);
261 return rc;
262}