summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMateusz Piekos <mateuszpiekos@gmail.com>2012-07-09 16:42:07 (GMT)
committerMateusz Piekos <mateuszpiekos@gmail.com>2012-07-09 16:42:07 (GMT)
commit648327e0eb09e125b95314bc2f97dad03dafe6d8 (patch)
tree2bfa2fcceef4f2d9fa3716b4c042661185a009a7
parentb4470a58d2f2f50e40eedd0a72a5c36fdcb79ae1 (diff)
downloadswift-contrib-648327e0eb09e125b95314bc2f97dad03dafe6d8.zip
swift-contrib-648327e0eb09e125b95314bc2f97dad03dafe6d8.tar.bz2
Added one more situation to WhiteboardClient test
-rw-r--r--Swiften/Whiteboard/UnitTest/WhiteboardClientTest.cpp81
-rw-r--r--Swiften/Whiteboard/WhiteboardClient.cpp18
-rw-r--r--Swiften/Whiteboard/WhiteboardClient.h1
3 files changed, 95 insertions, 5 deletions
diff --git a/Swiften/Whiteboard/UnitTest/WhiteboardClientTest.cpp b/Swiften/Whiteboard/UnitTest/WhiteboardClientTest.cpp
index 32e6cc3..0707e11 100644
--- a/Swiften/Whiteboard/UnitTest/WhiteboardClientTest.cpp
+++ b/Swiften/Whiteboard/UnitTest/WhiteboardClientTest.cpp
@@ -17,11 +17,12 @@ using namespace Swift;
class WhiteboardClientTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(WhiteboardClientTest);
- CPPUNIT_TEST(testNoninterrupedSynchronization);
- CPPUNIT_TEST(testInterrupedSynchronization);
+ CPPUNIT_TEST(testSynchronize_nonInterrupted);
+ CPPUNIT_TEST(testSynchronize_clientInterruption);
+ CPPUNIT_TEST(testSynchronize_serverInterruption);
CPPUNIT_TEST_SUITE_END();
public:
- void testNoninterrupedSynchronization() {
+ void testSynchronize_nonInterrupted() {
WhiteboardClient client;
WhiteboardInsertOperation::ref serverOp;
serverOp = createInsertOperation("0", "");
@@ -91,7 +92,7 @@ public:
CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.second);
}
- void testInterrupedSynchronization() {
+ void testSynchronize_clientInterruption() {
WhiteboardClient client;
WhiteboardInsertOperation::ref serverOp;
serverOp = createInsertOperation("0", "");
@@ -179,6 +180,78 @@ public:
CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.second);
}
+ void testSynchronize_serverInterruption() {
+ WhiteboardClient client;
+ WhiteboardInsertOperation::ref serverOp;
+ serverOp = createInsertOperation("0", "");
+ serverOp->setPos(0);
+ std::pair<WhiteboardOperation::ref, WhiteboardOperation::ref> pairResult = client.handleServerOperationReceived(serverOp);
+ CPPUNIT_ASSERT_EQUAL(serverOp, boost::dynamic_pointer_cast<WhiteboardInsertOperation>(pairResult.first));
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.second);
+
+ WhiteboardInsertOperation::ref clientOp;
+ clientOp = createInsertOperation("a", "0");
+ clientOp->setPos(1);
+ clientOp->setOrigin(WhiteboardOperation::Local);
+ WhiteboardEllipseElement::ref aElement = boost::make_shared<WhiteboardEllipseElement>(0,0,0,0);
+ clientOp->setElement(aElement);
+ WhiteboardInsertOperation::ref result = boost::dynamic_pointer_cast<WhiteboardInsertOperation>(client.handleLocalOperationReceived(clientOp));
+ CPPUNIT_ASSERT_EQUAL(clientOp, boost::dynamic_pointer_cast<WhiteboardInsertOperation>(result));
+ CPPUNIT_ASSERT_EQUAL(aElement, boost::dynamic_pointer_cast<WhiteboardEllipseElement>(result->getElement()));
+
+
+ clientOp = createInsertOperation("b", "a");
+ clientOp->setPos(2);
+ clientOp->setOrigin(WhiteboardOperation::Local);
+ WhiteboardEllipseElement::ref bElement = boost::make_shared<WhiteboardEllipseElement>(0,0,0,0);
+ clientOp->setElement(bElement);
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), client.handleLocalOperationReceived(clientOp));
+
+ serverOp = createInsertOperation("c", "0");
+ serverOp->setPos(1);
+ serverOp->setOrigin(WhiteboardOperation::Other);
+ WhiteboardEllipseElement::ref cElement = boost::make_shared<WhiteboardEllipseElement>(0,0,0,0);
+ serverOp->setElement(cElement);
+ pairResult = client.handleServerOperationReceived(serverOp);
+ result = boost::dynamic_pointer_cast<WhiteboardInsertOperation>(pairResult.first);
+ CPPUNIT_ASSERT_EQUAL(3, result->getPos());
+ CPPUNIT_ASSERT_EQUAL(cElement, boost::dynamic_pointer_cast<WhiteboardEllipseElement>(result->getElement()));
+ CPPUNIT_ASSERT_EQUAL(std::string("b"), result->getParentID());
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.second);
+
+ serverOp = createInsertOperation("a", "c");
+ serverOp->setPos(1);
+ serverOp->setOrigin(WhiteboardOperation::Other);
+ serverOp->setElement(aElement);
+ pairResult = client.handleServerOperationReceived(serverOp);
+ result = boost::dynamic_pointer_cast<WhiteboardInsertOperation>(pairResult.second);
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.first);
+ CPPUNIT_ASSERT_EQUAL(std::string("b"), result->getID());
+ CPPUNIT_ASSERT_EQUAL(bElement, boost::dynamic_pointer_cast<WhiteboardEllipseElement>(result->getElement()));
+ CPPUNIT_ASSERT_EQUAL(std::string("a"), result->getParentID());
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::Other, result->getOrigin());
+
+ serverOp = createInsertOperation("d", "a");
+ serverOp->setPos(3);
+ serverOp->setOrigin(WhiteboardOperation::Other);
+ WhiteboardEllipseElement::ref dElement = boost::make_shared<WhiteboardEllipseElement>(0,0,0,0);
+ serverOp->setElement(dElement);
+ pairResult = client.handleServerOperationReceived(serverOp);
+ result = boost::dynamic_pointer_cast<WhiteboardInsertOperation>(pairResult.first);
+ CPPUNIT_ASSERT_EQUAL(4, result->getPos());
+ CPPUNIT_ASSERT_EQUAL(dElement, boost::dynamic_pointer_cast<WhiteboardEllipseElement>(result->getElement()));
+ CPPUNIT_ASSERT_EQUAL(std::string("c"), result->getParentID());
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.second);
+
+ serverOp = createInsertOperation("b", "d");
+ serverOp->setPos(2);
+ serverOp->setElement(bElement);
+ serverOp->setOrigin(WhiteboardOperation::Other);
+ pairResult = client.handleServerOperationReceived(serverOp);
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.first);
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.second);
+ }
+
WhiteboardInsertOperation::ref createInsertOperation(std::string id, std::string parent) {
WhiteboardInsertOperation::ref operation = boost::make_shared<WhiteboardInsertOperation>();
operation->setParentID(parent);
diff --git a/Swiften/Whiteboard/WhiteboardClient.cpp b/Swiften/Whiteboard/WhiteboardClient.cpp
index cc41e85..02ee48d 100644
--- a/Swiften/Whiteboard/WhiteboardClient.cpp
+++ b/Swiften/Whiteboard/WhiteboardClient.cpp
@@ -32,11 +32,14 @@ namespace Swift {
localOperations_.push_back(operation);
clientOp = operation;
} else if (lastSentOperationID_ == operation->getID()) {
+ if (lastSentOperationID_ == bridge_.front()->getID()) {
+ bridge_.erase(bridge_.begin());
+ }
std::list<WhiteboardOperation::ref>::iterator it;
for (it = bridge_.begin(); it != bridge_.end(); ++it) {
if ((*it)->getParentID() == lastSentOperationID_) {
lastSentOperationID_ = (*it)->getID();
- serverOperations_.push_back(*it);
+ //serverOperations_.push_back(*it);
serverOp = *it;
serverOp->setOrigin(WhiteboardOperation::Other);
break;
@@ -95,4 +98,17 @@ namespace Swift {
return std::pair<WhiteboardOperation::ref, WhiteboardOperation::ref>(clientOp, serverOp);
}
+
+ void WhiteboardClient::print() {
+ std::list<WhiteboardOperation::ref>::iterator it;
+ std::cout << "Client" << std::endl;
+ for(it = localOperations_.begin(); it != localOperations_.end(); ++it) {
+ std::cout << (*it)->getID() << " " << (*it)->getPos() << std::endl;
+ }
+
+ std::cout << "Server" << std::endl;
+ for(it = serverOperations_.begin(); it != serverOperations_.end(); ++it) {
+ std::cout << (*it)->getID() << " " << (*it)->getPos() << std::endl;
+ }
+ }
}
diff --git a/Swiften/Whiteboard/WhiteboardClient.h b/Swiften/Whiteboard/WhiteboardClient.h
index f781e6f..e720d37 100644
--- a/Swiften/Whiteboard/WhiteboardClient.h
+++ b/Swiften/Whiteboard/WhiteboardClient.h
@@ -21,6 +21,7 @@ namespace Swift {
* @return pair.first-element to handle locally, pair.second-element to send to server
*/
std::pair<WhiteboardOperation::ref, WhiteboardOperation::ref> handleServerOperationReceived(WhiteboardOperation::ref operation);
+ void print();
private:
std::list<WhiteboardOperation::ref> localOperations_;