Make test argc/argv data mimic POSIX correct data.

This commit is contained in:
Atgeirr Flø Rasmussen 2015-04-14 15:58:37 +02:00
parent 37904a3e74
commit d4e7ad3ea1

View File

@ -47,22 +47,24 @@
#include <opm/core/utility/parameters/ParameterGroup.hpp>
#include <cstddef>
#include <sstream>
#include <vector>
using namespace Opm;
BOOST_AUTO_TEST_CASE(commandline_syntax_init)
{
typedef const char* cp;
cp argv[] = { "program_command",
"topitem=somestring",
"/slashtopitem=anotherstring",
"/group/item=1",
"/group/anotheritem=2",
"/group/subgroup/item=3",
"/group/subgroup/anotheritem=4",
"/group/item=overridingstring" };
const std::size_t argc = sizeof(argv)/sizeof(argv[0]);
parameter::ParameterGroup p(argc, argv);
std::vector<cp> argv = { "program_command",
"topitem=somestring",
"/slashtopitem=anotherstring",
"/group/item=1",
"/group/anotheritem=2",
"/group/subgroup/item=3",
"/group/subgroup/anotheritem=4",
"/group/item=overridingstring",
0 };
const std::size_t argc = argv.size() - 1;
parameter::ParameterGroup p(argc, argv.data());
BOOST_CHECK(p.get<std::string>("topitem") == "somestring");
std::ostringstream os;
p.writeParamToStream(os);
@ -84,12 +86,13 @@ BOOST_AUTO_TEST_CASE(commandline_syntax_init)
BOOST_AUTO_TEST_CASE(xml_syntax_init)
{
typedef const char* cp;
cp argv[] = { "program_command",
"testdata.xml",
"/group/item=overridingstring",
"unhandledargument" };
const std::size_t argc = sizeof(argv)/sizeof(argv[0]);
parameter::ParameterGroup p(argc, argv, false);
std::vector<cp> argv = { "program_command",
"testdata.xml",
"/group/item=overridingstring",
"unhandledargument",
0};
const std::size_t argc = argv.size() - 1;
parameter::ParameterGroup p(argc, argv.data(), false);
BOOST_CHECK(p.get<std::string>("topitem") == "somestring");
std::ostringstream os;
p.writeParamToStream(os);
@ -111,10 +114,11 @@ BOOST_AUTO_TEST_CASE(xml_syntax_init)
BOOST_AUTO_TEST_CASE(failing_strict_xml_syntax_init)
{
typedef const char* cp;
cp argv[] = { "program_command",
"testdata.xml",
"/group/item=overridingstring",
"unhandledargument" };
const std::size_t argc = sizeof(argv)/sizeof(argv[0]);
BOOST_CHECK_THROW(parameter::ParameterGroup p(argc, argv), std::runtime_error);
std::vector<cp> argv = { "program_command",
"testdata.xml",
"/group/item=overridingstring",
"unhandledargument",
0 };
const std::size_t argc = argv.size() - 1;
BOOST_CHECK_THROW(parameter::ParameterGroup p(argc, argv.data()), std::runtime_error);
}