U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 1 | #include "tinyxml2.h"
|
| 2 |
|
| 3 | #include <stdio.h>
|
| 4 | #include <stdlib.h>
|
Lee Thomason | ec5a7b4 | 2012-02-13 18:16:52 -0800 | [diff] [blame] | 5 | #include <string.h>
|
Lee Thomason | 6f381b7 | 2012-03-02 12:59:39 -0800 | [diff] [blame] | 6 | #include <time.h>
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 7 |
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 8 | #if defined( _MSC_VER )
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 9 | #include <crtdbg.h>
|
Lee Thomason | 6f381b7 | 2012-03-02 12:59:39 -0800 | [diff] [blame] | 10 | #define WIN32_LEAN_AND_MEAN
|
| 11 | #include <windows.h>
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 12 | _CrtMemState startMemState;
|
| 13 | _CrtMemState endMemState;
|
| 14 | #endif
|
Lee Thomason | e9ecdab | 2012-02-13 18:11:20 -0800 | [diff] [blame] | 15 |
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 16 | using namespace tinyxml2;
|
Lee Thomason | ec5a7b4 | 2012-02-13 18:16:52 -0800 | [diff] [blame] | 17 | int gPass = 0;
|
| 18 | int gFail = 0;
|
| 19 |
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 20 |
|
U-Stream\Lee | 09a11c5 | 2012-02-17 08:31:16 -0800 | [diff] [blame] | 21 | bool XMLTest (const char* testString, const char* expected, const char* found, bool echo=true )
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 22 | {
|
| 23 | bool pass = !strcmp( expected, found );
|
| 24 | if ( pass )
|
| 25 | printf ("[pass]");
|
| 26 | else
|
| 27 | printf ("[fail]");
|
| 28 |
|
U-Stream\Lee | 09a11c5 | 2012-02-17 08:31:16 -0800 | [diff] [blame] | 29 | if ( !echo )
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 30 | printf (" %s\n", testString);
|
| 31 | else
|
| 32 | printf (" %s [%s][%s]\n", testString, expected, found);
|
| 33 |
|
| 34 | if ( pass )
|
| 35 | ++gPass;
|
| 36 | else
|
| 37 | ++gFail;
|
| 38 | return pass;
|
| 39 | }
|
| 40 |
|
| 41 |
|
U-Stream\Lee | 09a11c5 | 2012-02-17 08:31:16 -0800 | [diff] [blame] | 42 | bool XMLTest( const char* testString, int expected, int found, bool echo=true )
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 43 | {
|
| 44 | bool pass = ( expected == found );
|
| 45 | if ( pass )
|
| 46 | printf ("[pass]");
|
| 47 | else
|
| 48 | printf ("[fail]");
|
| 49 |
|
U-Stream\Lee | 09a11c5 | 2012-02-17 08:31:16 -0800 | [diff] [blame] | 50 | if ( !echo )
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 51 | printf (" %s\n", testString);
|
| 52 | else
|
| 53 | printf (" %s [%d][%d]\n", testString, expected, found);
|
| 54 |
|
| 55 | if ( pass )
|
| 56 | ++gPass;
|
| 57 | else
|
| 58 | ++gFail;
|
| 59 | return pass;
|
| 60 | }
|
Lee Thomason | ec5a7b4 | 2012-02-13 18:16:52 -0800 | [diff] [blame] | 61 |
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 62 |
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame] | 63 | void NullLineEndings( char* p )
|
| 64 | {
|
| 65 | while( p && *p ) {
|
| 66 | if ( *p == '\n' || *p == '\r' ) {
|
| 67 | *p = 0;
|
| 68 | return;
|
| 69 | }
|
| 70 | ++p;
|
| 71 | }
|
| 72 | }
|
| 73 |
|
| 74 |
|
Lee Thomason (grinliz) | 9b093cc | 2012-02-25 21:30:18 -0800 | [diff] [blame] | 75 | int main( int /*argc*/, const char* /*argv*/ )
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 76 | {
|
Lee Thomason (grinliz) | 0a4df40 | 2012-02-27 20:50:52 -0800 | [diff] [blame] | 77 | #if defined( _MSC_VER ) && defined( DEBUG )
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 78 | _CrtMemCheckpoint( &startMemState );
|
| 79 | #endif
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 80 |
|
Lee Thomason | 87e475a | 2012-03-20 11:55:29 -0700 | [diff] [blame^] | 81 | /* ------ Example 1: Load and parse an XML file. ---- */
|
| 82 | {
|
| 83 | XMLDocument doc;
|
| 84 | doc.LoadFile( "dream.xml" );
|
| 85 | }
|
| 86 |
|
| 87 | /* ------ Example 2: Lookup information. ---- */
|
| 88 | {
|
| 89 | XMLDocument doc;
|
| 90 | doc.LoadFile( "dream.xml" );
|
| 91 |
|
| 92 | // Structure of the XML file:
|
| 93 | // - Element "PLAY" the root Element
|
| 94 | // - - Element "TITLE" child of the root PLAY Element
|
| 95 | // - - - Text child of the TITLE Element
|
| 96 |
|
| 97 | // Navigate to the title, using the convenience function, with a dangerous lack of error checking.
|
| 98 | const char* title = doc.FirstChildElement( "PLAY" )->FirstChildElement( "TITLE" )->GetText();
|
| 99 | printf( "Name of play (1): %s\n", title );
|
| 100 |
|
| 101 | // Text is just another Node to TinyXML-2. The more general way to get to the XMLText:
|
| 102 | XMLText* textNode = doc.FirstChildElement( "PLAY" )->FirstChildElement( "TITLE" )->FirstChild()->ToText();
|
| 103 | title = textNode->Value();
|
| 104 | printf( "Name of play (2): %s\n", title );
|
| 105 | }
|
| 106 |
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 107 | {
|
Lee Thomason | 43f5930 | 2012-02-06 18:18:11 -0800 | [diff] [blame] | 108 | static const char* test[] = { "<element />",
|
| 109 | "<element></element>",
|
| 110 | "<element><subelement/></element>",
|
| 111 | "<element><subelement></subelement></element>",
|
| 112 | "<element><subelement><subsub/></subelement></element>",
|
| 113 | "<!--comment beside elements--><element><subelement></subelement></element>",
|
| 114 | "<!--comment beside elements, this time with spaces--> \n <element> <subelement> \n </subelement> </element>",
|
| 115 | "<element attrib1='foo' attrib2=\"bar\" ></element>",
|
| 116 | "<element attrib1='foo' attrib2=\"bar\" ><subelement attrib3='yeehaa' /></element>",
|
| 117 | "<element>Text inside element.</element>",
|
| 118 | "<element><b></b></element>",
|
| 119 | "<element>Text inside and <b>bolded</b> in the element.</element>",
|
| 120 | "<outer><element>Text inside and <b>bolded</b> in the element.</element></outer>",
|
Lee Thomason | 8ee7989 | 2012-01-25 17:44:30 -0800 | [diff] [blame] | 121 | "<element>This & That.</element>",
|
Lee Thomason | 18d68bd | 2012-01-26 18:17:26 -0800 | [diff] [blame] | 122 | "<element attrib='This<That' />",
|
Lee Thomason | dadcdfa | 2012-01-18 17:55:48 -0800 | [diff] [blame] | 123 | 0
|
| 124 | };
|
Lee Thomason | 6ee99fc | 2012-01-21 18:45:16 -0800 | [diff] [blame] | 125 | for( int i=0; test[i]; ++i ) {
|
Lee Thomason | dadcdfa | 2012-01-18 17:55:48 -0800 | [diff] [blame] | 126 | XMLDocument doc;
|
Lee Thomason | 6ee99fc | 2012-01-21 18:45:16 -0800 | [diff] [blame] | 127 | doc.Parse( test[i] );
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 128 | doc.Print();
|
Lee Thomason | ec975ce | 2012-01-23 11:42:06 -0800 | [diff] [blame] | 129 | printf( "----------------------------------------------\n" );
|
Lee Thomason | dadcdfa | 2012-01-18 17:55:48 -0800 | [diff] [blame] | 130 | }
|
U-Lama\Lee | 4cee611 | 2011-12-31 14:58:18 -0800 | [diff] [blame] | 131 | }
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 132 | #if 1
|
Lee Thomason | d627776 | 2012-02-22 16:00:12 -0800 | [diff] [blame] | 133 | {
|
| 134 | static const char* test = "<!--hello world\n"
|
| 135 | " line 2\r"
|
| 136 | " line 3\r\n"
|
| 137 | " line 4\n\r"
|
| 138 | " line 5\r-->";
|
| 139 |
|
| 140 | XMLDocument doc;
|
| 141 | doc.Parse( test );
|
| 142 | doc.Print();
|
| 143 | }
|
| 144 |
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 145 | {
|
| 146 | static const char* test = "<element>Text before.</element>";
|
| 147 | XMLDocument doc;
|
| 148 | doc.Parse( test );
|
| 149 | XMLElement* root = doc.FirstChildElement();
|
| 150 | XMLElement* newElement = doc.NewElement( "Subelement" );
|
| 151 | root->InsertEndChild( newElement );
|
| 152 | doc.Print();
|
| 153 | }
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 154 | {
|
| 155 | XMLDocument* doc = new XMLDocument();
|
| 156 | static const char* test = "<element><sub/></element>";
|
| 157 | doc->Parse( test );
|
| 158 | delete doc;
|
| 159 | }
|
Lee Thomason | e9ecdab | 2012-02-13 18:11:20 -0800 | [diff] [blame] | 160 | {
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 161 | // Test: Programmatic DOM
|
Lee Thomason | ec5a7b4 | 2012-02-13 18:16:52 -0800 | [diff] [blame] | 162 | // Build:
|
| 163 | // <element>
|
| 164 | // <!--comment-->
|
| 165 | // <sub attrib="1" />
|
| 166 | // <sub attrib="2" />
|
U-Stream\Lee | 09a11c5 | 2012-02-17 08:31:16 -0800 | [diff] [blame] | 167 | // <sub attrib="3" >& Text!</sub>
|
Lee Thomason | ec5a7b4 | 2012-02-13 18:16:52 -0800 | [diff] [blame] | 168 | // <element>
|
| 169 |
|
Lee Thomason | e9ecdab | 2012-02-13 18:11:20 -0800 | [diff] [blame] | 170 | XMLDocument* doc = new XMLDocument();
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 171 | XMLNode* element = doc->InsertEndChild( doc->NewElement( "element" ) );
|
| 172 |
|
| 173 | XMLElement* sub[3] = { doc->NewElement( "sub" ), doc->NewElement( "sub" ), doc->NewElement( "sub" ) };
|
| 174 | for( int i=0; i<3; ++i ) {
|
| 175 | sub[i]->SetAttribute( "attrib", i );
|
| 176 | }
|
| 177 | element->InsertEndChild( sub[2] );
|
| 178 | XMLNode* comment = element->InsertFirstChild( doc->NewComment( "comment" ) );
|
| 179 | element->InsertAfterChild( comment, sub[0] );
|
| 180 | element->InsertAfterChild( sub[0], sub[1] );
|
U-Stream\Lee | 09a11c5 | 2012-02-17 08:31:16 -0800 | [diff] [blame] | 181 | sub[2]->InsertFirstChild( doc->NewText( "& Text!" ));
|
Lee Thomason | e9ecdab | 2012-02-13 18:11:20 -0800 | [diff] [blame] | 182 | doc->Print();
|
U-Stream\Lee | 09a11c5 | 2012-02-17 08:31:16 -0800 | [diff] [blame] | 183 | XMLTest( "Programmatic DOM", "comment", doc->FirstChildElement( "element" )->FirstChild()->Value() );
|
| 184 | XMLTest( "Programmatic DOM", "0", doc->FirstChildElement( "element" )->FirstChildElement()->Attribute( "attrib" ) );
|
| 185 | XMLTest( "Programmatic DOM", 2, doc->FirstChildElement()->LastChildElement( "sub" )->IntAttribute( "attrib" ) );
|
| 186 | XMLTest( "Programmatic DOM", "& Text!",
|
| 187 | doc->FirstChildElement()->LastChildElement( "sub" )->FirstChild()->ToText()->Value() );
|
U-Stream\Lee | ae25a44 | 2012-02-17 17:48:16 -0800 | [diff] [blame] | 188 |
|
| 189 | // And now deletion:
|
| 190 | element->DeleteChild( sub[2] );
|
| 191 | doc->DeleteNode( comment );
|
| 192 |
|
| 193 | element->FirstChildElement()->SetAttribute( "attrib", true );
|
| 194 | element->LastChildElement()->DeleteAttribute( "attrib" );
|
| 195 |
|
| 196 | XMLTest( "Programmatic DOM", true, doc->FirstChildElement()->FirstChildElement()->BoolAttribute( "attrib" ) );
|
| 197 | int value = 10;
|
| 198 | int result = doc->FirstChildElement()->LastChildElement()->QueryIntAttribute( "attrib", &value );
|
| 199 | XMLTest( "Programmatic DOM", result, NO_ATTRIBUTE );
|
| 200 | XMLTest( "Programmatic DOM", value, 10 );
|
| 201 |
|
| 202 | doc->Print();
|
| 203 |
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 204 | XMLPrinter streamer;
|
U-Stream\Lee | ae25a44 | 2012-02-17 17:48:16 -0800 | [diff] [blame] | 205 | doc->Print( &streamer );
|
| 206 | printf( "%s", streamer.CStr() );
|
| 207 |
|
Lee Thomason | e9ecdab | 2012-02-13 18:11:20 -0800 | [diff] [blame] | 208 | delete doc;
|
| 209 | }
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 210 | {
|
| 211 | // Test: Dream
|
| 212 | // XML1 : 1,187,569 bytes in 31,209 allocations
|
| 213 | // XML2 : 469,073 bytes in 323 allocations
|
| 214 | //int newStart = gNew;
|
| 215 | XMLDocument doc;
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame] | 216 | doc.LoadFile( "dream.xml" );
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 217 |
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame] | 218 | doc.SaveFile( "dreamout.xml" );
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 219 | doc.PrintError();
|
| 220 |
|
| 221 | XMLTest( "Dream", "xml version=\"1.0\"",
|
| 222 | doc.FirstChild()->ToDeclaration()->Value() );
|
| 223 | XMLTest( "Dream", true, doc.FirstChild()->NextSibling()->ToUnknown() ? true : false );
|
| 224 | XMLTest( "Dream", "DOCTYPE PLAY SYSTEM \"play.dtd\"",
|
| 225 | doc.FirstChild()->NextSibling()->ToUnknown()->Value() );
|
| 226 | XMLTest( "Dream", "And Robin shall restore amends.",
|
| 227 | doc.LastChild()->LastChild()->LastChild()->LastChild()->LastChildElement()->GetText() );
|
| 228 | XMLTest( "Dream", "And Robin shall restore amends.",
|
| 229 | doc.LastChild()->LastChild()->LastChild()->LastChild()->LastChildElement()->GetText() );
|
| 230 |
|
| 231 | XMLDocument doc2;
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame] | 232 | doc2.LoadFile( "dreamout.xml" );
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 233 | XMLTest( "Dream-out", "xml version=\"1.0\"",
|
| 234 | doc2.FirstChild()->ToDeclaration()->Value() );
|
| 235 | XMLTest( "Dream-out", true, doc2.FirstChild()->NextSibling()->ToUnknown() ? true : false );
|
| 236 | XMLTest( "Dream-out", "DOCTYPE PLAY SYSTEM \"play.dtd\"",
|
| 237 | doc2.FirstChild()->NextSibling()->ToUnknown()->Value() );
|
| 238 | XMLTest( "Dream-out", "And Robin shall restore amends.",
|
| 239 | doc2.LastChild()->LastChild()->LastChild()->LastChild()->LastChildElement()->GetText() );
|
| 240 |
|
| 241 | //gNewTotal = gNew - newStart;
|
| 242 | }
|
Lee Thomason | 6f381b7 | 2012-03-02 12:59:39 -0800 | [diff] [blame] | 243 |
|
| 244 |
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame] | 245 | {
|
| 246 | const char* error = "<?xml version=\"1.0\" standalone=\"no\" ?>\n"
|
| 247 | "<passages count=\"006\" formatversion=\"20020620\">\n"
|
| 248 | " <wrong error>\n"
|
| 249 | "</passages>";
|
| 250 |
|
| 251 | XMLDocument doc;
|
| 252 | doc.Parse( error );
|
| 253 | XMLTest( "Bad XML", doc.ErrorID(), ERROR_PARSING_ATTRIBUTE );
|
| 254 | }
|
| 255 |
|
| 256 | {
|
| 257 | const char* str = "<doc attr0='1' attr1='2.0' attr2='foo' />";
|
| 258 |
|
| 259 | XMLDocument doc;
|
| 260 | doc.Parse( str );
|
| 261 |
|
| 262 | XMLElement* ele = doc.FirstChildElement();
|
| 263 |
|
| 264 | int iVal, result;
|
| 265 | double dVal;
|
| 266 |
|
| 267 | result = ele->QueryDoubleAttribute( "attr0", &dVal );
|
| 268 | XMLTest( "Query attribute: int as double", result, XML_NO_ERROR );
|
| 269 | XMLTest( "Query attribute: int as double", (int)dVal, 1 );
|
| 270 | result = ele->QueryDoubleAttribute( "attr1", &dVal );
|
| 271 | XMLTest( "Query attribute: double as double", (int)dVal, 2 );
|
| 272 | result = ele->QueryIntAttribute( "attr1", &iVal );
|
| 273 | XMLTest( "Query attribute: double as int", result, XML_NO_ERROR );
|
| 274 | XMLTest( "Query attribute: double as int", iVal, 2 );
|
| 275 | result = ele->QueryIntAttribute( "attr2", &iVal );
|
| 276 | XMLTest( "Query attribute: not a number", result, WRONG_ATTRIBUTE_TYPE );
|
| 277 | result = ele->QueryIntAttribute( "bar", &iVal );
|
| 278 | XMLTest( "Query attribute: does not exist", result, NO_ATTRIBUTE );
|
| 279 | }
|
| 280 |
|
| 281 | {
|
| 282 | const char* str = "<doc/>";
|
| 283 |
|
| 284 | XMLDocument doc;
|
| 285 | doc.Parse( str );
|
| 286 |
|
| 287 | XMLElement* ele = doc.FirstChildElement();
|
| 288 |
|
| 289 | int iVal;
|
| 290 | double dVal;
|
| 291 |
|
| 292 | ele->SetAttribute( "str", "strValue" );
|
| 293 | ele->SetAttribute( "int", 1 );
|
| 294 | ele->SetAttribute( "double", -1.0 );
|
| 295 |
|
| 296 | const char* cStr = ele->Attribute( "str" );
|
| 297 | ele->QueryIntAttribute( "int", &iVal );
|
| 298 | ele->QueryDoubleAttribute( "double", &dVal );
|
| 299 |
|
| 300 | XMLTest( "Attribute round trip. c-string.", "strValue", cStr );
|
| 301 | XMLTest( "Attribute round trip. int.", 1, iVal );
|
| 302 | XMLTest( "Attribute round trip. double.", -1, (int)dVal );
|
| 303 | }
|
| 304 |
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame] | 305 | {
|
| 306 | XMLDocument doc;
|
| 307 | doc.LoadFile( "utf8test.xml" );
|
| 308 |
|
| 309 | // Get the attribute "value" from the "Russian" element and check it.
|
| 310 | XMLElement* element = doc.FirstChildElement( "document" )->FirstChildElement( "Russian" );
|
| 311 | const unsigned char correctValue[] = { 0xd1U, 0x86U, 0xd0U, 0xb5U, 0xd0U, 0xbdU, 0xd0U, 0xbdU,
|
| 312 | 0xd0U, 0xbeU, 0xd1U, 0x81U, 0xd1U, 0x82U, 0xd1U, 0x8cU, 0 };
|
| 313 |
|
| 314 | XMLTest( "UTF-8: Russian value.", (const char*)correctValue, element->Attribute( "value" ) );
|
| 315 |
|
| 316 | const unsigned char russianElementName[] = { 0xd0U, 0xa0U, 0xd1U, 0x83U,
|
| 317 | 0xd1U, 0x81U, 0xd1U, 0x81U,
|
| 318 | 0xd0U, 0xbaU, 0xd0U, 0xb8U,
|
| 319 | 0xd0U, 0xb9U, 0 };
|
| 320 | const char russianText[] = "<\xD0\xB8\xD0\xBC\xD0\xB5\xD0\xB5\xD1\x82>";
|
| 321 |
|
| 322 | XMLText* text = doc.FirstChildElement( "document" )->FirstChildElement( (const char*) russianElementName )->FirstChild()->ToText();
|
| 323 | XMLTest( "UTF-8: Browsing russian element name.",
|
| 324 | russianText,
|
| 325 | text->Value() );
|
| 326 |
|
| 327 | // Now try for a round trip.
|
| 328 | doc.SaveFile( "utf8testout.xml" );
|
| 329 |
|
| 330 | // Check the round trip.
|
| 331 | char savedBuf[256];
|
| 332 | char verifyBuf[256];
|
| 333 | int okay = 0;
|
| 334 |
|
Lee Thomason (grinliz) | 5ce4d97 | 2012-02-26 21:14:23 -0800 | [diff] [blame] | 335 |
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 336 | #if defined(_MSC_VER)
|
Lee Thomason (grinliz) | 5ce4d97 | 2012-02-26 21:14:23 -0800 | [diff] [blame] | 337 | #pragma warning ( push )
|
| 338 | #pragma warning ( disable : 4996 ) // Fail to see a compelling reason why this should be deprecated.
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 339 | #endif
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame] | 340 | FILE* saved = fopen( "utf8testout.xml", "r" );
|
| 341 | FILE* verify = fopen( "utf8testverify.xml", "r" );
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 342 | #if defined(_MSC_VER)
|
Lee Thomason (grinliz) | 5ce4d97 | 2012-02-26 21:14:23 -0800 | [diff] [blame] | 343 | #pragma warning ( pop )
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 344 | #endif
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame] | 345 |
|
| 346 | if ( saved && verify )
|
| 347 | {
|
| 348 | okay = 1;
|
| 349 | while ( fgets( verifyBuf, 256, verify ) )
|
| 350 | {
|
| 351 | fgets( savedBuf, 256, saved );
|
| 352 | NullLineEndings( verifyBuf );
|
| 353 | NullLineEndings( savedBuf );
|
| 354 |
|
| 355 | if ( strcmp( verifyBuf, savedBuf ) )
|
| 356 | {
|
| 357 | printf( "verify:%s<\n", verifyBuf );
|
| 358 | printf( "saved :%s<\n", savedBuf );
|
| 359 | okay = 0;
|
| 360 | break;
|
| 361 | }
|
| 362 | }
|
| 363 | }
|
| 364 | if ( saved )
|
| 365 | fclose( saved );
|
| 366 | if ( verify )
|
| 367 | fclose( verify );
|
| 368 | XMLTest( "UTF-8: Verified multi-language round trip.", 1, okay );
|
| 369 | }
|
| 370 |
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 371 | // --------GetText()-----------
|
| 372 | {
|
| 373 | const char* str = "<foo>This is text</foo>";
|
| 374 | XMLDocument doc;
|
| 375 | doc.Parse( str );
|
| 376 | const XMLElement* element = doc.RootElement();
|
| 377 |
|
| 378 | XMLTest( "GetText() normal use.", "This is text", element->GetText() );
|
| 379 |
|
| 380 | str = "<foo><b>This is text</b></foo>";
|
| 381 | doc.Parse( str );
|
| 382 | element = doc.RootElement();
|
| 383 |
|
| 384 | XMLTest( "GetText() contained element.", element->GetText() == 0, true );
|
| 385 | }
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame] | 386 |
|
Lee Thomason | d627776 | 2012-02-22 16:00:12 -0800 | [diff] [blame] | 387 |
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 388 | // ---------- CDATA ---------------
|
| 389 | {
|
| 390 | const char* str = "<xmlElement>"
|
| 391 | "<![CDATA["
|
| 392 | "I am > the rules!\n"
|
| 393 | "...since I make symbolic puns"
|
| 394 | "]]>"
|
| 395 | "</xmlElement>";
|
| 396 | XMLDocument doc;
|
| 397 | doc.Parse( str );
|
| 398 | doc.Print();
|
Lee Thomason | d627776 | 2012-02-22 16:00:12 -0800 | [diff] [blame] | 399 |
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 400 | XMLTest( "CDATA parse.", doc.FirstChildElement()->FirstChild()->Value(),
|
| 401 | "I am > the rules!\n...since I make symbolic puns",
|
Lee Thomason | d627776 | 2012-02-22 16:00:12 -0800 | [diff] [blame] | 402 | false );
|
| 403 | }
|
| 404 |
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 405 | // ----------- CDATA -------------
|
| 406 | {
|
| 407 | const char* str = "<xmlElement>"
|
| 408 | "<![CDATA["
|
| 409 | "<b>I am > the rules!</b>\n"
|
| 410 | "...since I make symbolic puns"
|
| 411 | "]]>"
|
| 412 | "</xmlElement>";
|
| 413 | XMLDocument doc;
|
| 414 | doc.Parse( str );
|
| 415 | doc.Print();
|
| 416 |
|
| 417 | XMLTest( "CDATA parse. [ tixml1:1480107 ]", doc.FirstChildElement()->FirstChild()->Value(),
|
| 418 | "<b>I am > the rules!</b>\n...since I make symbolic puns",
|
| 419 | false );
|
| 420 | }
|
| 421 |
|
| 422 | // InsertAfterChild causes crash.
|
| 423 | {
|
| 424 | // InsertBeforeChild and InsertAfterChild causes crash.
|
| 425 | XMLDocument doc;
|
| 426 | XMLElement* parent = doc.NewElement( "Parent" );
|
| 427 | doc.InsertFirstChild( parent );
|
| 428 |
|
| 429 | XMLElement* childText0 = doc.NewElement( "childText0" );
|
| 430 | XMLElement* childText1 = doc.NewElement( "childText1" );
|
| 431 |
|
| 432 | XMLNode* childNode0 = parent->InsertEndChild( childText0 );
|
| 433 | XMLNode* childNode1 = parent->InsertAfterChild( childNode0, childText1 );
|
| 434 |
|
| 435 | XMLTest( "Test InsertAfterChild on empty node. ", ( childNode1 == parent->LastChild() ), true );
|
| 436 | }
|
Lee Thomason | d627776 | 2012-02-22 16:00:12 -0800 | [diff] [blame] | 437 |
|
| 438 | {
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 439 | // Entities not being written correctly.
|
| 440 | // From Lynn Allen
|
Lee Thomason | d627776 | 2012-02-22 16:00:12 -0800 | [diff] [blame] | 441 |
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 442 | const char* passages =
|
| 443 | "<?xml version=\"1.0\" standalone=\"no\" ?>"
|
| 444 | "<passages count=\"006\" formatversion=\"20020620\">"
|
| 445 | "<psg context=\"Line 5 has "quotation marks" and 'apostrophe marks'."
|
| 446 | " It also has <, >, and &, as well as a fake copyright ©.\"> </psg>"
|
| 447 | "</passages>";
|
Lee Thomason | d627776 | 2012-02-22 16:00:12 -0800 | [diff] [blame] | 448 |
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 449 | XMLDocument doc;
|
| 450 | doc.Parse( passages );
|
| 451 | XMLElement* psg = doc.RootElement()->FirstChildElement();
|
| 452 | const char* context = psg->Attribute( "context" );
|
| 453 | const char* expected = "Line 5 has \"quotation marks\" and 'apostrophe marks'. It also has <, >, and &, as well as a fake copyright \xC2\xA9.";
|
Lee Thomason | d627776 | 2012-02-22 16:00:12 -0800 | [diff] [blame] | 454 |
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 455 | XMLTest( "Entity transformation: read. ", expected, context, true );
|
Lee Thomason | d627776 | 2012-02-22 16:00:12 -0800 | [diff] [blame] | 456 |
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 457 | #if defined(_MSC_VER)
|
Lee Thomason (grinliz) | 5ce4d97 | 2012-02-26 21:14:23 -0800 | [diff] [blame] | 458 | #pragma warning ( push )
|
| 459 | #pragma warning ( disable : 4996 ) // Fail to see a compelling reason why this should be deprecated.
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 460 | #endif
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 461 | FILE* textfile = fopen( "textfile.txt", "w" );
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 462 | #if defined(_MSC_VER)
|
Lee Thomason (grinliz) | 5ce4d97 | 2012-02-26 21:14:23 -0800 | [diff] [blame] | 463 | #pragma warning ( pop )
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 464 | #endif
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 465 | if ( textfile )
|
| 466 | {
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 467 | XMLPrinter streamer( textfile );
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 468 | psg->Accept( &streamer );
|
| 469 | fclose( textfile );
|
| 470 | }
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 471 | #if defined(_MSC_VER)
|
Lee Thomason (grinliz) | 5ce4d97 | 2012-02-26 21:14:23 -0800 | [diff] [blame] | 472 | #pragma warning ( push )
|
| 473 | #pragma warning ( disable : 4996 ) // Fail to see a compelling reason why this should be deprecated.
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 474 | #endif
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 475 | textfile = fopen( "textfile.txt", "r" );
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 476 | #if defined(_MSC_VER)
|
Lee Thomason (grinliz) | 5ce4d97 | 2012-02-26 21:14:23 -0800 | [diff] [blame] | 477 | #pragma warning ( pop )
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 478 | #endif
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 479 | TIXMLASSERT( textfile );
|
| 480 | if ( textfile )
|
| 481 | {
|
| 482 | char buf[ 1024 ];
|
| 483 | fgets( buf, 1024, textfile );
|
| 484 | XMLTest( "Entity transformation: write. ",
|
| 485 | "<psg context=\"Line 5 has "quotation marks" and 'apostrophe marks'."
|
| 486 | " It also has <, >, and &, as well as a fake copyright \xC2\xA9.\"/>\n",
|
| 487 | buf, false );
|
| 488 | }
|
| 489 | fclose( textfile );
|
| 490 | }
|
| 491 |
|
| 492 | {
|
Lee Thomason | 6f381b7 | 2012-03-02 12:59:39 -0800 | [diff] [blame] | 493 | // Suppress entities.
|
| 494 | const char* passages =
|
| 495 | "<?xml version=\"1.0\" standalone=\"no\" ?>"
|
| 496 | "<passages count=\"006\" formatversion=\"20020620\">"
|
| 497 | "<psg context=\"Line 5 has "quotation marks" and 'apostrophe marks'.\">Crazy &ttk;</psg>"
|
| 498 | "</passages>";
|
| 499 |
|
| 500 | XMLDocument doc( false );
|
| 501 | doc.Parse( passages );
|
| 502 |
|
| 503 | XMLTest( "No entity parsing.", doc.FirstChildElement()->FirstChildElement()->Attribute( "context" ),
|
| 504 | "Line 5 has "quotation marks" and 'apostrophe marks'." );
|
| 505 | XMLTest( "No entity parsing.", doc.FirstChildElement()->FirstChildElement()->FirstChild()->Value(),
|
| 506 | "Crazy &ttk;" );
|
| 507 | doc.Print();
|
| 508 | }
|
| 509 |
|
| 510 | {
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 511 | const char* test = "<?xml version='1.0'?><a.elem xmi.version='2.0'/>";
|
| 512 |
|
| 513 | XMLDocument doc;
|
| 514 | doc.Parse( test );
|
| 515 | XMLTest( "dot in names", doc.Error(), 0);
|
| 516 | XMLTest( "dot in names", doc.FirstChildElement()->Name(), "a.elem" );
|
| 517 | XMLTest( "dot in names", doc.FirstChildElement()->Attribute( "xmi.version" ), "2.0" );
|
| 518 | }
|
| 519 |
|
| 520 | {
|
| 521 | const char* test = "<element><Name>1.1 Start easy ignore fin thickness
</Name></element>";
|
| 522 |
|
| 523 | XMLDocument doc;
|
| 524 | doc.Parse( test );
|
| 525 |
|
| 526 | XMLText* text = doc.FirstChildElement()->FirstChildElement()->FirstChild()->ToText();
|
| 527 | XMLTest( "Entity with one digit.",
|
| 528 | text->Value(), "1.1 Start easy ignore fin thickness\n",
|
| 529 | false );
|
| 530 | }
|
| 531 |
|
| 532 | {
|
| 533 | // DOCTYPE not preserved (950171)
|
| 534 | //
|
| 535 | const char* doctype =
|
| 536 | "<?xml version=\"1.0\" ?>"
|
| 537 | "<!DOCTYPE PLAY SYSTEM 'play.dtd'>"
|
| 538 | "<!ELEMENT title (#PCDATA)>"
|
| 539 | "<!ELEMENT books (title,authors)>"
|
| 540 | "<element />";
|
| 541 |
|
| 542 | XMLDocument doc;
|
| 543 | doc.Parse( doctype );
|
| 544 | doc.SaveFile( "test7.xml" );
|
| 545 | doc.DeleteChild( doc.RootElement() );
|
| 546 | doc.LoadFile( "test7.xml" );
|
| 547 | doc.Print();
|
| 548 |
|
| 549 | const XMLUnknown* decl = doc.FirstChild()->NextSibling()->ToUnknown();
|
| 550 | XMLTest( "Correct value of unknown.", "DOCTYPE PLAY SYSTEM 'play.dtd'", decl->Value() );
|
| 551 |
|
| 552 | }
|
| 553 |
|
| 554 | {
|
| 555 | // Comments do not stream out correctly.
|
| 556 | const char* doctype =
|
| 557 | "<!-- Somewhat<evil> -->";
|
| 558 | XMLDocument doc;
|
| 559 | doc.Parse( doctype );
|
| 560 |
|
| 561 | XMLComment* comment = doc.FirstChild()->ToComment();
|
| 562 |
|
| 563 | XMLTest( "Comment formatting.", " Somewhat<evil> ", comment->Value() );
|
| 564 | }
|
| 565 | {
|
| 566 | // Double attributes
|
| 567 | const char* doctype = "<element attr='red' attr='blue' />";
|
| 568 |
|
| 569 | XMLDocument doc;
|
| 570 | doc.Parse( doctype );
|
| 571 |
|
| 572 | XMLTest( "Parsing repeated attributes.", ERROR_PARSING_ATTRIBUTE, doc.ErrorID() ); // is an error to tinyxml (didn't use to be, but caused issues)
|
Lee Thomason (grinliz) | 0a4df40 | 2012-02-27 20:50:52 -0800 | [diff] [blame] | 573 | doc.PrintError();
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 574 | }
|
| 575 |
|
| 576 | {
|
| 577 | // Embedded null in stream.
|
| 578 | const char* doctype = "<element att\0r='red' attr='blue' />";
|
| 579 |
|
| 580 | XMLDocument doc;
|
| 581 | doc.Parse( doctype );
|
| 582 | XMLTest( "Embedded null throws error.", true, doc.Error() );
|
| 583 | }
|
| 584 |
|
| 585 | {
|
| 586 | // Empty documents should return TIXML_ERROR_PARSING_EMPTY, bug 1070717
|
| 587 | const char* str = " ";
|
| 588 | XMLDocument doc;
|
| 589 | doc.Parse( str );
|
| 590 | XMLTest( "Empty document error", ERROR_EMPTY_DOCUMENT, doc.ErrorID() );
|
| 591 | }
|
| 592 |
|
| 593 | {
|
| 594 | // Low entities
|
| 595 | XMLDocument doc;
|
| 596 | doc.Parse( "<test></test>" );
|
| 597 | const char result[] = { 0x0e, 0 };
|
| 598 | XMLTest( "Low entities.", doc.FirstChildElement()->GetText(), result );
|
| 599 | doc.Print();
|
| 600 | }
|
| 601 |
|
| 602 | {
|
| 603 | // Attribute values with trailing quotes not handled correctly
|
| 604 | XMLDocument doc;
|
| 605 | doc.Parse( "<foo attribute=bar\" />" );
|
| 606 | XMLTest( "Throw error with bad end quotes.", doc.Error(), true );
|
| 607 | }
|
| 608 |
|
| 609 | {
|
| 610 | // [ 1663758 ] Failure to report error on bad XML
|
| 611 | XMLDocument xml;
|
| 612 | xml.Parse("<x>");
|
| 613 | XMLTest("Missing end tag at end of input", xml.Error(), true);
|
| 614 | xml.Parse("<x> ");
|
| 615 | XMLTest("Missing end tag with trailing whitespace", xml.Error(), true);
|
| 616 | xml.Parse("<x></y>");
|
| 617 | XMLTest("Mismatched tags", xml.ErrorID(), ERROR_MISMATCHED_ELEMENT);
|
| 618 | }
|
| 619 |
|
| 620 |
|
| 621 | {
|
| 622 | // [ 1475201 ] TinyXML parses entities in comments
|
| 623 | XMLDocument xml;
|
| 624 | xml.Parse("<!-- declarations for <head> & <body> -->"
|
| 625 | "<!-- far & away -->" );
|
| 626 |
|
| 627 | XMLNode* e0 = xml.FirstChild();
|
| 628 | XMLNode* e1 = e0->NextSibling();
|
| 629 | XMLComment* c0 = e0->ToComment();
|
| 630 | XMLComment* c1 = e1->ToComment();
|
| 631 |
|
| 632 | XMLTest( "Comments ignore entities.", " declarations for <head> & <body> ", c0->Value(), true );
|
| 633 | XMLTest( "Comments ignore entities.", " far & away ", c1->Value(), true );
|
| 634 | }
|
| 635 |
|
| 636 | {
|
| 637 | XMLDocument xml;
|
| 638 | xml.Parse( "<Parent>"
|
| 639 | "<child1 att=''/>"
|
| 640 | "<!-- With this comment, child2 will not be parsed! -->"
|
| 641 | "<child2 att=''/>"
|
| 642 | "</Parent>" );
|
| 643 | xml.Print();
|
| 644 |
|
| 645 | int count = 0;
|
| 646 |
|
| 647 | for( XMLNode* ele = xml.FirstChildElement( "Parent" )->FirstChild();
|
| 648 | ele;
|
| 649 | ele = ele->NextSibling() )
|
| 650 | {
|
| 651 | ++count;
|
| 652 | }
|
| 653 |
|
| 654 | XMLTest( "Comments iterate correctly.", 3, count );
|
| 655 | }
|
| 656 |
|
| 657 | {
|
| 658 | // trying to repro ]1874301]. If it doesn't go into an infinite loop, all is well.
|
| 659 | unsigned char buf[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?><feed><![CDATA[Test XMLblablablalblbl";
|
| 660 | buf[60] = 239;
|
| 661 | buf[61] = 0;
|
| 662 |
|
| 663 | XMLDocument doc;
|
| 664 | doc.Parse( (const char*)buf);
|
| 665 | }
|
| 666 |
|
| 667 |
|
| 668 | {
|
| 669 | // bug 1827248 Error while parsing a little bit malformed file
|
| 670 | // Actually not malformed - should work.
|
| 671 | XMLDocument xml;
|
| 672 | xml.Parse( "<attributelist> </attributelist >" );
|
| 673 | XMLTest( "Handle end tag whitespace", false, xml.Error() );
|
| 674 | }
|
| 675 |
|
| 676 | {
|
| 677 | // This one must not result in an infinite loop
|
| 678 | XMLDocument xml;
|
| 679 | xml.Parse( "<infinite>loop" );
|
| 680 | XMLTest( "Infinite loop test.", true, true );
|
| 681 | }
|
| 682 | #endif
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 683 | {
|
| 684 | const char* pub = "<?xml version='1.0'?> <element><sub/></element> <!--comment--> <!DOCTYPE>";
|
| 685 | XMLDocument doc;
|
| 686 | doc.Parse( pub );
|
| 687 |
|
| 688 | XMLDocument clone;
|
| 689 | for( const XMLNode* node=doc.FirstChild(); node; node=node->NextSibling() ) {
|
| 690 | XMLNode* copy = node->ShallowClone( &clone );
|
| 691 | clone.InsertEndChild( copy );
|
| 692 | }
|
| 693 |
|
| 694 | clone.Print();
|
| 695 |
|
| 696 | int count=0;
|
| 697 | const XMLNode* a=clone.FirstChild();
|
| 698 | const XMLNode* b=doc.FirstChild();
|
| 699 | for( ; a && b; a=a->NextSibling(), b=b->NextSibling() ) {
|
| 700 | ++count;
|
| 701 | XMLTest( "Clone and Equal", true, a->ShallowEqual( b ));
|
| 702 | }
|
| 703 | XMLTest( "Clone and Equal", 4, count );
|
| 704 | }
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 705 |
|
Lee Thomason | 6f381b7 | 2012-03-02 12:59:39 -0800 | [diff] [blame] | 706 | // ----------- Performance tracking --------------
|
| 707 | {
|
| 708 | #if defined( _MSC_VER )
|
| 709 | __int64 start, end, freq;
|
| 710 | QueryPerformanceFrequency( (LARGE_INTEGER*) &freq );
|
| 711 | #endif
|
| 712 |
|
| 713 | #if defined(_MSC_VER)
|
| 714 | #pragma warning ( push )
|
| 715 | #pragma warning ( disable : 4996 ) // Fail to see a compelling reason why this should be deprecated.
|
| 716 | #endif
|
| 717 | FILE* fp = fopen( "dream.xml", "r" );
|
| 718 | #if defined(_MSC_VER)
|
| 719 | #pragma warning ( pop )
|
| 720 | #endif
|
| 721 | fseek( fp, 0, SEEK_END );
|
| 722 | long size = ftell( fp );
|
| 723 | fseek( fp, 0, SEEK_SET );
|
| 724 |
|
| 725 | char* mem = new char[size+1];
|
| 726 | fread( mem, size, 1, fp );
|
| 727 | fclose( fp );
|
| 728 | mem[size] = 0;
|
| 729 |
|
| 730 | #if defined( _MSC_VER )
|
| 731 | QueryPerformanceCounter( (LARGE_INTEGER*) &start );
|
| 732 | #else
|
| 733 | clock_t cstart = clock();
|
| 734 | #endif
|
| 735 | static const int COUNT = 10;
|
| 736 | for( int i=0; i<COUNT; ++i ) {
|
| 737 | XMLDocument doc;
|
| 738 | doc.Parse( mem );
|
| 739 | }
|
| 740 | #if defined( _MSC_VER )
|
| 741 | QueryPerformanceCounter( (LARGE_INTEGER*) &end );
|
| 742 | #else
|
| 743 | clock_t cend = clock();
|
| 744 | #endif
|
| 745 |
|
| 746 | delete [] mem;
|
| 747 |
|
| 748 | static const char* note =
|
| 749 | #ifdef DEBUG
|
| 750 | "DEBUG";
|
| 751 | #else
|
| 752 | "Release";
|
| 753 | #endif
|
| 754 |
|
| 755 | #if defined( _MSC_VER )
|
| 756 | printf( "\nParsing %s of dream.xml: %.3f milli-seconds\n", note, 1000.0 * (double)(end-start) / ( (double)freq * (double)COUNT) );
|
| 757 | #else
|
| 758 | printf( "\nParsing %s of dream.xml: %.3f milli-seconds\n", note, (double)(cend - cstart)/(double)COUNT );
|
| 759 | #endif
|
| 760 | }
|
| 761 |
|
Lee Thomason (grinliz) | 7ca5558 | 2012-03-07 21:54:57 -0800 | [diff] [blame] | 762 | #if defined( _MSC_VER ) && defined( DEBUG )
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 763 | _CrtMemCheckpoint( &endMemState );
|
| 764 | //_CrtMemDumpStatistics( &endMemState );
|
| 765 |
|
| 766 | _CrtMemState diffMemState;
|
| 767 | _CrtMemDifference( &diffMemState, &startMemState, &endMemState );
|
| 768 | _CrtMemDumpStatistics( &diffMemState );
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 769 | //printf( "new total=%d\n", gNewTotal );
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 770 | #endif
|
| 771 |
|
| 772 | printf ("\nPass %d, Fail %d\n", gPass, gFail);
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 773 | return 0;
|
Lee Thomason (grinliz) | 9b093cc | 2012-02-25 21:30:18 -0800 | [diff] [blame] | 774 | }
|