diff options
Diffstat (limited to 'Swiften/Avatars')
-rw-r--r-- | Swiften/Avatars/CombinedAvatarProvider.cpp | 8 | ||||
-rw-r--r-- | Swiften/Avatars/UnitTest/CombinedAvatarProviderTest.cpp | 21 |
2 files changed, 21 insertions, 8 deletions
diff --git a/Swiften/Avatars/CombinedAvatarProvider.cpp b/Swiften/Avatars/CombinedAvatarProvider.cpp index d7e716c..eea0b89 100644 --- a/Swiften/Avatars/CombinedAvatarProvider.cpp +++ b/Swiften/Avatars/CombinedAvatarProvider.cpp @@ -14,13 +14,7 @@ namespace Swift { std::string CombinedAvatarProvider::getAvatarHash(const JID& jid) const { - std::map<JID, std::string>::const_iterator i = avatars.find(jid); - if (i == avatars.end()) { - return getCombinedAvatarAndCache(jid); - } - else { - return i->second; - } + return getCombinedAvatarAndCache(jid); } void CombinedAvatarProvider::addProvider(AvatarProvider* provider) { diff --git a/Swiften/Avatars/UnitTest/CombinedAvatarProviderTest.cpp b/Swiften/Avatars/UnitTest/CombinedAvatarProviderTest.cpp index 3e1cba3..4894e14 100644 --- a/Swiften/Avatars/UnitTest/CombinedAvatarProviderTest.cpp +++ b/Swiften/Avatars/UnitTest/CombinedAvatarProviderTest.cpp @@ -26,6 +26,7 @@ class CombinedAvatarProviderTest : public CppUnit::TestFixture { CPPUNIT_TEST(testProviderUpdateWithAvatarDisappearingTriggersChange); CPPUNIT_TEST(testProviderUpdateAfterAvatarDisappearedTriggersChange); CPPUNIT_TEST(testProviderUpdateAfterGetDoesNotTriggerChange); + CPPUNIT_TEST(testProviderUpdateBareJIDAfterGetFullJID); CPPUNIT_TEST(testRemoveProviderDisconnectsUpdates); CPPUNIT_TEST_SUITE_END(); @@ -168,6 +169,19 @@ class CombinedAvatarProviderTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(changes.size())); } + void testProviderUpdateBareJIDAfterGetFullJID() { + std::auto_ptr<CombinedAvatarProvider> testling(createProvider()); + avatarProvider1->useBare = true; + testling->addProvider(avatarProvider1); + + avatarProvider1->avatars[user1.toBare()] = avatarHash1; + testling->getAvatarHash(user1); + avatarProvider1->avatars[user1.toBare()] = avatarHash2; + avatarProvider1->onAvatarChanged(user1.toBare()); + + CPPUNIT_ASSERT_EQUAL(avatarHash2, testling->getAvatarHash(user1)); + } + private: std::auto_ptr<CombinedAvatarProvider> createProvider() { std::auto_ptr<CombinedAvatarProvider> result(new CombinedAvatarProvider()); @@ -181,8 +195,12 @@ class CombinedAvatarProviderTest : public CppUnit::TestFixture { private: struct DummyAvatarProvider : public AvatarProvider { + DummyAvatarProvider() : useBare(false) { + } + std::string getAvatarHash(const JID& jid) const { - std::map<JID, std::string>::const_iterator i = avatars.find(jid); + JID actualJID = useBare ? jid.toBare() : jid; + std::map<JID, std::string>::const_iterator i = avatars.find(actualJID); if (i != avatars.end()) { return i->second; } @@ -191,6 +209,7 @@ class CombinedAvatarProviderTest : public CppUnit::TestFixture { } } + bool useBare; std::map<JID, std::string> avatars; }; |