From 670520da7a20f95632d37ad5121f8a94f7397b64 Mon Sep 17 00:00:00 2001 From: Valentin Noel Date: Tue, 10 Sep 2013 18:29:32 +0200 Subject: [PATCH] add modifications for error and warning labels into Element class (and unit tests) issue #27 --- libraries/basicElement/src/Element.cpp | 31 +++++++++++++++++ libraries/basicElement/src/Element.hpp | 8 +++++ .../basicElement/tests/element/dataTests.hpp | 33 +++++++++++++++++++ 3 files changed, 72 insertions(+) diff --git a/libraries/basicElement/src/Element.cpp b/libraries/basicElement/src/Element.cpp index 6b34dfa..39a81d5 100644 --- a/libraries/basicElement/src/Element.cpp +++ b/libraries/basicElement/src/Element.cpp @@ -11,6 +11,8 @@ Element::Element( EType type ) , _uniqueId ( _lastUniqueId++ ) , _status ( eStatusUnknown ) , _subType ( 0 ) + , _error ( "" ) + , _warning ( "" ) , _bigEndianData ( true ) { } @@ -73,12 +75,40 @@ void Element::reverseEndianness( char* buffer, const char* data ) const std::reverse_copy( data, data + _size, buffer ); } + +void Element::addErrorLabel( const std::string& error ) +{ + _status = Element::eStatusInvalid; + _error += error; +} + +void Element::addWarningLabel( const std::string& warning ) +{ + _warning += warning; +} + +std::string Element::getErrorLabel() +{ + return _error; +} + +std::string Element::getWarningLabel() +{ + return _warning; +} + std::vector< std::pair< std::string, std::string > > Element::getCommonElementInfo() { std::vector< std::pair< std::string, std::string > > commonInfo; commonInfo.push_back( std::make_pair( "id", getId() ) ); commonInfo.push_back( std::make_pair( "label", getLabel() ) ); commonInfo.push_back( std::make_pair( "status", getStatusString() ) ); + + if( ! _error.empty() ) + commonInfo.push_back( std::make_pair( "error", _error ) ); + if( ! _warning.empty() ) + commonInfo.push_back( std::make_pair( "warning", _warning ) ); + return commonInfo; } @@ -95,4 +125,5 @@ std::string Element::getStatusString() return status; } + } diff --git a/libraries/basicElement/src/Element.hpp b/libraries/basicElement/src/Element.hpp index 46f3c01..270fafe 100644 --- a/libraries/basicElement/src/Element.hpp +++ b/libraries/basicElement/src/Element.hpp @@ -47,10 +47,16 @@ class Element void getEndianOrderedData( char* buffer, const char* data ) const; void reverseEndianness ( char* buffer, const char* data ) const; + void addErrorLabel( const std::string& error ); + void addWarningLabel( const std::string& warning ); + std::string getErrorLabel(); + std::string getWarningLabel(); + protected: std::vector< std::pair< std::string, std::string > > getCommonElementInfo(); std::string getStatusString(); + public: virtual void setData( const char* data, const size_t& size ) = 0; @@ -70,6 +76,8 @@ class Element EStatus _status; int _subType; size_t _size; + std::string _error; + std::string _warning; bool _bigEndianData; }; diff --git a/libraries/basicElement/tests/element/dataTests.hpp b/libraries/basicElement/tests/element/dataTests.hpp index 73e34eb..be66124 100644 --- a/libraries/basicElement/tests/element/dataTests.hpp +++ b/libraries/basicElement/tests/element/dataTests.hpp @@ -258,4 +258,37 @@ BOOST_AUTO_TEST_CASE( basic_element_data_subType ) } } +BOOST_AUTO_TEST_CASE( basic_element_data_error_warning ) +{ + LOG_INFO( "\n>>> basic_element_data_error_warning <<<" ); + { + dbe::Data data( eDataTypeUnknown ); + std::string error = "error"; + data.addErrorLabel( error ); + BOOST_CHECK_EQUAL( data.getErrorLabel(), error ); + BOOST_CHECK_EQUAL( data.getStatus(), be::Element::eStatusInvalid ); + } + { + dbe::Data data( eDataTypeUnknown ); + std::string error = "error"; + data.addErrorLabel( error ); + data.addErrorLabel( error ); + BOOST_CHECK_EQUAL( data.getErrorLabel(), "errorerror" ); + BOOST_CHECK_EQUAL( data.getStatus(), be::Element::eStatusInvalid ); + } + { + dbe::Data data( eDataTypeUnknown ); + std::string warning = "warning"; + data.addWarningLabel( warning ); + BOOST_CHECK_EQUAL( data.getWarningLabel(), warning ); + } + { + dbe::Data data( eDataTypeUnknown ); + std::string warning = "warning"; + data.addWarningLabel( warning ); + data.addWarningLabel( warning ); + BOOST_CHECK_EQUAL( data.getWarningLabel(), "warningwarning" ); + } +} + BOOST_AUTO_TEST_SUITE_END()