Skip to content
Snippets Groups Projects
Commit ca29068c authored by Jö Fahlke's avatar Jö Fahlke
Browse files

[parametertreetest][fs1527] Check for the error from fs1572.

parent e258c6dd
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <ostream> #include <ostream>
#include <sstream> #include <sstream>
#include <dune/common/exceptions.hh>
#include <dune/common/parametertree.hh> #include <dune/common/parametertree.hh>
#include <dune/common/parametertreeparser.hh> #include <dune/common/parametertreeparser.hh>
...@@ -24,6 +25,23 @@ ...@@ -24,6 +25,23 @@
} \ } \
} while(false) } while(false)
// Check that the given expression throws the given exception
#define check_throw(expr, except) \
do { \
try { \
expr; \
std::cerr << __FILE__ << ":" << __LINE__ << ": " << #expr \
<< " should throw " << #except << std::endl; \
std::abort(); \
} \
catch(except) {} \
catch(...) { \
std::cerr << __FILE__ << ":" << __LINE__ << ": " << #expr \
<< " should throw " << #except << std::endl; \
std::abort(); \
} \
} while(false)
template<class P> template<class P>
void testparam(const P & p) void testparam(const P & p)
{ {
...@@ -198,6 +216,20 @@ void testOptionsParser() ...@@ -198,6 +216,20 @@ void testOptionsParser()
} }
} }
void testFS1527()
{
{ // Check that junk at the end is not accepted (int)
Dune::ParameterTree ptree;
check_throw(ptree["setting"] = "0.5"; ptree.get("setting", 0),
Dune::RangeError);
}
{ // Check that junk at the end is not accepted (double)
Dune::ParameterTree ptree;
check_throw(ptree["setting"] = "0.5 junk"; ptree.get("setting", 0.0),
Dune::RangeError);
}
}
int main() int main()
{ {
try { try {
...@@ -227,6 +259,9 @@ int main() ...@@ -227,6 +259,9 @@ int main()
// check the command line parser // check the command line parser
testOptionsParser(); testOptionsParser();
// check for specific bugs
testFS1527();
} }
catch (Dune::Exception & e) catch (Dune::Exception & e)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment