diff options
Diffstat (limited to 'Swiften/FileTransfer/UnitTest')
3 files changed, 241 insertions, 53 deletions
diff --git a/Swiften/FileTransfer/UnitTest/IBBReceiveSessionTest.cpp b/Swiften/FileTransfer/UnitTest/IBBReceiveSessionTest.cpp new file mode 100644 index 0000000..e759624 --- /dev/null +++ b/Swiften/FileTransfer/UnitTest/IBBReceiveSessionTest.cpp @@ -0,0 +1,188 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> +#include <vector> +#include <boost/bind.hpp> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Base/ByteArray.h> +#include <Swiften/FileTransfer/IBBReceiveSession.h> +#include <Swiften/Queries/IQRouter.h> +#include <Swiften/Client/DummyStanzaChannel.h> + +using namespace Swift; + +class IBBReceiveSessionTest : public CppUnit::TestFixture { +		CPPUNIT_TEST_SUITE(IBBReceiveSessionTest); +		CPPUNIT_TEST(testOpen); +		CPPUNIT_TEST(testReceiveData); +		CPPUNIT_TEST(testReceiveMultipleData); +		CPPUNIT_TEST(testReceiveDataForOtherSession); +		CPPUNIT_TEST(testReceiveDataOutOfOrder); +		CPPUNIT_TEST(testReceiveLastData); +		CPPUNIT_TEST(testReceiveClose); +		CPPUNIT_TEST(testStopWhileActive); +		CPPUNIT_TEST_SUITE_END(); + +	public: +		void setUp() { +			stanzaChannel = new DummyStanzaChannel(); +			iqRouter = new IQRouter(stanzaChannel); +			finished = false; +		} + +		void tearDown() { +			delete iqRouter; +			delete stanzaChannel; +		} + +		void testOpen() { +			boost::shared_ptr<IBBReceiveSession> testling(createSession("foo@bar.com/baz", "mysession")); +			testling->start(); +			stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBOpen("mysession", 0x10), "foo@bar.com/baz", "id-open")); + +			CPPUNIT_ASSERT(stanzaChannel->isResultAtIndex(0, "id-open")); +			CPPUNIT_ASSERT(!finished); + +			testling->stop(); +		} + +		void testReceiveData() { +			boost::shared_ptr<IBBReceiveSession> testling(createSession("foo@bar.com/baz", "mysession")); +			testling->start(); +			stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBOpen("mysession", 0x10), "foo@bar.com/baz", "id-open")); + +			stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBData("mysession", 0, createByteArray("abc")), "foo@bar.com/baz", "id-a")); + +			CPPUNIT_ASSERT(stanzaChannel->isResultAtIndex(1, "id-a")); +			CPPUNIT_ASSERT(createByteArray("abc") == receivedData); +			CPPUNIT_ASSERT(!finished); + +			testling->stop(); +		} + +		void testReceiveMultipleData() { +			boost::shared_ptr<IBBReceiveSession> testling(createSession("foo@bar.com/baz", "mysession")); +			testling->start(); +			stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBOpen("mysession", 0x10), "foo@bar.com/baz", "id-open")); + +			stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBData("mysession", 0, createByteArray("abc")), "foo@bar.com/baz", "id-a")); +			stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBData("mysession", 1, createByteArray("def")), "foo@bar.com/baz", "id-b")); + +			CPPUNIT_ASSERT(stanzaChannel->isResultAtIndex(2, "id-b")); +			CPPUNIT_ASSERT(createByteArray("abcdef") == receivedData); +			CPPUNIT_ASSERT(!finished); + +			testling->stop(); +		} + +		void testReceiveDataForOtherSession() { +			boost::shared_ptr<IBBReceiveSession> testling(createSession("foo@bar.com/baz", "mysession")); +			testling->start(); +			stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBOpen("mysession", 0x10), "foo@bar.com/baz", "id-open")); + +			stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBData("othersession", 0, createByteArray("abc")), "foo@bar.com/baz", "id-a")); + +			CPPUNIT_ASSERT(stanzaChannel->isErrorAtIndex(1, "id-a")); + +			testling->stop(); +		} + +		void testReceiveDataOutOfOrder() { +			boost::shared_ptr<IBBReceiveSession> testling(createSession("foo@bar.com/baz", "mysession")); +			testling->start(); +			stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBOpen("mysession", 0x10), "foo@bar.com/baz", "id-open")); + +			stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBData("mysession", 0, createByteArray("abc")), "foo@bar.com/baz", "id-a")); +			stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBData("mysession", 0, createByteArray("def")), "foo@bar.com/baz", "id-b")); + +			CPPUNIT_ASSERT(stanzaChannel->isErrorAtIndex(2, "id-b")); +			CPPUNIT_ASSERT(finished); +			CPPUNIT_ASSERT(error); + +			testling->stop(); +		} + +		void testReceiveLastData() { +			boost::shared_ptr<IBBReceiveSession> testling(createSession("foo@bar.com/baz", "mysession", 6)); +			testling->start(); +			stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBOpen("mysession", 0x10), "foo@bar.com/baz", "id-open")); + +			stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBData("mysession", 0, createByteArray("abc")), "foo@bar.com/baz", "id-a")); +			stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBData("mysession", 1, createByteArray("def")), "foo@bar.com/baz", "id-b")); + +			CPPUNIT_ASSERT(stanzaChannel->isResultAtIndex(2, "id-b")); +			CPPUNIT_ASSERT(createByteArray("abcdef") == receivedData); +			CPPUNIT_ASSERT(finished); +			CPPUNIT_ASSERT(!error); + +			testling->stop(); +		} + +		void testReceiveClose() { +			boost::shared_ptr<IBBReceiveSession> testling(createSession("foo@bar.com/baz", "mysession")); +			testling->start(); +			stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBOpen("mysession", 0x10), "foo@bar.com/baz", "id-open")); + +			stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBClose("mysession"), "foo@bar.com/baz", "id-close")); + +			CPPUNIT_ASSERT(finished); +			CPPUNIT_ASSERT(error); + +			testling->stop(); +		} + +		void testStopWhileActive() { +			boost::shared_ptr<IBBReceiveSession> testling(createSession("foo@bar.com/baz", "mysession")); +			testling->start(); +			stanzaChannel->onIQReceived(createIBBRequest(IBB::createIBBOpen("mysession", 0x10), "foo@bar.com/baz", "id-open")); + +			testling->stop(); + +			CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<IBB>(1, JID("foo@bar.com/baz"), IQ::Set)); +			IBB::ref ibb = stanzaChannel->sentStanzas[1]->getPayload<IBB>(); +			CPPUNIT_ASSERT_EQUAL(IBB::Close, ibb->getAction()); +			CPPUNIT_ASSERT_EQUAL(std::string("mysession"), ibb->getStreamID()); +			CPPUNIT_ASSERT(finished); +			CPPUNIT_ASSERT(!error); +		} + +	private: +		IQ::ref createIBBRequest(IBB::ref ibb, const JID& from, const std::string& id) { +			IQ::ref request = IQ::createRequest(IQ::Set, JID("baz@fum.com/dum"), id, ibb); +			request->setFrom(from); +			return request; +		} + +		IBBReceiveSession* createSession(const std::string& from, const std::string& id, size_t size = 0x1000) { +			IBBReceiveSession* session = new IBBReceiveSession(id, JID(from), size, iqRouter); +			session->onDataReceived.connect(boost::bind(&IBBReceiveSessionTest::handleDataReceived, this, _1)); +			session->onFinished.connect(boost::bind(&IBBReceiveSessionTest::handleFinished, this, _1)); +			return session; +		} + + +		void handleFinished(boost::optional<FileTransferError> error) { +			finished = true; +			this->error = error; +		} + +		void handleDataReceived(const std::vector<unsigned char>& data) { +			receivedData.insert(receivedData.end(), data.begin(), data.end()); +		} + +	private: +		DummyStanzaChannel* stanzaChannel; +		IQRouter* iqRouter; +		bool finished; +		boost::optional<FileTransferError> error; +		std::vector<unsigned char> receivedData; +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(IBBReceiveSessionTest); diff --git a/Swiften/FileTransfer/UnitTest/IBBSendSessionTest.cpp b/Swiften/FileTransfer/UnitTest/IBBSendSessionTest.cpp index 0cd273a..558a3d7 100644 --- a/Swiften/FileTransfer/UnitTest/IBBSendSessionTest.cpp +++ b/Swiften/FileTransfer/UnitTest/IBBSendSessionTest.cpp @@ -4,17 +4,16 @@   * See Documentation/Licenses/GPLv3.txt for more information.   */ -#include "Swiften/Base/ByteArray.h" -  #include <cppunit/extensions/HelperMacros.h>  #include <cppunit/extensions/TestFactoryRegistry.h>  #include <vector>  #include <boost/bind.hpp> -#include "Swiften/FileTransfer/IBBSendSession.h" -#include "Swiften/FileTransfer/ByteArrayReadBytestream.h" -#include "Swiften/Queries/IQRouter.h" -#include "Swiften/Client/DummyStanzaChannel.h" +#include <Swiften/Base/ByteArray.h> +#include <Swiften/FileTransfer/IBBSendSession.h> +#include <Swiften/FileTransfer/ByteArrayReadBytestream.h> +#include <Swiften/Queries/IQRouter.h> +#include <Swiften/Client/DummyStanzaChannel.h>  using namespace Swift; @@ -33,7 +32,7 @@ class IBBSendSessionTest : public CppUnit::TestFixture {  		void setUp() {  			stanzaChannel = new DummyStanzaChannel();  			iqRouter = new IQRouter(stanzaChannel); -			bytestream = boost::shared_ptr<ByteArrayReadBytestream>(new ByteArrayReadBytestream(ByteArray("abcdefg"))); +			bytestream = boost::shared_ptr<ByteArrayReadBytestream>(new ByteArrayReadBytestream(createByteArray("abcdefg")));  		}  		void tearDown() { @@ -42,7 +41,7 @@ class IBBSendSessionTest : public CppUnit::TestFixture {  		}  		void testStart() { -			std::auto_ptr<IBBSendSession> testling = createSession("foo@bar.com/baz"); +			boost::shared_ptr<IBBSendSession> testling = createSession("foo@bar.com/baz");  			testling->setBlockSize(1234);  			testling->start(); @@ -56,7 +55,7 @@ class IBBSendSessionTest : public CppUnit::TestFixture {  		}  		void testStart_ResponseStartsSending() { -			std::auto_ptr<IBBSendSession> testling = createSession("foo@bar.com/baz"); +			boost::shared_ptr<IBBSendSession> testling = createSession("foo@bar.com/baz");  			testling->setBlockSize(3);  			testling->start(); @@ -66,13 +65,13 @@ class IBBSendSessionTest : public CppUnit::TestFixture {  			CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<IBB>(1, JID("foo@bar.com/baz"), IQ::Set));  			IBB::ref ibb = stanzaChannel->sentStanzas[1]->getPayload<IBB>();  			CPPUNIT_ASSERT_EQUAL(IBB::Data, ibb->getAction()); -			CPPUNIT_ASSERT_EQUAL(ByteArray("abc"), ibb->getData()); +			CPPUNIT_ASSERT(createByteArray("abc") == ibb->getData());  			CPPUNIT_ASSERT_EQUAL(0, ibb->getSequenceNumber());  			CPPUNIT_ASSERT_EQUAL(std::string("myid"), ibb->getStreamID());  		}  		void testResponseContinuesSending() { -			std::auto_ptr<IBBSendSession> testling = createSession("foo@bar.com/baz"); +			boost::shared_ptr<IBBSendSession> testling = createSession("foo@bar.com/baz");  			testling->setBlockSize(3);  			testling->start();  			stanzaChannel->onIQReceived(createIBBResult()); @@ -82,13 +81,13 @@ class IBBSendSessionTest : public CppUnit::TestFixture {  			CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<IBB>(2, JID("foo@bar.com/baz"), IQ::Set));  			IBB::ref ibb = stanzaChannel->sentStanzas[2]->getPayload<IBB>();  			CPPUNIT_ASSERT_EQUAL(IBB::Data, ibb->getAction()); -			CPPUNIT_ASSERT_EQUAL(ByteArray("def"), ibb->getData()); +			CPPUNIT_ASSERT(createByteArray("def") == ibb->getData());  			CPPUNIT_ASSERT_EQUAL(1, ibb->getSequenceNumber());  			CPPUNIT_ASSERT_EQUAL(std::string("myid"), ibb->getStreamID());  		}  		void testRespondToAllFinishes() { -			std::auto_ptr<IBBSendSession> testling = createSession("foo@bar.com/baz"); +			boost::shared_ptr<IBBSendSession> testling = createSession("foo@bar.com/baz");  			testling->setBlockSize(3);  			testling->start();  			stanzaChannel->onIQReceived(createIBBResult()); @@ -101,7 +100,7 @@ class IBBSendSessionTest : public CppUnit::TestFixture {  		}  		void testErrorResponseFinishesWithError() { -			std::auto_ptr<IBBSendSession> testling = createSession("foo@bar.com/baz"); +			boost::shared_ptr<IBBSendSession> testling = createSession("foo@bar.com/baz");  			testling->setBlockSize(3);  			testling->start();  			stanzaChannel->onIQReceived(IQ::createError(JID("baz@fum.com/foo"), stanzaChannel->sentStanzas[0]->getID())); @@ -111,7 +110,7 @@ class IBBSendSessionTest : public CppUnit::TestFixture {  		}  		void testStopDuringSessionCloses() { -			std::auto_ptr<IBBSendSession> testling = createSession("foo@bar.com/baz"); +			boost::shared_ptr<IBBSendSession> testling = createSession("foo@bar.com/baz");  			testling->setBlockSize(3);  			testling->start();  			testling->stop(); @@ -126,7 +125,7 @@ class IBBSendSessionTest : public CppUnit::TestFixture {  		}  		void testStopAfterFinishedDoesNotClose() { -			std::auto_ptr<IBBSendSession> testling = createSession("foo@bar.com/baz"); +			boost::shared_ptr<IBBSendSession> testling = createSession("foo@bar.com/baz");  			testling->setBlockSize(16);  			testling->start();  			stanzaChannel->onIQReceived(createIBBResult()); @@ -144,8 +143,8 @@ class IBBSendSessionTest : public CppUnit::TestFixture {  		}  	private: -		std::auto_ptr<IBBSendSession> createSession(const std::string& to) { -			std::auto_ptr<IBBSendSession> session(new IBBSendSession("myid", JID(to), bytestream, iqRouter)); +		boost::shared_ptr<IBBSendSession> createSession(const std::string& to) { +			boost::shared_ptr<IBBSendSession> session(new IBBSendSession("myid", JID(to), bytestream, iqRouter));  			session->onFinished.connect(boost::bind(&IBBSendSessionTest::handleFinished, this, _1));  			return session;  		} diff --git a/Swiften/FileTransfer/UnitTest/SOCKS5BytestreamServerSessionTest.cpp b/Swiften/FileTransfer/UnitTest/SOCKS5BytestreamServerSessionTest.cpp index c6d246d..06bc98f 100644 --- a/Swiften/FileTransfer/UnitTest/SOCKS5BytestreamServerSessionTest.cpp +++ b/Swiften/FileTransfer/UnitTest/SOCKS5BytestreamServerSessionTest.cpp @@ -4,18 +4,19 @@   * See Documentation/Licenses/GPLv3.txt for more information.   */ -#include "Swiften/Base/ByteArray.h" +#include <Swiften/Base/ByteArray.h>  #include <cppunit/extensions/HelperMacros.h>  #include <cppunit/extensions/TestFactoryRegistry.h>  #include <boost/bind.hpp> -#include "Swiften/FileTransfer/SOCKS5BytestreamServerSession.h" -#include "Swiften/FileTransfer/ByteArrayReadBytestream.h" -#include "Swiften/FileTransfer/SOCKS5BytestreamRegistry.h" -#include "Swiften/Network/DummyConnection.h" -#include "Swiften/EventLoop/DummyEventLoop.h" -#include "Swiften/Base/StartStopper.h" +#include <Swiften/Base/Concat.h> +#include <Swiften/FileTransfer/SOCKS5BytestreamServerSession.h> +#include <Swiften/FileTransfer/ByteArrayReadBytestream.h> +#include <Swiften/FileTransfer/SOCKS5BytestreamRegistry.h> +#include <Swiften/Network/DummyConnection.h> +#include <Swiften/EventLoop/DummyEventLoop.h> +#include <Swiften/Base/StartStopper.h>  using namespace Swift; @@ -35,7 +36,7 @@ class SOCKS5BytestreamServerSessionTest : public CppUnit::TestFixture {  			eventLoop = new DummyEventLoop();  			connection = boost::shared_ptr<DummyConnection>(new DummyConnection(eventLoop));  			connection->onDataSent.connect(boost::bind(&SOCKS5BytestreamServerSessionTest::handleDataWritten, this, _1)); -			stream1 = boost::shared_ptr<ByteArrayReadBytestream>(new ByteArrayReadBytestream(ByteArray("abcdefg"))); +			stream1 = boost::shared_ptr<ByteArrayReadBytestream>(new ByteArrayReadBytestream(createByteArray("abcdefg")));  		}  		void tearDown() { @@ -44,48 +45,48 @@ class SOCKS5BytestreamServerSessionTest : public CppUnit::TestFixture {  		}  		void testAuthenticate() { -			std::auto_ptr<SOCKS5BytestreamServerSession> testling(createSession()); +			boost::shared_ptr<SOCKS5BytestreamServerSession> testling(createSession());  			StartStopper<SOCKS5BytestreamServerSession> stopper(testling.get()); -			receive(ByteArray("\x05\x02\x01\x02")); +			receive(createSafeByteArray("\x05\x02\x01\x02")); -			CPPUNIT_ASSERT_EQUAL(ByteArray("\x05\x00", 2), receivedData); +			CPPUNIT_ASSERT(createByteArray("\x05\x00", 2) == receivedData);  		}  		void testAuthenticate_Chunked() { -			std::auto_ptr<SOCKS5BytestreamServerSession> testling(createSession()); +			boost::shared_ptr<SOCKS5BytestreamServerSession> testling(createSession());  			StartStopper<SOCKS5BytestreamServerSession> stopper(testling.get()); -			receive(ByteArray("\x05\x02\x01")); +			receive(createSafeByteArray("\x05\x02\x01")); -			CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedData.getSize())); -			receive(ByteArray("\x01")); -			CPPUNIT_ASSERT_EQUAL(ByteArray("\x05\x00", 2), receivedData); +			CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedData.size())); +			receive(createSafeByteArray("\x01")); +			CPPUNIT_ASSERT(createByteArray("\x05\x00", 2) == receivedData);  		}  		void testRequest() { -			std::auto_ptr<SOCKS5BytestreamServerSession> testling(createSession()); +			boost::shared_ptr<SOCKS5BytestreamServerSession> testling(createSession());  			StartStopper<SOCKS5BytestreamServerSession> stopper(testling.get());  			bytestreams.addBytestream("abcdef", stream1);  			authenticate(); -			ByteArray hostname("abcdef"); -			receive(ByteArray("\x05\x01\x00\x03", 4) + hostname.getSize() + hostname + ByteArray("\x00\x00", 2)); -			CPPUNIT_ASSERT_EQUAL(ByteArray("\x05\x00\x00\x03\x06\x61\x62\x63\x64\x65\x66\x00\x00", 13), ByteArray(receivedData.getData(), 13)); +			ByteArray hostname(createByteArray("abcdef")); +			receive(concat(createSafeByteArray("\x05\x01\x00\x03", 4), createSafeByteArray(hostname.size()), createSafeByteArray(hostname), createSafeByteArray("\x00\x00", 2))); +			CPPUNIT_ASSERT(createByteArray("\x05\x00\x00\x03\x06\x61\x62\x63\x64\x65\x66\x00\x00", 13) == createByteArray(&receivedData[0], 13));  		}  		void testRequest_UnknownBytestream() { -			std::auto_ptr<SOCKS5BytestreamServerSession> testling(createSession()); +			boost::shared_ptr<SOCKS5BytestreamServerSession> testling(createSession());  			StartStopper<SOCKS5BytestreamServerSession> stopper(testling.get());  			authenticate(); -			ByteArray hostname("abcdef"); -			receive(ByteArray("\x05\x01\x00\x03", 4) + hostname.getSize() + hostname + ByteArray("\x00\x00", 2)); -			CPPUNIT_ASSERT_EQUAL(ByteArray("\x05\x04\x00\x03\x06\x61\x62\x63\x64\x65\x66\x00\x00", 13), receivedData); +			ByteArray hostname(createByteArray("abcdef")); +			receive(concat(createSafeByteArray("\x05\x01\x00\x03", 4), createSafeByteArray(hostname.size()), createSafeByteArray(hostname), createSafeByteArray("\x00\x00", 2))); +			CPPUNIT_ASSERT(createByteArray("\x05\x04\x00\x03\x06\x61\x62\x63\x64\x65\x66\x00\x00", 13) == receivedData);  		}  		void testReceiveData() { -			std::auto_ptr<SOCKS5BytestreamServerSession> testling(createSession()); +			boost::shared_ptr<SOCKS5BytestreamServerSession> testling(createSession());  			StartStopper<SOCKS5BytestreamServerSession> stopper(testling.get());  			bytestreams.addBytestream("abcdef", stream1);  			authenticate(); @@ -93,12 +94,12 @@ class SOCKS5BytestreamServerSessionTest : public CppUnit::TestFixture {  			eventLoop->processEvents();  			skipHeader("abcdef"); -			CPPUNIT_ASSERT_EQUAL(ByteArray("abcdefg"), receivedData); +			CPPUNIT_ASSERT(createByteArray("abcdefg") == receivedData);  			CPPUNIT_ASSERT_EQUAL(2, receivedDataChunks);  		}  		void testReceiveData_Chunked() { -			std::auto_ptr<SOCKS5BytestreamServerSession> testling(createSession()); +			boost::shared_ptr<SOCKS5BytestreamServerSession> testling(createSession());  			testling->setChunkSize(3);  			StartStopper<SOCKS5BytestreamServerSession> stopper(testling.get());  			bytestreams.addBytestream("abcdef", stream1); @@ -107,34 +108,34 @@ class SOCKS5BytestreamServerSessionTest : public CppUnit::TestFixture {  			eventLoop->processEvents();  			skipHeader("abcdef"); -			CPPUNIT_ASSERT_EQUAL(ByteArray("abcdefg"), receivedData); +			CPPUNIT_ASSERT(createByteArray("abcdefg") == receivedData);  			CPPUNIT_ASSERT_EQUAL(4, receivedDataChunks);  		}  	private: -		void receive(const ByteArray& data) { +		void receive(const SafeByteArray& data) {  			connection->receive(data);  			eventLoop->processEvents();  		}  		void authenticate() { -			receive(ByteArray("\x05\x02\x01\x02")); +			receive(createSafeByteArray("\x05\x02\x01\x02"));  			receivedData.clear();  			receivedDataChunks = 0;  		}  		void request(const std::string& hostname) { -			receive(ByteArray("\x05\x01\x00\x03", 4) + hostname.size() + hostname + ByteArray("\x00\x00", 2)); +			receive(concat(createSafeByteArray("\x05\x01\x00\x03", 4), createSafeByteArray(hostname.size()), createSafeByteArray(hostname), createSafeByteArray("\x00\x00", 2)));  		}  		void skipHeader(const std::string& hostname) {  			int headerSize = 7 + hostname.size(); -			receivedData = ByteArray(receivedData.getData() + headerSize, receivedData.getSize() - headerSize); +			receivedData = createByteArray(&receivedData[headerSize], receivedData.size() - headerSize);  		} -		void handleDataWritten(const ByteArray& data) { -			receivedData += data; +		void handleDataWritten(const SafeByteArray& data) { +			receivedData.insert(receivedData.end(), data.begin(), data.end());  			receivedDataChunks++;  		} @@ -148,7 +149,7 @@ class SOCKS5BytestreamServerSessionTest : public CppUnit::TestFixture {  		DummyEventLoop* eventLoop;  		SOCKS5BytestreamRegistry bytestreams;  		boost::shared_ptr<DummyConnection> connection; -		ByteArray receivedData; +		std::vector<unsigned char> receivedData;  		int receivedDataChunks;  		boost::shared_ptr<ByteArrayReadBytestream> stream1;  };  | 
 Swift