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 <senf/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 );
50 BOOST_CHECK_EQUAL( tsPacket->pointer_field(), 0x0u );
54 template<class InputIterator, class T>
55 bool equal_elements(InputIterator first, InputIterator last, const T& value)
57 return std::find_if( first, last, boost::lambda::_1 != value) == last;
61 SENF_AUTO_UNIT_TEST(one_section_to_one_transportpacket)
63 senf::ppi::module::debug::ActiveSource source;
64 senf::ppi::module::debug::PassiveSink sink;
66 Psi2TsModule psi2ts (PID);
68 senf::ppi::connect( source, psi2ts);
69 senf::ppi::connect( psi2ts, sink);
72 std::string sec_data ( "psi2ts_test: one_section_to_one_transportpacket");
73 senf::Packet sec_packet (senf::DataPacket::create(sec_data));
74 sec_packet.finalize();
76 source.submit(sec_packet);
77 BOOST_CHECK_EQUAL( sink.size(), 1u);
79 senf::TransportPacket ts_packet = sink.pop_front().as<senf::TransportPacket>();
80 check_transportpacket_header( ts_packet, true, PID, 1);
81 senf::PacketData & ts_payload_data = ts_packet.next().data();
82 BOOST_CHECK_EQUAL_COLLECTIONS(
83 ts_payload_data.begin(),
84 boost::next( ts_payload_data.begin(), sec_data.size()),
87 BOOST_CHECK( equal_elements(
88 boost::next( ts_payload_data.begin(), ts_payload_data.size()),
89 ts_payload_data.end(),
93 SENF_AUTO_UNIT_TEST(one_section_to_two_transportpackets)
95 senf::ppi::module::debug::ActiveSource source;
96 senf::ppi::module::debug::PassiveSink sink;
98 Psi2TsModule psi2ts (PID);
100 senf::ppi::connect( source, psi2ts);
101 senf::ppi::connect( psi2ts, sink);
104 std::string sec_data ( 183, 0x42);
105 std::string sec_data2 ( "psi2ts_test: one_section_to_two_transportpackets");
106 sec_data.append( sec_data2);
107 senf::Packet sec_packet (senf::DataPacket::create(sec_data));
108 sec_packet.finalize();
110 source.submit( sec_packet);
111 BOOST_CHECK_EQUAL( sink.size(), 2u);
113 senf::TransportPacket ts_packet = sink.pop_front().as<senf::TransportPacket>();
114 check_transportpacket_header( ts_packet, true, PID, 1);
115 senf::PacketData & ts_payload_data1 = ts_packet.next().data();
117 BOOST_CHECK( equal_elements( ts_payload_data1.begin(), ts_payload_data1.end(), 0x42));
119 ts_packet = sink.pop_front().as<senf::TransportPacket>();
120 check_transportpacket_header( ts_packet, false, PID, 2);
121 senf::PacketData & ts_payload_data2 = ts_packet.next().data();
122 BOOST_CHECK_EQUAL_COLLECTIONS(
123 ts_payload_data2.begin(),
124 boost::next( ts_payload_data2.begin(), sec_data2.size()),
127 BOOST_CHECK( equal_elements(
128 boost::next( ts_payload_data2.begin(), sec_data2.size()),
129 ts_payload_data2.end(),
133 SENF_AUTO_UNIT_TEST(many_sections_to_many_transportpackets)
135 senf::ppi::module::debug::ActiveSource source;
136 senf::ppi::module::debug::PassiveSink sink;
138 Psi2TsModule psi2ts (PID);
140 senf::ppi::connect( source, psi2ts);
141 senf::ppi::connect( psi2ts, sink);
144 std::string sec_data ( "many_sections_to_many_transportpackets");
145 senf::Packet sec_packet (senf::DataPacket::create(sec_data));
146 sec_packet.finalize();
148 unsigned NUMBER_OF_SECTIONS = 42u;
149 for (unsigned i=1; i<=NUMBER_OF_SECTIONS; i++) {
150 source.submit( sec_packet);
152 BOOST_CHECK_EQUAL( sink.size(), NUMBER_OF_SECTIONS);
154 for (unsigned i=1; i<=NUMBER_OF_SECTIONS; i++) {
155 senf::TransportPacket ts_packet = sink.pop_front().as<senf::TransportPacket>();
156 check_transportpacket_header( ts_packet, true, PID, i%16);
160 ///////////////////////////////cc.e////////////////////////////////////////
167 // comment-column: 40
168 // c-file-style: "senf"
169 // indent-tabs-mode: nil
170 // ispell-local-dictionary: "american"
171 // compile-command: "scons -u test"