diff options
author | Jose <jose@zeroc.com> | 2019-02-23 00:18:48 +0100 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2019-02-23 00:18:48 +0100 |
commit | 0f7087cb15f4d2f878a6eb39893b5ba08452c0e8 (patch) | |
tree | 31ed89ed6a908c5d74639c45aa3934b95b07ed00 | |
parent | Test fixes (diff) | |
download | ice-0f7087cb15f4d2f878a6eb39893b5ba08452c0e8.tar.bz2 ice-0f7087cb15f4d2f878a6eb39893b5ba08452c0e8.tar.xz ice-0f7087cb15f4d2f878a6eb39893b5ba08452c0e8.zip |
Test fixes
-rw-r--r-- | swift/src/Ice/CommunicatorI.swift | 4 | ||||
-rw-r--r-- | swift/src/Ice/Globals.swift | 4 | ||||
-rw-r--r-- | swift/src/Ice/InitializationData.swift | 6 | ||||
-rw-r--r-- | swift/src/Ice/OutputStream.swift | 2 | ||||
-rw-r--r-- | swift/test/Ice/stream/Client.swift | 67 | ||||
-rw-r--r-- | swift/test/TestCommon/TestCommon.swift | 129 | ||||
-rw-r--r-- | swift/test/TestDriver.xcodeproj/project.pbxproj | 4 | ||||
-rw-r--r-- | swift/test/TestDriver/main.swift | 4 |
8 files changed, 112 insertions, 108 deletions
diff --git a/swift/src/Ice/CommunicatorI.swift b/swift/src/Ice/CommunicatorI.swift index 9c2f2f46b9b..f4dff7c7666 100644 --- a/swift/src/Ice/CommunicatorI.swift +++ b/swift/src/Ice/CommunicatorI.swift @@ -36,10 +36,6 @@ class CommunicatorI: LocalObject<ICECommunicator>, Communicator { super.init(handle: handle) } - deinit { - print("destryoing communicator") - } - func destroy() { _handle.destroy() } diff --git a/swift/src/Ice/Globals.swift b/swift/src/Ice/Globals.swift index da213916735..a609c55adfd 100644 --- a/swift/src/Ice/Globals.swift +++ b/swift/src/Ice/Globals.swift @@ -64,14 +64,14 @@ public func initialize(args: StringSeq = [], } } -public func createProperties(args: StringSeq? = nil, defaults: Properties? = nil) throws -> (Properties, StringSeq?) { +public func createProperties(args: StringSeq? = nil, defaults: Properties? = nil) throws -> (Properties, StringSeq) { return try autoreleasepool { var remArgs: NSArray? let propertiesHandle = try ICEUtil.createProperties(args, defaults: (defaults as? PropertiesI)?._handle, remArgs: &remArgs) - return (PropertiesI(handle: propertiesHandle), remArgs as? StringSeq) + return (PropertiesI(handle: propertiesHandle), remArgs as! StringSeq) } } diff --git a/swift/src/Ice/InitializationData.swift b/swift/src/Ice/InitializationData.swift index dae3ffe629b..b5ba18b077b 100644 --- a/swift/src/Ice/InitializationData.swift +++ b/swift/src/Ice/InitializationData.swift @@ -8,6 +8,8 @@ // ********************************************************************** public struct InitializationData { - var properties: Properties? - var logger: Logger? + public init() {} + + public var properties: Properties? + public var logger: Logger? } diff --git a/swift/src/Ice/OutputStream.swift b/swift/src/Ice/OutputStream.swift index 22266a29ee4..7b9a7c1f1f6 100644 --- a/swift/src/Ice/OutputStream.swift +++ b/swift/src/Ice/OutputStream.swift @@ -125,7 +125,7 @@ public class OutputStream { } } - func finished() -> [UInt8] { + public func finished() -> [UInt8] { // Create a copy return Array(UnsafeRawBufferPointer(start: buf.baseAddress!, count: buf.count)) } diff --git a/swift/test/Ice/stream/Client.swift b/swift/test/Ice/stream/Client.swift index 5aca41b2e38..bdd169bb9c3 100644 --- a/swift/test/Ice/stream/Client.swift +++ b/swift/test/Ice/stream/Client.swift @@ -3,43 +3,46 @@ // import Ice +import TestCommon import Foundation -func main() throws { - fputs("testing primitive types... ", stdout) - do - { - var communicator = try Ice.initialize() - defer { - communicator.destroy() - } +public class Client : TestHelperI { - var inS:Ice.InputStream - var outS:Ice.OutputStream + public override func run(args: [String]) throws { - do { - let data = [UInt8]() - inS = Ice.InputStream(communicator: communicator, bytes: data) - } + fputs("testing primitive types... ", stdout) + do + { + var communicator = try Ice.initialize() + defer { + communicator.destroy() + } + + var inS:Ice.InputStream + var outS:Ice.OutputStream - do { - outS = Ice.OutputStream(communicator: communicator) - outS.startEncapsulation() - outS.write(true) - outS.endEncapsulation() - var data = outS.finished() - - inS = Ice.InputStream(communicator: communicator, bytes: data) - try inS.startEncapsulation() - assert(inS.read(as: Bool.self)) - - - + do { + let data = [UInt8]() + inS = Ice.InputStream(communicator: communicator, bytes: data) + } + + do { + outS = Ice.OutputStream(communicator: communicator) + outS.startEncapsulation() + outS.write(true) + outS.endEncapsulation() + let data = outS.finished() + + inS = Ice.InputStream(communicator: communicator, bytes: data) + try inS.startEncapsulation() + let b = try Bool(from: inS) + assert(b) + } } + catch let err + { + print(err) + } + print("ok") } - catch let err - { - print(err) - } - print("ok") } diff --git a/swift/test/TestCommon/TestCommon.swift b/swift/test/TestCommon/TestCommon.swift index e794095f1f4..3bfa7934773 100644 --- a/swift/test/TestCommon/TestCommon.swift +++ b/swift/test/TestCommon/TestCommon.swift @@ -5,136 +5,133 @@ import Ice import Foundation -protocol TextWriter +public protocol TextWriter { func write(data:String) func writeLine(data:String) } -class StdoutWriter : TextWriter +public class StdoutWriter : TextWriter { - func write(data:String) + public func write(data:String) { fputs(data, stdout) } - func writeLine(data:String) + public func writeLine(data:String) { print(data) } } -protocol TestHelper +public protocol TestHelper { - func run(args:[String]?) -> Void - func getTestEndpoint(num:Int, prot:String) -> String - func getTestEndpoint(properties:Ice.Properties, num:Int, prot:String) -> String + func run(args:[String]) throws + func getTestEndpoint(num:Int32, prot:String) -> String + func getTestEndpoint(properties:Ice.Properties, num:Int32, prot:String) -> String func getTestHost() -> String func getTestHost(properties:Ice.Properties) -> String func getTestProtocol() -> String func getTestProtocol(properties:Ice.Properties) -> String - func getTestPort(num:Int) -> Int - func getTestPort(properties:Ice.Properties, num:Int) -> Int - func createTestProperties(args:[String]?) -> (Ice.Properties, [String]?) - func initialize(args:[String]?) -> (Ice.Communicator, [String]?) - func initialize(properties:Ice.Properties) -> Ice.Communicator - func initialize(initData:Ice.InitializationData) -> Ice.Communicator + func getTestPort(num:Int32) -> Int32 + func getTestPort(properties:Ice.Properties, num:Int32) -> Int32 + func createTestProperties(args:[String]) throws -> (Ice.Properties, [String]) + func initialize(args:[String]) throws -> (Ice.Communicator, [String]) + func initialize(properties:Ice.Properties) throws -> Ice.Communicator + func initialize(initData:Ice.InitializationData) throws -> Ice.Communicator func getWriter() -> TextWriter - func setWriter(writer:TextWriter) -> Void + func setWriter(writer:TextWriter) } -extension TestHelper -{ - private var _communicator:Ice.Communicator - private var _writer:StdoutWriter +open class TestHelperI : TestHelper { - func getTestEndpoint(num:Int = 0, prot:String = "") -> String - { - return getTestEndpoint(_communicator.getProperties(), num, prot) + private var _communicator:Ice.Communicator! + private var _writer:TextWriter! + + public init(){ } - func getTestEndpoint(properties:Ice.Properties, num:Int = 0, prot:String = "") -> String - { + open func run(args:[String]) throws { + print("Subclass has not implemented abstract method `run`!") + abort() + } + + public func getTestEndpoint(num:Int32 = 0, prot:String = "") -> String { + return getTestEndpoint(properties:_communicator!.getProperties(), + num:num, + prot:prot) + } + + public func getTestEndpoint(properties: Ice.Properties, num: Int32 = 0, prot: String = "") -> String { var s = ""; - s += (prot == "") ? properties.getPropertyWithDefault("Ice.Default.Protocol", "default") : prot + s += (prot == "") ? properties.getPropertyWithDefault(key:"Ice.Default.Protocol", value:"default") : prot s += " -p " - s += properties.getPropertyAsIntWithDefault("Test.BasePort", 12010) + num + let port = properties.getPropertyAsIntWithDefault(key:"Test.BasePort", value:12010) + num + s += String(port) return s } - func getTestHost() -> String - { - return getTestHost(_communicator.getProperties()) + public func getTestHost() -> String { + return getTestHost(properties: _communicator!.getProperties()) } - func getTestHost(properties:Ice.Properties) -> String - { - return properties.getPropertyWithDefault("Ice.Default.Host", "127.0.0.1") + public func getTestHost(properties:Ice.Properties) -> String { + return properties.getPropertyWithDefault(key: "Ice.Default.Host", value: "127.0.0.1") } - func getTestProtocol() -> String - { - return getTestProtocol(_communicator.getProperties()); + public func getTestProtocol() -> String { + return getTestProtocol(properties: _communicator!.getProperties()); } - func getTestProtocol(properties:Ice.Properties) -> String - { - return properties.getPropertyWithDefault("Ice.Default.Protocol", "tcp") + public func getTestProtocol(properties: Ice.Properties) -> String { + return properties.getPropertyWithDefault(key: "Ice.Default.Protocol", value: "tcp") } - func getTestPort(num:Int) -> Int - { - return getTestPort(_communicator.getProperties(), num) + public func getTestPort(num:Int32) -> Int32 { + return getTestPort(properties: _communicator.getProperties(), num: num) } - func getTestPort(properties:Ice.Properties, num:Int) -> Int - { - return properties.getPropertyAsIntWithDefault("Test.BasePort", 12010) + num; + public func getTestPort(properties: Ice.Properties, num: Int32) -> Int32 { + return properties.getPropertyAsIntWithDefault(key: "Test.BasePort", value: 12010) + num; } - func createTestProperties(args:[String]?) -> (Ice.Properties, [String]?) - { - var (properties, args) = createProperties(args) - args = properties.parseCommandLineOptions("Test", args) + public func createTestProperties(args: [String]) throws -> (Ice.Properties, [String]) { + var (properties, args) = try Ice.createProperties(args: args) + args = try properties.parseCommandLineOptions(prefix: "Test", options: args) return (properties, args) } - func initialize(args:[String]?) -> (Ice.Communicator, [String]?) - { + public func initialize(args: [String]) throws -> (Ice.Communicator, [String]) { var initData = Ice.InitializationData() - initData.properties = createTestProperties(args) - return initialize(initData) + var (props, args) = try createTestProperties(args: args) + (initData.properties, args) = (props, args) + let communicator = try initialize(initData: initData) + return (communicator, args) } - func initialize(properties:Ice.Properties) -> Ice.Communicator - { + public func initialize(properties:Ice.Properties) throws -> Ice.Communicator { var initData = Ice.InitializationData() initData.properties = properties - return initialize(initData) + return try initialize(initData: initData) } - func initialize(initData:Ice.InitializationData) -> Ice.Communicator - { - var communicator = Ice.initialize(initData) - if(_communicator == nil) - { + public func initialize(initData: Ice.InitializationData) throws -> Ice.Communicator { + let communicator = try Ice.initialize(initData: initData) + if(_communicator == nil) { _communicator = communicator } return communicator } - func getWriter() -> TextWriter - { - if(_writer == nil) - { + public func getWriter() -> TextWriter { + if(_writer == nil) { _writer = StdoutWriter() } return _writer } - func setWriter(writer:TextWriter) - { + public func setWriter(writer:TextWriter) { _writer = writer } } diff --git a/swift/test/TestDriver.xcodeproj/project.pbxproj b/swift/test/TestDriver.xcodeproj/project.pbxproj index 9eaeef4f634..5099f00a69b 100644 --- a/swift/test/TestDriver.xcodeproj/project.pbxproj +++ b/swift/test/TestDriver.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 8279A2F222206F7B0053BC0E /* stream.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 82E6C09E2220535300B7A404 /* stream.framework */; }; + 8279A2F3222074E00053BC0E /* TestCommon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 82E6C0802220515F00B7A404 /* TestCommon.framework */; }; 82AB3A8522205B5E001A88F1 /* Ice.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 82AB3A8422205B5E001A88F1 /* Ice.framework */; }; 82E6C0752220514000B7A404 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82E6C0742220514000B7A404 /* main.swift */; }; 82E6C0842220515F00B7A404 /* TestCommon.h in Headers */ = {isa = PBXBuildFile; fileRef = 82E6C0822220515F00B7A404 /* TestCommon.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -46,6 +48,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 8279A2F222206F7B0053BC0E /* stream.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -60,6 +63,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 8279A2F3222074E00053BC0E /* TestCommon.framework in Frameworks */, 82AB3A8522205B5E001A88F1 /* Ice.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/swift/test/TestDriver/main.swift b/swift/test/TestDriver/main.swift index 6d4944d5db0..46ad240b5d5 100644 --- a/swift/test/TestDriver/main.swift +++ b/swift/test/TestDriver/main.swift @@ -7,5 +7,7 @@ // import Foundation +import stream -print("Hello, World!") +var client = stream.Client() +try client.run(args: CommandLine.arguments) |