test_mouse.py 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977
  1. #!/bin/env python3
  2. # SPDX-License-Identifier: GPL-2.0
  3. # -*- coding: utf-8 -*-
  4. #
  5. # Copyright (c) 2017 Benjamin Tissoires <benjamin.tissoires@gmail.com>
  6. # Copyright (c) 2017 Red Hat, Inc.
  7. #
  8. from . import base
  9. import hidtools.hid
  10. from hidtools.util import BusType
  11. import libevdev
  12. import logging
  13. import pytest
  14. logger = logging.getLogger("hidtools.test.mouse")
  15. # workaround https://gitlab.freedesktop.org/libevdev/python-libevdev/issues/6
  16. try:
  17. libevdev.EV_REL.REL_WHEEL_HI_RES
  18. except AttributeError:
  19. libevdev.EV_REL.REL_WHEEL_HI_RES = libevdev.EV_REL.REL_0B
  20. libevdev.EV_REL.REL_HWHEEL_HI_RES = libevdev.EV_REL.REL_0C
  21. class InvalidHIDCommunication(Exception):
  22. pass
  23. class MouseData(object):
  24. pass
  25. class BaseMouse(base.UHIDTestDevice):
  26. def __init__(self, rdesc, name=None, input_info=None):
  27. assert rdesc is not None
  28. super().__init__(name, "Mouse", input_info=input_info, rdesc=rdesc)
  29. self.left = False
  30. self.right = False
  31. self.middle = False
  32. def create_report(self, x, y, buttons=None, wheels=None, reportID=None):
  33. """
  34. Return an input report for this device.
  35. :param x: relative x
  36. :param y: relative y
  37. :param buttons: a (l, r, m) tuple of bools for the button states,
  38. where ``None`` is "leave unchanged"
  39. :param wheels: a single value for the vertical wheel or a (vertical, horizontal) tuple for
  40. the two wheels
  41. :param reportID: the numeric report ID for this report, if needed
  42. """
  43. if buttons is not None:
  44. left, right, middle = buttons
  45. if left is not None:
  46. self.left = left
  47. if right is not None:
  48. self.right = right
  49. if middle is not None:
  50. self.middle = middle
  51. left = self.left
  52. right = self.right
  53. middle = self.middle
  54. # Note: the BaseMouse doesn't actually have a wheel but the
  55. # create_report magic only fills in those fields exist, so let's
  56. # make this generic here.
  57. wheel, acpan = 0, 0
  58. if wheels is not None:
  59. if isinstance(wheels, tuple):
  60. wheel = wheels[0]
  61. acpan = wheels[1]
  62. else:
  63. wheel = wheels
  64. reportID = reportID or self.default_reportID
  65. mouse = MouseData()
  66. mouse.b1 = int(left)
  67. mouse.b2 = int(right)
  68. mouse.b3 = int(middle)
  69. mouse.x = x
  70. mouse.y = y
  71. mouse.wheel = wheel
  72. mouse.acpan = acpan
  73. return super().create_report(mouse, reportID=reportID)
  74. def event(self, x, y, buttons=None, wheels=None):
  75. """
  76. Send an input event on the default report ID.
  77. :param x: relative x
  78. :param y: relative y
  79. :param buttons: a (l, r, m) tuple of bools for the button states,
  80. where ``None`` is "leave unchanged"
  81. :param wheels: a single value for the vertical wheel or a (vertical, horizontal) tuple for
  82. the two wheels
  83. """
  84. r = self.create_report(x, y, buttons, wheels)
  85. self.call_input_event(r)
  86. return [r]
  87. class ButtonMouse(BaseMouse):
  88. # fmt: off
  89. report_descriptor = [
  90. 0x05, 0x01, # .Usage Page (Generic Desktop) 0
  91. 0x09, 0x02, # .Usage (Mouse) 2
  92. 0xa1, 0x01, # .Collection (Application) 4
  93. 0x09, 0x02, # ..Usage (Mouse) 6
  94. 0xa1, 0x02, # ..Collection (Logical) 8
  95. 0x09, 0x01, # ...Usage (Pointer) 10
  96. 0xa1, 0x00, # ...Collection (Physical) 12
  97. 0x05, 0x09, # ....Usage Page (Button) 14
  98. 0x19, 0x01, # ....Usage Minimum (1) 16
  99. 0x29, 0x03, # ....Usage Maximum (3) 18
  100. 0x15, 0x00, # ....Logical Minimum (0) 20
  101. 0x25, 0x01, # ....Logical Maximum (1) 22
  102. 0x75, 0x01, # ....Report Size (1) 24
  103. 0x95, 0x03, # ....Report Count (3) 26
  104. 0x81, 0x02, # ....Input (Data,Var,Abs) 28
  105. 0x75, 0x05, # ....Report Size (5) 30
  106. 0x95, 0x01, # ....Report Count (1) 32
  107. 0x81, 0x03, # ....Input (Cnst,Var,Abs) 34
  108. 0x05, 0x01, # ....Usage Page (Generic Desktop) 36
  109. 0x09, 0x30, # ....Usage (X) 38
  110. 0x09, 0x31, # ....Usage (Y) 40
  111. 0x15, 0x81, # ....Logical Minimum (-127) 42
  112. 0x25, 0x7f, # ....Logical Maximum (127) 44
  113. 0x75, 0x08, # ....Report Size (8) 46
  114. 0x95, 0x02, # ....Report Count (2) 48
  115. 0x81, 0x06, # ....Input (Data,Var,Rel) 50
  116. 0xc0, # ...End Collection 52
  117. 0xc0, # ..End Collection 53
  118. 0xc0, # .End Collection 54
  119. ]
  120. # fmt: on
  121. def __init__(self, rdesc=report_descriptor, name=None, input_info=None):
  122. super().__init__(rdesc, name, input_info)
  123. def fake_report(self, x, y, buttons):
  124. if buttons is not None:
  125. left, right, middle = buttons
  126. if left is None:
  127. left = self.left
  128. if right is None:
  129. right = self.right
  130. if middle is None:
  131. middle = self.middle
  132. else:
  133. left = self.left
  134. right = self.right
  135. middle = self.middle
  136. button_mask = sum(1 << i for i, b in enumerate([left, right, middle]) if b)
  137. x = max(-127, min(127, x))
  138. y = max(-127, min(127, y))
  139. x = hidtools.util.to_twos_comp(x, 8)
  140. y = hidtools.util.to_twos_comp(y, 8)
  141. return [button_mask, x, y]
  142. class WheelMouse(ButtonMouse):
  143. # fmt: off
  144. report_descriptor = [
  145. 0x05, 0x01, # Usage Page (Generic Desktop) 0
  146. 0x09, 0x02, # Usage (Mouse) 2
  147. 0xa1, 0x01, # Collection (Application) 4
  148. 0x05, 0x09, # .Usage Page (Button) 6
  149. 0x19, 0x01, # .Usage Minimum (1) 8
  150. 0x29, 0x03, # .Usage Maximum (3) 10
  151. 0x15, 0x00, # .Logical Minimum (0) 12
  152. 0x25, 0x01, # .Logical Maximum (1) 14
  153. 0x95, 0x03, # .Report Count (3) 16
  154. 0x75, 0x01, # .Report Size (1) 18
  155. 0x81, 0x02, # .Input (Data,Var,Abs) 20
  156. 0x95, 0x01, # .Report Count (1) 22
  157. 0x75, 0x05, # .Report Size (5) 24
  158. 0x81, 0x03, # .Input (Cnst,Var,Abs) 26
  159. 0x05, 0x01, # .Usage Page (Generic Desktop) 28
  160. 0x09, 0x01, # .Usage (Pointer) 30
  161. 0xa1, 0x00, # .Collection (Physical) 32
  162. 0x09, 0x30, # ..Usage (X) 34
  163. 0x09, 0x31, # ..Usage (Y) 36
  164. 0x15, 0x81, # ..Logical Minimum (-127) 38
  165. 0x25, 0x7f, # ..Logical Maximum (127) 40
  166. 0x75, 0x08, # ..Report Size (8) 42
  167. 0x95, 0x02, # ..Report Count (2) 44
  168. 0x81, 0x06, # ..Input (Data,Var,Rel) 46
  169. 0xc0, # .End Collection 48
  170. 0x09, 0x38, # .Usage (Wheel) 49
  171. 0x15, 0x81, # .Logical Minimum (-127) 51
  172. 0x25, 0x7f, # .Logical Maximum (127) 53
  173. 0x75, 0x08, # .Report Size (8) 55
  174. 0x95, 0x01, # .Report Count (1) 57
  175. 0x81, 0x06, # .Input (Data,Var,Rel) 59
  176. 0xc0, # End Collection 61
  177. ]
  178. # fmt: on
  179. def __init__(self, rdesc=report_descriptor, name=None, input_info=None):
  180. super().__init__(rdesc, name, input_info)
  181. self.wheel_multiplier = 1
  182. class TwoWheelMouse(WheelMouse):
  183. # fmt: off
  184. report_descriptor = [
  185. 0x05, 0x01, # Usage Page (Generic Desktop) 0
  186. 0x09, 0x02, # Usage (Mouse) 2
  187. 0xa1, 0x01, # Collection (Application) 4
  188. 0x09, 0x01, # .Usage (Pointer) 6
  189. 0xa1, 0x00, # .Collection (Physical) 8
  190. 0x05, 0x09, # ..Usage Page (Button) 10
  191. 0x19, 0x01, # ..Usage Minimum (1) 12
  192. 0x29, 0x10, # ..Usage Maximum (16) 14
  193. 0x15, 0x00, # ..Logical Minimum (0) 16
  194. 0x25, 0x01, # ..Logical Maximum (1) 18
  195. 0x95, 0x10, # ..Report Count (16) 20
  196. 0x75, 0x01, # ..Report Size (1) 22
  197. 0x81, 0x02, # ..Input (Data,Var,Abs) 24
  198. 0x05, 0x01, # ..Usage Page (Generic Desktop) 26
  199. 0x16, 0x01, 0x80, # ..Logical Minimum (-32767) 28
  200. 0x26, 0xff, 0x7f, # ..Logical Maximum (32767) 31
  201. 0x75, 0x10, # ..Report Size (16) 34
  202. 0x95, 0x02, # ..Report Count (2) 36
  203. 0x09, 0x30, # ..Usage (X) 38
  204. 0x09, 0x31, # ..Usage (Y) 40
  205. 0x81, 0x06, # ..Input (Data,Var,Rel) 42
  206. 0x15, 0x81, # ..Logical Minimum (-127) 44
  207. 0x25, 0x7f, # ..Logical Maximum (127) 46
  208. 0x75, 0x08, # ..Report Size (8) 48
  209. 0x95, 0x01, # ..Report Count (1) 50
  210. 0x09, 0x38, # ..Usage (Wheel) 52
  211. 0x81, 0x06, # ..Input (Data,Var,Rel) 54
  212. 0x05, 0x0c, # ..Usage Page (Consumer Devices) 56
  213. 0x0a, 0x38, 0x02, # ..Usage (AC Pan) 58
  214. 0x95, 0x01, # ..Report Count (1) 61
  215. 0x81, 0x06, # ..Input (Data,Var,Rel) 63
  216. 0xc0, # .End Collection 65
  217. 0xc0, # End Collection 66
  218. ]
  219. # fmt: on
  220. def __init__(self, rdesc=report_descriptor, name=None, input_info=None):
  221. super().__init__(rdesc, name, input_info)
  222. self.hwheel_multiplier = 1
  223. class MIDongleMIWirelessMouse(TwoWheelMouse):
  224. # fmt: off
  225. report_descriptor = [
  226. 0x05, 0x01, # Usage Page (Generic Desktop)
  227. 0x09, 0x02, # Usage (Mouse)
  228. 0xa1, 0x01, # Collection (Application)
  229. 0x85, 0x01, # .Report ID (1)
  230. 0x09, 0x01, # .Usage (Pointer)
  231. 0xa1, 0x00, # .Collection (Physical)
  232. 0x95, 0x05, # ..Report Count (5)
  233. 0x75, 0x01, # ..Report Size (1)
  234. 0x05, 0x09, # ..Usage Page (Button)
  235. 0x19, 0x01, # ..Usage Minimum (1)
  236. 0x29, 0x05, # ..Usage Maximum (5)
  237. 0x15, 0x00, # ..Logical Minimum (0)
  238. 0x25, 0x01, # ..Logical Maximum (1)
  239. 0x81, 0x02, # ..Input (Data,Var,Abs)
  240. 0x95, 0x01, # ..Report Count (1)
  241. 0x75, 0x03, # ..Report Size (3)
  242. 0x81, 0x01, # ..Input (Cnst,Arr,Abs)
  243. 0x75, 0x08, # ..Report Size (8)
  244. 0x95, 0x01, # ..Report Count (1)
  245. 0x05, 0x01, # ..Usage Page (Generic Desktop)
  246. 0x09, 0x38, # ..Usage (Wheel)
  247. 0x15, 0x81, # ..Logical Minimum (-127)
  248. 0x25, 0x7f, # ..Logical Maximum (127)
  249. 0x81, 0x06, # ..Input (Data,Var,Rel)
  250. 0x05, 0x0c, # ..Usage Page (Consumer Devices)
  251. 0x0a, 0x38, 0x02, # ..Usage (AC Pan)
  252. 0x95, 0x01, # ..Report Count (1)
  253. 0x81, 0x06, # ..Input (Data,Var,Rel)
  254. 0xc0, # .End Collection
  255. 0x85, 0x02, # .Report ID (2)
  256. 0x09, 0x01, # .Usage (Consumer Control)
  257. 0xa1, 0x00, # .Collection (Physical)
  258. 0x75, 0x0c, # ..Report Size (12)
  259. 0x95, 0x02, # ..Report Count (2)
  260. 0x05, 0x01, # ..Usage Page (Generic Desktop)
  261. 0x09, 0x30, # ..Usage (X)
  262. 0x09, 0x31, # ..Usage (Y)
  263. 0x16, 0x01, 0xf8, # ..Logical Minimum (-2047)
  264. 0x26, 0xff, 0x07, # ..Logical Maximum (2047)
  265. 0x81, 0x06, # ..Input (Data,Var,Rel)
  266. 0xc0, # .End Collection
  267. 0xc0, # End Collection
  268. 0x05, 0x0c, # Usage Page (Consumer Devices)
  269. 0x09, 0x01, # Usage (Consumer Control)
  270. 0xa1, 0x01, # Collection (Application)
  271. 0x85, 0x03, # .Report ID (3)
  272. 0x15, 0x00, # .Logical Minimum (0)
  273. 0x25, 0x01, # .Logical Maximum (1)
  274. 0x75, 0x01, # .Report Size (1)
  275. 0x95, 0x01, # .Report Count (1)
  276. 0x09, 0xcd, # .Usage (Play/Pause)
  277. 0x81, 0x06, # .Input (Data,Var,Rel)
  278. 0x0a, 0x83, 0x01, # .Usage (AL Consumer Control Config)
  279. 0x81, 0x06, # .Input (Data,Var,Rel)
  280. 0x09, 0xb5, # .Usage (Scan Next Track)
  281. 0x81, 0x06, # .Input (Data,Var,Rel)
  282. 0x09, 0xb6, # .Usage (Scan Previous Track)
  283. 0x81, 0x06, # .Input (Data,Var,Rel)
  284. 0x09, 0xea, # .Usage (Volume Down)
  285. 0x81, 0x06, # .Input (Data,Var,Rel)
  286. 0x09, 0xe9, # .Usage (Volume Up)
  287. 0x81, 0x06, # .Input (Data,Var,Rel)
  288. 0x0a, 0x25, 0x02, # .Usage (AC Forward)
  289. 0x81, 0x06, # .Input (Data,Var,Rel)
  290. 0x0a, 0x24, 0x02, # .Usage (AC Back)
  291. 0x81, 0x06, # .Input (Data,Var,Rel)
  292. 0xc0, # End Collection
  293. ]
  294. # fmt: on
  295. device_input_info = (BusType.USB, 0x2717, 0x003B)
  296. device_name = "uhid test MI Dongle MI Wireless Mouse"
  297. def __init__(
  298. self, rdesc=report_descriptor, name=device_name, input_info=device_input_info
  299. ):
  300. super().__init__(rdesc, name, input_info)
  301. def event(self, x, y, buttons=None, wheels=None):
  302. # this mouse spreads the relative pointer and the mouse buttons
  303. # onto 2 distinct reports
  304. rs = []
  305. r = self.create_report(x, y, buttons, wheels, reportID=1)
  306. self.call_input_event(r)
  307. rs.append(r)
  308. r = self.create_report(x, y, buttons, reportID=2)
  309. self.call_input_event(r)
  310. rs.append(r)
  311. return rs
  312. class ResolutionMultiplierMouse(TwoWheelMouse):
  313. # fmt: off
  314. report_descriptor = [
  315. 0x05, 0x01, # Usage Page (Generic Desktop) 83
  316. 0x09, 0x02, # Usage (Mouse) 85
  317. 0xa1, 0x01, # Collection (Application) 87
  318. 0x05, 0x01, # .Usage Page (Generic Desktop) 89
  319. 0x09, 0x02, # .Usage (Mouse) 91
  320. 0xa1, 0x02, # .Collection (Logical) 93
  321. 0x85, 0x11, # ..Report ID (17) 95
  322. 0x09, 0x01, # ..Usage (Pointer) 97
  323. 0xa1, 0x00, # ..Collection (Physical) 99
  324. 0x05, 0x09, # ...Usage Page (Button) 101
  325. 0x19, 0x01, # ...Usage Minimum (1) 103
  326. 0x29, 0x03, # ...Usage Maximum (3) 105
  327. 0x95, 0x03, # ...Report Count (3) 107
  328. 0x75, 0x01, # ...Report Size (1) 109
  329. 0x25, 0x01, # ...Logical Maximum (1) 111
  330. 0x81, 0x02, # ...Input (Data,Var,Abs) 113
  331. 0x95, 0x01, # ...Report Count (1) 115
  332. 0x81, 0x01, # ...Input (Cnst,Arr,Abs) 117
  333. 0x09, 0x05, # ...Usage (Vendor Usage 0x05) 119
  334. 0x81, 0x02, # ...Input (Data,Var,Abs) 121
  335. 0x95, 0x03, # ...Report Count (3) 123
  336. 0x81, 0x01, # ...Input (Cnst,Arr,Abs) 125
  337. 0x05, 0x01, # ...Usage Page (Generic Desktop) 127
  338. 0x09, 0x30, # ...Usage (X) 129
  339. 0x09, 0x31, # ...Usage (Y) 131
  340. 0x95, 0x02, # ...Report Count (2) 133
  341. 0x75, 0x08, # ...Report Size (8) 135
  342. 0x15, 0x81, # ...Logical Minimum (-127) 137
  343. 0x25, 0x7f, # ...Logical Maximum (127) 139
  344. 0x81, 0x06, # ...Input (Data,Var,Rel) 141
  345. 0xa1, 0x02, # ...Collection (Logical) 143
  346. 0x85, 0x12, # ....Report ID (18) 145
  347. 0x09, 0x48, # ....Usage (Resolution Multiplier) 147
  348. 0x95, 0x01, # ....Report Count (1) 149
  349. 0x75, 0x02, # ....Report Size (2) 151
  350. 0x15, 0x00, # ....Logical Minimum (0) 153
  351. 0x25, 0x01, # ....Logical Maximum (1) 155
  352. 0x35, 0x01, # ....Physical Minimum (1) 157
  353. 0x45, 0x04, # ....Physical Maximum (4) 159
  354. 0xb1, 0x02, # ....Feature (Data,Var,Abs) 161
  355. 0x35, 0x00, # ....Physical Minimum (0) 163
  356. 0x45, 0x00, # ....Physical Maximum (0) 165
  357. 0x75, 0x06, # ....Report Size (6) 167
  358. 0xb1, 0x01, # ....Feature (Cnst,Arr,Abs) 169
  359. 0x85, 0x11, # ....Report ID (17) 171
  360. 0x09, 0x38, # ....Usage (Wheel) 173
  361. 0x15, 0x81, # ....Logical Minimum (-127) 175
  362. 0x25, 0x7f, # ....Logical Maximum (127) 177
  363. 0x75, 0x08, # ....Report Size (8) 179
  364. 0x81, 0x06, # ....Input (Data,Var,Rel) 181
  365. 0xc0, # ...End Collection 183
  366. 0x05, 0x0c, # ...Usage Page (Consumer Devices) 184
  367. 0x75, 0x08, # ...Report Size (8) 186
  368. 0x0a, 0x38, 0x02, # ...Usage (AC Pan) 188
  369. 0x81, 0x06, # ...Input (Data,Var,Rel) 191
  370. 0xc0, # ..End Collection 193
  371. 0xc0, # .End Collection 194
  372. 0xc0, # End Collection 195
  373. ]
  374. # fmt: on
  375. def __init__(self, rdesc=report_descriptor, name=None, input_info=None):
  376. super().__init__(rdesc, name, input_info)
  377. self.default_reportID = 0x11
  378. # Feature Report 12, multiplier Feature value must be set to 0b01,
  379. # i.e. 1. We should extract that from the descriptor instead
  380. # of hardcoding it here, but meanwhile this will do.
  381. self.set_feature_report = [0x12, 0x1]
  382. def set_report(self, req, rnum, rtype, data):
  383. if rtype != self.UHID_FEATURE_REPORT:
  384. raise InvalidHIDCommunication(f"Unexpected report type: {rtype}")
  385. if rnum != 0x12:
  386. raise InvalidHIDCommunication(f"Unexpected report number: {rnum}")
  387. if data != self.set_feature_report:
  388. raise InvalidHIDCommunication(
  389. f"Unexpected data: {data}, expected {self.set_feature_report}"
  390. )
  391. self.wheel_multiplier = 4
  392. return 0
  393. class BadResolutionMultiplierMouse(ResolutionMultiplierMouse):
  394. def set_report(self, req, rnum, rtype, data):
  395. super().set_report(req, rnum, rtype, data)
  396. self.wheel_multiplier = 1
  397. self.hwheel_multiplier = 1
  398. return 32 # EPIPE
  399. class ResolutionMultiplierHWheelMouse(TwoWheelMouse):
  400. # fmt: off
  401. report_descriptor = [
  402. 0x05, 0x01, # Usage Page (Generic Desktop) 0
  403. 0x09, 0x02, # Usage (Mouse) 2
  404. 0xa1, 0x01, # Collection (Application) 4
  405. 0x05, 0x01, # .Usage Page (Generic Desktop) 6
  406. 0x09, 0x02, # .Usage (Mouse) 8
  407. 0xa1, 0x02, # .Collection (Logical) 10
  408. 0x85, 0x1a, # ..Report ID (26) 12
  409. 0x09, 0x01, # ..Usage (Pointer) 14
  410. 0xa1, 0x00, # ..Collection (Physical) 16
  411. 0x05, 0x09, # ...Usage Page (Button) 18
  412. 0x19, 0x01, # ...Usage Minimum (1) 20
  413. 0x29, 0x05, # ...Usage Maximum (5) 22
  414. 0x95, 0x05, # ...Report Count (5) 24
  415. 0x75, 0x01, # ...Report Size (1) 26
  416. 0x15, 0x00, # ...Logical Minimum (0) 28
  417. 0x25, 0x01, # ...Logical Maximum (1) 30
  418. 0x81, 0x02, # ...Input (Data,Var,Abs) 32
  419. 0x75, 0x03, # ...Report Size (3) 34
  420. 0x95, 0x01, # ...Report Count (1) 36
  421. 0x81, 0x01, # ...Input (Cnst,Arr,Abs) 38
  422. 0x05, 0x01, # ...Usage Page (Generic Desktop) 40
  423. 0x09, 0x30, # ...Usage (X) 42
  424. 0x09, 0x31, # ...Usage (Y) 44
  425. 0x95, 0x02, # ...Report Count (2) 46
  426. 0x75, 0x10, # ...Report Size (16) 48
  427. 0x16, 0x01, 0x80, # ...Logical Minimum (-32767) 50
  428. 0x26, 0xff, 0x7f, # ...Logical Maximum (32767) 53
  429. 0x81, 0x06, # ...Input (Data,Var,Rel) 56
  430. 0xa1, 0x02, # ...Collection (Logical) 58
  431. 0x85, 0x12, # ....Report ID (18) 60
  432. 0x09, 0x48, # ....Usage (Resolution Multiplier) 62
  433. 0x95, 0x01, # ....Report Count (1) 64
  434. 0x75, 0x02, # ....Report Size (2) 66
  435. 0x15, 0x00, # ....Logical Minimum (0) 68
  436. 0x25, 0x01, # ....Logical Maximum (1) 70
  437. 0x35, 0x01, # ....Physical Minimum (1) 72
  438. 0x45, 0x0c, # ....Physical Maximum (12) 74
  439. 0xb1, 0x02, # ....Feature (Data,Var,Abs) 76
  440. 0x85, 0x1a, # ....Report ID (26) 78
  441. 0x09, 0x38, # ....Usage (Wheel) 80
  442. 0x35, 0x00, # ....Physical Minimum (0) 82
  443. 0x45, 0x00, # ....Physical Maximum (0) 84
  444. 0x95, 0x01, # ....Report Count (1) 86
  445. 0x75, 0x10, # ....Report Size (16) 88
  446. 0x16, 0x01, 0x80, # ....Logical Minimum (-32767) 90
  447. 0x26, 0xff, 0x7f, # ....Logical Maximum (32767) 93
  448. 0x81, 0x06, # ....Input (Data,Var,Rel) 96
  449. 0xc0, # ...End Collection 98
  450. 0xa1, 0x02, # ...Collection (Logical) 99
  451. 0x85, 0x12, # ....Report ID (18) 101
  452. 0x09, 0x48, # ....Usage (Resolution Multiplier) 103
  453. 0x75, 0x02, # ....Report Size (2) 105
  454. 0x15, 0x00, # ....Logical Minimum (0) 107
  455. 0x25, 0x01, # ....Logical Maximum (1) 109
  456. 0x35, 0x01, # ....Physical Minimum (1) 111
  457. 0x45, 0x0c, # ....Physical Maximum (12) 113
  458. 0xb1, 0x02, # ....Feature (Data,Var,Abs) 115
  459. 0x35, 0x00, # ....Physical Minimum (0) 117
  460. 0x45, 0x00, # ....Physical Maximum (0) 119
  461. 0x75, 0x04, # ....Report Size (4) 121
  462. 0xb1, 0x01, # ....Feature (Cnst,Arr,Abs) 123
  463. 0x85, 0x1a, # ....Report ID (26) 125
  464. 0x05, 0x0c, # ....Usage Page (Consumer Devices) 127
  465. 0x95, 0x01, # ....Report Count (1) 129
  466. 0x75, 0x10, # ....Report Size (16) 131
  467. 0x16, 0x01, 0x80, # ....Logical Minimum (-32767) 133
  468. 0x26, 0xff, 0x7f, # ....Logical Maximum (32767) 136
  469. 0x0a, 0x38, 0x02, # ....Usage (AC Pan) 139
  470. 0x81, 0x06, # ....Input (Data,Var,Rel) 142
  471. 0xc0, # ...End Collection 144
  472. 0xc0, # ..End Collection 145
  473. 0xc0, # .End Collection 146
  474. 0xc0, # End Collection 147
  475. ]
  476. # fmt: on
  477. def __init__(self, rdesc=report_descriptor, name=None, input_info=None):
  478. super().__init__(rdesc, name, input_info)
  479. self.default_reportID = 0x1A
  480. # Feature Report 12, multiplier Feature value must be set to 0b0101,
  481. # i.e. 5. We should extract that from the descriptor instead
  482. # of hardcoding it here, but meanwhile this will do.
  483. self.set_feature_report = [0x12, 0x5]
  484. def set_report(self, req, rnum, rtype, data):
  485. super().set_report(req, rnum, rtype, data)
  486. self.wheel_multiplier = 12
  487. self.hwheel_multiplier = 12
  488. return 0
  489. class BaseTest:
  490. class TestMouse(base.BaseTestCase.TestUhid):
  491. def test_buttons(self):
  492. """check for button reliability."""
  493. uhdev = self.uhdev
  494. evdev = uhdev.get_evdev()
  495. syn_event = self.syn_event
  496. r = uhdev.event(0, 0, (None, True, None))
  497. expected_event = libevdev.InputEvent(libevdev.EV_KEY.BTN_RIGHT, 1)
  498. events = uhdev.next_sync_events()
  499. self.debug_reports(r, uhdev, events)
  500. self.assertInputEventsIn((syn_event, expected_event), events)
  501. assert evdev.value[libevdev.EV_KEY.BTN_RIGHT] == 1
  502. r = uhdev.event(0, 0, (None, False, None))
  503. expected_event = libevdev.InputEvent(libevdev.EV_KEY.BTN_RIGHT, 0)
  504. events = uhdev.next_sync_events()
  505. self.debug_reports(r, uhdev, events)
  506. self.assertInputEventsIn((syn_event, expected_event), events)
  507. assert evdev.value[libevdev.EV_KEY.BTN_RIGHT] == 0
  508. r = uhdev.event(0, 0, (None, None, True))
  509. expected_event = libevdev.InputEvent(libevdev.EV_KEY.BTN_MIDDLE, 1)
  510. events = uhdev.next_sync_events()
  511. self.debug_reports(r, uhdev, events)
  512. self.assertInputEventsIn((syn_event, expected_event), events)
  513. assert evdev.value[libevdev.EV_KEY.BTN_MIDDLE] == 1
  514. r = uhdev.event(0, 0, (None, None, False))
  515. expected_event = libevdev.InputEvent(libevdev.EV_KEY.BTN_MIDDLE, 0)
  516. events = uhdev.next_sync_events()
  517. self.debug_reports(r, uhdev, events)
  518. self.assertInputEventsIn((syn_event, expected_event), events)
  519. assert evdev.value[libevdev.EV_KEY.BTN_MIDDLE] == 0
  520. r = uhdev.event(0, 0, (True, None, None))
  521. expected_event = libevdev.InputEvent(libevdev.EV_KEY.BTN_LEFT, 1)
  522. events = uhdev.next_sync_events()
  523. self.debug_reports(r, uhdev, events)
  524. self.assertInputEventsIn((syn_event, expected_event), events)
  525. assert evdev.value[libevdev.EV_KEY.BTN_LEFT] == 1
  526. r = uhdev.event(0, 0, (False, None, None))
  527. expected_event = libevdev.InputEvent(libevdev.EV_KEY.BTN_LEFT, 0)
  528. events = uhdev.next_sync_events()
  529. self.debug_reports(r, uhdev, events)
  530. self.assertInputEventsIn((syn_event, expected_event), events)
  531. assert evdev.value[libevdev.EV_KEY.BTN_LEFT] == 0
  532. r = uhdev.event(0, 0, (True, True, None))
  533. expected_event0 = libevdev.InputEvent(libevdev.EV_KEY.BTN_LEFT, 1)
  534. expected_event1 = libevdev.InputEvent(libevdev.EV_KEY.BTN_RIGHT, 1)
  535. events = uhdev.next_sync_events()
  536. self.debug_reports(r, uhdev, events)
  537. self.assertInputEventsIn(
  538. (syn_event, expected_event0, expected_event1), events
  539. )
  540. assert evdev.value[libevdev.EV_KEY.BTN_RIGHT] == 1
  541. assert evdev.value[libevdev.EV_KEY.BTN_LEFT] == 1
  542. r = uhdev.event(0, 0, (False, None, None))
  543. expected_event = libevdev.InputEvent(libevdev.EV_KEY.BTN_LEFT, 0)
  544. events = uhdev.next_sync_events()
  545. self.debug_reports(r, uhdev, events)
  546. self.assertInputEventsIn((syn_event, expected_event), events)
  547. assert evdev.value[libevdev.EV_KEY.BTN_RIGHT] == 1
  548. assert evdev.value[libevdev.EV_KEY.BTN_LEFT] == 0
  549. r = uhdev.event(0, 0, (None, False, None))
  550. expected_event = libevdev.InputEvent(libevdev.EV_KEY.BTN_RIGHT, 0)
  551. events = uhdev.next_sync_events()
  552. self.debug_reports(r, uhdev, events)
  553. self.assertInputEventsIn((syn_event, expected_event), events)
  554. assert evdev.value[libevdev.EV_KEY.BTN_RIGHT] == 0
  555. assert evdev.value[libevdev.EV_KEY.BTN_LEFT] == 0
  556. def test_relative(self):
  557. """Check for relative events."""
  558. uhdev = self.uhdev
  559. syn_event = self.syn_event
  560. r = uhdev.event(0, -1)
  561. expected_event = libevdev.InputEvent(libevdev.EV_REL.REL_Y, -1)
  562. events = uhdev.next_sync_events()
  563. self.debug_reports(r, uhdev, events)
  564. self.assertInputEvents((syn_event, expected_event), events)
  565. r = uhdev.event(1, 0)
  566. expected_event = libevdev.InputEvent(libevdev.EV_REL.REL_X, 1)
  567. events = uhdev.next_sync_events()
  568. self.debug_reports(r, uhdev, events)
  569. self.assertInputEvents((syn_event, expected_event), events)
  570. r = uhdev.event(-1, 2)
  571. expected_event0 = libevdev.InputEvent(libevdev.EV_REL.REL_X, -1)
  572. expected_event1 = libevdev.InputEvent(libevdev.EV_REL.REL_Y, 2)
  573. events = uhdev.next_sync_events()
  574. self.debug_reports(r, uhdev, events)
  575. self.assertInputEvents(
  576. (syn_event, expected_event0, expected_event1), events
  577. )
  578. class TestSimpleMouse(BaseTest.TestMouse):
  579. def create_device(self):
  580. return ButtonMouse()
  581. def test_rdesc(self):
  582. """Check that the testsuite actually manages to format the
  583. reports according to the report descriptors.
  584. No kernel device is used here"""
  585. uhdev = self.uhdev
  586. event = (0, 0, (None, None, None))
  587. assert uhdev.fake_report(*event) == uhdev.create_report(*event)
  588. event = (0, 0, (None, True, None))
  589. assert uhdev.fake_report(*event) == uhdev.create_report(*event)
  590. event = (0, 0, (True, True, None))
  591. assert uhdev.fake_report(*event) == uhdev.create_report(*event)
  592. event = (0, 0, (False, False, False))
  593. assert uhdev.fake_report(*event) == uhdev.create_report(*event)
  594. event = (1, 0, (True, False, True))
  595. assert uhdev.fake_report(*event) == uhdev.create_report(*event)
  596. event = (-1, 0, (True, False, True))
  597. assert uhdev.fake_report(*event) == uhdev.create_report(*event)
  598. event = (-5, 5, (True, False, True))
  599. assert uhdev.fake_report(*event) == uhdev.create_report(*event)
  600. event = (-127, 127, (True, False, True))
  601. assert uhdev.fake_report(*event) == uhdev.create_report(*event)
  602. event = (0, -128, (True, False, True))
  603. with pytest.raises(hidtools.hid.RangeError):
  604. uhdev.create_report(*event)
  605. class TestWheelMouse(BaseTest.TestMouse):
  606. def create_device(self):
  607. return WheelMouse()
  608. def is_wheel_highres(self, uhdev):
  609. evdev = uhdev.get_evdev()
  610. assert evdev.has(libevdev.EV_REL.REL_WHEEL)
  611. return evdev.has(libevdev.EV_REL.REL_WHEEL_HI_RES)
  612. def test_wheel(self):
  613. uhdev = self.uhdev
  614. # check if the kernel is high res wheel compatible
  615. high_res_wheel = self.is_wheel_highres(uhdev)
  616. syn_event = self.syn_event
  617. # The Resolution Multiplier is applied to the HID reports, so we
  618. # need to pre-multiply too.
  619. mult = uhdev.wheel_multiplier
  620. r = uhdev.event(0, 0, wheels=1 * mult)
  621. expected = [syn_event]
  622. expected.append(libevdev.InputEvent(libevdev.EV_REL.REL_WHEEL, 1))
  623. if high_res_wheel:
  624. expected.append(libevdev.InputEvent(libevdev.EV_REL.REL_WHEEL_HI_RES, 120))
  625. events = uhdev.next_sync_events()
  626. self.debug_reports(r, uhdev, events)
  627. self.assertInputEvents(expected, events)
  628. r = uhdev.event(0, 0, wheels=-1 * mult)
  629. expected = [syn_event]
  630. expected.append(libevdev.InputEvent(libevdev.EV_REL.REL_WHEEL, -1))
  631. if high_res_wheel:
  632. expected.append(libevdev.InputEvent(libevdev.EV_REL.REL_WHEEL_HI_RES, -120))
  633. events = uhdev.next_sync_events()
  634. self.debug_reports(r, uhdev, events)
  635. self.assertInputEvents(expected, events)
  636. r = uhdev.event(-1, 2, wheels=3 * mult)
  637. expected = [syn_event]
  638. expected.append(libevdev.InputEvent(libevdev.EV_REL.REL_X, -1))
  639. expected.append(libevdev.InputEvent(libevdev.EV_REL.REL_Y, 2))
  640. expected.append(libevdev.InputEvent(libevdev.EV_REL.REL_WHEEL, 3))
  641. if high_res_wheel:
  642. expected.append(libevdev.InputEvent(libevdev.EV_REL.REL_WHEEL_HI_RES, 360))
  643. events = uhdev.next_sync_events()
  644. self.debug_reports(r, uhdev, events)
  645. self.assertInputEvents(expected, events)
  646. class TestTwoWheelMouse(TestWheelMouse):
  647. def create_device(self):
  648. return TwoWheelMouse()
  649. def is_hwheel_highres(self, uhdev):
  650. evdev = uhdev.get_evdev()
  651. assert evdev.has(libevdev.EV_REL.REL_HWHEEL)
  652. return evdev.has(libevdev.EV_REL.REL_HWHEEL_HI_RES)
  653. def test_ac_pan(self):
  654. uhdev = self.uhdev
  655. # check if the kernel is high res wheel compatible
  656. high_res_wheel = self.is_wheel_highres(uhdev)
  657. high_res_hwheel = self.is_hwheel_highres(uhdev)
  658. assert high_res_wheel == high_res_hwheel
  659. syn_event = self.syn_event
  660. # The Resolution Multiplier is applied to the HID reports, so we
  661. # need to pre-multiply too.
  662. hmult = uhdev.hwheel_multiplier
  663. vmult = uhdev.wheel_multiplier
  664. r = uhdev.event(0, 0, wheels=(0, 1 * hmult))
  665. expected = [syn_event]
  666. expected.append(libevdev.InputEvent(libevdev.EV_REL.REL_HWHEEL, 1))
  667. if high_res_hwheel:
  668. expected.append(libevdev.InputEvent(libevdev.EV_REL.REL_HWHEEL_HI_RES, 120))
  669. events = uhdev.next_sync_events()
  670. self.debug_reports(r, uhdev, events)
  671. self.assertInputEvents(expected, events)
  672. r = uhdev.event(0, 0, wheels=(0, -1 * hmult))
  673. expected = [syn_event]
  674. expected.append(libevdev.InputEvent(libevdev.EV_REL.REL_HWHEEL, -1))
  675. if high_res_hwheel:
  676. expected.append(
  677. libevdev.InputEvent(libevdev.EV_REL.REL_HWHEEL_HI_RES, -120)
  678. )
  679. events = uhdev.next_sync_events()
  680. self.debug_reports(r, uhdev, events)
  681. self.assertInputEvents(expected, events)
  682. r = uhdev.event(-1, 2, wheels=(0, 3 * hmult))
  683. expected = [syn_event]
  684. expected.append(libevdev.InputEvent(libevdev.EV_REL.REL_X, -1))
  685. expected.append(libevdev.InputEvent(libevdev.EV_REL.REL_Y, 2))
  686. expected.append(libevdev.InputEvent(libevdev.EV_REL.REL_HWHEEL, 3))
  687. if high_res_hwheel:
  688. expected.append(libevdev.InputEvent(libevdev.EV_REL.REL_HWHEEL_HI_RES, 360))
  689. events = uhdev.next_sync_events()
  690. self.debug_reports(r, uhdev, events)
  691. self.assertInputEvents(expected, events)
  692. r = uhdev.event(-1, 2, wheels=(-3 * vmult, 4 * hmult))
  693. expected = [syn_event]
  694. expected.append(libevdev.InputEvent(libevdev.EV_REL.REL_X, -1))
  695. expected.append(libevdev.InputEvent(libevdev.EV_REL.REL_Y, 2))
  696. expected.append(libevdev.InputEvent(libevdev.EV_REL.REL_WHEEL, -3))
  697. if high_res_wheel:
  698. expected.append(libevdev.InputEvent(libevdev.EV_REL.REL_WHEEL_HI_RES, -360))
  699. expected.append(libevdev.InputEvent(libevdev.EV_REL.REL_HWHEEL, 4))
  700. if high_res_wheel:
  701. expected.append(libevdev.InputEvent(libevdev.EV_REL.REL_HWHEEL_HI_RES, 480))
  702. events = uhdev.next_sync_events()
  703. self.debug_reports(r, uhdev, events)
  704. self.assertInputEvents(expected, events)
  705. class TestResolutionMultiplierMouse(TestTwoWheelMouse):
  706. def create_device(self):
  707. return ResolutionMultiplierMouse()
  708. def is_wheel_highres(self, uhdev):
  709. high_res = super().is_wheel_highres(uhdev)
  710. if not high_res:
  711. # the kernel doesn't seem to support the high res wheel mice,
  712. # make sure we haven't triggered the feature
  713. assert uhdev.wheel_multiplier == 1
  714. return high_res
  715. def test_resolution_multiplier_wheel(self):
  716. uhdev = self.uhdev
  717. if not self.is_wheel_highres(uhdev):
  718. pytest.skip("Kernel not compatible, we can not trigger the conditions")
  719. assert uhdev.wheel_multiplier > 1
  720. assert 120 % uhdev.wheel_multiplier == 0
  721. def test_wheel_with_multiplier(self):
  722. uhdev = self.uhdev
  723. if not self.is_wheel_highres(uhdev):
  724. pytest.skip("Kernel not compatible, we can not trigger the conditions")
  725. assert uhdev.wheel_multiplier > 1
  726. syn_event = self.syn_event
  727. mult = uhdev.wheel_multiplier
  728. r = uhdev.event(0, 0, wheels=1)
  729. expected = [syn_event]
  730. expected.append(
  731. libevdev.InputEvent(libevdev.EV_REL.REL_WHEEL_HI_RES, 120 / mult)
  732. )
  733. events = uhdev.next_sync_events()
  734. self.debug_reports(r, uhdev, events)
  735. self.assertInputEvents(expected, events)
  736. r = uhdev.event(0, 0, wheels=-1)
  737. expected = [syn_event]
  738. expected.append(
  739. libevdev.InputEvent(libevdev.EV_REL.REL_WHEEL_HI_RES, -120 / mult)
  740. )
  741. events = uhdev.next_sync_events()
  742. self.debug_reports(r, uhdev, events)
  743. self.assertInputEvents(expected, events)
  744. expected = [syn_event]
  745. expected.append(libevdev.InputEvent(libevdev.EV_REL.REL_X, 1))
  746. expected.append(libevdev.InputEvent(libevdev.EV_REL.REL_Y, -2))
  747. expected.append(
  748. libevdev.InputEvent(libevdev.EV_REL.REL_WHEEL_HI_RES, 120 / mult)
  749. )
  750. for _ in range(mult - 1):
  751. r = uhdev.event(1, -2, wheels=1)
  752. events = uhdev.next_sync_events()
  753. self.debug_reports(r, uhdev, events)
  754. self.assertInputEvents(expected, events)
  755. r = uhdev.event(1, -2, wheels=1)
  756. expected.append(libevdev.InputEvent(libevdev.EV_REL.REL_WHEEL, 1))
  757. events = uhdev.next_sync_events()
  758. self.debug_reports(r, uhdev, events)
  759. self.assertInputEvents(expected, events)
  760. class TestBadResolutionMultiplierMouse(TestTwoWheelMouse):
  761. def create_device(self):
  762. return BadResolutionMultiplierMouse()
  763. def is_wheel_highres(self, uhdev):
  764. high_res = super().is_wheel_highres(uhdev)
  765. assert uhdev.wheel_multiplier == 1
  766. return high_res
  767. def test_resolution_multiplier_wheel(self):
  768. uhdev = self.uhdev
  769. assert uhdev.wheel_multiplier == 1
  770. class TestResolutionMultiplierHWheelMouse(TestResolutionMultiplierMouse):
  771. def create_device(self):
  772. return ResolutionMultiplierHWheelMouse()
  773. def is_hwheel_highres(self, uhdev):
  774. high_res = super().is_hwheel_highres(uhdev)
  775. if not high_res:
  776. # the kernel doesn't seem to support the high res wheel mice,
  777. # make sure we haven't triggered the feature
  778. assert uhdev.hwheel_multiplier == 1
  779. return high_res
  780. def test_resolution_multiplier_ac_pan(self):
  781. uhdev = self.uhdev
  782. if not self.is_hwheel_highres(uhdev):
  783. pytest.skip("Kernel not compatible, we can not trigger the conditions")
  784. assert uhdev.hwheel_multiplier > 1
  785. assert 120 % uhdev.hwheel_multiplier == 0
  786. def test_ac_pan_with_multiplier(self):
  787. uhdev = self.uhdev
  788. if not self.is_hwheel_highres(uhdev):
  789. pytest.skip("Kernel not compatible, we can not trigger the conditions")
  790. assert uhdev.hwheel_multiplier > 1
  791. syn_event = self.syn_event
  792. hmult = uhdev.hwheel_multiplier
  793. r = uhdev.event(0, 0, wheels=(0, 1))
  794. expected = [syn_event]
  795. expected.append(
  796. libevdev.InputEvent(libevdev.EV_REL.REL_HWHEEL_HI_RES, 120 / hmult)
  797. )
  798. events = uhdev.next_sync_events()
  799. self.debug_reports(r, uhdev, events)
  800. self.assertInputEvents(expected, events)
  801. r = uhdev.event(0, 0, wheels=(0, -1))
  802. expected = [syn_event]
  803. expected.append(
  804. libevdev.InputEvent(libevdev.EV_REL.REL_HWHEEL_HI_RES, -120 / hmult)
  805. )
  806. events = uhdev.next_sync_events()
  807. self.debug_reports(r, uhdev, events)
  808. self.assertInputEvents(expected, events)
  809. expected = [syn_event]
  810. expected.append(libevdev.InputEvent(libevdev.EV_REL.REL_X, 1))
  811. expected.append(libevdev.InputEvent(libevdev.EV_REL.REL_Y, -2))
  812. expected.append(
  813. libevdev.InputEvent(libevdev.EV_REL.REL_HWHEEL_HI_RES, 120 / hmult)
  814. )
  815. for _ in range(hmult - 1):
  816. r = uhdev.event(1, -2, wheels=(0, 1))
  817. events = uhdev.next_sync_events()
  818. self.debug_reports(r, uhdev, events)
  819. self.assertInputEvents(expected, events)
  820. r = uhdev.event(1, -2, wheels=(0, 1))
  821. expected.append(libevdev.InputEvent(libevdev.EV_REL.REL_HWHEEL, 1))
  822. events = uhdev.next_sync_events()
  823. self.debug_reports(r, uhdev, events)
  824. self.assertInputEvents(expected, events)
  825. class TestMiMouse(TestWheelMouse):
  826. def create_device(self):
  827. return MIDongleMIWirelessMouse()
  828. def assertInputEvents(self, expected_events, effective_events):
  829. # Buttons and x/y are spread over two HID reports, so we can get two
  830. # event frames for this device.
  831. remaining = self.assertInputEventsIn(expected_events, effective_events)
  832. try:
  833. remaining.remove(libevdev.InputEvent(libevdev.EV_SYN.SYN_REPORT, 0))
  834. except ValueError:
  835. # If there's no SYN_REPORT in the list, continue and let the
  836. # assert below print out the real error
  837. pass
  838. assert remaining == []