| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import unittest | 5 import unittest |
| 6 import module | 6 import module |
| 7 | 7 |
| 8 try: | 8 try: |
| 9 import mojom_translator | 9 import mojom_translator |
| 10 from generated import mojom_files_mojom | 10 from generated import mojom_files_mojom |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 source_file_info =mojom_types_mojom.SourceFileInfo( | 285 source_file_info =mojom_types_mojom.SourceFileInfo( |
| 286 file_name=file_name))) | 286 file_name=file_name))) |
| 287 graph.resolved_types = {'struct_key': mojom_types_mojom.UserDefinedType( | 287 graph.resolved_types = {'struct_key': mojom_types_mojom.UserDefinedType( |
| 288 struct_type=mojom_struct)} | 288 struct_type=mojom_struct)} |
| 289 | 289 |
| 290 enum = module.Enum() | 290 enum = module.Enum() |
| 291 translator = mojom_translator.FileTranslator(graph, file_name) | 291 translator = mojom_translator.FileTranslator(graph, file_name) |
| 292 translator.EnumFromMojom( | 292 translator.EnumFromMojom( |
| 293 enum, mojom_types_mojom.UserDefinedType(enum_type=mojom_enum)) | 293 enum, mojom_types_mojom.UserDefinedType(enum_type=mojom_enum)) |
| 294 | 294 |
| 295 self.assertEquals('AStruct.' + mojom_enum.decl_data.short_name, enum.name) | 295 self.assertEquals(mojom_enum.decl_data.short_name, enum.name) |
| 296 self.assertEquals(len(mojom_enum.values), len(enum.fields)) | 296 self.assertEquals(len(mojom_enum.values), len(enum.fields)) |
| 297 | 297 |
| 298 def test_unions(self): | 298 def test_unions(self): |
| 299 file_name = 'a.mojom' | 299 file_name = 'a.mojom' |
| 300 mojom_union = mojom_types_mojom.MojomUnion() | 300 mojom_union = mojom_types_mojom.MojomUnion() |
| 301 mojom_union.decl_data = mojom_types_mojom.DeclarationData( | 301 mojom_union.decl_data = mojom_types_mojom.DeclarationData( |
| 302 short_name='AUnion', | 302 short_name='AUnion', |
| 303 source_file_info=mojom_types_mojom.SourceFileInfo(file_name=file_name)) | 303 source_file_info=mojom_types_mojom.SourceFileInfo(file_name=file_name)) |
| 304 | 304 |
| 305 field1 = mojom_types_mojom.UnionField( | 305 field1 = mojom_types_mojom.UnionField( |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 contained_declarations = mojom_types_mojom.ContainedDeclarations( | 519 contained_declarations = mojom_types_mojom.ContainedDeclarations( |
| 520 enums=['enum_key'], constants=['value_key']) | 520 enums=['enum_key'], constants=['value_key']) |
| 521 | 521 |
| 522 translator = mojom_translator.FileTranslator(graph, file_name) | 522 translator = mojom_translator.FileTranslator(graph, file_name) |
| 523 struct = module.Struct(name='parent') | 523 struct = module.Struct(name='parent') |
| 524 translator._type_cache['parent_key'] = struct | 524 translator._type_cache['parent_key'] = struct |
| 525 translator.PopulateContainedDeclarationsFromMojom( | 525 translator.PopulateContainedDeclarationsFromMojom( |
| 526 struct, contained_declarations) | 526 struct, contained_declarations) |
| 527 | 527 |
| 528 self.assertEquals( | 528 self.assertEquals( |
| 529 'parent.' + mojom_enum.decl_data.short_name, struct.enums[0].name) | 529 mojom_enum.decl_data.short_name, struct.enums[0].name) |
| 530 self.assertEquals(struct, struct.enums[0].parent_kind) | 530 self.assertEquals(struct, struct.enums[0].parent_kind) |
| 531 self.assertEquals( | 531 self.assertEquals( |
| 532 mojom_const.decl_data.short_name, struct.constants[0].name) | 532 mojom_const.decl_data.short_name, struct.constants[0].name) |
| 533 self.assertEquals(struct, struct.constants[0].parent_kind) | 533 self.assertEquals(struct, struct.constants[0].parent_kind) |
| 534 | 534 |
| 535 | 535 |
| 536 @unittest.skipUnless(bindings_imported, 'Could not import python bindings.') | 536 @unittest.skipUnless(bindings_imported, 'Could not import python bindings.') |
| 537 class TestValueFromMojom(unittest.TestCase): | 537 class TestValueFromMojom(unittest.TestCase): |
| 538 | 538 |
| 539 def test_literal_value(self): | 539 def test_literal_value(self): |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 result2 = t.KindFromMojom(mojom_type) | 795 result2 = t.KindFromMojom(mojom_type) |
| 796 self.assertIs(result, result2) | 796 self.assertIs(result, result2) |
| 797 | 797 |
| 798 # Nullable type reference | 798 # Nullable type reference |
| 799 mojom_type.type_reference.nullable = True | 799 mojom_type.type_reference.nullable = True |
| 800 nullable_result = t.KindFromMojom(mojom_type) | 800 nullable_result = t.KindFromMojom(mojom_type) |
| 801 self.assertTrue(module.IsNullableKind(nullable_result)) | 801 self.assertTrue(module.IsNullableKind(nullable_result)) |
| 802 | 802 |
| 803 if __name__ == '__main__': | 803 if __name__ == '__main__': |
| 804 unittest.main() | 804 unittest.main() |
| OLD | NEW |