diff options
Diffstat (limited to 'js/test/Ice/slicing/exceptions')
-rw-r--r-- | js/test/Ice/slicing/exceptions/.gitignore | 2 | ||||
-rw-r--r-- | js/test/Ice/slicing/exceptions/Client.js | 286 | ||||
-rw-r--r-- | js/test/Ice/slicing/exceptions/Makefile | 23 | ||||
-rw-r--r-- | js/test/Ice/slicing/exceptions/Makefile.mak | 20 | ||||
-rw-r--r-- | js/test/Ice/slicing/exceptions/Test.ice | 98 | ||||
-rw-r--r-- | js/test/Ice/slicing/exceptions/run.js | 10 | ||||
-rwxr-xr-x | js/test/Ice/slicing/exceptions/run.py | 28 |
7 files changed, 467 insertions, 0 deletions
diff --git a/js/test/Ice/slicing/exceptions/.gitignore b/js/test/Ice/slicing/exceptions/.gitignore new file mode 100644 index 00000000000..d158d9308ba --- /dev/null +++ b/js/test/Ice/slicing/exceptions/.gitignore @@ -0,0 +1,2 @@ +Test.js +index.html diff --git a/js/test/Ice/slicing/exceptions/Client.js b/js/test/Ice/slicing/exceptions/Client.js new file mode 100644 index 00000000000..a7ba70440e5 --- /dev/null +++ b/js/test/Ice/slicing/exceptions/Client.js @@ -0,0 +1,286 @@ +// ********************************************************************** +// +// 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"); + var Ice = global.Ice; + + require("Test"); + var Test = global.Test; + var Promise = Ice.Promise; + var ArrayUtil = Ice.ArrayUtil; + + var allTests = function(out, communicator) + { + var failCB = function(){ test(false); }; + var p = new Promise(); + var test = function(b) + { + if(!b) + { + try + { + throw new Error("test failed"); + } + catch(err) + { + p.fail(err); + throw err; + } + } + }; + + var ref, base, prx; + + Promise.try( + function() + { + out.write("testing stringToProxy... "); + ref = "Test:default -p 12010 -t 10000"; + base = communicator.stringToProxy(ref); + test(base !== null); + out.writeLine("ok"); + + out.write("testing checked cast... "); + return Test.TestIntfPrx.checkedCast(base); + } + ).then( + function(obj) + { + prx = obj; + test(prx !== null); + test(prx.equals(base)); + out.writeLine("ok"); + out.write("base... "); + return prx.baseAsBase(); + } + ).then( + failCB, + function(ex) + { + test(Object.getPrototypeOf(ex) === Test.Base.prototype); + test(ex.b == "Base.b"); + test(ex.ice_name() == "Test::Base"); + + out.writeLine("ok"); + out.write("slicing of unknown derived... "); + return prx.unknownDerivedAsBase(); + } + ).then( + failCB, + function(ex) + { + test(Object.getPrototypeOf(ex) === Test.Base.prototype); + test(ex.b == "UnknownDerived.b"); + test(ex.ice_name() == "Test::Base"); + + out.writeLine("ok"); + out.write("non-slicing of known derived as base... "); + return prx.knownDerivedAsBase(); + } + ).then( + failCB, + function(ex) + { + test(Object.getPrototypeOf(ex) === Test.KnownDerived.prototype); + test(ex.b == "KnownDerived.b"); + test(ex.kd == "KnownDerived.kd"); + test(ex.ice_name() == "Test::KnownDerived"); + out.writeLine("ok"); + out.write("non-slicing of known derived as derived... "); + + return prx.knownDerivedAsKnownDerived(); + } + ).then( + failCB, + function(ex) + { + test(Object.getPrototypeOf(ex) === Test.KnownDerived.prototype); + test(ex.b == "KnownDerived.b"); + test(ex.kd == "KnownDerived.kd"); + test(ex.ice_name() == "Test::KnownDerived"); + + out.writeLine("ok"); + out.write("slicing of unknown intermediate as base... "); + return prx.unknownIntermediateAsBase(); + } + ).then( + failCB, + function(ex) + { + test(Object.getPrototypeOf(ex) === Test.Base.prototype); + test(ex.b == "UnknownIntermediate.b"); + test(ex.ice_name() == "Test::Base"); + + out.writeLine("ok"); + out.write("slicing of known intermediate as base... "); + return prx.knownIntermediateAsBase(); + } + ).then( + failCB, + function(ex) + { + test(Object.getPrototypeOf(ex) === Test.KnownIntermediate.prototype); + test(ex.b == "KnownIntermediate.b"); + test(ex.ki == "KnownIntermediate.ki"); + test(ex.ice_name() == "Test::KnownIntermediate"); + + out.writeLine("ok"); + out.write("slicing of known most derived as base... "); + return prx.knownMostDerivedAsBase(); + } + ).then( + failCB, + function(ex) + { + test(Object.getPrototypeOf(ex) === Test.KnownMostDerived.prototype); + test(ex.b == "KnownMostDerived.b"); + test(ex.ki == "KnownMostDerived.ki"); + test(ex.kmd == "KnownMostDerived.kmd"); + test(ex.ice_name() == "Test::KnownMostDerived"); + + out.writeLine("ok"); + out.write("non-slicing of known intermediate as intermediate... "); + + return prx.knownIntermediateAsKnownIntermediate(); + } + ).then( + failCB, + function(ex) + { + test(Object.getPrototypeOf(ex) === Test.KnownIntermediate.prototype); + test(ex.b == "KnownIntermediate.b"); + test(ex.ki == "KnownIntermediate.ki"); + test(ex.ice_name() == "Test::KnownIntermediate"); + out.writeLine("ok"); + out.write("non-slicing of known most derived as intermediate... "); + return prx.knownMostDerivedAsKnownIntermediate(); + } + ).then( + failCB, + function(ex) + { + test(Object.getPrototypeOf(ex) === Test.KnownMostDerived.prototype); + test(ex.b == "KnownMostDerived.b"); + test(ex.ki == "KnownMostDerived.ki"); + test(ex.kmd == "KnownMostDerived.kmd"); + test(ex.ice_name() == "Test::KnownMostDerived"); + out.writeLine("ok"); + out.write("non-slicing of known most derived as most derived... "); + + return prx.knownMostDerivedAsKnownMostDerived(); + } + ).then( + failCB, + function(ex) + { + test(Object.getPrototypeOf(ex) === Test.KnownMostDerived.prototype); + test(ex.b == "KnownMostDerived.b"); + test(ex.ki == "KnownMostDerived.ki"); + test(ex.kmd == "KnownMostDerived.kmd"); + test(ex.ice_name() == "Test::KnownMostDerived"); + + out.writeLine("ok"); + out.write("slicing of unknown most derived, known intermediate as base... "); + return prx.unknownMostDerived1AsBase(); + } + ).then( + failCB, + function(ex) + { + test(Object.getPrototypeOf(ex) === Test.KnownIntermediate.prototype); + test(ex.b == "UnknownMostDerived1.b"); + test(ex.ki == "UnknownMostDerived1.ki"); + test(ex.ice_name() == "Test::KnownIntermediate"); + out.writeLine("ok"); + out.write("slicing of unknown most derived, known intermediate as intermediate... "); + return prx.unknownMostDerived1AsKnownIntermediate(); + } + ).then( + failCB, + function(ex) + { + test(Object.getPrototypeOf(ex) === Test.KnownIntermediate.prototype); + test(ex.b == "UnknownMostDerived1.b"); + test(ex.ki == "UnknownMostDerived1.ki"); + test(ex.ice_name() == "Test::KnownIntermediate"); + + out.writeLine("ok"); + out.write("slicing of unknown most derived, unknown intermediate thrown as base... "); + + return prx.unknownMostDerived2AsBase(); + } + ).then( + failCB, + function(ex) + { + test(Object.getPrototypeOf(ex) === Test.Base.prototype); + test(ex.b == "UnknownMostDerived2.b"); + test(ex.ice_name() == "Test::Base"); + + out.writeLine("ok"); + out.write("unknown most derived in compact format... "); + + return prx.unknownMostDerived2AsBaseCompact(); + } + ).then( + failCB, + function(ex) + { + if(Object.getPrototypeOf(ex) === Test.Base.prototype) + { + // + // For the 1.0 encoding, the unknown exception is sliced to Base. + // + test(prx.ice_getEncodingVersion().equals(Ice.Encoding_1_0)); + } + else if(Object.getPrototypeOf(ex) === Ice.UnknownUserException.prototype) + { + // + // An UnknownUserException is raised for the compact format because the + // most-derived type is unknown and the exception cannot be sliced. + // + test(!prx.ice_getEncodingVersion().equals(Ice.Encoding_1_0)); + } + else + { + test(false); + } + out.writeLine("ok"); + return prx.shutdown(); + } + ).then( + function() + { + p.succeed(); + }); + return p; + }; + + var run = function(out, id) + { + return Promise.try( + function() + { + var c = Ice.initialize(id); + return allTests(out, c).finally( + function() + { + if(c) + { + return c.destroy(); + } + }); + }); + }; + + global.__test__ = run; + global.__runServer__ = true; +}(typeof (global) === "undefined" ? window : global)); diff --git a/js/test/Ice/slicing/exceptions/Makefile b/js/test/Ice/slicing/exceptions/Makefile new file mode 100644 index 00000000000..e6856d287c7 --- /dev/null +++ b/js/test/Ice/slicing/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/slicing/exceptions/Makefile.mak b/js/test/Ice/slicing/exceptions/Makefile.mak new file mode 100644 index 00000000000..ee2ff1de5f1 --- /dev/null +++ b/js/test/Ice/slicing/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/slicing/exceptions/Test.ice b/js/test/Ice/slicing/exceptions/Test.ice new file mode 100644 index 00000000000..95d1d76e576 --- /dev/null +++ b/js/test/Ice/slicing/exceptions/Test.ice @@ -0,0 +1,98 @@ +// ********************************************************************** +// +// 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 + +module Test +{ + +exception Base +{ + string b; +}; + +exception KnownDerived extends Base +{ + string kd; +}; + +exception KnownIntermediate extends Base +{ + string ki; +}; + +exception KnownMostDerived extends KnownIntermediate +{ + string kmd; +}; + +["preserve-slice"] +exception KnownPreserved extends Base +{ + string kp; +}; + +exception KnownPreservedDerived extends KnownPreserved +{ + string kpd; +}; + +["preserve-slice"] +class BaseClass +{ + string bc; +}; + +["format:sliced"] +interface Relay +{ + void knownPreservedAsBase() throws Base; + void knownPreservedAsKnownPreserved() throws KnownPreserved; + + void unknownPreservedAsBase() throws Base; + void unknownPreservedAsKnownPreserved() throws KnownPreserved; +}; + +["format:sliced"] +interface TestIntf +{ + void baseAsBase() throws Base; + void unknownDerivedAsBase() throws Base; + void knownDerivedAsBase() throws Base; + void knownDerivedAsKnownDerived() throws KnownDerived; + + void unknownIntermediateAsBase() throws Base; + void knownIntermediateAsBase() throws Base; + void knownMostDerivedAsBase() throws Base; + void knownIntermediateAsKnownIntermediate() throws KnownIntermediate; + void knownMostDerivedAsKnownIntermediate() throws KnownIntermediate; + void knownMostDerivedAsKnownMostDerived() throws KnownMostDerived; + + void unknownMostDerived1AsBase() throws Base; + void unknownMostDerived1AsKnownIntermediate() throws KnownIntermediate; + void unknownMostDerived2AsBase() throws Base; + + ["format:compact"] void unknownMostDerived2AsBaseCompact() throws Base; + + void knownPreservedAsBase() throws Base; + void knownPreservedAsKnownPreserved() throws KnownPreserved; + + void relayKnownPreservedAsBase(Relay* r) throws Base; + void relayKnownPreservedAsKnownPreserved(Relay* r) throws KnownPreserved; + + void unknownPreservedAsBase() throws Base; + void unknownPreservedAsKnownPreserved() throws KnownPreserved; + + void relayUnknownPreservedAsBase(Relay* r) throws Base; + void relayUnknownPreservedAsKnownPreserved(Relay* r) throws KnownPreserved; + + void shutdown(); +}; + +}; diff --git a/js/test/Ice/slicing/exceptions/run.js b/js/test/Ice/slicing/exceptions/run.js new file mode 100644 index 00000000000..4906b3f4105 --- /dev/null +++ b/js/test/Ice/slicing/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/slicing/exceptions/run.py b/js/test/Ice/slicing/exceptions/run.py new file mode 100755 index 00000000000..c56059f657d --- /dev/null +++ b/js/test/Ice/slicing/exceptions/run.py @@ -0,0 +1,28 @@ +#!/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 sliced format.") +TestUtil.clientServerTest() + +print("Running test with 1.0 encoding.") +TestUtil.clientServerTest(additionalClientOptions="--Ice.Default.EncodingVersion=1.0", + additionalServerOptions="--Ice.Default.EncodingVersion=1.0") |