summaryrefslogtreecommitdiff
path: root/cpp/src/tests
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2008-03-11 22:13:10 +0000
committerAlan Conway <aconway@apache.org>2008-03-11 22:13:10 +0000
commiteadb91781ab0d6e786500a3798f1bf2a83293a05 (patch)
treee582626920f3583e27deda835a2e2389c9c5e8c7 /cpp/src/tests
parent2250ec787ae5fb84fbebfee35bd9925ebd1dd679 (diff)
downloadqpid-python-eadb91781ab0d6e786500a3798f1bf2a83293a05.tar.gz
rubygen/0-10/specification.rb:
- Simplified enum mapping/encoding. - struct encoding - ostream << operators src/qpid/Serializer.h - free funciton serialization - separate Encoder/Decoder for const correctness - split() to allow separate encode/decode for complex cases. src/qpid/amqp_0_10/Assembly.cpp, Assembly.h: AMQP 0-10 final Assembly src/qpid/amqp_0_10/Codec.h - Replaced enable_if with overloads, simpler & more flexible. src/qpid/amqp_0_10/Frame.cpp, .h: AMQP 0-10 final frame. src/qpid/amqp_0_10/Holder.h: - provide const and non-const apply src/qpid/amqp_0_10/Segment.cpp, .h: AMQP 0-10 final Segment. src/qpid/amqp_0_10/apply.h - ConstApplyFunctor for const apply. src/qpid/amqp_0_10/built_in_types.h - SerializableString encoding src/qpid/amqp_0_10/complex_types.cpp, .h - const application - Action base class for command/control. src/qpid/framing/AMQBody.h - removed 0-10 final changes, moving integration point down the stack. src/qpid/sys/Shlib.h - removed unused and uncompilable (on some compilers) function. src/qpid/sys/Time.h, .cpp - ostream << for AbsTime and Duration. src/tests/Assembly.cpp, Segment.cpp, apply.cpp, serialize.cpp: testing new code. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@636126 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/tests')
-rw-r--r--cpp/src/tests/apply.cpp2
-rw-r--r--cpp/src/tests/serialize.cpp55
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()