From 78f702aba1b1a0978c152536053233e6f9aedb91 Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Wed, 27 Oct 2010 21:17:02 +0100
Subject: Starting to test getHighestPriorityPresence


diff --git a/Swiften/Presence/UnitTest/PresenceOracleTest.cpp b/Swiften/Presence/UnitTest/PresenceOracleTest.cpp
index e96d8a4..645f917 100644
--- a/Swiften/Presence/UnitTest/PresenceOracleTest.cpp
+++ b/Swiften/Presence/UnitTest/PresenceOracleTest.cpp
@@ -20,6 +20,7 @@ class PresenceOracleTest : public CppUnit::TestFixture {
 		CPPUNIT_TEST(testReceivePresenceFromDifferentResources);
 		CPPUNIT_TEST(testSubscriptionRequest);
 		CPPUNIT_TEST(testReconnectResetsPresences);
+		CPPUNIT_TEST(testHighestPresence);
 		CPPUNIT_TEST_SUITE_END();
 
 	public:
@@ -38,6 +39,19 @@ class PresenceOracleTest : public CppUnit::TestFixture {
 			delete stanzaChannel_;
 		}
 
+		void testHighestPresence() {
+			JID bareJID("alice@wonderland.lit");
+			Presence::ref fiveOn = makeOnline("blah", 5);
+			Presence::ref fiveOff = makeOffline("/blah");
+			Presence::ref tenOn = makeOnline("bert", 10);
+			Presence::ref allOff = makeOffline("");
+			CPPUNIT_ASSERT_EQUAL(Presence::ref(), oracle_->getHighestPriorityPresence(bareJID));
+			stanzaChannel_->onPresenceReceived(fiveOn);
+			CPPUNIT_ASSERT_EQUAL(fiveOn, oracle_->getHighestPriorityPresence(bareJID));
+			stanzaChannel_->onPresenceReceived(fiveOff);
+			CPPUNIT_ASSERT_EQUAL(fiveOff, oracle_->getHighestPriorityPresence(bareJID));
+		}
+
 		void testReceivePresence() {
 			boost::shared_ptr<Presence> sentPresence(createPresence(user1));
 			stanzaChannel_->onPresenceReceived(sentPresence);
@@ -84,6 +98,20 @@ class PresenceOracleTest : public CppUnit::TestFixture {
 		}
 	
 	private:
+		Presence::ref makeOnline(const String& resource, int priority) {
+			Presence::ref presence(new Presence());
+			presence->setPriority(priority);
+			presence->setFrom(JID("alice@wonderland.lit/" + resource));
+			return presence;
+		}
+
+		Presence::ref makeOffline(const String& resource) {
+			Presence::ref presence(new Presence());
+			presence->setFrom(JID("alice@wonderland.lit" + resource));
+			presence->setType(Presence::Unavailable);
+			return presence;
+		}
+
 		void handlePresenceChange(boost::shared_ptr<Presence> newPresence) {
 			changes.push_back(newPresence);
 		}
-- 
cgit v0.10.2-6-g49f6