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
|
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//
import Ice
import Foundation
public protocol TextWriter
{
func write(data:String)
func writeLine(data:String)
}
public class StdoutWriter : TextWriter
{
public func write(data:String)
{
fputs(data, stdout)
}
public func writeLine(data:String)
{
print(data)
}
}
public protocol TestHelper
{
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: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)
}
open class TestHelperI : TestHelper {
private var _communicator:Ice.Communicator!
private var _writer:TextWriter!
public init(){
}
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(key:"Ice.Default.Protocol", value:"default") : prot
s += " -p "
let port = properties.getPropertyAsIntWithDefault(key:"Test.BasePort", value:12010) + num
s += String(port)
return s
}
public func getTestHost() -> String {
return getTestHost(properties: _communicator!.getProperties())
}
public func getTestHost(properties:Ice.Properties) -> String {
return properties.getPropertyWithDefault(key: "Ice.Default.Host", value: "127.0.0.1")
}
public func getTestProtocol() -> String {
return getTestProtocol(properties: _communicator!.getProperties());
}
public func getTestProtocol(properties: Ice.Properties) -> String {
return properties.getPropertyWithDefault(key: "Ice.Default.Protocol", value: "tcp")
}
public func getTestPort(num:Int32) -> Int32 {
return getTestPort(properties: _communicator.getProperties(), num: num)
}
public func getTestPort(properties: Ice.Properties, num: Int32) -> Int32 {
return properties.getPropertyAsIntWithDefault(key: "Test.BasePort", value: 12010) + num;
}
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)
}
public func initialize(args: [String]) throws -> (Ice.Communicator, [String]) {
var initData = Ice.InitializationData()
var (props, args) = try createTestProperties(args: args)
(initData.properties, args) = (props, args)
let communicator = try initialize(initData: initData)
return (communicator, args)
}
public func initialize(properties:Ice.Properties) throws -> Ice.Communicator {
var initData = Ice.InitializationData()
initData.properties = properties
return try initialize(initData: initData)
}
public func initialize(initData: Ice.InitializationData) throws -> Ice.Communicator {
let communicator = try Ice.initialize(initData: initData)
if(_communicator == nil) {
_communicator = communicator
}
return communicator
}
public func getWriter() -> TextWriter {
if(_writer == nil) {
_writer = StdoutWriter()
}
return _writer
}
public func setWriter(writer:TextWriter) {
_writer = writer
}
}
|