File: byte_array_test.py

package info (click to toggle)
lcm 1.3.1%2Brepack1-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,848 kB
  • sloc: ansic: 16,186; java: 6,843; cs: 2,266; cpp: 1,594; python: 989; makefile: 352; xml: 252; sh: 59
file content (29 lines) | stat: -rwxr-xr-x 821 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/python
import struct
import unittest

import lcmtest

class TestByteArray(unittest.TestCase):

    def test_construct(self):
        """Verify that a message constructed without explicitly setting any
        fields can be encoded."""
        msg = lcmtest.byte_array_t()
        msg.encode()

    def test_fill(self):
        """Create a message with a small byte array and encode it.  Decode it
        and verify that the decoded message matches the original."""
        msg = lcmtest.byte_array_t()
        msg.num_bytes = 5
        msg.data = struct.pack("bbbbb", 1, 2, 3, 4, 5)

        data = msg.encode()

        decoded = lcmtest.byte_array_t.decode(data)
        self.assertEqual(5, decoded.num_bytes)
        self.assertEqual(msg.data, decoded.data)

if __name__ == '__main__':
    unittest.main()