From ecc08604895fa37410e3bf7d5eb35d0ce13ddbc8 Mon Sep 17 00:00:00 2001 From: Valentin Noel Date: Thu, 31 Oct 2013 18:38:36 +0100 Subject: [PATCH] add Translator unit test for get< std::string > method issue #33 --- .../ElementChecker/Translator/Translator.tcc | 2 +- .../ElementChecker/test/translatorTest.hpp | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/libraries/ElementChecker/src/ElementChecker/Translator/Translator.tcc b/libraries/ElementChecker/src/ElementChecker/Translator/Translator.tcc index c24b912..09c52e2 100644 --- a/libraries/ElementChecker/src/ElementChecker/Translator/Translator.tcc +++ b/libraries/ElementChecker/src/ElementChecker/Translator/Translator.tcc @@ -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" ); diff --git a/libraries/ElementChecker/test/translatorTest.hpp b/libraries/ElementChecker/test/translatorTest.hpp index d8bf213..56acec2 100644 --- a/libraries/ElementChecker/test/translatorTest.hpp +++ b/libraries/ElementChecker/test/translatorTest.hpp @@ -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 ); } }