Ejemplo n.º 1
0
def test_usage_types():
    assert hid_parser.Usage(
        0x0001, 0x0001).usage_types == (hid_parser.data.UsageTypes.CP, )
    assert hid_parser.Usage(0x0001, 0x0047).usage_types == (
        hid_parser.data.UsageTypes.DV,
        hid_parser.data.UsageTypes.DF,
    )
Ejemplo n.º 2
0
def test_create():
    usage = hid_parser.Usage(0x1234, 0x4321)

    assert usage.page == 0x1234
    assert usage.usage == 0x4321

    usage = hid_parser.Usage(extended_usage=0x12344321)

    assert usage.page == 0x1234
    assert usage.usage == 0x4321
Ejemplo n.º 3
0
def test_arrayitem():
    assert issubclass(hid_parser.ArrayItem, hid_parser.MainItem)

    usages = [
        hid_parser.Usage(0x0001, 0x0030),
        hid_parser.Usage(0x0001, 0x0031),
    ]

    item = hid_parser.ArrayItem(0, 0, 0, 1, usages, -1, 1)

    assert item.usages == usages
Ejemplo n.º 4
0
def test_repr():
    assert repr(hid_parser.Usage(0x1234,
                                 0x4321)) == 'Usage(page=0x1234, usage=0x4321)'
    assert repr(hid_parser.Usage(
        extended_usage=0x12344321)) == 'Usage(page=0x1234, usage=0x4321)'
    assert repr(hid_parser.Usage(
        0x0001,
        0x0000)) == 'Usage(page=Generic Desktop Controls, usage=0x0000)'
    assert repr(hid_parser.Usage(
        0x0001,
        0x0001)) == 'Usage(page=Generic Desktop Controls, usage=Pointer)'
Ejemplo n.º 5
0
def test_eq():
    assert hid_parser.Usage(0x1234, 0x4321) == hid_parser.Usage(0x1234, 0x4321)
    assert hid_parser.Usage(
        0x1234, 0x4321) == hid_parser.Usage(extended_usage=0x12344321)
    assert hid_parser.Usage(extended_usage=0x12344321) == hid_parser.Usage(
        0x1234, 0x4321)

    assert hid_parser.Usage(0x1234, 0x4321) != hid_parser.Usage(0x1234, 0x1234)
    assert hid_parser.Usage(0x1234, 0x4321) != []
Ejemplo n.º 6
0
def test_arrayitem_repr():
    usages = [
        hid_parser.Usage(0x0001, 0x0030),
        hid_parser.Usage(0x0001, 0x0031),
    ]
    assert repr(hid_parser.ArrayItem(
        1, 2, 10, 0, usages, -1,
        1)) == ('ArrayItem(\n'
                '    offset=1bit, size=2bits, count=10,\n'
                '    usages=[\n'
                '        Usage(page=Generic Desktop Controls, usage=X),\n'
                '        Usage(page=Generic Desktop Controls, usage=Y),\n'
                '    ],\n'
                ')')
Ejemplo n.º 7
0
def test_create_error():
    with pytest.raises(
            ValueError,
            match=
            'You need to specify either the usage page and usage or the extended usage'
    ):
        hid_parser.Usage(0x1234, 0x4321, extended_usage=0x12344321)

    with pytest.raises(ValueError, match='No usage specified'):
        hid_parser.Usage()

    with pytest.raises(ValueError, match='No usage specified'):
        hid_parser.Usage(page=0x1234)

    with pytest.raises(ValueError, match='No usage specified'):
        hid_parser.Usage(usage=0x1234)
Ejemplo n.º 8
0
def test_variableitem_compliance():
    with pytest.warns(hid_parser.HIDComplianceWarning):
        hid_parser.VariableItem(1, 2, 0, hid_parser.Usage(0x0001, 0x0001), -1,
                                1)

    with pytest.warns(None):
        hid_parser.VariableItem(1, 2, 0, hid_parser.Usage(0x0001, 0x0030), -1,
                                1)

    with pytest.warns(None):
        hid_parser.VariableItem(1, 2, 0, hid_parser.Usage(0x0001, 0x0000), -1,
                                1)

    with pytest.warns(None):
        hid_parser.VariableItem(1, 2, 0, hid_parser.Usage(0x0000, 0x0000), -1,
                                1)
