summaryrefslogtreecommitdiff
path: root/js/test/Ice/exceptions
diff options
context:
space:
mode:
Diffstat (limited to 'js/test/Ice/exceptions')
-rw-r--r--js/test/Ice/exceptions/.gitignore2
-rw-r--r--js/test/Ice/exceptions/Client.js476
-rw-r--r--js/test/Ice/exceptions/Makefile23
-rw-r--r--js/test/Ice/exceptions/Makefile.mak20
-rw-r--r--js/test/Ice/exceptions/Test.ice76
-rw-r--r--js/test/Ice/exceptions/run.js10
-rwxr-xr-xjs/test/Ice/exceptions/run.py45
7 files changed, 652 insertions, 0 deletions
diff --git a/js/test/Ice/exceptions/.gitignore b/js/test/Ice/exceptions/.gitignore
new file mode 100644
index 00000000000..d158d9308ba
--- /dev/null
+++ b/js/test/Ice/exceptions/.gitignore
@@ -0,0 +1,2 @@
+Test.js
+index.html
diff --git a/js/test/Ice/exceptions/Client.js b/js/test/Ice/exceptions/Client.js
new file mode 100644
index 00000000000..e357d21d134
--- /dev/null
+++ b/js/test/Ice/exceptions/Client.js
@@ -0,0 +1,476 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+(function(global){
+ var require = typeof(module) !== "undefined" ? module.require : function(){};
+ require("Ice/Ice");
+ require("Test");
+
+ var Ice = global.Ice;
+ var Promise = Ice.Promise;
+
+ var allTests = function(out, communicator, Test)
+ {
+ var EmptyI = function()
+ {
+ };
+
+ EmptyI.prototype = new Test.Empty();
+ EmptyI.prototype.constructor = EmptyI;
+
+ var ServantLocatorI = function()
+ {
+ };
+
+ ServantLocatorI.prototype.locate = function(curr, cookie)
+ {
+ return null;
+ };
+
+ ServantLocatorI.prototype.finished = function(curr, servant, cookie)
+ {
+ };
+
+ ServantLocatorI.prototype.deactivate = function(category)
+ {
+ };
+
+ var ObjectFactoryI = function()
+ {
+ };
+
+ ObjectFactoryI.prototype.create = function(type)
+ {
+ return null;
+ };
+
+ ObjectFactoryI.prototype.destroy = function()
+ {
+ };
+
+ var p = new Ice.Promise();
+ var test = function(b)
+ {
+ if(!b)
+ {
+ try
+ {
+ throw new Error("test failed");
+ }
+ catch(err)
+ {
+ p.fail(err);
+ throw err;
+ }
+ }
+ };
+
+ var failCB = function(){ test(false); };
+
+ var supportsUndeclaredExceptions = function(thrower)
+ {
+ return Promise.try(
+ function()
+ {
+ return thrower.supportsUndeclaredExceptions().then(
+ function(v)
+ {
+ if(v)
+ {
+ out.write("catching unknown user exception... ");
+ return thrower.throwUndeclaredA(1).then(
+ failCB,
+ function(ex)
+ {
+ test(ex instanceof Ice.UnknownUserException);
+ return thrower.throwUndeclaredB(1, 2);
+ }
+ ).then(
+ failCB,
+ function(ex)
+ {
+ test(ex instanceof Ice.UnknownUserException);
+ return thrower.throwUndeclaredC(1, 2, 3);
+ }
+ ).then(
+ failCB,
+ function(ex)
+ {
+ test(ex instanceof Ice.UnknownUserException);
+ out.writeLine("ok");
+ }
+ );
+ }
+ });
+ });
+ };
+
+ var supportsAssertException = function(thrower)
+ {
+ return Promise.try(
+ function()
+ {
+ return thrower.supportsAssertException().then(
+ function(v)
+ {
+ if(v)
+ {
+ out.write("testing assert in the server... ");
+ return thrower.throwAssertException().then(
+ failCB,
+ function(ex)
+ {
+ test(ex instanceof Ice.ConnectionLostException);
+ out.writeLine("ok");
+ }
+ );
+ }
+ });
+ });
+ };
+
+ var base, ref, thrower;
+ Promise.try(
+ function()
+ {
+ out.write("testing object adapter registration exceptions... ");
+ return communicator.createObjectAdapter("TestAdapter0").then(
+ failCB,
+ function(ex)
+ {
+ test(ex instanceof Ice.InitializationException); // Expected
+ });
+ }
+ ).then(
+ function()
+ {
+ return communicator.createObjectAdapterWithEndpoints("TestAdapter0", "default").then(
+ failCB,
+ function(ex)
+ {
+ test(ex instanceof Ice.FeatureNotSupportedException); // Expected
+ out.writeLine("ok");
+ });
+ }
+ ).then(
+ function()
+ {
+ out.write("testing servant registration exceptions... ");
+ return communicator.createObjectAdapter("").then(
+ function(adapter)
+ {
+ var obj = new EmptyI();
+ adapter.add(obj, communicator.stringToIdentity("x"));
+ try
+ {
+ adapter.add(obj, communicator.stringToIdentity("x"));
+ test(false);
+ }
+ catch(ex)
+ {
+ test(ex instanceof Ice.AlreadyRegisteredException);
+ }
+
+ adapter.remove(communicator.stringToIdentity("x"));
+ try
+ {
+ adapter.remove(communicator.stringToIdentity("x"));
+ test(false);
+ }
+ catch(ex)
+ {
+ test(ex instanceof Ice.NotRegisteredException);
+ }
+ adapter.deactivate();
+ out.writeLine("ok");
+ });
+ }
+ ).then(
+ function()
+ {
+ out.write("testing servant locator registration exceptions... ");
+ return communicator.createObjectAdapter("").then(
+ function(adapter)
+ {
+ var loc = new ServantLocatorI();
+ adapter.addServantLocator(loc, "x");
+ try
+ {
+ adapter.addServantLocator(loc, "x");
+ test(false);
+ }
+ catch(ex)
+ {
+ test(ex instanceof Ice.AlreadyRegisteredException);
+ }
+ adapter.deactivate();
+ out.writeLine("ok");
+ });
+ }
+ ).then(
+ function()
+ {
+ out.write("testing object factory registration exception... ");
+ var of = new ObjectFactoryI();
+ communicator.addObjectFactory(of, "::x");
+ try
+ {
+ communicator.addObjectFactory(of, "::x");
+ test(false);
+ }
+ catch(ex)
+ {
+ test(ex instanceof Ice.AlreadyRegisteredException);
+ }
+ out.writeLine("ok");
+
+ out.write("testing stringToProxy... ");
+ ref = "thrower:default -p 12010";
+ base = communicator.stringToProxy(ref);
+ test(base !== null);
+ out.writeLine("ok");
+ out.write("testing checked cast... ");
+ return Test.ThrowerPrx.checkedCast(base);
+ }
+ ).then(
+ function(obj)
+ {
+ thrower = obj;
+ test(thrower !== null);
+ test(thrower.equals(base));
+ out.writeLine("ok");
+ out.write("catching exact types... ");
+ return thrower.throwAasA(1);
+ }
+ ).then(
+ failCB,
+ function(ex)
+ {
+ test(ex instanceof Test.A);
+ test(ex.aMem === 1);
+ return thrower.throwAorDasAorD(1);
+ }
+ ).then(
+ failCB,
+ function(ex)
+ {
+ test(ex instanceof Test.A);
+ test(ex.aMem === 1);
+ return thrower.throwAorDasAorD(-1);
+ }
+ ).then(
+ failCB,
+ function(ex)
+ {
+ test(ex instanceof Test.D);
+ test(ex.dMem === -1);
+ return thrower.throwBasB(1, 2);
+ }
+ ).then(
+ failCB,
+ function(ex)
+ {
+ test(ex instanceof Test.B);
+ test(ex.aMem == 1);
+ test(ex.bMem == 2);
+ return thrower.throwCasC(1, 2, 3);
+ }
+ ).then(
+ failCB,
+ function(ex)
+ {
+ test(ex instanceof Test.C);
+ test(ex.aMem == 1);
+ test(ex.bMem == 2);
+ test(ex.cMem == 3);
+ out.writeLine("ok");
+ out.write("catching base types... ");
+ return thrower.throwBasB(1, 2);
+ }
+ ).then(
+ failCB,
+ function(ex)
+ {
+ test(ex instanceof Test.A);
+ test(ex.aMem == 1);
+ return thrower.throwCasC(1, 2, 3);
+ }
+ ).then(
+ failCB,
+ function(ex)
+ {
+ test(ex instanceof Test.B);
+ test(ex.aMem == 1);
+ test(ex.bMem == 2);
+ out.writeLine("ok");
+ out.write("catching derived types... ");
+ return thrower.throwBasA(1, 2);
+ }
+ ).then(
+ failCB,
+ function(ex)
+ {
+ test(ex instanceof Test.B);
+ test(ex.aMem == 1);
+ test(ex.bMem == 2);
+ return thrower.throwCasA(1, 2, 3);
+ }
+ ).then(
+ failCB,
+ function(ex)
+ {
+ test(ex instanceof Test.C);
+ test(ex.aMem == 1);
+ test(ex.bMem == 2);
+ test(ex.cMem == 3);
+ return thrower.throwCasB(1, 2, 3);
+ }
+ ).then(
+ failCB,
+ function(ex)
+ {
+ test(ex instanceof Test.C);
+ test(ex.aMem == 1);
+ test(ex.bMem == 2);
+ test(ex.cMem == 3);
+ out.writeLine("ok");
+ return supportsUndeclaredExceptions(thrower);
+ }
+ ).then(
+ function()
+ {
+ return supportsAssertException(thrower);
+ }
+ ).then(
+ function()
+ {
+ out.write("testing memory limit marshal exception...");
+ return thrower.throwMemoryLimitException(null);
+ }
+ ).then(
+ failCB,
+ function(ex)
+ {
+ test(ex instanceof Ice.UnknownLocalException);
+ return thrower.throwMemoryLimitException(new Array(20 * 1024));
+ }
+ ).then(
+ failCB,
+ function(ex)
+ {
+ test(ex instanceof Ice.MemoryLimitException);
+ out.writeLine("ok");
+ out.write("catching object not exist exception... ");
+ var id = communicator.stringToIdentity("does not exist");
+ var thrower2 = Test.ThrowerPrx.uncheckedCast(thrower.ice_identity(id));
+ return thrower2.ice_ping();
+ }
+ ).then(
+ failCB,
+ function(ex)
+ {
+ test(ex instanceof Ice.ObjectNotExistException);
+ test(ex.id.equals(communicator.stringToIdentity("does not exist")));
+ out.writeLine("ok");
+ out.write("catching facet not exist exception... ");
+ var thrower2 = Test.ThrowerPrx.uncheckedCast(thrower, "no such facet");
+ return thrower2.ice_ping();
+ }
+ ).then(
+ failCB,
+ function(ex)
+ {
+ test(ex instanceof Ice.FacetNotExistException);
+ test(ex.facet == "no such facet");
+ out.writeLine("ok");
+ out.write("catching operation not exist exception... ");
+ var thrower2 = Test.WrongOperationPrx.uncheckedCast(thrower);
+ return thrower2.noSuchOperation();
+ }
+ ).then(
+ failCB,
+ function(ex)
+ {
+ test(ex instanceof Ice.OperationNotExistException);
+ test(ex.operation == "noSuchOperation");
+ out.writeLine("ok");
+ out.write("catching unknown local exception... ");
+ return thrower.throwLocalException();
+ }
+ ).then(
+ failCB,
+ function(ex)
+ {
+ test(ex instanceof Ice.UnknownLocalException);
+ return thrower.throwLocalExceptionIdempotent();
+ }
+ ).then(
+ failCB,
+ function(ex)
+ {
+ test(ex instanceof Ice.UnknownLocalException ||
+ ex instanceof Ice.OperationNotExistException);
+ out.writeLine("ok");
+ out.write("catching unknown non-Ice exception... ");
+ return thrower.throwNonIceException();
+ }
+ ).then(
+ failCB,
+ function(ex)
+ {
+ test(ex instanceof Ice.UnknownException);
+ out.writeLine("ok");
+ out.write("testing asynchronous exceptions... ");
+ return thrower.throwAfterResponse();
+ }
+ ).then(
+ function()
+ {
+ return thrower.throwAfterException();
+ }
+ ).then(
+ failCB,
+ function(ex)
+ {
+ test(ex instanceof Test.A);
+ out.writeLine("ok");
+ return thrower.shutdown();
+ }
+ ).then(
+ function()
+ {
+ p.succeed();
+ },
+ function(ex)
+ {
+ p.fail(ex);
+ }
+ );
+ return p;
+ };
+
+ var run = function(out, id)
+ {
+ return Promise.try(
+ function()
+ {
+ id.properties.setProperty("Ice.MessageSizeMax", "10");
+ var c = Ice.initialize(id);
+ return allTests(out, c, global.Test).finally(
+ function()
+ {
+ return c.destroy();
+ });
+ });
+ };
+ global.__test__ = run;
+ global.__clientAllTests__ = allTests;
+ global.__runServer__ = true;
+
+}(typeof (global) === "undefined" ? window : global));
diff --git a/js/test/Ice/exceptions/Makefile b/js/test/Ice/exceptions/Makefile
new file mode 100644
index 00000000000..8f81ea44140
--- /dev/null
+++ b/js/test/Ice/exceptions/Makefile
@@ -0,0 +1,23 @@
+# **********************************************************************
+#
+# Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved.
+#
+# This copy of Ice is licensed to you under the terms described in the
+# ICE_LICENSE file included in this distribution.
+#
+# **********************************************************************
+
+top_srcdir = ../../..
+
+TARGETS = index.html
+
+SLICES = Test.ice
+
+GEN_SRCS = $(patsubst %.ice, %.js, $(SLICES))
+
+SRCS = Client.js
+
+include $(top_srcdir)/config/Make.rules.js
+
+SLICE2JSFLAGS := $(SLICE2JSFLAGS) -I$(slicedir)
+
diff --git a/js/test/Ice/exceptions/Makefile.mak b/js/test/Ice/exceptions/Makefile.mak
new file mode 100644
index 00000000000..61a62482429
--- /dev/null
+++ b/js/test/Ice/exceptions/Makefile.mak
@@ -0,0 +1,20 @@
+# **********************************************************************
+#
+# Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved.
+#
+# This copy of Ice is licensed to you under the terms described in the
+# ICE_LICENSE file included in this distribution.
+#
+# **********************************************************************
+
+top_srcdir = ..\..\..
+
+TARGETS = index.html
+
+GEN_SRCS = Test.js
+
+SRCS = Client.js
+
+!include $(top_srcdir)\config\Make.rules.mak.js
+
+SLICE2JSFLAGS = $(SLICE2JSFLAGS) -I"$(slicedir)"
diff --git a/js/test/Ice/exceptions/Test.ice b/js/test/Ice/exceptions/Test.ice
new file mode 100644
index 00000000000..3725971d7c2
--- /dev/null
+++ b/js/test/Ice/exceptions/Test.ice
@@ -0,0 +1,76 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+#pragma once
+
+#include <Ice/BuiltinSequences.ice>
+
+module Test
+{
+
+interface Empty
+{
+};
+
+interface Thrower;
+
+exception A
+{
+ int aMem;
+};
+
+exception B extends A
+{
+ int bMem;
+};
+
+exception C extends B
+{
+ int cMem;
+};
+
+exception D
+{
+ int dMem;
+};
+
+["ami"] interface Thrower
+{
+ void shutdown();
+ bool supportsUndeclaredExceptions();
+ bool supportsAssertException();
+
+ 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);
+ void throwUndeclaredB(int a, int b);
+ void throwUndeclaredC(int a, int b, int c);
+ void throwLocalException();
+ void throwNonIceException();
+ void throwAssertException();
+ Ice::ByteSeq throwMemoryLimitException(Ice::ByteSeq seq);
+
+ idempotent void throwLocalExceptionIdempotent();
+
+ void throwAfterResponse();
+ void throwAfterException() throws A;
+};
+
+["ami"] interface WrongOperation
+{
+ void noSuchOperation();
+};
+
+};
diff --git a/js/test/Ice/exceptions/run.js b/js/test/Ice/exceptions/run.js
new file mode 100644
index 00000000000..a875f421701
--- /dev/null
+++ b/js/test/Ice/exceptions/run.js
@@ -0,0 +1,10 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+require("../../Common/Common")(module);
diff --git a/js/test/Ice/exceptions/run.py b/js/test/Ice/exceptions/run.py
new file mode 100755
index 00000000000..1da101f4919
--- /dev/null
+++ b/js/test/Ice/exceptions/run.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+# **********************************************************************
+#
+# Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved.
+#
+# This copy of Ice is licensed to you under the terms described in the
+# ICE_LICENSE file included in this distribution.
+#
+# **********************************************************************
+
+import os, sys
+
+path = [ ".", "..", "../..", "../../..", "../../../.." ]
+head = os.path.dirname(sys.argv[0])
+if len(head) > 0:
+ path = [os.path.join(head, p) for p in path]
+path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ]
+if len(path) == 0:
+ raise RuntimeError("can't find toplevel directory!")
+sys.path.append(os.path.join(path[0], "scripts"))
+import TestUtil
+
+print("Running test with compact (default) format.")
+TestUtil.clientServerTest()
+
+print("Running test with sliced format.")
+TestUtil.clientServerTest(additionalClientOptions="--Ice.Default.SlicedFormat",
+ additionalServerOptions="--Ice.Default.SlicedFormat")
+
+print("Running test with 1.0 encoding.")
+TestUtil.clientServerTest(additionalClientOptions="--Ice.Default.EncodingVersion=1.0",
+ additionalServerOptions="--Ice.Default.EncodingVersion=1.0")
+
+print("Running test with compact (default) format and AMD server.")
+TestUtil.clientServerTest(server="serveramd")
+
+print("Running test with sliced format and AMD server.")
+TestUtil.clientServerTest(server="serveramd",
+ additionalClientOptions="--Ice.Default.SlicedFormat",
+ additionalServerOptions="--Ice.Default.SlicedFormat")
+
+print("Running test with 1.0 encoding and AMD server.")
+TestUtil.clientServerTest(server="serveramd",
+ additionalClientOptions="--Ice.Default.EncodingVersion=1.0",
+ additionalServerOptions="--Ice.Default.EncodingVersion=1.0")