summaryrefslogtreecommitdiff
path: root/cpp/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/tests')
-rw-r--r--cpp/tests/MessageBuilderTest.cpp72
-rw-r--r--cpp/tests/TxAckTest.cpp18
-rw-r--r--cpp/tests/TxPublishTest.cpp12
3 files changed, 56 insertions, 46 deletions
diff --git a/cpp/tests/MessageBuilderTest.cpp b/cpp/tests/MessageBuilderTest.cpp
index 3f84142461..88e8318832 100644
--- a/cpp/tests/MessageBuilderTest.cpp
+++ b/cpp/tests/MessageBuilderTest.cpp
@@ -50,7 +50,7 @@ class MessageBuilderTest : public CppUnit::TestCase
public:
- void stage(Message::shared_ptr& msg)
+ void stage(Message* const msg)
{
if (msg->getPersistenceId() == 0) {
header = new Buffer(msg->encodedHeaderSize());
@@ -71,6 +71,11 @@ class MessageBuilderTest : public CppUnit::TestCase
}
}
+ void destroy(Message* msg)
+ {
+ CPPUNIT_ASSERT(msg->getPersistenceId());
+ }
+
Message::shared_ptr getRestoredMessage()
{
Message::shared_ptr msg(new Message());
@@ -164,37 +169,42 @@ class MessageBuilderTest : public CppUnit::TestCase
}
void testStaging(){
- DummyHandler handler;
+ //store must be the last thing to be destroyed or destructor
+ //of Message fails (it uses the store to call destroy if lazy
+ //loaded content is in use)
TestMessageStore store(14);
- MessageBuilder builder(&handler, &store, 5);
-
- string data1("abcdefg");
- string data2("hijklmn");
-
- Message::shared_ptr message(new Message(0, "test", "my_routing_key", false, false));
- AMQHeaderBody::shared_ptr header(new AMQHeaderBody(BASIC));
- header->setContentSize(14);
- BasicHeaderProperties* properties = dynamic_cast<BasicHeaderProperties*>(header->getProperties());
- properties->setMessageId("MyMessage");
- properties->getHeaders().setString("abc", "xyz");
-
- AMQContentBody::shared_ptr part1(new AMQContentBody(data1));
- AMQContentBody::shared_ptr part2(new AMQContentBody(data2));
-
- builder.initialise(message);
- builder.setHeader(header);
- builder.addContent(part1);
- builder.addContent(part2);
- CPPUNIT_ASSERT(handler.msg);
- CPPUNIT_ASSERT_EQUAL(message, handler.msg);
-
- Message::shared_ptr restored = store.getRestoredMessage();
- CPPUNIT_ASSERT_EQUAL(message->getExchange(), restored->getExchange());
- CPPUNIT_ASSERT_EQUAL(message->getRoutingKey(), restored->getRoutingKey());
- CPPUNIT_ASSERT_EQUAL(message->getHeaderProperties()->getMessageId(), restored->getHeaderProperties()->getMessageId());
- CPPUNIT_ASSERT_EQUAL(message->getHeaderProperties()->getHeaders().getString("abc"),
- restored->getHeaderProperties()->getHeaders().getString("abc"));
- CPPUNIT_ASSERT_EQUAL((u_int64_t) 14, restored->contentSize());
+ {
+ DummyHandler handler;
+ MessageBuilder builder(&handler, &store, 5);
+
+ string data1("abcdefg");
+ string data2("hijklmn");
+
+ Message::shared_ptr message(new Message(0, "test", "my_routing_key", false, false));
+ AMQHeaderBody::shared_ptr header(new AMQHeaderBody(BASIC));
+ header->setContentSize(14);
+ BasicHeaderProperties* properties = dynamic_cast<BasicHeaderProperties*>(header->getProperties());
+ properties->setMessageId("MyMessage");
+ properties->getHeaders().setString("abc", "xyz");
+
+ AMQContentBody::shared_ptr part1(new AMQContentBody(data1));
+ AMQContentBody::shared_ptr part2(new AMQContentBody(data2));
+
+ builder.initialise(message);
+ builder.setHeader(header);
+ builder.addContent(part1);
+ builder.addContent(part2);
+ CPPUNIT_ASSERT(handler.msg);
+ CPPUNIT_ASSERT_EQUAL(message, handler.msg);
+
+ Message::shared_ptr restored = store.getRestoredMessage();
+ CPPUNIT_ASSERT_EQUAL(message->getExchange(), restored->getExchange());
+ CPPUNIT_ASSERT_EQUAL(message->getRoutingKey(), restored->getRoutingKey());
+ CPPUNIT_ASSERT_EQUAL(message->getHeaderProperties()->getMessageId(), restored->getHeaderProperties()->getMessageId());
+ CPPUNIT_ASSERT_EQUAL(message->getHeaderProperties()->getHeaders().getString("abc"),
+ restored->getHeaderProperties()->getHeaders().getString("abc"));
+ CPPUNIT_ASSERT_EQUAL((u_int64_t) 14, restored->contentSize());
+ }
}
};
diff --git a/cpp/tests/TxAckTest.cpp b/cpp/tests/TxAckTest.cpp
index 709d45c1ad..6832c5995b 100644
--- a/cpp/tests/TxAckTest.cpp
+++ b/cpp/tests/TxAckTest.cpp
@@ -37,9 +37,9 @@ class TxAckTest : public CppUnit::TestCase
class TestMessageStore : public NullMessageStore
{
public:
- vector<Message::shared_ptr> dequeued;
+ vector<Message*> dequeued;
- void dequeue(TransactionContext*, Message::shared_ptr& msg, const Queue& /*queue*/, const string * const /*xid*/)
+ void dequeue(TransactionContext*, Message* const msg, const Queue& /*queue*/, const string * const /*xid*/)
{
dequeued.push_back(msg);
}
@@ -86,13 +86,13 @@ public:
op.prepare(0);
CPPUNIT_ASSERT_EQUAL((size_t) 7, store.dequeued.size());
CPPUNIT_ASSERT_EQUAL((size_t) 10, deliveries.size());
- CPPUNIT_ASSERT_EQUAL(messages[0], store.dequeued[0]);//msg 1
- CPPUNIT_ASSERT_EQUAL(messages[1], store.dequeued[1]);//msg 2
- CPPUNIT_ASSERT_EQUAL(messages[2], store.dequeued[2]);//msg 3
- CPPUNIT_ASSERT_EQUAL(messages[3], store.dequeued[3]);//msg 4
- CPPUNIT_ASSERT_EQUAL(messages[4], store.dequeued[4]);//msg 5
- CPPUNIT_ASSERT_EQUAL(messages[6], store.dequeued[5]);//msg 7
- CPPUNIT_ASSERT_EQUAL(messages[8], store.dequeued[6]);//msg 9
+ CPPUNIT_ASSERT_EQUAL(messages[0].get(), store.dequeued[0]);//msg 1
+ CPPUNIT_ASSERT_EQUAL(messages[1].get(), store.dequeued[1]);//msg 2
+ CPPUNIT_ASSERT_EQUAL(messages[2].get(), store.dequeued[2]);//msg 3
+ CPPUNIT_ASSERT_EQUAL(messages[3].get(), store.dequeued[3]);//msg 4
+ CPPUNIT_ASSERT_EQUAL(messages[4].get(), store.dequeued[4]);//msg 5
+ CPPUNIT_ASSERT_EQUAL(messages[6].get(), store.dequeued[5]);//msg 7
+ CPPUNIT_ASSERT_EQUAL(messages[8].get(), store.dequeued[6]);//msg 9
}
void testCommit()
diff --git a/cpp/tests/TxPublishTest.cpp b/cpp/tests/TxPublishTest.cpp
index 6324e5fb01..d33d84ec6e 100644
--- a/cpp/tests/TxPublishTest.cpp
+++ b/cpp/tests/TxPublishTest.cpp
@@ -38,11 +38,11 @@ class TxPublishTest : public CppUnit::TestCase
class TestMessageStore : public NullMessageStore
{
public:
- vector< pair<string, Message::shared_ptr> > enqueued;
+ vector< pair<string, Message*> > enqueued;
- void enqueue(TransactionContext*, Message::shared_ptr& msg, const Queue& queue, const string * const /*xid*/)
+ void enqueue(TransactionContext*, Message* const msg, const Queue& queue, const string * const /*xid*/)
{
- enqueued.push_back(pair<string, Message::shared_ptr>(queue.getName(),msg));
+ enqueued.push_back(pair<string, Message*>(queue.getName(),msg));
}
//dont care about any of the other methods:
@@ -59,7 +59,7 @@ class TxPublishTest : public CppUnit::TestCase
TestMessageStore store;
Queue::shared_ptr queue1;
Queue::shared_ptr queue2;
- Message::shared_ptr msg;
+ Message::shared_ptr const msg;
TxPublish op;
@@ -82,9 +82,9 @@ public:
op.prepare(0);
CPPUNIT_ASSERT_EQUAL((size_t) 2, store.enqueued.size());
CPPUNIT_ASSERT_EQUAL(string("queue1"), store.enqueued[0].first);
- CPPUNIT_ASSERT_EQUAL(msg, store.enqueued[0].second);
+ CPPUNIT_ASSERT_EQUAL(msg.get(), store.enqueued[0].second);
CPPUNIT_ASSERT_EQUAL(string("queue2"), store.enqueued[1].first);
- CPPUNIT_ASSERT_EQUAL(msg, store.enqueued[1].second);
+ CPPUNIT_ASSERT_EQUAL(msg.get(), store.enqueued[1].second);
}
void testCommit()