Changeset - 26fc8a0323bb
[Not reviewed]
0 9 0
Jan Kaluza - 10 years ago 2016-02-15 09:57:25
jkaluza@redhat.com
Fix compilation with Swiften 3.0-rc2. This is now the minimal Swiften 3 version to compile with. Compilation with Swiften 2 is still supported.
9 files changed with 129 insertions and 68 deletions:
0 comments (0 inline, 0 general)
libtransport/AdminInterface.cpp
Show inline comments
 
@@ -30,12 +30,15 @@
 
#include "transport/MemoryUsage.h"
 
#include "transport/Config.h"
 

	
 
#include <boost/foreach.hpp>
 
#include <boost/lexical_cast.hpp>
 

	
 
#include <Swiften/Version.h>
 
#define HAVE_SWIFTEN_3  (SWIFTEN_VERSION >= 0x030000)
 

	
 
namespace Transport {
 

	
 
DEFINE_LOGGER(logger, "AdminInterface");
 

	
 
static std::string getArg(const std::string &body) {
 
	std::string ret;
 
@@ -57,50 +60,55 @@ AdminInterface::AdminInterface(Component *component, UserManager *userManager, N
 
}
 

	
 
AdminInterface::~AdminInterface() {
 
}
 

	
 
void AdminInterface::handleQuery(Swift::Message::ref message) {
 
	LOG4CXX_INFO(logger, "Message from admin received: '" << message->getBody() << "'");
 
#if HAVE_SWIFTEN_3
 
	std::string msg = message->getBody().value_or("");
 
#else
 
	std::string msg = message->getBody();
 
#endif
 
	LOG4CXX_INFO(logger, "Message from admin received: '" << msg << "'");
 
	message->setTo(message->getFrom());
 
	message->setFrom(m_component->getJID());
 

	
 
	if (message->getBody() == "status") {
 
	if (msg == "status") {
 
		int users = m_userManager->getUserCount();
 
		int backends = m_server->getBackendCount();
 
		message->setBody("Running (" + boost::lexical_cast<std::string>(users) + " users connected using " + boost::lexical_cast<std::string>(backends) + " backends)");
 
	}
 
	else if (message->getBody() == "uptime") {
 
	else if (msg == "uptime") {
 
		message->setBody(boost::lexical_cast<std::string>(time(0) - m_start));
 
	}
 
	else if (message->getBody() == "online_users") {
 
	else if (msg == "online_users") {
 
		std::string lst;
 
		const std::map<std::string, User *> &users = m_userManager->getUsers();
 
		if (users.size() == 0)
 
			lst = "0";
 

	
 
		for (std::map<std::string, User *>::const_iterator it = users.begin(); it != users.end(); it ++) {
 
			lst += (*it).first + "\n";
 
		}
 

	
 
		message->setBody(lst);
 
	}
 
	else if (message->getBody() == "online_users_count") {
 
	else if (msg == "online_users_count") {
 
		int users = m_userManager->getUserCount();
 
		message->setBody(boost::lexical_cast<std::string>(users));
 
	}
 
	else if (message->getBody() == "reload") {
 
	else if (msg == "reload") {
 
		bool done = m_component->getConfig()->reload();
 
		if (done) {
 
			message->setBody("Config reloaded");
 
		}
 
		else {
 
			message->setBody("Error during config reload");
 
		}
 
	}
 
	else if (message->getBody() == "online_users_per_backend") {
 
	else if (msg == "online_users_per_backend") {
 
		std::string lst;
 
		int id = 1;
 

	
 
		const std::list <NetworkPluginServer::Backend *> &backends = m_server->getBackends();
 
		for (std::list <NetworkPluginServer::Backend *>::const_iterator b = backends.begin(); b != backends.end(); b++) {
 
			NetworkPluginServer::Backend *backend = *b;
 
@@ -122,57 +130,57 @@ void AdminInterface::handleQuery(Swift::Message::ref message) {
 
			}
 
			id++;
 
		}
 

	
 
		message->setBody(lst);
 
	}
 
	else if (message->getBody().find("has_online_user") == 0) {
 
		User *user = m_userManager->getUser(getArg(message->getBody()));
 
		std::cout << getArg(message->getBody()) << "\n";
 
	else if (msg.find("has_online_user") == 0) {
 
		User *user = m_userManager->getUser(getArg(msg));
 
		std::cout << getArg(msg) << "\n";
 
		message->setBody(boost::lexical_cast<std::string>(user != NULL));
 
	}
 
	else if (message->getBody() == "backends_count") {
 
	else if (msg == "backends_count") {
 
		int backends = m_server->getBackendCount();
 
		message->setBody(boost::lexical_cast<std::string>(backends));
 
	}
 
	else if (message->getBody() == "res_memory") {
 
	else if (msg == "res_memory") {
 
		double shared = 0;
 
		double rss = 0;
 
		process_mem_usage(shared, rss);
 
		const std::list <NetworkPluginServer::Backend *> &backends = m_server->getBackends();
 
		BOOST_FOREACH(NetworkPluginServer::Backend * backend, backends) {
 
			rss += backend->res;
 
		}
 

	
 
		message->setBody(boost::lexical_cast<std::string>(rss));
 
	}
 
	else if (message->getBody() == "shr_memory") {
 
	else if (msg == "shr_memory") {
 
		double shared = 0;
 
		double rss = 0;
 
		process_mem_usage(shared, rss);
 
		const std::list <NetworkPluginServer::Backend *> &backends = m_server->getBackends();
 
		BOOST_FOREACH(NetworkPluginServer::Backend * backend, backends) {
 
			shared += backend->shared;
 
		}
 

	
 
		message->setBody(boost::lexical_cast<std::string>(shared));
 
	}
 
	else if (message->getBody() == "used_memory") {
 
	else if (msg == "used_memory") {
 
		double shared = 0;
 
		double rss = 0;
 
		process_mem_usage(shared, rss);
 
		rss -= shared;
 

	
 
		const std::list <NetworkPluginServer::Backend *> &backends = m_server->getBackends();
 
		BOOST_FOREACH(NetworkPluginServer::Backend * backend, backends) {
 
			rss += backend->res - backend->shared;
 
		}
 

	
 
		message->setBody(boost::lexical_cast<std::string>(rss));
 
	}
 
	else if (message->getBody() == "average_memory_per_user") {
 
	else if (msg == "average_memory_per_user") {
 
		if (m_userManager->getUserCount() == 0) {
 
			message->setBody(boost::lexical_cast<std::string>(0));
 
		}
 
		else {
 
			unsigned long per_user = 0;
 
			const std::list <NetworkPluginServer::Backend *> &backends = m_server->getBackends();
 
@@ -182,46 +190,46 @@ void AdminInterface::handleQuery(Swift::Message::ref message) {
 
				}
 
			}
 

	
 
			message->setBody(boost::lexical_cast<std::string>(per_user / m_userManager->getUserCount()));
 
		}
 
	}
 
	else if (message->getBody() == "res_memory_per_backend") {
 
	else if (msg == "res_memory_per_backend") {
 
		std::string lst;
 
		int id = 1;
 
		const std::list <NetworkPluginServer::Backend *> &backends = m_server->getBackends();
 
		BOOST_FOREACH(NetworkPluginServer::Backend * backend, backends) {
 
			lst += "Backend " + boost::lexical_cast<std::string>(id) + " (ID=" + backend->id + "): " + boost::lexical_cast<std::string>(backend->res) + "\n";
 
			id++;
 
		}
 

	
 
		message->setBody(lst);
 
	}
 
	else if (message->getBody() == "shr_memory_per_backend") {
 
	else if (msg == "shr_memory_per_backend") {
 
		std::string lst;
 
		int id = 1;
 
		const std::list <NetworkPluginServer::Backend *> &backends = m_server->getBackends();
 
		BOOST_FOREACH(NetworkPluginServer::Backend * backend, backends) {
 
			lst += "Backend " + boost::lexical_cast<std::string>(id)  + " (ID=" + backend->id + "): " + boost::lexical_cast<std::string>(backend->shared) + "\n";
 
			id++;
 
		}
 

	
 
		message->setBody(lst);
 
	}
 
	else if (message->getBody() == "used_memory_per_backend") {
 
	else if (msg == "used_memory_per_backend") {
 
		std::string lst;
 
		int id = 1;
 
		const std::list <NetworkPluginServer::Backend *> &backends = m_server->getBackends();
 
		BOOST_FOREACH(NetworkPluginServer::Backend * backend, backends) {
 
			lst += "Backend " + boost::lexical_cast<std::string>(id)  + " (ID=" + backend->id + "): " + boost::lexical_cast<std::string>(backend->res - backend->shared) + "\n";
 
			id++;
 
		}
 

	
 
		message->setBody(lst);
 
	}
 
	else if (message->getBody() == "average_memory_per_user_per_backend") {
 
	else if (msg == "average_memory_per_user_per_backend") {
 
		std::string lst;
 
		int id = 1;
 
		const std::list <NetworkPluginServer::Backend *> &backends = m_server->getBackends();
 
		BOOST_FOREACH(NetworkPluginServer::Backend * backend, backends) {
 
			if (backend->users.size() == 0 || backend->res < backend->init_res) {
 
				lst += "Backend " + boost::lexical_cast<std::string>(id)  + " (ID=" + backend->id + "): 0\n";
 
@@ -231,36 +239,36 @@ void AdminInterface::handleQuery(Swift::Message::ref message) {
 
			}
 
			id++;
 
		}
 

	
 
		message->setBody(lst);
 
	}
 
	else if (message->getBody() == "collect_backend") {
 
	else if (msg == "collect_backend") {
 
		m_server->collectBackend();
 
	}
 
	else if (message->getBody() == "crashed_backends") {
 
	else if (msg == "crashed_backends") {
 
		std::string lst;
 
		const std::vector<std::string> &backends = m_server->getCrashedBackends();
 
		BOOST_FOREACH(const std::string &backend, backends) {
 
			lst += backend + "\n";
 
		}
 
		message->setBody(lst);
 
	}
 
	else if (message->getBody() == "crashed_backends_count") {
 
	else if (msg == "crashed_backends_count") {
 
		message->setBody(boost::lexical_cast<std::string>(m_server->getCrashedBackends().size()));
 
	}
 
	else if (message->getBody() == "messages_from_xmpp") {
 
	else if (msg == "messages_from_xmpp") {
 
		int msgCount = m_userManager->getMessagesToBackend();
 
		message->setBody(boost::lexical_cast<std::string>(msgCount));
 
	}
 
	else if (message->getBody() == "messages_to_xmpp") {
 
	else if (msg == "messages_to_xmpp") {
 
		int msgCount = m_userManager->getMessagesToXMPP();
 
		message->setBody(boost::lexical_cast<std::string>(msgCount));
 
	}
 
	else if (message->getBody().find("register ") == 0 && m_userRegistration) {
 
		std::string body = message->getBody();
 
	else if (msg.find("register ") == 0 && m_userRegistration) {
 
		std::string body = msg;
 
		std::vector<std::string> args;
 
		boost::split(args, body, boost::is_any_of(" "));
 
		if (args.size() == 4) {
 
			UserInfo res;
 
			res.jid = args[1];
 
			res.uin = args[2];
 
@@ -277,14 +285,14 @@ void AdminInterface::handleQuery(Swift::Message::ref message) {
 
			}
 
		}
 
		else {
 
			message->setBody("Bad argument count. See 'help'.");
 
		}
 
	}
 
	else if (message->getBody().find("unregister ") == 0 && m_userRegistration) {
 
		std::string body = message->getBody();
 
	else if (msg.find("unregister ") == 0 && m_userRegistration) {
 
		std::string body = msg;
 
		std::vector<std::string> args;
 
		boost::split(args, body, boost::is_any_of(" "));
 
		if (args.size() == 2) {
 
			if (m_userRegistration->unregisterUser(args[1])) {
 
				message->setBody("User '" + args[1] + "' unregistered.");
 
			}
 
@@ -293,14 +301,14 @@ void AdminInterface::handleQuery(Swift::Message::ref message) {
 
			}
 
		}
 
		else {
 
			message->setBody("Bad argument count. See 'help'.");
 
		}
 
	}
 
	else if (message->getBody().find("set_oauth2_code ") == 0) {
 
		std::string body = message->getBody();
 
	else if (msg.find("set_oauth2_code ") == 0) {
 
		std::string body = msg;
 
		std::vector<std::string> args;
 
		boost::split(args, body, boost::is_any_of(" "));
 
		if (args.size() == 3) {
 
			std::string error = m_component->getFrontend()->setOAuth2Code(args[1], args[2]);
 
			if (error.empty()) {
 
				message->setBody("OAuth2 code and state set.");
 
@@ -310,27 +318,27 @@ void AdminInterface::handleQuery(Swift::Message::ref message) {
 
			}
 
		}
 
		else {
 
			message->setBody("Bad argument count. See 'help'.");
 
		}
 
	}
 
	else if (message->getBody().find("get_oauth2_url") == 0) {
 
		std::string body = message->getBody();
 
	else if (msg.find("get_oauth2_url") == 0) {
 
		std::string body = msg;
 
		std::vector<std::string> args;
 
		boost::split(args, body, boost::is_any_of(" "));
 
		std::string url = m_component->getFrontend()->getOAuth2URL(args);
 
		message->setBody(url);
 
	}
 
	else if (message->getBody() == "registration_fields") {
 
	else if (msg == "registration_fields") {
 
		std::string fields = m_component->getFrontend()->getRegistrationFields();
 
		message->setBody(fields);
 
	}
 
	else if (m_component->getFrontend()->handleAdminMessage(message)) {
 
		LOG4CXX_INFO(logger, "Message handled by frontend");
 
	}
 
	else if (message->getBody().find("help") == 0) {
 
	else if (msg.find("help") == 0) {
 
		std::string help;
 
		help += "General:\n";
 
		help += "    status - shows instance status\n";
 
		help += "    reload - Reloads config file\n";
 
		help += "    uptime - returns ptime in seconds\n";
 
		help += "Users:\n";
 
@@ -362,13 +370,13 @@ void AdminInterface::handleQuery(Swift::Message::ref message) {
 
		help += "    average_memory_per_user_per_backend - (memory_used_without_any_user - res_memory) per backend\n";
 
		
 
		
 
		message->setBody(help);
 
	}
 
	else {
 
		message->setBody("Unknown command \"" + message->getBody() + "\". Try \"help\"");
 
		message->setBody("Unknown command \"" + msg + "\". Try \"help\"");
 
	}
 
}
 

	
 
void AdminInterface::handleMessageReceived(Swift::Message::ref message) {
 
	if (!message->getTo().getNode().empty())
 
		return;
 
@@ -378,15 +386,21 @@ void AdminInterface::handleMessageReceived(Swift::Message::ref message) {
 
	    LOG4CXX_WARN(logger, "Message not from admin user, but from " << message->getFrom().toBare().toString());
 
	    return;
 
	
 
	}
 
	
 
	// Ignore empty messages
 
#if HAVE_SWIFTEN_3
 
	if (message->getBody().value_or("").empty()) {
 
		return;
 
	}
 
#else
 
	if (message->getBody().empty()) {
 
		return;
 
	}
 
#endif
 

	
 
	handleQuery(message);
 

	
 
	m_component->getFrontend()->sendMessage(message);
 
}
 

	
libtransport/NetworkPluginServer.cpp
Show inline comments
 
@@ -967,13 +967,17 @@ void NetworkPluginServer::handleQueryPayload(Backend *b, const std::string &data
 

	
 
	boost::shared_ptr<Swift::Message> msg(new Swift::Message());
 
	msg->setBody(payload.config());
 
	m_adminInterface->handleQuery(msg);
 

	
 
	pbnetwork::BackendConfig response;
 
#if HAVE_SWIFTEN_3
 
	response.set_config(msg->getBody().value_or(""));
 
#else
 
	response.set_config(msg->getBody());
 
#endif
 

	
 
	std::string message;
 
	response.SerializeToString(&message);
 

	
 
	WRAP(message, pbnetwork::WrapperMessage_Type_TYPE_QUERY);
 

	
 
@@ -1689,13 +1693,17 @@ void NetworkPluginServer::handleMessageReceived(NetworkConversation *conv, boost
 

	
 
	boost::shared_ptr<Swift::AttentionPayload> attentionPayload = msg->getPayload<Swift::AttentionPayload>();
 
	if (attentionPayload) {
 
		pbnetwork::ConversationMessage m;
 
		m.set_username(conv->getConversationManager()->getUser()->getJID().toBare());
 
		m.set_buddyname(conv->getLegacyName());
 
#if HAVE_SWIFTEN_3
 
		m.set_message(msg->getBody().value_or(""));
 
#else
 
		m.set_message(msg->getBody());
 
#endif
 

	
 
		std::string message;
 
		m.SerializeToString(&message);
 

	
 
		WRAP(message, pbnetwork::WrapperMessage_Type_TYPE_ATTENTION);
 

	
 
@@ -1725,17 +1733,22 @@ void NetworkPluginServer::handleMessageReceived(NetworkConversation *conv, boost
 
	boost::shared_ptr<Swift::XHTMLIMPayload> xhtmlPayload = msg->getPayload<Swift::XHTMLIMPayload>();
 
	if (xhtmlPayload) {
 
		xhtml = xhtmlPayload->getBody();
 
	}
 

	
 
	// Send normal message
 
	if (!msg->getBody().empty() || !xhtml.empty()) {
 
#if HAVE_SWIFTEN_3
 
	std::string body = msg->getBody().value_or("");
 
#else
 
	std::string body = msg->getBody();
 
#endif
 
	if (!body.empty() || !xhtml.empty()) {
 
		pbnetwork::ConversationMessage m;
 
		m.set_username(conv->getConversationManager()->getUser()->getJID().toBare());
 
		m.set_buddyname(conv->getLegacyName());
 
		m.set_message(msg->getBody());
 
		m.set_message(body);
 
		m.set_xhtml(xhtml);
 
		boost::shared_ptr<Swift::DeliveryReceiptRequest> receiptPayload = msg->getPayload<Swift::DeliveryReceiptRequest>();
 
		if (receiptPayload && !msg->getID().empty()) {
 
			m.set_id(msg->getID());
 
		}
 

	
libtransport/UserManager.cpp
Show inline comments
 
@@ -371,13 +371,18 @@ void UserManager::handleMessageReceived(Swift::Message::ref message) {
 
	// Do not count chatstate notification...
 
	boost::shared_ptr<Swift::ChatState> statePayload = message->getPayload<Swift::ChatState>();
 
	if (!statePayload) {
 
		messageToBackendSent();
 
	}
 

	
 
	if (message->getBody().empty() && !statePayload && message->getSubject().empty()) {
 
#if HAVE_SWIFTEN_3
 
	std::string body = message->getBody().value_or("");
 
#else
 
	std::string body = message->getBody();
 
#endif
 
	if (body.empty() && !statePayload && message->getSubject().empty()) {
 
		return;
 
	}
 

	
 
	User *user = getUser(message->getFrom().toBare().toString());
 
	if (!user){
 
		return;
spectrum/src/frontends/slack/SlackSession.cpp
Show inline comments
 
@@ -36,12 +36,14 @@
 
#include <boost/foreach.hpp>
 
#include <boost/make_shared.hpp>
 
#include <boost/lexical_cast.hpp>
 
#include <boost/algorithm/string.hpp>
 

	
 
#include "Swiften/Elements/MUCPayload.h"
 
#include <Swiften/Version.h>
 
#define HAVE_SWIFTEN_3  (SWIFTEN_VERSION >= 0x030000)
 

	
 
#include <map>
 
#include <iterator>
 

	
 
namespace Transport {
 

	
 
@@ -145,13 +147,18 @@ void SlackSession::sendMessage(boost::shared_ptr<Swift::Message> message) {
 
		if (m_user && (b = m_user->getRosterManager()->getBuddy(from)) != NULL) {
 
			from = b->getAlias() + " (" + from + ")";
 
		}
 
	}
 

	
 
	LOG4CXX_INFO(logger, m_uinfo.jid << "Sending message to Slack channel " << channel << " from " << from);
 
	m_rtm->getAPI()->sendMessage(from, channel, message->getBody());
 
#if HAVE_SWIFTEN_3
 
	std::string body = message->getBody().value_or("");
 
#else
 
	std::string body = message->getBody();
 
#endif
 
	m_rtm->getAPI()->sendMessage(from, channel, body);
 
}
 

	
 
void SlackSession::setPurpose(const std::string &purpose, const std::string &channel) {
 
	std::string ch = channel;
 
	if (ch.empty()) {
 
		ch = m_slackChannel;
spectrum/src/frontends/slack/SlackUserManager.cpp
Show inline comments
 
@@ -29,12 +29,15 @@
 
#include "transport/StorageBackend.h"
 
#include "transport/Logging.h"
 

	
 
#include <boost/algorithm/string.hpp>
 
#include <boost/foreach.hpp>
 

	
 
#include <Swiften/Version.h>
 
#define HAVE_SWIFTEN_3  (SWIFTEN_VERSION >= 0x030000)
 

	
 
namespace Transport {
 

	
 
DEFINE_LOGGER(logger, "SlackUserManager");
 

	
 
SlackUserManager::SlackUserManager(Component *component, UserRegistry *userRegistry, StorageBackend *storageBackend) : UserManager(component, userRegistry, storageBackend) {
 
	m_component = component;
 
@@ -103,14 +106,19 @@ std::string SlackUserManager::getOAuth2URL(const std::vector<std::string> &args)
 
void SlackUserManager::handleUserCreated(User *user) {
 
	LOG4CXX_INFO(logger, "handleUserCreated");
 
	static_cast<SlackUser *>(user)->getSession()->handleConnected();
 
}
 

	
 
bool SlackUserManager::handleAdminMessage(Swift::Message::ref message) {
 
	if (message->getBody().find("list_rooms") == 0) {
 
		std::string body = message->getBody();
 
#if HAVE_SWIFTEN_3
 
	std::string body = message->getBody().value_or("");
 
#else
 
	std::string body = message->getBody();
 
#endif
 

	
 
	if (body.find("list_rooms") == 0) {
 
		std::vector<std::string> args;
 
		boost::split(args, body, boost::is_any_of(" "));
 
		if (args.size() == 2) {
 
			UserInfo uinfo;
 
			if (!m_storageBackend->getUser(args[1], uinfo)) {
 
				message->setBody("Error: Unknown user");
 
@@ -122,39 +130,37 @@ bool SlackUserManager::handleAdminMessage(Swift::Message::ref message) {
 
			m_storageBackend->getUserSetting(uinfo.id, "rooms", type, rooms);
 

	
 
			message->setBody(rooms);
 
			return true;
 
		}
 
	}
 
	else if (message->getBody().find("join_room ") == 0) {
 
		std::string body = message->getBody();
 
	else if (body.find("join_room ") == 0) {
 
		std::vector<std::string> args;
 
		boost::split(args, body, boost::is_any_of(" "));
 
		if (args.size() == 6) {
 
			UserInfo uinfo;
 
			if (!m_storageBackend->getUser(args[1], uinfo)) {
 
				message->setBody("Error: Unknown user");
 
				return true;
 
			}
 

	
 
			std::string rooms = "";
 
			int type = (int) TYPE_STRING;
 
			m_storageBackend->getUserSetting(uinfo.id, "rooms", type, rooms);
 
			rooms += message->getBody() + "\n";
 
			rooms += body + "\n";
 
			m_storageBackend->updateUserSetting(uinfo.id, "rooms", rooms);
 

	
 
			SlackUser *user = static_cast<SlackUser *>(getUser(args[1]));
 
			if (user) {
 
				user->getSession()->handleJoinMessage("", args, true);
 
			}
 
			message->setBody("Joined the room");
 
			return true;
 
		}
 
	}
 
	else if (message->getBody().find("leave_room ") == 0) {
 
		std::string body = message->getBody();
 
	else if (body.find("leave_room ") == 0) {
 
		std::vector<std::string> args;
 
		boost::split(args, body, boost::is_any_of(" "));
 
		if (args.size() == 3) {
 
			UserInfo uinfo;
 
			if (!m_storageBackend->getUser(args[1], uinfo)) {
 
				message->setBody("Error: Unknown user");
tests/libtransport/conversationmanager.cpp
Show inline comments
 
@@ -10,12 +10,16 @@
 
#include "Swiften/Server/ServerFromClientSession.h"
 
#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h"
 
#include "basictest.h"
 

	
 
using namespace Transport;
 

	
 
#if !HAVE_SWIFTEN_3
 
#define value_or(X) substr()
 
#endif
 

	
 
class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
	CPPUNIT_TEST_SUITE(ConversationManagerTest);
 
	CPPUNIT_TEST(conversationSize);
 
	CPPUNIT_TEST(handleNormalMessages);
 
	CPPUNIT_TEST(handleNormalMessagesInitiatedFromXMPP);
 
	CPPUNIT_TEST(handleNormalMessagesHeadline);
 
@@ -154,13 +158,13 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
 
		// Forward it
 
		conv->handleMessage(msg);
 
		loop->processEvents();
 
		
 
		CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[0])));
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there<>!"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getBody());
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there<>!"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getBody().value_or(""));
 
		CPPUNIT_ASSERT_EQUAL(std::string("user@localhost"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getTo().toString());
 
		CPPUNIT_ASSERT_EQUAL(std::string("buddy1\\40test@localhost/bot"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getFrom().toString());
 
		
 
		received.clear();
 

	
 
		// send response
 
@@ -169,25 +173,25 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
 
		msg->setBody("response<>!");
 
		injectMessage(msg);
 
		loop->processEvents();
 
		
 
		CPPUNIT_ASSERT_EQUAL(0, (int) received.size());
 
		CPPUNIT_ASSERT(m_msg);
 
		CPPUNIT_ASSERT_EQUAL(std::string("response<>!"), m_msg->getBody());
 
		CPPUNIT_ASSERT_EQUAL(std::string("response<>!"), m_msg->getBody().value_or(""));
 

	
 
		// send another message from legacy network, should be sent to user@localhost/resource now
 
		boost::shared_ptr<Swift::Message> msg2(new Swift::Message());
 
		msg2->setBody("hi there!");
 

	
 
		// Forward it
 
		conv->handleMessage(msg2);
 
		loop->processEvents();
 

	
 
		CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[0])));
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there!"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getBody());
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there!"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getBody().value_or(""));
 
		CPPUNIT_ASSERT_EQUAL(std::string("user@localhost/resource"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getTo().toString());
 
		CPPUNIT_ASSERT_EQUAL(std::string("buddy1\\40test@localhost/bot"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getFrom().toString());
 
		
 
		received.clear();
 

	
 
		// disable jid_escaping
 
@@ -202,13 +206,13 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
 
		// enable jid_escaping again
 
		std::istringstream ifs2("service.server_mode = 1\nservice.jid_escaping=1\nservice.jid=localhost\nservice.more_resources=1\n");
 
		cfg->load(ifs2);
 
		
 
		CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[0])));
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there!"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getBody());
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there!"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getBody().value_or(""));
 
		CPPUNIT_ASSERT_EQUAL(std::string("user@localhost"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getTo().toString());
 
		CPPUNIT_ASSERT_EQUAL(std::string("buddy1%test@localhost/bot"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getFrom().toString());
 
		
 
		received.clear();
 
	}
 

	
 
@@ -223,13 +227,13 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
 

	
 
		// Forward it
 
		loop->processEvents();
 
		
 
		CPPUNIT_ASSERT_EQUAL(0, (int) received.size());
 
		CPPUNIT_ASSERT(m_msg);
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there<>!"), m_msg->getBody());
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there<>!"), m_msg->getBody().value_or(""));
 
		CPPUNIT_ASSERT_EQUAL(std::string("BuddY1"), m_conv->getLegacyName());
 
		
 
		TestingConversation *conv = (TestingConversation *) user->getConversationManager()->getConversation("BuddY1");
 
		CPPUNIT_ASSERT(conv);
 
		CPPUNIT_ASSERT_EQUAL(std::string("BuddY1"), conv->getLegacyName());
 
	}
 
@@ -250,26 +254,26 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
 
		conv->handleMessage(msg);
 
		loop->processEvents();
 
		
 
		CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[0])));
 
		CPPUNIT_ASSERT_EQUAL(Swift::Message::Headline, dynamic_cast<Swift::Message *>(getStanza(received[0]))->getType());
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there<>!"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getBody());
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there<>!"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getBody().value_or(""));
 
		CPPUNIT_ASSERT_EQUAL(std::string("user@localhost"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getTo().toString());
 
		CPPUNIT_ASSERT_EQUAL(std::string("buddy1\\40test@localhost/bot"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getFrom().toString());
 

	
 
		received.clear();
 
		user->addUserSetting("send_headlines", "0");
 
		// Forward it
 
		conv->handleMessage(msg);
 
		loop->processEvents();
 

	
 
		CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[0])));
 
		CPPUNIT_ASSERT_EQUAL(Swift::Message::Chat, dynamic_cast<Swift::Message *>(getStanza(received[0]))->getType());
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there<>!"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getBody());
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there<>!"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getBody().value_or(""));
 
		CPPUNIT_ASSERT_EQUAL(std::string("user@localhost"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getTo().toString());
 
		CPPUNIT_ASSERT_EQUAL(std::string("buddy1\\40test@localhost/bot"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getFrom().toString());
 

	
 
		received.clear();
 
		msg->setType(Swift::Message::Chat);
 
		user->addUserSetting("send_headlines", "1");
 
@@ -277,13 +281,13 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
 
		conv->handleMessage(msg);
 
		loop->processEvents();
 

	
 
		CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[0])));
 
		CPPUNIT_ASSERT_EQUAL(Swift::Message::Chat, dynamic_cast<Swift::Message *>(getStanza(received[0]))->getType());
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there<>!"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getBody());
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there<>!"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getBody().value_or(""));
 
		CPPUNIT_ASSERT_EQUAL(std::string("user@localhost"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getTo().toString());
 
		CPPUNIT_ASSERT_EQUAL(std::string("buddy1\\40test@localhost/bot"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getFrom().toString());
 
	}
 

	
 
	void handleGroupchatMessages() {
 
		User *user = userManager->getUser("user@localhost");
 
@@ -302,13 +306,13 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
 
		// Forward it
 
		conv->handleMessage(msg, "anotheruser");
 

	
 
		loop->processEvents();
 
		CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[0])));
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there!"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getBody());
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there!"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getBody().value_or(""));
 
		CPPUNIT_ASSERT_EQUAL(std::string("user@localhost/resource"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getTo().toString());
 
		CPPUNIT_ASSERT_EQUAL(std::string("#room@localhost/anotheruser"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getFrom().toString());
 

	
 
		received.clear();
 

	
 
		// send response
 
@@ -318,13 +322,13 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
 
		msg->setType(Swift::Message::Groupchat);
 
		injectMessage(msg);
 
		loop->processEvents();
 
		
 
		CPPUNIT_ASSERT_EQUAL(0, (int) received.size());
 
		CPPUNIT_ASSERT(m_msg);
 
		CPPUNIT_ASSERT_EQUAL(std::string("response!"), m_msg->getBody());
 
		CPPUNIT_ASSERT_EQUAL(std::string("response!"), m_msg->getBody().value_or(""));
 
	}
 

	
 
	void handleGroupchatMessagesAlias() {
 
		User *user = userManager->getUser("user@localhost");
 
		TestingConversation *conv = new TestingConversation(user->getConversationManager(), "#room", true);
 
		user->getConversationManager()->addConversation(conv);
 
@@ -352,13 +356,13 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
 
		// Forward it
 
		conv->handleMessage(msg, "anotheruser");
 

	
 
		loop->processEvents();
 
		CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[0])));
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there!"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getBody());
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there!"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getBody().value_or(""));
 
		CPPUNIT_ASSERT_EQUAL(std::string("user@localhost/resource"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getTo().toString());
 
		CPPUNIT_ASSERT_EQUAL(std::string("#room@localhost/alias"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getFrom().toString());
 
	}
 

	
 
	void handleGroupchatMessagesBouncer() {
 
		User *user = userManager->getUser("user@localhost");
 
@@ -417,18 +421,18 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
 
		CPPUNIT_ASSERT_EQUAL(std::string("#room@localhost/hanzz"), dynamic_cast<Swift::Presence *>(getStanza(received[2]))->getFrom().toString());
 
		CPPUNIT_ASSERT(getStanza(received[2])->getPayload<Swift::MUCUserPayload>());
 
		CPPUNIT_ASSERT_EQUAL(std::string("nickname"), *getStanza(received[2])->getPayload<Swift::MUCUserPayload>()->getItems()[0].nick);
 
		CPPUNIT_ASSERT_EQUAL(303, getStanza(received[2])->getPayload<Swift::MUCUserPayload>()->getStatusCodes()[2].code);
 

	
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[4])));
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there!"), dynamic_cast<Swift::Message *>(getStanza(received[4]))->getBody());
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there!"), dynamic_cast<Swift::Message *>(getStanza(received[4]))->getBody().value_or(""));
 
		CPPUNIT_ASSERT_EQUAL(std::string("user@localhost/resource"), dynamic_cast<Swift::Message *>(getStanza(received[4]))->getTo().toString());
 
		CPPUNIT_ASSERT_EQUAL(std::string("#room@localhost/anotheruser"), dynamic_cast<Swift::Message *>(getStanza(received[4]))->getFrom().toString());
 

	
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[5])));
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there2!"), dynamic_cast<Swift::Message *>(getStanza(received[5]))->getBody());
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there2!"), dynamic_cast<Swift::Message *>(getStanza(received[5]))->getBody().value_or(""));
 
		CPPUNIT_ASSERT_EQUAL(std::string("user@localhost/resource"), dynamic_cast<Swift::Message *>(getStanza(received[5]))->getTo().toString());
 
		CPPUNIT_ASSERT_EQUAL(std::string("#room@localhost/anotheruser"), dynamic_cast<Swift::Message *>(getStanza(received[5]))->getFrom().toString());
 

	
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[6])));
 
		CPPUNIT_ASSERT_EQUAL(std::string("subject"), dynamic_cast<Swift::Message *>(getStanza(received[6]))->getSubject());
 
		CPPUNIT_ASSERT_EQUAL(std::string("user@localhost/resource"), dynamic_cast<Swift::Message *>(getStanza(received[6]))->getTo().toString());
 
@@ -494,18 +498,18 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
 
		CPPUNIT_ASSERT_EQUAL(std::string("#room@localhost/hanzz"), dynamic_cast<Swift::Presence *>(getStanza(received[2]))->getFrom().toString());
 
		CPPUNIT_ASSERT(getStanza(received[2])->getPayload<Swift::MUCUserPayload>());
 
		CPPUNIT_ASSERT_EQUAL(std::string("nickname"), *getStanza(received[2])->getPayload<Swift::MUCUserPayload>()->getItems()[0].nick);
 
		CPPUNIT_ASSERT_EQUAL(303, getStanza(received[2])->getPayload<Swift::MUCUserPayload>()->getStatusCodes()[2].code);
 

	
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[4])));
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there!"), dynamic_cast<Swift::Message *>(getStanza(received[4]))->getBody());
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there!"), dynamic_cast<Swift::Message *>(getStanza(received[4]))->getBody().value_or(""));
 
		CPPUNIT_ASSERT_EQUAL(std::string("user@localhost/resource"), dynamic_cast<Swift::Message *>(getStanza(received[4]))->getTo().toString());
 
		CPPUNIT_ASSERT_EQUAL(std::string("#room@localhost/anotheruser"), dynamic_cast<Swift::Message *>(getStanza(received[4]))->getFrom().toString());
 

	
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[5])));
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there2!"), dynamic_cast<Swift::Message *>(getStanza(received[5]))->getBody());
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there2!"), dynamic_cast<Swift::Message *>(getStanza(received[5]))->getBody().value_or(""));
 
		CPPUNIT_ASSERT_EQUAL(std::string("user@localhost/resource"), dynamic_cast<Swift::Message *>(getStanza(received[5]))->getTo().toString());
 
		CPPUNIT_ASSERT_EQUAL(std::string("#room@localhost/anotheruser"), dynamic_cast<Swift::Message *>(getStanza(received[5]))->getFrom().toString());
 

	
 
	}
 

	
 
	void handleGroupchatMessagesTwoResources() {
 
@@ -528,13 +532,13 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
 
		// Forward it
 
		conv->handleMessage(msg, "anotheruser");
 

	
 
		loop->processEvents();
 
		CPPUNIT_ASSERT_EQUAL(1, (int) received2.size());
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received2[0])));
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there!"), dynamic_cast<Swift::Message *>(getStanza(received2[0]))->getBody());
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there!"), dynamic_cast<Swift::Message *>(getStanza(received2[0]))->getBody().value_or(""));
 
		CPPUNIT_ASSERT_EQUAL(std::string("user@localhost/resource2"), dynamic_cast<Swift::Message *>(getStanza(received2[0]))->getTo().toString());
 
		CPPUNIT_ASSERT_EQUAL(std::string("#room@localhost/anotheruser"), dynamic_cast<Swift::Message *>(getStanza(received2[0]))->getFrom().toString());
 

	
 
		received.clear();
 

	
 
		// send response
 
@@ -544,13 +548,13 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
 
		msg->setType(Swift::Message::Groupchat);
 
		injectMessage(msg);
 
		loop->processEvents();
 
		
 
		CPPUNIT_ASSERT_EQUAL(0, (int) received.size());
 
		CPPUNIT_ASSERT(m_msg);
 
		CPPUNIT_ASSERT_EQUAL(std::string("response!"), m_msg->getBody());
 
		CPPUNIT_ASSERT_EQUAL(std::string("response!"), m_msg->getBody().value_or(""));
 
	}
 

	
 
	void handleParticipantChanged() {
 
		User *user = userManager->getUser("user@localhost");
 
		TestingConversation *conv = new TestingConversation(user->getConversationManager(), "#room", true);
 
		
 
@@ -720,13 +724,13 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
 
		msg->setBody("hi there!");
 
		injectMessage(msg);
 
		loop->processEvents();
 

	
 
		CPPUNIT_ASSERT_EQUAL(0, (int) received.size());
 
		CPPUNIT_ASSERT(m_msg);
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there!"), m_msg->getBody());
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there!"), m_msg->getBody().value_or(""));
 
		CPPUNIT_ASSERT_EQUAL(std::string("#room/anotheruser"), m_conv->getLegacyName());
 

	
 
		Conversation *pmconv = user->getConversationManager()->getConversation("#room/anotheruser");
 

	
 
		boost::shared_ptr<Swift::Message> msg2(new Swift::Message());
 
		msg2->setBody("response!");
tests/libtransport/user.cpp
Show inline comments
 
@@ -9,12 +9,16 @@
 
#include "Swiften/Server/ServerFromClientSession.h"
 
#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h"
 
#include "basictest.h"
 

	
 
using namespace Transport;
 

	
 
#if !HAVE_SWIFTEN_3
 
#define value_or(X) substr()
 
#endif
 

	
 
class UserTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
	CPPUNIT_TEST_SUITE(UserTest);
 
	CPPUNIT_TEST(sendCurrentPresence);
 
    CPPUNIT_TEST(handlePresence);
 
	CPPUNIT_TEST(handlePresenceJoinRoom);
 
	CPPUNIT_TEST(handlePresenceJoinRoomTwoResources);
 
@@ -424,13 +428,13 @@ class UserTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
		CPPUNIT_ASSERT(streamEnded);
 
		user = userManager->getUser("user@localhost");
 
		CPPUNIT_ASSERT(!user);
 

	
 
		CPPUNIT_ASSERT_EQUAL(2, (int) received.size());
 
		Swift::Message *m = dynamic_cast<Swift::Message *>(getStanza(received[0]));
 
		CPPUNIT_ASSERT_EQUAL(std::string("Connection error"), m->getBody());
 
		CPPUNIT_ASSERT_EQUAL(std::string("Connection error"), m->getBody().value_or(""));
 

	
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::StreamError *>(received[1].get()));
 
		CPPUNIT_ASSERT_EQUAL(std::string("Connection error"), dynamic_cast<Swift::StreamError *>(received[1].get())->getText());
 

	
 
		disconnected = true;
 
	}
tests/libtransport/usermanager.cpp
Show inline comments
 
@@ -9,12 +9,16 @@
 
#include "Swiften/Server/ServerFromClientSession.h"
 
#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h"
 
#include "basictest.h"
 

	
 
using namespace Transport;
 

	
 
#if !HAVE_SWIFTEN_3
 
#define value_or(X) substr()
 
#endif
 

	
 
class UserManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
	CPPUNIT_TEST_SUITE(UserManagerTest);
 
	CPPUNIT_TEST(connectUser);
 
	CPPUNIT_TEST(connectTwoResources);
 
	CPPUNIT_TEST(connectUserTransportDisabled);
 
	CPPUNIT_TEST(connectUserRegistrationNeeded);
 
@@ -74,13 +78,13 @@ class UserManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
		CPPUNIT_ASSERT_EQUAL(0, userManager->getUserCount());
 
		userRegistry->isValidUserPassword(Swift::JID("user@localhost/resource"), serverFromClientSession.get(), Swift::createSafeByteArray("password"));
 
		loop->processEvents();
 

	
 
		CPPUNIT_ASSERT_EQUAL(3, (int) received.size());
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[1])));
 
		CPPUNIT_ASSERT_EQUAL(std::string("Ahoj"), dynamic_cast<Swift::Message *>(getStanza(received[1]))->getBody());
 
		CPPUNIT_ASSERT_EQUAL(std::string("Ahoj"), dynamic_cast<Swift::Message *>(getStanza(received[1]))->getBody().value_or(""));
 
		CPPUNIT_ASSERT_EQUAL(std::string("user@localhost/resource"), dynamic_cast<Swift::Message *>(getStanza(received[1]))->getTo().toString());
 
		CPPUNIT_ASSERT_EQUAL(std::string("localhost"), dynamic_cast<Swift::Message *>(getStanza(received[1]))->getFrom().toString());
 

	
 
		CPPUNIT_ASSERT_EQUAL(0, userManager->getUserCount());
 
		CPPUNIT_ASSERT(streamEnded);
 
		std::istringstream ifs2("service.server_mode = 1\nservice.jid_escaping=1\nservice.jid=localhost\nservice.more_resources=1\n");
tests/libtransport/userregistration.cpp
Show inline comments
 
@@ -9,12 +9,16 @@
 
#include "Swiften/Server/ServerFromClientSession.h"
 
#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h"
 
#include "basictest.h"
 

	
 
using namespace Transport;
 

	
 
#if !HAVE_SWIFTEN_3
 
#define value_or(X) substr()
 
#endif
 

	
 
class UserRegistrationTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
	CPPUNIT_TEST_SUITE(UserRegistrationTest);
 
	CPPUNIT_TEST(getForm);
 
	CPPUNIT_TEST(getFormRegistered);
 
	CPPUNIT_TEST(registerUser);
 
	CPPUNIT_TEST(registerUserWithoutRR);
 
@@ -197,13 +201,13 @@ class UserRegistrationTest : public CPPUNIT_NS :: TestFixture, public BasicTest
 
			CPPUNIT_ASSERT(dynamic_cast<Swift::IQ *>(getStanza(received[0])));
 
			CPPUNIT_ASSERT_EQUAL(Swift::IQ::Set, dynamic_cast<Swift::IQ *>(getStanza(received[0]))->getType());
 
			CPPUNIT_ASSERT(getStanza(received[0])->getPayload<Swift::RosterPayload>());
 
			CPPUNIT_ASSERT_EQUAL(std::string("localhost"), getStanza(received[0])->getPayload<Swift::RosterPayload>()->getItems()[0].getJID().toString());
 

	
 
			CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[1])));
 
			CPPUNIT_ASSERT_EQUAL(std::string("registered: user@localhost"), dynamic_cast<Swift::Message *>(getStanza(received[1]))->getBody());
 
			CPPUNIT_ASSERT_EQUAL(std::string("registered: user@localhost"), dynamic_cast<Swift::Message *>(getStanza(received[1]))->getBody().value_or(""));
 

	
 
			UserInfo user;
 
			CPPUNIT_ASSERT_EQUAL(true, storage->getUser("user@localhost", user));
 

	
 
			CPPUNIT_ASSERT_EQUAL(std::string("legacyname"), user.uin);
 
			CPPUNIT_ASSERT_EQUAL(std::string("password"), user.password);
 
@@ -235,13 +239,13 @@ class UserRegistrationTest : public CPPUNIT_NS :: TestFixture, public BasicTest
 
			CPPUNIT_ASSERT_EQUAL(2, (int) received.size());
 
			CPPUNIT_ASSERT(dynamic_cast<Swift::IQ *>(getStanza(received[0])));
 
			CPPUNIT_ASSERT_EQUAL(Swift::IQ::Set, dynamic_cast<Swift::IQ *>(getStanza(received[0]))->getType());
 
			CPPUNIT_ASSERT(getStanza(received[0])->getPayload<Swift::RosterPayload>());
 

	
 
			CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[1])));
 
			CPPUNIT_ASSERT_EQUAL(std::string("unregistered: user@localhost"), dynamic_cast<Swift::Message *>(getStanza(received[1]))->getBody());
 
			CPPUNIT_ASSERT_EQUAL(std::string("unregistered: user@localhost"), dynamic_cast<Swift::Message *>(getStanza(received[1]))->getBody().value_or(""));
 

	
 

	
 
			UserInfo user;
 
			CPPUNIT_ASSERT_EQUAL(false, storage->getUser("user@localhost", user));
 
		}
 

	
0 comments (0 inline, 0 general)