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) :
19 19
20 # Set environment variables for running the test 20 # Set environment variables for running the test
21 test_env = env.Clone() 21 test_env = env.Clone()
22 for i in ["HOME", "USERPROFILE", "APPDATA"]: 22 for i in ["HOME", "USERPROFILE", "APPDATA", "ASAN_OPTIONS", "LSAN_OPTIONS", "SWIFT_NETWORK_TEST_IPV4", "SWIFT_NETWORK_TEST_IPV6"]:
23 if os.environ.get(i, "") : 23 if os.environ.get(i, "") :
24 test_env["ENV"][i] = os.environ[i] 24 test_env["ENV"][i] = os.environ[i]
25 if env["target"] == "android" : 25 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 @@
4 * See the COPYING file for more information. 4 * See the COPYING file for more information.
5 */ 5 */
6 6
7#include <cppunit/extensions/HelperMacros.h> 7#include <string>
8#include <cppunit/extensions/TestFactoryRegistry.h> 8
9#include <boost/shared_ptr.hpp> 9#include <boost/shared_ptr.hpp>
10#include <boost/smart_ptr/make_shared.hpp> 10#include <boost/smart_ptr/make_shared.hpp>
11 11
12#include <string> 12#include <cppunit/extensions/HelperMacros.h>
13#include <cppunit/extensions/TestFactoryRegistry.h>
14
13#include <Swiften/Base/Algorithm.h> 15#include <Swiften/Base/Algorithm.h>
14#include <Swiften/Base/sleep.h> 16#include <Swiften/Base/sleep.h>
17#include <Swiften/EventLoop/DummyEventLoop.h>
15#include <Swiften/Network/BoostConnection.h> 18#include <Swiften/Network/BoostConnection.h>
19#include <Swiften/Network/BoostIOServiceThread.h>
16#include <Swiften/Network/HostAddress.h> 20#include <Swiften/Network/HostAddress.h>
17#include <Swiften/Network/HostAddressPort.h> 21#include <Swiften/Network/HostAddressPort.h>
18#include <Swiften/Network/BoostIOServiceThread.h>
19#include <Swiften/EventLoop/DummyEventLoop.h>
20
21static const unsigned char* address = reinterpret_cast<const unsigned char*>("\x4A\x32\x3e\x31");
22 22
23using namespace Swift; 23using namespace Swift;
24 24
@@ -37,9 +37,9 @@ class BoostConnectionTest : public CppUnit::TestFixture {
37 void setUp() { 37 void setUp() {
38 eventLoop_ = new DummyEventLoop(); 38 eventLoop_ = new DummyEventLoop();
39 boostIOServiceThread_ = new BoostIOServiceThread(); 39 boostIOServiceThread_ = new BoostIOServiceThread();
40 boostIOService = boost::make_shared<boost::asio::io_service>(); 40 boostIOService_ = boost::make_shared<boost::asio::io_service>();
41 disconnected = false; 41 disconnected_ = false;
42 connectFinished = false; 42 connectFinished_ = false;
43 } 43 }
44 44
45 void tearDown() { 45 void tearDown() {
@@ -53,14 +53,14 @@ class BoostConnectionTest : public CppUnit::TestFixture {
53 void testDestructor() { 53 void testDestructor() {
54 { 54 {
55 BoostConnection::ref testling(BoostConnection::create(boostIOServiceThread_->getIOService(), eventLoop_)); 55 BoostConnection::ref testling(BoostConnection::create(boostIOServiceThread_->getIOService(), eventLoop_));
56 testling->connect(HostAddressPort(HostAddress(address, 4), 5222)); 56 testling->connect(HostAddressPort(HostAddress(getenv("SWIFT_NETWORK_TEST_IPV4")), 5222));
57 } 57 }
58 } 58 }
59 59
60 void testDestructor_PendingEvents() { 60 void testDestructor_PendingEvents() {
61 { 61 {
62 BoostConnection::ref testling(BoostConnection::create(boostIOServiceThread_->getIOService(), eventLoop_)); 62 BoostConnection::ref testling(BoostConnection::create(boostIOServiceThread_->getIOService(), eventLoop_));
63 testling->connect(HostAddressPort(HostAddress(address, 4), 5222)); 63 testling->connect(HostAddressPort(HostAddress(getenv("SWIFT_NETWORK_TEST_IPV4")), 5222));
64 while (!eventLoop_->hasEvents()) { 64 while (!eventLoop_->hasEvents()) {
65 Swift::sleep(10); 65 Swift::sleep(10);
66 } 66 }
@@ -73,8 +73,8 @@ class BoostConnectionTest : public CppUnit::TestFixture {
73 testling->onConnectFinished.connect(boost::bind(&BoostConnectionTest::doWrite, this, testling.get())); 73 testling->onConnectFinished.connect(boost::bind(&BoostConnectionTest::doWrite, this, testling.get()));
74 testling->onDataRead.connect(boost::bind(&BoostConnectionTest::handleDataRead, this, _1)); 74 testling->onDataRead.connect(boost::bind(&BoostConnectionTest::handleDataRead, this, _1));
75 testling->onDisconnected.connect(boost::bind(&BoostConnectionTest::handleDisconnected, this)); 75 testling->onDisconnected.connect(boost::bind(&BoostConnectionTest::handleDisconnected, this));
76 testling->connect(HostAddressPort(HostAddress("74.50.62.49"), 5222)); 76 testling->connect(HostAddressPort(HostAddress(getenv("SWIFT_NETWORK_TEST_IPV4")), 5222));
77 while (receivedData.empty()) { 77 while (receivedData_.empty()) {
78 Swift::sleep(10); 78 Swift::sleep(10);
79 eventLoop_->processEvents(); 79 eventLoop_->processEvents();
80 } 80 }
@@ -86,8 +86,8 @@ class BoostConnectionTest : public CppUnit::TestFixture {
86 testling->onConnectFinished.connect(boost::bind(&BoostConnectionTest::doWrite, this, testling.get())); 86 testling->onConnectFinished.connect(boost::bind(&BoostConnectionTest::doWrite, this, testling.get()));
87 testling->onDataRead.connect(boost::bind(&BoostConnectionTest::handleDataRead, this, _1)); 87 testling->onDataRead.connect(boost::bind(&BoostConnectionTest::handleDataRead, this, _1));
88 testling->onDisconnected.connect(boost::bind(&BoostConnectionTest::handleDisconnected, this)); 88 testling->onDisconnected.connect(boost::bind(&BoostConnectionTest::handleDisconnected, this));
89 testling->connect(HostAddressPort(HostAddress("2001:470:1f0e:852::2"), 80)); 89 testling->connect(HostAddressPort(HostAddress(getenv("SWIFT_NETWORK_TEST_IPV6")), 80));
90 while (receivedData.empty()) { 90 while (receivedData_.empty()) {
91 Swift::sleep(10); 91 Swift::sleep(10);
92 eventLoop_->processEvents(); 92 eventLoop_->processEvents();
93 } 93 }
@@ -96,13 +96,13 @@ class BoostConnectionTest : public CppUnit::TestFixture {
96 96
97 97
98 void testWriteMultipleSimultaniouslyQueuesWrites() { 98 void testWriteMultipleSimultaniouslyQueuesWrites() {
99 BoostConnection::ref testling(BoostConnection::create(boostIOService, eventLoop_)); 99 BoostConnection::ref testling(BoostConnection::create(boostIOService_, eventLoop_));
100 testling->onConnectFinished.connect(boost::bind(&BoostConnectionTest::handleConnectFinished, this)); 100 testling->onConnectFinished.connect(boost::bind(&BoostConnectionTest::handleConnectFinished, this));
101 testling->onDataRead.connect(boost::bind(&BoostConnectionTest::handleDataRead, this, _1)); 101 testling->onDataRead.connect(boost::bind(&BoostConnectionTest::handleDataRead, this, _1));
102 testling->onDisconnected.connect(boost::bind(&BoostConnectionTest::handleDisconnected, this)); 102 testling->onDisconnected.connect(boost::bind(&BoostConnectionTest::handleDisconnected, this));
103 testling->connect(HostAddressPort(HostAddress("74.50.62.49"), 5222)); 103 testling->connect(HostAddressPort(HostAddress(getenv("SWIFT_NETWORK_TEST_IPV4")), 5222));
104 while (!connectFinished) { 104 while (!connectFinished_) {
105 boostIOService->run_one(); 105 boostIOService_->run_one();
106 eventLoop_->processEvents(); 106 eventLoop_->processEvents();
107 } 107 }
108 108
@@ -111,20 +111,20 @@ class BoostConnectionTest : public CppUnit::TestFixture {
111 testling->write(createSafeByteArray(">")); 111 testling->write(createSafeByteArray(">"));
112 112
113 // Check that we only did one write event, the others are queued 113 // Check that we only did one write event, the others are queued
114 /*int runHandlers = */boostIOService->poll(); 114 /*int runHandlers = */boostIOService_->poll();
115 // Disabling this test, because poll runns all handlers that are added during poll() as well, so 115 // Disabling this test, because poll runns all handlers that are added during poll() as well, so
116 // this test doesn't really work any more. We'll have to trust that things are queued. 116 // this test doesn't really work any more. We'll have to trust that things are queued.
117 //CPPUNIT_ASSERT_EQUAL(1, runHandlers); 117 //CPPUNIT_ASSERT_EQUAL(1, runHandlers);
118 // Process the other events 118 // Process the other events
119 while (receivedData.empty()) { 119 while (receivedData_.empty()) {
120 boostIOService->run_one(); 120 boostIOService_->run_one();
121 eventLoop_->processEvents(); 121 eventLoop_->processEvents();
122 } 122 }
123 123
124 // Disconnect & clean up 124 // Disconnect & clean up
125 testling->disconnect(); 125 testling->disconnect();
126 while (!disconnected) { 126 while (!disconnected_) {
127 boostIOService->run_one(); 127 boostIOService_->run_one();
128 eventLoop_->processEvents(); 128 eventLoop_->processEvents();
129 } 129 }
130 } 130 }
@@ -135,24 +135,24 @@ class BoostConnectionTest : public CppUnit::TestFixture {
135 } 135 }
136 136
137 void handleDataRead(boost::shared_ptr<SafeByteArray> data) { 137 void handleDataRead(boost::shared_ptr<SafeByteArray> data) {
138 append(receivedData, *data); 138 append(receivedData_, *data);
139 } 139 }
140 140
141 void handleDisconnected() { 141 void handleDisconnected() {
142 disconnected = true; 142 disconnected_ = true;
143 } 143 }
144 144
145 void handleConnectFinished() { 145 void handleConnectFinished() {
146 connectFinished = true; 146 connectFinished_ = true;
147 } 147 }
148 148
149 private: 149 private:
150 BoostIOServiceThread* boostIOServiceThread_; 150 BoostIOServiceThread* boostIOServiceThread_;
151 boost::shared_ptr<boost::asio::io_service> boostIOService; 151 boost::shared_ptr<boost::asio::io_service> boostIOService_;
152 DummyEventLoop* eventLoop_; 152 DummyEventLoop* eventLoop_;
153 ByteArray receivedData; 153 ByteArray receivedData_;
154 bool disconnected; 154 bool disconnected_;
155 bool connectFinished; 155 bool connectFinished_;
156}; 156};
157 157
158CPPUNIT_TEST_SUITE_REGISTRATION(BoostConnectionTest); 158CPPUNIT_TEST_SUITE_REGISTRATION(BoostConnectionTest);