2013-05-27 14:27:22 +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>
|
|
|
|
|
|
2013-05-30 10:11:12 +02:00
|
|
|
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
|
|
|
|
|
2013-05-27 14:27:22 +02:00
|
|
|
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
2015-07-24 15:38:22 +02:00
|
|
|
#include <opm/parser/eclipse/Parser/ParseMode.hpp>
|
2013-05-27 14:27:22 +02:00
|
|
|
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
|
|
|
|
|
#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>
|
2013-06-20 13:56:11 +02:00
|
|
|
#include <opm/parser/eclipse/Parser/ParserStringItem.hpp>
|
|
|
|
|
|
2013-05-27 14:27:22 +02:00
|
|
|
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
|
|
|
|
|
|
|
|
|
using namespace Opm;
|
|
|
|
|
|
2015-04-23 11:31:10 +02:00
|
|
|
std::shared_ptr<ParserKeyword> createFixedSized(const std::string& kw , size_t size) {
|
|
|
|
|
std::shared_ptr<ParserKeyword> pkw = std::make_shared<ParserKeyword>(kw);
|
|
|
|
|
pkw->setFixedSize( size );
|
|
|
|
|
return pkw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<ParserKeyword> createDynamicSized(const std::string& kw) {
|
|
|
|
|
std::shared_ptr<ParserKeyword> pkw = std::make_shared<ParserKeyword>(kw);
|
|
|
|
|
pkw->setSizeType(SLASH_TERMINATED);
|
|
|
|
|
return pkw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-05-08 16:26:14 +02:00
|
|
|
static ParserPtr createWWCTParser() {
|
2015-04-23 11:31:10 +02:00
|
|
|
ParserKeywordPtr parserKeyword = createDynamicSized("WWCT");
|
2013-06-20 13:56:11 +02:00
|
|
|
{
|
2015-02-26 11:47:14 +01:00
|
|
|
std::shared_ptr<ParserRecord> record = std::make_shared<ParserRecord>();
|
|
|
|
|
record->addItem( ParserStringItemConstPtr(new ParserStringItem("WELL", ALL)) );
|
|
|
|
|
parserKeyword->addRecord( record );
|
2013-06-20 13:56:11 +02:00
|
|
|
}
|
2015-04-23 11:31:10 +02:00
|
|
|
ParserKeywordPtr summaryKeyword = createFixedSized("SUMMARY" , (size_t) 0);
|
2013-06-20 13:56:11 +02:00
|
|
|
|
|
|
|
|
ParserPtr parser(new Parser());
|
2014-06-27 16:42:54 +02:00
|
|
|
parser->addParserKeyword(parserKeyword);
|
|
|
|
|
parser->addParserKeyword(summaryKeyword);
|
2013-06-20 13:56:11 +02:00
|
|
|
return parser;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(parse_fileWithWWCTKeyword_deckReturned) {
|
|
|
|
|
boost::filesystem::path singleKeywordFile("testdata/integration_tests/wwct.data");
|
|
|
|
|
ParserPtr parser = createWWCTParser();
|
2014-09-02 17:26:07 +02:00
|
|
|
BOOST_CHECK( parser->isRecognizedKeyword("WWCT"));
|
|
|
|
|
BOOST_CHECK( parser->isRecognizedKeyword("SUMMARY"));
|
2015-07-24 15:38:22 +02:00
|
|
|
BOOST_CHECK_NO_THROW( parser->parseFile(singleKeywordFile.string(), ParseMode()) );
|
2013-06-20 13:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
2014-05-20 11:44:27 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(parse_stringWithWWCTKeyword_deckReturned) {
|
|
|
|
|
const char *wwctString =
|
|
|
|
|
"SUMMARY\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"-- Kommentar\n"
|
|
|
|
|
"WWCT\n"
|
|
|
|
|
" 'WELL-1' 'WELL-2' / -- Ehne mehne muh\n"
|
|
|
|
|
"/\n";
|
|
|
|
|
ParserPtr parser = createWWCTParser();
|
2014-09-02 17:26:07 +02:00
|
|
|
BOOST_CHECK( parser->isRecognizedKeyword("WWCT"));
|
|
|
|
|
BOOST_CHECK( parser->isRecognizedKeyword("SUMMARY"));
|
2015-07-24 15:38:22 +02:00
|
|
|
BOOST_CHECK_NO_THROW(DeckPtr deck = parser->parseString(wwctString, ParseMode()));
|
2014-05-20 11:44:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(parse_streamWithWWCTKeyword_deckReturned) {
|
|
|
|
|
const char *wwctString =
|
|
|
|
|
"SUMMARY\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"-- Kommentar\n"
|
|
|
|
|
"WWCT\n"
|
|
|
|
|
" 'WELL-1' 'WELL-2' / -- Rumpelstilzchen\n"
|
|
|
|
|
"/\n";
|
2014-05-20 13:27:37 +02:00
|
|
|
std::shared_ptr<std::istream> wwctStream(new std::istringstream(wwctString));
|
2014-05-20 11:44:27 +02:00
|
|
|
ParserPtr parser = createWWCTParser();
|
2014-09-02 17:26:07 +02:00
|
|
|
BOOST_CHECK( parser->isRecognizedKeyword("WWCT"));
|
|
|
|
|
BOOST_CHECK( parser->isRecognizedKeyword("SUMMARY"));
|
2015-07-24 15:38:22 +02:00
|
|
|
BOOST_CHECK_NO_THROW(DeckPtr deck = parser->parseStream(wwctStream, ParseMode()));
|
2014-05-20 11:44:27 +02:00
|
|
|
}
|
|
|
|
|
|
2013-06-20 13:56:11 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(parse_fileWithWWCTKeyword_deckHasWWCT) {
|
|
|
|
|
boost::filesystem::path singleKeywordFile("testdata/integration_tests/wwct.data");
|
|
|
|
|
ParserPtr parser = createWWCTParser();
|
2015-07-24 15:38:22 +02:00
|
|
|
DeckPtr deck = parser->parseFile(singleKeywordFile.string(), ParseMode());
|
2013-08-21 07:41:06 +02:00
|
|
|
BOOST_CHECK(deck->hasKeyword("SUMMARY"));
|
2013-06-20 13:56:11 +02:00
|
|
|
BOOST_CHECK(deck->hasKeyword("WWCT"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(parse_fileWithWWCTKeyword_dataIsCorrect) {
|
|
|
|
|
boost::filesystem::path singleKeywordFile("testdata/integration_tests/wwct.data");
|
|
|
|
|
ParserPtr parser = createWWCTParser();
|
2015-07-24 15:38:22 +02:00
|
|
|
DeckPtr deck = parser->parseFile(singleKeywordFile.string(), ParseMode());
|
2013-08-01 10:57:25 +02:00
|
|
|
BOOST_CHECK_EQUAL("WELL-1", deck->getKeyword("WWCT" , 0)->getRecord(0)->getItem(0)->getString(0));
|
|
|
|
|
BOOST_CHECK_EQUAL("WELL-2", deck->getKeyword("WWCT" , 0)->getRecord(0)->getItem(0)->getString(1));
|
2013-06-20 13:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
2014-07-01 16:57:07 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(parser_internal_name_vs_deck_name) {
|
|
|
|
|
ParserPtr parser(new Opm::Parser());
|
|
|
|
|
|
|
|
|
|
// the WELL_PROBE keyword is present by default
|
|
|
|
|
BOOST_CHECK(parser->hasInternalKeyword("WELL_PROBE"));
|
|
|
|
|
|
|
|
|
|
// the NONEXISTING_PROBE keyword is _not_ present by default
|
|
|
|
|
BOOST_CHECK(!parser->hasInternalKeyword("NONEXISTING_PROBE"));
|
|
|
|
|
|
|
|
|
|
// internal names cannot appear in the deck if the deck names and/or deck regular
|
|
|
|
|
// match expressions are given
|
2014-09-02 17:26:07 +02:00
|
|
|
BOOST_CHECK(!parser->isRecognizedKeyword("WELL_PROBE"));
|
2014-07-01 16:57:07 +02:00
|
|
|
|
|
|
|
|
// an existing deck name
|
2014-09-02 17:26:07 +02:00
|
|
|
BOOST_CHECK(parser->isRecognizedKeyword("WWPR"));
|
2014-07-01 16:57:07 +02:00
|
|
|
|
|
|
|
|
// a non-existing deck name
|
2014-09-02 17:26:07 +02:00
|
|
|
BOOST_CHECK(!parser->isRecognizedKeyword("WWPRFOO"));
|
2014-07-01 16:57:07 +02:00
|
|
|
|
|
|
|
|
// user defined quantity. (regex needs to be used.)
|
2014-09-02 17:26:07 +02:00
|
|
|
BOOST_CHECK(parser->isRecognizedKeyword("WUFOO"));
|
2014-07-01 16:57:07 +02:00
|
|
|
}
|
|
|
|
|
|
2014-05-08 16:26:14 +02:00
|
|
|
static ParserPtr createBPRParser() {
|
2015-04-23 11:31:10 +02:00
|
|
|
ParserKeywordPtr parserKeyword = createDynamicSized("BPR");
|
2013-05-30 10:11:12 +02:00
|
|
|
{
|
2015-02-26 11:47:14 +01:00
|
|
|
std::shared_ptr<ParserRecord> bprRecord = std::make_shared<ParserRecord>();
|
2013-05-30 10:11:12 +02:00
|
|
|
bprRecord->addItem(ParserIntItemConstPtr(new ParserIntItem("I", SINGLE)));
|
|
|
|
|
bprRecord->addItem(ParserIntItemConstPtr(new ParserIntItem("J", SINGLE)));
|
|
|
|
|
bprRecord->addItem(ParserIntItemConstPtr(new ParserIntItem("K", SINGLE)));
|
2015-02-26 11:47:14 +01:00
|
|
|
parserKeyword->addRecord( bprRecord );
|
2013-05-30 10:11:12 +02:00
|
|
|
}
|
2015-04-23 11:31:10 +02:00
|
|
|
ParserKeywordPtr summaryKeyword = createFixedSized("SUMMARY" , (size_t) 0);
|
2013-05-30 10:11:12 +02:00
|
|
|
ParserPtr parser(new Parser());
|
2014-06-27 16:42:54 +02:00
|
|
|
parser->addParserKeyword(parserKeyword);
|
|
|
|
|
parser->addParserKeyword(summaryKeyword);
|
2013-05-30 10:11:12 +02:00
|
|
|
return parser;
|
|
|
|
|
}
|
2013-05-27 14:27:22 +02:00
|
|
|
|
2013-05-30 10:11:12 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(parse_fileWithBPRKeyword_deckReturned) {
|
2013-05-27 14:27:22 +02:00
|
|
|
boost::filesystem::path singleKeywordFile("testdata/integration_tests/bpr.data");
|
2013-05-30 10:11:12 +02:00
|
|
|
ParserPtr parser = createBPRParser();
|
|
|
|
|
|
2015-07-24 15:38:22 +02:00
|
|
|
BOOST_CHECK_NO_THROW(parser->parseFile(singleKeywordFile.string(), ParseMode()));
|
2013-05-30 10:11:12 +02:00
|
|
|
}
|
2013-05-27 14:27:22 +02:00
|
|
|
|
2013-05-30 10:11:12 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(parse_fileWithBPRKeyword_DeckhasBRP) {
|
|
|
|
|
boost::filesystem::path singleKeywordFile("testdata/integration_tests/bpr.data");
|
2013-06-04 14:32:30 +02:00
|
|
|
|
2013-05-30 10:11:12 +02:00
|
|
|
ParserPtr parser = createBPRParser();
|
2015-07-24 15:38:22 +02:00
|
|
|
DeckPtr deck = parser->parseFile(singleKeywordFile.string(), ParseMode());
|
2013-05-30 10:11:12 +02:00
|
|
|
|
2013-06-04 14:32:30 +02:00
|
|
|
BOOST_CHECK_EQUAL(true, deck->hasKeyword("BPR"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(parse_fileWithBPRKeyword_dataiscorrect) {
|
|
|
|
|
boost::filesystem::path singleKeywordFile("testdata/integration_tests/bpr.data");
|
|
|
|
|
|
|
|
|
|
ParserPtr parser = createBPRParser();
|
2015-07-24 15:38:22 +02:00
|
|
|
DeckPtr deck = parser->parseFile(singleKeywordFile.string(), ParseMode());
|
2013-06-04 14:32:30 +02:00
|
|
|
|
2013-08-01 10:57:25 +02:00
|
|
|
DeckKeywordConstPtr keyword = deck->getKeyword("BPR" , 0);
|
2013-06-04 14:32:30 +02:00
|
|
|
BOOST_CHECK_EQUAL(2U, keyword->size());
|
|
|
|
|
|
|
|
|
|
DeckRecordConstPtr record1 = keyword->getRecord(0);
|
|
|
|
|
BOOST_CHECK_EQUAL(3U, record1->size());
|
|
|
|
|
|
2013-08-01 09:52:49 +02:00
|
|
|
DeckItemConstPtr I1 = record1->getItem(0);
|
2013-06-04 14:32:30 +02:00
|
|
|
BOOST_CHECK_EQUAL(1, I1->getInt(0));
|
2013-08-01 09:52:49 +02:00
|
|
|
I1 = record1->getItem("I");
|
2013-06-04 14:32:30 +02:00
|
|
|
BOOST_CHECK_EQUAL(1, I1->getInt(0));
|
|
|
|
|
|
2013-08-01 09:52:49 +02:00
|
|
|
DeckItemConstPtr J1 = record1->getItem(1);
|
2013-06-04 14:32:30 +02:00
|
|
|
BOOST_CHECK_EQUAL(2, J1->getInt(0));
|
2013-08-01 09:52:49 +02:00
|
|
|
J1 = record1->getItem("J");
|
2013-06-04 14:32:30 +02:00
|
|
|
BOOST_CHECK_EQUAL(2, J1->getInt(0));
|
|
|
|
|
|
2013-08-01 09:52:49 +02:00
|
|
|
DeckItemConstPtr K1 = record1->getItem(2);
|
2013-06-04 14:32:30 +02:00
|
|
|
BOOST_CHECK_EQUAL(3, K1->getInt(0));
|
2013-08-01 09:52:49 +02:00
|
|
|
K1 = record1->getItem("K");
|
2013-06-04 14:32:30 +02:00
|
|
|
BOOST_CHECK_EQUAL(3, K1->getInt(0));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DeckRecordConstPtr record2 = keyword->getRecord(0);
|
|
|
|
|
BOOST_CHECK_EQUAL(3U, record2->size());
|
|
|
|
|
|
2013-08-01 09:52:49 +02:00
|
|
|
I1 = record2->getItem(0);
|
2013-06-04 14:32:30 +02:00
|
|
|
BOOST_CHECK_EQUAL(1, I1->getInt(0));
|
2013-08-01 09:52:49 +02:00
|
|
|
I1 = record2->getItem("I");
|
2013-06-04 14:32:30 +02:00
|
|
|
BOOST_CHECK_EQUAL(1, I1->getInt(0));
|
|
|
|
|
|
2013-08-01 09:52:49 +02:00
|
|
|
J1 = record2->getItem(1);
|
2013-06-04 14:32:30 +02:00
|
|
|
BOOST_CHECK_EQUAL(2, J1->getInt(0));
|
2013-08-01 09:52:49 +02:00
|
|
|
J1 = record2->getItem("J");
|
2013-06-04 14:32:30 +02:00
|
|
|
BOOST_CHECK_EQUAL(2, J1->getInt(0));
|
|
|
|
|
|
2013-08-01 09:52:49 +02:00
|
|
|
K1 = record2->getItem(2);
|
2013-06-04 14:32:30 +02:00
|
|
|
BOOST_CHECK_EQUAL(3, K1->getInt(0));
|
2013-08-01 09:52:49 +02:00
|
|
|
K1 = record2->getItem("K");
|
2013-06-04 14:32:30 +02:00
|
|
|
BOOST_CHECK_EQUAL(3, K1->getInt(0));
|
2013-05-27 14:27:22 +02:00
|
|
|
}
|
2013-06-18 10:28:30 +02:00
|
|
|
|
|
|
|
|
|
2013-08-21 08:51:00 +02:00
|
|
|
/***************** Testing non-recognized keywords ********************/
|
2014-09-01 20:35:40 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(parse_unknownkeyword_exceptionthrown) {
|
2013-09-14 22:39:43 +02:00
|
|
|
ParserPtr parser(new Parser());
|
2015-07-24 15:38:22 +02:00
|
|
|
BOOST_CHECK_THROW( parser->parseFile("testdata/integration_tests/someobscureelements.data", ParseMode()), std::invalid_argument);
|
2013-06-18 10:28:30 +02:00
|
|
|
}
|
2013-08-23 14:20:32 +02:00
|
|
|
|
|
|
|
|
/*********************Testing truncated (default) records ***************************/
|
|
|
|
|
|
2013-08-26 15:17:52 +02:00
|
|
|
|
|
|
|
|
// Datafile contains 3 RADFIN4 keywords. One fully specified, one with 2 out of 11 items, and one with no items.
|
2013-08-23 14:20:32 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(parse_truncatedrecords_deckFilledWithDefaults) {
|
|
|
|
|
ParserPtr parser(new Parser());
|
2015-07-24 15:38:22 +02:00
|
|
|
DeckPtr deck = parser->parseFile("testdata/integration_tests/truncated_records.data", ParseMode());
|
2014-11-11 15:26:18 +01:00
|
|
|
BOOST_CHECK_EQUAL(3U, deck->size());
|
2013-08-26 15:17:52 +02:00
|
|
|
DeckKeywordConstPtr radfin4_0_full= deck->getKeyword("RADFIN4", 0);
|
|
|
|
|
DeckKeywordConstPtr radfin4_1_partial= deck->getKeyword("RADFIN4", 1);
|
|
|
|
|
|
|
|
|
|
// Specified in datafile
|
|
|
|
|
BOOST_CHECK_EQUAL("NAME", radfin4_0_full->getRecord(0)->getItem(0)->getString(0));
|
|
|
|
|
BOOST_CHECK_EQUAL("NAME", radfin4_1_partial->getRecord(0)->getItem(0)->getString(0));
|
2014-12-08 16:34:28 +01:00
|
|
|
|
2013-08-26 15:17:52 +02:00
|
|
|
// Specified in datafile
|
|
|
|
|
BOOST_CHECK_EQUAL(213, radfin4_0_full->getRecord(0)->getItem(1)->getInt(0));
|
|
|
|
|
BOOST_CHECK_EQUAL(213, radfin4_1_partial->getRecord(0)->getItem(1)->getInt(0));
|
2014-12-08 16:34:28 +01:00
|
|
|
|
2014-11-11 15:26:18 +01:00
|
|
|
const auto record_0 = radfin4_0_full->getRecord(0);
|
|
|
|
|
const auto lastItem_0 = record_0->getItem(record_0->size() - 1);
|
|
|
|
|
BOOST_CHECK(!lastItem_0->defaultApplied(0));
|
|
|
|
|
BOOST_CHECK_EQUAL(lastItem_0->getInt(0), 18);
|
|
|
|
|
|
|
|
|
|
const auto record_1 = radfin4_1_partial->getRecord(0);
|
|
|
|
|
const auto lastItem_1 = record_1->getItem(record_1->size() - 1);
|
|
|
|
|
BOOST_CHECK_EQUAL(213, radfin4_1_partial->getRecord(0)->getItem(1)->getInt(0));
|
|
|
|
|
BOOST_CHECK(lastItem_1->defaultApplied(0));
|
|
|
|
|
BOOST_CHECK_EQUAL(lastItem_1->getInt(0), 1);
|
2014-12-08 16:34:28 +01:00
|
|
|
|
2014-07-01 16:57:07 +02:00
|
|
|
ParserKeywordConstPtr parserKeyword = parser->getParserKeywordFromDeckName("RADFIN4");
|
2015-02-20 00:21:32 +01:00
|
|
|
ParserRecordConstPtr parserRecord = parserKeyword->getRecord(0);
|
2013-08-26 15:17:52 +02:00
|
|
|
ParserItemConstPtr nwmaxItem = parserRecord->get("NWMAX");
|
2013-12-02 13:07:01 +01:00
|
|
|
ParserIntItemConstPtr intItem = std::static_pointer_cast<const ParserIntItem>(nwmaxItem);
|
2014-12-08 16:34:28 +01:00
|
|
|
|
2013-08-26 15:17:52 +02:00
|
|
|
BOOST_CHECK_EQUAL(18, radfin4_0_full->getRecord(0)->getItem(10)->getInt(0));
|
|
|
|
|
BOOST_CHECK_EQUAL(intItem->getDefault(), radfin4_1_partial->getRecord(0)->getItem(10)->getInt(0));
|
2013-08-23 14:20:32 +02:00
|
|
|
}
|