| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826 |
- /*
- * Copyright © 2014 Red Hat, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
- #include <config.h>
- #include <errno.h>
- #include <fcntl.h>
- #include <libinput.h>
- #include <libudev.h>
- #include <unistd.h>
- #include "libinput-util.h"
- #include "litest.h"
- START_TEST(device_sendevents_config)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput_device *device;
- uint32_t modes;
- device = dev->libinput_device;
- modes = libinput_device_config_send_events_get_modes(device);
- litest_assert_int_eq(modes, (uint32_t)LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
- }
- END_TEST
- START_TEST(device_sendevents_config_invalid)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput_device *device;
- enum libinput_config_status status;
- device = dev->libinput_device;
- status = libinput_device_config_send_events_set_mode(
- device,
- LIBINPUT_CONFIG_SEND_EVENTS_DISABLED | bit(4));
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED);
- }
- END_TEST
- START_TEST(device_sendevents_config_touchpad)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput_device *device;
- uint32_t modes, expected;
- expected = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED;
- /* The wacom devices in the test suite are external */
- if (libevdev_get_id_vendor(dev->evdev) != VENDOR_ID_WACOM &&
- !litest_touchpad_is_external(dev))
- expected |= LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE;
- device = dev->libinput_device;
- modes = libinput_device_config_send_events_get_modes(device);
- litest_assert_int_eq(modes, expected);
- }
- END_TEST
- START_TEST(device_sendevents_config_touchpad_superset)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput_device *device;
- enum libinput_config_status status;
- uint32_t modes;
- /* The wacom devices in the test suite are external */
- if (libevdev_get_id_vendor(dev->evdev) == VENDOR_ID_WACOM ||
- litest_touchpad_is_external(dev))
- return LITEST_NOT_APPLICABLE;
- device = dev->libinput_device;
- modes = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED |
- LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE;
- status = libinput_device_config_send_events_set_mode(device, modes);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- /* DISABLED supersedes the rest, expect the rest to be dropped */
- modes = libinput_device_config_send_events_get_mode(device);
- litest_assert_enum_eq(modes, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
- }
- END_TEST
- START_TEST(device_sendevents_config_default)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput_device *device;
- uint32_t mode;
- device = dev->libinput_device;
- mode = libinput_device_config_send_events_get_mode(device);
- litest_assert_enum_eq(mode, LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
- mode = libinput_device_config_send_events_get_default_mode(device);
- litest_assert_enum_eq(mode, LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
- }
- END_TEST
- START_TEST(device_disable)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_device *device;
- enum libinput_config_status status;
- struct libinput_event *event;
- struct litest_device *tmp;
- device = dev->libinput_device;
- litest_drain_events(li);
- status = libinput_device_config_send_events_set_mode(
- device,
- LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- /* no event from disabling */
- litest_assert_empty_queue(li);
- /* no event from disabled device */
- litest_event(dev, EV_REL, REL_X, 10);
- litest_event(dev, EV_SYN, SYN_REPORT, 0);
- litest_assert_empty_queue(li);
- /* create a new device so the resumed fd isn't the same as the
- suspended one */
- tmp = litest_add_device(li, LITEST_KEYBOARD);
- litest_assert_notnull(tmp);
- litest_drain_events(li);
- /* no event from resuming */
- status = libinput_device_config_send_events_set_mode(
- device,
- LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- litest_assert_empty_queue(li);
- /* event from re-enabled device */
- litest_event(dev, EV_REL, REL_X, 10);
- litest_event(dev, EV_SYN, SYN_REPORT, 0);
- litest_dispatch(li);
- event = libinput_get_event(li);
- litest_assert_notnull(event);
- litest_assert_enum_eq(libinput_event_get_type(event),
- LIBINPUT_EVENT_POINTER_MOTION);
- libinput_event_destroy(event);
- litest_device_destroy(tmp);
- }
- END_TEST
- START_TEST(device_disable_tablet)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_device *device;
- enum libinput_config_status status;
- struct axis_replacement axes[] = {
- { ABS_DISTANCE, 10 },
- { ABS_PRESSURE, 0 },
- { -1, -1 },
- };
- device = dev->libinput_device;
- litest_drain_events(li);
- status = libinput_device_config_send_events_set_mode(
- device,
- LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- /* no event from disabling */
- litest_assert_empty_queue(li);
- litest_tablet_proximity_in(dev, 60, 60, axes);
- for (int i = 60; i < 70; i++) {
- litest_tablet_motion(dev, i, i, axes);
- litest_dispatch(li);
- }
- litest_tablet_proximity_out(dev);
- litest_assert_empty_queue(li);
- /* no event from resuming */
- status = libinput_device_config_send_events_set_mode(
- device,
- LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- litest_assert_empty_queue(li);
- }
- END_TEST
- START_TEST(device_disable_touchpad)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_device *device;
- enum libinput_config_status status;
- device = dev->libinput_device;
- litest_drain_events(li);
- status = libinput_device_config_send_events_set_mode(
- device,
- LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- /* no event from disabling */
- litest_assert_empty_queue(li);
- litest_touch_down(dev, 0, 50, 50);
- litest_touch_move_to(dev, 0, 50, 50, 90, 90, 10);
- litest_touch_up(dev, 0);
- litest_assert_empty_queue(li);
- /* no event from resuming */
- status = libinput_device_config_send_events_set_mode(
- device,
- LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- litest_assert_empty_queue(li);
- }
- END_TEST
- START_TEST(device_disable_touch)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_device *device;
- enum libinput_config_status status;
- device = dev->libinput_device;
- litest_drain_events(li);
- status = libinput_device_config_send_events_set_mode(
- device,
- LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- /* no event from disabling */
- litest_assert_empty_queue(li);
- litest_touch_down(dev, 0, 50, 50);
- litest_touch_move_to(dev, 0, 50, 50, 90, 90, 10);
- litest_touch_up(dev, 0);
- litest_assert_empty_queue(li);
- /* no event from resuming */
- status = libinput_device_config_send_events_set_mode(
- device,
- LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- litest_assert_empty_queue(li);
- }
- END_TEST
- START_TEST(device_disable_touch_during_touch)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_device *device;
- enum libinput_config_status status;
- struct libinput_event *event;
- device = dev->libinput_device;
- litest_touch_down(dev, 0, 50, 50);
- litest_touch_move_to(dev, 0, 50, 50, 90, 90, 10);
- litest_drain_events(li);
- status = libinput_device_config_send_events_set_mode(
- device,
- LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- /* after disabling sendevents we require a touch up */
- litest_dispatch(li);
- event = libinput_get_event(li);
- litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_CANCEL);
- libinput_event_destroy(event);
- event = libinput_get_event(li);
- litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_FRAME);
- libinput_event_destroy(event);
- litest_assert_empty_queue(li);
- litest_touch_move_to(dev, 0, 90, 90, 50, 50, 10);
- litest_touch_up(dev, 0);
- litest_touch_down(dev, 0, 50, 50);
- litest_touch_move_to(dev, 0, 50, 50, 90, 90, 10);
- litest_touch_up(dev, 0);
- litest_assert_empty_queue(li);
- /* no event from resuming */
- status = libinput_device_config_send_events_set_mode(
- device,
- LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- litest_assert_empty_queue(li);
- }
- END_TEST
- START_TEST(device_disable_events_pending)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_device *device;
- enum libinput_config_status status;
- struct libinput_event *event;
- int i;
- device = dev->libinput_device;
- litest_drain_events(li);
- /* put a couple of events in the queue, enough to
- feed the ptraccel trackers */
- for (i = 0; i < 10; i++) {
- litest_event(dev, EV_REL, REL_X, 10);
- litest_event(dev, EV_SYN, SYN_REPORT, 0);
- }
- litest_dispatch(li);
- status = libinput_device_config_send_events_set_mode(
- device,
- LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- /* expect above events */
- litest_wait_for_event(li);
- while ((event = libinput_get_event(li)) != NULL) {
- litest_assert_enum_eq(libinput_event_get_type(event),
- LIBINPUT_EVENT_POINTER_MOTION);
- libinput_event_destroy(event);
- }
- }
- END_TEST
- START_TEST(device_double_disable)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_device *device;
- enum libinput_config_status status;
- device = dev->libinput_device;
- litest_drain_events(li);
- status = libinput_device_config_send_events_set_mode(
- device,
- LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- status = libinput_device_config_send_events_set_mode(
- device,
- LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- litest_assert_empty_queue(li);
- }
- END_TEST
- START_TEST(device_double_enable)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_device *device;
- enum libinput_config_status status;
- device = dev->libinput_device;
- litest_drain_events(li);
- status = libinput_device_config_send_events_set_mode(
- device,
- LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- status = libinput_device_config_send_events_set_mode(
- device,
- LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- litest_assert_empty_queue(li);
- }
- END_TEST
- START_TEST(device_reenable_syspath_changed)
- {
- struct litest_device *litest_device;
- struct libinput_device *device1;
- enum libinput_config_status status;
- struct libinput_event *event;
- _litest_context_destroy_ struct libinput *li = litest_create_context();
- litest_device = litest_add_device(li, LITEST_MOUSE);
- device1 = litest_device->libinput_device;
- libinput_device_ref(device1);
- status = libinput_device_config_send_events_set_mode(
- device1,
- LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- litest_drain_events(li);
- litest_device_destroy(litest_device);
- litest_drain_events(li);
- litest_device = litest_add_device(li, LITEST_MOUSE);
- status = libinput_device_config_send_events_set_mode(
- device1,
- LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- /* can't really check for much here, other than that if we pump
- events through libinput, none of them should be from the first
- device */
- litest_event(litest_device, EV_REL, REL_X, 1);
- litest_event(litest_device, EV_REL, REL_Y, 1);
- litest_event(litest_device, EV_SYN, SYN_REPORT, 0);
- litest_dispatch(li);
- while ((event = libinput_get_event(li))) {
- litest_assert(libinput_event_get_device(event) != device1);
- libinput_event_destroy(event);
- }
- litest_device_destroy(litest_device);
- libinput_device_unref(device1);
- }
- END_TEST
- START_TEST(device_reenable_device_removed)
- {
- struct litest_device *litest_device;
- struct libinput_device *device;
- enum libinput_config_status status;
- _litest_context_destroy_ struct libinput *li = litest_create_context();
- litest_device = litest_add_device(li, LITEST_MOUSE);
- device = litest_device->libinput_device;
- libinput_device_ref(device);
- status = libinput_device_config_send_events_set_mode(
- device,
- LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- litest_drain_events(li);
- litest_device_destroy(litest_device);
- litest_drain_events(li);
- status = libinput_device_config_send_events_set_mode(
- device,
- LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- /* can't really check for much here, this really just exercises the
- code path. */
- litest_assert_empty_queue(li);
- libinput_device_unref(device);
- }
- END_TEST
- START_TEST(device_disable_release_buttons)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_device *device;
- struct libinput_event *event;
- struct libinput_event_pointer *ptrevent;
- enum libinput_config_status status;
- device = dev->libinput_device;
- litest_button_click_debounced(dev, li, BTN_LEFT, true);
- litest_drain_events(li);
- status = libinput_device_config_send_events_set_mode(
- device,
- LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- litest_wait_for_event(li);
- event = libinput_get_event(li);
- litest_assert_enum_eq(libinput_event_get_type(event),
- LIBINPUT_EVENT_POINTER_BUTTON);
- ptrevent = libinput_event_get_pointer_event(event);
- litest_assert_int_eq(libinput_event_pointer_get_button(ptrevent),
- (unsigned int)BTN_LEFT);
- litest_assert_enum_eq(libinput_event_pointer_get_button_state(ptrevent),
- LIBINPUT_BUTTON_STATE_RELEASED);
- libinput_event_destroy(event);
- litest_assert_empty_queue(li);
- }
- END_TEST
- START_TEST(device_disable_release_keys)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_device *device;
- struct libinput_event *event;
- struct libinput_event_keyboard *kbdevent;
- enum libinput_config_status status;
- device = dev->libinput_device;
- litest_keyboard_key(dev, KEY_A, true);
- litest_drain_events(li);
- status = libinput_device_config_send_events_set_mode(
- device,
- LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- litest_wait_for_event(li);
- event = libinput_get_event(li);
- litest_assert_enum_eq(libinput_event_get_type(event),
- LIBINPUT_EVENT_KEYBOARD_KEY);
- kbdevent = libinput_event_get_keyboard_event(event);
- litest_assert_int_eq(libinput_event_keyboard_get_key(kbdevent),
- (unsigned int)KEY_A);
- litest_assert_enum_eq(libinput_event_keyboard_get_key_state(kbdevent),
- LIBINPUT_KEY_STATE_RELEASED);
- libinput_event_destroy(event);
- litest_assert_empty_queue(li);
- }
- END_TEST
- START_TEST(device_disable_release_tap)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_device *device;
- enum libinput_config_status status;
- device = dev->libinput_device;
- libinput_device_config_tap_set_enabled(device, LIBINPUT_CONFIG_TAP_ENABLED);
- litest_drain_events(li);
- litest_touch_down(dev, 0, 50, 50);
- litest_touch_up(dev, 0);
- litest_dispatch(li);
- status = libinput_device_config_send_events_set_mode(
- device,
- LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- /* tap happened before suspending, so we still expect the event */
- litest_timeout_tap(li);
- litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
- litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED);
- litest_assert_empty_queue(li);
- /* resume, make sure we don't get anything */
- status = libinput_device_config_send_events_set_mode(
- device,
- LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- litest_dispatch(li);
- litest_assert_empty_queue(li);
- }
- END_TEST
- START_TEST(device_disable_release_tap_n_drag)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_device *device;
- enum libinput_config_status status;
- device = dev->libinput_device;
- libinput_device_config_tap_set_enabled(device, LIBINPUT_CONFIG_TAP_ENABLED);
- litest_drain_events(li);
- litest_touch_down(dev, 0, 50, 50);
- litest_touch_up(dev, 0);
- litest_touch_down(dev, 0, 50, 50);
- litest_timeout_tap(li);
- status = libinput_device_config_send_events_set_mode(
- device,
- LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- litest_dispatch(li);
- litest_touch_up(dev, 0);
- litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
- litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED);
- litest_assert_empty_queue(li);
- }
- END_TEST
- START_TEST(device_disable_release_softbutton)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_device *device;
- enum libinput_config_status status;
- device = dev->libinput_device;
- litest_drain_events(li);
- litest_touch_down(dev, 0, 90, 90);
- litest_button_click_debounced(dev, li, BTN_LEFT, true);
- /* make sure softbutton works */
- litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED);
- /* disable */
- status = libinput_device_config_send_events_set_mode(
- device,
- LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED);
- litest_assert_empty_queue(li);
- litest_button_click_debounced(dev, li, BTN_LEFT, false);
- litest_touch_up(dev, 0);
- litest_assert_empty_queue(li);
- /* resume, make sure we don't get anything */
- status = libinput_device_config_send_events_set_mode(
- device,
- LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- litest_dispatch(li);
- litest_assert_empty_queue(li);
- }
- END_TEST
- START_TEST(device_disable_topsoftbutton)
- {
- struct litest_device *dev = litest_current_device();
- struct litest_device *trackpoint;
- struct libinput *li = dev->libinput;
- struct libinput_device *device;
- enum libinput_config_status status;
- struct libinput_event *event;
- struct libinput_event_pointer *ptrevent;
- device = dev->libinput_device;
- trackpoint = litest_add_device(li, LITEST_TRACKPOINT);
- status = libinput_device_config_send_events_set_mode(
- device,
- LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- litest_drain_events(li);
- litest_touch_down(dev, 0, 90, 10);
- litest_button_click_debounced(dev, li, BTN_LEFT, true);
- litest_button_click_debounced(dev, li, BTN_LEFT, false);
- litest_touch_up(dev, 0);
- litest_wait_for_event(li);
- event = libinput_get_event(li);
- litest_assert_enum_eq(libinput_event_get_type(event),
- LIBINPUT_EVENT_POINTER_BUTTON);
- litest_assert_ptr_eq(libinput_event_get_device(event),
- trackpoint->libinput_device);
- ptrevent = libinput_event_get_pointer_event(event);
- litest_assert_int_eq(libinput_event_pointer_get_button(ptrevent),
- (unsigned int)BTN_RIGHT);
- litest_assert_enum_eq(libinput_event_pointer_get_button_state(ptrevent),
- LIBINPUT_BUTTON_STATE_PRESSED);
- libinput_event_destroy(event);
- event = libinput_get_event(li);
- litest_assert_enum_eq(libinput_event_get_type(event),
- LIBINPUT_EVENT_POINTER_BUTTON);
- litest_assert_ptr_eq(libinput_event_get_device(event),
- trackpoint->libinput_device);
- ptrevent = libinput_event_get_pointer_event(event);
- litest_assert_int_eq(libinput_event_pointer_get_button(ptrevent),
- (unsigned int)BTN_RIGHT);
- litest_assert_enum_eq(libinput_event_pointer_get_button_state(ptrevent),
- LIBINPUT_BUTTON_STATE_RELEASED);
- libinput_event_destroy(event);
- litest_assert_empty_queue(li);
- litest_device_destroy(trackpoint);
- }
- END_TEST
- START_TEST(device_ids)
- {
- struct litest_device *dev = litest_current_device();
- const char *name;
- unsigned int bus, pid, vid;
- name = libevdev_get_name(dev->evdev);
- bus = libevdev_get_id_bustype(dev->evdev);
- pid = libevdev_get_id_product(dev->evdev);
- vid = libevdev_get_id_vendor(dev->evdev);
- litest_assert_str_eq(name, libinput_device_get_name(dev->libinput_device));
- litest_assert_int_eq(bus, libinput_device_get_id_bustype(dev->libinput_device));
- litest_assert_int_eq(pid, libinput_device_get_id_product(dev->libinput_device));
- litest_assert_int_eq(vid, libinput_device_get_id_vendor(dev->libinput_device));
- }
- END_TEST
- START_TEST(device_get_udev_handle)
- {
- struct litest_device *dev = litest_current_device();
- struct udev_device *udev_device;
- udev_device = libinput_device_get_udev_device(dev->libinput_device);
- litest_assert_notnull(udev_device);
- udev_device_unref(udev_device);
- }
- END_TEST
- START_TEST(device_context)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput_seat *seat;
- litest_assert(dev->libinput ==
- libinput_device_get_context(dev->libinput_device));
- seat = libinput_device_get_seat(dev->libinput_device);
- litest_assert(dev->libinput == libinput_seat_get_context(seat));
- }
- END_TEST
- START_TEST(device_user_data)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput_device *device = dev->libinput_device;
- void *userdata = &dev; /* not referenced */
- litest_assert(libinput_device_get_user_data(device) == NULL);
- libinput_device_set_user_data(device, userdata);
- litest_assert_ptr_eq(libinput_device_get_user_data(device), userdata);
- libinput_device_set_user_data(device, NULL);
- litest_assert(libinput_device_get_user_data(device) == NULL);
- }
- END_TEST
- START_TEST(device_group_get)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput_device_group *group;
- int userdata = 10;
- group = libinput_device_get_device_group(dev->libinput_device);
- litest_assert_notnull(group);
- libinput_device_group_ref(group);
- libinput_device_group_set_user_data(group, &userdata);
- litest_assert_ptr_eq(&userdata, libinput_device_group_get_user_data(group));
- libinput_device_group_unref(group);
- }
- END_TEST
- START_TEST(device_group_ref)
- {
- _litest_context_destroy_ struct libinput *li = litest_create_context();
- struct litest_device *dev = litest_add_device(li, LITEST_MOUSE);
- struct libinput_device *device = dev->libinput_device;
- struct libinput_device_group *group;
- group = libinput_device_get_device_group(device);
- litest_assert_notnull(group);
- libinput_device_group_ref(group);
- libinput_device_ref(device);
- litest_drain_events(li);
- litest_device_destroy(dev);
- litest_drain_events(li);
- /* make sure the device is dead but the group is still around */
- litest_assert(libinput_device_unref(device) == NULL);
- libinput_device_group_ref(group);
- litest_assert_notnull(libinput_device_group_unref(group));
- litest_assert(libinput_device_group_unref(group) == NULL);
- }
- END_TEST
- START_TEST(device_group_leak)
- {
- struct libinput_device *device;
- struct libevdev_uinput *uinput;
- struct libinput_device_group *group;
- /* clang-format off */
- uinput = litest_create_uinput_device("test device", NULL,
- EV_KEY, BTN_LEFT,
- EV_KEY, BTN_RIGHT,
- EV_REL, REL_X,
- EV_REL, REL_Y,
- -1);
- /* clang-format on */
- _litest_context_destroy_ struct libinput *li = litest_create_context();
- device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput));
- group = libinput_device_get_device_group(device);
- libinput_device_group_ref(group);
- libinput_path_remove_device(device);
- libevdev_uinput_destroy(uinput);
- /* the device group leaks, check valgrind */
- }
- END_TEST
- START_TEST(abs_device_missing_one_abs)
- {
- struct libevdev_uinput *uinput;
- struct libinput_device *device;
- int axis = litest_test_param_get_i32(test_env->params, "axis");
- /* clang-format off */
- uinput = litest_create_uinput_device("test device", NULL,
- EV_KEY, BTN_LEFT,
- EV_KEY, BTN_RIGHT,
- EV_ABS, axis,
- -1);
- /* clang-format on */
- _litest_context_destroy_ struct libinput *li = litest_create_context();
- litest_disable_log_handler(li);
- device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput));
- litest_restore_log_handler(li);
- litest_assert(device == NULL);
- libevdev_uinput_destroy(uinput);
- }
- END_TEST
- START_TEST(abs_mt_device_missing_one_mt_abs)
- {
- struct libevdev_uinput *uinput;
- struct libinput_device *device;
- int axis = litest_test_param_get_i32(test_env->params, "axis");
- /* clang-format off */
- uinput = litest_create_uinput_device("test device", NULL,
- EV_KEY, BTN_LEFT,
- EV_KEY, BTN_RIGHT,
- EV_ABS, ABS_X,
- EV_ABS, ABS_Y,
- EV_ABS, ABS_MT_SLOT,
- EV_ABS, axis,
- -1);
- /* clang-format on */
- _litest_context_destroy_ struct libinput *li = litest_create_context();
- litest_disable_log_handler(li);
- device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput));
- litest_restore_log_handler(li);
- litest_assert(device == NULL);
- libevdev_uinput_destroy(uinput);
- }
- END_TEST
- static void
- assert_device_ignored(struct libinput *li, struct input_absinfo *absinfo)
- {
- struct libevdev_uinput *uinput;
- struct libinput_device *device;
- /* clang-format off */
- uinput = litest_create_uinput_abs_device("test device", NULL,
- absinfo,
- EV_KEY, BTN_LEFT,
- EV_KEY, BTN_RIGHT,
- -1);
- /* clang-format on */
- device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput));
- litest_assert_ptr_null(device);
- libevdev_uinput_destroy(uinput);
- }
- START_TEST(abs_device_no_range)
- {
- int code = _i; /* looped test */
- /* set x/y so libinput doesn't just reject for missing axes */
- struct input_absinfo absinfo[] = {
- { ABS_X, 0, 10, 0, 0, 0 },
- { ABS_Y, 0, 10, 0, 0, 0 },
- { code, 0, 0, 0, 0, 0 },
- { -1, -1, -1, -1, -1, -1 },
- };
- _litest_context_destroy_ struct libinput *li = litest_create_context();
- litest_disable_log_handler(li);
- assert_device_ignored(li, absinfo);
- litest_restore_log_handler(li);
- }
- END_TEST
- START_TEST(abs_mt_device_no_range)
- {
- int code = _i; /* looped test */
- /* set x/y so libinput doesn't just reject for missing axes */
- struct input_absinfo absinfo[] = {
- { ABS_X, 0, 10, 0, 0, 0 },
- { ABS_Y, 0, 10, 0, 0, 0 },
- { ABS_MT_SLOT, 0, 10, 0, 0, 0 },
- { ABS_MT_TRACKING_ID, 0, 255, 0, 0, 0 },
- { ABS_MT_POSITION_X, 0, 10, 0, 0, 0 },
- { ABS_MT_POSITION_Y, 0, 10, 0, 0, 0 },
- { code, 0, 0, 0, 0, 0 },
- { -1, -1, -1, -1, -1, -1 },
- };
- _litest_context_destroy_ struct libinput *li = litest_create_context();
- litest_disable_log_handler(li);
- if (code != ABS_MT_TOOL_TYPE &&
- code != ABS_MT_TRACKING_ID) /* kernel overrides it */
- assert_device_ignored(li, absinfo);
- litest_restore_log_handler(li);
- }
- END_TEST
- START_TEST(abs_device_missing_res)
- {
- struct input_absinfo absinfo[] = {
- { ABS_X, 0, 10, 0, 0, 10 },
- { ABS_Y, 0, 10, 0, 0, 10 },
- { -1, -1, -1, -1, -1, -1 },
- };
- int axis = litest_test_param_get_i32(test_env->params, "axis");
- switch (axis) {
- case ABS_X:
- absinfo[0].resolution = 0;
- break;
- case ABS_Y:
- absinfo[1].resolution = 0;
- break;
- default:
- litest_abort_msg("Invalid test parameter %d", axis);
- }
- _litest_context_destroy_ struct libinput *li = litest_create_context();
- litest_disable_log_handler(li);
- assert_device_ignored(li, absinfo);
- litest_restore_log_handler(li);
- }
- END_TEST
- START_TEST(abs_mt_device_missing_res)
- {
- struct input_absinfo absinfo[] = {
- { ABS_X, 0, 10, 0, 0, 10 },
- { ABS_Y, 0, 10, 0, 0, 10 },
- { ABS_MT_SLOT, 0, 2, 0, 0, 0 },
- { ABS_MT_TRACKING_ID, 0, 255, 0, 0, 0 },
- { ABS_MT_POSITION_X, 0, 10, 0, 0, 10 },
- { ABS_MT_POSITION_Y, 0, 10, 0, 0, 10 },
- { -1, -1, -1, -1, -1, -1 },
- };
- int axis = litest_test_param_get_i32(test_env->params, "axis");
- switch (axis) {
- case ABS_MT_POSITION_X:
- absinfo[4].resolution = 0;
- break;
- case ABS_MT_POSITION_Y:
- absinfo[5].resolution = 0;
- break;
- default:
- litest_abort_msg("Invalid test parameter %d", axis);
- }
- _litest_context_destroy_ struct libinput *li = litest_create_context();
- litest_disable_log_handler(li);
- assert_device_ignored(li, absinfo);
- litest_restore_log_handler(li);
- }
- END_TEST
- START_TEST(ignore_joystick)
- {
- struct libevdev_uinput *uinput;
- struct libinput_device *device;
- struct input_absinfo absinfo[] = {
- { ABS_X, 0, 10, 0, 0, 10 }, { ABS_Y, 0, 10, 0, 0, 10 },
- { ABS_RX, 0, 10, 0, 0, 10 }, { ABS_RY, 0, 10, 0, 0, 10 },
- { ABS_THROTTLE, 0, 2, 0, 0, 0 }, { ABS_RUDDER, 0, 255, 0, 0, 0 },
- { -1, -1, -1, -1, -1, -1 },
- };
- _litest_context_destroy_ struct libinput *li = litest_create_context();
- litest_disable_log_handler(li);
- litest_drain_events(li);
- /* clang-format off */
- uinput = litest_create_uinput_abs_device("joystick test device", NULL,
- absinfo,
- EV_KEY, BTN_TRIGGER,
- EV_KEY, BTN_A,
- -1);
- /* clang-format on */
- device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput));
- litest_assert_ptr_null(device);
- libevdev_uinput_destroy(uinput);
- litest_restore_log_handler(li);
- }
- END_TEST
- START_TEST(device_wheel_only)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput_device *device = dev->libinput_device;
- litest_assert(
- libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER));
- }
- END_TEST
- START_TEST(device_accelerometer)
- {
- struct libevdev_uinput *uinput;
- struct libinput_device *device;
- struct input_absinfo absinfo[] = {
- { ABS_X, 0, 10, 0, 0, 10 },
- { ABS_Y, 0, 10, 0, 0, 10 },
- { ABS_Z, 0, 10, 0, 0, 10 },
- { -1, -1, -1, -1, -1, -1 },
- };
- _litest_context_destroy_ struct libinput *li = litest_create_context();
- litest_disable_log_handler(li);
- uinput = litest_create_uinput_abs_device("test device", NULL, absinfo, -1);
- device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput));
- litest_assert_ptr_null(device);
- libevdev_uinput_destroy(uinput);
- litest_restore_log_handler(li);
- }
- END_TEST
- START_TEST(device_udev_tag_wacom_tablet)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput_device *device = dev->libinput_device;
- struct udev_device *d;
- const char *prop;
- d = libinput_device_get_udev_device(device);
- prop = udev_device_get_property_value(d, "ID_INPUT_TABLET");
- litest_assert_notnull(prop);
- udev_device_unref(d);
- }
- END_TEST
- START_TEST(device_nonpointer_rel)
- {
- struct libevdev_uinput *uinput;
- struct libinput_device *device;
- int i;
- /* clang-format off */
- uinput = litest_create_uinput_device("test device",
- NULL,
- EV_KEY, KEY_A,
- EV_KEY, KEY_B,
- EV_REL, REL_X,
- EV_REL, REL_Y,
- -1);
- /* clang-format on */
- _litest_context_destroy_ struct libinput *li = litest_create_context();
- device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput));
- litest_assert_notnull(device);
- litest_disable_log_handler(li);
- for (i = 0; i < 100; i++) {
- libevdev_uinput_write_event(uinput, EV_REL, REL_X, 1);
- libevdev_uinput_write_event(uinput, EV_REL, REL_Y, -1);
- libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
- litest_dispatch(li);
- }
- litest_restore_log_handler(li);
- libevdev_uinput_destroy(uinput);
- }
- END_TEST
- START_TEST(device_touchpad_rel)
- {
- struct libevdev_uinput *uinput;
- struct libinput_device *device;
- const struct input_absinfo abs[] = {
- { ABS_X, 0, 10, 0, 0, 10 },
- { ABS_Y, 0, 10, 0, 0, 10 },
- { ABS_MT_SLOT, 0, 2, 0, 0, 0 },
- { ABS_MT_TRACKING_ID, 0, 255, 0, 0, 0 },
- { ABS_MT_POSITION_X, 0, 10, 0, 0, 10 },
- { ABS_MT_POSITION_Y, 0, 10, 0, 0, 10 },
- { -1, -1, -1, -1, -1, -1 },
- };
- int i;
- /* clang-format off */
- uinput = litest_create_uinput_abs_device("test device",
- NULL, abs,
- EV_KEY, BTN_TOOL_FINGER,
- EV_KEY, BTN_TOUCH,
- EV_REL, REL_X,
- EV_REL, REL_Y,
- -1);
- /* clang-format on */
- _litest_context_destroy_ struct libinput *li = litest_create_context();
- device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput));
- litest_assert_notnull(device);
- for (i = 0; i < 100; i++) {
- libevdev_uinput_write_event(uinput, EV_REL, REL_X, 1);
- libevdev_uinput_write_event(uinput, EV_REL, REL_Y, -1);
- libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
- litest_dispatch(li);
- }
- libevdev_uinput_destroy(uinput);
- }
- END_TEST
- START_TEST(device_touch_rel)
- {
- struct libevdev_uinput *uinput;
- struct libinput_device *device;
- const struct input_absinfo abs[] = {
- { ABS_X, 0, 10, 0, 0, 10 },
- { ABS_Y, 0, 10, 0, 0, 10 },
- { ABS_MT_SLOT, 0, 2, 0, 0, 0 },
- { ABS_MT_TRACKING_ID, 0, 255, 0, 0, 0 },
- { ABS_MT_POSITION_X, 0, 10, 0, 0, 10 },
- { ABS_MT_POSITION_Y, 0, 10, 0, 0, 10 },
- { -1, -1, -1, -1, -1, -1 },
- };
- int i;
- /* clang-format off */
- uinput = litest_create_uinput_abs_device("test device",
- NULL, abs,
- EV_KEY, BTN_TOUCH,
- EV_REL, REL_X,
- EV_REL, REL_Y,
- -1);
- /* clang-format on */
- _litest_context_destroy_ struct libinput *li = litest_create_context();
- device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput));
- litest_assert_notnull(device);
- litest_disable_log_handler(li);
- for (i = 0; i < 100; i++) {
- libevdev_uinput_write_event(uinput, EV_REL, REL_X, 1);
- libevdev_uinput_write_event(uinput, EV_REL, REL_Y, -1);
- libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
- litest_dispatch(li);
- }
- litest_restore_log_handler(li);
- libevdev_uinput_destroy(uinput);
- }
- END_TEST
- START_TEST(device_abs_rel)
- {
- struct libevdev_uinput *uinput;
- struct libinput_device *device;
- const struct input_absinfo abs[] = {
- { ABS_X, 0, 10, 0, 0, 10 },
- { ABS_Y, 0, 10, 0, 0, 10 },
- { -1, -1, -1, -1, -1, -1 },
- };
- int i;
- /* clang-format off */
- uinput = litest_create_uinput_abs_device("test device",
- NULL, abs,
- EV_KEY, BTN_TOUCH,
- EV_KEY, BTN_LEFT,
- EV_REL, REL_X,
- EV_REL, REL_Y,
- -1);
- /* clang-format on */
- _litest_context_destroy_ struct libinput *li = litest_create_context();
- device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput));
- litest_assert_notnull(device);
- for (i = 0; i < 100; i++) {
- libevdev_uinput_write_event(uinput, EV_REL, REL_X, 1);
- libevdev_uinput_write_event(uinput, EV_REL, REL_Y, -1);
- libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
- litest_dispatch(li);
- }
- libevdev_uinput_destroy(uinput);
- }
- END_TEST
- START_TEST(device_quirks_no_abs_mt_y)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_event *event;
- struct libinput_event_pointer *pev;
- bool hi_res_event_found, low_res_event_found;
- int code, i;
- hi_res_event_found = false;
- low_res_event_found = false;
- litest_drain_events(li);
- litest_event(dev, EV_REL, REL_HWHEEL, 1);
- litest_event(dev, EV_REL, REL_HWHEEL_HI_RES, 120);
- litest_event(dev, EV_SYN, SYN_REPORT, 0);
- litest_dispatch(li);
- /* both high and low scroll end events must be sent */
- for (i = 0; i < 2; i++) {
- event = libinput_get_event(li);
- pev = litest_is_axis_event(event,
- LIBINPUT_EVENT_POINTER_SCROLL_WHEEL,
- LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
- LIBINPUT_POINTER_AXIS_SOURCE_WHEEL);
- if (litest_is_high_res_axis_event(event)) {
- litest_assert(!hi_res_event_found);
- hi_res_event_found = true;
- } else {
- litest_assert(!low_res_event_found);
- low_res_event_found = true;
- }
- libinput_event_destroy(libinput_event_pointer_get_base_event(pev));
- }
- litest_assert(low_res_event_found);
- litest_assert(hi_res_event_found);
- for (code = ABS_MISC + 1; code < ABS_MAX; code++) {
- litest_event(dev, EV_ABS, code, 1);
- litest_event(dev, EV_SYN, SYN_REPORT, 0);
- litest_assert_empty_queue(li);
- }
- }
- END_TEST
- START_TEST(device_quirks_cyborg_rat_mode_button)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput_device *device = dev->libinput_device;
- struct libinput *li = dev->libinput;
- litest_assert(!libinput_device_pointer_has_button(device, 0x118));
- litest_assert(!libinput_device_pointer_has_button(device, 0x119));
- litest_assert(!libinput_device_pointer_has_button(device, 0x11a));
- litest_drain_events(li);
- litest_event(dev, EV_KEY, 0x118, 0);
- litest_event(dev, EV_KEY, 0x119, 1);
- litest_event(dev, EV_SYN, SYN_REPORT, 0);
- litest_assert_empty_queue(li);
- litest_event(dev, EV_KEY, 0x119, 0);
- litest_event(dev, EV_KEY, 0x11a, 1);
- litest_event(dev, EV_SYN, SYN_REPORT, 0);
- litest_assert_empty_queue(li);
- litest_event(dev, EV_KEY, 0x11a, 0);
- litest_event(dev, EV_KEY, 0x118, 1);
- litest_event(dev, EV_SYN, SYN_REPORT, 0);
- litest_assert_empty_queue(li);
- }
- END_TEST
- START_TEST(device_quirks_apple_magicmouse)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- litest_drain_events(li);
- /* ensure we get no events from the touch */
- litest_touch_down(dev, 0, 50, 50);
- litest_touch_move_to(dev, 0, 50, 50, 80, 80, 10);
- litest_touch_up(dev, 0);
- litest_assert_empty_queue(li);
- }
- END_TEST
- START_TEST(device_quirks_logitech_marble_mouse)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- litest_drain_events(li);
- litest_assert(
- !libinput_device_pointer_has_button(dev->libinput_device, BTN_MIDDLE));
- }
- END_TEST
- static char *debug_messages[64] = { NULL };
- LIBINPUT_ATTRIBUTE_PRINTF(3, 0)
- static void
- debug_log_handler(struct libinput *libinput,
- enum libinput_log_priority priority,
- const char *format,
- va_list args)
- {
- char *message;
- int n;
- if (priority != LIBINPUT_LOG_PRIORITY_DEBUG)
- return;
- n = xvasprintf(&message, format, args);
- litest_assert_int_gt(n, 0);
- ARRAY_FOR_EACH(debug_messages, dmsg) {
- if (*dmsg == NULL) {
- *dmsg = message;
- return;
- }
- }
- litest_abort_msg("Out of space for debug messages");
- }
- START_TEST(device_quirks)
- {
- struct litest_device *dev;
- struct libinput_device *device;
- char **message;
- bool disable_key_f1 = false, enable_btn_left = false,
- disable_pointingstick = false, enable_buttonpad = false,
- enable_direct = false, disable_direct = false, enable_semi_mt = false,
- disable_semi_mt = false;
- _litest_context_destroy_ struct libinput *li = litest_create_context();
- libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_DEBUG);
- libinput_log_set_handler(li, debug_log_handler);
- dev = litest_add_device(li, LITEST_KEYBOARD_QUIRKED);
- device = dev->libinput_device;
- litest_assert(libinput_device_pointer_has_button(device, BTN_LEFT));
- litest_assert(
- libinput_device_pointer_has_button(dev->libinput_device, BTN_RIGHT));
- litest_assert(!libinput_device_pointer_has_button(device, BTN_MIDDLE));
- litest_assert(!libinput_device_keyboard_has_key(dev->libinput_device, KEY_F1));
- litest_assert(!libinput_device_keyboard_has_key(dev->libinput_device, KEY_F2));
- litest_assert(!libinput_device_keyboard_has_key(dev->libinput_device, KEY_F3));
- /* Scrape the debug messages for confirmation that our quirks are
- * triggered, the above checks cannot work non-key codes */
- message = debug_messages;
- while (*message) {
- if (strstr(*message, "disabling EV_KEY KEY_F1"))
- disable_key_f1 = true;
- if (strstr(*message, "enabling EV_KEY BTN_LEFT"))
- enable_btn_left = true;
- if (strstr(*message, "enabling INPUT_PROP_BUTTONPAD"))
- enable_buttonpad = true;
- if (strstr(*message, "disabling INPUT_PROP_POINTING_STICK"))
- disable_pointingstick = true;
- if (strstr(*message, "enabling INPUT_PROP_DIRECT")) {
- litest_assert(!disable_direct);
- enable_direct = true;
- }
- if (strstr(*message, "disabling INPUT_PROP_DIRECT")) {
- litest_assert(enable_direct);
- disable_direct = true;
- }
- if (strstr(*message, "enabling INPUT_PROP_SEMI_MT")) {
- litest_assert(disable_semi_mt);
- enable_semi_mt = true;
- }
- if (strstr(*message, "disabling INPUT_PROP_SEMI_MT")) {
- litest_assert(!enable_semi_mt);
- disable_semi_mt = true;
- }
- free(*message);
- message++;
- }
- litest_assert(disable_key_f1);
- litest_assert(enable_btn_left);
- litest_assert(enable_buttonpad);
- litest_assert(disable_pointingstick);
- litest_assert(enable_direct);
- litest_assert(disable_direct);
- litest_assert(enable_semi_mt);
- litest_assert(disable_semi_mt);
- litest_disable_log_handler(li);
- litest_device_destroy(dev);
- }
- END_TEST
- START_TEST(device_capability_at_least_one)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput_device *device = dev->libinput_device;
- enum libinput_device_capability caps[] = {
- LIBINPUT_DEVICE_CAP_KEYBOARD, LIBINPUT_DEVICE_CAP_POINTER,
- LIBINPUT_DEVICE_CAP_TOUCH, LIBINPUT_DEVICE_CAP_TABLET_TOOL,
- LIBINPUT_DEVICE_CAP_TABLET_PAD, LIBINPUT_DEVICE_CAP_GESTURE,
- LIBINPUT_DEVICE_CAP_SWITCH,
- };
- int ncaps = 0;
- ARRAY_FOR_EACH(caps, cap) {
- if (libinput_device_has_capability(device, *cap))
- ncaps++;
- }
- litest_assert_int_gt(ncaps, 0);
- }
- END_TEST
- START_TEST(device_capability_check_invalid)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput_device *device = dev->libinput_device;
- litest_assert(!libinput_device_has_capability(device, -1));
- litest_assert(!libinput_device_has_capability(device, 7));
- litest_assert(!libinput_device_has_capability(device, 0xffff));
- }
- END_TEST
- START_TEST(device_capability_nocaps_ignored)
- {
- struct libevdev_uinput *uinput;
- struct libinput_device *device;
- /* SW_PEN_INSERTED isn't handled in libinput so the device is
- * processed but ends up without seat capabilities and is ignored.
- */
- /* clang-format off */
- uinput = litest_create_uinput_device("test device", NULL,
- EV_SW, SW_PEN_INSERTED,
- -1);
- /* clang-format on */
- _litest_context_destroy_ struct libinput *li = litest_create_context();
- device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput));
- litest_assert_ptr_null(device);
- libevdev_uinput_destroy(uinput);
- }
- END_TEST
- START_TEST(device_has_size)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput_device *device = dev->libinput_device;
- double w, h;
- int rc;
- rc = libinput_device_get_size(device, &w, &h);
- litest_assert_int_eq(rc, 0);
- /* This matches the current set of test devices but may fail if
- * newer ones are added */
- litest_assert_double_gt(w, 30);
- litest_assert_double_gt(h, 20);
- }
- END_TEST
- START_TEST(device_has_no_size)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput_device *device = dev->libinput_device;
- double w = 45, h = 67;
- int rc;
- rc = libinput_device_get_size(device, &w, &h);
- litest_assert_int_eq(rc, -1);
- litest_assert_double_eq(w, 45);
- litest_assert_double_eq(h, 67);
- }
- END_TEST
- START_TEST(device_get_output)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput_device *device = dev->libinput_device;
- const char *output_name;
- output_name = libinput_device_get_output_name(device);
- litest_assert_str_eq(output_name, "myOutput");
- }
- END_TEST
- START_TEST(device_no_output)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput_device *device = dev->libinput_device;
- const char *output_name;
- output_name = libinput_device_get_output_name(device);
- litest_assert(output_name == NULL);
- }
- END_TEST
- START_TEST(device_seat_phys_name)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput_device *device = dev->libinput_device;
- struct libinput_seat *seat = libinput_device_get_seat(device);
- const char *seat_name;
- seat_name = libinput_seat_get_physical_name(seat);
- litest_assert(streq(seat_name, "seat0"));
- }
- END_TEST
- START_TEST(device_button_down_remove)
- {
- struct litest_device *lidev = litest_current_device();
- struct litest_device *dev;
- for (int code = 0; code < KEY_MAX; code++) {
- struct libinput_event *event;
- struct libinput_event_pointer *p;
- bool have_down = false, have_up = false;
- const char *keyname;
- int button_down = 0, button_up = 0;
- keyname = libevdev_event_code_get_name(EV_KEY, code);
- if (!keyname || !strstartswith(keyname, "BTN_") ||
- strstartswith(keyname, "BTN_TOOL_"))
- continue;
- if (!libevdev_has_event_code(lidev->evdev, EV_KEY, code))
- continue;
- _litest_context_destroy_ struct libinput *li = litest_create_context();
- dev = litest_add_device(li, lidev->which);
- litest_drain_events(li);
- /* Clickpads require a touch down to trigger the button
- * press */
- if (libevdev_has_property(lidev->evdev, INPUT_PROP_BUTTONPAD)) {
- litest_touch_down(dev, 0, 20, 90);
- litest_dispatch(li);
- }
- litest_event(dev, EV_KEY, code, 1);
- litest_event(dev, EV_SYN, SYN_REPORT, 0);
- litest_dispatch(li);
- litest_device_destroy(dev);
- litest_dispatch(li);
- while ((event = libinput_get_event(li))) {
- if (libinput_event_get_type(event) !=
- LIBINPUT_EVENT_POINTER_BUTTON) {
- libinput_event_destroy(event);
- continue;
- }
- p = libinput_event_get_pointer_event(event);
- if (libinput_event_pointer_get_button_state(p)) {
- litest_assert(button_down == 0);
- button_down = libinput_event_pointer_get_button(p);
- } else {
- litest_assert(button_up == 0);
- button_up = libinput_event_pointer_get_button(p);
- litest_assert_int_eq(button_down, button_up);
- }
- libinput_event_destroy(event);
- }
- litest_assert_int_eq(have_down, have_up);
- }
- }
- END_TEST
- enum extreme_axis_range_idx {
- EXTREME_RANGE_0_TO_INT32MAX,
- EXTREME_RANGE_INT32MIN_TO_0,
- EXTREME_RANGE_NEGHALF_TO_POSHALF,
- };
- START_TEST(abs_device_extreme_axis_range)
- {
- struct libevdev_uinput *uinput;
- struct libinput_device *device;
- int idx = litest_test_param_get_i32(test_env->params, "range");
- /* All ranges exceed INT32_MAX/2, device should be rejected */
- const struct {
- int32_t min, max;
- } ranges[] = {
- [EXTREME_RANGE_0_TO_INT32MAX] = { 0, INT32_MAX },
- [EXTREME_RANGE_INT32MIN_TO_0] = { INT32_MIN, 0 },
- [EXTREME_RANGE_NEGHALF_TO_POSHALF] = { -(INT32_MAX / 2),
- INT32_MAX / 2 },
- };
- struct input_absinfo absinfo[] = {
- { ABS_X, ranges[idx].min, ranges[idx].max, 0, 0, 0 },
- { ABS_Y, 0, 1000, 0, 0, 0 },
- { -1, -1, -1, -1, -1, -1 },
- };
- _litest_context_destroy_ struct libinput *li = litest_create_context();
- litest_disable_log_handler(li);
- /* clang-format off */
- uinput = litest_create_uinput_abs_device("test device", NULL,
- absinfo,
- EV_KEY, BTN_LEFT,
- EV_KEY, BTN_RIGHT,
- -1);
- /* clang-format on */
- device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput));
- litest_restore_log_handler(li);
- litest_assert_ptr_null(device);
- libevdev_uinput_destroy(uinput);
- }
- END_TEST
- START_TEST(abs_device_negative_resolution)
- {
- struct libevdev_uinput *uinput;
- struct libinput_device *device;
- struct input_absinfo absinfo[] = {
- { ABS_X, 0, 1000, 0, 0, -1 }, /* negative resolution */
- { ABS_Y, 0, 1000, 0, 0, -1 }, /* negative resolution */
- { -1, -1, -1, -1, -1, -1 },
- };
- _litest_context_destroy_ struct libinput *li = litest_create_context();
- litest_disable_log_handler(li);
- /* clang-format off */
- uinput = litest_create_uinput_abs_device("test device", NULL,
- absinfo,
- EV_KEY, BTN_LEFT,
- EV_KEY, BTN_RIGHT,
- -1);
- /* clang-format on */
- device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput));
- litest_restore_log_handler(li);
- /* Device should be rejected */
- litest_assert_ptr_null(device);
- libevdev_uinput_destroy(uinput);
- }
- END_TEST
- TEST_COLLECTION(device)
- {
- /* clang-format off */
- struct range abs_range = range_init_exclusive(0, ABS_MISC);
- struct range abs_mt_range = range_init_exclusive(ABS_MT_SLOT + 1, ABS_CNT);
- litest_add(device_sendevents_config, LITEST_ANY, LITEST_TOUCHPAD|LITEST_TABLET);
- litest_add(device_sendevents_config_invalid, LITEST_ANY, LITEST_TABLET);
- litest_add(device_sendevents_config_touchpad, LITEST_TOUCHPAD, LITEST_TABLET);
- litest_add(device_sendevents_config_touchpad_superset, LITEST_TOUCHPAD, LITEST_TABLET);
- litest_add(device_sendevents_config_default, LITEST_ANY, LITEST_TABLET);
- litest_add(device_disable, LITEST_RELATIVE, LITEST_TABLET);
- litest_add(device_disable_tablet, LITEST_TABLET, LITEST_ANY);
- litest_add(device_disable_touchpad, LITEST_TOUCHPAD, LITEST_TABLET);
- litest_add(device_disable_touch, LITEST_TOUCH, LITEST_ANY);
- litest_add(device_disable_touch_during_touch, LITEST_TOUCH, LITEST_ANY);
- litest_add(device_disable_touch, LITEST_SINGLE_TOUCH, LITEST_TOUCHPAD);
- litest_add(device_disable_touch_during_touch, LITEST_SINGLE_TOUCH, LITEST_TOUCHPAD);
- litest_add(device_disable_events_pending, LITEST_RELATIVE, LITEST_TOUCHPAD|LITEST_TABLET);
- litest_add(device_double_disable, LITEST_ANY, LITEST_TABLET);
- litest_add(device_double_enable, LITEST_ANY, LITEST_TABLET);
- litest_add_no_device(device_reenable_syspath_changed);
- litest_add_no_device(device_reenable_device_removed);
- litest_add_for_device(device_disable_release_buttons, LITEST_MOUSE);
- litest_add_for_device(device_disable_release_keys, LITEST_KEYBOARD);
- litest_add(device_disable_release_tap, LITEST_TOUCHPAD, LITEST_ANY);
- litest_add(device_disable_release_tap_n_drag, LITEST_TOUCHPAD, LITEST_ANY);
- litest_add(device_disable_release_softbutton, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD);
- litest_add(device_disable_topsoftbutton, LITEST_TOPBUTTONPAD, LITEST_ANY);
- litest_add(device_ids, LITEST_ANY, LITEST_ANY);
- litest_add_for_device(device_context, LITEST_SYNAPTICS_CLICKPAD_X220);
- litest_add_for_device(device_user_data, LITEST_SYNAPTICS_CLICKPAD_X220);
- litest_add(device_get_udev_handle, LITEST_ANY, LITEST_ANY);
- litest_add(device_group_get, LITEST_ANY, LITEST_ANY);
- litest_add_no_device(device_group_ref);
- litest_add_no_device(device_group_leak);
- litest_with_parameters(params, "axis", 'I', 2,
- litest_named_i32(ABS_X),
- litest_named_i32(ABS_Y)) {
- litest_add_parametrized_no_device(abs_device_missing_one_abs, params);
- litest_add_parametrized_no_device(abs_device_missing_res, params);
- }
- litest_with_parameters(params, "axis", 'I', 2,
- litest_named_i32(ABS_MT_POSITION_X),
- litest_named_i32(ABS_MT_POSITION_Y)) {
- litest_add_parametrized_no_device(abs_mt_device_missing_one_mt_abs, params);
- litest_add_parametrized_no_device(abs_mt_device_missing_res, params);
- }
- litest_add_ranged_no_device(abs_device_no_range, &abs_range);
- litest_add_ranged_no_device(abs_mt_device_no_range, &abs_mt_range);
- litest_add_no_device(ignore_joystick);
- litest_add(device_wheel_only, LITEST_WHEEL, LITEST_RELATIVE|LITEST_ABSOLUTE|LITEST_TABLET);
- litest_add_no_device(device_accelerometer);
- litest_with_parameters(params, "range", 'I', 3,
- litest_named_i32(EXTREME_RANGE_0_TO_INT32MAX, "0-to-INT32MAX"),
- litest_named_i32(EXTREME_RANGE_INT32MIN_TO_0, "INT32MIN-to-0"),
- litest_named_i32(EXTREME_RANGE_NEGHALF_TO_POSHALF, "-INT32MAX/2-to-INT32MAX/2")) {
- litest_add_parametrized_no_device(abs_device_extreme_axis_range, params);
- }
- litest_add_no_device(abs_device_negative_resolution);
- litest_add(device_udev_tag_wacom_tablet, LITEST_TABLET, LITEST_TOTEM);
- litest_add_no_device(device_nonpointer_rel);
- litest_add_no_device(device_touchpad_rel);
- litest_add_no_device(device_touch_rel);
- litest_add_no_device(device_abs_rel);
- litest_add_for_device(device_quirks_no_abs_mt_y, LITEST_ANKER_MOUSE_KBD);
- litest_add_for_device(device_quirks_cyborg_rat_mode_button, LITEST_CYBORG_RAT);
- litest_add_for_device(device_quirks_apple_magicmouse, LITEST_MAGICMOUSE);
- litest_add_for_device(device_quirks_logitech_marble_mouse, LITEST_LOGITECH_TRACKBALL);
- litest_add_no_device(device_quirks);
- litest_add(device_capability_at_least_one, LITEST_ANY, LITEST_ANY);
- litest_add(device_capability_check_invalid, LITEST_ANY, LITEST_ANY);
- litest_add_no_device(device_capability_nocaps_ignored);
- litest_add(device_has_size, LITEST_TOUCHPAD, LITEST_ANY);
- litest_add(device_has_size, LITEST_TABLET, LITEST_ANY);
- litest_add(device_has_no_size, LITEST_ANY,
- LITEST_TOUCHPAD|LITEST_TABLET|LITEST_TOUCH|LITEST_ABSOLUTE|LITEST_SINGLE_TOUCH|LITEST_TOTEM);
- litest_add_for_device(device_get_output, LITEST_CALIBRATED_TOUCHSCREEN);
- litest_add(device_no_output, LITEST_RELATIVE, LITEST_ANY);
- litest_add(device_no_output, LITEST_KEYS, LITEST_ANY);
- litest_add(device_seat_phys_name, LITEST_ANY, LITEST_ANY);
- litest_add(device_button_down_remove, LITEST_BUTTON, LITEST_ANY);
- /* clang-format off */
- }
|