switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Packets / DefaultBundle / IPv6Packet.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2007
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 IPv6Packet unit tests */
30
31 //#include "IPv6Packet.test.hh"
32 //#include "IPv6Packet.test.ih"
33
34 // Custom includes
35 #include "IPv6Packet.hh"
36 #include <senf/Socket/Protocols/INet/INetAddressing.hh>
37 #include <senf/Packets/DataPacket.hh>
38
39 #include <senf/Utils/auto_unit_test.hh>
40 #include <boost/test/test_tools.hpp>
41
42 #define prefix_
43 //-/////////////////////////////////////////////////////////////////////////////////////////////////
44
45 SENF_AUTO_UNIT_TEST(ipV6Packet_parse)
46 {
47     unsigned char data[] = {
48             0x60, 0x12, 0x20, 0x30,
49             0x00, 0x01, 0x03, 0x04,
50             0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
51             0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
52             0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
53             0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
54             0xff
55     };
56
57     senf::IPv6Packet p (senf::IPv6Packet::create(data));
58
59     BOOST_CHECK_EQUAL( p->version(),       0x06u      );
60     BOOST_CHECK_EQUAL( p->trafficClass(),  0x01u      );
61     BOOST_CHECK_EQUAL( p->flowLabel(),     0x22030u   );
62     BOOST_CHECK_EQUAL( p->length(),        0x0001u    );
63     BOOST_CHECK_EQUAL( p->nextHeader(),    0x03u      );
64     BOOST_CHECK_EQUAL( p->hopLimit(),      0x04u      );
65     BOOST_CHECK_EQUAL( p->source().value(),
66                        senf::INet6Address::from_string("1011:1213:1415:1617:1819:1a1b:1c1d:1e1f") );
67     BOOST_CHECK_EQUAL( p->destination().value(),
68                        senf::INet6Address::from_string("2021:2223:2425:2627:2829:2a2b:2c2d:2e2f") );
69
70     BOOST_CHECK( p.next() );
71     BOOST_CHECK( p.next().is<senf::DataPacket>() );
72     BOOST_CHECK_EQUAL( p.next().size(), 1u );
73
74     std::ostringstream oss (std::ostringstream::out);
75     SENF_CHECK_NO_THROW( p.dump( oss));
76 }
77
78 SENF_AUTO_UNIT_TEST(ipV6Packet_create)
79 {
80     senf::IPv6Packet ip (senf::IPv6Packet::create());
81
82     ip->trafficClass() = 0x01u;
83     ip->flowLabel() = 0x22030u;
84     ip->hopLimit() = 0x04u;
85     ip->source() = senf::INet6Address::from_string("1011:1213:1415:1617:1819:1a1b:1c1d:1e1f");
86     ip->destination() = senf::INet6Address::from_string("2021:2223:2425:2627:2829:2a2b:2c2d:2e2f");
87
88     ip.finalizeAll();
89
90     unsigned char data[] = {
91             0x60, 0x12, 0x20, 0x30,
92             0x00, 0x00, 0x3b, 0x04,
93             0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
94             0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
95             0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
96             0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f
97     };
98     BOOST_CHECK_EQUAL_COLLECTIONS(
99             data, data+sizeof(data), ip.data().begin(), ip.data().end() );
100 }
101
102 //-/////////////////////////////////////////////////////////////////////////////////////////////////
103 #undef prefix_
104
105 \f
106 // Local Variables:
107 // mode: c++
108 // fill-column: 100
109 // c-file-style: "senf"
110 // indent-tabs-mode: nil
111 // ispell-local-dictionary: "american"
112 // compile-command: "scons -u test"
113 // comment-column: 40
114 // End: