Merged changes from Kristian
This commit is contained in:
commit
e860091f30
@ -1,5 +1,5 @@
|
||||
|
||||
add_library(Parser Parser.cpp data/KeywordRecordSet.cpp ParserKW.cpp)
|
||||
add_library(Parser Parser.cpp data/RawDeck.cpp data/RawKeyword.cpp data/RawRecord.cpp ParserKW.cpp)
|
||||
add_library(Logger Logger.cpp)
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
@ -27,23 +27,20 @@ namespace Opm {
|
||||
const int Logger::INFO = 1;
|
||||
const int Logger::ERROR = 2;
|
||||
|
||||
Logger::Logger(int logLevel) {
|
||||
m_logLevel = logLevel;
|
||||
m_logFile = "log.log";
|
||||
initLogger();
|
||||
}
|
||||
|
||||
Logger::Logger(const std::string& path, int logLevel) {
|
||||
m_logLevel = logLevel;
|
||||
m_logFile = path;
|
||||
initLogger();
|
||||
}
|
||||
std::string Logger::m_logFile = "log.log";
|
||||
int Logger::m_logLevel = INFO;
|
||||
std::ofstream Logger::m_logStream;
|
||||
|
||||
void Logger::setLogLevel(int logLevel) {
|
||||
m_logLevel = logLevel;
|
||||
}
|
||||
|
||||
void Logger::setPath(const std::string& path) {
|
||||
m_logFile = path;
|
||||
}
|
||||
|
||||
void Logger::debug(const std::string& message) {
|
||||
|
||||
if (m_logLevel <= DEBUG) {
|
||||
log(message, "DEBUG");
|
||||
}
|
||||
|
@ -31,21 +31,19 @@ namespace Opm {
|
||||
static const int INFO;
|
||||
static const int ERROR;
|
||||
|
||||
Logger(int logLevel = INFO);
|
||||
Logger(const std::string& path, int logLevel = INFO);
|
||||
|
||||
void setLogLevel(int logLevel);
|
||||
void debug(const std::string& message);
|
||||
void info(const std::string& message);
|
||||
void error(const std::string& message);
|
||||
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:
|
||||
std::string m_logFile;
|
||||
std::ofstream m_logStream;
|
||||
int m_logLevel;
|
||||
void initLogger();
|
||||
void log(const std::string& message, std::string logLevel);
|
||||
void initLoggingConstants();
|
||||
static std::string m_logFile;
|
||||
static std::ofstream m_logStream;
|
||||
static int m_logLevel;
|
||||
static void initLogger();
|
||||
static void log(const std::string& message, std::string logLevel);
|
||||
static void initLoggingConstants();
|
||||
};
|
||||
}// namespace Opm
|
||||
#endif /* LOGGER_HPP */
|
||||
|
@ -16,14 +16,6 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <regex.h>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
namespace fs = boost::filesystem;
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include "Parser.hpp"
|
||||
|
||||
namespace Opm {
|
||||
@ -31,92 +23,12 @@ namespace Opm {
|
||||
Parser::Parser() {
|
||||
}
|
||||
|
||||
Parser::Parser(const std::string &path) {
|
||||
m_dataFilePath = path;
|
||||
}
|
||||
|
||||
void Parser::parse() {
|
||||
parse(m_dataFilePath);
|
||||
}
|
||||
|
||||
void Parser::parse(const std::string &path) {
|
||||
checkInputFile(path);
|
||||
std::ifstream file;
|
||||
initInputStream(path, file);
|
||||
|
||||
readKeywordAndDataTokens(file);
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
int Parser::getNumberOfKeywords() {
|
||||
return m_keywordRawDatas.size();
|
||||
}
|
||||
|
||||
void Parser::readKeywordAndDataTokens(std::ifstream& inputstream) {
|
||||
std::string line;
|
||||
KeywordRecordSet currentKeywordRecordSet;
|
||||
while (std::getline(inputstream, line)) {
|
||||
if (isKeyword(line)) {
|
||||
currentKeywordRecordSet = KeywordRecordSet(line);
|
||||
m_keywordRawDatas.push_back(currentKeywordRecordSet);
|
||||
} else {
|
||||
addDataToDataToken(line, currentKeywordRecordSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Parser::addDataToDataToken(const std::string& line, KeywordRecordSet& currentKeywordRecordSet) {
|
||||
if (currentKeywordRecordSet.getKeyword() != "" && looksLikeData(line)) {
|
||||
currentKeywordRecordSet.addDataElement(line);
|
||||
}
|
||||
}
|
||||
|
||||
bool Parser::looksLikeData(const std::string& line) {
|
||||
if (line.substr(0, 2) == "--") {
|
||||
m_logger.debug("COMMENT LINE <" + line + ">");
|
||||
return false;
|
||||
} else if (boost::algorithm::trim_copy(line).length() == 0) {
|
||||
m_logger.debug("EMPTY LINE <" + line + ">");
|
||||
return false;
|
||||
} else {
|
||||
m_logger.debug("LOOKS LIKE DATA<" + line + ">");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool Parser::isKeyword(const std::string& line) {
|
||||
std::string keywordRegex = "^[A-Z]{1,8}$";
|
||||
int status;
|
||||
regex_t re;
|
||||
regmatch_t rm;
|
||||
if (regcomp(&re, keywordRegex.c_str(), REG_EXTENDED) != 0) {
|
||||
m_logger.error("Unable to compile regular expression for keyword! Expression: " + keywordRegex);
|
||||
throw std::runtime_error("Unable to compile regular expression for keyword! Expression: " + keywordRegex);
|
||||
}
|
||||
|
||||
std::string trimmedRight = boost::trim_right_copy(line);
|
||||
status = regexec(&re, trimmedRight.c_str(), 1, &rm, 0);
|
||||
regfree(&re);
|
||||
|
||||
if (status == 0) {
|
||||
m_logger.debug("KEYWORD LINE <" + line + ">");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Parser::initInputStream(const std::string &path, std::ifstream& file) {
|
||||
m_logger.info("Initializing from file: " + path);
|
||||
file.open(path.c_str());
|
||||
}
|
||||
|
||||
void Parser::checkInputFile(const std::string& inputPath) {
|
||||
fs::path pathToInputFile(inputPath);
|
||||
if (!fs::is_regular_file(pathToInputFile)) {
|
||||
m_logger.error("Unable to open file with path: " + inputPath);
|
||||
throw std::invalid_argument("Given path is not a valid file-path, path: " + inputPath);
|
||||
}
|
||||
RawDeckPtr Parser::parse(const std::string &path) {
|
||||
Logger::info("Starting parsing of file: " + path);
|
||||
RawDeckPtr rawDeck(new RawDeck());
|
||||
rawDeck -> readDataIntoDeck(path);
|
||||
Logger::info("Done parsing of file: " + path);
|
||||
return rawDeck;
|
||||
}
|
||||
|
||||
Parser::~Parser() {
|
||||
|
@ -21,33 +21,25 @@
|
||||
#define PARSER_H
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include "Logger.hpp"
|
||||
#include "data/KeywordRecordSet.hpp"
|
||||
#include "data/RawKeyword.hpp"
|
||||
#include "data/RawDeck.hpp"
|
||||
|
||||
|
||||
namespace Opm {
|
||||
|
||||
class Parser {
|
||||
public:
|
||||
Parser();
|
||||
Parser(const std::string &path);
|
||||
void parse();
|
||||
void parse(const std::string &path);
|
||||
int getNumberOfKeywords();
|
||||
void getListOfKeywords(std::list<std::string>& list);
|
||||
RawDeckPtr parse(const std::string &path);
|
||||
virtual ~Parser();
|
||||
private:
|
||||
std::string m_dataFilePath;
|
||||
Logger m_logger;
|
||||
std::list<KeywordRecordSet> m_keywordRawDatas;
|
||||
void initInputStream(const std::string &path, std::ifstream& file);
|
||||
void readKeywordAndDataTokens(std::ifstream& inputstream);
|
||||
bool isKeyword(const std::string& line);
|
||||
void addDataToDataToken(const std::string& line, KeywordRecordSet& currentKeywordRecordSet);
|
||||
bool looksLikeData(const std::string& line);
|
||||
void checkInputFile(const std::string& pathToInputFile);
|
||||
|
||||
//Logger m_logger;
|
||||
};
|
||||
|
||||
typedef boost::shared_ptr<Parser> ParserPtr;
|
||||
} // namespace Opm
|
||||
#endif /* PARSER_H */
|
||||
|
||||
|
@ -1,51 +0,0 @@
|
||||
/*
|
||||
Copyright 2013 Statoil ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <utility>
|
||||
#include "KeywordRecordSet.hpp"
|
||||
namespace Opm {
|
||||
|
||||
KeywordRecordSet::KeywordRecordSet() {
|
||||
}
|
||||
|
||||
KeywordRecordSet::KeywordRecordSet(const std::string& keyword, const std::list<std::string>& dataElements) {
|
||||
setKeyword(keyword);
|
||||
m_data = dataElements;
|
||||
}
|
||||
|
||||
KeywordRecordSet::KeywordRecordSet(const std::string& keyword) {
|
||||
m_keyword = keyword;
|
||||
}
|
||||
|
||||
void KeywordRecordSet::setKeyword(const std::string& keyword) {
|
||||
m_keyword = keyword;
|
||||
}
|
||||
|
||||
void KeywordRecordSet::addDataElement(const std::string& element) {
|
||||
m_data.push_back(element);
|
||||
}
|
||||
|
||||
std::string KeywordRecordSet::getKeyword() {
|
||||
return m_keyword;
|
||||
}
|
||||
|
||||
KeywordRecordSet::~KeywordRecordSet() {
|
||||
}
|
||||
}
|
||||
|
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* File: KeywordRawData.hpp
|
||||
* Author: kflik
|
||||
*
|
||||
* Created on March 20, 2013, 3:59 PM
|
||||
*/
|
||||
|
||||
#ifndef KEYWORDRECORDSET_HPP
|
||||
#define KEYWORDRECORDSET_HPP
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <list>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
class KeywordRecordSet {
|
||||
public:
|
||||
KeywordRecordSet();
|
||||
KeywordRecordSet(const std::string& keyword, const std::list<std::string>& dataElements);
|
||||
KeywordRecordSet(const std::string& keyword);
|
||||
|
||||
std::string getKeyword();
|
||||
void setKeyword(const std::string& keyword);
|
||||
void addDataElement(const std::string& element);
|
||||
virtual ~KeywordRecordSet();
|
||||
|
||||
private:
|
||||
std::string m_keyword;
|
||||
std::list<std::string> m_data;
|
||||
};
|
||||
}
|
||||
#endif /* KEYWORDRECORDSET_HPP */
|
||||
|
94
opm/parser/eclipse/data/RawDeck.cpp
Normal file
94
opm/parser/eclipse/data/RawDeck.cpp
Normal file
@ -0,0 +1,94 @@
|
||||
/*
|
||||
Copyright 2013 Statoil ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <iostream>
|
||||
#include "RawDeck.hpp"
|
||||
|
||||
namespace Opm {
|
||||
|
||||
RawDeck::RawDeck() {
|
||||
}
|
||||
|
||||
RawKeywordPtr RawDeck::getKeyword(const std::string& keyword) {
|
||||
for(std::list<RawKeywordPtr>::iterator it = m_keywords.begin(); it != m_keywords.end(); it++) {
|
||||
if ((*it)->getKeyword() == keyword) {
|
||||
return (*it);
|
||||
}
|
||||
}
|
||||
return RawKeywordPtr(new RawKeyword());
|
||||
}
|
||||
|
||||
void RawDeck::readDataIntoDeck(const std::string& path) {
|
||||
checkInputFile(path);
|
||||
std::ifstream inputstream;
|
||||
Logger::info("Initializing from file: " + path);
|
||||
inputstream.open(path.c_str());
|
||||
|
||||
std::string line;
|
||||
std::string keywordString;
|
||||
RawKeywordPtr currentRawKeyword;
|
||||
while (std::getline(inputstream, line)) {
|
||||
if (RawKeyword::tryParseKeyword(line, keywordString)) {
|
||||
currentRawKeyword = RawKeywordPtr(new RawKeyword(keywordString));
|
||||
m_keywords.push_back(currentRawKeyword);
|
||||
} else if (currentRawKeyword != NULL) {
|
||||
addRawRecordStringToRawKeyword(line, currentRawKeyword);
|
||||
}
|
||||
}
|
||||
inputstream.close();
|
||||
}
|
||||
|
||||
void RawDeck::addRawRecordStringToRawKeyword(const std::string& line, RawKeywordPtr currentRawKeyword) {
|
||||
if (looksLikeData(line)) {
|
||||
currentRawKeyword->addRawRecordString(line);
|
||||
}
|
||||
}
|
||||
|
||||
bool RawDeck::looksLikeData(const std::string& line) {
|
||||
if (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 (line.substr(0, 1) == "/") {
|
||||
Logger::debug("END OF RECORD <" + line + ">");
|
||||
return false;
|
||||
} else {
|
||||
Logger::debug("LOOKS LIKE DATA<" + line + ">");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void RawDeck::checkInputFile(const std::string& 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);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int RawDeck::getNumberOfKeywords() {
|
||||
return m_keywords.size();
|
||||
}
|
||||
|
||||
RawDeck::~RawDeck() {
|
||||
}
|
||||
}
|
36
opm/parser/eclipse/data/RawDeck.hpp
Normal file
36
opm/parser/eclipse/data/RawDeck.hpp
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* File: RawDeck.hpp
|
||||
* Author: kflik
|
||||
*
|
||||
* Created on March 21, 2013, 2:02 PM
|
||||
*/
|
||||
|
||||
#ifndef RAWDECK_HPP
|
||||
#define RAWDECK_HPP
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include "opm/parser/eclipse/Logger.hpp"
|
||||
#include "RawKeyword.hpp"
|
||||
|
||||
namespace Opm {
|
||||
|
||||
class RawDeck {
|
||||
public:
|
||||
RawDeck();
|
||||
void readDataIntoDeck(const std::string& path);
|
||||
RawKeywordPtr getKeyword(const std::string& keyword);
|
||||
unsigned int getNumberOfKeywords();
|
||||
virtual ~RawDeck();
|
||||
private:
|
||||
std::list<RawKeywordPtr> m_keywords;
|
||||
void addRawRecordStringToRawKeyword(const std::string& line, RawKeywordPtr currentRawKeyword);
|
||||
bool looksLikeData(const std::string& line);
|
||||
void checkInputFile(const std::string& inputPath);
|
||||
};
|
||||
|
||||
typedef boost::shared_ptr<RawDeck> RawDeckPtr;
|
||||
}
|
||||
|
||||
#endif /* RAWDECK_HPP */
|
||||
|
95
opm/parser/eclipse/data/RawKeyword.cpp
Normal file
95
opm/parser/eclipse/data/RawKeyword.cpp
Normal file
@ -0,0 +1,95 @@
|
||||
/*
|
||||
Copyright 2013 Statoil ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stdexcept>
|
||||
#include <regex.h>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include "RawKeyword.hpp"
|
||||
#include <iostream>
|
||||
|
||||
namespace Opm {
|
||||
RawKeyword::RawKeyword() {
|
||||
}
|
||||
|
||||
RawKeyword::RawKeyword(const std::string& keyword) {
|
||||
setKeyword(keyword);
|
||||
}
|
||||
|
||||
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() > 8) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void RawKeyword::addRawRecordString(const std::string& partialRecordString) {
|
||||
m_partialRecordString += partialRecordString;
|
||||
if (RawRecord::isCompleteRecordString(m_partialRecordString)) {
|
||||
RawRecordPtr record(new RawRecord(m_partialRecordString));
|
||||
m_records.push_back(record);
|
||||
m_partialRecordString.clear();
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int RawKeyword::getNumberOfRecords() {
|
||||
return m_records.size();
|
||||
}
|
||||
|
||||
void RawKeyword::getRecords(std::list<RawRecordPtr>& records) {
|
||||
records = m_records;
|
||||
}
|
||||
|
||||
std::string RawKeyword::getKeyword() {
|
||||
return m_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]{1,8}$";
|
||||
int status;
|
||||
regex_t re;
|
||||
regmatch_t rm;
|
||||
if (regcomp(&re, keywordRegex.c_str(), REG_EXTENDED) != 0) {
|
||||
throw std::runtime_error("Unable to compile regular expression for keyword! Expression: " + keywordRegex);
|
||||
}
|
||||
|
||||
status = regexec(&re, keywordCandidate.c_str(), 1, &rm, 0);
|
||||
regfree(&re);
|
||||
|
||||
if (status == 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
RawKeyword::~RawKeyword() {
|
||||
}
|
||||
}
|
||||
|
41
opm/parser/eclipse/data/RawKeyword.hpp
Normal file
41
opm/parser/eclipse/data/RawKeyword.hpp
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* File: KeywordRawData.hpp
|
||||
* Author: kflik
|
||||
*
|
||||
* Created on March 20, 2013, 3:59 PM
|
||||
*/
|
||||
|
||||
#ifndef RAWKEYWORD_HPP
|
||||
#define RAWKEYWORD_HPP
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <list>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include "opm/parser/eclipse/Logger.hpp"
|
||||
#include "RawRecord.hpp"
|
||||
|
||||
namespace Opm {
|
||||
class RawKeyword {
|
||||
public:
|
||||
RawKeyword();
|
||||
RawKeyword(const std::string& keyword);
|
||||
static bool tryParseKeyword(const std::string& line, std::string& result);
|
||||
std::string getKeyword();
|
||||
void getRecords(std::list<RawRecordPtr>& records);
|
||||
unsigned int getNumberOfRecords();
|
||||
void setKeyword(const std::string& keyword);
|
||||
void addRawRecordString(const std::string& partialRecordString);
|
||||
virtual ~RawKeyword();
|
||||
|
||||
private:
|
||||
std::string m_keyword;
|
||||
std::list<RawRecordPtr> m_records;
|
||||
std::string m_partialRecordString;
|
||||
static bool isValidKeyword(const std::string& keywordCandidate);
|
||||
};
|
||||
typedef boost::shared_ptr<RawKeyword> RawKeywordPtr;
|
||||
}
|
||||
#endif /* RAWKEYWORD_HPP */
|
||||
|
124
opm/parser/eclipse/data/RawRecord.cpp
Normal file
124
opm/parser/eclipse/data/RawRecord.cpp
Normal file
@ -0,0 +1,124 @@
|
||||
/*
|
||||
Copyright 2013 Statoil ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include "RawRecord.hpp"
|
||||
using namespace std;
|
||||
|
||||
namespace Opm {
|
||||
const char RawRecord::SLASH = '/';
|
||||
const char RawRecord::QUOTE = '\'';
|
||||
|
||||
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.
|
||||
*/
|
||||
RawRecord::RawRecord(const std::string& singleRecordString) {
|
||||
if (isCompleteRecordString(singleRecordString)) {
|
||||
setRecordString(singleRecordString);
|
||||
} else {
|
||||
throw std::invalid_argument("Input string is not a complete record string,"
|
||||
" offending string: " + singleRecordString);
|
||||
}
|
||||
|
||||
std::string tokenSeparators = "\t ";
|
||||
std::string quoteSeparators = "\'\"";
|
||||
char currentChar;
|
||||
char tokenStarter;
|
||||
std::string currentToken = "";
|
||||
for (unsigned i = 0; i < m_sanitizedRecordString.size(); i++) {
|
||||
currentChar = m_sanitizedRecordString[i];
|
||||
if (stringContains(tokenSeparators, currentChar)) {
|
||||
if (stringContains(quoteSeparators, tokenStarter)) {
|
||||
currentToken += currentChar;
|
||||
} else {
|
||||
if (currentToken.size() > 0) {
|
||||
m_recordItems.push_back(currentToken);
|
||||
currentToken.clear();
|
||||
}
|
||||
tokenStarter = currentChar;
|
||||
}
|
||||
} else if (stringContains(quoteSeparators, currentChar)) {
|
||||
if (currentChar == tokenStarter) {
|
||||
if (currentToken.size() > 0) {
|
||||
m_recordItems.push_back(currentToken);
|
||||
currentToken.clear();
|
||||
}
|
||||
tokenStarter = '\0';
|
||||
} else {
|
||||
tokenStarter = currentChar;
|
||||
currentToken.clear();
|
||||
}
|
||||
} else {
|
||||
currentToken += currentChar;
|
||||
}
|
||||
}
|
||||
if (currentToken.size() > 0) {
|
||||
m_recordItems.push_back(currentToken);
|
||||
currentToken.clear();
|
||||
}
|
||||
}
|
||||
|
||||
bool RawRecord::stringContains(std::string collection, char candidate) {
|
||||
return std::string::npos != collection.find(candidate);
|
||||
}
|
||||
|
||||
void RawRecord::getRecords(std::vector<std::string>& recordItems) {
|
||||
recordItems = m_recordItems;
|
||||
}
|
||||
|
||||
void RawRecord::getRecordString(std::string& recordString) {
|
||||
recordString = m_sanitizedRecordString;
|
||||
}
|
||||
|
||||
bool RawRecord::isCompleteRecordString(const std::string& candidateRecordString) {
|
||||
unsigned int terminatingSlash = findTerminatingSlash(candidateRecordString);
|
||||
return (terminatingSlash < candidateRecordString.size());
|
||||
}
|
||||
|
||||
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(SLASH);
|
||||
unsigned int lastQuotePosition = singleRecordString.find_last_of(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(SLASH, lastQuotePosition);
|
||||
}
|
||||
return terminatingSlash;
|
||||
}
|
||||
|
||||
RawRecord::~RawRecord() {
|
||||
}
|
||||
|
||||
|
||||
}
|
38
opm/parser/eclipse/data/RawRecord.hpp
Normal file
38
opm/parser/eclipse/data/RawRecord.hpp
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* File: Record.hpp
|
||||
* Author: kflik
|
||||
*
|
||||
* Created on March 21, 2013, 10:44 AM
|
||||
*/
|
||||
|
||||
#ifndef RECORD_HPP
|
||||
#define RECORD_HPP
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace Opm {
|
||||
|
||||
class RawRecord {
|
||||
public:
|
||||
static const char SLASH;
|
||||
static const char QUOTE;
|
||||
RawRecord();
|
||||
RawRecord(const std::string& singleRecordString);
|
||||
void getRecordString(std::string& recordString);
|
||||
void getRecords(std::vector<std::string>& recordItems);
|
||||
static bool isCompleteRecordString(const std::string& candidateRecordString);
|
||||
virtual ~RawRecord();
|
||||
private:
|
||||
std::string m_sanitizedRecordString;
|
||||
std::vector<std::string> m_recordItems;
|
||||
void setRecordString(const std::string& singleRecordString);
|
||||
bool stringContains(std::string collection, char candidate);
|
||||
static unsigned int findTerminatingSlash(const std::string& singleRecordString);
|
||||
};
|
||||
typedef boost::shared_ptr<RawRecord> RawRecordPtr;
|
||||
}
|
||||
|
||||
#endif /* RECORD_HPP */
|
||||
|
@ -1,30 +0,0 @@
|
||||
/*
|
||||
Copyright 2013 Statoil ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Record.hpp"
|
||||
|
||||
Record::Record() {
|
||||
}
|
||||
|
||||
Record::Record(const std::string& slashTerminatedRecordStringl) {
|
||||
}
|
||||
|
||||
Record::~Record() {
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
/*
|
||||
* File: Record.hpp
|
||||
* Author: kflik
|
||||
*
|
||||
* Created on March 21, 2013, 10:44 AM
|
||||
*/
|
||||
|
||||
#ifndef RECORD_HPP
|
||||
#define RECORD_HPP
|
||||
|
||||
class Record {
|
||||
public:
|
||||
Record();
|
||||
Record(const Record& orig);
|
||||
virtual ~Record();
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif /* RECORD_HPP */
|
||||
|
3
testdata/mini.data
vendored
Normal file
3
testdata/mini.data
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
--Use saturation table end-point scaling
|
||||
ENDSCALE
|
||||
'NODIR' 'REVERS' 1 20 /
|
23
testdata/small.data
vendored
23
testdata/small.data
vendored
@ -1,18 +1,25 @@
|
||||
-- Dette er en supertest, 8 tegn kommer
|
||||
-- Dette er en supertest - OK
|
||||
HALLOENZ
|
||||
|
||||
-- Saa bare en
|
||||
A
|
||||
|
||||
-- Saa kommer en for lang en
|
||||
-- Saa bare en - OK
|
||||
INCLUDE
|
||||
'sti til fil/den er her' /
|
||||
-- Saa kommer en for lang en, skal bli "trunkert", slik at keywordet blir ABCXYZFF - OK
|
||||
|
||||
ABCXYZFFD
|
||||
|
||||
-- Og en med tall
|
||||
-- Og en med tall - IKKE OK
|
||||
|
||||
ABC5ADFC
|
||||
|
||||
|
||||
-- Og en med mellomrom etter
|
||||
-- Og en med mellomrom etter - OK
|
||||
|
||||
ABC5AD
|
||||
ABCDAD
|
||||
4.5 5 5 /
|
||||
3 3 fisk /
|
||||
/
|
||||
|
||||
-- Og en med liten bokstav i IKKE OK
|
||||
|
||||
ABCDAd
|
||||
|
@ -1,14 +1,12 @@
|
||||
# Add test executables
|
||||
add_executable(runParserTests ParserTests.cpp)
|
||||
add_executable(runKeywordRecordSetTests KeywordRecordSetTests.cpp)
|
||||
add_executable(runRawDataTests RawDataStructuresTests.cpp)
|
||||
add_executable(runParserKWTests ParserKWTests.cpp)
|
||||
|
||||
|
||||
target_link_libraries(runParserTests Parser Logger ${Boost_LIBRARIES})
|
||||
target_link_libraries(runKeywordRecordSetTests Parser Logger ${Boost_LIBRARIES})
|
||||
target_link_libraries(runRawDataTests Parser Logger ${Boost_LIBRARIES})
|
||||
target_link_libraries(runParserKWTests Parser Logger ${Boost_LIBRARIES})
|
||||
|
||||
|
||||
add_test(NAME runParserTests WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} COMMAND ${EXECUTABLE_OUTPUT_PATH}/runParserTests )
|
||||
add_test(NAME runKeywordRecordSetTests WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} COMMAND ${EXECUTABLE_OUTPUT_PATH}/runKeywordRecordSetTests )
|
||||
add_test(NAME runRawDataTests WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} COMMAND ${EXECUTABLE_OUTPUT_PATH}/runRawDataTests )
|
||||
add_test(NAME runParserKWTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runParserKWTests )
|
||||
|
@ -1,69 +0,0 @@
|
||||
/*
|
||||
Copyright 2013 Statoil ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define BOOST_TEST_MODULE ParserTests
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <opm/parser/eclipse/data/KeywordRecordSet.hpp>
|
||||
|
||||
BOOST_AUTO_TEST_CASE(EmptyConstructorEmptyKeyword) {
|
||||
Opm::KeywordRecordSet keyword;
|
||||
BOOST_CHECK(keyword.getKeyword() == "");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(KeywordToConstructorKeywordSet) {
|
||||
Opm::KeywordRecordSet keyword("KEYWORD");
|
||||
BOOST_CHECK(keyword.getKeyword() == "KEYWORD");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(KeywordAndRecordsToConstructorSetCorrectly) {
|
||||
Opm::KeywordRecordSet keyword("KEYWORD", std::list<std::string>());
|
||||
BOOST_CHECK(keyword.getKeyword() == "KEYWORD");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(SetTooLongKeywordNoError) {
|
||||
Opm::KeywordRecordSet keyword;
|
||||
keyword.setKeyword("TESTTOOLONG");
|
||||
BOOST_CHECK(keyword.getKeyword() == "TESTTOOLONG");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(SetCorrectLenghtKeywordNoError) {
|
||||
Opm::KeywordRecordSet keyword;
|
||||
keyword.setKeyword("GOODONE");
|
||||
BOOST_CHECK(keyword.getKeyword() == "GOODONE");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(SetKeywordWithTrailingWhitespaceKeywordNotTrimmed) {
|
||||
Opm::KeywordRecordSet keyword;
|
||||
keyword.setKeyword("GOODONE ");
|
||||
BOOST_CHECK(keyword.getKeyword() == "GOODONE ");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(AddDataRecordNoKeywordNoError) {
|
||||
Opm::KeywordRecordSet keyword;
|
||||
keyword.addDataElement("This is a record");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(AddDataRecordHasKeywordNoError) {
|
||||
Opm::KeywordRecordSet keyword;
|
||||
keyword.setKeyword("RECORD");
|
||||
keyword.addDataElement("This is a record");
|
||||
BOOST_CHECK(keyword.getKeyword() == "RECORD ");
|
||||
}
|
||||
|
||||
|
@ -27,58 +27,106 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include "opm/parser/eclipse/Parser.hpp"
|
||||
|
||||
#include "opm/parser/eclipse/data/RawDeck.hpp"
|
||||
using namespace Opm;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Initializing) {
|
||||
Parser parser;
|
||||
BOOST_CHECK(&parser != NULL);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParseWithoutInputFileThrows) {
|
||||
Parser parser;
|
||||
BOOST_REQUIRE_THROW(parser.parse(), std::invalid_argument);
|
||||
BOOST_REQUIRE_NO_THROW(Parser parser);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParseWithInvalidInputFileThrows) {
|
||||
Parser parser("nonexistingfile.asdf");
|
||||
BOOST_REQUIRE_THROW(parser.parse(), std::invalid_argument);
|
||||
ParserPtr parser(new Parser());
|
||||
BOOST_REQUIRE_THROW(parser -> parse("nonexistingfile.asdf"), std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParseWithValidFileSetOnParseCallNoThrow) {
|
||||
|
||||
boost::filesystem::path singleKeywordFile("testdata/small.data");
|
||||
Parser parser;
|
||||
BOOST_REQUIRE_NO_THROW(parser.parse(singleKeywordFile.string()));
|
||||
ParserPtr parser(new Parser());
|
||||
|
||||
BOOST_REQUIRE_NO_THROW(parser -> parse(singleKeywordFile.string()));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParseWithInValidFileSetOnParseCallThrows) {
|
||||
boost::filesystem::path singleKeywordFile("testdata/nosuchfile.data");
|
||||
Parser parser;
|
||||
BOOST_REQUIRE_THROW(parser.parse(singleKeywordFile.string()), std::invalid_argument);
|
||||
ParserPtr parser(new Parser());
|
||||
BOOST_REQUIRE_THROW(parser -> parse(singleKeywordFile.string()), std::invalid_argument);
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParseFileWithOneKeyword) {
|
||||
boost::filesystem::path singleKeywordFile("testdata/mini.data");
|
||||
|
||||
ParserPtr parser(new Parser());
|
||||
|
||||
RawDeckPtr rawDeck = parser -> parse(singleKeywordFile.string());
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 1, rawDeck -> getNumberOfKeywords());
|
||||
RawKeywordPtr rawKeyword = rawDeck->getKeyword("ENDSCALE");
|
||||
std::list<RawRecordPtr> records;
|
||||
rawKeyword -> getRecords(records);
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 1, records.size());
|
||||
RawRecordPtr record = records.back();
|
||||
|
||||
std::string recordString;
|
||||
record -> getRecordString(recordString);
|
||||
BOOST_REQUIRE_EQUAL("'NODIR' 'REVERS' 1 20", recordString);
|
||||
|
||||
std::vector<std::string> recordElements;
|
||||
record -> getRecords(recordElements);
|
||||
BOOST_REQUIRE_EQUAL((unsigned)4, recordElements.size());
|
||||
|
||||
BOOST_REQUIRE_EQUAL("NODIR", recordElements[0]);
|
||||
BOOST_REQUIRE_EQUAL("REVERS", recordElements[1]);
|
||||
BOOST_REQUIRE_EQUAL("1", recordElements[2]);
|
||||
BOOST_REQUIRE_EQUAL("20", recordElements[3]);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParseFileWithFewKeywords) {
|
||||
boost::filesystem::path singleKeywordFile("testdata/small.data");
|
||||
|
||||
Parser parser(singleKeywordFile.string());
|
||||
parser.parse();
|
||||
BOOST_REQUIRE_EQUAL(2, parser.getNumberOfKeywords());
|
||||
ParserPtr parser(new Parser());
|
||||
|
||||
RawDeckPtr rawDeck = parser -> parse(singleKeywordFile.string());
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 4, rawDeck -> getNumberOfKeywords());
|
||||
|
||||
RawKeywordPtr matchingKeyword = rawDeck -> getKeyword("INCLUDE");
|
||||
BOOST_REQUIRE_EQUAL("INCLUDE", matchingKeyword->getKeyword());
|
||||
|
||||
std::list<RawRecordPtr> records;
|
||||
matchingKeyword->getRecords(records);
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 1, records.size());
|
||||
|
||||
RawRecordPtr theRecord = records.front();
|
||||
std::string recordString;
|
||||
theRecord -> getRecordString(recordString);
|
||||
BOOST_REQUIRE_EQUAL("\'sti til fil/den er her\'", recordString);
|
||||
|
||||
RawKeywordPtr matchingKeyword2 = rawDeck -> getKeyword("ABCDAD");
|
||||
BOOST_REQUIRE_EQUAL("ABCDAD", matchingKeyword2->getKeyword());
|
||||
|
||||
std::list<RawRecordPtr> records2;
|
||||
matchingKeyword2->getRecords(records2);
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 2, records2.size());
|
||||
}
|
||||
|
||||
//NOTE: needs statoil dataset
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParseFileWithManyKeywords) {
|
||||
boost::filesystem::path multipleKeywordFile("testdata/gurbat_trimmed.DATA");
|
||||
|
||||
Parser parser(multipleKeywordFile.string());
|
||||
parser.parse();
|
||||
BOOST_REQUIRE_EQUAL(18, parser.getNumberOfKeywords());
|
||||
ParserPtr parser(new Parser());
|
||||
|
||||
RawDeckPtr rawDeck = parser -> parse(multipleKeywordFile.string());
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 18, rawDeck -> getNumberOfKeywords());
|
||||
}
|
||||
|
||||
//NOTE: needs statoil dataset
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParseFullTestFile) {
|
||||
boost::filesystem::path multipleKeywordFile("testdata/ECLIPSE.DATA");
|
||||
|
||||
Parser parser(multipleKeywordFile.string());
|
||||
parser.parse();
|
||||
BOOST_REQUIRE_EQUAL(73, parser.getNumberOfKeywords());
|
||||
ParserPtr parser(new Parser());
|
||||
|
||||
RawDeckPtr rawDeck = parser -> parse(multipleKeywordFile.string());
|
||||
BOOST_REQUIRE_EQUAL((unsigned) 73, rawDeck -> getNumberOfKeywords());
|
||||
}
|
||||
|
83
tests/RawDataStructuresTests.cpp
Normal file
83
tests/RawDataStructuresTests.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
/*
|
||||
Copyright 2013 Statoil ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define BOOST_TEST_MODULE ParserTests
|
||||
#include <stdexcept>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <opm/parser/eclipse/data/RawKeyword.hpp>
|
||||
#include <opm/parser/eclipse/data/RawRecord.hpp>
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(EmptyConstructorEmptyKeyword) {
|
||||
Opm::RawKeyword keyword;
|
||||
BOOST_CHECK(keyword.getKeyword() == "");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(KeywordToConstructorKeywordSet) {
|
||||
Opm::RawKeyword keyword("KEYYWORD");
|
||||
BOOST_CHECK(keyword.getKeyword() == "KEYYWORD");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(KeywordToConstructorTooLongThrows) {
|
||||
BOOST_CHECK_THROW(Opm::RawKeyword keyword("KEYYYWORD"), std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(SetTooLongKeywordThrows) {
|
||||
Opm::RawKeyword keyword;
|
||||
BOOST_CHECK_THROW(keyword.setKeyword("TESTTOOLONG"), std::invalid_argument);
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(SetKeywordInitialWhitespaceInKeywordThrows) {
|
||||
Opm::RawKeyword keyword;
|
||||
BOOST_CHECK_THROW(keyword.setKeyword(" TELONG"), std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(SetKeywordInitialTabInKeywordThrows) {
|
||||
Opm::RawKeyword keyword;
|
||||
BOOST_CHECK_THROW(keyword.setKeyword("\tTELONG"), std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(SetCorrectLenghtKeywordNoError) {
|
||||
Opm::RawKeyword keyword;
|
||||
keyword.setKeyword("GOODONE");
|
||||
BOOST_CHECK(keyword.getKeyword() == "GOODONE");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Set8CharKeywordWithTrailingWhitespaceKeywordTrimmed) {
|
||||
Opm::RawKeyword keyword;
|
||||
keyword.setKeyword("GOODONEE ");
|
||||
BOOST_CHECK(keyword.getKeyword() == "GOODONEE");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RawRecordSetRecordCheckCorrectTrimAndSplit) {
|
||||
Opm::RawRecordPtr record(new Opm::RawRecord(" 'NODIR ' 'REVERS' 1 20 /"));
|
||||
std::string recordString;
|
||||
record -> getRecordString(recordString);
|
||||
BOOST_REQUIRE_EQUAL("'NODIR ' 'REVERS' 1 20", recordString);
|
||||
|
||||
std::vector<std::string> recordElements;
|
||||
record -> getRecords(recordElements);
|
||||
BOOST_REQUIRE_EQUAL((unsigned)4, recordElements.size());
|
||||
|
||||
BOOST_REQUIRE_EQUAL("NODIR ", recordElements[0]);
|
||||
BOOST_REQUIRE_EQUAL("REVERS", recordElements[1]);
|
||||
BOOST_REQUIRE_EQUAL("1", recordElements[2]);
|
||||
BOOST_REQUIRE_EQUAL("20", recordElements[3]);
|
||||
}
|
Loading…
Reference in New Issue
Block a user