diff options
Diffstat (limited to 'cpp/tests')
-rw-r--r-- | cpp/tests/BrokerChannelTest.cpp | 28 | ||||
-rw-r--r-- | cpp/tests/LazyLoadedContentTest.cpp | 2 | ||||
-rw-r--r-- | cpp/tests/MessageBuilderTest.cpp | 19 | ||||
-rw-r--r-- | cpp/tests/TxAckTest.cpp | 22 | ||||
-rw-r--r-- | cpp/tests/TxBufferTest.cpp | 19 | ||||
-rw-r--r-- | cpp/tests/TxPublishTest.cpp | 31 |
6 files changed, 47 insertions, 74 deletions
diff --git a/cpp/tests/BrokerChannelTest.cpp b/cpp/tests/BrokerChannelTest.cpp index 61135c898b..66a7138dab 100644 --- a/cpp/tests/BrokerChannelTest.cpp +++ b/cpp/tests/BrokerChannelTest.cpp @@ -68,7 +68,7 @@ class BrokerChannelTest : public CppUnit::TestCase struct MethodCall { const string name; - Message* const msg; + PersistableMessage* msg; const string data;//only needed for appendContent void check(const MethodCall& other) const @@ -92,7 +92,7 @@ class BrokerChannelTest : public CppUnit::TestCase } } - void handle(const string& name, Message* msg, const string& data) + void handle(const string& name, PersistableMessage* msg, const string& data) { MethodCall call = {name, msg, data}; handle(call); @@ -102,25 +102,25 @@ class BrokerChannelTest : public CppUnit::TestCase MockMessageStore() : expectMode(false) {} - void stage(Message* const msg) + void stage(PersistableMessage& msg) { - if(!expectMode) msg->setPersistenceId(1); - MethodCall call = {"stage", msg, ""}; + if(!expectMode) msg.setPersistenceId(1); + MethodCall call = {"stage", &msg, ""}; handle(call); } - void appendContent(Message* msg, const string& data) + void appendContent(PersistableMessage& msg, const string& data) { - MethodCall call = {"appendContent", msg, data}; + MethodCall call = {"appendContent", &msg, data}; handle(call); } // Don't hide overloads. using NullMessageStore::destroy; - void destroy(Message* msg) + void destroy(PersistableMessage& msg) { - MethodCall call = {"destroy", msg, ""}; + MethodCall call = {"destroy", &msg, ""}; handle(call); } @@ -249,11 +249,11 @@ class BrokerChannelTest : public CppUnit::TestCase MockChannel::basicGetBody()); store.expect(); - store.stage(msg); + store.stage(*msg); for (int i = 0; i < 3; i++) { - store.appendContent(msg, data[i]); + store.appendContent(*msg, data[i]); } - store.destroy(msg); + store.destroy(*msg); store.test(); Exchange::shared_ptr exchange = @@ -304,8 +304,8 @@ class BrokerChannelTest : public CppUnit::TestCase policy.update(settings); store.expect(); - store.stage(msg3.get()); - store.destroy(msg3.get()); + store.stage(*msg3); + store.destroy(*msg3); store.test(); Queue::shared_ptr queue(new Queue("my_queue", false, &store, 0)); diff --git a/cpp/tests/LazyLoadedContentTest.cpp b/cpp/tests/LazyLoadedContentTest.cpp index 5a4dd34b53..4cd8e9b307 100644 --- a/cpp/tests/LazyLoadedContentTest.cpp +++ b/cpp/tests/LazyLoadedContentTest.cpp @@ -50,7 +50,7 @@ class LazyLoadedContentTest : public CppUnit::TestCase public: TestMessageStore(const string& _content) : content(_content) {} - void loadContent(Message* const, string& data, uint64_t offset, uint32_t length) + void loadContent(PersistableMessage&, string& data, uint64_t offset, uint32_t length) { if (offset + length <= content.size()) { data = content.substr(offset, length); diff --git a/cpp/tests/MessageBuilderTest.cpp b/cpp/tests/MessageBuilderTest.cpp index d3b3902e97..68e5abf60e 100644 --- a/cpp/tests/MessageBuilderTest.cpp +++ b/cpp/tests/MessageBuilderTest.cpp @@ -51,33 +51,32 @@ class MessageBuilderTest : public CppUnit::TestCase public: - void stage(Message* const msg) + void stage(PersistableMessage& msg) { - if (msg->getPersistenceId() == 0) { - header = new Buffer(msg->encodedHeaderSize()); - msg->encodeHeader(*header); + if (msg.getPersistenceId() == 0) { + header = new Buffer(msg.encodedSize()); + msg.encode(*header); content = new Buffer(contentBufferSize); - msg->setPersistenceId(1); + msg.setPersistenceId(1); } else { throw qpid::Exception("Message already staged!"); } } - void appendContent(Message* msg, const string& data) + void appendContent(PersistableMessage& msg, const string& data) { - if (msg) { + if (msg.getPersistenceId() == 1) { content->putRawData(data); } else { throw qpid::Exception("Invalid message id!"); } } - // Don't hide overloads. using NullMessageStore::destroy; - void destroy(BasicMessage* msg) + void destroy(PersistableMessage& msg) { - CPPUNIT_ASSERT(msg->getPersistenceId()); + CPPUNIT_ASSERT(msg.getPersistenceId()); } BasicMessage::shared_ptr getRestoredMessage() diff --git a/cpp/tests/TxAckTest.cpp b/cpp/tests/TxAckTest.cpp index c189533ea9..eb4ada4ac8 100644 --- a/cpp/tests/TxAckTest.cpp +++ b/cpp/tests/TxAckTest.cpp @@ -38,11 +38,11 @@ class TxAckTest : public CppUnit::TestCase class TestMessageStore : public NullMessageStore { public: - vector< std::pair<Message*, const string*> > dequeued; + vector<PersistableMessage*> dequeued; - void dequeue(TransactionContext*, Message* const msg, const Queue& /*queue*/, const string * const xid) + void dequeue(TransactionContext*, PersistableMessage& msg, const PersistableQueue& /*queue*/) { - dequeued.push_back(std::pair<Message*, const string*>(msg, xid)); + dequeued.push_back(&msg); } TestMessageStore() : NullMessageStore() {} @@ -50,7 +50,6 @@ class TxAckTest : public CppUnit::TestCase }; CPPUNIT_TEST_SUITE(TxAckTest); - CPPUNIT_TEST(testPrepare2pc); CPPUNIT_TEST(testPrepare); CPPUNIT_TEST(testCommit); CPPUNIT_TEST_SUITE_END(); @@ -62,12 +61,11 @@ class TxAckTest : public CppUnit::TestCase vector<Message::shared_ptr> messages; list<DeliveryRecord> deliveries; TxAck op; - std::string xid; public: - TxAckTest() : acked(0), queue(new Queue("my_queue", false, &store, 0)), op(acked, deliveries, &xid) + TxAckTest() : acked(0), queue(new Queue("my_queue", false, &store, 0)), op(acked, deliveries) { for(int i = 0; i < 10; i++){ Message::shared_ptr msg( @@ -93,17 +91,7 @@ public: CPPUNIT_ASSERT_EQUAL((size_t) 10, deliveries.size()); int dequeued[] = {0, 1, 2, 3, 4, 6, 8}; for (int i = 0; i < 7; i++) { - CPPUNIT_ASSERT_EQUAL(messages[dequeued[i]].get(), store.dequeued[i].first); - } - } - - void testPrepare2pc() - { - xid = "abcdefg"; - testPrepare(); - const string expected(xid); - for (int i = 0; i < 7; i++) { - CPPUNIT_ASSERT_EQUAL(expected, *store.dequeued[i].second); + CPPUNIT_ASSERT_EQUAL((PersistableMessage*) messages[dequeued[i]].get(), store.dequeued[i]); } } diff --git a/cpp/tests/TxBufferTest.cpp b/cpp/tests/TxBufferTest.cpp index 8a9b233eb9..bd8ae3796b 100644 --- a/cpp/tests/TxBufferTest.cpp +++ b/cpp/tests/TxBufferTest.cpp @@ -102,22 +102,25 @@ class TxBufferTest : public CppUnit::TestCase public: MockTransactionalStore() : state(OPEN){} + std::auto_ptr<TPCTransactionContext> begin(const std::string&){ + throw "Operation not supported"; + } + void prepare(TPCTransactionContext&){ + throw "Operation not supported"; + } + std::auto_ptr<TransactionContext> begin(){ actual.push_back(BEGIN); std::auto_ptr<TransactionContext> txn(new TestTransactionContext(this)); return txn; } - void commit(TransactionContext* ctxt){ + void commit(TransactionContext& ctxt){ actual.push_back(COMMIT); - TestTransactionContext* txn(dynamic_cast<TestTransactionContext*>(ctxt)); - CPPUNIT_ASSERT(txn); - txn->commit(); + dynamic_cast<TestTransactionContext&>(ctxt).commit(); } - void abort(TransactionContext* ctxt){ + void abort(TransactionContext& ctxt){ actual.push_back(ABORT); - TestTransactionContext* txn(dynamic_cast<TestTransactionContext*>(ctxt)); - CPPUNIT_ASSERT(txn); - txn->abort(); + dynamic_cast<TestTransactionContext&>(ctxt).abort(); } MockTransactionalStore& expectBegin(){ expected.push_back(BEGIN); diff --git a/cpp/tests/TxPublishTest.cpp b/cpp/tests/TxPublishTest.cpp index d9d5607c06..8ce0da6508 100644 --- a/cpp/tests/TxPublishTest.cpp +++ b/cpp/tests/TxPublishTest.cpp @@ -35,22 +35,16 @@ using namespace qpid::framing; class TxPublishTest : public CppUnit::TestCase { - struct Triple - { - string first; - Message* second; - const string* third; - }; + typedef std::pair<string, PersistableMessage*> msg_queue_pair; class TestMessageStore : public NullMessageStore { public: - vector<Triple> enqueued; + vector<msg_queue_pair> enqueued; - void enqueue(TransactionContext*, Message* const msg, const Queue& queue, const string * const xid) + void enqueue(TransactionContext*, PersistableMessage& msg, const PersistableQueue& queue) { - Triple args = {queue.getName(), msg, xid}; - enqueued.push_back(args); + enqueued.push_back(msg_queue_pair(queue.getName(), &msg)); } //dont care about any of the other methods: @@ -60,7 +54,6 @@ class TxPublishTest : public CppUnit::TestCase CPPUNIT_TEST_SUITE(TxPublishTest); CPPUNIT_TEST(testPrepare); - CPPUNIT_TEST(testPrepare2pc); CPPUNIT_TEST(testCommit); CPPUNIT_TEST_SUITE_END(); @@ -70,7 +63,6 @@ class TxPublishTest : public CppUnit::TestCase Queue::shared_ptr queue2; Message::shared_ptr const msg; TxPublish op; - string xid; public: @@ -79,7 +71,7 @@ public: queue2(new Queue("queue2", false, &store, 0)), msg(new BasicMessage(0, "exchange", "routing_key", false, false, MockChannel::basicGetBody())), - op(msg, &xid) + op(msg) { msg->setHeader(AMQHeaderBody::shared_ptr(new AMQHeaderBody(BASIC))); msg->getHeaderProperties()->setDeliveryMode(PERSISTENT); @@ -93,18 +85,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.get(), store.enqueued[0].second); + CPPUNIT_ASSERT_EQUAL((PersistableMessage*) msg.get(), store.enqueued[0].second); CPPUNIT_ASSERT_EQUAL(string("queue2"), store.enqueued[1].first); - CPPUNIT_ASSERT_EQUAL(msg.get(), store.enqueued[1].second); - } - - void testPrepare2pc() - { - xid = "abcde"; - const string expected(xid); - testPrepare(); - CPPUNIT_ASSERT_EQUAL(expected, *store.enqueued[0].third); - CPPUNIT_ASSERT_EQUAL(expected, *store.enqueued[1].third); + CPPUNIT_ASSERT_EQUAL((PersistableMessage*) msg.get(), store.enqueued[1].second); } void testCommit() |