OLD | NEW |
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 Loading... |
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() |
OLD | NEW |