summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-05-10 19:15:44 +0000
committerarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-05-10 19:15:44 +0000
commit7bda2cb529550fae678224102e1c5d0697dacf04 (patch)
treebfd1821299e405ad8f82b8b19df4ccc7188e5836 /tests
parent55f3cba20c5fc037e9f5973984ea9d596680a6f8 (diff)
Implemented better DOCTYPE parsing, added more DOCTYPE tests
git-svn-id: http://pugixml.googlecode.com/svn/trunk@409 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests')
-rw-r--r--tests/test_parse.cpp29
-rw-r--r--tests/test_parse_doctype.cpp92
2 files changed, 92 insertions, 29 deletions
diff --git a/tests/test_parse.cpp b/tests/test_parse.cpp
index 0719e5d..fb0dd23 100644
--- a/tests/test_parse.cpp
+++ b/tests/test_parse.cpp
@@ -497,35 +497,6 @@ TEST(parse_declaration_error)
CHECK(doc.load(STR("<?xml version='1?>"), parse_minimal | parse_declaration).status == status_bad_attribute);
}
-TEST(parse_doctype_skip)
-{
- xml_document doc;
- CHECK(doc.load(STR("<!DOCTYPE doc>")) && !doc.first_child());
- CHECK(doc.load(STR("<!DOCTYPE doc SYSTEM 'foo'>")) && !doc.first_child());
- CHECK(doc.load(STR("<!DOCTYPE doc SYSTEM \"foo\">")) && !doc.first_child());
- CHECK(doc.load(STR("<!DOCTYPE doc PUBLIC \"foo\" 'bar'>")) && !doc.first_child());
- CHECK(doc.load(STR("<!DOCTYPE doc PUBLIC \"foo'\">")) && !doc.first_child());
- CHECK(doc.load(STR("<!DOCTYPE doc SYSTEM 'foo' [<!ELEMENT foo 'ANY'>]>")) && !doc.first_child());
-
- CHECK(doc.load(STR("<!DOCTYPE doc SYSTEM 'foo' [<!ELEMENT foo 'ANY'>]><node/>")));
- CHECK_NODE(doc, STR("<node />"));
-}
-
-TEST(parse_doctype_error)
-{
- xml_document doc;
- CHECK(doc.load(STR("<!DOCTYPE")).status == status_bad_doctype);
- CHECK(doc.load(STR("<!DOCTYPE doc")).status == status_bad_doctype);
- CHECK(doc.load(STR("<!DOCTYPE doc SYSTEM 'foo")).status == status_bad_doctype);
- CHECK(doc.load(STR("<!DOCTYPE doc SYSTEM \"foo")).status == status_bad_doctype);
- CHECK(doc.load(STR("<!DOCTYPE doc PUBLIC \"foo\" 'bar")).status == status_bad_doctype);
- CHECK(doc.load(STR("<!DOCTYPE doc PUBLIC \"foo'\"")).status == status_bad_doctype);
- CHECK(doc.load(STR("<!DOCTYPE doc SYSTEM 'foo' [<!ELEMENT foo 'ANY")).status == status_bad_doctype);
- CHECK(doc.load(STR("<!DOCTYPE doc SYSTEM 'foo' [<!ELEMENT foo 'ANY'>")).status == status_bad_doctype);
- CHECK(doc.load(STR("<!DOCTYPE doc SYSTEM 'foo' [<!ELEMENT foo 'ANY'>]")).status == status_bad_doctype);
- CHECK(doc.load(STR("<!DOCTYPE doc SYSTEM 'foo' [<!ELEMENT foo 'ANY'>] ")).status == status_bad_doctype);
-}
-
TEST(parse_empty)
{
xml_document doc;
diff --git a/tests/test_parse_doctype.cpp b/tests/test_parse_doctype.cpp
new file mode 100644
index 0000000..35015ff
--- /dev/null
+++ b/tests/test_parse_doctype.cpp
@@ -0,0 +1,92 @@
+#include "common.hpp"
+
+#include <string>
+
+bool test_doctype_wf(const std::basic_string<char_t>& decl)
+{
+ xml_document doc;
+
+ // standalone
+ if (!doc.load(decl.c_str()) || doc.first_child()) return false;
+
+ // pcdata pre/postfix
+ if (!doc.load(("a" + decl).c_str()) || doc.first_child()) return false;
+ if (!doc.load((decl + "b").c_str()) || doc.first_child()) return false;
+ if (!doc.load(("a" + decl + "b").c_str()) || doc.first_child()) return false;
+
+ // node pre/postfix
+ if (!doc.load(("<nodea/>" + decl).c_str()) || !test_node(doc, STR("<nodea />"), STR(""), format_raw)) return false;
+ if (!doc.load((decl + "<nodeb/>").c_str()) || !test_node(doc, STR("<nodeb />"), STR(""), format_raw)) return false;
+ if (!doc.load(("<nodea/>" + decl + "<nodeb/>").c_str()) || !test_node(doc, STR("<nodea /><nodeb />"), STR(""), format_raw)) return false;
+
+ return true;
+}
+
+bool test_doctype_nwf(const std::basic_string<char_t>& decl)
+{
+ xml_document doc;
+
+ // standalone
+ if (doc.load(decl.c_str()).status != status_bad_doctype) return false;
+
+ // pcdata postfix
+ if (doc.load((decl + "b").c_str()).status != status_bad_doctype) return false;
+
+ // node postfix
+ if (doc.load((decl + "<nodeb/>").c_str()).status != status_bad_doctype) return false;
+
+ return true;
+}
+
+#define TEST_DOCTYPE_WF(contents) CHECK(test_doctype_wf(STR(contents)))
+#define TEST_DOCTYPE_NWF(contents) CHECK(test_doctype_nwf(STR(contents)))
+
+TEST(parse_doctype_skip)
+{
+ TEST_DOCTYPE_WF("<!DOCTYPE doc>");
+ TEST_DOCTYPE_WF("<!DOCTYPE doc SYSTEM 'foo'>");
+ TEST_DOCTYPE_WF("<!DOCTYPE doc SYSTEM \"foo\">");
+ TEST_DOCTYPE_WF("<!DOCTYPE doc PUBLIC \"foo\" 'bar'>");
+ TEST_DOCTYPE_WF("<!DOCTYPE doc PUBLIC \"foo'\">");
+ TEST_DOCTYPE_WF("<!DOCTYPE doc SYSTEM 'foo' [<!ELEMENT foo 'ANY'>]>");
+}
+
+TEST(parse_doctype_error)
+{
+ TEST_DOCTYPE_NWF("<!DOCTYPE");
+ TEST_DOCTYPE_NWF("<!DOCTYPE doc");
+ TEST_DOCTYPE_NWF("<!DOCTYPE doc SYSTEM 'foo");
+ TEST_DOCTYPE_NWF("<!DOCTYPE doc SYSTEM \"foo");
+ TEST_DOCTYPE_NWF("<!DOCTYPE doc PUBLIC \"foo\" 'bar");
+ TEST_DOCTYPE_NWF("<!DOCTYPE doc PUBLIC \"foo'\"");
+ TEST_DOCTYPE_NWF("<!DOCTYPE doc SYSTEM 'foo' [<!ELEMENT foo 'ANY");
+ TEST_DOCTYPE_NWF("<!DOCTYPE doc SYSTEM 'foo' [<!ELEMENT foo 'ANY'>");
+ TEST_DOCTYPE_NWF("<!DOCTYPE doc SYSTEM 'foo' [<!ELEMENT foo 'ANY'>]");
+ TEST_DOCTYPE_NWF("<!DOCTYPE doc SYSTEM 'foo' [<!ELEMENT foo 'ANY'>] ");
+}
+
+// Examples from W3C recommendations
+TEST(parse_doctype_w3c_wf)
+{
+ TEST_DOCTYPE_WF("<!DOCTYPE greeting SYSTEM \"hello.dtd\">");
+ TEST_DOCTYPE_WF("<!DOCTYPE greeting [ <!ELEMENT greeting (#PCDATA)> ]>");
+ TEST_DOCTYPE_WF("<!DOCTYPE greeting [ <!ATTLIST list type (bullets|ordered|glossary) \"ordered\"> <!ATTLIST form method CDATA #FIXED \"POST\"> ]>");
+ TEST_DOCTYPE_WF("<!DOCTYPE greeting [ <!ENTITY % draft 'INCLUDE' > <!ENTITY % final 'IGNORE' > <![%draft;[ <!ELEMENT book (comments*, title, body, supplements?)> ]]> <![%final;[ <!ELEMENT book (title, body, supplements?)> ]]>]>");
+ TEST_DOCTYPE_WF("<!DOCTYPE greeting [ <!ENTITY open-hatch PUBLIC \"-//Textuality//TEXT Standard open-hatch boilerplate//EN\" \"http://www.textuality.com/boilerplate/OpenHatch.xml\"> ]>");
+ TEST_DOCTYPE_WF("<!DOCTYPE greeting [ <!ENTITY EndAttr \"27'\" > ]>");
+}
+
+TEST(parse_doctype_w3c_nwf)
+{
+ TEST_DOCTYPE_NWF("<!DOCTYPE greeting SYSTEM \"hello.dtd>");
+ TEST_DOCTYPE_NWF("<!DOCTYPE greeting SYSTEM");
+ TEST_DOCTYPE_NWF("<!DOCTYPE greeting [ <!ELEMENT greeting (#PCDATA)> ]");
+ TEST_DOCTYPE_NWF("<!DOCTYPE greeting [ <!ELEMENT greeting (#PCDATA)>");
+ TEST_DOCTYPE_NWF("<!DOCTYPE greeting [ <!ELEMENT greeting (#PCDATA");
+ TEST_DOCTYPE_NWF("<!DOCTYPE greeting [ ");
+ TEST_DOCTYPE_NWF("<!DOCTYPE greeting [ <!ATTLIST list type (bullets|ordered|glossary) \"ordered\"> ]");
+ TEST_DOCTYPE_NWF("<!DOCTYPE greeting [ <!ATTLIST list type (bullets|ordered|glossary) \"ordered\">");
+ TEST_DOCTYPE_NWF("<!DOCTYPE greeting [ <!ATTLIST list type (bullets|ordered|glossary) \"orde");
+ TEST_DOCTYPE_NWF("<!DOCTYPE greeting [ <!ATTLIST list type (bullets|ordered|glossary) ");
+ TEST_DOCTYPE_NWF("<!DOCTYPE greeting [ <!ENTITY open-hatch PUBLIC \"-//Textuality//TEXT Standard open-hatch boilerplate//EN\" \"http://www.textuality.com/boilerplate/OpenHatch.x");
+}