From bf3be4695d2470c383d9286f07105de85bb1861b Mon Sep 17 00:00:00 2001 From: Kristian Flikka Date: Mon, 6 May 2013 12:13:49 +0200 Subject: [PATCH] Refactoring, prefixing parser setup classes with Parser. 4 space indent. --- opm/parser/eclipse/CMakeLists.txt | 2 +- opm/parser/eclipse/Logger/Logger.cpp | 90 +++---- opm/parser/eclipse/Logger/Logger.hpp | 47 ++-- opm/parser/eclipse/Parser/ItemSize.cpp | 64 ----- opm/parser/eclipse/Parser/Parser.cpp | 32 +-- opm/parser/eclipse/Parser/Parser.hpp | 33 +-- opm/parser/eclipse/Parser/ParserConst.hpp | 6 +- opm/parser/eclipse/Parser/ParserEnums.hpp | 23 +- opm/parser/eclipse/Parser/ParserItem.hpp | 84 +++++++ opm/parser/eclipse/Parser/ParserItemSize.cpp | 61 +++++ .../{ItemSize.hpp => ParserItemSize.hpp} | 37 ++- opm/parser/eclipse/Parser/ParserKW.cpp | 34 +-- opm/parser/eclipse/Parser/ParserKW.hpp | 24 +- .../eclipse/Parser/ParserRecordItem.hpp | 87 ------- .../eclipse/Parser/ParserRecordSize.cpp | 32 +-- .../eclipse/Parser/ParserRecordSize.hpp | 24 +- opm/parser/eclipse/RawDeck/RawConsts.hpp | 16 +- opm/parser/eclipse/RawDeck/RawDeck.cpp | 232 +++++++++--------- opm/parser/eclipse/RawDeck/RawDeck.hpp | 55 +++-- opm/parser/eclipse/RawDeck/RawKeyword.cpp | 167 ++++++------- opm/parser/eclipse/RawDeck/RawKeyword.hpp | 1 + opm/parser/eclipse/RawDeck/RawParserKWs.cpp | 94 +++---- opm/parser/eclipse/RawDeck/RawParserKWs.hpp | 31 +-- opm/parser/eclipse/RawDeck/RawRecord.cpp | 202 +++++++-------- opm/parser/eclipse/RawDeck/RawRecord.hpp | 51 ++-- tests/ParserItemSizeTests.cpp | 49 ++-- tests/ParserKWTests.cpp | 26 +- tests/ParserRecordItemTest.cpp | 4 +- tests/ParserRecordItemTests.cpp | 142 +++++------ tests/ParserRecordSizeTests.cpp | 12 +- tests/ParserTests.cpp | 136 +++++----- tests/ParserTestsInternalData.cpp | 52 ++-- tests/RawDeckTests.cpp | 19 +- tests/RawKeywordTests.cpp | 34 +-- tests/RawParserKWsTests.cpp | 20 +- tests/RawRecordTests.cpp | 32 +-- 36 files changed, 1024 insertions(+), 1031 deletions(-) delete mode 100644 opm/parser/eclipse/Parser/ItemSize.cpp create mode 100644 opm/parser/eclipse/Parser/ParserItem.hpp create mode 100644 opm/parser/eclipse/Parser/ParserItemSize.cpp rename opm/parser/eclipse/Parser/{ItemSize.hpp => ParserItemSize.hpp} (57%) delete mode 100644 opm/parser/eclipse/Parser/ParserRecordItem.hpp diff --git a/opm/parser/eclipse/CMakeLists.txt b/opm/parser/eclipse/CMakeLists.txt index 94e0a7357..698f719ad 100644 --- a/opm/parser/eclipse/CMakeLists.txt +++ b/opm/parser/eclipse/CMakeLists.txt @@ -12,7 +12,7 @@ set( parser_source Parser/ParserRecordSize.cpp Parser/ParserKW.cpp Parser/Parser.cpp -Parser/ItemSize.cpp ) +Parser/ParserItemSize.cpp ) add_library(Parser ${rawdeck_source} ${parser_source}) diff --git a/opm/parser/eclipse/Logger/Logger.cpp b/opm/parser/eclipse/Logger/Logger.cpp index 5e14e7551..bfc2ebb86 100644 --- a/opm/parser/eclipse/Logger/Logger.cpp +++ b/opm/parser/eclipse/Logger/Logger.cpp @@ -23,60 +23,64 @@ using namespace boost::posix_time; #include "Logger.hpp" namespace Opm { - - /// The log levels, used to avoid clutter in the log - const int Logger::DEBUG = 0; - const int Logger::INFO = 1; - const int Logger::ERROR = 2; - std::string Logger::m_logFile = "log.log"; - int Logger::m_logLevel = INFO; - std::ofstream Logger::m_logStream; + /// The log levels, used to avoid clutter in the log + const int Logger::DEBUG = 0; + const int Logger::INFO = 1; + const int Logger::ERROR = 2; - void Logger::setLogLevel(int logLevel) { - m_logLevel = logLevel; - } + std::string Logger::m_logFile = "log.log"; + int Logger::m_logLevel = INFO; + std::ofstream Logger::m_logStream; - /// Changes the default path from log.log to path - void Logger::setPath(const std::string& path) { - m_logFile = path; - } - - /// Logs a debug message - void Logger::debug(const std::string& message) { - if (m_logLevel <= DEBUG) { - log(message, "DEBUG"); + void Logger::setLogLevel(int logLevel) { + m_logLevel = logLevel; } - } - /// Logs an info message - void Logger::info(const std::string& message) { - if (m_logLevel <= INFO) { - log(message, "INFO"); + /// Changes the default path from log.log to path + + void Logger::setPath(const std::string& path) { + m_logFile = path; } - } - /// Logs an error message - void Logger::error(const std::string& message) { - if (m_logLevel <= ERROR) { - log(message, "ERROR"); + /// Logs a debug message + + void Logger::debug(const std::string& message) { + if (m_logLevel <= DEBUG) { + log(message, "DEBUG"); + } } - } - void Logger::log(const std::string& message, std::string logLevel) { - ptime now = second_clock::universal_time(); - m_logStream << to_simple_string(now) << " " << logLevel << " " << message << "\n"; - } + /// Logs an info message - void Logger::initLogger() { - m_logStream.open(m_logFile.c_str(), std::ios::app); - } + void Logger::info(const std::string& message) { + if (m_logLevel <= INFO) { + log(message, "INFO"); + } + } - void Logger::closeLogger() { - m_logStream.close(); - } + /// Logs an error message - Logger::~Logger() { + void Logger::error(const std::string& message) { + if (m_logLevel <= ERROR) { + log(message, "ERROR"); + } + } - } + void Logger::log(const std::string& message, std::string logLevel) { + ptime now = second_clock::universal_time(); + m_logStream << to_simple_string(now) << " " << logLevel << " " << message << "\n"; + } + + void Logger::initLogger() { + m_logStream.open(m_logFile.c_str(), std::ios::app); + } + + void Logger::closeLogger() { + m_logStream.close(); + } + + Logger::~Logger() { + + } } // namespace Opm diff --git a/opm/parser/eclipse/Logger/Logger.hpp b/opm/parser/eclipse/Logger/Logger.hpp index c436cefa0..a59528ac8 100644 --- a/opm/parser/eclipse/Logger/Logger.hpp +++ b/opm/parser/eclipse/Logger/Logger.hpp @@ -25,30 +25,31 @@ namespace Opm { - /// Class to use for simple logging to file. Default output file is log.log - /// initLogger and closeLogger have to be called to open and close the stream. - /// The logging is performed using the debug, info and error methods. - class Logger { - public: - static const int DEBUG; - static const int INFO; - static const int ERROR; + /// Class to use for simple logging to file. Default output file is log.log + /// initLogger and closeLogger have to be called to open and close the stream. + /// The logging is performed using the debug, info and error methods. - static void initLogger(); - static void closeLogger(); - static void setLogLevel(int logLevel); - static void setPath(const std::string& path); - static void debug(const std::string& message); - static void info(const std::string& message); - static void error(const std::string& message); - virtual ~Logger(); - private: - static std::string m_logFile; - static std::ofstream m_logStream; - static int m_logLevel; - static void log(const std::string& message, std::string logLevel); - static void initLoggingConstants(); - }; + class Logger { + public: + static const int DEBUG; + static const int INFO; + static const int ERROR; + + static void initLogger(); + static void closeLogger(); + static void setLogLevel(int logLevel); + static void setPath(const std::string& path); + static void debug(const std::string& message); + static void info(const std::string& message); + static void error(const std::string& message); + virtual ~Logger(); + private: + static std::string m_logFile; + static std::ofstream m_logStream; + static int m_logLevel; + static void log(const std::string& message, std::string logLevel); + static void initLoggingConstants(); + }; }// namespace Opm #endif /* LOGGER_HPP */ diff --git a/opm/parser/eclipse/Parser/ItemSize.cpp b/opm/parser/eclipse/Parser/ItemSize.cpp deleted file mode 100644 index 655163e32..000000000 --- a/opm/parser/eclipse/Parser/ItemSize.cpp +++ /dev/null @@ -1,64 +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 . -*/ - -#include -#include - - - -namespace Opm { - - ItemSize::ItemSize() { - m_sizeType = UNSPECIFIED; - m_sizeValue = 0; - } - - - ItemSize::ItemSize(int sizeValue) { - m_sizeType = ITEM_FIXED; - m_sizeValue = sizeValue; - } - - - ItemSize::ItemSize(ItemSizeEnum sizeType) { - m_sizeType = sizeType; - m_sizeValue = 0; - } - - - ItemSize::ItemSize(ItemSizeEnum sizeType, size_t sizeValue) { - m_sizeType = sizeType; - m_sizeValue = sizeValue; - } - - - ItemSizeEnum ItemSize::sizeType() const{ - return m_sizeType; - } - - - size_t ItemSize::sizeValue() const{ - if (m_sizeType == ITEM_FIXED) - return m_sizeValue; - else - throw std::invalid_argument("Can not ask for actual size when type != ITEM_FIXED"); - } - - -} diff --git a/opm/parser/eclipse/Parser/Parser.cpp b/opm/parser/eclipse/Parser/Parser.cpp index df786f081..185535bfb 100644 --- a/opm/parser/eclipse/Parser/Parser.cpp +++ b/opm/parser/eclipse/Parser/Parser.cpp @@ -22,24 +22,24 @@ namespace Opm { - Parser::Parser() { - } + Parser::Parser() { + } - RawDeckPtr 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); - Logger::info("Done parsing of file: " + path); - Logger::closeLogger(); - return rawDeck; - } + RawDeckPtr 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); + Logger::info("Done parsing of file: " + path); + Logger::closeLogger(); + return rawDeck; + } - Parser::~Parser() { - } + Parser::~Parser() { + } - void Parser::addKW(ParserKWConstPtr parserKW) { - keywords.insert(std::make_pair(parserKW->getName(), parserKW)); - } + void Parser::addKW(ParserKWConstPtr parserKW) { + keywords.insert(std::make_pair(parserKW->getName(), parserKW)); + } } // namespace Opm diff --git a/opm/parser/eclipse/Parser/Parser.hpp b/opm/parser/eclipse/Parser/Parser.hpp index ae653d399..ae955dd7e 100644 --- a/opm/parser/eclipse/Parser/Parser.hpp +++ b/opm/parser/eclipse/Parser/Parser.hpp @@ -31,25 +31,26 @@ namespace Opm { - /// The hub of the parsing process. - /// An input file in the eclipse data format is specified, several steps of parsing is performed - /// and the semantically parsed result is returned. - class Parser { - public: - Parser(); + /// The hub of the parsing process. + /// An input file in the eclipse data format is specified, several steps of parsing is performed + /// and the semantically parsed result is returned. - /// The starting point of the parsing process. The supplied file is parsed, and the resulting Deck is returned. - RawDeckPtr parse(const std::string &path); - virtual ~Parser(); - - /// Method to add ParserKW instances, these holding type and size information about the keywords and their data. - void addKW(ParserKWConstPtr parserKW); + class Parser { + public: + Parser(); - private: - std::map keywords; - }; + /// The starting point of the parsing process. The supplied file is parsed, and the resulting Deck is returned. + RawDeckPtr parse(const std::string &path); + virtual ~Parser(); - typedef boost::shared_ptr ParserPtr; + /// Method to add ParserKW instances, these holding type and size information about the keywords and their data. + void addKW(ParserKWConstPtr parserKW); + + private: + std::map keywords; + }; + + typedef boost::shared_ptr ParserPtr; } // namespace Opm #endif /* PARSER_H */ diff --git a/opm/parser/eclipse/Parser/ParserConst.hpp b/opm/parser/eclipse/Parser/ParserConst.hpp index e947fbd74..f202650a8 100644 --- a/opm/parser/eclipse/Parser/ParserConst.hpp +++ b/opm/parser/eclipse/Parser/ParserConst.hpp @@ -22,9 +22,9 @@ namespace Opm { - namespace ParserConst { - const unsigned int maxKWLength = 8; - } + namespace ParserConst { + const unsigned int maxKWLength = 8; + } } diff --git a/opm/parser/eclipse/Parser/ParserEnums.hpp b/opm/parser/eclipse/Parser/ParserEnums.hpp index 86d19240b..037e8a49b 100644 --- a/opm/parser/eclipse/Parser/ParserEnums.hpp +++ b/opm/parser/eclipse/Parser/ParserEnums.hpp @@ -25,19 +25,18 @@ namespace Opm { - enum ParserRecordSizeEnum { - UNDEFINED = 0, - FIXED = 1, - BOX = 2, - GRID = 3 - }; - + enum ParserRecordSizeEnum { + UNDEFINED = 0, + FIXED = 1, + BOX = 2, + GRID = 3 + }; - enum ItemSizeEnum { - UNSPECIFIED = 0, - ITEM_FIXED = 1, - ITEM_BOX = 2 - }; + enum ParserItemSizeEnum { + UNSPECIFIED = 0, + ITEM_FIXED = 1, + ITEM_BOX = 2 + }; } diff --git a/opm/parser/eclipse/Parser/ParserItem.hpp b/opm/parser/eclipse/Parser/ParserItem.hpp new file mode 100644 index 000000000..531f8389a --- /dev/null +++ b/opm/parser/eclipse/Parser/ParserItem.hpp @@ -0,0 +1,84 @@ +/* + 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 . + */ +#ifndef PARSER_ITEM_H +#define PARSER_ITEM_H + +#include +#include + +#include + +#include + +namespace Opm { + + template + class ParserItem { + private: + std::string m_name; + ParserItemSizeConstPtr m_itemSize; + + public: + + ParserItem(const std::string& itemName, ParserItemSizeConstPtr itemSize) { + m_name.assign(itemName); + m_itemSize = itemSize; + } + + bool scanItem(const std::string& itemString, T& value) { + std::istringstream inputStream(itemString); + T newValue; + inputStream >> newValue; + + if (inputStream.fail()) + return false; + else { + char c; + inputStream >> c; + if (inputStream.eof() || c == ' ') { + value = newValue; + return true; + } else + return false; + } + }; + + int scanItems(const std::string& itemString, size_t items, std::vector& values) { + std::istringstream inputStream(itemString); + unsigned int itemsRead = 0; + + while (inputStream.good() && itemsRead < items) { + T value; + inputStream >> value; + values.push_back(value); + itemsRead++; + } + + return itemsRead; + } + + int scanItems(const std::string& itemString, std::vector& values) { + return scanItems(itemString, m_itemSize->sizeValue(), values); + } + + + }; +} + +#endif diff --git a/opm/parser/eclipse/Parser/ParserItemSize.cpp b/opm/parser/eclipse/Parser/ParserItemSize.cpp new file mode 100644 index 000000000..2cee7c99c --- /dev/null +++ b/opm/parser/eclipse/Parser/ParserItemSize.cpp @@ -0,0 +1,61 @@ +/* + 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 + + + +namespace Opm { + + ParserItemSize::ParserItemSize() { + m_sizeType = UNSPECIFIED; + m_sizeValue = 0; + } + + ParserItemSize::ParserItemSize(int sizeValue) { + m_sizeType = ITEM_FIXED; + m_sizeValue = sizeValue; + } + + ParserItemSize::ParserItemSize(ParserItemSizeEnum sizeType) { + m_sizeType = sizeType; + m_sizeValue = 0; + } + + ParserItemSize::ParserItemSize(ParserItemSizeEnum sizeType, size_t sizeValue) { + if (sizeType == ITEM_BOX || sizeType == UNSPECIFIED) + throw std::invalid_argument("Cannot combine ITEM_BOX/UNSPECIFIED with explicit size value"); + else { + m_sizeType = sizeType; + m_sizeValue = sizeValue; + } + } + + ParserItemSizeEnum ParserItemSize::sizeType() const { + return m_sizeType; + } + + size_t ParserItemSize::sizeValue() const { + if (m_sizeType == ITEM_FIXED) + return m_sizeValue; + else + throw std::invalid_argument("Can not ask for actual size when type != ITEM_FIXED"); + } +} diff --git a/opm/parser/eclipse/Parser/ItemSize.hpp b/opm/parser/eclipse/Parser/ParserItemSize.hpp similarity index 57% rename from opm/parser/eclipse/Parser/ItemSize.hpp rename to opm/parser/eclipse/Parser/ParserItemSize.hpp index 43170fe7b..644381604 100644 --- a/opm/parser/eclipse/Parser/ItemSize.hpp +++ b/opm/parser/eclipse/Parser/ParserItemSize.hpp @@ -15,10 +15,10 @@ You should have received a copy of the GNU General Public License along with OPM. If not, see . -*/ + */ -#ifndef RECORD_ITEM_SIZE_H -#define RECORD_ITEM_SIZE_H +#ifndef PARSER_ITEM_SIZE_H +#define PARSER_ITEM_SIZE_H #include @@ -26,23 +26,22 @@ namespace Opm { - class ItemSize { + class ParserItemSize { + private: + ParserItemSizeEnum m_sizeType; + size_t m_sizeValue; - private: - ItemSizeEnum m_sizeType; - size_t m_sizeValue; - - public: - ItemSize(); - ItemSize(int sizeValue); - ItemSize(ItemSizeEnum sizeType); - ItemSize(ItemSizeEnum sizeType, size_t sizeValue); - - ItemSizeEnum sizeType() const; - size_t sizeValue() const; - }; - typedef boost::shared_ptr ItemSizePtr; - typedef boost::shared_ptr ItemSizeConstPtr; + public: + ParserItemSize(); + ParserItemSize(int sizeValue); + ParserItemSize(ParserItemSizeEnum sizeType); + ParserItemSize(ParserItemSizeEnum sizeType, size_t sizeValue); + + ParserItemSizeEnum sizeType() const; + size_t sizeValue() const; + }; + typedef boost::shared_ptr ParserItemSizePtr; + typedef boost::shared_ptr ParserItemSizeConstPtr; } #endif diff --git a/opm/parser/eclipse/Parser/ParserKW.cpp b/opm/parser/eclipse/Parser/ParserKW.cpp index fcd3ef88a..269012afd 100644 --- a/opm/parser/eclipse/Parser/ParserKW.cpp +++ b/opm/parser/eclipse/Parser/ParserKW.cpp @@ -26,28 +26,28 @@ namespace Opm { - ParserKW::ParserKW() { - m_name.assign(""); - } + ParserKW::ParserKW() { + m_name.assign(""); + } - ParserKW::ParserKW(const std::string& name, ParserRecordSizeConstPtr recordSize) { - if (name.length() > ParserConst::maxKWLength) - throw std::invalid_argument("Given keyword name is too long - max 8 characters."); + ParserKW::ParserKW(const std::string& name, ParserRecordSizeConstPtr recordSize) { + if (name.length() > ParserConst::maxKWLength) + throw std::invalid_argument("Given keyword name is too long - max 8 characters."); - for (unsigned int i = 0; i < name.length(); i++) - if (islower(name[i])) - throw std::invalid_argument("Keyword must be all upper case - mixed case not allowed:" + name); + for (unsigned int i = 0; i < name.length(); i++) + if (islower(name[i])) + throw std::invalid_argument("Keyword must be all upper case - mixed case not allowed:" + name); - m_name.assign(name); - this->recordSize = recordSize; - } + m_name.assign(name); + this->recordSize = recordSize; + } - ParserKW::~ParserKW() { - } + ParserKW::~ParserKW() { + } - const std::string& ParserKW::getName() const { - return m_name; - } + const std::string& ParserKW::getName() const { + return m_name; + } } diff --git a/opm/parser/eclipse/Parser/ParserKW.hpp b/opm/parser/eclipse/Parser/ParserKW.hpp index 9b9023e97..4b734cf6b 100644 --- a/opm/parser/eclipse/Parser/ParserKW.hpp +++ b/opm/parser/eclipse/Parser/ParserKW.hpp @@ -26,18 +26,18 @@ namespace Opm { - class ParserKW { - public: - ParserKW(); - ParserKW(const std::string& name, ParserRecordSizeConstPtr recordSize); - ~ParserKW(); - const std::string& getName() const; - private: - std::string m_name; - ParserRecordSizeConstPtr recordSize; - }; - typedef boost::shared_ptr ParserKWPtr; - typedef boost::shared_ptr ParserKWConstPtr; + class ParserKW { + public: + ParserKW(); + ParserKW(const std::string& name, ParserRecordSizeConstPtr recordSize); + ~ParserKW(); + const std::string& getName() const; + private: + std::string m_name; + ParserRecordSizeConstPtr recordSize; + }; + typedef boost::shared_ptr ParserKWPtr; + typedef boost::shared_ptr ParserKWConstPtr; } #endif diff --git a/opm/parser/eclipse/Parser/ParserRecordItem.hpp b/opm/parser/eclipse/Parser/ParserRecordItem.hpp deleted file mode 100644 index 85da10ca7..000000000 --- a/opm/parser/eclipse/Parser/ParserRecordItem.hpp +++ /dev/null @@ -1,87 +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 . -*/ -#ifndef PARSER_RECORD_ITEM_H -#define PARSER_RECORD_ITEM_H - -#include -#include - -#include - -#include - -namespace Opm { - template - class ParserRecordItem { - private: - std::string m_name; - ItemSizeConstPtr m_itemSize; - - public: - - ParserRecordItem(const std::string& itemName , ItemSizeConstPtr itemSize) { - m_name.assign( itemName ); - m_itemSize = itemSize; - } - - - bool scanItem(const std::string& itemString , T& value) { - std::istringstream inputStream( itemString ); - T newValue; - inputStream >> newValue; - - if (inputStream.fail()) - return false; - else { - char c; - inputStream >> c; - if (inputStream.eof() || c == ' ') { - value = newValue; - return true; - } - else - return false; - } - }; - - - int scanItems(const std::string& itemString , size_t items , std::vector& values) { - std::istringstream inputStream( itemString ); - unsigned int itemsRead = 0; - - while (inputStream.good() && itemsRead < items) { - T value; - inputStream >> value; - values.push_back( value ); - itemsRead++; - } - - return itemsRead; - } - - - int scanItems(const std::string& itemString , std::vector& values) { - return scanItems( itemString , m_itemSize->sizeValue() , values); - } - - - }; -} - -#endif diff --git a/opm/parser/eclipse/Parser/ParserRecordSize.cpp b/opm/parser/eclipse/Parser/ParserRecordSize.cpp index 5b4091cb1..9053dc90a 100644 --- a/opm/parser/eclipse/Parser/ParserRecordSize.cpp +++ b/opm/parser/eclipse/Parser/ParserRecordSize.cpp @@ -26,26 +26,26 @@ namespace Opm { - ParserRecordSize::ParserRecordSize() { - recordSizeType = UNDEFINED; - fixedSize = 0; - } + ParserRecordSize::ParserRecordSize() { + recordSizeType = UNDEFINED; + fixedSize = 0; + } - ParserRecordSize::ParserRecordSize(size_t fixedSize) { - recordSizeType = FIXED; - this->fixedSize = fixedSize; - } + ParserRecordSize::ParserRecordSize(size_t fixedSize) { + recordSizeType = FIXED; + this->fixedSize = fixedSize; + } - size_t ParserRecordSize::recordSize() { - if (recordSizeType == FIXED) { - return fixedSize; - } else - throw std::logic_error("Only the FIXED recordSize is supported.\n"); - } + size_t ParserRecordSize::recordSize() { + if (recordSizeType == FIXED) { + return fixedSize; + } else + throw std::logic_error("Only the FIXED recordSize is supported.\n"); + } - ParserRecordSize::~ParserRecordSize() { + ParserRecordSize::~ParserRecordSize() { - } + } } diff --git a/opm/parser/eclipse/Parser/ParserRecordSize.hpp b/opm/parser/eclipse/Parser/ParserRecordSize.hpp index c48bf5ecb..3cfcb8868 100644 --- a/opm/parser/eclipse/Parser/ParserRecordSize.hpp +++ b/opm/parser/eclipse/Parser/ParserRecordSize.hpp @@ -29,22 +29,22 @@ namespace Opm { - class ParserRecordSize { - public: - ParserRecordSize(); - ParserRecordSize(size_t fixedSize); - ~ParserRecordSize(); + class ParserRecordSize { + public: + ParserRecordSize(); + ParserRecordSize(size_t fixedSize); + ~ParserRecordSize(); - size_t recordSize(); + size_t recordSize(); - private: - enum ParserRecordSizeEnum recordSizeType; - size_t fixedSize; - }; + private: + enum ParserRecordSizeEnum recordSizeType; + size_t fixedSize; + }; - typedef boost::shared_ptr ParserRecordSizePtr; - typedef boost::shared_ptr ParserRecordSizeConstPtr; + typedef boost::shared_ptr ParserRecordSizePtr; + typedef boost::shared_ptr ParserRecordSizeConstPtr; } #endif diff --git a/opm/parser/eclipse/RawDeck/RawConsts.hpp b/opm/parser/eclipse/RawDeck/RawConsts.hpp index 6e8610425..5575eb113 100644 --- a/opm/parser/eclipse/RawDeck/RawConsts.hpp +++ b/opm/parser/eclipse/RawDeck/RawConsts.hpp @@ -23,14 +23,14 @@ namespace Opm { - /// Consts used in the non semantic, raw parsing of the eclipse file - namespace RawConsts { - const char slash = '/'; - const char quote = '\''; - const std::string separators = "\t "; - const std::string include = "INCLUDE"; - const unsigned int maxKeywordLength = 8; - } + /// Consts used in the non semantic, raw parsing of the eclipse file + namespace RawConsts { + const char slash = '/'; + const char quote = '\''; + const std::string separators = "\t "; + const std::string include = "INCLUDE"; + const unsigned int maxKeywordLength = 8; + } } diff --git a/opm/parser/eclipse/RawDeck/RawDeck.cpp b/opm/parser/eclipse/RawDeck/RawDeck.cpp index 9b97f327a..c4f423174 100644 --- a/opm/parser/eclipse/RawDeck/RawDeck.cpp +++ b/opm/parser/eclipse/RawDeck/RawDeck.cpp @@ -24,128 +24,132 @@ namespace Opm { - RawDeck::RawDeck(RawParserKWsConstPtr rawParserKWs) { - m_rawParserKWs = rawParserKWs; - } - - /// Iterate through list of RawKeywords in search for the specified string. - /// O(n), not using map or hash because the keywords are not unique, - /// and the order matters. Returns first matching keyword. - RawKeywordConstPtr RawDeck::getKeyword(const std::string& keyword) const { - for (std::list::const_iterator it = m_keywords.begin(); it != m_keywords.end(); it++) { - if ((*it)->getKeyword() == keyword) { - return (*it); - } + RawDeck::RawDeck(RawParserKWsConstPtr rawParserKWs) { + m_rawParserKWs = rawParserKWs; } - throw std::invalid_argument("Keyword not found, keyword: " + keyword); - } - bool RawDeck::hasKeyword(const std::string& keyword) const { - for (std::list::const_iterator it = m_keywords.begin(); it != m_keywords.end(); it++) { - if ((*it)->getKeyword() == keyword) { - return true; - } - } - return false; - } + /// Iterate through list of RawKeywords in search for the specified string. + /// O(n), not using map or hash because the keywords are not unique, + /// and the order matters. Returns first matching keyword. - /// The main data reading function, reads one and one keyword into the RawDeck - /// If the INCLUDE keyword is found, the specified include file is inline read into the RawDeck. - /// 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) { - boost::filesystem::path dataFolderPath = verifyValidInputPath(path); - { - std::ifstream inputstream; - Logger::info("Initializing from file: " + path); - inputstream.open(path.c_str()); - - std::string line; - RawKeywordPtr currentRawKeyword; - while (std::getline(inputstream, line)) { - std::string keywordString; - if (currentRawKeyword == NULL) { - if (RawKeyword::tryParseKeyword(line, keywordString)) { - currentRawKeyword = RawKeywordPtr(new RawKeyword(keywordString)); - if (isKeywordFinished(currentRawKeyword)) { - addKeyword(currentRawKeyword, dataFolderPath); - currentRawKeyword.reset(); + RawKeywordConstPtr RawDeck::getKeyword(const std::string& keyword) const { + for (std::list::const_iterator it = m_keywords.begin(); it != m_keywords.end(); it++) { + if ((*it)->getKeyword() == keyword) { + return (*it); } - } - } else if (currentRawKeyword != NULL && RawKeyword::lineContainsData(line)) { - currentRawKeyword->addRawRecordString(line); - if (isKeywordFinished(currentRawKeyword)) { - addKeyword(currentRawKeyword, dataFolderPath); - currentRawKeyword.reset(); - } - } else if (currentRawKeyword != NULL && RawKeyword::lineTerminatesKeyword(line)) { - if (!currentRawKeyword->isPartialRecordStringEmpty()) { - Logger::error("Reached keyword terminator slash, but there is non-terminated data on current keyword. " - "Adding terminator, but records should be terminated by slash in data file"); - currentRawKeyword->addRawRecordString(std::string(1,Opm::RawConsts::slash)); - } - addKeyword(currentRawKeyword, dataFolderPath); - currentRawKeyword.reset(); } - } - inputstream.close(); + throw std::invalid_argument("Keyword not found, keyword: " + keyword); } - } - void RawDeck::addKeyword(RawKeywordConstPtr keyword, const boost::filesystem::path& dataFolderPath) { - if (keyword->getKeyword() == Opm::RawConsts::include) { - std::string includeFileString = keyword->getRecords().front()->getItems().front(); - boost::filesystem::path pathToIncludedFile(dataFolderPath); - pathToIncludedFile /= includeFileString; - - readDataIntoDeck(pathToIncludedFile.string()); - } else { - m_keywords.push_back(keyword); - } - } - - boost::filesystem::path RawDeck::verifyValidInputPath(const std::string& inputPath) { - Logger::info("Verifying path: " + inputPath); - boost::filesystem::path pathToInputFile(inputPath); - if (!boost::filesystem::is_regular_file(pathToInputFile)) { - Logger::error("Unable to open file with path: " + inputPath); - throw std::invalid_argument("Given path is not a valid file-path, path: " + inputPath); - } - return pathToInputFile.parent_path(); - } - - unsigned int RawDeck::getNumberOfKeywords() const { - return m_keywords.size(); - } - - /// Checks if the current keyword being read is finished, based on the number of records - /// specified for the current keyword type in the RawParserKW class. - bool RawDeck::isKeywordFinished(RawKeywordConstPtr rawKeyword) { - if (m_rawParserKWs->keywordExists(rawKeyword->getKeyword())) { - return rawKeyword->getNumberOfRecords() == m_rawParserKWs->getFixedNumberOfRecords(rawKeyword->getKeyword()); - } - return false; - } - - /// Operator overload to write the content of the RawDeck to an ostream - std::ostream& operator<<(std::ostream& os, const RawDeck& deck) { - for (std::list::const_iterator keyword = deck.m_keywords.begin(); keyword != deck.m_keywords.end(); keyword++) { - os << (*keyword)->getKeyword() << " -- Keyword\n"; - - std::list records = (*keyword)->getRecords(); - for (std::list::const_iterator record = records.begin(); record != records.end(); record++) { - std::vector recordItems = (*record)->getItems(); - - for (std::vector::const_iterator recordItem = recordItems.begin(); recordItem != recordItems.end(); recordItem++) { - os << (*recordItem) << " "; + bool RawDeck::hasKeyword(const std::string& keyword) const { + for (std::list::const_iterator it = m_keywords.begin(); it != m_keywords.end(); it++) { + if ((*it)->getKeyword() == keyword) { + return true; + } } - os << " / -- Data\n"; - } - os << "\n"; + return false; } - return os; - } - RawDeck::~RawDeck() { - } + /// The main data reading function, reads one and one keyword into the RawDeck + /// If the INCLUDE keyword is found, the specified include file is inline read into the RawDeck. + /// 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) { + boost::filesystem::path dataFolderPath = verifyValidInputPath(path); + { + std::ifstream inputstream; + Logger::info("Initializing from file: " + path); + inputstream.open(path.c_str()); + + std::string line; + RawKeywordPtr currentRawKeyword; + while (std::getline(inputstream, line)) { + std::string keywordString; + if (currentRawKeyword == NULL) { + if (RawKeyword::tryParseKeyword(line, keywordString)) { + currentRawKeyword = RawKeywordPtr(new RawKeyword(keywordString)); + if (isKeywordFinished(currentRawKeyword)) { + addKeyword(currentRawKeyword, dataFolderPath); + currentRawKeyword.reset(); + } + } + } else if (currentRawKeyword != NULL && RawKeyword::lineContainsData(line)) { + currentRawKeyword->addRawRecordString(line); + if (isKeywordFinished(currentRawKeyword)) { + addKeyword(currentRawKeyword, dataFolderPath); + currentRawKeyword.reset(); + } + } else if (currentRawKeyword != NULL && RawKeyword::lineTerminatesKeyword(line)) { + if (!currentRawKeyword->isPartialRecordStringEmpty()) { + Logger::error("Reached keyword terminator slash, but there is non-terminated data on current keyword. " + "Adding terminator, but records should be terminated by slash in data file"); + currentRawKeyword->addRawRecordString(std::string(1, Opm::RawConsts::slash)); + } + addKeyword(currentRawKeyword, dataFolderPath); + currentRawKeyword.reset(); + } + } + inputstream.close(); + } + } + + void RawDeck::addKeyword(RawKeywordConstPtr keyword, const boost::filesystem::path& dataFolderPath) { + if (keyword->getKeyword() == Opm::RawConsts::include) { + std::string includeFileString = keyword->getRecords().front()->getItems().front(); + boost::filesystem::path pathToIncludedFile(dataFolderPath); + pathToIncludedFile /= includeFileString; + + readDataIntoDeck(pathToIncludedFile.string()); + } else { + m_keywords.push_back(keyword); + } + } + + boost::filesystem::path RawDeck::verifyValidInputPath(const std::string& inputPath) { + Logger::info("Verifying path: " + inputPath); + boost::filesystem::path pathToInputFile(inputPath); + if (!boost::filesystem::is_regular_file(pathToInputFile)) { + Logger::error("Unable to open file with path: " + inputPath); + throw std::invalid_argument("Given path is not a valid file-path, path: " + inputPath); + } + return pathToInputFile.parent_path(); + } + + unsigned int RawDeck::getNumberOfKeywords() const { + return m_keywords.size(); + } + + /// Checks if the current keyword being read is finished, based on the number of records + /// specified for the current keyword type in the RawParserKW class. + + bool RawDeck::isKeywordFinished(RawKeywordConstPtr rawKeyword) { + if (m_rawParserKWs->keywordExists(rawKeyword->getKeyword())) { + return rawKeyword->getNumberOfRecords() == m_rawParserKWs->getFixedNumberOfRecords(rawKeyword->getKeyword()); + } + return false; + } + + /// Operator overload to write the content of the RawDeck to an ostream + + std::ostream& operator<<(std::ostream& os, const RawDeck& deck) { + for (std::list::const_iterator keyword = deck.m_keywords.begin(); keyword != deck.m_keywords.end(); keyword++) { + os << (*keyword)->getKeyword() << " -- Keyword\n"; + + std::list records = (*keyword)->getRecords(); + for (std::list::const_iterator record = records.begin(); record != records.end(); record++) { + std::vector recordItems = (*record)->getItems(); + + for (std::vector::const_iterator recordItem = recordItems.begin(); recordItem != recordItems.end(); recordItem++) { + os << (*recordItem) << " "; + } + os << " / -- Data\n"; + } + os << "\n"; + } + return os; + } + + RawDeck::~RawDeck() { + } } diff --git a/opm/parser/eclipse/RawDeck/RawDeck.hpp b/opm/parser/eclipse/RawDeck/RawDeck.hpp index 37dc7d991..19faf1c80 100644 --- a/opm/parser/eclipse/RawDeck/RawDeck.hpp +++ b/opm/parser/eclipse/RawDeck/RawDeck.hpp @@ -30,36 +30,37 @@ namespace Opm { - /// Class representing the most high level structure, a deck. The RawDeck holds non parsed - /// data, in the form of a list of RawKeywords. The order of the keywords is important, as this - /// reflects the order they were read in from the eclipse file. The RawDeck forms the basis of the - /// semantic parsing that comes after the RawDeck has been created from the eclipse file. - class RawDeck { - public: + /// Class representing the most high level structure, a deck. The RawDeck holds non parsed + /// data, in the form of a list of RawKeywords. The order of the keywords is important, as this + /// reflects the order they were read in from the eclipse file. The RawDeck forms the basis of the + /// semantic parsing that comes after the RawDeck has been created from the eclipse file. - /// Constructor that requires information about the fixed record length keywords. - /// All relevant keywords with a fixed number of records - /// 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); - - 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(); + class RawDeck { + public: - private: - std::list m_keywords; - RawParserKWsConstPtr m_rawParserKWs; - 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); - }; + /// Constructor that requires information about the fixed record length keywords. + /// All relevant keywords with a fixed number of records + /// 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); - typedef boost::shared_ptr RawDeckPtr; + 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 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; } #endif /* RAWDECK_HPP */ diff --git a/opm/parser/eclipse/RawDeck/RawKeyword.cpp b/opm/parser/eclipse/RawDeck/RawKeyword.cpp index 3d2ef7596..8552d1b9a 100644 --- a/opm/parser/eclipse/RawDeck/RawKeyword.cpp +++ b/opm/parser/eclipse/RawDeck/RawKeyword.cpp @@ -25,103 +25,104 @@ namespace Opm { - RawKeyword::RawKeyword() { - } - - RawKeyword::RawKeyword(const std::string& keyword) { - setKeyword(keyword); - } - - bool RawKeyword::tryParseKeyword(const std::string& keywordCandidate, std::string& result) { - result = boost::trim_right_copy(keywordCandidate.substr(0, 8)); - if (isValidKeyword(result)) { - Logger::debug("KEYWORD <" + keywordCandidate + ">"); - return true; - } - return false; - } - - bool RawKeyword::isValidKeyword(const std::string& keywordCandidate) { - - std::string keywordRegex = "^[A-Z][A-Z,0-9]{1,7}$"; - int status; - regex_t regularExpression; - regmatch_t rm; - if (regcomp(®ularExpression, keywordRegex.c_str(), REG_EXTENDED) != 0) { - throw std::runtime_error("Unable to compile regular expression for keyword! Expression: " + keywordRegex); + RawKeyword::RawKeyword() { } - status = regexec(®ularExpression, keywordCandidate.c_str(), 1, &rm, 0); - regfree(®ularExpression); - - if (status == 0) { - return true; + RawKeyword::RawKeyword(const std::string& keyword) { + setKeyword(keyword); } - return false; - } - bool RawKeyword::lineContainsData(const std::string& line) { - if (boost::algorithm::trim_left_copy(line).substr(0, 2) == "--") { - Logger::debug("COMMENT LINE <" + line + ">"); - return false; - } else if (boost::algorithm::trim_copy(line).length() == 0) { - Logger::debug("EMPTY LINE <" + line + ">"); - return false; - } else if (lineTerminatesKeyword(line)) { - Logger::debug("END OF RECORD <" + line + ">"); - return false; - } else { - Logger::debug("LOOKS LIKE DATA<" + line + ">"); - return true; + bool RawKeyword::tryParseKeyword(const std::string& keywordCandidate, std::string& result) { + result = boost::trim_right_copy(keywordCandidate.substr(0, 8)); + if (isValidKeyword(result)) { + Logger::debug("KEYWORD <" + keywordCandidate + ">"); + return true; + } + return false; } - } - bool RawKeyword::lineTerminatesKeyword(const std::string& line) { - std::string firstNonBlank = boost::algorithm::trim_left_copy(line).substr(0, 1); - if (firstNonBlank.size() > (unsigned) 0) { - return firstNonBlank[0] == Opm::RawConsts::slash; + bool RawKeyword::isValidKeyword(const std::string& keywordCandidate) { + + std::string keywordRegex = "^[A-Z][A-Z,0-9]{1,7}$"; + int status; + regex_t regularExpression; + regmatch_t rm; + if (regcomp(®ularExpression, keywordRegex.c_str(), REG_EXTENDED) != 0) { + throw std::runtime_error("Unable to compile regular expression for keyword! Expression: " + keywordRegex); + } + + status = regexec(®ularExpression, keywordCandidate.c_str(), 1, &rm, 0); + regfree(®ularExpression); + + if (status == 0) { + return true; + } + return false; } - return false; - } - void RawKeyword::setKeyword(const std::string& keyword) { - m_keyword = boost::algorithm::trim_right_copy(keyword); - if (!isValidKeyword(m_keyword)) { - throw std::invalid_argument("Not a valid keyword:" + keyword); - } else if (m_keyword.size() > Opm::RawConsts::maxKeywordLength) { - throw std::invalid_argument("Too long keyword:" + keyword); - } else if (boost::algorithm::trim_left_copy(m_keyword) != m_keyword) { - throw std::invalid_argument("Illegal whitespace start of keyword:" + keyword); + bool RawKeyword::lineContainsData(const std::string& line) { + if (boost::algorithm::trim_left_copy(line).substr(0, 2) == "--") { + Logger::debug("COMMENT LINE <" + line + ">"); + return false; + } else if (boost::algorithm::trim_copy(line).length() == 0) { + Logger::debug("EMPTY LINE <" + line + ">"); + return false; + } else if (lineTerminatesKeyword(line)) { + Logger::debug("END OF RECORD <" + line + ">"); + return false; + } else { + Logger::debug("LOOKS LIKE DATA<" + line + ">"); + return true; + } } - } - /// Important method, being repeatedly called. When a record is terminated, - /// it is added to the list of records, and a new record is started. - void RawKeyword::addRawRecordString(const std::string& partialRecordString) { - m_partialRecordString += partialRecordString; - if (RawRecord::isTerminatedRecordString(partialRecordString)) { - RawRecordPtr record(new RawRecord(m_partialRecordString)); - m_records.push_back(record); - m_partialRecordString.clear(); + + bool RawKeyword::lineTerminatesKeyword(const std::string& line) { + std::string firstNonBlank = boost::algorithm::trim_left_copy(line).substr(0, 1); + if (firstNonBlank.size() > (unsigned) 0) { + return firstNonBlank[0] == Opm::RawConsts::slash; + } + return false; } - } - bool RawKeyword::isPartialRecordStringEmpty() const { - return m_partialRecordString.size() == 0; - } + void RawKeyword::setKeyword(const std::string& keyword) { + m_keyword = boost::algorithm::trim_right_copy(keyword); + if (!isValidKeyword(m_keyword)) { + throw std::invalid_argument("Not a valid keyword:" + keyword); + } else if (m_keyword.size() > Opm::RawConsts::maxKeywordLength) { + throw std::invalid_argument("Too long keyword:" + keyword); + } else if (boost::algorithm::trim_left_copy(m_keyword) != m_keyword) { + throw std::invalid_argument("Illegal whitespace start of keyword:" + keyword); + } + } + /// Important method, being repeatedly called. When a record is terminated, + /// it is added to the list of records, and a new record is started. - unsigned int RawKeyword::getNumberOfRecords() const { - return m_records.size(); - } + void RawKeyword::addRawRecordString(const std::string& partialRecordString) { + m_partialRecordString += partialRecordString; + if (RawRecord::isTerminatedRecordString(partialRecordString)) { + RawRecordPtr record(new RawRecord(m_partialRecordString)); + m_records.push_back(record); + m_partialRecordString.clear(); + } + } - const std::list& RawKeyword::getRecords() const { - return m_records; - } + bool RawKeyword::isPartialRecordStringEmpty() const { + return m_partialRecordString.size() == 0; + } - const std::string& RawKeyword::getKeyword() const { - return m_keyword; - } + unsigned int RawKeyword::getNumberOfRecords() const { + return m_records.size(); + } - RawKeyword::~RawKeyword() { - } + const std::list& RawKeyword::getRecords() const { + return m_records; + } + + const std::string& RawKeyword::getKeyword() const { + return m_keyword; + } + + RawKeyword::~RawKeyword() { + } } diff --git a/opm/parser/eclipse/RawDeck/RawKeyword.hpp b/opm/parser/eclipse/RawDeck/RawKeyword.hpp index 90f147324..de08f830d 100644 --- a/opm/parser/eclipse/RawDeck/RawKeyword.hpp +++ b/opm/parser/eclipse/RawDeck/RawKeyword.hpp @@ -34,6 +34,7 @@ namespace Opm { /// represented as a list of RawRecord objects. /// The class also contains static functions to aid the parsing of the input file. /// The creationg of an instance is performed by calling the addRawRecordString method repeatedly. + class RawKeyword { public: RawKeyword(); diff --git a/opm/parser/eclipse/RawDeck/RawParserKWs.cpp b/opm/parser/eclipse/RawDeck/RawParserKWs.cpp index da30537ca..37935fe3c 100644 --- a/opm/parser/eclipse/RawDeck/RawParserKWs.cpp +++ b/opm/parser/eclipse/RawDeck/RawParserKWs.cpp @@ -21,59 +21,59 @@ namespace Opm { - RawParserKWs::RawParserKWs() { - initializeFixedKeywordLenghts(); - } + RawParserKWs::RawParserKWs() { + initializeFixedKeywordLenghts(); + } - bool RawParserKWs::keywordExists(const std::string& keyword) const { - return m_keywordRecordLengths.find(keyword) != m_keywordRecordLengths.end(); - } + bool RawParserKWs::keywordExists(const std::string& keyword) const { + return m_keywordRecordLengths.find(keyword) != m_keywordRecordLengths.end(); + } - unsigned int RawParserKWs::getFixedNumberOfRecords(const std::string& keyword) const { - if (keywordExists(keyword)) { - return m_keywordRecordLengths.find(keyword) -> second; - } else - throw std::invalid_argument("Given keyword is not found, offending keyword: " + keyword); - } + unsigned int RawParserKWs::getFixedNumberOfRecords(const std::string& keyword) const { + if (keywordExists(keyword)) { + return m_keywordRecordLengths.find(keyword) -> second; + } else + throw std::invalid_argument("Given keyword is not found, offending keyword: " + keyword); + } - void RawParserKWs::add(std::pair keywordAndNumRecords) { - m_keywordRecordLengths.insert(keywordAndNumRecords); - } + void RawParserKWs::add(std::pair keywordAndNumRecords) { + m_keywordRecordLengths.insert(keywordAndNumRecords); + } - void RawParserKWs::initializeFixedKeywordLenghts() { - add(std::pair("GRIDUNIT", 1)); - add(std::pair("INCLUDE", 1)); - add(std::pair("RADFIN4", 1)); - add(std::pair("DIMENS", 1)); - add(std::pair("START", 1)); - add(std::pair("GRIDOPTS", 1)); - add(std::pair("ENDSCALE", 1)); - add(std::pair("EQLOPTS", 1)); - add(std::pair("TABDIMS", 1)); - add(std::pair("EQLDIMS", 1)); - add(std::pair("REGDIMS", 1)); - add(std::pair("FAULTDIM", 1)); - add(std::pair("WELLDIMS", 1)); - add(std::pair("VFPPDIMS", 1)); - add(std::pair("RPTSCHED", 1)); - add(std::pair("WHISTCTL", 1)); + void RawParserKWs::initializeFixedKeywordLenghts() { + add(std::pair("GRIDUNIT", 1)); + add(std::pair("INCLUDE", 1)); + add(std::pair("RADFIN4", 1)); + add(std::pair("DIMENS", 1)); + add(std::pair("START", 1)); + add(std::pair("GRIDOPTS", 1)); + add(std::pair("ENDSCALE", 1)); + add(std::pair("EQLOPTS", 1)); + add(std::pair("TABDIMS", 1)); + add(std::pair("EQLDIMS", 1)); + add(std::pair("REGDIMS", 1)); + add(std::pair("FAULTDIM", 1)); + add(std::pair("WELLDIMS", 1)); + add(std::pair("VFPPDIMS", 1)); + add(std::pair("RPTSCHED", 1)); + add(std::pair("WHISTCTL", 1)); - add(std::pair("TITLE", 0)); - add(std::pair("RUNSPEC", 0)); - add(std::pair("METRIC", 0)); - add(std::pair("SCHEDULE", 0)); - add(std::pair("SKIPREST", 0)); - add(std::pair("NOECHO", 0)); - add(std::pair("END", 0)); - add(std::pair("OIL", 0)); - add(std::pair("GAS", 0)); - add(std::pair("WATER", 0)); - add(std::pair("DISGAS", 0)); - add(std::pair("VAPOIL", 0)); - } + add(std::pair("TITLE", 0)); + add(std::pair("RUNSPEC", 0)); + add(std::pair("METRIC", 0)); + add(std::pair("SCHEDULE", 0)); + add(std::pair("SKIPREST", 0)); + add(std::pair("NOECHO", 0)); + add(std::pair("END", 0)); + add(std::pair("OIL", 0)); + add(std::pair("GAS", 0)); + add(std::pair("WATER", 0)); + add(std::pair("DISGAS", 0)); + add(std::pair("VAPOIL", 0)); + } - RawParserKWs::~RawParserKWs() { - } + RawParserKWs::~RawParserKWs() { + } } diff --git a/opm/parser/eclipse/RawDeck/RawParserKWs.hpp b/opm/parser/eclipse/RawDeck/RawParserKWs.hpp index 5ca267290..0e8b57732 100644 --- a/opm/parser/eclipse/RawDeck/RawParserKWs.hpp +++ b/opm/parser/eclipse/RawDeck/RawParserKWs.hpp @@ -13,22 +13,23 @@ #include namespace Opm { - /// Class holding information about the characteristics of all known fixed length keywords. - /// The characteristics being held is the ones important for the raw parsing, - /// these being the keywords name and fixed number of records for the keyword. - class RawParserKWs { - public: - RawParserKWs(); - bool keywordExists(const std::string& keyword) const; - unsigned int getFixedNumberOfRecords(const std::string& keyword) const; - virtual ~RawParserKWs(); - private: - std::map m_keywordRecordLengths; - void initializeFixedKeywordLenghts(); - void add(std::pair keywordAndNumRecords); + /// Class holding information about the characteristics of all known fixed length keywords. + /// The characteristics being held is the ones important for the raw parsing, + /// these being the keywords name and fixed number of records for the keyword. - }; - typedef boost::shared_ptr RawParserKWsConstPtr; + class RawParserKWs { + public: + RawParserKWs(); + bool keywordExists(const std::string& keyword) const; + unsigned int getFixedNumberOfRecords(const std::string& keyword) const; + virtual ~RawParserKWs(); + private: + std::map m_keywordRecordLengths; + void initializeFixedKeywordLenghts(); + void add(std::pair keywordAndNumRecords); + + }; + typedef boost::shared_ptr RawParserKWsConstPtr; } #endif /* RAWPARSERKW_H */ diff --git a/opm/parser/eclipse/RawDeck/RawRecord.cpp b/opm/parser/eclipse/RawDeck/RawRecord.cpp index 474690386..f9d6dd81a 100644 --- a/opm/parser/eclipse/RawDeck/RawRecord.cpp +++ b/opm/parser/eclipse/RawDeck/RawRecord.cpp @@ -28,118 +28,118 @@ using namespace std; namespace Opm { - RawRecord::RawRecord() { - } - - /* - * It is assumed that after a record is terminated, there is no quote marks - * in the subsequent comment. This is in accordance with the Eclipse user - * manual. - * - * If a "non-complete" record string is supplied, an invalid_argument - * exception is thrown. - * - */ - RawRecord::RawRecord(const std::string& singleRecordString) { - if (isTerminatedRecordString(singleRecordString)) { - setRecordString(singleRecordString); - } else { - throw std::invalid_argument("Input string is not a complete record string," - " offending string: " + singleRecordString); + RawRecord::RawRecord() { } - splitSingleRecordString(); - } - const std::vector& RawRecord::getItems() const { - return m_recordItems; - } - - const std::string& RawRecord::getRecordString() const { - return m_sanitizedRecordString; - } - - bool RawRecord::isTerminatedRecordString(const std::string& candidateRecordString) { - unsigned int terminatingSlash = findTerminatingSlash(candidateRecordString); - bool hasTerminatingSlash = (terminatingSlash < candidateRecordString.size()); - int numberOfQuotes = std::count(candidateRecordString.begin(), candidateRecordString.end(), RawConsts::quote); - bool hasEvenNumberOfQuotes = (numberOfQuotes % 2) == 0; - return hasTerminatingSlash && hasEvenNumberOfQuotes; - } - - void RawRecord::splitSingleRecordString() { - char currentChar; - char tokenStartCharacter; - std::string currentToken = ""; - for (unsigned i = 0; i < m_sanitizedRecordString.size(); i++) { - currentChar = m_sanitizedRecordString[i]; - if (charIsSeparator(currentChar)) { - processSeparatorCharacter(currentToken, currentChar, tokenStartCharacter); - } else if (currentChar == RawConsts::quote) { - processQuoteCharacters(currentToken, currentChar, tokenStartCharacter); - } else { - processNonSpecialCharacters(currentToken, currentChar); - } + /* + * It is assumed that after a record is terminated, there is no quote marks + * in the subsequent comment. This is in accordance with the Eclipse user + * manual. + * + * If a "non-complete" record string is supplied, an invalid_argument + * exception is thrown. + * + */ + RawRecord::RawRecord(const std::string& singleRecordString) { + if (isTerminatedRecordString(singleRecordString)) { + setRecordString(singleRecordString); + } else { + throw std::invalid_argument("Input string is not a complete record string," + " offending string: " + singleRecordString); + } + splitSingleRecordString(); } - if (currentToken.size() > 0) { - m_recordItems.push_back(currentToken); - currentToken.clear(); + + const std::vector& RawRecord::getItems() const { + return m_recordItems; } - } - void RawRecord::processSeparatorCharacter(std::string& currentToken, const char& currentChar, char& tokenStartCharacter) { - if (tokenStartCharacter == RawConsts::quote) { - currentToken += currentChar; - } else { - if (currentToken.size() > 0) { - m_recordItems.push_back(currentToken); - currentToken.clear(); - } - tokenStartCharacter = currentChar; + const std::string& RawRecord::getRecordString() const { + return m_sanitizedRecordString; } - } - void RawRecord::processQuoteCharacters(std::string& currentToken, const char& currentChar, char& tokenStartCharacter) { - if (currentChar == tokenStartCharacter) { - if (currentToken.size() > 0) { - m_recordItems.push_back(currentToken); - currentToken.clear(); - } - tokenStartCharacter = '\0'; - } else { - tokenStartCharacter = currentChar; - currentToken.clear(); + bool RawRecord::isTerminatedRecordString(const std::string& candidateRecordString) { + unsigned int terminatingSlash = findTerminatingSlash(candidateRecordString); + bool hasTerminatingSlash = (terminatingSlash < candidateRecordString.size()); + int numberOfQuotes = std::count(candidateRecordString.begin(), candidateRecordString.end(), RawConsts::quote); + bool hasEvenNumberOfQuotes = (numberOfQuotes % 2) == 0; + return hasTerminatingSlash && hasEvenNumberOfQuotes; } - } - void RawRecord::processNonSpecialCharacters(std::string& currentToken, const char& currentChar) { - currentToken += currentChar; - } - - bool RawRecord::charIsSeparator(char candidate) { - return std::string::npos != RawConsts::separators.find(candidate); - } - - void RawRecord::setRecordString(const std::string& singleRecordString) { - unsigned terminatingSlash = findTerminatingSlash(singleRecordString); - m_sanitizedRecordString = singleRecordString.substr(0, terminatingSlash); - boost::trim(m_sanitizedRecordString); - } - - unsigned int RawRecord::findTerminatingSlash(const std::string& singleRecordString) { - unsigned int terminatingSlash = singleRecordString.find_first_of(RawConsts::slash); - unsigned int lastQuotePosition = singleRecordString.find_last_of(RawConsts::quote); - - // Checks lastQuotePosition vs terminatingSlashPosition, - // since specifications of WELLS, FILENAMES etc can include slash, but - // these are always in quotes (and there are no quotes after record-end). - if (terminatingSlash < lastQuotePosition && lastQuotePosition < singleRecordString.size()) { - terminatingSlash = singleRecordString.find_first_of(RawConsts::slash, lastQuotePosition); + void RawRecord::splitSingleRecordString() { + char currentChar; + char tokenStartCharacter; + std::string currentToken = ""; + for (unsigned i = 0; i < m_sanitizedRecordString.size(); i++) { + currentChar = m_sanitizedRecordString[i]; + if (charIsSeparator(currentChar)) { + processSeparatorCharacter(currentToken, currentChar, tokenStartCharacter); + } else if (currentChar == RawConsts::quote) { + processQuoteCharacters(currentToken, currentChar, tokenStartCharacter); + } else { + processNonSpecialCharacters(currentToken, currentChar); + } + } + if (currentToken.size() > 0) { + m_recordItems.push_back(currentToken); + currentToken.clear(); + } } - return terminatingSlash; - } - RawRecord::~RawRecord() { - } + void RawRecord::processSeparatorCharacter(std::string& currentToken, const char& currentChar, char& tokenStartCharacter) { + if (tokenStartCharacter == RawConsts::quote) { + currentToken += currentChar; + } else { + if (currentToken.size() > 0) { + m_recordItems.push_back(currentToken); + currentToken.clear(); + } + tokenStartCharacter = currentChar; + } + } + + void RawRecord::processQuoteCharacters(std::string& currentToken, const char& currentChar, char& tokenStartCharacter) { + if (currentChar == tokenStartCharacter) { + if (currentToken.size() > 0) { + m_recordItems.push_back(currentToken); + currentToken.clear(); + } + tokenStartCharacter = '\0'; + } else { + tokenStartCharacter = currentChar; + currentToken.clear(); + } + } + + void RawRecord::processNonSpecialCharacters(std::string& currentToken, const char& currentChar) { + currentToken += currentChar; + } + + bool RawRecord::charIsSeparator(char candidate) { + return std::string::npos != RawConsts::separators.find(candidate); + } + + void RawRecord::setRecordString(const std::string& singleRecordString) { + unsigned terminatingSlash = findTerminatingSlash(singleRecordString); + m_sanitizedRecordString = singleRecordString.substr(0, terminatingSlash); + boost::trim(m_sanitizedRecordString); + } + + unsigned int RawRecord::findTerminatingSlash(const std::string& singleRecordString) { + unsigned int terminatingSlash = singleRecordString.find_first_of(RawConsts::slash); + unsigned int lastQuotePosition = singleRecordString.find_last_of(RawConsts::quote); + + // Checks lastQuotePosition vs terminatingSlashPosition, + // since specifications of WELLS, FILENAMES etc can include slash, but + // these are always in quotes (and there are no quotes after record-end). + if (terminatingSlash < lastQuotePosition && lastQuotePosition < singleRecordString.size()) { + terminatingSlash = singleRecordString.find_first_of(RawConsts::slash, lastQuotePosition); + } + return terminatingSlash; + } + + RawRecord::~RawRecord() { + } } diff --git a/opm/parser/eclipse/RawDeck/RawRecord.hpp b/opm/parser/eclipse/RawDeck/RawRecord.hpp index bf6149ebc..7ac2fa70e 100644 --- a/opm/parser/eclipse/RawDeck/RawRecord.hpp +++ b/opm/parser/eclipse/RawDeck/RawRecord.hpp @@ -26,31 +26,32 @@ namespace Opm { - /// Class representing the lowest level of the Raw datatypes, a record. A record is simply - /// a vector containing the record elements, represented as strings. Some logic is present - /// to handle special elements in a record string, particularly with quote characters. - class RawRecord { - public: - RawRecord(); - RawRecord(const std::string& singleRecordString); - const std::string& getRecordString() const; - const std::vector& getItems() const; - static bool isTerminatedRecordString(const std::string& candidateRecordString); - virtual ~RawRecord(); - private: - std::string m_sanitizedRecordString; - std::vector m_recordItems; - - void setRecordString(const std::string& singleRecordString); - void splitSingleRecordString(); - void processSeparatorCharacter(std::string& currentToken, const char& currentChar, char& tokenStarter); - void processQuoteCharacters(std::string& currentToken, const char& currentChar, char& tokenStarter); - void processNonSpecialCharacters(std::string& currentToken, const char& currentChar); - bool charIsSeparator(char candidate); - static unsigned int findTerminatingSlash(const std::string& singleRecordString); - }; - typedef boost::shared_ptr RawRecordPtr; - typedef boost::shared_ptr RawRecordConstPtr; + /// Class representing the lowest level of the Raw datatypes, a record. A record is simply + /// a vector containing the record elements, represented as strings. Some logic is present + /// to handle special elements in a record string, particularly with quote characters. + + class RawRecord { + public: + RawRecord(); + RawRecord(const std::string& singleRecordString); + const std::string& getRecordString() const; + const std::vector& getItems() const; + static bool isTerminatedRecordString(const std::string& candidateRecordString); + virtual ~RawRecord(); + private: + std::string m_sanitizedRecordString; + std::vector m_recordItems; + + void setRecordString(const std::string& singleRecordString); + void splitSingleRecordString(); + void processSeparatorCharacter(std::string& currentToken, const char& currentChar, char& tokenStarter); + void processQuoteCharacters(std::string& currentToken, const char& currentChar, char& tokenStarter); + void processNonSpecialCharacters(std::string& currentToken, const char& currentChar); + bool charIsSeparator(char candidate); + static unsigned int findTerminatingSlash(const std::string& singleRecordString); + }; + typedef boost::shared_ptr RawRecordPtr; + typedef boost::shared_ptr RawRecordConstPtr; } diff --git a/tests/ParserItemSizeTests.cpp b/tests/ParserItemSizeTests.cpp index 905f23853..eb480d09e 100644 --- a/tests/ParserItemSizeTests.cpp +++ b/tests/ParserItemSizeTests.cpp @@ -15,57 +15,56 @@ You should have received a copy of the GNU General Public License along with OPM. If not, see . -*/ + */ #define BOOST_TEST_MODULE ParserTests #include -#include "opm/parser/eclipse/Parser/ItemSize.hpp" +#include "opm/parser/eclipse/Parser/ParserItemSize.hpp" #include "opm/parser/eclipse/Parser/ParserEnums.hpp" using namespace Opm; BOOST_AUTO_TEST_CASE(Initialize) { - BOOST_REQUIRE_NO_THROW( ItemSize itemSize ); + BOOST_REQUIRE_NO_THROW(ParserItemSize itemSize); } - - BOOST_AUTO_TEST_CASE(Default) { - ItemSize itemSize; - BOOST_REQUIRE_EQUAL( itemSize.sizeType() , UNSPECIFIED ); - BOOST_REQUIRE_THROW( itemSize.sizeValue() , std::invalid_argument ); + ParserItemSize itemSize; + BOOST_REQUIRE_EQUAL(itemSize.sizeType(), UNSPECIFIED); + BOOST_REQUIRE_THROW(itemSize.sizeValue(), std::invalid_argument); } - - BOOST_AUTO_TEST_CASE(Fixed) { - ItemSize itemSize(100); - BOOST_REQUIRE_EQUAL( itemSize.sizeType() , ITEM_FIXED ); - BOOST_REQUIRE_EQUAL( itemSize.sizeValue() , 100U ); + ParserItemSize itemSize(100); + BOOST_REQUIRE_EQUAL(itemSize.sizeType(), ITEM_FIXED); + BOOST_REQUIRE_EQUAL(itemSize.sizeValue(), 100U); } - - BOOST_AUTO_TEST_CASE(Fixed2) { - ItemSize itemSize(ITEM_FIXED , 100U); - BOOST_REQUIRE_EQUAL( itemSize.sizeType() , ITEM_FIXED ); - BOOST_REQUIRE_EQUAL( itemSize.sizeValue() , 100U ); + ParserItemSize itemSize(ITEM_FIXED, 100U); + BOOST_REQUIRE_EQUAL(itemSize.sizeType(), ITEM_FIXED); + BOOST_REQUIRE_EQUAL(itemSize.sizeValue(), 100U); } +BOOST_AUTO_TEST_CASE(Constructor_UnspecifiedWithValue_ShouldThrow) { + BOOST_REQUIRE_THROW(ParserItemSize itemSize(UNSPECIFIED, 100U), std::invalid_argument); +} +BOOST_AUTO_TEST_CASE(Constructor_BoxWithValue_ShouldThrow) { + BOOST_REQUIRE_THROW(ParserItemSize itemSize(ITEM_BOX, 100U), std::invalid_argument); +} BOOST_AUTO_TEST_CASE(Box) { - ItemSize itemSize(ITEM_BOX); - BOOST_REQUIRE_EQUAL( itemSize.sizeType() , ITEM_BOX ); - BOOST_REQUIRE_THROW( itemSize.sizeValue() , std::invalid_argument ); + ParserItemSize itemSize(ITEM_BOX); + BOOST_REQUIRE_EQUAL(itemSize.sizeType(), ITEM_BOX); + BOOST_REQUIRE_THROW(itemSize.sizeValue(), std::invalid_argument); } - BOOST_AUTO_TEST_CASE(Boost) { - ItemSizeConstPtr itemSize( new ItemSize( ITEM_BOX )); - BOOST_REQUIRE_EQUAL( itemSize->sizeType() , ITEM_BOX ); - BOOST_REQUIRE_THROW( itemSize->sizeValue() , std::invalid_argument ); + ParserItemSizeConstPtr itemSize(new ParserItemSize(ITEM_BOX)); + BOOST_REQUIRE_EQUAL(itemSize->sizeType(), ITEM_BOX); + BOOST_REQUIRE_THROW(itemSize->sizeValue(), std::invalid_argument); } diff --git a/tests/ParserKWTests.cpp b/tests/ParserKWTests.cpp index bf7950ed4..7a05d5438 100644 --- a/tests/ParserKWTests.cpp +++ b/tests/ParserKWTests.cpp @@ -27,29 +27,29 @@ using namespace Opm; BOOST_AUTO_TEST_CASE(Initialize) { - BOOST_REQUIRE_NO_THROW(ParserKW parserKW); + BOOST_REQUIRE_NO_THROW(ParserKW parserKW); - ParserKW parserKW; - BOOST_CHECK_EQUAL(parserKW.getName(), ""); + ParserKW parserKW; + BOOST_CHECK_EQUAL(parserKW.getName(), ""); } BOOST_AUTO_TEST_CASE(NamedInit) { - std::string keyword("KEYWORD"); + std::string keyword("KEYWORD"); - ParserRecordSizeConstPtr recordSize(new ParserRecordSize(100)); - ParserKW parserKW(keyword, recordSize); - BOOST_CHECK_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_CHECK_THROW(ParserKW parserKW(keyword, recordSize), std::invalid_argument); + std::string keyword("KEYWORDTOOLONG"); + ParserRecordSizeConstPtr recordSize(new ParserRecordSize(100)); + BOOST_CHECK_THROW(ParserKW parserKW(keyword, recordSize), std::invalid_argument); } BOOST_AUTO_TEST_CASE(MixedCase) { - std::string keyword("KeyWord"); + std::string keyword("KeyWord"); - ParserRecordSizeConstPtr recordSize(new ParserRecordSize(100)); - BOOST_CHECK_THROW(ParserKW parserKW(keyword, recordSize), std::invalid_argument); + ParserRecordSizeConstPtr recordSize(new ParserRecordSize(100)); + BOOST_CHECK_THROW(ParserKW parserKW(keyword, recordSize), std::invalid_argument); } diff --git a/tests/ParserRecordItemTest.cpp b/tests/ParserRecordItemTest.cpp index 6ffdd3d72..4a6a4d703 100644 --- a/tests/ParserRecordItemTest.cpp +++ b/tests/ParserRecordItemTest.cpp @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with OPM. If not, see . -*/ + */ #define BOOST_TEST_MODULE ParserTests @@ -27,5 +27,5 @@ using namespace Opm; BOOST_AUTO_TEST_CASE(Initialize_int) { - BOOST_REQUIRE_NO_THROW( ParserRecordItem item ); + BOOST_REQUIRE_NO_THROW(ParserRecordItem item); } diff --git a/tests/ParserRecordItemTests.cpp b/tests/ParserRecordItemTests.cpp index 470e10844..97a78fa7a 100644 --- a/tests/ParserRecordItemTests.cpp +++ b/tests/ParserRecordItemTests.cpp @@ -15,118 +15,106 @@ You should have received a copy of the GNU General Public License along with OPM. If not, see . -*/ + */ #define BOOST_TEST_MODULE ParserTests #include -#include "opm/parser/eclipse/Parser/ParserRecordItem.hpp" -#include +#include "opm/parser/eclipse/Parser/ParserItem.hpp" +#include using namespace Opm; BOOST_AUTO_TEST_CASE(Initialize) { - ItemSizeConstPtr itemSize( new ItemSize(10)); + ParserItemSizeConstPtr itemSize(new ParserItemSize(10)); - BOOST_REQUIRE_NO_THROW( ParserRecordItem item1("ITEM1" , itemSize)); - BOOST_REQUIRE_NO_THROW( ParserRecordItem item1("ITEM1" , itemSize)); - BOOST_REQUIRE_NO_THROW( ParserRecordItem item1("ITEM1" , itemSize)); - BOOST_REQUIRE_NO_THROW( ParserRecordItem item1("ITEM1" , itemSize)); + BOOST_REQUIRE_NO_THROW(ParserItem item1("ITEM1", itemSize)); + BOOST_REQUIRE_NO_THROW(ParserItem item1("ITEM1", itemSize)); + BOOST_REQUIRE_NO_THROW(ParserItem item1("ITEM1", itemSize)); + BOOST_REQUIRE_NO_THROW(ParserItem item1("ITEM1", itemSize)); } - - - BOOST_AUTO_TEST_CASE(TestScanInt) { - ItemSizeConstPtr itemSize( new ItemSize(10)); - ParserRecordItem itemInt("ITEM2" , itemSize); - int value = 78; - - BOOST_REQUIRE( itemInt.scanItem("100" , value)); - BOOST_REQUIRE_EQUAL( value , 100 ); - - BOOST_REQUIRE( !itemInt.scanItem("200X" , value)); - BOOST_REQUIRE_EQUAL( value , 100 ); + ParserItemSizeConstPtr itemSize(new ParserItemSize(10)); + ParserItem itemInt("ITEM2", itemSize); + int value = 78; - BOOST_REQUIRE( !itemInt.scanItem("" , value)); - BOOST_REQUIRE_EQUAL( value , 100 ); + BOOST_REQUIRE(itemInt.scanItem("100", value)); + BOOST_REQUIRE_EQUAL(value, 100); + + BOOST_REQUIRE(!itemInt.scanItem("200X", value)); + BOOST_REQUIRE_EQUAL(value, 100); + + BOOST_REQUIRE(!itemInt.scanItem("", value)); + BOOST_REQUIRE_EQUAL(value, 100); } - - BOOST_AUTO_TEST_CASE(TestScanDouble) { - ItemSizeConstPtr itemSize( new ItemSize(10)); - ParserRecordItem itemDouble("ITEM2" , itemSize); - double value = 78; - - BOOST_REQUIRE( itemDouble.scanItem("100.25" , value)); - BOOST_REQUIRE_EQUAL( value , 100.25 ); - - BOOST_REQUIRE( !itemDouble.scanItem("200X" , value)); - BOOST_REQUIRE_EQUAL( value , 100.25 ); + ParserItemSizeConstPtr itemSize(new ParserItemSize(10)); + ParserItem itemDouble("ITEM2", itemSize); + double value = 78; - BOOST_REQUIRE( !itemDouble.scanItem("" , value)); - BOOST_REQUIRE_EQUAL( value , 100.25 ); + BOOST_REQUIRE(itemDouble.scanItem("100.25", value)); + BOOST_REQUIRE_EQUAL(value, 100.25); + + BOOST_REQUIRE(!itemDouble.scanItem("200X", value)); + BOOST_REQUIRE_EQUAL(value, 100.25); + + BOOST_REQUIRE(!itemDouble.scanItem("", value)); + BOOST_REQUIRE_EQUAL(value, 100.25); } - - BOOST_AUTO_TEST_CASE(TestScanString) { - ItemSizeConstPtr itemSize( new ItemSize(10)); - ParserRecordItem itemString("ITEM2" , itemSize); - std::string value = "Hei"; - - BOOST_REQUIRE( itemString.scanItem("100.25" , value)); - BOOST_REQUIRE_EQUAL( value , "100.25" ); - - BOOST_REQUIRE( !itemString.scanItem("" , value)); - BOOST_REQUIRE_EQUAL( value , "100.25" ); + ParserItemSizeConstPtr itemSize(new ParserItemSize(10)); + ParserItem itemString("ITEM2", itemSize); + std::string value = "Hei"; + + BOOST_REQUIRE(itemString.scanItem("100.25", value)); + BOOST_REQUIRE_EQUAL(value, "100.25"); + + BOOST_REQUIRE(!itemString.scanItem("", value)); + BOOST_REQUIRE_EQUAL(value, "100.25"); } - - BOOST_AUTO_TEST_CASE(TestScanBool) { - ItemSizeConstPtr itemSize( new ItemSize(10)); - ParserRecordItem itemString("ITEM2" , itemSize); - bool value = true; - - BOOST_REQUIRE( itemString.scanItem("1" , value)); - BOOST_REQUIRE_EQUAL( value , true ); + ParserItemSizeConstPtr itemSize(new ParserItemSize(10)); + ParserItem itemString("ITEM2", itemSize); + bool value = true; - BOOST_REQUIRE( itemString.scanItem("0" , value)); - BOOST_REQUIRE_EQUAL( value , false ); - - BOOST_REQUIRE( !itemString.scanItem("" , value)); - BOOST_REQUIRE_EQUAL( value , false ); + BOOST_REQUIRE(itemString.scanItem("1", value)); + BOOST_REQUIRE_EQUAL(value, true); - BOOST_REQUIRE( !itemString.scanItem("10" , value)); - BOOST_REQUIRE_EQUAL( value , false ); + BOOST_REQUIRE(itemString.scanItem("0", value)); + BOOST_REQUIRE_EQUAL(value, false); + + BOOST_REQUIRE(!itemString.scanItem("", value)); + BOOST_REQUIRE_EQUAL(value, false); + + BOOST_REQUIRE(!itemString.scanItem("10", value)); + BOOST_REQUIRE_EQUAL(value, false); } - /*****************************************************************/ BOOST_AUTO_TEST_CASE(TestScanItemsFail) { - ItemSizeConstPtr itemSize( new ItemSize( ITEM_BOX ) ); - ParserRecordItem itemInt("ITEM2" , itemSize); - std::vector values; - - BOOST_REQUIRE_THROW( itemInt.scanItems("100 100 100" , values) , std::invalid_argument ); + ParserItemSizeConstPtr itemSize(new ParserItemSize(ITEM_BOX)); + ParserItem itemInt("ITEM2", itemSize); + std::vector values; + + BOOST_REQUIRE_THROW(itemInt.scanItems("100 100 100", values), std::invalid_argument); } - - BOOST_AUTO_TEST_CASE(TestScanItemsInt) { - ItemSizeConstPtr itemSize( new ItemSize( 4 ) ); - ParserRecordItem itemInt("ITEM2" , itemSize); - std::vector values; + ParserItemSizeConstPtr itemSize(new ParserItemSize(4)); + ParserItem itemInt("ITEM2", itemSize); + std::vector values; - BOOST_REQUIRE_EQUAL( itemInt.scanItems("1 2 3 4" , values) , 4 ); - BOOST_REQUIRE_EQUAL( values[0] , 1); - BOOST_REQUIRE_EQUAL( values[1] , 2); - BOOST_REQUIRE_EQUAL( values[2] , 3); - BOOST_REQUIRE_EQUAL( values[3] , 4); + BOOST_REQUIRE_EQUAL(itemInt.scanItems("1 2 3 4", values), 4); + BOOST_REQUIRE_EQUAL(values[0], 1); + BOOST_REQUIRE_EQUAL(values[1], 2); + BOOST_REQUIRE_EQUAL(values[2], 3); + BOOST_REQUIRE_EQUAL(values[3], 4); } diff --git a/tests/ParserRecordSizeTests.cpp b/tests/ParserRecordSizeTests.cpp index d36cd211c..e9f1b255d 100644 --- a/tests/ParserRecordSizeTests.cpp +++ b/tests/ParserRecordSizeTests.cpp @@ -27,17 +27,17 @@ 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_CHECK_THROW(recordSize.recordSize(), std::logic_error); + ParserRecordSize recordSize; + BOOST_CHECK_THROW(recordSize.recordSize(), std::logic_error); } BOOST_AUTO_TEST_CASE(FixedSize) { - BOOST_REQUIRE_NO_THROW(ParserRecordSize recordSize(100)); - ParserRecordSize recordSize(100); + BOOST_REQUIRE_NO_THROW(ParserRecordSize recordSize(100)); + ParserRecordSize recordSize(100); - BOOST_CHECK_EQUAL(recordSize.recordSize(), (size_t) 100); + BOOST_CHECK_EQUAL(recordSize.recordSize(), (size_t) 100); } diff --git a/tests/ParserTests.cpp b/tests/ParserTests.cpp index 745fb7e64..eff6532c5 100644 --- a/tests/ParserTests.cpp +++ b/tests/ParserTests.cpp @@ -31,115 +31,115 @@ using namespace Opm; BOOST_AUTO_TEST_CASE(RawDeckPrintToOStream) { - 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()); - std::cout << *rawDeck << "\n"; + 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(Parser parser); } BOOST_AUTO_TEST_CASE(ParseWithInvalidInputFileThrows) { - ParserPtr parser(new Parser()); - BOOST_CHECK_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::filesystem::path singleKeywordFile("testdata/small.data"); + ParserPtr parser(new Parser()); - BOOST_CHECK_NO_THROW(parser->parse(singleKeywordFile.string())); + 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::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_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(); + 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::string& recordString = record->getRecordString(); + BOOST_CHECK_EQUAL("'NODIR' 'REVERS' 1 20", recordString); - const std::vector& recordElements = record->getItems(); - BOOST_CHECK_EQUAL((unsigned) 4, recordElements.size()); + const std::vector& 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_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_CHECK_EQUAL((unsigned) 7, rawDeck->getNumberOfKeywords()); + 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()); + 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()); + // 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("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("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("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("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(); + matchingKeyword = rawDeck->getKeyword("ABCDAD"); + BOOST_CHECK_EQUAL("ABCDAD", matchingKeyword->getKeyword()); + records = matchingKeyword->getRecords(); - BOOST_CHECK_EQUAL((unsigned) 2, records.size()); + BOOST_CHECK_EQUAL((unsigned) 2, records.size()); } BOOST_AUTO_TEST_CASE(ParserAddKW) { - Parser parser; - { - ParserRecordSizePtr recordSize(new ParserRecordSize(9)); - ParserKWPtr equilKW(new ParserKW("EQUIL", recordSize)); + Parser parser; + { + ParserRecordSizePtr recordSize(new ParserRecordSize(9)); + ParserKWPtr equilKW(new ParserKW("EQUIL", recordSize)); - parser.addKW(equilKW); - } + parser.addKW(equilKW); + } } diff --git a/tests/ParserTestsInternalData.cpp b/tests/ParserTestsInternalData.cpp index 0537672eb..8e0bcd62b 100644 --- a/tests/ParserTestsInternalData.cpp +++ b/tests/ParserTestsInternalData.cpp @@ -34,44 +34,44 @@ 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"; + boost::filesystem::path multipleKeywordFile("testdata/statoil/gurbat_trimmed.DATA"); + std::cout << "BOOST path running ParseFullTestFile\n"; - ParserPtr parser(new Parser()); + ParserPtr parser(new Parser()); - RawDeckPtr rawDeck = parser->parse(multipleKeywordFile.string()); + 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()); + //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"); + boost::filesystem::path multipleKeywordFile("testdata/statoil/ECLIPSE.DATA"); - ParserPtr parser(new Parser()); + 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 + 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 records = matchingKeyword->getRecords(); - BOOST_CHECK_EQUAL("OIL", matchingKeyword->getKeyword()); + RawKeywordConstPtr matchingKeyword = rawDeck->getKeyword("OIL"); + std::list records = matchingKeyword->getRecords(); + BOOST_CHECK_EQUAL("OIL", matchingKeyword->getKeyword()); - BOOST_CHECK_EQUAL((unsigned) 0, records.size()); + 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()); + 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 recordItems = records.front()->getItems(); - BOOST_CHECK_EQUAL((unsigned) 6, recordItems.size()); + const std::string& recordString = records.front()->getRecordString(); + BOOST_CHECK_EQUAL("20 20 15 15 15 50", recordString); + std::vector recordItems = records.front()->getItems(); + BOOST_CHECK_EQUAL((unsigned) 6, recordItems.size()); } diff --git a/tests/RawDeckTests.cpp b/tests/RawDeckTests.cpp index dc8e1bb46..66269d6eb 100644 --- a/tests/RawDeckTests.cpp +++ b/tests/RawDeckTests.cpp @@ -26,21 +26,20 @@ #include #include - 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()); + 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")); + 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); + Opm::RawParserKWsConstPtr fixedKeywords(new Opm::RawParserKWs()); + Opm::RawDeckPtr rawDeck(new Opm::RawDeck(fixedKeywords)); + BOOST_CHECK_THROW(rawDeck->getKeyword("TEST"), std::invalid_argument); } diff --git a/tests/RawKeywordTests.cpp b/tests/RawKeywordTests.cpp index 5542e52b2..26b00d5ee 100644 --- a/tests/RawKeywordTests.cpp +++ b/tests/RawKeywordTests.cpp @@ -23,42 +23,42 @@ #include BOOST_AUTO_TEST_CASE(RawKeywordEmptyConstructorEmptyKeyword) { - Opm::RawKeyword keyword; - BOOST_CHECK(keyword.getKeyword() == ""); + Opm::RawKeyword keyword; + BOOST_CHECK(keyword.getKeyword() == ""); } BOOST_AUTO_TEST_CASE(RawKeywordGiveKeywordToConstructorKeywordSet) { - Opm::RawKeyword keyword("KEYYWORD"); - BOOST_CHECK(keyword.getKeyword() == "KEYYWORD"); + 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_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); + 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); + 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); + 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"); + 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"); + Opm::RawKeyword keyword; + keyword.setKeyword("GOODONEE "); + BOOST_CHECK(keyword.getKeyword() == "GOODONEE"); } diff --git a/tests/RawParserKWsTests.cpp b/tests/RawParserKWsTests.cpp index 527d75bdc..840f34e50 100644 --- a/tests/RawParserKWsTests.cpp +++ b/tests/RawParserKWsTests.cpp @@ -26,26 +26,26 @@ using namespace Opm; BOOST_AUTO_TEST_CASE(KeywordExists_KeywordNotPresent_ReturnsFalse) { - RawParserKWsConstPtr parserKWs(new RawParserKWs()); - BOOST_CHECK_EQUAL(false, parserKWs->keywordExists("FLASKE")); + 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")); + 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); + 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")); + 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")); + RawParserKWsConstPtr parserKWs(new RawParserKWs()); + BOOST_CHECK_EQUAL((unsigned) 0, parserKWs->getFixedNumberOfRecords("METRIC")); } diff --git a/tests/RawRecordTests.cpp b/tests/RawRecordTests.cpp index 18213479a..ab184a0b9 100644 --- a/tests/RawRecordTests.cpp +++ b/tests/RawRecordTests.cpp @@ -23,31 +23,31 @@ #include 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); + 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 /")); + Opm::RawRecordPtr record(new Opm::RawRecord(" 'NODIR ' 'REVERS' 1 20 /")); - const std::vector& recordElements = record->getItems(); - BOOST_CHECK_EQUAL((unsigned) 4, recordElements.size()); + const std::vector& 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_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); + 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); + 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); }