2009-05-25 16:35:25 +01: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
|
|
|
|
|
|
|
|
|
|
// $Id$
|
|
|
|
|
|
2011-02-15 09:30:46 +00:00
|
|
|
#ifdef NDEBUG
|
|
|
|
|
#undef NDEBUG
|
2011-02-16 09:00:40 +00:00
|
|
|
#else
|
|
|
|
|
#define CYPHESIS_DEBUG
|
2011-02-15 09:30:46 +00:00
|
|
|
#endif
|
|
|
|
|
#ifndef DEBUG
|
|
|
|
|
#define DEBUG
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-05-25 16:35:25 +01:00
|
|
|
#include <Python.h>
|
|
|
|
|
|
2009-11-20 20:18:53 +00:00
|
|
|
#include "python_testers.h"
|
|
|
|
|
|
2009-05-25 16:35:25 +01:00
|
|
|
#include "rulesets/Python_API.h"
|
2009-11-11 02:26:56 +00:00
|
|
|
#include "rulesets/Py_Map.h"
|
2009-05-25 16:35:25 +01:00
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
2009-11-11 02:26:56 +00:00
|
|
|
static PyObject * null_wrapper(PyObject * self, PyMap * o)
|
|
|
|
|
{
|
|
|
|
|
if (!PyMap_Check(o)) {
|
|
|
|
|
PyErr_SetString(PyExc_TypeError, "Unknown Object type");
|
2009-11-12 02:46:30 +00:00
|
|
|
return NULL;
|
2009-11-11 02:26:56 +00:00
|
|
|
}
|
2011-02-16 09:00:40 +00:00
|
|
|
#ifdef CYPHESIS_DEBUG
|
2009-11-11 02:26:56 +00:00
|
|
|
o->m_map = NULL;
|
|
|
|
|
#endif // NDEBUG
|
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
|
return Py_None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PyMethodDef sabotage_methods[] = {
|
|
|
|
|
{"null", (PyCFunction)null_wrapper, METH_O},
|
|
|
|
|
{NULL, NULL} /* Sentinel */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void setup_test_functions()
|
|
|
|
|
{
|
|
|
|
|
PyObject * sabotage = Py_InitModule("sabotage", sabotage_methods);
|
|
|
|
|
assert(sabotage != 0);
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-25 16:35:25 +01:00
|
|
|
int main()
|
|
|
|
|
{
|
2012-01-19 19:34:20 +00:00
|
|
|
init_python_api("93b8eac3-9ab9-40f7-b419-d740c18c09e4");
|
2009-05-25 16:35:25 +01:00
|
|
|
|
2009-11-11 02:26:56 +00:00
|
|
|
setup_test_functions();
|
|
|
|
|
|
|
|
|
|
PyMap * map = newPyMap();
|
|
|
|
|
assert(map != 0);
|
|
|
|
|
|
2009-11-20 20:18:53 +00:00
|
|
|
run_python_string("from server import Map");
|
|
|
|
|
run_python_string("from atlas import Location");
|
|
|
|
|
run_python_string("from atlas import Entity");
|
|
|
|
|
run_python_string("from atlas import Message");
|
|
|
|
|
run_python_string("m=Map()");
|
2012-01-04 13:44:36 +00:00
|
|
|
expect_python_error("m.find_by_location()", PyExc_TypeError);
|
2009-11-20 20:18:53 +00:00
|
|
|
run_python_string("l=Location()");
|
2012-01-04 13:44:36 +00:00
|
|
|
expect_python_error("m.find_by_location(l)", PyExc_TypeError);
|
|
|
|
|
expect_python_error("m.find_by_location(l, 5.0, 'foo')",
|
|
|
|
|
PyExc_RuntimeError);
|
|
|
|
|
expect_python_error("m.find_by_location(5, 5.0, 'foo')", PyExc_TypeError);
|
|
|
|
|
expect_python_error("m.find_by_type()", PyExc_TypeError);
|
|
|
|
|
expect_python_error("m.find_by_type(1)", PyExc_TypeError);
|
2009-11-20 20:18:53 +00:00
|
|
|
run_python_string("m.find_by_type('foo')");
|
2012-01-04 13:44:36 +00:00
|
|
|
expect_python_error("m.add()", PyExc_TypeError);
|
|
|
|
|
expect_python_error("m.add('2')", PyExc_TypeError);
|
|
|
|
|
expect_python_error("m.add('2', 1.2)", PyExc_TypeError);
|
|
|
|
|
expect_python_error("m.add(Message())", PyExc_TypeError);
|
|
|
|
|
expect_python_error("m.add(Message(), 1.2)", PyExc_TypeError);
|
|
|
|
|
expect_python_error("m.add(Message({'objtype': 'op', 'parents': ['get']}), 1.2)",
|
|
|
|
|
PyExc_TypeError);
|
|
|
|
|
expect_python_error("m.add(Message({}), 1.2)", PyExc_TypeError);
|
|
|
|
|
expect_python_error("m.add(Message({'parents': 'get'}), 1.2)",
|
|
|
|
|
PyExc_TypeError);
|
2009-11-20 20:18:53 +00:00
|
|
|
run_python_string("m.add(Message({'id': '2'}), 1.2)");
|
|
|
|
|
run_python_string("m.add(Message({'id': '2'}), 1.2)");
|
2012-01-04 13:44:36 +00:00
|
|
|
expect_python_error("m.add(Entity())", PyExc_TypeError);
|
|
|
|
|
expect_python_error("m.add(Entity('1', type='oak'))", PyExc_TypeError);
|
2009-11-20 20:18:53 +00:00
|
|
|
run_python_string("m.add(Entity('1', type='thing'), 1.1)");
|
|
|
|
|
run_python_string("m.find_by_type('thing')");
|
2012-01-04 13:44:36 +00:00
|
|
|
expect_python_error("m.get()", PyExc_TypeError);
|
|
|
|
|
expect_python_error("m.get(1)", PyExc_TypeError);
|
2009-11-20 20:18:53 +00:00
|
|
|
run_python_string("m.get('1')");
|
|
|
|
|
run_python_string("m.get('23')");
|
2012-01-04 13:44:36 +00:00
|
|
|
expect_python_error("m.get_add()", PyExc_TypeError);
|
|
|
|
|
expect_python_error("m.get_add(3)", PyExc_TypeError);
|
2009-11-20 20:18:53 +00:00
|
|
|
run_python_string("m.get_add('3')");
|
2012-01-04 13:44:36 +00:00
|
|
|
run_python_string("m.update(Entity('3', type='thing'), 1.1)");
|
|
|
|
|
expect_python_error("m.update()", PyExc_TypeError);
|
|
|
|
|
expect_python_error("m.delete()", PyExc_TypeError);
|
|
|
|
|
expect_python_error("m.delete(1)", PyExc_TypeError);
|
2009-11-20 20:18:53 +00:00
|
|
|
run_python_string("m.delete('1')");
|
2012-01-04 13:44:36 +00:00
|
|
|
expect_python_error("m.add_hooks_append()", PyExc_TypeError);
|
|
|
|
|
expect_python_error("m.add_hooks_append(1)", PyExc_TypeError);
|
2009-11-20 20:18:53 +00:00
|
|
|
run_python_string("m.add_hooks_append('add_map')");
|
2012-01-04 13:44:36 +00:00
|
|
|
expect_python_error("m.update_hooks_append()", PyExc_TypeError);
|
|
|
|
|
expect_python_error("m.update_hooks_append(1)", PyExc_TypeError);
|
2009-11-20 20:18:53 +00:00
|
|
|
run_python_string("m.update_hooks_append('update_map')");
|
2012-01-04 13:44:36 +00:00
|
|
|
expect_python_error("m.delete_hooks_append()", PyExc_TypeError);
|
|
|
|
|
expect_python_error("m.delete_hooks_append(1)", PyExc_TypeError);
|
2009-11-20 20:18:53 +00:00
|
|
|
run_python_string("m.delete_hooks_append('delete_map')");
|
2009-05-25 16:35:25 +01:00
|
|
|
|
2011-02-16 09:00:40 +00:00
|
|
|
#ifdef CYPHESIS_DEBUG
|
2009-11-20 20:18:53 +00:00
|
|
|
run_python_string("import sabotage");
|
|
|
|
|
run_python_string("sabotage.null(m)");
|
2009-11-11 02:26:56 +00:00
|
|
|
// Hit the assert checks.
|
2012-01-04 13:44:36 +00:00
|
|
|
expect_python_error("m.find_by_location(l, 5.0, 'foo')",
|
|
|
|
|
PyExc_AssertionError);
|
|
|
|
|
expect_python_error("m.find_by_type('foo')", PyExc_AssertionError);
|
|
|
|
|
expect_python_error("m.add(Entity('1', type='thing'), 1.1)",
|
|
|
|
|
PyExc_AssertionError);
|
|
|
|
|
expect_python_error("m.delete('1')", PyExc_AssertionError);
|
|
|
|
|
expect_python_error("m.get('1')", PyExc_AssertionError);
|
|
|
|
|
expect_python_error("m.get_add('3')", PyExc_AssertionError);
|
|
|
|
|
expect_python_error("m.add_hooks_append('add_map')",
|
|
|
|
|
PyExc_AssertionError);
|
|
|
|
|
expect_python_error("m.update_hooks_append('update_map')",
|
|
|
|
|
PyExc_AssertionError);
|
|
|
|
|
expect_python_error("m.delete_hooks_append('delete_map')",
|
|
|
|
|
PyExc_AssertionError);
|
2009-11-11 02:26:56 +00:00
|
|
|
#endif // NDEBUG
|
|
|
|
|
|
2009-05-25 16:35:25 +01:00
|
|
|
shutdown_python_api();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|