From d3aabd9404dffd9f8eaaaba1d364a9c377f1853f Mon Sep 17 00:00:00 2001 From: Christoph Lehmann <christoph.lehmann@ufz.de> Date: Sun, 24 Jan 2016 11:48:01 +0100 Subject: [PATCH] [T] filename added to config tree --- Tests/AssemblerLib/TestSerialLinearSolver.cpp | 2 +- Tests/BaseLib/TestConfigTree.cpp | 51 +++++++++++++------ Tests/MathLib/TestLinearSolver.cpp | 14 ++--- 3 files changed, 43 insertions(+), 24 deletions(-) diff --git a/Tests/AssemblerLib/TestSerialLinearSolver.cpp b/Tests/AssemblerLib/TestSerialLinearSolver.cpp index ef64f0a9ad5..5d03fb32dc9 100644 --- a/Tests/AssemblerLib/TestSerialLinearSolver.cpp +++ b/Tests/AssemblerLib/TestSerialLinearSolver.cpp @@ -136,7 +136,7 @@ TEST(AssemblerLibSerialLinearSolver, Steady2DdiffusionQuadElem) t_root.put_child("eigen", t_solver); } t_root.put("lis", "-i cg -p none -tol 1e-16 -maxiter 1000"); - BaseLib::ConfigTreeNew conf(t_root); + BaseLib::ConfigTreeNew conf(t_root, ""); GlobalSetup::LinearSolver ls(*A, "solver_name", &conf); ls.solve(*rhs, *x); diff --git a/Tests/BaseLib/TestConfigTree.cpp b/Tests/BaseLib/TestConfigTree.cpp index 69dd1c88bb3..3b89a6f3e5d 100644 --- a/Tests/BaseLib/TestConfigTree.cpp +++ b/Tests/BaseLib/TestConfigTree.cpp @@ -37,9 +37,15 @@ public: BaseLib::ConfigTreeNew::Callback get_error_cb() { - return [this](std::string const& path, std::string const& message) + return [this](std::string const& filename, std::string const& path, + std::string const& message) { (void) path; (void) message; + + // check that filename is passed around properly, especially with + // move construction/assignment + EXPECT_EQ("FILENAME", filename); + DBUG("error <%s> : %s", path.c_str(), message.c_str()); _error = true; throw Exc(); // throw in order to stop normal execution @@ -49,9 +55,15 @@ public: BaseLib::ConfigTreeNew::Callback get_warning_cb() { - return [this](std::string const& path, std::string const& message) + return [this](std::string const& filename, std::string const& path, + std::string const& message) { (void) path; (void) message; + + // check that filename is passed around properly, especially with + // move construction/assignment + EXPECT_EQ("FILENAME", filename); + DBUG("warning <%s> : %s", path.c_str(), message.c_str()); _warning = true; }; @@ -78,6 +90,13 @@ readXml(const char xml[]) return ptree; } +BaseLib::ConfigTreeNew +makeConfigTree(boost::property_tree::ptree const& ptree, Callbacks& cbs) +{ + return BaseLib::ConfigTreeNew(ptree, "FILENAME", + cbs.get_error_cb(), cbs.get_warning_cb()); +} + TEST(BaseLibConfigTree, Empty) { @@ -85,7 +104,7 @@ TEST(BaseLibConfigTree, Empty) Callbacks cbs; { - BaseLib::ConfigTreeNew conf(ptree, cbs.get_error_cb(), cbs.get_warning_cb()); + auto const conf = makeConfigTree(ptree, cbs); (void) conf; } // ConfigTree destroyed here @@ -115,7 +134,7 @@ TEST(BaseLibConfigTree, Get) Callbacks cbs; { - BaseLib::ConfigTreeNew conf(ptree, cbs.get_error_cb(), cbs.get_warning_cb()); + auto const conf = makeConfigTree(ptree, cbs); EXPECT_EQ(5.6e-4, conf.getConfParam<double>("double")); // read certain types EXPECT_ERR_WARN(cbs, false, false); @@ -227,7 +246,7 @@ TEST(BaseLibConfigTree, IncompleteParse) Callbacks cbs; { - BaseLib::ConfigTreeNew conf(ptree, cbs.get_error_cb(), cbs.get_warning_cb()); + auto const conf = makeConfigTree(ptree, cbs); EXPECT_EQ(5.6, conf.getConfParam<double>("double")); EXPECT_ERR_WARN(cbs, false, false); @@ -268,7 +287,7 @@ TEST(BaseLibConfigTree, CheckRange) Callbacks cbs; { - BaseLib::ConfigTreeNew conf(ptree, cbs.get_error_cb(), cbs.get_warning_cb()); + auto const conf = makeConfigTree(ptree, cbs); { // check that std::distance can be computed twice in a row @@ -307,7 +326,7 @@ TEST(BaseLibConfigTree, GetSubtreeList) Callbacks cbs; { - BaseLib::ConfigTreeNew conf(ptree, cbs.get_error_cb(), cbs.get_warning_cb()); + auto const conf = makeConfigTree(ptree, cbs); int i = 0; for (auto ct : conf.getConfSubtreeList("val")) @@ -331,7 +350,7 @@ TEST(BaseLibConfigTree, GetValueList) Callbacks cbs; { - BaseLib::ConfigTreeNew conf(ptree, cbs.get_error_cb(), cbs.get_warning_cb()); + auto const conf = makeConfigTree(ptree, cbs); int n = 0; for (auto i : conf.getConfParamList<int>("int")) @@ -359,7 +378,7 @@ TEST(BaseLibConfigTree, NoConversion) Callbacks cbs; { - BaseLib::ConfigTreeNew conf(ptree, cbs.get_error_cb(), cbs.get_warning_cb()); + auto const conf = makeConfigTree(ptree, cbs); RUN_SAFE(conf.getConfParam<int>("int")); EXPECT_ERR_WARN(cbs, true, false); @@ -411,7 +430,7 @@ TEST(BaseLibConfigTree, BadKeynames) Callbacks cbs; { - BaseLib::ConfigTreeNew conf(ptree, cbs.get_error_cb(), cbs.get_warning_cb()); + auto const conf = makeConfigTree(ptree, cbs); for (auto tag : { "<", "Z", ".", "$", "0", "", "/", "_", "a__" }) { @@ -460,7 +479,7 @@ TEST(BaseLibConfigTree, StringLiterals) Callbacks cbs; { - BaseLib::ConfigTreeNew conf(ptree, cbs.get_error_cb(), cbs.get_warning_cb()); + auto const conf = makeConfigTree(ptree, cbs); EXPECT_EQ("test", conf.getConfParam<std::string>("s", "XX")); EXPECT_ERR_WARN(cbs, false, false); @@ -486,7 +505,7 @@ TEST(BaseLibConfigTree, MoveConstruct) Callbacks cbs; { - BaseLib::ConfigTreeNew conf(ptree, cbs.get_error_cb(), cbs.get_warning_cb()); + auto conf = makeConfigTree(ptree, cbs); EXPECT_EQ("test", conf.getConfParam<std::string>("s", "XX")); EXPECT_ERR_WARN(cbs, false, false); @@ -499,7 +518,7 @@ TEST(BaseLibConfigTree, MoveConstruct) // test that read status of data is transferred in move construction { - BaseLib::ConfigTreeNew u2(std::move(u)); + BaseLib::ConfigTreeNew const u2(std::move(u)); EXPECT_ERR_WARN(cbs, false, false); } EXPECT_ERR_WARN(cbs, false, false); @@ -530,7 +549,7 @@ TEST(BaseLibConfigTree, MoveAssign) Callbacks cbs; { - BaseLib::ConfigTreeNew conf(ptree, cbs.get_error_cb(), cbs.get_warning_cb()); + auto conf = makeConfigTree(ptree, cbs); EXPECT_EQ("test", conf.getConfParam<std::string>("s", "XX")); EXPECT_ERR_WARN(cbs, false, false); @@ -543,7 +562,7 @@ TEST(BaseLibConfigTree, MoveAssign) // test that read status of data is transferred in move assignment { - BaseLib::ConfigTreeNew u2(ptree, cbs.get_error_cb(), cbs.get_warning_cb()); + auto u2 = makeConfigTree(ptree, cbs); u2 = std::move(u); // Expect warning because u2 has not been traversed // entirely before assignment. @@ -553,7 +572,7 @@ TEST(BaseLibConfigTree, MoveAssign) // test that read status of children is transferred in move construction { - BaseLib::ConfigTreeNew conf2(ptree, cbs.get_error_cb(), cbs.get_warning_cb()); + auto conf2 = makeConfigTree(ptree, cbs); conf2 = std::move(conf); // Expect warning because conf2 has not been traversed // entirely before assignment. diff --git a/Tests/MathLib/TestLinearSolver.cpp b/Tests/MathLib/TestLinearSolver.cpp index 9de70b1e7d3..b6eb35a7bdb 100644 --- a/Tests/MathLib/TestLinearSolver.cpp +++ b/Tests/MathLib/TestLinearSolver.cpp @@ -204,7 +204,7 @@ void checkLinearSolverInterface(T_MATRIX& A, T_VECTOR& b, TEST(MathLib, CheckInterface_GaussAlgorithm) { boost::property_tree::ptree t_root; - BaseLib::ConfigTreeNew conf(t_root); + BaseLib::ConfigTreeNew conf(t_root, ""); using Example = Example1<std::size_t>; @@ -226,7 +226,7 @@ TEST(Math, CheckInterface_Eigen) t_solver.put("error_tolerance", 1e-15); t_solver.put("max_iteration_step", 1000); t_root.put_child("eigen", t_solver); - BaseLib::ConfigTreeNew conf(t_root); + BaseLib::ConfigTreeNew conf(t_root, ""); using IntType = MathLib::EigenMatrix::IndexType; @@ -243,7 +243,7 @@ TEST(Math, CheckInterface_EigenLis) boost::property_tree::ptree t_root; boost::property_tree::ptree t_solver; t_root.put("lis", "-i cg -p none -tol 1e-15 -maxiter 1000"); - BaseLib::ConfigTreeNew conf(t_root); + BaseLib::ConfigTreeNew conf(t_root, ""); using IntType = MathLib::LisMatrix::IndexType; @@ -260,7 +260,7 @@ TEST(Math, CheckInterface_Lis) boost::property_tree::ptree t_root; boost::property_tree::ptree t_solver; t_root.put("lis", "-i cg -p none -tol 1e-15 -maxiter 1000"); - BaseLib::ConfigTreeNew conf(t_root); + BaseLib::ConfigTreeNew conf(t_root, ""); using IntType = MathLib::LisMatrix::IndexType; @@ -294,7 +294,7 @@ TEST(MPITest_Math, CheckInterface_PETSc_Linear_Solver_basic) checkLinearSolverInterface<MathLib::PETScMatrix, MathLib::PETScVector, MathLib::PETScLinearSolver>( - A, b, "ptest1_", BaseLib::ConfigTreeNew(t_root)); + A, b, "ptest1_", BaseLib::ConfigTreeNew(t_root, "")); } TEST(MPITest_Math, CheckInterface_PETSc_Linear_Solver_chebyshev_sor) @@ -320,7 +320,7 @@ TEST(MPITest_Math, CheckInterface_PETSc_Linear_Solver_chebyshev_sor) checkLinearSolverInterface<MathLib::PETScMatrix, MathLib::PETScVector, MathLib::PETScLinearSolver>( - A, b, "ptest2_", BaseLib::ConfigTreeNew(t_root)); + A, b, "ptest2_", BaseLib::ConfigTreeNew(t_root, "")); } TEST(MPITest_Math, CheckInterface_PETSc_Linear_Solver_gmres_amg) @@ -348,7 +348,7 @@ TEST(MPITest_Math, CheckInterface_PETSc_Linear_Solver_gmres_amg) checkLinearSolverInterface<MathLib::PETScMatrix, MathLib::PETScVector, MathLib::PETScLinearSolver>( - A, b, "ptest3_", BaseLib::ConfigTreeNew(t_root)); + A, b, "ptest3_", BaseLib::ConfigTreeNew(t_root, "")); } #endif -- GitLab