From 2bb6bb5bee97c5431457390ae749a3f9f2de8813 Mon Sep 17 00:00:00 2001 From: Sarat Addepalli Date: Mon, 18 May 2015 09:16:34 +0530 Subject: [PATCH] Add a test case for issue #332 XML Declarations can occur only at the beginning of an XML Document. Parse() should throw an error, for not well-formed XML Documents. --- xmltest.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/xmltest.cpp b/xmltest.cpp index b70fc51..597cebb 100644 --- a/xmltest.cpp +++ b/xmltest.cpp @@ -1459,6 +1459,25 @@ int main( int argc, const char ** argv ) doc.LoadFile( "resources/dream.xml" ); XMLTest( "Error should be cleared", false, doc.Error() ); } + + { + // Check that declarations are parsed only as the FirstChild + const char* xml0 = "" + " " + ""; + const char* xml1 = "" + " " + ""; + const char* xml2 = "" + ""; + XMLDocument doc; + doc.Parse(xml0); + XMLTest("Test that the code changes do not affect normal parsing", doc.Error(), false); + doc.Parse(xml1); + XMLTest("Test that the second declaration throws an error", doc.Error(), true); + doc.Parse(xml2); + XMLTest("Test that declaration after a child throws an error", doc.Error(), true); + } // ----------- Performance tracking -------------- {