Merged in documentation
This commit is contained in:
@@ -1,15 +1,40 @@
|
||||
add_executable(runParserTests ParserTests.cpp)
|
||||
add_executable(runRawDataTests RawDataStructuresTests.cpp)
|
||||
add_executable(runParserTestsInternalData ParserTestsInternalData.cpp)
|
||||
|
||||
add_executable(runRawRecordTests RawRecordTests.cpp)
|
||||
add_executable(runRawKeywordTests RawKeywordTests.cpp)
|
||||
add_executable(runRawDeckTests RawDeckTests.cpp)
|
||||
add_executable(runRawParserKWsTests RawParserKWsTests.cpp)
|
||||
|
||||
add_executable(runParserKWTests ParserKWTests.cpp)
|
||||
add_executable(runParserRecordSizeTests ParserRecordSizeTests.cpp)
|
||||
|
||||
target_link_libraries(runParserTests Parser Logger ${Boost_LIBRARIES})
|
||||
target_link_libraries(runRawDataTests Parser Logger ${Boost_LIBRARIES})
|
||||
target_link_libraries(runParserTestsInternalData Parser Logger ${Boost_LIBRARIES})
|
||||
|
||||
target_link_libraries(runRawRecordTests Parser Logger ${Boost_LIBRARIES})
|
||||
target_link_libraries(runRawKeywordTests 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})
|
||||
|
||||
add_test(NAME runParserTests WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${EXECUTABLE_OUTPUT_PATH}/runParserTests )
|
||||
add_test(NAME runParserTestsInternalData WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${EXECUTABLE_OUTPUT_PATH}/runParserTestsInternalData)
|
||||
set_tests_properties(runParserTestsInternalData PROPERTIES LABELS Statoil)
|
||||
|
||||
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 runRawParserKWsTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runRawParserKWsTests )
|
||||
set_tests_properties(runRawParserKWsTests PROPERTIES LABELS Raw)
|
||||
|
||||
add_test(NAME runParserTests WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} COMMAND ${EXECUTABLE_OUTPUT_PATH}/runParserTests )
|
||||
add_test(NAME runRawDataTests WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} COMMAND ${EXECUTABLE_OUTPUT_PATH}/runRawDataTests )
|
||||
add_test(NAME runParserKWTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runParserKWTests )
|
||||
add_test(NAME runParserRecordSizeTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runParserRecordSizeTests )
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
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 ParserTests
|
||||
@@ -26,35 +26,30 @@
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Initialize) {
|
||||
BOOST_REQUIRE_NO_THROW( ParserKW parserKW );
|
||||
|
||||
ParserKW parserKW;
|
||||
BOOST_REQUIRE_EQUAL( parserKW.getName() , "");
|
||||
}
|
||||
BOOST_REQUIRE_NO_THROW(ParserKW parserKW);
|
||||
|
||||
ParserKW parserKW;
|
||||
BOOST_CHECK_EQUAL(parserKW.getName(), "");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(NamedInit) {
|
||||
std::string keyword("KEYWORD");
|
||||
|
||||
ParserRecordSizeConstPtr recordSize( new ParserRecordSize( 100 ));
|
||||
ParserKW parserKW( keyword , recordSize);
|
||||
BOOST_REQUIRE_EQUAL( parserKW.getName( ) , keyword );
|
||||
|
||||
ParserRecordSizeConstPtr recordSize(new ParserRecordSize(100));
|
||||
ParserKW parserKW(keyword, recordSize);
|
||||
BOOST_CHECK_EQUAL(parserKW.getName(), keyword);
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(NameTooLong) {
|
||||
std::string keyword("KEYWORDTOOLONG");
|
||||
ParserRecordSizeConstPtr recordSize( new ParserRecordSize( 100 ));
|
||||
BOOST_REQUIRE_THROW( ParserKW parserKW( keyword , recordSize ) , std::invalid_argument );
|
||||
ParserRecordSizeConstPtr recordSize(new ParserRecordSize(100));
|
||||
BOOST_CHECK_THROW(ParserKW parserKW(keyword, recordSize), std::invalid_argument);
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(MixedCase) {
|
||||
std::string keyword("KeyWord");
|
||||
|
||||
ParserRecordSizeConstPtr recordSize( new ParserRecordSize( 100 ));
|
||||
BOOST_REQUIRE_THROW( ParserKW parserKW( keyword , recordSize ) , std::invalid_argument );
|
||||
|
||||
ParserRecordSizeConstPtr recordSize(new ParserRecordSize(100));
|
||||
BOOST_CHECK_THROW(ParserKW parserKW(keyword, recordSize), std::invalid_argument);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
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 ParserTests
|
||||
@@ -26,21 +26,18 @@
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Initialize) {
|
||||
BOOST_REQUIRE_NO_THROW( ParserRecordSize recordSize );
|
||||
BOOST_REQUIRE_NO_THROW(ParserRecordSize recordSize);
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(DynamicSize) {
|
||||
ParserRecordSize recordSize;
|
||||
BOOST_REQUIRE_THROW( recordSize.recordSize() , std::logic_error );
|
||||
BOOST_CHECK_THROW(recordSize.recordSize(), std::logic_error);
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(FixedSize) {
|
||||
BOOST_REQUIRE_NO_THROW( ParserRecordSize recordSize(100) );
|
||||
BOOST_REQUIRE_NO_THROW(ParserRecordSize recordSize(100));
|
||||
ParserRecordSize recordSize(100);
|
||||
|
||||
BOOST_REQUIRE_EQUAL( recordSize.recordSize() , (size_t) 100 );
|
||||
|
||||
BOOST_CHECK_EQUAL(recordSize.recordSize(), (size_t) 100);
|
||||
}
|
||||
|
||||
@@ -20,9 +20,6 @@
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#define BOOST_TEST_MODULE ParserTests
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
@@ -33,105 +30,116 @@
|
||||
#include "opm/parser/eclipse/RawDeck/RawDeck.hpp"
|
||||
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_REQUIRE_NO_THROW(Parser parser);
|
||||
BOOST_CHECK_NO_THROW(Parser parser);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParseWithInvalidInputFileThrows) {
|
||||
ParserPtr parser(new Parser());
|
||||
BOOST_REQUIRE_THROW(parser -> parse("nonexistingfile.asdf"), std::invalid_argument);
|
||||
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_REQUIRE_NO_THROW(parser -> parse(singleKeywordFile.string()));
|
||||
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_REQUIRE_THROW(parser -> parse(singleKeywordFile.string()), std::invalid_argument);
|
||||
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");
|
||||
boost::filesystem::path singleKeywordFile("testdata/mini.data");
|
||||
|
||||
ParserPtr parser(new Parser());
|
||||
ParserPtr parser(new Parser());
|
||||
|
||||
RawDeckPtr rawDeck = parser -> parse(singleKeywordFile.string());
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 1, rawDeck -> getNumberOfKeywords());
|
||||
RawKeywordPtr rawKeyword = rawDeck->getKeyword("ENDSCALE");
|
||||
std::list<RawRecordPtr> records;
|
||||
rawKeyword -> getRecords(records);
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 1, records.size());
|
||||
RawRecordPtr record = records.back();
|
||||
|
||||
std::string recordString;
|
||||
record -> getRecordString(recordString);
|
||||
BOOST_REQUIRE_EQUAL("'NODIR' 'REVERS' 1 20", recordString);
|
||||
|
||||
std::vector<std::string> recordElements;
|
||||
record -> getRecords(recordElements);
|
||||
BOOST_REQUIRE_EQUAL((unsigned)4, recordElements.size());
|
||||
|
||||
BOOST_REQUIRE_EQUAL("NODIR", recordElements[0]);
|
||||
BOOST_REQUIRE_EQUAL("REVERS", recordElements[1]);
|
||||
BOOST_REQUIRE_EQUAL("1", recordElements[2]);
|
||||
BOOST_REQUIRE_EQUAL("20", recordElements[3]);
|
||||
RawDeckPtr rawDeck = parser->parse(singleKeywordFile.string());
|
||||
BOOST_CHECK_EQUAL((unsigned) 1, rawDeck->getNumberOfKeywords());
|
||||
RawKeywordConstPtr rawKeyword = rawDeck->getKeyword("ENDSCALE");
|
||||
const std::list<RawRecordConstPtr>& 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::vector<std::string>& 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");
|
||||
boost::filesystem::path singleKeywordFile("testdata/small.data");
|
||||
|
||||
ParserPtr parser(new Parser());
|
||||
ParserPtr parser(new Parser());
|
||||
|
||||
RawDeckPtr rawDeck = parser -> parse(singleKeywordFile.string());
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 4, rawDeck -> getNumberOfKeywords());
|
||||
RawDeckPtr rawDeck = parser->parse(singleKeywordFile.string());
|
||||
BOOST_CHECK_EQUAL((unsigned) 7, rawDeck->getNumberOfKeywords());
|
||||
|
||||
RawKeywordPtr matchingKeyword = rawDeck -> getKeyword("INCLUDE");
|
||||
BOOST_REQUIRE_EQUAL("INCLUDE", matchingKeyword->getKeyword());
|
||||
RawKeywordConstPtr matchingKeyword = rawDeck->getKeyword("OIL");
|
||||
std::list<RawRecordConstPtr> records = matchingKeyword->getRecords();
|
||||
BOOST_CHECK_EQUAL("OIL", matchingKeyword->getKeyword());
|
||||
BOOST_CHECK_EQUAL((unsigned) 0, records.size());
|
||||
|
||||
std::list<RawRecordPtr> records;
|
||||
matchingKeyword->getRecords(records);
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 1, 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());
|
||||
|
||||
RawRecordPtr theRecord = records.front();
|
||||
std::string recordString;
|
||||
theRecord -> getRecordString(recordString);
|
||||
BOOST_REQUIRE_EQUAL("\'sti til fil/den er her\'", recordString);
|
||||
|
||||
RawKeywordPtr matchingKeyword2 = rawDeck -> getKeyword("ABCDAD");
|
||||
BOOST_REQUIRE_EQUAL("ABCDAD", matchingKeyword2->getKeyword());
|
||||
matchingKeyword = rawDeck->getKeyword("WHISTCTL");
|
||||
BOOST_CHECK_EQUAL("WHISTCTL", matchingKeyword->getKeyword());
|
||||
records = matchingKeyword->getRecords();
|
||||
BOOST_CHECK_EQUAL((unsigned) 1, records.size());
|
||||
|
||||
std::list<RawRecordPtr> records2;
|
||||
matchingKeyword2->getRecords(records2);
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 2, records2.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());
|
||||
}
|
||||
|
||||
//NOTE: needs statoil dataset
|
||||
BOOST_AUTO_TEST_CASE(ParserAddKW) {
|
||||
Parser parser;
|
||||
{
|
||||
ParserRecordSizePtr recordSize(new ParserRecordSize(9));
|
||||
ParserKWPtr equilKW(new ParserKW("EQUIL", recordSize));
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParseFileWithManyKeywords) {
|
||||
boost::filesystem::path multipleKeywordFile("testdata/statoil/gurbat_trimmed.DATA");
|
||||
|
||||
ParserPtr parser(new Parser());
|
||||
|
||||
RawDeckPtr rawDeck = parser -> parse(multipleKeywordFile.string());
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 18, rawDeck -> getNumberOfKeywords());
|
||||
}
|
||||
|
||||
//NOTE: needs statoil dataset
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParseFullTestFile) {
|
||||
boost::filesystem::path multipleKeywordFile("testdata/statoil/ECLIPSE.DATA");
|
||||
|
||||
ParserPtr parser(new Parser());
|
||||
|
||||
RawDeckPtr rawDeck = parser -> parse(multipleKeywordFile.string());
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 73, rawDeck -> getNumberOfKeywords());
|
||||
parser.addKW(equilKW);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
77
tests/ParserTestsInternalData.cpp
Normal file
77
tests/ParserTestsInternalData.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#define BOOST_TEST_MODULE ParserTestsInternalData
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
|
||||
#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"
|
||||
using namespace Opm;
|
||||
|
||||
//NOTE: needs statoil dataset
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParseFileWithManyKeywords) {
|
||||
boost::filesystem::path multipleKeywordFile("testdata/statoil/gurbat_trimmed.DATA");
|
||||
std::cout << "BOOST path running ParseFullTestFile\n";
|
||||
|
||||
ParserPtr parser(new Parser());
|
||||
|
||||
RawDeckPtr rawDeck = parser->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");
|
||||
|
||||
ParserPtr parser(new Parser());
|
||||
|
||||
RawDeckPtr rawDeck = parser->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<RawRecordConstPtr> 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::vector<std::string> recordItems = records.front()->getItems();
|
||||
BOOST_CHECK_EQUAL((unsigned) 6, recordItems.size());
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define BOOST_TEST_MODULE ParserTests
|
||||
#include <stdexcept>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawKeyword.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawRecord.hpp>
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RawKeywordEmptyConstructorEmptyKeyword) {
|
||||
Opm::RawKeyword keyword;
|
||||
BOOST_CHECK(keyword.getKeyword() == "");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RawKeywordGiveKeywordToConstructorKeywordSet) {
|
||||
Opm::RawKeyword keyword("KEYYWORD");
|
||||
BOOST_CHECK(keyword.getKeyword() == "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_AUTO_TEST_CASE(RawKeywordSetKeywordInitialWhitespaceInKeywordThrows) {
|
||||
Opm::RawKeyword keyword;
|
||||
BOOST_CHECK_THROW(keyword.setKeyword(" TELONG"), std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RawKeywordSetKeywordInitialTabInKeywordThrows) {
|
||||
Opm::RawKeyword keyword;
|
||||
BOOST_CHECK_THROW(keyword.setKeyword("\tTELONG"), std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RawKeywordSetCorrectLenghtKeywordNoError) {
|
||||
Opm::RawKeyword keyword;
|
||||
keyword.setKeyword("GOODONE");
|
||||
BOOST_CHECK(keyword.getKeyword() == "GOODONE");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RawKeywordSet8CharKeywordWithTrailingWhitespaceKeywordTrimmed) {
|
||||
Opm::RawKeyword keyword;
|
||||
keyword.setKeyword("GOODONEE ");
|
||||
BOOST_CHECK(keyword.getKeyword() == "GOODONEE");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RawRecordGetRecordStringReturnsTrimmedString) {
|
||||
Opm::RawRecordPtr record(new Opm::RawRecord(" 'NODIR ' 'REVERS' 1 20 /"));
|
||||
std::string recordString;
|
||||
record -> getRecordString(recordString);
|
||||
BOOST_REQUIRE_EQUAL("'NODIR ' 'REVERS' 1 20", recordString);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RawRecordGetRecordsCorrectElementsReturned) {
|
||||
Opm::RawRecordPtr record(new Opm::RawRecord(" 'NODIR ' 'REVERS' 1 20 /"));
|
||||
|
||||
std::vector<std::string> recordElements;
|
||||
record -> getRecords(recordElements);
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 4, recordElements.size());
|
||||
|
||||
BOOST_REQUIRE_EQUAL("NODIR ", recordElements[0]);
|
||||
BOOST_REQUIRE_EQUAL("REVERS", recordElements[1]);
|
||||
BOOST_REQUIRE_EQUAL("1", recordElements[2]);
|
||||
BOOST_REQUIRE_EQUAL("20", recordElements[3]);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RawRecordIsCompleteRecordCompleteRecordReturnsTrue) {
|
||||
bool isComplete = Opm::RawRecord::isCompleteRecordString("'NODIR ' 'REVERS' 1 20 /");
|
||||
BOOST_REQUIRE_EQUAL(true, isComplete);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RawRecordIsCompleteRecordInCompleteRecordReturnsFalse) {
|
||||
bool isComplete = Opm::RawRecord::isCompleteRecordString("'NODIR ' 'REVERS' 1 20 ");
|
||||
BOOST_REQUIRE_EQUAL(false, isComplete);
|
||||
isComplete = Opm::RawRecord::isCompleteRecordString("'NODIR ' 'REVERS 1 20 /");
|
||||
BOOST_REQUIRE_EQUAL(false, isComplete);
|
||||
}
|
||||
46
tests/RawDeckTests.cpp
Normal file
46
tests/RawDeckTests.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#define BOOST_TEST_MODULE RawDeckTests
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawDeck.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawParserKWs.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawKeyword.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(GetNumberOfKeywords_EmptyDeck_RetunsZero) {
|
||||
Opm::RawParserKWsConstPtr fixedKeywords(new Opm::RawParserKWs());
|
||||
Opm::RawDeckPtr rawDeck(new Opm::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));
|
||||
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));
|
||||
BOOST_CHECK_THROW(rawDeck->getKeyword("TEST"), std::invalid_argument);
|
||||
}
|
||||
64
tests/RawKeywordTests.cpp
Normal file
64
tests/RawKeywordTests.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define BOOST_TEST_MODULE RawKeywordTests
|
||||
#include <stdexcept>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawKeyword.hpp>
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RawKeywordEmptyConstructorEmptyKeyword) {
|
||||
Opm::RawKeyword keyword;
|
||||
BOOST_CHECK(keyword.getKeyword() == "");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RawKeywordGiveKeywordToConstructorKeywordSet) {
|
||||
Opm::RawKeyword keyword("KEYYWORD");
|
||||
BOOST_CHECK(keyword.getKeyword() == "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_AUTO_TEST_CASE(RawKeywordSetKeywordInitialWhitespaceInKeywordThrows) {
|
||||
Opm::RawKeyword keyword;
|
||||
BOOST_CHECK_THROW(keyword.setKeyword(" TELONG"), std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RawKeywordSetKeywordInitialTabInKeywordThrows) {
|
||||
Opm::RawKeyword keyword;
|
||||
BOOST_CHECK_THROW(keyword.setKeyword("\tTELONG"), std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RawKeywordSetCorrectLenghtKeywordNoError) {
|
||||
Opm::RawKeyword keyword;
|
||||
keyword.setKeyword("GOODONE");
|
||||
BOOST_CHECK(keyword.getKeyword() == "GOODONE");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RawKeywordSet8CharKeywordWithTrailingWhitespaceKeywordTrimmed) {
|
||||
Opm::RawKeyword keyword;
|
||||
keyword.setKeyword("GOODONEE ");
|
||||
BOOST_CHECK(keyword.getKeyword() == "GOODONEE");
|
||||
}
|
||||
51
tests/RawParserKWsTests.cpp
Normal file
51
tests/RawParserKWsTests.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#define BOOST_TEST_MODULE RawParserKWsTests
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawDeck.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawParserKWs.hpp>
|
||||
using namespace Opm;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(KeywordExists_KeywordNotPresent_ReturnsFalse) {
|
||||
RawParserKWsConstPtr parserKWs(new RawParserKWs());
|
||||
BOOST_CHECK_EQUAL(false, parserKWs->keywordExists("FLASKE"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(KeywordExists_KeywordPresent_ReturnsTrue) {
|
||||
RawParserKWsConstPtr parserKWs(new RawParserKWs());
|
||||
BOOST_CHECK_EQUAL(true, parserKWs->keywordExists("TITLE"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(GetFixedNumberOfRecords_KeywordNotPresent_ThrowsException) {
|
||||
RawParserKWsConstPtr parserKWs(new RawParserKWs());
|
||||
BOOST_CHECK_THROW(parserKWs->getFixedNumberOfRecords("FLASKE"), std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(GetFixedNumberOfRecords_OneRecord_ReturnsOne) {
|
||||
RawParserKWsConstPtr parserKWs(new RawParserKWs());
|
||||
BOOST_CHECK_EQUAL((unsigned) 1, parserKWs->getFixedNumberOfRecords("GRIDUNIT"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(GetFixedNumberOfRecords_ZeroRecords_ReturnsZero) {
|
||||
RawParserKWsConstPtr parserKWs(new RawParserKWs());
|
||||
BOOST_CHECK_EQUAL((unsigned) 0, parserKWs->getFixedNumberOfRecords("METRIC"));
|
||||
}
|
||||
53
tests/RawRecordTests.cpp
Normal file
53
tests/RawRecordTests.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define BOOST_TEST_MODULE ParserTests
|
||||
#include <stdexcept>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawRecord.hpp>
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RawRecordGetRecordStringReturnsTrimmedString) {
|
||||
Opm::RawRecordPtr record(new Opm::RawRecord(" 'NODIR ' 'REVERS' 1 20 /"));
|
||||
const std::string& recordString = record->getRecordString();
|
||||
BOOST_CHECK_EQUAL("'NODIR ' 'REVERS' 1 20", recordString);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RawRecordGetRecordsCorrectElementsReturned) {
|
||||
Opm::RawRecordPtr record(new Opm::RawRecord(" 'NODIR ' 'REVERS' 1 20 /"));
|
||||
|
||||
const std::vector<std::string>& 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(RawRecordIsCompleteRecordCompleteRecordReturnsTrue) {
|
||||
bool isComplete = Opm::RawRecord::isTerminatedRecordString("'NODIR ' 'REVERS' 1 20 /");
|
||||
BOOST_CHECK_EQUAL(true, isComplete);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RawRecordIsCompleteRecordInCompleteRecordReturnsFalse) {
|
||||
bool isComplete = Opm::RawRecord::isTerminatedRecordString("'NODIR ' 'REVERS' 1 20 ");
|
||||
BOOST_CHECK_EQUAL(false, isComplete);
|
||||
isComplete = Opm::RawRecord::isTerminatedRecordString("'NODIR ' 'REVERS 1 20 /");
|
||||
BOOST_CHECK_EQUAL(false, isComplete);
|
||||
}
|
||||
Reference in New Issue
Block a user