When Retrier succeeds, record errors it encountered.
[chromium-blink-merge.git] / tools / json_to_struct / struct_generator_test.py
blob8566c335bcd8b198ca03e5e0ba8ac914e2648163
1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 from struct_generator import GenerateField
7 from struct_generator import GenerateStruct
8 import unittest
10 class StructGeneratorTest(unittest.TestCase):
11 def testGenerateIntField(self):
12 self.assertEquals('const int foo_bar',
13 GenerateField({'type': 'int', 'field': 'foo_bar'}))
15 def testGenerateStringField(self):
16 self.assertEquals('const char* const bar_foo',
17 GenerateField({'type': 'string', 'field': 'bar_foo'}))
19 def testGenerateString16Field(self):
20 self.assertEquals('const wchar_t* const foo_bar',
21 GenerateField({'type': 'string16', 'field': 'foo_bar'}))
23 def testGenerateEnumField(self):
24 self.assertEquals('const MyEnumType foo_foo',
25 GenerateField({'type': 'enum',
26 'field': 'foo_foo',
27 'ctype': 'MyEnumType'}))
29 def testGenerateArrayField(self):
30 self.assertEquals('const int * bar_bar;\n'
31 ' const size_t bar_bar_size',
32 GenerateField({'type': 'array',
33 'field': 'bar_bar',
34 'contents': {'type': 'int'}}))
36 def testGenerateStruct(self):
37 schema = [
38 {'type': 'int', 'field': 'foo_bar'},
39 {'type': 'string', 'field': 'bar_foo', 'default': 'dummy'},
41 'type': 'array',
42 'field': 'bar_bar',
43 'contents': {
44 'type': 'enum',
45 'ctype': 'MyEnumType'
49 struct = ('struct MyTypeName {\n'
50 ' const int foo_bar;\n'
51 ' const char* const bar_foo;\n'
52 ' const MyEnumType * bar_bar;\n'
53 ' const size_t bar_bar_size;\n'
54 '};\n')
55 self.assertEquals(struct, GenerateStruct('MyTypeName', schema))
57 if __name__ == '__main__':
58 unittest.main()