diff options
Diffstat (limited to 'Swiften/Parser/PayloadParsers/UnitTest')
16 files changed, 111 insertions, 119 deletions
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/BodyParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/BodyParserTest.cpp index c747452..2fc6180 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/BodyParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/BodyParserTest.cpp @@ -2,7 +2,7 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include "Swiften/Parser/PayloadParsers/BodyParser.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h" +#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" using namespace Swift; @@ -16,12 +16,11 @@ class BodyParserTest : public CppUnit::TestFixture BodyParserTest() {} void testParse() { - BodyParser testling; - PayloadParserTester parser(&testling); + PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse("<body>foo<baz>bar</baz>fum</body>")); - Body* payload = dynamic_cast<Body*>(testling.getPayload().get()); + Body* payload = dynamic_cast<Body*>(parser.getPayload().get()); CPPUNIT_ASSERT_EQUAL(String("foobarfum"), payload->getText()); } }; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp index 5aed12f..49b706e 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp @@ -2,7 +2,7 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include "Swiften/Parser/PayloadParsers/DiscoInfoParser.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h" +#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" using namespace Swift; @@ -16,8 +16,7 @@ class DiscoInfoParserTest : public CppUnit::TestFixture DiscoInfoParserTest() {} void testParse() { - DiscoInfoParser testling; - PayloadParserTester parser(&testling); + PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "<query xmlns=\"http://jabber.org/protocol/disco#info\">" @@ -28,7 +27,7 @@ class DiscoInfoParserTest : public CppUnit::TestFixture "<feature var=\"baz-feature\"/>" "</query>")); - DiscoInfo* payload = dynamic_cast<DiscoInfo*>(testling.getPayload().get()); + DiscoInfo* payload = dynamic_cast<DiscoInfo*>(parser.getPayload().get()); CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getIdentities().size())); CPPUNIT_ASSERT_EQUAL(String("Swift"), payload->getIdentities()[0].getName()); CPPUNIT_ASSERT_EQUAL(String("pc"), payload->getIdentities()[0].getType()); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/ErrorParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/ErrorParserTest.cpp index 719702d..338fb3f 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/ErrorParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/ErrorParserTest.cpp @@ -2,7 +2,7 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include "Swiften/Parser/PayloadParsers/ErrorParser.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h" +#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" using namespace Swift; @@ -16,8 +16,7 @@ class ErrorParserTest : public CppUnit::TestFixture ErrorParserTest() {} void testParse() { - ErrorParser testling; - PayloadParserTester parser(&testling); + PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "<error type=\"modify\">" @@ -25,7 +24,7 @@ class ErrorParserTest : public CppUnit::TestFixture "<text xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\">boo</text>" "</error>")); - Error* payload = dynamic_cast<Error*>(testling.getPayload().get()); + Error* payload = dynamic_cast<Error*>(parser.getPayload().get()); CPPUNIT_ASSERT_EQUAL(Error::BadRequest, payload->getCondition()); CPPUNIT_ASSERT_EQUAL(Error::Modify, payload->getType()); CPPUNIT_ASSERT_EQUAL(String("boo"), payload->getText()); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h b/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h new file mode 100644 index 0000000..ac167cf --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h @@ -0,0 +1,55 @@ +#pragma once + +#include <cppunit/extensions/HelperMacros.h> + +#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h" +#include "Swiften/Parser/XMLParser.h" +#include "Swiften/Parser/XMLParserClient.h" +#include "Swiften/Parser/PlatformXMLParserFactory.h" + +namespace Swift { + class PayloadsParserTester : public XMLParserClient { + public: + PayloadsParserTester() : level(0) { + xmlParser = PlatformXMLParserFactory().createXMLParser(this); + } + + ~PayloadsParserTester() { + delete xmlParser; + } + + bool parse(const String& data) { + return xmlParser->parse(data); + } + + virtual void handleStartElement(const String& element, const String& ns, const AttributeMap& attributes) { + if (level == 0) { + CPPUNIT_ASSERT(!payloadParser.get()); + PayloadParserFactory* payloadParserFactory = factories.getPayloadParserFactory(element, ns, attributes); + CPPUNIT_ASSERT(payloadParserFactory); + payloadParser.reset(payloadParserFactory->createPayloadParser()); + } + payloadParser->handleStartElement(element, ns, attributes); + level++; + } + + virtual void handleEndElement(const String& element, const String& ns) { + level--; + payloadParser->handleEndElement(element, ns); + } + + virtual void handleCharacterData(const String& data) { + payloadParser->handleCharacterData(data); + } + + boost::shared_ptr<Payload> getPayload() const { + return payloadParser->getPayload(); + } + + private: + XMLParser* xmlParser; + FullPayloadParserFactoryCollection factories; + std::auto_ptr<PayloadParser> payloadParser; + int level; + }; +} diff --git a/Swiften/Parser/PayloadParsers/UnitTest/PriorityParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/PriorityParserTest.cpp index a186ebd..acea437 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/PriorityParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/PriorityParserTest.cpp @@ -2,7 +2,7 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include "Swiften/Parser/PayloadParsers/PriorityParser.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h" +#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" using namespace Swift; @@ -16,12 +16,11 @@ class PriorityParserTest : public CppUnit::TestFixture PriorityParserTest() {} void testParse() { - PriorityParser testling; - PayloadParserTester parser(&testling); + PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse("<priority>-120</priority>")); - Priority* payload = dynamic_cast<Priority*>(testling.getPayload().get()); + Priority* payload = dynamic_cast<Priority*>(parser.getPayload().get()); CPPUNIT_ASSERT_EQUAL(-120, payload->getPriority()); } }; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/ResourceBindParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/ResourceBindParserTest.cpp index 67cb9cc..b1b61ef 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/ResourceBindParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/ResourceBindParserTest.cpp @@ -2,7 +2,7 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include "Swiften/Parser/PayloadParsers/ResourceBindParser.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h" +#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" using namespace Swift; @@ -17,22 +17,20 @@ class ResourceBindParserTest : public CppUnit::TestFixture ResourceBindParserTest() {} void testParse_JID() { - ResourceBindParser testling; - PayloadParserTester parser(&testling); + PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse("<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><jid>somenode@example.com/someresource</jid></bind>")); - ResourceBind* payload = dynamic_cast<ResourceBind*>(testling.getPayload().get()); + ResourceBind* payload = dynamic_cast<ResourceBind*>(parser.getPayload().get()); CPPUNIT_ASSERT_EQUAL(JID("somenode@example.com/someresource"), payload->getJID()); } void testParse_Resource() { - ResourceBindParser testling; - PayloadParserTester parser(&testling); + PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse("<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><resource>someresource</resource></bind>")); - ResourceBind* payload = dynamic_cast<ResourceBind*>(testling.getPayload().get()); + ResourceBind* payload = dynamic_cast<ResourceBind*>(parser.getPayload().get()); CPPUNIT_ASSERT_EQUAL(String("someresource"), payload->getResource()); } }; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/RosterParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/RosterParserTest.cpp index 7f0fc64..4c8db07 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/RosterParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/RosterParserTest.cpp @@ -2,7 +2,7 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include "Swiften/Parser/PayloadParsers/RosterParser.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/XMLPayloadParser.h" +#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" using namespace Swift; @@ -16,8 +16,7 @@ class RosterParserTest : public CppUnit::TestFixture RosterParserTest() {} void testParse() { - RosterParser testling; - XMLPayloadParser parser(&testling); + PayloadsParserTester parser; parser.parse( "<query xmlns='jabber:iq:roster'>" " <item jid='foo@bar.com' name='Foo @ Bar' subscription='from' ask='subscribe'>" @@ -27,7 +26,7 @@ class RosterParserTest : public CppUnit::TestFixture " <item jid='baz@blo.com' name='Baz'/>" "</query>"); - RosterPayload* payload = dynamic_cast<RosterPayload*>(testling.getPayload().get()); + RosterPayload* payload = dynamic_cast<RosterPayload*>(parser.getPayload().get()); const RosterPayload::RosterItemPayloads& items = payload->getItems(); CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items.size()); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelParserTest.cpp index 325309f..8272bee 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelParserTest.cpp @@ -2,7 +2,7 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include "Swiften/Parser/PayloadParsers/SecurityLabelParser.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h" +#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" using namespace Swift; @@ -16,8 +16,7 @@ class SecurityLabelParserTest : public CppUnit::TestFixture SecurityLabelParserTest() {} void testParse() { - SecurityLabelParser testling; - PayloadParserTester parser(&testling); + PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" @@ -33,7 +32,7 @@ class SecurityLabelParserTest : public CppUnit::TestFixture "</equivalentlabel>" "</securitylabel>")); - SecurityLabel* payload = dynamic_cast<SecurityLabel*>(testling.getPayload().get()); + SecurityLabel* payload = dynamic_cast<SecurityLabel*>(parser.getPayload().get()); CPPUNIT_ASSERT_EQUAL(String("SECRET"), payload->getDisplayMarking()); CPPUNIT_ASSERT_EQUAL(String("black"), payload->getForegroundColor()); CPPUNIT_ASSERT_EQUAL(String("red"), payload->getBackgroundColor()); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelsCatalogParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelsCatalogParserTest.cpp index 2f3f47a..b2378b6 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelsCatalogParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelsCatalogParserTest.cpp @@ -2,7 +2,7 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include "Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h" +#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" using namespace Swift; @@ -16,8 +16,7 @@ class SecurityLabelsCatalogParserTest : public CppUnit::TestFixture SecurityLabelsCatalogParserTest() {} void testParse() { - SecurityLabelsCatalogParser testling; - PayloadParserTester parser(&testling); + PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "<catalog desc=\"an example set of labels\" name=\"Default\" to=\"example.com\" xmlns=\"urn:xmpp:sec-label:catalog:0\">" @@ -31,7 +30,7 @@ class SecurityLabelsCatalogParserTest : public CppUnit::TestFixture "</securitylabel>" "</catalog>")); - SecurityLabelsCatalog* payload = dynamic_cast<SecurityLabelsCatalog*>(testling.getPayload().get()); + SecurityLabelsCatalog* payload = dynamic_cast<SecurityLabelsCatalog*>(parser.getPayload().get()); CPPUNIT_ASSERT_EQUAL(String("Default"), payload->getName()); CPPUNIT_ASSERT_EQUAL(String("an example set of labels"), payload->getDescription()); CPPUNIT_ASSERT_EQUAL(JID("example.com"), payload->getTo()); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/SoftwareVersionParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/SoftwareVersionParserTest.cpp index 0ff1d00..eeaa8d9 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/SoftwareVersionParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/SoftwareVersionParserTest.cpp @@ -2,7 +2,7 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include "Swiften/Parser/PayloadParsers/SoftwareVersionParser.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h" +#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" using namespace Swift; @@ -16,8 +16,7 @@ class SoftwareVersionParserTest : public CppUnit::TestFixture SoftwareVersionParserTest() {} void testParse() { - SoftwareVersionParser testling; - PayloadParserTester parser(&testling); + PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "<query xmlns=\"jabber:iq:version\">" @@ -26,7 +25,7 @@ class SoftwareVersionParserTest : public CppUnit::TestFixture "<os>Mac OS X</os>" "</query>")); - SoftwareVersion* payload = dynamic_cast<SoftwareVersion*>(testling.getPayload().get()); + SoftwareVersion* payload = dynamic_cast<SoftwareVersion*>(parser.getPayload().get()); CPPUNIT_ASSERT_EQUAL(String("myclient"), payload->getName()); CPPUNIT_ASSERT_EQUAL(String("1.0"), payload->getVersion()); CPPUNIT_ASSERT_EQUAL(String("Mac OS X"), payload->getOS()); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/StatusParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/StatusParserTest.cpp index f1fa7b1..71d5b0b 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/StatusParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/StatusParserTest.cpp @@ -2,7 +2,7 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include "Swiften/Parser/PayloadParsers/StatusParser.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h" +#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" using namespace Swift; @@ -16,12 +16,11 @@ class StatusParserTest : public CppUnit::TestFixture StatusParserTest() {} void testParse() { - StatusParser testling; - PayloadParserTester parser(&testling); + PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse("<status>foo<baz>bar</baz>fum</status>")); - Status* payload = dynamic_cast<Status*>(testling.getPayload().get()); + Status* payload = dynamic_cast<Status*>(parser.getPayload().get()); CPPUNIT_ASSERT_EQUAL(String("foobarfum"), payload->getText()); } }; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/StatusShowParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/StatusShowParserTest.cpp index d89fdc5..d45e98b 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/StatusShowParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/StatusShowParserTest.cpp @@ -2,7 +2,7 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include "Swiften/Parser/PayloadParsers/StatusShowParser.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h" +#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" using namespace Swift; @@ -20,52 +20,47 @@ class StatusShowParserTest : public CppUnit::TestFixture StatusShowParserTest() {} void testParse_Invalid() { - StatusShowParser testling; - PayloadParserTester parser(&testling); + PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse("<show>invalid</show>")); - StatusShow* payload = dynamic_cast<StatusShow*>(testling.getPayload().get()); + StatusShow* payload = dynamic_cast<StatusShow*>(parser.getPayload().get()); CPPUNIT_ASSERT(StatusShow::Online == payload->getType()); } void testParse_Away() { - StatusShowParser testling; - PayloadParserTester parser(&testling); + PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse("<show>away</show>")); - StatusShow* payload = dynamic_cast<StatusShow*>(testling.getPayload().get()); + StatusShow* payload = dynamic_cast<StatusShow*>(parser.getPayload().get()); CPPUNIT_ASSERT(StatusShow::Away == payload->getType()); } void testParse_FFC() { - StatusShowParser testling; - PayloadParserTester parser(&testling); + PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse("<show>chat</show>")); - StatusShow* payload = dynamic_cast<StatusShow*>(testling.getPayload().get()); + StatusShow* payload = dynamic_cast<StatusShow*>(parser.getPayload().get()); CPPUNIT_ASSERT(StatusShow::FFC == payload->getType()); } void testParse_XA() { - StatusShowParser testling; - PayloadParserTester parser(&testling); + PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse("<show>xa</show>")); - StatusShow* payload = dynamic_cast<StatusShow*>(testling.getPayload().get()); + StatusShow* payload = dynamic_cast<StatusShow*>(parser.getPayload().get()); CPPUNIT_ASSERT(StatusShow::XA == payload->getType()); } void testParse_DND() { - StatusShowParser testling; - PayloadParserTester parser(&testling); + PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse("<show>dnd</show>")); - StatusShow* payload = dynamic_cast<StatusShow*>(testling.getPayload().get()); + StatusShow* payload = dynamic_cast<StatusShow*>(parser.getPayload().get()); CPPUNIT_ASSERT(StatusShow::DND == payload->getType()); } }; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/StorageParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/StorageParserTest.cpp index fa188b7..384a0e9 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/StorageParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/StorageParserTest.cpp @@ -2,7 +2,7 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include "Swiften/Parser/PayloadParsers/StorageParser.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h" +#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" using namespace Swift; @@ -17,8 +17,7 @@ class StorageParserTest : public CppUnit::TestFixture StorageParserTest() {} void testParse_Conference() { - StorageParser testling; - PayloadParserTester parser(&testling); + PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "<storage xmlns='storage:bookmarks'>" @@ -30,7 +29,7 @@ class StorageParserTest : public CppUnit::TestFixture "</conference>" "</storage>")); - Storage* payload = dynamic_cast<Storage*>(testling.getPayload().get()); + Storage* payload = dynamic_cast<Storage*>(parser.getPayload().get()); std::vector<Storage::Conference> conferences = payload->getConferences(); CPPUNIT_ASSERT_EQUAL(1U, conferences.size()); CPPUNIT_ASSERT_EQUAL(String("Council of Oberon"), conferences[0].name); @@ -41,8 +40,7 @@ class StorageParserTest : public CppUnit::TestFixture } void testParse_MultipleConferences() { - StorageParser testling; - PayloadParserTester parser(&testling); + PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "<storage xmlns='storage:bookmarks'>" @@ -54,7 +52,7 @@ class StorageParserTest : public CppUnit::TestFixture "jid='teaparty@wonderland.lit' />" "</storage>")); - Storage* payload = dynamic_cast<Storage*>(testling.getPayload().get()); + Storage* payload = dynamic_cast<Storage*>(parser.getPayload().get()); std::vector<Storage::Conference> conferences = payload->getConferences(); CPPUNIT_ASSERT_EQUAL(2U, conferences.size()); CPPUNIT_ASSERT_EQUAL(String("Council of Oberon"), conferences[0].name); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp index bfae4f0..d1ddba3 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp @@ -2,7 +2,7 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include "Swiften/Parser/PayloadParsers/VCardParser.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h" +#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" using namespace Swift; @@ -17,8 +17,7 @@ class VCardParserTest : public CppUnit::TestFixture VCardParserTest() {} void testParse_Photo() { - VCardParser testling; - PayloadParserTester parser(&testling); + PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "<vCard xmlns='vcard-temp'>" @@ -31,21 +30,20 @@ class VCardParserTest : public CppUnit::TestFixture "</PHOTO>" "</vCard>")); - VCard* payload = dynamic_cast<VCard*>(testling.getPayload().get()); + VCard* payload = dynamic_cast<VCard*>(parser.getPayload().get()); CPPUNIT_ASSERT_EQUAL(String("image/jpeg"), payload->getPhotoType()); CPPUNIT_ASSERT_EQUAL(ByteArray("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"), payload->getPhoto()); } void testParse_Nickname() { - VCardParser testling; - PayloadParserTester parser(&testling); + PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "<vCard xmlns='vcard-temp'>" "<NICKNAME>mynick</NICKNAME>" "</vCard>")); - VCard* payload = dynamic_cast<VCard*>(testling.getPayload().get()); + VCard* payload = dynamic_cast<VCard*>(parser.getPayload().get()); CPPUNIT_ASSERT_EQUAL(String("mynick"), payload->getNickname()); } }; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/VCardUpdateParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/VCardUpdateParserTest.cpp index 0d9ae64..ef6c78e 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/VCardUpdateParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/VCardUpdateParserTest.cpp @@ -2,7 +2,7 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include "Swiften/Parser/PayloadParsers/VCardUpdateParser.h" -#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h" +#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" using namespace Swift; @@ -16,15 +16,14 @@ class VCardUpdateParserTest : public CppUnit::TestFixture VCardUpdateParserTest() {} void testParse() { - VCardUpdateParser testling; - PayloadParserTester parser(&testling); + PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "<x xmlns='vcard-temp:x:update'>" "<photo>sha1-hash-of-image</photo>" "</x>")); - VCardUpdate* payload = dynamic_cast<VCardUpdate*>(testling.getPayload().get()); + VCardUpdate* payload = dynamic_cast<VCardUpdate*>(parser.getPayload().get()); CPPUNIT_ASSERT_EQUAL(String("sha1-hash-of-image"), payload->getPhotoHash()); } }; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/XMLPayloadParser.h b/Swiften/Parser/PayloadParsers/UnitTest/XMLPayloadParser.h deleted file mode 100644 index 2b893c4..0000000 --- a/Swiften/Parser/PayloadParsers/UnitTest/XMLPayloadParser.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef SWIFTEN_XMLPayloadParser_H -#define SWIFTEN_XMLPayloadParser_H - -#include "Swiften/Parser/PayloadParser.h" -#include "Swiften/Parser/XMLParserClient.h" -#include "Swiften/Parser/XMLParser.h" -#include "Swiften/Parser/PlatformXMLParserFactory.h" - -namespace Swift { - class XMLPayloadParser : public XMLParserClient { - public: - XMLPayloadParser(PayloadParser* payloadParser) : - payloadParser_(payloadParser) { - xmlParser_ = PlatformXMLParserFactory().createXMLParser(this); - } - - ~XMLPayloadParser() { - delete xmlParser_; - } - - bool parse(const String& data) { - return xmlParser_->parse(data); - } - - virtual void handleStartElement(const String& element, const String& ns, const AttributeMap& attributes) { - payloadParser_->handleStartElement(element, ns, attributes); - } - - virtual void handleEndElement(const String& element, const String& ns) { - payloadParser_->handleEndElement(element, ns); - } - - virtual void handleCharacterData(const String& data) { - payloadParser_->handleCharacterData(data); - } - - private: - XMLParser* xmlParser_; - PayloadParser* payloadParser_; - }; -} -#endif |