Now also testing xml input.

This commit is contained in:
Atgeirr Flø Rasmussen
2011-12-07 14:14:01 +01:00
parent ed0da5d7c5
commit 3be4d52b95
3 changed files with 56 additions and 0 deletions

View 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>

View File

@@ -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

View 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>