diff options
author | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-07-07 16:49:10 (GMT) |
---|---|---|
committer | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-07-07 16:49:10 (GMT) |
commit | 2bad2edf797c9fefb1facd2a63c69cce34a0e635 (patch) | |
tree | c71218951d0017d67284531a114a55c3c89d2b90 /Swiften/Whiteboard/UnitTest | |
parent | 0071e9ed46775ee4e49ed969099ce08c49c9a07b (diff) | |
download | swift-contrib-2bad2edf797c9fefb1facd2a63c69cce34a0e635.zip swift-contrib-2bad2edf797c9fefb1facd2a63c69cce34a0e635.tar.bz2 |
Added WhiteboardClient with passing simple unit test
Diffstat (limited to 'Swiften/Whiteboard/UnitTest')
-rw-r--r-- | Swiften/Whiteboard/UnitTest/WhiteboardClientTest.cpp | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/Swiften/Whiteboard/UnitTest/WhiteboardClientTest.cpp b/Swiften/Whiteboard/UnitTest/WhiteboardClientTest.cpp new file mode 100644 index 0000000..f6f8249 --- /dev/null +++ b/Swiften/Whiteboard/UnitTest/WhiteboardClientTest.cpp @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2012 Mateusz Piękos + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include <boost/smart_ptr/make_shared.hpp> +#include <Swiften/Whiteboard/WhiteboardClient.h> +#include <Swiften/Whiteboard/Operations/WhiteboardInsertOperation.h> +#include <Swiften/Whiteboard/Elements/WhiteboardEllipseElement.h> + +using namespace Swift; + +class WhiteboardClientTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(WhiteboardClientTest); + CPPUNIT_TEST(testNoninterrupedSynchronization); + CPPUNIT_TEST_SUITE_END(); +public: + void testNoninterrupedSynchronization() { + 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("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(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("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); + 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); + operation->setID(id); + return operation; + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(WhiteboardClientTest); |