test_signature.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 unittest
  10. from uavcan.dsdl import signature
  11. class TestSignature(unittest.TestCase):
  12. def test_add(self):
  13. s = signature.Signature()
  14. s.add('123456789')
  15. self.assertEqual(s.get_value(), 0x62EC59E3F1A4F00A)
  16. def test_add_multiple(self):
  17. s = signature.Signature()
  18. for c in '123456789':
  19. s.add(c)
  20. self.assertEqual(s.get_value(), 0x62EC59E3F1A4F00A)
  21. def test_add_bytes(self):
  22. s = signature.Signature()
  23. s.add(b'123456789')
  24. self.assertEqual(s.get_value(), 0x62EC59E3F1A4F00A)
  25. def test_add_bytearray(self):
  26. s = signature.Signature()
  27. s.add(bytearray('123456789', 'utf-8'))
  28. self.assertEqual(s.get_value(), 0x62EC59E3F1A4F00A)
  29. class TestComputeSignature(unittest.TestCase):
  30. def test_str(self):
  31. self.assertEqual(signature.compute_signature('123456789'),
  32. 0x62EC59E3F1A4F00A)
  33. def test_bytes(self):
  34. self.assertEqual(signature.compute_signature(b'123456789'),
  35. 0x62EC59E3F1A4F00A)
  36. def test_bytearray(self):
  37. self.assertEqual(
  38. signature.compute_signature(bytearray('123456789', 'utf-8')),
  39. 0x62EC59E3F1A4F00A)
  40. if __name__ == '__main__':
  41. unittest.main()