Skip to content

Commit

Permalink
add modifications for error and warning labels into Element class (an…
Browse files Browse the repository at this point in the history
…d unit tests)

issue #27
  • Loading branch information
Valentin Noel committed Sep 10, 2013
1 parent 8cd0511 commit 670520d
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
31 changes: 31 additions & 0 deletions libraries/basicElement/src/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Element::Element( EType type )
, _uniqueId ( _lastUniqueId++ )
, _status ( eStatusUnknown )
, _subType ( 0 )
, _error ( "" )
, _warning ( "" )
, _bigEndianData ( true )
{
}
Expand Down Expand Up @@ -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;
}

Expand All @@ -95,4 +125,5 @@ std::string Element::getStatusString()
return status;
}


}
8 changes: 8 additions & 0 deletions libraries/basicElement/src/Element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -70,6 +76,8 @@ class Element
EStatus _status;
int _subType;
size_t _size;
std::string _error;
std::string _warning;
bool _bigEndianData;
};

Expand Down
33 changes: 33 additions & 0 deletions libraries/basicElement/tests/element/dataTests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 670520d

Please sign in to comment.