test-device.c 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826
  1. /*
  2. * Copyright © 2014 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. #include <config.h>
  24. #include <errno.h>
  25. #include <fcntl.h>
  26. #include <libinput.h>
  27. #include <libudev.h>
  28. #include <unistd.h>
  29. #include "libinput-util.h"
  30. #include "litest.h"
  31. START_TEST(device_sendevents_config)
  32. {
  33. struct litest_device *dev = litest_current_device();
  34. struct libinput_device *device;
  35. uint32_t modes;
  36. device = dev->libinput_device;
  37. modes = libinput_device_config_send_events_get_modes(device);
  38. litest_assert_int_eq(modes, (uint32_t)LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
  39. }
  40. END_TEST
  41. START_TEST(device_sendevents_config_invalid)
  42. {
  43. struct litest_device *dev = litest_current_device();
  44. struct libinput_device *device;
  45. enum libinput_config_status status;
  46. device = dev->libinput_device;
  47. status = libinput_device_config_send_events_set_mode(
  48. device,
  49. LIBINPUT_CONFIG_SEND_EVENTS_DISABLED | bit(4));
  50. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED);
  51. }
  52. END_TEST
  53. START_TEST(device_sendevents_config_touchpad)
  54. {
  55. struct litest_device *dev = litest_current_device();
  56. struct libinput_device *device;
  57. uint32_t modes, expected;
  58. expected = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED;
  59. /* The wacom devices in the test suite are external */
  60. if (libevdev_get_id_vendor(dev->evdev) != VENDOR_ID_WACOM &&
  61. !litest_touchpad_is_external(dev))
  62. expected |= LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE;
  63. device = dev->libinput_device;
  64. modes = libinput_device_config_send_events_get_modes(device);
  65. litest_assert_int_eq(modes, expected);
  66. }
  67. END_TEST
  68. START_TEST(device_sendevents_config_touchpad_superset)
  69. {
  70. struct litest_device *dev = litest_current_device();
  71. struct libinput_device *device;
  72. enum libinput_config_status status;
  73. uint32_t modes;
  74. /* The wacom devices in the test suite are external */
  75. if (libevdev_get_id_vendor(dev->evdev) == VENDOR_ID_WACOM ||
  76. litest_touchpad_is_external(dev))
  77. return LITEST_NOT_APPLICABLE;
  78. device = dev->libinput_device;
  79. modes = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED |
  80. LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE;
  81. status = libinput_device_config_send_events_set_mode(device, modes);
  82. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
  83. /* DISABLED supersedes the rest, expect the rest to be dropped */
  84. modes = libinput_device_config_send_events_get_mode(device);
  85. litest_assert_enum_eq(modes, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
  86. }
  87. END_TEST
  88. START_TEST(device_sendevents_config_default)
  89. {
  90. struct litest_device *dev = litest_current_device();
  91. struct libinput_device *device;
  92. uint32_t mode;
  93. device = dev->libinput_device;
  94. mode = libinput_device_config_send_events_get_mode(device);
  95. litest_assert_enum_eq(mode, LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
  96. mode = libinput_device_config_send_events_get_default_mode(device);
  97. litest_assert_enum_eq(mode, LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
  98. }
  99. END_TEST
  100. START_TEST(device_disable)
  101. {
  102. struct litest_device *dev = litest_current_device();
  103. struct libinput *li = dev->libinput;
  104. struct libinput_device *device;
  105. enum libinput_config_status status;
  106. struct libinput_event *event;
  107. struct litest_device *tmp;
  108. device = dev->libinput_device;
  109. litest_drain_events(li);
  110. status = libinput_device_config_send_events_set_mode(
  111. device,
  112. LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
  113. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
  114. /* no event from disabling */
  115. litest_assert_empty_queue(li);
  116. /* no event from disabled device */
  117. litest_event(dev, EV_REL, REL_X, 10);
  118. litest_event(dev, EV_SYN, SYN_REPORT, 0);
  119. litest_assert_empty_queue(li);
  120. /* create a new device so the resumed fd isn't the same as the
  121. suspended one */
  122. tmp = litest_add_device(li, LITEST_KEYBOARD);
  123. litest_assert_notnull(tmp);
  124. litest_drain_events(li);
  125. /* no event from resuming */
  126. status = libinput_device_config_send_events_set_mode(
  127. device,
  128. LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
  129. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
  130. litest_assert_empty_queue(li);
  131. /* event from re-enabled device */
  132. litest_event(dev, EV_REL, REL_X, 10);
  133. litest_event(dev, EV_SYN, SYN_REPORT, 0);
  134. litest_dispatch(li);
  135. event = libinput_get_event(li);
  136. litest_assert_notnull(event);
  137. litest_assert_enum_eq(libinput_event_get_type(event),
  138. LIBINPUT_EVENT_POINTER_MOTION);
  139. libinput_event_destroy(event);
  140. litest_device_destroy(tmp);
  141. }
  142. END_TEST
  143. START_TEST(device_disable_tablet)
  144. {
  145. struct litest_device *dev = litest_current_device();
  146. struct libinput *li = dev->libinput;
  147. struct libinput_device *device;
  148. enum libinput_config_status status;
  149. struct axis_replacement axes[] = {
  150. { ABS_DISTANCE, 10 },
  151. { ABS_PRESSURE, 0 },
  152. { -1, -1 },
  153. };
  154. device = dev->libinput_device;
  155. litest_drain_events(li);
  156. status = libinput_device_config_send_events_set_mode(
  157. device,
  158. LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
  159. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
  160. /* no event from disabling */
  161. litest_assert_empty_queue(li);
  162. litest_tablet_proximity_in(dev, 60, 60, axes);
  163. for (int i = 60; i < 70; i++) {
  164. litest_tablet_motion(dev, i, i, axes);
  165. litest_dispatch(li);
  166. }
  167. litest_tablet_proximity_out(dev);
  168. litest_assert_empty_queue(li);
  169. /* no event from resuming */
  170. status = libinput_device_config_send_events_set_mode(
  171. device,
  172. LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
  173. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
  174. litest_assert_empty_queue(li);
  175. }
  176. END_TEST
  177. START_TEST(device_disable_touchpad)
  178. {
  179. struct litest_device *dev = litest_current_device();
  180. struct libinput *li = dev->libinput;
  181. struct libinput_device *device;
  182. enum libinput_config_status status;
  183. device = dev->libinput_device;
  184. litest_drain_events(li);
  185. status = libinput_device_config_send_events_set_mode(
  186. device,
  187. LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
  188. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
  189. /* no event from disabling */
  190. litest_assert_empty_queue(li);
  191. litest_touch_down(dev, 0, 50, 50);
  192. litest_touch_move_to(dev, 0, 50, 50, 90, 90, 10);
  193. litest_touch_up(dev, 0);
  194. litest_assert_empty_queue(li);
  195. /* no event from resuming */
  196. status = libinput_device_config_send_events_set_mode(
  197. device,
  198. LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
  199. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
  200. litest_assert_empty_queue(li);
  201. }
  202. END_TEST
  203. START_TEST(device_disable_touch)
  204. {
  205. struct litest_device *dev = litest_current_device();
  206. struct libinput *li = dev->libinput;
  207. struct libinput_device *device;
  208. enum libinput_config_status status;
  209. device = dev->libinput_device;
  210. litest_drain_events(li);
  211. status = libinput_device_config_send_events_set_mode(
  212. device,
  213. LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
  214. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
  215. /* no event from disabling */
  216. litest_assert_empty_queue(li);
  217. litest_touch_down(dev, 0, 50, 50);
  218. litest_touch_move_to(dev, 0, 50, 50, 90, 90, 10);
  219. litest_touch_up(dev, 0);
  220. litest_assert_empty_queue(li);
  221. /* no event from resuming */
  222. status = libinput_device_config_send_events_set_mode(
  223. device,
  224. LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
  225. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
  226. litest_assert_empty_queue(li);
  227. }
  228. END_TEST
  229. START_TEST(device_disable_touch_during_touch)
  230. {
  231. struct litest_device *dev = litest_current_device();
  232. struct libinput *li = dev->libinput;
  233. struct libinput_device *device;
  234. enum libinput_config_status status;
  235. struct libinput_event *event;
  236. device = dev->libinput_device;
  237. litest_touch_down(dev, 0, 50, 50);
  238. litest_touch_move_to(dev, 0, 50, 50, 90, 90, 10);
  239. litest_drain_events(li);
  240. status = libinput_device_config_send_events_set_mode(
  241. device,
  242. LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
  243. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
  244. /* after disabling sendevents we require a touch up */
  245. litest_dispatch(li);
  246. event = libinput_get_event(li);
  247. litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_CANCEL);
  248. libinput_event_destroy(event);
  249. event = libinput_get_event(li);
  250. litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_FRAME);
  251. libinput_event_destroy(event);
  252. litest_assert_empty_queue(li);
  253. litest_touch_move_to(dev, 0, 90, 90, 50, 50, 10);
  254. litest_touch_up(dev, 0);
  255. litest_touch_down(dev, 0, 50, 50);
  256. litest_touch_move_to(dev, 0, 50, 50, 90, 90, 10);
  257. litest_touch_up(dev, 0);
  258. litest_assert_empty_queue(li);
  259. /* no event from resuming */
  260. status = libinput_device_config_send_events_set_mode(
  261. device,
  262. LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
  263. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
  264. litest_assert_empty_queue(li);
  265. }
  266. END_TEST
  267. START_TEST(device_disable_events_pending)
  268. {
  269. struct litest_device *dev = litest_current_device();
  270. struct libinput *li = dev->libinput;
  271. struct libinput_device *device;
  272. enum libinput_config_status status;
  273. struct libinput_event *event;
  274. int i;
  275. device = dev->libinput_device;
  276. litest_drain_events(li);
  277. /* put a couple of events in the queue, enough to
  278. feed the ptraccel trackers */
  279. for (i = 0; i < 10; i++) {
  280. litest_event(dev, EV_REL, REL_X, 10);
  281. litest_event(dev, EV_SYN, SYN_REPORT, 0);
  282. }
  283. litest_dispatch(li);
  284. status = libinput_device_config_send_events_set_mode(
  285. device,
  286. LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
  287. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
  288. /* expect above events */
  289. litest_wait_for_event(li);
  290. while ((event = libinput_get_event(li)) != NULL) {
  291. litest_assert_enum_eq(libinput_event_get_type(event),
  292. LIBINPUT_EVENT_POINTER_MOTION);
  293. libinput_event_destroy(event);
  294. }
  295. }
  296. END_TEST
  297. START_TEST(device_double_disable)
  298. {
  299. struct litest_device *dev = litest_current_device();
  300. struct libinput *li = dev->libinput;
  301. struct libinput_device *device;
  302. enum libinput_config_status status;
  303. device = dev->libinput_device;
  304. litest_drain_events(li);
  305. status = libinput_device_config_send_events_set_mode(
  306. device,
  307. LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
  308. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
  309. status = libinput_device_config_send_events_set_mode(
  310. device,
  311. LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
  312. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
  313. litest_assert_empty_queue(li);
  314. }
  315. END_TEST
  316. START_TEST(device_double_enable)
  317. {
  318. struct litest_device *dev = litest_current_device();
  319. struct libinput *li = dev->libinput;
  320. struct libinput_device *device;
  321. enum libinput_config_status status;
  322. device = dev->libinput_device;
  323. litest_drain_events(li);
  324. status = libinput_device_config_send_events_set_mode(
  325. device,
  326. LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
  327. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
  328. status = libinput_device_config_send_events_set_mode(
  329. device,
  330. LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
  331. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
  332. litest_assert_empty_queue(li);
  333. }
  334. END_TEST
  335. START_TEST(device_reenable_syspath_changed)
  336. {
  337. struct litest_device *litest_device;
  338. struct libinput_device *device1;
  339. enum libinput_config_status status;
  340. struct libinput_event *event;
  341. _litest_context_destroy_ struct libinput *li = litest_create_context();
  342. litest_device = litest_add_device(li, LITEST_MOUSE);
  343. device1 = litest_device->libinput_device;
  344. libinput_device_ref(device1);
  345. status = libinput_device_config_send_events_set_mode(
  346. device1,
  347. LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
  348. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
  349. litest_drain_events(li);
  350. litest_device_destroy(litest_device);
  351. litest_drain_events(li);
  352. litest_device = litest_add_device(li, LITEST_MOUSE);
  353. status = libinput_device_config_send_events_set_mode(
  354. device1,
  355. LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
  356. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
  357. /* can't really check for much here, other than that if we pump
  358. events through libinput, none of them should be from the first
  359. device */
  360. litest_event(litest_device, EV_REL, REL_X, 1);
  361. litest_event(litest_device, EV_REL, REL_Y, 1);
  362. litest_event(litest_device, EV_SYN, SYN_REPORT, 0);
  363. litest_dispatch(li);
  364. while ((event = libinput_get_event(li))) {
  365. litest_assert(libinput_event_get_device(event) != device1);
  366. libinput_event_destroy(event);
  367. }
  368. litest_device_destroy(litest_device);
  369. libinput_device_unref(device1);
  370. }
  371. END_TEST
  372. START_TEST(device_reenable_device_removed)
  373. {
  374. struct litest_device *litest_device;
  375. struct libinput_device *device;
  376. enum libinput_config_status status;
  377. _litest_context_destroy_ struct libinput *li = litest_create_context();
  378. litest_device = litest_add_device(li, LITEST_MOUSE);
  379. device = litest_device->libinput_device;
  380. libinput_device_ref(device);
  381. status = libinput_device_config_send_events_set_mode(
  382. device,
  383. LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
  384. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
  385. litest_drain_events(li);
  386. litest_device_destroy(litest_device);
  387. litest_drain_events(li);
  388. status = libinput_device_config_send_events_set_mode(
  389. device,
  390. LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
  391. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
  392. /* can't really check for much here, this really just exercises the
  393. code path. */
  394. litest_assert_empty_queue(li);
  395. libinput_device_unref(device);
  396. }
  397. END_TEST
  398. START_TEST(device_disable_release_buttons)
  399. {
  400. struct litest_device *dev = litest_current_device();
  401. struct libinput *li = dev->libinput;
  402. struct libinput_device *device;
  403. struct libinput_event *event;
  404. struct libinput_event_pointer *ptrevent;
  405. enum libinput_config_status status;
  406. device = dev->libinput_device;
  407. litest_button_click_debounced(dev, li, BTN_LEFT, true);
  408. litest_drain_events(li);
  409. status = libinput_device_config_send_events_set_mode(
  410. device,
  411. LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
  412. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
  413. litest_wait_for_event(li);
  414. event = libinput_get_event(li);
  415. litest_assert_enum_eq(libinput_event_get_type(event),
  416. LIBINPUT_EVENT_POINTER_BUTTON);
  417. ptrevent = libinput_event_get_pointer_event(event);
  418. litest_assert_int_eq(libinput_event_pointer_get_button(ptrevent),
  419. (unsigned int)BTN_LEFT);
  420. litest_assert_enum_eq(libinput_event_pointer_get_button_state(ptrevent),
  421. LIBINPUT_BUTTON_STATE_RELEASED);
  422. libinput_event_destroy(event);
  423. litest_assert_empty_queue(li);
  424. }
  425. END_TEST
  426. START_TEST(device_disable_release_keys)
  427. {
  428. struct litest_device *dev = litest_current_device();
  429. struct libinput *li = dev->libinput;
  430. struct libinput_device *device;
  431. struct libinput_event *event;
  432. struct libinput_event_keyboard *kbdevent;
  433. enum libinput_config_status status;
  434. device = dev->libinput_device;
  435. litest_keyboard_key(dev, KEY_A, true);
  436. litest_drain_events(li);
  437. status = libinput_device_config_send_events_set_mode(
  438. device,
  439. LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
  440. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
  441. litest_wait_for_event(li);
  442. event = libinput_get_event(li);
  443. litest_assert_enum_eq(libinput_event_get_type(event),
  444. LIBINPUT_EVENT_KEYBOARD_KEY);
  445. kbdevent = libinput_event_get_keyboard_event(event);
  446. litest_assert_int_eq(libinput_event_keyboard_get_key(kbdevent),
  447. (unsigned int)KEY_A);
  448. litest_assert_enum_eq(libinput_event_keyboard_get_key_state(kbdevent),
  449. LIBINPUT_KEY_STATE_RELEASED);
  450. libinput_event_destroy(event);
  451. litest_assert_empty_queue(li);
  452. }
  453. END_TEST
  454. START_TEST(device_disable_release_tap)
  455. {
  456. struct litest_device *dev = litest_current_device();
  457. struct libinput *li = dev->libinput;
  458. struct libinput_device *device;
  459. enum libinput_config_status status;
  460. device = dev->libinput_device;
  461. libinput_device_config_tap_set_enabled(device, LIBINPUT_CONFIG_TAP_ENABLED);
  462. litest_drain_events(li);
  463. litest_touch_down(dev, 0, 50, 50);
  464. litest_touch_up(dev, 0);
  465. litest_dispatch(li);
  466. status = libinput_device_config_send_events_set_mode(
  467. device,
  468. LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
  469. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
  470. /* tap happened before suspending, so we still expect the event */
  471. litest_timeout_tap(li);
  472. litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
  473. litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED);
  474. litest_assert_empty_queue(li);
  475. /* resume, make sure we don't get anything */
  476. status = libinput_device_config_send_events_set_mode(
  477. device,
  478. LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
  479. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
  480. litest_dispatch(li);
  481. litest_assert_empty_queue(li);
  482. }
  483. END_TEST
  484. START_TEST(device_disable_release_tap_n_drag)
  485. {
  486. struct litest_device *dev = litest_current_device();
  487. struct libinput *li = dev->libinput;
  488. struct libinput_device *device;
  489. enum libinput_config_status status;
  490. device = dev->libinput_device;
  491. libinput_device_config_tap_set_enabled(device, LIBINPUT_CONFIG_TAP_ENABLED);
  492. litest_drain_events(li);
  493. litest_touch_down(dev, 0, 50, 50);
  494. litest_touch_up(dev, 0);
  495. litest_touch_down(dev, 0, 50, 50);
  496. litest_timeout_tap(li);
  497. status = libinput_device_config_send_events_set_mode(
  498. device,
  499. LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
  500. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
  501. litest_dispatch(li);
  502. litest_touch_up(dev, 0);
  503. litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
  504. litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED);
  505. litest_assert_empty_queue(li);
  506. }
  507. END_TEST
  508. START_TEST(device_disable_release_softbutton)
  509. {
  510. struct litest_device *dev = litest_current_device();
  511. struct libinput *li = dev->libinput;
  512. struct libinput_device *device;
  513. enum libinput_config_status status;
  514. device = dev->libinput_device;
  515. litest_drain_events(li);
  516. litest_touch_down(dev, 0, 90, 90);
  517. litest_button_click_debounced(dev, li, BTN_LEFT, true);
  518. /* make sure softbutton works */
  519. litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED);
  520. /* disable */
  521. status = libinput_device_config_send_events_set_mode(
  522. device,
  523. LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
  524. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
  525. litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED);
  526. litest_assert_empty_queue(li);
  527. litest_button_click_debounced(dev, li, BTN_LEFT, false);
  528. litest_touch_up(dev, 0);
  529. litest_assert_empty_queue(li);
  530. /* resume, make sure we don't get anything */
  531. status = libinput_device_config_send_events_set_mode(
  532. device,
  533. LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
  534. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
  535. litest_dispatch(li);
  536. litest_assert_empty_queue(li);
  537. }
  538. END_TEST
  539. START_TEST(device_disable_topsoftbutton)
  540. {
  541. struct litest_device *dev = litest_current_device();
  542. struct litest_device *trackpoint;
  543. struct libinput *li = dev->libinput;
  544. struct libinput_device *device;
  545. enum libinput_config_status status;
  546. struct libinput_event *event;
  547. struct libinput_event_pointer *ptrevent;
  548. device = dev->libinput_device;
  549. trackpoint = litest_add_device(li, LITEST_TRACKPOINT);
  550. status = libinput_device_config_send_events_set_mode(
  551. device,
  552. LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
  553. litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
  554. litest_drain_events(li);
  555. litest_touch_down(dev, 0, 90, 10);
  556. litest_button_click_debounced(dev, li, BTN_LEFT, true);
  557. litest_button_click_debounced(dev, li, BTN_LEFT, false);
  558. litest_touch_up(dev, 0);
  559. litest_wait_for_event(li);
  560. event = libinput_get_event(li);
  561. litest_assert_enum_eq(libinput_event_get_type(event),
  562. LIBINPUT_EVENT_POINTER_BUTTON);
  563. litest_assert_ptr_eq(libinput_event_get_device(event),
  564. trackpoint->libinput_device);
  565. ptrevent = libinput_event_get_pointer_event(event);
  566. litest_assert_int_eq(libinput_event_pointer_get_button(ptrevent),
  567. (unsigned int)BTN_RIGHT);
  568. litest_assert_enum_eq(libinput_event_pointer_get_button_state(ptrevent),
  569. LIBINPUT_BUTTON_STATE_PRESSED);
  570. libinput_event_destroy(event);
  571. event = libinput_get_event(li);
  572. litest_assert_enum_eq(libinput_event_get_type(event),
  573. LIBINPUT_EVENT_POINTER_BUTTON);
  574. litest_assert_ptr_eq(libinput_event_get_device(event),
  575. trackpoint->libinput_device);
  576. ptrevent = libinput_event_get_pointer_event(event);
  577. litest_assert_int_eq(libinput_event_pointer_get_button(ptrevent),
  578. (unsigned int)BTN_RIGHT);
  579. litest_assert_enum_eq(libinput_event_pointer_get_button_state(ptrevent),
  580. LIBINPUT_BUTTON_STATE_RELEASED);
  581. libinput_event_destroy(event);
  582. litest_assert_empty_queue(li);
  583. litest_device_destroy(trackpoint);
  584. }
  585. END_TEST
  586. START_TEST(device_ids)
  587. {
  588. struct litest_device *dev = litest_current_device();
  589. const char *name;
  590. unsigned int bus, pid, vid;
  591. name = libevdev_get_name(dev->evdev);
  592. bus = libevdev_get_id_bustype(dev->evdev);
  593. pid = libevdev_get_id_product(dev->evdev);
  594. vid = libevdev_get_id_vendor(dev->evdev);
  595. litest_assert_str_eq(name, libinput_device_get_name(dev->libinput_device));
  596. litest_assert_int_eq(bus, libinput_device_get_id_bustype(dev->libinput_device));
  597. litest_assert_int_eq(pid, libinput_device_get_id_product(dev->libinput_device));
  598. litest_assert_int_eq(vid, libinput_device_get_id_vendor(dev->libinput_device));
  599. }
  600. END_TEST
  601. START_TEST(device_get_udev_handle)
  602. {
  603. struct litest_device *dev = litest_current_device();
  604. struct udev_device *udev_device;
  605. udev_device = libinput_device_get_udev_device(dev->libinput_device);
  606. litest_assert_notnull(udev_device);
  607. udev_device_unref(udev_device);
  608. }
  609. END_TEST
  610. START_TEST(device_context)
  611. {
  612. struct litest_device *dev = litest_current_device();
  613. struct libinput_seat *seat;
  614. litest_assert(dev->libinput ==
  615. libinput_device_get_context(dev->libinput_device));
  616. seat = libinput_device_get_seat(dev->libinput_device);
  617. litest_assert(dev->libinput == libinput_seat_get_context(seat));
  618. }
  619. END_TEST
  620. START_TEST(device_user_data)
  621. {
  622. struct litest_device *dev = litest_current_device();
  623. struct libinput_device *device = dev->libinput_device;
  624. void *userdata = &dev; /* not referenced */
  625. litest_assert(libinput_device_get_user_data(device) == NULL);
  626. libinput_device_set_user_data(device, userdata);
  627. litest_assert_ptr_eq(libinput_device_get_user_data(device), userdata);
  628. libinput_device_set_user_data(device, NULL);
  629. litest_assert(libinput_device_get_user_data(device) == NULL);
  630. }
  631. END_TEST
  632. START_TEST(device_group_get)
  633. {
  634. struct litest_device *dev = litest_current_device();
  635. struct libinput_device_group *group;
  636. int userdata = 10;
  637. group = libinput_device_get_device_group(dev->libinput_device);
  638. litest_assert_notnull(group);
  639. libinput_device_group_ref(group);
  640. libinput_device_group_set_user_data(group, &userdata);
  641. litest_assert_ptr_eq(&userdata, libinput_device_group_get_user_data(group));
  642. libinput_device_group_unref(group);
  643. }
  644. END_TEST
  645. START_TEST(device_group_ref)
  646. {
  647. _litest_context_destroy_ struct libinput *li = litest_create_context();
  648. struct litest_device *dev = litest_add_device(li, LITEST_MOUSE);
  649. struct libinput_device *device = dev->libinput_device;
  650. struct libinput_device_group *group;
  651. group = libinput_device_get_device_group(device);
  652. litest_assert_notnull(group);
  653. libinput_device_group_ref(group);
  654. libinput_device_ref(device);
  655. litest_drain_events(li);
  656. litest_device_destroy(dev);
  657. litest_drain_events(li);
  658. /* make sure the device is dead but the group is still around */
  659. litest_assert(libinput_device_unref(device) == NULL);
  660. libinput_device_group_ref(group);
  661. litest_assert_notnull(libinput_device_group_unref(group));
  662. litest_assert(libinput_device_group_unref(group) == NULL);
  663. }
  664. END_TEST
  665. START_TEST(device_group_leak)
  666. {
  667. struct libinput_device *device;
  668. struct libevdev_uinput *uinput;
  669. struct libinput_device_group *group;
  670. /* clang-format off */
  671. uinput = litest_create_uinput_device("test device", NULL,
  672. EV_KEY, BTN_LEFT,
  673. EV_KEY, BTN_RIGHT,
  674. EV_REL, REL_X,
  675. EV_REL, REL_Y,
  676. -1);
  677. /* clang-format on */
  678. _litest_context_destroy_ struct libinput *li = litest_create_context();
  679. device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput));
  680. group = libinput_device_get_device_group(device);
  681. libinput_device_group_ref(group);
  682. libinput_path_remove_device(device);
  683. libevdev_uinput_destroy(uinput);
  684. /* the device group leaks, check valgrind */
  685. }
  686. END_TEST
  687. START_TEST(abs_device_missing_one_abs)
  688. {
  689. struct libevdev_uinput *uinput;
  690. struct libinput_device *device;
  691. int axis = litest_test_param_get_i32(test_env->params, "axis");
  692. /* clang-format off */
  693. uinput = litest_create_uinput_device("test device", NULL,
  694. EV_KEY, BTN_LEFT,
  695. EV_KEY, BTN_RIGHT,
  696. EV_ABS, axis,
  697. -1);
  698. /* clang-format on */
  699. _litest_context_destroy_ struct libinput *li = litest_create_context();
  700. litest_disable_log_handler(li);
  701. device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput));
  702. litest_restore_log_handler(li);
  703. litest_assert(device == NULL);
  704. libevdev_uinput_destroy(uinput);
  705. }
  706. END_TEST
  707. START_TEST(abs_mt_device_missing_one_mt_abs)
  708. {
  709. struct libevdev_uinput *uinput;
  710. struct libinput_device *device;
  711. int axis = litest_test_param_get_i32(test_env->params, "axis");
  712. /* clang-format off */
  713. uinput = litest_create_uinput_device("test device", NULL,
  714. EV_KEY, BTN_LEFT,
  715. EV_KEY, BTN_RIGHT,
  716. EV_ABS, ABS_X,
  717. EV_ABS, ABS_Y,
  718. EV_ABS, ABS_MT_SLOT,
  719. EV_ABS, axis,
  720. -1);
  721. /* clang-format on */
  722. _litest_context_destroy_ struct libinput *li = litest_create_context();
  723. litest_disable_log_handler(li);
  724. device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput));
  725. litest_restore_log_handler(li);
  726. litest_assert(device == NULL);
  727. libevdev_uinput_destroy(uinput);
  728. }
  729. END_TEST
  730. static void
  731. assert_device_ignored(struct libinput *li, struct input_absinfo *absinfo)
  732. {
  733. struct libevdev_uinput *uinput;
  734. struct libinput_device *device;
  735. /* clang-format off */
  736. uinput = litest_create_uinput_abs_device("test device", NULL,
  737. absinfo,
  738. EV_KEY, BTN_LEFT,
  739. EV_KEY, BTN_RIGHT,
  740. -1);
  741. /* clang-format on */
  742. device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput));
  743. litest_assert_ptr_null(device);
  744. libevdev_uinput_destroy(uinput);
  745. }
  746. START_TEST(abs_device_no_range)
  747. {
  748. int code = _i; /* looped test */
  749. /* set x/y so libinput doesn't just reject for missing axes */
  750. struct input_absinfo absinfo[] = {
  751. { ABS_X, 0, 10, 0, 0, 0 },
  752. { ABS_Y, 0, 10, 0, 0, 0 },
  753. { code, 0, 0, 0, 0, 0 },
  754. { -1, -1, -1, -1, -1, -1 },
  755. };
  756. _litest_context_destroy_ struct libinput *li = litest_create_context();
  757. litest_disable_log_handler(li);
  758. assert_device_ignored(li, absinfo);
  759. litest_restore_log_handler(li);
  760. }
  761. END_TEST
  762. START_TEST(abs_mt_device_no_range)
  763. {
  764. int code = _i; /* looped test */
  765. /* set x/y so libinput doesn't just reject for missing axes */
  766. struct input_absinfo absinfo[] = {
  767. { ABS_X, 0, 10, 0, 0, 0 },
  768. { ABS_Y, 0, 10, 0, 0, 0 },
  769. { ABS_MT_SLOT, 0, 10, 0, 0, 0 },
  770. { ABS_MT_TRACKING_ID, 0, 255, 0, 0, 0 },
  771. { ABS_MT_POSITION_X, 0, 10, 0, 0, 0 },
  772. { ABS_MT_POSITION_Y, 0, 10, 0, 0, 0 },
  773. { code, 0, 0, 0, 0, 0 },
  774. { -1, -1, -1, -1, -1, -1 },
  775. };
  776. _litest_context_destroy_ struct libinput *li = litest_create_context();
  777. litest_disable_log_handler(li);
  778. if (code != ABS_MT_TOOL_TYPE &&
  779. code != ABS_MT_TRACKING_ID) /* kernel overrides it */
  780. assert_device_ignored(li, absinfo);
  781. litest_restore_log_handler(li);
  782. }
  783. END_TEST
  784. START_TEST(abs_device_missing_res)
  785. {
  786. struct input_absinfo absinfo[] = {
  787. { ABS_X, 0, 10, 0, 0, 10 },
  788. { ABS_Y, 0, 10, 0, 0, 10 },
  789. { -1, -1, -1, -1, -1, -1 },
  790. };
  791. int axis = litest_test_param_get_i32(test_env->params, "axis");
  792. switch (axis) {
  793. case ABS_X:
  794. absinfo[0].resolution = 0;
  795. break;
  796. case ABS_Y:
  797. absinfo[1].resolution = 0;
  798. break;
  799. default:
  800. litest_abort_msg("Invalid test parameter %d", axis);
  801. }
  802. _litest_context_destroy_ struct libinput *li = litest_create_context();
  803. litest_disable_log_handler(li);
  804. assert_device_ignored(li, absinfo);
  805. litest_restore_log_handler(li);
  806. }
  807. END_TEST
  808. START_TEST(abs_mt_device_missing_res)
  809. {
  810. struct input_absinfo absinfo[] = {
  811. { ABS_X, 0, 10, 0, 0, 10 },
  812. { ABS_Y, 0, 10, 0, 0, 10 },
  813. { ABS_MT_SLOT, 0, 2, 0, 0, 0 },
  814. { ABS_MT_TRACKING_ID, 0, 255, 0, 0, 0 },
  815. { ABS_MT_POSITION_X, 0, 10, 0, 0, 10 },
  816. { ABS_MT_POSITION_Y, 0, 10, 0, 0, 10 },
  817. { -1, -1, -1, -1, -1, -1 },
  818. };
  819. int axis = litest_test_param_get_i32(test_env->params, "axis");
  820. switch (axis) {
  821. case ABS_MT_POSITION_X:
  822. absinfo[4].resolution = 0;
  823. break;
  824. case ABS_MT_POSITION_Y:
  825. absinfo[5].resolution = 0;
  826. break;
  827. default:
  828. litest_abort_msg("Invalid test parameter %d", axis);
  829. }
  830. _litest_context_destroy_ struct libinput *li = litest_create_context();
  831. litest_disable_log_handler(li);
  832. assert_device_ignored(li, absinfo);
  833. litest_restore_log_handler(li);
  834. }
  835. END_TEST
  836. START_TEST(ignore_joystick)
  837. {
  838. struct libevdev_uinput *uinput;
  839. struct libinput_device *device;
  840. struct input_absinfo absinfo[] = {
  841. { ABS_X, 0, 10, 0, 0, 10 }, { ABS_Y, 0, 10, 0, 0, 10 },
  842. { ABS_RX, 0, 10, 0, 0, 10 }, { ABS_RY, 0, 10, 0, 0, 10 },
  843. { ABS_THROTTLE, 0, 2, 0, 0, 0 }, { ABS_RUDDER, 0, 255, 0, 0, 0 },
  844. { -1, -1, -1, -1, -1, -1 },
  845. };
  846. _litest_context_destroy_ struct libinput *li = litest_create_context();
  847. litest_disable_log_handler(li);
  848. litest_drain_events(li);
  849. /* clang-format off */
  850. uinput = litest_create_uinput_abs_device("joystick test device", NULL,
  851. absinfo,
  852. EV_KEY, BTN_TRIGGER,
  853. EV_KEY, BTN_A,
  854. -1);
  855. /* clang-format on */
  856. device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput));
  857. litest_assert_ptr_null(device);
  858. libevdev_uinput_destroy(uinput);
  859. litest_restore_log_handler(li);
  860. }
  861. END_TEST
  862. START_TEST(device_wheel_only)
  863. {
  864. struct litest_device *dev = litest_current_device();
  865. struct libinput_device *device = dev->libinput_device;
  866. litest_assert(
  867. libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER));
  868. }
  869. END_TEST
  870. START_TEST(device_accelerometer)
  871. {
  872. struct libevdev_uinput *uinput;
  873. struct libinput_device *device;
  874. struct input_absinfo absinfo[] = {
  875. { ABS_X, 0, 10, 0, 0, 10 },
  876. { ABS_Y, 0, 10, 0, 0, 10 },
  877. { ABS_Z, 0, 10, 0, 0, 10 },
  878. { -1, -1, -1, -1, -1, -1 },
  879. };
  880. _litest_context_destroy_ struct libinput *li = litest_create_context();
  881. litest_disable_log_handler(li);
  882. uinput = litest_create_uinput_abs_device("test device", NULL, absinfo, -1);
  883. device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput));
  884. litest_assert_ptr_null(device);
  885. libevdev_uinput_destroy(uinput);
  886. litest_restore_log_handler(li);
  887. }
  888. END_TEST
  889. START_TEST(device_udev_tag_wacom_tablet)
  890. {
  891. struct litest_device *dev = litest_current_device();
  892. struct libinput_device *device = dev->libinput_device;
  893. struct udev_device *d;
  894. const char *prop;
  895. d = libinput_device_get_udev_device(device);
  896. prop = udev_device_get_property_value(d, "ID_INPUT_TABLET");
  897. litest_assert_notnull(prop);
  898. udev_device_unref(d);
  899. }
  900. END_TEST
  901. START_TEST(device_nonpointer_rel)
  902. {
  903. struct libevdev_uinput *uinput;
  904. struct libinput_device *device;
  905. int i;
  906. /* clang-format off */
  907. uinput = litest_create_uinput_device("test device",
  908. NULL,
  909. EV_KEY, KEY_A,
  910. EV_KEY, KEY_B,
  911. EV_REL, REL_X,
  912. EV_REL, REL_Y,
  913. -1);
  914. /* clang-format on */
  915. _litest_context_destroy_ struct libinput *li = litest_create_context();
  916. device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput));
  917. litest_assert_notnull(device);
  918. litest_disable_log_handler(li);
  919. for (i = 0; i < 100; i++) {
  920. libevdev_uinput_write_event(uinput, EV_REL, REL_X, 1);
  921. libevdev_uinput_write_event(uinput, EV_REL, REL_Y, -1);
  922. libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
  923. litest_dispatch(li);
  924. }
  925. litest_restore_log_handler(li);
  926. libevdev_uinput_destroy(uinput);
  927. }
  928. END_TEST
  929. START_TEST(device_touchpad_rel)
  930. {
  931. struct libevdev_uinput *uinput;
  932. struct libinput_device *device;
  933. const struct input_absinfo abs[] = {
  934. { ABS_X, 0, 10, 0, 0, 10 },
  935. { ABS_Y, 0, 10, 0, 0, 10 },
  936. { ABS_MT_SLOT, 0, 2, 0, 0, 0 },
  937. { ABS_MT_TRACKING_ID, 0, 255, 0, 0, 0 },
  938. { ABS_MT_POSITION_X, 0, 10, 0, 0, 10 },
  939. { ABS_MT_POSITION_Y, 0, 10, 0, 0, 10 },
  940. { -1, -1, -1, -1, -1, -1 },
  941. };
  942. int i;
  943. /* clang-format off */
  944. uinput = litest_create_uinput_abs_device("test device",
  945. NULL, abs,
  946. EV_KEY, BTN_TOOL_FINGER,
  947. EV_KEY, BTN_TOUCH,
  948. EV_REL, REL_X,
  949. EV_REL, REL_Y,
  950. -1);
  951. /* clang-format on */
  952. _litest_context_destroy_ struct libinput *li = litest_create_context();
  953. device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput));
  954. litest_assert_notnull(device);
  955. for (i = 0; i < 100; i++) {
  956. libevdev_uinput_write_event(uinput, EV_REL, REL_X, 1);
  957. libevdev_uinput_write_event(uinput, EV_REL, REL_Y, -1);
  958. libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
  959. litest_dispatch(li);
  960. }
  961. libevdev_uinput_destroy(uinput);
  962. }
  963. END_TEST
  964. START_TEST(device_touch_rel)
  965. {
  966. struct libevdev_uinput *uinput;
  967. struct libinput_device *device;
  968. const struct input_absinfo abs[] = {
  969. { ABS_X, 0, 10, 0, 0, 10 },
  970. { ABS_Y, 0, 10, 0, 0, 10 },
  971. { ABS_MT_SLOT, 0, 2, 0, 0, 0 },
  972. { ABS_MT_TRACKING_ID, 0, 255, 0, 0, 0 },
  973. { ABS_MT_POSITION_X, 0, 10, 0, 0, 10 },
  974. { ABS_MT_POSITION_Y, 0, 10, 0, 0, 10 },
  975. { -1, -1, -1, -1, -1, -1 },
  976. };
  977. int i;
  978. /* clang-format off */
  979. uinput = litest_create_uinput_abs_device("test device",
  980. NULL, abs,
  981. EV_KEY, BTN_TOUCH,
  982. EV_REL, REL_X,
  983. EV_REL, REL_Y,
  984. -1);
  985. /* clang-format on */
  986. _litest_context_destroy_ struct libinput *li = litest_create_context();
  987. device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput));
  988. litest_assert_notnull(device);
  989. litest_disable_log_handler(li);
  990. for (i = 0; i < 100; i++) {
  991. libevdev_uinput_write_event(uinput, EV_REL, REL_X, 1);
  992. libevdev_uinput_write_event(uinput, EV_REL, REL_Y, -1);
  993. libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
  994. litest_dispatch(li);
  995. }
  996. litest_restore_log_handler(li);
  997. libevdev_uinput_destroy(uinput);
  998. }
  999. END_TEST
  1000. START_TEST(device_abs_rel)
  1001. {
  1002. struct libevdev_uinput *uinput;
  1003. struct libinput_device *device;
  1004. const struct input_absinfo abs[] = {
  1005. { ABS_X, 0, 10, 0, 0, 10 },
  1006. { ABS_Y, 0, 10, 0, 0, 10 },
  1007. { -1, -1, -1, -1, -1, -1 },
  1008. };
  1009. int i;
  1010. /* clang-format off */
  1011. uinput = litest_create_uinput_abs_device("test device",
  1012. NULL, abs,
  1013. EV_KEY, BTN_TOUCH,
  1014. EV_KEY, BTN_LEFT,
  1015. EV_REL, REL_X,
  1016. EV_REL, REL_Y,
  1017. -1);
  1018. /* clang-format on */
  1019. _litest_context_destroy_ struct libinput *li = litest_create_context();
  1020. device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput));
  1021. litest_assert_notnull(device);
  1022. for (i = 0; i < 100; i++) {
  1023. libevdev_uinput_write_event(uinput, EV_REL, REL_X, 1);
  1024. libevdev_uinput_write_event(uinput, EV_REL, REL_Y, -1);
  1025. libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
  1026. litest_dispatch(li);
  1027. }
  1028. libevdev_uinput_destroy(uinput);
  1029. }
  1030. END_TEST
  1031. START_TEST(device_quirks_no_abs_mt_y)
  1032. {
  1033. struct litest_device *dev = litest_current_device();
  1034. struct libinput *li = dev->libinput;
  1035. struct libinput_event *event;
  1036. struct libinput_event_pointer *pev;
  1037. bool hi_res_event_found, low_res_event_found;
  1038. int code, i;
  1039. hi_res_event_found = false;
  1040. low_res_event_found = false;
  1041. litest_drain_events(li);
  1042. litest_event(dev, EV_REL, REL_HWHEEL, 1);
  1043. litest_event(dev, EV_REL, REL_HWHEEL_HI_RES, 120);
  1044. litest_event(dev, EV_SYN, SYN_REPORT, 0);
  1045. litest_dispatch(li);
  1046. /* both high and low scroll end events must be sent */
  1047. for (i = 0; i < 2; i++) {
  1048. event = libinput_get_event(li);
  1049. pev = litest_is_axis_event(event,
  1050. LIBINPUT_EVENT_POINTER_SCROLL_WHEEL,
  1051. LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
  1052. LIBINPUT_POINTER_AXIS_SOURCE_WHEEL);
  1053. if (litest_is_high_res_axis_event(event)) {
  1054. litest_assert(!hi_res_event_found);
  1055. hi_res_event_found = true;
  1056. } else {
  1057. litest_assert(!low_res_event_found);
  1058. low_res_event_found = true;
  1059. }
  1060. libinput_event_destroy(libinput_event_pointer_get_base_event(pev));
  1061. }
  1062. litest_assert(low_res_event_found);
  1063. litest_assert(hi_res_event_found);
  1064. for (code = ABS_MISC + 1; code < ABS_MAX; code++) {
  1065. litest_event(dev, EV_ABS, code, 1);
  1066. litest_event(dev, EV_SYN, SYN_REPORT, 0);
  1067. litest_assert_empty_queue(li);
  1068. }
  1069. }
  1070. END_TEST
  1071. START_TEST(device_quirks_cyborg_rat_mode_button)
  1072. {
  1073. struct litest_device *dev = litest_current_device();
  1074. struct libinput_device *device = dev->libinput_device;
  1075. struct libinput *li = dev->libinput;
  1076. litest_assert(!libinput_device_pointer_has_button(device, 0x118));
  1077. litest_assert(!libinput_device_pointer_has_button(device, 0x119));
  1078. litest_assert(!libinput_device_pointer_has_button(device, 0x11a));
  1079. litest_drain_events(li);
  1080. litest_event(dev, EV_KEY, 0x118, 0);
  1081. litest_event(dev, EV_KEY, 0x119, 1);
  1082. litest_event(dev, EV_SYN, SYN_REPORT, 0);
  1083. litest_assert_empty_queue(li);
  1084. litest_event(dev, EV_KEY, 0x119, 0);
  1085. litest_event(dev, EV_KEY, 0x11a, 1);
  1086. litest_event(dev, EV_SYN, SYN_REPORT, 0);
  1087. litest_assert_empty_queue(li);
  1088. litest_event(dev, EV_KEY, 0x11a, 0);
  1089. litest_event(dev, EV_KEY, 0x118, 1);
  1090. litest_event(dev, EV_SYN, SYN_REPORT, 0);
  1091. litest_assert_empty_queue(li);
  1092. }
  1093. END_TEST
  1094. START_TEST(device_quirks_apple_magicmouse)
  1095. {
  1096. struct litest_device *dev = litest_current_device();
  1097. struct libinput *li = dev->libinput;
  1098. litest_drain_events(li);
  1099. /* ensure we get no events from the touch */
  1100. litest_touch_down(dev, 0, 50, 50);
  1101. litest_touch_move_to(dev, 0, 50, 50, 80, 80, 10);
  1102. litest_touch_up(dev, 0);
  1103. litest_assert_empty_queue(li);
  1104. }
  1105. END_TEST
  1106. START_TEST(device_quirks_logitech_marble_mouse)
  1107. {
  1108. struct litest_device *dev = litest_current_device();
  1109. struct libinput *li = dev->libinput;
  1110. litest_drain_events(li);
  1111. litest_assert(
  1112. !libinput_device_pointer_has_button(dev->libinput_device, BTN_MIDDLE));
  1113. }
  1114. END_TEST
  1115. static char *debug_messages[64] = { NULL };
  1116. LIBINPUT_ATTRIBUTE_PRINTF(3, 0)
  1117. static void
  1118. debug_log_handler(struct libinput *libinput,
  1119. enum libinput_log_priority priority,
  1120. const char *format,
  1121. va_list args)
  1122. {
  1123. char *message;
  1124. int n;
  1125. if (priority != LIBINPUT_LOG_PRIORITY_DEBUG)
  1126. return;
  1127. n = xvasprintf(&message, format, args);
  1128. litest_assert_int_gt(n, 0);
  1129. ARRAY_FOR_EACH(debug_messages, dmsg) {
  1130. if (*dmsg == NULL) {
  1131. *dmsg = message;
  1132. return;
  1133. }
  1134. }
  1135. litest_abort_msg("Out of space for debug messages");
  1136. }
  1137. START_TEST(device_quirks)
  1138. {
  1139. struct litest_device *dev;
  1140. struct libinput_device *device;
  1141. char **message;
  1142. bool disable_key_f1 = false, enable_btn_left = false,
  1143. disable_pointingstick = false, enable_buttonpad = false,
  1144. enable_direct = false, disable_direct = false, enable_semi_mt = false,
  1145. disable_semi_mt = false;
  1146. _litest_context_destroy_ struct libinput *li = litest_create_context();
  1147. libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_DEBUG);
  1148. libinput_log_set_handler(li, debug_log_handler);
  1149. dev = litest_add_device(li, LITEST_KEYBOARD_QUIRKED);
  1150. device = dev->libinput_device;
  1151. litest_assert(libinput_device_pointer_has_button(device, BTN_LEFT));
  1152. litest_assert(
  1153. libinput_device_pointer_has_button(dev->libinput_device, BTN_RIGHT));
  1154. litest_assert(!libinput_device_pointer_has_button(device, BTN_MIDDLE));
  1155. litest_assert(!libinput_device_keyboard_has_key(dev->libinput_device, KEY_F1));
  1156. litest_assert(!libinput_device_keyboard_has_key(dev->libinput_device, KEY_F2));
  1157. litest_assert(!libinput_device_keyboard_has_key(dev->libinput_device, KEY_F3));
  1158. /* Scrape the debug messages for confirmation that our quirks are
  1159. * triggered, the above checks cannot work non-key codes */
  1160. message = debug_messages;
  1161. while (*message) {
  1162. if (strstr(*message, "disabling EV_KEY KEY_F1"))
  1163. disable_key_f1 = true;
  1164. if (strstr(*message, "enabling EV_KEY BTN_LEFT"))
  1165. enable_btn_left = true;
  1166. if (strstr(*message, "enabling INPUT_PROP_BUTTONPAD"))
  1167. enable_buttonpad = true;
  1168. if (strstr(*message, "disabling INPUT_PROP_POINTING_STICK"))
  1169. disable_pointingstick = true;
  1170. if (strstr(*message, "enabling INPUT_PROP_DIRECT")) {
  1171. litest_assert(!disable_direct);
  1172. enable_direct = true;
  1173. }
  1174. if (strstr(*message, "disabling INPUT_PROP_DIRECT")) {
  1175. litest_assert(enable_direct);
  1176. disable_direct = true;
  1177. }
  1178. if (strstr(*message, "enabling INPUT_PROP_SEMI_MT")) {
  1179. litest_assert(disable_semi_mt);
  1180. enable_semi_mt = true;
  1181. }
  1182. if (strstr(*message, "disabling INPUT_PROP_SEMI_MT")) {
  1183. litest_assert(!enable_semi_mt);
  1184. disable_semi_mt = true;
  1185. }
  1186. free(*message);
  1187. message++;
  1188. }
  1189. litest_assert(disable_key_f1);
  1190. litest_assert(enable_btn_left);
  1191. litest_assert(enable_buttonpad);
  1192. litest_assert(disable_pointingstick);
  1193. litest_assert(enable_direct);
  1194. litest_assert(disable_direct);
  1195. litest_assert(enable_semi_mt);
  1196. litest_assert(disable_semi_mt);
  1197. litest_disable_log_handler(li);
  1198. litest_device_destroy(dev);
  1199. }
  1200. END_TEST
  1201. START_TEST(device_capability_at_least_one)
  1202. {
  1203. struct litest_device *dev = litest_current_device();
  1204. struct libinput_device *device = dev->libinput_device;
  1205. enum libinput_device_capability caps[] = {
  1206. LIBINPUT_DEVICE_CAP_KEYBOARD, LIBINPUT_DEVICE_CAP_POINTER,
  1207. LIBINPUT_DEVICE_CAP_TOUCH, LIBINPUT_DEVICE_CAP_TABLET_TOOL,
  1208. LIBINPUT_DEVICE_CAP_TABLET_PAD, LIBINPUT_DEVICE_CAP_GESTURE,
  1209. LIBINPUT_DEVICE_CAP_SWITCH,
  1210. };
  1211. int ncaps = 0;
  1212. ARRAY_FOR_EACH(caps, cap) {
  1213. if (libinput_device_has_capability(device, *cap))
  1214. ncaps++;
  1215. }
  1216. litest_assert_int_gt(ncaps, 0);
  1217. }
  1218. END_TEST
  1219. START_TEST(device_capability_check_invalid)
  1220. {
  1221. struct litest_device *dev = litest_current_device();
  1222. struct libinput_device *device = dev->libinput_device;
  1223. litest_assert(!libinput_device_has_capability(device, -1));
  1224. litest_assert(!libinput_device_has_capability(device, 7));
  1225. litest_assert(!libinput_device_has_capability(device, 0xffff));
  1226. }
  1227. END_TEST
  1228. START_TEST(device_capability_nocaps_ignored)
  1229. {
  1230. struct libevdev_uinput *uinput;
  1231. struct libinput_device *device;
  1232. /* SW_PEN_INSERTED isn't handled in libinput so the device is
  1233. * processed but ends up without seat capabilities and is ignored.
  1234. */
  1235. /* clang-format off */
  1236. uinput = litest_create_uinput_device("test device", NULL,
  1237. EV_SW, SW_PEN_INSERTED,
  1238. -1);
  1239. /* clang-format on */
  1240. _litest_context_destroy_ struct libinput *li = litest_create_context();
  1241. device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput));
  1242. litest_assert_ptr_null(device);
  1243. libevdev_uinput_destroy(uinput);
  1244. }
  1245. END_TEST
  1246. START_TEST(device_has_size)
  1247. {
  1248. struct litest_device *dev = litest_current_device();
  1249. struct libinput_device *device = dev->libinput_device;
  1250. double w, h;
  1251. int rc;
  1252. rc = libinput_device_get_size(device, &w, &h);
  1253. litest_assert_int_eq(rc, 0);
  1254. /* This matches the current set of test devices but may fail if
  1255. * newer ones are added */
  1256. litest_assert_double_gt(w, 30);
  1257. litest_assert_double_gt(h, 20);
  1258. }
  1259. END_TEST
  1260. START_TEST(device_has_no_size)
  1261. {
  1262. struct litest_device *dev = litest_current_device();
  1263. struct libinput_device *device = dev->libinput_device;
  1264. double w = 45, h = 67;
  1265. int rc;
  1266. rc = libinput_device_get_size(device, &w, &h);
  1267. litest_assert_int_eq(rc, -1);
  1268. litest_assert_double_eq(w, 45);
  1269. litest_assert_double_eq(h, 67);
  1270. }
  1271. END_TEST
  1272. START_TEST(device_get_output)
  1273. {
  1274. struct litest_device *dev = litest_current_device();
  1275. struct libinput_device *device = dev->libinput_device;
  1276. const char *output_name;
  1277. output_name = libinput_device_get_output_name(device);
  1278. litest_assert_str_eq(output_name, "myOutput");
  1279. }
  1280. END_TEST
  1281. START_TEST(device_no_output)
  1282. {
  1283. struct litest_device *dev = litest_current_device();
  1284. struct libinput_device *device = dev->libinput_device;
  1285. const char *output_name;
  1286. output_name = libinput_device_get_output_name(device);
  1287. litest_assert(output_name == NULL);
  1288. }
  1289. END_TEST
  1290. START_TEST(device_seat_phys_name)
  1291. {
  1292. struct litest_device *dev = litest_current_device();
  1293. struct libinput_device *device = dev->libinput_device;
  1294. struct libinput_seat *seat = libinput_device_get_seat(device);
  1295. const char *seat_name;
  1296. seat_name = libinput_seat_get_physical_name(seat);
  1297. litest_assert(streq(seat_name, "seat0"));
  1298. }
  1299. END_TEST
  1300. START_TEST(device_button_down_remove)
  1301. {
  1302. struct litest_device *lidev = litest_current_device();
  1303. struct litest_device *dev;
  1304. for (int code = 0; code < KEY_MAX; code++) {
  1305. struct libinput_event *event;
  1306. struct libinput_event_pointer *p;
  1307. bool have_down = false, have_up = false;
  1308. const char *keyname;
  1309. int button_down = 0, button_up = 0;
  1310. keyname = libevdev_event_code_get_name(EV_KEY, code);
  1311. if (!keyname || !strstartswith(keyname, "BTN_") ||
  1312. strstartswith(keyname, "BTN_TOOL_"))
  1313. continue;
  1314. if (!libevdev_has_event_code(lidev->evdev, EV_KEY, code))
  1315. continue;
  1316. _litest_context_destroy_ struct libinput *li = litest_create_context();
  1317. dev = litest_add_device(li, lidev->which);
  1318. litest_drain_events(li);
  1319. /* Clickpads require a touch down to trigger the button
  1320. * press */
  1321. if (libevdev_has_property(lidev->evdev, INPUT_PROP_BUTTONPAD)) {
  1322. litest_touch_down(dev, 0, 20, 90);
  1323. litest_dispatch(li);
  1324. }
  1325. litest_event(dev, EV_KEY, code, 1);
  1326. litest_event(dev, EV_SYN, SYN_REPORT, 0);
  1327. litest_dispatch(li);
  1328. litest_device_destroy(dev);
  1329. litest_dispatch(li);
  1330. while ((event = libinput_get_event(li))) {
  1331. if (libinput_event_get_type(event) !=
  1332. LIBINPUT_EVENT_POINTER_BUTTON) {
  1333. libinput_event_destroy(event);
  1334. continue;
  1335. }
  1336. p = libinput_event_get_pointer_event(event);
  1337. if (libinput_event_pointer_get_button_state(p)) {
  1338. litest_assert(button_down == 0);
  1339. button_down = libinput_event_pointer_get_button(p);
  1340. } else {
  1341. litest_assert(button_up == 0);
  1342. button_up = libinput_event_pointer_get_button(p);
  1343. litest_assert_int_eq(button_down, button_up);
  1344. }
  1345. libinput_event_destroy(event);
  1346. }
  1347. litest_assert_int_eq(have_down, have_up);
  1348. }
  1349. }
  1350. END_TEST
  1351. enum extreme_axis_range_idx {
  1352. EXTREME_RANGE_0_TO_INT32MAX,
  1353. EXTREME_RANGE_INT32MIN_TO_0,
  1354. EXTREME_RANGE_NEGHALF_TO_POSHALF,
  1355. };
  1356. START_TEST(abs_device_extreme_axis_range)
  1357. {
  1358. struct libevdev_uinput *uinput;
  1359. struct libinput_device *device;
  1360. int idx = litest_test_param_get_i32(test_env->params, "range");
  1361. /* All ranges exceed INT32_MAX/2, device should be rejected */
  1362. const struct {
  1363. int32_t min, max;
  1364. } ranges[] = {
  1365. [EXTREME_RANGE_0_TO_INT32MAX] = { 0, INT32_MAX },
  1366. [EXTREME_RANGE_INT32MIN_TO_0] = { INT32_MIN, 0 },
  1367. [EXTREME_RANGE_NEGHALF_TO_POSHALF] = { -(INT32_MAX / 2),
  1368. INT32_MAX / 2 },
  1369. };
  1370. struct input_absinfo absinfo[] = {
  1371. { ABS_X, ranges[idx].min, ranges[idx].max, 0, 0, 0 },
  1372. { ABS_Y, 0, 1000, 0, 0, 0 },
  1373. { -1, -1, -1, -1, -1, -1 },
  1374. };
  1375. _litest_context_destroy_ struct libinput *li = litest_create_context();
  1376. litest_disable_log_handler(li);
  1377. /* clang-format off */
  1378. uinput = litest_create_uinput_abs_device("test device", NULL,
  1379. absinfo,
  1380. EV_KEY, BTN_LEFT,
  1381. EV_KEY, BTN_RIGHT,
  1382. -1);
  1383. /* clang-format on */
  1384. device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput));
  1385. litest_restore_log_handler(li);
  1386. litest_assert_ptr_null(device);
  1387. libevdev_uinput_destroy(uinput);
  1388. }
  1389. END_TEST
  1390. START_TEST(abs_device_negative_resolution)
  1391. {
  1392. struct libevdev_uinput *uinput;
  1393. struct libinput_device *device;
  1394. struct input_absinfo absinfo[] = {
  1395. { ABS_X, 0, 1000, 0, 0, -1 }, /* negative resolution */
  1396. { ABS_Y, 0, 1000, 0, 0, -1 }, /* negative resolution */
  1397. { -1, -1, -1, -1, -1, -1 },
  1398. };
  1399. _litest_context_destroy_ struct libinput *li = litest_create_context();
  1400. litest_disable_log_handler(li);
  1401. /* clang-format off */
  1402. uinput = litest_create_uinput_abs_device("test device", NULL,
  1403. absinfo,
  1404. EV_KEY, BTN_LEFT,
  1405. EV_KEY, BTN_RIGHT,
  1406. -1);
  1407. /* clang-format on */
  1408. device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput));
  1409. litest_restore_log_handler(li);
  1410. /* Device should be rejected */
  1411. litest_assert_ptr_null(device);
  1412. libevdev_uinput_destroy(uinput);
  1413. }
  1414. END_TEST
  1415. TEST_COLLECTION(device)
  1416. {
  1417. /* clang-format off */
  1418. struct range abs_range = range_init_exclusive(0, ABS_MISC);
  1419. struct range abs_mt_range = range_init_exclusive(ABS_MT_SLOT + 1, ABS_CNT);
  1420. litest_add(device_sendevents_config, LITEST_ANY, LITEST_TOUCHPAD|LITEST_TABLET);
  1421. litest_add(device_sendevents_config_invalid, LITEST_ANY, LITEST_TABLET);
  1422. litest_add(device_sendevents_config_touchpad, LITEST_TOUCHPAD, LITEST_TABLET);
  1423. litest_add(device_sendevents_config_touchpad_superset, LITEST_TOUCHPAD, LITEST_TABLET);
  1424. litest_add(device_sendevents_config_default, LITEST_ANY, LITEST_TABLET);
  1425. litest_add(device_disable, LITEST_RELATIVE, LITEST_TABLET);
  1426. litest_add(device_disable_tablet, LITEST_TABLET, LITEST_ANY);
  1427. litest_add(device_disable_touchpad, LITEST_TOUCHPAD, LITEST_TABLET);
  1428. litest_add(device_disable_touch, LITEST_TOUCH, LITEST_ANY);
  1429. litest_add(device_disable_touch_during_touch, LITEST_TOUCH, LITEST_ANY);
  1430. litest_add(device_disable_touch, LITEST_SINGLE_TOUCH, LITEST_TOUCHPAD);
  1431. litest_add(device_disable_touch_during_touch, LITEST_SINGLE_TOUCH, LITEST_TOUCHPAD);
  1432. litest_add(device_disable_events_pending, LITEST_RELATIVE, LITEST_TOUCHPAD|LITEST_TABLET);
  1433. litest_add(device_double_disable, LITEST_ANY, LITEST_TABLET);
  1434. litest_add(device_double_enable, LITEST_ANY, LITEST_TABLET);
  1435. litest_add_no_device(device_reenable_syspath_changed);
  1436. litest_add_no_device(device_reenable_device_removed);
  1437. litest_add_for_device(device_disable_release_buttons, LITEST_MOUSE);
  1438. litest_add_for_device(device_disable_release_keys, LITEST_KEYBOARD);
  1439. litest_add(device_disable_release_tap, LITEST_TOUCHPAD, LITEST_ANY);
  1440. litest_add(device_disable_release_tap_n_drag, LITEST_TOUCHPAD, LITEST_ANY);
  1441. litest_add(device_disable_release_softbutton, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
  1442. litest_add(device_disable_topsoftbutton, LITEST_TOPBUTTONPAD, LITEST_ANY);
  1443. litest_add(device_ids, LITEST_ANY, LITEST_ANY);
  1444. litest_add_for_device(device_context, LITEST_SYNAPTICS_CLICKPAD_X220);
  1445. litest_add_for_device(device_user_data, LITEST_SYNAPTICS_CLICKPAD_X220);
  1446. litest_add(device_get_udev_handle, LITEST_ANY, LITEST_ANY);
  1447. litest_add(device_group_get, LITEST_ANY, LITEST_ANY);
  1448. litest_add_no_device(device_group_ref);
  1449. litest_add_no_device(device_group_leak);
  1450. litest_with_parameters(params, "axis", 'I', 2,
  1451. litest_named_i32(ABS_X),
  1452. litest_named_i32(ABS_Y)) {
  1453. litest_add_parametrized_no_device(abs_device_missing_one_abs, params);
  1454. litest_add_parametrized_no_device(abs_device_missing_res, params);
  1455. }
  1456. litest_with_parameters(params, "axis", 'I', 2,
  1457. litest_named_i32(ABS_MT_POSITION_X),
  1458. litest_named_i32(ABS_MT_POSITION_Y)) {
  1459. litest_add_parametrized_no_device(abs_mt_device_missing_one_mt_abs, params);
  1460. litest_add_parametrized_no_device(abs_mt_device_missing_res, params);
  1461. }
  1462. litest_add_ranged_no_device(abs_device_no_range, &abs_range);
  1463. litest_add_ranged_no_device(abs_mt_device_no_range, &abs_mt_range);
  1464. litest_add_no_device(ignore_joystick);
  1465. litest_add(device_wheel_only, LITEST_WHEEL, LITEST_RELATIVE|LITEST_ABSOLUTE|LITEST_TABLET);
  1466. litest_add_no_device(device_accelerometer);
  1467. litest_with_parameters(params, "range", 'I', 3,
  1468. litest_named_i32(EXTREME_RANGE_0_TO_INT32MAX, "0-to-INT32MAX"),
  1469. litest_named_i32(EXTREME_RANGE_INT32MIN_TO_0, "INT32MIN-to-0"),
  1470. litest_named_i32(EXTREME_RANGE_NEGHALF_TO_POSHALF, "-INT32MAX/2-to-INT32MAX/2")) {
  1471. litest_add_parametrized_no_device(abs_device_extreme_axis_range, params);
  1472. }
  1473. litest_add_no_device(abs_device_negative_resolution);
  1474. litest_add(device_udev_tag_wacom_tablet, LITEST_TABLET, LITEST_TOTEM);
  1475. litest_add_no_device(device_nonpointer_rel);
  1476. litest_add_no_device(device_touchpad_rel);
  1477. litest_add_no_device(device_touch_rel);
  1478. litest_add_no_device(device_abs_rel);
  1479. litest_add_for_device(device_quirks_no_abs_mt_y, LITEST_ANKER_MOUSE_KBD);
  1480. litest_add_for_device(device_quirks_cyborg_rat_mode_button, LITEST_CYBORG_RAT);
  1481. litest_add_for_device(device_quirks_apple_magicmouse, LITEST_MAGICMOUSE);
  1482. litest_add_for_device(device_quirks_logitech_marble_mouse, LITEST_LOGITECH_TRACKBALL);
  1483. litest_add_no_device(device_quirks);
  1484. litest_add(device_capability_at_least_one, LITEST_ANY, LITEST_ANY);
  1485. litest_add(device_capability_check_invalid, LITEST_ANY, LITEST_ANY);
  1486. litest_add_no_device(device_capability_nocaps_ignored);
  1487. litest_add(device_has_size, LITEST_TOUCHPAD, LITEST_ANY);
  1488. litest_add(device_has_size, LITEST_TABLET, LITEST_ANY);
  1489. litest_add(device_has_no_size, LITEST_ANY,
  1490. LITEST_TOUCHPAD|LITEST_TABLET|LITEST_TOUCH|LITEST_ABSOLUTE|LITEST_SINGLE_TOUCH|LITEST_TOTEM);
  1491. litest_add_for_device(device_get_output, LITEST_CALIBRATED_TOUCHSCREEN);
  1492. litest_add(device_no_output, LITEST_RELATIVE, LITEST_ANY);
  1493. litest_add(device_no_output, LITEST_KEYS, LITEST_ANY);
  1494. litest_add(device_seat_phys_name, LITEST_ANY, LITEST_ANY);
  1495. litest_add(device_button_down_remove, LITEST_BUTTON, LITEST_ANY);
  1496. /* clang-format off */
  1497. }