1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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);
|