test_common.py
Go to the documentation of this file.
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 
10 import os
11 import unittest
12 from pyuavcan_v0.dsdl import common
13 
14 
15 class TestCRC16FromBytes(unittest.TestCase):
16  def test_str(self):
17  self.assertEqual(common.crc16_from_bytes('123456789'), 0x29B1)
18 
19  def test_bytes(self):
20  self.assertEqual(common.crc16_from_bytes(b'123456789'), 0x29B1)
21 
22  def test_bytearray(self):
23  self.assertEqual(
24  common.crc16_from_bytes(bytearray('123456789', 'utf-8')),
25  0x29B1)
26 
27 
28 class TestBytesFromCRC64(unittest.TestCase):
29  def test_zero(self):
30  self.assertEqual(common.bytes_from_crc64(0),
31  b"\x00\x00\x00\x00\x00\x00\x00\x00")
32 
33  def test_check_val(self):
34  self.assertEqual(common.bytes_from_crc64(0x62EC59E3F1A4F00A),
35  b"\x0A\xF0\xA4\xF1\xE3\x59\xEC\x62")
36 
37 
38 if __name__ == '__main__':
39  unittest.main()


uavcan_communicator
Author(s):
autogenerated on Wed Jan 11 2023 03:59:39