summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-12-20 19:32:47 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-12-20 19:32:47 (GMT)
commit3f7f5cca368cb19315210c3e6b6a77deb690fcf5 (patch)
tree20aa0a3b8aa3504c3b74925c2a7f67433a2e2db1
parent5fb907768fb3bfbd095564146b19a3a8492b91ec (diff)
downloadswift-contrib-3f7f5cca368cb19315210c3e6b6a77deb690fcf5.zip
swift-contrib-3f7f5cca368cb19315210c3e6b6a77deb690fcf5.tar.bz2
Re-enabling XMPPLayer unit tests.
-rw-r--r--Swiften/StreamStack/UnitTest/XMPPLayerTest.cpp49
1 files changed, 26 insertions, 23 deletions
diff --git a/Swiften/StreamStack/UnitTest/XMPPLayerTest.cpp b/Swiften/StreamStack/UnitTest/XMPPLayerTest.cpp
index 21683e8..77e6f7e 100644
--- a/Swiften/StreamStack/UnitTest/XMPPLayerTest.cpp
+++ b/Swiften/StreamStack/UnitTest/XMPPLayerTest.cpp
@@ -13,35 +13,34 @@
#include "Swiften/Elements/Presence.h"
#include "Swiften/Base/ByteArray.h"
#include "Swiften/StreamStack/XMPPLayer.h"
+#include "Swiften/StreamStack/LowLayer.h"
#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h"
#include "Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h"
using namespace Swift;
-class XMPPLayerTest : public CppUnit::TestFixture
-{
+class XMPPLayerTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(XMPPLayerTest);
- //FIXME: re-enable tests!
- //CPPUNIT_TEST(testParseData_Error);
- //CPPUNIT_TEST(testResetParser);
- //CPPUNIT_TEST(testResetParser_FromSlot);
- //CPPUNIT_TEST(testWriteHeader);
- //CPPUNIT_TEST(testWriteElement);
- //CPPUNIT_TEST(testWriteFooter);
+ CPPUNIT_TEST(testParseData_Error);
+ CPPUNIT_TEST(testResetParser);
+ CPPUNIT_TEST(testResetParser_FromSlot);
+ CPPUNIT_TEST(testWriteHeader);
+ CPPUNIT_TEST(testWriteElement);
+ CPPUNIT_TEST(testWriteFooter);
CPPUNIT_TEST_SUITE_END();
public:
- XMPPLayerTest() {}
-
void setUp() {
+ lowLayer_ = new DummyLowLayer();
testling_ = new XMPPLayerExposed(&parserFactories_, &serializers_, ClientStreamType);
+ testling_->setChildLayer(lowLayer_);
elementsReceived_ = 0;
- dataReceived_ = "";
errorReceived_ = 0;
}
void tearDown() {
delete testling_;
+ delete lowLayer_;
}
void testParseData_Error() {
@@ -75,26 +74,23 @@ class XMPPLayerTest : public CppUnit::TestFixture
}
void testWriteHeader() {
- testling_->onWriteData.connect(boost::bind(&XMPPLayerTest::handleWriteData, this, _1));
ProtocolHeader header;
header.setTo("example.com");
testling_->writeHeader(header);
- CPPUNIT_ASSERT_EQUAL(String("<?xml version=\"1.0\"?><stream:stream xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\" to=\"example.com\" version=\"1.0\">"), dataReceived_);
+ CPPUNIT_ASSERT_EQUAL(String("<?xml version=\"1.0\"?><stream:stream xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\" to=\"example.com\" version=\"1.0\">"), lowLayer_->writtenData);
}
void testWriteElement() {
- testling_->onWriteData.connect(boost::bind(&XMPPLayerTest::handleWriteData, this, _1));
testling_->writeElement(boost::shared_ptr<Presence>(new Presence()));
- CPPUNIT_ASSERT_EQUAL(String("<presence/>"), dataReceived_);
+ CPPUNIT_ASSERT_EQUAL(String("<presence/>"), lowLayer_->writtenData);
}
void testWriteFooter() {
- testling_->onWriteData.connect(boost::bind(&XMPPLayerTest::handleWriteData, this, _1));
testling_->writeFooter();
- CPPUNIT_ASSERT_EQUAL(String("</stream:stream>"), dataReceived_);
+ CPPUNIT_ASSERT_EQUAL(String("</stream:stream>"), lowLayer_->writtenData);
}
void handleElement(boost::shared_ptr<Element>) {
@@ -106,10 +102,6 @@ class XMPPLayerTest : public CppUnit::TestFixture
testling_->resetParser();
}
- void handleWriteData(ByteArray ba) {
- dataReceived_ += std::string(ba.getData(), ba.getSize());
- }
-
void handleError() {
++errorReceived_;
}
@@ -121,14 +113,25 @@ class XMPPLayerTest : public CppUnit::TestFixture
PayloadParserFactoryCollection* payloadParserFactories,
PayloadSerializerCollection* payloadSerializers,
StreamType streamType) : XMPPLayer(payloadParserFactories, payloadSerializers, streamType) {}
+
using XMPPLayer::handleDataRead;
+ using HighLayer::setChildLayer;
+ };
+
+ class DummyLowLayer : public LowLayer {
+ public:
+ virtual void writeData(const ByteArray& data) {
+ writtenData += std::string(data.getData(), data.getSize());
+ }
+
+ String writtenData;
};
FullPayloadParserFactoryCollection parserFactories_;
FullPayloadSerializerCollection serializers_;
+ DummyLowLayer* lowLayer_;
XMPPLayerExposed* testling_;
int elementsReceived_;
- String dataReceived_;
int errorReceived_;
};