mirror of
https://github.com/worldforge/cyphesis
synced 2026-08-13 12:26:04 -04:00
Add full coverage test for PythonArithmeticScript
This commit is contained in:
parent
5aaf097e2f
commit
d975bdfaf1
2 changed files with 84 additions and 1 deletions
72
tests/PythonArithmeticScripttest.cpp
Normal file
72
tests/PythonArithmeticScripttest.cpp
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
// 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$
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include "rulesets/Python_API.h"
|
||||
#include "rulesets/Python_Script_Utils.h"
|
||||
#include "rulesets/PythonArithmeticScript.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
static PyMethodDef no_methods[] = {
|
||||
{NULL, NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
init_python_api();
|
||||
|
||||
PyObject * testmod = Py_InitModule("testmod", no_methods);
|
||||
|
||||
assert(testmod != 0);
|
||||
|
||||
assert(PyRun_SimpleString("import testmod") == 0);
|
||||
assert(PyRun_SimpleString("class TestArithmeticScript(object):\n"
|
||||
" def __init__(self):\n"
|
||||
" self.foo=1\n"
|
||||
" self.bar=1.1\n"
|
||||
" self.baz=None\n"
|
||||
" self.qux='1'\n"
|
||||
) == 0);
|
||||
assert(PyRun_SimpleString("testmod.TestArithmeticScript=TestArithmeticScript") == 0);
|
||||
|
||||
PyObject * clss = Get_PyClass(testmod, "testmod", "TestArithmeticScript");
|
||||
|
||||
assert(clss != 0);
|
||||
|
||||
PyObject * instance = PyEval_CallFunction(clss,"()");
|
||||
|
||||
assert(instance != 0);
|
||||
|
||||
PythonArithmeticScript pas(instance);
|
||||
|
||||
float val;
|
||||
pas.attribute("foo", val);
|
||||
pas.attribute("bar", val);
|
||||
pas.attribute("baz", val);
|
||||
pas.attribute("qux", val);
|
||||
pas.attribute("nonexistent", val);
|
||||
|
||||
pas.set("foo", 1.0f);
|
||||
pas.set("mim", 1.0f);
|
||||
|
||||
shutdown_python_api();
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue