summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Parser/UnitTest')
-rw-r--r--Swiften/Parser/UnitTest/AttributeMapTest.cpp22
-rw-r--r--Swiften/Parser/UnitTest/BOSHBodyExtractorTest.cpp104
-rw-r--r--Swiften/Parser/UnitTest/ElementParserTester.h8
-rw-r--r--Swiften/Parser/UnitTest/GenericPayloadTreeParserTest.cpp58
-rw-r--r--Swiften/Parser/UnitTest/IQParserTest.cpp6
-rw-r--r--Swiften/Parser/UnitTest/MessageParserTest.cpp6
-rw-r--r--Swiften/Parser/UnitTest/ParserTester.h12
-rw-r--r--Swiften/Parser/UnitTest/PayloadParserFactoryCollectionTest.cpp4
-rw-r--r--Swiften/Parser/UnitTest/PresenceParserTest.cpp6
-rw-r--r--Swiften/Parser/UnitTest/SerializingParserTest.cpp4
-rw-r--r--Swiften/Parser/UnitTest/StanzaAckParserTest.cpp6
-rw-r--r--Swiften/Parser/UnitTest/StanzaParserTest.cpp22
-rw-r--r--Swiften/Parser/UnitTest/StanzaParserTester.h9
-rw-r--r--Swiften/Parser/UnitTest/StreamFeaturesParserTest.cpp6
-rw-r--r--Swiften/Parser/UnitTest/StreamManagementEnabledParserTest.cpp34
-rw-r--r--Swiften/Parser/UnitTest/XMLParserTest.cpp39
-rw-r--r--Swiften/Parser/UnitTest/XMPPParserTest.cpp20
17 files changed, 294 insertions, 72 deletions
diff --git a/Swiften/Parser/UnitTest/AttributeMapTest.cpp b/Swiften/Parser/UnitTest/AttributeMapTest.cpp
index fb68f29..d6c3c01 100644
--- a/Swiften/Parser/UnitTest/AttributeMapTest.cpp
+++ b/Swiften/Parser/UnitTest/AttributeMapTest.cpp
@@ -7,13 +7,14 @@
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
-#include "Swiften/Parser/AttributeMap.h"
+#include <Swiften/Parser/AttributeMap.h>
using namespace Swift;
class AttributeMapTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(AttributeMapTest);
+ CPPUNIT_TEST(testGetAttribute_Namespaced);
CPPUNIT_TEST(testGetBoolAttribute_True);
CPPUNIT_TEST(testGetBoolAttribute_1);
CPPUNIT_TEST(testGetBoolAttribute_False);
@@ -24,39 +25,46 @@ class AttributeMapTest : public CppUnit::TestFixture
CPPUNIT_TEST_SUITE_END();
public:
- AttributeMapTest() {}
+ void testGetAttribute_Namespaced() {
+ AttributeMap testling;
+ testling.addAttribute("lang", "", "nl");
+ testling.addAttribute("lang", "http://www.w3.org/XML/1998/namespace", "en");
+ testling.addAttribute("lang", "", "fr");
+
+ CPPUNIT_ASSERT_EQUAL(std::string("en"), testling.getAttribute("lang", "http://www.w3.org/XML/1998/namespace"));
+ }
void testGetBoolAttribute_True() {
AttributeMap testling;
- testling["foo"] = "true";
+ testling.addAttribute("foo", "", "true");
CPPUNIT_ASSERT(testling.getBoolAttribute("foo"));
}
void testGetBoolAttribute_1() {
AttributeMap testling;
- testling["foo"] = "1";
+ testling.addAttribute("foo", "", "1");
CPPUNIT_ASSERT(testling.getBoolAttribute("foo"));
}
void testGetBoolAttribute_False() {
AttributeMap testling;
- testling["foo"] = "false";
+ testling.addAttribute("foo", "", "false");
CPPUNIT_ASSERT(!testling.getBoolAttribute("foo", true));
}
void testGetBoolAttribute_0() {
AttributeMap testling;
- testling["foo"] = "0";
+ testling.addAttribute("foo", "", "0");
CPPUNIT_ASSERT(!testling.getBoolAttribute("foo", true));
}
void testGetBoolAttribute_Invalid() {
AttributeMap testling;
- testling["foo"] = "bla";
+ testling.addAttribute("foo", "", "bla");
CPPUNIT_ASSERT(!testling.getBoolAttribute("foo", true));
}
diff --git a/Swiften/Parser/UnitTest/BOSHBodyExtractorTest.cpp b/Swiften/Parser/UnitTest/BOSHBodyExtractorTest.cpp
new file mode 100644
index 0000000..fc7d17b
--- /dev/null
+++ b/Swiften/Parser/UnitTest/BOSHBodyExtractorTest.cpp
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2011 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <Swiften/Parser/PlatformXMLParserFactory.h>
+#include <Swiften/Parser/BOSHBodyExtractor.h>
+
+using namespace Swift;
+
+class BOSHBodyExtractorTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(BOSHBodyExtractorTest);
+ CPPUNIT_TEST(testGetBody);
+ CPPUNIT_TEST(testGetBody_EmptyContent);
+ CPPUNIT_TEST(testGetBody_EmptyContent2);
+ CPPUNIT_TEST(testGetBody_EmptyElementEmptyContent);
+ CPPUNIT_TEST(testGetBody_InvalidStartTag);
+ CPPUNIT_TEST(testGetBody_InvalidStartTag2);
+ CPPUNIT_TEST(testGetBody_IncompleteStartTag);
+ CPPUNIT_TEST(testGetBody_InvalidEndTag);
+ CPPUNIT_TEST(testGetBody_InvalidEndTag2);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testGetBody() {
+ BOSHBodyExtractor testling(&parserFactory, createByteArray(
+ "<body a1='a\"1' a2=\"a'2\" boo='bar' >"
+ "foo <message> <body> bar"
+ "</body > "));
+
+ CPPUNIT_ASSERT(testling.getBody());
+ CPPUNIT_ASSERT_EQUAL(std::string("a\"1"), testling.getBody()->attributes.getAttribute("a1"));
+ CPPUNIT_ASSERT_EQUAL(std::string("foo <message> <body> bar"), testling.getBody()->content);
+ }
+
+ void testGetBody_EmptyContent() {
+ BOSHBodyExtractor testling(&parserFactory, createByteArray(
+ "<body foo='bar'/>"));
+
+ CPPUNIT_ASSERT(testling.getBody());
+ CPPUNIT_ASSERT_EQUAL(std::string("bar"), testling.getBody()->attributes.getAttribute("foo"));
+ CPPUNIT_ASSERT(testling.getBody()->content.empty());
+ }
+
+ void testGetBody_EmptyContent2() {
+ BOSHBodyExtractor testling(&parserFactory, createByteArray(
+ "<body foo='bar'></body>"));
+
+ CPPUNIT_ASSERT(testling.getBody());
+ CPPUNIT_ASSERT_EQUAL(std::string("bar"), testling.getBody()->attributes.getAttribute("foo"));
+ CPPUNIT_ASSERT(testling.getBody()->content.empty());
+ }
+
+ void testGetBody_EmptyElementEmptyContent() {
+ BOSHBodyExtractor testling(&parserFactory, createByteArray(
+ "<body/>"));
+
+ CPPUNIT_ASSERT(testling.getBody());
+ }
+
+ void testGetBody_InvalidStartTag() {
+ BOSHBodyExtractor testling(&parserFactory, createByteArray(
+ "<bodi></body>"));
+
+ CPPUNIT_ASSERT(!testling.getBody());
+ }
+
+ void testGetBody_InvalidStartTag2() {
+ BOSHBodyExtractor testling(&parserFactory, createByteArray(
+ "<bodyy></body>"));
+
+ CPPUNIT_ASSERT(!testling.getBody());
+ }
+
+ void testGetBody_IncompleteStartTag() {
+ BOSHBodyExtractor testling(&parserFactory, createByteArray(
+ "<body"));
+
+ CPPUNIT_ASSERT(!testling.getBody());
+ }
+
+ void testGetBody_InvalidEndTag() {
+ BOSHBodyExtractor testling(&parserFactory, createByteArray(
+ "<body></bodi>"));
+
+ CPPUNIT_ASSERT(!testling.getBody());
+ }
+
+ void testGetBody_InvalidEndTag2() {
+ BOSHBodyExtractor testling(&parserFactory, createByteArray(
+ "<body><b/body>"));
+
+ CPPUNIT_ASSERT(!testling.getBody());
+ }
+
+ private:
+ PlatformXMLParserFactory parserFactory;
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(BOSHBodyExtractorTest);
diff --git a/Swiften/Parser/UnitTest/ElementParserTester.h b/Swiften/Parser/UnitTest/ElementParserTester.h
index ba39eb7..76b8870 100644
--- a/Swiften/Parser/UnitTest/ElementParserTester.h
+++ b/Swiften/Parser/UnitTest/ElementParserTester.h
@@ -4,13 +4,11 @@
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#ifndef SWIFTEN_ElementParserTester_H
-#define SWIFTEN_ElementParserTester_H
+#pragma once
-#include "Swiften/Parser/UnitTest/ParserTester.h"
+
+#include <Swiften/Parser/UnitTest/ParserTester.h>
namespace Swift {
typedef ParserTester<ElementParser> ElementParserTester;
}
-
-#endif
diff --git a/Swiften/Parser/UnitTest/GenericPayloadTreeParserTest.cpp b/Swiften/Parser/UnitTest/GenericPayloadTreeParserTest.cpp
new file mode 100644
index 0000000..d095afc
--- /dev/null
+++ b/Swiften/Parser/UnitTest/GenericPayloadTreeParserTest.cpp
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2011 Kevin Smith
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <Swiften/Parser/GenericPayloadTreeParser.h>
+#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h>
+#include <Swiften/Elements/RawXMLPayload.h>
+
+using namespace Swift;
+
+class GenericPayloadTreeParserTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(GenericPayloadTreeParserTest);
+ CPPUNIT_TEST(testTree);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testTree() {
+ MyParser testling;
+
+ std::string data = "<topLevel xmlns='urn:test:top'><firstLevelInheritedEmpty/><firstLevelInherited><secondLevelMultiChildren num='1'/><secondLevelMultiChildren num='2'/></firstLevelInherited><firstLevelNS xmlns='urn:test:first'/></topLevel>";
+
+ PayloadParserTester tester(&testling);
+ tester.parse(data);
+
+ ParserElement::ref tree = testling.tree;
+
+ CPPUNIT_ASSERT_EQUAL(std::string("topLevel"), tree->getName());
+ CPPUNIT_ASSERT_EQUAL(std::string("urn:test:top"), tree->getNamespace());
+ CPPUNIT_ASSERT(tree->getChild("firstLevelInheritedEmpty", "urn:test:top"));
+ CPPUNIT_ASSERT(!*tree->getChild("firstLevelInheritedEmpty", ""));
+ CPPUNIT_ASSERT(tree->getChild("firstLevelInherited", "urn:test:top"));
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), tree->getChild("firstLevelInherited", "urn:test:top")->getChildren("secondLevelMultiChildren", "urn:test:top").size());
+ CPPUNIT_ASSERT_EQUAL(std::string("1"), tree->getChild("firstLevelInherited", "urn:test:top")->getChildren("secondLevelMultiChildren", "urn:test:top")[0]->getAttributes().getAttribute("num"));
+ CPPUNIT_ASSERT_EQUAL(std::string("2"), tree->getChild("firstLevelInherited", "urn:test:top")->getChildren("secondLevelMultiChildren", "urn:test:top")[1]->getAttributes().getAttribute("num"));
+ CPPUNIT_ASSERT(tree->getChild("firstLevelNS", "urn:test:first"));
+ }
+
+ private:
+
+
+ class MyParser : public GenericPayloadTreeParser<RawXMLPayload>
+ {
+ public:
+ virtual ~MyParser() {}
+ virtual void handleTree(ParserElement::ref root) {
+ tree = root;
+ }
+ ParserElement::ref tree;
+ };
+
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(GenericPayloadTreeParserTest);
diff --git a/Swiften/Parser/UnitTest/IQParserTest.cpp b/Swiften/Parser/UnitTest/IQParserTest.cpp
index 3cc7d45..3c86a5d 100644
--- a/Swiften/Parser/UnitTest/IQParserTest.cpp
+++ b/Swiften/Parser/UnitTest/IQParserTest.cpp
@@ -7,9 +7,9 @@
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
-#include "Swiften/Parser/IQParser.h"
-#include "Swiften/Parser/PayloadParserFactoryCollection.h"
-#include "Swiften/Parser/UnitTest/StanzaParserTester.h"
+#include <Swiften/Parser/IQParser.h>
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/UnitTest/StanzaParserTester.h>
using namespace Swift;
diff --git a/Swiften/Parser/UnitTest/MessageParserTest.cpp b/Swiften/Parser/UnitTest/MessageParserTest.cpp
index 7615fa3..8ab59ed 100644
--- a/Swiften/Parser/UnitTest/MessageParserTest.cpp
+++ b/Swiften/Parser/UnitTest/MessageParserTest.cpp
@@ -7,9 +7,9 @@
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
-#include "Swiften/Parser/MessageParser.h"
-#include "Swiften/Parser/PayloadParserFactoryCollection.h"
-#include "Swiften/Parser/UnitTest/StanzaParserTester.h"
+#include <Swiften/Parser/MessageParser.h>
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/UnitTest/StanzaParserTester.h>
using namespace Swift;
diff --git a/Swiften/Parser/UnitTest/ParserTester.h b/Swiften/Parser/UnitTest/ParserTester.h
index 970c1be..73f013c 100644
--- a/Swiften/Parser/UnitTest/ParserTester.h
+++ b/Swiften/Parser/UnitTest/ParserTester.h
@@ -4,12 +4,12 @@
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#ifndef SWIFTEN_ParserTester_H
-#define SWIFTEN_ParserTester_H
+#pragma once
-#include "Swiften/Parser/XMLParserClient.h"
-#include "Swiften/Parser/PlatformXMLParserFactory.h"
-#include "Swiften/Parser/XMLParser.h"
+
+#include <Swiften/Parser/XMLParserClient.h>
+#include <Swiften/Parser/PlatformXMLParserFactory.h>
+#include <Swiften/Parser/XMLParser.h>
namespace Swift {
class XMLParser;
@@ -46,5 +46,3 @@ namespace Swift {
ParserType* parser_;
};
}
-
-#endif
diff --git a/Swiften/Parser/UnitTest/PayloadParserFactoryCollectionTest.cpp b/Swiften/Parser/UnitTest/PayloadParserFactoryCollectionTest.cpp
index 8e49764..fea64e2 100644
--- a/Swiften/Parser/UnitTest/PayloadParserFactoryCollectionTest.cpp
+++ b/Swiften/Parser/UnitTest/PayloadParserFactoryCollectionTest.cpp
@@ -7,8 +7,8 @@
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
-#include "Swiften/Parser/PayloadParserFactoryCollection.h"
-#include "Swiften/Parser/PayloadParserFactory.h"
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
using namespace Swift;
diff --git a/Swiften/Parser/UnitTest/PresenceParserTest.cpp b/Swiften/Parser/UnitTest/PresenceParserTest.cpp
index f68db40..f9d6cf6 100644
--- a/Swiften/Parser/UnitTest/PresenceParserTest.cpp
+++ b/Swiften/Parser/UnitTest/PresenceParserTest.cpp
@@ -7,9 +7,9 @@
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
-#include "Swiften/Parser/PresenceParser.h"
-#include "Swiften/Parser/PayloadParserFactoryCollection.h"
-#include "Swiften/Parser/UnitTest/StanzaParserTester.h"
+#include <Swiften/Parser/PresenceParser.h>
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/UnitTest/StanzaParserTester.h>
using namespace Swift;
diff --git a/Swiften/Parser/UnitTest/SerializingParserTest.cpp b/Swiften/Parser/UnitTest/SerializingParserTest.cpp
index c0af493..aef1dfb 100644
--- a/Swiften/Parser/UnitTest/SerializingParserTest.cpp
+++ b/Swiften/Parser/UnitTest/SerializingParserTest.cpp
@@ -7,8 +7,8 @@
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
-#include "Swiften/Parser/SerializingParser.h"
-#include "Swiften/Parser/UnitTest/StanzaParserTester.h"
+#include <Swiften/Parser/SerializingParser.h>
+#include <Swiften/Parser/UnitTest/StanzaParserTester.h>
using namespace Swift;
diff --git a/Swiften/Parser/UnitTest/StanzaAckParserTest.cpp b/Swiften/Parser/UnitTest/StanzaAckParserTest.cpp
index b90af6e..b68fb30 100644
--- a/Swiften/Parser/UnitTest/StanzaAckParserTest.cpp
+++ b/Swiften/Parser/UnitTest/StanzaAckParserTest.cpp
@@ -7,9 +7,9 @@
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
-#include "Swiften/Parser/StanzaAckParser.h"
-#include "Swiften/Parser/PayloadParserFactoryCollection.h"
-#include "Swiften/Parser/UnitTest/ElementParserTester.h"
+#include <Swiften/Parser/StanzaAckParser.h>
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/UnitTest/ElementParserTester.h>
using namespace Swift;
diff --git a/Swiften/Parser/UnitTest/StanzaParserTest.cpp b/Swiften/Parser/UnitTest/StanzaParserTest.cpp
index d57f798..b2ddb39 100644
--- a/Swiften/Parser/UnitTest/StanzaParserTest.cpp
+++ b/Swiften/Parser/UnitTest/StanzaParserTest.cpp
@@ -7,12 +7,12 @@
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
-#include "Swiften/Parser/StanzaParser.h"
-#include "Swiften/Parser/GenericPayloadParser.h"
-#include "Swiften/Parser/PayloadParserFactory.h"
-#include "Swiften/Parser/PayloadParserFactoryCollection.h"
-#include "Swiften/Elements/Stanza.h"
-#include "Swiften/Elements/Payload.h"
+#include <Swiften/Parser/StanzaParser.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Elements/Stanza.h>
+#include <Swiften/Elements/Payload.h>
using namespace Swift;
@@ -40,8 +40,8 @@ class StanzaParserTest : public CppUnit::TestFixture {
MyStanzaParser testling(factoryCollection_);
AttributeMap attributes;
- attributes["foo"] = "fum";
- attributes["bar"] = "baz";
+ attributes.addAttribute("foo", "", "fum");
+ attributes.addAttribute("bar", "", "baz");
testling.handleStartElement("mystanza", "", attributes);
testling.handleStartElement("mypayload1", "", attributes);
testling.handleStartElement("child", "", attributes);
@@ -107,9 +107,9 @@ class StanzaParserTest : public CppUnit::TestFixture {
MyStanzaParser testling(factoryCollection_);
AttributeMap attributes;
- attributes["to"] = "foo@example.com/blo";
- attributes["from"] = "bar@example.com/baz";
- attributes["id"] = "id-123";
+ attributes.addAttribute("to", "", "foo@example.com/blo");
+ attributes.addAttribute("from", "", "bar@example.com/baz");
+ attributes.addAttribute("id", "", "id-123");
testling.handleStartElement("mystanza", "", attributes);
testling.handleEndElement("mypayload1", "");
diff --git a/Swiften/Parser/UnitTest/StanzaParserTester.h b/Swiften/Parser/UnitTest/StanzaParserTester.h
index eb3a18b..e4ce48e 100644
--- a/Swiften/Parser/UnitTest/StanzaParserTester.h
+++ b/Swiften/Parser/UnitTest/StanzaParserTester.h
@@ -4,14 +4,11 @@
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#ifndef SWIFTEN_StanzaParserTester_H
-#define SWIFTEN_StanzaParserTester_H
+#pragma once
-#include "Swiften/Parser/StanzaParser.h"
-#include "Swiften/Parser/UnitTest/ParserTester.h"
+#include <Swiften/Parser/StanzaParser.h>
+#include <Swiften/Parser/UnitTest/ParserTester.h>
namespace Swift {
typedef ParserTester<StanzaParser> StanzaParserTester;
}
-
-#endif
diff --git a/Swiften/Parser/UnitTest/StreamFeaturesParserTest.cpp b/Swiften/Parser/UnitTest/StreamFeaturesParserTest.cpp
index 1cdaf54..4bc971f 100644
--- a/Swiften/Parser/UnitTest/StreamFeaturesParserTest.cpp
+++ b/Swiften/Parser/UnitTest/StreamFeaturesParserTest.cpp
@@ -7,8 +7,8 @@
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
-#include "Swiften/Parser/StreamFeaturesParser.h"
-#include "Swiften/Parser/UnitTest/ElementParserTester.h"
+#include <Swiften/Parser/StreamFeaturesParser.h>
+#include <Swiften/Parser/UnitTest/ElementParserTester.h>
using namespace Swift;
@@ -37,6 +37,7 @@ class StreamFeaturesParserTest : public CppUnit::TestFixture {
"<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\"/>"
"<sm xmlns='urn:xmpp:sm:2'/>"
"<session xmlns=\"urn:ietf:params:xml:ns:xmpp-session\"/>"
+ "<ver xmlns=\"urn:xmpp:features:rosterver\"/>"
"</stream:features>"));
StreamFeatures::ref element = boost::dynamic_pointer_cast<StreamFeatures>(testling.getElement());
@@ -49,6 +50,7 @@ class StreamFeaturesParserTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT(element->hasAuthenticationMechanism("DIGEST-MD5"));
CPPUNIT_ASSERT(element->hasAuthenticationMechanism("PLAIN"));
CPPUNIT_ASSERT(element->hasStreamManagement());
+ CPPUNIT_ASSERT(element->hasRosterVersioning());
}
void testParse_Empty() {
diff --git a/Swiften/Parser/UnitTest/StreamManagementEnabledParserTest.cpp b/Swiften/Parser/UnitTest/StreamManagementEnabledParserTest.cpp
new file mode 100644
index 0000000..07b7b31
--- /dev/null
+++ b/Swiften/Parser/UnitTest/StreamManagementEnabledParserTest.cpp
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <Swiften/Parser/StreamManagementEnabledParser.h>
+#include <Swiften/Parser/UnitTest/ElementParserTester.h>
+
+using namespace Swift;
+
+class StreamManagementEnabledParserTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(StreamManagementEnabledParserTest);
+ CPPUNIT_TEST(testParse);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testParse() {
+ StreamManagementEnabledParser testling;
+ ElementParserTester parser(&testling);
+
+ CPPUNIT_ASSERT(parser.parse(
+ "<enabled xmlns=\"urn:xmpp:sm:3\" id=\"some-long-sm-id\" resume=\"true\"/>"));
+
+ boost::shared_ptr<StreamManagementEnabled> element = boost::dynamic_pointer_cast<StreamManagementEnabled>(testling.getElement());
+ CPPUNIT_ASSERT(element->getResumeSupported());
+ CPPUNIT_ASSERT_EQUAL(std::string("some-long-sm-id"), element->getResumeID());
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(StreamManagementEnabledParserTest);
diff --git a/Swiften/Parser/UnitTest/XMLParserTest.cpp b/Swiften/Parser/UnitTest/XMLParserTest.cpp
index 2086ece..8ff56c0 100644
--- a/Swiften/Parser/UnitTest/XMLParserTest.cpp
+++ b/Swiften/Parser/UnitTest/XMLParserTest.cpp
@@ -9,12 +9,12 @@
#include <vector>
#include <string>
-#include "Swiften/Parser/XMLParserClient.h"
+#include <Swiften/Parser/XMLParserClient.h>
#ifdef HAVE_EXPAT
-#include "Swiften/Parser/ExpatParser.h"
+#include <Swiften/Parser/ExpatParser.h>
#endif
#ifdef HAVE_LIBXML
-#include "Swiften/Parser/LibXMLParser.h"
+#include <Swiften/Parser/LibXMLParser.h>
#endif
using namespace Swift;
@@ -32,6 +32,8 @@ class XMLParserTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testParse_InErrorState);
CPPUNIT_TEST(testParse_Incremental);
CPPUNIT_TEST(testParse_WhitespaceInAttribute);
+ CPPUNIT_TEST(testParse_AttributeWithoutNamespace);
+ CPPUNIT_TEST(testParse_AttributeWithNamespace);
CPPUNIT_TEST(testParse_BillionLaughs);
CPPUNIT_TEST_SUITE_END();
@@ -48,13 +50,13 @@ class XMLParserTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type);
CPPUNIT_ASSERT_EQUAL(std::string("iq"), client_.events[0].data);
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].attributes.size());
- CPPUNIT_ASSERT_EQUAL(std::string("get"), client_.events[0].attributes["type"]);
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].attributes.getEntries().size());
+ CPPUNIT_ASSERT_EQUAL(std::string("get"), client_.events[0].attributes.getAttribute("type"));
CPPUNIT_ASSERT_EQUAL(std::string(), client_.events[0].ns);
CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[1].type);
CPPUNIT_ASSERT_EQUAL(std::string("query"), client_.events[1].data);
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), client_.events[1].attributes.size());
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), client_.events[1].attributes.getEntries().size());
CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[1].ns);
CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[2].type);
@@ -78,7 +80,7 @@ class XMLParserTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type);
CPPUNIT_ASSERT_EQUAL(std::string("query"), client_.events[0].data);
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), client_.events[0].attributes.size());
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), client_.events[0].attributes.getEntries().size());
CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[0].ns);
CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[1].type);
@@ -228,6 +230,28 @@ class XMLParserTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(std::string("presence"), client_.events[2].data);
}
+ void testParse_AttributeWithoutNamespace() {
+ ParserType testling(&client_);
+
+ CPPUNIT_ASSERT(testling.parse(
+ "<query xmlns='http://swift.im' attr='3'/>"));
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].attributes.getEntries().size());
+ CPPUNIT_ASSERT_EQUAL(std::string("attr"), client_.events[0].attributes.getEntries()[0].getAttribute().getName());
+ CPPUNIT_ASSERT_EQUAL(std::string(""), client_.events[0].attributes.getEntries()[0].getAttribute().getNamespace());
+ }
+
+ void testParse_AttributeWithNamespace() {
+ ParserType testling(&client_);
+
+ CPPUNIT_ASSERT(testling.parse(
+ "<query xmlns='http://swift.im' xmlns:f='http://swift.im/f' f:attr='3'/>"));
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].attributes.getEntries().size());
+ CPPUNIT_ASSERT_EQUAL(std::string("attr"), client_.events[0].attributes.getEntries()[0].getAttribute().getName());
+ CPPUNIT_ASSERT_EQUAL(std::string("http://swift.im/f"), client_.events[0].attributes.getEntries()[0].getAttribute().getNamespace());
+ }
+
void testParse_BillionLaughs() {
ParserType testling(&client_);
@@ -246,7 +270,6 @@ class XMLParserTest : public CppUnit::TestFixture {
"]>"
"<lolz>&lol9;</lolz>"
));
-
}
private:
diff --git a/Swiften/Parser/UnitTest/XMPPParserTest.cpp b/Swiften/Parser/UnitTest/XMPPParserTest.cpp
index 8ce96d8..dbee18a 100644
--- a/Swiften/Parser/UnitTest/XMPPParserTest.cpp
+++ b/Swiften/Parser/UnitTest/XMPPParserTest.cpp
@@ -8,17 +8,17 @@
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <vector>
-#include "Swiften/Elements/ProtocolHeader.h"
+#include <Swiften/Elements/ProtocolHeader.h>
#include <string>
-#include "Swiften/Parser/XMPPParser.h"
-#include "Swiften/Parser/ElementParser.h"
-#include "Swiften/Parser/XMPPParserClient.h"
-#include "Swiften/Parser/PayloadParserFactoryCollection.h"
-#include "Swiften/Elements/Presence.h"
-#include "Swiften/Elements/IQ.h"
-#include "Swiften/Elements/Message.h"
-#include "Swiften/Elements/StreamFeatures.h"
-#include "Swiften/Elements/UnknownElement.h"
+#include <Swiften/Parser/XMPPParser.h>
+#include <Swiften/Parser/ElementParser.h>
+#include <Swiften/Parser/XMPPParserClient.h>
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Elements/Presence.h>
+#include <Swiften/Elements/IQ.h>
+#include <Swiften/Elements/Message.h>
+#include <Swiften/Elements/StreamFeatures.h>
+#include <Swiften/Elements/UnknownElement.h>
using namespace Swift;