Consolidate path handling for test data files.
Added CERES_TEST_SRCDIR_POSTFIX macro.
Added TestFileAbsolutePath function.
Change-Id: I223b74af027bfb775447e062edab897395b21514
diff --git a/internal/ceres/schur_eliminator_test.cc b/internal/ceres/schur_eliminator_test.cc
index 7fedb96..c14901f 100644
--- a/internal/ceres/schur_eliminator_test.cc
+++ b/internal/ceres/schur_eliminator_test.cc
@@ -35,21 +35,18 @@
#include "ceres/block_sparse_matrix.h"
#include "ceres/casts.h"
#include "ceres/detect_structure.h"
-#include "ceres/file.h"
#include "ceres/internal/eigen.h"
#include "ceres/internal/scoped_ptr.h"
#include "ceres/linear_least_squares_problems.h"
+#include "ceres/test_util.h"
#include "ceres/triplet_sparse_matrix.h"
#include "ceres/types.h"
-#include "gflags/gflags.h"
#include "glog/logging.h"
#include "gtest/gtest.h"
// TODO(sameeragarwal): Reduce the size of these tests and redo the
// parameterization to be more efficient.
-DECLARE_string(test_srcdir);
-
namespace ceres {
namespace internal {
@@ -219,9 +216,7 @@
#ifndef CERES_DONT_HAVE_PROTOCOL_BUFFERS
TEST_F(SchurEliminatorTest, BlockProblem) {
- const string input_file =
- JoinPath(FLAGS_test_srcdir,
- "problem-6-1384-000.lsqp"); // NOLINT
+ const string input_file = TestFileAbsolutePath("problem-6-1384-000.lsqp");
SetUpFromFilename(input_file);
ComputeReferenceSolution(VectorRef(D.get(), A->num_cols()));
diff --git a/internal/ceres/system_test.cc b/internal/ceres/system_test.cc
index b771268..7cdff21 100644
--- a/internal/ceres/system_test.cc
+++ b/internal/ceres/system_test.cc
@@ -44,7 +44,6 @@
#include <string>
#include "ceres/autodiff_cost_function.h"
-#include "ceres/file.h"
#include "ceres/problem.h"
#include "ceres/rotation.h"
#include "ceres/solver.h"
@@ -55,8 +54,6 @@
#include "glog/logging.h"
#include "gtest/gtest.h"
-DECLARE_string(test_srcdir);
-
namespace ceres {
namespace internal {
@@ -311,8 +308,7 @@
class BundleAdjustmentProblem {
public:
BundleAdjustmentProblem() {
- const string input_file = JoinPath(FLAGS_test_srcdir,
- "problem-16-22106-pre.txt");
+ const string input_file = TestFileAbsolutePath("problem-16-22106-pre.txt");
ReadData(input_file);
BuildProblem();
}
diff --git a/internal/ceres/test_util.cc b/internal/ceres/test_util.cc
index e98052d..8a1def7 100644
--- a/internal/ceres/test_util.cc
+++ b/internal/ceres/test_util.cc
@@ -31,10 +31,20 @@
// Utility functions useful for testing.
#include <cmath>
+#include "ceres/file.h"
#include "ceres/stringprintf.h"
#include "glog/logging.h"
#include "gtest/gtest.h"
+DECLARE_string(test_srcdir);
+
+// This macro is used to inject additional path information specific
+// to the build system.
+
+#ifndef CERES_TEST_SRCDIR_SUFFIX
+#define CERES_TEST_SRCDIR_SUFFIX ""
+#endif
+
namespace ceres {
namespace internal {
@@ -106,5 +116,11 @@
}
}
+string TestFileAbsolutePath(const string& filename) {
+ return JoinPath(FLAGS_test_srcdir + CERES_TEST_SRCDIR_SUFFIX,
+ filename);
+}
+
+
} // namespace internal
} // namespace ceres
diff --git a/internal/ceres/test_util.h b/internal/ceres/test_util.h
index 93dc343..4c530de 100644
--- a/internal/ceres/test_util.h
+++ b/internal/ceres/test_util.h
@@ -28,6 +28,9 @@
//
// Author: keir@google.com (Keir Mierle)
+#include <string>
+#include "ceres/internal/port.h"
+
#ifndef CERES_INTERNAL_TEST_UTIL_H_
#define CERES_INTERNAL_TEST_UTIL_H_
@@ -58,6 +61,10 @@
const double* q,
double tolerance);
+// Construct a fully qualified path for the test file depending on the
+// local build/testing environment.
+string TestFileAbsolutePath(const string& filename);
+
} // namespace internal
} // namespace ceres
diff --git a/internal/ceres/visibility_based_preconditioner_test.cc b/internal/ceres/visibility_based_preconditioner_test.cc
index 5c4a6e8..bf01acb 100644
--- a/internal/ceres/visibility_based_preconditioner_test.cc
+++ b/internal/ceres/visibility_based_preconditioner_test.cc
@@ -45,11 +45,10 @@
#include "ceres/schur_eliminator.h"
#include "ceres/stringprintf.h"
#include "ceres/types.h"
+#include "ceres/test_util.h"
#include "glog/logging.h"
#include "gtest/gtest.h"
-DECLARE_string(test_srcdir);
-
namespace ceres {
namespace internal {
@@ -65,9 +64,7 @@
protected:
void SetUp() {
- string input_file =
- JoinPath(FLAGS_test_srcdir,
- "problem-6-1384-000.lsqp"); // NOLINT
+ string input_file = TestFileAbsolutePath("problem-6-1384-000.lsqp");
scoped_ptr<LinearLeastSquaresProblem> problem(
CHECK_NOTNULL(CreateLinearLeastSquaresProblemFromFile(input_file)));