summaryrefslogtreecommitdiff
path: root/swift/test/Ice/servantLocator/AllTests.swift
blob: 51232f4075dbd684be9c1490c5d95ed340bf6421 (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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//

import Ice
import TestCommon

func testExceptions(_ obj: TestIntfPrx, _ helper: TestHelper) throws {
    do {
        try obj.requestFailedException()
        try helper.test(false)
    } catch let ex as Ice.ObjectNotExistException {
        try helper.test(ex.id == obj.ice_getIdentity())
        try helper.test(ex.facet == obj.ice_getFacet())
        try helper.test(ex.operation == "requestFailedException")
    }

    do {
        try obj.unknownUserException()
        try helper.test(false)
    } catch let ex as Ice.UnknownUserException {
        try helper.test(ex.unknown == "reason")
    }

    do {
        try obj.unknownLocalException()
        try helper.test(false)
    } catch let ex as Ice.UnknownLocalException {
        try helper.test(ex.unknown == "reason")
    }

    do {
        try obj.unknownException()
        try helper.test(false)
    } catch let ex as Ice.UnknownException {
        try helper.test(ex.unknown == "reason")
    }

    do {
        try obj.userException()
        try helper.test(false)
    } catch let ex as Ice.UnknownUserException {
        try helper.test(ex.unknown.contains("Test::TestIntfUserException"))
    } catch is Ice.OperationNotExistException {}

    do {
        try obj.localException()
        try helper.test(false)
    } catch let ex as Ice.UnknownLocalException {
        try helper.test(ex.unknown.contains("Ice::SocketException") || ex.unknown.contains("Ice.SocketException"))
    }

    do {
        try obj.unknownExceptionWithServantException()
        try helper.test(false)
    } catch let ex as Ice.UnknownException {
        try helper.test(ex.unknown == "reason")
    }

    do {
        _ = try obj.impossibleException(false)
        try helper.test(false)
    } catch is Ice.UnknownUserException {
        // Operation doesn't throw, but locate() and finished() throw TestIntfUserException.
    }

    do {
        _ = try obj.impossibleException(true)
        try helper.test(false)
    } catch is Ice.UnknownUserException {
        // Operation throws TestImpossibleException, but locate() and finished() throw TestIntfUserException.
    }

    do {
        _ = try obj.intfUserException(false)
        try helper.test(false)
    } catch is TestImpossibleException {
        // Operation doesn't throw, but locate() and finished() throw TestImpossibleException.
    }

    do {
        _ = try obj.intfUserException(true)
        try helper.test(false)
    } catch is TestImpossibleException {
        // Operation throws TestIntfUserException, but locate() and finished() throw TestImpossibleException.
    }
}

func allTests(_ helper: TestHelper) throws -> TestIntfPrx {
    func test(_ value: Bool, file: String = #file, line: Int = #line) throws {
        try helper.test(value, file: file, line: line)
    }
    let output = helper.getWriter()

    let communicator = helper.communicator()

    output.write("testing stringToProxy... ")
    var base = try communicator.stringToProxy("asm:\(helper.getTestEndpoint(num: 0))")!
    output.writeLine("ok")

    output.write("testing checked cast... ")
    var obj = try checkedCast(prx: base, type: TestIntfPrx.self)!
    try test(obj == base)
    output.writeLine("ok")

    output.write("testing ice_ids... ")
    do {
        let o = try communicator.stringToProxy("category/locate:\(helper.getTestEndpoint(num: 0))")!
        _ = try o.ice_ids()
        try test(false)
    } catch let ex as Ice.UnknownUserException {
        try test(ex.unknown == "::Test::TestIntfUserException")
    }

    do {
        let o = try communicator.stringToProxy("category/finished:\(helper.getTestEndpoint(num: 0))")!
        _ = try o.ice_ids()
        try test(false)
    } catch let ex as Ice.UnknownUserException {
        try test(ex.unknown == "::Test::TestIntfUserException")
    }
    output.writeLine("ok")

    output.write("testing servant locator...")
    base = try communicator.stringToProxy("category/locate:\(helper.getTestEndpoint(num: 0))")!
    obj = try checkedCast(prx: base, type: TestIntfPrx.self)!
    do {
        _ = try checkedCast(prx: communicator.stringToProxy("category/unknown:\(helper.getTestEndpoint(num: 0))")!,
                            type: TestIntfPrx.self)
    } catch is Ice.ObjectNotExistException {}
    output.writeLine("ok")

    output.write("testing default servant locator...")
    base = try communicator.stringToProxy("anothercat/locate:\(helper.getTestEndpoint(num: 0))")!
    obj = try checkedCast(prx: base, type: TestIntfPrx.self)!
    base = try communicator.stringToProxy("locate:\(helper.getTestEndpoint(num: 0))")!
    obj = try checkedCast(prx: base, type: TestIntfPrx.self)!

    do {
        _ = try checkedCast(prx: communicator.stringToProxy("anothercat/unknown:\(helper.getTestEndpoint(num: 0))")!,
                            type: TestIntfPrx.self)
    } catch is Ice.ObjectNotExistException {}

    do {
        _ = try checkedCast(prx: communicator.stringToProxy("unknown:\(helper.getTestEndpoint(num: 0))")!,
                            type: TestIntfPrx.self)
    } catch is Ice.ObjectNotExistException {}
    output.writeLine("ok")

    output.write("testing locate exceptions... ")
    base = try communicator.stringToProxy("category/locate:\(helper.getTestEndpoint(num: 0))")!
    obj = try checkedCast(prx: base, type: TestIntfPrx.self)!
    try testExceptions(obj, helper)
    output.writeLine("ok")

    output.write("testing finished exceptions... ")
    base = try communicator.stringToProxy("category/finished:\(helper.getTestEndpoint(num: 0))")!
    obj = try checkedCast(prx: base, type: TestIntfPrx.self)!
    try testExceptions(obj, helper)

    //
    // Only call these for category/finished.
    //
    do {
        try obj.asyncResponse()
    } catch is TestIntfUserException {
        try test(false)
    } catch is TestImpossibleException {
        //
        // Called by finished().
        //
    }

    //
    // Only call these for category/finished.
    //
    do {
        try obj.asyncException()
    } catch is TestIntfUserException {
        try test(false)
    } catch is TestImpossibleException {
        //
        // Called by finished().
        //
    }
    output.writeLine("ok")

    output.write("testing servant locator removal... ")
    base = try communicator.stringToProxy("test/activation:\(helper.getTestEndpoint(num: 0))")!
    let activation = try checkedCast(prx: base, type: TestActivationPrx.self)!
    try activation.activateServantLocator(false)
    do {
        try obj.ice_ping()
        try test(false)
    } catch is Ice.ObjectNotExistException {
        output.writeLine("ok")
    }

    output.write("testing servant locator addition... ")
    try activation.activateServantLocator(true)
    do {
        try obj.ice_ping()
        output.writeLine("ok")
    } catch {
        try test(false)
    }
    return obj
}