Redesign cmake
Tune the makefile according to new principles, which adds a few bells
and whistles and for clarity.
Synopsis:
* The dependency on opm-common is completely gone. This is reflected in
travis and appveyor as well. No non-kitware cmake modules are used.
* Directories are flattened, quite a bit - source code is located in the
lib/ directory if it belongs to opm-parser, and external/ if third
party.
* The sibling build feature is implemented through cmake's
export(PACKAGE) rather than implicitly looking through source files.
* Targets explicitly set required public and private include
directories, compile options and definitions, which cmake will handle
and propagate
* opm-parser-config.cmake for downstream users is now provided.
* Dependencies are set up using targets. In the future, when cmake 3.x+
can be used, these should be either targets from newer Find modules,
or interface libraries.
* Fewer system specific assumptions are coded in, instead we assume
cmake or users set up system specific details.
* All module wide configuration and looking up libraries is handled in
the root makefile - all sub directories only set up libraries and
compile options for the module in question.
* Targets are defined and links handled transitively because cmake now
is told about them. ${module_LIBRARIES} variables are gone.
This is largely guided by the principles outlined in
https://rix0r.nl/blog/2015/08/13/cmake-guide/
Most source files are just moved - if they have some content change then
it's nothing more than include fixes or similar in order to make them
compile.
This commit is contained in:
126
tests/parser/StarTokenTests.cpp
Normal file
126
tests/parser/StarTokenTests.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
Copyright 2013 Statoil ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM 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.
|
||||
|
||||
OPM 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 OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define BOOST_TEST_MODULE ParserTests
|
||||
#include <stdexcept>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/StarToken.hpp>
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(NoStarThrows) {
|
||||
BOOST_REQUIRE_THROW(Opm::StarToken st("Hei...") , std::invalid_argument);
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(InvalidCountThrow) {
|
||||
BOOST_REQUIRE_THROW( Opm::StarToken st("X*") , std::invalid_argument);
|
||||
BOOST_REQUIRE_THROW( Opm::StarToken st("1.25*") , std::invalid_argument);
|
||||
BOOST_REQUIRE_THROW( Opm::StarToken st("-3*") , std::invalid_argument);
|
||||
BOOST_REQUIRE_THROW( Opm::StarToken st("0*") , std::invalid_argument);
|
||||
BOOST_REQUIRE_THROW( Opm::StarToken st("*123") , std::invalid_argument);
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(CountCorrect) {
|
||||
Opm::StarToken st1("*");
|
||||
Opm::StarToken st2("5*");
|
||||
Opm::StarToken st3("54*");
|
||||
BOOST_CHECK(st1.countString() == "");
|
||||
BOOST_CHECK(st2.countString() == "5");
|
||||
BOOST_CHECK(st3.countString() == "54");
|
||||
|
||||
BOOST_CHECK(st1.valueString() == "");
|
||||
BOOST_CHECK(st2.valueString() == "");
|
||||
BOOST_CHECK(st3.valueString() == "");
|
||||
|
||||
BOOST_CHECK(!st1.hasValue());
|
||||
BOOST_CHECK(!st2.hasValue());
|
||||
BOOST_CHECK(!st3.hasValue());
|
||||
|
||||
BOOST_REQUIRE_EQUAL(1U , st1.count());
|
||||
BOOST_REQUIRE_EQUAL(5U , st2.count());
|
||||
BOOST_REQUIRE_EQUAL(54U , st3.count());
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(NoValueGetValueThrow) {
|
||||
Opm::StarToken st1("*");
|
||||
Opm::StarToken st2("5*");
|
||||
BOOST_CHECK_EQUAL( false , st1.hasValue());
|
||||
BOOST_CHECK_EQUAL( false , st2.hasValue());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(StarNoCountThrows) {
|
||||
BOOST_CHECK_THROW( Opm::StarToken st1("*10") , std::invalid_argument);
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(CorrectValueString) {
|
||||
Opm::StarToken st1("1*10.09");
|
||||
Opm::StarToken st2("5*20.13");
|
||||
Opm::StarToken st3("1*'123'");
|
||||
Opm::StarToken st4("1*123*456");
|
||||
BOOST_CHECK_EQUAL( true , st1.hasValue());
|
||||
BOOST_CHECK_EQUAL( true , st2.hasValue());
|
||||
BOOST_CHECK_EQUAL( true , st3.hasValue());
|
||||
BOOST_CHECK_EQUAL( true , st4.hasValue());
|
||||
|
||||
BOOST_CHECK_EQUAL( "10.09" , st1.valueString());
|
||||
BOOST_CHECK_EQUAL( "20.13" , st2.valueString());
|
||||
BOOST_CHECK_EQUAL( "'123'" , st3.valueString());
|
||||
BOOST_CHECK_EQUAL( "123*456" , st4.valueString());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( ContainsStar_WithStar_ReturnsTrue ) {
|
||||
std::string countString, valueString;
|
||||
BOOST_CHECK_EQUAL( true , Opm::isStarToken("*", countString, valueString) );
|
||||
BOOST_CHECK_EQUAL( true , Opm::isStarToken("*1", countString, valueString) );
|
||||
BOOST_CHECK_EQUAL( true , Opm::isStarToken("1*", countString, valueString) );
|
||||
BOOST_CHECK_EQUAL( true , Opm::isStarToken("1*2", countString, valueString) );
|
||||
|
||||
BOOST_CHECK_EQUAL( false , Opm::isStarToken("12", countString, valueString) );
|
||||
BOOST_CHECK_EQUAL( false , Opm::isStarToken("'12*34'", countString, valueString) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( readValueToken_basic_validity_tests ) {
|
||||
BOOST_CHECK_THROW( Opm::readValueToken<int>( std::string( "3.3" ) ), std::invalid_argument );
|
||||
BOOST_CHECK_EQUAL( 3, Opm::readValueToken<int>( std::string( "3" ) ) );
|
||||
BOOST_CHECK_EQUAL( 3, Opm::readValueToken<int>( std::string( "+3" ) ) );
|
||||
BOOST_CHECK_EQUAL( -3, Opm::readValueToken<int>( std::string( "-3" ) ) );
|
||||
BOOST_CHECK_THROW( Opm::readValueToken<double>( std::string( "truls" ) ), std::invalid_argument );
|
||||
BOOST_CHECK_EQUAL( 0, Opm::readValueToken<double>( std::string( "0" ) ) );
|
||||
BOOST_CHECK_EQUAL( 0, Opm::readValueToken<double>( std::string( "0.0" ) ) );
|
||||
BOOST_CHECK_EQUAL( 0, Opm::readValueToken<double>( std::string( "+0.0" ) ) );
|
||||
BOOST_CHECK_EQUAL( 0, Opm::readValueToken<double>( std::string( "-0.0" ) ) );
|
||||
BOOST_CHECK_EQUAL( 0, Opm::readValueToken<double>( std::string( ".0" ) ) );
|
||||
BOOST_CHECK_THROW( Opm::readValueToken<double>( std::string( "1.0.0" ) ), std::invalid_argument );
|
||||
BOOST_CHECK_THROW( Opm::readValueToken<double>( std::string( "1g0" ) ), std::invalid_argument );
|
||||
BOOST_CHECK_THROW( Opm::readValueToken<double>( std::string( "1.23h" ) ), std::invalid_argument );
|
||||
BOOST_CHECK_THROW( Opm::readValueToken<double>( std::string( "+1.23h" ) ), std::invalid_argument );
|
||||
BOOST_CHECK_THROW( Opm::readValueToken<double>( std::string( "-1.23h" ) ), std::invalid_argument );
|
||||
BOOST_CHECK_EQUAL( 3.3, Opm::readValueToken<double>( std::string( "3.3" ) ) );
|
||||
BOOST_CHECK_CLOSE( 3.3, Opm::readValueToken<double>( std::string( "3.3e0" ) ), 1e-6 );
|
||||
BOOST_CHECK_CLOSE( 3.3, Opm::readValueToken<double>( std::string( "3.3d0" ) ), 1e-6 );
|
||||
BOOST_CHECK_CLOSE( 3.3, Opm::readValueToken<double>( std::string( "3.3E0" ) ), 1e-6 );
|
||||
BOOST_CHECK_CLOSE( 3.3, Opm::readValueToken<double>( std::string( "3.3D0" ) ), 1e-6 );
|
||||
BOOST_CHECK_EQUAL( "OLGA", Opm::readValueToken<std::string>( std::string( "OLGA" ) ) );
|
||||
BOOST_CHECK_EQUAL( "OLGA", Opm::readValueToken<std::string>( std::string( "'OLGA'" ) ) );
|
||||
BOOST_CHECK_EQUAL( "123*456", Opm::readValueToken<std::string>( std::string( "123*456" ) ) );
|
||||
BOOST_CHECK_EQUAL( "123*456", Opm::readValueToken<std::string>( std::string( "'123*456'" ) ) );
|
||||
}
|
||||
Reference in New Issue
Block a user