afc47a20a22bcdd7e419cb08f5f76e5dd91ff7a6
[senf.git] / Packets / IpV4Packet.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2006 
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@fokus.fraunhofer.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 // Unit tests
24
25 //#include "IpV4Packet.test.hh"
26 //#include "IpV4Packet.test.ih"
27
28 // Custom includes
29 #include "IpV4Packet.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(ipV4Packet_parser)
40 {
41     unsigned char data[] = { 0x01, 0x02, 0x03, 0x04, 
42                              0x05, 0x06, 0x07, 0x08, 
43                              0x09, 0x0A, 0x0B, 0x0C,   
44                              0x11, 0x12, 0x13, 0x14, 
45                              0x15, 0x16, 0x17, 0x18
46                            };                        
47
48     typedef unsigned char * iterator;
49     Parse_IpV4<iterator> p(data);
50
51     BOOST_CHECK_EQUAL( p.version(),     0x00u       );
52     BOOST_CHECK_EQUAL( p.ihl(),         0x01u       );
53     // the static_cast is to silence gcc-3.3
54     BOOST_CHECK_EQUAL( static_cast<unsigned>(p.tos()), 0x02u );
55     BOOST_CHECK_EQUAL( static_cast<unsigned>(p.length()), 0x0304u );
56     BOOST_CHECK_EQUAL( static_cast<unsigned>(p.identifier()), 0x0506u );
57     BOOST_CHECK_EQUAL( p.reserved(),    0           );
58     BOOST_CHECK_EQUAL( p.df(),          0           );
59     BOOST_CHECK_EQUAL( p.mf(),          0           );
60     BOOST_CHECK_EQUAL( p.frag(),        0x0708u     );
61     BOOST_CHECK_EQUAL( static_cast<unsigned>(p.ttl()), 0x09u );
62     BOOST_CHECK_EQUAL( static_cast<unsigned>(p.protocol()), 0x0Au );
63     BOOST_CHECK_EQUAL( static_cast<unsigned>(p.crc()), 0x0B0Cu );
64     BOOST_CHECK_EQUAL( p.source(),      0x11121314u );
65     BOOST_CHECK_EQUAL( p.destination(), 0x15161718u );
66     
67 }
68
69                       
70 BOOST_AUTO_UNIT_TEST(ipV4Packet_packet)
71 {
72
73     unsigned char data[] = { 0x01, 0x02, 0x03, 0x04, 
74                              0x05, 0x06, 0x07, 0x08, 
75                              0x09, 0x0A, 0x0B, 0x0C,   
76                              0x11, 0x12, 0x13, 0x14, 
77                              0x15, 0x16, 0x17, 0x18
78                            };  
79
80     IpV4Packet::ptr p (Packet::create<IpV4Packet>(data, data+sizeof(data)));
81
82     BOOST_CHECK_EQUAL( p->version(),     0x00u       );
83     BOOST_CHECK_EQUAL( p->ihl(),         0x01u       );
84     // the static_cast is to silence gcc-3.3
85     BOOST_CHECK_EQUAL( static_cast<unsigned>(p->tos()), 0x02u );
86     BOOST_CHECK_EQUAL( static_cast<unsigned>(p->length()), 0x0304u );
87     BOOST_CHECK_EQUAL( static_cast<unsigned>(p->identifier()), 0x0506u );
88     BOOST_CHECK_EQUAL( p->reserved(),    0           );
89     BOOST_CHECK_EQUAL( p->df(),          0           );
90     BOOST_CHECK_EQUAL( p->mf(),          0           );
91     BOOST_CHECK_EQUAL( p->frag(),        0x0708u     );
92     BOOST_CHECK_EQUAL( static_cast<unsigned>(p->ttl()), 0x09u );
93     BOOST_CHECK_EQUAL( static_cast<unsigned>(p->protocol()), 0x0Au );
94     BOOST_CHECK_EQUAL( static_cast<unsigned>(p->crc()), 0x0B0Cu );
95     BOOST_CHECK_EQUAL( p->source(),      0x11121314u );
96     BOOST_CHECK_EQUAL( p->destination(), 0x15161718u );
97
98
99 }
100
101
102
103 ///////////////////////////////cc.e////////////////////////////////////////
104 #undef prefix_
105
106 \f
107 // Local Variables:
108 // mode: c++
109 // c-file-style: "senf"
110 // End: