ICE 3.4.2
[php5-ice-freebsdport.git] / py / test / Ice / operations / TwowaysAMI.py
blob5a231a52eb8a71090c297850651945db23b5aa77
1 # **********************************************************************
3 # Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
5 # This copy of Ice is licensed to you under the terms described in the
6 # ICE_LICENSE file included in this distribution.
8 # **********************************************************************
10 import Ice, Test, math, threading
12 def test(b):
13 if not b:
14 raise RuntimeError('test assertion failed')
16 class CallbackBase:
17 def __init__(self):
18 self._called = False
19 self._cond = threading.Condition()
21 def check(self):
22 self._cond.acquire()
23 try:
24 while not self._called:
25 self._cond.wait()
26 self._called = False
27 finally:
28 self._cond.release()
30 def called(self):
31 self._cond.acquire()
32 self._called = True
33 self._cond.notify()
34 self._cond.release()
36 class AMI_MyClass_opVoidI(CallbackBase):
37 def __init__(self):
38 CallbackBase.__init__(self)
40 def ice_response(self):
41 self.called()
43 def ice_exception(self, ex):
44 test(False)
46 class AMI_MyClass_opVoidExI(CallbackBase):
47 def __init__(self):
48 CallbackBase.__init__(self)
50 def ice_response(self):
51 test(False)
53 def ice_exception(self, ex):
54 test(isinstance(ex, Ice.NoEndpointException))
55 self.called()
57 class AMI_MyClass_opByteI(CallbackBase):
58 def __init__(self):
59 CallbackBase.__init__(self)
61 def ice_response(self, r, b):
62 test(b == 0xf0)
63 test(r == 0xff)
64 self.called()
66 def ice_exception(self, ex):
67 test(False)
69 class AMI_MyClass_opByteExI(CallbackBase):
70 def __init__(self):
71 CallbackBase.__init__(self)
73 def ice_response(self, r, b):
74 test(False)
76 def ice_exception(self, ex):
77 test(isinstance(ex, Ice.NoEndpointException))
78 self.called()
80 class AMI_MyClass_opBoolI(CallbackBase):
81 def __init__(self):
82 CallbackBase.__init__(self)
84 def ice_response(self, r, b):
85 test(b)
86 test(not r)
87 self.called()
89 def ice_exception(self, ex):
90 test(False)
92 class AMI_MyClass_opShortIntLongI(CallbackBase):
93 def __init__(self):
94 CallbackBase.__init__(self)
96 def ice_response(self, r, s, i, l):
97 test(s == 10)
98 test(i == 11)
99 test(l == 12)
100 test(r == 12)
101 self.called()
103 def ice_exception(self, ex):
104 test(False)
106 class AMI_MyClass_opFloatDoubleI(CallbackBase):
107 def __init__(self):
108 CallbackBase.__init__(self)
110 def ice_response(self, r, f, d):
111 test(f - 3.14 < 0.001)
112 test(d == 1.1E10)
113 test(r == 1.1E10)
114 self.called()
116 def ice_exception(self, ex):
117 test(False)
119 class AMI_MyClass_opStringI(CallbackBase):
120 def __init__(self):
121 CallbackBase.__init__(self)
123 def ice_response(self, r, s):
124 test(s == "world hello")
125 test(r == "hello world")
126 self.called()
128 def ice_exception(self, ex):
129 test(False)
131 class AMI_MyClass_opMyEnumI(CallbackBase):
132 def __init__(self):
133 CallbackBase.__init__(self)
135 def ice_response(self, r, e):
136 test(e == Test.MyEnum.enum2)
137 test(r == Test.MyEnum.enum3)
138 self.called()
140 def ice_exception(self, ex):
141 test(False)
143 class AMI_MyClass_opMyClassI(CallbackBase):
144 def __init__(self, communicator):
145 CallbackBase.__init__(self)
146 self._communicator = communicator
148 def ice_response(self, r, c1, c2):
149 test(c1.ice_getIdentity() == self._communicator.stringToIdentity("test"))
150 test(c2.ice_getIdentity() == self._communicator.stringToIdentity("noSuchIdentity"))
151 test(r.ice_getIdentity() == self._communicator.stringToIdentity("test"))
152 # We can't do the callbacks below in serialize mode
153 if self._communicator.getProperties().getPropertyAsInt("Ice.Client.ThreadPool.Serialize") == 0:
154 r.opVoid()
155 c1.opVoid()
156 try:
157 c2.opVoid()
158 test(False)
159 except Ice.ObjectNotExistException:
160 pass
161 self.called()
163 def ice_exception(self, ex):
164 test(False)
166 class AMI_MyClass_opStructI(CallbackBase):
168 def __init__(self, communicator):
169 CallbackBase.__init__(self)
170 self._communicator = communicator
172 def ice_response(self, rso, so):
173 test(rso.p == None)
174 test(rso.e == Test.MyEnum.enum2)
175 test(rso.s.s == "def")
176 test(so.e == Test.MyEnum.enum3)
177 test(so.s.s == "a new string")
178 # We can't do the callbacks below in serialize mode.
179 if self._communicator.getProperties().getPropertyAsInt("Ice.ThreadPool.Client.Serialize") == 0:
180 so.p.opVoid()
181 self.called()
183 def ice_exception(self, ex):
184 test(False)
186 class AMI_MyClass_opByteSI(CallbackBase):
187 def __init__(self):
188 CallbackBase.__init__(self)
190 def ice_response(self, rso, bso):
191 test(len(bso) == 4)
192 test(bso[0] == '\x22')
193 test(bso[1] == '\x12')
194 test(bso[2] == '\x11')
195 test(bso[3] == '\x01')
196 test(len(rso) == 8)
197 test(rso[0] == '\x01')
198 test(rso[1] == '\x11')
199 test(rso[2] == '\x12')
200 test(rso[3] == '\x22')
201 test(rso[4] == '\xf1')
202 test(rso[5] == '\xf2')
203 test(rso[6] == '\xf3')
204 test(rso[7] == '\xf4')
205 self.called()
207 def ice_exception(self, ex):
208 test(False)
210 class AMI_MyClass_opBoolSI(CallbackBase):
211 def __init__(self):
212 CallbackBase.__init__(self)
214 def ice_response(self, rso, bso):
215 test(len(bso) == 4)
216 test(bso[0])
217 test(bso[1])
218 test(not bso[2])
219 test(not bso[3])
220 test(len(rso) == 3)
221 test(not rso[0])
222 test(rso[1])
223 test(rso[2])
224 self.called()
226 def ice_exception(self, ex):
227 test(False)
229 class AMI_MyClass_opShortIntLongSI(CallbackBase):
230 def __init__(self):
231 CallbackBase.__init__(self)
233 def ice_response(self, rso, sso, iso, lso):
234 test(len(sso) == 3)
235 test(sso[0] == 1)
236 test(sso[1] == 2)
237 test(sso[2] == 3)
238 test(len(iso) == 4)
239 test(iso[0] == 8)
240 test(iso[1] == 7)
241 test(iso[2] == 6)
242 test(iso[3] == 5)
243 test(len(lso) == 6)
244 test(lso[0] == 10)
245 test(lso[1] == 30)
246 test(lso[2] == 20)
247 test(lso[3] == 10)
248 test(lso[4] == 30)
249 test(lso[5] == 20)
250 test(len(rso) == 3)
251 test(rso[0] == 10)
252 test(rso[1] == 30)
253 test(rso[2] == 20)
254 self.called()
256 def ice_exception(self, ex):
257 test(False)
259 class AMI_MyClass_opFloatDoubleSI(CallbackBase):
260 def __init__(self):
261 CallbackBase.__init__(self)
263 def ice_response(self, rso, fso, dso):
264 test(len(fso) == 2)
265 test(fso[0] - 3.14 < 0.001)
266 test(fso[1] - 1.11 < 0.001)
267 test(len(dso) == 3)
268 test(dso[0] == 1.3E10)
269 test(dso[1] == 1.2E10)
270 test(dso[2] == 1.1E10)
271 test(len(rso) == 5)
272 test(rso[0] == 1.1E10)
273 test(rso[1] == 1.2E10)
274 test(rso[2] == 1.3E10)
275 test(rso[3] - 3.14 < 0.001)
276 test(rso[4] - 1.11 < 0.001)
277 self.called()
279 def ice_exception(self, ex):
280 test(False)
282 class AMI_MyClass_opStringSI(CallbackBase):
283 def __init__(self):
284 CallbackBase.__init__(self)
286 def ice_response(self, rso, sso):
287 test(len(sso) == 4)
288 test(sso[0] == "abc")
289 test(sso[1] == "de")
290 test(sso[2] == "fghi")
291 test(sso[3] == "xyz")
292 test(len(rso) == 3)
293 test(rso[0] == "fghi")
294 test(rso[1] == "de")
295 test(rso[2] == "abc")
296 self.called()
298 def ice_exception(self, ex):
299 test(False)
301 class AMI_MyClass_opByteSSI(CallbackBase):
302 def __init__(self):
303 CallbackBase.__init__(self)
305 def ice_response(self, rso, bso):
306 test(len(bso) == 2)
307 test(len(bso[0]) == 1)
308 test(bso[0][0] == '\xff')
309 test(len(bso[1]) == 3)
310 test(bso[1][0] == '\x01')
311 test(bso[1][1] == '\x11')
312 test(bso[1][2] == '\x12')
313 test(len(rso) == 4)
314 test(len(rso[0]) == 3)
315 test(rso[0][0] == '\x01')
316 test(rso[0][1] == '\x11')
317 test(rso[0][2] == '\x12')
318 test(len(rso[1]) == 1)
319 test(rso[1][0] == '\xff')
320 test(len(rso[2]) == 1)
321 test(rso[2][0] == '\x0e')
322 test(len(rso[3]) == 2)
323 test(rso[3][0] == '\xf2')
324 test(rso[3][1] == '\xf1')
325 self.called()
327 def ice_exception(self, ex):
328 test(False)
330 class AMI_MyClass_opFloatDoubleSSI(CallbackBase):
331 def __init__(self):
332 CallbackBase.__init__(self)
334 def ice_response(self, rso, fso, dso):
335 test(len(fso) == 3)
336 test(len(fso[0]) == 1)
337 test(fso[0][0] - 3.14 < 0.001)
338 test(len(fso[1]) == 1)
339 test(fso[1][0] - 1.11 < 0.001)
340 test(len(fso[2]) == 0)
341 test(len(dso) == 1)
342 test(len(dso[0]) == 3)
343 test(dso[0][0] == 1.1E10)
344 test(dso[0][1] == 1.2E10)
345 test(dso[0][2] == 1.3E10)
346 test(len(rso) == 2)
347 test(len(rso[0]) == 3)
348 test(rso[0][0] == 1.1E10)
349 test(rso[0][1] == 1.2E10)
350 test(rso[0][2] == 1.3E10)
351 test(len(rso[1]) == 3)
352 test(rso[1][0] == 1.1E10)
353 test(rso[1][1] == 1.2E10)
354 test(rso[1][2] == 1.3E10)
355 self.called()
357 def ice_exception(self, ex):
358 test(False)
360 class AMI_MyClass_opStringSSI(CallbackBase):
361 def __init__(self):
362 CallbackBase.__init__(self)
364 def ice_response(self, rso, sso):
365 test(len(sso) == 5)
366 test(len(sso[0]) == 1)
367 test(sso[0][0] == "abc")
368 test(len(sso[1]) == 2)
369 test(sso[1][0] == "de")
370 test(sso[1][1] == "fghi")
371 test(len(sso[2]) == 0)
372 test(len(sso[3]) == 0)
373 test(len(sso[4]) == 1)
374 test(sso[4][0] == "xyz")
375 test(len(rso) == 3)
376 test(len(rso[0]) == 1)
377 test(rso[0][0] == "xyz")
378 test(len(rso[1]) == 0)
379 test(len(rso[2]) == 0)
380 self.called()
382 def ice_exception(self, ex):
383 test(False)
385 class AMI_MyClass_opByteBoolDI(CallbackBase):
386 def __init__(self):
387 CallbackBase.__init__(self)
389 def ice_response(self, ro, do):
390 di1 = {10: True, 100: False}
391 test(do == di1)
392 test(len(ro) == 4)
393 test(ro[10])
394 test(not ro[11])
395 test(not ro[100])
396 test(ro[101])
397 self.called()
399 def ice_exception(self, ex):
400 test(False)
402 class AMI_MyClass_opShortIntDI(CallbackBase):
403 def __init__(self):
404 CallbackBase.__init__(self)
406 def ice_response(self, ro, do):
407 di1 = {110: -1, 1100: 123123}
408 test(do == di1)
409 test(len(ro) == 4)
410 test(ro[110] == -1)
411 test(ro[111] == -100)
412 test(ro[1100] == 123123)
413 test(ro[1101] == 0)
414 self.called()
416 def ice_exception(self, ex):
417 test(False)
419 class AMI_MyClass_opLongFloatDI(CallbackBase):
420 def __init__(self):
421 CallbackBase.__init__(self)
423 def ice_response(self, ro, do):
424 di1 = {999999110: -1.1, 999999111: 123123.2}
425 for k in do:
426 test(math.fabs(do[k] - di1[k]) < 0.01)
427 test(len(ro) == 4)
428 test(ro[999999110] - -1.1 < 0.01)
429 test(ro[999999120] - -100.4 < 0.01)
430 test(ro[999999111] - 123123.2 < 0.01)
431 test(ro[999999130] - 0.5 < 0.01)
432 self.called()
434 def ice_exception(self, ex):
435 test(False)
437 class AMI_MyClass_opStringStringDI(CallbackBase):
438 def __init__(self):
439 CallbackBase.__init__(self)
441 def ice_response(self, ro, do):
442 di1 = {'foo': 'abc -1.1', 'bar': 'abc 123123.2'}
443 test(do == di1)
444 test(len(ro) == 4)
445 test(ro["foo"] == "abc -1.1")
446 test(ro["FOO"] == "abc -100.4")
447 test(ro["bar"] == "abc 123123.2")
448 test(ro["BAR"] == "abc 0.5")
449 self.called()
451 def ice_exception(self, ex):
452 test(False)
454 class AMI_MyClass_opStringMyEnumDI(CallbackBase):
455 def __init__(self):
456 CallbackBase.__init__(self)
458 def ice_response(self, ro, do):
459 di1 = {'abc': Test.MyEnum.enum1, '': Test.MyEnum.enum2}
460 test(do == di1)
461 test(len(ro) == 4)
462 test(ro["abc"] == Test.MyEnum.enum1)
463 test(ro["qwerty"] == Test.MyEnum.enum3)
464 test(ro[""] == Test.MyEnum.enum2)
465 test(ro["Hello!!"] == Test.MyEnum.enum2)
466 self.called()
468 def ice_exception(self, ex):
469 test(False)
471 class AMI_MyClass_opMyEnumStringDI(CallbackBase):
472 def __init__(self):
473 CallbackBase.__init__(self)
475 def ice_response(self, ro, do):
476 di1 = {Test.MyEnum.enum1: 'abc'}
477 test(do == di1)
478 test(len(ro) == 3)
479 test(ro[Test.MyEnum.enum1] == "abc")
480 test(ro[Test.MyEnum.enum2] == "Hello!!")
481 test(ro[Test.MyEnum.enum3] == "qwerty")
482 self.called()
484 def ice_exception(self, ex):
485 test(False)
487 class AMI_MyClass_opMyStructMyEnumDI(CallbackBase):
488 def __init__(self):
489 CallbackBase.__init__(self)
491 def ice_response(self, ro, do):
492 s11 = Test.MyStruct()
493 s11.i = 1
494 s11.j = 1
495 s12 = Test.MyStruct()
496 s12.i = 1
497 s12.j = 2
498 s22 = Test.MyStruct()
499 s22.i = 2
500 s22.j = 2
501 s23 = Test.MyStruct()
502 s23.i = 2
503 s23.j = 3
504 di1 = {s11: Test.MyEnum.enum1, s12: Test.MyEnum.enum2}
505 test(do == di1)
506 test(len(ro) == 4)
507 test(ro[s11] == Test.MyEnum.enum1)
508 test(ro[s12] == Test.MyEnum.enum2)
509 test(ro[s22] == Test.MyEnum.enum3)
510 test(ro[s23] == Test.MyEnum.enum2)
511 self.called()
513 def ice_exception(self, ex):
514 test(False)
516 class AMI_MyClass_opIntSI(CallbackBase):
517 def __init__(self, l):
518 CallbackBase.__init__(self)
519 self._l = l
521 def ice_response(self, r):
522 test(len(r) == self._l)
523 for j in range(0, self._l):
524 test(r[j] == -j)
525 self.called()
527 def ice_exception(self, ex):
528 test(False)
530 class AMI_MyClass_opContextEqualI(CallbackBase):
531 def __init__(self, d):
532 CallbackBase.__init__(self)
533 self._d = d
535 def ice_response(self, r):
536 test(r == self._d)
537 self.called()
539 def ice_exception(self, ex):
540 test(False)
542 class AMI_MyClass_opContextNotEqualI(CallbackBase):
543 def __init__(self, d):
544 CallbackBase.__init__(self)
545 self._d = d
547 def ice_response(self, r):
548 test(r != self._d)
549 self.called()
551 def ice_exception(self, ex):
552 test(False)
554 class AMI_MyClass_opIdempotentI(CallbackBase):
555 def __init__(self):
556 CallbackBase.__init__(self)
558 def ice_response(self):
559 self.called()
561 def ice_exception(self, ex):
562 test(False)
564 class AMI_MyClass_opNonmutatingI(CallbackBase):
565 def __init__(self):
566 CallbackBase.__init__(self)
568 def ice_response(self):
569 self.called()
571 def ice_exception(self, ex):
572 test(False)
574 class AMI_MyDerivedClass_opDerivedI(CallbackBase):
575 def __init__(self):
576 CallbackBase.__init__(self)
578 def ice_response(self):
579 self.called()
581 def ice_exception(self, ex):
582 test(False)
584 def twowaysAMI(communicator, p):
585 # Check that a call to a void operation raises NoEndpointException
586 # in the ice_exception() callback instead of at the point of call.
587 indirect = Test.MyClassPrx.uncheckedCast(p.ice_adapterId("dummy"))
588 cb = AMI_MyClass_opVoidExI()
589 try:
590 test(not indirect.opVoid_async(cb))
591 except Ice.Exception:
592 test(False)
593 cb.check()
595 # Check that a call to a twoway operation raises NoEndpointException
596 # in the ice_exception() callback instead of at the point of call.
597 indirect = Test.MyClassPrx.uncheckedCast(p.ice_adapterId("dummy"))
598 cb = AMI_MyClass_opByteExI()
599 try:
600 test(not indirect.opByte_async(cb, 0, 0))
601 except Ice.Exception:
602 test(False)
603 cb.check()
606 # opVoid
608 cb = AMI_MyClass_opVoidI()
609 p.opVoid_async(cb)
610 cb.check()
611 # Let's check if we can reuse the same callback object for another call.
612 p.opVoid_async(cb)
613 cb.check()
615 # Check that CommunicatorDestroyedException is raised directly.
616 initData = Ice.InitializationData()
617 initData.properties = communicator.getProperties().clone()
618 ic = Ice.initialize(initData)
619 obj = ic.stringToProxy(p.ice_toString())
620 p2 = Test.MyClassPrx.checkedCast(obj)
622 ic.destroy()
624 cb = AMI_MyClass_opVoidI()
625 try:
626 test(not p2.opVoid_async(cb))
627 test(False)
628 except Ice.CommunicatorDestroyedException:
629 pass # Expected.
632 # opByte
634 cb = AMI_MyClass_opByteI()
635 p.opByte_async(cb, 0xff, 0x0f)
636 cb.check()
639 # opBool
641 cb = AMI_MyClass_opBoolI()
642 p.opBool_async(cb, True, False)
643 cb.check()
646 # opShortIntLong
648 cb = AMI_MyClass_opShortIntLongI()
649 p.opShortIntLong_async(cb, 10, 11, 12)
650 cb.check()
653 # opFloatDouble
655 cb = AMI_MyClass_opFloatDoubleI()
656 p.opFloatDouble_async(cb, 3.14, 1.1E10)
657 cb.check()
658 # Let's check if we can reuse the same callback object for another call.
659 p.opFloatDouble_async(cb, 3.14, 1.1E10)
660 cb.check()
663 # opString
665 cb = AMI_MyClass_opStringI()
666 p.opString_async(cb, "hello", "world")
667 cb.check()
670 # opMyEnum
672 cb = AMI_MyClass_opMyEnumI()
673 p.opMyEnum_async(cb, Test.MyEnum.enum2)
674 cb.check()
677 # opMyClass
679 cb = AMI_MyClass_opMyClassI(communicator)
680 p.opMyClass_async(cb, p)
681 cb.check()
684 # opStruct
686 si1 = Test.Structure()
687 si1.p = p
688 si1.e = Test.MyEnum.enum3
689 si1.s = Test.AnotherStruct()
690 si1.s.s = "abc"
691 si2 = Test.Structure()
692 si2.p = None
693 si2.e = Test.MyEnum.enum2
694 si2.s = Test.AnotherStruct()
695 si2.s.s = "def"
697 cb = AMI_MyClass_opStructI(communicator)
698 p.opStruct_async(cb, si1, si2)
699 cb.check()
702 # opByteS
704 bsi1 = (0x01, 0x11, 0x12, 0x22)
705 bsi2 = (0xf1, 0xf2, 0xf3, 0xf4)
707 cb = AMI_MyClass_opByteSI()
708 p.opByteS_async(cb, bsi1, bsi2)
709 cb.check()
712 # opBoolS
714 bsi1 = (True, True, False)
715 bsi2 = (False,)
717 cb = AMI_MyClass_opBoolSI()
718 p.opBoolS_async(cb, bsi1, bsi2)
719 cb.check()
722 # opShortIntLongS
724 ssi = (1, 2, 3)
725 isi = (5, 6, 7, 8)
726 lsi = (10, 30, 20)
728 cb = AMI_MyClass_opShortIntLongSI()
729 p.opShortIntLongS_async(cb, ssi, isi, lsi)
730 cb.check()
733 # opFloatDoubleS
735 fsi = (3.14, 1.11)
736 dsi = (1.1E10, 1.2E10, 1.3E10)
738 cb = AMI_MyClass_opFloatDoubleSI()
739 p.opFloatDoubleS_async(cb, fsi, dsi)
740 cb.check()
743 # opStringS
745 ssi1 = ('abc', 'de', 'fghi')
746 ssi2 = ('xyz',)
748 cb = AMI_MyClass_opStringSI()
749 p.opStringS_async(cb, ssi1, ssi2)
750 cb.check()
753 # opByteSS
755 bsi1 = ((0x01, 0x11, 0x12), (0xff,))
756 bsi2 = ((0x0e,), (0xf2, 0xf1))
758 cb = AMI_MyClass_opByteSSI()
759 p.opByteSS_async(cb, bsi1, bsi2)
760 cb.check()
763 # opFloatDoubleSS
765 fsi = ((3.14,), (1.11,), ())
766 dsi = ((1.1E10, 1.2E10, 1.3E10),)
768 cb = AMI_MyClass_opFloatDoubleSSI()
769 p.opFloatDoubleSS_async(cb, fsi, dsi)
770 cb.check()
773 # opStringSS
775 ssi1 = (('abc',), ('de', 'fghi'))
776 ssi2 = ((), (), ('xyz',))
778 cb = AMI_MyClass_opStringSSI()
779 p.opStringSS_async(cb, ssi1, ssi2)
780 cb.check()
783 # opByteBoolD
785 di1 = {10: True, 100: False}
786 di2 = {10: True, 11: False, 101: True}
788 cb = AMI_MyClass_opByteBoolDI()
789 p.opByteBoolD_async(cb, di1, di2)
790 cb.check()
793 # opShortIntD
795 di1 = {110: -1, 1100: 123123}
796 di2 = {110: -1, 111: -100, 1101: 0}
798 cb = AMI_MyClass_opShortIntDI()
799 p.opShortIntD_async(cb, di1, di2)
800 cb.check()
803 # opLongFloatD
805 di1 = {999999110: -1.1, 999999111: 123123.2}
806 di2 = {999999110: -1.1, 999999120: -100.4, 999999130: 0.5}
808 cb = AMI_MyClass_opLongFloatDI()
809 p.opLongFloatD_async(cb, di1, di2)
810 cb.check()
813 # opStringStringD
815 di1 = {'foo': 'abc -1.1', 'bar': 'abc 123123.2'}
816 di2 = {'foo': 'abc -1.1', 'FOO': 'abc -100.4', 'BAR': 'abc 0.5'}
818 cb = AMI_MyClass_opStringStringDI()
819 p.opStringStringD_async(cb, di1, di2)
820 cb.check()
823 # opStringMyEnumD
825 di1 = {'abc': Test.MyEnum.enum1, '': Test.MyEnum.enum2}
826 di2 = {'abc': Test.MyEnum.enum1, 'qwerty': Test.MyEnum.enum3, 'Hello!!': Test.MyEnum.enum2}
828 cb = AMI_MyClass_opStringMyEnumDI()
829 p.opStringMyEnumD_async(cb, di1, di2)
830 cb.check()
833 # opMyEnumStringD
835 di1 = {Test.MyEnum.enum1: 'abc'}
836 di2 = {Test.MyEnum.enum2: 'Hello!!', Test.MyEnum.enum3: 'qwerty'}
838 cb = AMI_MyClass_opMyEnumStringDI()
839 p.opMyEnumStringD_async(cb, di1, di2)
840 cb.check()
843 # opMyStructMyEnumD
845 s11 = Test.MyStruct()
846 s11.i = 1
847 s11.j = 1
848 s12 = Test.MyStruct()
849 s12.i = 1
850 s12.j = 2
851 s22 = Test.MyStruct()
852 s22.i = 2
853 s22.j = 2
854 s23 = Test.MyStruct()
855 s23.i = 2
856 s23.j = 3
857 di1 = {s11: Test.MyEnum.enum1, s12: Test.MyEnum.enum2}
858 di2 = {s11: Test.MyEnum.enum1, s22: Test.MyEnum.enum3, s23: Test.MyEnum.enum2}
860 cb = AMI_MyClass_opMyStructMyEnumDI()
861 p.opMyStructMyEnumD_async(cb, di1, di2)
862 cb.check()
865 # opIntS
867 lengths = ( 0, 1, 2, 126, 127, 128, 129, 253, 254, 255, 256, 257, 1000 )
868 for l in lengths:
869 s = []
870 for i in range(l):
871 s.append(i)
872 cb = AMI_MyClass_opIntSI(l)
873 p.opIntS_async(cb, s)
874 cb.check()
877 # opContext
879 ctx = {'one': 'ONE', 'two': 'TWO', 'three': 'THREE'}
881 test(len(p.ice_getContext()) == 0)
882 cb = AMI_MyClass_opContextNotEqualI(ctx)
883 p.opContext_async(cb)
884 cb.check()
886 test(len(p.ice_getContext()) == 0)
887 cb = AMI_MyClass_opContextEqualI(ctx)
888 p.opContext_async(cb, ctx)
889 cb.check()
891 p2 = Test.MyClassPrx.checkedCast(p.ice_context(ctx))
892 test(p2.ice_getContext() == ctx)
893 cb = AMI_MyClass_opContextEqualI(ctx)
894 p2.opContext_async(cb)
895 cb.check()
897 p2 = Test.MyClassPrx.checkedCast(p.ice_context(ctx))
898 test(p2.ice_getContext() == ctx)
899 cb = AMI_MyClass_opContextEqualI(ctx)
900 p2.opContext_async(cb, ctx)
901 cb.check()
904 # Test implicit context propagation
906 impls = ( 'Shared', 'PerThread' )
907 for i in impls:
908 initData = Ice.InitializationData()
909 initData.properties = communicator.getProperties().clone()
910 initData.properties.setProperty('Ice.ImplicitContext', i)
911 ic = Ice.initialize(data=initData)
913 ctx = {'one': 'ONE', 'two': 'TWO', 'three': 'THREE'}
915 p3 = Test.MyClassPrx.uncheckedCast(ic.stringToProxy("test:default -p 12010"))
917 ic.getImplicitContext().setContext(ctx)
918 test(ic.getImplicitContext().getContext() == ctx)
920 cb = AMI_MyClass_opContextEqualI(ctx)
921 p3.opContext_async(cb)
922 cb.check()
924 ic.getImplicitContext().put('zero', 'ZERO')
925 ctx = ic.getImplicitContext().getContext()
927 cb = AMI_MyClass_opContextEqualI(ctx)
928 p3.opContext_async(cb)
929 cb.check()
931 prxContext = {'one': 'UN', 'four': 'QUATRE'}
933 combined = ctx
934 combined.update(prxContext)
935 test(combined['one'] == 'UN')
937 p3 = Test.MyClassPrx.uncheckedCast(p3.ice_context(prxContext))
938 ic.getImplicitContext().setContext({})
940 cb = AMI_MyClass_opContextEqualI(prxContext)
941 p3.opContext_async(cb)
942 cb.check()
944 ic.getImplicitContext().setContext(ctx)
946 cb = AMI_MyClass_opContextEqualI(combined)
947 p3.opContext_async(cb)
948 cb.check()
950 ic.destroy()
953 # opIdempotent
955 cb = AMI_MyClass_opIdempotentI()
956 p.opIdempotent_async(cb)
957 cb.check()
960 # opNonmutating
962 cb = AMI_MyClass_opNonmutatingI()
963 p.opNonmutating_async(cb)
964 cb.check()
966 derived = Test.MyDerivedClassPrx.checkedCast(p)
967 test(derived)
968 cb = AMI_MyDerivedClass_opDerivedI()
969 derived.opDerived_async(cb)
970 cb.check()