Add patch that contain Mali fixes.
[deb_xorg-server.git] / test / fixes.c
CommitLineData
a09e091a
JB
1/**
2 * Copyright © 2011 Red Hat, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24#ifdef HAVE_DIX_CONFIG_H
25#include <dix-config.h>
26#endif
27
28#include <stdio.h>
29#include <stdlib.h>
30#include <X11/X.h>
31#include <xfixesint.h>
32#include <X11/extensions/xfixeswire.h>
33
34static void
35_fixes_test_direction(struct PointerBarrier *barrier, int d[4], int permitted)
36{
37 BOOL blocking;
38 int i, j;
39 int dir = barrier_get_direction(d[0], d[1], d[2], d[3]);
40
41 barrier->directions = 0;
42 blocking = barrier_is_blocking_direction(barrier, dir);
43 assert(blocking);
44
45 for (j = 0; j <= BarrierNegativeY; j++) {
46 for (i = 0; i <= BarrierNegativeY; i++) {
47 barrier->directions |= 1 << i;
48 blocking = barrier_is_blocking_direction(barrier, dir);
49 assert((barrier->directions & permitted) ==
50 permitted ? !blocking : blocking);
51 }
52 }
53
54}
55
56static void
57fixes_pointer_barrier_direction_test(void)
58{
59 struct PointerBarrier barrier;
60
61 int x = 100;
62 int y = 100;
63
64 int directions[8][4] = {
65 {x, y, x, y + 100}, /* S */
66 {x + 50, y, x - 50, y + 100}, /* SW */
67 {x + 100, y, x, y}, /* W */
68 {x + 100, y + 50, x, y - 50}, /* NW */
69 {x, y + 100, x, y}, /* N */
70 {x - 50, y + 100, x + 50, y}, /* NE */
71 {x, y, x + 100, y}, /* E */
72 {x, y - 50, x + 100, y + 50}, /* SE */
73 };
74
75 barrier.x1 = x;
76 barrier.x2 = x;
77 barrier.y1 = y - 50;
78 barrier.y2 = y + 49;
79
80 _fixes_test_direction(&barrier, directions[0], BarrierPositiveY);
81 _fixes_test_direction(&barrier, directions[1],
82 BarrierPositiveY | BarrierNegativeX);
83 _fixes_test_direction(&barrier, directions[2], BarrierNegativeX);
84 _fixes_test_direction(&barrier, directions[3],
85 BarrierNegativeY | BarrierNegativeX);
86 _fixes_test_direction(&barrier, directions[4], BarrierNegativeY);
87 _fixes_test_direction(&barrier, directions[5],
88 BarrierPositiveX | BarrierNegativeY);
89 _fixes_test_direction(&barrier, directions[6], BarrierPositiveX);
90 _fixes_test_direction(&barrier, directions[7],
91 BarrierPositiveY | BarrierPositiveX);
92
93}
94
95static void
96fixes_pointer_barriers_test(void)
97{
98 struct PointerBarrier barrier;
99 int x1, y1, x2, y2;
100 double distance;
101
102 int x = 100;
103 int y = 100;
104
105 /* vert barrier */
106 barrier.x1 = x;
107 barrier.x2 = x;
108 barrier.y1 = y - 50;
109 barrier.y2 = y + 50;
110
111 /* across at half-way */
112 x1 = x + 1;
113 x2 = x - 1;
114 y1 = y;
115 y2 = y;
116 assert(barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
117 assert(distance == 1);
118
119 /* definitely not across */
120 x1 = x + 10;
121 x2 = x + 5;
122 assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
123
124 /* across, but outside of y range */
125 x1 = x + 1;
126 x2 = x - 1;
127 y1 = y + 100;
128 y2 = y + 100;
129 assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
130
131 /* across, diagonally */
132 x1 = x + 5;
133 x2 = x - 5;
134 y1 = y + 5;
135 y2 = y - 5;
136 assert(barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
137
138 /* across but outside boundary, diagonally */
139 x1 = x + 5;
140 x2 = x - 5;
141 y1 = y + 100;
142 y2 = y + 50;
143 assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
144
145 /* edge case: startpoint of movement on barrier → blocking */
146 x1 = x;
147 x2 = x - 1;
148 y1 = y;
149 y2 = y;
150 assert(barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
151
152 /* edge case: startpoint of movement on barrier → not blocking, positive */
153 x1 = x;
154 x2 = x + 1;
155 y1 = y;
156 y2 = y;
157 assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
158
159 /* edge case: startpoint of movement on barrier → not blocking, negative */
160 x1 = x - 1;
161 x2 = x - 2;
162 y1 = y;
163 y2 = y;
164 assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
165
166 /* edge case: endpoint of movement on barrier → blocking */
167 x1 = x + 1;
168 x2 = x;
169 y1 = y;
170 y2 = y;
171 assert(barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
172
173 /* startpoint on barrier but outside y range */
174 x1 = x;
175 x2 = x - 1;
176 y1 = y + 100;
177 y2 = y + 100;
178 assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
179
180 /* endpoint on barrier but outside y range */
181 x1 = x + 1;
182 x2 = x;
183 y1 = y + 100;
184 y2 = y + 100;
185 assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
186
187 /* horizontal barrier */
188 barrier.x1 = x - 50;
189 barrier.x2 = x + 50;
190 barrier.y1 = y;
191 barrier.y2 = y;
192
193 /* across at half-way */
194 x1 = x;
195 x2 = x;
196 y1 = y - 1;
197 y2 = y + 1;
198 assert(barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
199
200 /* definitely not across */
201 y1 = y + 10;
202 y2 = y + 5;
203 assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
204
205 /* across, but outside of y range */
206 x1 = x + 100;
207 x2 = x + 100;
208 y1 = y + 1;
209 y2 = y - 1;
210 assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
211
212 /* across, diagonally */
213 y1 = y + 5;
214 y2 = y - 5;
215 x1 = x + 5;
216 x2 = x - 5;
217 assert(barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
218
219 /* across but outside boundary, diagonally */
220 y1 = y + 5;
221 y2 = y - 5;
222 x1 = x + 100;
223 x2 = x + 50;
224 assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
225
226 /* edge case: startpoint of movement on barrier → blocking */
227 y1 = y;
228 y2 = y - 1;
229 x1 = x;
230 x2 = x;
231 assert(barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
232
233 /* edge case: startpoint of movement on barrier → not blocking, positive */
234 y1 = y;
235 y2 = y + 1;
236 x1 = x;
237 x2 = x;
238 assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
239
240 /* edge case: startpoint of movement on barrier → not blocking, negative */
241 y1 = y - 1;
242 y2 = y - 2;
243 x1 = x;
244 x2 = x;
245 assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
246
247 /* edge case: endpoint of movement on barrier → blocking */
248 y1 = y + 1;
249 y2 = y;
250 x1 = x;
251 x2 = x;
252 assert(barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
253
254 /* startpoint on barrier but outside y range */
255 y1 = y;
256 y2 = y - 1;
257 x1 = x + 100;
258 x2 = x + 100;
259 assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
260
261 /* endpoint on barrier but outside y range */
262 y1 = y + 1;
263 y2 = y;
264 x1 = x + 100;
265 x2 = x + 100;
266 assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
267
268 /* ray vert barrier */
269 barrier.x1 = x;
270 barrier.x2 = x;
271 barrier.y1 = -1;
272 barrier.y2 = y + 100;
273
274 /* ray barrier simple case */
275 y1 = y;
276 y2 = y;
277 x1 = x + 50;
278 x2 = x - 50;
279 assert(barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
280
281 /* endpoint outside y range; should be blocked */
282 y1 = y - 1000;
283 y2 = y - 1000;
284 x1 = x + 50;
285 x2 = x - 50;
286 assert(barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
287
288 /* endpoint outside y range */
289 y1 = y + 150;
290 y2 = y + 150;
291 x1 = x + 50;
292 x2 = x - 50;
293 assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
294}
295
296static void
297fixes_pointer_barrier_clamp_test(void)
298{
299 struct PointerBarrier barrier;
300
301 int x = 100;
302 int y = 100;
303
304 int cx, cy; /* clamped */
305
306 /* vert barrier */
307 barrier.x1 = x;
308 barrier.x2 = x;
309 barrier.y1 = y - 50;
310 barrier.y2 = y + 49;
311 barrier.directions = 0;
312
313 cx = INT_MAX;
314 cy = INT_MAX;
315 barrier_clamp_to_barrier(&barrier, BarrierPositiveX, &cx, &cy);
316 assert(cx == barrier.x1 - 1);
317 assert(cy == INT_MAX);
318
319 cx = 0;
320 cy = INT_MAX;
321 barrier_clamp_to_barrier(&barrier, BarrierNegativeX, &cx, &cy);
322 assert(cx == barrier.x1);
323 assert(cy == INT_MAX);
324
325 /* horiz barrier */
326 barrier.x1 = x - 50;
327 barrier.x2 = x + 49;
328 barrier.y1 = y;
329 barrier.y2 = y;
330 barrier.directions = 0;
331
332 cx = INT_MAX;
333 cy = INT_MAX;
334 barrier_clamp_to_barrier(&barrier, BarrierPositiveY, &cx, &cy);
335 assert(cx == INT_MAX);
336 assert(cy == barrier.y1 - 1);
337
338 cx = INT_MAX;
339 cy = 0;
340 barrier_clamp_to_barrier(&barrier, BarrierNegativeY, &cx, &cy);
341 assert(cx == INT_MAX);
342 assert(cy == barrier.y1);
343}
344
345int
346main(int argc, char **argv)
347{
348
349 fixes_pointer_barriers_test();
350 fixes_pointer_barrier_direction_test();
351 fixes_pointer_barrier_clamp_test();
352
353 return 0;
354}