diff --git a/xmltest.cpp b/xmltest.cpp index 4bed9e9..bee12d3 100644 --- a/xmltest.cpp +++ b/xmltest.cpp @@ -375,6 +375,7 @@ int main( int argc, const char ** argv ) for( int i=0; test[i]; ++i ) { XMLDocument doc; doc.Parse( test[i] ); + XMLTest( "Element test", false, doc.Error() ); doc.Print(); printf( "----------------------------------------------\n" ); } @@ -389,6 +390,7 @@ int main( int argc, const char ** argv ) XMLDocument doc; doc.Parse( test ); + XMLTest( "Hello world declaration", false, doc.Error() ); doc.Print(); } @@ -396,6 +398,7 @@ int main( int argc, const char ** argv ) static const char* test = "Text before."; XMLDocument doc; doc.Parse( test ); + XMLTest( "Element text before", false, doc.Error() ); XMLElement* root = doc.FirstChildElement(); XMLElement* newElement = doc.NewElement( "Subelement" ); root->InsertEndChild( newElement ); @@ -405,6 +408,7 @@ int main( int argc, const char ** argv ) XMLDocument* doc = new XMLDocument(); static const char* test = ""; doc->Parse( test ); + XMLTest( "Element with sub element", false, doc->Error() ); delete doc; } { @@ -520,6 +524,7 @@ int main( int argc, const char ** argv ) XMLDocument doc; doc.Parse( str ); + XMLTest( "Top level attributes", false, doc.Error() ); XMLElement* ele = doc.FirstChildElement(); @@ -555,6 +560,7 @@ int main( int argc, const char ** argv ) XMLDocument doc; doc.Parse( str ); + XMLTest( "Empty top element", false, doc.Error() ); XMLElement* ele = doc.FirstChildElement(); @@ -645,12 +651,14 @@ int main( int argc, const char ** argv ) const char* str = "This is text"; XMLDocument doc; doc.Parse( str ); + XMLTest( "Double whitespace", false, doc.Error() ); const XMLElement* element = doc.RootElement(); XMLTest( "GetText() normal use.", "This is text", element->GetText() ); str = "This is text"; doc.Parse( str ); + XMLTest( "Bold text simulation", false, doc.Error() ); element = doc.RootElement(); XMLTest( "GetText() contained element.", element->GetText() == 0, true ); @@ -662,6 +670,7 @@ int main( int argc, const char ** argv ) const char* str = ""; XMLDocument doc; doc.Parse( str ); + XMLTest( "Empty closed element", false, doc.Error() ); XMLElement* element = doc.RootElement(); element->SetText("darkness."); @@ -672,6 +681,7 @@ int main( int argc, const char ** argv ) str = ""; doc.Parse( str ); + XMLTest( "Empty self-closed element", false, doc.Error() ); element = doc.RootElement(); element->SetText("The driver"); @@ -683,6 +693,7 @@ int main( int argc, const char ** argv ) str = "Text in nested element"; doc.Parse( str ); + XMLTest( "Text in nested element", false, doc.Error() ); element = doc.RootElement(); element->SetText("wolves"); @@ -690,6 +701,7 @@ int main( int argc, const char ** argv ) str = ""; doc.Parse( str ); + XMLTest( "Empty self-closed element round 2", false, doc.Error() ); element = doc.RootElement(); element->SetText( "str" ); @@ -841,6 +853,7 @@ int main( int argc, const char ** argv ) ""; XMLDocument doc; doc.Parse( str ); + XMLTest( "CDATA symbolic puns round 1", false, doc.Error() ); doc.Print(); XMLTest( "CDATA parse.", "I am > the rules!\n...since I make symbolic puns", @@ -858,6 +871,7 @@ int main( int argc, const char ** argv ) ""; XMLDocument doc; doc.Parse( str ); + XMLTest( "CDATA symbolic puns round 2", false, doc.Error() ); doc.Print(); XMLTest( "CDATA parse. [ tixml1:1480107 ]", @@ -895,6 +909,7 @@ int main( int argc, const char ** argv ) XMLDocument doc; doc.Parse( passages ); + XMLTest( "Entity transformation parse round 1", false, doc.Error() ); XMLElement* psg = doc.RootElement()->FirstChildElement(); const char* context = psg->Attribute( "context" ); const char* expected = "Line 5 has \"quotation marks\" and 'apostrophe marks'. It also has <, >, and &, as well as a fake copyright \xC2\xA9."; @@ -933,6 +948,7 @@ int main( int argc, const char ** argv ) XMLDocument doc( false ); doc.Parse( passages ); + XMLTest( "Entity transformation parse round 2", false, doc.Error() ); XMLTest( "No entity parsing.", "Line 5 has "quotation marks" and 'apostrophe marks'.", @@ -957,6 +973,7 @@ int main( int argc, const char ** argv ) XMLDocument doc; doc.Parse( test ); + XMLTest( "fin thickness", false, doc.Error() ); XMLText* text = doc.FirstChildElement()->FirstChildElement()->FirstChild()->ToText(); XMLTest( "Entity with one digit.", @@ -976,9 +993,12 @@ int main( int argc, const char ** argv ) XMLDocument doc; doc.Parse( doctype ); + XMLTest( "PLAY SYSTEM parse", false, doc.Error() ); doc.SaveFile( "resources/out/test7.xml" ); + XMLTest( "PLAY SYSTEM save", false, doc.Error() ); doc.DeleteChild( doc.RootElement() ); doc.LoadFile( "resources/out/test7.xml" ); + XMLTest( "PLAY SYSTEM load", false, doc.Error() ); doc.Print(); const XMLUnknown* decl = doc.FirstChild()->NextSibling()->ToUnknown(); @@ -992,6 +1012,7 @@ int main( int argc, const char ** argv ) ""; XMLDocument doc; doc.Parse( doctype ); + XMLTest( "Comment somewhat evil", false, doc.Error() ); XMLComment* comment = doc.FirstChild()->ToComment(); @@ -1037,6 +1058,7 @@ int main( int argc, const char ** argv ) // Low entities XMLDocument doc; doc.Parse( "" ); + XMLTest( "Hex values", false, doc.Error() ); const char result[] = { 0x0e, 0 }; XMLTest( "Low entities.", result, doc.FirstChildElement()->GetText() ); doc.Print(); @@ -1066,6 +1088,7 @@ int main( int argc, const char ** argv ) XMLDocument xml; xml.Parse("" "" ); + XMLTest( "Declarations for head and body", false, xml.Error() ); XMLNode* e0 = xml.FirstChild(); XMLNode* e1 = e0->NextSibling(); @@ -1083,6 +1106,7 @@ int main( int argc, const char ** argv ) "" "" "" ); + XMLTest( "Comments iteration", false, xml.Error() ); xml.Print(); int count = 0; @@ -1105,6 +1129,7 @@ int main( int argc, const char ** argv ) XMLDocument doc; doc.Parse( (const char*)buf); + XMLTest( "Broken CDATA", true, doc.Error() ); } @@ -1120,6 +1145,7 @@ int main( int argc, const char ** argv ) // This one must not result in an infinite loop XMLDocument xml; xml.Parse( "loop" ); + XMLTest( "No closing element", true, xml.Error() ); XMLTest( "Infinite loop test.", true, true ); } #endif @@ -1127,6 +1153,7 @@ int main( int argc, const char ** argv ) const char* pub = " "; XMLDocument doc; doc.Parse( pub ); + XMLTest( "Trailing DOCTYPE", false, doc.Error() ); XMLDocument clone; for( const XMLNode* node=doc.FirstChild(); node; node=node->NextSibling() ) { @@ -1160,6 +1187,7 @@ int main( int argc, const char ** argv ) ""; XMLDocument doc; doc.Parse(xml); + XMLTest( "Parse before deep cloning root element", false, doc.Error() ); doc.Print(&printer1); XMLNode* root = doc.RootElement()->DeepClone(&doc2); @@ -1186,6 +1214,7 @@ int main( int argc, const char ** argv ) ""; XMLDocument doc; doc.Parse(xml); + XMLTest( "Parse before deep cloning sub element", false, doc.Error() ); const XMLElement* subElement = doc.FirstChildElement("root")->FirstChildElement("child2"); subElement->Accept(&printer1); @@ -1215,6 +1244,7 @@ int main( int argc, const char ** argv ) ""; XMLDocument doc; doc.Parse(xml); + XMLTest( "Parse before deep cloning document", false, doc.Error() ); doc.Print(&printer1); doc.DeepCopy(&doc2); @@ -1241,6 +1271,7 @@ int main( int argc, const char ** argv ) static const char* xml = ""; XMLDocument doc; doc.Parse( xml ); + XMLTest( "Parse for attribute ordering", false, doc.Error() ); XMLElement* ele = doc.FirstChildElement(); const XMLAttribute* a = ele->FirstAttribute(); @@ -1269,10 +1300,13 @@ int main( int argc, const char ** argv ) static const char* xml2 = ""; XMLDocument doc0; doc0.Parse( xml0 ); + XMLTest( "Parse attribute with space 1", false, doc0.Error() ); XMLDocument doc1; doc1.Parse( xml1 ); + XMLTest( "Parse attribute with space 2", false, doc1.Error() ); XMLDocument doc2; doc2.Parse( xml2 ); + XMLTest( "Parse attribute with space 3", false, doc2.Error() ); XMLElement* ele = 0; ele = doc0.FirstChildElement(); @@ -1288,6 +1322,7 @@ int main( int argc, const char ** argv ) static const char* xml = ""; XMLDocument doc; doc.Parse( xml ); + XMLTest( "Parse two elements with attribute", false, doc.Error() ); XMLElement* ele0 = doc.FirstChildElement()->FirstChildElement(); XMLElement* ele1 = ele0->NextSiblingElement(); bool equal = ele0->ShallowEqual( ele1 ); @@ -1300,6 +1335,7 @@ int main( int argc, const char ** argv ) static const char* xml = "Text"; XMLDocument doc; doc.Parse( xml ); + XMLTest( "Parse element with attribute and nested element round 1", false, doc.Error() ); XMLElement* ele = XMLHandle( doc ).FirstChildElement( "element" ).FirstChild().ToElement(); XMLTest( "Handle, success, mutable", "sub", ele->Value() ); @@ -1313,6 +1349,7 @@ int main( int argc, const char ** argv ) static const char* xml = "Text"; XMLDocument doc; doc.Parse( xml ); + XMLTest( "Parse element with attribute and nested element round 2", false, doc.Error() ); XMLConstHandle docH( doc ); const XMLElement* ele = docH.FirstChildElement( "element" ).FirstChild().ToElement(); @@ -1346,6 +1383,7 @@ int main( int argc, const char ** argv ) const char* xml = " 1.2 1 38 true "; XMLDocument doc; doc.Parse( xml ); + XMLTest( "Parse points", false, doc.Error() ); const XMLElement* pointElement = doc.RootElement(); @@ -1417,6 +1455,7 @@ int main( int argc, const char ** argv ) ""; XMLDocument doc( true, COLLAPSE_WHITESPACE ); doc.Parse( xml ); + XMLTest( "Parse with whitespace collapsing and &apos", false, doc.Error() ); const XMLElement* element = doc.FirstChildElement(); for( const XMLElement* parent = element->FirstChildElement(); @@ -1444,6 +1483,7 @@ int main( int argc, const char ** argv ) const char* xml = " "; XMLDocument doc( true, COLLAPSE_WHITESPACE ); doc.Parse( xml ); + XMLTest( "Parse with all whitespaces", false, doc.Error() ); XMLTest( "Whitespace all space", true, 0 == doc.FirstChildElement()->FirstChild() ); } @@ -1452,6 +1492,7 @@ int main( int argc, const char ** argv ) const char* xml = ""; XMLDocument doc; doc.Parse( xml ); + XMLTest( "Parse with self-closed element", false, doc.Error() ); XMLElement* ele = doc.NewElement( "unused" ); // This will get cleaned up with the 'doc' going out of scope. XMLTest( "Tracking unused elements", true, ele != 0, false ); } @@ -1461,6 +1502,7 @@ int main( int argc, const char ** argv ) const char* xml = "abc"; XMLDocument doc; doc.Parse( xml ); + XMLTest( "Parse for printing of sub-element", false, doc.Error() ); XMLElement* ele = doc.FirstChildElement( "parent")->FirstChildElement( "child"); XMLPrinter printer; @@ -1539,6 +1581,7 @@ int main( int argc, const char ** argv ) XMLDocument doc; doc.Parse(xml); + XMLTest( "Insertion with removal parse round 1", false, doc.Error() ); XMLElement* subtree = doc.RootElement()->FirstChildElement("one")->FirstChildElement("subtree"); XMLElement* two = doc.RootElement()->FirstChildElement("two"); two->InsertFirstChild(subtree); @@ -1547,6 +1590,7 @@ int main( int argc, const char ** argv ) XMLTest("Move node from within to ", xmlInsideTwo, printer1.CStr()); doc.Parse(xml); + XMLTest( "Insertion with removal parse round 2", false, doc.Error() ); subtree = doc.RootElement()->FirstChildElement("one")->FirstChildElement("subtree"); two = doc.RootElement()->FirstChildElement("two"); doc.RootElement()->InsertAfterChild(two, subtree); @@ -1555,6 +1599,7 @@ int main( int argc, const char ** argv ) XMLTest("Move node from within after ", xmlAfterTwo, printer2.CStr(), false); doc.Parse(xml); + XMLTest( "Insertion with removal parse round 3", false, doc.Error() ); XMLNode* one = doc.RootElement()->FirstChildElement("one"); subtree = one->FirstChildElement("subtree"); doc.RootElement()->InsertAfterChild(one, subtree); @@ -1563,6 +1608,7 @@ int main( int argc, const char ** argv ) XMLTest("Move node from within after ", xmlAfterOne, printer3.CStr(), false); doc.Parse(xml); + XMLTest( "Insertion with removal parse round 4", false, doc.Error() ); subtree = doc.RootElement()->FirstChildElement("one")->FirstChildElement("subtree"); two = doc.RootElement()->FirstChildElement("two"); doc.RootElement()->InsertEndChild(subtree); @@ -1577,6 +1623,7 @@ int main( int argc, const char ** argv ) ""; XMLDocument doc; doc.Parse(xml); + XMLTest( "Parse svg with text", false, doc.Error() ); doc.Print(); } @@ -1585,6 +1632,7 @@ int main( int argc, const char ** argv ) const char* xml = "<12"; XMLDocument doc; doc.Parse(xml); + XMLTest( "Parse root-sample-field0", true, doc.Error() ); doc.PrintError(); } @@ -1596,6 +1644,7 @@ int main( int argc, const char ** argv ) const char* xml = ""; XMLDocument doc; doc.Parse( xml ); + XMLTest( "Parse self-closed empty element", false, doc.Error() ); doc.FirstChildElement()->SetAttribute( "attrA-f64", 123456789.123456789 ); doc.FirstChildElement()->SetAttribute( "attrB-f64", 1.001e9 ); doc.FirstChildElement()->SetAttribute( "attrC-f64", 1.0e9 ); @@ -1632,10 +1681,12 @@ int main( int argc, const char ** argv ) { XMLDocument doc; doc.Parse(xmlText); + XMLTest( "Parse hex no closing tag round 1", true, doc.Error() ); } { XMLDocument doc; doc.Parse(xmlText); + XMLTest( "Parse hex no closing tag round 2", true, doc.Error() ); doc.Clear(); } } @@ -1657,6 +1708,7 @@ int main( int argc, const char ** argv ) const char* xml = "�"; XMLDocument doc; doc.Parse( xml ); + XMLTest( "Parse hex with closing tag", false, doc.Error() ); XMLPrinter printer; doc.Print( &printer ); @@ -1730,6 +1782,7 @@ int main( int argc, const char ** argv ) XMLDocument* doc = new XMLDocument(); XMLTest( "XMLDocument::Value() returns null?", NULL, doc->Value() ); doc->Parse( validXml ); + XMLTest( "Parse to test XMLDocument::Value()", false, doc->Error()); XMLTest( "XMLDocument::Value() returns null?", NULL, doc->Value() ); delete doc; } @@ -1974,11 +2027,14 @@ int main( int argc, const char ** argv ) #else clock_t cstart = clock(); #endif + bool parseDreamXmlFailed = false; static const int COUNT = 10; for (int i = 0; i < COUNT; ++i) { XMLDocument doc; doc.Parse(mem); + parseDreamXmlFailed = parseDreamXmlFailed || doc.Error(); } + XMLTest( "Parse dream.xml", false, parseDreamXmlFailed ); #if defined( _MSC_VER ) QueryPerformanceCounter((LARGE_INTEGER*)&end); #else