Merge branch 'master' of github.com:hanzz/libtransport
This commit is contained in:
commit
b1ad81237c
15 changed files with 238 additions and 46 deletions
|
@ -47,7 +47,7 @@ class Buddy {
|
|||
/// \param rosterManager RosterManager associated with this buddy.
|
||||
/// \param id ID which identifies the buddy in database or -1 if it's new buddy which is
|
||||
/// not in database yet.
|
||||
Buddy(RosterManager *rosterManager, long id = -1);
|
||||
Buddy(RosterManager *rosterManager, long id = -1, BuddyFlag flags = BUDDY_NO_FLAG);
|
||||
|
||||
/// Destructor
|
||||
virtual ~Buddy();
|
||||
|
@ -165,7 +165,7 @@ class Buddy {
|
|||
/// \param jid Jabber ID.
|
||||
/// \return legacy name of buddy from JID.
|
||||
static std::string JIDToLegacyName(const Swift::JID &jid);
|
||||
static BuddyFlag buddFlagsFromJID(const Swift::JID &jid);
|
||||
static BuddyFlag buddyFlagsFromJID(const Swift::JID &jid);
|
||||
|
||||
protected:
|
||||
void generateJID();
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace Transport {
|
|||
|
||||
class LocalBuddy : public Buddy {
|
||||
public:
|
||||
LocalBuddy(RosterManager *rosterManager, long id);
|
||||
LocalBuddy(RosterManager *rosterManager, long id, const std::string &name, const std::string &alias = "", const std::vector<std::string> &groups = std::vector<std::string>(), BuddyFlag flags = BUDDY_NO_FLAG);
|
||||
virtual ~LocalBuddy();
|
||||
|
||||
std::string getAlias() { return m_alias; }
|
||||
|
@ -61,6 +61,11 @@ class LocalBuddy : public Buddy {
|
|||
std::vector<std::string> getGroups() { return m_groups; }
|
||||
void setGroups(const std::vector<std::string> &groups);
|
||||
|
||||
bool isValid() {
|
||||
std::string safeName = getSafeName();
|
||||
return m_jid.isValid() && safeName.find("/") == std::string::npos;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
std::string m_alias;
|
||||
|
@ -68,7 +73,6 @@ class LocalBuddy : public Buddy {
|
|||
std::string m_statusMessage;
|
||||
std::string m_iconHash;
|
||||
Swift::StatusShow m_status;
|
||||
bool m_firstSet;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
namespace Transport {
|
||||
|
||||
Buddy::Buddy(RosterManager *rosterManager, long id) : m_id(id), m_flags(BUDDY_NO_FLAG), m_rosterManager(rosterManager),
|
||||
Buddy::Buddy(RosterManager *rosterManager, long id, BuddyFlag flags) : m_id(id), m_flags(flags), m_rosterManager(rosterManager),
|
||||
m_subscription(Ask) {
|
||||
// m_rosterManager->setBuddy(this);
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ std::string Buddy::JIDToLegacyName(const Swift::JID &jid) {
|
|||
return name;
|
||||
}
|
||||
|
||||
BuddyFlag Buddy::buddFlagsFromJID(const Swift::JID &jid) {
|
||||
BuddyFlag Buddy::buddyFlagsFromJID(const Swift::JID &jid) {
|
||||
if (jid.getUnescapedNode() == jid.getNode()) {
|
||||
return BUDDY_NO_FLAG;
|
||||
}
|
||||
|
|
|
@ -23,9 +23,15 @@
|
|||
|
||||
namespace Transport {
|
||||
|
||||
LocalBuddy::LocalBuddy(RosterManager *rosterManager, long id) : Buddy(rosterManager, id) {
|
||||
LocalBuddy::LocalBuddy(RosterManager *rosterManager, long id, const std::string &name, const std::string &alias, const std::vector<std::string> &groups, BuddyFlag flags) : Buddy(rosterManager, id, flags) {
|
||||
m_status = Swift::StatusShow::None;
|
||||
m_firstSet = true;
|
||||
m_alias = alias;
|
||||
m_name = name;
|
||||
m_groups = groups;
|
||||
try {
|
||||
generateJID();
|
||||
} catch (...) {
|
||||
}
|
||||
}
|
||||
|
||||
LocalBuddy::~LocalBuddy() {
|
||||
|
@ -47,11 +53,6 @@ bool LocalBuddy::setName(const std::string &name) {
|
|||
}
|
||||
|
||||
void LocalBuddy::setAlias(const std::string &alias) {
|
||||
// if (m_firstSet) {
|
||||
// m_firstSet = false;
|
||||
// m_alias = alias;
|
||||
// return;
|
||||
// }
|
||||
bool changed = m_alias != alias;
|
||||
m_alias = alias;
|
||||
|
||||
|
|
|
@ -84,6 +84,8 @@ class NetworkFactory : public Factory {
|
|||
m_nps = nps;
|
||||
}
|
||||
|
||||
virtual ~NetworkFactory() {}
|
||||
|
||||
// Creates new conversation (NetworkConversation in this case)
|
||||
Conversation *createConversation(ConversationManager *conversationManager, const std::string &legacyName) {
|
||||
NetworkConversation *nc = new NetworkConversation(conversationManager, legacyName);
|
||||
|
@ -93,10 +95,8 @@ class NetworkFactory : public Factory {
|
|||
|
||||
// Creates new LocalBuddy
|
||||
Buddy *createBuddy(RosterManager *rosterManager, const BuddyInfo &buddyInfo) {
|
||||
LocalBuddy *buddy = new LocalBuddy(rosterManager, buddyInfo.id);
|
||||
buddy->setAlias(buddyInfo.alias);
|
||||
buddy->setFlags((BuddyFlag) (buddyInfo.flags));
|
||||
if (!buddy->setName(buddyInfo.legacyName)) {
|
||||
LocalBuddy *buddy = new LocalBuddy(rosterManager, buddyInfo.id, buddyInfo.legacyName, buddyInfo.alias, buddyInfo.groups, (BuddyFlag) buddyInfo.flags);
|
||||
if (!buddy->isValid()) {
|
||||
delete buddy;
|
||||
return NULL;
|
||||
}
|
||||
|
@ -106,7 +106,6 @@ class NetworkFactory : public Factory {
|
|||
else {
|
||||
buddy->setSubscription(Buddy::Ask);
|
||||
}
|
||||
buddy->setGroups(buddyInfo.groups);
|
||||
if (buddyInfo.settings.find("icon_hash") != buddyInfo.settings.end())
|
||||
buddy->setIconHash(buddyInfo.settings.find("icon_hash")->second.s);
|
||||
return buddy;
|
||||
|
@ -510,13 +509,18 @@ void NetworkPluginServer::handleBuddyChangedPayload(const std::string &data) {
|
|||
buddy->handleBuddyChanged();
|
||||
}
|
||||
else {
|
||||
buddy = new LocalBuddy(user->getRosterManager(), -1);
|
||||
if (!buddy->setName(payload.buddyname())) {
|
||||
std::vector<std::string> groups;
|
||||
for (int i = 0; i < payload.group_size(); i++) {
|
||||
groups.push_back(payload.group(i));
|
||||
}
|
||||
buddy = new LocalBuddy(user->getRosterManager(), -1, payload.buddyname(), payload.alias(), groups, BUDDY_JID_ESCAPING);
|
||||
if (!buddy->isValid()) {
|
||||
delete buddy;
|
||||
return;
|
||||
}
|
||||
buddy->setFlags(BUDDY_JID_ESCAPING);
|
||||
handleBuddyPayload(buddy, payload);
|
||||
buddy->setStatus(Swift::StatusShow((Swift::StatusShow::Type) payload.status()), payload.statusmessage());
|
||||
buddy->setIconHash(payload.iconhash());
|
||||
buddy->setBlocked(payload.blocked());
|
||||
user->getRosterManager()->setBuddy(buddy);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -299,7 +299,7 @@ void RosterManager::handleRemoteRosterResponse(boost::shared_ptr<Swift::RosterPa
|
|||
buddyInfo.alias = item.getName();
|
||||
buddyInfo.legacyName = legacyName;
|
||||
buddyInfo.subscription = "both";
|
||||
buddyInfo.flags = Buddy::buddFlagsFromJID(item.getJID());
|
||||
buddyInfo.flags = Buddy::buddyFlagsFromJID(item.getJID());
|
||||
buddyInfo.groups = item.getGroups();
|
||||
|
||||
Buddy *buddy = m_component->getFactory()->createBuddy(this, buddyInfo);
|
||||
|
@ -394,7 +394,7 @@ void RosterManager::handleSubscription(Swift::Presence::ref presence) {
|
|||
buddyInfo.alias = "";
|
||||
buddyInfo.legacyName = Buddy::JIDToLegacyName(presence->getTo());
|
||||
buddyInfo.subscription = "both";
|
||||
buddyInfo.flags = Buddy::buddFlagsFromJID(presence->getTo());
|
||||
buddyInfo.flags = Buddy::buddyFlagsFromJID(presence->getTo());
|
||||
LOG4CXX_INFO(logger, m_user->getJID().toString() << ": Subscription received for new buddy " << buddyInfo.legacyName << " => adding to legacy network");
|
||||
|
||||
buddy = m_component->getFactory()->createBuddy(this, buddyInfo);
|
||||
|
@ -473,7 +473,7 @@ void RosterManager::handleSubscription(Swift::Presence::ref presence) {
|
|||
buddyInfo.alias = "";
|
||||
buddyInfo.legacyName = Buddy::JIDToLegacyName(presence->getTo());
|
||||
buddyInfo.subscription = "both";
|
||||
buddyInfo.flags = Buddy::buddFlagsFromJID(presence->getTo());
|
||||
buddyInfo.flags = Buddy::buddyFlagsFromJID(presence->getTo());
|
||||
|
||||
buddy = m_component->getFactory()->createBuddy(this, buddyInfo);
|
||||
setBuddy(buddy);
|
||||
|
|
|
@ -96,7 +96,7 @@ bool RosterResponder::handleSetRequest(const Swift::JID& from, const Swift::JID&
|
|||
buddyInfo.alias = item.getName();
|
||||
buddyInfo.legacyName = Buddy::JIDToLegacyName(item.getJID());
|
||||
buddyInfo.subscription = "both";
|
||||
buddyInfo.flags = Buddy::buddFlagsFromJID(item.getJID());
|
||||
buddyInfo.flags = Buddy::buddyFlagsFromJID(item.getJID());
|
||||
LOG4CXX_INFO(logger, from.toBare().toString() << ": Adding buddy " << buddyInfo.legacyName);
|
||||
|
||||
buddy = user->getComponent()->getFactory()->createBuddy(user->getRosterManager(), buddyInfo);
|
||||
|
|
|
@ -18,6 +18,24 @@
|
|||
#include "Swiften/Server/ServerFromClientSession.h"
|
||||
#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h"
|
||||
|
||||
#include "Swiften/Serializer/GenericPayloadSerializer.h"
|
||||
|
||||
#include "../storageparser.h"
|
||||
#include "Swiften/Parser/PayloadParsers/AttentionParser.h"
|
||||
#include "Swiften/Serializer/PayloadSerializers/AttentionSerializer.h"
|
||||
#include "Swiften/Parser/PayloadParsers/XHTMLIMParser.h"
|
||||
#include "Swiften/Serializer/PayloadSerializers/XHTMLIMSerializer.h"
|
||||
#include "Swiften/Parser/PayloadParsers/StatsParser.h"
|
||||
#include "Swiften/Serializer/PayloadSerializers/StatsSerializer.h"
|
||||
#include "Swiften/Parser/PayloadParsers/GatewayPayloadParser.h"
|
||||
#include "Swiften/Serializer/PayloadSerializers/GatewayPayloadSerializer.h"
|
||||
#include "Swiften/Serializer/PayloadSerializers/SpectrumErrorSerializer.h"
|
||||
#include "Swiften/Parser/PayloadParsers/MUCPayloadParser.h"
|
||||
#include "transport/BlockParser.h"
|
||||
#include "transport/BlockSerializer.h"
|
||||
#include "Swiften/Parser/PayloadParsers/InvisibleParser.h"
|
||||
#include "Swiften/Serializer/PayloadSerializers/InvisibleSerializer.h"
|
||||
|
||||
using namespace Transport;
|
||||
|
||||
void BasicTest::setMeUp (void) {
|
||||
|
@ -40,6 +58,24 @@ void BasicTest::setMeUp (void) {
|
|||
|
||||
payloadSerializers = new Swift::FullPayloadSerializerCollection();
|
||||
payloadParserFactories = new Swift::FullPayloadParserFactoryCollection();
|
||||
|
||||
payloadParserFactories->addFactory(new Swift::GenericPayloadParserFactory<StorageParser>("private", "jabber:iq:private"));
|
||||
payloadParserFactories->addFactory(new Swift::GenericPayloadParserFactory<Swift::AttentionParser>("attention", "urn:xmpp:attention:0"));
|
||||
payloadParserFactories->addFactory(new Swift::GenericPayloadParserFactory<Swift::XHTMLIMParser>("html", "http://jabber.org/protocol/xhtml-im"));
|
||||
payloadParserFactories->addFactory(new Swift::GenericPayloadParserFactory<Transport::BlockParser>("block", "urn:xmpp:block:0"));
|
||||
payloadParserFactories->addFactory(new Swift::GenericPayloadParserFactory<Swift::InvisibleParser>("invisible", "urn:xmpp:invisible:0"));
|
||||
payloadParserFactories->addFactory(new Swift::GenericPayloadParserFactory<Swift::StatsParser>("query", "http://jabber.org/protocol/stats"));
|
||||
payloadParserFactories->addFactory(new Swift::GenericPayloadParserFactory<Swift::GatewayPayloadParser>("query", "jabber:iq:gateway"));
|
||||
payloadParserFactories->addFactory(new Swift::GenericPayloadParserFactory<Swift::MUCPayloadParser>("x", "http://jabber.org/protocol/muc"));
|
||||
|
||||
payloadSerializers->addSerializer(new Swift::AttentionSerializer());
|
||||
payloadSerializers->addSerializer(new Swift::XHTMLIMSerializer());
|
||||
payloadSerializers->addSerializer(new Transport::BlockSerializer());
|
||||
payloadSerializers->addSerializer(new Swift::InvisibleSerializer());
|
||||
payloadSerializers->addSerializer(new Swift::StatsSerializer());
|
||||
payloadSerializers->addSerializer(new Swift::SpectrumErrorSerializer());
|
||||
payloadSerializers->addSerializer(new Swift::GatewayPayloadSerializer());
|
||||
|
||||
parser = new Swift::XMPPParser(this, payloadParserFactories, factories->getXMLParserFactory());
|
||||
|
||||
serverFromClientSession = boost::shared_ptr<Swift::ServerFromClientSession>(new Swift::ServerFromClientSession("id", factories->getConnectionFactory()->createConnection(),
|
||||
|
@ -51,6 +87,7 @@ void BasicTest::setMeUp (void) {
|
|||
dynamic_cast<Swift::ServerStanzaChannel *>(component->getStanzaChannel())->addSession(serverFromClientSession);
|
||||
parser->parse("<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' to='localhost' version='1.0'>");
|
||||
received.clear();
|
||||
receivedData.clear();
|
||||
loop->processEvents();
|
||||
}
|
||||
|
||||
|
@ -64,10 +101,12 @@ void BasicTest::tearMeDown (void) {
|
|||
delete cfg;
|
||||
delete parser;
|
||||
received.clear();
|
||||
receivedData.clear();
|
||||
}
|
||||
|
||||
void BasicTest::handleDataReceived(const Swift::SafeByteArray &data) {
|
||||
// std::cout << safeByteArrayToString(data) << "\n";
|
||||
receivedData += safeByteArrayToString(data) + "\n";
|
||||
parser->parse(safeByteArrayToString(data));
|
||||
}
|
||||
|
||||
|
@ -75,8 +114,12 @@ void BasicTest::handleStreamStart(const Swift::ProtocolHeader&) {
|
|||
|
||||
}
|
||||
|
||||
void BasicTest::dumpReceived() {
|
||||
std::cout << receivedData << "\n";
|
||||
}
|
||||
|
||||
void BasicTest::handleElement(boost::shared_ptr<Swift::Element> element) {
|
||||
received.push_back(element);
|
||||
received.push_back(element);
|
||||
}
|
||||
|
||||
void BasicTest::handleStreamEnd() {
|
||||
|
|
|
@ -69,12 +69,12 @@ class TestingFactory : public Factory {
|
|||
|
||||
// Creates new LocalBuddy
|
||||
Buddy *createBuddy(RosterManager *rosterManager, const BuddyInfo &buddyInfo) {
|
||||
LocalBuddy *buddy = new LocalBuddy(rosterManager, buddyInfo.id);
|
||||
buddy->setAlias(buddyInfo.alias);
|
||||
buddy->setName(buddyInfo.legacyName);
|
||||
LocalBuddy *buddy = new LocalBuddy(rosterManager, buddyInfo.id, buddyInfo.legacyName, buddyInfo.alias, buddyInfo.groups, (BuddyFlag) buddyInfo.flags);
|
||||
if (!buddy->isValid()) {
|
||||
delete buddy;
|
||||
return NULL;
|
||||
}
|
||||
buddy->setSubscription(Buddy::Ask);
|
||||
buddy->setGroups(buddyInfo.groups);
|
||||
buddy->setFlags((BuddyFlag) buddyInfo.flags);
|
||||
if (buddyInfo.settings.find("icon_hash") != buddyInfo.settings.end())
|
||||
buddy->setIconHash(buddyInfo.settings.find("icon_hash")->second.s);
|
||||
return buddy;
|
||||
|
@ -99,6 +99,8 @@ class BasicTest : public Swift::XMPPParserClient {
|
|||
void injectPresence(boost::shared_ptr<Swift::Presence> &response);
|
||||
void injectIQ(boost::shared_ptr<Swift::IQ> iq);
|
||||
|
||||
void dumpReceived();
|
||||
|
||||
Swift::Stanza *getStanza(boost::shared_ptr<Swift::Element> element);
|
||||
|
||||
protected:
|
||||
|
@ -116,5 +118,6 @@ class BasicTest : public Swift::XMPPParserClient {
|
|||
TestingFactory *factory;
|
||||
Component *component;
|
||||
std::vector<boost::shared_ptr<Swift::Element> > received;
|
||||
std::string receivedData;
|
||||
};
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ class ComponentTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
|
|||
CPPUNIT_TEST_SUITE(ComponentTest);
|
||||
CPPUNIT_TEST(handlePresenceWithNode);
|
||||
CPPUNIT_TEST(handlePresenceWithoutNode);
|
||||
CPPUNIT_TEST(handleErrorPresence);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
|
@ -56,6 +57,18 @@ class ComponentTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
|
|||
CPPUNIT_ASSERT_EQUAL(0, (int) received.size());
|
||||
}
|
||||
|
||||
// Error presence should be ignored
|
||||
void handleErrorPresence() {
|
||||
Swift::Presence::ref response = Swift::Presence::create();
|
||||
response->setTo("localhost");
|
||||
response->setFrom("user@localhost/resource");
|
||||
response->setType(Swift::Presence::Error);
|
||||
dynamic_cast<Swift::ServerStanzaChannel *>(component->getStanzaChannel())->onPresenceReceived(response);
|
||||
|
||||
loop->processEvents();
|
||||
CPPUNIT_ASSERT_EQUAL(0, (int) received.size());
|
||||
}
|
||||
|
||||
void handlePresenceWithoutNode() {
|
||||
Swift::Presence::ref response = Swift::Presence::create();
|
||||
response->setTo("localhost");
|
||||
|
|
129
src/tests/localbuddy.cpp
Normal file
129
src/tests/localbuddy.cpp
Normal file
|
@ -0,0 +1,129 @@
|
|||
#include "transport/userregistry.h"
|
||||
#include "transport/config.h"
|
||||
#include "transport/storagebackend.h"
|
||||
#include "transport/user.h"
|
||||
#include "transport/transport.h"
|
||||
#include "transport/conversation.h"
|
||||
#include "transport/usermanager.h"
|
||||
#include "transport/localbuddy.h"
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <Swiften/Swiften.h>
|
||||
#include <Swiften/EventLoop/DummyEventLoop.h>
|
||||
#include <Swiften/Server/Server.h>
|
||||
#include <Swiften/Network/DummyNetworkFactories.h>
|
||||
#include <Swiften/Network/DummyConnectionServer.h>
|
||||
#include "Swiften/Server/ServerStanzaChannel.h"
|
||||
#include "Swiften/Server/ServerFromClientSession.h"
|
||||
#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h"
|
||||
#include "basictest.h"
|
||||
|
||||
using namespace Transport;
|
||||
|
||||
class LocalBuddyTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
|
||||
CPPUNIT_TEST_SUITE(LocalBuddyTest);
|
||||
CPPUNIT_TEST(createWithInvalidName);
|
||||
CPPUNIT_TEST(buddyFlagsFromJID);
|
||||
CPPUNIT_TEST(JIDToLegacyName);
|
||||
CPPUNIT_TEST(handleBuddyChanged);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
void setUp (void) {
|
||||
setMeUp();
|
||||
connectUser();
|
||||
received.clear();
|
||||
}
|
||||
|
||||
void tearDown (void) {
|
||||
received.clear();
|
||||
disconnectUser();
|
||||
tearMeDown();
|
||||
}
|
||||
|
||||
void connectUser() {
|
||||
CPPUNIT_ASSERT_EQUAL(0, userManager->getUserCount());
|
||||
userRegistry->isValidUserPassword(Swift::JID("user@localhost/resource"), serverFromClientSession.get(), Swift::createSafeByteArray("password"));
|
||||
loop->processEvents();
|
||||
CPPUNIT_ASSERT_EQUAL(1, userManager->getUserCount());
|
||||
|
||||
User *user = userManager->getUser("user@localhost");
|
||||
CPPUNIT_ASSERT(user);
|
||||
|
||||
UserInfo userInfo = user->getUserInfo();
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("password"), userInfo.password);
|
||||
CPPUNIT_ASSERT(user->isReadyToConnect() == true);
|
||||
CPPUNIT_ASSERT(user->isConnected() == false);
|
||||
|
||||
user->setConnected(true);
|
||||
CPPUNIT_ASSERT(user->isConnected() == true);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
|
||||
CPPUNIT_ASSERT(getStanza(received[0])->getPayload<Swift::DiscoInfo>());
|
||||
received.clear();
|
||||
}
|
||||
|
||||
void createWithInvalidName() {
|
||||
User *user = userManager->getUser("user@localhost");
|
||||
CPPUNIT_ASSERT(user);
|
||||
|
||||
std::vector<std::string> grp;
|
||||
grp.push_back("group");
|
||||
|
||||
// with BUDDY_JID_ESCAPING it escapes /
|
||||
LocalBuddy *buddy = new LocalBuddy(user->getRosterManager(), -1, "msn/something", "Buddy 1", grp, BUDDY_JID_ESCAPING);
|
||||
CPPUNIT_ASSERT(buddy->isValid());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("msn\\2fsomething@localhost/bot"), buddy->getJID().toString());
|
||||
delete buddy;
|
||||
|
||||
// without BUDDY_JID_ESCAPING it shoudl fail
|
||||
buddy = new LocalBuddy(user->getRosterManager(), -1, "msn/something", "Buddy 1", grp);
|
||||
CPPUNIT_ASSERT(!buddy->isValid());
|
||||
delete buddy;
|
||||
|
||||
buddy = new LocalBuddy(user->getRosterManager(), -1, "\xd7\x92\xd7\x9c\xd7\x99\xd7\x9d@nimbuzz.com", "Buddy 1", grp);
|
||||
CPPUNIT_ASSERT(!buddy->isValid());
|
||||
delete buddy;
|
||||
}
|
||||
|
||||
void JIDToLegacyName() {
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("hanzz@test"), Buddy::JIDToLegacyName("hanzz\\40test@localhost/bot"));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("hanzz@test"), Buddy::JIDToLegacyName("hanzz%test@localhost/bot"));
|
||||
}
|
||||
|
||||
void buddyFlagsFromJID() {
|
||||
CPPUNIT_ASSERT_EQUAL(BUDDY_JID_ESCAPING, Buddy::buddyFlagsFromJID("hanzz\\40test@localhost/bot"));
|
||||
CPPUNIT_ASSERT_EQUAL(BUDDY_NO_FLAG, Buddy::buddyFlagsFromJID("hanzz%test@localhost/bot"));
|
||||
}
|
||||
|
||||
void handleBuddyChanged() {
|
||||
User *user = userManager->getUser("user@localhost");
|
||||
CPPUNIT_ASSERT(user);
|
||||
|
||||
std::vector<std::string> grp;
|
||||
grp.push_back("group1");
|
||||
LocalBuddy *buddy = new LocalBuddy(user->getRosterManager(), -1, "buddy1", "Buddy 1", grp, BUDDY_JID_ESCAPING);
|
||||
buddy->setStatus(Swift::StatusShow(Swift::StatusShow::Away), "status1");
|
||||
user->getRosterManager()->setBuddy(buddy);
|
||||
received.clear();
|
||||
|
||||
buddy->handleBuddyChanged();
|
||||
CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
|
||||
CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[0])));
|
||||
CPPUNIT_ASSERT_EQUAL(Swift::StatusShow::Away, dynamic_cast<Swift::Presence *>(getStanza(received[0]))->getShow());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("status1"), dynamic_cast<Swift::Presence *>(getStanza(received[0]))->getStatus());
|
||||
}
|
||||
|
||||
void disconnectUser() {
|
||||
userManager->disconnectUser("user@localhost");
|
||||
dynamic_cast<Swift::DummyTimerFactory *>(factories->getTimerFactory())->setTime(10);
|
||||
loop->processEvents();
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(0, userManager->getUserCount());
|
||||
CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
|
||||
CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[0])));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION (LocalBuddyTest);
|
|
@ -71,23 +71,15 @@ class RosterManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
|
|||
User *user = userManager->getUser("user@localhost");
|
||||
CPPUNIT_ASSERT(user);
|
||||
|
||||
LocalBuddy *buddy = new LocalBuddy(user->getRosterManager(), -1);
|
||||
buddy->setFlags(BUDDY_JID_ESCAPING);
|
||||
buddy->setName("buddy1");
|
||||
buddy->setAlias("Buddy 1");
|
||||
std::vector<std::string> grp;
|
||||
grp.push_back("group1");
|
||||
buddy->setGroups(grp);
|
||||
LocalBuddy *buddy = new LocalBuddy(user->getRosterManager(), -1, "buddy1", "Buddy 1", grp, BUDDY_JID_ESCAPING);
|
||||
buddy->setStatus(Swift::StatusShow(Swift::StatusShow::Away), "status1");
|
||||
user->getRosterManager()->setBuddy(buddy);
|
||||
|
||||
buddy = new LocalBuddy(user->getRosterManager(), -1);
|
||||
buddy->setFlags(BUDDY_JID_ESCAPING);
|
||||
buddy->setName("buddy2");
|
||||
buddy->setAlias("Buddy 2");
|
||||
std::vector<std::string> grp2;
|
||||
grp2.push_back("group2");
|
||||
buddy->setGroups(grp2);
|
||||
buddy = new LocalBuddy(user->getRosterManager(), -1, "buddy2", "Buddy 2", grp2, BUDDY_JID_ESCAPING);
|
||||
buddy->setStatus(Swift::StatusShow(Swift::StatusShow::Away), "status2");
|
||||
user->getRosterManager()->setBuddy(buddy);
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ class UserTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
|
|||
void handleUserCreated(User *user) {
|
||||
user->onReadyToConnect.connect(boost::bind(&UserTest::handleUserReadyToConnect, this, user));
|
||||
user->onPresenceChanged.connect(boost::bind(&UserTest::handleUserPresenceChanged, this, user, _1));
|
||||
user->onRoomJoined.connect(boost::bind(&UserTest::handleRoomJoined, this, user, _1, _2, _3));
|
||||
user->onRoomJoined.connect(boost::bind(&UserTest::handleRoomJoined, this, user, _1, _2, _3, _4));
|
||||
user->onRoomLeft.connect(boost::bind(&UserTest::handleRoomLeft, this, user, _1));
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ class UserTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
|
|||
changedPresence = presence;
|
||||
}
|
||||
|
||||
void handleRoomJoined(User *user, const std::string &r, const std::string &nickname, const std::string &password) {
|
||||
void handleRoomJoined(User *user, const std::string &jid, const std::string &r, const std::string &nickname, const std::string &password) {
|
||||
room = r;
|
||||
roomNickname = nickname;
|
||||
roomPassword = password;
|
||||
|
@ -172,7 +172,7 @@ class UserTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
|
|||
|
||||
void handleDisconnected() {
|
||||
User *user = userManager->getUser("user@localhost");
|
||||
user->handleDisconnected("Connection error");
|
||||
user->handleDisconnected("Connection error", Swift::SpectrumErrorPayload::CONNECTION_ERROR_AUTHENTICATION_FAILED);
|
||||
loop->processEvents();
|
||||
|
||||
CPPUNIT_ASSERT(streamEnded);
|
||||
|
|
|
@ -204,7 +204,9 @@ void Component::start() {
|
|||
|
||||
//Type casting to BoostConnectionServer since onStopped signal is not defined in ConnectionServer
|
||||
//Ideally, onStopped must be defined in ConnectionServer
|
||||
boost::dynamic_pointer_cast<Swift::BoostConnectionServer>(m_server->getConnectionServer())->onStopped.connect(boost::bind(&Component::handleServerStopped, this, _1));
|
||||
if (boost::dynamic_pointer_cast<Swift::BoostConnectionServer>(m_server->getConnectionServer())) {
|
||||
boost::dynamic_pointer_cast<Swift::BoostConnectionServer>(m_server->getConnectionServer())->onStopped.connect(boost::bind(&Component::handleServerStopped, this, _1));
|
||||
}
|
||||
|
||||
// We're connected right here, because we're in server mode...
|
||||
handleConnected();
|
||||
|
|
|
@ -179,6 +179,7 @@ void User::setConnected(bool connected) {
|
|||
}
|
||||
|
||||
void User::handlePresence(Swift::Presence::ref presence) {
|
||||
|
||||
int currentResourcesCount = m_presenceOracle->getAllPresence(m_jid).size();
|
||||
|
||||
m_conversationManager->resetResources();
|
||||
|
|
Loading…
Add table
Reference in a new issue