4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Thorsten Horstmann <tho@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief psi2ts unit tests */
27 #include "senf/PPI/DebugModules.hh"
28 #include "senf/PPI/Setup.hh"
29 #include <senf/Packets/MPEGDVBBundle/MPESection.hh>
30 #include <senf/Packets/MPEGDVBBundle/TransportPacket.hh>
33 #include "../../Utils/auto_unit_test.hh"
34 #include <boost/test/test_tools.hpp>
35 #include <boost/lambda/lambda.hpp>
38 ///////////////////////////////cc.p////////////////////////////////////////
40 void check_transportpacket_header(senf::TransportPacket tsPacket, bool pusi, unsigned pid, unsigned counter)
42 BOOST_CHECK_EQUAL( tsPacket->sync_byte(), senf::TransportPacketType::SYNC_BYTE+0 );
43 BOOST_CHECK_EQUAL( tsPacket->transport_error_indicator(), false );
44 BOOST_CHECK_EQUAL( tsPacket->pusi(), pusi );
45 BOOST_CHECK_EQUAL( tsPacket->transport_priority(), false );
46 BOOST_CHECK_EQUAL( tsPacket->transport_scrmbl_ctrl(), 0x0u );
47 BOOST_CHECK_EQUAL( tsPacket->adaptation_field_ctrl(), 0x1u );
48 BOOST_CHECK_EQUAL( tsPacket->continuity_counter(), counter );
52 template<class InputIterator, class T>
53 bool equal_elements(InputIterator first, InputIterator last, const T& value)
55 return std::find_if( first, last, boost::lambda::_1 != value) == last;
59 BOOST_AUTO_UNIT_TEST(one_section_to_one_transportpacket)
61 senf::ppi::module::debug::ActiveSource source;
62 senf::ppi::module::debug::PassiveSink sink;
64 Psi2TsModule psi2ts (PID);
66 senf::ppi::connect( source, psi2ts);
67 senf::ppi::connect( psi2ts, sink);
70 std::string sec_data ( "psi2ts_test: one_section_to_one_transportpacket");
71 senf::Packet sec_packet (senf::DataPacket::create(sec_data));
72 sec_packet.finalize();
74 source.submit(sec_packet);
75 BOOST_CHECK_EQUAL( sink.size(), 1u);
77 senf::TransportPacket ts_packet = sink.pop_front().as<senf::TransportPacket>();
78 check_transportpacket_header( ts_packet, true, PID, 1);
79 senf::PacketData & ts_payload_data = ts_packet.next().data();
80 BOOST_CHECK_EQUAL_COLLECTIONS(
81 ts_payload_data.begin(),
82 boost::next( ts_payload_data.begin(), sec_data.size()),
85 BOOST_CHECK( equal_elements(
86 boost::next( ts_payload_data.begin(), ts_payload_data.size()),
87 ts_payload_data.end(),
91 BOOST_AUTO_UNIT_TEST(one_section_to_two_transportpackets)
93 senf::ppi::module::debug::ActiveSource source;
94 senf::ppi::module::debug::PassiveSink sink;
96 Psi2TsModule psi2ts (PID);
98 senf::ppi::connect( source, psi2ts);
99 senf::ppi::connect( psi2ts, sink);
102 std::string sec_data ( 184, 0x42);
103 std::string sec_data2 ( "psi2ts_test: one_section_to_two_transportpackets");
104 sec_data.append( sec_data2);
105 senf::Packet sec_packet (senf::DataPacket::create(sec_data));
106 sec_packet.finalize();
108 source.submit( sec_packet);
109 BOOST_CHECK_EQUAL( sink.size(), 2u);
111 senf::TransportPacket ts_packet = sink.pop_front().as<senf::TransportPacket>();
112 check_transportpacket_header( ts_packet, true, PID, 1);
113 senf::PacketData & ts_payload_data1 = ts_packet.next().data();
114 BOOST_CHECK( equal_elements( ts_payload_data1.begin(), ts_payload_data1.end(), 0x42));
116 ts_packet = sink.pop_front().as<senf::TransportPacket>();
117 check_transportpacket_header( ts_packet, false, PID, 2);
118 senf::PacketData & ts_payload_data2 = ts_packet.next().data();
119 BOOST_CHECK_EQUAL_COLLECTIONS(
120 ts_payload_data2.begin(),
121 boost::next( ts_payload_data2.begin(), sec_data2.size()),
124 BOOST_CHECK( equal_elements(
125 boost::next( ts_payload_data2.begin(), sec_data2.size()),
126 ts_payload_data2.end(),
130 BOOST_AUTO_UNIT_TEST(many_sections_to_many_transportpackets)
132 senf::ppi::module::debug::ActiveSource source;
133 senf::ppi::module::debug::PassiveSink sink;
135 Psi2TsModule psi2ts (PID);
137 senf::ppi::connect( source, psi2ts);
138 senf::ppi::connect( psi2ts, sink);
141 std::string sec_data ( "many_sections_to_many_transportpackets");
142 senf::Packet sec_packet (senf::DataPacket::create(sec_data));
143 sec_packet.finalize();
145 unsigned NUMBER_OF_SECTIONS = 42u;
146 for (unsigned i=1; i<=NUMBER_OF_SECTIONS; i++) {
147 source.submit( sec_packet);
149 BOOST_CHECK_EQUAL( sink.size(), NUMBER_OF_SECTIONS);
151 for (unsigned i=1; i<=NUMBER_OF_SECTIONS; i++) {
152 senf::TransportPacket ts_packet = sink.pop_front().as<senf::TransportPacket>();
153 check_transportpacket_header( ts_packet, true, PID, i%16);
157 ///////////////////////////////cc.e////////////////////////////////////////
164 // comment-column: 40
165 // c-file-style: "senf"
166 // indent-tabs-mode: nil
167 // ispell-local-dictionary: "american"
168 // compile-command: "scons -u test"