Ejemplo n.º 1
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))
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
    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))