X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Examples%2Fpsi2tsModule%2Fpsi2ts.test.cc;h=f2faa710044040965a424130ddcd4019e4407b88;hb=b2fff1b50e0010fdad28cb638987cbf88032e30e;hp=b57e39c262ae5c08cb7ba8ebb265a0dc2d47bc99;hpb=e995ef1b4ad86acdd5a104a21f375ef4360db743;p=senf.git diff --git a/Examples/psi2tsModule/psi2ts.test.cc b/Examples/psi2tsModule/psi2ts.test.cc index b57e39c..f2faa71 100644 --- a/Examples/psi2tsModule/psi2ts.test.cc +++ b/Examples/psi2tsModule/psi2ts.test.cc @@ -2,41 +2,167 @@ // // Copyright (C) 2008 // Fraunhofer Institute for Open Communication Systems (FOKUS) -// Competence Center NETwork research (NET), St. Augustin, GERMANY -// Thorsten Horstmann // -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. +// The contents of this file are subject to the Fraunhofer FOKUS Public License +// Version 1.0 (the "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// http://senf.berlios.de/license.html // -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. +// The Fraunhofer FOKUS Public License Version 1.0 is based on, +// but modifies the Mozilla Public License Version 1.1. +// See the full license text for the amendments. // -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the -// Free Software Foundation, Inc., -// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// Software distributed under the License is distributed on an "AS IS" basis, +// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +// for the specific language governing rights and limitations under the License. +// +// The Original Code is Fraunhofer FOKUS code. +// +// The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. +// (registered association), Hansastraße 27 c, 80686 Munich, Germany. +// All Rights Reserved. +// +// Contributor(s): +// Thorsten Horstmann /** \file \brief psi2ts unit tests */ // Custom includes +#include +#include +#include +#include #include "psi2ts.hh" -#include "../../Utils/auto_unit_test.hh" +#include #include +#include #define prefix_ -///////////////////////////////cc.p//////////////////////////////////////// -BOOST_AUTO_UNIT_TEST(one_section_to_one_transportpacket) +//-///////////////////////////////////////////////////////////////////////////////////////////////// + +void check_transportpacket_header(senf::TransportPacket tsPacket, bool pusi, unsigned pid, unsigned counter) +{ + BOOST_CHECK_EQUAL( tsPacket->sync_byte(), senf::TransportPacketType::SYNC_BYTE+0 ); + BOOST_CHECK_EQUAL( tsPacket->transport_error_indicator(), false ); + BOOST_CHECK_EQUAL( tsPacket->pusi(), pusi ); + BOOST_CHECK_EQUAL( tsPacket->transport_priority(), false ); + BOOST_CHECK_EQUAL( tsPacket->transport_scrmbl_ctrl(), 0x0u ); + BOOST_CHECK_EQUAL( tsPacket->adaptation_field_ctrl(), 0x1u ); + BOOST_CHECK_EQUAL( tsPacket->continuity_counter(), counter ); + if (pusi) + BOOST_CHECK_EQUAL( tsPacket->pointer_field(), 0x0u ); + +} + +template +bool equal_elements(InputIterator first, InputIterator last, const T& value) +{ + return std::find_if( first, last, boost::lambda::_1 != value) == last; +} + + +SENF_AUTO_UNIT_TEST(one_section_to_one_transportpacket) +{ + senf::ppi::module::debug::ActiveSource source; + senf::ppi::module::debug::PassiveSink sink; + unsigned PID = 42; + Psi2TsModule psi2ts (PID); + + senf::ppi::connect( source, psi2ts); + senf::ppi::connect( psi2ts, sink); + senf::ppi::init(); + + std::string sec_data ( "psi2ts_test: one_section_to_one_transportpacket"); + senf::Packet sec_packet (senf::DataPacket::create(sec_data)); + sec_packet.finalize(); + + source.submit(sec_packet); + BOOST_CHECK_EQUAL( sink.size(), 1u); + + senf::TransportPacket ts_packet = sink.pop_front().as(); + check_transportpacket_header( ts_packet, true, PID, 1); + senf::PacketData & ts_payload_data = ts_packet.next().data(); + BOOST_CHECK_EQUAL_COLLECTIONS( + ts_payload_data.begin(), + boost::next( ts_payload_data.begin(), sec_data.size()), + sec_data.begin(), + sec_data.end()); + BOOST_CHECK( equal_elements( + boost::next( ts_payload_data.begin(), ts_payload_data.size()), + ts_payload_data.end(), + 0xffu)); +} + +SENF_AUTO_UNIT_TEST(one_section_to_two_transportpackets) +{ + senf::ppi::module::debug::ActiveSource source; + senf::ppi::module::debug::PassiveSink sink; + unsigned PID = 42; + Psi2TsModule psi2ts (PID); + + senf::ppi::connect( source, psi2ts); + senf::ppi::connect( psi2ts, sink); + senf::ppi::init(); + + std::string sec_data ( 183, 0x42); + std::string sec_data2 ( "psi2ts_test: one_section_to_two_transportpackets"); + sec_data.append( sec_data2); + senf::Packet sec_packet (senf::DataPacket::create(sec_data)); + sec_packet.finalize(); + + source.submit( sec_packet); + BOOST_CHECK_EQUAL( sink.size(), 2u); + + senf::TransportPacket ts_packet = sink.pop_front().as(); + check_transportpacket_header( ts_packet, true, PID, 1); + senf::PacketData & ts_payload_data1 = ts_packet.next().data(); + + BOOST_CHECK( equal_elements( ts_payload_data1.begin(), ts_payload_data1.end(), 0x42)); + + ts_packet = sink.pop_front().as(); + check_transportpacket_header( ts_packet, false, PID, 2); + senf::PacketData & ts_payload_data2 = ts_packet.next().data(); + BOOST_CHECK_EQUAL_COLLECTIONS( + ts_payload_data2.begin(), + boost::next( ts_payload_data2.begin(), sec_data2.size()), + sec_data2.begin(), + sec_data2.end()); + BOOST_CHECK( equal_elements( + boost::next( ts_payload_data2.begin(), sec_data2.size()), + ts_payload_data2.end(), + 0xffu)); +} + +SENF_AUTO_UNIT_TEST(many_sections_to_many_transportpackets) { - BOOST_CHECK_EQUAL(1, 1+0); + senf::ppi::module::debug::ActiveSource source; + senf::ppi::module::debug::PassiveSink sink; + unsigned PID = 42; + Psi2TsModule psi2ts (PID); + + senf::ppi::connect( source, psi2ts); + senf::ppi::connect( psi2ts, sink); + senf::ppi::init(); + + std::string sec_data ( "many_sections_to_many_transportpackets"); + senf::Packet sec_packet (senf::DataPacket::create(sec_data)); + sec_packet.finalize(); + + unsigned NUMBER_OF_SECTIONS = 42u; + for (unsigned i=1; i<=NUMBER_OF_SECTIONS; i++) { + source.submit( sec_packet); + } + BOOST_CHECK_EQUAL( sink.size(), NUMBER_OF_SECTIONS); + + for (unsigned i=1; i<=NUMBER_OF_SECTIONS; i++) { + senf::TransportPacket ts_packet = sink.pop_front().as(); + check_transportpacket_header( ts_packet, true, PID, i%16); + } } -///////////////////////////////cc.e//////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// #undef prefix_