diff options
author | Remko Tronçon <git@el-tramo.be> | 2011-12-24 14:27:33 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2011-12-24 14:44:44 (GMT) |
commit | c060049e759571ae02a3a970c6a3088e099e5c9f (patch) | |
tree | 8512e2ca0ae0fba16238651b9d0edbb74e085b16 /Swiften/Network/UnitTest/BOSHConnectionTest.cpp | |
parent | b453b3bf94dcd40d71c30fd0053f7110cb52b211 (diff) | |
download | swift-contrib-c060049e759571ae02a3a970c6a3088e099e5c9f.zip swift-contrib-c060049e759571ae02a3a970c6a3088e099e5c9f.tar.bz2 |
Some BOSH refactoring.
Diffstat (limited to 'Swiften/Network/UnitTest/BOSHConnectionTest.cpp')
-rw-r--r-- | Swiften/Network/UnitTest/BOSHConnectionTest.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/Swiften/Network/UnitTest/BOSHConnectionTest.cpp b/Swiften/Network/UnitTest/BOSHConnectionTest.cpp index 9215725..8062bea 100644 --- a/Swiften/Network/UnitTest/BOSHConnectionTest.cpp +++ b/Swiften/Network/UnitTest/BOSHConnectionTest.cpp @@ -39,30 +39,31 @@ class BOSHConnectionTest : public CppUnit::TestFixture { CPPUNIT_TEST(testHTTPRequest_Empty); CPPUNIT_TEST_SUITE_END(); public: void setUp() { eventLoop = new DummyEventLoop(); connectionFactory = new MockConnectionFactory(eventLoop); connectFinished = false; disconnected = false; + disconnectedError = false; dataRead.clear(); } void tearDown() { eventLoop->processEvents(); delete connectionFactory; delete eventLoop; } void testHeader() { BOSHConnection::ref testling = createTestling(); - testling->connect(HostAddressPort(HostAddress("127.0.0.1"), 5280)); + testling->connect(); eventLoop->processEvents(); testling->startStream("wonderland.lit", 1); std::string initial("<body wait='60' " "inactivity='30' " "polling='5' " "requests='2' " "hold='1' " "maxpause='120' " "sid='MyShinySID' " @@ -70,82 +71,82 @@ class BOSHConnectionTest : public CppUnit::TestFixture { "from='wonderland.lit' " "xmlns='http://jabber.org/protocol/httpbind'/>"); readResponse(initial, connectionFactory->connections[0]); CPPUNIT_ASSERT_EQUAL(std::string("MyShinySID"), sid); CPPUNIT_ASSERT(testling->isReadyToSend()); } void testReadiness_ok() { BOSHConnection::ref testling = createTestling(); - testling->connect(HostAddressPort(HostAddress("127.0.0.1"), 5280)); + testling->connect(); eventLoop->processEvents(); testling->setSID("blahhhhh"); CPPUNIT_ASSERT(testling->isReadyToSend()); } void testReadiness_pending() { BOSHConnection::ref testling = createTestling(); - testling->connect(HostAddressPort(HostAddress("127.0.0.1"), 5280)); + testling->connect(); eventLoop->processEvents(); testling->setSID("mySID"); CPPUNIT_ASSERT(testling->isReadyToSend()); testling->write(createSafeByteArray("<mypayload/>")); CPPUNIT_ASSERT(!testling->isReadyToSend()); readResponse("<body><blah/></body>", connectionFactory->connections[0]); CPPUNIT_ASSERT(testling->isReadyToSend()); } void testReadiness_disconnect() { BOSHConnection::ref testling = createTestling(); - testling->connect(HostAddressPort(HostAddress("127.0.0.1"), 5280)); + testling->connect(); eventLoop->processEvents(); testling->setSID("mySID"); CPPUNIT_ASSERT(testling->isReadyToSend()); connectionFactory->connections[0]->onDisconnected(false); CPPUNIT_ASSERT(!testling->isReadyToSend()); } void testReadiness_noSID() { BOSHConnection::ref testling = createTestling(); - testling->connect(HostAddressPort(HostAddress("127.0.0.1"), 5280)); + testling->connect(); eventLoop->processEvents(); CPPUNIT_ASSERT(!testling->isReadyToSend()); } void testWrite_Receive() { BOSHConnection::ref testling = createTestling(); - testling->connect(HostAddressPort(HostAddress("127.0.0.1"), 5280)); + testling->connect(); eventLoop->processEvents(); testling->setSID("mySID"); testling->write(createSafeByteArray("<mypayload/>")); readResponse("<body><blah/></body>", connectionFactory->connections[0]); CPPUNIT_ASSERT_EQUAL(std::string("<blah/>"), byteArrayToString(dataRead)); } void testWrite_ReceiveTwice() { BOSHConnection::ref testling = createTestling(); - testling->connect(HostAddressPort(HostAddress("127.0.0.1"), 5280)); + testling->connect(); eventLoop->processEvents(); testling->setSID("mySID"); testling->write(createSafeByteArray("<mypayload/>")); readResponse("<body><blah/></body>", connectionFactory->connections[0]); CPPUNIT_ASSERT_EQUAL(std::string("<blah/>"), byteArrayToString(dataRead)); dataRead.clear(); testling->write(createSafeByteArray("<mypayload2/>")); readResponse("<body><bleh/></body>", connectionFactory->connections[0]); CPPUNIT_ASSERT_EQUAL(std::string("<bleh/>"), byteArrayToString(dataRead)); } void testRead_Fragment() { BOSHConnection::ref testling = createTestling(); - testling->connect(HostAddressPort(HostAddress("127.0.0.1"), 5280)); + testling->connect(); eventLoop->processEvents(); CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), connectionFactory->connections.size()); boost::shared_ptr<MockConnection> connection = connectionFactory->connections[0]; boost::shared_ptr<SafeByteArray> data1 = boost::make_shared<SafeByteArray>(createSafeByteArray( "HTTP/1.1 200 OK\r\n" "Content-Type: text/xml; charset=utf-8\r\n" "Access-Control-Allow-Origin: *\r\n" "Access-Control-Allow-Headers: Content-Type\r\n" "Content-Length: 64\r\n")); @@ -192,19 +193,19 @@ class BOSHConnectionTest : public CppUnit::TestFixture { c->setRID(42); return c; } void handleConnectFinished(bool error) { connectFinished = true; connectFinishedWithError = error; } - void handleDisconnected(const boost::optional<Connection::Error>& e) { + void handleDisconnected(bool e) { disconnected = true; disconnectedError = e; } void handleDataRead(const SafeByteArray& d) { append(dataRead, d); } void handleSID(const std::string& s) { @@ -274,18 +275,18 @@ class BOSHConnectionTest : public CppUnit::TestFixture { } private: DummyEventLoop* eventLoop; MockConnectionFactory* connectionFactory; bool connectFinished; bool connectFinishedWithError; bool disconnected; - boost::optional<Connection::Error> disconnectedError; + bool disconnectedError; ByteArray dataRead; PlatformXMLParserFactory parserFactory; std::string sid; }; CPPUNIT_TEST_SUITE_REGISTRATION(BOSHConnectionTest); |