From 8c53236875d2ca77f1b463449918458f6b424ab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Tue, 4 May 2010 20:20:52 +0200 Subject: Don't take an avatar from a presence type='error'. Resolves: #336 diff --git a/Swiften/Avatars/AvatarManager.cpp b/Swiften/Avatars/AvatarManager.cpp index a5b6b36..3861520 100644 --- a/Swiften/Avatars/AvatarManager.cpp +++ b/Swiften/Avatars/AvatarManager.cpp @@ -42,6 +42,9 @@ void AvatarManager::handlePresenceReceived(boost::shared_ptr presence) if (!update) { return; } + if (presence->getPayload()) { + return; + } JID from = getAvatarJID(presence->getFrom()); String& hash = avatarHashes_[from]; if (hash != update->getPhotoHash()) { diff --git a/Swiften/Avatars/UnitTest/AvatarManagerTest.cpp b/Swiften/Avatars/UnitTest/AvatarManagerTest.cpp index 046f33e..511bd12 100644 --- a/Swiften/Avatars/UnitTest/AvatarManagerTest.cpp +++ b/Swiften/Avatars/UnitTest/AvatarManagerTest.cpp @@ -19,18 +19,19 @@ using namespace Swift; class AvatarManagerTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(AvatarManagerTest); CPPUNIT_TEST(testUpdate_UpdateNewHash); + /*& CPPUNIT_TEST(testUpdate_UpdateNewHashAlreadyHaveAvatar); CPPUNIT_TEST(testUpdate_UpdateNewHashFromMUC); - CPPUNIT_TEST(testUpdate_UpdateSameHash); + CPPUNIT_TEST(testUpdate_UpdateSameHash);*/ + CPPUNIT_TEST(testUpdate_UpdateWithError); + /* CPPUNIT_TEST(testUpdate_UpdateNewHashSameThanOtherUser); CPPUNIT_TEST(testReceiveVCard); CPPUNIT_TEST(testGetAvatarPath); - CPPUNIT_TEST(testGetAvatarPathFromMUC); + CPPUNIT_TEST(testGetAvatarPathFromMUC);*/ CPPUNIT_TEST_SUITE_END(); public: - AvatarManagerTest() {} - void setUp() { stanzaChannel_ = new DummyStanzaChannel(); iqRouter_ = new IQRouter(stanzaChannel_); @@ -49,11 +50,12 @@ class AvatarManagerTest : public CppUnit::TestFixture { std::auto_ptr testling = createManager(); stanzaChannel_->onPresenceReceived(createPresenceWithPhotoHash()); - CPPUNIT_ASSERT_EQUAL(1, static_cast(stanzaChannel_->sentStanzas_.size())); - IQ* - CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex(0, JID("foo@bar.com"), IQ::Get)); + CPPUNIT_ASSERT_EQUAL(1, static_cast(stanzaChannel_->sentStanzas.size())); + // TODO + //CPPUNIT_ASSERT(stanzaChannel_->isRequestAtIndex(0, JID("foo@bar.com"), IQ::Get)); } +/* void testUpdate_UpdateNewHashAlreadyHaveAvatar() { std::auto_ptr testling = createManager(); } @@ -81,6 +83,17 @@ class AvatarManagerTest : public CppUnit::TestFixture { void testGetAvatarPathFromMUC() { std::auto_ptr testling = createManager(); } + */ + + void testUpdate_UpdateWithError() { + std::auto_ptr testling = createManager(); + boost::shared_ptr update = createPresenceWithPhotoHash(); + update->addPayload(boost::shared_ptr(new ErrorPayload())); + stanzaChannel_->onPresenceReceived(update); + + CPPUNIT_ASSERT_EQUAL(0, static_cast(stanzaChannel_->sentStanzas.size())); + } + private: std::auto_ptr createManager() { diff --git a/Swiften/SConscript b/Swiften/SConscript index a3426db..dfda3ba 100644 --- a/Swiften/SConscript +++ b/Swiften/SConscript @@ -132,6 +132,7 @@ if env["SCONS_STAGE"] == "build" : env.Append(UNITTEST_SOURCES = [ File("Application/UnitTest/ApplicationTest.cpp"), File("Avatars/UnitTest/MockAvatarManager.cpp"), + File("Avatars/UnitTest/AvatarManagerTest.cpp"), File("Base/UnitTest/IDGeneratorTest.cpp"), File("Base/UnitTest/StringTest.cpp"), File("Base/UnitTest/ByteArrayTest.cpp"), -- cgit v0.10.2-6-g49f6