2013-03-18 13:40:14 +01: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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-03-18 15:59:57 +01:00
|
|
|
#include <stdexcept>
|
2013-03-20 16:29:51 +01:00
|
|
|
#include <iostream>
|
2013-03-14 14:54:53 +01:00
|
|
|
#include <boost/filesystem.hpp>
|
2013-03-18 15:59:57 +01:00
|
|
|
#define BOOST_TEST_MODULE ParserTests
|
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
|
|
2013-04-03 11:38:06 +02:00
|
|
|
|
2013-05-30 10:11:12 +02:00
|
|
|
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
|
|
|
|
#include <opm/parser/eclipse/Parser/ParserKW.hpp>
|
|
|
|
|
#include <opm/parser/eclipse/Parser/ParserRecordSize.hpp>
|
|
|
|
|
#include <opm/parser/eclipse/RawDeck/RawDeck.hpp>
|
2013-04-04 09:56:00 +02:00
|
|
|
|
2013-06-20 13:56:11 +02:00
|
|
|
#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>
|
|
|
|
|
#include <opm/parser/eclipse/Parser/ParserStringItem.hpp>
|
|
|
|
|
|
2013-06-18 13:47:07 +02:00
|
|
|
|
2013-05-30 10:11:12 +02:00
|
|
|
using namespace Opm;
|
2013-04-04 09:56:00 +02:00
|
|
|
|
2013-03-18 15:59:57 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(Initializing) {
|
2013-05-06 12:13:49 +02:00
|
|
|
BOOST_CHECK_NO_THROW(Parser parser);
|
2013-05-30 10:11:12 +02:00
|
|
|
BOOST_CHECK_NO_THROW(ParserPtr parserPtr(new Parser()));
|
|
|
|
|
BOOST_CHECK_NO_THROW(ParserConstPtr parserConstPtr(new Parser()));
|
2013-03-14 12:07:33 +01:00
|
|
|
}
|
|
|
|
|
|
2013-06-18 13:47:07 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(addKW_keyword_doesntfail) {
|
2013-05-06 12:13:49 +02:00
|
|
|
Parser parser;
|
|
|
|
|
{
|
|
|
|
|
ParserRecordSizePtr recordSize(new ParserRecordSize(9));
|
|
|
|
|
ParserKWPtr equilKW(new ParserKW("EQUIL", recordSize));
|
|
|
|
|
parser.addKW(equilKW);
|
|
|
|
|
}
|
2013-03-20 17:35:03 +01:00
|
|
|
}
|
2013-04-03 11:38:06 +02:00
|
|
|
|
2013-06-04 14:32:30 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(hasKeyword_hasKeyword_returnstrue) {
|
2013-06-18 14:12:00 +02:00
|
|
|
ParserPtr parser(new Parser());
|
|
|
|
|
parser->addKW(ParserKWConstPtr(new ParserKW("FJAS")));
|
|
|
|
|
BOOST_CHECK(parser->hasKeyword("FJAS"));
|
2013-06-04 14:32:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-06-20 13:56:11 +02:00
|
|
|
/***************** Simple Int parsing ********************************/
|
|
|
|
|
|
|
|
|
|
ParserKWPtr setupParserKWInt(std::string name, int numberOfItems) {
|
|
|
|
|
ParserKWPtr parserKw(new ParserKW(name));
|
2013-06-18 13:47:07 +02:00
|
|
|
ParserRecordPtr parserRecord(new ParserRecord());
|
2013-06-18 14:12:00 +02:00
|
|
|
for (int i = 0; i < numberOfItems; i++) {
|
|
|
|
|
std::string name = "ITEM_" + boost::lexical_cast<std::string>(i);
|
|
|
|
|
ParserItemPtr intItem(new ParserIntItem(name, SINGLE));
|
|
|
|
|
parserRecord->addItem(intItem);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-18 13:47:07 +02:00
|
|
|
parserKw->setRecord(parserRecord);
|
2013-06-18 14:12:00 +02:00
|
|
|
|
|
|
|
|
return parserKw;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-20 13:56:11 +02:00
|
|
|
RawDeckPtr setupRawDeckInt(std::string name, int numberOfRecords, int numberOfItems) {
|
2013-06-18 13:47:07 +02:00
|
|
|
RawParserKWsConstPtr rawParserKWs(new RawParserKWs());
|
|
|
|
|
RawDeckPtr rawDeck(new RawDeck(rawParserKWs));
|
2013-06-18 14:12:00 +02:00
|
|
|
|
2013-06-20 13:56:11 +02:00
|
|
|
RawKeywordPtr rawKeyword(new RawKeyword(name));
|
2013-06-18 14:12:00 +02:00
|
|
|
for (int records = 0; records < numberOfRecords; records++) {
|
|
|
|
|
for (int i = 0; i < numberOfItems; i++)
|
|
|
|
|
rawKeyword->addRawRecordString("42 ");
|
|
|
|
|
rawKeyword->addRawRecordString("/");
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-18 13:47:07 +02:00
|
|
|
rawDeck->addKeyword(rawKeyword);
|
2013-06-18 14:12:00 +02:00
|
|
|
|
|
|
|
|
return rawDeck;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(parseFromRawDeck_singleRawSingleIntItem_deckReturned) {
|
|
|
|
|
ParserPtr parser(new Parser());
|
2013-06-20 13:56:11 +02:00
|
|
|
parser->addKW(setupParserKWInt("RANDOM", 1));
|
|
|
|
|
DeckPtr deck = parser->parseFromRawDeck(setupRawDeckInt("RANDOM", 1, 1));
|
2013-06-18 14:12:00 +02:00
|
|
|
|
2013-06-18 13:47:07 +02:00
|
|
|
BOOST_CHECK(!deck->hasKeyword("ANDOM"));
|
2013-06-18 14:12:00 +02:00
|
|
|
|
|
|
|
|
BOOST_CHECK(deck->hasKeyword("RANDOM"));
|
|
|
|
|
BOOST_CHECK_EQUAL(1U, deck->getKeyword("RANDOM")->getRecord(0)->size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(parseFromRawDeck_singleRawRecordsSeveralIntItem_deckReturned) {
|
|
|
|
|
ParserPtr parser(new Parser());
|
2013-06-20 13:56:11 +02:00
|
|
|
parser->addKW(setupParserKWInt("RANDOM", 50));
|
|
|
|
|
DeckPtr deck = parser->parseFromRawDeck(setupRawDeckInt("RANDOM", 1, 50));
|
2013-06-18 14:12:00 +02:00
|
|
|
|
|
|
|
|
BOOST_CHECK(deck->hasKeyword("RANDOM"));
|
|
|
|
|
BOOST_CHECK_EQUAL(50U, deck->getKeyword("RANDOM")->getRecord(0)->size());
|
2013-06-18 13:47:07 +02:00
|
|
|
}
|
|
|
|
|
|
2013-06-18 14:12:00 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(parseFromRawDeck_severalRawRecordsSeveralIntItem_deckReturned) {
|
|
|
|
|
ParserPtr parser(new Parser());
|
2013-06-20 13:56:11 +02:00
|
|
|
parser->addKW(setupParserKWInt("RANDOM", 50));
|
|
|
|
|
DeckPtr deck = parser->parseFromRawDeck(setupRawDeckInt("RANDOM", 10, 50));
|
2013-06-18 14:12:00 +02:00
|
|
|
|
|
|
|
|
BOOST_CHECK(deck->hasKeyword("RANDOM"));
|
|
|
|
|
BOOST_CHECK_EQUAL(10U, deck->getKeyword("RANDOM")->size());
|
|
|
|
|
BOOST_CHECK_EQUAL(50U, deck->getKeyword("RANDOM")->getRecord(0)->size());
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-20 13:56:11 +02:00
|
|
|
/***************** Simple String parsing ********************************/
|
|
|
|
|
|
|
|
|
|
ParserKWPtr setupParserKWString(std::string name, int numberOfItems) {
|
|
|
|
|
ParserKWPtr parserKw(new ParserKW(name));
|
|
|
|
|
ParserRecordPtr parserRecord(new ParserRecord());
|
|
|
|
|
for (int i = 0; i < numberOfItems; i++) {
|
|
|
|
|
std::string name = "ITEM_" + boost::lexical_cast<std::string>(i);
|
|
|
|
|
ParserItemPtr stringItem(new ParserStringItem(name, SINGLE));
|
|
|
|
|
parserRecord->addItem(stringItem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parserKw->setRecord(parserRecord);
|
|
|
|
|
|
|
|
|
|
return parserKw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RawDeckPtr setupRawDeckString(std::string name, int numberOfRecords, int numberOfItems) {
|
|
|
|
|
RawParserKWsConstPtr rawParserKWs(new RawParserKWs());
|
|
|
|
|
RawDeckPtr rawDeck(new RawDeck(rawParserKWs));
|
|
|
|
|
|
|
|
|
|
RawKeywordPtr rawKeyword(new RawKeyword(name));
|
|
|
|
|
for (int records = 0; records < numberOfRecords; records++) {
|
|
|
|
|
for (int i = 0; i < numberOfItems; i++) {
|
|
|
|
|
std::string data = "WELL-" + boost::lexical_cast<std::string>(i);
|
|
|
|
|
rawKeyword->addRawRecordString(data);
|
|
|
|
|
}
|
|
|
|
|
rawKeyword->addRawRecordString("/");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rawDeck->addKeyword(rawKeyword);
|
|
|
|
|
|
|
|
|
|
return rawDeck;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(parseFromRawDeck_singleRawRecordsSingleStringItem_deckReturned) {
|
|
|
|
|
ParserPtr parser(new Parser());
|
|
|
|
|
parser->addKW(setupParserKWString("WWCT", 1));
|
|
|
|
|
DeckPtr deck = parser->parseFromRawDeck(setupRawDeckString("WWCT",1, 1));
|
|
|
|
|
|
|
|
|
|
BOOST_CHECK(deck->hasKeyword("WWCT"));
|
|
|
|
|
BOOST_CHECK_EQUAL(1U, deck->getKeyword("WWCT")->size());
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-18 14:12:00 +02:00
|
|
|
|
2013-06-18 13:47:07 +02:00
|
|
|
|
|
|
|
|
|
2013-06-04 14:32:30 +02:00
|
|
|
|
|
|
|
|
|
2013-04-03 11:38:06 +02:00
|
|
|
|
|
|
|
|
|