added more tests to increase test coverage
[senf.git] / Packets / MPEGDVBBundle / DTCPPacket.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 //     Stefan Bund <g0dil@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 DTCPPacket.test unit tests */
25
26 //#include "DTCPPacket.test.hh"
27 //#include "DTCPPacket.test.ih"
28
29 // Custom includes
30 #include "DTCPPacket.hh"
31 #include "../../Utils/String.hh"
32
33 #include "../../Utils/auto_unit_test.hh"
34 #include <boost/test/test_tools.hpp>
35
36 #define prefix_
37 ///////////////////////////////cc.p////////////////////////////////////////
38
39 BOOST_AUTO_UNIT_TEST(dtcpPacket)
40 {
41     unsigned char data[] = { 0x11,                 // versionNumber = 1, command = JOIN
42                              5,                    // interval
43                              0x0A, 0x0B,           // sequence number
44                              0x14,                 // receiveCapable = true, ipVersion = 4
45                              23,                   // tunnelProtocol
46                              2,                    // fbipCount
47                              0x00,
48                              101, 102, 103, 104,   // fbip1
49                              201, 202, 203, 204 }; // fbip2
50
51     senf::DTCPHelloPacket hello (senf::DTCPHelloPacket::create(
52                                      boost::make_iterator_range(data, data+sizeof(data))));
53
54     BOOST_CHECK_EQUAL_COLLECTIONS( data, data+sizeof(data),
55                                    hello.data().begin(), hello.data().end() );
56
57     BOOST_CHECK_EQUAL( senf::bytes(hello.parser()), 16u );
58
59     BOOST_CHECK_EQUAL( hello->versionNumber(), 1u );
60     BOOST_CHECK_EQUAL( hello->command(), unsigned(senf::DTCPHelloPacket::Parser::JOIN) );
61     BOOST_CHECK_EQUAL( hello->interval(), 5u );
62     BOOST_CHECK_EQUAL( hello->sequenceNumber(), 0x0A0Bu );
63     BOOST_CHECK_EQUAL( hello->receiveCapableFeed(), true );
64     BOOST_CHECK_EQUAL( hello->ipVersion(), 4u );
65     BOOST_CHECK_EQUAL( hello->tunnelProtocol(), 23u );
66     BOOST_CHECK_EQUAL( hello->fbipCount(), 2u );
67     BOOST_CHECK( hello->has_v4fbipList() );
68     BOOST_CHECK_EQUAL( senf::str(hello->v4fbipList()[0]), "101.102.103.104" );
69     BOOST_CHECK_EQUAL( senf::str(hello->v4fbipList()[1]), "201.202.203.204" );
70
71     std::stringstream ss;
72     hello.dump(ss);
73     BOOST_CHECK_EQUAL( ss.str(), 
74                        "DTCP HELLO Packet:\n"
75                        "  version              : 1\n"
76                        "  command              : JOIN\n"
77                        "  interval             : 5\n"
78                        "  sequence number      : 2571\n"
79                        "  receive capable feed : yes\n"
80                        "  ip version           : 4\n"
81                        "  tunnel protocol      : 23\n"
82                        "  number of BDL ips    : 2\n"
83                        "  feed BDL ips         : \n"
84                        "    101.102.103.104\n"
85                        "    201.202.203.204\n" );
86
87     senf::DTCPHelloPacket hello2 (senf::DTCPHelloPacket::create());
88
89     SENF_CHECK_NO_THROW( hello2->versionNumber() = 1u );
90     SENF_CHECK_NO_THROW( hello2->command() = senf::DTCPHelloPacket::Parser::JOIN );
91     SENF_CHECK_NO_THROW( hello2->interval() = 5u );
92     SENF_CHECK_NO_THROW( hello2->sequenceNumber() = 0x0A0B );
93     SENF_CHECK_NO_THROW( hello2->receiveCapableFeed() = true );
94     SENF_CHECK_NO_THROW( hello2->tunnelProtocol() = 23u );
95     SENF_CHECK_NO_THROW( hello2->init_v4fbipList() );
96     SENF_CHECK_NO_THROW( hello2->v4fbipList().push_back( senf::INet4Address(0x65666768u) ) );
97     SENF_CHECK_NO_THROW( hello2->v4fbipList().push_back( senf::INet4Address(0xC9CACBCCu) ) );
98
99     BOOST_CHECK_EQUAL( senf::bytes(hello2.parser()), 16u );
100     BOOST_CHECK_EQUAL_COLLECTIONS( data, data+sizeof(data),
101                                    hello2.data().begin(), hello2.data().end() );
102 }
103
104 ///////////////////////////////cc.e////////////////////////////////////////
105 #undef prefix_
106
107 \f
108 // Local Variables:
109 // mode: c++
110 // fill-column: 100
111 // comment-column: 40
112 // c-file-style: "senf"
113 // indent-tabs-mode: nil
114 // ispell-local-dictionary: "american"
115 // compile-command: "scons -u test"
116 // End: