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
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',
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',
34 'contents': {'type': 'int'}}))
36 def testGenerateStruct(self
):
38 {'type': 'int', 'field': 'foo_bar'},
39 {'type': 'string', 'field': 'bar_foo', 'default': 'dummy'},
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'
55 self
.assertEquals(struct
, GenerateStruct('MyTypeName', schema
))
57 if __name__
== '__main__':