2009-05-28 02:18:41 +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-28 02:18:41 +01:00
|
|
|
#include <Python.h>
|
|
|
|
|
|
2009-11-20 20:18:53 +00:00
|
|
|
#include "python_testers.h"
|
|
|
|
|
|
2009-05-28 02:18:41 +01:00
|
|
|
#include "rulesets/Python_API.h"
|
2009-11-11 01:28:27 +00:00
|
|
|
#include "rulesets/Py_WorldTime.h"
|
2009-05-28 02:18:41 +01:00
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
2009-11-11 01:28:27 +00:00
|
|
|
static PyObject * null_wrapper(PyObject * self, PyWorldTime * o)
|
|
|
|
|
{
|
|
|
|
|
if (!PyWorldTime_Check(o)) {
|
|
|
|
|
PyErr_SetString(PyExc_TypeError, "Unknown Object type");
|
|
|
|
|
return Py_True;
|
|
|
|
|
}
|
2011-02-16 09:00:40 +00:00
|
|
|
#ifdef CYPHESIS_DEBUG
|
2009-11-11 01:28:27 +00:00
|
|
|
o->time = 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-28 02:18:41 +01:00
|
|
|
int main()
|
|
|
|
|
{
|
2012-01-19 19:34:20 +00:00
|
|
|
init_python_api("cc4b05b9-4ff9-4127-85b0-300298d16c3c");
|
2009-05-28 02:18:41 +01:00
|
|
|
|
2009-11-11 01:28:27 +00:00
|
|
|
setup_test_functions();
|
|
|
|
|
|
|
|
|
|
PyWorldTime * world_time = newPyWorldTime();
|
|
|
|
|
assert(world_time != 0);
|
|
|
|
|
|
2009-11-20 20:18:53 +00:00
|
|
|
run_python_string("from server import WorldTime");
|
2012-01-04 17:17:52 +00:00
|
|
|
expect_python_error("WorldTime()", PyExc_TypeError);
|
2009-11-20 20:18:53 +00:00
|
|
|
run_python_string("WorldTime(23)");
|
2010-12-28 15:09:07 +00:00
|
|
|
// FIXME This started failing with Python 2.7
|
|
|
|
|
// run_python_string("WorldTime(23.1)");
|
2009-05-28 02:18:41 +01:00
|
|
|
|
2009-11-20 20:18:53 +00:00
|
|
|
run_python_string("w=WorldTime(23)");
|
|
|
|
|
run_python_string("w.season");
|
2012-01-04 17:17:52 +00:00
|
|
|
expect_python_error("w.foo", PyExc_AttributeError);
|
2009-11-20 20:18:53 +00:00
|
|
|
run_python_string("w.is_now('morning')");
|
2012-01-04 17:17:52 +00:00
|
|
|
expect_python_error("w.is_now(1)", PyExc_TypeError);
|
2009-11-20 20:18:53 +00:00
|
|
|
run_python_string("w.seconds()");
|
2009-05-28 02:18:41 +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(w)");
|
2009-11-11 01:28:27 +00:00
|
|
|
// Hit the assert checks.
|
2012-01-04 17:17:52 +00:00
|
|
|
expect_python_error("w.is_now('morning')", PyExc_AssertionError);
|
|
|
|
|
expect_python_error("w.seconds()", PyExc_AssertionError);
|
2009-11-11 01:28:27 +00:00
|
|
|
#endif // NDEBUG
|
2009-05-28 02:18:41 +01:00
|
|
|
|
|
|
|
|
shutdown_python_api();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|