From f4b96b3e1d66f1a7f3e13f5d3e3b293509190db2 Mon Sep 17 00:00:00 2001 From: Tobias Markmann Date: Tue, 30 Jun 2015 09:50:35 +0200 Subject: 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 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 -#include +#include + #include #include -#include +#include +#include + #include #include +#include #include +#include #include #include -#include -#include - -static const unsigned char* address = reinterpret_cast("\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(); - disconnected = false; - connectFinished = false; + boostIOService_ = boost::make_shared(); + 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 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 boostIOService; + boost::shared_ptr boostIOService_; DummyEventLoop* eventLoop_; - ByteArray receivedData; - bool disconnected; - bool connectFinished; + ByteArray receivedData_; + bool disconnected_; + bool connectFinished_; }; CPPUNIT_TEST_SUITE_REGISTRATION(BoostConnectionTest); -- cgit v0.10.2-6-g49f6