Skip to content

Commit

Permalink
modifications in Checker after status update (and unit tests)
Browse files Browse the repository at this point in the history
issue #33
  • Loading branch information
Valentin Noel committed Dec 10, 2013
1 parent 607537c commit 9318119
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 71 deletions.
20 changes: 8 additions & 12 deletions libraries/ElementChecker/src/ElementChecker/Checker/Checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ namespace utils

element->_mapValue = Map< NumberType >( element->_map ).getLabel( value );

if( element->_rangeExpr.empty() )
return eStatusPassOver;
if( Ranges< NumberType >( element->_rangeExpr ).isInRanges( value ) )
return eStatusValid;
return eStatusInvalid;
if( ! Ranges< NumberType >( element->_rangeExpr ).isInRanges( value ) )
return eStatusInvalid;
return eStatusValid;
}
}

Expand All @@ -48,7 +46,7 @@ void Checker::check( const ShPtrElement element )

switch( element->_type )
{
case eTypeUnknown : LOG_ERROR( "[checker] Unknown element type, cannot check it" ); break;
case eTypeUnknown : status = eStatusUnknown; break;

case eTypeInt8 : status = utils::checkNumberElement< be::int8 >( element ); break;
case eTypeUInt8 : status = utils::checkNumberElement< be::uint8 >( element ); break;
Expand Down Expand Up @@ -77,9 +75,8 @@ void Checker::check( const ShPtrElement element )
if( element->_mapValue.empty() && ! element->_isCaseSensitive )
element->_mapValue = Map< std::string >( element->_map ).getLabel( lowCase );

if( ( element->_values.empty() && ! element->_mapValue.empty() ) ||
( element->_values.empty() && element->_mapValue.empty() && element->_map.empty() ) )
status = eStatusPassOver;
if( element->_values.empty() && ! element->_mapValue.empty() && getSize( element ) )
status = eStatusValid;

if( status == eStatusInvalid )
element->_error.push_back( "[checker] Invalid value " );
Expand All @@ -88,7 +85,7 @@ void Checker::check( const ShPtrElement element )

case eTypeRaw :
{
status = eStatusPassOver;
status = eStatusUnknown;
break;
}
}
Expand Down Expand Up @@ -133,8 +130,7 @@ void Checker::check( const ShPtrElement element )
switch( status )
{
case eStatusValid :
case eStatusInvalid :
case eStatusPassOver : _exprParser->addElementToContext( element ); break;
case eStatusInvalid : _exprParser->addElementToContext( element ); break;
default : break;
}

Expand Down
3 changes: 3 additions & 0 deletions libraries/ElementChecker/src/ElementChecker/Ranges/Ranges.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class Ranges

