diff options
| author | Kenneth Anthony Giusti <kgiusti@apache.org> | 2012-03-19 21:05:01 +0000 |
|---|---|---|
| committer | Kenneth Anthony Giusti <kgiusti@apache.org> | 2012-03-19 21:05:01 +0000 |
| commit | b4294229869c5f7b0fd5da3c5fe9e6b6b6fd6c6c (patch) | |
| tree | 116e58401dbd116aa003db31764eb5e656200d03 /qpid/cpp/src | |
| parent | 841377c0309773dad4db14af13002fff5cc6d236 (diff) | |
| download | qpid-python-b4294229869c5f7b0fd5da3c5fe9e6b6b6fd6c6c.tar.gz | |
QPID-3890: resync this branch to latest trunk
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/qpid-3890@1302655 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/src')
21 files changed, 52 insertions, 937 deletions
diff --git a/qpid/cpp/src/CMakeLists.txt b/qpid/cpp/src/CMakeLists.txt index cfcdead883..b6ce249708 100644 --- a/qpid/cpp/src/CMakeLists.txt +++ b/qpid/cpp/src/CMakeLists.txt @@ -874,7 +874,6 @@ set (qpidcommon_SOURCES qpid/framing/AMQHeaderBody.cpp qpid/framing/AMQHeartbeatBody.cpp qpid/framing/Array.cpp - qpid/framing/BodyHandler.cpp qpid/framing/Buffer.cpp qpid/framing/Endian.cpp qpid/framing/FieldTable.cpp diff --git a/qpid/cpp/src/Makefile.am b/qpid/cpp/src/Makefile.am index e03c88ec8b..5dcc4cd210 100644 --- a/qpid/cpp/src/Makefile.am +++ b/qpid/cpp/src/Makefile.am @@ -398,8 +398,6 @@ libqpidcommon_la_SOURCES += \ qpid/framing/AccumulatedAck.h \ qpid/framing/Array.cpp \ qpid/framing/BodyFactory.h \ - qpid/framing/BodyHandler.cpp \ - qpid/framing/BodyHandler.h \ qpid/framing/Buffer.cpp \ qpid/framing/ResizableBuffer.h \ qpid/framing/ChannelHandler.h \ diff --git a/qpid/cpp/src/qpid/cluster/ClusterMap.cpp b/qpid/cpp/src/qpid/cluster/ClusterMap.cpp index a8389095c9..12730d20ec 100644 --- a/qpid/cpp/src/qpid/cluster/ClusterMap.cpp +++ b/qpid/cpp/src/qpid/cluster/ClusterMap.cpp @@ -29,7 +29,8 @@ #include <ostream> using namespace std; -using namespace boost; +using boost::ref; +using boost::optional; namespace qpid { using namespace framing; diff --git a/qpid/cpp/src/qpid/cluster/InitialStatusMap.cpp b/qpid/cpp/src/qpid/cluster/InitialStatusMap.cpp index eb65005a9e..fc53d1076b 100644 --- a/qpid/cpp/src/qpid/cluster/InitialStatusMap.cpp +++ b/qpid/cpp/src/qpid/cluster/InitialStatusMap.cpp @@ -30,9 +30,9 @@ namespace qpid { namespace cluster { using namespace std; -using namespace boost; using namespace framing::cluster; using namespace framing; +using boost::optional; InitialStatusMap::InitialStatusMap(const MemberId& self_, size_t size_) : self(self_), completed(), resendNeeded(), size(size_) diff --git a/qpid/cpp/src/qpid/framing/BodyHandler.cpp b/qpid/cpp/src/qpid/framing/BodyHandler.cpp deleted file mode 100644 index db302b1e4c..0000000000 --- a/qpid/cpp/src/qpid/framing/BodyHandler.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * - * 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 "qpid/framing/BodyHandler.h" -#include "qpid/framing/AMQMethodBody.h" -#include "qpid/framing/AMQHeaderBody.h" -#include "qpid/framing/AMQContentBody.h" -#include "qpid/framing/AMQHeartbeatBody.h" -#include <boost/cast.hpp> -#include "qpid/framing/reply_exceptions.h" -#include "qpid/Msg.h" - -using namespace qpid::framing; -using namespace boost; - -BodyHandler::~BodyHandler() {} - -// TODO aconway 2007-08-13: Replace with visitor. -void BodyHandler::handleBody(AMQBody* body) { - switch(body->type()) - { - case METHOD_BODY: - handleMethod(polymorphic_downcast<AMQMethodBody*>(body)); - break; - case HEADER_BODY: - handleHeader(polymorphic_downcast<AMQHeaderBody*>(body)); - break; - case CONTENT_BODY: - handleContent(polymorphic_downcast<AMQContentBody*>(body)); - break; - case HEARTBEAT_BODY: - handleHeartbeat(polymorphic_downcast<AMQHeartbeatBody*>(body)); - break; - default: - throw FramingErrorException( - QPID_MSG("Invalid frame type " << body->type())); - } -} - diff --git a/qpid/cpp/src/qpid/framing/BodyHandler.h b/qpid/cpp/src/qpid/framing/BodyHandler.h deleted file mode 100644 index 9ded737195..0000000000 --- a/qpid/cpp/src/qpid/framing/BodyHandler.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _BodyHandler_ -#define _BodyHandler_ - -/* - * - * 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 <boost/shared_ptr.hpp> - -namespace qpid { -namespace framing { -class AMQBody; -class AMQMethodBody; -class AMQHeaderBody; -class AMQContentBody; -class AMQHeartbeatBody; - -// TODO aconway 2007-08-10: rework using Visitor pattern? - -/** - * Interface to handle incoming frame bodies. - * Derived classes provide logic for each frame type. - */ -class BodyHandler { - public: - virtual ~BodyHandler(); - virtual void handleBody(AMQBody* body); - - protected: - virtual void handleMethod(AMQMethodBody*) = 0; - virtual void handleHeader(AMQHeaderBody*) = 0; - virtual void handleContent(AMQContentBody*) = 0; - virtual void handleHeartbeat(AMQHeartbeatBody*) = 0; -}; - -}} - - -#endif diff --git a/qpid/cpp/src/qpid/framing/FieldTable.cpp b/qpid/cpp/src/qpid/framing/FieldTable.cpp index b696b5e54f..f9dc42916d 100644 --- a/qpid/cpp/src/qpid/framing/FieldTable.cpp +++ b/qpid/cpp/src/qpid/framing/FieldTable.cpp @@ -28,22 +28,45 @@ #include "qpid/Msg.h" #include <assert.h> +// The locking rationale in the FieldTable seems a little odd, but it +// maintains the concurrent guarantees and requirements that were in +// place before the cachedBytes/cachedSize were added: +// +// The FieldTable client code needs to make sure that they call no write +// operation in parallel with any other operation on the FieldTable. +// However multiple parallel read operations are safe. +// +// To this end the only code that is locked is code that can transparently +// change the state of the FieldTable during a read only operation. +// (In other words the code that required the mutable members in the class +// definition!) +// namespace qpid { + +using sys::Mutex; +using sys::ScopedLock; + namespace framing { FieldTable::FieldTable() : - cachedSize(0) + cachedSize(0), + newBytes(false) { } FieldTable::FieldTable(const FieldTable& ft) : cachedBytes(ft.cachedBytes), - cachedSize(ft.cachedSize) + cachedSize(ft.cachedSize), + newBytes(ft.newBytes) { // Only copy the values if we have no raw data // - copying the map is expensive and we can // reconstruct it if necessary from the raw data - if (!cachedBytes && !ft.values.empty()) values = ft.values; + if (cachedBytes) { + newBytes = true; + return; + } + if (!ft.values.empty()) values = ft.values; } FieldTable& FieldTable::operator=(const FieldTable& ft) @@ -52,10 +75,13 @@ FieldTable& FieldTable::operator=(const FieldTable& ft) values.swap(nft.values); cachedBytes.swap(nft.cachedBytes); cachedSize = nft.cachedSize; + newBytes = nft.newBytes; return (*this); } uint32_t FieldTable::encodedSize() const { + ScopedLock<Mutex> l(lock); + if (cachedSize != 0) { return cachedSize; } @@ -238,6 +264,7 @@ void FieldTable::encode(Buffer& buffer) const { i->second->encode(buffer); } // Now create raw bytes in case we are used again + ScopedLock<Mutex> l(lock); cachedSize = buffer.getPosition() - p; cachedBytes = boost::shared_array<uint8_t>(new uint8_t[cachedSize]); buffer.setPosition(p); @@ -261,14 +288,17 @@ void FieldTable::decode(Buffer& buffer){ // Copy data into our buffer cachedBytes = boost::shared_array<uint8_t>(new uint8_t[len + 4]); cachedSize = len + 4; + newBytes = true; buffer.setPosition(p); buffer.getRawData(&cachedBytes[0], cachedSize); } void FieldTable::realDecode() const { + ScopedLock<Mutex> l(lock); + // If we've got no raw data stored up then nothing to do - if (!cachedBytes) + if (!newBytes) return; Buffer buffer((char*)&cachedBytes[0], cachedSize); @@ -286,10 +316,13 @@ void FieldTable::realDecode() const values[name] = ValuePtr(value); } } + newBytes = false; } -void FieldTable::flushRawCache() const +void FieldTable::flushRawCache() { + // We can only flush the cache if there are no cached bytes to decode + assert(newBytes==false); // Avoid recreating shared array unless we actually have one. if (cachedBytes) cachedBytes.reset(); cachedSize = 0; @@ -319,6 +352,7 @@ void FieldTable::erase(const std::string& name) void FieldTable::clear() { values.clear(); + newBytes = false; flushRawCache(); } diff --git a/qpid/cpp/src/qpid/framing/FrameSet.cpp b/qpid/cpp/src/qpid/framing/FrameSet.cpp index 255aaf6e6b..d2612e484f 100644 --- a/qpid/cpp/src/qpid/framing/FrameSet.cpp +++ b/qpid/cpp/src/qpid/framing/FrameSet.cpp @@ -26,7 +26,6 @@ #include "qpid/framing/TypeFilter.h" using namespace qpid::framing; -using namespace boost; FrameSet::FrameSet(const SequenceNumber& _id) : id(_id),contentSize(0),recalculateSize(true) { } FrameSet::FrameSet(const FrameSet& original) : id(original.id), contentSize(0), recalculateSize(true) diff --git a/qpid/cpp/src/qpid/framing/amqp_framing.h b/qpid/cpp/src/qpid/framing/amqp_framing.h index 3a8b39afb5..2e58922364 100644 --- a/qpid/cpp/src/qpid/framing/amqp_framing.h +++ b/qpid/cpp/src/qpid/framing/amqp_framing.h @@ -21,7 +21,6 @@ #include "qpid/framing/amqp_types.h" #include "qpid/framing/AMQFrame.h" #include "qpid/framing/AMQBody.h" -#include "qpid/framing/BodyHandler.h" #include "qpid/framing/AMQMethodBody.h" #include "qpid/framing/AMQHeaderBody.h" #include "qpid/framing/AMQContentBody.h" diff --git a/qpid/cpp/src/qpid/store/ms-clfs/Transaction.h b/qpid/cpp/src/qpid/store/ms-clfs/Transaction.h index fd07f2fb2e..499b01d503 100644 --- a/qpid/cpp/src/qpid/store/ms-clfs/Transaction.h +++ b/qpid/cpp/src/qpid/store/ms-clfs/Transaction.h @@ -27,6 +27,7 @@ #include <boost/enable_shared_from_this.hpp> #include <boost/shared_ptr.hpp> #include <string> +#include <vector> #include "TransactionLog.h" diff --git a/qpid/cpp/src/tests/CMakeLists.txt b/qpid/cpp/src/tests/CMakeLists.txt index 79c82106cb..bb4f52d319 100644 --- a/qpid/cpp/src/tests/CMakeLists.txt +++ b/qpid/cpp/src/tests/CMakeLists.txt @@ -151,13 +151,6 @@ set(unit_tests_to_build mark_as_advanced(unit_tests_to_build) -# Disabled till we move to amqp_0_10 codec. -# amqp_0_10/serialize.cpp allSegmentTypes.h \ -# amqp_0_10/ProxyTemplate.cpp \ -# amqp_0_10/apply.cpp \ -# amqp_0_10/Map.cpp \ -# amqp_0_10/handlers.cpp - add_executable (unit_test unit_test ${unit_tests_to_build} ${platform_test_additions}) target_link_libraries (unit_test @@ -326,7 +319,7 @@ if (BUILD_MSSQL) add_test (store_tests ${shell} ${CMAKE_CURRENT_SOURCE_DIR}/run_store_tests${test_script_suffix} MSSQL) endif (BUILD_MSSQL) if (BUILD_MSCLFS) - add_test (store_tests ${shell} ${CMAKE_CURRENT_SOURCE_DIR}/run_store_tests${test_script_suffix} MSSQL-CLFS) + add_test (store_tests_clfs ${shell} ${CMAKE_CURRENT_SOURCE_DIR}/run_store_tests${test_script_suffix} MSSQL-CLFS) endif (BUILD_MSCLFS) endif (PYTHON_EXECUTABLE) diff --git a/qpid/cpp/src/tests/Frame.cpp b/qpid/cpp/src/tests/Frame.cpp index 1270eabba3..cfcfde04a7 100644 --- a/qpid/cpp/src/tests/Frame.cpp +++ b/qpid/cpp/src/tests/Frame.cpp @@ -30,7 +30,6 @@ QPID_AUTO_TEST_SUITE(FrameTestSuite) using namespace std; using namespace qpid::framing; -using namespace boost; QPID_AUTO_TEST_CASE(testContentBody) { Frame f(42, AMQContentBody("foobar")); diff --git a/qpid/cpp/src/tests/Makefile.am b/qpid/cpp/src/tests/Makefile.am index a7f3bc1fbd..7c0afc4a63 100644 --- a/qpid/cpp/src/tests/Makefile.am +++ b/qpid/cpp/src/tests/Makefile.am @@ -352,7 +352,8 @@ EXTRA_DIST += \ run_queue_flow_limit_tests \ run_msg_group_tests \ ipv6_test \ - ha_tests.py + ha_tests.py \ + test_env.ps1.in check_LTLIBRARIES += libdlclose_noop.la libdlclose_noop_la_LDFLAGS = -module -rpath $(abs_builddir) diff --git a/qpid/cpp/src/tests/SessionState.cpp b/qpid/cpp/src/tests/SessionState.cpp index 3be9bb0cbc..1cf3415484 100644 --- a/qpid/cpp/src/tests/SessionState.cpp +++ b/qpid/cpp/src/tests/SessionState.cpp @@ -34,7 +34,6 @@ namespace tests { QPID_AUTO_TEST_SUITE(SessionStateTestSuite) using namespace std; -using namespace boost; using namespace qpid::framing; // ================================================================ diff --git a/qpid/cpp/src/tests/amqp_0_10/Map.cpp b/qpid/cpp/src/tests/amqp_0_10/Map.cpp deleted file mode 100644 index ffb235829e..0000000000 --- a/qpid/cpp/src/tests/amqp_0_10/Map.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - * - * 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 "amqp_0_10/unit_test.h" -#include "qpid/amqp_0_10/Map.h" -#include "qpid/amqp_0_10/Array.h" -#include "qpid/amqp_0_10/Struct32.h" -#include "qpid/amqp_0_10/UnknownType.h" -#include "qpid/amqp_0_10/Codec.h" -#include <iostream> - -using namespace qpid::amqp_0_10; -using namespace std; - -QPID_AUTO_TEST_SUITE(MapTestSuite) - - QPID_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; } -}; - -QPID_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&) {} -} - - -QPID_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"); -} - -QPID_AUTO_TEST_CASE(testEncode) { - Map map; - std::string data; - map["A"] = true; - map["b"] = Str8("hello"); - Codec::encode(back_inserter(data))(map); - BOOST_CHECK_EQUAL(Codec::size(map), data.size()); - 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/amqp_0_10/ProxyTemplate.cpp b/qpid/cpp/src/tests/amqp_0_10/ProxyTemplate.cpp deleted file mode 100644 index f54ee0da22..0000000000 --- a/qpid/cpp/src/tests/amqp_0_10/ProxyTemplate.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * - * 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 "amqp_0_10/unit_test.h" -#include "qpid/amqp_0_10/ProxyTemplate.h" -#include <boost/any.hpp> - -QPID_AUTO_TEST_SUITE(ProxyTemplateTestSuite) - -using namespace qpid::amqp_0_10; - -struct ToAny { - template <class T> - boost::any operator()(const T& t) { return boost::any(t); } -}; - -struct AnyProxy : public ProxyTemplate<ToAny, boost::any> {}; - -QPID_AUTO_TEST_CASE(testAnyProxy) { - AnyProxy p; - boost::any a=p.connectionTune(1,2,3,4); - BOOST_CHECK_EQUAL(a.type().name(), typeid(connection::Tune).name()); - connection::Tune* tune=boost::any_cast<connection::Tune>(&a); - BOOST_REQUIRE(tune); - 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() diff --git a/qpid/cpp/src/tests/amqp_0_10/apply.cpp b/qpid/cpp/src/tests/amqp_0_10/apply.cpp deleted file mode 100644 index 0aa4421791..0000000000 --- a/qpid/cpp/src/tests/amqp_0_10/apply.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* - * - * 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 "amqp_0_10/unit_test.h" -#include "qpid/amqp_0_10/specification.h" -#include "qpid/amqp_0_10/ApplyControl.h" - -QPID_AUTO_TEST_SUITE(VisitorTestSuite) - -using namespace qpid::amqp_0_10; - -struct GetCode : public ApplyFunctor<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) { - BOOST_CHECK_EQUAL(tune.channelMax, 1u); - BOOST_CHECK_EQUAL(tune.maxFrameSize, 2u); - BOOST_CHECK_EQUAL(tune.heartbeatMin, 3u); - BOOST_CHECK_EQUAL(tune.heartbeatMax, 4u); - return true; - } - template <class T> - bool operator()(const T&) { return false; } -}; - -QPID_AUTO_TEST_CASE(testApply) { - connection::Tune tune(1,2,3,4); - Control* p = &tune; - - // boost oddity - without the cast we get undefined symbol errors. - BOOST_CHECK_EQUAL(apply(GetCode(), *p), (uint8_t)connection::Tune::CODE); - - TestFunctor tf; - BOOST_CHECK(apply(tf, *p)); - - connection::Start start; - p = &start; - BOOST_CHECK(!apply(tf, *p)); - - apply(SetChannelMax(), tune); - BOOST_CHECK_EQUAL(tune.channelMax, 42); -} - -struct VoidTestFunctor { - typedef void result_type; - - int code; - VoidTestFunctor() : code() {} - - void operator()(const connection::Tune& tune) { - BOOST_CHECK_EQUAL(tune.channelMax, 1u); - BOOST_CHECK_EQUAL(tune.maxFrameSize, 2u); - BOOST_CHECK_EQUAL(tune.heartbeatMin, 3u); - BOOST_CHECK_EQUAL(tune.heartbeatMax, 4u); - code=connection::Tune::CODE; - } - template <class T> - void operator()(const T&) { code=0xFF; } -}; - -QPID_AUTO_TEST_CASE(testApplyVoid) { - connection::Tune tune(1,2,3,4); - Control* p = &tune; - VoidTestFunctor tf; - apply(tf, *p); - BOOST_CHECK_EQUAL(uint8_t(connection::Tune::CODE), tf.code); - - connection::Start start; - p = &start; - apply(tf, *p); - BOOST_CHECK_EQUAL(0xFF, tf.code); -} - -QPID_AUTO_TEST_SUITE_END() diff --git a/qpid/cpp/src/tests/amqp_0_10/handlers.cpp b/qpid/cpp/src/tests/amqp_0_10/handlers.cpp deleted file mode 100644 index 91bb304a17..0000000000 --- a/qpid/cpp/src/tests/amqp_0_10/handlers.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - * - * 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 "amqp_0_10/unit_test.h" -#include "qpid/Exception.h" -#include "qpid/amqp_0_10/Unit.h" -#include "qpid/amqp_0_10/ControlHolder.h" -#include "qpid/amqp_0_10/CommandHolder.h" -#include "qpid/amqp_0_10/handlers.h" -#include "qpid/amqp_0_10/specification.h" - -QPID_AUTO_TEST_SUITE(handler_tests) - -using namespace qpid::amqp_0_10; -using namespace std; - -string called; // Set by called handler function - -// Note on handlers: -// -// Control and Command handlers are separate, both behave the same way, -// so substitute "control or command" for command in the following. -// -// Command handlers derive from CommandHandler and implement functions -// for all the commands they handle. Handling an unimplemented command -// will raise NotImplementedException. -// -// Using virtual inheritance from CommandHandler allows multiple -// handlers to be aggregated into one with multiple inheritance, -// See test code for example. -// -// E.g. the existing broker model would have two control handlers: -// - ConnectionHandler: ControlHandler for connection controls. -// - SessionHandler: ControlHandler for session controls. -// It would have class-command handlers for each AMQP class: -// - QueueHandler, MessageHandler etc.. handle each class. -// And an aggregate handler in place of BrokerAdapter -// - BrokerCommandHandler: public QueueHandler, MessageHandler ... -// -// In other applications (e.g. cluster) any combination of commands -// can be handled by a given handler. It _might_ simplify the code -// to collaps ConnectionHandler and SessionHandler into a single -// ControlHandler (or it might not.) - -struct TestExecutionHandler : public virtual CommandHandler { - void executionSync() { called = "executionSync"; } - // ... etc. for all execution commands -}; - -struct TestMessageHandler : public virtual CommandHandler { - void messageCancel(const Str8&) { called="messageCancel"; } - // ... etc. -}; - -// Aggregate handler for all recognised commands. -struct TestCommandHandler : - public TestExecutionHandler, - public TestMessageHandler - // ... etc. handlers for all command classes. -{}; // Nothing to do. - - -// Sample unit handler, written as a static_visitor. -// Note it could equally be written with if/else statements -// in handle. -// -struct TestUnitHandler : public boost::static_visitor<void> { - TestCommandHandler handler; - void handle(const Unit& u) { u.applyVisitor(*this); } - - void operator()(const Body&) { called="Body"; } - void operator()(const Header&) { called="Header"; } - void operator()(const ControlHolder&) { throw qpid::Exception("I don't do controls."); } - void operator()(const CommandHolder& c) { c.invoke(handler); } -}; - -QPID_AUTO_TEST_CASE(testHandlers) { - TestUnitHandler handler; - Unit u; - - u = Body(); - handler.handle(u); - BOOST_CHECK_EQUAL("Body", called); - - u = Header(); - handler.handle(u); - BOOST_CHECK_EQUAL("Header", called); - - // in_place<Foo>(...) is equivalent to Foo(...) but - // constructs Foo directly in the holder, avoiding - // a copy. - - u = CommandHolder(in_place<execution::Sync>()); - handler.handle(u); - BOOST_CHECK_EQUAL("executionSync", called); - - u = ControlHolder(in_place<connection::Start>(Map(), Str16Array(), Str16Array())); - try { - handler.handle(u); - } catch (const qpid::Exception&) {} - - u = CommandHolder(in_place<message::Cancel>(Str8())); - handler.handle(u); - BOOST_CHECK_EQUAL("messageCancel", called); -} - -QPID_AUTO_TEST_SUITE_END() diff --git a/qpid/cpp/src/tests/amqp_0_10/serialize.cpp b/qpid/cpp/src/tests/amqp_0_10/serialize.cpp deleted file mode 100644 index 975d6206ec..0000000000 --- a/qpid/cpp/src/tests/amqp_0_10/serialize.cpp +++ /dev/null @@ -1,429 +0,0 @@ -/* - * - * 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 "amqp_0_10/unit_test.h" -#include "amqp_0_10/allSegmentTypes.h" - -#include "qpid/framing/AMQFrame.h" -#include "qpid/framing/Buffer.h" - -#include "qpid/amqp_0_10/Packer.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 "qpid/amqp_0_10/Struct32.h" -#include "qpid/amqp_0_10/FrameHeader.h" -#include "qpid/amqp_0_10/Map.h" -#include "qpid/amqp_0_10/Unit.h" -#include "allSegmentTypes.h" - -#include <boost/test/test_case_template.hpp> -#include <boost/type_traits/is_arithmetic.hpp> -#include <boost/utility/enable_if.hpp> -#include <boost/optional.hpp> -#include <boost/mpl/vector.hpp> -#include <boost/mpl/back_inserter.hpp> -#include <boost/mpl/copy.hpp> -#include <boost/mpl/empty_sequence.hpp> -#include <boost/current_function.hpp> -#include <iterator> -#include <string> -#include <sstream> -#include <iostream> -#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 - -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; }; -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<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<Map, 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. -QPID_AUTO_TEST_CASE(testNetworkByteOrder) { - string data; - - uint32_t l = 0x11223344; - 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); - uint32_t s2 = ntohs(*reinterpret_cast<const uint32_t*>(data.data())); - BOOST_CHECK_EQUAL(s, s2); -} - -QPID_AUTO_TEST_CASE(testSetLimit) { - typedef Codec::Encoder<back_insert_iterator<string> > Encoder; - string data; - Encoder encode(back_inserter(data), 3); - encode('1')('2')('3'); - try { - encode('4'); - BOOST_FAIL("Expected exception"); - } catch (...) {} // FIXME aconway 2008-04-03: catch proper exception - BOOST_CHECK_EQUAL(data, "123"); -} - -QPID_AUTO_TEST_CASE(testScopedLimit) { - typedef Codec::Encoder<back_insert_iterator<string> > Encoder; - string data; - Encoder encode(back_inserter(data), 10); - encode(Str8("123")); // 4 bytes - { - Encoder::ScopedLimit l(encode, 3); - encode('a')('b')('c'); - try { - encode('d'); - BOOST_FAIL("Expected exception"); - } catch(...) {} // FIXME aconway 2008-04-03: catch proper exception - } - BOOST_CHECK_EQUAL(data, "\003123abc"); - encode('x')('y')('z'); - try { - encode('!'); - BOOST_FAIL("Expected exception"); - } catch(...) {} // FIXME aconway 2008-04-03: catch proper exception - BOOST_CHECK_EQUAL(data.size(), 10u); -} - -// 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, 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) -{ - 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); -} -*/ - -struct TestMe { - bool encoded, decoded; - char value; - TestMe(char v) : encoded(), decoded(), value(v) {} - 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); } -}; - -QPID_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'); -} - -QPID_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::Decoder<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_CASE(testStruct32) { - message::DeliveryProperties dp; - dp.priority=message::MEDIUM; - dp.routingKey="foo"; - Struct32 s(dp); - string data; - Codec::encode(back_inserter(data))(s); - - uint32_t structSize; // Starts with size - Codec::decode(data.begin())(structSize); - BOOST_CHECK_EQUAL(structSize, Codec::size(dp) + 2); // +2 for code - BOOST_CHECK_EQUAL(structSize, data.size()-4); // encoded body - - BOOST_CHECK_EQUAL(data.size(), Codec::size(s)); - Struct32 s2; - Codec::decode(data.begin())(s2); - message::DeliveryProperties* dp2 = s2.getIf<message::DeliveryProperties>(); - BOOST_REQUIRE(dp2); - BOOST_CHECK_EQUAL(dp2->priority, message::MEDIUM); - BOOST_CHECK_EQUAL(dp2->routingKey, "foo"); -} - -QPID_AUTO_TEST_CASE(testStruct32Unknown) { - // Verify we can recode an unknown struct unchanged. - Struct32 s; - string data; - Codec::encode(back_inserter(data))(uint32_t(10)); - data.append(10, 'X'); - Codec::decode(data.begin())(s); - string data2; - Codec::encode(back_inserter(data2))(s); - BOOST_CHECK_EQUAL(data.size(), data2.size()); - BOOST_CHECK_EQUAL(data, data2); -} - -struct DummyPacked { - static const uint8_t PACK=1; - boost::optional<char> i, j; - char k; - Bit l,m; - DummyPacked(char a=0, char b=0, char c=0) : i(a), j(b), k(c), l(), m() {} - template <class S> void serialize(S& s) { s(i)(j)(k)(l)(m); } -}; - -Packer<DummyPacked> serializable(DummyPacked& d) { return Packer<DummyPacked>(d); } - -QPID_AUTO_TEST_CASE(testPackBits) { - DummyPacked d('a','b','c'); - BOOST_CHECK_EQUAL(packBits(d), 7u); - d.j = boost::none; - BOOST_CHECK_EQUAL(packBits(d), 5u); - d.m = true; - BOOST_CHECK_EQUAL(packBits(d), 0x15u); -} - - -QPID_AUTO_TEST_CASE(testPacked) { - string data; - - Codec::encode(back_inserter(data))('a')(boost::optional<char>('b'))(boost::optional<char>())('c'); - BOOST_CHECK_EQUAL(data, "abc"); - data.clear(); - - DummyPacked dummy('a','b','c'); - - Codec::encode(back_inserter(data))(dummy); - BOOST_CHECK_EQUAL(data.size(), 4u); - BOOST_CHECK_EQUAL(data, string("\007abc")); - data.clear(); - - dummy.i = boost::none; - Codec::encode(back_inserter(data))(dummy); - BOOST_CHECK_EQUAL(data, string("\6bc")); - data.clear(); - - const char* missing = "\5xy"; - Codec::decode(missing)(dummy); - BOOST_CHECK(dummy.i); - BOOST_CHECK_EQUAL(*dummy.i, 'x'); - BOOST_CHECK(!dummy.j); - BOOST_CHECK_EQUAL(dummy.k, 'y'); -} - -QPID_AUTO_TEST_CASE(testUnitControl) { - string data; - Control::Holder h(in_place<connection::Tune>(1,2,3,4)); - Codec::encode(std::back_inserter(data))(h); - - Unit unit(FrameHeader(FIRST_FRAME|LAST_FRAME, CONTROL)); - Codec::decode(data.begin())(unit); - - BOOST_REQUIRE(unit.get<ControlHolder>()); - - string data2; - Codec::encode(back_inserter(data2))(unit); - - BOOST_CHECK_EQUAL(data, data2); -} - -QPID_AUTO_TEST_CASE(testArray) { - ArrayDomain<char> a; - a.resize(3, 'x'); - string data; - Codec::encode(back_inserter(data))(a); - - ArrayDomain<char> b; - Codec::decode(data.begin())(b); - BOOST_CHECK_EQUAL(b.size(), 3u); - string data3; - Codec::encode(back_inserter(data3))(a); - BOOST_CHECK_EQUAL(data, data3); - - Array x; - Codec::decode(data.begin())(x); - BOOST_CHECK_EQUAL(x.size(), 3u); - BOOST_CHECK_EQUAL(x[0].size(), 1u); - BOOST_CHECK_EQUAL(*x[0].begin(), 'x'); - BOOST_CHECK_EQUAL(*x[2].begin(), 'x'); - - string data2; - Codec::encode(back_inserter(data2))(x); - BOOST_CHECK_EQUAL(data,data2); -} - -QPID_AUTO_TEST_CASE(testStruct) { - string data; - - message::DeliveryProperties dp; - BOOST_CHECK(!dp.discardUnroutable); - dp.immediate = true; - dp.redelivered = false; - dp.priority = message::MEDIUM; - dp.exchange = "foo"; - - Codec::encode(back_inserter(data))(dp); - // Skip 4 bytes size, little-endian decode for pack bits. - uint16_t encodedBits=uint8_t(data[5]); - encodedBits <<= 8; - encodedBits += uint8_t(data[4]); - BOOST_CHECK_EQUAL(encodedBits, packBits(dp)); - - data.clear(); - Struct32 h(dp); - Codec::encode(back_inserter(data))(h); - - Struct32 h2; - Codec::decode(data.begin())(h2); - BOOST_CHECK_EQUAL(h2.getClassCode(), Uint8(message::DeliveryProperties::CLASS_CODE)); - BOOST_CHECK_EQUAL(h2.getCode(), Uint8(message::DeliveryProperties::CODE)); - message::DeliveryProperties* dp2 = - dynamic_cast<message::DeliveryProperties*>(h2.get()); - BOOST_CHECK(dp2); - BOOST_CHECK(!dp2->discardUnroutable); - BOOST_CHECK(dp2->immediate); - BOOST_CHECK(!dp2->redelivered); - BOOST_CHECK_EQUAL(dp2->priority, message::MEDIUM); - BOOST_CHECK_EQUAL(dp2->exchange, "foo"); -} - -struct RecodeUnit { - template <class T> - void operator() (const T& t) { - BOOST_MESSAGE(BOOST_CURRENT_FUNCTION << " called with: " << t); - using qpid::framing::Buffer; - using qpid::framing::AMQFrame; - - session::Header sh; - BOOST_CHECK_EQUAL(Codec::size(sh), 2u); - - // Encode unit. - Unit u(t); - string data; - Codec::encode(back_inserter(data))(u.getHeader())(u); - data.push_back(char(0xCE)); // Preview end-of-frame - - // Decode AMQFrame - Buffer buf(&data[0], data.size()); - AMQFrame f; - f.decode(buf); - BOOST_MESSAGE("AMQFrame decoded: " << f); - // Encode AMQFrame - string data2(f.size(), ' '); - Buffer buf2(&data2[0], data.size()); - f.encode(buf2); - - // Verify encoded by unit == encoded by AMQFrame - BOOST_CHECK_MESSAGE(data == data2, BOOST_CURRENT_FUNCTION); - - // Decode unit - // FIXME aconway 2008-04-15: must set limit to decode a header. - Codec::Decoder<string::iterator> decode(data2.begin(), data2.size()-1); - - FrameHeader h; - decode(h); - BOOST_CHECK_EQUAL(u.getHeader(), h); - Unit u2(h); - decode(u2); - - // Re-encode unit - string data3; - Codec::encode(back_inserter(data3))(u2.getHeader())(u2); - data3.push_back(char(0xCE)); // Preview end-of-frame - - BOOST_CHECK_MESSAGE(data3 == data2, BOOST_CURRENT_FUNCTION); - } -}; - -QPID_AUTO_TEST_CASE(testSerializeAllSegmentTypes) { - RecodeUnit recode; - allSegmentTypes(recode); -} - -QPID_AUTO_TEST_SUITE_END() diff --git a/qpid/cpp/src/tests/logging.cpp b/qpid/cpp/src/tests/logging.cpp index dcecf0b54c..5d5bb1feef 100644 --- a/qpid/cpp/src/tests/logging.cpp +++ b/qpid/cpp/src/tests/logging.cpp @@ -44,8 +44,10 @@ namespace tests { QPID_AUTO_TEST_SUITE(loggingTestSuite) using namespace std; -using namespace boost; using namespace qpid::log; +using boost::ends_with; +using boost::contains; +using boost::format; QPID_AUTO_TEST_CASE(testStatementInit) { Statement s=QPID_LOG_STATEMENT_INIT(debug); int line=__LINE__; diff --git a/qpid/cpp/src/tests/ssl_test b/qpid/cpp/src/tests/ssl_test index fc634ba242..ac978d3bd0 100755 --- a/qpid/cpp/src/tests/ssl_test +++ b/qpid/cpp/src/tests/ssl_test @@ -100,8 +100,10 @@ start_ssl_mux_broker() { PORTS=( ${PORTS[@]} $1 ) } +sasl_config_dir=$builddir/sasl_config + start_authenticating_broker() { - start_brokers 1 "--transport ssl --ssl-port 0 --require-encryption --ssl-sasl-no-dict --ssl-require-client-authentication --auth yes" + start_brokers 1 "--transport ssl --ssl-port 0 --require-encryption --ssl-sasl-no-dict --ssl-require-client-authentication --auth yes --sasl-config=${sasl_config_dir}" } ssl_cluster_broker() { # $1 = port |
