diff --git a/opm/parser/eclipse/CMakeLists.txt b/opm/parser/eclipse/CMakeLists.txt index d4194f1a0..4f82044c5 100644 --- a/opm/parser/eclipse/CMakeLists.txt +++ b/opm/parser/eclipse/CMakeLists.txt @@ -11,6 +11,7 @@ RawDeck/RawRecord.cpp RawDeck/RawParserKWs.cpp ) set( deck_source +Deck/Deck.cpp Deck/DeckItem.cpp Deck/DeckIntItem.cpp Deck/DeckDoubleItem.cpp diff --git a/opm/parser/eclipse/Deck/Deck.cpp b/opm/parser/eclipse/Deck/Deck.cpp index 85cc3335e..7efaedaad 100644 --- a/opm/parser/eclipse/Deck/Deck.cpp +++ b/opm/parser/eclipse/Deck/Deck.cpp @@ -24,6 +24,11 @@ namespace Opm { Deck::Deck() { } + bool Deck::hasKeyword(const std::string& keyWord) const { + + } + + Deck::~Deck() { } } diff --git a/opm/parser/eclipse/Deck/Deck.hpp b/opm/parser/eclipse/Deck/Deck.hpp index 1cf6eee1e..0b0cb28bc 100644 --- a/opm/parser/eclipse/Deck/Deck.hpp +++ b/opm/parser/eclipse/Deck/Deck.hpp @@ -18,7 +18,7 @@ */ #ifndef DECK_HPP -#define DECK_HPP +#define DECK_HPP #include @@ -28,6 +28,8 @@ namespace Opm { public: Deck(); virtual ~Deck(); + + bool hasKeyword( const std::string& keyWord ) const; private: }; @@ -35,5 +37,5 @@ namespace Opm { typedef boost::shared_ptr DeckPtr; typedef boost::shared_ptr DeckConstPtr; } -#endif /* DECK_HPP */ +#endif /* DECK_HPP */ diff --git a/opm/parser/eclipse/Deck/tests/CMakeLists.txt b/opm/parser/eclipse/Deck/tests/CMakeLists.txt index 69d95ed5e..2b5a9258e 100644 --- a/opm/parser/eclipse/Deck/tests/CMakeLists.txt +++ b/opm/parser/eclipse/Deck/tests/CMakeLists.txt @@ -8,3 +8,13 @@ add_executable(runDeckItemTests DeckItemTests.cpp) target_link_libraries(runDeckItemTests Parser Logger ${Boost_LIBRARIES}) add_test(NAME runDeckItemTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runDeckItemTests ) set_property(SOURCE DeckItemTests.cpp PROPERTY COMPILE_FLAGS "-Wno-error") + + +add_executable(runDeckTests DeckTests.cpp) +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") + + + + diff --git a/opm/parser/eclipse/IntegrationTests/IntegrationTests.cpp b/opm/parser/eclipse/IntegrationTests/IntegrationTests.cpp index 45052e23a..2de09e361 100644 --- a/opm/parser/eclipse/IntegrationTests/IntegrationTests.cpp +++ b/opm/parser/eclipse/IntegrationTests/IntegrationTests.cpp @@ -21,6 +21,8 @@ #include #include +#include + #include #include #include @@ -28,19 +30,35 @@ using namespace Opm; -BOOST_AUTO_TEST_CASE(parse_fileWithBPRKeyword_deckReturned) { +ParserPtr createBPRParser() { ParserKWPtr parserKW(new ParserKW("BPR")); - ParserRecordPtr bprRecord(new ParserRecord()); - bprRecord->addItem(ParserIntItemConstPtr(new ParserIntItem("I", SINGLE))); - bprRecord->addItem(ParserIntItemConstPtr(new ParserIntItem("J", SINGLE))); - bprRecord->addItem(ParserIntItemConstPtr(new ParserIntItem("K", SINGLE))); + { + ParserRecordPtr bprRecord(new ParserRecord()); + bprRecord->addItem(ParserIntItemConstPtr(new ParserIntItem("I", SINGLE))); + bprRecord->addItem(ParserIntItemConstPtr(new ParserIntItem("J", SINGLE))); + bprRecord->addItem(ParserIntItemConstPtr(new ParserIntItem("K", SINGLE))); + + parserKW->setRecord(bprRecord); + } - parserKW->setRecord(bprRecord); - - boost::filesystem::path singleKeywordFile("testdata/integration_tests/bpr.data"); ParserPtr parser(new Parser()); - - - BOOST_CHECK_NO_THROW(parser->parse(singleKeywordFile.string())); + 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_AUTO_TEST_CASE(parse_fileWithBPRKeyword_DeckhasBRP) { + boost::filesystem::path singleKeywordFile("testdata/integration_tests/bpr.data"); + ParserPtr parser = createBPRParser(); + + DeckPtr deck = parser->parse(singleKeywordFile.string()); + BOOST_CHECK_EQUAL( true , deck.hasKeyword("BPR")); } diff --git a/opm/parser/eclipse/Parser/Parser.cpp b/opm/parser/eclipse/Parser/Parser.cpp index 90297d749..6a7bbd601 100644 --- a/opm/parser/eclipse/Parser/Parser.cpp +++ b/opm/parser/eclipse/Parser/Parser.cpp @@ -28,24 +28,26 @@ namespace Opm { Parser::Parser() { } - RawDeckPtr Parser::parse(const std::string &path) { + DeckPtr Parser::parse(const std::string &path) { Logger::initLogger(); Logger::info("Starting parsing of file: " + path); - - RawDeckPtr rawDeck(new RawDeck(RawParserKWsConstPtr(new RawParserKWs()))); - rawDeck->readDataIntoDeck(path); - - - //Iterate through rawDeck, and return Deck - DeckPtr deck(new Deck()); - + { + RawDeckPtr rawDeck(new RawDeck(RawParserKWsConstPtr(new RawParserKWs()))); + rawDeck->parse(path); + + + + } Logger::info("Done parsing of file: " + path); Logger::closeLogger(); - return rawDeck; + return deck; } + + + Parser::~Parser() { } diff --git a/opm/parser/eclipse/Parser/Parser.hpp b/opm/parser/eclipse/Parser/Parser.hpp index ae955dd7e..79c2bc0e8 100644 --- a/opm/parser/eclipse/Parser/Parser.hpp +++ b/opm/parser/eclipse/Parser/Parser.hpp @@ -27,6 +27,7 @@ #include #include #include +#include #include namespace Opm { @@ -40,7 +41,7 @@ namespace Opm { Parser(); /// The starting point of the parsing process. The supplied file is parsed, and the resulting Deck is returned. - RawDeckPtr parse(const std::string &path); + DeckPtr parse(const std::string &path); virtual ~Parser(); /// Method to add ParserKW instances, these holding type and size information about the keywords and their data. @@ -51,6 +52,7 @@ namespace Opm { }; typedef boost::shared_ptr ParserPtr; + typedef boost::shared_ptr ParserConstPtr; } // namespace Opm #endif /* PARSER_H */ diff --git a/opm/parser/eclipse/Parser/tests/CMakeLists.txt b/opm/parser/eclipse/Parser/tests/CMakeLists.txt index 4dc494ab4..e2eebf752 100644 --- a/opm/parser/eclipse/Parser/tests/CMakeLists.txt +++ b/opm/parser/eclipse/Parser/tests/CMakeLists.txt @@ -1,24 +1,20 @@ add_executable(runParserTests ParserTests.cpp) -add_executable(runParserTestsInternalData ParserTestsInternalData.cpp) add_executable(runParserKWTests ParserKWTests.cpp) add_executable(runParserRecordTests ParserRecordTests.cpp) add_executable(runParserRecordSizeTests ParserRecordSizeTests.cpp) add_executable(runParserItemTests ParserItemTests.cpp) target_link_libraries(runParserTests Parser ${Boost_LIBRARIES}) -target_link_libraries(runParserTestsInternalData 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}) add_test(NAME runParserTests WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${EXECUTABLE_OUTPUT_PATH}/runParserTests ) -add_test(NAME runParserTestsInternalData WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} COMMAND runParserTestsInternalData) 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 ) -set_tests_properties(runParserTestsInternalData PROPERTIES LABELS Statoil) set_property(SOURCE ParserRecordTests.cpp PROPERTY COMPILE_FLAGS "-Wno-error") diff --git a/opm/parser/eclipse/Parser/tests/ParserTests.cpp b/opm/parser/eclipse/Parser/tests/ParserTests.cpp index 8eebc8028..360153daa 100644 --- a/opm/parser/eclipse/Parser/tests/ParserTests.cpp +++ b/opm/parser/eclipse/Parser/tests/ParserTests.cpp @@ -24,113 +24,24 @@ #include -#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 +#include +#include +#include + using namespace Opm; -BOOST_AUTO_TEST_CASE(RawDeckPrintToOStream) { - boost::filesystem::path singleKeywordFile("testdata/small.data"); - - ParserPtr parser(new Parser()); - - RawDeckPtr rawDeck = parser->parse(singleKeywordFile.string()); - std::cout << *rawDeck << "\n"; -} - BOOST_AUTO_TEST_CASE(Initializing) { BOOST_CHECK_NO_THROW(Parser parser); + BOOST_CHECK_NO_THROW(ParserPtr parserPtr(new Parser())); + BOOST_CHECK_NO_THROW(ParserConstPtr parserConstPtr(new Parser())); } -BOOST_AUTO_TEST_CASE(ParseWithInvalidInputFileThrows) { - ParserPtr parser(new Parser()); - BOOST_CHECK_THROW(parser->parse("nonexistingfile.asdf"), std::invalid_argument); -} -BOOST_AUTO_TEST_CASE(ParseWithValidFileSetOnParseCallNoThrow) { - boost::filesystem::path singleKeywordFile("testdata/small.data"); - ParserPtr parser(new Parser()); - BOOST_CHECK_NO_THROW(parser->parse(singleKeywordFile.string())); -} -BOOST_AUTO_TEST_CASE(ParseWithInValidFileSetOnParseCallThrows) { - boost::filesystem::path singleKeywordFile("testdata/nosuchfile.data"); - ParserPtr parser(new Parser()); - BOOST_CHECK_THROW(parser->parse(singleKeywordFile.string()), std::invalid_argument); -} -BOOST_AUTO_TEST_CASE(ParseFileWithOneKeyword) { - boost::filesystem::path singleKeywordFile("testdata/mini.data"); - - ParserPtr parser(new Parser()); - - RawDeckPtr rawDeck = parser->parse(singleKeywordFile.string()); - 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(); - - 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("NODIR", recordElements[0]); - BOOST_CHECK_EQUAL("REVERS", recordElements[1]); - BOOST_CHECK_EQUAL("1", recordElements[2]); - BOOST_CHECK_EQUAL("20", recordElements[3]); -} - -BOOST_AUTO_TEST_CASE(ParseFileWithFewKeywords) { - boost::filesystem::path singleKeywordFile("testdata/small.data"); - - ParserPtr parser(new Parser()); - - RawDeckPtr rawDeck = parser->parse(singleKeywordFile.string()); - 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()); - - // 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()); - - matchingKeyword = rawDeck->getKeyword("WHISTCTL"); - BOOST_CHECK_EQUAL("WHISTCTL", matchingKeyword->getKeyword()); - records = matchingKeyword->getRecords(); - BOOST_CHECK_EQUAL((unsigned) 1, records.size()); - - matchingKeyword = rawDeck->getKeyword("METRIC"); - BOOST_CHECK_EQUAL("METRIC", matchingKeyword->getKeyword()); - records = matchingKeyword->getRecords(); - BOOST_CHECK_EQUAL((unsigned) 0, records.size()); - - matchingKeyword = rawDeck->getKeyword("GRIDUNIT"); - BOOST_CHECK_EQUAL("GRIDUNIT", matchingKeyword->getKeyword()); - records = matchingKeyword->getRecords(); - BOOST_CHECK_EQUAL((unsigned) 1, records.size()); - - matchingKeyword = rawDeck->getKeyword("RADFIN4"); - records = matchingKeyword->getRecords(); - BOOST_CHECK_EQUAL("RADFIN4", matchingKeyword->getKeyword()); - BOOST_CHECK_EQUAL((unsigned) 1, records.size()); - - matchingKeyword = rawDeck->getKeyword("ABCDAD"); - BOOST_CHECK_EQUAL("ABCDAD", matchingKeyword->getKeyword()); - records = matchingKeyword->getRecords(); - - BOOST_CHECK_EQUAL((unsigned) 2, records.size()); -} BOOST_AUTO_TEST_CASE(ParserAddKW) { Parser parser; diff --git a/opm/parser/eclipse/Parser/tests/ParserTestsInternalData.cpp b/opm/parser/eclipse/Parser/tests/ParserTestsInternalData.cpp index c122e084d..86c452e66 100644 --- a/opm/parser/eclipse/Parser/tests/ParserTestsInternalData.cpp +++ b/opm/parser/eclipse/Parser/tests/ParserTestsInternalData.cpp @@ -25,10 +25,11 @@ #include -#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 +#include +#include +#include +#include using namespace Opm; //NOTE: needs statoil dataset diff --git a/opm/parser/eclipse/RawDeck/RawDeck.cpp b/opm/parser/eclipse/RawDeck/RawDeck.cpp index 8b2c8eab0..e083cee89 100644 --- a/opm/parser/eclipse/RawDeck/RawDeck.cpp +++ b/opm/parser/eclipse/RawDeck/RawDeck.cpp @@ -55,7 +55,7 @@ namespace Opm { /// 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::readDataIntoDeck(const std::string& path) { + void RawDeck::parse(const std::string& path) { boost::filesystem::path dataFolderPath = verifyValidInputPath(path); { std::ifstream inputstream; @@ -100,7 +100,7 @@ namespace Opm { boost::filesystem::path pathToIncludedFile(dataFolderPath); pathToIncludedFile /= includeFileString; - readDataIntoDeck(pathToIncludedFile.string()); + parse(pathToIncludedFile.string()); } else { m_keywords.push_back(keyword); } diff --git a/opm/parser/eclipse/RawDeck/RawDeck.hpp b/opm/parser/eclipse/RawDeck/RawDeck.hpp index 19faf1c80..52bded6bd 100644 --- a/opm/parser/eclipse/RawDeck/RawDeck.hpp +++ b/opm/parser/eclipse/RawDeck/RawDeck.hpp @@ -43,24 +43,28 @@ namespace Opm { /// 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; bool hasKeyword(const std::string& keyword) const; - void readDataIntoDeck(const std::string& path); unsigned int getNumberOfKeywords() const; friend std::ostream& operator<<(std::ostream& os, const RawDeck& deck); virtual ~RawDeck(); + private: std::list m_keywords; RawParserKWsConstPtr m_rawParserKWs; - void readDataIntoDeck(const std::string& path, std::list& keywordList); + + + //void readDataIntoDeck(const std::string& path, std::list& keywordList); void addKeyword(RawKeywordConstPtr keyword, const boost::filesystem::path& baseDataFolder); bool isKeywordFinished(RawKeywordConstPtr rawKeyword); static boost::filesystem::path verifyValidInputPath(const std::string& inputPath); }; typedef boost::shared_ptr RawDeckPtr; + typedef boost::shared_ptr RawDeckConstPtr; } #endif /* RAWDECK_HPP */ diff --git a/opm/parser/eclipse/RawDeck/tests/CMakeLists.txt b/opm/parser/eclipse/RawDeck/tests/CMakeLists.txt index fe99362b9..ffbb2c39e 100644 --- a/opm/parser/eclipse/RawDeck/tests/CMakeLists.txt +++ b/opm/parser/eclipse/RawDeck/tests/CMakeLists.txt @@ -1,21 +1,22 @@ 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 ) -set_tests_properties(runRawRecordTests PROPERTIES LABELS Raw) add_test(NAME runRawKeywordTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runRawKeywordTests ) -set_tests_properties(runRawKeywordTests PROPERTIES LABELS Raw) -add_test(NAME runRawDeckTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runRawDeckTests ) -set_tests_properties(runRawDeckTests PROPERTIES LABELS Raw) +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 ) -set_tests_properties(runRawParserKWsTests PROPERTIES LABELS Raw) \ No newline at end of file diff --git a/opm/parser/eclipse/RawDeck/tests/RawDeckInternalDataTests.cpp b/opm/parser/eclipse/RawDeck/tests/RawDeckInternalDataTests.cpp new file mode 100644 index 000000000..2ce4bf5a3 --- /dev/null +++ b/opm/parser/eclipse/RawDeck/tests/RawDeckInternalDataTests.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 +#include + +#define BOOST_TEST_MODULE ParserTestsInternalData +#include + + +#include +#include +#include +#include +#include +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"); + std::list records = matchingKeyword->getRecords(); + BOOST_CHECK_EQUAL("OIL", matchingKeyword->getKeyword()); + + BOOST_CHECK_EQUAL((unsigned) 0, records.size()); + + matchingKeyword = rawDeck->getKeyword("VFPPDIMS"); + records = matchingKeyword->getRecords(); + BOOST_CHECK_EQUAL("VFPPDIMS", matchingKeyword->getKeyword()); + 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 recordItems = records.front()->getItems(); + BOOST_CHECK_EQUAL((unsigned) 6, recordItems.size()); +} diff --git a/opm/parser/eclipse/RawDeck/tests/RawDeckTests.cpp b/opm/parser/eclipse/RawDeck/tests/RawDeckTests.cpp index 66269d6eb..887873dba 100644 --- a/opm/parser/eclipse/RawDeck/tests/RawDeckTests.cpp +++ b/opm/parser/eclipse/RawDeck/tests/RawDeckTests.cpp @@ -19,6 +19,7 @@ #include #include +#include #define BOOST_TEST_MODULE RawDeckTests #include #include @@ -26,20 +27,125 @@ #include #include +using namespace Opm; + +BOOST_AUTO_TEST_CASE(Initialize_NoThrow) { + RawParserKWsConstPtr fixedKeywords(new RawParserKWs()); + BOOST_CHECK_NO_THROW( RawDeck rawDeck( fixedKeywords )); +} + + BOOST_AUTO_TEST_CASE(GetNumberOfKeywords_EmptyDeck_RetunsZero) { - Opm::RawParserKWsConstPtr fixedKeywords(new Opm::RawParserKWs()); - Opm::RawDeckPtr rawDeck(new Opm::RawDeck(fixedKeywords)); + RawParserKWsConstPtr fixedKeywords(new RawParserKWs()); + RawDeckPtr rawDeck(new RawDeck(fixedKeywords)); BOOST_CHECK_EQUAL((unsigned) 0, rawDeck->getNumberOfKeywords()); } BOOST_AUTO_TEST_CASE(HasKeyword_NotExisting_RetunsFalse) { - Opm::RawParserKWsConstPtr fixedKeywords(new Opm::RawParserKWs()); - Opm::RawDeckPtr rawDeck(new Opm::RawDeck(fixedKeywords)); + RawParserKWsConstPtr fixedKeywords(new RawParserKWs()); + RawDeckPtr rawDeck(new RawDeck(fixedKeywords)); BOOST_CHECK_EQUAL(false, rawDeck->hasKeyword("TEST")); } BOOST_AUTO_TEST_CASE(GetKeyword_EmptyDeck_ThrowsExeption) { - Opm::RawParserKWsConstPtr fixedKeywords(new Opm::RawParserKWs()); - Opm::RawDeckPtr rawDeck(new Opm::RawDeck(fixedKeywords)); + RawParserKWsConstPtr fixedKeywords(new RawParserKWs()); + RawDeckPtr rawDeck(new RawDeck(fixedKeywords)); BOOST_CHECK_THROW(rawDeck->getKeyword("TEST"), std::invalid_argument); } + + + +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(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"); + const std::list& records = rawKeyword->getRecords(); + BOOST_CHECK_EQUAL((unsigned) 1, records.size()); + RawRecordConstPtr record = records.back(); + + 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("NODIR", recordElements[0]); + BOOST_CHECK_EQUAL("REVERS", recordElements[1]); + BOOST_CHECK_EQUAL("1", recordElements[2]); + BOOST_CHECK_EQUAL("20", recordElements[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"); + std::list records = matchingKeyword->getRecords(); + BOOST_CHECK_EQUAL("OIL", matchingKeyword->getKeyword()); + BOOST_CHECK_EQUAL((unsigned) 0, records.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()); + + matchingKeyword = rawDeck->getKeyword("WHISTCTL"); + BOOST_CHECK_EQUAL("WHISTCTL", matchingKeyword->getKeyword()); + records = matchingKeyword->getRecords(); + BOOST_CHECK_EQUAL((unsigned) 1, records.size()); + + matchingKeyword = rawDeck->getKeyword("METRIC"); + BOOST_CHECK_EQUAL("METRIC", matchingKeyword->getKeyword()); + records = matchingKeyword->getRecords(); + BOOST_CHECK_EQUAL((unsigned) 0, records.size()); + + matchingKeyword = rawDeck->getKeyword("GRIDUNIT"); + BOOST_CHECK_EQUAL("GRIDUNIT", matchingKeyword->getKeyword()); + records = matchingKeyword->getRecords(); + BOOST_CHECK_EQUAL((unsigned) 1, records.size()); + + matchingKeyword = rawDeck->getKeyword("RADFIN4"); + records = matchingKeyword->getRecords(); + BOOST_CHECK_EQUAL("RADFIN4", matchingKeyword->getKeyword()); + BOOST_CHECK_EQUAL((unsigned) 1, records.size()); + + matchingKeyword = rawDeck->getKeyword("ABCDAD"); + BOOST_CHECK_EQUAL("ABCDAD", matchingKeyword->getKeyword()); + records = matchingKeyword->getRecords(); + + BOOST_CHECK_EQUAL((unsigned) 2, records.size()); +}