#include "tinyxml2.h" #include #include #include #if defined( WIN32 ) #include _CrtMemState startMemState; _CrtMemState endMemState; #endif using namespace tinyxml2; int gPass = 0; int gFail = 0; bool XmlTest (const char* testString, const char* expected, const char* found, bool noEcho ) { bool pass = !strcmp( expected, found ); if ( pass ) printf ("[pass]"); else printf ("[fail]"); if ( noEcho ) printf (" %s\n", testString); else printf (" %s [%s][%s]\n", testString, expected, found); if ( pass ) ++gPass; else ++gFail; return pass; } bool XmlTest( const char* testString, int expected, int found, bool noEcho ) { bool pass = ( expected == found ); if ( pass ) printf ("[pass]"); else printf ("[fail]"); if ( noEcho ) printf (" %s\n", testString); else printf (" %s [%d][%d]\n", testString, expected, found); if ( pass ) ++gPass; else ++gFail; return pass; } int main( int argc, const char* argv ) { #if defined( WIN32 ) _CrtMemCheckpoint( &startMemState ); #endif #if 0 { static const char* test = ""; XMLDocument doc; doc.Parse( test ); doc.Print(); } #endif #if 0 { static const char* test[] = { "", "", "", "", "", "", " \n \n ", "", "", "Text inside element.", "", "Text inside and bolded in the element.", "Text inside and bolded in the element.", "This & That.", "", 0 }; for( int i=0; test[i]; ++i ) { XMLDocument doc; doc.Parse( test[i] ); doc.Print(); printf( "----------------------------------------------\n" ); } } #endif #if 0 { static const char* test = "Text before."; XMLDocument doc; doc.Parse( test ); XMLElement* root = doc.FirstChildElement(); XMLElement* newElement = doc.NewElement( "Subelement" ); root->InsertEndChild( newElement ); doc.Print(); } { XMLDocument* doc = new XMLDocument(); static const char* test = ""; doc->Parse( test ); delete doc; } #endif { // Test: Programmatic DOM // Build: // // // // // With Text! // XMLDocument* doc = new XMLDocument(); XMLNode* element = doc->InsertEndChild( doc->NewElement( "element" ) ); XMLElement* sub[3] = { doc->NewElement( "sub" ), doc->NewElement( "sub" ), doc->NewElement( "sub" ) }; for( int i=0; i<3; ++i ) { sub[i]->SetAttribute( "attrib", i ); } element->InsertEndChild( sub[2] ); XMLNode* comment = element->InsertFirstChild( doc->NewComment( "comment" ) ); element->InsertAfterChild( comment, sub[0] ); element->InsertAfterChild( sub[0], sub[1] ); sub[2]->InsertFirstChild( doc->NewText( "With Text!" )); doc->Print(); delete doc; } #if defined( WIN32 ) _CrtMemCheckpoint( &endMemState ); //_CrtMemDumpStatistics( &endMemState ); _CrtMemState diffMemState; _CrtMemDifference( &diffMemState, &startMemState, &endMemState ); _CrtMemDumpStatistics( &diffMemState ); #endif printf ("\nPass %d, Fail %d\n", gPass, gFail); return 0; }