| 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 | */ |
| 52 | static void |
| 53 | dix_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. */ |
| 156 | static void |
| 157 | dix_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 | */ |
| 228 | static void |
| 229 | dix_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 | |
| 349 | static void |
| 350 | dix_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 | |
| 365 | static void |
| 366 | dix_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 | |
| 381 | static 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 | */ |
| 425 | static void |
| 426 | dix_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 | |
| 539 | static void |
| 540 | xi2_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 | |
| 569 | static void |
| 570 | dix_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 | |
| 931 | static void |
| 932 | test_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 | |
| 943 | static void |
| 944 | test_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 | |
| 955 | static void |
| 956 | test_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 | |
| 967 | static void |
| 968 | test_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 | |
| 980 | static void |
| 981 | include_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 | |
| 1047 | static void |
| 1048 | xi_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 | |
| 1101 | static void |
| 1102 | cmp_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 | |
| 1180 | static void |
| 1181 | dix_input_attributes(void) |
| 1182 | { |
| 1183 | InputAttributes orig = { 0 }; |
| 1184 | InputAttributes *new; |
| 1185 | char *tags[4] = { "tag1", "tag2", "tag2", NULL }; |
| 1186 | |
| 1187 | new = DuplicateInputAttributes(NULL); |
| 1188 | assert(!new); |
| 1189 | |
| 1190 | new = DuplicateInputAttributes(&orig); |
| 1191 | assert(memcmp(&orig, new, sizeof(InputAttributes)) == 0); |
| 1192 | |
| 1193 | orig.product = "product name"; |
| 1194 | new = DuplicateInputAttributes(&orig); |
| 1195 | cmp_attr_fields(&orig, new); |
| 1196 | FreeInputAttributes(new); |
| 1197 | |
| 1198 | orig.vendor = "vendor name"; |
| 1199 | new = DuplicateInputAttributes(&orig); |
| 1200 | cmp_attr_fields(&orig, new); |
| 1201 | FreeInputAttributes(new); |
| 1202 | |
| 1203 | orig.device = "device path"; |
| 1204 | new = DuplicateInputAttributes(&orig); |
| 1205 | cmp_attr_fields(&orig, new); |
| 1206 | FreeInputAttributes(new); |
| 1207 | |
| 1208 | orig.pnp_id = "PnPID"; |
| 1209 | new = DuplicateInputAttributes(&orig); |
| 1210 | cmp_attr_fields(&orig, new); |
| 1211 | FreeInputAttributes(new); |
| 1212 | |
| 1213 | orig.usb_id = "USBID"; |
| 1214 | new = DuplicateInputAttributes(&orig); |
| 1215 | cmp_attr_fields(&orig, new); |
| 1216 | FreeInputAttributes(new); |
| 1217 | |
| 1218 | orig.flags = 0xF0; |
| 1219 | new = DuplicateInputAttributes(&orig); |
| 1220 | cmp_attr_fields(&orig, new); |
| 1221 | FreeInputAttributes(new); |
| 1222 | |
| 1223 | orig.tags = tags; |
| 1224 | new = DuplicateInputAttributes(&orig); |
| 1225 | cmp_attr_fields(&orig, new); |
| 1226 | FreeInputAttributes(new); |
| 1227 | } |
| 1228 | |
| 1229 | static void |
| 1230 | dix_input_valuator_masks(void) |
| 1231 | { |
| 1232 | ValuatorMask *mask = NULL, *copy; |
| 1233 | int nvaluators = MAX_VALUATORS; |
| 1234 | double valuators[nvaluators]; |
| 1235 | int val_ranged[nvaluators]; |
| 1236 | int i; |
| 1237 | int first_val, num_vals; |
| 1238 | |
| 1239 | for (i = 0; i < nvaluators; i++) { |
| 1240 | valuators[i] = i + 0.5; |
| 1241 | val_ranged[i] = i; |
| 1242 | } |
| 1243 | |
| 1244 | mask = valuator_mask_new(nvaluators); |
| 1245 | assert(mask != NULL); |
| 1246 | assert(valuator_mask_size(mask) == 0); |
| 1247 | assert(valuator_mask_num_valuators(mask) == 0); |
| 1248 | |
| 1249 | for (i = 0; i < nvaluators; i++) { |
| 1250 | assert(!valuator_mask_isset(mask, i)); |
| 1251 | valuator_mask_set_double(mask, i, valuators[i]); |
| 1252 | assert(valuator_mask_isset(mask, i)); |
| 1253 | assert(valuator_mask_get(mask, i) == trunc(valuators[i])); |
| 1254 | assert(valuator_mask_get_double(mask, i) == valuators[i]); |
| 1255 | assert(valuator_mask_size(mask) == i + 1); |
| 1256 | assert(valuator_mask_num_valuators(mask) == i + 1); |
| 1257 | } |
| 1258 | |
| 1259 | for (i = 0; i < nvaluators; i++) { |
| 1260 | assert(valuator_mask_isset(mask, i)); |
| 1261 | valuator_mask_unset(mask, i); |
| 1262 | /* we're removing valuators from the front, so size should stay the |
| 1263 | * same until the last bit is removed */ |
| 1264 | if (i < nvaluators - 1) |
| 1265 | assert(valuator_mask_size(mask) == nvaluators); |
| 1266 | assert(!valuator_mask_isset(mask, i)); |
| 1267 | } |
| 1268 | |
| 1269 | assert(valuator_mask_size(mask) == 0); |
| 1270 | valuator_mask_zero(mask); |
| 1271 | assert(valuator_mask_size(mask) == 0); |
| 1272 | assert(valuator_mask_num_valuators(mask) == 0); |
| 1273 | for (i = 0; i < nvaluators; i++) |
| 1274 | assert(!valuator_mask_isset(mask, i)); |
| 1275 | |
| 1276 | first_val = 5; |
| 1277 | num_vals = 6; |
| 1278 | |
| 1279 | valuator_mask_set_range(mask, first_val, num_vals, val_ranged); |
| 1280 | assert(valuator_mask_size(mask) == first_val + num_vals); |
| 1281 | assert(valuator_mask_num_valuators(mask) == num_vals); |
| 1282 | for (i = 0; i < nvaluators; i++) { |
| 1283 | double val; |
| 1284 | |
| 1285 | if (i < first_val || i >= first_val + num_vals) { |
| 1286 | assert(!valuator_mask_isset(mask, i)); |
| 1287 | assert(!valuator_mask_fetch_double(mask, i, &val)); |
| 1288 | } |
| 1289 | else { |
| 1290 | assert(valuator_mask_isset(mask, i)); |
| 1291 | assert(valuator_mask_get(mask, i) == val_ranged[i - first_val]); |
| 1292 | assert(valuator_mask_get_double(mask, i) == |
| 1293 | val_ranged[i - first_val]); |
| 1294 | assert(valuator_mask_fetch_double(mask, i, &val)); |
| 1295 | assert(val_ranged[i - first_val] == val); |
| 1296 | } |
| 1297 | } |
| 1298 | |
| 1299 | copy = valuator_mask_new(nvaluators); |
| 1300 | valuator_mask_copy(copy, mask); |
| 1301 | assert(mask != copy); |
| 1302 | assert(valuator_mask_size(mask) == valuator_mask_size(copy)); |
| 1303 | assert(valuator_mask_num_valuators(mask) == |
| 1304 | valuator_mask_num_valuators(copy)); |
| 1305 | |
| 1306 | for (i = 0; i < nvaluators; i++) { |
| 1307 | double a, b; |
| 1308 | |
| 1309 | assert(valuator_mask_isset(mask, i) == valuator_mask_isset(copy, i)); |
| 1310 | |
| 1311 | if (!valuator_mask_isset(mask, i)) |
| 1312 | continue; |
| 1313 | |
| 1314 | assert(valuator_mask_get(mask, i) == valuator_mask_get(copy, i)); |
| 1315 | assert(valuator_mask_get_double(mask, i) == |
| 1316 | valuator_mask_get_double(copy, i)); |
| 1317 | assert(valuator_mask_fetch_double(mask, i, &a)); |
| 1318 | assert(valuator_mask_fetch_double(copy, i, &b)); |
| 1319 | assert(a == b); |
| 1320 | } |
| 1321 | |
| 1322 | valuator_mask_free(&mask); |
| 1323 | assert(mask == NULL); |
| 1324 | } |
| 1325 | |
| 1326 | static void |
| 1327 | dix_valuator_mode(void) |
| 1328 | { |
| 1329 | DeviceIntRec dev; |
| 1330 | const int num_axes = MAX_VALUATORS; |
| 1331 | int i; |
| 1332 | Atom atoms[MAX_VALUATORS] = { 0 }; |
| 1333 | |
| 1334 | memset(&dev, 0, sizeof(DeviceIntRec)); |
| 1335 | dev.type = MASTER_POINTER; /* claim it's a master to stop ptracccel */ |
| 1336 | |
| 1337 | assert(InitValuatorClassDeviceStruct(NULL, 0, atoms, 0, 0) == FALSE); |
| 1338 | assert(InitValuatorClassDeviceStruct(&dev, num_axes, atoms, 0, Absolute)); |
| 1339 | |
| 1340 | for (i = 0; i < num_axes; i++) { |
| 1341 | assert(valuator_get_mode(&dev, i) == Absolute); |
| 1342 | valuator_set_mode(&dev, i, Relative); |
| 1343 | assert(dev.valuator->axes[i].mode == Relative); |
| 1344 | assert(valuator_get_mode(&dev, i) == Relative); |
| 1345 | } |
| 1346 | |
| 1347 | valuator_set_mode(&dev, VALUATOR_MODE_ALL_AXES, Absolute); |
| 1348 | for (i = 0; i < num_axes; i++) |
| 1349 | assert(valuator_get_mode(&dev, i) == Absolute); |
| 1350 | |
| 1351 | valuator_set_mode(&dev, VALUATOR_MODE_ALL_AXES, Relative); |
| 1352 | for (i = 0; i < num_axes; i++) |
| 1353 | assert(valuator_get_mode(&dev, i) == Relative); |
| 1354 | } |
| 1355 | |
| 1356 | static void |
| 1357 | include_bit_test_macros(void) |
| 1358 | { |
| 1359 | uint8_t mask[9] = { 0 }; |
| 1360 | int i; |
| 1361 | |
| 1362 | for (i = 0; i < sizeof(mask) / sizeof(mask[0]); i++) { |
| 1363 | assert(BitIsOn(mask, i) == 0); |
| 1364 | SetBit(mask, i); |
| 1365 | assert(BitIsOn(mask, i) == 1); |
| 1366 | assert(! !(mask[i / 8] & (1 << (i % 8)))); |
| 1367 | assert(CountBits(mask, sizeof(mask)) == 1); |
| 1368 | ClearBit(mask, i); |
| 1369 | assert(BitIsOn(mask, i) == 0); |
| 1370 | } |
| 1371 | } |
| 1372 | |
| 1373 | /** |
| 1374 | * Ensure that val->axisVal and val->axes are aligned on doubles. |
| 1375 | */ |
| 1376 | static void |
| 1377 | dix_valuator_alloc(void) |
| 1378 | { |
| 1379 | ValuatorClassPtr v = NULL; |
| 1380 | int num_axes = 0; |
| 1381 | |
| 1382 | while (num_axes < 5) { |
| 1383 | v = AllocValuatorClass(v, num_axes); |
| 1384 | |
| 1385 | assert(v); |
| 1386 | assert(v->numAxes == num_axes); |
| 1387 | #if !defined(__i386__) && !defined(__m68k__) && !defined(__sh__) |
| 1388 | /* must be double-aligned on 64 bit */ |
| 1389 | assert(((void *) v->axisVal - (void *) v) % sizeof(double) == 0); |
| 1390 | assert(((void *) v->axes - (void *) v) % sizeof(double) == 0); |
| 1391 | #endif |
| 1392 | num_axes++; |
| 1393 | } |
| 1394 | |
| 1395 | free(v); |
| 1396 | } |
| 1397 | |
| 1398 | static void |
| 1399 | dix_get_master(void) |
| 1400 | { |
| 1401 | DeviceIntRec vcp, vck; |
| 1402 | DeviceIntRec ptr, kbd; |
| 1403 | DeviceIntRec floating; |
| 1404 | SpriteInfoRec vcp_sprite, vck_sprite; |
| 1405 | SpriteInfoRec ptr_sprite, kbd_sprite; |
| 1406 | SpriteInfoRec floating_sprite; |
| 1407 | |
| 1408 | memset(&vcp, 0, sizeof(vcp)); |
| 1409 | memset(&vck, 0, sizeof(vck)); |
| 1410 | memset(&ptr, 0, sizeof(ptr)); |
| 1411 | memset(&kbd, 0, sizeof(kbd)); |
| 1412 | memset(&floating, 0, sizeof(floating)); |
| 1413 | |
| 1414 | memset(&vcp_sprite, 0, sizeof(vcp_sprite)); |
| 1415 | memset(&vck_sprite, 0, sizeof(vck_sprite)); |
| 1416 | memset(&ptr_sprite, 0, sizeof(ptr_sprite)); |
| 1417 | memset(&kbd_sprite, 0, sizeof(kbd_sprite)); |
| 1418 | memset(&floating_sprite, 0, sizeof(floating_sprite)); |
| 1419 | |
| 1420 | vcp.type = MASTER_POINTER; |
| 1421 | vck.type = MASTER_KEYBOARD; |
| 1422 | ptr.type = SLAVE; |
| 1423 | kbd.type = SLAVE; |
| 1424 | floating.type = SLAVE; |
| 1425 | |
| 1426 | vcp.spriteInfo = &vcp_sprite; |
| 1427 | vck.spriteInfo = &vck_sprite; |
| 1428 | ptr.spriteInfo = &ptr_sprite; |
| 1429 | kbd.spriteInfo = &kbd_sprite; |
| 1430 | floating.spriteInfo = &floating_sprite; |
| 1431 | |
| 1432 | vcp_sprite.paired = &vck; |
| 1433 | vck_sprite.paired = &vcp; |
| 1434 | ptr_sprite.paired = &vcp; |
| 1435 | kbd_sprite.paired = &vck; |
| 1436 | floating_sprite.paired = &floating; |
| 1437 | |
| 1438 | vcp_sprite.spriteOwner = TRUE; |
| 1439 | floating_sprite.spriteOwner = TRUE; |
| 1440 | |
| 1441 | ptr.master = &vcp; |
| 1442 | kbd.master = &vck; |
| 1443 | |
| 1444 | assert(GetPairedDevice(&vcp) == &vck); |
| 1445 | assert(GetPairedDevice(&vck) == &vcp); |
| 1446 | assert(GetMaster(&ptr, MASTER_POINTER) == &vcp); |
| 1447 | assert(GetMaster(&ptr, MASTER_KEYBOARD) == &vck); |
| 1448 | assert(GetMaster(&kbd, MASTER_POINTER) == &vcp); |
| 1449 | assert(GetMaster(&kbd, MASTER_KEYBOARD) == &vck); |
| 1450 | assert(GetMaster(&ptr, MASTER_ATTACHED) == &vcp); |
| 1451 | assert(GetMaster(&kbd, MASTER_ATTACHED) == &vck); |
| 1452 | |
| 1453 | assert(GetPairedDevice(&floating) == &floating); |
| 1454 | assert(GetMaster(&floating, MASTER_POINTER) == NULL); |
| 1455 | assert(GetMaster(&floating, MASTER_KEYBOARD) == NULL); |
| 1456 | assert(GetMaster(&floating, MASTER_ATTACHED) == NULL); |
| 1457 | |
| 1458 | assert(GetMaster(&vcp, POINTER_OR_FLOAT) == &vcp); |
| 1459 | assert(GetMaster(&vck, POINTER_OR_FLOAT) == &vcp); |
| 1460 | assert(GetMaster(&ptr, POINTER_OR_FLOAT) == &vcp); |
| 1461 | assert(GetMaster(&kbd, POINTER_OR_FLOAT) == &vcp); |
| 1462 | |
| 1463 | assert(GetMaster(&vcp, KEYBOARD_OR_FLOAT) == &vck); |
| 1464 | assert(GetMaster(&vck, KEYBOARD_OR_FLOAT) == &vck); |
| 1465 | assert(GetMaster(&ptr, KEYBOARD_OR_FLOAT) == &vck); |
| 1466 | assert(GetMaster(&kbd, KEYBOARD_OR_FLOAT) == &vck); |
| 1467 | |
| 1468 | assert(GetMaster(&floating, KEYBOARD_OR_FLOAT) == &floating); |
| 1469 | assert(GetMaster(&floating, POINTER_OR_FLOAT) == &floating); |
| 1470 | } |
| 1471 | |
| 1472 | static void |
| 1473 | input_option_test(void) |
| 1474 | { |
| 1475 | InputOption *list = NULL; |
| 1476 | InputOption *opt; |
| 1477 | const char *val; |
| 1478 | |
| 1479 | printf("Testing input_option list interface\n"); |
| 1480 | |
| 1481 | list = input_option_new(list, "key", "value"); |
| 1482 | assert(list); |
| 1483 | opt = input_option_find(list, "key"); |
| 1484 | val = input_option_get_value(opt); |
| 1485 | assert(strcmp(val, "value") == 0); |
| 1486 | |
| 1487 | list = input_option_new(list, "2", "v2"); |
| 1488 | opt = input_option_find(list, "key"); |
| 1489 | val = input_option_get_value(opt); |
| 1490 | assert(strcmp(val, "value") == 0); |
| 1491 | |
| 1492 | opt = input_option_find(list, "2"); |
| 1493 | val = input_option_get_value(opt); |
| 1494 | assert(strcmp(val, "v2") == 0); |
| 1495 | |
| 1496 | list = input_option_new(list, "3", "v3"); |
| 1497 | |
| 1498 | /* search, delete */ |
| 1499 | opt = input_option_find(list, "key"); |
| 1500 | val = input_option_get_value(opt); |
| 1501 | assert(strcmp(val, "value") == 0); |
| 1502 | list = input_option_free_element(list, "key"); |
| 1503 | opt = input_option_find(list, "key"); |
| 1504 | assert(opt == NULL); |
| 1505 | |
| 1506 | opt = input_option_find(list, "2"); |
| 1507 | val = input_option_get_value(opt); |
| 1508 | assert(strcmp(val, "v2") == 0); |
| 1509 | list = input_option_free_element(list, "2"); |
| 1510 | opt = input_option_find(list, "2"); |
| 1511 | assert(opt == NULL); |
| 1512 | |
| 1513 | opt = input_option_find(list, "3"); |
| 1514 | val = input_option_get_value(opt); |
| 1515 | assert(strcmp(val, "v3") == 0); |
| 1516 | list = input_option_free_element(list, "3"); |
| 1517 | opt = input_option_find(list, "3"); |
| 1518 | assert(opt == NULL); |
| 1519 | |
| 1520 | /* list deletion */ |
| 1521 | list = input_option_new(list, "1", "v3"); |
| 1522 | list = input_option_new(list, "2", "v3"); |
| 1523 | list = input_option_new(list, "3", "v3"); |
| 1524 | input_option_free_list(&list); |
| 1525 | |
| 1526 | assert(list == NULL); |
| 1527 | |
| 1528 | list = input_option_new(list, "1", "v1"); |
| 1529 | list = input_option_new(list, "2", "v2"); |
| 1530 | list = input_option_new(list, "3", "v3"); |
| 1531 | |
| 1532 | /* value replacement */ |
| 1533 | opt = input_option_find(list, "2"); |
| 1534 | val = input_option_get_value(opt); |
| 1535 | assert(strcmp(val, "v2") == 0); |
| 1536 | input_option_set_value(opt, "foo"); |
| 1537 | val = input_option_get_value(opt); |
| 1538 | assert(strcmp(val, "foo") == 0); |
| 1539 | opt = input_option_find(list, "2"); |
| 1540 | val = input_option_get_value(opt); |
| 1541 | assert(strcmp(val, "foo") == 0); |
| 1542 | |
| 1543 | /* key replacement */ |
| 1544 | input_option_set_key(opt, "bar"); |
| 1545 | val = input_option_get_key(opt); |
| 1546 | assert(strcmp(val, "bar") == 0); |
| 1547 | opt = input_option_find(list, "bar"); |
| 1548 | val = input_option_get_value(opt); |
| 1549 | assert(strcmp(val, "foo") == 0); |
| 1550 | |
| 1551 | /* value replacement in input_option_new */ |
| 1552 | list = input_option_new(list, "bar", "foobar"); |
| 1553 | opt = input_option_find(list, "bar"); |
| 1554 | val = input_option_get_value(opt); |
| 1555 | assert(strcmp(val, "foobar") == 0); |
| 1556 | |
| 1557 | input_option_free_list(&list); |
| 1558 | assert(list == NULL); |
| 1559 | } |
| 1560 | |
| 1561 | static void |
| 1562 | _test_double_fp16_values(double orig_d) |
| 1563 | { |
| 1564 | FP1616 first_fp16, final_fp16; |
| 1565 | double final_d; |
| 1566 | |
| 1567 | if (orig_d > 0x7FFF) { |
| 1568 | printf("Test out of range\n"); |
| 1569 | assert(0); |
| 1570 | } |
| 1571 | |
| 1572 | first_fp16 = double_to_fp1616(orig_d); |
| 1573 | final_d = fp1616_to_double(first_fp16); |
| 1574 | final_fp16 = double_to_fp1616(final_d); |
| 1575 | |
| 1576 | /* { |
| 1577 | * char first_fp16_s[64]; |
| 1578 | * char final_fp16_s[64]; |
| 1579 | * snprintf(first_fp16_s, sizeof(first_fp16_s), "%d + %u * 2^-16", (first_fp16 & 0xffff0000) >> 16, first_fp16 & 0xffff); |
| 1580 | * snprintf(final_fp16_s, sizeof(final_fp16_s), "%d + %u * 2^-16", (final_fp16 & 0xffff0000) >> 16, final_fp16 & 0xffff); |
| 1581 | * |
| 1582 | * 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); |
| 1583 | * } |
| 1584 | */ |
| 1585 | |
| 1586 | /* since we lose precision, we only do rough range testing */ |
| 1587 | assert(final_d > orig_d - 0.1); |
| 1588 | assert(final_d < orig_d + 0.1); |
| 1589 | |
| 1590 | assert(memcmp(&first_fp16, &final_fp16, sizeof(FP1616)) == 0); |
| 1591 | |
| 1592 | if (orig_d > 0) |
| 1593 | _test_double_fp16_values(-orig_d); |
| 1594 | } |
| 1595 | |
| 1596 | static void |
| 1597 | _test_double_fp32_values(double orig_d) |
| 1598 | { |
| 1599 | FP3232 first_fp32, final_fp32; |
| 1600 | double final_d; |
| 1601 | |
| 1602 | if (orig_d > 0x7FFFFFFF) { |
| 1603 | printf("Test out of range\n"); |
| 1604 | assert(0); |
| 1605 | } |
| 1606 | |
| 1607 | first_fp32 = double_to_fp3232(orig_d); |
| 1608 | final_d = fp3232_to_double(first_fp32); |
| 1609 | final_fp32 = double_to_fp3232(final_d); |
| 1610 | |
| 1611 | /* { |
| 1612 | * char first_fp32_s[64]; |
| 1613 | * char final_fp32_s[64]; |
| 1614 | * snprintf(first_fp32_s, sizeof(first_fp32_s), "%d + %u * 2^-32", first_fp32.integral, first_fp32.frac); |
| 1615 | * snprintf(final_fp32_s, sizeof(final_fp32_s), "%d + %u * 2^-32", first_fp32.integral, final_fp32.frac); |
| 1616 | * |
| 1617 | * 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); |
| 1618 | * } |
| 1619 | */ |
| 1620 | |
| 1621 | /* since we lose precision, we only do rough range testing */ |
| 1622 | assert(final_d > orig_d - 0.1); |
| 1623 | assert(final_d < orig_d + 0.1); |
| 1624 | |
| 1625 | assert(memcmp(&first_fp32, &final_fp32, sizeof(FP3232)) == 0); |
| 1626 | |
| 1627 | if (orig_d > 0) |
| 1628 | _test_double_fp32_values(-orig_d); |
| 1629 | } |
| 1630 | |
| 1631 | static void |
| 1632 | dix_double_fp_conversion(void) |
| 1633 | { |
| 1634 | uint32_t i; |
| 1635 | |
| 1636 | printf("Testing double to FP1616/FP3232 conversions\n"); |
| 1637 | |
| 1638 | _test_double_fp16_values(0); |
| 1639 | for (i = 1; i < 0x7FFF; i <<= 1) { |
| 1640 | double val; |
| 1641 | |
| 1642 | val = i; |
| 1643 | _test_double_fp16_values(val); |
| 1644 | _test_double_fp32_values(val); |
| 1645 | |
| 1646 | /* and some pseudo-random floating points */ |
| 1647 | val = i - 0.00382; |
| 1648 | _test_double_fp16_values(val); |
| 1649 | _test_double_fp32_values(val); |
| 1650 | |
| 1651 | val = i + 0.00382; |
| 1652 | _test_double_fp16_values(val); |
| 1653 | _test_double_fp32_values(val); |
| 1654 | |
| 1655 | val = i + 0.05234; |
| 1656 | _test_double_fp16_values(val); |
| 1657 | _test_double_fp32_values(val); |
| 1658 | |
| 1659 | val = i + 0.12342; |
| 1660 | _test_double_fp16_values(val); |
| 1661 | _test_double_fp32_values(val); |
| 1662 | |
| 1663 | val = i + 0.27583; |
| 1664 | _test_double_fp16_values(val); |
| 1665 | _test_double_fp32_values(val); |
| 1666 | |
| 1667 | val = i + 0.50535; |
| 1668 | _test_double_fp16_values(val); |
| 1669 | _test_double_fp32_values(val); |
| 1670 | |
| 1671 | val = i + 0.72342; |
| 1672 | _test_double_fp16_values(val); |
| 1673 | _test_double_fp32_values(val); |
| 1674 | |
| 1675 | val = i + 0.80408; |
| 1676 | _test_double_fp16_values(val); |
| 1677 | _test_double_fp32_values(val); |
| 1678 | } |
| 1679 | |
| 1680 | for (i = 0x7FFFF; i < 0x7FFFFFFF; i <<= 1) { |
| 1681 | _test_double_fp32_values(i); |
| 1682 | /* and a few more random floating points, obtained |
| 1683 | * by faceplanting into the numpad repeatedly */ |
| 1684 | _test_double_fp32_values(i + 0.010177); |
| 1685 | _test_double_fp32_values(i + 0.213841); |
| 1686 | _test_double_fp32_values(i + 0.348720); |
| 1687 | _test_double_fp32_values(i + 0.472020); |
| 1688 | _test_double_fp32_values(i + 0.572020); |
| 1689 | _test_double_fp32_values(i + 0.892929); |
| 1690 | } |
| 1691 | } |
| 1692 | |
| 1693 | /* The mieq test verifies that events added to the queue come out in the same |
| 1694 | * order that they went in. |
| 1695 | */ |
| 1696 | static uint32_t mieq_test_event_last_processed; |
| 1697 | |
| 1698 | static void |
| 1699 | mieq_test_event_handler(int screenNum, InternalEvent *ie, DeviceIntPtr dev) |
| 1700 | { |
| 1701 | RawDeviceEvent *e = (RawDeviceEvent *) ie; |
| 1702 | |
| 1703 | assert(e->type == ET_RawMotion); |
| 1704 | assert(e->flags > mieq_test_event_last_processed); |
| 1705 | mieq_test_event_last_processed = e->flags; |
| 1706 | } |
| 1707 | |
| 1708 | static void |
| 1709 | _mieq_test_generate_events(uint32_t start, uint32_t count) |
| 1710 | { |
| 1711 | count += start; |
| 1712 | while (start < count) { |
| 1713 | RawDeviceEvent e = { 0 }; |
| 1714 | e.header = ET_Internal; |
| 1715 | e.type = ET_RawMotion; |
| 1716 | e.length = sizeof(e); |
| 1717 | e.time = GetTimeInMillis(); |
| 1718 | e.flags = start; |
| 1719 | |
| 1720 | mieqEnqueue(NULL, (InternalEvent *) &e); |
| 1721 | |
| 1722 | start++; |
| 1723 | } |
| 1724 | } |
| 1725 | |
| 1726 | #define mieq_test_generate_events(c) { _mieq_test_generate_events(next, c); next += c; } |
| 1727 | |
| 1728 | static void |
| 1729 | mieq_test(void) |
| 1730 | { |
| 1731 | uint32_t next = 1; |
| 1732 | |
| 1733 | mieq_test_event_last_processed = 0; |
| 1734 | mieqInit(); |
| 1735 | mieqSetHandler(ET_RawMotion, mieq_test_event_handler); |
| 1736 | |
| 1737 | /* Enough to fit the buffer but trigger a grow */ |
| 1738 | mieq_test_generate_events(180); |
| 1739 | |
| 1740 | /* We should resize to 512 now */ |
| 1741 | mieqProcessInputEvents(); |
| 1742 | |
| 1743 | /* Some should now get dropped */ |
| 1744 | mieq_test_generate_events(500); |
| 1745 | |
| 1746 | /* Tell us how many got dropped, 1024 now */ |
| 1747 | mieqProcessInputEvents(); |
| 1748 | |
| 1749 | /* Now make it 2048 */ |
| 1750 | mieq_test_generate_events(900); |
| 1751 | mieqProcessInputEvents(); |
| 1752 | |
| 1753 | /* Now make it 4096 (max) */ |
| 1754 | mieq_test_generate_events(1950); |
| 1755 | mieqProcessInputEvents(); |
| 1756 | |
| 1757 | /* Now overflow one last time with the maximal queue and reach the verbosity limit */ |
| 1758 | mieq_test_generate_events(10000); |
| 1759 | mieqProcessInputEvents(); |
| 1760 | |
| 1761 | mieqFini(); |
| 1762 | } |
| 1763 | |
| 1764 | /* Simple check that we're replaying events in-order */ |
| 1765 | static void |
| 1766 | process_input_proc(InternalEvent *ev, DeviceIntPtr device) |
| 1767 | { |
| 1768 | static int last_evtype = -1; |
| 1769 | |
| 1770 | if (ev->any.header == 0xac) |
| 1771 | last_evtype = -1; |
| 1772 | |
| 1773 | assert(ev->any.type == ++last_evtype); |
| 1774 | } |
| 1775 | |
| 1776 | static void |
| 1777 | dix_enqueue_events(void) |
| 1778 | { |
| 1779 | #define NEVENTS 5 |
| 1780 | DeviceIntRec dev; |
| 1781 | InternalEvent ev[NEVENTS]; |
| 1782 | SpriteInfoRec spriteInfo; |
| 1783 | SpriteRec sprite; |
| 1784 | QdEventPtr qe; |
| 1785 | int i; |
| 1786 | |
| 1787 | memset(&dev, 0, sizeof(dev)); |
| 1788 | dev.public.processInputProc = process_input_proc; |
| 1789 | |
| 1790 | memset(&spriteInfo, 0, sizeof(spriteInfo)); |
| 1791 | memset(&sprite, 0, sizeof(sprite)); |
| 1792 | dev.spriteInfo = &spriteInfo; |
| 1793 | spriteInfo.sprite = &sprite; |
| 1794 | |
| 1795 | InitEvents(); |
| 1796 | assert(xorg_list_is_empty(&syncEvents.pending)); |
| 1797 | |
| 1798 | /* this way PlayReleasedEvents really runs through all events in the |
| 1799 | * queue */ |
| 1800 | inputInfo.devices = &dev; |
| 1801 | |
| 1802 | /* to reset process_input_proc */ |
| 1803 | ev[0].any.header = 0xac; |
| 1804 | |
| 1805 | for (i = 0; i < NEVENTS; i++) { |
| 1806 | ev[i].any.length = sizeof(*ev); |
| 1807 | ev[i].any.type = i; |
| 1808 | EnqueueEvent(&ev[i], &dev); |
| 1809 | assert(!xorg_list_is_empty(&syncEvents.pending)); |
| 1810 | qe = xorg_list_last_entry(&syncEvents.pending, QdEventRec, next); |
| 1811 | assert(memcmp(qe->event, &ev[i], ev[i].any.length) == 0); |
| 1812 | qe = xorg_list_first_entry(&syncEvents.pending, QdEventRec, next); |
| 1813 | assert(memcmp(qe->event, &ev[0], ev[i].any.length) == 0); |
| 1814 | } |
| 1815 | |
| 1816 | /* calls process_input_proc */ |
| 1817 | dev.deviceGrab.sync.frozen = 1; |
| 1818 | PlayReleasedEvents(); |
| 1819 | assert(!xorg_list_is_empty(&syncEvents.pending)); |
| 1820 | |
| 1821 | dev.deviceGrab.sync.frozen = 0; |
| 1822 | PlayReleasedEvents(); |
| 1823 | assert(xorg_list_is_empty(&syncEvents.pending)); |
| 1824 | |
| 1825 | inputInfo.devices = NULL; |
| 1826 | } |
| 1827 | |
| 1828 | int |
| 1829 | main(int argc, char **argv) |
| 1830 | { |
| 1831 | dix_enqueue_events(); |
| 1832 | dix_double_fp_conversion(); |
| 1833 | dix_input_valuator_masks(); |
| 1834 | dix_input_attributes(); |
| 1835 | dix_init_valuators(); |
| 1836 | dix_event_to_core_conversion(); |
| 1837 | dix_event_to_xi1_conversion(); |
| 1838 | dix_check_grab_values(); |
| 1839 | xi2_struct_sizes(); |
| 1840 | dix_grab_matching(); |
| 1841 | dix_valuator_mode(); |
| 1842 | include_byte_padding_macros(); |
| 1843 | include_bit_test_macros(); |
| 1844 | xi_unregister_handlers(); |
| 1845 | dix_valuator_alloc(); |
| 1846 | dix_get_master(); |
| 1847 | input_option_test(); |
| 1848 | mieq_test(); |
| 1849 | |
| 1850 | return 0; |
| 1851 | } |