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
@@ -194,7 +194,7 @@ class BOSHConnectionPoolTest : public CppUnit::TestFixture {
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);
@@ -310,7 +310,7 @@ class BOSHConnectionPoolTest : public CppUnit::TestFixture {
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));
@@ -427,7 +427,7 @@ class BOSHConnectionPoolTest : public CppUnit::TestFixture {
"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);
@@ -440,7 +440,7 @@ class BOSHConnectionPoolTest : public CppUnit::TestFixture {
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;
}
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
@@ -318,7 +318,7 @@ class BOSHConnectionTest : public CppUnit::TestFixture {
"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);
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,5 +1,5 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -26,6 +26,7 @@ class ConnectorTest : public CppUnit::TestFixture {
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);
@@ -91,7 +92,7 @@ class ConnectorTest : public CppUnit::TestFixture {
}
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());
@@ -102,7 +103,7 @@ 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_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));
}
@@ -119,6 +120,21 @@ class ConnectorTest : public CppUnit::TestFixture {
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());
@@ -312,7 +328,7 @@ class ConnectorTest : public CppUnit::TestFixture {
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;
@@ -356,12 +372,15 @@ class ConnectorTest : public CppUnit::TestFixture {
}
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:
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,5 +1,5 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -421,7 +421,7 @@ class HTTPConnectProxiedConnectionTest : public CppUnit::TestFixture {
private:
std::string proxyHost;
HostAddressPort proxyHostAddress;
- int proxyPort;
+ unsigned short proxyPort;
HostAddressPort host;
DummyEventLoop* eventLoop;
StaticDomainNameResolver* resolver;
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,5 +1,5 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -10,6 +10,7 @@
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <Swiften/Network/HostAddress.h>
+#include <Swiften/Network/HostAddressPort.h>
using namespace Swift;
@@ -21,6 +22,7 @@ class HostAddressTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testToString);
CPPUNIT_TEST(testToString_IPv6);
CPPUNIT_TEST(testToString_Invalid);
+ CPPUNIT_TEST(testComparison);
CPPUNIT_TEST_SUITE_END();
public:
@@ -62,6 +64,32 @@ class HostAddressTest : public CppUnit::TestFixture {
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);