Add patch that contain Mali fixes.
[deb_xorg-server.git] / test / touch.c
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 <stdint.h>
29 #include "inputstr.h"
30 #include "assert.h"
31 #include "scrnintstr.h"
32
33 static void
34 touch_grow_queue(void)
35 {
36 DeviceIntRec dev;
37 ValuatorClassRec val;
38 TouchClassRec touch;
39 size_t size, new_size;
40 int i;
41
42 memset(&dev, 0, sizeof(dev));
43 dev.name = "test device";
44 dev.id = 2;
45 dev.valuator = &val;
46 val.numAxes = 5;
47 dev.touch = &touch;
48 inputInfo.devices = &dev;
49
50 size = 5;
51
52 dev.last.num_touches = size;
53 dev.last.touches = calloc(dev.last.num_touches, sizeof(*dev.last.touches));
54 assert(dev.last.touches);
55 for (i = 0; i < size; i++) {
56 dev.last.touches[i].active = TRUE;
57 dev.last.touches[i].ddx_id = i;
58 dev.last.touches[i].client_id = i * 2;
59 }
60
61 /* no more space, should've scheduled a workproc */
62 assert(TouchBeginDDXTouch(&dev, 1234) == NULL);
63 ProcessWorkQueue();
64
65 new_size = size + size / 2 + 1;
66 assert(dev.last.num_touches == new_size);
67
68 /* make sure we haven't touched those */
69 for (i = 0; i < size; i++) {
70 DDXTouchPointInfoPtr t = &dev.last.touches[i];
71
72 assert(t->active == TRUE);
73 assert(t->ddx_id == i);
74 assert(t->client_id == i * 2);
75 }
76
77 /* make sure those are zero-initialized */
78 for (i = size; i < new_size; i++) {
79 DDXTouchPointInfoPtr t = &dev.last.touches[i];
80
81 assert(t->active == FALSE);
82 assert(t->client_id == 0);
83 assert(t->ddx_id == 0);
84 }
85 }
86
87 static void
88 touch_find_ddxid(void)
89 {
90 DeviceIntRec dev;
91 DDXTouchPointInfoPtr ti;
92 ValuatorClassRec val;
93 TouchClassRec touch;
94 int size = 5;
95 int i;
96
97 memset(&dev, 0, sizeof(dev));
98 dev.name = "test device";
99 dev.id = 2;
100 dev.valuator = &val;
101 val.numAxes = 5;
102 dev.touch = &touch;
103 dev.last.num_touches = size;
104 dev.last.touches = calloc(dev.last.num_touches, sizeof(*dev.last.touches));
105 inputInfo.devices = &dev;
106 assert(dev.last.touches);
107
108 dev.last.touches[0].active = TRUE;
109 dev.last.touches[0].ddx_id = 10;
110 dev.last.touches[0].client_id = 20;
111
112 /* existing */
113 ti = TouchFindByDDXID(&dev, 10, FALSE);
114 assert(ti == &dev.last.touches[0]);
115
116 /* non-existing */
117 ti = TouchFindByDDXID(&dev, 20, FALSE);
118 assert(ti == NULL);
119
120 /* Non-active */
121 dev.last.touches[0].active = FALSE;
122 ti = TouchFindByDDXID(&dev, 10, FALSE);
123 assert(ti == NULL);
124
125 /* create on number 2 */
126 dev.last.touches[0].active = TRUE;
127
128 ti = TouchFindByDDXID(&dev, 20, TRUE);
129 assert(ti == &dev.last.touches[1]);
130 assert(ti->active);
131 assert(ti->ddx_id == 20);
132
133 /* set all to active */
134 for (i = 0; i < size; i++)
135 dev.last.touches[i].active = TRUE;
136
137 /* Try to create more, fail */
138 ti = TouchFindByDDXID(&dev, 30, TRUE);
139 assert(ti == NULL);
140 ti = TouchFindByDDXID(&dev, 30, TRUE);
141 assert(ti == NULL);
142 /* make sure we haven't resized, we're in the signal handler */
143 assert(dev.last.num_touches == size);
144
145 /* stop one touchpoint, try to create, succeed */
146 dev.last.touches[2].active = FALSE;
147 ti = TouchFindByDDXID(&dev, 30, TRUE);
148 assert(ti == &dev.last.touches[2]);
149 /* but still grow anyway */
150 ProcessWorkQueue();
151 ti = TouchFindByDDXID(&dev, 40, TRUE);
152 assert(ti == &dev.last.touches[size]);
153 }
154
155 static void
156 touch_begin_ddxtouch(void)
157 {
158 DeviceIntRec dev;
159 DDXTouchPointInfoPtr ti;
160 ValuatorClassRec val;
161 TouchClassRec touch;
162 int ddx_id = 123;
163 unsigned int last_client_id = 0;
164 int size = 5;
165
166 memset(&dev, 0, sizeof(dev));
167 dev.name = "test device";
168 dev.id = 2;
169 dev.valuator = &val;
170 val.numAxes = 5;
171 touch.mode = XIDirectTouch;
172 dev.touch = &touch;
173 dev.last.num_touches = size;
174 dev.last.touches = calloc(dev.last.num_touches, sizeof(*dev.last.touches));
175 inputInfo.devices = &dev;
176 assert(dev.last.touches);
177
178 ti = TouchBeginDDXTouch(&dev, ddx_id);
179 assert(ti);
180 assert(ti->ddx_id == ddx_id);
181 /* client_id == ddx_id can happen in real life, but not in this test */
182 assert(ti->client_id != ddx_id);
183 assert(ti->active);
184 assert(ti->client_id > last_client_id);
185 assert(ti->emulate_pointer);
186 last_client_id = ti->client_id;
187
188 ddx_id += 10;
189 ti = TouchBeginDDXTouch(&dev, ddx_id);
190 assert(ti);
191 assert(ti->ddx_id == ddx_id);
192 /* client_id == ddx_id can happen in real life, but not in this test */
193 assert(ti->client_id != ddx_id);
194 assert(ti->active);
195 assert(ti->client_id > last_client_id);
196 assert(!ti->emulate_pointer);
197 last_client_id = ti->client_id;
198 }
199
200 static void
201 touch_begin_touch(void)
202 {
203 DeviceIntRec dev;
204 TouchClassRec touch;
205 ValuatorClassRec val;
206 TouchPointInfoPtr ti;
207 int touchid = 12434;
208 int sourceid = 23;
209 SpriteInfoRec sprite;
210 ScreenRec screen;
211
212 screenInfo.screens[0] = &screen;
213
214 memset(&dev, 0, sizeof(dev));
215 dev.name = "test device";
216 dev.id = 2;
217
218 memset(&sprite, 0, sizeof(sprite));
219 dev.spriteInfo = &sprite;
220
221 memset(&touch, 0, sizeof(touch));
222 touch.num_touches = 0;
223
224 memset(&val, 0, sizeof(val));
225 dev.valuator = &val;
226 val.numAxes = 2;
227
228 ti = TouchBeginTouch(&dev, sourceid, touchid, TRUE);
229 assert(!ti);
230
231 dev.touch = &touch;
232 ti = TouchBeginTouch(&dev, sourceid, touchid, TRUE);
233 assert(ti);
234 assert(ti->client_id == touchid);
235 assert(ti->active);
236 assert(ti->sourceid == sourceid);
237 assert(ti->emulate_pointer);
238
239 assert(touch.num_touches == 1);
240 }
241
242 static void
243 touch_init(void)
244 {
245 DeviceIntRec dev;
246 Atom labels[2] = { 0 };
247 int rc;
248 SpriteInfoRec sprite;
249 ScreenRec screen;
250
251 screenInfo.screens[0] = &screen;
252
253 memset(&dev, 0, sizeof(dev));
254 dev.name = "test device";
255
256 memset(&sprite, 0, sizeof(sprite));
257 dev.spriteInfo = &sprite;
258
259 InitAtoms();
260 rc = InitTouchClassDeviceStruct(&dev, 1, XIDirectTouch, 2);
261 assert(rc == FALSE);
262
263 InitValuatorClassDeviceStruct(&dev, 2, labels, 10, Absolute);
264 rc = InitTouchClassDeviceStruct(&dev, 1, XIDirectTouch, 2);
265 assert(rc == TRUE);
266 assert(dev.touch);
267 }
268
269 int
270 main(int argc, char **argv)
271 {
272 touch_grow_queue();
273 touch_find_ddxid();
274 touch_begin_ddxtouch();
275 touch_init();
276 touch_begin_touch();
277
278 return 0;
279 }