summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMateusz Piekos <mateuszpiekos@gmail.com>2012-07-09 10:15:06 (GMT)
committerMateusz Piekos <mateuszpiekos@gmail.com>2012-07-09 10:15:06 (GMT)
commitb4470a58d2f2f50e40eedd0a72a5c36fdcb79ae1 (patch)
treedfa3a70cd0932f00828e656ea08f5230d823f490 /Swiften
parent2bad2edf797c9fefb1facd2a63c69cce34a0e635 (diff)
downloadswift-contrib-b4470a58d2f2f50e40eedd0a72a5c36fdcb79ae1.zip
swift-contrib-b4470a58d2f2f50e40eedd0a72a5c36fdcb79ae1.tar.bz2
Added more complicated WhiteboardClient test and updated this class to pass it
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Whiteboard/UnitTest/WhiteboardClientTest.cpp89
-rw-r--r--Swiften/Whiteboard/WhiteboardClient.cpp7
2 files changed, 96 insertions, 0 deletions
diff --git a/Swiften/Whiteboard/UnitTest/WhiteboardClientTest.cpp b/Swiften/Whiteboard/UnitTest/WhiteboardClientTest.cpp
index f6f8249..32e6cc3 100644
--- a/Swiften/Whiteboard/UnitTest/WhiteboardClientTest.cpp
+++ b/Swiften/Whiteboard/UnitTest/WhiteboardClientTest.cpp
@@ -18,6 +18,7 @@ using namespace Swift;
class WhiteboardClientTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(WhiteboardClientTest);
CPPUNIT_TEST(testNoninterrupedSynchronization);
+ CPPUNIT_TEST(testInterrupedSynchronization);
CPPUNIT_TEST_SUITE_END();
public:
void testNoninterrupedSynchronization() {
@@ -90,6 +91,94 @@ public:
CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.second);
}
+ void testInterrupedSynchronization() {
+ 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);
+
+ clientOp = createInsertOperation("e", "a");
+ clientOp->setPos(4);
+ clientOp->setOrigin(WhiteboardOperation::Local);
+ WhiteboardEllipseElement::ref eElement = boost::make_shared<WhiteboardEllipseElement>(0,0,0,0);
+ clientOp->setElement(eElement);
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), client.handleLocalOperationReceived(clientOp));
+
+ serverOp = createInsertOperation("d", "c");
+ serverOp->setPos(2);
+ 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(5, result->getPos());
+ CPPUNIT_ASSERT_EQUAL(dElement, boost::dynamic_pointer_cast<WhiteboardEllipseElement>(result->getElement()));
+ CPPUNIT_ASSERT_EQUAL(std::string("e"), result->getParentID());
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.second);
+
+ serverOp = createInsertOperation("a", "d");
+ serverOp->setPos(1);
+ serverOp->setOrigin(WhiteboardOperation::Other);
+ 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("b", "a");
+ serverOp->setPos(2);
+ serverOp->setOrigin(WhiteboardOperation::Other);
+ pairResult = client.handleServerOperationReceived(serverOp);
+ result = boost::dynamic_pointer_cast<WhiteboardInsertOperation>(pairResult.second);
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.first);
+ CPPUNIT_ASSERT_EQUAL(std::string("e"), result->getID());
+ CPPUNIT_ASSERT_EQUAL(eElement, boost::dynamic_pointer_cast<WhiteboardEllipseElement>(result->getElement()));
+ CPPUNIT_ASSERT_EQUAL(std::string("b"), result->getParentID());
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::Other, result->getOrigin());
+
+ serverOp = createInsertOperation("e", "b");
+ serverOp->setPos(4);
+ 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 6b352f5..cc41e85 100644
--- a/Swiften/Whiteboard/WhiteboardClient.cpp
+++ b/Swiften/Whiteboard/WhiteboardClient.cpp
@@ -6,10 +6,16 @@
#include <Swiften/Whiteboard/WhiteboardClient.h>
#include <Swiften/Whiteboard/WhiteboardTransformer.h>
+#include <boost/smart_ptr/make_shared.hpp>
namespace Swift {
WhiteboardOperation::ref WhiteboardClient::handleLocalOperationReceived(WhiteboardOperation::ref operation) {
localOperations_.push_back(operation);
+ if (bridge_.size() > 0) {
+ WhiteboardOperation::ref op = boost::make_shared<WhiteboardInsertOperation>(*boost::dynamic_pointer_cast<WhiteboardInsertOperation>(operation).get());
+ op->setParentID(bridge_.back()->getID());
+ bridge_.push_back(op);
+ }
if (lastSentOperationID_.empty())
{
lastSentOperationID_ = operation->getID();
@@ -54,6 +60,7 @@ namespace Swift {
(*it)->setParentID(previousID);
previousID = (*it)->getID();
}
+
temp->setParentID(localOperations_.back()->getID());
localOperations_.push_back(temp);
clientOp = temp;