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
@@ -39,6 +39,10 @@ class XMLParserTest : public CppUnit::TestFixture {
39 CPPUNIT_TEST(testParse_InternalEntity); 39 CPPUNIT_TEST(testParse_InternalEntity);
40 //CPPUNIT_TEST(testParse_UndefinedPrefix); 40 //CPPUNIT_TEST(testParse_UndefinedPrefix);
41 //CPPUNIT_TEST(testParse_UndefinedAttributePrefix); 41 //CPPUNIT_TEST(testParse_UndefinedAttributePrefix);
42 CPPUNIT_TEST(testParse_AllowCommentsInXML);
43 CPPUNIT_TEST(testParse_DisallowCommentsInXML);
44 CPPUNIT_TEST(testParse_Doctype);
45 CPPUNIT_TEST(testParse_ProcessingInstructions);
42 CPPUNIT_TEST_SUITE_END(); 46 CPPUNIT_TEST_SUITE_END();
43 47
44 public: 48 public:
@@ -185,7 +189,7 @@ class XMLParserTest : public CppUnit::TestFixture {
185 } 189 }
186 190
187 void testParse_UnhandledXML() { 191 void testParse_UnhandledXML() {
188 ParserType testling(&client_); 192 ParserType testling(&client_, true);
189 193
190 CPPUNIT_ASSERT(testling.parse("<iq><!-- Testing --></iq>")); 194 CPPUNIT_ASSERT(testling.parse("<iq><!-- Testing --></iq>"));
191 195
@@ -331,13 +335,44 @@ class XMLParserTest : public CppUnit::TestFixture {
331 void testParse_UndefinedAttributePrefix() { 335 void testParse_UndefinedAttributePrefix() {
332 ParserType testling(&client_); 336 ParserType testling(&client_);
333 337
334 CPPUNIT_ASSERT(testling.parse( 338 CPPUNIT_ASSERT(testling.parse("<foo bar:baz='bla'/>"));
335 "<foo bar:baz='bla'/>"));
336 339
337 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].attributes.getEntries().size()); 340 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].attributes.getEntries().size());
338 CPPUNIT_ASSERT_EQUAL(std::string("bar:baz"), client_.events[0].attributes.getEntries()[0].getAttribute().getName()); 341 CPPUNIT_ASSERT_EQUAL(std::string("bar:baz"), client_.events[0].attributes.getEntries()[0].getAttribute().getName());
339 } 342 }
340 343
344 void testParse_AllowCommentsInXML() {
345 ParserType testling(&client_, true);
346
347 CPPUNIT_ASSERT(testling.parse("<message><!-- Some More Comments Testing --></message>"));
348
349 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), client_.events.size());
350
351 CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type);
352 CPPUNIT_ASSERT_EQUAL(std::string("message"), client_.events[0].data);
353
354 CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[1].type);
355 CPPUNIT_ASSERT_EQUAL(std::string("message"), client_.events[1].data);
356 }
357
358 void testParse_DisallowCommentsInXML() {
359 ParserType testling(&client_);
360
361 CPPUNIT_ASSERT(!testling.parse("<message><!-- Some More Comments Testing --></message>"));
362 }
363
364 void testParse_Doctype() {
365 ParserType testling(&client_);
366
367 CPPUNIT_ASSERT(!testling.parse("<!DOCTYPE greeting SYSTEM \"hello.dtd\">"));
368 }
369
370 void testParse_ProcessingInstructions() {
371 ParserType testling(&client_);
372
373 CPPUNIT_ASSERT(!testling.parse("<?xml-stylesheet type=\"text/xsl\" href=\"Sample.xsl\"?>"));
374 }
375
341 private: 376 private:
342 class Client : public XMLParserClient { 377 class Client : public XMLParserClient {
343 public: 378 public:
@@ -378,6 +413,7 @@ class XMLParserTest : public CppUnit::TestFixture {
378 void handleNamespaceDeclaration(const std::string& prefix, const std::string& uri) override { 413 void handleNamespaceDeclaration(const std::string& prefix, const std::string& uri) override {
379 namespaces_[prefix] = uri; 414 namespaces_[prefix] = uri;
380 } 415 }
416
381 std::vector<Event> events; 417 std::vector<Event> events;
382 private: 418 private:
383 NamespaceMap namespaces_; 419 NamespaceMap namespaces_;