diff --git a/opm/parser/eclipse/CMakeLists.txt b/opm/parser/eclipse/CMakeLists.txt index ab1d6cbce..04af26651 100644 --- a/opm/parser/eclipse/CMakeLists.txt +++ b/opm/parser/eclipse/CMakeLists.txt @@ -5,6 +5,7 @@ add_subdirectory(Parser/tests) add_subdirectory(Generator/tests) add_subdirectory(RawDeck/tests) add_subdirectory(Deck/tests) +add_subdirectory(Units/tests) add_subdirectory(EclipseState/tests) add_subdirectory(EclipseState/Schedule/tests) add_subdirectory(EclipseState/SimulationConfig/tests) diff --git a/opm/parser/eclipse/Parser/ParserKeyword.cpp b/opm/parser/eclipse/Parser/ParserKeyword.cpp index a77118f36..9dd3353c6 100644 --- a/opm/parser/eclipse/Parser/ParserKeyword.cpp +++ b/opm/parser/eclipse/Parser/ParserKeyword.cpp @@ -78,8 +78,12 @@ namespace Opm { bool ParserKeyword::hasDimension() const { if (m_records.size() > 0) { - std::shared_ptr record = getRecord(0); - return record->hasDimension(); + bool hasDim = false; + for (auto& record : m_records) { + if (record->hasDimension()) + hasDim = true; + } + return hasDim; } else return false; } diff --git a/opm/parser/eclipse/Units/tests/CMakeLists.txt b/opm/parser/eclipse/Units/tests/CMakeLists.txt index 0194ae2fe..cba904c02 100644 --- a/opm/parser/eclipse/Units/tests/CMakeLists.txt +++ b/opm/parser/eclipse/Units/tests/CMakeLists.txt @@ -1,3 +1,3 @@ -add_executable(runUnitTests UnitTests.cpp) -target_link_libraries(runUnitTests Parser ${Boost_LIBRARIES}) -add_test(NAME runUnitTests COMMAND ${TEST_MEMCHECK_TOOL} ${EXECUTABLE_OUTPUT_PATH}/runUnitTests ) +foreach(tapp UnitTests COMPSEGUnits) + opm_add_test( run${tapp} SOURCES ${tapp}.cpp LIBRARIES opmparser ${Boost_LIBRARIES}) +endforeach() diff --git a/opm/parser/eclipse/Units/tests/COMPSEGUnits.cpp b/opm/parser/eclipse/Units/tests/COMPSEGUnits.cpp new file mode 100644 index 000000000..563e20057 --- /dev/null +++ b/opm/parser/eclipse/Units/tests/COMPSEGUnits.cpp @@ -0,0 +1,55 @@ +/* + 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 COMPSEGUNITS + +#include +#include +#include + +#include +#include +#include +#include + +using namespace Opm; + +std::shared_ptr createCOMPSEGSDeck() { + const char *deckData = + "COMPSEGS\n" + " WELL /\n" + " 1 1 1 1 100 100 X 10/\n" + "/\n"; + + Parser parser; + DeckConstPtr deck(parser.parseString(deckData, ParseMode())); + return deck; +} + + + +BOOST_AUTO_TEST_CASE(CreateDimension) { + DeckConstPtr deck = createCOMPSEGSDeck(); + std::shared_ptr keyword = deck->getKeyword(); + std::shared_ptr record = keyword->getRecord(1); + BOOST_CHECK_NO_THROW( record->getItem()->getSIDouble(0) ); +} + + + diff --git a/opm/parser/eclipse/Units/tests/UnitTests.cpp b/opm/parser/eclipse/Units/tests/UnitTests.cpp index 202e10e00..2bc766bc0 100644 --- a/opm/parser/eclipse/Units/tests/UnitTests.cpp +++ b/opm/parser/eclipse/Units/tests/UnitTests.cpp @@ -41,11 +41,6 @@ BOOST_AUTO_TEST_CASE(makeComposite) { BOOST_CHECK_EQUAL(100 , composite->getSIScaling()); } -BOOST_AUTO_TEST_CASE(MakeCompositeInvalid) { - // conversion to SI temperatures requires an offset, but such - // composite units are (currently?) invalid - BOOST_CHECK_THROW(Dimension::newComposite("Length*Temperature", 100), std::logic_error); -} BOOST_AUTO_TEST_CASE(CreateDimensionInvalidNameThrows) { BOOST_CHECK_THROW(Dimension(" " , 1) , std::invalid_argument); @@ -58,13 +53,13 @@ BOOST_AUTO_TEST_CASE(CreateDimensionInvalidNameThrows) { BOOST_AUTO_TEST_CASE(CreateUnitSystem) { - UnitSystem system("Metric"); + UnitSystem system(UnitSystem::UNIT_TYPE_METRIC); BOOST_CHECK_EQUAL("Metric" , system.getName()); } BOOST_AUTO_TEST_CASE(UnitSystemEmptyHasNone) { - UnitSystem system("Metric"); + UnitSystem system(UnitSystem::UNIT_TYPE_METRIC); BOOST_CHECK_EQUAL( false , system.hasDimension("Length")); BOOST_CHECK_EQUAL( false , system.hasDimension("LXY")); } @@ -72,12 +67,12 @@ BOOST_AUTO_TEST_CASE(UnitSystemEmptyHasNone) { BOOST_AUTO_TEST_CASE(UnitSystemGetMissingDimensionThrows) { - UnitSystem system("Metric"); + UnitSystem system(UnitSystem::UNIT_TYPE_METRIC); BOOST_CHECK_THROW( system.getDimension("Length") , std::invalid_argument ); } BOOST_AUTO_TEST_CASE(UnitSystemGetNewOK) { - UnitSystem system("Metric"); + UnitSystem system(UnitSystem::UNIT_TYPE_METRIC); system.addDimension("Length" , 10 ); system.addDimension("Time" , 100); @@ -91,7 +86,7 @@ BOOST_AUTO_TEST_CASE(UnitSystemGetNewOK) { BOOST_AUTO_TEST_CASE(UnitSystemAddDimensions) { - UnitSystem system("Metric"); + UnitSystem system(UnitSystem::UNIT_TYPE_METRIC); system.addDimension("Length" , 1 ); system.addDimension("Time" , 86400 ); system.addDimension("Temperature", 1.0, 273.15); @@ -111,7 +106,7 @@ BOOST_AUTO_TEST_CASE(UnitSystemAddDimensions) { BOOST_AUTO_TEST_CASE(UnitSystemParseInvalidThrows) { - UnitSystem system("Metric"); + UnitSystem system(UnitSystem::UNIT_TYPE_METRIC); BOOST_CHECK_THROW( system.parse("//") , std::invalid_argument); BOOST_CHECK_THROW( system.parse("Length * Length / Time") , std::invalid_argument);