bool isInRanges( const ValueType& value )
{
if( ! _ranges.size() )
return true;

for( Range< ValueType > range : _ranges )
{
if( range.isInRange( value ) )
Expand Down
29 changes: 14 additions & 15 deletions libraries/ElementChecker/test/checkerTest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ BOOST_AUTO_TEST_CASE( element_checker_checker_data )
)*";

Checker checker;
{
spec_reader::Specification spec;
spec.setFromString( jsonStringBegin + jsonStringEnd );
std::shared_ptr< spec_reader::SpecNode > node = spec.getFirstNode();
// {
// spec_reader::Specification spec;
// spec.setFromString( jsonStringBegin + jsonStringEnd );
// std::shared_ptr< spec_reader::SpecNode > node = spec.getFirstNode();

std::shared_ptr< basic_element::Element > elem( new basic_element::Element( node ) );
// std::shared_ptr< basic_element::Element > elem( new basic_element::Element( node ) );

std::vector< char > buff { 'W', 'A', 'V', 'E' };
elem->set( buff, 4 );

checker.check( elem );
BOOST_CHECK_EQUAL( elem->_status, eStatusPassOver );
BOOST_CHECK( node->next() == nullptr );
BOOST_CHECK( elem->next() == nullptr );
}
// std::vector< char > buff { 'W', 'A', 'V', 'E' };
// elem->set( buff, 4 );

// checker.check( elem );
// BOOST_CHECK_EQUAL( elem->_status, eStatusPassOver ); // @todo: support WORD types (end char = null)
// BOOST_CHECK( node->next() == nullptr );
// BOOST_CHECK( elem->next() == nullptr );
// }
{
spec_reader::Specification spec;
spec.setFromString( jsonStringBegin + R"*( ,"values": "WAVE" )*" + jsonStringEnd );
Expand Down Expand Up @@ -116,9 +116,8 @@ BOOST_AUTO_TEST_CASE( element_checker_checker_number )

checker.check( elem );
BOOST_CHECK_EQUAL( elem->_type, eTypeUInt32 );
BOOST_CHECK_EQUAL( elem->_status, eStatusPassOver );
BOOST_CHECK_EQUAL( elem->_status, eStatusValid );
}

{
spec_reader::Specification spec;
spec.setFromString( jsonStringBegin + R"*( ,"range": [ { "min": "1", "max": "10" } ] )*" + jsonStringEnd );
Expand Down
12 changes: 6 additions & 6 deletions libraries/ElementChecker/test/checkerTestCount.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ BOOST_AUTO_TEST_CASE( element_checker_checker_count )
Checker checker;

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

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

std::shared_ptr< basic_element::Element > elem3( new basic_element::Element( elem2->next(), elem2 ) );
BOOST_CHECK_EQUAL( checker.getSize( elem3 ), 5 );
Expand All @@ -87,20 +87,20 @@ BOOST_AUTO_TEST_CASE( element_checker_checker_count )
Checker checker;

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

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

std::shared_ptr< basic_element::Element > elem3( new basic_element::Element( elem2->next(), elem2 ) );
BOOST_CHECK_EQUAL( checker.getSize( elem3 ), 5 );
Expand Down
6 changes: 3 additions & 3 deletions libraries/ElementChecker/test/checkerTestDisplayType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@ BOOST_AUTO_TEST_CASE( element_checker_test_checker_display_type )
BOOST_CHECK_EQUAL( elem1->_displayType, eDisplayTypeAscii );
elem1->set( buff1, checker.getSize( elem1 ) );
checker.check( elem1 );
BOOST_CHECK_EQUAL( elem1->_status, eStatusPassOver );
BOOST_CHECK_EQUAL( elem1->_status, eStatusUnknown );
BOOST_CHECK_EQUAL( elem1->_dispValue, "WAVE1" );

std::shared_ptr< basic_element::Element > elem2( new basic_element::Element( elem1->next(), elem1 ) );
BOOST_CHECK_EQUAL( elem2->_id, node->next()->getId() );
BOOST_CHECK_EQUAL( elem2->_displayType, eDisplayTypeNumbers );
elem2->set( buff2, checker.getSize( elem2 ) );
checker.check( elem2 );
BOOST_CHECK_EQUAL( elem2->_status, eStatusPassOver );
BOOST_CHECK_EQUAL( elem2->_status, eStatusUnknown );
BOOST_CHECK_EQUAL( elem2->_dispValue, "8765866950" );

std::shared_ptr< basic_element::Element > elem3( new basic_element::Element( elem2->next(), elem2 ) );
BOOST_CHECK_EQUAL( elem3->_id, node->next()->next()->getId() );
BOOST_CHECK_EQUAL( elem3->_displayType, eDisplayTypeDefault );
elem3->set( buff3, checker.getSize( elem3 ) );
checker.check( elem3 );
BOOST_CHECK_EQUAL( elem3->_status, eStatusPassOver );
BOOST_CHECK_EQUAL( elem3->_status, eStatusUnknown );
BOOST_CHECK_EQUAL( elem3->_dispValue, "WAV" );

std::shared_ptr< basic_element::Element > elem4( new basic_element::Element( elem3->next(), elem3 ) );
Expand Down
6 changes: 3 additions & 3 deletions libraries/ElementChecker/test/checkerTestGroupSize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ BOOST_AUTO_TEST_CASE( element_checker_checker_groupSize )
BOOST_CHECK_EQUAL( elem1->_id, node->getId() );
elem1->set( buff1, checker.getSize( elem1 ) );
checker.check( elem1 );
BOOST_CHECK_EQUAL( elem1->_status, eStatusPassOver );
BOOST_CHECK_EQUAL( elem1->_status, eStatusValid );

std::shared_ptr< basic_element::Element > elem2( new basic_element::Element( elem1->next(), elem1 ) );
BOOST_CHECK_EQUAL( elem2->_id, node->next()->getId() );
Expand Down Expand Up @@ -141,7 +141,7 @@ BOOST_AUTO_TEST_CASE( element_checker_checker_groupSize_2 )
BOOST_CHECK_EQUAL( elem3->_id, node->next()->firstChild()->getId() );
elem3->set( buff4, checker.getSize( elem3 ) );
checker.check( elem3 );
BOOST_CHECK_EQUAL( elem3->_status, eStatusPassOver );
BOOST_CHECK_EQUAL( elem3->_status, eStatusValid );
BOOST_CHECK_EQUAL( elem3->_dispValue, "14" );

std::shared_ptr< basic_element::Element > elem4( new basic_element::Element( elem3->next(), elem3, elem2 ) );
Expand Down Expand Up @@ -217,7 +217,7 @@ BOOST_AUTO_TEST_CASE( element_checker_checker_groupSize_3 )
BOOST_CHECK_EQUAL( elem3->_id, node->next()->firstChild()->getId() );
elem3->set( buff4, checker.getSize( elem3 ) );
checker.check( elem3 );
BOOST_CHECK_EQUAL( elem3->_status, eStatusPassOver );
BOOST_CHECK_EQUAL( elem3->_status, eStatusValid );
BOOST_CHECK_EQUAL( elem3->_dispValue, "4" );

std::shared_ptr< basic_element::Element > elem4( new basic_element::Element( elem3->next(), elem3 ) );
Expand Down
14 changes: 7 additions & 7 deletions libraries/ElementChecker/test/checkerTestMap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ BOOST_AUTO_TEST_CASE( element_checker_test_checker_map )
BOOST_CHECK( ! elem2->_map.empty() );
elem2->set( buff2, checker.getSize( elem2 ) );
checker.check( elem2 );
BOOST_CHECK_EQUAL( elem2->_status, eStatusPassOver );
BOOST_CHECK_EQUAL( elem2->_status, eStatusValid );
BOOST_CHECK_EQUAL( elem2->_mapValue, "First Label" );

std::shared_ptr< basic_element::Element > elem3( new basic_element::Element( elem2->next(), elem2 ) );
Expand Down Expand Up @@ -74,7 +74,7 @@ BOOST_AUTO_TEST_CASE( element_checker_test_checker_map )
BOOST_CHECK( ! elem2->_map.empty() );
elem2->set( buff2, checker.getSize( elem2 ) );
checker.check( elem2 );
BOOST_CHECK_EQUAL( elem2->_status, eStatusPassOver );
BOOST_CHECK_EQUAL( elem2->_status, eStatusValid );
BOOST_CHECK_EQUAL( elem2->_mapValue, "Second Label" );

std::shared_ptr< basic_element::Element > elem3( new basic_element::Element( elem2->next(), elem2 ) );
Expand Down Expand Up @@ -102,7 +102,7 @@ BOOST_AUTO_TEST_CASE( element_checker_test_checker_map )
BOOST_CHECK( ! elem2->_map.empty() );
elem2->set( buff2, checker.getSize( elem2 ) );
checker.check( elem2 );
BOOST_CHECK_EQUAL( elem2->_status, eStatusPassOver );
BOOST_CHECK_EQUAL( elem2->_status, eStatusValid );
BOOST_CHECK_EQUAL( elem2->_mapValue, "Third Label" );

std::shared_ptr< basic_element::Element > elem3( new basic_element::Element( elem2->next(), elem2 ) );
Expand Down Expand Up @@ -130,7 +130,7 @@ BOOST_AUTO_TEST_CASE( element_checker_test_checker_map )
BOOST_CHECK( ! elem2->_map.empty() );
elem2->set( buff2, checker.getSize( elem2 ) );
checker.check( elem2 );
BOOST_CHECK_EQUAL( elem2->_status, eStatusPassOver );
BOOST_CHECK_EQUAL( elem2->_status, eStatusValid );
BOOST_CHECK( elem2->_mapValue.empty() );

std::shared_ptr< basic_element::Element > elem3( new basic_element::Element( elem2->next(), elem2 ) );
Expand Down Expand Up @@ -189,7 +189,7 @@ BOOST_AUTO_TEST_CASE( element_checker_test_checker_map_hexa )
BOOST_CHECK( ! elem2->_map.empty() );
elem2->set( buff2, checker.getSize( elem2 ) );
checker.check( elem2 );
BOOST_CHECK_EQUAL( elem2->_status, eStatusPassOver );
BOOST_CHECK_EQUAL( elem2->_status, eStatusValid );
BOOST_CHECK_EQUAL( elem2->_mapValue, "First Label" );

std::shared_ptr< basic_element::Element > elem3( new basic_element::Element( elem2->next(), elem2 ) );
Expand Down Expand Up @@ -217,7 +217,7 @@ BOOST_AUTO_TEST_CASE( element_checker_test_checker_map_hexa )
BOOST_CHECK( ! elem2->_map.empty() );
elem2->set( buff2, checker.getSize( elem2 ) );
checker.check( elem2 );
BOOST_CHECK_EQUAL( elem2->_status, eStatusPassOver );
BOOST_CHECK_EQUAL( elem2->_status, eStatusValid );
BOOST_CHECK_EQUAL( elem2->_mapValue, "Second Label" );

std::shared_ptr< basic_element::Element > elem3( new basic_element::Element( elem2->next(), elem2 ) );
Expand Down Expand Up @@ -245,7 +245,7 @@ BOOST_AUTO_TEST_CASE( element_checker_test_checker_map_hexa )
BOOST_CHECK( ! elem2->_map.empty() );
elem2->set( buff2, checker.getSize( elem2 ) );
checker.check( elem2 );
BOOST_CHECK_EQUAL( elem2->_status, eStatusPassOver );
BOOST_CHECK_EQUAL( elem2->_status, eStatusValid );
BOOST_CHECK_EQUAL( elem2->_mapValue, "Third Label" );

std::shared_ptr< basic_element::Element > elem3( new basic_element::Element( elem2->next(), elem2 ) );
Expand Down
16 changes: 8 additions & 8 deletions libraries/ElementChecker/test/checkerTestRepetitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ BOOST_AUTO_TEST_CASE( element_checker_checker_repetition )
Checker checker;

std::shared_ptr< basic_element::Element > elem1( new basic_element::Element( node ) );
BOOST_CHECK_EQUAL( elem1->_status, eStatusNotChecked );
BOOST_CHECK_EQUAL( elem1->_status, eStatusUnknown );
elem1->set( buff1, 5 );
checker.check( elem1 );
BOOST_CHECK_EQUAL( elem1->_status, eStatusValid );
Expand Down Expand Up @@ -101,7 +101,7 @@ BOOST_AUTO_TEST_CASE( element_checker_checker_repetition )
Checker checker;

std::shared_ptr< basic_element::Element > elem1( new basic_element::Element( node ) );
BOOST_CHECK_EQUAL( elem1->_status, eStatusNotChecked );
BOOST_CHECK_EQUAL( elem1->_status, eStatusUnknown );
elem1->set( buff1, 5 );
checker.check( elem1 );
BOOST_CHECK_EQUAL( elem1->_status, eStatusValid );
Expand Down Expand Up @@ -151,7 +151,7 @@ BOOST_AUTO_TEST_CASE( element_checker_checker_repetition )
Checker checker;

std::shared_ptr< basic_element::Element > elem1( new basic_element::Element( node ) );
BOOST_CHECK_EQUAL( elem1->_status, eStatusNotChecked );
BOOST_CHECK_EQUAL( elem1->_status, eStatusUnknown );
elem1->set( buff1, 5 );
checker.check( elem1 );
BOOST_CHECK_EQUAL( elem1->_status, eStatusValid );
Expand Down Expand Up @@ -201,7 +201,7 @@ BOOST_AUTO_TEST_CASE( element_checker_checker_repetition )
Checker checker;

std::shared_ptr< basic_element::Element > elem1( new basic_element::Element( node ) );
BOOST_CHECK_EQUAL( elem1->_status, eStatusNotChecked );
BOOST_CHECK_EQUAL( elem1->_status, eStatusUnknown );
elem1->set( buff1, 5 );
checker.check( elem1 );
BOOST_CHECK_EQUAL( elem1->_status, eStatusValid );
Expand Down Expand Up @@ -285,7 +285,7 @@ BOOST_AUTO_TEST_CASE( element_checker_checker_repetition_invalid )

Checker checker;
std::shared_ptr< basic_element::Element > elem1( new basic_element::Element( node ) );
BOOST_CHECK_EQUAL( elem1->_status, eStatusNotChecked );
BOOST_CHECK_EQUAL( elem1->_status, eStatusUnknown );
elem1->set( buff1, 5 );
checker.check( elem1 );
BOOST_CHECK_EQUAL( elem1->_status, eStatusValid );
Expand Down Expand Up @@ -330,7 +330,7 @@ BOOST_AUTO_TEST_CASE( element_checker_checker_repetition_invalid )
Checker checker;

std::shared_ptr< basic_element::Element > elem1( new basic_element::Element( node ) );
BOOST_CHECK_EQUAL( elem1->_status, eStatusNotChecked );
BOOST_CHECK_EQUAL( elem1->_status, eStatusUnknown );
elem1->set( buff1, 5 );
checker.check( elem1 );
BOOST_CHECK_EQUAL( elem1->_status, eStatusValid );
Expand Down Expand Up @@ -370,7 +370,7 @@ BOOST_AUTO_TEST_CASE( element_checker_checker_repetition_invalid )
Checker checker;

std::shared_ptr< basic_element::Element > elem1( new basic_element::Element( node ) );
BOOST_CHECK_EQUAL( elem1->_status, eStatusNotChecked );
BOOST_CHECK_EQUAL( elem1->_status, eStatusUnknown );
elem1->set( buff1, 5 );
checker.check( elem1 );
BOOST_CHECK_EQUAL( elem1->_status, eStatusValid );
Expand Down Expand Up @@ -430,7 +430,7 @@ BOOST_AUTO_TEST_CASE( element_checker_checker_repetition_invalid )
Checker checker;

std::shared_ptr< basic_element::Element > elem1( new basic_element::Element( node ) );
BOOST_CHECK_EQUAL( elem1->_status, eStatusNotChecked );
BOOST_CHECK_EQUAL( elem1->_status, eStatusUnknown );
elem1->set( buff1, 5 );
checker.check( elem1 );
BOOST_CHECK_EQUAL( elem1->_status, eStatusValid );
Expand Down
6 changes: 3 additions & 3 deletions libraries/ElementChecker/test/checkerTestRequirement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ BOOST_AUTO_TEST_CASE( element_checker_test_checker_requirement )
BOOST_CHECK( elem1->_requiredExpr.empty() );
elem1->set( buff4, checker.getSize( elem1 ) );
checker.check( elem1 );
BOOST_CHECK_EQUAL( elem1->_status, eStatusPassOver );
BOOST_CHECK_EQUAL( elem1->_status, eStatusValid );

std::shared_ptr< basic_element::Element > elem2( new basic_element::Element( elem1->next(), elem1 ) );
BOOST_CHECK_EQUAL( elem2->_id, node->next()->getId() );
Expand Down Expand Up @@ -135,7 +135,7 @@ BOOST_AUTO_TEST_CASE( element_checker_test_checker_requirement )
BOOST_CHECK( elem1->_requiredExpr.empty() );
elem1->set( buff4, checker.getSize( elem1 ) );
checker.check( elem1 );
BOOST_CHECK_EQUAL( elem1->_status, eStatusPassOver );
BOOST_CHECK_EQUAL( elem1->_status, eStatusValid );

std::shared_ptr< basic_element::Element > elem2( new basic_element::Element( elem1->next(), elem1 ) );
BOOST_CHECK_EQUAL( elem2->_id, node->next()->getId() );
Expand Down Expand Up @@ -177,7 +177,7 @@ BOOST_AUTO_TEST_CASE( element_checker_test_checker_requirement )
BOOST_CHECK( elem1->_requiredExpr.empty() );
elem1->set( buff4, checker.getSize( elem1 ) );
checker.check( elem1 );
BOOST_CHECK_EQUAL( elem1->_status, eStatusPassOver );
BOOST_CHECK_EQUAL( elem1->_status, eStatusValid );

std::shared_ptr< basic_element::Element > elem2( new basic_element::Element( elem1->next(), elem1 ) );
BOOST_CHECK_EQUAL( elem2->_id, node->next()->getId() );
Expand Down
Loading

0 comments on commit 9318119

Please sign in to comment.