Пример #1
0
    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)
Пример #2
0
def InterfaceFromData(module, data):
    interface = mojom.Interface(module=module)
    interface.name = data['name']
    interface.spec = 'x:' + module.namespace + '.' + interface.name
    interface.client = data['client'] if data.has_key('client') else None
    module.kinds[interface.spec] = interface
    interface.enums = map(lambda enum: EnumFromData(module, enum, interface),
                          data['enums'])
    # Stash methods data here temporarily.
    interface.methods_data = data['methods']
    return interface
  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)
Пример #4
0
def InterfaceFromData(module, data):
  interface = mojom.Interface(module=module)
  interface.name = data['name']
  interface.spec = 'x:' + module.namespace + '.' + interface.name
  module.kinds[interface.spec] = interface
  interface.enums = map(lambda enum:
      EnumFromData(module, enum, interface), data['enums'])
  interface.constants = map(lambda constant:
      ConstantFromData(module, constant, interface), data['constants'])
  # Stash methods data here temporarily.
  interface.methods_data = data['methods']
  interface.attributes = data.get('attributes')
  return interface
Пример #5
0
def TestNullableTypes():
    kinds = (mojom.STRING.MakeNullableKind(), mojom.HANDLE.MakeNullableKind(),
             mojom.Struct('test_struct').MakeNullableKind(),
             mojom.DCPIPE.MakeNullableKind(), mojom.Array().MakeNullableKind(),
             mojom.DPPIPE.MakeNullableKind(),
             mojom.Array(length=5).MakeNullableKind(),
             mojom.MSGPIPE.MakeNullableKind(),
             mojom.Interface('test_inteface').MakeNullableKind(),
             mojom.SHAREDBUFFER.MakeNullableKind(),
             mojom.InterfaceRequest().MakeNullableKind())
    fields = (1, 2, 4, 3, 5, 6, 8, 7, 9, 10, 11)
    offsets = (0, 8, 12, 16, 24, 32, 36, 40, 48, 52, 56)
    return TestSequence(kinds, fields, offsets)
Пример #6
0
    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)
Пример #7
0
def _Interface(module, parsed_iface):
    """
  Args:
    module: {mojom.Module} Module currently being constructed.
    parsed_iface: {ast.Interface} Parsed interface.

  Returns:
    {mojom.Interface} AST interface.
  """
    interface = mojom.Interface(module=module)
    interface.mojom_name = parsed_iface.mojom_name
    interface.spec = 'x:' + module.mojom_namespace + '.' + interface.mojom_name
    module.kinds[interface.spec] = interface
    interface.enums = map(
        lambda enum: _Enum(module, enum, interface),
        _ElemsOfType(parsed_iface.body, ast.Enum, parsed_iface.mojom_name))
    interface.constants = map(
        lambda constant: _Constant(module, constant, interface),
        _ElemsOfType(parsed_iface.body, ast.Const, parsed_iface.mojom_name))
    # Stash methods parsed_iface here temporarily.
    interface.methods_data = _ElemsOfType(parsed_iface.body, ast.Method,
                                          parsed_iface.mojom_name)
    interface.attributes = _AttributeListToDict(parsed_iface.attribute_list)
    return interface
Пример #8
0
    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)
Пример #9
0
    def do_interface_test(self, specify_service_name):
        file_name = 'a.mojom'
        mojom_interface = fidl_types_fidl.FidlInterface(
            current_version=47,
            decl_data=fidl_types_fidl.DeclarationData(
                short_name='AnInterface',
                source_file_info=fidl_types_fidl.SourceFileInfo(
                    file_name=file_name)))
        if specify_service_name:
            mojom_interface.service_name = 'test::TheInterface'
            mojom_interface.decl_data.attributes = [
                fidl_types_fidl.Attribute(
                    key='ServiceName',
                    value=fidl_types_fidl.LiteralValue(
                        string_value='test::TheInterface'))
            ]
        else:
            mojom_interface.service_name = None
        mojom_method10 = fidl_types_fidl.FidlMethod(
            ordinal=10,
            decl_data=fidl_types_fidl.DeclarationData(
                short_name='AMethod10',
                declaration_order=1,
                source_file_info=fidl_types_fidl.SourceFileInfo(
                    file_name=file_name)),
            parameters=fidl_types_fidl.FidlStruct(
                fields=[],
                version_info=build_version_info(0),
                decl_data=build_decl_data('AMethod10_Request')))
        mojom_method0 = fidl_types_fidl.FidlMethod(
            ordinal=0,
            decl_data=fidl_types_fidl.DeclarationData(
                short_name='AMethod0',
                declaration_order=1,
                source_file_info=fidl_types_fidl.SourceFileInfo(
                    file_name=file_name)),
            parameters=fidl_types_fidl.FidlStruct(
                fields=[],
                version_info=build_version_info(0),
                decl_data=build_decl_data('AMethod0_Request')))
        mojom_method7 = fidl_types_fidl.FidlMethod(
            ordinal=7,
            decl_data=fidl_types_fidl.DeclarationData(
                short_name='AMethod7',
                declaration_order=0,
                source_file_info=fidl_types_fidl.SourceFileInfo(
                    file_name=file_name)),
            parameters=fidl_types_fidl.FidlStruct(
                fields=[],
                version_info=build_version_info(0),
                decl_data=build_decl_data('AMethod7_Request')))
        mojom_interface.methods = {
            10: mojom_method10,
            0: mojom_method0,
            7: mojom_method7
        }

        interface = module.Interface()
        graph = fidl_files_fidl.FidlFileGraph()
        translator = mojom_translator.FileTranslator(graph, file_name)
        translator.InterfaceFromMojom(
            interface,
            fidl_types_fidl.UserDefinedType(interface_type=mojom_interface))

        self.assertEquals(translator._module, interface.module)
        self.assertEquals('AnInterface', interface.name)
        self.assertEquals(mojom_interface.current_version, interface.version)
        # The methods should be ordered by declaration_order.
        self.assertEquals(7, interface.methods[0].ordinal)
        self.assertEquals(0, 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)