diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-10-15 16:15:57 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-10-15 16:15:57 (GMT) |
commit | 062658db9f46ef749eeec09c162e5afaf1524ab6 (patch) | |
tree | 12ea883e39c7d938310ea715c71127bc1801319c /Swiften/Serializer/UnitTest | |
parent | f52aa93c3d6d5976b072d31f3d3336beb1596ece (diff) | |
download | swift-062658db9f46ef749eeec09c162e5afaf1524ab6.zip swift-062658db9f46ef749eeec09c162e5afaf1524ab6.tar.bz2 |
Added Component parser, serializer, element, and connector.
Diffstat (limited to 'Swiften/Serializer/UnitTest')
-rw-r--r-- | Swiften/Serializer/UnitTest/XMPPSerializerTest.cpp | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/Swiften/Serializer/UnitTest/XMPPSerializerTest.cpp b/Swiften/Serializer/UnitTest/XMPPSerializerTest.cpp new file mode 100644 index 0000000..45ffe4b --- /dev/null +++ b/Swiften/Serializer/UnitTest/XMPPSerializerTest.cpp @@ -0,0 +1,75 @@ +/* + * 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 "Swiften/Serializer/XMPPSerializer.h" +#include "Swiften/Elements/AuthChallenge.h" +#include "Swiften/Serializer/PayloadSerializerCollection.h" +#include "Swiften/Elements/ProtocolHeader.h" + +using namespace Swift; + +class XMPPSerializerTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(XMPPSerializerTest); + CPPUNIT_TEST(testSerializeHeader_Client); + CPPUNIT_TEST(testSerializeHeader_Component); + CPPUNIT_TEST(testSerializeHeader_Server); + CPPUNIT_TEST_SUITE_END(); + + public: + void setUp() { + payloadSerializerCollection = new PayloadSerializerCollection(); + } + + void tearDown() { + delete payloadSerializerCollection; + } + + void testSerializeHeader_Client() { + std::auto_ptr<XMPPSerializer> testling(createSerializer(ClientStreamType)); + ProtocolHeader protocolHeader; + protocolHeader.setFrom("bla@foo.com"); + protocolHeader.setTo("foo.com"); + protocolHeader.setID("myid"); + protocolHeader.setVersion("0.99"); + + CPPUNIT_ASSERT_EQUAL(String("<?xml version=\"1.0\"?><stream:stream xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\" from=\"bla@foo.com\" to=\"foo.com\" id=\"myid\" version=\"0.99\">"), testling->serializeHeader(protocolHeader)); + } + + void testSerializeHeader_Component() { + std::auto_ptr<XMPPSerializer> testling(createSerializer(ComponentStreamType)); + ProtocolHeader protocolHeader; + protocolHeader.setFrom("bla@foo.com"); + protocolHeader.setTo("foo.com"); + protocolHeader.setID("myid"); + protocolHeader.setVersion("0.99"); + + CPPUNIT_ASSERT_EQUAL(String("<?xml version=\"1.0\"?><stream:stream xmlns=\"jabber:component:accept\" xmlns:stream=\"http://etherx.jabber.org/streams\" from=\"bla@foo.com\" to=\"foo.com\" id=\"myid\" version=\"0.99\">"), testling->serializeHeader(protocolHeader)); + } + + void testSerializeHeader_Server() { + std::auto_ptr<XMPPSerializer> testling(createSerializer(ServerStreamType)); + ProtocolHeader protocolHeader; + protocolHeader.setFrom("bla@foo.com"); + protocolHeader.setTo("foo.com"); + protocolHeader.setID("myid"); + protocolHeader.setVersion("0.99"); + + CPPUNIT_ASSERT_EQUAL(String("<?xml version=\"1.0\"?><stream:stream xmlns=\"jabber:server\" xmlns:stream=\"http://etherx.jabber.org/streams\" from=\"bla@foo.com\" to=\"foo.com\" id=\"myid\" version=\"0.99\">"), testling->serializeHeader(protocolHeader)); + } + + private: + XMPPSerializer* createSerializer(StreamType type) { + return new XMPPSerializer(payloadSerializerCollection, type); + } + + private: + PayloadSerializerCollection* payloadSerializerCollection; +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(XMPPSerializerTest); |