4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Stefan Bund <stefan.bund@fokus.fraunhofer.de>
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.
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.
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.
25 //#include "ParseVec.test.hh"
26 //#include "ParseVec.test.ih"
29 #include "ParseVec.hh"
30 #include "ParseInt.hh"
32 #include <boost/test/auto_unit_test.hpp>
33 #include <boost/test/test_tools.hpp>
34 #include <boost/assign.hpp>
37 ///////////////////////////////cc.p////////////////////////////////////////
41 BOOST_AUTO_UNIT_TEST(parseVec_test)
43 unsigned char data[] = { 0x03, // size
44 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, // data
45 0x20, 0x21, 0x22, 0x23, 0x24, 0x25 };
46 typedef unsigned char * iterator;
47 typedef Parse_Vector<Parse_UInt16<>,Parse_UInt8<>,iterator> Parse_UInt16Vec;
49 Parse_UInt8<iterator> sizeParser (data);
50 Parse_UInt16Vec v (sizeParser, data+1);
52 BOOST_CHECK_EQUAL( v[0], 0x1011 );
53 BOOST_CHECK_EQUAL( v[2], 0x1415 );
54 BOOST_CHECK_EQUAL( v.size(), 3u );
55 BOOST_CHECK_EQUAL( v.bytes(), 6u );
57 BOOST_CHECK_EQUAL( v.size(), 6u );
58 BOOST_CHECK_EQUAL( v.bytes(), 12u );
61 Parse_UInt16Vec::iterator j (v.begin());
62 Parse_UInt16Vec::iterator e (v.end());
64 BOOST_CHECK_EQUAL( Parse_UInt16<iterator>(i), *j );
65 BOOST_CHECK_EQUAL(i, data+13);
68 BOOST_AUTO_UNIT_TEST(parseVec_wrapper)
70 typedef std::vector<unsigned char> Container;
71 typedef Container::iterator iterator;
72 typedef Parse_UInt8<iterator> Parse_Size;
73 typedef Parse_Vector<Parse_UInt16<>,Parse_Size,iterator> Parse_UInt16Vec;
74 typedef Parse_UInt16Vec::wrapper<Container>::t Parse_UInt16VecWrap;
76 using namespace boost::assign;
81 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, // data
82 0x20, 0x21, 0x22, 0x23, 0x24, 0x25;
84 Parse_Size sizeParser (data.begin());
85 Parse_UInt16Vec v (sizeParser, data.begin()+1);
86 Parse_UInt16VecWrap w (v,data);
88 BOOST_CHECK_EQUAL( w[0], 0x1011 );
89 BOOST_CHECK_EQUAL( w[2], 0x1415 );
90 BOOST_CHECK_EQUAL( w.size(), 3u );
92 BOOST_CHECK_EQUAL( w.size(), 6u );
95 iterator i (data.begin()+1);
96 Parse_UInt16VecWrap::iterator j (w.begin());
97 Parse_UInt16VecWrap::iterator e (w.end());
99 BOOST_CHECK_EQUAL( Parse_UInt16<iterator>(i), *j );
100 BOOST_CHECK_EQUAL(data.end()-i, 0);
103 w.shift(w.begin()+1);
104 BOOST_CHECK_EQUAL( w.size(), 7u );
105 BOOST_CHECK_EQUAL( w[0], 0x1011 );
106 BOOST_CHECK_EQUAL( w[1], 0 );
107 BOOST_CHECK_EQUAL( w[2], 0x1213 );
109 w.insert(w.begin()+3, 2u, 0xfffe);
110 BOOST_CHECK_EQUAL( w.size(), 9u );
111 BOOST_CHECK_EQUAL( w[2], 0x1213 );
112 BOOST_CHECK_EQUAL( w[3], 0xfffe );
113 BOOST_CHECK_EQUAL( w[4], 0xfffe );
114 BOOST_CHECK_EQUAL( w[5], 0x1415 );
116 w.erase(w.begin()+3, w.begin()+5);
117 BOOST_CHECK_EQUAL( w.size(), 7u );
119 w.erase(w.begin()+1);
120 BOOST_CHECK_EQUAL( w.size(), 6u );
123 iterator i (data.begin()+1);
124 Parse_UInt16VecWrap::iterator j (w.begin());
125 Parse_UInt16VecWrap::iterator e (w.end());
126 for (;j!=e;++j, i+=2)
127 BOOST_CHECK_EQUAL( Parse_UInt16<iterator>(i), *j );
128 BOOST_CHECK_EQUAL(data.end()-i, 0);
132 BOOST_CHECK_EQUAL( w.size(), 0u );
133 BOOST_CHECK( w.begin() == w.end() );
134 BOOST_CHECK_EQUAL( data.size(), 1u );
137 // This really belongs into ParserBase.test.cc but it's simpler here
138 BOOST_AUTO_UNIT_TEST(parserTraits_test)
140 // Really, this could be checked by BOOST_STATIC_ASSERT since
141 // it's compile-time ...
142 BOOST_CHECK( Parser_traits< Parse_UInt32<> >::fixed_size );
143 BOOST_CHECK( (! Parser_traits< Parse_Vector< Parse_UInt16<>,Parse_UInt16<> > >::fixed_size) );
146 ///////////////////////////////cc.e////////////////////////////////////////
152 // c-file-style: "senf"