/* * Copyright (c) 2010 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include #include #include #include #include #include #include namespace Swift { class PayloadsParserTester : public XMLParserClient { public: PayloadsParserTester() : level(0) { xmlParser = PlatformXMLParserFactory().createXMLParser(this); } ~PayloadsParserTester() { delete xmlParser; } bool parse(const std::string& data) { return xmlParser->parse(data); } virtual void handleStartElement(const std::string& element, const std::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 std::string& element, const std::string& ns) { level--; payloadParser->handleEndElement(element, ns); } virtual void handleCharacterData(const std::string& data) { payloadParser->handleCharacterData(data); } boost::shared_ptr getPayload() const { return payloadParser->getPayload(); } template boost::shared_ptr getPayload() const { return boost::dynamic_pointer_cast(payloadParser->getPayload()); } private: XMLParser* xmlParser; FullPayloadParserFactoryCollection factories; boost::shared_ptr payloadParser; int level; }; }