summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-11-20 18:23:09 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-11-20 18:23:09 (GMT)
commitcf8e2aca04c9a4021448f829e5b264dad25b28c8 (patch)
tree6f11cb1a32a9d73f3b9a62db6d06e6ae2dcab6ab /Swiften/QA
parent97bdf1a66d321bcd059a0ee218bec0cc92d1bc7b (diff)
downloadswift-cf8e2aca04c9a4021448f829e5b264dad25b28c8.zip
swift-cf8e2aca04c9a4021448f829e5b264dad25b28c8.tar.bz2
Fixed connection leak.
Diffstat (limited to 'Swiften/QA')
-rw-r--r--Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp3
-rw-r--r--Swiften/QA/NetworkTest/BoostConnectionTest.cpp29
2 files changed, 32 insertions, 0 deletions
diff --git a/Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp b/Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp
index a5c51aa..926c9ae 100644
--- a/Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp
+++ b/Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp
@@ -25,6 +25,9 @@ class BoostConnectionServerTest : public CppUnit::TestFixture {
}
void tearDown() {
+ while (eventLoop_->hasEvents()) {
+ eventLoop_->processEvents();
+ }
delete eventLoop_;
delete boostIOServiceThread_;
}
diff --git a/Swiften/QA/NetworkTest/BoostConnectionTest.cpp b/Swiften/QA/NetworkTest/BoostConnectionTest.cpp
index 9929eaa..af4e003 100644
--- a/Swiften/QA/NetworkTest/BoostConnectionTest.cpp
+++ b/Swiften/QA/NetworkTest/BoostConnectionTest.cpp
@@ -18,6 +18,7 @@ class BoostConnectionTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(BoostConnectionTest);
CPPUNIT_TEST(testDestructor);
CPPUNIT_TEST(testDestructor_PendingEvents);
+ CPPUNIT_TEST(testWrite);
CPPUNIT_TEST_SUITE_END();
public:
@@ -26,6 +27,7 @@ class BoostConnectionTest : public CppUnit::TestFixture {
void setUp() {
boostIOServiceThread_ = new BoostIOServiceThread();
eventLoop_ = new DummyEventLoop();
+ disconnected = false;
}
void tearDown() {
@@ -51,9 +53,36 @@ class BoostConnectionTest : public CppUnit::TestFixture {
eventLoop_->processEvents();
}
+ void testWrite() {
+ boost::shared_ptr<BoostConnection> testling(new BoostConnection(&boostIOServiceThread_->getIOService()));
+ 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("65.99.222.137"), 5222));
+ while (receivedData.isEmpty()) {
+ Swift::sleep(10);
+ eventLoop_->processEvents();
+ }
+ testling->disconnect();
+ }
+
+ void doWrite(BoostConnection* connection) {
+ connection->write(ByteArray("<stream:stream>"));
+ }
+
+ void handleDataRead(const ByteArray& data) {
+ receivedData += data;
+ }
+
+ void handleDisconnected() {
+ disconnected = true;
+ }
+
private:
BoostIOServiceThread* boostIOServiceThread_;
DummyEventLoop* eventLoop_;
+ ByteArray receivedData;
+ bool disconnected;
};
CPPUNIT_TEST_SUITE_REGISTRATION(BoostConnectionTest);