cyphesis/tests/Py_FilterTest.cpp

49 lines
1.1 KiB
C++
Raw Permalink Normal View History

2014-08-05 21:52:03 -04:00
#ifdef NDEBUG
#undef NDEBUG
#endif
#ifndef DEBUG
#define DEBUG
#endif
#include <Python.h>
#include "python_testers.h"
#include "rulesets/Python_API.h"
#include "rulesets/Py_Filter.h"
#include <cassert>
int main()
{
init_python_api("");
run_python_string("import entity_filter");
2014-08-05 21:52:03 -04:00
//Try creating a filter with a valid query
run_python_string("test_filter=entity_filter.get_filter('entity.burn_speed=0.3')");
2014-08-05 21:52:03 -04:00
//Try creating an invalid filter
expect_python_error("entity_filter.get_filter('foobar')", PyExc_TypeError);
2014-08-05 21:52:03 -04:00
2014-08-11 15:46:19 -04:00
//test deallocator
run_python_string("assert(test_filter)");
run_python_string("del(test_filter)");
//We need PyThing components to test in-python entity matching
run_python_string("from server import *");
run_python_string("from atlas import Operation");
run_python_string("le1 = LocatedEntity('1')");
run_python_string("le2 = LocatedEntity('2')");
run_python_string("f = entity_filter.get_filter('entity.id=1')");
run_python_string("assert(f.match_entity(le1))");
run_python_string("assert(not f.match_entity(le2))");
2014-08-05 21:52:03 -04:00
shutdown_python_api();
return 0;
}