diff options
Diffstat (limited to 'Swiften/StreamStack/UnitTest/StreamStackTest.cpp')
-rw-r--r-- | Swiften/StreamStack/UnitTest/StreamStackTest.cpp | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/Swiften/StreamStack/UnitTest/StreamStackTest.cpp b/Swiften/StreamStack/UnitTest/StreamStackTest.cpp index 8949315..2405ddc 100644 --- a/Swiften/StreamStack/UnitTest/StreamStackTest.cpp +++ b/Swiften/StreamStack/UnitTest/StreamStackTest.cpp @@ -8,6 +8,7 @@ #include <vector> #include <boost/bind.hpp> +#include <boost/smart_ptr.hpp> #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> @@ -37,13 +38,15 @@ class StreamStackTest : public CppUnit::TestFixture StreamStackTest() {} void setUp() { - physicalStream_ = boost::shared_ptr<TestLowLayer>(new TestLowLayer()); - xmppStream_ = boost::shared_ptr<XMPPLayer>(new XMPPLayer(&parserFactories_, &serializers_, ClientStreamType)); + physicalStream_ = new TestLowLayer(); + xmppStream_ = new XMPPLayer(&parserFactories_, &serializers_, ClientStreamType); elementsReceived_ = 0; dataWriteReceived_ = 0; } void tearDown() { + delete physicalStream_; + delete xmppStream_; } void testWriteData_NoIntermediateStreamStack() { @@ -57,8 +60,8 @@ class StreamStackTest : public CppUnit::TestFixture void testWriteData_OneIntermediateStream() { StreamStack testling(xmppStream_, physicalStream_); - boost::shared_ptr<MyStreamLayer> xStream(new MyStreamLayer("X")); - testling.addLayer(xStream); + std::auto_ptr<MyStreamLayer> xStream(new MyStreamLayer("X")); + testling.addLayer(xStream.get()); xmppStream_->writeData("foo"); @@ -68,10 +71,10 @@ class StreamStackTest : public CppUnit::TestFixture void testWriteData_TwoIntermediateStreamStack() { StreamStack testling(xmppStream_, physicalStream_); - boost::shared_ptr<MyStreamLayer> xStream(new MyStreamLayer("X")); - boost::shared_ptr<MyStreamLayer> yStream(new MyStreamLayer("Y")); - testling.addLayer(xStream); - testling.addLayer(yStream); + std::auto_ptr<MyStreamLayer> xStream(new MyStreamLayer("X")); + std::auto_ptr<MyStreamLayer> yStream(new MyStreamLayer("Y")); + testling.addLayer(xStream.get()); + testling.addLayer(yStream.get()); xmppStream_->writeData("foo"); @@ -91,8 +94,8 @@ class StreamStackTest : public CppUnit::TestFixture void testReadData_OneIntermediateStream() { StreamStack testling(xmppStream_, physicalStream_); xmppStream_->onElement.connect(boost::bind(&StreamStackTest::handleElement, this, _1)); - boost::shared_ptr<MyStreamLayer> xStream(new MyStreamLayer("<")); - testling.addLayer(xStream); + std::auto_ptr<MyStreamLayer> xStream(new MyStreamLayer("<")); + testling.addLayer(xStream.get()); physicalStream_->onDataRead(ByteArray("stream:stream xmlns:stream='http://etherx.jabber.org/streams'><presence/>")); @@ -102,10 +105,10 @@ class StreamStackTest : public CppUnit::TestFixture void testReadData_TwoIntermediateStreamStack() { StreamStack testling(xmppStream_, physicalStream_); xmppStream_->onElement.connect(boost::bind(&StreamStackTest::handleElement, this, _1)); - boost::shared_ptr<MyStreamLayer> xStream(new MyStreamLayer("s")); - boost::shared_ptr<MyStreamLayer> yStream(new MyStreamLayer("<")); - testling.addLayer(xStream); - testling.addLayer(yStream); + std::auto_ptr<MyStreamLayer> xStream(new MyStreamLayer("s")); + std::auto_ptr<MyStreamLayer> yStream(new MyStreamLayer("<")); + testling.addLayer(xStream.get()); + testling.addLayer(yStream.get()); physicalStream_->onDataRead(ByteArray("tream:stream xmlns:stream='http://etherx.jabber.org/streams'><presence/>")); @@ -115,8 +118,8 @@ class StreamStackTest : public CppUnit::TestFixture void testAddLayer_ExistingOnWriteDataSlot() { StreamStack testling(xmppStream_, physicalStream_); xmppStream_->onWriteData.connect(boost::bind(&StreamStackTest::handleWriteData, this, _1)); - boost::shared_ptr<MyStreamLayer> xStream(new MyStreamLayer("X")); - testling.addLayer(xStream); + std::auto_ptr<MyStreamLayer> xStream(new MyStreamLayer("X")); + testling.addLayer(xStream.get()); xmppStream_->writeData("foo"); @@ -138,11 +141,11 @@ class StreamStackTest : public CppUnit::TestFixture } virtual void writeData(const ByteArray& data) { - onWriteData(ByteArray(prepend_) + data); + writeDataToChildLayer(ByteArray(prepend_) + data); } virtual void handleDataRead(const ByteArray& data) { - onDataRead(ByteArray(prepend_) + data); + writeDataToParentLayer(ByteArray(prepend_) + data); } private: @@ -158,14 +161,19 @@ class StreamStackTest : public CppUnit::TestFixture data_.push_back(data); } + void onDataRead(const ByteArray& data) { + writeDataToParentLayer(data); + } + std::vector<ByteArray> data_; }; - + + private: FullPayloadParserFactoryCollection parserFactories_; FullPayloadSerializerCollection serializers_; - boost::shared_ptr<TestLowLayer> physicalStream_; - boost::shared_ptr<XMPPLayer> xmppStream_; + TestLowLayer* physicalStream_; + XMPPLayer* xmppStream_; int elementsReceived_; int dataWriteReceived_; }; |