summaryrefslogtreecommitdiff
path: root/java/test/Ice/exceptions
diff options
context:
space:
mode:
Diffstat (limited to 'java/test/Ice/exceptions')
-rw-r--r--java/test/Ice/exceptions/AllTests.java397
-rw-r--r--java/test/Ice/exceptions/Client.java53
-rw-r--r--java/test/Ice/exceptions/Test.ice53
3 files changed, 503 insertions, 0 deletions
diff --git a/java/test/Ice/exceptions/AllTests.java b/java/test/Ice/exceptions/AllTests.java
new file mode 100644
index 00000000000..fc7059b6672
--- /dev/null
+++ b/java/test/Ice/exceptions/AllTests.java
@@ -0,0 +1,397 @@
+// **********************************************************************
+//
+// Copyright (c) 2001
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+public class AllTests
+{
+ private static class MyExceptionFactory implements Ice.UserExceptionFactory
+ {
+ public void
+ createAndThrow(String type)
+ throws Ice.UserException
+ {
+ if (type.equals("::A"))
+ {
+ throw new A();
+ }
+ else if (type.equals("::B"))
+ {
+ throw new B();
+ }
+ else if (type.equals("::C"))
+ {
+ throw new C();
+ }
+ else if (type.equals("::D"))
+ {
+ throw new D();
+ }
+ assert(false); // Should never be reached
+ }
+
+ public void
+ destroy()
+ {
+ // Nothing to do
+ }
+ }
+
+ private static void
+ test(boolean b)
+ {
+ if (!b)
+ {
+ throw new RuntimeException();
+ }
+ }
+
+ public static ThrowerPrx
+ allTests(Ice.Communicator communicator, boolean collocated)
+ {
+ System.out.print("testing stringToProxy... ");
+ System.out.flush();
+ String ref;
+
+ Ice.Properties properties = communicator.getProperties();
+
+ String protocol = properties.getProperty("Ice.Protocol");
+ String secure = "";
+
+ if (protocol == null)
+ {
+ protocol = "tcp";
+ }
+
+ if (protocol.equals("ssl"))
+ {
+ secure = " -s ";
+ }
+
+ String endpts = protocol + " -p 12345 -t 2000";
+
+ ref = "thrower" + secure + ":" + endpts;
+
+ Ice.ObjectPrx base = communicator.stringToProxy(ref);
+ test(base != null);
+ System.out.println("ok");
+
+ System.out.print("testing checked cast... ");
+ System.out.flush();
+ ThrowerPrx thrower = ThrowerPrxHelper.checkedCast(base);
+ test(thrower != null);
+ test(thrower.equals(base));
+ System.out.println("ok");
+
+ System.out.print("catching exact types... ");
+ System.out.flush();
+
+ try
+ {
+ thrower.throwAasA(1);
+ test(false);
+ }
+ catch (A ex)
+ {
+ test(ex.a == 1);
+ }
+ catch (Exception ex)
+ {
+ test(false);
+ }
+
+ try
+ {
+ thrower.throwAorDasAorD(1);
+ test(false);
+ }
+ catch (A ex)
+ {
+ test(ex.a == 1);
+ }
+ catch (Exception ex)
+ {
+ test(false);
+ }
+
+ try
+ {
+ thrower.throwAorDasAorD(-1);
+ test(false);
+ }
+ catch (D ex)
+ {
+ test(ex.d == -1);
+ }
+ catch (Exception ex)
+ {
+ test(false);
+ }
+
+ try
+ {
+ thrower.throwBasB(1, 2);
+ test(false);
+ }
+ catch (B ex)
+ {
+ test(ex.a == 1);
+ test(ex.b == 2);
+ }
+ catch (Exception ex)
+ {
+ test(false);
+ }
+
+ try
+ {
+ thrower.throwCasC(1, 2, 3);
+ test(false);
+ }
+ catch (C ex)
+ {
+ test(ex.a == 1);
+ test(ex.b == 2);
+ test(ex.c == 3);
+ }
+ catch (Exception ex)
+ {
+ test(false);
+ }
+
+ System.out.println("ok");
+
+ System.out.print("catching base types... ");
+ System.out.flush();
+
+ try
+ {
+ thrower.throwBasB(1, 2);
+ test(false);
+ }
+ catch (A ex)
+ {
+ test(ex.a == 1);
+ }
+ catch (Exception ex)
+ {
+ test(false);
+ }
+
+ try
+ {
+ thrower.throwCasC(1, 2, 3);
+ test(false);
+ }
+ catch (B ex)
+ {
+ test(ex.a == 1);
+ test(ex.b == 2);
+ }
+ catch (Exception ex)
+ {
+ test(false);
+ }
+
+ System.out.println("ok");
+
+ if (!collocated) // If the server is collocated, exception factories
+ { // are not needed.
+ System.out.print("catching derived types w/o exception " +
+ "factories... ");
+ System.out.flush();
+
+ try
+ {
+ thrower.throwBasA(1, 2);
+ test(false);
+ }
+ catch (Ice.NoUserExceptionFactoryException ex)
+ {
+ }
+ catch (Exception ex)
+ {
+ test(false);
+ }
+
+ try
+ {
+ thrower.throwCasA(1, 2, 3);
+ test(false);
+ }
+ catch (Ice.NoUserExceptionFactoryException ex)
+ {
+ }
+ catch (Exception ex)
+ {
+ test(false);
+ }
+
+ try
+ {
+ thrower.throwCasB(1, 2, 3);
+ test(false);
+ }
+ catch (Ice.NoUserExceptionFactoryException ex)
+ {
+ }
+ catch (Exception ex)
+ {
+ test(false);
+ }
+
+ System.out.println("ok");
+
+ System.out.print("catching derived types w/ exception " +
+ "factories... ");
+ System.out.flush();
+
+ Ice.UserExceptionFactory factory = new MyExceptionFactory();
+ communicator.addUserExceptionFactory(factory, "::A");
+ communicator.addUserExceptionFactory(factory, "::B");
+ communicator.addUserExceptionFactory(factory, "::C");
+ communicator.addUserExceptionFactory(factory, "::D");
+ }
+ else
+ {
+ System.out.print("catching derived types... ");
+ System.out.flush();
+ }
+
+ try
+ {
+ thrower.throwBasA(1, 2);
+ test(false);
+ }
+ catch (B ex)
+ {
+ test(ex.a == 1);
+ test(ex.b == 2);
+ }
+ catch (Exception ex)
+ {
+ test(false);
+ }
+
+ try
+ {
+ thrower.throwCasA(1, 2, 3);
+ test(false);
+ }
+ catch (C ex)
+ {
+ test(ex.a == 1);
+ test(ex.b == 2);
+ test(ex.c == 3);
+ }
+ catch (Exception ex)
+ {
+ test(false);
+ }
+
+ try
+ {
+ thrower.throwCasB(1, 2, 3);
+ test(false);
+ }
+ catch (C ex)
+ {
+ test(ex.a == 1);
+ test(ex.b == 2);
+ test(ex.c == 3);
+ }
+ catch (Exception ex)
+ {
+ test(false);
+ }
+
+ System.out.println("ok");
+
+ System.out.print("catching unknown user exception... ");
+ System.out.flush();
+
+ try
+ {
+ thrower.throwUndeclaredA(1);
+ test(false);
+ }
+ catch (Ice.UnknownUserException ex)
+ {
+ }
+ catch (Exception ex)
+ {
+ test(false);
+ }
+
+ try
+ {
+ thrower.throwUndeclaredB(1, 2);
+ test(false);
+ }
+ catch (Ice.UnknownUserException ex)
+ {
+ }
+ catch (Exception ex)
+ {
+ test(false);
+ }
+
+ try
+ {
+ thrower.throwUndeclaredC(1, 2, 3);
+ test(false);
+ }
+ catch (Ice.UnknownUserException ex)
+ {
+ }
+ catch (Exception ex)
+ {
+ test(false);
+ }
+
+ System.out.println("ok");
+
+ System.out.print("catching unknown local exception... ");
+ System.out.flush();
+
+ try
+ {
+ thrower.throwLocalException();
+ test(false);
+ }
+ catch (Ice.UnknownLocalException ex)
+ {
+ }
+ catch (Exception ex)
+ {
+ test(false);
+ }
+
+ System.out.println("ok");
+
+ System.out.print("catching unknown non-Ice exception... ");
+ System.out.flush();
+
+ try
+ {
+ thrower.throwNonIceException();
+ test(false);
+ }
+ catch (Ice.UnknownException ex)
+ {
+ }
+ catch (Exception ex)
+ {
+ test(false);
+ }
+
+ System.out.println("ok");
+
+ return thrower;
+ }
+}
diff --git a/java/test/Ice/exceptions/Client.java b/java/test/Ice/exceptions/Client.java
new file mode 100644
index 00000000000..b60db562a10
--- /dev/null
+++ b/java/test/Ice/exceptions/Client.java
@@ -0,0 +1,53 @@
+// **********************************************************************
+//
+// Copyright (c) 2001
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+public class Client
+{
+ private static int
+ run(String[] args, Ice.Communicator communicator)
+ {
+ ThrowerPrx thrower = AllTests.allTests(communicator, false);
+ thrower.shutdown();
+ return 0;
+ }
+
+ public static void
+ main(String[] args)
+ {
+ int status = 0;
+ Ice.Communicator communicator = null;
+
+ try
+ {
+ communicator = Ice.Util.initialize(args);
+ status = run(args, communicator);
+ }
+ catch (Ice.LocalException ex)
+ {
+ ex.printStackTrace();
+ status = 1;
+ }
+
+ if (communicator != null)
+ {
+ try
+ {
+ communicator.destroy();
+ }
+ catch (Ice.LocalException ex)
+ {
+ ex.printStackTrace();
+ status = 1;
+ }
+ }
+
+ System.exit(status);
+ }
+}
diff --git a/java/test/Ice/exceptions/Test.ice b/java/test/Ice/exceptions/Test.ice
new file mode 100644
index 00000000000..dc42b49e0f9
--- /dev/null
+++ b/java/test/Ice/exceptions/Test.ice
@@ -0,0 +1,53 @@
+// **********************************************************************
+//
+// Copyright (c) 2001
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+#ifndef TEST_ICE
+#define TEST_ICE
+
+interface Thrower;
+
+exception A
+{
+ int a;
+};
+
+exception B extends A
+{
+ int b;
+};
+
+exception C extends B
+{
+ int c;
+};
+
+exception D
+{
+ int d;
+};
+
+interface Thrower
+{
+ void shutdown();
+ void throwAasA(int a) throws A;
+ void throwAorDasAorD(int a) throws A, D;
+ void throwBasA(int a, int b) throws A;
+ void throwCasA(int a, int b, int c) throws A;
+ void throwBasB(int a, int b) throws B;
+ void throwCasB(int a, int b, int c) throws B;
+ void throwCasC(int a, int b, int c) throws C;
+ void throwUndeclaredA(int a) throws B, D;
+ void throwUndeclaredB(int a, int b);
+ void throwUndeclaredC(int a, int b, int c) throws D;
+ void throwLocalException();
+ void throwNonIceException();
+};
+
+#endif