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
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>
32 #include <X11/Xproto.h>
33 #include <X11/extensions/XI2proto.h>
34 #include <X11/Xatom.h>
35 #include "windowstr.h"
37 #include "eventconvert.h"
39 #include "exglobals.h"
42 #include "inpututils.h"
47 * Init a device with axes.
48 * Verify values set on the device.
50 * Result: All axes set to default values (usually 0).
53 dix_init_valuators(void)
58 const int num_axes
= 2;
60 Atom atoms
[MAX_VALUATORS
] = { 0 };
62 memset(&dev
, 0, sizeof(DeviceIntRec
));
63 dev
.type
= MASTER_POINTER
; /* claim it's a master to stop ptracccel */
65 assert(InitValuatorClassDeviceStruct(NULL
, 0, atoms
, 0, 0) == FALSE
);
66 assert(InitValuatorClassDeviceStruct(&dev
, num_axes
, atoms
, 0, Absolute
));
70 assert(val
->numAxes
== num_axes
);
71 assert(val
->numMotionEvents
== 0);
74 for (i
= 0; i
< num_axes
; i
++) {
75 assert(val
->axisVal
[i
] == 0);
76 assert(val
->axes
->min_value
== NO_AXIS_LIMITS
);
77 assert(val
->axes
->max_value
== NO_AXIS_LIMITS
);
78 assert(val
->axes
->mode
== Absolute
);
81 assert(dev
.last
.numValuators
== num_axes
);
83 /* invalid increment */
84 assert(SetScrollValuator
85 (&dev
, 0, SCROLL_TYPE_VERTICAL
, 0.0, SCROLL_FLAG_NONE
) == FALSE
);
87 assert(SetScrollValuator
88 (&dev
, 0, SCROLL_TYPE_VERTICAL
- 1, 1.0, SCROLL_FLAG_NONE
) == FALSE
);
89 assert(SetScrollValuator
90 (&dev
, 0, SCROLL_TYPE_HORIZONTAL
+ 1, 1.0,
91 SCROLL_FLAG_NONE
) == FALSE
);
93 assert(SetScrollValuator
94 (&dev
, 2, SCROLL_TYPE_HORIZONTAL
, 1.0, SCROLL_FLAG_NONE
) == FALSE
);
97 assert(SetScrollValuator
98 (&dev
, 0, SCROLL_TYPE_VERTICAL
, 3.0, SCROLL_FLAG_NONE
) == TRUE
);
99 axis
= &dev
.valuator
->axes
[0];
100 assert(axis
->scroll
.increment
== 3.0);
101 assert(axis
->scroll
.type
== SCROLL_TYPE_VERTICAL
);
102 assert(axis
->scroll
.flags
== 0);
105 assert(SetScrollValuator
106 (&dev
, 1, SCROLL_TYPE_HORIZONTAL
, 2.0, SCROLL_FLAG_NONE
) == TRUE
);
107 axis
= &dev
.valuator
->axes
[1];
108 assert(axis
->scroll
.increment
== 2.0);
109 assert(axis
->scroll
.type
== SCROLL_TYPE_HORIZONTAL
);
110 assert(axis
->scroll
.flags
== 0);
112 /* can add another non-preffered axis */
113 assert(SetScrollValuator
114 (&dev
, 1, SCROLL_TYPE_VERTICAL
, 5.0, SCROLL_FLAG_NONE
) == TRUE
);
115 assert(SetScrollValuator
116 (&dev
, 0, SCROLL_TYPE_HORIZONTAL
, 5.0, SCROLL_FLAG_NONE
) == TRUE
);
118 /* can overwrite with Preferred */
119 assert(SetScrollValuator
120 (&dev
, 1, SCROLL_TYPE_VERTICAL
, 5.5, SCROLL_FLAG_PREFERRED
) == TRUE
);
121 axis
= &dev
.valuator
->axes
[1];
122 assert(axis
->scroll
.increment
== 5.5);
123 assert(axis
->scroll
.type
== SCROLL_TYPE_VERTICAL
);
124 assert(axis
->scroll
.flags
== SCROLL_FLAG_PREFERRED
);
126 assert(SetScrollValuator
127 (&dev
, 0, SCROLL_TYPE_HORIZONTAL
, 8.8,
128 SCROLL_FLAG_PREFERRED
) == TRUE
);
129 axis
= &dev
.valuator
->axes
[0];
130 assert(axis
->scroll
.increment
== 8.8);
131 assert(axis
->scroll
.type
== SCROLL_TYPE_HORIZONTAL
);
132 assert(axis
->scroll
.flags
== SCROLL_FLAG_PREFERRED
);
134 /* can overwrite as none */
135 assert(SetScrollValuator(&dev
, 0, SCROLL_TYPE_NONE
, 5.0,
136 SCROLL_FLAG_NONE
) == TRUE
);
137 axis
= &dev
.valuator
->axes
[0];
138 assert(axis
->scroll
.type
== SCROLL_TYPE_NONE
);
140 /* can overwrite axis with new settings */
141 assert(SetScrollValuator
142 (&dev
, 0, SCROLL_TYPE_VERTICAL
, 5.0, SCROLL_FLAG_NONE
) == TRUE
);
143 axis
= &dev
.valuator
->axes
[0];
144 assert(axis
->scroll
.type
== SCROLL_TYPE_VERTICAL
);
145 assert(axis
->scroll
.increment
== 5.0);
146 assert(axis
->scroll
.flags
== SCROLL_FLAG_NONE
);
147 assert(SetScrollValuator
148 (&dev
, 0, SCROLL_TYPE_VERTICAL
, 3.0, SCROLL_FLAG_NONE
) == TRUE
);
149 assert(axis
->scroll
.type
== SCROLL_TYPE_VERTICAL
);
150 assert(axis
->scroll
.increment
== 3.0);
151 assert(axis
->scroll
.flags
== SCROLL_FLAG_NONE
);
154 /* just check the known success cases, and that error cases set the client's
155 * error value correctly. */
157 dix_check_grab_values(void)
160 GrabParameters param
;
163 memset(&client
, 0, sizeof(client
));
165 param
.grabtype
= CORE
;
166 param
.this_device_mode
= GrabModeSync
;
167 param
.other_devices_mode
= GrabModeSync
;
168 param
.modifiers
= AnyModifier
;
169 param
.ownerEvents
= FALSE
;
171 rc
= CheckGrabValues(&client
, ¶m
);
172 assert(rc
== Success
);
174 param
.this_device_mode
= GrabModeAsync
;
175 rc
= CheckGrabValues(&client
, ¶m
);
176 assert(rc
== Success
);
178 param
.this_device_mode
= XIGrabModeTouch
;
179 rc
= CheckGrabValues(&client
, ¶m
);
180 assert(rc
== Success
);
182 param
.this_device_mode
= XIGrabModeTouch
+ 1;
183 rc
= CheckGrabValues(&client
, ¶m
);
184 assert(rc
== BadValue
);
185 assert(client
.errorValue
== param
.this_device_mode
);
186 assert(client
.errorValue
== XIGrabModeTouch
+ 1);
188 param
.this_device_mode
= GrabModeSync
;
189 param
.other_devices_mode
= GrabModeAsync
;
190 rc
= CheckGrabValues(&client
, ¶m
);
192 param
.this_device_mode
= GrabModeSync
;
193 param
.other_devices_mode
= XIGrabModeTouch
;
194 rc
= CheckGrabValues(&client
, ¶m
);
195 assert(rc
== Success
);
196 assert(rc
== Success
);
198 param
.other_devices_mode
= XIGrabModeTouch
+ 1;
199 rc
= CheckGrabValues(&client
, ¶m
);
200 assert(rc
== BadValue
);
201 assert(client
.errorValue
== param
.other_devices_mode
);
202 assert(client
.errorValue
== XIGrabModeTouch
+ 1);
204 param
.other_devices_mode
= GrabModeSync
;
206 param
.modifiers
= 1 << 13;
207 rc
= CheckGrabValues(&client
, ¶m
);
208 assert(rc
== BadValue
);
209 assert(client
.errorValue
== param
.modifiers
);
210 assert(client
.errorValue
== (1 << 13));
212 param
.modifiers
= AnyModifier
;
213 param
.ownerEvents
= TRUE
;
214 rc
= CheckGrabValues(&client
, ¶m
);
215 assert(rc
== Success
);
217 param
.ownerEvents
= 3;
218 rc
= CheckGrabValues(&client
, ¶m
);
219 assert(rc
== BadValue
);
220 assert(client
.errorValue
== param
.ownerEvents
);
221 assert(client
.errorValue
== 3);
225 * Convert various internal events to the matching core event and verify the
229 dix_event_to_core(int type
)
239 const int ROOT_WINDOW_ID
= 0x100;
241 /* EventToCore memsets the event to 0 */
242 #define test_event() \
243 assert(rc == Success); \
245 assert(count == 1); \
246 assert(core->u.u.type == type); \
247 assert(core->u.u.detail == detail); \
248 assert(core->u.keyButtonPointer.time == time); \
249 assert(core->u.keyButtonPointer.rootX == x); \
250 assert(core->u.keyButtonPointer.rootY == y); \
251 assert(core->u.keyButtonPointer.state == state); \
252 assert(core->u.keyButtonPointer.eventX == 0); \
253 assert(core->u.keyButtonPointer.eventY == 0); \
254 assert(core->u.keyButtonPointer.root == ROOT_WINDOW_ID); \
255 assert(core->u.keyButtonPointer.event == 0); \
256 assert(core->u.keyButtonPointer.child == 0); \
257 assert(core->u.keyButtonPointer.sameScreen == FALSE);
266 ev
.length
= sizeof(DeviceEvent
);
270 SetBit(ev
.valuators
.mask
, 0);
271 SetBit(ev
.valuators
.mask
, 1);
272 ev
.root
= ROOT_WINDOW_ID
;
273 ev
.corestate
= state
;
274 ev
.detail
.key
= detail
;
278 rc
= EventToCore((InternalEvent
*) &ev
, &core
, &count
);
285 rc
= EventToCore((InternalEvent
*) &ev
, &core
, &count
);
292 rc
= EventToCore((InternalEvent
*) &ev
, &core
, &count
);
295 x
= 0x8000; /* too high */
296 y
= 0x8000; /* too high */
299 rc
= EventToCore((InternalEvent
*) &ev
, &core
, &count
);
300 assert(rc
== Success
);
303 assert(core
->u
.keyButtonPointer
.rootX
!= x
);
304 assert(core
->u
.keyButtonPointer
.rootY
!= y
);
312 rc
= EventToCore((InternalEvent
*) &ev
, &core
, &count
);
316 ev
.detail
.key
= detail
;
317 rc
= EventToCore((InternalEvent
*) &ev
, &core
, &count
);
320 detail
= 0xFF; /* highest value */
321 ev
.detail
.key
= detail
;
322 rc
= EventToCore((InternalEvent
*) &ev
, &core
, &count
);
325 detail
= 0xFFF; /* too big */
326 ev
.detail
.key
= detail
;
327 rc
= EventToCore((InternalEvent
*) &ev
, &core
, &count
);
328 assert(rc
== BadMatch
);
330 detail
= 0xFF; /* too big */
331 ev
.detail
.key
= detail
;
332 state
= 0xFFFF; /* highest value */
333 ev
.corestate
= state
;
334 rc
= EventToCore((InternalEvent
*) &ev
, &core
, &count
);
337 state
= 0x10000; /* too big */
338 ev
.corestate
= state
;
339 rc
= EventToCore((InternalEvent
*) &ev
, &core
, &count
);
340 assert(rc
== Success
);
343 assert(core
->u
.keyButtonPointer
.state
!= state
);
344 assert(core
->u
.keyButtonPointer
.state
== (state
& 0xFFFF));
350 dix_event_to_core_fail(int evtype
, int expected_rc
)
358 ev
.length
= sizeof(DeviceEvent
);
361 rc
= EventToCore((InternalEvent
*) &ev
, &core
, &count
);
362 assert(rc
== expected_rc
);
366 dix_event_to_core_conversion(void)
368 dix_event_to_core_fail(0, BadImplementation
);
369 dix_event_to_core_fail(1, BadImplementation
);
370 dix_event_to_core_fail(ET_ProximityOut
+ 1, BadImplementation
);
371 dix_event_to_core_fail(ET_ProximityIn
, BadMatch
);
372 dix_event_to_core_fail(ET_ProximityOut
, BadMatch
);
374 dix_event_to_core(ET_KeyPress
);
375 dix_event_to_core(ET_KeyRelease
);
376 dix_event_to_core(ET_ButtonPress
);
377 dix_event_to_core(ET_ButtonRelease
);
378 dix_event_to_core(ET_Motion
);
382 _dix_test_xi_convert(DeviceEvent
*ev
, int expected_rc
, int expected_count
)
388 rc
= EventToXI((InternalEvent
*) ev
, &xi
, &count
);
389 assert(rc
== expected_rc
);
390 assert(count
>= expected_count
);
392 deviceKeyButtonPointer
*kbp
= (deviceKeyButtonPointer
*) xi
;
394 assert(kbp
->type
== IEventBase
+ ev
->type
);
395 assert(kbp
->detail
== ev
->detail
.key
);
396 assert(kbp
->time
== ev
->time
);
397 assert((kbp
->deviceid
& ~MORE_EVENTS
) == ev
->deviceid
);
398 assert(kbp
->root_x
== ev
->root_x
);
399 assert(kbp
->root_y
== ev
->root_y
);
400 assert(kbp
->state
== ev
->corestate
);
401 assert(kbp
->event_x
== 0);
402 assert(kbp
->event_y
== 0);
403 assert(kbp
->root
== ev
->root
);
404 assert(kbp
->event
== 0);
405 assert(kbp
->child
== 0);
406 assert(kbp
->same_screen
== FALSE
);
408 while (--count
> 0) {
409 deviceValuator
*v
= (deviceValuator
*) &xi
[count
];
411 assert(v
->type
== DeviceValuator
);
412 assert(v
->num_valuators
<= 6);
420 * This tests for internal event → XI1 event conversion
421 * - all conversions should generate the right XI event type
422 * - right number of events generated
423 * - extra events are valuators
426 dix_event_to_xi1_conversion(void)
428 DeviceEvent ev
= { 0 };
433 const int ROOT_WINDOW_ID
= 0x100;
437 DeviceValuator
= IEventBase
- 1;
438 DeviceKeyPress
= IEventBase
+ ET_KeyPress
;
439 DeviceKeyRelease
= IEventBase
+ ET_KeyRelease
;
440 DeviceButtonPress
= IEventBase
+ ET_ButtonPress
;
441 DeviceButtonRelease
= IEventBase
+ ET_ButtonRelease
;
442 DeviceMotionNotify
= IEventBase
+ ET_Motion
;
443 DeviceFocusIn
= IEventBase
+ ET_FocusIn
;
444 DeviceFocusOut
= IEventBase
+ ET_FocusOut
;
445 ProximityIn
= IEventBase
+ ET_ProximityIn
;
446 ProximityOut
= IEventBase
+ ET_ProximityOut
;
448 /* EventToXI callocs */
459 ev
.length
= sizeof(DeviceEvent
);
463 SetBit(ev
.valuators
.mask
, 0);
464 SetBit(ev
.valuators
.mask
, 1);
465 ev
.root
= ROOT_WINDOW_ID
;
466 ev
.corestate
= state
;
467 ev
.detail
.key
= detail
;
468 ev
.deviceid
= deviceid
;
470 /* test all types for bad match */
471 ev
.type
= ET_KeyPress
;
472 _dix_test_xi_convert(&ev
, Success
, 1);
473 ev
.type
= ET_KeyRelease
;
474 _dix_test_xi_convert(&ev
, Success
, 1);
475 ev
.type
= ET_ButtonPress
;
476 _dix_test_xi_convert(&ev
, Success
, 1);
477 ev
.type
= ET_ButtonRelease
;
478 _dix_test_xi_convert(&ev
, Success
, 1);
480 _dix_test_xi_convert(&ev
, Success
, 1);
481 ev
.type
= ET_ProximityIn
;
482 _dix_test_xi_convert(&ev
, Success
, 1);
483 ev
.type
= ET_ProximityOut
;
484 _dix_test_xi_convert(&ev
, Success
, 1);
487 ClearBit(ev
.valuators
.mask
, 0);
488 ClearBit(ev
.valuators
.mask
, 1);
489 ev
.type
= ET_KeyPress
;
490 _dix_test_xi_convert(&ev
, Success
, 1);
491 ev
.type
= ET_KeyRelease
;
492 _dix_test_xi_convert(&ev
, Success
, 1);
493 ev
.type
= ET_ButtonPress
;
494 _dix_test_xi_convert(&ev
, Success
, 1);
495 ev
.type
= ET_ButtonRelease
;
496 _dix_test_xi_convert(&ev
, Success
, 1);
498 _dix_test_xi_convert(&ev
, BadMatch
, 0);
499 ev
.type
= ET_ProximityIn
;
500 _dix_test_xi_convert(&ev
, BadMatch
, 0);
501 ev
.type
= ET_ProximityOut
;
502 _dix_test_xi_convert(&ev
, BadMatch
, 0);
504 /* more than 6 axes → 2 valuator events */
505 SetBit(ev
.valuators
.mask
, 0);
506 SetBit(ev
.valuators
.mask
, 1);
507 SetBit(ev
.valuators
.mask
, 2);
508 SetBit(ev
.valuators
.mask
, 3);
509 SetBit(ev
.valuators
.mask
, 4);
510 SetBit(ev
.valuators
.mask
, 5);
511 SetBit(ev
.valuators
.mask
, 6);
512 ev
.type
= ET_KeyPress
;
513 _dix_test_xi_convert(&ev
, Success
, 2);
514 ev
.type
= ET_KeyRelease
;
515 _dix_test_xi_convert(&ev
, Success
, 2);
516 ev
.type
= ET_ButtonPress
;
517 _dix_test_xi_convert(&ev
, Success
, 2);
518 ev
.type
= ET_ButtonRelease
;
519 _dix_test_xi_convert(&ev
, Success
, 2);
521 _dix_test_xi_convert(&ev
, Success
, 2);
522 ev
.type
= ET_ProximityIn
;
523 _dix_test_xi_convert(&ev
, Success
, 2);
524 ev
.type
= ET_ProximityOut
;
525 _dix_test_xi_convert(&ev
, Success
, 2);
527 /* keycode too high */
528 ev
.type
= ET_KeyPress
;
530 _dix_test_xi_convert(&ev
, Success
, 0);
532 /* deviceid too high */
533 ev
.type
= ET_KeyPress
;
536 _dix_test_xi_convert(&ev
, Success
, 0);
540 xi2_struct_sizes(void)
542 #define compare(req) \
543 assert(sizeof(req) == sz_##req);
545 compare(xXIQueryVersionReq
);
546 compare(xXIWarpPointerReq
);
547 compare(xXIChangeCursorReq
);
548 compare(xXIChangeHierarchyReq
);
549 compare(xXISetClientPointerReq
);
550 compare(xXIGetClientPointerReq
);
551 compare(xXISelectEventsReq
);
552 compare(xXIQueryVersionReq
);
553 compare(xXIQueryDeviceReq
);
554 compare(xXISetFocusReq
);
555 compare(xXIGetFocusReq
);
556 compare(xXIGrabDeviceReq
);
557 compare(xXIUngrabDeviceReq
);
558 compare(xXIAllowEventsReq
);
559 compare(xXIPassiveGrabDeviceReq
);
560 compare(xXIPassiveUngrabDeviceReq
);
561 compare(xXIListPropertiesReq
);
562 compare(xXIChangePropertyReq
);
563 compare(xXIDeletePropertyReq
);
564 compare(xXIGetPropertyReq
);
565 compare(xXIGetSelectedEventsReq
);
570 dix_grab_matching(void)
572 DeviceIntRec xi_all_devices
, xi_all_master_devices
, dev1
, dev2
;
576 memset(&a
, 0, sizeof(a
));
577 memset(&b
, 0, sizeof(b
));
579 /* different grabtypes must fail */
582 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
584 rc
= GrabMatchesSecond(&b
, &a
, FALSE
);
589 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
591 rc
= GrabMatchesSecond(&b
, &a
, FALSE
);
596 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
598 rc
= GrabMatchesSecond(&b
, &a
, FALSE
);
601 /* XI2 grabs for different devices must fail, regardless of ignoreDevice
602 * XI2 grabs for master devices must fail against a slave */
603 memset(&xi_all_devices
, 0, sizeof(DeviceIntRec
));
604 memset(&xi_all_master_devices
, 0, sizeof(DeviceIntRec
));
605 memset(&dev1
, 0, sizeof(DeviceIntRec
));
606 memset(&dev2
, 0, sizeof(DeviceIntRec
));
608 xi_all_devices
.id
= XIAllDevices
;
609 xi_all_master_devices
.id
= XIAllMasterDevices
;
615 inputInfo
.all_devices
= &xi_all_devices
;
616 inputInfo
.all_master_devices
= &xi_all_master_devices
;
622 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
627 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
629 rc
= GrabMatchesSecond(&a
, &b
, TRUE
);
632 a
.device
= inputInfo
.all_master_devices
;
634 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
636 rc
= GrabMatchesSecond(&a
, &b
, TRUE
);
640 b
.device
= inputInfo
.all_master_devices
;
641 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
643 rc
= GrabMatchesSecond(&a
, &b
, TRUE
);
646 /* ignoreDevice FALSE must fail for different devices for CORE and XI */
651 a
.modifierDevice
= &dev1
;
652 b
.modifierDevice
= &dev1
;
653 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
660 a
.modifierDevice
= &dev1
;
661 b
.modifierDevice
= &dev1
;
662 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
665 /* ignoreDevice FALSE must fail for different modifier devices for CORE
671 a
.modifierDevice
= &dev1
;
672 b
.modifierDevice
= &dev2
;
673 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
680 a
.modifierDevice
= &dev1
;
681 b
.modifierDevice
= &dev2
;
682 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
685 /* different event type must fail */
690 a
.modifierDevice
= &dev1
;
691 b
.modifierDevice
= &dev1
;
692 a
.type
= XI_KeyPress
;
693 b
.type
= XI_KeyRelease
;
694 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
696 rc
= GrabMatchesSecond(&a
, &b
, TRUE
);
703 a
.modifierDevice
= &dev1
;
704 b
.modifierDevice
= &dev1
;
705 a
.type
= XI_KeyPress
;
706 b
.type
= XI_KeyRelease
;
707 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
709 rc
= GrabMatchesSecond(&a
, &b
, TRUE
);
716 a
.modifierDevice
= &dev1
;
717 b
.modifierDevice
= &dev1
;
718 a
.type
= XI_KeyPress
;
719 b
.type
= XI_KeyRelease
;
720 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
722 rc
= GrabMatchesSecond(&a
, &b
, TRUE
);
725 /* different modifiers must fail */
730 a
.modifierDevice
= &dev1
;
731 b
.modifierDevice
= &dev1
;
732 a
.type
= XI_KeyPress
;
733 b
.type
= XI_KeyPress
;
734 a
.modifiersDetail
.exact
= 1;
735 b
.modifiersDetail
.exact
= 2;
736 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
738 rc
= GrabMatchesSecond(&b
, &a
, FALSE
);
743 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
745 rc
= GrabMatchesSecond(&b
, &a
, FALSE
);
750 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
752 rc
= GrabMatchesSecond(&b
, &a
, FALSE
);
755 /* AnyModifier must fail for XI2 */
758 a
.modifiersDetail
.exact
= AnyModifier
;
759 b
.modifiersDetail
.exact
= 1;
760 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
762 rc
= GrabMatchesSecond(&b
, &a
, FALSE
);
765 /* XIAnyModifier must fail for CORE and XI */
768 a
.modifiersDetail
.exact
= XIAnyModifier
;
769 b
.modifiersDetail
.exact
= 1;
770 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
772 rc
= GrabMatchesSecond(&b
, &a
, FALSE
);
777 a
.modifiersDetail
.exact
= XIAnyModifier
;
778 b
.modifiersDetail
.exact
= 1;
779 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
781 rc
= GrabMatchesSecond(&b
, &a
, FALSE
);
784 /* different detail must fail */
789 a
.modifiersDetail
.exact
= 1;
790 b
.modifiersDetail
.exact
= 1;
791 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
793 rc
= GrabMatchesSecond(&b
, &a
, FALSE
);
798 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
800 rc
= GrabMatchesSecond(&b
, &a
, FALSE
);
805 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
807 rc
= GrabMatchesSecond(&b
, &a
, FALSE
);
810 /* detail of AnyModifier must fail */
813 a
.detail
.exact
= AnyModifier
;
815 a
.modifiersDetail
.exact
= 1;
816 b
.modifiersDetail
.exact
= 1;
817 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
819 rc
= GrabMatchesSecond(&b
, &a
, FALSE
);
824 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
826 rc
= GrabMatchesSecond(&b
, &a
, FALSE
);
831 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
833 rc
= GrabMatchesSecond(&b
, &a
, FALSE
);
836 /* detail of XIAnyModifier must fail */
839 a
.detail
.exact
= XIAnyModifier
;
841 a
.modifiersDetail
.exact
= 1;
842 b
.modifiersDetail
.exact
= 1;
843 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
845 rc
= GrabMatchesSecond(&b
, &a
, FALSE
);
850 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
852 rc
= GrabMatchesSecond(&b
, &a
, FALSE
);
857 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
859 rc
= GrabMatchesSecond(&b
, &a
, FALSE
);
862 /* XIAnyModifier or AnyModifer must succeed */
867 a
.modifiersDetail
.exact
= XIAnyModifier
;
868 b
.modifiersDetail
.exact
= 1;
869 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
871 rc
= GrabMatchesSecond(&b
, &a
, FALSE
);
878 a
.modifiersDetail
.exact
= AnyModifier
;
879 b
.modifiersDetail
.exact
= 1;
880 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
882 rc
= GrabMatchesSecond(&b
, &a
, FALSE
);
889 a
.modifiersDetail
.exact
= AnyModifier
;
890 b
.modifiersDetail
.exact
= 1;
891 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
893 rc
= GrabMatchesSecond(&b
, &a
, FALSE
);
896 /* AnyKey or XIAnyKeycode must succeed */
899 a
.detail
.exact
= XIAnyKeycode
;
901 a
.modifiersDetail
.exact
= 1;
902 b
.modifiersDetail
.exact
= 1;
903 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
905 rc
= GrabMatchesSecond(&b
, &a
, FALSE
);
910 a
.detail
.exact
= AnyKey
;
912 a
.modifiersDetail
.exact
= 1;
913 b
.modifiersDetail
.exact
= 1;
914 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
916 rc
= GrabMatchesSecond(&b
, &a
, FALSE
);
921 a
.detail
.exact
= AnyKey
;
923 a
.modifiersDetail
.exact
= 1;
924 b
.modifiersDetail
.exact
= 1;
925 rc
= GrabMatchesSecond(&a
, &b
, FALSE
);
927 rc
= GrabMatchesSecond(&b
, &a
, FALSE
);
932 test_bits_to_byte(int i
)
936 expected_bytes
= (i
+ 7) / 8;
938 assert(bits_to_bytes(i
) >= i
/ 8);
939 assert((bits_to_bytes(i
) * 8) - i
<= 7);
940 assert(expected_bytes
== bits_to_bytes(i
));
944 test_bytes_to_int32(int i
)
948 expected_4byte
= (i
+ 3) / 4;
950 assert(bytes_to_int32(i
) <= i
);
951 assert((bytes_to_int32(i
) * 4) - i
<= 3);
952 assert(expected_4byte
== bytes_to_int32(i
));
956 test_pad_to_int32(int i
)
960 expected_bytes
= ((i
+ 3) / 4) * 4;
962 assert(pad_to_int32(i
) >= i
);
963 assert(pad_to_int32(i
) - i
<= 3);
964 assert(expected_bytes
== pad_to_int32(i
));
968 test_padding_for_int32(int i
)
970 static const int padlength
[4] = { 0, 3, 2, 1 };
971 int expected_bytes
= (((i
+ 3) / 4) * 4) - i
;
973 assert(padding_for_int32(i
) >= 0);
974 assert(padding_for_int32(i
) <= 3);
975 assert(padding_for_int32(i
) == expected_bytes
);
976 assert(padding_for_int32(i
) == padlength
[i
& 3]);
977 assert((padding_for_int32(i
) + i
) == pad_to_int32(i
));
981 include_byte_padding_macros(void)
983 printf("Testing bits_to_bytes()\n");
985 /* the macros don't provide overflow protection */
986 test_bits_to_byte(0);
987 test_bits_to_byte(1);
988 test_bits_to_byte(2);
989 test_bits_to_byte(7);
990 test_bits_to_byte(8);
991 test_bits_to_byte(0xFF);
992 test_bits_to_byte(0x100);
993 test_bits_to_byte(INT_MAX
- 9);
994 test_bits_to_byte(INT_MAX
- 8);
996 printf("Testing bytes_to_int32()\n");
998 test_bytes_to_int32(0);
999 test_bytes_to_int32(1);
1000 test_bytes_to_int32(2);
1001 test_bytes_to_int32(7);
1002 test_bytes_to_int32(8);
1003 test_bytes_to_int32(0xFF);
1004 test_bytes_to_int32(0x100);
1005 test_bytes_to_int32(0xFFFF);
1006 test_bytes_to_int32(0x10000);
1007 test_bytes_to_int32(0xFFFFFF);
1008 test_bytes_to_int32(0x1000000);
1009 test_bytes_to_int32(INT_MAX
- 4);
1010 test_bytes_to_int32(INT_MAX
- 3);
1012 printf("Testing pad_to_int32()\n");
1014 test_pad_to_int32(0);
1015 test_pad_to_int32(1);
1016 test_pad_to_int32(2);
1017 test_pad_to_int32(3);
1018 test_pad_to_int32(7);
1019 test_pad_to_int32(8);
1020 test_pad_to_int32(0xFF);
1021 test_pad_to_int32(0x100);
1022 test_pad_to_int32(0xFFFF);
1023 test_pad_to_int32(0x10000);
1024 test_pad_to_int32(0xFFFFFF);
1025 test_pad_to_int32(0x1000000);
1026 test_pad_to_int32(INT_MAX
- 4);
1027 test_pad_to_int32(INT_MAX
- 3);
1029 printf("Testing padding_for_int32()\n");
1031 test_padding_for_int32(0);
1032 test_padding_for_int32(1);
1033 test_padding_for_int32(2);
1034 test_padding_for_int32(3);
1035 test_padding_for_int32(7);
1036 test_padding_for_int32(8);
1037 test_padding_for_int32(0xFF);
1038 test_padding_for_int32(0x100);
1039 test_padding_for_int32(0xFFFF);
1040 test_padding_for_int32(0x10000);
1041 test_padding_for_int32(0xFFFFFF);
1042 test_padding_for_int32(0x1000000);
1043 test_padding_for_int32(INT_MAX
- 4);
1044 test_padding_for_int32(INT_MAX
- 3);
1048 xi_unregister_handlers(void)
1053 memset(&dev
, 0, sizeof(dev
));
1055 handler
= XIRegisterPropertyHandler(&dev
, NULL
, NULL
, NULL
);
1056 assert(handler
== 1);
1057 handler
= XIRegisterPropertyHandler(&dev
, NULL
, NULL
, NULL
);
1058 assert(handler
== 2);
1059 handler
= XIRegisterPropertyHandler(&dev
, NULL
, NULL
, NULL
);
1060 assert(handler
== 3);
1062 printf("Unlinking from front.\n");
1064 XIUnregisterPropertyHandler(&dev
, 4); /* NOOP */
1065 assert(dev
.properties
.handlers
->id
== 3);
1066 XIUnregisterPropertyHandler(&dev
, 3);
1067 assert(dev
.properties
.handlers
->id
== 2);
1068 XIUnregisterPropertyHandler(&dev
, 2);
1069 assert(dev
.properties
.handlers
->id
== 1);
1070 XIUnregisterPropertyHandler(&dev
, 1);
1071 assert(dev
.properties
.handlers
== NULL
);
1073 handler
= XIRegisterPropertyHandler(&dev
, NULL
, NULL
, NULL
);
1074 assert(handler
== 4);
1075 handler
= XIRegisterPropertyHandler(&dev
, NULL
, NULL
, NULL
);
1076 assert(handler
== 5);
1077 handler
= XIRegisterPropertyHandler(&dev
, NULL
, NULL
, NULL
);
1078 assert(handler
== 6);
1079 XIUnregisterPropertyHandler(&dev
, 3); /* NOOP */
1080 assert(dev
.properties
.handlers
->next
->next
->next
== NULL
);
1081 XIUnregisterPropertyHandler(&dev
, 4);
1082 assert(dev
.properties
.handlers
->next
->next
== NULL
);
1083 XIUnregisterPropertyHandler(&dev
, 5);
1084 assert(dev
.properties
.handlers
->next
== NULL
);
1085 XIUnregisterPropertyHandler(&dev
, 6);
1086 assert(dev
.properties
.handlers
== NULL
);
1088 handler
= XIRegisterPropertyHandler(&dev
, NULL
, NULL
, NULL
);
1089 assert(handler
== 7);
1090 handler
= XIRegisterPropertyHandler(&dev
, NULL
, NULL
, NULL
);
1091 assert(handler
== 8);
1092 handler
= XIRegisterPropertyHandler(&dev
, NULL
, NULL
, NULL
);
1093 assert(handler
== 9);
1095 XIDeleteAllDeviceProperties(&dev
);
1096 assert(dev
.properties
.handlers
== NULL
);
1097 XIUnregisterPropertyHandler(&dev
, 7); /* NOOP */
1102 cmp_attr_fields(InputAttributes
* attr1
, InputAttributes
* attr2
)
1104 char **tags1
, **tags2
;
1106 assert(attr1
&& attr2
);
1107 assert(attr1
!= attr2
);
1108 assert(attr1
->flags
== attr2
->flags
);
1110 if (attr1
->product
!= NULL
) {
1111 assert(attr1
->product
!= attr2
->product
);
1112 assert(strcmp(attr1
->product
, attr2
->product
) == 0);
1115 assert(attr2
->product
== NULL
);
1117 if (attr1
->vendor
!= NULL
) {
1118 assert(attr1
->vendor
!= attr2
->vendor
);
1119 assert(strcmp(attr1
->vendor
, attr2
->vendor
) == 0);
1122 assert(attr2
->vendor
== NULL
);
1124 if (attr1
->device
!= NULL
) {
1125 assert(attr1
->device
!= attr2
->device
);
1126 assert(strcmp(attr1
->device
, attr2
->device
) == 0);
1129 assert(attr2
->device
== NULL
);
1131 if (attr1
->pnp_id
!= NULL
) {
1132 assert(attr1
->pnp_id
!= attr2
->pnp_id
);
1133 assert(strcmp(attr1
->pnp_id
, attr2
->pnp_id
) == 0);
1136 assert(attr2
->pnp_id
== NULL
);
1138 if (attr1
->usb_id
!= NULL
) {
1139 assert(attr1
->usb_id
!= attr2
->usb_id
);
1140 assert(strcmp(attr1
->usb_id
, attr2
->usb_id
) == 0);
1143 assert(attr2
->usb_id
== NULL
);
1145 tags1
= attr1
->tags
;
1146 tags2
= attr2
->tags
;
1148 /* if we don't have any tags, skip the tag checking bits */
1154 /* Don't lug around empty arrays */
1158 /* check for identical content, but duplicated */
1160 assert(*tags1
!= *tags2
);
1161 assert(strcmp(*tags1
, *tags2
) == 0);
1166 /* ensure tags1 and tags2 have the same no of elements */
1169 /* check for not sharing memory */
1170 tags1
= attr1
->tags
;
1172 tags2
= attr2
->tags
;
1174 assert(*tags1
!= *tags2
++);
1181 dix_input_attributes(void)
1183 InputAttributes orig
= { 0 };
1184 InputAttributes
*new;
1185 char *tags
[4] = { "tag1", "tag2", "tag2", NULL
};
1187 new = DuplicateInputAttributes(NULL
);
1190 new = DuplicateInputAttributes(&orig
);
1191 assert(memcmp(&orig
, new, sizeof(InputAttributes
)) == 0);
1193 orig
.product
= "product name";
1194 new = DuplicateInputAttributes(&orig
);
1195 cmp_attr_fields(&orig
, new);
1196 FreeInputAttributes(new);
1198 orig
.vendor
= "vendor name";
1199 new = DuplicateInputAttributes(&orig
);
1200 cmp_attr_fields(&orig
, new);
1201 FreeInputAttributes(new);
1203 orig
.device
= "device path";
1204 new = DuplicateInputAttributes(&orig
);
1205 cmp_attr_fields(&orig
, new);
1206 FreeInputAttributes(new);
1208 orig
.pnp_id
= "PnPID";
1209 new = DuplicateInputAttributes(&orig
);
1210 cmp_attr_fields(&orig
, new);
1211 FreeInputAttributes(new);
1213 orig
.usb_id
= "USBID";
1214 new = DuplicateInputAttributes(&orig
);
1215 cmp_attr_fields(&orig
, new);
1216 FreeInputAttributes(new);
1219 new = DuplicateInputAttributes(&orig
);
1220 cmp_attr_fields(&orig
, new);
1221 FreeInputAttributes(new);
1224 new = DuplicateInputAttributes(&orig
);
1225 cmp_attr_fields(&orig
, new);
1226 FreeInputAttributes(new);
1230 dix_input_valuator_masks(void)
1232 ValuatorMask
*mask
= NULL
, *copy
;
1233 int nvaluators
= MAX_VALUATORS
;
1234 double valuators
[nvaluators
];
1235 int val_ranged
[nvaluators
];
1237 int first_val
, num_vals
;
1239 for (i
= 0; i
< nvaluators
; i
++) {
1240 valuators
[i
] = i
+ 0.5;
1244 mask
= valuator_mask_new(nvaluators
);
1245 assert(mask
!= NULL
);
1246 assert(valuator_mask_size(mask
) == 0);
1247 assert(valuator_mask_num_valuators(mask
) == 0);
1249 for (i
= 0; i
< nvaluators
; i
++) {
1250 assert(!valuator_mask_isset(mask
, i
));
1251 valuator_mask_set_double(mask
, i
, valuators
[i
]);
1252 assert(valuator_mask_isset(mask
, i
));
1253 assert(valuator_mask_get(mask
, i
) == trunc(valuators
[i
]));
1254 assert(valuator_mask_get_double(mask
, i
) == valuators
[i
]);
1255 assert(valuator_mask_size(mask
) == i
+ 1);
1256 assert(valuator_mask_num_valuators(mask
) == i
+ 1);
1259 for (i
= 0; i
< nvaluators
; i
++) {
1260 assert(valuator_mask_isset(mask
, i
));
1261 valuator_mask_unset(mask
, i
);
1262 /* we're removing valuators from the front, so size should stay the
1263 * same until the last bit is removed */
1264 if (i
< nvaluators
- 1)
1265 assert(valuator_mask_size(mask
) == nvaluators
);
1266 assert(!valuator_mask_isset(mask
, i
));
1269 assert(valuator_mask_size(mask
) == 0);
1270 valuator_mask_zero(mask
);
1271 assert(valuator_mask_size(mask
) == 0);
1272 assert(valuator_mask_num_valuators(mask
) == 0);
1273 for (i
= 0; i
< nvaluators
; i
++)
1274 assert(!valuator_mask_isset(mask
, i
));
1279 valuator_mask_set_range(mask
, first_val
, num_vals
, val_ranged
);
1280 assert(valuator_mask_size(mask
) == first_val
+ num_vals
);
1281 assert(valuator_mask_num_valuators(mask
) == num_vals
);
1282 for (i
= 0; i
< nvaluators
; i
++) {
1285 if (i
< first_val
|| i
>= first_val
+ num_vals
) {
1286 assert(!valuator_mask_isset(mask
, i
));
1287 assert(!valuator_mask_fetch_double(mask
, i
, &val
));
1290 assert(valuator_mask_isset(mask
, i
));
1291 assert(valuator_mask_get(mask
, i
) == val_ranged
[i
- first_val
]);
1292 assert(valuator_mask_get_double(mask
, i
) ==
1293 val_ranged
[i
- first_val
]);
1294 assert(valuator_mask_fetch_double(mask
, i
, &val
));
1295 assert(val_ranged
[i
- first_val
] == val
);
1299 copy
= valuator_mask_new(nvaluators
);
1300 valuator_mask_copy(copy
, mask
);
1301 assert(mask
!= copy
);
1302 assert(valuator_mask_size(mask
) == valuator_mask_size(copy
));
1303 assert(valuator_mask_num_valuators(mask
) ==
1304 valuator_mask_num_valuators(copy
));
1306 for (i
= 0; i
< nvaluators
; i
++) {
1309 assert(valuator_mask_isset(mask
, i
) == valuator_mask_isset(copy
, i
));
1311 if (!valuator_mask_isset(mask
, i
))
1314 assert(valuator_mask_get(mask
, i
) == valuator_mask_get(copy
, i
));
1315 assert(valuator_mask_get_double(mask
, i
) ==
1316 valuator_mask_get_double(copy
, i
));
1317 assert(valuator_mask_fetch_double(mask
, i
, &a
));
1318 assert(valuator_mask_fetch_double(copy
, i
, &b
));
1322 valuator_mask_free(&mask
);
1323 assert(mask
== NULL
);
1327 dix_valuator_mode(void)
1330 const int num_axes
= MAX_VALUATORS
;
1332 Atom atoms
[MAX_VALUATORS
] = { 0 };
1334 memset(&dev
, 0, sizeof(DeviceIntRec
));
1335 dev
.type
= MASTER_POINTER
; /* claim it's a master to stop ptracccel */
1337 assert(InitValuatorClassDeviceStruct(NULL
, 0, atoms
, 0, 0) == FALSE
);
1338 assert(InitValuatorClassDeviceStruct(&dev
, num_axes
, atoms
, 0, Absolute
));
1340 for (i
= 0; i
< num_axes
; i
++) {
1341 assert(valuator_get_mode(&dev
, i
) == Absolute
);
1342 valuator_set_mode(&dev
, i
, Relative
);
1343 assert(dev
.valuator
->axes
[i
].mode
== Relative
);
1344 assert(valuator_get_mode(&dev
, i
) == Relative
);
1347 valuator_set_mode(&dev
, VALUATOR_MODE_ALL_AXES
, Absolute
);
1348 for (i
= 0; i
< num_axes
; i
++)
1349 assert(valuator_get_mode(&dev
, i
) == Absolute
);
1351 valuator_set_mode(&dev
, VALUATOR_MODE_ALL_AXES
, Relative
);
1352 for (i
= 0; i
< num_axes
; i
++)
1353 assert(valuator_get_mode(&dev
, i
) == Relative
);
1357 include_bit_test_macros(void)
1359 uint8_t mask
[9] = { 0 };
1362 for (i
= 0; i
< sizeof(mask
) / sizeof(mask
[0]); i
++) {
1363 assert(BitIsOn(mask
, i
) == 0);
1365 assert(BitIsOn(mask
, i
) == 1);
1366 assert(! !(mask
[i
/ 8] & (1 << (i
% 8))));
1367 assert(CountBits(mask
, sizeof(mask
)) == 1);
1369 assert(BitIsOn(mask
, i
) == 0);
1374 * Ensure that val->axisVal and val->axes are aligned on doubles.
1377 dix_valuator_alloc(void)
1379 ValuatorClassPtr v
= NULL
;
1382 while (num_axes
< 5) {
1383 v
= AllocValuatorClass(v
, num_axes
);
1386 assert(v
->numAxes
== num_axes
);
1387 #if !defined(__i386__) && !defined(__m68k__) && !defined(__sh__)
1388 /* must be double-aligned on 64 bit */
1389 assert(((void *) v
->axisVal
- (void *) v
) % sizeof(double) == 0);
1390 assert(((void *) v
->axes
- (void *) v
) % sizeof(double) == 0);
1399 dix_get_master(void)
1401 DeviceIntRec vcp
, vck
;
1402 DeviceIntRec ptr
, kbd
;
1403 DeviceIntRec floating
;
1404 SpriteInfoRec vcp_sprite
, vck_sprite
;
1405 SpriteInfoRec ptr_sprite
, kbd_sprite
;
1406 SpriteInfoRec floating_sprite
;
1408 memset(&vcp
, 0, sizeof(vcp
));
1409 memset(&vck
, 0, sizeof(vck
));
1410 memset(&ptr
, 0, sizeof(ptr
));
1411 memset(&kbd
, 0, sizeof(kbd
));
1412 memset(&floating
, 0, sizeof(floating
));
1414 memset(&vcp_sprite
, 0, sizeof(vcp_sprite
));
1415 memset(&vck_sprite
, 0, sizeof(vck_sprite
));
1416 memset(&ptr_sprite
, 0, sizeof(ptr_sprite
));
1417 memset(&kbd_sprite
, 0, sizeof(kbd_sprite
));
1418 memset(&floating_sprite
, 0, sizeof(floating_sprite
));
1420 vcp
.type
= MASTER_POINTER
;
1421 vck
.type
= MASTER_KEYBOARD
;
1424 floating
.type
= SLAVE
;
1426 vcp
.spriteInfo
= &vcp_sprite
;
1427 vck
.spriteInfo
= &vck_sprite
;
1428 ptr
.spriteInfo
= &ptr_sprite
;
1429 kbd
.spriteInfo
= &kbd_sprite
;
1430 floating
.spriteInfo
= &floating_sprite
;
1432 vcp_sprite
.paired
= &vck
;
1433 vck_sprite
.paired
= &vcp
;
1434 ptr_sprite
.paired
= &vcp
;
1435 kbd_sprite
.paired
= &vck
;
1436 floating_sprite
.paired
= &floating
;
1438 vcp_sprite
.spriteOwner
= TRUE
;
1439 floating_sprite
.spriteOwner
= TRUE
;
1444 assert(GetPairedDevice(&vcp
) == &vck
);
1445 assert(GetPairedDevice(&vck
) == &vcp
);
1446 assert(GetMaster(&ptr
, MASTER_POINTER
) == &vcp
);
1447 assert(GetMaster(&ptr
, MASTER_KEYBOARD
) == &vck
);
1448 assert(GetMaster(&kbd
, MASTER_POINTER
) == &vcp
);
1449 assert(GetMaster(&kbd
, MASTER_KEYBOARD
) == &vck
);
1450 assert(GetMaster(&ptr
, MASTER_ATTACHED
) == &vcp
);
1451 assert(GetMaster(&kbd
, MASTER_ATTACHED
) == &vck
);
1453 assert(GetPairedDevice(&floating
) == &floating
);
1454 assert(GetMaster(&floating
, MASTER_POINTER
) == NULL
);
1455 assert(GetMaster(&floating
, MASTER_KEYBOARD
) == NULL
);
1456 assert(GetMaster(&floating
, MASTER_ATTACHED
) == NULL
);
1458 assert(GetMaster(&vcp
, POINTER_OR_FLOAT
) == &vcp
);
1459 assert(GetMaster(&vck
, POINTER_OR_FLOAT
) == &vcp
);
1460 assert(GetMaster(&ptr
, POINTER_OR_FLOAT
) == &vcp
);
1461 assert(GetMaster(&kbd
, POINTER_OR_FLOAT
) == &vcp
);
1463 assert(GetMaster(&vcp
, KEYBOARD_OR_FLOAT
) == &vck
);
1464 assert(GetMaster(&vck
, KEYBOARD_OR_FLOAT
) == &vck
);
1465 assert(GetMaster(&ptr
, KEYBOARD_OR_FLOAT
) == &vck
);
1466 assert(GetMaster(&kbd
, KEYBOARD_OR_FLOAT
) == &vck
);
1468 assert(GetMaster(&floating
, KEYBOARD_OR_FLOAT
) == &floating
);
1469 assert(GetMaster(&floating
, POINTER_OR_FLOAT
) == &floating
);
1473 input_option_test(void)
1475 InputOption
*list
= NULL
;
1479 printf("Testing input_option list interface\n");
1481 list
= input_option_new(list
, "key", "value");
1483 opt
= input_option_find(list
, "key");
1484 val
= input_option_get_value(opt
);
1485 assert(strcmp(val
, "value") == 0);
1487 list
= input_option_new(list
, "2", "v2");
1488 opt
= input_option_find(list
, "key");
1489 val
= input_option_get_value(opt
);
1490 assert(strcmp(val
, "value") == 0);
1492 opt
= input_option_find(list
, "2");
1493 val
= input_option_get_value(opt
);
1494 assert(strcmp(val
, "v2") == 0);
1496 list
= input_option_new(list
, "3", "v3");
1498 /* search, delete */
1499 opt
= input_option_find(list
, "key");
1500 val
= input_option_get_value(opt
);
1501 assert(strcmp(val
, "value") == 0);
1502 list
= input_option_free_element(list
, "key");
1503 opt
= input_option_find(list
, "key");
1504 assert(opt
== NULL
);
1506 opt
= input_option_find(list
, "2");
1507 val
= input_option_get_value(opt
);
1508 assert(strcmp(val
, "v2") == 0);
1509 list
= input_option_free_element(list
, "2");
1510 opt
= input_option_find(list
, "2");
1511 assert(opt
== NULL
);
1513 opt
= input_option_find(list
, "3");
1514 val
= input_option_get_value(opt
);
1515 assert(strcmp(val
, "v3") == 0);
1516 list
= input_option_free_element(list
, "3");
1517 opt
= input_option_find(list
, "3");
1518 assert(opt
== NULL
);
1521 list
= input_option_new(list
, "1", "v3");
1522 list
= input_option_new(list
, "2", "v3");
1523 list
= input_option_new(list
, "3", "v3");
1524 input_option_free_list(&list
);
1526 assert(list
== NULL
);
1528 list
= input_option_new(list
, "1", "v1");
1529 list
= input_option_new(list
, "2", "v2");
1530 list
= input_option_new(list
, "3", "v3");
1532 /* value replacement */
1533 opt
= input_option_find(list
, "2");
1534 val
= input_option_get_value(opt
);
1535 assert(strcmp(val
, "v2") == 0);
1536 input_option_set_value(opt
, "foo");
1537 val
= input_option_get_value(opt
);
1538 assert(strcmp(val
, "foo") == 0);
1539 opt
= input_option_find(list
, "2");
1540 val
= input_option_get_value(opt
);
1541 assert(strcmp(val
, "foo") == 0);
1543 /* key replacement */
1544 input_option_set_key(opt
, "bar");
1545 val
= input_option_get_key(opt
);
1546 assert(strcmp(val
, "bar") == 0);
1547 opt
= input_option_find(list
, "bar");
1548 val
= input_option_get_value(opt
);
1549 assert(strcmp(val
, "foo") == 0);
1551 /* value replacement in input_option_new */
1552 list
= input_option_new(list
, "bar", "foobar");
1553 opt
= input_option_find(list
, "bar");
1554 val
= input_option_get_value(opt
);
1555 assert(strcmp(val
, "foobar") == 0);
1557 input_option_free_list(&list
);
1558 assert(list
== NULL
);
1562 _test_double_fp16_values(double orig_d
)
1564 FP1616 first_fp16
, final_fp16
;
1567 if (orig_d
> 0x7FFF) {
1568 printf("Test out of range\n");
1572 first_fp16
= double_to_fp1616(orig_d
);
1573 final_d
= fp1616_to_double(first_fp16
);
1574 final_fp16
= double_to_fp1616(final_d
);
1577 * char first_fp16_s[64];
1578 * char final_fp16_s[64];
1579 * snprintf(first_fp16_s, sizeof(first_fp16_s), "%d + %u * 2^-16", (first_fp16 & 0xffff0000) >> 16, first_fp16 & 0xffff);
1580 * snprintf(final_fp16_s, sizeof(final_fp16_s), "%d + %u * 2^-16", (final_fp16 & 0xffff0000) >> 16, final_fp16 & 0xffff);
1582 * printf("FP16: original double: %f first fp16: %s, re-encoded double: %f, final fp16: %s\n", orig_d, first_fp16_s, final_d, final_fp16_s);
1586 /* since we lose precision, we only do rough range testing */
1587 assert(final_d
> orig_d
- 0.1);
1588 assert(final_d
< orig_d
+ 0.1);
1590 assert(memcmp(&first_fp16
, &final_fp16
, sizeof(FP1616
)) == 0);
1593 _test_double_fp16_values(-orig_d
);
1597 _test_double_fp32_values(double orig_d
)
1599 FP3232 first_fp32
, final_fp32
;
1602 if (orig_d
> 0x7FFFFFFF) {
1603 printf("Test out of range\n");
1607 first_fp32
= double_to_fp3232(orig_d
);
1608 final_d
= fp3232_to_double(first_fp32
);
1609 final_fp32
= double_to_fp3232(final_d
);
1612 * char first_fp32_s[64];
1613 * char final_fp32_s[64];
1614 * snprintf(first_fp32_s, sizeof(first_fp32_s), "%d + %u * 2^-32", first_fp32.integral, first_fp32.frac);
1615 * snprintf(final_fp32_s, sizeof(final_fp32_s), "%d + %u * 2^-32", first_fp32.integral, final_fp32.frac);
1617 * printf("FP32: original double: %f first fp32: %s, re-encoded double: %f, final fp32: %s\n", orig_d, first_fp32_s, final_d, final_fp32_s);
1621 /* since we lose precision, we only do rough range testing */
1622 assert(final_d
> orig_d
- 0.1);
1623 assert(final_d
< orig_d
+ 0.1);
1625 assert(memcmp(&first_fp32
, &final_fp32
, sizeof(FP3232
)) == 0);
1628 _test_double_fp32_values(-orig_d
);
1632 dix_double_fp_conversion(void)
1636 printf("Testing double to FP1616/FP3232 conversions\n");
1638 _test_double_fp16_values(0);
1639 for (i
= 1; i
< 0x7FFF; i
<<= 1) {
1643 _test_double_fp16_values(val
);
1644 _test_double_fp32_values(val
);
1646 /* and some pseudo-random floating points */
1648 _test_double_fp16_values(val
);
1649 _test_double_fp32_values(val
);
1652 _test_double_fp16_values(val
);
1653 _test_double_fp32_values(val
);
1656 _test_double_fp16_values(val
);
1657 _test_double_fp32_values(val
);
1660 _test_double_fp16_values(val
);
1661 _test_double_fp32_values(val
);
1664 _test_double_fp16_values(val
);
1665 _test_double_fp32_values(val
);
1668 _test_double_fp16_values(val
);
1669 _test_double_fp32_values(val
);
1672 _test_double_fp16_values(val
);
1673 _test_double_fp32_values(val
);
1676 _test_double_fp16_values(val
);
1677 _test_double_fp32_values(val
);
1680 for (i
= 0x7FFFF; i
< 0x7FFFFFFF; i
<<= 1) {
1681 _test_double_fp32_values(i
);
1682 /* and a few more random floating points, obtained
1683 * by faceplanting into the numpad repeatedly */
1684 _test_double_fp32_values(i
+ 0.010177);
1685 _test_double_fp32_values(i
+ 0.213841);
1686 _test_double_fp32_values(i
+ 0.348720);
1687 _test_double_fp32_values(i
+ 0.472020);
1688 _test_double_fp32_values(i
+ 0.572020);
1689 _test_double_fp32_values(i
+ 0.892929);
1693 /* The mieq test verifies that events added to the queue come out in the same
1694 * order that they went in.
1696 static uint32_t mieq_test_event_last_processed
;
1699 mieq_test_event_handler(int screenNum
, InternalEvent
*ie
, DeviceIntPtr dev
)
1701 RawDeviceEvent
*e
= (RawDeviceEvent
*) ie
;
1703 assert(e
->type
== ET_RawMotion
);
1704 assert(e
->flags
> mieq_test_event_last_processed
);
1705 mieq_test_event_last_processed
= e
->flags
;
1709 _mieq_test_generate_events(uint32_t start
, uint32_t count
)
1712 while (start
< count
) {
1713 RawDeviceEvent e
= { 0 };
1714 e
.header
= ET_Internal
;
1715 e
.type
= ET_RawMotion
;
1716 e
.length
= sizeof(e
);
1717 e
.time
= GetTimeInMillis();
1720 mieqEnqueue(NULL
, (InternalEvent
*) &e
);
1726 #define mieq_test_generate_events(c) { _mieq_test_generate_events(next, c); next += c; }
1733 mieq_test_event_last_processed
= 0;
1735 mieqSetHandler(ET_RawMotion
, mieq_test_event_handler
);
1737 /* Enough to fit the buffer but trigger a grow */
1738 mieq_test_generate_events(180);
1740 /* We should resize to 512 now */
1741 mieqProcessInputEvents();
1743 /* Some should now get dropped */
1744 mieq_test_generate_events(500);
1746 /* Tell us how many got dropped, 1024 now */
1747 mieqProcessInputEvents();
1749 /* Now make it 2048 */
1750 mieq_test_generate_events(900);
1751 mieqProcessInputEvents();
1753 /* Now make it 4096 (max) */
1754 mieq_test_generate_events(1950);
1755 mieqProcessInputEvents();
1757 /* Now overflow one last time with the maximal queue and reach the verbosity limit */
1758 mieq_test_generate_events(10000);
1759 mieqProcessInputEvents();
1764 /* Simple check that we're replaying events in-order */
1766 process_input_proc(InternalEvent
*ev
, DeviceIntPtr device
)
1768 static int last_evtype
= -1;
1770 if (ev
->any
.header
== 0xac)
1773 assert(ev
->any
.type
== ++last_evtype
);
1777 dix_enqueue_events(void)
1781 InternalEvent ev
[NEVENTS
];
1782 SpriteInfoRec spriteInfo
;
1787 memset(&dev
, 0, sizeof(dev
));
1788 dev
.public.processInputProc
= process_input_proc
;
1790 memset(&spriteInfo
, 0, sizeof(spriteInfo
));
1791 memset(&sprite
, 0, sizeof(sprite
));
1792 dev
.spriteInfo
= &spriteInfo
;
1793 spriteInfo
.sprite
= &sprite
;
1796 assert(xorg_list_is_empty(&syncEvents
.pending
));
1798 /* this way PlayReleasedEvents really runs through all events in the
1800 inputInfo
.devices
= &dev
;
1802 /* to reset process_input_proc */
1803 ev
[0].any
.header
= 0xac;
1805 for (i
= 0; i
< NEVENTS
; i
++) {
1806 ev
[i
].any
.length
= sizeof(*ev
);
1808 EnqueueEvent(&ev
[i
], &dev
);
1809 assert(!xorg_list_is_empty(&syncEvents
.pending
));
1810 qe
= xorg_list_last_entry(&syncEvents
.pending
, QdEventRec
, next
);
1811 assert(memcmp(qe
->event
, &ev
[i
], ev
[i
].any
.length
) == 0);
1812 qe
= xorg_list_first_entry(&syncEvents
.pending
, QdEventRec
, next
);
1813 assert(memcmp(qe
->event
, &ev
[0], ev
[i
].any
.length
) == 0);
1816 /* calls process_input_proc */
1817 dev
.deviceGrab
.sync
.frozen
= 1;
1818 PlayReleasedEvents();
1819 assert(!xorg_list_is_empty(&syncEvents
.pending
));
1821 dev
.deviceGrab
.sync
.frozen
= 0;
1822 PlayReleasedEvents();
1823 assert(xorg_list_is_empty(&syncEvents
.pending
));
1825 inputInfo
.devices
= NULL
;
1829 main(int argc
, char **argv
)
1831 dix_enqueue_events();
1832 dix_double_fp_conversion();
1833 dix_input_valuator_masks();
1834 dix_input_attributes();
1835 dix_init_valuators();
1836 dix_event_to_core_conversion();
1837 dix_event_to_xi1_conversion();
1838 dix_check_grab_values();
1840 dix_grab_matching();
1841 dix_valuator_mode();
1842 include_byte_padding_macros();
1843 include_bit_test_macros();
1844 xi_unregister_handlers();
1845 dix_valuator_alloc();
1847 input_option_test();