xmltest.cpp 19 KB

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