Fixed whitespace in all files (no tabs)
[senf.git] / Packets / IpV6Packet.test.cc
1 // Copyright (C) 2007
2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
4 //     Stefan Bund <g0dil@berlios.de>
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
21 /** \file
22     \brief IpV6Packet unit tests */
23
24 //#include "IpV6Packet.test.hh"
25 //#include "IpV6Packet.test.ih"
26
27 // Custom includes
28 #include "IpV6Packet.hh"
29 #include "Socket/INetAddressing.hh"
30
31 #include <boost/test/auto_unit_test.hpp>
32 #include <boost/test/test_tools.hpp>
33
34 #define prefix_
35 ///////////////////////////////cc.p////////////////////////////////////////
36
37 using namespace senf;
38
39 BOOST_AUTO_UNIT_TEST(ipV6Packet_parser)
40 {
41     unsigned char data[] = { 0x60, 0x12, 0x20, 0x30,
42                              0x01, 0x02, 0x03, 0x04,
43                              0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
44                              0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
45                              0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
46                              0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f };
47
48     typedef unsigned char * iterator;
49     Parse_IpV6<iterator> p (data);
50
51     BOOST_CHECK_EQUAL( unsigned(p.version()),       0x06u      );
52     BOOST_CHECK_EQUAL( unsigned(p.trafficClass()),  0x01u      );
53     BOOST_CHECK_EQUAL( unsigned(p.flowLabel()),     0x22030u   );
54     BOOST_CHECK_EQUAL( unsigned(p.length()),        0x0102u    );
55     BOOST_CHECK_EQUAL( unsigned(p.nextHeader()),    0x03u      );
56     BOOST_CHECK_EQUAL( unsigned(p.hopLimit()),      0x04u      );
57     BOOST_CHECK_EQUAL( INet6Address(p.source().range()).address() ,
58                        "1011:1213:1415:1617:1819:1a1b:1c1d:1e1f" );
59     BOOST_CHECK_EQUAL( INet6Address(p.destination().range()).address() ,
60                        "2021:2223:2425:2627:2829:2a2b:2c2d:2e2f" );
61 }
62
63 BOOST_AUTO_UNIT_TEST(ipV6Packet_packet)
64 {
65     unsigned char data[] = { 0x60, 0x12, 0x20, 0x30,
66                              0x01, 0x02, 0x03, 0x04,
67                              0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
68                              0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
69                              0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
70                              0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f };
71
72     IpV6Packet::ptr p (Packet::create<IpV6Packet>(data, data+sizeof(data)));
73
74
75     BOOST_CHECK_EQUAL( unsigned(p->version()),       0x06u      );
76     BOOST_CHECK_EQUAL( unsigned(p->trafficClass()),  0x01u      );
77     BOOST_CHECK_EQUAL( unsigned(p->flowLabel()),     0x22030u   );
78     BOOST_CHECK_EQUAL( unsigned(p->length()),        0x0102u    );
79     BOOST_CHECK_EQUAL( unsigned(p->nextHeader()),    0x03u      );
80     BOOST_CHECK_EQUAL( unsigned(p->hopLimit()),      0x04u      );
81     BOOST_CHECK_EQUAL( INet6Address(p->source().range()).address() ,
82                        "1011:1213:1415:1617:1819:1a1b:1c1d:1e1f" );
83     BOOST_CHECK_EQUAL( INet6Address(p->destination().range()).address() ,
84                        "2021:2223:2425:2627:2829:2a2b:2c2d:2e2f" );
85
86     BOOST_CHECK( p->next() );
87     BOOST_CHECK( p->next()->is<DataPacket>() );
88     BOOST_CHECK_EQUAL( p->next()->size(), 0u );
89 }
90
91 ///////////////////////////////cc.e////////////////////////////////////////
92 #undef prefix_
93
94 \f
95 // Local Variables:
96 // mode: c++
97 // fill-column: 100
98 // c-file-style: "senf"
99 // indent-tabs-mode: nil
100 // ispell-local-dictionary: "american"
101 // End: