diff --git a/libraries/comparator/src/Comparator.tcc b/libraries/comparator/src/Comparator.tcc index 9b8c6cf..0730104 100644 --- a/libraries/comparator/src/Comparator.tcc +++ b/libraries/comparator/src/Comparator.tcc @@ -120,7 +120,7 @@ void Comparator::checkNode( const sr::SpecNode& node, report_generator::ReportNo } std::string nodeId = node.getId(); - + // check node std::shared_ptr< be::Element > element( getElementFromNode( node ) ); @@ -147,21 +147,71 @@ void Comparator::checkNode( const sr::SpecNode& node, report_generator::ReportNo extractRepetition( repetNumber, repetRange, node.getRepetition() ); sr::SpecNode nextNode = node.next(); - LOG_TRACE( "nextNode: " << nextNode.getId() << " | nodeId: " << nodeId ); - rg::ReportNode* nextReportNode; - // check if optional bool sentToReport = true; - if( node.isOptional() && element->getStatus() != 1 ) + // check repetitions + if( _elementIter.at( nodeId ).iter < repetNumber ) + nextNode = node; + + bool inRangeCheck = false; + if( repetRange.size() > 0 ) { - LOG_TRACE( "Optional & Not Valid -> Go back: " << element->getSize() ); - sentToReport = false; - _file->goBack( element->getSize() ); - // element->setData( NULL, 0 ); + size_t min = repetRange.at(0).first; + size_t max = repetRange.at(0).second; + for( std::pair< size_t, size_t > range : repetRange ) + { + min = std::min( range.first, min ); + max = ( range.second * max == 0 )? 0 : std::max( range.second, max ); + } + LOG_TRACE( "\tmin : " << min ); + LOG_TRACE( "\tmax : " << max ); + + if( element->getStatus() == 1 ) + { + inRangeCheck = true; + nextNode = node; + } + else + { + size_t initPos = _file->getPosition(); + + if( _file->getLength() - initPos < element->getSize() ) + _file->goBack( _file->getLength() - initPos ); + else + _file->goBack( element->getSize() ); + + sentToReport = false; + + size_t elemIter = --_elementIter.at( nodeId ).iter; + bool isInRange = false; + for( std::pair< size_t, size_t > range : repetRange ) + { + if( elemIter >= range.first && range.second == 0 ) + isInRange = true; + else if( elemIter >= range.first && elemIter <= range.second ) + isInRange = true; + } + if( ! isInRange ) + { + std::stringstream error; + error << "Out of repetition range (" << elemIter << " iterations)"; + reportNode.getSecond()->begin()->second.data()->addErrorLabel( error.str() ); + LOG_ERROR( error.str() ); + } + } } + // check if optional + // if( node.isOptional() && element->getStatus() != 1 ) + // { + // LOG_TRACE( "Optional & Not Valid -> Go back: " << element->getSize() ); + // sentToReport = false; + // _file->goBack( element->getSize() ); + // } + // node to report + rg::ReportNode* nextReportNode; if( isFirstChild && sentToReport ) { rg::ReportNode newReportNode = reportNode.appendChild( element ); @@ -180,62 +230,23 @@ void Comparator::checkNode( const sr::SpecNode& node, report_generator::ReportNo nextReportNode = &reportNode; } - // children nodes check if( node.hasGroup() && sentToReport ) checkNode( node.firstChild(), *nextReportNode, true ); - // check repetitions - if( _elementIter.at( nodeId ).iter < repetNumber ) - nextNode = node; - - bool inRange = false; - if( repetRange.size() > 0 ) - { - size_t min = repetRange.at(0).first; - size_t max = repetRange.at(0).second; - for( std::pair< size_t, size_t > range : repetRange ) - { - min = std::min( range.first, min ); - max = std::max( range.second, max ); - } - LOG_TRACE( "\tmin : " << min ); - LOG_TRACE( "\tmax : " << max ); - - if( _elementIter.at( nodeId ).iter < max || max == 0 ) - { - inRange = true; - if( _elementIter.at( nodeId ).iter < min ) - nextNode = node; - else - { - size_t initPos = _file->getPosition(); - std::shared_ptr< be::Element > nextElement( getElementFromNode( node ) ); - - if( _file->getLength() - initPos < nextElement->getSize() ) - _file->goBack( _file->getLength() - initPos ); - else - _file->goBack( nextElement->getSize() ); - - if( nextElement->getStatus() == 1 ) - nextNode = node; - else - inRange = false; - } - } - } - // next node check + LOG_TRACE( "nodeId: " << nodeId << " | nextNode: " << nextNode.getId() ); + if( ! node.isLastNode() ) checkNode( nextNode, *nextReportNode, ( isFirstChild && ! sentToReport ) ); - else if( nextNode.getId() == nodeId && ! _file->isEndOfFile() && inRange ) + else if( nextNode.getId() == nodeId && ! _file->isEndOfFile() && inRangeCheck ) checkNode( nextNode, *nextReportNode, ( isFirstChild && ! sentToReport ) ); else if( _elementIter.at( nodeId ).iter < repetNumber ) checkNode( node, *nextReportNode, ( isFirstChild && ! sentToReport ) ); else LOG_TRACE( "\t IS LAST NODE !" ); - // remove iteration (?) + // remove iteration _elementIter.at( nodeId ).iter = 0; } @@ -275,7 +286,7 @@ void Comparator::extractRepetition( size_t& repetNumber, Vector< size_t >::Pair& } else { - // LOG_TRACE( "REP RANGE: [" << repetPair.first << ", " << repetPair.second << "]" ); + LOG_TRACE( "REP RANGE: [" << repetPair.first << ", " << repetPair.second << "]" ); be::expression_parser::ExpressionParser repetParser( _elementList ); size_t repetMin = 0; size_t repetMax = 0; diff --git a/libraries/comparator/tests/comparatorTests.cpp b/libraries/comparator/tests/comparatorTests.cpp index 1edcc8b..6aa1059 100644 --- a/libraries/comparator/tests/comparatorTests.cpp +++ b/libraries/comparator/tests/comparatorTests.cpp @@ -51,887 +51,8 @@ BOOST_AUTO_TEST_CASE( report_init ) color->enable(); } - -BOOST_AUTO_TEST_CASE( comparator_comparator ) -{ - LOG_WARNING( ">>> comparator_comparator <<<" ); - // { - // sr::SpecList specs; - // sr::Specification spec; - // spec.setFromFile( "comparetest.json" ); - // specs.addSpecification( spec ); - // BOOST_CHECK_EQUAL( specs.getSpecNumber(), 1 ); - - // std::ifstream is; - // is.open( "test.txt", std::ios::in ); - // fr::FileReader file( is.rdbuf() ); - - // Comparator comp( &file, specs ); - - // rg::Report report; - // comp.compare( "test", report ); - // } - { - std::string jsonString =R"*( - { - "standard": - { - "id": "test", - "extension": [ - "ext1", - "ext2", - "ext3"] - }, - "header": [ - { - "id": "test1", - "label": "Test 1", - "type": "unknown" - } - ] - })*"; - sr::Specification spec; - sr::SpecList specList; - - spec.setFromString( jsonString ); - specList.addSpecification( spec ); - - std::stringbuf buffer; - buffer.str( "FILE reader" ); - fr::FileReader file( &buffer ); - - Comparator comp( &file, specList ); - - rg::Report report; - BOOST_CHECK_THROW( comp.compare( "test", report ), std::runtime_error ); - } - { - std::string jsonString =R"*( - { - "standard": - { - "id": "test", - "extension": [ - "ext1", - "ext2", - "ext3"] - }, - "header": [ - { - "id": "test1", - "label": "Test 1", - "type": "ascii" - } - ] - })*"; - sr::Specification spec; - sr::SpecList specList; - - spec.setFromString( jsonString ); - specList.addSpecification( spec ); - - std::stringbuf buffer; - buffer.str( "FILE reader" ); - fr::FileReader file( &buffer ); - - Comparator comp( &file, specList ); - - rg::Report report; - BOOST_CHECK_THROW( comp.compare( "test", report ), std::runtime_error ); - } -} - -BOOST_AUTO_TEST_CASE( comparator_comparator_only_root ) -{ - LOG_WARNING( ">>> comparator_comparator_only_root <<<" ); - { - std::string jsonString = R"*( - { - "standard": - { - "id": "test", - "extension": [ - "ext1", - "ext2", - "ext3"] - }, - "header": [ - { - "id": "test1", - "label": "Test 1", - "type": "hexa", - "count": "0" - }, - { - "id": "test2", - "label": "Test 2", - "type": "ascii", - "count": "0" - }, - { - "id": "test3", - "label": "Test 3", - "type": "raw", - "count": "0" - } - ] - } - )*"; - - sr::Specification spec; - sr::SpecList specList; - - spec.setFromString( jsonString ); - specList.addSpecification( spec ); - - std::stringbuf buffer; - buffer.str( "FILE reader" ); - fr::FileReader file( &buffer ); - - Comparator comp( &file, specList ); - - rg::Report report; - comp.compare( "test", report ); - - rg::Transform tr( report ); - rg::Export exporter( tr.transformTree( rg::Transform::eReportTypeXml ) ); - - LOG_INFO( "\n==== REPORT ====" ); - // exporter.writeXmlFile( "test.xml" ); - LOG_INFO( exporter.getXmlString() ); - - std::istringstream xmlStream( exporter.getXmlString() ); - std::istringstream jsonStream( jsonString ); - bpt::ptree xmlReport; - bpt::ptree jsonReport; - bpt::read_xml ( xmlStream, xmlReport ); - bpt::read_json( jsonStream, jsonReport ); - - BOOST_CHECK_EQUAL( xmlReport.size(), jsonReport.get_child( "header" ).size() ); - - std::vector< std::string > xmlIds; - std::vector< std::string > jsonIds; - - fillVectorXml( xmlReport, xmlIds, ".id" ); - fillVectorJson( jsonReport.get_child( "header" ), jsonIds, "id" ); - - BOOST_CHECK_EQUAL( xmlIds.size(), jsonIds.size() ); - for( size_t i = 0; i < xmlIds.size(); ++i ) - BOOST_CHECK_EQUAL( xmlIds.at(i), jsonIds.at(i) ); - } -} - -BOOST_AUTO_TEST_CASE( comparator_comparator_one_child ) -{ - LOG_WARNING( ">>> comparator_comparator_one_child <<<" ); - { - std::string jsonString = R"*( - { - "standard": - { - "id": "test", - "extension": [ - "ext1", - "ext2", - "ext3"] - }, - "header": [ - { - "id": "test1", - "label": "Test 1", - "type": "hexa", - "count": "0" - }, - { - "id": "test2", - "label": "Test 2", - "type": "ascii", - "count": "0", - "group": [ - { - "id": "child1", - "label": "Child 1", - "type": "hexa", - "values": "ff00" - } - ] - }, - { - "id": "test3", - "label": "Test 3", - "type": "raw", - "count": "0" - } - ] - } - )*"; - - sr::Specification spec; - sr::SpecList specList; - - spec.setFromString( jsonString ); - specList.addSpecification( spec ); - - std::stringbuf buffer; - buffer.str( "FILE reader" ); - fr::FileReader file( &buffer ); - - Comparator comp( &file, specList ); - - rg::Report report; - comp.compare( "test", report ); - - rg::Transform tr( report ); - rg::Export exporter( tr.transformTree( rg::Transform::eReportTypeXml ) ); - - LOG_INFO( "\n==== REPORT ====" ); - // exporter.writeXmlFile( "test_one_child.xml" ); - LOG_INFO( exporter.getXmlString() ); - - std::istringstream xmlStream( exporter.getXmlString() ); - std::istringstream jsonStream( jsonString ); - bpt::ptree xmlReport; - bpt::ptree jsonReport; - bpt::read_xml ( xmlStream, xmlReport ); - bpt::read_json( jsonStream, jsonReport ); - - BOOST_CHECK_EQUAL( xmlReport.size(), jsonReport.get_child( "header" ).size() ); - - std::vector< std::string > xmlIds; - std::vector< std::string > jsonIds; - - fillVectorXml( xmlReport, xmlIds, ".id" ); - fillVectorJson( jsonReport.get_child( "header" ), jsonIds, "id" ); - - BOOST_CHECK_EQUAL( xmlIds.size(), jsonIds.size() ); - for( size_t i = 0; i < xmlIds.size(); ++i ) - BOOST_CHECK_EQUAL( xmlIds.at(i), jsonIds.at(i) ); - } -} - - -BOOST_AUTO_TEST_CASE( comparator_comparator_n_children ) -{ - LOG_WARNING( ">>> comparator_comparator_n_children <<<" ); - { - std::string jsonString = R"*( - { - "standard": - { - "id": "test", - "extension": [ - "ext1", - "ext2", - "ext3"] - }, - "header": [ - { - "id": "test1", - "label": "Test 1", - "type": "hexa", - "count": "0" - }, - { - "id": "test2", - "label": "Test 2", - "type": "ascii", - "count": "0", - "group": [ - { - "id": "child1", - "label": "Child 1", - "type": "hexa", - "values": "ff00" - }, - { - "id": "child2", - "label": "Child 2", - "type": "hexa", - "values": "00ff" - }, - { - "id": "child3", - "label": "Child 3", - "type": "hexa", - "values": "00ff" - }, - { - "id": "child4", - "label": "Child 4", - "type": "hexa", - "values": "00ff" - }, - { - "id": "child5", - "label": "Child 5", - "type": "hexa", - "values": "00ff" - } - ] - }, - { - "id": "test3", - "label": "Test 3", - "type": "raw", - "count": "0" - } - ] - } - )*"; - - sr::Specification spec; - sr::SpecList specList; - - spec.setFromString( jsonString ); - specList.addSpecification( spec ); - - std::stringbuf buffer; - buffer.str( "FILE reader" ); - fr::FileReader file( &buffer ); - - Comparator comp( &file, specList ); - - rg::Report report; - comp.compare( "test", report ); - - rg::Transform tr( report ); - rg::Export exporter( tr.transformTree( rg::Transform::eReportTypeXml ) ); - - LOG_INFO( "\n==== REPORT ====" ); - // exporter.writeXmlFile( "test_n_child.xml" ); - LOG_INFO( exporter.getXmlString() ); - - std::istringstream xmlStream( exporter.getXmlString() ); - std::istringstream jsonStream( jsonString ); - bpt::ptree xmlReport; - bpt::ptree jsonReport; - bpt::read_xml ( xmlStream, xmlReport ); - bpt::read_json( jsonStream, jsonReport ); - - BOOST_CHECK_EQUAL( xmlReport.size(), jsonReport.get_child( "header" ).size() ); - - std::vector< std::string > xmlIds; - std::vector< std::string > jsonIds; - - fillVectorXml( xmlReport, xmlIds, ".id" ); - fillVectorJson( jsonReport.get_child( "header" ), jsonIds, "id" ); - - BOOST_CHECK_EQUAL( xmlIds.size(), jsonIds.size() ); - for( size_t i = 0; i < xmlIds.size(); ++i ) - BOOST_CHECK_EQUAL( xmlIds.at(i), jsonIds.at(i) ); - } -} - - -BOOST_AUTO_TEST_CASE( comparator_comparator_one_subchild ) -{ - LOG_WARNING( ">>> comparator_comparator_one_subchild <<<" ); - { - std::string jsonString = R"*( - { - "standard": - { - "id": "test", - "extension": [ - "ext1", - "ext2", - "ext3"] - }, - "header": [ - { - "id": "test1", - "label": "Test 1", - "type": "hexa", - "count": "0" - }, - { - "id": "test2", - "label": "Test 2", - "type": "ascii", - "count": "0", - "group": [ - { - "id": "child1", - "label": "Child 1", - "type": "hexa", - "values": "ff00" - }, - { - "id": "child2", - "label": "Child 2", - "type": "hexa", - "values": "00ff", - "group": [ - { - "id": "child21", - "label": "Child 21", - "type": "hexa", - "values": "00ff" - } - ] - } - ] - }, - { - "id": "test3", - "label": "Test 3", - "type": "raw", - "count": "0" - } - ] - } - )*"; - - sr::Specification spec; - sr::SpecList specList; - - spec.setFromString( jsonString ); - specList.addSpecification( spec ); - - std::stringbuf buffer; - buffer.str( "FILE reader" ); - fr::FileReader file( &buffer ); - - Comparator comp( &file, specList ); - - rg::Report report; - comp.compare( "test", report ); - - rg::Transform tr( report ); - rg::Export exporter( tr.transformTree( rg::Transform::eReportTypeXml ) ); - - LOG_INFO( "\n==== REPORT ====" ); - // exporter.writeXmlFile( "test_one_subchild.xml" ); - LOG_INFO( exporter.getXmlString() ); - - std::istringstream xmlStream( exporter.getXmlString() ); - std::istringstream jsonStream( jsonString ); - bpt::ptree xmlReport; - bpt::ptree jsonReport; - bpt::read_xml ( xmlStream, xmlReport ); - bpt::read_json( jsonStream, jsonReport ); - - BOOST_CHECK_EQUAL( xmlReport.size(), jsonReport.get_child( "header" ).size() ); - - std::vector< std::string > xmlIds; - std::vector< std::string > jsonIds; - - fillVectorXml( xmlReport, xmlIds, ".id" ); - fillVectorJson( jsonReport.get_child( "header" ), jsonIds, "id" ); - - BOOST_CHECK_EQUAL( xmlIds.size(), jsonIds.size() ); - for( size_t i = 0; i < xmlIds.size(); ++i ) - BOOST_CHECK_EQUAL( xmlIds.at(i), jsonIds.at(i) ); - } -} - -BOOST_AUTO_TEST_CASE( comparator_comparator_n_subchildren ) -{ - LOG_WARNING( ">>> comparator_comparator_n_subchildren <<<" ); - { - std::string jsonString = R"*( - { - "standard": - { - "id": "test", - "extension": [ - "ext1", - "ext2", - "ext3"] - }, - "header": [ - { - "id": "test1", - "label": "Test 1", - "type": "hexa", - "count": "0" - }, - { - "id": "test2", - "label": "Test 2", - "type": "ascii", - "count": "0", - "group": [ - { - "id": "child1", - "label": "Child 1", - "type": "hexa", - "values": "ff00" - }, - { - "id": "child2", - "label": "Child 2", - "type": "hexa", - "values": "00ff", - "group": [ - { - "id": "child21", - "label": "Child 21", - "type": "hexa", - "values": "00ff" - }, - { - "id": "child22", - "label": "Child 22", - "type": "hexa", - "values": "00ff" - } - ] - } - ] - }, - { - "id": "test3", - "label": "Test 3", - "type": "raw", - "count": "0" - } - ] - } - )*"; - - sr::Specification spec; - sr::SpecList specList; - - spec.setFromString( jsonString ); - specList.addSpecification( spec ); - - std::stringbuf buffer; - buffer.str( "FILE reader" ); - fr::FileReader file( &buffer ); - - Comparator comp( &file, specList ); - - rg::Report report; - comp.compare( "test", report ); - - rg::Transform tr( report ); - rg::Export exporter( tr.transformTree( rg::Transform::eReportTypeXml ) ); - - LOG_INFO( "\n==== REPORT ====" ); - // exporter.writeXmlFile( "test_n_subchildren.xml" ); - LOG_INFO( exporter.getXmlString() ); - - std::istringstream xmlStream( exporter.getXmlString() ); - std::istringstream jsonStream( jsonString ); - bpt::ptree xmlReport; - bpt::ptree jsonReport; - bpt::read_xml ( xmlStream, xmlReport ); - bpt::read_json( jsonStream, jsonReport ); - - BOOST_CHECK_EQUAL( xmlReport.size(), jsonReport.get_child( "header" ).size() ); - - std::vector< std::string > xmlIds; - std::vector< std::string > jsonIds; - - fillVectorXml( xmlReport, xmlIds, ".id" ); - fillVectorJson( jsonReport.get_child( "header" ), jsonIds, "id" ); - - BOOST_CHECK_EQUAL( xmlIds.size(), jsonIds.size() ); - for( size_t i = 0; i < xmlIds.size(); ++i ) - BOOST_CHECK_EQUAL( xmlIds.at(i), jsonIds.at(i) ); - } -} - -BOOST_AUTO_TEST_CASE( comparator_comparator_n_levels ) -{ - LOG_WARNING( ">>> comparator_comparator_n_levels <<<" ); - { - std::string jsonString = R"*( - { - "standard": - { - "id": "test", - "extension": [ - "ext1", - "ext2", - "ext3"] - }, - "header": [ - { - "id": "test1", - "label": "Test 1", - "type": "hexa", - "count": "0" - }, - { - "id": "test2", - "label": "Test 2", - "type": "ascii", - "count": "0", - "group": [ - { - "id": "child1", - "label": "Child 1", - "type": "hexa", - "values": "4649" - }, - { - "id": "child2", - "label": "Child 2", - "type": "hexa", - "values": "4c45", - "group": [ - { - "id": "child21", - "label": "Child 21", - "type": "hexa", - "values": "2072", - "group": [ - { - "id": "child211", - "label": "Child 211", - "type": "hexa", - "values": "6561" - }, - { - "id": "child212", - "label": "Child 212", - "type": "hexa", - "values": "6465", - "group": [ - { - "id": "child2121", - "label": "Child 2121", - "type": "hexa", - "values": "7220" - }, - { - "id": "child2122", - "label": "Child 2122", - "type": "hexa", - "values": "2020", - "group": [ - { - "id": "child21221", - "label": "Child 21221", - "type": "hexa", - "values": "2020" - } - ] - } - ] - } - ] - }, - { - "id": "child22", - "label": "Child 22", - "type": "hexa", - "values": "7265" - } - ] - } - ] - }, - { - "id": "test3", - "label": "Test 3", - "type": "raw", - "count": "0", - "group": [ - { - "id": "child31", - "label": "Child 31", - "type": "hexa", - "values": "6461", - "group": [ - { - "id": "child311", - "label": "Child 311", - "type": "hexa", - "values": "6572", - "group": [ - { - "id": "child3111", - "label": "Child 3111", - "type": "hexa", - "values": "2045" - } - ] - } - ] - } - ] - } - ] - } - )*"; - - sr::Specification spec; - sr::SpecList specList; - - spec.setFromString( jsonString ); - specList.addSpecification( spec ); - - std::stringbuf buffer; - buffer.str( "FILE reader redaer ELIF" ); - fr::FileReader file( &buffer ); - - Comparator comp( &file, specList ); - - rg::Report report; - comp.compare( "test", report ); - - rg::Transform tr( report ); - rg::Export exporter( tr.transformTree( rg::Transform::eReportTypeXml ) ); - - LOG_INFO( "\n==== REPORT ====" ); - // exporter.writeXmlFile( "test_n_levels.xml" ); - LOG_INFO( exporter.getXmlString() ); - - std::istringstream xmlStream( exporter.getXmlString() ); - std::istringstream jsonStream( jsonString ); - bpt::ptree xmlReport; - bpt::ptree jsonReport; - bpt::read_xml ( xmlStream, xmlReport ); - bpt::read_json( jsonStream, jsonReport ); - - BOOST_CHECK_EQUAL( xmlReport.size(), jsonReport.get_child( "header" ).size() ); - - std::vector< std::string > xmlIds; - std::vector< std::string > jsonIds; - - fillVectorXml( xmlReport, xmlIds, ".id" ); - fillVectorJson( jsonReport.get_child( "header" ), jsonIds, "id" ); - - BOOST_CHECK_EQUAL( xmlIds.size(), jsonIds.size() ); - for( size_t i = 0; i < xmlIds.size(); ++i ) - BOOST_CHECK_EQUAL( xmlIds.at(i), jsonIds.at(i) ); - } -} - -BOOST_AUTO_TEST_CASE( comparator_comparator_n_levels_2 ) -{ - LOG_WARNING( ">>> comparator_comparator_n_levels_2 <<<" ); - { - std::string jsonString = R"*( - { - "standard": - { - "id": "test", - "extension": [ - "ext1", - "ext2", - "ext3"] - }, - "header": [ - { - "id": "test1", - "label": "Test 1", - "type": "uint8" - }, - { - "id": "test2", - "label": "Test 2", - "type": "ascii", - "count": "0", - "group": [ - { - "id": "child1", - "label": "Child 1", - "type": "uint32" - }, - { - "id": "child2", - "label": "Child 2", - "type": "int8", - "group": [ - { - "id": "child21", - "label": "Child 21", - "type": "hexa", - "values": "00ff", - "group": [ - { - "id": "child211", - "label": "Child 211", - "type": "float" - }, - { - "id": "child212", - "label": "Child 212", - "type": "double", - "group": [ - { - "id": "child2121", - "label": "Child 2121", - "type": "ieeeExtended" - }, - { - "id": "child2122", - "label": "Child 2122", - "type": "uint64", - "group": [ - { - "id": "child21221", - "label": "Child 21221", - "type": "int32" - } - ] - } - ] - } - ] - }, - { - "id": "child22", - "label": "Child 22", - "type": "int16" - } - ] - } - ] - } - ] - } - )*"; - - sr::Specification spec; - sr::SpecList specList; - - spec.setFromString( jsonString ); - specList.addSpecification( spec ); - - std::stringbuf buffer; - buffer.str( "FILE reader 1.0 vs. 0.1 redaer ELIF ? " ); - fr::FileReader file( &buffer ); - - Comparator comp( &file, specList ); - - rg::Report report; - comp.compare( "test", report ); - - rg::Transform tr( report ); - rg::Export exporter( tr.transformTree( rg::Transform::eReportTypeXml ) ); - - LOG_INFO( "\n==== REPORT ====" ); - // exporter.writeXmlFile( "test_n_levels_2.xml" ); - LOG_INFO( exporter.getXmlString() ); - - std::istringstream xmlStream( exporter.getXmlString() ); - std::istringstream jsonStream( jsonString ); - bpt::ptree xmlReport; - bpt::ptree jsonReport; - bpt::read_xml ( xmlStream, xmlReport ); - bpt::read_json( jsonStream, jsonReport ); - - BOOST_CHECK_EQUAL( xmlReport.size(), jsonReport.get_child( "header" ).size() ); - - std::vector< std::string > xmlIds; - std::vector< std::string > jsonIds; - - fillVectorXml( xmlReport, xmlIds, ".id" ); - fillVectorJson( jsonReport.get_child( "header" ), jsonIds, "id" ); - - BOOST_CHECK_EQUAL( xmlIds.size(), jsonIds.size() ); - for( size_t i = 0; i < xmlIds.size(); ++i ) - BOOST_CHECK_EQUAL( xmlIds.at(i), jsonIds.at(i) ); - } -} - BOOST_AUTO_TEST_SUITE_END() -// #include "comparatorTestsFeatures.hpp" -// #include "comparatorTestsRepetitions.hpp" -#include "comparatorTestsOptional.hpp" +#include "comparatorTestsFeatures.hpp" +#include "comparatorTestsRepetitions.hpp" +// #include "comparatorTestsOptional.hpp" diff --git a/libraries/comparator/tests/comparatorTestsFeatures.hpp b/libraries/comparator/tests/comparatorTestsFeatures.hpp index 00c9711..3a8faa7 100644 --- a/libraries/comparator/tests/comparatorTestsFeatures.hpp +++ b/libraries/comparator/tests/comparatorTestsFeatures.hpp @@ -1,8 +1,886 @@ -// contains range, map, displayType, values and count tests +// contains parsing, range, map, displayType, values and count tests BOOST_AUTO_TEST_SUITE( comparator_test_suite_features ) +BOOST_AUTO_TEST_CASE( comparator_comparator ) +{ + LOG_WARNING( ">>> comparator_comparator <<<" ); + // { + // sr::SpecList specs; + // sr::Specification spec; + // spec.setFromFile( "comparetest.json" ); + // specs.addSpecification( spec ); + // BOOST_CHECK_EQUAL( specs.getSpecNumber(), 1 ); + + // std::ifstream is; + // is.open( "test.txt", std::ios::in ); + // fr::FileReader file( is.rdbuf() ); + + // Comparator comp( &file, specs ); + + // rg::Report report; + // comp.compare( "test", report ); + // } + { + std::string jsonString =R"*( + { + "standard": + { + "id": "test", + "extension": [ + "ext1", + "ext2", + "ext3"] + }, + "header": [ + { + "id": "test1", + "label": "Test 1", + "type": "unknown" + } + ] + })*"; + sr::Specification spec; + sr::SpecList specList; + + spec.setFromString( jsonString ); + specList.addSpecification( spec ); + + std::stringbuf buffer; + buffer.str( "FILE reader" ); + fr::FileReader file( &buffer ); + + Comparator comp( &file, specList ); + + rg::Report report; + BOOST_CHECK_THROW( comp.compare( "test", report ), std::runtime_error ); + } + { + std::string jsonString =R"*( + { + "standard": + { + "id": "test", + "extension": [ + "ext1", + "ext2", + "ext3"] + }, + "header": [ + { + "id": "test1", + "label": "Test 1", + "type": "ascii" + } + ] + })*"; + sr::Specification spec; + sr::SpecList specList; + + spec.setFromString( jsonString ); + specList.addSpecification( spec ); + + std::stringbuf buffer; + buffer.str( "FILE reader" ); + fr::FileReader file( &buffer ); + + Comparator comp( &file, specList ); + + rg::Report report; + BOOST_CHECK_THROW( comp.compare( "test", report ), std::runtime_error ); + } +} + +BOOST_AUTO_TEST_CASE( comparator_comparator_only_root ) +{ + LOG_WARNING( ">>> comparator_comparator_only_root <<<" ); + { + std::string jsonString = R"*( + { + "standard": + { + "id": "test", + "extension": [ + "ext1", + "ext2", + "ext3"] + }, + "header": [ + { + "id": "test1", + "label": "Test 1", + "type": "hexa", + "count": "0" + }, + { + "id": "test2", + "label": "Test 2", + "type": "ascii", + "count": "0" + }, + { + "id": "test3", + "label": "Test 3", + "type": "raw", + "count": "0" + } + ] + } + )*"; + + sr::Specification spec; + sr::SpecList specList; + + spec.setFromString( jsonString ); + specList.addSpecification( spec ); + + std::stringbuf buffer; + buffer.str( "FILE reader" ); + fr::FileReader file( &buffer ); + + Comparator comp( &file, specList ); + + rg::Report report; + comp.compare( "test", report ); + + rg::Transform tr( report ); + rg::Export exporter( tr.transformTree( rg::Transform::eReportTypeXml ) ); + + LOG_INFO( "\n==== REPORT ====" ); + // exporter.writeXmlFile( "test.xml" ); + LOG_INFO( exporter.getXmlString() ); + + std::istringstream xmlStream( exporter.getXmlString() ); + std::istringstream jsonStream( jsonString ); + bpt::ptree xmlReport; + bpt::ptree jsonReport; + bpt::read_xml ( xmlStream, xmlReport ); + bpt::read_json( jsonStream, jsonReport ); + + BOOST_CHECK_EQUAL( xmlReport.size(), jsonReport.get_child( "header" ).size() ); + + std::vector< std::string > xmlIds; + std::vector< std::string > jsonIds; + + fillVectorXml( xmlReport, xmlIds, ".id" ); + fillVectorJson( jsonReport.get_child( "header" ), jsonIds, "id" ); + + BOOST_CHECK_EQUAL( xmlIds.size(), jsonIds.size() ); + for( size_t i = 0; i < xmlIds.size(); ++i ) + BOOST_CHECK_EQUAL( xmlIds.at(i), jsonIds.at(i) ); + } +} + +BOOST_AUTO_TEST_CASE( comparator_comparator_one_child ) +{ + LOG_WARNING( ">>> comparator_comparator_one_child <<<" ); + { + std::string jsonString = R"*( + { + "standard": + { + "id": "test", + "extension": [ + "ext1", + "ext2", + "ext3"] + }, + "header": [ + { + "id": "test1", + "label": "Test 1", + "type": "hexa", + "count": "0" + }, + { + "id": "test2", + "label": "Test 2", + "type": "ascii", + "count": "0", + "group": [ + { + "id": "child1", + "label": "Child 1", + "type": "hexa", + "values": "ff00" + } + ] + }, + { + "id": "test3", + "label": "Test 3", + "type": "raw", + "count": "0" + } + ] + } + )*"; + + sr::Specification spec; + sr::SpecList specList; + + spec.setFromString( jsonString ); + specList.addSpecification( spec ); + + std::stringbuf buffer; + buffer.str( "FILE reader" ); + fr::FileReader file( &buffer ); + + Comparator comp( &file, specList ); + + rg::Report report; + comp.compare( "test", report ); + + rg::Transform tr( report ); + rg::Export exporter( tr.transformTree( rg::Transform::eReportTypeXml ) ); + + LOG_INFO( "\n==== REPORT ====" ); + // exporter.writeXmlFile( "test_one_child.xml" ); + LOG_INFO( exporter.getXmlString() ); + + std::istringstream xmlStream( exporter.getXmlString() ); + std::istringstream jsonStream( jsonString ); + bpt::ptree xmlReport; + bpt::ptree jsonReport; + bpt::read_xml ( xmlStream, xmlReport ); + bpt::read_json( jsonStream, jsonReport ); + + BOOST_CHECK_EQUAL( xmlReport.size(), jsonReport.get_child( "header" ).size() ); + + std::vector< std::string > xmlIds; + std::vector< std::string > jsonIds; + + fillVectorXml( xmlReport, xmlIds, ".id" ); + fillVectorJson( jsonReport.get_child( "header" ), jsonIds, "id" ); + + BOOST_CHECK_EQUAL( xmlIds.size(), jsonIds.size() ); + for( size_t i = 0; i < xmlIds.size(); ++i ) + BOOST_CHECK_EQUAL( xmlIds.at(i), jsonIds.at(i) ); + } +} + + +BOOST_AUTO_TEST_CASE( comparator_comparator_n_children ) +{ + LOG_WARNING( ">>> comparator_comparator_n_children <<<" ); + { + std::string jsonString = R"*( + { + "standard": + { + "id": "test", + "extension": [ + "ext1", + "ext2", + "ext3"] + }, + "header": [ + { + "id": "test1", + "label": "Test 1", + "type": "hexa", + "count": "0" + }, + { + "id": "test2", + "label": "Test 2", + "type": "ascii", + "count": "0", + "group": [ + { + "id": "child1", + "label": "Child 1", + "type": "hexa", + "values": "ff00" + }, + { + "id": "child2", + "label": "Child 2", + "type": "hexa", + "values": "00ff" + }, + { + "id": "child3", + "label": "Child 3", + "type": "hexa", + "values": "00ff" + }, + { + "id": "child4", + "label": "Child 4", + "type": "hexa", + "values": "00ff" + }, + { + "id": "child5", + "label": "Child 5", + "type": "hexa", + "values": "00ff" + } + ] + }, + { + "id": "test3", + "label": "Test 3", + "type": "raw", + "count": "0" + } + ] + } + )*"; + + sr::Specification spec; + sr::SpecList specList; + + spec.setFromString( jsonString ); + specList.addSpecification( spec ); + + std::stringbuf buffer; + buffer.str( "FILE reader" ); + fr::FileReader file( &buffer ); + + Comparator comp( &file, specList ); + + rg::Report report; + comp.compare( "test", report ); + + rg::Transform tr( report ); + rg::Export exporter( tr.transformTree( rg::Transform::eReportTypeXml ) ); + + LOG_INFO( "\n==== REPORT ====" ); + // exporter.writeXmlFile( "test_n_child.xml" ); + LOG_INFO( exporter.getXmlString() ); + + std::istringstream xmlStream( exporter.getXmlString() ); + std::istringstream jsonStream( jsonString ); + bpt::ptree xmlReport; + bpt::ptree jsonReport; + bpt::read_xml ( xmlStream, xmlReport ); + bpt::read_json( jsonStream, jsonReport ); + + BOOST_CHECK_EQUAL( xmlReport.size(), jsonReport.get_child( "header" ).size() ); + + std::vector< std::string > xmlIds; + std::vector< std::string > jsonIds; + + fillVectorXml( xmlReport, xmlIds, ".id" ); + fillVectorJson( jsonReport.get_child( "header" ), jsonIds, "id" ); + + BOOST_CHECK_EQUAL( xmlIds.size(), jsonIds.size() ); + for( size_t i = 0; i < xmlIds.size(); ++i ) + BOOST_CHECK_EQUAL( xmlIds.at(i), jsonIds.at(i) ); + } +} + + +BOOST_AUTO_TEST_CASE( comparator_comparator_one_subchild ) +{ + LOG_WARNING( ">>> comparator_comparator_one_subchild <<<" ); + { + std::string jsonString = R"*( + { + "standard": + { + "id": "test", + "extension": [ + "ext1", + "ext2", + "ext3"] + }, + "header": [ + { + "id": "test1", + "label": "Test 1", + "type": "hexa", + "count": "0" + }, + { + "id": "test2", + "label": "Test 2", + "type": "ascii", + "count": "0", + "group": [ + { + "id": "child1", + "label": "Child 1", + "type": "hexa", + "values": "ff00" + }, + { + "id": "child2", + "label": "Child 2", + "type": "hexa", + "values": "00ff", + "group": [ + { + "id": "child21", + "label": "Child 21", + "type": "hexa", + "values": "00ff" + } + ] + } + ] + }, + { + "id": "test3", + "label": "Test 3", + "type": "raw", + "count": "0" + } + ] + } + )*"; + + sr::Specification spec; + sr::SpecList specList; + + spec.setFromString( jsonString ); + specList.addSpecification( spec ); + + std::stringbuf buffer; + buffer.str( "FILE reader" ); + fr::FileReader file( &buffer ); + + Comparator comp( &file, specList ); + + rg::Report report; + comp.compare( "test", report ); + + rg::Transform tr( report ); + rg::Export exporter( tr.transformTree( rg::Transform::eReportTypeXml ) ); + + LOG_INFO( "\n==== REPORT ====" ); + // exporter.writeXmlFile( "test_one_subchild.xml" ); + LOG_INFO( exporter.getXmlString() ); + + std::istringstream xmlStream( exporter.getXmlString() ); + std::istringstream jsonStream( jsonString ); + bpt::ptree xmlReport; + bpt::ptree jsonReport; + bpt::read_xml ( xmlStream, xmlReport ); + bpt::read_json( jsonStream, jsonReport ); + + BOOST_CHECK_EQUAL( xmlReport.size(), jsonReport.get_child( "header" ).size() ); + + std::vector< std::string > xmlIds; + std::vector< std::string > jsonIds; + + fillVectorXml( xmlReport, xmlIds, ".id" ); + fillVectorJson( jsonReport.get_child( "header" ), jsonIds, "id" ); + + BOOST_CHECK_EQUAL( xmlIds.size(), jsonIds.size() ); + for( size_t i = 0; i < xmlIds.size(); ++i ) + BOOST_CHECK_EQUAL( xmlIds.at(i), jsonIds.at(i) ); + } +} + +BOOST_AUTO_TEST_CASE( comparator_comparator_n_subchildren ) +{ + LOG_WARNING( ">>> comparator_comparator_n_subchildren <<<" ); + { + std::string jsonString = R"*( + { + "standard": + { + "id": "test", + "extension": [ + "ext1", + "ext2", + "ext3"] + }, + "header": [ + { + "id": "test1", + "label": "Test 1", + "type": "hexa", + "count": "0" + }, + { + "id": "test2", + "label": "Test 2", + "type": "ascii", + "count": "0", + "group": [ + { + "id": "child1", + "label": "Child 1", + "type": "hexa", + "values": "ff00" + }, + { + "id": "child2", + "label": "Child 2", + "type": "hexa", + "values": "00ff", + "group": [ + { + "id": "child21", + "label": "Child 21", + "type": "hexa", + "values": "00ff" + }, + { + "id": "child22", + "label": "Child 22", + "type": "hexa", + "values": "00ff" + } + ] + } + ] + }, + { + "id": "test3", + "label": "Test 3", + "type": "raw", + "count": "0" + } + ] + } + )*"; + + sr::Specification spec; + sr::SpecList specList; + + spec.setFromString( jsonString ); + specList.addSpecification( spec ); + + std::stringbuf buffer; + buffer.str( "FILE reader" ); + fr::FileReader file( &buffer ); + + Comparator comp( &file, specList ); + + rg::Report report; + comp.compare( "test", report ); + + rg::Transform tr( report ); + rg::Export exporter( tr.transformTree( rg::Transform::eReportTypeXml ) ); + + LOG_INFO( "\n==== REPORT ====" ); + // exporter.writeXmlFile( "test_n_subchildren.xml" ); + LOG_INFO( exporter.getXmlString() ); + + std::istringstream xmlStream( exporter.getXmlString() ); + std::istringstream jsonStream( jsonString ); + bpt::ptree xmlReport; + bpt::ptree jsonReport; + bpt::read_xml ( xmlStream, xmlReport ); + bpt::read_json( jsonStream, jsonReport ); + + BOOST_CHECK_EQUAL( xmlReport.size(), jsonReport.get_child( "header" ).size() ); + + std::vector< std::string > xmlIds; + std::vector< std::string > jsonIds; + + fillVectorXml( xmlReport, xmlIds, ".id" ); + fillVectorJson( jsonReport.get_child( "header" ), jsonIds, "id" ); + + BOOST_CHECK_EQUAL( xmlIds.size(), jsonIds.size() ); + for( size_t i = 0; i < xmlIds.size(); ++i ) + BOOST_CHECK_EQUAL( xmlIds.at(i), jsonIds.at(i) ); + } +} + +BOOST_AUTO_TEST_CASE( comparator_comparator_n_levels ) +{ + LOG_WARNING( ">>> comparator_comparator_n_levels <<<" ); + { + std::string jsonString = R"*( + { + "standard": + { + "id": "test", + "extension": [ + "ext1", + "ext2", + "ext3"] + }, + "header": [ + { + "id": "test1", + "label": "Test 1", + "type": "hexa", + "count": "0" + }, + { + "id": "test2", + "label": "Test 2", + "type": "ascii", + "count": "0", + "group": [ + { + "id": "child1", + "label": "Child 1", + "type": "hexa", + "values": "4649" + }, + { + "id": "child2", + "label": "Child 2", + "type": "hexa", + "values": "4c45", + "group": [ + { + "id": "child21", + "label": "Child 21", + "type": "hexa", + "values": "2072", + "group": [ + { + "id": "child211", + "label": "Child 211", + "type": "hexa", + "values": "6561" + }, + { + "id": "child212", + "label": "Child 212", + "type": "hexa", + "values": "6465", + "group": [ + { + "id": "child2121", + "label": "Child 2121", + "type": "hexa", + "values": "7220" + }, + { + "id": "child2122", + "label": "Child 2122", + "type": "hexa", + "values": "2020", + "group": [ + { + "id": "child21221", + "label": "Child 21221", + "type": "hexa", + "values": "2020" + } + ] + } + ] + } + ] + }, + { + "id": "child22", + "label": "Child 22", + "type": "hexa", + "values": "7265" + } + ] + } + ] + }, + { + "id": "test3", + "label": "Test 3", + "type": "raw", + "count": "0", + "group": [ + { + "id": "child31", + "label": "Child 31", + "type": "hexa", + "values": "6461", + "group": [ + { + "id": "child311", + "label": "Child 311", + "type": "hexa", + "values": "6572", + "group": [ + { + "id": "child3111", + "label": "Child 3111", + "type": "hexa", + "values": "2045" + } + ] + } + ] + } + ] + } + ] + } + )*"; + + sr::Specification spec; + sr::SpecList specList; + + spec.setFromString( jsonString ); + specList.addSpecification( spec ); + + std::stringbuf buffer; + buffer.str( "FILE reader redaer ELIF" ); + fr::FileReader file( &buffer ); + + Comparator comp( &file, specList ); + + rg::Report report; + comp.compare( "test", report ); + + rg::Transform tr( report ); + rg::Export exporter( tr.transformTree( rg::Transform::eReportTypeXml ) ); + + LOG_INFO( "\n==== REPORT ====" ); + // exporter.writeXmlFile( "test_n_levels.xml" ); + LOG_INFO( exporter.getXmlString() ); + + std::istringstream xmlStream( exporter.getXmlString() ); + std::istringstream jsonStream( jsonString ); + bpt::ptree xmlReport; + bpt::ptree jsonReport; + bpt::read_xml ( xmlStream, xmlReport ); + bpt::read_json( jsonStream, jsonReport ); + + BOOST_CHECK_EQUAL( xmlReport.size(), jsonReport.get_child( "header" ).size() ); + + std::vector< std::string > xmlIds; + std::vector< std::string > jsonIds; + + fillVectorXml( xmlReport, xmlIds, ".id" ); + fillVectorJson( jsonReport.get_child( "header" ), jsonIds, "id" ); + + BOOST_CHECK_EQUAL( xmlIds.size(), jsonIds.size() ); + for( size_t i = 0; i < xmlIds.size(); ++i ) + BOOST_CHECK_EQUAL( xmlIds.at(i), jsonIds.at(i) ); + } +} + +BOOST_AUTO_TEST_CASE( comparator_comparator_n_levels_2 ) +{ + LOG_WARNING( ">>> comparator_comparator_n_levels_2 <<<" ); + { + std::string jsonString = R"*( + { + "standard": + { + "id": "test", + "extension": [ + "ext1", + "ext2", + "ext3"] + }, + "header": [ + { + "id": "test1", + "label": "Test 1", + "type": "uint8" + }, + { + "id": "test2", + "label": "Test 2", + "type": "ascii", + "count": "0", + "group": [ + { + "id": "child1", + "label": "Child 1", + "type": "uint32" + }, + { + "id": "child2", + "label": "Child 2", + "type": "int8", + "group": [ + { + "id": "child21", + "label": "Child 21", + "type": "hexa", + "values": "00ff", + "group": [ + { + "id": "child211", + "label": "Child 211", + "type": "float" + }, + { + "id": "child212", + "label": "Child 212", + "type": "double", + "group": [ + { + "id": "child2121", + "label": "Child 2121", + "type": "ieeeExtended" + }, + { + "id": "child2122", + "label": "Child 2122", + "type": "uint64", + "group": [ + { + "id": "child21221", + "label": "Child 21221", + "type": "int32" + } + ] + } + ] + } + ] + }, + { + "id": "child22", + "label": "Child 22", + "type": "int16" + } + ] + } + ] + } + ] + } + )*"; + + sr::Specification spec; + sr::SpecList specList; + + spec.setFromString( jsonString ); + specList.addSpecification( spec ); + + std::stringbuf buffer; + buffer.str( "FILE reader 1.0 vs. 0.1 redaer ELIF ? " ); + fr::FileReader file( &buffer ); + + Comparator comp( &file, specList ); + + rg::Report report; + comp.compare( "test", report ); + + rg::Transform tr( report ); + rg::Export exporter( tr.transformTree( rg::Transform::eReportTypeXml ) ); + + LOG_INFO( "\n==== REPORT ====" ); + // exporter.writeXmlFile( "test_n_levels_2.xml" ); + LOG_INFO( exporter.getXmlString() ); + + std::istringstream xmlStream( exporter.getXmlString() ); + std::istringstream jsonStream( jsonString ); + bpt::ptree xmlReport; + bpt::ptree jsonReport; + bpt::read_xml ( xmlStream, xmlReport ); + bpt::read_json( jsonStream, jsonReport ); + + BOOST_CHECK_EQUAL( xmlReport.size(), jsonReport.get_child( "header" ).size() ); + + std::vector< std::string > xmlIds; + std::vector< std::string > jsonIds; + + fillVectorXml( xmlReport, xmlIds, ".id" ); + fillVectorJson( jsonReport.get_child( "header" ), jsonIds, "id" ); + + BOOST_CHECK_EQUAL( xmlIds.size(), jsonIds.size() ); + for( size_t i = 0; i < xmlIds.size(); ++i ) + BOOST_CHECK_EQUAL( xmlIds.at(i), jsonIds.at(i) ); + } +} + BOOST_AUTO_TEST_CASE( comparator_comparator_validation_1 ) { LOG_WARNING( ">>> comparator_comparator_validation_1 <<<" ); diff --git a/libraries/comparator/tests/comparatorTestsRepetitions.hpp b/libraries/comparator/tests/comparatorTestsRepetitions.hpp index a80c115..9095628 100644 --- a/libraries/comparator/tests/comparatorTestsRepetitions.hpp +++ b/libraries/comparator/tests/comparatorTestsRepetitions.hpp @@ -467,8 +467,8 @@ BOOST_AUTO_TEST_CASE( comparator_comparator_validation_repetition_range_group ) ], "group": [ { - "id": "element2.1.1", - "label": "Element 2.1.1", + "id": "element4.1.1", + "label": "Element 4.1.1", "type": "ascii", "values": "£", "repeated": [ @@ -513,7 +513,7 @@ BOOST_AUTO_TEST_CASE( comparator_comparator_validation_repetition_range_group ) str += "digit°+-+---/"; str += "max$£$£££"; str += "max$£$£££$££"; - str += "max$$££$£$£"; + str += "max$££$£$£"; str += "max$£$£££$££"; str += "max$£$£££"; str += "n"; @@ -569,4 +569,149 @@ BOOST_AUTO_TEST_CASE( comparator_comparator_validation_repetition_range_group ) } } +BOOST_AUTO_TEST_CASE( comparator_comparator_validation_repetition_range_group_complex ) +{ + LOG_WARNING( ">>> comparator_comparator_validation_repetition_range_group_complex <<<" ); + { + std::string jsonString = R"*( + { + "standard": + { + "id": "test", + "extension": [ + "ext1" + ] + }, + "header": [ + { + "id": "file", + "label": "FILE", + "type": "ascii", + "values": "group", + "group": [ + { + "id": "repetition", + "label": "Repetition", + "type": "uint8" + }, + { + "id": "elementMinOut", + "label": "Element Min Out", + "type": "ascii", + "values": "n", + "repeated": [ + { "min": "2", "max": "4" } + ] + }, + { + "id": "elementMaxOut", + "label": "Element Max Out", + "type": "ascii", + "values": "p", + "repeated": [ + { "min": "2", "max": "4" } + ] + }, + { + "id": "elementMulti", + "label": "Element Multi", + "type": "ascii", + "values": "m", + "repeated": [ + { "min": "4" }, + { "max": "2" } + ] + }, + { + "id": "elementMultiOut", + "label": "Element Multi Out", + "type": "ascii", + "values": "o", + "repeated": [ + { "min": "4" }, + { "max": "2" } + ] + }, + { + "id": "elementDoubleMulti", + "label": "Element Double Multi", + "type": "ascii", + "values": "d", + "repeated": [ + { "min": 5, "max": 6 }, + { "min": 2, "max": 3 } + ] + }, + { + "id": "elementDoubleMultiOut", + "label": "Element Double Multi Out", + "type": "ascii", + "values": "u", + "repeated": [ + { "min": 5, "max": 6 }, + { "min": 2, "max": 3 } + ] + }, + { + "id": "elementEnd", + "label": "Element End", + "type": "ascii", + "values": "end", + "repeated": [ + { "min": "2" } + ] + } + ] + } + ] + } + )*"; + + sr::Specification spec; + sr::SpecList specList; + + spec.setFromString( jsonString ); + specList.addSpecification( spec ); + + std::stringbuf buffer; + std::string str = "group"; + str += " "; + str += "n"; + str += "ppppp"; + str += "mmmm"; + str += "ooo"; + str += "dddddd"; + str += "uuuu"; + str += "end"; + buffer.str( str ); + fr::FileReader file( &buffer ); + + Comparator comp( &file, specList ); + + rg::Report report; + comp.compare( "test", report ); + + rg::Transform tr( report ); + rg::Export exporter( tr.transformTree( rg::Transform::eReportTypeXml ) ); + + LOG_INFO( "\n==== REPORT ====" ); + LOG_INFO( exporter.getXmlString() ); + + std::istringstream xmlStream( exporter.getXmlString() ); + std::istringstream jsonStream( jsonString ); + bpt::ptree xmlReport; + bpt::ptree jsonReport; + bpt::read_xml ( xmlStream, xmlReport ); + bpt::read_json( jsonStream, jsonReport ); + + BOOST_CHECK_EQUAL( xmlReport.size(), jsonReport.get_child( "header" ).size() ); + + std::vector< std::string > xmlIds; + std::vector< std::string > jsonIds; + + fillVectorXml( xmlReport, xmlIds, ".id" ); + fillVectorJson( jsonReport.get_child( "header" ), jsonIds, "id" ); + } +} + BOOST_AUTO_TEST_SUITE_END()