Exemplo n.º 1
0
    def test_set_get_id(self):
        l = Libevdev()
        id = l.id
        self.assertEqual(id["bustype"], 0)
        self.assertEqual(id["vendor"], 0)
        self.assertEqual(id["product"], 0)
        self.assertEqual(id["version"], 0)

        id["bustype"] = 1
        id["vendor"] = 2
        id["product"] = 3
        id["version"] = 4

        l.id = id
        id = l.id
        self.assertEqual(id["bustype"], 1)
        self.assertEqual(id["vendor"], 2)
        self.assertEqual(id["product"], 3)
        self.assertEqual(id["version"], 4)

        del id["bustype"]
        del id["vendor"]
        del id["product"]
        id["version"] = 5

        l.id = id
        id = l.id
        self.assertEqual(id["bustype"], 1)
        self.assertEqual(id["vendor"], 2)
        self.assertEqual(id["product"], 3)
        self.assertEqual(id["version"], 5)
Exemplo n.º 2
0
 def test_prop_to_name_invalid(self):
     name = Libevdev.property_to_name(-1)
     self.assertIsNone(name)
     name = Libevdev.property_to_name(100)
     self.assertIsNone(name)
     with self.assertRaises(ctypes.ArgumentError):
         name = Libevdev.property_to_name("foo")
Exemplo n.º 3
0
 def testDeviceNode(self):
     dev = Libevdev()
     dev.name = "test device"
     dev.enable("EV_REL", "REL_X")
     dev.enable("EV_REL", "REL_Y")
     uinput = UinputDevice(dev)
     self.assertTrue(uinput.devnode.startswith("/dev/input/event"))
Exemplo n.º 4
0
 def testSyspath(self):
     dev = Libevdev()
     dev.name = "test device"
     dev.enable("EV_REL", "REL_X")
     dev.enable("EV_REL", "REL_Y")
     uinput = UinputDevice(dev)
     self.assertTrue(uinput.syspath.startswith("/sys/devices/virtual/input/input"))
Exemplo n.º 5
0
 def test_code_to_name_invalid(self):
     name = Libevdev.event_to_name(0, 1000)
     self.assertIsNone(name)
     name = Libevdev.event_to_name(0, -1)
     self.assertIsNone(name)
     with self.assertRaises(ctypes.ArgumentError):
         name = Libevdev.event_to_name(0, "foo")
Exemplo n.º 6
0
 def test_set_slot_value(self):
     l = Libevdev(self.fd)
     v = l.slot_value(l.current_slot, "ABS_MT_POSITION_X")
     v += 10
     v2 = l.slot_value(l.current_slot, "ABS_MT_POSITION_X", v)
     self.assertEqual(v, v2)
     v2 = l.slot_value(l.current_slot, "ABS_MT_POSITION_X")
     self.assertEqual(v, v2)
Exemplo n.º 7
0
 def test_get_set_event_value(self):
     l = Libevdev(self.fd)
     v = l.event_value("EV_ABS", "ABS_Y")
     self.assertIsNotNone(v)
     v = l.event_value(0x03, 0x01, new_value=300)
     self.assertEqual(v, 300)
     v = l.event_value(0x03, 0x01)
     self.assertEqual(v, 300)
Exemplo n.º 8
0
 def test_absinfo(self):
     l = Libevdev(self.fd)
     a = l.absinfo("ABS_Y")
     self.assertTrue("minimum" in a)
     self.assertTrue("maximum" in a)
     self.assertTrue("resolution" in a)
     self.assertTrue("fuzz" in a)
     self.assertTrue("flat" in a)
     self.assertTrue("value" in a)
Exemplo n.º 9
0
 def is_identical(self, d1, d2):
     for t in range(Libevdev.event_to_value("EV_MAX")):
         max = Libevdev.type_max(t)
         if max is None:
             continue
         for c in range(max):
             if d1.has_event(t, c) != d1.has_event(t, c):
                 return False
     return True
Exemplo n.º 10
0
 def test_set_clock_id(self):
     l = Libevdev(self.fd)
     try:
         import time
         clock = time.CLOCK_MONOTONIC
     except AttributeError:
         clock = 1
     rc = l.set_clock_id(clock)
     self.assertEqual(rc, 0)
