4 from vppapigen import VPPAPI, Option, ParseError
7 # - test parsing of options, typedefs, enums, defines, CRC
8 # - test JSON, C output
11 class TestVersion(unittest.TestCase):
16 def test_version(self):
17 version_string = 'option version = "1.0.0";'
18 r = self.parser.parse_string(version_string)
19 self.assertTrue(isinstance(r[0], Option))
22 class TestTypedef(unittest.TestCase):
27 def test_duplicatetype(self):
29 typeonly define foo1 { u8 dummy; };
30 typeonly define foo1 { u8 dummy; };
32 self.assertRaises(KeyError, self.parser.parse_string, test_string)
35 class TestDefine(unittest.TestCase):
40 def test_unknowntype(self):
41 test_string = 'define foo { foobar foo;};'
42 self.assertRaises(ParseError, self.parser.parse_string, test_string)
43 test_string = 'define { u8 foo;};'
44 self.assertRaises(ParseError, self.parser.parse_string, test_string)
48 manual_print dont_trace manual_endian define foo { u8 foo; };
50 r = self.parser.parse_string(test_string)
51 self.assertIsNotNone(r)
52 s = self.parser.process(r)
53 self.assertIsNotNone(s)
54 for d in s['defines']:
55 self.assertTrue(d.dont_trace)
56 self.assertTrue(d.manual_endian)
57 self.assertTrue(d.manual_print)
58 self.assertFalse(d.autoreply)
61 nonexisting_flag define foo { u8 foo; };
63 self.assertRaises(ParseError, self.parser.parse_string, test_string)
66 class TestService(unittest.TestCase):
71 def test_service(self):
73 service foo { rpc foo (show_version) returns (show_version) };
75 r = self.parser.parse_string(test_string)
79 if __name__ == '__main__':