Skip to content

Commit

Permalink
add Translator unit test for get< std::string > method
Browse files Browse the repository at this point in the history
issue #33
  • Loading branch information
Valentin Noel committed Oct 31, 2013
1 parent 5c36938 commit ecc0860
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ GET_VECTOR( long double )


template< >
std::string Translator::get< std::string >()
std::string Translator::get< std::string >() // get ascii character !
{
if( _ref->_data == nullptr )
throw std::runtime_error( "Undefined data" );
Expand Down
37 changes: 37 additions & 0 deletions libraries/ElementChecker/test/translatorTest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,43 @@ BOOST_AUTO_TEST_CASE( element_checker_translator_2 )
BOOST_CHECK_EQUAL( (short) Translator( elem ).get< std::vector< short > >().at(0), 1 );
BOOST_CHECK_EQUAL( (short) Translator( elem ).get< std::vector< short > >().at(1), 0 );

BOOST_CHECK_THROW( Translator( elem ).get< short >(), std::runtime_error );
}
{
LOG_INFO( "\t>>> translator_2_5 <<<" );
std::string jsonString = R"*(
{
"header": [
{
"id": "id",
"label": "label",
"type": "uint32"
}
]
}
)*";

spec_reader::Specification spec;
spec.setFromString( jsonString );
std::shared_ptr< spec_reader::SpecNode > node = spec.getFirstNode();

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

const char buff[4] { 0x62, 0x61, 0x62, 0x61 };
elem->set( (const char*)&buff, 4 );

BOOST_CHECK_EQUAL( Translator( elem ).get< int >(), 1650549345 );
BOOST_CHECK_EQUAL( Translator( elem ).get< std::string >(), "baba" );
BOOST_CHECK_EQUAL( (short) Translator( elem ).get< std::vector< char > >().size(), 4 );
BOOST_CHECK_EQUAL( (short) Translator( elem ).get< std::vector< char > >().at(0), 98 );
BOOST_CHECK_EQUAL( (short) Translator( elem ).get< std::vector< char > >().at(1), 97 );
BOOST_CHECK_EQUAL( (short) Translator( elem ).get< std::vector< char > >().at(2), 98 );
BOOST_CHECK_EQUAL( (short) Translator( elem ).get< std::vector< char > >().at(3), 97 );

BOOST_CHECK_EQUAL( (short) Translator( elem ).get< std::vector< short > >().size(), 2 );
BOOST_CHECK_EQUAL( (short) Translator( elem ).get< std::vector< short > >().at(0), 24930 );
BOOST_CHECK_EQUAL( (short) Translator( elem ).get< std::vector< short > >().at(1), 24930 );

BOOST_CHECK_THROW( Translator( elem ).get< short >(), std::runtime_error );
}
}
Expand Down

0 comments on commit ecc0860

Please sign in to comment.