diff options
author | Benoit Foucher <benoit@zeroc.com> | 2009-11-23 13:28:08 +0100 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2009-11-23 13:28:08 +0100 |
commit | 2c578015edcb36cdc0acd0227295de1dcca1b995 (patch) | |
tree | e163980b5dabb43a40089a29fdf8ff47a3e07f1c /cpp/test/Ice/exceptions/AllTests.cpp | |
parent | no longer generating inspect method for each Ruby exception (diff) | |
download | ice-2c578015edcb36cdc0acd0227295de1dcca1b995.tar.bz2 ice-2c578015edcb36cdc0acd0227295de1dcca1b995.tar.xz ice-2c578015edcb36cdc0acd0227295de1dcca1b995.zip |
New AMI mapping
Diffstat (limited to 'cpp/test/Ice/exceptions/AllTests.cpp')
-rw-r--r-- | cpp/test/Ice/exceptions/AllTests.cpp | 542 |
1 files changed, 513 insertions, 29 deletions
diff --git a/cpp/test/Ice/exceptions/AllTests.cpp b/cpp/test/Ice/exceptions/AllTests.cpp index 6384e231699..1e36c4dae0e 100644 --- a/cpp/test/Ice/exceptions/AllTests.cpp +++ b/cpp/test/Ice/exceptions/AllTests.cpp @@ -563,6 +563,309 @@ public: typedef IceUtil::Handle<AMI_WrongOperation_noSuchOperationI> AMI_WrongOperation_noSuchOperationIPtr; +class Callback : public CallbackBase, public IceUtil::Shared +{ +public: + + Callback() + { + } + + Callback(const Ice::CommunicatorPtr& c) + : _communicator(c) + { + } + + virtual void response() + { + test(false); + } + + virtual void exception_AasA(const Ice::Exception& exc) + { + const A* ex = dynamic_cast<const A*>(&exc); + test(ex); + test(ex->aMem == 1); + called(); + } + + virtual void exception_AorDasAorD(const Ice::Exception& exc) + { + try + { + exc.ice_throw(); + } + catch(const A& ex) + { + test(ex.aMem == 1); + } + catch(const D& ex) + { + test(ex.dMem == -1); + } + catch(...) + { + test(false); + } + called(); + } + + virtual void exception_BasB(const Ice::Exception& exc) + { + try + { + exc.ice_throw(); + } + catch(const B& ex) + { + test(ex.aMem == 1); + test(ex.bMem == 2); + } + catch(...) + { + test(false); + } + called(); + } + + virtual void exception_CasC(const Ice::Exception& exc) + { + try + { + exc.ice_throw(); + } + catch(const C& ex) + { + test(ex.aMem == 1); + test(ex.bMem == 2); + test(ex.cMem == 3); + } + catch(...) + { + test(false); + } + called(); + } + + virtual void exception_ModA(const Ice::Exception& exc) + { + try + { + exc.ice_throw(); + } + catch(const Mod::A& ex) + { + test(ex.aMem == 1); + test(ex.a2Mem == 2); + } + catch(const Ice::OperationNotExistException&) + { + // + // This operation is not supported in Java. + // + } + catch(...) + { + test(false); + } + called(); + } + + virtual void exception_BasA(const Ice::Exception& exc) + { + try + { + exc.ice_throw(); + } + catch(const B& ex) + { + test(ex.aMem == 1); + test(ex.bMem == 2); + } + catch(...) + { + test(false); + } + called(); + } + + virtual void exception_CasA(const Ice::Exception& exc) + { + try + { + exc.ice_throw(); + } + catch(const C& ex) + { + test(ex.aMem == 1); + test(ex.bMem == 2); + test(ex.cMem == 3); + } + catch(...) + { + test(false); + } + called(); + } + + virtual void exception_CasB(const Ice::Exception& exc) + { + try + { + exc.ice_throw(); + } + catch(const C& ex) + { + test(ex.aMem == 1); + test(ex.bMem == 2); + test(ex.cMem == 3); + } + catch(...) + { + test(false); + } + called(); + } + + virtual void exception_UndeclaredA(const Ice::Exception& exc) + { + try + { + exc.ice_throw(); + } + catch(const Ice::UnknownUserException&) + { + } + catch(...) + { + test(false); + } + called(); + } + + virtual void exception_UndeclaredB(const Ice::Exception& exc) + { + try + { + exc.ice_throw(); + } + catch(const Ice::UnknownUserException&) + { + } + catch(...) + { + test(false); + } + called(); + } + + virtual void exception_UndeclaredC(const Ice::Exception& exc) + { + try + { + exc.ice_throw(); + } + catch(const Ice::UnknownUserException&) + { + } + catch(...) + { + test(false); + } + called(); + } + + virtual void exception_AasAObjectNotExist(const Ice::Exception& exc) + { + try + { + exc.ice_throw(); + } + catch(const Ice::ObjectNotExistException& ex) + { + Ice::Identity id = _communicator->stringToIdentity("does not exist"); + test(ex.id == id); + } + catch(...) + { + test(false); + } + called(); + } + + virtual void exception_AasAFacetNotExist(const Ice::Exception& exc) + { + try + { + exc.ice_throw(); + } + catch(const Ice::FacetNotExistException& ex) + { + test(ex.facet == "no such facet"); + } + catch(...) + { + test(false); + } + called(); + } + + virtual void exception_noSuchOperation(const Ice::Exception& exc) + { + try + { + exc.ice_throw(); + } + catch(const Ice::OperationNotExistException& ex) + { + test(ex.operation == "noSuchOperation"); + } + catch(...) + { + test(false); + } + called(); + } + + virtual void exception_LocalException(const Ice::Exception& exc) + { + try + { + exc.ice_throw(); + } + catch(const Ice::UnknownLocalException&) + { + } + catch(...) + { + test(false); + } + called(); + } + + virtual void exception_NonIceException(const Ice::Exception& exc) + { + try + { + exc.ice_throw(); + } + catch(const Ice::UnknownException&) + { + } + catch(...) + { + test(false); + } + called(); + } + +private: + + Ice::CommunicatorPtr _communicator; +}; + +typedef IceUtil::Handle<Callback> CallbackPtr; + ThrowerPrx allTests(const Ice::CommunicatorPtr& communicator, bool collocated) { @@ -640,7 +943,7 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) try { - Ice::ObjectAdapterPtr second = + Ice::ObjectAdapterPtr second = communicator->createObjectAdapterWithEndpoints("TestAdapter0", "ssl -h foo -p 12011"); test(false); } @@ -651,7 +954,7 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) first->deactivate(); } cout << "ok" << endl; - + cout << "testing servant registration exceptions... " << flush; { communicator->getProperties()->setProperty("TestAdapter1.Endpoints", "default"); @@ -894,7 +1197,7 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) cout << "ok" << endl; cout << "catching derived types... " << flush; - + try { thrower->throwBasA(1, 2); @@ -947,7 +1250,7 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) if(thrower->supportsUndeclaredExceptions()) { cout << "catching unknown user exception... " << flush; - + try { thrower->throwUndeclaredA(1); @@ -966,7 +1269,7 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) { test(false); } - + try { thrower->throwUndeclaredB(1, 2); @@ -979,7 +1282,7 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) { test(false); } - + try { thrower->throwUndeclaredC(1, 2, 3); @@ -992,7 +1295,7 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) { test(false); } - + cout << "ok" << endl; } @@ -1016,7 +1319,7 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) } cout << "ok" << endl; - + cout << "catching facet not exist exception... " << flush; try @@ -1038,7 +1341,7 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) } cout << "ok" << endl; - + cout << "catching operation not exist exception... " << flush; try @@ -1057,7 +1360,7 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) } cout << "ok" << endl; - + cout << "catching unknown local exception... " << flush; try @@ -1074,9 +1377,9 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) } cout << "ok" << endl; - + cout << "catching unknown non-Ice exception... " << flush; - + try { thrower->throwNonIceException(); @@ -1089,7 +1392,7 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) { test(false); } - + cout << "ok" << endl; if(!collocated) @@ -1104,25 +1407,25 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) thrower->throwAasA_async(cb, 1); cb->check(); } - + { AMI_Thrower_throwAorDasAorDIPtr cb = new AMI_Thrower_throwAorDasAorDI; thrower->throwAorDasAorD_async(cb, 1); cb->check(); } - + { AMI_Thrower_throwAorDasAorDIPtr cb = new AMI_Thrower_throwAorDasAorDI; thrower->throwAorDasAorD_async(cb, -1); cb->check(); } - + { AMI_Thrower_throwBasBIPtr cb = new AMI_Thrower_throwBasBI; thrower->throwBasB_async(cb, 1, 2); cb->check(); } - + { AMI_Thrower_throwCasCIPtr cb = new AMI_Thrower_throwCasCI; thrower->throwCasC_async(cb, 1, 2, 3); @@ -1131,7 +1434,7 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) thrower->throwCasC_async(cb, 1, 2, 3); cb->check(); } - + #if (!defined(_MSC_VER) || _MSC_VER >= 1300) // // With VC6 SP5, there is no way to call ::A::__write from ::Mod::A @@ -1144,9 +1447,9 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) #endif cout << "ok" << endl; - + cout << "catching derived types... " << flush; - + { AMI_Thrower_throwBasAIPtr cb = new AMI_Thrower_throwBasAI; thrower->throwBasA_async(cb, 1, 2); @@ -1158,19 +1461,19 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) thrower->throwCasA_async(cb, 1, 2, 3); cb->check(); } - + { AMI_Thrower_throwCasBIPtr cb = new AMI_Thrower_throwCasBI; thrower->throwCasB_async(cb, 1, 2, 3); cb->check(); } - + cout << "ok" << endl; if(thrower->supportsUndeclaredExceptions()) { cout << "catching unknown user exception with AMI... " << flush; - + { AMI_Thrower_throwUndeclaredAIPtr cb = new AMI_Thrower_throwUndeclaredAI; thrower->throwUndeclaredA_async(cb, 1); @@ -1188,7 +1491,7 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) thrower->throwUndeclaredC_async(cb, 1, 2, 3); cb->check(); } - + cout << "ok" << endl; } @@ -1225,7 +1528,7 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) } cout << "ok" << endl; - + cout << "catching unknown local exception with AMI... " << flush; { @@ -1233,17 +1536,198 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) thrower->throwLocalException_async(cb); cb->check(); } - + cout << "ok" << endl; cout << "catching unknown non-Ice exception with AMI... " << flush; - + AMI_Thrower_throwNonIceExceptionIPtr cb = new AMI_Thrower_throwNonIceExceptionI; thrower->throwNonIceException_async(cb); cb->check(); - + cout << "ok" << endl; - + + cout << "catching exact types with new AMI mapping... " << flush; + + { + CallbackPtr cb = new Callback; + Callback_Thrower_throwAasAPtr callback = + newCallback_Thrower_throwAasA(cb, &Callback::response, &Callback::exception_AasA); + thrower->begin_throwAasA(1, callback); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + Callback_Thrower_throwAorDasAorDPtr callback = + newCallback_Thrower_throwAorDasAorD(cb, &Callback::response, &Callback::exception_AorDasAorD); + thrower->begin_throwAorDasAorD(1, callback); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + Callback_Thrower_throwAorDasAorDPtr callback = + newCallback_Thrower_throwAorDasAorD(cb, &Callback::response, &Callback::exception_AorDasAorD); + thrower->begin_throwAorDasAorD(-1, callback); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + Callback_Thrower_throwBasBPtr callback = + newCallback_Thrower_throwBasB(cb, &Callback::response, &Callback::exception_BasB); + thrower->begin_throwBasB(1, 2, callback); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + Callback_Thrower_throwCasCPtr callback = + newCallback_Thrower_throwCasC(cb, &Callback::response, &Callback::exception_CasC); + thrower->begin_throwCasC(1, 2, 3, callback); + cb->check(); + } + +#if (!defined(_MSC_VER) || _MSC_VER >= 1300) +// +// With VC6 SP5, there is no way to call ::A::__write from ::Mod::A +// + { + CallbackPtr cb = new Callback; + Callback_Thrower_throwModAPtr callback = + newCallback_Thrower_throwModA(cb, &Callback::response, &Callback::exception_ModA); + thrower->begin_throwModA(1, 2, callback); + cb->check(); + } +#endif + + cout << "ok" << endl; + + cout << "catching derived types with new AMI mapping... " << flush; + + { + CallbackPtr cb = new Callback; + Callback_Thrower_throwBasAPtr callback = + newCallback_Thrower_throwBasA(cb, &Callback::response, &Callback::exception_BasA); + thrower->begin_throwBasA(1, 2, callback); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + Callback_Thrower_throwCasAPtr callback = + newCallback_Thrower_throwCasA(cb, &Callback::response, &Callback::exception_CasA); + thrower->begin_throwCasA(1, 2, 3, callback); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + Callback_Thrower_throwCasBPtr callback = + newCallback_Thrower_throwCasB(cb, &Callback::response, &Callback::exception_CasB); + thrower->begin_throwCasB(1, 2, 3, callback); + cb->check(); + } + + cout << "ok" << endl; + + if(thrower->supportsUndeclaredExceptions()) + { + cout << "catching unknown user exception with new AMI mapping... " << flush; + + { + CallbackPtr cb = new Callback; + Callback_Thrower_throwUndeclaredAPtr callback = + newCallback_Thrower_throwUndeclaredA(cb, &Callback::response, &Callback::exception_UndeclaredA); + thrower->begin_throwUndeclaredA(1, callback); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + Callback_Thrower_throwUndeclaredBPtr callback = + newCallback_Thrower_throwUndeclaredB(cb, &Callback::response, &Callback::exception_UndeclaredB); + thrower->begin_throwUndeclaredB(1, 2, callback); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + Callback_Thrower_throwUndeclaredCPtr callback = + newCallback_Thrower_throwUndeclaredC(cb, &Callback::response, &Callback::exception_UndeclaredC); + thrower->begin_throwUndeclaredC(1, 2, 3, callback); + cb->check(); + } + + cout << "ok" << endl; + } + + cout << "catching object not exist exception with new AMI mapping... " << flush; + + { + id = communicator->stringToIdentity("does not exist"); + ThrowerPrx thrower2 = ThrowerPrx::uncheckedCast(thrower->ice_identity(id)); + CallbackPtr cb = new Callback(communicator); + Callback_Thrower_throwAasAPtr callback = + newCallback_Thrower_throwAasA(cb, &Callback::response, &Callback::exception_AasAObjectNotExist); + thrower2->begin_throwAasA(1, callback); + cb->check(); + } + + cout << "ok" << endl; + + cout << "catching facet not exist exception with new AMI mapping... " << flush; + + thrower2 = ThrowerPrx::uncheckedCast(thrower, "no such facet"); + { + CallbackPtr cb = new Callback; + Callback_Thrower_throwAasAPtr callback = + newCallback_Thrower_throwAasA(cb, &Callback::response, &Callback::exception_AasAFacetNotExist); + thrower2->begin_throwAasA(1, callback); + cb->check(); + } + + cout << "ok" << endl; + + cout << "catching operation not exist exception with new AMI mapping... " << flush; + + { + CallbackPtr cb = new Callback; + Callback_WrongOperation_noSuchOperationPtr callback = + newCallback_WrongOperation_noSuchOperation(cb, &Callback::response, + &Callback::exception_noSuchOperation); + WrongOperationPrx thrower4 = WrongOperationPrx::uncheckedCast(thrower); + thrower4->begin_noSuchOperation(callback); + cb->check(); + } + + cout << "ok" << endl; + + cout << "catching unknown local exception with new AMI mapping... " << flush; + + { + CallbackPtr cb = new Callback; + Callback_Thrower_throwLocalExceptionPtr callback = + newCallback_Thrower_throwLocalException(cb, &Callback::response, &Callback::exception_LocalException); + thrower->begin_throwLocalException(callback); + cb->check(); + } + + cout << "ok" << endl; + + cout << "catching unknown non-Ice exception with AMI... " << flush; + + { + CallbackPtr cb = new Callback; + Callback_Thrower_throwNonIceExceptionPtr callback = + newCallback_Thrower_throwNonIceException(cb, &Callback::response, &Callback::exception_NonIceException); + thrower->begin_throwNonIceException(callback); + cb->check(); + } + + cout << "ok" << endl; + } return thrower; |