summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/LinkLocal/UnitTest')
-rw-r--r--Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp10
-rw-r--r--Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp26
-rw-r--r--Swiften/LinkLocal/UnitTest/LinkLocalServiceInfoTest.cpp17
-rw-r--r--Swiften/LinkLocal/UnitTest/LinkLocalServiceTest.cpp6
4 files changed, 42 insertions, 17 deletions
diff --git a/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp b/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp
index 85ae537..59cf996 100644
--- a/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp
+++ b/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp
@@ -1,11 +1,11 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <boost/bind.hpp>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
@@ -47,19 +47,19 @@ class LinkLocalConnectorTest : public CppUnit::TestFixture {
querier->setAddress("rabbithole.local", HostAddress::fromString("192.168.1.1").get());
testling->connect();
eventLoop->processEvents();
CPPUNIT_ASSERT(connectFinished);
CPPUNIT_ASSERT(!connectError);
CPPUNIT_ASSERT(connection->connectedTo);
CPPUNIT_ASSERT_EQUAL(std::string(connection->connectedTo->getAddress().toString()), std::string("192.168.1.1"));
- CPPUNIT_ASSERT_EQUAL(connection->connectedTo->getPort(), 1234);
+ CPPUNIT_ASSERT_EQUAL(connection->connectedTo->getPort(), static_cast<unsigned short>(1234));
}
void testConnect_UnableToResolve() {
std::shared_ptr<LinkLocalConnector>
testling(createConnector("rabbithole.local", 1234));
querier->setAddress("rabbithole.local", boost::optional<HostAddress>());
testling->connect();
eventLoop->processEvents();
@@ -108,24 +108,26 @@ class LinkLocalConnectorTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT(FakeConnection::Connecting == connection->state);
testling->cancel();
eventLoop->processEvents();
CPPUNIT_ASSERT(FakeConnection::Disconnected == connection->state);
}
private:
- std::shared_ptr<LinkLocalConnector> createConnector(const std::string& hostname, int port) {
+ std::shared_ptr<LinkLocalConnector> createConnector(const std::string& hostname, unsigned short port) {
+ auto txtRecord = LinkLocalServiceInfo().toTXTRecord();
+ CPPUNIT_ASSERT(txtRecord);
LinkLocalService service(
DNSSDServiceID("myname", "local."),
DNSSDResolveServiceQuery::Result(
"myname._presence._tcp.local", hostname, port,
- LinkLocalServiceInfo().toTXTRecord()));
+ *txtRecord));
std::shared_ptr<LinkLocalConnector> result(
new LinkLocalConnector(service, querier, connection));
result->onConnectFinished.connect(
boost::bind(&LinkLocalConnectorTest::handleConnected, this, _1));
return result;
}
void handleConnected(bool e) {
connectFinished = true;
diff --git a/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp b/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp
index a80d748..3491634 100644
--- a/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp
+++ b/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp
@@ -1,11 +1,11 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <map>
#include <memory>
#include <boost/bind.hpp>
@@ -41,22 +41,24 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testRegisterService_Reregister);
CPPUNIT_TEST(testUpdateService);
CPPUNIT_TEST_SUITE_END();
public:
void setUp() {
eventLoop = new DummyEventLoop();
querier = std::make_shared<FakeDNSSDQuerier>("wonderland.lit", eventLoop);
aliceServiceID = new DNSSDServiceID("alice", "wonderland.lit");
- aliceServiceInfo = new DNSSDResolveServiceQuery::Result("_presence._tcp.wonderland.lit", "xmpp.wonderland.lit", 1234, LinkLocalServiceInfo().toTXTRecord());
+ auto txtRecord = LinkLocalServiceInfo().toTXTRecord();
+ CPPUNIT_ASSERT(txtRecord);
+ aliceServiceInfo = new DNSSDResolveServiceQuery::Result("_presence._tcp.wonderland.lit", "xmpp.wonderland.lit", 1234, *txtRecord);
testServiceID = new DNSSDServiceID("foo", "bar.local");
- testServiceInfo = new DNSSDResolveServiceQuery::Result("_presence._tcp.bar.local", "xmpp.bar.local", 1234, LinkLocalServiceInfo().toTXTRecord());
- testServiceInfo2 = new DNSSDResolveServiceQuery::Result("_presence.tcp.bar.local", "xmpp.foo.local", 2345, LinkLocalServiceInfo().toTXTRecord());
+ testServiceInfo = new DNSSDResolveServiceQuery::Result("_presence._tcp.bar.local", "xmpp.bar.local", 1234, *txtRecord);
+ testServiceInfo2 = new DNSSDResolveServiceQuery::Result("_presence.tcp.bar.local", "xmpp.foo.local", 2345, *txtRecord);
errorStopReceived = false;
normalStopReceived = false;
}
void tearDown() {
querier->clearAllQueriesEverRun();
addedServices.clear();
removedServices.clear();
changedServices.clear();
@@ -286,73 +288,81 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture {
std::shared_ptr<LinkLocalServiceBrowser> testling = createTestling();
testling->start();
eventLoop->processEvents();
LinkLocalServiceInfo info;
info.setFirstName("Foo");
testling->registerService("foo@bar", 1234, info);
eventLoop->processEvents();
- CPPUNIT_ASSERT(querier->isServiceRegistered("foo@bar", 1234, info.toTXTRecord()));
+ auto txtRecord = info.toTXTRecord();
+ CPPUNIT_ASSERT(txtRecord);
+ CPPUNIT_ASSERT(querier->isServiceRegistered("foo@bar", 1234, *txtRecord));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(registeredServices.size()));
CPPUNIT_ASSERT(registeredServices[0] == DNSSDServiceID("foo@bar", "wonderland.lit"));
testling->stop();
}
void testRegisterService_Error() {
std::shared_ptr<LinkLocalServiceBrowser> testling = createTestling();
testling->start();
LinkLocalServiceInfo info;
testling->registerService("foo@bar", 1234, info);
eventLoop->processEvents();
querier->setRegisterError();
eventLoop->processEvents();
CPPUNIT_ASSERT(!testling->isRunning());
CPPUNIT_ASSERT(testling->hasError());
CPPUNIT_ASSERT(errorStopReceived);
- CPPUNIT_ASSERT(!querier->isServiceRegistered("foo@bar", 1234, info.toTXTRecord()));
+ auto txtRecord = info.toTXTRecord();
+ CPPUNIT_ASSERT(txtRecord);
+ CPPUNIT_ASSERT(!querier->isServiceRegistered("foo@bar", 1234, *txtRecord));
}
void testRegisterService_Reregister() {
std::shared_ptr<LinkLocalServiceBrowser> testling = createTestling();
testling->start();
eventLoop->processEvents();
LinkLocalServiceInfo info;
info.setFirstName("Foo");
testling->registerService("foo@bar", 1234, info);
eventLoop->processEvents();
testling->unregisterService();
eventLoop->processEvents();
info.setFirstName("Bar");
testling->registerService("bar@baz", 3456, info);
eventLoop->processEvents();
- CPPUNIT_ASSERT(querier->isServiceRegistered("bar@baz", 3456, info.toTXTRecord()));
+ auto txtRecord = info.toTXTRecord();
+ CPPUNIT_ASSERT(txtRecord);
+ CPPUNIT_ASSERT(querier->isServiceRegistered("bar@baz", 3456, *txtRecord));
testling->stop();
}
void testUpdateService() {
std::shared_ptr<LinkLocalServiceBrowser> testling = createTestling();
testling->start();
eventLoop->processEvents();
LinkLocalServiceInfo info;
info.setFirstName("Foo");
testling->registerService("foo@bar", 1234, info);
eventLoop->processEvents();
info.setFirstName("Bar");
testling->updateService(info);
- CPPUNIT_ASSERT(querier->isServiceRegistered("foo@bar", 1234, info.toTXTRecord()));
+ auto txtRecord = info.toTXTRecord();
+ CPPUNIT_ASSERT(txtRecord);
+ CPPUNIT_ASSERT(querier->isServiceRegistered("foo@bar", 1234, *txtRecord));
testling->stop();
}
private:
std::shared_ptr<LinkLocalServiceBrowser> createTestling() {
std::shared_ptr<LinkLocalServiceBrowser> testling(
new LinkLocalServiceBrowser(querier));
testling->onServiceAdded.connect(boost::bind(
diff --git a/Swiften/LinkLocal/UnitTest/LinkLocalServiceInfoTest.cpp b/Swiften/LinkLocal/UnitTest/LinkLocalServiceInfoTest.cpp
index 0a94a98..35cb1b4 100644
--- a/Swiften/LinkLocal/UnitTest/LinkLocalServiceInfoTest.cpp
+++ b/Swiften/LinkLocal/UnitTest/LinkLocalServiceInfoTest.cpp
@@ -1,11 +1,11 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <QA/Checker/IO.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
@@ -23,19 +23,21 @@ class LinkLocalServiceInfoTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE_END();
public:
void testGetTXTRecord() {
LinkLocalServiceInfo info;
info.setFirstName("Remko");
info.setLastName("Tron\xc3\xe7on");
info.setStatus(LinkLocalServiceInfo::Away);
- CPPUNIT_ASSERT_EQUAL(createByteArray("\x09txtvers=1\x09" + std::string("1st=Remko\x0dlast=Tron\xc3\xe7on\x0bstatus=away")), info.toTXTRecord());
+ auto txtRecord = info.toTXTRecord();
+ CPPUNIT_ASSERT(txtRecord);
+ CPPUNIT_ASSERT_EQUAL(createByteArray("\x09txtvers=1\x09" + std::string("1st=Remko\x0dlast=Tron\xc3\xe7on\x0bstatus=away")), *txtRecord);
}
void testCreateFromTXTRecord() {
LinkLocalServiceInfo info = LinkLocalServiceInfo::createFromTXTRecord(createByteArray("\x09txtvers=1\x09" + std::string("1st=Remko\x0dlast=Tron\xc3\xe7on\x0bstatus=away")));
CPPUNIT_ASSERT_EQUAL(std::string("Remko"), info.getFirstName());
CPPUNIT_ASSERT_EQUAL(std::string("Tron\xc3\xe7on"), info.getLastName());
CPPUNIT_ASSERT_EQUAL(LinkLocalServiceInfo::Away, info.getStatus());
}
@@ -51,22 +53,31 @@ class LinkLocalServiceInfoTest : public CppUnit::TestFixture {
info.setFirstName("Remko");
info.setLastName("Tron\xc3\xe7on");
info.setEMail("remko-email@swift.im");
info.setJID(JID("remko-jid@swift.im"));
info.setMessage("I'm busy");
info.setNick("el-tramo");
info.setStatus(LinkLocalServiceInfo::DND);
info.setPort(1234);
- LinkLocalServiceInfo info2 = LinkLocalServiceInfo::createFromTXTRecord(info.toTXTRecord());
+ auto txtRecord = info.toTXTRecord();
+ CPPUNIT_ASSERT(txtRecord);
+ LinkLocalServiceInfo info2 = LinkLocalServiceInfo::createFromTXTRecord(*txtRecord);
CPPUNIT_ASSERT_EQUAL(info.getFirstName(), info2.getFirstName());
CPPUNIT_ASSERT_EQUAL(info.getLastName(), info2.getLastName());
CPPUNIT_ASSERT_EQUAL(info.getEMail(), info2.getEMail());
CPPUNIT_ASSERT_EQUAL(info.getJID(), info2.getJID());
CPPUNIT_ASSERT_EQUAL(info.getMessage(), info2.getMessage());
CPPUNIT_ASSERT_EQUAL(info.getNick(), info2.getNick());
CPPUNIT_ASSERT(info.getStatus() == info2.getStatus());
CPPUNIT_ASSERT(info.getPort() == info2.getPort());
}
+
+ void testToTXTRecordWithInvalidParameter() {
+ LinkLocalServiceInfo info;
+ info.setFirstName(std::string(256, 'x'));
+ auto txtRecord = info.toTXTRecord();
+ CPPUNIT_ASSERT(!txtRecord);
+ }
};
CPPUNIT_TEST_SUITE_REGISTRATION(LinkLocalServiceInfoTest);
diff --git a/Swiften/LinkLocal/UnitTest/LinkLocalServiceTest.cpp b/Swiften/LinkLocal/UnitTest/LinkLocalServiceTest.cpp
index 206d824..cb5f40a 100644
--- a/Swiften/LinkLocal/UnitTest/LinkLocalServiceTest.cpp
+++ b/Swiften/LinkLocal/UnitTest/LinkLocalServiceTest.cpp
@@ -1,11 +1,11 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <Swiften/LinkLocal/LinkLocalService.h>
@@ -52,17 +52,19 @@ class LinkLocalServiceTest : public CppUnit::TestFixture {
}
private:
LinkLocalService createService(const std::string& name, const std::string& nickName = std::string(), const std::string& firstName = std::string(), const std::string& lastName = std::string()) {
DNSSDServiceID service(name, "local.");
LinkLocalServiceInfo info;
info.setFirstName(firstName);
info.setLastName(lastName);
info.setNick(nickName);
+ auto txtRecord = info.toTXTRecord();
+ CPPUNIT_ASSERT(txtRecord);
return LinkLocalService(service,
DNSSDResolveServiceQuery::Result(
name + "._presence._tcp.local", "rabbithole.local", 1234,
- info.toTXTRecord()));
+ *txtRecord));
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(LinkLocalServiceTest);