Skip to content

Commit

Permalink
added error test case
Browse files Browse the repository at this point in the history
  • Loading branch information
mpgerlek committed Mar 22, 2012
1 parent 905be18 commit 7567cdb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/filters/Predicate.cpp
Expand Up @@ -93,7 +93,10 @@ boost::uint32_t Predicate::processBuffer(PointBuffer& srcData, PointBuffer& dstD

python.execute();

assert(python.hasOutputVariable("Mask"));
if (!python.hasOutputVariable("Mask"))
{
throw python_error("Mask variable not set in predicate filter function");
}

boost::uint8_t* mask = new boost::uint8_t[srcData.getNumPoints()];
python.extractResult("Mask", (boost::uint8_t*)mask, srcData.getNumPoints(), 1, pdal::dimension::UnsignedByte, 1);
Expand Down
38 changes: 38 additions & 0 deletions test/unit/PredicateFilterTest.cpp
Expand Up @@ -270,5 +270,43 @@ BOOST_AUTO_TEST_CASE(PredicateFilterTest_test4)
return;
}

BOOST_AUTO_TEST_CASE(PredicateFilterTest_test5)
{
// test error handling if missing Mask

Bounds<double> bounds(0.0, 0.0, 0.0, 2.0, 2.0, 2.0);
pdal::drivers::faux::Reader reader(bounds, 1000, pdal::drivers::faux::Reader::Ramp);

const pdal::Option source("source",
// "Y > 0.5"
"import numpy as np\n"
"def yow2(ins,outs):\n"
" Y = ins['Y']\n"
" Mask = np.greater(Y, 0.5)\n"
" #print Mask\n"
" outs['xxxMaskxxx'] = Mask # delierbately rong\n"
" return True\n"
);
const pdal::Option module("module", "MyModule1");
const pdal::Option function("function", "yow2");
pdal::Options opts;
opts.add(source);
opts.add(module);
opts.add(function);

pdal::filters::Predicate filter(reader, opts);

filter.initialize();

const Schema& schema = filter.getSchema();
PointBuffer data(schema, 1000);

boost::scoped_ptr<pdal::StageSequentialIterator> iter(filter.createSequentialIterator(data));

BOOST_REQUIRE_THROW(iter->read(data), pdal::python_error);

return;
}

BOOST_AUTO_TEST_SUITE_END()
#endif

0 comments on commit 7567cdb

Please sign in to comment.