def test_create_header(self): # tests the .rep property to ensure that # a new XIPacketHeader can be created by # the string rep of an existing header. header1 = xi.XIPacketHeader(type=xi.PACKET_TYPE.ACK, payloadLength=0) header2 = xi.XIPacketHeader.createXIPacketHeader(header1.rep) self.assertEqual(header1.rep, header2.rep) header1 = xi.XIPacketHeader(type=xi.PACKET_TYPE.DATA, payloadLength=xi.XIPacket.maxPayload()) header2 = xi.XIPacketHeader.createXIPacketHeader(header1.rep) self.assertEqual(header1.rep, header2.rep) header1 = xi.XIPacketHeader(type=xi.PACKET_TYPE.CONNECTION, payloadLength=2**2) header2 = xi.XIPacketHeader.createXIPacketHeader(header1.rep) self.assertEqual(header1.rep, header2.rep)
def test_non_default_values(self): srcBits = xi.XIPacketHeader()._src_bit_length dstBits = xi.XIPacketHeader()._dst_bit_length seqNumBits = xi.XIPacketHeader()._seq_num_bit_length # test all possible type, src, dst, seq num combinations for _type in [ xi.PACKET_TYPE.ACK, xi.PACKET_TYPE.CONNECTION, xi.PACKET_TYPE.DATA ]: for src in range(2**srcBits): for dst in range(2**dstBits): for seqNum in range(2**seqNumBits): header1 = xi.XIPacketHeader(type=_type, payloadLength=0, seqNum=seqNum, src=src, dst=dst) header2 = xi.XIPacketHeader.createXIPacketHeader( header1.rep) self.assertEqual(header1.rep, header2.rep)
def test_crc_default(self): header1 = xi.XIPacketHeader() header2 = xi.XIPacketHeader() self.assertEqual(header1.crc, header2.crc) header1 = xi.XIPacketHeader(type=xi.PACKET_TYPE.CONNECTION) header2 = xi.XIPacketHeader(type=xi.PACKET_TYPE.CONNECTION) self.assertEqual(header1.crc, header2.crc) header1 = xi.XIPacketHeader(type=xi.PACKET_TYPE.ACK) header2 = xi.XIPacketHeader(type=xi.PACKET_TYPE.ACK) self.assertEqual(header1.crc, header2.crc) header1 = xi.XIPacketHeader(type=xi.PACKET_TYPE.DATA) header2 = xi.XIPacketHeader(type=xi.PACKET_TYPE.DATA) self.assertEqual(header1.crc, header2.crc)
def test_non_default_values(self): seqNumBits = xi.XIPacketHeader()._seq_num_bit_length # test all possible type, src, dst, seq num combinations for _type in [ xi.PACKET_TYPE.ACK, xi.PACKET_TYPE.CONNECTION, xi.PACKET_TYPE.DATA ]: for seqNum in range(2**seqNumBits): payloadLength = xi.XIPacket.maxPayload() packet1 = xi.XIPacket(type=_type, seqNum=seqNum, buffer="".join([ chr(x % 0xFF) for x in range(payloadLength) ])) packet2 = xi.XIPacket.createXIPacket(packet1.rep) self.assertEqual(packet1.rep, packet2.rep)
def test_crc_different_headers(self): header1 = xi.XIPacketHeader(type=xi.PACKET_TYPE.ACK, payloadLength=0) header2 = xi.XIPacketHeader(type=xi.PACKET_TYPE.CONNECTION, payloadLength=0) header3 = xi.XIPacketHeader(type=xi.PACKET_TYPE.DATA, payloadLength=0) self.assertNotEqual(header1.crc, header2.crc) self.assertNotEqual(header1.crc, header3.crc) self.assertNotEqual(header2.crc, header3.crc) header1 = xi.XIPacketHeader(type=xi.PACKET_TYPE.CONNECTION, payloadLength=300) header2 = xi.XIPacketHeader(type=xi.PACKET_TYPE.CONNECTION, payloadLength=3) header3 = xi.XIPacketHeader(type=xi.PACKET_TYPE.CONNECTION, payloadLength=2) self.assertNotEqual(header1.crc, header2.crc) self.assertNotEqual(header1.crc, header3.crc) self.assertNotEqual(header2.crc, header3.crc)
def test_init(self): self.assertNotEqual(xi.XIPacketHeader(), None)