diff options
| -rw-r--r-- | Swiften/Network/BoostConnectionServer.cpp | 1 | ||||
| -rw-r--r-- | Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp | 3 | ||||
| -rw-r--r-- | Swiften/QA/NetworkTest/BoostConnectionTest.cpp | 29 |
3 files changed, 33 insertions, 0 deletions
diff --git a/Swiften/Network/BoostConnectionServer.cpp b/Swiften/Network/BoostConnectionServer.cpp index 4e83ad5..cea016d 100644 --- a/Swiften/Network/BoostConnectionServer.cpp +++ b/Swiften/Network/BoostConnectionServer.cpp @@ -34,12 +34,13 @@ void BoostConnectionServer::stop() { stop(boost::optional<Error>()); } void BoostConnectionServer::stop(boost::optional<Error> e) { if (acceptor_) { acceptor_->close(); + delete acceptor_; acceptor_ = NULL; } MainEventLoop::postEvent(boost::bind(boost::ref(onStopped), e), shared_from_this()); } void BoostConnectionServer::acceptNextConnection() { 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 @@ -22,12 +22,15 @@ class BoostConnectionServerTest : public CppUnit::TestFixture { eventLoop_ = new DummyEventLoop(); stopped = false; stoppedError.reset(); } void tearDown() { + while (eventLoop_->hasEvents()) { + eventLoop_->processEvents(); + } delete eventLoop_; delete boostIOServiceThread_; } void testConstructor_TwoServersOnSamePort() { boost::shared_ptr<BoostConnectionServer> testling(new BoostConnectionServer(9999, &boostIOServiceThread_->getIOService())); 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 @@ -15,20 +15,22 @@ const unsigned char* address = reinterpret_cast<const unsigned char*>("\x41\x63\ using namespace Swift; class BoostConnectionTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(BoostConnectionTest); CPPUNIT_TEST(testDestructor); CPPUNIT_TEST(testDestructor_PendingEvents); + CPPUNIT_TEST(testWrite); CPPUNIT_TEST_SUITE_END(); public: BoostConnectionTest() {} void setUp() { boostIOServiceThread_ = new BoostIOServiceThread(); eventLoop_ = new DummyEventLoop(); + disconnected = false; } void tearDown() { delete eventLoop_; delete boostIOServiceThread_; } @@ -48,12 +50,39 @@ class BoostConnectionTest : public CppUnit::TestFixture { Swift::sleep(10); } } 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); |
Swift