Files
opm-common/tests/parser/integration/IncludeTest.cpp

192 lines
5.7 KiB
C++
Raw Normal View History

2013-09-02 10:08:37 +02:00
/*
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 ParserIntegrationTests
#include <boost/test/unit_test.hpp>
#include <boost/test/test_tools.hpp>
#include <boost/filesystem.hpp>
#include <ostream>
#include <fstream>
2013-09-02 10:08:37 +02:00
#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/parser/eclipse/Parser/Parser.hpp>
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
2013-09-02 10:08:37 +02:00
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
using namespace Opm;
using namespace boost::filesystem;
static void
2014-01-24 13:16:37 +01:00
createDeckWithInclude(path& datafile, std::string addEndKeyword)
2013-09-02 10:08:37 +02:00
{
path tmpdir = temp_directory_path();
path root = tmpdir / unique_path("%%%%-%%%%");
2013-09-02 10:08:37 +02:00
path absoluteInclude = root / "absolute.include";
path includePath1 = root / "include";
path includePath2 = root / "include2";
path pathIncludeFile = "path.file";
2013-09-02 10:08:37 +02:00
create_directories(root);
create_directories(includePath1);
create_directories(includePath2);
2013-09-02 10:08:37 +02:00
{
datafile = root / "TEST.DATA";
std::ofstream of(datafile.string().c_str());
of << "PATHS" << std::endl;
of << "PATH1 '" << includePath1.string() << "' /" << std::endl;
of << "PATH2 '" << includePath2.string() << "' /" << std::endl;
of << "/" << std::endl;
2013-09-02 10:08:37 +02:00
of << "INCLUDE" << std::endl;
of << " \'relative.include\' /" << std::endl;
of << std::endl;
of << "INCLUDE" << std::endl;
of << " \'" << absoluteInclude.string() << "\' /" << std::endl;
of << std::endl;
of << "INCLUDE" << std::endl;
of << " \'include/nested.include\' /" << std::endl;
2014-02-21 12:56:20 +01:00
of << std::endl;
of << std::endl;
of << "INCLUDE" << std::endl;
of << " \'$PATH1/" << pathIncludeFile.string() << "\' /" << std::endl;
of << std::endl;
2014-02-21 12:56:20 +01:00
of << "INCLUDE" << std::endl;
of << " \'$PATH2/" << pathIncludeFile.string() << "\' /" << std::endl;
2014-02-21 12:56:20 +01:00
2013-09-02 10:08:37 +02:00
of.close();
}
2014-01-24 13:16:37 +01:00
2013-09-02 10:08:37 +02:00
{
2014-01-24 13:16:37 +01:00
path relativeInclude = root / "relative.include";
std::ofstream of(relativeInclude.string().c_str());
2013-09-02 10:08:37 +02:00
2014-01-24 13:16:37 +01:00
of << "START" << std::endl;
of << " 10 'FEB' 2012 /" << std::endl;
2013-09-02 10:08:37 +02:00
of.close();
}
{
2014-01-24 13:16:37 +01:00
std::ofstream of(absoluteInclude.string().c_str());
2013-09-02 10:08:37 +02:00
2014-01-24 13:16:37 +01:00
if (addEndKeyword.length() > 0) {
of << addEndKeyword << std::endl;
}
2014-01-24 13:16:37 +01:00
of << "DIMENS" << std::endl;
of << " 10 20 30 /" << std::endl;
2013-09-02 10:08:37 +02:00
of.close();
}
{
path nestedInclude = includePath1 / "nested.include";
path gridInclude = includePath1 / "grid.include";
2013-09-02 10:08:37 +02:00
std::ofstream of(nestedInclude.string().c_str());
of << "INCLUDE" << std::endl;
of << " \'$PATH1/grid.include\' /" << std::endl;
2013-09-02 10:08:37 +02:00
of.close();
std::ofstream of2(gridInclude.string().c_str());
of2 << "GRIDUNIT" << std::endl;
of2 << "/" << std::endl;
of2.close();
}
2014-02-21 12:56:20 +01:00
{
path fullPathToPathIncludeFile1 = includePath1 / pathIncludeFile;
std::ofstream of1(fullPathToPathIncludeFile1.string().c_str());
of1 << "TITLE" << std::endl;
of1 << "This is the title /" << std::endl;
of1.close();
path fullPathToPathIncludeFile2 = includePath2 / pathIncludeFile;
std::ofstream of2(fullPathToPathIncludeFile2.string().c_str());
of2 << "BOX" << std::endl;
of2 << " 1 2 3 4 5 6 /" << std::endl;
of2.close();
2014-02-21 12:56:20 +01:00
}
std::cout << datafile << std::endl;
2013-09-02 10:08:37 +02:00
}
BOOST_AUTO_TEST_CASE(parse_fileWithWWCTKeyword_deckReturned) {
path datafile;
Parser parser;
2014-01-24 13:16:37 +01:00
createDeckWithInclude (datafile, "");
auto deck = parser.parseFile(datafile.string(), ParseContext());
2013-09-02 10:08:37 +02:00
BOOST_CHECK( deck.hasKeyword("START"));
BOOST_CHECK( deck.hasKeyword("DIMENS"));
BOOST_CHECK( deck.hasKeyword("GRIDUNIT"));
2013-09-02 10:08:37 +02:00
}
BOOST_AUTO_TEST_CASE(parse_fileWithENDINCKeyword_deckReturned) {
path datafile;
Parser parser;
2014-01-24 13:16:37 +01:00
createDeckWithInclude (datafile, "ENDINC");
auto deck = parser.parseFile(datafile.string(), ParseContext());
BOOST_CHECK( deck.hasKeyword("START"));
BOOST_CHECK( !deck.hasKeyword("DIMENS"));
BOOST_CHECK( deck.hasKeyword("GRIDUNIT"));
}
2014-01-24 13:16:37 +01:00
BOOST_AUTO_TEST_CASE(parse_fileWithENDKeyword_deckReturned) {
path datafile;
Parser parser;
2014-01-24 13:16:37 +01:00
createDeckWithInclude (datafile, "END");
auto deck = parser.parseFile(datafile.string(), ParseContext());
2014-01-24 13:16:37 +01:00
BOOST_CHECK( deck.hasKeyword("START"));
BOOST_CHECK( !deck.hasKeyword("DIMENS"));
BOOST_CHECK( !deck.hasKeyword("GRIDUNIT"));
2014-01-24 13:16:37 +01:00
}
2014-02-21 12:56:20 +01:00
BOOST_AUTO_TEST_CASE(parse_fileWithPathsKeyword_IncludeExtendsPath) {
path datafile;
Parser parser;
2014-02-21 12:56:20 +01:00
createDeckWithInclude (datafile, "");
auto deck = parser.parseFile(datafile.string(), ParseContext());
2014-02-21 12:56:20 +01:00
BOOST_CHECK( deck.hasKeyword("TITLE"));
BOOST_CHECK( deck.hasKeyword("BOX"));
2014-02-21 12:56:20 +01:00
}