diff --git a/tests/libtransport/user.cpp b/tests/libtransport/user.cpp index 8d40f27793b61d25921bd4a9b11f61486b2f123e..9c7191e98b0f47d9076310623f633f11748441ec 100644 --- a/tests/libtransport/user.cpp +++ b/tests/libtransport/user.cpp @@ -30,12 +30,14 @@ class UserTest : public CPPUNIT_NS :: TestFixture, public BasicTest { CPPUNIT_TEST(handleDisconnectedReconnect); CPPUNIT_TEST(joinRoomHandleDisconnectedRejoin); CPPUNIT_TEST(joinRoomAfterFlagNotAuthorized); + CPPUNIT_TEST(requestVCard); CPPUNIT_TEST_SUITE_END(); public: std::string room; std::string roomNickname; std::string roomPassword; + std::string photo; bool readyToConnect; bool disconnected; Swift::Presence::ref changedPresence; @@ -47,11 +49,14 @@ class UserTest : public CPPUNIT_NS :: TestFixture, public BasicTest { room = ""; roomNickname = ""; roomPassword = ""; + photo = ""; setMeUp(); userManager->onUserCreated.connect(boost::bind(&UserTest::handleUserCreated, this, _1)); connectUser(); received.clear(); + + frontend->onVCardUpdated.connect(boost::bind(&UserTest::handleVCardUpdated, this, _1, _2)); } void tearDown (void) { @@ -63,6 +68,10 @@ class UserTest : public CPPUNIT_NS :: TestFixture, public BasicTest { tearMeDown(); } + void handleVCardUpdated(User *user, boost::shared_ptr v) { + photo = Swift::byteArrayToString(v->getPhoto()); + } + void handleUserCreated(User *user) { user->onReadyToConnect.connect(boost::bind(&UserTest::handleUserReadyToConnect, this, user)); user->onPresenceChanged.connect(boost::bind(&UserTest::handleUserPresenceChanged, this, user, _1)); @@ -472,6 +481,36 @@ class UserTest : public CPPUNIT_NS :: TestFixture, public BasicTest { handlePresenceJoinRoom(); } + void requestVCard() { + User *user = userManager->getUser("user@localhost"); + user->setStorageBackend(storage); + + Swift::Presence::ref response = Swift::Presence::create(); + response->setTo("localhost"); + response->setFrom("user@localhost/resource"); + response->addPayload(boost::shared_ptr(new Swift::VCardUpdate("hash"))); + + injectPresence(response); + loop->processEvents(); + + CPPUNIT_ASSERT_EQUAL(2, (int) received.size()); + Swift::VCard::ref payload1 = getStanza(received[1])->getPayload(); + CPPUNIT_ASSERT(payload1); + + boost::shared_ptr vcard(new Swift::VCard()); + vcard->setPhoto(Swift::createByteArray("photo")); + injectIQ(Swift::IQ::createResult(getStanza(received[1])->getFrom(), getStanza(received[1])->getTo(), getStanza(received[1])->getID(), vcard)); + loop->processEvents(); + + CPPUNIT_ASSERT_EQUAL(2, (int) received.size()); + CPPUNIT_ASSERT_EQUAL(std::string("photo"), photo); + + received.clear(); + injectPresence(response); + loop->processEvents(); + CPPUNIT_ASSERT_EQUAL(1, (int) received.size()); + } + }; CPPUNIT_TEST_SUITE_REGISTRATION (UserTest);