def do_interface_test(self, specify_service_name): file_name = 'a.mojom' mojom_interface = mojom_types_mojom.MojomInterface( decl_data=mojom_types_mojom.DeclarationData( short_name='AnInterface', source_file_info=mojom_types_mojom.SourceFileInfo( file_name=file_name))) if specify_service_name: mojom_interface.service_name = 'test::TheInterface' mojom_interface.decl_data.attributes = [mojom_types_mojom.Attribute( key='ServiceName', value=mojom_types_mojom.LiteralValue( string_value='test::TheInterface'))] else: mojom_interface.service_name = None mojom_method10 = mojom_types_mojom.MojomMethod( ordinal=10, decl_data=mojom_types_mojom.DeclarationData( short_name='AMethod10', source_file_info=mojom_types_mojom.SourceFileInfo( file_name=file_name)), parameters=mojom_types_mojom.MojomStruct(fields=[])) mojom_method0 = mojom_types_mojom.MojomMethod( ordinal=0, decl_data=mojom_types_mojom.DeclarationData( short_name='AMethod0', source_file_info=mojom_types_mojom.SourceFileInfo( file_name=file_name)), parameters=mojom_types_mojom.MojomStruct(fields=[])) mojom_method7 = mojom_types_mojom.MojomMethod( ordinal=7, decl_data=mojom_types_mojom.DeclarationData( short_name='AMethod10', source_file_info=mojom_types_mojom.SourceFileInfo( file_name=file_name)), parameters=mojom_types_mojom.MojomStruct(fields=[])) mojom_interface.methods = {10: mojom_method10, 0: mojom_method0, 7: mojom_method7} interface = module.Interface() graph = mojom_files_mojom.MojomFileGraph() translator = mojom_translator.FileTranslator(graph, file_name) translator.InterfaceFromMojom(interface, mojom_types_mojom.UserDefinedType( interface_type=mojom_interface)) self.assertEquals(translator._module, interface.module) self.assertEquals('AnInterface', interface.name) self.assertEquals(0, interface.methods[0].ordinal) self.assertEquals(7, interface.methods[1].ordinal) self.assertEquals(10, interface.methods[2].ordinal) if specify_service_name: self.assertEquals('test::TheInterface', interface.service_name) else: self.assertEquals(None, interface.service_name)
def test_interface(self): file_name = 'a.mojom' mojom_interface = mojom_types_mojom.MojomInterface( decl_data=mojom_types_mojom.DeclarationData( source_file_info=mojom_types_mojom.SourceFileInfo( file_name=file_name)), interface_name='AnInterface') mojom_method = mojom_types_mojom.MojomMethod( ordinal=10, decl_data=mojom_types_mojom.DeclarationData( short_name='AMethod', source_file_info=mojom_types_mojom.SourceFileInfo( file_name=file_name)), parameters=mojom_types_mojom.MojomStruct(fields=[])) mojom_interface.methods = {10: mojom_method} interface = module.Interface() graph = mojom_files_mojom.MojomFileGraph() translator = mojom_translator.FileTranslator(graph, file_name) translator.InterfaceFromMojom( interface, mojom_types_mojom.UserDefinedType(interface_type=mojom_interface)) self.assertEquals(translator._module, interface.module) self.assertEquals(mojom_interface.interface_name, interface.name) self.assertEquals(mojom_method.ordinal, interface.methods[0].ordinal)
def test_method(self): file_name = 'a.mojom' mojom_method = mojom_types_mojom.MojomMethod( ordinal=10, decl_data=mojom_types_mojom.DeclarationData( short_name='AMethod', source_file_info=mojom_types_mojom.SourceFileInfo( file_name=file_name))) param1 = mojom_types_mojom.StructField( decl_data=mojom_types_mojom.DeclarationData(short_name='a_param'), type=mojom_types_mojom.Type( simple_type=mojom_types_mojom.SimpleType.UINT32)) param2 = mojom_types_mojom.StructField( decl_data=mojom_types_mojom.DeclarationData(short_name='b_param'), type=mojom_types_mojom.Type( simple_type=mojom_types_mojom.SimpleType.UINT64)) mojom_method.parameters = mojom_types_mojom.MojomStruct( fields=[param1, param2]) interface = module.Interface() graph = mojom_files_mojom.MojomFileGraph() translator = mojom_translator.FileTranslator(graph, file_name) method = translator.MethodFromMojom(mojom_method, interface) self.assertEquals(mojom_method.decl_data.short_name, method.name) self.assertEquals(interface, method.interface) self.assertEquals(mojom_method.ordinal, method.ordinal) self.assertIsNone(method.response_parameters) self.assertEquals(len(mojom_method.parameters.fields), len(method.parameters)) self.assertEquals(param1.decl_data.short_name, method.parameters[0].name) self.assertEquals(param2.decl_data.short_name, method.parameters[1].name) # Add empty return params. mojom_method.response_params = mojom_types_mojom.MojomStruct(fields=[]) method = translator.MethodFromMojom(mojom_method, interface) self.assertEquals([], method.response_parameters) # Add non-empty return params. mojom_method.response_params.fields = [param1] method = translator.MethodFromMojom(mojom_method, interface) self.assertEquals(param1.decl_data.short_name, method.response_parameters[0].name)
def test_method(self): file_name = 'a.mojom' mojom_method = mojom_types_mojom.MojomMethod( ordinal=10, min_version=6, decl_data=mojom_types_mojom.DeclarationData( short_name='AMethod', source_file_info=mojom_types_mojom.SourceFileInfo( file_name=file_name))) param1 = mojom_types_mojom.StructField( decl_data=mojom_types_mojom.DeclarationData(short_name='a_param'), type=mojom_types_mojom.Type( simple_type=mojom_types_mojom.SimpleType.UINT32), offset=21, bit=6, min_version=11) param2 = mojom_types_mojom.StructField( decl_data=mojom_types_mojom.DeclarationData(short_name='b_param'), type=mojom_types_mojom.Type( simple_type=mojom_types_mojom.SimpleType.UINT64), offset=22, bit=7, min_version=12) mojom_method.parameters = mojom_types_mojom.MojomStruct( fields=[param1, param2], version_info=build_version_info(2), decl_data=build_decl_data('Not used')) interface = module.Interface('MyInterface') graph = mojom_files_mojom.MojomFileGraph() translator = mojom_translator.FileTranslator(graph, file_name) method = translator.MethodFromMojom(mojom_method, interface) self.assertEquals(mojom_method.decl_data.short_name, method.name) self.assertEquals(interface, method.interface) self.assertEquals(mojom_method.ordinal, method.ordinal) self.assertEquals(mojom_method.min_version, method.min_version) self.assertIsNone(method.response_parameters) self.assertEquals(len(mojom_method.parameters.fields), len(method.parameters)) self.assertEquals(param1.decl_data.short_name, method.parameters[0].name) self.assertEquals(param2.decl_data.short_name, method.parameters[1].name) self.assertEquals('MyInterface_AMethod_Params', method.param_struct.name) self.assertEquals(len(mojom_method.parameters.fields), len(method.param_struct.fields)) for i in xrange(0, len(mojom_method.parameters.fields)): gold = mojom_method.parameters.fields[i] f = method.param_struct.fields_in_ordinal_order[i] self.assertEquals(gold.decl_data.short_name, f.name) self.assertEquals(gold.offset, f.computed_offset) self.assertEquals(gold.bit, f.computed_bit) self.assertEquals(gold.min_version, f.computed_min_version) # Add empty return params. mojom_method.response_params = mojom_types_mojom.MojomStruct(fields=[]) add_version_info(mojom_method.response_params, 0) add_decl_data(mojom_method.response_params, 'AMethod_Response') method = translator.MethodFromMojom(mojom_method, interface) self.assertEquals([], method.response_parameters) # Add non-empty return params. mojom_method.response_params.fields = [param1] method = translator.MethodFromMojom(mojom_method, interface) self.assertEquals(param1.decl_data.short_name, method.response_parameters[0].name)