From 91da563f15a356898c021d4fe4a2943a1d22147f Mon Sep 17 00:00:00 2001 From: Wenqing Wang <wenqing.wang@ufz.de> Date: Thu, 28 May 2020 16:07:27 +0200 Subject: [PATCH] [Tests] Set createTestProperty as a common function --- Tests/MaterialLib/TestMPL.cpp | 21 ++++++++++++++++ Tests/MaterialLib/TestMPL.h | 24 ++++++++++++++++++- ...pillaryPressureRegularizedVanGenuchten.cpp | 19 +-------------- 3 files changed, 45 insertions(+), 19 deletions(-) diff --git a/Tests/MaterialLib/TestMPL.cpp b/Tests/MaterialLib/TestMPL.cpp index f2c5e204283..ff4b43c31c8 100644 --- a/Tests/MaterialLib/TestMPL.cpp +++ b/Tests/MaterialLib/TestMPL.cpp @@ -32,3 +32,24 @@ std::unique_ptr<MPL::Medium> createTestMaterial(std::string const& xml) return MPL::createMedium(config, parameters, nullptr, curves); } + +namespace Tests +{ +std::unique_ptr<MaterialPropertyLib::Property> createTestProperty( + const char xml[], + std::function<std::unique_ptr<MaterialPropertyLib::Property>( + BaseLib::ConfigTree const& config)> + createProperty) +{ + auto const ptree = readXml(xml); + BaseLib::ConfigTree conf(ptree, "", BaseLib::ConfigTree::onerror, + BaseLib::ConfigTree::onwarning); + auto const& sub_config = conf.getConfigSubtree("property"); + // Parsing the property name: + auto const property_name = + sub_config.getConfigParameter<std::string>("name"); + + return createProperty(sub_config); +} + +} // namespace Tests diff --git a/Tests/MaterialLib/TestMPL.h b/Tests/MaterialLib/TestMPL.h index 9916a31b0e8..6f5e9584de6 100644 --- a/Tests/MaterialLib/TestMPL.h +++ b/Tests/MaterialLib/TestMPL.h @@ -13,9 +13,31 @@ #pragma once -#include "Tests/TestTools.h" +#include <functional> +#include <memory> #include "MaterialLib/MPL/Medium.h" + namespace MPL = MaterialPropertyLib; +namespace BaseLib +{ +class ConfigTree; +} + +namespace MaterialPropertyLib +{ +class Property; +} + std::unique_ptr<MPL::Medium> createTestMaterial(std::string const& xml); + +namespace Tests +{ +std::unique_ptr<MaterialPropertyLib::Property> createTestProperty( + const char xml[], + std::function<std::unique_ptr<MaterialPropertyLib::Property>( + BaseLib::ConfigTree const& config)> + createProperty); + +} // namespace Tests diff --git a/Tests/MaterialLib/TestMPLCapillaryPressureRegularizedVanGenuchten.cpp b/Tests/MaterialLib/TestMPLCapillaryPressureRegularizedVanGenuchten.cpp index 7561cc4e026..730a2a7fa1d 100644 --- a/Tests/MaterialLib/TestMPLCapillaryPressureRegularizedVanGenuchten.cpp +++ b/Tests/MaterialLib/TestMPLCapillaryPressureRegularizedVanGenuchten.cpp @@ -27,23 +27,6 @@ namespace MPL = MaterialPropertyLib; -std::unique_ptr<MaterialPropertyLib::Property> createTestProperty( - const char xml[], - std::function<std::unique_ptr<MaterialPropertyLib::Property>( - BaseLib::ConfigTree const& config)> - createProperty) -{ - auto const ptree = readXml(xml); - BaseLib::ConfigTree conf(ptree, "", BaseLib::ConfigTree::onerror, - BaseLib::ConfigTree::onwarning); - auto const& sub_config = conf.getConfigSubtree("property"); - // Parsing the property name: - auto const property_name = - sub_config.getConfigParameter<std::string>("name"); - - return createProperty(sub_config); -} - TEST(MaterialPropertyLib, CapillaryPressureRegularizedVanGenuchten) { const char xml_pc_S[] = @@ -55,7 +38,7 @@ TEST(MaterialPropertyLib, CapillaryPressureRegularizedVanGenuchten) " <exponent>0.6</exponent>" " <p_b>1.e+4</p_b>" "</property>"; - auto const capillary_pressure_property_ptr = createTestProperty( + auto const capillary_pressure_property_ptr = Tests::createTestProperty( xml_pc_S, MPL::createCapillaryPressureRegularizedVanGenuchten); MPL::Property const& capillary_pressure_property = -- GitLab