Ejemplo n.º 9
0
def test_arrayitem_compliance():
    usages = [
        hid_parser.Usage(0x0001, 0x0030),
        hid_parser.Usage(0x0001, 0x0031),
    ]

    with pytest.warns(hid_parser.HIDComplianceWarning):
        hid_parser.ArrayItem(1, 2, 1, 0, usages, -1, 1)

    with pytest.warns(None):
        hid_parser.ArrayItem(1, 2, 1, 0, usages, -1, 1)

    with pytest.warns(None):
        hid_parser.ArrayItem(1, 2, 1, 0, usages, -1, 1)

    with pytest.warns(None):
        hid_parser.ArrayItem(1, 2, 1, 0, usages, -1, 1)
Ejemplo n.º 10
0
def test_linux_hidpp_items():
    rdesc = hid_parser.ReportDescriptor(linux_hidpp_rdesc)

    assert rdesc.input_report_ids == [
        0x01,
        0x02,
        0x10,
        0x11,
        0x20,
        0x21,
    ]
    assert rdesc.output_report_ids == [
        0x0e,
        0x10,
        0x11,
        0x20,
        0x21,
    ]
    assert rdesc.feature_report_ids == []

    items = rdesc.get_input_items(0x01)

    offset = 0

    usage = hid_parser.data.KeyboardKeypad.KEYBOARD_LEFT_CONTROL
    for item in items[:8]:
        assert isinstance(item, hid_parser.VariableItem)
        assert int(item.offset) == offset
        assert int(item.size) == 1
        assert item.usage.page == hid_parser.data.UsagePages.KEYBOARD_KEYPAD_PAGE
        assert item.usage.usage == usage
        offset += 1
        usage += 1

    usages = []
    for i in range(255 + 1):
        usages.append(
            hid_parser.Usage(hid_parser.data.UsagePages.KEYBOARD_KEYPAD_PAGE,
                             i))

    for item in items[8:]:
        assert isinstance(item, hid_parser.ArrayItem)
        assert int(item.offset) == offset
        assert int(item.size) == 8
        assert item.usages == usages
        offset += 8
Ejemplo n.º 11
0
def test_int():
    assert int(hid_parser.Usage(0x1234, 0x4321)) == 0x12344321
    assert int(hid_parser.Usage(extended_usage=0x12344321)) == 0x12344321
Ejemplo n.º 12
0
def test_variableitem():
    assert issubclass(hid_parser.VariableItem, hid_parser.MainItem)

    item = hid_parser.VariableItem(0, 0, 0b00000000,
                                   hid_parser.Usage(0x0001, 0x0030), -1, 1)

    assert item.usage == hid_parser.Usage(0x0001, 0x0030)

    assert item.wrap is False
    assert item.linear is False
    assert item.preferred_state is False
    assert item.null_state is False
    assert item.buffered_bytes is False
    assert item.bitfield is True

    item = hid_parser.VariableItem(0, 0, 0b00001000,
                                   hid_parser.Usage(0x0001, 0x0030), -1, 1)

    assert item.wrap is True
    assert item.linear is False
    assert item.preferred_state is False
    assert item.null_state is False
    assert item.buffered_bytes is False
    assert item.bitfield is True

    item = hid_parser.VariableItem(0, 0, 0b00010000,
                                   hid_parser.Usage(0x0001, 0x0030), -1, 1)

    assert item.wrap is False
    assert item.linear is True
    assert item.preferred_state is False
    assert item.null_state is False
    assert item.buffered_bytes is False
    assert item.bitfield is True

    item = hid_parser.VariableItem(0, 0, 0b00100000,
                                   hid_parser.Usage(0x0001, 0x0030), -1, 1)

    assert item.wrap is False
    assert item.linear is False
    assert item.preferred_state is True
    assert item.null_state is False
    assert item.buffered_bytes is False
    assert item.bitfield is True

    item = hid_parser.VariableItem(0, 0, 0b01000000,
                                   hid_parser.Usage(0x0001, 0x0030), -1, 1)

    assert item.wrap is False
    assert item.linear is False
    assert item.preferred_state is False
    assert item.null_state is True
    assert item.buffered_bytes is False
    assert item.bitfield is True

    item = hid_parser.VariableItem(0, 0, 0b10000000,
                                   hid_parser.Usage(0x0001, 0x0030), -1, 1)

    assert item.wrap is False
    assert item.linear is False
    assert item.preferred_state is False
    assert item.null_state is False
    assert item.buffered_bytes is True
    assert item.bitfield is False
Ejemplo n.º 13
0
def test_variableitem_repr():
    assert repr(hid_parser.VariableItem(1, 2, 0, hid_parser.Usage(0x0001, 0x0030), -1, 1)) == \
        'VariableItem(offset=1bit, size=2bits, usage=Usage(page=Generic Desktop Controls, usage=X))'