diff options
Diffstat (limited to 'xorg-server/test')
-rw-r--r-- | xorg-server/test/Makefile.am | 90 | ||||
-rw-r--r-- | xorg-server/test/input.c | 2508 | ||||
-rw-r--r-- | xorg-server/test/list.c | 346 | ||||
-rw-r--r-- | xorg-server/test/xi2/Makefile.am | 114 | ||||
-rw-r--r-- | xorg-server/test/xi2/protocol-common.c | 354 | ||||
-rw-r--r-- | xorg-server/test/xi2/protocol-common.h | 306 | ||||
-rw-r--r-- | xorg-server/test/xi2/protocol-eventconvert.c | 1834 | ||||
-rw-r--r-- | xorg-server/test/xi2/protocol-xigetclientpointer.c | 324 | ||||
-rw-r--r-- | xorg-server/test/xi2/protocol-xigetselectedevents.c | 474 | ||||
-rw-r--r-- | xorg-server/test/xi2/protocol-xiquerydevice.c | 624 | ||||
-rw-r--r-- | xorg-server/test/xi2/protocol-xiquerypointer.c | 432 | ||||
-rw-r--r-- | xorg-server/test/xi2/protocol-xiqueryversion.c | 364 | ||||
-rw-r--r-- | xorg-server/test/xi2/protocol-xiselectevents.c | 668 | ||||
-rw-r--r-- | xorg-server/test/xi2/protocol-xisetclientpointer.c | 290 | ||||
-rw-r--r-- | xorg-server/test/xi2/protocol-xiwarppointer.c | 424 | ||||
-rw-r--r-- | xorg-server/test/xkb.c | 338 | ||||
-rw-r--r-- | xorg-server/test/xtest.c | 226 |
17 files changed, 4858 insertions, 4858 deletions
diff --git a/xorg-server/test/Makefile.am b/xorg-server/test/Makefile.am index 7ef408c93..423e96271 100644 --- a/xorg-server/test/Makefile.am +++ b/xorg-server/test/Makefile.am @@ -1,45 +1,45 @@ -if ENABLE_UNIT_TESTS -if HAVE_LD_WRAP -SUBDIRS= . xi2 -noinst_PROGRAMS = xkb input xtest list misc fixes -check_LTLIBRARIES = libxservertest.la - -TESTS=$(noinst_PROGRAMS) - -AM_CFLAGS = $(DIX_CFLAGS) @XORG_CFLAGS@ -INCLUDES = $(XORG_INCS) -I$(top_srcdir)/hw/xfree86/parser \ - -I$(top_srcdir)/miext/cw -I$(top_srcdir)/hw/xfree86/ddc \ - -I$(top_srcdir)/hw/xfree86/i2c -I$(top_srcdir)/hw/xfree86/modes \ - -I$(top_srcdir)/hw/xfree86/ramdac -TEST_LDADD=libxservertest.la $(XORG_SYS_LIBS) $(XSERVER_SYS_LIBS) - -if SPECIAL_DTRACE_OBJECTS -TEST_LDADD += $(OS_LIB) $(DIX_LIB) -endif - -xkb_LDADD=$(TEST_LDADD) -input_LDADD=$(TEST_LDADD) -xtest_LDADD=$(TEST_LDADD) -list_LDADD=$(TEST_LDADD) -misc_LDADD=$(TEST_LDADD) -fixes_LDADD=$(TEST_LDADD) - -nodist_libxservertest_la_SOURCES = $(top_builddir)/hw/xfree86/sdksyms.c -libxservertest_la_LIBADD = \ - $(XSERVER_LIBS) \ - $(top_builddir)/hw/xfree86/loader/libloader.la \ - $(top_builddir)/hw/xfree86/os-support/libxorgos.la \ - $(top_builddir)/hw/xfree86/common/libcommon.la \ - $(top_builddir)/hw/xfree86/parser/libxf86config_internal.la \ - $(top_builddir)/hw/xfree86/dixmods/libdixmods.la \ - $(top_builddir)/hw/xfree86/modes/libxf86modes.la \ - $(top_builddir)/hw/xfree86/ramdac/libramdac.la \ - $(top_builddir)/hw/xfree86/ddc/libddc.la \ - $(top_builddir)/hw/xfree86/i2c/libi2c.la \ - $(top_builddir)/hw/xfree86/dixmods/libxorgxkb.la \ - $(top_builddir)/mi/libmi.la \ - $(top_builddir)/os/libos.la \ - @XORG_LIBS@ -libxservertest_la_DEPENDENCIES = $(libxservertest_la_LIBADD) -endif -endif +if ENABLE_UNIT_TESTS
+if HAVE_LD_WRAP
+SUBDIRS= . xi2
+noinst_PROGRAMS = xkb input xtest list misc fixes
+check_LTLIBRARIES = libxservertest.la
+
+TESTS=$(noinst_PROGRAMS)
+
+AM_CFLAGS = $(DIX_CFLAGS) @XORG_CFLAGS@
+INCLUDES = $(XORG_INCS) -I$(top_srcdir)/hw/xfree86/parser \
+ -I$(top_srcdir)/miext/cw -I$(top_srcdir)/hw/xfree86/ddc \
+ -I$(top_srcdir)/hw/xfree86/i2c -I$(top_srcdir)/hw/xfree86/modes \
+ -I$(top_srcdir)/hw/xfree86/ramdac
+TEST_LDADD=libxservertest.la $(XORG_SYS_LIBS) $(XSERVER_SYS_LIBS)
+
+if SPECIAL_DTRACE_OBJECTS
+TEST_LDADD += $(OS_LIB) $(DIX_LIB)
+endif
+
+xkb_LDADD=$(TEST_LDADD)
+input_LDADD=$(TEST_LDADD)
+xtest_LDADD=$(TEST_LDADD)
+list_LDADD=$(TEST_LDADD)
+misc_LDADD=$(TEST_LDADD)
+fixes_LDADD=$(TEST_LDADD)
+
+nodist_libxservertest_la_SOURCES = $(top_builddir)/hw/xfree86/sdksyms.c
+libxservertest_la_LIBADD = \
+ $(XSERVER_LIBS) \
+ $(top_builddir)/hw/xfree86/loader/libloader.la \
+ $(top_builddir)/hw/xfree86/os-support/libxorgos.la \
+ $(top_builddir)/hw/xfree86/common/libcommon.la \
+ $(top_builddir)/hw/xfree86/parser/libxf86config_internal.la \
+ $(top_builddir)/hw/xfree86/dixmods/libdixmods.la \
+ $(top_builddir)/hw/xfree86/modes/libxf86modes.la \
+ $(top_builddir)/hw/xfree86/ramdac/libramdac.la \
+ $(top_builddir)/hw/xfree86/ddc/libddc.la \
+ $(top_builddir)/hw/xfree86/i2c/libi2c.la \
+ $(top_builddir)/hw/xfree86/dixmods/libxorgxkb.la \
+ $(top_builddir)/mi/libmi.la \
+ $(top_builddir)/os/libos.la \
+ @XORG_LIBS@
+libxservertest_la_DEPENDENCIES = $(libxservertest_la_LIBADD)
+endif
+endif
diff --git a/xorg-server/test/input.c b/xorg-server/test/input.c index 837ce49dc..87c752a7f 100644 --- a/xorg-server/test/input.c +++ b/xorg-server/test/input.c @@ -1,1254 +1,1254 @@ -/** - * Copyright © 2009 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include <dix-config.h> -#endif - -#include <stdint.h> -#include <X11/X.h> -#include "misc.h" -#include "resource.h" -#include <X11/Xproto.h> -#include <X11/extensions/XI2proto.h> -#include <X11/Xatom.h> -#include "windowstr.h" -#include "inputstr.h" -#include "eventconvert.h" -#include "exevents.h" -#include "exglobals.h" -#include "dixgrabs.h" -#include "eventstr.h" -#include "inpututils.h" -#include "assert.h" - -/** - * Init a device with axes. - * Verify values set on the device. - * - * Result: All axes set to default values (usually 0). - */ -static void dix_init_valuators(void) -{ - DeviceIntRec dev; - ValuatorClassPtr val; - const int num_axes = 2; - int i; - Atom atoms[MAX_VALUATORS] = { 0 }; - - - memset(&dev, 0, sizeof(DeviceIntRec)); - dev.type = MASTER_POINTER; /* claim it's a master to stop ptracccel */ - - assert(InitValuatorClassDeviceStruct(NULL, 0, atoms, 0, 0) == FALSE); - assert(InitValuatorClassDeviceStruct(&dev, num_axes, atoms, 0, Absolute)); - - val = dev.valuator; - assert(val); - assert(val->numAxes == num_axes); - assert(val->numMotionEvents == 0); - assert(val->axisVal); - - for (i = 0; i < num_axes; i++) - { - assert(val->axisVal[i] == 0); - assert(val->axes->min_value == NO_AXIS_LIMITS); - assert(val->axes->max_value == NO_AXIS_LIMITS); - assert(val->axes->mode == Absolute); - } - - assert(dev.last.numValuators == num_axes); -} - -/* just check the known success cases, and that error cases set the client's - * error value correctly. */ -static void dix_check_grab_values(void) -{ - ClientRec client; - GrabParameters param; - int rc; - - memset(&client, 0, sizeof(client)); - - param.grabtype = GRABTYPE_CORE; - param.this_device_mode = GrabModeSync; - param.other_devices_mode = GrabModeSync; - param.modifiers = AnyModifier; - param.ownerEvents = FALSE; - - rc = CheckGrabValues(&client, ¶m); - assert(rc == Success); - - param.this_device_mode = GrabModeAsync; - rc = CheckGrabValues(&client, ¶m); - assert(rc == Success); - - param.this_device_mode = GrabModeAsync + 1; - rc = CheckGrabValues(&client, ¶m); - assert(rc == BadValue); - assert(client.errorValue == param.this_device_mode); - assert(client.errorValue == GrabModeAsync + 1); - - param.this_device_mode = GrabModeSync; - param.other_devices_mode = GrabModeAsync; - rc = CheckGrabValues(&client, ¶m); - assert(rc == Success); - - param.other_devices_mode = GrabModeAsync + 1; - rc = CheckGrabValues(&client, ¶m); - assert(rc == BadValue); - assert(client.errorValue == param.other_devices_mode); - assert(client.errorValue == GrabModeAsync + 1); - - param.other_devices_mode = GrabModeSync; - - param.modifiers = 1 << 13; - rc = CheckGrabValues(&client, ¶m); - assert(rc == BadValue); - assert(client.errorValue == param.modifiers); - assert(client.errorValue == (1 << 13)); - - - param.modifiers = AnyModifier; - param.ownerEvents = TRUE; - rc = CheckGrabValues(&client, ¶m); - assert(rc == Success); - - param.ownerEvents = 3; - rc = CheckGrabValues(&client, ¶m); - assert(rc == BadValue); - assert(client.errorValue == param.ownerEvents); - assert(client.errorValue == 3); -} - - -/** - * Convert various internal events to the matching core event and verify the - * parameters. - */ -static void dix_event_to_core(int type) -{ - DeviceEvent ev; - xEvent *core; - int time; - int x, y; - int rc; - int state; - int detail; - int count; - const int ROOT_WINDOW_ID = 0x100; - - /* EventToCore memsets the event to 0 */ -#define test_event() \ - assert(rc == Success); \ - assert(core); \ - assert(count == 1); \ - assert(core->u.u.type == type); \ - assert(core->u.u.detail == detail); \ - assert(core->u.keyButtonPointer.time == time); \ - assert(core->u.keyButtonPointer.rootX == x); \ - assert(core->u.keyButtonPointer.rootY == y); \ - assert(core->u.keyButtonPointer.state == state); \ - assert(core->u.keyButtonPointer.eventX == 0); \ - assert(core->u.keyButtonPointer.eventY == 0); \ - assert(core->u.keyButtonPointer.root == ROOT_WINDOW_ID); \ - assert(core->u.keyButtonPointer.event == 0); \ - assert(core->u.keyButtonPointer.child == 0); \ - assert(core->u.keyButtonPointer.sameScreen == FALSE); - - x = 0; - y = 0; - time = 12345; - state = 0; - detail = 0; - - ev.header = 0xFF; - ev.length = sizeof(DeviceEvent); - ev.time = time; - ev.root_y = x; - ev.root_x = y; - SetBit(ev.valuators.mask, 0); - SetBit(ev.valuators.mask, 1); - ev.root = ROOT_WINDOW_ID; - ev.corestate = state; - ev.detail.key = detail; - - ev.type = type; - ev.detail.key = 0; - rc = EventToCore((InternalEvent*)&ev, &core, &count); - test_event(); - - x = 1; - y = 2; - ev.root_x = x; - ev.root_y = y; - rc = EventToCore((InternalEvent*)&ev, &core, &count); - test_event(); - - x = 0x7FFF; - y = 0x7FFF; - ev.root_x = x; - ev.root_y = y; - rc = EventToCore((InternalEvent*)&ev, &core, &count); - test_event(); - - x = 0x8000; /* too high */ - y = 0x8000; /* too high */ - ev.root_x = x; - ev.root_y = y; - rc = EventToCore((InternalEvent*)&ev, &core, &count); - assert(rc == Success); - assert(core); - assert(count == 1); - assert(core->u.keyButtonPointer.rootX != x); - assert(core->u.keyButtonPointer.rootY != y); - - x = 0x7FFF; - y = 0x7FFF; - ev.root_x = x; - ev.root_y = y; - time = 0; - ev.time = time; - rc = EventToCore((InternalEvent*)&ev, &core, &count); - test_event(); - - detail = 1; - ev.detail.key = detail; - rc = EventToCore((InternalEvent*)&ev, &core, &count); - test_event(); - - detail = 0xFF; /* highest value */ - ev.detail.key = detail; - rc = EventToCore((InternalEvent*)&ev, &core, &count); - test_event(); - - detail = 0xFFF; /* too big */ - ev.detail.key = detail; - rc = EventToCore((InternalEvent*)&ev, &core, &count); - assert(rc == BadMatch); - - detail = 0xFF; /* too big */ - ev.detail.key = detail; - state = 0xFFFF; /* highest value */ - ev.corestate = state; - rc = EventToCore((InternalEvent*)&ev, &core, &count); - test_event(); - - state = 0x10000; /* too big */ - ev.corestate = state; - rc = EventToCore((InternalEvent*)&ev, &core, &count); - assert(rc == Success); - assert(core); - assert(count == 1); - assert(core->u.keyButtonPointer.state != state); - assert(core->u.keyButtonPointer.state == (state & 0xFFFF)); - -#undef test_event -} - -static void dix_event_to_core_fail(int evtype, int expected_rc) -{ - DeviceEvent ev; - xEvent *core; - int rc; - int count; - - ev.header = 0xFF; - ev.length = sizeof(DeviceEvent); - - ev.type = evtype; - rc = EventToCore((InternalEvent*)&ev, &core, &count); - assert(rc == expected_rc); -} - -static void dix_event_to_core_conversion(void) -{ - dix_event_to_core_fail(0, BadImplementation); - dix_event_to_core_fail(1, BadImplementation); - dix_event_to_core_fail(ET_ProximityOut + 1, BadImplementation); - dix_event_to_core_fail(ET_ProximityIn, BadMatch); - dix_event_to_core_fail(ET_ProximityOut, BadMatch); - - dix_event_to_core(ET_KeyPress); - dix_event_to_core(ET_KeyRelease); - dix_event_to_core(ET_ButtonPress); - dix_event_to_core(ET_ButtonRelease); - dix_event_to_core(ET_Motion); -} - -static void -_dix_test_xi_convert(DeviceEvent *ev, int expected_rc, int expected_count) -{ - xEvent *xi; - int count = 0; - int rc; - - rc = EventToXI((InternalEvent*)ev, &xi, &count); - assert(rc == expected_rc); - assert(count >= expected_count); - if (count > 0){ - deviceKeyButtonPointer *kbp = (deviceKeyButtonPointer*)xi; - assert(kbp->type == IEventBase + ev->type); - assert(kbp->detail == ev->detail.key); - assert(kbp->time == ev->time); - assert((kbp->deviceid & ~MORE_EVENTS) == ev->deviceid); - assert(kbp->root_x == ev->root_x); - assert(kbp->root_y == ev->root_y); - assert(kbp->state == ev->corestate); - assert(kbp->event_x == 0); - assert(kbp->event_y == 0); - assert(kbp->root == ev->root); - assert(kbp->event == 0); - assert(kbp->child == 0); - assert(kbp->same_screen == FALSE); - - while (--count > 0) { - deviceValuator *v = (deviceValuator*)&xi[count]; - assert(v->type == DeviceValuator); - assert(v->num_valuators <= 6); - } - - - free(xi); - } -} - -/** - * This tests for internal event → XI1 event conversion - * - all conversions should generate the right XI event type - * - right number of events generated - * - extra events are valuators - */ -static void dix_event_to_xi1_conversion(void) -{ - DeviceEvent ev = {0}; - int time; - int x, y; - int state; - int detail; - const int ROOT_WINDOW_ID = 0x100; - int deviceid; - - IEventBase = 80; - DeviceValuator = IEventBase - 1; - DeviceKeyPress = IEventBase + ET_KeyPress; - DeviceKeyRelease = IEventBase + ET_KeyRelease; - DeviceButtonPress = IEventBase + ET_ButtonPress; - DeviceButtonRelease = IEventBase + ET_ButtonRelease; - DeviceMotionNotify = IEventBase + ET_Motion; - DeviceFocusIn = IEventBase + ET_FocusIn; - DeviceFocusOut = IEventBase + ET_FocusOut; - ProximityIn = IEventBase + ET_ProximityIn; - ProximityOut = IEventBase + ET_ProximityOut; - - /* EventToXI callocs */ - x = 0; - y = 0; - time = 12345; - state = 0; - detail = 0; - deviceid = 4; - - ev.header = 0xFF; - - ev.header = 0xFF; - ev.length = sizeof(DeviceEvent); - ev.time = time; - ev.root_y = x; - ev.root_x = y; - SetBit(ev.valuators.mask, 0); - SetBit(ev.valuators.mask, 1); - ev.root = ROOT_WINDOW_ID; - ev.corestate = state; - ev.detail.key = detail; - ev.deviceid = deviceid; - - /* test all types for bad match */ - ev.type = ET_KeyPress; _dix_test_xi_convert(&ev, Success, 1); - ev.type = ET_KeyRelease; _dix_test_xi_convert(&ev, Success, 1); - ev.type = ET_ButtonPress; _dix_test_xi_convert(&ev, Success, 1); - ev.type = ET_ButtonRelease; _dix_test_xi_convert(&ev, Success, 1); - ev.type = ET_Motion; _dix_test_xi_convert(&ev, Success, 1); - ev.type = ET_ProximityIn; _dix_test_xi_convert(&ev, Success, 1); - ev.type = ET_ProximityOut; _dix_test_xi_convert(&ev, Success, 1); - - /* No axes */ - ClearBit(ev.valuators.mask, 0); - ClearBit(ev.valuators.mask, 1); - ev.type = ET_KeyPress; _dix_test_xi_convert(&ev, Success, 1); - ev.type = ET_KeyRelease; _dix_test_xi_convert(&ev, Success, 1); - ev.type = ET_ButtonPress; _dix_test_xi_convert(&ev, Success, 1); - ev.type = ET_ButtonRelease; _dix_test_xi_convert(&ev, Success, 1); - ev.type = ET_Motion; _dix_test_xi_convert(&ev, BadMatch, 0); - ev.type = ET_ProximityIn; _dix_test_xi_convert(&ev, BadMatch, 0); - ev.type = ET_ProximityOut; _dix_test_xi_convert(&ev, BadMatch, 0); - - /* more than 6 axes → 2 valuator events */ - SetBit(ev.valuators.mask, 0); - SetBit(ev.valuators.mask, 1); - SetBit(ev.valuators.mask, 2); - SetBit(ev.valuators.mask, 3); - SetBit(ev.valuators.mask, 4); - SetBit(ev.valuators.mask, 5); - SetBit(ev.valuators.mask, 6); - ev.type = ET_KeyPress; _dix_test_xi_convert(&ev, Success, 2); - ev.type = ET_KeyRelease; _dix_test_xi_convert(&ev, Success, 2); - ev.type = ET_ButtonPress; _dix_test_xi_convert(&ev, Success, 2); - ev.type = ET_ButtonRelease; _dix_test_xi_convert(&ev, Success, 2); - ev.type = ET_Motion; _dix_test_xi_convert(&ev, Success, 2); - ev.type = ET_ProximityIn; _dix_test_xi_convert(&ev, Success, 2); - ev.type = ET_ProximityOut; _dix_test_xi_convert(&ev, Success, 2); - - - /* keycode too high */ - ev.type = ET_KeyPress; - ev.detail.key = 256; - _dix_test_xi_convert(&ev, Success, 0); - - /* deviceid too high */ - ev.type = ET_KeyPress; - ev.detail.key = 18; - ev.deviceid = 128; - _dix_test_xi_convert(&ev, Success, 0); -} - - -static void xi2_struct_sizes(void) -{ -#define compare(req) \ - assert(sizeof(req) == sz_##req); - - compare(xXIQueryVersionReq); - compare(xXIWarpPointerReq); - compare(xXIChangeCursorReq); - compare(xXIChangeHierarchyReq); - compare(xXISetClientPointerReq); - compare(xXIGetClientPointerReq); - compare(xXISelectEventsReq); - compare(xXIQueryVersionReq); - compare(xXIQueryDeviceReq); - compare(xXISetFocusReq); - compare(xXIGetFocusReq); - compare(xXIGrabDeviceReq); - compare(xXIUngrabDeviceReq); - compare(xXIAllowEventsReq); - compare(xXIPassiveGrabDeviceReq); - compare(xXIPassiveUngrabDeviceReq); - compare(xXIListPropertiesReq); - compare(xXIChangePropertyReq); - compare(xXIDeletePropertyReq); - compare(xXIGetPropertyReq); - compare(xXIGetSelectedEventsReq); -#undef compare -} - - -static void dix_grab_matching(void) -{ - DeviceIntRec xi_all_devices, xi_all_master_devices, dev1, dev2; - GrabRec a, b; - BOOL rc; - - memset(&a, 0, sizeof(a)); - memset(&b, 0, sizeof(b)); - - /* different grabtypes must fail */ - a.grabtype = GRABTYPE_CORE; - b.grabtype = GRABTYPE_XI2; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == FALSE); - rc = GrabMatchesSecond(&b, &a, FALSE); - assert(rc == FALSE); - - a.grabtype = GRABTYPE_XI; - b.grabtype = GRABTYPE_XI2; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == FALSE); - rc = GrabMatchesSecond(&b, &a, FALSE); - assert(rc == FALSE); - - a.grabtype = GRABTYPE_XI; - b.grabtype = GRABTYPE_CORE; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == FALSE); - rc = GrabMatchesSecond(&b, &a, FALSE); - assert(rc == FALSE); - - /* XI2 grabs for different devices must fail, regardless of ignoreDevice - * XI2 grabs for master devices must fail against a slave */ - memset(&xi_all_devices, 0, sizeof(DeviceIntRec)); - memset(&xi_all_master_devices, 0, sizeof(DeviceIntRec)); - memset(&dev1, 0, sizeof(DeviceIntRec)); - memset(&dev2, 0, sizeof(DeviceIntRec)); - - xi_all_devices.id = XIAllDevices; - xi_all_master_devices.id = XIAllMasterDevices; - dev1.id = 10; - dev1.type = SLAVE; - dev2.id = 11; - dev2.type = SLAVE; - - inputInfo.all_devices = &xi_all_devices; - inputInfo.all_master_devices = &xi_all_master_devices; - a.grabtype = GRABTYPE_XI2; - b.grabtype = GRABTYPE_XI2; - a.device = &dev1; - b.device = &dev2; - - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == FALSE); - - a.device = &dev2; - b.device = &dev1; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == FALSE); - rc = GrabMatchesSecond(&a, &b, TRUE); - assert(rc == FALSE); - - a.device = inputInfo.all_master_devices; - b.device = &dev1; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == FALSE); - rc = GrabMatchesSecond(&a, &b, TRUE); - assert(rc == FALSE); - - a.device = &dev1; - b.device = inputInfo.all_master_devices; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == FALSE); - rc = GrabMatchesSecond(&a, &b, TRUE); - assert(rc == FALSE); - - /* ignoreDevice FALSE must fail for different devices for CORE and XI */ - a.grabtype = GRABTYPE_XI; - b.grabtype = GRABTYPE_XI; - a.device = &dev1; - b.device = &dev2; - a.modifierDevice = &dev1; - b.modifierDevice = &dev1; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == FALSE); - - a.grabtype = GRABTYPE_CORE; - b.grabtype = GRABTYPE_CORE; - a.device = &dev1; - b.device = &dev2; - a.modifierDevice = &dev1; - b.modifierDevice = &dev1; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == FALSE); - - /* ignoreDevice FALSE must fail for different modifier devices for CORE - * and XI */ - a.grabtype = GRABTYPE_XI; - b.grabtype = GRABTYPE_XI; - a.device = &dev1; - b.device = &dev1; - a.modifierDevice = &dev1; - b.modifierDevice = &dev2; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == FALSE); - - a.grabtype = GRABTYPE_CORE; - b.grabtype = GRABTYPE_CORE; - a.device = &dev1; - b.device = &dev1; - a.modifierDevice = &dev1; - b.modifierDevice = &dev2; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == FALSE); - - /* different event type must fail */ - a.grabtype = GRABTYPE_XI2; - b.grabtype = GRABTYPE_XI2; - a.device = &dev1; - b.device = &dev1; - a.modifierDevice = &dev1; - b.modifierDevice = &dev1; - a.type = XI_KeyPress; - b.type = XI_KeyRelease; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == FALSE); - rc = GrabMatchesSecond(&a, &b, TRUE); - assert(rc == FALSE); - - a.grabtype = GRABTYPE_CORE; - b.grabtype = GRABTYPE_CORE; - a.device = &dev1; - b.device = &dev1; - a.modifierDevice = &dev1; - b.modifierDevice = &dev1; - a.type = XI_KeyPress; - b.type = XI_KeyRelease; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == FALSE); - rc = GrabMatchesSecond(&a, &b, TRUE); - assert(rc == FALSE); - - a.grabtype = GRABTYPE_XI; - b.grabtype = GRABTYPE_XI; - a.device = &dev1; - b.device = &dev1; - a.modifierDevice = &dev1; - b.modifierDevice = &dev1; - a.type = XI_KeyPress; - b.type = XI_KeyRelease; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == FALSE); - rc = GrabMatchesSecond(&a, &b, TRUE); - assert(rc == FALSE); - - /* different modifiers must fail */ - a.grabtype = GRABTYPE_XI2; - b.grabtype = GRABTYPE_XI2; - a.device = &dev1; - b.device = &dev1; - a.modifierDevice = &dev1; - b.modifierDevice = &dev1; - a.type = XI_KeyPress; - b.type = XI_KeyPress; - a.modifiersDetail.exact = 1; - b.modifiersDetail.exact = 2; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == FALSE); - rc = GrabMatchesSecond(&b, &a, FALSE); - assert(rc == FALSE); - - a.grabtype = GRABTYPE_CORE; - b.grabtype = GRABTYPE_CORE; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == FALSE); - rc = GrabMatchesSecond(&b, &a, FALSE); - assert(rc == FALSE); - - a.grabtype = GRABTYPE_XI; - b.grabtype = GRABTYPE_XI; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == FALSE); - rc = GrabMatchesSecond(&b, &a, FALSE); - assert(rc == FALSE); - - /* AnyModifier must fail for XI2 */ - a.grabtype = GRABTYPE_XI2; - b.grabtype = GRABTYPE_XI2; - a.modifiersDetail.exact = AnyModifier; - b.modifiersDetail.exact = 1; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == FALSE); - rc = GrabMatchesSecond(&b, &a, FALSE); - assert(rc == FALSE); - - /* XIAnyModifier must fail for CORE and XI */ - a.grabtype = GRABTYPE_XI; - b.grabtype = GRABTYPE_XI; - a.modifiersDetail.exact = XIAnyModifier; - b.modifiersDetail.exact = 1; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == FALSE); - rc = GrabMatchesSecond(&b, &a, FALSE); - assert(rc == FALSE); - - a.grabtype = GRABTYPE_CORE; - b.grabtype = GRABTYPE_CORE; - a.modifiersDetail.exact = XIAnyModifier; - b.modifiersDetail.exact = 1; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == FALSE); - rc = GrabMatchesSecond(&b, &a, FALSE); - assert(rc == FALSE); - - /* different detail must fail */ - a.grabtype = GRABTYPE_XI2; - b.grabtype = GRABTYPE_XI2; - a.detail.exact = 1; - b.detail.exact = 2; - a.modifiersDetail.exact = 1; - b.modifiersDetail.exact = 1; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == FALSE); - rc = GrabMatchesSecond(&b, &a, FALSE); - assert(rc == FALSE); - - a.grabtype = GRABTYPE_XI; - b.grabtype = GRABTYPE_XI; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == FALSE); - rc = GrabMatchesSecond(&b, &a, FALSE); - assert(rc == FALSE); - - a.grabtype = GRABTYPE_CORE; - b.grabtype = GRABTYPE_CORE; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == FALSE); - rc = GrabMatchesSecond(&b, &a, FALSE); - assert(rc == FALSE); - - /* detail of AnyModifier must fail */ - a.grabtype = GRABTYPE_XI2; - b.grabtype = GRABTYPE_XI2; - a.detail.exact = AnyModifier; - b.detail.exact = 1; - a.modifiersDetail.exact = 1; - b.modifiersDetail.exact = 1; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == FALSE); - rc = GrabMatchesSecond(&b, &a, FALSE); - assert(rc == FALSE); - - a.grabtype = GRABTYPE_CORE; - b.grabtype = GRABTYPE_CORE; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == FALSE); - rc = GrabMatchesSecond(&b, &a, FALSE); - assert(rc == FALSE); - - a.grabtype = GRABTYPE_XI; - b.grabtype = GRABTYPE_XI; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == FALSE); - rc = GrabMatchesSecond(&b, &a, FALSE); - assert(rc == FALSE); - - /* detail of XIAnyModifier must fail */ - a.grabtype = GRABTYPE_XI2; - b.grabtype = GRABTYPE_XI2; - a.detail.exact = XIAnyModifier; - b.detail.exact = 1; - a.modifiersDetail.exact = 1; - b.modifiersDetail.exact = 1; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == FALSE); - rc = GrabMatchesSecond(&b, &a, FALSE); - assert(rc == FALSE); - - a.grabtype = GRABTYPE_CORE; - b.grabtype = GRABTYPE_CORE; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == FALSE); - rc = GrabMatchesSecond(&b, &a, FALSE); - assert(rc == FALSE); - - a.grabtype = GRABTYPE_XI; - b.grabtype = GRABTYPE_XI; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == FALSE); - rc = GrabMatchesSecond(&b, &a, FALSE); - assert(rc == FALSE); - - /* XIAnyModifier or AnyModifer must succeed */ - a.grabtype = GRABTYPE_XI2; - b.grabtype = GRABTYPE_XI2; - a.detail.exact = 1; - b.detail.exact = 1; - a.modifiersDetail.exact = XIAnyModifier; - b.modifiersDetail.exact = 1; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == TRUE); - rc = GrabMatchesSecond(&b, &a, FALSE); - assert(rc == TRUE); - - a.grabtype = GRABTYPE_CORE; - b.grabtype = GRABTYPE_CORE; - a.detail.exact = 1; - b.detail.exact = 1; - a.modifiersDetail.exact = AnyModifier; - b.modifiersDetail.exact = 1; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == TRUE); - rc = GrabMatchesSecond(&b, &a, FALSE); - assert(rc == TRUE); - - a.grabtype = GRABTYPE_XI; - b.grabtype = GRABTYPE_XI; - a.detail.exact = 1; - b.detail.exact = 1; - a.modifiersDetail.exact = AnyModifier; - b.modifiersDetail.exact = 1; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == TRUE); - rc = GrabMatchesSecond(&b, &a, FALSE); - assert(rc == TRUE); - - /* AnyKey or XIAnyKeycode must succeed */ - a.grabtype = GRABTYPE_XI2; - b.grabtype = GRABTYPE_XI2; - a.detail.exact = XIAnyKeycode; - b.detail.exact = 1; - a.modifiersDetail.exact = 1; - b.modifiersDetail.exact = 1; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == TRUE); - rc = GrabMatchesSecond(&b, &a, FALSE); - assert(rc == TRUE); - - a.grabtype = GRABTYPE_CORE; - b.grabtype = GRABTYPE_CORE; - a.detail.exact = AnyKey; - b.detail.exact = 1; - a.modifiersDetail.exact = 1; - b.modifiersDetail.exact = 1; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == TRUE); - rc = GrabMatchesSecond(&b, &a, FALSE); - assert(rc == TRUE); - - a.grabtype = GRABTYPE_XI; - b.grabtype = GRABTYPE_XI; - a.detail.exact = AnyKey; - b.detail.exact = 1; - a.modifiersDetail.exact = 1; - b.modifiersDetail.exact = 1; - rc = GrabMatchesSecond(&a, &b, FALSE); - assert(rc == TRUE); - rc = GrabMatchesSecond(&b, &a, FALSE); - assert(rc == TRUE); -} - -static void test_bits_to_byte(int i) -{ - int expected_bytes; - expected_bytes = (i + 7)/8; - - assert(bits_to_bytes(i) >= i/8); - assert((bits_to_bytes(i) * 8) - i <= 7); - assert(expected_bytes == bits_to_bytes(i)); -} - -static void test_bytes_to_int32(int i) -{ - int expected_4byte; - expected_4byte = (i + 3)/4; - - assert(bytes_to_int32(i) <= i); - assert((bytes_to_int32(i) * 4) - i <= 3); - assert(expected_4byte == bytes_to_int32(i)); -} - -static void test_pad_to_int32(int i) -{ - int expected_bytes; - expected_bytes = ((i + 3)/4) * 4; - - assert(pad_to_int32(i) >= i); - assert(pad_to_int32(i) - i <= 3); - assert(expected_bytes == pad_to_int32(i)); -} -static void include_byte_padding_macros(void) -{ - printf("Testing bits_to_bytes()\n"); - - /* the macros don't provide overflow protection */ - test_bits_to_byte(0); - test_bits_to_byte(1); - test_bits_to_byte(2); - test_bits_to_byte(7); - test_bits_to_byte(8); - test_bits_to_byte(0xFF); - test_bits_to_byte(0x100); - test_bits_to_byte(INT_MAX - 9); - test_bits_to_byte(INT_MAX - 8); - - printf("Testing bytes_to_int32()\n"); - - test_bytes_to_int32(0); - test_bytes_to_int32(1); - test_bytes_to_int32(2); - test_bytes_to_int32(7); - test_bytes_to_int32(8); - test_bytes_to_int32(0xFF); - test_bytes_to_int32(0x100); - test_bytes_to_int32(0xFFFF); - test_bytes_to_int32(0x10000); - test_bytes_to_int32(0xFFFFFF); - test_bytes_to_int32(0x1000000); - test_bytes_to_int32(INT_MAX - 4); - test_bytes_to_int32(INT_MAX - 3); - - printf("Testing pad_to_int32\n"); - - test_pad_to_int32(0); - test_pad_to_int32(0); - test_pad_to_int32(1); - test_pad_to_int32(2); - test_pad_to_int32(7); - test_pad_to_int32(8); - test_pad_to_int32(0xFF); - test_pad_to_int32(0x100); - test_pad_to_int32(0xFFFF); - test_pad_to_int32(0x10000); - test_pad_to_int32(0xFFFFFF); - test_pad_to_int32(0x1000000); - test_pad_to_int32(INT_MAX - 4); - test_pad_to_int32(INT_MAX - 3); -} - -static void xi_unregister_handlers(void) -{ - DeviceIntRec dev; - int handler; - - memset(&dev, 0, sizeof(dev)); - - handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL); - assert(handler == 1); - handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL); - assert(handler == 2); - handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL); - assert(handler == 3); - - printf("Unlinking from front.\n"); - - XIUnregisterPropertyHandler(&dev, 4); /* NOOP */ - assert(dev.properties.handlers->id == 3); - XIUnregisterPropertyHandler(&dev, 3); - assert(dev.properties.handlers->id == 2); - XIUnregisterPropertyHandler(&dev, 2); - assert(dev.properties.handlers->id == 1); - XIUnregisterPropertyHandler(&dev, 1); - assert(dev.properties.handlers == NULL); - - handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL); - assert(handler == 4); - handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL); - assert(handler == 5); - handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL); - assert(handler == 6); - XIUnregisterPropertyHandler(&dev, 3); /* NOOP */ - assert(dev.properties.handlers->next->next->next == NULL); - XIUnregisterPropertyHandler(&dev, 4); - assert(dev.properties.handlers->next->next == NULL); - XIUnregisterPropertyHandler(&dev, 5); - assert(dev.properties.handlers->next == NULL); - XIUnregisterPropertyHandler(&dev, 6); - assert(dev.properties.handlers == NULL); - - handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL); - assert(handler == 7); - handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL); - assert(handler == 8); - handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL); - assert(handler == 9); - - XIDeleteAllDeviceProperties(&dev); - assert(dev.properties.handlers == NULL); - XIUnregisterPropertyHandler(&dev, 7); /* NOOP */ - -} - -static void cmp_attr_fields(InputAttributes *attr1, - InputAttributes *attr2) -{ - char **tags1, **tags2; - - assert(attr1 && attr2); - assert(attr1 != attr2); - assert(attr1->flags == attr2->flags); - - if (attr1->product != NULL) - { - assert(attr1->product != attr2->product); - assert(strcmp(attr1->product, attr2->product) == 0); - } else - assert(attr2->product == NULL); - - if (attr1->vendor != NULL) - { - assert(attr1->vendor != attr2->vendor); - assert(strcmp(attr1->vendor, attr2->vendor) == 0); - } else - assert(attr2->vendor == NULL); - - if (attr1->device != NULL) - { - assert(attr1->device != attr2->device); - assert(strcmp(attr1->device, attr2->device) == 0); - } else - assert(attr2->device == NULL); - - if (attr1->pnp_id != NULL) - { - assert(attr1->pnp_id != attr2->pnp_id); - assert(strcmp(attr1->pnp_id, attr2->pnp_id) == 0); - } else - assert(attr2->pnp_id == NULL); - - if (attr1->usb_id != NULL) - { - assert(attr1->usb_id != attr2->usb_id); - assert(strcmp(attr1->usb_id, attr2->usb_id) == 0); - } else - assert(attr2->usb_id == NULL); - - tags1 = attr1->tags; - tags2 = attr2->tags; - - /* if we don't have any tags, skip the tag checking bits */ - if (!tags1) - { - assert(!tags2); - return; - } - - /* Don't lug around empty arrays */ - assert(*tags1); - assert(*tags2); - - /* check for identical content, but duplicated */ - while (*tags1) - { - assert(*tags1 != *tags2); - assert(strcmp(*tags1, *tags2) == 0); - tags1++; - tags2++; - } - - /* ensure tags1 and tags2 have the same no of elements */ - assert(!*tags2); - - /* check for not sharing memory */ - tags1 = attr1->tags; - while (*tags1) - { - tags2 = attr2->tags; - while (*tags2) - assert(*tags1 != *tags2++); - - tags1++; - } -} - -static void dix_input_attributes(void) -{ - InputAttributes orig = {0}; - InputAttributes *new; - char *tags[4] = {"tag1", "tag2", "tag2", NULL}; - - new = DuplicateInputAttributes(NULL); - assert(!new); - - new = DuplicateInputAttributes(&orig); - assert(memcmp(&orig, new, sizeof(InputAttributes)) == 0); - - orig.product = "product name"; - new = DuplicateInputAttributes(&orig); - cmp_attr_fields(&orig, new); - FreeInputAttributes(new); - - orig.vendor = "vendor name"; - new = DuplicateInputAttributes(&orig); - cmp_attr_fields(&orig, new); - FreeInputAttributes(new); - - orig.device = "device path"; - new = DuplicateInputAttributes(&orig); - cmp_attr_fields(&orig, new); - FreeInputAttributes(new); - - orig.pnp_id = "PnPID"; - new = DuplicateInputAttributes(&orig); - cmp_attr_fields(&orig, new); - FreeInputAttributes(new); - - orig.usb_id = "USBID"; - new = DuplicateInputAttributes(&orig); - cmp_attr_fields(&orig, new); - FreeInputAttributes(new); - - orig.flags = 0xF0; - new = DuplicateInputAttributes(&orig); - cmp_attr_fields(&orig, new); - FreeInputAttributes(new); - - orig.tags = tags; - new = DuplicateInputAttributes(&orig); - cmp_attr_fields(&orig, new); - FreeInputAttributes(new); -} - -static void dix_input_valuator_masks(void) -{ - ValuatorMask *mask = NULL, *copy; - int nvaluators = MAX_VALUATORS; - int valuators[nvaluators]; - int i; - int first_val, num_vals; - - for (i = 0; i < nvaluators; i++) - valuators[i] = i; - - mask = valuator_mask_new(nvaluators); - assert(mask != NULL); - assert(valuator_mask_size(mask) == 0); - assert(valuator_mask_num_valuators(mask) == 0); - - for (i = 0; i < nvaluators; i++) - { - assert(!valuator_mask_isset(mask, i)); - valuator_mask_set(mask, i, valuators[i]); - assert(valuator_mask_isset(mask, i)); - assert(valuator_mask_get(mask, i) == valuators[i]); - assert(valuator_mask_size(mask) == i + 1); - assert(valuator_mask_num_valuators(mask) == i + 1); - } - - for (i = 0; i < nvaluators; i++) - { - assert(valuator_mask_isset(mask, i)); - valuator_mask_unset(mask, i); - /* we're removing valuators from the front, so size should stay the - * same until the last bit is removed */ - if (i < nvaluators - 1) - assert(valuator_mask_size(mask) == nvaluators); - assert(!valuator_mask_isset(mask, i)); - } - - assert(valuator_mask_size(mask) == 0); - valuator_mask_zero(mask); - assert(valuator_mask_size(mask) == 0); - assert(valuator_mask_num_valuators(mask) == 0); - for (i = 0; i < nvaluators; i++) - assert(!valuator_mask_isset(mask, i)); - - first_val = 5; - num_vals = 6; - - valuator_mask_set_range(mask, first_val, num_vals, valuators); - assert(valuator_mask_size(mask) == first_val + num_vals); - assert(valuator_mask_num_valuators(mask) == num_vals); - for (i = 0; i < nvaluators; i++) - { - if (i < first_val || i >= first_val + num_vals) - assert(!valuator_mask_isset(mask, i)); - else - { - assert(valuator_mask_isset(mask, i)); - assert(valuator_mask_get(mask, i) == valuators[i - first_val]); - } - } - - copy = valuator_mask_new(nvaluators); - valuator_mask_copy(copy, mask); - assert(mask != copy); - assert(valuator_mask_size(mask) == valuator_mask_size(copy)); - assert(valuator_mask_num_valuators(mask) == valuator_mask_num_valuators(copy)); - - for (i = 0; i < nvaluators; i++) - { - assert(valuator_mask_isset(mask, i) == valuator_mask_isset(copy, i)); - assert(valuator_mask_get(mask, i) == valuator_mask_get(copy, i)); - } - - valuator_mask_free(&mask); - assert(mask == NULL); -} - -static void dix_valuator_mode(void) -{ - DeviceIntRec dev; - const int num_axes = MAX_VALUATORS; - int i; - Atom atoms[MAX_VALUATORS] = { 0 }; - - memset(&dev, 0, sizeof(DeviceIntRec)); - dev.type = MASTER_POINTER; /* claim it's a master to stop ptracccel */ - - assert(InitValuatorClassDeviceStruct(NULL, 0, atoms, 0, 0) == FALSE); - assert(InitValuatorClassDeviceStruct(&dev, num_axes, atoms, 0, Absolute)); - - for (i = 0; i < num_axes; i++) - { - assert(valuator_get_mode(&dev, i) == Absolute); - valuator_set_mode(&dev, i, Relative); - assert(dev.valuator->axes[i].mode == Relative); - assert(valuator_get_mode(&dev, i) == Relative); - } - - valuator_set_mode(&dev, VALUATOR_MODE_ALL_AXES, Absolute); - for (i = 0; i < num_axes; i++) - assert(valuator_get_mode(&dev, i) == Absolute); - - valuator_set_mode(&dev, VALUATOR_MODE_ALL_AXES, Relative); - for (i = 0; i < num_axes; i++) - assert(valuator_get_mode(&dev, i) == Relative); -} - -static void include_bit_test_macros(void) -{ - uint8_t mask[9] = { 0 }; - int i; - - for (i = 0; i < sizeof(mask)/sizeof(mask[0]); i++) - { - assert(BitIsOn(mask, i) == 0); - SetBit(mask, i); - assert(BitIsOn(mask, i) == 1); - assert(!!(mask[i/8] & (1 << (i % 8)))); - assert(CountBits(mask, sizeof(mask)) == 1); - ClearBit(mask, i); - assert(BitIsOn(mask, i) == 0); - } -} - -/** - * Ensure that val->axisVal and val->axes are aligned on doubles. - */ -static void dix_valuator_alloc(void) -{ - ValuatorClassPtr v = NULL; - int num_axes = 0; - - while (num_axes < 5) - { - v = AllocValuatorClass(v, num_axes); - - assert(v); - assert(v->numAxes == num_axes); -#ifndef __i386__ - /* must be double-aligned on 64 bit */ - assert(((void*)v->axisVal - (void*)v) % sizeof(double) == 0); - assert(((void*)v->axes - (void*)v) % sizeof(double) == 0); -#endif - num_axes ++; - } - - free(v); -} - -int main(int argc, char** argv) -{ - dix_input_valuator_masks(); - dix_input_attributes(); - dix_init_valuators(); - dix_event_to_core_conversion(); - dix_event_to_xi1_conversion(); - dix_check_grab_values(); - xi2_struct_sizes(); - dix_grab_matching(); - dix_valuator_mode(); - include_byte_padding_macros(); - include_bit_test_macros(); - xi_unregister_handlers(); - dix_valuator_alloc(); - - return 0; -} +/**
+ * Copyright © 2009 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <stdint.h>
+#include <X11/X.h>
+#include "misc.h"
+#include "resource.h"
+#include <X11/Xproto.h>
+#include <X11/extensions/XI2proto.h>
+#include <X11/Xatom.h>
+#include "windowstr.h"
+#include "inputstr.h"
+#include "eventconvert.h"
+#include "exevents.h"
+#include "exglobals.h"
+#include "dixgrabs.h"
+#include "eventstr.h"
+#include "inpututils.h"
+#include "assert.h"
+
+/**
+ * Init a device with axes.
+ * Verify values set on the device.
+ *
+ * Result: All axes set to default values (usually 0).
+ */
+static void dix_init_valuators(void)
+{
+ DeviceIntRec dev;
+ ValuatorClassPtr val;
+ const int num_axes = 2;
+ int i;
+ Atom atoms[MAX_VALUATORS] = { 0 };
+
+
+ memset(&dev, 0, sizeof(DeviceIntRec));
+ dev.type = MASTER_POINTER; /* claim it's a master to stop ptracccel */
+
+ assert(InitValuatorClassDeviceStruct(NULL, 0, atoms, 0, 0) == FALSE);
+ assert(InitValuatorClassDeviceStruct(&dev, num_axes, atoms, 0, Absolute));
+
+ val = dev.valuator;
+ assert(val);
+ assert(val->numAxes == num_axes);
+ assert(val->numMotionEvents == 0);
+ assert(val->axisVal);
+
+ for (i = 0; i < num_axes; i++)
+ {
+ assert(val->axisVal[i] == 0);
+ assert(val->axes->min_value == NO_AXIS_LIMITS);
+ assert(val->axes->max_value == NO_AXIS_LIMITS);
+ assert(val->axes->mode == Absolute);
+ }
+
+ assert(dev.last.numValuators == num_axes);
+}
+
+/* just check the known success cases, and that error cases set the client's
+ * error value correctly. */
+static void dix_check_grab_values(void)
+{
+ ClientRec client;
+ GrabParameters param;
+ int rc;
+
+ memset(&client, 0, sizeof(client));
+
+ param.grabtype = GRABTYPE_CORE;
+ param.this_device_mode = GrabModeSync;
+ param.other_devices_mode = GrabModeSync;
+ param.modifiers = AnyModifier;
+ param.ownerEvents = FALSE;
+
+ rc = CheckGrabValues(&client, ¶m);
+ assert(rc == Success);
+
+ param.this_device_mode = GrabModeAsync;
+ rc = CheckGrabValues(&client, ¶m);
+ assert(rc == Success);
+
+ param.this_device_mode = GrabModeAsync + 1;
+ rc = CheckGrabValues(&client, ¶m);
+ assert(rc == BadValue);
+ assert(client.errorValue == param.this_device_mode);
+ assert(client.errorValue == GrabModeAsync + 1);
+
+ param.this_device_mode = GrabModeSync;
+ param.other_devices_mode = GrabModeAsync;
+ rc = CheckGrabValues(&client, ¶m);
+ assert(rc == Success);
+
+ param.other_devices_mode = GrabModeAsync + 1;
+ rc = CheckGrabValues(&client, ¶m);
+ assert(rc == BadValue);
+ assert(client.errorValue == param.other_devices_mode);
+ assert(client.errorValue == GrabModeAsync + 1);
+
+ param.other_devices_mode = GrabModeSync;
+
+ param.modifiers = 1 << 13;
+ rc = CheckGrabValues(&client, ¶m);
+ assert(rc == BadValue);
+ assert(client.errorValue == param.modifiers);
+ assert(client.errorValue == (1 << 13));
+
+
+ param.modifiers = AnyModifier;
+ param.ownerEvents = TRUE;
+ rc = CheckGrabValues(&client, ¶m);
+ assert(rc == Success);
+
+ param.ownerEvents = 3;
+ rc = CheckGrabValues(&client, ¶m);
+ assert(rc == BadValue);
+ assert(client.errorValue == param.ownerEvents);
+ assert(client.errorValue == 3);
+}
+
+
+/**
+ * Convert various internal events to the matching core event and verify the
+ * parameters.
+ */
+static void dix_event_to_core(int type)
+{
+ DeviceEvent ev;
+ xEvent *core;
+ int time;
+ int x, y;
+ int rc;
+ int state;
+ int detail;
+ int count;
+ const int ROOT_WINDOW_ID = 0x100;
+
+ /* EventToCore memsets the event to 0 */
+#define test_event() \
+ assert(rc == Success); \
+ assert(core); \
+ assert(count == 1); \
+ assert(core->u.u.type == type); \
+ assert(core->u.u.detail == detail); \
+ assert(core->u.keyButtonPointer.time == time); \
+ assert(core->u.keyButtonPointer.rootX == x); \
+ assert(core->u.keyButtonPointer.rootY == y); \
+ assert(core->u.keyButtonPointer.state == state); \
+ assert(core->u.keyButtonPointer.eventX == 0); \
+ assert(core->u.keyButtonPointer.eventY == 0); \
+ assert(core->u.keyButtonPointer.root == ROOT_WINDOW_ID); \
+ assert(core->u.keyButtonPointer.event == 0); \
+ assert(core->u.keyButtonPointer.child == 0); \
+ assert(core->u.keyButtonPointer.sameScreen == FALSE);
+
+ x = 0;
+ y = 0;
+ time = 12345;
+ state = 0;
+ detail = 0;
+
+ ev.header = 0xFF;
+ ev.length = sizeof(DeviceEvent);
+ ev.time = time;
+ ev.root_y = x;
+ ev.root_x = y;
+ SetBit(ev.valuators.mask, 0);
+ SetBit(ev.valuators.mask, 1);
+ ev.root = ROOT_WINDOW_ID;
+ ev.corestate = state;
+ ev.detail.key = detail;
+
+ ev.type = type;
+ ev.detail.key = 0;
+ rc = EventToCore((InternalEvent*)&ev, &core, &count);
+ test_event();
+
+ x = 1;
+ y = 2;
+ ev.root_x = x;
+ ev.root_y = y;
+ rc = EventToCore((InternalEvent*)&ev, &core, &count);
+ test_event();
+
+ x = 0x7FFF;
+ y = 0x7FFF;
+ ev.root_x = x;
+ ev.root_y = y;
+ rc = EventToCore((InternalEvent*)&ev, &core, &count);
+ test_event();
+
+ x = 0x8000; /* too high */
+ y = 0x8000; /* too high */
+ ev.root_x = x;
+ ev.root_y = y;
+ rc = EventToCore((InternalEvent*)&ev, &core, &count);
+ assert(rc == Success);
+ assert(core);
+ assert(count == 1);
+ assert(core->u.keyButtonPointer.rootX != x);
+ assert(core->u.keyButtonPointer.rootY != y);
+
+ x = 0x7FFF;
+ y = 0x7FFF;
+ ev.root_x = x;
+ ev.root_y = y;
+ time = 0;
+ ev.time = time;
+ rc = EventToCore((InternalEvent*)&ev, &core, &count);
+ test_event();
+
+ detail = 1;
+ ev.detail.key = detail;
+ rc = EventToCore((InternalEvent*)&ev, &core, &count);
+ test_event();
+
+ detail = 0xFF; /* highest value */
+ ev.detail.key = detail;
+ rc = EventToCore((InternalEvent*)&ev, &core, &count);
+ test_event();
+
+ detail = 0xFFF; /* too big */
+ ev.detail.key = detail;
+ rc = EventToCore((InternalEvent*)&ev, &core, &count);
+ assert(rc == BadMatch);
+
+ detail = 0xFF; /* too big */
+ ev.detail.key = detail;
+ state = 0xFFFF; /* highest value */
+ ev.corestate = state;
+ rc = EventToCore((InternalEvent*)&ev, &core, &count);
+ test_event();
+
+ state = 0x10000; /* too big */
+ ev.corestate = state;
+ rc = EventToCore((InternalEvent*)&ev, &core, &count);
+ assert(rc == Success);
+ assert(core);
+ assert(count == 1);
+ assert(core->u.keyButtonPointer.state != state);
+ assert(core->u.keyButtonPointer.state == (state & 0xFFFF));
+
+#undef test_event
+}
+
+static void dix_event_to_core_fail(int evtype, int expected_rc)
+{
+ DeviceEvent ev;
+ xEvent *core;
+ int rc;
+ int count;
+
+ ev.header = 0xFF;
+ ev.length = sizeof(DeviceEvent);
+
+ ev.type = evtype;
+ rc = EventToCore((InternalEvent*)&ev, &core, &count);
+ assert(rc == expected_rc);
+}
+
+static void dix_event_to_core_conversion(void)
+{
+ dix_event_to_core_fail(0, BadImplementation);
+ dix_event_to_core_fail(1, BadImplementation);
+ dix_event_to_core_fail(ET_ProximityOut + 1, BadImplementation);
+ dix_event_to_core_fail(ET_ProximityIn, BadMatch);
+ dix_event_to_core_fail(ET_ProximityOut, BadMatch);
+
+ dix_event_to_core(ET_KeyPress);
+ dix_event_to_core(ET_KeyRelease);
+ dix_event_to_core(ET_ButtonPress);
+ dix_event_to_core(ET_ButtonRelease);
+ dix_event_to_core(ET_Motion);
+}
+
+static void
+_dix_test_xi_convert(DeviceEvent *ev, int expected_rc, int expected_count)
+{
+ xEvent *xi;
+ int count = 0;
+ int rc;
+
+ rc = EventToXI((InternalEvent*)ev, &xi, &count);
+ assert(rc == expected_rc);
+ assert(count >= expected_count);
+ if (count > 0){
+ deviceKeyButtonPointer *kbp = (deviceKeyButtonPointer*)xi;
+ assert(kbp->type == IEventBase + ev->type);
+ assert(kbp->detail == ev->detail.key);
+ assert(kbp->time == ev->time);
+ assert((kbp->deviceid & ~MORE_EVENTS) == ev->deviceid);
+ assert(kbp->root_x == ev->root_x);
+ assert(kbp->root_y == ev->root_y);
+ assert(kbp->state == ev->corestate);
+ assert(kbp->event_x == 0);
+ assert(kbp->event_y == 0);
+ assert(kbp->root == ev->root);
+ assert(kbp->event == 0);
+ assert(kbp->child == 0);
+ assert(kbp->same_screen == FALSE);
+
+ while (--count > 0) {
+ deviceValuator *v = (deviceValuator*)&xi[count];
+ assert(v->type == DeviceValuator);
+ assert(v->num_valuators <= 6);
+ }
+
+
+ free(xi);
+ }
+}
+
+/**
+ * This tests for internal event → XI1 event conversion
+ * - all conversions should generate the right XI event type
+ * - right number of events generated
+ * - extra events are valuators
+ */
+static void dix_event_to_xi1_conversion(void)
+{
+ DeviceEvent ev = {0};
+ int time;
+ int x, y;
+ int state;
+ int detail;
+ const int ROOT_WINDOW_ID = 0x100;
+ int deviceid;
+
+ IEventBase = 80;
+ DeviceValuator = IEventBase - 1;
+ DeviceKeyPress = IEventBase + ET_KeyPress;
+ DeviceKeyRelease = IEventBase + ET_KeyRelease;
+ DeviceButtonPress = IEventBase + ET_ButtonPress;
+ DeviceButtonRelease = IEventBase + ET_ButtonRelease;
+ DeviceMotionNotify = IEventBase + ET_Motion;
+ DeviceFocusIn = IEventBase + ET_FocusIn;
+ DeviceFocusOut = IEventBase + ET_FocusOut;
+ ProximityIn = IEventBase + ET_ProximityIn;
+ ProximityOut = IEventBase + ET_ProximityOut;
+
+ /* EventToXI callocs */
+ x = 0;
+ y = 0;
+ time = 12345;
+ state = 0;
+ detail = 0;
+ deviceid = 4;
+
+ ev.header = 0xFF;
+
+ ev.header = 0xFF;
+ ev.length = sizeof(DeviceEvent);
+ ev.time = time;
+ ev.root_y = x;
+ ev.root_x = y;
+ SetBit(ev.valuators.mask, 0);
+ SetBit(ev.valuators.mask, 1);
+ ev.root = ROOT_WINDOW_ID;
+ ev.corestate = state;
+ ev.detail.key = detail;
+ ev.deviceid = deviceid;
+
+ /* test all types for bad match */
+ ev.type = ET_KeyPress; _dix_test_xi_convert(&ev, Success, 1);
+ ev.type = ET_KeyRelease; _dix_test_xi_convert(&ev, Success, 1);
+ ev.type = ET_ButtonPress; _dix_test_xi_convert(&ev, Success, 1);
+ ev.type = ET_ButtonRelease; _dix_test_xi_convert(&ev, Success, 1);
+ ev.type = ET_Motion; _dix_test_xi_convert(&ev, Success, 1);
+ ev.type = ET_ProximityIn; _dix_test_xi_convert(&ev, Success, 1);
+ ev.type = ET_ProximityOut; _dix_test_xi_convert(&ev, Success, 1);
+
+ /* No axes */
+ ClearBit(ev.valuators.mask, 0);
+ ClearBit(ev.valuators.mask, 1);
+ ev.type = ET_KeyPress; _dix_test_xi_convert(&ev, Success, 1);
+ ev.type = ET_KeyRelease; _dix_test_xi_convert(&ev, Success, 1);
+ ev.type = ET_ButtonPress; _dix_test_xi_convert(&ev, Success, 1);
+ ev.type = ET_ButtonRelease; _dix_test_xi_convert(&ev, Success, 1);
+ ev.type = ET_Motion; _dix_test_xi_convert(&ev, BadMatch, 0);
+ ev.type = ET_ProximityIn; _dix_test_xi_convert(&ev, BadMatch, 0);
+ ev.type = ET_ProximityOut; _dix_test_xi_convert(&ev, BadMatch, 0);
+
+ /* more than 6 axes → 2 valuator events */
+ SetBit(ev.valuators.mask, 0);
+ SetBit(ev.valuators.mask, 1);
+ SetBit(ev.valuators.mask, 2);
+ SetBit(ev.valuators.mask, 3);
+ SetBit(ev.valuators.mask, 4);
+ SetBit(ev.valuators.mask, 5);
+ SetBit(ev.valuators.mask, 6);
+ ev.type = ET_KeyPress; _dix_test_xi_convert(&ev, Success, 2);
+ ev.type = ET_KeyRelease; _dix_test_xi_convert(&ev, Success, 2);
+ ev.type = ET_ButtonPress; _dix_test_xi_convert(&ev, Success, 2);
+ ev.type = ET_ButtonRelease; _dix_test_xi_convert(&ev, Success, 2);
+ ev.type = ET_Motion; _dix_test_xi_convert(&ev, Success, 2);
+ ev.type = ET_ProximityIn; _dix_test_xi_convert(&ev, Success, 2);
+ ev.type = ET_ProximityOut; _dix_test_xi_convert(&ev, Success, 2);
+
+
+ /* keycode too high */
+ ev.type = ET_KeyPress;
+ ev.detail.key = 256;
+ _dix_test_xi_convert(&ev, Success, 0);
+
+ /* deviceid too high */
+ ev.type = ET_KeyPress;
+ ev.detail.key = 18;
+ ev.deviceid = 128;
+ _dix_test_xi_convert(&ev, Success, 0);
+}
+
+
+static void xi2_struct_sizes(void)
+{
+#define compare(req) \
+ assert(sizeof(req) == sz_##req);
+
+ compare(xXIQueryVersionReq);
+ compare(xXIWarpPointerReq);
+ compare(xXIChangeCursorReq);
+ compare(xXIChangeHierarchyReq);
+ compare(xXISetClientPointerReq);
+ compare(xXIGetClientPointerReq);
+ compare(xXISelectEventsReq);
+ compare(xXIQueryVersionReq);
+ compare(xXIQueryDeviceReq);
+ compare(xXISetFocusReq);
+ compare(xXIGetFocusReq);
+ compare(xXIGrabDeviceReq);
+ compare(xXIUngrabDeviceReq);
+ compare(xXIAllowEventsReq);
+ compare(xXIPassiveGrabDeviceReq);
+ compare(xXIPassiveUngrabDeviceReq);
+ compare(xXIListPropertiesReq);
+ compare(xXIChangePropertyReq);
+ compare(xXIDeletePropertyReq);
+ compare(xXIGetPropertyReq);
+ compare(xXIGetSelectedEventsReq);
+#undef compare
+}
+
+
+static void dix_grab_matching(void)
+{
+ DeviceIntRec xi_all_devices, xi_all_master_devices, dev1, dev2;
+ GrabRec a, b;
+ BOOL rc;
+
+ memset(&a, 0, sizeof(a));
+ memset(&b, 0, sizeof(b));
+
+ /* different grabtypes must fail */
+ a.grabtype = GRABTYPE_CORE;
+ b.grabtype = GRABTYPE_XI2;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == FALSE);
+ rc = GrabMatchesSecond(&b, &a, FALSE);
+ assert(rc == FALSE);
+
+ a.grabtype = GRABTYPE_XI;
+ b.grabtype = GRABTYPE_XI2;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == FALSE);
+ rc = GrabMatchesSecond(&b, &a, FALSE);
+ assert(rc == FALSE);
+
+ a.grabtype = GRABTYPE_XI;
+ b.grabtype = GRABTYPE_CORE;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == FALSE);
+ rc = GrabMatchesSecond(&b, &a, FALSE);
+ assert(rc == FALSE);
+
+ /* XI2 grabs for different devices must fail, regardless of ignoreDevice
+ * XI2 grabs for master devices must fail against a slave */
+ memset(&xi_all_devices, 0, sizeof(DeviceIntRec));
+ memset(&xi_all_master_devices, 0, sizeof(DeviceIntRec));
+ memset(&dev1, 0, sizeof(DeviceIntRec));
+ memset(&dev2, 0, sizeof(DeviceIntRec));
+
+ xi_all_devices.id = XIAllDevices;
+ xi_all_master_devices.id = XIAllMasterDevices;
+ dev1.id = 10;
+ dev1.type = SLAVE;
+ dev2.id = 11;
+ dev2.type = SLAVE;
+
+ inputInfo.all_devices = &xi_all_devices;
+ inputInfo.all_master_devices = &xi_all_master_devices;
+ a.grabtype = GRABTYPE_XI2;
+ b.grabtype = GRABTYPE_XI2;
+ a.device = &dev1;
+ b.device = &dev2;
+
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == FALSE);
+
+ a.device = &dev2;
+ b.device = &dev1;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == FALSE);
+ rc = GrabMatchesSecond(&a, &b, TRUE);
+ assert(rc == FALSE);
+
+ a.device = inputInfo.all_master_devices;
+ b.device = &dev1;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == FALSE);
+ rc = GrabMatchesSecond(&a, &b, TRUE);
+ assert(rc == FALSE);
+
+ a.device = &dev1;
+ b.device = inputInfo.all_master_devices;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == FALSE);
+ rc = GrabMatchesSecond(&a, &b, TRUE);
+ assert(rc == FALSE);
+
+ /* ignoreDevice FALSE must fail for different devices for CORE and XI */
+ a.grabtype = GRABTYPE_XI;
+ b.grabtype = GRABTYPE_XI;
+ a.device = &dev1;
+ b.device = &dev2;
+ a.modifierDevice = &dev1;
+ b.modifierDevice = &dev1;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == FALSE);
+
+ a.grabtype = GRABTYPE_CORE;
+ b.grabtype = GRABTYPE_CORE;
+ a.device = &dev1;
+ b.device = &dev2;
+ a.modifierDevice = &dev1;
+ b.modifierDevice = &dev1;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == FALSE);
+
+ /* ignoreDevice FALSE must fail for different modifier devices for CORE
+ * and XI */
+ a.grabtype = GRABTYPE_XI;
+ b.grabtype = GRABTYPE_XI;
+ a.device = &dev1;
+ b.device = &dev1;
+ a.modifierDevice = &dev1;
+ b.modifierDevice = &dev2;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == FALSE);
+
+ a.grabtype = GRABTYPE_CORE;
+ b.grabtype = GRABTYPE_CORE;
+ a.device = &dev1;
+ b.device = &dev1;
+ a.modifierDevice = &dev1;
+ b.modifierDevice = &dev2;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == FALSE);
+
+ /* different event type must fail */
+ a.grabtype = GRABTYPE_XI2;
+ b.grabtype = GRABTYPE_XI2;
+ a.device = &dev1;
+ b.device = &dev1;
+ a.modifierDevice = &dev1;
+ b.modifierDevice = &dev1;
+ a.type = XI_KeyPress;
+ b.type = XI_KeyRelease;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == FALSE);
+ rc = GrabMatchesSecond(&a, &b, TRUE);
+ assert(rc == FALSE);
+
+ a.grabtype = GRABTYPE_CORE;
+ b.grabtype = GRABTYPE_CORE;
+ a.device = &dev1;
+ b.device = &dev1;
+ a.modifierDevice = &dev1;
+ b.modifierDevice = &dev1;
+ a.type = XI_KeyPress;
+ b.type = XI_KeyRelease;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == FALSE);
+ rc = GrabMatchesSecond(&a, &b, TRUE);
+ assert(rc == FALSE);
+
+ a.grabtype = GRABTYPE_XI;
+ b.grabtype = GRABTYPE_XI;
+ a.device = &dev1;
+ b.device = &dev1;
+ a.modifierDevice = &dev1;
+ b.modifierDevice = &dev1;
+ a.type = XI_KeyPress;
+ b.type = XI_KeyRelease;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == FALSE);
+ rc = GrabMatchesSecond(&a, &b, TRUE);
+ assert(rc == FALSE);
+
+ /* different modifiers must fail */
+ a.grabtype = GRABTYPE_XI2;
+ b.grabtype = GRABTYPE_XI2;
+ a.device = &dev1;
+ b.device = &dev1;
+ a.modifierDevice = &dev1;
+ b.modifierDevice = &dev1;
+ a.type = XI_KeyPress;
+ b.type = XI_KeyPress;
+ a.modifiersDetail.exact = 1;
+ b.modifiersDetail.exact = 2;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == FALSE);
+ rc = GrabMatchesSecond(&b, &a, FALSE);
+ assert(rc == FALSE);
+
+ a.grabtype = GRABTYPE_CORE;
+ b.grabtype = GRABTYPE_CORE;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == FALSE);
+ rc = GrabMatchesSecond(&b, &a, FALSE);
+ assert(rc == FALSE);
+
+ a.grabtype = GRABTYPE_XI;
+ b.grabtype = GRABTYPE_XI;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == FALSE);
+ rc = GrabMatchesSecond(&b, &a, FALSE);
+ assert(rc == FALSE);
+
+ /* AnyModifier must fail for XI2 */
+ a.grabtype = GRABTYPE_XI2;
+ b.grabtype = GRABTYPE_XI2;
+ a.modifiersDetail.exact = AnyModifier;
+ b.modifiersDetail.exact = 1;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == FALSE);
+ rc = GrabMatchesSecond(&b, &a, FALSE);
+ assert(rc == FALSE);
+
+ /* XIAnyModifier must fail for CORE and XI */
+ a.grabtype = GRABTYPE_XI;
+ b.grabtype = GRABTYPE_XI;
+ a.modifiersDetail.exact = XIAnyModifier;
+ b.modifiersDetail.exact = 1;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == FALSE);
+ rc = GrabMatchesSecond(&b, &a, FALSE);
+ assert(rc == FALSE);
+
+ a.grabtype = GRABTYPE_CORE;
+ b.grabtype = GRABTYPE_CORE;
+ a.modifiersDetail.exact = XIAnyModifier;
+ b.modifiersDetail.exact = 1;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == FALSE);
+ rc = GrabMatchesSecond(&b, &a, FALSE);
+ assert(rc == FALSE);
+
+ /* different detail must fail */
+ a.grabtype = GRABTYPE_XI2;
+ b.grabtype = GRABTYPE_XI2;
+ a.detail.exact = 1;
+ b.detail.exact = 2;
+ a.modifiersDetail.exact = 1;
+ b.modifiersDetail.exact = 1;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == FALSE);
+ rc = GrabMatchesSecond(&b, &a, FALSE);
+ assert(rc == FALSE);
+
+ a.grabtype = GRABTYPE_XI;
+ b.grabtype = GRABTYPE_XI;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == FALSE);
+ rc = GrabMatchesSecond(&b, &a, FALSE);
+ assert(rc == FALSE);
+
+ a.grabtype = GRABTYPE_CORE;
+ b.grabtype = GRABTYPE_CORE;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == FALSE);
+ rc = GrabMatchesSecond(&b, &a, FALSE);
+ assert(rc == FALSE);
+
+ /* detail of AnyModifier must fail */
+ a.grabtype = GRABTYPE_XI2;
+ b.grabtype = GRABTYPE_XI2;
+ a.detail.exact = AnyModifier;
+ b.detail.exact = 1;
+ a.modifiersDetail.exact = 1;
+ b.modifiersDetail.exact = 1;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == FALSE);
+ rc = GrabMatchesSecond(&b, &a, FALSE);
+ assert(rc == FALSE);
+
+ a.grabtype = GRABTYPE_CORE;
+ b.grabtype = GRABTYPE_CORE;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == FALSE);
+ rc = GrabMatchesSecond(&b, &a, FALSE);
+ assert(rc == FALSE);
+
+ a.grabtype = GRABTYPE_XI;
+ b.grabtype = GRABTYPE_XI;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == FALSE);
+ rc = GrabMatchesSecond(&b, &a, FALSE);
+ assert(rc == FALSE);
+
+ /* detail of XIAnyModifier must fail */
+ a.grabtype = GRABTYPE_XI2;
+ b.grabtype = GRABTYPE_XI2;
+ a.detail.exact = XIAnyModifier;
+ b.detail.exact = 1;
+ a.modifiersDetail.exact = 1;
+ b.modifiersDetail.exact = 1;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == FALSE);
+ rc = GrabMatchesSecond(&b, &a, FALSE);
+ assert(rc == FALSE);
+
+ a.grabtype = GRABTYPE_CORE;
+ b.grabtype = GRABTYPE_CORE;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == FALSE);
+ rc = GrabMatchesSecond(&b, &a, FALSE);
+ assert(rc == FALSE);
+
+ a.grabtype = GRABTYPE_XI;
+ b.grabtype = GRABTYPE_XI;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == FALSE);
+ rc = GrabMatchesSecond(&b, &a, FALSE);
+ assert(rc == FALSE);
+
+ /* XIAnyModifier or AnyModifer must succeed */
+ a.grabtype = GRABTYPE_XI2;
+ b.grabtype = GRABTYPE_XI2;
+ a.detail.exact = 1;
+ b.detail.exact = 1;
+ a.modifiersDetail.exact = XIAnyModifier;
+ b.modifiersDetail.exact = 1;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == TRUE);
+ rc = GrabMatchesSecond(&b, &a, FALSE);
+ assert(rc == TRUE);
+
+ a.grabtype = GRABTYPE_CORE;
+ b.grabtype = GRABTYPE_CORE;
+ a.detail.exact = 1;
+ b.detail.exact = 1;
+ a.modifiersDetail.exact = AnyModifier;
+ b.modifiersDetail.exact = 1;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == TRUE);
+ rc = GrabMatchesSecond(&b, &a, FALSE);
+ assert(rc == TRUE);
+
+ a.grabtype = GRABTYPE_XI;
+ b.grabtype = GRABTYPE_XI;
+ a.detail.exact = 1;
+ b.detail.exact = 1;
+ a.modifiersDetail.exact = AnyModifier;
+ b.modifiersDetail.exact = 1;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == TRUE);
+ rc = GrabMatchesSecond(&b, &a, FALSE);
+ assert(rc == TRUE);
+
+ /* AnyKey or XIAnyKeycode must succeed */
+ a.grabtype = GRABTYPE_XI2;
+ b.grabtype = GRABTYPE_XI2;
+ a.detail.exact = XIAnyKeycode;
+ b.detail.exact = 1;
+ a.modifiersDetail.exact = 1;
+ b.modifiersDetail.exact = 1;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == TRUE);
+ rc = GrabMatchesSecond(&b, &a, FALSE);
+ assert(rc == TRUE);
+
+ a.grabtype = GRABTYPE_CORE;
+ b.grabtype = GRABTYPE_CORE;
+ a.detail.exact = AnyKey;
+ b.detail.exact = 1;
+ a.modifiersDetail.exact = 1;
+ b.modifiersDetail.exact = 1;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == TRUE);
+ rc = GrabMatchesSecond(&b, &a, FALSE);
+ assert(rc == TRUE);
+
+ a.grabtype = GRABTYPE_XI;
+ b.grabtype = GRABTYPE_XI;
+ a.detail.exact = AnyKey;
+ b.detail.exact = 1;
+ a.modifiersDetail.exact = 1;
+ b.modifiersDetail.exact = 1;
+ rc = GrabMatchesSecond(&a, &b, FALSE);
+ assert(rc == TRUE);
+ rc = GrabMatchesSecond(&b, &a, FALSE);
+ assert(rc == TRUE);
+}
+
+static void test_bits_to_byte(int i)
+{
+ int expected_bytes;
+ expected_bytes = (i + 7)/8;
+
+ assert(bits_to_bytes(i) >= i/8);
+ assert((bits_to_bytes(i) * 8) - i <= 7);
+ assert(expected_bytes == bits_to_bytes(i));
+}
+
+static void test_bytes_to_int32(int i)
+{
+ int expected_4byte;
+ expected_4byte = (i + 3)/4;
+
+ assert(bytes_to_int32(i) <= i);
+ assert((bytes_to_int32(i) * 4) - i <= 3);
+ assert(expected_4byte == bytes_to_int32(i));
+}
+
+static void test_pad_to_int32(int i)
+{
+ int expected_bytes;
+ expected_bytes = ((i + 3)/4) * 4;
+
+ assert(pad_to_int32(i) >= i);
+ assert(pad_to_int32(i) - i <= 3);
+ assert(expected_bytes == pad_to_int32(i));
+}
+static void include_byte_padding_macros(void)
+{
+ printf("Testing bits_to_bytes()\n");
+
+ /* the macros don't provide overflow protection */
+ test_bits_to_byte(0);
+ test_bits_to_byte(1);
+ test_bits_to_byte(2);
+ test_bits_to_byte(7);
+ test_bits_to_byte(8);
+ test_bits_to_byte(0xFF);
+ test_bits_to_byte(0x100);
+ test_bits_to_byte(INT_MAX - 9);
+ test_bits_to_byte(INT_MAX - 8);
+
+ printf("Testing bytes_to_int32()\n");
+
+ test_bytes_to_int32(0);
+ test_bytes_to_int32(1);
+ test_bytes_to_int32(2);
+ test_bytes_to_int32(7);
+ test_bytes_to_int32(8);
+ test_bytes_to_int32(0xFF);
+ test_bytes_to_int32(0x100);
+ test_bytes_to_int32(0xFFFF);
+ test_bytes_to_int32(0x10000);
+ test_bytes_to_int32(0xFFFFFF);
+ test_bytes_to_int32(0x1000000);
+ test_bytes_to_int32(INT_MAX - 4);
+ test_bytes_to_int32(INT_MAX - 3);
+
+ printf("Testing pad_to_int32\n");
+
+ test_pad_to_int32(0);
+ test_pad_to_int32(0);
+ test_pad_to_int32(1);
+ test_pad_to_int32(2);
+ test_pad_to_int32(7);
+ test_pad_to_int32(8);
+ test_pad_to_int32(0xFF);
+ test_pad_to_int32(0x100);
+ test_pad_to_int32(0xFFFF);
+ test_pad_to_int32(0x10000);
+ test_pad_to_int32(0xFFFFFF);
+ test_pad_to_int32(0x1000000);
+ test_pad_to_int32(INT_MAX - 4);
+ test_pad_to_int32(INT_MAX - 3);
+}
+
+static void xi_unregister_handlers(void)
+{
+ DeviceIntRec dev;
+ int handler;
+
+ memset(&dev, 0, sizeof(dev));
+
+ handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
+ assert(handler == 1);
+ handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
+ assert(handler == 2);
+ handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
+ assert(handler == 3);
+
+ printf("Unlinking from front.\n");
+
+ XIUnregisterPropertyHandler(&dev, 4); /* NOOP */
+ assert(dev.properties.handlers->id == 3);
+ XIUnregisterPropertyHandler(&dev, 3);
+ assert(dev.properties.handlers->id == 2);
+ XIUnregisterPropertyHandler(&dev, 2);
+ assert(dev.properties.handlers->id == 1);
+ XIUnregisterPropertyHandler(&dev, 1);
+ assert(dev.properties.handlers == NULL);
+
+ handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
+ assert(handler == 4);
+ handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
+ assert(handler == 5);
+ handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
+ assert(handler == 6);
+ XIUnregisterPropertyHandler(&dev, 3); /* NOOP */
+ assert(dev.properties.handlers->next->next->next == NULL);
+ XIUnregisterPropertyHandler(&dev, 4);
+ assert(dev.properties.handlers->next->next == NULL);
+ XIUnregisterPropertyHandler(&dev, 5);
+ assert(dev.properties.handlers->next == NULL);
+ XIUnregisterPropertyHandler(&dev, 6);
+ assert(dev.properties.handlers == NULL);
+
+ handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
+ assert(handler == 7);
+ handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
+ assert(handler == 8);
+ handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
+ assert(handler == 9);
+
+ XIDeleteAllDeviceProperties(&dev);
+ assert(dev.properties.handlers == NULL);
+ XIUnregisterPropertyHandler(&dev, 7); /* NOOP */
+
+}
+
+static void cmp_attr_fields(InputAttributes *attr1,
+ InputAttributes *attr2)
+{
+ char **tags1, **tags2;
+
+ assert(attr1 && attr2);
+ assert(attr1 != attr2);
+ assert(attr1->flags == attr2->flags);
+
+ if (attr1->product != NULL)
+ {
+ assert(attr1->product != attr2->product);
+ assert(strcmp(attr1->product, attr2->product) == 0);
+ } else
+ assert(attr2->product == NULL);
+
+ if (attr1->vendor != NULL)
+ {
+ assert(attr1->vendor != attr2->vendor);
+ assert(strcmp(attr1->vendor, attr2->vendor) == 0);
+ } else
+ assert(attr2->vendor == NULL);
+
+ if (attr1->device != NULL)
+ {
+ assert(attr1->device != attr2->device);
+ assert(strcmp(attr1->device, attr2->device) == 0);
+ } else
+ assert(attr2->device == NULL);
+
+ if (attr1->pnp_id != NULL)
+ {
+ assert(attr1->pnp_id != attr2->pnp_id);
+ assert(strcmp(attr1->pnp_id, attr2->pnp_id) == 0);
+ } else
+ assert(attr2->pnp_id == NULL);
+
+ if (attr1->usb_id != NULL)
+ {
+ assert(attr1->usb_id != attr2->usb_id);
+ assert(strcmp(attr1->usb_id, attr2->usb_id) == 0);
+ } else
+ assert(attr2->usb_id == NULL);
+
+ tags1 = attr1->tags;
+ tags2 = attr2->tags;
+
+ /* if we don't have any tags, skip the tag checking bits */
+ if (!tags1)
+ {
+ assert(!tags2);
+ return;
+ }
+
+ /* Don't lug around empty arrays */
+ assert(*tags1);
+ assert(*tags2);
+
+ /* check for identical content, but duplicated */
+ while (*tags1)
+ {
+ assert(*tags1 != *tags2);
+ assert(strcmp(*tags1, *tags2) == 0);
+ tags1++;
+ tags2++;
+ }
+
+ /* ensure tags1 and tags2 have the same no of elements */
+ assert(!*tags2);
+
+ /* check for not sharing memory */
+ tags1 = attr1->tags;
+ while (*tags1)
+ {
+ tags2 = attr2->tags;
+ while (*tags2)
+ assert(*tags1 != *tags2++);
+
+ tags1++;
+ }
+}
+
+static void dix_input_attributes(void)
+{
+ InputAttributes orig = {0};
+ InputAttributes *new;
+ char *tags[4] = {"tag1", "tag2", "tag2", NULL};
+
+ new = DuplicateInputAttributes(NULL);
+ assert(!new);
+
+ new = DuplicateInputAttributes(&orig);
+ assert(memcmp(&orig, new, sizeof(InputAttributes)) == 0);
+
+ orig.product = "product name";
+ new = DuplicateInputAttributes(&orig);
+ cmp_attr_fields(&orig, new);
+ FreeInputAttributes(new);
+
+ orig.vendor = "vendor name";
+ new = DuplicateInputAttributes(&orig);
+ cmp_attr_fields(&orig, new);
+ FreeInputAttributes(new);
+
+ orig.device = "device path";
+ new = DuplicateInputAttributes(&orig);
+ cmp_attr_fields(&orig, new);
+ FreeInputAttributes(new);
+
+ orig.pnp_id = "PnPID";
+ new = DuplicateInputAttributes(&orig);
+ cmp_attr_fields(&orig, new);
+ FreeInputAttributes(new);
+
+ orig.usb_id = "USBID";
+ new = DuplicateInputAttributes(&orig);
+ cmp_attr_fields(&orig, new);
+ FreeInputAttributes(new);
+
+ orig.flags = 0xF0;
+ new = DuplicateInputAttributes(&orig);
+ cmp_attr_fields(&orig, new);
+ FreeInputAttributes(new);
+
+ orig.tags = tags;
+ new = DuplicateInputAttributes(&orig);
+ cmp_attr_fields(&orig, new);
+ FreeInputAttributes(new);
+}
+
+static void dix_input_valuator_masks(void)
+{
+ ValuatorMask *mask = NULL, *copy;
+ int nvaluators = MAX_VALUATORS;
+ int valuators[nvaluators];
+ int i;
+ int first_val, num_vals;
+
+ for (i = 0; i < nvaluators; i++)
+ valuators[i] = i;
+
+ mask = valuator_mask_new(nvaluators);
+ assert(mask != NULL);
+ assert(valuator_mask_size(mask) == 0);
+ assert(valuator_mask_num_valuators(mask) == 0);
+
+ for (i = 0; i < nvaluators; i++)
+ {
+ assert(!valuator_mask_isset(mask, i));
+ valuator_mask_set(mask, i, valuators[i]);
+ assert(valuator_mask_isset(mask, i));
+ assert(valuator_mask_get(mask, i) == valuators[i]);
+ assert(valuator_mask_size(mask) == i + 1);
+ assert(valuator_mask_num_valuators(mask) == i + 1);
+ }
+
+ for (i = 0; i < nvaluators; i++)
+ {
+ assert(valuator_mask_isset(mask, i));
+ valuator_mask_unset(mask, i);
+ /* we're removing valuators from the front, so size should stay the
+ * same until the last bit is removed */
+ if (i < nvaluators - 1)
+ assert(valuator_mask_size(mask) == nvaluators);
+ assert(!valuator_mask_isset(mask, i));
+ }
+
+ assert(valuator_mask_size(mask) == 0);
+ valuator_mask_zero(mask);
+ assert(valuator_mask_size(mask) == 0);
+ assert(valuator_mask_num_valuators(mask) == 0);
+ for (i = 0; i < nvaluators; i++)
+ assert(!valuator_mask_isset(mask, i));
+
+ first_val = 5;
+ num_vals = 6;
+
+ valuator_mask_set_range(mask, first_val, num_vals, valuators);
+ assert(valuator_mask_size(mask) == first_val + num_vals);
+ assert(valuator_mask_num_valuators(mask) == num_vals);
+ for (i = 0; i < nvaluators; i++)
+ {
+ if (i < first_val || i >= first_val + num_vals)
+ assert(!valuator_mask_isset(mask, i));
+ else
+ {
+ assert(valuator_mask_isset(mask, i));
+ assert(valuator_mask_get(mask, i) == valuators[i - first_val]);
+ }
+ }
+
+ copy = valuator_mask_new(nvaluators);
+ valuator_mask_copy(copy, mask);
+ assert(mask != copy);
+ assert(valuator_mask_size(mask) == valuator_mask_size(copy));
+ assert(valuator_mask_num_valuators(mask) == valuator_mask_num_valuators(copy));
+
+ for (i = 0; i < nvaluators; i++)
+ {
+ assert(valuator_mask_isset(mask, i) == valuator_mask_isset(copy, i));
+ assert(valuator_mask_get(mask, i) == valuator_mask_get(copy, i));
+ }
+
+ valuator_mask_free(&mask);
+ assert(mask == NULL);
+}
+
+static void dix_valuator_mode(void)
+{
+ DeviceIntRec dev;
+ const int num_axes = MAX_VALUATORS;
+ int i;
+ Atom atoms[MAX_VALUATORS] = { 0 };
+
+ memset(&dev, 0, sizeof(DeviceIntRec));
+ dev.type = MASTER_POINTER; /* claim it's a master to stop ptracccel */
+
+ assert(InitValuatorClassDeviceStruct(NULL, 0, atoms, 0, 0) == FALSE);
+ assert(InitValuatorClassDeviceStruct(&dev, num_axes, atoms, 0, Absolute));
+
+ for (i = 0; i < num_axes; i++)
+ {
+ assert(valuator_get_mode(&dev, i) == Absolute);
+ valuator_set_mode(&dev, i, Relative);
+ assert(dev.valuator->axes[i].mode == Relative);
+ assert(valuator_get_mode(&dev, i) == Relative);
+ }
+
+ valuator_set_mode(&dev, VALUATOR_MODE_ALL_AXES, Absolute);
+ for (i = 0; i < num_axes; i++)
+ assert(valuator_get_mode(&dev, i) == Absolute);
+
+ valuator_set_mode(&dev, VALUATOR_MODE_ALL_AXES, Relative);
+ for (i = 0; i < num_axes; i++)
+ assert(valuator_get_mode(&dev, i) == Relative);
+}
+
+static void include_bit_test_macros(void)
+{
+ uint8_t mask[9] = { 0 };
+ int i;
+
+ for (i = 0; i < sizeof(mask)/sizeof(mask[0]); i++)
+ {
+ assert(BitIsOn(mask, i) == 0);
+ SetBit(mask, i);
+ assert(BitIsOn(mask, i) == 1);
+ assert(!!(mask[i/8] & (1 << (i % 8))));
+ assert(CountBits(mask, sizeof(mask)) == 1);
+ ClearBit(mask, i);
+ assert(BitIsOn(mask, i) == 0);
+ }
+}
+
+/**
+ * Ensure that val->axisVal and val->axes are aligned on doubles.
+ */
+static void dix_valuator_alloc(void)
+{
+ ValuatorClassPtr v = NULL;
+ int num_axes = 0;
+
+ while (num_axes < 5)
+ {
+ v = AllocValuatorClass(v, num_axes);
+
+ assert(v);
+ assert(v->numAxes == num_axes);
+#ifndef __i386__
+ /* must be double-aligned on 64 bit */
+ assert(((void*)v->axisVal - (void*)v) % sizeof(double) == 0);
+ assert(((void*)v->axes - (void*)v) % sizeof(double) == 0);
+#endif
+ num_axes ++;
+ }
+
+ free(v);
+}
+
+int main(int argc, char** argv)
+{
+ dix_input_valuator_masks();
+ dix_input_attributes();
+ dix_init_valuators();
+ dix_event_to_core_conversion();
+ dix_event_to_xi1_conversion();
+ dix_check_grab_values();
+ xi2_struct_sizes();
+ dix_grab_matching();
+ dix_valuator_mode();
+ include_byte_padding_macros();
+ include_bit_test_macros();
+ xi_unregister_handlers();
+ dix_valuator_alloc();
+
+ return 0;
+}
diff --git a/xorg-server/test/list.c b/xorg-server/test/list.c index b101c7619..2b56f9b8d 100644 --- a/xorg-server/test/list.c +++ b/xorg-server/test/list.c @@ -1,173 +1,173 @@ -/** - * Copyright © 2011 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include <dix-config.h> -#endif - -#include <X11/Xlib.h> -#include <list.h> -#include <string.h> -#include <assert.h> - -struct parent { - int a; - struct list children; - int b; -}; - -struct child { - int foo; - int bar; - struct list node; -}; - -static void -test_list_init(void) -{ - struct parent parent, tmp; - - memset(&parent, 0, sizeof(parent)); - parent.a = 0xa5a5a5; - parent.b = ~0xa5a5a5; - - tmp = parent; - - list_init(&parent.children); - - /* test we haven't touched anything else. */ - assert(parent.a == tmp.a); - assert(parent.b == tmp.b); - - assert(list_is_empty(&parent.children)); -} - -static void -test_list_add(void) -{ - struct parent parent = {0}; - struct child child[3]; - struct child *c; - - list_init(&parent.children); - - list_add(&child[0].node, &parent.children); - assert(!list_is_empty(&parent.children)); - - c = list_first_entry(&parent.children, struct child, node); - assert(memcmp(c, &child[0], sizeof(struct child)) == 0); - - /* note: list_add prepends */ - list_add(&child[1].node, &parent.children); - c = list_first_entry(&parent.children, struct child, node); - assert(memcmp(c, &child[1], sizeof(struct child)) == 0); - - list_add(&child[2].node, &parent.children); - c = list_first_entry(&parent.children, struct child, node); - assert(memcmp(c, &child[2], sizeof(struct child)) == 0); -}; - -static void -test_list_del(void) -{ - struct parent parent = {0}; - struct child child[3]; - struct child *c; - - list_init(&parent.children); - - list_add(&child[0].node, &parent.children); - assert(!list_is_empty(&parent.children)); - - list_del(&parent.children); - assert(list_is_empty(&parent.children)); - - list_add(&child[0].node, &parent.children); - list_del(&child[0].node); - assert(list_is_empty(&parent.children)); - - list_add(&child[0].node, &parent.children); - list_add(&child[1].node, &parent.children); - - c = list_first_entry(&parent.children, struct child, node); - assert(memcmp(c, &child[1], sizeof(struct child)) == 0); - - /* delete first node */ - list_del(&child[1].node); - assert(!list_is_empty(&parent.children)); - assert(list_is_empty(&child[1].node)); - c = list_first_entry(&parent.children, struct child, node); - assert(memcmp(c, &child[0], sizeof(struct child)) == 0); - - /* delete last node */ - list_add(&child[1].node, &parent.children); - list_del(&child[0].node); - c = list_first_entry(&parent.children, struct child, node); - assert(memcmp(c, &child[1], sizeof(struct child)) == 0); - - /* delete list head */ - list_add(&child[0].node, &parent.children); - list_del(&parent.children); - assert(list_is_empty(&parent.children)); - assert(!list_is_empty(&child[1].node)); - assert(!list_is_empty(&child[2].node)); -} - -static void -test_list_for_each(void) -{ - struct parent parent = {0}; - struct child child[3]; - struct child *c; - int i = 0; - - list_init(&parent.children); - - list_add(&child[2].node, &parent.children); - list_add(&child[1].node, &parent.children); - list_add(&child[0].node, &parent.children); - - list_for_each_entry(c, &parent.children, node) { - assert(memcmp(c, &child[i], sizeof(struct child)) == 0); - i++; - } - - /* foreach on empty list */ - list_del(&parent.children); - assert(list_is_empty(&parent.children)); - - list_for_each_entry(c, &parent.children, node) { - assert(0); /* we must not get here */ - } -} - - -int main(int argc, char** argv) -{ - test_list_init(); - test_list_add(); - test_list_del(); - test_list_for_each(); - - return 0; -} +/**
+ * Copyright © 2011 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <X11/Xlib.h>
+#include <list.h>
+#include <string.h>
+#include <assert.h>
+
+struct parent {
+ int a;
+ struct list children;
+ int b;
+};
+
+struct child {
+ int foo;
+ int bar;
+ struct list node;
+};
+
+static void
+test_list_init(void)
+{
+ struct parent parent, tmp;
+
+ memset(&parent, 0, sizeof(parent));
+ parent.a = 0xa5a5a5;
+ parent.b = ~0xa5a5a5;
+
+ tmp = parent;
+
+ list_init(&parent.children);
+
+ /* test we haven't touched anything else. */
+ assert(parent.a == tmp.a);
+ assert(parent.b == tmp.b);
+
+ assert(list_is_empty(&parent.children));
+}
+
+static void
+test_list_add(void)
+{
+ struct parent parent = {0};
+ struct child child[3];
+ struct child *c;
+
+ list_init(&parent.children);
+
+ list_add(&child[0].node, &parent.children);
+ assert(!list_is_empty(&parent.children));
+
+ c = list_first_entry(&parent.children, struct child, node);
+ assert(memcmp(c, &child[0], sizeof(struct child)) == 0);
+
+ /* note: list_add prepends */
+ list_add(&child[1].node, &parent.children);
+ c = list_first_entry(&parent.children, struct child, node);
+ assert(memcmp(c, &child[1], sizeof(struct child)) == 0);
+
+ list_add(&child[2].node, &parent.children);
+ c = list_first_entry(&parent.children, struct child, node);
+ assert(memcmp(c, &child[2], sizeof(struct child)) == 0);
+};
+
+static void
+test_list_del(void)
+{
+ struct parent parent = {0};
+ struct child child[3];
+ struct child *c;
+
+ list_init(&parent.children);
+
+ list_add(&child[0].node, &parent.children);
+ assert(!list_is_empty(&parent.children));
+
+ list_del(&parent.children);
+ assert(list_is_empty(&parent.children));
+
+ list_add(&child[0].node, &parent.children);
+ list_del(&child[0].node);
+ assert(list_is_empty(&parent.children));
+
+ list_add(&child[0].node, &parent.children);
+ list_add(&child[1].node, &parent.children);
+
+ c = list_first_entry(&parent.children, struct child, node);
+ assert(memcmp(c, &child[1], sizeof(struct child)) == 0);
+
+ /* delete first node */
+ list_del(&child[1].node);
+ assert(!list_is_empty(&parent.children));
+ assert(list_is_empty(&child[1].node));
+ c = list_first_entry(&parent.children, struct child, node);
+ assert(memcmp(c, &child[0], sizeof(struct child)) == 0);
+
+ /* delete last node */
+ list_add(&child[1].node, &parent.children);
+ list_del(&child[0].node);
+ c = list_first_entry(&parent.children, struct child, node);
+ assert(memcmp(c, &child[1], sizeof(struct child)) == 0);
+
+ /* delete list head */
+ list_add(&child[0].node, &parent.children);
+ list_del(&parent.children);
+ assert(list_is_empty(&parent.children));
+ assert(!list_is_empty(&child[1].node));
+ assert(!list_is_empty(&child[2].node));
+}
+
+static void
+test_list_for_each(void)
+{
+ struct parent parent = {0};
+ struct child child[3];
+ struct child *c;
+ int i = 0;
+
+ list_init(&parent.children);
+
+ list_add(&child[2].node, &parent.children);
+ list_add(&child[1].node, &parent.children);
+ list_add(&child[0].node, &parent.children);
+
+ list_for_each_entry(c, &parent.children, node) {
+ assert(memcmp(c, &child[i], sizeof(struct child)) == 0);
+ i++;
+ }
+
+ /* foreach on empty list */
+ list_del(&parent.children);
+ assert(list_is_empty(&parent.children));
+
+ list_for_each_entry(c, &parent.children, node) {
+ assert(0); /* we must not get here */
+ }
+}
+
+
+int main(int argc, char** argv)
+{
+ test_list_init();
+ test_list_add();
+ test_list_del();
+ test_list_for_each();
+
+ return 0;
+}
diff --git a/xorg-server/test/xi2/Makefile.am b/xorg-server/test/xi2/Makefile.am index b15d8ba02..3b69ed1a4 100644 --- a/xorg-server/test/xi2/Makefile.am +++ b/xorg-server/test/xi2/Makefile.am @@ -1,57 +1,57 @@ -if ENABLE_UNIT_TESTS -if HAVE_LD_WRAP -noinst_PROGRAMS = \ - protocol-xiqueryversion \ - protocol-xiquerydevice \ - protocol-xiselectevents \ - protocol-xigetselectedevents \ - protocol-xisetclientpointer \ - protocol-xigetclientpointer \ - protocol-xipassivegrabdevice \ - protocol-xiquerypointer \ - protocol-xiwarppointer \ - protocol-eventconvert - -TESTS=$(noinst_PROGRAMS) - -AM_CFLAGS = $(DIX_CFLAGS) @XORG_CFLAGS@ -INCLUDES = @XORG_INCS@ -TEST_LDADD=../libxservertest.la $(XORG_SYS_LIBS) $(XSERVER_SYS_LIBS) -COMMON_SOURCES=protocol-common.h protocol-common.c - -if SPECIAL_DTRACE_OBJECTS -TEST_LDADD += $(OS_LIB) $(DIX_LIB) -endif - -protocol_xiqueryversion_LDADD=$(TEST_LDADD) -protocol_xiquerydevice_LDADD=$(TEST_LDADD) -protocol_xiselectevents_LDADD=$(TEST_LDADD) -protocol_xigetselectedevents_LDADD=$(TEST_LDADD) -protocol_xisetclientpointer_LDADD=$(TEST_LDADD) -protocol_xigetclientpointer_LDADD=$(TEST_LDADD) -protocol_xiquerypointer_LDADD=$(TEST_LDADD) -protocol_xipassivegrabdevice_LDADD=$(TEST_LDADD) -protocol_xiwarppointer_LDADD=$(TEST_LDADD) -protocol_eventconvert_LDADD=$(TEST_LDADD) - -protocol_xiqueryversion_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient -protocol_xiquerydevice_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient -protocol_xiselectevents_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,dixLookupWindow -Wl,-wrap,XISetEventMask -protocol_xigetselectedevents_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient -Wl,-wrap,dixLookupWindow -Wl,-wrap,AddResource -protocol_xisetclientpointer_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,dixLookupClient -protocol_xigetclientpointer_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient -Wl,-wrap,dixLookupClient -protocol_xipassivegrabdevice_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,GrabButton -Wl,-wrap,dixLookupWindow -Wl,-wrap,WriteToClient -protocol_xiquerypointer_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient -Wl,-wrap,dixLookupWindow -protocol_xiwarppointer_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient -Wl,-wrap,dixLookupWindow - -protocol_xiqueryversion_SOURCES=$(COMMON_SOURCES) protocol-xiqueryversion.c -protocol_xiquerydevice_SOURCES=$(COMMON_SOURCES) protocol-xiquerydevice.c -protocol_xiselectevents_SOURCES=$(COMMON_SOURCES) protocol-xiselectevents.c -protocol_xigetselectedevents_SOURCES=$(COMMON_SOURCES) protocol-xigetselectedevents.c -protocol_xisetclientpointer_SOURCES=$(COMMON_SOURCES) protocol-xisetclientpointer.c -protocol_xigetclientpointer_SOURCES=$(COMMON_SOURCES) protocol-xigetclientpointer.c -protocol_xiquerypointer_SOURCES=$(COMMON_SOURCES) protocol-xiquerypointer.c -protocol_xipassivegrabdevice_SOURCES=$(COMMON_SOURCES) protocol-xipassivegrabdevice.c -protocol_xiwarppointer_SOURCES=$(COMMON_SOURCES) protocol-xiwarppointer.c -endif -endif +if ENABLE_UNIT_TESTS
+if HAVE_LD_WRAP
+noinst_PROGRAMS = \
+ protocol-xiqueryversion \
+ protocol-xiquerydevice \
+ protocol-xiselectevents \
+ protocol-xigetselectedevents \
+ protocol-xisetclientpointer \
+ protocol-xigetclientpointer \
+ protocol-xipassivegrabdevice \
+ protocol-xiquerypointer \
+ protocol-xiwarppointer \
+ protocol-eventconvert
+
+TESTS=$(noinst_PROGRAMS)
+
+AM_CFLAGS = $(DIX_CFLAGS) @XORG_CFLAGS@
+INCLUDES = @XORG_INCS@
+TEST_LDADD=../libxservertest.la $(XORG_SYS_LIBS) $(XSERVER_SYS_LIBS)
+COMMON_SOURCES=protocol-common.h protocol-common.c
+
+if SPECIAL_DTRACE_OBJECTS
+TEST_LDADD += $(OS_LIB) $(DIX_LIB)
+endif
+
+protocol_xiqueryversion_LDADD=$(TEST_LDADD)
+protocol_xiquerydevice_LDADD=$(TEST_LDADD)
+protocol_xiselectevents_LDADD=$(TEST_LDADD)
+protocol_xigetselectedevents_LDADD=$(TEST_LDADD)
+protocol_xisetclientpointer_LDADD=$(TEST_LDADD)
+protocol_xigetclientpointer_LDADD=$(TEST_LDADD)
+protocol_xiquerypointer_LDADD=$(TEST_LDADD)
+protocol_xipassivegrabdevice_LDADD=$(TEST_LDADD)
+protocol_xiwarppointer_LDADD=$(TEST_LDADD)
+protocol_eventconvert_LDADD=$(TEST_LDADD)
+
+protocol_xiqueryversion_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient
+protocol_xiquerydevice_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient
+protocol_xiselectevents_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,dixLookupWindow -Wl,-wrap,XISetEventMask
+protocol_xigetselectedevents_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient -Wl,-wrap,dixLookupWindow -Wl,-wrap,AddResource
+protocol_xisetclientpointer_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,dixLookupClient
+protocol_xigetclientpointer_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient -Wl,-wrap,dixLookupClient
+protocol_xipassivegrabdevice_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,GrabButton -Wl,-wrap,dixLookupWindow -Wl,-wrap,WriteToClient
+protocol_xiquerypointer_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient -Wl,-wrap,dixLookupWindow
+protocol_xiwarppointer_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient -Wl,-wrap,dixLookupWindow
+
+protocol_xiqueryversion_SOURCES=$(COMMON_SOURCES) protocol-xiqueryversion.c
+protocol_xiquerydevice_SOURCES=$(COMMON_SOURCES) protocol-xiquerydevice.c
+protocol_xiselectevents_SOURCES=$(COMMON_SOURCES) protocol-xiselectevents.c
+protocol_xigetselectedevents_SOURCES=$(COMMON_SOURCES) protocol-xigetselectedevents.c
+protocol_xisetclientpointer_SOURCES=$(COMMON_SOURCES) protocol-xisetclientpointer.c
+protocol_xigetclientpointer_SOURCES=$(COMMON_SOURCES) protocol-xigetclientpointer.c
+protocol_xiquerypointer_SOURCES=$(COMMON_SOURCES) protocol-xiquerypointer.c
+protocol_xipassivegrabdevice_SOURCES=$(COMMON_SOURCES) protocol-xipassivegrabdevice.c
+protocol_xiwarppointer_SOURCES=$(COMMON_SOURCES) protocol-xiwarppointer.c
+endif
+endif
diff --git a/xorg-server/test/xi2/protocol-common.c b/xorg-server/test/xi2/protocol-common.c index 423453358..b6909f925 100644 --- a/xorg-server/test/xi2/protocol-common.c +++ b/xorg-server/test/xi2/protocol-common.c @@ -1,177 +1,177 @@ -/** - * Copyright © 2009 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include <dix-config.h> -#endif - -#include <stdint.h> -#include "extinit.h" /* for XInputExtensionInit */ -#include "exglobals.h" -#include "xkbsrv.h" /* for XkbInitPrivates */ - -#include "protocol-common.h" - -struct devices devices; -ScreenRec screen; -WindowRec root; -WindowRec window; - -void *userdata; - -extern int CorePointerProc(DeviceIntPtr pDev, int what); -extern int CoreKeyboardProc(DeviceIntPtr pDev, int what); - -static void fake_init_sprite(DeviceIntPtr dev) -{ - SpritePtr sprite; - sprite = dev->spriteInfo->sprite; - - sprite->spriteTraceSize = 10; - sprite->spriteTrace = calloc(sprite->spriteTraceSize, sizeof(WindowPtr)); - sprite->spriteTraceGood = 1; - sprite->spriteTrace[0] = &root; - sprite->hot.x = SPRITE_X; - sprite->hot.y = SPRITE_Y; - sprite->hotPhys.x = sprite->hot.x; - sprite->hotPhys.y = sprite->hot.y; - sprite->win = &window; - sprite->hotPhys.pScreen = &screen; - sprite->physLimits.x1 = 0; - sprite->physLimits.y1 = 0; - sprite->physLimits.x2 = screen.width; - sprite->physLimits.y2 = screen.height; -} - -/** - * Create and init 2 master devices (VCP + VCK) and two slave devices, one - * default mouse, one default keyboard. - */ -struct devices init_devices(void) -{ - ClientRec client; - struct devices devices; - - client = init_client(0, NULL); - - AllocDevicePair(&client, "Virtual core", &devices.vcp, &devices.vck, - CorePointerProc, CoreKeyboardProc, TRUE); - inputInfo.pointer = devices.vcp; - inputInfo.keyboard = devices.vck; - ActivateDevice(devices.vcp, FALSE); - ActivateDevice(devices.vck, FALSE); - EnableDevice(devices.vcp, FALSE); - EnableDevice(devices.vck, FALSE); - - AllocDevicePair(&client, "", &devices.mouse, &devices.kbd, - CorePointerProc, CoreKeyboardProc, FALSE); - ActivateDevice(devices.mouse, FALSE); - ActivateDevice(devices.kbd, FALSE); - EnableDevice(devices.mouse, FALSE); - EnableDevice(devices.kbd, FALSE); - - devices.num_devices = 4; - devices.num_master_devices = 2; - - fake_init_sprite(devices.mouse); - fake_init_sprite(devices.vcp); - - return devices; -} - - -/* Create minimal client, with the given buffer and len as request buffer */ -ClientRec init_client(int len, void *data) -{ - ClientRec client = { 0 }; - - /* we store the privates now and reassign it after the memset. this way - * we can share them across multiple test runs and don't have to worry - * about freeing them after each test run. */ - - client.index = CLIENT_INDEX; - client.clientAsMask = CLIENT_MASK; - client.sequence = CLIENT_SEQUENCE; - client.req_len = len; - - client.requestBuffer = data; - dixAllocatePrivates(&client.devPrivates, PRIVATE_CLIENT); - return client; -} - -void init_window(WindowPtr window, WindowPtr parent, int id) -{ - memset(window, 0, sizeof(*window)); - - window->drawable.id = id; - if (parent) - { - window->drawable.x = 30; - window->drawable.y = 50; - window->drawable.width = 100; - window->drawable.height = 200; - } - window->parent = parent; - window->optional = calloc(1, sizeof(WindowOptRec)); - assert(window->optional); -} - -extern DevPrivateKeyRec miPointerScreenKeyRec; -extern DevPrivateKeyRec miPointerPrivKeyRec; - -/* Needed for the screen setup, otherwise we crash during sprite initialization */ -static Bool device_cursor_init(DeviceIntPtr dev, ScreenPtr screen) { return TRUE; } -static Bool set_cursor_pos(DeviceIntPtr dev, ScreenPtr screen, int x, int y, Bool event) { return TRUE; } -void init_simple(void) -{ - screenInfo.numScreens = 1; - screenInfo.screens[0] = &screen; - - screen.myNum = 0; - screen.id = 100; - screen.width = 640; - screen.height = 480; - screen.DeviceCursorInitialize = device_cursor_init; - screen.SetCursorPosition = set_cursor_pos; - - dixResetPrivates(); - InitAtoms(); - XkbInitPrivates(); - dixRegisterPrivateKey(&XIClientPrivateKeyRec, PRIVATE_CLIENT, sizeof(XIClientRec)); - dixRegisterPrivateKey(&miPointerScreenKeyRec, PRIVATE_SCREEN, 0); - dixRegisterPrivateKey(&miPointerPrivKeyRec, PRIVATE_DEVICE, 0); - XInputExtensionInit(); - - init_window(&root, NULL, ROOT_WINDOW_ID); - init_window(&window, &root, CLIENT_WINDOW_ID); - - devices = init_devices(); -} - -void __wrap_WriteToClient(ClientPtr client, int len, void *data) -{ - assert(reply_handler != NULL); - - (*reply_handler)(client, len, data, userdata); -} - +/**
+ * Copyright © 2009 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <stdint.h>
+#include "extinit.h" /* for XInputExtensionInit */
+#include "exglobals.h"
+#include "xkbsrv.h" /* for XkbInitPrivates */
+
+#include "protocol-common.h"
+
+struct devices devices;
+ScreenRec screen;
+WindowRec root;
+WindowRec window;
+
+void *userdata;
+
+extern int CorePointerProc(DeviceIntPtr pDev, int what);
+extern int CoreKeyboardProc(DeviceIntPtr pDev, int what);
+
+static void fake_init_sprite(DeviceIntPtr dev)
+{
+ SpritePtr sprite;
+ sprite = dev->spriteInfo->sprite;
+
+ sprite->spriteTraceSize = 10;
+ sprite->spriteTrace = calloc(sprite->spriteTraceSize, sizeof(WindowPtr));
+ sprite->spriteTraceGood = 1;
+ sprite->spriteTrace[0] = &root;
+ sprite->hot.x = SPRITE_X;
+ sprite->hot.y = SPRITE_Y;
+ sprite->hotPhys.x = sprite->hot.x;
+ sprite->hotPhys.y = sprite->hot.y;
+ sprite->win = &window;
+ sprite->hotPhys.pScreen = &screen;
+ sprite->physLimits.x1 = 0;
+ sprite->physLimits.y1 = 0;
+ sprite->physLimits.x2 = screen.width;
+ sprite->physLimits.y2 = screen.height;
+}
+
+/**
+ * Create and init 2 master devices (VCP + VCK) and two slave devices, one
+ * default mouse, one default keyboard.
+ */
+struct devices init_devices(void)
+{
+ ClientRec client;
+ struct devices devices;
+
+ client = init_client(0, NULL);
+
+ AllocDevicePair(&client, "Virtual core", &devices.vcp, &devices.vck,
+ CorePointerProc, CoreKeyboardProc, TRUE);
+ inputInfo.pointer = devices.vcp;
+ inputInfo.keyboard = devices.vck;
+ ActivateDevice(devices.vcp, FALSE);
+ ActivateDevice(devices.vck, FALSE);
+ EnableDevice(devices.vcp, FALSE);
+ EnableDevice(devices.vck, FALSE);
+
+ AllocDevicePair(&client, "", &devices.mouse, &devices.kbd,
+ CorePointerProc, CoreKeyboardProc, FALSE);
+ ActivateDevice(devices.mouse, FALSE);
+ ActivateDevice(devices.kbd, FALSE);
+ EnableDevice(devices.mouse, FALSE);
+ EnableDevice(devices.kbd, FALSE);
+
+ devices.num_devices = 4;
+ devices.num_master_devices = 2;
+
+ fake_init_sprite(devices.mouse);
+ fake_init_sprite(devices.vcp);
+
+ return devices;
+}
+
+
+/* Create minimal client, with the given buffer and len as request buffer */
+ClientRec init_client(int len, void *data)
+{
+ ClientRec client = { 0 };
+
+ /* we store the privates now and reassign it after the memset. this way
+ * we can share them across multiple test runs and don't have to worry
+ * about freeing them after each test run. */
+
+ client.index = CLIENT_INDEX;
+ client.clientAsMask = CLIENT_MASK;
+ client.sequence = CLIENT_SEQUENCE;
+ client.req_len = len;
+
+ client.requestBuffer = data;
+ dixAllocatePrivates(&client.devPrivates, PRIVATE_CLIENT);
+ return client;
+}
+
+void init_window(WindowPtr window, WindowPtr parent, int id)
+{
+ memset(window, 0, sizeof(*window));
+
+ window->drawable.id = id;
+ if (parent)
+ {
+ window->drawable.x = 30;
+ window->drawable.y = 50;
+ window->drawable.width = 100;
+ window->drawable.height = 200;
+ }
+ window->parent = parent;
+ window->optional = calloc(1, sizeof(WindowOptRec));
+ assert(window->optional);
+}
+
+extern DevPrivateKeyRec miPointerScreenKeyRec;
+extern DevPrivateKeyRec miPointerPrivKeyRec;
+
+/* Needed for the screen setup, otherwise we crash during sprite initialization */
+static Bool device_cursor_init(DeviceIntPtr dev, ScreenPtr screen) { return TRUE; }
+static Bool set_cursor_pos(DeviceIntPtr dev, ScreenPtr screen, int x, int y, Bool event) { return TRUE; }
+void init_simple(void)
+{
+ screenInfo.numScreens = 1;
+ screenInfo.screens[0] = &screen;
+
+ screen.myNum = 0;
+ screen.id = 100;
+ screen.width = 640;
+ screen.height = 480;
+ screen.DeviceCursorInitialize = device_cursor_init;
+ screen.SetCursorPosition = set_cursor_pos;
+
+ dixResetPrivates();
+ InitAtoms();
+ XkbInitPrivates();
+ dixRegisterPrivateKey(&XIClientPrivateKeyRec, PRIVATE_CLIENT, sizeof(XIClientRec));
+ dixRegisterPrivateKey(&miPointerScreenKeyRec, PRIVATE_SCREEN, 0);
+ dixRegisterPrivateKey(&miPointerPrivKeyRec, PRIVATE_DEVICE, 0);
+ XInputExtensionInit();
+
+ init_window(&root, NULL, ROOT_WINDOW_ID);
+ init_window(&window, &root, CLIENT_WINDOW_ID);
+
+ devices = init_devices();
+}
+
+void __wrap_WriteToClient(ClientPtr client, int len, void *data)
+{
+ assert(reply_handler != NULL);
+
+ (*reply_handler)(client, len, data, userdata);
+}
+
diff --git a/xorg-server/test/xi2/protocol-common.h b/xorg-server/test/xi2/protocol-common.h index b55f57c05..aa9852d3a 100644 --- a/xorg-server/test/xi2/protocol-common.h +++ b/xorg-server/test/xi2/protocol-common.h @@ -1,153 +1,153 @@ -/** - * Copyright © 2009 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include <dix-config.h> -#endif - -#include "scrnintstr.h" -#include "windowstr.h" -#include "exevents.h" -#include <assert.h> - -#ifndef PROTOCOL_COMMON_H -#define PROTOCOL_COMMON_H - -extern int BadDevice; - -/* Check default values in a reply */ -#define reply_check_defaults(rep, len, type) \ - { \ - assert((len) >= sz_x##type##Reply); \ - assert((rep)->repType == X_Reply); \ - assert((rep)->RepType == X_##type); \ - assert((rep)->sequenceNumber == CLIENT_SEQUENCE); \ - assert((rep)->length >= (sz_x##type##Reply - 32)/4); \ - } - -/* initialise default values for request */ -#define request_init(req, type) \ - { \ - (req)->reqType = 128; /* doesn't matter */ \ - (req)->ReqType = X_##type; \ - (req)->length = (sz_x##type##Req >> 2); \ - } - - -/* Various defines used in the tests. Some tests may use different values - * than these defaults */ -/* default client index */ -#define CLIENT_INDEX 1 -/* default client mask for resources and windows */ -#define CLIENT_MASK ((CLIENT_INDEX) << CLIENTOFFSET) -/* default client sequence number for replies */ -#define CLIENT_SEQUENCE 0x100 -/* default root window id */ -#define ROOT_WINDOW_ID 0x10 -/* default client window id */ -#define CLIENT_WINDOW_ID 0x100001 -/* invalid window ID. use for BadWindow checks. */ -#define INVALID_WINDOW_ID 0x111111 -/* initial fake sprite position */ -#define SPRITE_X 100 -#define SPRITE_Y 200 - - -/* Various structs used throughout the tests */ - - -/* The default devices struct, contains one pointer + keyboard and the - * matching master devices. Initialize with init_devices() if needed. */ -struct devices { - DeviceIntPtr vcp; - DeviceIntPtr vck; - DeviceIntPtr mouse; - DeviceIntPtr kbd; - - int num_devices; - int num_master_devices; -} devices; - -/** - * The set of default devices available in all tests if necessary. - */ -extern struct devices devices; - -/** - * test-specific userdata, passed into the reply handler. - */ -extern void *userdata; -/** - * The reply handler called from WriteToClient. Set this handler if you need - * to check the reply values. - */ -void (*reply_handler)(ClientPtr client, int len, char *data, void *userdata); - -/** - * The default screen used for the windows. Initialized by init_simple(). - */ -extern ScreenRec screen; -/** - * Semi-initialized root window. initialized by init(). - */ -extern WindowRec root; -/** - * Semi-initialized top-level window. initialized by init(). - */ -extern WindowRec window; - -/* various simple functions for quick setup */ -/** - * Initialize the above struct with default devices and return the struct. - * Usually not needed if you call ::init_simple. - */ -struct devices init_devices(void); -/** - * Init a mostly zeroed out client with default values for index and mask. - */ -ClientRec init_client(int request_len, void *request_data); -/** - * Init a mostly zeroed out window with the given window ID. - * Usually not needed if you call ::init_simple which sets up root and - * window. - */ -void init_window(WindowPtr window, WindowPtr parent, int id); -/** - * Create a very simple setup that provides the minimum values for most - * tests, including a screen, the root and client window and the default - * device setup. - */ -void init_simple(void); - -/* Declarations for various overrides in the test files. */ -void __wrap_WriteToClient(ClientPtr client, int len, void *data); -int __wrap_XISetEventMask(DeviceIntPtr dev, WindowPtr win, int len, unsigned char* mask); -int __wrap_dixLookupWindow(WindowPtr *win, XID id, ClientPtr client, Mask access); -int __real_dixLookupWindow(WindowPtr *win, XID id, ClientPtr client, Mask access); -Bool __wrap_AddResource(XID id, RESTYPE type, pointer value); -int __wrap_dixLookupClient(ClientPtr *c, XID id, ClientPtr client, Mask access); -int __real_dixLookupClient(ClientPtr *c, XID id, ClientPtr client, Mask access); - - -#endif /* PROTOCOL_COMMON_H */ - +/**
+ * Copyright © 2009 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include "scrnintstr.h"
+#include "windowstr.h"
+#include "exevents.h"
+#include <assert.h>
+
+#ifndef PROTOCOL_COMMON_H
+#define PROTOCOL_COMMON_H
+
+extern int BadDevice;
+
+/* Check default values in a reply */
+#define reply_check_defaults(rep, len, type) \
+ { \
+ assert((len) >= sz_x##type##Reply); \
+ assert((rep)->repType == X_Reply); \
+ assert((rep)->RepType == X_##type); \
+ assert((rep)->sequenceNumber == CLIENT_SEQUENCE); \
+ assert((rep)->length >= (sz_x##type##Reply - 32)/4); \
+ }
+
+/* initialise default values for request */
+#define request_init(req, type) \
+ { \
+ (req)->reqType = 128; /* doesn't matter */ \
+ (req)->ReqType = X_##type; \
+ (req)->length = (sz_x##type##Req >> 2); \
+ }
+
+
+/* Various defines used in the tests. Some tests may use different values
+ * than these defaults */
+/* default client index */
+#define CLIENT_INDEX 1
+/* default client mask for resources and windows */
+#define CLIENT_MASK ((CLIENT_INDEX) << CLIENTOFFSET)
+/* default client sequence number for replies */
+#define CLIENT_SEQUENCE 0x100
+/* default root window id */
+#define ROOT_WINDOW_ID 0x10
+/* default client window id */
+#define CLIENT_WINDOW_ID 0x100001
+/* invalid window ID. use for BadWindow checks. */
+#define INVALID_WINDOW_ID 0x111111
+/* initial fake sprite position */
+#define SPRITE_X 100
+#define SPRITE_Y 200
+
+
+/* Various structs used throughout the tests */
+
+
+/* The default devices struct, contains one pointer + keyboard and the
+ * matching master devices. Initialize with init_devices() if needed. */
+struct devices {
+ DeviceIntPtr vcp;
+ DeviceIntPtr vck;
+ DeviceIntPtr mouse;
+ DeviceIntPtr kbd;
+
+ int num_devices;
+ int num_master_devices;
+} devices;
+
+/**
+ * The set of default devices available in all tests if necessary.
+ */
+extern struct devices devices;
+
+/**
+ * test-specific userdata, passed into the reply handler.
+ */
+extern void *userdata;
+/**
+ * The reply handler called from WriteToClient. Set this handler if you need
+ * to check the reply values.
+ */
+void (*reply_handler)(ClientPtr client, int len, char *data, void *userdata);
+
+/**
+ * The default screen used for the windows. Initialized by init_simple().
+ */
+extern ScreenRec screen;
+/**
+ * Semi-initialized root window. initialized by init().
+ */
+extern WindowRec root;
+/**
+ * Semi-initialized top-level window. initialized by init().
+ */
+extern WindowRec window;
+
+/* various simple functions for quick setup */
+/**
+ * Initialize the above struct with default devices and return the struct.
+ * Usually not needed if you call ::init_simple.
+ */
+struct devices init_devices(void);
+/**
+ * Init a mostly zeroed out client with default values for index and mask.
+ */
+ClientRec init_client(int request_len, void *request_data);
+/**
+ * Init a mostly zeroed out window with the given window ID.
+ * Usually not needed if you call ::init_simple which sets up root and
+ * window.
+ */
+void init_window(WindowPtr window, WindowPtr parent, int id);
+/**
+ * Create a very simple setup that provides the minimum values for most
+ * tests, including a screen, the root and client window and the default
+ * device setup.
+ */
+void init_simple(void);
+
+/* Declarations for various overrides in the test files. */
+void __wrap_WriteToClient(ClientPtr client, int len, void *data);
+int __wrap_XISetEventMask(DeviceIntPtr dev, WindowPtr win, int len, unsigned char* mask);
+int __wrap_dixLookupWindow(WindowPtr *win, XID id, ClientPtr client, Mask access);
+int __real_dixLookupWindow(WindowPtr *win, XID id, ClientPtr client, Mask access);
+Bool __wrap_AddResource(XID id, RESTYPE type, pointer value);
+int __wrap_dixLookupClient(ClientPtr *c, XID id, ClientPtr client, Mask access);
+int __real_dixLookupClient(ClientPtr *c, XID id, ClientPtr client, Mask access);
+
+
+#endif /* PROTOCOL_COMMON_H */
+
diff --git a/xorg-server/test/xi2/protocol-eventconvert.c b/xorg-server/test/xi2/protocol-eventconvert.c index 6e61d74b4..540825ef6 100644 --- a/xorg-server/test/xi2/protocol-eventconvert.c +++ b/xorg-server/test/xi2/protocol-eventconvert.c @@ -1,917 +1,917 @@ -/** - * Copyright © 2009 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include <dix-config.h> -#endif - -#include <stdint.h> - -#include "inputstr.h" -#include "eventstr.h" -#include "eventconvert.h" -#include "exevents.h" -#include <X11/extensions/XI2proto.h> - -static void test_values_XIRawEvent(RawDeviceEvent *in, xXIRawEvent *out, - BOOL swap) -{ - int i; - unsigned char *ptr; - FP3232 *value, *raw_value; - int nvals = 0; - int bits_set; - int len; - - if (swap) - { - char n; - - swaps(&out->sequenceNumber, n); - swapl(&out->length, n); - swaps(&out->evtype, n); - swaps(&out->deviceid, n); - swapl(&out->time, n); - swapl(&out->detail, n); - swaps(&out->valuators_len, n); - } - - - assert(out->type == GenericEvent); - assert(out->extension == 0); /* IReqCode defaults to 0 */ - assert(out->evtype == GetXI2Type((InternalEvent*)in)); - assert(out->time == in->time); - assert(out->detail == in->detail.button); - assert(out->deviceid == in->deviceid); - assert(out->valuators_len >= bytes_to_int32(bits_to_bytes(sizeof(in->valuators.mask)))); - assert(out->flags == 0); /* FIXME: we don't set the flags yet */ - - ptr = (unsigned char*)&out[1]; - bits_set = 0; - - for (i = 0; out->valuators_len && i < sizeof(in->valuators.mask) * 8; i++) - { - if (i >= MAX_VALUATORS) - assert (!XIMaskIsSet(in->valuators.mask, i)); - assert (XIMaskIsSet(in->valuators.mask, i) == XIMaskIsSet(ptr, i)); - if (XIMaskIsSet(in->valuators.mask, i)) - bits_set++; - } - - /* length is len of valuator mask (in 4-byte units) + the number of bits - * set. Each bit set represents 2 8-byte values, hence the - * 'bits_set * 4' */ - len = out->valuators_len + bits_set * 4; - assert(out->length == len); - - nvals = 0; - - for (i = 0; out->valuators_len && i < MAX_VALUATORS; i++) - { - assert (XIMaskIsSet(in->valuators.mask, i) == XIMaskIsSet(ptr, i)); - if (XIMaskIsSet(in->valuators.mask, i)) - { - FP3232 vi, vo; - value = (FP3232*)(((unsigned char*)&out[1]) + out->valuators_len * 4); - value += nvals; - - vi.integral = in->valuators.data[i]; - vi.frac = in->valuators.data_frac[i]; - - vo.integral = value->integral; - vo.frac = value->frac; - if (swap) - { - char n; - swapl(&vo.integral, n); - swapl(&vo.frac, n); - } - - assert(vi.integral == vo.integral); - assert(vi.frac == vo.frac); - - raw_value = value + bits_set; - - vi.integral = in->valuators.data_raw[i]; - vi.frac = in->valuators.data_raw_frac[i]; - - vo.integral = raw_value->integral; - vo.frac = raw_value->frac; - if (swap) - { - char n; - swapl(&vo.integral, n); - swapl(&vo.frac, n); - } - - assert(vi.integral == vo.integral); - assert(vi.frac == vo.frac); - - nvals++; - } - } -} - -static void test_XIRawEvent(RawDeviceEvent *in) -{ - xXIRawEvent *out, *swapped; - int rc; - - rc = EventToXI2((InternalEvent*)in, (xEvent**)&out); - assert(rc == Success); - - test_values_XIRawEvent(in, out, FALSE); - - swapped = calloc(1, sizeof(xEvent) + out->length * 4); - XI2EventSwap((xGenericEvent*)out, (xGenericEvent*)swapped); - test_values_XIRawEvent(in, swapped, TRUE); - - free(out); - free(swapped); -} - -static void test_convert_XIFocusEvent(void) -{ - xEvent *out; - DeviceEvent in; - int rc; - - in.header = ET_Internal; - in.type = ET_Enter; - rc = EventToXI2((InternalEvent*)&in, &out); - assert(rc == Success); - assert(out == NULL); - - in.header = ET_Internal; - in.type = ET_FocusIn; - rc = EventToXI2((InternalEvent*)&in, &out); - assert(rc == Success); - assert(out == NULL); - - in.header = ET_Internal; - in.type = ET_FocusOut; - rc = EventToXI2((InternalEvent*)&in, &out); - assert(rc == BadImplementation); - - in.header = ET_Internal; - in.type = ET_Leave; - rc = EventToXI2((InternalEvent*)&in, &out); - assert(rc == BadImplementation); -} - - -static void test_convert_XIRawEvent(void) -{ - RawDeviceEvent in; - int i; - - memset(&in, 0, sizeof(in)); - - printf("Testing all event types\n"); - in.header = ET_Internal; - in.type = ET_RawMotion; - test_XIRawEvent(&in); - - in.header = ET_Internal; - in.type = ET_RawKeyPress; - test_XIRawEvent(&in); - - in.header = ET_Internal; - in.type = ET_RawKeyRelease; - test_XIRawEvent(&in); - - in.header = ET_Internal; - in.type = ET_RawButtonPress; - test_XIRawEvent(&in); - - in.header = ET_Internal; - in.type = ET_RawButtonRelease; - test_XIRawEvent(&in); - - printf("Testing details and other fields\n"); - in.detail.button = 1L; - test_XIRawEvent(&in); - in.detail.button = 1L << 8; - test_XIRawEvent(&in); - in.detail.button = 1L << 16; - test_XIRawEvent(&in); - in.detail.button = 1L << 24; - test_XIRawEvent(&in); - in.detail.button = ~0L; - test_XIRawEvent(&in); - - in.detail.button = 0; - - in.time = 1L; - test_XIRawEvent(&in); - in.time = 1L << 8; - test_XIRawEvent(&in); - in.time = 1L << 16; - test_XIRawEvent(&in); - in.time = 1L << 24; - test_XIRawEvent(&in); - in.time = ~0L; - test_XIRawEvent(&in); - - in.deviceid = 1; - test_XIRawEvent(&in); - in.deviceid = 1 << 8; - test_XIRawEvent(&in); - in.deviceid = ~0 & 0xFF; - test_XIRawEvent(&in); - - printf("Testing valuator masks\n"); - for (i = 0; i < MAX_VALUATORS; i++) - { - XISetMask(in.valuators.mask, i); - test_XIRawEvent(&in); - XIClearMask(in.valuators.mask, i); - } - - for (i = 0; i < MAX_VALUATORS; i++) - { - XISetMask(in.valuators.mask, i); - - in.valuators.data[i] = i; - in.valuators.data_raw[i] = i + 10; - in.valuators.data_frac[i] = i + 20; - in.valuators.data_raw_frac[i] = i + 30; - test_XIRawEvent(&in); - XIClearMask(in.valuators.mask, i); - } - - for (i = 0; i < MAX_VALUATORS; i++) - { - XISetMask(in.valuators.mask, i); - test_XIRawEvent(&in); - } -} - -static void test_values_XIDeviceEvent(DeviceEvent *in, xXIDeviceEvent *out, - BOOL swap) -{ - int buttons, valuators; - int i; - unsigned char *ptr; - uint32_t flagmask = 0; - FP3232 *values; - - if (swap) { - char n; - - swaps(&out->sequenceNumber, n); - swapl(&out->length, n); - swaps(&out->evtype, n); - swaps(&out->deviceid, n); - swaps(&out->sourceid, n); - swapl(&out->time, n); - swapl(&out->detail, n); - swapl(&out->root, n); - swapl(&out->event, n); - swapl(&out->child, n); - swapl(&out->root_x, n); - swapl(&out->root_y, n); - swapl(&out->event_x, n); - swapl(&out->event_y, n); - swaps(&out->buttons_len, n); - swaps(&out->valuators_len, n); - swapl(&out->mods.base_mods, n); - swapl(&out->mods.latched_mods, n); - swapl(&out->mods.locked_mods, n); - swapl(&out->mods.effective_mods, n); - swapl(&out->flags, n); - } - - assert(out->extension == 0); /* IReqCode defaults to 0 */ - assert(out->evtype == GetXI2Type((InternalEvent*)in)); - assert(out->time == in->time); - assert(out->detail == in->detail.button); - assert(out->length >= 12); - - assert(out->deviceid == in->deviceid); - assert(out->sourceid == in->sourceid); - - switch (in->type) { - case ET_KeyPress: - flagmask = XIKeyRepeat; - break; - default: - flagmask = 0; - break; - } - assert((out->flags & ~flagmask) == 0); - - assert(out->root == in->root); - assert(out->event == None); /* set in FixUpEventFromWindow */ - assert(out->child == None); /* set in FixUpEventFromWindow */ - - assert(out->mods.base_mods == in->mods.base); - assert(out->mods.latched_mods == in->mods.latched); - assert(out->mods.locked_mods == in->mods.locked); - assert(out->mods.effective_mods == in->mods.effective); - - assert(out->group.base_group == in->group.base); - assert(out->group.latched_group == in->group.latched); - assert(out->group.locked_group == in->group.locked); - assert(out->group.effective_group == in->group.effective); - - assert(out->event_x == 0); /* set in FixUpEventFromWindow */ - assert(out->event_y == 0); /* set in FixUpEventFromWindow */ - - assert(out->root_x == FP1616(in->root_x, in->root_x_frac)); - assert(out->root_y == FP1616(in->root_y, in->root_y_frac)); - - buttons = 0; - for (i = 0; i < bits_to_bytes(sizeof(in->buttons)); i++) - { - if (XIMaskIsSet(in->buttons, i)) - { - assert(out->buttons_len >= bytes_to_int32(bits_to_bytes(i))); - buttons++; - } - } - - ptr = (unsigned char*)&out[1]; - for (i = 0; i < sizeof(in->buttons) * 8; i++) - assert(XIMaskIsSet(in->buttons, i) == XIMaskIsSet(ptr, i)); - - - valuators = 0; - for (i = 0; i < MAX_VALUATORS; i++) - if (XIMaskIsSet(in->valuators.mask, i)) - valuators++; - - assert(out->valuators_len >= bytes_to_int32(bits_to_bytes(valuators))); - - ptr += out->buttons_len * 4; - values = (FP3232*)(ptr + out->valuators_len * 4); - for (i = 0; i < sizeof(in->valuators.mask) * 8 || - i < (out->valuators_len * 4) * 8; i++) - { - if (i >= MAX_VALUATORS) - assert(!XIMaskIsSet(in->valuators.mask, i) && !XIMaskIsSet(ptr, i)); - else if (i > sizeof(in->valuators.mask) * 8) - assert(!XIMaskIsSet(ptr, i)); - else if (i > out->valuators_len * 4 * 8) - assert(!XIMaskIsSet(in->valuators.mask, i)); - else { - assert(XIMaskIsSet(in->valuators.mask, i) == - XIMaskIsSet(ptr, i)); - - if (XIMaskIsSet(ptr, i)) - { - FP3232 vi, vo; - - vi.integral = in->valuators.data[i]; - vi.frac = in->valuators.data_frac[i]; - - vo = *values; - - if (swap) - { - char n; - swapl(&vo.integral, n); - swapl(&vo.frac, n); - } - - - assert(vi.integral == vo.integral); - assert(vi.frac == vo.frac); - values++; - } - } - } -} - -static void test_XIDeviceEvent(DeviceEvent *in) -{ - xXIDeviceEvent *out, *swapped; - int rc; - - rc = EventToXI2((InternalEvent*)in, (xEvent**)&out); - assert(rc == Success); - - test_values_XIDeviceEvent(in, out, FALSE); - - swapped = calloc(1, sizeof(xEvent) + out->length * 4); - XI2EventSwap((xGenericEvent*)out, (xGenericEvent*)swapped); - test_values_XIDeviceEvent(in, swapped, TRUE); - - free(out); - free(swapped); -} - -static void test_convert_XIDeviceEvent(void) -{ - DeviceEvent in; - int i; - - memset(&in, 0, sizeof(in)); - - printf("Testing simple field values\n"); - in.header = ET_Internal; - in.type = ET_Motion; - in.length = sizeof(DeviceEvent); - in.time = 0; - in.deviceid = 1; - in.sourceid = 2; - in.root = 3; - in.root_x = 4; - in.root_x_frac = 5; - in.root_y = 6; - in.root_y_frac = 7; - in.detail.button = 8; - in.mods.base = 9; - in.mods.latched = 10; - in.mods.locked = 11; - in.mods.effective = 11; - in.group.base = 12; - in.group.latched = 13; - in.group.locked = 14; - in.group.effective = 15; - - test_XIDeviceEvent(&in); - - printf("Testing field ranges\n"); - /* 32 bit */ - in.detail.button = 1L; - test_XIDeviceEvent(&in); - in.detail.button = 1L << 8; - test_XIDeviceEvent(&in); - in.detail.button = 1L << 16; - test_XIDeviceEvent(&in); - in.detail.button = 1L << 24; - test_XIDeviceEvent(&in); - in.detail.button = ~0L; - test_XIDeviceEvent(&in); - - /* 32 bit */ - in.time = 1L; - test_XIDeviceEvent(&in); - in.time = 1L << 8; - test_XIDeviceEvent(&in); - in.time = 1L << 16; - test_XIDeviceEvent(&in); - in.time = 1L << 24; - test_XIDeviceEvent(&in); - in.time = ~0L; - test_XIDeviceEvent(&in); - - /* 16 bit */ - in.deviceid = 1; - test_XIDeviceEvent(&in); - in.deviceid = 1 << 8; - test_XIDeviceEvent(&in); - in.deviceid = ~0 & 0xFF; - test_XIDeviceEvent(&in); - - /* 16 bit */ - in.sourceid = 1; - test_XIDeviceEvent(&in); - in.deviceid = 1 << 8; - test_XIDeviceEvent(&in); - in.deviceid = ~0 & 0xFF; - test_XIDeviceEvent(&in); - - /* 32 bit */ - in.root = 1L; - test_XIDeviceEvent(&in); - in.root = 1L << 8; - test_XIDeviceEvent(&in); - in.root = 1L << 16; - test_XIDeviceEvent(&in); - in.root = 1L << 24; - test_XIDeviceEvent(&in); - in.root = ~0L; - test_XIDeviceEvent(&in); - - /* 16 bit */ - in.root_x = 1; - test_XIDeviceEvent(&in); - in.root_x = 1 << 8; - test_XIDeviceEvent(&in); - in.root_x = ~0 & 0xFF; - test_XIDeviceEvent(&in); - - in.root_x_frac = 1; - test_XIDeviceEvent(&in); - in.root_x_frac = 1 << 8; - test_XIDeviceEvent(&in); - in.root_x_frac = ~0 & 0xFF; - test_XIDeviceEvent(&in); - - in.root_y = 1; - test_XIDeviceEvent(&in); - in.root_y = 1 << 8; - test_XIDeviceEvent(&in); - in.root_y = ~0 & 0xFF; - test_XIDeviceEvent(&in); - - in.root_y_frac = 1; - test_XIDeviceEvent(&in); - in.root_y_frac = 1 << 8; - test_XIDeviceEvent(&in); - in.root_y_frac = ~0 & 0xFF; - test_XIDeviceEvent(&in); - - /* 32 bit */ - in.mods.base = 1L; - test_XIDeviceEvent(&in); - in.mods.base = 1L << 8; - test_XIDeviceEvent(&in); - in.mods.base = 1L << 16; - test_XIDeviceEvent(&in); - in.mods.base = 1L << 24; - test_XIDeviceEvent(&in); - in.mods.base = ~0L; - test_XIDeviceEvent(&in); - - in.mods.latched = 1L; - test_XIDeviceEvent(&in); - in.mods.latched = 1L << 8; - test_XIDeviceEvent(&in); - in.mods.latched = 1L << 16; - test_XIDeviceEvent(&in); - in.mods.latched = 1L << 24; - test_XIDeviceEvent(&in); - in.mods.latched = ~0L; - test_XIDeviceEvent(&in); - - in.mods.locked = 1L; - test_XIDeviceEvent(&in); - in.mods.locked = 1L << 8; - test_XIDeviceEvent(&in); - in.mods.locked = 1L << 16; - test_XIDeviceEvent(&in); - in.mods.locked = 1L << 24; - test_XIDeviceEvent(&in); - in.mods.locked = ~0L; - test_XIDeviceEvent(&in); - - in.mods.effective = 1L; - test_XIDeviceEvent(&in); - in.mods.effective = 1L << 8; - test_XIDeviceEvent(&in); - in.mods.effective = 1L << 16; - test_XIDeviceEvent(&in); - in.mods.effective = 1L << 24; - test_XIDeviceEvent(&in); - in.mods.effective = ~0L; - test_XIDeviceEvent(&in); - - /* 8 bit */ - in.group.base = 1; - test_XIDeviceEvent(&in); - in.group.base = ~0 & 0xFF; - test_XIDeviceEvent(&in); - - in.group.latched = 1; - test_XIDeviceEvent(&in); - in.group.latched = ~0 & 0xFF; - test_XIDeviceEvent(&in); - - in.group.locked = 1; - test_XIDeviceEvent(&in); - in.group.locked = ~0 & 0xFF; - test_XIDeviceEvent(&in); - - in.mods.effective = 1; - test_XIDeviceEvent(&in); - in.mods.effective = ~0 & 0xFF; - test_XIDeviceEvent(&in); - - printf("Testing button masks\n"); - for (i = 0; i < sizeof(in.buttons) * 8; i++) - { - XISetMask(in.buttons, i); - test_XIDeviceEvent(&in); - XIClearMask(in.buttons, i); - } - - for (i = 0; i < sizeof(in.buttons) * 8; i++) - { - XISetMask(in.buttons, i); - test_XIDeviceEvent(&in); - } - - printf("Testing valuator masks\n"); - for (i = 0; i < MAX_VALUATORS; i++) - { - XISetMask(in.valuators.mask, i); - test_XIDeviceEvent(&in); - XIClearMask(in.valuators.mask, i); - } - - for (i = 0; i < MAX_VALUATORS; i++) - { - XISetMask(in.valuators.mask, i); - - in.valuators.data[i] = i; - in.valuators.data_frac[i] = i + 20; - test_XIDeviceEvent(&in); - XIClearMask(in.valuators.mask, i); - } - - for (i = 0; i < MAX_VALUATORS; i++) - { - XISetMask(in.valuators.mask, i); - test_XIDeviceEvent(&in); - } -} - -static void test_values_XIDeviceChangedEvent(DeviceChangedEvent *in, - xXIDeviceChangedEvent *out, - BOOL swap) -{ - int i, j; - unsigned char *ptr; - - if (swap) - { - char n; - - swaps(&out->sequenceNumber, n); - swapl(&out->length, n); - swaps(&out->evtype, n); - swaps(&out->deviceid, n); - swaps(&out->sourceid, n); - swapl(&out->time, n); - swaps(&out->num_classes, n); - } - - assert(out->type == GenericEvent); - assert(out->extension == 0); /* IReqCode defaults to 0 */ - assert(out->evtype == GetXI2Type((InternalEvent*)in)); - assert(out->time == in->time); - assert(out->deviceid == in->deviceid); - assert(out->sourceid == in->sourceid); - - ptr = (unsigned char*)&out[1]; - for (i = 0; i < out->num_classes; i++) - { - xXIAnyInfo* any = (xXIAnyInfo*)ptr; - - if (swap) - { - char n; - swaps(&any->length, n); - swaps(&any->type, n); - swaps(&any->sourceid, n); - } - - switch(any->type) - { - case XIButtonClass: - { - xXIButtonInfo *b = (xXIButtonInfo*)any; - Atom *names; - - if (swap) - { - char n; - swaps(&b->num_buttons, n); - } - - assert(b->length == - bytes_to_int32(sizeof(xXIButtonInfo)) + - bytes_to_int32(bits_to_bytes(b->num_buttons)) + - b->num_buttons); - assert(b->num_buttons == in->buttons.num_buttons); - - names = (Atom*)((char*)&b[1] + - pad_to_int32(bits_to_bytes(b->num_buttons))); - for (j = 0; j < b->num_buttons; j++) - { - if (swap) - { - char n; - swapl(&names[j], n); - } - assert(names[j] == in->buttons.names[j]); - } - } - break; - case XIKeyClass: - { - xXIKeyInfo *k = (xXIKeyInfo*)any; - uint32_t *kc; - - if (swap) - { - char n; - swaps(&k->num_keycodes, n); - } - - assert(k->length == - bytes_to_int32(sizeof(xXIKeyInfo)) + - k->num_keycodes); - assert(k->num_keycodes == in->keys.max_keycode - - in->keys.min_keycode + 1); - - kc = (uint32_t*)&k[1]; - for (j = 0; j < k->num_keycodes; j++) - { - if (swap) - { - char n; - swapl(&kc[j], n); - } - assert(kc[j] >= in->keys.min_keycode); - assert(kc[j] <= in->keys.max_keycode); - } - } - break; - case XIValuatorClass: - { - xXIValuatorInfo *v = (xXIValuatorInfo*)any; - assert(v->length == - bytes_to_int32(sizeof(xXIValuatorInfo))); - - } - break; - default: - printf("Invalid class type.\n\n"); - assert(1); - break; - } - - ptr += any->length * 4; - } - -} - -static void test_XIDeviceChangedEvent(DeviceChangedEvent *in) -{ - xXIDeviceChangedEvent *out, *swapped; - int rc; - - rc = EventToXI2((InternalEvent*)in, (xEvent**)&out); - assert(rc == Success); - - test_values_XIDeviceChangedEvent(in, out, FALSE); - - swapped = calloc(1, sizeof(xEvent) + out->length * 4); - XI2EventSwap((xGenericEvent*)out, (xGenericEvent*)swapped); - test_values_XIDeviceChangedEvent(in, swapped, TRUE); - - free(out); - free(swapped); -} - -static void test_convert_XIDeviceChangedEvent(void) -{ - DeviceChangedEvent in; - int i; - - printf("Testing simple field values\n"); - memset(&in, 0, sizeof(in)); - in.header = ET_Internal; - in.type = ET_DeviceChanged; - in.length = sizeof(DeviceChangedEvent); - in.time = 0; - in.deviceid = 1; - in.sourceid = 2; - in.masterid = 3; - in.num_valuators = 4; - in.flags = DEVCHANGE_SLAVE_SWITCH | DEVCHANGE_POINTER_EVENT | DEVCHANGE_KEYBOARD_EVENT; - - for (i = 0; i < MAX_BUTTONS; i++) - in.buttons.names[i] = i + 10; - - in.keys.min_keycode = 8; - in.keys.max_keycode = 255; - - test_XIDeviceChangedEvent(&in); - - in.time = 1L; - test_XIDeviceChangedEvent(&in); - in.time = 1L << 8; - test_XIDeviceChangedEvent(&in); - in.time = 1L << 16; - test_XIDeviceChangedEvent(&in); - in.time = 1L << 24; - test_XIDeviceChangedEvent(&in); - in.time = ~0L; - test_XIDeviceChangedEvent(&in); - - in.deviceid = 1L; - test_XIDeviceChangedEvent(&in); - in.deviceid = 1L << 8; - test_XIDeviceChangedEvent(&in); - in.deviceid = ~0 & 0xFFFF; - test_XIDeviceChangedEvent(&in); - - in.sourceid = 1L; - test_XIDeviceChangedEvent(&in); - in.sourceid = 1L << 8; - test_XIDeviceChangedEvent(&in); - in.sourceid = ~0 & 0xFFFF; - test_XIDeviceChangedEvent(&in); - - in.masterid = 1L; - test_XIDeviceChangedEvent(&in); - in.masterid = 1L << 8; - test_XIDeviceChangedEvent(&in); - in.masterid = ~0 & 0xFFFF; - test_XIDeviceChangedEvent(&in); - - in.buttons.num_buttons = 0; - test_XIDeviceChangedEvent(&in); - - in.buttons.num_buttons = 1; - test_XIDeviceChangedEvent(&in); - - in.buttons.num_buttons = MAX_BUTTONS; - test_XIDeviceChangedEvent(&in); - - in.keys.min_keycode = 0; - in.keys.max_keycode = 0; - test_XIDeviceChangedEvent(&in); - - in.keys.max_keycode = 1 << 8; - test_XIDeviceChangedEvent(&in); - - in.keys.max_keycode = 0xFFFC; /* highest range, above that the length - field gives up */ - test_XIDeviceChangedEvent(&in); - - in.keys.min_keycode = 1 << 8; - in.keys.max_keycode = 1 << 8; - test_XIDeviceChangedEvent(&in); - - in.keys.min_keycode = 1 << 8; - in.keys.max_keycode = 0; - test_XIDeviceChangedEvent(&in); - - in.num_valuators = 0; - test_XIDeviceChangedEvent(&in); - - in.num_valuators = 1; - test_XIDeviceChangedEvent(&in); - - in.num_valuators = MAX_VALUATORS; - test_XIDeviceChangedEvent(&in); - - for (i = 0; i < MAX_VALUATORS; i++) - { - in.valuators[i].min = 0; - in.valuators[i].max = 0; - test_XIDeviceChangedEvent(&in); - - in.valuators[i].max = 1 << 8; - test_XIDeviceChangedEvent(&in); - in.valuators[i].max = 1 << 16; - test_XIDeviceChangedEvent(&in); - in.valuators[i].max = 1 << 24; - test_XIDeviceChangedEvent(&in); - in.valuators[i].max = abs(~0); - test_XIDeviceChangedEvent(&in); - - in.valuators[i].resolution = 1 << 8; - test_XIDeviceChangedEvent(&in); - in.valuators[i].resolution = 1 << 16; - test_XIDeviceChangedEvent(&in); - in.valuators[i].resolution = 1 << 24; - test_XIDeviceChangedEvent(&in); - in.valuators[i].resolution = abs(~0); - test_XIDeviceChangedEvent(&in); - - in.valuators[i].name = i; - test_XIDeviceChangedEvent(&in); - - in.valuators[i].mode = Relative; - test_XIDeviceChangedEvent(&in); - - in.valuators[i].mode = Absolute; - test_XIDeviceChangedEvent(&in); - } -} - -int main(int argc, char** argv) -{ - test_convert_XIRawEvent(); - test_convert_XIFocusEvent(); - test_convert_XIDeviceEvent(); - test_convert_XIDeviceChangedEvent(); - - return 0; -} +/**
+ * Copyright © 2009 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <stdint.h>
+
+#include "inputstr.h"
+#include "eventstr.h"
+#include "eventconvert.h"
+#include "exevents.h"
+#include <X11/extensions/XI2proto.h>
+
+static void test_values_XIRawEvent(RawDeviceEvent *in, xXIRawEvent *out,
+ BOOL swap)
+{
+ int i;
+ unsigned char *ptr;
+ FP3232 *value, *raw_value;
+ int nvals = 0;
+ int bits_set;
+ int len;
+
+ if (swap)
+ {
+ char n;
+
+ swaps(&out->sequenceNumber, n);
+ swapl(&out->length, n);
+ swaps(&out->evtype, n);
+ swaps(&out->deviceid, n);
+ swapl(&out->time, n);
+ swapl(&out->detail, n);
+ swaps(&out->valuators_len, n);
+ }
+
+
+ assert(out->type == GenericEvent);
+ assert(out->extension == 0); /* IReqCode defaults to 0 */
+ assert(out->evtype == GetXI2Type((InternalEvent*)in));
+ assert(out->time == in->time);
+ assert(out->detail == in->detail.button);
+ assert(out->deviceid == in->deviceid);
+ assert(out->valuators_len >= bytes_to_int32(bits_to_bytes(sizeof(in->valuators.mask))));
+ assert(out->flags == 0); /* FIXME: we don't set the flags yet */
+
+ ptr = (unsigned char*)&out[1];
+ bits_set = 0;
+
+ for (i = 0; out->valuators_len && i < sizeof(in->valuators.mask) * 8; i++)
+ {
+ if (i >= MAX_VALUATORS)
+ assert (!XIMaskIsSet(in->valuators.mask, i));
+ assert (XIMaskIsSet(in->valuators.mask, i) == XIMaskIsSet(ptr, i));
+ if (XIMaskIsSet(in->valuators.mask, i))
+ bits_set++;
+ }
+
+ /* length is len of valuator mask (in 4-byte units) + the number of bits
+ * set. Each bit set represents 2 8-byte values, hence the
+ * 'bits_set * 4' */
+ len = out->valuators_len + bits_set * 4;
+ assert(out->length == len);
+
+ nvals = 0;
+
+ for (i = 0; out->valuators_len && i < MAX_VALUATORS; i++)
+ {
+ assert (XIMaskIsSet(in->valuators.mask, i) == XIMaskIsSet(ptr, i));
+ if (XIMaskIsSet(in->valuators.mask, i))
+ {
+ FP3232 vi, vo;
+ value = (FP3232*)(((unsigned char*)&out[1]) + out->valuators_len * 4);
+ value += nvals;
+
+ vi.integral = in->valuators.data[i];
+ vi.frac = in->valuators.data_frac[i];
+
+ vo.integral = value->integral;
+ vo.frac = value->frac;
+ if (swap)
+ {
+ char n;
+ swapl(&vo.integral, n);
+ swapl(&vo.frac, n);
+ }
+
+ assert(vi.integral == vo.integral);
+ assert(vi.frac == vo.frac);
+
+ raw_value = value + bits_set;
+
+ vi.integral = in->valuators.data_raw[i];
+ vi.frac = in->valuators.data_raw_frac[i];
+
+ vo.integral = raw_value->integral;
+ vo.frac = raw_value->frac;
+ if (swap)
+ {
+ char n;
+ swapl(&vo.integral, n);
+ swapl(&vo.frac, n);
+ }
+
+ assert(vi.integral == vo.integral);
+ assert(vi.frac == vo.frac);
+
+ nvals++;
+ }
+ }
+}
+
+static void test_XIRawEvent(RawDeviceEvent *in)
+{
+ xXIRawEvent *out, *swapped;
+ int rc;
+
+ rc = EventToXI2((InternalEvent*)in, (xEvent**)&out);
+ assert(rc == Success);
+
+ test_values_XIRawEvent(in, out, FALSE);
+
+ swapped = calloc(1, sizeof(xEvent) + out->length * 4);
+ XI2EventSwap((xGenericEvent*)out, (xGenericEvent*)swapped);
+ test_values_XIRawEvent(in, swapped, TRUE);
+
+ free(out);
+ free(swapped);
+}
+
+static void test_convert_XIFocusEvent(void)
+{
+ xEvent *out;
+ DeviceEvent in;
+ int rc;
+
+ in.header = ET_Internal;
+ in.type = ET_Enter;
+ rc = EventToXI2((InternalEvent*)&in, &out);
+ assert(rc == Success);
+ assert(out == NULL);
+
+ in.header = ET_Internal;
+ in.type = ET_FocusIn;
+ rc = EventToXI2((InternalEvent*)&in, &out);
+ assert(rc == Success);
+ assert(out == NULL);
+
+ in.header = ET_Internal;
+ in.type = ET_FocusOut;
+ rc = EventToXI2((InternalEvent*)&in, &out);
+ assert(rc == BadImplementation);
+
+ in.header = ET_Internal;
+ in.type = ET_Leave;
+ rc = EventToXI2((InternalEvent*)&in, &out);
+ assert(rc == BadImplementation);
+}
+
+
+static void test_convert_XIRawEvent(void)
+{
+ RawDeviceEvent in;
+ int i;
+
+ memset(&in, 0, sizeof(in));
+
+ printf("Testing all event types\n");
+ in.header = ET_Internal;
+ in.type = ET_RawMotion;
+ test_XIRawEvent(&in);
+
+ in.header = ET_Internal;
+ in.type = ET_RawKeyPress;
+ test_XIRawEvent(&in);
+
+ in.header = ET_Internal;
+ in.type = ET_RawKeyRelease;
+ test_XIRawEvent(&in);
+
+ in.header = ET_Internal;
+ in.type = ET_RawButtonPress;
+ test_XIRawEvent(&in);
+
+ in.header = ET_Internal;
+ in.type = ET_RawButtonRelease;
+ test_XIRawEvent(&in);
+
+ printf("Testing details and other fields\n");
+ in.detail.button = 1L;
+ test_XIRawEvent(&in);
+ in.detail.button = 1L << 8;
+ test_XIRawEvent(&in);
+ in.detail.button = 1L << 16;
+ test_XIRawEvent(&in);
+ in.detail.button = 1L << 24;
+ test_XIRawEvent(&in);
+ in.detail.button = ~0L;
+ test_XIRawEvent(&in);
+
+ in.detail.button = 0;
+
+ in.time = 1L;
+ test_XIRawEvent(&in);
+ in.time = 1L << 8;
+ test_XIRawEvent(&in);
+ in.time = 1L << 16;
+ test_XIRawEvent(&in);
+ in.time = 1L << 24;
+ test_XIRawEvent(&in);
+ in.time = ~0L;
+ test_XIRawEvent(&in);
+
+ in.deviceid = 1;
+ test_XIRawEvent(&in);
+ in.deviceid = 1 << 8;
+ test_XIRawEvent(&in);
+ in.deviceid = ~0 & 0xFF;
+ test_XIRawEvent(&in);
+
+ printf("Testing valuator masks\n");
+ for (i = 0; i < MAX_VALUATORS; i++)
+ {
+ XISetMask(in.valuators.mask, i);
+ test_XIRawEvent(&in);
+ XIClearMask(in.valuators.mask, i);
+ }
+
+ for (i = 0; i < MAX_VALUATORS; i++)
+ {
+ XISetMask(in.valuators.mask, i);
+
+ in.valuators.data[i] = i;
+ in.valuators.data_raw[i] = i + 10;
+ in.valuators.data_frac[i] = i + 20;
+ in.valuators.data_raw_frac[i] = i + 30;
+ test_XIRawEvent(&in);
+ XIClearMask(in.valuators.mask, i);
+ }
+
+ for (i = 0; i < MAX_VALUATORS; i++)
+ {
+ XISetMask(in.valuators.mask, i);
+ test_XIRawEvent(&in);
+ }
+}
+
+static void test_values_XIDeviceEvent(DeviceEvent *in, xXIDeviceEvent *out,
+ BOOL swap)
+{
+ int buttons, valuators;
+ int i;
+ unsigned char *ptr;
+ uint32_t flagmask = 0;
+ FP3232 *values;
+
+ if (swap) {
+ char n;
+
+ swaps(&out->sequenceNumber, n);
+ swapl(&out->length, n);
+ swaps(&out->evtype, n);
+ swaps(&out->deviceid, n);
+ swaps(&out->sourceid, n);
+ swapl(&out->time, n);
+ swapl(&out->detail, n);
+ swapl(&out->root, n);
+ swapl(&out->event, n);
+ swapl(&out->child, n);
+ swapl(&out->root_x, n);
+ swapl(&out->root_y, n);
+ swapl(&out->event_x, n);
+ swapl(&out->event_y, n);
+ swaps(&out->buttons_len, n);
+ swaps(&out->valuators_len, n);
+ swapl(&out->mods.base_mods, n);
+ swapl(&out->mods.latched_mods, n);
+ swapl(&out->mods.locked_mods, n);
+ swapl(&out->mods.effective_mods, n);
+ swapl(&out->flags, n);
+ }
+
+ assert(out->extension == 0); /* IReqCode defaults to 0 */
+ assert(out->evtype == GetXI2Type((InternalEvent*)in));
+ assert(out->time == in->time);
+ assert(out->detail == in->detail.button);
+ assert(out->length >= 12);
+
+ assert(out->deviceid == in->deviceid);
+ assert(out->sourceid == in->sourceid);
+
+ switch (in->type) {
+ case ET_KeyPress:
+ flagmask = XIKeyRepeat;
+ break;
+ default:
+ flagmask = 0;
+ break;
+ }
+ assert((out->flags & ~flagmask) == 0);
+
+ assert(out->root == in->root);
+ assert(out->event == None); /* set in FixUpEventFromWindow */
+ assert(out->child == None); /* set in FixUpEventFromWindow */
+
+ assert(out->mods.base_mods == in->mods.base);
+ assert(out->mods.latched_mods == in->mods.latched);
+ assert(out->mods.locked_mods == in->mods.locked);
+ assert(out->mods.effective_mods == in->mods.effective);
+
+ assert(out->group.base_group == in->group.base);
+ assert(out->group.latched_group == in->group.latched);
+ assert(out->group.locked_group == in->group.locked);
+ assert(out->group.effective_group == in->group.effective);
+
+ assert(out->event_x == 0); /* set in FixUpEventFromWindow */
+ assert(out->event_y == 0); /* set in FixUpEventFromWindow */
+
+ assert(out->root_x == FP1616(in->root_x, in->root_x_frac));
+ assert(out->root_y == FP1616(in->root_y, in->root_y_frac));
+
+ buttons = 0;
+ for (i = 0; i < bits_to_bytes(sizeof(in->buttons)); i++)
+ {
+ if (XIMaskIsSet(in->buttons, i))
+ {
+ assert(out->buttons_len >= bytes_to_int32(bits_to_bytes(i)));
+ buttons++;
+ }
+ }
+
+ ptr = (unsigned char*)&out[1];
+ for (i = 0; i < sizeof(in->buttons) * 8; i++)
+ assert(XIMaskIsSet(in->buttons, i) == XIMaskIsSet(ptr, i));
+
+
+ valuators = 0;
+ for (i = 0; i < MAX_VALUATORS; i++)
+ if (XIMaskIsSet(in->valuators.mask, i))
+ valuators++;
+
+ assert(out->valuators_len >= bytes_to_int32(bits_to_bytes(valuators)));
+
+ ptr += out->buttons_len * 4;
+ values = (FP3232*)(ptr + out->valuators_len * 4);
+ for (i = 0; i < sizeof(in->valuators.mask) * 8 ||
+ i < (out->valuators_len * 4) * 8; i++)
+ {
+ if (i >= MAX_VALUATORS)
+ assert(!XIMaskIsSet(in->valuators.mask, i) && !XIMaskIsSet(ptr, i));
+ else if (i > sizeof(in->valuators.mask) * 8)
+ assert(!XIMaskIsSet(ptr, i));
+ else if (i > out->valuators_len * 4 * 8)
+ assert(!XIMaskIsSet(in->valuators.mask, i));
+ else {
+ assert(XIMaskIsSet(in->valuators.mask, i) ==
+ XIMaskIsSet(ptr, i));
+
+ if (XIMaskIsSet(ptr, i))
+ {
+ FP3232 vi, vo;
+
+ vi.integral = in->valuators.data[i];
+ vi.frac = in->valuators.data_frac[i];
+
+ vo = *values;
+
+ if (swap)
+ {
+ char n;
+ swapl(&vo.integral, n);
+ swapl(&vo.frac, n);
+ }
+
+
+ assert(vi.integral == vo.integral);
+ assert(vi.frac == vo.frac);
+ values++;
+ }
+ }
+ }
+}
+
+static void test_XIDeviceEvent(DeviceEvent *in)
+{
+ xXIDeviceEvent *out, *swapped;
+ int rc;
+
+ rc = EventToXI2((InternalEvent*)in, (xEvent**)&out);
+ assert(rc == Success);
+
+ test_values_XIDeviceEvent(in, out, FALSE);
+
+ swapped = calloc(1, sizeof(xEvent) + out->length * 4);
+ XI2EventSwap((xGenericEvent*)out, (xGenericEvent*)swapped);
+ test_values_XIDeviceEvent(in, swapped, TRUE);
+
+ free(out);
+ free(swapped);
+}
+
+static void test_convert_XIDeviceEvent(void)
+{
+ DeviceEvent in;
+ int i;
+
+ memset(&in, 0, sizeof(in));
+
+ printf("Testing simple field values\n");
+ in.header = ET_Internal;
+ in.type = ET_Motion;
+ in.length = sizeof(DeviceEvent);
+ in.time = 0;
+ in.deviceid = 1;
+ in.sourceid = 2;
+ in.root = 3;
+ in.root_x = 4;
+ in.root_x_frac = 5;
+ in.root_y = 6;
+ in.root_y_frac = 7;
+ in.detail.button = 8;
+ in.mods.base = 9;
+ in.mods.latched = 10;
+ in.mods.locked = 11;
+ in.mods.effective = 11;
+ in.group.base = 12;
+ in.group.latched = 13;
+ in.group.locked = 14;
+ in.group.effective = 15;
+
+ test_XIDeviceEvent(&in);
+
+ printf("Testing field ranges\n");
+ /* 32 bit */
+ in.detail.button = 1L;
+ test_XIDeviceEvent(&in);
+ in.detail.button = 1L << 8;
+ test_XIDeviceEvent(&in);
+ in.detail.button = 1L << 16;
+ test_XIDeviceEvent(&in);
+ in.detail.button = 1L << 24;
+ test_XIDeviceEvent(&in);
+ in.detail.button = ~0L;
+ test_XIDeviceEvent(&in);
+
+ /* 32 bit */
+ in.time = 1L;
+ test_XIDeviceEvent(&in);
+ in.time = 1L << 8;
+ test_XIDeviceEvent(&in);
+ in.time = 1L << 16;
+ test_XIDeviceEvent(&in);
+ in.time = 1L << 24;
+ test_XIDeviceEvent(&in);
+ in.time = ~0L;
+ test_XIDeviceEvent(&in);
+
+ /* 16 bit */
+ in.deviceid = 1;
+ test_XIDeviceEvent(&in);
+ in.deviceid = 1 << 8;
+ test_XIDeviceEvent(&in);
+ in.deviceid = ~0 & 0xFF;
+ test_XIDeviceEvent(&in);
+
+ /* 16 bit */
+ in.sourceid = 1;
+ test_XIDeviceEvent(&in);
+ in.deviceid = 1 << 8;
+ test_XIDeviceEvent(&in);
+ in.deviceid = ~0 & 0xFF;
+ test_XIDeviceEvent(&in);
+
+ /* 32 bit */
+ in.root = 1L;
+ test_XIDeviceEvent(&in);
+ in.root = 1L << 8;
+ test_XIDeviceEvent(&in);
+ in.root = 1L << 16;
+ test_XIDeviceEvent(&in);
+ in.root = 1L << 24;
+ test_XIDeviceEvent(&in);
+ in.root = ~0L;
+ test_XIDeviceEvent(&in);
+
+ /* 16 bit */
+ in.root_x = 1;
+ test_XIDeviceEvent(&in);
+ in.root_x = 1 << 8;
+ test_XIDeviceEvent(&in);
+ in.root_x = ~0 & 0xFF;
+ test_XIDeviceEvent(&in);
+
+ in.root_x_frac = 1;
+ test_XIDeviceEvent(&in);
+ in.root_x_frac = 1 << 8;
+ test_XIDeviceEvent(&in);
+ in.root_x_frac = ~0 & 0xFF;
+ test_XIDeviceEvent(&in);
+
+ in.root_y = 1;
+ test_XIDeviceEvent(&in);
+ in.root_y = 1 << 8;
+ test_XIDeviceEvent(&in);
+ in.root_y = ~0 & 0xFF;
+ test_XIDeviceEvent(&in);
+
+ in.root_y_frac = 1;
+ test_XIDeviceEvent(&in);
+ in.root_y_frac = 1 << 8;
+ test_XIDeviceEvent(&in);
+ in.root_y_frac = ~0 & 0xFF;
+ test_XIDeviceEvent(&in);
+
+ /* 32 bit */
+ in.mods.base = 1L;
+ test_XIDeviceEvent(&in);
+ in.mods.base = 1L << 8;
+ test_XIDeviceEvent(&in);
+ in.mods.base = 1L << 16;
+ test_XIDeviceEvent(&in);
+ in.mods.base = 1L << 24;
+ test_XIDeviceEvent(&in);
+ in.mods.base = ~0L;
+ test_XIDeviceEvent(&in);
+
+ in.mods.latched = 1L;
+ test_XIDeviceEvent(&in);
+ in.mods.latched = 1L << 8;
+ test_XIDeviceEvent(&in);
+ in.mods.latched = 1L << 16;
+ test_XIDeviceEvent(&in);
+ in.mods.latched = 1L << 24;
+ test_XIDeviceEvent(&in);
+ in.mods.latched = ~0L;
+ test_XIDeviceEvent(&in);
+
+ in.mods.locked = 1L;
+ test_XIDeviceEvent(&in);
+ in.mods.locked = 1L << 8;
+ test_XIDeviceEvent(&in);
+ in.mods.locked = 1L << 16;
+ test_XIDeviceEvent(&in);
+ in.mods.locked = 1L << 24;
+ test_XIDeviceEvent(&in);
+ in.mods.locked = ~0L;
+ test_XIDeviceEvent(&in);
+
+ in.mods.effective = 1L;
+ test_XIDeviceEvent(&in);
+ in.mods.effective = 1L << 8;
+ test_XIDeviceEvent(&in);
+ in.mods.effective = 1L << 16;
+ test_XIDeviceEvent(&in);
+ in.mods.effective = 1L << 24;
+ test_XIDeviceEvent(&in);
+ in.mods.effective = ~0L;
+ test_XIDeviceEvent(&in);
+
+ /* 8 bit */
+ in.group.base = 1;
+ test_XIDeviceEvent(&in);
+ in.group.base = ~0 & 0xFF;
+ test_XIDeviceEvent(&in);
+
+ in.group.latched = 1;
+ test_XIDeviceEvent(&in);
+ in.group.latched = ~0 & 0xFF;
+ test_XIDeviceEvent(&in);
+
+ in.group.locked = 1;
+ test_XIDeviceEvent(&in);
+ in.group.locked = ~0 & 0xFF;
+ test_XIDeviceEvent(&in);
+
+ in.mods.effective = 1;
+ test_XIDeviceEvent(&in);
+ in.mods.effective = ~0 & 0xFF;
+ test_XIDeviceEvent(&in);
+
+ printf("Testing button masks\n");
+ for (i = 0; i < sizeof(in.buttons) * 8; i++)
+ {
+ XISetMask(in.buttons, i);
+ test_XIDeviceEvent(&in);
+ XIClearMask(in.buttons, i);
+ }
+
+ for (i = 0; i < sizeof(in.buttons) * 8; i++)
+ {
+ XISetMask(in.buttons, i);
+ test_XIDeviceEvent(&in);
+ }
+
+ printf("Testing valuator masks\n");
+ for (i = 0; i < MAX_VALUATORS; i++)
+ {
+ XISetMask(in.valuators.mask, i);
+ test_XIDeviceEvent(&in);
+ XIClearMask(in.valuators.mask, i);
+ }
+
+ for (i = 0; i < MAX_VALUATORS; i++)
+ {
+ XISetMask(in.valuators.mask, i);
+
+ in.valuators.data[i] = i;
+ in.valuators.data_frac[i] = i + 20;
+ test_XIDeviceEvent(&in);
+ XIClearMask(in.valuators.mask, i);
+ }
+
+ for (i = 0; i < MAX_VALUATORS; i++)
+ {
+ XISetMask(in.valuators.mask, i);
+ test_XIDeviceEvent(&in);
+ }
+}
+
+static void test_values_XIDeviceChangedEvent(DeviceChangedEvent *in,
+ xXIDeviceChangedEvent *out,
+ BOOL swap)
+{
+ int i, j;
+ unsigned char *ptr;
+
+ if (swap)
+ {
+ char n;
+
+ swaps(&out->sequenceNumber, n);
+ swapl(&out->length, n);
+ swaps(&out->evtype, n);
+ swaps(&out->deviceid, n);
+ swaps(&out->sourceid, n);
+ swapl(&out->time, n);
+ swaps(&out->num_classes, n);
+ }
+
+ assert(out->type == GenericEvent);
+ assert(out->extension == 0); /* IReqCode defaults to 0 */
+ assert(out->evtype == GetXI2Type((InternalEvent*)in));
+ assert(out->time == in->time);
+ assert(out->deviceid == in->deviceid);
+ assert(out->sourceid == in->sourceid);
+
+ ptr = (unsigned char*)&out[1];
+ for (i = 0; i < out->num_classes; i++)
+ {
+ xXIAnyInfo* any = (xXIAnyInfo*)ptr;
+
+ if (swap)
+ {
+ char n;
+ swaps(&any->length, n);
+ swaps(&any->type, n);
+ swaps(&any->sourceid, n);
+ }
+
+ switch(any->type)
+ {
+ case XIButtonClass:
+ {
+ xXIButtonInfo *b = (xXIButtonInfo*)any;
+ Atom *names;
+
+ if (swap)
+ {
+ char n;
+ swaps(&b->num_buttons, n);
+ }
+
+ assert(b->length ==
+ bytes_to_int32(sizeof(xXIButtonInfo)) +
+ bytes_to_int32(bits_to_bytes(b->num_buttons)) +
+ b->num_buttons);
+ assert(b->num_buttons == in->buttons.num_buttons);
+
+ names = (Atom*)((char*)&b[1] +
+ pad_to_int32(bits_to_bytes(b->num_buttons)));
+ for (j = 0; j < b->num_buttons; j++)
+ {
+ if (swap)
+ {
+ char n;
+ swapl(&names[j], n);
+ }
+ assert(names[j] == in->buttons.names[j]);
+ }
+ }
+ break;
+ case XIKeyClass:
+ {
+ xXIKeyInfo *k = (xXIKeyInfo*)any;
+ uint32_t *kc;
+
+ if (swap)
+ {
+ char n;
+ swaps(&k->num_keycodes, n);
+ }
+
+ assert(k->length ==
+ bytes_to_int32(sizeof(xXIKeyInfo)) +
+ k->num_keycodes);
+ assert(k->num_keycodes == in->keys.max_keycode -
+ in->keys.min_keycode + 1);
+
+ kc = (uint32_t*)&k[1];
+ for (j = 0; j < k->num_keycodes; j++)
+ {
+ if (swap)
+ {
+ char n;
+ swapl(&kc[j], n);
+ }
+ assert(kc[j] >= in->keys.min_keycode);
+ assert(kc[j] <= in->keys.max_keycode);
+ }
+ }
+ break;
+ case XIValuatorClass:
+ {
+ xXIValuatorInfo *v = (xXIValuatorInfo*)any;
+ assert(v->length ==
+ bytes_to_int32(sizeof(xXIValuatorInfo)));
+
+ }
+ break;
+ default:
+ printf("Invalid class type.\n\n");
+ assert(1);
+ break;
+ }
+
+ ptr += any->length * 4;
+ }
+
+}
+
+static void test_XIDeviceChangedEvent(DeviceChangedEvent *in)
+{
+ xXIDeviceChangedEvent *out, *swapped;
+ int rc;
+
+ rc = EventToXI2((InternalEvent*)in, (xEvent**)&out);
+ assert(rc == Success);
+
+ test_values_XIDeviceChangedEvent(in, out, FALSE);
+
+ swapped = calloc(1, sizeof(xEvent) + out->length * 4);
+ XI2EventSwap((xGenericEvent*)out, (xGenericEvent*)swapped);
+ test_values_XIDeviceChangedEvent(in, swapped, TRUE);
+
+ free(out);
+ free(swapped);
+}
+
+static void test_convert_XIDeviceChangedEvent(void)
+{
+ DeviceChangedEvent in;
+ int i;
+
+ printf("Testing simple field values\n");
+ memset(&in, 0, sizeof(in));
+ in.header = ET_Internal;
+ in.type = ET_DeviceChanged;
+ in.length = sizeof(DeviceChangedEvent);
+ in.time = 0;
+ in.deviceid = 1;
+ in.sourceid = 2;
+ in.masterid = 3;
+ in.num_valuators = 4;
+ in.flags = DEVCHANGE_SLAVE_SWITCH | DEVCHANGE_POINTER_EVENT | DEVCHANGE_KEYBOARD_EVENT;
+
+ for (i = 0; i < MAX_BUTTONS; i++)
+ in.buttons.names[i] = i + 10;
+
+ in.keys.min_keycode = 8;
+ in.keys.max_keycode = 255;
+
+ test_XIDeviceChangedEvent(&in);
+
+ in.time = 1L;
+ test_XIDeviceChangedEvent(&in);
+ in.time = 1L << 8;
+ test_XIDeviceChangedEvent(&in);
+ in.time = 1L << 16;
+ test_XIDeviceChangedEvent(&in);
+ in.time = 1L << 24;
+ test_XIDeviceChangedEvent(&in);
+ in.time = ~0L;
+ test_XIDeviceChangedEvent(&in);
+
+ in.deviceid = 1L;
+ test_XIDeviceChangedEvent(&in);
+ in.deviceid = 1L << 8;
+ test_XIDeviceChangedEvent(&in);
+ in.deviceid = ~0 & 0xFFFF;
+ test_XIDeviceChangedEvent(&in);
+
+ in.sourceid = 1L;
+ test_XIDeviceChangedEvent(&in);
+ in.sourceid = 1L << 8;
+ test_XIDeviceChangedEvent(&in);
+ in.sourceid = ~0 & 0xFFFF;
+ test_XIDeviceChangedEvent(&in);
+
+ in.masterid = 1L;
+ test_XIDeviceChangedEvent(&in);
+ in.masterid = 1L << 8;
+ test_XIDeviceChangedEvent(&in);
+ in.masterid = ~0 & 0xFFFF;
+ test_XIDeviceChangedEvent(&in);
+
+ in.buttons.num_buttons = 0;
+ test_XIDeviceChangedEvent(&in);
+
+ in.buttons.num_buttons = 1;
+ test_XIDeviceChangedEvent(&in);
+
+ in.buttons.num_buttons = MAX_BUTTONS;
+ test_XIDeviceChangedEvent(&in);
+
+ in.keys.min_keycode = 0;
+ in.keys.max_keycode = 0;
+ test_XIDeviceChangedEvent(&in);
+
+ in.keys.max_keycode = 1 << 8;
+ test_XIDeviceChangedEvent(&in);
+
+ in.keys.max_keycode = 0xFFFC; /* highest range, above that the length
+ field gives up */
+ test_XIDeviceChangedEvent(&in);
+
+ in.keys.min_keycode = 1 << 8;
+ in.keys.max_keycode = 1 << 8;
+ test_XIDeviceChangedEvent(&in);
+
+ in.keys.min_keycode = 1 << 8;
+ in.keys.max_keycode = 0;
+ test_XIDeviceChangedEvent(&in);
+
+ in.num_valuators = 0;
+ test_XIDeviceChangedEvent(&in);
+
+ in.num_valuators = 1;
+ test_XIDeviceChangedEvent(&in);
+
+ in.num_valuators = MAX_VALUATORS;
+ test_XIDeviceChangedEvent(&in);
+
+ for (i = 0; i < MAX_VALUATORS; i++)
+ {
+ in.valuators[i].min = 0;
+ in.valuators[i].max = 0;
+ test_XIDeviceChangedEvent(&in);
+
+ in.valuators[i].max = 1 << 8;
+ test_XIDeviceChangedEvent(&in);
+ in.valuators[i].max = 1 << 16;
+ test_XIDeviceChangedEvent(&in);
+ in.valuators[i].max = 1 << 24;
+ test_XIDeviceChangedEvent(&in);
+ in.valuators[i].max = abs(~0);
+ test_XIDeviceChangedEvent(&in);
+
+ in.valuators[i].resolution = 1 << 8;
+ test_XIDeviceChangedEvent(&in);
+ in.valuators[i].resolution = 1 << 16;
+ test_XIDeviceChangedEvent(&in);
+ in.valuators[i].resolution = 1 << 24;
+ test_XIDeviceChangedEvent(&in);
+ in.valuators[i].resolution = abs(~0);
+ test_XIDeviceChangedEvent(&in);
+
+ in.valuators[i].name = i;
+ test_XIDeviceChangedEvent(&in);
+
+ in.valuators[i].mode = Relative;
+ test_XIDeviceChangedEvent(&in);
+
+ in.valuators[i].mode = Absolute;
+ test_XIDeviceChangedEvent(&in);
+ }
+}
+
+int main(int argc, char** argv)
+{
+ test_convert_XIRawEvent();
+ test_convert_XIFocusEvent();
+ test_convert_XIDeviceEvent();
+ test_convert_XIDeviceChangedEvent();
+
+ return 0;
+}
diff --git a/xorg-server/test/xi2/protocol-xigetclientpointer.c b/xorg-server/test/xi2/protocol-xigetclientpointer.c index 5e45e7b32..39fae8eaa 100644 --- a/xorg-server/test/xi2/protocol-xigetclientpointer.c +++ b/xorg-server/test/xi2/protocol-xigetclientpointer.c @@ -1,162 +1,162 @@ -/** - * Copyright © 2009 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include <dix-config.h> -#endif - -/* - * Protocol testing for XIGetClientPointer request. - */ -#include <stdint.h> -#include <X11/X.h> -#include <X11/Xproto.h> -#include <X11/extensions/XI2proto.h> -#include "inputstr.h" -#include "windowstr.h" -#include "scrnintstr.h" -#include "xigetclientpointer.h" -#include "exevents.h" - -#include "protocol-common.h" - -struct { - int cp_is_set; - DeviceIntPtr dev; - int win; -} test_data; - -static ClientRec client_window; -static ClientRec client_request; - -int __wrap_dixLookupClient(ClientPtr *pClient, XID rid, ClientPtr client, Mask access) -{ - if (rid == ROOT_WINDOW_ID) - return BadWindow; - - if (rid == CLIENT_WINDOW_ID) - { - *pClient = &client_window; - return Success; - } - - return __real_dixLookupClient(pClient, rid, client, access); -} - - -static void reply_XIGetClientPointer(ClientPtr client, int len, char *data, void *userdata) -{ - xXIGetClientPointerReply *rep = (xXIGetClientPointerReply*)data; - - if (client->swapped) - { - char n; - swapl(&rep->length, n); - swaps(&rep->sequenceNumber, n); - swaps(&rep->deviceid, n); - } - - reply_check_defaults(rep, len, XIGetClientPointer); - - assert(rep->set == test_data.cp_is_set); - if (rep->set) - assert(rep->deviceid == test_data.dev->id); -} - -static void request_XIGetClientPointer(ClientPtr client, xXIGetClientPointerReq* req, int error) -{ - char n; - int rc; - - test_data.win = req->win; - - rc = ProcXIGetClientPointer(&client_request); - assert(rc == error); - - if (rc == BadWindow) - assert(client_request.errorValue == req->win); - - client_request.swapped = TRUE; - swapl(&req->win, n); - swaps(&req->length, n); - rc = SProcXIGetClientPointer(&client_request); - assert(rc == error); - - if (rc == BadWindow) - assert(client_request.errorValue == req->win); - -} - -static void test_XIGetClientPointer(void) -{ - xXIGetClientPointerReq request; - - request_init(&request, XIGetClientPointer); - - request.win = CLIENT_WINDOW_ID; - - - reply_handler = reply_XIGetClientPointer; - - client_request = init_client(request.length, &request); - - printf("Testing invalid window\n"); - request.win = INVALID_WINDOW_ID; - request_XIGetClientPointer(&client_request, &request, BadWindow); - - test_data.cp_is_set = FALSE; - - printf("Testing window None, unset ClientPointer.\n"); - request.win = None; - request_XIGetClientPointer(&client_request, &request, Success); - - printf("Testing valid window, unset ClientPointer.\n"); - request.win = CLIENT_WINDOW_ID; - request_XIGetClientPointer(&client_request, &request, Success); - - printf("Testing valid window, set ClientPointer.\n"); - client_window.clientPtr = devices.vcp; - test_data.dev = devices.vcp; - test_data.cp_is_set = TRUE; - request.win = CLIENT_WINDOW_ID; - request_XIGetClientPointer(&client_request, &request, Success); - - client_window.clientPtr = NULL; - - printf("Testing window None, set ClientPointer.\n"); - client_request.clientPtr = devices.vcp; - test_data.dev = devices.vcp; - test_data.cp_is_set = TRUE; - request.win = None; - request_XIGetClientPointer(&client_request, &request, Success); -} - -int main(int argc, char** argv) -{ - init_simple(); - client_window = init_client(0, NULL); - - test_XIGetClientPointer(); - - return 0; -} +/**
+ * Copyright © 2009 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+/*
+ * Protocol testing for XIGetClientPointer request.
+ */
+#include <stdint.h>
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include <X11/extensions/XI2proto.h>
+#include "inputstr.h"
+#include "windowstr.h"
+#include "scrnintstr.h"
+#include "xigetclientpointer.h"
+#include "exevents.h"
+
+#include "protocol-common.h"
+
+struct {
+ int cp_is_set;
+ DeviceIntPtr dev;
+ int win;
+} test_data;
+
+static ClientRec client_window;
+static ClientRec client_request;
+
+int __wrap_dixLookupClient(ClientPtr *pClient, XID rid, ClientPtr client, Mask access)
+{
+ if (rid == ROOT_WINDOW_ID)
+ return BadWindow;
+
+ if (rid == CLIENT_WINDOW_ID)
+ {
+ *pClient = &client_window;
+ return Success;
+ }
+
+ return __real_dixLookupClient(pClient, rid, client, access);
+}
+
+
+static void reply_XIGetClientPointer(ClientPtr client, int len, char *data, void *userdata)
+{
+ xXIGetClientPointerReply *rep = (xXIGetClientPointerReply*)data;
+
+ if (client->swapped)
+ {
+ char n;
+ swapl(&rep->length, n);
+ swaps(&rep->sequenceNumber, n);
+ swaps(&rep->deviceid, n);
+ }
+
+ reply_check_defaults(rep, len, XIGetClientPointer);
+
+ assert(rep->set == test_data.cp_is_set);
+ if (rep->set)
+ assert(rep->deviceid == test_data.dev->id);
+}
+
+static void request_XIGetClientPointer(ClientPtr client, xXIGetClientPointerReq* req, int error)
+{
+ char n;
+ int rc;
+
+ test_data.win = req->win;
+
+ rc = ProcXIGetClientPointer(&client_request);
+ assert(rc == error);
+
+ if (rc == BadWindow)
+ assert(client_request.errorValue == req->win);
+
+ client_request.swapped = TRUE;
+ swapl(&req->win, n);
+ swaps(&req->length, n);
+ rc = SProcXIGetClientPointer(&client_request);
+ assert(rc == error);
+
+ if (rc == BadWindow)
+ assert(client_request.errorValue == req->win);
+
+}
+
+static void test_XIGetClientPointer(void)
+{
+ xXIGetClientPointerReq request;
+
+ request_init(&request, XIGetClientPointer);
+
+ request.win = CLIENT_WINDOW_ID;
+
+
+ reply_handler = reply_XIGetClientPointer;
+
+ client_request = init_client(request.length, &request);
+
+ printf("Testing invalid window\n");
+ request.win = INVALID_WINDOW_ID;
+ request_XIGetClientPointer(&client_request, &request, BadWindow);
+
+ test_data.cp_is_set = FALSE;
+
+ printf("Testing window None, unset ClientPointer.\n");
+ request.win = None;
+ request_XIGetClientPointer(&client_request, &request, Success);
+
+ printf("Testing valid window, unset ClientPointer.\n");
+ request.win = CLIENT_WINDOW_ID;
+ request_XIGetClientPointer(&client_request, &request, Success);
+
+ printf("Testing valid window, set ClientPointer.\n");
+ client_window.clientPtr = devices.vcp;
+ test_data.dev = devices.vcp;
+ test_data.cp_is_set = TRUE;
+ request.win = CLIENT_WINDOW_ID;
+ request_XIGetClientPointer(&client_request, &request, Success);
+
+ client_window.clientPtr = NULL;
+
+ printf("Testing window None, set ClientPointer.\n");
+ client_request.clientPtr = devices.vcp;
+ test_data.dev = devices.vcp;
+ test_data.cp_is_set = TRUE;
+ request.win = None;
+ request_XIGetClientPointer(&client_request, &request, Success);
+}
+
+int main(int argc, char** argv)
+{
+ init_simple();
+ client_window = init_client(0, NULL);
+
+ test_XIGetClientPointer();
+
+ return 0;
+}
diff --git a/xorg-server/test/xi2/protocol-xigetselectedevents.c b/xorg-server/test/xi2/protocol-xigetselectedevents.c index 55de77356..b85f57aaf 100644 --- a/xorg-server/test/xi2/protocol-xigetselectedevents.c +++ b/xorg-server/test/xi2/protocol-xigetselectedevents.c @@ -1,237 +1,237 @@ -/** - * Copyright © 2009 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include <dix-config.h> -#endif - -/* - * Protocol testing for XIGetSelectedEvents request. - * - * Tests include: - * BadWindow on wrong window. - * Zero-length masks if no masks are set. - * Valid masks for valid devices. - * Masks set on non-existent devices are not returned. - * - * Note that this test is not connected to the XISelectEvents request. - */ -#include <stdint.h> -#include <X11/X.h> -#include <X11/Xproto.h> -#include <X11/extensions/XI2proto.h> -#include "inputstr.h" -#include "windowstr.h" -#include "extinit.h" /* for XInputExtensionInit */ -#include "scrnintstr.h" -#include "xiselectev.h" -#include "exevents.h" - -#include "protocol-common.h" - -static void reply_XIGetSelectedEvents(ClientPtr client, int len, char *data, void *userdata); -static void reply_XIGetSelectedEvents_data(ClientPtr client, int len, char *data, void *userdata); - - -struct { - int num_masks_expected; - unsigned char mask[MAXDEVICES][XI2LASTEVENT]; /* intentionally bigger */ - int mask_len; -} test_data; - -/* dixLookupWindow requires a lot of setup not necessary for this test. - * Simple wrapper that returns either one of the fake root window or the - * fake client window. If the requested ID is neither of those wanted, - * return whatever the real dixLookupWindow does. - */ -int __wrap_dixLookupWindow(WindowPtr *win, XID id, ClientPtr client, Mask access) -{ - if (id == root.drawable.id) - { - *win = &root; - return Success; - } else if (id == window.drawable.id) - { - *win = &window; - return Success; - } - - return __real_dixLookupWindow(win, id, client, access); -} - -/* AddResource is called from XISetSEventMask, we don't need this */ -Bool __wrap_AddResource(XID id, RESTYPE type, pointer value) -{ - return TRUE; -} - -static void reply_XIGetSelectedEvents(ClientPtr client, int len, char *data, void *userdata) -{ - xXIGetSelectedEventsReply *rep = (xXIGetSelectedEventsReply*)data; - - if (client->swapped) - { - char n; - swapl(&rep->length, n); - swaps(&rep->sequenceNumber, n); - swaps(&rep->num_masks, n); - } - - reply_check_defaults(rep, len, XIGetSelectedEvents); - - assert(rep->num_masks == test_data.num_masks_expected); - - reply_handler = reply_XIGetSelectedEvents_data; -} - -static void reply_XIGetSelectedEvents_data(ClientPtr client, int len, char *data, void *userdata) -{ - int i; - xXIEventMask *mask; - unsigned char *bitmask; - - mask = (xXIEventMask*)data; - for (i = 0; i < test_data.num_masks_expected; i++) - { - if (client->swapped) - { - char n; - swaps(&mask->deviceid, n); - swaps(&mask->mask_len, n); - } - - assert(mask->deviceid < 6); - assert(mask->mask_len <= (((XI2LASTEVENT + 8)/8) + 3)/4) ; - - bitmask = (unsigned char*)&mask[1]; - assert(memcmp(bitmask, - test_data.mask[mask->deviceid], - mask->mask_len * 4) == 0); - - mask = (xXIEventMask*)((char*)mask + mask->mask_len * 4 + sizeof(xXIEventMask)); - } - - -} - -static void request_XIGetSelectedEvents(xXIGetSelectedEventsReq* req, int error) -{ - char n; - int rc; - ClientRec client; - client = init_client(req->length, req); - - reply_handler = reply_XIGetSelectedEvents; - - rc = ProcXIGetSelectedEvents(&client); - assert(rc == error); - - reply_handler = reply_XIGetSelectedEvents; - client.swapped = TRUE; - swapl(&req->win, n); - swaps(&req->length, n); - rc = SProcXIGetSelectedEvents(&client); - assert(rc == error); -} - -static void test_XIGetSelectedEvents(void) -{ - int i, j; - xXIGetSelectedEventsReq request; - ClientRec client = init_client(0, NULL); - unsigned char *mask; - DeviceIntRec dev; - - request_init(&request, XIGetSelectedEvents); - - printf("Testing for BadWindow on invalid window.\n"); - request.win = None; - request_XIGetSelectedEvents(&request, BadWindow); - - printf("Testing for zero-length (unset) masks.\n"); - /* No masks set yet */ - test_data.num_masks_expected = 0; - request.win = ROOT_WINDOW_ID; - request_XIGetSelectedEvents(&request, Success); - - request.win = CLIENT_WINDOW_ID; - request_XIGetSelectedEvents(&request, Success); - - memset(test_data.mask, 0, - sizeof(test_data.mask)); - - printf("Testing for valid masks\n"); - memset(&dev, 0, sizeof(dev)); /* dev->id is enough for XISetEventMask */ - request.win = ROOT_WINDOW_ID; - - /* devices 6 - MAXDEVICES don't exist, they mustn't be included in the - * reply even if a mask is set */ - for (j = 0; j < MAXDEVICES; j++) - { - test_data.num_masks_expected = min(j + 1, devices.num_devices + 2); - dev.id = j; - mask = test_data.mask[j]; - /* bits one-by-one */ - for (i = 0; i < XI2LASTEVENT; i++) - { - SetBit(mask, i); - XISetEventMask(&dev, &root, &client, (i + 8)/8, mask); - request_XIGetSelectedEvents(&request, Success); - ClearBit(mask, i); - } - - /* all valid mask bits */ - for (i = 0; i < XI2LASTEVENT; i++) - { - SetBit(mask, i); - XISetEventMask(&dev, &root, &client, (i + 8)/8, mask); - request_XIGetSelectedEvents(&request, Success); - } - } - - printf("Testing removing all masks\n"); - /* Unset all masks one-by-one */ - for (j = MAXDEVICES - 1; j >= 0; j--) - { - if (j < devices.num_devices + 2) - test_data.num_masks_expected--; - - mask = test_data.mask[j]; - memset(mask, 0, XI2LASTEVENT); - - dev.id = j; - XISetEventMask(&dev, &root, &client, 0, NULL); - - request_XIGetSelectedEvents(&request, Success); - } -} - -int main(int argc, char** argv) -{ - init_simple(); - - test_XIGetSelectedEvents(); - - return 0; -} - +/**
+ * Copyright © 2009 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+/*
+ * Protocol testing for XIGetSelectedEvents request.
+ *
+ * Tests include:
+ * BadWindow on wrong window.
+ * Zero-length masks if no masks are set.
+ * Valid masks for valid devices.
+ * Masks set on non-existent devices are not returned.
+ *
+ * Note that this test is not connected to the XISelectEvents request.
+ */
+#include <stdint.h>
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include <X11/extensions/XI2proto.h>
+#include "inputstr.h"
+#include "windowstr.h"
+#include "extinit.h" /* for XInputExtensionInit */
+#include "scrnintstr.h"
+#include "xiselectev.h"
+#include "exevents.h"
+
+#include "protocol-common.h"
+
+static void reply_XIGetSelectedEvents(ClientPtr client, int len, char *data, void *userdata);
+static void reply_XIGetSelectedEvents_data(ClientPtr client, int len, char *data, void *userdata);
+
+
+struct {
+ int num_masks_expected;
+ unsigned char mask[MAXDEVICES][XI2LASTEVENT]; /* intentionally bigger */
+ int mask_len;
+} test_data;
+
+/* dixLookupWindow requires a lot of setup not necessary for this test.
+ * Simple wrapper that returns either one of the fake root window or the
+ * fake client window. If the requested ID is neither of those wanted,
+ * return whatever the real dixLookupWindow does.
+ */
+int __wrap_dixLookupWindow(WindowPtr *win, XID id, ClientPtr client, Mask access)
+{
+ if (id == root.drawable.id)
+ {
+ *win = &root;
+ return Success;
+ } else if (id == window.drawable.id)
+ {
+ *win = &window;
+ return Success;
+ }
+
+ return __real_dixLookupWindow(win, id, client, access);
+}
+
+/* AddResource is called from XISetSEventMask, we don't need this */
+Bool __wrap_AddResource(XID id, RESTYPE type, pointer value)
+{
+ return TRUE;
+}
+
+static void reply_XIGetSelectedEvents(ClientPtr client, int len, char *data, void *userdata)
+{
+ xXIGetSelectedEventsReply *rep = (xXIGetSelectedEventsReply*)data;
+
+ if (client->swapped)
+ {
+ char n;
+ swapl(&rep->length, n);
+ swaps(&rep->sequenceNumber, n);
+ swaps(&rep->num_masks, n);
+ }
+
+ reply_check_defaults(rep, len, XIGetSelectedEvents);
+
+ assert(rep->num_masks == test_data.num_masks_expected);
+
+ reply_handler = reply_XIGetSelectedEvents_data;
+}
+
+static void reply_XIGetSelectedEvents_data(ClientPtr client, int len, char *data, void *userdata)
+{
+ int i;
+ xXIEventMask *mask;
+ unsigned char *bitmask;
+
+ mask = (xXIEventMask*)data;
+ for (i = 0; i < test_data.num_masks_expected; i++)
+ {
+ if (client->swapped)
+ {
+ char n;
+ swaps(&mask->deviceid, n);
+ swaps(&mask->mask_len, n);
+ }
+
+ assert(mask->deviceid < 6);
+ assert(mask->mask_len <= (((XI2LASTEVENT + 8)/8) + 3)/4) ;
+
+ bitmask = (unsigned char*)&mask[1];
+ assert(memcmp(bitmask,
+ test_data.mask[mask->deviceid],
+ mask->mask_len * 4) == 0);
+
+ mask = (xXIEventMask*)((char*)mask + mask->mask_len * 4 + sizeof(xXIEventMask));
+ }
+
+
+}
+
+static void request_XIGetSelectedEvents(xXIGetSelectedEventsReq* req, int error)
+{
+ char n;
+ int rc;
+ ClientRec client;
+ client = init_client(req->length, req);
+
+ reply_handler = reply_XIGetSelectedEvents;
+
+ rc = ProcXIGetSelectedEvents(&client);
+ assert(rc == error);
+
+ reply_handler = reply_XIGetSelectedEvents;
+ client.swapped = TRUE;
+ swapl(&req->win, n);
+ swaps(&req->length, n);
+ rc = SProcXIGetSelectedEvents(&client);
+ assert(rc == error);
+}
+
+static void test_XIGetSelectedEvents(void)
+{
+ int i, j;
+ xXIGetSelectedEventsReq request;
+ ClientRec client = init_client(0, NULL);
+ unsigned char *mask;
+ DeviceIntRec dev;
+
+ request_init(&request, XIGetSelectedEvents);
+
+ printf("Testing for BadWindow on invalid window.\n");
+ request.win = None;
+ request_XIGetSelectedEvents(&request, BadWindow);
+
+ printf("Testing for zero-length (unset) masks.\n");
+ /* No masks set yet */
+ test_data.num_masks_expected = 0;
+ request.win = ROOT_WINDOW_ID;
+ request_XIGetSelectedEvents(&request, Success);
+
+ request.win = CLIENT_WINDOW_ID;
+ request_XIGetSelectedEvents(&request, Success);
+
+ memset(test_data.mask, 0,
+ sizeof(test_data.mask));
+
+ printf("Testing for valid masks\n");
+ memset(&dev, 0, sizeof(dev)); /* dev->id is enough for XISetEventMask */
+ request.win = ROOT_WINDOW_ID;
+
+ /* devices 6 - MAXDEVICES don't exist, they mustn't be included in the
+ * reply even if a mask is set */
+ for (j = 0; j < MAXDEVICES; j++)
+ {
+ test_data.num_masks_expected = min(j + 1, devices.num_devices + 2);
+ dev.id = j;
+ mask = test_data.mask[j];
+ /* bits one-by-one */
+ for (i = 0; i < XI2LASTEVENT; i++)
+ {
+ SetBit(mask, i);
+ XISetEventMask(&dev, &root, &client, (i + 8)/8, mask);
+ request_XIGetSelectedEvents(&request, Success);
+ ClearBit(mask, i);
+ }
+
+ /* all valid mask bits */
+ for (i = 0; i < XI2LASTEVENT; i++)
+ {
+ SetBit(mask, i);
+ XISetEventMask(&dev, &root, &client, (i + 8)/8, mask);
+ request_XIGetSelectedEvents(&request, Success);
+ }
+ }
+
+ printf("Testing removing all masks\n");
+ /* Unset all masks one-by-one */
+ for (j = MAXDEVICES - 1; j >= 0; j--)
+ {
+ if (j < devices.num_devices + 2)
+ test_data.num_masks_expected--;
+
+ mask = test_data.mask[j];
+ memset(mask, 0, XI2LASTEVENT);
+
+ dev.id = j;
+ XISetEventMask(&dev, &root, &client, 0, NULL);
+
+ request_XIGetSelectedEvents(&request, Success);
+ }
+}
+
+int main(int argc, char** argv)
+{
+ init_simple();
+
+ test_XIGetSelectedEvents();
+
+ return 0;
+}
+
diff --git a/xorg-server/test/xi2/protocol-xiquerydevice.c b/xorg-server/test/xi2/protocol-xiquerydevice.c index cb1cc8130..7a631e0dd 100644 --- a/xorg-server/test/xi2/protocol-xiquerydevice.c +++ b/xorg-server/test/xi2/protocol-xiquerydevice.c @@ -1,312 +1,312 @@ -/** - * Copyright © 2009 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include <dix-config.h> -#endif - -#include <stdint.h> -#include <X11/X.h> -#include <X11/Xproto.h> -#include <X11/extensions/XI2proto.h> -#include <X11/Xatom.h> -#include "inputstr.h" -#include "extinit.h" -#include "scrnintstr.h" -#include "xkbsrv.h" - -#include "xiquerydevice.h" - -#include "protocol-common.h" -/* - * Protocol testing for XIQueryDevice request and reply. - * - * Test approach: - * Wrap WriteToClient to intercept server's reply. ProcXIQueryDevice returns - * data in two batches, once for the request, once for the trailing data - * with the device information. - * Repeatedly test with varying deviceids and check against data in reply. - */ - -struct test_data { - int which_device; - int num_devices_in_reply; -}; - -static void reply_XIQueryDevice_data(ClientPtr client, int len, char *data, void *userdata); -static void reply_XIQueryDevice(ClientPtr client, int len, char* data, void *userdata); - -/* reply handling for the first bytes that constitute the reply */ -static void reply_XIQueryDevice(ClientPtr client, int len, char* data, void *userdata) -{ - xXIQueryDeviceReply *rep = (xXIQueryDeviceReply*)data; - struct test_data *querydata = (struct test_data*)userdata; - - if (client->swapped) - { - char n; - swapl(&rep->length, n); - swaps(&rep->sequenceNumber, n); - swaps(&rep->num_devices, n); - } - - reply_check_defaults(rep, len, XIQueryDevice); - - if (querydata->which_device == XIAllDevices) - assert(rep->num_devices == devices.num_devices); - else if (querydata->which_device == XIAllMasterDevices) - assert(rep->num_devices == devices.num_master_devices); - else - assert(rep->num_devices == 1); - - querydata->num_devices_in_reply = rep->num_devices; - reply_handler = reply_XIQueryDevice_data; -} - -/* reply handling for the trailing bytes that constitute the device info */ -static void reply_XIQueryDevice_data(ClientPtr client, int len, char *data, void *userdata) -{ - char n; - int i, j; - struct test_data *querydata = (struct test_data*)userdata; - - DeviceIntPtr dev; - xXIDeviceInfo *info = (xXIDeviceInfo*)data; - xXIAnyInfo *any; - - for (i = 0; i < querydata->num_devices_in_reply; i++) - { - if (client->swapped) - { - swaps(&info->deviceid, n); - swaps(&info->attachment, n); - swaps(&info->use, n); - swaps(&info->num_classes, n); - swaps(&info->name_len, n); - } - - if (querydata->which_device > XIAllMasterDevices) - assert(info->deviceid == querydata->which_device); - - assert(info->deviceid >= 2); /* 0 and 1 is reserved */ - - - switch(info->deviceid) - { - case 2: /* VCP */ - dev = devices.vcp; - assert(info->use == XIMasterPointer); - assert(info->attachment == devices.vck->id); - assert(info->num_classes == 3); /* 2 axes + button */ - break; - case 3: /* VCK */ - dev = devices.vck; - assert(info->use == XIMasterKeyboard); - assert(info->attachment == devices.vcp->id); - assert(info->num_classes == 1); - break; - case 4: /* mouse */ - dev = devices.mouse; - assert(info->use == XISlavePointer); - assert(info->attachment == devices.vcp->id); - assert(info->num_classes == 3); /* 2 axes + button */ - break; - case 5: /* keyboard */ - dev = devices.kbd; - assert(info->use == XISlaveKeyboard); - assert(info->attachment == devices.vck->id); - assert(info->num_classes == 1); - break; - - default: - /* We shouldn't get here */ - assert(0); - break; - } - assert(info->enabled == dev->enabled); - assert(info->name_len == strlen(dev->name)); - assert(strncmp((char*)&info[1], dev->name, info->name_len) == 0); - - any = (xXIAnyInfo*)((char*)&info[1] + ((info->name_len + 3)/4) * 4); - for (j = 0; j < info->num_classes; j++) - { - if (client->swapped) - { - swaps(&any->type, n); - swaps(&any->length, n); - swaps(&any->sourceid, n); - } - - switch(info->deviceid) - { - case 3: /* VCK and kbd have the same properties */ - case 5: - { - int k; - xXIKeyInfo *ki = (xXIKeyInfo*)any; - XkbDescPtr xkb = devices.vck->key->xkbInfo->desc; - uint32_t *kc; - - if (client->swapped) - swaps(&ki->num_keycodes, n); - - assert(any->type == XIKeyClass); - assert(ki->num_keycodes == (xkb->max_key_code - xkb->min_key_code + 1)); - assert(any->length == (2 + ki->num_keycodes)); - - kc = (uint32_t*)&ki[1]; - for (k = 0; k < ki->num_keycodes; k++, kc++) - { - if (client->swapped) - swapl(kc, n); - - assert(*kc >= xkb->min_key_code); - assert(*kc <= xkb->max_key_code); - } - break; - } - case 2: /* VCP and mouse have the same properties */ - case 4: - { - assert(any->type == XIButtonClass || - any->type == XIValuatorClass); - - if (any->type == XIButtonClass) - { - int len; - xXIButtonInfo *bi = (xXIButtonInfo*)any; - - if (client->swapped) - swaps(&bi->num_buttons, n); - - assert(bi->num_buttons == devices.vcp->button->numButtons); - - len = 2 + bi->num_buttons + bytes_to_int32(bits_to_bytes(bi->num_buttons)); - assert(bi->length == len); - } else if (any->type == XIValuatorClass) - { - xXIValuatorInfo *vi = (xXIValuatorInfo*)any; - - if (client->swapped) - { - swaps(&vi->number, n); - swapl(&vi->label, n); - swapl(&vi->min.integral, n); - swapl(&vi->min.frac, n); - swapl(&vi->max.integral, n); - swapl(&vi->max.frac, n); - swapl(&vi->resolution, n); - } - - assert(vi->length == 11); - assert(vi->number == 0 || - vi->number == 1); - assert(vi->mode == XIModeRelative); - /* device was set up as relative, so standard - * values here. */ - assert(vi->min.integral == -1); - assert(vi->min.frac == 0); - assert(vi->max.integral == -1); - assert(vi->max.frac == 0); - assert(vi->resolution == 0); - } - } - break; - } - any = (xXIAnyInfo*)(((char*)any) + any->length * 4); - } - - info = (xXIDeviceInfo*)any; - } -} - -static void request_XIQueryDevice(struct test_data *querydata, - int deviceid, int error) -{ - int rc; - char n; - ClientRec client; - xXIQueryDeviceReq request; - - request_init(&request, XIQueryDevice); - client = init_client(request.length, &request); - reply_handler = reply_XIQueryDevice; - - querydata->which_device = deviceid; - - request.deviceid = deviceid; - rc = ProcXIQueryDevice(&client); - assert(rc == error); - - if (rc != Success) - assert(client.errorValue == deviceid); - - reply_handler = reply_XIQueryDevice; - - client.swapped = TRUE; - swaps(&request.length, n); - swaps(&request.deviceid, n); - rc = SProcXIQueryDevice(&client); - assert(rc == error); - - if (rc != Success) - assert(client.errorValue == deviceid); -} - -static void test_XIQueryDevice(void) -{ - int i; - xXIQueryDeviceReq request; - struct test_data data; - - reply_handler = reply_XIQueryDevice; - userdata = &data; - request_init(&request, XIQueryDevice); - - printf("Testing XIAllDevices.\n"); - request_XIQueryDevice(&data, XIAllDevices, Success); - printf("Testing XIAllMasterDevices.\n"); - request_XIQueryDevice(&data, XIAllMasterDevices, Success); - - printf("Testing existing device ids.\n"); - for (i = 2; i < 6; i++) - request_XIQueryDevice(&data, i, Success); - - printf("Testing non-existing device ids.\n"); - for (i = 6; i <= 0xFFFF; i++) - request_XIQueryDevice(&data, i, BadDevice); - - - reply_handler = NULL; - -} - -int main(int argc, char** argv) -{ - init_simple(); - - test_XIQueryDevice(); - - return 0; -} - +/**
+ * Copyright © 2009 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <stdint.h>
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include <X11/extensions/XI2proto.h>
+#include <X11/Xatom.h>
+#include "inputstr.h"
+#include "extinit.h"
+#include "scrnintstr.h"
+#include "xkbsrv.h"
+
+#include "xiquerydevice.h"
+
+#include "protocol-common.h"
+/*
+ * Protocol testing for XIQueryDevice request and reply.
+ *
+ * Test approach:
+ * Wrap WriteToClient to intercept server's reply. ProcXIQueryDevice returns
+ * data in two batches, once for the request, once for the trailing data
+ * with the device information.
+ * Repeatedly test with varying deviceids and check against data in reply.
+ */
+
+struct test_data {
+ int which_device;
+ int num_devices_in_reply;
+};
+
+static void reply_XIQueryDevice_data(ClientPtr client, int len, char *data, void *userdata);
+static void reply_XIQueryDevice(ClientPtr client, int len, char* data, void *userdata);
+
+/* reply handling for the first bytes that constitute the reply */
+static void reply_XIQueryDevice(ClientPtr client, int len, char* data, void *userdata)
+{
+ xXIQueryDeviceReply *rep = (xXIQueryDeviceReply*)data;
+ struct test_data *querydata = (struct test_data*)userdata;
+
+ if (client->swapped)
+ {
+ char n;
+ swapl(&rep->length, n);
+ swaps(&rep->sequenceNumber, n);
+ swaps(&rep->num_devices, n);
+ }
+
+ reply_check_defaults(rep, len, XIQueryDevice);
+
+ if (querydata->which_device == XIAllDevices)
+ assert(rep->num_devices == devices.num_devices);
+ else if (querydata->which_device == XIAllMasterDevices)
+ assert(rep->num_devices == devices.num_master_devices);
+ else
+ assert(rep->num_devices == 1);
+
+ querydata->num_devices_in_reply = rep->num_devices;
+ reply_handler = reply_XIQueryDevice_data;
+}
+
+/* reply handling for the trailing bytes that constitute the device info */
+static void reply_XIQueryDevice_data(ClientPtr client, int len, char *data, void *userdata)
+{
+ char n;
+ int i, j;
+ struct test_data *querydata = (struct test_data*)userdata;
+
+ DeviceIntPtr dev;
+ xXIDeviceInfo *info = (xXIDeviceInfo*)data;
+ xXIAnyInfo *any;
+
+ for (i = 0; i < querydata->num_devices_in_reply; i++)
+ {
+ if (client->swapped)
+ {
+ swaps(&info->deviceid, n);
+ swaps(&info->attachment, n);
+ swaps(&info->use, n);
+ swaps(&info->num_classes, n);
+ swaps(&info->name_len, n);
+ }
+
+ if (querydata->which_device > XIAllMasterDevices)
+ assert(info->deviceid == querydata->which_device);
+
+ assert(info->deviceid >= 2); /* 0 and 1 is reserved */
+
+
+ switch(info->deviceid)
+ {
+ case 2: /* VCP */
+ dev = devices.vcp;
+ assert(info->use == XIMasterPointer);
+ assert(info->attachment == devices.vck->id);
+ assert(info->num_classes == 3); /* 2 axes + button */
+ break;
+ case 3: /* VCK */
+ dev = devices.vck;
+ assert(info->use == XIMasterKeyboard);
+ assert(info->attachment == devices.vcp->id);
+ assert(info->num_classes == 1);
+ break;
+ case 4: /* mouse */
+ dev = devices.mouse;
+ assert(info->use == XISlavePointer);
+ assert(info->attachment == devices.vcp->id);
+ assert(info->num_classes == 3); /* 2 axes + button */
+ break;
+ case 5: /* keyboard */
+ dev = devices.kbd;
+ assert(info->use == XISlaveKeyboard);
+ assert(info->attachment == devices.vck->id);
+ assert(info->num_classes == 1);
+ break;
+
+ default:
+ /* We shouldn't get here */
+ assert(0);
+ break;
+ }
+ assert(info->enabled == dev->enabled);
+ assert(info->name_len == strlen(dev->name));
+ assert(strncmp((char*)&info[1], dev->name, info->name_len) == 0);
+
+ any = (xXIAnyInfo*)((char*)&info[1] + ((info->name_len + 3)/4) * 4);
+ for (j = 0; j < info->num_classes; j++)
+ {
+ if (client->swapped)
+ {
+ swaps(&any->type, n);
+ swaps(&any->length, n);
+ swaps(&any->sourceid, n);
+ }
+
+ switch(info->deviceid)
+ {
+ case 3: /* VCK and kbd have the same properties */
+ case 5:
+ {
+ int k;
+ xXIKeyInfo *ki = (xXIKeyInfo*)any;
+ XkbDescPtr xkb = devices.vck->key->xkbInfo->desc;
+ uint32_t *kc;
+
+ if (client->swapped)
+ swaps(&ki->num_keycodes, n);
+
+ assert(any->type == XIKeyClass);
+ assert(ki->num_keycodes == (xkb->max_key_code - xkb->min_key_code + 1));
+ assert(any->length == (2 + ki->num_keycodes));
+
+ kc = (uint32_t*)&ki[1];
+ for (k = 0; k < ki->num_keycodes; k++, kc++)
+ {
+ if (client->swapped)
+ swapl(kc, n);
+
+ assert(*kc >= xkb->min_key_code);
+ assert(*kc <= xkb->max_key_code);
+ }
+ break;
+ }
+ case 2: /* VCP and mouse have the same properties */
+ case 4:
+ {
+ assert(any->type == XIButtonClass ||
+ any->type == XIValuatorClass);
+
+ if (any->type == XIButtonClass)
+ {
+ int len;
+ xXIButtonInfo *bi = (xXIButtonInfo*)any;
+
+ if (client->swapped)
+ swaps(&bi->num_buttons, n);
+
+ assert(bi->num_buttons == devices.vcp->button->numButtons);
+
+ len = 2 + bi->num_buttons + bytes_to_int32(bits_to_bytes(bi->num_buttons));
+ assert(bi->length == len);
+ } else if (any->type == XIValuatorClass)
+ {
+ xXIValuatorInfo *vi = (xXIValuatorInfo*)any;
+
+ if (client->swapped)
+ {
+ swaps(&vi->number, n);
+ swapl(&vi->label, n);
+ swapl(&vi->min.integral, n);
+ swapl(&vi->min.frac, n);
+ swapl(&vi->max.integral, n);
+ swapl(&vi->max.frac, n);
+ swapl(&vi->resolution, n);
+ }
+
+ assert(vi->length == 11);
+ assert(vi->number == 0 ||
+ vi->number == 1);
+ assert(vi->mode == XIModeRelative);
+ /* device was set up as relative, so standard
+ * values here. */
+ assert(vi->min.integral == -1);
+ assert(vi->min.frac == 0);
+ assert(vi->max.integral == -1);
+ assert(vi->max.frac == 0);
+ assert(vi->resolution == 0);
+ }
+ }
+ break;
+ }
+ any = (xXIAnyInfo*)(((char*)any) + any->length * 4);
+ }
+
+ info = (xXIDeviceInfo*)any;
+ }
+}
+
+static void request_XIQueryDevice(struct test_data *querydata,
+ int deviceid, int error)
+{
+ int rc;
+ char n;
+ ClientRec client;
+ xXIQueryDeviceReq request;
+
+ request_init(&request, XIQueryDevice);
+ client = init_client(request.length, &request);
+ reply_handler = reply_XIQueryDevice;
+
+ querydata->which_device = deviceid;
+
+ request.deviceid = deviceid;
+ rc = ProcXIQueryDevice(&client);
+ assert(rc == error);
+
+ if (rc != Success)
+ assert(client.errorValue == deviceid);
+
+ reply_handler = reply_XIQueryDevice;
+
+ client.swapped = TRUE;
+ swaps(&request.length, n);
+ swaps(&request.deviceid, n);
+ rc = SProcXIQueryDevice(&client);
+ assert(rc == error);
+
+ if (rc != Success)
+ assert(client.errorValue == deviceid);
+}
+
+static void test_XIQueryDevice(void)
+{
+ int i;
+ xXIQueryDeviceReq request;
+ struct test_data data;
+
+ reply_handler = reply_XIQueryDevice;
+ userdata = &data;
+ request_init(&request, XIQueryDevice);
+
+ printf("Testing XIAllDevices.\n");
+ request_XIQueryDevice(&data, XIAllDevices, Success);
+ printf("Testing XIAllMasterDevices.\n");
+ request_XIQueryDevice(&data, XIAllMasterDevices, Success);
+
+ printf("Testing existing device ids.\n");
+ for (i = 2; i < 6; i++)
+ request_XIQueryDevice(&data, i, Success);
+
+ printf("Testing non-existing device ids.\n");
+ for (i = 6; i <= 0xFFFF; i++)
+ request_XIQueryDevice(&data, i, BadDevice);
+
+
+ reply_handler = NULL;
+
+}
+
+int main(int argc, char** argv)
+{
+ init_simple();
+
+ test_XIQueryDevice();
+
+ return 0;
+}
+
diff --git a/xorg-server/test/xi2/protocol-xiquerypointer.c b/xorg-server/test/xi2/protocol-xiquerypointer.c index 0985ec70d..15ebc5a24 100644 --- a/xorg-server/test/xi2/protocol-xiquerypointer.c +++ b/xorg-server/test/xi2/protocol-xiquerypointer.c @@ -1,216 +1,216 @@ -/** - * Copyright © 2009 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include <dix-config.h> -#endif - -/* - * Protocol testing for XIQueryPointer request. - */ -#include <stdint.h> -#include <X11/X.h> -#include <X11/Xproto.h> -#include <X11/extensions/XI2proto.h> -#include "inputstr.h" -#include "windowstr.h" -#include "scrnintstr.h" -#include "xiquerypointer.h" -#include "exevents.h" - -#include "protocol-common.h" - -static ClientRec client_request; -static void reply_XIQueryPointer_data(ClientPtr client, int len, - char *data, void *userdata); - -static struct { - DeviceIntPtr dev; - WindowPtr win; -} test_data; - - -/* dixLookupWindow requires a lot of setup not necessary for this test. - * Simple wrapper that returns either one of the fake root window or the - * fake client window. If the requested ID is neither of those wanted, - * return whatever the real dixLookupWindow does. - */ -int __wrap_dixLookupWindow(WindowPtr *win, XID id, ClientPtr client, Mask access) -{ - if (id == root.drawable.id) - { - *win = &root; - return Success; - } else if (id == window.drawable.id) - { - *win = &window; - return Success; - } - - return __real_dixLookupWindow(win, id, client, access); -} - -static void reply_XIQueryPointer(ClientPtr client, int len, char *data, - void *userdata) -{ - xXIQueryPointerReply *rep = (xXIQueryPointerReply*)data; - SpritePtr sprite; - - if (!rep->repType) - return; - - if (client->swapped) - { - char n; - swapl(&rep->length, n); - swaps(&rep->sequenceNumber, n); - swapl(&rep->root, n); - swapl(&rep->child, n); - swapl(&rep->root_x, n); - swapl(&rep->root_y, n); - swapl(&rep->win_x, n); - swapl(&rep->win_y, n); - swaps(&rep->buttons_len, n); - } - - reply_check_defaults(rep, len, XIQueryPointer); - - assert(rep->root == root.drawable.id); - assert(rep->same_screen == xTrue); - - sprite = test_data.dev->spriteInfo->sprite; - assert((rep->root_x >> 16) == sprite->hot.x); - assert((rep->root_y >> 16) == sprite->hot.y); - - if (test_data.win == &root) - { - assert(rep->root_x == rep->win_x); - assert(rep->root_y == rep->win_y); - assert(rep->child == window.drawable.id); - } else - { - int x, y; - - x = sprite->hot.x - window.drawable.x; - y = sprite->hot.y - window.drawable.y; - - assert((rep->win_x >> 16) == x); - assert((rep->win_y >> 16) == y); - assert(rep->child == None); - } - - - assert(rep->same_screen == xTrue); - - reply_handler = reply_XIQueryPointer_data; -} - -static void reply_XIQueryPointer_data(ClientPtr client, int len, char *data, void *userdata) -{ - reply_handler = reply_XIQueryPointer; -} - -static void request_XIQueryPointer(ClientPtr client, xXIQueryPointerReq* req, int error) -{ - char n; - int rc; - - rc = ProcXIQueryPointer(&client_request); - assert(rc == error); - - if (rc == BadDevice) - assert(client_request.errorValue == req->deviceid); - - client_request.swapped = TRUE; - swaps(&req->deviceid, n); - swaps(&req->length, n); - rc = SProcXIQueryPointer(&client_request); - assert(rc == error); - - if (rc == BadDevice) - assert(client_request.errorValue == req->deviceid); -} - -static void test_XIQueryPointer(void) -{ - int i; - xXIQueryPointerReq request; - - memset(&request, 0, sizeof(request)); - - request_init(&request, XIQueryPointer); - - reply_handler = reply_XIQueryPointer; - - client_request = init_client(request.length, &request); - - request.deviceid = XIAllDevices; - request_XIQueryPointer(&client_request, &request, BadDevice); - - request.deviceid = XIAllMasterDevices; - request_XIQueryPointer(&client_request, &request, BadDevice); - - request.win = root.drawable.id; - test_data.win = &root; - - test_data.dev = devices.vcp; - request.deviceid = devices.vcp->id; - request_XIQueryPointer(&client_request, &request, Success); - request.deviceid = devices.vck->id; - request_XIQueryPointer(&client_request, &request, BadDevice); - request.deviceid = devices.mouse->id; - request_XIQueryPointer(&client_request, &request, BadDevice); - request.deviceid = devices.kbd->id; - request_XIQueryPointer(&client_request, &request, BadDevice); - - test_data.dev = devices.mouse; - devices.mouse->master = NULL; /* Float, kind-of */ - request.deviceid = devices.mouse->id; - request_XIQueryPointer(&client_request, &request, Success); - - for (i = devices.kbd->id + 1; i <= 0xFFFF; i++) - { - request.deviceid = i; - request_XIQueryPointer(&client_request, &request, BadDevice); - } - - request.win = window.drawable.id; - - test_data.dev = devices.vcp; - test_data.win = &window; - request.deviceid = devices.vcp->id; - request_XIQueryPointer(&client_request, &request, Success); - - test_data.dev = devices.mouse; - request.deviceid = devices.mouse->id; - request_XIQueryPointer(&client_request, &request, Success); -} - -int main(int argc, char** argv) -{ - init_simple(); - - test_XIQueryPointer(); - - return 0; -} +/**
+ * Copyright © 2009 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+/*
+ * Protocol testing for XIQueryPointer request.
+ */
+#include <stdint.h>
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include <X11/extensions/XI2proto.h>
+#include "inputstr.h"
+#include "windowstr.h"
+#include "scrnintstr.h"
+#include "xiquerypointer.h"
+#include "exevents.h"
+
+#include "protocol-common.h"
+
+static ClientRec client_request;
+static void reply_XIQueryPointer_data(ClientPtr client, int len,
+ char *data, void *userdata);
+
+static struct {
+ DeviceIntPtr dev;
+ WindowPtr win;
+} test_data;
+
+
+/* dixLookupWindow requires a lot of setup not necessary for this test.
+ * Simple wrapper that returns either one of the fake root window or the
+ * fake client window. If the requested ID is neither of those wanted,
+ * return whatever the real dixLookupWindow does.
+ */
+int __wrap_dixLookupWindow(WindowPtr *win, XID id, ClientPtr client, Mask access)
+{
+ if (id == root.drawable.id)
+ {
+ *win = &root;
+ return Success;
+ } else if (id == window.drawable.id)
+ {
+ *win = &window;
+ return Success;
+ }
+
+ return __real_dixLookupWindow(win, id, client, access);
+}
+
+static void reply_XIQueryPointer(ClientPtr client, int len, char *data,
+ void *userdata)
+{
+ xXIQueryPointerReply *rep = (xXIQueryPointerReply*)data;
+ SpritePtr sprite;
+
+ if (!rep->repType)
+ return;
+
+ if (client->swapped)
+ {
+ char n;
+ swapl(&rep->length, n);
+ swaps(&rep->sequenceNumber, n);
+ swapl(&rep->root, n);
+ swapl(&rep->child, n);
+ swapl(&rep->root_x, n);
+ swapl(&rep->root_y, n);
+ swapl(&rep->win_x, n);
+ swapl(&rep->win_y, n);
+ swaps(&rep->buttons_len, n);
+ }
+
+ reply_check_defaults(rep, len, XIQueryPointer);
+
+ assert(rep->root == root.drawable.id);
+ assert(rep->same_screen == xTrue);
+
+ sprite = test_data.dev->spriteInfo->sprite;
+ assert((rep->root_x >> 16) == sprite->hot.x);
+ assert((rep->root_y >> 16) == sprite->hot.y);
+
+ if (test_data.win == &root)
+ {
+ assert(rep->root_x == rep->win_x);
+ assert(rep->root_y == rep->win_y);
+ assert(rep->child == window.drawable.id);
+ } else
+ {
+ int x, y;
+
+ x = sprite->hot.x - window.drawable.x;
+ y = sprite->hot.y - window.drawable.y;
+
+ assert((rep->win_x >> 16) == x);
+ assert((rep->win_y >> 16) == y);
+ assert(rep->child == None);
+ }
+
+
+ assert(rep->same_screen == xTrue);
+
+ reply_handler = reply_XIQueryPointer_data;
+}
+
+static void reply_XIQueryPointer_data(ClientPtr client, int len, char *data, void *userdata)
+{
+ reply_handler = reply_XIQueryPointer;
+}
+
+static void request_XIQueryPointer(ClientPtr client, xXIQueryPointerReq* req, int error)
+{
+ char n;
+ int rc;
+
+ rc = ProcXIQueryPointer(&client_request);
+ assert(rc == error);
+
+ if (rc == BadDevice)
+ assert(client_request.errorValue == req->deviceid);
+
+ client_request.swapped = TRUE;
+ swaps(&req->deviceid, n);
+ swaps(&req->length, n);
+ rc = SProcXIQueryPointer(&client_request);
+ assert(rc == error);
+
+ if (rc == BadDevice)
+ assert(client_request.errorValue == req->deviceid);
+}
+
+static void test_XIQueryPointer(void)
+{
+ int i;
+ xXIQueryPointerReq request;
+
+ memset(&request, 0, sizeof(request));
+
+ request_init(&request, XIQueryPointer);
+
+ reply_handler = reply_XIQueryPointer;
+
+ client_request = init_client(request.length, &request);
+
+ request.deviceid = XIAllDevices;
+ request_XIQueryPointer(&client_request, &request, BadDevice);
+
+ request.deviceid = XIAllMasterDevices;
+ request_XIQueryPointer(&client_request, &request, BadDevice);
+
+ request.win = root.drawable.id;
+ test_data.win = &root;
+
+ test_data.dev = devices.vcp;
+ request.deviceid = devices.vcp->id;
+ request_XIQueryPointer(&client_request, &request, Success);
+ request.deviceid = devices.vck->id;
+ request_XIQueryPointer(&client_request, &request, BadDevice);
+ request.deviceid = devices.mouse->id;
+ request_XIQueryPointer(&client_request, &request, BadDevice);
+ request.deviceid = devices.kbd->id;
+ request_XIQueryPointer(&client_request, &request, BadDevice);
+
+ test_data.dev = devices.mouse;
+ devices.mouse->master = NULL; /* Float, kind-of */
+ request.deviceid = devices.mouse->id;
+ request_XIQueryPointer(&client_request, &request, Success);
+
+ for (i = devices.kbd->id + 1; i <= 0xFFFF; i++)
+ {
+ request.deviceid = i;
+ request_XIQueryPointer(&client_request, &request, BadDevice);
+ }
+
+ request.win = window.drawable.id;
+
+ test_data.dev = devices.vcp;
+ test_data.win = &window;
+ request.deviceid = devices.vcp->id;
+ request_XIQueryPointer(&client_request, &request, Success);
+
+ test_data.dev = devices.mouse;
+ request.deviceid = devices.mouse->id;
+ request_XIQueryPointer(&client_request, &request, Success);
+}
+
+int main(int argc, char** argv)
+{
+ init_simple();
+
+ test_XIQueryPointer();
+
+ return 0;
+}
diff --git a/xorg-server/test/xi2/protocol-xiqueryversion.c b/xorg-server/test/xi2/protocol-xiqueryversion.c index 3bb356e7f..7c4c018b1 100644 --- a/xorg-server/test/xi2/protocol-xiqueryversion.c +++ b/xorg-server/test/xi2/protocol-xiqueryversion.c @@ -1,182 +1,182 @@ -/** - * Copyright © 2009 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include <dix-config.h> -#endif - -/* - * Protocol testing for XIQueryVersion request and reply. - * - * Test approach: - * Wrap WriteToClient to intercept the server's reply. - * Repeatedly test a client/server version combination, compare version in - * reply with versions given. Version must be equal to either - * server version or client version, whichever is smaller. - * Client version less than 2 must return BadValue. - */ - -#include <stdint.h> -#include <X11/X.h> -#include <X11/Xproto.h> -#include <X11/extensions/XI2proto.h> -#include "inputstr.h" -#include "extinit.h" /* for XInputExtensionInit */ -#include "scrnintstr.h" -#include "xiqueryversion.h" - -#include "protocol-common.h" - -extern XExtensionVersion XIVersion; - -struct test_data { - int major_client; - int minor_client; - int major_server; - int minor_server; -}; - -static void reply_XIQueryVersion(ClientPtr client, int len, char* data, void *userdata) -{ - xXIQueryVersionReply *rep = (xXIQueryVersionReply*)data; - struct test_data *versions = (struct test_data*)userdata; - unsigned int sver, cver, ver; - - if (client->swapped) - { - char n; - swapl(&rep->length, n); - swaps(&rep->sequenceNumber, n); - swaps(&rep->major_version, n); - swaps(&rep->minor_version, n); - } - - reply_check_defaults(rep, len, XIQueryVersion); - - assert(rep->length == 0); - - sver = versions->major_server * 1000 + versions->minor_server; - cver = versions->major_client * 1000 + versions->minor_client; - ver = rep->major_version * 1000 + rep->minor_version; - - assert(ver >= 2000); - assert((sver > cver) ? ver == cver : ver == sver); -} - -/** - * Run a single test with server version smaj.smin and client - * version cmaj.cmin. Verify that return code is equal to 'error'. - * - * Test is run normal, then for a swapped client. - */ -static void request_XIQueryVersion(int smaj, int smin, int cmaj, int cmin, int error) -{ - char n; - int rc; - struct test_data versions; - xXIQueryVersionReq request; - ClientRec client; - - request_init(&request, XIQueryVersion); - client = init_client(request.length, &request); - userdata = (void*)&versions; - - /* Change the server to support smaj.smin */ - XIVersion.major_version = smaj; - XIVersion.minor_version = smin; - - /* remember versions we send and expect */ - versions.major_client = cmaj; - versions.minor_client = cmin; - versions.major_server = XIVersion.major_version; - versions.minor_server = XIVersion.minor_version; - - request.major_version = versions.major_client; - request.minor_version = versions.minor_client; - rc = ProcXIQueryVersion(&client); - assert(rc == error); - - client.swapped = TRUE; - - swaps(&request.length, n); - swaps(&request.major_version, n); - swaps(&request.minor_version, n); - - rc = SProcXIQueryVersion(&client); - assert(rc == error); -} - -/* Client version less than 2.0 must return BadValue, all other combinations - * Success */ -static void test_XIQueryVersion(void) -{ - reply_handler = reply_XIQueryVersion; - - printf("Server version 2.0 - client versions [1..3].0\n"); - /* some simple tests to catch common errors quickly */ - request_XIQueryVersion(2, 0, 1, 0, BadValue); - request_XIQueryVersion(2, 0, 2, 0, Success); - request_XIQueryVersion(2, 0, 3, 0, Success); - - printf("Server version 3.0 - client versions [1..3].0\n"); - request_XIQueryVersion(3, 0, 1, 0, BadValue); - request_XIQueryVersion(3, 0, 2, 0, Success); - request_XIQueryVersion(3, 0, 3, 0, Success); - - printf("Server version 2.0 - client versions [1..3].[1..3]\n"); - request_XIQueryVersion(2, 0, 1, 1, BadValue); - request_XIQueryVersion(2, 0, 2, 2, Success); - request_XIQueryVersion(2, 0, 3, 3, Success); - - printf("Server version 2.2 - client versions [1..3].0\n"); - request_XIQueryVersion(2, 2, 1, 0, BadValue); - request_XIQueryVersion(2, 2, 2, 0, Success); - request_XIQueryVersion(2, 2, 3, 0, Success); - -#if 0 - /* this one takes a while */ - unsigned int cmin, cmaj, smin, smaj; - - printf("Testing all combinations.\n"); - for (smaj = 2; smaj <= 0xFFFF; smaj++) - for (smin = 0; smin <= 0xFFFF; smin++) - for (cmin = 0; cmin <= 0xFFFF; cmin++) - for (cmaj = 0; cmaj <= 0xFFFF; cmaj++) - { - int error = (cmaj < 2) ? BadValue : Success; - request_XIQueryVersion(smaj, smin, cmaj, cmin, error); - } - -#endif - - reply_handler = NULL; -} - -int main(int argc, char** argv) -{ - init_simple(); - - test_XIQueryVersion(); - - return 0; -} +/**
+ * Copyright © 2009 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+/*
+ * Protocol testing for XIQueryVersion request and reply.
+ *
+ * Test approach:
+ * Wrap WriteToClient to intercept the server's reply.
+ * Repeatedly test a client/server version combination, compare version in
+ * reply with versions given. Version must be equal to either
+ * server version or client version, whichever is smaller.
+ * Client version less than 2 must return BadValue.
+ */
+
+#include <stdint.h>
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include <X11/extensions/XI2proto.h>
+#include "inputstr.h"
+#include "extinit.h" /* for XInputExtensionInit */
+#include "scrnintstr.h"
+#include "xiqueryversion.h"
+
+#include "protocol-common.h"
+
+extern XExtensionVersion XIVersion;
+
+struct test_data {
+ int major_client;
+ int minor_client;
+ int major_server;
+ int minor_server;
+};
+
+static void reply_XIQueryVersion(ClientPtr client, int len, char* data, void *userdata)
+{
+ xXIQueryVersionReply *rep = (xXIQueryVersionReply*)data;
+ struct test_data *versions = (struct test_data*)userdata;
+ unsigned int sver, cver, ver;
+
+ if (client->swapped)
+ {
+ char n;
+ swapl(&rep->length, n);
+ swaps(&rep->sequenceNumber, n);
+ swaps(&rep->major_version, n);
+ swaps(&rep->minor_version, n);
+ }
+
+ reply_check_defaults(rep, len, XIQueryVersion);
+
+ assert(rep->length == 0);
+
+ sver = versions->major_server * 1000 + versions->minor_server;
+ cver = versions->major_client * 1000 + versions->minor_client;
+ ver = rep->major_version * 1000 + rep->minor_version;
+
+ assert(ver >= 2000);
+ assert((sver > cver) ? ver == cver : ver == sver);
+}
+
+/**
+ * Run a single test with server version smaj.smin and client
+ * version cmaj.cmin. Verify that return code is equal to 'error'.
+ *
+ * Test is run normal, then for a swapped client.
+ */
+static void request_XIQueryVersion(int smaj, int smin, int cmaj, int cmin, int error)
+{
+ char n;
+ int rc;
+ struct test_data versions;
+ xXIQueryVersionReq request;
+ ClientRec client;
+
+ request_init(&request, XIQueryVersion);
+ client = init_client(request.length, &request);
+ userdata = (void*)&versions;
+
+ /* Change the server to support smaj.smin */
+ XIVersion.major_version = smaj;
+ XIVersion.minor_version = smin;
+
+ /* remember versions we send and expect */
+ versions.major_client = cmaj;
+ versions.minor_client = cmin;
+ versions.major_server = XIVersion.major_version;
+ versions.minor_server = XIVersion.minor_version;
+
+ request.major_version = versions.major_client;
+ request.minor_version = versions.minor_client;
+ rc = ProcXIQueryVersion(&client);
+ assert(rc == error);
+
+ client.swapped = TRUE;
+
+ swaps(&request.length, n);
+ swaps(&request.major_version, n);
+ swaps(&request.minor_version, n);
+
+ rc = SProcXIQueryVersion(&client);
+ assert(rc == error);
+}
+
+/* Client version less than 2.0 must return BadValue, all other combinations
+ * Success */
+static void test_XIQueryVersion(void)
+{
+ reply_handler = reply_XIQueryVersion;
+
+ printf("Server version 2.0 - client versions [1..3].0\n");
+ /* some simple tests to catch common errors quickly */
+ request_XIQueryVersion(2, 0, 1, 0, BadValue);
+ request_XIQueryVersion(2, 0, 2, 0, Success);
+ request_XIQueryVersion(2, 0, 3, 0, Success);
+
+ printf("Server version 3.0 - client versions [1..3].0\n");
+ request_XIQueryVersion(3, 0, 1, 0, BadValue);
+ request_XIQueryVersion(3, 0, 2, 0, Success);
+ request_XIQueryVersion(3, 0, 3, 0, Success);
+
+ printf("Server version 2.0 - client versions [1..3].[1..3]\n");
+ request_XIQueryVersion(2, 0, 1, 1, BadValue);
+ request_XIQueryVersion(2, 0, 2, 2, Success);
+ request_XIQueryVersion(2, 0, 3, 3, Success);
+
+ printf("Server version 2.2 - client versions [1..3].0\n");
+ request_XIQueryVersion(2, 2, 1, 0, BadValue);
+ request_XIQueryVersion(2, 2, 2, 0, Success);
+ request_XIQueryVersion(2, 2, 3, 0, Success);
+
+#if 0
+ /* this one takes a while */
+ unsigned int cmin, cmaj, smin, smaj;
+
+ printf("Testing all combinations.\n");
+ for (smaj = 2; smaj <= 0xFFFF; smaj++)
+ for (smin = 0; smin <= 0xFFFF; smin++)
+ for (cmin = 0; cmin <= 0xFFFF; cmin++)
+ for (cmaj = 0; cmaj <= 0xFFFF; cmaj++)
+ {
+ int error = (cmaj < 2) ? BadValue : Success;
+ request_XIQueryVersion(smaj, smin, cmaj, cmin, error);
+ }
+
+#endif
+
+ reply_handler = NULL;
+}
+
+int main(int argc, char** argv)
+{
+ init_simple();
+
+ test_XIQueryVersion();
+
+ return 0;
+}
diff --git a/xorg-server/test/xi2/protocol-xiselectevents.c b/xorg-server/test/xi2/protocol-xiselectevents.c index fa422e2cb..fc780b358 100644 --- a/xorg-server/test/xi2/protocol-xiselectevents.c +++ b/xorg-server/test/xi2/protocol-xiselectevents.c @@ -1,334 +1,334 @@ -/** - * Copyright © 2009 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include <dix-config.h> -#endif - -/* - * Protocol testing for XISelectEvents request. - * - * Test approach: - * - * Wrap XISetEventMask to intercept when the server tries to apply the event - * mask. Ensure that the mask passed in is equivalent to the one supplied by - * the client. Ensure that invalid devices and invalid masks return errors - * as appropriate. - * - * Tests included: - * BadValue for num_masks < 0 - * BadWindow for invalid windows - * BadDevice for non-existing devices - * BadImplemenation for devices >= 0xFF - * BadValue if HierarchyChanged bit is set for devices other than - * XIAllDevices - * BadValue for invalid mask bits - * Sucecss for excessive mask lengths - * - */ - -#include <stdint.h> -#include <X11/X.h> -#include <X11/Xproto.h> -#include <X11/extensions/XI2proto.h> -#include "inputstr.h" -#include "windowstr.h" -#include "extinit.h" /* for XInputExtensionInit */ -#include "scrnintstr.h" -#include "xiselectev.h" - -#include "protocol-common.h" - -static unsigned char *data[4096 * 20]; /* the request data buffer */ - -int __wrap_XISetEventMask(DeviceIntPtr dev, WindowPtr win, int len, unsigned char* mask) -{ - return Success; -} - -/* dixLookupWindow requires a lot of setup not necessary for this test. - * Simple wrapper that returns either one of the fake root window or the - * fake client window. If the requested ID is neither of those wanted, - * return whatever the real dixLookupWindow does. - */ -int __wrap_dixLookupWindow(WindowPtr *win, XID id, ClientPtr client, Mask access) -{ - if (id == root.drawable.id) - { - *win = &root; - return Success; - } else if (id == window.drawable.id) - { - *win = &window; - return Success; - } - - return __real_dixLookupWindow(win, id, client, access); -} - - -static void request_XISelectEvent(xXISelectEventsReq *req, int error) -{ - char n; - int i; - int rc; - ClientRec client; - xXIEventMask *mask, *next; - - req->length = (sz_xXISelectEventsReq/4); - mask = (xXIEventMask*)&req[1]; - for (i = 0; i < req->num_masks; i++) - { - req->length += sizeof(xXIEventMask)/4 + mask->mask_len; - mask = (xXIEventMask*)((char*)&mask[1] + mask->mask_len * 4); - } - - client = init_client(req->length, req); - - rc = ProcXISelectEvents(&client); - assert(rc == error); - - client.swapped = TRUE; - - mask = (xXIEventMask*)&req[1]; - for (i = 0; i < req->num_masks; i++) - { - next = (xXIEventMask*)((char*)&mask[1] + mask->mask_len * 4); - swaps(&mask->deviceid, n); - swaps(&mask->mask_len, n); - mask = next; - } - - swapl(&req->win, n); - swaps(&req->length, n); - swaps(&req->num_masks, n); - rc = SProcXISelectEvents(&client); - assert(rc == error); -} - -static void request_XISelectEvents_masks(xXISelectEventsReq *req) -{ - int i, j; - xXIEventMask *mask; - int nmasks = (XI2LASTEVENT + 7)/8; - unsigned char *bits; - - mask = (xXIEventMask*)&req[1]; - req->win = ROOT_WINDOW_ID; - - /* if a clients submits more than 100 masks, consider it insane and untested */ - for (i = 1; i <= 1000; i++) - { - req->num_masks = i; - mask->deviceid = XIAllDevices; - - /* Test 0: - * mask_len is 0 -> Success - */ - mask->mask_len = 0; - request_XISelectEvent(req, Success); - - /* Test 1: - * mask may be larger than needed for XI2LASTEVENT. - * Test setting each valid mask bit, while leaving unneeded bits 0. - * -> Success - */ - bits = (unsigned char*)&mask[1]; - mask->mask_len = (nmasks + 3)/4 * 10; - memset(bits, 0, mask->mask_len * 4); - for (j = 0; j <= XI2LASTEVENT; j++) - { - SetBit(bits, j); - request_XISelectEvent(req, Success); - ClearBit(bits, j); - } - - /* Test 2: - * mask may be larger than needed for XI2LASTEVENT. - * Test setting all valid mask bits, while leaving unneeded bits 0. - * -> Success - */ - bits = (unsigned char*)&mask[1]; - mask->mask_len = (nmasks + 3)/4 * 10; - memset(bits, 0, mask->mask_len * 4); - - for (j = 0; j <= XI2LASTEVENT; j++) - { - SetBit(bits, j); - request_XISelectEvent(req, Success); - } - - /* Test 3: - * mask is larger than needed for XI2LASTEVENT. If any unneeded bit - * is set -> BadValue - */ - bits = (unsigned char*)&mask[1]; - mask->mask_len = (nmasks + 3)/4 * 10; - memset(bits, 0, mask->mask_len * 4); - - for (j = XI2LASTEVENT + 1; j < mask->mask_len * 4; j++) - { - SetBit(bits, j); - request_XISelectEvent(req, BadValue); - ClearBit(bits, j); - } - - /* Test 4: - * Mask len is a sensible length, only valid bits are set -> Success - */ - bits = (unsigned char*)&mask[1]; - mask->mask_len = (nmasks + 3)/4; - memset(bits, 0, mask->mask_len * 4); - for (j = 0; j <= XI2LASTEVENT; j++) - { - SetBit(bits, j); - request_XISelectEvent(req, Success); - } - - /* Test 5: - * HierarchyChanged bit is BadValue for devices other than - * XIAllDevices - */ - bits = (unsigned char*)&mask[1]; - mask->mask_len = (nmasks + 3)/4; - memset(bits, 0, mask->mask_len * 4); - SetBit(bits, XI_HierarchyChanged); - mask->deviceid = XIAllDevices; - request_XISelectEvent(req, Success); - for (j = 1; j < devices.num_devices; j++) - { - mask->deviceid = j; - request_XISelectEvent(req, BadValue); - } - - /* Test 6: - * All bits set minus hierarchy changed bit -> Success - */ - bits = (unsigned char*)&mask[1]; - mask->mask_len = (nmasks + 3)/4; - memset(bits, 0, mask->mask_len * 4); - for (j = 0; j <= XI2LASTEVENT; j++) - SetBit(bits, j); - ClearBit(bits, XI_HierarchyChanged); - for (j = 1; j < 6; j++) - { - mask->deviceid = j; - request_XISelectEvent(req, Success); - } - - mask = (xXIEventMask*)((char*)mask + sizeof(xXIEventMask) + mask->mask_len * 4); - } -} - -static void test_XISelectEvents(void) -{ - int i; - xXIEventMask *mask; - xXISelectEventsReq *req; - req = (xXISelectEventsReq*)data; - - request_init(req, XISelectEvents); - - printf("Testing for BadValue on zero-length masks\n"); - /* zero masks are BadValue, regardless of the window */ - req->num_masks = 0; - - req->win = None; - request_XISelectEvent(req, BadValue); - - req->win = ROOT_WINDOW_ID; - request_XISelectEvent(req, BadValue); - - req->win = CLIENT_WINDOW_ID; - request_XISelectEvent(req, BadValue); - - printf("Testing for BadWindow.\n"); - /* None window is BadWindow, regardless of the masks. - * We don't actually need to set the masks here, BadWindow must occur - * before checking the masks. - */ - req->win = None; - req->num_masks = 1; - request_XISelectEvent(req, BadWindow); - - req->num_masks = 2; - request_XISelectEvent(req, BadWindow); - - req->num_masks = 0xFF; - request_XISelectEvent(req, BadWindow); - - /* request size is 3, so 0xFFFC is the highest num_mask that doesn't - * overflow req->length */ - req->num_masks = 0xFFFC; - request_XISelectEvent(req, BadWindow); - - printf("Triggering num_masks/length overflow\n"); - req->win = ROOT_WINDOW_ID; - /* Integer overflow - req->length can't hold that much */ - req->num_masks = 0xFFFF; - request_XISelectEvent(req, BadLength); - - req->win = ROOT_WINDOW_ID; - req->num_masks = 1; - - printf("Triggering bogus mask length error\n"); - mask = (xXIEventMask*)&req[1]; - mask->deviceid = 0; - mask->mask_len = 0xFFFF; - request_XISelectEvent(req, BadLength); - - /* testing various device ids */ - printf("Testing existing device ids.\n"); - for (i = 0; i < 6; i++) - { - mask = (xXIEventMask*)&req[1]; - mask->deviceid = i; - mask->mask_len = 1; - req->win = ROOT_WINDOW_ID; - req->num_masks = 1; - request_XISelectEvent(req, Success); - } - - printf("Testing non-existing device ids.\n"); - for (i = 6; i <= 0xFFFF; i++) - { - req->win = ROOT_WINDOW_ID; - req->num_masks = 1; - mask = (xXIEventMask*)&req[1]; - mask->deviceid = i; - mask->mask_len = 1; - request_XISelectEvent(req, BadDevice); - } - - request_XISelectEvents_masks(req); -} - -int main(int argc, char** argv) -{ - init_simple(); - - test_XISelectEvents(); - - return 0; -} - +/**
+ * Copyright © 2009 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+/*
+ * Protocol testing for XISelectEvents request.
+ *
+ * Test approach:
+ *
+ * Wrap XISetEventMask to intercept when the server tries to apply the event
+ * mask. Ensure that the mask passed in is equivalent to the one supplied by
+ * the client. Ensure that invalid devices and invalid masks return errors
+ * as appropriate.
+ *
+ * Tests included:
+ * BadValue for num_masks < 0
+ * BadWindow for invalid windows
+ * BadDevice for non-existing devices
+ * BadImplemenation for devices >= 0xFF
+ * BadValue if HierarchyChanged bit is set for devices other than
+ * XIAllDevices
+ * BadValue for invalid mask bits
+ * Sucecss for excessive mask lengths
+ *
+ */
+
+#include <stdint.h>
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include <X11/extensions/XI2proto.h>
+#include "inputstr.h"
+#include "windowstr.h"
+#include "extinit.h" /* for XInputExtensionInit */
+#include "scrnintstr.h"
+#include "xiselectev.h"
+
+#include "protocol-common.h"
+
+static unsigned char *data[4096 * 20]; /* the request data buffer */
+
+int __wrap_XISetEventMask(DeviceIntPtr dev, WindowPtr win, int len, unsigned char* mask)
+{
+ return Success;
+}
+
+/* dixLookupWindow requires a lot of setup not necessary for this test.
+ * Simple wrapper that returns either one of the fake root window or the
+ * fake client window. If the requested ID is neither of those wanted,
+ * return whatever the real dixLookupWindow does.
+ */
+int __wrap_dixLookupWindow(WindowPtr *win, XID id, ClientPtr client, Mask access)
+{
+ if (id == root.drawable.id)
+ {
+ *win = &root;
+ return Success;
+ } else if (id == window.drawable.id)
+ {
+ *win = &window;
+ return Success;
+ }
+
+ return __real_dixLookupWindow(win, id, client, access);
+}
+
+
+static void request_XISelectEvent(xXISelectEventsReq *req, int error)
+{
+ char n;
+ int i;
+ int rc;
+ ClientRec client;
+ xXIEventMask *mask, *next;
+
+ req->length = (sz_xXISelectEventsReq/4);
+ mask = (xXIEventMask*)&req[1];
+ for (i = 0; i < req->num_masks; i++)
+ {
+ req->length += sizeof(xXIEventMask)/4 + mask->mask_len;
+ mask = (xXIEventMask*)((char*)&mask[1] + mask->mask_len * 4);
+ }
+
+ client = init_client(req->length, req);
+
+ rc = ProcXISelectEvents(&client);
+ assert(rc == error);
+
+ client.swapped = TRUE;
+
+ mask = (xXIEventMask*)&req[1];
+ for (i = 0; i < req->num_masks; i++)
+ {
+ next = (xXIEventMask*)((char*)&mask[1] + mask->mask_len * 4);
+ swaps(&mask->deviceid, n);
+ swaps(&mask->mask_len, n);
+ mask = next;
+ }
+
+ swapl(&req->win, n);
+ swaps(&req->length, n);
+ swaps(&req->num_masks, n);
+ rc = SProcXISelectEvents(&client);
+ assert(rc == error);
+}
+
+static void request_XISelectEvents_masks(xXISelectEventsReq *req)
+{
+ int i, j;
+ xXIEventMask *mask;
+ int nmasks = (XI2LASTEVENT + 7)/8;
+ unsigned char *bits;
+
+ mask = (xXIEventMask*)&req[1];
+ req->win = ROOT_WINDOW_ID;
+
+ /* if a clients submits more than 100 masks, consider it insane and untested */
+ for (i = 1; i <= 1000; i++)
+ {
+ req->num_masks = i;
+ mask->deviceid = XIAllDevices;
+
+ /* Test 0:
+ * mask_len is 0 -> Success
+ */
+ mask->mask_len = 0;
+ request_XISelectEvent(req, Success);
+
+ /* Test 1:
+ * mask may be larger than needed for XI2LASTEVENT.
+ * Test setting each valid mask bit, while leaving unneeded bits 0.
+ * -> Success
+ */
+ bits = (unsigned char*)&mask[1];
+ mask->mask_len = (nmasks + 3)/4 * 10;
+ memset(bits, 0, mask->mask_len * 4);
+ for (j = 0; j <= XI2LASTEVENT; j++)
+ {
+ SetBit(bits, j);
+ request_XISelectEvent(req, Success);
+ ClearBit(bits, j);
+ }
+
+ /* Test 2:
+ * mask may be larger than needed for XI2LASTEVENT.
+ * Test setting all valid mask bits, while leaving unneeded bits 0.
+ * -> Success
+ */
+ bits = (unsigned char*)&mask[1];
+ mask->mask_len = (nmasks + 3)/4 * 10;
+ memset(bits, 0, mask->mask_len * 4);
+
+ for (j = 0; j <= XI2LASTEVENT; j++)
+ {
+ SetBit(bits, j);
+ request_XISelectEvent(req, Success);
+ }
+
+ /* Test 3:
+ * mask is larger than needed for XI2LASTEVENT. If any unneeded bit
+ * is set -> BadValue
+ */
+ bits = (unsigned char*)&mask[1];
+ mask->mask_len = (nmasks + 3)/4 * 10;
+ memset(bits, 0, mask->mask_len * 4);
+
+ for (j = XI2LASTEVENT + 1; j < mask->mask_len * 4; j++)
+ {
+ SetBit(bits, j);
+ request_XISelectEvent(req, BadValue);
+ ClearBit(bits, j);
+ }
+
+ /* Test 4:
+ * Mask len is a sensible length, only valid bits are set -> Success
+ */
+ bits = (unsigned char*)&mask[1];
+ mask->mask_len = (nmasks + 3)/4;
+ memset(bits, 0, mask->mask_len * 4);
+ for (j = 0; j <= XI2LASTEVENT; j++)
+ {
+ SetBit(bits, j);
+ request_XISelectEvent(req, Success);
+ }
+
+ /* Test 5:
+ * HierarchyChanged bit is BadValue for devices other than
+ * XIAllDevices
+ */
+ bits = (unsigned char*)&mask[1];
+ mask->mask_len = (nmasks + 3)/4;
+ memset(bits, 0, mask->mask_len * 4);
+ SetBit(bits, XI_HierarchyChanged);
+ mask->deviceid = XIAllDevices;
+ request_XISelectEvent(req, Success);
+ for (j = 1; j < devices.num_devices; j++)
+ {
+ mask->deviceid = j;
+ request_XISelectEvent(req, BadValue);
+ }
+
+ /* Test 6:
+ * All bits set minus hierarchy changed bit -> Success
+ */
+ bits = (unsigned char*)&mask[1];
+ mask->mask_len = (nmasks + 3)/4;
+ memset(bits, 0, mask->mask_len * 4);
+ for (j = 0; j <= XI2LASTEVENT; j++)
+ SetBit(bits, j);
+ ClearBit(bits, XI_HierarchyChanged);
+ for (j = 1; j < 6; j++)
+ {
+ mask->deviceid = j;
+ request_XISelectEvent(req, Success);
+ }
+
+ mask = (xXIEventMask*)((char*)mask + sizeof(xXIEventMask) + mask->mask_len * 4);
+ }
+}
+
+static void test_XISelectEvents(void)
+{
+ int i;
+ xXIEventMask *mask;
+ xXISelectEventsReq *req;
+ req = (xXISelectEventsReq*)data;
+
+ request_init(req, XISelectEvents);
+
+ printf("Testing for BadValue on zero-length masks\n");
+ /* zero masks are BadValue, regardless of the window */
+ req->num_masks = 0;
+
+ req->win = None;
+ request_XISelectEvent(req, BadValue);
+
+ req->win = ROOT_WINDOW_ID;
+ request_XISelectEvent(req, BadValue);
+
+ req->win = CLIENT_WINDOW_ID;
+ request_XISelectEvent(req, BadValue);
+
+ printf("Testing for BadWindow.\n");
+ /* None window is BadWindow, regardless of the masks.
+ * We don't actually need to set the masks here, BadWindow must occur
+ * before checking the masks.
+ */
+ req->win = None;
+ req->num_masks = 1;
+ request_XISelectEvent(req, BadWindow);
+
+ req->num_masks = 2;
+ request_XISelectEvent(req, BadWindow);
+
+ req->num_masks = 0xFF;
+ request_XISelectEvent(req, BadWindow);
+
+ /* request size is 3, so 0xFFFC is the highest num_mask that doesn't
+ * overflow req->length */
+ req->num_masks = 0xFFFC;
+ request_XISelectEvent(req, BadWindow);
+
+ printf("Triggering num_masks/length overflow\n");
+ req->win = ROOT_WINDOW_ID;
+ /* Integer overflow - req->length can't hold that much */
+ req->num_masks = 0xFFFF;
+ request_XISelectEvent(req, BadLength);
+
+ req->win = ROOT_WINDOW_ID;
+ req->num_masks = 1;
+
+ printf("Triggering bogus mask length error\n");
+ mask = (xXIEventMask*)&req[1];
+ mask->deviceid = 0;
+ mask->mask_len = 0xFFFF;
+ request_XISelectEvent(req, BadLength);
+
+ /* testing various device ids */
+ printf("Testing existing device ids.\n");
+ for (i = 0; i < 6; i++)
+ {
+ mask = (xXIEventMask*)&req[1];
+ mask->deviceid = i;
+ mask->mask_len = 1;
+ req->win = ROOT_WINDOW_ID;
+ req->num_masks = 1;
+ request_XISelectEvent(req, Success);
+ }
+
+ printf("Testing non-existing device ids.\n");
+ for (i = 6; i <= 0xFFFF; i++)
+ {
+ req->win = ROOT_WINDOW_ID;
+ req->num_masks = 1;
+ mask = (xXIEventMask*)&req[1];
+ mask->deviceid = i;
+ mask->mask_len = 1;
+ request_XISelectEvent(req, BadDevice);
+ }
+
+ request_XISelectEvents_masks(req);
+}
+
+int main(int argc, char** argv)
+{
+ init_simple();
+
+ test_XISelectEvents();
+
+ return 0;
+}
+
diff --git a/xorg-server/test/xi2/protocol-xisetclientpointer.c b/xorg-server/test/xi2/protocol-xisetclientpointer.c index c266b6560..fa3c87f62 100644 --- a/xorg-server/test/xi2/protocol-xisetclientpointer.c +++ b/xorg-server/test/xi2/protocol-xisetclientpointer.c @@ -1,145 +1,145 @@ -/** - * Copyright © 2009 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include <dix-config.h> -#endif - -/* - * Protocol testing for XISetClientPointer request. - * - * Tests include: - * BadDevice of all devices except master pointers. - * Success for a valid window. - * Success for window None. - * BadWindow for invalid windows. - */ -#include <stdint.h> -#include <X11/X.h> -#include <X11/Xproto.h> -#include <X11/extensions/XI2proto.h> -#include "inputstr.h" -#include "windowstr.h" -#include "extinit.h" /* for XInputExtensionInit */ -#include "scrnintstr.h" -#include "xisetclientpointer.h" -#include "exevents.h" - -#include "protocol-common.h" - -static ClientRec client_window; -static ClientRec client_request; - -int __wrap_dixLookupClient(ClientPtr *pClient, XID rid, ClientPtr client, Mask access) -{ - if (rid == ROOT_WINDOW_ID) - return BadWindow; - - if (rid == CLIENT_WINDOW_ID) - { - *pClient = &client_window; - return Success; - } - - return __real_dixLookupClient(pClient, rid, client, access); -} - -static void request_XISetClientPointer(xXISetClientPointerReq* req, int error) -{ - char n; - int rc; - client_request = init_client(req->length, req); - - rc = ProcXISetClientPointer(&client_request); - assert(rc == error); - - if (rc == BadDevice) - assert(client_request.errorValue == req->deviceid); - - client_request.swapped = TRUE; - swapl(&req->win, n); - swaps(&req->length, n); - swaps(&req->deviceid, n); - rc = SProcXISetClientPointer(&client_request); - assert(rc == error); - - if (rc == BadDevice) - assert(client_request.errorValue == req->deviceid); - -} - -static void test_XISetClientPointer(void) -{ - int i; - xXISetClientPointerReq request; - - request_init(&request, XISetClientPointer); - - request.win = CLIENT_WINDOW_ID; - - printf("Testing BadDevice error for XIAllDevices and XIMasterDevices.\n"); - request.deviceid = XIAllDevices; - request_XISetClientPointer(&request, BadDevice); - - request.deviceid = XIAllMasterDevices; - request_XISetClientPointer(&request, BadDevice); - - printf("Testing Success for VCP and VCK.\n"); - request.deviceid = devices.vcp->id; /* 2 */ - request_XISetClientPointer(&request, Success); - assert(client_window.clientPtr->id == 2); - - request.deviceid = devices.vck->id; /* 3 */ - request_XISetClientPointer(&request, Success); - assert(client_window.clientPtr->id == 2); - - printf("Testing BadDevice error for all other devices.\n"); - for (i = 4; i <= 0xFFFF; i++) - { - request.deviceid = i; - request_XISetClientPointer(&request, BadDevice); - } - - printf("Testing window None\n"); - request.win = None; - request.deviceid = devices.vcp->id; /* 2 */ - request_XISetClientPointer(&request, Success); - assert(client_request.clientPtr->id == 2); - - printf("Testing invalid window\n"); - request.win = INVALID_WINDOW_ID; - request.deviceid = devices.vcp->id; - request_XISetClientPointer(&request, BadWindow); - -} - - -int main(int argc, char** argv) -{ - init_simple(); - client_window = init_client(0, NULL); - - test_XISetClientPointer(); - - return 0; -} +/**
+ * Copyright © 2009 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+/*
+ * Protocol testing for XISetClientPointer request.
+ *
+ * Tests include:
+ * BadDevice of all devices except master pointers.
+ * Success for a valid window.
+ * Success for window None.
+ * BadWindow for invalid windows.
+ */
+#include <stdint.h>
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include <X11/extensions/XI2proto.h>
+#include "inputstr.h"
+#include "windowstr.h"
+#include "extinit.h" /* for XInputExtensionInit */
+#include "scrnintstr.h"
+#include "xisetclientpointer.h"
+#include "exevents.h"
+
+#include "protocol-common.h"
+
+static ClientRec client_window;
+static ClientRec client_request;
+
+int __wrap_dixLookupClient(ClientPtr *pClient, XID rid, ClientPtr client, Mask access)
+{
+ if (rid == ROOT_WINDOW_ID)
+ return BadWindow;
+
+ if (rid == CLIENT_WINDOW_ID)
+ {
+ *pClient = &client_window;
+ return Success;
+ }
+
+ return __real_dixLookupClient(pClient, rid, client, access);
+}
+
+static void request_XISetClientPointer(xXISetClientPointerReq* req, int error)
+{
+ char n;
+ int rc;
+ client_request = init_client(req->length, req);
+
+ rc = ProcXISetClientPointer(&client_request);
+ assert(rc == error);
+
+ if (rc == BadDevice)
+ assert(client_request.errorValue == req->deviceid);
+
+ client_request.swapped = TRUE;
+ swapl(&req->win, n);
+ swaps(&req->length, n);
+ swaps(&req->deviceid, n);
+ rc = SProcXISetClientPointer(&client_request);
+ assert(rc == error);
+
+ if (rc == BadDevice)
+ assert(client_request.errorValue == req->deviceid);
+
+}
+
+static void test_XISetClientPointer(void)
+{
+ int i;
+ xXISetClientPointerReq request;
+
+ request_init(&request, XISetClientPointer);
+
+ request.win = CLIENT_WINDOW_ID;
+
+ printf("Testing BadDevice error for XIAllDevices and XIMasterDevices.\n");
+ request.deviceid = XIAllDevices;
+ request_XISetClientPointer(&request, BadDevice);
+
+ request.deviceid = XIAllMasterDevices;
+ request_XISetClientPointer(&request, BadDevice);
+
+ printf("Testing Success for VCP and VCK.\n");
+ request.deviceid = devices.vcp->id; /* 2 */
+ request_XISetClientPointer(&request, Success);
+ assert(client_window.clientPtr->id == 2);
+
+ request.deviceid = devices.vck->id; /* 3 */
+ request_XISetClientPointer(&request, Success);
+ assert(client_window.clientPtr->id == 2);
+
+ printf("Testing BadDevice error for all other devices.\n");
+ for (i = 4; i <= 0xFFFF; i++)
+ {
+ request.deviceid = i;
+ request_XISetClientPointer(&request, BadDevice);
+ }
+
+ printf("Testing window None\n");
+ request.win = None;
+ request.deviceid = devices.vcp->id; /* 2 */
+ request_XISetClientPointer(&request, Success);
+ assert(client_request.clientPtr->id == 2);
+
+ printf("Testing invalid window\n");
+ request.win = INVALID_WINDOW_ID;
+ request.deviceid = devices.vcp->id;
+ request_XISetClientPointer(&request, BadWindow);
+
+}
+
+
+int main(int argc, char** argv)
+{
+ init_simple();
+ client_window = init_client(0, NULL);
+
+ test_XISetClientPointer();
+
+ return 0;
+}
diff --git a/xorg-server/test/xi2/protocol-xiwarppointer.c b/xorg-server/test/xi2/protocol-xiwarppointer.c index 0c8db453d..7faf593c6 100644 --- a/xorg-server/test/xi2/protocol-xiwarppointer.c +++ b/xorg-server/test/xi2/protocol-xiwarppointer.c @@ -1,212 +1,212 @@ -/** - * Copyright © 2009 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include <dix-config.h> -#endif - -/* - * Protocol testing for XIWarpPointer request. - */ -#include <stdint.h> -#include <X11/X.h> -#include <X11/Xproto.h> -#include <X11/extensions/XI2proto.h> -#include "inputstr.h" -#include "windowstr.h" -#include "scrnintstr.h" -#include "xiwarppointer.h" -#include "exevents.h" - -#include "protocol-common.h" - -static int expected_x = SPRITE_X; -static int expected_y = SPRITE_Y; - -/* dixLookupWindow requires a lot of setup not necessary for this test. - * Simple wrapper that returns either one of the fake root window or the - * fake client window. If the requested ID is neither of those wanted, - * return whatever the real dixLookupWindow does. - */ -int __wrap_dixLookupWindow(WindowPtr *win, XID id, ClientPtr client, Mask access) -{ - if (id == root.drawable.id) - { - *win = &root; - return Success; - } else if (id == window.drawable.id) - { - *win = &window; - return Success; - } - - return __real_dixLookupWindow(win, id, client, access); -} - -/** - * This function overrides the one in the screen rec. - */ -static Bool ScreenSetCursorPosition(DeviceIntPtr dev, ScreenPtr screen, - int x, int y, Bool generateEvent) -{ - assert(x == expected_x); - assert(y == expected_y); - return TRUE; -} - - -static void request_XIWarpPointer(ClientPtr client, xXIWarpPointerReq* req, - int error) -{ - char n; - int rc; - - rc = ProcXIWarpPointer(client); - assert(rc == error); - - if (rc == BadDevice) - assert(client->errorValue == req->deviceid); - else if (rc == BadWindow) - assert(client->errorValue == req->dst_win || - client->errorValue == req->src_win); - - - client->swapped = TRUE; - - swapl(&req->src_win, n); - swapl(&req->dst_win, n); - swapl(&req->src_x, n); - swapl(&req->src_y, n); - swapl(&req->dst_x, n); - swapl(&req->dst_y, n); - swaps(&req->src_width, n); - swaps(&req->src_height, n); - swaps(&req->deviceid, n); - - rc = SProcXIWarpPointer(client); - assert(rc == error); - - if (rc == BadDevice) - assert(client->errorValue == req->deviceid); - else if (rc == BadWindow) - assert(client->errorValue == req->dst_win || - client->errorValue == req->src_win); - - client->swapped = FALSE; -} - -static void test_XIWarpPointer(void) -{ - int i; - ClientRec client_request; - xXIWarpPointerReq request; - - memset(&request, 0, sizeof(request)); - - request_init(&request, XIWarpPointer); - - client_request = init_client(request.length, &request); - - request.deviceid = XIAllDevices; - request_XIWarpPointer(&client_request, &request, BadDevice); - - request.deviceid = XIAllMasterDevices; - request_XIWarpPointer(&client_request, &request, BadDevice); - - request.src_win = root.drawable.id; - request.dst_win = root.drawable.id; - request.deviceid = devices.vcp->id; - request_XIWarpPointer(&client_request, &request, Success); - request.deviceid = devices.vck->id; - request_XIWarpPointer(&client_request, &request, BadDevice); - request.deviceid = devices.mouse->id; - request_XIWarpPointer(&client_request, &request, BadDevice); - request.deviceid = devices.kbd->id; - request_XIWarpPointer(&client_request, &request, BadDevice); - - devices.mouse->master = NULL; /* Float, kind-of */ - request.deviceid = devices.mouse->id; - request_XIWarpPointer(&client_request, &request, Success); - - for (i = devices.kbd->id + 1; i <= 0xFFFF; i++) - { - request.deviceid = i; - request_XIWarpPointer(&client_request, &request, BadDevice); - } - - request.src_win = window.drawable.id; - request.deviceid = devices.vcp->id; - request_XIWarpPointer(&client_request, &request, Success); - - request.deviceid = devices.mouse->id; - request_XIWarpPointer(&client_request, &request, Success); - - request.src_win = root.drawable.id; - request.dst_win = 0xFFFF; /* invalid window */ - request_XIWarpPointer(&client_request, &request, BadWindow); - - request.src_win = 0xFFFF; /* invalid window */ - request.dst_win = root.drawable.id; - request_XIWarpPointer(&client_request, &request, BadWindow); - - request.src_win = None; - request.dst_win = None; - - request.dst_y = 0; - expected_y = SPRITE_Y; - - request.dst_x = 1 << 16; - expected_x = SPRITE_X + 1; - request.deviceid = devices.vcp->id; - request_XIWarpPointer(&client_request, &request, Success); - - request.dst_x = -1 << 16; - expected_x = SPRITE_X - 1; - request.deviceid = devices.vcp->id; - request_XIWarpPointer(&client_request, &request, Success); - - request.dst_x = 0; - expected_x = SPRITE_X; - - request.dst_y = 1 << 16; - expected_y = SPRITE_Y + 1; - request.deviceid = devices.vcp->id; - request_XIWarpPointer(&client_request, &request, Success); - - request.dst_y = -1 << 16; - expected_y = SPRITE_Y - 1; - request.deviceid = devices.vcp->id; - request_XIWarpPointer(&client_request, &request, Success); - - /* FIXME: src_x/y checks */ -} - -int main(int argc, char** argv) -{ - init_simple(); - screen.SetCursorPosition = ScreenSetCursorPosition; - - test_XIWarpPointer(); - - return 0; -} +/**
+ * Copyright © 2009 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+/*
+ * Protocol testing for XIWarpPointer request.
+ */
+#include <stdint.h>
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include <X11/extensions/XI2proto.h>
+#include "inputstr.h"
+#include "windowstr.h"
+#include "scrnintstr.h"
+#include "xiwarppointer.h"
+#include "exevents.h"
+
+#include "protocol-common.h"
+
+static int expected_x = SPRITE_X;
+static int expected_y = SPRITE_Y;
+
+/* dixLookupWindow requires a lot of setup not necessary for this test.
+ * Simple wrapper that returns either one of the fake root window or the
+ * fake client window. If the requested ID is neither of those wanted,
+ * return whatever the real dixLookupWindow does.
+ */
+int __wrap_dixLookupWindow(WindowPtr *win, XID id, ClientPtr client, Mask access)
+{
+ if (id == root.drawable.id)
+ {
+ *win = &root;
+ return Success;
+ } else if (id == window.drawable.id)
+ {
+ *win = &window;
+ return Success;
+ }
+
+ return __real_dixLookupWindow(win, id, client, access);
+}
+
+/**
+ * This function overrides the one in the screen rec.
+ */
+static Bool ScreenSetCursorPosition(DeviceIntPtr dev, ScreenPtr screen,
+ int x, int y, Bool generateEvent)
+{
+ assert(x == expected_x);
+ assert(y == expected_y);
+ return TRUE;
+}
+
+
+static void request_XIWarpPointer(ClientPtr client, xXIWarpPointerReq* req,
+ int error)
+{
+ char n;
+ int rc;
+
+ rc = ProcXIWarpPointer(client);
+ assert(rc == error);
+
+ if (rc == BadDevice)
+ assert(client->errorValue == req->deviceid);
+ else if (rc == BadWindow)
+ assert(client->errorValue == req->dst_win ||
+ client->errorValue == req->src_win);
+
+
+ client->swapped = TRUE;
+
+ swapl(&req->src_win, n);
+ swapl(&req->dst_win, n);
+ swapl(&req->src_x, n);
+ swapl(&req->src_y, n);
+ swapl(&req->dst_x, n);
+ swapl(&req->dst_y, n);
+ swaps(&req->src_width, n);
+ swaps(&req->src_height, n);
+ swaps(&req->deviceid, n);
+
+ rc = SProcXIWarpPointer(client);
+ assert(rc == error);
+
+ if (rc == BadDevice)
+ assert(client->errorValue == req->deviceid);
+ else if (rc == BadWindow)
+ assert(client->errorValue == req->dst_win ||
+ client->errorValue == req->src_win);
+
+ client->swapped = FALSE;
+}
+
+static void test_XIWarpPointer(void)
+{
+ int i;
+ ClientRec client_request;
+ xXIWarpPointerReq request;
+
+ memset(&request, 0, sizeof(request));
+
+ request_init(&request, XIWarpPointer);
+
+ client_request = init_client(request.length, &request);
+
+ request.deviceid = XIAllDevices;
+ request_XIWarpPointer(&client_request, &request, BadDevice);
+
+ request.deviceid = XIAllMasterDevices;
+ request_XIWarpPointer(&client_request, &request, BadDevice);
+
+ request.src_win = root.drawable.id;
+ request.dst_win = root.drawable.id;
+ request.deviceid = devices.vcp->id;
+ request_XIWarpPointer(&client_request, &request, Success);
+ request.deviceid = devices.vck->id;
+ request_XIWarpPointer(&client_request, &request, BadDevice);
+ request.deviceid = devices.mouse->id;
+ request_XIWarpPointer(&client_request, &request, BadDevice);
+ request.deviceid = devices.kbd->id;
+ request_XIWarpPointer(&client_request, &request, BadDevice);
+
+ devices.mouse->master = NULL; /* Float, kind-of */
+ request.deviceid = devices.mouse->id;
+ request_XIWarpPointer(&client_request, &request, Success);
+
+ for (i = devices.kbd->id + 1; i <= 0xFFFF; i++)
+ {
+ request.deviceid = i;
+ request_XIWarpPointer(&client_request, &request, BadDevice);
+ }
+
+ request.src_win = window.drawable.id;
+ request.deviceid = devices.vcp->id;
+ request_XIWarpPointer(&client_request, &request, Success);
+
+ request.deviceid = devices.mouse->id;
+ request_XIWarpPointer(&client_request, &request, Success);
+
+ request.src_win = root.drawable.id;
+ request.dst_win = 0xFFFF; /* invalid window */
+ request_XIWarpPointer(&client_request, &request, BadWindow);
+
+ request.src_win = 0xFFFF; /* invalid window */
+ request.dst_win = root.drawable.id;
+ request_XIWarpPointer(&client_request, &request, BadWindow);
+
+ request.src_win = None;
+ request.dst_win = None;
+
+ request.dst_y = 0;
+ expected_y = SPRITE_Y;
+
+ request.dst_x = 1 << 16;
+ expected_x = SPRITE_X + 1;
+ request.deviceid = devices.vcp->id;
+ request_XIWarpPointer(&client_request, &request, Success);
+
+ request.dst_x = -1 << 16;
+ expected_x = SPRITE_X - 1;
+ request.deviceid = devices.vcp->id;
+ request_XIWarpPointer(&client_request, &request, Success);
+
+ request.dst_x = 0;
+ expected_x = SPRITE_X;
+
+ request.dst_y = 1 << 16;
+ expected_y = SPRITE_Y + 1;
+ request.deviceid = devices.vcp->id;
+ request_XIWarpPointer(&client_request, &request, Success);
+
+ request.dst_y = -1 << 16;
+ expected_y = SPRITE_Y - 1;
+ request.deviceid = devices.vcp->id;
+ request_XIWarpPointer(&client_request, &request, Success);
+
+ /* FIXME: src_x/y checks */
+}
+
+int main(int argc, char** argv)
+{
+ init_simple();
+ screen.SetCursorPosition = ScreenSetCursorPosition;
+
+ test_XIWarpPointer();
+
+ return 0;
+}
diff --git a/xorg-server/test/xkb.c b/xorg-server/test/xkb.c index 421153cd1..775390eb9 100644 --- a/xorg-server/test/xkb.c +++ b/xorg-server/test/xkb.c @@ -1,169 +1,169 @@ -/** - * Copyright © 2009 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include <dix-config.h> -#endif - -#include <xkb-config.h> - -#include <stdio.h> -#include <stdlib.h> -#include <ctype.h> -#include <unistd.h> -#include <math.h> -#include <X11/X.h> -#include <X11/Xproto.h> -#include <X11/keysym.h> -#include <X11/Xatom.h> -#include "misc.h" -#include "inputstr.h" -#include "opaque.h" -#include "property.h" -#define XKBSRV_NEED_FILE_FUNCS -#include <xkbsrv.h> -#include "../xkb/xkbgeom.h" -#include <X11/extensions/XKMformat.h> -#include "xkbfile.h" -#include "../xkb/xkb.h" -#include <assert.h> - -/** - * Initialize an empty XkbRMLVOSet. - * Call XkbGetRulesDflts to obtain the default ruleset. - * Compare obtained ruleset with the built-in defaults. - * - * Result: RMLVO defaults are the same as obtained. - */ -static void xkb_get_rules_test(void) -{ - XkbRMLVOSet rmlvo = { NULL}; - XkbGetRulesDflts(&rmlvo); - - - assert(rmlvo.rules); - assert(rmlvo.model); - assert(rmlvo.layout); - assert(rmlvo.variant); - assert(rmlvo.options); - assert(strcmp(rmlvo.rules, XKB_DFLT_RULES) == 0); - assert(strcmp(rmlvo.model, XKB_DFLT_MODEL) == 0); - assert(strcmp(rmlvo.layout, XKB_DFLT_LAYOUT) == 0); - assert(strcmp(rmlvo.variant, XKB_DFLT_VARIANT) == 0); - assert(strcmp(rmlvo.options, XKB_DFLT_OPTIONS) == 0); -} - -/** - * Initialize an random XkbRMLVOSet. - * Call XkbGetRulesDflts to obtain the default ruleset. - * Compare obtained ruleset with the built-in defaults. - * Result: RMLVO defaults are the same as obtained. - */ -static void xkb_set_rules_test(void) -{ - XkbRMLVOSet rmlvo = { - .rules = "test-rules", - .model = "test-model", - .layout = "test-layout", - .variant = "test-variant", - .options = "test-options" - }; - XkbRMLVOSet rmlvo_new = { NULL }; - - XkbSetRulesDflts(&rmlvo); - XkbGetRulesDflts(&rmlvo_new); - - /* XkbGetRulesDflts strdups the values */ - assert(rmlvo.rules != rmlvo_new.rules); - assert(rmlvo.model != rmlvo_new.model); - assert(rmlvo.layout != rmlvo_new.layout); - assert(rmlvo.variant != rmlvo_new.variant); - assert(rmlvo.options != rmlvo_new.options); - - assert(strcmp(rmlvo.rules, rmlvo_new.rules) == 0); - assert(strcmp(rmlvo.model, rmlvo_new.model) == 0); - assert(strcmp(rmlvo.layout, rmlvo_new.layout) == 0); - assert(strcmp(rmlvo.variant, rmlvo_new.variant) == 0); - assert(strcmp(rmlvo.options, rmlvo_new.options) == 0); -} - - -/** - * Get the default RMLVO set. - * Set the default RMLVO set. - * Get the default RMLVO set. - * Repeat the last two steps. - * - * Result: RMLVO set obtained is the same as previously set. - */ -static void xkb_set_get_rules_test(void) -{ -/* This test failed before XkbGetRulesDftlts changed to strdup. - We test this twice because the first time using XkbGetRulesDflts we obtain - the built-in defaults. The unexpected free isn't triggered until the second - XkbSetRulesDefaults. - */ - XkbRMLVOSet rmlvo = { NULL }; - XkbRMLVOSet rmlvo_backup; - - XkbGetRulesDflts(&rmlvo); - - /* pass 1 */ - XkbSetRulesDflts(&rmlvo); - XkbGetRulesDflts(&rmlvo); - - /* Make a backup copy */ - rmlvo_backup.rules = strdup(rmlvo.rules); - rmlvo_backup.layout = strdup(rmlvo.layout); - rmlvo_backup.model = strdup(rmlvo.model); - rmlvo_backup.variant = strdup(rmlvo.variant); - rmlvo_backup.options = strdup(rmlvo.options); - - /* pass 2 */ - XkbSetRulesDflts(&rmlvo); - - /* This test is iffy, because strictly we may be comparing against already - * freed memory */ - assert(strcmp(rmlvo.rules, rmlvo_backup.rules) == 0); - assert(strcmp(rmlvo.model, rmlvo_backup.model) == 0); - assert(strcmp(rmlvo.layout, rmlvo_backup.layout) == 0); - assert(strcmp(rmlvo.variant, rmlvo_backup.variant) == 0); - assert(strcmp(rmlvo.options, rmlvo_backup.options) == 0); - - XkbGetRulesDflts(&rmlvo); - assert(strcmp(rmlvo.rules, rmlvo_backup.rules) == 0); - assert(strcmp(rmlvo.model, rmlvo_backup.model) == 0); - assert(strcmp(rmlvo.layout, rmlvo_backup.layout) == 0); - assert(strcmp(rmlvo.variant, rmlvo_backup.variant) == 0); - assert(strcmp(rmlvo.options, rmlvo_backup.options) == 0); -} - - -int main(int argc, char** argv) -{ - xkb_set_get_rules_test(); - xkb_get_rules_test(); - xkb_set_rules_test(); - - return 0; -} +/**
+ * Copyright © 2009 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <xkb-config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <unistd.h>
+#include <math.h>
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include <X11/keysym.h>
+#include <X11/Xatom.h>
+#include "misc.h"
+#include "inputstr.h"
+#include "opaque.h"
+#include "property.h"
+#define XKBSRV_NEED_FILE_FUNCS
+#include <xkbsrv.h>
+#include "../xkb/xkbgeom.h"
+#include <X11/extensions/XKMformat.h>
+#include "xkbfile.h"
+#include "../xkb/xkb.h"
+#include <assert.h>
+
+/**
+ * Initialize an empty XkbRMLVOSet.
+ * Call XkbGetRulesDflts to obtain the default ruleset.
+ * Compare obtained ruleset with the built-in defaults.
+ *
+ * Result: RMLVO defaults are the same as obtained.
+ */
+static void xkb_get_rules_test(void)
+{
+ XkbRMLVOSet rmlvo = { NULL};
+ XkbGetRulesDflts(&rmlvo);
+
+
+ assert(rmlvo.rules);
+ assert(rmlvo.model);
+ assert(rmlvo.layout);
+ assert(rmlvo.variant);
+ assert(rmlvo.options);
+ assert(strcmp(rmlvo.rules, XKB_DFLT_RULES) == 0);
+ assert(strcmp(rmlvo.model, XKB_DFLT_MODEL) == 0);
+ assert(strcmp(rmlvo.layout, XKB_DFLT_LAYOUT) == 0);
+ assert(strcmp(rmlvo.variant, XKB_DFLT_VARIANT) == 0);
+ assert(strcmp(rmlvo.options, XKB_DFLT_OPTIONS) == 0);
+}
+
+/**
+ * Initialize an random XkbRMLVOSet.
+ * Call XkbGetRulesDflts to obtain the default ruleset.
+ * Compare obtained ruleset with the built-in defaults.
+ * Result: RMLVO defaults are the same as obtained.
+ */
+static void xkb_set_rules_test(void)
+{
+ XkbRMLVOSet rmlvo = {
+ .rules = "test-rules",
+ .model = "test-model",
+ .layout = "test-layout",
+ .variant = "test-variant",
+ .options = "test-options"
+ };
+ XkbRMLVOSet rmlvo_new = { NULL };
+
+ XkbSetRulesDflts(&rmlvo);
+ XkbGetRulesDflts(&rmlvo_new);
+
+ /* XkbGetRulesDflts strdups the values */
+ assert(rmlvo.rules != rmlvo_new.rules);
+ assert(rmlvo.model != rmlvo_new.model);
+ assert(rmlvo.layout != rmlvo_new.layout);
+ assert(rmlvo.variant != rmlvo_new.variant);
+ assert(rmlvo.options != rmlvo_new.options);
+
+ assert(strcmp(rmlvo.rules, rmlvo_new.rules) == 0);
+ assert(strcmp(rmlvo.model, rmlvo_new.model) == 0);
+ assert(strcmp(rmlvo.layout, rmlvo_new.layout) == 0);
+ assert(strcmp(rmlvo.variant, rmlvo_new.variant) == 0);
+ assert(strcmp(rmlvo.options, rmlvo_new.options) == 0);
+}
+
+
+/**
+ * Get the default RMLVO set.
+ * Set the default RMLVO set.
+ * Get the default RMLVO set.
+ * Repeat the last two steps.
+ *
+ * Result: RMLVO set obtained is the same as previously set.
+ */
+static void xkb_set_get_rules_test(void)
+{
+/* This test failed before XkbGetRulesDftlts changed to strdup.
+ We test this twice because the first time using XkbGetRulesDflts we obtain
+ the built-in defaults. The unexpected free isn't triggered until the second
+ XkbSetRulesDefaults.
+ */
+ XkbRMLVOSet rmlvo = { NULL };
+ XkbRMLVOSet rmlvo_backup;
+
+ XkbGetRulesDflts(&rmlvo);
+
+ /* pass 1 */
+ XkbSetRulesDflts(&rmlvo);
+ XkbGetRulesDflts(&rmlvo);
+
+ /* Make a backup copy */
+ rmlvo_backup.rules = strdup(rmlvo.rules);
+ rmlvo_backup.layout = strdup(rmlvo.layout);
+ rmlvo_backup.model = strdup(rmlvo.model);
+ rmlvo_backup.variant = strdup(rmlvo.variant);
+ rmlvo_backup.options = strdup(rmlvo.options);
+
+ /* pass 2 */
+ XkbSetRulesDflts(&rmlvo);
+
+ /* This test is iffy, because strictly we may be comparing against already
+ * freed memory */
+ assert(strcmp(rmlvo.rules, rmlvo_backup.rules) == 0);
+ assert(strcmp(rmlvo.model, rmlvo_backup.model) == 0);
+ assert(strcmp(rmlvo.layout, rmlvo_backup.layout) == 0);
+ assert(strcmp(rmlvo.variant, rmlvo_backup.variant) == 0);
+ assert(strcmp(rmlvo.options, rmlvo_backup.options) == 0);
+
+ XkbGetRulesDflts(&rmlvo);
+ assert(strcmp(rmlvo.rules, rmlvo_backup.rules) == 0);
+ assert(strcmp(rmlvo.model, rmlvo_backup.model) == 0);
+ assert(strcmp(rmlvo.layout, rmlvo_backup.layout) == 0);
+ assert(strcmp(rmlvo.variant, rmlvo_backup.variant) == 0);
+ assert(strcmp(rmlvo.options, rmlvo_backup.options) == 0);
+}
+
+
+int main(int argc, char** argv)
+{
+ xkb_set_get_rules_test();
+ xkb_get_rules_test();
+ xkb_set_rules_test();
+
+ return 0;
+}
diff --git a/xorg-server/test/xtest.c b/xorg-server/test/xtest.c index 2ab46505f..d7e3feaa3 100644 --- a/xorg-server/test/xtest.c +++ b/xorg-server/test/xtest.c @@ -1,113 +1,113 @@ -/** - * Copyright © 2009 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include <dix-config.h> -#endif -#include <stdint.h> -#include <X11/Xatom.h> -#include "input.h" -#include "inputstr.h" -#include "scrnintstr.h" -#include "exevents.h" -#include "xkbsrv.h" -#include "xserver-properties.h" - -/** - */ - -/* from Xext/xtest.c */ -extern DeviceIntPtr xtestpointer, xtestkeyboard; - -/* Needed for the screen setup, otherwise we crash during sprite initialization */ -static Bool device_cursor_init(DeviceIntPtr dev, ScreenPtr screen) { return TRUE; } - -static void xtest_init_devices(void) -{ - ScreenRec screen; - - /* random stuff that needs initialization */ - memset(&screen, 0, sizeof(screen)); - screenInfo.numScreens = 1; - screenInfo.screens[0] = &screen; - screen.myNum = 0; - screen.id = 100; - screen.width = 640; - screen.height = 480; - screen.DeviceCursorInitialize = device_cursor_init; - dixResetPrivates(); - InitAtoms(); - - XkbInitPrivates(); - - /* this also inits the xtest devices */ - InitCoreDevices(); - - assert(xtestpointer); - assert(xtestkeyboard); - assert(IsXTestDevice(xtestpointer, NULL)); - assert(IsXTestDevice(xtestkeyboard, NULL)); - assert(IsXTestDevice(xtestpointer, inputInfo.pointer)); - assert(IsXTestDevice(xtestkeyboard, inputInfo.keyboard)); - assert(GetXTestDevice(inputInfo.pointer) == xtestpointer); - assert(GetXTestDevice(inputInfo.keyboard) == xtestkeyboard); -} - -/** - * Each xtest devices has a property attached marking it. This property - * cannot be changed. - */ -static void xtest_properties(void) -{ - int rc; - char value = 1; - XIPropertyValuePtr prop; - Atom xtest_prop = XIGetKnownProperty(XI_PROP_XTEST_DEVICE); - - rc = XIGetDeviceProperty(xtestpointer, xtest_prop, &prop); - assert(rc == Success); - assert(prop); - - rc = XIGetDeviceProperty(xtestkeyboard, xtest_prop, &prop); - assert(rc == Success); - assert(prop != NULL); - - rc = XIChangeDeviceProperty(xtestpointer, xtest_prop, - XA_INTEGER, 8, PropModeReplace, 1, &value, FALSE); - assert(rc == BadAccess); - rc = XIChangeDeviceProperty(xtestkeyboard, xtest_prop, - XA_INTEGER, 8, PropModeReplace, 1, &value, FALSE); - assert(rc == BadAccess); -} - - - -int main(int argc, char** argv) -{ - xtest_init_devices(); - xtest_properties(); - - return 0; -} - - +/**
+ * Copyright © 2009 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+#include <stdint.h>
+#include <X11/Xatom.h>
+#include "input.h"
+#include "inputstr.h"
+#include "scrnintstr.h"
+#include "exevents.h"
+#include "xkbsrv.h"
+#include "xserver-properties.h"
+
+/**
+ */
+
+/* from Xext/xtest.c */
+extern DeviceIntPtr xtestpointer, xtestkeyboard;
+
+/* Needed for the screen setup, otherwise we crash during sprite initialization */
+static Bool device_cursor_init(DeviceIntPtr dev, ScreenPtr screen) { return TRUE; }
+
+static void xtest_init_devices(void)
+{
+ ScreenRec screen;
+
+ /* random stuff that needs initialization */
+ memset(&screen, 0, sizeof(screen));
+ screenInfo.numScreens = 1;
+ screenInfo.screens[0] = &screen;
+ screen.myNum = 0;
+ screen.id = 100;
+ screen.width = 640;
+ screen.height = 480;
+ screen.DeviceCursorInitialize = device_cursor_init;
+ dixResetPrivates();
+ InitAtoms();
+
+ XkbInitPrivates();
+
+ /* this also inits the xtest devices */
+ InitCoreDevices();
+
+ assert(xtestpointer);
+ assert(xtestkeyboard);
+ assert(IsXTestDevice(xtestpointer, NULL));
+ assert(IsXTestDevice(xtestkeyboard, NULL));
+ assert(IsXTestDevice(xtestpointer, inputInfo.pointer));
+ assert(IsXTestDevice(xtestkeyboard, inputInfo.keyboard));
+ assert(GetXTestDevice(inputInfo.pointer) == xtestpointer);
+ assert(GetXTestDevice(inputInfo.keyboard) == xtestkeyboard);
+}
+
+/**
+ * Each xtest devices has a property attached marking it. This property
+ * cannot be changed.
+ */
+static void xtest_properties(void)
+{
+ int rc;
+ char value = 1;
+ XIPropertyValuePtr prop;
+ Atom xtest_prop = XIGetKnownProperty(XI_PROP_XTEST_DEVICE);
+
+ rc = XIGetDeviceProperty(xtestpointer, xtest_prop, &prop);
+ assert(rc == Success);
+ assert(prop);
+
+ rc = XIGetDeviceProperty(xtestkeyboard, xtest_prop, &prop);
+ assert(rc == Success);
+ assert(prop != NULL);
+
+ rc = XIChangeDeviceProperty(xtestpointer, xtest_prop,
+ XA_INTEGER, 8, PropModeReplace, 1, &value, FALSE);
+ assert(rc == BadAccess);
+ rc = XIChangeDeviceProperty(xtestkeyboard, xtest_prop,
+ XA_INTEGER, 8, PropModeReplace, 1, &value, FALSE);
+ assert(rc == BadAccess);
+}
+
+
+
+int main(int argc, char** argv)
+{
+ xtest_init_devices();
+ xtest_properties();
+
+ return 0;
+}
+
+
|