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#ifdef HAVE_DIX_CONFIG_H
25#include <dix-config.h>
26#endif
27
28#include <stdint.h>
29#include <X11/X.h>
30#include "misc.h"
31#include "resource.h"
32#include <X11/Xproto.h>
33#include <X11/extensions/XI2proto.h>
34#include <X11/Xatom.h>
35#include "windowstr.h"
36#include "inputstr.h"
37#include "eventconvert.h"
38#include "exevents.h"
39#include "exglobals.h"
40#include "dixgrabs.h"
41#include "eventstr.h"
42#include "inpututils.h"
43#include <glib.h>
44
45/**
46 * Init a device with axes.
47 * Verify values set on the device.
48 *
49 * Result: All axes set to default values (usually 0).
50 */
51static void dix_init_valuators(void)
52{
53    DeviceIntRec dev;
54    ValuatorClassPtr val;
55    const int num_axes = 2;
56    int i;
57    Atom atoms[MAX_VALUATORS] = { 0 };
58
59
60    memset(&dev, 0, sizeof(DeviceIntRec));
61    dev.type = MASTER_POINTER; /* claim it's a master to stop ptracccel */
62
63    g_assert(InitValuatorClassDeviceStruct(NULL, 0, atoms, 0, 0) == FALSE);
64    g_assert(InitValuatorClassDeviceStruct(&dev, num_axes, atoms, 0, Absolute));
65
66    val = dev.valuator;
67    g_assert(val);
68    g_assert(val->numAxes == num_axes);
69    g_assert(val->numMotionEvents == 0);
70    g_assert(val->axisVal);
71
72    for (i = 0; i < num_axes; i++)
73    {
74        g_assert(val->axisVal[i] == 0);
75        g_assert(val->axes->min_value == NO_AXIS_LIMITS);
76        g_assert(val->axes->max_value == NO_AXIS_LIMITS);
77        g_assert(val->axes->mode == Absolute);
78    }
79
80    g_assert(dev.last.numValuators == num_axes);
81}
82
83/* just check the known success cases, and that error cases set the client's
84 * error value correctly. */
85static void dix_check_grab_values(void)
86{
87    ClientRec client;
88    GrabParameters param;
89    int rc;
90
91    memset(&client, 0, sizeof(client));
92
93    param.grabtype = GRABTYPE_CORE;
94    param.this_device_mode = GrabModeSync;
95    param.other_devices_mode = GrabModeSync;
96    param.modifiers = AnyModifier;
97    param.ownerEvents = FALSE;
98
99    rc = CheckGrabValues(&client, &param);
100    g_assert(rc == Success);
101
102    param.this_device_mode = GrabModeAsync;
103    rc = CheckGrabValues(&client, &param);
104    g_assert(rc == Success);
105
106    param.this_device_mode = GrabModeAsync + 1;
107    rc = CheckGrabValues(&client, &param);
108    g_assert(rc == BadValue);
109    g_assert(client.errorValue == param.this_device_mode);
110    g_assert(client.errorValue == GrabModeAsync + 1);
111
112    param.this_device_mode = GrabModeSync;
113    param.other_devices_mode = GrabModeAsync;
114    rc = CheckGrabValues(&client, &param);
115    g_assert(rc == Success);
116
117    param.other_devices_mode = GrabModeAsync + 1;
118    rc = CheckGrabValues(&client, &param);
119    g_assert(rc == BadValue);
120    g_assert(client.errorValue == param.other_devices_mode);
121    g_assert(client.errorValue == GrabModeAsync + 1);
122
123    param.other_devices_mode = GrabModeSync;
124
125    param.modifiers = 1 << 13;
126    rc = CheckGrabValues(&client, &param);
127    g_assert(rc == BadValue);
128    g_assert(client.errorValue == param.modifiers);
129    g_assert(client.errorValue == (1 << 13));
130
131
132    param.modifiers = AnyModifier;
133    param.ownerEvents = TRUE;
134    rc = CheckGrabValues(&client, &param);
135    g_assert(rc == Success);
136
137    param.ownerEvents = 3;
138    rc = CheckGrabValues(&client, &param);
139    g_assert(rc == BadValue);
140    g_assert(client.errorValue == param.ownerEvents);
141    g_assert(client.errorValue == 3);
142}
143
144
145/**
146 * Convert various internal events to the matching core event and verify the
147 * parameters.
148 */
149static void dix_event_to_core(int type)
150{
151    DeviceEvent ev;
152    xEvent core;
153    int time;
154    int x, y;
155    int rc;
156    int state;
157    int detail;
158    const int ROOT_WINDOW_ID = 0x100;
159
160    /* EventToCore memsets the event to 0 */
161#define test_event() \
162    g_assert(rc == Success); \
163    g_assert(core.u.u.type == type); \
164    g_assert(core.u.u.detail == detail); \
165    g_assert(core.u.keyButtonPointer.time == time); \
166    g_assert(core.u.keyButtonPointer.rootX == x); \
167    g_assert(core.u.keyButtonPointer.rootY == y); \
168    g_assert(core.u.keyButtonPointer.state == state); \
169    g_assert(core.u.keyButtonPointer.eventX == 0); \
170    g_assert(core.u.keyButtonPointer.eventY == 0); \
171    g_assert(core.u.keyButtonPointer.root == ROOT_WINDOW_ID); \
172    g_assert(core.u.keyButtonPointer.event == 0); \
173    g_assert(core.u.keyButtonPointer.child == 0); \
174    g_assert(core.u.keyButtonPointer.sameScreen == FALSE);
175
176    x = 0;
177    y = 0;
178    time = 12345;
179    state = 0;
180    detail = 0;
181
182    ev.header   = 0xFF;
183    ev.length   = sizeof(DeviceEvent);
184    ev.time     = time;
185    ev.root_y   = x;
186    ev.root_x   = y;
187    SetBit(ev.valuators.mask, 0);
188    SetBit(ev.valuators.mask, 1);
189    ev.root     = ROOT_WINDOW_ID;
190    ev.corestate = state;
191    ev.detail.key = detail;
192
193    ev.type = type;
194    ev.detail.key = 0;
195    rc = EventToCore((InternalEvent*)&ev, &core);
196    test_event();
197
198    x = 1;
199    y = 2;
200    ev.root_x = x;
201    ev.root_y = y;
202    rc = EventToCore((InternalEvent*)&ev, &core);
203    test_event();
204
205    x = 0x7FFF;
206    y = 0x7FFF;
207    ev.root_x = x;
208    ev.root_y = y;
209    rc = EventToCore((InternalEvent*)&ev, &core);
210    test_event();
211
212    x = 0x8000; /* too high */
213    y = 0x8000; /* too high */
214    ev.root_x = x;
215    ev.root_y = y;
216    rc = EventToCore((InternalEvent*)&ev, &core);
217    g_assert(core.u.keyButtonPointer.rootX != x);
218    g_assert(core.u.keyButtonPointer.rootY != y);
219
220    x = 0x7FFF;
221    y = 0x7FFF;
222    ev.root_x = x;
223    ev.root_y = y;
224    time = 0;
225    ev.time = time;
226    rc = EventToCore((InternalEvent*)&ev, &core);
227    test_event();
228
229    detail = 1;
230    ev.detail.key = detail;
231    rc = EventToCore((InternalEvent*)&ev, &core);
232    test_event();
233
234    detail = 0xFF; /* highest value */
235    ev.detail.key = detail;
236    rc = EventToCore((InternalEvent*)&ev, &core);
237    test_event();
238
239    detail = 0xFFF; /* too big */
240    ev.detail.key = detail;
241    rc = EventToCore((InternalEvent*)&ev, &core);
242    g_assert(rc == BadMatch);
243
244    detail = 0xFF; /* too big */
245    ev.detail.key = detail;
246    state = 0xFFFF; /* highest value */
247    ev.corestate = state;
248    rc = EventToCore((InternalEvent*)&ev, &core);
249    test_event();
250
251    state = 0x10000; /* too big */
252    ev.corestate = state;
253    rc = EventToCore((InternalEvent*)&ev, &core);
254    g_assert(core.u.keyButtonPointer.state != state);
255    g_assert(core.u.keyButtonPointer.state == (state & 0xFFFF));
256
257#undef test_event
258}
259
260static void dix_event_to_core_fail(int evtype, int expected_rc)
261{
262    DeviceEvent ev;
263    xEvent core;
264    int rc;
265
266    ev.header   = 0xFF;
267    ev.length   = sizeof(DeviceEvent);
268
269    ev.type     = evtype;
270    rc = EventToCore((InternalEvent*)&ev, &core);
271    g_assert(rc == expected_rc);
272}
273
274static void dix_event_to_core_conversion(void)
275{
276    dix_event_to_core_fail(0, BadImplementation);
277    dix_event_to_core_fail(1, BadImplementation);
278    dix_event_to_core_fail(ET_ProximityOut + 1, BadImplementation);
279    dix_event_to_core_fail(ET_ProximityIn, BadMatch);
280    dix_event_to_core_fail(ET_ProximityOut, BadMatch);
281
282    dix_event_to_core(ET_KeyPress);
283    dix_event_to_core(ET_KeyRelease);
284    dix_event_to_core(ET_ButtonPress);
285    dix_event_to_core(ET_ButtonRelease);
286    dix_event_to_core(ET_Motion);
287}
288
289static void
290_dix_test_xi_convert(DeviceEvent *ev, int expected_rc, int expected_count)
291{
292    xEvent *xi;
293    int count = 0;
294    int rc;
295
296    rc = EventToXI((InternalEvent*)ev, &xi, &count);
297    g_assert(rc == expected_rc);
298    g_assert(count >= expected_count);
299    if (count > 0){
300        deviceKeyButtonPointer *kbp = (deviceKeyButtonPointer*)xi;
301        g_assert(kbp->type == IEventBase + ev->type);
302        g_assert(kbp->detail == ev->detail.key);
303        g_assert(kbp->time == ev->time);
304        g_assert((kbp->deviceid & ~MORE_EVENTS) == ev->deviceid);
305        g_assert(kbp->root_x == ev->root_x);
306        g_assert(kbp->root_y == ev->root_y);
307        g_assert(kbp->state == ev->corestate);
308        g_assert(kbp->event_x == 0);
309        g_assert(kbp->event_y == 0);
310        g_assert(kbp->root == ev->root);
311        g_assert(kbp->event == 0);
312        g_assert(kbp->child == 0);
313        g_assert(kbp->same_screen == FALSE);
314
315        while (--count > 0) {
316            deviceValuator *v = (deviceValuator*)&xi[count];
317            g_assert(v->type == DeviceValuator);
318            g_assert(v->num_valuators <= 6);
319        }
320
321
322        free(xi);
323    }
324}
325
326/**
327 * This tests for internal event → XI1 event conversion
328 * - all conversions should generate the right XI event type
329 * - right number of events generated
330 * - extra events are valuators
331 */
332static void dix_event_to_xi1_conversion(void)
333{
334    DeviceEvent ev = {0};
335    int time;
336    int x, y;
337    int state;
338    int detail;
339    const int ROOT_WINDOW_ID = 0x100;
340    int deviceid;
341
342    IEventBase = 80;
343    DeviceValuator      = IEventBase - 1;
344    DeviceKeyPress      = IEventBase + ET_KeyPress;
345    DeviceKeyRelease    = IEventBase + ET_KeyRelease;
346    DeviceButtonPress   = IEventBase + ET_ButtonPress;
347    DeviceButtonRelease = IEventBase + ET_ButtonRelease;
348    DeviceMotionNotify  = IEventBase + ET_Motion;
349    DeviceFocusIn       = IEventBase + ET_FocusIn;
350    DeviceFocusOut      = IEventBase + ET_FocusOut;
351    ProximityIn         = IEventBase + ET_ProximityIn;
352    ProximityOut        = IEventBase + ET_ProximityOut;
353
354    /* EventToXI callocs */
355    x = 0;
356    y = 0;
357    time = 12345;
358    state = 0;
359    detail = 0;
360    deviceid = 4;
361
362    ev.header   = 0xFF;
363
364    ev.header           = 0xFF;
365    ev.length           = sizeof(DeviceEvent);
366    ev.time             = time;
367    ev.root_y           = x;
368    ev.root_x           = y;
369    SetBit(ev.valuators.mask, 0);
370    SetBit(ev.valuators.mask, 1);
371    ev.root             = ROOT_WINDOW_ID;
372    ev.corestate        = state;
373    ev.detail.key       = detail;
374    ev.deviceid         = deviceid;
375
376    /* test all types for bad match */
377    ev.type = ET_KeyPress;         _dix_test_xi_convert(&ev, Success, 1);
378    ev.type = ET_KeyRelease;       _dix_test_xi_convert(&ev, Success, 1);
379    ev.type = ET_ButtonPress;      _dix_test_xi_convert(&ev, Success, 1);
380    ev.type = ET_ButtonRelease;    _dix_test_xi_convert(&ev, Success, 1);
381    ev.type = ET_Motion;           _dix_test_xi_convert(&ev, Success, 1);
382    ev.type = ET_ProximityIn;      _dix_test_xi_convert(&ev, Success, 1);
383    ev.type = ET_ProximityOut;     _dix_test_xi_convert(&ev, Success, 1);
384
385    /* No axes */
386    ClearBit(ev.valuators.mask, 0);
387    ClearBit(ev.valuators.mask, 1);
388    ev.type = ET_KeyPress;         _dix_test_xi_convert(&ev, Success, 1);
389    ev.type = ET_KeyRelease;       _dix_test_xi_convert(&ev, Success, 1);
390    ev.type = ET_ButtonPress;      _dix_test_xi_convert(&ev, Success, 1);
391    ev.type = ET_ButtonRelease;    _dix_test_xi_convert(&ev, Success, 1);
392    ev.type = ET_Motion;           _dix_test_xi_convert(&ev, BadMatch, 0);
393    ev.type = ET_ProximityIn;      _dix_test_xi_convert(&ev, BadMatch, 0);
394    ev.type = ET_ProximityOut;     _dix_test_xi_convert(&ev, BadMatch, 0);
395
396    /* more than 6 axes → 2 valuator events */
397    SetBit(ev.valuators.mask, 0);
398    SetBit(ev.valuators.mask, 1);
399    SetBit(ev.valuators.mask, 2);
400    SetBit(ev.valuators.mask, 3);
401    SetBit(ev.valuators.mask, 4);
402    SetBit(ev.valuators.mask, 5);
403    SetBit(ev.valuators.mask, 6);
404    ev.type = ET_KeyPress;         _dix_test_xi_convert(&ev, Success, 2);
405    ev.type = ET_KeyRelease;       _dix_test_xi_convert(&ev, Success, 2);
406    ev.type = ET_ButtonPress;      _dix_test_xi_convert(&ev, Success, 2);
407    ev.type = ET_ButtonRelease;    _dix_test_xi_convert(&ev, Success, 2);
408    ev.type = ET_Motion;           _dix_test_xi_convert(&ev, Success, 2);
409    ev.type = ET_ProximityIn;      _dix_test_xi_convert(&ev, Success, 2);
410    ev.type = ET_ProximityOut;     _dix_test_xi_convert(&ev, Success, 2);
411
412
413    /* keycode too high */
414    ev.type = ET_KeyPress;
415    ev.detail.key = 256;
416    _dix_test_xi_convert(&ev, Success, 0);
417
418    /* deviceid too high */
419    ev.type = ET_KeyPress;
420    ev.detail.key = 18;
421    ev.deviceid = 128;
422    _dix_test_xi_convert(&ev, Success, 0);
423}
424
425
426static void xi2_struct_sizes(void)
427{
428#define compare(req) \
429    g_assert(sizeof(req) == sz_##req);
430
431    compare(xXIQueryVersionReq);
432    compare(xXIWarpPointerReq);
433    compare(xXIChangeCursorReq);
434    compare(xXIChangeHierarchyReq);
435    compare(xXISetClientPointerReq);
436    compare(xXIGetClientPointerReq);
437    compare(xXISelectEventsReq);
438    compare(xXIQueryVersionReq);
439    compare(xXIQueryDeviceReq);
440    compare(xXISetFocusReq);
441    compare(xXIGetFocusReq);
442    compare(xXIGrabDeviceReq);
443    compare(xXIUngrabDeviceReq);
444    compare(xXIAllowEventsReq);
445    compare(xXIPassiveGrabDeviceReq);
446    compare(xXIPassiveUngrabDeviceReq);
447    compare(xXIListPropertiesReq);
448    compare(xXIChangePropertyReq);
449    compare(xXIDeletePropertyReq);
450    compare(xXIGetPropertyReq);
451    compare(xXIGetSelectedEventsReq);
452#undef compare
453}
454
455
456static void dix_grab_matching(void)
457{
458    DeviceIntRec xi_all_devices, xi_all_master_devices, dev1, dev2;
459    GrabRec a, b;
460    BOOL rc;
461
462    memset(&a, 0, sizeof(a));
463    memset(&b, 0, sizeof(b));
464
465    /* different grabtypes must fail */
466    a.grabtype = GRABTYPE_CORE;
467    b.grabtype = GRABTYPE_XI2;
468    rc = GrabMatchesSecond(&a, &b, FALSE);
469    g_assert(rc == FALSE);
470    rc = GrabMatchesSecond(&b, &a, FALSE);
471    g_assert(rc == FALSE);
472
473    a.grabtype = GRABTYPE_XI;
474    b.grabtype = GRABTYPE_XI2;
475    rc = GrabMatchesSecond(&a, &b, FALSE);
476    g_assert(rc == FALSE);
477    rc = GrabMatchesSecond(&b, &a, FALSE);
478    g_assert(rc == FALSE);
479
480    a.grabtype = GRABTYPE_XI;
481    b.grabtype = GRABTYPE_CORE;
482    rc = GrabMatchesSecond(&a, &b, FALSE);
483    g_assert(rc == FALSE);
484    rc = GrabMatchesSecond(&b, &a, FALSE);
485    g_assert(rc == FALSE);
486
487    /* XI2 grabs for different devices must fail, regardless of ignoreDevice
488     * XI2 grabs for master devices must fail against a slave */
489    memset(&xi_all_devices, 0, sizeof(DeviceIntRec));
490    memset(&xi_all_master_devices, 0, sizeof(DeviceIntRec));
491    memset(&dev1, 0, sizeof(DeviceIntRec));
492    memset(&dev2, 0, sizeof(DeviceIntRec));
493
494    xi_all_devices.id = XIAllDevices;
495    xi_all_master_devices.id = XIAllMasterDevices;
496    dev1.id = 10;
497    dev1.type = SLAVE;
498    dev2.id = 11;
499    dev2.type = SLAVE;
500
501    inputInfo.all_devices = &xi_all_devices;
502    inputInfo.all_master_devices = &xi_all_master_devices;
503    a.grabtype = GRABTYPE_XI2;
504    b.grabtype = GRABTYPE_XI2;
505    a.device = &dev1;
506    b.device = &dev2;
507
508    rc = GrabMatchesSecond(&a, &b, FALSE);
509    g_assert(rc == FALSE);
510
511    a.device = &dev2;
512    b.device = &dev1;
513    rc = GrabMatchesSecond(&a, &b, FALSE);
514    g_assert(rc == FALSE);
515    rc = GrabMatchesSecond(&a, &b, TRUE);
516    g_assert(rc == FALSE);
517
518    a.device = inputInfo.all_master_devices;
519    b.device = &dev1;
520    rc = GrabMatchesSecond(&a, &b, FALSE);
521    g_assert(rc == FALSE);
522    rc = GrabMatchesSecond(&a, &b, TRUE);
523    g_assert(rc == FALSE);
524
525    a.device = &dev1;
526    b.device = inputInfo.all_master_devices;
527    rc = GrabMatchesSecond(&a, &b, FALSE);
528    g_assert(rc == FALSE);
529    rc = GrabMatchesSecond(&a, &b, TRUE);
530    g_assert(rc == FALSE);
531
532    /* ignoreDevice FALSE must fail for different devices for CORE and XI */
533    a.grabtype = GRABTYPE_XI;
534    b.grabtype = GRABTYPE_XI;
535    a.device = &dev1;
536    b.device = &dev2;
537    a.modifierDevice = &dev1;
538    b.modifierDevice = &dev1;
539    rc = GrabMatchesSecond(&a, &b, FALSE);
540    g_assert(rc == FALSE);
541
542    a.grabtype = GRABTYPE_CORE;
543    b.grabtype = GRABTYPE_CORE;
544    a.device = &dev1;
545    b.device = &dev2;
546    a.modifierDevice = &dev1;
547    b.modifierDevice = &dev1;
548    rc = GrabMatchesSecond(&a, &b, FALSE);
549    g_assert(rc == FALSE);
550
551    /* ignoreDevice FALSE must fail for different modifier devices for CORE
552     * and XI */
553    a.grabtype = GRABTYPE_XI;
554    b.grabtype = GRABTYPE_XI;
555    a.device = &dev1;
556    b.device = &dev1;
557    a.modifierDevice = &dev1;
558    b.modifierDevice = &dev2;
559    rc = GrabMatchesSecond(&a, &b, FALSE);
560    g_assert(rc == FALSE);
561
562    a.grabtype = GRABTYPE_CORE;
563    b.grabtype = GRABTYPE_CORE;
564    a.device = &dev1;
565    b.device = &dev1;
566    a.modifierDevice = &dev1;
567    b.modifierDevice = &dev2;
568    rc = GrabMatchesSecond(&a, &b, FALSE);
569    g_assert(rc == FALSE);
570
571    /* different event type must fail */
572    a.grabtype = GRABTYPE_XI2;
573    b.grabtype = GRABTYPE_XI2;
574    a.device = &dev1;
575    b.device = &dev1;
576    a.modifierDevice = &dev1;
577    b.modifierDevice = &dev1;
578    a.type = XI_KeyPress;
579    b.type = XI_KeyRelease;
580    rc = GrabMatchesSecond(&a, &b, FALSE);
581    g_assert(rc == FALSE);
582    rc = GrabMatchesSecond(&a, &b, TRUE);
583    g_assert(rc == FALSE);
584
585    a.grabtype = GRABTYPE_CORE;
586    b.grabtype = GRABTYPE_CORE;
587    a.device = &dev1;
588    b.device = &dev1;
589    a.modifierDevice = &dev1;
590    b.modifierDevice = &dev1;
591    a.type = XI_KeyPress;
592    b.type = XI_KeyRelease;
593    rc = GrabMatchesSecond(&a, &b, FALSE);
594    g_assert(rc == FALSE);
595    rc = GrabMatchesSecond(&a, &b, TRUE);
596    g_assert(rc == FALSE);
597
598    a.grabtype = GRABTYPE_XI;
599    b.grabtype = GRABTYPE_XI;
600    a.device = &dev1;
601    b.device = &dev1;
602    a.modifierDevice = &dev1;
603    b.modifierDevice = &dev1;
604    a.type = XI_KeyPress;
605    b.type = XI_KeyRelease;
606    rc = GrabMatchesSecond(&a, &b, FALSE);
607    g_assert(rc == FALSE);
608    rc = GrabMatchesSecond(&a, &b, TRUE);
609    g_assert(rc == FALSE);
610
611    /* different modifiers must fail */
612    a.grabtype = GRABTYPE_XI2;
613    b.grabtype = GRABTYPE_XI2;
614    a.device = &dev1;
615    b.device = &dev1;
616    a.modifierDevice = &dev1;
617    b.modifierDevice = &dev1;
618    a.type = XI_KeyPress;
619    b.type = XI_KeyPress;
620    a.modifiersDetail.exact = 1;
621    b.modifiersDetail.exact = 2;
622    rc = GrabMatchesSecond(&a, &b, FALSE);
623    g_assert(rc == FALSE);
624    rc = GrabMatchesSecond(&b, &a, FALSE);
625    g_assert(rc == FALSE);
626
627    a.grabtype = GRABTYPE_CORE;
628    b.grabtype = GRABTYPE_CORE;
629    rc = GrabMatchesSecond(&a, &b, FALSE);
630    g_assert(rc == FALSE);
631    rc = GrabMatchesSecond(&b, &a, FALSE);
632    g_assert(rc == FALSE);
633
634    a.grabtype = GRABTYPE_XI;
635    b.grabtype = GRABTYPE_XI;
636    rc = GrabMatchesSecond(&a, &b, FALSE);
637    g_assert(rc == FALSE);
638    rc = GrabMatchesSecond(&b, &a, FALSE);
639    g_assert(rc == FALSE);
640
641    /* AnyModifier must fail for XI2 */
642    a.grabtype = GRABTYPE_XI2;
643    b.grabtype = GRABTYPE_XI2;
644    a.modifiersDetail.exact = AnyModifier;
645    b.modifiersDetail.exact = 1;
646    rc = GrabMatchesSecond(&a, &b, FALSE);
647    g_assert(rc == FALSE);
648    rc = GrabMatchesSecond(&b, &a, FALSE);
649    g_assert(rc == FALSE);
650
651    /* XIAnyModifier must fail for CORE and XI */
652    a.grabtype = GRABTYPE_XI;
653    b.grabtype = GRABTYPE_XI;
654    a.modifiersDetail.exact = XIAnyModifier;
655    b.modifiersDetail.exact = 1;
656    rc = GrabMatchesSecond(&a, &b, FALSE);
657    g_assert(rc == FALSE);
658    rc = GrabMatchesSecond(&b, &a, FALSE);
659    g_assert(rc == FALSE);
660
661    a.grabtype = GRABTYPE_CORE;
662    b.grabtype = GRABTYPE_CORE;
663    a.modifiersDetail.exact = XIAnyModifier;
664    b.modifiersDetail.exact = 1;
665    rc = GrabMatchesSecond(&a, &b, FALSE);
666    g_assert(rc == FALSE);
667    rc = GrabMatchesSecond(&b, &a, FALSE);
668    g_assert(rc == FALSE);
669
670    /* different detail must fail */
671    a.grabtype = GRABTYPE_XI2;
672    b.grabtype = GRABTYPE_XI2;
673    a.detail.exact = 1;
674    b.detail.exact = 2;
675    a.modifiersDetail.exact = 1;
676    b.modifiersDetail.exact = 1;
677    rc = GrabMatchesSecond(&a, &b, FALSE);
678    g_assert(rc == FALSE);
679    rc = GrabMatchesSecond(&b, &a, FALSE);
680    g_assert(rc == FALSE);
681
682    a.grabtype = GRABTYPE_XI;
683    b.grabtype = GRABTYPE_XI;
684    rc = GrabMatchesSecond(&a, &b, FALSE);
685    g_assert(rc == FALSE);
686    rc = GrabMatchesSecond(&b, &a, FALSE);
687    g_assert(rc == FALSE);
688
689    a.grabtype = GRABTYPE_CORE;
690    b.grabtype = GRABTYPE_CORE;
691    rc = GrabMatchesSecond(&a, &b, FALSE);
692    g_assert(rc == FALSE);
693    rc = GrabMatchesSecond(&b, &a, FALSE);
694    g_assert(rc == FALSE);
695
696    /* detail of AnyModifier must fail */
697    a.grabtype = GRABTYPE_XI2;
698    b.grabtype = GRABTYPE_XI2;
699    a.detail.exact = AnyModifier;
700    b.detail.exact = 1;
701    a.modifiersDetail.exact = 1;
702    b.modifiersDetail.exact = 1;
703    rc = GrabMatchesSecond(&a, &b, FALSE);
704    g_assert(rc == FALSE);
705    rc = GrabMatchesSecond(&b, &a, FALSE);
706    g_assert(rc == FALSE);
707
708    a.grabtype = GRABTYPE_CORE;
709    b.grabtype = GRABTYPE_CORE;
710    rc = GrabMatchesSecond(&a, &b, FALSE);
711    g_assert(rc == FALSE);
712    rc = GrabMatchesSecond(&b, &a, FALSE);
713    g_assert(rc == FALSE);
714
715    a.grabtype = GRABTYPE_XI;
716    b.grabtype = GRABTYPE_XI;
717    rc = GrabMatchesSecond(&a, &b, FALSE);
718    g_assert(rc == FALSE);
719    rc = GrabMatchesSecond(&b, &a, FALSE);
720    g_assert(rc == FALSE);
721
722    /* detail of XIAnyModifier must fail */
723    a.grabtype = GRABTYPE_XI2;
724    b.grabtype = GRABTYPE_XI2;
725    a.detail.exact = XIAnyModifier;
726    b.detail.exact = 1;
727    a.modifiersDetail.exact = 1;
728    b.modifiersDetail.exact = 1;
729    rc = GrabMatchesSecond(&a, &b, FALSE);
730    g_assert(rc == FALSE);
731    rc = GrabMatchesSecond(&b, &a, FALSE);
732    g_assert(rc == FALSE);
733
734    a.grabtype = GRABTYPE_CORE;
735    b.grabtype = GRABTYPE_CORE;
736    rc = GrabMatchesSecond(&a, &b, FALSE);
737    g_assert(rc == FALSE);
738    rc = GrabMatchesSecond(&b, &a, FALSE);
739    g_assert(rc == FALSE);
740
741    a.grabtype = GRABTYPE_XI;
742    b.grabtype = GRABTYPE_XI;
743    rc = GrabMatchesSecond(&a, &b, FALSE);
744    g_assert(rc == FALSE);
745    rc = GrabMatchesSecond(&b, &a, FALSE);
746    g_assert(rc == FALSE);
747
748    /* XIAnyModifier or AnyModifer must succeed */
749    a.grabtype = GRABTYPE_XI2;
750    b.grabtype = GRABTYPE_XI2;
751    a.detail.exact = 1;
752    b.detail.exact = 1;
753    a.modifiersDetail.exact = XIAnyModifier;
754    b.modifiersDetail.exact = 1;
755    rc = GrabMatchesSecond(&a, &b, FALSE);
756    g_assert(rc == TRUE);
757    rc = GrabMatchesSecond(&b, &a, FALSE);
758    g_assert(rc == TRUE);
759
760    a.grabtype = GRABTYPE_CORE;
761    b.grabtype = GRABTYPE_CORE;
762    a.detail.exact = 1;
763    b.detail.exact = 1;
764    a.modifiersDetail.exact = AnyModifier;
765    b.modifiersDetail.exact = 1;
766    rc = GrabMatchesSecond(&a, &b, FALSE);
767    g_assert(rc == TRUE);
768    rc = GrabMatchesSecond(&b, &a, FALSE);
769    g_assert(rc == TRUE);
770
771    a.grabtype = GRABTYPE_XI;
772    b.grabtype = GRABTYPE_XI;
773    a.detail.exact = 1;
774    b.detail.exact = 1;
775    a.modifiersDetail.exact = AnyModifier;
776    b.modifiersDetail.exact = 1;
777    rc = GrabMatchesSecond(&a, &b, FALSE);
778    g_assert(rc == TRUE);
779    rc = GrabMatchesSecond(&b, &a, FALSE);
780    g_assert(rc == TRUE);
781
782    /* AnyKey or XIAnyKeycode must succeed */
783    a.grabtype = GRABTYPE_XI2;
784    b.grabtype = GRABTYPE_XI2;
785    a.detail.exact = XIAnyKeycode;
786    b.detail.exact = 1;
787    a.modifiersDetail.exact = 1;
788    b.modifiersDetail.exact = 1;
789    rc = GrabMatchesSecond(&a, &b, FALSE);
790    g_assert(rc == TRUE);
791    rc = GrabMatchesSecond(&b, &a, FALSE);
792    g_assert(rc == TRUE);
793
794    a.grabtype = GRABTYPE_CORE;
795    b.grabtype = GRABTYPE_CORE;
796    a.detail.exact = AnyKey;
797    b.detail.exact = 1;
798    a.modifiersDetail.exact = 1;
799    b.modifiersDetail.exact = 1;
800    rc = GrabMatchesSecond(&a, &b, FALSE);
801    g_assert(rc == TRUE);
802    rc = GrabMatchesSecond(&b, &a, FALSE);
803    g_assert(rc == TRUE);
804
805    a.grabtype = GRABTYPE_XI;
806    b.grabtype = GRABTYPE_XI;
807    a.detail.exact = AnyKey;
808    b.detail.exact = 1;
809    a.modifiersDetail.exact = 1;
810    b.modifiersDetail.exact = 1;
811    rc = GrabMatchesSecond(&a, &b, FALSE);
812    g_assert(rc == TRUE);
813    rc = GrabMatchesSecond(&b, &a, FALSE);
814    g_assert(rc == TRUE);
815}
816
817static void test_bits_to_byte(int i)
818{
819        int expected_bytes;
820        expected_bytes = (i + 7)/8;
821
822        g_assert(bits_to_bytes(i) >= i/8);
823        g_assert((bits_to_bytes(i) * 8) - i <= 7);
824        g_assert(expected_bytes == bits_to_bytes(i));
825}
826
827static void test_bytes_to_int32(int i)
828{
829        int expected_4byte;
830        expected_4byte = (i + 3)/4;
831
832        g_assert(bytes_to_int32(i) <= i);
833        g_assert((bytes_to_int32(i) * 4) - i <= 3);
834        g_assert(expected_4byte == bytes_to_int32(i));
835}
836
837static void test_pad_to_int32(int i)
838{
839        int expected_bytes;
840        expected_bytes = ((i + 3)/4) * 4;
841
842        g_assert(pad_to_int32(i) >= i);
843        g_assert(pad_to_int32(i) - i <= 3);
844        g_assert(expected_bytes == pad_to_int32(i));
845}
846static void include_byte_padding_macros(void)
847{
848    g_test_message("Testing bits_to_bytes()");
849
850    /* the macros don't provide overflow protection */
851    test_bits_to_byte(0);
852    test_bits_to_byte(1);
853    test_bits_to_byte(2);
854    test_bits_to_byte(7);
855    test_bits_to_byte(8);
856    test_bits_to_byte(0xFF);
857    test_bits_to_byte(0x100);
858    test_bits_to_byte(INT_MAX - 9);
859    test_bits_to_byte(INT_MAX - 8);
860
861    g_test_message("Testing bytes_to_int32()");
862
863    test_bytes_to_int32(0);
864    test_bytes_to_int32(1);
865    test_bytes_to_int32(2);
866    test_bytes_to_int32(7);
867    test_bytes_to_int32(8);
868    test_bytes_to_int32(0xFF);
869    test_bytes_to_int32(0x100);
870    test_bytes_to_int32(0xFFFF);
871    test_bytes_to_int32(0x10000);
872    test_bytes_to_int32(0xFFFFFF);
873    test_bytes_to_int32(0x1000000);
874    test_bytes_to_int32(INT_MAX - 4);
875    test_bytes_to_int32(INT_MAX - 3);
876
877    g_test_message("Testing pad_to_int32");
878
879    test_pad_to_int32(0);
880    test_pad_to_int32(0);
881    test_pad_to_int32(1);
882    test_pad_to_int32(2);
883    test_pad_to_int32(7);
884    test_pad_to_int32(8);
885    test_pad_to_int32(0xFF);
886    test_pad_to_int32(0x100);
887    test_pad_to_int32(0xFFFF);
888    test_pad_to_int32(0x10000);
889    test_pad_to_int32(0xFFFFFF);
890    test_pad_to_int32(0x1000000);
891    test_pad_to_int32(INT_MAX - 4);
892    test_pad_to_int32(INT_MAX - 3);
893}
894
895static void xi_unregister_handlers(void)
896{
897    DeviceIntRec dev;
898    int handler;
899
900    memset(&dev, 0, sizeof(dev));
901
902    handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
903    g_assert(handler == 1);
904    handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
905    g_assert(handler == 2);
906    handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
907    g_assert(handler == 3);
908
909    g_test_message("Unlinking from front.");
910
911    XIUnregisterPropertyHandler(&dev, 4); /* NOOP */
912    g_assert(dev.properties.handlers->id == 3);
913    XIUnregisterPropertyHandler(&dev, 3);
914    g_assert(dev.properties.handlers->id == 2);
915    XIUnregisterPropertyHandler(&dev, 2);
916    g_assert(dev.properties.handlers->id == 1);
917    XIUnregisterPropertyHandler(&dev, 1);
918    g_assert(dev.properties.handlers == NULL);
919
920    handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
921    g_assert(handler == 4);
922    handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
923    g_assert(handler == 5);
924    handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
925    g_assert(handler == 6);
926    XIUnregisterPropertyHandler(&dev, 3); /* NOOP */
927    g_assert(dev.properties.handlers->next->next->next == NULL);
928    XIUnregisterPropertyHandler(&dev, 4);
929    g_assert(dev.properties.handlers->next->next == NULL);
930    XIUnregisterPropertyHandler(&dev, 5);
931    g_assert(dev.properties.handlers->next == NULL);
932    XIUnregisterPropertyHandler(&dev, 6);
933    g_assert(dev.properties.handlers == NULL);
934
935    handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
936    g_assert(handler == 7);
937    handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
938    g_assert(handler == 8);
939    handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
940    g_assert(handler == 9);
941
942    XIDeleteAllDeviceProperties(&dev);
943    g_assert(dev.properties.handlers == NULL);
944    XIUnregisterPropertyHandler(&dev, 7); /* NOOP */
945
946}
947
948static void cmp_attr_fields(InputAttributes *attr1,
949                            InputAttributes *attr2)
950{
951    char **tags1, **tags2;
952
953    g_assert(attr1 && attr2);
954    g_assert(attr1 != attr2);
955    g_assert(attr1->flags == attr2->flags);
956
957    if (attr1->product != NULL)
958    {
959        g_assert(attr1->product != attr2->product);
960        g_assert(strcmp(attr1->product, attr2->product) == 0);
961    } else
962        g_assert(attr2->product == NULL);
963
964    if (attr1->vendor != NULL)
965    {
966        g_assert(attr1->vendor != attr2->vendor);
967        g_assert(strcmp(attr1->vendor, attr2->vendor) == 0);
968    } else
969        g_assert(attr2->vendor == NULL);
970
971    if (attr1->device != NULL)
972    {
973        g_assert(attr1->device != attr2->device);
974        g_assert(strcmp(attr1->device, attr2->device) == 0);
975    } else
976        g_assert(attr2->device == NULL);
977
978    if (attr1->pnp_id != NULL)
979    {
980        g_assert(attr1->pnp_id != attr2->pnp_id);
981        g_assert(strcmp(attr1->pnp_id, attr2->pnp_id) == 0);
982    } else
983        g_assert(attr2->pnp_id == NULL);
984
985    if (attr1->usb_id != NULL)
986    {
987        g_assert(attr1->usb_id != attr2->usb_id);
988        g_assert(strcmp(attr1->usb_id, attr2->usb_id) == 0);
989    } else
990        g_assert(attr2->usb_id == NULL);
991
992    tags1 = attr1->tags;
993    tags2 = attr2->tags;
994
995    /* if we don't have any tags, skip the tag checking bits */
996    if (!tags1)
997    {
998        g_assert(!tags2);
999        return;
1000    }
1001
1002    /* Don't lug around empty arrays */
1003    g_assert(*tags1);
1004    g_assert(*tags2);
1005
1006    /* check for identical content, but duplicated */
1007    while (*tags1)
1008    {
1009        g_assert(*tags1 != *tags2);
1010        g_assert(strcmp(*tags1, *tags2) == 0);
1011        tags1++;
1012        tags2++;
1013    }
1014
1015    /* ensure tags1 and tags2 have the same no of elements */
1016    g_assert(!*tags2);
1017
1018    /* check for not sharing memory */
1019    tags1 = attr1->tags;
1020    while (*tags1)
1021    {
1022        tags2 = attr2->tags;
1023        while (*tags2)
1024            g_assert(*tags1 != *tags2++);
1025
1026        tags1++;
1027    }
1028}
1029
1030static void dix_input_attributes(void)
1031{
1032    InputAttributes orig = {0};
1033    InputAttributes *new;
1034    char *tags[4] = {"tag1", "tag2", "tag2", NULL};
1035
1036    new = DuplicateInputAttributes(NULL);
1037    g_assert(!new);
1038
1039    new = DuplicateInputAttributes(&orig);
1040    g_assert(memcmp(&orig, new, sizeof(InputAttributes)) == 0);
1041
1042    orig.product = "product name";
1043    new = DuplicateInputAttributes(&orig);
1044    cmp_attr_fields(&orig, new);
1045    FreeInputAttributes(new);
1046
1047    orig.vendor = "vendor name";
1048    new = DuplicateInputAttributes(&orig);
1049    cmp_attr_fields(&orig, new);
1050    FreeInputAttributes(new);
1051
1052    orig.device = "device path";
1053    new = DuplicateInputAttributes(&orig);
1054    cmp_attr_fields(&orig, new);
1055    FreeInputAttributes(new);
1056
1057    orig.pnp_id = "PnPID";
1058    new = DuplicateInputAttributes(&orig);
1059    cmp_attr_fields(&orig, new);
1060    FreeInputAttributes(new);
1061
1062    orig.usb_id = "USBID";
1063    new = DuplicateInputAttributes(&orig);
1064    cmp_attr_fields(&orig, new);
1065    FreeInputAttributes(new);
1066
1067    orig.flags = 0xF0;
1068    new = DuplicateInputAttributes(&orig);
1069    cmp_attr_fields(&orig, new);
1070    FreeInputAttributes(new);
1071
1072    orig.tags = tags;
1073    new = DuplicateInputAttributes(&orig);
1074    cmp_attr_fields(&orig, new);
1075    FreeInputAttributes(new);
1076}
1077
1078static void dix_input_valuator_masks(void)
1079{
1080    ValuatorMask *mask = NULL, *copy;
1081    int nvaluators = MAX_VALUATORS;
1082    int valuators[nvaluators];
1083    int i;
1084    int first_val, num_vals;
1085
1086    for (i = 0; i < nvaluators; i++)
1087        valuators[i] = i;
1088
1089    mask = valuator_mask_new(nvaluators);
1090    g_assert(mask != NULL);
1091    g_assert(valuator_mask_size(mask) == 0);
1092    g_assert(valuator_mask_num_valuators(mask) == 0);
1093
1094    for (i = 0; i < nvaluators; i++)
1095    {
1096        g_assert(!valuator_mask_isset(mask, i));
1097        valuator_mask_set(mask, i, valuators[i]);
1098        g_assert(valuator_mask_isset(mask, i));
1099        g_assert(valuator_mask_get(mask, i) == valuators[i]);
1100        g_assert(valuator_mask_size(mask) == i + 1);
1101        g_assert(valuator_mask_num_valuators(mask) == i + 1);
1102    }
1103
1104    for (i = 0; i < nvaluators; i++)
1105    {
1106        g_assert(valuator_mask_isset(mask, i));
1107        valuator_mask_unset(mask, i);
1108        /* we're removing valuators from the front, so size should stay the
1109         * same until the last bit is removed */
1110        if (i < nvaluators - 1)
1111            g_assert(valuator_mask_size(mask) == nvaluators);
1112        g_assert(!valuator_mask_isset(mask, i));
1113    }
1114
1115    g_assert(valuator_mask_size(mask) == 0);
1116    valuator_mask_zero(mask);
1117    g_assert(valuator_mask_size(mask) == 0);
1118    g_assert(valuator_mask_num_valuators(mask) == 0);
1119    for (i = 0; i < nvaluators; i++)
1120        g_assert(!valuator_mask_isset(mask, i));
1121
1122    first_val = 5;
1123    num_vals = 6;
1124
1125    valuator_mask_set_range(mask, first_val, num_vals, valuators);
1126    g_assert(valuator_mask_size(mask) == first_val + num_vals);
1127    g_assert(valuator_mask_num_valuators(mask) == num_vals);
1128    for (i = 0; i < nvaluators; i++)
1129    {
1130        if (i < first_val || i >= first_val + num_vals)
1131            g_assert(!valuator_mask_isset(mask, i));
1132        else
1133        {
1134            g_assert(valuator_mask_isset(mask, i));
1135            g_assert(valuator_mask_get(mask, i) == valuators[i - first_val]);
1136        }
1137    }
1138
1139    copy = valuator_mask_new(nvaluators);
1140    valuator_mask_copy(copy, mask);
1141    g_assert(mask != copy);
1142    g_assert(valuator_mask_size(mask) == valuator_mask_size(copy));
1143    g_assert(valuator_mask_num_valuators(mask) == valuator_mask_num_valuators(copy));
1144
1145    for (i = 0; i < nvaluators; i++)
1146    {
1147        g_assert(valuator_mask_isset(mask, i) == valuator_mask_isset(copy, i));
1148        g_assert(valuator_mask_get(mask, i) == valuator_mask_get(copy, i));
1149    }
1150
1151    valuator_mask_free(&mask);
1152    g_assert(mask == NULL);
1153}
1154
1155static void dix_valuator_mode(void)
1156{
1157    DeviceIntRec dev;
1158    const int num_axes = MAX_VALUATORS;
1159    int i;
1160    Atom atoms[MAX_VALUATORS] = { 0 };
1161
1162    memset(&dev, 0, sizeof(DeviceIntRec));
1163    dev.type = MASTER_POINTER; /* claim it's a master to stop ptracccel */
1164
1165    g_assert(InitValuatorClassDeviceStruct(NULL, 0, atoms, 0, 0) == FALSE);
1166    g_assert(InitValuatorClassDeviceStruct(&dev, num_axes, atoms, 0, Absolute));
1167
1168    for (i = 0; i < num_axes; i++)
1169    {
1170        g_assert(valuator_get_mode(&dev, i) == Absolute);
1171        valuator_set_mode(&dev, i, Relative);
1172        g_assert(dev.valuator->axes[i].mode == Relative);
1173        g_assert(valuator_get_mode(&dev, i) == Relative);
1174    }
1175
1176    valuator_set_mode(&dev, VALUATOR_MODE_ALL_AXES, Absolute);
1177    for (i = 0; i < num_axes; i++)
1178        g_assert(valuator_get_mode(&dev, i) == Absolute);
1179
1180    valuator_set_mode(&dev, VALUATOR_MODE_ALL_AXES, Relative);
1181    for (i = 0; i < num_axes; i++)
1182        g_assert(valuator_get_mode(&dev, i) == Relative);
1183}
1184
1185static void include_bit_test_macros(void)
1186{
1187    uint8_t mask[9] = { 0 };
1188    int i;
1189
1190    for (i = 0; i < sizeof(mask)/sizeof(mask[0]); i++)
1191    {
1192        g_assert(BitIsOn(mask, i) == 0);
1193        SetBit(mask, i);
1194        g_assert(BitIsOn(mask, i) == 1);
1195        g_assert(!!(mask[i/8] & (1 << (i % 8))));
1196        g_assert(CountBits(mask, sizeof(mask)) == 1);
1197        ClearBit(mask, i);
1198        g_assert(BitIsOn(mask, i) == 0);
1199    }
1200}
1201
1202/**
1203 * Ensure that val->axisVal and val->axes are aligned on doubles.
1204 */
1205static void dix_valuator_alloc(void)
1206{
1207    ValuatorClassPtr v = NULL;
1208    int num_axes = 0;
1209
1210    while (num_axes < 5)
1211    {
1212        v = AllocValuatorClass(v, num_axes);
1213
1214        g_assert(v);
1215        g_assert(v->numAxes == num_axes);
1216#ifndef __i386__
1217        /* must be double-aligned on 64 bit */
1218        g_assert(((void*)v->axisVal - (void*)v) % sizeof(double) == 0);
1219        g_assert(((void*)v->axes - (void*)v) % sizeof(double) == 0);
1220#endif
1221        num_axes ++;
1222    }
1223
1224    free(v);
1225}
1226
1227int main(int argc, char** argv)
1228{
1229    g_test_init(&argc, &argv,NULL);
1230    g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id=");
1231
1232    g_test_add_func("/dix/input/valuator-masks", dix_input_valuator_masks);
1233    g_test_add_func("/dix/input/attributes", dix_input_attributes);
1234    g_test_add_func("/dix/input/init-valuators", dix_init_valuators);
1235    g_test_add_func("/dix/input/event-core-conversion", dix_event_to_core_conversion);
1236    g_test_add_func("/dix/input/event-xi1-conversion", dix_event_to_xi1_conversion);
1237    g_test_add_func("/dix/input/check-grab-values", dix_check_grab_values);
1238    g_test_add_func("/dix/input/xi2-struct-sizes", xi2_struct_sizes);
1239    g_test_add_func("/dix/input/grab_matching", dix_grab_matching);
1240    g_test_add_func("/dix/input/valuator_mode", dix_valuator_mode);
1241    g_test_add_func("/include/byte_padding_macros", include_byte_padding_macros);
1242    g_test_add_func("/include/bit_test_macros", include_bit_test_macros);
1243    g_test_add_func("/Xi/xiproperty/register-unregister", xi_unregister_handlers);
1244    g_test_add_func("/dix/input/valuator-alloc", dix_valuator_alloc);
1245
1246    return g_test_run();
1247}
1248