void oneways(const Ice::CommunicatorPtr& communicator, const Test::MyClassPrx& proxy) { Test::MyClassPrx p = Test::MyClassPrx::uncheckedCast(proxy->ice_oneway()); { p->ice_ping(); } { try { p->ice_isA("dummy"); test(false); } catch(const Ice::TwowayOnlyException&) { } } { try { p->ice_id(); test(false); } catch(const Ice::TwowayOnlyException&) { } } { try { p->ice_ids(); test(false); } catch(const Ice::TwowayOnlyException&) { } } { p->opVoid(); } { p->opIdempotent(); } { p->opNonmutating(); } { Ice::Byte b; try { p->opByte(Ice::Byte(0xff), Ice::Byte(0x0f), b); test(false); } catch(const Ice::TwowayOnlyException&) { } } }
void onewaysAMI(const Ice::CommunicatorPtr&, const Test::MyClassPrx& proxy) { Test::MyClassPrx p = Test::MyClassPrx::uncheckedCast(proxy->ice_oneway()); { CallbackPtr cb = new Callback; Ice::Callback_Object_ice_pingPtr callback = Ice::newCallback_Object_ice_ping(cb, &Callback::noException, &Callback::sent); p->begin_ice_ping(callback); cb->check(); } { try { p->begin_ice_isA(Test::MyClass::ice_staticId()); test(false); } catch(const IceUtil::IllegalArgumentException&) { } } { try { p->begin_ice_id(); test(false); } catch(const IceUtil::IllegalArgumentException&) { } } { try { p->begin_ice_ids(); test(false); } catch(const IceUtil::IllegalArgumentException&) { } } { CallbackPtr cb = new Callback; Test::Callback_MyClass_opVoidPtr callback = Test::newCallback_MyClass_opVoid(cb, &Callback::noException, &Callback::sent); p->begin_opVoid(callback); cb->check(); } { CallbackPtr cb = new Callback; Test::Callback_MyClass_opIdempotentPtr callback = Test::newCallback_MyClass_opIdempotent(cb, &Callback::noException, &Callback::sent); p->begin_opIdempotent(callback); cb->check(); } { CallbackPtr cb = new Callback; Test::Callback_MyClass_opNonmutatingPtr callback = Test::newCallback_MyClass_opNonmutating(cb, &Callback::noException, &Callback::sent); p->begin_opNonmutating(callback); cb->check(); } { try { p->begin_opByte(Ice::Byte(0xff), Ice::Byte(0x0f)); test(false); } catch(const IceUtil::IllegalArgumentException&) { } } #ifdef ICE_CPP11 { CallbackPtr cb = new Callback; p->begin_ice_ping(nullptr, [=](const Ice::Exception& ex){ cb->noException(ex); }, [=](bool sent){ cb->sent(sent); }); cb->check(); } { try { p->begin_ice_isA(Test::MyClass::ice_staticId(), [=](bool){ test(false); }); test(false); } catch(const IceUtil::IllegalArgumentException&) { } } { try { p->begin_ice_id([=](const string&){ test(false); }); test(false); } catch(const IceUtil::IllegalArgumentException&) { } } { try { p->begin_ice_ids([=](const Ice::StringSeq&){ test(false); }); test(false); } catch(const IceUtil::IllegalArgumentException&) { } } { CallbackPtr cb = new Callback; p->begin_opVoid(nullptr, [=](const Ice::Exception& ex){ cb->noException(ex); }, [=](bool sent){ cb->sent(sent); }); cb->check(); } { CallbackPtr cb = new Callback; p->begin_opIdempotent(nullptr, [=](const Ice::Exception& ex){ cb->noException(ex); }, [=](bool sent){ cb->sent(sent); }); cb->check(); } { CallbackPtr cb = new Callback; p->begin_opNonmutating(nullptr, [=](const Ice::Exception& ex){ cb->noException(ex); }, [=](bool sent){ cb->sent(sent); }); cb->check(); } { try { p->begin_opByte(Ice::Byte(0xff), Ice::Byte(0x0f), [=](const Ice::Byte&, const Ice::Byte&){ test(false); }); test(false); } catch(const IceUtil::IllegalArgumentException&) { } } #endif }
Test::MyClassPrx allTests(const Ice::CommunicatorPtr& communicator) { string ref = "test:default -p 12010"; Ice::ObjectPrx base = communicator->stringToProxy(ref); test(base); Test::MyClassPrx cl = Test::MyClassPrx::checkedCast(base); test(cl); Test::MyClassPrx oneway = cl->ice_oneway(); void (Callback::*nullEx)(const Ice::Exception&) = 0; void (Callback::*nullExWC)(const Ice::Exception&, const CookiePtr&) = 0; cout << "testing ice_invoke... " << flush; { Ice::ByteSeq inParams, outParams; if(!oneway->ice_invoke("opOneway", Ice::Normal, inParams, outParams)) { test(false); } Ice::OutputStreamPtr out = Ice::createOutputStream(communicator); out->write(testString); out->finished(inParams); // ice_invoke if(cl->ice_invoke("opString", Ice::Normal, inParams, outParams)) { Ice::InputStreamPtr in = Ice::createInputStream(communicator, outParams); string s; in->read(s); test(s == testString); in->read(s); test(s == testString); } else { test(false); } // ice_invoke with array mapping pair<const ::Ice::Byte*, const ::Ice::Byte*> inPair(&inParams[0], &inParams[0] + inParams.size()); if(cl->ice_invoke("opString", Ice::Normal, inPair, outParams)) { Ice::InputStreamPtr in = Ice::createInputStream(communicator, outParams); string s; in->read(s); test(s == testString); in->read(s); test(s == testString); } else { test(false); } } { Ice::ByteSeq inParams, outParams; if(cl->ice_invoke("opException", Ice::Normal, inParams, outParams)) { test(false); } else { Ice::InputStreamPtr in = Ice::createInputStream(communicator, outParams); try { in->throwException(); } catch(const Test::MyException&) { } catch(...) { test(false); } } } cout << "ok" << endl; cout << "testing asynchronous ice_invoke... " << flush; { CookiePtr cookie = new Cookie(); Ice::ByteSeq inParams, outParams; Ice::AsyncResultPtr result = oneway->begin_ice_invoke("opOneway", Ice::Normal, inParams); if(!oneway->end_ice_invoke(outParams, result)) { test(false); } Ice::OutputStreamPtr out = Ice::createOutputStream(communicator); out->write(testString); out->finished(inParams); // begin_ice_invoke with no callback result = cl->begin_ice_invoke("opString", Ice::Normal, inParams); if(cl->end_ice_invoke(outParams, result)) { Ice::InputStreamPtr in = Ice::createInputStream(communicator, outParams); string s; in->read(s); test(s == testString); in->read(s); test(s == testString); } else { test(false); }; // begin_ice_invoke with no callback and array mapping pair<const ::Ice::Byte*, const ::Ice::Byte*> inPair(&inParams[0], &inParams[0] + inParams.size()); result = cl->begin_ice_invoke("opString", Ice::Normal, inPair); if(cl->end_ice_invoke(outParams, result)) { Ice::InputStreamPtr in = Ice::createInputStream(communicator, outParams); string s; in->read(s); test(s == testString); in->read(s); test(s == testString); } else { test(false); }; // begin_ice_invoke with Callback CallbackPtr cb = new Callback(communicator, false); cl->begin_ice_invoke("opString", Ice::Normal, inParams, Ice::newCallback(cb, &Callback::opString)); cb->check(); // begin_ice_invoke with Callback and Cookie cb = new Callback(communicator, true); cl->begin_ice_invoke("opString", Ice::Normal, inParams, Ice::newCallback(cb, &Callback::opString), cookie); cb->check(); // begin_ice_invoke with Callback_Object_ice_invoke cb = new Callback(communicator, false); Ice::Callback_Object_ice_invokePtr d = Ice::newCallback_Object_ice_invoke(cb, &Callback::opStringNC, nullEx); cl->begin_ice_invoke("opString", Ice::Normal, inParams, d); cb->check(); // begin_ice_invoke with Callback_Object_ice_invoke with Cookie cb = new Callback(communicator, false); d = Ice::newCallback_Object_ice_invoke(cb, &Callback::opStringWC, nullExWC); cl->begin_ice_invoke("opString", Ice::Normal, inParams, d, cookie); cb->check(); // begin_ice_invoke with Callback_Object_ice_invoke and array mapping cb = new Callback(communicator, false); d = Ice::newCallback_Object_ice_invoke(cb, &Callback::opStringNC, nullEx); cl->begin_ice_invoke("opString", Ice::Normal, inPair, d); cb->check(); // begin_ice_invoke with Callback_Object_ice_invoke and array mapping with Cookie cb = new Callback(communicator, false); d = Ice::newCallback_Object_ice_invoke(cb, &Callback::opStringWC, nullExWC); cl->begin_ice_invoke("opString", Ice::Normal, inPair, d, cookie); cb->check(); } { CookiePtr cookie = new Cookie(); Ice::ByteSeq inParams, outParams; // begin_ice_invoke with no callback Ice::AsyncResultPtr result = cl->begin_ice_invoke("opException", Ice::Normal, inParams); if(cl->end_ice_invoke(outParams, result)) { test(false); } else { Ice::InputStreamPtr in = Ice::createInputStream(communicator, outParams); try { in->throwException(); } catch(const Test::MyException&) { } catch(...) { test(false); } } // begin_ice_invoke with Callback CallbackPtr cb = new Callback(communicator, false); cl->begin_ice_invoke("opException", Ice::Normal, inParams, Ice::newCallback(cb, &Callback::opException)); cb->check(); // begin_ice_invoke with Callback and Cookie cb = new Callback(communicator, true); cl->begin_ice_invoke("opException", Ice::Normal, inParams, Ice::newCallback(cb, &Callback::opException), cookie); cb->check(); // begin_ice_invoke with Callback_Object_ice_invoke cb = new Callback(communicator, false); Ice::Callback_Object_ice_invokePtr d = Ice::newCallback_Object_ice_invoke(cb, &Callback::opExceptionNC, nullEx); cl->begin_ice_invoke("opException", Ice::Normal, inParams, d); cb->check(); // begin_ice_invoke with Callback_Object_ice_invoke with Cookie cb = new Callback(communicator, false); d = Ice::newCallback_Object_ice_invoke(cb, &Callback::opExceptionWC, nullExWC); cl->begin_ice_invoke("opException", Ice::Normal, inParams, d, cookie); cb->check(); } cout << "ok" << endl; return cl; }