Exemplo n.º 11
0
    def test_init_fd(self):
        l = Libevdev(self.fd)
        fd = l.fd
        self.assertEqual(self.fd, fd)

        fd2 = open("/dev/input/event3", "rb")
        l.fd = fd2
        fd = l.fd
        self.assertEqual(fd, fd2)
        fd2.close()
Exemplo n.º 12
0
    def test_prop_name(self):
        name = Libevdev.property_to_name(0)
        self.assertEqual(name, "INPUT_PROP_POINTER")

        prevname = None
        for i in range(5):
            name = Libevdev.property_to_name(i)
            self.assertIsNotNone(name)
            self.assertTrue(name.startswith("INPUT_PROP_"))
            self.assertNotEqual(prevname, name)
            prevname = name
Exemplo n.º 13
0
    def test_type_to_name(self):
        name = Libevdev.event_to_name(1)
        self.assertEqual(name, "EV_KEY")

        prevname = None
        for i in range(5):
            name = Libevdev.event_to_name(i)
            self.assertIsNotNone(name)
            self.assertTrue(name.startswith("EV_"))
            self.assertNotEqual(prevname, name)
            prevname = name
Exemplo n.º 14
0
    def test_set_get_name(self):
        l = Libevdev()
        name = l.name
        self.assertEqual(name, '')

        l.name = "foo"
        name = l.name
        self.assertEqual(name, "foo")

        l.name = None
        name = l.name
        self.assertEqual(name, "")
Exemplo n.º 15
0
    def test_set_absinfo(self):
        l = Libevdev(self.fd)
        real_a = l.absinfo("ABS_Y")
        a = l.absinfo("ABS_Y")
        a["minimum"] = 100
        a["maximum"] = 200
        a["fuzz"] = 300
        a["flat"] = 400
        a["resolution"] = 500
        a["value"] = 600

        a = l.absinfo("ABS_Y", new_values=a)
        self.assertEqual(a["minimum"], 100)
        self.assertEqual(a["maximum"], 200)
        self.assertEqual(a["fuzz"], 300)
        self.assertEqual(a["flat"], 400)
        self.assertEqual(a["resolution"], 500)
        self.assertEqual(a["value"], 600)

        l2 = Libevdev(self.fd)
        a2 = l2.absinfo("ABS_Y")
        self.assertNotEqual(a["minimum"], real_a["minimum"])
        self.assertNotEqual(a["maximum"], real_a["maximum"])
        self.assertNotEqual(a["fuzz"], real_a["fuzz"])
        self.assertNotEqual(a["flat"], real_a["flat"])
        self.assertNotEqual(a["resolution"], real_a["resolution"])
        self.assertEqual(a2["value"], real_a["value"])
        self.assertEqual(a2["minimum"], real_a["minimum"])
        self.assertEqual(a2["maximum"], real_a["maximum"])
        self.assertEqual(a2["fuzz"], real_a["fuzz"])
        self.assertEqual(a2["flat"], real_a["flat"])
        self.assertEqual(a2["resolution"], real_a["resolution"])
        self.assertEqual(a2["value"], real_a["value"])
Exemplo n.º 16
0
    def test_set_get_phys(self):
        l = Libevdev()
        phys = l.phys
        self.assertIsNone(phys)

        l.phys = "foo"
        phys = l.phys
        self.assertEqual(phys, "foo")

        # libevdev issue: phys may be NULL (unlike the name) but we can't
        # set it to NULL. But the conversion code returns None for the empty
        # string, so let's test for that
        l.phys = None
        phys = l.phys
        self.assertEqual(phys, None)
Exemplo n.º 17
0
    def test_set_get_uniq(self):
        l = Libevdev()
        uniq = l.uniq
        self.assertIsNone(uniq)

        l.uniq = "foo"
        uniq = l.uniq
        self.assertEqual(uniq, "foo")

        # libevdev issue: phys may be NULL (unlike the name) but we can't
        # set it to NULL. But the conversion code returns None for the empty
        # string, so let's test for that
        l.uniq = None
        uniq = l.uniq
        self.assertEqual(uniq, None)
Exemplo n.º 18
0
 def test_ids(self):
     l = Libevdev(self.fd)
     id = l.id
     self.assertNotEqual(id["bustype"], 0)
     self.assertNotEqual(id["vendor"], 0)
     self.assertNotEqual(id["product"], 0)
     self.assertNotEqual(id["version"], 0)
