4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Thorsten Horstmann <tho@berlios.de>
29 \brief psi2ts unit tests */
32 #include <senf/PPI/DebugModules.hh>
33 #include <senf/PPI/Setup.hh>
34 #include <senf/Packets/MPEGDVBBundle/MPESection.hh>
35 #include <senf/Packets/MPEGDVBBundle/TransportPacket.hh>
38 #include <senf/Utils/auto_unit_test.hh>
39 #include <boost/test/test_tools.hpp>
40 #include <boost/lambda/lambda.hpp>
43 //-/////////////////////////////////////////////////////////////////////////////////////////////////
45 void check_transportpacket_header(senf::TransportPacket tsPacket, bool pusi, unsigned pid, unsigned counter)
47 BOOST_CHECK_EQUAL( tsPacket->sync_byte(), senf::TransportPacketType::SYNC_BYTE+0 );
48 BOOST_CHECK_EQUAL( tsPacket->transport_error_indicator(), false );
49 BOOST_CHECK_EQUAL( tsPacket->pusi(), pusi );
50 BOOST_CHECK_EQUAL( tsPacket->transport_priority(), false );
51 BOOST_CHECK_EQUAL( tsPacket->transport_scrmbl_ctrl(), 0x0u );
52 BOOST_CHECK_EQUAL( tsPacket->adaptation_field_ctrl(), 0x1u );
53 BOOST_CHECK_EQUAL( tsPacket->continuity_counter(), counter );
55 BOOST_CHECK_EQUAL( tsPacket->pointer_field(), 0x0u );
59 template<class InputIterator, class T>
60 bool equal_elements(InputIterator first, InputIterator last, const T& value)
62 return std::find_if( first, last, boost::lambda::_1 != value) == last;
66 SENF_AUTO_UNIT_TEST(one_section_to_one_transportpacket)
68 senf::ppi::module::debug::ActiveSource source;
69 senf::ppi::module::debug::PassiveSink sink;
71 Psi2TsModule psi2ts (PID);
73 senf::ppi::connect( source, psi2ts);
74 senf::ppi::connect( psi2ts, sink);
77 std::string sec_data ( "psi2ts_test: one_section_to_one_transportpacket");
78 senf::Packet sec_packet (senf::DataPacket::create(sec_data));
79 sec_packet.finalize();
81 source.submit(sec_packet);
82 BOOST_CHECK_EQUAL( sink.size(), 1u);
84 senf::TransportPacket ts_packet = sink.pop_front().as<senf::TransportPacket>();
85 check_transportpacket_header( ts_packet, true, PID, 1);
86 senf::PacketData & ts_payload_data = ts_packet.next().data();
87 BOOST_CHECK_EQUAL_COLLECTIONS(
88 ts_payload_data.begin(),
89 boost::next( ts_payload_data.begin(), sec_data.size()),
92 BOOST_CHECK( equal_elements(
93 boost::next( ts_payload_data.begin(), ts_payload_data.size()),
94 ts_payload_data.end(),
98 SENF_AUTO_UNIT_TEST(one_section_to_two_transportpackets)
100 senf::ppi::module::debug::ActiveSource source;
101 senf::ppi::module::debug::PassiveSink sink;
103 Psi2TsModule psi2ts (PID);
105 senf::ppi::connect( source, psi2ts);
106 senf::ppi::connect( psi2ts, sink);
109 std::string sec_data ( 183, 0x42);
110 std::string sec_data2 ( "psi2ts_test: one_section_to_two_transportpackets");
111 sec_data.append( sec_data2);
112 senf::Packet sec_packet (senf::DataPacket::create(sec_data));
113 sec_packet.finalize();
115 source.submit( sec_packet);
116 BOOST_CHECK_EQUAL( sink.size(), 2u);
118 senf::TransportPacket ts_packet = sink.pop_front().as<senf::TransportPacket>();
119 check_transportpacket_header( ts_packet, true, PID, 1);
120 senf::PacketData & ts_payload_data1 = ts_packet.next().data();
122 BOOST_CHECK( equal_elements( ts_payload_data1.begin(), ts_payload_data1.end(), 0x42));
124 ts_packet = sink.pop_front().as<senf::TransportPacket>();
125 check_transportpacket_header( ts_packet, false, PID, 2);
126 senf::PacketData & ts_payload_data2 = ts_packet.next().data();
127 BOOST_CHECK_EQUAL_COLLECTIONS(
128 ts_payload_data2.begin(),
129 boost::next( ts_payload_data2.begin(), sec_data2.size()),
132 BOOST_CHECK( equal_elements(
133 boost::next( ts_payload_data2.begin(), sec_data2.size()),
134 ts_payload_data2.end(),
138 SENF_AUTO_UNIT_TEST(many_sections_to_many_transportpackets)
140 senf::ppi::module::debug::ActiveSource source;
141 senf::ppi::module::debug::PassiveSink sink;
143 Psi2TsModule psi2ts (PID);
145 senf::ppi::connect( source, psi2ts);
146 senf::ppi::connect( psi2ts, sink);
149 std::string sec_data ( "many_sections_to_many_transportpackets");
150 senf::Packet sec_packet (senf::DataPacket::create(sec_data));
151 sec_packet.finalize();
153 unsigned NUMBER_OF_SECTIONS = 42u;
154 for (unsigned i=1; i<=NUMBER_OF_SECTIONS; i++) {
155 source.submit( sec_packet);
157 BOOST_CHECK_EQUAL( sink.size(), NUMBER_OF_SECTIONS);
159 for (unsigned i=1; i<=NUMBER_OF_SECTIONS; i++) {
160 senf::TransportPacket ts_packet = sink.pop_front().as<senf::TransportPacket>();
161 check_transportpacket_header( ts_packet, true, PID, i%16);
165 //-/////////////////////////////////////////////////////////////////////////////////////////////////
172 // comment-column: 40
173 // c-file-style: "senf"
174 // indent-tabs-mode: nil
175 // ispell-local-dictionary: "american"
176 // compile-command: "scons -u test"