summaryrefslogtreecommitdiff
path: root/cpp/src/tests
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2007-04-05 19:16:09 +0000
committerAlan Conway <aconway@apache.org>2007-04-05 19:16:09 +0000
commitbb79efff2408de5f6cd66089cde8b8a82cc80cc2 (patch)
tree9d9c72158da31cebdd7ee538a11951b240922065 /cpp/src/tests
parent2a1e4c9663ff0725c061248a96ebab763678fdd6 (diff)
downloadqpid-python-bb79efff2408de5f6cd66089cde8b8a82cc80cc2.tar.gz
* Exteneded use of shared pointers frame bodies across all send() commands.
* tests/Makefile.am: added check-unit target to run just unit tests. * Introduced make_shared_ptr convenience function for wrapping plain pointers with shared_ptr. * cpp/src/client/ClientChannel.h,cpp (sendsendAndReceive,sendAndReceiveSync): Pass shared_ptr instead of raw ptr to fix memory problems. Updated the following files to use make_shared_ptr - src/client/BasicMessageChannel.cpp - src/client/ClientConnection.cpp * src/client/MessageMessageChannel.cpp: implemented 0-9 message.get. * src/framing/Correlator.h,cpp: Allow request sender to register actions to take when the correlated response arrives. * cpp/src/tests/FramingTest.cpp: Added Correlator tests. * src/framing/ChannelAdapter.h,cpp: use Correlator to dispatch response actions. * cpp/src/shared_ptr.h (make_shared_ptr): Convenience function to make a shared pointer from a raw pointer. * cpp/src/tests/ClientChannelTest.cpp: Added message.get test. * cpp/src/tests/Makefile.am (check-unit): Added test-unit target to run unit tests. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@525932 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/tests')
-rw-r--r--cpp/src/tests/ClientChannelTest.cpp11
-rw-r--r--cpp/src/tests/FramingTest.cpp53
-rw-r--r--cpp/src/tests/Makefile.am3
3 files changed, 63 insertions, 4 deletions
diff --git a/cpp/src/tests/ClientChannelTest.cpp b/cpp/src/tests/ClientChannelTest.cpp
index d5d1005aa9..8dc3e4b432 100644
--- a/cpp/src/tests/ClientChannelTest.cpp
+++ b/cpp/src/tests/ClientChannelTest.cpp
@@ -27,6 +27,7 @@
#include "../client/ClientExchange.h"
#include "../client/MessageListener.h"
#include "../client/BasicMessageChannel.h"
+#include "../client/MessageMessageChannel.h"
using namespace std;
using namespace boost;
@@ -203,7 +204,17 @@ class BasicClientChannelTest : public ClientChannelTestBase {
}
};
+class MessageClientChannelTest : public ClientChannelTestBase {
+ CPPUNIT_TEST_SUITE(MessageClientChannelTest);
+ CPPUNIT_TEST(testPublishGet);
+ CPPUNIT_TEST_SUITE_END();
+ public:
+ MessageClientChannelTest() {
+ channel.reset(new Channel(false, 500, Channel::AMQP_09));
+ }
+};
// Make this test suite a plugin.
CPPUNIT_PLUGIN_IMPLEMENT();
CPPUNIT_TEST_SUITE_REGISTRATION(BasicClientChannelTest);
+CPPUNIT_TEST_SUITE_REGISTRATION(MessageClientChannelTest);
diff --git a/cpp/src/tests/FramingTest.cpp b/cpp/src/tests/FramingTest.cpp
index 954c378c37..aa7cd90bc2 100644
--- a/cpp/src/tests/FramingTest.cpp
+++ b/cpp/src/tests/FramingTest.cpp
@@ -18,9 +18,6 @@
* under the License.
*
*/
-#include <memory>
-#include <boost/lexical_cast.hpp>
-
#include "ConnectionRedirectBody.h"
#include "../framing/ProtocolVersion.h"
#include "../framing/amqp_framing.h"
@@ -38,6 +35,11 @@
#include "../client/Connection.h"
#include "../client/ClientExchange.h"
#include "../client/ClientQueue.h"
+#include "../framing/Correlator.h"
+#include "BasicGetOkBody.h"
+#include <memory>
+#include <boost/lexical_cast.hpp>
+#include <boost/bind.hpp>
using namespace qpid;
using namespace qpid::framing;
@@ -65,6 +67,7 @@ class FramingTest : public CppUnit::TestCase
CPPUNIT_TEST(testResponseBodyFrame);
CPPUNIT_TEST(testRequester);
CPPUNIT_TEST(testResponder);
+ CPPUNIT_TEST(testCorrelator);
CPPUNIT_TEST(testInlineContent);
CPPUNIT_TEST(testContentReference);
CPPUNIT_TEST(testContentValidation);
@@ -300,7 +303,7 @@ class FramingTest : public CppUnit::TestCase
Responder r;
AMQRequestBody::Data q;
AMQResponseBody::Data p;
-
+
q.requestId = 1;
q.responseMark = 0;
r.received(q);
@@ -335,6 +338,48 @@ class FramingTest : public CppUnit::TestCase
}
+
+ std::vector<Correlator::ResponsePtr> correlations;
+
+ void correlatorCallback(Correlator::ResponsePtr r) {
+ correlations.push_back(r);
+ }
+
+ struct DummyResponse : public AMQResponseBody {
+ DummyResponse(ResponseId id=0, RequestId req=0, BatchOffset off=0)
+ : AMQResponseBody(version, id, req, off) {}
+ uint32_t size() const { return 0; }
+ void print(std::ostream&) const {}
+ MethodId amqpMethodId() const { return 0; }
+ ClassId amqpClassId() const { return 0; }
+ void encodeContent(Buffer& ) const {}
+ void decodeContent(Buffer& ) {}
+ };
+
+ void testCorrelator() {
+ CPPUNIT_ASSERT(correlations.empty());
+ Correlator c;
+ Correlator::Action action = boost::bind(&FramingTest::correlatorCallback, this, _1);
+ c.request(5, action);
+ Correlator::ResponsePtr r1(new DummyResponse(3, 5, 0));
+ CPPUNIT_ASSERT(c.response(r1));
+ CPPUNIT_ASSERT_EQUAL(size_t(1), correlations.size());
+ CPPUNIT_ASSERT(correlations.front() == r1);
+ correlations.clear();
+
+ c.request(6, action);
+ c.request(7, action);
+ c.request(8, action);
+ Correlator::ResponsePtr r2(new DummyResponse(4, 6, 3));
+ CPPUNIT_ASSERT(c.response(r2));
+ CPPUNIT_ASSERT_EQUAL(size_t(3), correlations.size());
+ CPPUNIT_ASSERT(r2 == correlations[0]);
+ CPPUNIT_ASSERT(r2 == correlations[1]);
+ CPPUNIT_ASSERT(r2 == correlations[2]);
+ Correlator::ResponsePtr r3(new DummyResponse(5, 99, 0));
+ CPPUNIT_ASSERT(!c.response(r3));
+ }
+
// expect may contain null chars so use string(ptr,size) constructor
// Use sizeof(expect)-1 to strip the trailing null.
#define ASSERT_FRAME(expect, frame) \
diff --git a/cpp/src/tests/Makefile.am b/cpp/src/tests/Makefile.am
index 0dc6c3343e..a5d1fdbab5 100644
--- a/cpp/src/tests/Makefile.am
+++ b/cpp/src/tests/Makefile.am
@@ -110,6 +110,9 @@ gen.mk: Makefile.am
check: .valgrindrc $(check_LTLIBRARIES) $(lib_common) $(lib_client) $(lib_broker)
+check-unit:
+ $(MAKE) check TESTS=run-unit-tests
+
# Create a copy so user can modify without risk of checking in their mods.
.valgrindrc: .valgrindrc-default
cp .valgrindrc-default .valgrindrc