From 3f7f5cca368cb19315210c3e6b6a77deb690fcf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= <git@el-tramo.be> Date: Mon, 20 Dec 2010 20:32:47 +0100 Subject: Re-enabling XMPPLayer unit tests. 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_; }; -- cgit v0.10.2-6-g49f6