diff options
author | Mark Spruiell <mes@zeroc.com> | 2012-05-16 16:05:50 -0700 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2012-05-16 16:05:50 -0700 |
commit | 3b6fbd2cb1ab0e9f6dbdfd4cbda02eb16fd85569 (patch) | |
tree | edfa533e67fb4ee003d1afbb2e1ba8a9b03ef3f3 | |
parent | porting ami test changes to python (diff) | |
download | ice-3b6fbd2cb1ab0e9f6dbdfd4cbda02eb16fd85569.tar.bz2 ice-3b6fbd2cb1ab0e9f6dbdfd4cbda02eb16fd85569.tar.xz ice-3b6fbd2cb1ab0e9f6dbdfd4cbda02eb16fd85569.zip |
* Ruby port of sliced/compact/preserved
* Python clean up
* More changes to exceptions test
47 files changed, 1917 insertions, 457 deletions
diff --git a/cpp/src/Slice/RubyUtil.cpp b/cpp/src/Slice/RubyUtil.cpp index 4d941c7c6a8..c9a3bae5820 100755 --- a/cpp/src/Slice/RubyUtil.cpp +++ b/cpp/src/Slice/RubyUtil.cpp @@ -607,7 +607,9 @@ Slice::Ruby::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) _classHistory.insert(scoped); // Avoid redundant declarations. bool isAbstract = p->isInterface() || p->allOperations().size() > 0; // Don't use isAbstract() here - see bug 3739 - _out << sp << nl << "T_" << name << ".defineClass(" << name << ", " << (isAbstract ? "true" : "false") << ", "; + const bool preserved = p->hasMetaData("preserve-slice") || p->inheritsMetaData("preserve-slice"); + _out << sp << nl << "T_" << name << ".defineClass(" << name << ", " << (isAbstract ? "true" : "false") << ", " + << (preserved ? "true" : "false") << ", "; if(!base) { _out << "nil"; @@ -675,7 +677,7 @@ Slice::Ruby::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) // // Define each operation. The arguments to __defineOperation are: // - // 'opName', Mode, [InParams], [OutParams], ReturnType, [Exceptions] + // 'opName', Mode, IsAmd, FormatType, [InParams], [OutParams], ReturnType, [Exceptions] // // where InParams and OutParams are arrays of type descriptions, and Exceptions // is an array of exception types. @@ -694,6 +696,19 @@ Slice::Ruby::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) ParamDeclList params = (*s)->parameters(); ParamDeclList::iterator t; int count; + string format; + switch((*s)->format()) + { + case DefaultFormat: + format = "nil"; + break; + case CompactFormat: + format = "::Ice::FormatType::CompactFormat"; + break; + case SlicedFormat: + format = "::Ice::FormatType::SlicedFormat"; + break; + } _out << nl << name << "_mixin::OP_" << (*s)->name() << " = ::Ice::__defineOperation('" << (*s)->name() << "', "; @@ -722,7 +737,8 @@ Slice::Ruby::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) _out << "::Ice::OperationMode::Idempotent"; break; } - _out << ", " << ((p->hasMetaData("amd") || (*s)->hasMetaData("amd")) ? "true" : "false") << ", ["; + _out << ", " << ((p->hasMetaData("amd") || (*s)->hasMetaData("amd")) ? "true" : "false") << ", " << format + << ", ["; for(t = params.begin(), count = 0; t != params.end(); ++t) { if(!(*t)->isOutParam()) diff --git a/cpp/test/Ice/slicing/exceptions/AllTests.cpp b/cpp/test/Ice/slicing/exceptions/AllTests.cpp index d1102c0dd7e..74ce31bba6c 100644 --- a/cpp/test/Ice/slicing/exceptions/AllTests.cpp +++ b/cpp/test/Ice/slicing/exceptions/AllTests.cpp @@ -327,17 +327,19 @@ class RelayI : public Relay { virtual void knownPreservedAsBase(const ::Ice::Current&) { - KnownPreserved ex; + KnownPreservedDerived ex; ex.b = "base"; ex.kp = "preserved"; + ex.kpd = "derived"; throw ex; } virtual void knownPreservedAsKnownPreserved(const ::Ice::Current&) { - KnownPreserved ex; + KnownPreservedDerived ex; ex.b = "base"; ex.kp = "preserved"; + ex.kpd = "derived"; throw ex; } @@ -346,6 +348,7 @@ class RelayI : public Relay Preserved2 ex; ex.b = "base"; ex.kp = "preserved"; + ex.kpd = "derived"; ex.p1 = new PreservedClass("bc", "pc"); ex.p2 = ex.p1; throw ex; @@ -356,6 +359,7 @@ class RelayI : public Relay Preserved2 ex; ex.b = "base"; ex.kp = "preserved"; + ex.kpd = "derived"; ex.p1 = new PreservedClass("bc", "pc"); ex.p2 = ex.p1; throw ex; @@ -795,10 +799,11 @@ allTests(const Ice::CommunicatorPtr& communicator) test->relayKnownPreservedAsBase(relay); test(false); } - catch(const KnownPreserved& ex) + catch(const KnownPreservedDerived& ex) { test(ex.b == "base"); test(ex.kp == "preserved"); + test(ex.kpd == "derived"); } catch(...) { @@ -810,10 +815,11 @@ allTests(const Ice::CommunicatorPtr& communicator) test->relayKnownPreservedAsKnownPreserved(relay); test(false); } - catch(const KnownPreserved& ex) + catch(const KnownPreservedDerived& ex) { test(ex.b == "base"); test(ex.kp == "preserved"); + test(ex.kpd == "derived"); } catch(...) { @@ -829,13 +835,14 @@ allTests(const Ice::CommunicatorPtr& communicator) { test(ex.b == "base"); test(ex.kp == "preserved"); + test(ex.kpd == "derived"); test(ex.p1->ice_id() == PreservedClass::ice_staticId()); PreservedClassPtr pc = PreservedClassPtr::dynamicCast(ex.p1); test(pc->bc == "bc"); test(pc->pc == "pc"); test(ex.p2 == ex.p1); } - catch(const KnownPreserved& ex) + catch(const KnownPreservedDerived& ex) { // // For the 1.0 encoding, the unknown exception is sliced to KnownPreserved. @@ -843,6 +850,7 @@ allTests(const Ice::CommunicatorPtr& communicator) test(test->ice_getEncodingVersion() == Ice::Encoding_1_0); test(ex.b == "base"); test(ex.kp == "preserved"); + test(ex.kpd == "derived"); } catch(...) { @@ -858,13 +866,14 @@ allTests(const Ice::CommunicatorPtr& communicator) { test(ex.b == "base"); test(ex.kp == "preserved"); + test(ex.kpd == "derived"); test(ex.p1->ice_id() == PreservedClass::ice_staticId()); PreservedClassPtr pc = PreservedClassPtr::dynamicCast(ex.p1); test(pc->bc == "bc"); test(pc->pc == "pc"); test(ex.p2 == ex.p1); } - catch(const KnownPreserved& ex) + catch(const KnownPreservedDerived& ex) { // // For the 1.0 encoding, the unknown exception is sliced to KnownPreserved. @@ -872,6 +881,7 @@ allTests(const Ice::CommunicatorPtr& communicator) test(test->ice_getEncodingVersion() == Ice::Encoding_1_0); test(ex.b == "base"); test(ex.kp == "preserved"); + test(ex.kpd == "derived"); } catch(...) { diff --git a/cpp/test/Ice/slicing/exceptions/ClientPrivate.ice b/cpp/test/Ice/slicing/exceptions/ClientPrivate.ice index 9b2e381798a..029e6d5d37e 100644 --- a/cpp/test/Ice/slicing/exceptions/ClientPrivate.ice +++ b/cpp/test/Ice/slicing/exceptions/ClientPrivate.ice @@ -19,7 +19,7 @@ class PreservedClass extends BaseClass string pc; }; -exception Preserved1 extends KnownPreserved +exception Preserved1 extends KnownPreservedDerived { BaseClass p1; }; diff --git a/cpp/test/Ice/slicing/exceptions/ServerPrivate.ice b/cpp/test/Ice/slicing/exceptions/ServerPrivate.ice index df89aa2efea..e03994a4641 100644 --- a/cpp/test/Ice/slicing/exceptions/ServerPrivate.ice +++ b/cpp/test/Ice/slicing/exceptions/ServerPrivate.ice @@ -34,4 +34,19 @@ exception UnknownMostDerived2 extends UnknownIntermediate string umd2; }; +class SPreservedClass extends BaseClass +{ + string spc; +}; + +exception SPreserved1 extends KnownPreservedDerived +{ + BaseClass p1; +}; + +exception SPreserved2 extends SPreserved1 +{ + BaseClass p2; +}; + }; diff --git a/cpp/test/Ice/slicing/exceptions/ServerPrivateAMD.ice b/cpp/test/Ice/slicing/exceptions/ServerPrivateAMD.ice index 59542af8d16..7d99c0182c4 100644 --- a/cpp/test/Ice/slicing/exceptions/ServerPrivateAMD.ice +++ b/cpp/test/Ice/slicing/exceptions/ServerPrivateAMD.ice @@ -34,4 +34,19 @@ exception UnknownMostDerived2 extends UnknownIntermediate string umd2; }; +class SPreservedClass extends BaseClass +{ + string spc; +}; + +exception SPreserved1 extends KnownPreservedDerived +{ + BaseClass p1; +}; + +exception SPreserved2 extends SPreserved1 +{ + BaseClass p2; +}; + }; diff --git a/cpp/test/Ice/slicing/exceptions/Test.ice b/cpp/test/Ice/slicing/exceptions/Test.ice index f210b8e2c46..ddf84d47e82 100644 --- a/cpp/test/Ice/slicing/exceptions/Test.ice +++ b/cpp/test/Ice/slicing/exceptions/Test.ice @@ -38,6 +38,11 @@ exception KnownPreserved extends Base string kp; }; +exception KnownPreservedDerived extends KnownPreserved +{ + string kpd; +}; + ["preserve-slice"] class BaseClass { @@ -75,9 +80,15 @@ interface TestIntf ["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; diff --git a/cpp/test/Ice/slicing/exceptions/TestAMD.ice b/cpp/test/Ice/slicing/exceptions/TestAMD.ice index d9e69f00b05..9d5e2422550 100644 --- a/cpp/test/Ice/slicing/exceptions/TestAMD.ice +++ b/cpp/test/Ice/slicing/exceptions/TestAMD.ice @@ -38,6 +38,11 @@ exception KnownPreserved extends Base string kp; }; +exception KnownPreservedDerived extends KnownPreserved +{ + string kpd; +}; + ["preserve-slice"] class BaseClass { @@ -75,9 +80,15 @@ interface TestIntf ["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; diff --git a/cpp/test/Ice/slicing/exceptions/TestAMDI.cpp b/cpp/test/Ice/slicing/exceptions/TestAMDI.cpp index f8358484dfb..f87288d4f08 100644 --- a/cpp/test/Ice/slicing/exceptions/TestAMDI.cpp +++ b/cpp/test/Ice/slicing/exceptions/TestAMDI.cpp @@ -156,6 +156,27 @@ TestI::unknownMostDerived2AsBaseCompact_async(const AMD_TestIntf_unknownMostDeri } void +TestI::knownPreservedAsBase_async(const AMD_TestIntf_knownPreservedAsBasePtr& cb, const ::Ice::Current&) +{ + KnownPreservedDerived ex; + ex.b = "base"; + ex.kp = "preserved"; + ex.kpd = "derived"; + cb->ice_exception(ex); +} + +void +TestI::knownPreservedAsKnownPreserved_async(const AMD_TestIntf_knownPreservedAsKnownPreservedPtr& cb, + const ::Ice::Current&) +{ + KnownPreservedDerived ex; + ex.b = "base"; + ex.kp = "preserved"; + ex.kpd = "derived"; + cb->ice_exception(ex); +} + +void TestI::relayKnownPreservedAsBase_async(const AMD_TestIntf_relayKnownPreservedAsBasePtr& cb, const RelayPrx& r, const ::Ice::Current&) { @@ -186,6 +207,31 @@ TestI::relayKnownPreservedAsKnownPreserved_async(const AMD_TestIntf_relayKnownPr } void +TestI::unknownPreservedAsBase_async(const AMD_TestIntf_unknownPreservedAsBasePtr& cb, const ::Ice::Current&) +{ + SPreserved2 ex; + ex.b = "base"; + ex.kp = "preserved"; + ex.kpd = "derived"; + ex.p1 = new SPreservedClass("bc", "spc"); + ex.p2 = ex.p1; + cb->ice_exception(ex); +} + +void +TestI::unknownPreservedAsKnownPreserved_async(const AMD_TestIntf_unknownPreservedAsKnownPreservedPtr& cb, + const ::Ice::Current&) +{ + SPreserved2 ex; + ex.b = "base"; + ex.kp = "preserved"; + ex.kpd = "derived"; + ex.p1 = new SPreservedClass("bc", "spc"); + ex.p2 = ex.p1; + cb->ice_exception(ex); +} + +void TestI::relayUnknownPreservedAsBase_async(const AMD_TestIntf_relayUnknownPreservedAsBasePtr& cb, const RelayPrx& r, const ::Ice::Current&) { diff --git a/cpp/test/Ice/slicing/exceptions/TestAMDI.h b/cpp/test/Ice/slicing/exceptions/TestAMDI.h index 58772018430..13b3edcd1ff 100644 --- a/cpp/test/Ice/slicing/exceptions/TestAMDI.h +++ b/cpp/test/Ice/slicing/exceptions/TestAMDI.h @@ -54,6 +54,14 @@ public: const ::Test::AMD_TestIntf_unknownMostDerived2AsBaseCompactPtr&, const ::Ice::Current&); + virtual void knownPreservedAsBase_async( + const ::Test::AMD_TestIntf_knownPreservedAsBasePtr&, + const ::Ice::Current&); + + virtual void knownPreservedAsKnownPreserved_async( + const ::Test::AMD_TestIntf_knownPreservedAsKnownPreservedPtr&, + const ::Ice::Current&); + virtual void relayKnownPreservedAsBase_async( const ::Test::AMD_TestIntf_relayKnownPreservedAsBasePtr&, const ::Test::RelayPrx&, @@ -64,6 +72,14 @@ public: const ::Test::RelayPrx&, const ::Ice::Current&); + virtual void unknownPreservedAsBase_async( + const ::Test::AMD_TestIntf_unknownPreservedAsBasePtr&, + const ::Ice::Current&); + + virtual void unknownPreservedAsKnownPreserved_async( + const ::Test::AMD_TestIntf_unknownPreservedAsKnownPreservedPtr&, + const ::Ice::Current&); + virtual void relayUnknownPreservedAsBase_async( const ::Test::AMD_TestIntf_relayUnknownPreservedAsBasePtr&, const ::Test::RelayPrx&, diff --git a/cpp/test/Ice/slicing/exceptions/TestI.cpp b/cpp/test/Ice/slicing/exceptions/TestI.cpp index 7a982738d21..6cbff79f8cc 100644 --- a/cpp/test/Ice/slicing/exceptions/TestI.cpp +++ b/cpp/test/Ice/slicing/exceptions/TestI.cpp @@ -151,6 +151,26 @@ TestI::unknownMostDerived2AsBaseCompact(const ::Ice::Current&) } void +TestI::knownPreservedAsBase(const ::Ice::Current&) +{ + KnownPreservedDerived ex; + ex.b = "base"; + ex.kp = "preserved"; + ex.kpd = "derived"; + throw ex; +} + +void +TestI::knownPreservedAsKnownPreserved(const ::Ice::Current&) +{ + KnownPreservedDerived ex; + ex.b = "base"; + ex.kp = "preserved"; + ex.kpd = "derived"; + throw ex; +} + +void TestI::relayKnownPreservedAsBase(const RelayPrx& r, const ::Ice::Current&) { r->knownPreservedAsBase(); @@ -165,6 +185,30 @@ TestI::relayKnownPreservedAsKnownPreserved(const RelayPrx& r, const ::Ice::Curre } void +TestI::unknownPreservedAsBase(const ::Ice::Current&) +{ + SPreserved2 ex; + ex.b = "base"; + ex.kp = "preserved"; + ex.kpd = "derived"; + ex.p1 = new SPreservedClass("bc", "spc"); + ex.p2 = ex.p1; + throw ex; +} + +void +TestI::unknownPreservedAsKnownPreserved(const ::Ice::Current&) +{ + SPreserved2 ex; + ex.b = "base"; + ex.kp = "preserved"; + ex.kpd = "derived"; + ex.p1 = new SPreservedClass("bc", "spc"); + ex.p2 = ex.p1; + throw ex; +} + +void TestI::relayUnknownPreservedAsBase(const RelayPrx& r, const ::Ice::Current&) { r->unknownPreservedAsBase(); diff --git a/cpp/test/Ice/slicing/exceptions/TestI.h b/cpp/test/Ice/slicing/exceptions/TestI.h index b9ae73b51ae..7514794ef0a 100644 --- a/cpp/test/Ice/slicing/exceptions/TestI.h +++ b/cpp/test/Ice/slicing/exceptions/TestI.h @@ -35,9 +35,15 @@ public: virtual void unknownMostDerived2AsBaseCompact(const ::Ice::Current&); + virtual void knownPreservedAsBase(const ::Ice::Current&); + virtual void knownPreservedAsKnownPreserved(const ::Ice::Current&); + virtual void relayKnownPreservedAsBase(const ::Test::RelayPrx&, const ::Ice::Current&); virtual void relayKnownPreservedAsKnownPreserved(const ::Test::RelayPrx&, const ::Ice::Current&); + virtual void unknownPreservedAsBase(const ::Ice::Current&); + virtual void unknownPreservedAsKnownPreserved(const ::Ice::Current&); + virtual void relayUnknownPreservedAsBase(const ::Test::RelayPrx&, const ::Ice::Current&); virtual void relayUnknownPreservedAsKnownPreserved(const ::Test::RelayPrx&, const ::Ice::Current&); diff --git a/py/modules/IcePy/Init.cpp b/py/modules/IcePy/Init.cpp index afcd7e59019..77b463f44ad 100644 --- a/py/modules/IcePy/Init.cpp +++ b/py/modules/IcePy/Init.cpp @@ -45,11 +45,11 @@ static PyMethodDef methods[] = { STRCAST("stringToProtocolVersion"), reinterpret_cast<PyCFunction>(IcePy_stringToProtocolVersion), METH_VARARGS, PyDoc_STR(STRCAST("stringToProtocolVersion(str) -> Ice.ProtocolVersion")) }, { STRCAST("protocolVersionToString"), reinterpret_cast<PyCFunction>(IcePy_protocolVersionToString), METH_VARARGS, - PyDoc_STR(STRCAST("stringToProtocolVersion(Ice.ProtocolVersion) -> string")) }, + PyDoc_STR(STRCAST("protocolVersionToString(Ice.ProtocolVersion) -> string")) }, { STRCAST("stringToEncodingVersion"), reinterpret_cast<PyCFunction>(IcePy_stringToEncodingVersion), METH_VARARGS, PyDoc_STR(STRCAST("stringToEncodingVersion(str) -> Ice.EncodingVersion")) }, { STRCAST("encodingVersionToString"), reinterpret_cast<PyCFunction>(IcePy_encodingVersionToString), METH_VARARGS, - PyDoc_STR(STRCAST("stringToEncodingVersion(Ice.EncodingVersion) -> string")) }, + PyDoc_STR(STRCAST("encodingVersionToString(Ice.EncodingVersion) -> string")) }, { STRCAST("generateUUID"), reinterpret_cast<PyCFunction>(IcePy_generateUUID), METH_NOARGS, PyDoc_STR(STRCAST("generateUUID() -> string")) }, { STRCAST("createProperties"), reinterpret_cast<PyCFunction>(IcePy_createProperties), METH_VARARGS, diff --git a/py/modules/IcePy/Proxy.cpp b/py/modules/IcePy/Proxy.cpp index da53698dbc7..f71f8069717 100644 --- a/py/modules/IcePy/Proxy.cpp +++ b/py/modules/IcePy/Proxy.cpp @@ -1021,9 +1021,6 @@ extern "C" static PyObject* proxyIceGetEncodingVersion(ProxyObject* self) { - PyObject* cls = lookupType("Ice.EncodingVersion"); - assert(cls); - assert(self->proxy); PyObject* version; diff --git a/py/modules/IcePy/Types.cpp b/py/modules/IcePy/Types.cpp index fbcd0bf8e84..97dbf7f989f 100644 --- a/py/modules/IcePy/Types.cpp +++ b/py/modules/IcePy/Types.cpp @@ -2749,7 +2749,6 @@ IcePy::ExceptionInfo::unmarshal(const Ice::InputStreamPtr& is) while(info) { is->startSlice(); - for(DataMemberList::iterator q = info->members.begin(); q != info->members.end(); ++q) { DataMemberPtr member = *q; diff --git a/py/modules/IcePy/Util.cpp b/py/modules/IcePy/Util.cpp index 837ed1e3b71..1aae7f471a6 100644 --- a/py/modules/IcePy/Util.cpp +++ b/py/modules/IcePy/Util.cpp @@ -1084,15 +1084,14 @@ IcePy::createEncodingVersion(const Ice::EncodingVersion& v) bool IcePy::getEncodingVersion(PyObject* args, Ice::EncodingVersion& v) { - PyObject* versionType = IcePy::lookupType(IcePy::Ice_EncodingVersion); + PyObject* versionType = IcePy::lookupType(Ice_EncodingVersion); PyObject* p; if(!PyArg_ParseTuple(args, STRCAST("O!"), versionType, &p)) { return false; } - - if(!getVersion<Ice::EncodingVersion, IcePy::Ice_EncodingVersion>(p, v)) + if(!getVersion<Ice::EncodingVersion, Ice_EncodingVersion>(p, v)) { return false; } @@ -1100,7 +1099,6 @@ IcePy::getEncodingVersion(PyObject* args, Ice::EncodingVersion& v) return true; } - extern "C" PyObject* IcePy_stringVersion(PyObject* /*self*/) @@ -1137,25 +1135,29 @@ IcePy_currentEncoding(PyObject* /*self*/) return IcePy::createEncodingVersion(Ice::currentEncoding); } -extern "C" PyObject* +extern "C" +PyObject* IcePy_protocolVersionToString(PyObject* /*self*/, PyObject* args) { return IcePy::versionToString<Ice::ProtocolVersion, IcePy::Ice_ProtocolVersion>(args); } -extern "C" PyObject* +extern "C" +PyObject* IcePy_stringToProtocolVersion(PyObject* /*self*/, PyObject* args) { return IcePy::stringToVersion<Ice::ProtocolVersion, IcePy::Ice_ProtocolVersion>(args); } -extern "C" PyObject* +extern "C" +PyObject* IcePy_encodingVersionToString(PyObject* /*self*/, PyObject* args) { return IcePy::versionToString<Ice::EncodingVersion, IcePy::Ice_EncodingVersion>(args); } -extern "C" PyObject* +extern "C" +PyObject* IcePy_stringToEncodingVersion(PyObject* /*self*/, PyObject* args) { return IcePy::stringToVersion<Ice::EncodingVersion, IcePy::Ice_EncodingVersion>(args); diff --git a/py/modules/IcePy/Util.h b/py/modules/IcePy/Util.h index fdbef73b5c8..372343ba11e 100644 --- a/py/modules/IcePy/Util.h +++ b/py/modules/IcePy/Util.h @@ -244,7 +244,7 @@ PyObject* createProtocolVersion(const Ice::ProtocolVersion&); PyObject* createEncodingVersion(const Ice::EncodingVersion&); // -// Extracts the members of an encoding version +// Extracts the members of an encoding version. // bool getEncodingVersion(PyObject*, Ice::EncodingVersion&); diff --git a/py/test/Ice/proxy/AllTests.py b/py/test/Ice/proxy/AllTests.py index da1db1f2324..6cb4507bf6c 100644 --- a/py/test/Ice/proxy/AllTests.py +++ b/py/test/Ice/proxy/AllTests.py @@ -293,14 +293,14 @@ def allTests(communicator, collocated): prop.setProperty(property, "6.5") try: communicator.propertyToProxy(propertyPrefix) - test(false) + test(False) except Ice.UnsupportedEncodingException: pass prop.setProperty(property, "1.2") - try : + try: communicator.propertyToProxy(propertyPrefix) - test(false) + test(False) except Ice.UnsupportedEncodingException: pass prop.setProperty(property, "") @@ -311,7 +311,7 @@ def allTests(communicator, collocated): sys.stdout.flush() b1 = communicator.stringToProxy("test") - #b1 = b1.ice_collocationOptimized(true) + #b1 = b1.ice_collocationOptimized(True) b1 = b1.ice_connectionCached(True) b1 = b1.ice_preferSecure(False) b1 = b1.ice_endpointSelection(Ice.EndpointSelectionType.Ordered) @@ -319,14 +319,14 @@ def allTests(communicator, collocated): b1 = b1.ice_encodingVersion(Ice.EncodingVersion(1, 0)) router = communicator.stringToProxy("router") - #router = router.ice_collocationOptimized(false) + #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) locator = communicator.stringToProxy("locator") - #locator = locator.ice_collocationOptimized(true) + #locator = locator.ice_collocationOptimized(True) locator = locator.ice_connectionCached(False) locator = locator.ice_preferSecure(True) locator = locator.ice_endpointSelection(Ice.EndpointSelectionType.Random) @@ -340,7 +340,7 @@ def allTests(communicator, collocated): test(proxyProps["Test"] == "test -t") #test(proxyProps["Test.CollocationOptimized"] == "1") - test(proxyProps["Test.EncodingVersion"] == "1.0"); + test(proxyProps["Test.EncodingVersion"] == "1.0") test(proxyProps["Test.ConnectionCached"] == "1") test(proxyProps["Test.PreferSecure"] == "0") test(proxyProps["Test.EndpointSelection"] == "Ordered") @@ -348,14 +348,14 @@ def allTests(communicator, collocated): test(proxyProps["Test.Locator"] == "locator -t") #test(proxyProps["Test.Locator.CollocationOptimized"] == "1") - test(proxyProps["Test.Locator.EncodingVersion"] == Ice.encodingVersionToString(Ice.currentEncoding())); + test(proxyProps["Test.Locator.EncodingVersion"] == Ice.encodingVersionToString(Ice.currentEncoding())) 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.Router"] == "router -t") - test(proxyProps["Test.Locator.Router.EncodingVersion"] == Ice.encodingVersionToString(Ice.currentEncoding())); + test(proxyProps["Test.Locator.Router.EncodingVersion"] == 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") @@ -363,8 +363,8 @@ def allTests(communicator, collocated): test(proxyProps["Test.Locator.Router.LocatorCacheTimeout"] == "200") try: - b1.ice_encodingVersion(Ice.EncodingVersion(3, 4)); - test(false); + b1.ice_encodingVersion(Ice.EncodingVersion(3, 4)) + test(False) except Ice.UnsupportedEncodingException: pass @@ -390,13 +390,13 @@ def allTests(communicator, collocated): test(base.ice_batchDatagram().ice_isBatchDatagram()) test(base.ice_secure(True).ice_isSecure()) test(not base.ice_secure(False).ice_isSecure()) - #test(base.ice_collocationOptimized(true)->ice_isCollocationOptimized()) - #test(!base.ice_collocationOptimized(false)->ice_isCollocationOptimized()) + #test(base.ice_collocationOptimized(True)->ice_isCollocationOptimized()) + #test(!base.ice_collocationOptimized(False)->ice_isCollocationOptimized()) test(base.ice_preferSecure(True).ice_isPreferSecure()) test(not 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); + 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) print("ok") sys.stdout.write("testing proxy comparison... ") @@ -471,7 +471,7 @@ def allTests(communicator, collocated): test(not (compObj.ice_locator(loc1) < compObj.ice_locator(None))) test(compObj.ice_locator(loc1) < compObj.ice_locator(loc2)) test(not (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(None) == compObj.ice_router(None)) @@ -495,12 +495,12 @@ def allTests(communicator, collocated): test(compObj.ice_context(ctx1) != compObj.ice_context(ctx2)) test(compObj.ice_context(ctx1) < compObj.ice_context(ctx2)) test(not (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(not (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) @@ -531,10 +531,10 @@ def allTests(communicator, collocated): test(not (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(not (compObj.ice_encodingVersion(Ice.Encoding_1_1) < compObj.ice_encodingVersion(Ice.Encoding_1_0))); + 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(not (compObj.ice_encodingVersion(Ice.Encoding_1_1) < compObj.ice_encodingVersion(Ice.Encoding_1_0))) # # TODO: Ideally we should also test comparison of fixed proxies. @@ -666,15 +666,15 @@ def allTests(communicator, collocated): p1 = communicator.stringToProxy("test:opaque -t 1 -e 1.0 -v CTEyNy4wLjAuMeouAAAQJwAAAA==") pstr = communicator.proxyToString(p1) test(pstr == "test -t:tcp -h 127.0.0.1 -p 12010 -t 10000") - + # 1.1 TCP endpoint encoded with 1.1 encoding. - p2 = communicator.stringToProxy("test:opaque -e 1.1 -t 1 -v CTEyNy4wLjAuMeouAAAQJwAAAAEAAQE="); - test(communicator.proxyToString(p2) == "test -t:tcp -e 1.1 -h 127.0.0.1 -p 12010 -t 10000"); - + p2 = communicator.stringToProxy("test:opaque -e 1.1 -t 1 -v CTEyNy4wLjAuMeouAAAQJwAAAAEAAQE=") + test(communicator.proxyToString(p2) == "test -t:tcp -e 1.1 -h 127.0.0.1 -p 12010 -t 10000") + # 1.0 TCP endpoint encoded with 1.1 encoding. - p2 = communicator.stringToProxy("test: opaque -t 1 -e 1.1 -v CTEyNy4wLjAuMeouAAAQJwAAAAEAAQA="); - test(communicator.proxyToString(p2) == "test -t:tcp -h 127.0.0.1 -p 12010 -t 10000"); - + p2 = communicator.stringToProxy("test: opaque -t 1 -e 1.1 -v CTEyNy4wLjAuMeouAAAQJwAAAAEAAQA=") + test(communicator.proxyToString(p2) == "test -t:tcp -h 127.0.0.1 -p 12010 -t 10000") + if communicator.getProperties().getPropertyAsInt("Ice.IPv6") == 0: # Working? ssl = communicator.getProperties().getProperty("Ice.Default.Protocol") == "ssl" diff --git a/py/test/Ice/slicing/exceptions/AllTests.py b/py/test/Ice/slicing/exceptions/AllTests.py index 079212fe755..aa77f42e009 100644 --- a/py/test/Ice/slicing/exceptions/AllTests.py +++ b/py/test/Ice/slicing/exceptions/AllTests.py @@ -185,21 +185,24 @@ class Callback(CallbackBase): class RelayI(Test.Relay): def knownPreservedAsBase(self, current=None): - ex = Test.KnownPreserved() + ex = Test.KnownPreservedDerived() ex.b = "base" ex.kp = "preserved" + ex.kpd = "derived" raise ex def knownPreservedAsKnownPreserved(self, current=None): - ex = Test.KnownPreserved() + ex = Test.KnownPreservedDerived() ex.b = "base" ex.kp = "preserved" + ex.kpd = "derived" raise ex def unknownPreservedAsBase(self, current=None): ex = Test.Preserved2() ex.b = "base" ex.kp = "preserved" + ex.kpd = "derived" ex.p1 = Test.PreservedClass("bc", "pc") ex.p2 = ex.p1 raise ex @@ -208,6 +211,7 @@ class RelayI(Test.Relay): ex = Test.Preserved2() ex.b = "base" ex.kp = "preserved" + ex.kpd = "derived" ex.p1 = Test.PreservedClass("bc", "pc") ex.p2 = ex.p1 raise ex @@ -504,18 +508,20 @@ def allTests(communicator): try: t.relayKnownPreservedAsBase(relay) test(False) - except Test.KnownPreserved as ex: + except Test.KnownPreservedDerived as ex: test(ex.b == "base") test(ex.kp == "preserved") + test(ex.kpd == "derived") except: test(False) try: t.relayKnownPreservedAsKnownPreserved(relay) test(False) - except Test.KnownPreserved as ex: + except Test.KnownPreservedDerived as ex: test(ex.b == "base") test(ex.kp == "preserved") + test(ex.kpd == "derived") except: test(False) @@ -525,19 +531,21 @@ def allTests(communicator): except Test.Preserved2 as ex: test(ex.b == "base") test(ex.kp == "preserved") + test(ex.kpd == "derived") test(ex.p1.ice_id() == Test.PreservedClass.ice_staticId()) pc = ex.p1 test(isinstance(pc, Test.PreservedClass)) test(pc.bc == "bc") test(pc.pc == "pc") test(ex.p2 == ex.p1) - except Test.KnownPreserved as ex: + except Test.KnownPreservedDerived as ex: # # For the 1.0 encoding, the unknown exception is sliced to KnownPreserved. # test(t.ice_getEncodingVersion() == Ice.Encoding_1_0) test(ex.b == "base") test(ex.kp == "preserved") + test(ex.kpd == "derived") except: test(False) @@ -547,19 +555,21 @@ def allTests(communicator): except Test.Preserved2 as ex: test(ex.b == "base") test(ex.kp == "preserved") + test(ex.kpd == "derived") test(ex.p1.ice_id() == Test.PreservedClass.ice_staticId()) pc = ex.p1 test(isinstance(pc, Test.PreservedClass)) test(pc.bc == "bc") test(pc.pc == "pc") test(ex.p2 == ex.p1) - except Test.KnownPreserved as ex: + except Test.KnownPreservedDerived as ex: # # For the 1.0 encoding, the unknown exception is sliced to KnownPreserved. # test(t.ice_getEncodingVersion() == Ice.Encoding_1_0) test(ex.b == "base") test(ex.kp == "preserved") + test(ex.kpd == "derived") except: test(False) diff --git a/py/test/Ice/slicing/exceptions/ClientPrivate.ice b/py/test/Ice/slicing/exceptions/ClientPrivate.ice index 9b2e381798a..029e6d5d37e 100644 --- a/py/test/Ice/slicing/exceptions/ClientPrivate.ice +++ b/py/test/Ice/slicing/exceptions/ClientPrivate.ice @@ -19,7 +19,7 @@ class PreservedClass extends BaseClass string pc; }; -exception Preserved1 extends KnownPreserved +exception Preserved1 extends KnownPreservedDerived { BaseClass p1; }; diff --git a/py/test/Ice/slicing/exceptions/Server.py b/py/test/Ice/slicing/exceptions/Server.py index eb0c585a9b6..a880f12b335 100755 --- a/py/test/Ice/slicing/exceptions/Server.py +++ b/py/test/Ice/slicing/exceptions/Server.py @@ -107,12 +107,44 @@ class TestI(Test.TestIntf): umd2.umd2 = "UnknownMostDerived2.umd2" raise umd2 + def knownPreservedAsBase(self, current=None): + ex = Test.KnownPreservedDerived() + ex.b = "base" + ex.kp = "preserved" + ex.kpd = "derived" + raise ex + + def knownPreservedAsKnownPreserved(self, current=None): + ex = Test.KnownPreservedDerived() + ex.b = "base" + ex.kp = "preserved" + ex.kpd = "derived" + raise ex + def relayKnownPreservedAsBase(self, r, current=None): r.knownPreservedAsBase() def relayKnownPreservedAsKnownPreserved(self, r, current=None): r.knownPreservedAsKnownPreserved() + def unknownPreservedAsBase(self, current=None): + ex = Test.SPreserved2() + ex.b = "base" + ex.kp = "preserved" + ex.kpd = "derived" + ex.p1 = Test.SPreservedClass("bc", "spc") + ex.p2 = ex.p1 + raise ex + + def unknownPreservedAsKnownPreserved(self, current=None): + ex = Test.SPreserved2() + ex.b = "base" + ex.kp = "preserved" + ex.kpd = "derived" + ex.p1 = Test.SPreservedClass("bc", "spc") + ex.p2 = ex.p1 + raise ex + def relayUnknownPreservedAsBase(self, r, current=None): r.unknownPreservedAsBase() diff --git a/py/test/Ice/slicing/exceptions/ServerAMD.py b/py/test/Ice/slicing/exceptions/ServerAMD.py index 426550025dd..7bc152bbd90 100755 --- a/py/test/Ice/slicing/exceptions/ServerAMD.py +++ b/py/test/Ice/slicing/exceptions/ServerAMD.py @@ -109,6 +109,20 @@ class TestI(Test.TestIntf): umd2.umd2 = "UnknownMostDerived2.umd2" cb.ice_exception(umd2) + def knownPreservedAsBase_async(self, cb, r, current=None): + ex = Test.KnownPreservedDerived() + ex.b = "base" + ex.kp = "preserved" + ex.kpd = "derived" + cb.ice_exception(ex) + + def knownPreservedAsKnownPreserved_async(self, cb, r, current=None): + ex = Test.KnownPreservedDerived() + ex.b = "base" + ex.kp = "preserved" + ex.kpd = "derived" + cb.ice_exception(ex) + def relayKnownPreservedAsBase_async(self, cb, r, current=None): try: r.knownPreservedAsBase() @@ -123,6 +137,24 @@ class TestI(Test.TestIntf): except Ice.Exception as ex: cb.ice_exception(ex) + def unknownPreservedAsBase_async(self, cb, r, current=None): + ex = Test.SPreserved2() + ex.b = "base" + ex.kp = "preserved" + ex.kpd = "derived" + ex.p1 = Test.SPreservedClass("bc", "spc") + ex.p2 = ex.p1 + cb.ice_exception(ex) + + def unknownPreservedAsKnownPreserved_async(self, cb, r, current=None): + ex = Test.SPreserved2() + ex.b = "base" + ex.kp = "preserved" + ex.kpd = "derived" + ex.p1 = Test.SPreservedClass("bc", "spc") + ex.p2 = ex.p1 + cb.ice_exception(ex) + def relayUnknownPreservedAsBase_async(self, cb, r, current=None): try: r.unknownPreservedAsBase() diff --git a/py/test/Ice/slicing/exceptions/ServerPrivate.ice b/py/test/Ice/slicing/exceptions/ServerPrivate.ice index df89aa2efea..e03994a4641 100644 --- a/py/test/Ice/slicing/exceptions/ServerPrivate.ice +++ b/py/test/Ice/slicing/exceptions/ServerPrivate.ice @@ -34,4 +34,19 @@ exception UnknownMostDerived2 extends UnknownIntermediate string umd2; }; +class SPreservedClass extends BaseClass +{ + string spc; +}; + +exception SPreserved1 extends KnownPreservedDerived +{ + BaseClass p1; +}; + +exception SPreserved2 extends SPreserved1 +{ + BaseClass p2; +}; + }; diff --git a/py/test/Ice/slicing/exceptions/Test.ice b/py/test/Ice/slicing/exceptions/Test.ice index be67cb391e6..e558935d440 100644 --- a/py/test/Ice/slicing/exceptions/Test.ice +++ b/py/test/Ice/slicing/exceptions/Test.ice @@ -38,6 +38,11 @@ exception KnownPreserved extends Base string kp; }; +exception KnownPreservedDerived extends KnownPreserved +{ + string kpd; +}; + ["preserve-slice"] class BaseClass { @@ -75,9 +80,15 @@ interface TestIntf ["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; diff --git a/py/test/Ice/slicing/exceptions/TestAMD.ice b/py/test/Ice/slicing/exceptions/TestAMD.ice index fbf94f29a56..259a297fd63 100644 --- a/py/test/Ice/slicing/exceptions/TestAMD.ice +++ b/py/test/Ice/slicing/exceptions/TestAMD.ice @@ -38,6 +38,11 @@ exception KnownPreserved extends Base string kp; }; +exception KnownPreservedDerived extends KnownPreserved +{ + string kpd; +}; + ["preserve-slice"] class BaseClass { @@ -75,9 +80,15 @@ interface TestIntf ["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; diff --git a/py/test/Ice/slicing/objects/AllTests.py b/py/test/Ice/slicing/objects/AllTests.py index f13cd7c6d8f..0ae2726c152 100644 --- a/py/test/Ice/slicing/objects/AllTests.py +++ b/py/test/Ice/slicing/objects/AllTests.py @@ -1482,7 +1482,7 @@ def allTests(communicator): # The object will be sliced to Preserved for the 1.0 encoding. # pcd = Test.PCDerived3() - pcd.pi = 3; + pcd.pi = 3 # # Sending more than 254 objects exercises the encoding for object ids. # @@ -1572,7 +1572,7 @@ def allTests(communicator): # The object will be sliced to Preserved for the 1.0 encoding. # pcd = Test.PCDerived3() - pcd.pi = 3; + pcd.pi = 3 # # Sending more than 254 objects exercises the encoding for object ids. # diff --git a/rb/ruby/Ice.rb b/rb/ruby/Ice.rb index 4815342b2ef..dc178d26a4e 100644 --- a/rb/ruby/Ice.rb +++ b/rb/ruby/Ice.rb @@ -88,6 +88,8 @@ module Ice def ice_ping(current=nil) end + + attr_accessor :_ice_slicedData # Only used for instances of preserved classes. end class Object @@ -98,7 +100,7 @@ module Ice end end - T_Object.defineClass(nil, true, nil, [], []) + T_Object.defineClass(nil, true, false, nil, [], []) Object_mixin::ICE_TYPE = T_Object T_ObjectPrx.defineProxy(ObjectPrx, T_Object) @@ -108,7 +110,7 @@ module Ice # LocalObject. # T_LocalObject = Ice.__declareLocalClass('::Ice::LocalObject') - T_LocalObject.defineClass(nil, true, nil, [], []) + T_LocalObject.defineClass(nil, true, false, nil, [], []) # # InitializationData. @@ -123,6 +125,68 @@ module Ice end # + # SlicedData + # + class SlicedData + attr_accessor :slices # array of SliceInfo + end + + # + # SliceInfo + # + class SliceInfo + attr_accessor :typeId, :bytes, :objects + end + + class FormatType + include Comparable + + def initialize(val) + fail("invalid value #{val} for FormatType") unless(val >= 0 and val < 3) + @val = val + end + + def FormatType.from_int(val) + raise IndexError, "#{val} is out of range 0..2" if(val < 0 || val > 2) + @@_values[val] + end + + def to_s + @@_names[@val] + end + + def to_i + @val + end + + def <=>(other) + other.is_a?(FormatType) or raise ArgumentError, "value must be a FormatType" + @val <=> other.to_i + end + + def hash + @val.hash + end + + def inspect + @@_names[@val] + "(#{@val})" + end + + def FormatType.each(&block) + @@_values.each(&block) + end + + @@_names = ['DefaultFormat', 'CompactFormat', 'SlicedFormat'] + @@_values = [FormatType.new(0), FormatType.new(1), FormatType.new(2)] + + DefaultFormat = @@_values[0] + CompactFormat = @@_values[1] + SlicedFormat = @@_values[2] + + private_class_method :new + end + + # # Slice checksum dictionary. # SliceChecksums = {} @@ -141,6 +205,7 @@ require 'Ice/ObjectFactory.rb' require 'Ice/Process.rb' require 'Ice/Router.rb' require 'Ice/Endpoint.rb' +require 'Ice/Version.rb' module Ice # @@ -568,9 +633,13 @@ module Ice def Ice.proxyIdentityAndFacetEqual(lhs, rhs) return proxyIdentityAndFacetCompare(lhs, rhs) == 0 end + + Protocol_1_0 = ProtocolVersion.new(1, 0) + Encoding_1_0 = EncodingVersion.new(1, 0) + Encoding_1_1 = EncodingVersion.new(1, 1) end -Ice::Object_mixin::OP_ice_isA = ::Ice::__defineOperation('ice_isA', ::Ice::OperationMode::Idempotent, ::Ice::OperationMode::Nonmutating, false, [::Ice::T_string], [], ::Ice::T_bool, []) -Ice::Object_mixin::OP_ice_ping = ::Ice::__defineOperation('ice_ping', ::Ice::OperationMode::Idempotent, ::Ice::OperationMode::Nonmutating, false, [], [], nil, []) -Ice::Object_mixin::OP_ice_ids = ::Ice::__defineOperation('ice_ids', ::Ice::OperationMode::Idempotent, ::Ice::OperationMode::Nonmutating, false, [], [], ::Ice::T_StringSeq, []) -Ice::Object_mixin::OP_ice_id = ::Ice::__defineOperation('ice_id', ::Ice::OperationMode::Idempotent, ::Ice::OperationMode::Nonmutating, false, [], [], ::Ice::T_string, []) +Ice::Object_mixin::OP_ice_isA = ::Ice::__defineOperation('ice_isA', ::Ice::OperationMode::Idempotent, ::Ice::OperationMode::Nonmutating, false, nil, [::Ice::T_string], [], ::Ice::T_bool, []) +Ice::Object_mixin::OP_ice_ping = ::Ice::__defineOperation('ice_ping', ::Ice::OperationMode::Idempotent, ::Ice::OperationMode::Nonmutating, false, nil, [], [], nil, []) +Ice::Object_mixin::OP_ice_ids = ::Ice::__defineOperation('ice_ids', ::Ice::OperationMode::Idempotent, ::Ice::OperationMode::Nonmutating, false, nil, [], [], ::Ice::T_StringSeq, []) +Ice::Object_mixin::OP_ice_id = ::Ice::__defineOperation('ice_id', ::Ice::OperationMode::Idempotent, ::Ice::OperationMode::Nonmutating, false, nil, [], [], ::Ice::T_string, []) diff --git a/rb/ruby/Makefile b/rb/ruby/Makefile index db8aae49e2c..587cab68f03 100644 --- a/rb/ruby/Makefile +++ b/rb/ruby/Makefile @@ -45,7 +45,8 @@ ICE_SRCS = Ice/LocalException.rb \ Ice/SliceChecksumDict.rb \ Ice/Endpoint.rb \ Ice/EndpointF.rb \ - Ice/EndpointTypes.rb + Ice/EndpointTypes.rb \ + Ice/Version.rb # # IMPORTANT: If you add or remove Slice files, you also need to check Glacier2.rb! diff --git a/rb/ruby/Makefile.mak b/rb/ruby/Makefile.mak index 0ba68796c66..0471bce8b8a 100644 --- a/rb/ruby/Makefile.mak +++ b/rb/ruby/Makefile.mak @@ -45,7 +45,8 @@ ICE_SRCS = Ice\LocalException.rb \ Ice\SliceChecksumDict.rb \
Ice\Endpoint.rb \
Ice\EndpointF.rb \
- Ice\EndpointTypes.rb
+ Ice\EndpointTypes.rb \
+ Ice\Version.rb
#
# IMPORTANT: If you add or remove Slice files, you also need to check Glacier2.rb!
diff --git a/rb/src/IceRuby/Endpoint.cpp b/rb/src/IceRuby/Endpoint.cpp index 31dc8f473cb..c5ea7cb5ba3 100644 --- a/rb/src/IceRuby/Endpoint.cpp +++ b/rb/src/IceRuby/Endpoint.cpp @@ -143,10 +143,6 @@ IceRuby::createEndpointInfo(const Ice::EndpointInfoPtr& p) Ice::UDPEndpointInfoPtr udp = Ice::UDPEndpointInfoPtr::dynamicCast(p); rb_ivar_set(info, rb_intern("@host"), createString(udp->host)); rb_ivar_set(info, rb_intern("@port"), INT2FIX(udp->port)); - rb_ivar_set(info, rb_intern("@protocolMajor"), CHR2FIX(udp->protocolMajor)); - rb_ivar_set(info, rb_intern("@protocolMinor"), CHR2FIX(udp->protocolMinor)); - rb_ivar_set(info, rb_intern("@encodingMajor"), CHR2FIX(udp->encodingMajor)); - rb_ivar_set(info, rb_intern("@encodingMinor"), CHR2FIX(udp->encodingMinor)); rb_ivar_set(info, rb_intern("@mcastInterface"), createString(udp->mcastInterface)); rb_ivar_set(info, rb_intern("@mcastTtl"), INT2FIX(udp->mcastTtl)); } @@ -158,6 +154,7 @@ IceRuby::createEndpointInfo(const Ice::EndpointInfoPtr& p) Ice::ByteSeq b = opaque->rawBytes; VALUE v = callRuby(rb_str_new, reinterpret_cast<const char*>(&b[0]), static_cast<long>(b.size())); rb_ivar_set(info, rb_intern("@rawBytes"), v); + rb_ivar_set(info, rb_intern("@rawEncoding"), createEncodingVersion(opaque->rawEncoding)); } else if(Ice::IPEndpointInfoPtr::dynamicCast(p)) { @@ -171,6 +168,8 @@ IceRuby::createEndpointInfo(const Ice::EndpointInfoPtr& p) { info = Data_Wrap_Struct(_endpointInfoClass, 0, IceRuby_EndpointInfo_free, new Ice::EndpointInfoPtr(p)); } + rb_ivar_set(info, rb_intern("@protocol"), createProtocolVersion(p->protocol)); + rb_ivar_set(info, rb_intern("@encoding"), createEncodingVersion(p->encoding)); rb_ivar_set(info, rb_intern("@timeout"), INT2FIX(p->timeout)); rb_ivar_set(info, rb_intern("@compress"), p->compress ? Qtrue : Qfalse); return info; @@ -256,10 +255,12 @@ IceRuby::initEndpoint(VALUE iceModule) rb_define_method(_endpointInfoClass, "secure", CAST_METHOD(IceRuby_EndpointInfo_secure), 0); // - // Instance members. + // Instance members. // - rb_define_attr(_endpointInfoClass, "timeout", 1, 0); - rb_define_attr(_endpointInfoClass, "compress", 1, 0); + rb_define_attr(_endpointInfoClass, "protocol", 1, 0); + rb_define_attr(_endpointInfoClass, "encoding", 1, 0); + rb_define_attr(_endpointInfoClass, "timeout", 1, 0); + rb_define_attr(_endpointInfoClass, "compress", 1, 0); // // IPEndpointInfo @@ -267,10 +268,10 @@ IceRuby::initEndpoint(VALUE iceModule) _ipEndpointInfoClass = rb_define_class_under(iceModule, "IPEndpointInfo", _endpointInfoClass); // - // Instance members. + // Instance members. // - rb_define_attr(_ipEndpointInfoClass, "host", 1, 0); - rb_define_attr(_ipEndpointInfoClass, "port", 1, 0); + rb_define_attr(_ipEndpointInfoClass, "host", 1, 0); + rb_define_attr(_ipEndpointInfoClass, "port", 1, 0); // // TCPEndpointInfo @@ -283,14 +284,10 @@ IceRuby::initEndpoint(VALUE iceModule) _udpEndpointInfoClass = rb_define_class_under(iceModule, "UDPEndpointInfo", _ipEndpointInfoClass); // - // Instance members. + // Instance members. // - rb_define_attr(_udpEndpointInfoClass, "protocolMajor", 1, 0); - rb_define_attr(_udpEndpointInfoClass, "protocolMinor", 1, 0); - rb_define_attr(_udpEndpointInfoClass, "encodingMajor", 1, 0); - rb_define_attr(_udpEndpointInfoClass, "encodingMinor", 1, 0); - rb_define_attr(_udpEndpointInfoClass, "mcastInterface", 1, 0); - rb_define_attr(_udpEndpointInfoClass, "mcastTtl", 1, 0); + rb_define_attr(_udpEndpointInfoClass, "mcastInterface", 1, 0); + rb_define_attr(_udpEndpointInfoClass, "mcastTtl", 1, 0); // // OpaqueEndpointInfo @@ -298,9 +295,10 @@ IceRuby::initEndpoint(VALUE iceModule) _opaqueEndpointInfoClass = rb_define_class_under(iceModule, "OpaqueEndpointInfo", _endpointInfoClass); // - // Instance members. + // Instance members. // - rb_define_attr(_opaqueEndpointInfoClass, "rawBytes", 1, 0); + rb_define_attr(_opaqueEndpointInfoClass, "rawBytes", 1, 0); + rb_define_attr(_opaqueEndpointInfoClass, "rawEncoding", 1, 0); } bool @@ -308,4 +306,3 @@ IceRuby::checkEndpoint(VALUE v) { return callRuby(rb_obj_is_kind_of, v, _endpointClass) == Qtrue; } - diff --git a/rb/src/IceRuby/Operation.cpp b/rb/src/IceRuby/Operation.cpp index bdee38a11b7..a8743a3145e 100644 --- a/rb/src/IceRuby/Operation.cpp +++ b/rb/src/IceRuby/Operation.cpp @@ -43,7 +43,7 @@ class OperationI : public Operation { public: - OperationI(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE); + OperationI(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE); virtual VALUE invoke(const Ice::ObjectPrx&, VALUE, VALUE); virtual void deprecate(const string&); @@ -54,6 +54,7 @@ private: Ice::OperationMode _mode; Ice::OperationMode _sendMode; bool _amd; + Ice::FormatType _format; ParamInfoList _inParams; ParamInfoList _outParams; ParamInfoPtr _returnType; @@ -63,7 +64,7 @@ private: bool _returnsClasses; string _deprecateMessage; - void prepareRequest(const Ice::CommunicatorPtr&, VALUE, bool, vector<Ice::Byte>&); + void prepareRequest(const Ice::ObjectPrx&, VALUE, bool, vector<Ice::Byte>&); VALUE unmarshalResults(const vector<Ice::Byte>&, const Ice::CommunicatorPtr&); VALUE unmarshalException(const vector<Ice::Byte>&, const Ice::CommunicatorPtr&); bool validateException(VALUE) const; @@ -71,6 +72,29 @@ private: }; typedef IceUtil::Handle<OperationI> OperationIPtr; +class UserExceptionReaderFactoryI : public Ice::UserExceptionReaderFactory +{ +public: + + UserExceptionReaderFactoryI(const Ice::CommunicatorPtr& communicator) : + _communicator(communicator) + { + } + + virtual void createAndThrow(const string& id) const + { + ExceptionInfoPtr info = lookupExceptionInfo(id); + if(info) + { + throw ExceptionReader(_communicator, info); + } + } + +private: + + const Ice::CommunicatorPtr _communicator; +}; + } extern "C" @@ -82,12 +106,13 @@ IceRuby_Operation_free(OperationPtr* p) extern "C" VALUE -IceRuby_defineOperation(VALUE /*self*/, VALUE name, VALUE mode, VALUE sendMode, VALUE amd, VALUE inParams, +IceRuby_defineOperation(VALUE /*self*/, VALUE name, VALUE mode, VALUE sendMode, VALUE amd, VALUE format, VALUE inParams, VALUE outParams, VALUE returnType, VALUE exceptions) { ICE_RUBY_TRY { - OperationIPtr op = new OperationI(name, mode, sendMode, amd, inParams, outParams, returnType, exceptions); + OperationIPtr op = new OperationI(name, mode, sendMode, amd, format, inParams, outParams, returnType, + exceptions); return Data_Wrap_Struct(_operationClass, 0, IceRuby_Operation_free, new OperationPtr(op)); } ICE_RUBY_CATCH @@ -145,8 +170,8 @@ IceRuby::ParamInfo::unmarshaled(VALUE val, VALUE target, void* closure) // // OperationI implementation. // -IceRuby::OperationI::OperationI(VALUE name, VALUE mode, VALUE sendMode, VALUE amd, VALUE inParams, VALUE outParams, - VALUE returnType, VALUE exceptions) +IceRuby::OperationI::OperationI(VALUE name, VALUE mode, VALUE sendMode, VALUE amd, VALUE format, VALUE inParams, + VALUE outParams, VALUE returnType, VALUE exceptions) { _name = getString(name); _amd = amd == Qtrue; @@ -173,6 +198,20 @@ IceRuby::OperationI::OperationI(VALUE name, VALUE mode, VALUE sendMode, VALUE am assert(TYPE(sendModeValue) == T_FIXNUM); _sendMode = static_cast<Ice::OperationMode>(FIX2LONG(sendModeValue)); + // + // format + // + if(format == Qnil) + { + _format = Ice::DefaultFormat; + } + else + { + volatile VALUE formatValue = callRuby(rb_funcall, format, rb_intern("to_i"), 0); + assert(TYPE(formatValue) == T_FIXNUM); + _format = static_cast<Ice::FormatType>(FIX2LONG(formatValue)); + } + long i; // @@ -236,7 +275,7 @@ IceRuby::OperationI::invoke(const Ice::ObjectPrx& proxy, VALUE args, VALUE hctx) // Marshal the input parameters to a byte sequence. // Ice::ByteSeq params; - prepareRequest(communicator, args, false, params); + prepareRequest(proxy, args, false, params); if(!_deprecateMessage.empty()) { @@ -316,8 +355,7 @@ IceRuby::OperationI::deprecate(const string& msg) } void -IceRuby::OperationI::prepareRequest(const Ice::CommunicatorPtr& communicator, VALUE args, bool async, - vector<Ice::Byte>& bytes) +IceRuby::OperationI::prepareRequest(const Ice::ObjectPrx& proxy, VALUE args, bool async, vector<Ice::Byte>& bytes) { // // Validate the number of arguments. @@ -335,7 +373,13 @@ IceRuby::OperationI::prepareRequest(const Ice::CommunicatorPtr& communicator, VA // // Marshal the in parameters. // - Ice::OutputStreamPtr os = Ice::createOutputStream(communicator); + Ice::OutputStreamPtr os = Ice::createOutputStream(proxy->ice_getCommunicator()); + os->startEncapsulation(proxy->ice_getEncodingVersion()); + + if(_sendsClasses && _format != Ice::DefaultFormat) + { + os->format(_format); + } ObjectMap objectMap; long i = 0; @@ -364,6 +408,7 @@ IceRuby::OperationI::prepareRequest(const Ice::CommunicatorPtr& communicator, VA os->writePendingObjects(); } + os->endEncapsulation(); os->finished(bytes); } } @@ -382,6 +427,17 @@ IceRuby::OperationI::unmarshalResults(const vector<Ice::Byte>& bytes, const Ice: // in a tuple of the form (result, outParam1, ...). Otherwise just return the value. // Ice::InputStreamPtr is = Ice::createInputStream(communicator, bytes); + + // + // Store a pointer to a local SlicedDataUtil object as the stream's closure. + // This is necessary to support object unmarshaling (see ObjectReader). + // + SlicedDataUtil util; + assert(!is->closure()); + is->closure(&util); + + is->startEncapsulation(); + for(ParamInfoList::iterator p = _outParams.begin(); p != _outParams.end(); ++p, ++i) { void* closure = reinterpret_cast<void*>(i); @@ -398,85 +454,55 @@ IceRuby::OperationI::unmarshalResults(const vector<Ice::Byte>& bytes, const Ice: is->readPendingObjects(); } + util.update(); + + is->endEncapsulation(); + return results; } VALUE IceRuby::OperationI::unmarshalException(const vector<Ice::Byte>& bytes, const Ice::CommunicatorPtr& communicator) { - int traceSlicing = -1; - Ice::InputStreamPtr is = Ice::createInputStream(communicator, bytes); - bool usesClasses; - is->read(usesClasses); + // + // Store a pointer to a local SlicedDataUtil object as the stream's closure. + // This is necessary to support object unmarshaling (see ObjectReader). + // + SlicedDataUtil util; + assert(!is->closure()); + is->closure(&util); - string id; - is->read(id); - const string origId = id; + is->startEncapsulation(); - while(!id.empty()) + try { - ExceptionInfoPtr info = lookupExceptionInfo(id); - if(info) + Ice::UserExceptionReaderFactoryPtr factory = new UserExceptionReaderFactoryI(communicator); + is->throwException(factory); + } + catch(const ExceptionReader& r) + { + volatile VALUE ex = r.getException(); + + if(validateException(ex)) { - volatile VALUE ex = info->unmarshal(is); - if(info->usesClasses) - { - is->readPendingObjects(); - } + util.update(); - if(validateException(ex)) - { - return ex; - } - else - { - volatile VALUE cls = CLASS_OF(ex); - volatile VALUE path = callRuby(rb_class_path, cls); - assert(TYPE(path) == T_STRING); - Ice::UnknownUserException e(__FILE__, __LINE__); - e.unknown = RSTRING_PTR(path); - throw e; - } + return ex; } else { - if(traceSlicing == -1) - { - traceSlicing = communicator->getProperties()->getPropertyAsInt("Ice.Trace.Slicing") > 0; - } - - if(traceSlicing > 0) - { - communicator->getLogger()->trace("Slicing", "unknown exception type `" + id + "'"); - } - - is->skipSlice(); // Slice off what we don't understand. - - try - { - is->read(id); // Read type id for next slice. - } - catch(Ice::UnmarshalOutOfBoundsException& ex) - { - // - // When readString raises this exception it means we've seen the last slice, - // so we set the reason member to a more helpful message. - // - ex.reason = "unknown exception type `" + origId + "'"; - throw; - } + volatile VALUE cls = CLASS_OF(ex); + volatile VALUE path = callRuby(rb_class_path, cls); + assert(TYPE(path) == T_STRING); + Ice::UnknownUserException e(__FILE__, __LINE__); + e.unknown = RSTRING_PTR(path); + throw e; } } - // - // Getting here should be impossible: we can get here only if the - // sender has marshaled a sequence of type IDs, none of which we - // have a factory for. This means that sender and receiver disagree - // about the Slice definitions they use. - // - throw Ice::UnknownUserException(__FILE__, __LINE__, "unknown exception type `" + origId + "'"); + throw Ice::UnknownUserException(__FILE__, __LINE__, "unknown exception"); } bool @@ -507,7 +533,7 @@ IceRuby::OperationI::checkTwowayOnly(const Ice::ObjectPrx& proxy) const bool IceRuby::initOperation(VALUE iceModule) { - rb_define_module_function(iceModule, "__defineOperation", CAST_METHOD(IceRuby_defineOperation), 8); + rb_define_module_function(iceModule, "__defineOperation", CAST_METHOD(IceRuby_defineOperation), 9); // // Define a class to represent an operation. diff --git a/rb/src/IceRuby/Proxy.cpp b/rb/src/IceRuby/Proxy.cpp index 45027d02e80..96821876a6e 100644 --- a/rb/src/IceRuby/Proxy.cpp +++ b/rb/src/IceRuby/Proxy.cpp @@ -547,6 +547,37 @@ IceRuby_ObjectPrx_ice_secure(VALUE self, VALUE b) extern "C" VALUE +IceRuby_ObjectPrx_ice_getEncodingVersion(VALUE self) +{ + ICE_RUBY_TRY + { + Ice::ObjectPrx p = getProxy(self); + return createEncodingVersion(p->ice_getEncodingVersion()); + } + ICE_RUBY_CATCH + return Qnil; +} + +extern "C" +VALUE +IceRuby_ObjectPrx_ice_encodingVersion(VALUE self, VALUE v) +{ + Ice::EncodingVersion val; + if(getEncodingVersion(v, val)) + { + ICE_RUBY_TRY + { + Ice::ObjectPrx p = getProxy(self); + return createProxy(p->ice_encodingVersion(val), rb_class_of(self)); + } + ICE_RUBY_CATCH + } + + return Qnil; +} + +extern "C" +VALUE IceRuby_ObjectPrx_ice_isPreferSecure(VALUE self) { ICE_RUBY_TRY @@ -861,6 +892,19 @@ IceRuby_ObjectPrx_ice_getCachedConnection(VALUE self) extern "C" VALUE +IceRuby_ObjectPrx_ice_flushBatchRequests(VALUE self) +{ + ICE_RUBY_TRY + { + Ice::ObjectPrx p = getProxy(self); + p->ice_flushBatchRequests(); + } + ICE_RUBY_CATCH + return Qnil; +} + +extern "C" +VALUE IceRuby_ObjectPrx_cmp(VALUE self, VALUE other) { ICE_RUBY_TRY @@ -1180,6 +1224,8 @@ IceRuby::initProxy(VALUE iceModule) rb_define_method(_proxyClass, "ice_endpointSelection", CAST_METHOD(IceRuby_ObjectPrx_ice_endpointSelection), 1); rb_define_method(_proxyClass, "ice_isSecure", CAST_METHOD(IceRuby_ObjectPrx_ice_isSecure), 0); rb_define_method(_proxyClass, "ice_secure", CAST_METHOD(IceRuby_ObjectPrx_ice_secure), 1); + rb_define_method(_proxyClass, "ice_getEncodingVersion", CAST_METHOD(IceRuby_ObjectPrx_ice_getEncodingVersion), 0); + rb_define_method(_proxyClass, "ice_encodingVersion", CAST_METHOD(IceRuby_ObjectPrx_ice_encodingVersion), 1); rb_define_method(_proxyClass, "ice_isPreferSecure", CAST_METHOD(IceRuby_ObjectPrx_ice_isPreferSecure), 0); rb_define_method(_proxyClass, "ice_preferSecure", CAST_METHOD(IceRuby_ObjectPrx_ice_preferSecure), 1); rb_define_method(_proxyClass, "ice_getRouter", CAST_METHOD(IceRuby_ObjectPrx_ice_getRouter), 0); @@ -1201,6 +1247,7 @@ IceRuby::initProxy(VALUE iceModule) rb_define_method(_proxyClass, "ice_connectionId", CAST_METHOD(IceRuby_ObjectPrx_ice_connectionId), 1); rb_define_method(_proxyClass, "ice_getConnection", CAST_METHOD(IceRuby_ObjectPrx_ice_getConnection), 0); rb_define_method(_proxyClass, "ice_getCachedConnection", CAST_METHOD(IceRuby_ObjectPrx_ice_getCachedConnection), 0); + rb_define_method(_proxyClass, "ice_flushBatchRequests", CAST_METHOD(IceRuby_ObjectPrx_ice_flushBatchRequests), 0); rb_define_method(_proxyClass, "hash", CAST_METHOD(IceRuby_ObjectPrx_hash), 0); rb_define_method(_proxyClass, "to_s", CAST_METHOD(IceRuby_ObjectPrx_ice_toString), 0); diff --git a/rb/src/IceRuby/Types.cpp b/rb/src/IceRuby/Types.cpp index f9648123349..5c29dd817b1 100644 --- a/rb/src/IceRuby/Types.cpp +++ b/rb/src/IceRuby/Types.cpp @@ -14,6 +14,7 @@ #include <IceUtil/OutputUtil.h> #include <IceUtil/ScopedArray.h> #include <Ice/LocalException.h> +#include <Ice/SlicedData.h> // // Required for RHASH_SIZE to work properly with Ruby 1.8.x. @@ -175,6 +176,193 @@ addExceptionInfo(const string& id, const ExceptionInfoPtr& info) } // +// SlicedDataUtil implementation +// +VALUE IceRuby::SlicedDataUtil::_slicedDataType = Qnil; +VALUE IceRuby::SlicedDataUtil::_sliceInfoType = Qnil; + +IceRuby::SlicedDataUtil::SlicedDataUtil() +{ +} + +IceRuby::SlicedDataUtil::~SlicedDataUtil() +{ + // + // Make sure we break any cycles among the objects in preserved slices. + // + for(set<ObjectReaderPtr>::iterator p = _readers.begin(); p != _readers.end(); ++p) + { + (*p)->getSlicedData()->clearObjects(); + } +} + +void +IceRuby::SlicedDataUtil::add(const ObjectReaderPtr& reader) +{ + assert(reader->getSlicedData()); + _readers.insert(reader); +} + +void +IceRuby::SlicedDataUtil::update() +{ + for(set<ObjectReaderPtr>::iterator p = _readers.begin(); p != _readers.end(); ++p) + { + setMember((*p)->getObject(), (*p)->getSlicedData()); + } +} + +void +IceRuby::SlicedDataUtil::setMember(VALUE obj, const Ice::SlicedDataPtr& slicedData) +{ + // + // Create a Ruby equivalent of the SlicedData object. + // + + assert(slicedData); + + if(_slicedDataType == Qnil) + { + _slicedDataType = callRuby(rb_path2class, "Ice::SlicedData"); + assert(!NIL_P(_slicedDataType)); + } + if(_sliceInfoType == Qnil) + { + _sliceInfoType = callRuby(rb_path2class, "Ice::SliceInfo"); + assert(!NIL_P(_sliceInfoType)); + } + + volatile VALUE sd = callRuby(rb_class_new_instance, 0, static_cast<VALUE*>(0), _slicedDataType); + + Ice::Int sz = slicedData->slices.size(); + volatile VALUE slices = createArray(sz); + + callRuby(rb_iv_set, sd, "@slices", slices); + + // + // Translate each SliceInfo object into its Ruby equivalent. + // + int i = 0; + for(vector<Ice::SliceInfoPtr>::const_iterator p = slicedData->slices.begin(); p != slicedData->slices.end(); ++p) + { + volatile VALUE slice = callRuby(rb_class_new_instance, 0, static_cast<VALUE*>(0), _sliceInfoType); + + RARRAY_PTR(slices)[i++] = slice; + + // + // typeId + // + volatile VALUE typeId = createString((*p)->typeId); + callRuby(rb_iv_set, slice, "@typeId", typeId); + + // + // bytes + // + volatile VALUE bytes = callRuby(rb_str_new, reinterpret_cast<const char*>(&(*p)->bytes[0]), (*p)->bytes.size()); + callRuby(rb_iv_set, slice, "@bytes", bytes); + + // + // objects + // + volatile VALUE objects = createArray((*p)->objects.size()); + callRuby(rb_iv_set, slice, "@objects", objects); + + int j = 0; + for(vector<Ice::ObjectPtr>::iterator q = (*p)->objects.begin(); q != (*p)->objects.end(); ++q) + { + // + // Each element in the objects list is an instance of ObjectReader that wraps a Python object. + // + assert(*q); + ObjectReaderPtr r = ObjectReaderPtr::dynamicCast(*q); + assert(r); + VALUE o = r->getObject(); + assert(o != Qnil); // Should be non-nil. + RARRAY_PTR(objects)[j++] = o; + } + } + + callRuby(rb_iv_set, obj, "@_ice_slicedData", sd); +} + +// +// Instances of preserved class and exception types may have a data member +// named _ice_slicedData which is an instance of the Ruby class Ice::SlicedData. +// +Ice::SlicedDataPtr +IceRuby::SlicedDataUtil::getMember(VALUE obj, ObjectMap* objectMap) +{ + Ice::SlicedDataPtr slicedData; + + if(callRuby(rb_ivar_defined, obj, rb_intern("@_ice_slicedData")) == Qtrue) + { + volatile VALUE sd = callRuby(rb_iv_get, obj, "@_ice_slicedData"); + + if(sd != Qnil) + { + // + // The "slices" member is an array of Ice::SliceInfo objects. + // + volatile VALUE sl = callRuby(rb_iv_get, sd, "@slices"); + assert(TYPE(sl) == T_ARRAY); + + Ice::SliceInfoSeq slices; + + long sz = RARRAY_LEN(sl); + for(long i = 0; i < sz; ++i) + { + volatile VALUE s = RARRAY_PTR(sl)[i]; + + Ice::SliceInfoPtr info = new Ice::SliceInfo; + + volatile VALUE typeId = callRuby(rb_iv_get, s, "@typeId"); + info->typeId = getString(typeId); + + volatile VALUE bytes = callRuby(rb_iv_get, s, "@bytes"); + assert(TYPE(bytes) == T_STRING); + const char* str = RSTRING_PTR(bytes); + const long len = RSTRING_LEN(bytes); + if(str != 0 && len != 0) + { + vector<Ice::Byte> vtmp(reinterpret_cast<const Ice::Byte*>(str), + reinterpret_cast<const Ice::Byte*>(str + len)); + info->bytes.swap(vtmp); + } + + volatile VALUE objects = callRuby(rb_iv_get, s, "@objects"); + assert(TYPE(objects) == T_ARRAY); + long osz = RARRAY_LEN(objects); + for(long j = 0; j < osz; ++j) + { + VALUE o = RARRAY_PTR(objects)[j]; + + Ice::ObjectPtr writer; + + ObjectMap::iterator i = objectMap->find(o); + if(i == objectMap->end()) + { + writer = new ObjectWriter(o, objectMap); + objectMap->insert(ObjectMap::value_type(o, writer)); + } + else + { + writer = i->second; + } + + info->objects.push_back(writer); + } + + slices.push_back(info); + } + + slicedData = new Ice::SlicedData(slices); + } + } + + return slicedData; +} + +// // UnmarshalCallback implementation. // IceRuby::UnmarshalCallback::~UnmarshalCallback() @@ -1397,12 +1585,7 @@ IceRuby::ClassInfo::marshal(VALUE p, const Ice::OutputStreamPtr& os, ObjectMap* ObjectMap::iterator q = objectMap->find(p); if(q == objectMap->end()) { - volatile VALUE cls = CLASS_OF(p); - volatile VALUE type = callRuby(rb_const_get, cls, rb_intern("ICE_TYPE")); - assert(!NIL_P(type)); // Should have been caught by validate(). - ClassInfoPtr info = ClassInfoPtr::dynamicCast(getType(type)); - assert(info); - writer = new ObjectWriter(info, p, objectMap); + writer = new ObjectWriter(p, objectMap); objectMap->insert(ObjectMap::value_type(p, writer)); } else @@ -1457,7 +1640,6 @@ IceRuby::ClassInfo::print(VALUE value, IceUtilInternal::Output& out, PrintObject { type = callRuby(rb_const_get, cls, rb_intern("ICE_TYPE")); info = ClassInfoPtr::dynamicCast(getType(type)); - assert(info); } catch(const RubyException& ex) { @@ -1659,9 +1841,14 @@ IceRuby::ProxyInfo::destroy() // // ObjectWriter implementation. // -IceRuby::ObjectWriter::ObjectWriter(const ClassInfoPtr& info, VALUE object, ObjectMap* objectMap) : - _info(info), _object(object), _map(objectMap) +IceRuby::ObjectWriter::ObjectWriter(VALUE object, ObjectMap* objectMap) : + _object(object), _map(objectMap) { + volatile VALUE cls = CLASS_OF(object); + volatile VALUE type = callRuby(rb_const_get, cls, rb_intern("ICE_TYPE")); + assert(!NIL_P(type)); + _info = ClassInfoPtr::dynamicCast(getType(type)); + assert(_info); } void @@ -1677,12 +1864,22 @@ IceRuby::ObjectWriter::ice_preMarshal() void IceRuby::ObjectWriter::write(const Ice::OutputStreamPtr& os) const { + Ice::SlicedDataPtr slicedData; + + if(_info->preserve) + { + // + // Retrieve the SlicedData object that we stored as a hidden member of the Python object. + // + slicedData = SlicedDataUtil::getMember(_object, const_cast<ObjectMap*>(_map)); + } + + os->startObject(slicedData); + ClassInfoPtr info = _info; while(info) { - os->writeTypeId(info->id); - - os->startSlice(); + os->startSlice(info->id, !info->base); for(DataMemberList::iterator q = info->members.begin(); q != info->members.end(); ++q) { DataMemberPtr member = *q; @@ -1700,13 +1897,7 @@ IceRuby::ObjectWriter::write(const Ice::OutputStreamPtr& os) const info = info->base; } - // - // Marshal the Ice::Object slice. - // - os->writeTypeId(Ice::Object::ice_staticId()); - os->startSlice(); - os->writeSize(0); // For compatibility with the old AFM. - os->endSlice(); + os->endObject(); } // @@ -1728,8 +1919,10 @@ IceRuby::ObjectReader::ice_postUnmarshal() } void -IceRuby::ObjectReader::read(const Ice::InputStreamPtr& is, bool rid) +IceRuby::ObjectReader::read(const Ice::InputStreamPtr& is) { + is->startObject(); + // // Unmarshal the slices of a user-defined class. // @@ -1738,11 +1931,6 @@ IceRuby::ObjectReader::read(const Ice::InputStreamPtr& is, bool rid) ClassInfoPtr info = _info; while(info) { - if(rid) - { - is->readTypeId(); - } - is->startSlice(); for(DataMemberList::iterator p = info->members.begin(); p != info->members.end(); ++p) { @@ -1751,28 +1939,18 @@ IceRuby::ObjectReader::read(const Ice::InputStreamPtr& is, bool rid) } is->endSlice(); - rid = true; - info = info->base; } } - // - // Unmarshal the Ice::Object slice. - // - if(rid) - { - is->readTypeId(); - } + _slicedData = is->endObject(_info->preserve); - is->startSlice(); - // For compatibility with the old AFM. - Ice::Int sz = is->readSize(); - if(sz != 0) + if(_slicedData) { - throw Ice::MarshalException(__FILE__, __LINE__); + SlicedDataUtil* util = reinterpret_cast<SlicedDataUtil*>(is->closure()); + assert(util); + util->add(this); } - is->endSlice(); } ClassInfoPtr @@ -1787,6 +1965,12 @@ IceRuby::ObjectReader::getObject() const return _object; } +Ice::SlicedDataPtr +IceRuby::ObjectReader::getSlicedData() const +{ + return _slicedData; +} + // // InfoMapDestroyer implementation. // @@ -1848,48 +2032,11 @@ IceRuby::ReadObjectCallback::invoke(const Ice::ObjectPtr& p) // // ExceptionInfo implementation. // -void -IceRuby::ExceptionInfo::marshal(VALUE p, const Ice::OutputStreamPtr& os, ObjectMap* objectMap) -{ - if(callRuby(rb_obj_is_kind_of, p, rubyClass) == Qfalse) - { - throw RubyException(rb_eTypeError, "expected exception %s", id.c_str()); - } - - os->write(usesClasses); - - ExceptionInfoPtr info = this; - while(info) - { - os->write(info->id); - - os->startSlice(); - for(DataMemberList::iterator q = info->members.begin(); q != info->members.end(); ++q) - { - DataMemberPtr member = *q; - volatile VALUE val = callRuby(rb_ivar_get, p, member->rubyID); - if(!member->type->validate(val)) - { - throw RubyException(rb_eTypeError, "invalid value for %s member `%s'", id.c_str(), - member->name.c_str()); - } - - member->type->marshal(val, os, objectMap); - } - os->endSlice(); - - info = info->base; - } -} - VALUE IceRuby::ExceptionInfo::unmarshal(const Ice::InputStreamPtr& is) { volatile VALUE obj = callRuby(rb_class_new_instance, 0, static_cast<VALUE*>(0), rubyClass); - // - // NOTE: The type id for the first slice has already been read. - // ExceptionInfoPtr info = this; while(info) { @@ -1902,11 +2049,6 @@ IceRuby::ExceptionInfo::unmarshal(const Ice::InputStreamPtr& is) is->endSlice(); info = info->base; - if(info) - { - string id; - is->read(id); // Read the ID of the next slice. - } } return obj; @@ -1954,6 +2096,71 @@ IceRuby::ExceptionInfo::printMembers(VALUE value, IceUtilInternal::Output& out, } } +// +// ExceptionReader implementation. +// +IceRuby::ExceptionReader::ExceptionReader(const Ice::CommunicatorPtr& communicator, const ExceptionInfoPtr& info) : + Ice::UserExceptionReader(communicator), _info(info) +{ +} + +IceRuby::ExceptionReader::~ExceptionReader() + throw() +{ +} + +void +IceRuby::ExceptionReader::read(const Ice::InputStreamPtr& is) const +{ + is->startException(); + + const_cast<VALUE&>(_ex) = _info->unmarshal(is); + + is->endException(false); +} + +bool +IceRuby::ExceptionReader::usesClasses() const +{ + return _info->usesClasses; +} + +void +IceRuby::ExceptionReader::usesClasses(bool) +{ +} + +string +IceRuby::ExceptionReader::ice_name() const +{ + return _info->id; +} + +Ice::Exception* +IceRuby::ExceptionReader::ice_clone() const +{ + assert(false); + return 0; +} + +void +IceRuby::ExceptionReader::ice_throw() const +{ + throw *this; +} + +VALUE +IceRuby::ExceptionReader::getException() const +{ + return _ex; +} + +Ice::SlicedDataPtr +IceRuby::ExceptionReader::getSlicedData() const +{ + return 0; +} + extern "C" VALUE IceRuby_defineEnum(VALUE /*self*/, VALUE id, VALUE type, VALUE enumerators) @@ -2078,8 +2285,10 @@ IceRuby_declareClass(VALUE /*self*/, VALUE id) { info = new ClassInfo; info->id = idstr; - info->isBase = idstr == "::Ice::Object"; + info->isBase = idstr == Ice::Object::ice_staticId(); info->isLocal = false; + info->isAbstract = false; + info->preserve = false; info->rubyClass = Qnil; info->typeObj = createType(info); info->defined = false; @@ -2106,6 +2315,8 @@ IceRuby_declareLocalClass(VALUE /*self*/, VALUE id) info->id = idstr; info->isBase = idstr == "::Ice::LocalObject"; info->isLocal = true; + info->isAbstract = false; + info->preserve = false; info->rubyClass = Qnil; info->typeObj = createType(info); info->defined = false; @@ -2183,7 +2394,8 @@ IceRuby_TypeInfo_defineProxy(VALUE self, VALUE type, VALUE classInfo) extern "C" VALUE -IceRuby_TypeInfo_defineClass(VALUE self, VALUE type, VALUE isAbstract, VALUE base, VALUE interfaces, VALUE members) +IceRuby_TypeInfo_defineClass(VALUE self, VALUE type, VALUE isAbstract, VALUE preserve, VALUE base, VALUE interfaces, + VALUE members) { ICE_RUBY_TRY { @@ -2191,6 +2403,7 @@ IceRuby_TypeInfo_defineClass(VALUE self, VALUE type, VALUE isAbstract, VALUE bas assert(info); info->isAbstract = isAbstract == Qtrue; + info->preserve = preserve == Qtrue; if(!NIL_P(base)) { @@ -2329,7 +2542,7 @@ IceRuby::initTypes(VALUE iceModule) rb_define_module_function(iceModule, "__declareLocalClass", CAST_METHOD(IceRuby_declareLocalClass), 1); rb_define_module_function(iceModule, "__defineException", CAST_METHOD(IceRuby_defineException), 4); - rb_define_method(_typeInfoClass, "defineClass", CAST_METHOD(IceRuby_TypeInfo_defineClass), 5); + rb_define_method(_typeInfoClass, "defineClass", CAST_METHOD(IceRuby_TypeInfo_defineClass), 6); rb_define_method(_typeInfoClass, "defineProxy", CAST_METHOD(IceRuby_TypeInfo_defineProxy), 2); rb_define_module_function(iceModule, "__stringify", CAST_METHOD(IceRuby_stringify), 2); diff --git a/rb/src/IceRuby/Types.h b/rb/src/IceRuby/Types.h index a42840a568d..954272f8f02 100644 --- a/rb/src/IceRuby/Types.h +++ b/rb/src/IceRuby/Types.h @@ -37,6 +37,34 @@ class AbortMarshaling typedef std::map<VALUE, Ice::ObjectPtr> ObjectMap; +class ObjectReader; +typedef IceUtil::Handle<ObjectReader> ObjectReaderPtr; + +// +// This class keeps track of Ruby objects (instances of Slice classes +// and exceptions) that have preserved slices. +// +class SlicedDataUtil +{ +public: + + SlicedDataUtil(); + ~SlicedDataUtil(); + + void add(const ObjectReaderPtr&); + + void update(); + + static void setMember(VALUE, const Ice::SlicedDataPtr&); + static Ice::SlicedDataPtr getMember(VALUE, ObjectMap*); + +private: + + std::set<ObjectReaderPtr> _readers; + static VALUE _slicedDataType; + static VALUE _sliceInfoType; +}; + struct PrintObjectHistory { int index; @@ -298,6 +326,7 @@ public: bool isBase; // Is this the ClassInfo for Ice::Object or Ice::LocalObject? bool isLocal; bool isAbstract; + bool preserve; ClassInfoPtr base; ClassInfoList interfaces; DataMemberList members; @@ -338,7 +367,6 @@ class ExceptionInfo : public IceUtil::Shared { public: - void marshal(VALUE, const Ice::OutputStreamPtr&, ObjectMap*); VALUE unmarshal(const Ice::InputStreamPtr&); void print(VALUE, IceUtilInternal::Output&); @@ -358,7 +386,7 @@ class ObjectWriter : public Ice::ObjectWriter { public: - ObjectWriter(const ClassInfoPtr&, VALUE, ObjectMap*); + ObjectWriter(VALUE, ObjectMap*); virtual void ice_preMarshal(); @@ -366,9 +394,9 @@ public: private: - ClassInfoPtr _info; VALUE _object; ObjectMap* _map; + ClassInfoPtr _info; }; // @@ -382,19 +410,51 @@ public: virtual void ice_postUnmarshal(); - virtual void read(const Ice::InputStreamPtr&, bool); + virtual void read(const Ice::InputStreamPtr&); virtual ClassInfoPtr getInfo() const; VALUE getObject() const; // Borrowed reference. + Ice::SlicedDataPtr getSlicedData() const; + private: VALUE _object; ClassInfoPtr _info; + Ice::SlicedDataPtr _slicedData; }; typedef IceUtil::Handle<ObjectReader> ObjectReaderPtr; +// +// ExceptionReader creates a Ruby user exception and unmarshals it. +// +class ExceptionReader : public Ice::UserExceptionReader +{ +public: + + ExceptionReader(const Ice::CommunicatorPtr&, const ExceptionInfoPtr&); + ~ExceptionReader() throw(); + + virtual void read(const Ice::InputStreamPtr&) const; + virtual bool usesClasses() const; + virtual void usesClasses(bool); + + virtual std::string ice_name() const; + virtual Ice::Exception* ice_clone() const; + virtual void ice_throw() const; + + VALUE getException() const; + + Ice::SlicedDataPtr getSlicedData() const; + +private: + + ExceptionInfoPtr _info; + VALUE _ex; + Ice::SlicedDataPtr _slicedData; +}; + ClassInfoPtr lookupClassInfo(const std::string&); ExceptionInfoPtr lookupExceptionInfo(const std::string&); diff --git a/rb/src/IceRuby/Util.cpp b/rb/src/IceRuby/Util.cpp index 0674c80f352..b5333cbcbd1 100644 --- a/rb/src/IceRuby/Util.cpp +++ b/rb/src/IceRuby/Util.cpp @@ -14,6 +14,123 @@ using namespace std; using namespace IceRuby; +namespace +{ + +bool +checkIsInstance(VALUE p, const char* type) +{ + volatile VALUE rbType = callRuby(rb_path2class, type); + assert(!NIL_P(rbType)); + return callRuby(rb_obj_is_instance_of, p, rbType) == Qtrue; +} + +template<typename T, const char* PT> +bool +setVersion(VALUE p, const T& version) +{ + assert(checkIsInstance(p, PT)); + + VALUE major = callRuby(rb_int2inum, version.major); + VALUE minor = callRuby(rb_int2inum, version.minor); + rb_ivar_set(p, rb_intern("@major"), major); + rb_ivar_set(p, rb_intern("@minor"), minor); + + return true; +} + +template<typename T, const char* PT> +bool +getVersion(VALUE p, T& v) +{ + assert(checkIsInstance(p, PT)); + volatile VALUE major = callRuby(rb_ivar_get, p, rb_intern("@major")); + volatile VALUE minor = callRuby(rb_ivar_get, p, rb_intern("@minor")); + + long m; + + m = getInteger(major); + if(m < 0 || m > 255) + { + throw RubyException(rb_eTypeError, "version major must be a value between 0 and 255"); + return false; + } + v.major = m; + + m = getInteger(minor); + if(m < 0 || m > 255) + { + throw RubyException(rb_eTypeError, "version minor must be a value between 0 and 255"); + return false; + } + v.minor = m; + + return true; +} + +template<typename T, const char* PT> +VALUE +createVersion(const T& version) +{ + volatile VALUE rbType = callRuby(rb_path2class, PT); + assert(!NIL_P(rbType)); + + volatile VALUE obj = callRuby(rb_class_new_instance, 0, static_cast<VALUE*>(0), rbType); + + if(!setVersion<T, PT>(obj, version)) + { + return Qnil; + } + + return obj; +} + +template<typename T, const char* PT> +VALUE +versionToString(VALUE p) +{ + volatile VALUE rbType = callRuby(rb_path2class, PT); + assert(!NIL_P(rbType)); + if(callRuby(rb_obj_is_instance_of, p, rbType) != Qtrue) + { + throw RubyException(rb_eTypeError, "argument is not an instance of %s", PT); + } + + T v; + if(!getVersion<T, PT>(p, v)) + { + return NULL; + } + + ICE_RUBY_TRY + { + string s = IceInternal::versionToString<T>(v); + return createString(s); + } + ICE_RUBY_CATCH + return Qnil; +} + +template<typename T, const char* PT> +VALUE +stringToVersion(VALUE p) +{ + string str = getString(p); + + ICE_RUBY_TRY + { + T v = IceInternal::stringToVersion<T>(str); + return createVersion<T, PT>(v); + } + ICE_RUBY_CATCH + return Qnil; +} + +char Ice_ProtocolVersion[] = "Ice::ProtocolVersion"; +char Ice_EncodingVersion[] = "Ice::EncodingVersion"; + +} + extern "C" VALUE IceRuby_stringVersion(int /*argc*/, VALUE* /*argv*/, VALUE /*self*/) @@ -39,11 +156,82 @@ IceRuby_intVersion(int /*argc*/, VALUE* /*argv*/, VALUE /*self*/) return Qnil; } +extern "C" +VALUE +IceRuby_currentProtocol(int /*argc*/, VALUE* /*argv*/, VALUE /*self*/) +{ + ICE_RUBY_TRY + { + return createProtocolVersion(Ice::currentProtocol); + } + ICE_RUBY_CATCH + return Qnil; +} + +extern "C" +VALUE +IceRuby_currentProtocolEncoding(int /*argc*/, VALUE* /*argv*/, VALUE /*self*/) +{ + ICE_RUBY_TRY + { + return createEncodingVersion(Ice::currentProtocolEncoding); + } + ICE_RUBY_CATCH + return Qnil; +} + +extern "C" +VALUE +IceRuby_currentEncoding(int /*argc*/, VALUE* /*argv*/, VALUE /*self*/) +{ + ICE_RUBY_TRY + { + return createEncodingVersion(Ice::currentEncoding); + } + ICE_RUBY_CATCH + return Qnil; +} + +extern "C" +VALUE +IceRuby_protocolVersionToString(VALUE /*self*/, VALUE v) +{ + return versionToString<Ice::ProtocolVersion, Ice_ProtocolVersion>(v); +} + +extern "C" +VALUE +IceRuby_stringToProtocolVersion(VALUE /*self*/, VALUE v) +{ + return stringToVersion<Ice::ProtocolVersion, Ice_ProtocolVersion>(v); +} + +extern "C" +VALUE +IceRuby_encodingVersionToString(VALUE /*self*/, VALUE v) +{ + return versionToString<Ice::EncodingVersion, Ice_EncodingVersion>(v); +} + +extern "C" +VALUE +IceRuby_stringToEncodingVersion(VALUE /*self*/, VALUE v) +{ + return stringToVersion<Ice::EncodingVersion, Ice_EncodingVersion>(v); +} + void IceRuby::initUtil(VALUE iceModule) { rb_define_module_function(iceModule, "stringVersion", CAST_METHOD(IceRuby_stringVersion), -1); rb_define_module_function(iceModule, "intVersion", CAST_METHOD(IceRuby_intVersion), -1); + rb_define_module_function(iceModule, "currentProtocol", CAST_METHOD(IceRuby_currentProtocol), -1); + rb_define_module_function(iceModule, "currentProtocolEncoding", CAST_METHOD(IceRuby_currentProtocolEncoding), -1); + rb_define_module_function(iceModule, "currentEncoding", CAST_METHOD(IceRuby_currentEncoding), -1); + rb_define_module_function(iceModule, "protocolVersionToString", CAST_METHOD(IceRuby_protocolVersionToString), 1); + rb_define_module_function(iceModule, "stringToProtocolVersion", CAST_METHOD(IceRuby_stringToProtocolVersion), 1); + rb_define_module_function(iceModule, "encodingVersionToString", CAST_METHOD(IceRuby_encodingVersionToString), 1); + rb_define_module_function(iceModule, "stringToEncodingVersion", CAST_METHOD(IceRuby_stringToEncodingVersion), 1); } IceRuby::RubyException::RubyException() @@ -340,6 +528,74 @@ IceRuby::createIdentity(const Ice::Identity& id) } VALUE +IceRuby::createProtocolVersion(const Ice::ProtocolVersion& v) +{ + return createVersion<Ice::ProtocolVersion, Ice_ProtocolVersion>(v); +} + +VALUE +IceRuby::createEncodingVersion(const Ice::EncodingVersion& v) +{ + return createVersion<Ice::EncodingVersion, Ice_EncodingVersion>(v); +} + +bool +IceRuby::getEncodingVersion(VALUE p, Ice::EncodingVersion& v) +{ + volatile VALUE cls = callRuby(rb_path2class, Ice_EncodingVersion); + assert(!NIL_P(cls)); + + if(callRuby(rb_obj_is_kind_of, p, cls) == Qfalse) + { + throw RubyException(rb_eTypeError, "value is not an Ice::EncodingVersion"); + } + + if(!getVersion<Ice::EncodingVersion, Ice_EncodingVersion>(p, v)) + { + return false; + } + + return true; +} + +#if 0 +VALUE +IceRuby::currentProtocol(VALUE) +{ +} + +VALUE +IceRuby::currentProtocolEncoding(VALUE) +{ +} + +VALUE +IceRuby::currentEncoding(VALUE) +{ +} + +VALUE +IceRuby::protocolVersionToString(VALUE, VALUE) +{ +} + +VALUE +IceRuby::stringToProtocolVersion(VALUE, VALUE) +{ +} + +VALUE +IceRuby::encodingVersionToString(VALUE, VALUE) +{ +} + +VALUE +IceRuby::stringToEncodingVersion(VALUE, VALUE) +{ +} +#endif + +VALUE IceRuby::callProtected(RubyFunction func, VALUE arg) { int error = 0; @@ -464,17 +720,19 @@ setExceptionMembers(const Ice::LocalException& ex, VALUE p) } catch(const Ice::UnsupportedProtocolException& e) { - callRuby(rb_iv_set, p, "@badMajor", INT2FIX(e.badMajor)); - callRuby(rb_iv_set, p, "@badMinor", INT2FIX(e.badMinor)); - callRuby(rb_iv_set, p, "@major", INT2FIX(e.major)); - callRuby(rb_iv_set, p, "@minor", INT2FIX(e.minor)); + VALUE m; + m = createProtocolVersion(e.bad); + callRuby(rb_iv_set, p, "@bad", m); + m = createProtocolVersion(e.supported); + callRuby(rb_iv_set, p, "@supported", m); } catch(const Ice::UnsupportedEncodingException& e) { - callRuby(rb_iv_set, p, "@badMajor", INT2FIX(e.badMajor)); - callRuby(rb_iv_set, p, "@badMinor", INT2FIX(e.badMinor)); - callRuby(rb_iv_set, p, "@major", INT2FIX(e.major)); - callRuby(rb_iv_set, p, "@minor", INT2FIX(e.minor)); + VALUE m; + m = createEncodingVersion(e.bad); + callRuby(rb_iv_set, p, "@bad", m); + m = createEncodingVersion(e.supported); + callRuby(rb_iv_set, p, "@supported", m); } catch(const Ice::NoObjectFactoryException& e) { diff --git a/rb/src/IceRuby/Util.h b/rb/src/IceRuby/Util.h index a58416800dd..236b18c029e 100644 --- a/rb/src/IceRuby/Util.h +++ b/rb/src/IceRuby/Util.h @@ -131,6 +131,21 @@ Ice::Identity getIdentity(VALUE); VALUE createIdentity(const Ice::Identity&); // +// Create a Ruby instance of Ice.ProtocolVersion. +// +VALUE createProtocolVersion(const Ice::ProtocolVersion&); + +// +// Create a Ruby instance of Ice.EncodingVersion. +// +VALUE createEncodingVersion(const Ice::EncodingVersion&); + +// +// Extracts the members of an encoding version. +// +bool getEncodingVersion(VALUE, Ice::EncodingVersion&); + +// // The callRuby functions are used to invoke Ruby C API functions // while translating any Ruby exception into RubyException so that // C++ objects are cleaned up properly. Overloadings are provided diff --git a/rb/test/Ice/info/AllTests.rb b/rb/test/Ice/info/AllTests.rb index 7c9b5f66ecb..7aed5469f2f 100644 --- a/rb/test/Ice/info/AllTests.rb +++ b/rb/test/Ice/info/AllTests.rb @@ -11,14 +11,16 @@ def allTests(communicator) print "testing proxy endpoint information..." STDOUT.flush - p1 = communicator.stringToProxy("test -t:default -h tcphost -p 10000 -t 1200 -z:" + \ + p1 = communicator.stringToProxy("test -t:default -v 1.4 -e 1.3 -h tcphost -p 10000 -t 1200 -z:" + \ "udp -h udphost -p 10001 --interface eth0 --ttl 5:" + \ - "opaque -t 100 -v ABCD") + "opaque -e 1.8 -t 100 -v ABCD") endps = p1.ice_getEndpoints() ipEndpoint = endps[0].getInfo() test(ipEndpoint.is_a?(Ice::IPEndpointInfo)); + test(ipEndpoint.protocol == Ice::ProtocolVersion.new(1, 4)) + test(ipEndpoint.encoding == Ice::EncodingVersion.new(1, 3)) test(ipEndpoint.host == "tcphost") test(ipEndpoint.port == 10000) test(ipEndpoint.timeout == 1200) @@ -31,6 +33,8 @@ def allTests(communicator) udpEndpoint = endps[1].getInfo() test(udpEndpoint.is_a?(Ice::UDPEndpointInfo)); + test(udpEndpoint.protocol == Ice::currentProtocol) + test(udpEndpoint.encoding == Ice::currentEncoding) test(udpEndpoint.host == "udphost") test(udpEndpoint.port == 10001) test(udpEndpoint.mcastInterface == "eth0") @@ -43,6 +47,7 @@ def allTests(communicator) opaqueEndpoint = endps[2].getInfo() test(opaqueEndpoint.is_a?(Ice::OpaqueEndpointInfo)); + test(opaqueEndpoint.rawEncoding == Ice::EncodingVersion.new(1, 8)) puts "ok" diff --git a/rb/test/Ice/info/run.py b/rb/test/Ice/info/run.py index 61d1af84e72..751a8e1d456 100755 --- a/rb/test/Ice/info/run.py +++ b/rb/test/Ice/info/run.py @@ -21,4 +21,3 @@ sys.path.append(os.path.join(path[0], "scripts")) import TestUtil TestUtil.clientServerTest() - diff --git a/rb/test/Ice/operations/BatchOneways.rb b/rb/test/Ice/operations/BatchOneways.rb index e9571ef5e92..c7ae9d62b72 100644 --- a/rb/test/Ice/operations/BatchOneways.rb +++ b/rb/test/Ice/operations/BatchOneways.rb @@ -41,4 +41,45 @@ def batchOneways(p) 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) + begin + batch.ice_ping() + test(false) + rescue Ice::CloseConnectionException + end + + begin + batch2.ice_ping() + test(false) + rescue Ice::CloseConnectionException + end + + 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/rb/test/Ice/proxy/AllTests.rb b/rb/test/Ice/proxy/AllTests.rb index 16ea6e978c5..23b28227b11 100644 --- a/rb/test/Ice/proxy/AllTests.rb +++ b/rb/test/Ice/proxy/AllTests.rb @@ -270,6 +270,26 @@ def allTests(communicator) #test(!b1.ice_isCollocationOptimized()) #prop.setProperty(property, "") + property = propertyPrefix + ".EncodingVersion" + test(b1.ice_getEncodingVersion() == Ice::currentEncoding()) + prop.setProperty(property, "1.0") + b1 = communicator.propertyToProxy(propertyPrefix) + test(b1.ice_getEncodingVersion().major == 1 && b1.ice_getEncodingVersion().minor == 0) + prop.setProperty(property, "6.5") + begin + communicator.propertyToProxy(propertyPrefix) + test(false) + rescue Ice::UnsupportedEncodingException + end + + prop.setProperty(property, "1.2") + begin + communicator.propertyToProxy(propertyPrefix) + test(false) + rescue Ice::UnsupportedEncodingException + end + prop.setProperty(property, "") + puts "ok" print "testing proxyToProperty... " @@ -281,6 +301,7 @@ def allTests(communicator) b1 = b1.ice_preferSecure(false) b1 = b1.ice_endpointSelection(Ice::EndpointSelectionType::Ordered) b1 = b1.ice_locatorCacheTimeout(100) + b1 = b1.ice_encodingVersion(Ice::EncodingVersion.new(1, 0)) router = communicator.stringToProxy("router") #router = router.ice_collocationOptimized(false) @@ -300,10 +321,11 @@ def allTests(communicator) b1 = b1.ice_locator(Ice::LocatorPrx::uncheckedCast(locator)) proxyProps = communicator.proxyToProperty(b1, "Test") - test(proxyProps.length() == 18) + test(proxyProps.length() == 21) test(proxyProps["Test"] == "test -t") #test(proxyProps["Test.CollocationOptimized"] == "1") + test(proxyProps["Test.EncodingVersion"] == "1.0") test(proxyProps["Test.ConnectionCached"] == "1") test(proxyProps["Test.PreferSecure"] == "0") test(proxyProps["Test.EndpointSelection"] == "Ordered") @@ -311,6 +333,7 @@ def allTests(communicator) test(proxyProps["Test.Locator"] == "locator -t") #test(proxyProps["Test.Locator.CollocationOptimized"] == "1") + test(proxyProps["Test.Locator.EncodingVersion"] == Ice::encodingVersionToString(Ice::currentEncoding())) test(proxyProps["Test.Locator.ConnectionCached"] == "0") test(proxyProps["Test.Locator.PreferSecure"] == "1") test(proxyProps["Test.Locator.EndpointSelection"] == "Random") @@ -318,11 +341,18 @@ def allTests(communicator) test(proxyProps["Test.Locator.Router"] == "router -t") #test(proxyProps["Test.Locator.Router.CollocationOptimized"] == "0") + test(proxyProps["Test.Locator.Router.EncodingVersion"] == Ice::encodingVersionToString(Ice::currentEncoding())) 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") + begin + b1.ice_encodingVersion(Ice::EncodingVersion.new(3, 4)) + test(false) + rescue Ice::UnsupportedEncodingException + end + puts "ok" print "testing ice_getCommunicator... " @@ -332,143 +362,147 @@ def allTests(communicator) 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(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) puts "ok" - print "testing proxy comparison... ", + 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"))); + 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"); + 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_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_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_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_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_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)); + compObj.ice_endpointSelection(Ice::EndpointSelectionType::Random)) test(compObj.ice_endpointSelection(Ice::EndpointSelectionType::Random) != \ - compObj.ice_endpointSelection(Ice::EndpointSelectionType::Ordered)); + compObj.ice_endpointSelection(Ice::EndpointSelectionType::Ordered)) #test(compObj.ice_endpointSelection(Ice::EndpointSelectionType::Random) < \ - # compObj.ice_endpointSelection(Ice::EndpointSelectionType::Ordered)); + # 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))); + # 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))); + 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"; + 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))); + 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))); + 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))); - - 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)); + 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))) + + 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() @@ -477,6 +511,11 @@ def allTests(communicator) #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. # @@ -528,135 +567,145 @@ def allTests(communicator) begin # Invalid -x option - p = communicator.stringToProxy("id:opaque -t 99 -v abc -x abc"); - test(false); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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:opaque -t 1 -v CTEyNy4wLjAuMeouAAAQJwAAAA=="); - pstr = communicator.proxyToString(p1); - test(pstr == "test -t:tcp -h 127.0.0.1 -p 12010 -t 10000"); + p1 = communicator.stringToProxy("test:opaque -t 1 -e 1.0 -v CTEyNy4wLjAuMeouAAAQJwAAAA==") + pstr = communicator.proxyToString(p1) + test(pstr == "test -t:tcp -h 127.0.0.1 -p 12010 -t 10000") + + # 1.1 TCP endpoint encoded with 1.1 encoding. + p2 = communicator.stringToProxy("test:opaque -e 1.1 -t 1 -v CTEyNy4wLjAuMeouAAAQJwAAAAEAAQE=") + test(communicator.proxyToString(p2) == "test -t:tcp -e 1.1 -h 127.0.0.1 -p 12010 -t 10000") + + # 1.0 TCP endpoint encoded with 1.1 encoding. + p2 = communicator.stringToProxy("test: opaque -t 1 -e 1.1 -v CTEyNy4wLjAuMeouAAAQJwAAAAEAAQA=") + test(communicator.proxyToString(p2) == "test -t: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"; + ssl = communicator.getProperties().getProperty("Ice.Default.Protocol") == "ssl" + if !ssl + p1.ice_encodingVersion(Ice::Encoding_1_0).ice_ping() + end + + # Two legal TCP endpoints expressed as opaque endpoints + p1 = communicator.stringToProxy("test:opaque -t 1 -e 1.0 -v CTEyNy4wLjAuMeouAAAQJwAAAA==:opaque -t 1 -e 1.0 -v CTEyNy4wLjAuMusuAAAQJwAAAA==") + pstr = communicator.proxyToString(p1) + test(pstr == "test -t: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:opaque -t 2 -e 1.0 -v CTEyNy4wLjAuMREnAAD/////AA==:opaque -t 99 -e 1.0 -v abch") + pstr = communicator.proxyToString(p1) if !ssl - p1.ice_ping(); + test(pstr == "test -t:opaque -t 2 -e 1.0 -v CTEyNy4wLjAuMREnAAD/////AA==:opaque -t 99 -e 1.0 -v abch") + else + test(pstr == "test -t:ssl -h 127.0.0.1 -p 10001:opaque -t 99 -v abch") end - # Two legal TCP endpoints expressed as opaque endpoints - p1 = communicator.stringToProxy("test:opaque -t 1 -v CTEyNy4wLjAuMeouAAAQJwAAAA==:opaque -t 1 -v CTEyNy4wLjAuMusuAAAQJwAAAA=="); - pstr = communicator.proxyToString(p1); - test(pstr == "test -t: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:opaque -t 2 -v CTEyNy4wLjAuMREnAAD/////AA==:opaque -t 99 -v abch"); - pstr = communicator.proxyToString(p1); - if !ssl - test(pstr == "test -t:opaque -t 2 -v CTEyNy4wLjAuMREnAAD/////AA==:opaque -t 99 -v abch"); - else - test(pstr == "test -t:ssl -h 127.0.0.1 -p 10001:opaque -t 99 -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_ping(); - test(false); - rescue Ice::NoEndpointException - rescue Ice::ConnectionRefusedException - 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:opaque -t 2 -v CTEyNy4wLjAuMREnAAD/////AA==:opaque -t 99 -v abch"); - else - test(pstr == "test -t:ssl -h 127.0.0.1 -p 10001:opaque -t 99 -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(ssl) + 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:opaque -t 2 -e 1.0 -v CTEyNy4wLjAuMREnAAD/////AA==:opaque -t 99 -e 1.0 -v abch") + else + test(pstr == "test -t:ssl -h 127.0.0.1 -p 10001:opaque -t 99 -e 1.0 -v abch") + end end puts "ok" diff --git a/rb/test/Ice/slicing/exceptions/AllTests.rb b/rb/test/Ice/slicing/exceptions/AllTests.rb index 83833f46a4e..489135ba803 100644 --- a/rb/test/Ice/slicing/exceptions/AllTests.rb +++ b/rb/test/Ice/slicing/exceptions/AllTests.rb @@ -7,7 +7,7 @@ # # ********************************************************************** -Ice::loadSlice('Test.ice') +Ice::loadSlice('-I. --all ClientPrivate.ice') def test(b) if !b @@ -200,5 +200,75 @@ def allTests(communicator) 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::MarshalException + # + # A MarshalException 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/rb/test/Ice/slicing/exceptions/ClientPrivate.ice b/rb/test/Ice/slicing/exceptions/ClientPrivate.ice new file mode 100644 index 00000000000..029e6d5d37e --- /dev/null +++ b/rb/test/Ice/slicing/exceptions/ClientPrivate.ice @@ -0,0 +1,32 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2012 ZeroC, Inc. 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 PreservedClass extends BaseClass +{ + string pc; +}; + +exception Preserved1 extends KnownPreservedDerived +{ + BaseClass p1; +}; + +exception Preserved2 extends Preserved1 +{ + BaseClass p2; +}; + +}; diff --git a/rb/test/Ice/slicing/exceptions/Test.ice b/rb/test/Ice/slicing/exceptions/Test.ice index 1c92fe0fbcf..e558935d440 100644 --- a/rb/test/Ice/slicing/exceptions/Test.ice +++ b/rb/test/Ice/slicing/exceptions/Test.ice @@ -32,7 +32,35 @@ exception KnownMostDerived extends KnownIntermediate string kmd; }; -["ami"] interface TestIntf +["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; @@ -50,6 +78,20 @@ exception KnownMostDerived extends KnownIntermediate 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/rb/test/Ice/slicing/exceptions/run.py b/rb/test/Ice/slicing/exceptions/run.py index bdd3cf18408..9fde25714bd 100755 --- a/rb/test/Ice/slicing/exceptions/run.py +++ b/rb/test/Ice/slicing/exceptions/run.py @@ -20,5 +20,7 @@ if len(path) == 0: 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/rb/test/Ice/slicing/objects/AllTests.rb b/rb/test/Ice/slicing/objects/AllTests.rb index e0b604078ad..8e753e18057 100644 --- a/rb/test/Ice/slicing/objects/AllTests.rb +++ b/rb/test/Ice/slicing/objects/AllTests.rb @@ -79,6 +79,30 @@ def allTests(communicator) 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::MarshalException + # Expected. + rescue + test(false) + end + end puts "ok" print "unknown with Object as Object... " @@ -447,7 +471,7 @@ def allTests(communicator) print "sequence slicing... " STDOUT.flush begin - ss = Test::SS.new + ss = Test::SS3.new ss1b = Test::B.new ss1b.sb = "B.sb" ss1b.pb = ss1b @@ -656,5 +680,146 @@ def allTests(communicator) 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 + + # + # Send an object that will have multiple preserved slices in the server. + # The object will be sliced to Preserved 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::Preserved)) + 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/rb/test/Ice/slicing/objects/ClientPrivate.ice b/rb/test/Ice/slicing/objects/ClientPrivate.ice index b4e22a0d495..f8708d424c3 100644 --- a/rb/test/Ice/slicing/objects/ClientPrivate.ice +++ b/rb/test/Ice/slicing/objects/ClientPrivate.ice @@ -20,4 +20,25 @@ class D3 extends B 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; +}; + }; diff --git a/rb/test/Ice/slicing/objects/Test.ice b/rb/test/Ice/slicing/objects/Test.ice index 509a6544f25..8e20db55def 100644 --- a/rb/test/Ice/slicing/objects/Test.ice +++ b/rb/test/Ice/slicing/objects/Test.ice @@ -46,7 +46,7 @@ class SS2 BSeq s; }; -struct SS +struct SS3 { SS1 c1; SS2 c2; @@ -66,9 +66,39 @@ exception DerivedException extends BaseException D1 pd1; }; -class Forward; // Forward-declared class defined in another compilation unit +class Forward; /* Forward-declared class defined in another compilation unit */ -["ami"] interface TestIntf +class PBase +{ + int pi; +}; + +sequence<PBase> PBaseSeq; + +["preserve-slice"] +class Preserved extends PBase +{ + string ps; +}; + +class PDerived extends Preserved +{ + PBase pb; +}; + +["preserve-slice"] +class PNode +{ + PNode next; +}; + +["preserve-slice"] +exception PreservedException +{ +}; + +["format:sliced"] +interface TestIntf { Object SBaseAsObject(); SBase SBaseAsSBase(); @@ -77,6 +107,8 @@ class Forward; // Forward-declared class defined in another compilation SBase SBSUnknownDerivedAsSBase(); + ["format:compact"] SBase SBSUnknownDerivedAsSBaseCompact(); + Object SUnknownAsObject(); B oneElementCycle(); @@ -94,14 +126,28 @@ class Forward; // Forward-declared class defined in another compilation B returnTest2(out B p2, out B p1); B returnTest3(B p1, B p2); - SS sequenceTest(SS1 p1, SS2 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. */ diff --git a/rb/test/Ice/slicing/objects/run.py b/rb/test/Ice/slicing/objects/run.py index bdd3cf18408..9fde25714bd 100755 --- a/rb/test/Ice/slicing/objects/run.py +++ b/rb/test/Ice/slicing/objects/run.py @@ -20,5 +20,7 @@ if len(path) == 0: 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") |