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