xmltest.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. #include "tinyxml2.h"
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #if defined( WIN32 )
  6. #include <crtdbg.h>
  7. _CrtMemState startMemState;
  8. _CrtMemState endMemState;
  9. #endif
  10. using namespace tinyxml2;
  11. int gPass = 0;
  12. int gFail = 0;
  13. //#define DREAM_ONLY
  14. /*
  15. int gNew = 0;
  16. int gNewTotal = 0;
  17. void* operator new( size_t size )
  18. {
  19. ++gNew;
  20. return malloc( size );
  21. }
  22. void* operator new[]( size_t size )
  23. {
  24. ++gNew;
  25. return malloc( size );
  26. }
  27. void operator delete[]( void* mem )
  28. {
  29. free( mem );
  30. }
  31. void operator delete( void* mem )
  32. {
  33. free( mem );
  34. }
  35. */
  36. bool XMLTest (const char* testString, const char* expected, const char* found, bool echo=true )
  37. {
  38. bool pass = !strcmp( expected, found );
  39. if ( pass )
  40. printf ("[pass]");
  41. else
  42. printf ("[fail]");
  43. if ( !echo )
  44. printf (" %s\n", testString);
  45. else
  46. printf (" %s [%s][%s]\n", testString, expected, found);
  47. if ( pass )
  48. ++gPass;
  49. else
  50. ++gFail;
  51. return pass;
  52. }
  53. bool XMLTest( const char* testString, int expected, int found, bool echo=true )
  54. {
  55. bool pass = ( expected == found );
  56. if ( pass )
  57. printf ("[pass]");
  58. else
  59. printf ("[fail]");
  60. if ( !echo )
  61. printf (" %s\n", testString);
  62. else
  63. printf (" %s [%d][%d]\n", testString, expected, found);
  64. if ( pass )
  65. ++gPass;
  66. else
  67. ++gFail;
  68. return pass;
  69. }
  70. void NullLineEndings( char* p )
  71. {
  72. while( p && *p ) {
  73. if ( *p == '\n' || *p == '\r' ) {
  74. *p = 0;
  75. return;
  76. }
  77. ++p;
  78. }
  79. }
  80. int main( int argc, const char* argv )
  81. {
  82. #if defined( WIN32 )
  83. _CrtMemCheckpoint( &startMemState );
  84. #endif
  85. {
  86. static const char* test[] = { "<element />",
  87. "<element></element>",
  88. "<element><subelement/></element>",
  89. "<element><subelement></subelement></element>",
  90. "<element><subelement><subsub/></subelement></element>",
  91. "<!--comment beside elements--><element><subelement></subelement></element>",
  92. "<!--comment beside elements, this time with spaces--> \n <element> <subelement> \n </subelement> </element>",
  93. "<element attrib1='foo' attrib2=\"bar\" ></element>",
  94. "<element attrib1='foo' attrib2=\"bar\" ><subelement attrib3='yeehaa' /></element>",
  95. "<element>Text inside element.</element>",
  96. "<element><b></b></element>",
  97. "<element>Text inside and <b>bolded</b> in the element.</element>",
  98. "<outer><element>Text inside and <b>bolded</b> in the element.</element></outer>",
  99. "<element>This &amp; That.</element>",
  100. "<element attrib='This&lt;That' />",
  101. 0
  102. };
  103. for( int i=0; test[i]; ++i ) {
  104. XMLDocument doc;
  105. doc.Parse( test[i] );
  106. doc.Print();
  107. printf( "----------------------------------------------\n" );
  108. }
  109. }
  110. {
  111. static const char* test = "<!--hello world\n"
  112. " line 2\r"
  113. " line 3\r\n"
  114. " line 4\n\r"
  115. " line 5\r-->";
  116. XMLDocument doc;
  117. doc.Parse( test );
  118. doc.Print();
  119. }
  120. {
  121. static const char* test = "<element>Text before.</element>";
  122. XMLDocument doc;
  123. doc.Parse( test );
  124. XMLElement* root = doc.FirstChildElement();
  125. XMLElement* newElement = doc.NewElement( "Subelement" );
  126. root->InsertEndChild( newElement );
  127. doc.Print();
  128. }
  129. {
  130. XMLDocument* doc = new XMLDocument();
  131. static const char* test = "<element><sub/></element>";
  132. doc->Parse( test );
  133. delete doc;
  134. }
  135. {
  136. // Test: Programmatic DOM
  137. // Build:
  138. // <element>
  139. // <!--comment-->
  140. // <sub attrib="1" />
  141. // <sub attrib="2" />
  142. // <sub attrib="3" >& Text!</sub>
  143. // <element>
  144. XMLDocument* doc = new XMLDocument();
  145. XMLNode* element = doc->InsertEndChild( doc->NewElement( "element" ) );
  146. XMLElement* sub[3] = { doc->NewElement( "sub" ), doc->NewElement( "sub" ), doc->NewElement( "sub" ) };
  147. for( int i=0; i<3; ++i ) {
  148. sub[i]->SetAttribute( "attrib", i );
  149. }
  150. element->InsertEndChild( sub[2] );
  151. XMLNode* comment = element->InsertFirstChild( doc->NewComment( "comment" ) );
  152. element->InsertAfterChild( comment, sub[0] );
  153. element->InsertAfterChild( sub[0], sub[1] );
  154. sub[2]->InsertFirstChild( doc->NewText( "& Text!" ));
  155. doc->Print();
  156. XMLTest( "Programmatic DOM", "comment", doc->FirstChildElement( "element" )->FirstChild()->Value() );
  157. XMLTest( "Programmatic DOM", "0", doc->FirstChildElement( "element" )->FirstChildElement()->Attribute( "attrib" ) );
  158. XMLTest( "Programmatic DOM", 2, doc->FirstChildElement()->LastChildElement( "sub" )->IntAttribute( "attrib" ) );
  159. XMLTest( "Programmatic DOM", "& Text!",
  160. doc->FirstChildElement()->LastChildElement( "sub" )->FirstChild()->ToText()->Value() );
  161. // And now deletion:
  162. element->DeleteChild( sub[2] );
  163. doc->DeleteNode( comment );
  164. element->FirstChildElement()->SetAttribute( "attrib", true );
  165. element->LastChildElement()->DeleteAttribute( "attrib" );
  166. XMLTest( "Programmatic DOM", true, doc->FirstChildElement()->FirstChildElement()->BoolAttribute( "attrib" ) );
  167. int value = 10;
  168. int result = doc->FirstChildElement()->LastChildElement()->QueryIntAttribute( "attrib", &value );
  169. XMLTest( "Programmatic DOM", result, NO_ATTRIBUTE );
  170. XMLTest( "Programmatic DOM", value, 10 );
  171. doc->Print();
  172. XMLStreamer streamer;
  173. doc->Print( &streamer );
  174. printf( "%s", streamer.CStr() );
  175. delete doc;
  176. }
  177. {
  178. // Test: Dream
  179. // XML1 : 1,187,569 bytes in 31,209 allocations
  180. // XML2 : 469,073 bytes in 323 allocations
  181. //int newStart = gNew;
  182. XMLDocument doc;
  183. doc.LoadFile( "dream.xml" );
  184. doc.SaveFile( "dreamout.xml" );
  185. doc.PrintError();
  186. XMLTest( "Dream", "xml version=\"1.0\"",
  187. doc.FirstChild()->ToDeclaration()->Value() );
  188. XMLTest( "Dream", true, doc.FirstChild()->NextSibling()->ToUnknown() ? true : false );
  189. XMLTest( "Dream", "DOCTYPE PLAY SYSTEM \"play.dtd\"",
  190. doc.FirstChild()->NextSibling()->ToUnknown()->Value() );
  191. XMLTest( "Dream", "And Robin shall restore amends.",
  192. doc.LastChild()->LastChild()->LastChild()->LastChild()->LastChildElement()->GetText() );
  193. XMLTest( "Dream", "And Robin shall restore amends.",
  194. doc.LastChild()->LastChild()->LastChild()->LastChild()->LastChildElement()->GetText() );
  195. XMLDocument doc2;
  196. doc2.LoadFile( "dreamout.xml" );
  197. XMLTest( "Dream-out", "xml version=\"1.0\"",
  198. doc2.FirstChild()->ToDeclaration()->Value() );
  199. XMLTest( "Dream-out", true, doc2.FirstChild()->NextSibling()->ToUnknown() ? true : false );
  200. XMLTest( "Dream-out", "DOCTYPE PLAY SYSTEM \"play.dtd\"",
  201. doc2.FirstChild()->NextSibling()->ToUnknown()->Value() );
  202. XMLTest( "Dream-out", "And Robin shall restore amends.",
  203. doc2.LastChild()->LastChild()->LastChild()->LastChild()->LastChildElement()->GetText() );
  204. //gNewTotal = gNew - newStart;
  205. }
  206. {
  207. const char* error = "<?xml version=\"1.0\" standalone=\"no\" ?>\n"
  208. "<passages count=\"006\" formatversion=\"20020620\">\n"
  209. " <wrong error>\n"
  210. "</passages>";
  211. XMLDocument doc;
  212. doc.Parse( error );
  213. XMLTest( "Bad XML", doc.ErrorID(), ERROR_PARSING_ATTRIBUTE );
  214. }
  215. {
  216. const char* str = "<doc attr0='1' attr1='2.0' attr2='foo' />";
  217. XMLDocument doc;
  218. doc.Parse( str );
  219. XMLElement* ele = doc.FirstChildElement();
  220. int iVal, result;
  221. double dVal;
  222. result = ele->QueryDoubleAttribute( "attr0", &dVal );
  223. XMLTest( "Query attribute: int as double", result, XML_NO_ERROR );
  224. XMLTest( "Query attribute: int as double", (int)dVal, 1 );
  225. result = ele->QueryDoubleAttribute( "attr1", &dVal );
  226. XMLTest( "Query attribute: double as double", (int)dVal, 2 );
  227. result = ele->QueryIntAttribute( "attr1", &iVal );
  228. XMLTest( "Query attribute: double as int", result, XML_NO_ERROR );
  229. XMLTest( "Query attribute: double as int", iVal, 2 );
  230. result = ele->QueryIntAttribute( "attr2", &iVal );
  231. XMLTest( "Query attribute: not a number", result, WRONG_ATTRIBUTE_TYPE );
  232. result = ele->QueryIntAttribute( "bar", &iVal );
  233. XMLTest( "Query attribute: does not exist", result, NO_ATTRIBUTE );
  234. }
  235. {
  236. const char* str = "<doc/>";
  237. XMLDocument doc;
  238. doc.Parse( str );
  239. XMLElement* ele = doc.FirstChildElement();
  240. int iVal;
  241. double dVal;
  242. ele->SetAttribute( "str", "strValue" );
  243. ele->SetAttribute( "int", 1 );
  244. ele->SetAttribute( "double", -1.0 );
  245. const char* cStr = ele->Attribute( "str" );
  246. ele->QueryIntAttribute( "int", &iVal );
  247. ele->QueryDoubleAttribute( "double", &dVal );
  248. XMLTest( "Attribute round trip. c-string.", "strValue", cStr );
  249. XMLTest( "Attribute round trip. int.", 1, iVal );
  250. XMLTest( "Attribute round trip. double.", -1, (int)dVal );
  251. }
  252. {
  253. XMLDocument doc;
  254. doc.LoadFile( "utf8test.xml" );
  255. // Get the attribute "value" from the "Russian" element and check it.
  256. XMLElement* element = doc.FirstChildElement( "document" )->FirstChildElement( "Russian" );
  257. const unsigned char correctValue[] = { 0xd1U, 0x86U, 0xd0U, 0xb5U, 0xd0U, 0xbdU, 0xd0U, 0xbdU,
  258. 0xd0U, 0xbeU, 0xd1U, 0x81U, 0xd1U, 0x82U, 0xd1U, 0x8cU, 0 };
  259. XMLTest( "UTF-8: Russian value.", (const char*)correctValue, element->Attribute( "value" ) );
  260. const unsigned char russianElementName[] = { 0xd0U, 0xa0U, 0xd1U, 0x83U,
  261. 0xd1U, 0x81U, 0xd1U, 0x81U,
  262. 0xd0U, 0xbaU, 0xd0U, 0xb8U,
  263. 0xd0U, 0xb9U, 0 };
  264. const char russianText[] = "<\xD0\xB8\xD0\xBC\xD0\xB5\xD0\xB5\xD1\x82>";
  265. XMLText* text = doc.FirstChildElement( "document" )->FirstChildElement( (const char*) russianElementName )->FirstChild()->ToText();
  266. XMLTest( "UTF-8: Browsing russian element name.",
  267. russianText,
  268. text->Value() );
  269. // Now try for a round trip.
  270. doc.SaveFile( "utf8testout.xml" );
  271. // Check the round trip.
  272. char savedBuf[256];
  273. char verifyBuf[256];
  274. int okay = 0;
  275. FILE* saved = fopen( "utf8testout.xml", "r" );
  276. FILE* verify = fopen( "utf8testverify.xml", "r" );
  277. if ( saved && verify )
  278. {
  279. okay = 1;
  280. while ( fgets( verifyBuf, 256, verify ) )
  281. {
  282. fgets( savedBuf, 256, saved );
  283. NullLineEndings( verifyBuf );
  284. NullLineEndings( savedBuf );
  285. if ( strcmp( verifyBuf, savedBuf ) )
  286. {
  287. printf( "verify:%s<\n", verifyBuf );
  288. printf( "saved :%s<\n", savedBuf );
  289. okay = 0;
  290. break;
  291. }
  292. }
  293. }
  294. if ( saved )
  295. fclose( saved );
  296. if ( verify )
  297. fclose( verify );
  298. XMLTest( "UTF-8: Verified multi-language round trip.", 1, okay );
  299. }
  300. // --------GetText()-----------
  301. {
  302. const char* str = "<foo>This is text</foo>";
  303. XMLDocument doc;
  304. doc.Parse( str );
  305. const XMLElement* element = doc.RootElement();
  306. XMLTest( "GetText() normal use.", "This is text", element->GetText() );
  307. str = "<foo><b>This is text</b></foo>";
  308. doc.Parse( str );
  309. element = doc.RootElement();
  310. XMLTest( "GetText() contained element.", element->GetText() == 0, true );
  311. }
  312. // ---------- CDATA ---------------
  313. {
  314. const char* str = "<xmlElement>"
  315. "<![CDATA["
  316. "I am > the rules!\n"
  317. "...since I make symbolic puns"
  318. "]]>"
  319. "</xmlElement>";
  320. XMLDocument doc;
  321. doc.Parse( str );
  322. doc.Print();
  323. XMLTest( "CDATA parse.", doc.FirstChildElement()->FirstChild()->Value(),
  324. "I am > the rules!\n...since I make symbolic puns",
  325. false );
  326. }
  327. // ----------- CDATA -------------
  328. {
  329. const char* str = "<xmlElement>"
  330. "<![CDATA["
  331. "<b>I am > the rules!</b>\n"
  332. "...since I make symbolic puns"
  333. "]]>"
  334. "</xmlElement>";
  335. XMLDocument doc;
  336. doc.Parse( str );
  337. doc.Print();
  338. XMLTest( "CDATA parse. [ tixml1:1480107 ]", doc.FirstChildElement()->FirstChild()->Value(),
  339. "<b>I am > the rules!</b>\n...since I make symbolic puns",
  340. false );
  341. }
  342. // InsertAfterChild causes crash.
  343. {
  344. // InsertBeforeChild and InsertAfterChild causes crash.
  345. XMLDocument doc;
  346. XMLElement* parent = doc.NewElement( "Parent" );
  347. doc.InsertFirstChild( parent );
  348. XMLElement* childText0 = doc.NewElement( "childText0" );
  349. XMLElement* childText1 = doc.NewElement( "childText1" );
  350. XMLNode* childNode0 = parent->InsertEndChild( childText0 );
  351. XMLNode* childNode1 = parent->InsertAfterChild( childNode0, childText1 );
  352. XMLTest( "Test InsertAfterChild on empty node. ", ( childNode1 == parent->LastChild() ), true );
  353. }
  354. {
  355. // Entities not being written correctly.
  356. // From Lynn Allen
  357. const char* passages =
  358. "<?xml version=\"1.0\" standalone=\"no\" ?>"
  359. "<passages count=\"006\" formatversion=\"20020620\">"
  360. "<psg context=\"Line 5 has &quot;quotation marks&quot; and &apos;apostrophe marks&apos;."
  361. " It also has &lt;, &gt;, and &amp;, as well as a fake copyright &#xA9;.\"> </psg>"
  362. "</passages>";
  363. XMLDocument doc;
  364. doc.Parse( passages );
  365. XMLElement* psg = doc.RootElement()->FirstChildElement();
  366. const char* context = psg->Attribute( "context" );
  367. const char* expected = "Line 5 has \"quotation marks\" and 'apostrophe marks'. It also has <, >, and &, as well as a fake copyright \xC2\xA9.";
  368. XMLTest( "Entity transformation: read. ", expected, context, true );
  369. FILE* textfile = fopen( "textfile.txt", "w" );
  370. if ( textfile )
  371. {
  372. XMLStreamer streamer( textfile );
  373. psg->Accept( &streamer );
  374. fclose( textfile );
  375. }
  376. textfile = fopen( "textfile.txt", "r" );
  377. TIXMLASSERT( textfile );
  378. if ( textfile )
  379. {
  380. char buf[ 1024 ];
  381. fgets( buf, 1024, textfile );
  382. XMLTest( "Entity transformation: write. ",
  383. "<psg context=\"Line 5 has &quot;quotation marks&quot; and &apos;apostrophe marks&apos;."
  384. " It also has &lt;, &gt;, and &amp;, as well as a fake copyright \xC2\xA9.\"/>\n",
  385. buf, false );
  386. }
  387. fclose( textfile );
  388. }
  389. {
  390. const char* test = "<?xml version='1.0'?><a.elem xmi.version='2.0'/>";
  391. XMLDocument doc;
  392. doc.Parse( test );
  393. XMLTest( "dot in names", doc.Error(), 0);
  394. XMLTest( "dot in names", doc.FirstChildElement()->Name(), "a.elem" );
  395. XMLTest( "dot in names", doc.FirstChildElement()->Attribute( "xmi.version" ), "2.0" );
  396. }
  397. {
  398. const char* test = "<element><Name>1.1 Start easy ignore fin thickness&#xA;</Name></element>";
  399. XMLDocument doc;
  400. doc.Parse( test );
  401. XMLText* text = doc.FirstChildElement()->FirstChildElement()->FirstChild()->ToText();
  402. XMLTest( "Entity with one digit.",
  403. text->Value(), "1.1 Start easy ignore fin thickness\n",
  404. false );
  405. }
  406. {
  407. // DOCTYPE not preserved (950171)
  408. //
  409. const char* doctype =
  410. "<?xml version=\"1.0\" ?>"
  411. "<!DOCTYPE PLAY SYSTEM 'play.dtd'>"
  412. "<!ELEMENT title (#PCDATA)>"
  413. "<!ELEMENT books (title,authors)>"
  414. "<element />";
  415. XMLDocument doc;
  416. doc.Parse( doctype );
  417. doc.SaveFile( "test7.xml" );
  418. doc.DeleteChild( doc.RootElement() );
  419. doc.LoadFile( "test7.xml" );
  420. doc.Print();
  421. const XMLUnknown* decl = doc.FirstChild()->NextSibling()->ToUnknown();
  422. XMLTest( "Correct value of unknown.", "DOCTYPE PLAY SYSTEM 'play.dtd'", decl->Value() );
  423. }
  424. {
  425. // Comments do not stream out correctly.
  426. const char* doctype =
  427. "<!-- Somewhat<evil> -->";
  428. XMLDocument doc;
  429. doc.Parse( doctype );
  430. XMLComment* comment = doc.FirstChild()->ToComment();
  431. XMLTest( "Comment formatting.", " Somewhat<evil> ", comment->Value() );
  432. }
  433. {
  434. // Double attributes
  435. const char* doctype = "<element attr='red' attr='blue' />";
  436. XMLDocument doc;
  437. doc.Parse( doctype );
  438. XMLTest( "Parsing repeated attributes.", ERROR_PARSING_ATTRIBUTE, doc.ErrorID() ); // is an error to tinyxml (didn't use to be, but caused issues)
  439. }
  440. {
  441. // Embedded null in stream.
  442. const char* doctype = "<element att\0r='red' attr='blue' />";
  443. XMLDocument doc;
  444. doc.Parse( doctype );
  445. XMLTest( "Embedded null throws error.", true, doc.Error() );
  446. }
  447. {
  448. // Empty documents should return TIXML_ERROR_PARSING_EMPTY, bug 1070717
  449. const char* str = " ";
  450. XMLDocument doc;
  451. doc.Parse( str );
  452. XMLTest( "Empty document error", ERROR_EMPTY_DOCUMENT, doc.ErrorID() );
  453. }
  454. {
  455. // Low entities
  456. XMLDocument doc;
  457. doc.Parse( "<test>&#x0e;</test>" );
  458. const char result[] = { 0x0e, 0 };
  459. XMLTest( "Low entities.", doc.FirstChildElement()->GetText(), result );
  460. doc.Print();
  461. }
  462. {
  463. // Attribute values with trailing quotes not handled correctly
  464. XMLDocument doc;
  465. doc.Parse( "<foo attribute=bar\" />" );
  466. XMLTest( "Throw error with bad end quotes.", doc.Error(), true );
  467. }
  468. {
  469. // [ 1663758 ] Failure to report error on bad XML
  470. XMLDocument xml;
  471. xml.Parse("<x>");
  472. XMLTest("Missing end tag at end of input", xml.Error(), true);
  473. xml.Parse("<x> ");
  474. XMLTest("Missing end tag with trailing whitespace", xml.Error(), true);
  475. xml.Parse("<x></y>");
  476. XMLTest("Mismatched tags", xml.ErrorID(), ERROR_MISMATCHED_ELEMENT);
  477. }
  478. {
  479. // [ 1475201 ] TinyXML parses entities in comments
  480. XMLDocument xml;
  481. xml.Parse("<!-- declarations for <head> & <body> -->"
  482. "<!-- far &amp; away -->" );
  483. XMLNode* e0 = xml.FirstChild();
  484. XMLNode* e1 = e0->NextSibling();
  485. XMLComment* c0 = e0->ToComment();
  486. XMLComment* c1 = e1->ToComment();
  487. XMLTest( "Comments ignore entities.", " declarations for <head> & <body> ", c0->Value(), true );
  488. XMLTest( "Comments ignore entities.", " far &amp; away ", c1->Value(), true );
  489. }
  490. {
  491. XMLDocument xml;
  492. xml.Parse( "<Parent>"
  493. "<child1 att=''/>"
  494. "<!-- With this comment, child2 will not be parsed! -->"
  495. "<child2 att=''/>"
  496. "</Parent>" );
  497. int count = 0;
  498. for( XMLNode* ele = xml.FirstChildElement( "Parent" )->FirstChild();
  499. ele;
  500. ele = ele->NextSibling() )
  501. {
  502. ++count;
  503. }
  504. XMLTest( "Comments iterate correctly.", 3, count );
  505. }
  506. {
  507. // trying to repro ]1874301]. If it doesn't go into an infinite loop, all is well.
  508. unsigned char buf[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?><feed><![CDATA[Test XMLblablablalblbl";
  509. buf[60] = 239;
  510. buf[61] = 0;
  511. XMLDocument doc;
  512. doc.Parse( (const char*)buf);
  513. }
  514. {
  515. // bug 1827248 Error while parsing a little bit malformed file
  516. // Actually not malformed - should work.
  517. XMLDocument xml;
  518. xml.Parse( "<attributelist> </attributelist >" );
  519. XMLTest( "Handle end tag whitespace", false, xml.Error() );
  520. }
  521. {
  522. // This one must not result in an infinite loop
  523. XMLDocument xml;
  524. xml.Parse( "<infinite>loop" );
  525. XMLTest( "Infinite loop test.", true, true );
  526. }
  527. #if defined( WIN32 )
  528. _CrtMemCheckpoint( &endMemState );
  529. //_CrtMemDumpStatistics( &endMemState );
  530. _CrtMemState diffMemState;
  531. _CrtMemDifference( &diffMemState, &startMemState, &endMemState );
  532. _CrtMemDumpStatistics( &diffMemState );
  533. //printf( "new total=%d\n", gNewTotal );
  534. #endif
  535. printf ("\nPass %d, Fail %d\n", gPass, gFail);
  536. return 0;
  537. }