Fix SCons 1.2.0 build failure
[senf.git] / senf / Packets / DefaultBundle / ICMPv6Packet.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 //     Philipp Batroff <pug@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 ICMPv6Packet unit tests */
25
26 // Custom includes
27 #include "ICMPv6Packet.hh"
28 #include "ICMPv6TypePacket.hh"
29
30 #include "../../Utils/auto_unit_test.hh"
31 #include <boost/test/test_tools.hpp>
32
33
34 BOOST_AUTO_UNIT_TEST(ICMPv6Packet_packet)
35 {
36     unsigned char dataListenerReport[] = {
37             0x8f, 0x00, 0x8d, 0x54, 0x00, 0x00, 0x00, 0x01,
38             0x04, 0x00, 0x00, 0x00, 0xff, 0x15, 0x00, 0x00,
39             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
40             0x00, 0x00, 0x00, 0x16
41     };
42
43     senf::ICMPv6Packet pListenerReport ( senf::ICMPv6Packet::create(dataListenerReport) );
44
45     BOOST_CHECK_EQUAL( pListenerReport->type(),     0x8f   );
46     BOOST_CHECK_EQUAL( pListenerReport->code(),     0x00   );
47     BOOST_CHECK_EQUAL( pListenerReport->checksum(), 0x8d54 );
48     BOOST_CHECK( pListenerReport.next() );
49     BOOST_CHECK( pListenerReport.next().is<senf::MLDv2ListenerReport>() );
50     BOOST_CHECK_EQUAL( pListenerReport.next().size(), 24u );
51
52     std::ostringstream oss (std::ostringstream::out);
53     SENF_CHECK_NO_THROW( pListenerReport.dump( oss));
54
55     unsigned char dataListenerQuery[] = {
56         0x82, 0x00, 0xf7, 0xd6, 0x27, 0x10, 0x00, 0x00, 
57         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
58         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
59         0x02, 0x7d, 0x00, 0x00
60     };
61     senf::ICMPv6Packet pListenerQuery ( senf::ICMPv6Packet::create(dataListenerQuery) );
62     BOOST_CHECK_EQUAL( pListenerQuery->type(),     0x82   );
63     BOOST_CHECK_EQUAL( pListenerQuery->code(),     0x00   );
64     BOOST_CHECK_EQUAL( pListenerQuery->checksum(), 0xf7d6 );
65     BOOST_CHECK( pListenerQuery.next() );
66     BOOST_CHECK( pListenerQuery.next().is<senf::MLDv2ListenerQuery>() );
67     BOOST_CHECK_EQUAL( pListenerQuery.next().size(), 24u );
68
69     SENF_CHECK_NO_THROW( pListenerQuery.dump( oss));
70     
71     unsigned char dataEchoRequest[] = {
72         0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x07
73     };
74     senf::ICMPv6Packet pEchoRequest ( senf::ICMPv6Packet::create(dataEchoRequest) );
75     BOOST_CHECK_EQUAL( pEchoRequest->type(),     0x80   );
76     BOOST_CHECK_EQUAL( pEchoRequest->code(),     0x00   );
77     BOOST_CHECK_EQUAL( pEchoRequest->checksum(), 0x0000 );
78     BOOST_CHECK( pEchoRequest.next() );
79     BOOST_CHECK( pEchoRequest.next().is<senf::ICMPv6EchoRequest>() );
80     BOOST_CHECK_EQUAL( pEchoRequest.next().size(), 4u );
81
82     SENF_CHECK_NO_THROW( pEchoRequest.dump( oss));
83     
84     unsigned char dataEchoReply[] = {
85         0x81, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x4d
86     };
87     
88     senf::ICMPv6Packet pEchoReply ( senf::ICMPv6Packet::create(dataEchoReply) );
89     BOOST_CHECK_EQUAL( pEchoReply->type(),     0x81   );
90     BOOST_CHECK_EQUAL( pEchoReply->code(),     0x00   );
91     BOOST_CHECK_EQUAL( pEchoReply->checksum(), 0x0000 );
92     BOOST_CHECK( pEchoReply.next() );
93     BOOST_CHECK( pEchoReply.next().is<senf::ICMPv6EchoReply>() );
94     BOOST_CHECK_EQUAL( pEchoReply.next().size(), 4u );
95
96     SENF_CHECK_NO_THROW( pEchoReply.dump( oss));
97     
98     
99     unsigned char dataErrDestUnreachable[] = {
100         0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 
101     };
102     
103     senf::ICMPv6Packet pErrDestUnreachable ( senf::ICMPv6Packet::create(dataErrDestUnreachable) );
104     BOOST_CHECK_EQUAL( pErrDestUnreachable->type(),     0x01   );
105     BOOST_CHECK_EQUAL( pErrDestUnreachable->code(),     0x00   );
106     BOOST_CHECK_EQUAL( pErrDestUnreachable->checksum(), 0x0000 );
107     BOOST_CHECK( pErrDestUnreachable.next() );
108     BOOST_CHECK( pErrDestUnreachable.next().is<senf::ICMPv6ErrDestUnreachable>() );
109     BOOST_CHECK_EQUAL( pErrDestUnreachable.next().size(), 4u );
110
111     SENF_CHECK_NO_THROW( pErrDestUnreachable.dump( oss));
112     
113     
114     unsigned char dataErrTooBig[] = {
115         0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0xd8 
116     };
117     
118     senf::ICMPv6Packet pErrTooBig ( senf::ICMPv6Packet::create(dataErrTooBig) );
119     BOOST_CHECK_EQUAL( pErrTooBig->type(),     0x02   );
120     BOOST_CHECK_EQUAL( pErrTooBig->code(),     0x00   );
121     BOOST_CHECK_EQUAL( pErrTooBig->checksum(), 0x0000 );
122     BOOST_CHECK( pErrTooBig.next() );
123     BOOST_CHECK( pErrTooBig.next().is<senf::ICMPv6ErrTooBig>() );
124     BOOST_CHECK_EQUAL( pErrTooBig.next().size(), 4u );
125
126     SENF_CHECK_NO_THROW( pErrTooBig.dump( oss));
127     
128     
129     unsigned char dataErrTimeExceeded[] = {
130         0x03, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
131     };
132     
133     senf::ICMPv6Packet pErrTimeExceeded ( senf::ICMPv6Packet::create(dataErrTimeExceeded) );
134     BOOST_CHECK_EQUAL( pErrTimeExceeded->type(),     0x03   );
135     BOOST_CHECK_EQUAL( pErrTimeExceeded->code(),     0x63   );
136     BOOST_CHECK_EQUAL( pErrTimeExceeded->checksum(), 0x0000 );
137     BOOST_CHECK( pErrTimeExceeded.next() );
138     BOOST_CHECK( pErrTimeExceeded.next().is<senf::ICMPv6ErrTimeExceeded>() );
139     BOOST_CHECK_EQUAL( pErrTimeExceeded.next().size(), 4u );
140
141     SENF_CHECK_NO_THROW( pErrTimeExceeded.dump( oss));
142     
143     
144     unsigned char dataErrParamProblem[] = {
145         0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
146     };
147     
148     senf::ICMPv6Packet pErrParamProblem ( senf::ICMPv6Packet::create(dataErrParamProblem) );
149     BOOST_CHECK_EQUAL( pErrParamProblem->type(),     0x04   );
150     BOOST_CHECK_EQUAL( pErrParamProblem->code(),     0x01   );
151     BOOST_CHECK_EQUAL( pErrParamProblem->checksum(), 0x0000 );
152     BOOST_CHECK( pErrParamProblem.next() );
153     BOOST_CHECK( pErrParamProblem.next().is<senf::ICMPv6ErrParamProblem>() );
154     BOOST_CHECK_EQUAL( pErrParamProblem.next().size(), 4u );
155
156     SENF_CHECK_NO_THROW( pErrParamProblem.dump( oss));
157     
158 }
159
160 // Local Variables:
161 // mode: c++
162 // fill-column: 100
163 // c-file-style: "senf"
164 // indent-tabs-mode: nil
165 // ispell-local-dictionary: "american"
166 // compile-command: "scons -u test"
167 // comment-column: 40
168 // End: