diff options
author | Ole Troan <ot@cisco.com> | 2019-09-18 12:12:47 +0200 |
---|---|---|
committer | Ole Trøan <otroan@employees.org> | 2019-09-18 15:10:12 +0000 |
commit | d5a78a5310ff25c0c34ce5773acd8211d48f59f6 (patch) | |
tree | 76b7607b90fd0af8848520e9185c95616329f48b /src/tools/vppapigen/test_vppapigen.py | |
parent | a41b0b78a4341478ee6c8701f9ec642b5c2d1cdd (diff) |
vppapigen: fix missing vla check for union class
Type: fix
Signed-off-by: Ole Troan <ot@cisco.com>
Change-Id: Ie775cf3469d761847ac39cf0d80a3ec6463b7928
Diffstat (limited to 'src/tools/vppapigen/test_vppapigen.py')
-rwxr-xr-x | src/tools/vppapigen/test_vppapigen.py | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/src/tools/vppapigen/test_vppapigen.py b/src/tools/vppapigen/test_vppapigen.py index 5b64310e51f..cff2400ece3 100755 --- a/src/tools/vppapigen/test_vppapigen.py +++ b/src/tools/vppapigen/test_vppapigen.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import unittest -from vppapigen import VPPAPI, Option, ParseError +from vppapigen import VPPAPI, Option, ParseError, Union # TODO # - test parsing of options, typedefs, enums, defines, CRC @@ -18,6 +18,60 @@ class TestVersion(unittest.TestCase): r = self.parser.parse_string(version_string) self.assertTrue(isinstance(r[0], Option)) +class TestUnion(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.parser = VPPAPI() + + def test_union(self): + test_string = ''' + union foo_union { + u32 a; + u8 b; + }; + ''' + r = self.parser.parse_string(test_string) + self.assertTrue(isinstance(r[0], Union)) + + def test_union_vla(self): + test_string = ''' + union foo_union_vla { + u32 a; + u8 b[a]; + }; + autoreply define foo { + vl_api_foo_union_vla_t v; + }; + ''' + r = self.parser.parse_string(test_string) + self.assertTrue(isinstance(r[0], Union)) + self.assertTrue(r[0].vla) + s = self.parser.process(r) + + + test_string2 = ''' + union foo_union_vla2 { + u32 a; + u8 b[a]; + u32 c; + }; + autoreply define foo2 { + vl_api_foo_union_vla2_t v; + }; + ''' + self.assertRaises(ValueError, self.parser.parse_string, test_string2) + + test_string3 = ''' + union foo_union_vla3 { + u32 a; + u8 b[a]; + }; + autoreply define foo3 { + vl_api_foo_union_vla3_t v; + u32 x; + }; + ''' + self.assertRaises(ValueError, self.parser.parse_string, test_string3) class TestTypedef(unittest.TestCase): @classmethod |