def test_decode_valid_unicast_packet_with_eight_byte_data(self):
        expectedAsbPacket = AsbPacket(
            meta=AsbMeta(type=0x02, port=0x42, source=0x00A1, target=0x00B1),
            length=8,
            data=[0xAA, 0x01, 0xBB, 0x02, 0xCC, 0x03, 0xDD, 0x04])

        decodedPacket = decodeAsbPacket("2B1A1428AA1BB2CC3DD4")
        self.assertEqual(expectedAsbPacket, decodedPacket)
    def test_decode_valid_multicast_packet(self):
        expectedAsbPacket = AsbPacket(meta=AsbMeta(type=0x01,
                                                   port=0xFF,
                                                   source=0x00A1,
                                                   target=0x00B1),
                                      length=2,
                                      data=[0xAA, 0x02])

        decodedPacket = decodeAsbPacket("1B1A1FF2AA2")
        self.assertEqual(expectedAsbPacket, decodedPacket)
    def test_decode_valid_broadcast_packet(self):
        expectedAsbPacket = AsbPacket(meta=AsbMeta(type=0x00,
                                                   port=0xFF,
                                                   source=0x000A,
                                                   target=0x0000),
                                      length=2,
                                      data=[0x51, 0x01])

        decodedPacket = decodeAsbPacket("00AFF2511")
        self.assertEqual(expectedAsbPacket, decodedPacket)
    def test_decode_valid_unicast_packet_with_lowercase_hex_data(self):
        expectedAsbPacket = AsbPacket(meta=AsbMeta(type=0x02,
                                                   port=0x42,
                                                   source=0x00A1,
                                                   target=0x00B1),
                                      length=4,
                                      data=[0xAA, 0x01, 0xBB, 0x02])

        decodedPacket = decodeAsbPacket("2B1A1424aa1bb2")
        self.assertEqual(expectedAsbPacket, decodedPacket)
    def test_decode_valid_unicast_packet_with_one_byte_data(self):
        expectedAsbPacket = AsbPacket(meta=AsbMeta(type=0x02,
                                                   port=0x42,
                                                   source=0x0034,
                                                   target=0x0012),
                                      length=1,
                                      data=[0x44])

        decodedPacket = decodeAsbPacket("2123442144")
        self.assertEqual(expectedAsbPacket, decodedPacket)
    def test_decode_valid_unicast_packet_with_multibyte_source_and_address(
            self):
        expectedAsbPacket = AsbPacket(meta=AsbMeta(type=0x02,
                                                   port=0x42,
                                                   source=0x1234,
                                                   target=0x5678),
                                      length=2,
                                      data=[0xAA, 0xBB])

        decodedPacket = decodeAsbPacket("256781234422AABB")
        self.assertEqual(expectedAsbPacket, decodedPacket)
 def test_decode_invalid_packet_string(self):
     self.assertIsNone(decodeAsbPacket("invalidpacketstring"))