summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Controllers/UnitTest/NickResolverTest.cpp')
-rw-r--r--Swiften/Controllers/UnitTest/NickResolverTest.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/Swiften/Controllers/UnitTest/NickResolverTest.cpp b/Swiften/Controllers/UnitTest/NickResolverTest.cpp
new file mode 100644
index 0000000..9c89d4d
--- /dev/null
+++ b/Swiften/Controllers/UnitTest/NickResolverTest.cpp
@@ -0,0 +1,62 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include "Swiften/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);
+