summaryrefslogtreecommitdiffstats
blob: 0296cdc0c47cd0970a85923e409afd5bef1747a3 (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
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>

#include "Swift/Controllers/RosterController.h"
#include "Swift/Controllers/UnitTest/MockMainWindowFactory.h"
#include "Swiften/Roster/UnitTest/MockTreeWidgetFactory.h"
// #include "Swiften/Elements/Payload.h"
// #include "Swiften/Elements/RosterItemPayload.h"
// #include "Swiften/Elements/RosterPayload.h"
#include "Swiften/Queries/DummyIQChannel.h"
#include "Swiften/Queries/IQRouter.h"
#include "Swiften/Roster/XMPPRoster.h"
#include "Swift/Controllers/NickResolver.h"

using namespace Swift;

class RosterControllerTest : public CppUnit::TestFixture
{
		CPPUNIT_TEST_SUITE(RosterControllerTest);
		CPPUNIT_TEST(testAdd);
		CPPUNIT_TEST_SUITE_END();

	public:
		RosterControllerTest() {};

		void setUp() {
			jid_ = JID("testjid@swift.im/swift");
			xmppRoster_ = boost::shared_ptr<XMPPRoster>(new XMPPRoster());
			avatarManager_ = NULL;//new AvatarManager();
			treeWidgetFactory_ = new MockTreeWidgetFactory();
			mainWindowFactory_ = new MockMainWindowFactory(treeWidgetFactory_);
			nickResolver_ = new NickResolver(xmppRoster_);
			rosterController_ = new RosterController(jid_, xmppRoster_, avatarManager_, mainWindowFactory_, treeWidgetFactory_, nickResolver_);

			channel_ = new DummyIQChannel();
			router_ = new IQRouter(channel_);

		};

		void tearDown() {
			delete rosterController_;
			delete nickResolver_;
			delete treeWidgetFactory_;
			delete mainWindowFactory_;
			delete avatarManager_;
			delete channel_;
			delete router_;
		};

		void testAdd() {
			std::vector<String> groups;
			groups.push_back("testGroup1");
			groups.push_back("testGroup2");
			xmppRoster_->addContact(JID("test@testdomain.com/bob"), "name", groups);
			
			CPPUNIT_ASSERT_EQUAL(2, (int)treeWidgetFactory_->getGroups().size());
			//CPPUNIT_ASSERT_EQUAL(String("Bob"), xmppRoster_->getNameForJID(JID("foo@bar.com")));
		};

	private:
		JID jid_;
		boost::shared_ptr<XMPPRoster> xmppRoster_;
		AvatarManager* avatarManager_;
		MainWindowFactory* mainWindowFactory_;
		MockTreeWidgetFactory* treeWidgetFactory_;
		NickResolver* nickResolver_;
		RosterController* rosterController_;
		DummyIQChannel* channel_;
		IQRouter* router_;

};