diff --git a/opm/parser/eclipse/Parser/ParserItem.hpp b/opm/parser/eclipse/Parser/ParserItem.hpp index 12fedabcc..d6bae1acc 100644 --- a/opm/parser/eclipse/Parser/ParserItem.hpp +++ b/opm/parser/eclipse/Parser/ParserItem.hpp @@ -25,6 +25,7 @@ #include #include +#include namespace Json { class JsonObject; @@ -34,22 +35,44 @@ namespace Opm { class RawRecord; + + /* + The ParserItem class describes one item handled by the parser. A parser + item is the schema for parsing values from the deck, when configuring the + ParserItem *two* types are in action: + + InputType: These are the types specified when instantiating a + ParserItem, the available types are currently: INT, DOUBLE, STRING, + RAW_STRING and UDA. + + DataType: This the C++ type of items generated when parsing the deck, + currently the available datatypes are int, double and std::string. + The mapping from input type to data type is many-to-one, and + currently both STRING and RAW_STRING map to std::string and both + DOUBLE and UDA map to double. + + Splitting the type treatment in two layers in this way enables + properties/transformations to be added to the data before they are + internalized as data in a DataType instance; e.g. the difference between + STRING and RAW_STRING is that for the latter quotes and '*' tokens are + retained. + */ + + class ParserItem { public: enum class item_size { ALL, SINGLE }; static item_size size_from_string( const std::string& ); static std::string string_from_size( item_size ); - explicit ParserItem( const std::string& name ); - ParserItem( const std::string& name, item_size ); - template< typename T > - ParserItem( const std::string& item_name, T val ) : - ParserItem( item_name, item_size::SINGLE, std::move( val ) ) {} - ParserItem( const std::string& name, item_size, int defaultValue ); - ParserItem( const std::string& name, item_size, double defaultValue ); - ParserItem( const std::string& name, item_size, std::string defaultValue ); + enum class itype {UNKNOWN, DOUBLE, INT, STRING, RAW_STRING}; + static itype from_string(const std::string& string_value); + static std::string to_string(itype input_type); + std::string type_literal() const; - explicit ParserItem(const Json::JsonObject& jsonConfig); + + explicit ParserItem( const std::string& name, ParserItem::itype input_type ); + explicit ParserItem( const Json::JsonObject& jsonConfig ); void push_backDimension( const std::string& ); const std::string& getDimension(size_t index) const; @@ -57,14 +80,14 @@ namespace Opm { size_t numDimensions() const; const std::string& name() const; item_size sizeType() const; + void setSizeType(item_size size_type); std::string getDescription() const; bool scalar() const; - void setDescription(std::string helpText); + void setDescription(const std::string& helpText); template< typename T > void setDefault( T ); /* set type without a default value. will reset dimension etc. */ - template< typename T > void setType( T ); - template< typename T > void setType( T , bool raw); + void setInputType( itype input_type ); bool parseRaw() const; bool hasDefault() const; template< typename T > const T& getDefault() const; @@ -73,8 +96,10 @@ namespace Opm { bool operator!=( const ParserItem& ) const; DeckItem scan( RawRecord& rawRecord ) const; + + std::string size_literal() const; const std::string className() const; - std::string createCode() const; + std::string createCode(const std::string& indent) const; std::ostream& inlineClass(std::ostream&, const std::string& indent) const; std::string inlineClassInit(const std::string& parentClass, const std::string* defaultValue = nullptr ) const; @@ -83,18 +108,19 @@ namespace Opm { double dval; int ival; std::string sval; - bool raw_string = false; std::vector< std::string > dimensions; std::string m_name; - item_size m_sizeType; + item_size m_sizeType = item_size::SINGLE; std::string m_description; - type_tag type = type_tag::unknown; + type_tag data_type = type_tag::unknown; + itype input_type = itype::UNKNOWN; bool m_defaultSet; template< typename T > T& value_ref(); template< typename T > const T& value_ref() const; + template< typename T > void setDataType( T ); friend std::ostream& operator<<( std::ostream&, const ParserItem& ); }; diff --git a/src/opm/parser/eclipse/Generator/KeywordGenerator.cpp b/src/opm/parser/eclipse/Generator/KeywordGenerator.cpp index 08fabfb13..3549456ad 100644 --- a/src/opm/parser/eclipse/Generator/KeywordGenerator.cpp +++ b/src/opm/parser/eclipse/Generator/KeywordGenerator.cpp @@ -196,7 +196,7 @@ namespace Opm { stream << " BOOST_CHECK_EQUAL( jsonKeyword, inlineKeyword );" << std::endl; stream << " if (jsonKeyword.hasDimension()) {" < #include +#include +#include #include @@ -50,7 +52,7 @@ template<> const std::string& default_value< std::string >() { return value; } -type_tag get_type_json( const std::string& str ) { +type_tag get_data_type_json( const std::string& str ) { if( str == "INT" ) return type_tag::integer; if( str == "DOUBLE" ) return type_tag::fdouble; if( str == "STRING" ) return type_tag::string; @@ -58,6 +60,17 @@ type_tag get_type_json( const std::string& str ) { throw std::invalid_argument( str + " cannot be converted to enum 'tag'" ); } +/* + For very small numbers std::to_string() will just return the string "0.000000" +*/ +std::string as_string(double value) { + if (std::fabs(value) < 1e-4) { + std::ostringstream ss; + ss << std::setprecision(12) << std::fixed << value; + return ss.str(); + } else + return std::to_string(value); +} } @@ -78,20 +91,21 @@ std::string ParserItem::string_from_size( ParserItem::item_size sz ) { } template<> const int& ParserItem::value_ref< int >() const { - if( this->type != get_type< int >() ) - throw std::invalid_argument( "Wrong type." ); + if( this->data_type != get_type< int >() ) + throw std::invalid_argument( "ValueRef: Wrong type." ); return this->ival; } template<> const double& ParserItem::value_ref< double >() const { - if( this->type != get_type< double >() ) - throw std::invalid_argument( "Wrong type." ); + if( this->data_type != get_type< double >() ) + throw std::invalid_argument("ValueRef Wrong type." ); + return this->dval; } template<> const std::string& ParserItem::value_ref< std::string >() const { - if( this->type != get_type< std::string >() ) - throw std::invalid_argument( "Wrong type." ); + if( this->data_type != get_type< std::string >() ) + throw std::invalid_argument( "ValueRef Wrong type." ); return this->sval; } @@ -102,44 +116,13 @@ T& ParserItem::value_ref() { ); } -ParserItem::ParserItem( const std::string& itemName ) : - ParserItem( itemName, ParserItem::item_size::SINGLE ) -{} -ParserItem::ParserItem( const std::string& itemName, - ParserItem::item_size p_sizeType ) : - m_name( itemName ), - m_sizeType( p_sizeType ), - m_defaultSet( false ) -{} - -ParserItem::ParserItem( const std::string& itemName, item_size sz, int val ) : - ival( val ), - m_name( itemName ), - m_sizeType( sz ), - type( get_type< int >() ), - m_defaultSet( true ) -{} - -ParserItem::ParserItem( const std::string& itemName, - item_size sz, - double val ) : - dval( val ), - m_name( itemName ), - m_sizeType( sz ), - type( get_type< double >() ), - m_defaultSet( true ) -{} - -ParserItem::ParserItem( const std::string& itemName, - item_size sz, - std::string val ) : - sval( std::move( val ) ), - m_name( itemName ), - m_sizeType( sz ), - type( get_type< std::string >() ), - m_defaultSet( true ) -{} +ParserItem::ParserItem( const std::string& itemName, ParserItem::itype input_type) : + m_name(itemName), + m_defaultSet(false) +{ + this->setInputType(input_type); +} ParserItem::ParserItem( const Json::JsonObject& json ) : m_name( json.get_string( "name" ) ), @@ -149,7 +132,8 @@ ParserItem::ParserItem( const Json::JsonObject& json ) : m_description( json.has_item( "description" ) ? json.get_string( "description" ) : "" ), - type( get_type_json( json.get_string( "value_type" ) ) ), + data_type( get_data_type_json( json.get_string( "value_type" ) ) ), + input_type( ParserItem::from_string( json.get_string("value_type"))), m_defaultSet( false ) { if( json.has_item( "dimension" ) ) { @@ -168,12 +152,9 @@ ParserItem::ParserItem( const Json::JsonObject& json ) : ); } } - if (json.get_string("value_type") == "RAW_STRING") - this->raw_string = true; - if( !json.has_item( "default" ) ) return; - switch( this->type ) { + switch( this->data_type ) { case type_tag::integer: this->setDefault( json.get_int( "default" ) ); break; @@ -193,7 +174,7 @@ ParserItem::ParserItem( const Json::JsonObject& json ) : template< typename T > void ParserItem::setDefault( T val ) { - if( this->type != type_tag::fdouble && this->m_sizeType == item_size::ALL ) + if( this->data_type != type_tag::fdouble && this->m_sizeType == item_size::ALL ) throw std::invalid_argument( "The size type ALL can not be combined " "with an explicit default value." ); @@ -201,27 +182,37 @@ void ParserItem::setDefault( T val ) { this->m_defaultSet = true; } -template< typename T > -void ParserItem::setType( T) { - this->type = get_type< T >(); + +void ParserItem::setInputType(ParserItem::itype input_type) { + this->input_type = input_type; + if (input_type == itype::INT) + this->setDataType(int()); + + if (input_type == itype::DOUBLE) + this->setDataType(double()); + + if (input_type == itype::STRING) + this->setDataType( std::string() ); + + if (input_type == itype::RAW_STRING) + this->setDataType( std::string() ); } -template< typename T > -void ParserItem::setType( T, bool raw ) { - this->type = get_type< T >(); - this->raw_string = raw; -} +template< typename T > +void ParserItem::setDataType( T) { + this->data_type = get_type< T >(); +} bool ParserItem::hasDefault() const { return this->m_defaultSet; } -template< typename T > +template< typename T> const T& ParserItem::getDefault() const { - if( get_type< T >() != this->type ) - throw std::invalid_argument( "Wrong type." ); + if( get_type< T >() != this->data_type ) + throw std::invalid_argument( "getDefault: Wrong type." ); if( !this->hasDefault() && this->m_sizeType == item_size::ALL ) return default_value< T >(); @@ -234,26 +225,26 @@ const T& ParserItem::getDefault() const { } bool ParserItem::hasDimension() const { - if( this->type != type_tag::fdouble ) + if( this->data_type != type_tag::fdouble ) return false; return !this->dimensions.empty(); } size_t ParserItem::numDimensions() const { - if( this->type != type_tag::fdouble ) return 0; + if( this->data_type != type_tag::fdouble ) return 0; return this->dimensions.size(); } const std::string& ParserItem::getDimension( size_t index ) const { - if( this->type != type_tag::fdouble ) + if( this->data_type != type_tag::fdouble ) throw std::invalid_argument("Item is not double."); return this->dimensions.at( index ); } void ParserItem::push_backDimension( const std::string& dim ) { - if( this->type != type_tag::fdouble ) + if( this->data_type != type_tag::fdouble ) throw std::invalid_argument( "Invalid type, does not have dimension." ); if( this->sizeType() == item_size::SINGLE && this->dimensions.size() > 0 ) { @@ -287,26 +278,38 @@ void ParserItem::push_backDimension( const std::string& dim ) { return m_description; } - void ParserItem::setDescription(std::string description) { + + void ParserItem::setSizeType(item_size size_type) { + this->m_sizeType = size_type; + } + + + void ParserItem::setDescription(const std::string& description) { m_description = description; } bool ParserItem::operator==( const ParserItem& rhs ) const { - if( !( this->type == rhs.type - && this->m_name == rhs.m_name - && this->m_description == rhs.m_description - && this->m_sizeType == rhs.m_sizeType - && this->m_defaultSet == rhs.m_defaultSet ) ) - return false; + if( !( this->data_type == rhs.data_type + && this->m_name == rhs.m_name + && this->m_description == rhs.m_description + && this->input_type == rhs.input_type + && this->m_sizeType == rhs.m_sizeType + && this->m_defaultSet == rhs.m_defaultSet ) ) + return false; if( this->m_defaultSet ) { - switch( this->type ) { + switch( this->data_type ) { case type_tag::integer: if( this->ival != rhs.ival ) return false; break; case type_tag::fdouble: - if( this->dval != rhs.dval ) return false; + if( this->dval != rhs.dval ) { + double diff = std::fabs(this->dval - rhs.dval); + double sum = std::fabs(this->dval) + std::fabs(rhs.dval); + if ((diff / sum) > 1e-8) + return false; + } break; case type_tag::string: @@ -317,9 +320,7 @@ bool ParserItem::operator==( const ParserItem& rhs ) const { throw std::logic_error( "Item of unknown type." ); } } - - if( this->type != type_tag::fdouble ) return true; - + if( this->data_type != type_tag::fdouble ) return true; return this->dimensions.size() == rhs.dimensions.size() && std::equal( this->dimensions.begin(), this->dimensions.end(), @@ -330,38 +331,85 @@ bool ParserItem::operator!=( const ParserItem& rhs ) const { return !( *this == rhs ); } -std::string ParserItem::createCode() const { - std::stringstream stream; - stream << "ParserItem item(\"" << this->name() - << "\", ParserItem::item_size::" << this->sizeType(); - if( m_defaultSet ) { - stream << ", "; - switch( this->type ) { - case type_tag::integer: - stream << this->getDefault< int >(); - break; - - case type_tag::fdouble: - stream << "double( " - << boost::lexical_cast< std::string > - ( this->getDefault< double >() ) - << " )"; - break; - - case type_tag::string: - stream << "\"" << this->getDefault< std::string >() << "\""; - break; - - default: - throw std::logic_error( "Item of unknown type." ); - } - } - - if (raw_string) - stream << " ); item.setType( " << tag_name( this->type ) << "(), true );"; +std::string ParserItem::size_literal() const { + if (this->m_sizeType == item_size::ALL) + return "ParserItem::item_size::ALL"; else - stream << " ); item.setType( " << tag_name( this->type ) << "() );"; + return "ParserItem::item_size::SINGLE"; +} + +std::string ParserItem::type_literal() const { + if (this->input_type == itype::DOUBLE) + return "ParserItem::itype::DOUBLE"; + + if (this->input_type == itype::INT) + return "ParserItem::itype::INT"; + + if (this->input_type == itype::STRING) + return "ParserItem::itype::STRING"; + + if (this->input_type == itype::RAW_STRING) + return "ParserItem::itype::RAW_STRING"; + + throw std::invalid_argument("Could not resolve type literal"); +} + +std::string ParserItem::to_string(itype input_type) { + if (input_type == itype::RAW_STRING) + return "RAW_STRING"; + + if (input_type == itype::STRING) + return "STRING"; + + if (input_type == itype::DOUBLE) + return "DOUBLE"; + + if (input_type == itype::INT) + return "INT"; + + throw std::invalid_argument("Can not convert to string"); +} + + +ParserItem::itype ParserItem::from_string(const std::string& string_value) { + if( string_value == "INT" ) return itype::INT; + if( string_value == "DOUBLE" ) return itype::DOUBLE; + if( string_value == "STRING" ) return itype::STRING; + if( string_value == "RAW_STRING") return itype::RAW_STRING; + throw std::invalid_argument( string_value + " cannot be converted to ParserInputType" ); +} + + +std::string ParserItem::createCode(const std::string& indent) const { + std::stringstream stream; + stream << indent << "ParserItem item(\"" << this->name() <<"\", " << this->type_literal() << ");" << std::endl; + if (this->m_sizeType != ParserItem::item_size::SINGLE) + stream << indent << "item.setSizeType(" << this->size_literal() << ");" << std::endl; + + if( m_defaultSet ) { + stream << indent << "item.setDefault( "; + switch( this->data_type ) { + case type_tag::integer: + stream << this->getDefault< int >(); + break; + + case type_tag::fdouble: + stream << "double(" << as_string(this->getDefault()) << ")"; + break; + + case type_tag::string: + stream << "std::string(\"" << this->getDefault< std::string >() << "\")"; + break; + + default: + throw std::logic_error( "Item of unknown type." ); + } + stream << " );" << std::endl; + } + + if (this->m_description.size() > 0) + stream << indent << "item.setDescription(\"" << this->m_description << "\");" << std::endl; return stream.str(); } @@ -468,7 +516,7 @@ DeckItem scan_item( const ParserItem& p, RawRecord& record ) { /// returns a DeckItem object. /// NOTE: data are popped from the records deque! DeckItem ParserItem::scan( RawRecord& record ) const { - switch( this->type ) { + switch( this->data_type ) { case type_tag::integer: return scan_item< int >( *this, record ); case type_tag::fdouble: @@ -489,7 +537,7 @@ std::ostream& ParserItem::inlineClass( std::ostream& stream, const std::string& if( this->hasDefault() ) { stream << local_indent << "static const " - << tag_name( this->type ) + << tag_name( this->data_type ) << " defaultValue;" << std::endl; } @@ -507,10 +555,10 @@ std::string ParserItem::inlineClassInit(const std::string& parentClass, if( !this->hasDefault() ) return ss.str(); - auto typestring = tag_name( this->type ); + auto typestring = tag_name( this->data_type ); auto defval = [this]() -> std::string { - switch( this->type ) { + switch( this->data_type ) { case type_tag::integer: return std::to_string( this->getDefault< int >() ); case type_tag::fdouble: @@ -545,7 +593,7 @@ std::ostream& operator<<( std::ostream& stream, const ParserItem& item ) { if( item.hasDefault() ) { stream << "default: "; - switch( item.type ) { + switch( item.data_type ) { case type_tag::integer: stream << item.getDefault< int >(); break; @@ -578,17 +626,16 @@ std::ostream& operator<<( std::ostream& stream, const ParserItem& item ) { } bool ParserItem::parseRaw( ) const { - return this->raw_string; + return (this->input_type == itype::RAW_STRING); } template void ParserItem::setDefault( int ); template void ParserItem::setDefault( double ); template void ParserItem::setDefault( std::string ); -template void ParserItem::setType( int ); -template void ParserItem::setType( double ); -template void ParserItem::setType( std::string ); -template void ParserItem::setType( std::string , bool); +template void ParserItem::setDataType( int ); +template void ParserItem::setDataType( double ); +template void ParserItem::setDataType( std::string ); template const int& ParserItem::getDefault() const; template const double& ParserItem::getDefault() const; diff --git a/src/opm/parser/eclipse/Parser/ParserKeyword.cpp b/src/opm/parser/eclipse/Parser/ParserKeyword.cpp index 6bcbebd75..8177659df 100644 --- a/src/opm/parser/eclipse/Parser/ParserKeyword.cpp +++ b/src/opm/parser/eclipse/Parser/ParserKeyword.cpp @@ -348,11 +348,13 @@ void set_dimensions( ParserItem& item, const std::string value_type = dataConfig.get_string("value_type"); const std::string itemName("data"); bool hasDefault = dataConfig.has_item("default"); - ParserItem item( itemName, ParserItem::item_size::ALL ); + auto input_type = ParserItem::from_string(dataConfig.get_string("value_type")); + ParserItem item( itemName, input_type); ParserRecord record; - if (value_type == "INT") { - item.setType( int() ); + item.setSizeType( ParserItem::item_size::ALL ); + + if (input_type == ParserItem::itype::INT) { if(hasDefault) { int defaultValue = dataConfig.get_int("default"); item.setDefault(defaultValue); @@ -362,13 +364,7 @@ void set_dimensions( ParserItem& item, return; } - - if (value_type == "STRING" || value_type == "RAW_STRING") { - if (value_type == "RAW_STRING") - item.setType( std::string(), true ); - else - item.setType( std::string() ); - + if (input_type == ParserItem::itype::STRING || input_type == ParserItem::itype::RAW_STRING) { if (hasDefault) { std::string defaultValue = dataConfig.get_string("default"); item.setDefault(defaultValue); @@ -378,8 +374,7 @@ void set_dimensions( ParserItem& item, return; } - if (value_type == "DOUBLE") { - item.setType( double() ); + if (input_type == ParserItem::itype::DOUBLE) { if (hasDefault) { double defaultValue = dataConfig.get_double("default"); item.setDefault(defaultValue); @@ -620,10 +615,8 @@ void set_dimensions( ParserItem& item, break; } } - ss << indent << "setDescription(\"" << getDescription() << "\");" << std::endl; // add the valid sections for the keyword - ss << indent << "clearValidSectionNames();\n"; for (auto sectionNameIt = m_validSectionNames.begin(); sectionNameIt != m_validSectionNames.end(); ++sectionNameIt) @@ -654,8 +647,7 @@ void set_dimensions( ParserItem& item, ss << local_indent << "{" << std::endl; { std::string indent3 = local_indent + " "; - ss << indent3 << item.createCode() << std::endl - << indent3 << "item.setDescription(\"" << item.getDescription() << "\");" << std::endl; + ss << item.createCode(indent3); for (size_t idim=0; idim < item.numDimensions(); idim++) ss << indent3 <<"item.push_backDimension(\"" << item.getDimension( idim ) << "\");" << std::endl; { @@ -709,7 +701,7 @@ void set_dimensions( ParserItem& item, || m_keywordSizeType != rhs.m_keywordSizeType || isDataKeyword() != rhs.isDataKeyword() || m_isTableCollection != rhs.m_isTableCollection ) - return false; + return false; switch( m_keywordSizeType ) { case FIXED: diff --git a/src/opm/parser/eclipse/share/keywords/000_Eclipse100/W/WSEGITER b/src/opm/parser/eclipse/share/keywords/000_Eclipse100/W/WSEGITER index 14c8082dc..6d867684d 100644 --- a/src/opm/parser/eclipse/share/keywords/000_Eclipse100/W/WSEGITER +++ b/src/opm/parser/eclipse/share/keywords/000_Eclipse100/W/WSEGITER @@ -1,6 +1,6 @@ - {"name" : "WSEGITER", "sections" : ["SCHEDULE"], "size" : 1, "items" : [ - {"name" : "MAX_WELL_ITERATIONS" , "value_type" : "INT" , "default" : 20}, - {"name" : "MAX_TIMES_REDUCED" , "value_type" : "INT" , "default" : 5}, - {"name" : "REDUCTION_FACTOR" , "value_type" : "DOUBLE" , "default" : 0.3}, - {"name" : "INCREASING_FACTOR" , "value_type" : "DOUBLE" , "default" : 2.0} - ]} +{"name" : "WSEGITER", "sections" : ["SCHEDULE"], "size" : 1, "items" : [ + {"name" : "MAX_WELL_ITERATIONS" , "value_type" : "INT" , "default" : 20}, + {"name" : "MAX_TIMES_REDUCED" , "value_type" : "INT" , "default" : 5}, + {"name" : "REDUCTION_FACTOR" , "value_type" : "DOUBLE" , "default" : 0.3}, + {"name" : "INCREASING_FACTOR" , "value_type" : "DOUBLE" , "default" : 2.0} +]} diff --git a/tests/parser/DeckTests.cpp b/tests/parser/DeckTests.cpp index 2d84d926c..dc65c8334 100644 --- a/tests/parser/DeckTests.cpp +++ b/tests/parser/DeckTests.cpp @@ -517,7 +517,7 @@ BOOST_AUTO_TEST_CASE(get_byNameNonExisting_throws) { } BOOST_AUTO_TEST_CASE(StringsWithSpaceOK) { - ParserItem itemString("STRINGITEM1", "" ); + ParserItem itemString("STRINGITEM1", ParserItem::itype::STRING); ParserRecord record1; RawRecord rawRecord( " ' VALUE ' " ); ParseContext parseContext; diff --git a/tests/parser/ParserTests.cpp b/tests/parser/ParserTests.cpp index df7ced2d7..af84740c5 100644 --- a/tests/parser/ParserTests.cpp +++ b/tests/parser/ParserTests.cpp @@ -36,6 +36,13 @@ using namespace Opm; namespace { +constexpr ParserItem::itype INT = ParserItem::itype::INT; +constexpr ParserItem::itype STRING= ParserItem::itype::STRING; +constexpr ParserItem::itype RAW_STRING = ParserItem::itype::RAW_STRING; +constexpr ParserItem::itype DOUBLE = ParserItem::itype::DOUBLE; + + + std::string prefix() { return boost::unit_test::framework::master_test_suite().argv[1]; } @@ -382,23 +389,25 @@ BOOST_AUTO_TEST_CASE(ParseTNUM) { } BOOST_AUTO_TEST_CASE(ScalarCheck) { - ParserItem item1("ITEM1", ParserItem::item_size::SINGLE ); - ParserItem item2("ITEM1", ParserItem::item_size::ALL ); + ParserItem item1("ITEM1", INT); + ParserItem item2("ITEM1", INT); item2.setSizeType( ParserItem::item_size::ALL ); + BOOST_CHECK( item1.scalar()); BOOST_CHECK( !item2.scalar()); } BOOST_AUTO_TEST_CASE(Initialize_DefaultSizeType) { - ParserItem item1(std::string("ITEM1")); + ParserItem item1(std::string("ITEM1"), INT); BOOST_CHECK_EQUAL( ParserItem::item_size::SINGLE, item1.sizeType()); } BOOST_AUTO_TEST_CASE(Initialize_Default) { - ParserItem item1(std::string("ITEM1")); - ParserItem item2(std::string("ITEM1"), 88); + ParserItem item1(std::string("ITEM1"), INT); + ParserItem item2(std::string("ITEM1"), INT); item2.setDefault(88); + BOOST_CHECK(!item1.hasDefault()); BOOST_CHECK_THROW(item1.getDefault< int >(), std::invalid_argument); BOOST_CHECK(item2.hasDefault()); @@ -407,25 +416,23 @@ BOOST_AUTO_TEST_CASE(Initialize_Default) { BOOST_AUTO_TEST_CASE(Initialize_Default_Double) { - ParserItem item1(std::string("ITEM1")); - ParserItem item2("ITEM1", 88.91); + ParserItem item1(std::string("ITEM1"), DOUBLE); + ParserItem item2("ITEM1", DOUBLE); item2.setDefault(88.91); + BOOST_CHECK(!item1.hasDefault()); BOOST_CHECK_THROW( item1.getDefault< double >(), std::invalid_argument ); BOOST_CHECK_EQUAL( 88.91 , item2.getDefault< double >()); } BOOST_AUTO_TEST_CASE(Initialize_Default_String) { - ParserItem item1(std::string("ITEM1")); + ParserItem item1(std::string("ITEM1"), STRING); BOOST_CHECK(!item1.hasDefault()); BOOST_CHECK_THROW(item1.getDefault< std::string >(), std::invalid_argument); - - ParserItem item2("ITEM1", "String"); - BOOST_CHECK(item2.hasDefault()); - BOOST_CHECK_EQUAL( "String" , item2.getDefault< std::string >()); } BOOST_AUTO_TEST_CASE(scan_PreMatureTerminator_defaultUsed) { - ParserItem itemInt("ITEM2", 123); + ParserItem itemInt("ITEM2", INT); + itemInt.setDefault(123); RawRecord rawRecord1( "" ); const auto defaulted = itemInt.scan(rawRecord1); @@ -435,7 +442,7 @@ BOOST_AUTO_TEST_CASE(scan_PreMatureTerminator_defaultUsed) { } BOOST_AUTO_TEST_CASE(InitializeIntItem_setDescription_canReadBack) { - ParserItem itemInt("ITEM1"); + ParserItem itemInt("ITEM1", INT); std::string description("This is the description"); itemInt.setDescription(description); @@ -514,8 +521,8 @@ BOOST_AUTO_TEST_CASE(InitializeIntItem_WithoutDescription_DescriptionPropertySho BOOST_AUTO_TEST_CASE(IntItem_Equal_ReturnsTrue) { auto sizeType = ParserItem::item_size::ALL; - ParserItem item1("ITEM1", sizeType); - ParserItem item2("ITEM1", sizeType); + ParserItem item1("ITEM1", INT); item1.setSizeType(sizeType); + ParserItem item2("ITEM1", INT); item2.setSizeType(sizeType); ParserItem item3 = item1; BOOST_CHECK_EQUAL( item1, item2 ); @@ -524,10 +531,10 @@ BOOST_AUTO_TEST_CASE(IntItem_Equal_ReturnsTrue) { BOOST_AUTO_TEST_CASE(IntItem_Different_ReturnsFalse) { - ParserItem item1("ITEM1", ParserItem::item_size::ALL); - ParserItem item2("ITEM2", ParserItem::item_size::ALL); - ParserItem item3("ITEM1"); - ParserItem item4("ITEM1" , 42); + ParserItem item1("ITEM1", INT); item1.setSizeType(ParserItem::item_size::ALL); + ParserItem item2("ITEM2", INT); item2.setSizeType(ParserItem::item_size::ALL); + ParserItem item3("ITEM1", INT); + ParserItem item4("ITEM1", INT); item4.setDefault(52); BOOST_CHECK_NE( item1, item2 ); BOOST_CHECK_NE( item1, item3 ); @@ -537,8 +544,8 @@ BOOST_AUTO_TEST_CASE(IntItem_Different_ReturnsFalse) { BOOST_AUTO_TEST_CASE(DoubleItem_DimEqual_ReturnsTrue) { auto sizeType = ParserItem::item_size::ALL; - ParserItem item1("ITEM1", sizeType, 0.0); - ParserItem item2("ITEM1", sizeType, 0.0); + ParserItem item1("ITEM1", DOUBLE); item1.setSizeType(sizeType); + ParserItem item2("ITEM1", DOUBLE); item2.setSizeType(sizeType); item1.push_backDimension("Length*Length"); item2.push_backDimension("Length*Length"); @@ -549,10 +556,10 @@ BOOST_AUTO_TEST_CASE(DoubleItem_DimEqual_ReturnsTrue) { BOOST_AUTO_TEST_CASE(DoubleItem_DimDifferent_ReturnsFalse) { auto sizeType = ParserItem::item_size::ALL; - ParserItem item1("ITEM1", sizeType, 0.0); // Dim: [] - ParserItem item2("ITEM1", sizeType, 0.0); // Dim: [Length] - ParserItem item3("ITEM1", sizeType, 0.0); // Dim: [Length ,Length] - ParserItem item4("ITEM1", sizeType, 0.0); // Dim: [t] + ParserItem item1("ITEM1", DOUBLE); item1.setSizeType(sizeType); // Dim: [] + ParserItem item2("ITEM1", DOUBLE); item2.setSizeType(sizeType); // Dim: [Length] + ParserItem item3("ITEM1", DOUBLE); item3.setSizeType(sizeType); // Dim: [Length ,Length] + ParserItem item4("ITEM1", DOUBLE); item4.setSizeType(sizeType); // Dim: [t] item2.push_backDimension("Length"); item3.push_backDimension("Length"); @@ -570,10 +577,10 @@ BOOST_AUTO_TEST_CASE(DoubleItem_DimDifferent_ReturnsFalse) { BOOST_AUTO_TEST_CASE(DoubleItem_Different_ReturnsFalse) { - ParserItem item1("ITEM1", ParserItem::item_size::ALL, 0.0); - ParserItem item2("ITEM2", ParserItem::item_size::ALL, 0.0); - ParserItem item3("ITEM1", 0.0 ); - ParserItem item4("ITEM1", 42.89); + ParserItem item1("ITEM1", DOUBLE); item1.setDefault(0.0); item1.setSizeType(ParserItem::item_size::ALL); + ParserItem item2("ITEM2", DOUBLE); item2.setDefault(0.0); item2.setSizeType(ParserItem::item_size::ALL); + ParserItem item3("ITEM1", DOUBLE); item3.setDefault(0.0); + ParserItem item4("ITEM1", DOUBLE); item4.setDefault(42.89); BOOST_CHECK_NE( item1, item2 ); BOOST_CHECK_NE( item1, item3 ); @@ -584,8 +591,8 @@ BOOST_AUTO_TEST_CASE(DoubleItem_Different_ReturnsFalse) { BOOST_AUTO_TEST_CASE(StringItem_Equal_ReturnsTrue) { auto sizeType = ParserItem::item_size::ALL; - ParserItem item1("ITEM1", sizeType, ""); - ParserItem item2("ITEM1", sizeType, ""); + ParserItem item1("ITEM1", STRING); item1.setSizeType(sizeType); + ParserItem item2("ITEM1", STRING); item2.setSizeType(sizeType); ParserItem item3 = item1; BOOST_CHECK_EQUAL( item1, item2 ); @@ -594,10 +601,11 @@ BOOST_AUTO_TEST_CASE(StringItem_Equal_ReturnsTrue) { BOOST_AUTO_TEST_CASE(StringItem_Different_ReturnsFalse) { - ParserItem item1("ITEM1", ParserItem::item_size::ALL, ""); - ParserItem item2("ITEM2", ParserItem::item_size::ALL, ""); - ParserItem item3("ITEM1", "" ); - ParserItem item4("ITEM1", "42.89"); + auto sizeType = ParserItem::item_size::ALL; + ParserItem item1("ITEM1", STRING); item1.setDefault( std::string("")); item1.setSizeType(sizeType); + ParserItem item2("ITEM2", STRING); item2.setDefault( std::string("")); item2.setSizeType(sizeType); + ParserItem item3("ITEM1", STRING); item3.setDefault( std::string("")); + ParserItem item4("ITEM1", STRING); item4.setDefault( std::string("42.89")); BOOST_CHECK_NE( item1, item2 ); BOOST_CHECK_NE( item1, item3 ); @@ -613,28 +621,28 @@ BOOST_AUTO_TEST_CASE(StringItem_Different_ReturnsFalse) { BOOST_AUTO_TEST_CASE(Name_ReturnsCorrectName) { auto sizeType = ParserItem::item_size::ALL; - ParserItem item1("ITEM1", sizeType); + ParserItem item1("ITEM1", INT); item1.setSizeType(sizeType); BOOST_CHECK_EQUAL("ITEM1", item1.name()); - ParserItem item2("", sizeType); + ParserItem item2("", INT); item2.setSizeType(sizeType); BOOST_CHECK_EQUAL("", item2.name()); } BOOST_AUTO_TEST_CASE(Size_ReturnsCorrectSizeTypeSingle) { auto sizeType = ParserItem::item_size::SINGLE; - ParserItem item1("ITEM1", sizeType); + ParserItem item1("ITEM1", INT); BOOST_CHECK_EQUAL(sizeType, item1.sizeType()); } BOOST_AUTO_TEST_CASE(Size_ReturnsCorrectSizeTypeAll) { auto sizeType = ParserItem::item_size::ALL; - ParserItem item1("ITEM1", sizeType); + ParserItem item1("ITEM1", INT); item1.setSizeType(sizeType); BOOST_CHECK_EQUAL(sizeType, item1.sizeType()); } BOOST_AUTO_TEST_CASE(Scan_All_CorrectIntSetInDeckItem) { auto sizeType = ParserItem::item_size::ALL; - ParserItem itemInt("ITEM", sizeType, 0); + ParserItem itemInt("ITEM", INT); itemInt.setSizeType(sizeType); RawRecord rawRecord( "100 443 10*77 10*1 25" ); const auto deckIntItem = itemInt.scan(rawRecord); @@ -646,8 +654,8 @@ BOOST_AUTO_TEST_CASE(Scan_All_CorrectIntSetInDeckItem) { BOOST_AUTO_TEST_CASE(Scan_All_WithDefaults) { auto sizeType = ParserItem::item_size::ALL; - ParserItem itemInt("ITEM", sizeType); - itemInt.setType( int() ); + ParserItem itemInt("ITEM", INT); itemInt.setSizeType(sizeType); + itemInt.setInputType( ParserItem::itype::INT ); RawRecord rawRecord( "100 10* 10*1 25" ); const auto deckIntItem = itemInt.scan(rawRecord); @@ -661,7 +669,7 @@ BOOST_AUTO_TEST_CASE(Scan_All_WithDefaults) { } BOOST_AUTO_TEST_CASE(Scan_SINGLE_CorrectIntSetInDeckItem) { - ParserItem itemInt(std::string("ITEM2"), 0); + ParserItem itemInt(std::string("ITEM2"), INT); RawRecord rawRecord("100 44.3 'Heisann'" ); const auto deckIntItem = itemInt.scan(rawRecord); @@ -669,9 +677,9 @@ BOOST_AUTO_TEST_CASE(Scan_SINGLE_CorrectIntSetInDeckItem) { } BOOST_AUTO_TEST_CASE(Scan_SeveralInts_CorrectIntsSetInDeckItem) { - ParserItem itemInt1(std::string("ITEM1"), 0); - ParserItem itemInt2(std::string("ITEM2"), 0); - ParserItem itemInt3(std::string("ITEM3"), 0); + ParserItem itemInt1(std::string("ITEM1"), INT); + ParserItem itemInt2(std::string("ITEM2"), INT); + ParserItem itemInt3(std::string("ITEM3"), INT); RawRecord rawRecord( "100 443 338932 222.33 'Heisann' " ); const auto deckIntItem1 = itemInt1.scan(rawRecord); @@ -689,10 +697,10 @@ BOOST_AUTO_TEST_CASE(Scan_SeveralInts_CorrectIntsSetInDeckItem) { BOOST_AUTO_TEST_CASE(Scan_Multiplier_CorrectIntsSetInDeckItem) { - auto sizeType = ParserItem::item_size::ALL; - ParserItem itemInt("ITEM2", sizeType, 0); + ParserItem itemInt("ITEM2", INT); RawRecord rawRecord( "3*4 " ); + itemInt.setSizeType(ParserItem::item_size::ALL); const auto deckIntItem = itemInt.scan(rawRecord); BOOST_CHECK_EQUAL(4, deckIntItem.get< int >(0)); BOOST_CHECK_EQUAL(4, deckIntItem.get< int >(1)); @@ -700,16 +708,15 @@ BOOST_AUTO_TEST_CASE(Scan_Multiplier_CorrectIntsSetInDeckItem) { } BOOST_AUTO_TEST_CASE(Scan_StarNoMultiplier_ExceptionThrown) { - auto sizeType = ParserItem::item_size::SINGLE; - ParserItem itemInt("ITEM2", sizeType , 100); + ParserItem itemInt("ITEM2", INT); RawRecord rawRecord( "*45 " ); BOOST_CHECK_THROW(itemInt.scan(rawRecord), std::invalid_argument); } BOOST_AUTO_TEST_CASE(Scan_MultipleItems_CorrectIntsSetInDeckItem) { - ParserItem itemInt1(std::string("ITEM1"), 0); - ParserItem itemInt2(std::string("ITEM2"), 0); + ParserItem itemInt1(std::string("ITEM1"), INT); + ParserItem itemInt2(std::string("ITEM2"), INT); RawRecord rawRecord( "10 20" ); const auto deckIntItem1 = itemInt1.scan(rawRecord); @@ -720,8 +727,8 @@ BOOST_AUTO_TEST_CASE(Scan_MultipleItems_CorrectIntsSetInDeckItem) { } BOOST_AUTO_TEST_CASE(Scan_MultipleDefault_CorrectIntsSetInDeckItem) { - ParserItem itemInt1("ITEM1", 10); - ParserItem itemInt2("ITEM2", 20); + ParserItem itemInt1("ITEM1", INT); itemInt1.setDefault(10); + ParserItem itemInt2("ITEM2", INT); itemInt2.setDefault(20); RawRecord rawRecord( "* * " ); const auto deckIntItem1 = itemInt1.scan(rawRecord); @@ -732,8 +739,8 @@ BOOST_AUTO_TEST_CASE(Scan_MultipleDefault_CorrectIntsSetInDeckItem) { } BOOST_AUTO_TEST_CASE(Scan_MultipleWithMultiplier_CorrectIntsSetInDeckItem) { - ParserItem itemInt1("ITEM1", 10); - ParserItem itemInt2("ITEM2", 20); + ParserItem itemInt1("ITEM1", INT); + ParserItem itemInt2("ITEM2", INT); RawRecord rawRecord( "2*30" ); const auto deckIntItem1 = itemInt1.scan(rawRecord); @@ -744,22 +751,22 @@ BOOST_AUTO_TEST_CASE(Scan_MultipleWithMultiplier_CorrectIntsSetInDeckItem) { } BOOST_AUTO_TEST_CASE(Scan_MalformedMultiplier_Throw) { - ParserItem itemInt1("ITEM1" , 10); + ParserItem itemInt1("ITEM1", INT); RawRecord rawRecord( "2.10*30" ); BOOST_CHECK_THROW(itemInt1.scan(rawRecord), std::invalid_argument); } BOOST_AUTO_TEST_CASE(Scan_MalformedMultiplierChar_Throw) { - ParserItem itemInt1("ITEM1", 10); + ParserItem itemInt1("ITEM1", INT); RawRecord rawRecord( "210X30" ); BOOST_CHECK_THROW(itemInt1.scan(rawRecord), std::invalid_argument); } BOOST_AUTO_TEST_CASE(Scan_MultipleWithMultiplierDefault_CorrectIntsSetInDeckItem) { - ParserItem itemInt1("ITEM1", 10); - ParserItem itemInt2("ITEM2", 20); + ParserItem itemInt1("ITEM1", INT); itemInt1.setDefault(10); + ParserItem itemInt2("ITEM2", INT); itemInt2.setDefault(20); RawRecord rawRecord( "2*" ); const auto deckIntItem1 = itemInt1.scan(rawRecord); @@ -770,7 +777,7 @@ BOOST_AUTO_TEST_CASE(Scan_MultipleWithMultiplierDefault_CorrectIntsSetInDeckItem } BOOST_AUTO_TEST_CASE(Scan_RawRecordErrorInRawData_ExceptionThrown) { - ParserItem itemInt(std::string("ITEM2"), 0); + ParserItem itemInt(std::string("ITEM2"), INT); // Wrong type RawRecord rawRecord2( "333.2 /" ); @@ -808,25 +815,22 @@ BOOST_AUTO_TEST_CASE(InitializeStringItem_FromJsonObject_withDefaultInvalid_thro /*****************************************************************/ BOOST_AUTO_TEST_CASE(init_defaultvalue_defaultset) { - ParserItem itemString(std::string("ITEM1") , "DEFAULT"); - RawRecord rawRecord( "'1*'" ); - BOOST_CHECK_EQUAL("1*", itemString.scan( rawRecord ).get< std::string >(0) ); + ParserItem itemString(std::string("ITEM1"), STRING); + RawRecord rawRecord0( "'1*'" ); + itemString.setDefault(std::string("DEFAULT")); + BOOST_CHECK_EQUAL("1*", itemString.scan( rawRecord0 ).get< std::string >(0) ); RawRecord rawRecord1( "13*" ); BOOST_CHECK_EQUAL("DEFAULT" , itemString.scan( rawRecord1 ).get< std::string >(0) ); RawRecord rawRecord2( "*" ); BOOST_CHECK_EQUAL("DEFAULT", itemString.scan( rawRecord2 ).get< std::string >(0) ); - - ParserItem itemStringDefaultChanged("ITEM2", "SPECIAL"); - RawRecord rawRecord3( "*" ); - BOOST_CHECK_EQUAL("SPECIAL", itemStringDefaultChanged.scan( rawRecord3 ).get< std::string >(0) ); } BOOST_AUTO_TEST_CASE(scan_all_valuesCorrect) { - auto sizeType = ParserItem::item_size::ALL; - ParserItem itemString("ITEMWITHMANY", sizeType, ""); + ParserItem itemString("ITEMWITHMANY", STRING); RawRecord rawRecord( "'WELL1' FISK BANAN 3*X OPPLEGG_FOR_DATAANALYSE 'Foo$*!% BAR' " ); + itemString.setSizeType( ParserItem::item_size::ALL ); const auto deckItem = itemString.scan(rawRecord); BOOST_CHECK_EQUAL(8U, deckItem.size()); @@ -841,9 +845,10 @@ BOOST_AUTO_TEST_CASE(scan_all_valuesCorrect) { } BOOST_AUTO_TEST_CASE(scan_all_withdefaults) { - auto sizeType = ParserItem::item_size::ALL; - ParserItem itemString("ITEMWITHMANY", sizeType, 0); + ParserItem itemString("ITEMWITHMANY", INT); RawRecord rawRecord( "10*1 10* 10*2 " ); + itemString.setDefault(0); + itemString.setSizeType( ParserItem::item_size::ALL ); const auto deckItem = itemString.scan(rawRecord); BOOST_CHECK_EQUAL(30U, deckItem.size()); @@ -865,7 +870,7 @@ BOOST_AUTO_TEST_CASE(scan_all_withdefaults) { } BOOST_AUTO_TEST_CASE(scan_single_dataCorrect) { - ParserItem itemString( "ITEM1", ""); + ParserItem itemString( "ITEM1", STRING); RawRecord rawRecord( "'WELL1' 'WELL2'" ); const auto deckItem = itemString.scan(rawRecord); BOOST_CHECK_EQUAL(1U, deckItem.size()); @@ -873,8 +878,8 @@ BOOST_AUTO_TEST_CASE(scan_single_dataCorrect) { } BOOST_AUTO_TEST_CASE(scan_singleWithMixedRecord_dataCorrect) { - ParserItem itemString("ITEM1", ""); - ParserItem itemInt("ITEM1", ""); + ParserItem itemString("ITEM1", STRING); + ParserItem itemInt("ITEM1", INT); RawRecord rawRecord( "2 'WELL1' /" ); itemInt.scan(rawRecord); @@ -886,13 +891,12 @@ BOOST_AUTO_TEST_CASE(scan_singleWithMixedRecord_dataCorrect) { BOOST_AUTO_TEST_CASE(scan_intsAndStrings_dataCorrect) { RawRecord rawRecord( "'WELL1' 2 2 2*3" ); - auto sizeTypeItemBoxed = ParserItem::item_size::ALL; - - ParserItem itemSingleString(std::string("ITEM1"), ""); + ParserItem itemSingleString(std::string("ITEM1"), STRING); const auto deckItemWell1 = itemSingleString.scan(rawRecord); BOOST_CHECK_EQUAL("WELL1", deckItemWell1.get< std::string >(0)); - ParserItem itemSomeInts("SOMEINTS", sizeTypeItemBoxed, 0 ); + ParserItem itemSomeInts("SOMEINTS", INT); + itemSomeInts.setSizeType( ParserItem::item_size::ALL ); const auto deckItemInts = itemSomeInts.scan(rawRecord); BOOST_CHECK_EQUAL(2, deckItemInts.get< int >(0)); BOOST_CHECK_EQUAL(2, deckItemInts.get< int >(1)); @@ -904,9 +908,9 @@ BOOST_AUTO_TEST_CASE(scan_intsAndStrings_dataCorrect) { BOOST_AUTO_TEST_CASE(ParserDefaultHasDimensionReturnsFalse) { - ParserItem intItem(std::string("SOMEINTS"), 0); - ParserItem stringItem(std::string("SOMESTRING"), ""); - ParserItem doubleItem(std::string("SOMEDOUBLE"), 0.0); + ParserItem intItem(std::string("SOMEINTS"), INT); + ParserItem stringItem(std::string("SOMESTRING"), STRING); + ParserItem doubleItem(std::string("SOMEDOUBLE"), DOUBLE); BOOST_CHECK( !intItem.hasDimension() ); BOOST_CHECK( !stringItem.hasDimension() ); @@ -914,7 +918,7 @@ BOOST_AUTO_TEST_CASE(ParserDefaultHasDimensionReturnsFalse) { } BOOST_AUTO_TEST_CASE(ParserIntItemGetDimensionThrows) { - ParserItem intItem(std::string("SOMEINT")); + ParserItem intItem(std::string("SOMEINT"), INT); BOOST_CHECK_THROW( intItem.getDimension(0) , std::invalid_argument ); BOOST_CHECK_THROW( intItem.push_backDimension("Length") , std::invalid_argument ); @@ -923,7 +927,7 @@ BOOST_AUTO_TEST_CASE(ParserIntItemGetDimensionThrows) { BOOST_AUTO_TEST_CASE(ParserDoubleItemAddMultipleDimensionToSIngleSizeThrows) { - ParserItem doubleItem(std::string("SOMEDOUBLE"), 0.0); + ParserItem doubleItem(std::string("SOMEDOUBLE"), DOUBLE); doubleItem.push_backDimension("Length*Length"); BOOST_CHECK_THROW( doubleItem.push_backDimension("Length*Length"), std::invalid_argument); @@ -931,7 +935,7 @@ BOOST_AUTO_TEST_CASE(ParserDoubleItemAddMultipleDimensionToSIngleSizeThrows) { BOOST_AUTO_TEST_CASE(ParserDoubleItemWithDimensionHasReturnsCorrect) { - ParserItem doubleItem("SOMEDOUBLE", 0.0); + ParserItem doubleItem("SOMEDOUBLE", DOUBLE); BOOST_CHECK( !doubleItem.hasDimension() ); doubleItem.push_backDimension("Length*Length"); @@ -939,7 +943,9 @@ BOOST_AUTO_TEST_CASE(ParserDoubleItemWithDimensionHasReturnsCorrect) { } BOOST_AUTO_TEST_CASE(ParserDoubleItemGetDimension) { - ParserItem doubleItem( "SOMEDOUBLE" , ParserItem::item_size::ALL, 0.0 ); + ParserItem doubleItem( "SOMEDOUBLE", DOUBLE); + doubleItem.setSizeType( ParserItem::item_size::ALL ); + doubleItem.setDefault(0.0); BOOST_CHECK_THROW( doubleItem.getDimension( 10 ) , std::out_of_range ); BOOST_CHECK_THROW( doubleItem.getDimension( 0 ) , std::out_of_range ); @@ -967,14 +973,14 @@ BOOST_AUTO_TEST_CASE(Size_NoElements_ReturnsZero) { } BOOST_AUTO_TEST_CASE(Size_OneItem_Return1) { - ParserItem itemInt("ITEM1", SINGLE ); + ParserItem itemInt("ITEM1", INT); ParserRecord record; record.addItem(itemInt); BOOST_CHECK_EQUAL(1U, record.size()); } BOOST_AUTO_TEST_CASE(Get_OneItem_Return1) { - ParserItem itemInt("ITEM1", SINGLE); + ParserItem itemInt("ITEM1", INT); ParserRecord record; record.addItem(itemInt); @@ -991,14 +997,14 @@ BOOST_AUTO_TEST_CASE(Get_KeyNotFound_Throw) { } BOOST_AUTO_TEST_CASE(Get_KeyFound_OK) { - ParserItem itemInt("ITEM1", SINGLE ); + ParserItem itemInt("ITEM1", INT); ParserRecord record; record.addItem(itemInt); BOOST_CHECK_EQUAL(record.get("ITEM1"), itemInt); } BOOST_AUTO_TEST_CASE(Get_GetByNameAndIndex_OK) { - ParserItem itemInt("ITEM1", SINGLE); + ParserItem itemInt("ITEM1", INT); ParserRecord record; record.addItem(itemInt); @@ -1009,16 +1015,16 @@ BOOST_AUTO_TEST_CASE(Get_GetByNameAndIndex_OK) { } BOOST_AUTO_TEST_CASE(addItem_SameName_Throw) { - ParserItem itemInt1("ITEM1", SINGLE); - ParserItem itemInt2("ITEM1", SINGLE); + ParserItem itemInt1("ITEM1", INT); + ParserItem itemInt2("ITEM1", INT); ParserRecord record; record.addItem(itemInt1); BOOST_CHECK_THROW(record.addItem(itemInt2), std::invalid_argument); } static ParserRecord createSimpleParserRecord() { - ParserItem itemInt1("ITEM1", SINGLE, 0 ); - ParserItem itemInt2("ITEM2", SINGLE, 0 ); + ParserItem itemInt1("ITEM1", INT); + ParserItem itemInt2("ITEM2", INT); ParserRecord record; record.addItem(itemInt1); @@ -1047,14 +1053,12 @@ BOOST_AUTO_TEST_CASE(parse_validRecord_deckRecordCreated) { // INT INT DOUBLE DOUBLE INT DOUBLE static ParserRecord createMixedParserRecord() { - - auto sizeType = SINGLE; - ParserItem itemInt1( "INTITEM1", sizeType, 0 ); - ParserItem itemInt2( "INTITEM2", sizeType, 0 ); - ParserItem itemInt3( "INTITEM3", sizeType, 0 ); - ParserItem itemDouble1( "DOUBLEITEM1", sizeType, 0.0 ); - ParserItem itemDouble2( "DOUBLEITEM2", sizeType, 0.0 ); - ParserItem itemDouble3( "DOUBLEITEM3", sizeType, 0.0 ); + ParserItem itemInt1( "INTITEM1", INT); + ParserItem itemInt2( "INTITEM2", INT); + ParserItem itemInt3( "INTITEM3", INT); + ParserItem itemDouble1( "DOUBLEITEM1", DOUBLE); + ParserItem itemDouble2( "DOUBLEITEM2", DOUBLE); + ParserItem itemDouble3( "DOUBLEITEM3", DOUBLE); ParserRecord record; record.addItem(itemInt1); @@ -1084,10 +1088,9 @@ BOOST_AUTO_TEST_CASE(Equal_Equal_ReturnsTrue) { } BOOST_AUTO_TEST_CASE(Equal_Different_ReturnsFalse) { - auto sizeType = SINGLE; - ParserItem itemInt( "INTITEM1", sizeType, 0 ); - ParserItem itemDouble( "DOUBLEITEM1", sizeType, 0.0 ); - ParserItem itemString( "STRINGITEM1", sizeType, "" ); + ParserItem itemInt( "INTITEM1", INT); + ParserItem itemDouble( "DOUBLEITEM1", DOUBLE); + ParserItem itemString( "STRINGITEM1", STRING); ParserRecord record1; ParserRecord record2; ParserRecord record3; @@ -1108,9 +1111,9 @@ BOOST_AUTO_TEST_CASE(Equal_Different_ReturnsFalse) { BOOST_AUTO_TEST_CASE(ParseWithDefault_defaultAppliedCorrectInDeck) { ParserRecord parserRecord; - ParserItem itemInt("ITEM1", SINGLE , 100 ); - ParserItem itemString("ITEM2", SINGLE , "DEFAULT" ); - ParserItem itemDouble("ITEM3", SINGLE , 3.14 ); + ParserItem itemInt("ITEM1", INT); itemInt.setDefault(100); + ParserItem itemString("ITEM2", STRING); itemString.setDefault(std::string("DEFAULT")); + ParserItem itemDouble("ITEM3", DOUBLE); itemDouble.setDefault(3.14); parserRecord.addItem(itemInt); parserRecord.addItem(itemString); @@ -1201,9 +1204,9 @@ BOOST_AUTO_TEST_CASE(ParseWithDefault_defaultAppliedCorrectInDeck) { BOOST_AUTO_TEST_CASE(Parse_RawRecordTooManyItems_Throws) { ParserRecord parserRecord; - ParserItem itemI( "I", SINGLE, 0 ); - ParserItem itemJ( "J", SINGLE, 0 ); - ParserItem itemK( "K", SINGLE, 0 ); + ParserItem itemI( "I", INT); + ParserItem itemJ( "J", INT); + ParserItem itemK( "K", INT); ParseContext parseContext; ErrorGuard errors; @@ -1227,12 +1230,9 @@ BOOST_AUTO_TEST_CASE(Parse_RawRecordTooManyItems_Throws) { BOOST_AUTO_TEST_CASE(Parse_RawRecordTooFewItems) { ParserRecord parserRecord; - ParserItem itemI( "I", SINGLE ); - ParserItem itemJ( "J", SINGLE ); - ParserItem itemK( "K", SINGLE ); - itemI.setType( int() ); - itemJ.setType( int() ); - itemK.setType( int() ); + ParserItem itemI( "I" , INT); + ParserItem itemJ( "J" , INT); + ParserItem itemK( "K" , INT); parserRecord.addItem(itemI); parserRecord.addItem(itemJ); @@ -1253,14 +1253,14 @@ BOOST_AUTO_TEST_CASE(Parse_RawRecordTooFewItems) { BOOST_AUTO_TEST_CASE(ParseRecordHasDimensionCorrect) { ParserRecord parserRecord; - ParserItem itemI( "I", SINGLE, 0.0 ); + ParserItem itemI( "I", INT); BOOST_CHECK( !parserRecord.hasDimension() ); parserRecord.addItem( itemI ); BOOST_CHECK( !parserRecord.hasDimension() ); - ParserItem item2( "ID", SINGLE, 0.0 ); + ParserItem item2( "ID", DOUBLE); item2.push_backDimension("Length*Length/Time"); parserRecord.addItem( item2 ); BOOST_CHECK( parserRecord.hasDimension() ); @@ -1274,8 +1274,8 @@ BOOST_AUTO_TEST_CASE(DefaultNotDataRecord) { BOOST_AUTO_TEST_CASE(MixingDataAndItems_throws1) { ParserRecord record; - ParserItem dataItem( "ACTNUM" , ALL ); - ParserItem item ( "XXX" , ALL ); + ParserItem dataItem( "ACTNUM", INT); + ParserItem item ( "XXX", INT); record.addDataItem( dataItem ); BOOST_CHECK_THROW( record.addItem( item ) , std::invalid_argument); BOOST_CHECK_THROW( record.addItem( dataItem ) , std::invalid_argument); @@ -1283,8 +1283,8 @@ BOOST_AUTO_TEST_CASE(MixingDataAndItems_throws1) { BOOST_AUTO_TEST_CASE(MixingDataAndItems_throws2) { ParserRecord record; - ParserItem dataItem( "ACTNUM" , ALL); - ParserItem item ( "XXX" , ALL); + ParserItem dataItem( "ACTNUM", INT); + ParserItem item ( "XXX", INT); record.addItem( item ); BOOST_CHECK_THROW( record.addDataItem( dataItem ) , std::invalid_argument); @@ -1370,7 +1370,7 @@ BOOST_AUTO_TEST_CASE(ParserKeywordMatches) { BOOST_AUTO_TEST_CASE(AddDataKeyword_correctlyConfigured) { const auto& parserKeyword = createFixedSized("PORO", (size_t) 1); - ParserItem item( "ACTNUM" , ParserItem::item_size::ALL, 0 ); + ParserItem item( "ACTNUM", INT); ParserRecord record; BOOST_CHECK( !parserKeyword->isDataKeyword() ); @@ -1384,7 +1384,7 @@ BOOST_AUTO_TEST_CASE(AddDataKeyword_correctlyConfigured) { BOOST_AUTO_TEST_CASE(WrongConstructor_addDataItem_throws) { const auto& parserKeyword = createDynamicSized("PORO"); - ParserItem dataItem( "ACTNUM" , ParserItem::item_size::ALL ); + ParserItem dataItem( "ACTNUM", INT); ParserRecord record; record.addDataItem( dataItem ); BOOST_CHECK_THROW( parserKeyword->addDataRecord( record ) , std::invalid_argument); @@ -1617,8 +1617,7 @@ BOOST_AUTO_TEST_CASE(ConstructorIsTableCollection) { BOOST_AUTO_TEST_CASE(ParseEmptyRecord) { const auto& tabdimsKeyword = createFixedSized("TEST" , 1); ParserRecord record; - ParserItem item("ITEM", ParserItem::item_size::ALL ); - item.setType( int() ); + ParserItem item("ITEM", INT); auto rawkeyword = std::make_shared< RawKeyword >( tabdimsKeyword->getName() , "FILE" , 10U , 1 ); ParseContext parseContext; ErrorGuard errors; @@ -1643,8 +1642,8 @@ BOOST_AUTO_TEST_CASE(ParseEmptyRecord) { /* Dimension */ BOOST_AUTO_TEST_CASE(ParseKeywordHasDimensionCorrect) { const auto& parserKeyword = createDynamicSized("JA"); - ParserItem item1("I", ParserItem::item_size::SINGLE, 0 ); - ParserItem item2("ID", ParserItem::item_size::SINGLE, 0.0 ); + ParserItem item1("I", DOUBLE); + ParserItem item2("ID", DOUBLE); ParserRecord record; BOOST_CHECK( !parserKeyword->hasDimension()); diff --git a/tests/parser/integration/IntegrationTests.cpp b/tests/parser/integration/IntegrationTests.cpp index a315a22d1..4b3262589 100644 --- a/tests/parser/integration/IntegrationTests.cpp +++ b/tests/parser/integration/IntegrationTests.cpp @@ -56,7 +56,9 @@ Parser createWWCTParser() { auto parserKeyword = createDynamicSized("WWCT"); ParserRecord record; - record.addItem( ParserItem("WELL", ParserItem::item_size::ALL, "") ); + ParserItem item("WELL", ParserItem::itype::STRING); + item.setSizeType(ParserItem::item_size::ALL); + record.addItem(item); parserKeyword->addRecord( record ); auto summaryKeyword = createFixedSized("SUMMARY" , (size_t) 0); @@ -142,9 +144,9 @@ static Parser createBPRParser() { auto parserKeyword = createDynamicSized("BPR"); { ParserRecord bprRecord; - bprRecord.addItem( ParserItem("I", ParserItem::item_size::SINGLE, 0) ); - bprRecord.addItem( ParserItem("J", ParserItem::item_size::SINGLE, 0) ); - bprRecord.addItem( ParserItem("K", ParserItem::item_size::SINGLE, 0) ); + bprRecord.addItem( ParserItem("I", ParserItem::itype::INT) ); + bprRecord.addItem( ParserItem("J", ParserItem::itype::INT) ); + bprRecord.addItem( ParserItem("K", ParserItem::itype::INT) ); parserKeyword->addRecord( bprRecord ); } auto summaryKeyword = createFixedSized("SUMMARY" , (size_t) 0);