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