def test_read_int_string(self): self.assertEqual( util.read_int_string(b'\xff\xff\xff\xff', 0), (None, 4)) self.assertEqual( util.read_int_string(b'\x00\x00\x00\x00', 0), (b'', 4)) self.assertEqual( util.read_int_string(b'\x00\x00\x00\x0bsome string', 0), (b'some string', 15), )
def test_read_int_string_insufficient_bytes(self): """ BufferUnderflowError results when there aren't enough bytes left to satisfy the string length prefix. """ with self.assertRaises(BufferUnderflowError) as context: util.read_int_string(b'pad\x00\x00\x00\xffstr', 3) self.assertEqual( "Not enough data to read long string at offset 7: 255 bytes required, but 3 available.", str(context.exception), )
def test_read_int_string_missing_length(self): """ BufferUnderflowError results when there aren't enough bytes for a string length at the expected position. """ with self.assertRaises(BufferUnderflowError) as context: util.read_int_string(b'\x01', 0) self.assertEqual( "Not enough data to read long string length at offset 0: 4 bytes required, but 1 available.", str(context.exception), )
def test_read_int_string__insufficient_data_2(self): with self.assertRaises(afkak.common.BufferUnderflowError): util.read_int_string(b'\x00\x00\x00\x021', 2)