summaryrefslogtreecommitdiff
path: root/cpp/src/tests
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2008-02-21 02:58:37 +0000
committerAlan Conway <aconway@apache.org>2008-02-21 02:58:37 +0000
commitcc55340d5d7cf74d045f5f7608aa03c5fa7a4675 (patch)
treeb4fab5adce9886a328d3f646be674c108503a94a /cpp/src/tests
parenta00fe37e0854df1bdd9e0187873d3d1c8972eeb8 (diff)
downloadqpid-python-cc55340d5d7cf74d045f5f7608aa03c5fa7a4675.tar.gz
AMQP 0-10 type system:
- new lightweight templated serialization framework - all fixed-size built-in types tested and working - all vbin & str types implemented, tests disabled need to fix encoding. The following types remain to be implemented: byte-ranges 2 byte ranges within a 64-bit payload sequence-set 2 ranged set representation map 0xa8 4 a mapping of keys to typed values list 0xa9 4 a series of consecutive type-value pairs array 0xaa 4 a defined length collection of values of a single type struct32 0xab 4 a coded struct with a 32-bit size git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@629679 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/tests')
-rw-r--r--cpp/src/tests/Makefile.am3
-rw-r--r--cpp/src/tests/serialize.cpp135
2 files changed, 137 insertions, 1 deletions
diff --git a/cpp/src/tests/Makefile.am b/cpp/src/tests/Makefile.am
index 624834a6ba..3ce86b9da1 100644
--- a/cpp/src/tests/Makefile.am
+++ b/cpp/src/tests/Makefile.am
@@ -37,7 +37,8 @@ unit_test_SOURCES= unit_test.cpp unit_test.h \
Shlib.cpp FieldValue.cpp FieldTable.cpp Array.cpp \
InlineVector.cpp \
ISList.cpp IList.cpp \
- ClientSessionTest.cpp
+ ClientSessionTest.cpp \
+ serialize.cpp
# FIXME aconway 2008-02-20: removed RefCountedMap.cpp due to valgrind error.
check_LTLIBRARIES += libshlibtest.la
diff --git a/cpp/src/tests/serialize.cpp b/cpp/src/tests/serialize.cpp
new file mode 100644
index 0000000000..72a92ee226
--- /dev/null
+++ b/cpp/src/tests/serialize.cpp
@@ -0,0 +1,135 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include "unit_test.h"
+#include "qpid/amqp_0_10/built_in_types.h"
+#include "qpid/amqp_0_10/Codec.h"
+#include <boost/test/test_case_template.hpp>
+#include <boost/type_traits/is_arithmetic.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/back_inserter.hpp>
+#include <boost/mpl/copy.hpp>
+#include <boost/mpl/empty_sequence.hpp>
+#include <iterator>
+#include <string>
+#include <ostream>
+#include <netinet/in.h>
+
+// Missing operators needed for tests.
+namespace boost {
+template <class T, size_t N>
+std::ostream& operator<<(std::ostream& out, const array<T,N>& a) {
+ std::ostream_iterator<T> o(out, " ");
+ std::copy(a.begin(), a.end(), o);
+ return out;
+}
+} // boost
+
+namespace qpid {
+namespace sys {
+
+std::ostream& operator<<(std::ostream& out, const AbsTime& t) {
+ return out << t.timeValue();
+}
+}
+
+namespace amqp_0_10 {
+template <class T, class SizeType>
+std::ostream& operator<<(std::ostream& out, const CodableString<T,SizeType>& str) {
+ std::ostream_iterator<T> o(out, " ");
+ std::copy(str.begin(), str.end(), o);
+ return out;
+}
+}
+
+} // qpid
+
+
+QPID_AUTO_TEST_SUITE(SerializeTestSuite)
+
+
+
+using namespace std;
+namespace mpl=boost::mpl;
+using namespace qpid::amqp_0_10;
+
+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; };
+template <class A, class B, class C, class D> struct concat4 { typedef typename concat2<A, typename concat3<B, C, D>::type>::type type; };
+
+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;
+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;
+typedef concat2<FixedSizeTypes, VariableSizeTypes>::type AllTypes;
+
+// TODO aconway 2008-02-20: should test 64 bit integrals for order also.
+BOOST_AUTO_TEST_CASE(testNetworkByteOrder) {
+ string data;
+
+ uint32_t l = 1234567890;
+ 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 = 12345;
+ Codec::encode(std::back_inserter(data), s);
+ uint32_t s2 = ntohs(*reinterpret_cast<const uint32_t*>(data.data()));
+ BOOST_CHECK_EQUAL(s, s2);
+}
+
+void testValue(bool& b) { b = true; }
+template <class T> typename boost::enable_if<boost::is_arithmetic<T> >::type testValue(T& n) { n=42; }
+void testValue(long long& l) { l = 12345; }
+void testValue(DateTime& dt) { dt = qpid::sys::now(); }
+void testValue(Uuid& uuid) { uuid=Uuid(true); }
+template <class E, class M> void testValue(Decimal<E,M>& d) { d.exponent=2; d.mantissa=1234; }
+void testValue(SequenceNo& s) { s = 42; }
+template <class T, size_t N> void testValue(boost::array<T,N>& a) { a.assign(42); }
+template <class T, class SizeType> void testValue(CodableString<T, SizeType>& s) {
+ char msg[]="foobar";
+ s.assign(msg, msg+sizeof(msg));
+}
+
+// FIXME aconway 2008-02-20: test AllTypes
+BOOST_AUTO_TEST_CASE_TEMPLATE(testEncodeDecode, T, FixedSizeTypes)
+{
+ string data;
+ T t;
+ testValue(t);
+ Codec::encode(std::back_inserter(data), t);
+
+ BOOST_CHECK_EQUAL(Codec::size(t), data.size());
+
+ T t2;
+ Codec::decode(data.begin(), t2);
+ BOOST_CHECK_EQUAL(t,t2);
+}
+
+
+QPID_AUTO_TEST_SUITE_END()