summaryrefslogtreecommitdiff
path: root/cpp/src/tests
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2008-03-04 16:34:01 +0000
committerAlan Conway <aconway@apache.org>2008-03-04 16:34:01 +0000
commit24435b9c62976e0a4c0857f86057d3c93389b79f (patch)
treece9c88040f27fee8fc5f980e09c4ee487686cb4b /cpp/src/tests
parent089d3974d9555658f79e4ef02232877dab4dcad3 (diff)
downloadqpid-python-24435b9c62976e0a4c0857f86057d3c93389b79f.tar.gz
Completed holders, visitors and serialization for 0-10 commands and controls.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@633533 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/tests')
-rw-r--r--cpp/src/tests/apply.cpp11
-rw-r--r--cpp/src/tests/serialize.cpp56
2 files changed, 61 insertions, 6 deletions
diff --git a/cpp/src/tests/apply.cpp b/cpp/src/tests/apply.cpp
index 553026a35c..1b66d8e3b4 100644
--- a/cpp/src/tests/apply.cpp
+++ b/cpp/src/tests/apply.cpp
@@ -26,11 +26,15 @@ QPID_AUTO_TEST_SUITE(VisitorTestSuite)
using namespace qpid::amqp_0_10;
-struct GetCode {
- typedef uint8_t result_type;
+struct GetCode : public ConstApplyFunctor<uint8_t> {
template <class T> uint8_t operator()(const T&) const { return T::CODE; }
};
+struct SetChannelMax : ApplyFunctor<void> {
+ template <class T> void operator()(T&) const { BOOST_FAIL(""); }
+ void operator()(connection::Tune& t) const { t.channelMax=42; }
+};
+
struct TestFunctor {
typedef bool result_type;
bool operator()(const connection::Tune& tune) {
@@ -57,6 +61,9 @@ BOOST_AUTO_TEST_CASE(testApply) {
connection::Start start;
p = &start;
BOOST_CHECK(!apply(tf, *p));
+
+ apply(SetChannelMax(), tune);
+ BOOST_CHECK_EQUAL(tune.channelMax, 42);
}
struct VoidTestFunctor {
diff --git a/cpp/src/tests/serialize.cpp b/cpp/src/tests/serialize.cpp
index 8de2d4ca58..9eaf78ab78 100644
--- a/cpp/src/tests/serialize.cpp
+++ b/cpp/src/tests/serialize.cpp
@@ -22,6 +22,9 @@
#include "unit_test.h"
#include "qpid/amqp_0_10/built_in_types.h"
#include "qpid/amqp_0_10/Codec.h"
+#include "qpid/amqp_0_10/specification.h"
+#include "qpid/amqp_0_10/ControlHolder.h"
+
#include <boost/test/test_case_template.hpp>
#include <boost/type_traits/is_arithmetic.hpp>
#include <boost/utility/enable_if.hpp>
@@ -62,6 +65,7 @@ QPID_AUTO_TEST_SUITE(SerializeTestSuite)
using namespace std;
namespace mpl=boost::mpl;
using namespace qpid::amqp_0_10;
+using qpid::framing::in_place;
template <class A, class B> struct concat2 { typedef typename mpl::copy<B, typename mpl::back_inserter<A> >::type type; };
template <class A, class B, class C> struct concat3 { typedef typename concat2<A, typename concat2<B, C>::type>::type type; };
@@ -82,14 +86,14 @@ BOOST_AUTO_TEST_CASE(testNetworkByteOrder) {
string data;
uint32_t l = 0x11223344;
- Codec::encode(std::back_inserter(data), l);
+ Codec::encode(std::back_inserter(data))(l);
uint32_t enc=reinterpret_cast<const uint32_t&>(*data.data());
uint32_t l2 = ntohl(enc);
BOOST_CHECK_EQUAL(l, l2);
data.clear();
uint16_t s = 0x1122;
- Codec::encode(std::back_inserter(data), s);
+ Codec::encode(std::back_inserter(data))(s);
uint32_t s2 = ntohs(*reinterpret_cast<const uint32_t*>(data.data()));
BOOST_CHECK_EQUAL(s, s2);
}
@@ -116,14 +120,58 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(testEncodeDecode, T, AllTypes)
string data;
T t;
testValue(t);
- Codec::encode(std::back_inserter(data), t);
+ Codec::encode(std::back_inserter(data))(t);
BOOST_CHECK_EQUAL(Codec::size(t), data.size());
T t2;
- Codec::decode(data.begin(), t2);
+ Codec::decode(data.begin())(t2);
BOOST_CHECK_EQUAL(t,t2);
}
+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 decode(S& s) { decoded=true; s(value); }
+ template <class S> void serialize(S& s) { s.split(*this); }
+};
+
+BOOST_AUTO_TEST_CASE(testSplit) {
+ string data;
+ TestMe t1('x');
+ Codec::encode(std::back_inserter(data))(t1);
+ BOOST_CHECK(t1.encoded);
+ BOOST_CHECK(!t1.decoded);
+ BOOST_CHECK_EQUAL(data, "x");
+
+ TestMe t2('y');
+ Codec::decode(data.begin())(t2);
+ BOOST_CHECK(!t2.encoded);
+ BOOST_CHECK(t2.decoded);
+ BOOST_CHECK_EQUAL(t2.value, 'x');
+}
+
+BOOST_AUTO_TEST_CASE(testControlEncodeDecode) {
+ string data;
+ Control::Holder h(in_place<connection::Tune>(1,2,3,4));
+ Codec::encode(std::back_inserter(data))(h);
+
+ BOOST_CHECK_EQUAL(data.size(), Codec::size(h));
+
+ Codec::Decode<string::iterator> decode(data.begin());
+ Control::Holder h2;
+ decode(h2);
+
+ BOOST_REQUIRE(h2.get());
+ BOOST_CHECK_EQUAL(h2.get()->getClassCode(), connection::CODE);
+ BOOST_CHECK_EQUAL(h2.get()->getCode(), uint8_t(connection::Tune::CODE));
+ connection::Tune& tune=static_cast<connection::Tune&>(*h2.get());
+ BOOST_CHECK_EQUAL(tune.channelMax, 1u);
+ BOOST_CHECK_EQUAL(tune.maxFrameSize, 2u);
+ BOOST_CHECK_EQUAL(tune.heartbeatMin, 3u);
+ BOOST_CHECK_EQUAL(tune.heartbeatMax, 4u);
+}
QPID_AUTO_TEST_SUITE_END()