summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2015-10-27 16:20:09 (GMT)
committerTobias Markmann <tm@ayena.de>2015-10-30 12:34:52 (GMT)
commit0f5ef716a50c8d9761cafda12aacf818cdfd6353 (patch)
tree4ed80dedc2fa8b04036eb7567282094ea8fe07f1 /Swiften/Presence/UnitTest
parent4320235bef1b601856b295a8d6411d1898048802 (diff)
downloadswift-0f5ef716a50c8d9761cafda12aacf818cdfd6353.zip
swift-0f5ef716a50c8d9761cafda12aacf818cdfd6353.tar.bz2
Change bare JID presence lookup code to ignore priorities
Before presence handling code was handled by both, the ContactRosterItem in Swift and the PresenceOracle in Swiften. The ContactRosterItem also considered the presence priority for deciding what presence to show for a bare JID. With this code all full or bare JID presence requests are finally handled by the PresenceOracle. For bare JIDs it is looked up to a presence of one of the available resources of that JID regardless of the priorities. Test-Information: Adjusted tests according to above description and documentation in PresenceOracle. Change-Id: I972a4574f476cdf4d4b5593a035eb1c25ef2f8ba
Diffstat (limited to 'Swiften/Presence/UnitTest')
-rw-r--r--Swiften/Presence/UnitTest/PresenceOracleTest.cpp63
1 files changed, 54 insertions, 9 deletions
diff --git a/Swiften/Presence/UnitTest/PresenceOracleTest.cpp b/Swiften/Presence/UnitTest/PresenceOracleTest.cpp
index 85dcca9..6d16d80 100644
--- a/Swiften/Presence/UnitTest/PresenceOracleTest.cpp
+++ b/Swiften/Presence/UnitTest/PresenceOracleTest.cpp
@@ -28,6 +28,7 @@ class PresenceOracleTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testHighestPresenceMultiple);
CPPUNIT_TEST(testHighestPresenceGlobal);
CPPUNIT_TEST(testHighestPresenceChangePriority);
+ CPPUNIT_TEST(testGetActivePresence);
CPPUNIT_TEST_SUITE_END();
public:
@@ -52,15 +53,15 @@ class PresenceOracleTest : public CppUnit::TestFixture {
}
void testHighestPresenceSingle() {
- JID bareJID("alice@wonderland.lit");
- Presence::ref fiveOn = makeOnline("blah", 5);
- Presence::ref fiveOff = makeOffline("/blah");
- 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));
- }
+ JID bareJID("alice@wonderland.lit");
+ Presence::ref fiveOn = makeOnline("blah", 5);
+ Presence::ref fiveOff = makeOffline("/blah");
+ 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 testHighestPresenceMultiple() {
JID bareJID("alice@wonderland.lit");
@@ -151,8 +152,52 @@ class PresenceOracleTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT(!oracle_->getLastPresence(user1));
}
+
+ void testGetActivePresence() {
+ {
+ std::vector<Presence::ref> presenceList;
+ presenceList.push_back(createPresence("alice@wonderland.lit/resourceA", 10, Presence::Available, StatusShow::Away));
+ presenceList.push_back(createPresence("alice@wonderland.lit/resourceB", 5, Presence::Available, StatusShow::Online));
+
+ CPPUNIT_ASSERT_EQUAL(StatusShow::Online, PresenceOracle::getActivePresence(presenceList)->getShow());
+ }
+
+ {
+ std::vector<Presence::ref> presenceList;
+ presenceList.push_back(createPresence("alice@wonderland.lit/resourceA", 10, Presence::Available, StatusShow::Away));
+ presenceList.push_back(createPresence("alice@wonderland.lit/resourceB", 5, Presence::Available, StatusShow::DND));
+
+ CPPUNIT_ASSERT_EQUAL(StatusShow::DND, PresenceOracle::getActivePresence(presenceList)->getShow());
+ }
+
+ {
+ std::vector<Presence::ref> presenceList;
+ presenceList.push_back(createPresence("alice@wonderland.lit/resourceA", 0, Presence::Available, StatusShow::Online));
+ presenceList.push_back(createPresence("alice@wonderland.lit/resourceB", 0, Presence::Available, StatusShow::DND));
+
+ CPPUNIT_ASSERT_EQUAL(StatusShow::Online, PresenceOracle::getActivePresence(presenceList)->getShow());
+ }
+
+ {
+ std::vector<Presence::ref> presenceList;
+ presenceList.push_back(createPresence("alice@wonderland.lit/resourceA", 1, Presence::Available, StatusShow::Online));
+ presenceList.push_back(createPresence("alice@wonderland.lit/resourceB", 0, Presence::Available, StatusShow::Online));
+
+ CPPUNIT_ASSERT_EQUAL(JID("alice@wonderland.lit/resourceA"), PresenceOracle::getActivePresence(presenceList)->getFrom());
+ }
+ }
private:
+ Presence::ref createPresence(const JID &jid, int priority, Presence::Type type, const StatusShow::Type& statusShow) {
+ Presence::ref presence = boost::make_shared<Presence>();
+ presence->setFrom(jid);
+ presence->setPriority(priority);
+ presence->setType(type);
+ presence->setShow(statusShow);
+ return presence;
+ }
+
+
Presence::ref makeOnline(const std::string& resource, int priority) {
Presence::ref presence(new Presence());
presence->setPriority(priority);