diff options
| author | Tobias Markmann <tm@ayena.de> | 2015-09-25 14:06:35 (GMT) | 
|---|---|---|
| committer | Tobias Markmann <tm@ayena.de> | 2015-09-25 14:06:35 (GMT) | 
| commit | 37aafcb4d693a0b4f5944a52e0c070e5aa384245 (patch) | |
| tree | f6fe68c584de96992c2d2fde1f3cc7c3d702e084 | |
| parent | 2609a8a63662dfea9dccce2fd135b11a8d6c7875 (diff) | |
| download | swift-37aafcb4d693a0b4f5944a52e0c070e5aa384245.zip swift-37aafcb4d693a0b4f5944a52e0c070e5aa384245.tar.bz2 | |
Do not flush vCard cache if IQ request returns an error
Test-Information:
Adjusted the corresponding test case accordingly.
Change-Id: I4626f09cd51bac2ff9ca97d5a7da5a173fc627a5
| -rw-r--r-- | Swiften/VCards/UnitTest/VCardManagerTest.cpp | 25 | ||||
| -rw-r--r-- | Swiften/VCards/VCardManager.cpp | 17 | 
2 files changed, 22 insertions, 20 deletions
| 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,25 +1,26 @@ | |||
| 1 | /* | 1 | /* | 
| 2 | * Copyright (c) 2010-2013 Isode Limited. | 2 | * Copyright (c) 2010-2015 Isode Limited. | 
| 3 | * All rights reserved. | 3 | * All rights reserved. | 
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. | 
| 5 | */ | 5 | */ | 
| 6 | 6 | ||
| 7 | #include <Swiften/Base/ByteArray.h> | ||
| 8 | |||
| 9 | #include <cppunit/extensions/HelperMacros.h> | ||
| 10 | #include <cppunit/extensions/TestFactoryRegistry.h> | ||
| 11 | #include <vector> | 7 | #include <vector> | 
| 8 | |||
| 12 | #include <boost/bind.hpp> | 9 | #include <boost/bind.hpp> | 
| 13 | #include <boost/smart_ptr/make_shared.hpp> | 10 | #include <boost/smart_ptr/make_shared.hpp> | 
| 14 | 11 | ||
| 15 | #include <Swiften/VCards/VCardManager.h> | 12 | #include <cppunit/extensions/HelperMacros.h> | 
| 16 | #include <Swiften/VCards/VCardMemoryStorage.h> | 13 | #include <cppunit/extensions/TestFactoryRegistry.h> | 
| 17 | #include <Swiften/Queries/IQRouter.h> | 14 | |
| 15 | #include <Swiften/Base/ByteArray.h> | ||
| 18 | #include <Swiften/Client/DummyStanzaChannel.h> | 16 | #include <Swiften/Client/DummyStanzaChannel.h> | 
| 19 | #include <Swiften/Crypto/CryptoProvider.h> | 17 | #include <Swiften/Crypto/CryptoProvider.h> | 
| 20 | #include <Swiften/Crypto/PlatformCryptoProvider.h> | 18 | #include <Swiften/Crypto/PlatformCryptoProvider.h> | 
| 19 | #include <Swiften/Queries/IQRouter.h> | ||
| 20 | #include <Swiften/VCards/VCardManager.h> | ||
| 21 | #include <Swiften/VCards/VCardMemoryStorage.h> | ||
| 21 | 22 | ||
| 22 | using namespace Swift; | 23 | using namespace Swift; | 
| 23 | 24 | ||
| 24 | class VCardManagerTest : public CppUnit::TestFixture { | 25 | class VCardManagerTest : public CppUnit::TestFixture { | 
| 25 | CPPUNIT_TEST_SUITE(VCardManagerTest); | 26 | CPPUNIT_TEST_SUITE(VCardManagerTest); | 
| @@ -35,10 +36,12 @@ class VCardManagerTest : public CppUnit::TestFixture { | |||
| 35 | CPPUNIT_TEST(testCreateSetVCardRequest_Error); | 36 | CPPUNIT_TEST(testCreateSetVCardRequest_Error); | 
| 36 | CPPUNIT_TEST_SUITE_END(); | 37 | CPPUNIT_TEST_SUITE_END(); | 
| 37 | 38 | ||
| 38 | public: | 39 | public: | 
| 39 | void setUp() { | 40 | void setUp() { | 
| 41 | changes.clear(); | ||
| 42 | ownChanges.clear(); | ||
| 40 | ownJID = JID("baz@fum.com/dum"); | 43 | ownJID = JID("baz@fum.com/dum"); | 
| 41 | crypto = boost::shared_ptr<CryptoProvider>(PlatformCryptoProvider::create()); | 44 | crypto = boost::shared_ptr<CryptoProvider>(PlatformCryptoProvider::create()); | 
| 42 | stanzaChannel = new DummyStanzaChannel(); | 45 | stanzaChannel = new DummyStanzaChannel(); | 
| 43 | iqRouter = new IQRouter(stanzaChannel); | 46 | iqRouter = new IQRouter(stanzaChannel); | 
| 44 | vcardStorage = new VCardMemoryStorage(crypto.get()); | 47 | vcardStorage = new VCardMemoryStorage(crypto.get()); | 
| @@ -95,14 +98,12 @@ class VCardManagerTest : public CppUnit::TestFixture { | |||
| 95 | void testRequest_Error() { | 98 | void testRequest_Error() { | 
| 96 | boost::shared_ptr<VCardManager> testling = createManager(); | 99 | boost::shared_ptr<VCardManager> testling = createManager(); | 
| 97 | testling->requestVCard(JID("foo@bar.com/baz")); | 100 | testling->requestVCard(JID("foo@bar.com/baz")); | 
| 98 | stanzaChannel->onIQReceived(IQ::createError(JID("baz@fum.com/foo"), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID())); | 101 | stanzaChannel->onIQReceived(IQ::createError(JID("baz@fum.com/foo"), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID())); | 
| 99 | 102 | ||
| 100 | CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(changes.size())); | 103 | // On error, cached vCards should not be changed. | 
| 101 | CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com/baz"), changes[0].first); | 104 | CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(changes.size())); | 
| 102 | CPPUNIT_ASSERT_EQUAL(std::string(""), changes[0].second->getFullName()); | ||
| 103 | CPPUNIT_ASSERT_EQUAL(std::string(""), vcardStorage->getVCard(JID("foo@bar.com/baz"))->getFullName()); | ||
| 104 | } | 105 | } | 
| 105 | 106 | ||
| 106 | void testRequest_VCardAlreadyRequested() { | 107 | void testRequest_VCardAlreadyRequested() { | 
| 107 | boost::shared_ptr<VCardManager> testling = createManager(); | 108 | boost::shared_ptr<VCardManager> testling = createManager(); | 
| 108 | testling->requestVCard(JID("foo@bar.com/baz")); | 109 | testling->requestVCard(JID("foo@bar.com/baz")); | 
| 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,20 +1,19 @@ | |||
| 1 | /* | 1 | /* | 
| 2 | * Copyright (c) 2010-2014 Isode Limited. | 2 | * Copyright (c) 2010-2015 Isode Limited. | 
| 3 | * All rights reserved. | 3 | * All rights reserved. | 
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. | 
| 5 | */ | 5 | */ | 
| 6 | 6 | ||
| 7 | #include <Swiften/VCards/VCardManager.h> | 7 | #include <Swiften/VCards/VCardManager.h> | 
| 8 | 8 | ||
| 9 | #include <boost/bind.hpp> | 9 | #include <boost/bind.hpp> | 
| 10 | 10 | ||
| 11 | #include <Swiften/Base/Log.h> | 11 | #include <Swiften/Base/Log.h> | 
| 12 | #include <Swiften/JID/JID.h> | 12 | #include <Swiften/JID/JID.h> | 
| 13 | #include <Swiften/VCards/VCardStorage.h> | ||
| 14 | #include <Swiften/VCards/GetVCardRequest.h> | 13 | #include <Swiften/VCards/GetVCardRequest.h> | 
| 15 | 14 | #include <Swiften/VCards/VCardStorage.h> | |
| 16 | 15 | ||
| 17 | namespace Swift { | 16 | namespace Swift { | 
| 18 | 17 | ||
| 19 | VCardManager::VCardManager(const JID& ownJID, IQRouter* iqRouter, VCardStorage* vcardStorage) : ownJID(ownJID), iqRouter(iqRouter), storage(vcardStorage) { | 18 | VCardManager::VCardManager(const JID& ownJID, IQRouter* iqRouter, VCardStorage* vcardStorage) : ownJID(ownJID), iqRouter(iqRouter), storage(vcardStorage) { | 
| 20 | } | 19 | } | 
| @@ -51,16 +50,18 @@ void VCardManager::requestOwnVCard() { | |||
| 51 | requestVCard(JID()); | 50 | requestVCard(JID()); | 
| 52 | } | 51 | } | 
| 53 | 52 | ||
| 54 | 53 | ||
| 55 | void VCardManager::handleVCardReceived(const JID& actualJID, VCard::ref vcard, ErrorPayload::ref error) { | 54 | void VCardManager::handleVCardReceived(const JID& actualJID, VCard::ref vcard, ErrorPayload::ref error) { | 
| 56 | if (error || !vcard) { | ||
| 57 | vcard = VCard::ref(new VCard()); | ||
| 58 | } | ||
| 59 | requestedVCards.erase(actualJID); | 55 | requestedVCards.erase(actualJID); | 
| 60 | JID jid = actualJID.isValid() ? actualJID : ownJID.toBare(); | 56 | if (!error) { | 
| 61 | setVCard(jid, vcard); | 57 | if (!vcard) { | 
| 58 | vcard = VCard::ref(new VCard()); | ||
| 59 | } | ||
| 60 | JID jid = actualJID.isValid() ? actualJID : ownJID.toBare(); | ||
| 61 | setVCard(jid, vcard); | ||
| 62 | } | ||
| 62 | } | 63 | } | 
| 63 | 64 | ||
| 64 | SetVCardRequest::ref VCardManager::createSetVCardRequest(VCard::ref vcard) { | 65 | SetVCardRequest::ref VCardManager::createSetVCardRequest(VCard::ref vcard) { | 
| 65 | SetVCardRequest::ref request = SetVCardRequest::create(vcard, iqRouter); | 66 | SetVCardRequest::ref request = SetVCardRequest::create(vcard, iqRouter); | 
| 66 | request->onResponse.connect(boost::bind(&VCardManager::handleSetVCardResponse, this, vcard, _2)); | 67 | request->onResponse.connect(boost::bind(&VCardManager::handleSetVCardResponse, this, vcard, _2)); | 
 Swift
 Swift