Added CHECK_EXCEPTION() that can test whether an operation throws a specific exception, and used it in example tests
parent
bde73355b8
commit
cf2b3db5a6
|
@ -66,6 +66,15 @@ protected:
|
||||||
return; } \
|
return; } \
|
||||||
catch (...) {} }
|
catch (...) {} }
|
||||||
|
|
||||||
|
#define CHECK_EXCEPTION(condition, exception_name)\
|
||||||
|
{ try { condition; \
|
||||||
|
result_.addFailure (Failure (name_, __FILE__,__LINE__, SimpleString("Didn't throw: ") + StringFrom(#condition))); \
|
||||||
|
return; } \
|
||||||
|
catch (exception_name& e) {} \
|
||||||
|
catch (...) { \
|
||||||
|
result_.addFailure (Failure (name_, __FILE__,__LINE__, SimpleString("Wrong exception: ") + StringFrom(#condition) + StringFrom(", expected: ") + StringFrom(#exception_name))); \
|
||||||
|
return; } }
|
||||||
|
|
||||||
#define CHECK_EQUAL(expected,actual)\
|
#define CHECK_EQUAL(expected,actual)\
|
||||||
{ if ((expected) == (actual)) return; result_.addFailure(Failure(name_, __FILE__, __LINE__, StringFrom(expected), StringFrom(actual))); }
|
{ if ((expected) == (actual)) return; result_.addFailure(Failure(name_, __FILE__, __LINE__, StringFrom(expected), StringFrom(actual))); }
|
||||||
|
|
||||||
|
|
|
@ -81,12 +81,7 @@ TEST ( NonlinearEquality, linearization_fail ) {
|
||||||
shared_nle nle(new NLE(key, value,vector_compare));
|
shared_nle nle(new NLE(key, value,vector_compare));
|
||||||
|
|
||||||
// check linearize to ensure that it fails for bad linearization points
|
// check linearize to ensure that it fails for bad linearization points
|
||||||
try {
|
CHECK_EXCEPTION(nle->linearize(bad_linearize), std::invalid_argument);
|
||||||
GaussianFactor::shared_ptr actualLF = nle->linearize(bad_linearize);
|
|
||||||
CHECK(false);
|
|
||||||
} catch (std::invalid_argument) {
|
|
||||||
CHECK(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ********************************************************************** */
|
/* ********************************************************************** */
|
||||||
|
@ -102,12 +97,7 @@ TEST ( NonlinearEquality, linearization_fail_pose ) {
|
||||||
shared_poseNLE nle(new PoseNLE(key, value));
|
shared_poseNLE nle(new PoseNLE(key, value));
|
||||||
|
|
||||||
// check linearize to ensure that it fails for bad linearization points
|
// check linearize to ensure that it fails for bad linearization points
|
||||||
try {
|
CHECK_EXCEPTION(nle->linearize(bad_linearize), std::invalid_argument);
|
||||||
GaussianFactor::shared_ptr actualLF = nle->linearize(bad_linearize);
|
|
||||||
CHECK(false);
|
|
||||||
} catch (std::invalid_argument) {
|
|
||||||
CHECK(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ********************************************************************** */
|
/* ********************************************************************** */
|
||||||
|
@ -123,12 +113,7 @@ TEST ( NonlinearEquality, linearization_fail_pose_origin ) {
|
||||||
shared_poseNLE nle(new PoseNLE(key, value));
|
shared_poseNLE nle(new PoseNLE(key, value));
|
||||||
|
|
||||||
// check linearize to ensure that it fails for bad linearization points
|
// check linearize to ensure that it fails for bad linearization points
|
||||||
try {
|
CHECK_EXCEPTION(nle->linearize(bad_linearize), std::invalid_argument);
|
||||||
GaussianFactor::shared_ptr actualLF = nle->linearize(bad_linearize);
|
|
||||||
CHECK(false);
|
|
||||||
} catch (std::invalid_argument) {
|
|
||||||
CHECK(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
|
@ -146,21 +146,8 @@ TEST(TupleConfig, at)
|
||||||
CHECK(assert_equal(l1, config1[PointKey(1)]));
|
CHECK(assert_equal(l1, config1[PointKey(1)]));
|
||||||
CHECK(assert_equal(l2, config1[PointKey(2)]));
|
CHECK(assert_equal(l2, config1[PointKey(2)]));
|
||||||
|
|
||||||
bool caught = false;
|
CHECK_EXCEPTION(config1[PoseKey(3)], std::invalid_argument);
|
||||||
try {
|
CHECK_EXCEPTION(config1[PointKey(3)], std::invalid_argument);
|
||||||
config1[PoseKey(3)];
|
|
||||||
} catch(invalid_argument e) {
|
|
||||||
caught = true;
|
|
||||||
}
|
|
||||||
CHECK(caught);
|
|
||||||
|
|
||||||
caught = false;
|
|
||||||
try {
|
|
||||||
config1[PointKey(3)];
|
|
||||||
} catch(invalid_argument e) {
|
|
||||||
caught = true;
|
|
||||||
}
|
|
||||||
CHECK(caught);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
|
@ -33,7 +33,8 @@ TEST( wrap, ArgumentList ) {
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
TEST( wrap, check_exception ) {
|
TEST( wrap, check_exception ) {
|
||||||
THROWS_EXCEPTION(Module("/home", "geometry",verbose));
|
THROWS_EXCEPTION(Module("/notarealpath", "geometry",verbose));
|
||||||
|
CHECK_EXCEPTION(Module("/alsonotarealpath", "geometry",verbose), CantOpenFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
Loading…
Reference in New Issue