~ubuntu-branches/ubuntu/quantal/zeroc-ice/quantal

« back to all changes in this revision

Viewing changes to py/test/Ice/operations/TwowaysAMI.py

  • Committer: Bazaar Package Importer
  • Author(s): Cleto Martin Angelina
  • Date: 2011-04-25 18:44:24 UTC
  • mfrom: (6.1.14 sid)
  • Revision ID: james.westby@ubuntu.com-20110425184424-sep9i9euu434vq4c
Tags: 3.4.1-7
* Bug fix: "libdb5.1-java.jar was renamed to db.jar", thanks to Ondřej
  Surý (Closes: #623555).
* Bug fix: "causes noise in php5", thanks to Jayen Ashar (Closes:
  #623533).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# **********************************************************************
2
2
#
3
 
# Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved.
 
3
# Copyright (c) 2003-2010 ZeroC, Inc. All rights reserved.
4
4
#
5
5
# This copy of Ice is licensed to you under the terms described in the
6
6
# ICE_LICENSE file included in this distribution.
22
22
        self._cond.acquire()
23
23
        try:
24
24
            while not self._called:
25
 
                self._cond.wait(5.0)
26
 
            if self._called:
27
 
                self._called = False
28
 
                return True
29
 
            else:
30
 
                return False
 
25
                self._cond.wait()
 
26
            self._called = False
31
27
        finally:
32
28
            self._cond.release()
33
29
 
171
167
 
172
168
    def __init__(self, communicator):
173
169
        CallbackBase.__init__(self)
174
 
        self._communicator = communicator                      
175
 
    
 
170
        self._communicator = communicator
 
171
 
176
172
    def ice_response(self, rso, so):
177
173
        test(rso.p == None)
178
174
        test(rso.e == Test.MyEnum.enum2)
472
468
    def ice_exception(self, ex):
473
469
        test(False)
474
470
 
 
471
class AMI_MyClass_opMyEnumStringDI(CallbackBase):
 
472
    def __init__(self):
 
473
        CallbackBase.__init__(self)
 
474
 
 
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()
 
483
 
 
484
    def ice_exception(self, ex):
 
485
        test(False)
 
486
 
475
487
class AMI_MyClass_opMyStructMyEnumDI(CallbackBase):
476
488
    def __init__(self):
477
489
        CallbackBase.__init__(self)
558
570
        test(not indirect.opVoid_async(cb))
559
571
    except Ice.Exception:
560
572
        test(False)
561
 
    test(cb.check())
 
573
    cb.check()
562
574
 
563
575
    # Check that a call to a twoway operation raises NoEndpointException
564
576
    # in the ice_exception() callback instead of at the point of call.
568
580
        test(not indirect.opByte_async(cb, 0, 0))
569
581
    except Ice.Exception:
570
582
        test(False)
571
 
    test(cb.check())
 
583
    cb.check()
572
584
 
573
585
    #
574
586
    # opVoid
575
587
    #
576
588
    cb = AMI_MyClass_opVoidI()
577
589
    p.opVoid_async(cb)
578
 
    test(cb.check())
 
590
    cb.check()
579
591
    # Let's check if we can reuse the same callback object for another call.
580
592
    p.opVoid_async(cb)
581
 
    test(cb.check())
 
593
    cb.check()
582
594
 
583
595
    # Check that CommunicatorDestroyedException is raised directly.
584
596
    initData = Ice.InitializationData()
601
613
    #
602
614
    cb = AMI_MyClass_opByteI()
603
615
    p.opByte_async(cb, 0xff, 0x0f)
604
 
    test(cb.check())
 
616
    cb.check()
605
617
 
606
618
    #
607
619
    # opBool
608
620
    #
609
621
    cb = AMI_MyClass_opBoolI()
610
622
    p.opBool_async(cb, True, False)
611
 
    test(cb.check())
 
623
    cb.check()
612
624
 
613
625
    #
614
626
    # opShortIntLong
615
627
    #
616
628
    cb = AMI_MyClass_opShortIntLongI()
617
629
    p.opShortIntLong_async(cb, 10, 11, 12)
618
 
    test(cb.check())
 
630
    cb.check()
619
631
 
620
632
    #
621
633
    # opFloatDouble
622
634
    #
623
635
    cb = AMI_MyClass_opFloatDoubleI()
624
636
    p.opFloatDouble_async(cb, 3.14, 1.1E10)
625
 
    test(cb.check())
 
637
    cb.check()
626
638
    # Let's check if we can reuse the same callback object for another call.
627
639
    p.opFloatDouble_async(cb, 3.14, 1.1E10)
628
 
    test(cb.check())
 
640
    cb.check()
629
641
 
630
642
    #
631
643
    # opString
632
644
    #
633
645
    cb = AMI_MyClass_opStringI()
634
646
    p.opString_async(cb, "hello", "world")
635
 
    test(cb.check())
 
647
    cb.check()
636
648
 
637
649
    #
638
650
    # opMyEnum
639
651
    #
640
652
    cb = AMI_MyClass_opMyEnumI()
641
653
    p.opMyEnum_async(cb, Test.MyEnum.enum2)
642
 
    test(cb.check())
 
654
    cb.check()
643
655
 
644
656
    #
645
657
    # opMyClass
646
658
    #
647
659
    cb = AMI_MyClass_opMyClassI(communicator)
648
660
    p.opMyClass_async(cb, p)
649
 
    test(cb.check())
 
661
    cb.check()
650
662
 
651
663
    #
652
664
    # opStruct
664
676
 
665
677
    cb = AMI_MyClass_opStructI(communicator)
666
678
    p.opStruct_async(cb, si1, si2)
667
 
    test(cb.check())
 
679
    cb.check()
668
680
 
669
681
    #
670
682
    # opByteS
674
686
 
675
687
    cb = AMI_MyClass_opByteSI()
676
688
    p.opByteS_async(cb, bsi1, bsi2)
677
 
    test(cb.check())
 
689
    cb.check()
678
690
 
679
691
    #
680
692
    # opBoolS
684
696
 
685
697
    cb = AMI_MyClass_opBoolSI()
686
698
    p.opBoolS_async(cb, bsi1, bsi2)
687
 
    test(cb.check())
 
699
    cb.check()
688
700
 
689
701
    #
690
702
    # opShortIntLongS
695
707
 
696
708
    cb = AMI_MyClass_opShortIntLongSI()
697
709
    p.opShortIntLongS_async(cb, ssi, isi, lsi)
698
 
    test(cb.check())
 
710
    cb.check()
699
711
 
700
712
    #
701
713
    # opFloatDoubleS
705
717
 
706
718
    cb = AMI_MyClass_opFloatDoubleSI()
707
719
    p.opFloatDoubleS_async(cb, fsi, dsi)
708
 
    test(cb.check())
 
720
    cb.check()
709
721
 
710
722
    #
711
723
    # opStringS
715
727
 
716
728
    cb = AMI_MyClass_opStringSI()
717
729
    p.opStringS_async(cb, ssi1, ssi2)
718
 
    test(cb.check())
 
730
    cb.check()
719
731
 
720
732
    #
721
733
    # opByteSS
725
737
 
726
738
    cb = AMI_MyClass_opByteSSI()
727
739
    p.opByteSS_async(cb, bsi1, bsi2)
728
 
    test(cb.check())
 
740
    cb.check()
729
741
 
730
742
    #
731
743
    # opFloatDoubleSS
735
747
 
736
748
    cb = AMI_MyClass_opFloatDoubleSSI()
737
749
    p.opFloatDoubleSS_async(cb, fsi, dsi)
738
 
    test(cb.check())
 
750
    cb.check()
739
751
 
740
752
    #
741
753
    # opStringSS
745
757
 
746
758
    cb = AMI_MyClass_opStringSSI()
747
759
    p.opStringSS_async(cb, ssi1, ssi2)
748
 
    test(cb.check())
 
760
    cb.check()
749
761
 
750
762
    #
751
763
    # opByteBoolD
755
767
 
756
768
    cb = AMI_MyClass_opByteBoolDI()
757
769
    p.opByteBoolD_async(cb, di1, di2)
758
 
    test(cb.check())
 
770
    cb.check()
759
771
 
760
772
    #
761
773
    # opShortIntD
765
777
 
766
778
    cb = AMI_MyClass_opShortIntDI()
767
779
    p.opShortIntD_async(cb, di1, di2)
768
 
    test(cb.check())
 
780
    cb.check()
769
781
 
770
782
    #
771
783
    # opLongFloatD
775
787
 
776
788
    cb = AMI_MyClass_opLongFloatDI()
777
789
    p.opLongFloatD_async(cb, di1, di2)
778
 
    test(cb.check())
 
790
    cb.check()
779
791
 
780
792
    #
781
793
    # opStringStringD
785
797
 
786
798
    cb = AMI_MyClass_opStringStringDI()
787
799
    p.opStringStringD_async(cb, di1, di2)
788
 
    test(cb.check())
 
800
    cb.check()
789
801
 
790
802
    #
791
803
    # opStringMyEnumD
795
807
 
796
808
    cb = AMI_MyClass_opStringMyEnumDI()
797
809
    p.opStringMyEnumD_async(cb, di1, di2)
798
 
    test(cb.check())
 
810
    cb.check()
 
811
 
 
812
    #
 
813
    # opMyEnumStringD
 
814
    #
 
815
    di1 = {Test.MyEnum.enum1: 'abc'}
 
816
    di2 = {Test.MyEnum.enum2: 'Hello!!', Test.MyEnum.enum3: 'qwerty'}
 
817
 
 
818
    cb = AMI_MyClass_opMyEnumStringDI()
 
819
    p.opMyEnumStringD_async(cb, di1, di2)
 
820
    cb.check()
799
821
 
800
822
    #
801
823
    # opMyStructMyEnumD
817
839
 
818
840
    cb = AMI_MyClass_opMyStructMyEnumDI()
819
841
    p.opMyStructMyEnumD_async(cb, di1, di2)
820
 
    test(cb.check())
 
842
    cb.check()
821
843
 
822
844
    #
823
845
    # opIntS
829
851
            s.append(i)
830
852
        cb = AMI_MyClass_opIntSI(l)
831
853
        p.opIntS_async(cb, s)
832
 
        test(cb.check())
 
854
        cb.check()
833
855
 
834
856
    #
835
857
    # opContext
839
861
    test(len(p.ice_getContext()) == 0)
840
862
    cb = AMI_MyClass_opContextNotEqualI(ctx)
841
863
    p.opContext_async(cb)
842
 
    test(cb.check())
 
864
    cb.check()
843
865
 
844
866
    test(len(p.ice_getContext()) == 0)
845
867
    cb = AMI_MyClass_opContextEqualI(ctx)
846
868
    p.opContext_async(cb, ctx)
847
 
    test(cb.check())
 
869
    cb.check()
848
870
 
849
871
    p2 = Test.MyClassPrx.checkedCast(p.ice_context(ctx))
850
872
    test(p2.ice_getContext() == ctx)
851
873
    cb = AMI_MyClass_opContextEqualI(ctx)
852
874
    p2.opContext_async(cb)
853
 
    test(cb.check())
 
875
    cb.check()
854
876
 
855
877
    p2 = Test.MyClassPrx.checkedCast(p.ice_context(ctx))
856
878
    test(p2.ice_getContext() == ctx)
857
879
    cb = AMI_MyClass_opContextEqualI(ctx)
858
880
    p2.opContext_async(cb, ctx)
859
 
    test(cb.check())
860
 
 
861
 
    derived = Test.MyDerivedClassPrx.checkedCast(p)
862
 
    test(derived)
863
 
    cb = AMI_MyDerivedClass_opDerivedI()
864
 
    derived.opDerived_async(cb)
865
 
    test(cb.check())
866
 
 
867
 
    #
868
 
    # Test that default context is obtained correctly from communicator.
869
 
    #
870
 
# DEPRECATED
871
 
#    dflt = {'a': 'b'}
872
 
#    communicator.setDefaultContext(dflt)
873
 
#    cb = AMI_MyClass_opContextNotEqualI(dflt)
874
 
#    p.opContext_async(cb)
875
 
#    test(cb.check())
876
 
#
877
 
#    p2 = Test.MyClassPrx.uncheckedCast(p.ice_context({}))
878
 
#    cb = AMI_MyClass_opContextEqualI({})
879
 
#    p2.opContext_async(cb)
880
 
#    test(cb.check())
881
 
#
882
 
#    p2 = Test.MyClassPrx.uncheckedCast(p.ice_defaultContext())
883
 
#    cb = AMI_MyClass_opContextEqualI(dflt)
884
 
#    p2.opContext_async(cb)
885
 
#    test(cb.check())
886
 
#
887
 
#    communicator.setDefaultContext({})
888
 
#    cb = AMI_MyClass_opContextNotEqualI({})
889
 
#    p2.opContext_async(cb)
890
 
#    test(cb.check())
891
 
#
892
 
#    communicator.setDefaultContext(dflt)
893
 
#    c = Test.MyClassPrx.checkedCast(communicator.stringToProxy("test:default -p 12010 -t 10000"))
894
 
#    cb = AMI_MyClass_opContextEqualI({'a': 'b'})
895
 
#    c.opContext_async(cb)
896
 
#    test(cb.check())
897
 
#
898
 
#    dflt['a'] = 'c'
899
 
#    c2 = Test.MyClassPrx.uncheckedCast(c.ice_context(dflt))
900
 
#    cb = AMI_MyClass_opContextEqualI({'a': 'c'})
901
 
#    c2.opContext_async(cb)
902
 
#    test(cb.check())
903
 
#
904
 
#    dflt = {}
905
 
#    c3 = Test.MyClassPrx.uncheckedCast(c2.ice_context(dflt))
906
 
#    cb = AMI_MyClass_opContextEqualI({})
907
 
#    c3.opContext_async(cb)
908
 
#    test(cb.check())
909
 
#
910
 
#    c4 = Test.MyClassPrx.uncheckedCast(c2.ice_defaultContext())
911
 
#    cb = AMI_MyClass_opContextEqualI({'a': 'b'})
912
 
#    c4.opContext_async(cb)
913
 
#    test(cb.check())
914
 
#
915
 
#    dflt['a'] = 'd'
916
 
#    communicator.setDefaultContext(dflt)
917
 
#
918
 
#    c5 = Test.MyClassPrx.uncheckedCast(c.ice_defaultContext())
919
 
#    cb = AMI_MyClass_opContextEqualI({'a': 'd'})
920
 
#    c5.opContext_async(cb)
921
 
#    test(cb.check())
922
 
#
923
 
#    communicator.setDefaultContext({})
 
881
    cb.check()
924
882
 
925
883
    #
926
884
    # Test implicit context propagation
931
889
        initData.properties = communicator.getProperties().clone()
932
890
        initData.properties.setProperty('Ice.ImplicitContext', i)
933
891
        ic = Ice.initialize(data=initData)
934
 
        
 
892
 
935
893
        ctx = {'one': 'ONE', 'two': 'TWO', 'three': 'THREE'}
936
 
        
937
 
        p = Test.MyClassPrx.uncheckedCast(ic.stringToProxy("test:default -p 12010 -t 10000"))
938
 
        
 
894
 
 
895
        p3 = Test.MyClassPrx.uncheckedCast(ic.stringToProxy("test:default -p 12010"))
 
896
 
939
897
        ic.getImplicitContext().setContext(ctx)
940
898
        test(ic.getImplicitContext().getContext() == ctx)
941
899
 
942
900
        cb = AMI_MyClass_opContextEqualI(ctx)
943
 
        p.opContext_async(cb)
944
 
        test(cb.check())
945
 
        
 
901
        p3.opContext_async(cb)
 
902
        cb.check()
 
903
 
946
904
        ic.getImplicitContext().put('zero', 'ZERO')
947
905
        ctx = ic.getImplicitContext().getContext()
948
906
 
949
907
        cb = AMI_MyClass_opContextEqualI(ctx)
950
 
        p.opContext_async(cb)
951
 
        test(cb.check())
952
 
        
 
908
        p3.opContext_async(cb)
 
909
        cb.check()
 
910
 
953
911
        prxContext = {'one': 'UN', 'four': 'QUATRE'}
954
 
        
 
912
 
955
913
        combined = ctx
956
914
        combined.update(prxContext)
957
915
        test(combined['one'] == 'UN')
958
 
        
959
 
        p = Test.MyClassPrx.uncheckedCast(p.ice_context(prxContext))
 
916
 
 
917
        p3 = Test.MyClassPrx.uncheckedCast(p3.ice_context(prxContext))
960
918
        ic.getImplicitContext().setContext({})
961
919
 
962
920
        cb = AMI_MyClass_opContextEqualI(prxContext)
963
 
        p.opContext_async(cb)
964
 
        test(cb.check())
965
 
       
 
921
        p3.opContext_async(cb)
 
922
        cb.check()
 
923
 
966
924
        ic.getImplicitContext().setContext(ctx)
967
925
 
968
926
        cb = AMI_MyClass_opContextEqualI(combined)
969
 
        p.opContext_async(cb)
970
 
        test(cb.check())
 
927
        p3.opContext_async(cb)
 
928
        cb.check()
971
929
 
972
930
        ic.destroy()
 
931
 
 
932
    derived = Test.MyDerivedClassPrx.checkedCast(p)
 
933
    test(derived)
 
934
    cb = AMI_MyDerivedClass_opDerivedI()
 
935
    derived.opDerived_async(cb)
 
936
    cb.check()