[Eraser strings] Remove unused Supervised User infobar and corresponding strings
[chromium-blink-merge.git] / tools / json_to_struct / struct_generator_test.py
blobbff5db73af89a778c267bedfe717e76f78beb3c7
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 def testGenerateArrayOfStruct(self):
58 schema = [
60 'type': 'array',
61 'field': 'bar_bar',
62 'contents': {
63 'type': 'struct',
64 'type_name': 'InnerTypeName',
65 'fields': [
66 {'type': 'string', 'field': 'key'},
67 {'type': 'string', 'field': 'value'},
72 struct = (
73 'struct InnerTypeName {\n'
74 ' const char* const key;\n'
75 ' const char* const value;\n'
76 '};\n'
77 '\n'
78 'struct MyTypeName {\n'
79 ' const InnerTypeName * bar_bar;\n'
80 ' const size_t bar_bar_size;\n'
81 '};\n')
82 self.assertEquals(struct, GenerateStruct('MyTypeName', schema))
84 if __name__ == '__main__':
85 unittest.main()