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.
This commit is contained in:
parent
56eaa5e880
commit
26fc8a0323
9 changed files with 129 additions and 68 deletions
|
@ -33,6 +33,9 @@
|
|||
#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");
|
||||
|
@ -60,19 +63,24 @@ 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)
|
||||
|
@ -84,11 +92,11 @@ void AdminInterface::handleQuery(Swift::Message::ref message) {
|
|||
|
||||
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");
|
||||
|
@ -97,7 +105,7 @@ void AdminInterface::handleQuery(Swift::Message::ref message) {
|
|||
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;
|
||||
|
||||
|
@ -125,16 +133,16 @@ void AdminInterface::handleQuery(Swift::Message::ref message) {
|
|||
|
||||
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);
|
||||
|
@ -145,7 +153,7 @@ void AdminInterface::handleQuery(Swift::Message::ref message) {
|
|||
|
||||
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);
|
||||
|
@ -156,7 +164,7 @@ void AdminInterface::handleQuery(Swift::Message::ref message) {
|
|||
|
||||
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);
|
||||
|
@ -169,7 +177,7 @@ void AdminInterface::handleQuery(Swift::Message::ref message) {
|
|||
|
||||
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));
|
||||
}
|
||||
|
@ -185,7 +193,7 @@ 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();
|
||||
|
@ -196,7 +204,7 @@ void AdminInterface::handleQuery(Swift::Message::ref message) {
|
|||
|
||||
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();
|
||||
|
@ -207,7 +215,7 @@ void AdminInterface::handleQuery(Swift::Message::ref message) {
|
|||
|
||||
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();
|
||||
|
@ -218,7 +226,7 @@ void AdminInterface::handleQuery(Swift::Message::ref message) {
|
|||
|
||||
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();
|
||||
|
@ -234,10 +242,10 @@ void AdminInterface::handleQuery(Swift::Message::ref message) {
|
|||
|
||||
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) {
|
||||
|
@ -245,19 +253,19 @@ void AdminInterface::handleQuery(Swift::Message::ref message) {
|
|||
}
|
||||
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) {
|
||||
|
@ -280,8 +288,8 @@ void AdminInterface::handleQuery(Swift::Message::ref message) {
|
|||
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) {
|
||||
|
@ -296,8 +304,8 @@ void AdminInterface::handleQuery(Swift::Message::ref message) {
|
|||
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) {
|
||||
|
@ -313,21 +321,21 @@ void AdminInterface::handleQuery(Swift::Message::ref message) {
|
|||
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";
|
||||
|
@ -365,7 +373,7 @@ void AdminInterface::handleQuery(Swift::Message::ref message) {
|
|||
message->setBody(help);
|
||||
}
|
||||
else {
|
||||
message->setBody("Unknown command \"" + message->getBody() + "\". Try \"help\"");
|
||||
message->setBody("Unknown command \"" + msg + "\". Try \"help\"");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -381,9 +389,15 @@ void AdminInterface::handleMessageReceived(Swift::Message::ref message) {
|
|||
}
|
||||
|
||||
// Ignore empty messages
|
||||
#if HAVE_SWIFTEN_3
|
||||
if (message->getBody().value_or("").empty()) {
|
||||
return;
|
||||
}
|
||||
#else
|
||||
if (message->getBody().empty()) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
handleQuery(message);
|
||||
|
||||
|
|
|
@ -970,7 +970,11 @@ void NetworkPluginServer::handleQueryPayload(Backend *b, const std::string &data
|
|||
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);
|
||||
|
@ -1692,7 +1696,11 @@ void NetworkPluginServer::handleMessageReceived(NetworkConversation *conv, boost
|
|||
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);
|
||||
|
@ -1728,11 +1736,16 @@ void NetworkPluginServer::handleMessageReceived(NetworkConversation *conv, boost
|
|||
}
|
||||
|
||||
// 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()) {
|
||||
|
|
|
@ -374,7 +374,12 @@ void UserManager::handleMessageReceived(Swift::Message::ref message) {
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,8 @@
|
|||
#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>
|
||||
|
@ -148,7 +150,12 @@ void SlackSession::sendMessage(boost::shared_ptr<Swift::Message> message) {
|
|||
}
|
||||
|
||||
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) {
|
||||
|
|
|
@ -32,6 +32,9 @@
|
|||
#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");
|
||||
|
@ -106,8 +109,13 @@ void SlackUserManager::handleUserCreated(User *user) {
|
|||
}
|
||||
|
||||
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) {
|
||||
|
@ -125,8 +133,7 @@ bool SlackUserManager::handleAdminMessage(Swift::Message::ref message) {
|
|||
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) {
|
||||
|
@ -139,7 +146,7 @@ bool SlackUserManager::handleAdminMessage(Swift::Message::ref message) {
|
|||
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]));
|
||||
|
@ -150,8 +157,7 @@ bool SlackUserManager::handleAdminMessage(Swift::Message::ref message) {
|
|||
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) {
|
||||
|
|
|
@ -13,6 +13,10 @@
|
|||
|
||||
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);
|
||||
|
@ -157,7 +161,7 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
|
|||
|
||||
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());
|
||||
|
||||
|
@ -172,7 +176,7 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
|
|||
|
||||
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());
|
||||
|
@ -184,7 +188,7 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
|
|||
|
||||
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());
|
||||
|
||||
|
@ -205,7 +209,7 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
|
|||
|
||||
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());
|
||||
|
||||
|
@ -226,7 +230,7 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
|
|||
|
||||
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");
|
||||
|
@ -253,7 +257,7 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
|
|||
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());
|
||||
|
||||
|
@ -266,7 +270,7 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
|
|||
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());
|
||||
|
||||
|
@ -280,7 +284,7 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
|
|||
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());
|
||||
}
|
||||
|
@ -305,7 +309,7 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
|
|||
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());
|
||||
|
||||
|
@ -321,7 +325,7 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
|
|||
|
||||
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() {
|
||||
|
@ -355,7 +359,7 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
|
|||
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());
|
||||
}
|
||||
|
@ -420,12 +424,12 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
|
|||
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());
|
||||
|
||||
|
@ -497,12 +501,12 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
|
|||
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());
|
||||
|
||||
|
@ -531,7 +535,7 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
|
|||
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());
|
||||
|
||||
|
@ -547,7 +551,7 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
|
|||
|
||||
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() {
|
||||
|
@ -723,7 +727,7 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
|
|||
|
||||
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");
|
||||
|
|
|
@ -12,6 +12,10 @@
|
|||
|
||||
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);
|
||||
|
@ -427,7 +431,7 @@ class UserTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
|
|||
|
||||
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());
|
||||
|
|
|
@ -12,6 +12,10 @@
|
|||
|
||||
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);
|
||||
|
@ -77,7 +81,7 @@ class UserManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
|
|||
|
||||
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());
|
||||
|
||||
|
|
|
@ -12,6 +12,10 @@
|
|||
|
||||
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);
|
||||
|
@ -200,7 +204,7 @@ class UserRegistrationTest : public CPPUNIT_NS :: TestFixture, public BasicTest
|
|||
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));
|
||||
|
@ -238,7 +242,7 @@ class UserRegistrationTest : public CPPUNIT_NS :: TestFixture, public BasicTest
|
|||
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;
|
||||
|
|
Loading…
Add table
Reference in a new issue