Skip to content

Commit

Permalink
modifications in Checker after removing Element _size attribute
Browse files Browse the repository at this point in the history
issue #33
  • Loading branch information
Valentin Noel committed Dec 10, 2013
1 parent a326d02 commit 3e89296
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 17 deletions.
46 changes: 39 additions & 7 deletions libraries/ElementChecker/src/ElementChecker/Checker/Checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Checker::Checker()

void Checker::check( const ShPtrElement element )
{
if( element->_size == 0 && element->_countExpr.empty() )
if( element->_data.size() == 0 && element->_countExpr.empty() )
{
std::string warning = "Null data size ";
// LOG_WARNING( "[checker] " << element->_id << ": " << warning );
Expand Down Expand Up @@ -191,14 +191,46 @@ void Checker::check( const ShPtrElement element )

size_t Checker::getSize( const ShPtrElement element )
{
if( element->_type == eTypeHexa )
element->_size = element->_size >> 1;
if( ! element->_countExpr.empty() && element->_size == 0 )
size_t size = 0;
try
{
element->_size = _exprParser->getExpressionResult< size_t >( element->_countExpr );
LOG_TRACE( "[checker] get " << element->_id << "'s size: " << element->_size );
if( ! element->_values.empty() )
{
size = element->_values.at( 0 ).size();
for( std::string value : element->_values )
if( value.size() != size )
throw std::runtime_error( "[checker] Values must have the same size (" + element->_id + ")" );
}

switch( element->_type )
{
case eTypeHexa : size = size >> 1; break;
case eTypeInt8 :
case eTypeUInt8 : return 1;
case eTypeInt16 :
case eTypeUInt16 : return 2;
case eTypeInt32 :
case eTypeUInt32 :
case eTypeFloat : return 4;
case eTypeInt64 :
case eTypeUInt64 :
case eTypeDouble : return 8;
case eTypeIeeeExtended : return 10;
default: break;
}

if( ! element->_countExpr.empty() && size == 0 )
{
size = _exprParser->getExpressionResult< size_t >( element->_countExpr );
LOG_TRACE( "[checker] get " << element->_id << "'s size: " << size );
}
return size;
}
catch( std::runtime_error e )
{
LOG_ERROR( "[checker] " << e.what() << " (" << element->_id << ")" );
}
return element->_size;
return size;
}

bool Checker::isIterationValid( const ShPtrElement element, std::string& errorMessage )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ std::string Translator::get< std::string >() // get ascii character !
template< typename NumberType >
std::vector< NumberType > Translator::convertToVector()
{
if( _ref->_size % sizeof( NumberType ) != 0 )
if( _ref->_data.size() % sizeof( NumberType ) != 0 )
throw std::runtime_error( "invalid data size" );

std::vector< NumberType > vector;
Expand All @@ -74,7 +74,7 @@ std::vector< NumberType > Translator::convertToVector()
else
std::memcpy( buffer, &_ref->_data[0], _ref->_data.size() );

std::memcpy( num.data, &buffer[i], _ref->_size );
std::memcpy( num.data, &buffer[i], _ref->_data.size() );
delete[] buffer;
vector.push_back( num.value );
}
Expand Down
16 changes: 8 additions & 8 deletions libraries/ElementChecker/test/checkerTestCount.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,24 @@ BOOST_AUTO_TEST_CASE( element_checker_checker_count )

std::shared_ptr< basic_element::Element > elem1( new basic_element::Element( node ) );
BOOST_CHECK_EQUAL( elem1->_status, eStatusNotChecked );
BOOST_CHECK_EQUAL( elem1->_size, 4 );
BOOST_CHECK_EQUAL( checker.getSize( elem1 ), 4 );
elem1->set( (const char*)&buff1, checker.getSize( elem1 ) );
BOOST_CHECK_EQUAL( elem1->_data.size(), 4 );
checker.check( elem1 );
BOOST_CHECK_EQUAL( elem1->_status, eStatusPassOver );

std::shared_ptr< basic_element::Element > elem2( new basic_element::Element( elem1->next(), elem1 ) );
BOOST_CHECK_EQUAL( elem2->_size, 0 );
BOOST_CHECK_EQUAL( elem2->_data.size(), 0 );
BOOST_CHECK_EQUAL( checker.getSize( elem2 ), 5 );
elem2->set( (const char*)&buff2, checker.getSize( elem2 ) );
checker.check( elem2 );
BOOST_CHECK_EQUAL( elem2->_size, 5 );
BOOST_CHECK_EQUAL( elem2->_data.size(), 5 );
BOOST_CHECK_EQUAL( elem2->_status, eStatusPassOver );

std::shared_ptr< basic_element::Element > elem3( new basic_element::Element( elem2->next(), elem2 ) );
BOOST_CHECK_EQUAL( elem3->_size, 5 );
BOOST_CHECK_EQUAL( checker.getSize( elem3 ), 5 );
elem3->set( (const char*)&buff3, checker.getSize( elem3 ) );
BOOST_CHECK_EQUAL( elem3->_data.size(), 5 );
checker.check( elem3 );
BOOST_CHECK_EQUAL( elem3->_status, eStatusValid );

Expand All @@ -88,24 +88,24 @@ BOOST_AUTO_TEST_CASE( element_checker_checker_count )

std::shared_ptr< basic_element::Element > elem1( new basic_element::Element( node ) );
BOOST_CHECK_EQUAL( elem1->_status, eStatusNotChecked );
BOOST_CHECK_EQUAL( elem1->_size, 4 );
BOOST_CHECK_EQUAL( checker.getSize( elem1 ), 4 );
elem1->set( (const char*)&buff1, checker.getSize( elem1 ) );
BOOST_CHECK_EQUAL( elem1->_data.size(), 4 );
checker.check( elem1 );
BOOST_CHECK_EQUAL( elem1->_status, eStatusPassOver );

std::shared_ptr< basic_element::Element > elem2( new basic_element::Element( elem1->next(), elem1 ) );
BOOST_CHECK_EQUAL( elem2->_size, 0 );
BOOST_CHECK_EQUAL( elem2->_data.size(), 0 );
BOOST_CHECK_EQUAL( checker.getSize( elem2 ), 3 );
elem2->set( (const char*)&buff2, checker.getSize( elem2 ) );
checker.check( elem2 );
BOOST_CHECK_EQUAL( elem2->_size, 3 );
BOOST_CHECK_EQUAL( elem2->_data.size(), 3 );
BOOST_CHECK_EQUAL( elem2->_status, eStatusPassOver );

std::shared_ptr< basic_element::Element > elem3( new basic_element::Element( elem2->next(), elem2 ) );
BOOST_CHECK_EQUAL( elem3->_size, 5 );
BOOST_CHECK_EQUAL( checker.getSize( elem3 ), 5 );
elem3->set( (const char*)&buff3, checker.getSize( elem3 ) );
BOOST_CHECK_EQUAL( elem3->_data.size(), 5 );
checker.check( elem3 );
BOOST_CHECK_EQUAL( elem3->_status, eStatusValid );

Expand Down

0 comments on commit 3e89296

Please sign in to comment.