Replace EXPECT/ASSERT_DEATH with EXPECT_DEATH_IF_SUPPORTED.
This allows us to remove all the WIN32/MSVC ifdefs in the
various tests.
http://code.google.com/p/ceres-solver/issues/detail?id=55
Change-Id: Ida053e44ea84b6915758318403f3db05325f1226
diff --git a/internal/ceres/corrector_test.cc b/internal/ceres/corrector_test.cc
index b2ee9ab..55e7d6b 100644
--- a/internal/ceres/corrector_test.cc
+++ b/internal/ceres/corrector_test.cc
@@ -44,19 +44,15 @@
// If rho[1] is zero, the Corrector constructor should crash.
TEST(Corrector, ZeroGradientDeathTest) {
const double kRho[] = {0.0, 0.0, 0.0};
-#ifndef _WIN32
- ASSERT_DEATH({Corrector c(1.0, kRho);},
+ EXPECT_DEATH_IF_SUPPORTED({Corrector c(1.0, kRho);},
".*");
-#endif // _WIN32
}
// If rho[1] is negative, the Corrector constructor should crash.
TEST(Corrector, NegativeGradientDeathTest) {
const double kRho[] = {0.0, -0.1, 0.0};
-#ifndef _WIN32
- ASSERT_DEATH({Corrector c(1.0, kRho);},
+ EXPECT_DEATH_IF_SUPPORTED({Corrector c(1.0, kRho);},
".*");
-#endif // _WIN32
}
TEST(Corrector, ScalarCorrection) {
diff --git a/internal/ceres/graph_test.cc b/internal/ceres/graph_test.cc
index d4ee22d..85b80bf 100644
--- a/internal/ceres/graph_test.cc
+++ b/internal/ceres/graph_test.cc
@@ -83,22 +83,16 @@
EXPECT_EQ(graph.EdgeWeight(1, 0), 0.5);
}
-// Death tests don't work on Windows.
-// TODO(keir): Figure out why this test doesn't work on Windows.
-#ifndef _WIN32
-
TEST(Graph, DieOnNonExistentVertex) {
Graph<int> graph;
graph.AddVertex(0, 1.0);
graph.AddVertex(1, 2.0);
graph.AddEdge(0, 1, 0.5);
- EXPECT_DEATH(graph.VertexWeight(2), "key not found");
- EXPECT_DEATH(graph.Neighbors(2), "key not found");
+ EXPECT_DEATH_IF_SUPPORTED(graph.VertexWeight(2), "key not found");
+ EXPECT_DEATH_IF_SUPPORTED(graph.Neighbors(2), "key not found");
}
-#endif // _WIN32
-
TEST(Graph, NonExistentEdge) {
Graph<int> graph;
graph.AddVertex(0, 1.0);
diff --git a/internal/ceres/local_parameterization_test.cc b/internal/ceres/local_parameterization_test.cc
index 55c765b..9b775b4 100644
--- a/internal/ceres/local_parameterization_test.cc
+++ b/internal/ceres/local_parameterization_test.cc
@@ -62,30 +62,28 @@
}
}
-// Death tests are not working on Windows yet.
-// TODO(keir): Figure out how to enable these.
-#ifndef _WIN32
-
TEST(SubsetParameterization, DeathTests) {
vector<int> constant_parameters;
- EXPECT_DEATH(SubsetParameterization parameterization(1, constant_parameters),
- "at least");
+ EXPECT_DEATH_IF_SUPPORTED(
+ SubsetParameterization parameterization(1, constant_parameters),
+ "at least");
constant_parameters.push_back(0);
- EXPECT_DEATH(SubsetParameterization parameterization(1, constant_parameters),
- "Number of parameters");
+ EXPECT_DEATH_IF_SUPPORTED(
+ SubsetParameterization parameterization(1, constant_parameters),
+ "Number of parameters");
constant_parameters.push_back(1);
- EXPECT_DEATH(SubsetParameterization parameterization(2, constant_parameters),
- "Number of parameters");
+ EXPECT_DEATH_IF_SUPPORTED(
+ SubsetParameterization parameterization(2, constant_parameters),
+ "Number of parameters");
constant_parameters.push_back(1);
- EXPECT_DEATH(SubsetParameterization parameterization(2, constant_parameters),
- "duplicates");
+ EXPECT_DEATH_IF_SUPPORTED(
+ SubsetParameterization parameterization(2, constant_parameters),
+ "duplicates");
}
-#endif // _WIN32
-
TEST(SubsetParameterization, NormalFunctionTest) {
double x[4] = {1.0, 2.0, 3.0, 4.0};
for (int i = 0; i < 4; ++i) {
diff --git a/internal/ceres/parameter_block_test.cc b/internal/ceres/parameter_block_test.cc
index b1d69b0..35998dc 100644
--- a/internal/ceres/parameter_block_test.cc
+++ b/internal/ceres/parameter_block_test.cc
@@ -36,8 +36,6 @@
namespace ceres {
namespace internal {
-// TODO(keir): Figure out how to enable the death tests on Windows.
-
TEST(ParameterBlock, SetLocalParameterization) {
double x[3] = { 1.0, 2.0, 3.0 };
ParameterBlock parameter_block(x, 3);
@@ -48,13 +46,12 @@
// Can't set the parameterization if the sizes don't match.
SubsetParameterization subset_wrong_size(4, indices);
-#ifndef _WIN32
- ASSERT_DEATH(parameter_block.SetParameterization(&subset_wrong_size),
- "global");
+ EXPECT_DEATH_IF_SUPPORTED(
+ parameter_block.SetParameterization(&subset_wrong_size), "global");
// Can't set parameterization to NULL from NULL.
- ASSERT_DEATH(parameter_block.SetParameterization(NULL), "NULL");
-#endif // _WIN32
+ EXPECT_DEATH_IF_SUPPORTED
+ (parameter_block.SetParameterization(NULL), "NULL");
// Now set the parameterization.
SubsetParameterization subset(3, indices);
@@ -63,15 +60,13 @@
// Re-setting the parameterization to the same value is supported.
parameter_block.SetParameterization(&subset);
-#ifndef _WIN32
// Can't set parameterization to NULL from another parameterization.
- ASSERT_DEATH(parameter_block.SetParameterization(NULL), "NULL");
+ EXPECT_DEATH_IF_SUPPORTED(parameter_block.SetParameterization(NULL), "NULL");
// Can't set the parameterization more than once.
SubsetParameterization subset_different(3, indices);
- ASSERT_DEATH(parameter_block.SetParameterization(&subset_different),
- "re-set");
-#endif // _WIN32
+ EXPECT_DEATH_IF_SUPPORTED
+ (parameter_block.SetParameterization(&subset_different), "re-set");
// Ensure the local parameterization jacobian result is correctly computed.
ConstMatrixRef local_parameterization_jacobian(
diff --git a/internal/ceres/problem_test.cc b/internal/ceres/problem_test.cc
index b8dbc74..9b20dca 100644
--- a/internal/ceres/problem_test.cc
+++ b/internal/ceres/problem_test.cc
@@ -106,9 +106,6 @@
}
};
-// TODO(keir): Figure out how to enable death tests on Windows.
-#ifndef _WIN32
-
TEST(Problem, AddResidualWithNullCostFunctionDies) {
double x[3], y[4], z[5];
@@ -117,8 +114,8 @@
problem.AddParameterBlock(y, 4);
problem.AddParameterBlock(z, 5);
- ASSERT_DEATH(problem.AddResidualBlock(NULL, NULL, x),
- "'cost_function' Must be non NULL");
+ EXPECT_DEATH_IF_SUPPORTED(problem.AddResidualBlock(NULL, NULL, x),
+ "'cost_function' Must be non NULL");
}
TEST(Problem, AddResidualWithIncorrectNumberOfParameterBlocksDies) {
@@ -130,7 +127,7 @@
problem.AddParameterBlock(z, 5);
// UnaryCostFunction takes only one parameter, but two are passed.
- ASSERT_DEATH(
+ EXPECT_DEATH_IF_SUPPORTED(
problem.AddResidualBlock(new UnaryCostFunction(2, 3), NULL, x, y),
"parameter_blocks.size()");
}
@@ -140,21 +137,23 @@
Problem problem;
problem.AddResidualBlock(new UnaryCostFunction(2, 3), NULL, x);
- ASSERT_DEATH(problem.AddResidualBlock(
- new UnaryCostFunction(2, 4 /* 4 != 3 */), NULL, x),
- "different block sizes");
+ EXPECT_DEATH_IF_SUPPORTED(problem.AddResidualBlock(
+ new UnaryCostFunction(
+ 2, 4 /* 4 != 3 */), NULL, x),
+ "different block sizes");
}
TEST(Problem, AddResidualWithDuplicateParametersDies) {
double x[3], z[5];
Problem problem;
- ASSERT_DEATH(problem.AddResidualBlock(
- new BinaryCostFunction(2, 3, 3), NULL, x, x),
- "Duplicate parameter blocks");
- ASSERT_DEATH(problem.AddResidualBlock(
- new TernaryCostFunction(1, 5, 3, 5), NULL, z, x, z),
- "Duplicate parameter blocks");
+ EXPECT_DEATH_IF_SUPPORTED(problem.AddResidualBlock(
+ new BinaryCostFunction(2, 3, 3), NULL, x, x),
+ "Duplicate parameter blocks");
+ EXPECT_DEATH_IF_SUPPORTED(problem.AddResidualBlock(
+ new TernaryCostFunction(1, 5, 3, 5),
+ NULL, z, x, z),
+ "Duplicate parameter blocks");
}
TEST(Problem, AddResidualWithIncorrectSizesOfParameterBlockDies) {
@@ -167,13 +166,11 @@
// The cost function expects the size of the second parameter, z, to be 4
// instead of 5 as declared above. This is fatal.
- ASSERT_DEATH(problem.AddResidualBlock(
+ EXPECT_DEATH_IF_SUPPORTED(problem.AddResidualBlock(
new BinaryCostFunction(2, 3, 4), NULL, x, z),
"different block sizes");
}
-#endif // _WIN32
-
TEST(Problem, AddResidualAddsDuplicatedParametersOnlyOnce) {
double x[3], y[4], z[5];
@@ -187,8 +184,6 @@
EXPECT_EQ(12, problem.NumParameters());
}
-#ifndef _WIN32
-
TEST(Problem, AddParameterWithDifferentSizesOnTheSameVariableDies) {
double x[3], y[4];
@@ -196,7 +191,8 @@
problem.AddParameterBlock(x, 3);
problem.AddParameterBlock(y, 4);
- ASSERT_DEATH(problem.AddParameterBlock(x, 4), "different block sizes");
+ EXPECT_DEATH_IF_SUPPORTED(problem.AddParameterBlock(x, 4),
+ "different block sizes");
}
static double *IntToPtr(int i) {
@@ -218,12 +214,18 @@
problem.AddParameterBlock(IntToPtr(5), 5); // x
problem.AddParameterBlock(IntToPtr(13), 3); // y
- ASSERT_DEATH(problem.AddParameterBlock(IntToPtr( 4), 2), "Aliasing detected");
- ASSERT_DEATH(problem.AddParameterBlock(IntToPtr( 4), 3), "Aliasing detected");
- ASSERT_DEATH(problem.AddParameterBlock(IntToPtr( 4), 9), "Aliasing detected");
- ASSERT_DEATH(problem.AddParameterBlock(IntToPtr( 8), 3), "Aliasing detected");
- ASSERT_DEATH(problem.AddParameterBlock(IntToPtr(12), 2), "Aliasing detected");
- ASSERT_DEATH(problem.AddParameterBlock(IntToPtr(14), 3), "Aliasing detected");
+ EXPECT_DEATH_IF_SUPPORTED(problem.AddParameterBlock(IntToPtr( 4), 2),
+ "Aliasing detected");
+ EXPECT_DEATH_IF_SUPPORTED(problem.AddParameterBlock(IntToPtr( 4), 3),
+ "Aliasing detected");
+ EXPECT_DEATH_IF_SUPPORTED(problem.AddParameterBlock(IntToPtr( 4), 9),
+ "Aliasing detected");
+ EXPECT_DEATH_IF_SUPPORTED(problem.AddParameterBlock(IntToPtr( 8), 3),
+ "Aliasing detected");
+ EXPECT_DEATH_IF_SUPPORTED(problem.AddParameterBlock(IntToPtr(12), 2),
+ "Aliasing detected");
+ EXPECT_DEATH_IF_SUPPORTED(problem.AddParameterBlock(IntToPtr(14), 3),
+ "Aliasing detected");
// These ones should work.
problem.AddParameterBlock(IntToPtr( 2), 3);
@@ -233,8 +235,6 @@
ASSERT_EQ(5, problem.NumParameterBlocks());
}
-#endif // _WIN32
-
TEST(Problem, AddParameterIgnoresDuplicateCalls) {
double x[3], y[4];
diff --git a/internal/ceres/triplet_sparse_matrix_test.cc b/internal/ceres/triplet_sparse_matrix_test.cc
index 6bdd2bd..d16682e 100644
--- a/internal/ceres/triplet_sparse_matrix_test.cc
+++ b/internal/ceres/triplet_sparse_matrix_test.cc
@@ -67,9 +67,7 @@
ASSERT_TRUE(m.AllTripletsWithinBounds());
// We should never be able resize and lose data
-#ifndef _MSC_VER
- ASSERT_DEATH(m.Reserve(1), "Reallocation will cause data loss");
-#endif
+ EXPECT_DEATH_IF_SUPPORTED(m.Reserve(1), "Reallocation will cause data loss");
// We should be able to resize while preserving data
m.Reserve(50);