aea380ed5a6b72b42c2e83c9d65de831f995c20f
2 * Copyright © 2009 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
14 * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
23 #ifdef HAVE_DIX_CONFIG_H
24 #include <dix-config.h>
31 #include "eventconvert.h"
33 #include "inpututils.h"
34 #include <X11/extensions/XI2proto.h>
37 test_values_XIRawEvent(RawDeviceEvent
*in
, xXIRawEvent
* out
, BOOL swap
)
41 FP3232
*value
, *raw_value
;
45 uint32_t flagmask
= 0;
48 swaps(&out
->sequenceNumber
);
51 swaps(&out
->deviceid
);
54 swaps(&out
->valuators_len
);
58 assert(out
->type
== GenericEvent
);
59 assert(out
->extension
== 0); /* IReqCode defaults to 0 */
60 assert(out
->evtype
== GetXI2Type(in
->type
));
61 assert(out
->time
== in
->time
);
62 assert(out
->detail
== in
->detail
.button
);
63 assert(out
->deviceid
== in
->deviceid
);
64 assert(out
->valuators_len
>=
65 bytes_to_int32(bits_to_bytes(sizeof(in
->valuators
.mask
))));
69 case ET_RawButtonPress
:
70 case ET_RawButtonRelease
:
71 flagmask
= XIPointerEmulated
;
76 assert((out
->flags
& ~flagmask
) == 0);
78 ptr
= (unsigned char *) &out
[1];
81 for (i
= 0; out
->valuators_len
&& i
< sizeof(in
->valuators
.mask
) * 8; i
++) {
82 if (i
>= MAX_VALUATORS
)
83 assert(!XIMaskIsSet(in
->valuators
.mask
, i
));
84 assert(XIMaskIsSet(in
->valuators
.mask
, i
) == XIMaskIsSet(ptr
, i
));
85 if (XIMaskIsSet(in
->valuators
.mask
, i
))
89 /* length is len of valuator mask (in 4-byte units) + the number of bits
90 * set. Each bit set represents 2 8-byte values, hence the
92 len
= out
->valuators_len
+ bits_set
* 4;
93 assert(out
->length
== len
);
97 for (i
= 0; out
->valuators_len
&& i
< MAX_VALUATORS
; i
++) {
98 assert(XIMaskIsSet(in
->valuators
.mask
, i
) == XIMaskIsSet(ptr
, i
));
99 if (XIMaskIsSet(in
->valuators
.mask
, i
)) {
103 (FP3232
*) (((unsigned char *) &out
[1]) +
104 out
->valuators_len
* 4);
107 vi
= double_to_fp3232(in
->valuators
.data
[i
]);
109 vo
.integral
= value
->integral
;
110 vo
.frac
= value
->frac
;
116 assert(vi
.integral
== vo
.integral
);
117 assert(vi
.frac
== vo
.frac
);
119 raw_value
= value
+ bits_set
;
121 vi
= double_to_fp3232(in
->valuators
.data_raw
[i
]);
123 vo
.integral
= raw_value
->integral
;
124 vo
.frac
= raw_value
->frac
;
130 assert(vi
.integral
== vo
.integral
);
131 assert(vi
.frac
== vo
.frac
);
139 test_XIRawEvent(RawDeviceEvent
*in
)
141 xXIRawEvent
*out
, *swapped
;
144 rc
= EventToXI2((InternalEvent
*) in
, (xEvent
**) &out
);
145 assert(rc
== Success
);
147 test_values_XIRawEvent(in
, out
, FALSE
);
149 swapped
= calloc(1, sizeof(xEvent
) + out
->length
* 4);
150 XI2EventSwap((xGenericEvent
*) out
, (xGenericEvent
*) swapped
);
151 test_values_XIRawEvent(in
, swapped
, TRUE
);
158 test_convert_XIFocusEvent(void)
164 in
.header
= ET_Internal
;
166 rc
= EventToXI2((InternalEvent
*) &in
, &out
);
167 assert(rc
== Success
);
170 in
.header
= ET_Internal
;
171 in
.type
= ET_FocusIn
;
172 rc
= EventToXI2((InternalEvent
*) &in
, &out
);
173 assert(rc
== Success
);
176 in
.header
= ET_Internal
;
177 in
.type
= ET_FocusOut
;
178 rc
= EventToXI2((InternalEvent
*) &in
, &out
);
179 assert(rc
== BadImplementation
);
181 in
.header
= ET_Internal
;
183 rc
= EventToXI2((InternalEvent
*) &in
, &out
);
184 assert(rc
== BadImplementation
);
188 test_convert_XIRawEvent(void)
193 memset(&in
, 0, sizeof(in
));
195 in
.header
= ET_Internal
;
196 in
.type
= ET_RawMotion
;
197 test_XIRawEvent(&in
);
199 in
.header
= ET_Internal
;
200 in
.type
= ET_RawKeyPress
;
201 test_XIRawEvent(&in
);
203 in
.header
= ET_Internal
;
204 in
.type
= ET_RawKeyRelease
;
205 test_XIRawEvent(&in
);
207 in
.header
= ET_Internal
;
208 in
.type
= ET_RawButtonPress
;
209 test_XIRawEvent(&in
);
211 in
.header
= ET_Internal
;
212 in
.type
= ET_RawButtonRelease
;
213 test_XIRawEvent(&in
);
215 in
.detail
.button
= 1L;
216 test_XIRawEvent(&in
);
217 in
.detail
.button
= 1L << 8;
218 test_XIRawEvent(&in
);
219 in
.detail
.button
= 1L << 16;
220 test_XIRawEvent(&in
);
221 in
.detail
.button
= 1L << 24;
222 test_XIRawEvent(&in
);
223 in
.detail
.button
= ~0L;
224 test_XIRawEvent(&in
);
226 in
.detail
.button
= 0;
229 test_XIRawEvent(&in
);
231 test_XIRawEvent(&in
);
233 test_XIRawEvent(&in
);
235 test_XIRawEvent(&in
);
237 test_XIRawEvent(&in
);
240 test_XIRawEvent(&in
);
241 in
.deviceid
= 1 << 8;
242 test_XIRawEvent(&in
);
243 in
.deviceid
= ~0 & 0xFF;
244 test_XIRawEvent(&in
);
246 for (i
= 0; i
< MAX_VALUATORS
; i
++) {
247 XISetMask(in
.valuators
.mask
, i
);
248 test_XIRawEvent(&in
);
249 XIClearMask(in
.valuators
.mask
, i
);
252 for (i
= 0; i
< MAX_VALUATORS
; i
++) {
253 XISetMask(in
.valuators
.mask
, i
);
255 in
.valuators
.data
[i
] = i
+ (i
* 0.0010);
256 in
.valuators
.data_raw
[i
] = (i
+ 10) + (i
* 0.0030);
257 test_XIRawEvent(&in
);
258 XIClearMask(in
.valuators
.mask
, i
);
261 for (i
= 0; i
< MAX_VALUATORS
; i
++) {
262 XISetMask(in
.valuators
.mask
, i
);
263 test_XIRawEvent(&in
);
268 test_values_XIDeviceEvent(DeviceEvent
*in
, xXIDeviceEvent
* out
, BOOL swap
)
270 int buttons
, valuators
;
273 uint32_t flagmask
= 0;
277 swaps(&out
->sequenceNumber
);
280 swaps(&out
->deviceid
);
281 swaps(&out
->sourceid
);
289 swapl(&out
->event_x
);
290 swapl(&out
->event_y
);
291 swaps(&out
->buttons_len
);
292 swaps(&out
->valuators_len
);
293 swapl(&out
->mods
.base_mods
);
294 swapl(&out
->mods
.latched_mods
);
295 swapl(&out
->mods
.locked_mods
);
296 swapl(&out
->mods
.effective_mods
);
300 assert(out
->extension
== 0); /* IReqCode defaults to 0 */
301 assert(out
->evtype
== GetXI2Type(in
->type
));
302 assert(out
->time
== in
->time
);
303 assert(out
->detail
== in
->detail
.button
);
304 assert(out
->length
>= 12);
306 assert(out
->deviceid
== in
->deviceid
);
307 assert(out
->sourceid
== in
->sourceid
);
312 case ET_ButtonRelease
:
313 flagmask
= XIPointerEmulated
;
316 flagmask
= XIKeyRepeat
;
322 assert((out
->flags
& ~flagmask
) == 0);
324 assert(out
->root
== in
->root
);
325 assert(out
->event
== None
); /* set in FixUpEventFromWindow */
326 assert(out
->child
== None
); /* set in FixUpEventFromWindow */
328 assert(out
->mods
.base_mods
== in
->mods
.base
);
329 assert(out
->mods
.latched_mods
== in
->mods
.latched
);
330 assert(out
->mods
.locked_mods
== in
->mods
.locked
);
331 assert(out
->mods
.effective_mods
== in
->mods
.effective
);
333 assert(out
->group
.base_group
== in
->group
.base
);
334 assert(out
->group
.latched_group
== in
->group
.latched
);
335 assert(out
->group
.locked_group
== in
->group
.locked
);
336 assert(out
->group
.effective_group
== in
->group
.effective
);
338 assert(out
->event_x
== 0); /* set in FixUpEventFromWindow */
339 assert(out
->event_y
== 0); /* set in FixUpEventFromWindow */
341 assert(out
->root_x
== double_to_fp1616(in
->root_x
+ in
->root_x_frac
));
342 assert(out
->root_y
== double_to_fp1616(in
->root_y
+ in
->root_y_frac
));
345 for (i
= 0; i
< bits_to_bytes(sizeof(in
->buttons
)); i
++) {
346 if (XIMaskIsSet(in
->buttons
, i
)) {
347 assert(out
->buttons_len
>= bytes_to_int32(bits_to_bytes(i
)));
352 ptr
= (unsigned char *) &out
[1];
353 for (i
= 0; i
< sizeof(in
->buttons
) * 8; i
++)
354 assert(XIMaskIsSet(in
->buttons
, i
) == XIMaskIsSet(ptr
, i
));
357 for (i
= 0; i
< MAX_VALUATORS
; i
++)
358 if (XIMaskIsSet(in
->valuators
.mask
, i
))
361 assert(out
->valuators_len
>= bytes_to_int32(bits_to_bytes(valuators
)));
363 ptr
+= out
->buttons_len
* 4;
364 values
= (FP3232
*) (ptr
+ out
->valuators_len
* 4);
365 for (i
= 0; i
< sizeof(in
->valuators
.mask
) * 8 ||
366 i
< (out
->valuators_len
* 4) * 8; i
++) {
367 if (i
>= MAX_VALUATORS
)
368 assert(!XIMaskIsSet(in
->valuators
.mask
, i
) && !XIMaskIsSet(ptr
, i
));
369 else if (i
> sizeof(in
->valuators
.mask
) * 8)
370 assert(!XIMaskIsSet(ptr
, i
));
371 else if (i
> out
->valuators_len
* 4 * 8)
372 assert(!XIMaskIsSet(in
->valuators
.mask
, i
));
374 assert(XIMaskIsSet(in
->valuators
.mask
, i
) == XIMaskIsSet(ptr
, i
));
376 if (XIMaskIsSet(ptr
, i
)) {
379 vi
= double_to_fp3232(in
->valuators
.data
[i
]);
387 assert(vi
.integral
== vo
.integral
);
388 assert(vi
.frac
== vo
.frac
);
396 test_XIDeviceEvent(DeviceEvent
*in
)
398 xXIDeviceEvent
*out
, *swapped
;
401 rc
= EventToXI2((InternalEvent
*) in
, (xEvent
**) &out
);
402 assert(rc
== Success
);
404 test_values_XIDeviceEvent(in
, out
, FALSE
);
406 swapped
= calloc(1, sizeof(xEvent
) + out
->length
* 4);
407 XI2EventSwap((xGenericEvent
*) out
, (xGenericEvent
*) swapped
);
408 test_values_XIDeviceEvent(in
, swapped
, TRUE
);
415 test_convert_XIDeviceEvent(void)
420 memset(&in
, 0, sizeof(in
));
422 in
.header
= ET_Internal
;
424 in
.length
= sizeof(DeviceEvent
);
433 in
.detail
.button
= 8;
435 in
.mods
.latched
= 10;
437 in
.mods
.effective
= 11;
439 in
.group
.latched
= 13;
440 in
.group
.locked
= 14;
441 in
.group
.effective
= 15;
443 test_XIDeviceEvent(&in
);
446 in
.detail
.button
= 1L;
447 test_XIDeviceEvent(&in
);
448 in
.detail
.button
= 1L << 8;
449 test_XIDeviceEvent(&in
);
450 in
.detail
.button
= 1L << 16;
451 test_XIDeviceEvent(&in
);
452 in
.detail
.button
= 1L << 24;
453 test_XIDeviceEvent(&in
);
454 in
.detail
.button
= ~0L;
455 test_XIDeviceEvent(&in
);
459 test_XIDeviceEvent(&in
);
461 test_XIDeviceEvent(&in
);
463 test_XIDeviceEvent(&in
);
465 test_XIDeviceEvent(&in
);
467 test_XIDeviceEvent(&in
);
471 test_XIDeviceEvent(&in
);
472 in
.deviceid
= 1 << 8;
473 test_XIDeviceEvent(&in
);
474 in
.deviceid
= ~0 & 0xFF;
475 test_XIDeviceEvent(&in
);
479 test_XIDeviceEvent(&in
);
480 in
.deviceid
= 1 << 8;
481 test_XIDeviceEvent(&in
);
482 in
.deviceid
= ~0 & 0xFF;
483 test_XIDeviceEvent(&in
);
487 test_XIDeviceEvent(&in
);
489 test_XIDeviceEvent(&in
);
491 test_XIDeviceEvent(&in
);
493 test_XIDeviceEvent(&in
);
495 test_XIDeviceEvent(&in
);
499 test_XIDeviceEvent(&in
);
501 test_XIDeviceEvent(&in
);
502 in
.root_x
= ~0 & 0xFF;
503 test_XIDeviceEvent(&in
);
506 test_XIDeviceEvent(&in
);
507 in
.root_x_frac
= 1 << 8;
508 test_XIDeviceEvent(&in
);
509 in
.root_x_frac
= ~0 & 0xFF;
510 test_XIDeviceEvent(&in
);
513 test_XIDeviceEvent(&in
);
515 test_XIDeviceEvent(&in
);
516 in
.root_y
= ~0 & 0xFF;
517 test_XIDeviceEvent(&in
);
520 test_XIDeviceEvent(&in
);
521 in
.root_y_frac
= 1 << 8;
522 test_XIDeviceEvent(&in
);
523 in
.root_y_frac
= ~0 & 0xFF;
524 test_XIDeviceEvent(&in
);
528 test_XIDeviceEvent(&in
);
529 in
.mods
.base
= 1L << 8;
530 test_XIDeviceEvent(&in
);
531 in
.mods
.base
= 1L << 16;
532 test_XIDeviceEvent(&in
);
533 in
.mods
.base
= 1L << 24;
534 test_XIDeviceEvent(&in
);
536 test_XIDeviceEvent(&in
);
538 in
.mods
.latched
= 1L;
539 test_XIDeviceEvent(&in
);
540 in
.mods
.latched
= 1L << 8;
541 test_XIDeviceEvent(&in
);
542 in
.mods
.latched
= 1L << 16;
543 test_XIDeviceEvent(&in
);
544 in
.mods
.latched
= 1L << 24;
545 test_XIDeviceEvent(&in
);
546 in
.mods
.latched
= ~0L;
547 test_XIDeviceEvent(&in
);
550 test_XIDeviceEvent(&in
);
551 in
.mods
.locked
= 1L << 8;
552 test_XIDeviceEvent(&in
);
553 in
.mods
.locked
= 1L << 16;
554 test_XIDeviceEvent(&in
);
555 in
.mods
.locked
= 1L << 24;
556 test_XIDeviceEvent(&in
);
557 in
.mods
.locked
= ~0L;
558 test_XIDeviceEvent(&in
);
560 in
.mods
.effective
= 1L;
561 test_XIDeviceEvent(&in
);
562 in
.mods
.effective
= 1L << 8;
563 test_XIDeviceEvent(&in
);
564 in
.mods
.effective
= 1L << 16;
565 test_XIDeviceEvent(&in
);
566 in
.mods
.effective
= 1L << 24;
567 test_XIDeviceEvent(&in
);
568 in
.mods
.effective
= ~0L;
569 test_XIDeviceEvent(&in
);
573 test_XIDeviceEvent(&in
);
574 in
.group
.base
= ~0 & 0xFF;
575 test_XIDeviceEvent(&in
);
577 in
.group
.latched
= 1;
578 test_XIDeviceEvent(&in
);
579 in
.group
.latched
= ~0 & 0xFF;
580 test_XIDeviceEvent(&in
);
583 test_XIDeviceEvent(&in
);
584 in
.group
.locked
= ~0 & 0xFF;
585 test_XIDeviceEvent(&in
);
587 in
.mods
.effective
= 1;
588 test_XIDeviceEvent(&in
);
589 in
.mods
.effective
= ~0 & 0xFF;
590 test_XIDeviceEvent(&in
);
592 for (i
= 0; i
< sizeof(in
.buttons
) * 8; i
++) {
593 XISetMask(in
.buttons
, i
);
594 test_XIDeviceEvent(&in
);
595 XIClearMask(in
.buttons
, i
);
598 for (i
= 0; i
< sizeof(in
.buttons
) * 8; i
++) {
599 XISetMask(in
.buttons
, i
);
600 test_XIDeviceEvent(&in
);
603 for (i
= 0; i
< MAX_VALUATORS
; i
++) {
604 XISetMask(in
.valuators
.mask
, i
);
605 test_XIDeviceEvent(&in
);
606 XIClearMask(in
.valuators
.mask
, i
);
609 for (i
= 0; i
< MAX_VALUATORS
; i
++) {
610 XISetMask(in
.valuators
.mask
, i
);
612 in
.valuators
.data
[i
] = i
+ (i
* 0.0020);
613 test_XIDeviceEvent(&in
);
614 XIClearMask(in
.valuators
.mask
, i
);
617 for (i
= 0; i
< MAX_VALUATORS
; i
++) {
618 XISetMask(in
.valuators
.mask
, i
);
619 test_XIDeviceEvent(&in
);
624 test_values_XIDeviceChangedEvent(DeviceChangedEvent
*in
,
625 xXIDeviceChangedEvent
* out
, BOOL swap
)
631 swaps(&out
->sequenceNumber
);
634 swaps(&out
->deviceid
);
635 swaps(&out
->sourceid
);
637 swaps(&out
->num_classes
);
640 assert(out
->type
== GenericEvent
);
641 assert(out
->extension
== 0); /* IReqCode defaults to 0 */
642 assert(out
->evtype
== GetXI2Type(in
->type
));
643 assert(out
->time
== in
->time
);
644 assert(out
->deviceid
== in
->deviceid
);
645 assert(out
->sourceid
== in
->sourceid
);
647 ptr
= (unsigned char *) &out
[1];
648 for (i
= 0; i
< out
->num_classes
; i
++) {
649 xXIAnyInfo
*any
= (xXIAnyInfo
*) ptr
;
654 swaps(&any
->sourceid
);
660 xXIButtonInfo
*b
= (xXIButtonInfo
*) any
;
664 swaps(&b
->num_buttons
);
668 bytes_to_int32(sizeof(xXIButtonInfo
)) +
669 bytes_to_int32(bits_to_bytes(b
->num_buttons
)) +
671 assert(b
->num_buttons
== in
->buttons
.num_buttons
);
673 names
= (Atom
*) ((char *) &b
[1] +
674 pad_to_int32(bits_to_bytes(b
->num_buttons
)));
675 for (j
= 0; j
< b
->num_buttons
; j
++) {
679 assert(names
[j
] == in
->buttons
.names
[j
]);
685 xXIKeyInfo
*k
= (xXIKeyInfo
*) any
;
689 swaps(&k
->num_keycodes
);
693 bytes_to_int32(sizeof(xXIKeyInfo
)) + k
->num_keycodes
);
694 assert(k
->num_keycodes
== in
->keys
.max_keycode
-
695 in
->keys
.min_keycode
+ 1);
697 kc
= (uint32_t *) &k
[1];
698 for (j
= 0; j
< k
->num_keycodes
; j
++) {
702 assert(kc
[j
] >= in
->keys
.min_keycode
);
703 assert(kc
[j
] <= in
->keys
.max_keycode
);
707 case XIValuatorClass
:
709 xXIValuatorInfo
*v
= (xXIValuatorInfo
*) any
;
711 assert(v
->length
== bytes_to_int32(sizeof(xXIValuatorInfo
)));
717 xXIScrollInfo
*s
= (xXIScrollInfo
*) any
;
719 assert(s
->length
== bytes_to_int32(sizeof(xXIScrollInfo
)));
721 assert(s
->sourceid
== in
->sourceid
);
722 assert(s
->number
< in
->num_valuators
);
724 case XIScrollTypeVertical
:
725 assert(in
->valuators
[s
->number
].scroll
.type
==
726 SCROLL_TYPE_VERTICAL
);
728 case XIScrollTypeHorizontal
:
729 assert(in
->valuators
[s
->number
].scroll
.type
==
730 SCROLL_TYPE_HORIZONTAL
);
733 if (s
->flags
& XIScrollFlagPreferred
)
734 assert(in
->valuators
[s
->number
].scroll
.
735 flags
& SCROLL_FLAG_PREFERRED
);
738 printf("Invalid class type.\n\n");
743 ptr
+= any
->length
* 4;
749 test_XIDeviceChangedEvent(DeviceChangedEvent
*in
)
751 xXIDeviceChangedEvent
*out
, *swapped
;
754 rc
= EventToXI2((InternalEvent
*) in
, (xEvent
**) &out
);
755 assert(rc
== Success
);
757 test_values_XIDeviceChangedEvent(in
, out
, FALSE
);
759 swapped
= calloc(1, sizeof(xEvent
) + out
->length
* 4);
760 XI2EventSwap((xGenericEvent
*) out
, (xGenericEvent
*) swapped
);
761 test_values_XIDeviceChangedEvent(in
, swapped
, TRUE
);
768 test_convert_XIDeviceChangedEvent(void)
770 DeviceChangedEvent in
;
773 memset(&in
, 0, sizeof(in
));
774 in
.header
= ET_Internal
;
775 in
.type
= ET_DeviceChanged
;
776 in
.length
= sizeof(DeviceChangedEvent
);
781 in
.num_valuators
= 4;
783 DEVCHANGE_SLAVE_SWITCH
| DEVCHANGE_POINTER_EVENT
|
784 DEVCHANGE_KEYBOARD_EVENT
;
786 for (i
= 0; i
< MAX_BUTTONS
; i
++)
787 in
.buttons
.names
[i
] = i
+ 10;
789 in
.keys
.min_keycode
= 8;
790 in
.keys
.max_keycode
= 255;
792 test_XIDeviceChangedEvent(&in
);
795 test_XIDeviceChangedEvent(&in
);
797 test_XIDeviceChangedEvent(&in
);
799 test_XIDeviceChangedEvent(&in
);
801 test_XIDeviceChangedEvent(&in
);
803 test_XIDeviceChangedEvent(&in
);
806 test_XIDeviceChangedEvent(&in
);
807 in
.deviceid
= 1L << 8;
808 test_XIDeviceChangedEvent(&in
);
809 in
.deviceid
= ~0 & 0xFFFF;
810 test_XIDeviceChangedEvent(&in
);
813 test_XIDeviceChangedEvent(&in
);
814 in
.sourceid
= 1L << 8;
815 test_XIDeviceChangedEvent(&in
);
816 in
.sourceid
= ~0 & 0xFFFF;
817 test_XIDeviceChangedEvent(&in
);
820 test_XIDeviceChangedEvent(&in
);
821 in
.masterid
= 1L << 8;
822 test_XIDeviceChangedEvent(&in
);
823 in
.masterid
= ~0 & 0xFFFF;
824 test_XIDeviceChangedEvent(&in
);
826 in
.buttons
.num_buttons
= 0;
827 test_XIDeviceChangedEvent(&in
);
829 in
.buttons
.num_buttons
= 1;
830 test_XIDeviceChangedEvent(&in
);
832 in
.buttons
.num_buttons
= MAX_BUTTONS
;
833 test_XIDeviceChangedEvent(&in
);
835 in
.keys
.min_keycode
= 0;
836 in
.keys
.max_keycode
= 0;
837 test_XIDeviceChangedEvent(&in
);
839 in
.keys
.max_keycode
= 1 << 8;
840 test_XIDeviceChangedEvent(&in
);
842 in
.keys
.max_keycode
= 0xFFFC; /* highest range, above that the length
844 test_XIDeviceChangedEvent(&in
);
846 in
.keys
.min_keycode
= 1 << 8;
847 in
.keys
.max_keycode
= 1 << 8;
848 test_XIDeviceChangedEvent(&in
);
850 in
.keys
.min_keycode
= 1 << 8;
851 in
.keys
.max_keycode
= 0;
852 test_XIDeviceChangedEvent(&in
);
854 in
.num_valuators
= 0;
855 test_XIDeviceChangedEvent(&in
);
857 in
.num_valuators
= 1;
858 test_XIDeviceChangedEvent(&in
);
860 in
.num_valuators
= MAX_VALUATORS
;
861 test_XIDeviceChangedEvent(&in
);
863 for (i
= 0; i
< MAX_VALUATORS
; i
++) {
864 in
.valuators
[i
].min
= 0;
865 in
.valuators
[i
].max
= 0;
866 test_XIDeviceChangedEvent(&in
);
868 in
.valuators
[i
].max
= 1 << 8;
869 test_XIDeviceChangedEvent(&in
);
870 in
.valuators
[i
].max
= 1 << 16;
871 test_XIDeviceChangedEvent(&in
);
872 in
.valuators
[i
].max
= 1 << 24;
873 test_XIDeviceChangedEvent(&in
);
874 in
.valuators
[i
].max
= abs(~0);
875 test_XIDeviceChangedEvent(&in
);
877 in
.valuators
[i
].resolution
= 1 << 8;
878 test_XIDeviceChangedEvent(&in
);
879 in
.valuators
[i
].resolution
= 1 << 16;
880 test_XIDeviceChangedEvent(&in
);
881 in
.valuators
[i
].resolution
= 1 << 24;
882 test_XIDeviceChangedEvent(&in
);
883 in
.valuators
[i
].resolution
= abs(~0);
884 test_XIDeviceChangedEvent(&in
);
886 in
.valuators
[i
].name
= i
;
887 test_XIDeviceChangedEvent(&in
);
889 in
.valuators
[i
].mode
= Relative
;
890 test_XIDeviceChangedEvent(&in
);
892 in
.valuators
[i
].mode
= Absolute
;
893 test_XIDeviceChangedEvent(&in
);
898 test_values_XITouchOwnershipEvent(TouchOwnershipEvent
*in
,
899 xXITouchOwnershipEvent
* out
, BOOL swap
)
902 swaps(&out
->sequenceNumber
);
905 swaps(&out
->deviceid
);
906 swaps(&out
->sourceid
);
908 swapl(&out
->touchid
);
915 assert(out
->type
== GenericEvent
);
916 assert(out
->extension
== 0); /* IReqCode defaults to 0 */
917 assert(out
->evtype
== GetXI2Type(in
->type
));
918 assert(out
->time
== in
->time
);
919 assert(out
->deviceid
== in
->deviceid
);
920 assert(out
->sourceid
== in
->sourceid
);
921 assert(out
->touchid
== in
->touchid
);
922 assert(out
->flags
== in
->reason
);
926 test_XITouchOwnershipEvent(TouchOwnershipEvent
*in
)
928 xXITouchOwnershipEvent
*out
, *swapped
;
931 rc
= EventToXI2((InternalEvent
*) in
, (xEvent
**) &out
);
932 assert(rc
== Success
);
934 test_values_XITouchOwnershipEvent(in
, out
, FALSE
);
936 swapped
= calloc(1, sizeof(xEvent
) + out
->length
* 4);
937 XI2EventSwap((xGenericEvent
*) out
, (xGenericEvent
*) swapped
);
938 test_values_XITouchOwnershipEvent(in
, swapped
, TRUE
);
944 test_convert_XITouchOwnershipEvent(void)
946 TouchOwnershipEvent in
;
949 memset(&in
, 0, sizeof(in
));
950 in
.header
= ET_Internal
;
951 in
.type
= ET_TouchOwnership
;
952 in
.length
= sizeof(in
);
961 test_XITouchOwnershipEvent(&in
);
963 in
.flags
= XIAcceptTouch
;
964 test_XITouchOwnershipEvent(&in
);
966 in
.flags
= XIRejectTouch
;
967 test_XITouchOwnershipEvent(&in
);
969 for (i
= 1; i
<= 0xFFFF; i
<<= 1) {
971 test_XITouchOwnershipEvent(&in
);
974 for (i
= 1; i
<= 0xFFFF; i
<<= 1) {
976 test_XITouchOwnershipEvent(&in
);
979 for (i
= 1;; i
<<= 1) {
981 test_XITouchOwnershipEvent(&in
);
982 if (i
== ((long) 1 << 31))
988 test_XIBarrierEvent(BarrierEvent
*in
)
990 xXIBarrierEvent
*out
, *swapped
;
996 rc
= EventToXI((InternalEvent
*)in
, (xEvent
**)&out
, &count
);
997 assert(rc
== BadMatch
);
999 rc
= EventToCore((InternalEvent
*)in
, (xEvent
**)&out
, &count
);
1000 assert(rc
== BadMatch
);
1002 rc
= EventToXI2((InternalEvent
*)in
, (xEvent
**)&out
);
1004 assert(out
->type
== GenericEvent
);
1005 assert(out
->extension
== 0); /* IReqCode defaults to 0 */
1006 assert(out
->evtype
== GetXI2Type(in
->type
));
1007 assert(out
->time
== in
->time
);
1008 assert(out
->deviceid
== in
->deviceid
);
1009 assert(out
->sourceid
== in
->sourceid
);
1010 assert(out
->barrier
== in
->barrierid
);
1011 assert(out
->flags
== in
->flags
);
1012 assert(out
->event
== in
->window
);
1013 assert(out
->root
== in
->root
);
1014 assert(out
->dtime
== in
->dt
);
1015 assert(out
->eventid
== in
->event_id
);
1016 assert(out
->root_x
== double_to_fp1616(in
->root_x
));
1017 assert(out
->root_y
== double_to_fp1616(in
->root_y
));
1019 value
= double_to_fp3232(in
->dx
);
1020 assert(out
->dx
.integral
== value
.integral
);
1021 assert(out
->dx
.frac
== value
.frac
);
1022 value
= double_to_fp3232(in
->dy
);
1023 assert(out
->dy
.integral
== value
.integral
);
1024 assert(out
->dy
.frac
== value
.frac
);
1026 eventlen
= sizeof(xEvent
) + out
->length
* 4;
1027 swapped
= calloc(1, eventlen
);
1028 XI2EventSwap((xGenericEvent
*) out
, (xGenericEvent
*) swapped
);
1030 swaps(&swapped
->sequenceNumber
);
1031 swapl(&swapped
->length
);
1032 swaps(&swapped
->evtype
);
1033 swaps(&swapped
->deviceid
);
1034 swapl(&swapped
->time
);
1035 swapl(&swapped
->eventid
);
1036 swapl(&swapped
->root
);
1037 swapl(&swapped
->event
);
1038 swapl(&swapped
->barrier
);
1039 swapl(&swapped
->dtime
);
1040 swaps(&swapped
->sourceid
);
1041 swapl(&swapped
->root_x
);
1042 swapl(&swapped
->root_y
);
1043 swapl(&swapped
->dx
.integral
);
1044 swapl(&swapped
->dx
.frac
);
1045 swapl(&swapped
->dy
.integral
);
1046 swapl(&swapped
->dy
.frac
);
1048 assert(memcmp(swapped
, out
, eventlen
) == 0);
1055 test_convert_XIBarrierEvent(void)
1059 memset(&in
, 0, sizeof(in
));
1060 in
.header
= ET_Internal
;
1061 in
.type
= ET_BarrierHit
;
1062 in
.length
= sizeof(in
);
1067 test_XIBarrierEvent(&in
);
1070 while(in
.deviceid
& 0xFFFF) {
1071 test_XIBarrierEvent(&in
);
1077 while(in
.sourceid
& 0xFFFF) {
1078 test_XIBarrierEvent(&in
);
1085 test_XIBarrierEvent(&in
);
1090 while(in
.barrierid
) {
1091 test_XIBarrierEvent(&in
);
1097 test_XIBarrierEvent(&in
);
1102 while(in
.event_id
) {
1103 test_XIBarrierEvent(&in
);
1109 test_XIBarrierEvent(&in
);
1115 test_XIBarrierEvent(&in
);
1119 /* pseudo-random 16 bit numbers */
1121 test_XIBarrierEvent(&in
);
1123 test_XIBarrierEvent(&in
);
1124 in
.root_x
= 264.908;
1125 test_XIBarrierEvent(&in
);
1126 in
.root_x
= 35638.292;
1127 test_XIBarrierEvent(&in
);
1130 test_XIBarrierEvent(&in
);
1132 test_XIBarrierEvent(&in
);
1133 in
.root_x
= -264.908;
1134 test_XIBarrierEvent(&in
);
1135 in
.root_x
= -35638.292;
1136 test_XIBarrierEvent(&in
);
1139 test_XIBarrierEvent(&in
);
1141 test_XIBarrierEvent(&in
);
1142 in
.root_y
= 264.908;
1143 test_XIBarrierEvent(&in
);
1144 in
.root_y
= 35638.292;
1145 test_XIBarrierEvent(&in
);
1148 test_XIBarrierEvent(&in
);
1150 test_XIBarrierEvent(&in
);
1151 in
.root_y
= -264.908;
1152 test_XIBarrierEvent(&in
);
1153 in
.root_y
= -35638.292;
1154 test_XIBarrierEvent(&in
);
1156 /* equally pseudo-random 32 bit numbers */
1158 test_XIBarrierEvent(&in
);
1160 test_XIBarrierEvent(&in
);
1162 test_XIBarrierEvent(&in
);
1164 test_XIBarrierEvent(&in
);
1165 in
.dx
= 2947813871.2342;
1166 test_XIBarrierEvent(&in
);
1169 test_XIBarrierEvent(&in
);
1171 test_XIBarrierEvent(&in
);
1173 test_XIBarrierEvent(&in
);
1175 test_XIBarrierEvent(&in
);
1176 in
.dx
= -2947813871.2342;
1177 test_XIBarrierEvent(&in
);
1180 test_XIBarrierEvent(&in
);
1182 test_XIBarrierEvent(&in
);
1184 test_XIBarrierEvent(&in
);
1186 test_XIBarrierEvent(&in
);
1187 in
.dy
= 2947813871.2342;
1188 test_XIBarrierEvent(&in
);
1191 test_XIBarrierEvent(&in
);
1193 test_XIBarrierEvent(&in
);
1195 test_XIBarrierEvent(&in
);
1197 test_XIBarrierEvent(&in
);
1198 in
.dy
= -2947813871.2342;
1199 test_XIBarrierEvent(&in
);
1203 main(int argc
, char **argv
)
1205 test_convert_XIRawEvent();
1206 test_convert_XIFocusEvent();
1207 test_convert_XIDeviceEvent();
1208 test_convert_XIDeviceChangedEvent();
1209 test_convert_XITouchOwnershipEvent();
1210 test_convert_XIBarrierEvent();