Merge branch 'SirR4T-assert-fires-when-calling-XMLDocument--Value'

This commit is contained in:
Lee Thomason 2015-05-22 11:07:58 -07:00
commit 03d0f4ea25
3 changed files with 43 additions and 21 deletions

View File

@ -645,6 +645,9 @@ XMLNode::~XMLNode()
const char* XMLNode::Value() const const char* XMLNode::Value() const
{ {
// Catch an edge case: XMLDocuments don't have a a Value. Carefully return nullptr.
if ( this->ToDocument() )
return 0;
return _value.GetStr(); return _value.GetStr();
} }

View File

@ -708,7 +708,7 @@ public:
/** The meaning of 'value' changes for the specific type. /** The meaning of 'value' changes for the specific type.
@verbatim @verbatim
Document: empty Document: empty (NULL is returned, not an empty string)
Element: name of the element Element: name of the element
Comment: the comment text Comment: the comment text
Unknown: the tag contents Unknown: the tag contents

View File

@ -30,7 +30,13 @@ int gFail = 0;
bool XMLTest (const char* testString, const char* expected, const char* found, bool echo=true, bool extraNL=false ) bool XMLTest (const char* testString, const char* expected, const char* found, bool echo=true, bool extraNL=false )
{ {
bool pass = !strcmp( expected, found ); bool pass;
if ( !expected && !found )
pass = true;
else if ( !expected || !found )
pass = false;
else
pass = !strcmp( expected, found );
if ( pass ) if ( pass )
printf ("[pass]"); printf ("[pass]");
else else
@ -1479,6 +1485,19 @@ int main( int argc, const char ** argv )
XMLTest("Test that declaration after a child throws an error", doc.ErrorID(), XML_ERROR_PARSING_DECLARATION); XMLTest("Test that declaration after a child throws an error", doc.ErrorID(), XML_ERROR_PARSING_DECLARATION);
} }
{
// No matter - before or after successfully parsing a text -
// calling XMLDocument::Value() causes an assert in debug.
const char* validXml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"
"<first />"
"<second />";
XMLDocument* doc = new XMLDocument();
XMLTest( "XMLDocument::Value() returns null?", NULL, doc->Value() );
doc->Parse( validXml );
XMLTest( "XMLDocument::Value() returns null?", NULL, doc->Value() );
delete doc;
}
// ----------- Performance tracking -------------- // ----------- Performance tracking --------------
{ {
#if defined( _MSC_VER ) #if defined( _MSC_VER )