Beispiel #1
0
    def test_field_widths(self):
        field = mtapi.ParseField("Test1", 1)
        self.field_test_ok(field, "2", b'\x02')

        field = mtapi.ParseField("Test2", 2)
        self.field_test_ok(field, "0x123", b'\x23\x01')

        field = mtapi.ParseField("Test3", 3)
        self.field_test_ok(field, "0xfedcba", b'\xba\xdc\xfe')

        field = mtapi.ParseField("Test4", 4)
        self.field_test_ok(field, "0x01020304", b'\x04\x03\x02\x01')
Beispiel #2
0
    def dictionary_test(self, parser, ok_params, fail_params, width=1):
        field = mtapi.ParseField("Test", width, parser=parser)
        for token, result in ok_params.items():
            self.field_test_ok(field, token, result)

        buf = bytearray()
        for token in fail_params:
            self.assertFalse(field.parse_token(token, buf))
Beispiel #3
0
    def test_hword(self):
        field = mtapi.ParseField("TestH", 2, mtapi.field_parse_hword)
        self.field_test_ok(field, "2", b'\x02\x00')
        self.field_test_ok(field, "0x2fe", b'\xfe\x02')
        self.field_test_ok(field, "0x123456", b'\x56\x34')

        buf = bytearray()
        self.assertFalse(field.parse_token("Wombats are go", buf))
Beispiel #4
0
    def test_word(self):
        field = mtapi.ParseField("TestW", 4, mtapi.field_parse_word)
        self.field_test_ok(field, "3", b'\x03\x00\x00\x00')
        self.field_test_ok(field, "0x4fd", b'\xfd\x04\x00\x00')
        self.field_test_ok(field, "0x123456", b'\x56\x34\x12\x00')
        self.field_test_ok(field, "0x89abcdef", b'\xef\xcd\xab\x89')
        self.field_test_ok(field, "0x123456789", b'\x89\x67\x45\x23')

        buf = bytearray()
        self.assertFalse(field.parse_token("StillNaN", buf))
Beispiel #5
0
    def test_basic_numeric_field(self):
        field = mtapi.ParseField("Test", 2)
        self.field_test_ok(field, "1", b'\x01\x00')
        self.field_test_ok(field, "0x1ff", b'\xff\x01')
        self.field_test_ok(field, "0o13", b'\x0b\x00')
        self.field_test_ok(field, "0b1000111", b'\x47\x00')
        self.field_test_ok(field, "0x12345", b'\x45\x23')

        buf = bytearray()
        self.assertFalse(field.parse_token("NotANumber", buf))