ICE 3.4.2
[php5-ice-freebsdport.git] / java / test / Ice / slicing / exceptions / AllTests.java
blob507616490c10fe1e027eadac7ed87a2aae5d43d3
1 // **********************************************************************
2 //
3 // Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
4 //
5 // This copy of Ice is licensed to you under the terms described in the
6 // ICE_LICENSE file included in this distribution.
7 //
8 // **********************************************************************
10 package test.Ice.slicing.exceptions;
12 import test.Ice.slicing.exceptions.Test.Callback_TestIntf_baseAsBase;
13 import test.Ice.slicing.exceptions.Test.Callback_TestIntf_knownDerivedAsBase;
14 import test.Ice.slicing.exceptions.Test.Callback_TestIntf_knownDerivedAsKnownDerived;
15 import test.Ice.slicing.exceptions.Test.Callback_TestIntf_knownIntermediateAsBase;
16 import test.Ice.slicing.exceptions.Test.Callback_TestIntf_knownIntermediateAsKnownIntermediate;
17 import test.Ice.slicing.exceptions.Test.Callback_TestIntf_knownMostDerivedAsBase;
18 import test.Ice.slicing.exceptions.Test.Callback_TestIntf_knownMostDerivedAsKnownIntermediate;
19 import test.Ice.slicing.exceptions.Test.Callback_TestIntf_knownMostDerivedAsKnownMostDerived;
20 import test.Ice.slicing.exceptions.Test.Callback_TestIntf_unknownDerivedAsBase;
21 import test.Ice.slicing.exceptions.Test.Callback_TestIntf_unknownIntermediateAsBase;
22 import test.Ice.slicing.exceptions.Test.Callback_TestIntf_unknownMostDerived1AsBase;
23 import test.Ice.slicing.exceptions.Test.Callback_TestIntf_unknownMostDerived1AsKnownIntermediate;
24 import test.Ice.slicing.exceptions.Test.Callback_TestIntf_unknownMostDerived2AsBase;
25 import test.Ice.slicing.exceptions.Test.Base;
26 import test.Ice.slicing.exceptions.Test.KnownDerived;
27 import test.Ice.slicing.exceptions.Test.KnownIntermediate;
28 import test.Ice.slicing.exceptions.Test.KnownMostDerived;
29 import test.Ice.slicing.exceptions.Test.TestIntfPrx;
30 import test.Ice.slicing.exceptions.Test.TestIntfPrxHelper;
32 public class AllTests
34 private static void
35 test(boolean b)
37 if(!b)
39 throw new RuntimeException();
43 private static class Callback
45 Callback()
47 _called = false;
50 public synchronized void
51 check()
53 while(!_called)
55 try
57 wait();
59 catch(InterruptedException ex)
64 _called = false;
67 public synchronized void
68 called()
70 assert(!_called);
71 _called = true;
72 notify();
75 private boolean _called;
78 private static class Callback_TestIntf_baseAsBaseI extends Callback_TestIntf_baseAsBase
80 public void
81 response()
83 test(false);
86 public void
87 exception(Ice.LocalException exc)
89 test(false);
92 public void
93 exception(Ice.UserException exc)
95 try
97 throw exc;
99 catch(Base b)
101 test(b.b.equals("Base.b"));
102 test(b.ice_name().equals("Test::Base"));
104 catch(Exception ex)
106 test(false);
108 callback.called();
111 public void
112 check()
114 callback.check();
117 private Callback callback = new Callback();
120 private static class Callback_TestIntf_unknownDerivedAsBaseI extends Callback_TestIntf_unknownDerivedAsBase
122 public void
123 response()
125 test(false);
128 public void
129 exception(Ice.LocalException exc)
131 test(false);
134 public void
135 exception(Ice.UserException exc)
139 throw exc;
141 catch(Base b)
143 test(b.b.equals("UnknownDerived.b"));
144 test(b.ice_name().equals("Test::Base"));
146 catch(Exception ex)
148 test(false);
150 callback.called();
153 public void
154 check()
156 callback.check();
159 private Callback callback = new Callback();
162 private static class Callback_TestIntf_knownDerivedAsBaseI extends Callback_TestIntf_knownDerivedAsBase
164 public void
165 response()
167 test(false);
170 public void
171 exception(Ice.LocalException exc)
173 test(false);
176 public void
177 exception(Ice.UserException exc)
181 throw exc;
183 catch(KnownDerived k)
185 test(k.b.equals("KnownDerived.b"));
186 test(k.kd.equals("KnownDerived.kd"));
187 test(k.ice_name().equals("Test::KnownDerived"));
189 catch(Exception ex)
191 test(false);
193 callback.called();
196 public void
197 check()
199 callback.check();
202 private Callback callback = new Callback();
205 private static class Callback_TestIntf_knownDerivedAsKnownDerivedI
206 extends Callback_TestIntf_knownDerivedAsKnownDerived
208 public void
209 response()
211 test(false);
214 public void
215 exception(Ice.LocalException exc)
217 test(false);
220 public void
221 exception(Ice.UserException exc)
225 throw exc;
227 catch(KnownDerived k)
229 test(k.b.equals("KnownDerived.b"));
230 test(k.kd.equals("KnownDerived.kd"));
231 test(k.ice_name().equals("Test::KnownDerived"));
233 catch(Exception ex)
235 test(false);
237 callback.called();
240 public void
241 check()
243 callback.check();
246 private Callback callback = new Callback();
249 private static class Callback_TestIntf_unknownIntermediateAsBaseI
250 extends Callback_TestIntf_unknownIntermediateAsBase
252 public void
253 response()
255 test(false);
258 public void
259 exception(Ice.LocalException exc)
261 test(false);
264 public void
265 exception(Ice.UserException exc)
269 throw exc;
271 catch(Base b)
273 test(b.b.equals("UnknownIntermediate.b"));
274 test(b.ice_name().equals("Test::Base"));
276 catch(Exception ex)
278 test(false);
280 callback.called();
283 public void
284 check()
286 callback.check();
289 private Callback callback = new Callback();
292 private static class Callback_TestIntf_knownIntermediateAsBaseI extends Callback_TestIntf_knownIntermediateAsBase
294 public void
295 response()
297 test(false);
300 public void
301 exception(Ice.LocalException exc)
303 test(false);
306 public void
307 exception(Ice.UserException exc)
311 throw exc;
313 catch(KnownIntermediate ki)
315 test(ki.b.equals("KnownIntermediate.b"));
316 test(ki.ki.equals("KnownIntermediate.ki"));
317 test(ki.ice_name().equals("Test::KnownIntermediate"));
319 catch(Exception ex)
321 test(false);
323 callback.called();
326 public void
327 check()
329 callback.check();
332 private Callback callback = new Callback();
335 private static class Callback_TestIntf_knownMostDerivedAsBaseI extends Callback_TestIntf_knownMostDerivedAsBase
337 public void
338 response()
340 test(false);
343 public void
344 exception(Ice.LocalException exc)
346 test(false);
349 public void
350 exception(Ice.UserException exc)
354 throw exc;
356 catch(KnownMostDerived kmd)
358 test(kmd.b.equals("KnownMostDerived.b"));
359 test(kmd.ki.equals("KnownMostDerived.ki"));
360 test(kmd.kmd.equals("KnownMostDerived.kmd"));
361 test(kmd.ice_name().equals("Test::KnownMostDerived"));
363 catch(Exception ex)
365 test(false);
367 callback.called();
370 public void
371 check()
373 callback.check();
376 private Callback callback = new Callback();
379 private static class Callback_TestIntf_knownIntermediateAsKnownIntermediateI
380 extends Callback_TestIntf_knownIntermediateAsKnownIntermediate
382 public void
383 response()
385 test(false);
388 public void
389 exception(Ice.LocalException exc)
391 test(false);
394 public void
395 exception(Ice.UserException exc)
399 throw exc;
401 catch(KnownIntermediate ki)
403 test(ki.b.equals("KnownIntermediate.b"));
404 test(ki.ki.equals("KnownIntermediate.ki"));
405 test(ki.ice_name().equals("Test::KnownIntermediate"));
407 catch(Exception ex)
409 test(false);
411 callback.called();
414 public void
415 check()
417 callback.check();
420 private Callback callback = new Callback();
423 private static class Callback_TestIntf_knownMostDerivedAsKnownIntermediateI
424 extends Callback_TestIntf_knownMostDerivedAsKnownIntermediate
426 public void
427 response()
429 test(false);
432 public void
433 exception(Ice.LocalException exc)
435 test(false);
438 public void
439 exception(Ice.UserException exc)
443 throw exc;
445 catch(KnownMostDerived kmd)
447 test(kmd.b.equals("KnownMostDerived.b"));
448 test(kmd.ki.equals("KnownMostDerived.ki"));
449 test(kmd.kmd.equals("KnownMostDerived.kmd"));
450 test(kmd.ice_name().equals("Test::KnownMostDerived"));
452 catch(Exception ex)
454 test(false);
456 callback.called();
459 public void
460 check()
462 callback.check();
465 private Callback callback = new Callback();
468 private static class Callback_TestIntf_knownMostDerivedAsKnownMostDerivedI
469 extends Callback_TestIntf_knownMostDerivedAsKnownMostDerived
471 public void
472 response()
474 test(false);
477 public void
478 exception(Ice.LocalException exc)
480 test(false);
483 public void
484 exception(Ice.UserException exc)
488 throw exc;
490 catch(KnownMostDerived kmd)
492 test(kmd.b.equals("KnownMostDerived.b"));
493 test(kmd.ki.equals("KnownMostDerived.ki"));
494 test(kmd.kmd.equals("KnownMostDerived.kmd"));
495 test(kmd.ice_name().equals("Test::KnownMostDerived"));
497 catch(Exception ex)
499 test(false);
501 callback.called();
504 public void
505 check()
507 callback.check();
510 private Callback callback = new Callback();
513 private static class Callback_TestIntf_unknownMostDerived1AsBaseI
514 extends Callback_TestIntf_unknownMostDerived1AsBase
516 public void
517 response()
519 test(false);
522 public void
523 exception(Ice.LocalException exc)
525 test(false);
528 public void
529 exception(Ice.UserException exc)
533 throw exc;
535 catch(KnownIntermediate ki)
537 test(ki.b.equals("UnknownMostDerived1.b"));
538 test(ki.ki.equals("UnknownMostDerived1.ki"));
539 test(ki.ice_name().equals("Test::KnownIntermediate"));
541 catch(Exception ex)
543 test(false);
545 callback.called();
548 public void
549 check()
551 callback.check();
554 private Callback callback = new Callback();
557 private static class Callback_TestIntf_unknownMostDerived1AsKnownIntermediateI
558 extends Callback_TestIntf_unknownMostDerived1AsKnownIntermediate
560 public void
561 response()
563 test(false);
566 public void
567 exception(Ice.LocalException exc)
569 test(false);
572 public void
573 exception(Ice.UserException exc)
577 throw exc;
579 catch(KnownIntermediate ki)
581 test(ki.b.equals("UnknownMostDerived1.b"));
582 test(ki.ki.equals("UnknownMostDerived1.ki"));
583 test(ki.ice_name().equals("Test::KnownIntermediate"));
585 catch(Exception ex)
587 test(false);
589 callback.called();
592 public void
593 check()
595 callback.check();
598 private Callback callback = new Callback();
601 private static class Callback_TestIntf_unknownMostDerived2AsBaseI
602 extends Callback_TestIntf_unknownMostDerived2AsBase
604 public void
605 response()
607 test(false);
610 public void
611 exception(Ice.LocalException exc)
613 test(false);
616 public void
617 exception(Ice.UserException exc)
621 throw exc;
623 catch(Base b)
625 test(b.b.equals("UnknownMostDerived2.b"));
626 test(b.ice_name().equals("Test::Base"));
628 catch(Exception ex)
630 test(false);
632 callback.called();
635 public void
636 check()
638 callback.check();
641 private Callback callback = new Callback();
644 public static TestIntfPrx
645 allTests(Ice.Communicator communicator, boolean collocated, java.io.PrintWriter out)
647 out.print("testing stringToProxy... ");
648 out.flush();
649 String ref = "Test:default -p 12010 -t 10000";
650 Ice.ObjectPrx base = communicator.stringToProxy(ref);
651 test(base != null);
652 out.println("ok");
654 out.print("testing checked cast... ");
655 out.flush();
656 TestIntfPrx test = TestIntfPrxHelper.checkedCast(base);
657 test(test != null);
658 test(test.equals(base));
659 out.println("ok");
661 out.print("base... ");
662 out.flush();
666 test.baseAsBase();
667 test(false);
669 catch(Base b)
671 test(b.b.equals("Base.b"));
672 test(b.ice_name().equals("Test::Base"));
674 catch(Exception ex)
676 test(false);
679 out.println("ok");
681 out.print("base (AMI)... ");
682 out.flush();
684 Callback_TestIntf_baseAsBaseI cb = new Callback_TestIntf_baseAsBaseI();
685 test.begin_baseAsBase(cb);
686 cb.check();
688 out.println("ok");
690 out.print("slicing of unknown derived... ");
691 out.flush();
695 test.unknownDerivedAsBase();
696 test(false);
698 catch(Base b)
700 test(b.b.equals("UnknownDerived.b"));
701 test(b.ice_name().equals("Test::Base"));
703 catch(Exception ex)
705 test(false);
708 out.println("ok");
710 out.print("slicing of unknown derived (AMI)... ");
711 out.flush();
713 Callback_TestIntf_unknownDerivedAsBaseI cb = new Callback_TestIntf_unknownDerivedAsBaseI();
714 test.begin_unknownDerivedAsBase(cb);
715 cb.check();
717 out.println("ok");
719 out.print("non-slicing of known derived as base... ");
720 out.flush();
724 test.knownDerivedAsBase();
725 test(false);
727 catch(KnownDerived k)
729 test(k.b.equals("KnownDerived.b"));
730 test(k.kd.equals("KnownDerived.kd"));
731 test(k.ice_name().equals("Test::KnownDerived"));
733 catch(Exception ex)
735 test(false);
738 out.println("ok");
740 out.print("non-slicing of known derived as base (AMI)... ");
741 out.flush();
743 Callback_TestIntf_knownDerivedAsBaseI cb = new Callback_TestIntf_knownDerivedAsBaseI();
744 test.begin_knownDerivedAsBase(cb);
745 cb.check();
747 out.println("ok");
749 out.print("non-slicing of known derived as derived... ");
750 out.flush();
754 test.knownDerivedAsKnownDerived();
755 test(false);
757 catch(KnownDerived k)
759 test(k.b.equals("KnownDerived.b"));
760 test(k.kd.equals("KnownDerived.kd"));
761 test(k.ice_name().equals("Test::KnownDerived"));
763 catch(Exception ex)
765 test(false);
768 out.println("ok");
770 out.print("non-slicing of known derived as derived (AMI)... ");
771 out.flush();
773 Callback_TestIntf_knownDerivedAsKnownDerivedI cb = new Callback_TestIntf_knownDerivedAsKnownDerivedI();
774 test.begin_knownDerivedAsKnownDerived(cb);
775 cb.check();
777 out.println("ok");
779 out.print("slicing of unknown intermediate as base... ");
780 out.flush();
784 test.unknownIntermediateAsBase();
785 test(false);
787 catch(Base b)
789 test(b.b.equals("UnknownIntermediate.b"));
790 test(b.ice_name().equals("Test::Base"));
792 catch(Exception ex)
794 test(false);
797 out.println("ok");
799 out.print("slicing of unknown intermediate as base (AMI)... ");
800 out.flush();
802 Callback_TestIntf_unknownIntermediateAsBaseI cb = new Callback_TestIntf_unknownIntermediateAsBaseI();
803 test.begin_unknownIntermediateAsBase(cb);
804 cb.check();
806 out.println("ok");
808 out.print("slicing of known intermediate as base... ");
809 out.flush();
813 test.knownIntermediateAsBase();
814 test(false);
816 catch(KnownIntermediate ki)
818 test(ki.b.equals("KnownIntermediate.b"));
819 test(ki.ki.equals("KnownIntermediate.ki"));
820 test(ki.ice_name().equals("Test::KnownIntermediate"));
822 catch(Exception ex)
824 test(false);
827 out.println("ok");
829 out.print("slicing of known intermediate as base (AMI)... ");
830 out.flush();
832 Callback_TestIntf_knownIntermediateAsBaseI cb = new Callback_TestIntf_knownIntermediateAsBaseI();
833 test.begin_knownIntermediateAsBase(cb);
834 cb.check();
836 out.println("ok");
838 out.print("slicing of known most derived as base... ");
839 out.flush();
843 test.knownMostDerivedAsBase();
844 test(false);
846 catch(KnownMostDerived kmd)
848 test(kmd.b.equals("KnownMostDerived.b"));
849 test(kmd.ki.equals("KnownMostDerived.ki"));
850 test(kmd.kmd.equals("KnownMostDerived.kmd"));
851 test(kmd.ice_name().equals("Test::KnownMostDerived"));
853 catch(Exception ex)
855 test(false);
858 out.println("ok");
860 out.print("slicing of known most derived as base (AMI)... ");
861 out.flush();
863 Callback_TestIntf_knownMostDerivedAsBaseI cb = new Callback_TestIntf_knownMostDerivedAsBaseI();
864 test.begin_knownMostDerivedAsBase(cb);
865 cb.check();
867 out.println("ok");
869 out.print("non-slicing of known intermediate as intermediate... ");
870 out.flush();
874 test.knownIntermediateAsKnownIntermediate();
875 test(false);
877 catch(KnownIntermediate ki)
879 test(ki.b.equals("KnownIntermediate.b"));
880 test(ki.ki.equals("KnownIntermediate.ki"));
881 test(ki.ice_name().equals("Test::KnownIntermediate"));
883 catch(Exception ex)
885 test(false);
888 out.println("ok");
890 out.print("non-slicing of known intermediate as intermediate (AMI)... ");
891 out.flush();
893 Callback_TestIntf_knownIntermediateAsKnownIntermediateI cb =
894 new Callback_TestIntf_knownIntermediateAsKnownIntermediateI();
895 test.begin_knownIntermediateAsKnownIntermediate(cb);
896 cb.check();
898 out.println("ok");
900 out.print("non-slicing of known most derived as intermediate... ");
901 out.flush();
905 test.knownMostDerivedAsKnownIntermediate();
906 test(false);
908 catch(KnownMostDerived kmd)
910 test(kmd.b.equals("KnownMostDerived.b"));
911 test(kmd.ki.equals("KnownMostDerived.ki"));
912 test(kmd.kmd.equals("KnownMostDerived.kmd"));
913 test(kmd.ice_name().equals("Test::KnownMostDerived"));
915 catch(Exception ex)
917 test(false);
920 out.println("ok");
922 out.print("non-slicing of known most derived as intermediate (AMI)... ");
923 out.flush();
925 Callback_TestIntf_knownMostDerivedAsKnownIntermediateI cb =
926 new Callback_TestIntf_knownMostDerivedAsKnownIntermediateI();
927 test.begin_knownMostDerivedAsKnownIntermediate(cb);
928 cb.check();
930 out.println("ok");
932 out.print("non-slicing of known most derived as most derived... ");
933 out.flush();
937 test.knownMostDerivedAsKnownMostDerived();
938 test(false);
940 catch(KnownMostDerived kmd)
942 test(kmd.b.equals("KnownMostDerived.b"));
943 test(kmd.ki.equals("KnownMostDerived.ki"));
944 test(kmd.kmd.equals("KnownMostDerived.kmd"));
945 test(kmd.ice_name().equals("Test::KnownMostDerived"));
947 catch(Exception ex)
949 test(false);
952 out.println("ok");
954 out.print("non-slicing of known most derived as most derived (AMI)... ");
955 out.flush();
957 Callback_TestIntf_knownMostDerivedAsKnownMostDerivedI cb =
958 new Callback_TestIntf_knownMostDerivedAsKnownMostDerivedI();
959 test.begin_knownMostDerivedAsKnownMostDerived(cb);
960 cb.check();
962 out.println("ok");
964 out.print("slicing of unknown most derived, known intermediate as base... ");
965 out.flush();
969 test.unknownMostDerived1AsBase();
970 test(false);
972 catch(KnownIntermediate ki)
974 test(ki.b.equals("UnknownMostDerived1.b"));
975 test(ki.ki.equals("UnknownMostDerived1.ki"));
976 test(ki.ice_name().equals("Test::KnownIntermediate"));
978 catch(Exception ex)
980 test(false);
983 out.println("ok");
985 out.print("slicing of unknown most derived, known intermediate as base (AMI)... ");
986 out.flush();
988 Callback_TestIntf_unknownMostDerived1AsBaseI cb = new Callback_TestIntf_unknownMostDerived1AsBaseI();
989 test.begin_unknownMostDerived1AsBase(cb);
990 cb.check();
992 out.println("ok");
994 out.print("slicing of unknown most derived, known intermediate as intermediate... ");
995 out.flush();
999 test.unknownMostDerived1AsKnownIntermediate();
1000 test(false);
1002 catch(KnownIntermediate ki)
1004 test(ki.b.equals("UnknownMostDerived1.b"));
1005 test(ki.ki.equals("UnknownMostDerived1.ki"));
1006 test(ki.ice_name().equals("Test::KnownIntermediate"));
1008 catch(Exception ex)
1010 test(false);
1013 out.println("ok");
1015 out.print("slicing of unknown most derived, known intermediate as intermediate (AMI)... ");
1016 out.flush();
1018 Callback_TestIntf_unknownMostDerived1AsKnownIntermediateI cb =
1019 new Callback_TestIntf_unknownMostDerived1AsKnownIntermediateI();
1020 test.begin_unknownMostDerived1AsKnownIntermediate(cb);
1021 cb.check();
1023 out.println("ok");
1025 out.print("slicing of unknown most derived, unknown intermediate thrown as base... ");
1026 out.flush();
1030 test.unknownMostDerived2AsBase();
1031 test(false);
1033 catch(Base b)
1035 test(b.b.equals("UnknownMostDerived2.b"));
1036 test(b.ice_name().equals("Test::Base"));
1038 catch(Exception ex)
1040 test(false);
1043 out.println("ok");
1045 out.print("slicing of unknown most derived, unknown intermediate thrown as base (AMI)... ");
1046 out.flush();
1048 Callback_TestIntf_unknownMostDerived2AsBaseI cb = new Callback_TestIntf_unknownMostDerived2AsBaseI();
1049 test.begin_unknownMostDerived2AsBase(cb);
1050 cb.check();
1052 out.println("ok");
1054 return test;