blob: a8a0a49a8dba70f141656fcb61cde4188445ecb2 [file] [log] [blame]
Paul Vinciguerra7e0c48e2019-02-01 19:37:45 -08001#!/usr/bin/env python3
Ole Troan9d420872017-10-12 13:06:35 +02002
3import unittest
4from vppapigen import VPPAPI, Option, ParseError
5
6# TODO
7# - test parsing of options, typedefs, enums, defines, CRC
8# - test JSON, C output
9
10
11class TestVersion(unittest.TestCase):
12 @classmethod
13 def setUpClass(cls):
14 cls.parser = VPPAPI()
15
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))
20
21
22class TestTypedef(unittest.TestCase):
23 @classmethod
24 def setUpClass(cls):
25 cls.parser = VPPAPI()
26
27 def test_duplicatetype(self):
28 test_string = '''
29 typeonly define foo1 { u8 dummy; };
30 typeonly define foo1 { u8 dummy; };
31 '''
32 self.assertRaises(KeyError, self.parser.parse_string, test_string)
33
34
35class TestDefine(unittest.TestCase):
36 @classmethod
37 def setUpClass(cls):
38 cls.parser = VPPAPI()
39
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)
45
46 def test_flags(self):
47 test_string = '''
48 manual_print dont_trace manual_endian define foo { u8 foo; };
49 '''
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)
59
60 test_string = '''
61 nonexisting_flag define foo { u8 foo; };
62 '''
Paul Vinciguerra7e0c48e2019-02-01 19:37:45 -080063 with self.assertRaises(ParseError):
64 self.parser.parse_string(test_string)
Ole Troan9d420872017-10-12 13:06:35 +020065
66
67class TestService(unittest.TestCase):
68 @classmethod
69 def setUpClass(cls):
70 cls.parser = VPPAPI()
71
72 def test_service(self):
73 test_string = '''
74 service foo { rpc foo (show_version) returns (show_version) };
75 '''
76 r = self.parser.parse_string(test_string)
77 print('R', r)
78
79
80if __name__ == '__main__':
81 unittest.main()