summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Network/UnitTest')
-rw-r--r--Swiften/Network/UnitTest/BOSHConnectionPoolTest.cpp8
-rw-r--r--Swiften/Network/UnitTest/BOSHConnectionTest.cpp2
-rw-r--r--Swiften/Network/UnitTest/ConnectorTest.cpp29
-rw-r--r--Swiften/Network/UnitTest/HTTPConnectProxiedConnectionTest.cpp4
-rw-r--r--Swiften/Network/UnitTest/HostAddressTest.cpp30
5 files changed, 60 insertions, 13 deletions
diff --git a/Swiften/Network/UnitTest/BOSHConnectionPoolTest.cpp b/Swiften/Network/UnitTest/BOSHConnectionPoolTest.cpp
index 5d6fedd..4aeaf24 100644
--- a/Swiften/Network/UnitTest/BOSHConnectionPoolTest.cpp
+++ b/Swiften/Network/UnitTest/BOSHConnectionPoolTest.cpp
@@ -188,19 +188,19 @@ class BOSHConnectionPoolTest : public CppUnit::TestFixture {
eventLoop->processEvents();
readResponse("<body/>", connectionFactory->connections[0]);
rid++;
testling->write(createSafeByteArray("<blah/>"));
eventLoop->processEvents();
CPPUNIT_ASSERT_EQUAL(st(2), connectionFactory->connections.size()); /* 0 was waiting for response, open and send on 1 */
CPPUNIT_ASSERT_EQUAL(st(4), boshDataWritten.size()); /* data */
c1 = connectionFactory->connections[1];
- std::string fullBody = "<body rid='" + boost::lexical_cast<std::string>(rid) + "' sid='" + sid + "' xmlns='http://jabber.org/protocol/httpbind'><blah/></body>"; /* check empty write */
+ std::string fullBody = "<body rid='" + std::to_string(rid) + "' sid='" + sid + "' xmlns='http://jabber.org/protocol/httpbind'><blah/></body>"; /* check empty write */
CPPUNIT_ASSERT_EQUAL(fullBody, lastBody());
CPPUNIT_ASSERT(c0->pending);
CPPUNIT_ASSERT(c1->pending);
rid++;
readResponse("<body xmlns='http://jabber.org/protocol/httpbind'><message><splatploing/></message></body>", c0); /* Doesn't include necessary attributes - as the support is improved this'll start to fail */
eventLoop->processEvents();
CPPUNIT_ASSERT(!c0->pending);
@@ -304,19 +304,19 @@ class BOSHConnectionPoolTest : public CppUnit::TestFixture {
eventLoop->processEvents();
CPPUNIT_ASSERT_EQUAL(st(1), boshDataWritten.size()); /* Shouldn't have sent anything extra */
eventLoop->processEvents();
testling->restartStream();
eventLoop->processEvents();
CPPUNIT_ASSERT_EQUAL(st(2), boshDataWritten.size());
readResponse("<body></body>", c0);
eventLoop->processEvents();
CPPUNIT_ASSERT_EQUAL(st(3), boshDataWritten.size());
- std::string fullBody = "<body rid='" + boost::lexical_cast<std::string>(initialRID + 2) + "' sid='" + sid + "' xmlns='http://jabber.org/protocol/httpbind'></body>";
+ std::string fullBody = "<body rid='" + std::to_string(initialRID + 2) + "' sid='" + sid + "' xmlns='http://jabber.org/protocol/httpbind'></body>";
std::string response = boshDataWritten[2];
size_t bodyPosition = response.find("\r\n\r\n");
CPPUNIT_ASSERT_EQUAL(fullBody, response.substr(bodyPosition+4));
}
private:
@@ -421,32 +421,32 @@ class BOSHConnectionPoolTest : public CppUnit::TestFixture {
void readResponse(const std::string& response, std::shared_ptr<MockConnection> connection) {
connection->pending = false;
std::shared_ptr<SafeByteArray> data1 = std::make_shared<SafeByteArray>(createSafeByteArray(
"HTTP/1.1 200 OK\r\n"
"Content-Type: text/xml; charset=utf-8\r\n"
"Access-Control-Allow-Origin: *\r\n"
"Access-Control-Allow-Headers: Content-Type\r\n"
"Content-Length: "));
connection->onDataRead(data1);
- std::shared_ptr<SafeByteArray> data2 = std::make_shared<SafeByteArray>(createSafeByteArray(boost::lexical_cast<std::string>(response.size())));
+ std::shared_ptr<SafeByteArray> data2 = std::make_shared<SafeByteArray>(createSafeByteArray(std::to_string(response.size())));
connection->onDataRead(data2);
std::shared_ptr<SafeByteArray> data3 = std::make_shared<SafeByteArray>(createSafeByteArray("\r\n\r\n"));
connection->onDataRead(data3);
std::shared_ptr<SafeByteArray> data4 = std::make_shared<SafeByteArray>(createSafeByteArray(response));
connection->onDataRead(data4);
}
std::string fullRequestFor(const std::string& data) {
std::string body = data;
std::string result = "POST /" + path + " HTTP/1.1\r\n"
+ "Host: " + to + ":" + port + "\r\n"
+ "Content-Type: text/xml; charset=utf-8\r\n"
- + "Content-Length: " + boost::lexical_cast<std::string>(body.size()) + "\r\n\r\n"
+ + "Content-Length: " + std::to_string(body.size()) + "\r\n\r\n"
+ body;
return result;
}
private:
URL boshURL;
DummyEventLoop* eventLoop;
MockConnectionFactory* connectionFactory;
std::vector<std::string> xmppDataRead;
diff --git a/Swiften/Network/UnitTest/BOSHConnectionTest.cpp b/Swiften/Network/UnitTest/BOSHConnectionTest.cpp
index e34cb96..17d8333 100644
--- a/Swiften/Network/UnitTest/BOSHConnectionTest.cpp
+++ b/Swiften/Network/UnitTest/BOSHConnectionTest.cpp
@@ -312,19 +312,19 @@ class BOSHConnectionTest : public CppUnit::TestFixture {
void readResponse(const std::string& response, std::shared_ptr<MockConnection> connection) {
std::shared_ptr<SafeByteArray> data1 = std::make_shared<SafeByteArray>(createSafeByteArray(
"HTTP/1.1 200 OK\r\n"
"Content-Type: text/xml; charset=utf-8\r\n"
"Access-Control-Allow-Origin: *\r\n"
"Access-Control-Allow-Headers: Content-Type\r\n"
"Content-Length: "));
connection->onDataRead(data1);
- std::shared_ptr<SafeByteArray> data2 = std::make_shared<SafeByteArray>(createSafeByteArray(boost::lexical_cast<std::string>(response.size())));
+ std::shared_ptr<SafeByteArray> data2 = std::make_shared<SafeByteArray>(createSafeByteArray(std::to_string(response.size())));
connection->onDataRead(data2);
std::shared_ptr<SafeByteArray> data3 = std::make_shared<SafeByteArray>(createSafeByteArray("\r\n\r\n"));
connection->onDataRead(data3);
std::shared_ptr<SafeByteArray> data4 = std::make_shared<SafeByteArray>(createSafeByteArray(response));
connection->onDataRead(data4);
}
private:
diff --git a/Swiften/Network/UnitTest/ConnectorTest.cpp b/Swiften/Network/UnitTest/ConnectorTest.cpp
index 8524439..065911d 100644
--- a/Swiften/Network/UnitTest/ConnectorTest.cpp
+++ b/Swiften/Network/UnitTest/ConnectorTest.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 <boost/optional.hpp>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
@@ -20,18 +20,19 @@
#include <Swiften/Network/StaticDomainNameResolver.h>
using namespace Swift;
class ConnectorTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(ConnectorTest);
CPPUNIT_TEST(testConnect);
CPPUNIT_TEST(testConnect_NoServiceLookups);
CPPUNIT_TEST(testConnect_NoServiceLookups_DefaultPort);
+ CPPUNIT_TEST(testConnect_OnlyLiteral);
CPPUNIT_TEST(testConnect_FirstAddressHostFails);
CPPUNIT_TEST(testConnect_NoSRVHost);
CPPUNIT_TEST(testConnect_NoHosts);
CPPUNIT_TEST(testConnect_FirstSRVHostFails);
CPPUNIT_TEST(testConnect_AllSRVHostsFailWithoutFallbackHost);
CPPUNIT_TEST(testConnect_AllSRVHostsFailWithFallbackHost);
CPPUNIT_TEST(testConnect_SRVAndFallbackHostsFail);
//CPPUNIT_TEST(testConnect_TimeoutDuringResolve);
CPPUNIT_TEST(testConnect_TimeoutDuringConnectToOnlyCandidate);
@@ -85,46 +86,61 @@ class ConnectorTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(connections.size()));
CPPUNIT_ASSERT(connections[0]);
CPPUNIT_ASSERT(host3.getAddress() == (*(connections[0]->hostAddressPort)).getAddress());
CPPUNIT_ASSERT(4321 == (*(connections[0]->hostAddressPort)).getPort());
CPPUNIT_ASSERT(!std::dynamic_pointer_cast<DomainNameResolveError>(error));
}
void testConnect_NoServiceLookups_DefaultPort() {
- Connector::ref testling(createConnector(-1, boost::optional<std::string>()));
+ Connector::ref testling(createConnector(0, boost::optional<std::string>()));
resolver->addXMPPClientService("foo.com", host1);
resolver->addXMPPClientService("foo.com", host2);
resolver->addAddress("foo.com", host3.getAddress());
testling->start();
eventLoop->processEvents();
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(connections.size()));
CPPUNIT_ASSERT(connections[0]);
CPPUNIT_ASSERT(host3.getAddress() == (*(connections[0]->hostAddressPort)).getAddress());
- CPPUNIT_ASSERT_EQUAL(5222, (*(connections[0]->hostAddressPort)).getPort());
+ CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(5222), (*(connections[0]->hostAddressPort)).getPort());
CPPUNIT_ASSERT(!std::dynamic_pointer_cast<DomainNameResolveError>(error));
}
void testConnect_NoSRVHost() {
Connector::ref testling(createConnector());
resolver->addAddress("foo.com", host3.getAddress());
testling->start();
eventLoop->processEvents();
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(connections.size()));
CPPUNIT_ASSERT(connections[0]);
CPPUNIT_ASSERT(host3 == *(connections[0]->hostAddressPort));
CPPUNIT_ASSERT(!std::dynamic_pointer_cast<DomainNameResolveError>(error));
}
+ void testConnect_OnlyLiteral() {
+ auto testling = Connector::create("1.1.1.1", 1234, boost::none, resolver, connectionFactory, timerFactory);
+ testling->onConnectFinished.connect(boost::bind(&ConnectorTest::handleConnectorFinished, this, _1, _2));
+
+ auto address1 = HostAddress::fromString("1.1.1.1").get();
+ connectionFactory->failingPorts.push_back(HostAddressPort(address1, 1234));
+
+ testling->start();
+ eventLoop->processEvents();
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(connections.size()));
+ CPPUNIT_ASSERT(!connections[0]);
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(connectionFactory->createdConnections.size()));
+ }
+
void testConnect_FirstAddressHostFails() {
Connector::ref testling(createConnector());
auto address1 = HostAddress::fromString("1.1.1.1").get();
auto address2 = HostAddress::fromString("2.2.2.2").get();
resolver->addXMPPClientService("foo.com", "host-foo.com", 1234);
resolver->addAddress("host-foo.com", address1);
resolver->addAddress("host-foo.com", address2);
connectionFactory->failingPorts.push_back(HostAddressPort(address1, 1234));
@@ -306,19 +322,19 @@ class ConnectorTest : public CppUnit::TestFixture {
timerFactory->setTime(10);
eventLoop->processEvents();
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(connections.size()));
CPPUNIT_ASSERT(!connections[0]);
}
private:
- Connector::ref createConnector(int port = -1, boost::optional<std::string> serviceLookupPrefix = boost::optional<std::string>("_xmpp-client._tcp.")) {
+ Connector::ref createConnector(unsigned short port = 0, boost::optional<std::string> serviceLookupPrefix = boost::optional<std::string>("_xmpp-client._tcp.")) {
Connector::ref connector = Connector::create("foo.com", port, serviceLookupPrefix, resolver, connectionFactory, timerFactory);
connector->onConnectFinished.connect(boost::bind(&ConnectorTest::handleConnectorFinished, this, _1, _2));
return connector;
}
void handleConnectorFinished(std::shared_ptr<Connection> connection, std::shared_ptr<Error> resultError) {
std::shared_ptr<MockConnection> c(std::dynamic_pointer_cast<MockConnection>(connection));
if (connection) {
assert(c);
@@ -350,24 +366,27 @@ class ConnectorTest : public CppUnit::TestFixture {
std::vector<HostAddressPort> failingPorts;
bool isResponsive;
};
struct MockConnectionFactory : public ConnectionFactory {
MockConnectionFactory(EventLoop* eventLoop) : eventLoop(eventLoop), isResponsive(true) {
}
std::shared_ptr<Connection> createConnection() {
- return std::make_shared<MockConnection>(failingPorts, isResponsive, eventLoop);
+ auto connection = std::make_shared<MockConnection>(failingPorts, isResponsive, eventLoop);
+ createdConnections.push_back(connection);
+ return connection;
}
EventLoop* eventLoop;
bool isResponsive;
std::vector<HostAddressPort> failingPorts;
+ std::vector<std::shared_ptr<MockConnection>> createdConnections;
};
private:
HostAddressPort host1;
HostAddressPort host2;
HostAddressPort host3;
DummyEventLoop* eventLoop;
StaticDomainNameResolver* resolver;
MockConnectionFactory* connectionFactory;
diff --git a/Swiften/Network/UnitTest/HTTPConnectProxiedConnectionTest.cpp b/Swiften/Network/UnitTest/HTTPConnectProxiedConnectionTest.cpp
index 1a160b7..065d015 100644
--- a/Swiften/Network/UnitTest/HTTPConnectProxiedConnectionTest.cpp
+++ b/Swiften/Network/UnitTest/HTTPConnectProxiedConnectionTest.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 <memory>
#include <boost/algorithm/string.hpp>
#include <boost/bind.hpp>
#include <boost/lexical_cast.hpp>
@@ -415,19 +415,19 @@ class HTTPConnectProxiedConnectionTest : public CppUnit::TestFixture {
EventLoop* eventLoop;
std::vector< std::shared_ptr<MockConnection> > connections;
std::vector<HostAddressPort> failingPorts;
};
private:
std::string proxyHost;
HostAddressPort proxyHostAddress;
- int proxyPort;
+ unsigned short proxyPort;
HostAddressPort host;
DummyEventLoop* eventLoop;
StaticDomainNameResolver* resolver;
MockConnectionFactory* connectionFactory;
TimerFactory* timerFactory;
bool connectFinished;
bool connectFinishedWithError;
bool disconnected;
boost::optional<Connection::Error> disconnectedError;
diff --git a/Swiften/Network/UnitTest/HostAddressTest.cpp b/Swiften/Network/UnitTest/HostAddressTest.cpp
index 226346b..bd345a7 100644
--- a/Swiften/Network/UnitTest/HostAddressTest.cpp
+++ b/Swiften/Network/UnitTest/HostAddressTest.cpp
@@ -1,32 +1,34 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <string>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <Swiften/Network/HostAddress.h>
+#include <Swiften/Network/HostAddressPort.h>
using namespace Swift;
class HostAddressTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(HostAddressTest);
CPPUNIT_TEST(testConstructor);
CPPUNIT_TEST(testConstructor_Invalid);
CPPUNIT_TEST(testConstructor_InvalidString);
CPPUNIT_TEST(testToString);
CPPUNIT_TEST(testToString_IPv6);
CPPUNIT_TEST(testToString_Invalid);
+ CPPUNIT_TEST(testComparison);
CPPUNIT_TEST_SUITE_END();
public:
void testConstructor() {
auto testling = HostAddress::fromString("192.168.1.254");
CPPUNIT_ASSERT_EQUAL(std::string("192.168.1.254"), testling->toString());
CPPUNIT_ASSERT(testling->isValid());
}
@@ -56,12 +58,38 @@ class HostAddressTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(std::string("102:304:506:708:90a:b0c:d0e:f11"), testling.toString());
}
void testToString_Invalid() {
HostAddress testling;
CPPUNIT_ASSERT_EQUAL(std::string("0.0.0.0"), testling.toString());
}
+
+ void testComparison() {
+ auto ha127_0_0_1 = *HostAddress::fromString("127.0.0.1");
+ auto ha127_0_0_2 = *HostAddress::fromString("127.0.0.2");
+ auto ha127_0_1_0 = *HostAddress::fromString("127.0.1.0");
+
+ CPPUNIT_ASSERT(ha127_0_0_1 < ha127_0_0_2);
+ CPPUNIT_ASSERT(ha127_0_0_2 < ha127_0_1_0);
+ CPPUNIT_ASSERT(!(ha127_0_0_1 < ha127_0_0_1));
+ CPPUNIT_ASSERT(!(ha127_0_0_2 < ha127_0_0_1));
+ CPPUNIT_ASSERT(!(ha127_0_0_2 == ha127_0_0_1));
+ CPPUNIT_ASSERT(ha127_0_0_1 == ha127_0_0_1);
+
+ auto hap_127_0_0_1__1 = HostAddressPort(ha127_0_0_1, 1);
+ auto hap_127_0_0_1__2 = HostAddressPort(ha127_0_0_1, 2);
+ auto hap_127_0_0_2__1 = HostAddressPort(ha127_0_0_2, 1);
+ auto hap_127_0_0_2__2 = HostAddressPort(ha127_0_0_2, 2);
+
+ CPPUNIT_ASSERT(hap_127_0_0_1__1 < hap_127_0_0_1__2);
+ CPPUNIT_ASSERT(!(hap_127_0_0_1__1 < hap_127_0_0_1__1));
+ CPPUNIT_ASSERT(!(hap_127_0_0_1__1 == hap_127_0_0_1__2));
+ CPPUNIT_ASSERT(hap_127_0_0_1__1 == hap_127_0_0_1__1);
+ CPPUNIT_ASSERT(!(hap_127_0_0_1__2 == hap_127_0_0_1__1));
+ CPPUNIT_ASSERT(hap_127_0_0_1__2 < hap_127_0_0_2__1);
+ CPPUNIT_ASSERT(hap_127_0_0_2__1 < hap_127_0_0_2__2);
+ }
};
CPPUNIT_TEST_SUITE_REGISTRATION(HostAddressTest);