Beispiel #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)
Beispiel #2
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))
Beispiel #3
0
    def test_string_type(self):
        g = mojom_files_mojom.MojomFileGraph()
        t = mojom_translator.FileTranslator(g, None)

        s = mojom_types_mojom.Type(string_type=mojom_types_mojom.StringType())
        self.assertEquals(module.STRING, t.KindFromMojom(s))

        s.string_type.nullable = True
        self.assertEquals(module.NULLABLE_STRING, t.KindFromMojom(s))