Finished up the last pieces for a simple BPR keyword vertical.
This commit is contained in:
parent
18db675f71
commit
fbb468342d
@ -17,7 +17,7 @@
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Deck.hpp"
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
@ -28,9 +28,14 @@ namespace Opm {
|
||||
bool Deck::hasKeyword(const std::string& keyword) const {
|
||||
return m_keywords->hasKeyword(keyword);
|
||||
}
|
||||
|
||||
|
||||
Deck::~Deck() {
|
||||
|
||||
void Deck::addKeyword( DeckKWConstPtr keyword) {
|
||||
m_keywords->addKeyword(keyword);
|
||||
}
|
||||
|
||||
DeckKWConstPtr Deck::getKeyword(const std::string& keyword) const {
|
||||
return m_keywords->getKeyword(keyword);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -28,9 +28,10 @@ namespace Opm {
|
||||
class Deck {
|
||||
public:
|
||||
Deck();
|
||||
virtual ~Deck();
|
||||
|
||||
bool hasKeyword( const std::string& keyword ) const;
|
||||
void addKeyword( DeckKWConstPtr keyword);
|
||||
DeckKWConstPtr getKeyword(const std::string& keyword) const;
|
||||
|
||||
private:
|
||||
KeywordContainerPtr m_keywords;
|
||||
};
|
||||
|
@ -42,18 +42,18 @@ namespace Opm {
|
||||
throw std::invalid_argument("Item with name: " + deckItem->name() + " already exists in DeckRecord");
|
||||
}
|
||||
|
||||
DeckItemConstPtr DeckRecord::get(size_t index) {
|
||||
DeckItemConstPtr DeckRecord::get(size_t index) const {
|
||||
if (index < m_items.size())
|
||||
return m_items[index];
|
||||
else
|
||||
throw std::range_error("Index out of range.");
|
||||
}
|
||||
|
||||
DeckItemConstPtr DeckRecord::get(const std::string& name) {
|
||||
DeckItemConstPtr DeckRecord::get(const std::string& name) const {
|
||||
if (m_itemMap.find(name) == m_itemMap.end())
|
||||
throw std::invalid_argument("Itemname: " + name + " does not exist.");
|
||||
else
|
||||
return m_itemMap[name];
|
||||
return m_itemMap.find(name)->second;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -34,8 +34,8 @@ namespace Opm {
|
||||
DeckRecord();
|
||||
size_t size() const;
|
||||
void addItem(DeckItemConstPtr deckItem);
|
||||
DeckItemConstPtr get(size_t index);
|
||||
DeckItemConstPtr get(const std::string& name);
|
||||
DeckItemConstPtr get(size_t index) const;
|
||||
DeckItemConstPtr get(const std::string& name) const;
|
||||
|
||||
private:
|
||||
std::vector<DeckItemConstPtr> m_items;
|
||||
|
@ -37,7 +37,7 @@ namespace Opm {
|
||||
void KeywordContainer::addKeyword(DeckKWConstPtr keyword) {
|
||||
m_keywordList.push_back(keyword);
|
||||
|
||||
if (m_keywordMap.find(keyword->name()) == m_keywordMap.end()) {
|
||||
if (!hasKeyword(keyword->name())) {
|
||||
m_keywordMap[keyword->name()] = std::vector<DeckKWConstPtr>();
|
||||
}
|
||||
|
||||
@ -46,5 +46,15 @@ namespace Opm {
|
||||
keywordList.push_back(keyword);
|
||||
}
|
||||
}
|
||||
|
||||
DeckKWConstPtr KeywordContainer::getKeyword(const std::string& keyword) const {
|
||||
if (hasKeyword(keyword)) {
|
||||
const std::vector<DeckKWConstPtr>& keywordList = m_keywordMap.find(keyword)->second;
|
||||
return keywordList.back();
|
||||
}
|
||||
else
|
||||
throw std::invalid_argument("Keyword: " + keyword + " is not found in the container");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ namespace Opm {
|
||||
bool hasKeyword(const std::string& keyword) const;
|
||||
size_t size() const;
|
||||
void addKeyword(DeckKWConstPtr keyword);
|
||||
DeckKWConstPtr getKeyword(const std::string& keyword) const;
|
||||
|
||||
|
||||
private:
|
||||
std::vector<DeckKWConstPtr> m_keywordList;
|
||||
|
@ -32,13 +32,29 @@ BOOST_AUTO_TEST_CASE(Initialize) {
|
||||
BOOST_REQUIRE_NO_THROW(DeckConstPtr deckConstPtr(new Deck()));
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(hasKeyword_empty_returnFalse) {
|
||||
Deck deck;
|
||||
BOOST_CHECK_EQUAL( false , deck.hasKeyword("Bjarne"));
|
||||
BOOST_CHECK_EQUAL(false, deck.hasKeyword("Bjarne"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(addKeyword_singlekeyword_keywordAdded) {
|
||||
Deck deck;
|
||||
DeckKWConstPtr keyword(new DeckKW("BJARNE"));
|
||||
BOOST_CHECK_NO_THROW(deck.addKeyword(keyword));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(getKeyword_nosuchkeyword_throws) {
|
||||
Deck deck;
|
||||
BOOST_CHECK_THROW(deck.getKeyword("TRULS"), std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(getKeyword_singlekeyword_keywordreturned) {
|
||||
Deck deck;
|
||||
DeckKWConstPtr keyword(new DeckKW("BJARNE"));
|
||||
deck.addKeyword(keyword);
|
||||
BOOST_CHECK_EQUAL(keyword, deck.getKeyword("BJARNE"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -50,6 +50,18 @@ BOOST_AUTO_TEST_CASE(addKeyword_keywordAdded_keywordAdded) {
|
||||
BOOST_CHECK_EQUAL(1U, container->size());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(getKeyword_nosuchkeyword_throws) {
|
||||
KeywordContainerPtr container(new KeywordContainer());
|
||||
BOOST_CHECK_THROW(container->getKeyword("TRULS"), std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(getKeyword_singleKeyword_keywordReturned) {
|
||||
KeywordContainerPtr container(new KeywordContainer());
|
||||
DeckKWPtr keyword = DeckKWPtr(new DeckKW("TRULS"));
|
||||
container->addKeyword(keyword);
|
||||
BOOST_CHECK_EQUAL(keyword, container->getKeyword("TRULS"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -30,7 +30,6 @@
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
|
||||
ParserPtr createBPRParser() {
|
||||
ParserKWPtr parserKW(new ParserKW("BPR"));
|
||||
{
|
||||
@ -38,27 +37,75 @@ ParserPtr createBPRParser() {
|
||||
bprRecord->addItem(ParserIntItemConstPtr(new ParserIntItem("I", SINGLE)));
|
||||
bprRecord->addItem(ParserIntItemConstPtr(new ParserIntItem("J", SINGLE)));
|
||||
bprRecord->addItem(ParserIntItemConstPtr(new ParserIntItem("K", SINGLE)));
|
||||
|
||||
|
||||
parserKW->setRecord(bprRecord);
|
||||
}
|
||||
|
||||
ParserPtr parser(new Parser());
|
||||
parser->addKW(parserKW);
|
||||
return parser;
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_fileWithBPRKeyword_deckReturned) {
|
||||
boost::filesystem::path singleKeywordFile("testdata/integration_tests/bpr.data");
|
||||
ParserPtr parser = createBPRParser();
|
||||
|
||||
BOOST_CHECK_NO_THROW( DeckPtr deck = parser->parse(singleKeywordFile.string()));
|
||||
BOOST_CHECK_NO_THROW(DeckPtr deck = parser->parse(singleKeywordFile.string()));
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_fileWithBPRKeyword_DeckhasBRP) {
|
||||
boost::filesystem::path singleKeywordFile("testdata/integration_tests/bpr.data");
|
||||
ParserPtr parser = createBPRParser();
|
||||
|
||||
ParserPtr parser = createBPRParser();
|
||||
DeckPtr deck = parser->parse(singleKeywordFile.string());
|
||||
BOOST_CHECK_EQUAL( true , deck->hasKeyword("BPR"));
|
||||
|
||||
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();
|
||||
DeckPtr deck = parser->parse(singleKeywordFile.string());
|
||||
|
||||
DeckKWConstPtr keyword = deck->getKeyword("BPR");
|
||||
BOOST_CHECK_EQUAL(2U, keyword->size());
|
||||
|
||||
DeckRecordConstPtr record1 = keyword->getRecord(0);
|
||||
BOOST_CHECK_EQUAL(3U, record1->size());
|
||||
|
||||
DeckItemConstPtr I1 = record1->get(0);
|
||||
BOOST_CHECK_EQUAL(1, I1->getInt(0));
|
||||
I1 = record1->get("I");
|
||||
BOOST_CHECK_EQUAL(1, I1->getInt(0));
|
||||
|
||||
DeckItemConstPtr J1 = record1->get(1);
|
||||
BOOST_CHECK_EQUAL(2, J1->getInt(0));
|
||||
J1 = record1->get("J");
|
||||
BOOST_CHECK_EQUAL(2, J1->getInt(0));
|
||||
|
||||
DeckItemConstPtr K1 = record1->get(2);
|
||||
BOOST_CHECK_EQUAL(3, K1->getInt(0));
|
||||
K1 = record1->get("K");
|
||||
BOOST_CHECK_EQUAL(3, K1->getInt(0));
|
||||
|
||||
|
||||
DeckRecordConstPtr record2 = keyword->getRecord(0);
|
||||
BOOST_CHECK_EQUAL(3U, record2->size());
|
||||
|
||||
I1 = record2->get(0);
|
||||
BOOST_CHECK_EQUAL(1, I1->getInt(0));
|
||||
I1 = record2->get("I");
|
||||
BOOST_CHECK_EQUAL(1, I1->getInt(0));
|
||||
|
||||
J1 = record2->get(1);
|
||||
BOOST_CHECK_EQUAL(2, J1->getInt(0));
|
||||
J1 = record2->get("J");
|
||||
BOOST_CHECK_EQUAL(2, J1->getInt(0));
|
||||
|
||||
K1 = record2->get(2);
|
||||
BOOST_CHECK_EQUAL(3, K1->getInt(0));
|
||||
K1 = record2->get("K");
|
||||
BOOST_CHECK_EQUAL(3, K1->getInt(0));
|
||||
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserKW.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawParserKWs.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawConsts.hpp>
|
||||
#include <opm/parser/eclipse/Logger/Logger.hpp>
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
|
||||
@ -29,31 +30,103 @@ namespace Opm {
|
||||
}
|
||||
|
||||
DeckPtr Parser::parse(const std::string &path) {
|
||||
Logger::initLogger();
|
||||
Logger::info("Starting parsing of file: " + path);
|
||||
|
||||
RawDeckPtr rawDeck(new RawDeck(RawParserKWsConstPtr(new RawParserKWs())));
|
||||
rawDeck->parse(path);
|
||||
RawDeckPtr rawDeck = readToRawDeck(path);
|
||||
|
||||
DeckPtr deck(new Deck());
|
||||
for (size_t i = 0; i < rawDeck->getNumberOfKeywords(); i++) {
|
||||
//RawKeywordPtr rawKeyword = rawDeck->getKeyword(0);
|
||||
for (size_t i = 0; i < rawDeck->size(); i++) {
|
||||
RawKeywordConstPtr rawKeyword = rawDeck->getKeyword(i);
|
||||
|
||||
if (hasKeyword(rawKeyword->getKeywordName())) {
|
||||
ParserKWConstPtr parserKW = m_parserKeywords[rawKeyword->getKeywordName()];
|
||||
DeckKWConstPtr deckKW = parserKW->parse(rawKeyword);
|
||||
deck->addKeyword(deckKW);
|
||||
}
|
||||
else
|
||||
std::cerr << "Keyword: " << rawKeyword->getKeywordName() << " is not recognized, skipping this." << std::endl;
|
||||
}
|
||||
|
||||
|
||||
Logger::info("Done parsing of file: " + path);
|
||||
Logger::closeLogger();
|
||||
return deck;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Parser::~Parser() {
|
||||
}
|
||||
|
||||
void Parser::addKW(ParserKWConstPtr parserKW) {
|
||||
m_parserKeywords.insert(std::make_pair(parserKW->getName(), parserKW));
|
||||
}
|
||||
|
||||
bool Parser::hasKeyword(const std::string& keyword) const {
|
||||
return m_parserKeywords.find(keyword) != m_parserKeywords.end();
|
||||
}
|
||||
|
||||
RawDeckPtr Parser::readToRawDeck(const std::string& path) {
|
||||
RawDeckPtr rawDeck(new RawDeck(RawParserKWsConstPtr(new RawParserKWs())));
|
||||
readToRawDeck(rawDeck, path);
|
||||
return rawDeck;
|
||||
}
|
||||
|
||||
/// The main data reading function, reads one and one keyword into the RawDeck
|
||||
/// If the INCLUDE keyword is found, the specified include file is inline read into the RawDeck.
|
||||
/// The data is read into a keyword, record by record, until the fixed number of records specified
|
||||
/// in the RawParserKW is met, or till a slash on a separate line is found.
|
||||
|
||||
void Parser::readToRawDeck(RawDeckPtr rawDeck, const std::string& path) {
|
||||
boost::filesystem::path dataFolderPath = verifyValidInputPath(path);
|
||||
{
|
||||
std::ifstream inputstream;
|
||||
inputstream.open(path.c_str());
|
||||
|
||||
std::string line;
|
||||
RawKeywordPtr currentRawKeyword;
|
||||
while (std::getline(inputstream, line)) {
|
||||
std::string keywordString;
|
||||
if (currentRawKeyword == NULL) {
|
||||
if (RawKeyword::tryParseKeyword(line, keywordString)) {
|
||||
currentRawKeyword = RawKeywordPtr(new RawKeyword(keywordString));
|
||||
if (rawDeck->isKeywordFinished(currentRawKeyword)) {
|
||||
rawDeck->addKeyword(currentRawKeyword);
|
||||
currentRawKeyword.reset();
|
||||
}
|
||||
}
|
||||
} else if (currentRawKeyword != NULL && RawKeyword::lineContainsData(line)) {
|
||||
currentRawKeyword->addRawRecordString(line);
|
||||
if (rawDeck->isKeywordFinished(currentRawKeyword)) {
|
||||
// The INCLUDE keyword has fixed lenght 1, will hit here
|
||||
if (currentRawKeyword->getKeywordName() == Opm::RawConsts::include)
|
||||
processIncludeKeyword(rawDeck, currentRawKeyword, dataFolderPath);
|
||||
else
|
||||
rawDeck->addKeyword(currentRawKeyword);
|
||||
|
||||
currentRawKeyword.reset();
|
||||
}
|
||||
} else if (currentRawKeyword != NULL && RawKeyword::lineTerminatesKeyword(line)) {
|
||||
if (!currentRawKeyword->isPartialRecordStringEmpty()) {
|
||||
// This is an error in the input file, but sometimes occurs
|
||||
currentRawKeyword->addRawRecordString(std::string(1, Opm::RawConsts::slash));
|
||||
}
|
||||
// Don't need to check for include here, since only non-fixed lenght keywords come here.
|
||||
rawDeck->addKeyword(currentRawKeyword);
|
||||
currentRawKeyword.reset();
|
||||
}
|
||||
}
|
||||
inputstream.close();
|
||||
}
|
||||
}
|
||||
|
||||
void Parser::processIncludeKeyword(RawDeckPtr rawDeck, RawKeywordConstPtr keyword, const boost::filesystem::path& dataFolderPath) {
|
||||
RawRecordConstPtr firstRecord = keyword->getRecord(0);
|
||||
std::string includeFileString = firstRecord->getItem(0);
|
||||
boost::filesystem::path pathToIncludedFile(dataFolderPath);
|
||||
pathToIncludedFile /= includeFileString;
|
||||
|
||||
readToRawDeck(rawDeck, pathToIncludedFile.string());
|
||||
}
|
||||
|
||||
boost::filesystem::path Parser::verifyValidInputPath(const std::string& inputPath) {
|
||||
Logger::info("Verifying path: " + inputPath);
|
||||
boost::filesystem::path pathToInputFile(inputPath);
|
||||
if (!boost::filesystem::is_regular_file(pathToInputFile)) {
|
||||
Logger::error("Unable to open file with path: " + inputPath);
|
||||
throw std::invalid_argument("Given path is not a valid file-path, path: " + inputPath);
|
||||
}
|
||||
return pathToInputFile.parent_path();
|
||||
}
|
||||
|
||||
|
||||
} // namespace Opm
|
||||
|
@ -42,13 +42,19 @@ namespace Opm {
|
||||
|
||||
/// The starting point of the parsing process. The supplied file is parsed, and the resulting Deck is returned.
|
||||
DeckPtr parse(const std::string &path);
|
||||
virtual ~Parser();
|
||||
|
||||
RawDeckPtr readToRawDeck(const std::string& path);
|
||||
|
||||
/// Method to add ParserKW instances, these holding type and size information about the keywords and their data.
|
||||
void addKW(ParserKWConstPtr parserKW);
|
||||
bool hasKeyword(const std::string& keyword) const;
|
||||
|
||||
private:
|
||||
std::map<std::string, ParserKWConstPtr> m_parserKeywords;
|
||||
void readToRawDeck(RawDeckPtr rawDeck, const std::string& path);
|
||||
void processIncludeKeyword(RawDeckPtr rawDeck, RawKeywordConstPtr keyword, const boost::filesystem::path& dataFolderPath);
|
||||
boost::filesystem::path verifyValidInputPath(const std::string& inputPath);
|
||||
|
||||
};
|
||||
|
||||
typedef boost::shared_ptr<Parser> ParserPtr;
|
||||
|
@ -54,7 +54,7 @@ namespace Opm {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
DeckKWPtr ParserKW::parse(RawKeywordPtr rawKeyword) {
|
||||
DeckKWPtr ParserKW::parse(RawKeywordConstPtr rawKeyword) const {
|
||||
DeckKWPtr keyword(new DeckKW(getName()));
|
||||
if (m_record != NULL) {
|
||||
for (size_t i=0; i<rawKeyword->size(); i++) {
|
||||
|
@ -37,7 +37,7 @@ namespace Opm {
|
||||
void setRecord(ParserRecordConstPtr record);
|
||||
ParserRecordConstPtr getRecord();
|
||||
const std::string& getName() const;
|
||||
DeckKWPtr parse(RawKeywordPtr rawKeyword);
|
||||
DeckKWPtr parse(RawKeywordConstPtr rawKeyword) const;
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
|
@ -3,18 +3,22 @@ add_executable(runParserKWTests ParserKWTests.cpp)
|
||||
add_executable(runParserRecordTests ParserRecordTests.cpp)
|
||||
add_executable(runParserRecordSizeTests ParserRecordSizeTests.cpp)
|
||||
add_executable(runParserItemTests ParserItemTests.cpp)
|
||||
add_executable(runParserTestsInternalDataTests ParserTestsInternalData.cpp)
|
||||
|
||||
target_link_libraries(runParserTests Parser ${Boost_LIBRARIES})
|
||||
target_link_libraries(runParserKWTests Parser ${Boost_LIBRARIES})
|
||||
target_link_libraries(runParserRecordSizeTests Parser ${Boost_LIBRARIES})
|
||||
target_link_libraries(runParserRecordTests Parser ${Boost_LIBRARIES})
|
||||
target_link_libraries(runParserItemTests Parser ${Boost_LIBRARIES})
|
||||
target_link_libraries(runParserTestsInternalDataTests Parser ${Boost_LIBRARIES})
|
||||
|
||||
|
||||
add_test(NAME runParserTests WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${EXECUTABLE_OUTPUT_PATH}/runParserTests )
|
||||
add_test(NAME runParserKWTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runParserKWTests )
|
||||
add_test(NAME runParserRecordSizeTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runParserRecordSizeTests )
|
||||
add_test(NAME runParserRecordTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runParserRecordTests )
|
||||
add_test(NAME runParserItemTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runParserItemTests )
|
||||
add_test(NAME runParserTestsInternalDataTests WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} COMMAND ${EXECUTABLE_OUTPUT_PATH}/runParserTestsInternalDataTests )
|
||||
|
||||
|
||||
set_tests_properties(runParserTestsInternalDataTests PROPERTIES LABEL Statoil)
|
||||
set_property(SOURCE ParserRecordTests.cpp PROPERTY COMPILE_FLAGS "-Wno-error")
|
||||
|
@ -37,12 +37,6 @@ BOOST_AUTO_TEST_CASE(Initializing) {
|
||||
BOOST_CHECK_NO_THROW(ParserConstPtr parserConstPtr(new Parser()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParserAddKW) {
|
||||
Parser parser;
|
||||
{
|
||||
@ -53,5 +47,96 @@ BOOST_AUTO_TEST_CASE(ParserAddKW) {
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(hasKeyword_hasKeyword_returnstrue) {
|
||||
ParserPtr parser(new Parser());
|
||||
parser->addKW(ParserKWConstPtr(new ParserKW("FJAS")));
|
||||
BOOST_CHECK(parser->hasKeyword("FJAS"));
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(PrintToOStream_noThrow) {
|
||||
boost::filesystem::path singleKeywordFile("testdata/small.data");
|
||||
ParserPtr parser(new Parser());
|
||||
RawDeckPtr rawDeck = parser->readToRawDeck(singleKeywordFile.string());
|
||||
std::cout << *rawDeck << "\n";
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Parse_InvalidInputFile_Throws) {
|
||||
ParserPtr parser(new Parser());
|
||||
BOOST_CHECK_THROW(parser->readToRawDeck("nonexistingfile.asdf"), std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Parse_ValidInputFile_NoThrow) {
|
||||
boost::filesystem::path singleKeywordFile("testdata/small.data");
|
||||
ParserPtr parser(new Parser());
|
||||
|
||||
BOOST_CHECK_NO_THROW(parser->readToRawDeck(singleKeywordFile.string()));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParseFileWithOneKeyword) {
|
||||
|
||||
boost::filesystem::path singleKeywordFile("testdata/mini.data");
|
||||
ParserPtr parser(new Parser());
|
||||
|
||||
RawDeckPtr rawDeck = parser->readToRawDeck(singleKeywordFile.string());
|
||||
|
||||
BOOST_CHECK_EQUAL(1U, rawDeck->size());
|
||||
RawKeywordConstPtr rawKeyword = rawDeck->getKeyword(0);
|
||||
|
||||
BOOST_CHECK_EQUAL(1U, rawKeyword->size());
|
||||
RawRecordConstPtr record = rawKeyword->getRecord(rawKeyword->size() - 1);
|
||||
|
||||
const std::string& recordString = record->getRecordString();
|
||||
BOOST_CHECK_EQUAL("'NODIR' 'REVERS' 1 20", recordString);
|
||||
|
||||
BOOST_CHECK_EQUAL(4U, record->size());
|
||||
|
||||
BOOST_CHECK_EQUAL("NODIR", record->getItem(0));
|
||||
BOOST_CHECK_EQUAL("REVERS", record->getItem(1));
|
||||
BOOST_CHECK_EQUAL("1", record->getItem(2));
|
||||
BOOST_CHECK_EQUAL("20", record->getItem(3));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParseFileWithFewKeywords) {
|
||||
boost::filesystem::path singleKeywordFile("testdata/small.data");
|
||||
|
||||
ParserPtr parser(new Parser());
|
||||
|
||||
RawDeckPtr rawDeck = parser->readToRawDeck(singleKeywordFile.string());
|
||||
|
||||
BOOST_CHECK_EQUAL(7U, rawDeck->size());
|
||||
|
||||
RawKeywordConstPtr matchingKeyword = rawDeck->getKeyword(0);
|
||||
BOOST_CHECK_EQUAL("OIL", matchingKeyword->getKeywordName());
|
||||
BOOST_CHECK_EQUAL(0U, matchingKeyword->size());
|
||||
|
||||
// The two next come in via the include of the include path/readthis.sch file
|
||||
matchingKeyword = rawDeck->getKeyword(1);
|
||||
BOOST_CHECK_EQUAL("GRUPTREE", matchingKeyword->getKeywordName());
|
||||
BOOST_CHECK_EQUAL(2U, matchingKeyword->size());
|
||||
|
||||
matchingKeyword = rawDeck->getKeyword(2);
|
||||
BOOST_CHECK_EQUAL("WHISTCTL", matchingKeyword->getKeywordName());
|
||||
BOOST_CHECK_EQUAL(1U, matchingKeyword->size());
|
||||
|
||||
matchingKeyword = rawDeck->getKeyword(3);
|
||||
BOOST_CHECK_EQUAL("METRIC", matchingKeyword->getKeywordName());
|
||||
BOOST_CHECK_EQUAL(0U, matchingKeyword->size());
|
||||
|
||||
matchingKeyword = rawDeck->getKeyword(4);
|
||||
BOOST_CHECK_EQUAL("GRIDUNIT", matchingKeyword->getKeywordName());
|
||||
BOOST_CHECK_EQUAL(1U, matchingKeyword->size());
|
||||
|
||||
matchingKeyword = rawDeck->getKeyword(5);
|
||||
BOOST_CHECK_EQUAL("RADFIN4", matchingKeyword->getKeywordName());
|
||||
BOOST_CHECK_EQUAL(1U, matchingKeyword->size());
|
||||
|
||||
matchingKeyword = rawDeck->getKeyword(6);
|
||||
BOOST_CHECK_EQUAL("ABCDAD", matchingKeyword->getKeywordName());
|
||||
|
||||
BOOST_CHECK_EQUAL(2U, matchingKeyword->size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -35,47 +35,12 @@ using namespace Opm;
|
||||
//NOTE: needs statoil dataset
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParseFileWithManyKeywords) {
|
||||
boost::filesystem::path current = boost::filesystem::current_path();
|
||||
std::cout << "Current path: " << current.string() << "\n";
|
||||
|
||||
boost::filesystem::path multipleKeywordFile("testdata/statoil/gurbat_trimmed.DATA");
|
||||
std::cout << "BOOST path running ParseFullTestFile\n";
|
||||
|
||||
ParserPtr parser(new Parser());
|
||||
|
||||
RawDeckPtr rawDeck = parser->parse(multipleKeywordFile.string());
|
||||
RawDeckPtr rawDeck = parser->readToRawDeck(multipleKeywordFile.string());
|
||||
|
||||
//This check is not necessarily correct,
|
||||
//as it depends on that all the fixed recordNum keywords are specified
|
||||
BOOST_CHECK_EQUAL((unsigned) 275, rawDeck->getNumberOfKeywords());
|
||||
}
|
||||
|
||||
//NOTE: needs statoil dataset
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParseFullTestFile) {
|
||||
boost::filesystem::path multipleKeywordFile("testdata/statoil/ECLIPSE.DATA");
|
||||
|
||||
ParserPtr parser(new Parser());
|
||||
|
||||
RawDeckPtr rawDeck = parser->parse(multipleKeywordFile.string());
|
||||
// Note, cannot check the number of keywords, since the number of
|
||||
// records are not defined (yet) for all these keywords.
|
||||
// But we can check a copule of keywords, and that they have the correct
|
||||
// number of records
|
||||
|
||||
RawKeywordConstPtr matchingKeyword = rawDeck->getKeyword("OIL");
|
||||
std::list<RawRecordConstPtr> records = matchingKeyword->getRecords();
|
||||
BOOST_CHECK_EQUAL("OIL", matchingKeyword->getKeywordName());
|
||||
|
||||
BOOST_CHECK_EQUAL((unsigned) 0, records.size());
|
||||
|
||||
matchingKeyword = rawDeck->getKeyword("VFPPDIMS");
|
||||
records = matchingKeyword->getRecords();
|
||||
BOOST_CHECK_EQUAL("VFPPDIMS", matchingKeyword->getKeywordName());
|
||||
BOOST_CHECK_EQUAL((unsigned) 1, records.size());
|
||||
|
||||
const std::string& recordString = records.front()->getRecordString();
|
||||
BOOST_CHECK_EQUAL("20 20 15 15 15 50", recordString);
|
||||
std::deque<std::string> recordItems = records.front()->getItems();
|
||||
BOOST_CHECK_EQUAL((unsigned) 6, recordItems.size());
|
||||
BOOST_CHECK_EQUAL((unsigned) 275, rawDeck->size());
|
||||
}
|
||||
|
@ -28,101 +28,18 @@ namespace Opm {
|
||||
m_rawParserKWs = rawParserKWs;
|
||||
}
|
||||
|
||||
void RawDeck::addKeyword(RawKeywordConstPtr keyword) {
|
||||
m_keywords.push_back(keyword);
|
||||
}
|
||||
|
||||
RawKeywordConstPtr RawDeck::getKeyword(size_t index) const {
|
||||
return m_keywords.front();
|
||||
if (index < m_keywords.size())
|
||||
return m_keywords[index];
|
||||
else
|
||||
throw std::range_error("Index out of range");
|
||||
}
|
||||
|
||||
|
||||
/// Iterate through list of RawKeywords in search for the specified string.
|
||||
/// O(n), not using map or hash because the keywords are not unique,
|
||||
/// and the order matters. Returns first matching keyword.
|
||||
|
||||
RawKeywordConstPtr RawDeck::getKeyword(const std::string& keyword) const {
|
||||
for (std::list<RawKeywordConstPtr>::const_iterator it = m_keywords.begin(); it != m_keywords.end(); it++) {
|
||||
if ((*it)->getKeywordName() == keyword) {
|
||||
return (*it);
|
||||
}
|
||||
}
|
||||
throw std::invalid_argument("Keyword not found, keyword: " + keyword);
|
||||
}
|
||||
|
||||
bool RawDeck::hasKeyword(const std::string& keyword) const {
|
||||
for (std::list<RawKeywordConstPtr>::const_iterator it = m_keywords.begin(); it != m_keywords.end(); it++) {
|
||||
if ((*it)->getKeywordName() == keyword) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// The main data reading function, reads one and one keyword into the RawDeck
|
||||
/// If the INCLUDE keyword is found, the specified include file is inline read into the RawDeck.
|
||||
/// The data is read into a keyword, record by record, until the fixed number of records specified
|
||||
/// in the RawParserKW is met, or till a slash on a separate line is found.
|
||||
|
||||
void RawDeck::parse(const std::string& path) {
|
||||
boost::filesystem::path dataFolderPath = verifyValidInputPath(path);
|
||||
{
|
||||
std::ifstream inputstream;
|
||||
Logger::info("Initializing from file: " + path);
|
||||
inputstream.open(path.c_str());
|
||||
|
||||
std::string line;
|
||||
RawKeywordPtr currentRawKeyword;
|
||||
while (std::getline(inputstream, line)) {
|
||||
std::string keywordString;
|
||||
if (currentRawKeyword == NULL) {
|
||||
if (RawKeyword::tryParseKeyword(line, keywordString)) {
|
||||
currentRawKeyword = RawKeywordPtr(new RawKeyword(keywordString));
|
||||
if (isKeywordFinished(currentRawKeyword)) {
|
||||
addKeyword(currentRawKeyword, dataFolderPath);
|
||||
currentRawKeyword.reset();
|
||||
}
|
||||
}
|
||||
} else if (currentRawKeyword != NULL && RawKeyword::lineContainsData(line)) {
|
||||
currentRawKeyword->addRawRecordString(line);
|
||||
if (isKeywordFinished(currentRawKeyword)) {
|
||||
addKeyword(currentRawKeyword, dataFolderPath);
|
||||
currentRawKeyword.reset();
|
||||
}
|
||||
} else if (currentRawKeyword != NULL && RawKeyword::lineTerminatesKeyword(line)) {
|
||||
if (!currentRawKeyword->isPartialRecordStringEmpty()) {
|
||||
Logger::error("Reached keyword terminator slash, but there is non-terminated data on current keyword. "
|
||||
"Adding terminator, but records should be terminated by slash in data file");
|
||||
currentRawKeyword->addRawRecordString(std::string(1, Opm::RawConsts::slash));
|
||||
}
|
||||
addKeyword(currentRawKeyword, dataFolderPath);
|
||||
currentRawKeyword.reset();
|
||||
}
|
||||
}
|
||||
inputstream.close();
|
||||
}
|
||||
}
|
||||
|
||||
void RawDeck::addKeyword(RawKeywordConstPtr keyword, const boost::filesystem::path& dataFolderPath) {
|
||||
if (keyword->getKeywordName() == Opm::RawConsts::include) {
|
||||
RawRecordConstPtr firstRecord = keyword->getRecord(0);
|
||||
std::string includeFileString = firstRecord->getItem(0);
|
||||
boost::filesystem::path pathToIncludedFile(dataFolderPath);
|
||||
pathToIncludedFile /= includeFileString;
|
||||
|
||||
parse(pathToIncludedFile.string());
|
||||
} else {
|
||||
m_keywords.push_back(keyword);
|
||||
}
|
||||
}
|
||||
|
||||
boost::filesystem::path RawDeck::verifyValidInputPath(const std::string& inputPath) {
|
||||
Logger::info("Verifying path: " + inputPath);
|
||||
boost::filesystem::path pathToInputFile(inputPath);
|
||||
if (!boost::filesystem::is_regular_file(pathToInputFile)) {
|
||||
Logger::error("Unable to open file with path: " + inputPath);
|
||||
throw std::invalid_argument("Given path is not a valid file-path, path: " + inputPath);
|
||||
}
|
||||
return pathToInputFile.parent_path();
|
||||
}
|
||||
|
||||
unsigned int RawDeck::getNumberOfKeywords() const {
|
||||
size_t RawDeck::size() const {
|
||||
return m_keywords.size();
|
||||
}
|
||||
|
||||
@ -137,13 +54,12 @@ namespace Opm {
|
||||
}
|
||||
|
||||
/// Operator overload to write the content of the RawDeck to an ostream
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const RawDeck& deck) {
|
||||
for (std::list<RawKeywordConstPtr>::const_iterator keyword = deck.m_keywords.begin(); keyword != deck.m_keywords.end(); keyword++) {
|
||||
os << (*keyword)->getKeywordName() << " -- Keyword\n";
|
||||
|
||||
for (size_t i = 0; i < (*keyword)->size(); i++) {
|
||||
RawRecordConstPtr rawRecord = (*keyword)->getRecord(i);
|
||||
for (size_t i = 0; i < deck.size(); i++) {
|
||||
RawKeywordConstPtr keyword = deck.getKeyword(i);
|
||||
os << keyword->getKeywordName() << " -- Keyword\n";
|
||||
for (size_t i = 0; i < keyword->size(); i++) {
|
||||
RawRecordConstPtr rawRecord = keyword->getRecord(i);
|
||||
for (size_t j = 0; j < rawRecord->size(); j++) {
|
||||
os << rawRecord->getItem(j) << " ";
|
||||
}
|
||||
|
@ -19,14 +19,12 @@
|
||||
|
||||
#ifndef RAWDECK_HPP
|
||||
#define RAWDECK_HPP
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <ostream>
|
||||
#include <map>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include "opm/parser/eclipse/Logger/Logger.hpp"
|
||||
#include <boost/filesystem.hpp>
|
||||
#include "RawKeyword.hpp"
|
||||
#include "RawParserKWs.hpp"
|
||||
#include <opm/parser/eclipse/RawDeck/RawKeyword.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawParserKWs.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
@ -42,25 +40,25 @@ namespace Opm {
|
||||
/// All relevant keywords with a fixed number of records
|
||||
/// must be specified through the RawParserKW class. This is to be able to know how the records
|
||||
/// of the keyword is structured.
|
||||
RawDeck(RawParserKWsConstPtr rawParserKWs);
|
||||
|
||||
void parse(const std::string& path);
|
||||
RawKeywordConstPtr getKeyword(const std::string& keyword) const;
|
||||
RawKeywordConstPtr getKeyword(size_t index) const;
|
||||
|
||||
bool hasKeyword(const std::string& keyword) const;
|
||||
unsigned int getNumberOfKeywords() const;
|
||||
RawDeck(RawParserKWsConstPtr rawParserKWs);
|
||||
void addKeyword(RawKeywordConstPtr keyword);
|
||||
RawKeywordConstPtr getKeyword(size_t index) const;
|
||||
size_t size() const;
|
||||
|
||||
// This will move to Parser class when m_rawParserKWs is moved.
|
||||
bool isKeywordFinished(RawKeywordConstPtr rawKeyword);
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, const RawDeck& deck);
|
||||
virtual ~RawDeck();
|
||||
|
||||
|
||||
private:
|
||||
std::list<RawKeywordConstPtr> m_keywords;
|
||||
std::vector<RawKeywordConstPtr> m_keywords;
|
||||
|
||||
// This variable should be replaced by an equivalent collection of ParserKWs, and put in the Parser class
|
||||
RawParserKWsConstPtr m_rawParserKWs;
|
||||
|
||||
//void readDataIntoDeck(const std::string& path, std::list<RawKeywordConstPtr>& keywordList);
|
||||
void addKeyword(RawKeywordConstPtr keyword, const boost::filesystem::path& baseDataFolder);
|
||||
bool isKeywordFinished(RawKeywordConstPtr rawKeyword);
|
||||
void processIncludeKeyword(RawKeywordConstPtr keyword, const boost::filesystem::path& dataFolderPath);
|
||||
static boost::filesystem::path verifyValidInputPath(const std::string& inputPath);
|
||||
};
|
||||
|
||||
|
@ -67,7 +67,6 @@ namespace Opm {
|
||||
}
|
||||
|
||||
bool RawKeyword::isValidKeyword(const std::string& keywordCandidate) {
|
||||
|
||||
std::string keywordRegex = "^[A-Z][A-Z,0-9]{1,7}$";
|
||||
int status;
|
||||
regex_t regularExpression;
|
||||
|
@ -43,8 +43,6 @@ namespace Opm {
|
||||
size_t size() const;
|
||||
RawRecordPtr getRecord(size_t index) const;
|
||||
|
||||
|
||||
|
||||
static bool tryParseKeyword(const std::string& line, std::string& result);
|
||||
static bool lineContainsData(const std::string& line);
|
||||
static bool lineTerminatesKeyword(const std::string& line);
|
||||
|
@ -59,6 +59,7 @@ namespace Opm {
|
||||
add(std::pair<std::string, unsigned int>("WHISTCTL", 1));
|
||||
|
||||
|
||||
add(std::pair<std::string, unsigned int>("SUMMARY", 0));
|
||||
add(std::pair<std::string, unsigned int>("TITLE", 0));
|
||||
add(std::pair<std::string, unsigned int>("RUNSPEC", 0));
|
||||
add(std::pair<std::string, unsigned int>("METRIC", 0));
|
||||
|
@ -1,22 +1,14 @@
|
||||
add_executable(runRawRecordTests RawRecordTests.cpp)
|
||||
add_executable(runRawKeywordTests RawKeywordTests.cpp)
|
||||
add_executable(runRawDeckTests RawDeckTests.cpp)
|
||||
add_executable(runRawDeckInternalDataTests RawDeckInternalDataTests.cpp)
|
||||
add_executable(runRawParserKWsTests RawParserKWsTests.cpp)
|
||||
|
||||
target_link_libraries(runRawRecordTests Parser ${Boost_LIBRARIES})
|
||||
target_link_libraries(runRawKeywordTests Parser ${Boost_LIBRARIES})
|
||||
target_link_libraries(runRawDeckTests Parser ${Boost_LIBRARIES})
|
||||
target_link_libraries(runRawDeckInternalDataTests Parser ${Boost_LIBRARIES})
|
||||
target_link_libraries(runRawParserKWsTests Parser ${Boost_LIBRARIES})
|
||||
|
||||
add_test(NAME runRawRecordTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runRawRecordTests )
|
||||
|
||||
add_test(NAME runRawKeywordTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runRawKeywordTests )
|
||||
|
||||
add_test(NAME runRawDeckTests WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} COMMAND runRawDeckTests )
|
||||
|
||||
add_test(NAME runRawDeckInternalDataTests WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} COMMAND runRawDeckInternalDataTests )
|
||||
set_tests_properties(runRawDeckInternalDataTests PROPERTIES LABEL Statoil)
|
||||
|
||||
add_test(NAME runRawParserKWsTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runRawParserKWsTests )
|
||||
|
@ -1,72 +0,0 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#define BOOST_TEST_MODULE ParserTestsInternalData
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
|
||||
#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>
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
using namespace Opm;
|
||||
|
||||
//NOTE: needs statoil dataset
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParseFileWithManyKeywords) {
|
||||
boost::filesystem::path multipleKeywordFile("testdata/statoil/gurbat_trimmed.DATA");
|
||||
|
||||
RawDeckPtr rawDeck(new RawDeck(RawParserKWsConstPtr(new RawParserKWs())));
|
||||
rawDeck->parse(multipleKeywordFile.string());
|
||||
|
||||
//This check is not necessarily correct,
|
||||
//as it depends on that all the fixed recordNum keywords are specified
|
||||
BOOST_CHECK_EQUAL((unsigned) 275, rawDeck->getNumberOfKeywords());
|
||||
}
|
||||
|
||||
//NOTE: needs statoil dataset
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParseFullTestFile) {
|
||||
boost::filesystem::path multipleKeywordFile("testdata/statoil/ECLIPSE.DATA");
|
||||
|
||||
RawDeckPtr rawDeck(new RawDeck(RawParserKWsConstPtr(new RawParserKWs())));
|
||||
rawDeck->parse(multipleKeywordFile.string());
|
||||
|
||||
// Note, cannot check the number of keywords, since the number of
|
||||
// records are not defined (yet) for all these keywords.
|
||||
// But we can check a copule of keywords, and that they have the correct
|
||||
// number of records
|
||||
|
||||
RawKeywordConstPtr matchingKeyword = rawDeck->getKeyword("OIL");
|
||||
BOOST_CHECK_EQUAL("OIL", matchingKeyword->getKeywordName());
|
||||
BOOST_CHECK_EQUAL(0U, matchingKeyword->size());
|
||||
|
||||
matchingKeyword = rawDeck->getKeyword("VFPPDIMS");
|
||||
BOOST_CHECK_EQUAL("VFPPDIMS", matchingKeyword->getKeywordName());
|
||||
BOOST_CHECK_EQUAL((unsigned) 1, matchingKeyword->size());
|
||||
|
||||
const std::string& recordString = matchingKeyword->getRecord(0)->getRecordString();
|
||||
BOOST_CHECK_EQUAL("20 20 15 15 15 50", recordString);
|
||||
BOOST_CHECK_EQUAL((unsigned) 6, matchingKeyword->getRecord(0)->size());
|
||||
}
|
@ -27,6 +27,8 @@
|
||||
#include <opm/parser/eclipse/RawDeck/RawKeyword.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
|
||||
#include "opm/parser/eclipse/Parser/Parser.hpp"
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Initialize_NoThrow) {
|
||||
@ -34,110 +36,33 @@ BOOST_AUTO_TEST_CASE(Initialize_NoThrow) {
|
||||
BOOST_CHECK_NO_THROW(RawDeck rawDeck(fixedKeywords));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(getKeyword_byIndex_keywordReturned) {
|
||||
RawParserKWsConstPtr fixedKeywords(new RawParserKWs());
|
||||
RawDeck rawDeck(fixedKeywords);
|
||||
rawDeck.parse("testdata/small.data");
|
||||
RawKeywordConstPtr rawKeyword = rawDeck.getKeyword(0U);
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(GetNumberOfKeywords_EmptyDeck_RetunsZero) {
|
||||
RawParserKWsConstPtr fixedKeywords(new RawParserKWs());
|
||||
RawDeckPtr rawDeck(new RawDeck(fixedKeywords));
|
||||
BOOST_CHECK_EQUAL((unsigned) 0, rawDeck->getNumberOfKeywords());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(HasKeyword_NotExisting_RetunsFalse) {
|
||||
RawParserKWsConstPtr fixedKeywords(new RawParserKWs());
|
||||
RawDeckPtr rawDeck(new RawDeck(fixedKeywords));
|
||||
BOOST_CHECK_EQUAL(false, rawDeck->hasKeyword("TEST"));
|
||||
BOOST_CHECK_EQUAL((unsigned) 0, rawDeck->size());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(GetKeyword_EmptyDeck_ThrowsExeption) {
|
||||
RawParserKWsConstPtr fixedKeywords(new RawParserKWs());
|
||||
RawDeckPtr rawDeck(new RawDeck(fixedKeywords));
|
||||
BOOST_CHECK_THROW(rawDeck->getKeyword("TEST"), std::invalid_argument);
|
||||
BOOST_CHECK_THROW(rawDeck->getKeyword(0), std::range_error);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(PrintToOStream_noThrow) {
|
||||
boost::filesystem::path singleKeywordFile("testdata/small.data");
|
||||
|
||||
|
||||
RawDeckPtr rawDeck(new RawDeck(RawParserKWsConstPtr(new RawParserKWs())));
|
||||
rawDeck->parse(singleKeywordFile.string());
|
||||
std::cout << *rawDeck << "\n";
|
||||
BOOST_AUTO_TEST_CASE(addKeyword_withkeywords_keywordAdded) {
|
||||
RawParserKWsConstPtr fixedKeywords(new RawParserKWs());
|
||||
RawDeckPtr rawDeck(new RawDeck(fixedKeywords));
|
||||
|
||||
RawKeywordPtr keyword(new RawKeyword("BJARNE"));
|
||||
rawDeck->addKeyword(keyword);
|
||||
BOOST_CHECK_EQUAL(keyword, rawDeck->getKeyword(0));
|
||||
|
||||
RawKeywordPtr keyword2(new RawKeyword("BJARNE2"));
|
||||
rawDeck->addKeyword(keyword2);
|
||||
BOOST_CHECK_EQUAL(keyword2, rawDeck->getKeyword(1));
|
||||
|
||||
BOOST_CHECK_EQUAL(2U, rawDeck->size());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Parse_InvalidInputFile_Throws) {
|
||||
RawDeckPtr rawDeck(new RawDeck(RawParserKWsConstPtr(new RawParserKWs())));
|
||||
BOOST_CHECK_THROW(rawDeck->parse("nonexistingfile.asdf"), std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Parse_ValidInputFile_NoThrow) {
|
||||
boost::filesystem::path singleKeywordFile("testdata/small.data");
|
||||
RawDeckPtr rawDeck(new RawDeck(RawParserKWsConstPtr(new RawParserKWs())));
|
||||
BOOST_CHECK_NO_THROW(rawDeck->parse(singleKeywordFile.string()));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParseFileWithOneKeyword) {
|
||||
boost::filesystem::path singleKeywordFile("testdata/mini.data");
|
||||
|
||||
RawDeckPtr rawDeck(new RawDeck(RawParserKWsConstPtr(new RawParserKWs())));
|
||||
rawDeck->parse(singleKeywordFile.string());
|
||||
|
||||
BOOST_CHECK_EQUAL((unsigned) 1, rawDeck->getNumberOfKeywords());
|
||||
RawKeywordConstPtr rawKeyword = rawDeck->getKeyword("ENDSCALE");
|
||||
|
||||
BOOST_CHECK_EQUAL(1U, rawKeyword->size());
|
||||
RawRecordConstPtr record = rawKeyword->getRecord(rawKeyword->size() - 1);
|
||||
|
||||
const std::string& recordString = record->getRecordString();
|
||||
BOOST_CHECK_EQUAL("'NODIR' 'REVERS' 1 20", recordString);
|
||||
|
||||
BOOST_CHECK_EQUAL((unsigned) 4, record->size());
|
||||
|
||||
BOOST_CHECK_EQUAL("NODIR", record->getItem(0));
|
||||
BOOST_CHECK_EQUAL("REVERS", record->getItem(1));
|
||||
BOOST_CHECK_EQUAL("1", record->getItem(2));
|
||||
BOOST_CHECK_EQUAL("20", record->getItem(3));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParseFileWithFewKeywords) {
|
||||
boost::filesystem::path singleKeywordFile("testdata/small.data");
|
||||
|
||||
RawDeckPtr rawDeck(new RawDeck(RawParserKWsConstPtr(new RawParserKWs())));
|
||||
rawDeck->parse(singleKeywordFile.string());
|
||||
|
||||
BOOST_CHECK_EQUAL((unsigned) 7, rawDeck->getNumberOfKeywords());
|
||||
|
||||
RawKeywordConstPtr matchingKeyword = rawDeck->getKeyword("OIL");
|
||||
BOOST_CHECK_EQUAL("OIL", matchingKeyword->getKeywordName());
|
||||
BOOST_CHECK_EQUAL(0U, matchingKeyword->size());
|
||||
|
||||
// The two next come in via the include of the include path/readthis.sch file
|
||||
matchingKeyword = rawDeck->getKeyword("GRUPTREE");
|
||||
BOOST_CHECK_EQUAL("GRUPTREE", matchingKeyword->getKeywordName());
|
||||
BOOST_CHECK_EQUAL((unsigned) 2, matchingKeyword->size());
|
||||
|
||||
matchingKeyword = rawDeck->getKeyword("WHISTCTL");
|
||||
BOOST_CHECK_EQUAL("WHISTCTL", matchingKeyword->getKeywordName());
|
||||
BOOST_CHECK_EQUAL((unsigned) 1, matchingKeyword->size());
|
||||
|
||||
matchingKeyword = rawDeck->getKeyword("METRIC");
|
||||
BOOST_CHECK_EQUAL("METRIC", matchingKeyword->getKeywordName());
|
||||
BOOST_CHECK_EQUAL((unsigned) 0, matchingKeyword->size());
|
||||
|
||||
matchingKeyword = rawDeck->getKeyword("GRIDUNIT");
|
||||
BOOST_CHECK_EQUAL("GRIDUNIT", matchingKeyword->getKeywordName());
|
||||
BOOST_CHECK_EQUAL((unsigned) 1, matchingKeyword->size());
|
||||
|
||||
matchingKeyword = rawDeck->getKeyword("RADFIN4");
|
||||
BOOST_CHECK_EQUAL("RADFIN4", matchingKeyword->getKeywordName());
|
||||
BOOST_CHECK_EQUAL((unsigned) 1, matchingKeyword->size());
|
||||
|
||||
matchingKeyword = rawDeck->getKeyword("ABCDAD");
|
||||
BOOST_CHECK_EQUAL("ABCDAD", matchingKeyword->getKeywordName());
|
||||
|
||||
BOOST_CHECK_EQUAL((unsigned) 2, matchingKeyword->size());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user