opm-core/tests/param_test.cpp
Bård Skaflestad be1ca06fa3 Use dynamic Boost.Test mode only if supported
Use result of OPM_DYNLINK_BOOST_TEST to determine whether or not to
#define the Boost symbol BOOST_TEST_DYN_LINK .

While here, replace an unprintable character with the proper UTF-8
encoding in a comment.
2012-06-27 16:51:37 +02:00

106 lines
3.2 KiB
C++

//===========================================================================
//
// File: param_test.cpp
//
// Created: Sun Dec 13 20:08:36 2009
//
// Author(s): Atgeirr F Rasmussen <atgeirr@sintef.no>
// Bård Skaflestad <bard.skaflestad@sintef.no>
//
// $Date$
//
// $Revision$
//
//===========================================================================
/*
Copyright 2009, 2010 SINTEF ICT, Applied Mathematics.
Copyright 2009, 2010 Statoil ASA.
This file is part of The Open Reservoir Simulator Project (OpenRS).
OpenRS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenRS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenRS. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#if HAVE_DYNAMIC_BOOST_TEST
#define BOOST_TEST_DYN_LINK
#endif
#define NVERBOSE // to suppress our messages when throwing
#define BOOST_TEST_MODULE ParameterTest
#include <boost/test/unit_test.hpp>
#include <opm/core/utility/parameters/ParameterGroup.hpp>
#include <cstddef>
#include <sstream>
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);
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
#endif
}