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
|
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//
import Ice
import TestCommon
final class MyObjectI: ObjectI<MyObjectTraits>, MyObject {
override func ice_ping(current: Ice.Current) throws {
if current.id.name == "ObjectNotExist" {
throw Ice.ObjectNotExistException(id: current.id, facet: "", operation: "ice_ping")
} else if current.id.name == "FacetNotExist" {
throw Ice.FacetNotExistException(id: current.id, facet: "", operation: "ice_ping")
}
}
func getName(current: Ice.Current) throws -> String {
if current.id.name == "ObjectNotExist" {
throw Ice.ObjectNotExistException(id: current.id, facet: "", operation: "ice_ping")
} else if current.id.name == "FacetNotExist" {
throw Ice.FacetNotExistException(id: current.id, facet: "", operation: "ice_ping")
}
return current.id.name
}
}
func allTests(_ helper: TestHelper) throws {
func test(_ value: Bool, file: String = #file, line: Int = #line) throws {
try helper.test(value, file: file, line: line)
}
let communicator = helper.communicator()
let output = helper.getWriter()
let oa = try communicator.createObjectAdapterWithEndpoints(name: "MyOA", endpoints: "tcp -h localhost")
try oa.activate()
let servant = MyObjectI()
//
// Register default servant with category "foo"
//
try oa.addDefaultServant(servant: MyObjectDisp(servant), category: "foo")
//
// Start test
//
output.write("testing single category... ")
var r = oa.findDefaultServant("foo")
try test((r as! MyObjectDisp).servant as? MyObjectI === servant)
r = oa.findDefaultServant("bar")
try test(r == nil)
var identity = Ice.Identity()
identity.category = "foo"
let names = ["foo", "bar", "x", "y", "abcdefg"]
var prx: MyObjectPrx!
for name in names {
identity.name = name
prx = try uncheckedCast(prx: oa.createProxy(identity), type: MyObjectPrx.self)
try prx.ice_ping()
try test(prx.getName() == name)
}
identity.name = "ObjectNotExist"
prx = try uncheckedCast(prx: oa.createProxy(identity), type: MyObjectPrx.self)
do {
try prx.ice_ping()
try test(false)
} catch is Ice.ObjectNotExistException {} // Expected
do {
_ = try prx.getName()
try test(false)
} catch is Ice.ObjectNotExistException {} // Expected
identity.name = "FacetNotExist"
prx = try uncheckedCast(prx: oa.createProxy(identity), type: MyObjectPrx.self)
do {
try prx.ice_ping()
try test(false)
} catch is Ice.FacetNotExistException {} // Expected
do {
_ = try prx.getName()
try test(false)
} catch is Ice.FacetNotExistException {} // Expected
identity.category = "bar"
for name in names {
identity.name = name
prx = try uncheckedCast(prx: oa.createProxy(identity), type: MyObjectPrx.self)
do {
try prx.ice_ping()
try test(false)
} catch is Ice.ObjectNotExistException {} // Expected
do {
_ = try prx.getName()
try test(false)
} catch is Ice.ObjectNotExistException {} // Expected
}
_ = try oa.removeDefaultServant("foo")
identity.category = "foo"
prx = try uncheckedCast(prx: oa.createProxy(identity), type: MyObjectPrx.self)
do {
try prx.ice_ping()
try test(false)
} catch is Ice.ObjectNotExistException {} // Expected
output.writeLine("ok")
output.write("testing default category... ")
try oa.addDefaultServant(servant: MyObjectDisp(servant), category: "")
r = oa.findDefaultServant("bar")
try test(r == nil)
r = oa.findDefaultServant("")
try test((r as! MyObjectDisp).servant as? MyObjectI === servant)
for name in names {
identity.name = name
prx = try uncheckedCast(prx: oa.createProxy(identity), type: MyObjectPrx.self)
try prx.ice_ping()
try test(prx.getName() == name)
}
output.writeLine("ok")
}
|