diff options
48 files changed, 2577 insertions, 836 deletions
diff --git a/cpp/allTests.py b/cpp/allTests.py index c713bb80dcb..58eeeef6a86 100755 --- a/cpp/allTests.py +++ b/cpp/allTests.py @@ -59,6 +59,7 @@ tests = [ ("Ice/stringConverter", ["core"]), ("Ice/udp", ["core"]), ("Ice/defaultServant", ["core"]), + ("Ice/invoke", ["core", "novc6"]), ("IceSSL/configuration", ["once", "novalgrind"]), # valgrind doesn't work well with openssl ("IceBox/configuration", ["core", "noipv6", "nobcc", "novc6"]), ("Freeze/dbmap", ["once", "novc6"]), diff --git a/cpp/demo/Ice/invoke/Client.cpp b/cpp/demo/Ice/invoke/Client.cpp index 4226899e60a..c13d94b57d0 100644 --- a/cpp/demo/Ice/invoke/Client.cpp +++ b/cpp/demo/Ice/invoke/Client.cpp @@ -31,106 +31,6 @@ operator<<(ostream& out, Demo::Color c) return out; } -class AMI_Object_ice_invokeI : public Ice::AMI_Object_ice_invoke -{ -public: - - virtual void - ice_response(bool result, const Ice::ByteSeq& outParams) - { - if(!result) - { - cout << "Unknown user exception" << endl; - } - } - - virtual void - ice_exception(const Ice::Exception& ex) - { - cout << ex << endl; - } -}; - -class AMI_Object_ice_invokeGetValuesI : public Ice::AMI_Object_ice_invoke -{ -public: - - AMI_Object_ice_invokeGetValuesI(const Ice::CommunicatorPtr& communicator) : - _communicator(communicator) - { - } - - virtual void - ice_response(bool result, const Ice::ByteSeq& outParams) - { - if(!result) - { - cout << "Unknown user exception" << endl; - } - else - { - // - // Unmarshal the results. - // - Ice::InputStreamPtr in = Ice::createInputStream(_communicator, outParams); - Demo::CPtr c; - in->read(c); - string str = in->readString(); - in->readPendingObjects(); - cout << "Got string `" << str << "' and class: s.name=" << c->s.name - << ", s.value=" << c->s.value << endl; - } - } - - virtual void - ice_exception(const Ice::Exception& ex) - { - cout << ex << endl; - } - -private: - - Ice::CommunicatorPtr _communicator; -}; - -class AMI_Object_ice_invokeThrowPrintFailureI : public Ice::AMI_Object_ice_invoke -{ -public: - - AMI_Object_ice_invokeThrowPrintFailureI(const Ice::CommunicatorPtr& communicator) : - _communicator(communicator) - { - } - - virtual void - ice_response(bool result, const Ice::ByteSeq& outParams) - { - Ice::InputStreamPtr in = Ice::createInputStream(_communicator, outParams); - try - { - in->throwException(); - } - catch(const Demo::PrintFailure&) - { - // Expected. - } - catch(const Ice::UserException&) - { - cout << "Unknown user exception" << endl; - } - } - - virtual void - ice_exception(const Ice::Exception& ex) - { - cout << ex << endl; - } - -private: - - Ice::CommunicatorPtr _communicator; -}; - class InvokeClient : public Ice::Application { public: @@ -163,14 +63,9 @@ InvokeClient::InvokeClient() : int InvokeClient::run(int argc, char* argv[]) { - bool async = false; - if(argc == 2 && strcmp(argv[1], "--async") == 0) - { - async = true; - } - else if(argc > 1) + if(argc > 1) { - cerr << "Usage: " << appName() << " [--async]" << endl; + cerr << appName() << ": too many arguments" << endl; return EXIT_FAILURE; } @@ -198,16 +93,9 @@ InvokeClient::run(int argc, char* argv[]) // // Invoke operation. // - if(async) - { - obj->ice_invoke_async(new AMI_Object_ice_invokeI(), "printString", Ice::Normal, inParams); - } - else + if(!obj->ice_invoke("printString", Ice::Normal, inParams, outParams)) { - if(!obj->ice_invoke("printString", Ice::Normal, inParams, outParams)) - { - cout << "Unknown user exception" << endl; - } + cout << "Unknown user exception" << endl; } } else if(ch == '2') @@ -228,16 +116,9 @@ InvokeClient::run(int argc, char* argv[]) // // Invoke operation. // - if(async) + if(!obj->ice_invoke("printStringSequence", Ice::Normal, inParams, outParams)) { - obj->ice_invoke_async(new AMI_Object_ice_invokeI(), "printStringSequence", Ice::Normal, inParams); - } - else - { - if(!obj->ice_invoke("printStringSequence", Ice::Normal, inParams, outParams)) - { - cout << "Unknown user exception" << endl; - } + cout << "Unknown user exception" << endl; } } else if(ch == '3') @@ -256,16 +137,9 @@ InvokeClient::run(int argc, char* argv[]) // // Invoke operation. // - if(async) + if(!obj->ice_invoke("printDictionary", Ice::Normal, inParams, outParams)) { - obj->ice_invoke_async(new AMI_Object_ice_invokeI(), "printDictionary", Ice::Normal, inParams); - } - else - { - if(!obj->ice_invoke("printDictionary", Ice::Normal, inParams, outParams)) - { - cout << "Unknown user exception" << endl; - } + cout << "Unknown user exception" << endl; } } else if(ch == '4') @@ -281,16 +155,9 @@ InvokeClient::run(int argc, char* argv[]) // // Invoke operation. // - if(async) - { - obj->ice_invoke_async(new AMI_Object_ice_invokeI(), "printEnum", Ice::Normal, inParams); - } - else + if(!obj->ice_invoke("printEnum", Ice::Normal, inParams, outParams)) { - if(!obj->ice_invoke("printEnum", Ice::Normal, inParams, outParams)) - { - cout << "Unknown user exception" << endl; - } + cout << "Unknown user exception" << endl; } } else if(ch == '5') @@ -309,16 +176,9 @@ InvokeClient::run(int argc, char* argv[]) // // Invoke operation. // - if(async) - { - obj->ice_invoke_async(new AMI_Object_ice_invokeI(), "printStruct", Ice::Normal, inParams); - } - else + if(!obj->ice_invoke("printStruct", Ice::Normal, inParams, outParams)) { - if(!obj->ice_invoke("printStruct", Ice::Normal, inParams, outParams)) - { - cout << "Unknown user exception" << endl; - } + cout << "Unknown user exception" << endl; } } else if(ch == '6') @@ -344,16 +204,9 @@ InvokeClient::run(int argc, char* argv[]) // // Invoke operation. // - if(async) + if(!obj->ice_invoke("printStructSequence", Ice::Normal, inParams, outParams)) { - obj->ice_invoke_async(new AMI_Object_ice_invokeI(), "printStructSequence", Ice::Normal, inParams); - } - else - { - if(!obj->ice_invoke("printStructSequence", Ice::Normal, inParams, outParams)) - { - cout << "Unknown user exception" << endl; - } + cout << "Unknown user exception" << endl; } } else if(ch == '7') @@ -373,16 +226,9 @@ InvokeClient::run(int argc, char* argv[]) // // Invoke operation. // - if(async) + if(!obj->ice_invoke("printClass", Ice::Normal, inParams, outParams)) { - obj->ice_invoke_async(new AMI_Object_ice_invokeI(), "printClass", Ice::Normal, inParams); - } - else - { - if(!obj->ice_invoke("printClass", Ice::Normal, inParams, outParams)) - { - cout << "Unknown user exception" << endl; - } + cout << "Unknown user exception" << endl; } } else if(ch == '8') @@ -391,30 +237,22 @@ InvokeClient::run(int argc, char* argv[]) // Invoke operation. // Ice::ByteSeq inParams, outParams; - if(async) + if(!obj->ice_invoke("getValues", Ice::Normal, inParams, outParams)) { - obj->ice_invoke_async(new AMI_Object_ice_invokeGetValuesI(communicator()), "getValues", - Ice::Normal, inParams); + cout << "Unknown user exception" << endl; + continue; } - else - { - if(!obj->ice_invoke("getValues", Ice::Normal, inParams, outParams)) - { - cout << "Unknown user exception" << endl; - continue; - } - // - // Unmarshal the results. - // - Ice::InputStreamPtr in = Ice::createInputStream(communicator(), outParams); - Demo::CPtr c; - in->read(c); - string str = in->readString(); - in->readPendingObjects(); - cout << "Got string `" << str << "' and class: s.name=" << c->s.name - << ", s.value=" << c->s.value << endl; - } + // + // Unmarshal the results. + // + Ice::InputStreamPtr in = Ice::createInputStream(communicator(), outParams); + Demo::CPtr c; + in->read(c); + string str = in->readString(); + in->readPendingObjects(); + cout << "Got string `" << str << "' and class: s.name=" << c->s.name + << ", s.value=" << c->s.value << endl; } else if(ch == '9') { @@ -422,46 +260,31 @@ InvokeClient::run(int argc, char* argv[]) // Invoke operation. // Ice::ByteSeq inParams, outParams; - if(async) + if(obj->ice_invoke("throwPrintFailure", Ice::Normal, inParams, outParams)) { - obj->ice_invoke_async(new AMI_Object_ice_invokeThrowPrintFailureI(communicator()), - "throwPrintFailure", Ice::Normal, inParams); + cout << "Expected exception" << endl; + continue; } - else - { - if(obj->ice_invoke("throwPrintFailure", Ice::Normal, inParams, outParams)) - { - cout << "Expected exception" << endl; - continue; - } - Ice::InputStreamPtr in = Ice::createInputStream(communicator(), outParams); - try - { - in->throwException(); - } - catch(const Demo::PrintFailure&) - { - // Expected. - } - catch(const Ice::UserException&) - { - cout << "Unknown user exception" << endl; - } + Ice::InputStreamPtr in = Ice::createInputStream(communicator(), outParams); + try + { + in->throwException(); } - } - else if(ch == 's') - { - Ice::ByteSeq inParams, outParams; - if(async) + catch(const Demo::PrintFailure&) { - obj->ice_invoke_async(new AMI_Object_ice_invokeI(), "shutdown", Ice::Normal, inParams); + // Expected. } - else + catch(const Ice::UserException&) { - obj->ice_invoke("shutdown", Ice::Normal, inParams, outParams); + cout << "Unknown user exception" << endl; } } + else if(ch == 's') + { + Ice::ByteSeq inParams, outParams; + obj->ice_invoke("shutdown", Ice::Normal, inParams, outParams); + } else if(ch == 'x') { // Nothing to do. diff --git a/cpp/demo/Ice/invoke/README b/cpp/demo/Ice/invoke/README index 8fc943163cc..76ca767d80b 100644 --- a/cpp/demo/Ice/invoke/README +++ b/cpp/demo/Ice/invoke/README @@ -7,7 +7,3 @@ $ server In a separate window, start the client: $ client - -To run the client using asynchronous calls use: - -$ client --async diff --git a/cpp/include/Ice/Object.h b/cpp/include/Ice/Object.h index c3170a88ff3..325ffa35ba3 100644 --- a/cpp/include/Ice/Object.h +++ b/cpp/include/Ice/Object.h @@ -146,7 +146,6 @@ class ICE_API BlobjectAsync : virtual public Object { public: - // Returns true if ok, false if user exception. virtual void ice_invoke_async(const AMD_Object_ice_invokePtr&, const std::vector<Byte>&, const Current&) = 0; virtual DispatchStatus __dispatch(IceInternal::Incoming&, const Current&); }; @@ -155,7 +154,6 @@ class ICE_API BlobjectArrayAsync : virtual public Object { public: - // Returns true if ok, false if user exception. virtual void ice_invoke_async(const AMD_Object_ice_invokePtr&, const std::pair<const Byte*, const Byte*>&, const Current&) = 0; virtual DispatchStatus __dispatch(IceInternal::Incoming&, const Current&); diff --git a/cpp/include/Ice/Proxy.h b/cpp/include/Ice/Proxy.h index 0fd5603a2d1..c3729e4826c 100644 --- a/cpp/include/Ice/Proxy.h +++ b/cpp/include/Ice/Proxy.h @@ -425,7 +425,7 @@ public: return begin_ice_invoke(operation, mode, inParams, &__ctx, __del, __cookie); } - bool end_ice_invoke(const ::Ice::AsyncResultPtr&, ::std::vector< ::Ice::Byte>&); + bool end_ice_invoke(::std::vector< ::Ice::Byte>&, const ::Ice::AsyncResultPtr&); bool ice_invoke(const ::std::string& operation, ::Ice::OperationMode mode, @@ -503,7 +503,7 @@ public: return begin_ice_invoke(operation, mode, inParams, &__ctx, __del, __cookie); } - bool end_ice_invoke(const ::Ice::AsyncResultPtr&, ::std::pair<const ::Ice::Byte*, const ::Ice::Byte*>&); + bool end_ice_invoke(::std::pair<const ::Ice::Byte*, const ::Ice::Byte*>&, const ::Ice::AsyncResultPtr&); ::Ice::Identity ice_getIdentity() const; ::Ice::ObjectPrx ice_identity(const ::Ice::Identity&) const; @@ -1590,7 +1590,7 @@ public: std::vector< ::Ice::Byte> outParams; try { - __ok = __result->getProxy()->end_ice_invoke(__result, outParams); + __ok = __result->getProxy()->end_ice_invoke(outParams, __result); } catch(const ::Ice::Exception& ex) { @@ -1615,7 +1615,7 @@ public: std::pair<const ::Ice::Byte*, const::Ice::Byte*> outParams; try { - __ok = __result->getProxy()->end_ice_invoke(__result, outParams); + __ok = __result->getProxy()->end_ice_invoke(outParams, __result); } catch(const ::Ice::Exception& ex) { @@ -1670,7 +1670,7 @@ public: std::vector< ::Ice::Byte> outParams; try { - __ok = __result->getProxy()->end_ice_invoke(__result, outParams); + __ok = __result->getProxy()->end_ice_invoke(outParams, __result); } catch(const ::Ice::Exception& ex) { @@ -1697,7 +1697,7 @@ public: std::pair<const ::Ice::Byte*, const::Ice::Byte*> outParams; try { - __ok = __result->getProxy()->end_ice_invoke(__result, outParams); + __ok = __result->getProxy()->end_ice_invoke(outParams, __result); } catch(const ::Ice::Exception& ex) { diff --git a/cpp/src/Ice/Proxy.cpp b/cpp/src/Ice/Proxy.cpp index e8e583cf78c..cb31063381e 100644 --- a/cpp/src/Ice/Proxy.cpp +++ b/cpp/src/Ice/Proxy.cpp @@ -468,7 +468,7 @@ IceProxy::Ice::Object::begin_ice_invoke(const string& operation, } bool -IceProxy::Ice::Object::end_ice_invoke(const AsyncResultPtr& __result, vector<Byte>& outParams) +IceProxy::Ice::Object::end_ice_invoke(vector<Byte>& outParams, const AsyncResultPtr& __result) { AsyncResult::__check(__result, this, ice_invoke_name); bool ok = __result->__wait(); @@ -592,7 +592,7 @@ IceProxy::Ice::Object::begin_ice_invoke(const string& operation, } bool -IceProxy::Ice::Object::end_ice_invoke(const AsyncResultPtr& __result, pair<const Byte*, const Byte*>& outParams) +IceProxy::Ice::Object::end_ice_invoke(pair<const Byte*, const Byte*>& outParams, const AsyncResultPtr& __result) { AsyncResult::__check(__result, this, ice_invoke_name); bool ok = __result->__wait(); diff --git a/cpp/test/Ice/Makefile b/cpp/test/Ice/Makefile index d4a2b82b556..c606bf3ef27 100644 --- a/cpp/test/Ice/Makefile +++ b/cpp/test/Ice/Makefile @@ -37,7 +37,8 @@ SUBDIRS = proxy \ background \ udp \ defaultServant \ - threadPoolPriority + threadPoolPriority \ + invoke $(EVERYTHING):: @for subdir in $(SUBDIRS); \ diff --git a/cpp/test/Ice/Makefile.mak b/cpp/test/Ice/Makefile.mak index fdeb3dfafd2..36f808dbec7 100644 --- a/cpp/test/Ice/Makefile.mak +++ b/cpp/test/Ice/Makefile.mak @@ -36,11 +36,12 @@ SUBDIRS = proxy \ background \
udp \
defaultServant \
- threadPoolPriority
+ threadPoolPriority \
!if "$(CPP_COMPILER)" != "VC60"
SUBDIRS = $(SUBDIRS) \
- stream
+ stream,
+ invoke
!endif
$(EVERYTHING)::
diff --git a/cpp/test/Ice/invoke/.depend b/cpp/test/Ice/invoke/.depend new file mode 100644 index 00000000000..f2177514ce0 --- /dev/null +++ b/cpp/test/Ice/invoke/.depend @@ -0,0 +1,8 @@ +Test$(OBJEXT): Test.cpp ./Test.h $(includedir)/Ice/LocalObjectF.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Config.h $(includedir)/Ice/Handle.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/Ice/Config.h $(includedir)/Ice/ProxyHandle.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/Ice/Proxy.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Time.h $(includedir)/IceUtil/MutexProtocol.h $(includedir)/Ice/ProxyFactoryF.h $(includedir)/Ice/ConnectionIF.h $(includedir)/Ice/RequestHandlerF.h $(includedir)/Ice/EndpointIF.h $(includedir)/Ice/EndpointF.h $(includedir)/IceUtil/ScopedArray.h $(includedir)/Ice/UndefSysMacros.h $(includedir)/Ice/EndpointTypes.h $(includedir)/Ice/ObjectAdapterF.h $(includedir)/Ice/ReferenceF.h $(includedir)/Ice/OutgoingAsync.h $(includedir)/IceUtil/Monitor.h $(includedir)/IceUtil/Cond.h $(includedir)/IceUtil/Timer.h $(includedir)/IceUtil/Thread.h $(includedir)/Ice/OutgoingAsyncF.h $(includedir)/Ice/InstanceF.h $(includedir)/Ice/CommunicatorF.h $(includedir)/Ice/Current.h $(includedir)/Ice/ConnectionF.h $(includedir)/Ice/Identity.h $(includedir)/Ice/BasicStream.h $(includedir)/Ice/ObjectFactoryF.h $(includedir)/Ice/Buffer.h $(includedir)/Ice/Protocol.h $(includedir)/Ice/StreamF.h $(includedir)/Ice/Object.h $(includedir)/Ice/IncomingAsyncF.h $(includedir)/Ice/Outgoing.h $(includedir)/Ice/Incoming.h $(includedir)/Ice/ServantLocatorF.h $(includedir)/Ice/ServantManagerF.h $(includedir)/Ice/Direct.h $(includedir)/Ice/FactoryTableInit.h $(includedir)/Ice/FactoryTable.h $(includedir)/IceUtil/StaticMutex.h $(includedir)/Ice/UserExceptionFactory.h $(includedir)/Ice/Stream.h $(includedir)/Ice/LocalException.h $(includedir)/Ice/BuiltinSequences.h $(includedir)/Ice/ObjectFactory.h $(includedir)/IceUtil/Iterator.h +Client$(OBJEXT): Client.cpp $(includedir)/Ice/Ice.h $(includedir)/Ice/Initialize.h $(includedir)/Ice/CommunicatorF.h $(includedir)/Ice/LocalObjectF.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Config.h $(includedir)/Ice/Handle.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/Ice/Config.h $(includedir)/Ice/ProxyHandle.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/IceUtil/ScopedArray.h $(includedir)/Ice/UndefSysMacros.h $(includedir)/Ice/PropertiesF.h $(includedir)/Ice/Proxy.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Time.h $(includedir)/IceUtil/MutexProtocol.h $(includedir)/Ice/ProxyFactoryF.h $(includedir)/Ice/ConnectionIF.h $(includedir)/Ice/RequestHandlerF.h $(includedir)/Ice/EndpointIF.h $(includedir)/Ice/EndpointF.h $(includedir)/Ice/EndpointTypes.h $(includedir)/Ice/ObjectAdapterF.h $(includedir)/Ice/ReferenceF.h $(includedir)/Ice/OutgoingAsync.h $(includedir)/IceUtil/Monitor.h $(includedir)/IceUtil/Cond.h $(includedir)/IceUtil/Timer.h $(includedir)/IceUtil/Thread.h $(includedir)/Ice/OutgoingAsyncF.h $(includedir)/Ice/InstanceF.h $(includedir)/Ice/Current.h $(includedir)/Ice/ConnectionF.h $(includedir)/Ice/Identity.h $(includedir)/Ice/BasicStream.h $(includedir)/Ice/ObjectFactoryF.h $(includedir)/Ice/Buffer.h $(includedir)/Ice/Protocol.h $(includedir)/Ice/StreamF.h $(includedir)/Ice/Object.h $(includedir)/Ice/IncomingAsyncF.h $(includedir)/Ice/LoggerF.h $(includedir)/Ice/StatsF.h $(includedir)/Ice/StringConverter.h $(includedir)/Ice/Plugin.h $(includedir)/Ice/BuiltinSequences.h $(includedir)/Ice/Stream.h $(includedir)/IceUtil/Unicode.h $(includedir)/Ice/LocalException.h $(includedir)/Ice/Properties.h $(includedir)/Ice/Outgoing.h $(includedir)/Ice/Incoming.h $(includedir)/Ice/ServantLocatorF.h $(includedir)/Ice/ServantManagerF.h $(includedir)/Ice/Direct.h $(includedir)/Ice/Logger.h $(includedir)/Ice/LoggerUtil.h $(includedir)/Ice/Stats.h $(includedir)/Ice/Communicator.h $(includedir)/Ice/RouterF.h $(includedir)/Ice/LocatorF.h $(includedir)/Ice/PluginF.h $(includedir)/Ice/ImplicitContextF.h $(includedir)/Ice/ObjectFactory.h $(includedir)/Ice/ObjectAdapter.h $(includedir)/Ice/FacetMap.h $(includedir)/Ice/Endpoint.h $(includedir)/Ice/ServantLocator.h $(includedir)/Ice/IncomingAsync.h $(includedir)/Ice/Process.h $(includedir)/Ice/Application.h $(includedir)/Ice/Connection.h $(includedir)/Ice/Functional.h $(includedir)/IceUtil/Functional.h $(includedir)/Ice/ImplicitContext.h $(includedir)/Ice/Locator.h $(includedir)/Ice/FactoryTableInit.h $(includedir)/Ice/FactoryTable.h $(includedir)/IceUtil/StaticMutex.h $(includedir)/Ice/UserExceptionFactory.h $(includedir)/Ice/ProcessF.h $(includedir)/Ice/Router.h $(includedir)/Ice/DispatchInterceptor.h $(includedir)/Ice/IconvStringConverter.h ../../include/TestCommon.h ./Test.h +AllTests$(OBJEXT): AllTests.cpp $(includedir)/Ice/Ice.h $(includedir)/Ice/Initialize.h $(includedir)/Ice/CommunicatorF.h $(includedir)/Ice/LocalObjectF.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Config.h $(includedir)/Ice/Handle.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/Ice/Config.h $(includedir)/Ice/ProxyHandle.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/IceUtil/ScopedArray.h $(includedir)/Ice/UndefSysMacros.h $(includedir)/Ice/PropertiesF.h $(includedir)/Ice/Proxy.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Time.h $(includedir)/IceUtil/MutexProtocol.h $(includedir)/Ice/ProxyFactoryF.h $(includedir)/Ice/ConnectionIF.h $(includedir)/Ice/RequestHandlerF.h $(includedir)/Ice/EndpointIF.h $(includedir)/Ice/EndpointF.h $(includedir)/Ice/EndpointTypes.h $(includedir)/Ice/ObjectAdapterF.h $(includedir)/Ice/ReferenceF.h $(includedir)/Ice/OutgoingAsync.h $(includedir)/IceUtil/Monitor.h $(includedir)/IceUtil/Cond.h $(includedir)/IceUtil/Timer.h $(includedir)/IceUtil/Thread.h $(includedir)/Ice/OutgoingAsyncF.h $(includedir)/Ice/InstanceF.h $(includedir)/Ice/Current.h $(includedir)/Ice/ConnectionF.h $(includedir)/Ice/Identity.h $(includedir)/Ice/BasicStream.h $(includedir)/Ice/ObjectFactoryF.h $(includedir)/Ice/Buffer.h $(includedir)/Ice/Protocol.h $(includedir)/Ice/StreamF.h $(includedir)/Ice/Object.h $(includedir)/Ice/IncomingAsyncF.h $(includedir)/Ice/LoggerF.h $(includedir)/Ice/StatsF.h $(includedir)/Ice/StringConverter.h $(includedir)/Ice/Plugin.h $(includedir)/Ice/BuiltinSequences.h $(includedir)/Ice/Stream.h $(includedir)/IceUtil/Unicode.h $(includedir)/Ice/LocalException.h $(includedir)/Ice/Properties.h $(includedir)/Ice/Outgoing.h $(includedir)/Ice/Incoming.h $(includedir)/Ice/ServantLocatorF.h $(includedir)/Ice/ServantManagerF.h $(includedir)/Ice/Direct.h $(includedir)/Ice/Logger.h $(includedir)/Ice/LoggerUtil.h $(includedir)/Ice/Stats.h $(includedir)/Ice/Communicator.h $(includedir)/Ice/RouterF.h $(includedir)/Ice/LocatorF.h $(includedir)/Ice/PluginF.h $(includedir)/Ice/ImplicitContextF.h $(includedir)/Ice/ObjectFactory.h $(includedir)/Ice/ObjectAdapter.h $(includedir)/Ice/FacetMap.h $(includedir)/Ice/Endpoint.h $(includedir)/Ice/ServantLocator.h $(includedir)/Ice/IncomingAsync.h $(includedir)/Ice/Process.h $(includedir)/Ice/Application.h $(includedir)/Ice/Connection.h $(includedir)/Ice/Functional.h $(includedir)/IceUtil/Functional.h $(includedir)/Ice/ImplicitContext.h $(includedir)/Ice/Locator.h $(includedir)/Ice/FactoryTableInit.h $(includedir)/Ice/FactoryTable.h $(includedir)/IceUtil/StaticMutex.h $(includedir)/Ice/UserExceptionFactory.h $(includedir)/Ice/ProcessF.h $(includedir)/Ice/Router.h $(includedir)/Ice/DispatchInterceptor.h $(includedir)/Ice/IconvStringConverter.h ../../include/TestCommon.h ./Test.h +Test$(OBJEXT): Test.cpp ./Test.h $(includedir)/Ice/LocalObjectF.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Config.h $(includedir)/Ice/Handle.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/Ice/Config.h $(includedir)/Ice/ProxyHandle.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/Ice/Proxy.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Time.h $(includedir)/IceUtil/MutexProtocol.h $(includedir)/Ice/ProxyFactoryF.h $(includedir)/Ice/ConnectionIF.h $(includedir)/Ice/RequestHandlerF.h $(includedir)/Ice/EndpointIF.h $(includedir)/Ice/EndpointF.h $(includedir)/IceUtil/ScopedArray.h $(includedir)/Ice/UndefSysMacros.h $(includedir)/Ice/EndpointTypes.h $(includedir)/Ice/ObjectAdapterF.h $(includedir)/Ice/ReferenceF.h $(includedir)/Ice/OutgoingAsync.h $(includedir)/IceUtil/Monitor.h $(includedir)/IceUtil/Cond.h $(includedir)/IceUtil/Timer.h $(includedir)/IceUtil/Thread.h $(includedir)/Ice/OutgoingAsyncF.h $(includedir)/Ice/InstanceF.h $(includedir)/Ice/CommunicatorF.h $(includedir)/Ice/Current.h $(includedir)/Ice/ConnectionF.h $(includedir)/Ice/Identity.h $(includedir)/Ice/BasicStream.h $(includedir)/Ice/ObjectFactoryF.h $(includedir)/Ice/Buffer.h $(includedir)/Ice/Protocol.h $(includedir)/Ice/StreamF.h $(includedir)/Ice/Object.h $(includedir)/Ice/IncomingAsyncF.h $(includedir)/Ice/Outgoing.h $(includedir)/Ice/Incoming.h $(includedir)/Ice/ServantLocatorF.h $(includedir)/Ice/ServantManagerF.h $(includedir)/Ice/Direct.h $(includedir)/Ice/FactoryTableInit.h $(includedir)/Ice/FactoryTable.h $(includedir)/IceUtil/StaticMutex.h $(includedir)/Ice/UserExceptionFactory.h $(includedir)/Ice/Stream.h $(includedir)/Ice/LocalException.h $(includedir)/Ice/BuiltinSequences.h $(includedir)/Ice/ObjectFactory.h $(includedir)/IceUtil/Iterator.h +BlobjectI$(OBJEXT): BlobjectI.cpp $(includedir)/Ice/Ice.h $(includedir)/Ice/Initialize.h $(includedir)/Ice/CommunicatorF.h $(includedir)/Ice/LocalObjectF.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Config.h $(includedir)/Ice/Handle.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/Ice/Config.h $(includedir)/Ice/ProxyHandle.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/IceUtil/ScopedArray.h $(includedir)/Ice/UndefSysMacros.h $(includedir)/Ice/PropertiesF.h $(includedir)/Ice/Proxy.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Time.h $(includedir)/IceUtil/MutexProtocol.h $(includedir)/Ice/ProxyFactoryF.h $(includedir)/Ice/ConnectionIF.h $(includedir)/Ice/RequestHandlerF.h $(includedir)/Ice/EndpointIF.h $(includedir)/Ice/EndpointF.h $(includedir)/Ice/EndpointTypes.h $(includedir)/Ice/ObjectAdapterF.h $(includedir)/Ice/ReferenceF.h $(includedir)/Ice/OutgoingAsync.h $(includedir)/IceUtil/Monitor.h $(includedir)/IceUtil/Cond.h $(includedir)/IceUtil/Timer.h $(includedir)/IceUtil/Thread.h $(includedir)/Ice/OutgoingAsyncF.h $(includedir)/Ice/InstanceF.h $(includedir)/Ice/Current.h $(includedir)/Ice/ConnectionF.h $(includedir)/Ice/Identity.h $(includedir)/Ice/BasicStream.h $(includedir)/Ice/ObjectFactoryF.h $(includedir)/Ice/Buffer.h $(includedir)/Ice/Protocol.h $(includedir)/Ice/StreamF.h $(includedir)/Ice/Object.h $(includedir)/Ice/IncomingAsyncF.h $(includedir)/Ice/LoggerF.h $(includedir)/Ice/StatsF.h $(includedir)/Ice/StringConverter.h $(includedir)/Ice/Plugin.h $(includedir)/Ice/BuiltinSequences.h $(includedir)/Ice/Stream.h $(includedir)/IceUtil/Unicode.h $(includedir)/Ice/LocalException.h $(includedir)/Ice/Properties.h $(includedir)/Ice/Outgoing.h $(includedir)/Ice/Incoming.h $(includedir)/Ice/ServantLocatorF.h $(includedir)/Ice/ServantManagerF.h $(includedir)/Ice/Direct.h $(includedir)/Ice/Logger.h $(includedir)/Ice/LoggerUtil.h $(includedir)/Ice/Stats.h $(includedir)/Ice/Communicator.h $(includedir)/Ice/RouterF.h $(includedir)/Ice/LocatorF.h $(includedir)/Ice/PluginF.h $(includedir)/Ice/ImplicitContextF.h $(includedir)/Ice/ObjectFactory.h $(includedir)/Ice/ObjectAdapter.h $(includedir)/Ice/FacetMap.h $(includedir)/Ice/Endpoint.h $(includedir)/Ice/ServantLocator.h $(includedir)/Ice/IncomingAsync.h $(includedir)/Ice/Process.h $(includedir)/Ice/Application.h $(includedir)/Ice/Connection.h $(includedir)/Ice/Functional.h $(includedir)/IceUtil/Functional.h $(includedir)/Ice/ImplicitContext.h $(includedir)/Ice/Locator.h $(includedir)/Ice/FactoryTableInit.h $(includedir)/Ice/FactoryTable.h $(includedir)/IceUtil/StaticMutex.h $(includedir)/Ice/UserExceptionFactory.h $(includedir)/Ice/ProcessF.h $(includedir)/Ice/Router.h $(includedir)/Ice/DispatchInterceptor.h $(includedir)/Ice/IconvStringConverter.h ./BlobjectI.h ./Test.h ../../include/TestCommon.h +Server$(OBJEXT): Server.cpp $(includedir)/Ice/Ice.h $(includedir)/Ice/Initialize.h $(includedir)/Ice/CommunicatorF.h $(includedir)/Ice/LocalObjectF.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Config.h $(includedir)/Ice/Handle.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/Ice/Config.h $(includedir)/Ice/ProxyHandle.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/IceUtil/ScopedArray.h $(includedir)/Ice/UndefSysMacros.h $(includedir)/Ice/PropertiesF.h $(includedir)/Ice/Proxy.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Time.h $(includedir)/IceUtil/MutexProtocol.h $(includedir)/Ice/ProxyFactoryF.h $(includedir)/Ice/ConnectionIF.h $(includedir)/Ice/RequestHandlerF.h $(includedir)/Ice/EndpointIF.h $(includedir)/Ice/EndpointF.h $(includedir)/Ice/EndpointTypes.h $(includedir)/Ice/ObjectAdapterF.h $(includedir)/Ice/ReferenceF.h $(includedir)/Ice/OutgoingAsync.h $(includedir)/IceUtil/Monitor.h $(includedir)/IceUtil/Cond.h $(includedir)/IceUtil/Timer.h $(includedir)/IceUtil/Thread.h $(includedir)/Ice/OutgoingAsyncF.h $(includedir)/Ice/InstanceF.h $(includedir)/Ice/Current.h $(includedir)/Ice/ConnectionF.h $(includedir)/Ice/Identity.h $(includedir)/Ice/BasicStream.h $(includedir)/Ice/ObjectFactoryF.h $(includedir)/Ice/Buffer.h $(includedir)/Ice/Protocol.h $(includedir)/Ice/StreamF.h $(includedir)/Ice/Object.h $(includedir)/Ice/IncomingAsyncF.h $(includedir)/Ice/LoggerF.h $(includedir)/Ice/StatsF.h $(includedir)/Ice/StringConverter.h $(includedir)/Ice/Plugin.h $(includedir)/Ice/BuiltinSequences.h $(includedir)/Ice/Stream.h $(includedir)/IceUtil/Unicode.h $(includedir)/Ice/LocalException.h $(includedir)/Ice/Properties.h $(includedir)/Ice/Outgoing.h $(includedir)/Ice/Incoming.h $(includedir)/Ice/ServantLocatorF.h $(includedir)/Ice/ServantManagerF.h $(includedir)/Ice/Direct.h $(includedir)/Ice/Logger.h $(includedir)/Ice/LoggerUtil.h $(includedir)/Ice/Stats.h $(includedir)/Ice/Communicator.h $(includedir)/Ice/RouterF.h $(includedir)/Ice/LocatorF.h $(includedir)/Ice/PluginF.h $(includedir)/Ice/ImplicitContextF.h $(includedir)/Ice/ObjectFactory.h $(includedir)/Ice/ObjectAdapter.h $(includedir)/Ice/FacetMap.h $(includedir)/Ice/Endpoint.h $(includedir)/Ice/ServantLocator.h $(includedir)/Ice/IncomingAsync.h $(includedir)/Ice/Process.h $(includedir)/Ice/Application.h $(includedir)/Ice/Connection.h $(includedir)/Ice/Functional.h $(includedir)/IceUtil/Functional.h $(includedir)/Ice/ImplicitContext.h $(includedir)/Ice/Locator.h $(includedir)/Ice/FactoryTableInit.h $(includedir)/Ice/FactoryTable.h $(includedir)/IceUtil/StaticMutex.h $(includedir)/Ice/UserExceptionFactory.h $(includedir)/Ice/ProcessF.h $(includedir)/Ice/Router.h $(includedir)/Ice/DispatchInterceptor.h $(includedir)/Ice/IconvStringConverter.h $(includedir)/IceUtil/Options.h $(includedir)/IceUtil/RecMutex.h ./BlobjectI.h +Test.cpp: Test.ice +Test.ice: $(SLICE2CPP) $(SLICEPARSERLIB) diff --git a/cpp/test/Ice/invoke/.gitignore b/cpp/test/Ice/invoke/.gitignore new file mode 100644 index 00000000000..67872faa673 --- /dev/null +++ b/cpp/test/Ice/invoke/.gitignore @@ -0,0 +1,7 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +server +Test.cpp +Test.h diff --git a/cpp/test/Ice/invoke/AllTests.cpp b/cpp/test/Ice/invoke/AllTests.cpp new file mode 100644 index 00000000000..5d334bcfd18 --- /dev/null +++ b/cpp/test/Ice/invoke/AllTests.cpp @@ -0,0 +1,435 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 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. +// +// ********************************************************************** + +#include <Ice/Ice.h> +#include <Ice/Stream.h> +#include <TestCommon.h> +#include <Test.h> + +using namespace std; + +static string testString = "This is a test string"; + +class Cookie : public Ice::LocalObject +{ +public: + + string getString() + { + return testString; + } +}; +typedef IceUtil::Handle<Cookie> CookiePtr; + +class CallbackBase : public IceUtil::Monitor<IceUtil::Mutex> +{ +public: + + CallbackBase() : + _called(false) + { + } + + virtual ~CallbackBase() + { + } + + void check() + { + IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this); + while(!_called) + { + wait(); + } + _called = false; + } + +protected: + + void called() + { + IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this); + assert(!_called); + _called = true; + notify(); + } + +private: + + bool _called; +}; + +class Callback : public IceUtil::Shared, public CallbackBase +{ +public: + + Callback(const Ice::CommunicatorPtr& communicator, bool useCookie) : + _communicator(communicator), + _useCookie(useCookie) + { + } + + void opString(const Ice::AsyncResultPtr& result) + { + string cmp = testString; + if(_useCookie) + { + CookiePtr cookie = CookiePtr::dynamicCast(result->getCookie()); + cmp = cookie->getString(); + } + + Ice::ByteSeq outParams; + if(result->getProxy()->end_ice_invoke(outParams, result)) + { + Ice::InputStreamPtr in = Ice::createInputStream(_communicator, outParams); + string s; + in->read(s); + test(s == cmp); + in->read(s); + test(s == cmp); + called(); + } + else + { + test(false); + }; + } + + void opException(const Ice::AsyncResultPtr& result) + { + if(_useCookie) + { + CookiePtr cookie = CookiePtr::dynamicCast(result->getCookie()); + test(cookie->getString() == testString); + } + + Ice::ByteSeq outParams; + if(result->getProxy()->end_ice_invoke(outParams, result)) + { + test(false); + } + else + { + Ice::InputStreamPtr in = Ice::createInputStream(_communicator, outParams); + try + { + in->throwException(); + } + catch(const Test::MyException&) + { + called(); + } + catch(...) + { + test(false); + } + } + } + + void opStringNC(bool ok, const Ice::ByteSeq& outParams) + { + if(ok) + { + Ice::InputStreamPtr in = Ice::createInputStream(_communicator, outParams); + string s; + in->read(s); + test(s == testString); + in->read(s); + test(s == testString); + called(); + } + else + { + test(false); + } + } + + void opStringWC(bool ok, const Ice::ByteSeq& outParams, const CookiePtr& cookie) + { + if(ok) + { + Ice::InputStreamPtr in = Ice::createInputStream(_communicator, outParams); + string s; + in->read(s); + test(s == cookie->getString()); + in->read(s); + test(s == cookie->getString()); + called(); + } + else + { + test(false); + } + } + + void opExceptionNC(bool ok, const Ice::ByteSeq& outParams) + { + if(ok) + { + test(false); + } + else + { + Ice::InputStreamPtr in = Ice::createInputStream(_communicator, outParams); + try + { + in->throwException(); + } + catch(const Test::MyException&) + { + called(); + } + catch(...) + { + test(false); + } + } + } + + void opExceptionWC(bool ok, const Ice::ByteSeq& outParams, const CookiePtr& cookie) + { + test(cookie->getString() == testString); + if(ok) + { + test(false); + } + else + { + Ice::InputStreamPtr in = Ice::createInputStream(_communicator, outParams); + try + { + in->throwException(); + } + catch(const Test::MyException&) + { + called(); + } + catch(...) + { + test(false); + } + } + } + +private: + + Ice::CommunicatorPtr _communicator; + bool _useCookie; +}; +typedef IceUtil::Handle<Callback> CallbackPtr; + +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); + + cout << "testing ice_invoke... " << flush; + + { + Ice::ByteSeq inParams, outParams; + 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::OutputStreamPtr out = Ice::createOutputStream(communicator); + out->write(testString); + out->finished(inParams); + + // begin_ice_invoke with no callback + Ice::AsyncResultPtr 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); + pair<const ::Ice::Byte*, const ::Ice::Byte*> outPair; + if(cl->end_ice_invoke(outPair, result)) + { + Ice::InputStreamPtr in = Ice::createInputStream(communicator, outPair); + 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); + 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); + 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); + 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); + 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); + 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); + cl->begin_ice_invoke("opException", Ice::Normal, inParams, d, cookie); + cb->check(); + } + + cout << "ok" << endl; + + return cl; +} diff --git a/cpp/test/Ice/invoke/BlobjectI.cpp b/cpp/test/Ice/invoke/BlobjectI.cpp new file mode 100644 index 00000000000..b1bb6c08b9b --- /dev/null +++ b/cpp/test/Ice/invoke/BlobjectI.cpp @@ -0,0 +1,104 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 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. +// +// ********************************************************************** + +#include <Ice/Ice.h> +#include <BlobjectI.h> +#include <Test.h> +#include <TestCommon.h> + +using namespace std; + +bool +invokeInternal(const Ice::InputStreamPtr& in, vector<Ice::Byte>& outParams, const Ice::Current& current) +{ + Ice::CommunicatorPtr communicator = current.adapter->getCommunicator(); + Ice::OutputStreamPtr out = Ice::createOutputStream(communicator); + if(current.operation == "opString") + { + string s; + in->read(s); + out->write(s); + out->write(s); + out->finished(outParams); + return true; + } + else if(current.operation == "opException") + { + Test::MyException ex; + out->writeException(ex); + out->finished(outParams); + return false; + } + else if(current.operation == "shutdown") + { + communicator->shutdown(); + return true; + } + else if(current.operation == "ice_isA") + { + string s; + in->read(s); + if(s == "::Test::MyClass") + { + out->write(true); + } + else + { + out->write(false); + } + out->finished(outParams); + return true; + } + else + { + Ice::OperationNotExistException ex(__FILE__, __LINE__); + ex.id = current.id; + ex.facet = current.facet; + ex.operation = current.operation; + throw ex; + } +} + +bool +BlobjectI::ice_invoke(const vector<Ice::Byte>& inParams, vector<Ice::Byte>& outParams, const Ice::Current& current) +{ + Ice::InputStreamPtr in = Ice::createInputStream(current.adapter->getCommunicator(), inParams); + return invokeInternal(in, outParams, current); +} + +bool +BlobjectArrayI::ice_invoke(const pair<const Ice::Byte*, const Ice::Byte*>& inParams, vector<Ice::Byte>& outParams, + const Ice::Current& current) +{ + Ice::InputStreamPtr in = Ice::createInputStream(current.adapter->getCommunicator(), inParams); + return invokeInternal(in, outParams, current); +} + + +void +BlobjectAsyncI::ice_invoke_async(const Ice::AMD_Object_ice_invokePtr& cb, const vector<Ice::Byte>& inParams, + const Ice::Current& current) +{ + Ice::InputStreamPtr in = Ice::createInputStream(current.adapter->getCommunicator(), inParams); + vector<Ice::Byte> outParams; + bool ok = invokeInternal(in, outParams, current); + cb->ice_response(ok, outParams); +} + +void +BlobjectArrayAsyncI::ice_invoke_async(const Ice::AMD_Object_ice_invokePtr& cb, + const pair<const Ice::Byte*, const Ice::Byte*>& inParams, + const Ice::Current& current) +{ + Ice::InputStreamPtr in = Ice::createInputStream(current.adapter->getCommunicator(), inParams); + vector<Ice::Byte> outParams; + bool ok = invokeInternal(in, outParams, current); + pair<const Ice::Byte*, const Ice::Byte*> outPair(&outParams[0], &outParams[0] + outParams.size()); + cb->ice_response(ok, outParams); +} diff --git a/cpp/test/Ice/invoke/BlobjectI.h b/cpp/test/Ice/invoke/BlobjectI.h new file mode 100644 index 00000000000..08b6f4c1d2a --- /dev/null +++ b/cpp/test/Ice/invoke/BlobjectI.h @@ -0,0 +1,47 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 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. +// +// ********************************************************************** + +#ifndef BLOBJECT_H +#define BLOBJECT_H + +#include <Ice/Object.h> + +class BlobjectI : public Ice::Blobject +{ +public: + + virtual bool ice_invoke(const std::vector<Ice::Byte>&, std::vector<Ice::Byte>&, const Ice::Current&); +}; + +class BlobjectArrayI : public Ice::BlobjectArray +{ +public: + + virtual bool ice_invoke(const std::pair<const Ice::Byte*, const Ice::Byte*>&, std::vector<Ice::Byte>&, + const Ice::Current&); +}; + + +class BlobjectAsyncI : public Ice::BlobjectAsync +{ +public: + + virtual void ice_invoke_async(const Ice::AMD_Object_ice_invokePtr&, const std::vector<Ice::Byte>&, + const Ice::Current&); +}; + +class BlobjectArrayAsyncI : public Ice::BlobjectArrayAsync +{ +public: + + virtual void ice_invoke_async(const Ice::AMD_Object_ice_invokePtr&, + const std::pair<const Ice::Byte*, const Ice::Byte*>&, const Ice::Current&); +}; + +#endif diff --git a/cpp/test/Ice/invoke/Client.cpp b/cpp/test/Ice/invoke/Client.cpp new file mode 100644 index 00000000000..394be5c412d --- /dev/null +++ b/cpp/test/Ice/invoke/Client.cpp @@ -0,0 +1,62 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 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. +// +// ********************************************************************** + +#include <Ice/Ice.h> +#include <TestCommon.h> +#include <Test.h> + +using namespace std; + +int +run(int argc, char* argv[], + const Ice::CommunicatorPtr& communicator, + const Ice::InitializationData& initData) +{ + Test::MyClassPrx allTests(const Ice::CommunicatorPtr&); + Test::MyClassPrx myClass = allTests(communicator); + + myClass->shutdown(); + + return EXIT_SUCCESS; +} + +int +main(int argc, char* argv[]) +{ + int status; + Ice::CommunicatorPtr communicator; + + try + { + Ice::InitializationData initData; + initData.properties = Ice::createProperties(argc, argv); + communicator = Ice::initialize(argc, argv, initData); + status = run(argc, argv, communicator, initData); + } + catch(const Ice::Exception& ex) + { + cerr << ex << endl; + status = EXIT_FAILURE; + } + + if(communicator) + { + try + { + communicator->destroy(); + } + catch(const Ice::Exception& ex) + { + cerr << ex << endl; + status = EXIT_FAILURE; + } + } + + return status; +} diff --git a/cpp/test/Ice/invoke/Makefile b/cpp/test/Ice/invoke/Makefile new file mode 100644 index 00000000000..a00870cdcb3 --- /dev/null +++ b/cpp/test/Ice/invoke/Makefile @@ -0,0 +1,43 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2009 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. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client +SERVER = server + +TARGETS = $(CLIENT) $(SERVER) + +COBJS = Test.o \ + Client.o \ + AllTests.o + +SOBJS = Test.o \ + BlobjectI.o \ + Server.o + +SRCS = $(COBJS:.o=.cpp) \ + $(SOBJS:.o=.cpp) + +SLICE_SRCS = Test.ice + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I../../include $(CPPFLAGS) +SLICE2CPPFLAGS := --stream $(SLICE2CPPFLAGS) + +$(CLIENT): $(COBJS) + rm -f $@ + $(CXX) $(LDFLAGS) -o $@ $(COBJS) $(LIBS) + +$(SERVER): $(SOBJS) + rm -f $@ + $(CXX) $(LDFLAGS) -o $@ $(SOBJS) $(LIBS) + +include .depend diff --git a/cpp/test/Ice/invoke/Makefile.mak b/cpp/test/Ice/invoke/Makefile.mak new file mode 100644 index 00000000000..979a5e71f1c --- /dev/null +++ b/cpp/test/Ice/invoke/Makefile.mak @@ -0,0 +1,51 @@ +# **********************************************************************
+#
+# Copyright (c) 2003-2009 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.
+#
+# **********************************************************************
+
+top_srcdir = ..\..\..
+
+CLIENT = client.exe
+SERVER = server.exe
+
+TARGETS = $(CLIENT) $(SERVER)
+
+COBJS = Test.obj \
+ Client.obj \
+ AllTests.obj
+
+SOBJS = Test.obj \
+ BlobjectI.obj \
+ Server.obj
+
+SRCS = $(COBJS:.obj=.cpp) \
+ $(SOBJS:.obj=.cpp)
+
+!include $(top_srcdir)/config/Make.rules.mak
+
+CPPFLAGS = -I. -I../../include $(CPPFLAGS) -DWIN32_LEAN_AND_MEAN
+SLICE2CPPFLAGS = --stream $(SLICE2CPPFLAGS)
+
+!if "$(GENERATE_PDB)" == "yes"
+CPDBFLAGS = /pdb:$(CLIENT:.exe=.pdb)
+SPDBFLAGS = /pdb:$(SERVER:.exe=.pdb)
+!endif
+
+$(CLIENT): $(COBJS)
+ $(LINK) $(LD_EXEFLAGS) $(CPDBFLAGS) $(SETARGV) $(COBJS) $(PREOUT)$@ $(PRELIBS)$(LIBS)
+ @if exist $@.manifest echo ^ ^ ^ Embedding manifest using $(MT) && \
+ $(MT) -nologo -manifest $@.manifest -outputresource:$@;#1 && del /q $@.manifest
+
+$(SERVER): $(SOBJS)
+ $(LINK) $(LD_EXEFLAGS) $(SPDBFLAGS) $(SETARGV) $(SOBJS) $(PREOUT)$@ $(PRELIBS)$(LIBS)
+ @if exist $@.manifest echo ^ ^ ^ Embedding manifest using $(MT) && \
+ $(MT) -nologo -manifest $@.manifest -outputresource:$@;#1 && del /q $@.manifest
+
+clean::
+ del /q Test.cpp Test.h
+
+!include .depend
diff --git a/cpp/test/Ice/invoke/Server.cpp b/cpp/test/Ice/invoke/Server.cpp new file mode 100644 index 00000000000..f704ffae89c --- /dev/null +++ b/cpp/test/Ice/invoke/Server.cpp @@ -0,0 +1,130 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 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. +// +// ********************************************************************** + +#include <Ice/Ice.h> +#include <IceUtil/Options.h> +#include <BlobjectI.h> + +using namespace std; + +class ServantLocatorI : public Ice::ServantLocator +{ +public: + + ServantLocatorI(bool array, bool async) + { + if(array) + { + if(async) + { + _blobject = new BlobjectArrayAsyncI(); + } + else + { + _blobject = new BlobjectArrayI(); + } + } + else + { + if(async) + { + _blobject = new BlobjectAsyncI(); + } + else + { + _blobject = new BlobjectI(); + } + } + } + + virtual Ice::ObjectPtr + locate(const Ice::Current&, Ice::LocalObjectPtr&) + { + return _blobject; + } + + virtual void + finished(const Ice::Current&, const Ice::ObjectPtr&, const Ice::LocalObjectPtr&) + { + } + + virtual void + deactivate(const string&) + { + } + +private: + + Ice::ObjectPtr _blobject; +}; + + +int +run(int argc, char* argv[], const Ice::CommunicatorPtr& communicator) +{ + IceUtilInternal::Options opts; + opts.addOpt("", "array"); + opts.addOpt("", "async"); + + vector<string> args; + try + { + args = opts.parse(argc, (const char**)argv); + } + catch(const IceUtilInternal::BadOptException& e) + { + cout << argv[0] << ": " << e.reason << endl; + return false; + } + bool array = opts.isSet("array"); + bool async = opts.isSet("async"); + + communicator->getProperties()->setProperty("TestAdapter.Endpoints", "default -p 12010:udp"); + Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter("TestAdapter"); + adapter->addServantLocator(new ServantLocatorI(array, async), ""); + adapter->activate(); + + communicator->waitForShutdown(); + return EXIT_SUCCESS; +} + +int +main(int argc, char* argv[]) +{ + int status; + Ice::CommunicatorPtr communicator; + + try + { + Ice::InitializationData initData; + initData.properties = Ice::createProperties(argc, argv); + communicator = Ice::initialize(argc, argv, initData); + status = run(argc, argv, communicator); + } + catch(const Ice::Exception& ex) + { + cerr << ex << endl; + status = EXIT_FAILURE; + } + + if(communicator) + { + try + { + communicator->destroy(); + } + catch(const Ice::Exception& ex) + { + cerr << ex << endl; + status = EXIT_FAILURE; + } + } + + return status; +} diff --git a/cpp/test/Ice/invoke/Test.ice b/cpp/test/Ice/invoke/Test.ice new file mode 100644 index 00000000000..5e624e9204b --- /dev/null +++ b/cpp/test/Ice/invoke/Test.ice @@ -0,0 +1,31 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 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. +// +// ********************************************************************** + +#ifndef TEST_ICE +#define TEST_ICE + +module Test +{ + +exception MyException +{ +}; + +class MyClass +{ + string opString(string s1, out string s2); + + void opException() throws MyException; + + void shutdown(); +}; + +}; + +#endif diff --git a/cpp/test/Ice/invoke/run.py b/cpp/test/Ice/invoke/run.py new file mode 100755 index 00000000000..6b63023f48e --- /dev/null +++ b/cpp/test/Ice/invoke/run.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise "can't find toplevel directory!" +sys.path.append(os.path.join(path[0])) +from scripts import * + +print "tests with Blobject server." +TestUtil.clientServerTest() +print "tests with BlobjectArray server." +TestUtil.clientServerTest(additionalServerOptions = "--array") +print "tests with BlobjectAsync server." +TestUtil.clientServerTest(additionalServerOptions = "--async") +print "tests with BlobjectAsyncArray server." +TestUtil.clientServerTest(additionalServerOptions = "--array --async") + diff --git a/cs/allTests.py b/cs/allTests.py index 4d6cc0fa444..290a61df0f1 100755 --- a/cs/allTests.py +++ b/cs/allTests.py @@ -53,6 +53,7 @@ tests = [ ("Ice/udp", ["core"]), ("Ice/defaultServant", ["core"]), ("Ice/threadPoolPriority", ["core", "nomono"]), + ("Ice/invoke", ["core"]), ("IceBox/configuration", ["core", "noipv6"]), ("Glacier2/router", ["service"]), ("IceGrid/simple", ["service"]), diff --git a/cs/demo/Ice/invoke/Client.cs b/cs/demo/Ice/invoke/Client.cs index 2e062a7e017..8d58801305c 100644 --- a/cs/demo/Ice/invoke/Client.cs +++ b/cs/demo/Ice/invoke/Client.cs @@ -22,60 +22,6 @@ public class Client { public class App : Ice.Application { - private void success(bool ok, byte[] outParams) - { - if(!ok) - { - Console.Error.WriteLine("Unknown user exception"); - } - } - - private void exception(Ice.Exception ex) - { - Console.Error.WriteLine(ex); - } - - private void getValues(bool ok, byte[] outParams) - { - if(!ok) - { - Console.Error.WriteLine("Unknown user exception"); - } - else - { - // - // Unmarshal the results. - // - Ice.InputStream inStream = Ice.Util.createInputStream(communicator(), outParams); - Demo.CHelper ch = new Demo.CHelper(inStream); - ch.read(); - String str = inStream.readString(); - inStream.readPendingObjects(); - inStream.destroy(); - Demo.C c = ch.value; - Console.Error.WriteLine("Got string `" + str + "' and class: s.name=" + c.s.name + - ", s.value=" + c.s.value); - } - } - - private void printFailure(bool ok, byte[] outParams) - { - Ice.InputStream inStream = Ice.Util.createInputStream(communicator(), outParams); - try - { - inStream.throwException(); - } - catch(Demo.PrintFailure) - { - // Expected. - } - catch(Ice.UserException) - { - Console.Error.WriteLine("Unknown user exception"); - } - inStream.destroy(); - } - private static void menu() { Console.WriteLine( @@ -96,14 +42,9 @@ public class Client public override int run(string[] args) { - bool async = false; - if(args.Length == 1 && args[0].Equals("--async")) - { - async = true; - } - else if(args.Length > 0) + if(args.Length > 0) { - Console.Error.WriteLine("Usage: " + appName() + " [--async]"); + Console.Error.WriteLine(appName() + ": too many arguments"); return 1; } @@ -137,18 +78,10 @@ public class Client // // Invoke operation. // - if(async) + if(!obj.ice_invoke("printString", Ice.OperationMode.Normal, outStream.finished(), + out outParams)) { - obj.begin_ice_invoke("printString", Ice.OperationMode.Normal, outStream.finished()) - .whenCompleted(success, exception); - } - else - { - if(!obj.ice_invoke("printString", Ice.OperationMode.Normal, outStream.finished(), - out outParams)) - { - Console.Error.WriteLine("Unknown user exception"); - } + Console.Error.WriteLine("Unknown user exception"); } outStream.destroy(); @@ -165,18 +98,10 @@ public class Client // // Invoke operation. // - if(async) - { - obj.begin_ice_invoke("printStringSequence", Ice.OperationMode.Normal, outStream.finished()) - .whenCompleted(success, exception); - } - else + if(!obj.ice_invoke("printStringSequence", Ice.OperationMode.Normal, outStream.finished(), + out outParams)) { - if(!obj.ice_invoke("printStringSequence", Ice.OperationMode.Normal, outStream.finished(), - out outParams)) - { - Console.Error.WriteLine("Unknown user exception"); - } + Console.Error.WriteLine("Unknown user exception"); } outStream.destroy(); @@ -195,18 +120,10 @@ public class Client // // Invoke operation. // - if(async) + if(!obj.ice_invoke("printDictionary", Ice.OperationMode.Normal, outStream.finished(), + out outParams)) { - obj.begin_ice_invoke("printDictionary", Ice.OperationMode.Normal, outStream.finished()) - .whenCompleted(success, exception); - } - else - { - if(!obj.ice_invoke("printDictionary", Ice.OperationMode.Normal, outStream.finished(), - out outParams)) - { - Console.Error.WriteLine("Unknown user exception"); - } + Console.Error.WriteLine("Unknown user exception"); } outStream.destroy(); @@ -222,18 +139,9 @@ public class Client // // Invoke operation. // - if(async) + if(!obj.ice_invoke("printEnum", Ice.OperationMode.Normal, outStream.finished(), out outParams)) { - obj.begin_ice_invoke("printEnum", Ice.OperationMode.Normal, outStream.finished()) - .whenCompleted(success, exception); - } - else - { - if(!obj.ice_invoke("printEnum", Ice.OperationMode.Normal, outStream.finished(), - out outParams)) - { - Console.Error.WriteLine("Unknown user exception"); - } + Console.Error.WriteLine("Unknown user exception"); } outStream.destroy(); @@ -252,18 +160,10 @@ public class Client // // Invoke operation. // - if(async) - { - obj.begin_ice_invoke("printStruct", Ice.OperationMode.Normal, outStream.finished()) - .whenCompleted(success, exception); - } - else + if(!obj.ice_invoke("printStruct", Ice.OperationMode.Normal, outStream.finished(), + out outParams)) { - if(!obj.ice_invoke("printStruct", Ice.OperationMode.Normal, outStream.finished(), - out outParams)) - { - Console.Error.WriteLine("Unknown user exception"); - } + Console.Error.WriteLine("Unknown user exception"); } outStream.destroy(); @@ -289,18 +189,10 @@ public class Client // // Invoke operation. // - if(async) + if(!obj.ice_invoke("printStructSequence", Ice.OperationMode.Normal, outStream.finished(), + out outParams)) { - obj.begin_ice_invoke("printStructSequence", Ice.OperationMode.Normal, outStream.finished()) - .whenCompleted(success, exception); - } - else - { - if(!obj.ice_invoke("printStructSequence", Ice.OperationMode.Normal, outStream.finished(), - out outParams)) - { - Console.Error.WriteLine("Unknown user exception"); - } + Console.Error.WriteLine("Unknown user exception"); } outStream.destroy(); @@ -321,18 +213,9 @@ public class Client // // Invoke operation. // - if(async) - { - obj.begin_ice_invoke("printClass", Ice.OperationMode.Normal, outStream.finished()) - .whenCompleted(success, exception); - } - else + if(!obj.ice_invoke("printClass", Ice.OperationMode.Normal, outStream.finished(), out outParams)) { - if(!obj.ice_invoke("printClass", Ice.OperationMode.Normal, outStream.finished(), - out outParams)) - { - Console.Error.WriteLine("Unknown user exception"); - } + Console.Error.WriteLine("Unknown user exception"); } outStream.destroy(); @@ -342,78 +225,54 @@ public class Client // // Invoke operation. // - if(async) + if(!obj.ice_invoke("getValues", Ice.OperationMode.Normal, null, out outParams)) { - obj.begin_ice_invoke("getValues", Ice.OperationMode.Normal, null) - .whenCompleted(getValues, exception); + Console.Error.WriteLine("Unknown user exception"); + continue; } - else - { - if(!obj.ice_invoke("getValues", Ice.OperationMode.Normal, null, out outParams)) - { - Console.Error.WriteLine("Unknown user exception"); - continue; - } - // - // Unmarshal the results. - // - Ice.InputStream inStream = Ice.Util.createInputStream(communicator(), outParams); - Demo.CHelper ch = new Demo.CHelper(inStream); - ch.read(); - String str = inStream.readString(); - inStream.readPendingObjects(); - inStream.destroy(); - Demo.C c = ch.value; - Console.Error.WriteLine("Got string `" + str + "' and class: s.name=" + c.s.name + - ", s.value=" + c.s.value); - } + // + // Unmarshal the results. + // + Ice.InputStream inStream = Ice.Util.createInputStream(communicator(), outParams); + Demo.CHelper ch = new Demo.CHelper(inStream); + ch.read(); + String str = inStream.readString(); + inStream.readPendingObjects(); + inStream.destroy(); + Demo.C c = ch.value; + Console.Error.WriteLine("Got string `" + str + "' and class: s.name=" + c.s.name + + ", s.value=" + c.s.value); } else if(line.Equals("9")) { // // Invoke operation. // - if(async) + if(obj.ice_invoke("throwPrintFailure", Ice.OperationMode.Normal, null, out outParams)) { - obj.begin_ice_invoke("throwPrintFailure", Ice.OperationMode.Normal, null) - .whenCompleted(printFailure, exception); + Console.Error.WriteLine("Expected exception"); + continue; } - else - { - if(obj.ice_invoke("throwPrintFailure", Ice.OperationMode.Normal, null, out outParams)) - { - Console.Error.WriteLine("Expected exception"); - continue; - } - Ice.InputStream inStream = Ice.Util.createInputStream(communicator(), outParams); - try - { - inStream.throwException(); - } - catch(Demo.PrintFailure) - { - // Expected. - } - catch(Ice.UserException) - { - Console.Error.WriteLine("Unknown user exception"); - } - inStream.destroy(); + Ice.InputStream inStream = Ice.Util.createInputStream(communicator(), outParams); + try + { + inStream.throwException(); } - } - else if(line.Equals("s")) - { - if(async) + catch(Demo.PrintFailure) { - obj.begin_ice_invoke("shutdown", Ice.OperationMode.Normal, null) - .whenCompleted(success, exception); + // Expected. } - else + catch(Ice.UserException) { - obj.ice_invoke("shutdown", Ice.OperationMode.Normal, null, out outParams); + Console.Error.WriteLine("Unknown user exception"); } + inStream.destroy(); + } + else if(line.Equals("s")) + { + obj.ice_invoke("shutdown", Ice.OperationMode.Normal, null, out outParams); } else if(line.Equals("x")) { diff --git a/cs/demo/Ice/invoke/README b/cs/demo/Ice/invoke/README index e5306d44e5e..2fd62acc721 100644 --- a/cs/demo/Ice/invoke/README +++ b/cs/demo/Ice/invoke/README @@ -7,7 +7,3 @@ $ server.exe In a separate window, start the client: $ client.exe - -To run the client using asynchronous calls use: - -$ client.exe --async diff --git a/cs/test/Ice/Makefile b/cs/test/Ice/Makefile index 86878b4ef44..77da3984f53 100644 --- a/cs/test/Ice/Makefile +++ b/cs/test/Ice/Makefile @@ -18,6 +18,7 @@ SUBDIRS = application \ faultTolerance \ info \ inheritance \ + invoke \ hold \ location \ objects \ diff --git a/cs/test/Ice/Makefile.mak b/cs/test/Ice/Makefile.mak index 261671a6293..3775d299509 100644 --- a/cs/test/Ice/Makefile.mak +++ b/cs/test/Ice/Makefile.mak @@ -18,6 +18,7 @@ SUBDIRS = application \ faultTolerance \
info \
inheritance \
+ invoke \
hold \
location \
objects \
diff --git a/cs/test/Ice/invoke/.depend b/cs/test/Ice/invoke/.depend new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/cs/test/Ice/invoke/.depend diff --git a/cs/test/Ice/invoke/AllTests.cs b/cs/test/Ice/invoke/AllTests.cs new file mode 100644 index 00000000000..d8a52f077d6 --- /dev/null +++ b/cs/test/Ice/invoke/AllTests.cs @@ -0,0 +1,320 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 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. +// +// ********************************************************************** + +using System; +using System.Diagnostics; +using System.Threading; + +public class AllTests +{ + private static string testString = "This is a test string"; + + private class Cookie + { + public string getString() + { + return testString; + } + } + + private static void test(bool b) + { + if(!b) + { + throw new System.Exception(); + } + } + + private class CallbackBase + { + internal CallbackBase() + { + _called = false; + } + + public virtual void check() + { + lock(this) + { + while(!_called) + { + Monitor.Wait(this); + } + + _called = false; + } + } + + public virtual void called() + { + lock(this) + { + Debug.Assert(!_called); + _called = true; + Monitor.Pulse(this); + } + } + + private bool _called; + } + + private class Callback + { + public Callback(Ice.Communicator communicator, bool useCookie) + { + _communicator = communicator; + _useCookie = useCookie; + } + + public void opString(Ice.AsyncResult result) + { + string cmp = testString; + if(_useCookie) + { + Cookie cookie = (Cookie)result.AsyncState; + cmp = cookie.getString(); + } + + byte[] outParams; + if(result.getProxy().end_ice_invoke(out outParams, result)) + { + Ice.InputStream inS = Ice.Util.createInputStream(_communicator, outParams); + string s = inS.readString(); + test(s.Equals(cmp)); + s = inS.readString(); + test(s.Equals(cmp)); + callback.called(); + } + else + { + test(false); + } + } + + public void opStringNC(bool ok, byte[] outParams) + { + if(ok) + { + Ice.InputStream inS = Ice.Util.createInputStream(_communicator, outParams); + string s = inS.readString(); + test(s.Equals(testString)); + s = inS.readString(); + test(s.Equals(testString)); + callback.called(); + } + else + { + test(false); + } + } + + public void opException(Ice.AsyncResult result) + { + if(_useCookie) + { + Cookie cookie = (Cookie)result.AsyncState; + test(cookie.getString().Equals(testString)); + } + + byte[] outParams; + if(result.getProxy().end_ice_invoke(out outParams, result)) + { + test(false); + } + else + { + Ice.InputStream inS = Ice.Util.createInputStream(_communicator, outParams); + try + { + inS.throwException(); + } + catch(Test.MyException) + { + callback.called(); + } + catch(System.Exception) + { + test(false); + } + } + } + + public void opExceptionNC(bool ok, byte[] outParams) + { + if(ok) + { + test(false); + } + else + { + Ice.InputStream inS = Ice.Util.createInputStream(_communicator, outParams); + try + { + inS.throwException(); + } + catch(Test.MyException) + { + callback.called(); + } + catch(System.Exception) + { + test(false); + } + } + } + + public virtual void check() + { + callback.check(); + } + + private Ice.Communicator _communicator; + private bool _useCookie; + + private CallbackBase callback = new CallbackBase(); + } + + public static Test.MyClassPrx allTests(Ice.Communicator communicator) + { + Ice.ObjectPrx baseProxy = communicator.stringToProxy("test:default -p 12010"); + Test.MyClassPrx cl = Test.MyClassPrxHelper.checkedCast(baseProxy); + + Console.Out.Write("testing ice_invoke... "); + Console.Out.Flush(); + + { + byte[] inParams, outParams; + Ice.OutputStream outS = Ice.Util.createOutputStream(communicator); + outS.writeString(testString); + inParams = outS.finished(); + + if(cl.ice_invoke("opString", Ice.OperationMode.Normal, inParams, out outParams)) + { + Ice.InputStream inS = Ice.Util.createInputStream(communicator, outParams); + string s = inS.readString(); + test(s.Equals(testString)); + s = inS.readString(); + test(s.Equals(testString)); + } + else + { + test(false); + } + } + + { + byte[] outParams; + if(cl.ice_invoke("opException", Ice.OperationMode.Normal, null, out outParams)) + { + test(false); + } + else + { + Ice.InputStream inS = Ice.Util.createInputStream(communicator, outParams); + try + { + inS.throwException(); + } + catch(Test.MyException) + { + } + catch(System.Exception) + { + test(false); + } + } + } + + Console.Out.WriteLine("ok"); + + Console.Out.Write("testing asynchronous ice_invoke... "); + Console.Out.Flush(); + + { + byte[] inParams, outParams; + Ice.OutputStream outS = Ice.Util.createOutputStream(communicator); + outS.writeString(testString); + inParams = outS.finished(); + + // begin_ice_invoke with no callback + Ice.AsyncResult result = cl.begin_ice_invoke("opString", Ice.OperationMode.Normal, inParams); + if(cl.end_ice_invoke(out outParams, result)) + { + Ice.InputStream inS = Ice.Util.createInputStream(communicator, outParams); + string s = inS.readString(); + test(s.Equals(testString)); + s = inS.readString(); + test(s.Equals(testString)); + } + else + { + test(false); + } + + // begin_ice_invoke with Callback + Callback cb = new Callback(communicator, false); + cl.begin_ice_invoke("opString", Ice.OperationMode.Normal, inParams, cb.opString, null); + cb.check(); + + // begin_ice_invoke with Callback with cookie + cb = new Callback(communicator, true); + cl.begin_ice_invoke("opString", Ice.OperationMode.Normal, inParams, cb.opString, new Cookie()); + cb.check(); + + // begin_ice_invoke with Callback_Object_ice_invoke + cb = new Callback(communicator, true); + cl.begin_ice_invoke("opString", Ice.OperationMode.Normal, inParams).whenCompleted(cb.opStringNC); + cb.check(); + } + + { + // begin_ice_invoke with no callback + Ice.AsyncResult result = cl.begin_ice_invoke("opException", Ice.OperationMode.Normal, null); + byte[] outParams; + if(cl.end_ice_invoke(out outParams, result)) + { + test(false); + } + else + { + Ice.InputStream inS = Ice.Util.createInputStream(communicator, outParams); + try + { + inS.throwException(); + } + catch(Test.MyException) + { + } + catch(System.Exception) + { + test(false); + } + } + + // begin_ice_invoke with Callback + Callback cb = new Callback(communicator, false); + cl.begin_ice_invoke("opException", Ice.OperationMode.Normal, null, cb.opException, null); + cb.check(); + + // begin_ice_invoke with Callback with cookie + cb = new Callback(communicator, true); + cl.begin_ice_invoke("opException", Ice.OperationMode.Normal, null, cb.opException, new Cookie()); + cb.check(); + + // begin_ice_invoke with Callback_Object_ice_invoke + cb = new Callback(communicator, true); + cl.begin_ice_invoke("opException", Ice.OperationMode.Normal, null).whenCompleted(cb.opExceptionNC); + cb.check(); + } + + Console.Out.WriteLine("ok"); + + return cl; + } +} diff --git a/cs/test/Ice/invoke/BlobjectI.cs b/cs/test/Ice/invoke/BlobjectI.cs new file mode 100644 index 00000000000..20d494e02a1 --- /dev/null +++ b/cs/test/Ice/invoke/BlobjectI.cs @@ -0,0 +1,112 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 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. +// +// ********************************************************************** + +public class BlobjectI : Ice.Blobject +{ + public override bool + ice_invoke(byte[] inParams, out byte[] outParams, Ice.Current current) + { + Ice.Communicator communicator = current.adapter.getCommunicator(); + Ice.InputStream inS = Ice.Util.createInputStream(communicator, inParams); + Ice.OutputStream outS = Ice.Util.createOutputStream(communicator); + if(current.operation.Equals("opString")) + { + string s = inS.readString(); + outS.writeString(s); + outS.writeString(s); + outParams = outS.finished(); + return true; + } + else if(current.operation.Equals("opException")) + { + Test.MyException ex = new Test.MyException(); + outS.writeException(ex); + outParams = outS.finished(); + return false; + } + else if(current.operation.Equals("shutdown")) + { + communicator.shutdown(); + outParams = null; + return true; + } + else if(current.operation.Equals("ice_isA")) + { + string s = inS.readString(); + if(s.Equals("::Test::MyClass")) + { + outS.writeBool(true); + } + else + { + outS.writeBool(false); + } + outParams = outS.finished(); + return true; + } + else + { + Ice.OperationNotExistException ex = new Ice.OperationNotExistException(); + ex.id = current.id; + ex.facet = current.facet; + ex.operation = current.operation; + throw ex; + } + } +} + +public class BlobjectAsyncI : Ice.BlobjectAsync +{ + public override void + ice_invoke_async(Ice.AMD_Object_ice_invoke cb, byte[] inParams, Ice.Current current) + { + Ice.Communicator communicator = current.adapter.getCommunicator(); + Ice.InputStream inS = Ice.Util.createInputStream(communicator, inParams); + Ice.OutputStream outS = Ice.Util.createOutputStream(communicator); + if(current.operation.Equals("opString")) + { + string s = inS.readString(); + outS.writeString(s); + outS.writeString(s); + cb.ice_response(true, outS.finished()); + } + else if(current.operation.Equals("opException")) + { + Test.MyException ex = new Test.MyException(); + outS.writeException(ex); + cb.ice_response(false, outS.finished()); + } + else if(current.operation.Equals("shutdown")) + { + communicator.shutdown(); + cb.ice_response(true, null); + } + else if(current.operation.Equals("ice_isA")) + { + string s = inS.readString(); + if(s.Equals("::Test::MyClass")) + { + outS.writeBool(true); + } + else + { + outS.writeBool(false); + } + cb.ice_response(true, outS.finished()); + } + else + { + Ice.OperationNotExistException ex = new Ice.OperationNotExistException(); + ex.id = current.id; + ex.facet = current.facet; + ex.operation = current.operation; + throw ex; + } + } +} diff --git a/cs/test/Ice/invoke/Client.cs b/cs/test/Ice/invoke/Client.cs new file mode 100644 index 00000000000..1442e43a025 --- /dev/null +++ b/cs/test/Ice/invoke/Client.cs @@ -0,0 +1,67 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 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. +// +// ********************************************************************** + +using System; +using System.Diagnostics; +using System.Reflection; + +[assembly: CLSCompliant(true)] + +[assembly: AssemblyTitle("IceTest")] +[assembly: AssemblyDescription("Ice test")] +[assembly: AssemblyCompany("ZeroC, Inc.")] + +public class Client +{ + private static int run(String[] args, Ice.Communicator communicator) + { + Test.MyClassPrx myClass = AllTests.allTests(communicator); + myClass.shutdown(); + return 0; + } + + public static void Main(string[] args) + { + int status = 0; + Ice.Communicator communicator = null; + + Debug.Listeners.Add(new ConsoleTraceListener()); + + try + { + Ice.InitializationData initData = new Ice.InitializationData(); + initData.properties = Ice.Util.createProperties(ref args); + communicator = Ice.Util.initialize(ref args, initData); + status = run(args, communicator); + } + catch(System.Exception ex) + { + Console.Error.WriteLine(ex); + status = 1; + } + + if(communicator != null) + { + try + { + communicator.destroy(); + } + catch(Ice.LocalException ex) + { + Console.Error.WriteLine(ex); + status = 1; + } + } + + if(status != 0) + { + System.Environment.Exit(status); + } + } +} diff --git a/cs/test/Ice/invoke/Makefile b/cs/test/Ice/invoke/Makefile new file mode 100644 index 00000000000..c9684646562 --- /dev/null +++ b/cs/test/Ice/invoke/Makefile @@ -0,0 +1,35 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2009 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. +# +# ********************************************************************** + +top_srcdir = ../../.. + +TARGETS = client.exe server.exe + +C_SRCS = AllTests.cs Client.cs +S_SRCS = BlobjectI.cs Server.cs + +SLICE_SRCS = $(SDIR)/Test.ice + +SDIR = . + +GDIR = generated + +include $(top_srcdir)/config/Make.rules.cs + +MCSFLAGS := $(MCSFLAGS) -target:exe + +SLICE2CSFLAGS := $(SLICE2CSFLAGS) --ice -I. -I$(slicedir) + +client.exe: $(C_SRCS) $(GEN_SRCS) + $(MCS) $(MCSFLAGS) -out:$@ $(call ref,Ice) $(subst /,$(DSEP),$^) + +server.exe: $(S_SRCS) $(GEN_SRCS) + $(MCS) $(MCSFLAGS) -out:$@ $(call ref,Ice) $(subst /,$(DSEP),$^) + +include .depend diff --git a/cs/test/Ice/invoke/Makefile.mak b/cs/test/Ice/invoke/Makefile.mak new file mode 100644 index 00000000000..0dbe2c34df1 --- /dev/null +++ b/cs/test/Ice/invoke/Makefile.mak @@ -0,0 +1,35 @@ +# **********************************************************************
+#
+# Copyright (c) 2003-2009 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.
+#
+# **********************************************************************
+
+top_srcdir = ..\..\..
+
+TARGETS = client.exe server.exe
+
+C_SRCS = AllTests.cs Client.cs
+S_SRCS = Server.cs BlobjectI.cs
+
+GEN_SRCS = $(GDIR)\Test.cs
+
+SDIR = .
+
+GDIR = generated
+
+!include $(top_srcdir)\config\Make.rules.mak.cs
+
+MCSFLAGS = $(MCSFLAGS) -target:exe
+
+SLICE2CSFLAGS = $(SLICE2CSFLAGS) --ice -I. -I$(slicedir)
+
+client.exe: $(C_SRCS) $(GEN_SRCS)
+ $(MCS) $(MCSFLAGS) -out:$@ -r:$(refdir)\Ice.dll $(C_SRCS) $(GEN_SRCS)
+
+server.exe: $(S_SRCS) $(GEN_SRCS)
+ $(MCS) $(MCSFLAGS) -out:$@ -r:$(refdir)\Ice.dll $(S_SRCS) $(GEN_SRCS)
+
+!include .depend
diff --git a/cs/test/Ice/invoke/Server.cs b/cs/test/Ice/invoke/Server.cs new file mode 100644 index 00000000000..20e0b9603c7 --- /dev/null +++ b/cs/test/Ice/invoke/Server.cs @@ -0,0 +1,115 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 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. +// +// ********************************************************************** + +using System; +using System.Diagnostics; +using System.Reflection; + +[assembly: CLSCompliant(true)] + +[assembly: AssemblyTitle("IceTest")] +[assembly: AssemblyDescription("Ice test")] +[assembly: AssemblyCompany("ZeroC, Inc.")] + +public class ServantLocatorI : Ice.ServantLocator +{ + public ServantLocatorI(bool async) + { + if(async) + { + _blobject = new BlobjectAsyncI(); + } + else + { + _blobject = new BlobjectI(); + } + } + + public Ice.Object + locate(Ice.Current current, out System.Object cookie) + { + cookie = null; + return _blobject; + } + + public void + finished(Ice.Current current, Ice.Object servant, System.Object cookie) + { + } + + public void + deactivate(string category) + { + } + + private Ice.Object _blobject; +} + +public class Server +{ + public static int run(string[] args, Ice.Communicator communicator) + { + bool async = false; + for(int i = 0; i < args.Length; ++i) + { + if(args[i].Equals("--async")) + { + async = true; + } + } + + communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010:udp"); + Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter"); + adapter.addServantLocator(new ServantLocatorI(async), ""); + adapter.activate(); + + communicator.waitForShutdown(); + return 0; + } + + public static void Main(string[] args) + { + int status = 0; + Ice.Communicator communicator = null; + + Debug.Listeners.Add(new ConsoleTraceListener()); + + try + { + Ice.InitializationData initData = new Ice.InitializationData(); + initData.properties = Ice.Util.createProperties(ref args); + communicator = Ice.Util.initialize(ref args, initData); + status = run(args, communicator); + } + catch(System.Exception ex) + { + Console.Error.WriteLine(ex); + status = 1; + } + + if(communicator != null) + { + try + { + communicator.destroy(); + } + catch(Ice.LocalException ex) + { + Console.Error.WriteLine(ex); + status = 1; + } + } + + if(status != 0) + { + System.Environment.Exit(status); + } + } + +} diff --git a/cs/test/Ice/invoke/Test.ice b/cs/test/Ice/invoke/Test.ice new file mode 100644 index 00000000000..77492c307db --- /dev/null +++ b/cs/test/Ice/invoke/Test.ice @@ -0,0 +1,32 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 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. +// +// ********************************************************************** + +#ifndef TEST_ICE +#define TEST_ICE + +[["java:package:test.Ice.invoke"]] +module Test +{ + +exception MyException +{ +}; + +class MyClass +{ + string opString(string s1, out string s2); + + void opException() throws MyException; + + void shutdown(); +}; + +}; + +#endif diff --git a/cs/test/Ice/invoke/run.py b/cs/test/Ice/invoke/run.py new file mode 100755 index 00000000000..47f6323efaa --- /dev/null +++ b/cs/test/Ice/invoke/run.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise "can't find toplevel directory!" +sys.path.append(os.path.join(path[0])) +from scripts import * + +print "tests with Blobject server." +TestUtil.clientServerTest() + +print "tests with BlobjectAsync server." +TestUtil.clientServerTest(additionalServerOptions = "--async") + diff --git a/demoscript/Ice/invoke.py b/demoscript/Ice/invoke.py index 8ea8e0fba76..1c329ca7b45 100644 --- a/demoscript/Ice/invoke.py +++ b/demoscript/Ice/invoke.py @@ -51,16 +51,6 @@ def run(clientStr, server): runDemo(client, server) - client.sendline('x') - client.waitTestSuccess() - print "ok" - - print "testing async...", - client = Util.spawn(clientStr + ' --async') - client.expect('==>') - - runDemo(client, server) - client.sendline('s') server.waitTestSuccess() diff --git a/java/allTests.py b/java/allTests.py index 8b6874a4914..ac632fc1b5e 100755 --- a/java/allTests.py +++ b/java/allTests.py @@ -62,6 +62,7 @@ tests = [ ("Ice/defaultServant", ["core"]), ("Ice/threadPoolPriority", ["core"]), ("Ice/classLoader", ["core"]), + ("Ice/invoke", ["core"]), ("IceBox/configuration", ["core", "noipv6"]), ("Freeze/dbmap", ["once"]), ("Freeze/complex", ["once"]), diff --git a/java/build.xml b/java/build.xml index 56c8b93b054..510cc11b733 100644 --- a/java/build.xml +++ b/java/build.xml @@ -291,6 +291,9 @@ <fileset dir="test/Ice/interceptor"> <include name="Test.ice" /> </fileset> + <fileset dir="test/Ice/invoke"> + <include name="Test.ice" /> + </fileset> <fileset dir="test/Ice/location"> <include name="Test.ice" /> </fileset> diff --git a/java/demo/Ice/invoke/Client.java b/java/demo/Ice/invoke/Client.java index 50664b8931e..8ab0ea28158 100644 --- a/java/demo/Ice/invoke/Client.java +++ b/java/demo/Ice/invoke/Client.java @@ -11,97 +11,6 @@ import Demo.*; public class Client extends Ice.Application { - private class CallbackI extends Ice.AsyncCallback - { - @Override - public void completed(Ice.AsyncResult r) - { - Ice.ByteSeqHolder outParams = new Ice.ByteSeqHolder(); - try - { - if(!r.getProxy().end_ice_invoke(outParams, r)) - { - System.out.println("Unknown user exception"); - } - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - } - } - } - - private class Callback_getValuesI extends Ice.AsyncCallback - { - @Override - public void completed(Ice.AsyncResult r) - { - Ice.ByteSeqHolder outParams = new Ice.ByteSeqHolder(); - try - { - if(r.getProxy().end_ice_invoke(outParams, r)) - { - // - // Unmarshal the results. - // - Ice.InputStream in = Ice.Util.createInputStream(communicator(), outParams.value); - Demo.CHolder c = new Demo.CHolder(); - Demo.CHelper.read(in, c); - String str = in.readString(); - in.readPendingObjects(); - in.destroy(); - System.out.println("Got string `" + str + "' and class: s.name=" + c.value.s.name + - ", s.value=" + c.value.s.value); - } - else - { - System.out.println("Unknown user exception"); - } - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - } - } - } - - private class Callback_throwPrintFailureI extends Ice.AsyncCallback - { - @Override - public void completed(Ice.AsyncResult r) - { - Ice.ByteSeqHolder outParams = new Ice.ByteSeqHolder(); - try - { - if(!r.getProxy().end_ice_invoke(outParams, r)) - { - Ice.InputStream in = Ice.Util.createInputStream(communicator(), outParams.value); - try - { - in.throwException(); - } - catch(Demo.PrintFailure ex) - { - // Expected. - } - catch(Ice.UserException ex) - { - System.out.println("Unknown user exception"); - } - in.destroy(); - } - else - { - System.out.println("Expected user exception"); - } - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - } - } - } - private static void menu() { @@ -140,14 +49,9 @@ public class Client extends Ice.Application public int run(String[] args) { - boolean async = false; - if(args.length == 1 && args[0].equals("--async")) - { - async = true; - } - else if(args.length > 0) + if(args.length > 0) { - System.err.println("Usage: " + appName() + " [--async]"); + System.err.println(appName() + ": too many arguments"); return 1; } @@ -187,16 +91,9 @@ public class Client extends Ice.Application // // Invoke operation. // - if(async) + if(!obj.ice_invoke("printString", Ice.OperationMode.Normal, out.finished(), null)) { - obj.begin_ice_invoke("printString", Ice.OperationMode.Normal, out.finished(), new CallbackI()); - } - else - { - if(!obj.ice_invoke("printString", Ice.OperationMode.Normal, out.finished(), null)) - { - System.out.println("Unknown user exception"); - } + System.out.println("Unknown user exception"); } out.destroy(); @@ -213,17 +110,9 @@ public class Client extends Ice.Application // // Invoke operation. // - if(async) + if(!obj.ice_invoke("printStringSequence", Ice.OperationMode.Normal, out.finished(), null)) { - obj.begin_ice_invoke("printStringSequence", Ice.OperationMode.Normal, out.finished(), - new CallbackI()); - } - else - { - if(!obj.ice_invoke("printStringSequence", Ice.OperationMode.Normal, out.finished(), null)) - { - System.out.println("Unknown user exception"); - } + System.out.println("Unknown user exception"); } out.destroy(); @@ -242,17 +131,9 @@ public class Client extends Ice.Application // // Invoke operation. // - if(async) - { - obj.begin_ice_invoke("printDictionary", Ice.OperationMode.Normal, out.finished(), - new CallbackI()); - } - else + if(!obj.ice_invoke("printDictionary", Ice.OperationMode.Normal, out.finished(), null)) { - if(!obj.ice_invoke("printDictionary", Ice.OperationMode.Normal, out.finished(), null)) - { - System.out.println("Unknown user exception"); - } + System.out.println("Unknown user exception"); } out.destroy(); @@ -268,16 +149,9 @@ public class Client extends Ice.Application // // Invoke operation. // - if(async) - { - obj.begin_ice_invoke("printEnum", Ice.OperationMode.Normal, out.finished(), new CallbackI()); - } - else + if(!obj.ice_invoke("printEnum", Ice.OperationMode.Normal, out.finished(), null)) { - if(!obj.ice_invoke("printEnum", Ice.OperationMode.Normal, out.finished(), null)) - { - System.out.println("Unknown user exception"); - } + System.out.println("Unknown user exception"); } out.destroy(); @@ -296,16 +170,9 @@ public class Client extends Ice.Application // // Invoke operation. // - if(async) + if(!obj.ice_invoke("printStruct", Ice.OperationMode.Normal, out.finished(), null)) { - obj.begin_ice_invoke("printStruct", Ice.OperationMode.Normal, out.finished(), new CallbackI()); - } - else - { - if(!obj.ice_invoke("printStruct", Ice.OperationMode.Normal, out.finished(), null)) - { - System.out.println("Unknown user exception"); - } + System.out.println("Unknown user exception"); } out.destroy(); @@ -331,17 +198,9 @@ public class Client extends Ice.Application // // Invoke operation. // - if(async) + if(!obj.ice_invoke("printStructSequence", Ice.OperationMode.Normal, out.finished(), null)) { - obj.begin_ice_invoke("printStructSequence", Ice.OperationMode.Normal, out.finished(), - new CallbackI()); - } - else - { - if(!obj.ice_invoke("printStructSequence", Ice.OperationMode.Normal, out.finished(), null)) - { - System.out.println("Unknown user exception"); - } + System.out.println("Unknown user exception"); } out.destroy(); @@ -362,16 +221,9 @@ public class Client extends Ice.Application // // Invoke operation. // - if(async) - { - obj.begin_ice_invoke("printClass", Ice.OperationMode.Normal, out.finished(), new CallbackI()); - } - else + if(!obj.ice_invoke("printClass", Ice.OperationMode.Normal, out.finished(), null)) { - if(!obj.ice_invoke("printClass", Ice.OperationMode.Normal, out.finished(), null)) - { - System.out.println("Unknown user exception"); - } + System.out.println("Unknown user exception"); } out.destroy(); @@ -382,30 +234,23 @@ public class Client extends Ice.Application // Invoke operation. // Ice.ByteSeqHolder outParams = new Ice.ByteSeqHolder(); - if(async) + if(!obj.ice_invoke("getValues", Ice.OperationMode.Normal, null, outParams)) { - obj.begin_ice_invoke("getValues", Ice.OperationMode.Normal, null, new Callback_getValuesI()); + System.out.println("Unknown user exception"); + continue; } - else - { - if(!obj.ice_invoke("getValues", Ice.OperationMode.Normal, null, outParams)) - { - System.out.println("Unknown user exception"); - continue; - } - // - // Unmarshal the results. - // - Ice.InputStream in = Ice.Util.createInputStream(communicator(), outParams.value); - Demo.CHolder c = new Demo.CHolder(); - Demo.CHelper.read(in, c); - String str = in.readString(); - in.readPendingObjects(); - in.destroy(); - System.out.println("Got string `" + str + "' and class: s.name=" + c.value.s.name + - ", s.value=" + c.value.s.value); - } + // + // Unmarshal the results. + // + Ice.InputStream in = Ice.Util.createInputStream(communicator(), outParams.value); + Demo.CHolder c = new Demo.CHolder(); + Demo.CHelper.read(in, c); + String str = in.readString(); + in.readPendingObjects(); + in.destroy(); + System.out.println("Got string `" + str + "' and class: s.name=" + c.value.s.name + + ", s.value=" + c.value.s.value); } else if(line.equals("9")) { @@ -413,45 +258,30 @@ public class Client extends Ice.Application // Invoke operation. // Ice.ByteSeqHolder outParams = new Ice.ByteSeqHolder(); - if(async) + if(obj.ice_invoke("throwPrintFailure", Ice.OperationMode.Normal, null, outParams)) { - obj.begin_ice_invoke("throwPrintFailure", Ice.OperationMode.Normal, null, - new Callback_throwPrintFailureI()); + System.out.println("Expected exception"); + continue; } - else - { - if(obj.ice_invoke("throwPrintFailure", Ice.OperationMode.Normal, null, outParams)) - { - System.out.println("Expected exception"); - continue; - } - Ice.InputStream in = Ice.Util.createInputStream(communicator(), outParams.value); - try - { - in.throwException(); - } - catch(Demo.PrintFailure ex) - { - // Expected. - } - catch(Ice.UserException ex) - { - System.out.println("Unknown user exception"); - } - in.destroy(); + Ice.InputStream in = Ice.Util.createInputStream(communicator(), outParams.value); + try + { + in.throwException(); } - } - else if(line.equals("s")) - { - if(async) + catch(Demo.PrintFailure ex) { - obj.begin_ice_invoke("shutdown", Ice.OperationMode.Normal, null, new CallbackI()); + // Expected. } - else + catch(Ice.UserException ex) { - obj.ice_invoke("shutdown", Ice.OperationMode.Normal, null, null); + System.out.println("Unknown user exception"); } + in.destroy(); + } + else if(line.equals("s")) + { + obj.ice_invoke("shutdown", Ice.OperationMode.Normal, null, null); } else if(line.equals("x")) { diff --git a/java/demo/Ice/invoke/README b/java/demo/Ice/invoke/README index 954932fbce4..cd086ebeb42 100644 --- a/java/demo/Ice/invoke/README +++ b/java/demo/Ice/invoke/README @@ -7,7 +7,3 @@ $ java Server In a separate window, start the client: $ java Client - -To run the client using asynchronous calls use: - -$ java Client --async diff --git a/java/test/Ice/invoke/AllTests.java b/java/test/Ice/invoke/AllTests.java new file mode 100644 index 00000000000..c5555231f0c --- /dev/null +++ b/java/test/Ice/invoke/AllTests.java @@ -0,0 +1,355 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 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. +// +// ********************************************************************** + +package test.Ice.invoke; +import java.io.PrintWriter; + +import test.Ice.invoke.Test.MyClassPrx; +import test.Ice.invoke.Test.MyClassPrxHelper; +import test.Ice.invoke.Test.MyException; + +public class AllTests +{ + final static String testString = "This is a test string"; + + private static void + test(boolean b) + { + if(!b) + { + throw new RuntimeException(); + } + } + + private static class Callback + { + Callback() + { + _called = false; + } + + public synchronized void check() + { + while(!_called) + { + try + { + wait(); + } + catch(InterruptedException ex) + { + } + } + + _called = false; + } + + public synchronized void called() + { + assert(!_called); + _called = true; + notify(); + } + + private boolean _called; + } + + private static class opStringI extends Ice.AsyncCallback + { + public opStringI(Ice.Communicator communicator) + { + _communicator = communicator; + } + + @Override + public void completed(Ice.AsyncResult result) + { + Ice.ByteSeqHolder outParams = new Ice.ByteSeqHolder(); + if(result.getProxy().end_ice_invoke(outParams, result)) + { + Ice.InputStream inS = Ice.Util.createInputStream(_communicator, outParams.value); + String s = inS.readString(); + test(s.equals(testString)); + s = inS.readString(); + test(s.equals(testString)); + callback.called(); + } + else + { + test(false); + } + } + + public void check() + { + callback.check(); + } + + private Ice.Communicator _communicator; + private Callback callback = new Callback(); + } + + private static class opExceptionI extends Ice.AsyncCallback + { + public opExceptionI(Ice.Communicator communicator) + { + _communicator = communicator; + } + + @Override + public void completed(Ice.AsyncResult result) + { + Ice.ByteSeqHolder outParams = new Ice.ByteSeqHolder(); + if(result.getProxy().end_ice_invoke(outParams, result)) + { + test(false); + } + else + { + Ice.InputStream inS = Ice.Util.createInputStream(_communicator, outParams.value); + try + { + inS.throwException(); + } + catch(Test.MyException ex) + { + callback.called(); + } + catch(java.lang.Exception ex) + { + test(false); + } + } + } + + public void check() + { + callback.check(); + } + + private Ice.Communicator _communicator; + private Callback callback = new Callback(); + } + + private static class Callback_Object_opStringI extends Ice.Callback_Object_ice_invoke + { + public Callback_Object_opStringI(Ice.Communicator communicator) + { + _communicator = communicator; + } + + @Override + public void response(boolean ok, byte[] outParams) + { + if(ok) + { + Ice.InputStream inS = Ice.Util.createInputStream(_communicator, outParams); + String s = inS.readString(); + test(s.equals(testString)); + s = inS.readString(); + test(s.equals(testString)); + callback.called(); + } + else + { + test(false); + } + } + + @Override + public void exception(Ice.LocalException ex) + { + test(false); + } + + public void check() + { + callback.check(); + } + + private Ice.Communicator _communicator; + private Callback callback = new Callback(); + } + + private static class Callback_Object_opExceptionI extends Ice.Callback_Object_ice_invoke + { + public Callback_Object_opExceptionI(Ice.Communicator communicator) + { + _communicator = communicator; + } + + @Override + public void response(boolean ok, byte[] outParams) + { + if(ok) + { + test(false); + } + else + { + Ice.InputStream inS = Ice.Util.createInputStream(_communicator, outParams); + try + { + inS.throwException(); + } + catch(Test.MyException ex) + { + callback.called(); + } + catch(java.lang.Exception ex) + { + test(false); + } + } + } + + @Override + public void exception(Ice.LocalException ex) + { + test(false); + } + + public void check() + { + callback.check(); + } + + private Ice.Communicator _communicator; + private Callback callback = new Callback(); + } + + public static MyClassPrx + allTests(Ice.Communicator communicator, PrintWriter out) + { + String ref = "test:default -p 12010"; + Ice.ObjectPrx base = communicator.stringToProxy(ref); + MyClassPrx cl = MyClassPrxHelper.checkedCast(base); + + out.print("testing ice_invoke... "); + out.flush(); + + { + Ice.OutputStream outS = Ice.Util.createOutputStream(communicator); + outS.writeString(testString); + byte[] inParams = outS.finished(); + Ice.ByteSeqHolder outParams = new Ice.ByteSeqHolder(); + if(cl.ice_invoke("opString", Ice.OperationMode.Normal, inParams, outParams)) + { + Ice.InputStream inS = Ice.Util.createInputStream(communicator, outParams.value); + String s = inS.readString(); + test(s.equals(testString)); + s = inS.readString(); + test(s.equals(testString)); + } + else + { + test(false); + } + } + + { + Ice.ByteSeqHolder outParams = new Ice.ByteSeqHolder(); + if(cl.ice_invoke("opException", Ice.OperationMode.Normal, null, outParams)) + { + test(false); + } + else + { + Ice.InputStream inS = Ice.Util.createInputStream(communicator, outParams.value); + try + { + inS.throwException(); + } + catch(Test.MyException ex) + { + } + catch(java.lang.Exception ex) + { + test(false); + } + } + } + + out.println("ok"); + + out.print("testing asynchronous ice_invoke... "); + out.flush(); + + { + Ice.OutputStream outS = Ice.Util.createOutputStream(communicator); + outS.writeString(testString); + byte[] inParams = outS.finished(); + + // begin_ice_invoke with no callback + Ice.AsyncResult result = cl.begin_ice_invoke("opString", Ice.OperationMode.Normal, inParams); + Ice.ByteSeqHolder outParams = new Ice.ByteSeqHolder(); + if(cl.end_ice_invoke(outParams, result)) + { + Ice.InputStream inS = Ice.Util.createInputStream(communicator, outParams.value); + String s = inS.readString(); + test(s.equals(testString)); + s = inS.readString(); + test(s.equals(testString)); + } + else + { + test(false); + } + + // begin_ice_invoke with Callback + opStringI cb1 = new opStringI(communicator); + cl.begin_ice_invoke("opString", Ice.OperationMode.Normal, inParams, cb1); + cb1.check(); + + // begin_ice_invoke with Callback_Object_ice_invoke + Callback_Object_opStringI cb2 = new Callback_Object_opStringI(communicator); + cl.begin_ice_invoke("opString", Ice.OperationMode.Normal, inParams, cb2); + cb2.check(); + } + + { + // begin_ice_invoke with no callback + Ice.AsyncResult result = cl.begin_ice_invoke("opException", Ice.OperationMode.Normal, null); + Ice.ByteSeqHolder outParams = new Ice.ByteSeqHolder(); + if(cl.end_ice_invoke(outParams, result)) + { + test(false); + } + else + { + Ice.InputStream inS = Ice.Util.createInputStream(communicator, outParams.value); + try + { + inS.throwException(); + } + catch(Test.MyException ex) + { + } + catch(java.lang.Exception ex) + { + test(false); + } + } + + // begin_ice_invoke with Callback + opExceptionI cb1 = new opExceptionI(communicator); + cl.begin_ice_invoke("opException", Ice.OperationMode.Normal, null, cb1); + cb1.check(); + + // begin_ice_invoke with Callback_Object_ice_invoke + Callback_Object_opExceptionI cb2 = new Callback_Object_opExceptionI(communicator); + cl.begin_ice_invoke("opException", Ice.OperationMode.Normal, null, cb2); + cb2.check(); + } + + out.println("ok"); + + return cl; + } +} diff --git a/java/test/Ice/invoke/BlobjectAsyncI.java b/java/test/Ice/invoke/BlobjectAsyncI.java new file mode 100644 index 00000000000..07f00734d13 --- /dev/null +++ b/java/test/Ice/invoke/BlobjectAsyncI.java @@ -0,0 +1,62 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 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. +// +// ********************************************************************** + +package test.Ice.invoke; + +import test.Ice.invoke.Test.MyException; + +public class BlobjectAsyncI extends Ice.BlobjectAsync +{ + public void + ice_invoke_async(Ice.AMD_Object_ice_invoke cb, byte[] inParams, Ice.Current current) + { + Ice.Communicator communicator = current.adapter.getCommunicator(); + Ice.InputStream in = Ice.Util.createInputStream(communicator, inParams); + Ice.OutputStream out = Ice.Util.createOutputStream(communicator); + if(current.operation.equals("opString")) + { + String s = in.readString(); + out.writeString(s); + out.writeString(s); + cb.ice_response(true, out.finished()); + } + else if(current.operation.equals("opException")) + { + MyException ex = new MyException(); + out.writeException(ex); + cb.ice_response(false, out.finished()); + } + else if(current.operation.equals("shutdown")) + { + communicator.shutdown(); + cb.ice_response(true, null); + } + else if(current.operation.equals("ice_isA")) + { + String s = in.readString(); + if(s.equals("::Test::MyClass")) + { + out.writeBool(true); + } + else + { + out.writeBool(false); + } + cb.ice_response(true, out.finished()); + } + else + { + Ice.OperationNotExistException ex = new Ice.OperationNotExistException(); + ex.id = current.id; + ex.facet = current.facet; + ex.operation = current.operation; + throw ex; + } + } +} diff --git a/java/test/Ice/invoke/BlobjectI.java b/java/test/Ice/invoke/BlobjectI.java new file mode 100644 index 00000000000..e667155af05 --- /dev/null +++ b/java/test/Ice/invoke/BlobjectI.java @@ -0,0 +1,65 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 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. +// +// ********************************************************************** + +package test.Ice.invoke; + +import test.Ice.invoke.Test.MyException; + +public class BlobjectI extends Ice.Blobject +{ + public boolean + ice_invoke(byte[] inParams, Ice.ByteSeqHolder outParams, Ice.Current current) + { + Ice.Communicator communicator = current.adapter.getCommunicator(); + Ice.InputStream in = Ice.Util.createInputStream(communicator, inParams); + Ice.OutputStream out = Ice.Util.createOutputStream(communicator); + if(current.operation.equals("opString")) + { + String s = in.readString(); + out.writeString(s); + out.writeString(s); + outParams.value = out.finished(); + return true; + } + else if(current.operation.equals("opException")) + { + MyException ex = new MyException(); + out.writeException(ex); + outParams.value = out.finished(); + return false; + } + else if(current.operation.equals("shutdown")) + { + communicator.shutdown(); + return true; + } + else if(current.operation.equals("ice_isA")) + { + String s = in.readString(); + if(s.equals("::Test::MyClass")) + { + out.writeBool(true); + } + else + { + out.writeBool(false); + } + outParams.value = out.finished(); + return true; + } + else + { + Ice.OperationNotExistException ex = new Ice.OperationNotExistException(); + ex.id = current.id; + ex.facet = current.facet; + ex.operation = current.operation; + throw ex; + } + } +} diff --git a/java/test/Ice/invoke/Client.java b/java/test/Ice/invoke/Client.java new file mode 100644 index 00000000000..b987c4e3348 --- /dev/null +++ b/java/test/Ice/invoke/Client.java @@ -0,0 +1,40 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 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. +// +// ********************************************************************** + +package test.Ice.invoke; + +import test.Ice.invoke.Test.MyClassPrx; + +public class Client extends test.Util.Application +{ + public int run(String[] args) + { + MyClassPrx myClass = AllTests.allTests(communicator(), getWriter()); + myClass.shutdown(); + + return 0; + } + + protected Ice.InitializationData getInitData(Ice.StringSeqHolder argsH) + { + Ice.InitializationData initData = new Ice.InitializationData(); + initData.properties = Ice.Util.createProperties(argsH); + initData.properties.setProperty("Ice.Package.Test", "test.Ice.invoke"); + return initData; + } + + public static void main(String[] args) + { + Client c = new Client(); + int status = c.main("Client", args); + + System.gc(); + System.exit(status); + } +} diff --git a/java/test/Ice/invoke/ServantLocatorI.java b/java/test/Ice/invoke/ServantLocatorI.java new file mode 100644 index 00000000000..1e8cd3a3325 --- /dev/null +++ b/java/test/Ice/invoke/ServantLocatorI.java @@ -0,0 +1,43 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 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. +// +// ********************************************************************** + +package test.Ice.invoke; + +public class ServantLocatorI implements Ice.ServantLocator +{ + public ServantLocatorI( boolean async) + { + if(async) + { + _blobject = new BlobjectAsyncI(); + } + else + { + _blobject = new BlobjectI(); + } + } + + public Ice.Object + locate(Ice.Current current, Ice.LocalObjectHolder cookie) + { + return _blobject; + } + + public void + finished(Ice.Current current, Ice.Object servant, java.lang.Object cookie) + { + } + + public void + deactivate(String category) + { + } + + private Ice.Object _blobject; +} diff --git a/java/test/Ice/invoke/Server.java b/java/test/Ice/invoke/Server.java new file mode 100644 index 00000000000..2cf3bb7cdc2 --- /dev/null +++ b/java/test/Ice/invoke/Server.java @@ -0,0 +1,48 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 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. +// +// ********************************************************************** + +package test.Ice.invoke; + +public class Server extends test.Util.Application +{ + public int run(String[] args) + { + boolean async = false; + for(int i = 0; i < args.length; ++i) + { + if(args[i].equals("--async")) + { + async = true; + } + } + + communicator().getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010:udp"); + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("TestAdapter"); + adapter.addServantLocator(new ServantLocatorI(async), ""); + adapter.activate(); + return WAIT; + } + + protected Ice.InitializationData getInitData(Ice.StringSeqHolder argsH) + { + Ice.InitializationData initData = new Ice.InitializationData(); + initData.properties = Ice.Util.createProperties(argsH); + initData.properties.setProperty("Ice.Package.Test", "test.Ice.invoke"); + return initData; + } + + public static void main(String[] args) + { + Server c = new Server(); + int status = c.main("Server", args); + + System.gc(); + System.exit(status); + } +} diff --git a/java/test/Ice/invoke/Test.ice b/java/test/Ice/invoke/Test.ice new file mode 100644 index 00000000000..77492c307db --- /dev/null +++ b/java/test/Ice/invoke/Test.ice @@ -0,0 +1,32 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 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. +// +// ********************************************************************** + +#ifndef TEST_ICE +#define TEST_ICE + +[["java:package:test.Ice.invoke"]] +module Test +{ + +exception MyException +{ +}; + +class MyClass +{ + string opString(string s1, out string s2); + + void opException() throws MyException; + + void shutdown(); +}; + +}; + +#endif diff --git a/java/test/Ice/invoke/run.py b/java/test/Ice/invoke/run.py new file mode 100755 index 00000000000..47f6323efaa --- /dev/null +++ b/java/test/Ice/invoke/run.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise "can't find toplevel directory!" +sys.path.append(os.path.join(path[0])) +from scripts import * + +print "tests with Blobject server." +TestUtil.clientServerTest() + +print "tests with BlobjectAsync server." +TestUtil.clientServerTest(additionalServerOptions = "--async") + diff --git a/vb/demo/Ice/invoke/Client.vb b/vb/demo/Ice/invoke/Client.vb index f1585985aeb..71915e46cbd 100644 --- a/vb/demo/Ice/invoke/Client.vb +++ b/vb/demo/Ice/invoke/Client.vb @@ -16,70 +16,6 @@ Module InvokeC Class Client Inherits Ice.Application - Class AMI_Object_ice_invokeI - Inherits Ice.AMI_Object_ice_invoke - - Public Overloads Overrides Sub ice_response(ByVal ok As Boolean, ByVal outParams() As Byte) - If Not ok Then - Console.Error.WriteLine("Unknown user exception") - End If - End Sub - - Public Overloads Overrides Sub ice_exception(ByVal ex As Ice.Exception) - Console.Error.WriteLine(ex) - End Sub - - End Class - - Class AMI_Object_ice_invokeGetValuesI - Inherits Ice.AMI_Object_ice_invoke - - Public Overloads Overrides Sub ice_response(ByVal ok As Boolean, ByVal outParams() As Byte) - If Not ok Then - Console.Error.WriteLine("Unknown user exception") - Else - ' - ' Unmarshal the results. - ' - Dim inStream As Ice.InputStream = Ice.Util.createInputStream(communicator, outParams) - Dim ch As CHelper = New CHelper(inStream) - ch.read() - Dim str As String = inStream.readString() - inStream.readPendingObjects() - inStream.destroy() - Dim C As C = ch.value - Console.Error.WriteLine("Got string `" & str & "' and class: s.name=" & C.s.name & _ - ", s.value=" & C.s.value) - End If - End Sub - - Public Overloads Overrides Sub ice_exception(ByVal ex As Ice.Exception) - Console.Error.WriteLine(ex) - End Sub - - End Class - - Class AMI_Object_ice_invokeThrowPrintFailureI - Inherits Ice.AMI_Object_ice_invoke - - Public Overloads Overrides Sub ice_response(ByVal ok As Boolean, ByVal outParams() As Byte) - Dim inStream As Ice.InputStream = Ice.Util.createInputStream(communicator, outParams) - Try - inStream.throwException() - Catch ex As PrintFailure - ' Expected. - Catch ex As Ice.UserException - Console.Error.WriteLine("Unknown user exception", ex) - End Try - inStream.destroy() - End Sub - - Public Overloads Overrides Sub ice_exception(ByVal ex As Ice.Exception) - Console.Error.WriteLine(ex) - End Sub - - End Class - Private Sub menu() Console.WriteLine("usage:") Console.WriteLine("1: print string") @@ -97,13 +33,8 @@ Module InvokeC End Sub Public Overloads Overrides Function run(ByVal args() As String) As Integer - Dim async As Boolean = false - If args.Length = 1 Then - If args(0).Equals("--async") Then - async = true - End If - ElseIf args.Length > 0 Then - Console.Error.WriteLine("Usage: " & appName() & " [--async]") + If args.Length > 0 Then + Console.Error.WriteLine(appName() & ": too many arguments") Return 1 End If @@ -133,13 +64,8 @@ Module InvokeC ' ' Invoke operation. ' - If async Then - Dim cb As AMI_Object_ice_invokeI = New AMI_Object_ice_invokeI() - obj.ice_invoke_async(cb, "printString", Ice.OperationMode.Normal, outStream.finished()) - Else - If Not obj.ice_invoke("printString", Ice.OperationMode.Normal, outStream.finished(), outParams) Then - Console.Error.WriteLine("Unknown user exception") - End If + If Not obj.ice_invoke("printString", Ice.OperationMode.Normal, outStream.finished(), outParams) Then + Console.Error.WriteLine("Unknown user exception") End If outStream.destroy() @@ -154,13 +80,8 @@ Module InvokeC ' ' Invoke operation. ' - If async Then - Dim cb As AMI_Object_ice_invokeI = New AMI_Object_ice_invokeI() - obj.ice_invoke_async(cb, "printStringSequence", Ice.OperationMode.Normal, outStream.finished()) - Else - If Not obj.ice_invoke("printStringSequence", Ice.OperationMode.Normal, outStream.finished(), outParams) Then - Console.Error.WriteLine("Unknown user exception") - End If + If Not obj.ice_invoke("printStringSequence", Ice.OperationMode.Normal, outStream.finished(), outParams) Then + Console.Error.WriteLine("Unknown user exception") End If outStream.destroy() @@ -177,13 +98,8 @@ Module InvokeC ' ' Invoke operation. ' - If async Then - Dim cb As AMI_Object_ice_invokeI = New AMI_Object_ice_invokeI() - obj.ice_invoke_async(cb, "printDictionary", Ice.OperationMode.Normal, outStream.finished()) - Else - If Not obj.ice_invoke("printDictionary", Ice.OperationMode.Normal, outStream.finished(), outParams) Then - Console.Error.WriteLine("Unknown user exception") - End If + If Not obj.ice_invoke("printDictionary", Ice.OperationMode.Normal, outStream.finished(), outParams) Then + Console.Error.WriteLine("Unknown user exception") End If outStream.destroy() @@ -197,13 +113,8 @@ Module InvokeC ' ' Invoke operation. ' - If async Then - Dim cb As AMI_Object_ice_invokeI = New AMI_Object_ice_invokeI() - obj.ice_invoke_async(cb, "printEnum", Ice.OperationMode.Normal, outStream.finished()) - Else - If Not obj.ice_invoke("printEnum", Ice.OperationMode.Normal, outStream.finished(), outParams) Then - Console.Error.WriteLine("Unknown user exception") - End If + If Not obj.ice_invoke("printEnum", Ice.OperationMode.Normal, outStream.finished(), outParams) Then + Console.Error.WriteLine("Unknown user exception") End If outStream.destroy() @@ -220,13 +131,8 @@ Module InvokeC ' ' Invoke operation. ' - If async Then - Dim cb As AMI_Object_ice_invokeI = New AMI_Object_ice_invokeI() - obj.ice_invoke_async(cb, "printStruct", Ice.OperationMode.Normal, outStream.finished()) - Else - If Not obj.ice_invoke("printStruct", Ice.OperationMode.Normal, outStream.finished(), outParams) Then - Console.Error.WriteLine("Unknown user exception") - End If + If Not obj.ice_invoke("printStruct", Ice.OperationMode.Normal, outStream.finished(), outParams) Then + Console.Error.WriteLine("Unknown user exception") End If outStream.destroy() @@ -250,14 +156,9 @@ Module InvokeC ' ' Invoke operation. ' - If async Then - Dim cb As AMI_Object_ice_invokeI = New AMI_Object_ice_invokeI() - obj.ice_invoke_async(cb, "printStructSequence", Ice.OperationMode.Normal, outStream.finished()) - Else - If Not obj.ice_invoke("printStructSequence", Ice.OperationMode.Normal, outStream.finished(), _ - outParams) Then - Console.Error.WriteLine("Unknown user exception") - End If + If Not obj.ice_invoke("printStructSequence", Ice.OperationMode.Normal, outStream.finished(), _ + outParams) Then + Console.Error.WriteLine("Unknown user exception") End If outStream.destroy() @@ -276,13 +177,8 @@ Module InvokeC ' ' Invoke operation. ' - If async Then - Dim cb As AMI_Object_ice_invokeI = New AMI_Object_ice_invokeI() - obj.ice_invoke_async(cb, "printClass", Ice.OperationMode.Normal, outStream.finished()) - Else - If Not obj.ice_invoke("printClass", Ice.OperationMode.Normal, outStream.finished(), outParams) Then - Console.Error.WriteLine("Unknown user exception") - End If + If Not obj.ice_invoke("printClass", Ice.OperationMode.Normal, outStream.finished(), outParams) Then + Console.Error.WriteLine("Unknown user exception") End If outStream.destroy() @@ -290,58 +186,43 @@ Module InvokeC ' ' Invoke operation. ' - If async Then - Dim cb As AMI_Object_ice_invokeGetValuesI = New AMI_Object_ice_invokeGetValuesI() - obj.ice_invoke_async(cb, "getValues", Ice.OperationMode.Normal, Nothing) - Else - If Not obj.ice_invoke("getValues", Ice.OperationMode.Normal, Nothing, outParams) Then - Console.Error.WriteLine("Unknown user exception") - Exit Try - End If - - ' - ' Unmarshal the results. - ' - Dim inStream As Ice.InputStream = Ice.Util.createInputStream(communicator, outParams) - Dim ch As CHelper = New CHelper(inStream) - ch.read() - Dim str As String = inStream.readString() - inStream.readPendingObjects() - inStream.destroy() - Dim C As C = ch.value - Console.Error.WriteLine("Got string `" & str & "' and class: s.name=" & C.s.name & _ - ", s.value=" & C.s.value) + If Not obj.ice_invoke("getValues", Ice.OperationMode.Normal, Nothing, outParams) Then + Console.Error.WriteLine("Unknown user exception") + Exit Try End If + + ' + ' Unmarshal the results. + ' + Dim inStream As Ice.InputStream = Ice.Util.createInputStream(communicator, outParams) + Dim ch As CHelper = New CHelper(inStream) + ch.read() + Dim str As String = inStream.readString() + inStream.readPendingObjects() + inStream.destroy() + Dim C As C = ch.value + Console.Error.WriteLine("Got string `" & str & "' and class: s.name=" & C.s.name & _ + ", s.value=" & C.s.value) ElseIf line.Equals("9") Then ' ' Invoke operation. ' - If async Then - Dim cb As AMI_Object_ice_invokeThrowPrintFailureI = New AMI_Object_ice_invokeThrowPrintFailureI() - obj.ice_invoke_async(cb, "throwPrintFailure", Ice.OperationMode.Normal, Nothing) - Else - If obj.ice_invoke("throwPrintFailure", Ice.OperationMode.Normal, Nothing, outParams) Then - Console.Error.WriteLine("Expected exception") - Exit Try - End If - - Dim inStream As Ice.InputStream = Ice.Util.createInputStream(communicator, outParams) - Try - inStream.throwException() - Catch ex As PrintFailure - ' Expected. - Catch ex As Ice.UserException - Console.Error.WriteLine("Unknown user exception", ex) - End Try - inStream.destroy() + If obj.ice_invoke("throwPrintFailure", Ice.OperationMode.Normal, Nothing, outParams) Then + Console.Error.WriteLine("Expected exception") + Exit Try End If + + Dim inStream As Ice.InputStream = Ice.Util.createInputStream(communicator, outParams) + Try + inStream.throwException() + Catch ex As PrintFailure + ' Expected. + Catch ex As Ice.UserException + Console.Error.WriteLine("Unknown user exception", ex) + End Try + inStream.destroy() ElseIf line.Equals("s") Then - If async Then - Dim cb As AMI_Object_ice_invokeI = New AMI_Object_ice_invokeI() - obj.ice_invoke_async(cb, "shutdown", Ice.OperationMode.Normal, Nothing) - Else - obj.ice_invoke("shutdown", Ice.OperationMode.Normal, Nothing, outParams) - End If + obj.ice_invoke("shutdown", Ice.OperationMode.Normal, Nothing, outParams) ElseIf line.Equals("x") Then ' Nothing to do. ElseIf line.Equals("?") Then diff --git a/vb/demo/Ice/invoke/README b/vb/demo/Ice/invoke/README index 8fc943163cc..76ca767d80b 100644 --- a/vb/demo/Ice/invoke/README +++ b/vb/demo/Ice/invoke/README @@ -7,7 +7,3 @@ $ server In a separate window, start the client: $ client - -To run the client using asynchronous calls use: - -$ client --async |