diff options
Diffstat (limited to 'Swiften/QA/NetworkTest')
-rw-r--r-- | Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp | 24 | ||||
-rwxr-xr-x | Swiften/QA/NetworkTest/BoostConnectionTest.cpp | 21 | ||||
-rw-r--r-- | Swiften/QA/NetworkTest/DomainNameResolverTest.cpp | 2 |
3 files changed, 29 insertions, 18 deletions
diff --git a/Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp b/Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp index 11b0eb5..6982c0c 100644 --- a/Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp +++ b/Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp @@ -49,167 +49,167 @@ class BoostConnectionServerTest : public CppUnit::TestFixture { void testConstructor_TwoServersOnSamePort() { BoostConnectionServer::ref testling(BoostConnectionServer::create(9999, boostIOServiceThread_->getIOService(), eventLoop_)); BoostConnectionServer::ref testling2(BoostConnectionServer::create(9999, boostIOServiceThread_->getIOService(), eventLoop_)); } void testStart_Conflict() { BoostConnectionServer::ref testling(BoostConnectionServer::create(9999, boostIOServiceThread_->getIOService(), eventLoop_)); testling->start(); BoostConnectionServer::ref testling2(BoostConnectionServer::create(9999, boostIOServiceThread_->getIOService(), eventLoop_)); testling2->onStopped.connect( boost::bind(&BoostConnectionServerTest::handleStopped_, this, _1)); testling->stop(); } void testStop() { BoostConnectionServer::ref testling(BoostConnectionServer::create(9999, boostIOServiceThread_->getIOService(), eventLoop_)); testling->start(); testling->stop(); BoostConnectionServer::ref testling2(BoostConnectionServer::create(9999, boostIOServiceThread_->getIOService(), eventLoop_)); testling2->start(); testling2->stop(); } void testIPv4Server() { - BoostConnectionServer::ref testling = BoostConnectionServer::create(HostAddress("127.0.0.1"), 9999, boostIOServiceThread_->getIOService(), eventLoop_); + BoostConnectionServer::ref testling = BoostConnectionServer::create(HostAddress::fromString("127.0.0.1").get(), 9999, boostIOServiceThread_->getIOService(), eventLoop_); testling->onNewConnection.connect(boost::bind(&BoostConnectionServerTest::handleNewConnection, this, _1)); testling->start(); BoostConnection::ref clientTestling = BoostConnection::create(boostIOServiceThread_->getIOService(), eventLoop_); clientTestling->onConnectFinished.connect(boost::bind(&BoostConnectionServerTest::handleConnectFinished, this, _1)); - clientTestling->connect(HostAddressPort(HostAddress("127.0.0.1"), 9999)); + clientTestling->connect(HostAddressPort(HostAddress::fromString("127.0.0.1").get(), 9999)); while (!connectFinished_) { Swift::sleep(10); eventLoop_->processEvents(); } CPPUNIT_ASSERT_EQUAL(true, receivedNewConnection_); testling->stop(); } void testIPv6Server() { - BoostConnectionServer::ref testling = BoostConnectionServer::create(HostAddress("::1"), 9999, boostIOServiceThread_->getIOService(), eventLoop_); + BoostConnectionServer::ref testling = BoostConnectionServer::create(HostAddress::fromString("::1").get(), 9999, boostIOServiceThread_->getIOService(), eventLoop_); testling->onNewConnection.connect(boost::bind(&BoostConnectionServerTest::handleNewConnection, this, _1)); testling->start(); BoostConnection::ref clientTestling = BoostConnection::create(boostIOServiceThread_->getIOService(), eventLoop_); clientTestling->onConnectFinished.connect(boost::bind(&BoostConnectionServerTest::handleConnectFinished, this, _1)); - clientTestling->connect(HostAddressPort(HostAddress("::1"), 9999)); + clientTestling->connect(HostAddressPort(HostAddress::fromString("::1").get(), 9999)); while (!connectFinished_) { Swift::sleep(10); eventLoop_->processEvents(); } CPPUNIT_ASSERT_EQUAL(true, receivedNewConnection_); testling->stop(); } void testIPv4IPv6DualStackServer() { - BoostConnectionServer::ref testling = BoostConnectionServer::create(HostAddress("::"), 9999, boostIOServiceThread_->getIOService(), eventLoop_); + BoostConnectionServer::ref testling = BoostConnectionServer::create(HostAddress::fromString("::").get(), 9999, boostIOServiceThread_->getIOService(), eventLoop_); testling->onNewConnection.connect(boost::bind(&BoostConnectionServerTest::handleNewConnection, this, _1)); testling->start(); // Test IPv4. BoostConnection::ref clientTestling = BoostConnection::create(boostIOServiceThread_->getIOService(), eventLoop_); clientTestling->onConnectFinished.connect(boost::bind(&BoostConnectionServerTest::handleConnectFinished, this, _1)); - clientTestling->connect(HostAddressPort(HostAddress("127.0.0.1"), 9999)); + clientTestling->connect(HostAddressPort(HostAddress::fromString("127.0.0.1").get(), 9999)); while (!connectFinished_) { Swift::sleep(10); eventLoop_->processEvents(); } CPPUNIT_ASSERT_EQUAL(true, receivedNewConnection_); receivedNewConnection_ = false; connectFinished_ = false; // Test IPv6. clientTestling = BoostConnection::create(boostIOServiceThread_->getIOService(), eventLoop_); clientTestling->onConnectFinished.connect(boost::bind(&BoostConnectionServerTest::handleConnectFinished, this, _1)); - clientTestling->connect(HostAddressPort(HostAddress("::1"), 9999)); + clientTestling->connect(HostAddressPort(HostAddress::fromString("::1").get(), 9999)); while (!connectFinished_) { Swift::sleep(10); eventLoop_->processEvents(); } CPPUNIT_ASSERT_EQUAL(true, receivedNewConnection_); testling->stop(); } void testIPv6DualStackServerPeerAddress() { - BoostConnectionServer::ref testling = BoostConnectionServer::create(HostAddress("::"), 9999, boostIOServiceThread_->getIOService(), eventLoop_); + BoostConnectionServer::ref testling = BoostConnectionServer::create(HostAddress::fromString("::").get(), 9999, boostIOServiceThread_->getIOService(), eventLoop_); testling->onNewConnection.connect(boost::bind(&BoostConnectionServerTest::handleNewConnection, this, _1)); testling->start(); // Test IPv4. BoostConnection::ref clientTestling = BoostConnection::create(boostIOServiceThread_->getIOService(), eventLoop_); clientTestling->onConnectFinished.connect(boost::bind(&BoostConnectionServerTest::handleConnectFinished, this, _1)); - clientTestling->connect(HostAddressPort(HostAddress("127.0.0.1"), 9999)); + clientTestling->connect(HostAddressPort(HostAddress::fromString("127.0.0.1").get(), 9999)); while (!connectFinished_) { Swift::sleep(10); eventLoop_->processEvents(); } CPPUNIT_ASSERT_EQUAL(true, receivedNewConnection_); // The IPv4 localhost mapped to a IPv6 address is expected here. - CPPUNIT_ASSERT(HostAddress("::ffff:127.0.0.1") == remoteAddress_.get().getAddress()); + CPPUNIT_ASSERT(HostAddress::fromString("::ffff:127.0.0.1").get() == remoteAddress_.get().getAddress()); receivedNewConnection_ = false; connectFinished_ = false; remoteAddress_ = boost::optional<HostAddressPort>(); // Test IPv6. clientTestling = BoostConnection::create(boostIOServiceThread_->getIOService(), eventLoop_); clientTestling->onConnectFinished.connect(boost::bind(&BoostConnectionServerTest::handleConnectFinished, this, _1)); - clientTestling->connect(HostAddressPort(HostAddress("::1"), 9999)); + clientTestling->connect(HostAddressPort(HostAddress::fromString("::1").get(), 9999)); while (!connectFinished_) { Swift::sleep(10); eventLoop_->processEvents(); } CPPUNIT_ASSERT_EQUAL(true, receivedNewConnection_); // The IPv6 local host is expected here. - CPPUNIT_ASSERT(HostAddress("::1") == remoteAddress_.get().getAddress()); + CPPUNIT_ASSERT(HostAddress::fromString("::1").get() == remoteAddress_.get().getAddress()); testling->stop(); } void handleStopped_(boost::optional<BoostConnectionServer::Error> e) { stopped_ = true; stoppedError_ = e; } void handleNewConnection(std::shared_ptr<Connection> connection) { receivedNewConnection_ = true; remoteAddress_ = connection->getRemoteAddress(); } void handleConnectFinished(bool /*error*/) { connectFinished_ = true; } private: BoostIOServiceThread* boostIOServiceThread_; DummyEventLoop* eventLoop_; bool stopped_; bool receivedNewConnection_; bool connectFinished_; boost::optional<BoostConnectionServer::Error> stoppedError_; boost::optional<HostAddressPort> remoteAddress_; }; CPPUNIT_TEST_SUITE_REGISTRATION(BoostConnectionServerTest); diff --git a/Swiften/QA/NetworkTest/BoostConnectionTest.cpp b/Swiften/QA/NetworkTest/BoostConnectionTest.cpp index 12c4a77..e0890bf 100755 --- a/Swiften/QA/NetworkTest/BoostConnectionTest.cpp +++ b/Swiften/QA/NetworkTest/BoostConnectionTest.cpp @@ -26,118 +26,129 @@ class BoostConnectionTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(BoostConnectionTest); CPPUNIT_TEST(testDestructor); CPPUNIT_TEST(testDestructor_PendingEvents); CPPUNIT_TEST(testWrite); CPPUNIT_TEST(testWriteMultipleSimultaniouslyQueuesWrites); #ifdef TEST_IPV6 CPPUNIT_TEST(testWrite_IPv6); #endif CPPUNIT_TEST_SUITE_END(); public: void setUp() { eventLoop_ = new DummyEventLoop(); boostIOServiceThread_ = new BoostIOServiceThread(); boostIOService_ = std::make_shared<boost::asio::io_service>(); disconnected_ = false; connectFinished_ = false; } void tearDown() { delete boostIOServiceThread_; while (eventLoop_->hasEvents()) { eventLoop_->processEvents(); } delete eventLoop_; } void testDestructor() { { BoostConnection::ref testling(BoostConnection::create(boostIOServiceThread_->getIOService(), eventLoop_)); - testling->connect(HostAddressPort(HostAddress(getenv("SWIFT_NETWORK_TEST_IPV4")), 5222)); + auto hostAddress = HostAddress::fromString(getenv("SWIFT_NETWORK_TEST_IPV4")); + CPPUNIT_ASSERT_EQUAL(true, hostAddress.is_initialized()); + testling->connect(HostAddressPort(hostAddress.get(), 5222)); } } void testDestructor_PendingEvents() { { BoostConnection::ref testling(BoostConnection::create(boostIOServiceThread_->getIOService(), eventLoop_)); - testling->connect(HostAddressPort(HostAddress(getenv("SWIFT_NETWORK_TEST_IPV4")), 5222)); + auto hostAddress = HostAddress::fromString(getenv("SWIFT_NETWORK_TEST_IPV4")); + CPPUNIT_ASSERT_EQUAL(true, hostAddress.is_initialized()); + testling->connect(HostAddressPort(hostAddress.get(), 5222)); while (!eventLoop_->hasEvents()) { Swift::sleep(10); } } eventLoop_->processEvents(); } void testWrite() { using namespace boost::posix_time; BoostConnection::ref testling(BoostConnection::create(boostIOServiceThread_->getIOService(), eventLoop_)); testling->onConnectFinished.connect(boost::bind(&BoostConnectionTest::doWrite, this, testling.get())); testling->onDataRead.connect(boost::bind(&BoostConnectionTest::handleDataRead, this, _1)); testling->onDisconnected.connect(boost::bind(&BoostConnectionTest::handleDisconnected, this)); - testling->connect(HostAddressPort(HostAddress(getenv("SWIFT_NETWORK_TEST_IPV4")), 5222)); + auto hostAddress = HostAddress::fromString(getenv("SWIFT_NETWORK_TEST_IPV4")); + CPPUNIT_ASSERT_EQUAL(true, hostAddress.is_initialized()); + testling->connect(HostAddressPort(hostAddress.get(), 5222)); boost::posix_time::ptime start = second_clock::local_time(); while (receivedData_.empty() && ((second_clock::local_time() - start) < seconds(60))) { Swift::sleep(10); eventLoop_->processEvents(); } CPPUNIT_ASSERT_EQUAL(false, receivedData_.empty()); testling->disconnect(); } void testWrite_IPv6() { using namespace boost::posix_time; BoostConnection::ref testling(BoostConnection::create(boostIOServiceThread_->getIOService(), eventLoop_)); testling->onConnectFinished.connect(boost::bind(&BoostConnectionTest::doWrite, this, testling.get())); testling->onDataRead.connect(boost::bind(&BoostConnectionTest::handleDataRead, this, _1)); testling->onDisconnected.connect(boost::bind(&BoostConnectionTest::handleDisconnected, this)); - testling->connect(HostAddressPort(HostAddress(getenv("SWIFT_NETWORK_TEST_IPV6")), 5222)); + auto hostAddress = HostAddress::fromString(getenv("SWIFT_NETWORK_TEST_IPV6")); + CPPUNIT_ASSERT_EQUAL(true, hostAddress.is_initialized()); + testling->connect(HostAddressPort(hostAddress.get(), 5222)); boost::posix_time::ptime start = second_clock::local_time(); while (receivedData_.empty() && ((second_clock::local_time() - start) < seconds(60))) { Swift::sleep(10); eventLoop_->processEvents(); } CPPUNIT_ASSERT_EQUAL(false, receivedData_.empty()); testling->disconnect(); } void testWriteMultipleSimultaniouslyQueuesWrites() { BoostConnection::ref testling(BoostConnection::create(boostIOService_, eventLoop_)); testling->onConnectFinished.connect(boost::bind(&BoostConnectionTest::handleConnectFinished, this)); testling->onDataRead.connect(boost::bind(&BoostConnectionTest::handleDataRead, this, _1)); testling->onDisconnected.connect(boost::bind(&BoostConnectionTest::handleDisconnected, this)); - testling->connect(HostAddressPort(HostAddress(getenv("SWIFT_NETWORK_TEST_IPV4")), 5222)); + + auto hostAddress = HostAddress::fromString(getenv("SWIFT_NETWORK_TEST_IPV4")); + CPPUNIT_ASSERT_EQUAL(true, hostAddress.is_initialized()); + testling->connect(HostAddressPort(hostAddress.get(), 5222)); while (!connectFinished_) { boostIOService_->run_one(); eventLoop_->processEvents(); } testling->write(createSafeByteArray("<stream:strea")); testling->write(createSafeByteArray("m")); testling->write(createSafeByteArray(">")); // Check that we only did one write event, the others are queued /*int runHandlers = */boostIOService_->poll(); // Disabling this test, because poll runns all handlers that are added during poll() as well, so // this test doesn't really work any more. We'll have to trust that things are queued. //CPPUNIT_ASSERT_EQUAL(1, runHandlers); // Process the other events while (receivedData_.empty()) { boostIOService_->run_one(); eventLoop_->processEvents(); } // Disconnect & clean up testling->disconnect(); while (!disconnected_) { boostIOService_->run_one(); eventLoop_->processEvents(); } } void doWrite(BoostConnection* connection) { connection->write(createSafeByteArray("<stream:stream>")); diff --git a/Swiften/QA/NetworkTest/DomainNameResolverTest.cpp b/Swiften/QA/NetworkTest/DomainNameResolverTest.cpp index d45d118..95ebb6d 100644 --- a/Swiften/QA/NetworkTest/DomainNameResolverTest.cpp +++ b/Swiften/QA/NetworkTest/DomainNameResolverTest.cpp @@ -115,61 +115,61 @@ class DomainNameResolverTest : public CppUnit::TestFixture { void testResolveAddress_IPv4and6() { std::shared_ptr<DomainNameAddressQuery> query(createAddressQuery("xmpp-ipv46.test.swift.im")); query->run(); waitForResults(); CPPUNIT_ASSERT(!addressQueryError); CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(addressQueryResult.size())); CPPUNIT_ASSERT_EQUAL(std::string("10.0.0.7"), addressQueryResult[0].toString()); CPPUNIT_ASSERT_EQUAL(std::string("1234:5678:9abc:def0:fed:cba9:8765:4321"), addressQueryResult[1].toString()); } void testResolveAddress_International() { std::shared_ptr<DomainNameAddressQuery> query(createAddressQuery("tron\xc3\xa7on.test.swift.im")); query->run(); waitForResults(); CPPUNIT_ASSERT(!addressQueryError); CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(addressQueryResult.size())); CPPUNIT_ASSERT_EQUAL(std::string("10.0.0.3"), addressQueryResult[0].toString()); } void testResolveAddress_Localhost() { std::shared_ptr<DomainNameAddressQuery> query(createAddressQuery("localhost")); query->run(); waitForResults(); CPPUNIT_ASSERT(!addressQueryError); - CPPUNIT_ASSERT(std::find(addressQueryResult.begin(), addressQueryResult.end(), HostAddress("127.0.0.1")) != addressQueryResult.end()); + CPPUNIT_ASSERT(std::find(addressQueryResult.begin(), addressQueryResult.end(), HostAddress::fromString("127.0.0.1").get()) != addressQueryResult.end()); } void testResolveAddress_Parallel() { std::vector<DomainNameAddressQuery::ref> queries; static const size_t numQueries = 100; for (size_t i = 0; i < numQueries; ++i) { DomainNameAddressQuery::ref query(createAddressQuery("xmpp.test.swift.im")); queries.push_back(query); query->run(); } eventLoop->processEvents(); int ticks = 0; while (allAddressQueryResults.size() < numQueries) { ticks++; if (ticks > 1000) { CPPUNIT_ASSERT(false); } Swift::sleep(10); eventLoop->processEvents(); } CPPUNIT_ASSERT_EQUAL(numQueries, allAddressQueryResults.size()); for (size_t i = 0; i < numQueries; ++i) { CPPUNIT_ASSERT_EQUAL(std::string("10.0.0.0"), allAddressQueryResults[i].toString()); } } void testResolveService() { std::shared_ptr<DomainNameServiceQuery> query(createServiceQuery("_xmpp-client._tcp.", "xmpp-srv.test.swift.im")); |