Mercurial > lcfOS
comparison test/testhexfile.py @ 292:534b94b40aa8
Fixup reorganize
author | Windel Bouwman |
---|---|
date | Wed, 27 Nov 2013 08:06:42 +0100 |
parents | 05184b95fa16 |
children | e609d5296ee9 |
comparison
equal
deleted
inserted
replaced
290:7b38782ed496 | 292:534b94b40aa8 |
---|---|
1 import unittest | 1 import unittest |
2 import io | 2 import io |
3 from hexfile import HexFile, HexFileException | 3 from utils import HexFile, HexFileException |
4 | 4 |
5 | 5 |
6 class testHexFile(unittest.TestCase): | 6 class testHexFile(unittest.TestCase): |
7 def saveload(self, hf): | 7 def saveload(self, hf): |
8 f = io.StringIO() | 8 f = io.StringIO() |
36 def testSave5(self): | 36 def testSave5(self): |
37 hf = HexFile() | 37 hf = HexFile() |
38 hf.addRegion(0xF003, bytes.fromhex('ab')*0x10000) | 38 hf.addRegion(0xF003, bytes.fromhex('ab')*0x10000) |
39 self.saveload(hf) | 39 self.saveload(hf) |
40 | 40 |
41 def testTwoRegions(self): | |
42 hf = HexFile() | |
43 hf2 = HexFile() | |
44 hf.addRegion(0x100, bytes.fromhex('abcd')) | |
45 hf.addRegion(0x200, bytes.fromhex('beef')) | |
46 hf2.addRegion(0x200, bytes.fromhex('beef')) | |
47 hf2.addRegion(0x100, bytes.fromhex('abcd')) | |
48 self.assertEqual(hf, hf2) | |
49 | |
41 def testMerge(self): | 50 def testMerge(self): |
42 hf = HexFile() | 51 hf = HexFile() |
43 hf.addRegion(0x10, bytes.fromhex('abcdab')) | 52 hf.addRegion(0x10, bytes.fromhex('abcdab')) |
44 hf.addRegion(0x13, bytes.fromhex('abcdab')) | 53 hf.addRegion(0x13, bytes.fromhex('abcdab')) |
45 self.assertEqual(1, len(hf.regions)) | 54 self.assertEqual(1, len(hf.regions)) |
72 hf2.addRegion(22, bytes.fromhex('aabbcc')) | 81 hf2.addRegion(22, bytes.fromhex('aabbcc')) |
73 self.assertNotEqual(hf1, hf2) | 82 self.assertNotEqual(hf1, hf2) |
74 | 83 |
75 def testLoad(self): | 84 def testLoad(self): |
76 hf = HexFile() | 85 hf = HexFile() |
77 dummyhex = """ | 86 dummyhex = """:01400000aa15""" |
78 :01400000aa15 | |
79 """ | |
80 f = io.StringIO(dummyhex) | 87 f = io.StringIO(dummyhex) |
81 hf.load(f) | 88 hf.load(f) |
82 self.assertEqual(1, len(hf.regions)) | 89 self.assertEqual(1, len(hf.regions)) |
83 self.assertEqual(0x4000, hf.regions[0].address) | 90 self.assertEqual(0x4000, hf.regions[0].address) |
84 self.assertSequenceEqual(bytes.fromhex('aa'), hf.regions[0].data) | 91 self.assertSequenceEqual(bytes.fromhex('aa'), hf.regions[0].data) |
97 with self.assertRaisesRegex(HexFileException, 'count'): | 104 with self.assertRaisesRegex(HexFileException, 'count'): |
98 hf.load(f) | 105 hf.load(f) |
99 | 106 |
100 if __name__ == '__main__': | 107 if __name__ == '__main__': |
101 unittest.main() | 108 unittest.main() |
102 |