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