diff options
| author | Alan Conway <aconway@apache.org> | 2008-04-02 17:56:14 +0000 |
|---|---|---|
| committer | Alan Conway <aconway@apache.org> | 2008-04-02 17:56:14 +0000 |
| commit | c6bd8565ecc054fa3a393f7df04b1d44836c3a79 (patch) | |
| tree | a6e237fab1bba4ec6ea868ff719d5068fdc6f5c5 /qpid/cpp/src/tests | |
| parent | 735fbf00f9ddae479c6a4e682fd3fa4224b6131f (diff) | |
| download | qpid-python-c6bd8565ecc054fa3a393f7df04b1d44836c3a79.tar.gz | |
Encoding/decoding for new types: amqp_0_10::Map, amqp_0_10:UnknownType
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@643995 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/src/tests')
| -rw-r--r-- | qpid/cpp/src/tests/Makefile.am | 3 | ||||
| -rw-r--r-- | qpid/cpp/src/tests/amqp_0_10/Map.cpp | 99 | ||||
| -rw-r--r-- | qpid/cpp/src/tests/serialize.cpp | 15 |
3 files changed, 109 insertions, 8 deletions
diff --git a/qpid/cpp/src/tests/Makefile.am b/qpid/cpp/src/tests/Makefile.am index ca25ced5e0..ae47241e67 100644 --- a/qpid/cpp/src/tests/Makefile.am +++ b/qpid/cpp/src/tests/Makefile.am @@ -41,7 +41,8 @@ unit_test_SOURCES= unit_test.cpp unit_test.h \ SequenceSet.cpp \ serialize.cpp \ ProxyTemplate.cpp apply.cpp BoundedIterator.cpp \ - IncompleteMessageList.cpp + IncompleteMessageList.cpp \ + amqp_0_10/Map.cpp check_LTLIBRARIES += libshlibtest.la libshlibtest_la_LDFLAGS = -module -rpath $(abs_builddir) diff --git a/qpid/cpp/src/tests/amqp_0_10/Map.cpp b/qpid/cpp/src/tests/amqp_0_10/Map.cpp new file mode 100644 index 0000000000..958470f6d7 --- /dev/null +++ b/qpid/cpp/src/tests/amqp_0_10/Map.cpp @@ -0,0 +1,99 @@ +/* + * + * 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/Map.h" +#include "qpid/amqp_0_10/Codec.h" +#include <iostream> + +using namespace qpid::amqp_0_10; +using namespace std; + +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(MapTestSuite) + + BOOST_AUTO_TEST_CASE(testGetSet) { + MapValue v; + v = Str8("foo"); + BOOST_CHECK(v.get<Str8>()); + BOOST_CHECK(!v.get<uint8_t>()); + BOOST_CHECK_EQUAL(*v.get<Str8>(), "foo"); + + v = uint8_t(42); + BOOST_CHECK(!v.get<Str8>()); + BOOST_CHECK(v.get<uint8_t>()); + BOOST_CHECK_EQUAL(*v.get<uint8_t>(), 42); + + v = uint16_t(12); + BOOST_CHECK(v.get<uint16_t>()); + BOOST_CHECK_EQUAL(*v.get<uint16_t>(), 12); +} + +template <class R> struct TestVisitor : public MapValue::Visitor<R> { + template <class T> R operator()(const T&) const { throw MapValue::BadTypeException(); } + R operator()(const R& r) const { return r; } +}; + +BOOST_AUTO_TEST_CASE(testVisit) { + MapValue v; + v = Str8("foo"); + BOOST_CHECK_EQUAL(v.apply_visitor(TestVisitor<Str8>()), "foo"); + v = Uint16(42); + BOOST_CHECK_EQUAL(v.apply_visitor(TestVisitor<Uint16>()), 42); + try { + v.apply_visitor(TestVisitor<bool>()); + BOOST_FAIL("Expecting exception"); + } + catch(const MapValue::BadTypeException&) {} +} + + +BOOST_AUTO_TEST_CASE(testEncodeMapValue) { + MapValue mv; + std::string data; + mv = Str8("hello"); + Codec::encode(back_inserter(data))(mv); + BOOST_CHECK_EQUAL(data.size(), Codec::size(mv)); + MapValue mv2; + Codec::decode(data.begin())(mv2); + BOOST_CHECK_EQUAL(mv2.getCode(), 0x85); + BOOST_REQUIRE(mv2.get<Str8>()); + BOOST_CHECK_EQUAL(*mv2.get<Str8>(), "hello"); +} + +BOOST_AUTO_TEST_CASE(testEncode) { + Map map; + std::string data; + map["A"] = true; + map["b"] = Str8("hello"); + Codec::encode(back_inserter(data))(map); + Map map2; + Codec::decode(data.begin())(map2); + BOOST_CHECK_EQUAL(map.size(), 2u); + BOOST_CHECK(map["A"].get<bool>()); + BOOST_CHECK_EQUAL(*map["b"].get<Str8>(), "hello"); +} + + +QPID_AUTO_TEST_SUITE_END() diff --git a/qpid/cpp/src/tests/serialize.cpp b/qpid/cpp/src/tests/serialize.cpp index 228a4b6e3a..da71917cbd 100644 --- a/qpid/cpp/src/tests/serialize.cpp +++ b/qpid/cpp/src/tests/serialize.cpp @@ -25,6 +25,7 @@ #include "qpid/amqp_0_10/specification.h" #include "qpid/amqp_0_10/ControlHolder.h" #include "qpid/amqp_0_10/Frame.h" +#include "qpid/amqp_0_10/Map.h" #include <boost/test/test_case_template.hpp> #include <boost/type_traits/is_arithmetic.hpp> @@ -76,16 +77,13 @@ template <class A, class B> struct concat2 { typedef typename mpl::copy<B, typen 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<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 mpl::vector<Map, Vbin8, Str8Latin, Str8, Str8Utf16, Vbin16, Str16Latin, Str16, Str16Utf16, Vbin32> VariableSizeTypes; - -// FIXME aconway 2008-03-07: float encoding -typedef concat3<IntegralTypes, BinTypes, /*FloatTypes, */ FixedSizeClassTypes>::type FixedSizeTypes; +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. @@ -107,19 +105,22 @@ BOOST_AUTO_TEST_CASE(testNetworkByteOrder) { // Assign test values to the various types. void testValue(bool& b) { b = true; } +void testValue(Bit&) { } template <class T> typename boost::enable_if<boost::is_arithmetic<T> >::type testValue(T& n) { n=42; } +void testValue(CharUtf32& c) { c = 43; } void testValue(long long& l) { l = 0x012345; } 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=0x1122; } void testValue(SequenceNo& s) { s = 42; } template <size_t N> void testValue(Bin<N>& a) { a.assign(42); } -template <class T, class S> void testValue(SerializableString<T, S>& s) { +template <class T, class S, int Unique> void testValue(SerializableString<T, S, Unique>& s) { char msg[]="foobar"; s.assign(msg, msg+sizeof(msg)); } void testValue(Str16& s) { s = "the quick brown fox jumped over the lazy dog"; } void testValue(Str8& s) { s = "foobar"; } +void testValue(Map& m) { m["s"] = Str8("foobar"); m["b"] = true; m["c"] = uint16_t(42); } //typedef mpl::vector<Str8, Str16>::type TestTypes; BOOST_AUTO_TEST_CASE_TEMPLATE(testEncodeDecode, T, AllTypes) |
