test_common.py 844 B

123456789101112131415161718192021222324252627282930
  1. import os
  2. import unittest
  3. from uavcan.dsdl import common
  4. class TestCRC16FromBytes(unittest.TestCase):
  5. def test_str(self):
  6. self.assertEqual(common.crc16_from_bytes('123456789'), 0x29B1)
  7. def test_bytes(self):
  8. self.assertEqual(common.crc16_from_bytes(b'123456789'), 0x29B1)
  9. def test_bytearray(self):
  10. self.assertEqual(
  11. common.crc16_from_bytes(bytearray('123456789', 'utf-8')),
  12. 0x29B1)
  13. class TestBytesFromCRC64(unittest.TestCase):
  14. def test_zero(self):
  15. self.assertEqual(common.bytes_from_crc64(0),
  16. b"\x00\x00\x00\x00\x00\x00\x00\x00")
  17. def test_check_val(self):
  18. self.assertEqual(common.bytes_from_crc64(0x62EC59E3F1A4F00A),
  19. b"\x0A\xF0\xA4\xF1\xE3\x59\xEC\x62")
  20. if __name__ == '__main__':
  21. unittest.main()