test: add a test for pointer vs abs pointer receiving

This commit is contained in:
Peter Hutterer 2023-03-06 16:43:09 +10:00
parent 7f7880d953
commit 99b36ba652

View file

@ -934,3 +934,56 @@ class TestEiProtocol:
assert status.capability is not None
assert status.capability.name == wanted_interface
assert status.capability.version == VERSION_V(1)
@pytest.mark.parametrize(
"wanted_pointer",
(EiDevice.EiCapabilities.POINTER, EiDevice.EiCapabilities.POINTER_ABSOLUTE),
)
def test_connect_receive_pointer(self, eis, wanted_pointer):
"""
Ensure we get the correct pointer device after binding
"""
ei = eis.ei
@attr.s
class Status:
pointer: Optional[Interface] = attr.ib(default=None) # type: ignore
all_caps: int = attr.ib(default=0)
status = Status()
def on_capabilities(device, caps):
status.all_caps |= caps
def on_interface(device, object, name, version, new_objects):
logger.debug(
"new capability",
device=device,
object=object,
name=name,
version=version,
)
if name == "ei_pointer":
status.pointer = new_objects["object"]
def on_new_device(seat, device, version, new_objects):
logger.debug("new device", object=new_objects["device"])
new_objects["device"].connect("Interface", on_interface)
new_objects["device"].connect("Capabilities", on_capabilities)
def on_new_object(o: Interface):
logger.debug("new object", object=o)
if o.name == "ei_seat":
o.connect("Device", on_new_device)
ei.context.connect("register", on_new_object)
ei.dispatch()
ei.init_default_sender_connection()
ei.wait_for_seat()
ei.send(ei.seats[0].Bind(wanted_pointer))
ei.wait_for(lambda: status.pointer is not None)
assert status.pointer is not None
assert status.all_caps & wanted_pointer