From 5d5b650faf5835ae40bd1b255264be0225c6b867 Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Fri, 7 Jun 2024 09:39:11 -0400 Subject: [PATCH] New makeProxy factory function in Swift (#2275) --- cpp/src/slice2swift/Gen.cpp | 18 ++++++ cpp/test/Ice/binding/AllTests.cpp | 6 +- csharp/test/Ice/binding/AllTests.cs | 6 +- .../main/java/test/Ice/binding/AllTests.java | 6 +- js/test/Ice/binding/Client.js | 4 +- js/test/typescript/Ice/binding/Client.ts | 4 +- matlab/test/Ice/binding/AllTests.m | 6 +- php/test/Ice/binding/Client.php | 4 +- python/test/Ice/binding/AllTests.py | 4 +- ruby/test/Ice/binding/AllTests.rb | 2 +- swift/src/Ice/Communicator.swift | 6 ++ swift/src/Ice/CommunicatorI.swift | 23 ++++++-- swift/src/Ice/Proxy.swift | 18 +++++- swift/test/Ice/ami/AllTests.swift | 21 ++++--- swift/test/Ice/binding/AllTests.swift | 58 ++++++++----------- swift/test/Ice/location/AllTests.swift | 40 ++++++------- 16 files changed, 127 insertions(+), 99 deletions(-) diff --git a/cpp/src/slice2swift/Gen.cpp b/cpp/src/slice2swift/Gen.cpp index 017db70eae1..6e7e1275523 100644 --- a/cpp/src/slice2swift/Gen.cpp +++ b/cpp/src/slice2swift/Gen.cpp @@ -1140,6 +1140,24 @@ Gen::ProxyVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) out << eb; + // + // makeProxy + // + out << sp; + out << nl << "/// Makes a new proxy from a communicator and a proxy string."; + out << nl << "///"; + out << nl << "/// - Parameters:"; + out << nl << "/// - communicator: The communicator of the new proxy."; + out << nl << "/// - proxyString: The proxy string to parse."; + out << nl << "/// - type: The type of the new proxy."; + out << nl << "/// - Throws: `Ice.ProxyParseException` if the proxy string is invalid."; + out << nl << "/// - Returns: A new proxy with the requested type."; + out << nl << "public func makeProxy(communicator: Ice.Communicator, proxyString: String, type: " << prx + << ".Protocol) throws -> " << prx; + out << sb; + out << nl << "try communicator.makeProxyImpl(proxyString) as " << prxI; + out << eb; + // // checkedCast // diff --git a/cpp/test/Ice/binding/AllTests.cpp b/cpp/test/Ice/binding/AllTests.cpp index d09f2d41d6a..eb14535310d 100644 --- a/cpp/test/Ice/binding/AllTests.cpp +++ b/cpp/test/Ice/binding/AllTests.cpp @@ -397,7 +397,7 @@ allTests(Test::TestHelper* helper) int i; // - // Ensure that endpoints are tried in order by deactiving the adapters + // Ensure that endpoints are tried in order by deactivating the adapters // one after the other. // for (i = 0; i < nRetry && test->getAdapterName() == "Adapter31"; i++) @@ -616,7 +616,7 @@ allTests(Test::TestHelper* helper) int i; // - // Ensure that endpoints are tried in order by deactiving the adapters + // Ensure that endpoints are tried in order by deactivating the adapters // one after the other. // for (i = 0; i < nRetry && test->getAdapterName() == "Adapter61"; i++) @@ -707,7 +707,7 @@ allTests(Test::TestHelper* helper) int i; // - // Ensure that endpoints are tried in order by deactiving the adapters + // Ensure that endpoints are tried in order by deactivating the adapters // one after the other. // for (i = 0; i < nRetry && getAdapterNameWithAMI(test) == "AdapterAMI61"; i++) diff --git a/csharp/test/Ice/binding/AllTests.cs b/csharp/test/Ice/binding/AllTests.cs index 622563aa1ce..77b45fd828a 100644 --- a/csharp/test/Ice/binding/AllTests.cs +++ b/csharp/test/Ice/binding/AllTests.cs @@ -415,7 +415,7 @@ public static async Task allTests(global::Test.TestHelper helper) int i; // - // Ensure that endpoints are tried in order by deactiving the adapters + // Ensure that endpoints are tried in order by deactivating the adapters // one after the other. // for (i = 0; i < nRetry && obj.getAdapterName() == "Adapter31"; i++) ; @@ -585,7 +585,7 @@ public static async Task allTests(global::Test.TestHelper helper) int i; // - // Ensure that endpoints are tried in order by deactiving the adapters + // Ensure that endpoints are tried in order by deactivating the adapters // one after the other. // for (i = 0; i < nRetry && obj.getAdapterName() == "Adapter61"; i++) ; @@ -648,7 +648,7 @@ public static async Task allTests(global::Test.TestHelper helper) int i; // - // Ensure that endpoints are tried in order by deactiving the adapters + // Ensure that endpoints are tried in order by deactivating the adapters // one after the other. // for (i = 0; i < nRetry && (await obj.getAdapterNameAsync()) == "AdapterAMI61"; i++) ; diff --git a/java/test/src/main/java/test/Ice/binding/AllTests.java b/java/test/src/main/java/test/Ice/binding/AllTests.java index 9356e9a45e0..05581e1ecb2 100644 --- a/java/test/src/main/java/test/Ice/binding/AllTests.java +++ b/java/test/src/main/java/test/Ice/binding/AllTests.java @@ -390,7 +390,7 @@ public static void allTests(test.TestHelper helper) { int i; // - // Ensure that endpoints are tried in order by deactiving the adapters + // Ensure that endpoints are tried in order by deactivating the adapters // one after the other. // for (i = 0; i < nRetry && test.getAdapterName().equals("Adapter31"); i++) @@ -566,7 +566,7 @@ public static void allTests(test.TestHelper helper) { int i; // - // Ensure that endpoints are tried in order by deactiving the adapters + // Ensure that endpoints are tried in order by deactivating the adapters // one after the other. // for (i = 0; i < nRetry && test.getAdapterName().equals("Adapter61"); i++) @@ -637,7 +637,7 @@ public static void allTests(test.TestHelper helper) { int i; // - // Ensure that endpoints are tried in order by deactiving the adapters + // Ensure that endpoints are tried in order by deactivating the adapters // one after the other. // for (i = 0; i < nRetry && getAdapterNameWithAMI(test).equals("AdapterAMI61"); i++) diff --git a/js/test/Ice/binding/Client.js b/js/test/Ice/binding/Client.js index 7a794005031..dc35837d608 100644 --- a/js/test/Ice/binding/Client.js +++ b/js/test/Ice/binding/Client.js @@ -356,7 +356,7 @@ const nRetry = 3; // - // Ensure that endpoints are tried in order by deactiving the adapters + // Ensure that endpoints are tried in order by deactivating the adapters // one after the other. // /* eslint-disable curly */ @@ -523,7 +523,7 @@ let i; // - // Ensure that endpoints are tried in order by deactiving the adapters + // Ensure that endpoints are tried in order by deactivating the adapters // one after the other. // diff --git a/js/test/typescript/Ice/binding/Client.ts b/js/test/typescript/Ice/binding/Client.ts index 2284531f519..65fe6d576d7 100644 --- a/js/test/typescript/Ice/binding/Client.ts +++ b/js/test/typescript/Ice/binding/Client.ts @@ -338,7 +338,7 @@ export class Client extends TestHelper const nRetry = 3; // - // Ensure that endpoints are tried in order by deactiving the adapters + // Ensure that endpoints are tried in order by deactivating the adapters // one after the other. // /* eslint-disable curly */ @@ -505,7 +505,7 @@ export class Client extends TestHelper let i; // - // Ensure that endpoints are tried in order by deactiving the adapters + // Ensure that endpoints are tried in order by deactivating the adapters // one after the other. // diff --git a/matlab/test/Ice/binding/AllTests.m b/matlab/test/Ice/binding/AllTests.m index 4e312befd00..eb77b9ceba0 100644 --- a/matlab/test/Ice/binding/AllTests.m +++ b/matlab/test/Ice/binding/AllTests.m @@ -384,7 +384,7 @@ function allTests(helper) assert(test.ice_getEndpointSelection() == Ice.EndpointSelectionType.Ordered); % - % Ensure that endpoints are tried in order by deactiving the adapters + % Ensure that endpoints are tried in order by deactivating the adapters % one after the other. % nRetry = 5; @@ -581,7 +581,7 @@ function allTests(helper) assert(~test.ice_isConnectionCached()); % - % Ensure that endpoints are tried in order by deactiving the adapters + % Ensure that endpoints are tried in order by deactivating the adapters % one after the other. % nRetry = 5; @@ -666,7 +666,7 @@ function allTests(helper) assert(~test.ice_isConnectionCached()); % - % Ensure that endpoints are tried in order by deactiving the adapters + % Ensure that endpoints are tried in order by deactivating the adapters % one after the other. % nRetry = 5; diff --git a/php/test/Ice/binding/Client.php b/php/test/Ice/binding/Client.php index 0f68922ccf2..03f25569c85 100644 --- a/php/test/Ice/binding/Client.php +++ b/php/test/Ice/binding/Client.php @@ -221,7 +221,7 @@ function allTests($helper) $nRetry = 5; // - // Ensure that endpoints are tried in order by deactiving the adapters + // Ensure that endpoints are tried in order by deactivating the adapters // one after the other. // for($i = 0; $i < $nRetry && $test->getAdapterName() == "Adapter31"; $i++); @@ -358,7 +358,7 @@ function allTests($helper) $nRetry = 5; // - // Ensure that endpoints are tried in order by deactiving the adapters + // Ensure that endpoints are tried in order by deactivating the adapters // one after the other. // for($i = 0; $i < $nRetry && $test->getAdapterName() == "Adapter61"; $i++); diff --git a/python/test/Ice/binding/AllTests.py b/python/test/Ice/binding/AllTests.py index c3acb6a5246..ffb92aa2a2c 100644 --- a/python/test/Ice/binding/AllTests.py +++ b/python/test/Ice/binding/AllTests.py @@ -487,7 +487,7 @@ def allTests(helper, communicator): nRetry = 5 # - # Ensure that endpoints are tried in order by deactiving the adapters + # Ensure that endpoints are tried in order by deactivating the adapters # one after the other. # i = 0 @@ -561,7 +561,7 @@ def allTests(helper, communicator): nRetry = 5 # - # Ensure that endpoints are tried in order by deactiving the adapters + # Ensure that endpoints are tried in order by deactivating the adapters # one after the other. # i = 0 diff --git a/ruby/test/Ice/binding/AllTests.rb b/ruby/test/Ice/binding/AllTests.rb index 99eebe7993f..75fbee6b297 100644 --- a/ruby/test/Ice/binding/AllTests.rb +++ b/ruby/test/Ice/binding/AllTests.rb @@ -345,7 +345,7 @@ def allTests(helper, communicator) nRetry = 5 # - # Ensure that endpoints are tried in order by deactiving the adapters + # Ensure that endpoints are tried in order by deactivating the adapters # one after the other. # i = 0 diff --git a/swift/src/Ice/Communicator.swift b/swift/src/Ice/Communicator.swift index da64bbaefb0..c6044d7dc85 100644 --- a/swift/src/Ice/Communicator.swift +++ b/swift/src/Ice/Communicator.swift @@ -255,4 +255,10 @@ public protocol Communicator: AnyObject { /// /// - returns: `Dispatch.DispatchQueue` - The dispatch queue associated wih the Communicator's server thread pool. func getServerDispatchQueue() throws -> Dispatch.DispatchQueue + + /// Makes a new proxy. This is an internal operation used by the generated code. + /// + /// - Parameter proxyString: The stringified proxy. + /// - Returns: The new proxy. + func makeProxyImpl(_ proxyString: String) throws -> ProxyImpl where ProxyImpl: ObjectPrxI } diff --git a/swift/src/Ice/CommunicatorI.swift b/swift/src/Ice/CommunicatorI.swift index 42bb6e63c73..79f17de09ad 100644 --- a/swift/src/Ice/CommunicatorI.swift +++ b/swift/src/Ice/CommunicatorI.swift @@ -46,12 +46,7 @@ class CommunicatorI: LocalObject, Communicator { } func stringToProxy(_ str: String) throws -> ObjectPrx? { - return try autoreleasepool { - guard let prxHandle = try handle.stringToProxy(str: str) as? ICEObjectPrx else { - return nil - } - return ObjectPrxI(handle: prxHandle, communicator: self) - } + try stringToProxyImpl(str) } func proxyToString(_ obj: ObjectPrx?) -> String { @@ -256,6 +251,22 @@ class CommunicatorI: LocalObject, Communicator { try handle.getServerDispatchQueue() } } + + func makeProxyImpl(_ proxyString: String) throws -> ProxyImpl where ProxyImpl: ObjectPrxI { + guard let proxy: ProxyImpl = try stringToProxyImpl(proxyString) else { + throw ProxyParseException(str: "Invalid empty proxy string") + } + return proxy + } + + private func stringToProxyImpl(_ str: String) throws -> ProxyImpl? where ProxyImpl: ObjectPrxI { + return try autoreleasepool { + guard let prxHandle = try handle.stringToProxy(str: str) as? ICEObjectPrx else { + return nil + } + return ProxyImpl(handle: prxHandle, communicator: self) + } + } } extension Communicator { diff --git a/swift/src/Ice/Proxy.swift b/swift/src/Ice/Proxy.swift index 34b599173e1..96aee7878a9 100644 --- a/swift/src/Ice/Proxy.swift +++ b/swift/src/Ice/Proxy.swift @@ -302,6 +302,19 @@ public protocol ObjectPrx: CustomStringConvertible, AnyObject { func ice_collocationOptimized(_ collocated: Bool) -> Self } +/// Makes a new proxy from a communicator and a proxy string. +/// +/// - Parameters: +/// - communicator: The communicator of the new proxy. +/// - proxyString: The proxy string to parse. +/// - type: The type of the new proxy. +/// - Throws: `Ice.ProxyParseException` if the proxy string is invalid. +/// - Returns: A new proxy with the requested type. +public func makeProxy(communicator: Ice.Communicator, proxyString: String, type: ObjectPrx.Protocol) throws -> ObjectPrx +{ + try communicator.makeProxyImpl(proxyString) as ObjectPrxI +} + /// Casts a proxy to `Ice.ObjectPrx`. This call contacts the server and will throw an Ice run-time exception /// if the target object does not exist or the server cannot be reached. /// @@ -784,9 +797,8 @@ open class ObjectPrxI: ObjectPrx { isTwoway = impl.isTwoway } - func fromICEObjectPrx(_ h: ICEObjectPrx) -> ObjectPrxType - where ObjectPrxType: ObjectPrxI { - return ObjectPrxType(handle: h, communicator: communicator) + private func fromICEObjectPrx(_ h: ICEObjectPrx) -> ProxyImpl where ProxyImpl: ObjectPrxI { + return ProxyImpl(handle: h, communicator: communicator) } static func fromICEObjectPrx( diff --git a/swift/test/Ice/ami/AllTests.swift b/swift/test/Ice/ami/AllTests.swift index 8c6a79a0b54..008ff8e40ba 100644 --- a/swift/test/Ice/ami/AllTests.swift +++ b/swift/test/Ice/ami/AllTests.swift @@ -12,14 +12,13 @@ func allTests(_ helper: TestHelper, collocated: Bool = false) throws { let communicator = helper.communicator() let output = helper.getWriter() - var sref = "test:\(helper.getTestEndpoint(num: 0))" - var obj = try communicator.stringToProxy(sref)! + var p = try makeProxy( + communicator: communicator, proxyString: "test:\(helper.getTestEndpoint(num: 0))", type: TestIntfPrx.self) - var p = uncheckedCast(prx: obj, type: TestIntfPrx.self) - sref = "testController:\(helper.getTestEndpoint(num: 1))" - obj = try communicator.stringToProxy(sref)! - - let testController = uncheckedCast(prx: obj, type: TestIntfControllerPrx.self) + let testController = try makeProxy( + communicator: communicator, + proxyString: "testController:\(helper.getTestEndpoint(num: 1))", + type: TestIntfControllerPrx.self) output.write("testing async invocation...") do { @@ -61,7 +60,7 @@ func allTests(_ helper: TestHelper, collocated: Bool = false) throws { output.write("testing local exceptions... ") do { - let indirect = uncheckedCast(prx: p.ice_adapterId("dummy"), type: TestIntfPrx.self) + let indirect = p.ice_adapterId("dummy") try indirect.opAsync().wait() } catch is Ice.NoEndpointException {} @@ -77,8 +76,8 @@ func allTests(_ helper: TestHelper, collocated: Bool = false) throws { var initData = Ice.InitializationData() initData.properties = communicator.getProperties().clone() let ic = try helper.initialize(initData) - let o = try ic.stringToProxy(p.ice_toString())! - let p2 = try checkedCast(prx: o, type: TestIntfPrx.self)! + let p2 = try makeProxy(communicator: ic, proxyString: p.ice_toString(), type: TestIntfPrx.self) + try p2.ice_pingAsync().wait() ic.destroy() do { try p2.opAsync().wait() @@ -89,7 +88,7 @@ func allTests(_ helper: TestHelper, collocated: Bool = false) throws { output.write("testing exception callback... ") do { - let i = uncheckedCast(prx: p.ice_adapterId("dummy"), type: TestIntfPrx.self) + let i = p.ice_adapterId("dummy") do { _ = try i.ice_isAAsync(id: "::Test::TestIntf").wait() diff --git a/swift/test/Ice/binding/AllTests.swift b/swift/test/Ice/binding/AllTests.swift index 5391ea46d5d..ac9e369f922 100644 --- a/swift/test/Ice/binding/AllTests.swift +++ b/swift/test/Ice/binding/AllTests.swift @@ -29,8 +29,9 @@ func allTests(_ helper: TestHelper) throws { let communicator = helper.communicator() let output = helper.getWriter() - let com = try uncheckedCast( - prx: communicator.stringToProxy("communicator:\(helper.getTestEndpoint(num: 0))")!, + let com = try makeProxy( + communicator: communicator, + proxyString: "communicator:\(helper.getTestEndpoint(num: 0))", type: RemoteCommunicatorPrx.self) output.write("testing binding with single endpoint... ") @@ -48,12 +49,10 @@ func allTests(_ helper: TestHelper) throws { try com.deactivateObjectAdapter(adapter) - let test3 = uncheckedCast(prx: test1, type: TestIntfPrx.self) - try test(test3.ice_getConnection() === test1.ice_getConnection()) - try test(test3.ice_getConnection() === test2.ice_getConnection()) + try test(test1.ice_getConnection() === test2.ice_getConnection()) do { - try test3.ice_ping() + try test1.ice_ping() try test(false) } catch is Ice.ConnectFailedException { // expected @@ -318,7 +317,7 @@ func allTests(_ helper: TestHelper) throws { try obj.ice_getConnection()!.close(.GracefullyWithWait) } - obj = uncheckedCast(prx: obj.ice_endpointSelection(.Random), type: TestIntfPrx.self) + obj = obj.ice_endpointSelection(.Random) try test(obj.ice_getEndpointSelection() == .Random) names.append("Adapter21") @@ -344,12 +343,12 @@ func allTests(_ helper: TestHelper) throws { ] var obj = try createTestIntfPrx(adapters) - obj = uncheckedCast(prx: obj.ice_endpointSelection(.Ordered), type: TestIntfPrx.self) + obj = obj.ice_endpointSelection(.Ordered) try test(obj.ice_getEndpointSelection() == .Ordered) let nRetry = 3 // - // Ensure that endpoints are tried in order by deactiving the adapters + // Ensure that endpoints are tried in order by deactivating the adapters // one after the other. // var i = 0 @@ -423,12 +422,8 @@ func allTests(_ helper: TestHelper) throws { do { let adapter = try com.createObjectAdapter(name: "Adapter41", endpoints: "default")! - let test1 = try uncheckedCast( - prx: adapter.getTestIntf()!.ice_connectionCached(false), - type: TestIntfPrx.self) - let test2 = try uncheckedCast( - prx: adapter.getTestIntf()!.ice_connectionCached(false), - type: TestIntfPrx.self) + let test1 = try adapter.getTestIntf()!.ice_connectionCached(false) + let test2 = try adapter.getTestIntf()!.ice_connectionCached(false) try test(!test1.ice_isConnectionCached()) try test(!test2.ice_isConnectionCached()) try test(test1.ice_getConnection() != nil && test2.ice_getConnection() != nil) @@ -438,9 +433,8 @@ func allTests(_ helper: TestHelper) throws { try com.deactivateObjectAdapter(adapter) - let test3 = uncheckedCast(prx: test1, type: TestIntfPrx.self) do { - try test(test3.ice_getConnection() === test1.ice_getConnection()) + _ = try test1.ice_getConnection() try test(false) } catch is Ice.ConnectFailedException { // expected @@ -458,9 +452,7 @@ func allTests(_ helper: TestHelper) throws { com.createObjectAdapter(name: "Adapter53", endpoints: "default")!, ] - let obj = try uncheckedCast( - prx: createTestIntfPrx(adapters).ice_connectionCached(false), - type: TestIntfPrx.self) + let obj = try createTestIntfPrx(adapters).ice_connectionCached(false) try test(!obj.ice_isConnectionCached()) var names = ["Adapter51", "Adapter52", "Adapter53"] @@ -494,9 +486,7 @@ func allTests(_ helper: TestHelper) throws { com.createObjectAdapter(name: "AdapterAMI53", endpoints: "default")!, ] - let obj = try uncheckedCast( - prx: createTestIntfPrx(adapters).ice_connectionCached(false), - type: TestIntfPrx.self) + let obj = try createTestIntfPrx(adapters).ice_connectionCached(false) try test(!obj.ice_isConnectionCached()) var names = ["AdapterAMI51", "AdapterAMI52", "AdapterAMI53"] @@ -531,16 +521,14 @@ func allTests(_ helper: TestHelper) throws { ] var obj = try createTestIntfPrx(adapters) - obj = uncheckedCast( - prx: obj.ice_endpointSelection(.Ordered), - type: TestIntfPrx.self) + obj = obj.ice_endpointSelection(.Ordered) try test(obj.ice_getEndpointSelection() == .Ordered) - obj = uncheckedCast(prx: obj.ice_connectionCached(false), type: TestIntfPrx.self) + obj = obj.ice_connectionCached(false) try test(!obj.ice_isConnectionCached()) let nRetry = 3 var i = 0 // - // Ensure that endpoints are tried in order by deactiving the adapters + // Ensure that endpoints are tried in order by deactivating the adapters // one after the other. // while try i < nRetry && obj.getAdapterName() == "Adapter61" { @@ -616,16 +604,16 @@ func allTests(_ helper: TestHelper) throws { ] var obj = try createTestIntfPrx(adapters) - obj = uncheckedCast(prx: obj.ice_endpointSelection(.Ordered), type: TestIntfPrx.self) + obj = obj.ice_endpointSelection(.Ordered) try test(obj.ice_getEndpointSelection() == .Ordered) - obj = uncheckedCast(prx: obj.ice_connectionCached(false), type: TestIntfPrx.self) + obj = obj.ice_connectionCached(false) try test(!obj.ice_isConnectionCached()) let nRetry = 3 var i = 0 // - // Ensure that endpoints are tried in order by deactiving the adapters + // Ensure that endpoints are tried in order by deactivating the adapters // one after the other. // while try i < nRetry && obj.getAdapterNameAsync().wait() == "AdapterAMI61" { @@ -701,7 +689,7 @@ func allTests(_ helper: TestHelper) throws { let obj = try createTestIntfPrx(adapters) try test(obj.getAdapterName() == "Adapter71") - let testUDP = uncheckedCast(prx: obj.ice_datagram(), type: TestIntfPrx.self) + let testUDP = obj.ice_datagram() try test(obj.ice_getConnection() !== testUDP.ice_getConnection()) do { _ = try testUDP.getAdapterName() @@ -723,11 +711,11 @@ func allTests(_ helper: TestHelper) throws { try obj.ice_getConnection()!.close(.GracefullyWithWait) } - var testSecure = uncheckedCast(prx: obj.ice_secure(true), type: TestIntfPrx.self) + var testSecure = obj.ice_secure(true) try test(testSecure.ice_isSecure()) - testSecure = uncheckedCast(prx: obj.ice_secure(false), type: TestIntfPrx.self) + testSecure = obj.ice_secure(false) try test(!testSecure.ice_isSecure()) - testSecure = uncheckedCast(prx: obj.ice_secure(true), type: TestIntfPrx.self) + testSecure = obj.ice_secure(true) try test(testSecure.ice_isSecure()) try test(obj.ice_getConnection() !== testSecure.ice_getConnection()) diff --git a/swift/test/Ice/location/AllTests.swift b/swift/test/Ice/location/AllTests.swift index 6b25cbfe942..af8f23d476f 100644 --- a/swift/test/Ice/location/AllTests.swift +++ b/swift/test/Ice/location/AllTests.swift @@ -13,14 +13,14 @@ func allTests(_ helper: TestHelper) throws { let communicator = helper.communicator() - let manager = try checkedCast( - prx: communicator.stringToProxy("ServerManager:\(helper.getTestEndpoint(num: 0))")!, + let manager = try makeProxy( + communicator: communicator, + proxyString: "ServerManager:\(helper.getTestEndpoint(num: 0))", type: ServerManagerPrx.self - )! + ) let locator = uncheckedCast(prx: communicator.getDefaultLocator()!, type: TestLocatorPrx.self) - - let registry = try checkedCast(prx: locator.getRegistry()!, type: TestLocatorRegistryPrx.self)! + let registry = try uncheckedCast(prx: locator.getRegistry()!, type: TestLocatorRegistryPrx.self) output.write("testing stringToProxy... ") var base = try communicator.stringToProxy("test @ TestAdapter")! @@ -34,9 +34,8 @@ func allTests(_ helper: TestHelper) throws { output.write("testing ice_locator and ice_getLocator... ") try test( base.ice_getLocator()!.ice_getIdentity() == communicator.getDefaultLocator()!.ice_getIdentity()) - let anotherLocator = try uncheckedCast( - prx: communicator.stringToProxy("anotherLocator")!, - type: Ice.LocatorPrx.self) + let anotherLocator = try makeProxy( + communicator: communicator, proxyString: "anotherLocator", type: Ice.LocatorPrx.self) base = base.ice_locator(anotherLocator) try test(base.ice_getLocator()!.ice_getIdentity() == anotherLocator.ice_getIdentity()) communicator.setDefaultLocator(nil) @@ -55,12 +54,11 @@ func allTests(_ helper: TestHelper) throws { // test/Ice/router test?) // try test(base.ice_getRouter() == nil) - let anotherRouter = try uncheckedCast( - prx: communicator.stringToProxy("anotherRouter")!, type: Ice.RouterPrx.self) + let anotherRouter = try makeProxy( + communicator: communicator, proxyString: "anotherrouter", type: Ice.RouterPrx.self) base = base.ice_router(anotherRouter) try test(base.ice_getRouter()!.ice_getIdentity() == anotherRouter.ice_getIdentity()) - let router = try uncheckedCast( - prx: communicator.stringToProxy("dummyrouter")!, type: Ice.RouterPrx.self) + let router = try makeProxy(communicator: communicator, proxyString: "dummyrouter", type: Ice.RouterPrx.self) communicator.setDefaultRouter(router) base = try communicator.stringToProxy("test @ TestAdapter")! try test( @@ -227,8 +225,7 @@ func allTests(_ helper: TestHelper) throws { output.writeLine("ok") output.write("testing proxy from server... ") - obj = try checkedCast( - prx: communicator.stringToProxy("test@TestAdapter")!, type: TestIntfPrx.self)! + obj = try makeProxy(communicator: communicator, proxyString: "test@TestAdapter", type: TestIntfPrx.self) var hello = try obj.getHello()! try test(hello.ice_getAdapterId() == "TestAdapter") try hello.sayHello() @@ -449,7 +446,7 @@ func allTests(_ helper: TestHelper) throws { output.writeLine("ok") output.write("testing object migration... ") - hello = try checkedCast(prx: communicator.stringToProxy("hello")!, type: HelloPrx.self)! + hello = try makeProxy(communicator: communicator, proxyString: "hello", type: HelloPrx.self) try obj.migrateHello() try hello.ice_getConnection()!.close(.GracefullyWithWait) try hello.sayHello() @@ -460,7 +457,7 @@ func allTests(_ helper: TestHelper) throws { output.writeLine("ok") output.write("testing locator encoding resolution... ") - hello = try checkedCast(prx: communicator.stringToProxy("hello")!, type: HelloPrx.self)! + hello = try makeProxy(communicator: communicator, proxyString: "hello", type: HelloPrx.self) count = try locator.getRequestCount() try communicator.stringToProxy("test@TestAdapter")!.ice_encodingVersion(Ice.Encoding_1_1) .ice_ping() @@ -499,7 +496,7 @@ func allTests(_ helper: TestHelper) throws { // // Set up test for calling a collocated object through an - // indirect, adapterless reference. + // indirect, adapter-less reference. // communicator.getProperties().setProperty(key: "Hello.AdapterId", value: UUID().uuidString) let adapter = try communicator.createObjectAdapterWithEndpoints( @@ -510,13 +507,10 @@ func allTests(_ helper: TestHelper) throws { try adapter.add(servant: HelloDisp(HelloI()), id: ident) do { - // let helloPrx - _ = try checkedCast( - prx: communicator.stringToProxy("\"\(communicator.identityToString(ident))\"")!, - type: HelloPrx.self - )! + let helloPrx = try makeProxy( + communicator: communicator, proxyString: "\(communicator.identityToString(ident))", type: HelloPrx.self) + try helloPrx.ice_ping() try test(false) - // try test(helloPrx.ice_getConnection() == nil) } catch is Ice.NotRegisteredException { // Calls on the well-known proxy are not collocated because of issue #507 }