diff options
author | Gordon Sim <gsim@apache.org> | 2007-04-05 11:48:05 +0000 |
---|---|---|
committer | Gordon Sim <gsim@apache.org> | 2007-04-05 11:48:05 +0000 |
commit | be0ad1041a449196a328260d2210c5f7c27fa0a1 (patch) | |
tree | 6a4a648a2fca1de6f0a8572e063fc701a9de68b7 /cpp/src/tests | |
parent | 4547988868ea17dd34064204de84e66206b16d5b (diff) | |
download | qpid-python-be0ad1041a449196a328260d2210c5f7c27fa0a1.tar.gz |
* Further (minor) changes to the interface between store and broker.
* TxBuffer now uses shared_ptr to TxOps (removed DeletingTxOp)
* Queue now persists the field table of settings
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@525801 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/tests')
-rw-r--r-- | cpp/src/tests/FieldTableTest.cpp | 33 | ||||
-rw-r--r-- | cpp/src/tests/TxBufferTest.cpp | 107 |
2 files changed, 88 insertions, 52 deletions
diff --git a/cpp/src/tests/FieldTableTest.cpp b/cpp/src/tests/FieldTableTest.cpp index f485ca187e..a7a03cc574 100644 --- a/cpp/src/tests/FieldTableTest.cpp +++ b/cpp/src/tests/FieldTableTest.cpp @@ -28,6 +28,7 @@ class FieldTableTest : public CppUnit::TestCase { CPPUNIT_TEST_SUITE(FieldTableTest); CPPUNIT_TEST(testMe); + CPPUNIT_TEST(testAssignment); CPPUNIT_TEST_SUITE_END(); public: @@ -46,6 +47,38 @@ class FieldTableTest : public CppUnit::TestCase CPPUNIT_ASSERT_EQUAL(std::string("BCDE"), ft2.getString("A")); } + + void testAssignment() + { + FieldTable a; + FieldTable b; + + a.setString("A", "BBBB"); + a.setInt("B", 1234); + b = a; + a.setString("A", "CCCC"); + + CPPUNIT_ASSERT_EQUAL(std::string("CCCC"), a.getString("A")); + CPPUNIT_ASSERT_EQUAL(std::string("BBBB"), b.getString("A")); + CPPUNIT_ASSERT_EQUAL(1234, a.getInt("B")); + CPPUNIT_ASSERT_EQUAL(1234, b.getInt("B")); + + FieldTable d; + { + FieldTable c; + c = a; + + Buffer buffer(c.size()); + buffer.putFieldTable(c); + buffer.flip(); + buffer.getFieldTable(d); + CPPUNIT_ASSERT_EQUAL(c, d); + CPPUNIT_ASSERT_EQUAL(std::string("CCCC"), c.getString("A")); + CPPUNIT_ASSERT_EQUAL(1234, c.getInt("B")); + } + CPPUNIT_ASSERT_EQUAL(std::string("CCCC"), d.getString("A")); + CPPUNIT_ASSERT_EQUAL(1234, d.getInt("B")); + } }; diff --git a/cpp/src/tests/TxBufferTest.cpp b/cpp/src/tests/TxBufferTest.cpp index 0d1fe7a04b..91ccc1e47d 100644 --- a/cpp/src/tests/TxBufferTest.cpp +++ b/cpp/src/tests/TxBufferTest.cpp @@ -24,6 +24,7 @@ #include <vector> using namespace qpid::broker; +using boost::static_pointer_cast; template <class T> void assertEqualVector(std::vector<T>& expected, std::vector<T>& actual){ unsigned int i = 0; @@ -43,6 +44,8 @@ class TxBufferTest : public CppUnit::TestCase std::vector<int> actual; bool failOnPrepare; public: + typedef boost::shared_ptr<MockTxOp> shared_ptr; + MockTxOp() : failOnPrepare(false) {} MockTxOp(bool _failOnPrepare) : failOnPrepare(_failOnPrepare) {} @@ -166,100 +169,100 @@ class TxBufferTest : public CppUnit::TestCase MockTransactionalStore store; store.expectBegin().expectCommit(); - MockTxOp opA; - opA.expectPrepare().expectCommit(); - MockTxOp opB; - opB.expectPrepare().expectPrepare().expectCommit().expectCommit();//opB enlisted twice to test reative order - MockTxOp opC; - opC.expectPrepare().expectCommit(); + MockTxOp::shared_ptr opA(new MockTxOp()); + opA->expectPrepare().expectCommit(); + MockTxOp::shared_ptr opB(new MockTxOp()); + opB->expectPrepare().expectPrepare().expectCommit().expectCommit();//opB enlisted twice to test reative order + MockTxOp::shared_ptr opC(new MockTxOp()); + opC->expectPrepare().expectCommit(); TxBuffer buffer; - buffer.enlist(&opA); - buffer.enlist(&opB); - buffer.enlist(&opB);//opB enlisted twice - buffer.enlist(&opC); + buffer.enlist(static_pointer_cast<TxOp>(opA)); + buffer.enlist(static_pointer_cast<TxOp>(opB)); + buffer.enlist(static_pointer_cast<TxOp>(opB));//opB enlisted twice + buffer.enlist(static_pointer_cast<TxOp>(opC)); CPPUNIT_ASSERT(buffer.prepare(&store)); buffer.commit(); store.check(); CPPUNIT_ASSERT(store.isCommitted()); - opA.check(); - opB.check(); - opC.check(); + opA->check(); + opB->check(); + opC->check(); } void testFailOnPrepare(){ MockTransactionalStore store; store.expectBegin().expectAbort(); - MockTxOp opA; - opA.expectPrepare(); - MockTxOp opB(true); - opB.expectPrepare(); - MockTxOp opC;//will never get prepare as b will fail + MockTxOp::shared_ptr opA(new MockTxOp()); + opA->expectPrepare(); + MockTxOp::shared_ptr opB(new MockTxOp(true)); + opB->expectPrepare(); + MockTxOp::shared_ptr opC(new MockTxOp());//will never get prepare as b will fail TxBuffer buffer; - buffer.enlist(&opA); - buffer.enlist(&opB); - buffer.enlist(&opC); + buffer.enlist(static_pointer_cast<TxOp>(opA)); + buffer.enlist(static_pointer_cast<TxOp>(opB)); + buffer.enlist(static_pointer_cast<TxOp>(opC)); CPPUNIT_ASSERT(!buffer.prepare(&store)); store.check(); CPPUNIT_ASSERT(store.isAborted()); - opA.check(); - opB.check(); - opC.check(); + opA->check(); + opB->check(); + opC->check(); } void testRollback(){ - MockTxOp opA; - opA.expectRollback(); - MockTxOp opB(true); - opB.expectRollback(); - MockTxOp opC; - opC.expectRollback(); + MockTxOp::shared_ptr opA(new MockTxOp()); + opA->expectRollback(); + MockTxOp::shared_ptr opB(new MockTxOp(true)); + opB->expectRollback(); + MockTxOp::shared_ptr opC(new MockTxOp()); + opC->expectRollback(); TxBuffer buffer; - buffer.enlist(&opA); - buffer.enlist(&opB); - buffer.enlist(&opC); + buffer.enlist(static_pointer_cast<TxOp>(opA)); + buffer.enlist(static_pointer_cast<TxOp>(opB)); + buffer.enlist(static_pointer_cast<TxOp>(opC)); buffer.rollback(); - opA.check(); - opB.check(); - opC.check(); + opA->check(); + opB->check(); + opC->check(); } void testBufferIsClearedAfterRollback(){ - MockTxOp opA; - opA.expectRollback(); - MockTxOp opB; - opB.expectRollback(); + MockTxOp::shared_ptr opA(new MockTxOp()); + opA->expectRollback(); + MockTxOp::shared_ptr opB(new MockTxOp()); + opB->expectRollback(); TxBuffer buffer; - buffer.enlist(&opA); - buffer.enlist(&opB); + buffer.enlist(static_pointer_cast<TxOp>(opA)); + buffer.enlist(static_pointer_cast<TxOp>(opB)); buffer.rollback(); buffer.commit();//second call should not reach ops - opA.check(); - opB.check(); + opA->check(); + opB->check(); } void testBufferIsClearedAfterCommit(){ - MockTxOp opA; - opA.expectCommit(); - MockTxOp opB; - opB.expectCommit(); + MockTxOp::shared_ptr opA(new MockTxOp()); + opA->expectCommit(); + MockTxOp::shared_ptr opB(new MockTxOp()); + opB->expectCommit(); TxBuffer buffer; - buffer.enlist(&opA); - buffer.enlist(&opB); + buffer.enlist(static_pointer_cast<TxOp>(opA)); + buffer.enlist(static_pointer_cast<TxOp>(opB)); buffer.commit(); buffer.rollback();//second call should not reach ops - opA.check(); - opB.check(); + opA->check(); + opB->check(); } }; |