Merged revisions 262,264-265,267-282,284-298,300-311 via svnmerge from
[senf.git] / Packets / ParseListN.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 ParseListN.test unit tests */
23
24 //#include "ParseListN.test.hh"
25 //#include "ParseListN.test.ih"
26
27 // Custom includes
28 #include "ParseListN.hh"
29 #include "ParseVec.hh"
30 #include "ParseInt.hh"
31 #include "PacketType.hh"
32 #include "Packet.hh"
33
34 #include <boost/test/auto_unit_test.hpp>
35 #include <boost/test/test_tools.hpp>
36
37 #define prefix_
38 ///////////////////////////////cc.p////////////////////////////////////////
39
40 namespace {
41     struct VoidPacket_Type : public senf::PacketTypeBase
42     {};
43     typedef senf::ConcretePacket<VoidPacket_Type> VoidPacket;
44 }
45
46 BOOST_AUTO_UNIT_TEST(parseListN)
47 {
48     typedef senf::Parse_VectorN<senf::Parse_UInt16,senf::Parse_UInt8>::parser ParseVec;
49     typedef senf::Parse_ListN<ParseVec,senf::Parse_UInt16>::parser ParseList;
50     
51     VoidPacket vp (VoidPacket::create(ParseList::init_bytes));
52
53     {
54         ParseList p (vp.data().begin(),&vp.data());
55         p.init();
56         BOOST_CHECK_EQUAL( p.size(), 0u );
57         BOOST_CHECK_EQUAL( p.bytes(), 2u );
58         BOOST_CHECK( p.empty() );
59         BOOST_CHECK( p.begin() == p.end() );
60     }
61
62     {
63 #       define p ParseList(vp.data().begin(),&vp.data())
64
65         p.push_back_space();
66         BOOST_CHECK_EQUAL( p.bytes(), 3u );
67         BOOST_CHECK_EQUAL( p.size(), 1u );
68         BOOST_CHECK_EQUAL( p.front().bytes(), 1u );
69         BOOST_CHECK_EQUAL( p.front().size(), 0u );
70         BOOST_CHECK_EQUAL( vp.data()[1], 0x01u );
71
72         p.front().push_back(0x1234u);
73         BOOST_CHECK_EQUAL( p.front().size(), 1u );
74         BOOST_CHECK_EQUAL( p.front().bytes(), 3u );
75         BOOST_CHECK_EQUAL( p.front()[0], 0x1234u );
76         BOOST_CHECK_EQUAL( p.size(), 1u );
77         BOOST_CHECK_EQUAL( p.bytes(), 5u );
78
79         p.front().push_back(0x2345u);
80         BOOST_CHECK_EQUAL( p.front().back(), 0x2345u );
81         BOOST_CHECK_EQUAL( p.bytes(), 7u );
82
83         p.push_back_space();
84         BOOST_CHECK_EQUAL( p.size(), 2u );
85         BOOST_CHECK_EQUAL( p.bytes(), 8u );
86         
87         p.back().push_front(0x0123u);
88         BOOST_CHECK_EQUAL( p.front().size(), 2u );
89         BOOST_CHECK_EQUAL( p.back().size(), 1u );
90
91         p.push_front_space(2u);
92         BOOST_CHECK_EQUAL( p.size(), 4u );
93         BOOST_CHECK_EQUAL( p.front().size(), 0u);
94         
95         p.resize(3u);
96         BOOST_CHECK_EQUAL( p.size(), 3u );
97         BOOST_CHECK_EQUAL( p.back()[0], 0x1234u );
98         BOOST_CHECK_EQUAL( p.bytes(), 9u );
99
100 #       undef p
101     }
102 }
103
104 BOOST_AUTO_UNIT_TEST(parseListN_container)
105 {
106     typedef senf::Parse_VectorN<senf::Parse_UInt16,senf::Parse_UInt8>::parser ParseVec;
107     typedef senf::Parse_ListN<ParseVec,senf::Parse_UInt16>::parser ParseList;
108     
109     VoidPacket vp (VoidPacket::create(ParseList::init_bytes));
110
111     ParseList(vp.data().begin(),&vp.data()).init();
112
113     
114 }
115
116
117 ///////////////////////////////cc.e////////////////////////////////////////
118 #undef prefix_
119
120 \f
121 // Local Variables:
122 // mode: c++
123 // fill-column: 100
124 // comment-column: 40
125 // c-file-style: "senf"
126 // indent-tabs-mode: nil
127 // ispell-local-dictionary: "american"
128 // compile-command: "scons -u test"
129 // End: