diff --git a/dune/xt/common/test/common.hh b/dune/xt/common/test/common.hh index 904e7f586f8898b372aea4592695a04c6033c020..85e1f580b8b21b46662788ebacbac9fd4fa0f62d 100644 --- a/dune/xt/common/test/common.hh +++ b/dune/xt/common/test/common.hh @@ -76,6 +76,20 @@ void busywait(const size_t ms); namespace Dune { namespace XT { +namespace Common { +namespace Test { + + +/** + * \sa DXTC_TEST_CONFIG_GET + * \sa DXTC_TEST_CONFIG_SET + * \sa DXTC_TEST_CONFIG_SUB + */ +std::string get_unique_test_name(); + + +} // namespace Test +} // namespace Common namespace Test { namespace internal { @@ -193,4 +207,37 @@ ostream& operator<<(ostream& out, const map<F, S>& results) } // namespace std + +/** + * \brief Can be used to access the configuration assosicated with the currently running test + * \sa get_unique_test_name + */ +template <typename T> +static auto DXTC_TEST_CONFIG_GET(const std::string& key, T def) -> decltype(DXTC_CONFIG.get(key, def)) +{ + return DXTC_CONFIG.get(Dune::XT::Common::Test::get_unique_test_name() + "." + key, def); +} + +/** + * \brief Can be used to access the configuration assosicated with the currently running test + * \sa get_unique_test_name + */ +template <typename T> +static void DXTC_TEST_CONFIG_SET(const std::string& key, T val) +{ + return DXTC_CONFIG.set(Dune::XT::Common::Test::get_unique_test_name() + "." + key, val, /*overwrite=*/true); +} + +/** + * \brief Can be used to access the configuration assosicated with the currently running test + * \sa get_unique_test_name + */ +static Dune::XT::Common::Configuration DXTC_TEST_CONFIG_SUB(const std::string& sub_key) +{ + const auto key = Dune::XT::Common::Test::get_unique_test_name() + "." + sub_key; + EXPECT_TRUE(DXTC_CONFIG.has_sub(key)); + return DXTC_CONFIG.sub(key); +} + + #endif // DUNE_XT_COMMON_TEST_MAIN_COMMON_HH