summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Parser/UnitTest/XMLParserTest.cpp')
-rw-r--r--Swiften/Parser/UnitTest/XMLParserTest.cpp42
1 files changed, 39 insertions, 3 deletions
diff --git a/Swiften/Parser/UnitTest/XMLParserTest.cpp b/Swiften/Parser/UnitTest/XMLParserTest.cpp
index c026b4b..63d30ea 100644
--- a/Swiften/Parser/UnitTest/XMLParserTest.cpp
+++ b/Swiften/Parser/UnitTest/XMLParserTest.cpp
@@ -33,18 +33,22 @@ 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(testParse_InternalEntity);
//CPPUNIT_TEST(testParse_UndefinedPrefix);
//CPPUNIT_TEST(testParse_UndefinedAttributePrefix);
+ CPPUNIT_TEST(testParse_AllowCommentsInXML);
+ CPPUNIT_TEST(testParse_DisallowCommentsInXML);
+ CPPUNIT_TEST(testParse_Doctype);
+ CPPUNIT_TEST(testParse_ProcessingInstructions);
CPPUNIT_TEST_SUITE_END();
public:
void testParse_NestedElements() {
ParserType testling(&client_);
CPPUNIT_ASSERT(testling.parse(
"<iq type=\"get\">"
"<query xmlns='jabber:iq:version'/>"
@@ -179,19 +183,19 @@ class XMLParserTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(std::string("y"), client_.events[2].data);
CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[2].ns);
CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[3].type);
CPPUNIT_ASSERT_EQUAL(std::string("x"), client_.events[3].data);
CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[3].ns);
}
void testParse_UnhandledXML() {
- ParserType testling(&client_);
+ ParserType testling(&client_, true);
CPPUNIT_ASSERT(testling.parse("<iq><!-- Testing --></iq>"));
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), client_.events.size());
CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type);
CPPUNIT_ASSERT_EQUAL(std::string("iq"), client_.events[0].data);
CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[1].type);
@@ -325,25 +329,56 @@ class XMLParserTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[3].type);
CPPUNIT_ASSERT_EQUAL(std::string("foo:bar"), client_.events[3].data);
CPPUNIT_ASSERT_EQUAL(std::string(""), client_.events[3].ns);
}
void testParse_UndefinedAttributePrefix() {
ParserType testling(&client_);
- CPPUNIT_ASSERT(testling.parse(
- "<foo bar:baz='bla'/>"));
+ CPPUNIT_ASSERT(testling.parse("<foo bar:baz='bla'/>"));
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].attributes.getEntries().size());
CPPUNIT_ASSERT_EQUAL(std::string("bar:baz"), client_.events[0].attributes.getEntries()[0].getAttribute().getName());
}
+ void testParse_AllowCommentsInXML() {
+ ParserType testling(&client_, true);
+
+ CPPUNIT_ASSERT(testling.parse("<message><!-- Some More Comments Testing --></message>"));
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), client_.events.size());
+
+ CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type);
+ CPPUNIT_ASSERT_EQUAL(std::string("message"), client_.events[0].data);
+
+ CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[1].type);
+ CPPUNIT_ASSERT_EQUAL(std::string("message"), client_.events[1].data);
+ }
+
+ void testParse_DisallowCommentsInXML() {
+ ParserType testling(&client_);
+
+ CPPUNIT_ASSERT(!testling.parse("<message><!-- Some More Comments Testing --></message>"));
+ }
+
+ void testParse_Doctype() {
+ ParserType testling(&client_);
+
+ CPPUNIT_ASSERT(!testling.parse("<!DOCTYPE greeting SYSTEM \"hello.dtd\">"));
+ }
+
+ void testParse_ProcessingInstructions() {
+ ParserType testling(&client_);
+
+ CPPUNIT_ASSERT(!testling.parse("<?xml-stylesheet type=\"text/xsl\" href=\"Sample.xsl\"?>"));
+ }
+
private:
class Client : public XMLParserClient {
public:
using NamespaceMap = std::unordered_map<std::string /* prefix */, std::string /* uri */>;
enum Type { StartElement, EndElement, CharacterData, NamespaceDefined };
struct Event {
Event(
Type type,
const std::string& data,
@@ -372,18 +407,19 @@ class XMLParserTest : public CppUnit::TestFixture {
}
void handleCharacterData(const std::string& data) override {
events.push_back(Event(CharacterData, data));
}
void handleNamespaceDeclaration(const std::string& prefix, const std::string& uri) override {
namespaces_[prefix] = uri;
}
+
std::vector<Event> events;
private:
NamespaceMap namespaces_;
} client_;
};
#ifdef HAVE_EXPAT
CPPUNIT_TEST_SUITE_REGISTRATION(XMLParserTest<ExpatParser>);
#endif