Mercurial > lcfOS
annotate test/testhexfile.py @ 284:05184b95fa16
Moved tests to seperate folder
author | Windel Bouwman |
---|---|
date | Fri, 15 Nov 2013 13:43:22 +0100 |
parents | python/testhexfile.py@046017431c6a |
children | 534b94b40aa8 |
rev | line source |
---|---|
233 | 1 import unittest |
2 import io | |
244 | 3 from hexfile 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 | |
31 def testSave4(self): | |
32 hf = HexFile() | |
251
6ed3d3a82a63
Added another c3 example. First import attempt
Windel Bouwman
parents:
245
diff
changeset
|
33 hf.addRegion(0xF000, bytes.fromhex('ab')*0x10000) |
245 | 34 self.saveload(hf) |
35 | |
36 def testSave5(self): | |
37 hf = HexFile() | |
251
6ed3d3a82a63
Added another c3 example. First import attempt
Windel Bouwman
parents:
245
diff
changeset
|
38 hf.addRegion(0xF003, bytes.fromhex('ab')*0x10000) |
245 | 39 self.saveload(hf) |
40 | |
41 def testMerge(self): | |
42 hf = HexFile() | |
43 hf.addRegion(0x10, bytes.fromhex('abcdab')) | |
44 hf.addRegion(0x13, bytes.fromhex('abcdab')) | |
45 self.assertEqual(1, len(hf.regions)) | |
46 | |
47 def testOverlapped(self): | |
48 hf = HexFile() | |
49 hf.addRegion(0x10, bytes.fromhex('abcdab')) | |
50 with self.assertRaisesRegex(HexFileException, 'verlap'): | |
51 hf.addRegion(0x12, bytes.fromhex('abcdab')) | |
52 | |
244 | 53 def testEqual(self): |
54 hf1 = HexFile() | |
55 hf2 = HexFile() | |
56 hf1.addRegion(10, bytes.fromhex('aabbcc')) | |
57 hf2.addRegion(10, bytes.fromhex('aabbcc')) | |
58 self.assertEqual(hf1, hf2) | |
59 | |
60 def testNotEqual(self): | |
61 hf1 = HexFile() | |
62 hf2 = HexFile() | |
63 hf1.addRegion(10, bytes.fromhex('aabbcc')) | |
64 hf2.addRegion(10, bytes.fromhex('aabbdc')) | |
65 self.assertNotEqual(hf1, hf2) | |
245 | 66 |
244 | 67 def testNotEqual2(self): |
68 hf1 = HexFile() | |
69 hf2 = HexFile() | |
70 hf1.addRegion(10, bytes.fromhex('aabbcc')) | |
71 hf2.addRegion(10, bytes.fromhex('aabbcc')) | |
72 hf2.addRegion(22, bytes.fromhex('aabbcc')) | |
73 self.assertNotEqual(hf1, hf2) | |
233 | 74 |
75 def testLoad(self): | |
244 | 76 hf = HexFile() |
233 | 77 dummyhex = """ |
78 :01400000aa15 | |
79 """ | |
80 f = io.StringIO(dummyhex) | |
81 hf.load(f) | |
244 | 82 self.assertEqual(1, len(hf.regions)) |
83 self.assertEqual(0x4000, hf.regions[0].address) | |
84 self.assertSequenceEqual(bytes.fromhex('aa'), hf.regions[0].data) | |
233 | 85 |
86 def testIncorrectCrc(self): | |
244 | 87 hf = HexFile() |
233 | 88 txt = ":01400000aabb" |
89 f = io.StringIO(txt) | |
244 | 90 with self.assertRaisesRegex(HexFileException, 'crc'): |
233 | 91 hf.load(f) |
92 | |
93 def testIncorrectLength(self): | |
244 | 94 hf = HexFile() |
233 | 95 txt = ":0140002200aabb" |
96 f = io.StringIO(txt) | |
244 | 97 with self.assertRaisesRegex(HexFileException, 'count'): |
233 | 98 hf.load(f) |
99 | |
100 if __name__ == '__main__': | |
101 unittest.main() | |
102 |