2 * Copyright © 2011 Red Hat, Inc.
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:
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
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.
24 #ifdef HAVE_DIX_CONFIG_H
25 #include <dix-config.h>
31 #include "scrnintstr.h"
34 touch_grow_queue(void)
39 size_t size
, new_size
;
42 memset(&dev
, 0, sizeof(dev
));
43 dev
.name
= "test device";
48 inputInfo
.devices
= &dev
;
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;
61 /* no more space, should've scheduled a workproc */
62 assert(TouchBeginDDXTouch(&dev
, 1234) == NULL
);
65 new_size
= size
+ size
/ 2 + 1;
66 assert(dev
.last
.num_touches
== new_size
);
68 /* make sure we haven't touched those */
69 for (i
= 0; i
< size
; i
++) {
70 DDXTouchPointInfoPtr t
= &dev
.last
.touches
[i
];
72 assert(t
->active
== TRUE
);
73 assert(t
->ddx_id
== i
);
74 assert(t
->client_id
== i
* 2);
77 /* make sure those are zero-initialized */
78 for (i
= size
; i
< new_size
; i
++) {
79 DDXTouchPointInfoPtr t
= &dev
.last
.touches
[i
];
81 assert(t
->active
== FALSE
);
82 assert(t
->client_id
== 0);
83 assert(t
->ddx_id
== 0);
88 touch_find_ddxid(void)
91 DDXTouchPointInfoPtr ti
;
97 memset(&dev
, 0, sizeof(dev
));
98 dev
.name
= "test device";
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
);
108 dev
.last
.touches
[0].active
= TRUE
;
109 dev
.last
.touches
[0].ddx_id
= 10;
110 dev
.last
.touches
[0].client_id
= 20;
113 ti
= TouchFindByDDXID(&dev
, 10, FALSE
);
114 assert(ti
== &dev
.last
.touches
[0]);
117 ti
= TouchFindByDDXID(&dev
, 20, FALSE
);
121 dev
.last
.touches
[0].active
= FALSE
;
122 ti
= TouchFindByDDXID(&dev
, 10, FALSE
);
125 /* create on number 2 */
126 dev
.last
.touches
[0].active
= TRUE
;
128 ti
= TouchFindByDDXID(&dev
, 20, TRUE
);
129 assert(ti
== &dev
.last
.touches
[1]);
131 assert(ti
->ddx_id
== 20);
133 /* set all to active */
134 for (i
= 0; i
< size
; i
++)
135 dev
.last
.touches
[i
].active
= TRUE
;
137 /* Try to create more, fail */
138 ti
= TouchFindByDDXID(&dev
, 30, TRUE
);
140 ti
= TouchFindByDDXID(&dev
, 30, TRUE
);
142 /* make sure we haven't resized, we're in the signal handler */
143 assert(dev
.last
.num_touches
== size
);
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 */
151 ti
= TouchFindByDDXID(&dev
, 40, TRUE
);
152 assert(ti
== &dev
.last
.touches
[size
]);
156 touch_begin_ddxtouch(void)
159 DDXTouchPointInfoPtr ti
;
160 ValuatorClassRec val
;
163 unsigned int last_client_id
= 0;
166 memset(&dev
, 0, sizeof(dev
));
167 dev
.name
= "test device";
171 touch
.mode
= XIDirectTouch
;
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
);
178 ti
= TouchBeginDDXTouch(&dev
, ddx_id
);
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
);
184 assert(ti
->client_id
> last_client_id
);
185 assert(ti
->emulate_pointer
);
186 last_client_id
= ti
->client_id
;
189 ti
= TouchBeginDDXTouch(&dev
, ddx_id
);
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
);
195 assert(ti
->client_id
> last_client_id
);
196 assert(!ti
->emulate_pointer
);
197 last_client_id
= ti
->client_id
;
201 touch_begin_touch(void)
205 ValuatorClassRec val
;
206 TouchPointInfoPtr ti
;
209 SpriteInfoRec sprite
;
212 screenInfo
.screens
[0] = &screen
;
214 memset(&dev
, 0, sizeof(dev
));
215 dev
.name
= "test device";
218 memset(&sprite
, 0, sizeof(sprite
));
219 dev
.spriteInfo
= &sprite
;
221 memset(&touch
, 0, sizeof(touch
));
222 touch
.num_touches
= 0;
224 memset(&val
, 0, sizeof(val
));
228 ti
= TouchBeginTouch(&dev
, sourceid
, touchid
, TRUE
);
232 ti
= TouchBeginTouch(&dev
, sourceid
, touchid
, TRUE
);
234 assert(ti
->client_id
== touchid
);
236 assert(ti
->sourceid
== sourceid
);
237 assert(ti
->emulate_pointer
);
239 assert(touch
.num_touches
== 1);
246 Atom labels
[2] = { 0 };
248 SpriteInfoRec sprite
;
251 screenInfo
.screens
[0] = &screen
;
253 memset(&dev
, 0, sizeof(dev
));
254 dev
.name
= "test device";
256 memset(&sprite
, 0, sizeof(sprite
));
257 dev
.spriteInfo
= &sprite
;
260 rc
= InitTouchClassDeviceStruct(&dev
, 1, XIDirectTouch
, 2);
263 InitValuatorClassDeviceStruct(&dev
, 2, labels
, 10, Absolute
);
264 rc
= InitTouchClassDeviceStruct(&dev
, 1, XIDirectTouch
, 2);
270 main(int argc
, char **argv
)
274 touch_begin_ddxtouch();