⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 alltests.cpp

📁 ICE-3.2 一个开源的中间件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// **********************************************************************//// Copyright (c) 2003-2007 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;using namespace Test;class EmptyI : virtual public Empty{};class ServantLocatorI : virtual public Ice::ServantLocator{public:    virtual Ice::ObjectPtr locate(const Ice::Current&, Ice::LocalObjectPtr&) { return 0; }    virtual void finished(const Ice::Current&, const Ice::ObjectPtr&, const Ice::LocalObjectPtr&) {}    virtual void deactivate(const string&) {}};class ObjectFactoryI : virtual public Ice::ObjectFactory{public:    virtual Ice::ObjectPtr create(const string&) { return 0; }    virtual void destroy() {}};class CallbackBase : public IceUtil::Monitor<IceUtil::Mutex>{public:    CallbackBase() :        _called(false)    {    }    virtual ~CallbackBase()    {    }    bool check()    {        IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);        while(!_called)        {            if(!timedWait(IceUtil::Time::seconds(5)))            {                return false;            }        }        _called = false;        return true;    }protected:    void called()    {        IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);        assert(!_called);        _called = true;        notify();    }private:    bool _called;};class AMI_Thrower_throwAasAI : public AMI_Thrower_throwAasA, public CallbackBase{public:    virtual void ice_response()    {        test(false);    }    virtual void ice_exception(const Ice::Exception& exc)    {        try        {            exc.ice_throw();        }        catch(const A& ex)        {            test(ex.aMem == 1);        }        catch(...)        {            test(false);        }        called();    }};typedef IceUtil::Handle<AMI_Thrower_throwAasAI> AMI_Thrower_throwAasAIPtr;class AMI_Thrower_throwAasAObjectNotExistI : public AMI_Thrower_throwAasA, public CallbackBase{public:    AMI_Thrower_throwAasAObjectNotExistI(const Ice::CommunicatorPtr& communicator) :        _communicator(communicator)    {    }    virtual void ice_response()    {        test(false);    }    virtual void ice_exception(const Ice::Exception& exc)    {        try        {            exc.ice_throw();        }        catch(const Ice::ObjectNotExistException& ex)        {            Ice::Identity id = _communicator->stringToIdentity("does not exist");            test(ex.id == id);        }        catch(...)        {            test(false);        }        called();    }private:    Ice::CommunicatorPtr _communicator;};typedef IceUtil::Handle<AMI_Thrower_throwAasAObjectNotExistI> AMI_Thrower_throwAasAObjectNotExistIPtr;class AMI_Thrower_throwAasAFacetNotExistI : public AMI_Thrower_throwAasA, public CallbackBase{public:    virtual void ice_response()    {        test(false);    }    virtual void ice_exception(const Ice::Exception& exc)    {        try        {            exc.ice_throw();        }        catch(const Ice::FacetNotExistException& ex)        {            test(ex.facet == "no such facet");        }        catch(...)        {            test(false);        }        called();    }};typedef IceUtil::Handle<AMI_Thrower_throwAasAFacetNotExistI> AMI_Thrower_throwAasAFacetNotExistIPtr;class AMI_Thrower_throwAorDasAorDI : public AMI_Thrower_throwAorDasAorD, public CallbackBase{public:    virtual void ice_response()    {        test(false);    }    virtual void ice_exception(const Ice::Exception& exc)    {        try        {            exc.ice_throw();        }        catch(const A& ex)        {            test(ex.aMem == 1);        }        catch(const D& ex)        {            test(ex.dMem == -1);        }        catch(...)        {            test(false);        }        called();    }};typedef IceUtil::Handle<AMI_Thrower_throwAorDasAorDI> AMI_Thrower_throwAorDasAorDIPtr;class AMI_Thrower_throwBasAI : public AMI_Thrower_throwBasA, public CallbackBase{public:    virtual void ice_response()    {        test(false);    }    virtual void ice_exception(const Ice::Exception& exc)    {        try        {            exc.ice_throw();        }        catch(const B& ex)        {            test(ex.aMem == 1);            test(ex.bMem == 2);        }        catch(...)        {            test(false);        }        called();    }};typedef IceUtil::Handle<AMI_Thrower_throwBasAI> AMI_Thrower_throwBasAIPtr;class AMI_Thrower_throwCasAI : public AMI_Thrower_throwCasA, public CallbackBase{public:    virtual void ice_response()    {        test(false);    }    virtual void ice_exception(const Ice::Exception& exc)    {        try        {            exc.ice_throw();        }        catch(const C& ex)        {            test(ex.aMem == 1);            test(ex.bMem == 2);            test(ex.cMem == 3);        }        catch(...)        {            test(false);        }        called();    }};typedef IceUtil::Handle<AMI_Thrower_throwCasAI> AMI_Thrower_throwCasAIPtr;class AMI_Thrower_throwBasBI : public AMI_Thrower_throwBasB, public CallbackBase{public:    virtual void ice_response()    {        test(false);    }    virtual void ice_exception(const Ice::Exception& exc)    {        try        {            exc.ice_throw();        }        catch(const B& ex)        {            test(ex.aMem == 1);            test(ex.bMem == 2);        }        catch(...)        {            test(false);        }        called();    }};typedef IceUtil::Handle<AMI_Thrower_throwBasBI> AMI_Thrower_throwBasBIPtr;class AMI_Thrower_throwCasBI : public AMI_Thrower_throwCasB, public CallbackBase{public:    virtual void ice_response()    {        test(false);    }    virtual void ice_exception(const Ice::Exception& exc)    {        try        {            exc.ice_throw();        }        catch(const C& ex)        {            test(ex.aMem == 1);            test(ex.bMem == 2);            test(ex.cMem == 3);        }        catch(...)        {            test(false);        }        called();    }};typedef IceUtil::Handle<AMI_Thrower_throwCasBI> AMI_Thrower_throwCasBIPtr;class AMI_Thrower_throwCasCI : public AMI_Thrower_throwCasC, public CallbackBase{public:    virtual void ice_response()    {        test(false);    }    virtual void ice_exception(const Ice::Exception& exc)    {        try        {            exc.ice_throw();        }        catch(const C& ex)        {            test(ex.aMem == 1);            test(ex.bMem == 2);            test(ex.cMem == 3);        }        catch(...)        {            test(false);        }        called();    }};typedef IceUtil::Handle<AMI_Thrower_throwCasCI> AMI_Thrower_throwCasCIPtr;class AMI_Thrower_throwModAI : public AMI_Thrower_throwModA, public CallbackBase{public:    virtual void ice_response()    {        test(false);    }    virtual void ice_exception(const Ice::Exception& exc)    {        try        {            exc.ice_throw();        }        catch(const Mod::A& ex)        {            test(ex.aMem == 1);            test(ex.a2Mem == 2);        }        catch(const Ice::OperationNotExistException&)        {            //            // This operation is not supported in Java.            //        }        catch(...)        {            test(false);        }        called();    }};typedef IceUtil::Handle<AMI_Thrower_throwModAI> AMI_Thrower_throwModAIPtr;class AMI_Thrower_throwUndeclaredAI : public AMI_Thrower_throwUndeclaredA, public CallbackBase{public:    virtual void ice_response()    {        test(false);    }    virtual void ice_exception(const Ice::Exception& exc)    {        try        {            exc.ice_throw();        }        catch(const Ice::UnknownUserException&)        {        }        catch(...)        {            test(false);        }        called();    }};typedef IceUtil::Handle<AMI_Thrower_throwUndeclaredAI> AMI_Thrower_throwUndeclaredAIPtr;class AMI_Thrower_throwUndeclaredBI : public AMI_Thrower_throwUndeclaredB, public CallbackBase{public:    virtual void ice_response()    {        test(false);    }    virtual void ice_exception(const Ice::Exception& exc)    {        try        {            exc.ice_throw();        }        catch(const Ice::UnknownUserException&)        {        }        catch(...)        {            test(false);        }        called();    }};typedef IceUtil::Handle<AMI_Thrower_throwUndeclaredBI> AMI_Thrower_throwUndeclaredBIPtr;class AMI_Thrower_throwUndeclaredCI : public AMI_Thrower_throwUndeclaredC, public CallbackBase{public:    virtual void ice_response()    {        test(false);    }    virtual void ice_exception(const Ice::Exception& exc)    {        try        {            exc.ice_throw();        }        catch(const Ice::UnknownUserException&)        {        }        catch(...)        {            test(false);        }        called();    }};typedef IceUtil::Handle<AMI_Thrower_throwUndeclaredCI> AMI_Thrower_throwUndeclaredCIPtr;class AMI_Thrower_throwLocalExceptionI : public AMI_Thrower_throwLocalException, public CallbackBase{public:    virtual void ice_response()    {        test(false);    }    virtual void ice_exception(const Ice::Exception& exc)    {        try        {            exc.ice_throw();        }        catch(const Ice::UnknownLocalException&)        {        }        catch(...)        {            test(false);        }        called();    }};typedef IceUtil::Handle<AMI_Thrower_throwLocalExceptionI> AMI_Thrower_throwLocalExceptionIPtr;class AMI_Thrower_throwNonIceExceptionI : public AMI_Thrower_throwNonIceException, public CallbackBase{public:    virtual void ice_response()    {        test(false);    }    virtual void ice_exception(const Ice::Exception& exc)    {        try        {            exc.ice_throw();        }        catch(const Ice::UnknownException&)        {        }        catch(...)        {            test(false);        }        called();    }};typedef IceUtil::Handle<AMI_Thrower_throwNonIceExceptionI> AMI_Thrower_throwNonIceExceptionIPtr;class AMI_WrongOperation_noSuchOperationI : public AMI_WrongOperation_noSuchOperation, public CallbackBase{public:    virtual void ice_response()    {        test(false);    }    virtual void ice_exception(const Ice::Exception& exc)    {        try        {            exc.ice_throw();        }        catch(const Ice::OperationNotExistException& ex)        {            test(ex.operation == "noSuchOperation");        }        catch(...)        {            test(false);        }        called();    }};typedef IceUtil::Handle<AMI_WrongOperation_noSuchOperationI> AMI_WrongOperation_noSuchOperationIPtr;ThrowerPrxallTests(const Ice::CommunicatorPtr& communicator, bool collocated){    cout << "testing object adapter registration exceptions... " << flush;    {        Ice::ObjectAdapterPtr first;        try        {            first = communicator->createObjectAdapter("TestAdapter0");            test(false);        }        catch(const Ice::InitializationException&)        {            // Expected        }        communicator->getProperties()->setProperty("TestAdapter0.Endpoints", "default");        first = communicator->createObjectAdapter("TestAdapter0");        try        {            Ice::ObjectAdapterPtr second = communicator->createObjectAdapter("TestAdapter0");            test(false);        }        catch(const Ice::AlreadyRegisteredException&)        {            // Expected        }        try        {            Ice::ObjectAdapterPtr second =                 communicator->createObjectAdapterWithEndpoints("TestAdapter0", "ssl -h foo -p 12011 -t 10000");            test(false);        }        catch(const Ice::AlreadyRegisteredException&)        {            // Expected.        }        //        // Properties must remain unaffected if an exception occurs.        //        test(communicator->getProperties()->getProperty("TestAdapter0.Endpoints") == "default");        first->deactivate();    }    cout << "ok" << endl;        cout << "testing servant registration exceptions... " << flush;    {        communicator->getProperties()->setProperty("TestAdapter1.Endpoints", "default");        Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter("TestAdapter1");        Ice::ObjectPtr obj = new EmptyI;        adapter->add(obj, communicator->stringToIdentity("x"));        try        {            adapter->add(obj, communicator->stringToIdentity("x"));            test(false);        }        catch(const Ice::AlreadyRegisteredException&)        {        }        adapter->remove(communicator->stringToIdentity("x"));        try        {            adapter->remove(communicator->stringToIdentity("x"));            test(false);        }        catch(const Ice::NotRegisteredException&)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -