Now also testing xml input.
This commit is contained in:
8
dune/common/param/test/extratestdata.xml
Normal file
8
dune/common/param/test/extratestdata.xml
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version = '1.0' encoding = 'ISO-8859-1'?>
|
||||
<ParameterGroup>
|
||||
<ParameterGroup name="group">
|
||||
<ParameterGroup name="subgroup">
|
||||
<Parameter type="int" name="anotheritem" value="4"/>
|
||||
</ParameterGroup>
|
||||
</ParameterGroup>
|
||||
</ParameterGroup>
|
||||
@@ -42,6 +42,7 @@
|
||||
|
||||
#include "../ParameterGroup.hpp"
|
||||
#include <cstddef>
|
||||
#include <sstream>
|
||||
|
||||
using namespace Dune;
|
||||
|
||||
@@ -59,6 +60,40 @@ BOOST_AUTO_TEST_CASE(commandline_syntax_init)
|
||||
const std::size_t argc = sizeof(argv)/sizeof(argv[0]);
|
||||
parameter::ParameterGroup p(argc, argv);
|
||||
BOOST_CHECK(p.get<std::string>("topitem") == "somestring");
|
||||
std::ostringstream os;
|
||||
p.writeParamToStream(os);
|
||||
std::string correct_answer = "/group/anotheritem=2\n"
|
||||
"/group/item=overridingstring\n"
|
||||
"/group/subgroup/anotheritem=4\n"
|
||||
"/group/subgroup/item=3\n"
|
||||
"/slashtopitem=anotherstring\n"
|
||||
"/topitem=somestring\n";
|
||||
BOOST_CHECK(os.str() == correct_answer);
|
||||
|
||||
// Tests that only run in debug mode.
|
||||
#ifndef NDEBUG
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(xml_syntax_init)
|
||||
{
|
||||
typedef const char* cp;
|
||||
cp argv[] = { "program_command",
|
||||
"testdata.xml",
|
||||
"/group/item=overridingstring" };
|
||||
const std::size_t argc = sizeof(argv)/sizeof(argv[0]);
|
||||
parameter::ParameterGroup p(argc, argv);
|
||||
BOOST_CHECK(p.get<std::string>("topitem") == "somestring");
|
||||
std::ostringstream os;
|
||||
p.writeParamToStream(os);
|
||||
std::string correct_answer = "/group/anotheritem=2\n"
|
||||
"/group/item=overridingstring\n"
|
||||
"/group/subgroup/anotheritem=4\n"
|
||||
"/group/subgroup/item=3\n"
|
||||
"/slashtopitem=anotherstring\n"
|
||||
"/topitem=somestring\n";
|
||||
BOOST_CHECK(os.str() == correct_answer);
|
||||
|
||||
// Tests that only run in debug mode.
|
||||
#ifndef NDEBUG
|
||||
|
||||
13
dune/common/param/test/testdata.xml
Normal file
13
dune/common/param/test/testdata.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version = '1.0' encoding = 'ISO-8859-1'?>
|
||||
<ParameterGroup>
|
||||
<MergeWithFile value="extratestdata.xml"/>
|
||||
<Parameter type="string" name="topitem" value="somestring"/>
|
||||
<Parameter type="string" name="slashtopitem" value="anotherstring"/>
|
||||
<ParameterGroup name="group">
|
||||
<Parameter type="int" name="item" value="1"/>
|
||||
<Parameter type="int" name="anotheritem" value="2"/>
|
||||
<ParameterGroup name="subgroup">
|
||||
<Parameter type="int" name="item" value="3"/>
|
||||
</ParameterGroup>
|
||||
</ParameterGroup>
|
||||
</ParameterGroup>
|
||||
Reference in New Issue
Block a user