1# 2# Copyright (c) ZeroC, Inc. All rights reserved. 3# 4 5import Ice, Test, math, sys, threading 6 7def test(b): 8 if not b: 9 raise RuntimeError('test assertion failed') 10 11class CallbackBase: 12 def __init__(self): 13 self._called = False 14 self._cond = threading.Condition() 15 16 def check(self): 17 with self._cond: 18 while not self._called: 19 self._cond.wait() 20 self._called = False 21 22 def called(self): 23 with self._cond: 24 self._called = True 25 self._cond.notify() 26 27class Callback(CallbackBase): 28 def __init__(self, communicator=None): 29 CallbackBase.__init__(self) 30 self._communicator = communicator 31 32 def ping(self): 33 self.called() 34 35 def isA(self, r): 36 test(r) 37 self.called() 38 39 def id(self, id): 40 test(id == "::Test::MyDerivedClass") 41 self.called() 42 43 def ids(self, ids): 44 test(len(ids) == 3) 45 self.called() 46 47 def opVoid(self): 48 self.called() 49 50 def opByte(self, r, b): 51 test(b == 0xf0) 52 test(r == 0xff) 53 self.called() 54 55 def opBool(self, r, b): 56 test(b) 57 test(not r) 58 self.called() 59 60 def opShortIntLong(self, r, s, i, l): 61 test(s == 10) 62 test(i == 11) 63 test(l == 12) 64 test(r == 12) 65 self.called() 66 67 def opFloatDouble(self, r, f, d): 68 test(f - 3.14 < 0.001) 69 test(d == 1.1E10) 70 test(r == 1.1E10) 71 self.called() 72 73 def opString(self, r, s): 74 test(s == "world hello") 75 test(r == "hello world") 76 self.called() 77 78 def opMyEnum(self, r, e): 79 test(e == Test.MyEnum.enum2) 80 test(r == Test.MyEnum.enum3) 81 self.called() 82 83 def opMyClass(self, r, c1, c2): 84 test(c1.ice_getIdentity() == Ice.stringToIdentity("test")) 85 test(c2.ice_getIdentity() == Ice.stringToIdentity("noSuchIdentity")) 86 test(r.ice_getIdentity() == Ice.stringToIdentity("test")) 87 # We can't do the callbacks below in serialize mode 88 if self._communicator.getProperties().getPropertyAsInt("Ice.Client.ThreadPool.Serialize") == 0: 89 r.opVoid() 90 c1.opVoid() 91 try: 92 c2.opVoid() 93 test(False) 94 except Ice.ObjectNotExistException: 95 pass 96 self.called() 97 98 def opStruct(self, rso, so): 99 test(rso.p == None) 100 test(rso.e == Test.MyEnum.enum2) 101 test(rso.s.s == "def") 102 test(so.e == Test.MyEnum.enum3) 103 test(so.s.s == "a new string") 104 # We can't do the callbacks below in serialize mode. 105 if self._communicator.getProperties().getPropertyAsInt("Ice.ThreadPool.Client.Serialize") == 0: 106 so.p.opVoid() 107 self.called() 108 109 def opByteS(self, rso, bso): 110 test(len(bso) == 4) 111 test(len(rso) == 8) 112 if sys.version_info[0] == 2: 113 test(bso[0] == '\x22') 114 test(bso[1] == '\x12') 115 test(bso[2] == '\x11') 116 test(bso[3] == '\x01') 117 test(rso[0] == '\x01') 118 test(rso[1] == '\x11') 119 test(rso[2] == '\x12') 120 test(rso[3] == '\x22') 121 test(rso[4] == '\xf1') 122 test(rso[5] == '\xf2') 123 test(rso[6] == '\xf3') 124 test(rso[7] == '\xf4') 125 else: 126 test(bso[0] == 0x22) 127 test(bso[1] == 0x12) 128 test(bso[2] == 0x11) 129 test(bso[3] == 0x01) 130 test(rso[0] == 0x01) 131 test(rso[1] == 0x11) 132 test(rso[2] == 0x12) 133 test(rso[3] == 0x22) 134 test(rso[4] == 0xf1) 135 test(rso[5] == 0xf2) 136 test(rso[6] == 0xf3) 137 test(rso[7] == 0xf4) 138 self.called() 139 140 def opBoolS(self, rso, bso): 141 test(len(bso) == 4) 142 test(bso[0]) 143 test(bso[1]) 144 test(not bso[2]) 145 test(not bso[3]) 146 test(len(rso) == 3) 147 test(not rso[0]) 148 test(rso[1]) 149 test(rso[2]) 150 self.called() 151 152 def opShortIntLongS(self, rso, sso, iso, lso): 153 test(len(sso) == 3) 154 test(sso[0] == 1) 155 test(sso[1] == 2) 156 test(sso[2] == 3) 157 test(len(iso) == 4) 158 test(iso[0] == 8) 159 test(iso[1] == 7) 160 test(iso[2] == 6) 161 test(iso[3] == 5) 162 test(len(lso) == 6) 163 test(lso[0] == 10) 164 test(lso[1] == 30) 165 test(lso[2] == 20) 166 test(lso[3] == 10) 167 test(lso[4] == 30) 168 test(lso[5] == 20) 169 test(len(rso) == 3) 170 test(rso[0] == 10) 171 test(rso[1] == 30) 172 test(rso[2] == 20) 173 self.called() 174 175 def opFloatDoubleS(self, rso, fso, dso): 176 test(len(fso) == 2) 177 test(fso[0] - 3.14 < 0.001) 178 test(fso[1] - 1.11 < 0.001) 179 test(len(dso) == 3) 180 test(dso[0] == 1.3E10) 181 test(dso[1] == 1.2E10) 182 test(dso[2] == 1.1E10) 183 test(len(rso) == 5) 184 test(rso[0] == 1.1E10) 185 test(rso[1] == 1.2E10) 186 test(rso[2] == 1.3E10) 187 test(rso[3] - 3.14 < 0.001) 188 test(rso[4] - 1.11 < 0.001) 189 self.called() 190 191 def opStringS(self, rso, sso): 192 test(len(sso) == 4) 193 test(sso[0] == "abc") 194 test(sso[1] == "de") 195 test(sso[2] == "fghi") 196 test(sso[3] == "xyz") 197 test(len(rso) == 3) 198 test(rso[0] == "fghi") 199 test(rso[1] == "de") 200 test(rso[2] == "abc") 201 self.called() 202 203 def opByteSS(self, rso, bso): 204 test(len(bso) == 2) 205 test(len(bso[0]) == 1) 206 test(len(bso[1]) == 3) 207 test(len(rso) == 4) 208 test(len(rso[0]) == 3) 209 test(len(rso[1]) == 1) 210 test(len(rso[2]) == 1) 211 test(len(rso[3]) == 2) 212 if sys.version_info[0] == 2: 213 test(bso[0][0] == '\xff') 214 test(bso[1][0] == '\x01') 215 test(bso[1][1] == '\x11') 216 test(bso[1][2] == '\x12') 217 test(rso[0][0] == '\x01') 218 test(rso[0][1] == '\x11') 219 test(rso[0][2] == '\x12') 220 test(rso[1][0] == '\xff') 221 test(rso[2][0] == '\x0e') 222 test(rso[3][0] == '\xf2') 223 test(rso[3][1] == '\xf1') 224 else: 225 test(bso[0][0] == 0xff) 226 test(bso[1][0] == 0x01) 227 test(bso[1][1] == 0x11) 228 test(bso[1][2] == 0x12) 229 test(rso[0][0] == 0x01) 230 test(rso[0][1] == 0x11) 231 test(rso[0][2] == 0x12) 232 test(rso[1][0] == 0xff) 233 test(rso[2][0] == 0x0e) 234 test(rso[3][0] == 0xf2) 235 test(rso[3][1] == 0xf1) 236 self.called() 237 238 def opBoolSS(self, rso, bso): 239 test(len(bso) == 4); 240 test(len(bso[0]) == 1); 241 test(bso[0][0]); 242 test(len(bso[1]) == 1); 243 test(not bso[1][0]); 244 test(len(bso[2]) == 2); 245 test(bso[2][0]); 246 test(bso[2][1]); 247 test(len(bso[3]) == 3); 248 test(not bso[3][0]); 249 test(not bso[3][1]); 250 test(bso[3][2]); 251 test(len(rso) == 3); 252 test(len(rso[0]) == 2); 253 test(rso[0][0]); 254 test(rso[0][1]); 255 test(len(rso[1]) == 1); 256 test(not rso[1][0]); 257 test(len(rso[2]) == 1); 258 test(rso[2][0]); 259 self.called(); 260 261 def opShortIntLongSS(self, rso, sso, iso, lso): 262 test(len(rso) == 1); 263 test(len(rso[0]) == 2); 264 test(rso[0][0] == 496); 265 test(rso[0][1] == 1729); 266 test(len(sso) == 3); 267 test(len(sso[0]) == 3); 268 test(sso[0][0] == 1); 269 test(sso[0][1] == 2); 270 test(sso[0][2] == 5); 271 test(len(sso[1]) == 1); 272 test(sso[1][0] == 13); 273 test(len(sso[2]) == 0); 274 test(len(iso) == 2); 275 test(len(iso[0]) == 1); 276 test(iso[0][0] == 42); 277 test(len(iso[1]) == 2); 278 test(iso[1][0] == 24); 279 test(iso[1][1] == 98); 280 test(len(lso) == 2); 281 test(len(lso[0]) == 2); 282 test(lso[0][0] == 496); 283 test(lso[0][1] == 1729); 284 test(len(lso[1]) == 2); 285 test(lso[1][0] == 496); 286 test(lso[1][1] == 1729); 287 self.called(); 288 289 def opFloatDoubleSS(self, rso, fso, dso): 290 test(len(fso) == 3) 291 test(len(fso[0]) == 1) 292 test(fso[0][0] - 3.14 < 0.001) 293 test(len(fso[1]) == 1) 294 test(fso[1][0] - 1.11 < 0.001) 295 test(len(fso[2]) == 0) 296 test(len(dso) == 1) 297 test(len(dso[0]) == 3) 298 test(dso[0][0] == 1.1E10) 299 test(dso[0][1] == 1.2E10) 300 test(dso[0][2] == 1.3E10) 301 test(len(rso) == 2) 302 test(len(rso[0]) == 3) 303 test(rso[0][0] == 1.1E10) 304 test(rso[0][1] == 1.2E10) 305 test(rso[0][2] == 1.3E10) 306 test(len(rso[1]) == 3) 307 test(rso[1][0] == 1.1E10) 308 test(rso[1][1] == 1.2E10) 309 test(rso[1][2] == 1.3E10) 310 self.called() 311 312 def opStringSS(self, rso, sso): 313 test(len(sso) == 5) 314 test(len(sso[0]) == 1) 315 test(sso[0][0] == "abc") 316 test(len(sso[1]) == 2) 317 test(sso[1][0] == "de") 318 test(sso[1][1] == "fghi") 319 test(len(sso[2]) == 0) 320 test(len(sso[3]) == 0) 321 test(len(sso[4]) == 1) 322 test(sso[4][0] == "xyz") 323 test(len(rso) == 3) 324 test(len(rso[0]) == 1) 325 test(rso[0][0] == "xyz") 326 test(len(rso[1]) == 0) 327 test(len(rso[2]) == 0) 328 self.called() 329 330 def opByteBoolD(self, ro, do): 331 di1 = {10: True, 100: False} 332 test(do == di1) 333 test(len(ro) == 4) 334 test(ro[10]) 335 test(not ro[11]) 336 test(not ro[100]) 337 test(ro[101]) 338 self.called() 339 340 def opShortIntD(self, ro, do): 341 di1 = {110: -1, 1100: 123123} 342 test(do == di1) 343 test(len(ro) == 4) 344 test(ro[110] == -1) 345 test(ro[111] == -100) 346 test(ro[1100] == 123123) 347 test(ro[1101] == 0) 348 self.called() 349 350 def opLongFloatD(self, ro, do): 351 di1 = {999999110: -1.1, 999999111: 123123.2} 352 for k in do: 353 test(math.fabs(do[k] - di1[k]) < 0.01) 354 test(len(ro) == 4) 355 test(ro[999999110] - -1.1 < 0.01) 356 test(ro[999999120] - -100.4 < 0.01) 357 test(ro[999999111] - 123123.2 < 0.01) 358 test(ro[999999130] - 0.5 < 0.01) 359 self.called() 360 361 def opStringStringD(self, ro, do): 362 di1 = {'foo': 'abc -1.1', 'bar': 'abc 123123.2'} 363 test(do == di1) 364 test(len(ro) == 4) 365 test(ro["foo"] == "abc -1.1") 366 test(ro["FOO"] == "abc -100.4") 367 test(ro["bar"] == "abc 123123.2") 368 test(ro["BAR"] == "abc 0.5") 369 self.called() 370 371 def opStringMyEnumD(self, ro, do): 372 di1 = {'abc': Test.MyEnum.enum1, '': Test.MyEnum.enum2} 373 test(do == di1) 374 test(len(ro) == 4) 375 test(ro["abc"] == Test.MyEnum.enum1) 376 test(ro["qwerty"] == Test.MyEnum.enum3) 377 test(ro[""] == Test.MyEnum.enum2) 378 test(ro["Hello!!"] == Test.MyEnum.enum2) 379 self.called() 380 381 def opMyEnumStringD(self, ro, do): 382 di1 = {Test.MyEnum.enum1: 'abc'} 383 test(do == di1) 384 test(len(ro) == 3) 385 test(ro[Test.MyEnum.enum1] == "abc") 386 test(ro[Test.MyEnum.enum2] == "Hello!!") 387 test(ro[Test.MyEnum.enum3] == "qwerty") 388 self.called() 389 390 def opMyStructMyEnumD(self, ro, do): 391 s11 = Test.MyStruct() 392 s11.i = 1 393 s11.j = 1 394 s12 = Test.MyStruct() 395 s12.i = 1 396 s12.j = 2 397 s22 = Test.MyStruct() 398 s22.i = 2 399 s22.j = 2 400 s23 = Test.MyStruct() 401 s23.i = 2 402 s23.j = 3 403 di1 = {s11: Test.MyEnum.enum1, s12: Test.MyEnum.enum2} 404 test(do == di1) 405 test(len(ro) == 4) 406 test(ro[s11] == Test.MyEnum.enum1) 407 test(ro[s12] == Test.MyEnum.enum2) 408 test(ro[s22] == Test.MyEnum.enum3) 409 test(ro[s23] == Test.MyEnum.enum2) 410 self.called() 411 412 def opByteBoolDS(self, ro, do): 413 test(len(ro) == 2) 414 test(len(ro[0]) == 3) 415 test(ro[0][10]) 416 test(not ro[0][11]) 417 test(ro[0][101]) 418 test(len(ro[1]) == 2) 419 test(ro[1][10]) 420 test(not ro[1][100]) 421 test(len(do) == 3) 422 test(len(do[0]) == 2) 423 test(not do[0][100]) 424 test(not do[0][101]) 425 test(len(do[1]) == 2) 426 test(do[1][10]) 427 test(not do[1][100]) 428 test(len(do[2]) == 3) 429 test(do[2][10]) 430 test(not do[2][11]) 431 test(do[2][101]) 432 self.called() 433 434 def opShortIntDS(self, ro, do): 435 test(len(ro) == 2) 436 test(len(ro[0]) == 3) 437 test(ro[0][110] == -1) 438 test(ro[0][111] == -100) 439 test(ro[0][1101] == 0) 440 test(len(ro[1]) == 2) 441 test(ro[1][110] == -1) 442 test(ro[1][1100] == 123123) 443 test(len(do) == 3) 444 test(len(do[0]) == 1) 445 test(do[0][100] == -1001) 446 test(len(do[1]) == 2) 447 test(do[1][110] == -1) 448 test(do[1][1100] == 123123) 449 test(len(do[2]) == 3) 450 test(do[2][110] == -1) 451 test(do[2][111] == -100) 452 test(do[2][1101] == 0) 453 self.called() 454 455 def opLongFloatDS(self, ro, do): 456 test(len(ro) == 2) 457 test(len(ro[0]) == 3) 458 test(ro[0][999999110] - -1.1 < 0.01) 459 test(ro[0][999999120] - -100.4 < 0.01) 460 test(ro[0][999999130] - 0.5 < 0.01) 461 test(len(ro[1]) == 2) 462 test(ro[1][999999110] - -1.1 < 0.01) 463 test(ro[1][999999111] - 123123.2 < 0.01) 464 test(len(do) == 3) 465 test(len(do[0]) == 1) 466 test(do[0][999999140] - 3.14 < 0.01) 467 test(len(do[1]) == 2) 468 test(do[1][999999110] - -1.1 < 0.01) 469 test(do[1][999999111] - 123123.2 < 0.01) 470 test(len(do[2]) == 3) 471 test(do[2][999999110] - -1.1 < 0.01) 472 test(do[2][999999120] - -100.4 < 0.01) 473 test(do[2][999999130] - 0.5 < 0.01) 474 self.called() 475 476 def opStringStringDS(self, ro, do): 477 test(len(ro) == 2) 478 test(len(ro[0]) == 3) 479 test(ro[0]["foo"] == "abc -1.1") 480 test(ro[0]["FOO"] == "abc -100.4") 481 test(ro[0]["BAR"] == "abc 0.5") 482 test(len(ro[1]) == 2) 483 test(ro[1]["foo"] == "abc -1.1") 484 test(ro[1]["bar"] == "abc 123123.2") 485 test(len(do) == 3) 486 test(len(do[0]) == 1) 487 test(do[0]["f00"] == "ABC -3.14") 488 test(len(do[1]) == 2) 489 test(do[1]["foo"] == "abc -1.1") 490 test(do[1]["bar"] == "abc 123123.2") 491 test(len(do[2]) == 3) 492 test(do[2]["foo"] == "abc -1.1") 493 test(do[2]["FOO"] == "abc -100.4") 494 test(do[2]["BAR"] == "abc 0.5") 495 self.called() 496 497 def opStringMyEnumDS(self, ro, do): 498 test(len(ro) == 2) 499 test(len(ro[0]) == 3) 500 test(ro[0]["abc"] == Test.MyEnum.enum1) 501 test(ro[0]["qwerty"] == Test.MyEnum.enum3) 502 test(ro[0]["Hello!!"] == Test.MyEnum.enum2) 503 test(len(ro[1]) == 2) 504 test(ro[1]["abc"] == Test.MyEnum.enum1) 505 test(ro[1][""] == Test.MyEnum.enum2) 506 test(len(do) == 3) 507 test(len(do[0]) == 1) 508 test(do[0]["Goodbye"] == Test.MyEnum.enum1) 509 test(len(do[1]) == 2) 510 test(do[1]["abc"] == Test.MyEnum.enum1) 511 test(do[1][""] == Test.MyEnum.enum2) 512 test(len(do[2]) == 3) 513 test(do[2]["abc"] == Test.MyEnum.enum1) 514 test(do[2]["qwerty"] == Test.MyEnum.enum3) 515 test(do[2]["Hello!!"] == Test.MyEnum.enum2) 516 self.called() 517 518 def opMyEnumStringDS(self, ro, do): 519 test(len(ro) == 2) 520 test(len(ro[0]) == 2) 521 test(ro[0][Test.MyEnum.enum2] == "Hello!!") 522 test(ro[0][Test.MyEnum.enum3] == "qwerty") 523 test(len(ro[1]) == 1) 524 test(ro[1][Test.MyEnum.enum1] == "abc") 525 test(len(do) == 3) 526 test(len(do[0]) == 1) 527 test(do[0][Test.MyEnum.enum1] == "Goodbye") 528 test(len(do[1]) == 1) 529 test(do[1][Test.MyEnum.enum1] == "abc") 530 test(len(do[2]) == 2) 531 test(do[2][Test.MyEnum.enum2] == "Hello!!") 532 test(do[2][Test.MyEnum.enum3] == "qwerty") 533 self.called() 534 535 def opMyStructMyEnumDS(self, ro, do): 536 s11 = Test.MyStruct(1, 1) 537 s12 = Test.MyStruct(1, 2) 538 s22 = Test.MyStruct(2, 2) 539 s23 = Test.MyStruct(2, 3) 540 test(len(ro) == 2) 541 test(len(ro[0]) == 3) 542 test(ro[0][s11] == Test.MyEnum.enum1) 543 test(ro[0][s22] == Test.MyEnum.enum3) 544 test(ro[0][s23] == Test.MyEnum.enum2) 545 test(len(ro[1]) == 2) 546 test(ro[1][s11] == Test.MyEnum.enum1) 547 test(ro[1][s12] == Test.MyEnum.enum2) 548 test(len(do) == 3) 549 test(len(do[0]) == 1) 550 test(do[0][s23] == Test.MyEnum.enum3) 551 test(len(do[1]) == 2) 552 test(do[1][s11] == Test.MyEnum.enum1) 553 test(do[1][s12] == Test.MyEnum.enum2) 554 test(len(do[2]) == 3) 555 test(do[2][s11] == Test.MyEnum.enum1) 556 test(do[2][s22] == Test.MyEnum.enum3) 557 test(do[2][s23] == Test.MyEnum.enum2) 558 self.called() 559 560 def opByteByteSD(self, ro, do): 561 if sys.version_info[0] == 2: 562 test(len(do) == 1) 563 test(len(do[0xf1]) == 2) 564 test(do[0xf1][0] == '\xf2') 565 test(do[0xf1][1] == '\xf3') 566 test(len(ro) == 3) 567 test(len(ro[0x01]) == 2) 568 test(ro[0x01][0] == '\x01') 569 test(ro[0x01][1] == '\x11') 570 test(len(ro[0x22]) == 1) 571 test(ro[0x22][0] == '\x12') 572 test(len(ro[0xf1]) == 2) 573 test(ro[0xf1][0] == '\xf2') 574 test(ro[0xf1][1] == '\xf3') 575 else: 576 test(len(do) == 1) 577 test(len(do[0xf1]) == 2) 578 test(do[0xf1][0] == 0xf2) 579 test(do[0xf1][1] == 0xf3) 580 test(len(ro) == 3) 581 test(len(ro[0x01]) == 2) 582 test(ro[0x01][0] == 0x01) 583 test(ro[0x01][1] == 0x11) 584 test(len(ro[0x22]) == 1) 585 test(ro[0x22][0] == 0x12) 586 test(len(ro[0xf1]) == 2) 587 test(ro[0xf1][0] == 0xf2) 588 test(ro[0xf1][1] == 0xf3) 589 self.called() 590 591 def opBoolBoolSD(self, ro, do): 592 test(len(do) == 1) 593 test(len(do[False]) == 2) 594 test(do[False][0]) 595 test(not do[False][1]) 596 test(len(ro) == 2) 597 test(len(ro[False]) == 2) 598 test(ro[False][0]) 599 test(not ro[False][1]) 600 test(len(ro[True]) == 3) 601 test(not ro[True][0]) 602 test(ro[True][1]) 603 test(ro[True][2]) 604 self.called() 605 606 def opShortShortSD(self, ro, do): 607 test(len(do) == 1) 608 test(len(do[4]) == 2) 609 test(do[4][0] == 6) 610 test(do[4][1] == 7) 611 test(len(ro) == 3) 612 test(len(ro[1]) == 3) 613 test(ro[1][0] == 1) 614 test(ro[1][1] == 2) 615 test(ro[1][2] == 3) 616 test(len(ro[2]) == 2) 617 test(ro[2][0] == 4) 618 test(ro[2][1] == 5) 619 test(len(ro[4]) == 2) 620 test(ro[4][0] == 6) 621 test(ro[4][1] == 7) 622 self.called() 623 624 def opIntIntSD(self, ro, do): 625 test(len(do) == 1) 626 test(len(do[400]) == 2) 627 test(do[400][0] == 600) 628 test(do[400][1] == 700) 629 test(len(ro) == 3) 630 test(len(ro[100]) == 3) 631 test(ro[100][0] == 100) 632 test(ro[100][1] == 200) 633 test(ro[100][2] == 300) 634 test(len(ro[200]) == 2) 635 test(ro[200][0] == 400) 636 test(ro[200][1] == 500) 637 test(len(ro[400]) == 2) 638 test(ro[400][0] == 600) 639 test(ro[400][1] == 700) 640 self.called() 641 642 def opLongLongSD(self, ro, do): 643 test(len(do) == 1) 644 test(len(do[999999992]) == 2) 645 test(do[999999992][0] == 999999110) 646 test(do[999999992][1] == 999999120) 647 test(len(ro) == 3) 648 test(len(ro[999999990]) == 3) 649 test(ro[999999990][0] == 999999110) 650 test(ro[999999990][1] == 999999111) 651 test(ro[999999990][2] == 999999110) 652 test(len(ro[999999991]) == 2) 653 test(ro[999999991][0] == 999999120) 654 test(ro[999999991][1] == 999999130) 655 test(len(ro[999999992]) == 2) 656 test(ro[999999992][0] == 999999110) 657 test(ro[999999992][1] == 999999120) 658 self.called() 659 660 def opStringFloatSD(self, ro, do): 661 test(len(do) == 1) 662 test(len(do["aBc"]) == 2) 663 test(do["aBc"][0] - -3.14 < 0.10) 664 test(do["aBc"][1] - 3.14 < 0.10) 665 test(len(ro) == 3) 666 test(len(ro["abc"]) == 3) 667 test(ro["abc"][0] - -1.1 < 0.10) 668 test(ro["abc"][1] - 123123.2 < 0.10) 669 test(ro["abc"][2] - 100.0 < 0.10) 670 test(len(ro["ABC"]) == 2) 671 test(ro["ABC"][0] - 42.24 < 0.10) 672 test(ro["ABC"][1] - -1.61 < 0.10) 673 test(len(ro["aBc"]) == 2) 674 test(ro["aBc"][0] - -3.14 < 0.10) 675 test(ro["aBc"][1] - 3.14 < 0.10) 676 self.called() 677 678 def opStringDoubleSD(self, ro, do): 679 test(len(do) == 1) 680 test(len(do[""]) == 2) 681 test(do[""][0] == 1.6E10) 682 test(do[""][1] == 1.7E10) 683 test(len(ro) == 3) 684 test(len(ro["Hello!!"]) == 3) 685 test(ro["Hello!!"][0] == 1.1E10) 686 test(ro["Hello!!"][1] == 1.2E10) 687 test(ro["Hello!!"][2] == 1.3E10) 688 test(len(ro["Goodbye"]) == 2) 689 test(ro["Goodbye"][0] == 1.4E10) 690 test(ro["Goodbye"][1] == 1.5E10) 691 test(len(ro[""]) == 2) 692 test(ro[""][0] == 1.6E10) 693 test(ro[""][1] == 1.7E10) 694 self.called() 695 696 def opStringStringSD(self, ro, do): 697 test(len(do) == 1) 698 test(len(do["ghi"]) == 2) 699 test(do["ghi"][0] == "and") 700 test(do["ghi"][1] == "xor") 701 test(len(ro) == 3) 702 test(len(ro["abc"]) == 3) 703 test(ro["abc"][0] == "abc") 704 test(ro["abc"][1] == "de") 705 test(ro["abc"][2] == "fghi") 706 test(len(ro["def"]) == 2) 707 test(ro["def"][0] == "xyz") 708 test(ro["def"][1] == "or") 709 test(len(ro["ghi"]) == 2) 710 test(ro["ghi"][0] == "and") 711 test(ro["ghi"][1] == "xor") 712 self.called() 713 714 def opMyEnumMyEnumSD(self, ro, do): 715 test(len(do) == 1) 716 test(len(do[Test.MyEnum.enum1]) == 2) 717 test(do[Test.MyEnum.enum1][0] == Test.MyEnum.enum3) 718 test(do[Test.MyEnum.enum1][1] == Test.MyEnum.enum3) 719 test(len(ro) == 3) 720 test(len(ro[Test.MyEnum.enum3]) == 3) 721 test(ro[Test.MyEnum.enum3][0] == Test.MyEnum.enum1) 722 test(ro[Test.MyEnum.enum3][1] == Test.MyEnum.enum1) 723 test(ro[Test.MyEnum.enum3][2] == Test.MyEnum.enum2) 724 test(len(ro[Test.MyEnum.enum2]) == 2) 725 test(ro[Test.MyEnum.enum2][0] == Test.MyEnum.enum1) 726 test(ro[Test.MyEnum.enum2][1] == Test.MyEnum.enum2) 727 test(len(ro[Test.MyEnum.enum1]) == 2) 728 test(ro[Test.MyEnum.enum1][0] == Test.MyEnum.enum3) 729 test(ro[Test.MyEnum.enum1][1] == Test.MyEnum.enum3) 730 self.called() 731 732 def opIntS(self, r): 733 for j in range(0, len(r)): 734 test(r[j] == -j) 735 self.called() 736 737 def opIdempotent(self): 738 self.called() 739 740 def opNonmutating(self): 741 self.called() 742 743 def opDerived(self): 744 self.called() 745 746 def exCB(self, ex): 747 test(False) 748 749def twowaysAMI(helper, p): 750 communicator = helper.communicator() 751 cb = Callback() 752 p.begin_ice_ping(cb.ping, cb.exCB) 753 cb.check() 754 755 cb = Callback() 756 p.begin_ice_isA(Test.MyClass.ice_staticId(), cb.isA, cb.exCB) 757 cb.check() 758 759 cb = Callback() 760 p.begin_ice_id(cb.id, cb.exCB) 761 cb.check() 762 763 cb = Callback() 764 p.begin_ice_ids(cb.ids, cb.exCB) 765 cb.check() 766 767 r = p.begin_opVoid() 768 p.end_opVoid(r) 769 770 cb = Callback() 771 p.begin_opVoid(cb.opVoid, cb.exCB) 772 cb.check() 773 774 r = p.begin_opByte(0xff, 0x0f) 775 (ret, p3) = p.end_opByte(r) 776 test(p3 == 0xf0) 777 test(ret == 0xff) 778 779 cb = Callback() 780 p.begin_opByte(0xff, 0x0f, cb.opByte, cb.exCB) 781 cb.check() 782 783 cb = Callback() 784 p.begin_opBool(True, False, cb.opBool, cb.exCB) 785 cb.check() 786 787 cb = Callback() 788 p.begin_opShortIntLong(10, 11, 12, cb.opShortIntLong, cb.exCB) 789 cb.check() 790 791 cb = Callback() 792 p.begin_opFloatDouble(3.14, 1.1E10, cb.opFloatDouble, cb.exCB) 793 cb.check() 794 795 cb = Callback() 796 p.begin_opString("hello", "world", cb.opString, cb.exCB) 797 cb.check() 798 799 cb = Callback() 800 p.begin_opMyEnum(Test.MyEnum.enum2, cb.opMyEnum, cb.exCB) 801 cb.check() 802 803 cb = Callback(communicator) 804 p.begin_opMyClass(p, cb.opMyClass, cb.exCB) 805 cb.check() 806 807 si1 = Test.Structure() 808 si1.p = p 809 si1.e = Test.MyEnum.enum3 810 si1.s = Test.AnotherStruct() 811 si1.s.s = "abc" 812 si2 = Test.Structure() 813 si2.p = None 814 si2.e = Test.MyEnum.enum2 815 si2.s = Test.AnotherStruct() 816 si2.s.s = "def" 817 818 cb = Callback(communicator) 819 p.begin_opStruct(si1, si2, cb.opStruct, cb.exCB) 820 cb.check() 821 822 bsi1 = (0x01, 0x11, 0x12, 0x22) 823 bsi2 = (0xf1, 0xf2, 0xf3, 0xf4) 824 825 cb = Callback() 826 p.begin_opByteS(bsi1, bsi2, cb.opByteS, cb.exCB) 827 cb.check() 828 829 bsi1 = (True, True, False) 830 bsi2 = (False,) 831 832 cb = Callback() 833 p.begin_opBoolS(bsi1, bsi2, cb.opBoolS, cb.exCB) 834 cb.check() 835 836 ssi = (1, 2, 3) 837 isi = (5, 6, 7, 8) 838 lsi = (10, 30, 20) 839 840 cb = Callback() 841 p.begin_opShortIntLongS(ssi, isi, lsi, cb.opShortIntLongS, cb.exCB) 842 cb.check() 843 844 fsi = (3.14, 1.11) 845 dsi = (1.1E10, 1.2E10, 1.3E10) 846 847 cb = Callback() 848 p.begin_opFloatDoubleS(fsi, dsi, cb.opFloatDoubleS, cb.exCB) 849 cb.check() 850 851 ssi1 = ('abc', 'de', 'fghi') 852 ssi2 = ('xyz',) 853 854 cb = Callback() 855 p.begin_opStringS(ssi1, ssi2, cb.opStringS, cb.exCB) 856 cb.check() 857 858 bsi1 = ((0x01, 0x11, 0x12), (0xff,)) 859 bsi2 = ((0x0e,), (0xf2, 0xf1)) 860 861 cb = Callback() 862 p.begin_opByteSS(bsi1, bsi2, cb.opByteSS, cb.exCB) 863 cb.check() 864 865 bsi1 = ((True,), (False,), (True, True),) 866 bsi2 = ((False, False, True),) 867 868 cb = Callback() 869 p.begin_opBoolSS(bsi1, bsi2, cb.opBoolSS, cb.exCB) 870 cb.check(); 871 872 ssi = ((1,2,5), (13,), ()) 873 isi = ((24, 98), (42,)) 874 lsi = ((496, 1729),) 875 876 cb = Callback() 877 p.begin_opShortIntLongSS(ssi, isi, lsi, cb.opShortIntLongSS, cb.exCB) 878 cb.check() 879 880 fsi = ((3.14,), (1.11,), ()) 881 dsi = ((1.1E10, 1.2E10, 1.3E10),) 882 883 cb = Callback() 884 p.begin_opFloatDoubleSS(fsi, dsi, cb.opFloatDoubleSS, cb.exCB) 885 cb.check() 886 887 ssi1 = (('abc',), ('de', 'fghi')) 888 ssi2 = ((), (), ('xyz',)) 889 890 cb = Callback() 891 p.begin_opStringSS(ssi1, ssi2, cb.opStringSS, cb.exCB) 892 cb.check() 893 894 di1 = {10: True, 100: False} 895 di2 = {10: True, 11: False, 101: True} 896 897 cb = Callback() 898 p.begin_opByteBoolD(di1, di2, cb.opByteBoolD, cb.exCB) 899 cb.check() 900 901 di1 = {110: -1, 1100: 123123} 902 di2 = {110: -1, 111: -100, 1101: 0} 903 904 cb = Callback() 905 p.begin_opShortIntD(di1, di2, cb.opShortIntD, cb.exCB) 906 cb.check() 907 908 di1 = {999999110: -1.1, 999999111: 123123.2} 909 di2 = {999999110: -1.1, 999999120: -100.4, 999999130: 0.5} 910 911 cb = Callback() 912 p.begin_opLongFloatD(di1, di2, cb.opLongFloatD, cb.exCB) 913 cb.check() 914 915 di1 = {'foo': 'abc -1.1', 'bar': 'abc 123123.2'} 916 di2 = {'foo': 'abc -1.1', 'FOO': 'abc -100.4', 'BAR': 'abc 0.5'} 917 918 cb = Callback() 919 p.begin_opStringStringD(di1, di2, cb.opStringStringD, cb.exCB) 920 cb.check() 921 922 di1 = {'abc': Test.MyEnum.enum1, '': Test.MyEnum.enum2} 923 di2 = {'abc': Test.MyEnum.enum1, 'qwerty': Test.MyEnum.enum3, 'Hello!!': Test.MyEnum.enum2} 924 925 cb = Callback() 926 p.begin_opStringMyEnumD(di1, di2, cb.opStringMyEnumD, cb.exCB) 927 cb.check() 928 929 di1 = {Test.MyEnum.enum1: 'abc'} 930 di2 = {Test.MyEnum.enum2: 'Hello!!', Test.MyEnum.enum3: 'qwerty'} 931 932 cb = Callback() 933 p.begin_opMyEnumStringD(di1, di2, cb.opMyEnumStringD, cb.exCB) 934 cb.check() 935 936 s11 = Test.MyStruct() 937 s11.i = 1 938 s11.j = 1 939 s12 = Test.MyStruct() 940 s12.i = 1 941 s12.j = 2 942 s22 = Test.MyStruct() 943 s22.i = 2 944 s22.j = 2 945 s23 = Test.MyStruct() 946 s23.i = 2 947 s23.j = 3 948 di1 = {s11: Test.MyEnum.enum1, s12: Test.MyEnum.enum2} 949 di2 = {s11: Test.MyEnum.enum1, s22: Test.MyEnum.enum3, s23: Test.MyEnum.enum2} 950 951 cb = Callback() 952 p.begin_opMyStructMyEnumD(di1, di2, cb.opMyStructMyEnumD, cb.exCB) 953 cb.check() 954 955 dsi1 = ({ 10: True, 100: False }, { 10: True, 11: False, 101: True }) 956 dsi2 = ({ 100: False, 101: False },) 957 958 cb = Callback() 959 p.begin_opByteBoolDS(dsi1, dsi2, cb.opByteBoolDS, cb.exCB) 960 cb.check() 961 962 dsi1 = ({ 110: -1, 1100: 123123 }, { 110: -1, 111: -100, 1101: 0 }) 963 dsi2 = ({ 100: -1001 },) 964 965 cb = Callback() 966 p.begin_opShortIntDS(dsi1, dsi2, cb.opShortIntDS, cb.exCB) 967 cb.called() 968 969 dsi1 = ({ 999999110: -1.1, 999999111: 123123.2 }, { 999999110: -1.1, 999999120: -100.4, 999999130: 0.5 }) 970 dsi2 = ({ 999999140: 3.14 },) 971 972 cb = Callback() 973 p.begin_opLongFloatDS(dsi1, dsi2, cb.opLongFloatDS, cb.exCB) 974 cb.called() 975 976 dsi1 = ({ "foo": "abc -1.1", "bar": "abc 123123.2" }, { "foo": "abc -1.1", "FOO": "abc -100.4", "BAR": "abc 0.5" }) 977 dsi2 = ({ "f00": "ABC -3.14" },) 978 979 cb = Callback() 980 p.begin_opStringStringDS(dsi1, dsi2, cb.opStringStringDS, cb.exCB) 981 cb.called() 982 983 dsi1 = ( 984 { "abc": Test.MyEnum.enum1, "": Test.MyEnum.enum2 }, 985 { "abc": Test.MyEnum.enum1, "qwerty": Test.MyEnum.enum3, "Hello!!": Test.MyEnum.enum2 } 986 ) 987 988 dsi2 = ({ "Goodbye": Test.MyEnum.enum1 },) 989 990 cb = Callback() 991 p.begin_opStringMyEnumDS(dsi1, dsi2, cb.opStringMyEnumDS, cb.exCB) 992 cb.called() 993 994 dsi1 = ({ Test.MyEnum.enum1: 'abc' }, { Test.MyEnum.enum2: 'Hello!!', Test.MyEnum.enum3: 'qwerty'}) 995 dsi2 = ({ Test.MyEnum.enum1: 'Goodbye' },) 996 997 cb = Callback() 998 p.begin_opMyEnumStringDS(dsi1, dsi2, cb.opMyEnumStringDS, cb.exCB) 999 cb.called() 1000 1001 s11 = Test.MyStruct(1, 1) 1002 s12 = Test.MyStruct(1, 2) 1003 1004 s22 = Test.MyStruct(2, 2) 1005 s23 = Test.MyStruct(2, 3) 1006 1007 dsi1 = ( 1008 { s11: Test.MyEnum.enum1, s12: Test.MyEnum.enum2 }, 1009 { s11: Test.MyEnum.enum1, s22: Test.MyEnum.enum3, s23: Test.MyEnum.enum2 } 1010 ) 1011 dsi2 = ({ s23: Test.MyEnum.enum3 },) 1012 1013 cb = Callback() 1014 p.begin_opMyStructMyEnumDS(dsi1, dsi2, cb.opMyStructMyEnumDS, cb.exCB) 1015 cb.called() 1016 1017 sdi1 = { 0x01: (0x01, 0x11), 0x22: (0x12,) } 1018 sdi2 = { 0xf1: (0xf2, 0xf3) } 1019 1020 cb = Callback() 1021 p.begin_opByteByteSD(sdi1, sdi2, cb.opByteByteSD, cb.exCB) 1022 cb.called() 1023 1024 sdi1 = { False: (True, False), True: (False, True, True) } 1025 sdi2 = { False: (True, False) } 1026 1027 cb = Callback() 1028 p.begin_opBoolBoolSD(sdi1, sdi2, cb.opBoolBoolSD, cb.exCB) 1029 cb.called() 1030 1031 sdi1 = { 1: (1, 2, 3), 2: (4, 5) } 1032 sdi2 = { 4: (6, 7) } 1033 1034 cb = Callback() 1035 p.begin_opShortShortSD(sdi1, sdi2, cb.opShortShortSD, cb.exCB) 1036 cb.called() 1037 1038 sdi1 = { 100: (100, 200, 300), 200: (400, 500) } 1039 sdi2 = { 400: (600, 700) } 1040 1041 cb = Callback() 1042 p.begin_opIntIntSD(sdi1, sdi2, cb.opIntIntSD, cb.exCB) 1043 cb.called() 1044 1045 sdi1 = { 999999990: (999999110, 999999111, 999999110), 999999991: (999999120, 999999130) } 1046 sdi2 = { 999999992: (999999110, 999999120) } 1047 1048 cb = Callback() 1049 p.begin_opLongLongSD(sdi1, sdi2, cb.opLongLongSD, cb.exCB) 1050 cb.called() 1051 1052 sdi1 = { "abc": (-1.1, 123123.2, 100.0), "ABC": (42.24, -1.61) } 1053 sdi2 = { "aBc": (-3.14, 3.14) } 1054 1055 cb = Callback() 1056 p.begin_opStringFloatSD(sdi1, sdi2, cb.opStringFloatSD, cb.exCB) 1057 cb.called() 1058 1059 sdi1 = { "Hello!!": (1.1E10, 1.2E10, 1.3E10), "Goodbye": (1.4E10, 1.5E10) } 1060 sdi2 = { "": (1.6E10, 1.7E10) } 1061 1062 cb = Callback() 1063 p.begin_opStringDoubleSD(sdi1, sdi2, cb.opStringDoubleSD, cb.exCB); 1064 cb.called() 1065 1066 sdi1 = { "abc": ("abc", "de", "fghi") , "def": ("xyz", "or") } 1067 sdi2 = { "ghi": ("and", "xor") } 1068 1069 cb = Callback() 1070 p.begin_opStringStringSD(sdi1, sdi2, cb.opStringStringSD, cb.exCB) 1071 cb.called() 1072 1073 sdi1 = { 1074 Test.MyEnum.enum3: (Test.MyEnum.enum1, Test.MyEnum.enum1, Test.MyEnum.enum2), 1075 Test.MyEnum.enum2: (Test.MyEnum.enum1, Test.MyEnum.enum2) 1076 } 1077 sdi2 = { Test.MyEnum.enum1: (Test.MyEnum.enum3, Test.MyEnum.enum3) } 1078 1079 cb = Callback() 1080 p.begin_opMyEnumMyEnumSD(sdi1, sdi2, cb.opMyEnumMyEnumSD, cb.exCB) 1081 cb.called() 1082 1083 lengths = ( 0, 1, 2, 126, 127, 128, 129, 253, 254, 255, 256, 257, 1000 ) 1084 for l in lengths: 1085 s = [] 1086 for i in range(l): 1087 s.append(i) 1088 cb = Callback(l) 1089 p.begin_opIntS(s, cb.opIntS, cb.exCB) 1090 cb.check() 1091 1092 ctx = {'one': 'ONE', 'two': 'TWO', 'three': 'THREE'} 1093 1094 test(len(p.ice_getContext()) == 0) 1095 r = p.begin_opContext() 1096 c = p.end_opContext(r) 1097 test(c != ctx) 1098 1099 test(len(p.ice_getContext()) == 0) 1100 r = p.begin_opContext(context=ctx) 1101 c = p.end_opContext(r) 1102 test(c == ctx) 1103 1104 p2 = Test.MyClassPrx.checkedCast(p.ice_context(ctx)) 1105 test(p2.ice_getContext() == ctx) 1106 r = p2.begin_opContext() 1107 c = p2.end_opContext(r) 1108 test(c == ctx) 1109 1110 r = p2.begin_opContext(context=ctx) 1111 c = p2.end_opContext(r) 1112 test(c == ctx) 1113 1114 # 1115 # Test implicit context propagation 1116 # 1117 if p.ice_getConnection(): 1118 impls = ( 'Shared', 'PerThread' ) 1119 for i in impls: 1120 initData = Ice.InitializationData() 1121 initData.properties = communicator.getProperties().clone() 1122 initData.properties.setProperty('Ice.ImplicitContext', i) 1123 ic = Ice.initialize(data=initData) 1124 1125 ctx = {'one': 'ONE', 'two': 'TWO', 'three': 'THREE'} 1126 1127 p3 = Test.MyClassPrx.uncheckedCast(ic.stringToProxy("test:{0}".format(helper.getTestEndpoint()))) 1128 1129 ic.getImplicitContext().setContext(ctx) 1130 test(ic.getImplicitContext().getContext() == ctx) 1131 r = p3.begin_opContext() 1132 c = p3.end_opContext(r) 1133 test(c == ctx) 1134 1135 ic.getImplicitContext().put('zero', 'ZERO') 1136 1137 ctx = ic.getImplicitContext().getContext() 1138 r = p3.begin_opContext() 1139 c = p3.end_opContext(r) 1140 test(c == ctx) 1141 1142 prxContext = {'one': 'UN', 'four': 'QUATRE'} 1143 1144 combined = {} 1145 combined.update(ctx) 1146 combined.update(prxContext) 1147 test(combined['one'] == 'UN') 1148 1149 p3 = Test.MyClassPrx.uncheckedCast(p3.ice_context(prxContext)) 1150 ic.getImplicitContext().setContext({}) 1151 r = p3.begin_opContext() 1152 c = p3.end_opContext(r) 1153 test(c == prxContext) 1154 1155 ic.getImplicitContext().setContext(ctx) 1156 r = p3.begin_opContext() 1157 c = p3.end_opContext(r) 1158 test(c == combined) 1159 1160 ic.destroy() 1161 1162 cb = Callback() 1163 p.begin_opIdempotent(cb.opIdempotent, cb.exCB) 1164 cb.check() 1165 1166 cb = Callback() 1167 p.begin_opNonmutating(cb.opNonmutating, cb.exCB) 1168 cb.check() 1169 1170 derived = Test.MyDerivedClassPrx.checkedCast(p) 1171 test(derived) 1172 cb = Callback() 1173 derived.begin_opDerived(cb.opDerived, cb.exCB) 1174 cb.check() 1175 1176 r = p.begin_opByte1(0xFF) 1177 test(p.end_opByte1(r) == 0xFF) 1178 1179 r = p.begin_opShort1(0x7FFF) 1180 test(p.end_opShort1(r) == 0x7FFF) 1181 1182 r = p.begin_opInt1(0x7FFFFFFF) 1183 test(p.end_opInt1(r) == 0x7FFFFFFF) 1184 1185 r = p.begin_opLong1(0x7FFFFFFFFFFFFFFF) 1186 test(p.end_opLong1(r) == 0x7FFFFFFFFFFFFFFF) 1187 1188 r = p.begin_opFloat1(1.0) 1189 test(p.end_opFloat1(r) == 1.0) 1190 1191 r = p.begin_opDouble1(1.0) 1192 test(p.end_opDouble1(r) == 1.0) 1193 1194 r = p.begin_opString1("opString1") 1195 test(p.end_opString1(r) == "opString1") 1196 1197 r = p.begin_opStringS1(None) 1198 test(len(p.end_opStringS1(r)) == 0) 1199 1200 r = p.begin_opByteBoolD1(None) 1201 test(len(p.end_opByteBoolD1(r)) == 0) 1202 1203 r = p.begin_opStringS2(None) 1204 test(len(p.end_opStringS2(r)) == 0) 1205 1206 r = p.begin_opByteBoolD2(None) 1207 test(len(p.end_opByteBoolD2(r)) == 0) 1208