|
1 | | -# Copyright (c) 2005-2016, Alexander Belchenko |
| 1 | +# Copyright (c) 2005-2018, Alexander Belchenko |
2 | 2 | # All rights reserved. |
3 | 3 | # |
4 | 4 | # Redistribution and use in source and binary forms, |
@@ -1659,6 +1659,89 @@ def test_sripts_hexdiff_version(self): |
1659 | 1659 | def test_sripts_hexmerge_version(self): |
1660 | 1660 | self.versionChecker('%s scripts/hexmerge.py --version') |
1661 | 1661 |
|
| 1662 | + |
| 1663 | +class TestWriteHexFileByteCount(unittest.TestCase): |
| 1664 | + |
| 1665 | + def setUp(self): |
| 1666 | + self.f = StringIO(hex8) |
| 1667 | + |
| 1668 | + def tearDown(self): |
| 1669 | + self.f.close() |
| 1670 | + del self.f |
| 1671 | + |
| 1672 | + def test_write_hex_file_bad_byte_count(self): |
| 1673 | + ih = intelhex.IntelHex(self.f) |
| 1674 | + sio = StringIO() |
| 1675 | + self.assertRaises(ValueError, ih.write_hex_file, sio, byte_count=0) |
| 1676 | + self.assertRaises(ValueError, ih.write_hex_file, sio, byte_count=-1) |
| 1677 | + self.assertRaises(ValueError, ih.write_hex_file, sio, byte_count=256) |
| 1678 | + |
| 1679 | + def test_write_hex_file_byte_count_1(self): |
| 1680 | + ih = intelhex.IntelHex(self.f) |
| 1681 | + ih1 = ih[:4] |
| 1682 | + sio = StringIO() |
| 1683 | + ih1.write_hex_file(sio, byte_count=1) |
| 1684 | + s = sio.getvalue() |
| 1685 | + sio.close() |
| 1686 | + # check that we have all data records with data length == 1 |
| 1687 | + self.assertEqual(( |
| 1688 | + ':0100000002FD\n' |
| 1689 | + ':0100010005F9\n' |
| 1690 | + ':01000200A25B\n' |
| 1691 | + ':01000300E517\n' |
| 1692 | + ':00000001FF\n' |
| 1693 | + ), s, |
| 1694 | + "Written hex is not in byte count 1") |
| 1695 | + # read back and check content |
| 1696 | + fin = StringIO(s) |
| 1697 | + ih2 = intelhex.IntelHex(fin) |
| 1698 | + self.assertEqual(ih1.tobinstr(), ih2.tobinstr(), |
| 1699 | + "Written hex file does not equal with original") |
| 1700 | + |
| 1701 | + def test_write_hex_file_byte_count_13(self): |
| 1702 | + ih = intelhex.IntelHex(self.f) |
| 1703 | + sio = StringIO() |
| 1704 | + ih.write_hex_file(sio, byte_count=13) |
| 1705 | + s = sio.getvalue() |
| 1706 | + # control written hex first line to check that byte count is 13 |
| 1707 | + sio.seek(0) |
| 1708 | + self.assertEqual(sio.readline(), |
| 1709 | + ':0D0000000205A2E576246AF8E6057622786E\n', |
| 1710 | + "Written hex is not in byte count 13") |
| 1711 | + sio.close() |
| 1712 | + |
| 1713 | + fin = StringIO(s) |
| 1714 | + ih2 = intelhex.IntelHex(fin) |
| 1715 | + |
| 1716 | + self.assertEqual(ih.tobinstr(), ih2.tobinstr(), |
| 1717 | + "Written hex file does not equal with original") |
| 1718 | + |
| 1719 | + def test_write_hex_file_byte_count_255(self): |
| 1720 | + ih = intelhex.IntelHex(self.f) |
| 1721 | + sio = StringIO() |
| 1722 | + ih.write_hex_file(sio, byte_count=255) |
| 1723 | + s = sio.getvalue() |
| 1724 | + # control written hex first line to check that byte count is 255 |
| 1725 | + sio.seek(0) |
| 1726 | + self.assertEqual(sio.readline(), |
| 1727 | + (':FF0000000205A2E576246AF8E60576227867300702786AE475F0011204AD02' |
| 1728 | + '04552000EB7F2ED2008018EF540F2490D43440D4FF30040BEF24BFB41A0050' |
| 1729 | + '032461FFE57760021577057AE57A7002057930070D7867E475F0011204ADEF' |
| 1730 | + '02049B02057B7403D2078003E4C207F5768B678A688969E4F577F579F57AE5' |
| 1731 | + '7760077F2012003E80F57578FFC201C200C202C203C205C206C20812000CFF' |
| 1732 | + '700D3007057F0012004FAF7AAE7922B4255FC2D5C20412000CFF24D0B40A00' |
| 1733 | + '501A75F00A787730D50508B6FF0106C6A426F620D5047002D20380D924CFB4' |
| 1734 | + '1A00EF5004C2E5D20402024FD20180C6D20080C0D20280BCD2D580BAD20580' |
| 1735 | + 'B47F2012003E20020774010E\n'), |
| 1736 | + "Written hex is not in byte count 255") |
| 1737 | + sio.close() |
| 1738 | + |
| 1739 | + fin = StringIO(s) |
| 1740 | + ih2 = intelhex.IntelHex(fin) |
| 1741 | + |
| 1742 | + self.assertEqual(ih.tobinstr(), ih2.tobinstr(), |
| 1743 | + "Written hex file does not equal with original") |
| 1744 | + |
1662 | 1745 | ## |
1663 | 1746 | # MAIN |
1664 | 1747 | if __name__ == '__main__': |
|
0 commit comments