summaryrefslogtreecommitdiff
path: root/swift/test/Ice/exceptions/TestAMDI.swift
blob: 63e55dd08d6e6993a46e439dd1408442e50b556f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//

import Ice
import PromiseKit
import TestCommon

class RuntimeError: Error {}

class ThrowerI: Thrower {
    func shutdownAsync(current: Current) -> Promise<Void> {
        return Promise<Void> { seal in
            current.adapter!.getCommunicator().shutdown()
            seal.fulfill(())
        }
    }

    func supportsUndeclaredExceptionsAsync(current _: Current) -> Promise<Bool> {
        return Promise.value(true)
    }

    func supportsAssertExceptionAsync(current _: Current) -> Promise<Bool> {
        return Promise.value(false)
    }

    func throwAasAAsync(a: Int32, current _: Current) -> Promise<Void> {
        return Promise<Void> { seal in
            seal.reject(A(aMem: a))
        }
    }

    func throwAorDasAorDAsync(a: Int32, current _: Current) -> Promise<Void> {
        return Promise<Void> { seal in
            if a > 0 {
                seal.reject(A(aMem: a))
            } else {
                seal.reject(D(dMem: a))
            }
        }
    }

    func throwBasAAsync(a: Int32, b: Int32, current _: Current) -> Promise<Void> {
        return Promise<Void> { seal in
            seal.reject(B(aMem: a, bMem: b))
        }
    }

    func throwCasAAsync(a: Int32, b: Int32, c: Int32, current _: Current) -> Promise<Void> {
        return Promise<Void> { seal in
            seal.reject(C(aMem: a, bMem: b, cMem: c))
        }
    }

    func throwBasBAsync(a: Int32, b: Int32, current _: Current) -> Promise<Void> {
        return Promise<Void> { seal in
            seal.reject(B(aMem: a, bMem: b))
        }
    }

    func throwCasBAsync(a: Int32, b: Int32, c: Int32, current _: Current) -> Promise<Void> {
        return Promise<Void> { seal in
            seal.reject(C(aMem: a, bMem: b, cMem: c))
        }
    }

    func throwCasCAsync(a: Int32, b: Int32, c: Int32, current _: Current) -> Promise<Void> {
        return Promise<Void> { seal in
            seal.reject(C(aMem: a, bMem: b, cMem: c))
        }
    }

    func throwModAAsync(a: Int32, a2: Int32, current _: Current) -> Promise<Void> {
        return Promise<Void> { seal in
            seal.reject(ModA(aMem: a, a2Mem: a2))
        }
    }

    func throwUndeclaredAAsync(a: Int32, current _: Current) -> Promise<Void> {
        return Promise<Void> { seal in
            seal.reject(A(aMem: a))
        }
    }

    func throwUndeclaredBAsync(a: Int32, b: Int32, current _: Current) -> Promise<Void> {
        return Promise<Void> { seal in
            seal.reject(B(aMem: a, bMem: b))
        }
    }

    func throwUndeclaredCAsync(a: Int32, b: Int32, c: Int32, current _: Current) -> Promise<Void> {
        return Promise<Void> { seal in
            seal.reject(C(aMem: a, bMem: b, cMem: c))
        }
    }

    func throwLocalExceptionAsync(current _: Current) -> Promise<Void> {
        return Promise<Void> { seal in
            seal.reject(Ice.TimeoutException())
        }
    }

    func throwNonIceExceptionAsync(current _: Current) -> Promise<Void> {
        return Promise<Void> { seal in
            seal.reject(RuntimeError())
        }
    }

    func throwAssertExceptionAsync(current _: Current) -> Promise<Void> {
        return Promise.value(())
    }

    func throwMemoryLimitExceptionAsync(seq _: ByteSeq, current _: Current) -> Promise<ByteSeq> {
        return Promise<ByteSeq> { seal in
            // 20KB is over the configured 10KB message size max.
            seal.fulfill(ByteSeq(repeating: 0, count: 1024 * 20))
        }
    }

    func throwLocalExceptionIdempotentAsync(current _: Current) -> Promise<Void> {
        return Promise { seal in
            seal.reject(Ice.TimeoutException())
        }
    }

    func throwAfterResponseAsync(current _: Current) -> Promise<Void> {
        return Promise { seal in
            seal.fulfill(())
            throw Ice.RuntimeError("")
        }
    }

    func throwAfterExceptionAsync(current _: Current) -> Promise<Void> {
        return Promise { seal in
            seal.reject(A(aMem: 12345))
            throw Ice.RuntimeError("")
        }
    }

    func throwEAsync(current _: Current) -> Promise<Void> {
        return Promise<Void> { seal in
            seal.reject(E(data: "E"))
        }
    }

    func throwFAsync(current _: Current) -> Promise<Void> {
        return Promise<Void> { seal in
            seal.reject(F(data: "F"))
        }
    }

    func throwGAsync(current _: Current) -> Promise<Void> {
        return Promise<Void> { seal in
            seal.reject(G(data: "G"))
        }
    }

    func throwHAsync(current _: Current) -> Promise<Void> {
        return Promise<Void> { seal in
            seal.reject(H(data: "H"))
        }
    }
}