From b43d95c5a2919685a532fff30c22be7ceab5435d Mon Sep 17 00:00:00 2001 From: Kristian Flikka Date: Mon, 3 Jun 2013 15:54:16 +0200 Subject: [PATCH] Starting to wrap up from the top, added the missing DeckKW, and refactored a bit in some of the Raw classes that returned the internal structure --- opm/parser/eclipse/CMakeLists.txt | 4 +- opm/parser/eclipse/Deck/Deck.cpp | 5 +- opm/parser/eclipse/Deck/Deck.hpp | 5 +- opm/parser/eclipse/Deck/DeckKW.cpp | 49 +++++++++++++ opm/parser/eclipse/Deck/DeckKW.hpp | 37 ++++++++++ opm/parser/eclipse/Deck/KeywordContainer.cpp | 50 +++++++++++++ opm/parser/eclipse/Deck/KeywordContainer.hpp | 36 +++++++++ opm/parser/eclipse/Deck/tests/CMakeLists.txt | 9 +++ opm/parser/eclipse/Deck/tests/DeckKWTests.cpp | 73 +++++++++++++++++++ opm/parser/eclipse/Deck/tests/DeckTests.cpp | 4 +- .../Deck/tests/KeywordContainerTests.cpp | 58 +++++++++++++++ .../IntegrationTests/IntegrationTests.cpp | 2 +- opm/parser/eclipse/Parser/Parser.cpp | 17 ++--- opm/parser/eclipse/Parser/Parser.hpp | 2 +- opm/parser/eclipse/Parser/ParserKW.cpp | 16 +++- opm/parser/eclipse/Parser/ParserKW.hpp | 7 +- opm/parser/eclipse/Parser/ParserRecord.cpp | 13 ++-- opm/parser/eclipse/Parser/ParserRecord.hpp | 8 +- .../eclipse/Parser/tests/ParserKWTests.cpp | 22 ++++++ .../Parser/tests/ParserRecordTests.cpp | 2 +- .../Parser/tests/ParserTestsInternalData.cpp | 4 +- opm/parser/eclipse/RawDeck/RawDeck.cpp | 29 ++++---- opm/parser/eclipse/RawDeck/RawDeck.hpp | 3 +- opm/parser/eclipse/RawDeck/RawKeyword.cpp | 72 +++++++++--------- opm/parser/eclipse/RawDeck/RawKeyword.hpp | 25 ++++--- opm/parser/eclipse/RawDeck/RawRecord.cpp | 7 +- opm/parser/eclipse/RawDeck/RawRecord.hpp | 3 +- .../tests/RawDeckInternalDataTests.cpp | 16 ++-- .../eclipse/RawDeck/tests/RawDeckTests.cpp | 68 ++++++++--------- .../eclipse/RawDeck/tests/RawKeywordTests.cpp | 50 +++++++------ .../eclipse/RawDeck/tests/RawRecordTests.cpp | 27 ++++--- 31 files changed, 533 insertions(+), 190 deletions(-) create mode 100644 opm/parser/eclipse/Deck/DeckKW.cpp create mode 100644 opm/parser/eclipse/Deck/DeckKW.hpp create mode 100644 opm/parser/eclipse/Deck/KeywordContainer.cpp create mode 100644 opm/parser/eclipse/Deck/KeywordContainer.hpp create mode 100644 opm/parser/eclipse/Deck/tests/DeckKWTests.cpp create mode 100644 opm/parser/eclipse/Deck/tests/KeywordContainerTests.cpp diff --git a/opm/parser/eclipse/CMakeLists.txt b/opm/parser/eclipse/CMakeLists.txt index 4f82044c5..969f9d9f2 100644 --- a/opm/parser/eclipse/CMakeLists.txt +++ b/opm/parser/eclipse/CMakeLists.txt @@ -12,10 +12,12 @@ RawDeck/RawParserKWs.cpp ) set( deck_source Deck/Deck.cpp +Deck/DeckKW.cpp +Deck/DeckRecord.cpp Deck/DeckItem.cpp Deck/DeckIntItem.cpp Deck/DeckDoubleItem.cpp -Deck/DeckRecord.cpp +Deck/KeywordContainer.cpp ) set( parser_source diff --git a/opm/parser/eclipse/Deck/Deck.cpp b/opm/parser/eclipse/Deck/Deck.cpp index 7efaedaad..979306720 100644 --- a/opm/parser/eclipse/Deck/Deck.cpp +++ b/opm/parser/eclipse/Deck/Deck.cpp @@ -22,10 +22,11 @@ namespace Opm { Deck::Deck() { + m_keywords = KeywordContainerPtr(new KeywordContainer()); } - bool Deck::hasKeyword(const std::string& keyWord) const { - + bool Deck::hasKeyword(const std::string& keyword) const { + return m_keywords->hasKeyword(keyword); } diff --git a/opm/parser/eclipse/Deck/Deck.hpp b/opm/parser/eclipse/Deck/Deck.hpp index 0b0cb28bc..bbcd66935 100644 --- a/opm/parser/eclipse/Deck/Deck.hpp +++ b/opm/parser/eclipse/Deck/Deck.hpp @@ -21,6 +21,7 @@ #define DECK_HPP #include +#include namespace Opm { @@ -29,9 +30,9 @@ namespace Opm { Deck(); virtual ~Deck(); - bool hasKeyword( const std::string& keyWord ) const; + bool hasKeyword( const std::string& keyword ) const; private: - + KeywordContainerPtr m_keywords; }; typedef boost::shared_ptr DeckPtr; diff --git a/opm/parser/eclipse/Deck/DeckKW.cpp b/opm/parser/eclipse/Deck/DeckKW.cpp new file mode 100644 index 000000000..bc6ccd807 --- /dev/null +++ b/opm/parser/eclipse/Deck/DeckKW.cpp @@ -0,0 +1,49 @@ +/* + 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 "DeckKW.hpp" + +namespace Opm { + + DeckKW::DeckKW(const std::string& keywordName) { + m_keywordName = keywordName; + } + + std::string DeckKW::name() const { + return m_keywordName; + } + + size_t DeckKW::size() const { + return m_recordList.size(); + } + + void DeckKW::addRecord(DeckRecordConstPtr record) { + m_recordList.push_back(record); + } + + DeckRecordConstPtr DeckKW::getRecord(size_t index) const { + if (index < m_recordList.size()) { + return m_recordList[index]; + } + else + throw std::range_error("Index out of range"); + } + +} + diff --git a/opm/parser/eclipse/Deck/DeckKW.hpp b/opm/parser/eclipse/Deck/DeckKW.hpp new file mode 100644 index 000000000..d0fa3cbe3 --- /dev/null +++ b/opm/parser/eclipse/Deck/DeckKW.hpp @@ -0,0 +1,37 @@ +/* + * File: DeckKW.hpp + * Author: kflik + * + * Created on June 3, 2013, 12:55 PM + */ + +#ifndef DECKKW_HPP +#define DECKKW_HPP + +#include +#include +#include + +#include + +namespace Opm { + + class DeckKW { + public: + DeckKW(const std::string& keywordName); + std::string name() const; + size_t size() const; + void addRecord(DeckRecordConstPtr record); + DeckRecordConstPtr getRecord(size_t index) const; + + private: + std::string m_keywordName; + std::vector m_recordList; + + }; + typedef boost::shared_ptr DeckKWPtr; + typedef boost::shared_ptr DeckKWConstPtr; +} + +#endif /* DECKKW_HPP */ + diff --git a/opm/parser/eclipse/Deck/KeywordContainer.cpp b/opm/parser/eclipse/Deck/KeywordContainer.cpp new file mode 100644 index 000000000..236180028 --- /dev/null +++ b/opm/parser/eclipse/Deck/KeywordContainer.cpp @@ -0,0 +1,50 @@ +/* + 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 +#include + +namespace Opm { + + KeywordContainer::KeywordContainer() { + } + + bool KeywordContainer::hasKeyword(const std::string& keyword) const { + return (m_keywordMap.find(keyword) != m_keywordMap.end()); + } + + size_t KeywordContainer::size() const { + return m_keywordList.size(); + } + + void KeywordContainer::addKeyword(DeckKWConstPtr keyword) { + m_keywordList.push_back(keyword); + + if (m_keywordMap.find(keyword->name()) == m_keywordMap.end()) { + m_keywordMap[keyword->name()] = std::vector(); + } + + { + std::vector& keywordList = m_keywordMap[keyword->name()]; + keywordList.push_back(keyword); + } + } + +} diff --git a/opm/parser/eclipse/Deck/KeywordContainer.hpp b/opm/parser/eclipse/Deck/KeywordContainer.hpp new file mode 100644 index 000000000..63b1d3599 --- /dev/null +++ b/opm/parser/eclipse/Deck/KeywordContainer.hpp @@ -0,0 +1,36 @@ +/* + * File: KeywordContainer.hpp + * Author: kflik + * + * Created on June 3, 2013, 10:49 AM + */ + +#ifndef KEYWORDCONTAINER_HPP +#define KEYWORDCONTAINER_HPP + +#include +#include + +#include +#include + + +namespace Opm { + + class KeywordContainer { + public: + KeywordContainer(); + bool hasKeyword(const std::string& keyword) const; + size_t size() const; + void addKeyword(DeckKWConstPtr keyword); + + private: + std::vector m_keywordList; + std::map > m_keywordMap; + }; + typedef boost::shared_ptr KeywordContainerPtr; + typedef boost::shared_ptr KeywordContainerConstPtr; +} + +#endif /* KEYWORDCONTAINER_HPP */ + diff --git a/opm/parser/eclipse/Deck/tests/CMakeLists.txt b/opm/parser/eclipse/Deck/tests/CMakeLists.txt index 2b5a9258e..43712be69 100644 --- a/opm/parser/eclipse/Deck/tests/CMakeLists.txt +++ b/opm/parser/eclipse/Deck/tests/CMakeLists.txt @@ -15,6 +15,15 @@ target_link_libraries(runDeckTests Parser Logger ${Boost_LIBRARIES}) add_test(NAME runDeckTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runDeckTests ) set_property(SOURCE DeckTests.cpp PROPERTY COMPILE_FLAGS "-Wno-error") +add_executable(runKeywordContainerTests KeywordContainerTests.cpp) +target_link_libraries(runKeywordContainerTests Parser Logger ${Boost_LIBRARIES}) +add_test(NAME runKeywordContainerTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runKeywordContainerTests ) +set_property(SOURCE KeywordContainerTests.cpp PROPERTY COMPILE_FLAGS "-Wno-error") +add_executable(runDeckKWTests DeckKWTests.cpp) +target_link_libraries(runDeckKWTests Parser Logger ${Boost_LIBRARIES}) +add_test(NAME runDeckKWTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runDeckKWTests ) +set_property(SOURCE DeckKWTests.cpp PROPERTY COMPILE_FLAGS "-Wno-error") + diff --git a/opm/parser/eclipse/Deck/tests/DeckKWTests.cpp b/opm/parser/eclipse/Deck/tests/DeckKWTests.cpp new file mode 100644 index 000000000..92b740359 --- /dev/null +++ b/opm/parser/eclipse/Deck/tests/DeckKWTests.cpp @@ -0,0 +1,73 @@ +/* + 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 . + */ + + +#define BOOST_TEST_MODULE DeckKWTests + +#include +#include +#include + +using namespace Opm; + +BOOST_AUTO_TEST_CASE(Initialize) { + DeckKW deckKW1("KW"); + DeckKWPtr deckKW2(new DeckKW("KW")); + DeckKWConstPtr deckKW3(new DeckKW("KW")); +} +BOOST_AUTO_TEST_CASE(name_nameSetInConstructor_nameReturned) { + DeckKWPtr deckKW(new DeckKW("KW")); + BOOST_CHECK_EQUAL("KW", deckKW->name()); +} + +BOOST_AUTO_TEST_CASE(size_noRecords_returnszero) { + DeckKWPtr deckKW(new DeckKW("KW")); + BOOST_CHECK_EQUAL(0U, deckKW->size()); +} + + +BOOST_AUTO_TEST_CASE(addRecord_onerecord_recordadded) { + DeckKWPtr deckKW(new DeckKW("KW")); + deckKW->addRecord(DeckRecordConstPtr(new DeckRecord())); + BOOST_CHECK_EQUAL(1U, deckKW->size()); +} + +BOOST_AUTO_TEST_CASE(getRecord_onerecord_recordretured) { + DeckKWPtr deckKW(new DeckKW("KW")); + DeckRecordConstPtr deckRecord(new DeckRecord()); + deckKW->addRecord(deckRecord); + BOOST_CHECK_EQUAL(deckRecord, deckKW->getRecord(0)); +} + + +BOOST_AUTO_TEST_CASE(getRecord_outofrange_exceptionthrown) { + DeckKWPtr deckKW(new DeckKW("KW")); + DeckRecordConstPtr deckRecord(new DeckRecord()); + deckKW->addRecord(deckRecord); + BOOST_CHECK_THROW(deckKW->getRecord(1), std::range_error); +} + + + + + + + + + diff --git a/opm/parser/eclipse/Deck/tests/DeckTests.cpp b/opm/parser/eclipse/Deck/tests/DeckTests.cpp index 420425eb2..98c6106bb 100644 --- a/opm/parser/eclipse/Deck/tests/DeckTests.cpp +++ b/opm/parser/eclipse/Deck/tests/DeckTests.cpp @@ -27,14 +27,14 @@ using namespace Opm; BOOST_AUTO_TEST_CASE(Initialize) { - BOOST_REQUIRE_NO_THROW(Deck deck()); + BOOST_REQUIRE_NO_THROW(Deck deck); BOOST_REQUIRE_NO_THROW(DeckPtr deckPtr(new Deck())); BOOST_REQUIRE_NO_THROW(DeckConstPtr deckConstPtr(new Deck())); } BOOST_AUTO_TEST_CASE(hasKeyword_empty_returnFalse) { - Deck deck(); + Deck deck; BOOST_CHECK_EQUAL( false , deck.hasKeyword("Bjarne")); } diff --git a/opm/parser/eclipse/Deck/tests/KeywordContainerTests.cpp b/opm/parser/eclipse/Deck/tests/KeywordContainerTests.cpp new file mode 100644 index 000000000..8c924a77a --- /dev/null +++ b/opm/parser/eclipse/Deck/tests/KeywordContainerTests.cpp @@ -0,0 +1,58 @@ +/* + 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 . + */ + + +#define BOOST_TEST_MODULE KeywordContainerTests + +#include +#include +#include +#include +#include + + +using namespace Opm; + +BOOST_AUTO_TEST_CASE(Initialize) { + KeywordContainer container; + KeywordContainerPtr ptrContainer(new KeywordContainer()); + KeywordContainerConstPtr constPtrContainer(new KeywordContainer()); +} + +BOOST_AUTO_TEST_CASE(hasKeyword_empty_returnsfalse) { + KeywordContainerPtr container(new KeywordContainer()); + BOOST_CHECK_EQUAL(false, container->hasKeyword("Truls")); +} + + +BOOST_AUTO_TEST_CASE(addKeyword_keywordAdded_keywordAdded) { + KeywordContainerPtr container(new KeywordContainer()); + DeckKWPtr keyword = DeckKWPtr(new DeckKW("Truls")); + container->addKeyword(keyword); + + BOOST_CHECK_EQUAL(true, container->hasKeyword("Truls")); + BOOST_CHECK_EQUAL(1U, container->size()); +} + + + + + + + diff --git a/opm/parser/eclipse/IntegrationTests/IntegrationTests.cpp b/opm/parser/eclipse/IntegrationTests/IntegrationTests.cpp index 2de09e361..1a1e2a442 100644 --- a/opm/parser/eclipse/IntegrationTests/IntegrationTests.cpp +++ b/opm/parser/eclipse/IntegrationTests/IntegrationTests.cpp @@ -60,5 +60,5 @@ BOOST_AUTO_TEST_CASE(parse_fileWithBPRKeyword_DeckhasBRP) { ParserPtr parser = createBPRParser(); DeckPtr deck = parser->parse(singleKeywordFile.string()); - BOOST_CHECK_EQUAL( true , deck.hasKeyword("BPR")); + BOOST_CHECK_EQUAL( true , deck->hasKeyword("BPR")); } diff --git a/opm/parser/eclipse/Parser/Parser.cpp b/opm/parser/eclipse/Parser/Parser.cpp index 6a7bbd601..6354ba67b 100644 --- a/opm/parser/eclipse/Parser/Parser.cpp +++ b/opm/parser/eclipse/Parser/Parser.cpp @@ -31,16 +31,15 @@ namespace Opm { DeckPtr Parser::parse(const std::string &path) { Logger::initLogger(); Logger::info("Starting parsing of file: " + path); - - - DeckPtr deck(new Deck()); - { - RawDeckPtr rawDeck(new RawDeck(RawParserKWsConstPtr(new RawParserKWs()))); - rawDeck->parse(path); - - + RawDeckPtr rawDeck(new RawDeck(RawParserKWsConstPtr(new RawParserKWs()))); + rawDeck->parse(path); + + for (size_t i = rawDeck->getNumberOfKeywords(); i++) { + RawKeywordPtr rawKeyword = rawDeck->getKeyword(0); } + + Logger::info("Done parsing of file: " + path); Logger::closeLogger(); return deck; @@ -53,7 +52,7 @@ namespace Opm { } void Parser::addKW(ParserKWConstPtr parserKW) { - keywords.insert(std::make_pair(parserKW->getName(), parserKW)); + m_parserKeywords.insert(std::make_pair(parserKW->getName(), parserKW)); } } // namespace Opm diff --git a/opm/parser/eclipse/Parser/Parser.hpp b/opm/parser/eclipse/Parser/Parser.hpp index 79c2bc0e8..3e0b8629e 100644 --- a/opm/parser/eclipse/Parser/Parser.hpp +++ b/opm/parser/eclipse/Parser/Parser.hpp @@ -48,7 +48,7 @@ namespace Opm { void addKW(ParserKWConstPtr parserKW); private: - std::map keywords; + std::map m_parserKeywords; }; typedef boost::shared_ptr ParserPtr; diff --git a/opm/parser/eclipse/Parser/ParserKW.cpp b/opm/parser/eclipse/Parser/ParserKW.cpp index 2c81df733..6bd5d9663 100644 --- a/opm/parser/eclipse/Parser/ParserKW.cpp +++ b/opm/parser/eclipse/Parser/ParserKW.cpp @@ -54,9 +54,17 @@ namespace Opm { return m_name; } - ParserKW::~ParserKW() { + DeckKWPtr ParserKW::parse(RawKeywordPtr rawKeyword) { + DeckKWPtr keyword(new DeckKW(getName())); + if (m_record != NULL) { + for (size_t i=0; isize(); i++) { + DeckRecordConstPtr deckRecord = m_record->parse(rawKeyword->getRecord(i)); + keyword->addRecord(deckRecord); + } + } + else + throw std::logic_error("Unable to parse rawKeyword, because the ParserKW's record is not set!"); + + return keyword; } - - - } diff --git a/opm/parser/eclipse/Parser/ParserKW.hpp b/opm/parser/eclipse/Parser/ParserKW.hpp index 60c2f4919..21c8039e8 100644 --- a/opm/parser/eclipse/Parser/ParserKW.hpp +++ b/opm/parser/eclipse/Parser/ParserKW.hpp @@ -24,6 +24,9 @@ #include #include +#include +#include + namespace Opm { @@ -33,9 +36,9 @@ namespace Opm { ParserKW(const std::string& name, ParserRecordSizeConstPtr recordSize); void setRecord(ParserRecordConstPtr record); ParserRecordConstPtr getRecord(); - - ~ParserKW(); const std::string& getName() const; + DeckKWPtr parse(RawKeywordPtr rawKeyword); + private: std::string m_name; ParserRecordConstPtr m_record; diff --git a/opm/parser/eclipse/Parser/ParserRecord.cpp b/opm/parser/eclipse/Parser/ParserRecord.cpp index 291475408..b4cf0d620 100644 --- a/opm/parser/eclipse/Parser/ParserRecord.cpp +++ b/opm/parser/eclipse/Parser/ParserRecord.cpp @@ -26,7 +26,7 @@ namespace Opm { } - size_t ParserRecord::size() { + size_t ParserRecord::size() const { return m_items.size(); } @@ -39,7 +39,7 @@ namespace Opm { } - ParserItemConstPtr ParserRecord::get(size_t index) { + ParserItemConstPtr ParserRecord::get(size_t index) const{ if (index < m_items.size()) return m_items[ index ]; else @@ -47,14 +47,17 @@ namespace Opm { } - ParserItemConstPtr ParserRecord::get(const std::string& itemName) { + ParserItemConstPtr ParserRecord::get(const std::string& itemName) const { if (m_itemMap.find( itemName ) == m_itemMap.end()) throw std::invalid_argument("Itemname: " + itemName + " does not exist."); else - return m_itemMap[ itemName ]; + { + std::map::const_iterator theItem = m_itemMap.find(itemName); + return (*theItem).second; + } } - DeckRecordConstPtr ParserRecord::parse(RawRecordPtr rawRecord) { + DeckRecordConstPtr ParserRecord::parse(RawRecordPtr rawRecord) const { DeckRecordPtr deckRecord(new DeckRecord()); for(size_t i=0; i m_items; diff --git a/opm/parser/eclipse/Parser/tests/ParserKWTests.cpp b/opm/parser/eclipse/Parser/tests/ParserKWTests.cpp index bb7c5dc76..a554bebca 100644 --- a/opm/parser/eclipse/Parser/tests/ParserKWTests.cpp +++ b/opm/parser/eclipse/Parser/tests/ParserKWTests.cpp @@ -22,6 +22,9 @@ #include #include "opm/parser/eclipse/Parser/ParserKW.hpp" +#include "opm/parser/eclipse/Parser/ParserIntItem.hpp" +#include "opm/parser/eclipse/Parser/ParserItem.hpp" + using namespace Opm; @@ -58,3 +61,22 @@ BOOST_AUTO_TEST_CASE(MixedCase) { ParserRecordSizeConstPtr recordSize(new ParserRecordSize(100)); BOOST_CHECK_THROW(ParserKW parserKW(keyword, recordSize), std::invalid_argument); } + +BOOST_AUTO_TEST_CASE(parse_rawKeyword_returnsDeckKW) { + RawKeywordPtr rawKeyword(new RawKeyword("TEST2")); + rawKeyword->addRawRecordString("2 3 5 /"); + ParserKWPtr parserKW(new ParserKW("TEST2")); + + ParserRecordPtr parserRecord = ParserRecordPtr(new ParserRecord()); + + ParserItemPtr item1(new ParserIntItem("I", SINGLE)); + parserRecord->addItem(item1); + ParserItemPtr item2(new ParserIntItem("J", SINGLE)); + parserRecord->addItem(item2); + ParserItemPtr item3(new ParserIntItem("K", SINGLE)); + parserRecord->addItem(item3); + + parserKW->setRecord(parserRecord); + DeckKWPtr deckKW = parserKW->parse(rawKeyword); + BOOST_CHECK_EQUAL(1U, deckKW->size()); +} diff --git a/opm/parser/eclipse/Parser/tests/ParserRecordTests.cpp b/opm/parser/eclipse/Parser/tests/ParserRecordTests.cpp index 1c719b7b1..9d9527338 100644 --- a/opm/parser/eclipse/Parser/tests/ParserRecordTests.cpp +++ b/opm/parser/eclipse/Parser/tests/ParserRecordTests.cpp @@ -63,7 +63,7 @@ BOOST_AUTO_TEST_CASE(Get_OneItem_Return1) { } BOOST_AUTO_TEST_CASE(Get_outOfRange_Throw) { - ParserRecordPtr record(new ParserRecord()); + ParserRecordConstPtr record(new ParserRecord()); BOOST_CHECK_THROW(record->get(0), std::out_of_range); } diff --git a/opm/parser/eclipse/Parser/tests/ParserTestsInternalData.cpp b/opm/parser/eclipse/Parser/tests/ParserTestsInternalData.cpp index 86c452e66..45c9c6624 100644 --- a/opm/parser/eclipse/Parser/tests/ParserTestsInternalData.cpp +++ b/opm/parser/eclipse/Parser/tests/ParserTestsInternalData.cpp @@ -65,13 +65,13 @@ BOOST_AUTO_TEST_CASE(ParseFullTestFile) { RawKeywordConstPtr matchingKeyword = rawDeck->getKeyword("OIL"); std::list records = matchingKeyword->getRecords(); - BOOST_CHECK_EQUAL("OIL", matchingKeyword->getKeyword()); + 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->getKeyword()); + BOOST_CHECK_EQUAL("VFPPDIMS", matchingKeyword->getKeywordName()); BOOST_CHECK_EQUAL((unsigned) 1, records.size()); const std::string& recordString = records.front()->getRecordString(); diff --git a/opm/parser/eclipse/RawDeck/RawDeck.cpp b/opm/parser/eclipse/RawDeck/RawDeck.cpp index e083cee89..e0b3c76bd 100644 --- a/opm/parser/eclipse/RawDeck/RawDeck.cpp +++ b/opm/parser/eclipse/RawDeck/RawDeck.cpp @@ -28,13 +28,17 @@ namespace Opm { m_rawParserKWs = rawParserKWs; } + RawKeywordConstPtr RawDeck::getKeyword(size_t index) const { + } + + /// 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::const_iterator it = m_keywords.begin(); it != m_keywords.end(); it++) { - if ((*it)->getKeyword() == keyword) { + if ((*it)->getKeywordName() == keyword) { return (*it); } } @@ -43,7 +47,7 @@ namespace Opm { bool RawDeck::hasKeyword(const std::string& keyword) const { for (std::list::const_iterator it = m_keywords.begin(); it != m_keywords.end(); it++) { - if ((*it)->getKeyword() == keyword) { + if ((*it)->getKeywordName() == keyword) { return true; } } @@ -95,8 +99,9 @@ namespace Opm { } void RawDeck::addKeyword(RawKeywordConstPtr keyword, const boost::filesystem::path& dataFolderPath) { - if (keyword->getKeyword() == Opm::RawConsts::include) { - std::string includeFileString = keyword->getRecords().front()->getItems().front(); + if (keyword->getKeywordName() == Opm::RawConsts::include) { + RawRecordConstPtr firstRecord = keyword->getRecord(0); + std::string includeFileString = firstRecord->getItem(0); boost::filesystem::path pathToIncludedFile(dataFolderPath); pathToIncludedFile /= includeFileString; @@ -124,8 +129,8 @@ namespace Opm { /// specified for the current keyword type in the RawParserKW class. bool RawDeck::isKeywordFinished(RawKeywordConstPtr rawKeyword) { - if (m_rawParserKWs->keywordExists(rawKeyword->getKeyword())) { - return rawKeyword->getNumberOfRecords() == m_rawParserKWs->getFixedNumberOfRecords(rawKeyword->getKeyword()); + if (m_rawParserKWs->keywordExists(rawKeyword->getKeywordName())) { + return rawKeyword->size() == m_rawParserKWs->getFixedNumberOfRecords(rawKeyword->getKeywordName()); } return false; } @@ -134,14 +139,12 @@ 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"; + os << (*keyword)->getKeywordName() << " -- Keyword\n"; - std::list records = (*keyword)->getRecords(); - for (std::list::const_iterator record = records.begin(); record != records.end(); record++) { - std::deque recordItems = (*record)->getItems(); - - for (size_t i=0; isize(); i++) { + RawRecordConstPtr rawRecord = (*keyword)->getRecord(i); + for (size_t j = 0; j < rawRecord->size(); j++) { + os << rawRecord->getItem(j) << " "; } os << " / -- Data\n"; } diff --git a/opm/parser/eclipse/RawDeck/RawDeck.hpp b/opm/parser/eclipse/RawDeck/RawDeck.hpp index 52bded6bd..76a056ffc 100644 --- a/opm/parser/eclipse/RawDeck/RawDeck.hpp +++ b/opm/parser/eclipse/RawDeck/RawDeck.hpp @@ -46,6 +46,8 @@ namespace Opm { 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; friend std::ostream& operator<<(std::ostream& os, const RawDeck& deck); @@ -56,7 +58,6 @@ namespace Opm { std::list m_keywords; RawParserKWsConstPtr m_rawParserKWs; - //void readDataIntoDeck(const std::string& path, std::list& keywordList); void addKeyword(RawKeywordConstPtr keyword, const boost::filesystem::path& baseDataFolder); bool isKeywordFinished(RawKeywordConstPtr rawKeyword); diff --git a/opm/parser/eclipse/RawDeck/RawKeyword.cpp b/opm/parser/eclipse/RawDeck/RawKeyword.cpp index 8552d1b9a..aebe3d1ce 100644 --- a/opm/parser/eclipse/RawDeck/RawKeyword.cpp +++ b/opm/parser/eclipse/RawDeck/RawKeyword.cpp @@ -25,11 +25,36 @@ namespace Opm { - RawKeyword::RawKeyword() { + RawKeyword::RawKeyword(const std::string& name) { + setKeywordName(name); } - RawKeyword::RawKeyword(const std::string& keyword) { - setKeyword(keyword); + const std::string& RawKeyword::getKeywordName() const { + return m_name; + } + + size_t RawKeyword::size() const { + return m_records.size(); + } + + /// Important method, being repeatedly called. When a record is terminated, + /// it is added to the list of records, and a new record is started. + + void RawKeyword::addRawRecordString(const std::string& partialRecordString) { + m_partialRecordString += partialRecordString; + if (RawRecord::isTerminatedRecordString(partialRecordString)) { + RawRecordPtr record(new RawRecord(m_partialRecordString)); + m_records.push_back(record); + m_partialRecordString.clear(); + } + } + + RawRecordPtr RawKeyword::getRecord(size_t index) const { + if (index < m_records.size()) { + return m_records[index]; + } + else + throw std::range_error("Index out of range"); } bool RawKeyword::tryParseKeyword(const std::string& keywordCandidate, std::string& result) { @@ -84,25 +109,14 @@ namespace Opm { return false; } - void RawKeyword::setKeyword(const std::string& keyword) { - m_keyword = boost::algorithm::trim_right_copy(keyword); - if (!isValidKeyword(m_keyword)) { - throw std::invalid_argument("Not a valid keyword:" + keyword); - } else if (m_keyword.size() > Opm::RawConsts::maxKeywordLength) { - throw std::invalid_argument("Too long keyword:" + keyword); - } else if (boost::algorithm::trim_left_copy(m_keyword) != m_keyword) { - throw std::invalid_argument("Illegal whitespace start of keyword:" + keyword); - } - } - /// Important method, being repeatedly called. When a record is terminated, - /// it is added to the list of records, and a new record is started. - - void RawKeyword::addRawRecordString(const std::string& partialRecordString) { - m_partialRecordString += partialRecordString; - if (RawRecord::isTerminatedRecordString(partialRecordString)) { - RawRecordPtr record(new RawRecord(m_partialRecordString)); - m_records.push_back(record); - m_partialRecordString.clear(); + void RawKeyword::setKeywordName(const std::string& name) { + m_name = boost::algorithm::trim_right_copy(name); + if (!isValidKeyword(m_name)) { + throw std::invalid_argument("Not a valid keyword:" + name); + } else if (m_name.size() > Opm::RawConsts::maxKeywordLength) { + throw std::invalid_argument("Too long keyword:" + name); + } else if (boost::algorithm::trim_left_copy(m_name) != m_name) { + throw std::invalid_argument("Illegal whitespace start of keyword:" + name); } } @@ -110,19 +124,5 @@ namespace Opm { return m_partialRecordString.size() == 0; } - unsigned int RawKeyword::getNumberOfRecords() const { - return m_records.size(); - } - - const std::list& RawKeyword::getRecords() const { - return m_records; - } - - const std::string& RawKeyword::getKeyword() const { - return m_keyword; - } - - RawKeyword::~RawKeyword() { - } } diff --git a/opm/parser/eclipse/RawDeck/RawKeyword.hpp b/opm/parser/eclipse/RawDeck/RawKeyword.hpp index de08f830d..ef678c1c0 100644 --- a/opm/parser/eclipse/RawDeck/RawKeyword.hpp +++ b/opm/parser/eclipse/RawDeck/RawKeyword.hpp @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include "opm/parser/eclipse/Logger/Logger.hpp" @@ -33,28 +33,29 @@ namespace Opm { /// Class representing a RawKeyword, meaning both the actual keyword phrase, and the records, /// represented as a list of RawRecord objects. /// The class also contains static functions to aid the parsing of the input file. - /// The creationg of an instance is performed by calling the addRawRecordString method repeatedly. + /// The creating of an instance is performed by calling the addRawRecordString method repeatedly. class RawKeyword { public: - RawKeyword(); - RawKeyword(const std::string& keyword); + RawKeyword(const std::string& name); + const std::string& getKeywordName() const; + void addRawRecordString(const std::string& partialRecordString); + 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); - const std::string& getKeyword() const; - const std::list& getRecords() const; - unsigned int getNumberOfRecords() const; - void setKeyword(const std::string& keyword); - void addRawRecordString(const std::string& partialRecordString); bool isPartialRecordStringEmpty() const; - virtual ~RawKeyword(); private: - std::string m_keyword; - std::list m_records; + std::string m_name; + std::vector m_records; std::string m_partialRecordString; + void setKeywordName(const std::string& keyword); static bool isValidKeyword(const std::string& keywordCandidate); }; typedef boost::shared_ptr RawKeywordPtr; diff --git a/opm/parser/eclipse/RawDeck/RawRecord.cpp b/opm/parser/eclipse/RawDeck/RawRecord.cpp index 83cd36311..63100d6e6 100644 --- a/opm/parser/eclipse/RawDeck/RawRecord.cpp +++ b/opm/parser/eclipse/RawDeck/RawRecord.cpp @@ -67,18 +67,13 @@ namespace Opm { } - const std::string& RawRecord::operator[](size_t index) const { + const std::string& RawRecord::getItem(size_t index) const { if (index < m_recordItems.size()) return m_recordItems[index]; else throw std::out_of_range("Lookup index out of range"); } - - const std::deque& RawRecord::getItems() const { - return m_recordItems; - } - const std::string& RawRecord::getRecordString() const { return m_sanitizedRecordString; } diff --git a/opm/parser/eclipse/RawDeck/RawRecord.hpp b/opm/parser/eclipse/RawDeck/RawRecord.hpp index 13478fa0b..a68c87951 100644 --- a/opm/parser/eclipse/RawDeck/RawRecord.hpp +++ b/opm/parser/eclipse/RawDeck/RawRecord.hpp @@ -40,8 +40,7 @@ namespace Opm { size_t size() const; const std::string& getRecordString() const; - const std::deque& getItems() const; - const std::string& operator[](size_t index) const; + const std::string& getItem(size_t index) const; static bool isTerminatedRecordString(const std::string& candidateRecordString); virtual ~RawRecord(); diff --git a/opm/parser/eclipse/RawDeck/tests/RawDeckInternalDataTests.cpp b/opm/parser/eclipse/RawDeck/tests/RawDeckInternalDataTests.cpp index 2ce4bf5a3..3d729cf56 100644 --- a/opm/parser/eclipse/RawDeck/tests/RawDeckInternalDataTests.cpp +++ b/opm/parser/eclipse/RawDeck/tests/RawDeckInternalDataTests.cpp @@ -59,18 +59,14 @@ BOOST_AUTO_TEST_CASE(ParseFullTestFile) { // number of records RawKeywordConstPtr matchingKeyword = rawDeck->getKeyword("OIL"); - std::list records = matchingKeyword->getRecords(); - BOOST_CHECK_EQUAL("OIL", matchingKeyword->getKeyword()); - - BOOST_CHECK_EQUAL((unsigned) 0, records.size()); + BOOST_CHECK_EQUAL("OIL", matchingKeyword->getKeywordName()); + BOOST_CHECK_EQUAL(0U, matchingKeyword->size()); matchingKeyword = rawDeck->getKeyword("VFPPDIMS"); - records = matchingKeyword->getRecords(); - BOOST_CHECK_EQUAL("VFPPDIMS", matchingKeyword->getKeyword()); - BOOST_CHECK_EQUAL((unsigned) 1, records.size()); + BOOST_CHECK_EQUAL("VFPPDIMS", matchingKeyword->getKeywordName()); + BOOST_CHECK_EQUAL((unsigned) 1, matchingKeyword->size()); - const std::string& recordString = records.front()->getRecordString(); + const std::string& recordString = matchingKeyword->getRecord(0)->getRecordString(); BOOST_CHECK_EQUAL("20 20 15 15 15 50", recordString); - std::deque recordItems = records.front()->getItems(); - BOOST_CHECK_EQUAL((unsigned) 6, recordItems.size()); + BOOST_CHECK_EQUAL((unsigned) 6, matchingKeyword->getRecord(0)->size()); } diff --git a/opm/parser/eclipse/RawDeck/tests/RawDeckTests.cpp b/opm/parser/eclipse/RawDeck/tests/RawDeckTests.cpp index 887873dba..ae460741b 100644 --- a/opm/parser/eclipse/RawDeck/tests/RawDeckTests.cpp +++ b/opm/parser/eclipse/RawDeck/tests/RawDeckTests.cpp @@ -31,9 +31,16 @@ using namespace Opm; BOOST_AUTO_TEST_CASE(Initialize_NoThrow) { RawParserKWsConstPtr fixedKeywords(new RawParserKWs()); - BOOST_CHECK_NO_THROW( RawDeck rawDeck( fixedKeywords )); + 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()); @@ -53,8 +60,6 @@ BOOST_AUTO_TEST_CASE(GetKeyword_EmptyDeck_ThrowsExeption) { BOOST_CHECK_THROW(rawDeck->getKeyword("TEST"), std::invalid_argument); } - - BOOST_AUTO_TEST_CASE(PrintToOStream_noThrow) { boost::filesystem::path singleKeywordFile("testdata/small.data"); @@ -64,22 +69,17 @@ BOOST_AUTO_TEST_CASE(PrintToOStream_noThrow) { std::cout << *rawDeck << "\n"; } - 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"); @@ -88,20 +88,19 @@ BOOST_AUTO_TEST_CASE(ParseFileWithOneKeyword) { BOOST_CHECK_EQUAL((unsigned) 1, rawDeck->getNumberOfKeywords()); RawKeywordConstPtr rawKeyword = rawDeck->getKeyword("ENDSCALE"); - const std::list& records = rawKeyword->getRecords(); - BOOST_CHECK_EQUAL((unsigned) 1, records.size()); - RawRecordConstPtr record = records.back(); + + 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); - const std::deque& recordElements = record->getItems(); - BOOST_CHECK_EQUAL((unsigned) 4, recordElements.size()); + BOOST_CHECK_EQUAL((unsigned) 4, record->size()); - BOOST_CHECK_EQUAL("NODIR", recordElements[0]); - BOOST_CHECK_EQUAL("REVERS", recordElements[1]); - BOOST_CHECK_EQUAL("1", recordElements[2]); - BOOST_CHECK_EQUAL("20", recordElements[3]); + 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) { @@ -113,39 +112,32 @@ BOOST_AUTO_TEST_CASE(ParseFileWithFewKeywords) { BOOST_CHECK_EQUAL((unsigned) 7, rawDeck->getNumberOfKeywords()); RawKeywordConstPtr matchingKeyword = rawDeck->getKeyword("OIL"); - std::list records = matchingKeyword->getRecords(); - BOOST_CHECK_EQUAL("OIL", matchingKeyword->getKeyword()); - BOOST_CHECK_EQUAL((unsigned) 0, records.size()); + 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->getKeyword()); - records = matchingKeyword->getRecords(); - BOOST_CHECK_EQUAL((unsigned) 2, records.size()); + BOOST_CHECK_EQUAL("GRUPTREE", matchingKeyword->getKeywordName()); + BOOST_CHECK_EQUAL((unsigned) 2, matchingKeyword->size()); matchingKeyword = rawDeck->getKeyword("WHISTCTL"); - BOOST_CHECK_EQUAL("WHISTCTL", matchingKeyword->getKeyword()); - records = matchingKeyword->getRecords(); - BOOST_CHECK_EQUAL((unsigned) 1, records.size()); + BOOST_CHECK_EQUAL("WHISTCTL", matchingKeyword->getKeywordName()); + BOOST_CHECK_EQUAL((unsigned) 1, matchingKeyword->size()); matchingKeyword = rawDeck->getKeyword("METRIC"); - BOOST_CHECK_EQUAL("METRIC", matchingKeyword->getKeyword()); - records = matchingKeyword->getRecords(); - BOOST_CHECK_EQUAL((unsigned) 0, records.size()); + BOOST_CHECK_EQUAL("METRIC", matchingKeyword->getKeywordName()); + BOOST_CHECK_EQUAL((unsigned) 0, matchingKeyword->size()); matchingKeyword = rawDeck->getKeyword("GRIDUNIT"); - BOOST_CHECK_EQUAL("GRIDUNIT", matchingKeyword->getKeyword()); - records = matchingKeyword->getRecords(); - BOOST_CHECK_EQUAL((unsigned) 1, records.size()); + BOOST_CHECK_EQUAL("GRIDUNIT", matchingKeyword->getKeywordName()); + BOOST_CHECK_EQUAL((unsigned) 1, matchingKeyword->size()); matchingKeyword = rawDeck->getKeyword("RADFIN4"); - records = matchingKeyword->getRecords(); - BOOST_CHECK_EQUAL("RADFIN4", matchingKeyword->getKeyword()); - BOOST_CHECK_EQUAL((unsigned) 1, records.size()); + BOOST_CHECK_EQUAL("RADFIN4", matchingKeyword->getKeywordName()); + BOOST_CHECK_EQUAL((unsigned) 1, matchingKeyword->size()); matchingKeyword = rawDeck->getKeyword("ABCDAD"); - BOOST_CHECK_EQUAL("ABCDAD", matchingKeyword->getKeyword()); - records = matchingKeyword->getRecords(); + BOOST_CHECK_EQUAL("ABCDAD", matchingKeyword->getKeywordName()); - BOOST_CHECK_EQUAL((unsigned) 2, records.size()); + BOOST_CHECK_EQUAL((unsigned) 2, matchingKeyword->size()); } diff --git a/opm/parser/eclipse/RawDeck/tests/RawKeywordTests.cpp b/opm/parser/eclipse/RawDeck/tests/RawKeywordTests.cpp index 26b00d5ee..9c9f84289 100644 --- a/opm/parser/eclipse/RawDeck/tests/RawKeywordTests.cpp +++ b/opm/parser/eclipse/RawDeck/tests/RawKeywordTests.cpp @@ -22,43 +22,49 @@ #include #include -BOOST_AUTO_TEST_CASE(RawKeywordEmptyConstructorEmptyKeyword) { - Opm::RawKeyword keyword; - BOOST_CHECK(keyword.getKeyword() == ""); -} + +using namespace Opm; BOOST_AUTO_TEST_CASE(RawKeywordGiveKeywordToConstructorKeywordSet) { - Opm::RawKeyword keyword("KEYYWORD"); - BOOST_CHECK(keyword.getKeyword() == "KEYYWORD"); + RawKeyword keyword("KEYYWORD"); + BOOST_CHECK(keyword.getKeywordName() == "KEYYWORD"); } BOOST_AUTO_TEST_CASE(RawKeywordGiveKeywordToConstructorTooLongThrows) { - BOOST_CHECK_THROW(Opm::RawKeyword keyword("KEYYYWORD"), std::invalid_argument); -} - -BOOST_AUTO_TEST_CASE(RawKeywordSetTooLongKeywordThrows) { - Opm::RawKeyword keyword; - BOOST_CHECK_THROW(keyword.setKeyword("TESTTOOLONG"), std::invalid_argument); + BOOST_CHECK_THROW(RawKeyword keyword("KEYYYWORD"), std::invalid_argument); } BOOST_AUTO_TEST_CASE(RawKeywordSetKeywordInitialWhitespaceInKeywordThrows) { - Opm::RawKeyword keyword; - BOOST_CHECK_THROW(keyword.setKeyword(" TELONG"), std::invalid_argument); + BOOST_CHECK_THROW(RawKeyword(" TELONG"), std::invalid_argument); +} + +BOOST_AUTO_TEST_CASE(constructor_mixedCaseName_throws) { + BOOST_CHECK_THROW(RawKeyword("Test"), std::invalid_argument); } BOOST_AUTO_TEST_CASE(RawKeywordSetKeywordInitialTabInKeywordThrows) { - Opm::RawKeyword keyword; - BOOST_CHECK_THROW(keyword.setKeyword("\tTELONG"), std::invalid_argument); + BOOST_CHECK_THROW( RawKeyword("\tTELONG"), std::invalid_argument); } BOOST_AUTO_TEST_CASE(RawKeywordSetCorrectLenghtKeywordNoError) { - Opm::RawKeyword keyword; - keyword.setKeyword("GOODONE"); - BOOST_CHECK(keyword.getKeyword() == "GOODONE"); + RawKeyword keyword("GOODONE"); + BOOST_CHECK(keyword.getKeywordName() == "GOODONE"); } BOOST_AUTO_TEST_CASE(RawKeywordSet8CharKeywordWithTrailingWhitespaceKeywordTrimmed) { - Opm::RawKeyword keyword; - keyword.setKeyword("GOODONEE "); - BOOST_CHECK(keyword.getKeyword() == "GOODONEE"); + RawKeyword keyword("GOODONEE "); + BOOST_CHECK(keyword.getKeywordName() == "GOODONEE"); +} + + +BOOST_AUTO_TEST_CASE(addRecord_singleRecord_recordAdded) { + RawKeyword keyword("TEST"); + keyword.addRawRecordString("test 1 3 4 /"); + BOOST_CHECK_EQUAL(1U, keyword.size()); +} + +BOOST_AUTO_TEST_CASE(getRecord_outOfRange_throws) { + RawKeyword keyword("TEST"); + keyword.addRawRecordString("test 1 3 4 /"); + BOOST_CHECK_THROW(keyword.getRecord(1), std::range_error); } diff --git a/opm/parser/eclipse/RawDeck/tests/RawRecordTests.cpp b/opm/parser/eclipse/RawDeck/tests/RawRecordTests.cpp index 08802b16d..7f8381e15 100644 --- a/opm/parser/eclipse/RawDeck/tests/RawRecordTests.cpp +++ b/opm/parser/eclipse/RawDeck/tests/RawRecordTests.cpp @@ -31,13 +31,12 @@ BOOST_AUTO_TEST_CASE(RawRecordGetRecordStringReturnsTrimmedString) { BOOST_AUTO_TEST_CASE(RawRecordGetRecordsCorrectElementsReturned) { Opm::RawRecordPtr record(new Opm::RawRecord(" 'NODIR ' 'REVERS' 1 20 /")); - const std::deque& recordElements = record->getItems(); - BOOST_CHECK_EQUAL((unsigned) 4, recordElements.size()); + BOOST_CHECK_EQUAL((unsigned) 4, record->size()); - BOOST_CHECK_EQUAL("NODIR ", recordElements[0]); - BOOST_CHECK_EQUAL("REVERS", recordElements[1]); - BOOST_CHECK_EQUAL("1", recordElements[2]); - BOOST_CHECK_EQUAL("20", recordElements[3]); + 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(RawRecordIsCompleteRecordCompleteRecordReturnsTrue) { @@ -57,14 +56,14 @@ BOOST_AUTO_TEST_CASE(Rawrecord_OperatorThis_OK) { Opm::RawRecord record(" 'NODIR ' 'REVERS' 1 20 /"); Opm::RawRecordPtr recordPtr(new Opm::RawRecord(" 'NODIR ' 'REVERS' 1 20 /")); - BOOST_CHECK_EQUAL( "NODIR " , record[0]); - BOOST_CHECK_EQUAL( "REVERS" , record[1]); - BOOST_CHECK_EQUAL( "1" , record[2]); - BOOST_CHECK_EQUAL( "20" , record[3]); + 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_CHECK_EQUAL( "20" , (*recordPtr)[3]); + BOOST_CHECK_EQUAL( "20" , recordPtr->getItem(3)); - BOOST_CHECK_THROW( record[4] , std::out_of_range); + BOOST_CHECK_THROW( record.getItem(4) , std::out_of_range); } @@ -74,8 +73,8 @@ BOOST_AUTO_TEST_CASE(Rawrecord_PushFront_OK) { record->push_front( "String1" ); - BOOST_CHECK_EQUAL( "String1" , (*record)[0]); - BOOST_CHECK_EQUAL( "String2" , (*record)[1]); + BOOST_CHECK_EQUAL( "String1" , record->getItem(0)); + BOOST_CHECK_EQUAL( "String2" , record->getItem(1)); }