1/**
2 * Copyright © 2009 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/* Test relies on assert() */
25#undef NDEBUG
26
27#ifdef HAVE_DIX_CONFIG_H
28#include <dix-config.h>
29#endif
30
31#include <stdint.h>
32#include <X11/X.h>
33#include "misc.h"
34#include "resource.h"
35#include <X11/Xproto.h>
36#include <X11/extensions/XI2proto.h>
37#include <X11/Xatom.h>
38#include "windowstr.h"
39#include "inputstr.h"
40#include "eventconvert.h"
41#include "exevents.h"
42#include "exglobals.h"
43#include "dixgrabs.h"
44#include "eventstr.h"
45#include "inpututils.h"
46#include "mi.h"
47#include "assert.h"
48
49#include "tests-common.h"
50
51/**
52 * Init a device with axes.
53 * Verify values set on the device.
54 *
55 * Result: All axes set to default values (usually 0).
56 */
57static void
58dix_init_valuators(void)
59{
60    DeviceIntRec dev;
61    ValuatorClassPtr val;
62    AxisInfoPtr axis;
63    const int num_axes = 2;
64    int i;
65    Atom atoms[MAX_VALUATORS] = { 0 };
66
67    memset(&dev, 0, sizeof(DeviceIntRec));
68    dev.type = MASTER_POINTER;  /* claim it's a master to stop ptracccel */
69
70    assert(InitValuatorClassDeviceStruct(NULL, 0, atoms, 0, 0) == FALSE);
71    assert(InitValuatorClassDeviceStruct(&dev, num_axes, atoms, 0, Absolute));
72
73    val = dev.valuator;
74    assert(val);
75    assert(val->numAxes == num_axes);
76    assert(val->numMotionEvents == 0);
77    assert(val->axisVal);
78
79    for (i = 0; i < num_axes; i++) {
80        assert(val->axisVal[i] == 0);
81        assert(val->axes->min_value == NO_AXIS_LIMITS);
82        assert(val->axes->max_value == NO_AXIS_LIMITS);
83        assert(val->axes->mode == Absolute);
84    }
85
86    assert(dev.last.numValuators == num_axes);
87
88    /* invalid increment */
89    assert(SetScrollValuator
90           (&dev, 0, SCROLL_TYPE_VERTICAL, 0.0, SCROLL_FLAG_NONE) == FALSE);
91    /* invalid type */
92    assert(SetScrollValuator
93           (&dev, 0, SCROLL_TYPE_VERTICAL - 1, 1.0, SCROLL_FLAG_NONE) == FALSE);
94    assert(SetScrollValuator
95           (&dev, 0, SCROLL_TYPE_HORIZONTAL + 1, 1.0,
96            SCROLL_FLAG_NONE) == FALSE);
97    /* invalid axisnum */
98    assert(SetScrollValuator
99           (&dev, 2, SCROLL_TYPE_HORIZONTAL, 1.0, SCROLL_FLAG_NONE) == FALSE);
100
101    /* valid */
102    assert(SetScrollValuator
103           (&dev, 0, SCROLL_TYPE_VERTICAL, 3.0, SCROLL_FLAG_NONE) == TRUE);
104    axis = &dev.valuator->axes[0];
105    assert(axis->scroll.increment == 3.0);
106    assert(axis->scroll.type == SCROLL_TYPE_VERTICAL);
107    assert(axis->scroll.flags == 0);
108
109    /* valid */
110    assert(SetScrollValuator
111           (&dev, 1, SCROLL_TYPE_HORIZONTAL, 2.0, SCROLL_FLAG_NONE) == TRUE);
112    axis = &dev.valuator->axes[1];
113    assert(axis->scroll.increment == 2.0);
114    assert(axis->scroll.type == SCROLL_TYPE_HORIZONTAL);
115    assert(axis->scroll.flags == 0);
116
117    /* can add another non-preffered axis */
118    assert(SetScrollValuator
119           (&dev, 1, SCROLL_TYPE_VERTICAL, 5.0, SCROLL_FLAG_NONE) == TRUE);
120    assert(SetScrollValuator
121           (&dev, 0, SCROLL_TYPE_HORIZONTAL, 5.0, SCROLL_FLAG_NONE) == TRUE);
122
123    /* can overwrite with Preferred */
124    assert(SetScrollValuator
125           (&dev, 1, SCROLL_TYPE_VERTICAL, 5.5, SCROLL_FLAG_PREFERRED) == TRUE);
126    axis = &dev.valuator->axes[1];
127    assert(axis->scroll.increment == 5.5);
128    assert(axis->scroll.type == SCROLL_TYPE_VERTICAL);
129    assert(axis->scroll.flags == SCROLL_FLAG_PREFERRED);
130
131    assert(SetScrollValuator
132           (&dev, 0, SCROLL_TYPE_HORIZONTAL, 8.8,
133            SCROLL_FLAG_PREFERRED) == TRUE);
134    axis = &dev.valuator->axes[0];
135    assert(axis->scroll.increment == 8.8);
136    assert(axis->scroll.type == SCROLL_TYPE_HORIZONTAL);
137    assert(axis->scroll.flags == SCROLL_FLAG_PREFERRED);
138
139    /* can overwrite as none */
140    assert(SetScrollValuator(&dev, 0, SCROLL_TYPE_NONE, 5.0,
141                             SCROLL_FLAG_NONE) == TRUE);
142    axis = &dev.valuator->axes[0];
143    assert(axis->scroll.type == SCROLL_TYPE_NONE);
144
145    /* can overwrite axis with new settings */
146    assert(SetScrollValuator
147           (&dev, 0, SCROLL_TYPE_VERTICAL, 5.0, SCROLL_FLAG_NONE) == TRUE);
148    axis = &dev.valuator->axes[0];
149    assert(axis->scroll.type == SCROLL_TYPE_VERTICAL);
150    assert(axis->scroll.increment == 5.0);
151    assert(axis->scroll.flags == SCROLL_FLAG_NONE);
152    assert(SetScrollValuator
153           (&dev, 0, SCROLL_TYPE_VERTICAL, 3.0, SCROLL_FLAG_NONE) == TRUE);
154    assert(axis->scroll.type == SCROLL_TYPE_VERTICAL);
155    assert(axis->scroll.increment == 3.0);
156    assert(axis->scroll.flags == SCROLL_FLAG_NONE);
157}
158
159/* just check the known success cases, and that error cases set the client's
160 * error value correctly. */
161static void
162dix_check_grab_values(void)
163{
164    ClientRec client;
165    GrabParameters param;
166    int rc;
167
168    memset(&client, 0, sizeof(client));
169
170    param.grabtype = CORE;
171    param.this_device_mode = GrabModeSync;
172    param.other_devices_mode = GrabModeSync;
173    param.modifiers = AnyModifier;
174    param.ownerEvents = FALSE;
175
176    rc = CheckGrabValues(&client, &param);
177    assert(rc == Success);
178
179    param.this_device_mode = GrabModeAsync;
180    rc = CheckGrabValues(&client, &param);
181    assert(rc == Success);
182
183    param.this_device_mode = XIGrabModeTouch;
184    rc = CheckGrabValues(&client, &param);
185    assert(rc == Success);
186
187    param.this_device_mode = XIGrabModeTouch + 1;
188    rc = CheckGrabValues(&client, &param);
189    assert(rc == BadValue);
190    assert(client.errorValue == param.this_device_mode);
191    assert(client.errorValue == XIGrabModeTouch + 1);
192
193    param.this_device_mode = GrabModeSync;
194    param.other_devices_mode = GrabModeAsync;
195    rc = CheckGrabValues(&client, &param);
196
197    param.this_device_mode = GrabModeSync;
198    param.other_devices_mode = XIGrabModeTouch;
199    rc = CheckGrabValues(&client, &param);
200    assert(rc == Success);
201    assert(rc == Success);
202
203    param.other_devices_mode = XIGrabModeTouch + 1;
204    rc = CheckGrabValues(&client, &param);
205    assert(rc == BadValue);
206    assert(client.errorValue == param.other_devices_mode);
207    assert(client.errorValue == XIGrabModeTouch + 1);
208
209    param.other_devices_mode = GrabModeSync;
210
211    param.modifiers = 1 << 13;
212    rc = CheckGrabValues(&client, &param);
213    assert(rc == BadValue);
214    assert(client.errorValue == param.modifiers);
215    assert(client.errorValue == (1 << 13));
216
217    param.modifiers = AnyModifier;
218    param.ownerEvents = TRUE;
219    rc = CheckGrabValues(&client, &param);
220    assert(rc == Success);
221
222    param.ownerEvents = 3;
223    rc = CheckGrabValues(&client, &param);
224    assert(rc == BadValue);
225    assert(client.errorValue == param.ownerEvents);
226    assert(client.errorValue == 3);
227}
228
229/**
230 * Convert various internal events to the matching core event and verify the
231 * parameters.
232 */
233static void
234dix_event_to_core(int type)
235{
236    DeviceEvent ev = {};
237    xEvent *core;
238    int time;
239    int x, y;
240    int rc;
241    int state;
242    int detail;
243    int count;
244    const int ROOT_WINDOW_ID = 0x100;
245
246    /* EventToCore memsets the event to 0 */
247#define test_event() \
248    assert(rc == Success); \
249    assert(core); \
250    assert(count == 1); \
251    assert(core->u.u.type == type); \
252    assert(core->u.u.detail == detail); \
253    assert(core->u.keyButtonPointer.time == time); \
254    assert(core->u.keyButtonPointer.rootX == x); \
255    assert(core->u.keyButtonPointer.rootY == y); \
256    assert(core->u.keyButtonPointer.state == state); \
257    assert(core->u.keyButtonPointer.eventX == 0); \
258    assert(core->u.keyButtonPointer.eventY == 0); \
259    assert(core->u.keyButtonPointer.root == ROOT_WINDOW_ID); \
260    assert(core->u.keyButtonPointer.event == 0); \
261    assert(core->u.keyButtonPointer.child == 0); \
262    assert(core->u.keyButtonPointer.sameScreen == FALSE);
263
264    x = 0;
265    y = 0;
266    time = 12345;
267    state = 0;
268    detail = 0;
269
270    ev.header = 0xFF;
271    ev.length = sizeof(DeviceEvent);
272    ev.time = time;
273    ev.root_y = x;
274    ev.root_x = y;
275    SetBit(ev.valuators.mask, 0);
276    SetBit(ev.valuators.mask, 1);
277    ev.root = ROOT_WINDOW_ID;
278    ev.corestate = state;
279    ev.detail.key = detail;
280
281    ev.type = type;
282    ev.detail.key = 0;
283    rc = EventToCore((InternalEvent *) &ev, &core, &count);
284    test_event();
285
286    x = 1;
287    y = 2;
288    ev.root_x = x;
289    ev.root_y = y;
290    rc = EventToCore((InternalEvent *) &ev, &core, &count);
291    test_event();
292
293    x = 0x7FFF;
294    y = 0x7FFF;
295    ev.root_x = x;
296    ev.root_y = y;
297    rc = EventToCore((InternalEvent *) &ev, &core, &count);
298    test_event();
299
300    x = 0x8000;                 /* too high */
301    y = 0x8000;                 /* too high */
302    ev.root_x = x;
303    ev.root_y = y;
304    rc = EventToCore((InternalEvent *) &ev, &core, &count);
305    assert(rc == Success);
306    assert(core);
307    assert(count == 1);
308    assert(core->u.keyButtonPointer.rootX != x);
309    assert(core->u.keyButtonPointer.rootY != y);
310
311    x = 0x7FFF;
312    y = 0x7FFF;
313    ev.root_x = x;
314    ev.root_y = y;
315    time = 0;
316    ev.time = time;
317    rc = EventToCore((InternalEvent *) &ev, &core, &count);
318    test_event();
319
320    detail = 1;
321    ev.detail.key = detail;
322    rc = EventToCore((InternalEvent *) &ev, &core, &count);
323    test_event();
324
325    detail = 0xFF;              /* highest value */
326    ev.detail.key = detail;
327    rc = EventToCore((InternalEvent *) &ev, &core, &count);
328    test_event();
329
330    detail = 0xFFF;             /* too big */
331    ev.detail.key = detail;
332    rc = EventToCore((InternalEvent *) &ev, &core, &count);
333    assert(rc == BadMatch);
334
335    detail = 0xFF;              /* too big */
336    ev.detail.key = detail;
337    state = 0xFFFF;             /* highest value */
338    ev.corestate = state;
339    rc = EventToCore((InternalEvent *) &ev, &core, &count);
340    test_event();
341
342    state = 0x10000;            /* too big */
343    ev.corestate = state;
344    rc = EventToCore((InternalEvent *) &ev, &core, &count);
345    assert(rc == Success);
346    assert(core);
347    assert(count == 1);
348    assert(core->u.keyButtonPointer.state != state);
349    assert(core->u.keyButtonPointer.state == (state & 0xFFFF));
350
351#undef test_event
352}
353
354static void
355dix_event_to_core_fail(int evtype, int expected_rc)
356{
357    DeviceEvent ev;
358    xEvent *core;
359    int rc;
360    int count;
361
362    ev.header = 0xFF;
363    ev.length = sizeof(DeviceEvent);
364
365    ev.type = evtype;
366    rc = EventToCore((InternalEvent *) &ev, &core, &count);
367    assert(rc == expected_rc);
368}
369
370static void
371dix_event_to_core_conversion(void)
372{
373    dix_event_to_core_fail(0, BadImplementation);
374    dix_event_to_core_fail(1, BadImplementation);
375    dix_event_to_core_fail(ET_ProximityOut + 1, BadImplementation);
376    dix_event_to_core_fail(ET_ProximityIn, BadMatch);
377    dix_event_to_core_fail(ET_ProximityOut, BadMatch);
378
379    dix_event_to_core(ET_KeyPress);
380    dix_event_to_core(ET_KeyRelease);
381    dix_event_to_core(ET_ButtonPress);
382    dix_event_to_core(ET_ButtonRelease);
383    dix_event_to_core(ET_Motion);
384}
385
386static void
387_dix_test_xi_convert(DeviceEvent *ev, int expected_rc, int expected_count)
388{
389    xEvent *xi;
390    int count = 0;
391    int rc;
392
393    rc = EventToXI((InternalEvent *) ev, &xi, &count);
394    assert(rc == expected_rc);
395    assert(count >= expected_count);
396    if (count > 0) {
397        deviceKeyButtonPointer *kbp = (deviceKeyButtonPointer *) xi;
398
399        assert(kbp->type == IEventBase + ev->type);
400        assert(kbp->detail == ev->detail.key);
401        assert(kbp->time == ev->time);
402        assert((kbp->deviceid & ~MORE_EVENTS) == ev->deviceid);
403        assert(kbp->root_x == ev->root_x);
404        assert(kbp->root_y == ev->root_y);
405        assert(kbp->state == ev->corestate);
406        assert(kbp->event_x == 0);
407        assert(kbp->event_y == 0);
408        assert(kbp->root == ev->root);
409        assert(kbp->event == 0);
410        assert(kbp->child == 0);
411        assert(kbp->same_screen == FALSE);
412
413        while (--count > 0) {
414            deviceValuator *v = (deviceValuator *) &xi[count];
415
416            assert(v->type == DeviceValuator);
417            assert(v->num_valuators <= 6);
418        }
419
420        free(xi);
421    }
422}
423
424/**
425 * This tests for internal event → XI1 event conversion
426 * - all conversions should generate the right XI event type
427 * - right number of events generated
428 * - extra events are valuators
429 */
430static void
431dix_event_to_xi1_conversion(void)
432{
433    DeviceEvent ev = { 0 };
434    int time;
435    int x, y;
436    int state;
437    int detail;
438    const int ROOT_WINDOW_ID = 0x100;
439    int deviceid;
440
441    IEventBase = 80;
442    DeviceValuator = IEventBase - 1;
443    DeviceKeyPress = IEventBase + ET_KeyPress;
444    DeviceKeyRelease = IEventBase + ET_KeyRelease;
445    DeviceButtonPress = IEventBase + ET_ButtonPress;
446    DeviceButtonRelease = IEventBase + ET_ButtonRelease;
447    DeviceMotionNotify = IEventBase + ET_Motion;
448    DeviceFocusIn = IEventBase + ET_FocusIn;
449    DeviceFocusOut = IEventBase + ET_FocusOut;
450    ProximityIn = IEventBase + ET_ProximityIn;
451    ProximityOut = IEventBase + ET_ProximityOut;
452
453    /* EventToXI callocs */
454    x = 0;
455    y = 0;
456    time = 12345;
457    state = 0;
458    detail = 0;
459    deviceid = 4;
460
461    ev.header = 0xFF;
462
463    ev.header = 0xFF;
464    ev.length = sizeof(DeviceEvent);
465    ev.time = time;
466    ev.root_y = x;
467    ev.root_x = y;
468    SetBit(ev.valuators.mask, 0);
469    SetBit(ev.valuators.mask, 1);
470    ev.root = ROOT_WINDOW_ID;
471    ev.corestate = state;
472    ev.detail.key = detail;
473    ev.deviceid = deviceid;
474
475    /* test all types for bad match */
476    ev.type = ET_KeyPress;
477    _dix_test_xi_convert(&ev, Success, 1);
478    ev.type = ET_KeyRelease;
479    _dix_test_xi_convert(&ev, Success, 1);
480    ev.type = ET_ButtonPress;
481    _dix_test_xi_convert(&ev, Success, 1);
482    ev.type = ET_ButtonRelease;
483    _dix_test_xi_convert(&ev, Success, 1);
484    ev.type = ET_Motion;
485    _dix_test_xi_convert(&ev, Success, 1);
486    ev.type = ET_ProximityIn;
487    _dix_test_xi_convert(&ev, Success, 1);
488    ev.type = ET_ProximityOut;
489    _dix_test_xi_convert(&ev, Success, 1);
490
491    /* No axes */
492    ClearBit(ev.valuators.mask, 0);
493    ClearBit(ev.valuators.mask, 1);
494    ev.type = ET_KeyPress;
495    _dix_test_xi_convert(&ev, Success, 1);
496    ev.type = ET_KeyRelease;
497    _dix_test_xi_convert(&ev, Success, 1);
498    ev.type = ET_ButtonPress;
499    _dix_test_xi_convert(&ev, Success, 1);
500    ev.type = ET_ButtonRelease;
501    _dix_test_xi_convert(&ev, Success, 1);
502    ev.type = ET_Motion;
503    _dix_test_xi_convert(&ev, BadMatch, 0);
504    ev.type = ET_ProximityIn;
505    _dix_test_xi_convert(&ev, BadMatch, 0);
506    ev.type = ET_ProximityOut;
507    _dix_test_xi_convert(&ev, BadMatch, 0);
508
509    /* more than 6 axes → 2 valuator events */
510    SetBit(ev.valuators.mask, 0);
511    SetBit(ev.valuators.mask, 1);
512    SetBit(ev.valuators.mask, 2);
513    SetBit(ev.valuators.mask, 3);
514    SetBit(ev.valuators.mask, 4);
515    SetBit(ev.valuators.mask, 5);
516    SetBit(ev.valuators.mask, 6);
517    ev.type = ET_KeyPress;
518    _dix_test_xi_convert(&ev, Success, 2);
519    ev.type = ET_KeyRelease;
520    _dix_test_xi_convert(&ev, Success, 2);
521    ev.type = ET_ButtonPress;
522    _dix_test_xi_convert(&ev, Success, 2);
523    ev.type = ET_ButtonRelease;
524    _dix_test_xi_convert(&ev, Success, 2);
525    ev.type = ET_Motion;
526    _dix_test_xi_convert(&ev, Success, 2);
527    ev.type = ET_ProximityIn;
528    _dix_test_xi_convert(&ev, Success, 2);
529    ev.type = ET_ProximityOut;
530    _dix_test_xi_convert(&ev, Success, 2);
531
532    /* keycode too high */
533    ev.type = ET_KeyPress;
534    ev.detail.key = 256;
535    _dix_test_xi_convert(&ev, Success, 0);
536
537    /* deviceid too high */
538    ev.type = ET_KeyPress;
539    ev.detail.key = 18;
540    ev.deviceid = 128;
541    _dix_test_xi_convert(&ev, Success, 0);
542}
543
544static void
545xi2_struct_sizes(void)
546{
547#define compare(req) \
548    assert(sizeof(req) == sz_##req);
549
550    compare(xXIQueryVersionReq);
551    compare(xXIWarpPointerReq);
552    compare(xXIChangeCursorReq);
553    compare(xXIChangeHierarchyReq);
554    compare(xXISetClientPointerReq);
555    compare(xXIGetClientPointerReq);
556    compare(xXISelectEventsReq);
557    compare(xXIQueryVersionReq);
558    compare(xXIQueryDeviceReq);
559    compare(xXISetFocusReq);
560    compare(xXIGetFocusReq);
561    compare(xXIGrabDeviceReq);
562    compare(xXIUngrabDeviceReq);
563    compare(xXIAllowEventsReq);
564    compare(xXIPassiveGrabDeviceReq);
565    compare(xXIPassiveUngrabDeviceReq);
566    compare(xXIListPropertiesReq);
567    compare(xXIChangePropertyReq);
568    compare(xXIDeletePropertyReq);
569    compare(xXIGetPropertyReq);
570    compare(xXIGetSelectedEventsReq);
571#undef compare
572}
573
574static void
575dix_grab_matching(void)
576{
577    DeviceIntRec xi_all_devices, xi_all_master_devices, dev1, dev2;
578    GrabRec a, b;
579    BOOL rc;
580
581    memset(&a, 0, sizeof(a));
582    memset(&b, 0, sizeof(b));
583
584    /* different grabtypes must fail */
585    a.grabtype = CORE;
586    b.grabtype = XI2;
587    rc = GrabMatchesSecond(&a, &b, FALSE);
588    assert(rc == FALSE);
589    rc = GrabMatchesSecond(&b, &a, FALSE);
590    assert(rc == FALSE);
591
592    a.grabtype = XI;
593    b.grabtype = XI2;
594    rc = GrabMatchesSecond(&a, &b, FALSE);
595    assert(rc == FALSE);
596    rc = GrabMatchesSecond(&b, &a, FALSE);
597    assert(rc == FALSE);
598
599    a.grabtype = XI;
600    b.grabtype = CORE;
601    rc = GrabMatchesSecond(&a, &b, FALSE);
602    assert(rc == FALSE);
603    rc = GrabMatchesSecond(&b, &a, FALSE);
604    assert(rc == FALSE);
605
606    /* XI2 grabs for different devices must fail, regardless of ignoreDevice
607     * XI2 grabs for master devices must fail against a slave */
608    memset(&xi_all_devices, 0, sizeof(DeviceIntRec));
609    memset(&xi_all_master_devices, 0, sizeof(DeviceIntRec));
610    memset(&dev1, 0, sizeof(DeviceIntRec));
611    memset(&dev2, 0, sizeof(DeviceIntRec));
612
613    xi_all_devices.id = XIAllDevices;
614    xi_all_master_devices.id = XIAllMasterDevices;
615    dev1.id = 10;
616    dev1.type = SLAVE;
617    dev2.id = 11;
618    dev2.type = SLAVE;
619
620    inputInfo.all_devices = &xi_all_devices;
621    inputInfo.all_master_devices = &xi_all_master_devices;
622    a.grabtype = XI2;
623    b.grabtype = XI2;
624    a.device = &dev1;
625    b.device = &dev2;
626
627    rc = GrabMatchesSecond(&a, &b, FALSE);
628    assert(rc == FALSE);
629
630    a.device = &dev2;
631    b.device = &dev1;
632    rc = GrabMatchesSecond(&a, &b, FALSE);
633    assert(rc == FALSE);
634    rc = GrabMatchesSecond(&a, &b, TRUE);
635    assert(rc == FALSE);
636
637    a.device = inputInfo.all_master_devices;
638    b.device = &dev1;
639    rc = GrabMatchesSecond(&a, &b, FALSE);
640    assert(rc == FALSE);
641    rc = GrabMatchesSecond(&a, &b, TRUE);
642    assert(rc == FALSE);
643
644    a.device = &dev1;
645    b.device = inputInfo.all_master_devices;
646    rc = GrabMatchesSecond(&a, &b, FALSE);
647    assert(rc == FALSE);
648    rc = GrabMatchesSecond(&a, &b, TRUE);
649    assert(rc == FALSE);
650
651    /* ignoreDevice FALSE must fail for different devices for CORE and XI */
652    a.grabtype = XI;
653    b.grabtype = XI;
654    a.device = &dev1;
655    b.device = &dev2;
656    a.modifierDevice = &dev1;
657    b.modifierDevice = &dev1;
658    rc = GrabMatchesSecond(&a, &b, FALSE);
659    assert(rc == FALSE);
660
661    a.grabtype = CORE;
662    b.grabtype = CORE;
663    a.device = &dev1;
664    b.device = &dev2;
665    a.modifierDevice = &dev1;
666    b.modifierDevice = &dev1;
667    rc = GrabMatchesSecond(&a, &b, FALSE);
668    assert(rc == FALSE);
669
670    /* ignoreDevice FALSE must fail for different modifier devices for CORE
671     * and XI */
672    a.grabtype = XI;
673    b.grabtype = XI;
674    a.device = &dev1;
675    b.device = &dev1;
676    a.modifierDevice = &dev1;
677    b.modifierDevice = &dev2;
678    rc = GrabMatchesSecond(&a, &b, FALSE);
679    assert(rc == FALSE);
680
681    a.grabtype = CORE;
682    b.grabtype = CORE;
683    a.device = &dev1;
684    b.device = &dev1;
685    a.modifierDevice = &dev1;
686    b.modifierDevice = &dev2;
687    rc = GrabMatchesSecond(&a, &b, FALSE);
688    assert(rc == FALSE);
689
690    /* different event type must fail */
691    a.grabtype = XI2;
692    b.grabtype = XI2;
693    a.device = &dev1;
694    b.device = &dev1;
695    a.modifierDevice = &dev1;
696    b.modifierDevice = &dev1;
697    a.type = XI_KeyPress;
698    b.type = XI_KeyRelease;
699    rc = GrabMatchesSecond(&a, &b, FALSE);
700    assert(rc == FALSE);
701    rc = GrabMatchesSecond(&a, &b, TRUE);
702    assert(rc == FALSE);
703
704    a.grabtype = CORE;
705    b.grabtype = CORE;
706    a.device = &dev1;
707    b.device = &dev1;
708    a.modifierDevice = &dev1;
709    b.modifierDevice = &dev1;
710    a.type = XI_KeyPress;
711    b.type = XI_KeyRelease;
712    rc = GrabMatchesSecond(&a, &b, FALSE);
713    assert(rc == FALSE);
714    rc = GrabMatchesSecond(&a, &b, TRUE);
715    assert(rc == FALSE);
716
717    a.grabtype = XI;
718    b.grabtype = XI;
719    a.device = &dev1;
720    b.device = &dev1;
721    a.modifierDevice = &dev1;
722    b.modifierDevice = &dev1;
723    a.type = XI_KeyPress;
724    b.type = XI_KeyRelease;
725    rc = GrabMatchesSecond(&a, &b, FALSE);
726    assert(rc == FALSE);
727    rc = GrabMatchesSecond(&a, &b, TRUE);
728    assert(rc == FALSE);
729
730    /* different modifiers must fail */
731    a.grabtype = XI2;
732    b.grabtype = XI2;
733    a.device = &dev1;
734    b.device = &dev1;
735    a.modifierDevice = &dev1;
736    b.modifierDevice = &dev1;
737    a.type = XI_KeyPress;
738    b.type = XI_KeyPress;
739    a.modifiersDetail.exact = 1;
740    b.modifiersDetail.exact = 2;
741    rc = GrabMatchesSecond(&a, &b, FALSE);
742    assert(rc == FALSE);
743    rc = GrabMatchesSecond(&b, &a, FALSE);
744    assert(rc == FALSE);
745
746    a.grabtype = CORE;
747    b.grabtype = CORE;
748    rc = GrabMatchesSecond(&a, &b, FALSE);
749    assert(rc == FALSE);
750    rc = GrabMatchesSecond(&b, &a, FALSE);
751    assert(rc == FALSE);
752
753    a.grabtype = XI;
754    b.grabtype = XI;
755    rc = GrabMatchesSecond(&a, &b, FALSE);
756    assert(rc == FALSE);
757    rc = GrabMatchesSecond(&b, &a, FALSE);
758    assert(rc == FALSE);
759
760    /* AnyModifier must fail for XI2 */
761    a.grabtype = XI2;
762    b.grabtype = XI2;
763    a.modifiersDetail.exact = AnyModifier;
764    b.modifiersDetail.exact = 1;
765    rc = GrabMatchesSecond(&a, &b, FALSE);
766    assert(rc == FALSE);
767    rc = GrabMatchesSecond(&b, &a, FALSE);
768    assert(rc == FALSE);
769
770    /* XIAnyModifier must fail for CORE and XI */
771    a.grabtype = XI;
772    b.grabtype = XI;
773    a.modifiersDetail.exact = XIAnyModifier;
774    b.modifiersDetail.exact = 1;
775    rc = GrabMatchesSecond(&a, &b, FALSE);
776    assert(rc == FALSE);
777    rc = GrabMatchesSecond(&b, &a, FALSE);
778    assert(rc == FALSE);
779
780    a.grabtype = CORE;
781    b.grabtype = CORE;
782    a.modifiersDetail.exact = XIAnyModifier;
783    b.modifiersDetail.exact = 1;
784    rc = GrabMatchesSecond(&a, &b, FALSE);
785    assert(rc == FALSE);
786    rc = GrabMatchesSecond(&b, &a, FALSE);
787    assert(rc == FALSE);
788
789    /* different detail must fail */
790    a.grabtype = XI2;
791    b.grabtype = XI2;
792    a.detail.exact = 1;
793    b.detail.exact = 2;
794    a.modifiersDetail.exact = 1;
795    b.modifiersDetail.exact = 1;
796    rc = GrabMatchesSecond(&a, &b, FALSE);
797    assert(rc == FALSE);
798    rc = GrabMatchesSecond(&b, &a, FALSE);
799    assert(rc == FALSE);
800
801    a.grabtype = XI;
802    b.grabtype = XI;
803    rc = GrabMatchesSecond(&a, &b, FALSE);
804    assert(rc == FALSE);
805    rc = GrabMatchesSecond(&b, &a, FALSE);
806    assert(rc == FALSE);
807
808    a.grabtype = CORE;
809    b.grabtype = CORE;
810    rc = GrabMatchesSecond(&a, &b, FALSE);
811    assert(rc == FALSE);
812    rc = GrabMatchesSecond(&b, &a, FALSE);
813    assert(rc == FALSE);
814
815    /* detail of AnyModifier must fail */
816    a.grabtype = XI2;
817    b.grabtype = XI2;
818    a.detail.exact = AnyModifier;
819    b.detail.exact = 1;
820    a.modifiersDetail.exact = 1;
821    b.modifiersDetail.exact = 1;
822    rc = GrabMatchesSecond(&a, &b, FALSE);
823    assert(rc == FALSE);
824    rc = GrabMatchesSecond(&b, &a, FALSE);
825    assert(rc == FALSE);
826
827    a.grabtype = CORE;
828    b.grabtype = CORE;
829    rc = GrabMatchesSecond(&a, &b, FALSE);
830    assert(rc == FALSE);
831    rc = GrabMatchesSecond(&b, &a, FALSE);
832    assert(rc == FALSE);
833
834    a.grabtype = XI;
835    b.grabtype = XI;
836    rc = GrabMatchesSecond(&a, &b, FALSE);
837    assert(rc == FALSE);
838    rc = GrabMatchesSecond(&b, &a, FALSE);
839    assert(rc == FALSE);
840
841    /* detail of XIAnyModifier must fail */
842    a.grabtype = XI2;
843    b.grabtype = XI2;
844    a.detail.exact = XIAnyModifier;
845    b.detail.exact = 1;
846    a.modifiersDetail.exact = 1;
847    b.modifiersDetail.exact = 1;
848    rc = GrabMatchesSecond(&a, &b, FALSE);
849    assert(rc == FALSE);
850    rc = GrabMatchesSecond(&b, &a, FALSE);
851    assert(rc == FALSE);
852
853    a.grabtype = CORE;
854    b.grabtype = CORE;
855    rc = GrabMatchesSecond(&a, &b, FALSE);
856    assert(rc == FALSE);
857    rc = GrabMatchesSecond(&b, &a, FALSE);
858    assert(rc == FALSE);
859
860    a.grabtype = XI;
861    b.grabtype = XI;
862    rc = GrabMatchesSecond(&a, &b, FALSE);
863    assert(rc == FALSE);
864    rc = GrabMatchesSecond(&b, &a, FALSE);
865    assert(rc == FALSE);
866
867    /* XIAnyModifier or AnyModifer must succeed */
868    a.grabtype = XI2;
869    b.grabtype = XI2;
870    a.detail.exact = 1;
871    b.detail.exact = 1;
872    a.modifiersDetail.exact = XIAnyModifier;
873    b.modifiersDetail.exact = 1;
874    rc = GrabMatchesSecond(&a, &b, FALSE);
875    assert(rc == TRUE);
876    rc = GrabMatchesSecond(&b, &a, FALSE);
877    assert(rc == TRUE);
878
879    a.grabtype = CORE;
880    b.grabtype = CORE;
881    a.detail.exact = 1;
882    b.detail.exact = 1;
883    a.modifiersDetail.exact = AnyModifier;
884    b.modifiersDetail.exact = 1;
885    rc = GrabMatchesSecond(&a, &b, FALSE);
886    assert(rc == TRUE);
887    rc = GrabMatchesSecond(&b, &a, FALSE);
888    assert(rc == TRUE);
889
890    a.grabtype = XI;
891    b.grabtype = XI;
892    a.detail.exact = 1;
893    b.detail.exact = 1;
894    a.modifiersDetail.exact = AnyModifier;
895    b.modifiersDetail.exact = 1;
896    rc = GrabMatchesSecond(&a, &b, FALSE);
897    assert(rc == TRUE);
898    rc = GrabMatchesSecond(&b, &a, FALSE);
899    assert(rc == TRUE);
900
901    /* AnyKey or XIAnyKeycode must succeed */
902    a.grabtype = XI2;
903    b.grabtype = XI2;
904    a.detail.exact = XIAnyKeycode;
905    b.detail.exact = 1;
906    a.modifiersDetail.exact = 1;
907    b.modifiersDetail.exact = 1;
908    rc = GrabMatchesSecond(&a, &b, FALSE);
909    assert(rc == TRUE);
910    rc = GrabMatchesSecond(&b, &a, FALSE);
911    assert(rc == TRUE);
912
913    a.grabtype = CORE;
914    b.grabtype = CORE;
915    a.detail.exact = AnyKey;
916    b.detail.exact = 1;
917    a.modifiersDetail.exact = 1;
918    b.modifiersDetail.exact = 1;
919    rc = GrabMatchesSecond(&a, &b, FALSE);
920    assert(rc == TRUE);
921    rc = GrabMatchesSecond(&b, &a, FALSE);
922    assert(rc == TRUE);
923
924    a.grabtype = XI;
925    b.grabtype = XI;
926    a.detail.exact = AnyKey;
927    b.detail.exact = 1;
928    a.modifiersDetail.exact = 1;
929    b.modifiersDetail.exact = 1;
930    rc = GrabMatchesSecond(&a, &b, FALSE);
931    assert(rc == TRUE);
932    rc = GrabMatchesSecond(&b, &a, FALSE);
933    assert(rc == TRUE);
934}
935
936static void
937test_bits_to_byte(int i)
938{
939    int expected_bytes;
940
941    expected_bytes = (i + 7) / 8;
942
943    assert(bits_to_bytes(i) >= i / 8);
944    assert((bits_to_bytes(i) * 8) - i <= 7);
945    assert(expected_bytes == bits_to_bytes(i));
946}
947
948static void
949test_bytes_to_int32(int i)
950{
951    int expected_4byte;
952
953    expected_4byte = (i + 3) / 4;
954
955    assert(bytes_to_int32(i) <= i);
956    assert((bytes_to_int32(i) * 4) - i <= 3);
957    assert(expected_4byte == bytes_to_int32(i));
958}
959
960static void
961test_pad_to_int32(int i)
962{
963    int expected_bytes;
964
965    expected_bytes = ((i + 3) / 4) * 4;
966
967    assert(pad_to_int32(i) >= i);
968    assert(pad_to_int32(i) - i <= 3);
969    assert(expected_bytes == pad_to_int32(i));
970}
971
972static void
973test_padding_for_int32(int i)
974{
975    static const int padlength[4] = { 0, 3, 2, 1 };
976    int expected_bytes = (((i + 3) / 4) * 4) - i;
977
978    assert(padding_for_int32(i) >= 0);
979    assert(padding_for_int32(i) <= 3);
980    assert(padding_for_int32(i) == expected_bytes);
981    assert(padding_for_int32(i) == padlength[i & 3]);
982    assert((padding_for_int32(i) + i) == pad_to_int32(i));
983}
984
985static void
986include_byte_padding_macros(void)
987{
988    printf("Testing bits_to_bytes()\n");
989
990    /* the macros don't provide overflow protection */
991    test_bits_to_byte(0);
992    test_bits_to_byte(1);
993    test_bits_to_byte(2);
994    test_bits_to_byte(7);
995    test_bits_to_byte(8);
996    test_bits_to_byte(0xFF);
997    test_bits_to_byte(0x100);
998    test_bits_to_byte(INT_MAX - 9);
999    test_bits_to_byte(INT_MAX - 8);
1000
1001    printf("Testing bytes_to_int32()\n");
1002
1003    test_bytes_to_int32(0);
1004    test_bytes_to_int32(1);
1005    test_bytes_to_int32(2);
1006    test_bytes_to_int32(7);
1007    test_bytes_to_int32(8);
1008    test_bytes_to_int32(0xFF);
1009    test_bytes_to_int32(0x100);
1010    test_bytes_to_int32(0xFFFF);
1011    test_bytes_to_int32(0x10000);
1012    test_bytes_to_int32(0xFFFFFF);
1013    test_bytes_to_int32(0x1000000);
1014    test_bytes_to_int32(INT_MAX - 4);
1015    test_bytes_to_int32(INT_MAX - 3);
1016
1017    printf("Testing pad_to_int32()\n");
1018
1019    test_pad_to_int32(0);
1020    test_pad_to_int32(1);
1021    test_pad_to_int32(2);
1022    test_pad_to_int32(3);
1023    test_pad_to_int32(7);
1024    test_pad_to_int32(8);
1025    test_pad_to_int32(0xFF);
1026    test_pad_to_int32(0x100);
1027    test_pad_to_int32(0xFFFF);
1028    test_pad_to_int32(0x10000);
1029    test_pad_to_int32(0xFFFFFF);
1030    test_pad_to_int32(0x1000000);
1031    test_pad_to_int32(INT_MAX - 4);
1032    test_pad_to_int32(INT_MAX - 3);
1033
1034    printf("Testing padding_for_int32()\n");
1035
1036    test_padding_for_int32(0);
1037    test_padding_for_int32(1);
1038    test_padding_for_int32(2);
1039    test_padding_for_int32(3);
1040    test_padding_for_int32(7);
1041    test_padding_for_int32(8);
1042    test_padding_for_int32(0xFF);
1043    test_padding_for_int32(0x100);
1044    test_padding_for_int32(0xFFFF);
1045    test_padding_for_int32(0x10000);
1046    test_padding_for_int32(0xFFFFFF);
1047    test_padding_for_int32(0x1000000);
1048    test_padding_for_int32(INT_MAX - 4);
1049    test_padding_for_int32(INT_MAX - 3);
1050}
1051
1052static void
1053xi_unregister_handlers(void)
1054{
1055    DeviceIntRec dev;
1056    int handler;
1057
1058    memset(&dev, 0, sizeof(dev));
1059
1060    handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
1061    assert(handler == 1);
1062    handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
1063    assert(handler == 2);
1064    handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
1065    assert(handler == 3);
1066
1067    printf("Unlinking from front.\n");
1068
1069    XIUnregisterPropertyHandler(&dev, 4);       /* NOOP */
1070    assert(dev.properties.handlers->id == 3);
1071    XIUnregisterPropertyHandler(&dev, 3);
1072    assert(dev.properties.handlers->id == 2);
1073    XIUnregisterPropertyHandler(&dev, 2);
1074    assert(dev.properties.handlers->id == 1);
1075    XIUnregisterPropertyHandler(&dev, 1);
1076    assert(dev.properties.handlers == NULL);
1077
1078    handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
1079    assert(handler == 4);
1080    handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
1081    assert(handler == 5);
1082    handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
1083    assert(handler == 6);
1084    XIUnregisterPropertyHandler(&dev, 3);       /* NOOP */
1085    assert(dev.properties.handlers->next->next->next == NULL);
1086    XIUnregisterPropertyHandler(&dev, 4);
1087    assert(dev.properties.handlers->next->next == NULL);
1088    XIUnregisterPropertyHandler(&dev, 5);
1089    assert(dev.properties.handlers->next == NULL);
1090    XIUnregisterPropertyHandler(&dev, 6);
1091    assert(dev.properties.handlers == NULL);
1092
1093    handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
1094    assert(handler == 7);
1095    handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
1096    assert(handler == 8);
1097    handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
1098    assert(handler == 9);
1099
1100    XIDeleteAllDeviceProperties(&dev);
1101    assert(dev.properties.handlers == NULL);
1102    XIUnregisterPropertyHandler(&dev, 7);       /* NOOP */
1103
1104}
1105
1106static void
1107cmp_attr_fields(InputAttributes * attr1, InputAttributes * attr2)
1108{
1109    char **tags1, **tags2;
1110
1111    assert(attr1);
1112    assert(attr2);
1113    assert(attr1 != attr2);
1114    assert(attr1->flags == attr2->flags);
1115
1116    if (attr1->product != NULL) {
1117        assert(attr1->product != attr2->product);
1118        assert(strcmp(attr1->product, attr2->product) == 0);
1119    }
1120    else
1121        assert(attr2->product == NULL);
1122
1123    if (attr1->vendor != NULL) {
1124        assert(attr1->vendor != attr2->vendor);
1125        assert(strcmp(attr1->vendor, attr2->vendor) == 0);
1126    }
1127    else
1128        assert(attr2->vendor == NULL);
1129
1130    if (attr1->device != NULL) {
1131        assert(attr1->device != attr2->device);
1132        assert(strcmp(attr1->device, attr2->device) == 0);
1133    }
1134    else
1135        assert(attr2->device == NULL);
1136
1137    if (attr1->pnp_id != NULL) {
1138        assert(attr1->pnp_id != attr2->pnp_id);
1139        assert(strcmp(attr1->pnp_id, attr2->pnp_id) == 0);
1140    }
1141    else
1142        assert(attr2->pnp_id == NULL);
1143
1144    if (attr1->usb_id != NULL) {
1145        assert(attr1->usb_id != attr2->usb_id);
1146        assert(strcmp(attr1->usb_id, attr2->usb_id) == 0);
1147    }
1148    else
1149        assert(attr2->usb_id == NULL);
1150
1151    tags1 = attr1->tags;
1152    tags2 = attr2->tags;
1153
1154    /* if we don't have any tags, skip the tag checking bits */
1155    if (!tags1) {
1156        assert(!tags2);
1157        return;
1158    }
1159
1160    /* Don't lug around empty arrays */
1161    assert(*tags1);
1162    assert(*tags2);
1163
1164    /* check for identical content, but duplicated */
1165    while (*tags1) {
1166        assert(*tags1 != *tags2);
1167        assert(strcmp(*tags1, *tags2) == 0);
1168        tags1++;
1169        tags2++;
1170    }
1171
1172    /* ensure tags1 and tags2 have the same no of elements */
1173    assert(!*tags2);
1174
1175    /* check for not sharing memory */
1176    tags1 = attr1->tags;
1177    while (*tags1) {
1178        tags2 = attr2->tags;
1179        while (*tags2)
1180            assert(*tags1 != *tags2++);
1181
1182        tags1++;
1183    }
1184}
1185
1186static void
1187dix_input_attributes(void)
1188{
1189    InputAttributes *orig;
1190    InputAttributes *new;
1191
1192    new = DuplicateInputAttributes(NULL);
1193    assert(!new);
1194
1195    orig = calloc(1, sizeof(InputAttributes));
1196    assert(orig);
1197
1198    new = DuplicateInputAttributes(orig);
1199    assert(memcmp(orig, new, sizeof(InputAttributes)) == 0);
1200
1201    orig->product = xnfstrdup("product name");
1202    new = DuplicateInputAttributes(orig);
1203    cmp_attr_fields(orig, new);
1204    FreeInputAttributes(new);
1205
1206    orig->vendor = xnfstrdup("vendor name");
1207    new = DuplicateInputAttributes(orig);
1208    cmp_attr_fields(orig, new);
1209    FreeInputAttributes(new);
1210
1211    orig->device = xnfstrdup("device path");
1212    new = DuplicateInputAttributes(orig);
1213    cmp_attr_fields(orig, new);
1214    FreeInputAttributes(new);
1215
1216    orig->pnp_id = xnfstrdup("PnPID");
1217    new = DuplicateInputAttributes(orig);
1218    cmp_attr_fields(orig, new);
1219    FreeInputAttributes(new);
1220
1221    orig->usb_id = xnfstrdup("USBID");
1222    new = DuplicateInputAttributes(orig);
1223    cmp_attr_fields(orig, new);
1224    FreeInputAttributes(new);
1225
1226    orig->flags = 0xF0;
1227    new = DuplicateInputAttributes(orig);
1228    cmp_attr_fields(orig, new);
1229    FreeInputAttributes(new);
1230
1231    orig->tags = xstrtokenize("tag1 tag2 tag3", " ");
1232    new = DuplicateInputAttributes(orig);
1233    cmp_attr_fields(orig, new);
1234    FreeInputAttributes(new);
1235
1236    FreeInputAttributes(orig);
1237}
1238
1239static void
1240dix_input_valuator_masks(void)
1241{
1242    ValuatorMask *mask = NULL, *copy;
1243    int nvaluators = MAX_VALUATORS;
1244    double valuators[nvaluators];
1245    int val_ranged[nvaluators];
1246    int i;
1247    int first_val, num_vals;
1248
1249    for (i = 0; i < nvaluators; i++) {
1250        valuators[i] = i + 0.5;
1251        val_ranged[i] = i;
1252    }
1253
1254    mask = valuator_mask_new(nvaluators);
1255    assert(mask != NULL);
1256    assert(valuator_mask_size(mask) == 0);
1257    assert(valuator_mask_num_valuators(mask) == 0);
1258
1259    for (i = 0; i < nvaluators; i++) {
1260        assert(!valuator_mask_isset(mask, i));
1261        valuator_mask_set_double(mask, i, valuators[i]);
1262        assert(valuator_mask_isset(mask, i));
1263        assert(valuator_mask_get(mask, i) == trunc(valuators[i]));
1264        assert(valuator_mask_get_double(mask, i) == valuators[i]);
1265        assert(valuator_mask_size(mask) == i + 1);
1266        assert(valuator_mask_num_valuators(mask) == i + 1);
1267    }
1268
1269    for (i = 0; i < nvaluators; i++) {
1270        assert(valuator_mask_isset(mask, i));
1271        valuator_mask_unset(mask, i);
1272        /* we're removing valuators from the front, so size should stay the
1273         * same until the last bit is removed */
1274        if (i < nvaluators - 1)
1275            assert(valuator_mask_size(mask) == nvaluators);
1276        assert(!valuator_mask_isset(mask, i));
1277    }
1278
1279    assert(valuator_mask_size(mask) == 0);
1280    valuator_mask_zero(mask);
1281    assert(valuator_mask_size(mask) == 0);
1282    assert(valuator_mask_num_valuators(mask) == 0);
1283    for (i = 0; i < nvaluators; i++)
1284        assert(!valuator_mask_isset(mask, i));
1285
1286    first_val = 5;
1287    num_vals = 6;
1288
1289    valuator_mask_set_range(mask, first_val, num_vals, val_ranged);
1290    assert(valuator_mask_size(mask) == first_val + num_vals);
1291    assert(valuator_mask_num_valuators(mask) == num_vals);
1292    for (i = 0; i < nvaluators; i++) {
1293        double val;
1294
1295        if (i < first_val || i >= first_val + num_vals) {
1296            assert(!valuator_mask_isset(mask, i));
1297            assert(!valuator_mask_fetch_double(mask, i, &val));
1298        }
1299        else {
1300            assert(valuator_mask_isset(mask, i));
1301            assert(valuator_mask_get(mask, i) == val_ranged[i - first_val]);
1302            assert(valuator_mask_get_double(mask, i) ==
1303                   val_ranged[i - first_val]);
1304            assert(valuator_mask_fetch_double(mask, i, &val));
1305            assert(val_ranged[i - first_val] == val);
1306        }
1307    }
1308
1309    copy = valuator_mask_new(nvaluators);
1310    valuator_mask_copy(copy, mask);
1311    assert(mask != copy);
1312    assert(valuator_mask_size(mask) == valuator_mask_size(copy));
1313    assert(valuator_mask_num_valuators(mask) ==
1314           valuator_mask_num_valuators(copy));
1315
1316    for (i = 0; i < nvaluators; i++) {
1317        double a, b;
1318
1319        assert(valuator_mask_isset(mask, i) == valuator_mask_isset(copy, i));
1320
1321        if (!valuator_mask_isset(mask, i))
1322            continue;
1323
1324        assert(valuator_mask_get(mask, i) == valuator_mask_get(copy, i));
1325        assert(valuator_mask_get_double(mask, i) ==
1326               valuator_mask_get_double(copy, i));
1327        assert(valuator_mask_fetch_double(mask, i, &a));
1328        assert(valuator_mask_fetch_double(copy, i, &b));
1329        assert(a == b);
1330    }
1331
1332    valuator_mask_free(&mask);
1333    assert(mask == NULL);
1334}
1335
1336static void
1337dix_valuator_mode(void)
1338{
1339    DeviceIntRec dev;
1340    const int num_axes = MAX_VALUATORS;
1341    int i;
1342    Atom atoms[MAX_VALUATORS] = { 0 };
1343
1344    memset(&dev, 0, sizeof(DeviceIntRec));
1345    dev.type = MASTER_POINTER;  /* claim it's a master to stop ptracccel */
1346
1347    assert(InitValuatorClassDeviceStruct(NULL, 0, atoms, 0, 0) == FALSE);
1348    assert(InitValuatorClassDeviceStruct(&dev, num_axes, atoms, 0, Absolute));
1349
1350    for (i = 0; i < num_axes; i++) {
1351        assert(valuator_get_mode(&dev, i) == Absolute);
1352        valuator_set_mode(&dev, i, Relative);
1353        assert(dev.valuator->axes[i].mode == Relative);
1354        assert(valuator_get_mode(&dev, i) == Relative);
1355    }
1356
1357    valuator_set_mode(&dev, VALUATOR_MODE_ALL_AXES, Absolute);
1358    for (i = 0; i < num_axes; i++)
1359        assert(valuator_get_mode(&dev, i) == Absolute);
1360
1361    valuator_set_mode(&dev, VALUATOR_MODE_ALL_AXES, Relative);
1362    for (i = 0; i < num_axes; i++)
1363        assert(valuator_get_mode(&dev, i) == Relative);
1364}
1365
1366static void
1367dix_input_valuator_masks_unaccel(void)
1368{
1369    ValuatorMask *mask = NULL;
1370    double x, ux;
1371
1372    /* set mask normally */
1373    mask = valuator_mask_new(MAX_VALUATORS);
1374    assert(!valuator_mask_has_unaccelerated(mask));
1375    valuator_mask_set_double(mask, 0, 1.0);
1376    assert(!valuator_mask_has_unaccelerated(mask));
1377    valuator_mask_unset(mask, 0);
1378    assert(!valuator_mask_has_unaccelerated(mask));
1379
1380    /* all unset, now set accel mask */
1381    valuator_mask_set_unaccelerated(mask, 0, 1.0, 2.0);
1382    assert(valuator_mask_has_unaccelerated(mask));
1383    assert(valuator_mask_isset(mask, 0));
1384    assert(!valuator_mask_isset(mask, 1));
1385    assert(valuator_mask_get_accelerated(mask, 0) ==  1.0);
1386    assert(valuator_mask_get_unaccelerated(mask, 0) ==  2.0);
1387    assert(valuator_mask_fetch_unaccelerated(mask, 0, &x, &ux));
1388    assert(x == 1.0);
1389    assert(ux == 2.0);
1390    x = 0xff;
1391    ux = 0xfe;
1392    assert(!valuator_mask_fetch_unaccelerated(mask, 1, &x, &ux));
1393    assert(x == 0xff);
1394    assert(ux == 0xfe);
1395
1396    /* all unset, now set normally again */
1397    valuator_mask_unset(mask, 0);
1398    assert(!valuator_mask_has_unaccelerated(mask));
1399    assert(!valuator_mask_isset(mask, 0));
1400    valuator_mask_set_double(mask, 0, 1.0);
1401    assert(!valuator_mask_has_unaccelerated(mask));
1402    valuator_mask_unset(mask, 0);
1403    assert(!valuator_mask_has_unaccelerated(mask));
1404
1405    valuator_mask_zero(mask);
1406    assert(!valuator_mask_has_unaccelerated(mask));
1407
1408    valuator_mask_set_unaccelerated(mask, 0, 1.0, 2.0);
1409    valuator_mask_set_unaccelerated(mask, 1, 3.0, 4.5);
1410    assert(valuator_mask_isset(mask, 0));
1411    assert(valuator_mask_isset(mask, 1));
1412    assert(!valuator_mask_isset(mask, 2));
1413    assert(valuator_mask_has_unaccelerated(mask));
1414    assert(valuator_mask_get_accelerated(mask, 0) == 1.0);
1415    assert(valuator_mask_get_accelerated(mask, 1) == 3.0);
1416    assert(valuator_mask_get_unaccelerated(mask, 0) == 2.0);
1417    assert(valuator_mask_get_unaccelerated(mask, 1) == 4.5);
1418    assert(valuator_mask_fetch_unaccelerated(mask, 0, &x, &ux));
1419    assert(x == 1.0);
1420    assert(ux == 2.0);
1421    assert(valuator_mask_fetch_unaccelerated(mask, 1, &x, &ux));
1422    assert(x == 3.0);
1423    assert(ux == 4.5);
1424
1425    valuator_mask_free(&mask);
1426}
1427
1428static void
1429include_bit_test_macros(void)
1430{
1431    uint8_t mask[9] = { 0 };
1432    int i;
1433
1434    for (i = 0; i < ARRAY_SIZE(mask); i++) {
1435        assert(BitIsOn(mask, i) == 0);
1436        SetBit(mask, i);
1437        assert(BitIsOn(mask, i) == 1);
1438        assert(! !(mask[i / 8] & (1 << (i % 8))));
1439        assert(CountBits(mask, sizeof(mask)) == 1);
1440        ClearBit(mask, i);
1441        assert(BitIsOn(mask, i) == 0);
1442    }
1443}
1444
1445/**
1446 * Ensure that val->axisVal and val->axes are aligned on doubles.
1447 */
1448static void
1449dix_valuator_alloc(void)
1450{
1451    ValuatorClassPtr v = NULL;
1452    int num_axes = 0;
1453
1454    while (num_axes < 5) {
1455        v = AllocValuatorClass(v, num_axes);
1456
1457        assert(v);
1458        assert(v->numAxes == num_axes);
1459#if !defined(__i386__) && !defined(__m68k__) && !defined(__sh__)
1460        /* must be double-aligned on 64 bit */
1461        assert(offsetof(struct _ValuatorClassRec, axisVal) % sizeof(double) == 0);
1462        assert(offsetof(struct _ValuatorClassRec, axes) % sizeof(double) == 0);
1463#endif
1464        num_axes++;
1465    }
1466
1467    free(v);
1468}
1469
1470static void
1471dix_get_master(void)
1472{
1473    DeviceIntRec vcp, vck;
1474    DeviceIntRec ptr, kbd;
1475    DeviceIntRec floating;
1476    SpriteInfoRec vcp_sprite, vck_sprite;
1477    SpriteInfoRec ptr_sprite, kbd_sprite;
1478    SpriteInfoRec floating_sprite;
1479
1480    memset(&vcp, 0, sizeof(vcp));
1481    memset(&vck, 0, sizeof(vck));
1482    memset(&ptr, 0, sizeof(ptr));
1483    memset(&kbd, 0, sizeof(kbd));
1484    memset(&floating, 0, sizeof(floating));
1485
1486    memset(&vcp_sprite, 0, sizeof(vcp_sprite));
1487    memset(&vck_sprite, 0, sizeof(vck_sprite));
1488    memset(&ptr_sprite, 0, sizeof(ptr_sprite));
1489    memset(&kbd_sprite, 0, sizeof(kbd_sprite));
1490    memset(&floating_sprite, 0, sizeof(floating_sprite));
1491
1492    vcp.type = MASTER_POINTER;
1493    vck.type = MASTER_KEYBOARD;
1494    ptr.type = SLAVE;
1495    kbd.type = SLAVE;
1496    floating.type = SLAVE;
1497
1498    vcp.spriteInfo = &vcp_sprite;
1499    vck.spriteInfo = &vck_sprite;
1500    ptr.spriteInfo = &ptr_sprite;
1501    kbd.spriteInfo = &kbd_sprite;
1502    floating.spriteInfo = &floating_sprite;
1503
1504    vcp_sprite.paired = &vck;
1505    vck_sprite.paired = &vcp;
1506    ptr_sprite.paired = &vcp;
1507    kbd_sprite.paired = &vck;
1508    floating_sprite.paired = &floating;
1509
1510    vcp_sprite.spriteOwner = TRUE;
1511    floating_sprite.spriteOwner = TRUE;
1512
1513    ptr.master = &vcp;
1514    kbd.master = &vck;
1515
1516    assert(GetPairedDevice(&vcp) == &vck);
1517    assert(GetPairedDevice(&vck) == &vcp);
1518    assert(GetMaster(&ptr, MASTER_POINTER) == &vcp);
1519    assert(GetMaster(&ptr, MASTER_KEYBOARD) == &vck);
1520    assert(GetMaster(&kbd, MASTER_POINTER) == &vcp);
1521    assert(GetMaster(&kbd, MASTER_KEYBOARD) == &vck);
1522    assert(GetMaster(&ptr, MASTER_ATTACHED) == &vcp);
1523    assert(GetMaster(&kbd, MASTER_ATTACHED) == &vck);
1524
1525    assert(GetPairedDevice(&floating) == &floating);
1526    assert(GetMaster(&floating, MASTER_POINTER) == NULL);
1527    assert(GetMaster(&floating, MASTER_KEYBOARD) == NULL);
1528    assert(GetMaster(&floating, MASTER_ATTACHED) == NULL);
1529
1530    assert(GetMaster(&vcp, POINTER_OR_FLOAT) == &vcp);
1531    assert(GetMaster(&vck, POINTER_OR_FLOAT) == &vcp);
1532    assert(GetMaster(&ptr, POINTER_OR_FLOAT) == &vcp);
1533    assert(GetMaster(&kbd, POINTER_OR_FLOAT) == &vcp);
1534
1535    assert(GetMaster(&vcp, KEYBOARD_OR_FLOAT) == &vck);
1536    assert(GetMaster(&vck, KEYBOARD_OR_FLOAT) == &vck);
1537    assert(GetMaster(&ptr, KEYBOARD_OR_FLOAT) == &vck);
1538    assert(GetMaster(&kbd, KEYBOARD_OR_FLOAT) == &vck);
1539
1540    assert(GetMaster(&floating, KEYBOARD_OR_FLOAT) == &floating);
1541    assert(GetMaster(&floating, POINTER_OR_FLOAT) == &floating);
1542}
1543
1544static void
1545input_option_test(void)
1546{
1547    InputOption *list = NULL;
1548    InputOption *opt;
1549    const char *val;
1550
1551    printf("Testing input_option list interface\n");
1552
1553    list = input_option_new(list, "key", "value");
1554    assert(list);
1555    opt = input_option_find(list, "key");
1556    val = input_option_get_value(opt);
1557    assert(strcmp(val, "value") == 0);
1558
1559    list = input_option_new(list, "2", "v2");
1560    opt = input_option_find(list, "key");
1561    val = input_option_get_value(opt);
1562    assert(strcmp(val, "value") == 0);
1563
1564    opt = input_option_find(list, "2");
1565    val = input_option_get_value(opt);
1566    assert(strcmp(val, "v2") == 0);
1567
1568    list = input_option_new(list, "3", "v3");
1569
1570    /* search, delete */
1571    opt = input_option_find(list, "key");
1572    val = input_option_get_value(opt);
1573    assert(strcmp(val, "value") == 0);
1574    list = input_option_free_element(list, "key");
1575    opt = input_option_find(list, "key");
1576    assert(opt == NULL);
1577
1578    opt = input_option_find(list, "2");
1579    val = input_option_get_value(opt);
1580    assert(strcmp(val, "v2") == 0);
1581    list = input_option_free_element(list, "2");
1582    opt = input_option_find(list, "2");
1583    assert(opt == NULL);
1584
1585    opt = input_option_find(list, "3");
1586    val = input_option_get_value(opt);
1587    assert(strcmp(val, "v3") == 0);
1588    list = input_option_free_element(list, "3");
1589    opt = input_option_find(list, "3");
1590    assert(opt == NULL);
1591
1592    /* list deletion */
1593    list = input_option_new(list, "1", "v3");
1594    list = input_option_new(list, "2", "v3");
1595    list = input_option_new(list, "3", "v3");
1596    input_option_free_list(&list);
1597
1598    assert(list == NULL);
1599
1600    list = input_option_new(list, "1", "v1");
1601    list = input_option_new(list, "2", "v2");
1602    list = input_option_new(list, "3", "v3");
1603
1604    /* value replacement */
1605    opt = input_option_find(list, "2");
1606    val = input_option_get_value(opt);
1607    assert(strcmp(val, "v2") == 0);
1608    input_option_set_value(opt, "foo");
1609    val = input_option_get_value(opt);
1610    assert(strcmp(val, "foo") == 0);
1611    opt = input_option_find(list, "2");
1612    val = input_option_get_value(opt);
1613    assert(strcmp(val, "foo") == 0);
1614
1615    /* key replacement */
1616    input_option_set_key(opt, "bar");
1617    val = input_option_get_key(opt);
1618    assert(strcmp(val, "bar") == 0);
1619    opt = input_option_find(list, "bar");
1620    val = input_option_get_value(opt);
1621    assert(strcmp(val, "foo") == 0);
1622
1623    /* value replacement in input_option_new */
1624    list = input_option_new(list, "bar", "foobar");
1625    opt = input_option_find(list, "bar");
1626    val = input_option_get_value(opt);
1627    assert(strcmp(val, "foobar") == 0);
1628
1629    input_option_free_list(&list);
1630    assert(list == NULL);
1631}
1632
1633static void
1634_test_double_fp16_values(double orig_d)
1635{
1636    FP1616 first_fp16, final_fp16;
1637    double final_d;
1638
1639    if (orig_d > 0x7FFF) {
1640        printf("Test out of range\n");
1641        assert(0);
1642    }
1643
1644    first_fp16 = double_to_fp1616(orig_d);
1645    final_d = fp1616_to_double(first_fp16);
1646    final_fp16 = double_to_fp1616(final_d);
1647
1648    /* {
1649     *    char first_fp16_s[64];
1650     *    char final_fp16_s[64];
1651     *    snprintf(first_fp16_s, sizeof(first_fp16_s), "%d + %u * 2^-16", (first_fp16 & 0xffff0000) >> 16, first_fp16 & 0xffff);
1652     *    snprintf(final_fp16_s, sizeof(final_fp16_s), "%d + %u * 2^-16", (final_fp16 & 0xffff0000) >> 16, final_fp16 & 0xffff);
1653     *
1654     *    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);
1655     * }
1656     */
1657
1658    /* since we lose precision, we only do rough range testing */
1659    assert(final_d > orig_d - 0.1);
1660    assert(final_d < orig_d + 0.1);
1661
1662    assert(memcmp(&first_fp16, &final_fp16, sizeof(FP1616)) == 0);
1663
1664    if (orig_d > 0)
1665        _test_double_fp16_values(-orig_d);
1666}
1667
1668static void
1669_test_double_fp32_values(double orig_d)
1670{
1671    FP3232 first_fp32, final_fp32;
1672    double final_d;
1673
1674    if (orig_d > 0x7FFFFFFF) {
1675        printf("Test out of range\n");
1676        assert(0);
1677    }
1678
1679    first_fp32 = double_to_fp3232(orig_d);
1680    final_d = fp3232_to_double(first_fp32);
1681    final_fp32 = double_to_fp3232(final_d);
1682
1683    /* {
1684     *     char first_fp32_s[64];
1685     *     char final_fp32_s[64];
1686     *     snprintf(first_fp32_s, sizeof(first_fp32_s), "%d + %u * 2^-32", first_fp32.integral, first_fp32.frac);
1687     *     snprintf(final_fp32_s, sizeof(final_fp32_s), "%d + %u * 2^-32", first_fp32.integral, final_fp32.frac);
1688     *
1689     *     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);
1690     * }
1691     */
1692
1693    /* since we lose precision, we only do rough range testing */
1694    assert(final_d > orig_d - 0.1);
1695    assert(final_d < orig_d + 0.1);
1696
1697    assert(memcmp(&first_fp32, &final_fp32, sizeof(FP3232)) == 0);
1698
1699    if (orig_d > 0)
1700        _test_double_fp32_values(-orig_d);
1701}
1702
1703static void
1704dix_double_fp_conversion(void)
1705{
1706    uint32_t i;
1707
1708    printf("Testing double to FP1616/FP3232 conversions\n");
1709
1710    _test_double_fp16_values(0);
1711    for (i = 1; i < 0x7FFF; i <<= 1) {
1712        double val;
1713
1714        val = i;
1715        _test_double_fp16_values(val);
1716        _test_double_fp32_values(val);
1717
1718        /* and some pseudo-random floating points */
1719        val = i - 0.00382;
1720        _test_double_fp16_values(val);
1721        _test_double_fp32_values(val);
1722
1723        val = i + 0.00382;
1724        _test_double_fp16_values(val);
1725        _test_double_fp32_values(val);
1726
1727        val = i + 0.05234;
1728        _test_double_fp16_values(val);
1729        _test_double_fp32_values(val);
1730
1731        val = i + 0.12342;
1732        _test_double_fp16_values(val);
1733        _test_double_fp32_values(val);
1734
1735        val = i + 0.27583;
1736        _test_double_fp16_values(val);
1737        _test_double_fp32_values(val);
1738
1739        val = i + 0.50535;
1740        _test_double_fp16_values(val);
1741        _test_double_fp32_values(val);
1742
1743        val = i + 0.72342;
1744        _test_double_fp16_values(val);
1745        _test_double_fp32_values(val);
1746
1747        val = i + 0.80408;
1748        _test_double_fp16_values(val);
1749        _test_double_fp32_values(val);
1750    }
1751
1752    for (i = 0x7FFFF; i < 0x7FFFFFFF; i <<= 1) {
1753        _test_double_fp32_values(i);
1754        /* and a few more random floating points, obtained
1755         * by faceplanting into the numpad repeatedly */
1756        _test_double_fp32_values(i + 0.010177);
1757        _test_double_fp32_values(i + 0.213841);
1758        _test_double_fp32_values(i + 0.348720);
1759        _test_double_fp32_values(i + 0.472020);
1760        _test_double_fp32_values(i + 0.572020);
1761        _test_double_fp32_values(i + 0.892929);
1762    }
1763}
1764
1765/* The mieq test verifies that events added to the queue come out in the same
1766 * order that they went in.
1767 */
1768static uint32_t mieq_test_event_last_processed;
1769
1770static void
1771mieq_test_event_handler(int screenNum, InternalEvent *ie, DeviceIntPtr dev)
1772{
1773    RawDeviceEvent *e = (RawDeviceEvent *) ie;
1774
1775    assert(e->type == ET_RawMotion);
1776    assert(e->flags > mieq_test_event_last_processed);
1777    mieq_test_event_last_processed = e->flags;
1778}
1779
1780static void
1781_mieq_test_generate_events(uint32_t start, uint32_t count)
1782{
1783    static DeviceIntRec dev;
1784    static SpriteInfoRec spriteInfo;
1785    static SpriteRec sprite;
1786
1787    memset(&dev, 0, sizeof(dev));
1788    memset(&spriteInfo, 0, sizeof(spriteInfo));
1789    memset(&sprite, 0, sizeof(sprite));
1790    dev.spriteInfo = &spriteInfo;
1791    spriteInfo.sprite = &sprite;
1792
1793    dev.enabled = 1;
1794
1795    count += start;
1796    while (start < count) {
1797        RawDeviceEvent e = { 0 };
1798        e.header = ET_Internal;
1799        e.type = ET_RawMotion;
1800        e.length = sizeof(e);
1801        e.time = GetTimeInMillis();
1802        e.flags = start;
1803
1804        mieqEnqueue(&dev, (InternalEvent *) &e);
1805
1806        start++;
1807    }
1808}
1809
1810#define mieq_test_generate_events(c) { _mieq_test_generate_events(next, c); next += c; }
1811
1812static void
1813mieq_test(void)
1814{
1815    uint32_t next = 1;
1816
1817    mieq_test_event_last_processed = 0;
1818    mieqInit();
1819    mieqSetHandler(ET_RawMotion, mieq_test_event_handler);
1820
1821    /* Enough to fit the buffer but trigger a grow */
1822    mieq_test_generate_events(180);
1823
1824    /* We should resize to 512 now */
1825    mieqProcessInputEvents();
1826
1827    /* Some should now get dropped */
1828    mieq_test_generate_events(500);
1829
1830    /* Tell us how many got dropped, 1024 now */
1831    mieqProcessInputEvents();
1832
1833    /* Now make it 2048 */
1834    mieq_test_generate_events(900);
1835    mieqProcessInputEvents();
1836
1837    /* Now make it 4096 (max) */
1838    mieq_test_generate_events(1950);
1839    mieqProcessInputEvents();
1840
1841    /* Now overflow one last time with the maximal queue and reach the verbosity limit */
1842    mieq_test_generate_events(10000);
1843    mieqProcessInputEvents();
1844
1845    mieqFini();
1846}
1847
1848/* Simple check that we're replaying events in-order */
1849static void
1850process_input_proc(InternalEvent *ev, DeviceIntPtr device)
1851{
1852    static int last_evtype = -1;
1853
1854    if (ev->any.header == 0xac)
1855        last_evtype = -1;
1856
1857    assert(ev->any.type == ++last_evtype);
1858}
1859
1860static void
1861dix_enqueue_events(void)
1862{
1863#define NEVENTS 5
1864    DeviceIntRec dev;
1865    InternalEvent ev[NEVENTS];
1866    SpriteInfoRec spriteInfo;
1867    SpriteRec sprite;
1868    QdEventPtr qe;
1869    int i;
1870
1871    memset(&dev, 0, sizeof(dev));
1872    dev.public.processInputProc = process_input_proc;
1873
1874    memset(&spriteInfo, 0, sizeof(spriteInfo));
1875    memset(&sprite, 0, sizeof(sprite));
1876    dev.spriteInfo = &spriteInfo;
1877    spriteInfo.sprite = &sprite;
1878
1879    InitEvents();
1880    assert(xorg_list_is_empty(&syncEvents.pending));
1881
1882    /* this way PlayReleasedEvents really runs through all events in the
1883     * queue */
1884    inputInfo.devices = &dev;
1885
1886    /* to reset process_input_proc */
1887    ev[0].any.header = 0xac;
1888
1889    for (i = 0; i < NEVENTS; i++) {
1890        ev[i].any.length = sizeof(*ev);
1891        ev[i].any.type = i;
1892        EnqueueEvent(&ev[i], &dev);
1893        assert(!xorg_list_is_empty(&syncEvents.pending));
1894        qe = xorg_list_last_entry(&syncEvents.pending, QdEventRec, next);
1895        assert(memcmp(qe->event, &ev[i], ev[i].any.length) == 0);
1896        qe = xorg_list_first_entry(&syncEvents.pending, QdEventRec, next);
1897        assert(memcmp(qe->event, &ev[0], ev[i].any.length) == 0);
1898    }
1899
1900    /* calls process_input_proc */
1901    dev.deviceGrab.sync.frozen = 1;
1902    PlayReleasedEvents();
1903    assert(!xorg_list_is_empty(&syncEvents.pending));
1904
1905    dev.deviceGrab.sync.frozen = 0;
1906    PlayReleasedEvents();
1907    assert(xorg_list_is_empty(&syncEvents.pending));
1908
1909    inputInfo.devices = NULL;
1910}
1911
1912int
1913input_test(void)
1914{
1915    dix_enqueue_events();
1916    dix_double_fp_conversion();
1917    dix_input_valuator_masks();
1918    dix_input_valuator_masks_unaccel();
1919    dix_input_attributes();
1920    dix_init_valuators();
1921    dix_event_to_core_conversion();
1922    dix_event_to_xi1_conversion();
1923    dix_check_grab_values();
1924    xi2_struct_sizes();
1925    dix_grab_matching();
1926    dix_valuator_mode();
1927    include_byte_padding_macros();
1928    include_bit_test_macros();
1929    xi_unregister_handlers();
1930    dix_valuator_alloc();
1931    dix_get_master();
1932    input_option_test();
1933    mieq_test();
1934
1935    return 0;
1936}
1937