Added/implemented XStringItem for Parser and Deck, with tests. Added integration test for WWCT keyword. Moved DeckItem tests into type-specific files. Removed unused file.
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include <opm/parser/eclipse/Parser/ParserItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
||||
#include <opm/parser/eclipse/Deck/DeckIntItem.hpp>
|
||||
|
||||
|
||||
namespace Opm {
|
||||
@@ -29,34 +30,47 @@ namespace Opm {
|
||||
ParserIntItem::ParserIntItem(const std::string& itemName, ParserItemSizeEnum sizeType) : ParserItem(itemName, sizeType) {
|
||||
m_default = defaultInt();
|
||||
}
|
||||
|
||||
|
||||
|
||||
ParserIntItem::ParserIntItem(const std::string& itemName, ParserItemSizeEnum sizeType, int defaultValue) : ParserItem(itemName, sizeType) {
|
||||
m_default = defaultValue;
|
||||
}
|
||||
|
||||
|
||||
DeckItemConstPtr ParserIntItem::scan(size_t expectedItems, RawRecordPtr rawRecord) const {
|
||||
return scan__(expectedItems, false, rawRecord);
|
||||
}
|
||||
|
||||
DeckItemConstPtr ParserIntItem::scan(RawRecordPtr rawRecord) const {
|
||||
if (sizeType() == SINGLE)
|
||||
return scan(1U, rawRecord);
|
||||
else if (sizeType() == ALL)
|
||||
return scan__(0, true, rawRecord);
|
||||
else
|
||||
throw std::invalid_argument("Unsupported size type, only support SINGLE and ALL. Use scan( numTokens , rawRecord) instead ");
|
||||
}
|
||||
|
||||
/// Scans the rawRecords data according to the ParserItems definition.
|
||||
/// returns a DeckItem object.
|
||||
/// NOTE: data are popped from the rawRecords deque!
|
||||
DeckItemConstPtr ParserIntItem::scan__(size_t expectedItems , bool scanAll , RawRecordPtr rawRecord) const {
|
||||
if (sizeType() == SINGLE && expectedItems > 1)
|
||||
|
||||
DeckItemConstPtr ParserIntItem::scan__(size_t expectedItems, bool scanAll, RawRecordPtr rawRecord) const {
|
||||
if (sizeType() == SINGLE && expectedItems > 1) {
|
||||
throw std::invalid_argument("Can only ask for one item when sizeType == SINGLE");
|
||||
}
|
||||
|
||||
{
|
||||
DeckIntItemPtr deckItem(new DeckIntItem(name()));
|
||||
|
||||
if ((expectedItems > 0) || scanAll) {
|
||||
|
||||
if ((expectedItems > 0) || scanAll) {
|
||||
bool defaultActive;
|
||||
std::vector<int> intsPreparedForDeckItem = readFromRawRecord(rawRecord , scanAll , expectedItems , m_default , defaultActive);
|
||||
|
||||
std::vector<int> intsPreparedForDeckItem = readFromRawRecord(rawRecord, scanAll, expectedItems, m_default, defaultActive);
|
||||
|
||||
if (scanAll)
|
||||
deckItem->push_back(intsPreparedForDeckItem);
|
||||
else if (intsPreparedForDeckItem.size() >= expectedItems) {
|
||||
deckItem->push_back(intsPreparedForDeckItem , expectedItems);
|
||||
|
||||
if (intsPreparedForDeckItem.size() > expectedItems)
|
||||
pushBackToRecord(rawRecord , intsPreparedForDeckItem , expectedItems , defaultActive);
|
||||
deckItem->push_back(intsPreparedForDeckItem, expectedItems);
|
||||
|
||||
if (intsPreparedForDeckItem.size() > expectedItems)
|
||||
pushBackToRecord(rawRecord, intsPreparedForDeckItem, expectedItems, defaultActive);
|
||||
|
||||
} else {
|
||||
std::string preparedInts = boost::lexical_cast<std::string>(intsPreparedForDeckItem.size());
|
||||
@@ -65,25 +79,9 @@ namespace Opm {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return deckItem;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DeckItemConstPtr ParserIntItem::scan(size_t expectedItems, RawRecordPtr rawRecord) const {
|
||||
return scan__( expectedItems , false , rawRecord);
|
||||
}
|
||||
|
||||
|
||||
DeckItemConstPtr ParserIntItem::scan(RawRecordPtr rawRecord) const {
|
||||
if (sizeType() == SINGLE)
|
||||
return scan(1U , rawRecord);
|
||||
else if (sizeType() == ALL)
|
||||
return scan__(0 , true , rawRecord);
|
||||
else
|
||||
throw std::invalid_argument("Unsupported size type, only support SINGLE. Use scan( numTokens , rawRecord) instead ");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#include <opm/parser/eclipse/Parser/ParserItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Deck/DeckIntItem.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawRecord.hpp>
|
||||
|
||||
|
||||
|
||||
@@ -38,5 +38,8 @@ namespace Opm {
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string ParserItem::defaultString() {
|
||||
return "DEFAULT";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -44,13 +44,15 @@ namespace Opm {
|
||||
ParserItemSizeEnum sizeType() const;
|
||||
|
||||
static int defaultInt();
|
||||
static std::string defaultString();
|
||||
|
||||
|
||||
virtual ~ParserItem() {
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
#include "ParserItemTemplate.hpp"
|
||||
#include <opm/parser/eclipse/Parser/ParserItemTemplate.hpp>
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
@@ -63,41 +65,3 @@ namespace Opm {
|
||||
|
||||
#endif
|
||||
|
||||
// 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<T>& 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<T>& values) {
|
||||
// return scanItems(itemString, m_itemSize->sizeValue(), values);
|
||||
// }
|
||||
|
||||
|
||||
// };
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
*/
|
||||
|
||||
template<class T> void fillVectorFromStringToken(std::string token , std::vector<T>& dataVector, T defaultValue , bool& defaultActive) const {
|
||||
template<class T> void fillVectorFromStringToken(std::string token, std::vector<T>& dataVector, T defaultValue, bool& defaultActive) const {
|
||||
std::istringstream inputStream(token);
|
||||
size_t starPos = token.find('*');
|
||||
T value;
|
||||
@@ -27,13 +27,13 @@ template<class T> void fillVectorFromStringToken(std::string token , std::vector
|
||||
|
||||
if (hasStar) {
|
||||
bool singleDefault = (starPos == 0);
|
||||
|
||||
|
||||
if (singleDefault) {
|
||||
defaultActive = true;
|
||||
inputStream.get();
|
||||
if (token.size() > 1)
|
||||
throw std::invalid_argument("Token : " + token + " is invalid.");
|
||||
dataVector.push_back( defaultValue );
|
||||
dataVector.push_back(defaultValue);
|
||||
} else {
|
||||
size_t multiplier;
|
||||
int starChar;
|
||||
@@ -42,36 +42,34 @@ template<class T> void fillVectorFromStringToken(std::string token , std::vector
|
||||
starChar = inputStream.get();
|
||||
if (starChar != '*')
|
||||
throw std::invalid_argument("Error ...");
|
||||
|
||||
|
||||
defaultActive = (inputStream.peek() == std::char_traits<char>::eof());
|
||||
|
||||
|
||||
if (defaultActive)
|
||||
value = defaultValue;
|
||||
else
|
||||
inputStream >> value;
|
||||
|
||||
|
||||
for (size_t i = 0; i < multiplier; i++)
|
||||
dataVector.push_back( value );
|
||||
}
|
||||
dataVector.push_back(value);
|
||||
}
|
||||
} else {
|
||||
inputStream >> value;
|
||||
dataVector.push_back( value );
|
||||
}
|
||||
dataVector.push_back(value);
|
||||
}
|
||||
|
||||
inputStream.get();
|
||||
if (!inputStream.eof())
|
||||
throw std::invalid_argument("Spurious data at the end of: <" + token + ">");
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class T> std::vector<T> readFromRawRecord(RawRecordPtr rawRecord , bool scanAll , size_t expectedItems , T defaultValue , bool& defaultActive) const {
|
||||
template<class T> std::vector<T> readFromRawRecord(RawRecordPtr rawRecord, bool scanAll, size_t expectedItems, T defaultValue, bool& defaultActive) const {
|
||||
bool cont = true;
|
||||
std::vector<T> data;
|
||||
do {
|
||||
std::string token = rawRecord->pop_front();
|
||||
fillVectorFromStringToken(token, data , defaultValue , defaultActive);
|
||||
|
||||
fillVectorFromStringToken(token, data, defaultValue, defaultActive);
|
||||
|
||||
if (rawRecord->size() == 0)
|
||||
cont = false;
|
||||
else {
|
||||
@@ -82,20 +80,19 @@ template<class T> std::vector<T> readFromRawRecord(RawRecordPtr rawRecord , bool
|
||||
} while (cont);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
template <class T> void pushBackToRecord( RawRecordPtr rawRecord , std::vector<T>& data , size_t expectedItems , bool defaultActive) const {
|
||||
template <class T> void pushBackToRecord(RawRecordPtr rawRecord, std::vector<T>& data, size_t expectedItems, bool defaultActive) const {
|
||||
size_t extraItems = data.size() - expectedItems;
|
||||
|
||||
for (size_t i=1; i <= extraItems; i++) {
|
||||
if (defaultActive)
|
||||
|
||||
for (size_t i = 1; i <= extraItems; i++) {
|
||||
if (defaultActive)
|
||||
rawRecord->push_front("*");
|
||||
else {
|
||||
size_t offset = data.size();
|
||||
int intValue = data[ offset - i ];
|
||||
std::string stringValue = boost::lexical_cast<std::string>( intValue );
|
||||
|
||||
rawRecord->push_front( stringValue );
|
||||
T intValue = data[ offset - i ];
|
||||
std::string stringValue = boost::lexical_cast<std::string>(intValue);
|
||||
|
||||
rawRecord->push_front(stringValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,63 @@
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ParserStringItem.hpp"
|
||||
#include <opm/parser/eclipse/Parser/ParserStringItem.hpp>
|
||||
#include <opm/parser/eclipse/Deck/DeckStringItem.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
|
||||
ParserStringItem::ParserStringItem(const std::string& itemName, ParserItemSizeEnum sizeType) : ParserItem(itemName, sizeType) {
|
||||
m_default = defaultString();
|
||||
}
|
||||
|
||||
ParserStringItem::ParserStringItem(const std::string& itemName, ParserItemSizeEnum sizeType, std::string defaultValue) : ParserItem(itemName, sizeType) {
|
||||
m_default = defaultValue;
|
||||
}
|
||||
|
||||
|
||||
DeckItemConstPtr ParserStringItem::scan(size_t expectedItems, RawRecordPtr rawRecord) const {
|
||||
return scan__(expectedItems, false, rawRecord);
|
||||
}
|
||||
|
||||
DeckItemConstPtr ParserStringItem::scan(RawRecordPtr rawRecord) const {
|
||||
if (sizeType() == SINGLE) {
|
||||
return scan(1U, rawRecord);
|
||||
} else if (sizeType() == ALL) {
|
||||
return scan__(0, true, rawRecord);
|
||||
} else
|
||||
throw std::invalid_argument("Unsupported size type, only support SINGLE and ALL. Use scan( numTokens , rawRecord) instead ");
|
||||
}
|
||||
|
||||
/// Scans the rawRecords data according to the ParserItems definition.
|
||||
/// returns a DeckItem object.
|
||||
/// NOTE: data are popped from the rawRecords deque!
|
||||
|
||||
DeckItemConstPtr ParserStringItem::scan__(size_t expectedItems, bool scanAll, RawRecordPtr rawRecord) const {
|
||||
if (sizeType() == SINGLE && expectedItems > 1) {
|
||||
throw std::invalid_argument("Can only ask for one item when sizeType == SINGLE");
|
||||
}
|
||||
|
||||
{
|
||||
DeckStringItemPtr deckItem(new DeckStringItem(name()));
|
||||
|
||||
if ((expectedItems > 0) || scanAll) {
|
||||
bool defaultActive;
|
||||
std::vector<std::string> stringsPreparedForDeckItem = readFromRawRecord(rawRecord, scanAll, expectedItems, m_default, defaultActive);
|
||||
if (scanAll)
|
||||
deckItem->push_back(stringsPreparedForDeckItem);
|
||||
else if (stringsPreparedForDeckItem.size() >= expectedItems) {
|
||||
deckItem->push_back(stringsPreparedForDeckItem, expectedItems);
|
||||
|
||||
if (stringsPreparedForDeckItem.size() > expectedItems)
|
||||
pushBackToRecord(rawRecord, stringsPreparedForDeckItem, expectedItems, defaultActive);
|
||||
} else {
|
||||
std::string preparedStrings = boost::lexical_cast<std::string>(stringsPreparedForDeckItem.size());
|
||||
std::string parserSizeValue = boost::lexical_cast<std::string>(expectedItems);
|
||||
throw std::invalid_argument("The number of parsed strings (" + preparedStrings + ") did not correspond to the expected number of items:(" + parserSizeValue + ")");
|
||||
}
|
||||
}
|
||||
|
||||
return deckItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,11 +28,23 @@ namespace Opm {
|
||||
|
||||
class ParserStringItem : public ParserItem {
|
||||
public:
|
||||
ParserStringItem(const std::string& itemName, ParserItemSizeEnum sizeType) : ParserItem(itemName, sizeType) {};
|
||||
ParserStringItem(const std::string& itemName, ParserItemSizeEnum sizeType);
|
||||
ParserStringItem(const std::string& itemName, ParserItemSizeEnum sizeType, std::string defaultValue);
|
||||
|
||||
DeckItemConstPtr scan(size_t expectedItems, RawRecordPtr rawRecord) const;
|
||||
DeckItemConstPtr scan(RawRecordPtr rawRecord) const;
|
||||
|
||||
std::string getDefault() const {
|
||||
return m_default;
|
||||
}
|
||||
|
||||
private:
|
||||
DeckItemConstPtr scan__(size_t expectedItems, bool readAll, RawRecordPtr rawRecord) const;
|
||||
std::string m_default;
|
||||
};
|
||||
|
||||
};
|
||||
typedef boost::shared_ptr<const ParserStringItem> ParserStringItemConstPtr;
|
||||
typedef boost::shared_ptr<ParserStringItem> ParserStringItemPtr;
|
||||
}
|
||||
|
||||
#endif /* PARSERSTRINGITEM_HPP */
|
||||
|
||||
@@ -1,70 +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/Parser/ParserItemSize.hpp"
|
||||
#include "opm/parser/eclipse/Parser/ParserEnums.hpp"
|
||||
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Initialize) {
|
||||
BOOST_REQUIRE_NO_THROW(ParserItemSize itemSize);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Default) {
|
||||
ParserItemSize itemSize;
|
||||
BOOST_REQUIRE_EQUAL(itemSize.sizeType(), UNSPECIFIED);
|
||||
BOOST_REQUIRE_THROW(itemSize.sizeValue(), std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Fixed) {
|
||||
ParserItemSize itemSize(100);
|
||||
BOOST_REQUIRE_EQUAL(itemSize.sizeType(), ITEM_FIXED);
|
||||
BOOST_REQUIRE_EQUAL(itemSize.sizeValue(), 100U);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Fixed2) {
|
||||
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) {
|
||||
ParserItemSize itemSize(ITEM_BOX);
|
||||
BOOST_REQUIRE_EQUAL(itemSize.sizeType(), ITEM_BOX);
|
||||
BOOST_REQUIRE_THROW(itemSize.sizeValue(), std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Boost) {
|
||||
ParserItemSizeConstPtr itemSize(new ParserItemSize(ITEM_BOX));
|
||||
BOOST_REQUIRE_EQUAL(itemSize->sizeType(), ITEM_BOX);
|
||||
BOOST_REQUIRE_THROW(itemSize->sizeValue(), std::invalid_argument);
|
||||
}
|
||||
@@ -37,22 +37,19 @@ using namespace Opm;
|
||||
BOOST_AUTO_TEST_CASE(Initialize) {
|
||||
ParserItemSizeEnum sizeType = SINGLE;
|
||||
BOOST_CHECK_NO_THROW(ParserIntItem item1("ITEM1", sizeType));
|
||||
// BOOST_CHECK_NO_THROW(ParserStringItem item1("ITEM1", sizeType));
|
||||
// BOOST_CHECK_NO_THROW(ParserBoolItem item1("ITEM1", sizeType));
|
||||
// BOOST_CHECK_NO_THROW(ParserDoubleItem item1("ITEM1", sizeType));
|
||||
BOOST_CHECK_NO_THROW(ParserStringItem item1("ITEM1", sizeType));
|
||||
// BOOST_CHECK_NO_THROW(ParserBoolItem item1("ITEM1", sizeType));
|
||||
// BOOST_CHECK_NO_THROW(ParserDoubleItem item1("ITEM1", sizeType));
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Initialize_Default) {
|
||||
ParserItemSizeEnum sizeType = SINGLE;
|
||||
ParserIntItem item1("ITEM1", sizeType);
|
||||
ParserIntItem item2("ITEM1", sizeType , 88);
|
||||
BOOST_CHECK_EQUAL( item1.getDefault() , ParserItem::defaultInt() );
|
||||
BOOST_CHECK_EQUAL( item2.getDefault() , 88 );
|
||||
ParserIntItem item2("ITEM1", sizeType, 88);
|
||||
BOOST_CHECK_EQUAL(item1.getDefault(), ParserItem::defaultInt());
|
||||
BOOST_CHECK_EQUAL(item2.getDefault(), 88);
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Name_ReturnsCorrectName) {
|
||||
ParserItemSizeEnum sizeType = ALL;
|
||||
|
||||
@@ -63,14 +60,12 @@ BOOST_AUTO_TEST_CASE(Name_ReturnsCorrectName) {
|
||||
BOOST_CHECK_EQUAL("", item2.name());
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Size_ReturnsCorrectSizeType) {
|
||||
ParserItemSizeEnum sizeType = ITEM_BOX;
|
||||
ParserIntItem item1("ITEM1", sizeType);
|
||||
BOOST_CHECK_EQUAL(sizeType, item1.sizeType());
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_WrongSizeType_ExceptionThrown) {
|
||||
ParserItemSizeEnum sizeType = ITEM_BOX;
|
||||
ParserIntItem itemInt("ITEM2", sizeType);
|
||||
@@ -79,39 +74,34 @@ BOOST_AUTO_TEST_CASE(Scan_WrongSizeType_ExceptionThrown) {
|
||||
BOOST_CHECK_THROW(itemInt.scan(rawRecord), std::invalid_argument);
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_All_CorrectIntSetInDeckItem) {
|
||||
ParserItemSizeEnum sizeType = ALL;
|
||||
ParserIntItem itemInt("ITEM", sizeType);
|
||||
|
||||
RawRecordPtr rawRecord(new RawRecord("100 443 10* 10*1 25/"));
|
||||
DeckItemConstPtr deckIntItem = itemInt.scan(rawRecord);
|
||||
BOOST_CHECK_EQUAL(23U , deckIntItem->size());
|
||||
BOOST_CHECK_EQUAL(23U, deckIntItem->size());
|
||||
BOOST_CHECK_EQUAL(1, deckIntItem->getInt(21));
|
||||
BOOST_CHECK_EQUAL(25, deckIntItem->getInt(22));
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_ScalarMultipleItems_ExceptionThrown) {
|
||||
ParserItemSizeEnum sizeType = SINGLE;
|
||||
ParserIntItem itemInt("ITEM2", sizeType);
|
||||
|
||||
RawRecordPtr rawRecord(new RawRecord("100 443 /"));
|
||||
BOOST_CHECK_THROW( itemInt.scan(2 , rawRecord), std::invalid_argument);
|
||||
BOOST_CHECK_THROW(itemInt.scan(2, rawRecord), std::invalid_argument);
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_NoData_OK) {
|
||||
ParserItemSizeEnum sizeType = ALL;
|
||||
ParserIntItem itemInt("ITEM2", sizeType);
|
||||
|
||||
RawRecordPtr rawRecord(new RawRecord("100 443 /"));
|
||||
DeckItemConstPtr deckIntItem = itemInt.scan(0 , rawRecord);
|
||||
BOOST_CHECK_EQUAL( 0U , deckIntItem->size());
|
||||
DeckItemConstPtr deckIntItem = itemInt.scan(0, rawRecord);
|
||||
BOOST_CHECK_EQUAL(0U, deckIntItem->size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_SINGLE_CorrectIntSetInDeckItem) {
|
||||
ParserItemSizeEnum sizeType = SINGLE;
|
||||
ParserIntItem itemInt("ITEM2", sizeType);
|
||||
@@ -121,260 +111,282 @@ BOOST_AUTO_TEST_CASE(Scan_SINGLE_CorrectIntSetInDeckItem) {
|
||||
BOOST_CHECK_EQUAL(100, deckIntItem->getInt(0));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_SeveralInts_CorrectIntsSetInDeckItem) {
|
||||
ParserItemSizeEnum sizeType = ITEM_BOX;
|
||||
ParserIntItem itemInt("ITEM2", sizeType);
|
||||
|
||||
RawRecordPtr rawRecord(new RawRecord("100 443 338932 222.33 'Heisann' /"));
|
||||
DeckItemConstPtr deckIntItem = itemInt.scan(3 , rawRecord);
|
||||
DeckItemConstPtr deckIntItem = itemInt.scan(3, rawRecord);
|
||||
BOOST_CHECK_EQUAL(100, deckIntItem->getInt(0));
|
||||
BOOST_CHECK_EQUAL(443, deckIntItem->getInt(1));
|
||||
BOOST_CHECK_EQUAL(338932, deckIntItem->getInt(2));
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_Default_CorrectIntsSetInDeckItem) {
|
||||
ParserItemSizeEnum sizeType = ITEM_BOX;
|
||||
int defaultValue = 199;
|
||||
ParserIntItem itemInt("ITEM2", sizeType , defaultValue);
|
||||
ParserIntItem itemInt("ITEM2", sizeType, defaultValue);
|
||||
|
||||
RawRecordPtr rawRecord1(new RawRecord("* /"));
|
||||
DeckItemConstPtr deckIntItem = itemInt.scan(1 , rawRecord1);
|
||||
BOOST_CHECK_EQUAL( 1U , deckIntItem->size());
|
||||
BOOST_CHECK_EQUAL( defaultValue , deckIntItem->getInt(0));
|
||||
DeckItemConstPtr deckIntItem = itemInt.scan(1, rawRecord1);
|
||||
BOOST_CHECK_EQUAL(1U, deckIntItem->size());
|
||||
BOOST_CHECK_EQUAL(defaultValue, deckIntItem->getInt(0));
|
||||
|
||||
|
||||
RawRecordPtr rawRecord2(new RawRecord("20* /"));
|
||||
deckIntItem = itemInt.scan(20 , rawRecord2);
|
||||
BOOST_CHECK_EQUAL(defaultValue , deckIntItem->getInt(0));
|
||||
BOOST_CHECK_EQUAL(20U , deckIntItem->size());
|
||||
BOOST_CHECK_EQUAL(defaultValue , deckIntItem->getInt(19));
|
||||
BOOST_CHECK_EQUAL(defaultValue , deckIntItem->getInt(9));
|
||||
deckIntItem = itemInt.scan(20, rawRecord2);
|
||||
BOOST_CHECK_EQUAL(defaultValue, deckIntItem->getInt(0));
|
||||
BOOST_CHECK_EQUAL(20U, deckIntItem->size());
|
||||
BOOST_CHECK_EQUAL(defaultValue, deckIntItem->getInt(19));
|
||||
BOOST_CHECK_EQUAL(defaultValue, deckIntItem->getInt(9));
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_Multiplier_CorrectIntsSetInDeckItem) {
|
||||
ParserItemSizeEnum sizeType = ITEM_BOX;
|
||||
ParserIntItem itemInt("ITEM2", sizeType);
|
||||
|
||||
RawRecordPtr rawRecord(new RawRecord("3*4 /"));
|
||||
DeckItemConstPtr deckIntItem = itemInt.scan(3 , rawRecord);
|
||||
BOOST_CHECK_EQUAL(4 , deckIntItem->getInt(0));
|
||||
BOOST_CHECK_EQUAL(4 , deckIntItem->getInt(1));
|
||||
BOOST_CHECK_EQUAL(4 , deckIntItem->getInt(2));
|
||||
DeckItemConstPtr deckIntItem = itemInt.scan(3, rawRecord);
|
||||
BOOST_CHECK_EQUAL(4, deckIntItem->getInt(0));
|
||||
BOOST_CHECK_EQUAL(4, deckIntItem->getInt(1));
|
||||
BOOST_CHECK_EQUAL(4, deckIntItem->getInt(2));
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_StarNoMultiplier_ExceptionThrown) {
|
||||
ParserItemSizeEnum sizeType = ITEM_BOX;
|
||||
ParserIntItem itemInt("ITEM2", sizeType);
|
||||
|
||||
RawRecordPtr rawRecord(new RawRecord("*45 /"));
|
||||
BOOST_CHECK_THROW(itemInt.scan(1 , rawRecord), std::invalid_argument);
|
||||
}
|
||||
|
||||
RawRecordPtr rawRecord(new RawRecord("*45 /"));
|
||||
BOOST_CHECK_THROW(itemInt.scan(1, rawRecord), std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_MultipleItems_CorrectIntsSetInDeckItem) {
|
||||
ParserItemSizeEnum sizeType = ITEM_BOX;
|
||||
ParserIntItem itemInt1("ITEM1", sizeType);
|
||||
ParserIntItem itemInt2("ITEM2", sizeType);
|
||||
|
||||
|
||||
RawRecordPtr rawRecord(new RawRecord("10 20 /"));
|
||||
DeckItemConstPtr deckIntItem1 = itemInt1.scan(1 , rawRecord);
|
||||
DeckItemConstPtr deckIntItem2 = itemInt2.scan(1 , rawRecord);
|
||||
DeckItemConstPtr deckIntItem1 = itemInt1.scan(1, rawRecord);
|
||||
DeckItemConstPtr deckIntItem2 = itemInt2.scan(1, rawRecord);
|
||||
|
||||
BOOST_CHECK_EQUAL( 10 , deckIntItem1->getInt(0));
|
||||
BOOST_CHECK_EQUAL( 20 , deckIntItem2->getInt(0));
|
||||
BOOST_CHECK_EQUAL(10, deckIntItem1->getInt(0));
|
||||
BOOST_CHECK_EQUAL(20, deckIntItem2->getInt(0));
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_MultipleDefault_CorrectIntsSetInDeckItem) {
|
||||
ParserItemSizeEnum sizeType = ITEM_BOX;
|
||||
ParserIntItem itemInt1("ITEM1", sizeType , 10);
|
||||
ParserIntItem itemInt2("ITEM2", sizeType , 20);
|
||||
|
||||
ParserIntItem itemInt1("ITEM1", sizeType, 10);
|
||||
ParserIntItem itemInt2("ITEM2", sizeType, 20);
|
||||
|
||||
RawRecordPtr rawRecord(new RawRecord("* * /"));
|
||||
DeckItemConstPtr deckIntItem1 = itemInt1.scan(1 , rawRecord);
|
||||
DeckItemConstPtr deckIntItem2 = itemInt2.scan(1 , rawRecord);
|
||||
DeckItemConstPtr deckIntItem1 = itemInt1.scan(1, rawRecord);
|
||||
DeckItemConstPtr deckIntItem2 = itemInt2.scan(1, rawRecord);
|
||||
|
||||
BOOST_CHECK_EQUAL( 10 , deckIntItem1->getInt(0));
|
||||
BOOST_CHECK_EQUAL( 20 , deckIntItem2->getInt(0));
|
||||
BOOST_CHECK_EQUAL(10, deckIntItem1->getInt(0));
|
||||
BOOST_CHECK_EQUAL(20, deckIntItem2->getInt(0));
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_MultipleWithMultiplier_CorrectIntsSetInDeckItem) {
|
||||
ParserItemSizeEnum sizeType = ITEM_BOX;
|
||||
ParserIntItem itemInt1("ITEM1", sizeType , 10);
|
||||
ParserIntItem itemInt2("ITEM2", sizeType , 20);
|
||||
|
||||
ParserIntItem itemInt1("ITEM1", sizeType, 10);
|
||||
ParserIntItem itemInt2("ITEM2", sizeType, 20);
|
||||
|
||||
RawRecordPtr rawRecord(new RawRecord("2*30/"));
|
||||
DeckItemConstPtr deckIntItem1 = itemInt1.scan(1 , rawRecord);
|
||||
DeckItemConstPtr deckIntItem2 = itemInt2.scan(1 , rawRecord);
|
||||
DeckItemConstPtr deckIntItem1 = itemInt1.scan(1, rawRecord);
|
||||
DeckItemConstPtr deckIntItem2 = itemInt2.scan(1, rawRecord);
|
||||
|
||||
BOOST_CHECK_EQUAL( 30 , deckIntItem1->getInt(0));
|
||||
BOOST_CHECK_EQUAL( 30 , deckIntItem2->getInt(0));
|
||||
BOOST_CHECK_EQUAL(30, deckIntItem1->getInt(0));
|
||||
BOOST_CHECK_EQUAL(30, deckIntItem2->getInt(0));
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_MalformedMultiplier_Throw) {
|
||||
ParserItemSizeEnum sizeType = ITEM_BOX;
|
||||
ParserIntItem itemInt1("ITEM1", sizeType , 10);
|
||||
|
||||
RawRecordPtr rawRecord(new RawRecord("2.10*30/"));
|
||||
BOOST_CHECK_THROW(itemInt1.scan(1 , rawRecord) , std::invalid_argument);
|
||||
}
|
||||
ParserIntItem itemInt1("ITEM1", sizeType, 10);
|
||||
|
||||
RawRecordPtr rawRecord(new RawRecord("2.10*30/"));
|
||||
BOOST_CHECK_THROW(itemInt1.scan(1, rawRecord), std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_MalformedMultiplierChar_Throw) {
|
||||
ParserItemSizeEnum sizeType = ITEM_BOX;
|
||||
ParserIntItem itemInt1("ITEM1", sizeType , 10);
|
||||
|
||||
ParserIntItem itemInt1("ITEM1", sizeType, 10);
|
||||
|
||||
RawRecordPtr rawRecord(new RawRecord("210X30/"));
|
||||
BOOST_CHECK_THROW(itemInt1.scan(1 , rawRecord) , std::invalid_argument);
|
||||
BOOST_CHECK_THROW(itemInt1.scan(1, rawRecord), std::invalid_argument);
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_MultipleWithMultiplierDefault_CorrectIntsSetInDeckItem) {
|
||||
ParserItemSizeEnum sizeType = ITEM_BOX;
|
||||
ParserIntItem itemInt1("ITEM1", sizeType , 10);
|
||||
ParserIntItem itemInt2("ITEM2", sizeType , 20);
|
||||
|
||||
ParserIntItem itemInt1("ITEM1", sizeType, 10);
|
||||
ParserIntItem itemInt2("ITEM2", sizeType, 20);
|
||||
|
||||
RawRecordPtr rawRecord(new RawRecord("2*/"));
|
||||
DeckItemConstPtr deckIntItem1 = itemInt1.scan(1 , rawRecord);
|
||||
DeckItemConstPtr deckIntItem2 = itemInt2.scan(1 , rawRecord);
|
||||
DeckItemConstPtr deckIntItem1 = itemInt1.scan(1, rawRecord);
|
||||
DeckItemConstPtr deckIntItem2 = itemInt2.scan(1, rawRecord);
|
||||
|
||||
BOOST_CHECK_EQUAL( 10 , deckIntItem1->getInt(0));
|
||||
BOOST_CHECK_EQUAL( 20 , deckIntItem2->getInt(0));
|
||||
BOOST_CHECK_EQUAL(10, deckIntItem1->getInt(0));
|
||||
BOOST_CHECK_EQUAL(20, deckIntItem2->getInt(0));
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_MultipleWithMultiplierDefault2_CorrectIntsSetInDeckItem) {
|
||||
ParserItemSizeEnum sizeType = ITEM_BOX;
|
||||
ParserIntItem itemInt1("ITEM1", sizeType , 10);
|
||||
ParserIntItem itemInt2("ITEM2", sizeType , 20);
|
||||
|
||||
RawRecordPtr rawRecord(new RawRecord("15* 5*77/")); // * * * * * * * * * * ^ * * * * * 77 77 77 77 77
|
||||
DeckItemConstPtr deckIntItem1 = itemInt1.scan(10 , rawRecord);
|
||||
DeckItemConstPtr deckIntItem2 = itemInt2.scan(10 , rawRecord);
|
||||
ParserIntItem itemInt1("ITEM1", sizeType, 10);
|
||||
ParserIntItem itemInt2("ITEM2", sizeType, 20);
|
||||
|
||||
BOOST_CHECK_EQUAL( 10 , deckIntItem1->getInt(0));
|
||||
BOOST_CHECK_EQUAL( 10 , deckIntItem1->getInt(9));
|
||||
|
||||
BOOST_CHECK_EQUAL( 20 , deckIntItem2->getInt(0));
|
||||
BOOST_CHECK_EQUAL( 77 , deckIntItem2->getInt(9));
|
||||
RawRecordPtr rawRecord(new RawRecord("15* 5*77/")); // * * * * * * * * * * ^ * * * * * 77 77 77 77 77
|
||||
DeckItemConstPtr deckIntItem1 = itemInt1.scan(10, rawRecord);
|
||||
DeckItemConstPtr deckIntItem2 = itemInt2.scan(10, rawRecord);
|
||||
|
||||
BOOST_CHECK_EQUAL(10, deckIntItem1->getInt(0));
|
||||
BOOST_CHECK_EQUAL(10, deckIntItem1->getInt(9));
|
||||
|
||||
BOOST_CHECK_EQUAL(20, deckIntItem2->getInt(0));
|
||||
BOOST_CHECK_EQUAL(77, deckIntItem2->getInt(9));
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_RawRecordErrorInRawData_ExceptionThrown) {
|
||||
ParserItemSizeEnum sizeType = ITEM_BOX;
|
||||
ParserIntItem itemInt("ITEM2", sizeType);
|
||||
|
||||
// Too few elements
|
||||
RawRecordPtr rawRecord1(new RawRecord("100 443 /"));
|
||||
BOOST_CHECK_THROW(itemInt.scan(3 , rawRecord1), std::invalid_argument);
|
||||
BOOST_CHECK_THROW(itemInt.scan(3, rawRecord1), std::invalid_argument);
|
||||
|
||||
// Wrong type
|
||||
RawRecordPtr rawRecord2(new RawRecord("100 443 333.2 /"));
|
||||
BOOST_CHECK_THROW(itemInt.scan(3 , rawRecord2), std::invalid_argument);
|
||||
BOOST_CHECK_THROW(itemInt.scan(3, rawRecord2), std::invalid_argument);
|
||||
|
||||
// Wrong type
|
||||
RawRecordPtr rawRecord3(new RawRecord("100X 443 3332 /"));
|
||||
BOOST_CHECK_THROW(itemInt.scan(3 , rawRecord3), std::invalid_argument);
|
||||
BOOST_CHECK_THROW(itemInt.scan(3, rawRecord3), std::invalid_argument);
|
||||
|
||||
// Wrong type
|
||||
RawRecordPtr rawRecord4(new RawRecord("100U 443 3332 /"));
|
||||
BOOST_CHECK_THROW(itemInt.scan(3 , rawRecord4), std::invalid_argument);
|
||||
BOOST_CHECK_THROW(itemInt.scan(3, rawRecord4), std::invalid_argument);
|
||||
|
||||
// Wrong type
|
||||
RawRecordPtr rawRecord5(new RawRecord("galneslig 443 3332 /"));
|
||||
BOOST_CHECK_THROW(itemInt.scan(3 , rawRecord5), std::invalid_argument);
|
||||
BOOST_CHECK_THROW(itemInt.scan(3, rawRecord5), std::invalid_argument);
|
||||
|
||||
// Too few elements
|
||||
RawRecordPtr rawRecord6(new RawRecord("2*2 2*1 /"));
|
||||
BOOST_CHECK_THROW(itemInt.scan(5 , rawRecord6), std::invalid_argument);
|
||||
BOOST_CHECK_THROW(itemInt.scan(5, rawRecord6), std::invalid_argument);
|
||||
|
||||
// Too few elements
|
||||
RawRecordPtr rawRecord7(new RawRecord("2* /"));
|
||||
BOOST_CHECK_THROW(itemInt.scan(3 , rawRecord7), std::invalid_argument);
|
||||
BOOST_CHECK_THROW(itemInt.scan(3, rawRecord7), std::invalid_argument);
|
||||
|
||||
// Too few elements
|
||||
RawRecordPtr rawRecord8(new RawRecord("* /"));
|
||||
BOOST_CHECK_THROW(itemInt.scan(3 , rawRecord8), std::invalid_argument);
|
||||
BOOST_CHECK_THROW(itemInt.scan(3, rawRecord8), std::invalid_argument);
|
||||
}
|
||||
|
||||
/*********************String************************'*/
|
||||
BOOST_AUTO_TEST_CASE(scan_boxWithoutExpected_ExceptionThrown) {
|
||||
ParserItemSizeEnum sizeType = ITEM_BOX;
|
||||
ParserStringItem itemString("ITEM1", sizeType);
|
||||
RawRecordPtr rawRecord(new RawRecord("'WELL1' 'WELL2' /"));
|
||||
BOOST_CHECK_THROW(itemString.scan(rawRecord), std::invalid_argument);
|
||||
}
|
||||
|
||||
// Husk kombocase, dvs en record med alt morro i 333 * 2*23 2* 'HEI' 4*'NEIDA' /
|
||||
BOOST_AUTO_TEST_CASE(scan_singleWithMoreThenOneExpected_ExceptionThrown) {
|
||||
ParserItemSizeEnum sizeType = SINGLE;
|
||||
ParserStringItem itemString("ITEM1", sizeType);
|
||||
RawRecordPtr rawRecord(new RawRecord("'WELL1' 'WELL2' /"));
|
||||
BOOST_CHECK_THROW(itemString.scan(2, rawRecord), std::invalid_argument);
|
||||
}
|
||||
|
||||
//BOOST_AUTO_TEST_CASE(TestScanDouble) {
|
||||
// ParserItemSizeConstPtr itemSize(new ParserItemSize(10));
|
||||
// ParserDoubleItem 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);
|
||||
//
|
||||
// BOOST_REQUIRE(!itemDouble.scanItem("", value));
|
||||
// BOOST_REQUIRE_EQUAL(value, 100.25);
|
||||
//}
|
||||
//
|
||||
//BOOST_AUTO_TEST_CASE(TestScanString) {
|
||||
// ParserItemSizeConstPtr itemSize(new ParserItemSize(10));
|
||||
// ParserStringItem 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) {
|
||||
// ParserItemSizeConstPtr itemSize(new ParserItemSize(10));
|
||||
// ParserBoolItem itemString("ITEM2", itemSize);
|
||||
// bool value = true;
|
||||
//
|
||||
// BOOST_REQUIRE(itemString.scanItem("1", value));
|
||||
// BOOST_REQUIRE_EQUAL(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("10", value));
|
||||
// BOOST_REQUIRE_EQUAL(value, false);
|
||||
//}
|
||||
//
|
||||
///*****************************************************************/
|
||||
//
|
||||
//
|
||||
//BOOST_AUTO_TEST_CASE(TestScanItemsFail) {
|
||||
// ParserItemSizeConstPtr itemSize(new ParserItemSize(ITEM_BOX));
|
||||
// ParserIntItem itemInt("ITEM2", itemSize);
|
||||
// std::vector<int> values;
|
||||
//
|
||||
// BOOST_REQUIRE_THROW(itemInt.scanItems("100 100 100", values), std::invalid_argument);
|
||||
//}
|
||||
//
|
||||
//BOOST_AUTO_TEST_CASE(TestScanItemsInt) {
|
||||
// ParserItemSizeConstPtr itemSize(new ParserItemSize(4));
|
||||
// ParserIntItem itemInt("ITEM2", itemSize);
|
||||
// std::vector<int> 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_AUTO_TEST_CASE(init_defaultvalue_defaultset) {
|
||||
ParserItemSizeEnum sizeType = SINGLE;
|
||||
ParserStringItem itemString("ITEM1", sizeType);
|
||||
RawRecordPtr rawRecord(new RawRecord(("'1*'/")));
|
||||
DeckItemConstPtr deckItem = itemString.scan(rawRecord);
|
||||
BOOST_CHECK_EQUAL(itemString.defaultString(), deckItem->getString(0));
|
||||
|
||||
rawRecord.reset(new RawRecord("13*/"));
|
||||
deckItem = itemString.scan(rawRecord);
|
||||
BOOST_CHECK_EQUAL(itemString.defaultString(), deckItem->getString(0));
|
||||
|
||||
rawRecord.reset(new RawRecord(("*/")));
|
||||
deckItem = itemString.scan(rawRecord);
|
||||
BOOST_CHECK_EQUAL(itemString.defaultString(), deckItem->getString(0));
|
||||
|
||||
ParserStringItem itemStringDefaultChanged("ITEM2", sizeType, "SPECIAL");
|
||||
rawRecord.reset(new RawRecord(("*/")));
|
||||
deckItem = itemStringDefaultChanged.scan(rawRecord);
|
||||
BOOST_CHECK_EQUAL("SPECIAL", deckItem->getString(0));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(scan_all_valuesCorrect) {
|
||||
ParserItemSizeEnum sizeType = ALL;
|
||||
ParserStringItem itemString("ITEMWITHMANY", sizeType);
|
||||
RawRecordPtr rawRecord(new RawRecord("'WELL1' '*' FISK BANAN 3* OPPLEGG_FOR_DATAANALYSE /"));
|
||||
DeckItemConstPtr deckItem = itemString.scan(rawRecord);
|
||||
BOOST_CHECK_EQUAL(8U, deckItem->size());
|
||||
|
||||
BOOST_CHECK_EQUAL("WELL1", deckItem->getString(0));
|
||||
BOOST_CHECK_EQUAL("DEFAULT", deckItem->getString(1));
|
||||
BOOST_CHECK_EQUAL("FISK", deckItem->getString(2));
|
||||
BOOST_CHECK_EQUAL("BANAN", deckItem->getString(3));
|
||||
BOOST_CHECK_EQUAL("DEFAULT", deckItem->getString(4));
|
||||
BOOST_CHECK_EQUAL("DEFAULT", deckItem->getString(5));
|
||||
BOOST_CHECK_EQUAL("DEFAULT", deckItem->getString(6));
|
||||
BOOST_CHECK_EQUAL("OPPLEGG_FOR_DATAANALYSE", deckItem->getString(7));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(scan_givenNumber_valuesCorrect) {
|
||||
ParserItemSizeEnum sizeType = ITEM_BOX;
|
||||
ParserStringItem itemString("ITEMWITHMANY", sizeType);
|
||||
RawRecordPtr rawRecord(new RawRecord("'WELL1' '*' FISK BANAN 3* OPPLEGG_FOR_DATAANALYSE /"));
|
||||
DeckItemConstPtr deckItem = itemString.scan(3, rawRecord);
|
||||
BOOST_CHECK_EQUAL(3U, deckItem->size());
|
||||
|
||||
BOOST_CHECK_EQUAL("WELL1", deckItem->getString(0));
|
||||
BOOST_CHECK_EQUAL("DEFAULT", deckItem->getString(1));
|
||||
BOOST_CHECK_EQUAL("FISK", deckItem->getString(2));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(scan_single_dataCorrect) {
|
||||
ParserItemSizeEnum sizeType = SINGLE;
|
||||
ParserStringItem itemString("ITEM1", sizeType);
|
||||
RawRecordPtr rawRecord(new RawRecord("'WELL1' 'WELL2' /"));
|
||||
DeckItemConstPtr deckItem = itemString.scan(rawRecord);
|
||||
BOOST_CHECK_EQUAL(1U, deckItem->size());
|
||||
BOOST_CHECK_EQUAL("WELL1", deckItem->getString(0));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(scan_singleWithMixedRecord_dataCorrect) {
|
||||
ParserItemSizeEnum sizeType = SINGLE;
|
||||
ParserStringItem itemString("ITEM1", sizeType);
|
||||
ParserStringItem itemInt("ITEM1", sizeType);
|
||||
|
||||
RawRecordPtr rawRecord(new RawRecord("2 'WELL1' /"));
|
||||
itemInt.scan(rawRecord);
|
||||
DeckItemConstPtr deckItem = itemString.scan(rawRecord);
|
||||
BOOST_CHECK_EQUAL("WELL1", deckItem->getString(0));
|
||||
}
|
||||
|
||||
/******************String and int**********************/
|
||||
BOOST_AUTO_TEST_CASE(scan_intsAndStrings_dataCorrect) {
|
||||
RawRecordPtr rawRecord(new RawRecord("'WELL1' 2 2 2*3 3*FLASKEHALS /"));
|
||||
|
||||
ParserItemSizeEnum sizeTypeSingle = SINGLE;
|
||||
ParserItemSizeEnum sizeTypeItemBoxed = ITEM_BOX;
|
||||
|
||||
ParserStringItem itemSingleString("ITEM1", sizeTypeSingle);
|
||||
DeckItemConstPtr deckItemWell1 = itemSingleString.scan(rawRecord);
|
||||
BOOST_CHECK_EQUAL("WELL1", deckItemWell1->getString(0));
|
||||
|
||||
ParserIntItem itemSomeInts("SOMEINTS", sizeTypeItemBoxed);
|
||||
DeckItemConstPtr deckItemInts = itemSomeInts.scan(4, rawRecord);
|
||||
BOOST_CHECK_EQUAL(2, deckItemInts->getInt(0));
|
||||
BOOST_CHECK_EQUAL(2, deckItemInts->getInt(1));
|
||||
BOOST_CHECK_EQUAL(3, deckItemInts->getInt(2));
|
||||
BOOST_CHECK_EQUAL(3, deckItemInts->getInt(3));
|
||||
|
||||
ParserStringItem itemTripleString("ITEM1", sizeTypeItemBoxed);
|
||||
DeckItemConstPtr deckItemTripleFlaskehals = itemTripleString.scan(3, rawRecord);
|
||||
BOOST_CHECK_EQUAL("FLASKEHALS", deckItemTripleFlaskehals->getString(0));
|
||||
BOOST_CHECK_EQUAL("FLASKEHALS", deckItemTripleFlaskehals->getString(1));
|
||||
BOOST_CHECK_EQUAL("FLASKEHALS", deckItemTripleFlaskehals->getString(2));
|
||||
}
|
||||
|
||||
@@ -29,7 +29,9 @@
|
||||
#include <opm/parser/eclipse/Parser/ParserRecordSize.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawDeck.hpp>
|
||||
|
||||
#include "opm/parser/eclipse/Parser/ParserIntItem.hpp"
|
||||
#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserStringItem.hpp>
|
||||
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
@@ -54,8 +56,10 @@ BOOST_AUTO_TEST_CASE(hasKeyword_hasKeyword_returnstrue) {
|
||||
BOOST_CHECK(parser->hasKeyword("FJAS"));
|
||||
}
|
||||
|
||||
ParserKWPtr setupParserKWInt(int numberOfItems) {
|
||||
ParserKWPtr parserKw(new ParserKW("RANDOM"));
|
||||
/***************** Simple Int parsing ********************************/
|
||||
|
||||
ParserKWPtr setupParserKWInt(std::string name, int numberOfItems) {
|
||||
ParserKWPtr parserKw(new ParserKW(name));
|
||||
ParserRecordPtr parserRecord(new ParserRecord());
|
||||
for (int i = 0; i < numberOfItems; i++) {
|
||||
std::string name = "ITEM_" + boost::lexical_cast<std::string>(i);
|
||||
@@ -68,11 +72,11 @@ ParserKWPtr setupParserKWInt(int numberOfItems) {
|
||||
return parserKw;
|
||||
}
|
||||
|
||||
RawDeckPtr setupRawDeckInt(int numberOfRecords, int numberOfItems) {
|
||||
RawDeckPtr setupRawDeckInt(std::string name, int numberOfRecords, int numberOfItems) {
|
||||
RawParserKWsConstPtr rawParserKWs(new RawParserKWs());
|
||||
RawDeckPtr rawDeck(new RawDeck(rawParserKWs));
|
||||
|
||||
RawKeywordPtr rawKeyword(new RawKeyword("RANDOM"));
|
||||
RawKeywordPtr rawKeyword(new RawKeyword(name));
|
||||
for (int records = 0; records < numberOfRecords; records++) {
|
||||
for (int i = 0; i < numberOfItems; i++)
|
||||
rawKeyword->addRawRecordString("42 ");
|
||||
@@ -86,8 +90,8 @@ RawDeckPtr setupRawDeckInt(int numberOfRecords, int numberOfItems) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parseFromRawDeck_singleRawSingleIntItem_deckReturned) {
|
||||
ParserPtr parser(new Parser());
|
||||
parser->addKW(setupParserKWInt(1));
|
||||
DeckPtr deck = parser->parseFromRawDeck(setupRawDeckInt(1,1));
|
||||
parser->addKW(setupParserKWInt("RANDOM", 1));
|
||||
DeckPtr deck = parser->parseFromRawDeck(setupRawDeckInt("RANDOM", 1, 1));
|
||||
|
||||
BOOST_CHECK(!deck->hasKeyword("ANDOM"));
|
||||
|
||||
@@ -97,8 +101,8 @@ BOOST_AUTO_TEST_CASE(parseFromRawDeck_singleRawSingleIntItem_deckReturned) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parseFromRawDeck_singleRawRecordsSeveralIntItem_deckReturned) {
|
||||
ParserPtr parser(new Parser());
|
||||
parser->addKW(setupParserKWInt(50));
|
||||
DeckPtr deck = parser->parseFromRawDeck(setupRawDeckInt(1, 50));
|
||||
parser->addKW(setupParserKWInt("RANDOM", 50));
|
||||
DeckPtr deck = parser->parseFromRawDeck(setupRawDeckInt("RANDOM", 1, 50));
|
||||
|
||||
BOOST_CHECK(deck->hasKeyword("RANDOM"));
|
||||
BOOST_CHECK_EQUAL(50U, deck->getKeyword("RANDOM")->getRecord(0)->size());
|
||||
@@ -106,14 +110,57 @@ BOOST_AUTO_TEST_CASE(parseFromRawDeck_singleRawRecordsSeveralIntItem_deckReturne
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parseFromRawDeck_severalRawRecordsSeveralIntItem_deckReturned) {
|
||||
ParserPtr parser(new Parser());
|
||||
parser->addKW(setupParserKWInt(50));
|
||||
DeckPtr deck = parser->parseFromRawDeck(setupRawDeckInt(10, 50));
|
||||
parser->addKW(setupParserKWInt("RANDOM", 50));
|
||||
DeckPtr deck = parser->parseFromRawDeck(setupRawDeckInt("RANDOM", 10, 50));
|
||||
|
||||
BOOST_CHECK(deck->hasKeyword("RANDOM"));
|
||||
BOOST_CHECK_EQUAL(10U, deck->getKeyword("RANDOM")->size());
|
||||
BOOST_CHECK_EQUAL(50U, deck->getKeyword("RANDOM")->getRecord(0)->size());
|
||||
}
|
||||
|
||||
/***************** Simple String parsing ********************************/
|
||||
|
||||
ParserKWPtr setupParserKWString(std::string name, int numberOfItems) {
|
||||
ParserKWPtr parserKw(new ParserKW(name));
|
||||
ParserRecordPtr parserRecord(new ParserRecord());
|
||||
for (int i = 0; i < numberOfItems; i++) {
|
||||
std::string name = "ITEM_" + boost::lexical_cast<std::string>(i);
|
||||
ParserItemPtr stringItem(new ParserStringItem(name, SINGLE));
|
||||
parserRecord->addItem(stringItem);
|
||||
}
|
||||
|
||||
parserKw->setRecord(parserRecord);
|
||||
|
||||
return parserKw;
|
||||
}
|
||||
|
||||
RawDeckPtr setupRawDeckString(std::string name, int numberOfRecords, int numberOfItems) {
|
||||
RawParserKWsConstPtr rawParserKWs(new RawParserKWs());
|
||||
RawDeckPtr rawDeck(new RawDeck(rawParserKWs));
|
||||
|
||||
RawKeywordPtr rawKeyword(new RawKeyword(name));
|
||||
for (int records = 0; records < numberOfRecords; records++) {
|
||||
for (int i = 0; i < numberOfItems; i++) {
|
||||
std::string data = "WELL-" + boost::lexical_cast<std::string>(i);
|
||||
rawKeyword->addRawRecordString(data);
|
||||
}
|
||||
rawKeyword->addRawRecordString("/");
|
||||
}
|
||||
|
||||
rawDeck->addKeyword(rawKeyword);
|
||||
|
||||
return rawDeck;
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parseFromRawDeck_singleRawRecordsSingleStringItem_deckReturned) {
|
||||
ParserPtr parser(new Parser());
|
||||
parser->addKW(setupParserKWString("WWCT", 1));
|
||||
DeckPtr deck = parser->parseFromRawDeck(setupRawDeckString("WWCT",1, 1));
|
||||
|
||||
BOOST_CHECK(deck->hasKeyword("WWCT"));
|
||||
BOOST_CHECK_EQUAL(1U, deck->getKeyword("WWCT")->size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user