From 37aafcb4d693a0b4f5944a52e0c070e5aa384245 Mon Sep 17 00:00:00 2001 From: Tobias Markmann Date: Fri, 25 Sep 2015 16:06:35 +0200 Subject: Do not flush vCard cache if IQ request returns an error Test-Information: Adjusted the corresponding test case accordingly. Change-Id: I4626f09cd51bac2ff9ca97d5a7da5a173fc627a5 diff --git a/Swiften/VCards/UnitTest/VCardManagerTest.cpp b/Swiften/VCards/UnitTest/VCardManagerTest.cpp index 32c91cf..278449b 100644 --- a/Swiften/VCards/UnitTest/VCardManagerTest.cpp +++ b/Swiften/VCards/UnitTest/VCardManagerTest.cpp @@ -1,23 +1,24 @@ /* - * Copyright (c) 2010-2013 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#include - -#include -#include #include + #include #include -#include -#include -#include +#include +#include + +#include #include #include #include +#include +#include +#include using namespace Swift; @@ -37,6 +38,8 @@ class VCardManagerTest : public CppUnit::TestFixture { public: void setUp() { + changes.clear(); + ownChanges.clear(); ownJID = JID("baz@fum.com/dum"); crypto = boost::shared_ptr(PlatformCryptoProvider::create()); stanzaChannel = new DummyStanzaChannel(); @@ -97,10 +100,8 @@ class VCardManagerTest : public CppUnit::TestFixture { testling->requestVCard(JID("foo@bar.com/baz")); stanzaChannel->onIQReceived(IQ::createError(JID("baz@fum.com/foo"), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID())); - CPPUNIT_ASSERT_EQUAL(1, static_cast(changes.size())); - CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com/baz"), changes[0].first); - CPPUNIT_ASSERT_EQUAL(std::string(""), changes[0].second->getFullName()); - CPPUNIT_ASSERT_EQUAL(std::string(""), vcardStorage->getVCard(JID("foo@bar.com/baz"))->getFullName()); + // On error, cached vCards should not be changed. + CPPUNIT_ASSERT_EQUAL(0, static_cast(changes.size())); } void testRequest_VCardAlreadyRequested() { diff --git a/Swiften/VCards/VCardManager.cpp b/Swiften/VCards/VCardManager.cpp index 5e552d6..5fa44ae 100644 --- a/Swiften/VCards/VCardManager.cpp +++ b/Swiften/VCards/VCardManager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2014 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -10,9 +10,8 @@ #include #include -#include #include - +#include namespace Swift { @@ -53,12 +52,14 @@ void VCardManager::requestOwnVCard() { void VCardManager::handleVCardReceived(const JID& actualJID, VCard::ref vcard, ErrorPayload::ref error) { - if (error || !vcard) { - vcard = VCard::ref(new VCard()); - } requestedVCards.erase(actualJID); - JID jid = actualJID.isValid() ? actualJID : ownJID.toBare(); - setVCard(jid, vcard); + if (!error) { + if (!vcard) { + vcard = VCard::ref(new VCard()); + } + JID jid = actualJID.isValid() ? actualJID : ownJID.toBare(); + setVCard(jid, vcard); + } } SetVCardRequest::ref VCardManager::createSetVCardRequest(VCard::ref vcard) { -- cgit v0.10.2-6-g49f6