diff options
Diffstat (limited to 'cpp/test/Ice/interceptor/Client.cpp')
-rw-r--r-- | cpp/test/Ice/interceptor/Client.cpp | 162 |
1 files changed, 37 insertions, 125 deletions
diff --git a/cpp/test/Ice/interceptor/Client.cpp b/cpp/test/Ice/interceptor/Client.cpp index bf80efea7b1..09aa2420de8 100644 --- a/cpp/test/Ice/interceptor/Client.cpp +++ b/cpp/test/Ice/interceptor/Client.cpp @@ -8,141 +8,60 @@ // ********************************************************************** #include <Ice/Ice.h> -#include <TestCommon.h> +#include <TestHelper.h> #include <Test.h> #include <MyObjectI.h> #include <InterceptorI.h> #include <AMDInterceptorI.h> #include <iostream> -DEFINE_TEST("client") - #ifndef _WIN32 // // SIGPIPE test // # include <signal.h> -#endif - -using namespace std; - -#if defined(__APPLE__) || defined(ICE_OS_UWP) -namespace -{ - -class App -{ -public: - - virtual ~App() - { - if(_communicator) - { - _communicator->destroy(); - } - } - - Ice::CommunicatorPtr communicator() - { - return _communicator; - } - - virtual int _main(int argc, char** argv) - { - Ice::InitializationData initData = getTestInitData(argc, argv); - initData.properties->setProperty("Ice.Warn.Dispatch", "0"); - _communicator = Ice::initialize(initData); - return run(argc, argv); - } - virtual int run(int argc, char** argv) = 0; - -private: - Ice::CommunicatorPtr _communicator; -}; - -} -#else -namespace +extern "C" void testAction(int) { -typedef Ice::Application App; + test(false); } + #endif -class ClientApp : public App +using namespace std; + +class Client : public Test::TestHelper { public: - virtual int run(int, char*[]); + virtual void run(int, char**); private: - int run(const Test::MyObjectPrxPtr&, const InterceptorIPtr&); - int runAmd(const Test::MyObjectPrxPtr&, const AMDInterceptorIPtr&); + void runTest(const Test::MyObjectPrxPtr&, const InterceptorIPtr&); + void runAmdTest(const Test::MyObjectPrxPtr&, const AMDInterceptorIPtr&); }; -#ifndef _WIN32 -extern "C" void testAction(int) +void +Client::run(int argc, char* argv[]) { - test(false); -} -#endif - -int -main(int argc, char* argv[]) -{ -#ifdef ICE_STATIC_LIBS - Ice::registerIceSSL(false); - Ice::registerIceWS(true); -#endif - #ifndef _WIN32 -// -// Set SIGPIPE action -// + // + // Set SIGPIPE action + // struct sigaction action; action.sa_handler = &testAction; sigemptyset(&action.sa_mask); action.sa_flags = 0; sigaction(SIGPIPE, &action, 0); #endif - - ClientApp app; -#if defined(__APPLE__) || defined(ICE_OS_UWP) - int result = app._main(argc, argv); -#else - int result = app.main(argc, argv); -#endif - -#ifndef _WIN32 -// -// Check SIGPIPE was properly reset to old action -// - struct sigaction newAction; - sigaction(SIGPIPE, 0, &newAction); - test(action.sa_handler == &testAction); -#endif - - return result; -} - -int -ClientApp::run(int, char*[]) -{ - -#ifndef _WIN32 -// -// Check SIGPIPE is now SIG_IGN -// - struct sigaction action; - sigaction(SIGPIPE, 0, &action); - test(action.sa_handler == SIG_IGN); -#endif - + Ice::PropertiesPtr properties = createTestProperties(argc, argv); + properties->setProperty("Ice.Warn.Dispatch", "0"); + Ice::CommunicatorHolder communicator = initialize(argc, argv, properties); // // Create OA and servants // - Ice::ObjectAdapterPtr oa = communicator()->createObjectAdapterWithEndpoints("MyOA", "tcp -h localhost"); + Ice::ObjectAdapterPtr oa = communicator->createObjectAdapterWithEndpoints("MyOA", "tcp -h localhost"); Ice::ObjectPtr servant = ICE_MAKE_SHARED(MyObjectI); InterceptorIPtr interceptor = ICE_MAKE_SHARED(InterceptorI, servant); @@ -152,40 +71,34 @@ ClientApp::run(int, char*[]) Test::MyObjectPrxPtr prxForAMD = ICE_UNCHECKED_CAST(Test::MyObjectPrx, oa->addWithUUID(amdInterceptor)); cout << "Collocation optimization on" << endl; - int rs = run(prx, interceptor); - if(rs != 0) - { - return rs; - } + runTest(prx, interceptor); cout << "Now with AMD" << endl; - rs = runAmd(prxForAMD, amdInterceptor); - if(rs != 0) - { - return rs; - } + runAmdTest(prxForAMD, amdInterceptor); oa->activate(); // Only necessary for non-collocation optimized tests cout << "Collocation optimization off" << endl; interceptor->clear(); prx = ICE_UNCHECKED_CAST(Test::MyObjectPrx, prx->ice_collocationOptimized(false)); - rs = run(prx, interceptor); - if(rs != 0) - { - return rs; - } + runTest(prx, interceptor); cout << "Now with AMD" << endl; amdInterceptor->clear(); prxForAMD = ICE_UNCHECKED_CAST(Test::MyObjectPrx, prxForAMD->ice_collocationOptimized(false)); - rs = runAmd(prxForAMD, amdInterceptor); - - return rs; + runAmdTest(prxForAMD, amdInterceptor); +#ifndef _WIN32 + // + // Check SIGPIPE was properly reset to old action + // + struct sigaction newAction; + sigaction(SIGPIPE, 0, &newAction); + test(action.sa_handler == &testAction); +#endif } -int -ClientApp::run(const Test::MyObjectPrxPtr& prx, const InterceptorIPtr& interceptor) +void +Client::runTest(const Test::MyObjectPrxPtr& prx, const InterceptorIPtr& interceptor) { cout << "testing simple interceptor... " << flush; test(interceptor->getLastOperation().empty()); @@ -261,12 +174,10 @@ ClientApp::run(const Test::MyObjectPrxPtr& prx, const InterceptorIPtr& intercept test(interceptor->getLastOperation() == "amdAdd"); test(!interceptor->getLastStatus()); cout << "ok" << endl; - - return EXIT_SUCCESS; } -int -ClientApp::runAmd(const Test::MyObjectPrxPtr& prx, const AMDInterceptorIPtr& interceptor) +void +Client::runAmdTest(const Test::MyObjectPrxPtr& prx, const AMDInterceptorIPtr& interceptor) { cout << "testing simple interceptor... " << flush; test(interceptor->getLastOperation().empty()); @@ -328,5 +239,6 @@ ClientApp::runAmd(const Test::MyObjectPrxPtr& prx, const AMDInterceptorIPtr& int test(!interceptor->getLastStatus()); test(dynamic_cast<MySystemException*>(interceptor->getException()) != 0); cout << "ok" << endl; - return EXIT_SUCCESS; } + +DEFINE_TEST(Client) |