2009-11-26 16:56:18 +00:00
|
|
|
// Cyphesis Online RPG Server and AI Engine
|
|
|
|
|
// Copyright (C) 2009 Alistair Riddoch
|
|
|
|
|
//
|
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
|
|
|
2011-02-15 09:30:46 +00:00
|
|
|
#ifdef NDEBUG
|
|
|
|
|
#undef NDEBUG
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef DEBUG
|
|
|
|
|
#define DEBUG
|
|
|
|
|
#endif
|
|
|
|
|
|
2013-01-03 11:54:37 +00:00
|
|
|
#include "TestBase.h"
|
|
|
|
|
|
2009-11-26 16:56:18 +00:00
|
|
|
#include "client/ClientConnection.h"
|
|
|
|
|
|
|
|
|
|
#include <Atlas/Objects/Operation.h>
|
|
|
|
|
#include <Atlas/Objects/Anonymous.h>
|
|
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
2013-01-03 12:33:29 +00:00
|
|
|
using Atlas::Message::Element;
|
2009-11-26 16:56:18 +00:00
|
|
|
using Atlas::Objects::Root;
|
|
|
|
|
using Atlas::Objects::Entity::Anonymous;
|
|
|
|
|
using Atlas::Objects::Operation::Error;
|
|
|
|
|
using Atlas::Objects::Operation::Info;
|
|
|
|
|
using Atlas::Objects::Operation::RootOperation;
|
|
|
|
|
|
2013-01-03 11:54:37 +00:00
|
|
|
class ClientConnectiontest : public Cyphesis::TestBase
|
|
|
|
|
{
|
2018-10-27 13:13:45 +02:00
|
|
|
boost::asio::io_service io_service;
|
|
|
|
|
ClientConnection * cc{};
|
2013-01-03 11:54:37 +00:00
|
|
|
public:
|
|
|
|
|
ClientConnectiontest();
|
|
|
|
|
|
2018-10-27 13:13:45 +02:00
|
|
|
void setup() override;
|
|
|
|
|
void teardown() override;
|
2013-01-03 11:54:37 +00:00
|
|
|
|
|
|
|
|
void test_sequence();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ClientConnectiontest::ClientConnectiontest()
|
|
|
|
|
{
|
|
|
|
|
ADD_TEST(ClientConnectiontest::test_sequence);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClientConnectiontest::setup()
|
|
|
|
|
{
|
2018-10-27 13:13:45 +02:00
|
|
|
cc = new ClientConnection(io_service);
|
2013-01-03 11:54:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClientConnectiontest::teardown()
|
2009-11-26 16:56:18 +00:00
|
|
|
{
|
|
|
|
|
delete cc;
|
2013-01-03 11:54:37 +00:00
|
|
|
}
|
2009-11-26 16:56:18 +00:00
|
|
|
|
2013-01-03 11:54:37 +00:00
|
|
|
void ClientConnectiontest::test_sequence()
|
|
|
|
|
{
|
2009-11-26 16:56:18 +00:00
|
|
|
// Try all the method calls when not connected
|
|
|
|
|
|
|
|
|
|
cc->login("username", "password");
|
2009-12-03 19:17:55 +00:00
|
|
|
cc->create("player", "username", "password");
|
2009-11-26 16:56:18 +00:00
|
|
|
cc->wait();
|
|
|
|
|
|
|
|
|
|
{
|
2013-01-03 12:00:13 +00:00
|
|
|
RootOperation op;
|
2009-11-26 16:56:18 +00:00
|
|
|
cc->send(op);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cc->pop();
|
|
|
|
|
cc->pending();
|
|
|
|
|
|
|
|
|
|
{
|
2013-01-03 12:00:13 +00:00
|
|
|
Root obj;
|
|
|
|
|
RootOperation op;
|
|
|
|
|
cc->operation(op);
|
2009-11-26 16:56:18 +00:00
|
|
|
|
|
|
|
|
Anonymous op_arg;
|
|
|
|
|
op->setArgs1(op_arg);
|
|
|
|
|
|
|
|
|
|
op->setFrom("1");
|
2017-07-24 13:39:22 +02:00
|
|
|
op->setParent("");
|
2013-01-03 12:00:13 +00:00
|
|
|
cc->operation(op);
|
2009-11-26 16:56:18 +00:00
|
|
|
|
|
|
|
|
Info i;
|
2013-01-03 12:33:29 +00:00
|
|
|
cc->operation(i);
|
2009-11-26 16:56:18 +00:00
|
|
|
|
|
|
|
|
Error e;
|
2013-01-03 12:33:29 +00:00
|
|
|
cc->operation(e);
|
2009-11-26 16:56:18 +00:00
|
|
|
}
|
2013-01-03 11:54:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
ClientConnectiontest t;
|
|
|
|
|
|
|
|
|
|
return t.run();
|
2009-11-26 16:56:18 +00:00
|
|
|
}
|
2013-01-03 12:33:29 +00:00
|
|
|
|
|
|
|
|
// stubs
|
2018-10-27 13:13:45 +02:00
|
|
|
#define STUB_AtlasStreamClient_poll
|
2013-01-03 12:33:29 +00:00
|
|
|
int AtlasStreamClient::poll(int timeOut, int msec)
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2018-10-27 13:13:45 +02:00
|
|
|
#include "stubs/common/stubAtlasStreamClient.h"
|