Files
@ bd4b3bcd1d4e
Branch filter:
Location: libtransport.git/src/tests/basictest.h - annotation
bd4b3bcd1d4e
4.0 KiB
text/plain
Merge branch 'master' of https://github.com/hanzz/libtransport
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 3949b84ed027 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 04cbb3a90713 9e05a8dffbe8 04cbb3a90713 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 848f672b07e5 | /**
* libtransport -- C++ library for easy XMPP Transports development
*
* Copyright (C) 2011, Jan Kaluza <hanzz.k@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/
#pragma once
#include <vector>
#include "Swiften/Swiften.h"
#include "Swiften/Queries/SetResponder.h"
#include "transport/conversation.h"
#include "transport/conversationmanager.h"
#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 <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"
using namespace Transport;
class TestingConversation : public Conversation {
public:
TestingConversation(ConversationManager *conversationManager, const std::string &legacyName, bool muc = false) : Conversation(conversationManager, legacyName, muc) {
}
// Called when there's new message to legacy network from XMPP network
void sendMessage(boost::shared_ptr<Swift::Message> &message) {
}
};
class TestingFactory : public Factory {
public:
TestingFactory() {
}
// Creates new conversation (NetworkConversation in this case)
Conversation *createConversation(ConversationManager *conversationManager, const std::string &legacyName) {
Conversation *nc = new TestingConversation(conversationManager, legacyName);
return nc;
}
// 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);
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;
}
};
class BasicTest : public Swift::XMPPParserClient {
public:
void setMeUp (void);
void tearMeDown (void);
void handleDataReceived(const Swift::SafeByteArray &data);
void handleStreamStart(const Swift::ProtocolHeader&);
void handleElement(boost::shared_ptr<Swift::Element> element);
void handleStreamEnd();
void injectPresence(boost::shared_ptr<Swift::Presence> &response);
void injectIQ(boost::shared_ptr<Swift::IQ> iq);
Swift::Stanza *getStanza(boost::shared_ptr<Swift::Element> element);
protected:
bool streamEnded;
UserManager *userManager;
boost::shared_ptr<Swift::ServerFromClientSession> serverFromClientSession;
Swift::FullPayloadSerializerCollection* payloadSerializers;
Swift::FullPayloadParserFactoryCollection* payloadParserFactories;
Swift::XMPPParser *parser;
UserRegistry *userRegistry;
Config *cfg;
Swift::Server *server;
Swift::DummyNetworkFactories *factories;
Swift::DummyEventLoop *loop;
TestingFactory *factory;
Component *component;
std::vector<boost::shared_ptr<Swift::Element> > received;
};
|