summaryrefslogtreecommitdiff
path: root/shared/tinyxml/xmltest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'shared/tinyxml/xmltest.cpp')
-rw-r--r--shared/tinyxml/xmltest.cpp108
1 files changed, 89 insertions, 19 deletions
diff --git a/shared/tinyxml/xmltest.cpp b/shared/tinyxml/xmltest.cpp
index 5ae3922c..1d01f535 100644
--- a/shared/tinyxml/xmltest.cpp
+++ b/shared/tinyxml/xmltest.cpp
@@ -19,11 +19,15 @@
#include "tinyxml.h"
+bool XmlTest (const char* testString, const char* expected, const char* found, bool noEcho = false);
+bool XmlTest( const char* testString, int expected, int found, bool noEcho = false );
+
static int gPass = 0;
static int gFail = 0;
-bool XmlTest (const char* testString, const char* expected, const char* found, bool noEcho = false)
+
+bool XmlTest (const char* testString, const char* expected, const char* found, bool noEcho )
{
bool pass = !strcmp( expected, found );
if ( pass )
@@ -44,7 +48,7 @@ bool XmlTest (const char* testString, const char* expected, const char* found, b
}
-bool XmlTest( const char* testString, int expected, int found, bool noEcho = false )
+bool XmlTest( const char* testString, int expected, int found, bool noEcho )
{
bool pass = ( expected == found );
if ( pass )
@@ -74,6 +78,7 @@ bool XmlTest( const char* testString, int expected, int found, bool noEcho = fal
int main()
{
+
//
// We start with the 'demoStart' todo list. Process it. And
// should hopefully end up with the todo list as illustrated.
@@ -91,8 +96,8 @@ int main()
{
#ifdef TIXML_USE_STL
- /* What the todo list should look like after processing.
- In stream (no formatting) representation. */
+ // What the todo list should look like after processing.
+ // In stream (no formatting) representation.
const char* demoEnd =
"<?xml version=\"1.0\" standalone=\"no\" ?>"
"<!-- Our to do list data -->"
@@ -399,7 +404,7 @@ int main()
}
#endif
}
-
+
{
const char* str = "<doc attr0='1' attr1='2.0' attr2='foo' />";
@@ -424,6 +429,30 @@ int main()
result = ele->QueryIntAttribute( "bar", &iVal );
XmlTest( "Query attribute: does not exist", result, TIXML_NO_ATTRIBUTE );
}
+
+ {
+ const char* str = "<doc/>";
+
+ TiXmlDocument doc;
+ doc.Parse( str );
+
+ TiXmlElement* ele = doc.FirstChildElement();
+
+ int iVal;
+ double dVal;
+
+ ele->SetAttribute( "str", "strValue" );
+ ele->SetAttribute( "int", 1 );
+ ele->SetDoubleAttribute( "double", -1.0 );
+
+ const char* cStr = ele->Attribute( "str" );
+ ele->QueryIntAttribute( "int", &iVal );
+ ele->QueryDoubleAttribute( "double", &dVal );
+
+ XmlTest( "Attribute round trip. c-string.", "strValue", cStr );
+ XmlTest( "Attribute round trip. int.", 1, iVal );
+ XmlTest( "Attribute round trip. double.", -1, (int)dVal );
+ }
{
const char* str = "\t<?xml version=\"1.0\" standalone=\"no\" ?>\t<room doors='2'>\n"
@@ -1063,8 +1092,8 @@ int main()
TiXmlDocument doc;
doc.Parse( doctype );
- XmlTest( "Parsing repeated attributes.", 0, (int)doc.Error() ); // not an error to tinyxml
- XmlTest( "Parsing repeated attributes.", "blue", doc.FirstChildElement( "element" )->Attribute( "attr" ) );
+ XmlTest( "Parsing repeated attributes.", true, doc.Error() ); // is an error to tinyxml (didn't use to be, but caused issues)
+ //XmlTest( "Parsing repeated attributes.", "blue", doc.FirstChildElement( "element" )->Attribute( "attr" ) );
}
{
@@ -1161,19 +1190,19 @@ int main()
int i;
float f;
bool b;
- //std::string str;
+ std::string str;
XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "bar", &d ), TIXML_SUCCESS );
XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "bar", &i ), TIXML_SUCCESS );
XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "bar", &f ), TIXML_SUCCESS );
XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "bar", &b ), TIXML_WRONG_TYPE );
XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "nobar", &b ), TIXML_NO_ATTRIBUTE );
- //XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "barStr", &str ), TIXML_SUCCESS );
+ XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "barStr", &str ), TIXML_SUCCESS );
XmlTest( "QueryValueAttribute", (d==3.0), true );
XmlTest( "QueryValueAttribute", (i==3), true );
XmlTest( "QueryValueAttribute", (f==3.0f), true );
- //XmlTest( "QueryValueAttribute", (str==std::string( "a string" )), true );
+ XmlTest( "QueryValueAttribute", (str==std::string( "a string" )), true );
}
#endif
@@ -1256,16 +1285,59 @@ int main()
XmlTest( "Comments ignore entities.", " declarations for <head> & <body> ", c0->Value(), true );
XmlTest( "Comments ignore entities.", " far &amp; away ", c1->Value(), true );
}
- /*
+
{
TiXmlDocument xml;
- xml.Parse( "<tag>/</tag>" );
- xml.Print();
- xml.FirstChild()->Print( stdout, 0 );
- xml.FirstChild()->Type();
+ xml.Parse( "<Parent>"
+ "<child1 att=''/>"
+ "<!-- With this comment, child2 will not be parsed! -->"
+ "<child2 att=''/>"
+ "</Parent>" );
+ int count = 0;
+
+ TiXmlNode* ele = 0;
+ while ( (ele = xml.FirstChildElement( "Parent" )->IterateChildren( ele ) ) != 0 ) {
+ ++count;
+ }
+ XmlTest( "Comments iterate correctly.", 3, count );
}
- */
-
+
+ {
+ // trying to repro ]1874301]. If it doesn't go into an infinite loop, all is well.
+ unsigned char buf[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?><feed><![CDATA[Test XMLblablablalblbl";
+ buf[60] = 239;
+ buf[61] = 0;
+
+ TiXmlDocument doc;
+ doc.Parse( (const char*)buf);
+ }
+
+
+ {
+ // bug 1827248 Error while parsing a little bit malformed file
+ // Actually not malformed - should work.
+ TiXmlDocument xml;
+ xml.Parse( "<attributelist> </attributelist >" );
+ XmlTest( "Handle end tag whitespace", false, xml.Error() );
+ }
+
+ {
+ // 1709904 - can not repro the crash
+ {
+ TiXmlDocument xml;
+ xml.Parse( "<tag>/</tag>" );
+ XmlTest( "Odd XML parsing.", xml.FirstChild()->Value(), "tag" );
+ }
+ /* Could not repro. {
+ TiXmlDocument xml;
+ xml.LoadFile( "EQUI_Inventory.xml" );
+ //XmlTest( "Odd XML parsing.", xml.FirstChildElement()->Value(), "XML" );
+ TiXmlPrinter printer;
+ xml.Accept( &printer );
+ fprintf( stdout, "%s", printer.CStr() );
+ }*/
+ }
+
/* 1417717 experiment
{
TiXmlDocument xml;
@@ -1290,5 +1362,3 @@ int main()
printf ("\nPass %d, Fail %d\n", gPass, gFail);
return gFail;
}
-
-
bgstack15