Mercurial > lcfOS
annotate test/testhexfile.py @ 347:742588fb8cd6 devel
Merge into devel branch
author | Windel Bouwman |
---|---|
date | Fri, 07 Mar 2014 17:10:21 +0100 |
parents | e609d5296ee9 |
children | b4ac28efcdf4 |
rev | line source |
---|---|
233 | 1 import unittest |
2 import io | |
292 | 3 from utils import HexFile, HexFileException |
233 | 4 |
5 | |
6 class testHexFile(unittest.TestCase): | |
244 | 7 def saveload(self, hf): |
8 f = io.StringIO() | |
9 hf.save(f) | |
10 hf2 = HexFile() | |
11 hf2.load(io.StringIO(f.getvalue())) | |
12 self.assertEqual(hf, hf2) | |
245 | 13 |
14 def testSave1(self): | |
244 | 15 hf = HexFile() |
16 hf.addRegion(0x8000, bytes.fromhex('aabbcc')) | |
17 self.saveload(hf) | |
18 | |
245 | 19 def testSave2(self): |
20 hf = HexFile() | |
21 hf.addRegion(0x8000, bytes.fromhex('aabbcc')) | |
22 hf.addRegion(0x118000, bytes.fromhex('aabbcc')) | |
23 self.saveload(hf) | |
24 | |
25 def testSave3(self): | |
26 hf = HexFile() | |
27 hf.addRegion(0x8000, bytes.fromhex('aabbcc')) | |
28 hf.addRegion(0xFFFE, bytes.fromhex('aabbcc')) | |
29 self.saveload(hf) | |
30 | |
307 | 31 @unittest.skip('Takes too long') |
245 | 32 def testSave4(self): |
33 hf = HexFile() | |
251
6ed3d3a82a63
Added another c3 example. First import attempt
Windel Bouwman
parents:
245
diff
changeset
|
34 hf.addRegion(0xF000, bytes.fromhex('ab')*0x10000) |
245 | 35 self.saveload(hf) |
36 | |
307 | 37 @unittest.skip('Takes too long') |
245 | 38 def testSave5(self): |
39 hf = HexFile() | |
251
6ed3d3a82a63
Added another c3 example. First import attempt
Windel Bouwman
parents:
245
diff
changeset
|
40 hf.addRegion(0xF003, bytes.fromhex('ab')*0x10000) |
245 | 41 self.saveload(hf) |
42 | |
292 | 43 def testTwoRegions(self): |
44 hf = HexFile() | |
45 hf2 = HexFile() | |
46 hf.addRegion(0x100, bytes.fromhex('abcd')) | |
47 hf.addRegion(0x200, bytes.fromhex('beef')) | |
48 hf2.addRegion(0x200, bytes.fromhex('beef')) | |
49 hf2.addRegion(0x100, bytes.fromhex('abcd')) | |
50 self.assertEqual(hf, hf2) | |
51 | |
245 | 52 def testMerge(self): |
53 hf = HexFile() | |
54 hf.addRegion(0x10, bytes.fromhex('abcdab')) | |
55 hf.addRegion(0x13, bytes.fromhex('abcdab')) | |
56 self.assertEqual(1, len(hf.regions)) | |
57 | |
58 def testOverlapped(self): | |
59 hf = HexFile() | |
60 hf.addRegion(0x10, bytes.fromhex('abcdab')) | |
61 with self.assertRaisesRegex(HexFileException, 'verlap'): | |
62 hf.addRegion(0x12, bytes.fromhex('abcdab')) | |
63 | |
244 | 64 def testEqual(self): |
65 hf1 = HexFile() | |
66 hf2 = HexFile() | |
67 hf1.addRegion(10, bytes.fromhex('aabbcc')) | |
68 hf2.addRegion(10, bytes.fromhex('aabbcc')) | |
69 self.assertEqual(hf1, hf2) | |
70 | |
71 def testNotEqual(self): | |
72 hf1 = HexFile() | |
73 hf2 = HexFile() | |
74 hf1.addRegion(10, bytes.fromhex('aabbcc')) | |
75 hf2.addRegion(10, bytes.fromhex('aabbdc')) | |
76 self.assertNotEqual(hf1, hf2) | |
245 | 77 |
244 | 78 def testNotEqual2(self): |
79 hf1 = HexFile() | |
80 hf2 = HexFile() | |
81 hf1.addRegion(10, bytes.fromhex('aabbcc')) | |
82 hf2.addRegion(10, bytes.fromhex('aabbcc')) | |
83 hf2.addRegion(22, bytes.fromhex('aabbcc')) | |
84 self.assertNotEqual(hf1, hf2) | |
233 | 85 |
86 def testLoad(self): | |
244 | 87 hf = HexFile() |
292 | 88 dummyhex = """:01400000aa15""" |
233 | 89 f = io.StringIO(dummyhex) |
90 hf.load(f) | |
244 | 91 self.assertEqual(1, len(hf.regions)) |
92 self.assertEqual(0x4000, hf.regions[0].address) | |
93 self.assertSequenceEqual(bytes.fromhex('aa'), hf.regions[0].data) | |
233 | 94 |
95 def testIncorrectCrc(self): | |
244 | 96 hf = HexFile() |
233 | 97 txt = ":01400000aabb" |
98 f = io.StringIO(txt) | |
244 | 99 with self.assertRaisesRegex(HexFileException, 'crc'): |
233 | 100 hf.load(f) |
101 | |
102 def testIncorrectLength(self): | |
244 | 103 hf = HexFile() |
233 | 104 txt = ":0140002200aabb" |
105 f = io.StringIO(txt) | |
244 | 106 with self.assertRaisesRegex(HexFileException, 'count'): |
233 | 107 hf.load(f) |
108 | |
109 if __name__ == '__main__': | |
110 unittest.main() |