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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442
|
#!/usr/bin/env python3
#
# Copyright (c) ZeroC, Inc. All rights reserved.
#
import os, sys, traceback, threading, time, concurrent.futures
import Ice
slice_dir = Ice.getSliceDir()
if not slice_dir:
print(sys.argv[0] + ': Slice directory not found.')
sys.exit(1)
Ice.loadSlice("'-I" + slice_dir + "' Test.ice")
import Test, M
def test(b):
if not b:
raise RuntimeError('test assertion failed')
class FutureThread(threading.Thread):
def __init__(self, f, r):
threading.Thread.__init__(self)
self.future = f
self.result = r
def run(self):
time.sleep(0.05)
self.future.set_result(self.result)
class MyDerivedClassI(Test.MyDerivedClass):
def __init__(self):
self.threads = []
self.threadLock = threading.Lock()
self.lock = threading.Lock()
self.opByteSOnewayCount = 0
def ice_isA(self, id, current=None):
test(current.mode == Ice.OperationMode.Nonmutating)
return Test.MyDerivedClass.ice_isA(self, id, current)
def ice_ping(self, current=None):
test(current.mode == Ice.OperationMode.Nonmutating)
Test.MyDerivedClass.ice_ping(self, current)
def ice_ids(self, current=None):
test(current.mode == Ice.OperationMode.Nonmutating)
return Test.MyDerivedClass.ice_ids(self, current)
def ice_id(self, current=None):
test(current.mode == Ice.OperationMode.Nonmutating)
return Test.MyDerivedClass.ice_id(self, current)
def shutdown(self, current=None):
with self.threadLock:
for thread in self.threads:
thread.join()
self.threads = []
current.adapter.getCommunicator().shutdown()
def supportsCompress(self, current=None):
return True
def opVoid(self, current=None):
test(current.mode == Ice.OperationMode.Normal)
f = Ice.Future()
with self.threadLock:
thread = FutureThread(f, None)
self.threads.append(thread)
thread.start()
return f
def opByte(self, p1, p2, current=None):
# Test the ability to use another Future type
f = concurrent.futures.Future()
with self.threadLock:
thread = FutureThread(f, (p1, p1 ^ p2))
self.threads.append(thread)
thread.start()
return f
def opBool(self, p1, p2, current=None):
return Ice.Future.completed((p2, p1))
# Test the ability to define a servant method as a coroutine
async def opShortIntLong(self, p1, p2, p3, current=None):
f = Ice.Future()
with self.threadLock:
thread = FutureThread(f, (p3, p1, p2, p3))
self.threads.append(thread)
thread.start()
return await f
def opFloatDouble(self, p1, p2, current=None):
return Ice.Future.completed((p2, p1, p2))
def opString(self, p1, p2, current=None):
return Ice.Future.completed((p1 + " " + p2, p2 + " " + p1))
def opMyEnum(self, p1, current=None):
return Ice.Future.completed((Test.MyEnum.enum3, p1))
def opMyClass(self, p1, current=None):
p2 = p1
p3 = Test.MyClassPrx.uncheckedCast(current.adapter.createProxy(Ice.stringToIdentity("noSuchIdentity")))
return Ice.Future.completed((Test.MyClassPrx.uncheckedCast(current.adapter.createProxy(current.id)), p2, p3))
def opStruct(self, p1, p2, current=None):
p1.s.s = "a new string"
return Ice.Future.completed((p2, p1))
def opByteS(self, p1, p2, current=None):
if sys.version_info[0] == 2:
# By default sequence<byte> maps to a string.
p3 = map(ord, p1)
p3.reverse()
r = map(ord, p1)
r.extend(map(ord, p2))
else:
p3 = bytes(reversed(p1))
r = p1 + p2
return Ice.Future.completed((r, p3))
def opBoolS(self, p1, p2, current=None):
p3 = p1[0:]
p3.extend(p2)
r = p1[0:]
r.reverse();
return Ice.Future.completed((r, p3))
def opShortIntLongS(self, p1, p2, p3, current=None):
p4 = p1[0:]
p5 = p2[0:]
p5.reverse()
p6 = p3[0:]
p6.extend(p3)
return Ice.Future.completed((p3, p4, p5, p6))
def opFloatDoubleS(self, p1, p2, current=None):
p3 = p1[0:]
p4 = p2[0:]
p4.reverse()
r = p2[0:]
r.extend(p1)
return Ice.Future.completed((r, p3, p4))
def opStringS(self, p1, p2, current=None):
p3 = p1[0:]
p3.extend(p2)
r = p1[0:]
r.reverse()
return Ice.Future.completed((r, p3))
def opByteSS(self, p1, p2, current=None):
p3 = p1[0:]
p3.reverse()
r = p1[0:]
r.extend(p2)
return Ice.Future.completed((r, p3))
def opBoolSS(self, p1, p2, current=None):
p3 = p1[0:]
p3.extend(p2)
r = p1[0:]
r.reverse()
return Ice.Future.completed((r, p3))
def opShortIntLongSS(self, p1, p2, p3, current=None):
p4 = p1[0:]
p5 = p2[0:]
p5.reverse()
p6 = p3[0:]
p6.extend(p3)
return Ice.Future.completed((p3, p4, p5, p6))
def opFloatDoubleSS(self, p1, p2, current=None):
p3 = p1[0:]
p4 = p2[0:]
p4.reverse()
r = p2[0:]
r.extend(p2)
return Ice.Future.completed((r, p3, p4))
def opStringSS(self, p1, p2, current=None):
p3 = p1[0:]
p3.extend(p2)
r = p2[0:]
r.reverse()
return Ice.Future.completed((r, p3))
def opStringSSS(self, p1, p2, current=None):
p3 = p1[0:]
p3.extend(p2)
r = p2[0:]
r.reverse()
return Ice.Future.completed((r, p3))
def opByteBoolD(self, p1, p2, current=None):
p3 = p1.copy()
r = p1.copy()
r.update(p2)
return Ice.Future.completed((r, p3))
def opShortIntD(self, p1, p2, current=None):
p3 = p1.copy()
r = p1.copy()
r.update(p2)
return Ice.Future.completed((r, p3))
def opLongFloatD(self, p1, p2, current=None):
p3 = p1.copy()
r = p1.copy()
r.update(p2)
return Ice.Future.completed((r, p3))
def opStringStringD(self, p1, p2, current=None):
p3 = p1.copy()
r = p1.copy()
r.update(p2)
return Ice.Future.completed((r, p3))
def opStringMyEnumD(self, p1, p2, current=None):
p3 = p1.copy()
r = p1.copy()
r.update(p2)
return Ice.Future.completed((r, p3))
def opMyEnumStringD(self, p1, p2, current=None):
p3 = p1.copy()
r = p1.copy()
r.update(p2)
return Ice.Future.completed((r, p3))
def opMyStructMyEnumD(self, p1, p2, current=None):
p3 = p1.copy()
r = p1.copy()
r.update(p2)
return Ice.Future.completed((r, p3))
def opByteBoolDS(self, p1, p2, current=None):
p3 = p2[0:]
p3.extend(p1)
r = p1[::-1]
return Ice.Future.completed((r, p3))
def opShortIntDS(self, p1, p2, current=None):
p3 = p2[0:]
p3.extend(p1)
r = p1[::-1]
return Ice.Future.completed((r, p3))
def opLongFloatDS(self, p1, p2, current=None):
p3 = p2[0:]
p3.extend(p1)
r = p1[::-1]
return Ice.Future.completed((r, p3))
def opStringStringDS(self, p1, p2, current=None):
p3 = p2[0:]
p3.extend(p1)
r = p1[::-1]
return Ice.Future.completed((r, p3))
def opStringMyEnumDS(self, p1, p2, current=None):
p3 = p2[0:]
p3.extend(p1)
r = p1[::-1]
return Ice.Future.completed((r, p3))
def opMyEnumStringDS(self, p1, p2, current=None):
p3 = p2[0:]
p3.extend(p1)
r = p1[::-1]
return Ice.Future.completed((r, p3))
def opMyStructMyEnumDS(self, p1, p2, current=None):
p3 = p2[0:]
p3.extend(p1)
r = p1[::-1]
return Ice.Future.completed((r, p3))
def opByteByteSD(self, p1, p2, current=None):
p3 = p2.copy()
r = p1.copy()
r.update(p2)
return Ice.Future.completed((r, p3))
def opBoolBoolSD(self, p1, p2, current=None):
p3 = p2.copy()
r = p1.copy()
r.update(p2)
return Ice.Future.completed((r, p3))
def opShortShortSD(self, p1, p2, current=None):
p3 = p2.copy()
r = p1.copy()
r.update(p2)
return Ice.Future.completed((r, p3))
def opIntIntSD(self, p1, p2, current=None):
p3 = p2.copy()
r = p1.copy()
r.update(p2)
return Ice.Future.completed((r, p3))
def opLongLongSD(self, p1, p2, current=None):
p3 = p2.copy()
r = p1.copy()
r.update(p2)
return Ice.Future.completed((r, p3))
def opStringFloatSD(self, p1, p2, current=None):
p3 = p2.copy()
r = p1.copy()
r.update(p2)
return Ice.Future.completed((r, p3))
def opStringDoubleSD(self, p1, p2, current=None):
p3 = p2.copy()
r = p1.copy()
r.update(p2)
return Ice.Future.completed((r, p3))
def opStringStringSD(self, p1, p2, current=None):
p3 = p2.copy()
r = p1.copy()
r.update(p2)
return Ice.Future.completed((r, p3))
def opMyEnumMyEnumSD(self, p1, p2, current=None):
p3 = p2.copy()
r = p1.copy()
r.update(p2)
return Ice.Future.completed((r, p3))
def opIntS(self, s, current=None):
return Ice.Future.completed([-x for x in s])
def opByteSOneway(self, s, current=None):
with self.lock:
self.opByteSOnewayCount += 1
return Ice.Future.completed(None)
def opByteSOnewayCallCount(self, current=None):
with self.lock:
count = self.opByteSOnewayCount
self.opByteSOnewayCount = 0
return Ice.Future.completed(count)
def opDoubleMarshaling(self, p1, p2, current=None):
d = 1278312346.0 / 13.0;
test(p1 == d)
for i in p2:
test(i == d)
return Ice.Future.completed(None)
def opContext(self, current=None):
return Ice.Future.completed(current.ctx)
def opIdempotent(self, current=None):
test(current.mode == Ice.OperationMode.Idempotent)
return Ice.Future.completed(None)
def opNonmutating(self, current=None):
test(current.mode == Ice.OperationMode.Nonmutating)
return Ice.Future.completed(None)
def opDerived(self, current=None):
return Ice.Future.completed(None)
def opByte1(self, value, current=None):
return Ice.Future.completed(value)
def opShort1(self, value, current=None):
return Ice.Future.completed(value)
def opInt1(self, value, current=None):
return Ice.Future.completed(value)
def opLong1(self, value, current=None):
return Ice.Future.completed(value)
def opFloat1(self, value, current=None):
return Ice.Future.completed(value)
def opDouble1(self, value, current=None):
return Ice.Future.completed(value)
def opString1(self, value, current=None):
return Ice.Future.completed(value)
def opStringS1(self, value, current=None):
return Ice.Future.completed(value)
def opByteBoolD1(self, value, current=None):
return Ice.Future.completed(value)
def opStringS2(self, value, current=None):
return Ice.Future.completed(value)
def opByteBoolD2(self, value, current=None):
return Ice.Future.completed(value)
def opMyClass1(self, value, current=None):
return Ice.Future.completed(value)
def opMyStruct1(self, value, current=None):
return Ice.Future.completed(value)
def opStringLiterals(self, current=None):
return Ice.Future.completed([
Test.s0, Test.s1, Test.s2, Test.s3, Test.s4, Test.s5, Test.s6, Test.s7, Test.s8, Test.s9, Test.s10,
Test.sw0, Test.sw1, Test.sw2, Test.sw3, Test.sw4, Test.sw5, Test.sw6, Test.sw7, Test.sw8, Test.sw9,
Test.sw10,
Test.ss0, Test.ss1, Test.ss2, Test.ss3, Test.ss4, Test.ss5,
Test.su0, Test.su1, Test.su2])
def opWStringLiterals(self, current=None):
return self.opStringLiterals(current)
def opMStruct1(self, current):
return Ice.Future.completed(Test.MyClass.OpMStruct1MarshaledResult(Test.Structure(), current))
def opMStruct2(self, p1, current):
return Ice.Future.completed(Test.MyClass.OpMStruct2MarshaledResult((p1, p1), current))
def opMSeq1(self, current):
return Ice.Future.completed(Test.MyClass.OpMSeq1MarshaledResult([], current))
def opMSeq2(self, p1, current):
return Ice.Future.completed(Test.MyClass.OpMSeq2MarshaledResult((p1, p1), current))
def opMDict1(self, current):
return Ice.Future.completed(Test.MyClass.OpMDict1MarshaledResult({}, current))
def opMDict2(self, p1, current):
return Ice.Future.completed(Test.MyClass.OpMDict2MarshaledResult((p1, p1), current))
|