diff options
Diffstat (limited to 'cpp/src/tests')
-rw-r--r-- | cpp/src/tests/apply.cpp | 2 | ||||
-rw-r--r-- | cpp/src/tests/serialize.cpp | 55 |
2 files changed, 54 insertions, 3 deletions
diff --git a/cpp/src/tests/apply.cpp b/cpp/src/tests/apply.cpp index 1b66d8e3b4..450aeac356 100644 --- a/cpp/src/tests/apply.cpp +++ b/cpp/src/tests/apply.cpp @@ -26,7 +26,7 @@ QPID_AUTO_TEST_SUITE(VisitorTestSuite) using namespace qpid::amqp_0_10; -struct GetCode : public ConstApplyFunctor<uint8_t> { +struct GetCode : public ApplyFunctor<uint8_t> { template <class T> uint8_t operator()(const T&) const { return T::CODE; } }; diff --git a/cpp/src/tests/serialize.cpp b/cpp/src/tests/serialize.cpp index 9eaf78ab78..228a4b6e3a 100644 --- a/cpp/src/tests/serialize.cpp +++ b/cpp/src/tests/serialize.cpp @@ -24,6 +24,7 @@ #include "qpid/amqp_0_10/Codec.h" #include "qpid/amqp_0_10/specification.h" #include "qpid/amqp_0_10/ControlHolder.h" +#include "qpid/amqp_0_10/Frame.h" #include <boost/test/test_case_template.hpp> #include <boost/type_traits/is_arithmetic.hpp> @@ -57,6 +58,10 @@ std::ostream& operator<<(std::ostream& out, const AbsTime& t) { } // qpid +namespace std { +// Dummy += for back inserters so we can use them with the decoder. +template <class C> back_insert_iterator<C>& operator+=(back_insert_iterator<C>& bi, size_t) { return bi; } +} QPID_AUTO_TEST_SUITE(SerializeTestSuite) @@ -73,12 +78,14 @@ template <class A, class B, class C, class D> struct concat4 { typedef typename typedef mpl::vector<Bit, Boolean, Char, Int32, Int64, Int8, Uint16, CharUtf32, Uint32, Uint64, Bin8, Uint8>::type IntegralTypes; typedef mpl::vector<Bin1024, Bin128, Bin16, Bin256, Bin32, Bin40, Bin512, Bin64, Bin72>::type BinTypes; +// FIXME aconway 2008-03-07: float encoding typedef mpl::vector<Double, Float>::type FloatTypes; typedef mpl::vector<SequenceNo, Uuid, Datetime, Dec32, Dec64> FixedSizeClassTypes; typedef mpl::vector<Vbin8, Str8Latin, Str8, Str8Utf16, Vbin16, Str16Latin, Str16, Str16Utf16, Vbin32> VariableSizeTypes; -typedef concat4<IntegralTypes, BinTypes, FloatTypes, FixedSizeClassTypes>::type FixedSizeTypes; +// FIXME aconway 2008-03-07: float encoding +typedef concat3<IntegralTypes, BinTypes, /*FloatTypes, */ FixedSizeClassTypes>::type FixedSizeTypes; typedef concat2<FixedSizeTypes, VariableSizeTypes>::type AllTypes; // TODO aconway 2008-02-20: should test 64 bit integrals for order also. @@ -133,7 +140,9 @@ struct TestMe { bool encoded, decoded; char value; TestMe(char v) : encoded(), decoded(), value(v) {} - template <class S> void encode(S& s) { encoded=true; s(value); } + template <class S> void encode(S& s) const { + const_cast<TestMe*>(this)->encoded=true; s(value); + } template <class S> void decode(S& s) { decoded=true; s(value); } template <class S> void serialize(S& s) { s.split(*this); } }; @@ -174,4 +183,46 @@ BOOST_AUTO_TEST_CASE(testControlEncodeDecode) { BOOST_CHECK_EQUAL(tune.heartbeatMax, 4u); } +BOOST_AUTO_TEST_CASE(testFrameEncodeDecode) { + static const int overhead=12; + string data; + Frame r, c; + char d1[]="abcdefg"; + r.refer(d1, d1+sizeof(d1)); + r.setFlags(Frame::FIRST_FRAME); + r.setType(CONTROL); + r.setChannel(32); + r.setTrack(1); + char d2[]="01234567"; + c.copy(d2, d2+sizeof(d2)); + + BOOST_CHECK_EQUAL(overhead+sizeof(d1), Codec::size(r)); + BOOST_CHECK_EQUAL(overhead+sizeof(d2), Codec::size(c)); + Codec::encode(std::back_inserter(data))(r)(c); + BOOST_CHECK_EQUAL(data.size(), Codec::size(r)+Codec::size(c)); + + FrameHeader fh; + std::string::iterator i = Codec::decode(data.begin())(fh).pos(); + size_t s = fh.size(); + BOOST_CHECK_EQUAL(s, sizeof(d1)); + BOOST_CHECK_EQUAL(std::string(i, i+s), std::string(d1, d1+s)); + + + Frame f1, f2; + Codec::decode(data.begin())(f1)(f2); + BOOST_CHECK_EQUAL(f1.size(), sizeof(d1)); + BOOST_CHECK_EQUAL(std::string(f1.begin(), f1.size()), + std::string(d1, sizeof(d1))); + BOOST_CHECK_EQUAL(f1.size(), r.size()); + BOOST_CHECK_EQUAL(f1.getFlags(), Frame::FIRST_FRAME); + BOOST_CHECK_EQUAL(f1.getType(), CONTROL); + BOOST_CHECK_EQUAL(f1.getChannel(), 32); + BOOST_CHECK_EQUAL(f1.getTrack(), 1); + + BOOST_CHECK_EQUAL(f2.size(), c.size()); + BOOST_CHECK_EQUAL(std::string(f2.begin(), f2.end()), + std::string(d2, d2+sizeof(d2))); + +} + QPID_AUTO_TEST_SUITE_END() |