summaryrefslogtreecommitdiff
path: root/cpp/test/Ice/slicing/exceptions/AllTests.cpp
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2012-05-08 18:14:39 -0700
committerMark Spruiell <mes@zeroc.com>2012-05-08 18:14:39 -0700
commit7774bb92669779fd165a0510a360fdaecd69f0c3 (patch)
tree8ea8bba6cac4128cd3e511ff21534db130ff8e49 /cpp/test/Ice/slicing/exceptions/AllTests.cpp
parentFixed ICE-4709, batch requests and UnmarshalOutOfBoundsException (diff)
downloadice-7774bb92669779fd165a0510a360fdaecd69f0c3.tar.bz2
ice-7774bb92669779fd165a0510a360fdaecd69f0c3.tar.xz
ice-7774bb92669779fd165a0510a360fdaecd69f0c3.zip
* C++ implementation for compact/sliced formats
* C++ implementation for "preserve-slice" metadata * C++ tests for compact/sliced/preserved types * Updated stream API * Python changes for stream API * Python tests for compact/sliced formats * Added Ice.Default.SlicedFormat property
Diffstat (limited to 'cpp/test/Ice/slicing/exceptions/AllTests.cpp')
-rw-r--r--cpp/test/Ice/slicing/exceptions/AllTests.cpp170
1 files changed, 167 insertions, 3 deletions
diff --git a/cpp/test/Ice/slicing/exceptions/AllTests.cpp b/cpp/test/Ice/slicing/exceptions/AllTests.cpp
index d39d298b66e..d1102c0dd7e 100644
--- a/cpp/test/Ice/slicing/exceptions/AllTests.cpp
+++ b/cpp/test/Ice/slicing/exceptions/AllTests.cpp
@@ -9,7 +9,7 @@
#include <Ice/Ice.h>
#include <TestCommon.h>
-#include <Test.h>
+#include <ClientPrivate.h>
using namespace std;
using namespace Test;
@@ -52,7 +52,6 @@ private:
bool _called;
};
-
class Callback : public CallbackBase, public IceUtil::Shared
{
public:
@@ -322,9 +321,47 @@ public:
called();
}
};
-
typedef IceUtil::Handle<Callback> CallbackPtr;
+class RelayI : public Relay
+{
+ virtual void knownPreservedAsBase(const ::Ice::Current&)
+ {
+ KnownPreserved ex;
+ ex.b = "base";
+ ex.kp = "preserved";
+ throw ex;
+ }
+
+ virtual void knownPreservedAsKnownPreserved(const ::Ice::Current&)
+ {
+ KnownPreserved ex;
+ ex.b = "base";
+ ex.kp = "preserved";
+ throw ex;
+ }
+
+ virtual void unknownPreservedAsBase(const ::Ice::Current&)
+ {
+ Preserved2 ex;
+ ex.b = "base";
+ ex.kp = "preserved";
+ ex.p1 = new PreservedClass("bc", "pc");
+ ex.p2 = ex.p1;
+ throw ex;
+ }
+
+ virtual void unknownPreservedAsKnownPreserved(const ::Ice::Current&)
+ {
+ Preserved2 ex;
+ ex.b = "base";
+ ex.kp = "preserved";
+ ex.p1 = new PreservedClass("bc", "pc");
+ ex.p2 = ex.p1;
+ throw ex;
+ }
+};
+
TestIntfPrx
allTests(const Ice::CommunicatorPtr& communicator)
{
@@ -718,5 +755,132 @@ allTests(const Ice::CommunicatorPtr& communicator)
}
cout << "ok" << endl;
+ cout << "unknown most derived in compact format... " << flush;
+ {
+ try
+ {
+ test->unknownMostDerived2AsBaseCompact();
+ test(false);
+ }
+ catch(const Base&)
+ {
+ //
+ // For the 1.0 encoding, the unknown exception is sliced to Base.
+ //
+ test(test->ice_getEncodingVersion() == Ice::Encoding_1_0);
+ }
+ catch(const Ice::MarshalException&)
+ {
+ //
+ // A MarshalException is raised for the compact format because the
+ // most-derived type is unknown and the exception cannot be sliced.
+ //
+ test(test->ice_getEncodingVersion() != Ice::Encoding_1_0);
+ }
+ catch(...)
+ {
+ test(false);
+ }
+ }
+ cout << "ok" << endl;
+
+ cout << "preserved exceptions... " << flush;
+ {
+ Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapterWithEndpoints("Relay", "default");
+ RelayPrx relay = RelayPrx::uncheckedCast(adapter->addWithUUID(new RelayI));
+ adapter->activate();
+
+ try
+ {
+ test->relayKnownPreservedAsBase(relay);
+ test(false);
+ }
+ catch(const KnownPreserved& ex)
+ {
+ test(ex.b == "base");
+ test(ex.kp == "preserved");
+ }
+ catch(...)
+ {
+ test(false);
+ }
+
+ try
+ {
+ test->relayKnownPreservedAsKnownPreserved(relay);
+ test(false);
+ }
+ catch(const KnownPreserved& ex)
+ {
+ test(ex.b == "base");
+ test(ex.kp == "preserved");
+ }
+ catch(...)
+ {
+ test(false);
+ }
+
+ try
+ {
+ test->relayUnknownPreservedAsBase(relay);
+ test(false);
+ }
+ catch(const Preserved2& ex)
+ {
+ test(ex.b == "base");
+ test(ex.kp == "preserved");
+ 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)
+ {
+ //
+ // For the 1.0 encoding, the unknown exception is sliced to KnownPreserved.
+ //
+ test(test->ice_getEncodingVersion() == Ice::Encoding_1_0);
+ test(ex.b == "base");
+ test(ex.kp == "preserved");
+ }
+ catch(...)
+ {
+ test(false);
+ }
+
+ try
+ {
+ test->relayUnknownPreservedAsKnownPreserved(relay);
+ test(false);
+ }
+ catch(const Preserved2& ex)
+ {
+ test(ex.b == "base");
+ test(ex.kp == "preserved");
+ 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)
+ {
+ //
+ // For the 1.0 encoding, the unknown exception is sliced to KnownPreserved.
+ //
+ test(test->ice_getEncodingVersion() == Ice::Encoding_1_0);
+ test(ex.b == "base");
+ test(ex.kp == "preserved");
+ }
+ catch(...)
+ {
+ test(false);
+ }
+
+ adapter->destroy();
+ }
+ cout << "ok" << endl;
+
return test;
}