def test(self, get_type): inst = SCIONCommonHdr() inst.dst_addr_type = 0b111111 inst.src_addr_type = 0b000000 inst.version = 0b1111 inst.total_len = 0x304 inst.hdr_len = 0x8 inst._iof_idx = 3 inst._hof_idx = 4 inst.next_hdr = 0x7 addr_type = create_mock(['name']) addr_type.name.return_value = "name" get_type.return_value = addr_type # Call str(inst)
def _check(self, pkt_len, path_len, expected, iof=1, hof=3): inst = SCIONCommonHdr() inst.total_len = 10 inst._iof_idx = iof inst._hof_idx = hof # Call if expected is None: inst.validate(pkt_len, path_len) return ntools.assert_raises(expected, inst.validate, pkt_len, path_len)
def test(self, calc_lens): # Setup dst_type = 1 src_type = 2 calc_lens.return_value = 44, 0 hdr_len = SCIONCommonHdr.LEN + 44 # Call inst = SCIONCommonHdr.from_values(dst_type, src_type, 3) # Tests ntools.assert_is_instance(inst, SCIONCommonHdr) ntools.eq_(inst.dst_addr_type, dst_type) ntools.eq_(inst.src_addr_type, src_type) calc_lens.assert_called_once_with(dst_type, src_type) ntools.eq_(inst.addrs_len, 44) ntools.eq_(inst.next_hdr, 3) ntools.eq_(inst.hdr_len, hdr_len) ntools.eq_(inst.total_len, hdr_len)
def _setup(self, first_b=0b00001111): inst = SCIONCommonHdr() data = create_mock(["pop"]) data.pop.return_value = bytes([first_b, 0b00111111]) + \ bytes.fromhex('0304 20 38 40 07') return inst, data
def test(self): inst = SCIONCommonHdr() inst.version = 0b1111 inst.dst_addr_type = 0b000000 inst.src_addr_type = 0b111111 inst.addrs_len = 24 inst.total_len = 0x0304 inst.hdr_len = 0x08 inst._iof_idx = 0x03 inst._hof_idx = 0x04 inst.next_hdr = 0x07 expected = b"".join([ bytes([0b11110000, 0b00111111]), bytes.fromhex('0304 08 38 40 07'), ]) # Call ntools.eq_(inst.pack(), expected)