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>
|
|
|
|
|
#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;
|
|
|
|
|
|
2013-06-20 13:56:11 +02:00
|
|
|
ParserPtr createWWCTParser() {
|
2013-06-20 15:30:37 +02:00
|
|
|
ParserKeywordPtr parserKeyword(new ParserKeyword("WWCT"));
|
2013-06-20 13:56:11 +02:00
|
|
|
{
|
2013-07-31 15:02:00 +02:00
|
|
|
ParserRecordPtr wwctRecord = parserKeyword->getRecord();
|
2013-06-20 13:56:11 +02:00
|
|
|
wwctRecord->addItem(ParserStringItemConstPtr(new ParserStringItem("WELL", ALL)));
|
|
|
|
|
}
|
2013-08-21 07:41:06 +02:00
|
|
|
ParserKeywordPtr summaryKeyword(new ParserKeyword("SUMMARY" , 0));
|
|
|
|
|
|
2013-06-20 13:56:11 +02:00
|
|
|
|
|
|
|
|
ParserPtr parser(new Parser());
|
2013-06-20 15:40:45 +02:00
|
|
|
parser->addKeyword(parserKeyword);
|
2013-08-21 07:41:06 +02:00
|
|
|
parser->addKeyword(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();
|
2013-08-21 07:41:06 +02:00
|
|
|
BOOST_CHECK( parser->hasKeyword("WWCT"));
|
|
|
|
|
BOOST_CHECK( parser->hasKeyword("SUMMARY"));
|
2013-06-20 13:56:11 +02:00
|
|
|
BOOST_CHECK_NO_THROW(DeckPtr deck = parser->parse(singleKeywordFile.string()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(parse_fileWithWWCTKeyword_deckHasWWCT) {
|
|
|
|
|
boost::filesystem::path singleKeywordFile("testdata/integration_tests/wwct.data");
|
|
|
|
|
ParserPtr parser = createWWCTParser();
|
|
|
|
|
DeckPtr deck = parser->parse(singleKeywordFile.string());
|
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();
|
|
|
|
|
DeckPtr deck = parser->parse(singleKeywordFile.string());
|
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
|
|
|
}
|
|
|
|
|
|
2013-05-30 10:11:12 +02:00
|
|
|
ParserPtr createBPRParser() {
|
2013-06-20 15:30:37 +02:00
|
|
|
ParserKeywordPtr parserKeyword(new ParserKeyword("BPR"));
|
2013-05-30 10:11:12 +02:00
|
|
|
{
|
2013-07-31 15:02:00 +02:00
|
|
|
ParserRecordPtr bprRecord = parserKeyword->getRecord();
|
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)));
|
|
|
|
|
}
|
2013-08-21 07:41:06 +02:00
|
|
|
ParserKeywordPtr summaryKeyword(new ParserKeyword("SUMMARY" , 0));
|
2013-05-30 10:11:12 +02:00
|
|
|
ParserPtr parser(new Parser());
|
2013-06-20 15:40:45 +02:00
|
|
|
parser->addKeyword(parserKeyword);
|
2013-08-21 07:41:06 +02:00
|
|
|
parser->addKeyword(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();
|
|
|
|
|
|
2013-06-04 14:32:30 +02:00
|
|
|
BOOST_CHECK_NO_THROW(DeckPtr deck = parser->parse(singleKeywordFile.string()));
|
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();
|
2013-06-04 14:32:30 +02:00
|
|
|
DeckPtr deck = parser->parse(singleKeywordFile.string());
|
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();
|
2013-05-30 10:11:12 +02:00
|
|
|
DeckPtr deck = parser->parse(singleKeywordFile.string());
|
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 ********************/
|
2013-08-21 14:54:38 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(parse_unknownkeywordWithnonstrictparsing_keywordmarked) {
|
2013-09-14 22:39:43 +02:00
|
|
|
ParserPtr parser(new Parser());
|
2013-08-21 14:54:38 +02:00
|
|
|
DeckPtr deck = parser->parse("testdata/integration_tests/someobscureelements.data", false);
|
2013-08-21 10:41:18 +02:00
|
|
|
BOOST_CHECK_EQUAL(4U, deck->size());
|
|
|
|
|
DeckKeywordConstPtr unknown = deck->getKeyword("GRUDINT");
|
|
|
|
|
BOOST_CHECK(!unknown->isKnown());
|
|
|
|
|
}
|
2013-06-18 10:28:30 +02:00
|
|
|
|
2013-08-21 14:54:38 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(parse_unknownkeywordWithstrictparsing_exceptionthrown) {
|
2013-09-14 22:39:43 +02:00
|
|
|
ParserPtr parser(new Parser());
|
2013-08-21 14:54:38 +02:00
|
|
|
BOOST_CHECK_THROW(parser->parse("testdata/integration_tests/someobscureelements.data", true), 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());
|
|
|
|
|
parser->loadKeywordsFromDirectory(KEYWORD_DIRECTORY);
|
|
|
|
|
DeckPtr deck = parser->parse("testdata/integration_tests/truncated_records.data");
|
2013-08-26 15:17:52 +02:00
|
|
|
BOOST_CHECK_EQUAL(4U, deck->size());
|
|
|
|
|
DeckKeywordConstPtr radfin4_0_full= deck->getKeyword("RADFIN4", 0);
|
|
|
|
|
DeckKeywordConstPtr radfin4_1_partial= deck->getKeyword("RADFIN4", 1);
|
|
|
|
|
DeckKeywordConstPtr radfin4_2_nodata= deck->getKeyword("RADFIN4", 2);
|
|
|
|
|
|
|
|
|
|
// 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));
|
|
|
|
|
// Default string
|
|
|
|
|
BOOST_CHECK_EQUAL(ParserItem::defaultString(), radfin4_2_nodata->getRecord(0)->getItem(0)->getString(0));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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));
|
|
|
|
|
// Default int
|
|
|
|
|
BOOST_CHECK_EQUAL(ParserItem::defaultInt(), radfin4_2_nodata->getRecord(0)->getItem(1)->getInt(0));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ParserKeywordConstPtr parserKeyword = parser->getKeyword("RADFIN4");
|
|
|
|
|
ParserRecordConstPtr parserRecord = parserKeyword->getRecord();
|
|
|
|
|
ParserItemConstPtr nwmaxItem = parserRecord->get("NWMAX");
|
|
|
|
|
ParserIntItemConstPtr intItem = boost::static_pointer_cast<const ParserIntItem>(nwmaxItem);
|
|
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
BOOST_CHECK_EQUAL(intItem->getDefault(), radfin4_2_nodata->getRecord(0)->getItem(10)->getInt(0));
|
2013-08-23 14:20:32 +02:00
|
|
|
|
|
|
|
|
}
|