Files
@ daeb6dfc9a9f
Branch filter:
Location: libtransport.git/tests/libtransport/localbuddy.cpp
daeb6dfc9a9f
5.3 KiB
text/x-c++hdr
Enable support for Qt5
Since Qt4 is EOL, we should also support libcommuni build with Qt5.
In order not to break Fedora docker builds, -DENABLE_QT4 is introduced.
When set to 'ON', support for Qt4 is being enabled,
otherwise support for Qt5 is enabled.
Signed-off-by: Conrad Kostecki <conrad@kostecki.com>
Since Qt4 is EOL, we should also support libcommuni build with Qt5.
In order not to break Fedora docker builds, -DENABLE_QT4 is introduced.
When set to 'ON', support for Qt4 is being enabled,
otherwise support for Qt5 is enabled.
Signed-off-by: Conrad Kostecki <conrad@kostecki.com>
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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | #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(localBuddySize);
CPPUNIT_TEST(createWithInvalidName);
CPPUNIT_TEST(buddyFlagsFromJID);
CPPUNIT_TEST(JIDToLegacyName);
CPPUNIT_TEST(getSafeName);
CPPUNIT_TEST(sendPresence);
CPPUNIT_TEST(setAlias);
CPPUNIT_TEST(sendPresenceTypeNone);
CPPUNIT_TEST_SUITE_END();
public:
void setUp (void) {
setMeUp();
connectUser();
received.clear();
}
void tearDown (void) {
received.clear();
disconnectUser();
tearMeDown();
}
void localBuddySize() {
std::cout << " = " << sizeof(LocalBuddy) << " B";
}
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 getSafeName() {
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@test", "Buddy 1", grp, BUDDY_JID_ESCAPING);
CPPUNIT_ASSERT_EQUAL(std::string("buddy1\\40test"), buddy->getSafeName());
buddy->setFlags(BUDDY_NO_FLAG);
CPPUNIT_ASSERT_EQUAL(std::string("buddy1%test"), buddy->getSafeName());
}
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 sendPresence() {
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->sendPresence();
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 setAlias() {
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->setAlias("Buddy 2");
CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
Swift::RosterPayload::ref payload1 = getStanza(received[0])->getPayload<Swift::RosterPayload>();
CPPUNIT_ASSERT(payload1);
CPPUNIT_ASSERT_EQUAL(1, (int) payload1->getItems().size());
Swift::RosterItemPayload item = payload1->getItems()[0];
CPPUNIT_ASSERT_EQUAL(std::string("buddy1"), Buddy::JIDToLegacyName(item.getJID()));
CPPUNIT_ASSERT_EQUAL(std::string("Buddy 2"), item.getName());
}
void sendPresenceTypeNone() {
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), "");
user->getRosterManager()->setBuddy(buddy);
received.clear();
buddy->setStatus(Swift::StatusShow(Swift::StatusShow::None), "");
CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[0])));
CPPUNIT_ASSERT_EQUAL(Swift::StatusShow::None, dynamic_cast<Swift::Presence *>(getStanza(received[0]))->getShow());
}
};
CPPUNIT_TEST_SUITE_REGISTRATION (LocalBuddyTest);
|