summaryrefslogtreecommitdiffstats
blob: c61f9d12de4ad48815ac654198b78719ab95fb1a (plain)
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
/*
 * 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/WhiteboardServer.h>
#include <Swiften/Whiteboard/Operations/WhiteboardInsertOperation.h>
#include <Swiften/Whiteboard/Elements/WhiteboardEllipseElement.h>

using namespace Swift;

class WhiteboardServerTest : public CppUnit::TestFixture {
	CPPUNIT_TEST_SUITE(WhiteboardServerTest);
	CPPUNIT_TEST(testSimpleOp);
	CPPUNIT_TEST(testFewSimpleOps);
	CPPUNIT_TEST_SUITE_END();
public:
	void testSimpleOp() {
		WhiteboardServer server;
		WhiteboardInsertOperation::ref firstOp = boost::make_shared<WhiteboardInsertOperation>();
		firstOp->setID("0");
		server.handleLocalOperationReceived(firstOp);
		WhiteboardInsertOperation::ref serverOp = boost::make_shared<WhiteboardInsertOperation>();
		serverOp->setID("b");
		serverOp->setParentID("0");
		serverOp->setPos(1);
		server.handleLocalOperationReceived(serverOp);
		WhiteboardInsertOperation::ref clientOp = boost::make_shared<WhiteboardInsertOperation>();
		WhiteboardEllipseElement::ref clientElement = boost::make_shared<WhiteboardEllipseElement>(0,0,0,0);
		clientOp->setID("a");
		clientOp->setParentID("0");
		clientOp->setPos(1);
		clientOp->setElement(clientElement);
		WhiteboardInsertOperation::ref op = boost::dynamic_pointer_cast<WhiteboardInsertOperation>(server.handleClientOperationReceived(clientOp));
		CPPUNIT_ASSERT_EQUAL(std::string("b"), op->getParentID());
		CPPUNIT_ASSERT_EQUAL(std::string("a"), op->getID());
		CPPUNIT_ASSERT_EQUAL(1, op->getPos());
		CPPUNIT_ASSERT_EQUAL(clientElement, boost::dynamic_pointer_cast<WhiteboardEllipseElement>(op->getElement()));
	}

	void testFewSimpleOps() {
		WhiteboardServer server;
		WhiteboardInsertOperation::ref firstOp = boost::make_shared<WhiteboardInsertOperation>();
		firstOp->setID("0");
		server.handleLocalOperationReceived(firstOp);
		WhiteboardInsertOperation::ref serverOp = boost::make_shared<WhiteboardInsertOperation>();
		serverOp->setID("a");
		serverOp->setParentID("0");
		serverOp->setPos(1);
		server.handleLocalOperationReceived(serverOp);
		serverOp = boost::make_shared<WhiteboardInsertOperation>();
		serverOp->setID("b");
		serverOp->setParentID("a");
		serverOp->setPos(2);
		server.handleLocalOperationReceived(serverOp);
		serverOp = boost::make_shared<WhiteboardInsertOperation>();
		serverOp->setID("c");
		serverOp->setParentID("b");
		serverOp->setPos(3);
		server.handleLocalOperationReceived(serverOp);
		WhiteboardInsertOperation::ref clientOp = boost::make_shared<WhiteboardInsertOperation>();
		WhiteboardEllipseElement::ref clientElement = boost::make_shared<WhiteboardEllipseElement>(0,0,0,0);
		clientOp->setID("d");
		clientOp->setParentID("0");
		clientOp->setPos(1);
		clientOp->setElement(clientElement);
		WhiteboardInsertOperation::ref op = boost::dynamic_pointer_cast<WhiteboardInsertOperation>(server.handleClientOperationReceived(clientOp));
		CPPUNIT_ASSERT_EQUAL(std::string("c"), op->getParentID());
		CPPUNIT_ASSERT_EQUAL(std::string("d"), op->getID());
		CPPUNIT_ASSERT_EQUAL(1, op->getPos());
		CPPUNIT_ASSERT_EQUAL(clientElement, boost::dynamic_pointer_cast<WhiteboardEllipseElement>(op->getElement()));
	}
};

CPPUNIT_TEST_SUITE_REGISTRATION(WhiteboardServerTest);