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)
Example #2
0
  def test_attributes(self):
    mojom_enum = mojom_types_mojom.MojomEnum()
    mojom_enum.decl_data = mojom_types_mojom.DeclarationData()
    gold = {
        'foo': 'bar',
        'other': 'thing',
        'hello': 'world',
        'min_version': 2,
        'pi': 3.14159,
        'is_happy': True
        }
    mojom_enum.decl_data.attributes = []
    for key, value in gold.iteritems():
      mojom_enum.decl_data.attributes.append(
          mojom_types_mojom.Attribute(key=key, value=self.literal_value(value)))

    graph = mojom_files_mojom.MojomFileGraph()
    attributes = mojom_translator.FileTranslator(
        graph, None).AttributesFromMojom(mojom_enum)

    self.assertEquals(gold, attributes)