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; } \
|
||||
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)\
|
||||
{ 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));
|
||||
|
||||
// check linearize to ensure that it fails for bad linearization points
|
||||
try {
|
||||
GaussianFactor::shared_ptr actualLF = nle->linearize(bad_linearize);
|
||||
CHECK(false);
|
||||
} catch (std::invalid_argument) {
|
||||
CHECK(true);
|
||||
}
|
||||
CHECK_EXCEPTION(nle->linearize(bad_linearize), std::invalid_argument);
|
||||
}
|
||||
|
||||
/* ********************************************************************** */
|
||||
|
@ -102,12 +97,7 @@ TEST ( NonlinearEquality, linearization_fail_pose ) {
|
|||
shared_poseNLE nle(new PoseNLE(key, value));
|
||||
|
||||
// check linearize to ensure that it fails for bad linearization points
|
||||
try {
|
||||
GaussianFactor::shared_ptr actualLF = nle->linearize(bad_linearize);
|
||||
CHECK(false);
|
||||
} catch (std::invalid_argument) {
|
||||
CHECK(true);
|
||||
}
|
||||
CHECK_EXCEPTION(nle->linearize(bad_linearize), std::invalid_argument);
|
||||
}
|
||||
|
||||
/* ********************************************************************** */
|
||||
|
@ -123,12 +113,7 @@ TEST ( NonlinearEquality, linearization_fail_pose_origin ) {
|
|||
shared_poseNLE nle(new PoseNLE(key, value));
|
||||
|
||||
// check linearize to ensure that it fails for bad linearization points
|
||||
try {
|
||||
GaussianFactor::shared_ptr actualLF = nle->linearize(bad_linearize);
|
||||
CHECK(false);
|
||||
} catch (std::invalid_argument) {
|
||||
CHECK(true);
|
||||
}
|
||||
CHECK_EXCEPTION(nle->linearize(bad_linearize), std::invalid_argument);
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
|
|
|
@ -146,21 +146,8 @@ TEST(TupleConfig, at)
|
|||
CHECK(assert_equal(l1, config1[PointKey(1)]));
|
||||
CHECK(assert_equal(l2, config1[PointKey(2)]));
|
||||
|
||||
bool caught = false;
|
||||
try {
|
||||
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);
|
||||
CHECK_EXCEPTION(config1[PoseKey(3)], std::invalid_argument);
|
||||
CHECK_EXCEPTION(config1[PointKey(3)], std::invalid_argument);
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
|
|
|
@ -33,7 +33,8 @@ TEST( wrap, ArgumentList ) {
|
|||
|
||||
/* ************************************************************************* */
|
||||
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