Files
opm-common/tests/parser/KeywordLoaderTests.cpp
Jørgen Kvalsvik e884b0664c 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.
2017-06-01 15:29:23 +02:00

110 lines
3.8 KiB
C++

/*
Copyright 2015 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/>.
*/
#include <stdexcept>
#include <iostream>
#include <cstdio>
#define BOOST_TEST_MODULE InputKeywordTests
#include <boost/filesystem.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <opm/parser/eclipse/Generator/KeywordLoader.hpp>
#include <opm/parser/eclipse/Parser/ParserKeyword.hpp>
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
inline std::string prefix() {
return boost::unit_test::framework::master_test_suite().argv[1];
}
BOOST_AUTO_TEST_CASE(EmptyKeywordLoader) {
Opm::KeywordLoader loader(false);
BOOST_CHECK_EQUAL( false , loader.hasKeyword("NO"));
BOOST_CHECK_EQUAL( 0U , loader.size() );
BOOST_CHECK_THROW( loader.getKeyword("NO") , std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(LoadKeyword) {
Opm::KeywordLoader loader(false);
BOOST_CHECK_THROW( loader.loadKeyword("does/not/exists") , std::invalid_argument );
BOOST_CHECK_THROW( loader.loadKeyword(prefix() + "invalid.json") , std::invalid_argument);
BOOST_CHECK_THROW( loader.loadKeyword(prefix() + "PORO-invalid") , std::invalid_argument);
loader.loadKeyword(prefix() + "PORO.json");
loader.loadKeyword(prefix() + "PORO.json");
BOOST_CHECK_EQUAL( true , loader.hasKeyword("PORO"));
BOOST_CHECK_EQUAL( 1U , loader.size() );
loader.getKeyword("PORO");
}
BOOST_AUTO_TEST_CASE(LoadKeywordDirectory) {
Opm::KeywordLoader loader(false);
BOOST_CHECK_THROW( loader.loadKeywordDirectory("does/not/exists") , std::invalid_argument );
BOOST_CHECK_THROW( loader.loadKeywordDirectory(prefix() + "invalid.json") , std::invalid_argument);
BOOST_CHECK_EQUAL( 4 , loader.loadKeywordDirectory( prefix() + "loader/001_ECLIPSE100"));
BOOST_CHECK( loader.hasKeyword("ADDREG") );
BOOST_CHECK( loader.hasKeyword("ACTNUM") );
BOOST_CHECK( loader.hasKeyword("BOX") );
BOOST_CHECK( loader.hasKeyword("BLOCK_PROBE") );
{
auto kw = loader.getKeyword("ADDREG");
auto record = kw->getRecord(0);
BOOST_CHECK( !record.hasItem("REGION_NUMBER") );
}
}
BOOST_AUTO_TEST_CASE(DirectorySort) {
BOOST_CHECK_THROW( Opm::KeywordLoader::sortSubdirectories( prefix() + "loader/ZCORN") , std::invalid_argument );
std::vector<std::string> dir_list = Opm::KeywordLoader::sortSubdirectories( prefix() + "loader");
namespace fs = boost::filesystem;
BOOST_CHECK_EQUAL( 2U , dir_list.size());
BOOST_CHECK_EQUAL( fs::path( dir_list[0] ), fs::path( prefix() + "loader/001_ECLIPSE100" ) );
BOOST_CHECK_EQUAL( fs::path( dir_list[1] ), fs::path( prefix() + "loader/002_ECLIPSE300" ) );
}
BOOST_AUTO_TEST_CASE(BigLoad) {
Opm::KeywordLoader loader(false);
BOOST_CHECK_THROW( loader.loadMultipleKeywordDirectories("does/not/exists") , std::invalid_argument );
BOOST_CHECK_THROW( loader.loadMultipleKeywordDirectories(prefix() + "invalid.json") , std::invalid_argument);
loader.loadMultipleKeywordDirectories(prefix() + "loader");
BOOST_CHECK( loader.hasKeyword("EQUIL"));
{
auto kw = loader.getKeyword("ADDREG");
auto record = kw->getRecord(0);
BOOST_CHECK( record.hasItem("REGION_NUMBER"));
}
}