From ba4292f83f92037fdd12b0f7413f628a4b2c7a22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Sat, 12 Sep 2009 08:38:23 +0200 Subject: Added more general PayloadsParserTester. This tester also tests whether the PayloadParserFactory works properly. 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 #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("foobarfum")); - Body* payload = dynamic_cast(testling.getPayload().get()); + Body* payload = dynamic_cast(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 #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( "" @@ -28,7 +27,7 @@ class DiscoInfoParserTest : public CppUnit::TestFixture "" "")); - DiscoInfo* payload = dynamic_cast(testling.getPayload().get()); + DiscoInfo* payload = dynamic_cast(parser.getPayload().get()); CPPUNIT_ASSERT_EQUAL(2, static_cast(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 #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( "" @@ -25,7 +24,7 @@ class ErrorParserTest : public CppUnit::TestFixture "boo" "")); - Error* payload = dynamic_cast(testling.getPayload().get()); + Error* payload = dynamic_cast(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 + +#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 getPayload() const { + return payloadParser->getPayload(); + } + + private: + XMLParser* xmlParser; + FullPayloadParserFactoryCollection factories; + std::auto_ptr 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 #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("-120")); - Priority* payload = dynamic_cast(testling.getPayload().get()); + Priority* payload = dynamic_cast(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 #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("somenode@example.com/someresource")); - ResourceBind* payload = dynamic_cast(testling.getPayload().get()); + ResourceBind* payload = dynamic_cast(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("someresource")); - ResourceBind* payload = dynamic_cast(testling.getPayload().get()); + ResourceBind* payload = dynamic_cast(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 #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( "" " " @@ -27,7 +26,7 @@ class RosterParserTest : public CppUnit::TestFixture " " ""); - RosterPayload* payload = dynamic_cast(testling.getPayload().get()); + RosterPayload* payload = dynamic_cast(parser.getPayload().get()); const RosterPayload::RosterItemPayloads& items = payload->getItems(); CPPUNIT_ASSERT_EQUAL(static_cast(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 #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( "" @@ -33,7 +32,7 @@ class SecurityLabelParserTest : public CppUnit::TestFixture "" "")); - SecurityLabel* payload = dynamic_cast(testling.getPayload().get()); + SecurityLabel* payload = dynamic_cast(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 #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( "" @@ -31,7 +30,7 @@ class SecurityLabelsCatalogParserTest : public CppUnit::TestFixture "" "")); - SecurityLabelsCatalog* payload = dynamic_cast(testling.getPayload().get()); + SecurityLabelsCatalog* payload = dynamic_cast(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 #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( "" @@ -26,7 +25,7 @@ class SoftwareVersionParserTest : public CppUnit::TestFixture "Mac OS X" "")); - SoftwareVersion* payload = dynamic_cast(testling.getPayload().get()); + SoftwareVersion* payload = dynamic_cast(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 #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("foobarfum")); - Status* payload = dynamic_cast(testling.getPayload().get()); + Status* payload = dynamic_cast(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 #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("invalid")); - StatusShow* payload = dynamic_cast(testling.getPayload().get()); + StatusShow* payload = dynamic_cast(parser.getPayload().get()); CPPUNIT_ASSERT(StatusShow::Online == payload->getType()); } void testParse_Away() { - StatusShowParser testling; - PayloadParserTester parser(&testling); + PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse("away")); - StatusShow* payload = dynamic_cast(testling.getPayload().get()); + StatusShow* payload = dynamic_cast(parser.getPayload().get()); CPPUNIT_ASSERT(StatusShow::Away == payload->getType()); } void testParse_FFC() { - StatusShowParser testling; - PayloadParserTester parser(&testling); + PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse("chat")); - StatusShow* payload = dynamic_cast(testling.getPayload().get()); + StatusShow* payload = dynamic_cast(parser.getPayload().get()); CPPUNIT_ASSERT(StatusShow::FFC == payload->getType()); } void testParse_XA() { - StatusShowParser testling; - PayloadParserTester parser(&testling); + PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse("xa")); - StatusShow* payload = dynamic_cast(testling.getPayload().get()); + StatusShow* payload = dynamic_cast(parser.getPayload().get()); CPPUNIT_ASSERT(StatusShow::XA == payload->getType()); } void testParse_DND() { - StatusShowParser testling; - PayloadParserTester parser(&testling); + PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse("dnd")); - StatusShow* payload = dynamic_cast(testling.getPayload().get()); + StatusShow* payload = dynamic_cast(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 #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( "" @@ -30,7 +29,7 @@ class StorageParserTest : public CppUnit::TestFixture "" "")); - Storage* payload = dynamic_cast(testling.getPayload().get()); + Storage* payload = dynamic_cast(parser.getPayload().get()); std::vector 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( "" @@ -54,7 +52,7 @@ class StorageParserTest : public CppUnit::TestFixture "jid='teaparty@wonderland.lit' />" "")); - Storage* payload = dynamic_cast(testling.getPayload().get()); + Storage* payload = dynamic_cast(parser.getPayload().get()); std::vector 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 #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( "" @@ -31,21 +30,20 @@ class VCardParserTest : public CppUnit::TestFixture "" "")); - VCard* payload = dynamic_cast(testling.getPayload().get()); + VCard* payload = dynamic_cast(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( "" "mynick" "")); - VCard* payload = dynamic_cast(testling.getPayload().get()); + VCard* payload = dynamic_cast(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 #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( "" "sha1-hash-of-image" "")); - VCardUpdate* payload = dynamic_cast(testling.getPayload().get()); + VCardUpdate* payload = dynamic_cast(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 -- cgit v0.10.2-6-g49f6