Beispiel #1
0
BaseConnection::BaseConnection(io_service& io_service, const std::string &cnm,
        const std::string &id, Atlas::Bridge& br) :
        _io_service(io_service), _status(DISCONNECTED), _id(
                id), _clientName(cnm), _bridge(br), _port(0)
{
    Atlas::Objects::Factories* f = Atlas::Objects::Factories::instance();
    if (!f->hasFactory("unseen")) {
        Atlas::Objects::Operation::UNSEEN_NO = f->addFactory("unseen",
                &Atlas::Objects::generic_factory);
        Atlas::Objects::Operation::ATTACK_NO = f->addFactory("attack",
                &Atlas::Objects::generic_factory);
    }
    if (!f->hasFactory("sys")) {
        Atlas::Objects::Entity::SYS_NO = f->addFactory("sys",
                &Atlas::Objects::factory<Atlas::Objects::Entity::SysData>);
    }
}
Beispiel #2
0
int main()
{

    boost::asio::io_service io_service;
    Eris::Logged.connect(sigc::ptr_fun(writeLog));

    Atlas::Objects::Factories * f = Atlas::Objects::Factories::instance();
    assert(!f->hasFactory("unseen"));

    {
        TestBaseConnection tbc(io_service, new Atlas::Message::QueuedDecoder);
    }

    // Make sure the op classes have been installed, and the initial
    // constructor code path has been tested.
    assert(f->hasFactory("unseen"));
    assert(f->hasFactory("attack"));

    // Test the other code path when a second connection is created.
    {
        TestBaseConnection tbc(io_service, new Atlas::Message::QueuedDecoder);
    }

    // Test isConnected.
    {
        TestBaseConnection tbc(io_service, new Atlas::Message::QueuedDecoder);

        assert(!tbc.isConnected());
    }

    // Test getStatus().
    {
        TestBaseConnection tbc(io_service, new Atlas::Message::QueuedDecoder);

        assert(tbc.getStatus() == Eris::BaseConnection::DISCONNECTED);
    }

    // Test setStatus().
    {
        TestBaseConnection tbc(io_service, new Atlas::Message::QueuedDecoder);

        assert(tbc.getStatus() == Eris::BaseConnection::DISCONNECTED);

        tbc.test_setStatus(Eris::BaseConnection::CONNECTED);

        assert(tbc.getStatus() == Eris::BaseConnection::CONNECTED);

        tbc.test_setStatus(Eris::BaseConnection::DISCONNECTED);
    }

    // Test connect() and verify getStatus() changes.
    {
        TestBaseConnection tbc(io_service, new Atlas::Message::QueuedDecoder);

        assert(tbc.getStatus() == Eris::BaseConnection::DISCONNECTED);

        int ret = tbc.connect("localhost", 6723);

        assert(ret == 0);

        assert(tbc.getStatus() == Eris::BaseConnection::CONNECTING);
    }

    // Test onConnect() does nothing.
    {
        TestBaseConnection tbc(io_service, new Atlas::Message::QueuedDecoder);

        tbc.test_onConnect();
    }

    // Test onConnect() emits the signal.
    {
        SignalFlagger onConnect_checker;

        assert(!onConnect_checker.flagged());

        TestBaseConnection tbc(io_service, new Atlas::Message::QueuedDecoder);

        tbc.Connected.connect(sigc::mem_fun(onConnect_checker,
                                            &SignalFlagger::set));

        assert(!onConnect_checker.flagged());

        tbc.test_onConnect();

        assert(onConnect_checker.flagged());
    }

    // Test hardDisconnect() does nothing.
    {
        TestBaseConnection tbc(io_service, new Atlas::Message::QueuedDecoder);

        tbc.test_hardDisconnect(true);
    }

//    // Test hardDisconnect() throws in polldefault when connected
//    {
//        TestBaseConnection tbc(io_service, new Atlas::Message::QueuedDecoder);
//
//        // Add members to be consistent with connected state.
//        tbc.setup_stream();
//        tbc.setup_codec();
//        tbc.setup_encode();
//        // Make the state different
//        tbc.test_setStatus(Eris::BaseConnection::CONNECTED);
//
//        try {
//            tbc.test_hardDisconnect(true);
//        }
//        catch (Eris::InvalidOperation & eio) {
//        }
//
//        // Make it disconnected again, or we crash on destructor
//        tbc.test_setStatus(Eris::BaseConnection::DISCONNECTED);
//    }
//
//    // Test hardDisconnect() throws in polldefault when disconnecting
//    {
//        TestBaseConnection tbc(io_service, new Atlas::Message::QueuedDecoder);
//
//        // Add members to be consistent with disconnecting state.
//        tbc.setup_stream();
//        tbc.setup_codec();
//        tbc.setup_encode();
//        // Make the state different
//        tbc.test_setStatus(Eris::BaseConnection::DISCONNECTING);
//
//        try {
//            tbc.test_hardDisconnect(true);
//        }
//        catch (Eris::InvalidOperation & eio) {
//        }
//
//        // Make it disconnected again, or we crash on destructor
//        tbc.test_setStatus(Eris::BaseConnection::DISCONNECTED);
//    }
//
//    // Test hardDisconnect() throws in polldefault when negotiating
//    {
//        TestBaseConnection tbc(io_service, new Atlas::Message::QueuedDecoder);
//
//        // Add members to be consistent with negotiating state.
//        tbc.setup_stream();
//        tbc.setup_sc();
//        // Make the state different
//        tbc.test_setStatus(Eris::BaseConnection::NEGOTIATE);
//
//        try {
//            tbc.test_hardDisconnect(true);
//        }
//        catch (Eris::InvalidOperation & eio) {
//        }
//
//        // Make it disconnected again, or we crash on destructor
//        tbc.test_setStatus(Eris::BaseConnection::DISCONNECTED);
//    }
//
//    // Test hardDisconnect() throws in polldefault when negotiating
//    {
//        TestBaseConnection tbc(io_service, new Atlas::Message::QueuedDecoder);
//
//        // Add members to be consistent with connecting state.
//        tbc.setup_stream();
//        // Make the state different
//        tbc.test_setStatus(Eris::BaseConnection::CONNECTING);
//
//        try {
//            tbc.test_hardDisconnect(true);
//        }
//        catch (Eris::InvalidOperation & eio) {
//        }
//
//        // Make it disconnected again, or we crash on destructor
//        tbc.test_setStatus(Eris::BaseConnection::DISCONNECTED);
//    }

    // Test hardDisconnect() throws in polldefault when negotiating
    {
        TestBaseConnection tbc(io_service, new Atlas::Message::QueuedDecoder);

        // Add members to be consistent with connecting state.
        tbc.setup_socket();
        // Make the state different
        tbc.test_setStatus(Eris::BaseConnection::INVALID_STATUS);

        try {
            tbc.test_hardDisconnect(true);
        }
        catch (Eris::InvalidOperation & eio) {
        }

        // Make it disconnected again, or we crash on destructor
        tbc.test_setStatus(Eris::BaseConnection::DISCONNECTED);
    }

    // Test onConnectTimeout()
    {
        TestBaseConnection tbc(io_service, new Atlas::Message::QueuedDecoder);

        tbc.test_onConnectTimeout();

        assert(tbc.timeout);
    }

    // Test onNegotiateTimeout()
    {
        TestBaseConnection tbc(io_service, new Atlas::Message::QueuedDecoder);

        tbc.test_onNegotiateTimeout();

        assert(tbc.timeout);
    }

    return 0;
}