input.c 53 KB

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