summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2015-06-30 07:50:35 (GMT)
committerKevin Smith <kevin.smith@isode.com>2015-07-07 19:58:27 (GMT)
commitf4b96b3e1d66f1a7f3e13f5d3e3b293509190db2 (patch)
treea99c28033760dfbdbd5b6e592cca7ea56e42cd36
parent799a7ac203dc2576872894dfdd1adb5cdbbacf7b (diff)
downloadswift-f4b96b3e1d66f1a7f3e13f5d3e3b293509190db2.zip
swift-f4b96b3e1d66f1a7f3e13f5d3e3b293509190db2.tar.bz2
Use environment variables for addresses used in NetworkTest
Introducing SWIFT_NETWORK_TEST_IPV4 and SWIFT_NETWORK_TEST_IPV6 for the host addresses used in BoostConnectionTest.cpp. Passing these variables and ASAN/LSAN_OPTIONS for memory leak detection when calling the test from SCons. Test-Information: Tested on Elementary OS with correct available hosts and unavailable hosts. In both cases the behavior is the same as before. Change-Id: I24128c766642c5a2ee273f7c11624525ae33e270
-rw-r--r--BuildTools/SCons/Tools/Test.py2
-rw-r--r--Swiften/QA/NetworkTest/BoostConnectionTest.cpp64
2 files changed, 33 insertions, 33 deletions
diff --git a/BuildTools/SCons/Tools/Test.py b/BuildTools/SCons/Tools/Test.py
index 7e4609d..1eee4f6 100644
--- a/BuildTools/SCons/Tools/Test.py
+++ b/BuildTools/SCons/Tools/Test.py
@@ -19,7 +19,7 @@ def generate(env) :
# Set environment variables for running the test
test_env = env.Clone()
- for i in ["HOME", "USERPROFILE", "APPDATA"]:
+ for i in ["HOME", "USERPROFILE", "APPDATA", "ASAN_OPTIONS", "LSAN_OPTIONS", "SWIFT_NETWORK_TEST_IPV4", "SWIFT_NETWORK_TEST_IPV6"]:
if os.environ.get(i, "") :
test_env["ENV"][i] = os.environ[i]
if env["target"] == "android" :
diff --git a/Swiften/QA/NetworkTest/BoostConnectionTest.cpp b/Swiften/QA/NetworkTest/BoostConnectionTest.cpp
index 0cb38c3..484c5e3 100644
--- a/Swiften/QA/NetworkTest/BoostConnectionTest.cpp
+++ b/Swiften/QA/NetworkTest/BoostConnectionTest.cpp
@@ -4,21 +4,21 @@
* See the COPYING file for more information.
*/
-#include <cppunit/extensions/HelperMacros.h>
-#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <string>
+
#include <boost/shared_ptr.hpp>
#include <boost/smart_ptr/make_shared.hpp>
-#include <string>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
#include <Swiften/Base/Algorithm.h>
#include <Swiften/Base/sleep.h>
+#include <Swiften/EventLoop/DummyEventLoop.h>
#include <Swiften/Network/BoostConnection.h>
+#include <Swiften/Network/BoostIOServiceThread.h>
#include <Swiften/Network/HostAddress.h>
#include <Swiften/Network/HostAddressPort.h>
-#include <Swiften/Network/BoostIOServiceThread.h>
-#include <Swiften/EventLoop/DummyEventLoop.h>
-
-static const unsigned char* address = reinterpret_cast<const unsigned char*>("\x4A\x32\x3e\x31");
using namespace Swift;
@@ -37,9 +37,9 @@ class BoostConnectionTest : public CppUnit::TestFixture {
void setUp() {
eventLoop_ = new DummyEventLoop();
boostIOServiceThread_ = new BoostIOServiceThread();
- boostIOService = boost::make_shared<boost::asio::io_service>();
- disconnected = false;
- connectFinished = false;
+ boostIOService_ = boost::make_shared<boost::asio::io_service>();
+ disconnected_ = false;
+ connectFinished_ = false;
}
void tearDown() {
@@ -53,14 +53,14 @@ class BoostConnectionTest : public CppUnit::TestFixture {
void testDestructor() {
{
BoostConnection::ref testling(BoostConnection::create(boostIOServiceThread_->getIOService(), eventLoop_));
- testling->connect(HostAddressPort(HostAddress(address, 4), 5222));
+ testling->connect(HostAddressPort(HostAddress(getenv("SWIFT_NETWORK_TEST_IPV4")), 5222));
}
}
void testDestructor_PendingEvents() {
{
BoostConnection::ref testling(BoostConnection::create(boostIOServiceThread_->getIOService(), eventLoop_));
- testling->connect(HostAddressPort(HostAddress(address, 4), 5222));
+ testling->connect(HostAddressPort(HostAddress(getenv("SWIFT_NETWORK_TEST_IPV4")), 5222));
while (!eventLoop_->hasEvents()) {
Swift::sleep(10);
}
@@ -73,8 +73,8 @@ class BoostConnectionTest : public CppUnit::TestFixture {
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("74.50.62.49"), 5222));
- while (receivedData.empty()) {
+ testling->connect(HostAddressPort(HostAddress(getenv("SWIFT_NETWORK_TEST_IPV4")), 5222));
+ while (receivedData_.empty()) {
Swift::sleep(10);
eventLoop_->processEvents();
}
@@ -86,8 +86,8 @@ class BoostConnectionTest : public CppUnit::TestFixture {
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("2001:470:1f0e:852::2"), 80));
- while (receivedData.empty()) {
+ testling->connect(HostAddressPort(HostAddress(getenv("SWIFT_NETWORK_TEST_IPV6")), 80));
+ while (receivedData_.empty()) {
Swift::sleep(10);
eventLoop_->processEvents();
}
@@ -96,13 +96,13 @@ class BoostConnectionTest : public CppUnit::TestFixture {
void testWriteMultipleSimultaniouslyQueuesWrites() {
- BoostConnection::ref testling(BoostConnection::create(boostIOService, eventLoop_));
+ 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("74.50.62.49"), 5222));
- while (!connectFinished) {
- boostIOService->run_one();
+ testling->connect(HostAddressPort(HostAddress(getenv("SWIFT_NETWORK_TEST_IPV4")), 5222));
+ while (!connectFinished_) {
+ boostIOService_->run_one();
eventLoop_->processEvents();
}
@@ -111,20 +111,20 @@ class BoostConnectionTest : public CppUnit::TestFixture {
testling->write(createSafeByteArray(">"));
// Check that we only did one write event, the others are queued
- /*int runHandlers = */boostIOService->poll();
+ /*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();
+ while (receivedData_.empty()) {
+ boostIOService_->run_one();
eventLoop_->processEvents();
}
// Disconnect & clean up
testling->disconnect();
- while (!disconnected) {
- boostIOService->run_one();
+ while (!disconnected_) {
+ boostIOService_->run_one();
eventLoop_->processEvents();
}
}
@@ -135,24 +135,24 @@ class BoostConnectionTest : public CppUnit::TestFixture {
}
void handleDataRead(boost::shared_ptr<SafeByteArray> data) {
- append(receivedData, *data);
+ append(receivedData_, *data);
}
void handleDisconnected() {
- disconnected = true;
+ disconnected_ = true;
}
void handleConnectFinished() {
- connectFinished = true;
+ connectFinished_ = true;
}
private:
BoostIOServiceThread* boostIOServiceThread_;
- boost::shared_ptr<boost::asio::io_service> boostIOService;
+ boost::shared_ptr<boost::asio::io_service> boostIOService_;
DummyEventLoop* eventLoop_;
- ByteArray receivedData;
- bool disconnected;
- bool connectFinished;
+ ByteArray receivedData_;
+ bool disconnected_;
+ bool connectFinished_;
};
CPPUNIT_TEST_SUITE_REGISTRATION(BoostConnectionTest);