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>
|
|
|
|
|
#include <boost/filesystem/operations.hpp>
|
|
|
|
|
#include <boost/filesystem/path.hpp>
|
|
|
|
|
|
2013-03-18 15:59:57 +01:00
|
|
|
#define BOOST_TEST_MODULE ParserTests
|
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
|
|
2013-04-02 15:19:32 +02:00
|
|
|
#include "opm/parser/eclipse/Parser/Parser.hpp"
|
2013-04-02 13:39:41 +02:00
|
|
|
#include "opm/parser/eclipse/RawDeck/RawDeck.hpp"
|
2013-03-18 15:59:57 +01:00
|
|
|
using namespace Opm;
|
2013-03-14 14:54:53 +01:00
|
|
|
|
2013-03-18 15:59:57 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(Initializing) {
|
2013-03-22 15:35:40 +01:00
|
|
|
BOOST_REQUIRE_NO_THROW(Parser parser);
|
2013-03-14 12:07:33 +01:00
|
|
|
}
|
|
|
|
|
|
2013-03-18 15:59:57 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(ParseWithInvalidInputFileThrows) {
|
2013-03-26 10:00:06 +01:00
|
|
|
ParserPtr parser(new Parser());
|
|
|
|
|
BOOST_REQUIRE_THROW(parser -> parse("nonexistingfile.asdf"), std::invalid_argument);
|
2013-03-18 15:59:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(ParseWithValidFileSetOnParseCallNoThrow) {
|
2013-03-22 15:35:40 +01:00
|
|
|
|
2013-03-20 16:29:51 +01:00
|
|
|
boost::filesystem::path singleKeywordFile("testdata/small.data");
|
2013-03-26 10:00:06 +01:00
|
|
|
ParserPtr parser(new Parser());
|
2013-03-26 14:31:05 +01:00
|
|
|
|
2013-03-26 10:00:06 +01:00
|
|
|
BOOST_REQUIRE_NO_THROW(parser -> parse(singleKeywordFile.string()));
|
2013-03-18 15:59:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(ParseWithInValidFileSetOnParseCallThrows) {
|
|
|
|
|
boost::filesystem::path singleKeywordFile("testdata/nosuchfile.data");
|
2013-03-26 10:00:06 +01:00
|
|
|
ParserPtr parser(new Parser());
|
|
|
|
|
BOOST_REQUIRE_THROW(parser -> parse(singleKeywordFile.string()), std::invalid_argument);
|
2013-03-14 14:54:53 +01:00
|
|
|
}
|
|
|
|
|
|
2013-03-26 14:31:05 +01:00
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(ParseFileWithOneKeyword) {
|
|
|
|
|
boost::filesystem::path singleKeywordFile("testdata/mini.data");
|
|
|
|
|
|
|
|
|
|
ParserPtr parser(new Parser());
|
|
|
|
|
|
|
|
|
|
RawDeckPtr rawDeck = parser -> parse(singleKeywordFile.string());
|
|
|
|
|
BOOST_REQUIRE_EQUAL((unsigned) 1, rawDeck -> getNumberOfKeywords());
|
|
|
|
|
RawKeywordPtr rawKeyword = rawDeck->getKeyword("ENDSCALE");
|
|
|
|
|
std::list<RawRecordPtr> records;
|
|
|
|
|
rawKeyword -> getRecords(records);
|
|
|
|
|
BOOST_REQUIRE_EQUAL((unsigned) 1, records.size());
|
|
|
|
|
RawRecordPtr record = records.back();
|
|
|
|
|
|
|
|
|
|
std::string recordString;
|
|
|
|
|
record -> getRecordString(recordString);
|
|
|
|
|
BOOST_REQUIRE_EQUAL("'NODIR' 'REVERS' 1 20", recordString);
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> recordElements;
|
|
|
|
|
record -> getRecords(recordElements);
|
|
|
|
|
BOOST_REQUIRE_EQUAL((unsigned)4, recordElements.size());
|
|
|
|
|
|
|
|
|
|
BOOST_REQUIRE_EQUAL("NODIR", recordElements[0]);
|
|
|
|
|
BOOST_REQUIRE_EQUAL("REVERS", recordElements[1]);
|
|
|
|
|
BOOST_REQUIRE_EQUAL("1", recordElements[2]);
|
|
|
|
|
BOOST_REQUIRE_EQUAL("20", recordElements[3]);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-22 15:35:40 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(ParseFileWithFewKeywords) {
|
2013-03-20 16:29:51 +01:00
|
|
|
boost::filesystem::path singleKeywordFile("testdata/small.data");
|
2013-03-14 14:54:53 +01:00
|
|
|
|
2013-03-26 10:00:06 +01:00
|
|
|
ParserPtr parser(new Parser());
|
2013-03-22 15:35:40 +01:00
|
|
|
|
2013-03-26 10:00:06 +01:00
|
|
|
RawDeckPtr rawDeck = parser -> parse(singleKeywordFile.string());
|
|
|
|
|
BOOST_REQUIRE_EQUAL((unsigned) 4, rawDeck -> getNumberOfKeywords());
|
2013-03-25 17:17:09 +01:00
|
|
|
|
2013-03-26 10:27:48 +01:00
|
|
|
RawKeywordPtr matchingKeyword = rawDeck -> getKeyword("INCLUDE");
|
|
|
|
|
BOOST_REQUIRE_EQUAL("INCLUDE", matchingKeyword->getKeyword());
|
2013-03-26 10:00:06 +01:00
|
|
|
|
2013-03-26 10:27:48 +01:00
|
|
|
std::list<RawRecordPtr> records;
|
2013-03-25 17:17:09 +01:00
|
|
|
matchingKeyword->getRecords(records);
|
|
|
|
|
BOOST_REQUIRE_EQUAL((unsigned) 1, records.size());
|
2013-03-26 10:00:06 +01:00
|
|
|
|
2013-03-26 10:27:48 +01:00
|
|
|
RawRecordPtr theRecord = records.front();
|
2013-03-25 17:17:09 +01:00
|
|
|
std::string recordString;
|
2013-03-26 14:31:05 +01:00
|
|
|
theRecord -> getRecordString(recordString);
|
2013-03-25 17:17:09 +01:00
|
|
|
BOOST_REQUIRE_EQUAL("\'sti til fil/den er her\'", recordString);
|
2013-03-26 10:27:48 +01:00
|
|
|
|
|
|
|
|
RawKeywordPtr matchingKeyword2 = rawDeck -> getKeyword("ABCDAD");
|
|
|
|
|
BOOST_REQUIRE_EQUAL("ABCDAD", matchingKeyword2->getKeyword());
|
|
|
|
|
|
|
|
|
|
std::list<RawRecordPtr> records2;
|
|
|
|
|
matchingKeyword2->getRecords(records2);
|
|
|
|
|
BOOST_REQUIRE_EQUAL((unsigned) 2, records2.size());
|
2013-03-14 12:07:33 +01:00
|
|
|
}
|
|
|
|
|
|
2013-03-20 17:35:03 +01:00
|
|
|
//NOTE: needs statoil dataset
|
2013-03-22 15:35:40 +01:00
|
|
|
|
2013-03-18 15:59:57 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(ParseFileWithManyKeywords) {
|
2013-04-02 12:34:44 +02:00
|
|
|
boost::filesystem::path multipleKeywordFile("testdata/statoil/gurbat_trimmed.DATA");
|
2013-03-15 16:09:24 +01:00
|
|
|
|
2013-03-26 10:00:06 +01:00
|
|
|
ParserPtr parser(new Parser());
|
|
|
|
|
|
|
|
|
|
RawDeckPtr rawDeck = parser -> parse(multipleKeywordFile.string());
|
|
|
|
|
BOOST_REQUIRE_EQUAL((unsigned) 18, rawDeck -> getNumberOfKeywords());
|
2013-03-14 12:07:33 +01:00
|
|
|
}
|
2013-03-20 17:35:03 +01:00
|
|
|
|
|
|
|
|
//NOTE: needs statoil dataset
|
2013-03-22 15:35:40 +01:00
|
|
|
|
2013-03-20 17:35:03 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(ParseFullTestFile) {
|
2013-04-02 12:34:44 +02:00
|
|
|
boost::filesystem::path multipleKeywordFile("testdata/statoil/ECLIPSE.DATA");
|
2013-03-20 17:35:03 +01:00
|
|
|
|
2013-03-26 10:00:06 +01:00
|
|
|
ParserPtr parser(new Parser());
|
|
|
|
|
|
|
|
|
|
RawDeckPtr rawDeck = parser -> parse(multipleKeywordFile.string());
|
|
|
|
|
BOOST_REQUIRE_EQUAL((unsigned) 73, rawDeck -> getNumberOfKeywords());
|
2013-03-20 17:35:03 +01:00
|
|
|
}
|