diff options
Diffstat (limited to 'js/test')
185 files changed, 19160 insertions, 0 deletions
diff --git a/js/test/Common/.gitignore b/js/test/Common/.gitignore new file mode 100644 index 00000000000..3738a532068 --- /dev/null +++ b/js/test/Common/.gitignore @@ -0,0 +1 @@ +Controller.js diff --git a/js/test/Common/Common.js b/js/test/Common/Common.js new file mode 100644 index 00000000000..ec1246fd0d3 --- /dev/null +++ b/js/test/Common/Common.js @@ -0,0 +1,48 @@ +// ********************************************************************** +// +// 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){ + require("Ice/Ice"); + + var write = function(msg) + { + process.stdout.write(msg); + }; + + var writeLine = function(msg) + { + this.write(msg + "\n"); + }; + + var run = function(module) + { + var id = new Ice.InitializationData(); + id.properties = Ice.createProperties(process.argv); + + module.require("./Client"); + var test = global.__test__; + + test({write: write, writeLine: writeLine}, id).exception( + function(ex, r) + { + console.log(ex.toString()); + if(r instanceof Ice.AsyncResult) + { + console.log("\nexception occurred in call to " + r.operation); + } + if(ex.stack) + { + console.log(ex.stack); + } + process.exit(1); + }); + }; + + module.exports = run; +}(typeof (global) === "undefined" ? window : global)); diff --git a/js/test/Common/Controller.ice b/js/test/Common/Controller.ice new file mode 100644 index 00000000000..65d0698913a --- /dev/null +++ b/js/test/Common/Controller.ice @@ -0,0 +1,24 @@ +// ********************************************************************** +// +// 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. +// +// ********************************************************************** + +module Test +{ + +interface Server +{ + void waitTestSuccess(); + void terminate(); +}; + +interface Controller +{ + Server* runServer(string lang, string name, string protocol, string host); +}; + +}; diff --git a/js/test/Common/Makefile b/js/test/Common/Makefile new file mode 100644 index 00000000000..6ffccef3825 --- /dev/null +++ b/js/test/Common/Makefile @@ -0,0 +1,16 @@ +# ********************************************************************** +# +# 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 = Controller.js + +include $(top_srcdir)/config/Make.rules.js + +SLICE2JSFLAGS := $(SLICE2JSFLAGS) -I$(slicedir) diff --git a/js/test/Common/Makefile.mak b/js/test/Common/Makefile.mak new file mode 100644 index 00000000000..93129494f44 --- /dev/null +++ b/js/test/Common/Makefile.mak @@ -0,0 +1,16 @@ +# ********************************************************************** +# +# 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 = Controller.js + +!include $(top_srcdir)\config\Make.rules.mak.js + +SLICE2JSFLAGS = $(SLICE2JSFLAGS) -I"$(slicedir)" diff --git a/js/test/Common/TestSuite.js b/js/test/Common/TestSuite.js new file mode 100644 index 00000000000..bd9671d7c7c --- /dev/null +++ b/js/test/Common/TestSuite.js @@ -0,0 +1,225 @@ +// ********************************************************************** +// +// 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. +// +// ********************************************************************** + +var communicator = Ice.initialize(); + +$(document).foundation(); + $(document).ready( + function(){ + $("#console").height(120); + $("#protocol").val(document.location.protocol == "https:" ? "wss" : "ws"); + for(var name in TestCases) + { + $("#test").append("<option value=\"" + basePath + name + "/index.html\">" + name + "</option>"); + } + $("#test").val(basePath + current + "/index.html"); + + + var out = + { + write: function(msg) + { + var text = $("#console").val(); + $("#console").val((text == "") ? msg : (text + msg)); + }, + writeLine: function(msg) + { + out.write(msg + "\n"); + $("#console").scrollTop($("#console").get(0).scrollHeight); + } + }; + + var protocol; + + $("#run").click(function(){ + if(!$(this).hasClass("disabled")) + { + $("#console").val(""); + $(this).addClass("disabled"); + $("#test").prop("disabled", "disabled"); + $("#protocol").prop("disabled", "disabled"); + var defaultHost = document.location.hostname || "127.0.0.1";; + + protocol = $("#protocol").val(); + var id = new Ice.InitializationData(); + id.properties = Ice.createProperties(); + id.properties.setProperty("Ice.Default.Host", defaultHost); + id.properties.setProperty("Ice.Default.Protocol", protocol); + + var str; + if(protocol == "ws") + { + str = "controller:ws -h " + defaultHost + " -p 12009"; + } + else + { + str = "controller:wss -h " + defaultHost + " -p 12008"; + } + var controller = Test.ControllerPrx.uncheckedCast(communicator.stringToProxy(str)); + + var p; + var server; + if(typeof(__runServer__) !== "undefined" || typeof(__runEchoServer__) !== "undefined") + { + if(typeof(__runEchoServer__) !== "undefined") + { + srv = "Ice/echo" + } + else + { + srv = current + } + out.write("starting " + srv + " server... "); + p = controller.runServer("cpp", srv, protocol, defaultHost).then( + function(proxy) + { + var ref = proxy.ice_getIdentity().name + ":" + protocol + " -h " + defaultHost + + " -p " + (protocol == "ws" ? "12009" : "12008"); + out.writeLine("ok"); + server = Test.ServerPrx.uncheckedCast(communicator.stringToProxy(ref)); + return __test__(out, id); + }, + function(ex) + { + out.writeLine("failed! (" + ex.ice_name() + ")"); + return __test__(out, id); + } + ).then( + function() + { + if(server) + { + return server.waitTestSuccess(); + } + } + ).exception( + function(ex) + { + if(server) + { + return server.terminate().then( + function() + { + throw ex; + }, + function() + { + throw ex; + }); + } + else + { + throw ex; + } + } + ); + } + else + { + p = __test__(out, id); + } + + p.finally( + function() + { + $("#test").prop("disabled", false); + $("#protocol").prop("disabled", false); + $("#run").removeClass("disabled"); + } + ).then( + function() + { + if($("#loop").is(":checked")) + { + var location = document.location; + var href = location.protocol + "//" + location.hostname; + if(protocol == "wss") + { + href += ":9090"; + } + else + { + href += ":8080"; + } + href += location.pathname.replace(current, next) + "?loop=true"; + document.location.assign(href); + } + } + ).exception( + function(ex, r) + { + out.writeLine(""); + if(r instanceof Ice.AsyncResult) + { + out.writeLine("exception occurred in call to " + r.operation); + } + out.writeLine(ex.toString()); + if(ex.stack) + { + out.writeLine(ex.stack); + } + }); + } + return false; + }); + + (function(){ + + if(basePath == "../../../") + { + $(".title-area a").attr("href", "../../../../index.html"); + $(".breadcrumbs li:first a").attr("href", "../../../../index.html"); + } + + // + // Check if we should start the test loop=true + // + var href = document.location.href; + var i = href.indexOf("?"); + var autoStart = i !== -1 && href.substr(i).indexOf("loop=true") !== -1; + if(autoStart) + { + $("#loop").prop("checked", true); + $("#run").click(); + } + }()); + + // + // Test case + // + $("#test").on("change", + function(e) + { + document.location.assign($(this).val()); + return false; + }); + // + // Protocol + // + $("#protocol").on("change", + function(e) + { + var newProtocol = $(this).val(); + if(protocol !== newProtocol) + { + var href = document.location.protocol + "//" + document.location.host + document.location.pathname; + if(newProtocol == "ws") + { + href = href.replace("https", "http"); + href = href.replace("9090", "8080"); + } + else + { + href = href.replace("http", "https"); + href = href.replace("8080", "9090"); + } + document.location.assign(href); + } + }); + }); diff --git a/js/test/Common/index.html b/js/test/Common/index.html new file mode 100644 index 00000000000..9738ef509e0 --- /dev/null +++ b/js/test/Common/index.html @@ -0,0 +1,195 @@ +<!doctype html> +<html class="no-js" lang="en"> + <head> + <meta charset="utf-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <title>Test Suite | Ice for JavaScript</title> + <link rel="icon" type="image/x-icon" href="/assets/favicon.ico"/> + </head> + <body> + <div id="header"> + <nav class="top-bar" data-topbar> + <ul class="title-area"> + <li class="name"> + <h1><a href="../../../index.html">Ice for JavaScript</a></h1> + </li> + <li class="toggle-topbar menu-icon"><a href="#">Menu</a></li> + </ul> + <section class="top-bar-section"> + <!-- Right Nav Section --> + <ul class="right"> + <li class="divider"></li> + <li><a href="#" id="viewReadme">Readme</a></li> + </ul> + </section> + </nav> + <ul class="breadcrumbs"> + <li><a href="../../../index.html">Ice</a></li> + <li class="current"><a href="#">Test</a></li> + </ul> + </div> + <section role="main" id="body"> + <div class="row"> + <div class="large-12 medium-12 columns"> + <form> + <div class="row"> + <div class="small-3 columns"> + <label class="right inline">Test:</label> + </div> + <div class="small-9 columns"> + <select id="test"> + </select> + </div> + </div> + <div class="row"> + <div class="small-3 columns"> + <label class="right inline">Protocol:</label> + </div> + <div class="small-9 columns"> + <select id="protocol"> + <option value="ws">WS</option> + <option value="wss">WSS</option> + </select> + </div> + </div> + <div class="row"> + <div class="small-3 columns"> + <label class="right inline" for="loop">Loop:</label> + </div> + <div class="small-9 columns"> + <input id="loop" type="checkbox"/> + </div> + </div> + <a href="#" class="button" id="run">Run</a> + <textarea id="console" class="disabled" readonly></textarea> + </form> + </div> + </div> + </section> + <!-- Modal dialog to show the client README --> + <div id="readme-modal" class="reveal-modal" data-reveal> + <a class="close-reveal-modal">×</a> + <h4>Test Suite Readme</h4> + <hr/> + <p>For instructions on how to run this test suite, please refer to the Ice for JavaScript + <a href="http://doc.zeroc.com/display/Rel/Ice+for+JavaScript+0.1.0+Release+Notes">Release Notes</a>.</p> + </div> + <!-- Modal dialog with setup instructions --> + <div id="setup-modal" class="reveal-modal" data-reveal> + <h3>The Ice for JavaScript tests require a web server. Please follow these steps to run the test suite:</h3> + <hr/> + <ul> + <li>To run the browser tests, you will need to run the test HTTP server with the + test/Common/run.py script. This script requires Ice for Python and the IceWS transport. + Follow the instructions from your Ice distribution to setup the environment for + Ice for Python.<br/> + Run the following to start the HTTP server: + <pre>python test/Common/run.py</pre></li> + <li>Now you can run the test by navigating to <a class="go" href=""></a></li> + </ul> + </div> + <div id="footer"> + <div class="logo"> + <h4><strong>ZeroC</strong></h4> + </div> + <div class="copyright"> + <h6>© 2014 ZeroC, Inc. All rights reserved.</h6> + </div> + </div> + <script type="text/javascript"> + var TestCases = { + "Ice/binding": ["Test.js", "Client.js"], + "Ice/defaultValue": ["Test.js", "Client.js"], + "Ice/enums": ["Test.js", "Client.js"], + "Ice/exceptions": ["Test.js", "Client.js"], + "Ice/exceptionsBidir": ["Test.js", "TestAMD.js", "ThrowerI.js", "AMDThrowerI.js", + "../exceptions/Client.js", "Client.js"], + "Ice/facets": ["Test.js", "Client.js"], + "Ice/facetsBidir": ["Test.js", "TestI.js", "../facets/Client.js", "Client.js"], + "Ice/inheritance": ["Test.js", "Client.js"], + "Ice/inheritanceBidir": ["Test.js", "InitialI.js", "../inheritance/Client.js", "Client.js"], + "Ice/operations": ["Test.js", "Twoways.js", "Oneways.js", "BatchOneways.js", "Client.js"], + "Ice/operationsBidir": ["Test.js", "TestAMD.js", "../operations/Twoways.js", "../operations/Oneways.js", + "../operations/BatchOneways.js", "MyDerivedClassI.js", "AMDMyDerivedClassI.js", + "../operations/Client.js", "Client.js"], + "Ice/objects": ["Test.js", "Client.js"], + "Ice/optional": ["Test.js", "Client.js"], + "Ice/optionalBidir": ["Test.js", "TestAMD.js", "InitialI.js", "AMDInitialI.js", + "../optional/Client.js", "Client.js"], + "Ice/promise": ["Client.js"], + "Ice/proxy": ["Test.js", "Client.js"], + "Ice/retry": ["Test.js", "Client.js"], + "Ice/slicing/exceptions": ["Test.js", "Client.js"], + "Ice/slicing/objects": ["Test.js", "Client.js"], + "Ice/timeout": ["Test.js", "Client.js"] + }; + + var current, next; + var basePath = "../../"; + for(name in TestCases) + { + if(current) + { + next = name; + break; + } + + if(document.location.pathname.indexOf(name + "/index.html") !== -1) + { + current = name; + if(name.split("/").length === 3) + { + basePath = "../../../"; + } + } + } + if(!next) + { + next = "Ice/binding"; + } + + scripts = [ + basePath + "../assets/common.min.js", + basePath + "../lib/Ice.js" + ]; + + TestCases[current].forEach( + function(script) + { + scripts.push(script); + }); + scripts.push(basePath + "Common/Controller.js"); + scripts.push(basePath + "Common/TestSuite.js"); + + var head = document.getElementsByTagName("head")[0]; + + var link = document.createElement("link"); + link.rel = "stylesheet"; + link.href = basePath + "../assets/common.css"; + head.appendChild(link); + + function loadScript() + { + if(scripts.length > 0) + { + var script = document.createElement("script"); + script.type = "text/javascript"; + script.src = scripts.shift(); + + var loaded = false; + + script.onload = script.onreadystatechange = function() + { + if(!loaded && (!this.readyState || this.readyState == "complete" || this.readyState == "loaded")) + { + loaded = true; + loadScript(); + } + }; + head.appendChild(script); + } + } + loadScript(); + </script> + </body> +</html> diff --git a/js/test/Common/run.py b/js/test/Common/run.py new file mode 100755 index 00000000000..e406f510875 --- /dev/null +++ b/js/test/Common/run.py @@ -0,0 +1,168 @@ +#!/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, threading, subprocess + +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 + +# +# Run the script with the environment correctly set. +# +if os.environ.get("RUNNING_TEST_CONTROLLER_WITH_ENV", "") == "": + env = TestUtil.getTestEnv("cpp", os.getcwd()) + env["RUNNING_TEST_CONTROLLER_WITH_ENV"] = "yes" + sys.exit(os.spawnve(os.P_WAIT, sys.executable, [sys.executable, "run.py"], env)) + +import Ice, Expect +Ice.loadSlice("\"" + os.path.join(TestUtil.toplevel, "js", "test", "Common", "Controller.ice") + "\"") +import Test + +class ServerI(Test.Server): + def __init__(self, name, process): + self.name = name + self.process = process + + def waitTestSuccess(self, current): + if not self.process: + return + sys.stdout.write("waiting for " + self.name + " to terminate... ") + sys.stdout.flush() + self.process.waitTestSuccess() + self.process = None + try: + current.adapter.remove(current.id) + except: + pass + print("ok") + + def terminate(self, current): + if not self.process: + return + sys.stdout.write("terminating " + self.name + "... ") + sys.stdout.flush() + self.process.terminate() + self.process = None + try: + current.adapter.remove(current.id) + except: + pass + print("ok") + +class ControllerI(Test.Controller): + def __init__(self): + self.currentServer = None + + def runServer(self, lang, name, protocol, host, current): + + # If server is still running, terminate it + if self.currentServer: + try: + self.currentServer.terminate() + except: + pass + self.currentServer = None + + pwd = os.getcwd() + try: + # Change current directory to the test directory + serverdir = os.path.join(TestUtil.toplevel, lang, "test", name) + os.chdir(serverdir) + + serverDesc = os.path.join(lang, "test", name) + lang = TestUtil.getDefaultMapping() + server = os.path.join(serverdir, TestUtil.getDefaultServerFile()) + serverenv = TestUtil.getTestEnv(lang, serverdir) + + sys.stdout.write("starting " + serverDesc + "... ") + sys.stdout.flush() + serverCfg = TestUtil.DriverConfig("server") + serverCfg.protocol = protocol + serverCfg.host = host + server = TestUtil.getCommandLine(server, serverCfg) + serverProc = TestUtil.spawnServer(server, env = serverenv, lang=serverCfg.lang, mx=serverCfg.mx) + print("ok") + finally: + os.chdir(pwd) + + self.currentServer = Test.ServerPrx.uncheckedCast(current.adapter.addWithUUID(ServerI(serverDesc, serverProc))) + return self.currentServer + +class Reader(threading.Thread): + def __init__(self, p): + self.p = p + threading.Thread.__init__(self) + + def run(self): + while True: + line = self.p.stdout.readline() + if self.p.poll() is not None and not line: + #process terminated + return self.p.poll() + if type(line) != str: + line = line.decode() + sys.stdout.write(line) + sys.stdout.flush() + +class Server(Ice.Application): + def run(self, args): + jsDir = os.path.join(TestUtil.toplevel, "js") + httpServer = subprocess.Popen("node \"" + os.path.join(jsDir, "bin", "HttpServer.js") + "\"", shell = True, + stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.STDOUT, + bufsize = 0) + # + # Wait for the HttpServer to start + # + while True: + line = httpServer.stdout.readline() + if httpServer.poll() is not None and not line: + #process terminated + return httpServer.poll() + if type(line) != str: + line = line.decode() + sys.stdout.write(line) + sys.stdout.flush() + if line.find("listening on ports 8080 (http) and 9090 (https)...") != -1: + break + + reader = Reader(httpServer) + reader.start() + + adapter = self.communicator().createObjectAdapter("ControllerAdapter") + adapter.add(ControllerI(), self.communicator().stringToIdentity("controller")) + adapter.activate() + self.communicator().waitForShutdown() + + if httpServer.poll() is None: + httpServer.terminate() + + reader.join() + return 0 + +app = Server() +initData = Ice.InitializationData() +initData.properties = Ice.createProperties(); +initData.properties.setProperty("Ice.Plugin.IceSSL", "IceSSL:createIceSSL") +initData.properties.setProperty("IceSSL.DefaultDir", os.path.join(TestUtil.toplevel, "certs")); +initData.properties.setProperty("IceSSL.CertAuthFile", "cacert.pem"); +initData.properties.setProperty("IceSSL.CertFile", "s_rsa1024_pub.pem"); +initData.properties.setProperty("IceSSL.KeyFile", "s_rsa1024_priv.pem"); +initData.properties.setProperty("IceSSL.VerifyPeer", "0"); +initData.properties.setProperty("Ice.Plugin.IceWS", "IceWS:createIceWS") +initData.properties.setProperty("Ice.ThreadPool.Server.SizeMax", "10") +initData.properties.setProperty("ControllerAdapter.Endpoints", "ws -p 12009:wss -p 12008") +sys.exit(app.main(sys.argv, initData=initData)) diff --git a/js/test/Glacier2/Makefile b/js/test/Glacier2/Makefile new file mode 100644 index 00000000000..a50f2198f58 --- /dev/null +++ b/js/test/Glacier2/Makefile @@ -0,0 +1,22 @@ +# ********************************************************************** +# +# 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 = ../.. + +include $(top_srcdir)/config/Make.rules.js + +SUBDIRS = router + +$(EVERYTHING):: + @for subdir in $(SUBDIRS); \ + do \ + echo "making $@ in $$subdir"; \ + ( cd $$subdir && $(MAKE) $@ ) || exit 1; \ + done + diff --git a/js/test/Glacier2/Makefile.mak b/js/test/Glacier2/Makefile.mak new file mode 100644 index 00000000000..13de44aa301 --- /dev/null +++ b/js/test/Glacier2/Makefile.mak @@ -0,0 +1,19 @@ +# ********************************************************************** +# +# 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 = ..\.. + +!include $(top_srcdir)\config\Make.rules.mak.js + +SUBDIRS = router + +$(EVERYTHING):: + @for %i in ( $(SUBDIRS) ) do \ + @echo "making $@ in %i" && \ + cmd /c "cd %i && $(MAKE) -nologo -f Makefile.mak $@" || exit 1 diff --git a/js/test/Glacier2/router/.gitignore b/js/test/Glacier2/router/.gitignore new file mode 100644 index 00000000000..ecb071cb842 --- /dev/null +++ b/js/test/Glacier2/router/.gitignore @@ -0,0 +1,2 @@ +Callback.js +index.html diff --git a/js/test/Glacier2/router/Callback.ice b/js/test/Glacier2/router/Callback.ice new file mode 100644 index 00000000000..2261297a889 --- /dev/null +++ b/js/test/Glacier2/router/Callback.ice @@ -0,0 +1,39 @@ +// ********************************************************************** +// +// 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 CallbackException +{ + double someValue; + string someString; +}; + +interface CallbackReceiver +{ + void callback(); + + void callbackEx() + throws CallbackException; +}; + +interface Callback +{ + void initiateCallback(CallbackReceiver* proxy); + + void initiateCallbackEx(CallbackReceiver* proxy) + throws CallbackException; + + void shutdown(); +}; + +}; diff --git a/js/test/Glacier2/router/Client.js b/js/test/Glacier2/router/Client.js new file mode 100644 index 00000000000..bc29d4fdc6c --- /dev/null +++ b/js/test/Glacier2/router/Client.js @@ -0,0 +1,406 @@ +// ********************************************************************** +// +// 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("Glacier2/Glacier2"); + + var Ice = global.Ice; + + require("Callback"); + var Test = global.Test; + var Promise = Ice.Promise; + var Debug = Ice.Debug; + + var test = function(b) + { + if(!b) + { + throw new Error("test failed"); + } + }; + + var CallbackPrx = Test.CallbackPrx; + var CallbackReceiverPrx = Test.CallbackReceiverPrx; + + var CallbackReceiverI = function() + { + this._callback = false; + this._p = new Promise(); + }; + CallbackReceiverI.prototype = new Test.CallbackReceiver(); + CallbackReceiverI.prototype.constructor = CallbackReceiverI; + + CallbackReceiverI.prototype.callback = function(current) + { + Debug.assert(!this._callback); + this._p.succeed(); + }; + + CallbackReceiverI.prototype.callbackEx = function(current) + { + this.callback(current); + var ex = new Test.CallbackException(); + ex.someValue = 3.14; + ex.someString = "3.14"; + throw ex; + }; + + CallbackReceiverI.prototype.callbackOK = function() + { + var p = new Promise(); + var self = this; + this._p.then(function(){ + p.succeed(); + this._callback = false; + self._p = new Promise(); + }); + return p; + }; + + var allTests = function(out, communicator) + { + var p = new Promise(); + + var failCB = function () { test(false); } + + var router, base, session, twoway, oneway, category, processBase, process, + adapter,callbackReceiverImpl, + callbackReceiver, + twowayR, onewayR, + fakeTwowayR; + + return Promise.try( + function() + { + out.write("testing stringToProxy for router... "); + var routerBase = communicator.stringToProxy("Glacier2/router:default -p 12347"); + test(routerBase !== null); + out.writeLine("ok"); + + out.write("testing checked cast for router... "); + return Glacier2.RouterPrx.checkedCast(routerBase); + } + ).then( + function(o) + { + router = o; + test(router !== null); + out.writeLine("ok"); + + out.write("installing router with communicator... "); + communicator.setDefaultRouter(router); + out.writeLine("ok"); + + out.write("getting the session timeout... "); + return router.getSessionTimeout(); + } + ).then( + function(timeout) + { + test(timeout.low === 30); + out.writeLine("ok"); + + out.write("testing stringToProxy for server object... "); + base = communicator.stringToProxy("c1/callback:tcp -p 12010"); + out.writeLine("ok"); + + out.write("trying to ping server before session creation... "); + return base.ice_ping(); + } + ).then( + failCB, + function(ex) + { + test(ex instanceof Ice.ConnectionLostException); + out.writeLine("ok"); + out.write("trying to create session with wrong password... "); + return router.createSession("userid", "xxx"); + } + ).then( + failCB, + function(ex) + { + test(ex instanceof Glacier2.PermissionDeniedException); + out.writeLine("ok"); + + out.write("trying to destroy non-existing session... "); + return router.destroySession(); + } + ).then( + failCB, + function(ex) + { + test(ex instanceof Glacier2.SessionNotExistException); + out.writeLine("ok"); + + out.write("creating session with correct password... "); + return router.createSession("userid", "abc123"); + } + ).then( + function(s) + { + session = s; + out.writeLine("ok"); + + out.write("trying to create a second session... "); + return router.createSession("userid", "abc123"); + } + ).then( + failCB, + function(ex) + { + test(ex instanceof Glacier2.CannotCreateSessionException); + out.writeLine("ok"); + + out.write("pinging server after session creation... "); + return base.ice_ping(); + } + ).then( + function() + { + out.writeLine("ok"); + + out.write("testing checked cast for server object... "); + return Test.CallbackPrx.checkedCast(base); + } + ).then( + function(o) + { + twoway = o; + test(twoway !== null); + out.writeLine("ok"); + out.write("creating and activating callback receiver adapter... "); + communicator.getProperties().setProperty("Ice.PrintAdapterReady", "0"); + return communicator.createObjectAdapterWithRouter("CallbackReceiverAdapter", router); + } + ).then( + function(o) + { + adapter = o; + return adapter.activate(); + } + ).then( + function() + { + out.writeLine("ok"); + out.write("getting category from router... "); + return router.getCategoryForClient(); + } + ).then( + function(c) + { + category = c; + out.writeLine("ok"); + out.write("creating and adding callback receiver object... "); + callbackReceiverImpl = new CallbackReceiverI(); + callbackReceiver = callbackReceiverImpl; + var callbackReceiverIdent = new Ice.Identity(); + callbackReceiverIdent.name = "callbackReceiver"; + callbackReceiverIdent.category = category; + twowayR = CallbackReceiverPrx.uncheckedCast(adapter.add(callbackReceiver, callbackReceiverIdent)); + var fakeCallbackReceiverIdent = new Ice.Identity(); + fakeCallbackReceiverIdent.name = "callbackReceiver"; + fakeCallbackReceiverIdent.category = "dummy"; + fakeTwowayR = CallbackReceiverPrx.uncheckedCast( + adapter.add(callbackReceiver, fakeCallbackReceiverIdent)); + } + ).then( + function() + { + out.writeLine("ok"); + out.write("testing oneway callback... "); + oneway = CallbackPrx.uncheckedCast(twoway.ice_oneway()); + onewayR = CallbackReceiverPrx.uncheckedCast(twowayR.ice_oneway()); + var context = new Ice.Context(); + context.set("_fwd", "o"); + return oneway.initiateCallback(onewayR, context); + } + ).then( + function() + { + return callbackReceiverImpl.callbackOK(); + } + ).then( + function() + { + out.writeLine("ok"); + out.write("testing twoway callback... "); + var context = new Ice.Context(); + context.set("_fwd", "t"); + return twoway.initiateCallback(twowayR, context); + } + ).then( + function() + { + return callbackReceiverImpl.callbackOK(); + } + ).then( + function() + { + out.writeLine("ok"); + out.write("ditto, but with user exception... "); + var context = new Ice.Context(); + context.set("_fwd", "t"); + return twoway.initiateCallbackEx(twowayR, context); + } + ).then( + failCB, + function(ex) + { + test(ex instanceof Test.CallbackException); + test(ex.someValue == 3.14); + test(ex.someString == "3.14"); + return callbackReceiverImpl.callbackOK(); + } + ).then( + function() + { + out.writeLine("ok"); + out.write("trying twoway callback with fake category... "); + var context = new Ice.Context(); + context.set("_fwd", "t"); + return twoway.initiateCallback(fakeTwowayR, context); + } + ).then( + failCB, + function(ex) + { + test(ex instanceof Ice.ObjectNotExistException); + out.writeLine("ok"); + out.write("testing whether other allowed category is accepted... "); + var context = new Ice.Context(); + context.set("_fwd", "t"); + var otherCategoryTwoway = CallbackPrx.uncheckedCast( + twoway.ice_identity(communicator.stringToIdentity("c2/callback"))); + return otherCategoryTwoway.initiateCallback(twowayR, context); + } + ).then( + function() + { + return callbackReceiverImpl.callbackOK(); + } + ).then( + function() + { + out.writeLine("ok"); + out.write("testing whether disallowed category gets rejected... "); + var context = new Ice.Context(); + context.set("_fwd", "t"); + var otherCategoryTwoway = CallbackPrx.uncheckedCast( + twoway.ice_identity(communicator.stringToIdentity("c3/callback"))); + return otherCategoryTwoway.initiateCallback(twowayR, context); + } + ).then( + failCB, + function(ex) + { + test(ex instanceof Ice.ObjectNotExistException); + out.writeLine("ok"); + out.write("testing whether user-id as category is accepted... "); + var context = new Ice.Context(); + context.set("_fwd", "t"); + var otherCategoryTwoway = CallbackPrx.uncheckedCast( + twoway.ice_identity(communicator.stringToIdentity("_userid/callback"))); + return otherCategoryTwoway.initiateCallback(twowayR, context); + } + ).then( + function() + { + return callbackReceiverImpl.callbackOK(); + } + ).then( + function() + { + out.writeLine("ok"); + out.write("testing server shutdown... "); + return twoway.shutdown(); + // No ping, otherwise the router prints a warning message if it's + // started with --Ice.Warn.Connections. + } + ).then( + function() + { + out.writeLine("ok"); + + out.write("destroying session... "); + return router.destroySession(); + } + ).then( + function() + { + out.writeLine("ok"); + + out.write("trying to ping server after session destruction... "); + return base.ice_ping(); + } + ).then( + failCB, + function(ex) + { + test(ex instanceof Ice.ConnectionLostException); + out.writeLine("ok"); + + out.write("uninstalling router with communicator... "); + communicator.setDefaultRouter(null); + out.writeLine("ok"); + + out.write("testing stringToProxy for process object... "); + processBase = communicator.stringToProxy("Glacier2/admin -f Process:tcp -h 127.0.0.1 -p 12348"); + out.writeLine("ok"); + + out.write("testing checked cast for admin object... "); + return Ice.ProcessPrx.checkedCast(processBase); + } + ).then( + function(o) + { + process = o; + test(process !== null); + out.writeLine("ok"); + + out.write("testing Glacier2 shutdown... "); + return process.shutdown(); + } + ).then( + function() + { + return process.ice_ping(); + } + ).then( + failCB, + function(ex) + { + test(ex instanceof Ice.LocalException); + out.writeLine("ok"); + } + ); + }; + + var run = function(out, id) + { + return Promise.try( + function() + { + id.properties.setProperty("Ice.Warn.Dispatch", "1"); + id.properties.setProperty("Ice.Warn.Connections", "0"); + var c = Ice.initialize(id); + return allTests(out, c).finally( + function() + { + if(c) + { + return c.destroy(); + } + }); + }); + }; + global.__test__ = run; +}(typeof (global) === "undefined" ? window : global)); diff --git a/js/test/Glacier2/router/Makefile b/js/test/Glacier2/router/Makefile new file mode 100644 index 00000000000..f80f63801e5 --- /dev/null +++ b/js/test/Glacier2/router/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 = Callback.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/Glacier2/router/Makefile.mak b/js/test/Glacier2/router/Makefile.mak new file mode 100644 index 00000000000..5f1ad83301f --- /dev/null +++ b/js/test/Glacier2/router/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 = Callback.js + +SRCS = Client.js + +!include $(top_srcdir)\config\Make.rules.mak.js + +SLICE2JSFLAGS = $(SLICE2JSFLAGS) -I"$(slicedir)" diff --git a/js/test/Glacier2/router/Test.ice b/js/test/Glacier2/router/Test.ice new file mode 100644 index 00000000000..b8cc98ca9ca --- /dev/null +++ b/js/test/Glacier2/router/Test.ice @@ -0,0 +1,188 @@ +// ********************************************************************** +// +// 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 +{ + +struct S +{ + string str; +}; + +class Base +{ + S theS; + string str; +}; + +class AbstractBase extends Base +{ + void op(); +}; + +class B; +class C; + +class A +{ + B theB; + C theC; + + bool preMarshalInvoked; + bool postUnmarshalInvoked(); +}; + +class B extends A +{ + A theA; +}; + +class C +{ + B theB; + + bool preMarshalInvoked; + bool postUnmarshalInvoked(); +}; + +class D +{ + A theA; + B theB; + C theC; + + bool preMarshalInvoked; + bool postUnmarshalInvoked(); +}; + +["protected"] class E +{ + int i; + string s; + + bool checkValues(); +}; + +class F +{ + ["protected"] E e1; + E e2; + + bool checkValues(); +}; + +interface I +{ + void doI(); +}; + +interface J extends I +{ + void doJ(); +}; + +class H implements I +{ + void doH(); + void doH2(); +}; + +sequence<Base> BaseSeq; + +class CompactExt; + +class Compact(1) +{ +}; + +const int CompactExtId = 789; + +class CompactExt(CompactExtId) extends Compact +{ +}; + +class Initial +{ + void shutdown(); + B getB1(); + B getB2(); + C getC(); + D getD(); + E getE(); + F getF(); + + void getAll(out B b1, out B b2, out C theC, out D theD); + + I getI(); + I getJ(); + I getH(); + + void setI(I theI); + + BaseSeq opBaseSeq(BaseSeq inSeq, out BaseSeq outSeq); + + Compact getCompact(); +}; + +class Empty +{ +}; + +class AlsoEmpty +{ +}; + +interface UnexpectedObjectExceptionTest +{ + Empty op(); +}; + +// +// Remaining definitions are here to ensure that the generated code compiles. +// + +class COneMember +{ + Empty e; +}; + +class CTwoMembers +{ + Empty e1; + Empty e2; +}; + +exception EOneMember +{ + Empty e; +}; + +exception ETwoMembers +{ + Empty e1; + Empty e2; +}; + +struct SOneMember +{ + Empty e; +}; + +struct STwoMembers +{ + Empty e1; + Empty e2; +}; + +dictionary<int, COneMember> DOneMember; +dictionary<int, CTwoMembers> DTwoMembers; + +}; diff --git a/js/test/Glacier2/router/passwords b/js/test/Glacier2/router/passwords new file mode 100644 index 00000000000..a1527dec2b9 --- /dev/null +++ b/js/test/Glacier2/router/passwords @@ -0,0 +1 @@ +userid xxMqsnnDcK8tw
\ No newline at end of file diff --git a/js/test/Glacier2/router/run.js b/js/test/Glacier2/router/run.js new file mode 100644 index 00000000000..a875f421701 --- /dev/null +++ b/js/test/Glacier2/router/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/Glacier2/router/run.py b/js/test/Glacier2/router/run.py new file mode 100755 index 00000000000..04f4d7f5287 --- /dev/null +++ b/js/test/Glacier2/router/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 + +router = os.path.join(TestUtil.getCppBinDir(), "glacier2router") + +args = ' --Ice.Warn.Dispatch=0' + \ + ' --Ice.Warn.Connections=0' + \ + ' --Glacier2.Filter.Category.Accept="c1 c2"' + \ + ' --Glacier2.Filter.Category.AcceptUser="2"' + \ + ' --Glacier2.SessionTimeout="30"' + \ + ' --Glacier2.Client.Endpoints="default -p 12347"' + \ + ' --Glacier2.Server.Endpoints="tcp -h 127.0.0.1"' \ + ' --Ice.Admin.Endpoints="tcp -h 127.0.0.1 -p 12348"' + \ + ' --Ice.Admin.InstanceName=Glacier2' + \ + ' --Glacier2.CryptPasswords="' + os.path.join(os.getcwd(), "passwords") + '"' + +sys.stdout.write("starting router... ") +sys.stdout.flush() +routerConfig = TestUtil.DriverConfig("server") +routerConfig.lang = "cpp" +starterProc = TestUtil.startServer(router, args, count=2, config=routerConfig) +print("ok") + +TestUtil.clientServerTest() + +starterProc.waitTestSuccess() diff --git a/js/test/Ice/Makefile b/js/test/Ice/Makefile new file mode 100644 index 00000000000..d33bba96981 --- /dev/null +++ b/js/test/Ice/Makefile @@ -0,0 +1,41 @@ +# ********************************************************************** +# +# 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 = ../.. + +include $(top_srcdir)/config/Make.rules.js + +SUBDIRS = binding \ + defaultValue \ + enums \ + exceptions \ + exceptionsBidir \ + facets \ + facetsBidir \ + inheritance \ + inheritanceBidir \ + location \ + objects \ + operations \ + operationsBidir \ + optional \ + optionalBidir \ + promise \ + proxy \ + retry \ + slicing \ + timeout + +$(EVERYTHING):: + @for subdir in $(SUBDIRS); \ + do \ + echo "making $@ in $$subdir"; \ + ( cd $$subdir && $(MAKE) $@ ) || exit 1; \ + done + diff --git a/js/test/Ice/Makefile.mak b/js/test/Ice/Makefile.mak new file mode 100644 index 00000000000..50051b4f0cd --- /dev/null +++ b/js/test/Ice/Makefile.mak @@ -0,0 +1,38 @@ +# ********************************************************************** +# +# 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 = ..\.. + +!include $(top_srcdir)\config\Make.rules.mak.js + +SUBDIRS = binding \ + defaultValue \ + enums \ + exceptions \ + exceptionsBidir \ + facets \ + facetsBidir \ + inheritance \ + inheritanceBidir \ + location \ + objects \ + operations \ + operationsBidir \ + optional \ + optionalBidir \ + promise \ + proxy \ + retry \ + slicing \ + timeout + +$(EVERYTHING):: + @for %i in ( $(SUBDIRS) ) do \ + @echo "making $@ in %i" && \ + cmd /c "cd %i && $(MAKE) -nologo -f Makefile.mak $@" || exit 1 diff --git a/js/test/Ice/binding/.gitignore b/js/test/Ice/binding/.gitignore new file mode 100644 index 00000000000..d158d9308ba --- /dev/null +++ b/js/test/Ice/binding/.gitignore @@ -0,0 +1,2 @@ +Test.js +index.html diff --git a/js/test/Ice/binding/Client.js b/js/test/Ice/binding/Client.js new file mode 100644 index 00000000000..17e92ad6cb2 --- /dev/null +++ b/js/test/Ice/binding/Client.js @@ -0,0 +1,1170 @@ +// ********************************************************************** +// +// 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 forEach = function(array, fn) + { + if(array.length === 0) + { + return new Promise.succeed(); + } + var p = null; + array.forEach(function(e) + { + p = p ? p.then(fn(e)) : fn(e); + }); + return p; + } + + var communicator; + var com; + var allTests = function(out, initData) + { + var initialize = function() + { + return Promise.try( + function() + { + if(communicator) + { + return communicator.destroy().then( + function() + { + communicator = Ice.initialize(initData); + com = Test.RemoteCommunicatorPrx.uncheckedCast( + communicator.stringToProxy("communicator:default -p 12010")); + }); + } + else + { + communicator = Ice.initialize(initData); + } + }); + }; + + var createTestIntfPrx = function(adapters) + { + var endpoints = []; + var closePromises = []; + var p = null; + + return Promise.all(adapters.map(function(adapter){ return adapter.getTestIntf(); })).then( + function() + { + var results = Array.prototype.slice.call(arguments); + results.forEach( + function(r) + { + p = r[0]; + test(p); + endpoints = endpoints.concat(p.ice_getEndpoints()); + } + ); + return Test.TestIntfPrx.uncheckedCast(p.ice_endpoints(endpoints)); + }); + }; + + var deactivate = function(communicator, adapters) + { + var f1 = function(adapters) + { + var adapter = adapters.shift(); + communicator.deactivateObjectAdapter(adapter).then( + function() + { + if(adapters.length > 0) + { + f1(adapters) + } + } + ); + }; + return f1(ArrayUtil.clone(adapters)); + }; + + 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 ref, adapter, test1, test2, test3, conn1, conn2, conn3, adapters, names, prx; + + Promise.try( + function() + { + return initialize(); + } + ).then( + function() + { + out.write("testing stringToProxy... "); + ref = "communicator:default -p 12010"; + com = Test.RemoteCommunicatorPrx.uncheckedCast(communicator.stringToProxy(ref)); + test(com !== null); + out.writeLine("ok"); + + out.write("testing binding with single endpoint... "); + adapter, test1, test2, test3, conn1, conn2, conn3; + adapters = []; + names = ["Adapter11", "Adapter12", "Adapter13"]; + + return com.createObjectAdapter("Adapter", "default"); + } + ).then( + function(obj) + { + adapter = obj; + return Promise.all(adapter.getTestIntf(), adapter.getTestIntf()); + } + ).then( + function(r1, r2) + { + test1 = r1[0]; + test2 = r2[0]; + + return Promise.all(test1.ice_getConnection(), test2.ice_getConnection()); + } + ).then( + function(r1, r2) + { + conn1 = r1[0]; + conn2 = r2[0]; + test(conn1 === conn2); + return Promise.all(test1.ice_ping(), test2.ice_ping()); + } + ).then( + function(r1, r2) + { + return com.deactivateObjectAdapter(adapter); + } + ).then( + function() + { + test3 = Test.TestIntfPrx.uncheckedCast(test1); + return Promise.all(test3.ice_getConnection(), test1.ice_getConnection()); + } + ).then( + function(r1, r2) + { + conn3 = r1[0]; + conn1 = r2[0]; + test(conn3 === conn1); + return Promise.all(test3.ice_getConnection(), test2.ice_getConnection()); + } + ).then( + function(r1, r2) + { + conn3 = r1[0]; + conn2 = r2[0]; + test(conn3 === conn2); + return test3.ice_ping(); + } + ).then( + function() + { + test(false); + }, + function(ex) + { + if(!(typeof(window) == 'undefined' && ex instanceof Ice.ConnectionRefusedException) && + !(typeof(window) != 'undefined' && ex instanceof Ice.ConnectFailedException)) + { + throw ex; + } + out.writeLine("ok"); + return initialize(); + } + ).then( + function() + { + out.write("testing binding with multiple endpoints... "); + + return Promise.all( + com.createObjectAdapter("Adapter11", "default"), + com.createObjectAdapter("Adapter12", "default"), + com.createObjectAdapter("Adapter13", "default")); + } + ).then( + // + // Ensure that when a connection is opened it's reused for new + // proxies and that all endpoints are eventually tried. + // + function(r1, r2, r3) + { + adapters.push(r1[0]); + adapters.push(r2[0]); + adapters.push(r3[0]); + + var f1 = function(names) + { + var adpts = ArrayUtil.clone(adapters); + return createTestIntfPrx(adpts).then( + function(obj) + { + test1 = obj; + ArrayUtil.shuffle(adpts); + return createTestIntfPrx(adpts); + } + ).then( + function(obj) + { + test2 = obj; + ArrayUtil.shuffle(adpts); + return createTestIntfPrx(adpts); + } + ).then( + function(obj) + { + test3 = obj; + return Promise.all(test1.ice_getConnection(), test2.ice_getConnection()); + } + ).then( + function(r1, r2) + { + test(r1[0] === r2[0]); + return Promise.all(test2.ice_getConnection(), test3.ice_getConnection()); + } + ).then( + function(r1, r2) + { + test(r1[0] === r2[0]); + return test1.getAdapterName(); + } + ).then( + function(name) + { + if(names.indexOf(name) !== -1) + { + names.splice(names.indexOf(name), 1); + } + return test1.ice_getConnection(); + } + ).then( + function(conn) + { + return conn.close(false); + } + ).then( + function() + { + if(names.length > 0) + { + return f1(names); + } + } + ); + } + return f1(ArrayUtil.clone(names)); + } + ).then( + function() + { + // + // Ensure that the proxy correctly caches the connection (we + // always send the request over the same connection.) + // + return Promise.all(adapters.map(function(adapter) + { + return adapter.getTestIntf().then( + function(p) + { + return p.ice_ping(); + }); + })); + } + ).then( + function() + { + return createTestIntfPrx(adapters).then( + function(test1) + { + var i = 0; + var nRetry = 10; + var adapterName; + + var f1 = function() + { + return test1.getAdapterName().then( + function(name) + { + test(adapterName === name); + if(++i < nRetry) + { + return f1(); + } + else + { + test(i == nRetry); + } + } + ); + }; + + return test1.getAdapterName().then( + function(name) + { + adapterName = name; + return f1(); + } + ); + }); + } + ).then( + function() + { + return Promise.all(adapters.map(function(adapter) + { + return adapter.getTestIntf().then( + function(p) + { + return p.ice_getConnection(); + }).then( + function(c) + { + return c.close(false); + } + ); + })); + } + ).then( + function() + { + names = ["Adapter12", "Adapter13"]; + return com.deactivateObjectAdapter(adapters[0]); + } + ).then( + function() + { + var f1 = function(names) + { + var adpts = ArrayUtil.clone(adapters); + return createTestIntfPrx(adpts).then( + function(obj) + { + test1 = obj; + ArrayUtil.shuffle(adpts); + return createTestIntfPrx(adpts); + } + ).then( + function(obj) + { + test2 = obj; + ArrayUtil.shuffle(adpts); + return createTestIntfPrx(adpts); + } + ).then( + function(obj) + { + test3 = obj; + var conn1, conn2; + return test1.ice_getConnection().then( + function(conn) + { + conn1 = conn + return test2.ice_getConnection(); + } + ).then( + function(conn) + { + conn2 = conn; + test(conn1 === conn2); + }); + } + ).then( + function() + { + var conn1, conn2; + return test2.ice_getConnection().then( + function(conn) + { + conn1 = conn + return test3.ice_getConnection(); + } + ).then( + function(conn) + { + conn2 = conn; + test(conn1 === conn2); + }); + } + ).then( + function() + { + return test1.getAdapterName(); + } + ).then( + function(name) + { + if(names.indexOf(name) !== -1) + { + names.splice(names.indexOf(name), 1); + } + return test1.ice_getConnection(); + } + ).then( + function(conn) + { + return conn.close(false); + } + ).then( + function() + { + if(names.length > 0) + { + return f1(names); + } + } + ); + }; + return f1(ArrayUtil.clone(names)); + } + ).then( + function() + { + return com.deactivateObjectAdapter(adapters[2]); + } + ).then( + function() + { + return createTestIntfPrx(adapters); + } + ).then( + function(prx) + { + return prx.getAdapterName(); + } + ).then( + function(name) + { + test(name == "Adapter12"); + return deactivate(com, adapters); + } + ).then( + function() + { + out.writeLine("ok"); + return initialize(); + } + ).then( + function() + { + // + // Skip this test with IE it open too many connections IE doesn't allow more + // than 6 connections. Firefox has a configuration that causes failed connections + // to be delayed on retry (network.websocket.delay-failed-reconnects=true by + // default), so we prefer to also disable this test with Firefox. + // + if(typeof(navigator) !== "undefined" && + (navigator.userAgent.indexOf("MSIE") !== -1 || + navigator.userAgent.indexOf("Trident/7.0") || + navigator.userAgent.indexOf("Firefox") !== -1)) + { + return; + } + + out.write("testing binding with multiple random endpoints... "); + names = ["AdapterRandom11", "AdapterRandom12", "AdapterRandom13", "AdapterRandom14", "AdapterRandom15"]; + + return Promise.all( + names.map(function(name) + { + return com.createObjectAdapter(name, "default"); + }) + ).then( + function() + { + adapters = Array.prototype.slice.call(arguments).map(function(r) { return r[0]; }); + var count = 20; + var adapterCount = adapters.length; + var proxies = new Array(10); + var nextInt = function(n) { return Math.floor((Math.random() * n)); }; + + var f1 = function(count, adapterCount, proxies) + { + var p1 = count === 10 ? com.deactivateObjectAdapter(adapters[2]) : new Promise().succeed(); + return p1.then( + function() + { + if(count === 10) + { + adapterCount--; + } + + var f2 = function(i) + { + var adpts = new Array(nextInt(adapters.length) + 1); + for(var j = 0; j < adpts.length; ++j) + { + adpts[j] = adapters[nextInt(adapters.length)]; + } + + return createTestIntfPrx(adpts).then( + function(prx) + { + proxies[i] = prx; + if(i < 10) + { + return f2(++i); + } + else + { + return proxies; + } + }); + }; + + return f2(0); + } + ).then( + function(proxies) + { + return Ice.Promise.try( + function() + { + return forEach(proxies, + function(p) + { + p.getAdapterName(); + }); + } + ).then( + function() + { + return forEach(proxies, + function(proxy) + { + return proxy.ice_ping().exception( + function(ex) + { + test(ex instanceof Ice.LocalException); + }); + }); + } + ).then( + function() + { + var connections = []; + proxies.forEach( + function(p) + { + var conn = p.ice_getCachedConnection(); + if(conn !== null) + { + if(connections.indexOf(conn) !== -1) + { + connections.push(conn); + } + } + }); + test(connections.length <= adapters.length); + + return Promise.all(adapters.map( + function(adapter) + { + return adapter.getTestIntf().then( + function(p) + { + return p.ice_getConnection(); + }).then( + function(c) + { + return c.close(false); + }, + function(ex) + { + // Expected if adapter is down. + test(ex instanceof Ice.LocalException); + } + ); + })); + } + ); + } + ).then( + function() + { + if(count > 0) + { + return f1(--count, adapterCount, proxies); + } + }); + }; + return f1(count, adapterCount, proxies); + }).then( + function() + { + out.writeLine("ok"); + }, + function(ex) + { + out.writeLine("failed! " + ex.stack); + } + ); + } + ).then( + function() + { + return initialize(); + } + ).then( + function() + { + out.write("testing random endpoint selection... "); + names = ["Adapter21", "Adapter22", "Adapter23"]; + return Promise.all(names.map(function(name) { return com.createObjectAdapter(name, "default"); })); + } + ).then( + function() + { + adapters = Array.prototype.slice.call(arguments).map(function(r) { return r[0]; }); + return createTestIntfPrx(adapters); + }, + function(ex) + { + console.log(ex.toString()); + test(false); + } + ).then( + function(prx) + { + test(prx.ice_getEndpointSelection() == Ice.EndpointSelectionType.Random); + + var f1 = function() + { + return prx.getAdapterName().then( + function(name) + { + if(names.indexOf(name) !== -1) + { + names.splice(names.indexOf(name), 1); + } + return prx.ice_getConnection(); + } + ).then( + function(conn) + { + return conn.close(false); + } + ).then( + function() + { + if(names.length > 0) + { + return f1(); + } + else + { + return prx; + } + } + ); + }; + + return f1(); + } + ).then( + function(obj) + { + prx = obj; + prx = Test.TestIntfPrx.uncheckedCast(prx.ice_endpointSelection(Ice.EndpointSelectionType.Random)); + test(prx.ice_getEndpointSelection() === Ice.EndpointSelectionType.Random); + names = ["Adapter21", "Adapter22", "Adapter23"]; + var f1 = function() + { + return prx.getAdapterName().then( + function(name) + { + if(names.indexOf(name) !== -1) + { + names.splice(names.indexOf(name), 1); + } + return prx.ice_getConnection(); + } + ).then( + function(conn) + { + return conn.close(false); + } + ).then( + function() + { + if(names.length > 0) + { + return f1(); + } + else + { + return prx; + } + } + ); + }; + return f1(); + }, + function(ex) + { + test(false); + } + ).then( + function() + { + return deactivate(com, adapters); + } + ).then( + function() + { + out.writeLine("ok"); + return initialize(); + } + ).then( + function() + { + out.write("testing ordered endpoint selection... "); + names = ["Adapter31", "Adapter32", "Adapter33"]; + return Promise.all(names.map(function(name) { return com.createObjectAdapter(name, "default"); })); + } + ).then( + function() + { + adapters = Array.prototype.slice.call(arguments).map(function(r) { return r[0]; }); + return createTestIntfPrx(adapters); + } + ).then( + function(obj) + { + prx = obj; + prx = Test.TestIntfPrx.uncheckedCast(prx.ice_endpointSelection(Ice.EndpointSelectionType.Ordered)); + test(prx.ice_getEndpointSelection() === Ice.EndpointSelectionType.Ordered); + var i, nRetry = 5; + var f1 = function(i, idx, names) + { + return prx.getAdapterName().then( + function(name) + { + test(name === names[0]); + } + ).then( + function() + { + if(i < nRetry) + { + return f1(++i, idx, names); + } + else + { + return com.deactivateObjectAdapter(adapters[idx]).then( + function() + { + if(names.length > 1) + { + names.shift() + return f1(0, ++idx, names); + } + } + ); + } + } + ); + }; + + return f1(0, 0, ArrayUtil.clone(names)); + } + ).then( + function() + { + return prx.getAdapterName(); + } + ).then( + function() + { + test(false); + }, + function(ex) + { + test((typeof(window) == 'undefined' && ex instanceof Ice.ConnectionRefusedException) || + (typeof(window) != 'undefined' && ex instanceof Ice.ConnectFailedException)); + return prx.ice_getEndpoints(); + } + ).then( + function(endpoints) + { + var nRetry = 5; + var j = 2; + var f1 = function(i, names) + { + return com.createObjectAdapter(names[0], endpoints[j--].toString()).then( + function(obj) + { + return obj.getTestIntf(); + } + ).then( + function(prx) + { + var f2 = function(i, names) + { + return prx.getAdapterName().then( + function(name) + { + test(name === names[0]); + if(i < nRetry) + { + return f2(++i, names); + } + else if(names.length > 1) + { + names.shift(); + return f1(0, names); + } + }); + }; + return f2(0, names); + }); + }; + + return f1(0, ["Adapter36", "Adapter35", "Adapter34"]); + } + ).then( + function() + { + return deactivate(com, adapters); + } + ).then( + function(){ + out.writeLine("ok"); + return initialize + } + ).then( + function() + { + out.write("testing per request binding with single endpoint... "); + return com.createObjectAdapter("Adapter41", "default"); + } + ).then( + function(adapter) + { + var f1 = function() + { + return adapter.getTestIntf().then( + function(obj) + { + test1 = Test.TestIntfPrx.uncheckedCast(obj.ice_connectionCached(false)); + return adapter.getTestIntf() + } + ).then( + function(obj) + { + test2 = Test.TestIntfPrx.uncheckedCast(obj.ice_connectionCached(false)); + test(!test1.ice_isConnectionCached()); + test(!test2.ice_isConnectionCached()); + return Promise.all(test1.ice_getConnection(), + test2.ice_getConnection()); + } + ).then( + function(r1, r2) + { + test(r1[0] == r2[0]); + return test1.ice_ping(); + } + ).then( + function() + { + return com.deactivateObjectAdapter(adapter); + } + ).then( + function() + { + var test3 = Test.TestIntfPrx.uncheckedCast(test1); + return Promise.all(test3.ice_getConnection(), + test1.ice_getConnection()); + } + ).then( + function() + { + test(false); + }, + function(ex) + { + test((typeof(window) == 'undefined' && ex instanceof Ice.ConnectionRefusedException) || + (typeof(window) != 'undefined' && ex instanceof Ice.ConnectFailedException)); + }); + }; + return f1(); + } + ).then( + function() + { + out.writeLine("ok"); + return initialize(); + } + ).then( + function() + { + out.write("testing per request binding with multiple endpoints... "); + names = ["Adapter51", "Adapter52", "Adapter53"]; + return Promise.all(names.map(function(name) { return com.createObjectAdapter(name, "default"); })); + } + ).then( + function() + { + adapters = Array.prototype.slice.call(arguments).map(function(r) { return r[0]; }); + + var f2 = function(prx) + { + return prx.getAdapterName().then( + function(name) + { + if(names.indexOf(name) !== -1) + { + names.splice(names.indexOf(name), 1); + } + if(names.length > 0) + { + return f2(prx); + } + else + { + return prx; + } + }); + }; + + var f1 = function() + { + return createTestIntfPrx(adapters).then( + function(prx) + { + prx = Test.TestIntfPrx.uncheckedCast(prx.ice_connectionCached(false)); + test(!prx.ice_isConnectionCached()); + return f2(prx); + }); + + }; + + return f1().then( + function(prx) + { + com.deactivateObjectAdapter(adapters[0]).then( + function() + { + names = ["Adapter52", "Adapter53"]; + return f2(prx); + } + ).then( + function() + { + return com.deactivateObjectAdapter(adapters[0]); + } + ).then( + function() + { + names = ["Adapter52"]; + return f2(prx); + } + ); + }); + } + ).then( + function() + { + return deactivate(com, adapters); + } + ).then( + function() + { + out.writeLine("ok"); + return initialize(); + } + ).then( + function() + { + if(typeof(navigator) !== "undefined" && + (navigator.userAgent.indexOf("Firefox") !== -1 || + navigator.userAgent.indexOf("MSIE") !== -1 || + navigator.userAgent.indexOf("Trident/7.0") !== -1)) + { + // + // Firefox adds a delay on websocket failed reconnects that causes this test to take too + // much time to complete. + // + // You can set network.websocket.delay-failed-reconnects to false in Firefox about:config + // to disable this behaviour + // + return; + } + out.write("testing per request binding and ordered endpoint selection... "); + names = ["Adapter61", "Adapter62", "Adapter63"]; + return Promise.all(names.map(function(name) { return com.createObjectAdapter(name, "default"); })).then( + function(a) + { + adapters = Array.prototype.slice.call(arguments).map(function(r) { return r[0]; }); + return createTestIntfPrx(adapters); + } + ).then( + function(obj) + { + prx = obj; + prx = Test.TestIntfPrx.uncheckedCast(prx.ice_endpointSelection(Ice.EndpointSelectionType.Ordered)); + test(prx.ice_getEndpointSelection() == Ice.EndpointSelectionType.Ordered); + prx = Test.TestIntfPrx.uncheckedCast(prx.ice_connectionCached(false)); + test(!prx.ice_isConnectionCached()); + var nRetry = 5; + var f1 = function(i, idx, names) + { + return prx.getAdapterName().then( + function(name) + { + test(name === names[0]); + } + ).then( + function() + { + if(i < nRetry) + { + return f1(++i, idx, names); + } + else + { + return com.deactivateObjectAdapter(adapters[idx]).then( + function() + { + if(names.length > 1) + { + names.shift() + return f1(0, ++idx, names); + } + } + ); + } + }); + }; + + return f1(0, 0, ArrayUtil.clone(names)); + } + ).then( + function() + { + return prx.getAdapterName(); + } + ).then( + function() + { + test(false); + }, + function(ex) + { + test((typeof(window) == 'undefined' && ex instanceof Ice.ConnectionRefusedException) || + (typeof(window) != 'undefined' && ex instanceof Ice.ConnectFailedException)); + return prx.ice_getEndpoints(); + } + ).then( + function(endpoints) + { + var nRetry = 5; + var j = 2; + var f1 = function(i, names) + { + return com.createObjectAdapter(names[0], endpoints[j--].toString()).then( + function() + { + var f2 = function(i, names) + { + return prx.getAdapterName().then( + function(name) + { + test(name === names[0]); + if(i < nRetry) + { + return f2(++i, names); + } + else if(names.length > 1) + { + names.shift(); + return f1(0, names); + } + } + ); + }; + return f2(0, names); + } + ); + }; + return f1(0, ["Adapter66", "Adapter65", "Adapter64"]); + } + ).then( + function() + { + out.writeLine("ok"); + }); + } + ).then( + function() + { + return com.shutdown(); + } + ).then( + function() + { + p.succeed(); + }, + function(ex) + { + p.fail(ex); + } + ); + return p; + }; + + var run = function(out, id) + { + var p = new Ice.Promise(); + setTimeout( + function() + { + try + { + allTests(out, id).then(function(){ + return communicator.destroy(); + }).then(function(){ + p.succeed(); + }).exception(function(ex){ + p.fail(ex); + }); + } + catch(ex) + { + p.fail(ex); + } + }); + return p; + }; + + global.__test__ = run; + global.__runServer__ = true; +}(typeof (global) === "undefined" ? window : global)); diff --git a/js/test/Ice/binding/Makefile b/js/test/Ice/binding/Makefile new file mode 100644 index 00000000000..3dab6765eba --- /dev/null +++ b/js/test/Ice/binding/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/binding/Makefile.mak b/js/test/Ice/binding/Makefile.mak new file mode 100644 index 00000000000..61a62482429 --- /dev/null +++ b/js/test/Ice/binding/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/binding/Test.ice b/js/test/Ice/binding/Test.ice new file mode 100644 index 00000000000..c2ddcf4f3e5 --- /dev/null +++ b/js/test/Ice/binding/Test.ice @@ -0,0 +1,37 @@ +// ********************************************************************** +// +// 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 +{ + +interface TestIntf +{ + string getAdapterName(); +}; + +interface RemoteObjectAdapter +{ + TestIntf* getTestIntf(); + + void deactivate(); +}; + +interface RemoteCommunicator +{ + RemoteObjectAdapter* createObjectAdapter(string name, string endpoints); + + void deactivateObjectAdapter(RemoteObjectAdapter* adapter); + + void shutdown(); +}; + +}; + diff --git a/js/test/Ice/binding/run.js b/js/test/Ice/binding/run.js new file mode 100644 index 00000000000..a875f421701 --- /dev/null +++ b/js/test/Ice/binding/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/binding/run.py b/js/test/Ice/binding/run.py new file mode 100755 index 00000000000..33fc2e8f3ac --- /dev/null +++ b/js/test/Ice/binding/run.py @@ -0,0 +1,23 @@ +#!/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 + +TestUtil.clientServerTest() diff --git a/js/test/Ice/defaultValue/.gitignore b/js/test/Ice/defaultValue/.gitignore new file mode 100644 index 00000000000..d158d9308ba --- /dev/null +++ b/js/test/Ice/defaultValue/.gitignore @@ -0,0 +1,2 @@ +Test.js +index.html diff --git a/js/test/Ice/defaultValue/Client.js b/js/test/Ice/defaultValue/Client.js new file mode 100644 index 00000000000..73a6615217a --- /dev/null +++ b/js/test/Ice/defaultValue/Client.js @@ -0,0 +1,181 @@ +// ********************************************************************** +// +// 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 run = function(out, id) + { + var p = new Ice.Promise(); + var test = function(b) + { + if(!b) + { + try + { + throw new Error("test failed"); + } + catch(err) + { + p.fail(err); + throw err; + } + } + }; + + Promise.try( + function() + { + out.write("testing default values... "); + var v = new Test.Struct1(); + test(!v.boolFalse); + test(v.boolTrue); + test(v.b === 254); + test(v.s === 16000); + test(v.i === 3); + test(v.l.equals(new Ice.Long(0, 4))); + test(v.f === 5.1); + test(v.d === 6.2); + test(v.str === "foo \\ \"bar\n \r\n\t\u000b\f\u0007\b?"); + test(v.c1 === Test.Color.red); + test(v.c2 === Test.Color.green); + test(v.c3 === Test.Color.blue); + test(v.nc1 === Test.Nested.Color.red); + test(v.nc2 === Test.Nested.Color.green); + test(v.nc3 === Test.Nested.Color.blue); + test(v.noDefault === null); + test(v.zeroI === 0); + test(v.zeroL.equals(new Ice.Long(0, 0))); + test(v.zeroF === 0); + test(v.zeroDotF === 0); + test(v.zeroD === 0); + test(v.zeroDotD === 0); + + v = new Test.Struct2(); + test(v.boolTrue === Test.ConstBool); + test(v.b === Test.ConstByte); + test(v.s === Test.ConstShort); + test(v.i === Test.ConstInt); + test(v.l.equals(Test.ConstLong)); + test(v.f === Test.ConstFloat); + test(v.d === Test.ConstDouble); + test(v.str == Test.ConstString); + test(v.c1 === Test.ConstColor1); + test(v.c2 === Test.ConstColor2); + test(v.c3 === Test.ConstColor3); + test(v.nc1 === Test.ConstNestedColor1); + test(v.nc2 === Test.ConstNestedColor2); + test(v.nc3 === Test.ConstNestedColor3); + + v = new Test.Base(); + test(!v.boolFalse); + test(v.boolTrue); + test(v.b === 1); + test(v.s === 2); + test(v.i === 3); + test(v.l.equals(new Ice.Long(0, 4))); + test(v.f === 5.1); + test(v.d === 6.2); + test(v.str == "foo \\ \"bar\n \r\n\t\u000b\f\u0007\b?"); + test(v.noDefault === null); + test(v.zeroI === 0); + test(v.zeroL.equals(new Ice.Long(0, 0))); + test(v.zeroF === 0); + test(v.zeroDotF === 0); + test(v.zeroD === 0); + test(v.zeroDotD === 0); + + v = new Test.Derived(); + test(!v.boolFalse); + test(v.boolTrue); + test(v.b === 1); + test(v.s === 2); + test(v.i === 3); + test(v.l.equals(new Ice.Long(0, 4))); + test(v.f === 5.1); + test(v.d === 6.2); + test(v.str == "foo \\ \"bar\n \r\n\t\u000b\f\u0007\b?"); + test(v.c1 === Test.Color.red); + test(v.c2 === Test.Color.green); + test(v.c3 === Test.Color.blue); + test(v.nc1 === Test.Nested.Color.red); + test(v.nc2 === Test.Nested.Color.green); + test(v.nc3 === Test.Nested.Color.blue); + test(v.noDefault === null); + test(v.zeroI === 0); + test(v.zeroL.equals(new Ice.Long(0, 0))); + test(v.zeroF === 0); + test(v.zeroDotF === 0); + test(v.zeroD === 0); + test(v.zeroDotD === 0); + + v = new Test.BaseEx(); + test(!v.boolFalse); + test(v.boolTrue); + test(v.b === 1); + test(v.s === 2); + test(v.i === 3); + test(v.l.equals(new Ice.Long(0, 4))); + test(v.f === 5.1); + test(v.d === 6.2); + test(v.str == "foo \\ \"bar\n \r\n\t\u000b\f\u0007\b?"); + test(v.noDefault === null); + test(v.zeroI === 0); + test(v.zeroL.equals(new Ice.Long(0, 0))); + test(v.zeroF === 0); + test(v.zeroDotF === 0); + test(v.zeroD === 0); + test(v.zeroDotD === 0); + + v = new Test.DerivedEx(); + test(!v.boolFalse); + test(v.boolTrue); + test(v.b === 1); + test(v.s === 2); + test(v.i === 3); + test(v.l.equals(new Ice.Long(0, 4))); + test(v.f === 5.1); + test(v.d === 6.2); + test(v.str == "foo \\ \"bar\n \r\n\t\u000b\f\u0007\b?"); + test(v.noDefault === null); + test(v.c1 === Test.Color.red); + test(v.c2 === Test.Color.green); + test(v.c3 === Test.Color.blue); + test(v.nc1 === Test.Nested.Color.red); + test(v.nc2 === Test.Nested.Color.green); + test(v.nc3 === Test.Nested.Color.blue); + test(v.zeroI === 0); + test(v.zeroL.equals(new Ice.Long(0, 0))); + test(v.zeroF === 0); + test(v.zeroDotF === 0); + test(v.zeroD === 0); + test(v.zeroDotD === 0); + + out.writeLine("ok"); + } + ).then( + function() + { + p.succeed(); + }, + function(ex) + { + p.fail(ex); + } + ); + return p; + }; + global.__test__ = run; +}(typeof (global) === "undefined" ? window : global)); diff --git a/js/test/Ice/defaultValue/Makefile b/js/test/Ice/defaultValue/Makefile new file mode 100644 index 00000000000..8f81ea44140 --- /dev/null +++ b/js/test/Ice/defaultValue/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/defaultValue/Makefile.mak b/js/test/Ice/defaultValue/Makefile.mak new file mode 100644 index 00000000000..61a62482429 --- /dev/null +++ b/js/test/Ice/defaultValue/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/defaultValue/Test.ice b/js/test/Ice/defaultValue/Test.ice new file mode 100644 index 00000000000..f6d46693923 --- /dev/null +++ b/js/test/Ice/defaultValue/Test.ice @@ -0,0 +1,182 @@ +// ********************************************************************** +// +// 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 +{ + +enum Color { red, green, blue }; + +module Nested +{ + +enum Color { red, green, blue }; + +}; + +struct Struct1 +{ + bool boolFalse = false; + bool boolTrue = true; + byte b = 254; + short s = 16000; + int i = 3; + long l = 4; + float f = 5.1; + double d = 6.2; + string str = "foo \\ \"bar\n \r\n\t\v\f\a\b\?"; + Color c1 = ::Test::red; + Color c2 = Test::green; + Color c3 = blue; + Nested::Color nc1 = ::Test::Nested::red; + Nested::Color nc2 = Nested::green; + Nested::Color nc3 = Nested::blue; + string noDefault; + int zeroI = 0; + long zeroL = 0; + float zeroF = 0; + float zeroDotF = 0.0; + double zeroD = 0; + double zeroDotD = 0; +}; + +const bool ConstBool = true; +const byte ConstByte = 254; +const short ConstShort = 16000; +const int ConstInt = 3; +const long ConstLong = 4; +const float ConstFloat = 5.1; +const double ConstDouble = 6.2; +const string ConstString = "foo \\ \"bar\n \r\n\t\v\f\a\b\?"; +const Color ConstColor1 = ::Test::red; +const Color ConstColor2 = Test::green; +const Color ConstColor3 = blue; +const Nested::Color ConstNestedColor1 = ::Test::Nested::red; +const Nested::Color ConstNestedColor2 = Test::Nested::green; +const Nested::Color ConstNestedColor3 = Nested::blue; +const int ConstZeroI = 0; +const long ConstZeroL = 0; +const float ConstZeroF = 0; +const float ConstZeroDotF = 0.0; +const double ConstZeroD = 0; +const double ConstZeroDotD = 0; + +struct Struct2 +{ + bool boolTrue = ConstBool; + byte b = ConstByte; + short s = ConstShort; + int i = ConstInt; + long l = ConstLong; + float f = ConstFloat; + double d = ConstDouble; + string str = ConstString; + Color c1 = ConstColor1; + Color c2 = ConstColor2; + Color c3 = ConstColor3; + Nested::Color nc1 = ConstNestedColor1; + Nested::Color nc2 = ConstNestedColor2; + Nested::Color nc3 = ConstNestedColor3; + int zeroI = ConstZeroI; + long zeroL = ConstZeroL; + float zeroF = ConstZeroF; + float zeroDotF = ConstZeroDotF; + double zeroD = ConstZeroD; + double zeroDotD = ConstZeroDotD; +}; + +["cpp:class"] +struct Struct3 +{ + bool boolFalse = false; + bool boolTrue = true; + byte b = 1; + short s = 2; + int i = 3; + long l = 4; + float f = 5.1; + double d = 6.2; + string str = "foo \\ \"bar\n \r\n\t\v\f\a\b\?"; + Color c1 = ::Test::red; + Color c2 = Test::green; + Color c3 = blue; + Nested::Color nc1 = ::Test::Nested::red; + Nested::Color nc2 = Nested::green; + Nested::Color nc3 = Nested::blue; + string noDefault; + int zeroI = 0; + long zeroL = 0; + float zeroF = 0; + float zeroDotF = 0.0; + double zeroD = 0; + double zeroDotD = 0; +}; + +class Base +{ + bool boolFalse = false; + bool boolTrue = true; + byte b = 1; + short s = 2; + int i = 3; + long l = 4; + float f = 5.1; + double d = 6.2; + string str = "foo \\ \"bar\n \r\n\t\v\f\a\b\?"; + string noDefault; + int zeroI = 0; + long zeroL = 0; + float zeroF = 0; + float zeroDotF = 0.0; + double zeroD = 0; + double zeroDotD = 0; +}; + +class Derived extends Base +{ + Color c1 = ::Test::red; + Color c2 = Test::green; + Color c3 = blue; + Nested::Color nc1 = ::Test::Nested::red; + Nested::Color nc2 = Nested::green; + Nested::Color nc3 = Nested::blue; +}; + +exception BaseEx +{ + bool boolFalse = false; + bool boolTrue = true; + byte b = 1; + short s = 2; + int i = 3; + long l = 4; + float f = 5.1; + double d = 6.2; + string str = "foo \\ \"bar\n \r\n\t\v\f\a\b\?"; + string noDefault; + int zeroI = 0; + long zeroL = 0; + float zeroF = 0; + float zeroDotF = 0.0; + double zeroD = 0; + double zeroDotD = 0; +}; + +exception DerivedEx extends BaseEx +{ + Color c1 = ConstColor1; + Color c2 = ConstColor2; + Color c3 = ConstColor3; + Nested::Color nc1 = ConstNestedColor1; + Nested::Color nc2 = ConstNestedColor2; + Nested::Color nc3 = ConstNestedColor3; +}; + +}; diff --git a/js/test/Ice/defaultValue/run.js b/js/test/Ice/defaultValue/run.js new file mode 100644 index 00000000000..fa3a4c19d4b --- /dev/null +++ b/js/test/Ice/defaultValue/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);
\ No newline at end of file diff --git a/js/test/Ice/defaultValue/run.py b/js/test/Ice/defaultValue/run.py new file mode 100755 index 00000000000..7aae9321854 --- /dev/null +++ b/js/test/Ice/defaultValue/run.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# ********************************************************************** +# +# 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 + +TestUtil.simpleTest() diff --git a/js/test/Ice/enums/.gitignore b/js/test/Ice/enums/.gitignore new file mode 100644 index 00000000000..d158d9308ba --- /dev/null +++ b/js/test/Ice/enums/.gitignore @@ -0,0 +1,2 @@ +Test.js +index.html diff --git a/js/test/Ice/enums/Client.js b/js/test/Ice/enums/Client.js new file mode 100644 index 00000000000..827d4e82ec7 --- /dev/null +++ b/js/test/Ice/enums/Client.js @@ -0,0 +1,237 @@ +// ********************************************************************** +// +// 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 allTests = function(out, communicator) + { + 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 base, proxy; + Promise.try( + function() + { + out.write("testing stringToProxy... "); + var ref = "test:default -p 12010"; + base = communicator.stringToProxy(ref); + test(base !== null); + out.writeLine("ok"); + out.write("testing checked cast... "); + return Test.TestIntfPrx.checkedCast(base); + } + ).then( + function(obj) + { + proxy = obj; + test(proxy !== null); + test(proxy.equals(base)); + out.writeLine("ok"); + out.write("testing enum values... "); + test(Test.ByteEnum.benum1.value === 0); + test(Test.ByteEnum.benum2.value === 1); + test(Test.ByteEnum.benum3.value === Test.ByteConst1); + test(Test.ByteEnum.benum4.value === Test.ByteConst1 + 1); + test(Test.ByteEnum.benum5.value === Test.ShortConst1); + test(Test.ByteEnum.benum6.value === Test.ShortConst1 + 1); + test(Test.ByteEnum.benum7.value === Test.IntConst1); + test(Test.ByteEnum.benum8.value === Test.IntConst1 + 1); + test(Test.ByteEnum.benum9.value === Test.LongConst1.low); + test(Test.ByteEnum.benum10.value === Test.LongConst1.low + 1); + test(Test.ByteEnum.benum11.value === Test.ByteConst2); + + test(Test.ByteEnum.valueOf(0) === Test.ByteEnum.benum1); + test(Test.ByteEnum.valueOf(1) === Test.ByteEnum.benum2); + test(Test.ByteEnum.valueOf(Test.ByteConst1) === Test.ByteEnum.benum3); + test(Test.ByteEnum.valueOf(Test.ByteConst1+ 1) === Test.ByteEnum.benum4); + test(Test.ByteEnum.valueOf(Test.ShortConst1) === Test.ByteEnum.benum5); + test(Test.ByteEnum.valueOf(Test.ShortConst1 + 1) === Test.ByteEnum.benum6); + test(Test.ByteEnum.valueOf(Test.IntConst1) === Test.ByteEnum.benum7); + test(Test.ByteEnum.valueOf(Test.IntConst1 + 1) === Test.ByteEnum.benum8); + test(Test.ByteEnum.valueOf(Test.LongConst1.low) === Test.ByteEnum.benum9); + test(Test.ByteEnum.valueOf(Test.LongConst1.low + 1) === Test.ByteEnum.benum10); + test(Test.ByteEnum.valueOf(Test.ByteConst2) === Test.ByteEnum.benum11); + + test(Test.ShortEnum.senum1.value === 3); + test(Test.ShortEnum.senum2.value === 4); + test(Test.ShortEnum.senum3.value === Test.ByteConst1); + test(Test.ShortEnum.senum4.value === Test.ByteConst1 + 1); + test(Test.ShortEnum.senum5.value === Test.ShortConst1); + test(Test.ShortEnum.senum6.value === Test.ShortConst1 + 1); + test(Test.ShortEnum.senum7.value === Test.IntConst1); + test(Test.ShortEnum.senum8.value === Test.IntConst1 + 1); + test(Test.ShortEnum.senum9.value === Test.LongConst1.low); + test(Test.ShortEnum.senum10.value === Test.LongConst1.low + 1); + test(Test.ShortEnum.senum11.value === Test.ShortConst2); + + test(Test.ShortEnum.valueOf(3) === Test.ShortEnum.senum1); + test(Test.ShortEnum.valueOf(4) === Test.ShortEnum.senum2); + test(Test.ShortEnum.valueOf(Test.ByteConst1) === Test.ShortEnum.senum3); + test(Test.ShortEnum.valueOf(Test.ByteConst1 + 1) === Test.ShortEnum.senum4); + test(Test.ShortEnum.valueOf(Test.ShortConst1) === Test.ShortEnum.senum5); + test(Test.ShortEnum.valueOf(Test.ShortConst1 + 1) === Test.ShortEnum.senum6); + test(Test.ShortEnum.valueOf(Test.IntConst1) === Test.ShortEnum.senum7); + test(Test.ShortEnum.valueOf(Test.IntConst1 + 1) === Test.ShortEnum.senum8); + test(Test.ShortEnum.valueOf(Test.LongConst1.low) === Test.ShortEnum.senum9); + test(Test.ShortEnum.valueOf(Test.LongConst1.low + 1) === Test.ShortEnum.senum10); + test(Test.ShortEnum.valueOf(Test.ShortConst2) === Test.ShortEnum.senum11); + + test(Test.IntEnum.ienum1.value === 0); + test(Test.IntEnum.ienum2.value === 1); + test(Test.IntEnum.ienum3.value === Test.ByteConst1); + test(Test.IntEnum.ienum4.value === Test.ByteConst1 + 1); + test(Test.IntEnum.ienum5.value === Test.ShortConst1); + test(Test.IntEnum.ienum6.value === Test.ShortConst1 + 1); + test(Test.IntEnum.ienum7.value === Test.IntConst1); + test(Test.IntEnum.ienum8.value === Test.IntConst1 + 1); + test(Test.IntEnum.ienum9.value === Test.LongConst1.low); + test(Test.IntEnum.ienum10.value === Test.LongConst1.low + 1); + test(Test.IntEnum.ienum11.value === Test.IntConst2); + test(Test.IntEnum.ienum12.value === Test.LongConst2.low); + + test(Test.IntEnum.valueOf(0) === Test.IntEnum.ienum1); + test(Test.IntEnum.valueOf(1) === Test.IntEnum.ienum2); + test(Test.IntEnum.valueOf(Test.ByteConst1) === Test.IntEnum.ienum3); + test(Test.IntEnum.valueOf(Test.ByteConst1 + 1) === Test.IntEnum.ienum4); + test(Test.IntEnum.valueOf(Test.ShortConst1) === Test.IntEnum.ienum5); + test(Test.IntEnum.valueOf(Test.ShortConst1 + 1) === Test.IntEnum.ienum6); + test(Test.IntEnum.valueOf(Test.IntConst1) === Test.IntEnum.ienum7); + test(Test.IntEnum.valueOf(Test.IntConst1 + 1) === Test.IntEnum.ienum8); + test(Test.IntEnum.valueOf(Test.LongConst1.low) === Test.IntEnum.ienum9); + test(Test.IntEnum.valueOf(Test.LongConst1.low + 1) === Test.IntEnum.ienum10); + test(Test.IntEnum.valueOf(Test.IntConst2) === Test.IntEnum.ienum11); + test(Test.IntEnum.valueOf(Test.LongConst2.low) === Test.IntEnum.ienum12); + + test(Test.SimpleEnum.red.value === 0); + test(Test.SimpleEnum.green.value === 1); + test(Test.SimpleEnum.blue.value === 2); + + test(Test.SimpleEnum.valueOf(0) === Test.SimpleEnum.red); + test(Test.SimpleEnum.valueOf(1) === Test.SimpleEnum.green); + test(Test.SimpleEnum.valueOf(2) === Test.SimpleEnum.blue); + + out.writeLine("ok"); + } + ).then( + function() + { + out.write("testing enum operations... "); + return proxy.opByte(Test.ByteEnum.benum1); + } + ).then( + function(r, b1) + { + test(r === b1); + test(r === Test.ByteEnum.benum1); + return proxy.opByte(Test.ByteEnum.benum11); + } + ).then( + function(r, b11) + { + test(r === b11); + test(r === Test.ByteEnum.benum11); + return proxy.opShort(Test.ShortEnum.senum1); + } + ).then( + function(r, s1) + { + test(r === s1); + test(r === Test.ShortEnum.senum1); + return proxy.opShort(Test.ShortEnum.senum11); + } + ).then( + function(r, s11) + { + test(r === s11); + test(r === Test.ShortEnum.senum11); + return proxy.opInt(Test.IntEnum.ienum1); + } + ).then( + function(r, i1) + { + test(r === i1); + test(r === Test.IntEnum.ienum1); + return proxy.opInt(Test.IntEnum.ienum11); + } + ).then( + function(r, i11) + { + test(r === i11); + test(r === Test.IntEnum.ienum11); + return proxy.opInt(Test.IntEnum.ienum12); + } + ).then( + function(r, i12) + { + test(r === i12); + test(r === Test.IntEnum.ienum12); + return proxy.opSimple(Test.SimpleEnum.green); + } + ).then( + function(r, g) + { + test(r === g); + test(r === Test.SimpleEnum.green); + + out.writeLine("ok"); + return proxy.shutdown(); + } + ).then( + function() + { + p.succeed(); + }, + function(ex) + { + p.fail(ex) + } + ); + 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/enums/Makefile b/js/test/Ice/enums/Makefile new file mode 100644 index 00000000000..8f81ea44140 --- /dev/null +++ b/js/test/Ice/enums/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/enums/Makefile.mak b/js/test/Ice/enums/Makefile.mak new file mode 100644 index 00000000000..61a62482429 --- /dev/null +++ b/js/test/Ice/enums/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/enums/Test.ice b/js/test/Ice/enums/Test.ice new file mode 100644 index 00000000000..e460a160b1d --- /dev/null +++ b/js/test/Ice/enums/Test.ice @@ -0,0 +1,88 @@ +// ********************************************************************** +// +// 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 +{ + +const byte ByteConst1 = 10; +const short ShortConst1 = 20; +const int IntConst1 = 30; +const long LongConst1 = 40; + +const byte ByteConst2 = 126; +const short ShortConst2 = 32766; +const int IntConst2 = 2147483647; +const long LongConst2 = 2147483646; + +enum ByteEnum +{ + benum1, + benum2, + benum3 = ByteConst1, + benum4, + benum5 = ShortConst1, + benum6, + benum7 = IntConst1, + benum8, + benum9 = LongConst1, + benum10, + benum11 = ByteConst2 +}; + +enum ShortEnum +{ + senum1 = 3, + senum2, + senum3 = ByteConst1, + senum4, + senum5 = ShortConst1, + senum6, + senum7 = IntConst1, + senum8, + senum9 = LongConst1, + senum10, + senum11 = ShortConst2 +}; + +enum IntEnum +{ + ienum1, + ienum2, + ienum3 = ByteConst1, + ienum4, + ienum5 = ShortConst1, + ienum6, + ienum7 = IntConst1, + ienum8, + ienum9 = LongConst1, + ienum10, + ienum11 = IntConst2, + ienum12 = LongConst2 +}; + +enum SimpleEnum +{ + red, + green, + blue +}; + +interface TestIntf +{ + ByteEnum opByte(ByteEnum b1, out ByteEnum b2); + ShortEnum opShort(ShortEnum s1, out ShortEnum s2); + IntEnum opInt(IntEnum i1, out IntEnum i2); + SimpleEnum opSimple(SimpleEnum s1, out SimpleEnum s2); + + void shutdown(); +}; + +}; diff --git a/js/test/Ice/enums/run.js b/js/test/Ice/enums/run.js new file mode 100644 index 00000000000..a875f421701 --- /dev/null +++ b/js/test/Ice/enums/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/enums/run.py b/js/test/Ice/enums/run.py new file mode 100755 index 00000000000..8e5d7b0562e --- /dev/null +++ b/js/test/Ice/enums/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 1.0 encoding.") +TestUtil.clientServerTest(additionalClientOptions="--Ice.Default.EncodingVersion=1.0", + additionalServerOptions="--Ice.Default.EncodingVersion=1.0") + +print("Running test with 1.1 encoding.") +TestUtil.clientServerTest() 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") diff --git a/js/test/Ice/exceptionsBidir/.gitignore b/js/test/Ice/exceptionsBidir/.gitignore new file mode 100644 index 00000000000..4b74460eef7 --- /dev/null +++ b/js/test/Ice/exceptionsBidir/.gitignore @@ -0,0 +1,3 @@ +Test.js +TestAMD.js +index.html diff --git a/js/test/Ice/exceptionsBidir/AMDThrowerI.js b/js/test/Ice/exceptionsBidir/AMDThrowerI.js new file mode 100644 index 00000000000..2e708e73c0b --- /dev/null +++ b/js/test/Ice/exceptionsBidir/AMDThrowerI.js @@ -0,0 +1,160 @@ +// ********************************************************************** +// +// 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 Ice = global.Ice; + + var Class = Ice.Class; + + var test = function(b) + { + if(!b) + { + throw new Error("test failed"); + } + }; + + var AMDThrowerI = Class(TestAMD.Thrower, { + shutdown_async: function(cb, current) + { + current.adapter.getCommunicator().shutdown(); + cb.ice_response(); + }, + + supportsUndeclaredExceptions_async: function(cb, current) + { + cb.ice_response(true); + }, + + supportsAssertException_async: function(cb, current) + { + cb.ice_response(false); + }, + + throwAasA_async: function(cb, a, current) + { + var ex = new TestAMD.A(); + ex.aMem = a; + cb.ice_exception(ex); + }, + + throwAorDasAorD_async: function(cb, a, current) + { + if(a > 0) + { + var ex = new TestAMD.A(); + ex.aMem = a; + cb.ice_exception(ex); + } + else + { + var ex = new TestAMD.D(); + ex.dMem = a; + cb.ice_exception(ex); + } + }, + + throwBasA_async: function(cb, a, b, current) + { + this.throwBasB_async(cb, a, b, current); + }, + + throwBasB_async: function(cb, a, b, current) + { + var ex = new TestAMD.B(); + ex.aMem = a; + ex.bMem = b; + cb.ice_exception(ex); + }, + + throwCasA_async: function(cb, a, b, c, current) + { + this.throwCasC_async(cb, a, b, c, current); + }, + + throwCasB_async: function(cb, a, b, c, current) + { + this.throwCasC_async(cb, a, b, c, current); + }, + + throwCasC_async: function(cb, a, b, c, current) + { + var ex = new TestAMD.C(); + ex.aMem = a; + ex.bMem = b; + ex.cMem = c; + cb.ice_exception(ex); + }, + + throwUndeclaredA_async: function(cb, a, current) + { + var ex = new TestAMD.A(); + ex.aMem = a; + cb.ice_exception(ex); + }, + + throwUndeclaredB_async: function(cb, a, b, current) + { + var ex = new TestAMD.B(); + ex.aMem = a; + ex.bMem = b; + cb.ice_exception(ex); + }, + + throwUndeclaredC_async: function(cb, a, b, c, current) + { + var ex = new TestAMD.C(); + ex.aMem = a; + ex.bMem = b; + ex.cMem = c; + cb.ice_exception(ex); + }, + + throwLocalException_async: function(cb, current) + { + cb.ice_exception(new Ice.TimeoutException()); + }, + + throwLocalExceptionIdempotent_async: function(cb, current) + { + cb.ice_exception(new Ice.TimeoutException()); + }, + + throwNonIceException_async: function(cb, current) + { + cb.ice_exception(new Error()); + }, + + throwAssertException_async: function(cb, current) + { + test(false); + }, + + throwMemoryLimitException_async: function(cb, seq, current) + { + cb.ice_response(Ice.Buffer.createNative(1024 * 20)); // 20KB is over the configured 10KB message size max. + }, + + throwAfterResponse_async: function(cb, current) + { + cb.ice_response(); + + throw new Error(); + }, + + throwAfterException_async: function(cb, current) + { + cb.ice_exception(new TestAMD.A()); + + throw new Error(); + } + }); + + global.AMDThrowerI = AMDThrowerI; +}(typeof (global) === "undefined" ? window : global)); diff --git a/js/test/Ice/exceptionsBidir/Client.js b/js/test/Ice/exceptionsBidir/Client.js new file mode 100644 index 00000000000..5c193f744a1 --- /dev/null +++ b/js/test/Ice/exceptionsBidir/Client.js @@ -0,0 +1,102 @@ +// ********************************************************************** +// +// 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; + var Promise = Ice.Promise; + + require("Test"); + require("TestAMD"); + require("../exceptions/Client"); + + require("ThrowerI"); + var ThrowerI = global.ThrowerI; + require("AMDThrowerI"); + var AMDThrowerI = global.AMDThrowerI; + + + var allTests = function(out, communicator, amd) + { + return Promise.try( + function() + { + return communicator.createObjectAdapter("").then( + function(adapter) + { + if(amd) + { + adapter.add(new AMDThrowerI(), communicator.stringToIdentity("thrower")); + } + else + { + adapter.add(new ThrowerI(), communicator.stringToIdentity("thrower")); + } + var base = communicator.stringToProxy("thrower:default -p 12010"); + return base.ice_getConnection().then( + function(conn) + { + conn.setAdapter(adapter); + return __clientAllTests__(out, communicator, amd ? global.TestAMD : global.Test); + }); + }); + }); + }; + + var run = function(out, id) + { + return Promise.try( + function() + { + id.properties.setProperty("Ice.MessageSizeMax", "10"); + id.properties.setProperty("Ice.Warn.Dispatch", "0"); + var communicator = Ice.initialize(id); + out.writeLine("testing bidir callbacks with synchronous dispatch..."); + return allTests(out, communicator, false).then( + function() + { + return communicator.destroy(); + } + ).then( + function() + { + communicator = Ice.initialize(id); + out.writeLine("testing bidir callbacks with asynchronous dispatch..."); + return allTests(out, communicator, true); + } + ).then( + function() + { + return communicator.destroy(); + } + ).then( + function() + { + communicator = Ice.initialize(id); + var ref = "__echo:default -p 12010"; + var base = communicator.stringToProxy(ref); + return global.Test.EchoPrx.checkedCast(base); + } + ).then( + function(prx) + { + return prx.shutdown(); + } + ).then( + function() + { + return communicator.destroy(); + }); + }); + return p; + }; + global.__test__ = run; + global.__runEchoServer__ = true; +}(typeof (global) === "undefined" ? window : global)); diff --git a/js/test/Ice/exceptionsBidir/Makefile b/js/test/Ice/exceptionsBidir/Makefile new file mode 100644 index 00000000000..2389e17b290 --- /dev/null +++ b/js/test/Ice/exceptionsBidir/Makefile @@ -0,0 +1,24 @@ +# ********************************************************************** +# +# 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 \ + TestAMD.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/exceptionsBidir/Makefile.mak b/js/test/Ice/exceptionsBidir/Makefile.mak new file mode 100644 index 00000000000..b6f6e8e97a1 --- /dev/null +++ b/js/test/Ice/exceptionsBidir/Makefile.mak @@ -0,0 +1,21 @@ +# ********************************************************************** +# +# 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 \ + TestAMD.js + +SRCS = Client.js + +!include $(top_srcdir)\config\Make.rules.mak.js + +SLICE2JSFLAGS = $(SLICE2JSFLAGS) -I"$(slicedir)" diff --git a/js/test/Ice/exceptionsBidir/Test.ice b/js/test/Ice/exceptionsBidir/Test.ice new file mode 100644 index 00000000000..347c85e7130 --- /dev/null +++ b/js/test/Ice/exceptionsBidir/Test.ice @@ -0,0 +1,83 @@ +// ********************************************************************** +// +// 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; +}; + +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; +}; + +interface WrongOperation +{ + void noSuchOperation(); +}; + +interface Echo +{ + void startBatch(); + void flushBatch(); + void shutdown(); +}; + +}; diff --git a/js/test/Ice/exceptionsBidir/TestAMD.ice b/js/test/Ice/exceptionsBidir/TestAMD.ice new file mode 100644 index 00000000000..7b8e9166036 --- /dev/null +++ b/js/test/Ice/exceptionsBidir/TestAMD.ice @@ -0,0 +1,83 @@ +// ********************************************************************** +// +// 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 TestAMD +{ + +interface Empty +{ +}; + +interface Thrower; + +exception A +{ + int aMem; +}; + +exception B extends A +{ + int bMem; +}; + +exception C extends B +{ + int cMem; +}; + +exception D +{ + int dMem; +}; + +["amd"] 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; +}; + +interface WrongOperation +{ + void noSuchOperation(); +}; + +interface Echo +{ + void startBatch(); + void flushBatch(); + void shutdown(); +}; + +}; diff --git a/js/test/Ice/exceptionsBidir/ThrowerI.js b/js/test/Ice/exceptionsBidir/ThrowerI.js new file mode 100644 index 00000000000..0c4ef9b883a --- /dev/null +++ b/js/test/Ice/exceptionsBidir/ThrowerI.js @@ -0,0 +1,161 @@ +// ********************************************************************** +// +// 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 Ice = global.Ice; + var Test = global.Test; + + var Class = Ice.Class; + + var test = function(b) + { + if(!b) + { + throw new Error("test failed"); + } + }; + + var ThrowerI = Class(Test.Thrower, { + shutdown: function(current) + { + current.adapter.getCommunicator().shutdown(); + }, + + supportsUndeclaredExceptions: function(current) + { + return true; + }, + + supportsAssertException: function(current) + { + return false; + }, + + throwAasA: function(a, current) + { + var ex = new Test.A(); + ex.aMem = a; + throw ex; + }, + + throwAorDasAorD: function(a, current) + { + if(a > 0) + { + var ex = new Test.A(); + ex.aMem = a; + throw ex; + } + else + { + var ex = new Test.D(); + ex.dMem = a; + throw ex; + } + }, + + throwBasA: function(a, b, current) + { + this.throwBasB(a, b, current); + }, + + throwBasB: function(a, b, current) + { + var ex = new Test.B(); + ex.aMem = a; + ex.bMem = b; + throw ex; + }, + + throwCasA: function(a, b, c, current) + { + this.throwCasC(a, b, c, current); + }, + + throwCasB: function(a, b, c, current) + { + this.throwCasC(a, b, c, current); + }, + + throwCasC: function(a, b, c, current) + { + var ex = new Test.C(); + ex.aMem = a; + ex.bMem = b; + ex.cMem = c; + throw ex; + }, + + throwUndeclaredA: function(a, current) + { + var ex = new Test.A(); + ex.aMem = a; + throw ex; + }, + + throwUndeclaredB: function(a, b, current) + { + var ex = new Test.B(); + ex.aMem = a; + ex.bMem = b; + throw ex; + }, + + throwUndeclaredC: function(a, b, c, current) + { + var ex = new Test.C(); + ex.aMem = a; + ex.bMem = b; + ex.cMem = c; + throw ex; + }, + + throwLocalException: function(current) + { + throw new Ice.TimeoutException(); + }, + + throwLocalExceptionIdempotent: function(current) + { + throw new Ice.TimeoutException(); + }, + + throwNonIceException: function(current) + { + throw new Error(); + }, + + throwAssertException: function(current) + { + test(false); + }, + + throwMemoryLimitException: function(seq, current) + { + return Ice.Buffer.createNative(1024 * 20); // 20KB is over the configured 10KB message size max. + }, + + throwAfterResponse: function(current) + { + // + // Only relevant for AMD. + // + }, + + throwAfterException: function(current) + { + // + // Only relevant for AMD. + // + throw new Test.A(); + }, + }); + + global.ThrowerI = ThrowerI; +}(typeof (global) === "undefined" ? window : global)); diff --git a/js/test/Ice/exceptionsBidir/run.js b/js/test/Ice/exceptionsBidir/run.js new file mode 100644 index 00000000000..a875f421701 --- /dev/null +++ b/js/test/Ice/exceptionsBidir/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/exceptionsBidir/run.py b/js/test/Ice/exceptionsBidir/run.py new file mode 100755 index 00000000000..d40340f6d10 --- /dev/null +++ b/js/test/Ice/exceptionsBidir/run.py @@ -0,0 +1,32 @@ +#!/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.clientEchoTest(additionalServerOptions="--Ice.Warn.Dispatch=0") + +print("Running test with sliced format.") +TestUtil.clientEchoTest(additionalClientOptions="--Ice.Default.SlicedFormat", + additionalServerOptions="--Ice.Default.SlicedFormat --Ice.Warn.Dispatch=0") + +print("Running test with 1.0 encoding.") +TestUtil.clientEchoTest(additionalClientOptions="--Ice.Default.EncodingVersion=1.0", + additionalServerOptions="--Ice.Default.EncodingVersion=1.0 --Ice.Warn.Dispatch=0") diff --git a/js/test/Ice/facets/.gitignore b/js/test/Ice/facets/.gitignore new file mode 100644 index 00000000000..d158d9308ba --- /dev/null +++ b/js/test/Ice/facets/.gitignore @@ -0,0 +1,2 @@ +Test.js +index.html diff --git a/js/test/Ice/facets/Client.js b/js/test/Ice/facets/Client.js new file mode 100644 index 00000000000..ba88bbc34b5 --- /dev/null +++ b/js/test/Ice/facets/Client.js @@ -0,0 +1,261 @@ +// ********************************************************************** +// +// 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 allTests = function(out, communicator) + { + 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 ref, db, prx, prx2, prx3, d, df, df2, df3, ff, gf, hf; + + Promise.try( + function() + { + out.write("testing stringToProxy... "); + ref = "d:default -p 12010"; + db = communicator.stringToProxy(ref); + test(db !== null); + out.writeLine("ok"); + + out.write("testing unchecked cast... "); + prx = Ice.ObjectPrx.uncheckedCast(db); + test(prx.ice_getFacet().length === 0); + prx = Ice.ObjectPrx.uncheckedCast(db, "facetABCD"); + test(prx.ice_getFacet() == "facetABCD"); + prx2 = Ice.ObjectPrx.uncheckedCast(prx); + test(prx2.ice_getFacet() == "facetABCD"); + prx3 = Ice.ObjectPrx.uncheckedCast(prx, ""); + test(prx3.ice_getFacet().length === 0); + d = Test.DPrx.uncheckedCast(db); + test(d.ice_getFacet().length === 0); + df = Test.DPrx.uncheckedCast(db, "facetABCD"); + test(df.ice_getFacet() == "facetABCD"); + df2 = Test.DPrx.uncheckedCast(df); + test(df2.ice_getFacet() == "facetABCD"); + df3 = Test.DPrx.uncheckedCast(df, ""); + test(df3.ice_getFacet().length === 0); + out.writeLine("ok"); + out.write("testing checked cast... "); + return Ice.ObjectPrx.checkedCast(db); + } + ).then( + function(obj) + { + prx = obj; + test(prx.ice_getFacet().length === 0); + return Ice.ObjectPrx.checkedCast(db, "facetABCD"); + } + ).then( + function(obj) + { + prx = obj; + test(prx.ice_getFacet() == "facetABCD"); + return Ice.ObjectPrx.checkedCast(prx); + } + ).then( + function(obj) + { + prx2 = obj; + test(prx2.ice_getFacet() == "facetABCD"); + return Ice.ObjectPrx.checkedCast(prx, ""); + } + ).then( + function(obj) + { + prx3 = obj; + test(prx3.ice_getFacet().length === 0); + return Test.DPrx.checkedCast(db); + } + ).then( + function(obj) + { + d = obj; + test(d.ice_getFacet().length === 0); + return Test.DPrx.checkedCast(db, "facetABCD"); + } + ).then( + function(obj) + { + df = obj; + test(df.ice_getFacet() == "facetABCD"); + return Test.DPrx.checkedCast(df); + } + ).then( + function(obj) + { + df2 = obj; + test(df2.ice_getFacet() == "facetABCD"); + return Test.DPrx.checkedCast(df, ""); + } + ).then( + function(obj) + { + df3 = obj; + test(df3.ice_getFacet().length === 0); + out.writeLine("ok"); + out.write("testing non-facets A, B, C, and D... "); + return Test.DPrx.checkedCast(db); + } + ).then( + function(obj) + { + d = obj; + test(d !== null); + test(d.equals(db)); + + return Promise.all( + d.callA(), + d.callB(), + d.callC(), + d.callD()); + } + ).then( + function(r1, r2, r3, r4) + { + test(r1[0] == "A"); + test(r2[0] == "B"); + test(r3[0] == "C"); + test(r4[0] == "D"); + out.writeLine("ok"); + out.write("testing facets A, B, C, and D... "); + return Test.DPrx.checkedCast(d, "facetABCD"); + } + ).then( + function(obj) + { + df = obj; + test(df !== null); + + return Promise.all( + df.callA(), + df.callB(), + df.callC(), + df.callD()); + } + ).then( + function(r1, r2, r3, r4) + { + test(r1[0] == "A"); + test(r2[0] == "B"); + test(r3[0] == "C"); + test(r4[0] == "D"); + out.writeLine("ok"); + out.write("testing facets E and F... "); + return Test.FPrx.checkedCast(d, "facetEF"); + } + ).then( + function(obj) + { + ff = obj; + test(ff !== null); + + return Promise.all( + ff.callE(), + ff.callF()); + } + ).then( + function(r1, r2) + { + test(r1[0] == "E"); + test(r2[0] == "F"); + out.writeLine("ok"); + out.write("testing facet G... "); + return Test.GPrx.checkedCast(ff, "facetGH"); + } + ).then( + function(obj) + { + gf = obj; + test(gf !== null); + return gf.callG(); + } + ).then( + function(v) + { + test(v == "G"); + out.writeLine("ok"); + out.write("testing whether casting preserves the facet... "); + return Test.HPrx.checkedCast(gf); + } + ).then( + function(obj) + { + hf = obj; + test(hf !== null); + + return Promise.all( + hf.callG(), + hf.callH()); + } + ).then( + function(r1, r2) + { + test(r1[0] == "G"); + test(r2[0] == "H"); + out.writeLine("ok"); + return gf.shutdown(); + } + ).then( + function() + { + p.succeed(); + }, + function(ex) + { + p.fail(ex); + } + ); + 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.__clientAllTests__ = allTests; + global.__runServer__ = true; +}(typeof (global) === "undefined" ? window : global)); diff --git a/js/test/Ice/facets/Makefile b/js/test/Ice/facets/Makefile new file mode 100644 index 00000000000..8f81ea44140 --- /dev/null +++ b/js/test/Ice/facets/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/facets/Makefile.mak b/js/test/Ice/facets/Makefile.mak new file mode 100644 index 00000000000..61a62482429 --- /dev/null +++ b/js/test/Ice/facets/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/facets/Test.ice b/js/test/Ice/facets/Test.ice new file mode 100644 index 00000000000..23273a5388a --- /dev/null +++ b/js/test/Ice/facets/Test.ice @@ -0,0 +1,61 @@ +// ********************************************************************** +// +// 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 +{ + +interface Empty +{ +}; + +interface A +{ + string callA(); +}; + +interface B extends A +{ + string callB(); +}; + +interface C extends A +{ + string callC(); +}; + +interface D extends B, C +{ + string callD(); +}; + +interface E +{ + string callE(); +}; + +interface F extends E +{ + string callF(); +}; + +interface G +{ + void shutdown(); + string callG(); +}; + +interface H extends G +{ + string callH(); +}; + +}; + diff --git a/js/test/Ice/facets/run.js b/js/test/Ice/facets/run.js new file mode 100644 index 00000000000..a875f421701 --- /dev/null +++ b/js/test/Ice/facets/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/facets/run.py b/js/test/Ice/facets/run.py new file mode 100755 index 00000000000..33fc2e8f3ac --- /dev/null +++ b/js/test/Ice/facets/run.py @@ -0,0 +1,23 @@ +#!/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 + +TestUtil.clientServerTest() diff --git a/js/test/Ice/facetsBidir/.gitignore b/js/test/Ice/facetsBidir/.gitignore new file mode 100644 index 00000000000..d158d9308ba --- /dev/null +++ b/js/test/Ice/facetsBidir/.gitignore @@ -0,0 +1,2 @@ +Test.js +index.html diff --git a/js/test/Ice/facetsBidir/Client.js b/js/test/Ice/facetsBidir/Client.js new file mode 100644 index 00000000000..757fcc9e956 --- /dev/null +++ b/js/test/Ice/facetsBidir/Client.js @@ -0,0 +1,178 @@ +// ********************************************************************** +// +// 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"); + require("../facets/Client"); + var Test = global.Test; + var Promise = Ice.Promise; + + require("TestI"); + var DI = global.DI; + var FI = global.FI; + var HI = global.HI; + var EmptyI = global.EmptyI; + + var allTests = function(out, communicator) + { + var p = new Promise(); + var test = function(b) + { + if(!b) + { + try + { + throw new Error("test failed"); + } + catch(err) + { + p.fail(err); + throw err; + } + } + }; + Promise.try( + function() + { + out.write("testing facet registration exceptions... "); + return communicator.createObjectAdapter(""); + } + ).then( + function(adapter) + { + var obj = new EmptyI(); + adapter.add(obj, communicator.stringToIdentity("d")); + adapter.addFacet(obj, communicator.stringToIdentity("d"), "facetABCD"); + try + { + adapter.addFacet(obj, communicator.stringToIdentity("d"), "facetABCD"); + test(false); + } + catch(ex) + { + test(ex instanceof Ice.AlreadyRegisteredException); + } + adapter.removeFacet(communicator.stringToIdentity("d"), "facetABCD"); + try + { + adapter.removeFacet(communicator.stringToIdentity("d"), "facetABCD"); + test(false); + } + catch(ex) + { + test(ex instanceof Ice.NotRegisteredException); + } + out.writeLine("ok"); + + out.write("testing removeAllFacets... "); + var obj1 = new EmptyI(); + var obj2 = new EmptyI(); + adapter.addFacet(obj1, communicator.stringToIdentity("id1"), "f1"); + adapter.addFacet(obj2, communicator.stringToIdentity("id1"), "f2"); + var obj3 = new EmptyI(); + adapter.addFacet(obj1, communicator.stringToIdentity("id2"), "f1"); + adapter.addFacet(obj2, communicator.stringToIdentity("id2"), "f2"); + adapter.addFacet(obj3, communicator.stringToIdentity("id2"), ""); + var fm = adapter.removeAllFacets(communicator.stringToIdentity("id1")); + test(fm.size === 2); + test(fm.get("f1") === obj1); + test(fm.get("f2") === obj2); + try + { + adapter.removeAllFacets(communicator.stringToIdentity("id1")); + test(false); + } + catch(ex) + { + test(ex instanceof Ice.NotRegisteredException); + } + fm = adapter.removeAllFacets(communicator.stringToIdentity("id2")); + test(fm.size == 3); + test(fm.get("f1") === obj1); + test(fm.get("f2") === obj2); + test(fm.get("") === obj3); + out.writeLine("ok"); + + return adapter.deactivate(); + } + ).then( + function(r) + { + return communicator.createObjectAdapter(""); + } + ).then( + function(adapter) + { + var di = new DI(); + adapter.add(di, communicator.stringToIdentity("d")); + adapter.addFacet(di, communicator.stringToIdentity("d"), "facetABCD"); + var fi = new FI(); + adapter.addFacet(fi, communicator.stringToIdentity("d"), "facetEF"); + var hi = new HI(); + adapter.addFacet(hi, communicator.stringToIdentity("d"), "facetGH"); + + var prx = Ice.ObjectPrx.uncheckedCast(communicator.stringToProxy("d:default -p 12010")); + return prx.ice_getConnection().then( + function(conn) + { + conn.setAdapter(adapter); + return __clientAllTests__(out, communicator); + }); + } + ).then( + function() + { + p.succeed(); + }, + function(ex) + { + p.fail(ex); + }); + + return p; + }; + + var run = function(out, id) + { + return Promise.try( + function() + { + var communicator = Ice.initialize(id); + out.writeLine("testing bidir callbacks with synchronous dispatch..."); + return allTests(out, communicator).then( + function() + { + return communicator.destroy(); + } + ).then( + function() + { + communicator = Ice.initialize(id); + return global.Test.EchoPrx.checkedCast( + communicator.stringToProxy("__echo:default -p 12010")); + } + ).then( + function(prx) + { + return prx.shutdown(); + } + ).then( + function() + { + return communicator.destroy(); + }); + }); + }; + global.__test__ = run; + global.__runEchoServer__ = true; +}(typeof (global) === "undefined" ? window : global)); diff --git a/js/test/Ice/facetsBidir/Makefile b/js/test/Ice/facetsBidir/Makefile new file mode 100644 index 00000000000..8f81ea44140 --- /dev/null +++ b/js/test/Ice/facetsBidir/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/facetsBidir/Makefile.mak b/js/test/Ice/facetsBidir/Makefile.mak new file mode 100644 index 00000000000..61a62482429 --- /dev/null +++ b/js/test/Ice/facetsBidir/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/facetsBidir/Test.ice b/js/test/Ice/facetsBidir/Test.ice new file mode 100644 index 00000000000..4d52ac39d51 --- /dev/null +++ b/js/test/Ice/facetsBidir/Test.ice @@ -0,0 +1,67 @@ +// ********************************************************************** +// +// 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 +{ + +interface Empty +{ +}; + +interface A +{ + string callA(); +}; + +interface B extends A +{ + string callB(); +}; + +interface C extends A +{ + string callC(); +}; + +interface D extends B, C +{ + string callD(); +}; + +interface E +{ + string callE(); +}; + +interface F extends E +{ + string callF(); +}; + +interface G +{ + void shutdown(); + string callG(); +}; + +interface H extends G +{ + string callH(); +}; + +interface Echo +{ + void startBatch(); + void flushBatch(); + void shutdown(); +}; + +}; diff --git a/js/test/Ice/facetsBidir/TestI.js b/js/test/Ice/facetsBidir/TestI.js new file mode 100644 index 00000000000..64675fba656 --- /dev/null +++ b/js/test/Ice/facetsBidir/TestI.js @@ -0,0 +1,70 @@ +// ********************************************************************** +// +// 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 Ice = global.Ice; + var Test = global.Test; + + var Class = Ice.Class; + + var DI = Class(Test.D, { + callA: function(current) + { + return "A"; + }, + callB: function(current) + { + return "B"; + }, + callC: function(current) + { + return "C"; + }, + callD: function(current) + { + return "D"; + } + }); + + global.DI = DI; + + var EmptyI = Class(Test.Empty, {}); + + global.EmptyI = EmptyI; + + var FI = Class(Test.F, { + callE: function(current) + { + return "E"; + }, + callF: function(current) + { + return "F"; + } + }); + + global.FI = FI; + + var HI = Class(Test.H, { + callG: function(current) + { + return "G"; + }, + callH: function(current) + { + return "H"; + }, + shutdown: function(current) + { + current.adapter.getCommunicator().shutdown(); + } + }); + + global.HI = HI; +}(typeof (global) === "undefined" ? window : global)); diff --git a/js/test/Ice/facetsBidir/run.js b/js/test/Ice/facetsBidir/run.js new file mode 100644 index 00000000000..a875f421701 --- /dev/null +++ b/js/test/Ice/facetsBidir/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/facetsBidir/run.py b/js/test/Ice/facetsBidir/run.py new file mode 100755 index 00000000000..c8be7a2da26 --- /dev/null +++ b/js/test/Ice/facetsBidir/run.py @@ -0,0 +1,23 @@ +#!/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 + +TestUtil.clientEchoTest() diff --git a/js/test/Ice/inheritance/.gitignore b/js/test/Ice/inheritance/.gitignore new file mode 100644 index 00000000000..d158d9308ba --- /dev/null +++ b/js/test/Ice/inheritance/.gitignore @@ -0,0 +1,2 @@ +Test.js +index.html diff --git a/js/test/Ice/inheritance/Client.js b/js/test/Ice/inheritance/Client.js new file mode 100644 index 00000000000..0e8de3ce6fb --- /dev/null +++ b/js/test/Ice/inheritance/Client.js @@ -0,0 +1,301 @@ +// ********************************************************************** +// +// 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 allTests = function(out, communicator) + { + var ref, base, initial, ca, cb, cc, cd, ia, ib1, ib2, ic; + var p = new Ice.Promise(); + var test = function(b) + { + if(!b) + { + try + { + throw new Error("test failed"); + } + catch(err) + { + p.fail(err); + throw err; + } + } + }; + + Promise.try( + function() + { + out.write("testing stringToProxy... "); + ref = "initial:default -p 12010"; + base = communicator.stringToProxy(ref); + test(base !== null); + out.writeLine("ok"); + out.write("testing checked cast... "); + return Test.InitialPrx.checkedCast(base); + } + ).then( + function(obj) + { + initial = obj; + test(initial !== null); + test(initial.equals(base)); + out.writeLine("ok"); + + out.write("getting proxies for class hierarchy... "); + return Promise.all(initial.caop(), + initial.cbop(), + initial.ccop(), + initial.cdop()); + } + ).then( + function(r1, r2, r3, r4) + { + ca = r1[0]; + cb = r2[0]; + cc = r3[0]; + cd = r4[0]; + + test(ca !== cb); + test(ca !== cc); + test(ca !== cd); + test(cb !== cc); + test(cb !== cd); + test(cc !== cd); + out.writeLine("ok"); + out.write("getting proxies for interface hierarchy... "); + + return Promise.all(initial.iaop(), + initial.ib1op(), + initial.ib2op(), + initial.icop()); + } + ).then( + function(r1, r2, r3, r4) + { + ia = r1[0]; + ib1 = r2[0]; + test(ib1.ice_instanceof(Test.MB.IB1Prx)); + ib2 = r3[0]; + ic = r4[0]; + + test(ia !== ib1); + test(ia !== ib2); + test(ia !== ic); + test(ib1 !== ic); + test(ib2 !== ic); + out.writeLine("ok"); + out.write("invoking proxy operations on class hierarchy... "); + return Promise.all( + ca.caop(ca), // r1 + ca.caop(cb), // r2 + ca.caop(cc), // r3 + cb.caop(ca), // r4 + cb.caop(cb), // r5 + cb.caop(cc), // r6 + cc.caop(ca), // r7 + cc.caop(cb), // r8 + cc.caop(cc), // r9 + cb.cbop(cb), // r10 + cb.cbop(cb), // r11 + cb.cbop(cc), // r12 + cb.cbop(cc), // r13 + cc.cbop(cb), // r14 + cc.cbop(cb), // r15 + cc.cbop(cc), // r16 + cc.cbop(cc), // r17 + cc.ccop(cc), // r18 + cc.ccop(cc), // r19 + cc.ccop(cc)) // r20 + } + ).then( + function(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, + r11, r12, r13, r14, r15, r16, r17, r18, r19, r20) + { + test(r1[0].equals(ca)); + test(r2[0].equals(cb)); + test(r3[0].equals(cc)); + test(r4[0].equals(ca)); + test(r5[0].equals(cb)); + test(r6[0].equals(cc)); + test(r7[0].equals(ca)); + test(r8[0].equals(cb)); + test(r9[0].equals(cc)); + test(r10[0].equals(cb)); + test(r11[0].equals(cb)); + test(r12[0].equals(cc)); + test(r13[0].equals(cc)); + test(r14[0].equals(cb)); + test(r15[0].equals(cb)); + test(r16[0].equals(cc)); + test(r17[0].equals(cc)); + test(r18[0].equals(cc)); + test(r19[0].equals(cc)); + test(r20[0].equals(cc)); + + out.writeLine("ok"); + out.write("ditto, but for interface hierarchy... "); + + return Promise.all( + ia.iaop(ia), // r1 + ia.iaop(ib1), // r2 + ia.iaop(ib2), // r3 + ia.iaop(ic), // r4 + ib1.ib1op(ia), // r5 + ib1.iaop(ib1), // r6 + ib1.iaop(ib2), // r7 + ib1.iaop(ic), // r8 + ib2.iaop(ia), // r9 + ib2.iaop(ib1), // r10 + ib2.iaop(ib2), // r11 + ib2.iaop(ic), // r12 + ic.iaop(ia), // r13 + ic.iaop(ib1), // r14 + ic.iaop(ib2), // r15 + ic.iaop(ic), // r16 + ib1.ib1op(ib1), // r17 + ib1.ib1op(ib1), // r18 + ib1.ib1op(ic), // r19 + ib1.ib1op(ic), // r20 + ic.ib1op(ib1), // r21 + ic.ib1op(ib1), // r22 + ic.ib1op(ic), // r23 + ic.ib1op(ic), // r24 + ib2.ib2op(ib2), // r25 + ib2.ib2op(ib2), // r26 + ib2.ib2op(ic), // r27 + ib2.ib2op(ic), // r28 + ic.ib2op(ib2), // r29 + ic.ib2op(ib2), // r30 + ic.ib2op(ic), // r31 + ic.ib2op(ic), // r32 + ic.icop(ic), // r33 + ic.icop(ic), // r34 + ic.icop(ic), // r35 + ic.icop(ic)); // r36 + } + ).then( + function(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, + r11, r12, r13, r14, r15, r16, r17, r18, r19, r20, + r21, r22, r23, r24, r25, r26, r27, r28, r29, r30, + r31, r32, r33, r34, r35, r36) + { + test(r1[0].equals(ia)); + test(r2[0].equals(ib1)); + test(r3[0].equals(ib2)); + test(r4[0].equals(ic)); + test(r5[0].equals(ia)); + test(r6[0].equals(ib1)); + test(r7[0].equals(ib2)); + test(r8[0].equals(ic)); + test(r9[0].equals(ia)); + test(r10[0].equals(ib1)); + test(r11[0].equals(ib2)); + test(r12[0].equals(ic)); + test(r13[0].equals(ia)); + test(r14[0].equals(ib1)); + test(r15[0].equals(ib2)); + test(r16[0].equals(ic)); + test(r17[0].equals(ib1)); + test(r18[0].equals(ib1)); + test(r19[0].equals(ic)); + test(r20[0].equals(ic)); + test(r21[0].equals(ib1)); + test(r22[0].equals(ib1)); + test(r23[0].equals(ic)); + test(r24[0].equals(ic)); + test(r25[0].equals(ib2)); + test(r26[0].equals(ib2)); + test(r27[0].equals(ic)); + test(r28[0].equals(ic)); + test(r29[0].equals(ib2)); + test(r30[0].equals(ib2)); + test(r31[0].equals(ic)); + test(r32[0].equals(ic)); + test(r33[0].equals(ic)); + test(r34[0].equals(ic)); + test(r35[0].equals(ic)); + test(r36[0].equals(ic)); + + out.writeLine("ok"); + out.write("ditto, but for class implementing interfaces... "); + + return Promise.all( + cd.caop(cd), // r1 + cd.cbop(cd), // r2 + cd.ccop(cd), // r3 + cd.iaop(cd), // r4 + cd.ib1op(cd), // r5 + cd.ib2op(cd), // r6 + cd.cdop(cd), // r7 + cd.cdop(cd), // r8 + cd.cdop(cd), // r9 + cd.cdop(cd), // r10 + cd.cdop(cd), // r11 + cd.cdop(cd)); // r12 + } + ).then( + function(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, + r11, r12) + { + test(r1[0].equals(cd)); + test(r2[0].equals(cd)); + test(r3[0].equals(cd)); + test(r4[0].equals(cd)); + test(r5[0].equals(cd)); + test(r6[0].equals(cd)); + test(r7[0].equals(cd)); + test(r8[0].equals(cd)); + test(r9[0].equals(cd)); + test(r10[0].equals(cd)); + test(r11[0].equals(cd)); + test(r12[0].equals(cd)); + out.writeLine("ok"); + return initial.shutdown(); + } + ).then( + function() + { + p.succeed(); + }, + function(ex) + { + p.fail(ex); + } + ); + 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.__clientAllTests__ = allTests; + global.__runServer__ = true; +}(typeof (global) === "undefined" ? window : global)); diff --git a/js/test/Ice/inheritance/Makefile b/js/test/Ice/inheritance/Makefile new file mode 100644 index 00000000000..8f81ea44140 --- /dev/null +++ b/js/test/Ice/inheritance/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/inheritance/Makefile.mak b/js/test/Ice/inheritance/Makefile.mak new file mode 100644 index 00000000000..61a62482429 --- /dev/null +++ b/js/test/Ice/inheritance/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/inheritance/Test.ice b/js/test/Ice/inheritance/Test.ice new file mode 100644 index 00000000000..3049e030d1c --- /dev/null +++ b/js/test/Ice/inheritance/Test.ice @@ -0,0 +1,234 @@ +// ********************************************************************** +// +// 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 +{ + +module MA +{ + +interface IA +{ + IA* iaop(IA* p); +}; + +class CA +{ + CA* caop(CA* p); +}; + +}; + +module MB +{ + +interface IB1 extends MA::IA +{ + IB1* ib1op(IB1* p); +}; + +interface IB2 extends MA::IA +{ + IB2* ib2op(IB2* p); +}; + +class CB extends MA::CA +{ + CB* cbop(CB* p); +}; + +}; + +module MA +{ + +interface IC extends MB::IB1, MB::IB2 +{ + IC* icop(IC* p); +}; + +class CC extends MB::CB +{ + CC* ccop(CC* p); +}; + +class CD extends CC implements MB::IB1, MB::IB2 +{ + CD* cdop(CD* p); +}; + +}; + +interface Initial +{ + void shutdown(); + MA::CA* caop(); + MB::CB* cbop(); + MA::CC* ccop(); + MA::CD* cdop(); + MA::IA* iaop(); + MB::IB1* ib1op(); + MB::IB2* ib2op(); + MA::IC* icop(); +}; + + +module MC +{ + +class A +{ + int aA; +}; + +class B extends A +{ + int bB; +}; + +class C extends B +{ + int cC; +}; + +class D extends C +{ + int dD; +}; + +}; + +module MD +{ + +class A +{ + int aA; +}; + +class B extends A +{ + int bB; +}; + +class C extends B +{ + int cC; +}; + +class D extends C +{ + int dD; +}; + +}; + +module ME +{ + +class A +{ + int aA; +}; + +class B extends A +{ + int bB; +}; + +class C extends B +{ + int cC; +}; + +class D extends C +{ + int dD; +}; + +}; + +module MF +{ + +class A +{ + int aA; +}; + +class B extends A +{ + int bB; +}; + +class C extends B +{ + int cC; +}; + +class D extends C +{ + int dD; +}; + +}; + +module MG +{ + +class A +{ + int aA; +}; + +class B extends A +{ + int bB; +}; + +class C extends B +{ + int cC; +}; + +class D extends C +{ + int dD; +}; + +}; + +module MH +{ + +class A +{ + int aA; +}; + +class B extends A +{ + int bB; +}; + +class C extends B +{ + int cC; +}; + +class D extends C +{ + int dD; +}; + +}; + +}; diff --git a/js/test/Ice/inheritance/run.js b/js/test/Ice/inheritance/run.js new file mode 100644 index 00000000000..a875f421701 --- /dev/null +++ b/js/test/Ice/inheritance/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/inheritance/run.py b/js/test/Ice/inheritance/run.py new file mode 100755 index 00000000000..33fc2e8f3ac --- /dev/null +++ b/js/test/Ice/inheritance/run.py @@ -0,0 +1,23 @@ +#!/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 + +TestUtil.clientServerTest() diff --git a/js/test/Ice/inheritanceBidir/.gitignore b/js/test/Ice/inheritanceBidir/.gitignore new file mode 100644 index 00000000000..d158d9308ba --- /dev/null +++ b/js/test/Ice/inheritanceBidir/.gitignore @@ -0,0 +1,2 @@ +Test.js +index.html diff --git a/js/test/Ice/inheritanceBidir/Client.js b/js/test/Ice/inheritanceBidir/Client.js new file mode 100644 index 00000000000..e2a6def30ac --- /dev/null +++ b/js/test/Ice/inheritanceBidir/Client.js @@ -0,0 +1,75 @@ +// ********************************************************************** +// +// 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"); + require("InitialI"); + require("../inheritance/Client"); + + var Ice = global.Ice; + var Promise = Ice.Promise; + var Test = global.Test; + var InitialI = global.InitialI; + + var allTests = function(out, communicator) + { + return Promise.try( + function() + { + return communicator.createObjectAdapter("").then( + function(adapter) + { + var base = communicator.stringToProxy("initial:default -p 12010"); + adapter.add(new InitialI(adapter, base), communicator.stringToIdentity("initial")); + return base.ice_getConnection().then( + function(conn) + { + conn.setAdapter(adapter); + return __clientAllTests__(out, communicator); + }); + }); + }); + }; + + var run = function(out, id) + { + return Promise.try( + function() + { + var communicator = Ice.initialize(id); + out.writeLine("testing bidir callbacks with synchronous dispatch..."); + return allTests(out, communicator).then( + function() + { + return communicator.destroy(); + } + ).then( + function() + { + communicator = Ice.initialize(id); + return Test.EchoPrx.checkedCast(communicator.stringToProxy("__echo:default -p 12010")); + } + ).then( + function(prx) + { + return prx.shutdown(); + } + ).then( + function() + { + return communicator.destroy(); + }); + }); + }; + global.__test__ = run; + global.__runEchoServer__ = true; +}(typeof (global) === "undefined" ? window : global)); diff --git a/js/test/Ice/inheritanceBidir/InitialI.js b/js/test/Ice/inheritanceBidir/InitialI.js new file mode 100644 index 00000000000..21e8e05ec16 --- /dev/null +++ b/js/test/Ice/inheritanceBidir/InitialI.js @@ -0,0 +1,180 @@ +// ********************************************************************** +// +// 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 Ice = global.Ice; + var Test = global.Test; + + var Class = Ice.Class; + + var CAI = Class(Test.MA.CA, { + caop: function(p, current) + { + return p; + } + }); + + var CBI = Class(Test.MB.CB, { + caop: function(p, current) + { + return p; + }, + cbop: function(p, current) + { + return p; + } + }); + + var CCI = Class(Test.MA.CC, { + caop: function(p, current) + { + return p; + }, + ccop: function(p, current) + { + return p; + }, + cbop: function(p, current) + { + return p; + } + }); + + var CDI = Class(Test.MA.CD, { + caop: function(p, current) + { + return p; + }, + ccop: function(p, current) + { + return p; + }, + cdop: function(p, current) + { + return p; + }, + iaop: function(p, current) + { + return p; + }, + cbop: function(p, current) + { + return p; + }, + ib1op: function(p, current) + { + return p; + }, + ib2op: function(p, current) + { + return p; + } + }); + + var IAI = Class(Test.MA.IA, { + iaop: function(p, current) + { + return p; + } + }); + + var IB1I = Class(Test.MB.IB1, { + iaop: function(p, current) + { + return p; + }, + ib1op: function(p, current) + { + return p; + } + }); + + var IB2I = Class(Test.MB.IB2, { + iaop: function(p, current) + { + return p; + }, + ib2op: function(p, current) + { + return p; + } + }); + + var ICI = Class(Test.MA.IC, { + iaop: function(p, current) + { + return p; + }, + icop: function(p, current) + { + return p; + }, + ib1op: function(p, current) + { + return p; + }, + ib2op: function(p, current) + { + return p; + } + }); + + var InitialI = Class(Test.Initial, { + __init__: function(adapter, obj) + { + var endpts = obj.ice_getEndpoints(); + this._ca = Test.MA.CAPrx.uncheckedCast(adapter.addWithUUID(new CAI()).ice_endpoints(endpts)); + this._cb = Test.MB.CBPrx.uncheckedCast(adapter.addWithUUID(new CBI()).ice_endpoints(endpts)); + this._cc = Test.MA.CCPrx.uncheckedCast(adapter.addWithUUID(new CCI()).ice_endpoints(endpts)); + this._cd = Test.MA.CDPrx.uncheckedCast(adapter.addWithUUID(new CDI()).ice_endpoints(endpts)); + this._ia = Test.MA.IAPrx.uncheckedCast(adapter.addWithUUID(new IAI()).ice_endpoints(endpts)); + this._ib1 = Test.MB.IB1Prx.uncheckedCast(adapter.addWithUUID(new IB1I()).ice_endpoints(endpts)); + this._ib2 = Test.MB.IB2Prx.uncheckedCast(adapter.addWithUUID(new IB2I()).ice_endpoints(endpts)); + this._ic = Test.MA.ICPrx.uncheckedCast(adapter.addWithUUID(new ICI()).ice_endpoints(endpts)); + }, + caop: function(current) + { + return this._ca; + }, + cbop: function(current) + { + return this._cb; + }, + ccop: function(current) + { + return this._cc; + }, + cdop: function(current) + { + return this._cd; + }, + iaop: function(current) + { + return this._ia; + }, + ib1op: function(current) + { + return this._ib1; + }, + ib2op: function(current) + { + return this._ib2; + }, + icop: function(current) + { + return this._ic; + }, + shutdown: function(current) + { + current.adapter.getCommunicator().shutdown(); + } + }); + + global.InitialI = InitialI; +}(typeof (global) === "undefined" ? window : global)); diff --git a/js/test/Ice/inheritanceBidir/Makefile b/js/test/Ice/inheritanceBidir/Makefile new file mode 100644 index 00000000000..8f81ea44140 --- /dev/null +++ b/js/test/Ice/inheritanceBidir/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/inheritanceBidir/Makefile.mak b/js/test/Ice/inheritanceBidir/Makefile.mak new file mode 100644 index 00000000000..61a62482429 --- /dev/null +++ b/js/test/Ice/inheritanceBidir/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/inheritanceBidir/Test.ice b/js/test/Ice/inheritanceBidir/Test.ice new file mode 100644 index 00000000000..09b3d2f6d19 --- /dev/null +++ b/js/test/Ice/inheritanceBidir/Test.ice @@ -0,0 +1,241 @@ +// ********************************************************************** +// +// 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 +{ + +module MA +{ + +interface IA +{ + IA* iaop(IA* p); +}; + +class CA +{ + CA* caop(CA* p); +}; + +}; + +module MB +{ + +interface IB1 extends MA::IA +{ + IB1* ib1op(IB1* p); +}; + +interface IB2 extends MA::IA +{ + IB2* ib2op(IB2* p); +}; + +class CB extends MA::CA +{ + CB* cbop(CB* p); +}; + +}; + +module MA +{ + +interface IC extends MB::IB1, MB::IB2 +{ + IC* icop(IC* p); +}; + +class CC extends MB::CB +{ + CC* ccop(CC* p); +}; + +class CD extends CC implements MB::IB1, MB::IB2 +{ + CD* cdop(CD* p); +}; + +}; + +interface Initial +{ + void shutdown(); + MA::CA* caop(); + MB::CB* cbop(); + MA::CC* ccop(); + MA::CD* cdop(); + MA::IA* iaop(); + MB::IB1* ib1op(); + MB::IB2* ib2op(); + MA::IC* icop(); +}; + + +module MC +{ + +class A +{ + int aA; +}; + +class B extends A +{ + int bB; +}; + +class C extends B +{ + int cC; +}; + +class D extends C +{ + int dD; +}; + +}; + +module MD +{ + +class A +{ + int aA; +}; + +class B extends A +{ + int bB; +}; + +class C extends B +{ + int cC; +}; + +class D extends C +{ + int dD; +}; + +}; + +module ME +{ + +class A +{ + int aA; +}; + +class B extends A +{ + int bB; +}; + +class C extends B +{ + int cC; +}; + +class D extends C +{ + int dD; +}; + +}; + +module MF +{ + +class A +{ + int aA; +}; + +class B extends A +{ + int bB; +}; + +class C extends B +{ + int cC; +}; + +class D extends C +{ + int dD; +}; + +}; + +module MG +{ + +class A +{ + int aA; +}; + +class B extends A +{ + int bB; +}; + +class C extends B +{ + int cC; +}; + +class D extends C +{ + int dD; +}; + +}; + +module MH +{ + +class A +{ + int aA; +}; + +class B extends A +{ + int bB; +}; + +class C extends B +{ + int cC; +}; + +class D extends C +{ + int dD; +}; + +}; + +interface Echo +{ + void startBatch(); + void flushBatch(); + void shutdown(); +}; + +}; diff --git a/js/test/Ice/inheritanceBidir/run.js b/js/test/Ice/inheritanceBidir/run.js new file mode 100644 index 00000000000..a875f421701 --- /dev/null +++ b/js/test/Ice/inheritanceBidir/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/inheritanceBidir/run.py b/js/test/Ice/inheritanceBidir/run.py new file mode 100755 index 00000000000..c8be7a2da26 --- /dev/null +++ b/js/test/Ice/inheritanceBidir/run.py @@ -0,0 +1,23 @@ +#!/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 + +TestUtil.clientEchoTest() diff --git a/js/test/Ice/location/.gitignore b/js/test/Ice/location/.gitignore new file mode 100644 index 00000000000..d158d9308ba --- /dev/null +++ b/js/test/Ice/location/.gitignore @@ -0,0 +1,2 @@ +Test.js +index.html diff --git a/js/test/Ice/location/Client.js b/js/test/Ice/location/Client.js new file mode 100644 index 00000000000..bf8c35ebf94 --- /dev/null +++ b/js/test/Ice/location/Client.js @@ -0,0 +1,1326 @@ +// ********************************************************************** +// +// 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(){ + 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 allTests = function(out, communicator) + { + var failCB = function() { test(false); } + + 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 manager, locator, anotherLocator, registry, base, base2, base3, + base4, base5, base6, bases, obj, obj2, obj3, + obj4, obj5, obj6, hello, anotherRouter, router; + + Promise.try( + function() + { + manager = Test.ServerManagerPrx.uncheckedCast( + communicator.stringToProxy("ServerManager:default -p 12010")); + test(manager !== null); + + locator = Test.TestLocatorPrx.uncheckedCast(communicator.getDefaultLocator()); + test(locator !== null); + + return locator.getRegistry(); + } + ).then( + function(obj) + { + registry = Test.TestLocatorRegistryPrx.uncheckedCast(obj); + test(registry !== null); + + out.write("testing stringToProxy... "); + base = communicator.stringToProxy("test @ TestAdapter"); + base2 = communicator.stringToProxy("test @ TestAdapter"); + base3 = communicator.stringToProxy("test"); + base4 = communicator.stringToProxy("ServerManager"); + base5 = communicator.stringToProxy("test2"); + base6 = communicator.stringToProxy("test @ ReplicatedAdapter"); + bases = [base, base2, base3, base4, base5, base6]; + out.writeLine("ok"); + + out.write("testing ice_locator and ice_getLocator... "); + test(Ice.proxyIdentityCompare(base.ice_getLocator(), communicator.getDefaultLocator()) === 0); + anotherLocator = + Ice.LocatorPrx.uncheckedCast(communicator.stringToProxy("anotherLocator")); + base = base.ice_locator(anotherLocator); + test(Ice.proxyIdentityCompare(base.ice_getLocator(), anotherLocator) === 0); + communicator.setDefaultLocator(null); + base = communicator.stringToProxy("test @ TestAdapter"); + test(base.ice_getLocator() === null); + base = base.ice_locator(anotherLocator); + test(Ice.proxyIdentityCompare(base.ice_getLocator(), anotherLocator) === 0); + communicator.setDefaultLocator(locator); + base = communicator.stringToProxy("test @ TestAdapter"); + test(Ice.proxyIdentityCompare(base.ice_getLocator(), communicator.getDefaultLocator()) === 0); + + // + // We also test ice_router/ice_getRouter (perhaps we should add a + // test/Ice/router test?) + // + test(base.ice_getRouter() === null); + anotherRouter = Ice.RouterPrx.uncheckedCast(communicator.stringToProxy("anotherRouter")); + base = base.ice_router(anotherRouter); + test(Ice.proxyIdentityCompare(base.ice_getRouter(), anotherRouter) === 0); + router = Ice.RouterPrx.uncheckedCast(communicator.stringToProxy("dummyrouter")); + communicator.setDefaultRouter(router); + base = communicator.stringToProxy("test @ TestAdapter"); + test(Ice.proxyIdentityCompare(base.ice_getRouter(), communicator.getDefaultRouter()) === 0); + communicator.setDefaultRouter(null); + base = communicator.stringToProxy("test @ TestAdapter"); + test(base.ice_getRouter() == null); + out.writeLine("ok"); + + out.write("starting server... "); + return manager.startServer(); + + } + ).then( + function() + { + out.writeLine("ok"); + out.write("testing checked cast... "); + return Test.TestIntfPrx.checkedCast(base); + } + ).then( + function(o) + { + obj = o; + test(obj !== null); + return Test.TestIntfPrx.checkedCast(base2); + } + ).then( + function(o) + { + obj2 = o; + test(obj2 !== null); + return Test.TestIntfPrx.checkedCast(base3); + } + ).then( + function(o) + { + obj3 = o; + test(obj3 !== null); + return Test.ServerManagerPrx.checkedCast(base4); + } + ).then( + function(o) + { + obj4 = o; + test(obj4 !== null); + return Test.TestIntfPrx.checkedCast(base5); + } + ).then( + function(o) + { + obj5 = o; + test(obj !== null); + return Test.TestIntfPrx.checkedCast(base6); + } + ).then( + function(o) + { + obj6 = o; + test(obj6 !== null); + out.writeLine("ok"); + out.write("testing id@AdapterId indirect proxy... "); + return obj.shutdown(); + } + ).then( + function() + { + return manager.startServer(); + } + ).then( + function() + { + return obj2.ice_ping(); + } + ).then( + function() + { + out.writeLine("ok"); + out.write("testing id@ReplicaGroupId indirect proxy... "); + return obj.shutdown(); + } + ).then( + function() + { + return manager.startServer(); + } + ).then( + function() + { + return obj6.ice_ping(); + } + ).then( + function() + { + out.writeLine("ok"); + out.write("testing identity indirect proxy... "); + obj.shutdown(); + } + ).then( + function() + { + return manager.startServer(); + } + ).then( + function() + { + return obj3.ice_ping(); + } + ).then( + function() + { + return obj2.ice_ping(); + } + ).then( + function() + { + return obj.shutdown(); + } + ).then( + function() + { + return manager.startServer(); + } + ).then( + function() + { + return obj2.ice_ping(); + } + ).then( + function() + { + return obj3.ice_ping(); + } + ).then( + function() + { + return obj.shutdown(); + } + ).then( + function() + { + return manager.startServer(); + } + ).then( + function() + { + return obj2.ice_ping(); + } + ).then( + function() + { + obj.shutdown(); + } + ).then( + function() + { + return manager.startServer(); + } + ).then( + function() + { + return obj3.ice_ping(); + } + ).then( + function() + { + return obj.shutdown(); + } + ).then( + function() + { + return manager.startServer(); + } + ).then( + function() + { + return obj2.ice_ping(); + } + ).then( + function() + { + return obj.shutdown(); + } + ).then( + function() + { + return manager.startServer(); + } + ).then( + function() + { + return obj5.ice_ping(); + } + ).then( + function() + { + out.writeLine("ok"); + out.write("testing proxy with unknown identity... "); + base = communicator.stringToProxy("unknown/unknown"); + return base.ice_ping(); + } + ).then( + failCB, + function(ex) + { + test(ex instanceof Ice.NotRegisteredException); + test(ex.kindOfObject == "object"); + test(ex.id == "unknown/unknown"); + out.writeLine("ok"); + out.write("testing proxy with unknown adapter... "); + base = communicator.stringToProxy("test @ TestAdapterUnknown"); + return base.ice_ping(); + } + ).then( + failCB, + function(ex) + { + test(ex instanceof Ice.NotRegisteredException); + test(ex.kindOfObject == "object adapter"); + test(ex.id == "TestAdapterUnknown"); + out.writeLine("ok"); + out.write("testing locator cache timeout... "); + return locator.getRequestCount(); + } + ).then( + function(count) + { + return Promise.try( + function() + { + // No locator cache. + return communicator.stringToProxy("test@TestAdapter").ice_locatorCacheTimeout(0).ice_ping(); + } + ).then( + function() + { + return locator.getRequestCount(); + } + ).then( + function(newCount) + { + test(++count == newCount); + return count; + }); + } + ).then( + function(count) + { + return Promise.try( + function() + { + // No locator cache. + return communicator.stringToProxy("test@TestAdapter").ice_locatorCacheTimeout(0).ice_ping(); + } + ).then( + function() + { + return locator.getRequestCount(); + } + ).then( + function(newCount) + { + test(++count == newCount); + return count; + }); + } + ).then( + function(count) + { + var p = new Promise(); + Promise.try( + function() + { + // 1s timeout. + return communicator.stringToProxy("test@TestAdapter").ice_locatorCacheTimeout(1).ice_ping(); + } + ).then( + function() + { + return locator.getRequestCount(); + } + ).then( + function(newCount) + { + test(count == newCount); + setTimeout( + function(){ + p.succeed(count); + }, 1200); + }, + function(ex) + { + p.fail(ex); + } + ); + return p; + } + ).then( + function(count) + { + return Promise.try( + function() + { + // 1s timeout. + return communicator.stringToProxy("test@TestAdapter").ice_locatorCacheTimeout(1).ice_ping(); + } + ).then( + function() + { + return locator.getRequestCount(); + } + ).then( + function(newCount) + { + test(++count == newCount); + return count; + }); + } + ).then( + function(count) + { + return Promise.try( + function() + { + // No locator cache. + return communicator.stringToProxy("test").ice_locatorCacheTimeout(0).ice_ping(); + } + ).then( + function() + { + return locator.getRequestCount(); + } + ).then( + function(newCount) + { + count += 2; + return count; + }); + } + ).then( + function(count) + { + var p = new Promise(); + // 1s timeout. + communicator.stringToProxy("test").ice_locatorCacheTimeout(1).ice_ping().then( + function() + { + return locator.getRequestCount(); + } + ).then( + function(newCount) + { + test(count == newCount); + p.succeed(count); + } + ).exception( + function(ex) + { + setTimeout( + function(){ + p.fail(ex); + }, 1200); + }); + return p; + } + ).then( + function(count) + { + return Promise.try( + function() + { + // No locator cache. + return communicator.stringToProxy("test").ice_locatorCacheTimeout(0).ice_ping(); + } + ).then( + function() + { + return locator.getRequestCount(); + } + ).then( + function(newCount) + { + count += 2; + test(count == newCount); + return count; + }); + } + ).then( + function(count) + { + return Promise.try( + function() + { + // 1s timeout. + return communicator.stringToProxy("test@TestAdapter").ice_locatorCacheTimeout(-1).ice_ping(); + } + ).then( + function() + { + return locator.getRequestCount(); + } + ).then( + function(newCount) + { + test(count == newCount); + return count; + }); + } + ).then( + function(count) + { + var p = new Promise(); + // 1s timeout. + communicator.stringToProxy("test").ice_locatorCacheTimeout(-1).ice_ping().then( + function() + { + return locator.getRequestCount(); + } + ).then( + function(newCount) + { + test(count == newCount); + p.succeed(count); + } + ).exception( + function(ex) + { + p.fail(ex); + }); + return p; + } + ).then( + function(count) + { + var p = new Promise(); + // 1s timeout. + communicator.stringToProxy("test@TestAdapter").ice_ping().then( + function() + { + return locator.getRequestCount(); + } + ).then( + function(newCount) + { + test(count == newCount); + p.succeed(count); + } + ).exception( + function(ex) + { + p.fail(ex); + }); + return p; + } + ).then( + function(count) + { + var p = new Promise(); + // 1s timeout. + communicator.stringToProxy("test").ice_ping().then( + function() + { + return locator.getRequestCount(); + } + ).then( + function(newCount) + { + test(count == newCount); + p.succeed(count); + } + ).exception( + function(ex) + { + p.fail(ex); + }); + return p; + } + ).then( + function() + { + test(communicator.stringToProxy("test").ice_locatorCacheTimeout(99).ice_getLocatorCacheTimeout() === 99); + out.writeLine("ok"); + out.write("testing proxy from server... "); + return Test.TestIntfPrx.checkedCast(communicator.stringToProxy("test@TestAdapter")); + } + ).then( + function(o) + { + obj = o; + return Promise.all(obj.getHello(), obj.getReplicatedHello()); + } + ).then( + function(r1, r2) + { + hello = r1[0]; + test(hello.ice_getAdapterId() == "TestAdapter"); + hello = r2[0]; + test(hello.ice_getAdapterId() == "ReplicatedAdapter"); + return hello.sayHello(); + } + ).then( + function() + { + out.writeLine("ok"); + out.write("testing proxy from server after shutdown... "); + return obj.shutdown(); + } + ).then( + function() + { + return manager.startServer(); + } + ).then( + function() + { + return hello.sayHello(); + } + ).then( + function() + { + out.writeLine("ok"); + out.write("testing locator request queuing... "); + return obj.getReplicatedHello(); + } + ).then( + function(o) + { + hello = o.ice_locatorCacheTimeout(0).ice_connectionCached(false); + return locator.getRequestCount(); + } + ).then( + function(count) + { + var p = new Promise(); + hello.ice_ping().then( + function() + { + return locator.getRequestCount(); + } + ).then( + function(newCount) + { + test(++count == newCount); + p.succeed(count); + } + ).exception( + function(ex){ + p.fail(ex); + }); + return p; + } + ).then( + function(count) + { + var all = []; + for(var i = 0; i < 1000; ++i) + { + all.push(hello.sayHello()); + } + + var p = new Promise(); + + Promise.all.apply(Promise, all).then( + function() + { + return locator.getRequestCount(); + } + ).then( + function(newCount) + { + test(count < newCount); + test(newCount < count + 999); + if(newCount > count + 800) + { + out.write("queuing = " + (newCount - count)); + } + hello = hello.ice_adapterId("unknown"); + count = newCount; + p.succeed(count); + } + ).exception( + function(ex) + { + p.fail(ex); + }); + return p; + } + ).then( + function(count) + { + var p = new Promise(); + + var all = 0; + var exCB = function(ex) + { + if(!(ex instanceof Ice.NotRegisteredException)) + { + p.fail(ex); + } + + if(all < 999) + { + all++; + } + else + { + p.succeed(); + } + }; + + var okCB = function() + { + p.fail("test failed"); + }; + + for(var i = 0; i < 1000; ++i) + { + hello.sayHello().then(okCB, exCB); + } + + return p; + } + ).then( + function() + { + out.writeLine("ok"); + out.write("testing adapter locator cache... "); + return communicator.stringToProxy("test@TestAdapter3").ice_ping(); + } + ).then( + failCB, + function(ex) + { + if(!(ex instanceof Ice.NotRegisteredException)) + { + throw ex; + } + test(ex.kindOfObject == "object adapter"); + test(ex.id == "TestAdapter3"); + + return locator.findAdapterById("TestAdapter"); + } + ).then( + function(adapter) + { + return registry.setAdapterDirectProxy("TestAdapter3", adapter); + } + ).then( + function() + { + return communicator.stringToProxy("test@TestAdapter3").ice_ping(); + } + ).then( + function() + { + registry.setAdapterDirectProxy("TestAdapter3", communicator.stringToProxy("dummy:tcp")); + return communicator.stringToProxy("test@TestAdapter3").ice_ping(); + } + ).then( + function() + { + return communicator.stringToProxy("test@TestAdapter3").ice_locatorCacheTimeout(0).ice_ping(); + } + ).then( + failCB, + function(ex) + { + if(!(ex instanceof Ice.LocalException)) + { + throw ex; + } + return communicator.stringToProxy("test@TestAdapter3").ice_ping(); + } + ).then( + failCB, + function(ex) + { + if(!(ex instanceof Ice.LocalException)) + { + throw ex; + } + return locator.findAdapterById("TestAdapter"); + } + ).then( + function(adapter) + { + registry.setAdapterDirectProxy("TestAdapter3", adapter); + return communicator.stringToProxy("test@TestAdapter3").ice_ping(); + } + ).then( + function() + { + out.writeLine("ok"); + out.write("testing well-known object locator cache... "); + return registry.addObject(communicator.stringToProxy("test3@TestUnknown")); + } + ).then( + function() + { + return communicator.stringToProxy("test3").ice_ping(); + } + ).then( + failCB, + function(ex) + { + if(!(ex instanceof Ice.NotRegisteredException)) + { + throw ex; + } + test(ex.kindOfObject == "object adapter"); + test(ex.id == "TestUnknown"); + } + ).then( + function() + { + return registry.addObject(communicator.stringToProxy("test3@TestAdapter4")); // Update + } + ).then( + function() + { + return registry.setAdapterDirectProxy("TestAdapter4", communicator.stringToProxy("dummy:tcp")); + } + ).then( + function() + { + return communicator.stringToProxy("test3").ice_ping(); + } + ).then( + failCB, + function(ex) + { + if(!(ex instanceof Ice.LocalException)) + { + throw ex; + } + return locator.findAdapterById("TestAdapter"); + } + ).then( + function(adapter) + { + return registry.setAdapterDirectProxy("TestAdapter4", adapter); + } + ).then( + function() + { + return communicator.stringToProxy("test3").ice_ping(); + } + ).then( + function() + { + return registry.setAdapterDirectProxy("TestAdapter4", communicator.stringToProxy("dummy:tcp")); + } + ).then( + function() + { + return communicator.stringToProxy("test3").ice_ping(); + } + ).then( + function() + { + return communicator.stringToProxy("test@TestAdapter4").ice_locatorCacheTimeout(0).ice_ping(); + } + ).then( + failCB, + function(ex) + { + if(!(ex instanceof Ice.LocalException)) + { + throw ex; + } + return communicator.stringToProxy("test@TestAdapter4").ice_ping(); + } + ).then( + failCB, + function(ex) + { + if(!(ex instanceof Ice.LocalException)) + { + throw ex; + } + return communicator.stringToProxy("test3").ice_ping(); + } + ).then( + failCB, + function(ex) + { + if(!(ex instanceof Ice.LocalException)) + { + throw ex; + } + return registry.addObject(communicator.stringToProxy("test3@TestAdapter")); + } + ).then( + function() + { + return communicator.stringToProxy("test3").ice_ping(); + } + ).then( + function() + { + return registry.addObject(communicator.stringToProxy("test4")); + } + ).then( + function() + { + return communicator.stringToProxy("test4").ice_ping(); + } + ).then( + failCB, + function(ex) + { + if(!(ex instanceof Ice.NoEndpointException)) + { + throw ex; + } + out.writeLine("ok"); + out.write("testing locator cache background updates... "); + + var initData = new Ice.InitializationData(); + initData.properties = communicator.getProperties().clone(); + initData.properties.setProperty("Ice.BackgroundLocatorCacheUpdates", "1"); + var ic = Ice.initialize(initData); + + var p = new Promise(); + + locator.findAdapterById("TestAdapter").then( + function(adapter) + { + return registry.setAdapterDirectProxy("TestAdapter5", adapter); + } + ).then( + function() + { + return registry.addObject(communicator.stringToProxy("test3@TestAdapter")); + } + ).then( + function() + { + return locator.getRequestCount(); + } + ).then( + function(count) + { + var p1 = new Promise(); + // No locator cache. + ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(0).ice_ping().then( + function() + { + // No locator cache. + return ic.stringToProxy("test3").ice_locatorCacheTimeout(0).ice_ping(); + } + ).then( + function() + { + return locator.getRequestCount(); + } + ).then( + function(newCount) + { + count += 3; + test(count === newCount); + p1.succeed(count); + } + ).exception( + function(ex){ + p1.fail(ex); + }); + + return p1; + } + ).then( + function(count) + { + var p1 = new Promise(); + registry.setAdapterDirectProxy("TestAdapter5", null).then( + function() + { + return registry.addObject(communicator.stringToProxy("test3:tcp")); + } + ).then( + function() + { + // 10s timeout. + return ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(10).ice_ping(); + } + ).then( + function() + { + // 10s timeout. + return ic.stringToProxy("test3").ice_locatorCacheTimeout(10).ice_ping(); + } + ).then( + function() + { + return locator.getRequestCount(); + } + ).then( + function(newCount) + { + test(count = newCount); + setTimeout( + function(){ + p1.succeed(count); + }, 1200); + } + ).exception( + function(ex) + { + p1.fail(ex); + }); + return p1; + } + ).then( + function(count) + { + var p1 = new Promise(); + // The following request should trigger the background updates but still use the cached endpoints + // and therefore succeed. + + // 1s timeout. + ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(1).ice_ping().then( + function() + { + // 1s timeout. + return ic.stringToProxy("test3").ice_locatorCacheTimeout(1).ice_ping(); + } + ).then( + function() + { + p1.succeed(); + } + ).exception( + function(ex) + { + p1.fail(ex); + } + ); + + return p1; + } + ).then( + function(){ + var p1 = new Promise(); + + var f1 = function() + { + ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(1).ice_ping().then( + function() + { + setTimeout(function(){ f1(); }, 10000); + }, + function(ex) + { + if(ex instanceof Ice.LocalException) + { + p1.succeed(); + } + else + { + p1.fail(ex); + } + } + ).exception( + function(ex) + { + p1.fail(ex); + } + ); + }; + + f1(); + + return p1; + } + ).then( + function() + { + var p1 = new Promise(); + + var f1 = function() + { + ic.stringToProxy("test3").ice_locatorCacheTimeout(1).ice_ping().then( + function() + { + setTimeout(function(){ f1(); }, 10000); + }, + function(ex) + { + if(ex instanceof Ice.LocalException) + { + p1.succeed(); + } + else + { + p1.fail(ex); + } + } + ).exception( + function(ex) + { + p1.fail(ex); + }); + }; + + f1(); + return p1; + } + ).then( + function() + { + return ic.destroy(); + } + ).then( + function() + { + p.succeed(); + } + ).exception( + function(ex) + { + p.fail(ex); + } + ); + return p; + } + ).then( + function() + { + out.writeLine("ok"); + out.write("testing proxy from server after shutdown... "); + return obj.getReplicatedHello(); + } + ).then( + function(o) + { + hello = o; + return obj.shutdown(); + } + ).then( + function() + { + return manager.startServer(); + } + ).then( + function() + { + return hello.sayHello(); + } + ).then( + function() + { + out.writeLine("ok"); + out.write("testing object migration..."); + return Test.HelloPrx.checkedCast(communicator.stringToProxy("hello")); + } + ).then( + function(o) + { + hello = o; + return obj.migrateHello(); + } + ).then( + function() + { + return hello.sayHello(); + } + ).then( + function() + { + return obj.migrateHello(); + } + ).then( + function() + { + return hello.sayHello(); + } + ).then( + function() + { + return obj.migrateHello(); + } + ).then( + function() + { + return hello.sayHello(); + } + ).then( + function() + { + out.writeLine("ok"); + out.write("testing locator encoding resolution... "); + return Test.HelloPrx.checkedCast(communicator.stringToProxy("hello")); + } + ).then( + function(o) + { + return locator.getRequestCount(); + } + ).then( + function(count) + { + var p = new Promise(); + + var prx = communicator.stringToProxy("test@TestAdapter").ice_encodingVersion( + Ice.Encoding_1_1); + return prx.ice_ping().then( + function() + { + return locator.getRequestCount(); + } + ).then( + function(newCount) + { + test(count == newCount); + return communicator.stringToProxy("test@TestAdapter10").ice_encodingVersion( + Ice.Encoding_1_0).ice_ping(); + } + ).then( + function() + { + return locator.getRequestCount(); + } + ).then( + function(newCount) + { + test(++count == newCount); + return communicator.stringToProxy("test -e 1.0@TestAdapter10-2").ice_ping(); + } + ).then( + function() + { + return locator.getRequestCount(); + } + ).then( + function(newCount) + { + test(++count == newCount); + p.succeed(); + } + ).exception( + function(ex) + { + p.fail(ex); + } + ); + + return p; + } + ).then( + function() + { + out.writeLine("ok") + out.write("shutdown server... "); + return obj.shutdown(); + } + ).then( + function() + { + out.writeLine("ok"); + out.write("testing whether server is gone... "); + return obj2.ice_ping(); + } + ).then( + failCB, + function(ex) + { + if(!(ex instanceof Ice.LocalException)) + { + throw ex; + } + return obj3.ice_ping(); + } + ).then( + failCB, + function(ex) + { + if(!(ex instanceof Ice.LocalException)) + { + throw ex; + } + return obj5.ice_ping(); + } + ).then( + failCB, + function(ex) + { + if(!(ex instanceof Ice.LocalException)) + { + throw ex; + } + out.writeLine("ok"); + out.write("shutdown server manager... "); + manager.shutdown(); + } + ).then( + function() + { + out.writeLine("ok"); + } + ).then( + function() + { + p.succeed(); + }, + function(ex) + { + p.fail(ex); + } + ); + return p; + }; + + var run = function(out, id) + { + return Promise.try( + function() + { + id.properties.setProperty("Ice.Default.Locator", "locator:default -p 12010"); + 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/location/Makefile b/js/test/Ice/location/Makefile new file mode 100644 index 00000000000..8f81ea44140 --- /dev/null +++ b/js/test/Ice/location/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/location/Makefile.mak b/js/test/Ice/location/Makefile.mak new file mode 100644 index 00000000000..61a62482429 --- /dev/null +++ b/js/test/Ice/location/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/location/Test.ice b/js/test/Ice/location/Test.ice new file mode 100644 index 00000000000..e260caa0c88 --- /dev/null +++ b/js/test/Ice/location/Test.ice @@ -0,0 +1,55 @@ +// ********************************************************************** +// +// 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/Locator.ice> + +module Test +{ + +interface TestLocatorRegistry extends ::Ice::LocatorRegistry +{ + // + // Allow remote addition of objects to the locator registry. + // + void addObject(Object* obj); +}; + +interface TestLocator extends ::Ice::Locator +{ + // + // Returns the number of request on the locator interface. + // + idempotent int getRequestCount(); +}; + +interface ServerManager +{ + void startServer(); + void shutdown(); +}; + +interface Hello +{ + void sayHello(); +}; + +interface TestIntf +{ + void shutdown(); + + Hello* getHello(); + + Hello* getReplicatedHello(); + + void migrateHello(); +}; + +}; diff --git a/js/test/Ice/location/run.js b/js/test/Ice/location/run.js new file mode 100644 index 00000000000..a875f421701 --- /dev/null +++ b/js/test/Ice/location/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/location/run.py b/js/test/Ice/location/run.py new file mode 100755 index 00000000000..33fc2e8f3ac --- /dev/null +++ b/js/test/Ice/location/run.py @@ -0,0 +1,23 @@ +#!/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 + +TestUtil.clientServerTest() diff --git a/js/test/Ice/objects/.gitignore b/js/test/Ice/objects/.gitignore new file mode 100644 index 00000000000..d158d9308ba --- /dev/null +++ b/js/test/Ice/objects/.gitignore @@ -0,0 +1,2 @@ +Test.js +index.html diff --git a/js/test/Ice/objects/Client.js b/js/test/Ice/objects/Client.js new file mode 100644 index 00000000000..02dbbc3f2eb --- /dev/null +++ b/js/test/Ice/objects/Client.js @@ -0,0 +1,469 @@ +// ********************************************************************** +// +// 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 BI = function() + { + Test.B.call(this); + this._postUnmarshalInvoked = false; + }; + + BI.prototype = new Test.B(); + BI.prototype.constructor = BI; + + BI.prototype.postUnmarshalInvoked = function(current) + { + return this._postUnmarshalInvoked; + }; + + BI.prototype.ice_preMarshal = function() + { + this.preMarshalInvoked = true; + }; + + BI.prototype.ice_postUnmarshal = function() + { + this._postUnmarshalInvoked = true; + }; + + var CI = function() + { + Test.C.call(this); + this._postUnmarshalInvoked = false; + }; + + CI.prototype = new Test.C(); + CI.prototype.constructor = CI; + + CI.prototype.postUnmarshalInvoked = function(current) + { + return this._postUnmarshalInvoked; + }; + + CI.prototype.ice_preMarshal = function() + { + this.preMarshalInvoked = true; + }; + + CI.prototype.ice_postUnmarshal = function() + { + this._postUnmarshalInvoked = true; + }; + + var DI = function() + { + Test.D.call(this); + this._postUnmarshalInvoked = false; + }; + + DI.prototype = new Test.D(); + + DI.prototype.postUnmarshalInvoked = function(current) + { + return this._postUnmarshalInvoked; + }; + + DI.prototype.ice_preMarshal = function() + { + this.preMarshalInvoked = true; + }; + + DI.prototype.ice_postUnmarshal = function() + { + this._postUnmarshalInvoked = true; + }; + + var EI = function() + { + Test.E.call(this, 1, "hello"); + }; + + EI.prototype = new Test.E(); + + EI.prototype.constructor = EI; + + EI.prototype.checkValues = function(current) + { + return this.i == 1 && this.s == "hello"; + }; + + var FI = function(e) + { + if(e !== undefined) + { + Test.F.call(this, e, e); + } + }; + + FI.prototype = new Test.F(); + + FI.prototype.checkValues = function(current) + { + return this.e1 != null && this.e1 === this.e2; + }; + + var HI = function() + { + Test.H.call(this); + }; + + HI.prototype = new Test.H(); + HI.prototype.constructor = HI; + + var II = function() + { + Test.I.call(this); + }; + II.prototype = new Test.I(); + II.prototype.constructor = II; + + var JI = function() + { + Test.J.call(this); + }; + JI.prototype = new Test.J(); + JI.prototype.constructor = JI; + + var MyObjectFactory = function() + { + Ice.ObjectFactory.call(this); + }; + + MyObjectFactory.prototype = new Ice.ObjectFactory(); + + MyObjectFactory.prototype.constructor = MyObjectFactory; + + MyObjectFactory.prototype.create = function(type) + { + switch(type) + { + case "::Test::B": + return new BI(); + case "::Test::C": + return new CI(); + case "::Test::D": + return new DI(); + case "::Test::E": + return new EI(); + case "::Test::F": + return new FI(); + case "::Test::I": + return new II(); + case "::Test::J": + return new JI(); + case "::Test::H": + return new HI(); + default: + break; + } + return null; + }; + + MyObjectFactory.prototype.destroy = function() + { + }; + + var allTests = function(out, communicator) + { + var factory, ref, base, initial, b1, b2, c, d, i, j, h; + + var p = new Ice.Promise(); + var test = function(b) + { + if(!b) + { + try + { + throw new Error("test failed"); + } + catch(err) + { + p.fail(err); + throw err; + } + } + }; + + Promise.try( + function() + { + var factory = new MyObjectFactory(); + communicator.addObjectFactory(factory, "::Test::B"); + communicator.addObjectFactory(factory, "::Test::C"); + communicator.addObjectFactory(factory, "::Test::D"); + communicator.addObjectFactory(factory, "::Test::E"); + communicator.addObjectFactory(factory, "::Test::F"); + communicator.addObjectFactory(factory, "::Test::I"); + communicator.addObjectFactory(factory, "::Test::J"); + communicator.addObjectFactory(factory, "::Test::H"); + + out.write("testing stringToProxy... "); + ref = "initial:default -p 12010"; + base = communicator.stringToProxy(ref); + test(base !== null); + out.writeLine("ok"); + + out.write("testing checked cast... "); + return Test.InitialPrx.checkedCast(base); + } + ).then( + function(obj) + { + initial = obj; + test(initial !== null); + test(initial.equals(base)); + out.writeLine("ok"); + } + ).then( + function() + { + out.write("getting B1... "); + return initial.getB1(); + } + ).then( + function(obj) + { + b1 = obj; + test(b1 !== null); + out.writeLine("ok"); + out.write("getting B2... "); + return initial.getB2(); + } + ).then( + function(obj) + { + b2 = obj; + test(b2 != null); + out.writeLine("ok"); + out.write("getting C... "); + return initial.getC(); + } + ).then( + function(obj) + { + c = obj; + test(c !== null); + out.writeLine("ok"); + out.write("getting D... "); + return initial.getD(); + } + ).then( + function(obj) + { + d = obj; + test(d !== null); + out.writeLine("ok"); + } + ).then( + function() + { + out.write("checking consistency... "); + test(b1 !== b2); + //test(b1 != c); + //test(b1 != d); + //test(b2 != c); + //test(b2 != d); + //test(c != d); + test(b1.theB === b1); + test(b1.theC === null); + test(b1.theA instanceof Test.B); + test(b1.theA.theA === b1.theA); + test(b1.theA.theB === b1); + test(b1.theA.theC instanceof Test.C); + test(b1.theA.theC.theB === b1.theA); + + test(b1.preMarshalInvoked); + test(b1.postUnmarshalInvoked(null)); + test(b1.theA.preMarshalInvoked); + test(b1.theA.postUnmarshalInvoked(null)); + test(b1.theA.theC.preMarshalInvoked); + test(b1.theA.theC.postUnmarshalInvoked(null)); + + // More tests possible for b2 and d, but I think this is already + // sufficient. + test(b2.theA === b2); + test(d.theC === null); + out.writeLine("ok"); + out.write("getting B1, B2, C, and D all at once... "); + + return initial.getAll(); + } + ).then( + function(b1, b2, c, d) + { + test(b1); + test(b2); + test(c); + test(d); + out.writeLine("ok"); + + out.write("checking consistency... "); + test(b1 !== b2); + //test(b1 != c); + //test(b1 != d); + //test(b2 != c); + //test(b2 != d); + //test(c != d); + test(b1.theA === b2); + test(b1.theB === b1); + test(b1.theC === null); + test(b2.theA === b2); + test(b2.theB === b1); + test(b2.theC === c); + test(c.theB === b2); + test(d.theA === b1); + test(d.theB === b2); + test(d.theC === null); + test(d.preMarshalInvoked); + test(d.postUnmarshalInvoked(null)); + test(d.theA.preMarshalInvoked); + test(d.theA.postUnmarshalInvoked(null)); + test(d.theB.preMarshalInvoked); + test(d.theB.postUnmarshalInvoked(null)); + test(d.theB.theC.preMarshalInvoked); + test(d.theB.theC.postUnmarshalInvoked(null)); + out.writeLine("ok"); + + out.write("testing protected members... "); + return initial.getE(); + } + ).then( + function(e) + { + test(e.checkValues()); + return initial.getF(); + } + ).then( + function(f) + { + test(f.checkValues()); + test(f.e2.checkValues()); + out.writeLine("ok"); + out.write("getting I, J and H... "); + return initial.getI(); + } + ).then( + function(obj) + { + i = obj; + test(i); + return initial.getJ(); + } + ).then( + function(obj) + { + j = obj; + test(j); + return initial.getH(); + } + ).then( + function(obj) + { + h = obj; + test(h); + out.write("setting I... "); + return initial.setI(i); + } + ).then( + function() + { + return initial.setI(j); + } + ).then( + function() + { + return initial.setI(h); + } + ).then( + function() + { + out.writeLine("ok"); + out.write("testing sequences... "); + return initial.opBaseSeq([]); + } + ).then( + function(retS, outS) + { + return initial.opBaseSeq([new Test.Base(new Test.S(), "")]); + } + ).then( + function(retS, outS) + { + test(retS.length === 1 && outS.length === 1); + out.writeLine("ok"); + out.write("testing compact ID... "); + + return initial.getCompact(); + } + ).then( + function(compact) + { + test(compact !== null); + out.writeLine("ok"); + out.write("testing UnexpectedObjectException... "); + ref = "uoet:default -p 12010"; + base = communicator.stringToProxy(ref); + test(base !== null); + var uoet = Test.UnexpectedObjectExceptionTestPrx.uncheckedCast(base); + test(uoet !== null); + return uoet.op(); + } + ).then( + function() + { + test(false); + }, + function(ex) + { + test(ex instanceof Ice.UnexpectedObjectException); + test(ex.type == "::Test::AlsoEmpty"); + test(ex.expectedType == "::Test::Empty"); + out.writeLine("ok"); + return initial.shutdown(); + } + ).then( + function() + { + p.succeed(); + }, + function(ex) + { + p.fail(ex); + } + ); + 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/objects/Makefile b/js/test/Ice/objects/Makefile new file mode 100644 index 00000000000..8f81ea44140 --- /dev/null +++ b/js/test/Ice/objects/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/objects/Makefile.mak b/js/test/Ice/objects/Makefile.mak new file mode 100644 index 00000000000..61a62482429 --- /dev/null +++ b/js/test/Ice/objects/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/objects/Test.ice b/js/test/Ice/objects/Test.ice new file mode 100644 index 00000000000..b8cc98ca9ca --- /dev/null +++ b/js/test/Ice/objects/Test.ice @@ -0,0 +1,188 @@ +// ********************************************************************** +// +// 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 +{ + +struct S +{ + string str; +}; + +class Base +{ + S theS; + string str; +}; + +class AbstractBase extends Base +{ + void op(); +}; + +class B; +class C; + +class A +{ + B theB; + C theC; + + bool preMarshalInvoked; + bool postUnmarshalInvoked(); +}; + +class B extends A +{ + A theA; +}; + +class C +{ + B theB; + + bool preMarshalInvoked; + bool postUnmarshalInvoked(); +}; + +class D +{ + A theA; + B theB; + C theC; + + bool preMarshalInvoked; + bool postUnmarshalInvoked(); +}; + +["protected"] class E +{ + int i; + string s; + + bool checkValues(); +}; + +class F +{ + ["protected"] E e1; + E e2; + + bool checkValues(); +}; + +interface I +{ + void doI(); +}; + +interface J extends I +{ + void doJ(); +}; + +class H implements I +{ + void doH(); + void doH2(); +}; + +sequence<Base> BaseSeq; + +class CompactExt; + +class Compact(1) +{ +}; + +const int CompactExtId = 789; + +class CompactExt(CompactExtId) extends Compact +{ +}; + +class Initial +{ + void shutdown(); + B getB1(); + B getB2(); + C getC(); + D getD(); + E getE(); + F getF(); + + void getAll(out B b1, out B b2, out C theC, out D theD); + + I getI(); + I getJ(); + I getH(); + + void setI(I theI); + + BaseSeq opBaseSeq(BaseSeq inSeq, out BaseSeq outSeq); + + Compact getCompact(); +}; + +class Empty +{ +}; + +class AlsoEmpty +{ +}; + +interface UnexpectedObjectExceptionTest +{ + Empty op(); +}; + +// +// Remaining definitions are here to ensure that the generated code compiles. +// + +class COneMember +{ + Empty e; +}; + +class CTwoMembers +{ + Empty e1; + Empty e2; +}; + +exception EOneMember +{ + Empty e; +}; + +exception ETwoMembers +{ + Empty e1; + Empty e2; +}; + +struct SOneMember +{ + Empty e; +}; + +struct STwoMembers +{ + Empty e1; + Empty e2; +}; + +dictionary<int, COneMember> DOneMember; +dictionary<int, CTwoMembers> DTwoMembers; + +}; diff --git a/js/test/Ice/objects/run.js b/js/test/Ice/objects/run.js new file mode 100644 index 00000000000..a875f421701 --- /dev/null +++ b/js/test/Ice/objects/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/objects/run.py b/js/test/Ice/objects/run.py new file mode 100755 index 00000000000..0fa5a4af43b --- /dev/null +++ b/js/test/Ice/objects/run.py @@ -0,0 +1,32 @@ +#!/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") diff --git a/js/test/Ice/operations/.gitignore b/js/test/Ice/operations/.gitignore new file mode 100644 index 00000000000..d158d9308ba --- /dev/null +++ b/js/test/Ice/operations/.gitignore @@ -0,0 +1,2 @@ +Test.js +index.html diff --git a/js/test/Ice/operations/BatchOneways.js b/js/test/Ice/operations/BatchOneways.js new file mode 100644 index 00000000000..016e13d4e94 --- /dev/null +++ b/js/test/Ice/operations/BatchOneways.js @@ -0,0 +1,161 @@ +// ********************************************************************** +// +// 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 Ice = global.Ice; + + var run = function(communicator, prx, Test, bidir) + { + var Promise = Ice.Promise; + var bs1, bs2, bs3, batch, batch2, batch3; + var p = new Promise(); + var test = function(b) + { + if(!b) + { + try + { + throw new Error("test failed"); + } + catch(err) + { + p.fail(err); + throw err; + } + } + }; + + Promise.try( + function() + { + bs1 = Ice.Buffer.createNative(new Array(10 * 1024)); + for(var i = 0; i < bs1.length; ++i) + { + bs1[i] = 0; + } + bs2 = Ice.Buffer.createNative(new Array(99 * 1024)); + for(var i = 0; i < bs2.length; ++i) + { + bs2[i] = 0; + } + bs3 = Ice.Buffer.createNative(new Array(100 * 1024)); + for(var i = 0; i < bs3.length; ++i) + { + bs3[i] = 0; + } + + return prx.opByteSOneway(bs1); + } + ).then( + function() + { + return prx.opByteSOneway(bs2); + } + ).then( + function() + { + return prx.opByteSOneway(bs3); + } + ).then( + function() + { + test(false); + }, + function(ex) + { + test(ex instanceof Ice.MemoryLimitException); + + batch = prx.ice_batchOneway(); + + var all = []; + for(var i = 0; i < 30; ++i) + { + all[i] = batch.opByteSOneway(bs1); + } + + return Promise.all(all).then( + function() + { + return batch.ice_getConnection(); + } + ).then( + function(con) + { + return con.flushBatchRequests(); + } + ).then( + function() + { + return prx; + }); + } + ).then( + function(prx) + { + batch2 = prx.ice_batchOneway(); + + return Promise.all(batch.ice_ping(), batch2.ice_ping()); + } + ).then( + function() + { + return batch.ice_flushBatchRequests(); + } + ).then( + function() + { + return batch.ice_getConnection(); + } + ).then( + function(con) + { + return con.close(false); + } + ).then( + function() + { + return Promise.all(batch.ice_ping(), batch2.ice_ping()); + } + ).then( + function() + { + var identity = communicator.stringToIdentity("invalid"); + batch3 = batch.ice_identity(identity); + return batch3.ice_ping(); + } + ).then( + function() + { + return batch3.ice_flushBatchRequests(); + } + ).then( + function() + { + // Make sure that a bogus batch request doesn't cause troubles to other ones. + return Promise.all(batch3.ice_ping(), batch.ice_ping()); + } + ).then( + function() + { + return batch.ice_flushBatchRequests(); + } + ).then( + function() + { + p.succeed(); + }, + function(ex) + { + p.fail(ex); + }); + return p; + }; + + global.BatchOneways = { run: run }; +}(typeof (global) === "undefined" ? window : global)); diff --git a/js/test/Ice/operations/Client.js b/js/test/Ice/operations/Client.js new file mode 100644 index 00000000000..77093f5f18c --- /dev/null +++ b/js/test/Ice/operations/Client.js @@ -0,0 +1,107 @@ +// ********************************************************************** +// +// 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"); + require("Twoways"); + require("Oneways"); + require("BatchOneways"); + + var Ice = global.Ice; + var Promise = Ice.Promise; + var Twoways = global.Twoways; + var Oneways = global.Oneways; + var BatchOneways = global.BatchOneways; + + var allTests = function(out, communicator, Test, bidir) + { + var ref, base, cl, derived; + + return Promise.try( + function() + { + out.write("testing twoway operations... "); + ref = "test:default -p 12010"; + base = communicator.stringToProxy(ref); + return Test.MyClassPrx.checkedCast(base); + } + ).then( + function(prx) + { + cl = prx; + return Test.MyDerivedClassPrx.checkedCast(cl); + } + ).then( + function(prx) + { + derived = prx; + return Twoways.run(communicator, cl, Test, bidir); + } + ).then( + function() + { + return Twoways.run(communicator, derived, Test, bidir); + } + ).then( + function() + { + out.writeLine("ok"); + out.write("testing oneway operations... "); + return Oneways.run(communicator, cl, Test, bidir); + } + ).then( + function() + { + out.writeLine("ok"); + out.write("testing batch oneway operations... "); + return BatchOneways.run(communicator, cl, Test, bidir); + } + ).then( + function() + { + out.writeLine("ok"); + return cl; + }); + }; + + var run = function(out, id) + { + return Promise.try( + function() + { + // + // We must set MessageSizeMax to an explicit value, + // because we run tests to check whether + // Ice.MemoryLimitException is raised as expected. + // + id.properties.setProperty("Ice.MessageSizeMax", "100"); + var c = Ice.initialize(id); + return allTests(out, c, global.Test, false).then( + function(cl) + { + return cl.shutdown(); + } + ).finally( + function() + { + if(c) + { + return c.destroy(); + } + }); + }); + }; + global.__test__ = run + global.__clientAllTests__ = allTests; + global.__runServer__ = true; + +}(typeof (global) === "undefined" ? window : global)); diff --git a/js/test/Ice/operations/Makefile b/js/test/Ice/operations/Makefile new file mode 100644 index 00000000000..8f81ea44140 --- /dev/null +++ b/js/test/Ice/operations/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/operations/Makefile.mak b/js/test/Ice/operations/Makefile.mak new file mode 100644 index 00000000000..61a62482429 --- /dev/null +++ b/js/test/Ice/operations/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/operations/Oneways.js b/js/test/Ice/operations/Oneways.js new file mode 100644 index 00000000000..6dc01f2d987 --- /dev/null +++ b/js/test/Ice/operations/Oneways.js @@ -0,0 +1,107 @@ +// ********************************************************************** +// +// 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 Ice = global.Ice; + + var run = function(communicator, prx, Test, bidir) + { + var p = new Ice.Promise(); + var test = function(b) + { + if(!b) + { + try + { + throw new Error("test failed"); + } + catch(err) + { + p.fail(err); + throw err; + } + } + }; + + Ice.Promise.try( + function() + { + prx = prx.ice_oneway(); + return prx.ice_ping(); + } + ).then( + function() + { + try + { + prx.ice_isA(Test.MyClass.ice_staticId()); + test(false); + } + catch(ex) + { + // Expected: twoway proxy required + } + try + { + prx.ice_id(); + test(false); + } + catch(ex) + { + // Expected: twoway proxy required + } + try + { + prx.ice_ids(); + test(false); + } + catch(ex) + { + // Expected: twoway proxy required + } + + return prx.opVoid(); + } + ).then( + function() + { + return prx.opIdempotent(); + } + ).then( + function() + { + return prx.opNonmutating(); + } + ).then( + function() + { + try + { + prx.opByte(0xff, 0x0f); + test(false); + } + catch(ex) + { + // Expected: twoway proxy required + } + } + ).then( + function() + { + p.succeed(); + }, + function(ex) + { + p.fail(ex); + }); + return p; + }; + + global.Oneways = { run: run }; +}(typeof (global) === "undefined" ? window : global)); diff --git a/js/test/Ice/operations/Test.ice b/js/test/Ice/operations/Test.ice new file mode 100644 index 00000000000..57afcf3b3d6 --- /dev/null +++ b/js/test/Ice/operations/Test.ice @@ -0,0 +1,179 @@ +// ********************************************************************** +// +// 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/Current.ice> + +module Test +{ + +enum MyEnum +{ + enum1, + enum2, + enum3 +}; + +class MyClass; + +struct AnotherStruct +{ + string s; +}; + +struct Structure +{ + MyClass* p; + MyEnum e; + AnotherStruct s; +}; + +sequence<byte> ByteS; +sequence<bool> BoolS; +sequence<short> ShortS; +sequence<int> IntS; +sequence<long> LongS; +sequence<float> FloatS; +sequence<double> DoubleS; +sequence<string> StringS; +sequence<MyEnum> MyEnumS; +sequence<MyClass*> MyClassS; + +sequence<ByteS> ByteSS; +sequence<BoolS> BoolSS; +sequence<ShortS> ShortSS; +sequence<IntS> IntSS; +sequence<LongS> LongSS; +sequence<FloatS> FloatSS; +sequence<DoubleS> DoubleSS; +sequence<StringS> StringSS; +sequence<MyEnumS> MyEnumSS; +sequence<MyClassS> MyClassSS; + +sequence<StringSS> StringSSS; + +struct MyStruct +{ + int i; + int j; +}; + +dictionary<byte, bool> ByteBoolD; +dictionary<short, int> ShortIntD; +dictionary<long, float> LongFloatD; +dictionary<string, string> StringStringD; +dictionary<string, MyEnum> StringMyEnumD; +dictionary<MyEnum, string> MyEnumStringD; +dictionary<MyStruct, MyEnum> MyStructMyEnumD; + +["ami"] class MyClass +{ + void shutdown(); + + void delay(int ms); + + void opVoid(); + + byte opByte(byte p1, byte p2, + out byte p3); + + bool opBool(bool p1, bool p2, + out bool p3); + + long opShortIntLong(short p1, int p2, long p3, + out short p4, out int p5, out long p6); + + double opFloatDouble(float p1, double p2, + out float p3, out double p4); + + string opString(string p1, string p2, + out string p3); + + MyEnum opMyEnum(MyEnum p1, out MyEnum p2); + + MyClass* opMyClass(MyClass* p1, out MyClass* p2, out MyClass* p3); + + Structure opStruct(Structure p1, Structure p2, + out Structure p3); + + ByteS opByteS(ByteS p1, ByteS p2, + out ByteS p3); + + BoolS opBoolS(BoolS p1, BoolS p2, + out BoolS p3); + + LongS opShortIntLongS(Test::ShortS p1, IntS p2, LongS p3, + out ::Test::ShortS p4, out IntS p5, out LongS p6); + + DoubleS opFloatDoubleS(FloatS p1, DoubleS p2, + out FloatS p3, out DoubleS p4); + + StringS opStringS(StringS p1, StringS p2, + out StringS p3); + + ByteSS opByteSS(ByteSS p1, ByteSS p2, + out ByteSS p3); + + BoolSS opBoolSS(BoolSS p1, BoolSS p2, + out BoolSS p3); + + LongSS opShortIntLongSS(ShortSS p1, IntSS p2, LongSS p3, + out ShortSS p4, out IntSS p5, out LongSS p6); + + + DoubleSS opFloatDoubleSS(FloatSS p1, DoubleSS p2, + out FloatSS p3, out DoubleSS p4); + + StringSS opStringSS(StringSS p1, StringSS p2, + out StringSS p3); + + StringSSS opStringSSS(StringSSS p1, StringSSS p2, + out StringSSS p3); + + ByteBoolD opByteBoolD(ByteBoolD p1, ByteBoolD p2, + out ByteBoolD p3); + + ShortIntD opShortIntD(ShortIntD p1, ShortIntD p2, + out ShortIntD p3); + + LongFloatD opLongFloatD(LongFloatD p1, LongFloatD p2, + out LongFloatD p3); + + StringStringD opStringStringD(StringStringD p1, StringStringD p2, + out StringStringD p3); + + StringMyEnumD opStringMyEnumD(StringMyEnumD p1, StringMyEnumD p2, + out StringMyEnumD p3); + + MyEnumStringD opMyEnumStringD(MyEnumStringD p1, MyEnumStringD p2, + out MyEnumStringD p3); + + MyStructMyEnumD opMyStructMyEnumD(MyStructMyEnumD p1, MyStructMyEnumD p2, + out MyStructMyEnumD p3); + + IntS opIntS(IntS s); + + void opByteSOneway(ByteS s); + + Ice::Context opContext(); + + void opDoubleMarshaling(double p1, DoubleS p2); + + idempotent void opIdempotent(); + + ["nonmutating"] idempotent void opNonmutating(); +}; + +["ami"] class MyDerivedClass extends MyClass +{ + void opDerived(); +}; + +}; diff --git a/js/test/Ice/operations/Twoways.js b/js/test/Ice/operations/Twoways.js new file mode 100644 index 00000000000..39448b7242d --- /dev/null +++ b/js/test/Ice/operations/Twoways.js @@ -0,0 +1,760 @@ +// ********************************************************************** +// +// 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 Ice = global.Ice; + + var run = function(communicator, prx, Test, bidir) + { + 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 si1, si2, ctx, combined; + Ice.Promise.try( + function() + { + ctx = new Ice.Context(); + ctx.set("one", "ONE"); + ctx.set("two", "TWO"); + ctx.set("three", "THREE"); + + return prx.ice_ping(); + } + ).then( + function() + { + return prx.ice_isA(Test.MyClass.ice_staticId()); + } + ).then( + function(b) + { + test(b); + return prx.ice_id(); + } + ).then( + function(id) + { + test(id === Test.MyDerivedClass.ice_staticId()); + return prx.ice_ids(); + } + ).then( + function(ids) + { + test(ids.length === 3); + return prx.opVoid(); + } + ).then( + function() + { + return prx.opByte(0xff, 0x0f); + } + ).then( + function(retval, p3) + { + test(p3 === 0xf0); + test(retval === 0xff); + return prx.opBool(true, false); + } + ).then( + function(retval, p3) + { + test(p3); + test(!retval); + var lo = new Ice.Long(0, 12); + return prx.opShortIntLong(10, 11, lo); + } + ).then( + function(retval, s, i, l) + { + var lo = new Ice.Long(0, 12); + test(s === 10); + test(i === 11); + test(l.equals(lo)); + test(retval.equals(lo)); + return prx.opFloatDouble(3.14, 1.1E10); + } + ).then( + function(retval, f, d) + { + test((f - 3.14) <= 0.01); + test(d == 1.1E10); + test(retval == 1.1E10); + return prx.opString("hello", "world"); + } + ).then( + function(retval, p3) + { + test(p3 === "world hello"); + test(retval === "hello world"); + return prx.opMyEnum(Test.MyEnum.enum2); + } + ).then( + function(retval, p2) + { + test(p2 === Test.MyEnum.enum2); + test(retval === Test.MyEnum.enum3); + return prx.opMyClass(prx); + } + ).then( + function(retval, p2, p3) + { + test(p2.ice_getIdentity().equals(communicator.stringToIdentity("test"))); + test(p3.ice_getIdentity().equals(communicator.stringToIdentity("noSuchIdentity"))); + test(retval.ice_getIdentity().equals(communicator.stringToIdentity("test"))); + + si1 = new Test.Structure(); + si1.p = prx; + si1.e = Test.MyEnum.enum3; + si1.s = new Test.AnotherStruct(); + si1.s.s = "abc"; + si2 = new Test.Structure(); + si2.p = null; + si2.e = Test.MyEnum.enum2; + si2.s = new Test.AnotherStruct(); + si2.s.s = "def"; + return prx.opStruct(si1, si2); + } + ).then( + function(retval, p3) + { + test(retval.p === null); + test(retval.e === Test.MyEnum.enum2); + test(retval.s.s === "def"); + test(p3.p !== null); + test(p3.e === Test.MyEnum.enum3); + test(p3.s.s === "a new string"); + + var bsi1 = Ice.Buffer.createNative([ 0x01, 0x11, 0x12, 0x22 ]); + var bsi2 = Ice.Buffer.createNative([ 0xf1, 0xf2, 0xf3, 0xf4 ]); + return prx.opByteS(bsi1, bsi2); + } + ).then( + function(retval, p3) + { + test(p3.length === 4); + test(p3[0] === 0x22); + test(p3[1] === 0x12); + test(p3[2] === 0x11); + test(p3[3] === 0x01); + test(retval.length === 8); + test(retval[0] === 0x01); + test(retval[1] === 0x11); + test(retval[2] === 0x12); + test(retval[3] === 0x22); + test(retval[4] === 0xf1); + test(retval[5] === 0xf2); + test(retval[6] === 0xf3); + test(retval[7] === 0xf4); + + var bsi1 = [ true, true, false ]; + var bsi2 = [ false ]; + return prx.opBoolS(bsi1, bsi2); + } + ).then( + function(retval, p3) + { + test(p3.length == 4); + test(p3[0]); + test(p3[1]); + test(!p3[2]); + test(!p3[3]); + test(retval.length == 3); + test(!retval[0]); + test(retval[1]); + test(retval[2]); + + var ssi = [ 1, 2, 3 ]; + var isi = [ 5, 6, 7, 8 ]; + var l1 = new Ice.Long(0, 10); + var l2 = new Ice.Long(0, 30); + var l3 = new Ice.Long(0, 20); + var lsi = [ l1, l2, l3 ]; + return prx.opShortIntLongS(ssi, isi, lsi); + } + ).then( + function(retval, sso, iso, lso) + { + var l1 = new Ice.Long(0, 10); + var l2 = new Ice.Long(0, 30); + var l3 = new Ice.Long(0, 20); + test(sso.length === 3); + test(sso[0] === 1); + test(sso[1] === 2); + test(sso[2] === 3); + test(iso.length === 4); + test(iso[0] === 8); + test(iso[1] === 7); + test(iso[2] === 6); + test(iso[3] === 5); + test(lso.length === 6); + test(lso[0].equals(l1)); + test(lso[1].equals(l2)); + test(lso[2].equals(l3)); + test(lso[3].equals(l1)); + test(lso[4].equals(l2)); + test(lso[5].equals(l3)); + test(retval.length === 3); + test(retval[0].equals(l1)); + test(retval[1].equals(l2)); + test(retval[2].equals(l3)); + + var fsi = [ 3.14, 1.11 ]; + var dsi = [ 1.1E10, 1.2E10, 1.3E10 ]; + return prx.opFloatDoubleS(fsi, dsi); + } + ).then( + function(retval, fso, dso) + { + test(fso.length === 2); + test((fso[0] - 3.14) <= 0.01); + test((fso[1] - 1.11) <= 0.01); + test(dso.length === 3); + test(dso[0] === 1.3E10); + test(dso[1] === 1.2E10); + test(dso[2] === 1.1E10); + test(retval.length === 5); + test(retval[0] === 1.1E10); + test(retval[1] === 1.2E10); + test(retval[2] === 1.3E10); + test((retval[3] - 3.14) <= 0.01); + test((retval[4] - 1.11) <= 0.01); + var ssi1 = [ "abc", "de", "fghi" ]; + var ssi2 = [ "xyz" ]; + return prx.opStringS(ssi1, ssi2); + } + ).then( + function(retval, sso) + { + test(sso.length === 4); + test(sso[0] === "abc"); + test(sso[1] === "de"); + test(sso[2] === "fghi"); + test(sso[3] === "xyz"); + test(retval.length === 3); + test(retval[0] === "fghi"); + test(retval[1] === "de"); + test(retval[2] === "abc"); + + var bsi1 = + [ + Ice.Buffer.createNative([ 0x01, 0x11, 0x12 ]), + Ice.Buffer.createNative([ 0xff ]) + ]; + var bsi2 = + [ + Ice.Buffer.createNative([ 0x0e ]), + Ice.Buffer.createNative([ 0xf2, 0xf1 ]) + ]; + return prx.opByteSS(bsi1, bsi2); + } + ).then( + function(retval, bso) + { + test(bso.length === 2); + test(bso[0].length === 1); + test(bso[0][0] === 0xff); + test(bso[1].length === 3); + test(bso[1][0] === 0x01); + test(bso[1][1] === 0x11); + test(bso[1][2] === 0x12); + test(retval.length === 4); + test(retval[0].length === 3); + test(retval[0][0] === 0x01); + test(retval[0][1] === 0x11); + test(retval[0][2] === 0x12); + test(retval[1].length === 1); + test(retval[1][0] === 0xff); + test(retval[2].length === 1); + test(retval[2][0] === 0x0e); + test(retval[3].length === 2); + test(retval[3][0] === 0xf2); + test(retval[3][1] === 0xf1); + + var fsi = + [ + [ 3.14 ], + [ 1.11 ], + [ ], + ]; + var dsi = + [ + [ 1.1E10, 1.2E10, 1.3E10 ] + ]; + return prx.opFloatDoubleSS(fsi, dsi); + } + ).then( + function(retval, fso, dso) + { + test(fso.length === 3); + test(fso[0].length === 1); + test((fso[0][0] - 3.14) <= 0.01); + test(fso[1].length === 1); + test((fso[1][0] - 1.11) <= 0.01); + test(fso[2].length === 0); + test(dso.length === 1); + test(dso[0].length === 3); + test(dso[0][0] === 1.1E10); + test(dso[0][1] === 1.2E10); + test(dso[0][2] === 1.3E10); + test(retval.length === 2); + test(retval[0].length === 3); + test(retval[0][0] === 1.1E10); + test(retval[0][1] === 1.2E10); + test(retval[0][2] === 1.3E10); + test(retval[1].length === 3); + test(retval[1][0] === 1.1E10); + test(retval[1][1] === 1.2E10); + test(retval[1][2] === 1.3E10); + + var ssi1 = + [ + [ "abc" ], + [ "de", "fghi" ] + ]; + var ssi2 = + [ + [ ], + [ ], + [ "xyz" ] + ]; + return prx.opStringSS(ssi1, ssi2); + } + ).then( + function(retval, sso) + { + test(sso.length === 5); + test(sso[0].length === 1); + test(sso[0][0] === "abc"); + test(sso[1].length === 2); + test(sso[1][0] === "de"); + test(sso[1][1] === "fghi"); + test(sso[2].length === 0); + test(sso[3].length === 0); + test(sso[4].length === 1); + test(sso[4][0] === "xyz"); + test(retval.length === 3); + test(retval[0].length === 1); + test(retval[0][0] === "xyz"); + test(retval[1].length === 0); + test(retval[2].length === 0); + + var sssi1 = + [ + [ + ["abc", "de"], + ["xyz"] + ], + [ + ["hello"] + ] + ]; + + var sssi2 = + [ + [ + ["", ""], + ["abcd"] + ], + [ + [""] + ], + [] + ]; + return prx.opStringSSS(sssi1, sssi2); + } + ).then( + function(retval, ssso) + { + test(ssso.length === 5); + test(ssso[0].length === 2); + test(ssso[0][0].length === 2); + test(ssso[0][1].length === 1); + test(ssso[1].length === 1); + test(ssso[1][0].length === 1); + test(ssso[2].length === 2); + test(ssso[2][0].length === 2); + test(ssso[2][1].length === 1); + test(ssso[3].length === 1); + test(ssso[3][0].length === 1); + test(ssso[4].length === 0); + test(ssso[0][0][0] === "abc"); + test(ssso[0][0][1] === "de"); + test(ssso[0][1][0] === "xyz"); + test(ssso[1][0][0] === "hello"); + test(ssso[2][0][0] === ""); + test(ssso[2][0][1] === ""); + test(ssso[2][1][0] === "abcd"); + test(ssso[3][0][0] === ""); + + test(retval.length === 3); + test(retval[0].length === 0); + test(retval[1].length === 1); + test(retval[1][0].length === 1); + test(retval[2].length === 2); + test(retval[2][0].length === 2); + test(retval[2][1].length === 1); + test(retval[1][0][0] === ""); + test(retval[2][0][0] === ""); + test(retval[2][0][1] === ""); + test(retval[2][1][0] === "abcd"); + + var di1 = new Test.ByteBoolD(); + di1.set(10, true); + di1.set(100, false); + var di2 = new Test.ByteBoolD(); + di2.set(10, true); + di2.set(11, false); + di2.set(101, true); + + return prx.opByteBoolD(di1, di2); + } + ).then( + function(retval, p3) + { + var tmp = new Test.ByteBoolD(); + tmp.set(10, true); + tmp.set(100, false); + test(p3.equals(tmp)); + test(retval.size === 4); + test(retval.get(10) == true); + test(retval.get(11) == false); + test(retval.get(100) == false); + test(retval.get(101) == true); + + var di1 = new Test.ShortIntD(); + di1.set(110, -1); + di1.set(1100, 123123); + var di2 = new Test.ShortIntD(); + di2.set(110, -1); + di2.set(111, -100); + di2.set(1101, 0); + + return prx.opShortIntD(di1, di2); + } + ).then( + function(retval, p3) + { + var tmp = new Test.ShortIntD(); + tmp.set(110, -1); + tmp.set(1100, 123123); + test(p3.equals(tmp)); + test(retval.size === 4); + test(retval.get(110) === -1); + test(retval.get(111) === -100); + test(retval.get(1100) === 123123); + test(retval.get(1101) === 0); + + var di1 = new Test.LongFloatD(); + di1.set(new Ice.Long(0, 999999110), -1.1); + di1.set(new Ice.Long(0, 999999111), 123123.2); + var di2 = new Test.LongFloatD(); + di2.set(new Ice.Long(0, 999999110), -1.1); + di2.set(new Ice.Long(0, 999999120), -100.4); + di2.set(new Ice.Long(0, 999999130), 0.5); + + return prx.opLongFloatD(di1, di2); + } + ).then( + function(retval, p3) + { + var tmp = new Test.LongFloatD(); + tmp.set(new Ice.Long(0, 999999110), -1.1); + tmp.set(new Ice.Long(0, 999999111), 123123.2); + p3.valueComparator = function(v1, v2) { return (Math.abs(v1) - Math.abs(v2)) <= 0.01; }; + test(p3.equals(tmp)); + test(retval.size === 4); + test(Math.abs(retval.get(new Ice.Long(0, 999999110))) - Math.abs(-1.1) <= 0.01); + test(Math.abs(retval.get(new Ice.Long(0, 999999120))) - Math.abs(-100.4) <= 0.01); + test(retval.get(new Ice.Long(0, 999999111)) - 123123.2 <= 0.01); + test(retval.get(new Ice.Long(0, 999999130)) - 0.5 <= 0.01); + + var di1 = new Test.StringStringD(); + di1.set("foo", "abc -1.1"); + di1.set("bar", "abc 123123.2"); + var di2 = new Test.StringStringD(); + di2.set("foo", "abc -1.1"); + di2.set("FOO", "abc -100.4"); + di2.set("BAR", "abc 0.5"); + + return prx.opStringStringD(di1, di2); + } + ).then( + function(retval, p3) + { + var tmp = new Test.StringStringD(); + tmp.set("foo", "abc -1.1"); + tmp.set("bar", "abc 123123.2"); + test(p3.equals(tmp)); + test(retval.size == 4); + test(retval.get("foo") === "abc -1.1"); + test(retval.get("FOO") === "abc -100.4"); + test(retval.get("bar") === "abc 123123.2"); + test(retval.get("BAR") === "abc 0.5"); + + var di1 = new Test.StringMyEnumD(); + di1.set("abc", Test.MyEnum.enum1); + di1.set("", Test.MyEnum.enum2); + var di2 = new Test.StringMyEnumD(); + di2.set("abc", Test.MyEnum.enum1); + di2.set("qwerty", Test.MyEnum.enum3); + di2.set("Hello!!", Test.MyEnum.enum2); + + return prx.opStringMyEnumD(di1, di2); + } + ).then( + function(retval, p3) + { + var tmp = new Test.StringMyEnumD(); + tmp.set("abc", Test.MyEnum.enum1); + tmp.set("", Test.MyEnum.enum2); + test(p3.equals(tmp)); + test(retval.size === 4); + test(retval.get("abc") === Test.MyEnum.enum1); + test(retval.get("qwerty") === Test.MyEnum.enum3); + test(retval.get("") === Test.MyEnum.enum2); + test(retval.get("Hello!!") === Test.MyEnum.enum2); + + var di1 = new Test.MyEnumStringD(); + di1.set(Test.MyEnum.enum1, "abc"); + var di2 = new Test.MyEnumStringD(); + di2.set(Test.MyEnum.enum2, "Hello!!"); + di2.set(Test.MyEnum.enum3, "qwerty"); + + return prx.opMyEnumStringD(di1, di2); + } + ).then( + function(retval, p3) + { + var tmp = new Test.MyEnumStringD(); + tmp.set(Test.MyEnum.enum1, "abc"); + test(p3.equals(tmp)); + test(retval.size === 3); + test(retval.get(Test.MyEnum.enum1) === "abc"); + test(retval.get(Test.MyEnum.enum2) === "Hello!!"); + test(retval.get(Test.MyEnum.enum3) === "qwerty"); + + var s11 = new Test.MyStruct(1, 1); + var s12 = new Test.MyStruct(1, 2); + var di1 = new Test.MyStructMyEnumD(); + di1.set(s11, Test.MyEnum.enum1); + di1.set(s12, Test.MyEnum.enum2); + var s22 = new Test.MyStruct(2, 2); + var s23 = new Test.MyStruct(2, 3); + var di2 = new Test.MyStructMyEnumD(); + di2.set(s11, Test.MyEnum.enum1); + di2.set(s22, Test.MyEnum.enum3); + di2.set(s23, Test.MyEnum.enum2); + + return prx.opMyStructMyEnumD(di1, di2); + } + ).then( + function(retval, p3) + { + var tmp = new Test.MyStructMyEnumD(); + var ts11 = new Test.MyStruct(1, 1); + var ts12 = new Test.MyStruct(1, 2); + tmp.set(ts11, Test.MyEnum.enum1); + tmp.set(ts12, Test.MyEnum.enum2); + test(p3.equals(tmp)); + var ts22 = new Test.MyStruct(2, 2); + var ts23 = new Test.MyStruct(2, 3); + test(retval.size === 4); + test(retval.get(ts11) === Test.MyEnum.enum1); + test(retval.get(ts12) === Test.MyEnum.enum2); + test(retval.get(ts22) === Test.MyEnum.enum3); + test(retval.get(ts23) === Test.MyEnum.enum2); + + var promise2 = new Ice.Promise(); + var next = function(n) + { + var lengths = [ 0, 1, 2, 126, 127, 128, 129, 253, 254, 255, 256, 257, 1000 ]; + if(n < lengths.length) + { + var len = lengths[n]; + var s = []; + for(var i = 0; i < len; ++i) + { + s.push(i); + } + + return prx.opIntS(s).then( + function(retval) + { + test(retval.length === len); + for(var i = 0; i < len; ++i) + { + test(retval[i] === -i); + } + return next(n + 1); + }); + } + }; + + return next(0); + } + ).then( + function() + { + test(prx.ice_getContext().size === 0); + + return prx.opContext(); + } + ).then( + function(c) + { + test(!c.equals(ctx)); + return prx.opContext(ctx); + } + ).then( + function(c) + { + test(c.equals(ctx)); + return Test.MyClassPrx.checkedCast(prx.ice_context(ctx)); + } + ).then( + function(p2) + { + test(p2.ice_getContext().equals(ctx)); + return p2.opContext(); + } + ).then( + function(c, r) + { + test(c.equals(ctx)); + return r.proxy.opContext(ctx); + } + ).then( + function(c, r) + { + test(c.equals(ctx)); + if(!bidir) + { + return Ice.Promise.try( + function() + { + test(c.equals(ctx)); + + // + // Test implicit context propagation + // + + var initData = new Ice.InitializationData(); + initData.properties = communicator.getProperties().clone(); + initData.properties.setProperty("Ice.ImplicitContext", "Shared"); + var ic = Ice.initialize(initData); + var p3 = Test.MyClassPrx.uncheckedCast(ic.stringToProxy("test:default -p 12010")); + ic.getImplicitContext().setContext(ctx); + test(ic.getImplicitContext().getContext().equals(ctx)); + return p3.opContext(); + } + ).then( + function(c, r) + { + r.communicator.getImplicitContext().put("zero", "ZERO"); + return r.proxy.opContext(); + } + ).then( + function(c, r) + { + test(c.equals(r.communicator.getImplicitContext().getContext())); + + ctx = r.communicator.getImplicitContext().getContext(); + + var prxContext = new Ice.Context(); + prxContext.set("one", "UN"); + prxContext.set("four", "QUATRE"); + + combined = new Ice.Context(ctx); + combined.merge(prxContext); + test(combined.get("one") === "UN"); + + var p3 = Test.MyClassPrx.uncheckedCast(r.proxy.ice_context(prxContext)); + + r.communicator.getImplicitContext().setContext(null); + + return p3.opContext(); + } + ).then( + function(c, r) + { + test(c.equals(r.proxy.ice_getContext())); + r.communicator.getImplicitContext().setContext(ctx); + + return r.proxy.opContext(); + } + ).then( + function(c, r) + { + test(c.equals(combined)); + + return r.communicator.destroy(); + }); + } + } + ).then( + function() + { + var d = 1278312346.0 / 13.0; + var ds = []; + for(var i = 0; i < 5; i++) + { + ds[i] = d; + } + + return prx.opDoubleMarshaling(d, ds); + } + ).then( + function() + { + return prx.opIdempotent(); + } + ).then( + function() + { + return prx.opNonmutating(); + } + ).then( + function() + { + return Test.MyDerivedClassPrx.checkedCast(prx); + } + ).then( + function(d) + { + return d.opDerived(); + } + ).then( + function() + { + p.succeed(); + }, + function(ex) + { + p.fail(ex); + } + ); + return p; + }; + + global.Twoways = { run: run }; +}(typeof (global) === "undefined" ? window : global)); diff --git a/js/test/Ice/operations/run.js b/js/test/Ice/operations/run.js new file mode 100644 index 00000000000..a875f421701 --- /dev/null +++ b/js/test/Ice/operations/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/operations/run.py b/js/test/Ice/operations/run.py new file mode 100755 index 00000000000..a1e4927bae6 --- /dev/null +++ b/js/test/Ice/operations/run.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# ********************************************************************** +# +# 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("tests with regular server.") +TestUtil.clientServerTest() +print("tests with AMD server.") +TestUtil.clientServerTest(server="serveramd") diff --git a/js/test/Ice/operationsBidir/.gitignore b/js/test/Ice/operationsBidir/.gitignore new file mode 100644 index 00000000000..4b74460eef7 --- /dev/null +++ b/js/test/Ice/operationsBidir/.gitignore @@ -0,0 +1,3 @@ +Test.js +TestAMD.js +index.html diff --git a/js/test/Ice/operationsBidir/AMDMyDerivedClassI.js b/js/test/Ice/operationsBidir/AMDMyDerivedClassI.js new file mode 100644 index 00000000000..0cb755ccb2a --- /dev/null +++ b/js/test/Ice/operationsBidir/AMDMyDerivedClassI.js @@ -0,0 +1,296 @@ +// ********************************************************************** +// +// 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 Ice = global.Ice; + + var Class = Ice.Class; + + var test = function(b) + { + if(!b) + { + throw new Error("test failed"); + } + }; + + var AMDMyDerivedClassI = Class(TestAMD.MyDerivedClass, { + // + // Override the Object "pseudo" operations to verify the operation mode. + // + + ice_isA: function(id, current) + { + test(current.mode === Ice.OperationMode.Nonmutating); + return Ice.Object.prototype.ice_isA.call(this, id, current); + }, + + ice_ping: function(current) + { + test(current.mode === Ice.OperationMode.Nonmutating); + Ice.Object.prototype.ice_ping.call(this, current); + }, + + ice_ids: function(current) + { + test(current.mode === Ice.OperationMode.Nonmutating); + return Ice.Object.prototype.ice_ids.call(this, current); + }, + + ice_id: function(current) + { + test(current.mode === Ice.OperationMode.Nonmutating); + return Ice.Object.prototype.ice_id.call(this, current); + }, + + shutdown_async: function(cb, current) + { + current.adapter.getCommunicator().shutdown(); + cb.ice_response(); + }, + + delay_async: function(cb, ms, current) + { + setTimeout( + function() + { + cb.ice_response(); + }, ms); + }, + + opVoid_async: function(cb, current) + { + test(current.mode === Ice.OperationMode.Normal); + cb.ice_response(); + }, + + opBool_async: function(cb, p1, p2, current) + { + cb.ice_response(p2, p1); + }, + + opBoolS_async: function(cb, p1, p2, current) + { + var p3 = p1.concat(p2); + cb.ice_response(p1.reverse(), p3); + }, + + opBoolSS_async: function(cb, p1, p2, current) + { + var p3 = p1.concat(p2); + cb.ice_response(p1.reverse(), p3); + }, + + opByte_async: function(cb, p1, p2, current) + { + cb.ice_response(p1, (p1 ^ p2) & 0xff); + }, + + opByteBoolD_async: function(cb, p1, p2, current) + { + var r = p1.clone(); + r.merge(p2); + cb.ice_response(r, p1); + }, + + opByteS_async: function(cb, p1, p2, current) + { + var p3 = Ice.Buffer.createNative(p1.length); + for(var i = 0; i < p1.length; i++) + { + p3[i] = p1[p1.length - (i + 1)]; + } + + var r = Ice.Buffer.createNative(p1.length + p2.length); + var i; + for(i = 0; i < p1.length; ++i) + { + r[i] = p1[i]; + } + for(i = 0; i < p2.length; ++i) + { + r[i + p1.length] = p2[i]; + } + cb.ice_response(r, p3); + }, + + opByteSS_async: function(cb, p1, p2, current) + { + var r = p1.concat(p2); + cb.ice_response(r, p1.reverse()); + }, + + opFloatDouble_async: function(cb, p1, p2, current) + { + cb.ice_response(p2, p1, p2); + }, + + opFloatDoubleS_async: function(cb, p1, p2, current) + { + var r = p2.concat(p1); + var p4 = p2.reverse(); + cb.ice_response(r, p1, p4); + }, + + opFloatDoubleSS_async: function(cb, p1, p2, current) + { + var r = p2.concat(p2); + var p4 = p2.reverse(); + cb.ice_response(r, p1, p4); + }, + + opLongFloatD_async: function(cb, p1, p2, current) + { + var r = p1.clone(); + r.merge(p2); + cb.ice_response(r, p1); + }, + + opMyClass_async: function(cb, p1, current) + { + var p2 = p1; + var p3 = TestAMD.MyClassPrx.uncheckedCast( + current.adapter.createProxy(current.adapter.getCommunicator().stringToIdentity("noSuchIdentity"))); + var r = TestAMD.MyClassPrx.uncheckedCast(current.adapter.createProxy(current.id)); + cb.ice_response(r, p2, p3); + }, + + opMyEnum_async: function(cb, p1, current) + { + cb.ice_response(TestAMD.MyEnum.enum3, p1); + }, + + opShortIntD_async: function(cb, p1, p2, current) + { + var r = p1.clone(); + r.merge(p2); + cb.ice_response(r, p1); + }, + + opShortIntLong_async: function(cb, p1, p2, p3, current) + { + cb.ice_response(p3, p1, p2, p3); + }, + + opShortIntLongS_async: function(cb, p1, p2, p3, current) + { + cb.ice_response(p3, p1, p2.reverse(), p3.concat(p3)); + }, + + opShortIntLongSS_async: function(cb, p1, p2, p3, current) + { + cb.ice_response(p3, p1, p2.reverse(), p3.concat(p3)); + }, + + opString_async: function(cb, p1, p2, current) + { + cb.ice_response(p1 + " " + p2, p2 + " " + p1); + }, + + opStringMyEnumD_async: function(cb, p1, p2, current) + { + var r = p1.clone(); + r.merge(p2); + cb.ice_response(r, p1); + }, + + opMyEnumStringD_async: function(cb, p1, p2, current) + { + var r = p1.clone(); + r.merge(p2); + cb.ice_response(r, p1); + }, + + opMyStructMyEnumD_async: function(cb, p1, p2, current) + { + var r = p1.clone(); + r.merge(p2); + cb.ice_response(r, p1); + }, + + opIntS_async: function(cb, s, current) + { + cb.ice_response(s.map(function(v, i, arr) { return -v; })); + }, + + opByteSOneway_async: function(cb, s, current) + { + cb.ice_response(); + }, + + opContext_async: function(cb, current) + { + cb.ice_response(current.ctx); + }, + + opDoubleMarshaling_async: function(cb, p1, p2, current) + { + var d = 1278312346.0 / 13.0; + test(p1 === d); + for(var i = 0; i < p2.length; ++i) + { + test(p2[i] === d); + } + cb.ice_response(); + }, + + opStringS_async: function(cb, p1, p2, current) + { + var p3 = p1.concat(p2); + var r = p1.reverse(); + cb.ice_response(r, p3); + }, + + opStringSS_async: function(cb, p1, p2, current) + { + var p3 = p1.concat(p2); + var r = p2.reverse(); + cb.ice_response(r, p3); + }, + + opStringSSS_async: function(cb, p1, p2, current) + { + var p3 = p1.concat(p2); + var r = p2.reverse(); + cb.ice_response(r, p3); + }, + + opStringStringD_async: function(cb, p1, p2, current) + { + var r = p1.clone(); + r.merge(p2); + cb.ice_response(r, p1); + }, + + opStruct_async: function(cb, p1, p2, current) + { + p1.s.s = "a new string"; + cb.ice_response(p2, p1); + }, + + opIdempotent_async: function(cb, current) + { + test(current.mode === Ice.OperationMode.Idempotent); + cb.ice_response(); + }, + + opNonmutating_async: function(cb, current) + { + test(current.mode === Ice.OperationMode.Nonmutating); + cb.ice_response(); + }, + + opDerived_async: function(cb, current) + { + cb.ice_response(); + } + }); + + global.AMDMyDerivedClassI = AMDMyDerivedClassI; +}(typeof (global) === "undefined" ? window : global)); diff --git a/js/test/Ice/operationsBidir/Client.js b/js/test/Ice/operationsBidir/Client.js new file mode 100644 index 00000000000..7092e4c60d4 --- /dev/null +++ b/js/test/Ice/operationsBidir/Client.js @@ -0,0 +1,96 @@ +// ********************************************************************** +// +// 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"); + require("TestAMD"); + require("MyDerivedClassI"); + require("AMDMyDerivedClassI"); + require("../operations/Client.js"); + + var Ice = global.Ice; + var Promise = Ice.Promise; + + var allTests = function(out, communicator, amd) + { + return communicator.createObjectAdapter("").then( + function(adapter) + { + if(amd) + { + adapter.add(new AMDMyDerivedClassI(), communicator.stringToIdentity("test")); + } + else + { + adapter.add(new MyDerivedClassI(), communicator.stringToIdentity("test")); + } + var base = communicator.stringToProxy("test:default -p 12010"); + return base.ice_getConnection().then( + function(conn) + { + conn.setAdapter(adapter); + return __clientAllTests__(out, communicator, amd ? global.TestAMD : global.Test, true); + }); + }); + }; + + var run = function(out, id) + { + return Promise.try( + function() + { + // + // We must set MessageSizeMax to an explicit value, + // because we run tests to check whether + // Ice.MemoryLimitException is raised as expected. + // + id.properties.setProperty("Ice.MessageSizeMax", "100"); + var communicator = Ice.initialize(id); + out.writeLine("testing bidir callbacks with synchronous dispatch..."); + return allTests(out, communicator, false).then( + function() + { + return communicator.destroy(); + } + ).then( + function() + { + communicator = Ice.initialize(id); + out.writeLine("testing bidir callbacks with asynchronous dispatch..."); + return allTests(out, communicator, true); + } + ).then( + function() + { + return communicator.destroy(); + } + ).then( + function() + { + communicator = Ice.initialize(id); + return Test.EchoPrx.checkedCast(communicator.stringToProxy("__echo:default -p 12010")); + } + ).then( + function(prx) + { + return prx.shutdown(); + } + ).then( + function() + { + return communicator.destroy(); + }); + }); + }; + global.__test__ = run; + global.__runEchoServer__ = true; +}(typeof (global) === "undefined" ? window : global)); diff --git a/js/test/Ice/operationsBidir/Makefile b/js/test/Ice/operationsBidir/Makefile new file mode 100644 index 00000000000..2389e17b290 --- /dev/null +++ b/js/test/Ice/operationsBidir/Makefile @@ -0,0 +1,24 @@ +# ********************************************************************** +# +# 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 \ + TestAMD.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/operationsBidir/Makefile.mak b/js/test/Ice/operationsBidir/Makefile.mak new file mode 100644 index 00000000000..a96f885cf0f --- /dev/null +++ b/js/test/Ice/operationsBidir/Makefile.mak @@ -0,0 +1,21 @@ +# ********************************************************************** +# +# 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 \ + TestAMD.js + +SRCS = Client.js + +!include $(top_srcdir)\config\Make.rules.mak.js + +SLICE2JSFLAGS = $(SLICE2JSFLAGS) -I"$(slicedir)" diff --git a/js/test/Ice/operationsBidir/MyDerivedClassI.js b/js/test/Ice/operationsBidir/MyDerivedClassI.js new file mode 100644 index 00000000000..f9b61da3f1d --- /dev/null +++ b/js/test/Ice/operationsBidir/MyDerivedClassI.js @@ -0,0 +1,290 @@ +// ********************************************************************** +// +// 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 Ice = global.Ice; + var Test = global.Test; + + var Class = Ice.Class; + + var test = function(b) + { + if(!b) + { + throw new Error("test failed"); + } + }; + + var MyDerivedClassI = Class(Test.MyDerivedClass, { + // + // Override the Object "pseudo" operations to verify the operation mode. + // + + ice_isA: function(id, current) + { + test(current.mode === Ice.OperationMode.Nonmutating); + return Ice.Object.prototype.ice_isA.call(this, id, current); + }, + + ice_ping: function(current) + { + test(current.mode === Ice.OperationMode.Nonmutating); + Ice.Object.prototype.ice_ping.call(this, current); + }, + + ice_ids: function(current) + { + test(current.mode === Ice.OperationMode.Nonmutating); + return Ice.Object.prototype.ice_ids.call(this, current); + }, + + ice_id: function(current) + { + test(current.mode === Ice.OperationMode.Nonmutating); + return Ice.Object.prototype.ice_id.call(this, current); + }, + + shutdown: function(current) + { + current.adapter.getCommunicator().shutdown(); + }, + + delay: function(cb, ms, current) + { + setTimeout( + function() + { + cb.ice_response(); + }, ms); + }, + + opVoid: function(current) + { + test(current.mode === Ice.OperationMode.Normal); + }, + + opBool: function(p1, p2, current) + { + return [p2, p1]; + }, + + opBoolS: function(p1, p2, current) + { + var p3 = p1.concat(p2); + return [p1.reverse(), p3]; + }, + + opBoolSS: function(p1, p2, current) + { + var p3 = p1.concat(p2); + return [p1.reverse(), p3]; + }, + + opByte: function(p1, p2, current) + { + return [p1, (p1 ^ p2) & 0xff]; + }, + + opByteBoolD: function(p1, p2, current) + { + var r = p1.clone(); + r.merge(p2); + return [r, p1]; + }, + + opByteS: function(p1, p2, current) + { + var p3 = Ice.Buffer.createNative(p1.length); + for(var i = 0; i < p1.length; i++) + { + p3[i] = p1[p1.length - (i + 1)]; + } + + var r = Ice.Buffer.createNative(p1.length + p2.length); + var i; + for(i = 0; i < p1.length; ++i) + { + r[i] = p1[i]; + } + for(i = 0; i < p2.length; ++i) + { + r[i + p1.length] = p2[i]; + } + return [r, p3]; + }, + + opByteSS: function(p1, p2, current) + { + var r = p1.concat(p2); + return [r, p1.reverse()]; + }, + + opFloatDouble: function(p1, p2, current) + { + return [p2, p1, p2]; + }, + + opFloatDoubleS: function(p1, p2, current) + { + var r = p2.concat(p1); + var p4 = p2.reverse(); + return [r, p1, p4]; + }, + + opFloatDoubleSS: function(p1, p2, current) + { + var r = p2.concat(p2); + var p4 = p2.reverse(); + return [r, p1, p4]; + }, + + opLongFloatD: function(p1, p2, current) + { + var r = p1.clone(); + r.merge(p2); + return [r, p1]; + }, + + opMyClass: function(p1, current) + { + var p2 = p1; + var p3 = Test.MyClassPrx.uncheckedCast( + current.adapter.createProxy(current.adapter.getCommunicator().stringToIdentity("noSuchIdentity"))); + var r = Test.MyClassPrx.uncheckedCast(current.adapter.createProxy(current.id)); + return [r, p2, p3]; + }, + + opMyEnum: function(p1, current) + { + return [Test.MyEnum.enum3, p1]; + }, + + opShortIntD: function(p1, p2, current) + { + var r = p1.clone(); + r.merge(p2); + return [r, p1]; + }, + + opShortIntLong: function(p1, p2, p3, current) + { + return [p3, p1, p2, p3]; + }, + + opShortIntLongS: function(p1, p2, p3, current) + { + return [p3, p1, p2.reverse(), p3.concat(p3)]; + }, + + opShortIntLongSS: function(p1, p2, p3, current) + { + return [p3, p1, p2.reverse(), p3.concat(p3)]; + }, + + opString: function(p1, p2, current) + { + return [p1 + " " + p2, p2 + " " + p1]; + }, + + opStringMyEnumD: function(p1, p2, current) + { + var r = p1.clone(); + r.merge(p2); + return [r, p1]; + }, + + opMyEnumStringD: function(p1, p2, current) + { + var r = p1.clone(); + r.merge(p2); + return [r, p1]; + }, + + opMyStructMyEnumD: function(p1, p2, current) + { + var r = p1.clone(); + r.merge(p2); + return [r, p1]; + }, + + opIntS: function(s, current) + { + return s.map(function(v, i, arr) { return -v; }); + }, + + opByteSOneway: function(s, current) + { + }, + + opContext: function(current) + { + return current.ctx; + }, + + opDoubleMarshaling: function(p1, p2, current) + { + var d = 1278312346.0 / 13.0; + test(p1 === d); + for(var i = 0; i < p2.length; ++i) + { + test(p2[i] === d); + } + }, + + opStringS: function(p1, p2, current) + { + var p3 = p1.concat(p2); + var r = p1.reverse(); + return [r, p3]; + }, + + opStringSS: function(p1, p2, current) + { + var p3 = p1.concat(p2); + var r = p2.reverse(); + return [r, p3]; + }, + + opStringSSS: function(p1, p2, current) + { + var p3 = p1.concat(p2); + var r = p2.reverse(); + return [r, p3]; + }, + + opStringStringD: function(p1, p2, current) + { + var r = p1.clone(); + r.merge(p2); + return [r, p1]; + }, + + opStruct: function(p1, p2, current) + { + p1.s.s = "a new string"; + return [p2, p1]; + }, + + opIdempotent: function(current) + { + test(current.mode === Ice.OperationMode.Idempotent); + }, + + opNonmutating: function(current) + { + test(current.mode === Ice.OperationMode.Nonmutating); + }, + + opDerived: function(current) + { + } + }); + + global.MyDerivedClassI = MyDerivedClassI; +}(typeof (global) === "undefined" ? window : global)); diff --git a/js/test/Ice/operationsBidir/Test.ice b/js/test/Ice/operationsBidir/Test.ice new file mode 100644 index 00000000000..3163de99915 --- /dev/null +++ b/js/test/Ice/operationsBidir/Test.ice @@ -0,0 +1,186 @@ +// ********************************************************************** +// +// 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/Current.ice> + +module Test +{ + +enum MyEnum +{ + enum1, + enum2, + enum3 +}; + +class MyClass; + +struct AnotherStruct +{ + string s; +}; + +struct Structure +{ + MyClass* p; + MyEnum e; + AnotherStruct s; +}; + +sequence<byte> ByteS; +sequence<bool> BoolS; +sequence<short> ShortS; +sequence<int> IntS; +sequence<long> LongS; +sequence<float> FloatS; +sequence<double> DoubleS; +sequence<string> StringS; +sequence<MyEnum> MyEnumS; +sequence<MyClass*> MyClassS; + +sequence<ByteS> ByteSS; +sequence<BoolS> BoolSS; +sequence<ShortS> ShortSS; +sequence<IntS> IntSS; +sequence<LongS> LongSS; +sequence<FloatS> FloatSS; +sequence<DoubleS> DoubleSS; +sequence<StringS> StringSS; +sequence<MyEnumS> MyEnumSS; +sequence<MyClassS> MyClassSS; + +sequence<StringSS> StringSSS; + +struct MyStruct +{ + int i; + int j; +}; + +dictionary<byte, bool> ByteBoolD; +dictionary<short, int> ShortIntD; +dictionary<long, float> LongFloatD; +dictionary<string, string> StringStringD; +dictionary<string, MyEnum> StringMyEnumD; +dictionary<MyEnum, string> MyEnumStringD; +dictionary<MyStruct, MyEnum> MyStructMyEnumD; + +class MyClass +{ + void shutdown(); + + ["amd"] void delay(int ms); + + void opVoid(); + + byte opByte(byte p1, byte p2, + out byte p3); + + bool opBool(bool p1, bool p2, + out bool p3); + + long opShortIntLong(short p1, int p2, long p3, + out short p4, out int p5, out long p6); + + double opFloatDouble(float p1, double p2, + out float p3, out double p4); + + string opString(string p1, string p2, + out string p3); + + MyEnum opMyEnum(MyEnum p1, out MyEnum p2); + + MyClass* opMyClass(MyClass* p1, out MyClass* p2, out MyClass* p3); + + Structure opStruct(Structure p1, Structure p2, + out Structure p3); + + ByteS opByteS(ByteS p1, ByteS p2, + out ByteS p3); + + BoolS opBoolS(BoolS p1, BoolS p2, + out BoolS p3); + + LongS opShortIntLongS(Test::ShortS p1, IntS p2, LongS p3, + out ::Test::ShortS p4, out IntS p5, out LongS p6); + + DoubleS opFloatDoubleS(FloatS p1, DoubleS p2, + out FloatS p3, out DoubleS p4); + + StringS opStringS(StringS p1, StringS p2, + out StringS p3); + + ByteSS opByteSS(ByteSS p1, ByteSS p2, + out ByteSS p3); + + BoolSS opBoolSS(BoolSS p1, BoolSS p2, + out BoolSS p3); + + LongSS opShortIntLongSS(ShortSS p1, IntSS p2, LongSS p3, + out ShortSS p4, out IntSS p5, out LongSS p6); + + + DoubleSS opFloatDoubleSS(FloatSS p1, DoubleSS p2, + out FloatSS p3, out DoubleSS p4); + + StringSS opStringSS(StringSS p1, StringSS p2, + out StringSS p3); + + StringSSS opStringSSS(StringSSS p1, StringSSS p2, + out StringSSS p3); + + ByteBoolD opByteBoolD(ByteBoolD p1, ByteBoolD p2, + out ByteBoolD p3); + + ShortIntD opShortIntD(ShortIntD p1, ShortIntD p2, + out ShortIntD p3); + + LongFloatD opLongFloatD(LongFloatD p1, LongFloatD p2, + out LongFloatD p3); + + StringStringD opStringStringD(StringStringD p1, StringStringD p2, + out StringStringD p3); + + StringMyEnumD opStringMyEnumD(StringMyEnumD p1, StringMyEnumD p2, + out StringMyEnumD p3); + + MyEnumStringD opMyEnumStringD(MyEnumStringD p1, MyEnumStringD p2, + out MyEnumStringD p3); + + MyStructMyEnumD opMyStructMyEnumD(MyStructMyEnumD p1, MyStructMyEnumD p2, + out MyStructMyEnumD p3); + + IntS opIntS(IntS s); + + void opByteSOneway(ByteS s); + + Ice::Context opContext(); + + void opDoubleMarshaling(double p1, DoubleS p2); + + idempotent void opIdempotent(); + + ["nonmutating"] idempotent void opNonmutating(); +}; + +class MyDerivedClass extends MyClass +{ + void opDerived(); +}; + +interface Echo +{ + void startBatch(); + void flushBatch(); + void shutdown(); +}; + +}; diff --git a/js/test/Ice/operationsBidir/TestAMD.ice b/js/test/Ice/operationsBidir/TestAMD.ice new file mode 100644 index 00000000000..11719b8c247 --- /dev/null +++ b/js/test/Ice/operationsBidir/TestAMD.ice @@ -0,0 +1,179 @@ +// ********************************************************************** +// +// 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/Current.ice> + +module TestAMD +{ + +enum MyEnum +{ + enum1, + enum2, + enum3 +}; + +class MyClass; + +struct AnotherStruct +{ + string s; +}; + +struct Structure +{ + MyClass* p; + MyEnum e; + AnotherStruct s; +}; + +sequence<byte> ByteS; +sequence<bool> BoolS; +sequence<short> ShortS; +sequence<int> IntS; +sequence<long> LongS; +sequence<float> FloatS; +sequence<double> DoubleS; +sequence<string> StringS; +sequence<MyEnum> MyEnumS; +sequence<MyClass*> MyClassS; + +sequence<ByteS> ByteSS; +sequence<BoolS> BoolSS; +sequence<ShortS> ShortSS; +sequence<IntS> IntSS; +sequence<LongS> LongSS; +sequence<FloatS> FloatSS; +sequence<DoubleS> DoubleSS; +sequence<StringS> StringSS; +sequence<MyEnumS> MyEnumSS; +sequence<MyClassS> MyClassSS; + +sequence<StringSS> StringSSS; + +struct MyStruct +{ + int i; + int j; +}; + +dictionary<byte, bool> ByteBoolD; +dictionary<short, int> ShortIntD; +dictionary<long, float> LongFloatD; +dictionary<string, string> StringStringD; +dictionary<string, MyEnum> StringMyEnumD; +dictionary<MyEnum, string> MyEnumStringD; +dictionary<MyStruct, MyEnum> MyStructMyEnumD; + +["amd"] class MyClass +{ + void shutdown(); + + void delay(int ms); + + void opVoid(); + + byte opByte(byte p1, byte p2, + out byte p3); + + bool opBool(bool p1, bool p2, + out bool p3); + + long opShortIntLong(short p1, int p2, long p3, + out short p4, out int p5, out long p6); + + double opFloatDouble(float p1, double p2, + out float p3, out double p4); + + string opString(string p1, string p2, + out string p3); + + MyEnum opMyEnum(MyEnum p1, out MyEnum p2); + + MyClass* opMyClass(MyClass* p1, out MyClass* p2, out MyClass* p3); + + Structure opStruct(Structure p1, Structure p2, + out Structure p3); + + ByteS opByteS(ByteS p1, ByteS p2, + out ByteS p3); + + BoolS opBoolS(BoolS p1, BoolS p2, + out BoolS p3); + + LongS opShortIntLongS(ShortS p1, IntS p2, LongS p3, + out ShortS p4, out IntS p5, out LongS p6); + + DoubleS opFloatDoubleS(FloatS p1, DoubleS p2, + out FloatS p3, out DoubleS p4); + + StringS opStringS(StringS p1, StringS p2, + out StringS p3); + + ByteSS opByteSS(ByteSS p1, ByteSS p2, + out ByteSS p3); + + BoolSS opBoolSS(BoolSS p1, BoolSS p2, + out BoolSS p3); + + LongSS opShortIntLongSS(ShortSS p1, IntSS p2, LongSS p3, + out ShortSS p4, out IntSS p5, out LongSS p6); + + + DoubleSS opFloatDoubleSS(FloatSS p1, DoubleSS p2, + out FloatSS p3, out DoubleSS p4); + + StringSS opStringSS(StringSS p1, StringSS p2, + out StringSS p3); + + StringSSS opStringSSS(StringSSS p1, StringSSS p2, + out StringSSS p3); + + ByteBoolD opByteBoolD(ByteBoolD p1, ByteBoolD p2, + out ByteBoolD p3); + + ShortIntD opShortIntD(ShortIntD p1, ShortIntD p2, + out ShortIntD p3); + + LongFloatD opLongFloatD(LongFloatD p1, LongFloatD p2, + out LongFloatD p3); + + StringStringD opStringStringD(StringStringD p1, StringStringD p2, + out StringStringD p3); + + StringMyEnumD opStringMyEnumD(StringMyEnumD p1, StringMyEnumD p2, + out StringMyEnumD p3); + + MyEnumStringD opMyEnumStringD(MyEnumStringD p1, MyEnumStringD p2, + out MyEnumStringD p3); + + MyStructMyEnumD opMyStructMyEnumD(MyStructMyEnumD p1, MyStructMyEnumD p2, + out MyStructMyEnumD p3); + + IntS opIntS(IntS s); + + void opByteSOneway(ByteS s); + + Ice::Context opContext(); + + void opDoubleMarshaling(double p1, DoubleS p2); + + idempotent void opIdempotent(); + + ["nonmutating"] idempotent void opNonmutating(); +}; + +["amd"] class MyDerivedClass extends MyClass +{ + void opDerived(); +}; + +}; diff --git a/js/test/Ice/operationsBidir/run.js b/js/test/Ice/operationsBidir/run.js new file mode 100644 index 00000000000..a875f421701 --- /dev/null +++ b/js/test/Ice/operationsBidir/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/operationsBidir/run.py b/js/test/Ice/operationsBidir/run.py new file mode 100755 index 00000000000..4f40e0bc53c --- /dev/null +++ b/js/test/Ice/operationsBidir/run.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# ********************************************************************** +# +# 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 + +TestUtil.addPathToEnv("NODE_PATH", os.path.join(os.path.dirname(__file__), "..", "operations")) +TestUtil.clientEchoTest() diff --git a/js/test/Ice/optional/.gitignore b/js/test/Ice/optional/.gitignore new file mode 100644 index 00000000000..d158d9308ba --- /dev/null +++ b/js/test/Ice/optional/.gitignore @@ -0,0 +1,2 @@ +Test.js +index.html diff --git a/js/test/Ice/optional/Client.js b/js/test/Ice/optional/Client.js new file mode 100644 index 00000000000..1a7a6c9dade --- /dev/null +++ b/js/test/Ice/optional/Client.js @@ -0,0 +1,982 @@ +// ********************************************************************** +// +// 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 Promise = Ice.Promise; + var ArrayUtil = Ice.ArrayUtil; + + var allTests = function(out, communicator, Test) + { + var failCB = function(){ test(false); }; + + var ref, base, mo1, mo6, mo8, oo1, initial, initial2; + + var p = new Ice.Promise(); + var test = function(b) + { + if(!b) + { + try + { + throw new Error("test failed"); + } + catch(err) + { + p.fail(err); + throw err; + } + } + }; + + Promise.try( + function() + { + out.write("testing stringToProxy... "); + ref = "initial:default -p 12010"; + base = communicator.stringToProxy(ref); + test(base !== null); + out.writeLine("ok"); + + oo1 = new Test.OneOptional(); + oo1.a = 15; + + var initial, initial2; + + out.write("testing checked cast... "); + return Test.InitialPrx.checkedCast(base); + } + ).then( + function(obj) + { + initial = obj; + test(initial !== null); + test(initial.equals(base)); + out.writeLine("ok"); + out.write("testing marshaling... "); + + return initial.pingPong(new Test.OneOptional()); + } + ).then( + function(oo4) + { + test(oo4.a === undefined); + return initial.pingPong(oo1); + } + ).then( + function(oo5) + { + test(oo5.a === oo1.a); + return initial.pingPong(new Test.MultiOptional()); + } + ).then( + function(mo4) + { + test(mo4.a === undefined); + test(mo4.b === undefined); + test(mo4.c === undefined); + test(mo4.d === undefined); + test(mo4.e === undefined); + test(mo4.f === undefined); + test(mo4.g === undefined); + test(mo4.h === undefined); + test(mo4.i === undefined); + test(mo4.j === undefined); + test(mo4.k === undefined); + test(mo4.bs === undefined); + test(mo4.ss === undefined); + test(mo4.iid === undefined); + test(mo4.sid === undefined); + test(mo4.fs === undefined); + test(mo4.vs === undefined); + + test(mo4.shs === undefined); + test(mo4.es === undefined); + test(mo4.fss === undefined); + test(mo4.vss === undefined); + test(mo4.oos === undefined); + test(mo4.oops === undefined); + + test(mo4.ied === undefined); + test(mo4.ifsd === undefined); + test(mo4.ivsd === undefined); + test(mo4.iood === undefined); + test(mo4.ioopd === undefined); + + test(mo4.bos === undefined); + + test(mo4.ser === undefined); + + + mo1 = new Test.MultiOptional(); + mo1.a = 15; + mo1.b = true; + mo1.c = 19; + mo1.d = 78; + mo1.e = new Ice.Long(0, 99); + mo1.f = 5.5; + mo1.g = 1.0; + mo1.h = "test"; + mo1.i = Test.MyEnum.MyEnumMember; + mo1.j = Test.MultiOptionalPrx.uncheckedCast(communicator.stringToProxy("test")); + mo1.k = mo1; + mo1.bs = Ice.Buffer.createNative([5]); + mo1.ss = ["test", "test2"]; + mo1.iid = new Ice.HashMap(); + mo1.iid.set(4, 3); + mo1.sid = new Ice.HashMap(); + mo1.sid.set("test", 10); + mo1.fs = new Test.FixedStruct(); + mo1.fs.m = 78; + mo1.vs = new Test.VarStruct(); + mo1.vs.m = "hello"; + + mo1.shs = [1]; + mo1.es = [Test.MyEnum.MyEnumMember, Test.MyEnum.MyEnumMember]; + mo1.fss = [mo1.fs]; + mo1.vss = [mo1.vs]; + mo1.oos = [oo1]; + mo1.oops = [Test.OneOptionalPrx.uncheckedCast(communicator.stringToProxy("test"))]; + + mo1.ied = new Ice.HashMap(); + mo1.ied.set(4, Test.MyEnum.MyEnumMember); + mo1.ifsd = new Ice.HashMap(); + mo1.ifsd.set(4, mo1.fs); + mo1.ivsd = new Ice.HashMap(); + mo1.ivsd.set(5, mo1.vs); + mo1.iood = new Ice.HashMap(); + mo1.iood.set(5, new Test.OneOptional(15)); + mo1.ioopd = new Ice.HashMap(); + mo1.ioopd.set(5, Test.OneOptionalPrx.uncheckedCast(communicator.stringToProxy("test"))); + + mo1.bos = [false, true, false]; + + return initial.pingPong(mo1); + } + ).then( + function(mo5) + { + test(mo1.a == mo5.a); + test(mo1.b == mo5.b); + test(mo1.c == mo5.c); + test(mo1.d == mo5.d); + test(mo1.e.equals(mo5.e)); + test(mo1.f == mo5.f); + test(mo1.g == mo5.g); + test(mo1.h == mo5.h); + test(mo1.i == mo5.i); + test(mo1.j.equals(mo5.j)); + test(mo5.k == mo5); + test(ArrayUtil.equals(mo5.bs, mo1.bs)); + test(ArrayUtil.equals(mo5.ss, mo1.ss)); + test(mo5.iid.get(4) == 3); + test(mo5.sid.get("test") == 10); + test(mo5.fs.equals(mo1.fs)); + test(mo5.vs.equals(mo1.vs)); + test(ArrayUtil.equals(mo5.shs, mo1.shs)); + test(mo5.es[0] == Test.MyEnum.MyEnumMember && mo5.es[1] == Test.MyEnum.MyEnumMember); + test(mo5.fss[0].equals(new Test.FixedStruct(78))); + test(mo5.vss[0].equals(new Test.VarStruct("hello"))); + test(mo5.oos[0].a == 15); + test(mo5.oops[0].equals(Test.OneOptionalPrx.uncheckedCast(communicator.stringToProxy("test")))); + + test(mo5.ied.get(4) == Test.MyEnum.MyEnumMember); + test(mo5.ifsd.get(4).equals(new Test.FixedStruct(78))); + test(mo5.ivsd.get(5).equals(new Test.VarStruct("hello"))); + test(mo5.iood.get(5).a == 15); + test(mo5.ioopd.get(5).equals(Test.OneOptionalPrx.uncheckedCast(communicator.stringToProxy("test")))); + + test(ArrayUtil.equals(mo5.bos, [false, true, false])); + + // Clear the first half of the optional parameters + mo6 = new Test.MultiOptional(); + mo6.b = mo5.b; + mo6.d = mo5.d; + mo6.f = mo5.f; + mo6.h = mo5.h; + mo6.j = mo5.j; + mo6.bs = mo5.bs; + mo6.iid = mo5.iid; + mo6.fs = mo5.fs; + mo6.shs = mo5.shs; + mo6.fss = mo5.fss; + mo6.oos = mo5.oos; + mo6.ifsd = mo5.ifsd; + mo6.iood = mo5.iood; + mo6.bos = mo5.bos; + + return initial.pingPong(mo6); + } + ).then( + function(mo7) + { + test(mo7.a === undefined); + test(mo7.b == mo1.b); + test(mo7.c === undefined ); + test(mo7.d == mo1.d); + test(mo7.e === undefined); + test(mo7.f == mo1.f); + test(mo7.g === undefined); + test(mo7.h == mo1.h); + test(mo7.i === undefined); + test(mo7.j.equals(mo1.j)); + test(mo7.k === undefined); + test(ArrayUtil.equals(mo7.bs, mo1.bs)); + test(mo7.ss === undefined); + test(mo7.iid.get(4) == 3); + test(mo7.sid === undefined); + test(mo7.fs.equals(mo1.fs)); + test(mo7.vs === undefined); + test(ArrayUtil.equals(mo7.shs, mo1.shs)); + test(mo7.es === undefined); + test(mo7.fss[0].equals(new Test.FixedStruct(78))); + test(mo7.vss === undefined); + test(mo7.oos[0].a == 15); + test(mo7.oops === undefined); + + test(mo7.ied === undefined); + test(mo7.ifsd.get(4).equals(new Test.FixedStruct(78))); + test(mo7.ivsd === undefined); + test(mo7.iood.get(5).a == 15); + test(mo7.ioopd === undefined); + + test(ArrayUtil.equals(mo7.bos, [false, true, false])); + + // Clear the second half of the optional parameters + mo8 = new Test.MultiOptional(); + mo8.a = mo1.a; + mo8.c = mo1.c; + mo8.e = mo1.e; + mo8.g = mo1.g; + mo8.i = mo1.i; + mo8.k = mo8; + mo8.ss = mo1.ss; + mo8.sid = mo1.sid; + mo8.vs = mo1.vs; + + mo8.es = mo1.es; + mo8.vss = mo1.vss; + mo8.oops = mo1.oops; + + mo8.ied = mo1.ied; + mo8.ivsd = mo1.ivsd; + mo8.ioopd = mo1.ioopd; + + return initial.pingPong(mo8); + } + ).then( + function(mo9) + { + test(mo9.a == mo1.a); + test(mo9.b === undefined); + test(mo9.c == mo1.c); + test(mo9.d === undefined); + test(mo9.e.equals(mo1.e)); + test(mo9.f === undefined); + test(mo9.g == mo1.g); + test(mo9.h === undefined); + test(mo9.i == mo1.i); + test(mo9.j === undefined); + test(mo9.k == mo9); + test(mo9.bs === undefined); + test(ArrayUtil.equals(mo9.ss, mo1.ss)); + test(mo9.iid === undefined); + test(mo9.sid.get("test") == 10); + test(mo9.fs === undefined); + test(mo9.vs.equals(mo1.vs)); + + test(mo9.shs === undefined); + test(mo9.es[0] == Test.MyEnum.MyEnumMember && mo9.es[1] == Test.MyEnum.MyEnumMember); + test(mo9.fss === undefined); + test(mo9.vss[0].equals(new Test.VarStruct("hello"))); + test(mo9.oos === undefined); + test(mo9.oops[0].equals(Test.OneOptionalPrx.uncheckedCast(communicator.stringToProxy("test")))); + + test(mo9.ied.get(4) == Test.MyEnum.MyEnumMember); + test(mo9.ifsd === undefined); + test(mo9.ivsd.get(5).equals(new Test.VarStruct("hello"))); + test(mo9.iood === undefined); + test(mo9.ioopd.get(5).equals(Test.OneOptionalPrx.uncheckedCast(communicator.stringToProxy("test")))); + + test(mo9.bos === undefined); + + // + // Use the 1.0 encoding with operations whose only class parameters are optional. + // + initial2 = initial.ice_encodingVersion(Ice.Encoding_1_0); + var oo = new Test.OneOptional(53); + + return initial.sendOptionalClass(true, oo).then( + function() + { + return initial2.sendOptionalClass(true, oo); + } + ).then( + function() + { + return initial.returnOptionalClass(true); + } + ).then( + function(oo1) + { + test(oo1 !== undefined && oo1.a == 53); + return initial2.returnOptionalClass(true); + } + ).then( + function(oo1) + { + test(oo1 === undefined); + } + ); + } + ).then( + function() + { + out.writeLine("ok"); + out.write("testing marshaling of large containers with fixed size elements... "); + var mc = new Test.MultiOptional(); + + mc.bs = Ice.Buffer.createNative(new Array(1000)); + mc.shs = new Array(300); + + var i; + mc.fss = []; + for(i = 0; i < 300; ++i) + { + mc.fss[i] = new Test.FixedStruct(); + } + + mc.ifsd = new Ice.HashMap(); + for(i = 0; i < 300; ++i) + { + mc.ifsd.set(i, new Test.FixedStruct()); + } + return initial.pingPong(mc); + } + ).then( + function(mc) + { + test(mc.bs.length == 1000); + test(mc.shs.length == 300); + test(mc.fss.length == 300); + test(mc.ifsd.size == 300); + + out.writeLine("ok"); + out.write("testing tag marshaling... "); + return initial.pingPong(new Test.B()); + } + ).then( + function(b) + { + test(b.ma === undefined); + test(b.mb === undefined); + test(b.mc === undefined); + + b.ma = 10; + b.mb = 11; + b.mc = 12; + b.md = 13; + + return initial.pingPong(b); + } + ).then( + function(b) + { + test(b.ma == 10); + test(b.mb == 11); + test(b.mc == 12); + test(b.md == 13); + + out.writeLine("ok"); + out.write("testing marshaling of objects with optional objects... "); + + var f = new Test.F(); + f.af = new Test.A(); + f.ae = f.af; + return initial.pingPong(f); + } + ).then( + function(f) + { + test(f.ae === f.af); + + out.writeLine("ok"); + out.write("testing optional with default values... "); + + return initial.pingPong(new Test.WD()); + } + ).then( + function(wd) + { + test(wd.a == 5); + test(wd.s == "test"); + wd.a = undefined; + wd.s = undefined; + return initial.pingPong(wd); + } + ).then( + function(wd) + { + test(wd.a === undefined); + test(wd.s === undefined); + + out.writeLine("ok"); + out.write("testing optional parameters... "); + + return initial.opByte(); // same as initial.opByte(undefined); + } + ).then( + function(p1, p2) + { + test(p1 === undefined); + test(p2 === undefined); + return initial.opByte(56); + } + ).then( + function(p1, p2) + { + test(p1 === 56); + test(p2 === 56); + return initial.opBool(); + } + ).then( + function(p1, p2) + { + test(p1 === undefined); + test(p2 === undefined); + return initial.opBool(true); + } + ).then( + function(p1, p2) + { + test(p1 === true); + test(p2 === true); + return initial.opShort(); + } + ).then( + function(p1, p2) + { + test(p1 === undefined); + test(p2 === undefined); + return initial.opShort(56); + } + ).then( + function(p1, p2) + { + test(p1 === 56); + test(p2 === 56); + return initial.opInt(); + } + ).then( + function(p1, p2) + { + test(p1 === undefined); + test(p2 === undefined); + return initial.opInt(56); + } + ).then( + function(p1, p2) + { + test(p1 === 56); + test(p2 === 56); + return initial.opLong(); + } + ).then( + function(p1, p2) + { + test(p1 === undefined); + test(p2 === undefined); + return initial.opLong(new Ice.Long(0, 56)); + } + ).then( + function(p1, p2) + { + test(p1.equals(new Ice.Long(0, 56))); + test(p2.equals(new Ice.Long(0, 56))); + return initial.opFloat(); + } + ).then( + function(p1, p2) + { + test(p1 === undefined); + test(p2 === undefined); + return initial.opFloat(1.0); + } + ).then( + function(p1, p2) + { + test(p1 === 1.0); + test(p2 === 1.0); + return initial.opDouble(); + } + ).then( + function(p1, p2) + { + test(p1 === undefined); + test(p2 === undefined); + return initial.opDouble(1.0); + } + ).then( + function(p1, p2) + { + test(p1 === 1.0); + test(p2 === 1.0); + return initial.opString(); + } + ).then( + function(p1, p2) + { + test(p1 === undefined); + test(p2 === undefined); + return initial.opString("test"); + } + ).then( + function(p1, p2) + { + test(p1 === "test"); + test(p2 === "test"); + return initial.opMyEnum(); + } + ).then( + function(p1, p2) + { + test(p1 === undefined); + test(p2 === undefined); + return initial.opMyEnum(Test.MyEnum.MyEnumMember); + } + ).then( + function(p1, p2) + { + test(p1 === Test.MyEnum.MyEnumMember); + test(p2 === Test.MyEnum.MyEnumMember); + return initial.opSmallStruct(); + } + ).then( + function(p1, p2) + { + test(p1 === undefined); + test(p2 === undefined); + return initial.opSmallStruct(new Test.SmallStruct(56)); + } + ).then( + function(p1, p2) + { + test(p1.equals(new Test.SmallStruct(56))); + test(p2.equals(new Test.SmallStruct(56))); + return initial.opFixedStruct(); + } + ).then( + function(p1, p2) + { + test(p1 === undefined); + test(p2 === undefined); + return initial.opFixedStruct(new Test.FixedStruct(56)); + } + ).then( + function(p1, p2) + { + test(p1.equals(new Test.FixedStruct(56))); + test(p2.equals(new Test.FixedStruct(56))); + + return initial.opVarStruct(); + } + ).then( + function(p1, p2) + { + test(p1 === undefined); + test(p2 === undefined); + return initial.opVarStruct(new Test.VarStruct("test")); + } + ).then( + function(p1, p2) + { + test(p1.equals(new Test.VarStruct("test"))); + test(p2.equals(new Test.VarStruct("test"))); + return initial.opOneOptional(); + } + ).then( + function(p1, p2) + { + test(p1 === undefined); + test(p2 === undefined); + return initial.opOneOptional(new Test.OneOptional(58)); + } + ).then( + function(p1, p2) + { + test(p1 === p2); + test(p2.a === 58); + return initial.opOneOptionalProxy(); + } + ).then( + function(p1, p2) + { + test(p1 === undefined); + test(p2 === undefined); + return initial.opOneOptionalProxy( + Test.OneOptionalPrx.uncheckedCast(communicator.stringToProxy("test"))); + } + ).then( + function(p1, p2) + { + var p3 = Test.OneOptionalPrx.uncheckedCast(communicator.stringToProxy("test")); + test(p1.equals(p3)); + test(p2.equals(p3)); + return initial.opByteSeq(); + } + ).then( + function(p1, p2) + { + test(p1 === undefined); + test(p2 === undefined); + var data = []; + for(var i = 0; i < 100; ++i){ data[i] = 56; } + return initial.opByteSeq(Ice.Buffer.createNative(data)); + } + ).then( + function(p1, p2) + { + test(p1.length === 100) + test(p2.length === 100); + for(var i = 0; i < 100; ++i) + { + test(p1[i] === 56); + test(p2[i] === 56); + } + return initial.opBoolSeq(); + } + ).then( + function(p1, p2) + { + test(p1 === undefined); + test(p2 === undefined); + var data = []; + for(var i = 0; i < 100; ++i){ data[i] = true; } + return initial.opBoolSeq(data); + } + ).then( + function(p1, p2) + { + test(p1.length === 100) + test(p2.length === 100); + for(var i = 0; i < 100; ++i) + { + test(p1[i] === true); + test(p2[i] === true); + } + return initial.opShortSeq(); + } + ).then( + function(p1, p2) + { + test(p1 === undefined); + test(p2 === undefined); + var data = []; + for(var i = 0; i < 100; ++i){ data[i] = 56; } + return initial.opShortSeq(data); + } + ).then( + function(p1, p2) + { + test(p1.length === 100) + test(p2.length === 100); + for(var i = 0; i < 100; ++i) + { + test(p1[i] === 56); + test(p2[i] === 56); + } + return initial.opIntSeq(); + } + ).then( + function(p1, p2) + { + test(p1 === undefined); + test(p2 === undefined); + var data = []; + for(var i = 0; i < 100; ++i){ data[i] = 56; } + return initial.opIntSeq(data); + } + ).then( + function(p1, p2) + { + test(p1.length === 100) + test(p2.length === 100); + for(var i = 0; i < 100; ++i) + { + test(p1[i] === 56); + test(p2[i] === 56); + } + return initial.opLongSeq(); + } + ).then( + function(p1, p2) + { + test(p1 === undefined); + test(p2 === undefined); + var data = []; + for(var i = 0; i < 100; ++i){ data[i] = new Ice.Long(0, 56); } + return initial.opLongSeq(data); + } + ).then( + function(p1, p2) + { + test(p1.length === 100) + test(p2.length === 100); + for(var i = 0; i < 100; ++i) + { + test(p1[i].equals(new Ice.Long(0, 56))); + test(p2[i].equals(new Ice.Long(0, 56))); + } + return initial.opFloatSeq(); + } + ).then( + function(p1, p2) + { + test(p1 === undefined); + test(p2 === undefined); + var data = []; + for(var i = 0; i < 100; ++i){ data[i] = 1.0; } + return initial.opFloatSeq(data); + } + ).then( + function(p1, p2) + { + test(p1.length === 100) + test(p2.length === 100); + for(var i = 0; i < 100; ++i) + { + test(p1[i] === 1.0); + test(p2[i] === 1.0); + } + return initial.opDoubleSeq(); + } + ).then( + function(p1, p2) + { + test(p1 === undefined); + test(p2 === undefined); + var data = []; + for(var i = 0; i < 100; ++i){ data[i] = 1.0; } + return initial.opDoubleSeq(data); + } + ).then( + function(p1, p2) + { + test(p1.length === 100) + test(p2.length === 100); + for(var i = 0; i < 100; ++i) + { + test(p1[i] === 1.0); + test(p2[i] === 1.0); + } + return initial.opStringSeq(); + } + ).then( + function(p1, p2) + { + test(p1 === undefined); + test(p2 === undefined); + var data = []; + for(var i = 0; i < 100; ++i){ data[i] = "test1"; } + return initial.opStringSeq(data); + } + ).then( + function(p1, p2) + { + test(p1.length === 100) + test(p2.length === 100); + for(var i = 0; i < 100; ++i) + { + test(p1[i] == "test1"); + test(p2[i] == "test1"); + } + return initial.opSmallStructSeq(); + } + ).then( + function(p1, p2) + { + test(p1 === undefined); + test(p2 === undefined); + var data = []; + for(var i = 0; i < 100; ++i){ data[i] = new Test.SmallStruct(); } + return initial.opSmallStructSeq(data); + } + ).then( + function(p1, p2) + { + var s = new Test.SmallStruct(); + test(p1.length === 100) + test(p2.length === 100); + for(var i = 0; i < 100; ++i) + { + test(p1[i].equals(s)); + test(p2[i].equals(s)); + } + return initial.opFixedStructSeq(); + } + ).then( + function(p1, p2) + { + test(p1 === undefined); + test(p2 === undefined); + var data = []; + for(var i = 0; i < 100; ++i){ data[i] = new Test.FixedStruct(); } + return initial.opFixedStructSeq(data); + } + ).then( + function(p1, p2) + { + var s = new Test.FixedStruct(); + test(p1.length === 100) + test(p2.length === 100); + for(var i = 0; i < 100; ++i) + { + test(p1[i].equals(s)); + test(p2[i].equals(s)); + } + return initial.opVarStructSeq(); + } + ).then( + function(p1, p2) + { + test(p1 === undefined); + test(p2 === undefined); + var data = []; + for(var i = 0; i < 100; ++i){ data[i] = new Test.VarStruct(""); } + return initial.opVarStructSeq(data); + } + ).then( + function(p1, p2) + { + var s = new Test.VarStruct(""); + test(p1.length === 100) + test(p2.length === 100); + for(var i = 0; i < 100; ++i) + { + test(p1[i].equals(s)); + test(p2[i].equals(s)); + } + return initial.opIntIntDict(); + } + ).then( + function(p1, p2) + { + test(p1 === undefined); + test(p2 === undefined); + var data = new Ice.HashMap(); + data.set(1, 2); + data.set(2, 3); + return initial.opIntIntDict(data); + } + ).then( + function(p1, p2) + { + test(p1.equals(p2)); + return initial.opStringIntDict(); + } + ).then( + function(p1, p2) + { + test(p1 === undefined); + test(p2 === undefined); + var data = new Ice.HashMap(); + data.set("1", 1); + data.set("2", 2); + + out.writeLine("ok"); + out.write("testing exception optionals... "); + + return initial.opOptionalException(); + } + ).then( + failCB, + function(ex) + { + test(ex instanceof Test.OptionalException); + test(ex.a === undefined); + test(ex.b === undefined); + test(ex.o === undefined); + + return initial.opOptionalException(30, "test", new Test.OneOptional(53)); + } + ).then( + failCB, + function(ex) + { + test(ex instanceof Test.OptionalException); + test(ex.a === 30); + test(ex.b == "test"); + test(ex.o.a == 53); + return initial.opDerivedException(); + } + ).then( + failCB, + function(ex) + { + test(ex instanceof Test.DerivedException); + test(ex.a === undefined); + test(ex.b === undefined); + test(ex.o === undefined); + test(ex.ss === undefined); + test(ex.o2 === undefined); + return initial.opDerivedException(30, "test2", new Test.OneOptional(53)); + } + ).then( + failCB, + function(ex) + { + test(ex instanceof Test.DerivedException); + test(ex.a === 30); + test(ex.b == "test2"); + test(ex.o.a === 53); + test(ex.ss == "test2"); + test(ex.o2.a === 53); + + out.writeLine("ok"); + return initial.shutdown(); + } + ).then( + function() + { + p.succeed(); + }, + function(ex) + { + p.fail(ex); + } + ); + + return p; + }; + + var run = function(out, id) + { + var Test = global.Test; + return Promise.try( + function() + { + var c = Ice.initialize(id); + return allTests(out, c, Test).finally( + function() + { + if(c) + { + return c.destroy(); + } + }); + }); + }; + global.__clientAllTests__ = allTests; + global.__test__ = run; + global.__runServer__ = true; +}(typeof (global) === "undefined" ? window : global)); diff --git a/js/test/Ice/optional/Makefile b/js/test/Ice/optional/Makefile new file mode 100644 index 00000000000..8f81ea44140 --- /dev/null +++ b/js/test/Ice/optional/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/optional/Makefile.mak b/js/test/Ice/optional/Makefile.mak new file mode 100644 index 00000000000..61a62482429 --- /dev/null +++ b/js/test/Ice/optional/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/optional/Test.ice b/js/test/Ice/optional/Test.ice new file mode 100644 index 00000000000..c535064b3a9 --- /dev/null +++ b/js/test/Ice/optional/Test.ice @@ -0,0 +1,294 @@ +// ********************************************************************** +// +// 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 +{ + +class OneOptional +{ + optional(1) int a; +}; + +enum MyEnum +{ + MyEnumMember +}; + +struct SmallStruct +{ + byte m; +}; + +struct FixedStruct +{ + int m; +}; + +struct VarStruct +{ + string m; +}; + +struct ClassVarStruct +{ + int a; +}; + +sequence<byte> ByteSeq; +sequence<bool> BoolSeq; +sequence<short> ShortSeq; +sequence<int> IntSeq; +sequence<long> LongSeq; +sequence<float> FloatSeq; +sequence<double> DoubleSeq; +sequence<string> StringSeq; +sequence<MyEnum> MyEnumSeq; +sequence<SmallStruct> SmallStructSeq; +sequence<SmallStruct> SmallStructList; +sequence<FixedStruct> FixedStructSeq; +sequence<FixedStruct> FixedStructList; +sequence<VarStruct> VarStructSeq; +sequence<OneOptional> OneOptionalSeq; +sequence<OneOptional*> OneOptionalPrxSeq; + +sequence<byte> Serializable; + +dictionary<int, int> IntIntDict; +dictionary<string, int> StringIntDict; +dictionary<int, MyEnum> IntEnumDict; +dictionary<int, FixedStruct> IntFixedStructDict; +dictionary<int, VarStruct> IntVarStructDict; +dictionary<int, OneOptional> IntOneOptionalDict; +dictionary<int, OneOptional*> IntOneOptionalPrxDict; + +class MultiOptional +{ + optional(1) byte a; + optional(2) bool b; + optional(3) short c; + optional(4) int d; + optional(5) long e; + optional(6) float f; + optional(7) double g; + optional(8) string h; + optional(9) MyEnum i; + optional(10) MultiOptional* j; + optional(11) MultiOptional k; + optional(12) ByteSeq bs; + optional(13) StringSeq ss; + optional(14) IntIntDict iid; + optional(15) StringIntDict sid; + optional(16) FixedStruct fs; + optional(17) VarStruct vs; + + optional(18) ShortSeq shs; + optional(19) MyEnumSeq es; + optional(20) FixedStructSeq fss; + optional(21) VarStructSeq vss; + optional(22) OneOptionalSeq oos; + optional(23) OneOptionalPrxSeq oops; + + optional(24) IntEnumDict ied; + optional(25) IntFixedStructDict ifsd; + optional(26) IntVarStructDict ivsd; + optional(27) IntOneOptionalDict iood; + optional(28) IntOneOptionalPrxDict ioopd; + + optional(29) BoolSeq bos; + + optional(30) Serializable ser; +}; + +class A +{ + int requiredA; + optional(1) int ma; + optional(50) int mb; + optional(500) int mc; +}; + +["preserve-slice"] +class B extends A +{ + int requiredB; + optional(10) int md; +}; + +class C extends B +{ + string ss; + optional(890) string ms; +}; + +class WD +{ + optional(1) int a = 5; + optional(2) string s = "test"; +}; + +exception OptionalException +{ + bool req = false; + optional(1) int a = 5; + optional(2) string b; + optional(50) OneOptional o; +}; + +exception DerivedException extends OptionalException +{ + optional(600) string ss = "test"; + optional(601) OneOptional o2; +}; + +exception RequiredException extends OptionalException +{ + string ss = "test"; + OneOptional o2; +}; + +class OptionalWithCustom +{ + optional(1) SmallStructList l; + ["protected"] optional(2) SmallStructList lp; + optional(3) ClassVarStruct s; +}; + +class E +{ + A ae; +}; + +class F extends E +{ + optional(1) A af; +}; + +class Initial +{ + void shutdown(); + + Object pingPong(Object o); + + void opOptionalException(optional(1) int a, optional(2) string b, optional(3) OneOptional o) + throws OptionalException; + + void opDerivedException(optional(1) int a, optional(2) string b, optional(3) OneOptional o) + throws OptionalException; + + void opRequiredException(optional(1) int a, optional(2) string b, optional(3) OneOptional o) + throws OptionalException; + + optional(1) byte opByte(optional(2) byte p1, out optional(3) byte p3); + optional(1) byte opByteReq(optional(2) byte p1, out optional(3) byte p3); + + optional(1) bool opBool(optional(2) bool p1, out optional(3) bool p3); + optional(1) bool opBoolReq(optional(2) bool p1, out optional(3) bool p3); + + optional(1) short opShort(optional(2) short p1, out optional(3) short p3); + optional(1) short opShortReq(optional(2) short p1, out optional(3) short p3); + + optional(1) int opInt(optional(2) int p1, out optional(3) int p3); + optional(1) int opIntReq(optional(2) int p1, out optional(3) int p3); + + optional(3) long opLong(optional(1) long p1, out optional(2) long p3); + optional(3) long opLongReq(optional(1) long p1, out optional(2) long p3); + + optional(1) float opFloat(optional(2) float p1, out optional(3) float p3); + optional(1) float opFloatReq(optional(2) float p1, out optional(3) float p3); + + optional(1) double opDouble(optional(2) double p1, out optional(3) double p3); + optional(1) double opDoubleReq(optional(2) double p1, out optional(3) double p3); + + optional(1) string opString(optional(2) string p1, out optional(3) string p3); + optional(1) string opStringReq(optional(2) string p1, out optional(3) string p3); + + optional(1) MyEnum opMyEnum(optional(2) MyEnum p1, out optional(3) MyEnum p3); + optional(1) MyEnum opMyEnumReq(optional(2) MyEnum p1, out optional(3) MyEnum p3); + + optional(1) SmallStruct opSmallStruct(optional(2) SmallStruct p1, out optional(3) SmallStruct p3); + optional(1) SmallStruct opSmallStructReq(optional(2) SmallStruct p1, out optional(3) SmallStruct p3); + + optional(1) FixedStruct opFixedStruct(optional(2) FixedStruct p1, out optional(3) FixedStruct p3); + optional(1) FixedStruct opFixedStructReq(optional(2) FixedStruct p1, out optional(3) FixedStruct p3); + + optional(1) VarStruct opVarStruct(optional(2) VarStruct p1, out optional(3) VarStruct p3); + optional(1) VarStruct opVarStructReq(optional(2) VarStruct p1, out optional(3) VarStruct p3); + + optional(1) OneOptional opOneOptional(optional(2) OneOptional p1, out optional(3) OneOptional p3); + optional(1) OneOptional opOneOptionalReq(optional(2) OneOptional p1, out optional(3) OneOptional p3); + + optional(1) OneOptional* opOneOptionalProxy(optional(2) OneOptional* p1, out optional(3) OneOptional* p3); + optional(1) OneOptional* opOneOptionalProxyReq(optional(2) OneOptional* p1, out optional(3) OneOptional* p3); + + optional(1) ByteSeq opByteSeq(optional(2) ByteSeq p1, out optional(3) ByteSeq p3); + optional(1) ByteSeq opByteSeqReq(optional(2) ByteSeq p1, out optional(3) ByteSeq p3); + + optional(1) BoolSeq opBoolSeq(optional(2) BoolSeq p1, out optional(3) BoolSeq p3); + optional(1) BoolSeq opBoolSeqReq(optional(2) BoolSeq p1, out optional(3) BoolSeq p3); + + optional(1) ShortSeq opShortSeq(optional(2) ShortSeq p1, out optional(3) ShortSeq p3); + optional(1) ShortSeq opShortSeqReq(optional(2) ShortSeq p1, out optional(3) ShortSeq p3); + + optional(1) IntSeq opIntSeq(optional(2) IntSeq p1, out optional(3) IntSeq p3); + optional(1) IntSeq opIntSeqReq(optional(2) IntSeq p1, out optional(3) IntSeq p3); + + optional(1) LongSeq opLongSeq(optional(2) LongSeq p1, out optional(3) LongSeq p3); + optional(1) LongSeq opLongSeqReq(optional(2) LongSeq p1, out optional(3) LongSeq p3); + + optional(1) FloatSeq opFloatSeq(optional(2) FloatSeq p1, out optional(3) FloatSeq p3); + optional(1) FloatSeq opFloatSeqReq(optional(2) FloatSeq p1, out optional(3) FloatSeq p3); + + optional(1) DoubleSeq opDoubleSeq(optional(2) DoubleSeq p1, out optional(3) DoubleSeq p3); + optional(1) DoubleSeq opDoubleSeqReq(optional(2) DoubleSeq p1, out optional(3) DoubleSeq p3); + + optional(1) StringSeq opStringSeq(optional(2) StringSeq p1, out optional(3) StringSeq p3); + optional(1) StringSeq opStringSeqReq(optional(2) StringSeq p1, out optional(3) StringSeq p3); + + optional(1) SmallStructSeq opSmallStructSeq(optional(2) SmallStructSeq p1, out optional(3) SmallStructSeq p3); + optional(1) SmallStructSeq opSmallStructSeqReq(optional(2) SmallStructSeq p1, out optional(3) SmallStructSeq p3); + + optional(1) SmallStructList opSmallStructList(optional(2) SmallStructList p1, out optional(3) SmallStructList p3); + optional(1) SmallStructList opSmallStructListReq(optional(2) SmallStructList p1, + out optional(3) SmallStructList p3); + + optional(1) FixedStructSeq opFixedStructSeq(optional(2) FixedStructSeq p1, out optional(3) FixedStructSeq p3); + optional(1) FixedStructSeq opFixedStructSeqReq(optional(2) FixedStructSeq p1, out optional(3) FixedStructSeq p3); + + optional(1) FixedStructList opFixedStructList(optional(2) FixedStructList p1, out optional(3) FixedStructList p3); + optional(1) FixedStructList opFixedStructListReq(optional(2) FixedStructList p1, + out optional(3) FixedStructList p3); + + optional(1) VarStructSeq opVarStructSeq(optional(2) VarStructSeq p1, out optional(3) VarStructSeq p3); + optional(1) VarStructSeq opVarStructSeqReq(optional(2) VarStructSeq p1, out optional(3) VarStructSeq p3); + + optional(1) Serializable opSerializable(optional(2) Serializable p1, out optional(3) Serializable p3); + optional(1) Serializable opSerializableReq(optional(2) Serializable p1, out optional(3) Serializable p3); + + optional(1) IntIntDict opIntIntDict(optional(2) IntIntDict p1, out optional(3) IntIntDict p3); + optional(1) IntIntDict opIntIntDictReq(optional(2) IntIntDict p1, out optional(3) IntIntDict p3); + + optional(1) StringIntDict opStringIntDict(optional(2) StringIntDict p1, out optional(3) StringIntDict p3); + optional(1) StringIntDict opStringIntDictReq(optional(2) StringIntDict p1, out optional(3) StringIntDict p3); + + void opClassAndUnknownOptional(A p); + + void sendOptionalClass(bool req, optional(1) OneOptional o); + + void returnOptionalClass(bool req, out optional(1) OneOptional o); + + bool supportsRequiredParams(); + + bool supportsJavaSerializable(); + + bool supportsCsharpSerializable(); +}; + +}; diff --git a/js/test/Ice/optional/run.js b/js/test/Ice/optional/run.js new file mode 100644 index 00000000000..a875f421701 --- /dev/null +++ b/js/test/Ice/optional/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/optional/run.py b/js/test/Ice/optional/run.py new file mode 100755 index 00000000000..45760a926cd --- /dev/null +++ b/js/test/Ice/optional/run.py @@ -0,0 +1,26 @@ +#!/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") diff --git a/js/test/Ice/optionalBidir/.gitignore b/js/test/Ice/optionalBidir/.gitignore new file mode 100644 index 00000000000..4b74460eef7 --- /dev/null +++ b/js/test/Ice/optionalBidir/.gitignore @@ -0,0 +1,3 @@ +Test.js +TestAMD.js +index.html diff --git a/js/test/Ice/optionalBidir/AMDInitialI.js b/js/test/Ice/optionalBidir/AMDInitialI.js new file mode 100644 index 00000000000..d4a7f15c38e --- /dev/null +++ b/js/test/Ice/optionalBidir/AMDInitialI.js @@ -0,0 +1,372 @@ +// ********************************************************************** +// +// 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 Ice = global.Ice; + var TestAMD = global.TestAMD; + + var Class = Ice.Class; + + var test = function(b) + { + if(!b) + { + throw new Error("test failed"); + } + }; + + var AMDInitialI = Class(TestAMD.Initial, { + shutdown_async: function(cb, current) + { + current.adapter.getCommunicator().shutdown(); + cb.ice_response(); + }, + pingPong_async: function(cb, obj, current) + { + cb.ice_response(obj); + }, + opOptionalException_async: function(cb, a, b, o, current) + { + var ex = new TestAMD.OptionalException(); + if(a !== undefined) + { + ex.a = a; + } + else + { + ex.a = undefined; // The member "a" has a default value. + } + if(b !== undefined) + { + ex.b = b; + } + if(o !== undefined) + { + ex.o = o; + } + cb.ice_exception(ex); + }, + opDerivedException_async: function(cb, a, b, o, current) + { + var ex = new TestAMD.DerivedException(); + if(a !== undefined) + { + ex.a = a; + } + else + { + ex.a = undefined; // The member "a" has a default value. + } + if(b !== undefined) + { + ex.b = b; + ex.ss = b; + } + else + { + ex.ss = undefined; // The member "ss" has a default value. + } + if(o !== undefined) + { + ex.o = o; + ex.o2 = o; + } + cb.ice_exception(ex); + }, + opRequiredException_async: function(cb, a, b, o, current) + { + var ex = new TestAMD.RequiredException(); + if(a !== undefined) + { + ex.a = a; + } + else + { + ex.a = undefined; // The member "a" has a default value. + } + if(b !== undefined) + { + ex.b = b; + ex.ss = b; + } + if(o !== undefined) + { + ex.o = o; + ex.o2 = o; + } + cb.ice_exception(ex); + }, + opByte_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opByteReq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opBool_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opBoolReq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opShort_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opShortReq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opInt_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opIntReq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opLong_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opLongReq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opFloat_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opFloatReq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opDouble_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opDoubleReq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opString_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opStringReq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opMyEnum_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opMyEnumReq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opSmallStruct_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opSmallStructReq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opFixedStruct_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opFixedStructReq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opVarStruct_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opVarStructReq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opOneOptional_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opOneOptionalReq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opOneOptionalProxy_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opOneOptionalProxyReq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opByteSeq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opByteSeqReq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opBoolSeq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opBoolSeqReq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opShortSeq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opShortSeqReq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opIntSeq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opIntSeqReq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opLongSeq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opLongSeqReq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opFloatSeq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opFloatSeqReq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opDoubleSeq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opDoubleSeqReq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opStringSeq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opStringSeqReq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opSmallStructSeq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opSmallStructSeqReq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opSmallStructList_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opSmallStructListReq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opFixedStructSeq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opFixedStructSeqReq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opFixedStructList_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opFixedStructListReq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opVarStructSeq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opVarStructSeqReq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opSerializable_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opSerializableReq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opIntIntDict_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opIntIntDictReq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opStringIntDict_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opStringIntDictReq_async: function(cb, p1, current) + { + cb.ice_response(p1, p1); + }, + opClassAndUnknownOptional_async: function(cb, p, current) + { + cb.ice_response(); + }, + sendOptionalClass_async: function(cb, req, current) + { + cb.ice_response(); + }, + returnOptionalClass_async: function(cb, req, current) + { + cb.ice_response(new TestAMD.OneOptional(53)); + }, + supportsRequiredParams_async: function(cb, current) + { + cb.ice_response(false); + }, + supportsJavaSerializable_async: function(cb, current) + { + cb.ice_response(false); + }, + supportsCsharpSerializable_async: function(cb, current) + { + cb.ice_response(false); + } + }); + + global.AMDInitialI = AMDInitialI; +}(typeof (global) === "undefined" ? window : global)); diff --git a/js/test/Ice/optionalBidir/Client.js b/js/test/Ice/optionalBidir/Client.js new file mode 100644 index 00000000000..5632bccb3ab --- /dev/null +++ b/js/test/Ice/optionalBidir/Client.js @@ -0,0 +1,106 @@ +// ********************************************************************** +// +// 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; + + var Promise = Ice.Promise; + var ArrayUtil = Ice.ArrayUtil; + + require("Test"); + require("TestAMD"); + + require("InitialI"); + require("AMDInitialI"); + require("../optional/Client"); + var InitialI = global.InitialI; + var AMDInitialI = global.AMDInitialI; + + var allTests = function(out, communicator, amd) + { + var Test = amd ? global.TestAMD : global.Test; + var base; + return Promise.try( + function() + { + base = communicator.stringToProxy("initial:default -p 12010"); + return communicator.createObjectAdapter(""); + } + ).then( + function(adapter) + { + if(amd) + { + adapter.add(new AMDInitialI(), communicator.stringToIdentity("initial")); + } + else + { + adapter.add(new InitialI(), communicator.stringToIdentity("initial")); + } + return base.ice_getConnection().then( + function(conn) + { + conn.setAdapter(adapter); + return __clientAllTests__(out, communicator, Test); + }); + } + ); + }; + + var run = function(out, id) + { + var communicator; + return Promise.try( + function() + { + communicator = Ice.initialize(id); + out.writeLine("testing bidir callbacks with synchronous dispatch..."); + return allTests(out, communicator, false); + } + ).then( + function() + { + return communicator.destroy(); + } + ).then( + function() + { + communicator = Ice.initialize(id); + out.writeLine("testing bidir callbacks with asynchronous dispatch..."); + return allTests(out, communicator, true); + } + ).then( + function() + { + return communicator.destroy(); + } + ).then( + function() + { + communicator = Ice.initialize(id); + var base = communicator.stringToProxy("__echo:default -p 12010"); + return global.Test.EchoPrx.checkedCast(base); + } + ).then( + function(prx) + { + return prx.shutdown(); + } + ).finally( + function() + { + return communicator.destroy(); + }); + }; + global.__test__ = run; + global.__runEchoServer__ = true; +}(typeof (global) === "undefined" ? window : global)); + diff --git a/js/test/Ice/optionalBidir/InitialI.js b/js/test/Ice/optionalBidir/InitialI.js new file mode 100644 index 00000000000..dc796860218 --- /dev/null +++ b/js/test/Ice/optionalBidir/InitialI.js @@ -0,0 +1,369 @@ +// ********************************************************************** +// +// 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 Ice = global.Ice; + var Test = global.Test; + + var Class = Ice.Class; + + var test = function(b) + { + if(!b) + { + throw new Error("test failed"); + } + }; + + var InitialI = Class(Test.Initial, { + shutdown: function(current) + { + current.adapter.getCommunicator().shutdown(); + }, + pingPong: function(obj, current) + { + return obj; + }, + opOptionalException: function(a, b, o, current) + { + var ex = new Test.OptionalException(); + if(a !== undefined) + { + ex.a = a; + } + else + { + ex.a = undefined; // The member "a" has a default value. + } + if(b !== undefined) + { + ex.b = b; + } + if(o !== undefined) + { + ex.o = o; + } + throw ex; + }, + opDerivedException: function(a, b, o, current) + { + var ex = new Test.DerivedException(); + if(a !== undefined) + { + ex.a = a; + } + else + { + ex.a = undefined; // The member "a" has a default value. + } + if(b !== undefined) + { + ex.b = b; + ex.ss = b; + } + else + { + ex.ss = undefined; // The member "ss" has a default value. + } + if(o !== undefined) + { + ex.o = o; + ex.o2 = o; + } + throw ex; + }, + opRequiredException: function(a, b, o, current) + { + var ex = new Test.RequiredException(); + if(a !== undefined) + { + ex.a = a; + } + else + { + ex.a = undefined; // The member "a" has a default value. + } + if(b !== undefined) + { + ex.b = b; + ex.ss = b; + } + if(o !== undefined) + { + ex.o = o; + ex.o2 = o; + } + throw ex; + }, + opByte: function(p1, current) + { + return [p1, p1]; + }, + opByteReq: function(p1, current) + { + return [p1, p1]; + }, + opBool: function(p1, current) + { + return [p1, p1]; + }, + opBoolReq: function(p1, current) + { + return [p1, p1]; + }, + opShort: function(p1, current) + { + return [p1, p1]; + }, + opShortReq: function(p1, current) + { + return [p1, p1]; + }, + opInt: function(p1, current) + { + return [p1, p1]; + }, + opIntReq: function(p1, current) + { + return [p1, p1]; + }, + opLong: function(p1, current) + { + return [p1, p1]; + }, + opLongReq: function(p1, current) + { + return [p1, p1]; + }, + opFloat: function(p1, current) + { + return [p1, p1]; + }, + opFloatReq: function(p1, current) + { + return [p1, p1]; + }, + opDouble: function(p1, current) + { + return [p1, p1]; + }, + opDoubleReq: function(p1, current) + { + return [p1, p1]; + }, + opString: function(p1, current) + { + return [p1, p1]; + }, + opStringReq: function(p1, current) + { + return [p1, p1]; + }, + opMyEnum: function(p1, current) + { + return [p1, p1]; + }, + opMyEnumReq: function(p1, current) + { + return [p1, p1]; + }, + opSmallStruct: function(p1, current) + { + return [p1, p1]; + }, + opSmallStructReq: function(p1, current) + { + return [p1, p1]; + }, + opFixedStruct: function(p1, current) + { + return [p1, p1]; + }, + opFixedStructReq: function(p1, current) + { + return [p1, p1]; + }, + opVarStruct: function(p1, current) + { + return [p1, p1]; + }, + opVarStructReq: function(p1, current) + { + return [p1, p1]; + }, + opOneOptional: function(p1, current) + { + return [p1, p1]; + }, + opOneOptionalReq: function(p1, current) + { + return [p1, p1]; + }, + opOneOptionalProxy: function(p1, current) + { + return [p1, p1]; + }, + opOneOptionalProxyReq: function(p1, current) + { + return [p1, p1]; + }, + opByteSeq: function(p1, current) + { + return [p1, p1]; + }, + opByteSeqReq: function(p1, current) + { + return [p1, p1]; + }, + opBoolSeq: function(p1, current) + { + return [p1, p1]; + }, + opBoolSeqReq: function(p1, current) + { + return [p1, p1]; + }, + opShortSeq: function(p1, current) + { + return [p1, p1]; + }, + opShortSeqReq: function(p1, current) + { + return [p1, p1]; + }, + opIntSeq: function(p1, current) + { + return [p1, p1]; + }, + opIntSeqReq: function(p1, current) + { + return [p1, p1]; + }, + opLongSeq: function(p1, current) + { + return [p1, p1]; + }, + opLongSeqReq: function(p1, current) + { + return [p1, p1]; + }, + opFloatSeq: function(p1, current) + { + return [p1, p1]; + }, + opFloatSeqReq: function(p1, current) + { + return [p1, p1]; + }, + opDoubleSeq: function(p1, current) + { + return [p1, p1]; + }, + opDoubleSeqReq: function(p1, current) + { + return [p1, p1]; + }, + opStringSeq: function(p1, current) + { + return [p1, p1]; + }, + opStringSeqReq: function(p1, current) + { + return [p1, p1]; + }, + opSmallStructSeq: function(p1, current) + { + return [p1, p1]; + }, + opSmallStructSeqReq: function(p1, current) + { + return [p1, p1]; + }, + opSmallStructList: function(p1, current) + { + return [p1, p1]; + }, + opSmallStructListReq: function(p1, current) + { + return [p1, p1]; + }, + opFixedStructSeq: function(p1, current) + { + return [p1, p1]; + }, + opFixedStructSeqReq: function(p1, current) + { + return [p1, p1]; + }, + opFixedStructList: function(p1, current) + { + return [p1, p1]; + }, + opFixedStructListReq: function(p1, current) + { + return [p1, p1]; + }, + opVarStructSeq: function(p1, current) + { + return [p1, p1]; + }, + opVarStructSeqReq: function(p1, current) + { + return [p1, p1]; + }, + opSerializable: function(p1, current) + { + return [p1, p1]; + }, + opSerializableReq: function(p1, current) + { + return [p1, p1]; + }, + opIntIntDict: function(p1, current) + { + return [p1, p1]; + }, + opIntIntDictReq: function(p1, current) + { + return [p1, p1]; + }, + opStringIntDict: function(p1, current) + { + return [p1, p1]; + }, + opStringIntDictReq: function(p1, current) + { + return [p1, p1]; + }, + opClassAndUnknownOptional: function(p, current) + { + }, + sendOptionalClass: function(req, current) + { + }, + returnOptionalClass: function(req, current) + { + return new Test.OneOptional(53); + }, + supportsRequiredParams: function(current) + { + return false; + }, + supportsJavaSerializable: function(current) + { + return false; + }, + supportsCsharpSerializable: function(current) + { + return false; + } + }); + + global.InitialI = InitialI; +}(typeof (global) === "undefined" ? window : global)); diff --git a/js/test/Ice/optionalBidir/Makefile b/js/test/Ice/optionalBidir/Makefile new file mode 100644 index 00000000000..2389e17b290 --- /dev/null +++ b/js/test/Ice/optionalBidir/Makefile @@ -0,0 +1,24 @@ +# ********************************************************************** +# +# 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 \ + TestAMD.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/optionalBidir/Makefile.mak b/js/test/Ice/optionalBidir/Makefile.mak new file mode 100644 index 00000000000..b6f6e8e97a1 --- /dev/null +++ b/js/test/Ice/optionalBidir/Makefile.mak @@ -0,0 +1,21 @@ +# ********************************************************************** +# +# 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 \ + TestAMD.js + +SRCS = Client.js + +!include $(top_srcdir)\config\Make.rules.mak.js + +SLICE2JSFLAGS = $(SLICE2JSFLAGS) -I"$(slicedir)" diff --git a/js/test/Ice/optionalBidir/Test.ice b/js/test/Ice/optionalBidir/Test.ice new file mode 100644 index 00000000000..fa326b05723 --- /dev/null +++ b/js/test/Ice/optionalBidir/Test.ice @@ -0,0 +1,301 @@ +// ********************************************************************** +// +// 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 +{ + +class OneOptional +{ + optional(1) int a; +}; + +enum MyEnum +{ + MyEnumMember +}; + +struct SmallStruct +{ + byte m; +}; + +struct FixedStruct +{ + int m; +}; + +struct VarStruct +{ + string m; +}; + +struct ClassVarStruct +{ + int a; +}; + +sequence<byte> ByteSeq; +sequence<bool> BoolSeq; +sequence<short> ShortSeq; +sequence<int> IntSeq; +sequence<long> LongSeq; +sequence<float> FloatSeq; +sequence<double> DoubleSeq; +sequence<string> StringSeq; +sequence<MyEnum> MyEnumSeq; +sequence<SmallStruct> SmallStructSeq; +sequence<SmallStruct> SmallStructList; +sequence<FixedStruct> FixedStructSeq; +sequence<FixedStruct> FixedStructList; +sequence<VarStruct> VarStructSeq; +sequence<OneOptional> OneOptionalSeq; +sequence<OneOptional*> OneOptionalPrxSeq; + +sequence<byte> Serializable; + +dictionary<int, int> IntIntDict; +dictionary<string, int> StringIntDict; +dictionary<int, MyEnum> IntEnumDict; +dictionary<int, FixedStruct> IntFixedStructDict; +dictionary<int, VarStruct> IntVarStructDict; +dictionary<int, OneOptional> IntOneOptionalDict; +dictionary<int, OneOptional*> IntOneOptionalPrxDict; + +class MultiOptional +{ + optional(1) byte a; + optional(2) bool b; + optional(3) short c; + optional(4) int d; + optional(5) long e; + optional(6) float f; + optional(7) double g; + optional(8) string h; + optional(9) MyEnum i; + optional(10) MultiOptional* j; + optional(11) MultiOptional k; + optional(12) ByteSeq bs; + optional(13) StringSeq ss; + optional(14) IntIntDict iid; + optional(15) StringIntDict sid; + optional(16) FixedStruct fs; + optional(17) VarStruct vs; + + optional(18) ShortSeq shs; + optional(19) MyEnumSeq es; + optional(20) FixedStructSeq fss; + optional(21) VarStructSeq vss; + optional(22) OneOptionalSeq oos; + optional(23) OneOptionalPrxSeq oops; + + optional(24) IntEnumDict ied; + optional(25) IntFixedStructDict ifsd; + optional(26) IntVarStructDict ivsd; + optional(27) IntOneOptionalDict iood; + optional(28) IntOneOptionalPrxDict ioopd; + + optional(29) BoolSeq bos; + + optional(30) Serializable ser; +}; + +class A +{ + int requiredA; + optional(1) int ma; + optional(50) int mb; + optional(500) int mc; +}; + +["preserve-slice"] +class B extends A +{ + int requiredB; + optional(10) int md; +}; + +class C extends B +{ + string ss; + optional(890) string ms; +}; + +class WD +{ + optional(1) int a = 5; + optional(2) string s = "test"; +}; + +exception OptionalException +{ + bool req = false; + optional(1) int a = 5; + optional(2) string b; + optional(50) OneOptional o; +}; + +exception DerivedException extends OptionalException +{ + optional(600) string ss = "test"; + optional(601) OneOptional o2; +}; + +exception RequiredException extends OptionalException +{ + string ss = "test"; + OneOptional o2; +}; + +class OptionalWithCustom +{ + optional(1) SmallStructList l; + ["protected"] optional(2) SmallStructList lp; + optional(3) ClassVarStruct s; +}; + +class E +{ + A ae; +}; + +class F extends E +{ + optional(1) A af; +}; + +class Initial +{ + void shutdown(); + + Object pingPong(Object o); + + void opOptionalException(optional(1) int a, optional(2) string b, optional(3) OneOptional o) + throws OptionalException; + + void opDerivedException(optional(1) int a, optional(2) string b, optional(3) OneOptional o) + throws OptionalException; + + void opRequiredException(optional(1) int a, optional(2) string b, optional(3) OneOptional o) + throws OptionalException; + + optional(1) byte opByte(optional(2) byte p1, out optional(3) byte p3); + optional(1) byte opByteReq(optional(2) byte p1, out optional(3) byte p3); + + optional(1) bool opBool(optional(2) bool p1, out optional(3) bool p3); + optional(1) bool opBoolReq(optional(2) bool p1, out optional(3) bool p3); + + optional(1) short opShort(optional(2) short p1, out optional(3) short p3); + optional(1) short opShortReq(optional(2) short p1, out optional(3) short p3); + + optional(1) int opInt(optional(2) int p1, out optional(3) int p3); + optional(1) int opIntReq(optional(2) int p1, out optional(3) int p3); + + optional(3) long opLong(optional(1) long p1, out optional(2) long p3); + optional(3) long opLongReq(optional(1) long p1, out optional(2) long p3); + + optional(1) float opFloat(optional(2) float p1, out optional(3) float p3); + optional(1) float opFloatReq(optional(2) float p1, out optional(3) float p3); + + optional(1) double opDouble(optional(2) double p1, out optional(3) double p3); + optional(1) double opDoubleReq(optional(2) double p1, out optional(3) double p3); + + optional(1) string opString(optional(2) string p1, out optional(3) string p3); + optional(1) string opStringReq(optional(2) string p1, out optional(3) string p3); + + optional(1) MyEnum opMyEnum(optional(2) MyEnum p1, out optional(3) MyEnum p3); + optional(1) MyEnum opMyEnumReq(optional(2) MyEnum p1, out optional(3) MyEnum p3); + + optional(1) SmallStruct opSmallStruct(optional(2) SmallStruct p1, out optional(3) SmallStruct p3); + optional(1) SmallStruct opSmallStructReq(optional(2) SmallStruct p1, out optional(3) SmallStruct p3); + + optional(1) FixedStruct opFixedStruct(optional(2) FixedStruct p1, out optional(3) FixedStruct p3); + optional(1) FixedStruct opFixedStructReq(optional(2) FixedStruct p1, out optional(3) FixedStruct p3); + + optional(1) VarStruct opVarStruct(optional(2) VarStruct p1, out optional(3) VarStruct p3); + optional(1) VarStruct opVarStructReq(optional(2) VarStruct p1, out optional(3) VarStruct p3); + + optional(1) OneOptional opOneOptional(optional(2) OneOptional p1, out optional(3) OneOptional p3); + optional(1) OneOptional opOneOptionalReq(optional(2) OneOptional p1, out optional(3) OneOptional p3); + + optional(1) OneOptional* opOneOptionalProxy(optional(2) OneOptional* p1, out optional(3) OneOptional* p3); + optional(1) OneOptional* opOneOptionalProxyReq(optional(2) OneOptional* p1, out optional(3) OneOptional* p3); + + optional(1) ByteSeq opByteSeq(optional(2) ByteSeq p1, out optional(3) ByteSeq p3); + optional(1) ByteSeq opByteSeqReq(optional(2) ByteSeq p1, out optional(3) ByteSeq p3); + + optional(1) BoolSeq opBoolSeq(optional(2) BoolSeq p1, out optional(3) BoolSeq p3); + optional(1) BoolSeq opBoolSeqReq(optional(2) BoolSeq p1, out optional(3) BoolSeq p3); + + optional(1) ShortSeq opShortSeq(optional(2) ShortSeq p1, out optional(3) ShortSeq p3); + optional(1) ShortSeq opShortSeqReq(optional(2) ShortSeq p1, out optional(3) ShortSeq p3); + + optional(1) IntSeq opIntSeq(optional(2) IntSeq p1, out optional(3) IntSeq p3); + optional(1) IntSeq opIntSeqReq(optional(2) IntSeq p1, out optional(3) IntSeq p3); + + optional(1) LongSeq opLongSeq(optional(2) LongSeq p1, out optional(3) LongSeq p3); + optional(1) LongSeq opLongSeqReq(optional(2) LongSeq p1, out optional(3) LongSeq p3); + + optional(1) FloatSeq opFloatSeq(optional(2) FloatSeq p1, out optional(3) FloatSeq p3); + optional(1) FloatSeq opFloatSeqReq(optional(2) FloatSeq p1, out optional(3) FloatSeq p3); + + optional(1) DoubleSeq opDoubleSeq(optional(2) DoubleSeq p1, out optional(3) DoubleSeq p3); + optional(1) DoubleSeq opDoubleSeqReq(optional(2) DoubleSeq p1, out optional(3) DoubleSeq p3); + + optional(1) StringSeq opStringSeq(optional(2) StringSeq p1, out optional(3) StringSeq p3); + optional(1) StringSeq opStringSeqReq(optional(2) StringSeq p1, out optional(3) StringSeq p3); + + optional(1) SmallStructSeq opSmallStructSeq(optional(2) SmallStructSeq p1, out optional(3) SmallStructSeq p3); + optional(1) SmallStructSeq opSmallStructSeqReq(optional(2) SmallStructSeq p1, out optional(3) SmallStructSeq p3); + + optional(1) SmallStructList opSmallStructList(optional(2) SmallStructList p1, out optional(3) SmallStructList p3); + optional(1) SmallStructList opSmallStructListReq(optional(2) SmallStructList p1, + out optional(3) SmallStructList p3); + + optional(1) FixedStructSeq opFixedStructSeq(optional(2) FixedStructSeq p1, out optional(3) FixedStructSeq p3); + optional(1) FixedStructSeq opFixedStructSeqReq(optional(2) FixedStructSeq p1, out optional(3) FixedStructSeq p3); + + optional(1) FixedStructList opFixedStructList(optional(2) FixedStructList p1, out optional(3) FixedStructList p3); + optional(1) FixedStructList opFixedStructListReq(optional(2) FixedStructList p1, + out optional(3) FixedStructList p3); + + optional(1) VarStructSeq opVarStructSeq(optional(2) VarStructSeq p1, out optional(3) VarStructSeq p3); + optional(1) VarStructSeq opVarStructSeqReq(optional(2) VarStructSeq p1, out optional(3) VarStructSeq p3); + + optional(1) Serializable opSerializable(optional(2) Serializable p1, out optional(3) Serializable p3); + optional(1) Serializable opSerializableReq(optional(2) Serializable p1, out optional(3) Serializable p3); + + optional(1) IntIntDict opIntIntDict(optional(2) IntIntDict p1, out optional(3) IntIntDict p3); + optional(1) IntIntDict opIntIntDictReq(optional(2) IntIntDict p1, out optional(3) IntIntDict p3); + + optional(1) StringIntDict opStringIntDict(optional(2) StringIntDict p1, out optional(3) StringIntDict p3); + optional(1) StringIntDict opStringIntDictReq(optional(2) StringIntDict p1, out optional(3) StringIntDict p3); + + void opClassAndUnknownOptional(A p); + + void sendOptionalClass(bool req, optional(1) OneOptional o); + + void returnOptionalClass(bool req, out optional(1) OneOptional o); + + bool supportsRequiredParams(); + + bool supportsJavaSerializable(); + + bool supportsCsharpSerializable(); +}; + +interface Echo +{ + void startBatch(); + void flushBatch(); + void shutdown(); +}; + +}; diff --git a/js/test/Ice/optionalBidir/TestAMD.ice b/js/test/Ice/optionalBidir/TestAMD.ice new file mode 100644 index 00000000000..217ed242679 --- /dev/null +++ b/js/test/Ice/optionalBidir/TestAMD.ice @@ -0,0 +1,301 @@ +// ********************************************************************** +// +// 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 TestAMD +{ + +class OneOptional +{ + optional(1) int a; +}; + +enum MyEnum +{ + MyEnumMember +}; + +struct SmallStruct +{ + byte m; +}; + +struct FixedStruct +{ + int m; +}; + +struct VarStruct +{ + string m; +}; + +struct ClassVarStruct +{ + int a; +}; + +sequence<byte> ByteSeq; +sequence<bool> BoolSeq; +sequence<short> ShortSeq; +sequence<int> IntSeq; +sequence<long> LongSeq; +sequence<float> FloatSeq; +sequence<double> DoubleSeq; +sequence<string> StringSeq; +sequence<MyEnum> MyEnumSeq; +sequence<SmallStruct> SmallStructSeq; +sequence<SmallStruct> SmallStructList; +sequence<FixedStruct> FixedStructSeq; +sequence<FixedStruct> FixedStructList; +sequence<VarStruct> VarStructSeq; +sequence<OneOptional> OneOptionalSeq; +sequence<OneOptional*> OneOptionalPrxSeq; + +sequence<byte> Serializable; + +dictionary<int, int> IntIntDict; +dictionary<string, int> StringIntDict; +dictionary<int, MyEnum> IntEnumDict; +dictionary<int, FixedStruct> IntFixedStructDict; +dictionary<int, VarStruct> IntVarStructDict; +dictionary<int, OneOptional> IntOneOptionalDict; +dictionary<int, OneOptional*> IntOneOptionalPrxDict; + +class MultiOptional +{ + optional(1) byte a; + optional(2) bool b; + optional(3) short c; + optional(4) int d; + optional(5) long e; + optional(6) float f; + optional(7) double g; + optional(8) string h; + optional(9) MyEnum i; + optional(10) MultiOptional* j; + optional(11) MultiOptional k; + optional(12) ByteSeq bs; + optional(13) StringSeq ss; + optional(14) IntIntDict iid; + optional(15) StringIntDict sid; + optional(16) FixedStruct fs; + optional(17) VarStruct vs; + + optional(18) ShortSeq shs; + optional(19) MyEnumSeq es; + optional(20) FixedStructSeq fss; + optional(21) VarStructSeq vss; + optional(22) OneOptionalSeq oos; + optional(23) OneOptionalPrxSeq oops; + + optional(24) IntEnumDict ied; + optional(25) IntFixedStructDict ifsd; + optional(26) IntVarStructDict ivsd; + optional(27) IntOneOptionalDict iood; + optional(28) IntOneOptionalPrxDict ioopd; + + optional(29) BoolSeq bos; + + optional(30) Serializable ser; +}; + +class A +{ + int requiredA; + optional(1) int ma; + optional(50) int mb; + optional(500) int mc; +}; + +["preserve-slice"] +class B extends A +{ + int requiredB; + optional(10) int md; +}; + +class C extends B +{ + string ss; + optional(890) string ms; +}; + +class WD +{ + optional(1) int a = 5; + optional(2) string s = "test"; +}; + +exception OptionalException +{ + bool req = false; + optional(1) int a = 5; + optional(2) string b; + optional(50) OneOptional o; +}; + +exception DerivedException extends OptionalException +{ + optional(600) string ss = "test"; + optional(601) OneOptional o2; +}; + +exception RequiredException extends OptionalException +{ + string ss = "test"; + OneOptional o2; +}; + +class OptionalWithCustom +{ + optional(1) SmallStructList l; + ["protected"] optional(2) SmallStructList lp; + optional(3) ClassVarStruct s; +}; + +class E +{ + A ae; +}; + +class F extends E +{ + optional(1) A af; +}; + +["amd"] class Initial +{ + void shutdown(); + + Object pingPong(Object o); + + void opOptionalException(optional(1) int a, optional(2) string b, optional(3) OneOptional o) + throws OptionalException; + + void opDerivedException(optional(1) int a, optional(2) string b, optional(3) OneOptional o) + throws OptionalException; + + void opRequiredException(optional(1) int a, optional(2) string b, optional(3) OneOptional o) + throws OptionalException; + + optional(1) byte opByte(optional(2) byte p1, out optional(3) byte p3); + optional(1) byte opByteReq(optional(2) byte p1, out optional(3) byte p3); + + optional(1) bool opBool(optional(2) bool p1, out optional(3) bool p3); + optional(1) bool opBoolReq(optional(2) bool p1, out optional(3) bool p3); + + optional(1) short opShort(optional(2) short p1, out optional(3) short p3); + optional(1) short opShortReq(optional(2) short p1, out optional(3) short p3); + + optional(1) int opInt(optional(2) int p1, out optional(3) int p3); + optional(1) int opIntReq(optional(2) int p1, out optional(3) int p3); + + optional(3) long opLong(optional(1) long p1, out optional(2) long p3); + optional(3) long opLongReq(optional(1) long p1, out optional(2) long p3); + + optional(1) float opFloat(optional(2) float p1, out optional(3) float p3); + optional(1) float opFloatReq(optional(2) float p1, out optional(3) float p3); + + optional(1) double opDouble(optional(2) double p1, out optional(3) double p3); + optional(1) double opDoubleReq(optional(2) double p1, out optional(3) double p3); + + optional(1) string opString(optional(2) string p1, out optional(3) string p3); + optional(1) string opStringReq(optional(2) string p1, out optional(3) string p3); + + optional(1) MyEnum opMyEnum(optional(2) MyEnum p1, out optional(3) MyEnum p3); + optional(1) MyEnum opMyEnumReq(optional(2) MyEnum p1, out optional(3) MyEnum p3); + + optional(1) SmallStruct opSmallStruct(optional(2) SmallStruct p1, out optional(3) SmallStruct p3); + optional(1) SmallStruct opSmallStructReq(optional(2) SmallStruct p1, out optional(3) SmallStruct p3); + + optional(1) FixedStruct opFixedStruct(optional(2) FixedStruct p1, out optional(3) FixedStruct p3); + optional(1) FixedStruct opFixedStructReq(optional(2) FixedStruct p1, out optional(3) FixedStruct p3); + + optional(1) VarStruct opVarStruct(optional(2) VarStruct p1, out optional(3) VarStruct p3); + optional(1) VarStruct opVarStructReq(optional(2) VarStruct p1, out optional(3) VarStruct p3); + + optional(1) OneOptional opOneOptional(optional(2) OneOptional p1, out optional(3) OneOptional p3); + optional(1) OneOptional opOneOptionalReq(optional(2) OneOptional p1, out optional(3) OneOptional p3); + + optional(1) OneOptional* opOneOptionalProxy(optional(2) OneOptional* p1, out optional(3) OneOptional* p3); + optional(1) OneOptional* opOneOptionalProxyReq(optional(2) OneOptional* p1, out optional(3) OneOptional* p3); + + optional(1) ByteSeq opByteSeq(optional(2) ByteSeq p1, out optional(3) ByteSeq p3); + optional(1) ByteSeq opByteSeqReq(optional(2) ByteSeq p1, out optional(3) ByteSeq p3); + + optional(1) BoolSeq opBoolSeq(optional(2) BoolSeq p1, out optional(3) BoolSeq p3); + optional(1) BoolSeq opBoolSeqReq(optional(2) BoolSeq p1, out optional(3) BoolSeq p3); + + optional(1) ShortSeq opShortSeq(optional(2) ShortSeq p1, out optional(3) ShortSeq p3); + optional(1) ShortSeq opShortSeqReq(optional(2) ShortSeq p1, out optional(3) ShortSeq p3); + + optional(1) IntSeq opIntSeq(optional(2) IntSeq p1, out optional(3) IntSeq p3); + optional(1) IntSeq opIntSeqReq(optional(2) IntSeq p1, out optional(3) IntSeq p3); + + optional(1) LongSeq opLongSeq(optional(2) LongSeq p1, out optional(3) LongSeq p3); + optional(1) LongSeq opLongSeqReq(optional(2) LongSeq p1, out optional(3) LongSeq p3); + + optional(1) FloatSeq opFloatSeq(optional(2) FloatSeq p1, out optional(3) FloatSeq p3); + optional(1) FloatSeq opFloatSeqReq(optional(2) FloatSeq p1, out optional(3) FloatSeq p3); + + optional(1) DoubleSeq opDoubleSeq(optional(2) DoubleSeq p1, out optional(3) DoubleSeq p3); + optional(1) DoubleSeq opDoubleSeqReq(optional(2) DoubleSeq p1, out optional(3) DoubleSeq p3); + + optional(1) StringSeq opStringSeq(optional(2) StringSeq p1, out optional(3) StringSeq p3); + optional(1) StringSeq opStringSeqReq(optional(2) StringSeq p1, out optional(3) StringSeq p3); + + optional(1) SmallStructSeq opSmallStructSeq(optional(2) SmallStructSeq p1, out optional(3) SmallStructSeq p3); + optional(1) SmallStructSeq opSmallStructSeqReq(optional(2) SmallStructSeq p1, out optional(3) SmallStructSeq p3); + + optional(1) SmallStructList opSmallStructList(optional(2) SmallStructList p1, out optional(3) SmallStructList p3); + optional(1) SmallStructList opSmallStructListReq(optional(2) SmallStructList p1, + out optional(3) SmallStructList p3); + + optional(1) FixedStructSeq opFixedStructSeq(optional(2) FixedStructSeq p1, out optional(3) FixedStructSeq p3); + optional(1) FixedStructSeq opFixedStructSeqReq(optional(2) FixedStructSeq p1, out optional(3) FixedStructSeq p3); + + optional(1) FixedStructList opFixedStructList(optional(2) FixedStructList p1, out optional(3) FixedStructList p3); + optional(1) FixedStructList opFixedStructListReq(optional(2) FixedStructList p1, + out optional(3) FixedStructList p3); + + optional(1) VarStructSeq opVarStructSeq(optional(2) VarStructSeq p1, out optional(3) VarStructSeq p3); + optional(1) VarStructSeq opVarStructSeqReq(optional(2) VarStructSeq p1, out optional(3) VarStructSeq p3); + + optional(1) Serializable opSerializable(optional(2) Serializable p1, out optional(3) Serializable p3); + optional(1) Serializable opSerializableReq(optional(2) Serializable p1, out optional(3) Serializable p3); + + optional(1) IntIntDict opIntIntDict(optional(2) IntIntDict p1, out optional(3) IntIntDict p3); + optional(1) IntIntDict opIntIntDictReq(optional(2) IntIntDict p1, out optional(3) IntIntDict p3); + + optional(1) StringIntDict opStringIntDict(optional(2) StringIntDict p1, out optional(3) StringIntDict p3); + optional(1) StringIntDict opStringIntDictReq(optional(2) StringIntDict p1, out optional(3) StringIntDict p3); + + void opClassAndUnknownOptional(A p); + + void sendOptionalClass(bool req, optional(1) OneOptional o); + + void returnOptionalClass(bool req, out optional(1) OneOptional o); + + bool supportsRequiredParams(); + + bool supportsJavaSerializable(); + + bool supportsCsharpSerializable(); +}; + +interface Echo +{ + void startBatch(); + void flushBatch(); + void shutdown(); +}; + +}; diff --git a/js/test/Ice/optionalBidir/run.js b/js/test/Ice/optionalBidir/run.js new file mode 100644 index 00000000000..a875f421701 --- /dev/null +++ b/js/test/Ice/optionalBidir/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/optionalBidir/run.py b/js/test/Ice/optionalBidir/run.py new file mode 100755 index 00000000000..f19909e6f59 --- /dev/null +++ b/js/test/Ice/optionalBidir/run.py @@ -0,0 +1,26 @@ +#!/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.clientEchoTest() +print("Running test with sliced format.") +TestUtil.clientEchoTest(additionalClientOptions="--Ice.Default.SlicedFormat", additionalServerOptions="--Ice.Default.SlicedFormat") diff --git a/js/test/Ice/promise/.gitignore b/js/test/Ice/promise/.gitignore new file mode 100644 index 00000000000..dcaf71693e4 --- /dev/null +++ b/js/test/Ice/promise/.gitignore @@ -0,0 +1 @@ +index.html diff --git a/js/test/Ice/promise/Client.js b/js/test/Ice/promise/Client.js new file mode 100644 index 00000000000..fa1e24970cd --- /dev/null +++ b/js/test/Ice/promise/Client.js @@ -0,0 +1,908 @@ +// ********************************************************************** +// +// 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("Ice/Debug"); + + var Ice = global.Ice || {}; + + var Debug = Ice.Debug; + var Promise = Ice.Promise; + + var test = function(b) + { + if(!b) + { + throw new Error("test failed"); + } + }; + + // + // Create a new promise object and call function fn with + // the promise as its first argument, then return the new + // promise. + // + var deferred = function(fn) + { + var promise = new Promise(); + fn.call(null, promise); + return promise; + }; + + var run = function(out) + { + var p = new Promise(); + + deferred( + function(promise) + { + out.write("Creating a promise object that is resolved and succeed... "); + var promise1 = new Promise().succeed(1024); + promise1.then( + function(i) + { + test(i === 1024); + test(promise1.succeeded()); + out.writeLine("ok"); + promise.succeed(); + }, + function(e) + { + promise.fail(); + test(false, e); + }); + }) + .then( + function() + { + return deferred( + function(promise) + { + out.write("Creating a promise object that is resolved and failed... "); + var promise1 = new Promise().fail("promise.fail"); + promise1.then( + function(i) + { + promise.fail(); + test(false, e); + }, + function(e) + { + test(e === "promise.fail"); + test(promise1.failed()); + out.writeLine("ok"); + promise.succeed(); + }); + }); + }) + .then( + function() + { + return deferred( + function(promise) + { + out.write("Creating a promise object that is resolved and succeed with multiple arguments... "); + var promise1 = new Promise().succeed(1024, "Hello World!"); + promise1.then( + function(i, msg) + { + test(i === 1024); + test(msg === "Hello World!"); + test(promise1.succeeded()); + out.writeLine("ok"); + promise.succeed(); + }, + function(e) + { + promise.fail(e); + test(false, e); + }); + }); + }) + .then( + function() + { + return deferred( + function(promise) + { + out.write("Creating a promise with a callback that returns a new value... "); + var promise1 = new Promise().succeed(1024); + promise1.then( + function(i) + { + test(i === 1024); + test(promise1.succeeded()); + return "Hello World!"; + }, + function(e) + { + promise.fail(); + test(false, e); + }) + .then( + function(msg) + { + test(msg === "Hello World!"); + out.writeLine("ok"); + promise.succeed(); + }, + function(e) + { + promise.fail(); + test(false, e); + }); + }); + }) + .then( + function() + { + return deferred( + function(promise) + { + out.write("Creating a promise object that recovers from a failure... "); + var promise1 = new Promise().fail("promise.fail"); + promise1.then( + function(i) + { + promise.fail(); + test(false, "Succeed called.failed expected"); + }, + function(e) + { + test(e === "promise.fail"); + test(promise1.failed()); + return "Hello World!"; + }) + .then( + function(msg) + { + test(msg === "Hello World!"); + out.writeLine("ok"); + promise.succeed(); + }, + function(e) + { + promise.fail(); + test(false, e); + }); + }); + }) + .then( + function() + { + return deferred( + function(promise) + { + out.write("Creating a promise object that rethrow a.failure... "); + var promise1 = new Promise().fail("promise.fail"); + promise1.then( + function(i) + { + promise.fail(); + test(false, e); + }, + function(e) + { + throw e; + }) + .then( + function(msg) + { + promise.fail(); + test(false, "Succeed called.failed expected"); + + }, + function(e) + { + test(e === "promise.fail"); + test(promise1.failed()); + out.writeLine("ok"); + promise.succeed(); + }); + }); + }) + .then( + function() + { + return deferred( + function(promise) + { + out.write("A second call to then should produce the same results... "); + var promise1 = new Promise().succeed(1024); + promise1.then( + function(i) + { + test(i === 1024); + test(promise1.succeeded()); + }, + function(e) + { + promise.fail(); + test(false, e); + }); + promise1.then( + function(i) + { + test(i === 1024); + test(promise1.succeeded()); + }, + function(e) + { + promise.fail(); + test(false, e); + }); + + promise1 = new Promise().fail("promise.fail"); + promise1.then( + function(i) + { + promise.fail(); + test(false, e); + }, + function(e) + { + test(e === "promise.fail"); + test(promise1.failed()); + }); + promise1.then( + function(i) + { + promise.fail(); + test(false, e); + }, + function(e) + { + test(e === "promise.fail"); + test(promise1.failed()); + out.writeLine("ok"); + promise.succeed(); + }); + }); + }) + .then( + function() + { + return deferred( + function(promise) + { + out.write("Create a promise that is not yet resolved, but will succeed... "); + var promise1 = new Promise(); + test(!promise1.completed()); + promise1.then( + function(i) + { + test(i === 1024); + out.writeLine("ok"); + promise.succeed(); + }, + function(e) + { + promise.fail(); + test(false, e); + } + ); + promise1.succeed(1024); + }); + }) + .then( + function() + { + return deferred( + function(promise) + { + out.write("Create a promise that is not yet resolved, but will.fail... "); + var promise1 = new Promise(); + test(!promise1.completed()); + promise1.then( + function(i) + { + promise.fail(); + test(false, "Succeed called.failed expected"); + }, + function(e) + { + test(e === "promise.fail"); + test(promise1.failed()); + out.writeLine("ok"); + promise.succeed(); + } + ); + promise1.fail("promise.fail"); + }); + }) + .then( + function() + { + return deferred( + function(promise) + { + out.write("Create a promise chain that is not yet resolved, but will succeed... "); + var promise1 = new Promise(); + var promise2 = new Promise(); + var promise3 = new Promise(); + promise1.then( + function(i) + { + test(i === 1); + return promise2; + }, + function(e) + { + promise.fail(); + test(false, e); + } + ).then( + function(i) + { + test(i === 2); + return promise3; + }, + function(e) + { + promise.fail(); + test(false, e); + } + ).then( + function(i) + { + test(i === 3); + return "Hello World!"; + }, + function(e) + { + promise.fail(); + test(false, e); + } + ).then( + function(msg) + { + test(promise1.succeeded() && promise2.succeeded() && promise3.succeeded()); + test(msg === "Hello World!"); + out.writeLine("ok"); + promise.succeed(); + }, + function(e) + { + promise.fail(); + test(false, e); + } + ); + test(!promise1.completed() && !promise2.completed() && !promise3.completed()); + + promise1.succeed(1); + promise2.succeed(2); + promise3.succeed(3); + }); + }) + .then( + function() + { + return deferred( + function(promise) + { + out.write("Use exception method on a Promise that will.fail... "); + var promise1 = new Promise().fail("promise.fail"); + promise1.exception( + function(e) + { + test(e === "promise.fail"); + out.writeLine("ok"); + promise.succeed(); + } + ); + }); + }) + .then( + function() + { + return deferred( + function(promise) + { + out.write("Promise exception propagation in succeed callback... "); + var promise1 = new Promise().fail("promise.fail"); + promise1.then( + function() + { + promise.fail(); + test(false, "response callback called but exception expected"); + } + ).then( + function() + { + promise.fail(); + test(false, "response callback called but exception expected"); + } + ).exception( + function(e) + { + // + // since no exception handler was passed to the first `.then`, the error propagates. + // + test(e === "promise.fail"); + out.writeLine("ok"); + promise.succeed(); + }); + } + ); + }) + .then( + function() + { + return deferred( + function(promise) + { + out.write("Promise exception propagation in exception callback... "); + var promise1 = new Promise().fail("promise.fail"); + promise1.then( + function() + { + promise.fail(); + test(false, "response callback called but exception expected"); + }, + function(ex) + { + throw "promise.fail"; + } + ).then( + function() + { + promise.fail(); + test(false, "response callback called but exception expected"); + } + ).then( + function() + { + promise.fail(); + test(false, "response callback called but exception expected"); + } + ).exception( + function(e) + { + // + // since no exception handler was passed to the first `.then`, the error propagates. + // + test(e === "promise.fail"); + out.writeLine("ok"); + promise.succeed(); + }); + } + ); + }) + .then( + function() + { + return deferred( + function(promise) + { + out.write("Use Promise.all to wait for several promises and all succeed... "); + var promise1 = new Promise(); + var promise2 = new Promise(); + var promise3 = new Promise(); + + Promise.all(promise1, promise2, promise3).then( + function(r1, r2, r3) + { + test(r1.length === 1); + test(r1[0] === 1024); + + test(r2.length === 2); + test(r2[0] === 1024); + test(r2[1] === 2048); + + test(r3.length === 3); + test(r3[0] === 1024); + test(r3[1] === 2048); + test(r3[2] === 4096); + + promise.succeed(); + }, + function() + { + promise.fail(); + test(false); + } + ); + + // + // Now resolve the promise in the reverse order, all succeed callback + // will get the result in the right order. + // + promise3.succeed(1024, 2048, 4096); + promise2.succeed(1024, 2048); + promise1.succeed(1024); + } + ); + }) + .then( + function() + { + return deferred( + function(promise) + { + // + // Now try the same using an array of promises + // + var promise1 = new Promise(); + var promise2 = new Promise(); + var promise3 = new Promise(); + + Promise.all([promise1, promise2, promise3]).then( + function(r1, r2, r3) + { + test(r1.length === 1); + test(r1[0] === 1024); + + test(r2.length === 2); + test(r2[0] === 1024); + test(r2[1] === 2048); + + test(r3.length === 3); + test(r3[0] === 1024); + test(r3[1] === 2048); + test(r3[2] === 4096); + + out.writeLine("ok"); + promise.succeed(); + }, + function() + { + promise.fail(); + test(false); + } + ); + + // + // Now resolve the promise in the reverse order, all succeed callback + // will get the result in the right order. + // + promise3.succeed(1024, 2048, 4096); + promise2.succeed(1024, 2048); + promise1.succeed(1024); + } + ); + }) + .then( + function() + { + return deferred( + function(promise) + { + out.write("Use Promise.all to wait for several promises and one fails... "); + var promise1 = new Promise(); + var promise2 = new Promise(); + var promise3 = new Promise(); + + Promise.all(promise1, promise2, promise3).then( + function(r1, r2, r3) + { + promise.fail(new Error()); + }, + function(e) + { + test(e === "promise.fail"); + promise.succeed(); + } + ); + + // + // Now resolve the promise in the reverse order. + // + promise3.succeed(1024, 2048, 4096); + promise2.succeed(1024, 2048); + promise1.fail("promise.fail"); + } + ); + }) + .then( + function() + { + return deferred( + function(promise) + { + // + // Same as before but using an array of promises. + var promise1 = new Promise(); + var promise2 = new Promise(); + var promise3 = new Promise(); + + Promise.all([promise1, promise2, promise3]).then( + function(r1, r2, r3) + { + promise.fail(new Error()); + }, + function(e) + { + test(e === "promise.fail"); + out.writeLine("ok"); + promise.succeed(); + } + ); + + // + // Now resolve the promise in the reverse order. + // + promise3.succeed(1024, 2048, 4096); + promise2.succeed(1024, 2048); + promise1.fail("promise.fail"); + } + ); + }) + .then( + function() + { + return deferred( + function(promise) + { + out.write("Test finally on a succeed promise... "); + + var p = new Promise().succeed(1024); + var called = false; + p.finally( + function(i) + { + called = true; + test(i == 1024); + return 1025; + } + ).then( + function(i) + { + test(i == 1024); + test(called); + out.writeLine("ok"); + promise.succeed(); + } + ).exception( + function(ex) + { + promise.fail(ex); + }); + } + ); + }) + .then( + function() + { + return deferred( + function(promise) + { + out.write("Test finally on a failed promise... "); + + var p = new Promise().fail("promise.failed"); + var called = false; + p.finally( + function(e) + { + called = true; + test(e == "promise.failed"); + return "foo"; + } + ).then( + function(i) + { + promise.fail(new Error()); + } + ).exception( + function(e) + { + test(called); + test(e == "promise.failed"); + out.writeLine("ok"); + promise.succeed(); + }); + } + ); + }) + .then( + function() + { + return deferred( + function(promise) + { + out.write("Test finally return a succeed promise... "); + + var p = new Promise().succeed(1024); + var called = false; + p.finally( + function(e) + { + called = true; + return new Promise().succeed(2048); + } + ).then( + function(i) + { + test(called); + test(i == 1024); + out.writeLine("ok"); + promise.succeed(); + } + ).exception( + function(ex) + { + promise.fail(ex); + }); + } + ); + }) + .then( + function() + { + return deferred( + function(promise) + { + out.write("Test finally return a fail promise... "); + + var p = new Promise().succeed(1024); + var called = false; + p.finally( + function(e) + { + called = true; + return new Promise().fail(new Error("error")); + } + ).then( + function(i) + { + test(called); + test(i == 1024); + out.writeLine("ok"); + promise.succeed(); + } + ).exception( + function(ex) + { + promise.fail(ex); + }); + } + ); + }) + .then( + function() + { + return deferred( + function(promise) + { + out.write("Test finally throw an exception... "); + + var p = new Promise().succeed(1024); + var called = false; + p.finally( + function(e) + { + called = true; + throw new Error("error"); + } + ).then( + function(i) + { + test(called); + test(i == 1024); + out.writeLine("ok"); + promise.succeed(); + } + ).exception( + function(ex) + { + promise.fail(ex); + }); + } + ); + }) + .then( + function() + { + return deferred( + function(promise) + { + out.write("Test Promise.try... "); + + Promise.try( + function() + { + out.writeLine("ok"); + promise.succeed(); + } + ).exception( + function() + { + promise.fail(new Error("test failed")); + } + ); + } + ); + }) + .then( + function() + { + return deferred( + function(promise) + { + out.write("Test promise delay... "); + + var p = new Promise(); + + var start = Date.now(); + + p = p.succeed(10).delay(500).then( + function(i) + { + test(i == 10); + test(Date.now() - start >= 500); + } + ).exception( + function(ex) + { + promise.fail(ex); + }); + + // + // Now test the static version. + // + p = p.then( + function() + { + start = Date.now(); + return Promise.delay(10, 500).then( + function(i) + { + test(i == 10); + test(Date.now() - start >= 500); + } + ).exception( + function(ex) + { + promise.fail(ex); + }); + }); + + // + // Same but with fail + // + p.then( + function() + { + f = new Promise(); + start = Date.now(); + return f.fail("failed").delay(500).then( + function(i) + { + test(false); + }, + function(ex) + { + test(ex == "failed"); + test(Date.now() - start >= 500); + out.writeLine("ok"); + promise.succeed(); + } + ).exception( + function(ex) + { + promise.fail(ex); + }); + }); + } + ); + }) + .then( + function(){ + p.succeed(); + }, + function(ex){ + p.fail(ex); + } + ); + return p; + }; + global.__test__ = run; +}(typeof (global) === "undefined" ? window : global)); diff --git a/js/test/Ice/promise/Makefile b/js/test/Ice/promise/Makefile new file mode 100644 index 00000000000..aa79fb2ecf2 --- /dev/null +++ b/js/test/Ice/promise/Makefile @@ -0,0 +1,15 @@ +# ********************************************************************** +# +# 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 + +include $(top_srcdir)/config/Make.rules.js + diff --git a/js/test/Ice/promise/Makefile.mak b/js/test/Ice/promise/Makefile.mak new file mode 100644 index 00000000000..66f6db7bb76 --- /dev/null +++ b/js/test/Ice/promise/Makefile.mak @@ -0,0 +1,16 @@ +# ********************************************************************** +# +# 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 + +SRCS = Client.js + +!include $(top_srcdir)\config\Make.rules.mak.js diff --git a/js/test/Ice/promise/run.js b/js/test/Ice/promise/run.js new file mode 100644 index 00000000000..fa3a4c19d4b --- /dev/null +++ b/js/test/Ice/promise/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);
\ No newline at end of file diff --git a/js/test/Ice/promise/run.py b/js/test/Ice/promise/run.py new file mode 100755 index 00000000000..7aae9321854 --- /dev/null +++ b/js/test/Ice/promise/run.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# ********************************************************************** +# +# 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 + +TestUtil.simpleTest() diff --git a/js/test/Ice/proxy/.gitignore b/js/test/Ice/proxy/.gitignore new file mode 100644 index 00000000000..d158d9308ba --- /dev/null +++ b/js/test/Ice/proxy/.gitignore @@ -0,0 +1,2 @@ +Test.js +index.html diff --git a/js/test/Ice/proxy/Client.js b/js/test/Ice/proxy/Client.js new file mode 100644 index 00000000000..89884560d00 --- /dev/null +++ b/js/test/Ice/proxy/Client.js @@ -0,0 +1,961 @@ +// ********************************************************************** +// +// 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 Test = global.Test; + var Promise = Ice.Promise; + + function allTests(communicator, out) + { + 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 ref, base, prx, cl, derived, cl10, cl20, cl13, port; + + var defaultProtocol = communicator.getProperties().getPropertyWithDefault("Ice.Default.Protocol", "tcp"); + + return Promise.try( + function() + { + out.write("testing stringToProxy... "); + ref = "test:default -p 12010"; + base = communicator.stringToProxy(ref); + test(base !== null); + + var b1 = communicator.stringToProxy("test"); + test(b1.ice_getIdentity().name === "test" && b1.ice_getIdentity().category.length === 0 && + b1.ice_getAdapterId().length === 0 && b1.ice_getFacet().length === 0); + b1 = communicator.stringToProxy("test "); + test(b1.ice_getIdentity().name === "test" && b1.ice_getIdentity().category.length === 0 && + b1.ice_getFacet().length === 0); + b1 = communicator.stringToProxy(" test "); + test(b1.ice_getIdentity().name === "test" && b1.ice_getIdentity().category.length === 0 && + b1.ice_getFacet().length === 0); + b1 = communicator.stringToProxy(" test"); + test(b1.ice_getIdentity().name === "test" && b1.ice_getIdentity().category.length === 0 && + b1.ice_getFacet().length === 0); + b1 = communicator.stringToProxy("'test -f facet'"); + test(b1.ice_getIdentity().name === "test -f facet" && b1.ice_getIdentity().category.length === 0 && + b1.ice_getFacet().length === 0); + try + { + b1 = communicator.stringToProxy("\"test -f facet'"); + test(false); + } + catch(ex) + { + if(!(ex instanceof Ice.ProxyParseException)) + { + test(false); + } + } + + b1 = communicator.stringToProxy("\"test -f facet\""); + test(b1.ice_getIdentity().name === "test -f facet" && b1.ice_getIdentity().category.length === 0 && + b1.ice_getFacet().length === 0); + b1 = communicator.stringToProxy("\"test -f facet@test\""); + test(b1.ice_getIdentity().name === "test -f facet@test" && b1.ice_getIdentity().category.length === 0 && + b1.ice_getFacet().length === 0); + b1 = communicator.stringToProxy("\"test -f facet@test @test\""); + test(b1.ice_getIdentity().name === "test -f facet@test @test" && b1.ice_getIdentity().category.length === 0 && + b1.ice_getFacet().length === 0); + try + { + b1 = communicator.stringToProxy("test test"); + test(false); + } + catch(ex) + { + if(!(ex instanceof Ice.ProxyParseException)) + { + test(false); + } + } + + b1 = communicator.stringToProxy("test\\040test"); + test(b1.ice_getIdentity().name === "test test" && b1.ice_getIdentity().category.length === 0); + try + { + b1 = communicator.stringToProxy("test\\777"); + test(false); + } + catch(ex) + { + if(!(ex instanceof Ice.IdentityParseException)) + { + test(false); + } + } + b1 = communicator.stringToProxy("test\\40test"); + test(b1.ice_getIdentity().name === "test test"); + + // Test some octal and hex corner cases. + b1 = communicator.stringToProxy("test\\4test"); + test(b1.ice_getIdentity().name === "test\x04test"); + b1 = communicator.stringToProxy("test\\04test"); + test(b1.ice_getIdentity().name === "test\x04test"); + b1 = communicator.stringToProxy("test\\004test"); + test(b1.ice_getIdentity().name === "test\x04test"); + b1 = communicator.stringToProxy("test\\1114test"); + test(b1.ice_getIdentity().name === "test\x494test"); + + b1 = communicator.stringToProxy("test\\b\\f\\n\\r\\t\\'\\\"\\\\test"); + test(b1.ice_getIdentity().name === "test\b\f\n\r\t\'\"\\test" && + b1.ice_getIdentity().category.length === 0); + + b1 = communicator.stringToProxy("category/test"); + test(b1.ice_getIdentity().name === "test" && b1.ice_getIdentity().category === "category" && + b1.ice_getAdapterId().length === 0); + + b1 = communicator.stringToProxy(""); + test(b1 === null); + b1 = communicator.stringToProxy("\"\""); + test(b1 === null); + try + { + b1 = communicator.stringToProxy("\"\" test"); // Invalid trailing characters. + test(false); + } + catch(ex) + { + if(!(ex instanceof Ice.ProxyParseException)) + { + test(false); + } + } + try + { + b1 = communicator.stringToProxy("test:"); // Missing endpoint. + test(false); + } + catch(ex) + { + if(!(ex instanceof Ice.EndpointParseException)) + { + test(false); + } + } + + b1 = communicator.stringToProxy("test@adapter"); + test(b1.ice_getIdentity().name === "test" && b1.ice_getIdentity().category.length === 0 && + b1.ice_getAdapterId() === "adapter"); + try + { + b1 = communicator.stringToProxy("id@adapter test"); + test(false); + } + catch(ex) + { + if(!(ex instanceof Ice.ProxyParseException)) + { + test(false); + } + } + b1 = communicator.stringToProxy("category/test@adapter"); + test(b1.ice_getIdentity().name === "test" && b1.ice_getIdentity().category === "category" && + b1.ice_getAdapterId() === "adapter"); + b1 = communicator.stringToProxy("category/test@adapter:" + defaultProtocol); + test(b1.ice_getIdentity().name === "test" && b1.ice_getIdentity().category === "category" && + b1.ice_getAdapterId() === "adapter:" + defaultProtocol); + b1 = communicator.stringToProxy("'category 1/test'@adapter"); + test(b1.ice_getIdentity().name === "test" && b1.ice_getIdentity().category === "category 1" && + b1.ice_getAdapterId() === "adapter"); + b1 = communicator.stringToProxy("'category/test 1'@adapter"); + test(b1.ice_getIdentity().name === "test 1" && b1.ice_getIdentity().category === "category" && + b1.ice_getAdapterId() === "adapter"); + b1 = communicator.stringToProxy("'category/test'@'adapter 1'"); + test(b1.ice_getIdentity().name === "test" && b1.ice_getIdentity().category === "category" && + b1.ice_getAdapterId() === "adapter 1"); + b1 = communicator.stringToProxy("\"category \\/test@foo/test\"@adapter"); + test(b1.ice_getIdentity().name === "test" && b1.ice_getIdentity().category === "category /test@foo" && + b1.ice_getAdapterId() === "adapter"); + b1 = communicator.stringToProxy("\"category \\/test@foo/test\"@\"adapter:" + defaultProtocol + "\""); + test(b1.ice_getIdentity().name === "test" && b1.ice_getIdentity().category === "category /test@foo" && + b1.ice_getAdapterId() === "adapter:" + defaultProtocol); + + b1 = communicator.stringToProxy("id -f facet"); + test(b1.ice_getIdentity().name === "id" && b1.ice_getIdentity().category.length === 0 && + b1.ice_getFacet() === "facet"); + b1 = communicator.stringToProxy("id -f 'facet x'"); + test(b1.ice_getIdentity().name === "id" && b1.ice_getIdentity().category.length === 0 && + b1.ice_getFacet() === "facet x"); + b1 = communicator.stringToProxy("id -f \"facet x\""); + test(b1.ice_getIdentity().name === "id" && b1.ice_getIdentity().category.length === 0 && + b1.ice_getFacet() === "facet x"); + try + { + b1 = communicator.stringToProxy("id -f \"facet x"); + test(false); + } + catch(ex) + { + if(!(ex instanceof Ice.ProxyParseException)) + { + test(false); + } + } + try + { + b1 = communicator.stringToProxy("id -f \'facet x"); + test(false); + } + catch(ex) + { + if(!(ex instanceof Ice.ProxyParseException)) + { + test(false); + } + } + b1 = communicator.stringToProxy("test -f facet:" + defaultProtocol); + test(b1.ice_getIdentity().name === "test" && b1.ice_getIdentity().category.length === 0 && + b1.ice_getFacet() === "facet" && b1.ice_getAdapterId().length === 0); + b1 = communicator.stringToProxy("test -f \"facet:" + defaultProtocol + "\""); + test(b1.ice_getIdentity().name === "test" && b1.ice_getIdentity().category.length === 0 && + b1.ice_getFacet() === "facet:" + defaultProtocol && b1.ice_getAdapterId().length === 0); + b1 = communicator.stringToProxy("test -f facet@test"); + test(b1.ice_getIdentity().name === "test" && b1.ice_getIdentity().category.length === 0 && + b1.ice_getFacet() === "facet" && b1.ice_getAdapterId() === "test"); + b1 = communicator.stringToProxy("test -f 'facet@test'"); + test(b1.ice_getIdentity().name === "test" && b1.ice_getIdentity().category.length === 0 && + b1.ice_getFacet() === "facet@test" && b1.ice_getAdapterId().length === 0); + b1 = communicator.stringToProxy("test -f 'facet@test'@test"); + test(b1.ice_getIdentity().name === "test" && b1.ice_getIdentity().category.length === 0 && + b1.ice_getFacet() === "facet@test" && b1.ice_getAdapterId() === "test"); + try + { + b1 = communicator.stringToProxy("test -f facet@test @test"); + test(false); + } + catch(ex) + { + if(!(ex instanceof Ice.ProxyParseException)) + { + test(false); + } + } + b1 = communicator.stringToProxy("test"); + test(b1.ice_isTwoway()); + b1 = communicator.stringToProxy("test -t"); + test(b1.ice_isTwoway()); + b1 = communicator.stringToProxy("test -o"); + test(b1.ice_isOneway()); + b1 = communicator.stringToProxy("test -O"); + test(b1.ice_isBatchOneway()); + b1 = communicator.stringToProxy("test -d"); + test(b1.ice_isDatagram()); + b1 = communicator.stringToProxy("test -D"); + test(b1.ice_isBatchDatagram()); + b1 = communicator.stringToProxy("test"); + test(!b1.ice_isSecure()); + b1 = communicator.stringToProxy("test -s"); + test(b1.ice_isSecure()); + + test(b1.ice_getEncodingVersion().equals(Ice.currentEncoding())); + + b1 = communicator.stringToProxy("test -e 1.0"); + test(b1.ice_getEncodingVersion().major === 1 && b1.ice_getEncodingVersion().minor === 0); + + b1 = communicator.stringToProxy("test -e 6.5"); + test(b1.ice_getEncodingVersion().major === 6 && b1.ice_getEncodingVersion().minor === 5); + + b1 = communicator.stringToProxy("test -p 1.0 -e 1.0"); + test(b1.toString() === "test -t -e 1.0"); + + b1 = communicator.stringToProxy("test -p 6.5 -e 1.0"); + test(b1.toString() === "test -t -p 6.5 -e 1.0"); + + try + { + b1 = communicator.stringToProxy("test:" + defaultProtocol + "@adapterId"); + test(false); + } + catch(ex) + { + if(!(ex instanceof Ice.EndpointParseException)) + { + test(false); + } + } + // This is an unknown endpoint warning, not a parse exception. + // + //try + //{ + // b1 = communicator.stringToProxy("test -f the:facet:tcp"); + // test(false); + //} + //catch(ex:Ice.EndpointParseException) + //{ + //} + try + { + b1 = communicator.stringToProxy("test::" + defaultProtocol); + test(false); + } + catch(ex) + { + if(!(ex instanceof Ice.EndpointParseException)) + { + test(false); + } + } + out.writeLine("ok"); + + out.write("testing propertyToProxy... "); + var prop = communicator.getProperties(); + var propertyPrefix = "Foo.Proxy"; + prop.setProperty(propertyPrefix, "test:default -p 12010"); + b1 = communicator.propertyToProxy(propertyPrefix); + test(b1.ice_getIdentity().name === "test" && b1.ice_getIdentity().category.length === 0 && + b1.ice_getAdapterId().length === 0 && b1.ice_getFacet().length === 0); + + var property; + + property = propertyPrefix + ".Locator"; + test(b1.ice_getLocator() === null); + prop.setProperty(property, "locator:default -p 10000"); + b1 = communicator.propertyToProxy(propertyPrefix); + test(b1.ice_getLocator() !== null && b1.ice_getLocator().ice_getIdentity().name === "locator"); + prop.setProperty(property, ""); + + property = propertyPrefix + ".LocatorCacheTimeout"; + test(b1.ice_getLocatorCacheTimeout() === -1); + prop.setProperty(property, "1"); + b1 = communicator.propertyToProxy(propertyPrefix); + test(b1.ice_getLocatorCacheTimeout() === 1); + prop.setProperty(property, ""); + + // Now retest with an indirect proxy. + prop.setProperty(propertyPrefix, "test"); + property = propertyPrefix + ".Locator"; + prop.setProperty(property, "locator:default -p 10000"); + b1 = communicator.propertyToProxy(propertyPrefix); + test(b1.ice_getLocator() !== null && b1.ice_getLocator().ice_getIdentity().name === "locator"); + prop.setProperty(property, ""); + + property = propertyPrefix + ".LocatorCacheTimeout"; + test(b1.ice_getLocatorCacheTimeout() === -1); + prop.setProperty(property, "1"); + b1 = communicator.propertyToProxy(propertyPrefix); + test(b1.ice_getLocatorCacheTimeout() === 1); + prop.setProperty(property, ""); + + // This cannot be tested so easily because the property is cached + // on communicator initialization. + // + //prop.setProperty("Ice.Default.LocatorCacheTimeout", "60"); + //b1 = communicator.propertyToProxy(propertyPrefix); + //test(b1.ice_getLocatorCacheTimeout() === 60); + //prop.setProperty("Ice.Default.LocatorCacheTimeout", ""); + + prop.setProperty(propertyPrefix, "test:default -p 12010"); + + property = propertyPrefix + ".Router"; + test(b1.ice_getRouter() === null); + prop.setProperty(property, "router:default -p 10000"); + b1 = communicator.propertyToProxy(propertyPrefix); + test(b1.ice_getRouter() !== null && b1.ice_getRouter().ice_getIdentity().name === "router"); + prop.setProperty(property, ""); + + property = propertyPrefix + ".PreferSecure"; + test(!b1.ice_isPreferSecure()); + prop.setProperty(property, "1"); + b1 = communicator.propertyToProxy(propertyPrefix); + test(b1.ice_isPreferSecure()); + prop.setProperty(property, ""); + + property = propertyPrefix + ".ConnectionCached"; + test(b1.ice_isConnectionCached()); + prop.setProperty(property, "0"); + b1 = communicator.propertyToProxy(propertyPrefix); + test(!b1.ice_isConnectionCached()); + prop.setProperty(property, ""); + + property = propertyPrefix + ".EndpointSelection"; + test(b1.ice_getEndpointSelection() === Ice.EndpointSelectionType.Random); + prop.setProperty(property, "Random"); + b1 = communicator.propertyToProxy(propertyPrefix); + test(b1.ice_getEndpointSelection() === Ice.EndpointSelectionType.Random); + prop.setProperty(property, "Ordered"); + b1 = communicator.propertyToProxy(propertyPrefix); + test(b1.ice_getEndpointSelection() === Ice.EndpointSelectionType.Ordered); + prop.setProperty(property, ""); + + out.writeLine("ok"); + + out.write("testing proxyToProperty... "); + + b1 = communicator.stringToProxy("test"); + b1 = b1.ice_connectionCached(true); + b1 = b1.ice_preferSecure(false); + b1 = b1.ice_endpointSelection(Ice.EndpointSelectionType.Ordered); + b1 = b1.ice_locatorCacheTimeout(100); + b1 = b1.ice_encodingVersion(new Ice.EncodingVersion(1, 0)); + + var router = communicator.stringToProxy("router"); + router = router.ice_connectionCached(true); + router = router.ice_preferSecure(true); + router = router.ice_endpointSelection(Ice.EndpointSelectionType.Random); + router = router.ice_locatorCacheTimeout(200); + + var locator = communicator.stringToProxy("locator"); + locator = locator.ice_connectionCached(false); + locator = locator.ice_preferSecure(true); + locator = locator.ice_endpointSelection(Ice.EndpointSelectionType.Random); + locator = locator.ice_locatorCacheTimeout(300); + + locator = locator.ice_router(Ice.RouterPrx.uncheckedCast(router)); + b1 = b1.ice_locator(Ice.LocatorPrx.uncheckedCast(locator)); + + var proxyProps = communicator.proxyToProperty(b1, "Test"); + test(proxyProps.size === 18); + + test(proxyProps.get("Test") === "test -t -e 1.0"); + test(proxyProps.get("Test.CollocationOptimized") === "0"); + test(proxyProps.get("Test.ConnectionCached") === "1"); + test(proxyProps.get("Test.PreferSecure") === "0"); + test(proxyProps.get("Test.EndpointSelection") === "Ordered"); + test(proxyProps.get("Test.LocatorCacheTimeout") === "100"); + + test(proxyProps.get("Test.Locator") === "locator -t -e " + + Ice.encodingVersionToString(Ice.currentEncoding())); + test(proxyProps.get("Test.Locator.CollocationOptimized") === "0"); + test(proxyProps.get("Test.Locator.ConnectionCached") === "0"); + test(proxyProps.get("Test.Locator.PreferSecure") === "1"); + test(proxyProps.get("Test.Locator.EndpointSelection") === "Random"); + test(proxyProps.get("Test.Locator.LocatorCacheTimeout") === "300"); + + test(proxyProps.get("Test.Locator.Router") === "router -t -e " + + Ice.encodingVersionToString(Ice.currentEncoding())); + test(proxyProps.get("Test.Locator.Router.CollocationOptimized") === "0"); + test(proxyProps.get("Test.Locator.Router.ConnectionCached") === "1"); + test(proxyProps.get("Test.Locator.Router.PreferSecure") === "1"); + test(proxyProps.get("Test.Locator.Router.EndpointSelection") === "Random"); + test(proxyProps.get("Test.Locator.Router.LocatorCacheTimeout") === "200"); + + out.writeLine("ok"); + + out.write("testing ice_getCommunicator... "); + test(base.ice_getCommunicator() === communicator); + out.writeLine("ok"); + + out.write("testing proxy methods... "); + test(communicator.identityToString( + base.ice_identity(communicator.stringToIdentity("other")).ice_getIdentity()) === "other"); + test(base.ice_facet("facet").ice_getFacet() === "facet"); + test(base.ice_adapterId("id").ice_getAdapterId() === "id"); + test(base.ice_twoway().ice_isTwoway()); + test(base.ice_oneway().ice_isOneway()); + test(base.ice_batchOneway().ice_isBatchOneway()); + test(base.ice_datagram().ice_isDatagram()); + test(base.ice_batchDatagram().ice_isBatchDatagram()); + test(base.ice_secure(true).ice_isSecure()); + test(!base.ice_secure(false).ice_isSecure()); + test(base.ice_preferSecure(true).ice_isPreferSecure()); + test(!base.ice_preferSecure(false).ice_isPreferSecure()); + test(base.ice_encodingVersion(Ice.Encoding_1_0).ice_getEncodingVersion().equals(Ice.Encoding_1_0)); + test(base.ice_encodingVersion(Ice.Encoding_1_1).ice_getEncodingVersion().equals(Ice.Encoding_1_1)); + test(!base.ice_encodingVersion(Ice.Encoding_1_0).ice_getEncodingVersion().equals(Ice.Encoding_1_1)); + out.writeLine("ok"); + + out.write("testing proxy comparison... "); + + test(communicator.stringToProxy("foo").equals(communicator.stringToProxy("foo"))); + test(!communicator.stringToProxy("foo").equals(communicator.stringToProxy("foo2"))); + + var compObj = communicator.stringToProxy("foo"); + + test(compObj.ice_facet("facet").equals(compObj.ice_facet("facet"))); + test(!compObj.ice_facet("facet").equals(compObj.ice_facet("facet1"))); + + test(compObj.ice_oneway().equals(compObj.ice_oneway())); + test(!compObj.ice_oneway().equals(compObj.ice_twoway())); + + test(compObj.ice_secure(true).equals(compObj.ice_secure(true))); + test(!compObj.ice_secure(false).equals(compObj.ice_secure(true))); + + test(compObj.ice_connectionCached(true).equals(compObj.ice_connectionCached(true))); + test(!compObj.ice_connectionCached(false).equals(compObj.ice_connectionCached(true))); + + test(compObj.ice_endpointSelection(Ice.EndpointSelectionType.Random).equals( + compObj.ice_endpointSelection(Ice.EndpointSelectionType.Random))); + test(!compObj.ice_endpointSelection(Ice.EndpointSelectionType.Random).equals( + compObj.ice_endpointSelection(Ice.EndpointSelectionType.Ordered))); + + test(compObj.ice_connectionId("id2").equals(compObj.ice_connectionId("id2"))); + test(!compObj.ice_connectionId("id1").equals(compObj.ice_connectionId("id2"))); + + test(compObj.ice_connectionId("id1").ice_getConnectionId() === "id1"); + test(compObj.ice_connectionId("id2").ice_getConnectionId() === "id2"); + + test(compObj.ice_compress(true).equals(compObj.ice_compress(true))); + test(!compObj.ice_compress(false).equals(compObj.ice_compress(true))); + + test(compObj.ice_timeout(20).equals(compObj.ice_timeout(20))); + test(!compObj.ice_timeout(10).equals(compObj.ice_timeout(20))); + + var loc1 = Ice.LocatorPrx.uncheckedCast(communicator.stringToProxy("loc1:default -p 10000")); + var loc2 = Ice.LocatorPrx.uncheckedCast(communicator.stringToProxy("loc2:default -p 10000")); + test(compObj.ice_locator(null).equals(compObj.ice_locator(null))); + test(compObj.ice_locator(loc1).equals(compObj.ice_locator(loc1))); + test(!compObj.ice_locator(loc1).equals(compObj.ice_locator(null))); + test(!compObj.ice_locator(null).equals(compObj.ice_locator(loc2))); + test(!compObj.ice_locator(loc1).equals(compObj.ice_locator(loc2))); + + var rtr1 = Ice.RouterPrx.uncheckedCast(communicator.stringToProxy("rtr1:default -p 10000")); + var rtr2 = Ice.RouterPrx.uncheckedCast(communicator.stringToProxy("rtr2:default -p 10000")); + test(compObj.ice_router(null).equals(compObj.ice_router(null))); + test(compObj.ice_router(rtr1).equals(compObj.ice_router(rtr1))); + test(!compObj.ice_router(rtr1).equals(compObj.ice_router(null))); + test(!compObj.ice_router(null).equals(compObj.ice_router(rtr2))); + test(!compObj.ice_router(rtr1).equals(compObj.ice_router(rtr2))); + + var ctx1 = new Ice.HashMap(); + ctx1.set("ctx1", "v1"); + var ctx2 = new Ice.HashMap(); + ctx2.set("ctx2", "v2"); + test(compObj.ice_context(null).equals(compObj.ice_context(null))); + test(compObj.ice_context(ctx1).equals(compObj.ice_context(ctx1))); + test(!compObj.ice_context(ctx1).equals(compObj.ice_context(null))); + test(!compObj.ice_context(null).equals(compObj.ice_context(ctx2))); + test(!compObj.ice_context(ctx1).equals(compObj.ice_context(ctx2))); + + test(compObj.ice_preferSecure(true).equals(compObj.ice_preferSecure(true))); + test(!compObj.ice_preferSecure(true).equals(compObj.ice_preferSecure(false))); + + var compObj1 = communicator.stringToProxy("foo:" + defaultProtocol + " -h 127.0.0.1 -p 10000"); + var compObj2 = communicator.stringToProxy("foo:" + defaultProtocol + " -h 127.0.0.1 -p 10001"); + test(!compObj1.equals(compObj2)); + + compObj1 = communicator.stringToProxy("foo@MyAdapter1"); + compObj2 = communicator.stringToProxy("foo@MyAdapter2"); + test(!compObj1.equals(compObj2)); + + test(compObj1.ice_locatorCacheTimeout(20).equals(compObj1.ice_locatorCacheTimeout(20))); + test(!compObj1.ice_locatorCacheTimeout(10).equals(compObj1.ice_locatorCacheTimeout(20))); + + compObj1 = communicator.stringToProxy("foo:" + defaultProtocol + " -h 127.0.0.1 -p 1000"); + compObj2 = communicator.stringToProxy("foo@MyAdapter1"); + test(!compObj1.equals(compObj2)); + + var endpts1 = communicator.stringToProxy("foo:" + defaultProtocol + " -h 127.0.0.1 -p 10000").ice_getEndpoints(); + var endpts2 = communicator.stringToProxy("foo:" + defaultProtocol + " -h 127.0.0.1 -p 10001").ice_getEndpoints(); + test(!endpts1[0].equals(endpts2[0])); + test(endpts1[0].equals(communicator.stringToProxy("foo:" + defaultProtocol + " -h 127.0.0.1 -p 10000").ice_getEndpoints()[0])); + + test(compObj1.ice_encodingVersion(Ice.Encoding_1_0).equals(compObj1.ice_encodingVersion(Ice.Encoding_1_0))); + test(!compObj1.ice_encodingVersion(Ice.Encoding_1_0).equals(compObj1.ice_encodingVersion(Ice.Encoding_1_1))); + + // + // TODO: Ideally we should also test comparison of fixed proxies. + // + out.writeLine("ok"); + + out.write("testing checked cast... "); + return Test.MyClassPrx.checkedCast(base); + } + ).then( + function(prx) + { + cl = prx; + test(cl !== null); + return Test.MyDerivedClassPrx.checkedCast(cl); + } + ).then( + function(prx) + { + derived = prx; + test(derived !== null); + test(cl.equals(base)); + test(derived.equals(base)); + test(cl.equals(derived)); + out.writeLine("ok"); + out.write("testing checked cast with context... "); + + return cl.getContext(); + } + ).then( + function(c) + { + test(c.size === 0); + c = new Ice.HashMap(); + c.set("one", "hello"); + c.set("two", "world"); + return Test.MyClassPrx.checkedCast(base, undefined, c).then( + function(cl) + { + return cl.getContext(); + } + ).then( + function(c2) + { + test(c.equals(c2)); + out.writeLine("ok"); + + out.write("testing encoding versioning... "); + + var ref20 = "test -e 2.0:default -p 12010"; + cl20 = Test.MyClassPrx.uncheckedCast(communicator.stringToProxy(ref20)); + return cl20.ice_ping(); + }); + } + ).then( + function() + { + test(false); + }, + function(ex) + { + test(ex instanceof Ice.UnsupportedEncodingException); + var ref10 = "test -e 1.0:default -p 12010"; + cl10 = Test.MyClassPrx.uncheckedCast(communicator.stringToProxy(ref10)); + return cl10.ice_ping(); + } + ).then( + function() + { + return cl10.ice_encodingVersion(Ice.Encoding_1_0).ice_ping(); + } + ).then( + function() + { + // 1.3 isn't supported but since a 1.3 proxy supports 1.1, the + // call will use the 1.1 encoding + var ref13 = "test -e 1.3:default -p 12010"; + var cl13 = Test.MyClassPrx.uncheckedCast(communicator.stringToProxy(ref13)); + + // TODO: Port ice_invoke tests? + + out.writeLine("ok"); + + out.write("testing protocol versioning... "); + + var ref20 = "test -p 2.0:default -p 12010"; + cl20 = Test.MyClassPrx.uncheckedCast(communicator.stringToProxy(ref20)); + return cl20.ice_ping(); + } + ).then( + function() + { + test(false); + }, + function(ex) + { + test(ex instanceof Ice.UnsupportedProtocolException); + var ref10 = "test -p 1.0:default -p 12010"; + cl10 = Test.MyClassPrx.uncheckedCast(communicator.stringToProxy(ref10)); + return cl10.ice_ping(); + } + ).then( + function() + { + // 1.3 isn't supported but since a 1.3 proxy supports 1.1, the + // call will use the 1.1 encoding + var ref13 = "test -p 1.3:default -p 12010"; + cl13 = Test.MyClassPrx.uncheckedCast(communicator.stringToProxy(ref13)); + return cl13.ice_ping(); + } + ).then( + function() + { + out.writeLine("ok"); + + out.write("testing opaque endpoints... "); + + try + { + // Invalid -x option + communicator.stringToProxy("id:opaque -t 99 -v abc -x abc"); + test(false); + } + catch(ex) + { + test(ex instanceof Ice.EndpointParseException); + } + + try + { + // Missing -t and -v + communicator.stringToProxy("id:opaque"); + test(false); + } + catch(ex) + { + test(ex instanceof Ice.EndpointParseException); + } + + try + { + // Repeated -t + communicator.stringToProxy("id:opaque -t 1 -t 1 -v abc"); + test(false); + } + catch(ex) + { + test(ex instanceof Ice.EndpointParseException); + } + + try + { + // Repeated -v + communicator.stringToProxy("id:opaque -t 1 -v abc -v abc"); + test(false); + } + catch(ex) + { + test(ex instanceof Ice.EndpointParseException); + } + + try + { + // Missing -t + communicator.stringToProxy("id:opaque -v abc"); + test(false); + } + catch(ex) + { + test(ex instanceof Ice.EndpointParseException); + } + + try + { + // Missing -v + communicator.stringToProxy("id:opaque -t 1"); + test(false); + } + catch(ex) + { + test(ex instanceof Ice.EndpointParseException); + } + + try + { + // Missing arg for -t + communicator.stringToProxy("id:opaque -t -v abc"); + test(false); + } + catch(ex) + { + test(ex instanceof Ice.EndpointParseException); + } + + try + { + // Missing arg for -v + communicator.stringToProxy("id:opaque -t 1 -v"); + test(false); + } + catch(ex) + { + test(ex instanceof Ice.EndpointParseException); + } + + try + { + // Not a number for -t + communicator.stringToProxy("id:opaque -t x -v abc"); + test(false); + } + catch(ex) + { + test(ex instanceof Ice.EndpointParseException); + } + + try + { + // < 0 for -t + communicator.stringToProxy("id:opaque -t -1 -v abc"); + test(false); + } + catch(ex) + { + test(ex instanceof Ice.EndpointParseException); + } + + try + { + // Invalid char for -v + communicator.stringToProxy("id:opaque -t 99 -v x?c"); + test(false); + } + catch(ex) + { + test(ex instanceof Ice.EndpointParseException); + } + + var p1, pstr; + if(defaultProtocol == "tcp") + { + // Legal TCP endpoint expressed as opaque endpoint + p1 = communicator.stringToProxy("test -e 1.1:opaque -e 1.0 -t 1 -v CTEyNy4wLjAuMeouAAAQJwAAAA=="); + pstr = communicator.proxyToString(p1); + test(pstr === "test -t -e 1.1:tcp -h 127.0.0.1 -p 12010 -t 10000"); + } + else + { + // Legal WS endpoint expressed as opaque endpoint + p1 = communicator.stringToProxy("test -e 1.1:opaque -t 4 -e 1.0 -v CTEyNy4wLjAuMeouAAAQJwAAAAA="); + pstr = communicator.proxyToString(p1); + test(pstr === "test -t -e 1.1:ws -h 127.0.0.1 -p 12010 -t 10000"); + } + + var p2; + // Opaque endpoint encoded with 1.1 encoding. + if(defaultProtocol == "tcp") + { + p2 = communicator.stringToProxy("test:opaque -e 1.1 -t 1 -v CTEyNy4wLjAuMeouAAAQJwAAAA=="); + test(communicator.proxyToString(p2) === "test -t -e 1.1:tcp -h 127.0.0.1 -p 12010 -t 10000"); + } + else + { + p2 = communicator.stringToProxy("test:opaque -e 1.1 -t 4 -v CTEyNy4wLjAuMeouAAAQJwAAAAA=="); + test(communicator.proxyToString(p2) === "test -t -e 1.1:ws -h 127.0.0.1 -p 12010 -t 10000"); + } + + if(communicator.getProperties().getPropertyAsInt("Ice.IPv6") === 0) + { + var ref = "test:default -p 12010"; + var base = communicator.stringToProxy(ref); + + var ssl = communicator.getProperties().getProperty("Ice.Default.Protocol") === "ssl"; + /* TODO: p1 contains 127.0.0.1 - OK to invoke? + if(!ssl) + { + p1.ice_encodingVersion(Ice.Util.Encoding_1_0).ice_ping(); + } + */ + + // Two legal TCP endpoints expressed as opaque endpoints + if(defaultProtocol == "tcp") + { + p1 = communicator.stringToProxy("test -e 1.0:opaque -e 1.0 -t 1 -v CTEyNy4wLjAuMeouAAAQJwAAAA==:opaque -e 1.0 -t 1 -v CTEyNy4wLjAuMusuAAAQJwAAAA=="); + pstr = communicator.proxyToString(p1); + test(pstr === "test -t -e 1.0:tcp -h 127.0.0.1 -p 12010 -t 10000:tcp -h 127.0.0.2 -p 12011 -t 10000"); + } + else + { + p1 = communicator.stringToProxy("test -e 1.0:opaque -t 4 -e 1.0 -v CTEyNy4wLjAuMeouAAAQJwAAAAA=:opaque -t 4 -e 1.0 -v CTEyNy4wLjAuMusuAAAQJwAAAAA="); + pstr = communicator.proxyToString(p1); + test(pstr === "test -t -e 1.0:ws -h 127.0.0.1 -p 12010 -t 10000:ws -h 127.0.0.2 -p 12011 -t 10000"); + } + + // + // Test that an SSL endpoint and a nonsense endpoint get + // written back out as an opaque endpoint. + // + p1 = communicator.stringToProxy("test -e 1.0:opaque -e 1.0 -t 2 -v CTEyNy4wLjAuMREnAAD/////AA==:opaque -t 99 -e 1.0 -v abch"); + pstr = communicator.proxyToString(p1); + if(!ssl) + { + test(pstr === "test -t -e 1.0:opaque -t 2 -e 1.0 -v CTEyNy4wLjAuMREnAAD/////AA==:opaque -t 99 -e 1.0 -v abch"); + } + else + { + test(pstr === "test -t -e 1.0:ssl -h 127.0.0.1 -p 10001:opaque -t 99 -e 1.0 -v abch"); + } + + // + // Try to invoke on the SSL endpoint to verify that we get a + // NoEndpointException (or ConnectFailedException when + // running with SSL). + // + return p1.ice_encodingVersion(Ice.Encoding_1_0).ice_ping().then( + function(r) + { + test(false); + } + ).exception( + function(ex) + { + if(ex instanceof Ice.NoEndpointException) + { + test(!ssl); + } + else if(ex instanceof Ice.ConnectFailedException) + { + test(ssl); + } + else + { + test(false); + } + return p1; + } + ).then( + function(p1) + { + // + // Test that the proxy with an SSL endpoint and a nonsense + // endpoint (which the server doesn't understand either) can + // be sent over the wire and returned by the server without + // losing the opaque endpoints. + // + var ref = "test -e 1.0:default -p 12010"; + var base = communicator.stringToProxy(ref); + var derived = Test.MyDerivedClassPrx.uncheckedCast(base); + return derived.echo(p1); + } + ).then( + function(p2) + { + var pstr = communicator.proxyToString(p2); + if(!ssl) + { + test(pstr === "test -t -e 1.0:opaque -t 2 -e 1.0 -v CTEyNy4wLjAuMREnAAD/////AA==:opaque -t 99 -e 1.0 -v abch"); + } + else + { + test(pstr === "test -t -e 1.0:ssl -h 127.0.0.1 -p 10001:opaque -t 99 -e 1.0 -v abch"); + } + }); + } + } + ).then( + function() + { + out.writeLine("ok"); + var derived = Test.MyDerivedClassPrx.uncheckedCast(communicator.stringToProxy("test:default -p 12010")); + return derived.shutdown(); + }); + } + + var run = function(out, id) + { + return Promise.try( + function() + { + var communicator = Ice.initialize(id); + return allTests(communicator, out).finally( + function() + { + communicator.destroy(); + }); + + }); + }; + global.__test__ = run; + global.__runServer__ = true; +}(typeof (global) === "undefined" ? window : global)); diff --git a/js/test/Ice/proxy/Makefile b/js/test/Ice/proxy/Makefile new file mode 100644 index 00000000000..8f81ea44140 --- /dev/null +++ b/js/test/Ice/proxy/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/proxy/Makefile.mak b/js/test/Ice/proxy/Makefile.mak new file mode 100644 index 00000000000..61a62482429 --- /dev/null +++ b/js/test/Ice/proxy/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/proxy/Test.ice b/js/test/Ice/proxy/Test.ice new file mode 100644 index 00000000000..02c9a71a505 --- /dev/null +++ b/js/test/Ice/proxy/Test.ice @@ -0,0 +1,29 @@ +// ********************************************************************** +// +// 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/Current.ice> + +module Test +{ + +class MyClass +{ + void shutdown(); + + Ice::Context getContext(); +}; + +class MyDerivedClass extends MyClass +{ + Object* echo(Object* obj); +}; + +}; diff --git a/js/test/Ice/proxy/run.js b/js/test/Ice/proxy/run.js new file mode 100644 index 00000000000..a875f421701 --- /dev/null +++ b/js/test/Ice/proxy/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/proxy/run.py b/js/test/Ice/proxy/run.py new file mode 100755 index 00000000000..d05cbcbf470 --- /dev/null +++ b/js/test/Ice/proxy/run.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# ********************************************************************** +# +# 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("tests with regular server.") +TestUtil.clientServerTest() +print("tests with AMD server.") +TestUtil.clientServerTest(server="serveramd")
\ No newline at end of file diff --git a/js/test/Ice/retry/.gitignore b/js/test/Ice/retry/.gitignore new file mode 100644 index 00000000000..d158d9308ba --- /dev/null +++ b/js/test/Ice/retry/.gitignore @@ -0,0 +1,2 @@ +Test.js +index.html diff --git a/js/test/Ice/retry/Client.js b/js/test/Ice/retry/Client.js new file mode 100644 index 00000000000..fa7a2e72f57 --- /dev/null +++ b/js/test/Ice/retry/Client.js @@ -0,0 +1,137 @@ +// ********************************************************************** +// +// 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 allTests = function(out, communicator) + { + var ref, base1, base2, retry1, retry2; + + var p = new Promise(); + var test = function(b) + { + if(!b) + { + try + { + throw new Error("test failed"); + } + catch(err) + { + p.fail(err); + throw err; + } + } + }; + + Promise.try( + function() + { + out.write("testing stringToProxy... "); + ref = "retry:default -p 12010"; + base1 = communicator.stringToProxy(ref); + test(base1 !== null); + base2 = communicator.stringToProxy(ref); + test(base2 !== null); + out.writeLine("ok"); + out.write("testing checked cast... "); + return Test.RetryPrx.checkedCast(base1); + } + ).then( + function(obj) + { + retry1 = obj; + test(retry1 !== null); + test(retry1.equals(base1)); + return Test.RetryPrx.checkedCast(base2); + } + ).then( + function(obj) + { + retry2 = obj; + test(retry2 !== null); + test(retry2.equals(base2)); + out.writeLine("ok"); + out.write("calling regular operation with first proxy... "); + return retry1.op(false); + } + ).then( + function() + { + out.writeLine("ok"); + out.write("calling operation to kill connection with second proxy... "); + return retry2.op(true); + } + ).then( + function() + { + test(false); + }, + function(ex) + { + test((typeof(window) === undefined && ex instanceof Ice.ConnectionLostException) || + (typeof(window) !== undefined && ex instanceof Ice.SocketException)); + out.writeLine("ok"); + out.write("calling regular operation with first proxy again... "); + return retry1.op(false); + } + ).then( + function() + { + out.writeLine("ok"); + return retry1.shutdown(); + } + ).then( + function() + { + p.succeed(); + }, + function(ex) + { + p.fail(ex); + } + ); + return p; + }; + + var run = function(out, id) + { + return Promise.try( + function() + { + // + // For this test, we want to disable retries. + // + id.properties.setProperty("Ice.RetryIntervals", "-1"); + + // + // We don't want connection warnings because of the timeout + // + id.properties.setProperty("Ice.Warn.Connections", "0"); + 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/retry/Makefile b/js/test/Ice/retry/Makefile new file mode 100644 index 00000000000..8f81ea44140 --- /dev/null +++ b/js/test/Ice/retry/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/retry/Makefile.mak b/js/test/Ice/retry/Makefile.mak new file mode 100644 index 00000000000..61a62482429 --- /dev/null +++ b/js/test/Ice/retry/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/retry/Test.ice b/js/test/Ice/retry/Test.ice new file mode 100644 index 00000000000..e04cbee435b --- /dev/null +++ b/js/test/Ice/retry/Test.ice @@ -0,0 +1,21 @@ +// ********************************************************************** +// +// 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 +{ + +interface Retry +{ + void op(bool kill); + void shutdown(); +}; + +}; diff --git a/js/test/Ice/retry/run.js b/js/test/Ice/retry/run.js new file mode 100644 index 00000000000..a875f421701 --- /dev/null +++ b/js/test/Ice/retry/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/retry/run.py b/js/test/Ice/retry/run.py new file mode 100755 index 00000000000..ee3bc52bf23 --- /dev/null +++ b/js/test/Ice/retry/run.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# ********************************************************************** +# +# 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 + +TestUtil.clientServerTest() diff --git a/js/test/Ice/slicing/Makefile b/js/test/Ice/slicing/Makefile new file mode 100644 index 00000000000..09a8086f4aa --- /dev/null +++ b/js/test/Ice/slicing/Makefile @@ -0,0 +1,22 @@ +# ********************************************************************** +# +# 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 = ../../.. + +include $(top_srcdir)/config/Make.rules.js + +SUBDIRS = exceptions objects + +$(EVERYTHING):: + @for subdir in $(SUBDIRS); \ + do \ + echo "making $@ in $$subdir"; \ + ( cd $$subdir && $(MAKE) $@ ) || exit 1; \ + done + diff --git a/js/test/Ice/slicing/Makefile.mak b/js/test/Ice/slicing/Makefile.mak new file mode 100644 index 00000000000..a15aa203cc9 --- /dev/null +++ b/js/test/Ice/slicing/Makefile.mak @@ -0,0 +1,19 @@ +# ********************************************************************** +# +# 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 = ..\..\.. + +!include $(top_srcdir)\config\Make.rules.mak.js + +SUBDIRS = exceptions objects + +$(EVERYTHING):: + @for %i in ( $(SUBDIRS) ) do \ + @echo "making $@ in %i" && \ + cmd /c "cd %i && $(MAKE) -nologo -f Makefile.mak $@" || exit 1 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") diff --git a/js/test/Ice/slicing/objects/.gitignore b/js/test/Ice/slicing/objects/.gitignore new file mode 100644 index 00000000000..d158d9308ba --- /dev/null +++ b/js/test/Ice/slicing/objects/.gitignore @@ -0,0 +1,2 @@ +Test.js +index.html diff --git a/js/test/Ice/slicing/objects/Client.js b/js/test/Ice/slicing/objects/Client.js new file mode 100644 index 00000000000..e5c5f71690a --- /dev/null +++ b/js/test/Ice/slicing/objects/Client.js @@ -0,0 +1,880 @@ +// ********************************************************************** +// +// 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 PreservedI = function() + { + ++PreservedI.counter; + }; + + PreservedI.prototype = new Test.Preserved(); + + PreservedI.prototype.constructor = PreservedI; + + var PreservedFactoryI = function() + { + }; + + PreservedFactoryI.prototype = new Ice.ObjectFactory(); + + PreservedFactoryI.prototype.constructor = PreservedFactoryI; + + PreservedFactoryI.prototype.create = function(id) + { + if(id === Test.Preserved.ice_staticId()) + { + return new PreservedI(); + } + return null; + }; + + PreservedFactoryI.prototype.destroy = function() + { + }; + + var p = new 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 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 as Object... "); + return prx.SBaseAsObject(); + } + ).then( + function(sb) + { + test(sb !== null); + test(sb.ice_id() == "::Test::SBase"); + test(sb.sb == "SBase.sb"); + out.writeLine("ok"); + out.write("base as base... "); + return prx.SBaseAsSBase(); + } + ).then( + function(sb) + { + test(sb.sb == "SBase.sb"); + out.writeLine("ok"); + out.write("base with known derived as base... "); + return prx.SBSKnownDerivedAsSBase(); + } + ).then( + function(sb) + { + test(sb !== null); + test(sb.sb == "SBSKnownDerived.sb"); + test(sb.sbskd == "SBSKnownDerived.sbskd"); + out.writeLine("ok"); + out.write("base with known derived as known derived... "); + return prx.SBSKnownDerivedAsSBSKnownDerived(); + } + ).then( + function(sb) + { + test(sb.sbskd == "SBSKnownDerived.sbskd"); + out.writeLine("ok"); + out.write("base with unknown derived as base... "); + return prx.SBSUnknownDerivedAsSBase(); + } + ).then( + function(sb) + { + test(sb.sb == "SBSUnknownDerived.sb"); + var p = new Promise(); + if(prx.ice_getEncodingVersion().equals(Ice.Encoding_1_0)) + { + return prx.SBSUnknownDerivedAsSBaseCompact().then( + function(sb) + { + test(sb.sb == "SBSUnknownDerived.sb"); + }, + function(ex) + { + test(ex instanceof Ice.OperationNotExistException); + }); + } + else + { + return prx.SBSUnknownDerivedAsSBaseCompact().then( + failCB, + function(ex) + { + test(ex instanceof Ice.OperationNotExistException || + ex instanceof Ice.NoObjectFactoryException); + }); + } + } + ).then( + function() + { + out.writeLine("ok"); + out.write("unknown with Object as Object... "); + return prx.SUnknownAsObject(); + } + ).then( + function(obj) + { + test(!prx.ice_getEncodingVersion().equals(Ice.Encoding_1_0)); + test(obj instanceof Ice.UnknownSlicedObject); + test(obj.getUnknownTypeId() == "::Test::SUnknown"); + return prx.checkSUnknown(obj); + }, + function(ex) + { + test(ex instanceof Ice.NoObjectFactoryException); + test(prx.ice_getEncodingVersion().equals(Ice.Encoding_1_0)); + } + ).then( + function() + { + out.writeLine("ok"); + out.write("one-element cycle... "); + return prx.oneElementCycle(); + } + ).then( + function(b) + { + test(b !== null); + test(b.ice_id() == "::Test::B"); + test(b.sb == "B1.sb"); + test(b.pb === b); + out.writeLine("ok"); + out.write("two-element cycle... "); + return prx.twoElementCycle(); + } + ).then( + function(b1) + { + test(b1 !== null); + test(b1.ice_id() == "::Test::B"); + test(b1.sb == "B1.sb"); + + var b2 = b1.pb; + test(b2 != null); + test(b2.ice_id() == "::Test::B"); + test(b2.sb == "B2.sb"); + test(b2.pb == b1); + + out.writeLine("ok"); + out.write("known derived pointer slicing as derived... "); + return prx.D1AsD1(); + } + ).then( + function(d1) + { + test(d1 !== null); + test(d1.ice_id() == "::Test::D1"); + test(d1.sb == "D1.sb"); + test(d1.pb !== null); + test(d1.pb !== d1); + + var b2 = d1.pb; + test(b2 !== null); + test(b2.ice_id() == "::Test::B"); + test(b2.sb == "D2.sb"); + test(b2.pb === d1); + + out.writeLine("ok"); + out.write("unknown derived pointer slicing as base... "); + return prx.D2AsB(); + } + ).then( + function(b2) + { + test(b2 != null); + test(b2.ice_id() == "::Test::B"); + test(b2.sb == "D2.sb"); + test(b2.pb !== null); + test(b2.pb !== b2); + + var b1 = b2.pb; + test(b1 !== null); + test(b1.ice_id() == "::Test::D1"); + test(b1.sb == "D1.sb"); + test(b1.pb == b2); + test(b1.sd1 == "D1.sd1"); + test(b1.pd1 === b2); + + out.writeLine("ok"); + out.write("param ptr slicing with known first... "); + return prx.paramTest1(); + } + ).then( + function(b1, b2) + { + test(b1 !== null); + test(b1.ice_id() == "::Test::D1"); + test(b1.sb == "D1.sb"); + test(b1.pb == b2); + test(b1 !== null); + test(b1.sd1 == "D1.sd1"); + test(b1.pd1 === b2); + + test(b2 !== null); + test(b2.ice_id() == "::Test::B"); // No factory, must be sliced + test(b2.sb == "D2.sb"); + test(b2.pb === b1); + out.writeLine("ok"); + out.write("param ptr slicing with unknown first... "); + return prx.paramTest2(); + } + ).then( + function(b2, b1) + { + test(b1 !== null); + test(b1.ice_id() == "::Test::D1"); + test(b1.sb == "D1.sb"); + test(b1.pb === b2); + test(b1 !== null); + test(b1.sd1 == "D1.sd1"); + test(b1.pd1 == b2); + + test(b2 !== null); + test(b2.ice_id() == "::Test::B"); // No factory, must be sliced + test(b2.sb == "D2.sb"); + test(b2.pb == b1); + out.writeLine("ok"); + out.write("return value identity with known first... "); + return prx.returnTest1(); + } + ).then( + function(r, p1, p2) + { + test(r === p1); + out.writeLine("ok"); + out.write("return value identity with unknown first... "); + return prx.returnTest2(); + } + ).then( + function(r, p1, p2) + { + test(r == p1); + out.writeLine("ok"); + out.write("return value identity for input params known first... "); + + var d1 = new Test.D1(); + d1.sb = "D1.sb"; + d1.sd1 = "D1.sd1"; + var d3 = new Test.D3(); + d3.pb = d1; + d3.sb = "D3.sb"; + d3.sd3 = "D3.sd3"; + d3.pd3 = d1; + d1.pb = d3; + d1.pd1 = d3; + + return prx.returnTest3(d1, d3).then( + function(b1) + { + test(b1 !== null); + test(b1.sb == "D1.sb"); + test(b1.ice_id() == "::Test::D1"); + var p1 = b1; + test(p1 !== null); + test(p1.sd1 == "D1.sd1"); + test(p1.pd1 == b1.pb); + + var b2 = b1.pb; + test(b2 !== null); + test(b2.sb == "D3.sb"); + test(b2.ice_id() == "::Test::B"); // Sliced by server + test(b2.pb == b1); + + test(!(b2 instanceof Test.D3)); + test(b1 !== d1); + test(b1 !== d3); + test(b2 !== d1); + test(b2 !== d3); + }); + } + ).then( + function() + { + out.writeLine("ok"); + out.write("return value identity for input params unknown first... "); + + var d1 = new Test.D1(); + d1.sb = "D1.sb"; + d1.sd1 = "D1.sd1"; + var d3 = new Test.D3(); + d3.pb = d1; + d3.sb = "D3.sb"; + d3.sd3 = "D3.sd3"; + d3.pd3 = d1; + d1.pb = d3; + d1.pd1 = d3; + + return prx.returnTest3(d3, d1).then( + function(b1) + { + test(b1 !== null); + test(b1.sb == "D3.sb"); + test(b1.ice_id() == "::Test::B"); // Sliced by server + test(!(b1 instanceof Test.D3)); + + var b2 = b1.pb; + test(b2 !== null); + test(b2.sb == "D1.sb"); + test(b2.ice_id() == "::Test::D1"); + test(b2.pb == b1); + var p3 = b2; + test(p3 !== null); + test(p3.sd1 == "D1.sd1"); + test(p3.pd1 === b1); + + test(b1 !== d1); + test(b1 !== d3); + test(b2 !== d1); + test(b2 !== d3); + }); + } + ).then( + function() + { + out.writeLine("ok"); + out.write("remainder unmarshaling (3 instances)... "); + return prx.paramTest3(); + } + ).then( + function(ret, p1, p2) + { + test(p1 !== null); + test(p1.sb == "D2.sb (p1 1)"); + test(p1.pb === null); + test(p1.ice_id() == "::Test::B"); + + test(p2 !== null); + test(p2.sb == "D2.sb (p2 1)"); + test(p2.pb === null); + test(p2.ice_id() == "::Test::B"); + + test(ret !== null); + test(ret.sb == "D1.sb (p2 2)"); + test(ret.pb === null); + test(ret.ice_id() == "::Test::D1"); + + out.writeLine("ok"); + out.write("remainder unmarshaling (4 instances)... "); + return prx.paramTest4(); + } + ).then( + function(ret, b) + { + test(b !== null); + test(b.sb == "D4.sb (1)"); + test(b.pb === null); + test(b.ice_id() == "::Test::B"); + + test(ret !== null); + test(ret.sb == "B.sb (2)"); + test(ret.pb === null); + test(ret.ice_id() == "::Test::B"); + + out.writeLine("ok"); + out.write("param ptr slicing, instance marshaled in unknown derived as base... "); + + var b1 = new Test.B(); + b1.sb = "B.sb(1)"; + b1.pb = b1; + + var d3 = new Test.D3(); + d3.sb = "D3.sb"; + d3.pb = d3; + d3.sd3 = "D3.sd3"; + d3.pd3 = b1; + + var b2 = new Test.B(); + b2.sb = "B.sb(2)"; + b2.pb = b1; + + return prx.returnTest3(d3, b2); + } + ).then( + function(ret) + { + test(ret !== null); + test(ret.ice_id() == "::Test::B"); + test(ret.sb == "D3.sb"); + test(ret.pb === ret); + + out.writeLine("ok"); + out.write("param ptr slicing, instance marshaled in unknown derived as derived... "); + + var d11 = new Test.D1(); + d11.sb = "D1.sb(1)"; + d11.pb = d11; + d11.sd1 = "D1.sd1(1)"; + + var d3 = new Test.D3(); + d3.sb = "D3.sb"; + d3.pb = d3; + d3.sd3 = "D3.sd3"; + d3.pd3 = d11; + + var d12 = new Test.D1(); + d12.sb = "D1.sb(2)"; + d12.pb = d12; + d12.sd1 = "D1.sd1(2)"; + d12.pd1 = d11; + + return prx.returnTest3(d3, d12); + } + ).then( + function(ret) + { + test(ret !== null); + test(ret.ice_id() == "::Test::B"); + test(ret.sb == "D3.sb"); + test(ret.pb === ret); + + out.writeLine("ok"); + out.write("sequence slicing... "); + + var ss1b = new Test.B(); + ss1b.sb = "B.sb"; + ss1b.pb = ss1b; + + var ss1d1 = new Test.D1(); + ss1d1.sb = "D1.sb"; + ss1d1.sd1 = "D1.sd1"; + ss1d1.pb = ss1b; + + var ss1d3 = new Test.D3(); + ss1d3.sb = "D3.sb"; + ss1d3.sd3 = "D3.sd3"; + ss1d3.pb = ss1b; + + var ss2b = new Test.B(); + ss2b.sb = "B.sb"; + ss2b.pb = ss1b; + + var ss2d1 = new Test.D1(); + ss2d1.sb = "D1.sb"; + ss2d1.sd1 = "D1.sd1"; + ss2d1.pb = ss2b; + + var ss2d3 = new Test.D3(); + ss2d3.sb = "D3.sb"; + ss2d3.sd3 = "D3.sd3"; + ss2d3.pb = ss2b; + + ss1d1.pd1 = ss2b; + ss1d3.pd3 = ss2d1; + + ss2d1.pd1 = ss1d3; + ss2d3.pd3 = ss1d1; + + var ss1 = new Test.SS1(); + ss1.s = []; + ss1.s[0] = ss1b; + ss1.s[1] = ss1d1; + ss1.s[2] = ss1d3; + + var ss2 = new Test.SS2(); + ss2.s = []; + ss2.s[0] = ss2b; + ss2.s[1] = ss2d1; + ss2.s[2] = ss2d3; + + return prx.sequenceTest(ss1, ss2); + } + ).then( + function(ss) + { + test(ss.c1 !== null); + var ss1b = ss.c1.s[0]; + var ss1d1 = ss.c1.s[1]; + test(ss.c2 !== null); + var ss1d3 = ss.c1.s[2]; + + test(ss.c2 !== null); + var ss2b = ss.c2.s[0]; + var ss2d1 = ss.c2.s[1]; + var ss2d3 = ss.c2.s[2]; + + test(ss1b.pb === ss1b); + test(ss1d1.pb === ss1b); + test(ss1d3.pb === ss1b); + + test(ss2b.pb === ss1b); + test(ss2d1.pb === ss2b); + test(ss2d3.pb === ss2b); + + test(ss1b.ice_id() == "::Test::B"); + test(ss1d1.ice_id() == "::Test::D1"); + test(ss1d3.ice_id() == "::Test::B"); + + test(ss2b.ice_id() == "::Test::B"); + test(ss2d1.ice_id() == "::Test::D1"); + test(ss2d3.ice_id() == "::Test::B"); + + out.writeLine("ok"); + out.write("dictionary slicing... "); + + var bin = new Ice.HashMap(); + for(var i = 0; i < 10; ++i) + { + var s = "D1." + i; + var d1 = new Test.D1(); + d1.sb = s; + d1.pb = d1; + d1.sd1 = s; + bin.set(i, d1); + } + return prx.dictionaryTest(bin); + } + ).then( + function(ret, boutH) + { + var i; + test(boutH.size === 10); + for(i = 0; i < 10; ++i) + { + var b = boutH.get(i * 10); + test(b !== null); + var s = "D1." + i; + test(b.sb == s); + test(b.pb !== null); + test(b.pb !== b); + test(b.pb.sb == s); + test(b.pb.pb == b.pb); + } + + test(ret.size === 10); + for(i = 0; i < 10; ++i) + { + var b = ret.get(i * 20); + test(b !== null); + var s = "D1." + (i * 20); + test(b.sb == s); + test(b.pb === (i === 0 ? null : ret.get((i - 1) * 20))); + test(b.sd1 == s); + test(b.pd1 === b); + } + + out.writeLine("ok"); + out.write("base exception thrown as base exception... "); + return prx.throwBaseAsBase(); + } + ).then( + failCB, + function(ex) + { + test(ex instanceof Test.BaseException); + test(ex.ice_name() == "Test::BaseException"); + test(ex.sbe == "sbe"); + test(ex.pb !== null); + test(ex.pb.sb == "sb"); + test(ex.pb.pb == ex.pb); + out.writeLine("ok"); + out.write("derived exception thrown as base exception... "); + return prx.throwDerivedAsBase(); + } + ).then( + failCB, + function(ex) + { + test(ex instanceof Test.DerivedException); + test(ex.ice_name() == "Test::DerivedException"); + test(ex.sbe == "sbe"); + test(ex.pb !== null); + test(ex.pb.sb == "sb1"); + test(ex.pb.pb === ex.pb); + test(ex.sde == "sde1"); + test(ex.pd1 !== null); + test(ex.pd1.sb == "sb2"); + test(ex.pd1.pb === ex.pd1); + test(ex.pd1.sd1 == "sd2"); + test(ex.pd1.pd1 === ex.pd1); + out.writeLine("ok"); + out.write("derived exception thrown as derived exception... "); + + return prx.throwDerivedAsDerived(); + } + ).then( + failCB, + function(ex) + { + test(ex instanceof Test.DerivedException); + test(ex.ice_name() == "Test::DerivedException"); + test(ex.sbe == "sbe"); + test(ex.pb !== null); + test(ex.pb.sb == "sb1"); + test(ex.pb.pb == ex.pb); + test(ex.sde == "sde1"); + test(ex.pd1 !== null); + test(ex.pd1.sb == "sb2"); + test(ex.pd1.pb === ex.pd1); + test(ex.pd1.sd1 == "sd2"); + test(ex.pd1.pd1 === ex.pd1); + + out.writeLine("ok"); + out.write("unknown derived exception thrown as base exception... "); + return prx.throwUnknownDerivedAsBase(); + } + ).then( + failCB, + function(ex) + { + test(ex instanceof Test.BaseException); + test(ex.ice_name() == "Test::BaseException"); + test(ex.sbe == "sbe"); + test(ex.pb !== null); + test(ex.pb.sb == "sb d2"); + test(ex.pb.pb == ex.pb); + + out.writeLine("ok"); + out.write("forward-declared class... "); + return prx.useForward(); + } + ).then( + function(f) + { + test(f !== null); + out.writeLine("ok"); + + out.write("preserved classes... "); + // + // Register a factory in order to substitute our own subclass of Preserved. This provides + // an easy way to determine how many unmarshaled instances currently exist. + // + // TODO: We have to install this now (even though it's not necessary yet), because otherwise + // the Ice run time will install its own internal factory for Preserved upon receiving the + // first instance. + // + communicator.addObjectFactory(new PreservedFactoryI(), Test.Preserved.ice_staticId()); + + // + // Server knows the most-derived class PDerived. + // + var pd = new Test.PDerived(); + pd.pi = 3; + pd.ps = "preserved"; + pd.pb = pd; + + return prx.exchangePBase(pd); + } + ).then( + function(r) + { + var p2 = r; + test(p2.pi === 3); + test(p2.ps == "preserved"); + test(p2.pb === p2); + + // + // Server only knows the base (non-preserved) type, so the object is sliced. + // + var pu = new Test.PCUnknown(); + pu.pi = 3; + pu.pu = "preserved"; + + return prx.exchangePBase(pu); + } + ).then( + function(r) + { + test(!(r instanceof Test.PCUnknown)); + test(r.pi == 3); + + // + // Server only knows the intermediate type Preserved. The object will be sliced to + // Preserved for the 1.0 encoding; otherwise it should be returned intact. + // + var pcd = new Test.PCDerived(); + pcd.pi = 3; + pcd.pbs = [ pcd ]; + + return prx.exchangePBase(pcd); + } + ).then( + function(r) + { + if(prx.ice_getEncodingVersion().equals(Ice.Encoding_1_0)) + { + test(!(r instanceof Test.PCDerived)); + test(r.pi === 3); + } + else + { + var p2 = r; + test(p2.pi === 3); + test(p2.pbs[0] === p2); + } + // + // Server only knows the intermediate type Preserved. The object will be sliced to + // Preserved for the 1.0 encoding; otherwise it should be returned intact. + // + var pcd = new Test.CompactPCDerived(); + pcd.pi = 3; + pcd.pbs = [ pcd ]; + + return prx.exchangePBase(pcd); + } + ).then( + function(r) + { + if(prx.ice_getEncodingVersion().equals(Ice.Encoding_1_0)) + { + test(!(r instanceof Test.CompactPCDerived)); + test(r.pi === 3); + } + else + { + var p2 = r; + test(p2.pi === 3); + test(p2.pbs[0] === p2); + } + + // + // Send an object that will have multiple preserved slices in the server. + // The object will be sliced to Preserved for the 1.0 encoding. + // + var pcd = new Test.PCDerived3(); + pcd.pi = 3; + + // + // Sending more than 254 objects exercises the encoding for object ids. + // + pcd.pbs = new Array(300); + for(var i = 0; i < 300; ++i) + { + var p2 = new Test.PCDerived2(); + p2.pi = i; + p2.pbs = [ null ]; // Nil reference. This slice should not have an indirection table. + p2.pcd2 = i; + pcd.pbs[i] = p2; + } + pcd.pcd2 = pcd.pi; + pcd.pcd3 = pcd.pbs[10]; + + return prx.exchangePBase(pcd); + } + ).then( + function(r) + { + if(prx.ice_getEncodingVersion().equals(Ice.Encoding_1_0)) + { + test(!(r instanceof Test.PCDerived3)); + test(r instanceof Test.Preserved); + test(r.pi === 3); + } + else + { + var p3 = r; + test(p3.pi === 3); + for(var i = 0; i < 300; ++i) + { + var p2 = p3.pbs[i]; + test(p2.pi === i); + test(p2.pbs.length === 1); + test(p2.pbs[0] === null); + test(p2.pcd2 === i); + } + test(p3.pcd2 === p3.pi); + test(p3.pcd3 === p3.pbs[10]); + } + // + // Obtain an object with preserved slices and send it back to the server. + // The preserved slices should be excluded for the 1.0 encoding, otherwise + // they should be included. + // + return prx.PBSUnknownAsPreserved(); + } + ).then( + function(p) + { + return prx.checkPBSUnknown(p).then( + function(r) + { + if(!prx.ice_getEncodingVersion().equals(Ice.Encoding_1_0)) + { + return prx.ice_encodingVersion(Ice.Encoding_1_0).checkPBSUnknown(p); + } + } + ); + } + ).then( + function() + { + 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/objects/Makefile b/js/test/Ice/slicing/objects/Makefile new file mode 100644 index 00000000000..e6856d287c7 --- /dev/null +++ b/js/test/Ice/slicing/objects/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/objects/Makefile.mak b/js/test/Ice/slicing/objects/Makefile.mak new file mode 100644 index 00000000000..ee2ff1de5f1 --- /dev/null +++ b/js/test/Ice/slicing/objects/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/objects/Test.ice b/js/test/Ice/slicing/objects/Test.ice new file mode 100644 index 00000000000..0b3d7685e7c --- /dev/null +++ b/js/test/Ice/slicing/objects/Test.ice @@ -0,0 +1,214 @@ +// ********************************************************************** +// +// 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 +{ + +// +// Duplicate types from Test.ice. We cannot use #include since +// that will use the types from the same prefix. +// + +class SBase +{ + string sb; +}; + +class SBSKnownDerived extends SBase +{ + string sbskd; +}; + +class B +{ + string sb; + B pb; +}; + +class D1 extends B +{ + string sd1; + B pd1; +}; + +sequence<B> BSeq; + +class SS1 +{ + BSeq s; +}; + +class SS2 +{ + BSeq s; +}; + +struct SS3 +{ + SS1 c1; + SS2 c2; +}; + +dictionary<int, B> BDict; + +exception BaseException +{ + string sbe; + B pb; +}; + +exception DerivedException extends BaseException +{ + string sde; + D1 pd1; +}; + +class Forward; /* Forward-declared class defined in another compilation unit */ + +class PBase +{ + int pi; +}; + +sequence<PBase> PBaseSeq; + +["preserve-slice"] +class Preserved extends PBase +{ + string ps; +}; + +class PDerived extends Preserved +{ + PBase pb; +}; + +class CompactPDerived(56) extends Preserved +{ + PBase pb; +}; + +["preserve-slice"] +class PNode +{ + PNode next; +}; + +["preserve-slice"] +exception PreservedException +{ +}; + +["ami", "format:sliced"] +interface TestIntf +{ + Object SBaseAsObject(); + SBase SBaseAsSBase(); + SBase SBSKnownDerivedAsSBase(); + SBSKnownDerived SBSKnownDerivedAsSBSKnownDerived(); + + SBase SBSUnknownDerivedAsSBase(); + + ["format:compact"] SBase SBSUnknownDerivedAsSBaseCompact(); + + Object SUnknownAsObject(); + void checkSUnknown(Object o); + + B oneElementCycle(); + B twoElementCycle(); + B D1AsB(); + D1 D1AsD1(); + B D2AsB(); + + void paramTest1(out B p1, out B p2); + void paramTest2(out B p2, out B p1); + B paramTest3(out B p1, out B p2); + B paramTest4(out B p); + + B returnTest1(out B p1, out B p2); + B returnTest2(out B p2, out B p1); + B returnTest3(B p1, B p2); + + SS3 sequenceTest(SS1 p1, SS2 p2); + + BDict dictionaryTest(BDict bin, out BDict bout); + + PBase exchangePBase(PBase pb); + + Preserved PBSUnknownAsPreserved(); + void checkPBSUnknown(Preserved p); + + ["amd"] Preserved PBSUnknownAsPreservedWithGraph(); + void checkPBSUnknownWithGraph(Preserved p); + + ["amd"] Preserved PBSUnknown2AsPreservedWithGraph(); + void checkPBSUnknown2WithGraph(Preserved p); + + PNode exchangePNode(PNode pn); + + void throwBaseAsBase() throws BaseException; + void throwDerivedAsBase() throws BaseException; + void throwDerivedAsDerived() throws DerivedException; + void throwUnknownDerivedAsBase() throws BaseException; + ["amd"] void throwPreservedException() throws PreservedException; + + void useForward(out Forward f); /* Use of forward-declared class to verify that code is generated correctly. */ + + void shutdown(); +}; + +// +// Types private to the client. +// + +class D3 extends B +{ + string sd3; + B pd3; +}; + +["preserve-slice"] +class PCUnknown extends PBase +{ + string pu; +}; + +class PCDerived extends PDerived +{ + PBaseSeq pbs; +}; + +class PCDerived2 extends PCDerived +{ + int pcd2; +}; + +class PCDerived3 extends PCDerived2 +{ + Object pcd3; +}; + +class CompactPCDerived(57) extends CompactPDerived +{ + PBaseSeq pbs; +}; + +class Hidden +{ + Forward f; +}; + +class Forward +{ + Hidden h; +}; + +}; diff --git a/js/test/Ice/slicing/objects/run.js b/js/test/Ice/slicing/objects/run.js new file mode 100644 index 00000000000..4906b3f4105 --- /dev/null +++ b/js/test/Ice/slicing/objects/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/objects/run.py b/js/test/Ice/slicing/objects/run.py new file mode 100755 index 00000000000..c56059f657d --- /dev/null +++ b/js/test/Ice/slicing/objects/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") diff --git a/js/test/Ice/timeout/.gitignore b/js/test/Ice/timeout/.gitignore new file mode 100644 index 00000000000..d158d9308ba --- /dev/null +++ b/js/test/Ice/timeout/.gitignore @@ -0,0 +1,2 @@ +Test.js +index.html diff --git a/js/test/Ice/timeout/Client.js b/js/test/Ice/timeout/Client.js new file mode 100644 index 00000000000..5e497a6b6d0 --- /dev/null +++ b/js/test/Ice/timeout/Client.js @@ -0,0 +1,432 @@ +// ********************************************************************** +// +// 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 allTests = function(out, communicator) + { + var failCB = function() { test(false); }; + var ref, obj, mult, timeout, to, connection, comm, now; + + var p = new Promise(); + var test = function(b) + { + if(!b) + { + try + { + throw new Error("test failed"); + } + catch(err) + { + p.fail(err); + throw err; + } + } + }; + + Promise.try( + function() + { + ref = "timeout:default -p 12010"; + obj = communicator.stringToProxy(ref); + test(obj !== null); + + mult = 1; + if(communicator.getProperties().getPropertyWithDefault("Ice.Default.Protocol", "tcp") === "ssl") + { + mult = 4; + } + + return Test.TimeoutPrx.checkedCast(obj); + } + ).then( + function(obj) + { + timeout = obj; + test(timeout !== null); + out.write("testing connect timeout... "); + to = Test.TimeoutPrx.uncheckedCast(obj.ice_timeout(500 * mult)); + return to.holdAdapter(2000 * mult); + } + ).then( + function() + { + return to.ice_getConnection(); + } + ).then( + function(con) + { + return con.close(true); // Force a reconnect. + } + ).then( + function() + { + // + // Expect ConnectTimeoutException. + // + return to.op(); + } + ).then( + failCB, + function(ex) + { + test(ex instanceof Ice.ConnectTimeoutException); + return timeout.op(); // Ensure adapter is active. + } + ).then( + function() + { + to = Test.TimeoutPrx.uncheckedCast(obj.ice_timeout(2000 * mult)); + return to.holdAdapter(500 * mult); + } + ).then( + function() + { + return to.ice_getConnection(); + } + ).then( + function(con) + { + return con.close(true); // Force a reconnect. + } + ).then( + function() + { + // + // Expect success. + // + return to.op(); + } + ).then( + function() + { + out.writeLine("ok"); + out.write("testing read timeout... "); + to = Test.TimeoutPrx.uncheckedCast(obj.ice_timeout(500 * mult)); + // + // Expect TimeoutException. + // + return to.sleep(750 * mult); + } + ).then( + failCB, + function(ex) + { + test(ex instanceof Ice.TimeoutException); + return timeout.op(); // Ensure adapter is active. + } + ).then( + function() + { + to = Test.TimeoutPrx.uncheckedCast(obj.ice_timeout(1500 * mult)); + return to.sleep(500 * mult); + } + ).then( + function() + { + out.writeLine("ok"); + out.write("testing write timeout... "); + to = Test.TimeoutPrx.uncheckedCast(obj.ice_timeout(500 * mult)); + return to.holdAdapter(2000 * mult); + } + ).then( + function() + { + var seq = Ice.Buffer.createNative(new Array(100000)); + for(var i = 0; i < seq.length; ++i) + { + seq[i] = 0; + } + // + // Expect TimeoutException. + // + return to.sendData(seq); + } + ).then( + failCB, + function(ex) + { + test(ex instanceof Ice.TimeoutException); + return timeout.op(); // Ensure adapter is active. + } + ).then( + function() + { + // NOTE: 30s timeout is necessary for Firefox/IE on Windows + to = Test.TimeoutPrx.uncheckedCast(obj.ice_timeout(30000 * mult)); + return to.holdAdapter(500 * mult); + } + ).then( + function() + { + var seq; + if(mult === 1) + { + seq = Ice.Buffer.createNative(new Array(512 * 1024)); + } + else + { + seq = Ice.Buffer.createNative(new Array(5 * 1024)); + } + for(var i = 0; i < seq.length; ++i) + { + seq[i] = 0; + } + // + // Expect success. + // + return to.sendData(seq); + } + ).then( + function() + { + out.writeLine("ok"); + out.write("testing close timeout... "); + to = Test.TimeoutPrx.uncheckedCast(obj.ice_timeout(250)); + return to.ice_getConnection(); + } + ).then( + function(con) + { + connection = con; + return timeout.holdAdapter(750); + } + ).then( + function() + { + return connection.close(false); + } + ).then( + function() + { + try + { + connection.getInfo(); // getInfo() doesn't throw in the closing state + } + catch(ex) + { + test(false); + } + } + ).delay(500).then( + function() + { + try + { + connection.getInfo(); + test(false); + } + catch(ex) + { + test(ex instanceof Ice.CloseConnectionException); // Expected + } + return timeout.op(); + } + ).then( + function() + { + out.writeLine("ok"); + out.write("testing timeout overrides... "); + // + // Test Ice.Override.Timeout. This property overrides all + // endpoint timeouts. + // + var initData = new Ice.InitializationData(); + initData.properties = communicator.getProperties().clone(); + if(mult === 1) + { + initData.properties.setProperty("Ice.Override.Timeout", "500"); + } + else + { + initData.properties.setProperty("Ice.Override.Timeout", "2000"); + } + comm = Ice.initialize(initData); + return Test.TimeoutPrx.checkedCast(comm.stringToProxy(ref)); + } + ).then( + function(obj) + { + to = obj; + return to.sleep(750 * mult); + } + ).then( + failCB, + function(ex) + { + test(ex instanceof Ice.TimeoutException); + return timeout.op(); // Ensure adapter is active. + } + ).then( + function() + { + // + // Calling ice_timeout() should have no effect. + // + return Test.TimeoutPrx.checkedCast(to.ice_timeout(1000 * mult)); + } + ).then( + function(obj) + { + to = obj; + return to.sleep(750 * mult); + } + ).then( + failCB, + function(ex) + { + test(ex instanceof Ice.TimeoutException); + return comm.destroy(); + } + ).then( + function() + { + // + // Test Ice.Override.ConnectTimeout. + // + var initData = new Ice.InitializationData(); + initData.properties = communicator.getProperties().clone(); + if(mult === 1) + { + initData.properties.setProperty("Ice.Override.ConnectTimeout", "1000"); + } + else + { + initData.properties.setProperty("Ice.Override.ConnectTimeout", "4000"); + } + comm = Ice.initialize(initData); + to = Test.TimeoutPrx.uncheckedCast(comm.stringToProxy(ref)); + return timeout.holdAdapter(3000 * mult); + } + ).then( + function() + { + return to.op(); + } + ).then( + failCB, + function(ex) + { + test(ex instanceof Ice.ConnectTimeoutException); + return timeout.op(); // Ensure adapter is active. + } + ).then( + function() + { + return timeout.holdAdapter(3000 * mult); + } + ).then( + function() + { + // + // Calling ice_timeout() should have no effect on the connect timeout. + // + to = Test.TimeoutPrx.uncheckedCast(to.ice_timeout(3500 * mult)); + return to.op(); + } + ).then( + failCB, + function(ex) + { + test(ex instanceof Ice.ConnectTimeoutException); + return timeout.op(); // Ensure adapter is active. + } + ).then( + function() + { + return to.op(); // Force connection. + } + ).then( + function() + { + return to.sleep(4000 * mult); + } + ).then( + failCB, + function(ex) + { + test(ex instanceof Ice.TimeoutException); + return comm.destroy(); + } + ).then( + function() + { + // + // Test Ice.Override.CloseTimeout. + // + var initData = new Ice.InitializationData(); + initData.properties = communicator.getProperties().clone(); + initData.properties.setProperty("Ice.Override.CloseTimeout", "200"); + comm = Ice.initialize(initData); + return comm.stringToProxy(ref).ice_getConnection(); + } + ).then( + function(con) + { + return timeout.holdAdapter(750); + } + ).then( + function() + { + now = Date.now(); + return comm.destroy(); + } + ).then( + function() + { + var t = Date.now(); + test(t - now < 500); + out.writeLine("ok"); + return timeout.shutdown(); + } + ).then( + function() + { + p.succeed(); + } + ); + return p; + }; + + var run = function(out, id) + { + return Promise.try( + function() + { + // + // For this test, we want to disable retries. + // + id.properties.setProperty("Ice.RetryIntervals", "-1"); + + // + // We don't want connection warnings because of the timeout + // + id.properties.setProperty("Ice.Warn.Connections", "0"); + 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/timeout/Makefile b/js/test/Ice/timeout/Makefile new file mode 100644 index 00000000000..8f81ea44140 --- /dev/null +++ b/js/test/Ice/timeout/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/timeout/Makefile.mak b/js/test/Ice/timeout/Makefile.mak new file mode 100644 index 00000000000..61a62482429 --- /dev/null +++ b/js/test/Ice/timeout/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/timeout/Test.ice b/js/test/Ice/timeout/Test.ice new file mode 100644 index 00000000000..4fc6fd980fe --- /dev/null +++ b/js/test/Ice/timeout/Test.ice @@ -0,0 +1,28 @@ +// ********************************************************************** +// +// 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 +{ + +sequence<byte> ByteSeq; + +interface Timeout +{ + void op(); + void sendData(ByteSeq seq); + void sleep(int to); + + void holdAdapter(int to); + + void shutdown(); +}; + +}; diff --git a/js/test/Ice/timeout/run.js b/js/test/Ice/timeout/run.js new file mode 100644 index 00000000000..a875f421701 --- /dev/null +++ b/js/test/Ice/timeout/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/timeout/run.py b/js/test/Ice/timeout/run.py new file mode 100755 index 00000000000..ee3bc52bf23 --- /dev/null +++ b/js/test/Ice/timeout/run.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# ********************************************************************** +# +# 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 + +TestUtil.clientServerTest() diff --git a/js/test/Makefile b/js/test/Makefile new file mode 100644 index 00000000000..1a64c13423f --- /dev/null +++ b/js/test/Makefile @@ -0,0 +1,22 @@ +# ********************************************************************** +# +# 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 = .. + +include $(top_srcdir)/config/Make.rules.js + +SUBDIRS = Common Ice Glacier2 + +$(EVERYTHING):: + @for subdir in $(SUBDIRS); \ + do \ + echo "making $@ in $$subdir"; \ + ( cd $$subdir && $(MAKE) $@ ) || exit 1; \ + done + diff --git a/js/test/Makefile.mak b/js/test/Makefile.mak new file mode 100644 index 00000000000..7e87559f53a --- /dev/null +++ b/js/test/Makefile.mak @@ -0,0 +1,19 @@ +# ********************************************************************** +# +# 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 = .. + +!include $(top_srcdir)\config\Make.rules.mak.js + +SUBDIRS = Common Ice Glacier2 + +$(EVERYTHING):: + @for %i in ( $(SUBDIRS) ) do \ + @echo "making $@ in %i" && \ + cmd /c "cd %i && $(MAKE) -nologo -f Makefile.mak $@" || exit 1 |