diff --git a/opm/parser/eclipse/CMakeLists.txt b/opm/parser/eclipse/CMakeLists.txt index 9dd812838..9e389cf1f 100644 --- a/opm/parser/eclipse/CMakeLists.txt +++ b/opm/parser/eclipse/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(Parser RawDeck/RawDeck.cpp RawDeck/RawKeyword.cpp RawDeck/RawRecord.cpp Parser/Parser.cpp Parser/ParserRecordSize.cpp Parser/ParserKW.cpp) +add_library(Parser RawDeck/RawDeck.cpp RawDeck/RawKeyword.cpp RawDeck/RawRecord.cpp RawDeck/RawParserKWs.cpp Parser/Parser.cpp Parser/ParserRecordSize.cpp Parser/ParserKW.cpp) add_library(Logger Logger.cpp) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/opm/parser/eclipse/Parser/Parser.cpp b/opm/parser/eclipse/Parser/Parser.cpp index 60a5bf843..aa9aef2af 100644 --- a/opm/parser/eclipse/Parser/Parser.cpp +++ b/opm/parser/eclipse/Parser/Parser.cpp @@ -17,53 +17,24 @@ along with OPM. If not, see . */ #include "Parser.hpp" +#include "RawDeck/RawParserKWs.hpp" namespace Opm { Parser::Parser() { - initializeFixedKeywordLenghts(); - } RawDeckPtr Parser::parse(const std::string &path) { Logger::initLogger(); Logger::setLogLevel(Logger::DEBUG); Logger::info("Starting parsing of file: " + path); - RawDeckPtr rawDeck(new RawDeck(m_keywordRecordLengths)); + RawDeckPtr rawDeck(new RawDeck(RawParserKWsConstPtr(new RawParserKWs()))); rawDeck->readDataIntoDeck(path); Logger::info("Done parsing of file: " + path); return rawDeck; } - void Parser::initializeFixedKeywordLenghts() { - m_keywordRecordLengths.insert(std::pair("GRIDUNIT", 1)); - m_keywordRecordLengths.insert(std::pair("INCLUDE", 1)); - m_keywordRecordLengths.insert(std::pair("RADFIN4", 1)); - m_keywordRecordLengths.insert(std::pair("DIMENS", 1)); - m_keywordRecordLengths.insert(std::pair("START", 1)); - m_keywordRecordLengths.insert(std::pair("GRIDOPTS", 1)); - m_keywordRecordLengths.insert(std::pair("ENDSCALE", 1)); - m_keywordRecordLengths.insert(std::pair("EQLOPTS", 1)); - m_keywordRecordLengths.insert(std::pair("TABDIMS", 1)); - m_keywordRecordLengths.insert(std::pair("EQLDIMS", 1)); - m_keywordRecordLengths.insert(std::pair("REGDIMS", 1)); - m_keywordRecordLengths.insert(std::pair("FAULTDIM", 1)); - m_keywordRecordLengths.insert(std::pair("WELLDIMS", 1)); - m_keywordRecordLengths.insert(std::pair("VFPPDIMS", 1)); - m_keywordRecordLengths.insert(std::pair("RPTSCHED", 1)); - m_keywordRecordLengths.insert(std::pair("TITLE", 0)); - m_keywordRecordLengths.insert(std::pair("RUNSPEC", 0)); - m_keywordRecordLengths.insert(std::pair("METRIC", 0)); - m_keywordRecordLengths.insert(std::pair("SCHEDULE", 0)); - m_keywordRecordLengths.insert(std::pair("SKIPREST", 0)); - m_keywordRecordLengths.insert(std::pair("NOECHO", 0)); - m_keywordRecordLengths.insert(std::pair("END", 0)); - m_keywordRecordLengths.insert(std::pair("OIL", 0)); - m_keywordRecordLengths.insert(std::pair("GAS", 0)); - m_keywordRecordLengths.insert(std::pair("WATER", 0)); - m_keywordRecordLengths.insert(std::pair("DISGAS", 0)); - m_keywordRecordLengths.insert(std::pair("VAPOIL", 0)); - } + Parser::~Parser() { } diff --git a/opm/parser/eclipse/Parser/Parser.hpp b/opm/parser/eclipse/Parser/Parser.hpp index b41c34f1d..67a5d85c7 100644 --- a/opm/parser/eclipse/Parser/Parser.hpp +++ b/opm/parser/eclipse/Parser/Parser.hpp @@ -36,8 +36,6 @@ namespace Opm { RawDeckPtr parse(const std::string &path); virtual ~Parser(); private: - std::map m_keywordRecordLengths; - void initializeFixedKeywordLenghts(); }; typedef boost::shared_ptr ParserPtr; diff --git a/opm/parser/eclipse/RawDeck/RawDeck.cpp b/opm/parser/eclipse/RawDeck/RawDeck.cpp index fcb2d55fd..ad607d2ba 100644 --- a/opm/parser/eclipse/RawDeck/RawDeck.cpp +++ b/opm/parser/eclipse/RawDeck/RawDeck.cpp @@ -23,8 +23,8 @@ namespace Opm { - RawDeck::RawDeck(std::map& keywordsWithFixedRecordNums) { - m_keywordsWithFixedRecordNums = keywordsWithFixedRecordNums; + RawDeck::RawDeck(RawParserKWsConstPtr rawParserKWs) { + m_rawParserKWs = rawParserKWs; } /* @@ -94,8 +94,8 @@ namespace Opm { } bool RawDeck::isKeywordFinished(RawKeywordPtr rawKeyword) { - if ((unsigned)m_keywordsWithFixedRecordNums.count(rawKeyword->getKeyword()) != 0) { - return rawKeyword->getNumberOfRecords() == (unsigned)m_keywordsWithFixedRecordNums[rawKeyword->getKeyword()]; + if (m_rawParserKWs->keywordExists(rawKeyword->getKeyword())) { + return rawKeyword->getNumberOfRecords() == m_rawParserKWs->getFixedNumberOfRecords(rawKeyword->getKeyword()); } return false; } @@ -103,11 +103,10 @@ namespace Opm { std::ostream& operator<<(std::ostream& os, const RawDeck& deck) { for (std::list::const_iterator keyword = deck.m_keywords.begin(); keyword != deck.m_keywords.end(); keyword++) { os << (*keyword)->getKeyword() << " -- Keyword\n"; - std::list records; - (*keyword)->getRecords(records); + + std::list records = (*keyword)->getRecords(); for (std::list::const_iterator record = records.begin(); record != records.end(); record++) { - std::vector recordItems; - (*record)->getRecords(recordItems); + std::vector recordItems = (*record)->getRecords(); for (std::vector::const_iterator recordItem = recordItems.begin(); recordItem != recordItems.end(); recordItem++) { os << (*recordItem) << " "; diff --git a/opm/parser/eclipse/RawDeck/RawDeck.hpp b/opm/parser/eclipse/RawDeck/RawDeck.hpp index 03b4611ae..694fc691f 100644 --- a/opm/parser/eclipse/RawDeck/RawDeck.hpp +++ b/opm/parser/eclipse/RawDeck/RawDeck.hpp @@ -25,12 +25,13 @@ #include #include "opm/parser/eclipse/Logger.hpp" #include "RawKeyword.hpp" +#include "RawParserKWs.hpp" namespace Opm { class RawDeck { public: - RawDeck(std::map& keywordsWithFixedRecordNums); + RawDeck(RawParserKWsConstPtr rawParserKWs); void readDataIntoDeck(const std::string& path); RawKeywordPtr getKeyword(const std::string& keyword); unsigned int getNumberOfKeywords(); @@ -38,7 +39,7 @@ namespace Opm { virtual ~RawDeck(); private: std::list m_keywords; - std::map m_keywordsWithFixedRecordNums; + RawParserKWsConstPtr m_rawParserKWs; void readDataIntoDeck(const std::string& path, std::list& keywordList); bool isKeywordFinished(RawKeywordPtr rawKeyword); static void verifyValidInputPath(const std::string& inputPath); diff --git a/opm/parser/eclipse/RawDeck/RawKeyword.cpp b/opm/parser/eclipse/RawDeck/RawKeyword.cpp index 6f12b4402..672abd192 100644 --- a/opm/parser/eclipse/RawDeck/RawKeyword.cpp +++ b/opm/parser/eclipse/RawDeck/RawKeyword.cpp @@ -102,11 +102,11 @@ namespace Opm { return m_records.size(); } - void RawKeyword::getRecords(std::list& records) { - records = m_records; + const std::list& RawKeyword::getRecords() const{ + return m_records; } - std::string RawKeyword::getKeyword() { + std::string RawKeyword::getKeyword() const{ return m_keyword; } diff --git a/opm/parser/eclipse/RawDeck/RawKeyword.hpp b/opm/parser/eclipse/RawDeck/RawKeyword.hpp index 84a1fddca..24b750d5d 100644 --- a/opm/parser/eclipse/RawDeck/RawKeyword.hpp +++ b/opm/parser/eclipse/RawDeck/RawKeyword.hpp @@ -38,8 +38,8 @@ namespace Opm { static bool lineContainsData(const std::string& line); static bool lineTerminatesKeyword(const std::string& line); - std::string getKeyword(); - void getRecords(std::list& records); + std::string getKeyword() const; + const std::list& getRecords() const; unsigned int getNumberOfRecords(); void setKeyword(const std::string& keyword); void addRawRecordString(const std::string& partialRecordString); @@ -52,6 +52,8 @@ namespace Opm { static bool isValidKeyword(const std::string& keywordCandidate); }; typedef boost::shared_ptr RawKeywordPtr; + typedef boost::shared_ptr RawKeywordConstPtr; + } #endif /* RAWKEYWORD_HPP */ diff --git a/opm/parser/eclipse/RawDeck/RawParserKWs.cpp b/opm/parser/eclipse/RawDeck/RawParserKWs.cpp new file mode 100644 index 000000000..0f43c780e --- /dev/null +++ b/opm/parser/eclipse/RawDeck/RawParserKWs.cpp @@ -0,0 +1,76 @@ +/* + 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 . + */ +#include +#include "RawParserKWs.hpp" + +namespace Opm { + + RawParserKWs::RawParserKWs() { + initializeFixedKeywordLenghts(); + } + + bool RawParserKWs::keywordExists(const std::string& keyword) const { + return m_keywordRecordLengths.find(keyword) != m_keywordRecordLengths.end(); + } + + unsigned int RawParserKWs::getFixedNumberOfRecords(const std::string& keyword) const { + if (keywordExists(keyword)) { + return m_keywordRecordLengths.find(keyword) -> second; + } else + throw std::invalid_argument("Given keyword is not found, offending keyword: " + keyword); + } + + void RawParserKWs::add(std::pair keywordAndNumRecords) { + m_keywordRecordLengths.insert(keywordAndNumRecords); + } + + void RawParserKWs::initializeFixedKeywordLenghts() { + add(std::pair("GRIDUNIT", 1)); + add(std::pair("INCLUDE", 1)); + add(std::pair("RADFIN4", 1)); + add(std::pair("DIMENS", 1)); + add(std::pair("START", 1)); + add(std::pair("GRIDOPTS", 1)); + add(std::pair("ENDSCALE", 1)); + add(std::pair("EQLOPTS", 1)); + add(std::pair("TABDIMS", 1)); + add(std::pair("EQLDIMS", 1)); + add(std::pair("REGDIMS", 1)); + add(std::pair("FAULTDIM", 1)); + add(std::pair("WELLDIMS", 1)); + add(std::pair("VFPPDIMS", 1)); + add(std::pair("RPTSCHED", 1)); + add(std::pair("TITLE", 0)); + add(std::pair("RUNSPEC", 0)); + add(std::pair("METRIC", 0)); + add(std::pair("SCHEDULE", 0)); + add(std::pair("SKIPREST", 0)); + add(std::pair("NOECHO", 0)); + add(std::pair("END", 0)); + add(std::pair("OIL", 0)); + add(std::pair("GAS", 0)); + add(std::pair("WATER", 0)); + add(std::pair("DISGAS", 0)); + add(std::pair("VAPOIL", 0)); + } + + RawParserKWs::~RawParserKWs() { + } +} + diff --git a/opm/parser/eclipse/RawDeck/RawParserKWs.hpp b/opm/parser/eclipse/RawDeck/RawParserKWs.hpp new file mode 100644 index 000000000..6eae5304c --- /dev/null +++ b/opm/parser/eclipse/RawDeck/RawParserKWs.hpp @@ -0,0 +1,32 @@ +/* + * File: RawParserKW.h + * Author: kflik + * + * Created on April 4, 2013, 12:12 PM + */ + +#ifndef RAWPARSERKW_H +#define RAWPARSERKW_H + +#include +#include +#include +namespace Opm { + + class RawParserKWs { + public: + RawParserKWs(); + bool keywordExists(const std::string& keyword) const; + unsigned int getFixedNumberOfRecords(const std::string& keyword) const; + virtual ~RawParserKWs(); + private: + std::map m_keywordRecordLengths; + void initializeFixedKeywordLenghts(); + void add(std::pair keywordAndNumRecords); + + }; + typedef boost::shared_ptr RawParserKWsConstPtr; + +} +#endif /* RAWPARSERKW_H */ + diff --git a/opm/parser/eclipse/RawDeck/RawRecord.cpp b/opm/parser/eclipse/RawDeck/RawRecord.cpp index e9b7ee62d..27dab0358 100644 --- a/opm/parser/eclipse/RawDeck/RawRecord.cpp +++ b/opm/parser/eclipse/RawDeck/RawRecord.cpp @@ -47,10 +47,25 @@ namespace Opm { throw std::invalid_argument("Input string is not a complete record string," " offending string: " + singleRecordString); } - splitSingleRecordString(); } + const std::vector& RawRecord::getRecords() const { + return m_recordItems; + } + + const std::string& RawRecord::getRecordString() const { + return m_sanitizedRecordString; + } + + bool RawRecord::isCompleteRecordString(const std::string& candidateRecordString) { + unsigned int terminatingSlash = findTerminatingSlash(candidateRecordString); + bool hasTerminatingSlash = (terminatingSlash < candidateRecordString.size()); + int size = std::count(candidateRecordString.begin(), candidateRecordString.end(), QUOTE); + bool hasEvenNumberOfQuotes = (size % 2) == 0; + return hasTerminatingSlash && hasEvenNumberOfQuotes; + } + void RawRecord::splitSingleRecordString() { char currentChar; char tokenStartCharacter; @@ -70,7 +85,7 @@ namespace Opm { currentToken.clear(); } } - + void RawRecord::processSeparatorCharacter(std::string& currentToken, const char& currentChar, char& tokenStartCharacter) { if (tokenStartCharacter == QUOTE) { currentToken += currentChar; @@ -86,7 +101,7 @@ namespace Opm { void RawRecord::processQuoteCharacters(std::string& currentToken, const char& currentChar, char& tokenStartCharacter) { if (currentChar == tokenStartCharacter) { if (currentToken.size() > 0) { - m_recordItems.push_back("'"+currentToken+"'"); //Adding quotes, not sure what is best. + m_recordItems.push_back("'" + currentToken + "'"); //Adding quotes, not sure what is best. currentToken.clear(); } tokenStartCharacter = '\0'; @@ -104,22 +119,6 @@ namespace Opm { return std::string::npos != SEPARATORS.find(candidate); } - void RawRecord::getRecords(std::vector& recordItems) { - recordItems = m_recordItems; - } - - void RawRecord::getRecordString(std::string& recordString) { - recordString = m_sanitizedRecordString; - } - - bool RawRecord::isCompleteRecordString(const std::string& candidateRecordString) { - unsigned int terminatingSlash = findTerminatingSlash(candidateRecordString); - bool hasTerminatingSlash = (terminatingSlash < candidateRecordString.size()); - int size = std::count(candidateRecordString.begin(), candidateRecordString.end(), QUOTE); - bool hasEvenNumberOfQuotes = (size % 2) == 0; - return hasTerminatingSlash && hasEvenNumberOfQuotes; - } - void RawRecord::setRecordString(const std::string& singleRecordString) { unsigned terminatingSlash = findTerminatingSlash(singleRecordString); m_sanitizedRecordString = singleRecordString.substr(0, terminatingSlash); diff --git a/opm/parser/eclipse/RawDeck/RawRecord.hpp b/opm/parser/eclipse/RawDeck/RawRecord.hpp index 36b9e34ba..01e77dcdd 100644 --- a/opm/parser/eclipse/RawDeck/RawRecord.hpp +++ b/opm/parser/eclipse/RawDeck/RawRecord.hpp @@ -34,8 +34,8 @@ namespace Opm { RawRecord(); RawRecord(const std::string& singleRecordString); - void getRecordString(std::string& recordString); - void getRecords(std::vector& recordItems); + const std::string& getRecordString() const; + const std::vector& getRecords() const; static bool isCompleteRecordString(const std::string& candidateRecordString); virtual ~RawRecord(); private: diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0fd8e1f73..67bb03f5e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,6 +1,9 @@ add_executable(runParserTests ParserTests.cpp) + add_executable(runRawDataTests RawDataStructuresTests.cpp) add_executable(runRawDeckTests RawDeckTests.cpp) +add_executable(runRawParserKWsTests RawParserKWsTests.cpp) + add_executable(runParserKWTests ParserKWTests.cpp) add_executable(runParserRecordSizeTests ParserRecordSizeTests.cpp) @@ -9,6 +12,7 @@ add_executable(runParserRecordSizeTests ParserRecordSizeTests.cpp) target_link_libraries(runParserTests Parser Logger ${Boost_LIBRARIES}) target_link_libraries(runRawDataTests Parser Logger ${Boost_LIBRARIES}) target_link_libraries(runRawDeckTests Parser Logger ${Boost_LIBRARIES}) +target_link_libraries(runRawParserKWsTests Parser Logger ${Boost_LIBRARIES}) target_link_libraries(runParserKWTests Parser Logger ${Boost_LIBRARIES}) target_link_libraries(runParserRecordSizeTests Parser Logger ${Boost_LIBRARIES}) @@ -16,5 +20,6 @@ target_link_libraries(runParserRecordSizeTests Parser Logger ${Boost_LIBRARIES}) add_test(NAME runParserTests WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${EXECUTABLE_OUTPUT_PATH}/runParserTests ) add_test(NAME runRawDataTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runRawDataTests ) add_test(NAME runRawDeckTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runRawDeckTests ) +add_test(NAME runRawParserKWsTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runRawDeckTests ) add_test(NAME runParserKWTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runParserKWTests ) add_test(NAME runParserRecordSizeTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runParserRecordSizeTests ) diff --git a/tests/ParserTests.cpp b/tests/ParserTests.cpp index 4527d3607..8228e6b3b 100644 --- a/tests/ParserTests.cpp +++ b/tests/ParserTests.cpp @@ -70,17 +70,14 @@ BOOST_AUTO_TEST_CASE(ParseFileWithOneKeyword) { RawDeckPtr rawDeck = parser->parse(singleKeywordFile.string()); BOOST_REQUIRE_EQUAL((unsigned) 1, rawDeck->getNumberOfKeywords()); RawKeywordPtr rawKeyword = rawDeck->getKeyword("ENDSCALE"); - std::list records; - rawKeyword->getRecords(records); + const std::list& records = rawKeyword->getRecords(); BOOST_REQUIRE_EQUAL((unsigned) 1, records.size()); RawRecordPtr record = records.back(); - std::string recordString; - record->getRecordString(recordString); + const std::string& recordString = record->getRecordString(); BOOST_REQUIRE_EQUAL("'NODIR' 'REVERS' 1 20", recordString); - std::vector recordElements; - record->getRecords(recordElements); + const std::vector& recordElements = record->getRecords(); BOOST_REQUIRE_EQUAL((unsigned) 4, recordElements.size()); BOOST_REQUIRE_EQUAL("\'NODIR\'", recordElements[0]); @@ -97,38 +94,33 @@ BOOST_AUTO_TEST_CASE(ParseFileWithFewKeywords) { RawDeckPtr rawDeck = parser->parse(singleKeywordFile.string()); BOOST_REQUIRE_EQUAL((unsigned) 5, rawDeck->getNumberOfKeywords()); - std::list records; - - RawKeywordPtr matchingKeyword = rawDeck->getKeyword("OIL"); - matchingKeyword->getRecords(records); + RawKeywordConstPtr matchingKeyword = rawDeck->getKeyword("OIL"); + std::list records = matchingKeyword->getRecords(); BOOST_REQUIRE_EQUAL("OIL", matchingKeyword->getKeyword()); - matchingKeyword->getRecords(records); BOOST_REQUIRE_EQUAL((unsigned) 0, records.size()); matchingKeyword = rawDeck->getKeyword("INCLUDE"); BOOST_REQUIRE_EQUAL("INCLUDE", matchingKeyword->getKeyword()); - matchingKeyword->getRecords(records); + records = matchingKeyword->getRecords(); BOOST_REQUIRE_EQUAL((unsigned) 1, records.size()); RawRecordPtr theRecord = records.front(); - std::string recordString; - theRecord->getRecordString(recordString); + const std::string& recordString = theRecord->getRecordString(); BOOST_REQUIRE_EQUAL("\'sti til fil/den er her\'", recordString); - matchingKeyword = rawDeck->getKeyword("GRIDUNIT"); - matchingKeyword->getRecords(records); BOOST_REQUIRE_EQUAL("GRIDUNIT", matchingKeyword->getKeyword()); - matchingKeyword->getRecords(records); + records = matchingKeyword->getRecords(); BOOST_REQUIRE_EQUAL((unsigned) 1, records.size()); matchingKeyword = rawDeck->getKeyword("RADFIN4"); - matchingKeyword->getRecords(records); + records = matchingKeyword->getRecords(); BOOST_REQUIRE_EQUAL("RADFIN4", matchingKeyword->getKeyword()); BOOST_REQUIRE_EQUAL((unsigned) 1, records.size()); matchingKeyword = rawDeck->getKeyword("ABCDAD"); BOOST_REQUIRE_EQUAL("ABCDAD", matchingKeyword->getKeyword()); - matchingKeyword->getRecords(records); + records = matchingKeyword->getRecords(); + BOOST_REQUIRE_EQUAL((unsigned) 2, records.size()); } @@ -155,26 +147,23 @@ BOOST_AUTO_TEST_CASE(ParseFullTestFile) { // 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 - std::list records; - RawKeywordPtr matchingKeyword = rawDeck->getKeyword("OIL"); - matchingKeyword->getRecords(records); + + RawKeywordConstPtr matchingKeyword = rawDeck->getKeyword("OIL"); + std::list records = matchingKeyword->getRecords(); BOOST_REQUIRE_EQUAL("OIL", matchingKeyword->getKeyword()); - matchingKeyword->getRecords(records); + BOOST_REQUIRE_EQUAL((unsigned) 0, records.size()); - + matchingKeyword = rawDeck->getKeyword("VFPPDIMS"); - matchingKeyword->getRecords(records); + records = matchingKeyword->getRecords(); BOOST_REQUIRE_EQUAL("VFPPDIMS", matchingKeyword->getKeyword()); - matchingKeyword->getRecords(records); BOOST_REQUIRE_EQUAL((unsigned) 1, records.size()); - - std::string recordString; - records.front()->getRecordString(recordString); + + const std::string& recordString = records.front()->getRecordString(); BOOST_REQUIRE_EQUAL("20 20 15 15 15 50", recordString); - std::vector recordItems; - records.front()->getRecords(recordItems); - BOOST_REQUIRE_EQUAL((unsigned)6, recordItems.size()); - + std::vector recordItems = records.front()->getRecords(); + BOOST_REQUIRE_EQUAL((unsigned) 6, recordItems.size()); + } diff --git a/tests/RawDataStructuresTests.cpp b/tests/RawDataStructuresTests.cpp index 77d25b4fa..d836d39a9 100644 --- a/tests/RawDataStructuresTests.cpp +++ b/tests/RawDataStructuresTests.cpp @@ -67,8 +67,7 @@ BOOST_AUTO_TEST_CASE(RawKeywordSet8CharKeywordWithTrailingWhitespaceKeywordTrimm BOOST_AUTO_TEST_CASE(RawRecordGetRecordStringReturnsTrimmedString) { Opm::RawRecordPtr record(new Opm::RawRecord(" 'NODIR ' 'REVERS' 1 20 /")); - std::string recordString; - record->getRecordString(recordString); + const std::string& recordString = record->getRecordString(); BOOST_REQUIRE_EQUAL("'NODIR ' 'REVERS' 1 20", recordString); } @@ -77,8 +76,7 @@ BOOST_AUTO_TEST_CASE(RawRecordGetRecordStringReturnsTrimmedString) { BOOST_AUTO_TEST_CASE(RawRecordGetRecordsCorrectElementsReturned) { Opm::RawRecordPtr record(new Opm::RawRecord(" 'NODIR ' 'REVERS' 1 20 /")); - std::vector recordElements; - record->getRecords(recordElements); + const std::vector& recordElements = record->getRecords(); BOOST_REQUIRE_EQUAL((unsigned) 4, recordElements.size()); BOOST_REQUIRE_EQUAL("\'NODIR \'", recordElements[0]); diff --git a/tests/RawDeckTests.cpp b/tests/RawDeckTests.cpp index 2dade80a2..462e90bcf 100644 --- a/tests/RawDeckTests.cpp +++ b/tests/RawDeckTests.cpp @@ -22,9 +22,10 @@ #define BOOST_TEST_MODULE RawDeckTests #include #include +#include + BOOST_AUTO_TEST_CASE(ReadData_MissingFixedKeywords_WrongNumberOfKeywordsFound) { - std::map fixedKeywords; - fixedKeywords.insert(std::pair("GRIDUNIT", 1)); - Opm::RawDeck rawDeck(fixedKeywords); + Opm::RawParserKWsConstPtr fixedKeywords(new Opm::RawParserKWs()); + Opm::RawDeck rawDeck(fixedKeywords); } diff --git a/tests/RawParserKWsTests.cpp b/tests/RawParserKWsTests.cpp new file mode 100644 index 000000000..8652d7f0c --- /dev/null +++ b/tests/RawParserKWsTests.cpp @@ -0,0 +1,52 @@ +/* + 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 . + */ + +#include +#include +#define BOOST_TEST_MODULE RawParserKWsTests +#include +#include +#include +using namespace Opm; + + +BOOST_AUTO_TEST_CASE(KeywordExists_KeywordNotPresent_ReturnsFalse) { + RawParserKWsConstPtr parserKWs(new RawParserKWs()); + BOOST_REQUIRE_EQUAL(false, parserKWs->keywordExists("FLASKE")); +} + +BOOST_AUTO_TEST_CASE(KeywordExists_KeywordPresent_ReturnsTrue) { + RawParserKWsConstPtr parserKWs(new RawParserKWs()); + BOOST_REQUIRE_EQUAL(true, parserKWs->keywordExists("TITLE")); +} + +BOOST_AUTO_TEST_CASE(GetFixedNumberOfRecords_KeywordNotPresent_ThrowsException) { + RawParserKWsConstPtr parserKWs(new RawParserKWs()); + BOOST_REQUIRE_THROW(parserKWs->getFixedNumberOfRecords("FLASKE"), std::invalid_argument); +} + +BOOST_AUTO_TEST_CASE(GetFixedNumberOfRecords_OneRecord_ReturnsOne) { + RawParserKWsConstPtr parserKWs(new RawParserKWs()); + BOOST_REQUIRE_EQUAL((unsigned)1,parserKWs->getFixedNumberOfRecords("GRIDUNIT")); +} + +BOOST_AUTO_TEST_CASE(GetFixedNumberOfRecords_ZeroRecords_ReturnsZero) { + RawParserKWsConstPtr parserKWs(new RawParserKWs()); + BOOST_REQUIRE_EQUAL((unsigned)1,parserKWs->getFixedNumberOfRecords("METRIC")); +}