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
|
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//
import Foundation
import Ice
import PromiseKit
import TestCommon
class TestI: TestIntf {
var _batchCount: Int32
var _shutdown: Bool
var _lock = os_unfair_lock()
var _semaphore = DispatchSemaphore(value: 0)
var _pending: Resolver<Void>?
var _helper: TestHelper
init(helper: TestHelper) {
_batchCount = 0
_shutdown = false
_helper = helper
}
func op(current _: Current) throws {}
func opWithPayload(seq _: ByteSeq, current _: Current) throws {}
func opWithResult(current _: Current) throws -> Int32 {
return 15
}
func opWithUE(current _: Current) throws {
throw TestIntfException()
}
func opWithResultAndUE(current _: Current) throws -> Int32 {
throw TestIntfException()
}
func opWithArgs(current _: Current) throws -> (one: Int32,
two: Int32,
three: Int32,
four: Int32,
five: Int32,
six: Int32,
seven: Int32,
eight: Int32,
nine: Int32,
ten: Int32,
eleven: Int32) {
return (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
}
func startDispatchAsync(current _: Current) -> Promise<Void> {
return withLock(&_lock) {
if _shutdown {
return Promise.value(())
} else if let pending = _pending {
pending.fulfill(())
}
return Promise<Void> { seal in
_pending = seal
}
}
}
func pingBiDir(reply: PingReplyPrx?, current: Current) throws {
if let reply = reply {
try reply.ice_fixed(current.con!).replyAsync().wait()
}
}
func opBatch(current _: Current) throws {
withLock(&_lock) {
_batchCount += 1
_semaphore.signal()
}
}
func opBatchCount(current _: Current) throws -> Int32 {
return withLock(&_lock) {
_batchCount
}
}
func waitForBatch(count: Int32, current _: Current) throws -> Bool {
while _batchCount < count {
if _semaphore.wait(timeout: .now() + .seconds(5)) == .timedOut {
try _helper.test(false)
}
}
let result = count == _batchCount
_batchCount = 0
return result
}
func close(mode: CloseMode, current: Current) throws {
if let con = current.con,
let closeMode = ConnectionClose(rawValue: mode.rawValue) {
try con.close(closeMode)
}
}
func sleep(ms: Int32, current _: Current) throws {
withLock(&_lock) {
Thread.sleep(forTimeInterval: TimeInterval(ms) / 1000)
}
}
func finishDispatch(current _: Current) throws {
withLock(&_lock) {
if _shutdown {
return
} else if let pending = _pending {
// Pending might not be set yet if startDispatch is dispatch out-of-order
pending.fulfill(())
_pending = nil
}
}
}
func shutdown(current: Current) throws {
withLock(&_lock) {
_shutdown = true
if let pending = _pending {
// Pending might not be set yet if startDispatch is dispatch out-of-order
pending.fulfill(())
_pending = nil
}
}
current.adapter!.getCommunicator().shutdown()
}
func supportsAMD(current _: Current) throws -> Bool {
return true
}
func supportsFunctionalTests(current _: Current) throws -> Bool {
return false
}
}
class TestII: OuterInnerTestIntf {
func op(i: Int32, current _: Ice.Current) throws -> (returnValue: Int32, j: Int32) {
return (i, i)
}
}
class TestControllerI: TestIntfController {
var _adapter: Ice.ObjectAdapter
init(adapter: Ice.ObjectAdapter) {
_adapter = adapter
}
func holdAdapter(current _: Ice.Current) {
_adapter.hold()
}
func resumeAdapter(current _: Ice.Current) throws {
try _adapter.activate()
}
}
|