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