working with attributes. adding missing methods

This commit is contained in:
Lee Thomason
2012-02-14 18:18:16 -08:00
parent ec5a7b4d18
commit 1ff38e0a5c
3 changed files with 272 additions and 70 deletions

View File

@@ -4,63 +4,63 @@
#include <stdlib.h>
#include <string.h>
#if defined( WIN32 )
#include <crtdbg.h>
_CrtMemState startMemState;
_CrtMemState endMemState;
#endif
#if defined( WIN32 )
#include <crtdbg.h>
_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;
}
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 defined( WIN32 )
_CrtMemCheckpoint( &startMemState );
#endif
#if 0
{
@@ -120,29 +120,40 @@ int main( int argc, const char* argv )
}
#endif
{
// Test: Programmatic DOM
// Build:
// <element>
// <!--comment-->
// <sub attrib="1" />
// <sub attrib="2" />
// <sub attrib="3" />
// <sub attrib="3" >With Text!</sub>
// <element>
XMLDocument* doc = new XMLDocument();
doc->InsertEndChild( doc->NewElement( "element" ) );
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);
#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;
}