def test_error(self): obj = binstruct.Binstruct(b"\x05test") with self.assertRaises(binstruct.error): obj.unpack_block_uleb128() obj = binstruct.Binstruct(b"") with self.assertRaises(binstruct.error): obj.unpack_block_uleb128() obj = binstruct.Binstruct(b"test") with self.assertRaises(TypeError): obj.unpack_block_uleb128(None)
def test_block(self): obj = binstruct.Binstruct(b"\x03test") value = obj.unpack_block_uleb128() self.assertIsInstance(value, str) self.assertEqual(value, "tes") self.assertEqual(obj.pos, 4) obj = binstruct.Binstruct(b"\x84\x80\x80\x00test") value = obj.unpack_block_uleb128() self.assertIsInstance(value, str) self.assertEqual(value, "test") self.assertEqual(obj.pos, 8)
def test_error(self): obj = binstruct.Binstruct(b"\x00\x00\x00\x00\x00\x00\x00\x05test") with self.assertRaises(binstruct.error): obj.unpack_block_be64() obj = binstruct.Binstruct(b"\x05\x00\x00\x00\x00\x00\x00\x00test") with self.assertRaises(binstruct.error): obj.unpack_block_le64() obj = binstruct.Binstruct(b"") with self.assertRaises(binstruct.error): obj.unpack_block_be64() with self.assertRaises(binstruct.error): obj.unpack_block_le64() obj = binstruct.Binstruct(b"test") with self.assertRaises(TypeError): obj.unpack_block_be64(None) with self.assertRaises(TypeError): obj.unpack_block_le64(None)
def test_string(self): obj = binstruct.Binstruct(b"test\x00next\x00") value = obj.unpack_string() self.assertIsInstance(value, str) self.assertEqual(value, "test") self.assertEqual(obj.pos, 5) value = obj.unpack_string() self.assertIsInstance(value, str) self.assertEqual(value, "next") self.assertEqual(obj.pos, 10)
def test_u8(self): obj = binstruct.Binstruct(b"\x81\x82") with self.assertRaises(TypeError): obj.unpack_u8(None) value = obj.unpack_u8() self.assertEqual(value, 0x81) self.assertEqual(obj.pos, 1) self.assertIsInstance(value, int) self.assertEqual(obj.unpack_u8(), 0x82) self.assertEqual(obj.pos, 2)
def test_bool(self): obj = binstruct.Binstruct(b"\x00\x01") value = obj.unpack_bool() self.assertIsInstance(value, bool) self.assertEqual(value, False) self.assertEqual(obj.pos, 1) value = obj.unpack_bool() self.assertIsInstance(value, bool) self.assertEqual(value, True) self.assertEqual(obj.pos, 2) with self.assertRaises(binstruct.error): obj.unpack_bool()
def test_block(self): obj = binstruct.Binstruct(b"\x00\x00\x00\x00\x00\x00\x00\x03test") value = obj.unpack_block_be64() self.assertIsInstance(value, str) self.assertEqual(value, "tes") self.assertEqual(obj.pos, 11) obj = binstruct.Binstruct(b"\x03\x00\x00\x00\x00\x00\x00\x00test") value = obj.unpack_block_le64() self.assertIsInstance(value, str) self.assertEqual(value, "tes") self.assertEqual(obj.pos, 11) obj = binstruct.Binstruct(b"\x00\x00\x00\x00\x00\x00\x00\x00test") value = obj.unpack_block_be64() self.assertIsInstance(value, str) self.assertEqual(value, "") self.assertEqual(obj.pos, 8) obj = binstruct.Binstruct(b"\x00\x00\x00\x00\x00\x00\x00\x00test") value = obj.unpack_block_le64() self.assertIsInstance(value, str) self.assertEqual(value, "") self.assertEqual(obj.pos, 8)
def test_block(self): obj = binstruct.Binstruct(b"test\x11") value = obj.unpack_block(4) self.assertIsInstance(value, str) self.assertEqual(value, b"test") self.assertEqual(obj.pos, 4) value = obj.unpack_block(1) self.assertIsInstance(value, str) self.assertEqual(value, b"\x11") self.assertEqual(obj.pos, 5) value = obj.unpack_block(0) self.assertIsInstance(value, str) self.assertEqual(value, b"") self.assertEqual(obj.pos, 5)
def test_error(self): data = "test\x11" obj = binstruct.Binstruct(data) with self.assertRaises(TypeError): obj.unpack_block() with self.assertRaises(TypeError): obj.unpack_block(None) with self.assertRaises(binstruct.error): obj.unpack_block(-1) with self.assertRaises(binstruct.error): obj.unpack_block(6) obj.pos = 5 with self.assertRaises(binstruct.error): obj.unpack_block(1) self.assertEqual(obj.pos, 5)
def test_empty(self): obj = binstruct.Binstruct(b"") with self.assertRaises(binstruct.error): obj.unpack_string()
def test_range_u8(self): obj = binstruct.Binstruct(b"") with self.assertRaises(binstruct.error): obj.unpack_u8() with self.assertRaises(binstruct.error): obj.pos += 1
def setUp(self): self.data = b"\x11\x22\x00\x44\x55" self.obj = binstruct.Binstruct(self.data)
def test_value(self): obj = binstruct.Binstruct(b"\xE5\x8E\x26\x00\xFF") value = obj.unpack_uleb128() self.assertIsInstance(value, int) self.assertEqual(value, 624485) self.assertEqual(obj.pos, 3)
def test_long(self): obj = binstruct.Binstruct(b"\xFF\xFF\xFF\xFF\xFF\xE5\x8E\x26\x00\xFF") value = obj.unpack_uleb128() self.assertIsInstance(value, long) self.assertEqual(value, 18446744073709551615L) self.assertEqual(obj.pos, 8)
def test_arg(self): obj = binstruct.Binstruct(b"\01") with self.assertRaises(TypeError): obj.unpack_string(None)
def setUp(self): self.obj = binstruct.Binstruct(b"\x81\x82\x83\x84\x85\x86\x87\x88")
def test_unterminated(self): obj = binstruct.Binstruct(b"test") value = obj.unpack_string() self.assertIsInstance(value, str) self.assertEqual(value, "test")
def test_value(self): obj = binstruct.Binstruct(b"\x9b\xf1\x59\x00\xFF") value = obj.unpack_sleb128() self.assertIsInstance(value, int) self.assertEqual(value, -624485) self.assertEqual(obj.pos, 3)
def test_messy(self): obj = binstruct.Binstruct(b"\x80\x01") self.assertEqual(obj.unpack_sleb128(), 0x80) self.assertEqual(obj.pos, 2)
def test_corrupt(self): obj = binstruct.Binstruct(b"\x80") with self.assertRaises(binstruct.error): obj.unpack_sleb128()
def test_zero(self): obj = binstruct.Binstruct(b"\x00") self.assertEqual(obj.unpack_sleb128(), 0) self.assertEqual(obj.pos, 1)
def test_long(self): obj = binstruct.Binstruct(b"\xFF\xFF\xFF\xE5\x8E\x76\x00\xFF") value = obj.unpack_sleb128() self.assertIsInstance(value, int) self.assertEqual(value, -322961409) self.assertEqual(obj.pos, 6)