diff options
author | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-07-09 16:42:07 (GMT) |
---|---|---|
committer | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-07-09 16:42:07 (GMT) |
commit | 648327e0eb09e125b95314bc2f97dad03dafe6d8 (patch) | |
tree | 2bfa2fcceef4f2d9fa3716b4c042661185a009a7 /Swiften/Whiteboard/UnitTest | |
parent | b4470a58d2f2f50e40eedd0a72a5c36fdcb79ae1 (diff) | |
download | swift-contrib-648327e0eb09e125b95314bc2f97dad03dafe6d8.zip swift-contrib-648327e0eb09e125b95314bc2f97dad03dafe6d8.tar.bz2 |
Added one more situation to WhiteboardClient test
Diffstat (limited to 'Swiften/Whiteboard/UnitTest')
-rw-r--r-- | Swiften/Whiteboard/UnitTest/WhiteboardClientTest.cpp | 81 |
1 files changed, 77 insertions, 4 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); |