def test04_CheckSumAdler32(self): self.assertEqual(0x00000001, eformat.helper.checksum(eformat.helper.CheckSum.ADLER32, [])) self.assertEqual(0x00180004, eformat.helper.checksum(eformat.helper.CheckSum.ADLER32, [1, 2])) self.assertEqual(0x23d407f1, eformat.helper.checksum(eformat.helper.CheckSum.ADLER32, [0xffffffff, 0xfff7ffff])) self.assertEqual(0x23d407f1, eformat.helper.checksum(eformat.helper.CheckSum.ADLER32, eformat.u32list([0xffffffff, 0xfff7ffff]))) # calling it a second time should give the same result self.assertEqual(0x23d407f1, eformat.helper.checksum(eformat.helper.CheckSum.ADLER32, eformat.u32list([0xffffffff, 0xfff7ffff])))
def block_data(method, data=None): """Sets or gets u32 data blocks""" if data: if not (isinstance(data, read.u32list) or isinstance(data, read.u32slice)): data = read.u32list(data) # we try a conversion method(data) else: return method()
def test05_CheckSumCrc16Ccitt(self): self.assertEqual(0xffffffff, eformat.helper.checksum(eformat.helper.CheckSum.CRC16_CCITT, [])) self.assertEqual(0x84c093b2, eformat.helper.checksum(eformat.helper.CheckSum.CRC16_CCITT, [1, 2])) self.assertEqual(0x9c071d0f, eformat.helper.checksum(eformat.helper.CheckSum.CRC16_CCITT, [0xffffffff, 0xfff7ffff])) self.assertEqual(0x9c071d0f, eformat.helper.checksum(eformat.helper.CheckSum.CRC16_CCITT, eformat.u32list([0xffffffff, 0xfff7ffff]))) # calling it a second time should give the same result self.assertEqual(0x9c071d0f, eformat.helper.checksum(eformat.helper.CheckSum.CRC16_CCITT, eformat.u32list([0xffffffff, 0xfff7ffff]))) # symmetry should be respected for symmetric entries tmp = eformat.helper.checksum(eformat.helper.CheckSum.CRC16_CCITT, eformat.u32list([0x0, 0x0])) self.assertEqual(tmp & 0xffff, tmp >> 16) tmp = eformat.helper.checksum(eformat.helper.CheckSum.CRC16_CCITT, eformat.u32list([0xffffffff, 0xffffffff])) self.assertEqual(tmp & 0xffff, tmp >> 16)