diff options
author | Matthew Newhook <matthew@zeroc.com> | 2015-03-21 15:35:40 -0230 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2015-03-21 15:35:40 -0230 |
commit | 630a37d2fe66f24518299e705f958b571803c522 (patch) | |
tree | 969723791bdc4d73bb099c19d45554d0ca241ad9 /ruby/test | |
parent | Fix some README.md markdown formatting (diff) | |
download | ice-630a37d2fe66f24518299e705f958b571803c522.tar.bz2 ice-630a37d2fe66f24518299e705f958b571803c522.tar.xz ice-630a37d2fe66f24518299e705f958b571803c522.zip |
py -> python
rb -> ruby
objc -> objective-c
cs -> csharp
Diffstat (limited to 'ruby/test')
93 files changed, 11059 insertions, 0 deletions
diff --git a/ruby/test/Ice/acm/AllTests.rb b/ruby/test/Ice/acm/AllTests.rb new file mode 100644 index 00000000000..3e64c2c3420 --- /dev/null +++ b/ruby/test/Ice/acm/AllTests.rb @@ -0,0 +1,55 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 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. +# +# ********************************************************************** + +def allTests(communicator) + print "testing setACM/getACM... " + STDOUT.flush + + ref = "communicator:default -p 12010" + com = Test::RemoteCommunicatorPrx::uncheckedCast(communicator.stringToProxy(ref)) + + adapter = com.createObjectAdapter(-1, -1, -1) + + initData = Ice::InitializationData.new + initData.properties = communicator.getProperties().clone() + initData.properties.setProperty("Ice.ACM.Timeout", "1") + initData.properties.setProperty("Ice.ACM.Client.Timeout", "15") + initData.properties.setProperty("Ice.ACM.Client.Close", "4") + initData.properties.setProperty("Ice.ACM.Client.Heartbeat", "2") + testCommunicator = Ice::initialize(initData) + proxy = Test::TestIntfPrx::uncheckedCast(testCommunicator.stringToProxy(adapter.getTestIntf().ice_toString())) + proxy.ice_getConnection() + + acm = proxy.ice_getCachedConnection().getACM() + test(acm.timeout == 15) + test(acm.close == Ice::ACMClose::CloseOnIdleForceful) + test(acm.heartbeat == Ice::ACMHeartbeat::HeartbeatOnIdle) + + proxy.ice_getCachedConnection().setACM(Ice::Unset, Ice::Unset, Ice::Unset) + acm = proxy.ice_getCachedConnection().getACM() + test(acm.timeout == 15) + test(acm.close == Ice::ACMClose::CloseOnIdleForceful) + test(acm.heartbeat == Ice::ACMHeartbeat::HeartbeatOnIdle) + + proxy.ice_getCachedConnection().setACM(20, Ice::ACMClose::CloseOnInvocationAndIdle, + Ice::ACMHeartbeat::HeartbeatOnInvocation) + acm = proxy.ice_getCachedConnection().getACM() + test(acm.timeout == 20) + test(acm.close == Ice::ACMClose::CloseOnInvocationAndIdle) + test(acm.heartbeat == Ice::ACMHeartbeat::HeartbeatOnInvocation) + + adapter.deactivate() + testCommunicator.destroy() + puts "ok" + + print "shutting down... " + STDOUT.flush + com.shutdown() + puts "ok" +end diff --git a/ruby/test/Ice/acm/Client.rb b/ruby/test/Ice/acm/Client.rb new file mode 100755 index 00000000000..2676472abe8 --- /dev/null +++ b/ruby/test/Ice/acm/Client.rb @@ -0,0 +1,54 @@ +#!/usr/bin/env ruby +# ********************************************************************** +# +# Copyright (c) 2003-2015 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 'pathname' +require 'Ice' +slice_dir = Ice.getSliceDir +if slice_dir.empty? + fail "Slice directory not found" +end + +Ice::loadSlice("'-I" + slice_dir + "' Test.ice") +require './AllTests' + +def test(b) + if !b + raise RuntimeError, 'test assertion failed' + end +end + +def run(args, communicator) + allTests(communicator) + return true +end + +begin + initData = Ice::InitializationData.new + initData.properties = Ice.createProperties(ARGV) + initData.properties.setProperty("Ice.Warn.Connections", "0") + communicator = Ice.initialize(ARGV, initData) + status = run(ARGV, communicator) +rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false +end + +if communicator + begin + communicator.destroy() + rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false + end +end + +exit(status ? 0 : 1) diff --git a/ruby/test/Ice/acm/Test.ice b/ruby/test/Ice/acm/Test.ice new file mode 100644 index 00000000000..b1c8b749109 --- /dev/null +++ b/ruby/test/Ice/acm/Test.ice @@ -0,0 +1,37 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 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 +{ + void sleep(int seconds); + void sleepAndHold(int seconds); + void interruptSleep(); +}; + +interface RemoteObjectAdapter +{ + TestIntf* getTestIntf(); + void activate(); + void hold(); + void deactivate(); +}; + +interface RemoteCommunicator +{ + RemoteObjectAdapter* createObjectAdapter(int acmTimeout, int close, int heartbeat); + void shutdown(); +}; + +}; + diff --git a/ruby/test/Ice/acm/run.py b/ruby/test/Ice/acm/run.py new file mode 100755 index 00000000000..01b4a35a996 --- /dev/null +++ b/ruby/test/Ice/acm/run.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 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() + +sys.exit(0) diff --git a/ruby/test/Ice/application/Client.rb b/ruby/test/Ice/application/Client.rb new file mode 100755 index 00000000000..59cf30b56a3 --- /dev/null +++ b/ruby/test/Ice/application/Client.rb @@ -0,0 +1,47 @@ +#!/usr/bin/env ruby +# ********************************************************************** +# +# Copyright (c) 2003-2015 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 'Ice' + +class Client < Ice::Application + def interruptCallback(sig) + puts "handling signal " + sig + end + + def run(args) + Ice::Application::ignoreInterrupt + puts "Ignore CTRL+C and the like for 5 seconds (try it!)" + sleep(5) + + Ice::Application::callbackOnInterrupt + + Ice::Application::holdInterrupt + puts "Hold CTRL+C and the like for 5 seconds (try it!)" + sleep(5) + + Ice::Application::releaseInterrupt + puts "Release CTRL+C (any held signals should be released)" + sleep(5) + + Ice::Application::holdInterrupt + puts "Hold CTRL+C and the like for 5 seconds (try it!)" + sleep(5) + + Ice::Application::callbackOnInterrupt + puts "Release CTRL+C (any held signals should be released)" + sleep(5) + + puts "ok" + return true + end +end + +app = Client.new() +exit(app.main(ARGV)) diff --git a/ruby/test/Ice/binding/AllTests.rb b/ruby/test/Ice/binding/AllTests.rb new file mode 100644 index 00000000000..8b376e6ea35 --- /dev/null +++ b/ruby/test/Ice/binding/AllTests.rb @@ -0,0 +1,476 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 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. +# +# ********************************************************************** + +def test(b) + if !b + raise RuntimeError, 'test assertion failed' + end +end + +def createTestIntfPrx(adapters) + endpoints = [] + test = nil + for p in adapters + test = p.getTestIntf() + edpts = test.ice_getEndpoints() + endpoints.concat(edpts) + end + return Test::TestIntfPrx::uncheckedCast(test.ice_endpoints(endpoints)) +end + +def deactivate(com, adapters) + for p in adapters + com.deactivateObjectAdapter(p) + end +end + +def allTests(communicator) + ref = "communicator:default -p 12010" + com = Test::RemoteCommunicatorPrx::uncheckedCast(communicator.stringToProxy(ref)) + + print "testing binding with single endpoint... " + STDOUT.flush + + adapter = com.createObjectAdapter("Adapter", "default") + + test1 = adapter.getTestIntf() + test2 = adapter.getTestIntf() + test(test1.ice_getConnection() == test2.ice_getConnection()) + + test1.ice_ping() + test2.ice_ping() + + com.deactivateObjectAdapter(adapter) + + test3 = Test::TestIntfPrx::uncheckedCast(test1) + test(test3.ice_getConnection() == test1.ice_getConnection()) + test(test3.ice_getConnection() == test2.ice_getConnection()) + + begin + test3.ice_ping() + test(false) + rescue Ice::ConnectionRefusedException + # Expected + end + + puts "ok" + + print "testing binding with multiple endpoints... " + STDOUT.flush + + adapters = [] + adapters.push(com.createObjectAdapter("Adapter11", "default")) + adapters.push(com.createObjectAdapter("Adapter12", "default")) + adapters.push(com.createObjectAdapter("Adapter13", "default")) + + # + # Ensure that when a connection is opened it's reused for new + # proxies and that all endpoints are eventually tried. + # + names = ["Adapter11", "Adapter12", "Adapter13"] + while names.length > 0 + adpts = adapters.clone + + test1 = createTestIntfPrx(adpts) + adpts = adpts.sort_by { rand } + test2 = createTestIntfPrx(adpts) + adpts = adpts.sort_by { rand } + test3 = createTestIntfPrx(adpts) + + test(test1.ice_getConnection() == test2.ice_getConnection()) + test(test2.ice_getConnection() == test3.ice_getConnection()) + + name = test1.getAdapterName() + if names.include?(name) + names.delete(name) + end + test1.ice_getConnection().close(false) + end + + # + # Ensure that the proxy correctly caches the connection (we + # always send the request over the same connection.) + # + for a in adapters + a.getTestIntf().ice_ping() + end + + t = createTestIntfPrx(adapters) + name = t.getAdapterName() + i = 0 + nRetry = 5 + while i < nRetry and t.getAdapterName() == name + i = i + 1 + end + test(i == nRetry) + + for a in adapters + a.getTestIntf().ice_getConnection().close(false) + end + + # + # Deactivate an adapter and ensure that we can still + # establish the connection to the remaining adapters. + # + com.deactivateObjectAdapter(adapters[0]) + names.push("Adapter12") + names.push("Adapter13") + while names.length > 0 + adpts = adapters.clone + + test1 = createTestIntfPrx(adpts) + adpts = adpts.sort_by { rand } + test2 = createTestIntfPrx(adpts) + adpts = adpts.sort_by { rand } + test3 = createTestIntfPrx(adpts) + + test(test1.ice_getConnection() == test2.ice_getConnection()) + test(test2.ice_getConnection() == test3.ice_getConnection()) + + name = test1.getAdapterName() + if names.include?(name) + names.delete(name) + end + test1.ice_getConnection().close(false) + end + + # + # Deactivate an adapter and ensure that we can still + # establish the connection to the remaining adapters. + # + com.deactivateObjectAdapter(adapters[2]) + t = createTestIntfPrx(adapters) + test(t.getAdapterName() == "Adapter12") + + deactivate(com, adapters) + + puts "ok" + + print "testing random endpoint selection... " + STDOUT.flush + + adapters = [] + adapters.push(com.createObjectAdapter("Adapter21", "default")) + adapters.push(com.createObjectAdapter("Adapter22", "default")) + adapters.push(com.createObjectAdapter("Adapter23", "default")) + + t = createTestIntfPrx(adapters) + test(t.ice_getEndpointSelection() == Ice::EndpointSelectionType::Random) + + names = ["Adapter21", "Adapter22", "Adapter23"] + while names.length > 0 + name = t.getAdapterName() + if names.include?(name) + names.delete(name) + end + t.ice_getConnection().close(false) + end + + t = Test::TestIntfPrx::uncheckedCast(t.ice_endpointSelection(Ice::EndpointSelectionType::Random)) + test(t.ice_getEndpointSelection() == Ice::EndpointSelectionType::Random) + + names.push("Adapter21") + names.push("Adapter22") + names.push("Adapter23") + while names.length > 0 + name = t.getAdapterName() + if names.include?(name) + names.delete(name) + end + t.ice_getConnection().close(false) + end + + deactivate(com, adapters) + + puts "ok" + + print "testing ordered endpoint selection... " + STDOUT.flush + + adapters = [] + adapters.push(com.createObjectAdapter("Adapter31", "default")) + adapters.push(com.createObjectAdapter("Adapter32", "default")) + adapters.push(com.createObjectAdapter("Adapter33", "default")) + + t = createTestIntfPrx(adapters) + t = Test::TestIntfPrx::uncheckedCast(t.ice_endpointSelection(Ice::EndpointSelectionType::Ordered)) + test(t.ice_getEndpointSelection() == Ice::EndpointSelectionType::Ordered) + nRetry = 5 + + # + # Ensure that endpoints are tried in order by deactivating the adapters + # one after the other. + # + i = 0 + while i < nRetry and t.getAdapterName() == "Adapter31" + i = i + 1 + end + test(i == nRetry) + com.deactivateObjectAdapter(adapters[0]) + i = 0 + while i < nRetry and t.getAdapterName() == "Adapter32" + i = i + 1 + end + test(i == nRetry) + com.deactivateObjectAdapter(adapters[1]) + i = 0 + while i < nRetry and t.getAdapterName() == "Adapter33" + i = i + 1 + end + test(i == nRetry) + com.deactivateObjectAdapter(adapters[2]) + + begin + t.getAdapterName() + rescue Ice::ConnectionRefusedException + # Expected + end + + endpoints = t.ice_getEndpoints() + + adapters = [] + + # + # Now, re-activate the adapters with the same endpoints in the opposite + # order. + # + adapters.push(com.createObjectAdapter("Adapter36", endpoints[2].toString())) + i = 0 + while i < nRetry and t.getAdapterName() == "Adapter36" + i = i + 1 + end + test(i == nRetry) + t.ice_getConnection().close(false) + adapters.push(com.createObjectAdapter("Adapter35", endpoints[1].toString())) + i = 0 + while i < nRetry and t.getAdapterName() == "Adapter35" + i = i + 1 + end + test(i == nRetry) + t.ice_getConnection().close(false) + adapters.push(com.createObjectAdapter("Adapter34", endpoints[0].toString())) + i = 0 + while i < nRetry and t.getAdapterName() == "Adapter34" + i = i + 1 + end + test(i == nRetry) + + deactivate(com, adapters) + + puts "ok" + + print "testing per request binding with single endpoint... " + STDOUT.flush + + adapter = com.createObjectAdapter("Adapter41", "default") + + test1 = Test::TestIntfPrx::uncheckedCast(adapter.getTestIntf().ice_connectionCached(false)) + test2 = Test::TestIntfPrx::uncheckedCast(adapter.getTestIntf().ice_connectionCached(false)) + test(!test1.ice_isConnectionCached()) + test(!test2.ice_isConnectionCached()) + test(test1.ice_getConnection() == test2.ice_getConnection()) + + test1.ice_ping() + + com.deactivateObjectAdapter(adapter) + + test3 = Test::TestIntfPrx::uncheckedCast(test1) + begin + test(test3.ice_getConnection() == test1.ice_getConnection()) + test(false) + rescue Ice::ConnectionRefusedException + # Expected + end + + puts "ok" + + print "testing per request binding with multiple endpoints... " + STDOUT.flush + + adapters = [] + adapters.push(com.createObjectAdapter("Adapter51", "default")) + adapters.push(com.createObjectAdapter("Adapter52", "default")) + adapters.push(com.createObjectAdapter("Adapter53", "default")) + + t = Test::TestIntfPrx::uncheckedCast(createTestIntfPrx(adapters).ice_connectionCached(false)) + test(!t.ice_isConnectionCached()) + + names = ["Adapter51", "Adapter52", "Adapter53"] + while names.length > 0 + name = t.getAdapterName() + if names.include?(name) + names.delete(name) + end + end + + com.deactivateObjectAdapter(adapters[0]) + + names.push("Adapter52") + names.push("Adapter53") + while names.length > 0 + name = t.getAdapterName() + if names.include?(name) + names.delete(name) + end + end + + com.deactivateObjectAdapter(adapters[2]) + + test(t.getAdapterName() == "Adapter52") + + deactivate(com, adapters) + + puts "ok" + + print "testing per request binding and ordered endpoint selection... " + STDOUT.flush + + adapters = [] + adapters.push(com.createObjectAdapter("Adapter61", "default")) + adapters.push(com.createObjectAdapter("Adapter62", "default")) + adapters.push(com.createObjectAdapter("Adapter63", "default")) + + t = createTestIntfPrx(adapters) + t = Test::TestIntfPrx::uncheckedCast(t.ice_endpointSelection(Ice::EndpointSelectionType::Ordered)) + test(t.ice_getEndpointSelection() == Ice::EndpointSelectionType::Ordered) + t = Test::TestIntfPrx::uncheckedCast(t.ice_connectionCached(false)) + test(!t.ice_isConnectionCached()) + nRetry = 5 + + # + # Ensure that endpoints are tried in order by deactiving the adapters + # one after the other. + # + i = 0 + while i < nRetry and t.getAdapterName() == "Adapter61" + i = i + 1 + end + test(i == nRetry) + com.deactivateObjectAdapter(adapters[0]) + i = 0 + while i < nRetry and t.getAdapterName() == "Adapter62" + i = i + 1 + end + test(i == nRetry) + com.deactivateObjectAdapter(adapters[1]) + i = 0 + while i < nRetry and t.getAdapterName() == "Adapter63" + i = i + 1 + end + test(i == nRetry) + com.deactivateObjectAdapter(adapters[2]) + + begin + t.getAdapterName() + rescue Ice::ConnectionRefusedException + # Expected + end + + endpoints = t.ice_getEndpoints() + + adapters = [] + + # + # Now, re-activate the adapters with the same endpoints in the opposite + # order. + # + adapters.push(com.createObjectAdapter("Adapter66", endpoints[2].toString())) + i = 0 + while i < nRetry and t.getAdapterName() == "Adapter66" + i = i + 1 + end + test(i == nRetry) + adapters.push(com.createObjectAdapter("Adapter65", endpoints[1].toString())) + i = 0 + while i < nRetry and t.getAdapterName() == "Adapter65" + i = i + 1 + end + test(i == nRetry) + adapters.push(com.createObjectAdapter("Adapter64", endpoints[0].toString())) + i = 0 + while i < nRetry and t.getAdapterName() == "Adapter64" + i = i + 1 + end + test(i == nRetry) + + deactivate(com, adapters) + + puts "ok" + + print "testing endpoint mode filtering... " + STDOUT.flush + + adapters = [] + adapters.push(com.createObjectAdapter("Adapter71", "default")) + adapters.push(com.createObjectAdapter("Adapter72", "udp")) + + t = createTestIntfPrx(adapters) + test(t.getAdapterName() == "Adapter71") + + testUDP = Test::TestIntfPrx::uncheckedCast(t.ice_datagram()) + test(t.ice_getConnection() != testUDP.ice_getConnection()) + begin + testUDP.getAdapterName() + rescue Ice::TwowayOnlyException + # Expected + end + + puts "ok" + + if communicator.getProperties().getProperty("Ice.Plugin.IceSSL").length > 0 + print "testing unsecure vs. secure endpoints... " + STDOUT.flush + + adapters = [] + adapters.push(com.createObjectAdapter("Adapter81", "ssl")) + adapters.push(com.createObjectAdapter("Adapter82", "tcp")) + + t = createTestIntfPrx(adapters) + for i in 0...5 + test(t.getAdapterName() == "Adapter82") + t.ice_getConnection().close(false) + end + + testSecure = Test::TestIntfPrx::uncheckedCast(t.ice_secure(true)) + test(testSecure.ice_isSecure()) + testSecure = Test::TestIntfPrx::uncheckedCast(t.ice_secure(false)) + test(!testSecure.ice_isSecure()) + testSecure = Test::TestIntfPrx::uncheckedCast(t.ice_secure(true)) + test(testSecure.ice_isSecure()) + test(t.ice_getConnection() != testSecure.ice_getConnection()) + + com.deactivateObjectAdapter(adapters[1]) + + for i in 0...5 + test(t.getAdapterName() == "Adapter81") + t.ice_getConnection().close(false) + end + + com.createObjectAdapter("Adapter83", (t.ice_getEndpoints()[1]).toString()) # Reactive tcp OA. + + for i in 0...5 + test(t.getAdapterName() == "Adapter83") + t.ice_getConnection().close(false) + end + + com.deactivateObjectAdapter(adapters[0]) + begin + testSecure.ice_ping() + test(false) + rescue Ice::ConnectionRefusedException + # Expected + end + + deactivate(com, adapters) + + puts "ok" + end + + com.shutdown() +end diff --git a/ruby/test/Ice/binding/Client.rb b/ruby/test/Ice/binding/Client.rb new file mode 100755 index 00000000000..8f0d1decce8 --- /dev/null +++ b/ruby/test/Ice/binding/Client.rb @@ -0,0 +1,41 @@ +#!/usr/bin/env ruby +# ********************************************************************** +# +# Copyright (c) 2003-2015 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 'pathname' +require 'Ice' + +Ice::loadSlice('Test.ice') +require './AllTests' + +def run(args, communicator) + allTests(communicator) + return true +end + +begin + communicator = Ice::initialize(ARGV) + status = run(ARGV, communicator) +rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false +end + +if communicator + begin + communicator.destroy() + rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false + end +end + +exit(status ? 0 : 1) diff --git a/ruby/test/Ice/binding/Test.ice b/ruby/test/Ice/binding/Test.ice new file mode 100644 index 00000000000..bd7cbe1a971 --- /dev/null +++ b/ruby/test/Ice/binding/Test.ice @@ -0,0 +1,36 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 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/ruby/test/Ice/binding/run.py b/ruby/test/Ice/binding/run.py new file mode 100755 index 00000000000..3489faf2571 --- /dev/null +++ b/ruby/test/Ice/binding/run.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 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/ruby/test/Ice/checksum/AllTests.rb b/ruby/test/Ice/checksum/AllTests.rb new file mode 100644 index 00000000000..1ee8a6ad3d9 --- /dev/null +++ b/ruby/test/Ice/checksum/AllTests.rb @@ -0,0 +1,64 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 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. +# +# ********************************************************************** + +def test(b) + if !b + raise RuntimeError, 'test assertion failed' + end +end + +def allTests(communicator) + ref = "test:default -p 12010" + base = communicator.stringToProxy(ref) + test(base) + + checksum = Test::ChecksumPrx::checkedCast(base) + test(checksum) + + # + # Verify that no checksums are present for local types. + # + print "testing checksums... " + STDOUT.flush + test(Ice::SliceChecksums.length > 0) + for i in Ice::SliceChecksums.keys + test(!i.include?("Local")) + end + + # + # Get server's Slice checksums. + # + d = checksum.getSliceChecksums() + + # + # Compare the checksums. For a type FooN whose name ends in an integer N, + # we assume that the server's type does not change for N = 1, and does + # change for N > 1. + # + patt = Regexp.new("\\d+") + for i in d.keys + n = 0 + m = patt.match(i) + if m + n = i[m.begin(0)...i.length].to_i + end + + test(Ice::SliceChecksums.has_key?(i)) + + if n <= 1 + test(Ice::SliceChecksums[i] == d[i]) + else + test(Ice::SliceChecksums[i] != d[i]) + end + end + + puts "ok" + + return checksum +end diff --git a/ruby/test/Ice/checksum/CTypes.ice b/ruby/test/Ice/checksum/CTypes.ice new file mode 100644 index 00000000000..1dfc5f719d5 --- /dev/null +++ b/ruby/test/Ice/checksum/CTypes.ice @@ -0,0 +1,634 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 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 +{ + +// +// TEST: Same +// +const int IntConst1 = 100; + +// +// TEST: Value changed +// +const int IntConst2 = 100; + +// +// TEST: Type changed +// +const int IntConst3 = 100; + +// +// TEST: Same +// +enum Enum1 { Enum11, Enum12, Enum13 }; + +// +// TEST: Add enumerator +// +enum Enum2 { Enum21, Enum22, Enum23 }; + +// +// TEST: Remove enumerator +// +enum Enum3 { Enum31, Enum32, Enum33 }; + +// +// TEST: Change to a different type +// +enum Enum4 { Enum41, Enum42, Enum43 }; + +// +// TEST: Enum with explicit values. +// +enum EnumExplicit0 { EnumExplicit01 = 1, EnumExplicit02 = 2, EnumExplicit03 = 3 }; + +// +// TEST: Enum with same explicit values, different order. +// +enum EnumExplicit1 { EnumExplicit11 = 1, EnumExplicit12 = 2, EnumExplicit13 = 3 }; + +// +// TEST: Enum with different explicit values. +// +enum EnumExplicit2 { EnumExplicit21 = 1, EnumExplicit22 = 2, EnumExplicit23 = 3}; + +// +// TEST: Enum with explicit values, removed enumerator. +// +enum EnumExplicit3 { EnumExplicit31 = 1, EnumExplicit32 = 2, EnumExplicit33 = 3}; + +// +// TEST: Same +// +sequence<int> Sequence1; + +// +// TEST: Change sequence type +// +sequence<int> Sequence2; + +// +// TEST: Change to a different type +// +sequence<int> Sequence3; + +// +// TEST: Same +// +dictionary<string, int> Dictionary1; + +// +// TEST: Change key type +// +dictionary<string, int> Dictionary2; + +// +// TEST: Change value type +// +dictionary<string, int> Dictionary3; + +// +// TEST: Change to a different type +// +dictionary<string, int> Dictionary4; + +// +// TEST: Same +// +struct Struct1 +{ + string str; + bool b; +}; + +// +// TEST: Add member +// +struct Struct2 +{ + string str; + bool b; +}; + +// +// TEST: Change member type +// +struct Struct3 +{ + string str; + bool b; +}; + +// +// TEST: Remove member +// +struct Struct4 +{ + string str; + bool b; +}; + +// +// TEST: Change to a different type +// +struct Struct5 +{ + string str; + bool b; +}; + +// +// TEST: Same +// +interface Interface1 +{ +}; + +// +// TEST: Change interface to class +// +interface Interface2 +{ +}; + +// +// TEST: Add base interface +// +interface Interface3 +{ +}; + +// +// TEST: Add operation +// +interface Interface4 +{ +}; + +// +// TEST: Same +// +class EmptyClass1 +{ +}; + +// +// TEST: Add data member +// +class EmptyClass2 +{ +}; + +// +// TEST: Add operation +// +class EmptyClass3 +{ +}; + +// +// TEST: Add base class +// +class EmptyClass4 +{ +}; + +// +// TEST: Add interface +// +class EmptyClass5 +{ +}; + +// +// TEST: Same +// +class SimpleClass1 +{ + string str; + float f; +}; + +// +// TEST: Add operation +// +class SimpleClass2 +{ + string str; + float f; +}; + +// +// TEST: Rename member +// +class SimpleClass3 +{ + string str; + float f; +}; + +// +// TEST: Add member +// +class SimpleClass4 +{ + string str; + float f; +}; + +// +// TEST: Remove member +// +class SimpleClass5 +{ + string str; + float f; +}; + +// +// TEST: Reorder members +// +class SimpleClass6 +{ + string str; + float f; +}; + +// +// TEST: Change member type +// +class SimpleClass7 +{ + string str; + float f; +}; + +// +// TEST: Same +// +exception Exception1 +{ + string str; + bool b; +}; + +// +// TEST: Add member +// +exception Exception2 +{ + string str; + bool b; +}; + +// +// TEST: Change member type +// +exception Exception3 +{ + string str; + bool b; +}; + +// +// TEST: Remove member +// +exception Exception4 +{ + string str; + bool b; +}; + +// +// TEST: Add base exception +// +exception Exception5 +{ +}; + +// +// TEST: Change to a different type +// +exception Exception6 +{ + string str; + bool b; +}; + +// +// TEST: Exception with optional members. +// +exception OptionalEx0 +{ + string firstName; + optional(1) string secondName; + optional(2) string emailAddress; +}; + +// +// TEST: Exception with optional members, different order, same tags. +// +exception OptionalEx1 +{ + string firstName; + optional(1) string secondName; + optional(2) string emailAddress; +}; + +// +// TEST: Exception with different optional members. +// +exception OptionalEx2 +{ + string firstName; + string secondName; + optional(1) string emailAddress; +}; + +// +// TEST: Exception with different optional members. +// +exception OptionalEx3 +{ + string firstName; + optional(1) string secondName; + optional(2) string emailAddress; +}; + +// +// TEST: Exception with optional members using different tags. +// +exception OptionalEx4 +{ + string firstName; + optional(1) string secondName; + optional(2) string emailAddress; +}; + +// +// TEST: Same +// +class BaseClass1 +{ + void baseOp1(); + void baseOp2(int i, out string s) throws Exception1; +}; + +// +// TEST: Change return type +// +class BaseClass2 +{ + void baseOp(); + void baseOp2(int i, out string s) throws Exception1; +}; + +// +// TEST: Add parameter +// +class BaseClass3 +{ + void baseOp(); + void baseOp2(int i, out string s) throws Exception1; +}; + +// +// TEST: Add exception +// +class BaseClass4 +{ + void baseOp(); + void baseOp2(int i, out string s) throws Exception1; +}; + +// +// TEST: Change out parameter to in parameter +// +class BaseClass5 +{ + void baseOp(); + void baseOp2(int i, out string s) throws Exception1; +}; + +// +// TEST: Remove parameter +// +class BaseClass6 +{ + void baseOp(); + void baseOp2(int i, out string s) throws Exception1; +}; + +// +// TEST: Remove exception +// +class BaseClass7 +{ + void baseOp(); + void baseOp2(int i, out string s) throws Exception1; +}; + +// +// TEST: Remove operation +// +class BaseClass8 +{ + void baseOp(); + void baseOp2(int i, out string s) throws Exception1; +}; + +// +// TEST: Add base class +// +class BaseClass9 +{ + void baseOp(); + void baseOp2(int i, out string s) throws Exception1; +}; + +// +// TEST: Add interface +// +class BaseClass10 +{ + void baseOp(); + void baseOp2(int i, out string s) throws Exception1; +}; + +// +// TEST: Add base class and interface +// +class BaseClass11 +{ + void baseOp(); + void baseOp2(int i, out string s) throws Exception1; +}; + +// +// TEST: Class with compact id +// +class Compact1(1) +{ + void baseOp(); + void baseOp2(int i, out string s) throws Exception1; +}; + +// +// TEST: Derived from class with compact id +// +class Derived1 extends Compact1 +{ +}; + +// +// TEST: Same class names but different compact id +// +class Compact2(2) +{ + void baseOp(); + void baseOp2(int i, out string s) throws Exception1; +}; + +// +// TEST: Class with optional members. +// +class Optional0 +{ + string firstName; + optional(1) string secondName; + optional(2) string emailAddress; +}; + +// +// TEST: Class with optional members, different order, same tags. +// +class Optional1 +{ + string firstName; + optional(1) string secondName; + optional(2) string emailAddress; +}; + +// +// TEST: Class with different optional members. +// +class Optional2 +{ + string firstName; + string secondName; + optional(1) string emailAddress; +}; + +// +// TEST: Class with different optional members. +// +class Optional3 +{ + string firstName; + optional(1) string secondName; + optional(2) string emailAddress; +}; + +// +// TEST: Class with optional members using different tags. +// +class Optional4 +{ + string firstName; + optional(1) string secondName; + optional(2) string emailAddress; +}; + +// +// TEST: Class with optional parameters. +// +class OptionalParameters0 +{ + void op1(string firstName, optional(1) string secondName, + optional(2) string emailAddress); +}; + +// +// TEST: Class with optional parameters, different order. +// +class OptionalParameters1 +{ + void op1(string firstName, optional(1) string secondName, + optional(2) string emailAddress); +}; + +// +// TEST: Class with optional parameters, different tags. +// +class OptionalParameters2 +{ + void op1(string firstName, optional(1) string emailAddress, + optional(2) string secondName); +}; + +// +// TEST: Class with different optional parameters. +// +class OptionalParameters3 +{ + void op1(string firstName, optional(1) string emailAddress, + string secondName); +}; + +// +// TEST: Class with optional return type. +// +class OptionalReturn0 +{ + optional(1) int op(); +}; + +// +// TEST: Class that changes optional return type. +// +class OptionalReturn2 +{ + optional(1) int op(); +}; + +// +// TEST: Local +// +local enum LocalEnum { LocalEnum1, LocalEnum2, LocalEnum3 }; + +// +// TEST: Local +// +local sequence<string> LocalSequence; + +// +// TEST: Local +// +local dictionary<string, string> LocalDictionary; + +// +// TEST: Local +// +local struct LocalStruct +{ + string str; +}; + +// +// TEST: Local +// +local class LocalClass +{ +}; + +}; diff --git a/ruby/test/Ice/checksum/Client.rb b/ruby/test/Ice/checksum/Client.rb new file mode 100755 index 00000000000..79dc3fdf77a --- /dev/null +++ b/ruby/test/Ice/checksum/Client.rb @@ -0,0 +1,47 @@ +#!/usr/bin/env ruby +# ********************************************************************** +# +# Copyright (c) 2003-2015 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 'pathname' +require 'Ice' + +slice_dir = Ice.getSliceDir +if slice_dir.empty? + fail "Slice directory not found" +end + +Ice::loadSlice("'-I" + slice_dir + "' --checksum Test.ice CTypes.ice") +require './AllTests' + +def run(args, communicator) + checksum = allTests(communicator) + checksum.shutdown() + return true +end + +begin + communicator = Ice.initialize(ARGV) + status = run(ARGV, communicator) +rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false +end + +if communicator + begin + communicator.destroy() + rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false + end +end + +exit(status ? 0 : 1) diff --git a/ruby/test/Ice/checksum/Test.ice b/ruby/test/Ice/checksum/Test.ice new file mode 100644 index 00000000000..21639acff0f --- /dev/null +++ b/ruby/test/Ice/checksum/Test.ice @@ -0,0 +1,24 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 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/SliceChecksumDict.ice> + +module Test +{ + +interface Checksum +{ + idempotent Ice::SliceChecksumDict getSliceChecksums(); + + void shutdown(); +}; + +}; diff --git a/ruby/test/Ice/checksum/run.py b/ruby/test/Ice/checksum/run.py new file mode 100755 index 00000000000..c53680b6c1b --- /dev/null +++ b/ruby/test/Ice/checksum/run.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 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(server='server/server') + diff --git a/ruby/test/Ice/defaultValue/AllTests.rb b/ruby/test/Ice/defaultValue/AllTests.rb new file mode 100644 index 00000000000..59f9de1d384 --- /dev/null +++ b/ruby/test/Ice/defaultValue/AllTests.rb @@ -0,0 +1,181 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 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. +# +# ********************************************************************** + +def allTests() + print "testing default values... " + STDOUT.flush + + v = Test::Struct1.new + test(!v.boolFalse) + test(v.boolTrue) + test(v.b == 254) + test(v.s == 16000) + test(v.i == 3) + test(v.l == 4) + test(v.f == 5.1) + test(v.d == 6.2) + test(v.str == "foo \\ \"bar\n \r\n\t\v\f\a\b? \007 \x07") + 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 == '') + test(v.zeroI == 0) + test(v.zeroL == 0) + test(v.zeroF == 0) + test(v.zeroDotF == 0) + test(v.zeroD == 0) + test(v.zeroDotD == 0) + + v = Test::Struct2.new + test(v.boolTrue == Test::ConstBool) + test(v.b == Test::ConstByte) + test(v.s == Test::ConstShort) + test(v.i == Test::ConstInt) + test(v.l == 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) + test(v.zeroI == Test::ConstZeroI) + test(v.zeroL == Test::ConstZeroL) + test(v.zeroF == Test::ConstZeroF) + test(v.zeroDotF == Test::ConstZeroDotF) + test(v.zeroD == Test::ConstZeroD) + test(v.zeroDotD == Test::ConstZeroDotD) + + v = Test::Base.new + test(!v.boolFalse) + test(v.boolTrue) + test(v.b == 1) + test(v.s == 2) + test(v.i == 3) + test(v.l == 4) + test(v.f == 5.1) + test(v.d == 6.2) + test(v.str == "foo \\ \"bar\n \r\n\t\v\f\a\b? \007 \x07") + test(v.noDefault == '') + test(v.zeroI == 0) + test(v.zeroL == 0) + test(v.zeroF == 0) + test(v.zeroDotF == 0) + test(v.zeroD == 0) + test(v.zeroDotD == 0) + + v = Test::Derived.new + test(!v.boolFalse) + test(v.boolTrue) + test(v.b == 1) + test(v.s == 2) + test(v.i == 3) + test(v.l == 4) + test(v.f == 5.1) + test(v.d == 6.2) + test(v.str == "foo \\ \"bar\n \r\n\t\v\f\a\b? \007 \x07") + 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 == '') + test(v.zeroI == 0) + test(v.zeroL == 0) + test(v.zeroF == 0) + test(v.zeroDotF == 0) + test(v.zeroD == 0) + test(v.zeroDotD == 0) + + v = Test::BaseEx.new + test(!v.boolFalse) + test(v.boolTrue) + test(v.b == 1) + test(v.s == 2) + test(v.i == 3) + test(v.l == 4) + test(v.f == 5.1) + test(v.d == 6.2) + test(v.str == "foo \\ \"bar\n \r\n\t\v\f\a\b? \007 \x07") + test(v.noDefault == '') + test(v.zeroI == 0) + test(v.zeroL == 0) + test(v.zeroF == 0) + test(v.zeroDotF == 0) + test(v.zeroD == 0) + test(v.zeroDotD == 0) + + v = Test::DerivedEx.new + test(!v.boolFalse) + test(v.boolTrue) + test(v.b == 1) + test(v.s == 2) + test(v.i == 3) + test(v.l == 4) + test(v.f == 5.1) + test(v.d == 6.2) + test(v.str == "foo \\ \"bar\n \r\n\t\v\f\a\b? \007 \x07") + test(v.noDefault == '') + 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 == '') + test(v.zeroI == 0) + test(v.zeroL == 0) + test(v.zeroF == 0) + test(v.zeroDotF == 0) + test(v.zeroD == 0) + test(v.zeroDotD == 0) + + puts "ok" + + print "testing default constructor... " + STDOUT.flush + + v = Test::StructNoDefaults.new + test(v.bo == false) + test(v.b == 0) + test(v.s == 0) + test(v.i == 0) + test(v.l == 0) + test(v.f == 0.0) + test(v.d == 0.0) + test(v.str == '') + test(v.c1 == Test::Color::Red) + test(v.bs == nil) + test(v.is == nil) + test(v.st.instance_of?(Test::InnerStruct)); + test(v.dict == nil); + + e = Test::ExceptionNoDefaults.new + test(e.str == '') + test(e.c1 == Test::Color::Red) + test(e.bs == nil) + test(e.st.instance_of?(Test::InnerStruct)); + test(e.dict == nil); + + c = Test::ClassNoDefaults.new + test(c.str == '') + test(c.c1 == Test::Color::Red) + test(c.bs == nil) + test(c.st.instance_of?(Test::InnerStruct)); + test(c.dict == nil); + + puts("ok") + +end diff --git a/ruby/test/Ice/defaultValue/Client.rb b/ruby/test/Ice/defaultValue/Client.rb new file mode 100755 index 00000000000..7d36cdd2cb5 --- /dev/null +++ b/ruby/test/Ice/defaultValue/Client.rb @@ -0,0 +1,36 @@ +#!/usr/bin/env ruby +# ********************************************************************** +# +# Copyright (c) 2003-2015 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 'pathname' +require 'Ice' + +Ice::loadSlice('Test.ice') +require './AllTests' + +def test(b) + if !b + raise RuntimeError, 'test assertion failed' + end +end + +def run(args) + allTests() + return true +end + +begin + status = run(ARGV) +rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false +end + +exit(status ? 0 : 1) diff --git a/ruby/test/Ice/defaultValue/Test.ice b/ruby/test/Ice/defaultValue/Test.ice new file mode 100644 index 00000000000..af768270ed7 --- /dev/null +++ b/ruby/test/Ice/defaultValue/Test.ice @@ -0,0 +1,207 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 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\? \007 \x07"; + 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\? \007 \x07"; +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; +}; + +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\? \007 \x07"; + 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\? \007 \x07"; + 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; +}; + +sequence<byte> ByteSeq; +sequence<int> IntSeq; +dictionary<int, string> IntStringDict; + +struct InnerStruct +{ + int a; +}; + +struct StructNoDefaults +{ + bool bo; + byte b; + short s; + int i; + long l; + float f; + double d; + string str; + Color c1; + ByteSeq bs; + IntSeq is; + IntStringDict dict; + InnerStruct st; +}; + +exception ExceptionNoDefaultsBase +{ + string str; + Color c1; + ByteSeq bs; +}; + +exception ExceptionNoDefaults extends ExceptionNoDefaultsBase +{ + InnerStruct st; + IntStringDict dict; +}; + +class ClassNoDefaultsBase +{ + string str; + Color c1; + ByteSeq bs; +}; + +class ClassNoDefaults extends ClassNoDefaultsBase +{ + InnerStruct st; + IntStringDict dict; +}; + +}; diff --git a/ruby/test/Ice/defaultValue/run.py b/ruby/test/Ice/defaultValue/run.py new file mode 100755 index 00000000000..ed19d61bed6 --- /dev/null +++ b/ruby/test/Ice/defaultValue/run.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 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 + +sys.stdout.write("starting client... ") +sys.stdout.flush() +clientProc = TestUtil.startClient("Client.rb", startReader = False) +print("ok") +clientProc.startReader() +clientProc.waitTestSuccess() diff --git a/ruby/test/Ice/enums/AllTests.rb b/ruby/test/Ice/enums/AllTests.rb new file mode 100644 index 00000000000..c2674d4fbed --- /dev/null +++ b/ruby/test/Ice/enums/AllTests.rb @@ -0,0 +1,129 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 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. +# +# ********************************************************************** + +def test(b) + if !b + raise RuntimeError, 'test assertion failed' + end +end + +def allTests(communicator) + ref = "test:default -p 12010" + base = communicator.stringToProxy(ref) + test(base) + + proxy = Test::TestIntfPrx::checkedCast(base) + test(proxy) + + print "testing enum values... " + STDOUT.flush + + test(Test::ByteEnum::Benum1.to_i == 0); + test(Test::ByteEnum::Benum2.to_i == 1); + test(Test::ByteEnum::Benum3.to_i == Test::ByteConst1); + test(Test::ByteEnum::Benum4.to_i == Test::ByteConst1 + 1); + test(Test::ByteEnum::Benum5.to_i == Test::ShortConst1); + test(Test::ByteEnum::Benum6.to_i == Test::ShortConst1 + 1); + test(Test::ByteEnum::Benum7.to_i == Test::IntConst1); + test(Test::ByteEnum::Benum8.to_i == Test::IntConst1 + 1); + test(Test::ByteEnum::Benum9.to_i == Test::LongConst1); + test(Test::ByteEnum::Benum10.to_i == Test::LongConst1 + 1); + test(Test::ByteEnum::Benum11.to_i == Test::ByteConst2); + + test(Test::ByteEnum::from_int(0) == Test::ByteEnum::Benum1); + test(Test::ByteEnum::from_int(1) == Test::ByteEnum::Benum2); + test(Test::ByteEnum::from_int(Test::ByteConst1) == Test::ByteEnum::Benum3); + test(Test::ByteEnum::from_int(Test::ByteConst1 + 1) == Test::ByteEnum::Benum4); + test(Test::ByteEnum::from_int(Test::ShortConst1) == Test::ByteEnum::Benum5); + test(Test::ByteEnum::from_int(Test::ShortConst1 + 1) == Test::ByteEnum::Benum6); + test(Test::ByteEnum::from_int(Test::IntConst1) == Test::ByteEnum::Benum7); + test(Test::ByteEnum::from_int(Test::IntConst1 + 1) == Test::ByteEnum::Benum8); + test(Test::ByteEnum::from_int(Test::LongConst1) == Test::ByteEnum::Benum9); + test(Test::ByteEnum::from_int(Test::LongConst1 + 1) == Test::ByteEnum::Benum10); + test(Test::ByteEnum::from_int(Test::ByteConst2) == Test::ByteEnum::Benum11); + + test(Test::ShortEnum::Senum1.to_i == 3); + test(Test::ShortEnum::Senum2.to_i == 4); + test(Test::ShortEnum::Senum3.to_i == Test::ByteConst1); + test(Test::ShortEnum::Senum4.to_i == Test::ByteConst1 + 1); + test(Test::ShortEnum::Senum5.to_i == Test::ShortConst1); + test(Test::ShortEnum::Senum6.to_i == Test::ShortConst1 + 1); + test(Test::ShortEnum::Senum7.to_i == Test::IntConst1); + test(Test::ShortEnum::Senum8.to_i == Test::IntConst1 + 1); + test(Test::ShortEnum::Senum9.to_i == Test::LongConst1); + test(Test::ShortEnum::Senum10.to_i == Test::LongConst1 + 1); + test(Test::ShortEnum::Senum11.to_i == Test::ShortConst2); + + test(Test::ShortEnum::from_int(3) == Test::ShortEnum::Senum1); + test(Test::ShortEnum::from_int(4) == Test::ShortEnum::Senum2); + test(Test::ShortEnum::from_int(Test::ByteConst1) == Test::ShortEnum::Senum3); + test(Test::ShortEnum::from_int(Test::ByteConst1 + 1) == Test::ShortEnum::Senum4); + test(Test::ShortEnum::from_int(Test::ShortConst1) == Test::ShortEnum::Senum5); + test(Test::ShortEnum::from_int(Test::ShortConst1 + 1) == Test::ShortEnum::Senum6); + test(Test::ShortEnum::from_int(Test::IntConst1) == Test::ShortEnum::Senum7); + test(Test::ShortEnum::from_int(Test::IntConst1 + 1) == Test::ShortEnum::Senum8); + test(Test::ShortEnum::from_int(Test::LongConst1) == Test::ShortEnum::Senum9); + test(Test::ShortEnum::from_int(Test::LongConst1 + 1) == Test::ShortEnum::Senum10); + test(Test::ShortEnum::from_int(Test::ShortConst2) == Test::ShortEnum::Senum11); + + test(Test::IntEnum::Ienum1.to_i == 0); + test(Test::IntEnum::Ienum2.to_i == 1); + test(Test::IntEnum::Ienum3.to_i == Test::ByteConst1); + test(Test::IntEnum::Ienum4.to_i == Test::ByteConst1 + 1); + test(Test::IntEnum::Ienum5.to_i == Test::ShortConst1); + test(Test::IntEnum::Ienum6.to_i == Test::ShortConst1 + 1); + test(Test::IntEnum::Ienum7.to_i == Test::IntConst1); + test(Test::IntEnum::Ienum8.to_i == Test::IntConst1 + 1); + test(Test::IntEnum::Ienum9.to_i == Test::LongConst1); + test(Test::IntEnum::Ienum10.to_i == Test::LongConst1 + 1); + test(Test::IntEnum::Ienum11.to_i == Test::IntConst2); + test(Test::IntEnum::Ienum12.to_i == Test::LongConst2); + + test(Test::IntEnum::from_int(0) == Test::IntEnum::Ienum1); + test(Test::IntEnum::from_int(1) == Test::IntEnum::Ienum2); + test(Test::IntEnum::from_int(Test::ByteConst1) == Test::IntEnum::Ienum3); + test(Test::IntEnum::from_int(Test::ByteConst1 + 1) == Test::IntEnum::Ienum4); + test(Test::IntEnum::from_int(Test::ShortConst1) == Test::IntEnum::Ienum5); + test(Test::IntEnum::from_int(Test::ShortConst1 + 1) == Test::IntEnum::Ienum6); + test(Test::IntEnum::from_int(Test::IntConst1) == Test::IntEnum::Ienum7); + test(Test::IntEnum::from_int(Test::IntConst1 + 1) == Test::IntEnum::Ienum8); + test(Test::IntEnum::from_int(Test::LongConst1) == Test::IntEnum::Ienum9); + test(Test::IntEnum::from_int(Test::LongConst1 + 1) == Test::IntEnum::Ienum10); + test(Test::IntEnum::from_int(Test::IntConst2) == Test::IntEnum::Ienum11); + test(Test::IntEnum::from_int(Test::LongConst2) == Test::IntEnum::Ienum12); + + test(Test::SimpleEnum::Red.to_i == 0); + test(Test::SimpleEnum::Green.to_i == 1); + test(Test::SimpleEnum::Blue.to_i == 2); + + test(Test::SimpleEnum::from_int(0) == Test::SimpleEnum::Red); + test(Test::SimpleEnum::from_int(1) == Test::SimpleEnum::Green); + test(Test::SimpleEnum::from_int(2) == Test::SimpleEnum::Blue); + + puts "ok" + + print "testing enum operations... " + STDOUT.flush + + test(proxy.opByte(Test::ByteEnum::Benum1) == [Test::ByteEnum::Benum1, Test::ByteEnum::Benum1]); + test(proxy.opByte(Test::ByteEnum::Benum11) == [Test::ByteEnum::Benum11, Test::ByteEnum::Benum11]); + + test(proxy.opShort(Test::ShortEnum::Senum1) == [Test::ShortEnum::Senum1, Test::ShortEnum::Senum1]); + test(proxy.opShort(Test::ShortEnum::Senum11) == [Test::ShortEnum::Senum11, Test::ShortEnum::Senum11]); + + test(proxy.opInt(Test::IntEnum::Ienum1) == [Test::IntEnum::Ienum1, Test::IntEnum::Ienum1]); + test(proxy.opInt(Test::IntEnum::Ienum11) == [Test::IntEnum::Ienum11, Test::IntEnum::Ienum11]); + test(proxy.opInt(Test::IntEnum::Ienum12) == [Test::IntEnum::Ienum12, Test::IntEnum::Ienum12]); + + test(proxy.opSimple(Test::SimpleEnum::Green) == [Test::SimpleEnum::Green, Test::SimpleEnum::Green]); + + puts "ok" + + return proxy +end diff --git a/ruby/test/Ice/enums/Client.rb b/ruby/test/Ice/enums/Client.rb new file mode 100755 index 00000000000..7835cbebc13 --- /dev/null +++ b/ruby/test/Ice/enums/Client.rb @@ -0,0 +1,41 @@ +#!/usr/bin/env ruby +# ********************************************************************** +# +# Copyright (c) 2003-2015 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 'Ice' + +Ice::loadSlice("Test.ice") +require './AllTests' + +def run(args, communicator) + proxy = allTests(communicator) + proxy.shutdown() + return true +end + +begin + communicator = Ice.initialize(ARGV) + status = run(ARGV, communicator) +rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false +end + +if communicator + begin + communicator.destroy() + rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false + end +end + +exit(status ? 0 : 1) diff --git a/ruby/test/Ice/enums/Test.ice b/ruby/test/Ice/enums/Test.ice new file mode 100644 index 00000000000..1cfe8c3eda8 --- /dev/null +++ b/ruby/test/Ice/enums/Test.ice @@ -0,0 +1,88 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 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/ruby/test/Ice/enums/run.py b/ruby/test/Ice/enums/run.py new file mode 100755 index 00000000000..614bfe363bf --- /dev/null +++ b/ruby/test/Ice/enums/run.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 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/ruby/test/Ice/exceptions/AllTests.rb b/ruby/test/Ice/exceptions/AllTests.rb new file mode 100644 index 00000000000..b0cf5e74293 --- /dev/null +++ b/ruby/test/Ice/exceptions/AllTests.rb @@ -0,0 +1,394 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 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. +# +# ********************************************************************** + +def test(b) + if !b + raise RuntimeError, 'test assertion failed' + end +end + +class ObjectFactoryI + def create(id) + return nil + end + + def destroy() + end +end + +def allTests(communicator) + platformInfo = RUBY_PLATFORM.split("-") + isWin32 = false + if platformInfo.length >= 2 && platformInfo[1] == "mswin32" + isWin32 = true + end + + print "testing object factory registration exception... " + STDOUT.flush + of = ObjectFactoryI.new + communicator.addObjectFactory(of, "x") + begin + communicator.addObjectFactory(of, "x") + test(false) + rescue Ice::AlreadyRegisteredException + end + puts "ok" + + print "testing stringToProxy... " + STDOUT.flush + ref = "thrower:default -p 12010" + base = communicator.stringToProxy(ref) + test(base) + puts "ok" + + print "testing checked cast... " + STDOUT.flush + thrower = Test::ThrowerPrx::checkedCast(base) + test(thrower) + test(thrower == base) + puts "ok" + + print "catching exact types... " + STDOUT.flush + + begin + thrower.throwAasA(1) + test(false) + rescue Test::A => ex + test(ex.aMem == 1) + rescue + print $!.backtrace.join("\n") + test(false) + end + + begin + thrower.throwAorDasAorD(1) + test(false) + rescue Test::A => ex + test(ex.aMem == 1) + rescue + print $!.backtrace.join("\n") + test(false) + end + + begin + thrower.throwAorDasAorD(-1) + test(false) + rescue Test::D => ex + test(ex.dMem == -1) + rescue + print $!.backtrace.join("\n") + test(false) + end + + begin + thrower.throwBasB(1, 2) + test(false) + rescue Test::B => ex + test(ex.aMem == 1) + test(ex.bMem == 2) + rescue + print $!.backtrace.join("\n") + test(false) + end + + begin + thrower.throwCasC(1, 2, 3) + test(false) + rescue Test::C => ex + test(ex.aMem == 1) + test(ex.bMem == 2) + test(ex.cMem == 3) + rescue + print $!.backtrace.join("\n") + test(false) + end + + # + # We cannot invoke throwModA if the server was built with VC6. + # + if !isWin32 + begin + thrower.throwModA(1, 2) + test(false) + rescue Test::Mod::A => ex + test(ex.aMem == 1) + test(ex.a2Mem == 2) + rescue Ice::OperationNotExistException + # + # This operation is not supported in Java. + # + rescue + print $! + print $!.backtrace.join("\n") + test(false) + end + end + + puts "ok" + + print "catching base types... " + STDOUT.flush + + begin + thrower.throwBasB(1, 2) + test(false) + rescue Test::A => ex + test(ex.aMem == 1) + rescue + print $!.backtrace.join("\n") + test(false) + end + + begin + thrower.throwCasC(1, 2, 3) + test(false) + rescue Test::B => ex + test(ex.aMem == 1) + test(ex.bMem == 2) + rescue + print $!.backtrace.join("\n") + test(false) + end + + # + # We cannot invoke throwModA if the server was built with VC6. + # + if !isWin32 + begin + thrower.throwModA(1, 2) + test(false) + rescue Test::A => ex + test(ex.aMem == 1) + rescue Ice::OperationNotExistException + # + # This operation is not supported in Java. + # + rescue + print $!.backtrace.join("\n") + test(false) + end + end + + puts "ok" + + print "catching derived types... " + STDOUT.flush + + begin + thrower.throwBasA(1, 2) + test(false) + rescue Test::B => ex + test(ex.aMem == 1) + test(ex.bMem == 2) + rescue + print $!.backtrace.join("\n") + test(false) + end + + begin + thrower.throwCasA(1, 2, 3) + test(false) + rescue Test::C => ex + test(ex.aMem == 1) + test(ex.bMem == 2) + test(ex.cMem == 3) + rescue + print $!.backtrace.join("\n") + test(false) + end + + begin + thrower.throwCasB(1, 2, 3) + test(false) + rescue Test::C => ex + test(ex.aMem == 1) + test(ex.bMem == 2) + test(ex.cMem == 3) + rescue + print $!.backtrace.join("\n") + test(false) + end + + puts "ok" + + if thrower.supportsUndeclaredExceptions() + print "catching unknown user exception... " + STDOUT.flush + + begin + thrower.throwUndeclaredA(1) + test(false) + rescue Ice::UnknownUserException + # + # We get an unknown user exception without collocation + # optimization. + # + rescue + print $!.backtrace.join("\n") + test(false) + end + + begin + thrower.throwUndeclaredB(1, 2) + test(false) + rescue Ice::UnknownUserException + # + # We get an unknown user exception without collocation + # optimization. + # + rescue + print $!.backtrace.join("\n") + test(false) + end + + begin + thrower.throwUndeclaredC(1, 2, 3) + test(false) + rescue Ice::UnknownUserException + # + # We get an unknown user exception without collocation + # optimization. + # + rescue + print $!.backtrace.join("\n") + test(false) + end + + puts "ok" + end + + print "testing memory limit marshal exception..." + STDOUT.flush + + begin + thrower.throwMemoryLimitException(Array.new(1, 0x00)); + test(false) + rescue Ice::MemoryLimitException + # Expected + rescue + test(false) + end + + begin + thrower.throwMemoryLimitException(Array.new(20 * 1024, 0x00)) # 20KB + test(false) + rescue Ice::ConnectionLostException + # Expected + rescue + print $!.backtrace.join("\n") + test(false) + end + + puts "ok" + + print "catching object not exist exception... " + STDOUT.flush + + id = communicator.stringToIdentity("does not exist") + begin + thrower2 = Test::ThrowerPrx::uncheckedCast(thrower.ice_identity(id)) + thrower2.throwAasA(1) +# thrower2.ice_ping() + test(false) + rescue Ice::ObjectNotExistException => ex + test(ex.id == id) + rescue + print $!.backtrace.join("\n") + test(false) + end + + puts "ok" + + print "catching facet not exist exception... " + STDOUT.flush + + begin + thrower2 = Test::ThrowerPrx::uncheckedCast(thrower, "no such facet") + begin + thrower2.ice_ping() + test(false) + rescue Ice::FacetNotExistException => ex + test(ex.facet == "no such facet") + end + rescue + print $!.backtrace.join("\n") + test(false) + end + + puts "ok" + + print "catching operation not exist exception... " + STDOUT.flush + + begin + thrower2 = Test::WrongOperationPrx::uncheckedCast(thrower) + thrower2.noSuchOperation() + test(false) + rescue Ice::OperationNotExistException => ex + test(ex.operation == "noSuchOperation") + rescue + print $!.backtrace.join("\n") + test(false) + end + + puts "ok" + + print "catching unknown local exception... " + STDOUT.flush + + begin + thrower.throwLocalException() + test(false) + rescue Ice::UnknownLocalException + # + # We get an unknown local exception without collocation + # optimization. + # + rescue + print $!.backtrace.join("\n") + test(false) + end + + begin + thrower.throwLocalExceptionIdempotent() + test(false) + rescue Ice::UnknownLocalException + # + # We get an unknown local exception without collocation + # optimization. + # + rescue Ice::OperationNotExistException + rescue + print $!.backtrace.join("\n") + test(false) + end + + puts "ok" + + print "catching unknown non-Ice exception... " + STDOUT.flush + + begin + thrower.throwNonIceException() + test(false) + rescue Ice::UnknownException + # + # We get an unknown exception without collocation + # optimization. + # + rescue + print $!.backtrace.join("\n") + test(false) + end + + puts "ok" + + return thrower +end diff --git a/ruby/test/Ice/exceptions/Client.rb b/ruby/test/Ice/exceptions/Client.rb new file mode 100755 index 00000000000..26b204ace46 --- /dev/null +++ b/ruby/test/Ice/exceptions/Client.rb @@ -0,0 +1,47 @@ +#!/usr/bin/env ruby +# ********************************************************************** +# +# Copyright (c) 2003-2015 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 'pathname' +require 'Ice' + +slice_dir = Ice.getSliceDir +Ice::loadSlice("'-I" + slice_dir + "' Test.ice") +require './AllTests' + +def run(args, communicator) + thrower = allTests(communicator) + thrower.shutdown() + return true +end + +begin + initData = Ice::InitializationData.new + initData.properties = Ice.createProperties(ARGV) + initData.properties.setProperty("Ice.MessageSizeMax", "10") + initData.properties.setProperty("Ice.Warn.Connections", "0") + communicator = Ice.initialize(ARGV, initData) + status = run(ARGV, communicator) +rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false +end + +if communicator + begin + communicator.destroy() + rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false + end +end + +exit(status ? 0 : 1) diff --git a/ruby/test/Ice/exceptions/Test.ice b/ruby/test/Ice/exceptions/Test.ice new file mode 100644 index 00000000000..0b04dc2bca2 --- /dev/null +++ b/ruby/test/Ice/exceptions/Test.ice @@ -0,0 +1,84 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 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; +}; + +module Mod +{ + exception A extends ::Test::A + { + int a2Mem; + }; +}; + + +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 throwModA(int a, int a2) throws Mod::A; + + 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(); +}; + +interface WrongOperation +{ + void noSuchOperation(); +}; + +}; diff --git a/ruby/test/Ice/exceptions/run.py b/ruby/test/Ice/exceptions/run.py new file mode 100755 index 00000000000..0b40bb60e8b --- /dev/null +++ b/ruby/test/Ice/exceptions/run.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 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/ruby/test/Ice/facets/AllTests.rb b/ruby/test/Ice/facets/AllTests.rb new file mode 100644 index 00000000000..c022f73fd14 --- /dev/null +++ b/ruby/test/Ice/facets/AllTests.rb @@ -0,0 +1,128 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 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. +# +# ********************************************************************** + +def test(b) + if !b + raise RuntimeError, 'test assertion failed' + end +end + +def allTests(communicator) + + print "testing Ice.Admin.Facets property... " + STDOUT.flush + test(communicator.getProperties().getPropertyAsList("Ice.Admin.Facets").length == 0) + communicator.getProperties().setProperty("Ice.Admin.Facets", "foobar"); + facetFilter = communicator.getProperties().getPropertyAsList("Ice.Admin.Facets"); + test(facetFilter.length == 1 && facetFilter[0] == "foobar"); + communicator.getProperties().setProperty("Ice.Admin.Facets", "foo\\'bar"); + facetFilter = communicator.getProperties().getPropertyAsList("Ice.Admin.Facets"); + test(facetFilter.length == 1 && facetFilter[0] == "foo'bar"); + communicator.getProperties().setProperty("Ice.Admin.Facets", "'foo bar' toto 'titi'"); + facetFilter = communicator.getProperties().getPropertyAsList("Ice.Admin.Facets"); + test(facetFilter.length == 3 && facetFilter[0] == "foo bar" && facetFilter[1] == "toto" && facetFilter[2] == "titi"); + communicator.getProperties().setProperty("Ice.Admin.Facets", "'foo bar\\' toto' 'titi'"); + facetFilter = communicator.getProperties().getPropertyAsList("Ice.Admin.Facets"); + test(facetFilter.length == 2 && facetFilter[0] == "foo bar' toto" && facetFilter[1] == "titi"); + # communicator.getProperties().setProperty("Ice.Admin.Facets", "'foo bar' 'toto titi"); + # facetFilter = communicator.getProperties().getPropertyAsList("Ice.Admin.Facets"); + # test(facetFilter.length == 0); + communicator.getProperties().setProperty("Ice.Admin.Facets", ""); + puts "ok" + + print "testing stringToProxy... " + STDOUT.flush + ref = "d:default -p 12010" + db = communicator.stringToProxy(ref) + test(db) + puts "ok" + + print "testing unchecked cast... " + STDOUT.flush + obj = Ice::ObjectPrx::uncheckedCast(db) + test(obj.ice_getFacet() == "") + obj = Ice::ObjectPrx::uncheckedCast(db, "facetABCD") + test(obj.ice_getFacet() == "facetABCD") + obj2 = Ice::ObjectPrx::uncheckedCast(obj) + test(obj2.ice_getFacet() == "facetABCD") + obj3 = Ice::ObjectPrx::uncheckedCast(obj, "") + test(obj3.ice_getFacet() == "") + d = Test::DPrx::uncheckedCast(db) + test(d.ice_getFacet() == "") + 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() == "") + puts "ok" + + print "testing checked cast... " + STDOUT.flush + obj = Ice::ObjectPrx::checkedCast(db) + test(obj.ice_getFacet() == "") + obj = Ice::ObjectPrx::checkedCast(db, "facetABCD") + test(obj.ice_getFacet() == "facetABCD") + obj2 = Ice::ObjectPrx::checkedCast(obj) + test(obj2.ice_getFacet() == "facetABCD") + obj3 = Ice::ObjectPrx::checkedCast(obj, "") + test(obj3.ice_getFacet() == "") + d = Test::DPrx::checkedCast(db) + test(d.ice_getFacet() == "") + df = Test::DPrx::checkedCast(db, "facetABCD") + test(df.ice_getFacet() == "facetABCD") + df2 = Test::DPrx::checkedCast(df) + test(df2.ice_getFacet() == "facetABCD") + df3 = Test::DPrx::checkedCast(df, "") + test(df3.ice_getFacet() == "") + puts "ok" + + print "testing non-facets A, B, C, and D... " + STDOUT.flush + test(d.callA() == "A") + test(d.callB() == "B") + test(d.callC() == "C") + test(d.callD() == "D") + puts "ok" + + print "testing facets A, B, C, and D... " + STDOUT.flush + df = Test::DPrx::checkedCast(d, "facetABCD") + test(df) + test(df.callA() == "A") + test(df.callB() == "B") + test(df.callC() == "C") + test(df.callD() == "D") + puts "ok" + + print "testing facets E and F... " + STDOUT.flush + ff = Test::FPrx::checkedCast(d, "facetEF") + test(ff) + test(ff.callE() == "E") + test(ff.callF() == "F") + puts "ok" + + print "testing facet G... " + STDOUT.flush + gf = Test::GPrx::checkedCast(ff, "facetGH") + test(gf) + test(gf.callG() == "G") + puts "ok" + + print "testing whether casting preserves the facet... " + STDOUT.flush + hf = Test::HPrx::checkedCast(gf) + test(hf) + test(hf.callG() == "G") + test(hf.callH() == "H") + puts "ok" + + return gf +end diff --git a/ruby/test/Ice/facets/Client.rb b/ruby/test/Ice/facets/Client.rb new file mode 100755 index 00000000000..10d9648bc53 --- /dev/null +++ b/ruby/test/Ice/facets/Client.rb @@ -0,0 +1,41 @@ +#!/usr/bin/env ruby +# ********************************************************************** +# +# Copyright (c) 2003-2015 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 'pathname' +require 'Ice' +Ice::loadSlice('Test.ice') +require './AllTests' + +def run(args, communicator) + g = allTests(communicator) + g.shutdown() + return true +end + +begin + communicator = Ice::initialize(ARGV) + status = run(ARGV, communicator) +rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false +end + +if communicator + begin + communicator.destroy() + rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false + end +end + +exit(status ? 0 : 1) diff --git a/ruby/test/Ice/facets/Test.ice b/ruby/test/Ice/facets/Test.ice new file mode 100644 index 00000000000..d73c6594829 --- /dev/null +++ b/ruby/test/Ice/facets/Test.ice @@ -0,0 +1,60 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 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/ruby/test/Ice/facets/run.py b/ruby/test/Ice/facets/run.py new file mode 100755 index 00000000000..3489faf2571 --- /dev/null +++ b/ruby/test/Ice/facets/run.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 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/ruby/test/Ice/info/AllTests.rb b/ruby/test/Ice/info/AllTests.rb new file mode 100644 index 00000000000..394ab3a5b38 --- /dev/null +++ b/ruby/test/Ice/info/AllTests.rb @@ -0,0 +1,125 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 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. +# +# ********************************************************************** + +def allTests(communicator) + print "testing proxy endpoint information..." + STDOUT.flush + + p1 = communicator.stringToProxy("test -t:default -h tcphost -p 10000 -t 1200 -z --sourceAddress 10.10.10.10:" + \ + "udp -h udphost -p 10001 --interface eth0 --ttl 5 --sourceAddress 10.10.10.10:" + \ + "opaque -e 1.8 -t 100 -v ABCD") + + endps = p1.ice_getEndpoints() + + ipEndpoint = endps[0].getInfo() + test(ipEndpoint.is_a?(Ice::IPEndpointInfo)); + test(ipEndpoint.host == "tcphost") + test(ipEndpoint.port == 10000) + test(ipEndpoint.sourceAddress == "10.10.10.10") + test(ipEndpoint.timeout == 1200) + test(ipEndpoint.compress) + test(!ipEndpoint.datagram()) + test((ipEndpoint.type() == Ice::TCPEndpointType && !ipEndpoint.secure()) || + (ipEndpoint.type() == Ice::SSLEndpointType && ipEndpoint.secure()) || + (ipEndpoint.type() == Ice::WSEndpointType && !ipEndpoint.secure()) || + (ipEndpoint.type() == Ice::WSSEndpointType && ipEndpoint.secure())) + test((ipEndpoint.type() == Ice::TCPEndpointType && ipEndpoint.is_a?(Ice::TCPEndpointInfo)) || + (ipEndpoint.type() == Ice::SSLEndpointType) || + (ipEndpoint.type() == Ice::WSEndpointType && ipEndpoint.is_a?(Ice::WSEndpointInfo)) || + (ipEndpoint.type() == Ice::WSSEndpointType && ipEndpoint.is_a?(Ice::WSEndpointInfo))) + + udpEndpoint = endps[1].getInfo() + test(udpEndpoint.is_a?(Ice::UDPEndpointInfo)); + test(udpEndpoint.host == "udphost") + test(udpEndpoint.port == 10001) + test(udpEndpoint.sourceAddress == "10.10.10.10") + test(udpEndpoint.mcastInterface == "eth0") + test(udpEndpoint.mcastTtl == 5) + test(udpEndpoint.timeout == -1) + test(!udpEndpoint.compress) + test(!udpEndpoint.secure()) + test(udpEndpoint.datagram()) + test(udpEndpoint.type() == Ice::UDPEndpointType) + + opaqueEndpoint = endps[2].getInfo() + test(opaqueEndpoint.is_a?(Ice::OpaqueEndpointInfo)); + test(opaqueEndpoint.rawEncoding == Ice::EncodingVersion.new(1, 8)) + + puts "ok" + + defaultHost = communicator.getProperties().getProperty("Ice.Default.Host") + base = communicator.stringToProxy("test:default -p 12010:udp -p 12010") + testIntf = Test::TestIntfPrx::checkedCast(base) + + print "test connection endpoint information..." + STDOUT.flush + + ipinfo = base.ice_getConnection().getEndpoint().getInfo() + test(ipinfo.port == 12010) + test(!ipinfo.compress) + test(ipinfo.host == defaultHost) + + ctx = testIntf.getEndpointInfoAsContext() + test(ctx["host"] == ipinfo.host) + test(ctx["compress"] == "false") + port = Integer(ctx["port"]) + test(port > 0) + + udp = base.ice_datagram().ice_getConnection().getEndpoint().getInfo() + test(udp.port == 12010) + test(udp.host == defaultHost) + + puts "ok" + + print "testing connection information..." + STDOUT.flush + + connection = base.ice_getConnection() + connection.setBufferSize(1024, 2048) + + info = connection.getInfo() + test(!info.incoming) + test(info.adapterName.length == 0) + test(info.remotePort == 12010) + if defaultHost == "127.0.0.1" + test(info.remoteAddress == defaultHost) + test(info.localAddress == defaultHost) + end + test(info.rcvSize >= 1024) + test(info.sndSize >= 2048) + + ctx = testIntf.getConnectionInfoAsContext() + test(ctx["incoming"] == "true") + test(ctx["adapterName"] == "TestAdapter") + test(ctx["remoteAddress"] == info.localAddress) + test(ctx["localAddress"] == info.remoteAddress) + test(ctx["remotePort"] == info.localPort.to_s()) + test(ctx["localPort"] == info.remotePort.to_s()) + + if base.ice_getConnection().type() == "ws" || base.ice_getConnection().type() == "wss" + test(info.is_a?(Ice::WSConnectionInfo)) + + test(info.headers["Upgrade"] == "websocket") + test(info.headers["Connection"] == "Upgrade") + test(info.headers["Sec-WebSocket-Protocol"] == "ice.zeroc.com") + test(info.headers.has_key?("Sec-WebSocket-Accept")) + + test(ctx["ws.Upgrade"] == "websocket") + test(ctx["ws.Connection"] == "Upgrade") + test(ctx["ws.Sec-WebSocket-Protocol"] == "ice.zeroc.com") + test(ctx["ws.Sec-WebSocket-Version"] == "13") + test(ctx.has_key?("ws.Sec-WebSocket-Key")) + end + + puts "ok" + + testIntf.shutdown() + + communicator.shutdown() +end diff --git a/ruby/test/Ice/info/Client.rb b/ruby/test/Ice/info/Client.rb new file mode 100755 index 00000000000..b3fc620ac0e --- /dev/null +++ b/ruby/test/Ice/info/Client.rb @@ -0,0 +1,53 @@ +#!/usr/bin/env ruby +# ********************************************************************** +# +# Copyright (c) 2003-2015 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 'pathname' +require 'Ice' +slice_dir = Ice.getSliceDir +if slice_dir.empty? + fail "Slice directory not found" +end + +Ice::loadSlice("'-I" + slice_dir + "' Test.ice") +require './AllTests' + +def test(b) + if !b + raise RuntimeError, 'test assertion failed' + end +end + +def run(args, communicator) + allTests(communicator) + return true +end + +begin + initData = Ice::InitializationData.new + initData.properties = Ice.createProperties(ARGV) + communicator = Ice.initialize(ARGV, initData) + status = run(ARGV, communicator) +rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false +end + +if communicator + begin + communicator.destroy() + rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false + end +end + +exit(status ? 0 : 1) diff --git a/ruby/test/Ice/info/Test.ice b/ruby/test/Ice/info/Test.ice new file mode 100644 index 00000000000..a71990ba3db --- /dev/null +++ b/ruby/test/Ice/info/Test.ice @@ -0,0 +1,26 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 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 +{ + +interface TestIntf +{ + void shutdown(); + + Ice::Context getEndpointInfoAsContext(); + + Ice::Context getConnectionInfoAsContext(); +}; + +}; diff --git a/ruby/test/Ice/info/run.py b/ruby/test/Ice/info/run.py new file mode 100755 index 00000000000..74d2e5d1724 --- /dev/null +++ b/ruby/test/Ice/info/run.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 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/ruby/test/Ice/inheritance/AllTests.rb b/ruby/test/Ice/inheritance/AllTests.rb new file mode 100644 index 00000000000..509e4553d39 --- /dev/null +++ b/ruby/test/Ice/inheritance/AllTests.rb @@ -0,0 +1,217 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 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. +# +# ********************************************************************** + +def test(b) + if !b + raise RuntimeError, 'test assertion failed' + end +end + +def allTests(communicator) + print "testing stringToProxy... " + STDOUT.flush + ref = "initial:default -p 12010" + base = communicator.stringToProxy(ref) + test(base) + puts "ok" + + print "testing checked cast... " + STDOUT.flush + initial = Test::InitialPrx::checkedCast(base) + test(initial) + test(initial == base) + puts "ok" + + print "getting proxies for class hierarchy... " + STDOUT.flush + ca = initial.caop() + cb = initial.cbop() + cc = initial.ccop() + cd = initial.cdop() + test(ca != cb) + test(ca != cc) + test(ca != cd) + test(cb != cc) + test(cb != cd) + test(cc != cd) + puts "ok" + + print "getting proxies for interface hierarchy... " + STDOUT.flush + ia = initial.iaop() + ib1 = initial.ib1op() + ib2 = initial.ib2op() + ic = initial.icop() + test(ia != ib1) + test(ia != ib2) + test(ia != ic) + test(ib1 != ic) + test(ib2 != ic) + puts "ok" + + print "invoking proxy operations on class hierarchy... " + STDOUT.flush + cao = ca.caop(ca) + test(cao == ca) + cao = ca.caop(cb) + test(cao == cb) + cao = ca.caop(cc) + test(cao == cc) + cao = cb.caop(ca) + test(cao == ca) + cao = cb.caop(cb) + test(cao == cb) + cao = cb.caop(cc) + test(cao == cc) + cao = cc.caop(ca) + test(cao == ca) + cao = cc.caop(cb) + test(cao == cb) + cao = cc.caop(cc) + test(cao == cc) + + cao = cb.cbop(cb) + test(cao == cb) + cbo = cb.cbop(cb) + test(cbo == cb) + cao = cb.cbop(cc) + test(cao == cc) + cbo = cb.cbop(cc) + test(cbo == cc) + cao = cc.cbop(cb) + test(cao == cb) + cbo = cc.cbop(cb) + test(cbo == cb) + cao = cc.cbop(cc) + test(cao == cc) + cbo = cc.cbop(cc) + test(cbo == cc) + + cao = cc.ccop(cc) + test(cao == cc) + cbo = cc.ccop(cc) + test(cbo == cc) + cco = cc.ccop(cc) + test(cco == cc) + puts "ok" + + print "ditto, but for interface hierarchy... " + STDOUT.flush + iao = ia.iaop(ia) + test(iao == ia) + iao = ia.iaop(ib1) + test(iao == ib1) + iao = ia.iaop(ib2) + test(iao == ib2) + iao = ia.iaop(ic) + test(iao == ic) + iao = ib1.iaop(ia) + test(iao == ia) + iao = ib1.iaop(ib1) + test(iao == ib1) + iao = ib1.iaop(ib2) + test(iao == ib2) + iao = ib1.iaop(ic) + test(iao == ic) + iao = ib2.iaop(ia) + test(iao == ia) + iao = ib2.iaop(ib1) + test(iao == ib1) + iao = ib2.iaop(ib2) + test(iao == ib2) + iao = ib2.iaop(ic) + test(iao == ic) + iao = ic.iaop(ia) + test(iao == ia) + iao = ic.iaop(ib1) + test(iao == ib1) + iao = ic.iaop(ib2) + test(iao == ib2) + iao = ic.iaop(ic) + test(iao == ic) + + iao = ib1.ib1op(ib1) + test(iao == ib1) + ib1o = ib1.ib1op(ib1) + test(ib1o == ib1) + iao = ib1.ib1op(ic) + test(iao == ic) + ib1o = ib1.ib1op(ic) + test(ib1o == ic) + iao = ic.ib1op(ib1) + test(iao == ib1) + ib1o = ic.ib1op(ib1) + test(ib1o == ib1) + iao = ic.ib1op(ic) + test(iao == ic) + ib1o = ic.ib1op(ic) + test(ib1o == ic) + + iao = ib2.ib2op(ib2) + test(iao == ib2) + ib2o = ib2.ib2op(ib2) + test(ib2o == ib2) + iao = ib2.ib2op(ic) + test(iao == ic) + ib2o = ib2.ib2op(ic) + test(ib2o == ic) + iao = ic.ib2op(ib2) + test(iao == ib2) + ib2o = ic.ib2op(ib2) + test(ib2o == ib2) + iao = ic.ib2op(ic) + test(iao == ic) + ib2o = ic.ib2op(ic) + test(ib2o == ic) + + iao = ic.icop(ic) + test(iao == ic) + ib1o = ic.icop(ic) + test(ib1o == ic) + ib2o = ic.icop(ic) + test(ib2o == ic) + ico = ic.icop(ic) + test(ico == ic) + + puts "ok" + + print "ditto, but for class implementing interfaces... " + STDOUT.flush + cao = cd.caop(cd) + test(cao == cd) + cbo = cd.cbop(cd) + test(cbo == cd) + cco = cd.ccop(cd) + test(cco == cd) + + iao = cd.iaop(cd) + test(iao == cd) + ib1o = cd.ib1op(cd) + test(ib1o == cd) + ib2o = cd.ib2op(cd) + test(ib2o == cd) + + cao = cd.cdop(cd) + test(cao == cd) + cbo = cd.cdop(cd) + test(cbo == cd) + cco = cd.cdop(cd) + test(cco == cd) + + iao = cd.cdop(cd) + test(iao == cd) + ib1o = cd.cdop(cd) + test(ib1o == cd) + ib2o = cd.cdop(cd) + test(ib2o == cd) + + puts "ok" + + return initial +end diff --git a/ruby/test/Ice/inheritance/Client.rb b/ruby/test/Ice/inheritance/Client.rb new file mode 100755 index 00000000000..88c276f1be9 --- /dev/null +++ b/ruby/test/Ice/inheritance/Client.rb @@ -0,0 +1,41 @@ +#!/usr/bin/env ruby +# ********************************************************************** +# +# Copyright (c) 2003-2015 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 'pathname' +require 'Ice' +Ice::loadSlice('Test.ice') +require './AllTests' + +def run(args, communicator) + initial = allTests(communicator) + initial.shutdown() + return true +end + +begin + communicator = Ice.initialize(ARGV) + status = run(ARGV, communicator) +rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false +end + +if communicator + begin + communicator.destroy() + rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false + end +end + +exit(status ? 0 : 1) diff --git a/ruby/test/Ice/inheritance/Test.ice b/ruby/test/Ice/inheritance/Test.ice new file mode 100644 index 00000000000..7dd63ee98b6 --- /dev/null +++ b/ruby/test/Ice/inheritance/Test.ice @@ -0,0 +1,83 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 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(); +}; + +}; diff --git a/ruby/test/Ice/inheritance/run.py b/ruby/test/Ice/inheritance/run.py new file mode 100755 index 00000000000..3489faf2571 --- /dev/null +++ b/ruby/test/Ice/inheritance/run.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 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/ruby/test/Ice/location/AllTests.rb b/ruby/test/Ice/location/AllTests.rb new file mode 100644 index 00000000000..00e6fb39d44 --- /dev/null +++ b/ruby/test/Ice/location/AllTests.rb @@ -0,0 +1,238 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 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. +# +# ********************************************************************** + +def test(b) + if !b + raise RuntimeError, 'test assertion failed' + end +end + +def allTests(communicator, ref) + manager = Test::ServerManagerPrx::checkedCast(communicator.stringToProxy(ref)) + locator = communicator.getDefaultLocator() + test(manager) + + print "testing stringToProxy... " + STDOUT.flush + base = communicator.stringToProxy("test @ TestAdapter") + base2 = communicator.stringToProxy("test @ TestAdapter") + base3 = communicator.stringToProxy("test") + base4 = communicator.stringToProxy("ServerManager") + base5 = communicator.stringToProxy("test2") + puts "ok" + + print "testing ice_locator and ice_getLocator... " + STDOUT.flush + test(Ice::proxyIdentityEqual(base.ice_getLocator(), communicator.getDefaultLocator())) + anotherLocator = Ice::LocatorPrx::uncheckedCast(communicator.stringToProxy("anotherLocator")) + base = base.ice_locator(anotherLocator) + test(Ice::proxyIdentityEqual(base.ice_getLocator(), anotherLocator)) + communicator.setDefaultLocator(nil) + base = communicator.stringToProxy("test @ TestAdapter") + test(!base.ice_getLocator()) + base = base.ice_locator(anotherLocator) + test(Ice::proxyIdentityEqual(base.ice_getLocator(), anotherLocator)) + communicator.setDefaultLocator(locator) + base = communicator.stringToProxy("test @ TestAdapter") + test(Ice::proxyIdentityEqual(base.ice_getLocator(), communicator.getDefaultLocator())); + + # + # We also test ice_router/ice_getRouter (perhaps we should add a + # test/Ice/router test?) + # + test(!base.ice_getRouter()) + anotherRouter = Ice::RouterPrx::uncheckedCast(communicator.stringToProxy("anotherRouter")) + base = base.ice_router(anotherRouter) + test(Ice::proxyIdentityEqual(base.ice_getRouter(), anotherRouter)) + router = Ice::RouterPrx::uncheckedCast(communicator.stringToProxy("dummyrouter")) + communicator.setDefaultRouter(router) + base = communicator.stringToProxy("test @ TestAdapter") + test(Ice::proxyIdentityEqual(base.ice_getRouter(), communicator.getDefaultRouter())) + communicator.setDefaultRouter(nil) + base = communicator.stringToProxy("test @ TestAdapter") + test(!base.ice_getRouter()) + puts "ok" + + print "starting server... " + STDOUT.flush + manager.startServer() + puts "ok" + + print "testing checked cast... " + STDOUT.flush + obj = Test::TestIntfPrx::checkedCast(base) + obj = Test::TestIntfPrx::checkedCast(communicator.stringToProxy("test@TestAdapter")) + obj = Test::TestIntfPrx::checkedCast(communicator.stringToProxy("test @TestAdapter")) + obj = Test::TestIntfPrx::checkedCast(communicator.stringToProxy("test@ TestAdapter")) + test(obj) + obj2 = Test::TestIntfPrx::checkedCast(base2) + test(obj2) + obj3 = Test::TestIntfPrx::checkedCast(base3) + test(obj3) + obj4 = Test::ServerManagerPrx::checkedCast(base4) + test(obj4) + obj5 = Test::TestIntfPrx::checkedCast(base5) + test(obj5) + puts "ok" + + print "testing id@AdapterId indirect proxy... " + STDOUT.flush + obj.shutdown() + manager.startServer() + begin + obj2 = Test::TestIntfPrx::checkedCast(base2) + obj2.ice_ping() + rescue Ice::LocalException + test(false) + end + puts "ok" + + print "testing identity indirect proxy... " + STDOUT.flush + obj.shutdown() + manager.startServer() + begin + obj3 = Test::TestIntfPrx::checkedCast(base3) + obj3.ice_ping() + rescue Ice::LocalException + test(false) + end + begin + obj2 = Test::TestIntfPrx::checkedCast(base2) + obj2.ice_ping() + rescue Ice::LocalException + test(false) + end + obj.shutdown() + manager.startServer() + begin + obj2 = Test::TestIntfPrx::checkedCast(base2) + obj2.ice_ping() + rescue Ice::LocalException + test(false) + end + begin + obj3 = Test::TestIntfPrx::checkedCast(base3) + obj3.ice_ping() + rescue Ice::LocalException + test(false) + end + obj.shutdown() + manager.startServer() + + begin + obj2 = Test::TestIntfPrx::checkedCast(base2) + obj2.ice_ping() + rescue Ice::LocalException + test(false) + end + obj.shutdown() + manager.startServer() + begin + obj3 = Test::TestIntfPrx::checkedCast(base3) + obj3.ice_ping() + rescue Ice::LocalException + test(false) + end + obj.shutdown() + manager.startServer() + begin + obj2 = Test::TestIntfPrx::checkedCast(base2) + obj2.ice_ping() + rescue Ice::LocalException + test(false) + end + obj.shutdown() + manager.startServer() + + begin + obj5 = Test::TestIntfPrx::checkedCast(base5) + obj5.ice_ping() + rescue Ice::LocalException + test(false) + end + puts "ok" + + print "testing reference with unknown identity... " + STDOUT.flush + begin + base = communicator.stringToProxy("unknown/unknown") + base.ice_ping() + test(false) + rescue Ice::NotRegisteredException => ex + test(ex.kindOfObject == "object") + test(ex.id == "unknown/unknown") + end + puts "ok" + + print "testing reference with unknown adapter... " + STDOUT.flush + begin + base = communicator.stringToProxy("test @ TestAdapterUnknown") + base.ice_ping() + test(false) + rescue Ice::NotRegisteredException => ex + test(ex.kindOfObject == "object adapter") + test(ex.id == "TestAdapterUnknown") + end + puts "ok" + + print "testing object reference from server... " + STDOUT.flush + hello = obj.getHello() + hello.sayHello() + puts "ok" + + print "testing object reference from server after shutdown... " + STDOUT.flush + obj.shutdown() + manager.startServer() + hello.sayHello() + puts "ok" + + print "testing object migration... " + STDOUT.flush + hello = Test::HelloPrx::checkedCast(communicator.stringToProxy("hello")) + obj.migrateHello() + hello.sayHello() + obj.migrateHello() + hello.sayHello() + obj.migrateHello() + hello.sayHello() + puts "ok" + + print "shutdown server... " + STDOUT.flush + obj.shutdown() + puts "ok" + + print "testing whether server is gone... " + STDOUT.flush + begin + obj2.ice_ping() + test(false) + rescue Ice::LocalException + end + begin + obj3.ice_ping() + test(false) + rescue Ice::LocalException + end + begin + obj5.ice_ping() + test(false) + rescue Ice::LocalException + end + puts "ok" + + print "shutdown server manager... " + STDOUT.flush + manager.shutdown() + puts "ok" +end diff --git a/ruby/test/Ice/location/Client.rb b/ruby/test/Ice/location/Client.rb new file mode 100755 index 00000000000..3bd8d18371d --- /dev/null +++ b/ruby/test/Ice/location/Client.rb @@ -0,0 +1,49 @@ +#!/usr/bin/env ruby +# ********************************************************************** +# +# Copyright (c) 2003-2015 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 'pathname' + +require 'Ice' +slice_dir = Ice.getSliceDir +if slice_dir.empty? + fail "Slice directory not found" +end + +Ice::loadSlice("'-I" + slice_dir + "' Test.ice") +require './AllTests' + +def run(args, communicator) + allTests(communicator, "ServerManager:default -p 12010") + return true +end + +begin + data = Ice::InitializationData.new + data.properties = Ice::createProperties(ARGV) + data.properties.setProperty("Ice.Default.Locator", "locator:default -p 12010") + communicator = Ice::initialize(ARGV, data) + status = run(ARGV, communicator) +rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false +end + +if communicator + begin + communicator.destroy() + rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false + end +end + +exit(status ? 0 : 1) diff --git a/ruby/test/Ice/location/Test.ice b/ruby/test/Ice/location/Test.ice new file mode 100644 index 00000000000..64fa6bdeb4f --- /dev/null +++ b/ruby/test/Ice/location/Test.ice @@ -0,0 +1,45 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 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 ServerManager +{ + void startServer(); + void shutdown(); +}; + +interface Hello +{ + void sayHello(); +}; + +interface TestIntf +{ + void shutdown(); + + Hello* getHello(); + + void migrateHello(); +}; + +}; diff --git a/ruby/test/Ice/location/run.py b/ruby/test/Ice/location/run.py new file mode 100755 index 00000000000..3489faf2571 --- /dev/null +++ b/ruby/test/Ice/location/run.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 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/ruby/test/Ice/objects/AllTests.rb b/ruby/test/Ice/objects/AllTests.rb new file mode 100644 index 00000000000..cb009438b80 --- /dev/null +++ b/ruby/test/Ice/objects/AllTests.rb @@ -0,0 +1,249 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 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 './TestI.rb' + +# +# Ice for Ruby behaves differently than Ice for C++, because +# collocated invocations are still sent "over the wire". Therefore +# we always need to install the factories, even for the collocated +# case. +# +class MyObjectFactory + def create(type) + if type == '::Test::B' + return BI.new + elsif type == '::Test::C' + return CI.new + # + # We do not specialize D, instead we just re-open it to define + # its methods. + # + #elsif type == '::Test::D' + # return DI.new + elsif type == '::Test::E' + return EI.new + elsif type == '::Test::F' + return FI.new + end + fail "unknown type" + end + + def destroy + # Nothing to do + end +end + +def test(b) + if !b + raise RuntimeError, 'test assertion failed' + end +end + +def allTests(communicator) + + factory = MyObjectFactory.new + 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') + + print "testing stringToProxy... " + STDOUT.flush + ref = "initial:default -p 12010" + base = communicator.stringToProxy(ref) + test(base) + puts "ok" + + print "testing checked cast... " + STDOUT.flush + initial = Test::InitialPrx::checkedCast(base) + test(initial) + test(initial == base) + puts "ok" + + print "getting B1... " + STDOUT.flush + b1 = initial.getB1() + test(b1) + puts "ok" + + print "getting B2... " + STDOUT.flush + b2 = initial.getB2() + test(b2) + puts "ok" + + print "getting C... " + STDOUT.flush + c = initial.getC() + test(c) + puts "ok" + + print "getting D... " + STDOUT.flush + d = initial.getD() + test(d) + puts "ok" + + print "checking consistency... " + STDOUT.flush + 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 == nil) + test(b1.theA.is_a?(Test::B)) + test(b1.theA.theA == b1.theA) + test(b1.theA.theB == b1) + test(b1.theA.theC) + test(b1.theA.theC.theB == b1.theA) + test(b1.preMarshalInvoked) + test(b1.postUnmarshalInvoked()) + test(b1.theA.preMarshalInvoked) + test(b1.theA.postUnmarshalInvoked()) + test(b1.theA.theC.preMarshalInvoked) + test(b1.theA.theC.postUnmarshalInvoked()) + # More tests possible for b2 and d, but I think this is already sufficient. + test(b2.theA == b2) + test(d.theC == nil) + puts "ok" + + print "getting B1, B2, C, and D all at once... " + STDOUT.flush + b1, b2, c, d = initial.getAll() + test(b1) + test(b2) + test(c) + test(d) + puts "ok" + + print "checking consistency... " + STDOUT.flush + 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 == nil) + 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 == nil) + test(d.preMarshalInvoked) + test(d.postUnmarshalInvoked()) + test(d.theA.preMarshalInvoked) + test(d.theA.postUnmarshalInvoked()) + test(d.theB.preMarshalInvoked) + test(d.theB.postUnmarshalInvoked()) + test(d.theB.theC.preMarshalInvoked) + test(d.theB.theC.postUnmarshalInvoked()) + puts "ok" + + print "testing protected members... " + STDOUT.flush + e = initial.getE() + test(e.checkValues()) + begin + e.i # Test that i is not accessible + test(false) + rescue NoMethodError + # Expected + end + begin + e.s # Test that s is not accessible + test(false) + rescue NoMethodError + # Expected + end + f = initial.getF() + test(f.checkValues()) + test(f.e2.checkValues()) + begin + f.e1 # Test that e1 is not accessible + test(false) + rescue NoMethodError + # Expected + end + puts "ok" + + print "getting I, J, H... " + STDOUT.flush + i = initial.getI() + test(i) + j = initial.getJ() + test(i) + h = initial.getH() + test(i) + puts "ok" + + print "setting I... " + STDOUT.flush + initial.setI(i) + initial.setI(j) + initial.setI(h) + puts "ok" + + print "testing sequences... " + STDOUT.flush + initial.opBaseSeq([]) + + retS, outS = initial.opBaseSeq([Test::Base.new]) + test(retS.length == 1 && outS.length == 1) + puts "ok" + + print "testing compact ID... " + STDOUT.flush + begin + r = initial.getCompact() + test(r != nil) + rescue Ice::OperationNotExistException + end + puts "ok" + + print "testing UnexpectedObjectException... " + STDOUT.flush + ref = "uoet:default -p 12010" + base = communicator.stringToProxy(ref) + test(base) + uoet = Test::UnexpectedObjectExceptionTestPrx::uncheckedCast(base) + test(uoet) + begin + uoet.op() + test(false) + rescue Ice::UnexpectedObjectException => ex + test(ex.type == "::Test::AlsoEmpty") + test(ex.expectedType == "::Test::Empty") + rescue Ice::UnmarshalOutOfBoundsException => ex + # This test raises Ice::UnmarshalOutOfBoundsException on Windows when the + # server is compiled with VC6. + test(RUBY_PLATFORM =~ /(win|w)32$/) + rescue Ice::Exception => ex + puts $! + print ex.backtrace.join("\n") + test(false) + rescue => ex + puts $! + print ex.backtrace.join("\n") + test(false) + end + puts "ok" + + return initial +end diff --git a/ruby/test/Ice/objects/Client.rb b/ruby/test/Ice/objects/Client.rb new file mode 100755 index 00000000000..e1c2e36f942 --- /dev/null +++ b/ruby/test/Ice/objects/Client.rb @@ -0,0 +1,42 @@ +#!/usr/bin/env ruby +# ********************************************************************** +# +# Copyright (c) 2003-2015 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 'pathname' +require 'Ice' +Ice::loadSlice('Test.ice') +Ice::loadSlice('ClientPrivate.ice') +require './AllTests' + +def run(args, communicator) + initial = allTests(communicator) + initial.shutdown() + return true +end + +begin + communicator = Ice.initialize(ARGV) + status = run(ARGV, communicator) +rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false +end + +if communicator + begin + communicator.destroy() + rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false + end +end + +exit(status ? 0 : 1) diff --git a/ruby/test/Ice/objects/ClientPrivate.ice b/ruby/test/Ice/objects/ClientPrivate.ice new file mode 100644 index 00000000000..31d2e12d833 --- /dev/null +++ b/ruby/test/Ice/objects/ClientPrivate.ice @@ -0,0 +1,68 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 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 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/ruby/test/Ice/objects/Test.ice b/ruby/test/Ice/objects/Test.ice new file mode 100644 index 00000000000..42852d1f75c --- /dev/null +++ b/ruby/test/Ice/objects/Test.ice @@ -0,0 +1,131 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 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 +{ +}; + +interface J extends I +{ +}; + +class H implements I +{ +}; + +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(); +}; + +}; diff --git a/ruby/test/Ice/objects/TestI.rb b/ruby/test/Ice/objects/TestI.rb new file mode 100644 index 00000000000..1f1f7f5e7aa --- /dev/null +++ b/ruby/test/Ice/objects/TestI.rb @@ -0,0 +1,88 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 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. +# +# ********************************************************************** + +class BI < Test::B + def initialize + @preMarshalInvoked = false + @_postUnmarshalInvoked = false + end + + def postUnmarshalInvoked(current=nil) + return @_postUnmarshalInvoked + end + + def ice_preMarshal + @preMarshalInvoked = true + end + + def ice_postUnmarshal + @_postUnmarshalInvoked = true + end +end + +class CI < Test::C + def initialize + @preMarshalInvoked = false + @_postUnmarshalInvoked = false + end + + def postUnmarshalInvoked(current=nil) + return @_postUnmarshalInvoked + end + + def ice_preMarshal + @preMarshalInvoked = true + end + + def ice_postUnmarshal + @_postUnmarshalInvoked = true + end +end + +# +# Re-open Test::D instead of specializing it. +# +class Test::D + def initialize + @preMarshalInvoked = false + @_postUnmarshalInvoked = false + end + + def postUnmarshalInvoked(current=nil) + return @_postUnmarshalInvoked + end + + def ice_preMarshal + @preMarshalInvoked = true + end + + def ice_postUnmarshal + @_postUnmarshalInvoked = true + end +end + +class EI < Test::E + def initialize + super(1, "hello") + end + + def checkValues(current=nil) + return i == 1 && s == "hello" + end +end + +class FI < Test::F + def initialize(e=nil) + super(e, e) + end + + def checkValues(current=nil) + return e1 != nil && e1 == e2 + end +end diff --git a/ruby/test/Ice/objects/run.py b/ruby/test/Ice/objects/run.py new file mode 100755 index 00000000000..19ac6f8a88c --- /dev/null +++ b/ruby/test/Ice/objects/run.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 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/ruby/test/Ice/operations/AllTests.rb b/ruby/test/Ice/operations/AllTests.rb new file mode 100644 index 00000000000..c1cb4318897 --- /dev/null +++ b/ruby/test/Ice/operations/AllTests.rb @@ -0,0 +1,33 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 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 './Twoways' +require './BatchOneways' + +def allTests(communicator) + ref = "test:default -p 12010" + base = communicator.stringToProxy(ref) + cl = Test::MyClassPrx::checkedCast(base) + derived = Test::MyDerivedClassPrx::checkedCast(cl) + + print "testing twoway operations... " + STDOUT.flush + twoways(communicator, cl) + twoways(communicator, derived) + derived.opDerived() + puts "ok" + + print "testing batch oneway operations... " + STDOUT.flush + batchOneways(cl) + batchOneways(derived) + puts "ok" + + return cl +end diff --git a/ruby/test/Ice/operations/BatchOneways.rb b/ruby/test/Ice/operations/BatchOneways.rb new file mode 100644 index 00000000000..dc2ec7add80 --- /dev/null +++ b/ruby/test/Ice/operations/BatchOneways.rb @@ -0,0 +1,60 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 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. +# +# ********************************************************************** + +def batchOneways(p) + bs1 = "\0" * (10 * 1024); + + batch = Test::MyClassPrx::uncheckedCast(p.ice_batchOneway()) + + batch.ice_flushBatchRequests() # Empty flush + + p.opByteSOnewayCallCount() # Reset the call count + + for i in (0...30) + batch.opByteSOneway(bs1) + end + + count = 0 + while (count < 27) # 3 * 9 requests auto-flushed. + count += p.opByteSOnewayCallCount() + sleep(0.01) + end + + batch.ice_getConnection().flushBatchRequests() + + batch2 = Test::MyClassPrx::uncheckedCast(p.ice_batchOneway()) + + batch.ice_ping() + batch2.ice_ping() + batch.ice_flushBatchRequests() + batch.ice_getConnection().close(false) + batch.ice_ping() + batch2.ice_ping() + + batch.ice_getConnection() + batch2.ice_getConnection() + + batch.ice_ping() + batch.ice_getConnection().close(false) + + batch.ice_ping() + batch2.ice_ping() + + identity = Ice::Identity.new() + identity.name = "invalid"; + batch3 = batch.ice_identity(identity) + batch3.ice_ping() + batch3.ice_flushBatchRequests() + + # Make sure that a bogus batch request doesn't cause troubles to other ones. + batch3.ice_ping() + batch.ice_ping() + batch.ice_flushBatchRequests() + batch.ice_ping() +end diff --git a/ruby/test/Ice/operations/Client.rb b/ruby/test/Ice/operations/Client.rb new file mode 100755 index 00000000000..208d2e76b0e --- /dev/null +++ b/ruby/test/Ice/operations/Client.rb @@ -0,0 +1,69 @@ +#!/usr/bin/env ruby +# ********************************************************************** +# +# Copyright (c) 2003-2015 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 'pathname' +require 'Ice' + +slice_dir = Ice.getSliceDir +Ice::loadSlice("'-I" + slice_dir + "' Test.ice") +require './AllTests' + +def test(b) + if !b + raise RuntimeError, 'test assertion failed' + end +end + +def run(args, communicator) + myClass = allTests(communicator) + + print "testing server shutdown... " + STDOUT.flush + myClass.shutdown() + begin + myClass.opVoid() + test(false) + rescue Ice::LocalException + puts "ok" + end + + return true +end + +begin + initData = Ice::InitializationData.new + initData.properties = Ice.createProperties(ARGV) + # + # This is not necessary since we don't have AMI support (yet). + # + #initData.properties.setProperty('Ice.ThreadPool.Client.Size', '2') + #initData.properties.setProperty('Ice.ThreadPool.Client.SizeWarn', '0') + + initData.properties.setProperty("Ice.BatchAutoFlushSize", "100") + + communicator = Ice.initialize(ARGV, initData) + status = run(ARGV, communicator) +rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false +end + +if communicator + begin + communicator.destroy() + rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false + end +end + +exit(status ? 0 : 1) diff --git a/ruby/test/Ice/operations/Test.ice b/ruby/test/Ice/operations/Test.ice new file mode 100644 index 00000000000..ae711d266a2 --- /dev/null +++ b/ruby/test/Ice/operations/Test.ice @@ -0,0 +1,271 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 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; + +sequence<ByteBoolD> ByteBoolDS; +sequence<ShortIntD> ShortIntDS; +sequence<LongFloatD> LongFloatDS; +sequence<StringStringD> StringStringDS; +sequence<StringMyEnumD> StringMyEnumDS; +sequence<MyEnumStringD> MyEnumStringDS; +sequence<MyStructMyEnumD> MyStructMyEnumDS; + +dictionary<byte, ByteS> ByteByteSD; +dictionary<bool, BoolS> BoolBoolSD; +dictionary<short, ShortS> ShortShortSD; +dictionary<int, IntS> IntIntSD; +dictionary<long, LongS> LongLongSD; +dictionary<string, FloatS> StringFloatSD; +dictionary<string, DoubleS> StringDoubleSD; +dictionary<string, StringS> StringStringSD; +dictionary<MyEnum, MyEnumS> MyEnumMyEnumSD; + +class MyClass +{ + void shutdown(); + + 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); + + ByteBoolDS opByteBoolDS(ByteBoolDS p1, ByteBoolDS p2, + out ByteBoolDS p3); + + ShortIntDS opShortIntDS(ShortIntDS p1, ShortIntDS p2, + out ShortIntDS p3); + + LongFloatDS opLongFloatDS(LongFloatDS p1, LongFloatDS p2, + out LongFloatDS p3); + + StringStringDS opStringStringDS(StringStringDS p1, StringStringDS p2, + out StringStringDS p3); + + StringMyEnumDS opStringMyEnumDS(StringMyEnumDS p1, StringMyEnumDS p2, + out StringMyEnumDS p3); + + MyEnumStringDS opMyEnumStringDS(MyEnumStringDS p1, MyEnumStringDS p2, + out MyEnumStringDS p3); + + MyStructMyEnumDS opMyStructMyEnumDS(MyStructMyEnumDS p1, MyStructMyEnumDS p2, + out MyStructMyEnumDS p3); + + ByteByteSD opByteByteSD(ByteByteSD p1, ByteByteSD p2, + out ByteByteSD p3); + + BoolBoolSD opBoolBoolSD(BoolBoolSD p1, BoolBoolSD p2, + out BoolBoolSD p3); + + ShortShortSD opShortShortSD(ShortShortSD p1, ShortShortSD p2, + out ShortShortSD p3); + + IntIntSD opIntIntSD(IntIntSD p1, IntIntSD p2, + out IntIntSD p3); + + LongLongSD opLongLongSD(LongLongSD p1, LongLongSD p2, + out LongLongSD p3); + + StringFloatSD opStringFloatSD(StringFloatSD p1, StringFloatSD p2, + out StringFloatSD p3); + + StringDoubleSD opStringDoubleSD(StringDoubleSD p1, StringDoubleSD p2, + out StringDoubleSD p3); + + StringStringSD opStringStringSD(StringStringSD p1, StringStringSD p2, + out StringStringSD p3); + + MyEnumMyEnumSD opMyEnumMyEnumSD(MyEnumMyEnumSD p1, MyEnumMyEnumSD p2, + out MyEnumMyEnumSD p3); + + IntS opIntS(IntS s); + + void opByteSOneway(ByteS s); + + int opByteSOnewayCallCount(); + + Ice::Context opContext(); + + idempotent void opIdempotent(); + + ["nonmutating"] idempotent void opNonmutating(); + + byte opByte1(byte opByte1); + short opShort1(short opShort1); + int opInt1(int opInt1); + long opLong1(long opLong1); + float opFloat1(float opFloat1); + double opDouble1(double opDouble1); + string opString1(string opString1); + StringS opStringS1(StringS opStringS1); + ByteBoolD opByteBoolD1(ByteBoolD opByteBoolD1); + StringS opStringS2(StringS stringS); + ByteBoolD opByteBoolD2(ByteBoolD byteBoolD); +}; + +struct MyStruct1 +{ + string tesT; // Same name as the enclosing module + MyClass myClass; // Same name as an already defined class + string myStruct1; // Same name as the enclosing struct +}; + +class MyClass1 +{ + string tesT; // Same name as the enclosing module + MyClass myClass; // Same name as an already defined class + string myClass1; // Same name as the enclosing class +}; + +class MyDerivedClass extends MyClass +{ + void opDerived(); + MyClass1 opMyClass1(MyClass1 opMyClass1); + MyStruct1 opMyStruct1(MyStruct1 opMyStruct1); +}; + +}; diff --git a/ruby/test/Ice/operations/Twoways.rb b/ruby/test/Ice/operations/Twoways.rb new file mode 100644 index 00000000000..c11a4955fd5 --- /dev/null +++ b/ruby/test/Ice/operations/Twoways.rb @@ -0,0 +1,1160 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 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. +# +# ********************************************************************** + +def twoways(communicator, p) + # + # ice_ping + # + p.ice_ping + + # + # ice_isA + # + test(p.ice_isA(Test::MyClass::ice_staticId())) + + # + # ice_ids + # + ids = p.ice_ids + test(ids.length == 3) + test(ids[0] == "::Ice::Object") + test(ids[1] == "::Test::MyClass") + test(ids[2] == "::Test::MyDerivedClass") + + # + # ice_id + # + test(p.ice_id == Test::MyDerivedClass::ice_staticId()) + + # + # Proxy ice_staticId + # + test(Test::MyClassPrx::ice_staticId() == Test::MyClass::ice_staticId()) + test(Test::MyDerivedClassPrx::ice_staticId() == Test::MyDerivedClass::ice_staticId()) + test(Ice::ObjectPrx::ice_staticId() == Ice::Object::ice_staticId()) + + # + # opVoid + # + p.opVoid() + + # + # opByte + # + r, b = p.opByte(0xff, 0x0f) + test(b == 0xf0) + test(r == 0xff) + + # + # opBool + # + r, b = p.opBool(true, false) + test(b) + test(!r) + + # + # opShortIntLong + # + r, s, i, l = p.opShortIntLong(10, 11, 12) + test(s == 10) + test(i == 11) + test(l == 12) + test(r == 12) + + r, s, i, l = p.opShortIntLong(-32768, -2147483648, -9223372036854775808) + test(s == -32768) + test(i == -2147483648) + test(l == -9223372036854775808) + test(r == -9223372036854775808) + + r, s, i, l = p.opShortIntLong(32767, 2147483647, 9223372036854775807) + test(s == 32767) + test(i == 2147483647) + test(l == 9223372036854775807) + test(r == 9223372036854775807) + + # + # opFloatDouble + # + r, f, d = p.opFloatDouble(3.14, 1.1E10) + test(f - 3.14 < 0.001) + test(d == 1.1E10) + test(r == 1.1E10) + + # + # Test invalid ranges for numbers + # + begin + r, b = p.opByte(0x01ff, 0x01ff) + test(false) + rescue TypeError + end + + begin + r, s, i, l = p.opShortIntLong(32767 + 1, 0, 0) + test(false) + rescue TypeError + end + + begin + r, s, i, l = p.opShortIntLong(-32768 - 1, 0, 0) + test(false) + rescue TypeError + end + + begin + r, s, i, l = p.opShortIntLong(0, 2147483647 + 1, 0) + test(false) + rescue TypeError + end + + begin + r, s, i, l = p.opShortIntLong(0, -2147483648 - 1, 0) + test(false) + rescue TypeError + end + + begin + r, s, i, l = p.opShortIntLong(0, 0, 9223372036854775807 + 1) + test(false) + rescue TypeError + end + + begin + r, s, i, l = p.opShortIntLong(0, 0, -9223372036854775808 - 1) + test(false) + rescue TypeError + end + + r, f, d = p.opFloatDouble(3.402823466E38, 0.0) + r, f, d = p.opFloatDouble(-3.402823466E38, 0.0) + + begin + r, f, d = p.opFloatDouble(3.402823466E38*2, 0.0) + test(false) + rescue TypeError + end + + begin + r, f, d = p.opFloatDouble(-3.402823466E38*2, 0.0) + test(false) + rescue TypeError + end + + # + # opString + # + r, s = p.opString("hello", "world") + test(s == "world hello") + test(r == "hello world") + + # + # opMyEnum + # + r, e = p.opMyEnum(Test::MyEnum::Enum2) + test(e == Test::MyEnum::Enum2) + test(r == Test::MyEnum::Enum3) + + # + # opMyClass + # + r, c1, c2 = p.opMyClass(p) + test(Ice::proxyIdentityAndFacetEqual(c1, p)) + test(!Ice::proxyIdentityAndFacetEqual(c2, p)) + test(Ice::proxyIdentityAndFacetEqual(r, p)) + test(c1.ice_getIdentity() == communicator.stringToIdentity("test")) + test(c2.ice_getIdentity() == communicator.stringToIdentity("noSuchIdentity")) + test(r.ice_getIdentity() == communicator.stringToIdentity("test")) + r.opVoid() + c1.opVoid() + begin + c2.opVoid() + test(false) + rescue Ice::ObjectNotExistException + end + + r, c1, c2 = p.opMyClass(nil) + test(!c1) + test(c2) + test(Ice::proxyIdentityAndFacetEqual(r, p)) + r.opVoid() + + # + # opStruct + # + si1 = Test::Structure.new + si1.p = p + si1.e = Test::MyEnum::Enum3 + si1.s = Test::AnotherStruct.new + si1.s.s = "abc" + si2 = Test::Structure.new + si2.p = nil + si2.e = Test::MyEnum::Enum2 + si2.s = Test::AnotherStruct.new + si2.s.s = "def" + + rso, so = p.opStruct(si1, si2) + test(!rso.p) + test(rso.e == Test::MyEnum::Enum2) + test(rso.s.s == "def") + test(so.p == p) + test(so.e == Test::MyEnum::Enum3) + test(so.s.s == "a new string") + so.p.opVoid() + + # Test marshalling of null structs and structs with null members. + si1 = Test::Structure.new + si2 = nil + + rso, so = p.opStruct(si1, si2) + test(!rso.p) + test(rso.e == Test::MyEnum::Enum1) + test(rso.s.s == "") + test(!so.p) + test(so.e == Test::MyEnum::Enum1) + test(so.s.s == "a new string") + + # + # opByteS + # + bsi1 = [0x01, 0x11, 0x12, 0x22] + bsi2 = [0xf1, 0xf2, 0xf3, 0xf4] + + rso, bso = p.opByteS(bsi1, bsi2) + test(bso.length == 4) + test(bso.unpack("C*").reverse() == bsi1) + arr = bsi1.dup().concat(bsi2) + test(rso.length == 8) + test(rso.unpack("C*") == arr) + + # + # opBoolS + # + bsi1 = [true, true, false] + bsi2 = [false] + + rso, bso = p.opBoolS(bsi1, bsi2) + test(bso.length == 4) + test(bso[0]) + test(bso[1]) + test(!bso[2]) + test(!bso[3]) + test(rso.length == 3) + test(!rso[0]) + test(rso[1]) + test(rso[2]) + + # + # opShortIntLongS + # + ssi = [1, 2, 3] + isi = [5, 6, 7, 8] + lsi = [10, 30, 20] + + rso, sso, iso, lso = p.opShortIntLongS(ssi, isi, lsi) + 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] == 10) + test(lso[1] == 30) + test(lso[2] == 20) + test(lso[3] == 10) + test(lso[4] == 30) + test(lso[5] == 20) + test(rso.length == 3) + test(rso[0] == 10) + test(rso[1] == 30) + test(rso[2] == 20) + + # + # opFloatDoubleS + # + fsi = [3.14, 1.11] + dsi = [1.1E10, 1.2E10, 1.3E10] + + rso, fso, dso = p.opFloatDoubleS(fsi, dsi) + test(fso.length == 2) + test(fso[0] - 3.14 < 0.001) + test(fso[1] - 1.11 < 0.001) + test(dso.length == 3) + test(dso[0] == 1.3E10) + test(dso[1] == 1.2E10) + test(dso[2] == 1.1E10) + test(rso.length == 5) + test(rso[0] == 1.1E10) + test(rso[1] == 1.2E10) + test(rso[2] == 1.3E10) + test(rso[3] - 3.14 < 0.001) + test(rso[4] - 1.11 < 0.001) + + # + # opStringS + # + ssi1 = ['abc', 'de', 'fghi'] + ssi2 = ['xyz'] + + rso, sso = p.opStringS(ssi1, ssi2) + test(sso.length == 4) + test(sso[0] == "abc") + test(sso[1] == "de") + test(sso[2] == "fghi") + test(sso[3] == "xyz") + test(rso.length == 3) + test(rso[0] == "fghi") + test(rso[1] == "de") + test(rso[2] == "abc") + + # + # opByteSS + # + bsi1 = [[0x01, 0x11, 0x12], [0xff]] + bsi2 = [[0x0e], [0xf2, 0xf1]] + + rso, bso = p.opByteSS(bsi1, bsi2) + test(bso.length == 2) + test(bso[0].length == 1) + test(bso[0].unpack("C*") == [0xff]) + test(bso[1].length == 3) + test(bso[1].unpack("C*") == [0x01, 0x11, 0x12]) + test(rso.length == 4) + test(rso[0].length == 3) + test(rso[0].unpack("C*") == [0x01, 0x11, 0x12]) + test(rso[1].length == 1) + test(rso[1].unpack("C*") == [0xff]) + test(rso[2].length == 1) + test(rso[2].unpack("C*") == [0x0e]) + test(rso[3].length == 2) + test(rso[3].unpack("C*") == [0xf2, 0xf1]) + + # + # opBoolSS + # + bsi1 = [[true], [false], [true, true]]; + bsi2 = [[false, false, true]]; + + rso, bso = p.opBoolSS(bsi1, bsi2); + test(bso.length == 4); + test(bso[0].length == 1); + test(bso[0][0]); + test(bso[1].length == 1); + test(!bso[1][0]); + test(bso[2].length == 2); + test(bso[2][0]); + test(bso[2][1]); + test(bso[3].length == 3); + test(!bso[3][0]); + test(!bso[3][1]); + test(bso[3][2]); + test(rso.length == 3); + test(rso[0].length == 2); + test(rso[0][0]); + test(rso[0][1]); + test(rso[1].length == 1); + test(!rso[1][0]); + test(rso[2].length == 1); + test(rso[2][0]); + + # + # opShortIntLongSS + # + ssi = [[1, 2, 5], [13], []]; + isi = [[24, 98], [42]]; + lsi = [[496, 1729]]; + + rso, sso, iso, lso = p.opShortIntLongSS(ssi, isi, lsi); + test(rso.length == 1); + test(rso[0].length == 2); + test(rso[0][0] == 496); + test(rso[0][1] == 1729); + test(sso.length == 3); + test(sso[0].length == 3); + test(sso[0][0] == 1); + test(sso[0][1] == 2); + test(sso[0][2] == 5); + test(sso[1].length == 1); + test(sso[1][0] == 13); + test(sso[2].length == 0); + test(iso.length == 2); + test(iso[0].length == 1); + test(iso[0][0] == 42); + test(iso[1].length == 2); + test(iso[1][0] == 24); + test(iso[1][1] == 98); + test(lso.length == 2); + test(lso[0].length == 2); + test(lso[0][0] == 496); + test(lso[0][1] == 1729); + test(lso[1].length == 2); + test(lso[1][0] == 496); + test(lso[1][1] == 1729); + + # + # opFloatDoubleSS + # + fsi = [[3.14], [1.11], []] + dsi = [[1.1E10, 1.2E10, 1.3E10]] + + rso, fso, dso = p.opFloatDoubleSS(fsi, dsi) + test(fso.length == 3) + test(fso[0].length == 1) + test(fso[0][0] - 3.14 < 0.001) + test(fso[1].length == 1) + test(fso[1][0] - 1.11 < 0.001) + 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(rso.length == 2) + test(rso[0].length == 3) + test(rso[0][0] == 1.1E10) + test(rso[0][1] == 1.2E10) + test(rso[0][2] == 1.3E10) + test(rso[1].length == 3) + test(rso[1][0] == 1.1E10) + test(rso[1][1] == 1.2E10) + test(rso[1][2] == 1.3E10) + + # + # opStringSS + # + ssi1 = [['abc'], ['de', 'fghi']] + ssi2 = [[], [], ['xyz']] + + rso, sso = p.opStringSS(ssi1, ssi2) + 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(rso.length == 3) + test(rso[0].length == 1) + test(rso[0][0] == "xyz") + test(rso[1].length == 0) + test(rso[2].length == 0) + + # + # opStringSSS + # + sssi1 = [[['abc', 'de'], ['xyz']], [['hello']]] + sssi2 = [[['', ''], ['abcd']], [['']], []] + + rsso, ssso = p.opStringSSS(sssi1, sssi2) + 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(rsso.length == 3) + test(rsso[0].length == 0) + test(rsso[1].length == 1) + test(rsso[1][0].length == 1) + test(rsso[2].length == 2) + test(rsso[2][0].length == 2) + test(rsso[2][1].length == 1) + test(rsso[1][0][0] == "") + test(rsso[2][0][0] == "") + test(rsso[2][0][1] == "") + test(rsso[2][1][0] == "abcd") + + # + # opByteBoolD + # + di1 = {10=>true, 100=>false} + di2 = {10=>true, 11=>false, 101=>true} + + ro, d = p.opByteBoolD(di1, di2) + + test(d == di1) + test(ro.length == 4) + test(ro[10]) + test(!ro[11]) + test(!ro[100]) + test(ro[101]) + + # + # opShortIntD + # + di1 = {110=>-1, 1100=>123123} + di2 = {110=>-1, 111=>-100, 1101=>0} + + ro, d = p.opShortIntD(di1, di2) + + test(d == di1) + test(ro.length == 4) + test(ro[110] == -1) + test(ro[111] == -100) + test(ro[1100] == 123123) + test(ro[1101] == 0) + + # + # opLongFloatD + # + di1 = {999999110=>-1.1, 999999111=>123123.2} + di2 = {999999110=>-1.1, 999999120=>-100.4, 999999130=>0.5} + + ro, d = p.opLongFloatD(di1, di2) + + for k in d.keys + test((d[k] - di1[k]).abs < 0.01) + end + test(ro.length == 4) + test(ro[999999110] - -1.1 < 0.01) + test(ro[999999120] - -100.4 < 0.01) + test(ro[999999111] - 123123.2 < 0.01) + test(ro[999999130] - 0.5 < 0.01) + + # + # opStringStringD + # + di1 = {'foo'=>'abc -1.1', 'bar'=>'abc 123123.2'} + di2 = {'foo'=>'abc -1.1', 'FOO'=>'abc -100.4', 'BAR'=>'abc 0.5'} + + ro, d = p.opStringStringD(di1, di2) + + test(d == di1) + test(ro.length == 4) + test(ro["foo"] == "abc -1.1") + test(ro["FOO"] == "abc -100.4") + test(ro["bar"] == "abc 123123.2") + test(ro["BAR"] == "abc 0.5") + + # + # opStringMyEnumD + # + di1 = {'abc'=>Test::MyEnum::Enum1, ''=>Test::MyEnum::Enum2} + di2 = {'abc'=>Test::MyEnum::Enum1, 'qwerty'=>Test::MyEnum::Enum3, 'Hello!!'=>Test::MyEnum::Enum2} + + ro, d = p.opStringMyEnumD(di1, di2) + + test(d == di1) + test(ro.length == 4) + test(ro["abc"] == Test::MyEnum::Enum1) + test(ro["qwerty"] == Test::MyEnum::Enum3) + test(ro[""] == Test::MyEnum::Enum2) + test(ro["Hello!!"] == Test::MyEnum::Enum2) + + # + # opMyEnumStringD + # + di1 = {Test::MyEnum::Enum1=>'abc'} + di2 = {Test::MyEnum::Enum2=>'Hello!!', Test::MyEnum::Enum3=>'qwerty'} + + ro, d = p.opMyEnumStringD(di1, di2) + + test(d == di1) + test(ro.length == 3) + test(ro[Test::MyEnum::Enum1] == "abc") + test(ro[Test::MyEnum::Enum2] == "Hello!!") + test(ro[Test::MyEnum::Enum3] == "qwerty") + + # + # opMyStructMyEnumD + # + s11 = Test::MyStruct.new + s11.i = 1 + s11.j = 1 + s12 = Test::MyStruct.new + s12.i = 1 + s12.j = 2 + s22 = Test::MyStruct.new + s22.i = 2 + s22.j = 2 + s23 = Test::MyStruct.new + s23.i = 2 + s23.j = 3 + di1 = {s11=>Test::MyEnum::Enum1, s12=>Test::MyEnum::Enum2} + di2 = {s11=>Test::MyEnum::Enum1, s22=>Test::MyEnum::Enum3, s23=>Test::MyEnum::Enum2} + + ro, d = p.opMyStructMyEnumD(di1, di2) + + test(d == di1) + test(ro.length == 4) + test(ro[s11] == Test::MyEnum::Enum1) + test(ro[s12] == Test::MyEnum::Enum2) + test(ro[s22] == Test::MyEnum::Enum3) + test(ro[s23] == Test::MyEnum::Enum2) + + # + # opByteBoolDS + # + # di1 = {10=>true, 100=>false} + # di2 = {10=>true, 11=>false, 101=>true} + + dsi1 = [{ 10=>true, 100=>false }, { 10=>true, 11=>false, 101=>true }] + dsi2 = [{ 100=>false, 101=>false }] + + ro, d = p.opByteBoolDS(dsi1, dsi2) + + test(ro.length == 2) + test(ro[0].length == 3) + test(ro[0][10]) + test(!ro[0][11]) + test(ro[0][101]) + test(ro[1].length == 2) + test(ro[1][10]) + test(!ro[1][100]) + test(d.length == 3) + test(d[0].length == 2) + test(!d[0][100]) + test(!d[0][101]) + test(d[1].length == 2) + test(d[1][10]) + test(!d[1][100]) + test(d[2].length == 3) + test(d[2][10]) + test(!d[2][11]) + test(d[2][101]) + + # + # opShortIntDS + # + dsi1 = [{ 110=>-1, 1100=>123123 }, { 110=>-1, 111=>-100, 1101=>0 }] + dsi2 = [{ 100=>-1001 }] + + ro, d = p.opShortIntDS(dsi1, dsi2) + + test(ro.length == 2) + test(ro[0].length == 3) + test(ro[0][110] == -1) + test(ro[0][111] == -100) + test(ro[0][1101] == 0) + test(ro[1].length == 2) + test(ro[1][110] == -1) + test(ro[1][1100] == 123123) + + test(d.length == 3) + test(d[0].length == 1) + test(d[0][100] == -1001) + test(d[1].length == 2) + test(d[1][110] == -1) + test(d[1][1100] == 123123) + test(d[2].length == 3) + test(d[2][110] == -1) + test(d[2][111] == -100) + test(d[2][1101] == 0) + + # + # opLongFloatDS + # + dsi1 = [{ 999999110=>-1.1, 999999111=>123123.2 }, { 999999110=>-1.1, 999999120=>-100.4, 999999130=>0.5 }] + dsi2 = [{ 999999140=>3.14 }] + + ro, d = p.opLongFloatDS(dsi1, dsi2) + + test(ro.length == 2) + test(ro[0].length == 3) + test(ro[0][999999110] - -1.1 < 0.01) + test(ro[0][999999120] - -100.4 < 0.01) + test(ro[0][999999130] - 0.5 < 0.01) + test(ro[1].length == 2) + test(ro[1][999999110] - -1.1 < 0.01) + test(ro[1][999999111] - 123123.2 < 0.01) + test(d.length == 3) + test(d[0].length == 1) + test(d[0][999999140] - 3.14 < 0.01) + test(d[1].length == 2) + test(d[1][999999110] - -1.1 < 0.01) + test(d[1][999999111] - 123123.2 < 0.01) + test(d[2].length == 3) + test(d[2][999999110] - -1.1 < 0.01) + test(d[2][999999120] - -100.4 < 0.01) + test(d[2][999999130] - 0.5 < 0.01) + + # + # opStringStringDS + # + + dsi1 = [{ "foo"=>"abc -1.1", "bar"=>"abc 123123.2" }, { "foo"=>"abc -1.1", "FOO"=>"abc -100.4", "BAR"=>"abc 0.5" }] + dsi2 = [{ "f00"=>"ABC -3.14" }] + + ro, d = p.opStringStringDS(dsi1, dsi2) + + test(ro.length == 2) + test(ro[0].length == 3) + test(ro[0]["foo"] == "abc -1.1") + test(ro[0]["FOO"] == "abc -100.4") + test(ro[0]["BAR"] == "abc 0.5") + test(ro[1].length == 2) + test(ro[1]["foo"] == "abc -1.1") + test(ro[1]["bar"] == "abc 123123.2") + + test(d.length == 3) + test(d[0].length == 1) + test(d[0]["f00"] == "ABC -3.14") + test(d[1].length == 2) + test(d[1]["foo"] == "abc -1.1") + test(d[1]["bar"] == "abc 123123.2") + test(d[2].length == 3) + test(d[2]["foo"] == "abc -1.1") + test(d[2]["FOO"] == "abc -100.4") + test(d[2]["BAR"] == "abc 0.5") + + # + # opStringMyEnumDS + # + dsi1 = [ + { "abc"=>Test::MyEnum::Enum1, ""=>Test::MyEnum::Enum2 }, + { "abc"=>Test::MyEnum::Enum1, "qwerty"=>Test::MyEnum::Enum3, "Hello!!"=>Test::MyEnum::Enum2 } + ] + + dsi2 = [{ "Goodbye"=>Test::MyEnum::Enum1 }] + + ro, d = p.opStringMyEnumDS(dsi1, dsi2) + + test(ro.length == 2) + test(ro[0].length == 3) + test(ro[0]["abc"] == Test::MyEnum::Enum1) + test(ro[0]["qwerty"] == Test::MyEnum::Enum3) + test(ro[0]["Hello!!"] == Test::MyEnum::Enum2) + test(ro[1].length == 2) + test(ro[1]["abc"] == Test::MyEnum::Enum1) + test(ro[1][""] == Test::MyEnum::Enum2) + + test(d.length == 3) + test(d[0].length == 1) + test(d[0]["Goodbye"] == Test::MyEnum::Enum1) + test(d[1].length == 2) + test(d[1]["abc"] == Test::MyEnum::Enum1) + test(d[1][""] == Test::MyEnum::Enum2) + test(d[2].length == 3) + test(d[2]["abc"] == Test::MyEnum::Enum1) + test(d[2]["qwerty"] == Test::MyEnum::Enum3) + test(d[2]["Hello!!"] == Test::MyEnum::Enum2) + + # + # opMyEnumStringDS + # + dsi1 = [{ Test::MyEnum::Enum1=>'abc' }, { Test::MyEnum::Enum2=>'Hello!!', Test::MyEnum::Enum3=>'qwerty'}] + dsi2 = [{ Test::MyEnum::Enum1=>'Goodbye' }] + + ro, d = p.opMyEnumStringDS(dsi1, dsi2) + + test(ro.length == 2) + test(ro[0].length == 2) + test(ro[0][Test::MyEnum::Enum2] == "Hello!!") + test(ro[0][Test::MyEnum::Enum3] == "qwerty") + test(ro[1].length == 1) + test(ro[1][Test::MyEnum::Enum1] == "abc") + + test(d.length == 3) + test(d[0].length == 1) + test(d[0][Test::MyEnum::Enum1] == "Goodbye") + test(d[1].length == 1) + test(d[1][Test::MyEnum::Enum1] == "abc") + test(d[2].length == 2) + test(d[2][Test::MyEnum::Enum2] == "Hello!!") + test(d[2][Test::MyEnum::Enum3] == "qwerty") + + # + # opMyStructMyEnumDS + # + s11 = Test::MyStruct.new + s11.i = 1 + s11.j = 1 + s12 = Test::MyStruct.new + s12.i = 1 + s12.j = 2 + s22 = Test::MyStruct.new + s22.i = 2 + s22.j = 2 + s23 = Test::MyStruct.new + s23.i = 2 + s23.j = 3 + + dsi1 = [ + { s11=>Test::MyEnum::Enum1, s12=>Test::MyEnum::Enum2 }, + { s11=>Test::MyEnum::Enum1, s22=>Test::MyEnum::Enum3, s23=>Test::MyEnum::Enum2 } + ] + dsi2 = [{ s23=>Test::MyEnum::Enum3 }] + + ro, d = p.opMyStructMyEnumDS(dsi1, dsi2) + + test(ro.length == 2) + test(ro[0].length == 3) + test(ro[0][s11] == Test::MyEnum::Enum1) + test(ro[0][s22] == Test::MyEnum::Enum3) + test(ro[0][s23] == Test::MyEnum::Enum2) + test(ro[1].length == 2) + test(ro[1][s11] == Test::MyEnum::Enum1) + test(ro[1][s12] == Test::MyEnum::Enum2) + + test(d.length == 3) + test(d[0].length == 1) + test(d[0][s23] == Test::MyEnum::Enum3) + test(d[1].length == 2) + test(d[1][s11] == Test::MyEnum::Enum1) + test(d[1][s12] == Test::MyEnum::Enum2) + test(d[2].length == 3) + test(d[2][s11] == Test::MyEnum::Enum1) + test(d[2][s22] == Test::MyEnum::Enum3) + test(d[2][s23] == Test::MyEnum::Enum2) + + # + # opByteByteSD + # + sdi1 = { 0x01=>[0x01, 0x11], 0x22=>[0x12] } + sdi2 = { 0xf1=>[0xf2, 0xf3] } + + ro, d = p.opByteByteSD(sdi1, sdi2) + + test(d.length == 1) + test(d[0xf1].length == 2) + test(d[0xf1].unpack("C*") == [0xf2, 0xf3]) + test(ro.length == 3) + test(ro[0x01].length == 2) + test(ro[0x01].unpack("C*") == [0x01, 0x11]) + test(ro[0x22].length == 1) + test(ro[0x22].unpack("C*") == [0x12]) + test(ro[0xf1].length == 2) + test(ro[0xf1].unpack("C*") == [0xf2, 0xf3]) + + # + # opBoolBoolSD + # + sdi1 = { false=>[true, false], true=>[false, true, true] } + sdi2 = { false=>[true, false] } + + ro, d = p.opBoolBoolSD(sdi1, sdi2) + + test(d.length == 1) + test(d[false].length == 2) + test(d[false][0]) + test(!d[false][1]) + test(ro.length == 2) + test(ro[false].length == 2) + test(ro[false][0]) + test(!ro[false][1]) + test(ro[true].length == 3) + test(!ro[true][0]) + test(ro[true][1]) + test(ro[true][2]) + + # + # opShortShortSD + # + sdi1 = { 1=>[1, 2, 3], 2=>[4, 5] } + sdi2 = { 4=>[6, 7] } + + ro, d = p.opShortShortSD(sdi1, sdi2) + + test(d.length == 1) + test(d[4].length == 2) + test(d[4][0] == 6) + test(d[4][1] == 7) + test(ro.length == 3) + test(ro[1].length == 3) + test(ro[1][0] == 1) + test(ro[1][1] == 2) + test(ro[1][2] == 3) + test(ro[2].length == 2) + test(ro[2][0] == 4) + test(ro[2][1] == 5) + test(ro[4].length == 2) + test(ro[4][0] == 6) + test(ro[4][1] == 7) + + # + # opIntIntSD + # + sdi1 = { 100=>[100, 200, 300], 200=>[400, 500] } + sdi2 = { 400=>[600, 700] } + + ro, d = p.opIntIntSD(sdi1, sdi2) + + test(d.length == 1) + test(d[400].length == 2) + test(d[400][0] == 600) + test(d[400][1] == 700) + test(ro.length == 3) + test(ro[100].length == 3) + test(ro[100][0] == 100) + test(ro[100][1] == 200) + test(ro[100][2] == 300) + test(ro[200].length == 2) + test(ro[200][0] == 400) + test(ro[200][1] == 500) + test(ro[400].length == 2) + test(ro[400][0] == 600) + test(ro[400][1] == 700) + + # + # opLongLongSD + # + sdi1 = { 999999990=>[999999110, 999999111, 999999110], 999999991=>[999999120, 999999130] } + sdi2 = { 999999992=>[999999110, 999999120] } + + ro, d = p.opLongLongSD(sdi1, sdi2) + + test(d.length == 1) + test(d[999999992].length == 2) + test(d[999999992][0] == 999999110) + test(d[999999992][1] == 999999120) + test(ro.length == 3) + test(ro[999999990].length == 3) + test(ro[999999990][0] == 999999110) + test(ro[999999990][1] == 999999111) + test(ro[999999990][2] == 999999110) + test(ro[999999991].length == 2) + test(ro[999999991][0] == 999999120) + test(ro[999999991][1] == 999999130) + test(ro[999999992].length == 2) + test(ro[999999992][0] == 999999110) + test(ro[999999992][1] == 999999120) + + # + # opStringFloatSD + # + sdi1 = { "abc"=>[-1.1, 123123.2, 100.0], "ABC"=>[42.24, -1.61] } + sdi2 = { "aBc"=>[-3.14, 3.14] } + + ro, d = p.opStringFloatSD(sdi1, sdi2) + + test(d.length == 1) + test(d["aBc"].length == 2) + test(d["aBc"][0] - -3.14 < 0.01) + test(d["aBc"][1] - 3.14 < 0.01) + + test(ro.length == 3) + test(ro["abc"].length == 3) + test(ro["abc"][0] - -1.1 < 0.01) + test(ro["abc"][1] - 123123.2 < 0.01) + test(ro["abc"][2] - 100.0 < 0.01) + test(ro["ABC"].length == 2) + test(ro["ABC"][0] - 42.24 < 0.01) + test(ro["ABC"][1] - -1.61 < 0.01) + test(ro["aBc"].length == 2) + test(ro["aBc"][0] - -3.14 < 0.01) + test(ro["aBc"][1] - 3.14 < 0.01) + + # + # opStringDoubleSD + # + sdi1 = { "Hello!!"=>[1.1E10, 1.2E10, 1.3E10], "Goodbye"=>[1.4E10, 1.5E10] } + sdi2 = { ""=>[1.6E10, 1.7E10] } + + ro, d = p.opStringDoubleSD(sdi1, sdi2); + + test(d.length == 1) + test(d[""].length == 2) + test(d[""][0] == 1.6E10) + test(d[""][1] == 1.7E10) + test(ro.length == 3) + test(ro["Hello!!"].length == 3) + test(ro["Hello!!"][0] == 1.1E10) + test(ro["Hello!!"][1] == 1.2E10) + test(ro["Hello!!"][2] == 1.3E10) + test(ro["Goodbye"].length == 2) + test(ro["Goodbye"][0] == 1.4E10) + test(ro["Goodbye"][1] == 1.5E10) + test(ro[""].length == 2) + test(ro[""][0] == 1.6E10) + test(ro[""][1] == 1.7E10) + + # + # opStringStringSD + # + sdi1 = { "abc"=>["abc", "de", "fghi"] , "def"=>["xyz", "or"] } + sdi2 = { "ghi"=>["and", "xor"] } + + ro, d = p.opStringStringSD(sdi1, sdi2) + + test(d.length == 1) + test(d["ghi"].length == 2) + test(d["ghi"][0] == "and") + test(d["ghi"][1] == "xor") + test(ro.length == 3) + test(ro["abc"].length == 3) + test(ro["abc"][0] == "abc") + test(ro["abc"][1] == "de") + test(ro["abc"][2] == "fghi") + test(ro["def"].length == 2) + test(ro["def"][0] == "xyz") + test(ro["def"][1] == "or") + test(ro["ghi"].length == 2) + test(ro["ghi"][0] == "and") + test(ro["ghi"][1] == "xor") + + # + # opMyEnumMyEnumSD + # + sdi1 = { + Test::MyEnum::Enum3=>[Test::MyEnum::Enum1, Test::MyEnum::Enum1, Test::MyEnum::Enum2], + Test::MyEnum::Enum2=>[Test::MyEnum::Enum1, Test::MyEnum::Enum2] + } + sdi2 = { Test::MyEnum::Enum1=>[Test::MyEnum::Enum3, Test::MyEnum::Enum3] } + + ro, d = p.opMyEnumMyEnumSD(sdi1, sdi2) + + test(d.length == 1) + test(d[Test::MyEnum::Enum1].length == 2) + test(d[Test::MyEnum::Enum1][0] == Test::MyEnum::Enum3) + test(d[Test::MyEnum::Enum1][1] == Test::MyEnum::Enum3) + test(ro.length == 3) + test(ro[Test::MyEnum::Enum3].length == 3) + test(ro[Test::MyEnum::Enum3][0] == Test::MyEnum::Enum1) + test(ro[Test::MyEnum::Enum3][1] == Test::MyEnum::Enum1) + test(ro[Test::MyEnum::Enum3][2] == Test::MyEnum::Enum2) + test(ro[Test::MyEnum::Enum2].length == 2) + test(ro[Test::MyEnum::Enum2][0] == Test::MyEnum::Enum1) + test(ro[Test::MyEnum::Enum2][1] == Test::MyEnum::Enum2) + test(ro[Test::MyEnum::Enum1].length == 2) + test(ro[Test::MyEnum::Enum1][0] == Test::MyEnum::Enum3) + test(ro[Test::MyEnum::Enum1][1] == Test::MyEnum::Enum3) + + # + # opIntS + # + lengths = [ 0, 1, 2, 126, 127, 128, 129, 253, 254, 255, 256, 257, 1000 ] + for l in lengths + s = [] + for i in (0...l) + s.push(i) + end + r = p.opIntS(s) + test(r.length == l) + for j in (0...r.length) + test(r[j] == -j) + end + end + + # + # opContext + # + ctx = {'one'=>'ONE', 'two'=>'TWO', 'three'=>'THREE'} + + r = p.opContext() + test(p.ice_getContext().length == 0) + test(r != ctx) + + r = p.opContext(ctx) + test(p.ice_getContext().length == 0) + test(r == ctx) + + p2 = Test::MyClassPrx::checkedCast(p.ice_context(ctx)) + test(p2.ice_getContext() == ctx) + r = p2.opContext() + test(r == ctx) + r = p2.opContext(ctx) + test(r == ctx) + + # + # opIdempotent + # + p.opIdempotent + + # + # opNonmutating + # + p.opNonmutating + + test(p.opByte1(0xFF) == 0xFF) + test(p.opShort1(0x7FFF) == 0x7FFF) + test(p.opInt1(0x7FFFFFFF) == 0x7FFFFFFF) + test(p.opLong1(0x7FFFFFFFFFFFFFFF) == 0x7FFFFFFFFFFFFFFF) + test(p.opFloat1(1.0) == 1.0) + test(p.opDouble1(1.0) == 1.0) + test(p.opString1("opString1") == "opString1") + test(p.opStringS1(nil).length == 0) + test(p.opByteBoolD1(nil).length == 0) + test(p.opStringS2(nil).length == 0) + test(p.opByteBoolD2(nil).length == 0) + + d = Test::MyDerivedClassPrx::uncheckedCast(p) + s = Test::MyStruct1.new + s.tesT = "Test.MyStruct1.s" + s.myClass = nil + s.myStruct1 = "Test.MyStruct1.myStruct1" + s = d.opMyStruct1(s) + test(s.tesT == "Test.MyStruct1.s") + test(s.myClass == nil) + test(s.myStruct1 == "Test.MyStruct1.myStruct1") + c = Test::MyClass1.new + c.tesT = "Test.MyClass1.testT" + c.myClass = nil + c.myClass1 = "Test.MyClass1.myClass1" + c = d.opMyClass1(c) + test(c.tesT == "Test.MyClass1.testT") + test(c.myClass == nil) + test(c.myClass1 == "Test.MyClass1.myClass1") + + # + # Test implicit context propagation + # + impls = [ 'Shared', 'PerThread' ] + for i in impls + initData = Ice::InitializationData.new + initData.properties = communicator.getProperties().clone() + initData.properties.setProperty('Ice.ImplicitContext', i) + ic = Ice::initialize(initData) + + ctx = {'one'=>'ONE', 'two'=>'TWO', 'three'=>'THREE'} + + p = Test::MyClassPrx::uncheckedCast(ic.stringToProxy('test:default -p 12010')) + + ic.getImplicitContext().setContext(ctx) + test(ic.getImplicitContext().getContext() == ctx) + test(p.opContext() == ctx) + + test(ic.getImplicitContext().containsKey('zero') == false); + r = ic.getImplicitContext().put('zero', 'ZERO'); + test(r == ''); + test(ic.getImplicitContext().containsKey('zero') == true); + test(ic.getImplicitContext().get('zero') == 'ZERO'); + + ctx = ic.getImplicitContext().getContext() + test(p.opContext() == ctx) + + prxContext = {'one'=>'UN', 'four'=>'QUATRE'} + + combined = ctx.clone() + combined.update(prxContext) + test(combined['one'] == 'UN') + + p = Test::MyClassPrx::uncheckedCast(p.ice_context(prxContext)) + ic.getImplicitContext().setContext({}) + test(p.opContext() == prxContext) + + ic.getImplicitContext().setContext(ctx) + test(p.opContext() == combined) + + test(ic.getImplicitContext().remove('one') == 'ONE'); + + ic.destroy() + end +end diff --git a/ruby/test/Ice/operations/run.py b/ruby/test/Ice/operations/run.py new file mode 100755 index 00000000000..541377d6ca6 --- /dev/null +++ b/ruby/test/Ice/operations/run.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 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/ruby/test/Ice/optional/AllTests.rb b/ruby/test/Ice/optional/AllTests.rb new file mode 100644 index 00000000000..1a4990314b2 --- /dev/null +++ b/ruby/test/Ice/optional/AllTests.rb @@ -0,0 +1,723 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 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. +# +# ********************************************************************** + +def test(b) + if !b + raise RuntimeError, 'test assertion failed' + end +end + +def allTests(communicator) + print "testing stringToProxy... " + STDOUT.flush + ref = "initial:default -p 12010" + base = communicator.stringToProxy(ref) + test(base) + puts "ok" + + print "testing checked cast... " + STDOUT.flush + initial = Test::InitialPrx::checkedCast(base) + test(initial) + test(initial == base) + puts "ok" + + print "testing optional data members... " + STDOUT.flush + + oo1 = Test::OneOptional.new + test(oo1.a == Ice::Unset) + oo1.a = 15 + + oo2 = Test::OneOptional.new(16) + test(oo2.a == 16) + + mo1 = Test::MultiOptional.new() + test(mo1.a == Ice::Unset) + test(mo1.b == Ice::Unset) + test(mo1.c == Ice::Unset) + test(mo1.d == Ice::Unset) + test(mo1.e == Ice::Unset) + test(mo1.f == Ice::Unset) + test(mo1.g == Ice::Unset) + test(mo1.h == Ice::Unset) + test(mo1.i == Ice::Unset) + test(mo1.j == Ice::Unset) + test(mo1.k == Ice::Unset) + test(mo1.bs == Ice::Unset) + test(mo1.ss == Ice::Unset) + test(mo1.iid == Ice::Unset) + test(mo1.sid == Ice::Unset) + test(mo1.fs == Ice::Unset) + test(mo1.vs == Ice::Unset) + + test(mo1.shs == Ice::Unset) + test(mo1.es == Ice::Unset) + test(mo1.fss == Ice::Unset) + test(mo1.vss == Ice::Unset) + test(mo1.oos == Ice::Unset) + test(mo1.oops == Ice::Unset) + + test(mo1.ied == Ice::Unset) + test(mo1.ifsd == Ice::Unset) + test(mo1.ivsd == Ice::Unset) + test(mo1.iood == Ice::Unset) + test(mo1.ioopd == Ice::Unset) + + test(mo1.bos == Ice::Unset) + + fs = Test::FixedStruct.new(78) + vs = Test::VarStruct.new("hello") + mo1 = Test::MultiOptional.new(15, true, 19, 78, 99, 5.5, 1.0, "test", Test::MyEnum::MyEnumMember, \ + Test::MultiOptionalPrx::uncheckedCast(communicator.stringToProxy("test")), \ + nil, [5], ["test", "test2"], {4=>3}, {"test"=>10}, fs, vs, [1], \ + [Test::MyEnum::MyEnumMember, Test::MyEnum::MyEnumMember], \ + [ fs ], [ vs ], [ oo1 ], \ + [ Test::OneOptionalPrx::uncheckedCast(communicator.stringToProxy("test")) ], \ + {4=>Test::MyEnum::MyEnumMember}, {4=>fs}, {5=>vs}, {5=>Test::OneOptional.new(15)}, \ + {5=>Test::OneOptionalPrx::uncheckedCast(communicator.stringToProxy("test"))}, \ + [false, true, false]) + + test(mo1.a == 15) + test(mo1.b == true) + test(mo1.c == 19) + test(mo1.d == 78) + test(mo1.e == 99) + test(mo1.f == 5.5) + test(mo1.g == 1.0) + test(mo1.h == "test") + test(mo1.i == Test::MyEnum::MyEnumMember) + test(mo1.j == Test::MultiOptionalPrx::uncheckedCast(communicator.stringToProxy("test"))) + test(mo1.k == nil) + test(mo1.bs == [5]) + test(mo1.ss == ["test", "test2"]) + test(mo1.iid[4] == 3) + test(mo1.sid["test"] == 10) + test(mo1.fs == Test::FixedStruct.new(78)) + test(mo1.vs == Test::VarStruct.new("hello")) + + test(mo1.shs[0] == 1) + test(mo1.es[0] == Test::MyEnum::MyEnumMember && mo1.es[1] == Test::MyEnum::MyEnumMember) + test(mo1.fss[0] == Test::FixedStruct.new(78)) + test(mo1.vss[0] == Test::VarStruct.new("hello")) + test(mo1.oos[0] == oo1) + test(mo1.oops[0] == Test::OneOptionalPrx::uncheckedCast(communicator.stringToProxy("test"))) + + test(mo1.ied[4] == Test::MyEnum::MyEnumMember) + test(mo1.ifsd[4] == Test::FixedStruct.new(78)) + test(mo1.ivsd[5] == Test::VarStruct.new("hello")) + test(mo1.iood[5].a == 15) + test(mo1.ioopd[5] == Test::OneOptionalPrx::uncheckedCast(communicator.stringToProxy("test"))) + + test(mo1.bos == [false, true, false]) + + puts "ok" + + print "testing marshaling... " + STDOUT.flush + + oo4 = initial.pingPong(Test::OneOptional.new) + test(oo4.a == Ice::Unset) + + oo5 = initial.pingPong(oo1) + test(oo1.a == oo5.a) + + mo4 = initial.pingPong(Test::MultiOptional.new) + test(mo4.a == Ice::Unset) + test(mo4.b == Ice::Unset) + test(mo4.c == Ice::Unset) + test(mo4.d == Ice::Unset) + test(mo4.e == Ice::Unset) + test(mo4.f == Ice::Unset) + test(mo4.g == Ice::Unset) + test(mo4.h == Ice::Unset) + test(mo4.i == Ice::Unset) + test(mo4.j == Ice::Unset) + test(mo4.k == Ice::Unset) + test(mo4.bs == Ice::Unset) + test(mo4.ss == Ice::Unset) + test(mo4.iid == Ice::Unset) + test(mo4.sid == Ice::Unset) + test(mo4.fs == Ice::Unset) + test(mo4.vs == Ice::Unset) + + test(mo4.shs == Ice::Unset) + test(mo4.es == Ice::Unset) + test(mo4.fss == Ice::Unset) + test(mo4.vss == Ice::Unset) + test(mo4.oos == Ice::Unset) + test(mo4.oops == Ice::Unset) + + test(mo4.ied == Ice::Unset) + test(mo4.ifsd == Ice::Unset) + test(mo4.ivsd == Ice::Unset) + test(mo4.iood == Ice::Unset) + test(mo4.ioopd == Ice::Unset) + + test(mo4.bos == Ice::Unset) + + mo5 = initial.pingPong(mo1) + test(mo5.a == mo1.a) + test(mo5.b == mo1.b) + test(mo5.c == mo1.c) + test(mo5.d == mo1.d) + test(mo5.e == mo1.e) + test(mo5.f == mo1.f) + test(mo5.g == mo1.g) + test(mo5.h == mo1.h) + test(mo5.i == mo1.i) + test(mo5.j == mo1.j) + test(mo5.k == nil) + test(mo5.bs.unpack("C*") == [0x05]) + test(mo5.ss == mo1.ss) + test(mo5.iid[4] == 3) + test(mo5.sid["test"] == 10) + test(mo5.fs == mo1.fs) + test(mo5.vs == mo1.vs) + test(mo5.shs == mo1.shs) + test(mo5.es[0] == Test::MyEnum::MyEnumMember && mo1.es[1] == Test::MyEnum::MyEnumMember) + test(mo5.fss[0] == Test::FixedStruct.new(78)) + test(mo5.vss[0] == Test::VarStruct.new("hello")) + test(mo5.oos[0].a == 15) + test(mo5.oops[0] == Test::OneOptionalPrx::uncheckedCast(communicator.stringToProxy("test"))) + + test(mo5.ied[4] == Test::MyEnum::MyEnumMember) + test(mo5.ifsd[4] == Test::FixedStruct.new(78)) + test(mo5.ivsd[5] == Test::VarStruct.new("hello")) + test(mo5.iood[5].a == 15) + test(mo5.ioopd[5] == Test::OneOptionalPrx::uncheckedCast(communicator.stringToProxy("test"))) + + test(mo5.bos == mo1.bos) + + # Clear the first half of the optional members + mo6 = Test::MultiOptional.new + 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 + + mo7 = initial.pingPong(mo6) + test(mo7.a == Ice::Unset) + test(mo7.b == mo1.b) + test(mo7.c == Ice::Unset) + test(mo7.d == mo1.d) + test(mo7.e == Ice::Unset) + test(mo7.f == mo1.f) + test(mo7.g == Ice::Unset) + test(mo7.h == mo1.h) + test(mo7.i == Ice::Unset) + test(mo7.j == mo1.j) + test(mo7.k == Ice::Unset) + test(mo7.bs.unpack("C*") == [0x05]) + test(mo7.ss == Ice::Unset) + test(mo7.iid[4] == 3) + test(mo7.sid == Ice::Unset) + test(mo7.fs == mo1.fs) + test(mo7.vs == Ice::Unset) + + test(mo7.shs == mo1.shs) + test(mo7.es == Ice::Unset) + test(mo7.fss[0] == Test::FixedStruct.new(78)) + test(mo7.vss == Ice::Unset) + test(mo7.oos[0].a == 15) + test(mo7.oops == Ice::Unset) + + test(mo7.ied == Ice::Unset) + test(mo7.ifsd[4] == Test::FixedStruct.new(78)) + test(mo7.ivsd == Ice::Unset) + test(mo7.iood[5].a == 15) + test(mo7.ioopd == Ice::Unset) + + test(mo7.bos == [false, true, false]) + + # Clear the second half of the optional members + mo8 = Test::MultiOptional.new + mo8.a = mo5.a + mo8.c = mo5.c + mo8.e = mo5.e + mo8.g = mo5.g + mo8.i = mo5.i + mo8.k = mo8 + mo8.ss = mo5.ss + mo8.sid = mo5.sid + mo8.vs = mo5.vs + + mo8.es = mo5.es + mo8.vss = mo5.vss + mo8.oops = mo5.oops + + mo8.ied = mo5.ied + mo8.ivsd = mo5.ivsd + mo8.ioopd = mo5.ioopd + + mo9 = initial.pingPong(mo8) + test(mo9.a == mo1.a) + test(mo9.b == Ice::Unset) + test(mo9.c == mo1.c) + test(mo9.d == Ice::Unset) + test(mo9.e == mo1.e) + test(mo9.f == Ice::Unset) + test(mo9.g == mo1.g) + test(mo9.h == Ice::Unset) + test(mo9.i == mo1.i) + test(mo9.j == Ice::Unset) + test(mo9.k == mo9) + test(mo9.bs == Ice::Unset) + test(mo9.ss == mo1.ss) + test(mo9.iid == Ice::Unset) + test(mo9.sid["test"] == 10) + test(mo9.fs == Ice::Unset) + test(mo9.vs == mo1.vs) + + test(mo9.shs == Ice::Unset) + test(mo9.es[0] == Test::MyEnum::MyEnumMember && mo1.es[1] == Test::MyEnum::MyEnumMember) + test(mo9.fss == Ice::Unset) + test(mo9.vss[0] == Test::VarStruct.new("hello")) + test(mo9.oos == Ice::Unset) + test(mo9.oops[0] == Test::OneOptionalPrx::uncheckedCast(communicator.stringToProxy("test"))) + + test(mo9.ied[4] == Test::MyEnum::MyEnumMember) + test(mo9.ifsd == Ice::Unset) + test(mo9.ivsd[5] == Test::VarStruct.new("hello")) + test(mo9.iood == Ice::Unset) + test(mo9.ioopd[5] == Test::OneOptionalPrx::uncheckedCast(communicator.stringToProxy("test"))) + + test(mo9.bos == Ice::Unset) + + # + # Use the 1.0 encoding with operations whose only class parameters are optional. + # + initial.sendOptionalClass(true, Test::OneOptional.new(53)) + initial.ice_encodingVersion(Ice::Encoding_1_0).sendOptionalClass(true, Test::OneOptional.new(53)) + + r = initial.returnOptionalClass(true) + test(r != Ice::Unset) + r = initial.ice_encodingVersion(Ice::Encoding_1_0).returnOptionalClass(true) + test(r == Ice::Unset) + + recursive1 = [ Test::Recursive.new ] + recursive2 = [ Test::Recursive.new ] + recursive1[0].value = recursive2; + + outer = Test::Recursive.new + outer.value = recursive1 + initial.pingPong(outer) + + puts "ok" + + print "testing marshaling of large containers with fixed size elements... " + STDOUT.flush + + mc = Test::MultiOptional.new + + mc.bs = [] + for i in (0...1000) + mc.bs.push(0) + end + mc.shs = [] + for i in (0...300) + mc.shs.push(0) + end + + mc.fss = [] + for i in (0...300) + mc.fss.push(Test::FixedStruct.new) + end + + mc.ifsd = {} + for i in (0...300) + mc.ifsd[i] = Test::FixedStruct.new + end + + mc = initial.pingPong(mc) + test(mc.bs.length == 1000) + test(mc.shs.length == 300) + test(mc.fss.length == 300) + test(mc.ifsd.length == 300) + + puts "ok" + + print "testing tag marshaling... " + STDOUT.flush + + b = Test::B.new + b2 = initial.pingPong(b) + test(b2.ma == Ice::Unset) + test(b2.mb == Ice::Unset) + test(b2.mc == Ice::Unset) + + b.ma = 10 + b.mb = 11 + b.mc = 12 + b.md = 13 + + b2 = initial.pingPong(b) + test(b2.ma == 10) + test(b2.mb == 11) + test(b2.mc == 12) + test(b2.md == 13) + + puts "ok" + + print "testing marshalling of objects with optional objects..." + STDOUT.flush + + f = Test::F.new + + f.af = Test::A.new + f.ae = f.af + + rf = initial.pingPong(f) + test(rf.ae == rf.af) + + puts "ok" + + print "testing optional with default values... " + STDOUT.flush + + wd = initial.pingPong(Test::WD.new) + test(wd.a == 5) + test(wd.s == "test") + wd.a = Ice::Unset + wd.s = Ice::Unset + wd = initial.pingPong(wd) + test(wd.a == Ice::Unset) + test(wd.s == Ice::Unset) + + puts "ok" + + if communicator.getProperties().getPropertyAsInt("Ice.Default.SlicedFormat") > 0 + print "testing marshaling with unknown class slices... " + STDOUT.flush + + c = Test::C.new + c.ss = "test" + c.ms = "testms" + c = initial.pingPong(c) + test(c.ma == Ice::Unset) + test(c.mb == Ice::Unset) + test(c.mc == Ice::Unset) + test(c.md == Ice::Unset) + test(c.ss == "test") + test(c.ms == "testms") + + puts "ok" + + print "testing optionals with unknown classes... " + STDOUT.flush + + initial2 = Test::Initial2Prx::uncheckedCast(base) + d = Test::D.new + d.ds = "test" + d.seq = ["test1", "test2", "test3", "test4"] + d.ao = Test::A.new(18) + d.requiredB = 14; + d.requiredA = 14; + initial2.opClassAndUnknownOptional(Test::A.new, d) + + puts "ok" + end + + print "testing optional parameters... " + STDOUT.flush + + p2, p3 = initial.opByte(Ice::Unset) + test(p2 == Ice::Unset && p3 == Ice::Unset) + p2, p3 = initial.opByte(56) + test(p2 == 56 && p3 == 56) + + p2, p3 = initial.opBool(Ice::Unset) + test(p2 == Ice::Unset && p3 == Ice::Unset) + p2, p3 = initial.opBool(true) + test(p2 == true && p3 == true) + + p2, p3 = initial.opShort(Ice::Unset) + test(p2 == Ice::Unset && p3 == Ice::Unset) + p2, p3 = initial.opShort(56) + test(p2 == 56 && p3 == 56) + + p2, p3 = initial.opInt(Ice::Unset) + test(p2 == Ice::Unset && p3 == Ice::Unset) + p2, p3 = initial.opInt(56) + test(p2 == 56 && p3 == 56) + + p2, p3 = initial.opLong(Ice::Unset) + test(p2 == Ice::Unset && p3 == Ice::Unset) + p2, p3 = initial.opLong(56) + test(p2 == 56 && p3 == 56) + + p2, p3 = initial.opFloat(Ice::Unset) + test(p2 == Ice::Unset && p3 == Ice::Unset) + p2, p3 = initial.opFloat(1.0) + test(p2 == 1.0 && p3 == 1.0) + + p2, p3 = initial.opDouble(Ice::Unset) + test(p2 == Ice::Unset && p3 == Ice::Unset) + p2, p3 = initial.opDouble(1.0) + test(p2 == 1.0 && p3 == 1.0) + + p2, p3 = initial.opString(Ice::Unset) + test(p2 == Ice::Unset && p3 == Ice::Unset) + p2, p3 = initial.opString("test") + test(p2 == "test" && p3 == "test") + + p2, p3 = initial.opMyEnum(Ice::Unset) + test(p2 == Ice::Unset && p3 == Ice::Unset) + p2, p3 = initial.opMyEnum(Test::MyEnum::MyEnumMember) + test(p2 == Test::MyEnum::MyEnumMember && p3 == Test::MyEnum::MyEnumMember) + + p2, p3 = initial.opSmallStruct(Ice::Unset) + test(p2 == Ice::Unset && p3 == Ice::Unset) + p1 = Test::SmallStruct.new(56) + p2, p3 = initial.opSmallStruct(p1) + test(p2 == p1 && p3 == p1) + p2, p3 = initial.opSmallStruct(nil) # Test null struct + test(p2.m == 0 && p3.m == 0) + + p2, p3 = initial.opFixedStruct(Ice::Unset) + test(p2 == Ice::Unset && p3 == Ice::Unset) + p1 = Test::FixedStruct.new(56) + p2, p3 = initial.opFixedStruct(p1) + test(p2 == p1 && p3 == p1) + + p2, p3 = initial.opVarStruct(Ice::Unset) + test(p2 == Ice::Unset && p3 == Ice::Unset) + p1 = Test::VarStruct.new("test") + p2, p3 = initial.opVarStruct(p1) + test(p2 == p1 && p3 == p1) + + p2, p3 = initial.opOneOptional(Ice::Unset) + test(p2 == Ice::Unset && p3 == Ice::Unset) + p1 = Test::OneOptional.new(58) + p2, p3 = initial.opOneOptional(p1) + test(p2.a == p1.a && p3.a == p1.a) + + p2, p3 = initial.opOneOptionalProxy(Ice::Unset) + test(p2 == Ice::Unset && p3 == Ice::Unset) + p1 = Test::OneOptionalPrx::uncheckedCast(communicator.stringToProxy("test")) + p2, p3 = initial.opOneOptionalProxy(p1) + test(p2 == p1 && p3 == p1) + + p2, p3 = initial.opByteSeq(Ice::Unset) + test(p2 == Ice::Unset && p3 == Ice::Unset) + p1 = [] + for x in (0...100) + p1.push(56) + end + p2, p3 = initial.opByteSeq(p1) + test(p2.length == p1.length && p3.length == p1.length) + test(p2[0] == "\x38" || p2[0] == 0x38) + test(p3[0] == "\x38" || p3[0] == 0x38) + + p2, p3 = initial.opBoolSeq(Ice::Unset) + test(p2 == Ice::Unset && p3 == Ice::Unset) + p1 = [] + for x in (0...100) + p1.push(true) + end + p2, p3 = initial.opBoolSeq(p1) + test(p2 == p1 && p3 == p1) + + p2, p3 = initial.opShortSeq(Ice::Unset) + test(p2 == Ice::Unset && p3 == Ice::Unset) + p1 = [] + for x in (0...100) + p1.push(56) + end + p2, p3 = initial.opShortSeq(p1) + test(p2 == p1 && p3 == p1) + + p2, p3 = initial.opIntSeq(Ice::Unset) + test(p2 == Ice::Unset && p3 == Ice::Unset) + p1 = [] + for x in (0...100) + p1.push(56) + end + p2, p3 = initial.opIntSeq(p1) + test(p2 == p1 && p3 == p1) + + p2, p3 = initial.opLongSeq(Ice::Unset) + test(p2 == Ice::Unset && p3 == Ice::Unset) + p1 = [] + for x in (0...100) + p1.push(56) + end + p2, p3 = initial.opLongSeq(p1) + test(p2 == p1 && p3 == p1) + + p2, p3 = initial.opFloatSeq(Ice::Unset) + test(p2 == Ice::Unset && p3 == Ice::Unset) + p1 = [] + for x in (0...100) + p1.push(1.0) + end + p2, p3 = initial.opFloatSeq(p1) + test(p2 == p1 && p3 == p1) + + p2, p3 = initial.opDoubleSeq(Ice::Unset) + test(p2 == Ice::Unset && p3 == Ice::Unset) + p1 = [] + for x in (0...100) + p1.push(1.0) + end + p2, p3 = initial.opDoubleSeq(p1) + test(p2 == p1 && p3 == p1) + + p2, p3 = initial.opStringSeq(Ice::Unset) + test(p2 == Ice::Unset && p3 == Ice::Unset) + p1 = [] + for x in (0...100) + p1.push("test1") + end + p2, p3 = initial.opStringSeq(p1) + test(p2 == p1 && p3 == p1) + + p2, p3 = initial.opSmallStructSeq(Ice::Unset) + test(p2 == Ice::Unset && p3 == Ice::Unset) + p1 = [] + for x in (0...10) + p1.push(Test::SmallStruct.new(1)) + end + p2, p3 = initial.opSmallStructSeq(p1) + test(p2 == p1 && p3 == p1) + + p2, p3 = initial.opSmallStructList(Ice::Unset) + test(p2 == Ice::Unset && p3 == Ice::Unset) + p1 = [] + for x in (0...10) + p1.push(Test::SmallStruct.new(1)) + end + p2, p3 = initial.opSmallStructList(p1) + test(p2 == p1 && p3 == p1) + + p2, p3 = initial.opFixedStructSeq(Ice::Unset) + test(p2 == Ice::Unset && p3 == Ice::Unset) + p1 = [] + for x in (0...10) + p1.push(Test::FixedStruct.new(1)) + end + p2, p3 = initial.opFixedStructSeq(p1) + test(p2 == p1 && p3 == p1) + + p2, p3 = initial.opFixedStructList(Ice::Unset) + test(p2 == Ice::Unset && p3 == Ice::Unset) + p1 = [] + for x in (0...10) + p1.push(Test::FixedStruct.new(1)) + end + p2, p3 = initial.opFixedStructList(p1) + test(p2 == p1 && p3 == p1) + + p2, p3 = initial.opVarStructSeq(Ice::Unset) + test(p2 == Ice::Unset && p3 == Ice::Unset) + p1 = [] + for x in (0...10) + p1.push(Test::VarStruct.new("test")) + end + p2, p3 = initial.opVarStructSeq(p1) + test(p2 == p1 && p3 == p1) + + p2, p3 = initial.opIntIntDict(Ice::Unset) + test(p2 == Ice::Unset && p3 == Ice::Unset) + p1 = {1=>2, 2=>3} + p2, p3 = initial.opIntIntDict(p1) + test(p2 == p1 && p3 == p1) + + p2, p3 = initial.opStringIntDict(Ice::Unset) + test(p2 == Ice::Unset && p3 == Ice::Unset) + p1 = {"1"=>2, "2"=>3} + p2, p3 = initial.opStringIntDict(p1) + test(p2 == p1 && p3 == p1) + + puts "ok" + + print "testing exception optionals... " + STDOUT.flush + + begin + initial.opOptionalException(Ice::Unset, Ice::Unset, Ice::Unset) + rescue Test::OptionalException => ex + test(ex.a == Ice::Unset) + test(ex.b == Ice::Unset) + test(ex.o == Ice::Unset) + end + + begin + initial.opOptionalException(30, "test", Test::OneOptional.new(53)) + rescue Test::OptionalException => ex + test(ex.a == 30) + test(ex.b == "test") + test(ex.o.a == 53) + end + + begin + # + # Use the 1.0 encoding with an exception whose only class members are optional. + # + initial.ice_encodingVersion(Ice::Encoding_1_0).opOptionalException(30, "test", Test::OneOptional.new(53)) + rescue Test::OptionalException => ex + test(ex.a == Ice::Unset) + test(ex.b == Ice::Unset) + test(ex.o == Ice::Unset) + end + + begin + initial.opDerivedException(Ice::Unset, Ice::Unset, Ice::Unset) + rescue Test::DerivedException => ex + test(ex.a == Ice::Unset) + test(ex.b == Ice::Unset) + test(ex.o == Ice::Unset) + test(ex.ss == Ice::Unset) + test(ex.o2 == Ice::Unset) + end + + begin + initial.opDerivedException(30, "test", Test::OneOptional.new(53)) + rescue Test::DerivedException => ex + test(ex.a == 30) + test(ex.b == "test") + test(ex.o.a == 53) + test(ex.ss == "test") + test(ex.o2 == ex.o) + end + + begin + initial.opRequiredException(Ice::Unset, Ice::Unset, Ice::Unset) + rescue Test::RequiredException => ex + test(ex.a == Ice::Unset) + test(ex.b == Ice::Unset) + test(ex.o == Ice::Unset) + test(ex.ss != Ice::Unset) + test(ex.o2 != Ice::Unset) + end + + begin + initial.opRequiredException(30, "test", Test::OneOptional.new(53)) + rescue Test::RequiredException => ex + test(ex.a == 30) + test(ex.b == "test") + test(ex.o.a == 53) + test(ex.ss == "test") + test(ex.o2 == ex.o) + end + + puts "ok" + + return initial +end diff --git a/ruby/test/Ice/optional/Client.rb b/ruby/test/Ice/optional/Client.rb new file mode 100755 index 00000000000..bb4043d7908 --- /dev/null +++ b/ruby/test/Ice/optional/Client.rb @@ -0,0 +1,47 @@ +#!/usr/bin/env ruby +# ********************************************************************** +# +# Copyright (c) 2003-2015 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 'Ice' + +Ice::loadSlice("--all -I. ClientPrivate.ice") +require './AllTests' + +def test(b) + if !b + raise RuntimeError, 'test assertion failed' + end +end + +def run(args, communicator) + initial = allTests(communicator) + initial.shutdown() + return true +end + +begin + communicator = Ice.initialize(ARGV) + status = run(ARGV, communicator) +rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false +end + +if communicator + begin + communicator.destroy() + rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false + end +end + +exit(status ? 0 : 1) diff --git a/ruby/test/Ice/optional/ClientPrivate.ice b/ruby/test/Ice/optional/ClientPrivate.ice new file mode 100644 index 00000000000..c7211442401 --- /dev/null +++ b/ruby/test/Ice/optional/ClientPrivate.ice @@ -0,0 +1,37 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 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 <Test.ice> + +module Test +{ + +// +// The server doesn't know this class. +// +class D extends B +{ + string ds; + optional(990) StringSeq seq; + optional(1000) A ao; +}; + +// +// This class is a hack that allows us to invoke the opClassAndUnknownOptional operation +// on the server and pass an optional argument. This isn't necessary in other language +// mappings where the public stream API is available. +// +class Initial2 +{ + void opClassAndUnknownOptional(A p, optional(1) Object o); +}; + +}; diff --git a/ruby/test/Ice/optional/Test.ice b/ruby/test/Ice/optional/Test.ice new file mode 100644 index 00000000000..65bbbaa18e9 --- /dev/null +++ b/ruby/test/Ice/optional/Test.ice @@ -0,0 +1,269 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 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 Recursive; +sequence<Recursive> RecursiveSeq; + +class Recursive { + optional(0) RecursiveSeq value; +}; + +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) bool opBool(optional(2) bool p1, out optional(3) bool p3); + + optional(1) short opShort(optional(2) short p1, out optional(3) short p3); + + optional(1) int opInt(optional(2) int p1, out optional(3) int p3); + + optional(3) long opLong(optional(1) long p1, out optional(2) long p3); + + optional(1) float opFloat(optional(2) float p1, out optional(3) float p3); + + optional(1) double opDouble(optional(2) double p1, out optional(3) double p3); + + optional(1) string opString(optional(2) string p1, out optional(3) string p3); + + optional(1) MyEnum opMyEnum(optional(2) MyEnum p1, out optional(3) MyEnum p3); + + optional(1) SmallStruct opSmallStruct(optional(2) SmallStruct p1, out optional(3) SmallStruct p3); + + optional(1) FixedStruct opFixedStruct(optional(2) FixedStruct p1, out optional(3) FixedStruct p3); + + optional(1) VarStruct opVarStruct(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* opOneOptionalProxy(optional(2) OneOptional* p1, out optional(3) OneOptional* p3); + + optional(1) ByteSeq opByteSeq(optional(2) ByteSeq p1, out optional(3) ByteSeq p3); + + optional(1) BoolSeq opBoolSeq(optional(2) BoolSeq p1, out optional(3) BoolSeq p3); + + optional(1) ShortSeq opShortSeq(optional(2) ShortSeq p1, out optional(3) ShortSeq p3); + + optional(1) IntSeq opIntSeq(optional(2) IntSeq p1, out optional(3) IntSeq p3); + + optional(1) LongSeq opLongSeq(optional(2) LongSeq p1, out optional(3) LongSeq p3); + + optional(1) FloatSeq opFloatSeq(optional(2) FloatSeq p1, out optional(3) FloatSeq p3); + + optional(1) DoubleSeq opDoubleSeq(optional(2) DoubleSeq p1, out optional(3) DoubleSeq p3); + + optional(1) StringSeq opStringSeq(optional(2) StringSeq p1, out optional(3) StringSeq p3); + + optional(1) SmallStructSeq opSmallStructSeq(optional(2) SmallStructSeq p1, out optional(3) SmallStructSeq p3); + + optional(1) SmallStructList opSmallStructList(optional(2) SmallStructList p1, out optional(3) SmallStructList p3); + + optional(1) FixedStructSeq opFixedStructSeq(optional(2) FixedStructSeq p1, out optional(3) FixedStructSeq p3); + + optional(1) FixedStructList opFixedStructList(optional(2) FixedStructList p1, out optional(3) FixedStructList p3); + + optional(1) VarStructSeq opVarStructSeq(optional(2) VarStructSeq p1, out optional(3) VarStructSeq p3); + + optional(1) Serializable opSerializable(optional(2) Serializable p1, out optional(3) Serializable p3); + + optional(1) IntIntDict opIntIntDict(optional(2) IntIntDict p1, out optional(3) IntIntDict p3); + + optional(1) StringIntDict opStringIntDict(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/ruby/test/Ice/optional/run.py b/ruby/test/Ice/optional/run.py new file mode 100755 index 00000000000..d76138b1e22 --- /dev/null +++ b/ruby/test/Ice/optional/run.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 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/ruby/test/Ice/properties/Client.rb b/ruby/test/Ice/properties/Client.rb new file mode 100644 index 00000000000..c4d905c3723 --- /dev/null +++ b/ruby/test/Ice/properties/Client.rb @@ -0,0 +1,87 @@ +#!/usr/bin/env ruby +# encoding: UTF-8 +# ********************************************************************** +# +# Copyright (c) 2003-2015 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 'Ice' + +def test(b) + if !b + raise RuntimeError, 'test assertion failed' + end +end + +class Client < Ice::Application + def run(args) + print "testing load properties from UTF-8 path using Ice::Application... " + properties = Ice::Application::communicator().getProperties() + test(properties.getProperty("Ice.Trace.Network") == "1") + test(properties.getProperty("Ice.Trace.Protocol") == "1") + test(properties.getProperty("Config.Path").eql? "./config/ä¸å›½_client.config") + test(properties.getProperty("Ice.ProgramName") == "PropertiesClient") + test(Ice::Application::appName() == properties.getProperty("Ice.ProgramName")) + puts "ok" + return true + end +end + + +print "testing load properties from UTF-8 path... " +properties = Ice.createProperties(ARGV) +properties.load("./config/ä¸å›½_client.config") +test(properties.getProperty("Ice.Trace.Network") == "1") +test(properties.getProperty("Ice.Trace.Protocol") == "1") +test(properties.getProperty("Config.Path").eql? "./config/ä¸å›½_client.config") +test(properties.getProperty("Ice.ProgramName") == "PropertiesClient") +puts "ok" + +app = Client.new() +app.main(ARGV, "./config/ä¸å›½_client.config") + +print "testing using Ice.Config with multiple config files... " +properties = Ice.createProperties(["--Ice.Config=config/config.1, config/config.2, config/config.3"]); +test(properties.getProperty("Config1") == "Config1"); +test(properties.getProperty("Config2") == "Config2"); +test(properties.getProperty("Config3") == "Config3"); +puts "ok" + + +print "testing configuration file escapes... " +properties = Ice.createProperties(["--Ice.Config=config/escapes.cfg"]) + +props = { "Foo\tBar" => "3", + "Foo\\tBar" => "4", + "Escape\\ Space" => "2", + "Prop1" => "1", + "Prop2" => "2", + "Prop3" => "3", + "My Prop1" => "1", + "My Prop2" => "2", + "My.Prop1" => "a property", + "My.Prop2" => "a property", + "My.Prop3" => " a property ", + "My.Prop4" => " a property ", + "My.Prop5" => "a \\ property", + "foo=bar" => "1", + "foo#bar" => "2", + "foo bar" => "3", + "A" => "1", + "B" => "2 3 4", + "C" => "5=#6", + "AServer" => "\\\\server\\dir", + "BServer" => "\\server\\dir" } + +props.each do |key, value| + test(properties.getProperty(key) == value) +end +puts "ok" + + +exit(0) diff --git a/ruby/test/Ice/properties/config/.gitignore b/ruby/test/Ice/properties/config/.gitignore new file mode 100644 index 00000000000..143c64680f3 --- /dev/null +++ b/ruby/test/Ice/properties/config/.gitignore @@ -0,0 +1 @@ +*.config diff --git a/ruby/test/Ice/properties/config/config.1 b/ruby/test/Ice/properties/config/config.1 new file mode 100644 index 00000000000..2a20653e4c5 --- /dev/null +++ b/ruby/test/Ice/properties/config/config.1 @@ -0,0 +1 @@ +Config1=Config1
\ No newline at end of file diff --git a/ruby/test/Ice/properties/config/config.2 b/ruby/test/Ice/properties/config/config.2 new file mode 100644 index 00000000000..be276df6602 --- /dev/null +++ b/ruby/test/Ice/properties/config/config.2 @@ -0,0 +1 @@ +Config2=Config2
\ No newline at end of file diff --git a/ruby/test/Ice/properties/config/config.3 b/ruby/test/Ice/properties/config/config.3 new file mode 100644 index 00000000000..55c1e1123f6 --- /dev/null +++ b/ruby/test/Ice/properties/config/config.3 @@ -0,0 +1 @@ +Config3=Config3
\ No newline at end of file diff --git a/ruby/test/Ice/properties/config/escapes.cfg b/ruby/test/Ice/properties/config/escapes.cfg new file mode 100644 index 00000000000..f438d2b59c8 --- /dev/null +++ b/ruby/test/Ice/properties/config/escapes.cfg @@ -0,0 +1,35 @@ +Foo Bar=3 #tab +Foo\tBar=4 # embedded\t +Escape\\ Space=2 + +# +# From Ice manual: +# + +Prop1 = 1 # Key is "Prop1" + Prop2 = 2 # Key is "Prop2" +\ Prop3 \ = 3 # Key is "Prop3" +My Prop1 = 1 # Key is "My Prop1" +My\ Prop2 = 2 # Key is "My Prop2" + +My.Prop1 = a property # Value is "a property" +My.Prop2 = a property # Value is "a property" +My.Prop3 = \ \ a property\ \ # Value is " a property " +My.Prop4 = \ \ a \ \ property\ \ # Value is " a property " +My.Prop5 = a \\ property # Value is "a \ property" + +foo\=bar=1 # Name is "foo=bar", value is "1" +foo\#bar = 2 # Name is "foo#bar", value is "2" +foo bar =3 # Name is "foo bar", value is "3" + + +A=1 # Name is "A", value is "1" +B= 2 3 4 # Name is "B", value is "2 3 4" +C=5=\#6 # 7 # Name is "C", value is "5=#6" + +AServer=\\\\server\dir # Value is "\\server\dir" +BServer=\\server\\dir # Value is "\server\dir" + + + + diff --git a/ruby/test/Ice/properties/run.py b/ruby/test/Ice/properties/run.py new file mode 100755 index 00000000000..c6ce2b8cfad --- /dev/null +++ b/ruby/test/Ice/properties/run.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# ********************************************************************** +# +# Copyright (c) 2003-2015 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 + +# +# Write config +# +if sys.version_info[0] == 2: + configPath = "./config/\xe4\xb8\xad\xe5\x9b\xbd_client.config" +else: + configPath = "./config/\u4e2d\u56fd_client.config" + +TestUtil.createConfig(configPath, + ["# Automatically generated by Ice test driver.", + "Ice.Trace.Protocol=1", + "Ice.Trace.Network=1", + "Ice.ProgramName=PropertiesClient", + "Config.Path=" + configPath], + "utf-8") + +TestUtil.simpleTest() + +if os.path.exists(configPath): + os.remove(configPath) diff --git a/ruby/test/Ice/proxy/AllTests.rb b/ruby/test/Ice/proxy/AllTests.rb new file mode 100644 index 00000000000..35131cda679 --- /dev/null +++ b/ruby/test/Ice/proxy/AllTests.rb @@ -0,0 +1,787 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 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. +# +# ********************************************************************** + +def allTests(communicator) + print "testing stringToProxy... " + STDOUT.flush + ref = "test:default -p 12010" + base = communicator.stringToProxy(ref) + test(base) + + b1 = communicator.stringToProxy("test") + test(b1.ice_getIdentity().name == "test" && b1.ice_getIdentity().category.empty? && \ + b1.ice_getAdapterId().empty? && b1.ice_getFacet().empty?) + b1 = communicator.stringToProxy("test ") + test(b1.ice_getIdentity().name == "test" && b1.ice_getIdentity().category.empty? && \ + b1.ice_getFacet().empty?) + b1 = communicator.stringToProxy(" test ") + test(b1.ice_getIdentity().name == "test" && b1.ice_getIdentity().category.empty? && \ + b1.ice_getFacet().empty?) + b1 = communicator.stringToProxy(" test") + test(b1.ice_getIdentity().name == "test" && b1.ice_getIdentity().category.empty? && \ + b1.ice_getFacet().empty?) + b1 = communicator.stringToProxy("'test -f facet'") + test(b1.ice_getIdentity().name == "test -f facet" && b1.ice_getIdentity().category.empty? && \ + b1.ice_getFacet().empty?) + begin + b1 = communicator.stringToProxy("\"test -f facet'") + test(false) + rescue Ice::ProxyParseException + end + b1 = communicator.stringToProxy("\"test -f facet\"") + test(b1.ice_getIdentity().name == "test -f facet" && b1.ice_getIdentity().category.empty? && \ + b1.ice_getFacet().empty?) + b1 = communicator.stringToProxy("\"test -f facet@test\"") + test(b1.ice_getIdentity().name == "test -f facet@test" && b1.ice_getIdentity().category.empty? && \ + b1.ice_getFacet().empty?) + b1 = communicator.stringToProxy("\"test -f facet@test @test\"") + test(b1.ice_getIdentity().name == "test -f facet@test @test" && b1.ice_getIdentity().category.empty? && \ + b1.ice_getFacet().empty?) + begin + b1 = communicator.stringToProxy("test test") + test(false) + rescue Ice::ProxyParseException + end + b1 = communicator.stringToProxy("test\\040test") + test(b1.ice_getIdentity().name == "test test" && b1.ice_getIdentity().category.empty?) + begin + b1 = communicator.stringToProxy("test\\777") + test(false) + rescue Ice::IdentityParseException + end + b1 = communicator.stringToProxy("test\\40test") + test(b1.ice_getIdentity().name == "test test") + + # Test some octal && hex corner cases. + b1 = communicator.stringToProxy("test\\4test") + test(b1.ice_getIdentity().name == "test\4test") + b1 = communicator.stringToProxy("test\\04test") + test(b1.ice_getIdentity().name == "test\4test") + b1 = communicator.stringToProxy("test\\004test") + test(b1.ice_getIdentity().name == "test\4test") + b1 = communicator.stringToProxy("test\\1114test") + test(b1.ice_getIdentity().name == "test\1114test") + + 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.empty?) + + b1 = communicator.stringToProxy("category/test") + test(b1.ice_getIdentity().name == "test" && b1.ice_getIdentity().category == "category" && \ + b1.ice_getAdapterId().empty?) + + b1 = communicator.stringToProxy("test@adapter") + test(b1.ice_getIdentity().name == "test" && b1.ice_getIdentity().category.empty? && \ + b1.ice_getAdapterId() == "adapter") + begin + b1 = communicator.stringToProxy("id@adapter test") + test(false) + rescue Ice::ProxyParseException + end + 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:tcp") + test(b1.ice_getIdentity().name == "test" && b1.ice_getIdentity().category == "category" && \ + b1.ice_getAdapterId() == "adapter:tcp") + 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:tcp\"") + test(b1.ice_getIdentity().name == "test" && b1.ice_getIdentity().category == "category /test@foo" && \ + b1.ice_getAdapterId() == "adapter:tcp") + + b1 = communicator.stringToProxy("id -f facet") + test(b1.ice_getIdentity().name == "id" && b1.ice_getIdentity().category.empty? && \ + b1.ice_getFacet() == "facet") + b1 = communicator.stringToProxy("id -f 'facet x'") + test(b1.ice_getIdentity().name == "id" && b1.ice_getIdentity().category.empty? && \ + b1.ice_getFacet() == "facet x") + b1 = communicator.stringToProxy("id -f \"facet x\"") + test(b1.ice_getIdentity().name == "id" && b1.ice_getIdentity().category.empty? && \ + b1.ice_getFacet() == "facet x") + begin + b1 = communicator.stringToProxy("id -f \"facet x") + test(false) + rescue Ice::ProxyParseException + end + begin + b1 = communicator.stringToProxy("id -f \'facet x") + test(false) + rescue Ice::ProxyParseException + end + b1 = communicator.stringToProxy("test -f facet:tcp") + test(b1.ice_getIdentity().name == "test" && b1.ice_getIdentity().category.empty? && \ + b1.ice_getFacet() == "facet" && b1.ice_getAdapterId().empty?) + b1 = communicator.stringToProxy("test -f \"facet:tcp\"") + test(b1.ice_getIdentity().name == "test" && b1.ice_getIdentity().category.empty? && \ + b1.ice_getFacet() == "facet:tcp" && b1.ice_getAdapterId().empty?) + b1 = communicator.stringToProxy("test -f facet@test") + test(b1.ice_getIdentity().name == "test" && b1.ice_getIdentity().category.empty? && \ + 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.empty? && \ + b1.ice_getFacet() == "facet@test" && b1.ice_getAdapterId().empty?) + b1 = communicator.stringToProxy("test -f 'facet@test'@test") + test(b1.ice_getIdentity().name == "test" && b1.ice_getIdentity().category.empty? && \ + b1.ice_getFacet() == "facet@test" && b1.ice_getAdapterId() == "test") + begin + b1 = communicator.stringToProxy("test -f facet@test @test") + test(false) + rescue Ice::ProxyParseException + end + 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() == 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); + + begin + b1 = communicator.stringToProxy("test:tcp@adapterId") + test(false) + rescue Ice::EndpointParseException + end + # This is an unknown endpoint warning, not a parse rescueion. + # + #begin + # b1 = communicator.stringToProxy("test -f the:facet:tcp") + # test(false) + #rescue Ice::EndpointParseException + #end + begin + b1 = communicator.stringToProxy("test::tcp") + test(false) + rescue Ice::EndpointParseException + end + puts "ok" + + print "testing propertyToProxy... " + STDOUT.flush + prop = communicator.getProperties() + propertyPrefix = "Foo.Proxy" + prop.setProperty(propertyPrefix, "test:default -p 12010") + b1 = communicator.propertyToProxy(propertyPrefix) + test(b1.ice_getIdentity().name == "test" && b1.ice_getIdentity().category.empty? && \ + b1.ice_getAdapterId().empty? && b1.ice_getFacet().empty?) + + property = propertyPrefix + ".Locator" + test(!b1.ice_getLocator()) + prop.setProperty(property, "locator:default -p 10000") + b1 = communicator.propertyToProxy(propertyPrefix) + test(b1.ice_getLocator() && 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() && 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()) + prop.setProperty(property, "router:default -p 10000") + b1 = communicator.propertyToProxy(propertyPrefix) + test(b1.ice_getRouter() && 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 + ".InvocationTimeout"; + test(b1.ice_getInvocationTimeout() == -1); + prop.setProperty(property, "1000"); + b1 = communicator.propertyToProxy(propertyPrefix); + test(b1.ice_getInvocationTimeout() == 1000); + 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, "") + + # + # isCollocationOptimized is not implemented because the + # collocation optimization is permanently disabled with IcePy. + # + #property = propertyPrefix + ".CollocationOptimized" + #test(b1.ice_isCollocationOptimized()) + #prop.setProperty(property, "0") + #b1 = communicator.propertyToProxy(propertyPrefix) + #test(!b1.ice_isCollocationOptimized()) + #prop.setProperty(property, "") + + puts "ok" + + print "testing proxyToProperty... " + STDOUT.flush + + b1 = communicator.stringToProxy("test") + #b1 = b1.ice_collocationOptimized(true) + 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_invocationTimeout(1234); + b1 = b1.ice_encodingVersion(Ice::EncodingVersion.new(1, 0)) + + router = communicator.stringToProxy("router") + #router = router.ice_collocationOptimized(false) + router = router.ice_connectionCached(true) + router = router.ice_preferSecure(true) + router = router.ice_endpointSelection(Ice::EndpointSelectionType::Random) + router = router.ice_locatorCacheTimeout(200) + router = router.ice_invocationTimeout(1500); + + locator = communicator.stringToProxy("locator") + #locator = locator.ice_collocationOptimized(true) + 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_invocationTimeout(1500); + + locator = locator.ice_router(Ice::RouterPrx::uncheckedCast(router)) + b1 = b1.ice_locator(Ice::LocatorPrx::uncheckedCast(locator)) + + proxyProps = communicator.proxyToProperty(b1, "Test") + test(proxyProps.length() == 21) + + test(proxyProps["Test"] == "test -t -e 1.0") + #test(proxyProps["Test.CollocationOptimized"] == "1") + test(proxyProps["Test.ConnectionCached"] == "1") + test(proxyProps["Test.PreferSecure"] == "0") + test(proxyProps["Test.EndpointSelection"] == "Ordered") + test(proxyProps["Test.LocatorCacheTimeout"] == "100") + test(proxyProps["Test.InvocationTimeout"] == "1234"); + + test(proxyProps["Test.Locator"] == "locator -t -e " + Ice::encodingVersionToString(Ice::currentEncoding())) + #test(proxyProps["Test.Locator.CollocationOptimized"] == "1") + test(proxyProps["Test.Locator.ConnectionCached"] == "0") + test(proxyProps["Test.Locator.PreferSecure"] == "1") + test(proxyProps["Test.Locator.EndpointSelection"] == "Random") + test(proxyProps["Test.Locator.LocatorCacheTimeout"] == "300") + test(proxyProps["Test.Locator.InvocationTimeout"] == "1500"); + + test(proxyProps["Test.Locator.Router"] == "router -t -e " + Ice::encodingVersionToString(Ice::currentEncoding())); + #test(proxyProps["Test.Locator.Router.CollocationOptimized"] == "0") + test(proxyProps["Test.Locator.Router.ConnectionCached"] == "1") + test(proxyProps["Test.Locator.Router.PreferSecure"] == "1") + test(proxyProps["Test.Locator.Router.EndpointSelection"] == "Random") + test(proxyProps["Test.Locator.Router.LocatorCacheTimeout"] == "200") + test(proxyProps["Test.Locator.Router.InvocationTimeout"] == "1500"); + + puts "ok" + + print "testing ice_getCommunicator... " + STDOUT.flush + test(base.ice_getCommunicator() == communicator) + puts "ok" + + print "testing proxy methods... " + STDOUT.flush + 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() == Ice::Encoding_1_0) + test(base.ice_encodingVersion(Ice::Encoding_1_1).ice_getEncodingVersion() == Ice::Encoding_1_1) + test(base.ice_encodingVersion(Ice::Encoding_1_0).ice_getEncodingVersion() != Ice::Encoding_1_1) + + begin + base.ice_timeout(0) + test(false) + rescue + end + + begin + base.ice_timeout(-1) + rescue + test(false) + end + + begin + base.ice_timeout(-2) + test(false) + rescue + end + + begin + base.ice_invocationTimeout(0) + test(false) + rescue + end + + begin + base.ice_invocationTimeout(-1) + rescue + test(false) + end + + begin + base.ice_invocationTimeout(-2) + test(false) + rescue + end + + begin + base.ice_locatorCacheTimeout(0) + rescue + test(false) + end + + begin + base.ice_locatorCacheTimeout(-1) + rescue + test(false) + end + + begin + base.ice_locatorCacheTimeout(-2) + test(false) + rescue + end + + puts "ok" + + print "testing proxy comparison... " + STDOUT.flush + + test(communicator.stringToProxy("foo") == communicator.stringToProxy("foo")) + test(communicator.stringToProxy("foo") != communicator.stringToProxy("foo2")) + #test(communicator.stringToProxy("foo") < communicator.stringToProxy("foo2")) + #test(!(communicator.stringToProxy("foo2") < communicator.stringToProxy("foo"))) + + compObj = communicator.stringToProxy("foo") + + test(compObj.ice_facet("facet") == compObj.ice_facet("facet")) + test(compObj.ice_facet("facet") != compObj.ice_facet("facet1")) + #test(compObj.ice_facet("facet") < compObj.ice_facet("facet1")) + #test(!(compObj.ice_facet("facet") < compObj.ice_facet("facet"))) + + test(compObj.ice_oneway() == compObj.ice_oneway()) + test(compObj.ice_oneway() != compObj.ice_twoway()) + #test(compObj.ice_twoway() < compObj.ice_oneway()) + #test(!(compObj.ice_oneway() < compObj.ice_twoway())) + + test(compObj.ice_secure(true) == compObj.ice_secure(true)) + test(compObj.ice_secure(false) != compObj.ice_secure(true)) + #test(compObj.ice_secure(false) < compObj.ice_secure(true)) + #test(!(compObj.ice_secure(true) < compObj.ice_secure(false))) + + #test(compObj.ice_collocationOptimized(true) == compObj.ice_collocationOptimized(true)) + #test(compObj.ice_collocationOptimized(false) != compObj.ice_collocationOptimized(true)) + #test(compObj.ice_collocationOptimized(false) < compObj.ice_collocationOptimized(true)) + #test(!(compObj.ice_collocationOptimized(true) < compObj.ice_collocationOptimized(false))) + + test(compObj.ice_connectionCached(true) == compObj.ice_connectionCached(true)) + test(compObj.ice_connectionCached(false) != compObj.ice_connectionCached(true)) + #test(compObj.ice_connectionCached(false) < compObj.ice_connectionCached(true)) + #test(!(compObj.ice_connectionCached(true) < compObj.ice_connectionCached(false))) + + test(compObj.ice_endpointSelection(Ice::EndpointSelectionType::Random) == \ + compObj.ice_endpointSelection(Ice::EndpointSelectionType::Random)) + test(compObj.ice_endpointSelection(Ice::EndpointSelectionType::Random) != \ + compObj.ice_endpointSelection(Ice::EndpointSelectionType::Ordered)) + #test(compObj.ice_endpointSelection(Ice::EndpointSelectionType::Random) < \ + # compObj.ice_endpointSelection(Ice::EndpointSelectionType::Ordered)) + #test(!(compObj.ice_endpointSelection(Ice::EndpointSelectionType::Ordered) < \ + # compObj.ice_endpointSelection(Ice::EndpointSelectionType::Random))) + + test(compObj.ice_connectionId("id2") == compObj.ice_connectionId("id2")) + test(compObj.ice_connectionId("id1") != compObj.ice_connectionId("id2")) + test(compObj.ice_connectionId("id1").ice_getConnectionId() == "id1") + test(compObj.ice_connectionId("id2").ice_getConnectionId() == "id2") + #test(compObj.ice_connectionId("id1") < compObj.ice_connectionId("id2")) + #test(!(compObj.ice_connectionId("id2") < compObj.ice_connectionId("id1"))) + + test(compObj.ice_compress(true) == compObj.ice_compress(true)) + test(compObj.ice_compress(false) != compObj.ice_compress(true)) + #test(compObj.ice_compress(false) < compObj.ice_compress(true)) + #test(!(compObj.ice_compress(true) < compObj.ice_compress(false))) + + test(compObj.ice_timeout(20) == compObj.ice_timeout(20)) + test(compObj.ice_timeout(10) != compObj.ice_timeout(20)) + #test(compObj.ice_timeout(10) < compObj.ice_timeout(20)) + #test(!(compObj.ice_timeout(20) < compObj.ice_timeout(10))) + + loc1 = Ice::LocatorPrx::uncheckedCast(communicator.stringToProxy("loc1:default -p 10000")) + loc2 = Ice::LocatorPrx::uncheckedCast(communicator.stringToProxy("loc2:default -p 10000")) + test(compObj.ice_locator(nil) == compObj.ice_locator(nil)) + test(compObj.ice_locator(loc1) == compObj.ice_locator(loc1)) + test(compObj.ice_locator(loc1) != compObj.ice_locator(nil)) + test(compObj.ice_locator(nil) != compObj.ice_locator(loc2)) + test(compObj.ice_locator(loc1) != compObj.ice_locator(loc2)) + #test(compObj.ice_locator(nil) < compObj.ice_locator(loc1)) + #test(!(compObj.ice_locator(loc1) < compObj.ice_locator(nil))) + #test(compObj.ice_locator(loc1) < compObj.ice_locator(loc2)) + #test(!(compObj.ice_locator(loc2) < compObj.ice_locator(loc1))) + + rtr1 = Ice::RouterPrx::uncheckedCast(communicator.stringToProxy("rtr1:default -p 10000")) + rtr2 = Ice::RouterPrx::uncheckedCast(communicator.stringToProxy("rtr2:default -p 10000")) + test(compObj.ice_router(nil) == compObj.ice_router(nil)) + test(compObj.ice_router(rtr1) == compObj.ice_router(rtr1)) + test(compObj.ice_router(rtr1) != compObj.ice_router(nil)) + test(compObj.ice_router(nil) != compObj.ice_router(rtr2)) + test(compObj.ice_router(rtr1) != compObj.ice_router(rtr2)) + #test(compObj.ice_router(nil) < compObj.ice_router(rtr1)) + #test(!(compObj.ice_router(rtr1) < compObj.ice_router(nil))) + #test(compObj.ice_router(rtr1) < compObj.ice_router(rtr2)) + #test(!(compObj.ice_router(rtr2) < compObj.ice_router(rtr1))) + + ctx1 = { } + ctx1["ctx1"] = "v1" + ctx2 = { } + ctx2["ctx2"] = "v2" + test(compObj.ice_context({ }) == compObj.ice_context({ })) + test(compObj.ice_context(ctx1) == compObj.ice_context(ctx1)) + test(compObj.ice_context(ctx1) != compObj.ice_context({ })) + test(compObj.ice_context({ }) != compObj.ice_context(ctx2)) + test(compObj.ice_context(ctx1) != compObj.ice_context(ctx2)) + #test(compObj.ice_context(ctx1) < compObj.ice_context(ctx2)) + #test(!(compObj.ice_context(ctx2) < compObj.ice_context(ctx1))) + + test(compObj.ice_preferSecure(true) == compObj.ice_preferSecure(true)) + test(compObj.ice_preferSecure(true) != compObj.ice_preferSecure(false)) + #test(compObj.ice_preferSecure(false) < compObj.ice_preferSecure(true)) + #test(!(compObj.ice_preferSecure(true) < compObj.ice_preferSecure(false))) + + compObj1 = communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 10000") + compObj2 = communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 10001") + test(compObj1 != compObj2) + #test(compObj1 < compObj2) + #test(!(compObj2 < compObj1)) + + compObj1 = communicator.stringToProxy("foo@MyAdapter1") + compObj2 = communicator.stringToProxy("foo@MyAdapter2") + test(compObj1 != compObj2) + #test(compObj1 < compObj2) + #test(!(compObj2 < compObj1)) + + test(compObj1.ice_locatorCacheTimeout(20) == compObj1.ice_locatorCacheTimeout(20)) + test(compObj1.ice_locatorCacheTimeout(10) != compObj1.ice_locatorCacheTimeout(20)) + #test(compObj1.ice_locatorCacheTimeout(10) < compObj1.ice_locatorCacheTimeout(20)) + #test(!(compObj1.ice_locatorCacheTimeout(20) < compObj1.ice_locatorCacheTimeout(10))) + + test(compObj1.ice_invocationTimeout(20) == compObj1.ice_invocationTimeout(20)); + test(compObj1.ice_invocationTimeout(10) != compObj1.ice_invocationTimeout(20)); + #test(compObj1.ice_invocationTimeout(10) < compObj1.ice_invocationTimeout(20)); + #test(not (compObj1.ice_invocationTimeout(20) < compObj1.ice_invocationTimeout(10))); + + compObj1 = communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 1000") + compObj2 = communicator.stringToProxy("foo@MyAdapter1") + test(compObj1 != compObj2) + #test(compObj1 < compObj2) + #test(!(compObj2 < compObj1)) + + endpts1 = communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 10000").ice_getEndpoints() + endpts2 = communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 10001").ice_getEndpoints() + test(endpts1 != endpts2) + #test(endpts1 < endpts2) + #test(!(endpts2 < endpts1)) + test(endpts1 == communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 10000").ice_getEndpoints()) + + test(compObj1.ice_encodingVersion(Ice::Encoding_1_0) == compObj1.ice_encodingVersion(Ice::Encoding_1_0)) + test(compObj1.ice_encodingVersion(Ice::Encoding_1_0) != compObj1.ice_encodingVersion(Ice::Encoding_1_1)) + #test(compObj.ice_encodingVersion(Ice::Encoding_1_0) < compObj.ice_encodingVersion(Ice::Encoding_1_1)) + #test(! (compObj.ice_encodingVersion(Ice::Encoding_1_1) < compObj.ice_encodingVersion(Ice::Encoding_1_0))) + + # + # TODO: Ideally we should also test comparison of fixed proxies. + # + + puts "ok" + + print "testing checked cast... " + STDOUT.flush + cl = Test::MyClassPrx::checkedCast(base) + test(cl) + + derived = Test::MyDerivedClassPrx::checkedCast(cl) + test(derived) + test(cl == base) + test(derived == base) + test(cl == derived) + + loc = Ice::LocatorPrx::checkedCast(base) + test(loc == nil) + + # + # Upcasting + # + cl2 = Test::MyClassPrx::checkedCast(derived) + obj = Ice::ObjectPrx::checkedCast(derived) + test(cl2) + test(obj) + test(cl2 == obj) + test(cl2 == derived) + + puts "ok" + + print "testing checked cast with context... " + STDOUT.flush + tccp = Test::MyClassPrx::checkedCast(base) + c = tccp.getContext() + test(c == nil || c.length == 0) + + c = { } + c["one"] = "hello" + c["two"] = "world" + tccp = Test::MyClassPrx::checkedCast(base, c) + c2 = tccp.getContext() + test(c == c2) + puts "ok" + + print "testing encoding versioning... " + STDOUT.flush + ref20 = "test -e 2.0:default -p 12010"; + cl20 = Test::MyClassPrx::uncheckedCast(communicator.stringToProxy(ref20)); + begin + cl20.ice_ping(); + test(false); + rescue Ice::UnsupportedEncodingException + # Server 2.0 endpoint doesn't support 1.1 version. + end + + ref10 = "test -e 1.0:default -p 12010" + cl10 = Test::MyClassPrx::uncheckedCast(communicator.stringToProxy(ref10)) + cl10.ice_ping() + cl10.ice_encodingVersion(Ice::Encoding_1_0).ice_ping() + cl.ice_encodingVersion(Ice::Encoding_1_0).ice_ping() + + # 1.3 isn't supported but since a 1.3 proxy supports 1.1, the + # call will use the 1.1 encoding + ref13 = "test -e 1.3:default -p 12010" + cl13 = Test::MyClassPrx::uncheckedCast(communicator.stringToProxy(ref13)) + cl13.ice_ping() + + puts "ok" + + print "testing opaque endpoints... " + STDOUT.flush + + begin + # Invalid -x option + p = communicator.stringToProxy("id:opaque -t 99 -v abc -x abc") + test(false) + rescue Ice::EndpointParseException + end + + begin + # Missing -t and -v + p = communicator.stringToProxy("id:opaque") + test(false) + rescue Ice::EndpointParseException + end + + begin + # Repeated -t + p = communicator.stringToProxy("id:opaque -t 1 -t 1 -v abc") + test(false) + rescue Ice::EndpointParseException + end + + begin + # Repeated -v + p = communicator.stringToProxy("id:opaque -t 1 -v abc -v abc") + test(false) + rescue Ice::EndpointParseException + end + + begin + # Missing -t + p = communicator.stringToProxy("id:opaque -v abc") + test(false) + rescue Ice::EndpointParseException + end + + begin + # Missing -v + p = communicator.stringToProxy("id:opaque -t 1") + test(false) + rescue Ice::EndpointParseException + end + + begin + # Missing arg for -t + p = communicator.stringToProxy("id:opaque -t -v abc") + test(false) + rescue Ice::EndpointParseException + end + + begin + # Missing arg for -v + p = communicator.stringToProxy("id:opaque -t 1 -v") + test(false) + rescue Ice::EndpointParseException + end + + begin + # Not a number for -t + p = communicator.stringToProxy("id:opaque -t x -v abc") + test(false) + rescue Ice::EndpointParseException + end + + begin + # < 0 for -t + p = communicator.stringToProxy("id:opaque -t -1 -v abc") + test(false) + rescue Ice::EndpointParseException + end + + begin + # Invalid char for -v + p = communicator.stringToProxy("id:opaque -t 99 -v x?c") + test(false) + rescue Ice::EndpointParseException + end + + # Legal TCP endpoint expressed as opaque endpoint. + p1 = communicator.stringToProxy("test -e 1.1:opaque -t 1 -e 1.0 -v CTEyNy4wLjAuMeouAAAQJwAAAA==") + pstr = communicator.proxyToString(p1) + test(pstr == "test -t -e 1.1:tcp -h 127.0.0.1 -p 12010 -t 10000") + + # Opaque endpoint encoded with 1.1 encoding. + p2 = communicator.stringToProxy("test -e 1.1: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") + + # Working? + if communicator.getProperties().getPropertyAsInt("Ice.IPv6") == 0 + ssl = communicator.getProperties().getProperty("Ice.Default.Protocol") == "ssl" + tcp = communicator.getProperties().getProperty("Ice.Default.Protocol") == "tcp" + if tcp + p1.ice_encodingVersion(Ice::Encoding_1_0).ice_ping() + end + + # Two legal TCP endpoints expressed as opaque endpoints + p1 = communicator.stringToProxy("test -e 1.0:opaque -t 1 -e 1.0 -v CTEyNy4wLjAuMeouAAAQJwAAAA==:opaque -t 1 -e 1.0 -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") + + # + # 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 -t 2 -e 1.0 -v CTEyNy4wLjAuMREnAAD/////AA==:opaque -t 99 -e 1.0 -v abch") + pstr = communicator.proxyToString(p1) + if ssl + test(pstr == "test -t -e 1.0:ssl -h 127.0.0.1 -p 10001 -t infinite:opaque -t 99 -e 1.0 -v abch") + elsif tcp + test(pstr == "test -t -e 1.0:opaque -t 2 -e 1.0 -v CTEyNy4wLjAuMREnAAD/////AA==:opaque -t 99 -e 1.0 -v abch") + end + + # + # Try to invoke on the SSL endpoint to verify that we get a + # NoEndpointException (or ConnectionRefusedException when + # running with SSL). + # + begin + p1.ice_encodingVersion(Ice::Encoding_1_0).ice_ping() + test(false) + rescue Ice::NoEndpointException + test(!ssl) + rescue Ice::ConnectionRefusedException + test(!tcp) + end + + # + # 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. + # + p2 = derived.echo(p1) + pstr = communicator.proxyToString(p2) + if ssl + test(pstr == "test -t -e 1.0:ssl -h 127.0.0.1 -p 10001 -t infinite:opaque -t 99 -e 1.0 -v abch") + elsif tcp + test(pstr == "test -t -e 1.0:opaque -t 2 -e 1.0 -v CTEyNy4wLjAuMREnAAD/////AA==:opaque -t 99 -e 1.0 -v abch") + end + end + puts "ok" + + return cl +end diff --git a/ruby/test/Ice/proxy/Client.rb b/ruby/test/Ice/proxy/Client.rb new file mode 100755 index 00000000000..47b08bc1a4f --- /dev/null +++ b/ruby/test/Ice/proxy/Client.rb @@ -0,0 +1,55 @@ +#!/usr/bin/env ruby +# ********************************************************************** +# +# Copyright (c) 2003-2015 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 'pathname' +require 'Ice' +slice_dir = Ice.getSliceDir +if slice_dir.empty? + fail "Slice directory not found" +end + +Ice::loadSlice("'-I" + slice_dir + "' Test.ice") +require './AllTests' + +def test(b) + if !b + raise RuntimeError, 'test assertion failed' + end +end + +def run(args, communicator) + myClass = allTests(communicator) + + myClass.shutdown() + return true +end + +begin + initData = Ice::InitializationData.new + initData.properties = Ice.createProperties(ARGV) + communicator = Ice.initialize(ARGV, initData) + status = run(ARGV, communicator) +rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false +end + +if communicator + begin + communicator.destroy() + rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false + end +end + +exit(status ? 0 : 1) diff --git a/ruby/test/Ice/proxy/Test.ice b/ruby/test/Ice/proxy/Test.ice new file mode 100644 index 00000000000..7f3701e81e2 --- /dev/null +++ b/ruby/test/Ice/proxy/Test.ice @@ -0,0 +1,29 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 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/ruby/test/Ice/proxy/run.py b/ruby/test/Ice/proxy/run.py new file mode 100755 index 00000000000..df1cbbd06d0 --- /dev/null +++ b/ruby/test/Ice/proxy/run.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 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") + +sys.exit(0) diff --git a/ruby/test/Ice/slicing/exceptions/AllTests.rb b/ruby/test/Ice/slicing/exceptions/AllTests.rb new file mode 100644 index 00000000000..c7ca6efd6ee --- /dev/null +++ b/ruby/test/Ice/slicing/exceptions/AllTests.rb @@ -0,0 +1,274 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 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. +# +# ********************************************************************** + +Ice::loadSlice('Test.ice') + +def test(b) + if !b + raise RuntimeError, 'test assertion failed' + end +end + +def allTests(communicator) + obj = communicator.stringToProxy("Test:default -p 12010") + t = Test::TestIntfPrx::checkedCast(obj) + + print "base... " + STDOUT.flush + begin + t.baseAsBase() + test(false) + rescue Test::Base => b + test(b.b == "Base.b") + test(b.ice_name() == "Test::Base") + rescue + test(false) + end + puts "ok" + + print "slicing of unknown derived... " + STDOUT.flush + begin + t.unknownDerivedAsBase() + test(false) + rescue Test::Base => b + test(b.b == "UnknownDerived.b") + test(b.ice_name() == "Test::Base") + rescue + test(false) + end + puts "ok" + + print "non-slicing of known derived as base... " + STDOUT.flush + begin + t.knownDerivedAsBase() + test(false) + rescue Test::KnownDerived => k + test(k.b == "KnownDerived.b") + test(k.kd == "KnownDerived.kd") + test(k.ice_name() == "Test::KnownDerived") + rescue + test(false) + end + puts "ok" + + print "non-slicing of known derived as derived... " + STDOUT.flush + begin + t.knownDerivedAsKnownDerived() + test(false) + rescue Test::KnownDerived => k + test(k.b == "KnownDerived.b") + test(k.kd == "KnownDerived.kd") + test(k.ice_name() == "Test::KnownDerived") + rescue + test(false) + end + puts "ok" + + print "slicing of unknown intermediate as base... " + STDOUT.flush + begin + t.unknownIntermediateAsBase() + test(false) + rescue Test::Base => b + test(b.b == "UnknownIntermediate.b") + test(b.ice_name() == "Test::Base") + rescue + test(false) + end + puts "ok" + + print "slicing of known intermediate as base... " + STDOUT.flush + begin + t.knownIntermediateAsBase() + test(false) + rescue Test::KnownIntermediate => ki + test(ki.b == "KnownIntermediate.b") + test(ki.ki == "KnownIntermediate.ki") + test(ki.ice_name() == "Test::KnownIntermediate") + rescue + test(false) + end + puts "ok" + + print "slicing of known most derived as base... " + STDOUT.flush + begin + t.knownMostDerivedAsBase() + test(false) + rescue Test::KnownMostDerived => kmd + test(kmd.b == "KnownMostDerived.b") + test(kmd.ki == "KnownMostDerived.ki") + test(kmd.kmd == "KnownMostDerived.kmd") + test(kmd.ice_name() == "Test::KnownMostDerived") + rescue + test(false) + end + puts "ok" + + print "non-slicing of known intermediate as intermediate... " + STDOUT.flush + begin + t.knownIntermediateAsKnownIntermediate() + test(false) + rescue Test::KnownIntermediate => ki + test(ki.b == "KnownIntermediate.b") + test(ki.ki == "KnownIntermediate.ki") + test(ki.ice_name() == "Test::KnownIntermediate") + rescue + test(false) + end + puts "ok" + + print "non-slicing of known most derived exception as intermediate... " + STDOUT.flush + begin + t.knownMostDerivedAsKnownIntermediate() + test(false) + rescue Test::KnownMostDerived => kmd + test(kmd.b == "KnownMostDerived.b") + test(kmd.ki == "KnownMostDerived.ki") + test(kmd.kmd == "KnownMostDerived.kmd") + test(kmd.ice_name() == "Test::KnownMostDerived") + rescue + test(false) + end + puts "ok" + + print "non-slicing of known most derived as most derived... " + STDOUT.flush + begin + t.knownMostDerivedAsKnownMostDerived() + test(false) + rescue Test::KnownMostDerived => kmd + test(kmd.b == "KnownMostDerived.b") + test(kmd.ki == "KnownMostDerived.ki") + test(kmd.kmd == "KnownMostDerived.kmd") + test(kmd.ice_name() == "Test::KnownMostDerived") + rescue + test(false) + end + puts "ok" + + print "slicing of unknown most derived, known intermediate as base... " + STDOUT.flush + begin + t.unknownMostDerived1AsBase() + test(false) + rescue Test::KnownIntermediate => ki + test(ki.b == "UnknownMostDerived1.b") + test(ki.ki == "UnknownMostDerived1.ki") + test(ki.ice_name() == "Test::KnownIntermediate") + rescue + test(false) + end + puts "ok" + + print "slicing of unknown most derived, known intermediate as intermediate... " + STDOUT.flush + begin + t.unknownMostDerived1AsKnownIntermediate() + test(false) + rescue Test::KnownIntermediate => ki + test(ki.b == "UnknownMostDerived1.b") + test(ki.ki == "UnknownMostDerived1.ki") + test(ki.ice_name() == "Test::KnownIntermediate") + rescue + test(false) + end + puts "ok" + + print "slicing of unknown most derived, unknown intermediate as base... " + STDOUT.flush + begin + t.unknownMostDerived2AsBase() + test(false) + rescue Test::Base => b + test(b.b == "UnknownMostDerived2.b") + test(b.ice_name() == "Test::Base") + rescue + test(false) + end + puts "ok" + + print "unknown most derived in compact format... " + STDOUT.flush + begin + t.unknownMostDerived2AsBaseCompact() + test(false) + rescue Test::Base + # + # For the 1.0 encoding, the unknown exception is sliced to Base. + # + test(t.ice_getEncodingVersion() == Ice::Encoding_1_0) + rescue Ice::UnknownUserException + # + # An UnkonwnUserException is raised for the compact format because the + # most-derived type is unknown and the exception cannot be sliced. + # + test(t.ice_getEncodingVersion() != Ice::Encoding_1_0) + rescue + test(false) + end + puts "ok" + + print "preserved exceptions... " + STDOUT.flush + + begin + t.knownPreservedAsBase() + test(false) + rescue Test::KnownPreservedDerived => ex + test(ex.b == "base") + test(ex.kp == "preserved") + test(ex.kpd == "derived") + rescue + test(false) + end + + begin + t.knownPreservedAsKnownPreserved() + test(false) + rescue Test::KnownPreservedDerived => ex + test(ex.b == "base") + test(ex.kp == "preserved") + test(ex.kpd == "derived") + rescue + test(false) + end + + begin + t.unknownPreservedAsBase() + test(false) + rescue Test::KnownPreservedDerived => ex + test(ex.b == "base") + test(ex.kp == "preserved") + test(ex.kpd == "derived") + rescue + test(false) + end + + begin + t.unknownPreservedAsKnownPreserved() + test(false) + rescue Test::KnownPreservedDerived => ex + test(ex.b == "base") + test(ex.kp == "preserved") + test(ex.kpd == "derived") + rescue + test(false) + end + + puts "ok" + + return t +end diff --git a/ruby/test/Ice/slicing/exceptions/Client.rb b/ruby/test/Ice/slicing/exceptions/Client.rb new file mode 100755 index 00000000000..a1ab21c7411 --- /dev/null +++ b/ruby/test/Ice/slicing/exceptions/Client.rb @@ -0,0 +1,41 @@ +#!/usr/bin/env ruby +# ********************************************************************** +# +# Copyright (c) 2003-2015 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 'pathname' +require 'Ice' +Ice::loadSlice('Test.ice') +require './AllTests' + +def run(args, communicator) + t = allTests(communicator) + t.shutdown() + return true +end + +begin + communicator = Ice.initialize(ARGV) + status = run(ARGV, communicator) +rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false +end + +if communicator + begin + communicator.destroy() + rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false + end +end + +exit(status ? 0 : 1) diff --git a/ruby/test/Ice/slicing/exceptions/Test.ice b/ruby/test/Ice/slicing/exceptions/Test.ice new file mode 100644 index 00000000000..e81c34580f6 --- /dev/null +++ b/ruby/test/Ice/slicing/exceptions/Test.ice @@ -0,0 +1,98 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 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/ruby/test/Ice/slicing/exceptions/run.py b/ruby/test/Ice/slicing/exceptions/run.py new file mode 100755 index 00000000000..c40f6f06f3e --- /dev/null +++ b/ruby/test/Ice/slicing/exceptions/run.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 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/ruby/test/Ice/slicing/objects/AllTests.rb b/ruby/test/Ice/slicing/objects/AllTests.rb new file mode 100644 index 00000000000..e43f52aef98 --- /dev/null +++ b/ruby/test/Ice/slicing/objects/AllTests.rb @@ -0,0 +1,847 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 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 'Ice' +Ice::loadSlice('-I. --all Forward.ice ClientPrivate.ice') + +def test(b) + if !b + raise RuntimeError, 'test assertion failed' + end +end + +def allTests(communicator) + obj = communicator.stringToProxy("Test:default -p 12010") + t = Test::TestIntfPrx::checkedCast(obj) + + print "base as Object... " + STDOUT.flush + o = nil + begin + o = t.SBaseAsObject() + test(o) + test(o.ice_id() == "::Test::SBase") + rescue Ice::Exception + puts $!.inspect + test(false) + end + sb = o + test(sb.is_a?(Test::SBase)) + test(sb) + test(sb.sb == "SBase.sb") + puts "ok" + + print "base as base... " + STDOUT.flush + begin + sb = t.SBaseAsSBase() + test(sb.sb == "SBase.sb") + rescue Ice::Exception + test(false) + end + puts "ok" + + print "base with known derived as base... " + STDOUT.flush + begin + sb = t.SBSKnownDerivedAsSBase() + test(sb.sb == "SBSKnownDerived.sb") + rescue Ice::Exception + test(false) + end + sbskd = sb + test(sbskd.is_a?(Test::SBSKnownDerived)) + test(sbskd) + test(sbskd.sbskd == "SBSKnownDerived.sbskd") + puts "ok" + + print "base with known derived as known derived... " + STDOUT.flush + begin + sbskd = t.SBSKnownDerivedAsSBSKnownDerived() + test(sbskd.sbskd == "SBSKnownDerived.sbskd") + rescue Ice::Exception + test(false) + end + puts "ok" + + print "base with unknown derived as base... " + STDOUT.flush + begin + sb = t.SBSUnknownDerivedAsSBase() + test(sb.sb == "SBSUnknownDerived.sb") + rescue Ice::Exception + test(false) + end + if t.ice_getEncodingVersion() == Ice::Encoding_1_0 + begin + # + # This test succeeds for the 1.0 encoding. + # + sb = t.SBSUnknownDerivedAsSBaseCompact() + test(sb.sb == "SBSUnknownDerived.sb") + rescue + test(false) + end + else + begin + # + # This test fails when using the compact format because the instance cannot + # be sliced to a known type. + # + sb = t.SBSUnknownDerivedAsSBaseCompact() + test(false) + rescue Ice::NoObjectFactoryException + # Expected. + rescue + test(false) + end + end + puts "ok" + + print "unknown with Object as Object... " + STDOUT.flush + begin + o = t.SUnknownAsObject() + test(t.ice_getEncodingVersion() != Ice::Encoding_1_0) + test(o.is_a?(Ice::UnknownSlicedObject)) + test(o.unknownTypeId == "::Test::SUnknown") + test(o._ice_slicedData != nil) + t.checkSUnknown(o) + rescue Ice::NoObjectFactoryException + test(t.ice_getEncodingVersion() == Ice::Encoding_1_0) + rescue Ice::Exception + test(false) + end + puts "ok" + + print "one-element cycle... " + STDOUT.flush + begin + b = t.oneElementCycle() + test(b) + test(b.ice_id() == "::Test::B") + test(b.sb == "B1.sb") + test(b.pb == b) + rescue Ice::Exception + test(false) + end + puts "ok" + + print "two-element cycle... " + STDOUT.flush + begin + b1 = t.twoElementCycle() + test(b1) + test(b1.ice_id() == "::Test::B") + test(b1.sb == "B1.sb") + + b2 = b1.pb + test(b2) + test(b2.ice_id() == "::Test::B") + test(b2.sb == "B2.sb") + test(b2.pb == b1) + rescue Ice::Exception + test(false) + end + puts "ok" + + print "known derived pointer slicing as base... " + STDOUT.flush + begin + b1 = t.D1AsB() + test(b1) + test(b1.ice_id() == "::Test::D1") + test(b1.sb == "D1.sb") + test(b1.pb) + test(b1.pb != b1) + d1 = b1 + test(d1.is_a?(Test::D1)) + test(d1.sd1 == "D1.sd1") + test(d1.pd1) + test(d1.pd1 != b1) + test(b1.pb == d1.pd1) + + b2 = b1.pb + test(b2) + test(b2.pb == b1) + test(b2.sb == "D2.sb") + test(b2.ice_id() == "::Test::B") + rescue Ice::Exception + test(false) + end + puts "ok" + + print "known derived pointer slicing as derived... " + STDOUT.flush + begin + d1 = t.D1AsD1() + test(d1) + test(d1.ice_id() == "::Test::D1") + test(d1.sb == "D1.sb") + test(d1.pb) + test(d1.pb != d1) + + b2 = d1.pb + test(b2) + test(b2.ice_id() == "::Test::B") + test(b2.sb == "D2.sb") + test(b2.pb == d1) + rescue Ice::Exception + test(false) + end + puts "ok" + + print "unknown derived pointer slicing as base... " + STDOUT.flush + begin + b2 = t.D2AsB() + test(b2) + test(b2.ice_id() == "::Test::B") + test(b2.sb == "D2.sb") + test(b2.pb) + test(b2.pb != b2) + + b1 = b2.pb + test(b1) + test(b1.ice_id() == "::Test::D1") + test(b1.sb == "D1.sb") + test(b1.pb == b2) + d1 = b1 + test(d1.is_a?(Test::D1)) + test(d1.sd1 == "D1.sd1") + test(d1.pd1 == b2) + rescue Ice::Exception + test(false) + end + puts "ok" + + print "param ptr slicing with known first... " + STDOUT.flush + begin + b1, b2 = t.paramTest1() + + test(b1) + test(b1.ice_id() == "::Test::D1") + test(b1.sb == "D1.sb") + test(b1.pb == b2) + d1 = b1 + test(d1.is_a?(Test::D1)) + test(d1.sd1 == "D1.sd1") + test(d1.pd1 == b2) + + test(b2) + test(b2.ice_id() == "::Test::B") # No factory, must be sliced + test(b2.sb == "D2.sb") + test(b2.pb == b1) + rescue Ice::Exception + test(false) + end + puts "ok" + + print "param ptr slicing with unknown first... " + STDOUT.flush + begin + b2, b1 = t.paramTest2() + + test(b1) + test(b1.ice_id() == "::Test::D1") + test(b1.sb == "D1.sb") + test(b1.pb == b2) + d1 = b1 + test(d1.is_a?(Test::D1)) + test(d1.sd1 == "D1.sd1") + test(d1.pd1 == b2) + + test(b2) + test(b2.ice_id() == "::Test::B") # No factory, must be sliced + test(b2.sb == "D2.sb") + test(b2.pb == b1) + rescue Ice::Exception + test(false) + end + puts "ok" + + print "return value identity with known first... " + STDOUT.flush + begin + r, p1, p2 = t.returnTest1() + test(r == p1) + rescue Ice::Exception + test(false) + end + puts "ok" + + print "return value identity with unknown first... " + STDOUT.flush + begin + r, p1, p2 = t.returnTest2() + test(r == p1) + rescue Ice::Exception + test(false) + end + puts "ok" + + print "return value identity for input params known first... " + STDOUT.flush + begin + d1 = Test::D1.new + d1.sb = "D1.sb" + d1.sd1 = "D1.sd1" + d3 = Test::D3.new + d3.pb = d1 + d3.sb = "D3.sb" + d3.sd3 = "D3.sd3" + d3.pd3 = d1 + d1.pb = d3 + d1.pd1 = d3 + + b1 = t.returnTest3(d1, d3) + + test(b1) + test(b1.sb == "D1.sb") + test(b1.ice_id() == "::Test::D1") + p1 = b1 + test(p1.is_a?(Test::D1)) + test(p1.sd1 == "D1.sd1") + test(p1.pd1 == b1.pb) + + b2 = b1.pb + test(b2) + test(b2.sb == "D3.sb") + test(b2.ice_id() == "::Test::B") # Sliced by server + test(b2.pb == b1) + p3 = b2 + test(!p3.is_a?(Test::D3)) + + test(b1 != d1) + test(b1 != d3) + test(b2 != d1) + test(b2 != d3) + rescue Ice::Exception + test(false) + end + puts "ok" + + print "return value identity for input params unknown first... " + STDOUT.flush + begin + d1 = Test::D1.new + d1.sb = "D1.sb" + d1.sd1 = "D1.sd1" + d3 = Test::D3.new + d3.pb = d1 + d3.sb = "D3.sb" + d3.sd3 = "D3.sd3" + d3.pd3 = d1 + d1.pb = d3 + d1.pd1 = d3 + + b1 = t.returnTest3(d3, d1) + + test(b1) + test(b1.sb == "D3.sb") + test(b1.ice_id() == "::Test::B") # Sliced by server + p1 = b1 + test(!p1.is_a?(Test::D3)) + + b2 = b1.pb + test(b2) + test(b2.sb == "D1.sb") + test(b2.ice_id() == "::Test::D1") + test(b2.pb == b1) + p3 = b2 + test(p3.is_a?(Test::D1)) + test(p3.sd1 == "D1.sd1") + test(p3.pd1 == b1) + + test(b1 != d1) + test(b1 != d3) + test(b2 != d1) + test(b2 != d3) + rescue Ice::Exception + test(false) + end + puts "ok" + + print "remainder unmarshaling (3 instances)... " + STDOUT.flush + begin + ret, p1, p2 = t.paramTest3() + + test(p1) + test(p1.sb == "D2.sb (p1 1)") + test(p1.pb == nil) + test(p1.ice_id() == "::Test::B") + + test(p2) + test(p2.sb == "D2.sb (p2 1)") + test(p2.pb == nil) + test(p2.ice_id() == "::Test::B") + + test(ret) + test(ret.sb == "D1.sb (p2 2)") + test(ret.pb == nil) + test(ret.ice_id() == "::Test::D1") + rescue Ice::Exception + test(false) + end + puts "ok" + + print "remainder unmarshaling (4 instances)... " + STDOUT.flush + begin + ret, b = t.paramTest4() + + test(b) + test(b.sb == "D4.sb (1)") + test(b.pb == nil) + test(b.ice_id() == "::Test::B") + + test(ret) + test(ret.sb == "B.sb (2)") + test(ret.pb == nil) + test(ret.ice_id() == "::Test::B") + rescue Ice::Exception + test(false) + end + puts "ok" + + print "param ptr slicing, instance marshaled in unknown derived as base... " + STDOUT.flush + begin + b1 = Test::B.new + b1.sb = "B.sb(1)" + b1.pb = b1 + + d3 = Test::D3.new + d3.sb = "D3.sb" + d3.pb = d3 + d3.sd3 = "D3.sd3" + d3.pd3 = b1 + + b2 = Test::B.new + b2.sb = "B.sb(2)" + b2.pb = b1 + + r = t.returnTest3(d3, b2) + + test(r) + test(r.ice_id() == "::Test::B") + test(r.sb == "D3.sb") + test(r.pb == r) + rescue Ice::Exception + test(false) + end + puts "ok" + + print "param ptr slicing, instance marshaled in unknown derived as derived... " + STDOUT.flush + begin + d11 = Test::D1.new + d11.sb = "D1.sb(1)" + d11.pb = d11 + d11.sd1 = "D1.sd1(1)" + d11.pd1 = nil + + d3 = Test::D3.new + d3.sb = "D3.sb" + d3.pb = d3 + d3.sd3 = "D3.sd3" + d3.pd3 = d11 + + d12 = Test::D1.new + d12.sb = "D1.sb(2)" + d12.pb = d12 + d12.sd1 = "D1.sd1(2)" + d12.pd1 = d11 + + r = t.returnTest3(d3, d12) + test(r) + test(r.ice_id() == "::Test::B") + test(r.sb == "D3.sb") + test(r.pb == r) + rescue Ice::Exception + test(false) + end + puts "ok" + + print "sequence slicing... " + STDOUT.flush + begin + ss = Test::SS3.new + ss1b = Test::B.new + ss1b.sb = "B.sb" + ss1b.pb = ss1b + + ss1d1 = Test::D1.new + ss1d1.sb = "D1.sb" + ss1d1.sd1 = "D1.sd1" + ss1d1.pb = ss1b + + ss1d3 = Test::D3.new + ss1d3.sb = "D3.sb" + ss1d3.sd3 = "D3.sd3" + ss1d3.pb = ss1b + + ss2b = Test::B.new + ss2b.sb = "B.sb" + ss2b.pb = ss1b + + ss2d1 = Test::D1.new + ss2d1.sb = "D1.sb" + ss2d1.sd1 = "D1.sd1" + ss2d1.pb = ss2b + + ss2d3 = Test::D3.new + ss2d3.sb = "D3.sb" + ss2d3.sd3 = "D3.sd3" + ss2d3.pb = ss2b + + ss1d1.pd1 = ss2b + ss1d3.pd3 = ss2d1 + + ss2d1.pd1 = ss1d3 + ss2d3.pd3 = ss1d1 + + ss1 = Test::SS1.new + ss1.s = [ss1b, ss1d1, ss1d3] + + ss2 = Test::SS2.new + ss2.s = [ss2b, ss2d1, ss2d3] + + ss = t.sequenceTest(ss1, ss2) + + test(ss.c1) + ss1b = ss.c1.s[0] + ss1d1 = ss.c1.s[1] + test(ss.c2) + ss1d3 = ss.c1.s[2] + + test(ss.c2) + ss2b = ss.c2.s[0] + ss2d1 = ss.c2.s[1] + 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") + rescue Ice::Exception + test(false) + end + puts "ok" + + print "dictionary slicing... " + STDOUT.flush + begin + bin = {} + for i in (0...10) + d1 = Test::D1.new + s = "D1." + i.to_s + d1.sb = s + d1.pb = d1 + d1.sd1 = s + d1.pd1 = nil + bin[i] = d1 + end + + r, bout = t.dictionaryTest(bin) + + test(bout.length == 10) + for i in (0...10) + b = bout[i * 10] + test(b) + s = "D1." + i.to_s + test(b.sb == s) + test(b.pb) + test(b.pb != b) + test(b.pb.sb == s) + test(b.pb.pb == b.pb) + end + + test(r.length == 10) + for i in (0...10) + b = r[i * 20] + test(b) + s = "D1." + (i * 20).to_s + test(b.sb == s) + if i == 0 + test(b.pb == nil) + else + test(b.pb == r[(i - 1) * 20]) + end + d1 = b + test(d1.is_a?(Test::D1)) + test(d1.sd1 == s) + test(d1.pd1 == d1) + end + rescue Ice::Exception + test(false) + end + puts "ok" + + print "base exception thrown as base exception... " + STDOUT.flush + begin + t.throwBaseAsBase() + test(false) + rescue Test::BaseException => e + test(e.ice_name() == "Test::BaseException") + test(e.sbe == "sbe") + test(e.pb) + test(e.pb.sb == "sb") + test(e.pb.pb == e.pb) + rescue Ice::Exception + test(false) + end + puts "ok" + + print "derived exception thrown as base exception... " + STDOUT.flush + begin + t.throwDerivedAsBase() + test(false) + rescue Test::DerivedException => e + test(e.ice_name() == "Test::DerivedException") + test(e.sbe == "sbe") + test(e.pb) + test(e.pb.sb == "sb1") + test(e.pb.pb == e.pb) + test(e.sde == "sde1") + test(e.pd1) + test(e.pd1.sb == "sb2") + test(e.pd1.pb == e.pd1) + test(e.pd1.sd1 == "sd2") + test(e.pd1.pd1 == e.pd1) + rescue Ice::Exception + test(false) + end + puts "ok" + + print "derived exception thrown as derived exception... " + STDOUT.flush + begin + t.throwDerivedAsDerived() + test(false) + rescue Test::DerivedException => e + test(e.ice_name() == "Test::DerivedException") + test(e.sbe == "sbe") + test(e.pb) + test(e.pb.sb == "sb1") + test(e.pb.pb == e.pb) + test(e.sde == "sde1") + test(e.pd1) + test(e.pd1.sb == "sb2") + test(e.pd1.pb == e.pd1) + test(e.pd1.sd1 == "sd2") + test(e.pd1.pd1 == e.pd1) + rescue Ice::Exception + test(false) + end + puts "ok" + + print "unknown derived exception thrown as base exception... " + STDOUT.flush + begin + t.throwUnknownDerivedAsBase() + test(false) + rescue Test::BaseException => e + test(e.ice_name() == "Test::BaseException") + test(e.sbe == "sbe") + test(e.pb) + test(e.pb.sb == "sb d2") + test(e.pb.pb == e.pb) + rescue Ice::Exception + test(false) + end + puts "ok" + + print "forward-declared class... " + STDOUT.flush + begin + f = t.useForward() + test(f) + rescue Ice::Exception + test(false) + end + puts "ok" + + print "preserved classes... " + STDOUT.flush + + # + # Server knows the most-derived class PDerived. + # + pd = Test::PDerived.new() + pd.pi = 3 + pd.ps = "preserved" + pd.pb = pd + + r = t.exchangePBase(pd) + test(r.is_a?(Test::PDerived)) + test(r.pi == 3) + test(r.ps == "preserved") + test(r.pb == r) + + # + # Server only knows the base (non-preserved) type, so the object is sliced. + # + pu = Test::PCUnknown.new() + pu.pi = 3 + pu.pu = "preserved" + + r = t.exchangePBase(pu) + test(!r.is_a?(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. + # + pcd = Test::PCDerived.new() + pcd.pi = 3 + pcd.pbs = [ pcd ] + + r = t.exchangePBase(pcd) + if t.ice_getEncodingVersion() == Ice::Encoding_1_0 + test(!r.is_a?(Test::PCDerived)) + test(r.pi == 3) + else + test(r.is_a?(Test::PCDerived)) + test(r.pi == 3) + test(r.pbs[0] == r) + end + + # + # Server only knows the intermediate type CompactPDerived. The object will be sliced to + # CompactPDerived for the 1.0 encoding; otherwise it should be returned intact. + # + pcd = Test::CompactPCDerived.new() + pcd.pi = 3 + pcd.pbs = [ pcd ] + + r = t.exchangePBase(pcd) + if t.ice_getEncodingVersion() == Ice::Encoding_1_0 + test(!r.is_a?(Test::CompactPCDerived)) + test(r.pi == 3) + else + test(r.is_a?(Test::CompactPCDerived)) + test(r.pi == 3) + test(r.pbs[0] == r) + end + + # + # Send an object that will have multiple preserved slices in the server. + # The object will be sliced to PDerived for the 1.0 encoding. + # + pcd = Test::PCDerived3.new() + pcd.pi = 3 + # + # Sending more than 254 objects exercises the encoding for object ids. + # + pcd.pbs = [] + for i in (0...300) + p2 = Test::PCDerived2.new() + p2.pi = i + p2.pbs = [ nil ] # Nil reference. This slice should not have an indirection table. + p2.pcd2 = i + pcd.pbs.push(p2) + end + pcd.pcd2 = pcd.pi + pcd.pcd3 = pcd.pbs[10] + + r = t.exchangePBase(pcd) + if t.ice_getEncodingVersion() == Ice::Encoding_1_0 + test(!r.is_a?(Test::PCDerived3)) + test(r.is_a?(Test::PDerived)) + test(r.pi == 3) + else + test(r.is_a?(Test::PCDerived3)) + test(r.pi == 3) + for i in (0...300) + p2 = r.pbs[i] + test(p2.is_a?(Test::PCDerived2)) + test(p2.pi == i) + test(p2.pbs.length == 1) + test(!p2.pbs[0]) + test(p2.pcd2 == i) + end + test(r.pcd2 == r.pi) + test(r.pcd3 == r.pbs[10]) + end + + # + # 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. + # + p = t.PBSUnknownAsPreserved() + t.checkPBSUnknown(p) + if t.ice_getEncodingVersion() != Ice::Encoding_1_0 + t.ice_encodingVersion(Ice::Encoding_1_0).checkPBSUnknown(p) + end + + # + # Relay a graph through the server. This test uses a preserved class + # with a class member. + # + c = Test::PNode.new() + c._next = Test::PNode.new() + c._next._next = Test::PNode.new() + c._next._next._next = c # Create a cyclic graph. + + n = t.exchangePNode(c) + test(n._next != nil) + test(n._next != n._next._next) + test(n._next._next != n._next._next._next) + test(n._next._next._next == n) + n = nil # Release reference. + + # + # Obtain a preserved object from the server where the most-derived + # type is unknown. The preserved slice refers to a graph of PNode + # objects. + # + p = t.PBSUnknownAsPreservedWithGraph() + test(p) + t.checkPBSUnknownWithGraph(p) + p = nil # Release reference. + + # + # Obtain a preserved object from the server where the most-derived + # type is unknown. A data member in the preserved slice refers to the + # outer object, so the chain of references looks like this: + # + # outer->slicedData->outer + # + p = t.PBSUnknown2AsPreservedWithGraph() + test(p != nil) + if t.ice_getEncodingVersion() != Ice::Encoding_1_0 + test(p._ice_slicedData != nil) + end + t.checkPBSUnknown2WithGraph(p) + p._ice_slicedData = nil # Break the cycle. + p = nil # Release reference. + + puts "ok" + + return t +end diff --git a/ruby/test/Ice/slicing/objects/Client.rb b/ruby/test/Ice/slicing/objects/Client.rb new file mode 100755 index 00000000000..015fc7aa591 --- /dev/null +++ b/ruby/test/Ice/slicing/objects/Client.rb @@ -0,0 +1,39 @@ +#!/usr/bin/env ruby +# ********************************************************************** +# +# Copyright (c) 2003-2015 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 'pathname' +require './AllTests' + +def run(args, communicator) + t = allTests(communicator) + t.shutdown() + return true +end + +begin + communicator = Ice.initialize(ARGV) + status = run(ARGV, communicator) +rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false +end + +if communicator + begin + communicator.destroy() + rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false + end +end + +exit(status ? 0 : 1) diff --git a/ruby/test/Ice/slicing/objects/ClientPrivate.ice b/ruby/test/Ice/slicing/objects/ClientPrivate.ice new file mode 100644 index 00000000000..3880bd583ab --- /dev/null +++ b/ruby/test/Ice/slicing/objects/ClientPrivate.ice @@ -0,0 +1,49 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 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 <Test.ice> + +module Test +{ + +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; +}; + +}; diff --git a/ruby/test/Ice/slicing/objects/Forward.ice b/ruby/test/Ice/slicing/objects/Forward.ice new file mode 100644 index 00000000000..89486e226cc --- /dev/null +++ b/ruby/test/Ice/slicing/objects/Forward.ice @@ -0,0 +1,27 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 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 Forward; + +class Hidden +{ + Forward f; +}; + +class Forward +{ + Hidden h; +}; + +}; diff --git a/ruby/test/Ice/slicing/objects/Test.ice b/ruby/test/Ice/slicing/objects/Test.ice new file mode 100644 index 00000000000..3b1d13db6bd --- /dev/null +++ b/ruby/test/Ice/slicing/objects/Test.ice @@ -0,0 +1,164 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 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 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 +{ +}; + +["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(); +}; + +}; + diff --git a/ruby/test/Ice/slicing/objects/run.py b/ruby/test/Ice/slicing/objects/run.py new file mode 100755 index 00000000000..c40f6f06f3e --- /dev/null +++ b/ruby/test/Ice/slicing/objects/run.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 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/ruby/test/Ice/timeout/AllTests.rb b/ruby/test/Ice/timeout/AllTests.rb new file mode 100644 index 00000000000..95f8b18506d --- /dev/null +++ b/ruby/test/Ice/timeout/AllTests.rb @@ -0,0 +1,209 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 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. +# +# ********************************************************************** + +def allTests(communicator) + sref = "timeout:default -p 12010" + obj = communicator.stringToProxy(sref) + test(obj) + + timeout = Test::TimeoutPrx::checkedCast(obj) + test(timeout) + + print "testing connect timeout... " + STDOUT.flush + # + # Expect ConnectTimeoutException. + # + to = Test::TimeoutPrx::uncheckedCast(obj.ice_timeout(100)) + timeout.holdAdapter(500) + begin + to.op() + test(false) + rescue Ice::ConnectTimeoutException + # Expected. + end + + # + # Expect success. + # + timeout.op() # Ensure adapter is active. + to = Test::TimeoutPrx::uncheckedCast(obj.ice_timeout(1000)) + timeout.holdAdapter(500) + begin + to.op() + rescue Ice::ConnectTimeoutException + test(false) + end + puts "ok" + + print "testing connection timeout... " + STDOUT.flush + # + # Expect TimeoutException. + # + seq = "\0" * 10000000 # 10,000,000 entries + to = Test::TimeoutPrx::uncheckedCast(obj.ice_timeout(100)) + timeout.holdAdapter(500) + begin + to.sendData(seq) + test(false) + rescue Ice::TimeoutException + # Expected. + end + # + # Expect success. + # + timeout.op() # Ensure adapter is active. + to = Test::TimeoutPrx::uncheckedCast(obj.ice_timeout(1000)) + timeout.holdAdapter(500) + begin + seq2 = "\0" * 1000000 # 1,000,000 entries + to.sendData(seq2) + rescue Ice::TimeoutException + test(false) + end + puts "ok" + + print "testing invocation timeout... " + STDOUT.flush + connection = obj.ice_getConnection() + to = Test::TimeoutPrx.uncheckedCast(obj.ice_invocationTimeout(100)) + test(connection == to.ice_getConnection()) + begin + to.sleep(750) + test(false) + rescue Ice::InvocationTimeoutException + # Expected + end + obj.ice_ping(); + + to = Test::TimeoutPrx.uncheckedCast(obj.ice_invocationTimeout(500)) + test(connection == to.ice_getConnection()) + begin + to.sleep(250) + rescue Ice::InvocationTimeoutException + test(false) + end + test(connection == to.ice_getConnection()) + puts "ok" + + print "testing close timeout... " + STDOUT.flush + to = Test::TimeoutPrx.checkedCast(obj.ice_timeout(100)) + connection = to.ice_getConnection() + timeout.holdAdapter(500) + connection.close(false) + begin + connection.getInfo() # getInfo() doesn't throw in the closing state. + rescue Ice::LocalException + test(false) + end + sleep(0.5) + begin + connection.getInfo() + test(false) + rescue Ice::CloseConnectionException + # Expected. + end + timeout.op() # Ensure adapter is active. + puts "ok" + + print "testing timeout overrides... " + STDOUT.flush + # + # Test Ice.Override.Timeout. This property overrides all + # endpoint timeouts. + # + initData = Ice::InitializationData.new + initData.properties = communicator.getProperties().clone() + initData.properties.setProperty("Ice.Override.Timeout", "100") + comm = Ice.initialize(initData) + to = Test::TimeoutPrx::checkedCast(comm.stringToProxy(sref)) + timeout.holdAdapter(500) + begin + to.sendData(seq) + test(false) + rescue Ice::TimeoutException + # expected + end + # + # Calling ice_timeout() should have no effect. + # + timeout.op() # Ensure adapter is active. + to = Test::TimeoutPrx::checkedCast(to.ice_timeout(1000)) + timeout.holdAdapter(500) + begin + to.sendData(seq) + test(false) + rescue Ice::TimeoutException + # Expected. + end + comm.destroy() + + # + # Test Ice.Override.ConnectTimeout. + # + initData = Ice::InitializationData.new + initData.properties = communicator.getProperties().clone() + initData.properties.setProperty("Ice.Override.ConnectTimeout", "250") + comm = Ice.initialize(initData) + timeout.holdAdapter(750) + to = Test::TimeoutPrx::uncheckedCast(comm.stringToProxy(sref)) + begin + to.op() + test(false) + rescue Ice::ConnectTimeoutException + # expected + end + + # + # Calling ice_timeout() should have no effect on the connect timeout. + # + timeout.op() # Ensure adapter is active. + timeout.holdAdapter(750) + to = Test::TimeoutPrx::uncheckedCast(to.ice_timeout(1000)) + begin + to.op() + test(false) + rescue Ice::ConnectTimeoutException + # expected + end + + # + # Verify that timeout set via ice_timeout() is still used for requests. + # + timeout.op() # Ensure adapter is active. + to = Test::TimeoutPrx::uncheckedCast(to.ice_timeout(100)) + to.ice_getConnection() # Establish connection. + timeout.holdAdapter(750) + begin + to.sendData(seq) + test(false) + rescue Ice::TimeoutException + # Expected. + end + comm.destroy() + + # + # Test Ice.Override.CloseTimeout. + # + initData = Ice::InitializationData.new + initData.properties = communicator.getProperties().clone() + initData.properties.setProperty("Ice.Override.CloseTimeout", "100") + comm = Ice.initialize(initData) + connection = comm.stringToProxy(sref).ice_getConnection(); + timeout.holdAdapter(500); + now = Time.now + comm.destroy(); + test((Time.now - now) < 0.4); + + puts "ok" + + return timeout +end diff --git a/ruby/test/Ice/timeout/Client.rb b/ruby/test/Ice/timeout/Client.rb new file mode 100755 index 00000000000..9d97518c724 --- /dev/null +++ b/ruby/test/Ice/timeout/Client.rb @@ -0,0 +1,82 @@ +#!/usr/bin/env ruby +# ********************************************************************** +# +# Copyright (c) 2003-2015 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 'pathname' +require 'Ice' +slice_dir = Ice.getSliceDir +if slice_dir.empty? + fail "Slice directory not found" +end + +Ice::loadSlice("'-I" + slice_dir + "' Test.ice") +require './AllTests' + +def test(b) + if !b + raise RuntimeError, 'test assertion failed' + end +end + +def run(args, communicator) + myClass = allTests(communicator) + + myClass.shutdown() + return true +end + +begin + # + # In this test, we need at least two threads in the + # client side thread pool for nested AMI. + # + initData = Ice::InitializationData.new + initData.properties = Ice.createProperties(ARGV) + + # + # We need to send messages large enough to cause the transport + # buffers to fill up. + # + initData.properties.setProperty("Ice.MessageSizeMax", "10000"); + + # + # For this test, we want to disable retries. + # + initData.properties.setProperty('Ice.RetryIntervals', '-1') + + # + # This test kills connections, so we don't want warnings. + # + initData.properties.setProperty('Ice.Warn.Connections', '0') + + # + # Limit the send buffer size, this test relies on the socket + # send() blocking after sending a given amount of data. + # + initData.properties.setProperty("Ice.TCP.SndSize", "50000"); + + communicator = Ice.initialize(ARGV, initData) + status = run(ARGV, communicator) +rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false +end + +if communicator + begin + communicator.destroy() + rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false + end +end + +exit(status ? 0 : 1) diff --git a/ruby/test/Ice/timeout/Test.ice b/ruby/test/Ice/timeout/Test.ice new file mode 100644 index 00000000000..dc54d71c16c --- /dev/null +++ b/ruby/test/Ice/timeout/Test.ice @@ -0,0 +1,28 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 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/ruby/test/Ice/timeout/run.py b/ruby/test/Ice/timeout/run.py new file mode 100755 index 00000000000..ca437762ed3 --- /dev/null +++ b/ruby/test/Ice/timeout/run.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 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() + diff --git a/ruby/test/Slice/keyword/Client.rb b/ruby/test/Slice/keyword/Client.rb new file mode 100755 index 00000000000..eee28bb0a4c --- /dev/null +++ b/ruby/test/Slice/keyword/Client.rb @@ -0,0 +1,91 @@ +#!/usr/bin/env ruby +# ********************************************************************** +# +# Copyright (c) 2003-2015 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 'pathname' + +rubyDir = nil +for toplevel in [".", "..", "../..", "../../..", "../../../.."] + path = Pathname.new(toplevel).join("ruby", "Ice.rb") + if path.file? + rubyDir = Pathname.new(toplevel).join("ruby") + break + end +end +if not rubyDir + fail "can't find toplevel directory!" +end + +require 'Ice' +Ice::loadSlice('--underscore Key.ice') + +def test(b) + if !b + raise RuntimeError, 'test assertion failed' + end +end + +class DisplayI < BEGIN_::Display + def _do(_dup, current=nil) + end +end + +def run(args, communicator) + print "testing type names... " + STDOUT.flush + a = BEGIN_::END_::Alias + b = BEGIN_::And.new + b._begin = 0; + c = BEGIN_::BreakPrx::uncheckedCast(communicator.stringToProxy("test:tcp")) + test(c.method(:_case)) + test(c.method(:_to_a)) + test(c.method(:_instance_variable_set)) + test(c.method(:_instance_variables)) + d = BEGIN_::DisplayPrx::uncheckedCast(communicator.stringToProxy("test:tcp")) + test(d.method(:_do)) + d1 = DisplayI.new + e = BEGIN_::ElsifPrx::uncheckedCast(communicator.stringToProxy("test:tcp")) + test(e.method(:_do)) + test(e.method(:_case)) + f = BEGIN_::Next.new + f._new = 0 + g = BEGIN_::Nil.new + g._new = 0 + g._not = 0 + g._or = 0 + # TODO: Test local interface + #h = BEGIN_::ExtendPrx::uncheckedCast(communicator.stringToProxy("test:tcp")) + i = BEGIN_::Redo + puts "ok" + + return true +end + +begin + initData = Ice::InitializationData.new + initData.properties = Ice.createProperties(ARGV) + communicator = Ice.initialize(ARGV, initData) + status = run(ARGV, communicator) +rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false +end + +if communicator + begin + communicator.destroy() + rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false + end +end + +exit(status ? 0 : 1) diff --git a/ruby/test/Slice/keyword/Key.ice b/ruby/test/Slice/keyword/Key.ice new file mode 100644 index 00000000000..4ae5ddc9c15 --- /dev/null +++ b/ruby/test/Slice/keyword/Key.ice @@ -0,0 +1,61 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 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 BEGIN +{ + enum END + { + alias + }; + + struct and + { + int begin; + }; + + interface break + { + void case(int clone, int def); + void to_a(); + void instance_variable_set(); + void instance_variables(); + }; + + class display + { + int when; + void do(break* dup, out int else); + }; + + class elsif extends display implements break + { + }; + + sequence<END> rescue; + dictionary<string, END> ensure; + + exception next + { + int new; + }; + + exception nil extends next + { + int not; + int or; + }; + + local interface extend + { + END for(display freeze, elsif hash, break* if, display inspect, elsif method, int methods) + throws nil; + }; + + const int redo = 1; +}; diff --git a/ruby/test/Slice/keyword/run.py b/ruby/test/Slice/keyword/run.py new file mode 100755 index 00000000000..2d07bcb513c --- /dev/null +++ b/ruby/test/Slice/keyword/run.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 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 + +sys.stdout.write("starting client... ") +sys.stdout.flush() +clientProc = TestUtil.startClient("Client.rb", "--Ice.Default.Host=127.0.0.1", startReader = False) +print("ok") +clientProc.startReader() +clientProc.waitTestSuccess() diff --git a/ruby/test/Slice/macros/Client.rb b/ruby/test/Slice/macros/Client.rb new file mode 100755 index 00000000000..3dc25dcf49f --- /dev/null +++ b/ruby/test/Slice/macros/Client.rb @@ -0,0 +1,57 @@ +#!/usr/bin/env ruby +# ********************************************************************** +# +# Copyright (c) 2003-2015 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 'pathname' + +rubyDir = nil +for toplevel in [".", "..", "../..", "../../..", "../../../.."] + path = Pathname.new(toplevel).join("ruby", "Ice.rb") + if path.file? + rubyDir = Pathname.new(toplevel).join("ruby") + break + end +end +if not rubyDir + fail "can't find toplevel directory!" +end + +require 'Ice' +Ice::loadSlice('Test.ice') + +def test(b) + if !b + raise RuntimeError, 'test assertion failed' + end +end + +status = true + +begin + print "testing Slice predefined macros... " + STDOUT.flush + d = Test::Default.new + test(d.x == 10) + test(d.y == 10) + + nd = Test::NoDefault.new + test(nd.x != 10) + test(nd.y != 10) + + c = Test::RubyOnly.new + test(c.lang.eql? "ruby") + test(c.version == Ice::intVersion()) + puts "ok" +rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false +end + +exit(status ? 0 : 1) diff --git a/ruby/test/Slice/macros/Test.ice b/ruby/test/Slice/macros/Test.ice new file mode 100644 index 00000000000..932414274f8 --- /dev/null +++ b/ruby/test/Slice/macros/Test.ice @@ -0,0 +1,54 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 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. +// +// ********************************************************************** + +// +// This macro sets the default value only when compiling with slice2rb. +// +#ifdef __SLICE2RB__ +# define DEFAULT(X) = X +#else +# define DEFAULT(X) /**/ +#endif + +// +// This macro sets the default value only when not compiling with slice2rb. +// +#ifndef __SLICE2RB__ +# define NODEFAULT(X) = X +#else +# define NODEFAULT(X) /**/ +#endif + +module Test +{ + +class Default +{ + int x DEFAULT(10); + int y DEFAULT(10); +}; + +class NoDefault +{ + int x NODEFAULT(10); + int y NODEFAULT(10); +}; + +// +// This class is only defined when compiling with slice2rb. +// +#ifdef __SLICE2RB__ +class RubyOnly +{ + string lang DEFAULT("ruby"); + int version DEFAULT(ICE_VERSION); +}; +#endif + +}; diff --git a/ruby/test/Slice/macros/run.py b/ruby/test/Slice/macros/run.py new file mode 100755 index 00000000000..b426a2dd72c --- /dev/null +++ b/ruby/test/Slice/macros/run.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 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 + +sys.stdout.write("starting client... ") +sys.stdout.flush() +clientProc = TestUtil.startClient("Client.rb", "--Ice.Default.Host=127.0.0.1", startReader = False) +print("ok") +clientProc.startReader() +clientProc.waitTestSuccess() + diff --git a/ruby/test/Slice/structure/Client.rb b/ruby/test/Slice/structure/Client.rb new file mode 100755 index 00000000000..9ae0482431c --- /dev/null +++ b/ruby/test/Slice/structure/Client.rb @@ -0,0 +1,229 @@ +#!/usr/bin/env ruby +# ********************************************************************** +# +# Copyright (c) 2003-2015 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 'pathname' + +rubyDir = nil +for toplevel in [".", "..", "../..", "../../..", "../../../.."] + path = Pathname.new(toplevel).join("ruby", "Ice.rb") + if path.file? + rubyDir = Pathname.new(toplevel).join("ruby") + break + end +end +if not rubyDir + fail "can't find toplevel directory!" +end + +require 'Ice' +Ice::loadSlice('Test.ice') + +def test(b) + if !b + raise RuntimeError, 'test assertion failed' + end +end + +def allTests(communicator) + print "testing equals() for Slice structures... " + STDOUT.flush + + # + # Define some default values. + # + def_s2 = Test::S2.new(true, 98, 99, 100, 101, 1.0, 2.0, "string", ["one", "two", "three"], {"abc"=>"def"}, \ + Test::S1.new("name"), Test::C.new(5), communicator.stringToProxy("test")) + + # + # Compare default-constructed structures. + # + test(Test::S2.new.eql?(Test::S2.new)) + + # + # Change one primitive member at a time. + # + v = def_s2.clone + test(v.eql?(def_s2)) + + v = def_s2.clone + v.bo = false + test(!v.eql?(def_s2)) + + v = def_s2.clone + v.by = v.by - 1 + test(!v.eql?(def_s2)) + + v = def_s2.clone + v.sh = v.sh - 1 + test(!v.eql?(def_s2)) + + v = def_s2.clone + v.i = v.i - 1 + test(!v.eql?(def_s2)) + + v = def_s2.clone + v.l = v.l - 1 + test(!v.eql?(def_s2)) + + v = def_s2.clone + v.f = v.f - 1 + test(!v.eql?(def_s2)) + + v = def_s2.clone + v.d = v.d - 1 + test(!v.eql?(def_s2)) + + v = def_s2.clone + v.str = "" + test(!v.eql?(def_s2)) + + # + # String member + # + v1 = def_s2.clone + v1.str = "string" + test(v1.eql?(def_s2)) + + v1 = def_s2.clone + v2 = def_s2.clone + v1.str = nil + test(!v1.eql?(v2)) + + v1 = def_s2.clone + v2 = def_s2.clone + v2.str = nil + test(!v1.eql?(v2)) + + v1 = def_s2.clone + v2 = def_s2.clone + v1.str = nil + v2.str = nil + test(v1.eql?(v2)) + + # + # Sequence member + # + v1 = def_s2.clone + v1.ss = def_s2.ss.clone + test(v1.eql?(def_s2)) + + v1 = def_s2.clone + v1.ss = [] + test(!v1.eql?(def_s2)) + + v1 = def_s2.clone + v1.ss = ["one", "two", "three"] + test(v1.eql?(def_s2)) + + v1 = def_s2.clone + v2 = def_s2.clone + v1.ss = nil + test(!v1.eql?(v2)) + + v1 = def_s2.clone + v2 = def_s2.clone + v2.ss = nil + test(!v1.eql?(v2)) + + # + # Dictionary member + # + v1 = def_s2.clone + v1.sd = {"abc"=>"def"} + test(v1.eql?(def_s2)) + + v1 = def_s2.clone + v1.sd = {} + test(!v1.eql?(def_s2)) + + v1 = def_s2.clone + v2 = def_s2.clone + v1.sd = nil + test(!v1.eql?(v2)) + + v1 = def_s2.clone + v2 = def_s2.clone + v2.sd = nil + test(!v1.eql?(v2)) + + # + # Struct member + # + v1 = def_s2.clone + v1.s = def_s2.s.clone + test(v1.eql?(def_s2)) + + v1 = def_s2.clone + v1.s = Test::S1.new("name") + test(v1.eql?(def_s2)) + + v1 = def_s2.clone + v1.s = Test::S1.new("noname") + test(!v1.eql?(def_s2)) + + # + # Class member + # + v1 = def_s2.clone + v1.cls = def_s2.cls.clone + test(!v1.eql?(def_s2)) + + # + # Proxy member + # + v1 = def_s2.clone + v1.prx = communicator.stringToProxy("test") + test(v1.eql?(def_s2)) + + v1 = def_s2.clone + v1.prx = communicator.stringToProxy("test2") + test(!v1.eql?(def_s2)) + + v1 = def_s2.clone + v2 = def_s2.clone + v1.prx = nil + test(!v1.eql?(v2)) + + v1 = def_s2.clone + v2 = def_s2.clone + v2.prx = nil + test(!v1.eql?(v2)) + + puts "ok" +end + +def run(args, communicator) + allTests(communicator) + + return true +end + +begin + initData = Ice::InitializationData.new + initData.properties = Ice.createProperties(ARGV) + communicator = Ice.initialize(ARGV, initData) + status = run(ARGV, communicator) +rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false +end + +if communicator + begin + communicator.destroy() + rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false + end +end + +exit(status ? 0 : 1) diff --git a/ruby/test/Slice/structure/Test.ice b/ruby/test/Slice/structure/Test.ice new file mode 100644 index 00000000000..d1be5ddc435 --- /dev/null +++ b/ruby/test/Slice/structure/Test.ice @@ -0,0 +1,45 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 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. +// +// ********************************************************************** + +[["cpp:include:list"]] + +module Test +{ + +sequence<string> StringSeq; +dictionary<string, string> StringDict; + +class C +{ + int i; +}; + +struct S1 +{ + string name; +}; + +struct S2 +{ + bool bo; + byte by; + short sh; + int i; + long l; + float f; + double d; + string str; + StringSeq ss; + StringDict sd; + S1 s; + C cls; + Object* prx; +}; + +}; diff --git a/ruby/test/Slice/structure/run.py b/ruby/test/Slice/structure/run.py new file mode 100755 index 00000000000..b426a2dd72c --- /dev/null +++ b/ruby/test/Slice/structure/run.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 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 + +sys.stdout.write("starting client... ") +sys.stdout.flush() +clientProc = TestUtil.startClient("Client.rb", "--Ice.Default.Host=127.0.0.1", startReader = False) +print("ok") +clientProc.startReader() +clientProc.waitTestSuccess() + |