summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2009-07-31 18:38:11 (GMT)
committerKevin Smith <git@kismith.co.uk>2009-07-31 18:38:11 (GMT)
commit99b65c4dd72105755a7cf95297c9cf69dcbc6446 (patch)
treec6c862f6ef33b2260c44c0229b29f65351223e7c /Swiften/Parser
parentfed11bbc3bffd383e097ea63bb92442ce2daf6ed (diff)
parentaa60aa80d2d170a536c246ef6c221f92de7dd8ed (diff)
downloadswift-99b65c4dd72105755a7cf95297c9cf69dcbc6446.zip
swift-99b65c4dd72105755a7cf95297c9cf69dcbc6446.tar.bz2
Merge commit 'origin/master' into roster
Diffstat (limited to 'Swiften/Parser')
-rw-r--r--Swiften/Parser/ExpatParser.cpp4
-rw-r--r--Swiften/Parser/UnitTest/XMLParserTest.cpp74
2 files changed, 60 insertions, 18 deletions
diff --git a/Swiften/Parser/ExpatParser.cpp b/Swiften/Parser/ExpatParser.cpp
index 6d23c93..6f7ff86 100644
--- a/Swiften/Parser/ExpatParser.cpp
+++ b/Swiften/Parser/ExpatParser.cpp
@@ -32,6 +32,10 @@ static void handleStartElement(void* client, const XML_Char* name, const XML_Cha
static void handleEndElement(void* client, const XML_Char* name) {
std::pair<String,String> nsTagPair = String(name).getSplittedAtFirst(NAMESPACE_SEPARATOR);
+ if (nsTagPair.second == "") {
+ nsTagPair.second = nsTagPair.first;
+ nsTagPair.first = "";
+ }
static_cast<XMLParserClient*>(client)->handleEndElement(nsTagPair.second, nsTagPair.first);
}
diff --git a/Swiften/Parser/UnitTest/XMLParserTest.cpp b/Swiften/Parser/UnitTest/XMLParserTest.cpp
index a26b31b..6a42d0d 100644
--- a/Swiften/Parser/UnitTest/XMLParserTest.cpp
+++ b/Swiften/Parser/UnitTest/XMLParserTest.cpp
@@ -2,7 +2,7 @@
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <vector>
-#ifdef HAVE_CONFIG_H
+#ifdef HAVE_SWIFTEN_CONFIG_H
#include "Swiften/config.h"
#endif
#include "Swiften/Base/String.h"
@@ -17,10 +17,10 @@
using namespace Swift;
template <typename ParserType>
-class XMLParserTest : public CppUnit::TestFixture
-{
+class XMLParserTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(XMLParserTest);
CPPUNIT_TEST(testParse_NestedElements);
+ CPPUNIT_TEST(testParse_ElementInNamespacedElement);
CPPUNIT_TEST(testParse_CharacterData);
CPPUNIT_TEST(testParse_NamespacePrefix);
CPPUNIT_TEST(testParse_UnhandledXML);
@@ -30,8 +30,6 @@ class XMLParserTest : public CppUnit::TestFixture
CPPUNIT_TEST_SUITE_END();
public:
- XMLParserTest() {}
-
void testParse_NestedElements() {
ParserType testling(&client_);
@@ -46,17 +44,51 @@ class XMLParserTest : public CppUnit::TestFixture
CPPUNIT_ASSERT_EQUAL(String("iq"), client_.events[0].data);
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].attributes.size());
CPPUNIT_ASSERT_EQUAL(String("get"), client_.events[0].attributes["type"]);
+ CPPUNIT_ASSERT_EQUAL(String(), client_.events[0].ns);
CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[1].type);
CPPUNIT_ASSERT_EQUAL(String("query"), client_.events[1].data);
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[1].attributes.size());
- CPPUNIT_ASSERT_EQUAL(String("jabber:iq:version"), client_.events[1].attributes["xmlns"]);
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), client_.events[1].attributes.size());
+ CPPUNIT_ASSERT_EQUAL(String("jabber:iq:version"), client_.events[1].ns);
CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[2].type);
CPPUNIT_ASSERT_EQUAL(String("query"), client_.events[2].data);
+ CPPUNIT_ASSERT_EQUAL(String("jabber:iq:version"), client_.events[2].ns);
CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[3].type);
CPPUNIT_ASSERT_EQUAL(String("iq"), client_.events[3].data);
+ CPPUNIT_ASSERT_EQUAL(String(), client_.events[3].ns);
+ }
+
+ void testParse_ElementInNamespacedElement() {
+ ParserType testling(&client_);
+
+ CPPUNIT_ASSERT(testling.parse(
+ "<query xmlns='jabber:iq:version'>"
+ "<name>Swift</name>"
+ "</query>"));
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(5), client_.events.size());
+
+ CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type);
+ CPPUNIT_ASSERT_EQUAL(String("query"), client_.events[0].data);
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), client_.events[0].attributes.size());
+ CPPUNIT_ASSERT_EQUAL(String("jabber:iq:version"), client_.events[0].ns);
+
+ CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[1].type);
+ CPPUNIT_ASSERT_EQUAL(String("name"), client_.events[1].data);
+ CPPUNIT_ASSERT_EQUAL(String("jabber:iq:version"), client_.events[1].ns);
+
+ CPPUNIT_ASSERT_EQUAL(Client::CharacterData, client_.events[2].type);
+ CPPUNIT_ASSERT_EQUAL(String("Swift"), client_.events[2].data);
+
+ CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[3].type);
+ CPPUNIT_ASSERT_EQUAL(String("name"), client_.events[3].data);
+ CPPUNIT_ASSERT_EQUAL(String("jabber:iq:version"), client_.events[3].ns);
+
+ CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[4].type);
+ CPPUNIT_ASSERT_EQUAL(String("query"), client_.events[4].data);
+ CPPUNIT_ASSERT_EQUAL(String("jabber:iq:version"), client_.events[4].ns);
}
void testParse_CharacterData() {
@@ -96,16 +128,20 @@ class XMLParserTest : public CppUnit::TestFixture
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), client_.events.size());
CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type);
- CPPUNIT_ASSERT_EQUAL(String("p:x"), client_.events[0].data);
+ CPPUNIT_ASSERT_EQUAL(String("x"), client_.events[0].data);
+ CPPUNIT_ASSERT_EQUAL(String("bla"), client_.events[0].ns);
CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[1].type);
- CPPUNIT_ASSERT_EQUAL(String("p:y"), client_.events[1].data);
+ CPPUNIT_ASSERT_EQUAL(String("y"), client_.events[1].data);
+ CPPUNIT_ASSERT_EQUAL(String("bla"), client_.events[1].ns);
CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[2].type);
- CPPUNIT_ASSERT_EQUAL(String("p:y"), client_.events[2].data);
+ CPPUNIT_ASSERT_EQUAL(String("y"), client_.events[2].data);
+ CPPUNIT_ASSERT_EQUAL(String("bla"), client_.events[2].ns);
CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[3].type);
- CPPUNIT_ASSERT_EQUAL(String("p:x"), client_.events[3].data);
+ CPPUNIT_ASSERT_EQUAL(String("x"), client_.events[3].data);
+ CPPUNIT_ASSERT_EQUAL(String("bla"), client_.events[3].ns);
}
void testParse_UnhandledXML() {
@@ -158,24 +194,26 @@ class XMLParserTest : public CppUnit::TestFixture
Event(
Type type,
const String& data,
+ const String& ns,
const AttributeMap& attributes)
- : type(type), data(data), attributes(attributes) {}
- Event(Type type, const String& data)
- : type(type), data(data) {}
+ : type(type), data(data), ns(ns), attributes(attributes) {}
+ Event(Type type, const String& data, const String& ns = String())
+ : type(type), data(data), ns(ns) {}
Type type;
String data;
+ String ns;
AttributeMap attributes;
};
Client() {}
- virtual void handleStartElement(const String& element, const AttributeMap& attributes) {
- events.push_back(Event(StartElement, element, attributes));
+ virtual void handleStartElement(const String& element, const String& ns, const AttributeMap& attributes) {
+ events.push_back(Event(StartElement, element, ns, attributes));
}
- virtual void handleEndElement(const String& element) {
- events.push_back(Event(EndElement, element));
+ virtual void handleEndElement(const String& element, const String& ns) {
+ events.push_back(Event(EndElement, element, ns));
}
virtual void handleCharacterData(const String& data) {