e34aa91befc6e499a21636467472a10b5dee22d9
[senf.git] / Examples / psi2tsModule / psi2ts.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2008
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Thorsten Horstmann <tho@berlios.de>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \file
24     \brief psi2ts unit tests */
25
26 // Custom includes
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>
31 #include "psi2ts.hh"
32
33 #include "../../Utils/auto_unit_test.hh"
34 #include <boost/test/test_tools.hpp>
35 #include <boost/lambda/lambda.hpp>
36
37 #define prefix_
38 ///////////////////////////////cc.p////////////////////////////////////////
39
40 void check_transportpacket_header(senf::TransportPacket tsPacket, bool pusi, unsigned pid, unsigned counter)
41 {
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                                );
49         
50 }
51
52 BOOST_AUTO_UNIT_TEST(one_section_to_one_transportpacket)
53 {
54     senf::ppi::module::debug::ActiveSource source;
55     senf::ppi::module::debug::PassiveSink sink;
56     Psi2TsModule psi2ts;
57     
58     senf::ppi::connect(source, psi2ts);
59     senf::ppi::connect(psi2ts, sink);
60     senf::ppi::init();
61     
62     std::string payload_data ( "psi2ts_test: one_section_to_one_transportpacket");
63     senf::Packet payload (senf::DataPacket::create(payload_data));
64     payload.finalize();
65     
66     source.submit(payload);
67     BOOST_CHECK_EQUAL( sink.size(), 1u);
68
69     senf::TransportPacket tsPacket = sink.pop_front().as<senf::TransportPacket>();
70     check_transportpacket_header( tsPacket, true, 0, 1);
71     senf::PacketData & ts_data = tsPacket.next().data();
72     BOOST_CHECK_EQUAL_COLLECTIONS( 
73             ts_data.begin(), 
74             boost::next( ts_data.begin(), payload_data.size()),
75             payload_data.begin(),
76             payload_data.end());
77 //    BOOST_CHECK( std::find_if( 
78 //            boost::next( ts_data.begin(), payload_data.size()), 
79 //            ts_data.end(),
80 //            boost::lambda::_1 != 0xffu) == ts_data.end() );
81
82 }
83
84 ///////////////////////////////cc.e////////////////////////////////////////
85 #undef prefix_
86
87 \f
88 // Local Variables:
89 // mode: c++
90 // fill-column: 100
91 // comment-column: 40
92 // c-file-style: "senf"
93 // indent-tabs-mode: nil
94 // ispell-local-dictionary: "american"
95 // compile-command: "scons -u test"
96 // End: