Exemple #1
0
    def test_array_type(self):
        array_types = [
            (False, False, -1),
            (False, False, 10),
            (True, False, -1),
            (True, True, -1),
            (False, True, -1),
            (False, True, 10),
        ]
        g = mojom_files_mojom.MojomFileGraph()
        t = mojom_translator.FileTranslator(g, None)

        for array_nullable, element_nullable, size in array_types:
            a = mojom_types_mojom.Type()
            a.array_type = mojom_types_mojom.ArrayType(nullable=array_nullable,
                                                       fixed_length=size)
            a.array_type.element_type = mojom_types_mojom.Type(
                string_type=mojom_types_mojom.StringType(
                    nullable=element_nullable))

            result = t.KindFromMojom(a)
            self.assertTrue(module.IsArrayKind(result))
            self.assertTrue(module.IsStringKind(result.kind))
            self.assertEquals(array_nullable, module.IsNullableKind(result))
            self.assertEquals(element_nullable,
                              module.IsNullableKind(result.kind))

            if size < 0:
                self.assertIsNone(result.length)
            else:
                self.assertEquals(size, result.length)
    def test_map_type(self):
        map_types = [
            (False, False),
            (True, False),
            (False, True),
            (True, True),
        ]
        g = fidl_files_fidl.FidlFileGraph()
        t = mojom_translator.FileTranslator(g, None)

        for map_nullable, value_nullable in map_types:
            m = fidl_types_fidl.Type()
            m.map_type = fidl_types_fidl.MapType(nullable=map_nullable)
            m.map_type.key_type = fidl_types_fidl.Type(
                string_type=fidl_types_fidl.StringType())
            m.map_type.value_type = fidl_types_fidl.Type(
                handle_type=fidl_types_fidl.HandleType(
                    kind=fidl_types_fidl.HandleType.Kind.VMO,
                    nullable=value_nullable))

            result = t.KindFromMojom(m)
            self.assertTrue(module.IsMapKind(result))
            self.assertTrue(module.IsStringKind(result.key_kind))
            self.assertTrue(module.IsVMOKind(result.value_kind))
            self.assertEquals(map_nullable, module.IsNullableKind(result))
            self.assertEquals(value_nullable,
                              module.IsNullableKind(result.value_kind))
Exemple #3
0
    def test_map_type(self):
        map_types = [
            (False, False),
            (True, False),
            (False, True),
            (True, True),
        ]
        g = mojom_files_mojom.MojomFileGraph()
        t = mojom_translator.FileTranslator(g, None)

        for map_nullable, value_nullable in map_types:
            m = mojom_types_mojom.Type()
            m.map_type = mojom_types_mojom.MapType(nullable=map_nullable)
            m.map_type.key_type = mojom_types_mojom.Type(
                string_type=mojom_types_mojom.StringType())
            m.map_type.value_type = mojom_types_mojom.Type(
                handle_type=mojom_types_mojom.HandleType(
                    kind=mojom_types_mojom.HandleType.Kind.SHARED_BUFFER,
                    nullable=value_nullable))

            result = t.KindFromMojom(m)
            self.assertTrue(module.IsMapKind(result))
            self.assertTrue(module.IsStringKind(result.key_kind))
            self.assertTrue(module.IsSharedBufferKind(result.value_kind))
            self.assertEquals(map_nullable, module.IsNullableKind(result))
            self.assertEquals(value_nullable,
                              module.IsNullableKind(result.value_kind))
Exemple #4
0
  def test_user_defined_type_type(self):
    graph = mojom_files_mojom.MojomFileGraph()
    mojom_struct = mojom_types_mojom.MojomStruct(
        decl_data=mojom_types_mojom.DeclarationData(short_name='FirstStruct'))
    type_key = 'some opaque string'
    mojom_struct.fields = [
        # Make sure recursive structs are correctly handled.
        mojom_types_mojom.StructField(
          decl_data=mojom_types_mojom.DeclarationData(short_name='field00'),
          type=mojom_types_mojom.Type(
            type_reference=mojom_types_mojom.TypeReference(type_key=type_key)))
        ]
    add_version_info(mojom_struct, 1)
    graph.resolved_types = {
        type_key: mojom_types_mojom.UserDefinedType(struct_type=mojom_struct)}

    mojom_type = mojom_types_mojom.Type()
    mojom_type.type_reference = mojom_types_mojom.TypeReference(
        type_key=type_key)

    t = mojom_translator.FileTranslator(graph, None)
    result = t.KindFromMojom(mojom_type)
    self.assertTrue(module.IsStructKind(result))
    self.assertEquals(mojom_struct.decl_data.short_name, result.name)
    self.assertEquals(result, result.fields[0].kind)
    self.assertEquals(type_key, result.type_key)

    # Make sure we create only one module object per type.
    result2 = t.KindFromMojom(mojom_type)
    self.assertIs(result, result2)

    # Nullable type reference
    mojom_type.type_reference.nullable = True
    nullable_result = t.KindFromMojom(mojom_type)
    self.assertTrue(module.IsNullableKind(nullable_result))