diff options
Diffstat (limited to 'Swiften/Parser/UnitTest/XMLParserTest.cpp')
-rw-r--r-- | Swiften/Parser/UnitTest/XMLParserTest.cpp | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/Swiften/Parser/UnitTest/XMLParserTest.cpp b/Swiften/Parser/UnitTest/XMLParserTest.cpp index 9e9012b..c026b4b 100644 --- a/Swiften/Parser/UnitTest/XMLParserTest.cpp +++ b/Swiften/Parser/UnitTest/XMLParserTest.cpp @@ -8,2 +8,3 @@ #include <cppunit/extensions/TestFactoryRegistry.h> +#include <unordered_map> #include <vector> @@ -63,2 +64,5 @@ class XMLParserTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[1].ns); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[1].namespaces.size()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[1].namespaces.count("")); + CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[1].namespaces[""]); @@ -87,2 +91,4 @@ class XMLParserTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[0].ns); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].namespaces.size()); + CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[0].namespaces[""]); @@ -91,2 +97,3 @@ class XMLParserTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[1].ns); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), client_.events[1].namespaces.size()); @@ -163,2 +170,4 @@ class XMLParserTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[0].ns); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].namespaces.size()); + CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[0].namespaces["p"]); @@ -264,2 +273,5 @@ class XMLParserTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(std::string("http://swift.im/f"), client_.events[0].attributes.getEntries()[0].getAttribute().getNamespace()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), client_.events[0].namespaces.size()); + CPPUNIT_ASSERT_EQUAL(std::string("http://swift.im"), client_.events[0].namespaces[""]); + CPPUNIT_ASSERT_EQUAL(std::string("http://swift.im/f"), client_.events[0].namespaces["f"]); } @@ -303,2 +315,3 @@ class XMLParserTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(std::string(""), client_.events[0].ns); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), client_.events[0].namespaces.size()); @@ -330,3 +343,4 @@ class XMLParserTest : public CppUnit::TestFixture { public: - enum Type { StartElement, EndElement, CharacterData }; + using NamespaceMap = std::unordered_map<std::string /* prefix */, std::string /* uri */>; + enum Type { StartElement, EndElement, CharacterData, NamespaceDefined }; struct Event { @@ -336,4 +350,5 @@ class XMLParserTest : public CppUnit::TestFixture { const std::string& ns, - const AttributeMap& attributes) - : type(type), data(data), ns(ns), attributes(attributes) {} + const AttributeMap& attributes, + NamespaceMap namespaces = {}) + : type(type), data(data), ns(ns), attributes(attributes), namespaces(std::move(namespaces)) {} Event(Type type, const std::string& data, const std::string& ns = std::string()) @@ -345,2 +360,3 @@ class XMLParserTest : public CppUnit::TestFixture { AttributeMap attributes; + NamespaceMap namespaces; }; @@ -349,7 +365,7 @@ class XMLParserTest : public CppUnit::TestFixture { - virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - events.push_back(Event(StartElement, element, ns, attributes)); + void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) override { + events.push_back(Event(StartElement, element, ns, attributes, std::move(namespaces_))); } - virtual void handleEndElement(const std::string& element, const std::string& ns) { + void handleEndElement(const std::string& element, const std::string& ns) override { events.push_back(Event(EndElement, element, ns)); @@ -357,3 +373,3 @@ class XMLParserTest : public CppUnit::TestFixture { - virtual void handleCharacterData(const std::string& data) { + void handleCharacterData(const std::string& data) override { events.push_back(Event(CharacterData, data)); @@ -361,3 +377,8 @@ class XMLParserTest : public CppUnit::TestFixture { + void handleNamespaceDeclaration(const std::string& prefix, const std::string& uri) override { + namespaces_[prefix] = uri; + } std::vector<Event> events; + private: + NamespaceMap namespaces_; } client_; |