| 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 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 self.assertEquals( | 575 self.assertEquals( |
| 576 translator._transitive_imports['root/c.mojom'], struct.imported_from) | 576 translator._transitive_imports['root/c.mojom'], struct.imported_from) |
| 577 | 577 |
| 578 def test_interface(self): | 578 def test_interface(self): |
| 579 self.do_interface_test(True) | 579 self.do_interface_test(True) |
| 580 self.do_interface_test(False) | 580 self.do_interface_test(False) |
| 581 | 581 |
| 582 def do_interface_test(self, specify_service_name): | 582 def do_interface_test(self, specify_service_name): |
| 583 file_name = 'a.mojom' | 583 file_name = 'a.mojom' |
| 584 mojom_interface = mojom_types_mojom.MojomInterface( | 584 mojom_interface = mojom_types_mojom.MojomInterface( |
| 585 current_version=47, |
| 585 decl_data=mojom_types_mojom.DeclarationData( | 586 decl_data=mojom_types_mojom.DeclarationData( |
| 586 short_name='AnInterface', | 587 short_name='AnInterface', |
| 587 source_file_info=mojom_types_mojom.SourceFileInfo( | 588 source_file_info=mojom_types_mojom.SourceFileInfo( |
| 588 file_name=file_name))) | 589 file_name=file_name))) |
| 589 if specify_service_name: | 590 if specify_service_name: |
| 590 mojom_interface.service_name = 'test::TheInterface' | 591 mojom_interface.service_name = 'test::TheInterface' |
| 591 mojom_interface.decl_data.attributes = [mojom_types_mojom.Attribute( | 592 mojom_interface.decl_data.attributes = [mojom_types_mojom.Attribute( |
| 592 key='ServiceName', value=mojom_types_mojom.LiteralValue( | 593 key='ServiceName', value=mojom_types_mojom.LiteralValue( |
| 593 string_value='test::TheInterface'))] | 594 string_value='test::TheInterface'))] |
| 594 else: | 595 else: |
| 595 mojom_interface.service_name = None | 596 mojom_interface.service_name = None |
| 596 mojom_method10 = mojom_types_mojom.MojomMethod( | 597 mojom_method10 = mojom_types_mojom.MojomMethod( |
| 597 ordinal=10, | 598 ordinal=10, |
| 598 decl_data=mojom_types_mojom.DeclarationData( | 599 decl_data=mojom_types_mojom.DeclarationData( |
| 599 short_name='AMethod10', | 600 short_name='AMethod10', |
| 601 declaration_order=1, |
| 600 source_file_info=mojom_types_mojom.SourceFileInfo( | 602 source_file_info=mojom_types_mojom.SourceFileInfo( |
| 601 file_name=file_name)), | 603 file_name=file_name)), |
| 602 parameters=mojom_types_mojom.MojomStruct(fields=[], | 604 parameters=mojom_types_mojom.MojomStruct(fields=[], |
| 603 version_info=build_version_info(0), | 605 version_info=build_version_info(0), |
| 604 decl_data=build_decl_data('AMethod10_Request'))) | 606 decl_data=build_decl_data('AMethod10_Request'))) |
| 605 mojom_method0 = mojom_types_mojom.MojomMethod( | 607 mojom_method0 = mojom_types_mojom.MojomMethod( |
| 606 ordinal=0, | 608 ordinal=0, |
| 607 decl_data=mojom_types_mojom.DeclarationData( | 609 decl_data=mojom_types_mojom.DeclarationData( |
| 608 short_name='AMethod0', | 610 short_name='AMethod0', |
| 611 declaration_order=1, |
| 609 source_file_info=mojom_types_mojom.SourceFileInfo( | 612 source_file_info=mojom_types_mojom.SourceFileInfo( |
| 610 file_name=file_name)), | 613 file_name=file_name)), |
| 611 parameters=mojom_types_mojom.MojomStruct(fields=[], | 614 parameters=mojom_types_mojom.MojomStruct(fields=[], |
| 612 version_info=build_version_info(0), | 615 version_info=build_version_info(0), |
| 613 decl_data=build_decl_data('AMethod0_Request'))) | 616 decl_data=build_decl_data('AMethod0_Request'))) |
| 614 mojom_method7 = mojom_types_mojom.MojomMethod( | 617 mojom_method7 = mojom_types_mojom.MojomMethod( |
| 615 ordinal=7, | 618 ordinal=7, |
| 616 decl_data=mojom_types_mojom.DeclarationData( | 619 decl_data=mojom_types_mojom.DeclarationData( |
| 617 short_name='AMethod7', | 620 short_name='AMethod7', |
| 621 declaration_order=0, |
| 618 source_file_info=mojom_types_mojom.SourceFileInfo( | 622 source_file_info=mojom_types_mojom.SourceFileInfo( |
| 619 file_name=file_name)), | 623 file_name=file_name)), |
| 620 parameters=mojom_types_mojom.MojomStruct(fields=[], | 624 parameters=mojom_types_mojom.MojomStruct(fields=[], |
| 621 version_info=build_version_info(0), | 625 version_info=build_version_info(0), |
| 622 decl_data=build_decl_data('AMethod7_Request'))) | 626 decl_data=build_decl_data('AMethod7_Request'))) |
| 623 mojom_interface.methods = {10: mojom_method10, 0: mojom_method0, | 627 mojom_interface.methods = {10: mojom_method10, 0: mojom_method0, |
| 624 7: mojom_method7} | 628 7: mojom_method7} |
| 625 | 629 |
| 626 interface = module.Interface() | 630 interface = module.Interface() |
| 627 graph = mojom_files_mojom.MojomFileGraph() | 631 graph = mojom_files_mojom.MojomFileGraph() |
| 628 translator = mojom_translator.FileTranslator(graph, file_name) | 632 translator = mojom_translator.FileTranslator(graph, file_name) |
| 629 translator.InterfaceFromMojom(interface, mojom_types_mojom.UserDefinedType( | 633 translator.InterfaceFromMojom(interface, mojom_types_mojom.UserDefinedType( |
| 630 interface_type=mojom_interface)) | 634 interface_type=mojom_interface)) |
| 631 | 635 |
| 636 |
| 632 self.assertEquals(translator._module, interface.module) | 637 self.assertEquals(translator._module, interface.module) |
| 633 self.assertEquals('AnInterface', interface.name) | 638 self.assertEquals('AnInterface', interface.name) |
| 634 self.assertEquals(0, interface.methods[0].ordinal) | 639 self.assertEquals(mojom_interface.current_version, interface.version) |
| 635 self.assertEquals(7, interface.methods[1].ordinal) | 640 # The methods should be ordered by declaration_order. |
| 641 self.assertEquals(7, interface.methods[0].ordinal) |
| 642 self.assertEquals(0, interface.methods[1].ordinal) |
| 636 self.assertEquals(10, interface.methods[2].ordinal) | 643 self.assertEquals(10, interface.methods[2].ordinal) |
| 637 if specify_service_name: | 644 if specify_service_name: |
| 638 self.assertEquals('test::TheInterface', interface.service_name) | 645 self.assertEquals('test::TheInterface', interface.service_name) |
| 639 else: | 646 else: |
| 640 self.assertEquals(None, interface.service_name) | 647 self.assertEquals(None, interface.service_name) |
| 641 | 648 |
| 642 # TODO(azani): Add the contained declarations. | 649 # TODO(azani): Add the contained declarations. |
| 643 | 650 |
| 644 def test_method(self): | 651 def test_method(self): |
| 645 file_name = 'a.mojom' | 652 file_name = 'a.mojom' |
| 646 mojom_method = mojom_types_mojom.MojomMethod( | 653 mojom_method = mojom_types_mojom.MojomMethod( |
| 647 ordinal=10, | 654 ordinal=10, |
| 655 min_version=6, |
| 648 decl_data=mojom_types_mojom.DeclarationData( | 656 decl_data=mojom_types_mojom.DeclarationData( |
| 649 short_name='AMethod', | 657 short_name='AMethod', |
| 650 source_file_info=mojom_types_mojom.SourceFileInfo( | 658 source_file_info=mojom_types_mojom.SourceFileInfo( |
| 651 file_name=file_name))) | 659 file_name=file_name))) |
| 652 | 660 |
| 653 param1 = mojom_types_mojom.StructField( | 661 param1 = mojom_types_mojom.StructField( |
| 654 decl_data=mojom_types_mojom.DeclarationData(short_name='a_param'), | 662 decl_data=mojom_types_mojom.DeclarationData(short_name='a_param'), |
| 655 type=mojom_types_mojom.Type( | 663 type=mojom_types_mojom.Type( |
| 656 simple_type=mojom_types_mojom.SimpleType.UINT32), | 664 simple_type=mojom_types_mojom.SimpleType.UINT32), |
| 657 offset=21, | 665 offset=21, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 670 decl_data=build_decl_data('Not used')) | 678 decl_data=build_decl_data('Not used')) |
| 671 | 679 |
| 672 interface = module.Interface('MyInterface') | 680 interface = module.Interface('MyInterface') |
| 673 graph = mojom_files_mojom.MojomFileGraph() | 681 graph = mojom_files_mojom.MojomFileGraph() |
| 674 translator = mojom_translator.FileTranslator(graph, file_name) | 682 translator = mojom_translator.FileTranslator(graph, file_name) |
| 675 method = translator.MethodFromMojom(mojom_method, interface) | 683 method = translator.MethodFromMojom(mojom_method, interface) |
| 676 | 684 |
| 677 self.assertEquals(mojom_method.decl_data.short_name, method.name) | 685 self.assertEquals(mojom_method.decl_data.short_name, method.name) |
| 678 self.assertEquals(interface, method.interface) | 686 self.assertEquals(interface, method.interface) |
| 679 self.assertEquals(mojom_method.ordinal, method.ordinal) | 687 self.assertEquals(mojom_method.ordinal, method.ordinal) |
| 688 self.assertEquals(mojom_method.min_version, method.min_version) |
| 680 self.assertIsNone(method.response_parameters) | 689 self.assertIsNone(method.response_parameters) |
| 681 self.assertEquals( | 690 self.assertEquals( |
| 682 len(mojom_method.parameters.fields), len(method.parameters)) | 691 len(mojom_method.parameters.fields), len(method.parameters)) |
| 683 self.assertEquals(param1.decl_data.short_name, method.parameters[0].name) | 692 self.assertEquals(param1.decl_data.short_name, method.parameters[0].name) |
| 684 self.assertEquals(param2.decl_data.short_name, method.parameters[1].name) | 693 self.assertEquals(param2.decl_data.short_name, method.parameters[1].name) |
| 685 self.assertEquals('MyInterface_AMethod_Params', method.param_struct.name) | 694 self.assertEquals('MyInterface_AMethod_Params', method.param_struct.name) |
| 686 self.assertEquals(len(mojom_method.parameters.fields), | 695 self.assertEquals(len(mojom_method.parameters.fields), |
| 687 len(method.param_struct.fields)) | 696 len(method.param_struct.fields)) |
| 688 for i in xrange(0, len(mojom_method.parameters.fields)): | 697 for i in xrange(0, len(mojom_method.parameters.fields)): |
| 689 gold = mojom_method.parameters.fields[i] | 698 gold = mojom_method.parameters.fields[i] |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1092 """Builds a list containing a single StructVersion with | 1101 """Builds a list containing a single StructVersion with |
| 1093 version_number=0, num_bytes=0, and the given value for num_fields. Adds this | 1102 version_number=0, num_bytes=0, and the given value for num_fields. Adds this |
| 1094 as the |version_info| attribute of |mojom_struct|. | 1103 as the |version_info| attribute of |mojom_struct|. |
| 1095 | 1104 |
| 1096 Args: | 1105 Args: |
| 1097 mojom_struct: {any} The Python object to which a |version_info| attribute | 1106 mojom_struct: {any} The Python object to which a |version_info| attribute |
| 1098 will be added. | 1107 will be added. |
| 1099 num_fields: {int} The value of num_fields to use. | 1108 num_fields: {int} The value of num_fields to use. |
| 1100 """ | 1109 """ |
| 1101 mojom_struct.version_info=build_version_info(num_fields) | 1110 mojom_struct.version_info=build_version_info(num_fields) |
| OLD | NEW |