diff options
| author | Andrew Stitcher <astitcher@apache.org> | 2009-09-09 19:46:56 +0000 |
|---|---|---|
| committer | Andrew Stitcher <astitcher@apache.org> | 2009-09-09 19:46:56 +0000 |
| commit | fbddf29b719cd610b01b2459c4827d636cda6c73 (patch) | |
| tree | 4f1a87c509b151d428eca8c3c01c1bea0cd205a4 /cpp/src/tests/TxMocks.h | |
| parent | fd40457f6f471d10c3c804202d2329c93b2cb29e (diff) | |
| download | qpid-python-fbddf29b719cd610b01b2459c4827d636cda6c73.tar.gz | |
Tidied up namespace usage
Miscelleneous whitespace fixes
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@813094 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/tests/TxMocks.h')
| -rw-r--r-- | cpp/src/tests/TxMocks.h | 49 |
1 files changed, 27 insertions, 22 deletions
diff --git a/cpp/src/tests/TxMocks.h b/cpp/src/tests/TxMocks.h index fe103c5fe5..a34d864bae 100644 --- a/cpp/src/tests/TxMocks.h +++ b/cpp/src/tests/TxMocks.h @@ -7,9 +7,9 @@ * 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 @@ -32,6 +32,9 @@ using namespace qpid::broker; using boost::static_pointer_cast; using std::string; +namespace qpid { +namespace tests { + template <class T> void assertEqualVector(std::vector<T>& expected, std::vector<T>& actual){ unsigned int i = 0; while(i < expected.size() && i < actual.size()){ @@ -62,15 +65,15 @@ class MockTxOp : public TxOp, public TxOpConstants{ string debugName; public: typedef boost::shared_ptr<MockTxOp> shared_ptr; - + MockTxOp() : failOnPrepare(false) {} MockTxOp(bool _failOnPrepare) : failOnPrepare(_failOnPrepare) {} - + void setDebugName(string name){ debugName = name; } - void printExpected(){ + void printExpected(){ std::cout << std::endl << "MockTxOp[" << debugName << "] expects: "; for (std::vector<string>::iterator i = expected.begin(); i < expected.end(); i++) { if(i != expected.begin()) std::cout << ", "; @@ -79,7 +82,7 @@ public: std::cout << std::endl; } - void printActual(){ + void printActual(){ std::cout << std::endl << "MockTxOp[" << debugName << "] actual: "; for (std::vector<string>::iterator i = actual.begin(); i < actual.end(); i++) { if(i != actual.begin()) std::cout << ", "; @@ -87,7 +90,7 @@ public: } std::cout << std::endl; } - + bool prepare(TransactionContext*) throw(){ actual.push_back(PREPARE); return !failOnPrepare; @@ -116,8 +119,8 @@ public: } void accept(TxOpConstVisitor&) const {} - - ~MockTxOp(){} + + ~MockTxOp(){} }; class MockTransactionalStore : public TransactionalStore{ @@ -128,10 +131,10 @@ class MockTransactionalStore : public TransactionalStore{ const string ABORT; std::vector<string> expected; std::vector<string> actual; - + enum states {OPEN = 1, PREPARED = 2, COMMITTED = 3, ABORTED = 4}; int state; - + class TestTransactionContext : public TPCTransactionContext{ MockTransactionalStore* store; public: @@ -145,29 +148,29 @@ class MockTransactionalStore : public TransactionalStore{ if(!store->isOpen() && !store->isPrepared()) throw "txn already completed"; store->state = COMMITTED; } - + void abort(){ if(!store->isOpen() && !store->isPrepared()) throw "txn already completed"; store->state = ABORTED; } ~TestTransactionContext(){} }; - + public: MockTransactionalStore() : BEGIN("BEGIN"), BEGIN2PC("BEGIN2PC"), PREPARE("PREPARE"), COMMIT("COMMIT"), ABORT("ABORT"), state(OPEN){} void collectPreparedXids(std::set<std::string>&) { - throw "Operation not supported"; + throw "Operation not supported"; } - - std::auto_ptr<TPCTransactionContext> begin(const std::string&){ + + std::auto_ptr<TPCTransactionContext> begin(const std::string&){ actual.push_back(BEGIN2PC); std::auto_ptr<TPCTransactionContext> txn(new TestTransactionContext(this)); return txn; } - std::auto_ptr<TransactionContext> begin(){ + std::auto_ptr<TransactionContext> begin(){ actual.push_back(BEGIN); std::auto_ptr<TransactionContext> txn(new TestTransactionContext(this)); return txn; @@ -183,7 +186,7 @@ public: void abort(TransactionContext& ctxt){ actual.push_back(ABORT); dynamic_cast<TestTransactionContext&>(ctxt).abort(); - } + } MockTransactionalStore& expectBegin(){ expected.push_back(BEGIN); return *this; @@ -207,23 +210,25 @@ public: void check(){ assertEqualVector(expected, actual); } - + bool isPrepared(){ return state == PREPARED; } - + bool isCommitted(){ return state == COMMITTED; } - + bool isAborted(){ return state == ABORTED; } - + bool isOpen() const{ return state == OPEN; } ~MockTransactionalStore(){} }; +}} // namespace qpid::tests + #endif |
