2009-11-26 01:37:47 +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
|
|
|
|
|
|
2009-11-26 01:37:47 +00:00
|
|
|
#include <Python.h>
|
|
|
|
|
|
|
|
|
|
#include "python_testers.h"
|
|
|
|
|
|
2010-07-27 18:05:34 +01:00
|
|
|
#include "client/Python_ClientAPI.h"
|
|
|
|
|
|
2009-11-26 01:37:47 +00:00
|
|
|
#include "rulesets/Python_API.h"
|
|
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
2011-12-29 17:50:27 +00:00
|
|
|
static bool stub_setup_fail = false;
|
|
|
|
|
static bool stub_createCharacter_fail = false;
|
|
|
|
|
static bool stub_send_wait_fail = false;
|
|
|
|
|
static int stub_send_wait_results = 0;
|
|
|
|
|
static bool stub_wait_fail = false;
|
|
|
|
|
|
2009-11-26 01:37:47 +00:00
|
|
|
int main()
|
|
|
|
|
{
|
2012-01-19 19:34:20 +00:00
|
|
|
init_python_api("230dabbb-d676-4d43-8a03-4623c02503b5");
|
2009-11-26 01:37:47 +00:00
|
|
|
extend_client_python_api();
|
|
|
|
|
|
2011-12-29 17:50:27 +00:00
|
|
|
run_python_string("import atlas");
|
2009-11-26 01:37:47 +00:00
|
|
|
run_python_string("import server");
|
2011-12-29 17:50:27 +00:00
|
|
|
run_python_string("import types");
|
|
|
|
|
run_python_string("o=server.ObserverClient()");
|
|
|
|
|
run_python_string("o.setup()");
|
2012-01-04 14:37:44 +00:00
|
|
|
expect_python_error("o.setup('bob')", PyExc_TypeError);
|
2011-12-29 17:50:27 +00:00
|
|
|
run_python_string("o.setup('bob', 'jim')");
|
|
|
|
|
run_python_string("o.setup('bob', 'jim', 'settler')");
|
|
|
|
|
stub_setup_fail = true;
|
2012-01-04 14:37:44 +00:00
|
|
|
expect_python_error("o.setup('bob', 'jim', 'settler')",
|
|
|
|
|
PyExc_RuntimeError);
|
2011-12-29 17:50:27 +00:00
|
|
|
stub_setup_fail = false;
|
|
|
|
|
run_python_string("o.create_avatar('settler')");
|
2012-01-04 14:37:44 +00:00
|
|
|
expect_python_error("o.create_avatar(1)", PyExc_TypeError);
|
2011-12-29 17:50:27 +00:00
|
|
|
run_python_string("o.run()");
|
2012-01-04 14:37:44 +00:00
|
|
|
expect_python_error("o.send()", PyExc_TypeError);
|
|
|
|
|
expect_python_error("o.send('get')", PyExc_TypeError);
|
2011-12-29 17:50:27 +00:00
|
|
|
run_python_string("o.send(atlas.Operation('get'))");
|
2012-01-04 14:37:44 +00:00
|
|
|
expect_python_error("o.send_wait()", PyExc_TypeError);
|
|
|
|
|
expect_python_error("o.send_wait('get')", PyExc_TypeError);
|
2011-12-29 17:50:27 +00:00
|
|
|
run_python_string("o.send_wait(atlas.Operation('get'))");
|
|
|
|
|
stub_send_wait_results = 1;
|
|
|
|
|
run_python_string("assert type(o.send_wait(atlas.Operation('get'))) == atlas.Operation");
|
|
|
|
|
stub_send_wait_results = 2;
|
|
|
|
|
run_python_string("assert type(o.send_wait(atlas.Operation('get'))) == atlas.Oplist");
|
|
|
|
|
run_python_string("assert len(o.send_wait(atlas.Operation('get'))) == 2");
|
|
|
|
|
stub_send_wait_fail = true;
|
|
|
|
|
// FIXME This really should fail
|
2012-01-04 14:37:44 +00:00
|
|
|
// expect_python_error("o.send_wait(atlas.Operation('get'))",
|
|
|
|
|
// PyExc_AssertionError);
|
2011-12-29 17:50:27 +00:00
|
|
|
run_python_string("o.wait()");
|
|
|
|
|
stub_wait_fail = true;
|
2012-01-04 14:37:44 +00:00
|
|
|
expect_python_error("o.wait()", PyExc_RuntimeError);
|
2018-05-04 19:17:55 +02:00
|
|
|
run_python_string("assert type(o.id) == str");
|
2011-12-29 17:50:27 +00:00
|
|
|
run_python_string("o.character");
|
|
|
|
|
run_python_string("o.server = 'foo'");
|
2012-01-04 14:37:44 +00:00
|
|
|
expect_python_error("o.server = 23", PyExc_TypeError);
|
2011-12-29 17:50:27 +00:00
|
|
|
|
|
|
|
|
run_python_string("o == server.ObserverClient()");
|
|
|
|
|
|
2009-11-26 01:37:47 +00:00
|
|
|
|
|
|
|
|
shutdown_python_api();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2011-12-28 18:20:22 +01:00
|
|
|
|
|
|
|
|
// stubs
|
|
|
|
|
|
|
|
|
|
#include "client/ObserverClient.h"
|
|
|
|
|
#include "client/CreatorClient.h"
|
|
|
|
|
|
|
|
|
|
#include <Atlas/Objects/Operation.h>
|
|
|
|
|
|
|
|
|
|
using Atlas::Objects::Entity::RootEntity;
|
|
|
|
|
|
2011-12-29 10:35:22 +01:00
|
|
|
CharacterClient::CharacterClient(const std::string & id, long intId,
|
|
|
|
|
ClientConnection & c) :
|
|
|
|
|
BaseMind(id, intId), m_connection(c)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-28 18:20:22 +01:00
|
|
|
LocatedEntity * CharacterClient::look(const std::string & id)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LocatedEntity * CharacterClient::lookFor(const RootEntity & ent)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-29 10:35:22 +01:00
|
|
|
void CharacterClient::send(const Operation & op)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CreatorClient::CreatorClient(const std::string & id, long intId,
|
|
|
|
|
ClientConnection &c) :
|
|
|
|
|
CharacterClient(id, intId, c)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-28 18:20:22 +01:00
|
|
|
LocatedEntity * CreatorClient::make(const RootEntity & entity)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CreatorClient::sendSet(const std::string & id,
|
|
|
|
|
const RootEntity & entity)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CreatorClient::del(const std::string & id)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ObserverClient::ObserverClient()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ObserverClient::~ObserverClient()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ObserverClient::setup(const std::string & account,
|
|
|
|
|
const std::string & password,
|
|
|
|
|
const std::string & avatar)
|
|
|
|
|
{
|
2011-12-29 17:50:27 +00:00
|
|
|
if (stub_setup_fail) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2011-12-28 18:20:22 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-27 10:45:19 +01:00
|
|
|
int ObserverClient::teardown()
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-28 18:20:22 +01:00
|
|
|
void ObserverClient::idle()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BaseClient::BaseClient() : m_character(0)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BaseClient::~BaseClient()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Atlas::Objects::Root BaseClient::createSystemAccount()
|
|
|
|
|
{
|
|
|
|
|
return Atlas::Objects::Operation::Info();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Atlas::Objects::Root BaseClient::createAccount(const std::string & name,
|
|
|
|
|
const std::string & password)
|
|
|
|
|
{
|
|
|
|
|
return Atlas::Objects::Operation::Info();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BaseClient::send(const Operation & op)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CreatorClient * BaseClient::createCharacter(const std::string & type)
|
|
|
|
|
{
|
2011-12-29 17:50:27 +00:00
|
|
|
if (stub_createCharacter_fail) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return new CreatorClient("1", 1, *new ClientConnection);
|
2011-12-28 18:20:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientConnection::ClientConnection()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientConnection::~ClientConnection()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ClientConnection::wait()
|
|
|
|
|
{
|
2011-12-29 17:50:27 +00:00
|
|
|
if (stub_wait_fail) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2011-12-28 18:20:22 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ClientConnection::sendAndWaitReply(const Operation & op, OpVector & res)
|
|
|
|
|
{
|
2011-12-29 17:50:27 +00:00
|
|
|
if (stub_send_wait_fail) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < stub_send_wait_results; ++i) {
|
|
|
|
|
res.push_back(Atlas::Objects::Operation::Info());
|
|
|
|
|
}
|
2011-12-28 18:20:22 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClientConnection::operation(const Operation & op)
|
|
|
|
|
{
|
|
|
|
|
}
|