def testStructDataConversion(self): """Tests that a struct can be converted from data.""" module = mojom.Module('test_module', 'test_namespace') struct_data = { 'name': 'SomeStruct', 'enums': [], 'constants': [], 'fields': [{ 'name': 'field1', 'kind': 'i32' }, { 'name': 'field2', 'kind': 'i32', 'ordinal': 10 }, { 'name': 'field3', 'kind': 'i32', 'default': 15 }] } struct = data.StructFromData(module, struct_data) struct.fields = map( lambda field: data.FieldFromData(module, field, struct), struct.fields_data) self.assertEquals(struct_data, data.StructToData(struct))
def testUnionDataConversion(self): """Tests that a union can be converted from data.""" module = mojom.Module('test_module', 'test_namespace') union_data = { 'name': 'SomeUnion', 'fields': [ {'name': 'field1', 'kind': 'i32'}, {'name': 'field2', 'kind': 'i32', 'ordinal': 10}]} union = data.UnionFromData(module, union_data) union.fields = map(lambda field: data.FieldFromData(module, field, union), union.fields_data) self.assertEquals(union_data, data.UnionToData(union))