int main() { PyImport_AppendInittab("testprop", [](){ auto module = new TestProp(); return module->module().ptr(); }); init_python_api({&CyPy_Server::init, &CyPy_Rules::init, &CyPy_Atlas::init, &CyPy_Physics::init, &CyPy_Common::init}); Ref<Entity> wrld(new Entity("0", 0)); TestWorld tw(wrld); run_python_string("from server import *"); run_python_string("import testprop"); run_python_string("t=Thing('1')"); run_python_string("t.props.line == None"); run_python_string("t.props.statistics == None"); run_python_string("t.props.terrain == None"); run_python_string("testprop.add_properties(t)"); run_python_string("t.props.line"); run_python_string("t.props.statistics"); run_python_string("t.props.terrain"); shutdown_python_api(); return 0; }
int main() { init_python_api("cb44c6cc-64fa-46c4-83d1-f43c6a2bb56c"); Entity wrld("0", 0); TestWorld tw(wrld); run_python_string("from server import World"); run_python_string("w=World()"); run_python_string("w.get_time()"); run_python_string("w.get_object('0')"); run_python_string("w.get_object('1')"); expect_python_error("w.get_object(1)", PyExc_TypeError); run_python_string("w == World()"); shutdown_python_api(); return 0; }
int main() { init_python_api("b513b7b1-b0d8-4495-b3f0-54c2ef3f27f6"); setup_test_functions(); Entity wrld("0", 0); TestWorld tw(wrld); run_python_string("from server import *"); run_python_string("import testprop"); run_python_string("t=Thing('1')"); expect_python_error("t.line", PyExc_AttributeError); expect_python_error("t.statistics", PyExc_AttributeError); expect_python_error("t.terrain", PyExc_AttributeError); run_python_string("testprop.add_properties(t)"); run_python_string("t.line"); run_python_string("t.statistics"); run_python_string("t.terrain"); shutdown_python_api(); return 0; }
int main() { // We have to use the TestWorld class, as it implements the functions // missing from BaseWorld interface. { // Test constructor Entity wrld("1", 1); TestWorld tw(wrld); } { // Test destructor Entity wrld("1", 1); BaseWorld * tw = new TestWorld(wrld); delete tw; } { // Test constructor sets singleton pointer Entity wrld("1", 1); TestWorld tw(wrld); assert(&BaseWorld::instance() == &tw); } { // Test constructor installs reference to world entity Entity wrld("1", 1); TestWorld tw(wrld); assert(&tw.m_gameWorld == &wrld); } { // Test retrieving non existant entity by string ID is ok Entity wrld("1", 1); TestWorld tw(wrld); assert(tw.getEntity("2") == 0); } { // Test retrieving existant entity by string ID is ok Entity wrld("1", 1); TestWorld tw(wrld); Entity * tc = new Entity("2", 2); tw.addEntity(tc); assert(tw.getEntity("2") == tc); } { // Test retrieving existant entity by integer ID is ok Entity wrld("1", 1); TestWorld tw(wrld); Entity * tc = new Entity("2", 2); tw.addEntity(tc); assert(tw.getEntity(2) == tc); } { // Test retrieving non existant entity by integer ID is ok Entity wrld("1", 1); TestWorld tw(wrld); assert(tw.getEntity(2) == 0); } { // Test retrieving reference to all entities is okay and empty Entity wrld("1", 1); TestWorld tw(wrld); assert(tw.getEntities().size() == 1); } { // Test getting the time Entity wrld("1", 1); TestWorld tw(wrld); tw.getTime(); } { // Test getting the uptime Entity wrld("1", 1); TestWorld tw(wrld); tw.upTime(); } { // Test connecting to the dispatch signal Entity wrld("1", 1); TestWorld tw(wrld); tw.Dispatching.connect(sigc::ptr_fun(&test_function)); } return 0; }