diff options
| author | Tobias Markmann <tm@ayena.de> | 2018-08-02 09:00:25 (GMT) |
|---|---|---|
| committer | Tobias Markmann <tm@ayena.de> | 2018-08-02 09:00:25 (GMT) |
| commit | 091f6e520694360a0407ab0cf3bb036fb461e6e3 (patch) | |
| tree | 717ff863e8cd799842e5c82fc2d833ae026c9b20 /Swiften | |
| parent | 80f74201f0a35718642e434c58b631b238fd85df (diff) | |
| download | swift-091f6e520694360a0407ab0cf3bb036fb461e6e3.zip swift-091f6e520694360a0407ab0cf3bb036fb461e6e3.tar.bz2 | |
Have StreamStack own the top and bottom layer
Test-Information:
Builds, unit tests and integration tests pass on macOS with
clang 7.0 master.
Change-Id: I0db411e49339ccb2301edd1a16612cb1ad2c927c
Diffstat (limited to 'Swiften')
| -rw-r--r-- | Swiften/Session/BasicSessionStream.cpp | 15 | ||||
| -rw-r--r-- | Swiften/Session/BasicSessionStream.h | 4 | ||||
| -rw-r--r-- | Swiften/Session/Session.cpp | 28 | ||||
| -rw-r--r-- | Swiften/Session/Session.h | 16 | ||||
| -rw-r--r-- | Swiften/StreamStack/StreamStack.cpp | 12 | ||||
| -rw-r--r-- | Swiften/StreamStack/StreamStack.h | 14 | ||||
| -rw-r--r-- | Swiften/StreamStack/UnitTest/StreamStackTest.cpp | 29 |
7 files changed, 56 insertions, 62 deletions
diff --git a/Swiften/Session/BasicSessionStream.cpp b/Swiften/Session/BasicSessionStream.cpp index 3e65640..c44961d 100644 --- a/Swiften/Session/BasicSessionStream.cpp +++ b/Swiften/Session/BasicSessionStream.cpp | |||
| @@ -35,7 +35,7 @@ BasicSessionStream::BasicSessionStream( | |||
| 35 | tlsContextFactory(tlsContextFactory), | 35 | tlsContextFactory(tlsContextFactory), |
| 36 | timerFactory(timerFactory), | 36 | timerFactory(timerFactory), |
| 37 | tlsOptions_(tlsOptions) { | 37 | tlsOptions_(tlsOptions) { |
| 38 | xmppLayer = new XMPPLayer(payloadParserFactories, payloadSerializers, xmlParserFactory, streamType); | 38 | auto xmppLayer = std::make_unique<XMPPLayer>(payloadParserFactories, payloadSerializers, xmlParserFactory, streamType); |
| 39 | xmppLayer->onStreamStart.connect(boost::bind(&BasicSessionStream::handleStreamStartReceived, this, _1)); | 39 | xmppLayer->onStreamStart.connect(boost::bind(&BasicSessionStream::handleStreamStartReceived, this, _1)); |
| 40 | xmppLayer->onStreamEnd.connect(boost::bind(&BasicSessionStream::handleStreamEndReceived, this)); | 40 | xmppLayer->onStreamEnd.connect(boost::bind(&BasicSessionStream::handleStreamEndReceived, this)); |
| 41 | xmppLayer->onElement.connect(boost::bind(&BasicSessionStream::handleElementReceived, this, _1)); | 41 | xmppLayer->onElement.connect(boost::bind(&BasicSessionStream::handleElementReceived, this, _1)); |
| @@ -44,10 +44,8 @@ BasicSessionStream::BasicSessionStream( | |||
| 44 | xmppLayer->onWriteData.connect(boost::bind(&BasicSessionStream::handleDataWritten, this, _1)); | 44 | xmppLayer->onWriteData.connect(boost::bind(&BasicSessionStream::handleDataWritten, this, _1)); |
| 45 | 45 | ||
| 46 | connection->onDisconnected.connect(boost::bind(&BasicSessionStream::handleConnectionFinished, this, _1)); | 46 | connection->onDisconnected.connect(boost::bind(&BasicSessionStream::handleConnectionFinished, this, _1)); |
| 47 | connectionLayer = new ConnectionLayer(connection); | ||
| 48 | |||
| 49 | streamStack = new StreamStack(xmppLayer, connectionLayer); | ||
| 50 | 47 | ||
| 48 | streamStack = std::make_unique<StreamStack>(std::move(xmppLayer), std::unique_ptr<ConnectionLayer>(new ConnectionLayer(connection))); | ||
| 51 | available = true; | 49 | available = true; |
| 52 | } | 50 | } |
| 53 | 51 | ||
| @@ -57,37 +55,39 @@ BasicSessionStream::~BasicSessionStream() { | |||
| 57 | tlsLayer->onError.disconnect(boost::bind(&BasicSessionStream::handleTLSError, this, _1)); | 55 | tlsLayer->onError.disconnect(boost::bind(&BasicSessionStream::handleTLSError, this, _1)); |
| 58 | tlsLayer->onConnected.disconnect(boost::bind(&BasicSessionStream::handleTLSConnected, this)); | 56 | tlsLayer->onConnected.disconnect(boost::bind(&BasicSessionStream::handleTLSConnected, this)); |
| 59 | } | 57 | } |
| 60 | delete streamStack; | ||
| 61 | 58 | ||
| 62 | connection->onDisconnected.disconnect(boost::bind(&BasicSessionStream::handleConnectionFinished, this, _1)); | 59 | connection->onDisconnected.disconnect(boost::bind(&BasicSessionStream::handleConnectionFinished, this, _1)); |
| 63 | delete connectionLayer; | ||
| 64 | 60 | ||
| 61 | auto xmppLayer = streamStack->getLayer<XMPPLayer>(); | ||
| 65 | xmppLayer->onStreamStart.disconnect(boost::bind(&BasicSessionStream::handleStreamStartReceived, this, _1)); | 62 | xmppLayer->onStreamStart.disconnect(boost::bind(&BasicSessionStream::handleStreamStartReceived, this, _1)); |
| 66 | xmppLayer->onStreamEnd.disconnect(boost::bind(&BasicSessionStream::handleStreamEndReceived, this)); | 63 | xmppLayer->onStreamEnd.disconnect(boost::bind(&BasicSessionStream::handleStreamEndReceived, this)); |
| 67 | xmppLayer->onElement.disconnect(boost::bind(&BasicSessionStream::handleElementReceived, this, _1)); | 64 | xmppLayer->onElement.disconnect(boost::bind(&BasicSessionStream::handleElementReceived, this, _1)); |
| 68 | xmppLayer->onError.disconnect(boost::bind(&BasicSessionStream::handleXMPPError, this)); | 65 | xmppLayer->onError.disconnect(boost::bind(&BasicSessionStream::handleXMPPError, this)); |
| 69 | xmppLayer->onDataRead.disconnect(boost::bind(&BasicSessionStream::handleDataRead, this, _1)); | 66 | xmppLayer->onDataRead.disconnect(boost::bind(&BasicSessionStream::handleDataRead, this, _1)); |
| 70 | xmppLayer->onWriteData.disconnect(boost::bind(&BasicSessionStream::handleDataWritten, this, _1)); | 67 | xmppLayer->onWriteData.disconnect(boost::bind(&BasicSessionStream::handleDataWritten, this, _1)); |
| 71 | delete xmppLayer; | ||
| 72 | } | 68 | } |
| 73 | 69 | ||
| 74 | void BasicSessionStream::writeHeader(const ProtocolHeader& header) { | 70 | void BasicSessionStream::writeHeader(const ProtocolHeader& header) { |
| 75 | assert(available); | 71 | assert(available); |
| 72 | auto* xmppLayer = streamStack->getLayer<XMPPLayer>(); | ||
| 76 | xmppLayer->writeHeader(header); | 73 | xmppLayer->writeHeader(header); |
| 77 | } | 74 | } |
| 78 | 75 | ||
| 79 | void BasicSessionStream::writeElement(std::shared_ptr<ToplevelElement> element) { | 76 | void BasicSessionStream::writeElement(std::shared_ptr<ToplevelElement> element) { |
| 80 | assert(available); | 77 | assert(available); |
| 78 | auto* xmppLayer = streamStack->getLayer<XMPPLayer>(); | ||
| 81 | xmppLayer->writeElement(element); | 79 | xmppLayer->writeElement(element); |
| 82 | } | 80 | } |
| 83 | 81 | ||
| 84 | void BasicSessionStream::writeFooter() { | 82 | void BasicSessionStream::writeFooter() { |
| 85 | assert(available); | 83 | assert(available); |
| 84 | auto* xmppLayer = streamStack->getLayer<XMPPLayer>(); | ||
| 86 | xmppLayer->writeFooter(); | 85 | xmppLayer->writeFooter(); |
| 87 | } | 86 | } |
| 88 | 87 | ||
| 89 | void BasicSessionStream::writeData(const std::string& data) { | 88 | void BasicSessionStream::writeData(const std::string& data) { |
| 90 | assert(available); | 89 | assert(available); |
| 90 | auto* xmppLayer = streamStack->getLayer<XMPPLayer>(); | ||
| 91 | xmppLayer->writeData(data); | 91 | xmppLayer->writeData(data); |
| 92 | } | 92 | } |
| 93 | 93 | ||
| @@ -162,6 +162,7 @@ void BasicSessionStream::setWhitespacePingEnabled(bool enabled) { | |||
| 162 | } | 162 | } |
| 163 | 163 | ||
| 164 | void BasicSessionStream::resetXMPPParser() { | 164 | void BasicSessionStream::resetXMPPParser() { |
| 165 | auto* xmppLayer = streamStack->getLayer<XMPPLayer>(); | ||
| 165 | xmppLayer->resetParser(); | 166 | xmppLayer->resetParser(); |
| 166 | } | 167 | } |
| 167 | 168 | ||
diff --git a/Swiften/Session/BasicSessionStream.h b/Swiften/Session/BasicSessionStream.h index 472b5cc..30a7e3b 100644 --- a/Swiften/Session/BasicSessionStream.h +++ b/Swiften/Session/BasicSessionStream.h | |||
| @@ -83,9 +83,7 @@ namespace Swift { | |||
| 83 | std::shared_ptr<Connection> connection; | 83 | std::shared_ptr<Connection> connection; |
| 84 | TLSContextFactory* tlsContextFactory; | 84 | TLSContextFactory* tlsContextFactory; |
| 85 | TimerFactory* timerFactory; | 85 | TimerFactory* timerFactory; |
| 86 | XMPPLayer* xmppLayer; | 86 | std::unique_ptr<StreamStack> streamStack; |
| 87 | ConnectionLayer* connectionLayer; | ||
| 88 | StreamStack* streamStack; | ||
| 89 | TLSOptions tlsOptions_; | 87 | TLSOptions tlsOptions_; |
| 90 | }; | 88 | }; |
| 91 | 89 | ||
diff --git a/Swiften/Session/Session.cpp b/Swiften/Session/Session.cpp index ebdb5d1..b1525b8 100644 --- a/Swiften/Session/Session.cpp +++ b/Swiften/Session/Session.cpp | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2010-2016 Isode Limited. | 2 | * Copyright (c) 2010-2018 Isode Limited. |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. |
| 5 | */ | 5 | */ |
| @@ -22,16 +22,10 @@ Session::Session( | |||
| 22 | payloadParserFactories(payloadParserFactories), | 22 | payloadParserFactories(payloadParserFactories), |
| 23 | payloadSerializers(payloadSerializers), | 23 | payloadSerializers(payloadSerializers), |
| 24 | xmlParserFactory(xmlParserFactory), | 24 | xmlParserFactory(xmlParserFactory), |
| 25 | xmppLayer(nullptr), | ||
| 26 | connectionLayer(nullptr), | ||
| 27 | streamStack(nullptr), | ||
| 28 | finishing(false) { | 25 | finishing(false) { |
| 29 | } | 26 | } |
| 30 | 27 | ||
| 31 | Session::~Session() { | 28 | Session::~Session() { |
| 32 | delete streamStack; | ||
| 33 | delete connectionLayer; | ||
| 34 | delete xmppLayer; | ||
| 35 | } | 29 | } |
| 36 | 30 | ||
| 37 | void Session::startSession() { | 31 | void Session::startSession() { |
| @@ -44,7 +38,7 @@ void Session::finishSession() { | |||
| 44 | return; | 38 | return; |
| 45 | } | 39 | } |
| 46 | finishing = true; | 40 | finishing = true; |
| 47 | if (xmppLayer) { | 41 | if (auto xmppLayer = getXMPPLayer()) { |
| 48 | xmppLayer->writeFooter(); | 42 | xmppLayer->writeFooter(); |
| 49 | } | 43 | } |
| 50 | connection->disconnect(); | 44 | connection->disconnect(); |
| @@ -55,14 +49,14 @@ void Session::finishSession(const SessionError& /*error*/) { | |||
| 55 | return; | 49 | return; |
| 56 | } | 50 | } |
| 57 | finishing = true; | 51 | finishing = true; |
| 58 | if (xmppLayer) { | 52 | if (auto xmppLayer = getXMPPLayer()) { |
| 59 | xmppLayer->writeFooter(); | 53 | xmppLayer->writeFooter(); |
| 60 | } | 54 | } |
| 61 | connection->disconnect(); | 55 | connection->disconnect(); |
| 62 | } | 56 | } |
| 63 | 57 | ||
| 64 | void Session::initializeStreamStack() { | 58 | void Session::initializeStreamStack() { |
| 65 | xmppLayer = new XMPPLayer(payloadParserFactories, payloadSerializers, xmlParserFactory, ClientStreamType); | 59 | auto xmppLayer = std::unique_ptr<XMPPLayer>(new XMPPLayer(payloadParserFactories, payloadSerializers, xmlParserFactory, ClientStreamType)); |
| 66 | xmppLayer->onStreamStart.connect( | 60 | xmppLayer->onStreamStart.connect( |
| 67 | boost::bind(&Session::handleStreamStart, this, _1)); | 61 | boost::bind(&Session::handleStreamStart, this, _1)); |
| 68 | xmppLayer->onElement.connect(boost::bind(&Session::handleElement, this, _1)); | 62 | xmppLayer->onElement.connect(boost::bind(&Session::handleElement, this, _1)); |
| @@ -72,12 +66,20 @@ void Session::initializeStreamStack() { | |||
| 72 | xmppLayer->onWriteData.connect(boost::bind(boost::ref(onDataWritten), _1)); | 66 | xmppLayer->onWriteData.connect(boost::bind(boost::ref(onDataWritten), _1)); |
| 73 | connection->onDisconnected.connect( | 67 | connection->onDisconnected.connect( |
| 74 | boost::bind(&Session::handleDisconnected, this, _1)); | 68 | boost::bind(&Session::handleDisconnected, this, _1)); |
| 75 | connectionLayer = new ConnectionLayer(connection); | 69 | streamStack = std::unique_ptr<StreamStack>(new StreamStack(std::move(xmppLayer), std::unique_ptr<ConnectionLayer>(new ConnectionLayer(connection)))); |
| 76 | streamStack = new StreamStack(xmppLayer, connectionLayer); | ||
| 77 | } | 70 | } |
| 78 | 71 | ||
| 72 | XMPPLayer* Session::getXMPPLayer() const { | ||
| 73 | return dynamic_cast<XMPPLayer*>(streamStack->getTopLayer()); | ||
| 74 | } | ||
| 75 | |||
| 76 | StreamStack* Session::getStreamStack() const { | ||
| 77 | return streamStack.get(); | ||
| 78 | } | ||
| 79 | |||
| 80 | |||
| 79 | void Session::sendElement(std::shared_ptr<ToplevelElement> stanza) { | 81 | void Session::sendElement(std::shared_ptr<ToplevelElement> stanza) { |
| 80 | xmppLayer->writeElement(stanza); | 82 | getXMPPLayer()->writeElement(stanza); |
| 81 | } | 83 | } |
| 82 | 84 | ||
| 83 | void Session::handleDisconnected(const boost::optional<Connection::Error>& connectionError) { | 85 | void Session::handleDisconnected(const boost::optional<Connection::Error>& connectionError) { |
diff --git a/Swiften/Session/Session.h b/Swiften/Session/Session.h index 04153ec..e6a0d53 100644 --- a/Swiften/Session/Session.h +++ b/Swiften/Session/Session.h | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2010-2017 Isode Limited. | 2 | * Copyright (c) 2010-2018 Isode Limited. |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. |
| 5 | */ | 5 | */ |
| @@ -85,13 +85,8 @@ namespace Swift { | |||
| 85 | 85 | ||
| 86 | void initializeStreamStack(); | 86 | void initializeStreamStack(); |
| 87 | 87 | ||
| 88 | XMPPLayer* getXMPPLayer() const { | 88 | XMPPLayer* getXMPPLayer() const; |
| 89 | return xmppLayer; | 89 | StreamStack* getStreamStack() const; |
| 90 | } | ||
| 91 | |||
| 92 | StreamStack* getStreamStack() const { | ||
| 93 | return streamStack; | ||
| 94 | } | ||
| 95 | 90 | ||
| 96 | void setFinished(); | 91 | void setFinished(); |
| 97 | 92 | ||
| @@ -105,9 +100,8 @@ namespace Swift { | |||
| 105 | PayloadParserFactoryCollection* payloadParserFactories; | 100 | PayloadParserFactoryCollection* payloadParserFactories; |
| 106 | PayloadSerializerCollection* payloadSerializers; | 101 | PayloadSerializerCollection* payloadSerializers; |
| 107 | XMLParserFactory* xmlParserFactory; | 102 | XMLParserFactory* xmlParserFactory; |
| 108 | XMPPLayer* xmppLayer; | 103 | |
| 109 | ConnectionLayer* connectionLayer; | 104 | std::unique_ptr<StreamStack> streamStack; |
| 110 | StreamStack* streamStack; | ||
| 111 | bool finishing; | 105 | bool finishing; |
| 112 | }; | 106 | }; |
| 113 | } | 107 | } |
diff --git a/Swiften/StreamStack/StreamStack.cpp b/Swiften/StreamStack/StreamStack.cpp index 75fb1ce..cf80fb1 100644 --- a/Swiften/StreamStack/StreamStack.cpp +++ b/Swiften/StreamStack/StreamStack.cpp | |||
| @@ -8,25 +8,25 @@ | |||
| 8 | 8 | ||
| 9 | #include <boost/bind.hpp> | 9 | #include <boost/bind.hpp> |
| 10 | 10 | ||
| 11 | #include <Swiften/StreamStack/HighLayer.h> | ||
| 11 | #include <Swiften/StreamStack/LowLayer.h> | 12 | #include <Swiften/StreamStack/LowLayer.h> |
| 12 | #include <Swiften/StreamStack/StreamLayer.h> | 13 | #include <Swiften/StreamStack/StreamLayer.h> |
| 13 | #include <Swiften/StreamStack/HighLayer.h> | ||
| 14 | 14 | ||
| 15 | namespace Swift { | 15 | namespace Swift { |
| 16 | 16 | ||
| 17 | StreamStack::StreamStack(HighLayer* topLayer, LowLayer* bottomLayer) : topLayer_(topLayer), bottomLayer_(bottomLayer) { | 17 | StreamStack::StreamStack(std::unique_ptr<HighLayer> topLayer, std::unique_ptr<LowLayer> bottomLayer) : topLayer_(std::move(topLayer)), bottomLayer_(std::move(bottomLayer)) { |
| 18 | bottomLayer_->setParentLayer(topLayer_); | 18 | bottomLayer_->setParentLayer(topLayer_.get()); |
| 19 | topLayer_->setChildLayer(bottomLayer_); | 19 | topLayer_->setChildLayer(bottomLayer_.get()); |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | StreamStack::~StreamStack() { | 22 | StreamStack::~StreamStack() { |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | void StreamStack::addLayer(std::unique_ptr<StreamLayer> streamLayer) { | 25 | void StreamStack::addLayer(std::unique_ptr<StreamLayer> streamLayer) { |
| 26 | LowLayer* lowLayer = layers_.empty() ? bottomLayer_ : layers_.rbegin()->get(); | 26 | auto* lowLayer = layers_.empty() ? bottomLayer_.get() : layers_.rbegin()->get(); |
| 27 | 27 | ||
| 28 | topLayer_->setChildLayer(streamLayer.get()); | 28 | topLayer_->setChildLayer(streamLayer.get()); |
| 29 | streamLayer->setParentLayer(topLayer_); | 29 | streamLayer->setParentLayer(topLayer_.get()); |
| 30 | 30 | ||
| 31 | lowLayer->setParentLayer(streamLayer.get()); | 31 | lowLayer->setParentLayer(streamLayer.get()); |
| 32 | streamLayer->setChildLayer(lowLayer); | 32 | streamLayer->setChildLayer(lowLayer); |
diff --git a/Swiften/StreamStack/StreamStack.h b/Swiften/StreamStack/StreamStack.h index bd95811..263b1f5 100644 --- a/Swiften/StreamStack/StreamStack.h +++ b/Swiften/StreamStack/StreamStack.h | |||
| @@ -21,13 +21,13 @@ namespace Swift { | |||
| 21 | 21 | ||
| 22 | class SWIFTEN_API StreamStack { | 22 | class SWIFTEN_API StreamStack { |
| 23 | public: | 23 | public: |
| 24 | StreamStack(HighLayer* topLayer, LowLayer* bottomLayer); | 24 | StreamStack(std::unique_ptr<HighLayer> topLayer, std::unique_ptr<LowLayer> bottomLayer); |
| 25 | ~StreamStack(); | 25 | ~StreamStack(); |
| 26 | 26 | ||
| 27 | void addLayer(std::unique_ptr<StreamLayer> /* streamLayer */); | 27 | void addLayer(std::unique_ptr<StreamLayer> /* streamLayer */); |
| 28 | 28 | ||
| 29 | HighLayer* getTopLayer() const { | 29 | HighLayer* getTopLayer() const { |
| 30 | return topLayer_; | 30 | return topLayer_.get(); |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | template<typename T> T* getLayer() const { | 33 | template<typename T> T* getLayer() const { |
| @@ -37,12 +37,18 @@ namespace Swift { | |||
| 37 | return layer; | 37 | return layer; |
| 38 | } | 38 | } |
| 39 | } | 39 | } |
| 40 | if (T* layer = dynamic_cast<T*>(topLayer_.get())) { | ||
| 41 | return layer; | ||
| 42 | } | ||
| 43 | if (T* layer = dynamic_cast<T*>(bottomLayer_.get())) { | ||
| 44 | return layer; | ||
| 45 | } | ||
| 40 | return nullptr; | 46 | return nullptr; |
| 41 | } | 47 | } |
| 42 | 48 | ||
| 43 | private: | 49 | private: |
| 44 | HighLayer* topLayer_; | 50 | std::unique_ptr<HighLayer> topLayer_; |
| 45 | LowLayer* bottomLayer_; | 51 | std::unique_ptr<LowLayer> bottomLayer_; |
| 46 | std::vector<std::unique_ptr<StreamLayer>> layers_; | 52 | std::vector<std::unique_ptr<StreamLayer>> layers_; |
| 47 | }; | 53 | }; |
| 48 | } | 54 | } |
diff --git a/Swiften/StreamStack/UnitTest/StreamStackTest.cpp b/Swiften/StreamStack/UnitTest/StreamStackTest.cpp index 0b520f1..b074736 100644 --- a/Swiften/StreamStack/UnitTest/StreamStackTest.cpp +++ b/Swiften/StreamStack/UnitTest/StreamStackTest.cpp | |||
| @@ -39,19 +39,17 @@ class StreamStackTest : public CppUnit::TestFixture { | |||
| 39 | 39 | ||
| 40 | public: | 40 | public: |
| 41 | void setUp() { | 41 | void setUp() { |
| 42 | physicalStream_ = new TestLowLayer(); | 42 | testling_ = std::make_unique<StreamStack>(std::make_unique<XMPPLayer>(&parserFactories_, &serializers_, &xmlParserFactory_, ClientStreamType), std::make_unique<TestLowLayer>()); |
| 43 | xmppStream_ = new XMPPLayer(&parserFactories_, &serializers_, &xmlParserFactory_, ClientStreamType); | 43 | physicalStream_ = testling_->getLayer<TestLowLayer>(); |
| 44 | xmppStream_ = testling_->getLayer<XMPPLayer>(); | ||
| 44 | elementsReceived_ = 0; | 45 | elementsReceived_ = 0; |
| 45 | dataWriteReceived_ = 0; | 46 | dataWriteReceived_ = 0; |
| 46 | } | 47 | } |
| 47 | 48 | ||
| 48 | void tearDown() { | 49 | void tearDown() { |
| 49 | delete physicalStream_; | ||
| 50 | delete xmppStream_; | ||
| 51 | } | 50 | } |
| 52 | 51 | ||
| 53 | void testWriteData_NoIntermediateStreamStack() { | 52 | void testWriteData_NoIntermediateStreamStack() { |
| 54 | StreamStack testling(xmppStream_, physicalStream_); | ||
| 55 | 53 | ||
| 56 | xmppStream_->writeData("foo"); | 54 | xmppStream_->writeData("foo"); |
| 57 | 55 | ||
| @@ -60,9 +58,8 @@ class StreamStackTest : public CppUnit::TestFixture { | |||
| 60 | } | 58 | } |
| 61 | 59 | ||
| 62 | void testWriteData_OneIntermediateStream() { | 60 | void testWriteData_OneIntermediateStream() { |
| 63 | StreamStack testling(xmppStream_, physicalStream_); | ||
| 64 | std::unique_ptr<MyStreamLayer> xStream(new MyStreamLayer("X")); | 61 | std::unique_ptr<MyStreamLayer> xStream(new MyStreamLayer("X")); |
| 65 | testling.addLayer(std::move(xStream)); | 62 | testling_->addLayer(std::move(xStream)); |
| 66 | 63 | ||
| 67 | xmppStream_->writeData("foo"); | 64 | xmppStream_->writeData("foo"); |
| 68 | 65 | ||
| @@ -71,11 +68,10 @@ class StreamStackTest : public CppUnit::TestFixture { | |||
| 71 | } | 68 | } |
| 72 | 69 | ||
| 73 | void testWriteData_TwoIntermediateStreamStack() { | 70 | void testWriteData_TwoIntermediateStreamStack() { |
| 74 | StreamStack testling(xmppStream_, physicalStream_); | ||
| 75 | std::unique_ptr<MyStreamLayer> xStream(new MyStreamLayer("X")); | 71 | std::unique_ptr<MyStreamLayer> xStream(new MyStreamLayer("X")); |
| 76 | std::unique_ptr<MyStreamLayer> yStream(new MyStreamLayer("Y")); | 72 | std::unique_ptr<MyStreamLayer> yStream(new MyStreamLayer("Y")); |
| 77 | testling.addLayer(std::move(xStream)); | 73 | testling_->addLayer(std::move(xStream)); |
| 78 | testling.addLayer(std::move(yStream)); | 74 | testling_->addLayer(std::move(yStream)); |
| 79 | 75 | ||
| 80 | xmppStream_->writeData("foo"); | 76 | xmppStream_->writeData("foo"); |
| 81 | 77 | ||
| @@ -84,7 +80,6 @@ class StreamStackTest : public CppUnit::TestFixture { | |||
| 84 | } | 80 | } |
| 85 | 81 | ||
| 86 | void testReadData_NoIntermediateStreamStack() { | 82 | void testReadData_NoIntermediateStreamStack() { |
| 87 | StreamStack testling(xmppStream_, physicalStream_); | ||
| 88 | xmppStream_->onElement.connect(boost::bind(&StreamStackTest::handleElement, this, _1)); | 83 | xmppStream_->onElement.connect(boost::bind(&StreamStackTest::handleElement, this, _1)); |
| 89 | 84 | ||
| 90 | physicalStream_->onDataRead(createSafeByteArray("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'><presence/>")); | 85 | physicalStream_->onDataRead(createSafeByteArray("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'><presence/>")); |
| @@ -93,10 +88,9 @@ class StreamStackTest : public CppUnit::TestFixture { | |||
| 93 | } | 88 | } |
| 94 | 89 | ||
| 95 | void testReadData_OneIntermediateStream() { | 90 | void testReadData_OneIntermediateStream() { |
| 96 | StreamStack testling(xmppStream_, physicalStream_); | ||
| 97 | xmppStream_->onElement.connect(boost::bind(&StreamStackTest::handleElement, this, _1)); | 91 | xmppStream_->onElement.connect(boost::bind(&StreamStackTest::handleElement, this, _1)); |
| 98 | std::unique_ptr<MyStreamLayer> xStream(new MyStreamLayer("<")); | 92 | std::unique_ptr<MyStreamLayer> xStream(new MyStreamLayer("<")); |
| 99 | testling.addLayer(std::move(xStream)); | 93 | testling_->addLayer(std::move(xStream)); |
| 100 | 94 | ||
| 101 | physicalStream_->onDataRead(createSafeByteArray("stream:stream xmlns:stream='http://etherx.jabber.org/streams'><presence/>")); | 95 | physicalStream_->onDataRead(createSafeByteArray("stream:stream xmlns:stream='http://etherx.jabber.org/streams'><presence/>")); |
| 102 | 96 | ||
| @@ -104,12 +98,11 @@ class StreamStackTest : public CppUnit::TestFixture { | |||
| 104 | } | 98 | } |
| 105 | 99 | ||
| 106 | void testReadData_TwoIntermediateStreamStack() { | 100 | void testReadData_TwoIntermediateStreamStack() { |
| 107 | StreamStack testling(xmppStream_, physicalStream_); | ||
| 108 | xmppStream_->onElement.connect(boost::bind(&StreamStackTest::handleElement, this, _1)); | 101 | xmppStream_->onElement.connect(boost::bind(&StreamStackTest::handleElement, this, _1)); |
| 109 | std::unique_ptr<MyStreamLayer> xStream(new MyStreamLayer("s")); | 102 | std::unique_ptr<MyStreamLayer> xStream(new MyStreamLayer("s")); |
| 110 | std::unique_ptr<MyStreamLayer> yStream(new MyStreamLayer("<")); | 103 | std::unique_ptr<MyStreamLayer> yStream(new MyStreamLayer("<")); |
| 111 | testling.addLayer(std::move(xStream)); | 104 | testling_->addLayer(std::move(xStream)); |
| 112 | testling.addLayer(std::move(yStream)); | 105 | testling_->addLayer(std::move(yStream)); |
| 113 | 106 | ||
| 114 | physicalStream_->onDataRead(createSafeByteArray("tream:stream xmlns:stream='http://etherx.jabber.org/streams'><presence/>")); | 107 | physicalStream_->onDataRead(createSafeByteArray("tream:stream xmlns:stream='http://etherx.jabber.org/streams'><presence/>")); |
| 115 | 108 | ||
| @@ -117,10 +110,9 @@ class StreamStackTest : public CppUnit::TestFixture { | |||
| 117 | } | 110 | } |
| 118 | 111 | ||
| 119 | void testAddLayer_ExistingOnWriteDataSlot() { | 112 | void testAddLayer_ExistingOnWriteDataSlot() { |
| 120 | StreamStack testling(xmppStream_, physicalStream_); | ||
| 121 | xmppStream_->onWriteData.connect(boost::bind(&StreamStackTest::handleWriteData, this, _1)); | 113 | xmppStream_->onWriteData.connect(boost::bind(&StreamStackTest::handleWriteData, this, _1)); |
| 122 | std::unique_ptr<MyStreamLayer> xStream(new MyStreamLayer("X")); | 114 | std::unique_ptr<MyStreamLayer> xStream(new MyStreamLayer("X")); |
| 123 | testling.addLayer(std::move(xStream)); | 115 | testling_->addLayer(std::move(xStream)); |
| 124 | 116 | ||
| 125 | xmppStream_->writeData("foo"); | 117 | xmppStream_->writeData("foo"); |
| 126 | 118 | ||
| @@ -176,6 +168,7 @@ class StreamStackTest : public CppUnit::TestFixture { | |||
| 176 | TestLowLayer* physicalStream_; | 168 | TestLowLayer* physicalStream_; |
| 177 | PlatformXMLParserFactory xmlParserFactory_; | 169 | PlatformXMLParserFactory xmlParserFactory_; |
| 178 | XMPPLayer* xmppStream_; | 170 | XMPPLayer* xmppStream_; |
| 171 | std::unique_ptr<StreamStack> testling_; | ||
| 179 | int elementsReceived_; | 172 | int elementsReceived_; |
| 180 | int dataWriteReceived_; | 173 | int dataWriteReceived_; |
| 181 | }; | 174 | }; |
Swift