Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: tools/json_to_struct/struct_generator_test.py

Issue 1209733002: Add the ability to code generated prepopulated static nested structs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add test Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/json_to_struct/struct_generator.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 from struct_generator import GenerateField 6 from struct_generator import GenerateField
7 from struct_generator import GenerateStruct 7 from struct_generator import GenerateStruct
8 import unittest 8 import unittest
9 9
10 class StructGeneratorTest(unittest.TestCase): 10 class StructGeneratorTest(unittest.TestCase):
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 } 47 }
48 ] 48 ]
49 struct = ('struct MyTypeName {\n' 49 struct = ('struct MyTypeName {\n'
50 ' const int foo_bar;\n' 50 ' const int foo_bar;\n'
51 ' const char* const bar_foo;\n' 51 ' const char* const bar_foo;\n'
52 ' const MyEnumType * bar_bar;\n' 52 ' const MyEnumType * bar_bar;\n'
53 ' const size_t bar_bar_size;\n' 53 ' const size_t bar_bar_size;\n'
54 '};\n') 54 '};\n')
55 self.assertEquals(struct, GenerateStruct('MyTypeName', schema)) 55 self.assertEquals(struct, GenerateStruct('MyTypeName', schema))
56 56
57 def testGenerateArrayOfStruct(self):
58 schema = [
59 {
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'},
68 ]
69 }
70 }
71 ]
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))
83
57 if __name__ == '__main__': 84 if __name__ == '__main__':
58 unittest.main() 85 unittest.main()
OLDNEW
« no previous file with comments | « tools/json_to_struct/struct_generator.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698