2009-05-19 00:25:51 +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
|
|
|
|
|
|
|
|
|
|
|
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-19 00:25:51 +01:00
|
|
|
#include <Python.h>
|
|
|
|
|
|
2009-11-20 20:18:53 +00:00
|
|
|
#include "python_testers.h"
|
|
|
|
|
|
2009-11-13 03:36:01 +00:00
|
|
|
#include "TestWorld.h"
|
|
|
|
|
|
2013-01-17 10:17:07 +00:00
|
|
|
#include "rulesets/Entity.h"
|
2009-05-19 00:25:51 +01:00
|
|
|
#include "rulesets/Python_API.h"
|
2009-11-11 01:49:23 +00:00
|
|
|
#include "rulesets/Py_Location.h"
|
2009-11-13 03:36:01 +00:00
|
|
|
#include "rulesets/Py_Thing.h"
|
2009-05-19 00:25:51 +01:00
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
2009-11-11 01:49:23 +00:00
|
|
|
static PyObject * null_wrapper(PyObject * self, PyLocation * o)
|
|
|
|
|
{
|
2009-11-13 03:36:01 +00:00
|
|
|
if (PyLocation_Check(o)) {
|
2011-02-16 09:00:40 +00:00
|
|
|
#ifdef CYPHESIS_DEBUG
|
2009-11-13 03:36:01 +00:00
|
|
|
o->location = NULL;
|
|
|
|
|
#endif // NDEBUG
|
2011-12-13 19:39:09 +00:00
|
|
|
} else if (PyLocatedEntity_Check(o)) {
|
2011-02-16 09:00:40 +00:00
|
|
|
#ifdef CYPHESIS_DEBUG
|
2009-11-13 03:36:01 +00:00
|
|
|
((PyEntity*)o)->m_entity.l = NULL;
|
|
|
|
|
#endif // NDEBUG
|
|
|
|
|
} else {
|
2009-11-11 01:49:23 +00:00
|
|
|
PyErr_SetString(PyExc_TypeError, "Unknown Object type");
|
2009-11-12 02:46:30 +00:00
|
|
|
return NULL;
|
2009-11-11 01:49:23 +00:00
|
|
|
}
|
|
|
|
|
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-19 00:25:51 +01:00
|
|
|
int main()
|
|
|
|
|
{
|
2012-01-19 19:34:20 +00:00
|
|
|
init_python_api("21b996b0-9dc3-4749-bd8c-24908f372ddc");
|
2009-05-19 00:25:51 +01:00
|
|
|
|
2009-11-11 01:49:23 +00:00
|
|
|
setup_test_functions();
|
|
|
|
|
|
2009-11-13 03:36:01 +00:00
|
|
|
Entity wrld("0", 0);
|
|
|
|
|
TestWorld tw(wrld);
|
|
|
|
|
|
2009-11-20 20:18:53 +00:00
|
|
|
run_python_string("import atlas");
|
|
|
|
|
run_python_string("import server");
|
|
|
|
|
run_python_string("from physics import Point3D");
|
2012-01-04 13:36:30 +00:00
|
|
|
expect_python_error("atlas.Location(set([1,1]))", PyExc_TypeError);
|
|
|
|
|
expect_python_error("atlas.Location(1,1,1)", PyExc_TypeError);
|
2009-11-20 20:18:53 +00:00
|
|
|
run_python_string("atlas.Location(server.LocatedEntity('1'))");
|
|
|
|
|
run_python_string("atlas.Location(server.Thing('1'))");
|
|
|
|
|
run_python_string("atlas.Location(server.Character('1'))");
|
|
|
|
|
run_python_string("atlas.Location(server.World())");
|
|
|
|
|
run_python_string("atlas.Location(server.Mind('1'))");
|
2012-01-04 13:36:30 +00:00
|
|
|
expect_python_error("atlas.Location(server.Thing('1'), 1)",
|
|
|
|
|
PyExc_TypeError);
|
2009-11-20 20:18:53 +00:00
|
|
|
run_python_string("atlas.Location(server.Thing('1'), Point3D(0,0,0))");
|
|
|
|
|
run_python_string("l=atlas.Location()");
|
|
|
|
|
run_python_string("l1=l.copy()");
|
|
|
|
|
run_python_string("l.parent");
|
|
|
|
|
run_python_string("l.coordinates");
|
|
|
|
|
run_python_string("l.velocity");
|
|
|
|
|
run_python_string("l.orientation");
|
|
|
|
|
run_python_string("l.bbox");
|
|
|
|
|
run_python_string("from physics import Vector3D");
|
|
|
|
|
run_python_string("from physics import Quaternion");
|
|
|
|
|
run_python_string("from physics import BBox");
|
|
|
|
|
run_python_string("l.coordinates=Point3D()");
|
|
|
|
|
run_python_string("l.coordinates=Point3D(0,0,0)");
|
|
|
|
|
run_python_string("l.coordinates=Vector3D()");
|
|
|
|
|
run_python_string("l.coordinates=Vector3D(0,0,0)");
|
2012-01-04 13:36:30 +00:00
|
|
|
expect_python_error("l.coordinates=()", PyExc_ValueError);
|
2009-11-20 20:18:53 +00:00
|
|
|
run_python_string("l.coordinates=(0,0,0)");
|
|
|
|
|
run_python_string("l.coordinates=(0.0,0,0)");
|
2012-01-04 13:36:30 +00:00
|
|
|
expect_python_error("l.coordinates=('0',0,0)", PyExc_TypeError);
|
|
|
|
|
expect_python_error("l.coordinates=[]", PyExc_ValueError);
|
2009-11-20 20:18:53 +00:00
|
|
|
run_python_string("l.coordinates=[0,0,0]");
|
|
|
|
|
run_python_string("l.coordinates=[0.0,0,0]");
|
2012-01-04 13:36:30 +00:00
|
|
|
expect_python_error("l.coordinates=['0',0,0]", PyExc_TypeError);
|
2009-11-20 20:18:53 +00:00
|
|
|
run_python_string("l.velocity=Vector3D()");
|
|
|
|
|
run_python_string("l.velocity=Vector3D(0,0,0)");
|
|
|
|
|
run_python_string("l.orientation=Quaternion()");
|
|
|
|
|
run_python_string("l.orientation=Quaternion(0,0,0,1)");
|
|
|
|
|
run_python_string("l.bbox=BBox()");
|
|
|
|
|
run_python_string("l.bbox=Vector3D(0,0,0)");
|
2012-01-04 13:36:30 +00:00
|
|
|
expect_python_error("l.parent='1'", PyExc_TypeError);
|
2009-11-20 20:18:53 +00:00
|
|
|
run_python_string("l.parent=server.Thing('1')");
|
2012-01-04 13:36:30 +00:00
|
|
|
expect_python_error("l.other=Vector3D(0,0,0)", PyExc_AttributeError);
|
2009-11-20 20:18:53 +00:00
|
|
|
run_python_string("repr(l)");
|
|
|
|
|
run_python_string("l2=atlas.Location(server.Thing('1'), Point3D(0,0,0))");
|
|
|
|
|
run_python_string("l.parent");
|
2012-01-24 16:39:02 +00:00
|
|
|
run_python_string("common_parent = server.Thing('1')");
|
|
|
|
|
run_python_string("atlas.Location(common_parent, Point3D(0,0,0)) - atlas.Location(common_parent, Point3D(1,0,0))");
|
|
|
|
|
expect_python_error("atlas.Location(common_parent, Point3D(0,0,0)) - Point3D(1,0,0)", PyExc_TypeError);
|
2009-05-19 00:25:51 +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");
|
2009-11-11 01:49:23 +00:00
|
|
|
// Hit the assert checks.
|
2009-11-20 20:18:53 +00:00
|
|
|
run_python_string("t=server.Thing('1')");
|
|
|
|
|
run_python_string("sabotage.null(t)");
|
2012-01-04 13:36:30 +00:00
|
|
|
expect_python_error("l.parent=t", PyExc_AssertionError);
|
|
|
|
|
expect_python_error("atlas.Location(t)", PyExc_AssertionError);
|
2009-11-20 20:18:53 +00:00
|
|
|
|
|
|
|
|
run_python_string("m=server.Mind('1')");
|
|
|
|
|
run_python_string("sabotage.null(m)");
|
2012-01-04 13:36:30 +00:00
|
|
|
expect_python_error("atlas.Location(m)", PyExc_AssertionError);
|
2009-11-20 20:18:53 +00:00
|
|
|
|
|
|
|
|
run_python_string("copy_methd=l.copy");
|
|
|
|
|
run_python_string("sabotage.null(l)");
|
2012-01-04 13:36:30 +00:00
|
|
|
expect_python_error("copy_methd()", PyExc_AssertionError);
|
|
|
|
|
expect_python_error("l.parent", PyExc_AssertionError);
|
|
|
|
|
expect_python_error("l.velocity=Vector3D()", PyExc_AssertionError);
|
2009-11-11 01:49:23 +00:00
|
|
|
#endif // NDEBUG
|
|
|
|
|
|
2009-05-19 00:25:51 +01:00
|
|
|
shutdown_python_api();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2012-09-06 13:48:40 +01:00
|
|
|
|
2013-01-17 10:17:07 +00:00
|
|
|
void TestWorld::message(const Operation & op, LocatedEntity & ent)
|
2012-09-11 22:53:15 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-17 10:17:07 +00:00
|
|
|
LocatedEntity * TestWorld::addNewEntity(const std::string &,
|
2012-09-06 13:48:40 +01:00
|
|
|
const Atlas::Objects::Entity::RootEntity &)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|