Exemplo n.º 19
0
    def setUp(self):
        want_fd = None
        for i in range(20):
            try:
                fd = open("/dev/input/event{}".format(i), "rb")
                l = Libevdev(fd)
                if l.has_event("EV_ABS", "ABS_Y"):
                    want_fd = fd
                    break
                fd.close()
            except IOError:
                # Not all eventX nodes are guaranteed to exist
                pass

        self.assertIsNotNone(want_fd)
        self.fd = want_fd
Exemplo n.º 20
0
    def test_has_event(self):
        l = Libevdev(self.fd)
        self.assertTrue(l.has_event("EV_SYN", "SYN_REPORT"))

        type_supported = -1
        for i in range(1, 5):
            if l.has_event(i):
                type_supported = i
                break

        self.assertGreater(type_supported, 0)

        codes_supported = 0
        for i in range(150):
            if l.has_event(type_supported, i):
                codes_supported += 1

        self.assertGreater(codes_supported, 0)
Exemplo n.º 21
0
    def testButton(self):
        dev = Libevdev()
        dev.name = "test device"
        dev.enable("EV_KEY", "BTN_LEFT")
        dev.enable("EV_KEY", "KEY_A")
        uinput = UinputDevice(dev)
        self.assertIsNotNone(uinput.devnode)

        with open(uinput.devnode) as f:
            newdev = Libevdev(f)
            self.assertTrue(self.is_identical(dev, newdev))
Exemplo n.º 22
0
    def test_has_property(self):
        """
        Let's assume at least one between event0 and event10 is a device
        with at least one property set. May cause false negatives.
        """

        props_supported = 0
        for i in range(10):
            try:
                with open("/dev/input/event{}".format(i), "rb") as fd:
                    l = Libevdev(fd)

                    for p in range(6):
                        if l.has_property(p):
                            props_supported += 1
            except IOError:
                # Not all eventX nodes are guaranteed to exist
                pass
        self.assertGreater(props_supported, 0)
Exemplo n.º 23
0
    def testRelative(self):
        dev = Libevdev()
        dev.name = "test device"
        dev.enable("EV_REL", "REL_X")
        dev.enable("EV_REL", "REL_Y")
        uinput = UinputDevice(dev)
        self.assertIsNotNone(uinput.devnode)

        with open(uinput.devnode) as f:
            newdev = Libevdev(f)
            self.assertTrue(self.is_identical(dev, newdev))
Exemplo n.º 24
0
    def testAbsolute(self):
        absinfo = {"minimum": 0,
                   "maximum": 1}

        dev = Libevdev()
        dev.name = "test device"
        dev.enable("EV_ABS", "ABS_X", absinfo)
        dev.enable("EV_ABS", "ABS_Y", absinfo)
        uinput = UinputDevice(dev)
        self.assertIsNotNone(uinput.devnode)

        with open(uinput.devnode) as f:
            newdev = Libevdev(f)
            self.assertTrue(self.is_identical(dev, newdev))
Exemplo n.º 25
0
 def test_ctx_init(self):
     l = Libevdev()
     del l
Exemplo n.º 26
0
 def test_code_value_invalid(self):
     v = Libevdev.event_to_value("EV_REL", "KEY_ESC")
     self.assertIsNone(v)
Exemplo n.º 27
0
    def test_code_value(self):
        v = Libevdev.event_to_value("EV_REL", "REL_Y")
        self.assertEqual(v, 1)

        v = Libevdev.event_to_value(0, "SYN_DROPPED")
        self.assertEqual(v, 3)
Exemplo n.º 28
0
 def test_type_value_invalid(self):
     v = Libevdev.event_to_value("foo")
     self.assertIsNone(v)
     with self.assertRaises(AttributeError):
         v = Libevdev.event_to_value(0)
Exemplo n.º 29
0
 def test_type_to_value(self):
     v = Libevdev.event_to_value("EV_REL")
     self.assertEqual(v, 2)
Exemplo n.º 30
0
    def test_code_to_name(self):
        name = Libevdev.event_to_name(0, 0)
        self.assertEqual(name, "SYN_REPORT")

        name = Libevdev.event_to_name(1, 1)
        self.assertEqual(name, "KEY_ESC")