The ParserKeyword->parse() method will throw if the raw input argument is not finished.
Requires several changes to assure that the rawkeyword instances are marked as finished before reacing the ParserKeyword->parse method.
This commit is contained in:
parent
c26ba00794
commit
5becf79dd1
@ -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)
|
||||
|
60
opm/parser/eclipse/IntegrationTests/ParseDATAWithDefault.cpp
Normal file
60
opm/parser/eclipse/IntegrationTests/ParseDATAWithDefault.cpp
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define BOOST_TEST_MODULE ParserIntegrationTests
|
||||
#include <math.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Utility/PvtgTable.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
#include <opm/parser/eclipse/Deck/DeckDoubleItem.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserKeyword.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserDoubleItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserStringItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
3
testdata/integration_tests/TITLE/TITLE1.txt
vendored
3
testdata/integration_tests/TITLE/TITLE1.txt
vendored
@ -1,4 +1,5 @@
|
||||
TITLE
|
||||
This is the title of the model.
|
||||
|
||||
START
|
||||
10 'FEB' 2012
|
||||
10 'FEB' 2012 /
|
||||
|
Loading…
Reference in New Issue
Block a user