test_common.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #
  2. # Copyright (C) 2014-2015 UAVCAN Development Team <uavcan.org>
  3. #
  4. # This software is distributed under the terms of the MIT License.
  5. #
  6. # Author: Ben Dyer <ben_dyer@mac.com>
  7. # Pavel Kirienko <pavel.kirienko@zubax.com>
  8. #
  9. import os
  10. import unittest
  11. from uavcan.dsdl import common
  12. class TestCRC16FromBytes(unittest.TestCase):
  13. def test_str(self):
  14. self.assertEqual(common.crc16_from_bytes('123456789'), 0x29B1)
  15. def test_bytes(self):
  16. self.assertEqual(common.crc16_from_bytes(b'123456789'), 0x29B1)
  17. def test_bytearray(self):
  18. self.assertEqual(
  19. common.crc16_from_bytes(bytearray('123456789', 'utf-8')),
  20. 0x29B1)
  21. class TestBytesFromCRC64(unittest.TestCase):
  22. def test_zero(self):
  23. self.assertEqual(common.bytes_from_crc64(0),
  24. b"\x00\x00\x00\x00\x00\x00\x00\x00")
  25. def test_check_val(self):
  26. self.assertEqual(common.bytes_from_crc64(0x62EC59E3F1A4F00A),
  27. b"\x0A\xF0\xA4\xF1\xE3\x59\xEC\x62")
  28. if __name__ == '__main__':
  29. unittest.main()