diff --git a/opm/parser/eclipse/IntegrationTests/CMakeLists.txt b/opm/parser/eclipse/IntegrationTests/CMakeLists.txt index 71e223a44..e69c022be 100644 --- a/opm/parser/eclipse/IntegrationTests/CMakeLists.txt +++ b/opm/parser/eclipse/IntegrationTests/CMakeLists.txt @@ -18,6 +18,11 @@ add_executable(runParsePORO ParsePORO.cpp) target_link_libraries(runParsePORO Parser ${Boost_LIBRARIES}) add_test(NAME runParsePORO WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} COMMAND ${TEST_MEMCHECK_TOOL} ${EXECUTABLE_OUTPUT_PATH}/runParsePORO) +add_executable(runParseDATAWithDefault ParseDATAWithDefault.cpp) +target_link_libraries(runParseDATAWithDefault Parser ${Boost_LIBRARIES}) +add_test(NAME runParseDATAWithDefault WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} COMMAND ${TEST_MEMCHECK_TOOL} ${EXECUTABLE_OUTPUT_PATH}/runParseDATAWithDefault) + + add_executable(runParseTVDP ParseTVDP.cpp) target_link_libraries(runParseTVDP Parser ${Boost_LIBRARIES}) add_test(NAME runParseTVDP WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} COMMAND ${TEST_MEMCHECK_TOOL} ${EXECUTABLE_OUTPUT_PATH}/runParseTVDP) diff --git a/opm/parser/eclipse/IntegrationTests/ParseDATAWithDefault.cpp b/opm/parser/eclipse/IntegrationTests/ParseDATAWithDefault.cpp new file mode 100644 index 000000000..66bf76aba --- /dev/null +++ b/opm/parser/eclipse/IntegrationTests/ParseDATAWithDefault.cpp @@ -0,0 +1,60 @@ +/* + Copyright (C) 2014 Statoil ASE + + 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 ParserIntegrationTests +#include + +#include +#include + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +using namespace Opm; + + + +const char *dataMissingRecord = "\n\ +ENDSCALE\n\ + 1* 1* 2 /\n\ +\n\ +ENKRVD\n\ +100 1 2 3 4 5 6 7 200 11 22 33 44 55 66 77 /\n\ +"; + + + +BOOST_AUTO_TEST_CASE( ParseMissingRECORD_THrows) { + ParserPtr parser(new Parser()); + BOOST_CHECK_THROW( parser->parseString( dataMissingRecord ) , std::invalid_argument); +} + + + + diff --git a/opm/parser/eclipse/Parser/Parser.cpp b/opm/parser/eclipse/Parser/Parser.cpp index cf40c10a9..b4c4aa243 100644 --- a/opm/parser/eclipse/Parser/Parser.cpp +++ b/opm/parser/eclipse/Parser/Parser.cpp @@ -347,6 +347,7 @@ namespace Opm { } else { if (parserState->rawKeyword->getSizeType() == Raw::UNKNOWN) { if (canParseKeyword(line)) { + parserState->rawKeyword->finalizeUnknownSize(); parserState->nextKeyword = line; return true; } @@ -359,6 +360,8 @@ namespace Opm { if (parserState->rawKeyword != NULL && parserState->rawKeyword->isFinished()) return true; } + if (parserState->rawKeyword && parserState->rawKeyword->getSizeType() == Raw::UNKNOWN) + parserState->rawKeyword->finalizeUnknownSize(); return false; } diff --git a/opm/parser/eclipse/Parser/ParserKeyword.cpp b/opm/parser/eclipse/Parser/ParserKeyword.cpp index fce8096be..8a0a6d0f9 100644 --- a/opm/parser/eclipse/Parser/ParserKeyword.cpp +++ b/opm/parser/eclipse/Parser/ParserKeyword.cpp @@ -386,12 +386,15 @@ namespace Opm { } DeckKeywordPtr ParserKeyword::parse(RawKeywordConstPtr rawKeyword) const { - DeckKeywordPtr keyword(new DeckKeyword(rawKeyword->getKeywordName())); - for (size_t i = 0; i < rawKeyword->size(); i++) { - DeckRecordConstPtr deckRecord = m_record->parse(rawKeyword->getRecord(i)); - keyword->addRecord(deckRecord); - } - return keyword; + if (rawKeyword->isFinished()) { + DeckKeywordPtr keyword(new DeckKeyword(rawKeyword->getKeywordName())); + for (size_t i = 0; i < rawKeyword->size(); i++) { + DeckRecordConstPtr deckRecord = m_record->parse(rawKeyword->getRecord(i)); + keyword->addRecord(deckRecord); + } + return keyword; + } else + throw std::invalid_argument("Tried to create a deck keyword from an imcomplete rawkeyword: " + rawKeyword->getKeywordName()); } size_t ParserKeyword::getFixedSize() const { diff --git a/opm/parser/eclipse/RawDeck/RawKeyword.cpp b/opm/parser/eclipse/RawDeck/RawKeyword.cpp index 6074cd069..d760c522e 100644 --- a/opm/parser/eclipse/RawDeck/RawKeyword.cpp +++ b/opm/parser/eclipse/RawDeck/RawKeyword.cpp @@ -175,6 +175,14 @@ namespace Opm { } + void RawKeyword::finalizeUnknownSize() { + if (m_sizeType == Raw::UNKNOWN) + m_isFinished = true; + else + throw std::invalid_argument("Fatal error finalizing keyword:" + m_name + " Only RawKeywords with UNKNOWN size can be explicitly finalized."); + } + + bool RawKeyword::isFinished() const { return m_isFinished; } diff --git a/opm/parser/eclipse/RawDeck/RawKeyword.hpp b/opm/parser/eclipse/RawDeck/RawKeyword.hpp index 4760704b0..af573d5b4 100644 --- a/opm/parser/eclipse/RawDeck/RawKeyword.hpp +++ b/opm/parser/eclipse/RawDeck/RawKeyword.hpp @@ -54,6 +54,7 @@ namespace Opm { bool isPartialRecordStringEmpty() const; bool isFinished() const; bool unKnownSize() const; + void finalizeUnknownSize(); const std::string& getFilename() const; size_t getLineNR() const; diff --git a/opm/parser/eclipse/RawDeck/tests/RawKeywordTests.cpp b/opm/parser/eclipse/RawDeck/tests/RawKeywordTests.cpp index 46af98311..85642f512 100644 --- a/opm/parser/eclipse/RawDeck/tests/RawKeywordTests.cpp +++ b/opm/parser/eclipse/RawDeck/tests/RawKeywordTests.cpp @@ -37,6 +37,21 @@ BOOST_AUTO_TEST_CASE(RawKeywordSizeTypeInvalidThrows) { BOOST_CHECK_THROW( RawKeyword("KEYYWORD", Raw::TABLE_COLLECTION , "FILE" , 10U) , std::invalid_argument); } +BOOST_AUTO_TEST_CASE(RawKeywordFinalizeWrongSizeTYpeThrows) { + RawKeyword kw("KEYYWORD", Raw::SLASH_TERMINATED , "FILE" , 0U); + BOOST_CHECK_THROW( kw.finalizeUnknownSize() , std::invalid_argument ); +} + + +BOOST_AUTO_TEST_CASE(RawKeywordFinalizeUnknownSize) { + RawKeyword kw("KEYYWORD", Raw::UNKNOWN , "FILE" , 0U); + BOOST_CHECK( !kw.isFinished() ); + kw.finalizeUnknownSize(); + BOOST_CHECK( kw.isFinished() ); +} + + + BOOST_AUTO_TEST_CASE(RawKeywordGiveKeywordToConstructorTooLongThrows) { BOOST_CHECK_THROW(RawKeyword keyword("KEYYYWORD", Raw::SLASH_TERMINATED , "FILE" , 10U), std::invalid_argument); diff --git a/testdata/integration_tests/TITLE/TITLE1.txt b/testdata/integration_tests/TITLE/TITLE1.txt index 9f23e7fd1..c16369ff0 100644 --- a/testdata/integration_tests/TITLE/TITLE1.txt +++ b/testdata/integration_tests/TITLE/TITLE1.txt @@ -1,4 +1,5 @@ TITLE This is the title of the model. + START - 10 'FEB' 2012 + 10 'FEB' 2012 /