diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-03-28 15:46:49 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-03-28 15:46:49 (GMT) |
commit | f53a1ef582494458301b97bf6e546be52d7ff7e8 (patch) | |
tree | 7571b5cbcbd8a8f1dd1c966c9045b6cb69f0e295 /Swiften/Avatars/UnitTest | |
parent | 638345680d72ca6acaf123f2c8c1c391f696e371 (diff) | |
download | swift-f53a1ef582494458301b97bf6e546be52d7ff7e8.zip swift-f53a1ef582494458301b97bf6e546be52d7ff7e8.tar.bz2 |
Moving submodule contents back.
Diffstat (limited to 'Swiften/Avatars/UnitTest')
-rw-r--r-- | Swiften/Avatars/UnitTest/AvatarManagerTest.cpp | 110 | ||||
-rw-r--r-- | Swiften/Avatars/UnitTest/MockAvatarManager.cpp | 26 | ||||
-rw-r--r-- | Swiften/Avatars/UnitTest/MockAvatarManager.h | 17 |
3 files changed, 153 insertions, 0 deletions
diff --git a/Swiften/Avatars/UnitTest/AvatarManagerTest.cpp b/Swiften/Avatars/UnitTest/AvatarManagerTest.cpp new file mode 100644 index 0000000..3b4c5f9 --- /dev/null +++ b/Swiften/Avatars/UnitTest/AvatarManagerTest.cpp @@ -0,0 +1,110 @@ +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include "Swiften/Elements/VCardUpdate.h" +#include "Swiften/Avatars/AvatarManager.h" +#include "Swiften/Avatars/AvatarStorage.h" +#include "Swiften/MUC/MUCRegistry.h" +#include "Swiften/Queries/IQRouter.h" +#include "Swiften/Client/DummyStanzaChannel.h" + +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_UpdateNewHashSameThanOtherUser); + CPPUNIT_TEST(testReceiveVCard); + CPPUNIT_TEST(testGetAvatarPath); + CPPUNIT_TEST(testGetAvatarPathFromMUC); + CPPUNIT_TEST_SUITE_END(); + + public: + AvatarManagerTest() {} + + void setUp() { + stanzaChannel_ = new DummyStanzaChannel(); + iqRouter_ = new IQRouter(stanzaChannel_); + mucRegistry_ = new DummyMUCRegistry(); + avatarStorage_ = new DummyAvatarStorage(); + } + + void tearDown() { + delete avatarStorage_; + delete mucRegistry_; + delete iqRouter_; + delete stanzaChannel_; + } + + void testUpdate_UpdateNewHash() { + std::auto_ptr<AvatarManager> testling = createManager(); + stanzaChannel_->onPresenceReceived(createPresenceWithPhotoHash()); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(stanzaChannel_->sentStanzas_.size())); + IQ* + CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<VCardUpdate>(0, JID("foo@bar.com"), IQ::Get)); + } + + void testUpdate_UpdateNewHashAlreadyHaveAvatar() { + std::auto_ptr<AvatarManager> testling = createManager(); + } + + void testUpdate_UpdateNewHashFromMUC() { + std::auto_ptr<AvatarManager> testling = createManager(); + } + + void testUpdate_UpdateSameHash() { + std::auto_ptr<AvatarManager> testling = createManager(); + } + + void testUpdate_UpdateNewHashSameThanOtherUser() { + std::auto_ptr<AvatarManager> testling = createManager(); + } + + void testReceiveVCard() { + std::auto_ptr<AvatarManager> testling = createManager(); + } + + void testGetAvatarPath() { + std::auto_ptr<AvatarManager> testling = createManager(); + } + + void testGetAvatarPathFromMUC() { + std::auto_ptr<AvatarManager> testling = createManager(); + } + + private: + std::auto_ptr<AvatarManager> createManager() { + return std::auto_ptr<AvatarManager>(new AvatarManager(stanzaChannel_, iqRouter_, avatarStorage_, mucRegistry_)); + } + + boost::shared_ptr<Presence> createPresenceWithPhotoHash() { + boost::shared_ptr<Presence> presence(new Presence()); + presence->setFrom(JID("foo@bar.com/baz")); + presence->addPayload(boost::shared_ptr<VCardUpdate>(new VCardUpdate("aef56135bcce35eb24a43fcd684005b4ca286497"))); + return presence; + } + + private: + struct DummyMUCRegistry : public MUCRegistry { + bool isMUC(const JID& jid) const { return std::find(mucs_.begin(), mucs_.end(), jid) != mucs_.end(); } + std::vector<JID> mucs_; + }; + struct DummyAvatarStorage : public AvatarStorage { + virtual bool hasAvatar(const String& hash) const { return avatars.find(hash) != avatars.end(); } + virtual void addAvatar(const String& hash, const ByteArray& avatar) { avatars[hash] = avatar; } + virtual boost::filesystem::path getAvatarPath(const String& hash) const { + return boost::filesystem::path("/avatars") / hash.getUTF8String(); + } + std::map<String, ByteArray> avatars; + }; + DummyStanzaChannel* stanzaChannel_; + IQRouter* iqRouter_; + DummyMUCRegistry* mucRegistry_; + DummyAvatarStorage* avatarStorage_; +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(AvatarManagerTest); diff --git a/Swiften/Avatars/UnitTest/MockAvatarManager.cpp b/Swiften/Avatars/UnitTest/MockAvatarManager.cpp new file mode 100644 index 0000000..2d3d48a --- /dev/null +++ b/Swiften/Avatars/UnitTest/MockAvatarManager.cpp @@ -0,0 +1,26 @@ +#include "Swiften/Avatars/UnitTest/MockAvatarManager.h" + +namespace Swift { + +MockAvatarManager::MockAvatarManager() { + +} + +MockAvatarManager::~MockAvatarManager() { + +} + +String MockAvatarManager::getAvatarHash(const JID& jid) const { + return jid.toBare(); +} + +boost::filesystem::path MockAvatarManager::getAvatarPath(const JID& jid) const { + return jid.getResource().getUTF8String(); +} + +void MockAvatarManager::setAvatar(const JID&, const ByteArray&) { + +} + +} + diff --git a/Swiften/Avatars/UnitTest/MockAvatarManager.h b/Swiften/Avatars/UnitTest/MockAvatarManager.h new file mode 100644 index 0000000..416d921 --- /dev/null +++ b/Swiften/Avatars/UnitTest/MockAvatarManager.h @@ -0,0 +1,17 @@ +#pragma once + +#include "Swiften/Avatars/AvatarManager.h" +#include "Swiften/Client/DummyStanzaChannel.h" + +namespace Swift { + class MockAvatarManager : public AvatarManager { + public: + MockAvatarManager(); + virtual ~MockAvatarManager(); + virtual String getAvatarHash(const JID&) const; + virtual boost::filesystem::path getAvatarPath(const JID&) const; + virtual void setAvatar(const JID&, const ByteArray& avatar); + private: + DummyStanzaChannel channel_; + }; +} |