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/NickResolver.h"
#include "Swiften/Roster/XMPPRoster.h"
using namespace Swift;
class NickResolverTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(NickResolverTest);
CPPUNIT_TEST(testNoMatch);
CPPUNIT_TEST(testZeroLengthMatch);
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 testJID("foo@bar/baz");
CPPUNIT_ASSERT_EQUAL(String("foo@bar"), resolver.jidToNick(testJID));
}
void testZeroLengthMatch() {
boost::shared_ptr<XMPPRoster> xmppRoster(new XMPPRoster());
NickResolver resolver(xmppRoster);
JID testJID("foo@bar/baz");
xmppRoster->addContact(testJID, "", groups_);
CPPUNIT_ASSERT_EQUAL(String("foo@bar"), resolver.jidToNick(testJID));
}
void testMatch() {
boost::shared_ptr<XMPPRoster> xmppRoster(new XMPPRoster());
NickResolver resolver(xmppRoster);
JID testJID("foo@bar/baz");
xmppRoster->addContact(testJID, "Test", groups_);
CPPUNIT_ASSERT_EQUAL(String("Test"), resolver.jidToNick(testJID));
}
void testOverwrittenMatch() {
boost::shared_ptr<XMPPRoster> xmppRoster(new XMPPRoster());
NickResolver resolver(xmppRoster);
JID testJID("foo@bar/baz");
xmppRoster->addContact(testJID, "FailTest", groups_);
xmppRoster->addContact(testJID, "Test", groups_);
CPPUNIT_ASSERT_EQUAL(String("Test"), resolver.jidToNick(testJID));
}
void testRemovedMatch() {
boost::shared_ptr<XMPPRoster> xmppRoster(new XMPPRoster());
NickResolver resolver(xmppRoster);
JID testJID("foo@bar/baz");
xmppRoster->addContact(testJID, "FailTest", groups_);
xmppRoster->removeContact(testJID);
CPPUNIT_ASSERT_EQUAL(String("foo@bar"), resolver.jidToNick(testJID));
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(NickResolverTest);
|