1706f2543Smrg/**
2706f2543Smrg * Copyright © 2009 Red Hat, Inc.
3706f2543Smrg *
4706f2543Smrg *  Permission is hereby granted, free of charge, to any person obtaining a
5706f2543Smrg *  copy of this software and associated documentation files (the "Software"),
6706f2543Smrg *  to deal in the Software without restriction, including without limitation
7706f2543Smrg *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
8706f2543Smrg *  and/or sell copies of the Software, and to permit persons to whom the
9706f2543Smrg *  Software is furnished to do so, subject to the following conditions:
10706f2543Smrg *
11706f2543Smrg *  The above copyright notice and this permission notice (including the next
12706f2543Smrg *  paragraph) shall be included in all copies or substantial portions of the
13706f2543Smrg *  Software.
14706f2543Smrg *
15706f2543Smrg *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16706f2543Smrg *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17706f2543Smrg *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18706f2543Smrg *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19706f2543Smrg *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20706f2543Smrg *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21706f2543Smrg *  DEALINGS IN THE SOFTWARE.
22706f2543Smrg */
23706f2543Smrg
24706f2543Smrg#ifdef HAVE_DIX_CONFIG_H
25706f2543Smrg#include <dix-config.h>
26706f2543Smrg#endif
27706f2543Smrg
28706f2543Smrg#include <stdint.h>
29706f2543Smrg#include <X11/X.h>
30706f2543Smrg#include "misc.h"
31706f2543Smrg#include "resource.h"
32706f2543Smrg#include <X11/Xproto.h>
33706f2543Smrg#include <X11/extensions/XI2proto.h>
34706f2543Smrg#include <X11/Xatom.h>
35706f2543Smrg#include "windowstr.h"
36706f2543Smrg#include "inputstr.h"
37706f2543Smrg#include "eventconvert.h"
38706f2543Smrg#include "exevents.h"
39706f2543Smrg#include "exglobals.h"
40706f2543Smrg#include "dixgrabs.h"
41706f2543Smrg#include "eventstr.h"
42706f2543Smrg#include "inpututils.h"
43706f2543Smrg#include <glib.h>
44706f2543Smrg
45706f2543Smrg/**
46706f2543Smrg * Init a device with axes.
47706f2543Smrg * Verify values set on the device.
48706f2543Smrg *
49706f2543Smrg * Result: All axes set to default values (usually 0).
50706f2543Smrg */
51706f2543Smrgstatic void dix_init_valuators(void)
52706f2543Smrg{
53706f2543Smrg    DeviceIntRec dev;
54706f2543Smrg    ValuatorClassPtr val;
55706f2543Smrg    const int num_axes = 2;
56706f2543Smrg    int i;
57706f2543Smrg    Atom atoms[MAX_VALUATORS] = { 0 };
58706f2543Smrg
59706f2543Smrg
60706f2543Smrg    memset(&dev, 0, sizeof(DeviceIntRec));
61706f2543Smrg    dev.type = MASTER_POINTER; /* claim it's a master to stop ptracccel */
62706f2543Smrg
63706f2543Smrg    g_assert(InitValuatorClassDeviceStruct(NULL, 0, atoms, 0, 0) == FALSE);
64706f2543Smrg    g_assert(InitValuatorClassDeviceStruct(&dev, num_axes, atoms, 0, Absolute));
65706f2543Smrg
66706f2543Smrg    val = dev.valuator;
67706f2543Smrg    g_assert(val);
68706f2543Smrg    g_assert(val->numAxes == num_axes);
69706f2543Smrg    g_assert(val->numMotionEvents == 0);
70706f2543Smrg    g_assert(val->axisVal);
71706f2543Smrg
72706f2543Smrg    for (i = 0; i < num_axes; i++)
73706f2543Smrg    {
74706f2543Smrg        g_assert(val->axisVal[i] == 0);
75706f2543Smrg        g_assert(val->axes->min_value == NO_AXIS_LIMITS);
76706f2543Smrg        g_assert(val->axes->max_value == NO_AXIS_LIMITS);
77706f2543Smrg        g_assert(val->axes->mode == Absolute);
78706f2543Smrg    }
79706f2543Smrg
80706f2543Smrg    g_assert(dev.last.numValuators == num_axes);
81706f2543Smrg}
82706f2543Smrg
83706f2543Smrg/* just check the known success cases, and that error cases set the client's
84706f2543Smrg * error value correctly. */
85706f2543Smrgstatic void dix_check_grab_values(void)
86706f2543Smrg{
87706f2543Smrg    ClientRec client;
88706f2543Smrg    GrabParameters param;
89706f2543Smrg    int rc;
90706f2543Smrg
91706f2543Smrg    memset(&client, 0, sizeof(client));
92706f2543Smrg
93706f2543Smrg    param.grabtype = GRABTYPE_CORE;
94706f2543Smrg    param.this_device_mode = GrabModeSync;
95706f2543Smrg    param.other_devices_mode = GrabModeSync;
96706f2543Smrg    param.modifiers = AnyModifier;
97706f2543Smrg    param.ownerEvents = FALSE;
98706f2543Smrg
99706f2543Smrg    rc = CheckGrabValues(&client, &param);
100706f2543Smrg    g_assert(rc == Success);
101706f2543Smrg
102706f2543Smrg    param.this_device_mode = GrabModeAsync;
103706f2543Smrg    rc = CheckGrabValues(&client, &param);
104706f2543Smrg    g_assert(rc == Success);
105706f2543Smrg
106706f2543Smrg    param.this_device_mode = GrabModeAsync + 1;
107706f2543Smrg    rc = CheckGrabValues(&client, &param);
108706f2543Smrg    g_assert(rc == BadValue);
109706f2543Smrg    g_assert(client.errorValue == param.this_device_mode);
110706f2543Smrg    g_assert(client.errorValue == GrabModeAsync + 1);
111706f2543Smrg
112706f2543Smrg    param.this_device_mode = GrabModeSync;
113706f2543Smrg    param.other_devices_mode = GrabModeAsync;
114706f2543Smrg    rc = CheckGrabValues(&client, &param);
115706f2543Smrg    g_assert(rc == Success);
116706f2543Smrg
117706f2543Smrg    param.other_devices_mode = GrabModeAsync + 1;
118706f2543Smrg    rc = CheckGrabValues(&client, &param);
119706f2543Smrg    g_assert(rc == BadValue);
120706f2543Smrg    g_assert(client.errorValue == param.other_devices_mode);
121706f2543Smrg    g_assert(client.errorValue == GrabModeAsync + 1);
122706f2543Smrg
123706f2543Smrg    param.other_devices_mode = GrabModeSync;
124706f2543Smrg
125706f2543Smrg    param.modifiers = 1 << 13;
126706f2543Smrg    rc = CheckGrabValues(&client, &param);
127706f2543Smrg    g_assert(rc == BadValue);
128706f2543Smrg    g_assert(client.errorValue == param.modifiers);
129706f2543Smrg    g_assert(client.errorValue == (1 << 13));
130706f2543Smrg
131706f2543Smrg
132706f2543Smrg    param.modifiers = AnyModifier;
133706f2543Smrg    param.ownerEvents = TRUE;
134706f2543Smrg    rc = CheckGrabValues(&client, &param);
135706f2543Smrg    g_assert(rc == Success);
136706f2543Smrg
137706f2543Smrg    param.ownerEvents = 3;
138706f2543Smrg    rc = CheckGrabValues(&client, &param);
139706f2543Smrg    g_assert(rc == BadValue);
140706f2543Smrg    g_assert(client.errorValue == param.ownerEvents);
141706f2543Smrg    g_assert(client.errorValue == 3);
142706f2543Smrg}
143706f2543Smrg
144706f2543Smrg
145706f2543Smrg/**
146706f2543Smrg * Convert various internal events to the matching core event and verify the
147706f2543Smrg * parameters.
148706f2543Smrg */
149706f2543Smrgstatic void dix_event_to_core(int type)
150706f2543Smrg{
151706f2543Smrg    DeviceEvent ev;
152706f2543Smrg    xEvent core;
153706f2543Smrg    int time;
154706f2543Smrg    int x, y;
155706f2543Smrg    int rc;
156706f2543Smrg    int state;
157706f2543Smrg    int detail;
158706f2543Smrg    const int ROOT_WINDOW_ID = 0x100;
159706f2543Smrg
160706f2543Smrg    /* EventToCore memsets the event to 0 */
161706f2543Smrg#define test_event() \
162706f2543Smrg    g_assert(rc == Success); \
163706f2543Smrg    g_assert(core.u.u.type == type); \
164706f2543Smrg    g_assert(core.u.u.detail == detail); \
165706f2543Smrg    g_assert(core.u.keyButtonPointer.time == time); \
166706f2543Smrg    g_assert(core.u.keyButtonPointer.rootX == x); \
167706f2543Smrg    g_assert(core.u.keyButtonPointer.rootY == y); \
168706f2543Smrg    g_assert(core.u.keyButtonPointer.state == state); \
169706f2543Smrg    g_assert(core.u.keyButtonPointer.eventX == 0); \
170706f2543Smrg    g_assert(core.u.keyButtonPointer.eventY == 0); \
171706f2543Smrg    g_assert(core.u.keyButtonPointer.root == ROOT_WINDOW_ID); \
172706f2543Smrg    g_assert(core.u.keyButtonPointer.event == 0); \
173706f2543Smrg    g_assert(core.u.keyButtonPointer.child == 0); \
174706f2543Smrg    g_assert(core.u.keyButtonPointer.sameScreen == FALSE);
175706f2543Smrg
176706f2543Smrg    x = 0;
177706f2543Smrg    y = 0;
178706f2543Smrg    time = 12345;
179706f2543Smrg    state = 0;
180706f2543Smrg    detail = 0;
181706f2543Smrg
182706f2543Smrg    ev.header   = 0xFF;
183706f2543Smrg    ev.length   = sizeof(DeviceEvent);
184706f2543Smrg    ev.time     = time;
185706f2543Smrg    ev.root_y   = x;
186706f2543Smrg    ev.root_x   = y;
187706f2543Smrg    SetBit(ev.valuators.mask, 0);
188706f2543Smrg    SetBit(ev.valuators.mask, 1);
189706f2543Smrg    ev.root     = ROOT_WINDOW_ID;
190706f2543Smrg    ev.corestate = state;
191706f2543Smrg    ev.detail.key = detail;
192706f2543Smrg
193706f2543Smrg    ev.type = type;
194706f2543Smrg    ev.detail.key = 0;
195706f2543Smrg    rc = EventToCore((InternalEvent*)&ev, &core);
196706f2543Smrg    test_event();
197706f2543Smrg
198706f2543Smrg    x = 1;
199706f2543Smrg    y = 2;
200706f2543Smrg    ev.root_x = x;
201706f2543Smrg    ev.root_y = y;
202706f2543Smrg    rc = EventToCore((InternalEvent*)&ev, &core);
203706f2543Smrg    test_event();
204706f2543Smrg
205706f2543Smrg    x = 0x7FFF;
206706f2543Smrg    y = 0x7FFF;
207706f2543Smrg    ev.root_x = x;
208706f2543Smrg    ev.root_y = y;
209706f2543Smrg    rc = EventToCore((InternalEvent*)&ev, &core);
210706f2543Smrg    test_event();
211706f2543Smrg
212706f2543Smrg    x = 0x8000; /* too high */
213706f2543Smrg    y = 0x8000; /* too high */
214706f2543Smrg    ev.root_x = x;
215706f2543Smrg    ev.root_y = y;
216706f2543Smrg    rc = EventToCore((InternalEvent*)&ev, &core);
217706f2543Smrg    g_assert(core.u.keyButtonPointer.rootX != x);
218706f2543Smrg    g_assert(core.u.keyButtonPointer.rootY != y);
219706f2543Smrg
220706f2543Smrg    x = 0x7FFF;
221706f2543Smrg    y = 0x7FFF;
222706f2543Smrg    ev.root_x = x;
223706f2543Smrg    ev.root_y = y;
224706f2543Smrg    time = 0;
225706f2543Smrg    ev.time = time;
226706f2543Smrg    rc = EventToCore((InternalEvent*)&ev, &core);
227706f2543Smrg    test_event();
228706f2543Smrg
229706f2543Smrg    detail = 1;
230706f2543Smrg    ev.detail.key = detail;
231706f2543Smrg    rc = EventToCore((InternalEvent*)&ev, &core);
232706f2543Smrg    test_event();
233706f2543Smrg
234706f2543Smrg    detail = 0xFF; /* highest value */
235706f2543Smrg    ev.detail.key = detail;
236706f2543Smrg    rc = EventToCore((InternalEvent*)&ev, &core);
237706f2543Smrg    test_event();
238706f2543Smrg
239706f2543Smrg    detail = 0xFFF; /* too big */
240706f2543Smrg    ev.detail.key = detail;
241706f2543Smrg    rc = EventToCore((InternalEvent*)&ev, &core);
242706f2543Smrg    g_assert(rc == BadMatch);
243706f2543Smrg
244706f2543Smrg    detail = 0xFF; /* too big */
245706f2543Smrg    ev.detail.key = detail;
246706f2543Smrg    state = 0xFFFF; /* highest value */
247706f2543Smrg    ev.corestate = state;
248706f2543Smrg    rc = EventToCore((InternalEvent*)&ev, &core);
249706f2543Smrg    test_event();
250706f2543Smrg
251706f2543Smrg    state = 0x10000; /* too big */
252706f2543Smrg    ev.corestate = state;
253706f2543Smrg    rc = EventToCore((InternalEvent*)&ev, &core);
254706f2543Smrg    g_assert(core.u.keyButtonPointer.state != state);
255706f2543Smrg    g_assert(core.u.keyButtonPointer.state == (state & 0xFFFF));
256706f2543Smrg
257706f2543Smrg#undef test_event
258706f2543Smrg}
259706f2543Smrg
260706f2543Smrgstatic void dix_event_to_core_fail(int evtype, int expected_rc)
261706f2543Smrg{
262706f2543Smrg    DeviceEvent ev;
263706f2543Smrg    xEvent core;
264706f2543Smrg    int rc;
265706f2543Smrg
266706f2543Smrg    ev.header   = 0xFF;
267706f2543Smrg    ev.length   = sizeof(DeviceEvent);
268706f2543Smrg
269706f2543Smrg    ev.type     = evtype;
270706f2543Smrg    rc = EventToCore((InternalEvent*)&ev, &core);
271706f2543Smrg    g_assert(rc == expected_rc);
272706f2543Smrg}
273706f2543Smrg
274706f2543Smrgstatic void dix_event_to_core_conversion(void)
275706f2543Smrg{
276706f2543Smrg    dix_event_to_core_fail(0, BadImplementation);
277706f2543Smrg    dix_event_to_core_fail(1, BadImplementation);
278706f2543Smrg    dix_event_to_core_fail(ET_ProximityOut + 1, BadImplementation);
279706f2543Smrg    dix_event_to_core_fail(ET_ProximityIn, BadMatch);
280706f2543Smrg    dix_event_to_core_fail(ET_ProximityOut, BadMatch);
281706f2543Smrg
282706f2543Smrg    dix_event_to_core(ET_KeyPress);
283706f2543Smrg    dix_event_to_core(ET_KeyRelease);
284706f2543Smrg    dix_event_to_core(ET_ButtonPress);
285706f2543Smrg    dix_event_to_core(ET_ButtonRelease);
286706f2543Smrg    dix_event_to_core(ET_Motion);
287706f2543Smrg}
288706f2543Smrg
289706f2543Smrgstatic void
290706f2543Smrg_dix_test_xi_convert(DeviceEvent *ev, int expected_rc, int expected_count)
291706f2543Smrg{
292706f2543Smrg    xEvent *xi;
293706f2543Smrg    int count = 0;
294706f2543Smrg    int rc;
295706f2543Smrg
296706f2543Smrg    rc = EventToXI((InternalEvent*)ev, &xi, &count);
297706f2543Smrg    g_assert(rc == expected_rc);
298706f2543Smrg    g_assert(count >= expected_count);
299706f2543Smrg    if (count > 0){
300706f2543Smrg        deviceKeyButtonPointer *kbp = (deviceKeyButtonPointer*)xi;
301706f2543Smrg        g_assert(kbp->type == IEventBase + ev->type);
302706f2543Smrg        g_assert(kbp->detail == ev->detail.key);
303706f2543Smrg        g_assert(kbp->time == ev->time);
304706f2543Smrg        g_assert((kbp->deviceid & ~MORE_EVENTS) == ev->deviceid);
305706f2543Smrg        g_assert(kbp->root_x == ev->root_x);
306706f2543Smrg        g_assert(kbp->root_y == ev->root_y);
307706f2543Smrg        g_assert(kbp->state == ev->corestate);
308706f2543Smrg        g_assert(kbp->event_x == 0);
309706f2543Smrg        g_assert(kbp->event_y == 0);
310706f2543Smrg        g_assert(kbp->root == ev->root);
311706f2543Smrg        g_assert(kbp->event == 0);
312706f2543Smrg        g_assert(kbp->child == 0);
313706f2543Smrg        g_assert(kbp->same_screen == FALSE);
314706f2543Smrg
315706f2543Smrg        while (--count > 0) {
316706f2543Smrg            deviceValuator *v = (deviceValuator*)&xi[count];
317706f2543Smrg            g_assert(v->type == DeviceValuator);
318706f2543Smrg            g_assert(v->num_valuators <= 6);
319706f2543Smrg        }
320706f2543Smrg
321706f2543Smrg
322706f2543Smrg        free(xi);
323706f2543Smrg    }
324706f2543Smrg}
325706f2543Smrg
326706f2543Smrg/**
327706f2543Smrg * This tests for internal event → XI1 event conversion
328706f2543Smrg * - all conversions should generate the right XI event type
329706f2543Smrg * - right number of events generated
330706f2543Smrg * - extra events are valuators
331706f2543Smrg */
332706f2543Smrgstatic void dix_event_to_xi1_conversion(void)
333706f2543Smrg{
334706f2543Smrg    DeviceEvent ev = {0};
335706f2543Smrg    int time;
336706f2543Smrg    int x, y;
337706f2543Smrg    int state;
338706f2543Smrg    int detail;
339706f2543Smrg    const int ROOT_WINDOW_ID = 0x100;
340706f2543Smrg    int deviceid;
341706f2543Smrg
342706f2543Smrg    IEventBase = 80;
343706f2543Smrg    DeviceValuator      = IEventBase - 1;
344706f2543Smrg    DeviceKeyPress      = IEventBase + ET_KeyPress;
345706f2543Smrg    DeviceKeyRelease    = IEventBase + ET_KeyRelease;
346706f2543Smrg    DeviceButtonPress   = IEventBase + ET_ButtonPress;
347706f2543Smrg    DeviceButtonRelease = IEventBase + ET_ButtonRelease;
348706f2543Smrg    DeviceMotionNotify  = IEventBase + ET_Motion;
349706f2543Smrg    DeviceFocusIn       = IEventBase + ET_FocusIn;
350706f2543Smrg    DeviceFocusOut      = IEventBase + ET_FocusOut;
351706f2543Smrg    ProximityIn         = IEventBase + ET_ProximityIn;
352706f2543Smrg    ProximityOut        = IEventBase + ET_ProximityOut;
353706f2543Smrg
354706f2543Smrg    /* EventToXI callocs */
355706f2543Smrg    x = 0;
356706f2543Smrg    y = 0;
357706f2543Smrg    time = 12345;
358706f2543Smrg    state = 0;
359706f2543Smrg    detail = 0;
360706f2543Smrg    deviceid = 4;
361706f2543Smrg
362706f2543Smrg    ev.header   = 0xFF;
363706f2543Smrg
364706f2543Smrg    ev.header           = 0xFF;
365706f2543Smrg    ev.length           = sizeof(DeviceEvent);
366706f2543Smrg    ev.time             = time;
367706f2543Smrg    ev.root_y           = x;
368706f2543Smrg    ev.root_x           = y;
369706f2543Smrg    SetBit(ev.valuators.mask, 0);
370706f2543Smrg    SetBit(ev.valuators.mask, 1);
371706f2543Smrg    ev.root             = ROOT_WINDOW_ID;
372706f2543Smrg    ev.corestate        = state;
373706f2543Smrg    ev.detail.key       = detail;
374706f2543Smrg    ev.deviceid         = deviceid;
375706f2543Smrg
376706f2543Smrg    /* test all types for bad match */
377706f2543Smrg    ev.type = ET_KeyPress;         _dix_test_xi_convert(&ev, Success, 1);
378706f2543Smrg    ev.type = ET_KeyRelease;       _dix_test_xi_convert(&ev, Success, 1);
379706f2543Smrg    ev.type = ET_ButtonPress;      _dix_test_xi_convert(&ev, Success, 1);
380706f2543Smrg    ev.type = ET_ButtonRelease;    _dix_test_xi_convert(&ev, Success, 1);
381706f2543Smrg    ev.type = ET_Motion;           _dix_test_xi_convert(&ev, Success, 1);
382706f2543Smrg    ev.type = ET_ProximityIn;      _dix_test_xi_convert(&ev, Success, 1);
383706f2543Smrg    ev.type = ET_ProximityOut;     _dix_test_xi_convert(&ev, Success, 1);
384706f2543Smrg
385706f2543Smrg    /* No axes */
386706f2543Smrg    ClearBit(ev.valuators.mask, 0);
387706f2543Smrg    ClearBit(ev.valuators.mask, 1);
388706f2543Smrg    ev.type = ET_KeyPress;         _dix_test_xi_convert(&ev, Success, 1);
389706f2543Smrg    ev.type = ET_KeyRelease;       _dix_test_xi_convert(&ev, Success, 1);
390706f2543Smrg    ev.type = ET_ButtonPress;      _dix_test_xi_convert(&ev, Success, 1);
391706f2543Smrg    ev.type = ET_ButtonRelease;    _dix_test_xi_convert(&ev, Success, 1);
392706f2543Smrg    ev.type = ET_Motion;           _dix_test_xi_convert(&ev, BadMatch, 0);
393706f2543Smrg    ev.type = ET_ProximityIn;      _dix_test_xi_convert(&ev, BadMatch, 0);
394706f2543Smrg    ev.type = ET_ProximityOut;     _dix_test_xi_convert(&ev, BadMatch, 0);
395706f2543Smrg
396706f2543Smrg    /* more than 6 axes → 2 valuator events */
397706f2543Smrg    SetBit(ev.valuators.mask, 0);
398706f2543Smrg    SetBit(ev.valuators.mask, 1);
399706f2543Smrg    SetBit(ev.valuators.mask, 2);
400706f2543Smrg    SetBit(ev.valuators.mask, 3);
401706f2543Smrg    SetBit(ev.valuators.mask, 4);
402706f2543Smrg    SetBit(ev.valuators.mask, 5);
403706f2543Smrg    SetBit(ev.valuators.mask, 6);
404706f2543Smrg    ev.type = ET_KeyPress;         _dix_test_xi_convert(&ev, Success, 2);
405706f2543Smrg    ev.type = ET_KeyRelease;       _dix_test_xi_convert(&ev, Success, 2);
406706f2543Smrg    ev.type = ET_ButtonPress;      _dix_test_xi_convert(&ev, Success, 2);
407706f2543Smrg    ev.type = ET_ButtonRelease;    _dix_test_xi_convert(&ev, Success, 2);
408706f2543Smrg    ev.type = ET_Motion;           _dix_test_xi_convert(&ev, Success, 2);
409706f2543Smrg    ev.type = ET_ProximityIn;      _dix_test_xi_convert(&ev, Success, 2);
410706f2543Smrg    ev.type = ET_ProximityOut;     _dix_test_xi_convert(&ev, Success, 2);
411706f2543Smrg
412706f2543Smrg
413706f2543Smrg    /* keycode too high */
414706f2543Smrg    ev.type = ET_KeyPress;
415706f2543Smrg    ev.detail.key = 256;
416706f2543Smrg    _dix_test_xi_convert(&ev, Success, 0);
417706f2543Smrg
418706f2543Smrg    /* deviceid too high */
419706f2543Smrg    ev.type = ET_KeyPress;
420706f2543Smrg    ev.detail.key = 18;
421706f2543Smrg    ev.deviceid = 128;
422706f2543Smrg    _dix_test_xi_convert(&ev, Success, 0);
423706f2543Smrg}
424706f2543Smrg
425706f2543Smrg
426706f2543Smrgstatic void xi2_struct_sizes(void)
427706f2543Smrg{
428706f2543Smrg#define compare(req) \
429706f2543Smrg    g_assert(sizeof(req) == sz_##req);
430706f2543Smrg
431706f2543Smrg    compare(xXIQueryVersionReq);
432706f2543Smrg    compare(xXIWarpPointerReq);
433706f2543Smrg    compare(xXIChangeCursorReq);
434706f2543Smrg    compare(xXIChangeHierarchyReq);
435706f2543Smrg    compare(xXISetClientPointerReq);
436706f2543Smrg    compare(xXIGetClientPointerReq);
437706f2543Smrg    compare(xXISelectEventsReq);
438706f2543Smrg    compare(xXIQueryVersionReq);
439706f2543Smrg    compare(xXIQueryDeviceReq);
440706f2543Smrg    compare(xXISetFocusReq);
441706f2543Smrg    compare(xXIGetFocusReq);
442706f2543Smrg    compare(xXIGrabDeviceReq);
443706f2543Smrg    compare(xXIUngrabDeviceReq);
444706f2543Smrg    compare(xXIAllowEventsReq);
445706f2543Smrg    compare(xXIPassiveGrabDeviceReq);
446706f2543Smrg    compare(xXIPassiveUngrabDeviceReq);
447706f2543Smrg    compare(xXIListPropertiesReq);
448706f2543Smrg    compare(xXIChangePropertyReq);
449706f2543Smrg    compare(xXIDeletePropertyReq);
450706f2543Smrg    compare(xXIGetPropertyReq);
451706f2543Smrg    compare(xXIGetSelectedEventsReq);
452706f2543Smrg#undef compare
453706f2543Smrg}
454706f2543Smrg
455706f2543Smrg
456706f2543Smrgstatic void dix_grab_matching(void)
457706f2543Smrg{
458706f2543Smrg    DeviceIntRec xi_all_devices, xi_all_master_devices, dev1, dev2;
459706f2543Smrg    GrabRec a, b;
460706f2543Smrg    BOOL rc;
461706f2543Smrg
462706f2543Smrg    memset(&a, 0, sizeof(a));
463706f2543Smrg    memset(&b, 0, sizeof(b));
464706f2543Smrg
465706f2543Smrg    /* different grabtypes must fail */
466706f2543Smrg    a.grabtype = GRABTYPE_CORE;
467706f2543Smrg    b.grabtype = GRABTYPE_XI2;
468706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
469706f2543Smrg    g_assert(rc == FALSE);
470706f2543Smrg    rc = GrabMatchesSecond(&b, &a, FALSE);
471706f2543Smrg    g_assert(rc == FALSE);
472706f2543Smrg
473706f2543Smrg    a.grabtype = GRABTYPE_XI;
474706f2543Smrg    b.grabtype = GRABTYPE_XI2;
475706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
476706f2543Smrg    g_assert(rc == FALSE);
477706f2543Smrg    rc = GrabMatchesSecond(&b, &a, FALSE);
478706f2543Smrg    g_assert(rc == FALSE);
479706f2543Smrg
480706f2543Smrg    a.grabtype = GRABTYPE_XI;
481706f2543Smrg    b.grabtype = GRABTYPE_CORE;
482706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
483706f2543Smrg    g_assert(rc == FALSE);
484706f2543Smrg    rc = GrabMatchesSecond(&b, &a, FALSE);
485706f2543Smrg    g_assert(rc == FALSE);
486706f2543Smrg
487706f2543Smrg    /* XI2 grabs for different devices must fail, regardless of ignoreDevice
488706f2543Smrg     * XI2 grabs for master devices must fail against a slave */
489706f2543Smrg    memset(&xi_all_devices, 0, sizeof(DeviceIntRec));
490706f2543Smrg    memset(&xi_all_master_devices, 0, sizeof(DeviceIntRec));
491706f2543Smrg    memset(&dev1, 0, sizeof(DeviceIntRec));
492706f2543Smrg    memset(&dev2, 0, sizeof(DeviceIntRec));
493706f2543Smrg
494706f2543Smrg    xi_all_devices.id = XIAllDevices;
495706f2543Smrg    xi_all_master_devices.id = XIAllMasterDevices;
496706f2543Smrg    dev1.id = 10;
497706f2543Smrg    dev1.type = SLAVE;
498706f2543Smrg    dev2.id = 11;
499706f2543Smrg    dev2.type = SLAVE;
500706f2543Smrg
501706f2543Smrg    inputInfo.all_devices = &xi_all_devices;
502706f2543Smrg    inputInfo.all_master_devices = &xi_all_master_devices;
503706f2543Smrg    a.grabtype = GRABTYPE_XI2;
504706f2543Smrg    b.grabtype = GRABTYPE_XI2;
505706f2543Smrg    a.device = &dev1;
506706f2543Smrg    b.device = &dev2;
507706f2543Smrg
508706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
509706f2543Smrg    g_assert(rc == FALSE);
510706f2543Smrg
511706f2543Smrg    a.device = &dev2;
512706f2543Smrg    b.device = &dev1;
513706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
514706f2543Smrg    g_assert(rc == FALSE);
515706f2543Smrg    rc = GrabMatchesSecond(&a, &b, TRUE);
516706f2543Smrg    g_assert(rc == FALSE);
517706f2543Smrg
518706f2543Smrg    a.device = inputInfo.all_master_devices;
519706f2543Smrg    b.device = &dev1;
520706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
521706f2543Smrg    g_assert(rc == FALSE);
522706f2543Smrg    rc = GrabMatchesSecond(&a, &b, TRUE);
523706f2543Smrg    g_assert(rc == FALSE);
524706f2543Smrg
525706f2543Smrg    a.device = &dev1;
526706f2543Smrg    b.device = inputInfo.all_master_devices;
527706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
528706f2543Smrg    g_assert(rc == FALSE);
529706f2543Smrg    rc = GrabMatchesSecond(&a, &b, TRUE);
530706f2543Smrg    g_assert(rc == FALSE);
531706f2543Smrg
532706f2543Smrg    /* ignoreDevice FALSE must fail for different devices for CORE and XI */
533706f2543Smrg    a.grabtype = GRABTYPE_XI;
534706f2543Smrg    b.grabtype = GRABTYPE_XI;
535706f2543Smrg    a.device = &dev1;
536706f2543Smrg    b.device = &dev2;
537706f2543Smrg    a.modifierDevice = &dev1;
538706f2543Smrg    b.modifierDevice = &dev1;
539706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
540706f2543Smrg    g_assert(rc == FALSE);
541706f2543Smrg
542706f2543Smrg    a.grabtype = GRABTYPE_CORE;
543706f2543Smrg    b.grabtype = GRABTYPE_CORE;
544706f2543Smrg    a.device = &dev1;
545706f2543Smrg    b.device = &dev2;
546706f2543Smrg    a.modifierDevice = &dev1;
547706f2543Smrg    b.modifierDevice = &dev1;
548706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
549706f2543Smrg    g_assert(rc == FALSE);
550706f2543Smrg
551706f2543Smrg    /* ignoreDevice FALSE must fail for different modifier devices for CORE
552706f2543Smrg     * and XI */
553706f2543Smrg    a.grabtype = GRABTYPE_XI;
554706f2543Smrg    b.grabtype = GRABTYPE_XI;
555706f2543Smrg    a.device = &dev1;
556706f2543Smrg    b.device = &dev1;
557706f2543Smrg    a.modifierDevice = &dev1;
558706f2543Smrg    b.modifierDevice = &dev2;
559706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
560706f2543Smrg    g_assert(rc == FALSE);
561706f2543Smrg
562706f2543Smrg    a.grabtype = GRABTYPE_CORE;
563706f2543Smrg    b.grabtype = GRABTYPE_CORE;
564706f2543Smrg    a.device = &dev1;
565706f2543Smrg    b.device = &dev1;
566706f2543Smrg    a.modifierDevice = &dev1;
567706f2543Smrg    b.modifierDevice = &dev2;
568706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
569706f2543Smrg    g_assert(rc == FALSE);
570706f2543Smrg
571706f2543Smrg    /* different event type must fail */
572706f2543Smrg    a.grabtype = GRABTYPE_XI2;
573706f2543Smrg    b.grabtype = GRABTYPE_XI2;
574706f2543Smrg    a.device = &dev1;
575706f2543Smrg    b.device = &dev1;
576706f2543Smrg    a.modifierDevice = &dev1;
577706f2543Smrg    b.modifierDevice = &dev1;
578706f2543Smrg    a.type = XI_KeyPress;
579706f2543Smrg    b.type = XI_KeyRelease;
580706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
581706f2543Smrg    g_assert(rc == FALSE);
582706f2543Smrg    rc = GrabMatchesSecond(&a, &b, TRUE);
583706f2543Smrg    g_assert(rc == FALSE);
584706f2543Smrg
585706f2543Smrg    a.grabtype = GRABTYPE_CORE;
586706f2543Smrg    b.grabtype = GRABTYPE_CORE;
587706f2543Smrg    a.device = &dev1;
588706f2543Smrg    b.device = &dev1;
589706f2543Smrg    a.modifierDevice = &dev1;
590706f2543Smrg    b.modifierDevice = &dev1;
591706f2543Smrg    a.type = XI_KeyPress;
592706f2543Smrg    b.type = XI_KeyRelease;
593706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
594706f2543Smrg    g_assert(rc == FALSE);
595706f2543Smrg    rc = GrabMatchesSecond(&a, &b, TRUE);
596706f2543Smrg    g_assert(rc == FALSE);
597706f2543Smrg
598706f2543Smrg    a.grabtype = GRABTYPE_XI;
599706f2543Smrg    b.grabtype = GRABTYPE_XI;
600706f2543Smrg    a.device = &dev1;
601706f2543Smrg    b.device = &dev1;
602706f2543Smrg    a.modifierDevice = &dev1;
603706f2543Smrg    b.modifierDevice = &dev1;
604706f2543Smrg    a.type = XI_KeyPress;
605706f2543Smrg    b.type = XI_KeyRelease;
606706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
607706f2543Smrg    g_assert(rc == FALSE);
608706f2543Smrg    rc = GrabMatchesSecond(&a, &b, TRUE);
609706f2543Smrg    g_assert(rc == FALSE);
610706f2543Smrg
611706f2543Smrg    /* different modifiers must fail */
612706f2543Smrg    a.grabtype = GRABTYPE_XI2;
613706f2543Smrg    b.grabtype = GRABTYPE_XI2;
614706f2543Smrg    a.device = &dev1;
615706f2543Smrg    b.device = &dev1;
616706f2543Smrg    a.modifierDevice = &dev1;
617706f2543Smrg    b.modifierDevice = &dev1;
618706f2543Smrg    a.type = XI_KeyPress;
619706f2543Smrg    b.type = XI_KeyPress;
620706f2543Smrg    a.modifiersDetail.exact = 1;
621706f2543Smrg    b.modifiersDetail.exact = 2;
622706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
623706f2543Smrg    g_assert(rc == FALSE);
624706f2543Smrg    rc = GrabMatchesSecond(&b, &a, FALSE);
625706f2543Smrg    g_assert(rc == FALSE);
626706f2543Smrg
627706f2543Smrg    a.grabtype = GRABTYPE_CORE;
628706f2543Smrg    b.grabtype = GRABTYPE_CORE;
629706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
630706f2543Smrg    g_assert(rc == FALSE);
631706f2543Smrg    rc = GrabMatchesSecond(&b, &a, FALSE);
632706f2543Smrg    g_assert(rc == FALSE);
633706f2543Smrg
634706f2543Smrg    a.grabtype = GRABTYPE_XI;
635706f2543Smrg    b.grabtype = GRABTYPE_XI;
636706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
637706f2543Smrg    g_assert(rc == FALSE);
638706f2543Smrg    rc = GrabMatchesSecond(&b, &a, FALSE);
639706f2543Smrg    g_assert(rc == FALSE);
640706f2543Smrg
641706f2543Smrg    /* AnyModifier must fail for XI2 */
642706f2543Smrg    a.grabtype = GRABTYPE_XI2;
643706f2543Smrg    b.grabtype = GRABTYPE_XI2;
644706f2543Smrg    a.modifiersDetail.exact = AnyModifier;
645706f2543Smrg    b.modifiersDetail.exact = 1;
646706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
647706f2543Smrg    g_assert(rc == FALSE);
648706f2543Smrg    rc = GrabMatchesSecond(&b, &a, FALSE);
649706f2543Smrg    g_assert(rc == FALSE);
650706f2543Smrg
651706f2543Smrg    /* XIAnyModifier must fail for CORE and XI */
652706f2543Smrg    a.grabtype = GRABTYPE_XI;
653706f2543Smrg    b.grabtype = GRABTYPE_XI;
654706f2543Smrg    a.modifiersDetail.exact = XIAnyModifier;
655706f2543Smrg    b.modifiersDetail.exact = 1;
656706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
657706f2543Smrg    g_assert(rc == FALSE);
658706f2543Smrg    rc = GrabMatchesSecond(&b, &a, FALSE);
659706f2543Smrg    g_assert(rc == FALSE);
660706f2543Smrg
661706f2543Smrg    a.grabtype = GRABTYPE_CORE;
662706f2543Smrg    b.grabtype = GRABTYPE_CORE;
663706f2543Smrg    a.modifiersDetail.exact = XIAnyModifier;
664706f2543Smrg    b.modifiersDetail.exact = 1;
665706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
666706f2543Smrg    g_assert(rc == FALSE);
667706f2543Smrg    rc = GrabMatchesSecond(&b, &a, FALSE);
668706f2543Smrg    g_assert(rc == FALSE);
669706f2543Smrg
670706f2543Smrg    /* different detail must fail */
671706f2543Smrg    a.grabtype = GRABTYPE_XI2;
672706f2543Smrg    b.grabtype = GRABTYPE_XI2;
673706f2543Smrg    a.detail.exact = 1;
674706f2543Smrg    b.detail.exact = 2;
675706f2543Smrg    a.modifiersDetail.exact = 1;
676706f2543Smrg    b.modifiersDetail.exact = 1;
677706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
678706f2543Smrg    g_assert(rc == FALSE);
679706f2543Smrg    rc = GrabMatchesSecond(&b, &a, FALSE);
680706f2543Smrg    g_assert(rc == FALSE);
681706f2543Smrg
682706f2543Smrg    a.grabtype = GRABTYPE_XI;
683706f2543Smrg    b.grabtype = GRABTYPE_XI;
684706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
685706f2543Smrg    g_assert(rc == FALSE);
686706f2543Smrg    rc = GrabMatchesSecond(&b, &a, FALSE);
687706f2543Smrg    g_assert(rc == FALSE);
688706f2543Smrg
689706f2543Smrg    a.grabtype = GRABTYPE_CORE;
690706f2543Smrg    b.grabtype = GRABTYPE_CORE;
691706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
692706f2543Smrg    g_assert(rc == FALSE);
693706f2543Smrg    rc = GrabMatchesSecond(&b, &a, FALSE);
694706f2543Smrg    g_assert(rc == FALSE);
695706f2543Smrg
696706f2543Smrg    /* detail of AnyModifier must fail */
697706f2543Smrg    a.grabtype = GRABTYPE_XI2;
698706f2543Smrg    b.grabtype = GRABTYPE_XI2;
699706f2543Smrg    a.detail.exact = AnyModifier;
700706f2543Smrg    b.detail.exact = 1;
701706f2543Smrg    a.modifiersDetail.exact = 1;
702706f2543Smrg    b.modifiersDetail.exact = 1;
703706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
704706f2543Smrg    g_assert(rc == FALSE);
705706f2543Smrg    rc = GrabMatchesSecond(&b, &a, FALSE);
706706f2543Smrg    g_assert(rc == FALSE);
707706f2543Smrg
708706f2543Smrg    a.grabtype = GRABTYPE_CORE;
709706f2543Smrg    b.grabtype = GRABTYPE_CORE;
710706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
711706f2543Smrg    g_assert(rc == FALSE);
712706f2543Smrg    rc = GrabMatchesSecond(&b, &a, FALSE);
713706f2543Smrg    g_assert(rc == FALSE);
714706f2543Smrg
715706f2543Smrg    a.grabtype = GRABTYPE_XI;
716706f2543Smrg    b.grabtype = GRABTYPE_XI;
717706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
718706f2543Smrg    g_assert(rc == FALSE);
719706f2543Smrg    rc = GrabMatchesSecond(&b, &a, FALSE);
720706f2543Smrg    g_assert(rc == FALSE);
721706f2543Smrg
722706f2543Smrg    /* detail of XIAnyModifier must fail */
723706f2543Smrg    a.grabtype = GRABTYPE_XI2;
724706f2543Smrg    b.grabtype = GRABTYPE_XI2;
725706f2543Smrg    a.detail.exact = XIAnyModifier;
726706f2543Smrg    b.detail.exact = 1;
727706f2543Smrg    a.modifiersDetail.exact = 1;
728706f2543Smrg    b.modifiersDetail.exact = 1;
729706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
730706f2543Smrg    g_assert(rc == FALSE);
731706f2543Smrg    rc = GrabMatchesSecond(&b, &a, FALSE);
732706f2543Smrg    g_assert(rc == FALSE);
733706f2543Smrg
734706f2543Smrg    a.grabtype = GRABTYPE_CORE;
735706f2543Smrg    b.grabtype = GRABTYPE_CORE;
736706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
737706f2543Smrg    g_assert(rc == FALSE);
738706f2543Smrg    rc = GrabMatchesSecond(&b, &a, FALSE);
739706f2543Smrg    g_assert(rc == FALSE);
740706f2543Smrg
741706f2543Smrg    a.grabtype = GRABTYPE_XI;
742706f2543Smrg    b.grabtype = GRABTYPE_XI;
743706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
744706f2543Smrg    g_assert(rc == FALSE);
745706f2543Smrg    rc = GrabMatchesSecond(&b, &a, FALSE);
746706f2543Smrg    g_assert(rc == FALSE);
747706f2543Smrg
748706f2543Smrg    /* XIAnyModifier or AnyModifer must succeed */
749706f2543Smrg    a.grabtype = GRABTYPE_XI2;
750706f2543Smrg    b.grabtype = GRABTYPE_XI2;
751706f2543Smrg    a.detail.exact = 1;
752706f2543Smrg    b.detail.exact = 1;
753706f2543Smrg    a.modifiersDetail.exact = XIAnyModifier;
754706f2543Smrg    b.modifiersDetail.exact = 1;
755706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
756706f2543Smrg    g_assert(rc == TRUE);
757706f2543Smrg    rc = GrabMatchesSecond(&b, &a, FALSE);
758706f2543Smrg    g_assert(rc == TRUE);
759706f2543Smrg
760706f2543Smrg    a.grabtype = GRABTYPE_CORE;
761706f2543Smrg    b.grabtype = GRABTYPE_CORE;
762706f2543Smrg    a.detail.exact = 1;
763706f2543Smrg    b.detail.exact = 1;
764706f2543Smrg    a.modifiersDetail.exact = AnyModifier;
765706f2543Smrg    b.modifiersDetail.exact = 1;
766706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
767706f2543Smrg    g_assert(rc == TRUE);
768706f2543Smrg    rc = GrabMatchesSecond(&b, &a, FALSE);
769706f2543Smrg    g_assert(rc == TRUE);
770706f2543Smrg
771706f2543Smrg    a.grabtype = GRABTYPE_XI;
772706f2543Smrg    b.grabtype = GRABTYPE_XI;
773706f2543Smrg    a.detail.exact = 1;
774706f2543Smrg    b.detail.exact = 1;
775706f2543Smrg    a.modifiersDetail.exact = AnyModifier;
776706f2543Smrg    b.modifiersDetail.exact = 1;
777706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
778706f2543Smrg    g_assert(rc == TRUE);
779706f2543Smrg    rc = GrabMatchesSecond(&b, &a, FALSE);
780706f2543Smrg    g_assert(rc == TRUE);
781706f2543Smrg
782706f2543Smrg    /* AnyKey or XIAnyKeycode must succeed */
783706f2543Smrg    a.grabtype = GRABTYPE_XI2;
784706f2543Smrg    b.grabtype = GRABTYPE_XI2;
785706f2543Smrg    a.detail.exact = XIAnyKeycode;
786706f2543Smrg    b.detail.exact = 1;
787706f2543Smrg    a.modifiersDetail.exact = 1;
788706f2543Smrg    b.modifiersDetail.exact = 1;
789706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
790706f2543Smrg    g_assert(rc == TRUE);
791706f2543Smrg    rc = GrabMatchesSecond(&b, &a, FALSE);
792706f2543Smrg    g_assert(rc == TRUE);
793706f2543Smrg
794706f2543Smrg    a.grabtype = GRABTYPE_CORE;
795706f2543Smrg    b.grabtype = GRABTYPE_CORE;
796706f2543Smrg    a.detail.exact = AnyKey;
797706f2543Smrg    b.detail.exact = 1;
798706f2543Smrg    a.modifiersDetail.exact = 1;
799706f2543Smrg    b.modifiersDetail.exact = 1;
800706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
801706f2543Smrg    g_assert(rc == TRUE);
802706f2543Smrg    rc = GrabMatchesSecond(&b, &a, FALSE);
803706f2543Smrg    g_assert(rc == TRUE);
804706f2543Smrg
805706f2543Smrg    a.grabtype = GRABTYPE_XI;
806706f2543Smrg    b.grabtype = GRABTYPE_XI;
807706f2543Smrg    a.detail.exact = AnyKey;
808706f2543Smrg    b.detail.exact = 1;
809706f2543Smrg    a.modifiersDetail.exact = 1;
810706f2543Smrg    b.modifiersDetail.exact = 1;
811706f2543Smrg    rc = GrabMatchesSecond(&a, &b, FALSE);
812706f2543Smrg    g_assert(rc == TRUE);
813706f2543Smrg    rc = GrabMatchesSecond(&b, &a, FALSE);
814706f2543Smrg    g_assert(rc == TRUE);
815706f2543Smrg}
816706f2543Smrg
817706f2543Smrgstatic void test_bits_to_byte(int i)
818706f2543Smrg{
819706f2543Smrg        int expected_bytes;
820706f2543Smrg        expected_bytes = (i + 7)/8;
821706f2543Smrg
822706f2543Smrg        g_assert(bits_to_bytes(i) >= i/8);
823706f2543Smrg        g_assert((bits_to_bytes(i) * 8) - i <= 7);
824706f2543Smrg        g_assert(expected_bytes == bits_to_bytes(i));
825706f2543Smrg}
826706f2543Smrg
827706f2543Smrgstatic void test_bytes_to_int32(int i)
828706f2543Smrg{
829706f2543Smrg        int expected_4byte;
830706f2543Smrg        expected_4byte = (i + 3)/4;
831706f2543Smrg
832706f2543Smrg        g_assert(bytes_to_int32(i) <= i);
833706f2543Smrg        g_assert((bytes_to_int32(i) * 4) - i <= 3);
834706f2543Smrg        g_assert(expected_4byte == bytes_to_int32(i));
835706f2543Smrg}
836706f2543Smrg
837706f2543Smrgstatic void test_pad_to_int32(int i)
838706f2543Smrg{
839706f2543Smrg        int expected_bytes;
840706f2543Smrg        expected_bytes = ((i + 3)/4) * 4;
841706f2543Smrg
842706f2543Smrg        g_assert(pad_to_int32(i) >= i);
843706f2543Smrg        g_assert(pad_to_int32(i) - i <= 3);
844706f2543Smrg        g_assert(expected_bytes == pad_to_int32(i));
845706f2543Smrg}
846706f2543Smrgstatic void include_byte_padding_macros(void)
847706f2543Smrg{
848706f2543Smrg    g_test_message("Testing bits_to_bytes()");
849706f2543Smrg
850706f2543Smrg    /* the macros don't provide overflow protection */
851706f2543Smrg    test_bits_to_byte(0);
852706f2543Smrg    test_bits_to_byte(1);
853706f2543Smrg    test_bits_to_byte(2);
854706f2543Smrg    test_bits_to_byte(7);
855706f2543Smrg    test_bits_to_byte(8);
856706f2543Smrg    test_bits_to_byte(0xFF);
857706f2543Smrg    test_bits_to_byte(0x100);
858706f2543Smrg    test_bits_to_byte(INT_MAX - 9);
859706f2543Smrg    test_bits_to_byte(INT_MAX - 8);
860706f2543Smrg
861706f2543Smrg    g_test_message("Testing bytes_to_int32()");
862706f2543Smrg
863706f2543Smrg    test_bytes_to_int32(0);
864706f2543Smrg    test_bytes_to_int32(1);
865706f2543Smrg    test_bytes_to_int32(2);
866706f2543Smrg    test_bytes_to_int32(7);
867706f2543Smrg    test_bytes_to_int32(8);
868706f2543Smrg    test_bytes_to_int32(0xFF);
869706f2543Smrg    test_bytes_to_int32(0x100);
870706f2543Smrg    test_bytes_to_int32(0xFFFF);
871706f2543Smrg    test_bytes_to_int32(0x10000);
872706f2543Smrg    test_bytes_to_int32(0xFFFFFF);
873706f2543Smrg    test_bytes_to_int32(0x1000000);
874706f2543Smrg    test_bytes_to_int32(INT_MAX - 4);
875706f2543Smrg    test_bytes_to_int32(INT_MAX - 3);
876706f2543Smrg
877706f2543Smrg    g_test_message("Testing pad_to_int32");
878706f2543Smrg
879706f2543Smrg    test_pad_to_int32(0);
880706f2543Smrg    test_pad_to_int32(0);
881706f2543Smrg    test_pad_to_int32(1);
882706f2543Smrg    test_pad_to_int32(2);
883706f2543Smrg    test_pad_to_int32(7);
884706f2543Smrg    test_pad_to_int32(8);
885706f2543Smrg    test_pad_to_int32(0xFF);
886706f2543Smrg    test_pad_to_int32(0x100);
887706f2543Smrg    test_pad_to_int32(0xFFFF);
888706f2543Smrg    test_pad_to_int32(0x10000);
889706f2543Smrg    test_pad_to_int32(0xFFFFFF);
890706f2543Smrg    test_pad_to_int32(0x1000000);
891706f2543Smrg    test_pad_to_int32(INT_MAX - 4);
892706f2543Smrg    test_pad_to_int32(INT_MAX - 3);
893706f2543Smrg}
894706f2543Smrg
895706f2543Smrgstatic void xi_unregister_handlers(void)
896706f2543Smrg{
897706f2543Smrg    DeviceIntRec dev;
898706f2543Smrg    int handler;
899706f2543Smrg
900706f2543Smrg    memset(&dev, 0, sizeof(dev));
901706f2543Smrg
902706f2543Smrg    handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
903706f2543Smrg    g_assert(handler == 1);
904706f2543Smrg    handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
905706f2543Smrg    g_assert(handler == 2);
906706f2543Smrg    handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
907706f2543Smrg    g_assert(handler == 3);
908706f2543Smrg
909706f2543Smrg    g_test_message("Unlinking from front.");
910706f2543Smrg
911706f2543Smrg    XIUnregisterPropertyHandler(&dev, 4); /* NOOP */
912706f2543Smrg    g_assert(dev.properties.handlers->id == 3);
913706f2543Smrg    XIUnregisterPropertyHandler(&dev, 3);
914706f2543Smrg    g_assert(dev.properties.handlers->id == 2);
915706f2543Smrg    XIUnregisterPropertyHandler(&dev, 2);
916706f2543Smrg    g_assert(dev.properties.handlers->id == 1);
917706f2543Smrg    XIUnregisterPropertyHandler(&dev, 1);
918706f2543Smrg    g_assert(dev.properties.handlers == NULL);
919706f2543Smrg
920706f2543Smrg    handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
921706f2543Smrg    g_assert(handler == 4);
922706f2543Smrg    handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
923706f2543Smrg    g_assert(handler == 5);
924706f2543Smrg    handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
925706f2543Smrg    g_assert(handler == 6);
926706f2543Smrg    XIUnregisterPropertyHandler(&dev, 3); /* NOOP */
927706f2543Smrg    g_assert(dev.properties.handlers->next->next->next == NULL);
928706f2543Smrg    XIUnregisterPropertyHandler(&dev, 4);
929706f2543Smrg    g_assert(dev.properties.handlers->next->next == NULL);
930706f2543Smrg    XIUnregisterPropertyHandler(&dev, 5);
931706f2543Smrg    g_assert(dev.properties.handlers->next == NULL);
932706f2543Smrg    XIUnregisterPropertyHandler(&dev, 6);
933706f2543Smrg    g_assert(dev.properties.handlers == NULL);
934706f2543Smrg
935706f2543Smrg    handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
936706f2543Smrg    g_assert(handler == 7);
937706f2543Smrg    handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
938706f2543Smrg    g_assert(handler == 8);
939706f2543Smrg    handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
940706f2543Smrg    g_assert(handler == 9);
941706f2543Smrg
942706f2543Smrg    XIDeleteAllDeviceProperties(&dev);
943706f2543Smrg    g_assert(dev.properties.handlers == NULL);
944706f2543Smrg    XIUnregisterPropertyHandler(&dev, 7); /* NOOP */
945706f2543Smrg
946706f2543Smrg}
947706f2543Smrg
948706f2543Smrgstatic void cmp_attr_fields(InputAttributes *attr1,
949706f2543Smrg                            InputAttributes *attr2)
950706f2543Smrg{
951706f2543Smrg    char **tags1, **tags2;
952706f2543Smrg
953706f2543Smrg    g_assert(attr1 && attr2);
954706f2543Smrg    g_assert(attr1 != attr2);
955706f2543Smrg    g_assert(attr1->flags == attr2->flags);
956706f2543Smrg
957706f2543Smrg    if (attr1->product != NULL)
958706f2543Smrg    {
959706f2543Smrg        g_assert(attr1->product != attr2->product);
960706f2543Smrg        g_assert(strcmp(attr1->product, attr2->product) == 0);
961706f2543Smrg    } else
962706f2543Smrg        g_assert(attr2->product == NULL);
963706f2543Smrg
964706f2543Smrg    if (attr1->vendor != NULL)
965706f2543Smrg    {
966706f2543Smrg        g_assert(attr1->vendor != attr2->vendor);
967706f2543Smrg        g_assert(strcmp(attr1->vendor, attr2->vendor) == 0);
968706f2543Smrg    } else
969706f2543Smrg        g_assert(attr2->vendor == NULL);
970706f2543Smrg
971706f2543Smrg    if (attr1->device != NULL)
972706f2543Smrg    {
973706f2543Smrg        g_assert(attr1->device != attr2->device);
974706f2543Smrg        g_assert(strcmp(attr1->device, attr2->device) == 0);
975706f2543Smrg    } else
976706f2543Smrg        g_assert(attr2->device == NULL);
977706f2543Smrg
978706f2543Smrg    if (attr1->pnp_id != NULL)
979706f2543Smrg    {
980706f2543Smrg        g_assert(attr1->pnp_id != attr2->pnp_id);
981706f2543Smrg        g_assert(strcmp(attr1->pnp_id, attr2->pnp_id) == 0);
982706f2543Smrg    } else
983706f2543Smrg        g_assert(attr2->pnp_id == NULL);
984706f2543Smrg
985706f2543Smrg    if (attr1->usb_id != NULL)
986706f2543Smrg    {
987706f2543Smrg        g_assert(attr1->usb_id != attr2->usb_id);
988706f2543Smrg        g_assert(strcmp(attr1->usb_id, attr2->usb_id) == 0);
989706f2543Smrg    } else
990706f2543Smrg        g_assert(attr2->usb_id == NULL);
991706f2543Smrg
992706f2543Smrg    tags1 = attr1->tags;
993706f2543Smrg    tags2 = attr2->tags;
994706f2543Smrg
995706f2543Smrg    /* if we don't have any tags, skip the tag checking bits */
996706f2543Smrg    if (!tags1)
997706f2543Smrg    {
998706f2543Smrg        g_assert(!tags2);
999706f2543Smrg        return;
1000706f2543Smrg    }
1001706f2543Smrg
1002706f2543Smrg    /* Don't lug around empty arrays */
1003706f2543Smrg    g_assert(*tags1);
1004706f2543Smrg    g_assert(*tags2);
1005706f2543Smrg
1006706f2543Smrg    /* check for identical content, but duplicated */
1007706f2543Smrg    while (*tags1)
1008706f2543Smrg    {
1009706f2543Smrg        g_assert(*tags1 != *tags2);
1010706f2543Smrg        g_assert(strcmp(*tags1, *tags2) == 0);
1011706f2543Smrg        tags1++;
1012706f2543Smrg        tags2++;
1013706f2543Smrg    }
1014706f2543Smrg
1015706f2543Smrg    /* ensure tags1 and tags2 have the same no of elements */
1016706f2543Smrg    g_assert(!*tags2);
1017706f2543Smrg
1018706f2543Smrg    /* check for not sharing memory */
1019706f2543Smrg    tags1 = attr1->tags;
1020706f2543Smrg    while (*tags1)
1021706f2543Smrg    {
1022706f2543Smrg        tags2 = attr2->tags;
1023706f2543Smrg        while (*tags2)
1024706f2543Smrg            g_assert(*tags1 != *tags2++);
1025706f2543Smrg
1026706f2543Smrg        tags1++;
1027706f2543Smrg    }
1028706f2543Smrg}
1029706f2543Smrg
1030706f2543Smrgstatic void dix_input_attributes(void)
1031706f2543Smrg{
1032706f2543Smrg    InputAttributes orig = {0};
1033706f2543Smrg    InputAttributes *new;
1034706f2543Smrg    char *tags[4] = {"tag1", "tag2", "tag2", NULL};
1035706f2543Smrg
1036706f2543Smrg    new = DuplicateInputAttributes(NULL);
1037706f2543Smrg    g_assert(!new);
1038706f2543Smrg
1039706f2543Smrg    new = DuplicateInputAttributes(&orig);
1040706f2543Smrg    g_assert(memcmp(&orig, new, sizeof(InputAttributes)) == 0);
1041706f2543Smrg
1042706f2543Smrg    orig.product = "product name";
1043706f2543Smrg    new = DuplicateInputAttributes(&orig);
1044706f2543Smrg    cmp_attr_fields(&orig, new);
1045706f2543Smrg    FreeInputAttributes(new);
1046706f2543Smrg
1047706f2543Smrg    orig.vendor = "vendor name";
1048706f2543Smrg    new = DuplicateInputAttributes(&orig);
1049706f2543Smrg    cmp_attr_fields(&orig, new);
1050706f2543Smrg    FreeInputAttributes(new);
1051706f2543Smrg
1052706f2543Smrg    orig.device = "device path";
1053706f2543Smrg    new = DuplicateInputAttributes(&orig);
1054706f2543Smrg    cmp_attr_fields(&orig, new);
1055706f2543Smrg    FreeInputAttributes(new);
1056706f2543Smrg
1057706f2543Smrg    orig.pnp_id = "PnPID";
1058706f2543Smrg    new = DuplicateInputAttributes(&orig);
1059706f2543Smrg    cmp_attr_fields(&orig, new);
1060706f2543Smrg    FreeInputAttributes(new);
1061706f2543Smrg
1062706f2543Smrg    orig.usb_id = "USBID";
1063706f2543Smrg    new = DuplicateInputAttributes(&orig);
1064706f2543Smrg    cmp_attr_fields(&orig, new);
1065706f2543Smrg    FreeInputAttributes(new);
1066706f2543Smrg
1067706f2543Smrg    orig.flags = 0xF0;
1068706f2543Smrg    new = DuplicateInputAttributes(&orig);
1069706f2543Smrg    cmp_attr_fields(&orig, new);
1070706f2543Smrg    FreeInputAttributes(new);
1071706f2543Smrg
1072706f2543Smrg    orig.tags = tags;
1073706f2543Smrg    new = DuplicateInputAttributes(&orig);
1074706f2543Smrg    cmp_attr_fields(&orig, new);
1075706f2543Smrg    FreeInputAttributes(new);
1076706f2543Smrg}
1077706f2543Smrg
1078706f2543Smrgstatic void dix_input_valuator_masks(void)
1079706f2543Smrg{
1080706f2543Smrg    ValuatorMask *mask = NULL, *copy;
1081706f2543Smrg    int nvaluators = MAX_VALUATORS;
1082706f2543Smrg    int valuators[nvaluators];
1083706f2543Smrg    int i;
1084706f2543Smrg    int first_val, num_vals;
1085706f2543Smrg
1086706f2543Smrg    for (i = 0; i < nvaluators; i++)
1087706f2543Smrg        valuators[i] = i;
1088706f2543Smrg
1089706f2543Smrg    mask = valuator_mask_new(nvaluators);
1090706f2543Smrg    g_assert(mask != NULL);
1091706f2543Smrg    g_assert(valuator_mask_size(mask) == 0);
1092706f2543Smrg    g_assert(valuator_mask_num_valuators(mask) == 0);
1093706f2543Smrg
1094706f2543Smrg    for (i = 0; i < nvaluators; i++)
1095706f2543Smrg    {
1096706f2543Smrg        g_assert(!valuator_mask_isset(mask, i));
1097706f2543Smrg        valuator_mask_set(mask, i, valuators[i]);
1098706f2543Smrg        g_assert(valuator_mask_isset(mask, i));
1099706f2543Smrg        g_assert(valuator_mask_get(mask, i) == valuators[i]);
1100706f2543Smrg        g_assert(valuator_mask_size(mask) == i + 1);
1101706f2543Smrg        g_assert(valuator_mask_num_valuators(mask) == i + 1);
1102706f2543Smrg    }
1103706f2543Smrg
1104706f2543Smrg    for (i = 0; i < nvaluators; i++)
1105706f2543Smrg    {
1106706f2543Smrg        g_assert(valuator_mask_isset(mask, i));
1107706f2543Smrg        valuator_mask_unset(mask, i);
1108706f2543Smrg        /* we're removing valuators from the front, so size should stay the
1109706f2543Smrg         * same until the last bit is removed */
1110706f2543Smrg        if (i < nvaluators - 1)
1111706f2543Smrg            g_assert(valuator_mask_size(mask) == nvaluators);
1112706f2543Smrg        g_assert(!valuator_mask_isset(mask, i));
1113706f2543Smrg    }
1114706f2543Smrg
1115706f2543Smrg    g_assert(valuator_mask_size(mask) == 0);
1116706f2543Smrg    valuator_mask_zero(mask);
1117706f2543Smrg    g_assert(valuator_mask_size(mask) == 0);
1118706f2543Smrg    g_assert(valuator_mask_num_valuators(mask) == 0);
1119706f2543Smrg    for (i = 0; i < nvaluators; i++)
1120706f2543Smrg        g_assert(!valuator_mask_isset(mask, i));
1121706f2543Smrg
1122706f2543Smrg    first_val = 5;
1123706f2543Smrg    num_vals = 6;
1124706f2543Smrg
1125706f2543Smrg    valuator_mask_set_range(mask, first_val, num_vals, valuators);
1126706f2543Smrg    g_assert(valuator_mask_size(mask) == first_val + num_vals);
1127706f2543Smrg    g_assert(valuator_mask_num_valuators(mask) == num_vals);
1128706f2543Smrg    for (i = 0; i < nvaluators; i++)
1129706f2543Smrg    {
1130706f2543Smrg        if (i < first_val || i >= first_val + num_vals)
1131706f2543Smrg            g_assert(!valuator_mask_isset(mask, i));
1132706f2543Smrg        else
1133706f2543Smrg        {
1134706f2543Smrg            g_assert(valuator_mask_isset(mask, i));
1135706f2543Smrg            g_assert(valuator_mask_get(mask, i) == valuators[i - first_val]);
1136706f2543Smrg        }
1137706f2543Smrg    }
1138706f2543Smrg
1139706f2543Smrg    copy = valuator_mask_new(nvaluators);
1140706f2543Smrg    valuator_mask_copy(copy, mask);
1141706f2543Smrg    g_assert(mask != copy);
1142706f2543Smrg    g_assert(valuator_mask_size(mask) == valuator_mask_size(copy));
1143706f2543Smrg    g_assert(valuator_mask_num_valuators(mask) == valuator_mask_num_valuators(copy));
1144706f2543Smrg
1145706f2543Smrg    for (i = 0; i < nvaluators; i++)
1146706f2543Smrg    {
1147706f2543Smrg        g_assert(valuator_mask_isset(mask, i) == valuator_mask_isset(copy, i));
1148706f2543Smrg        g_assert(valuator_mask_get(mask, i) == valuator_mask_get(copy, i));
1149706f2543Smrg    }
1150706f2543Smrg
1151706f2543Smrg    valuator_mask_free(&mask);
1152706f2543Smrg    g_assert(mask == NULL);
1153706f2543Smrg}
1154706f2543Smrg
1155706f2543Smrgstatic void dix_valuator_mode(void)
1156706f2543Smrg{
1157706f2543Smrg    DeviceIntRec dev;
1158706f2543Smrg    const int num_axes = MAX_VALUATORS;
1159706f2543Smrg    int i;
1160706f2543Smrg    Atom atoms[MAX_VALUATORS] = { 0 };
1161706f2543Smrg
1162706f2543Smrg    memset(&dev, 0, sizeof(DeviceIntRec));
1163706f2543Smrg    dev.type = MASTER_POINTER; /* claim it's a master to stop ptracccel */
1164706f2543Smrg
1165706f2543Smrg    g_assert(InitValuatorClassDeviceStruct(NULL, 0, atoms, 0, 0) == FALSE);
1166706f2543Smrg    g_assert(InitValuatorClassDeviceStruct(&dev, num_axes, atoms, 0, Absolute));
1167706f2543Smrg
1168706f2543Smrg    for (i = 0; i < num_axes; i++)
1169706f2543Smrg    {
1170706f2543Smrg        g_assert(valuator_get_mode(&dev, i) == Absolute);
1171706f2543Smrg        valuator_set_mode(&dev, i, Relative);
1172706f2543Smrg        g_assert(dev.valuator->axes[i].mode == Relative);
1173706f2543Smrg        g_assert(valuator_get_mode(&dev, i) == Relative);
1174706f2543Smrg    }
1175706f2543Smrg
1176706f2543Smrg    valuator_set_mode(&dev, VALUATOR_MODE_ALL_AXES, Absolute);
1177706f2543Smrg    for (i = 0; i < num_axes; i++)
1178706f2543Smrg        g_assert(valuator_get_mode(&dev, i) == Absolute);
1179706f2543Smrg
1180706f2543Smrg    valuator_set_mode(&dev, VALUATOR_MODE_ALL_AXES, Relative);
1181706f2543Smrg    for (i = 0; i < num_axes; i++)
1182706f2543Smrg        g_assert(valuator_get_mode(&dev, i) == Relative);
1183706f2543Smrg}
1184706f2543Smrg
1185706f2543Smrgstatic void include_bit_test_macros(void)
1186706f2543Smrg{
1187706f2543Smrg    uint8_t mask[9] = { 0 };
1188706f2543Smrg    int i;
1189706f2543Smrg
1190706f2543Smrg    for (i = 0; i < sizeof(mask)/sizeof(mask[0]); i++)
1191706f2543Smrg    {
1192706f2543Smrg        g_assert(BitIsOn(mask, i) == 0);
1193706f2543Smrg        SetBit(mask, i);
1194706f2543Smrg        g_assert(BitIsOn(mask, i) == 1);
1195706f2543Smrg        g_assert(!!(mask[i/8] & (1 << (i % 8))));
1196706f2543Smrg        g_assert(CountBits(mask, sizeof(mask)) == 1);
1197706f2543Smrg        ClearBit(mask, i);
1198706f2543Smrg        g_assert(BitIsOn(mask, i) == 0);
1199706f2543Smrg    }
1200706f2543Smrg}
1201706f2543Smrg
1202706f2543Smrg/**
1203706f2543Smrg * Ensure that val->axisVal and val->axes are aligned on doubles.
1204706f2543Smrg */
1205706f2543Smrgstatic void dix_valuator_alloc(void)
1206706f2543Smrg{
1207706f2543Smrg    ValuatorClassPtr v = NULL;
1208706f2543Smrg    int num_axes = 0;
1209706f2543Smrg
1210706f2543Smrg    while (num_axes < 5)
1211706f2543Smrg    {
1212706f2543Smrg        v = AllocValuatorClass(v, num_axes);
1213706f2543Smrg
1214706f2543Smrg        g_assert(v);
1215706f2543Smrg        g_assert(v->numAxes == num_axes);
1216706f2543Smrg#ifndef __i386__
1217706f2543Smrg        /* must be double-aligned on 64 bit */
1218706f2543Smrg        g_assert(((void*)v->axisVal - (void*)v) % sizeof(double) == 0);
1219706f2543Smrg        g_assert(((void*)v->axes - (void*)v) % sizeof(double) == 0);
1220706f2543Smrg#endif
1221706f2543Smrg        num_axes ++;
1222706f2543Smrg    }
1223706f2543Smrg
1224706f2543Smrg    free(v);
1225706f2543Smrg}
1226706f2543Smrg
1227706f2543Smrgint main(int argc, char** argv)
1228706f2543Smrg{
1229706f2543Smrg    g_test_init(&argc, &argv,NULL);
1230706f2543Smrg    g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id=");
1231706f2543Smrg
1232706f2543Smrg    g_test_add_func("/dix/input/valuator-masks", dix_input_valuator_masks);
1233706f2543Smrg    g_test_add_func("/dix/input/attributes", dix_input_attributes);
1234706f2543Smrg    g_test_add_func("/dix/input/init-valuators", dix_init_valuators);
1235706f2543Smrg    g_test_add_func("/dix/input/event-core-conversion", dix_event_to_core_conversion);
1236706f2543Smrg    g_test_add_func("/dix/input/event-xi1-conversion", dix_event_to_xi1_conversion);
1237706f2543Smrg    g_test_add_func("/dix/input/check-grab-values", dix_check_grab_values);
1238706f2543Smrg    g_test_add_func("/dix/input/xi2-struct-sizes", xi2_struct_sizes);
1239706f2543Smrg    g_test_add_func("/dix/input/grab_matching", dix_grab_matching);
1240706f2543Smrg    g_test_add_func("/dix/input/valuator_mode", dix_valuator_mode);
1241706f2543Smrg    g_test_add_func("/include/byte_padding_macros", include_byte_padding_macros);
1242706f2543Smrg    g_test_add_func("/include/bit_test_macros", include_bit_test_macros);
1243706f2543Smrg    g_test_add_func("/Xi/xiproperty/register-unregister", xi_unregister_handlers);
1244706f2543Smrg    g_test_add_func("/dix/input/valuator-alloc", dix_valuator_alloc);
1245706f2543Smrg
1246706f2543Smrg    return g_test_run();
1247706f2543Smrg}
1248