def testInvalidMagic(self): """Asserts that an exception is raised when the magic is invalid. """ stream = io.BytesIO(struct.pack('L', 0xC0BFFFFFFFFFFF10)) p = sancov_parser.SancovParser(stream) with self.assertRaises(parser.FileFormatError) as context: p.Parse() self.assertTrue('Invalid magic' in str(context.exception))
def testMagic64(self): """Asserts that values are correctly read in 64-bit sancov files. """ stream = io.BytesIO(struct.pack('L', sancov_parser.MAGIC64)) stream.seek(8) values = (4, 5, 6) stream.write(struct.pack('LLL', *values)) stream.seek(0) p = sancov_parser.SancovParser(stream) s = p.Parse() self.assertEqual(64, p._bitness) self.assertEqual(values, s)
def testMagic32(self): """Asserts that values are correctly read in 32-bit sancov files. """ stream = io.BytesIO(struct.pack('L', sancov_parser.MAGIC32)) stream.seek(8) values = (1, 2, 3) stream.write(struct.pack('III', *values)) stream.seek(0) p = sancov_parser.SancovParser(stream) s = p.Parse() self.assertEqual(32, p._bitness) self.assertEqual(values, s)
def testGetBitness64(self): """Asserts that bitness is correctly determined from a 64-bit sancov file. """ stream = io.BytesIO(struct.pack('L', sancov_parser.MAGIC64)) p = sancov_parser.SancovParser(stream) self.assertEqual(64, p.GetBitness())