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

#include "Swift/Controllers/NickResolver.h"
#include "Swiften/Roster/XMPPRoster.h"

using namespace Swift;

class NickResolverTest : public CppUnit::TestFixture
{
		CPPUNIT_TEST_SUITE(NickResolverTest);
		CPPUNIT_TEST(testNoMatch);
		CPPUNIT_TEST(testMatch);
		CPPUNIT_TEST(testOverwrittenMatch);
		CPPUNIT_TEST(testRemovedMatch);
		CPPUNIT_TEST_SUITE_END();

		std::vector<String> groups_;

	public:
		NickResolverTest() {}

		void testNoMatch() {
			boost::shared_ptr<XMPPRoster> xmppRoster(new XMPPRoster());
			NickResolver resolver(xmppRoster);
			JID testling("foo@bar/baz");

			CPPUNIT_ASSERT_EQUAL(String("foo@bar"), resolver.jidToNick(testling));
		}

		void testMatch() {
			boost::shared_ptr<XMPPRoster> xmppRoster(new XMPPRoster());
			NickResolver resolver(xmppRoster);
			JID testling("foo@bar/baz");
			xmppRoster->addContact(testling, "Test", groups_);

			CPPUNIT_ASSERT_EQUAL(String("Test"), resolver.jidToNick(testling));
		}

		void testOverwrittenMatch() {
			boost::shared_ptr<XMPPRoster> xmppRoster(new XMPPRoster());
			NickResolver resolver(xmppRoster);
			JID testling("foo@bar/baz");
			xmppRoster->addContact(testling, "FailTest", groups_);
			xmppRoster->addContact(testling, "Test", groups_);

			CPPUNIT_ASSERT_EQUAL(String("Test"), resolver.jidToNick(testling));
		}

		void testRemovedMatch() {
			boost::shared_ptr<XMPPRoster> xmppRoster(new XMPPRoster());
			NickResolver resolver(xmppRoster);
			JID testling("foo@bar/baz");
			xmppRoster->addContact(testling, "FailTest", groups_);
			xmppRoster->removeContact(testling);
			CPPUNIT_ASSERT_EQUAL(String("foo@bar"), resolver.jidToNick(testling));
		}

};

CPPUNIT_TEST_SUITE_REGISTRATION(NickResolverTest);