Scheduler
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
xmltest.cpp
Go to the documentation of this file.
1 
10 /*
11  Test program for TinyXML.
12 */
13 
14 
15 #ifdef TIXML_USE_STL
16  #include <iostream>
17  #include <sstream>
18  using namespace std;
19 #else
20  #include <stdio.h>
21 #endif
22 
23 #if defined( WIN32 ) && defined( TUNE )
24  #include <crtdbg.h>
25  _CrtMemState startMemState;
26  _CrtMemState endMemState;
27 #endif
28 
29 #include "tinyxml.h"
30 
31 bool XmlTest (const char* testString, const char* expected, const char* found, bool noEcho = false);
32 bool XmlTest( const char* testString, int expected, int found, bool noEcho = false );
33 
34 static int gPass = 0;
35 static int gFail = 0;
36 
37 
38 
39 bool XmlTest (const char* testString, const char* expected, const char* found, bool noEcho )
40 {
41  bool pass = !strcmp( expected, found );
42  if ( pass )
43  printf ("[pass]");
44  else
45  printf ("[fail]");
46 
47  if ( noEcho )
48  printf (" %s\n", testString);
49  else
50  printf (" %s [%s][%s]\n", testString, expected, found);
51 
52  if ( pass )
53  ++gPass;
54  else
55  ++gFail;
56  return pass;
57 }
58 
59 
60 bool XmlTest( const char* testString, int expected, int found, bool noEcho )
61 {
62  bool pass = ( expected == found );
63  if ( pass )
64  printf ("[pass]");
65  else
66  printf ("[fail]");
67 
68  if ( noEcho )
69  printf (" %s\n", testString);
70  else
71  printf (" %s [%d][%d]\n", testString, expected, found);
72 
73  if ( pass )
74  ++gPass;
75  else
76  ++gFail;
77  return pass;
78 }
79 
80 
81 void NullLineEndings( char* p )
82 {
83  while( p && *p ) {
84  if ( *p == '\n' || *p == '\r' ) {
85  *p = 0;
86  return;
87  }
88  ++p;
89  }
90 }
91 
92 //
93 // This file demonstrates some basic functionality of TinyXml.
94 // Note that the example is very contrived. It presumes you know
95 // what is in the XML file. But it does test the basic operations,
96 // and show how to add and remove nodes.
97 //
98 
99 int main()
100 {
101 
102  //
103  // We start with the 'demoStart' todo list. Process it. And
104  // should hopefully end up with the todo list as illustrated.
105  //
106  const char* demoStart =
107  "<?xml version=\"1.0\" standalone='no' >\n"
108  "<!-- Our to do list data -->"
109  "<ToDo>\n"
110  "<!-- Do I need a secure PDA? -->\n"
111  "<Item priority=\"1\" distance='close'> Go to the <bold>Toy store!</bold></Item>"
112  "<Item priority=\"2\" distance='none'> Do bills </Item>"
113  "<Item priority=\"2\" distance='far &amp; back'> Look for Evil Dinosaurs! </Item>"
114  "</ToDo>";
115 
116  {
117 
118  #ifdef TIXML_USE_STL
119  // What the todo list should look like after processing.
120  // In stream (no formatting) representation.
121  const char* demoEnd =
122  "<?xml version=\"1.0\" standalone=\"no\" ?>"
123  "<!-- Our to do list data -->"
124  "<ToDo>"
125  "<!-- Do I need a secure PDA? -->"
126  "<Item priority=\"2\" distance=\"close\">Go to the"
127  "<bold>Toy store!"
128  "</bold>"
129  "</Item>"
130  "<Item priority=\"1\" distance=\"far\">Talk to:"
131  "<Meeting where=\"School\">"
132  "<Attendee name=\"Marple\" position=\"teacher\" />"
133  "<Attendee name=\"Voel\" position=\"counselor\" />"
134  "</Meeting>"
135  "<Meeting where=\"Lunch\" />"
136  "</Item>"
137  "<Item priority=\"2\" distance=\"here\">Do bills"
138  "</Item>"
139  "</ToDo>";
140  #endif
141 
142  // The example parses from the character string (above):
143  #if defined( WIN32 ) && defined( TUNE )
144  _CrtMemCheckpoint( &startMemState );
145  #endif
146 
147  {
148  // Write to a file and read it back, to check file I/O.
149 
150  TiXmlDocument doc( "demotest.xml" );
151  doc.Parse( demoStart );
152 
153  if ( doc.Error() )
154  {
155  printf( "Error in %s: %s\n", doc.Value(), doc.ErrorDesc() );
156  exit( 1 );
157  }
158  doc.SaveFile();
159  }
160 
161  TiXmlDocument doc( "demotest.xml" );
162  bool loadOkay = doc.LoadFile();
163 
164  if ( !loadOkay )
165  {
166  printf( "Could not load test file 'demotest.xml'. Error='%s'. Exiting.\n", doc.ErrorDesc() );
167  exit( 1 );
168  }
169 
170  printf( "** Demo doc read from disk: ** \n\n" );
171  printf( "** Printing via doc.Print **\n" );
172  doc.Print( stdout );
173 
174  {
175  printf( "** Printing via TiXmlPrinter **\n" );
176  TiXmlPrinter printer;
177  doc.Accept( &printer );
178  fprintf( stdout, "%s", printer.CStr() );
179  }
180  #ifdef TIXML_USE_STL
181  {
182  printf( "** Printing via operator<< **\n" );
183  std::cout << doc;
184  }
185  #endif
186  TiXmlNode* node = 0;
187  TiXmlElement* todoElement = 0;
188  TiXmlElement* itemElement = 0;
189 
190 
191  // --------------------------------------------------------
192  // An example of changing existing attributes, and removing
193  // an element from the document.
194  // --------------------------------------------------------
195 
196  // Get the "ToDo" element.
197  // It is a child of the document, and can be selected by name.
198  node = doc.FirstChild( "ToDo" );
199  assert( node );
200  todoElement = node->ToElement();
201  assert( todoElement );
202 
203  // Going to the toy store is now our second priority...
204  // So set the "priority" attribute of the first item in the list.
205  node = todoElement->FirstChildElement(); // This skips the "PDA" comment.
206  assert( node );
207  itemElement = node->ToElement();
208  assert( itemElement );
209  itemElement->SetAttribute( "priority", 2 );
210 
211  // Change the distance to "doing bills" from
212  // "none" to "here". It's the next sibling element.
213  itemElement = itemElement->NextSiblingElement();
214  assert( itemElement );
215  itemElement->SetAttribute( "distance", "here" );
216 
217  // Remove the "Look for Evil Dinosaurs!" item.
218  // It is 1 more sibling away. We ask the parent to remove
219  // a particular child.
220  itemElement = itemElement->NextSiblingElement();
221  todoElement->RemoveChild( itemElement );
222 
223  itemElement = 0;
224 
225  // --------------------------------------------------------
226  // What follows is an example of created elements and text
227  // nodes and adding them to the document.
228  // --------------------------------------------------------
229 
230  // Add some meetings.
231  TiXmlElement item( "Item" );
232  item.SetAttribute( "priority", "1" );
233  item.SetAttribute( "distance", "far" );
234 
235  TiXmlText text( "Talk to:" );
236 
237  TiXmlElement meeting1( "Meeting" );
238  meeting1.SetAttribute( "where", "School" );
239 
240  TiXmlElement meeting2( "Meeting" );
241  meeting2.SetAttribute( "where", "Lunch" );
242 
243  TiXmlElement attendee1( "Attendee" );
244  attendee1.SetAttribute( "name", "Marple" );
245  attendee1.SetAttribute( "position", "teacher" );
246 
247  TiXmlElement attendee2( "Attendee" );
248  attendee2.SetAttribute( "name", "Voel" );
249  attendee2.SetAttribute( "position", "counselor" );
250 
251  // Assemble the nodes we've created:
252  meeting1.InsertEndChild( attendee1 );
253  meeting1.InsertEndChild( attendee2 );
254 
255  item.InsertEndChild( text );
256  item.InsertEndChild( meeting1 );
257  item.InsertEndChild( meeting2 );
258 
259  // And add the node to the existing list after the first child.
260  node = todoElement->FirstChild( "Item" );
261  assert( node );
262  itemElement = node->ToElement();
263  assert( itemElement );
264 
265  todoElement->InsertAfterChild( itemElement, item );
266 
267  printf( "\n** Demo doc processed: ** \n\n" );
268  doc.Print( stdout );
269 
270 
271  #ifdef TIXML_USE_STL
272  printf( "** Demo doc processed to stream: ** \n\n" );
273  cout << doc << endl << endl;
274  #endif
275 
276  // --------------------------------------------------------
277  // Different tests...do we have what we expect?
278  // --------------------------------------------------------
279 
280  int count = 0;
281  TiXmlElement* element;
282 
284 
285  #ifdef TIXML_USE_STL
286  cout << "** Basic structure. **\n";
287  ostringstream outputStream( ostringstream::out );
288  outputStream << doc;
289  XmlTest( "Output stream correct.", string( demoEnd ).c_str(),
290  outputStream.str().c_str(), true );
291  #endif
292 
293  node = doc.RootElement();
294  assert( node );
295  XmlTest( "Root element exists.", true, ( node != 0 && node->ToElement() ) );
296  XmlTest ( "Root element value is 'ToDo'.", "ToDo", node->Value());
297 
298  node = node->FirstChild();
299  XmlTest( "First child exists & is a comment.", true, ( node != 0 && node->ToComment() ) );
300  node = node->NextSibling();
301  XmlTest( "Sibling element exists & is an element.", true, ( node != 0 && node->ToElement() ) );
302  XmlTest ( "Value is 'Item'.", "Item", node->Value() );
303 
304  node = node->FirstChild();
305  XmlTest ( "First child exists.", true, ( node != 0 && node->ToText() ) );
306  XmlTest ( "Value is 'Go to the'.", "Go to the", node->Value() );
307 
308 
310  printf ("\n** Iterators. **\n");
311 
312  // Walk all the top level nodes of the document.
313  count = 0;
314  for( node = doc.FirstChild();
315  node;
316  node = node->NextSibling() )
317  {
318  count++;
319  }
320  XmlTest( "Top level nodes, using First / Next.", 3, count );
321 
322  count = 0;
323  for( node = doc.LastChild();
324  node;
325  node = node->PreviousSibling() )
326  {
327  count++;
328  }
329  XmlTest( "Top level nodes, using Last / Previous.", 3, count );
330 
331  // Walk all the top level nodes of the document,
332  // using a different syntax.
333  count = 0;
334  for( node = doc.IterateChildren( 0 );
335  node;
336  node = doc.IterateChildren( node ) )
337  {
338  count++;
339  }
340  XmlTest( "Top level nodes, using IterateChildren.", 3, count );
341 
342  // Walk all the elements in a node.
343  count = 0;
344  for( element = todoElement->FirstChildElement();
345  element;
346  element = element->NextSiblingElement() )
347  {
348  count++;
349  }
350  XmlTest( "Children of the 'ToDo' element, using First / Next.",
351  3, count );
352 
353  // Walk all the elements in a node by value.
354  count = 0;
355  for( node = todoElement->FirstChild( "Item" );
356  node;
357  node = node->NextSibling( "Item" ) )
358  {
359  count++;
360  }
361  XmlTest( "'Item' children of the 'ToDo' element, using First/Next.", 3, count );
362 
363  count = 0;
364  for( node = todoElement->LastChild( "Item" );
365  node;
366  node = node->PreviousSibling( "Item" ) )
367  {
368  count++;
369  }
370  XmlTest( "'Item' children of the 'ToDo' element, using Last/Previous.", 3, count );
371 
372  #ifdef TIXML_USE_STL
373  {
374  cout << "\n** Parsing. **\n";
375  istringstream parse0( "<Element0 attribute0='foo0' attribute1= noquotes attribute2 = '&gt;' />" );
376  TiXmlElement element0( "default" );
377  parse0 >> element0;
378 
379  XmlTest ( "Element parsed, value is 'Element0'.", "Element0", element0.Value() );
380  XmlTest ( "Reads attribute 'attribute0=\"foo0\"'.", "foo0", element0.Attribute( "attribute0" ));
381  XmlTest ( "Reads incorrectly formatted 'attribute1=noquotes'.", "noquotes", element0.Attribute( "attribute1" ) );
382  XmlTest ( "Read attribute with entity value '>'.", ">", element0.Attribute( "attribute2" ) );
383  }
384  #endif
385 
386  {
387  const char* error = "<?xml version=\"1.0\" standalone=\"no\" ?>\n"
388  "<passages count=\"006\" formatversion=\"20020620\">\n"
389  " <wrong error>\n"
390  "</passages>";
391 
392  TiXmlDocument docTest;
393  docTest.Parse( error );
394  XmlTest( "Error row", docTest.ErrorRow(), 3 );
395  XmlTest( "Error column", docTest.ErrorCol(), 17 );
396  //printf( "error=%d id='%s' row %d col%d\n", (int) doc.Error(), doc.ErrorDesc(), doc.ErrorRow()+1, doc.ErrorCol() + 1 );
397 
398  }
399 
400  #ifdef TIXML_USE_STL
401  {
403  cout << "\n** Streaming. **\n";
404 
405  // Round trip check: stream in, then stream back out to verify. The stream
406  // out has already been checked, above. We use the output
407 
408  istringstream inputStringStream( outputStream.str() );
409  TiXmlDocument document0;
410 
411  inputStringStream >> document0;
412 
413  ostringstream outputStream0( ostringstream::out );
414  outputStream0 << document0;
415 
416  XmlTest( "Stream round trip correct.", string( demoEnd ).c_str(),
417  outputStream0.str().c_str(), true );
418 
419  std::string str;
420  str << document0;
421 
422  XmlTest( "String printing correct.", string( demoEnd ).c_str(),
423  str.c_str(), true );
424  }
425  #endif
426  }
427 
428  {
429  const char* str = "<doc attr0='1' attr1='2.0' attr2='foo' />";
430 
431  TiXmlDocument doc;
432  doc.Parse( str );
433 
434  TiXmlElement* ele = doc.FirstChildElement();
435 
436  int iVal, result;
437  double dVal;
438 
439  result = ele->QueryDoubleAttribute( "attr0", &dVal );
440  XmlTest( "Query attribute: int as double", result, TIXML_SUCCESS );
441  XmlTest( "Query attribute: int as double", (int)dVal, 1 );
442  result = ele->QueryDoubleAttribute( "attr1", &dVal );
443  XmlTest( "Query attribute: double as double", (int)dVal, 2 );
444  result = ele->QueryIntAttribute( "attr1", &iVal );
445  XmlTest( "Query attribute: double as int", result, TIXML_SUCCESS );
446  XmlTest( "Query attribute: double as int", iVal, 2 );
447  result = ele->QueryIntAttribute( "attr2", &iVal );
448  XmlTest( "Query attribute: not a number", result, TIXML_WRONG_TYPE );
449  result = ele->QueryIntAttribute( "bar", &iVal );
450  XmlTest( "Query attribute: does not exist", result, TIXML_NO_ATTRIBUTE );
451  }
452 
453  {
454  const char* str = "<doc/>";
455 
456  TiXmlDocument doc;
457  doc.Parse( str );
458 
459  TiXmlElement* ele = doc.FirstChildElement();
460 
461  int iVal;
462  double dVal;
463 
464  ele->SetAttribute( "str", "strValue" );
465  ele->SetAttribute( "int", 1 );
466  ele->SetDoubleAttribute( "double", -1.0 );
467 
468  const char* cStr = ele->Attribute( "str" );
469  ele->QueryIntAttribute( "int", &iVal );
470  ele->QueryDoubleAttribute( "double", &dVal );
471 
472  XmlTest( "Attribute round trip. c-string.", "strValue", cStr );
473  XmlTest( "Attribute round trip. int.", 1, iVal );
474  XmlTest( "Attribute round trip. double.", -1, (int)dVal );
475  }
476 
477  {
478  const char* str = "\t<?xml version=\"1.0\" standalone=\"no\" ?>\t<room doors='2'>\n"
479  "</room>";
480 
481  TiXmlDocument doc;
482  doc.SetTabSize( 8 );
483  doc.Parse( str );
484 
485  TiXmlHandle docHandle( &doc );
486  TiXmlHandle roomHandle = docHandle.FirstChildElement( "room" );
487 
488  assert( docHandle.Node() );
489  assert( roomHandle.Element() );
490 
491  TiXmlElement* room = roomHandle.Element();
492  assert( room );
493  TiXmlAttribute* doors = room->FirstAttribute();
494  assert( doors );
495 
496  XmlTest( "Location tracking: Tab 8: room row", room->Row(), 1 );
497  XmlTest( "Location tracking: Tab 8: room col", room->Column(), 49 );
498  XmlTest( "Location tracking: Tab 8: doors row", doors->Row(), 1 );
499  XmlTest( "Location tracking: Tab 8: doors col", doors->Column(), 55 );
500  }
501 
502  {
503  const char* str = "\t<?xml version=\"1.0\" standalone=\"no\" ?>\t<room doors='2'>\n"
504  " <!-- Silly example -->\n"
505  " <door wall='north'>A great door!</door>\n"
506  "\t<door wall='east'/>"
507  "</room>";
508 
509  TiXmlDocument doc;
510  doc.Parse( str );
511 
512  TiXmlHandle docHandle( &doc );
513  TiXmlHandle roomHandle = docHandle.FirstChildElement( "room" );
514  TiXmlHandle commentHandle = docHandle.FirstChildElement( "room" ).FirstChild();
515  TiXmlHandle textHandle = docHandle.FirstChildElement( "room" ).ChildElement( "door", 0 ).FirstChild();
516  TiXmlHandle door0Handle = docHandle.FirstChildElement( "room" ).ChildElement( 0 );
517  TiXmlHandle door1Handle = docHandle.FirstChildElement( "room" ).ChildElement( 1 );
518 
519  assert( docHandle.Node() );
520  assert( roomHandle.Element() );
521  assert( commentHandle.Node() );
522  assert( textHandle.Text() );
523  assert( door0Handle.Element() );
524  assert( door1Handle.Element() );
525 
526  TiXmlDeclaration* declaration = doc.FirstChild()->ToDeclaration();
527  assert( declaration );
528  TiXmlElement* room = roomHandle.Element();
529  assert( room );
530  TiXmlAttribute* doors = room->FirstAttribute();
531  assert( doors );
532  TiXmlText* text = textHandle.Text();
533  TiXmlComment* comment = commentHandle.Node()->ToComment();
534  assert( comment );
535  TiXmlElement* door0 = door0Handle.Element();
536  TiXmlElement* door1 = door1Handle.Element();
537 
538  XmlTest( "Location tracking: Declaration row", declaration->Row(), 1 );
539  XmlTest( "Location tracking: Declaration col", declaration->Column(), 5 );
540  XmlTest( "Location tracking: room row", room->Row(), 1 );
541  XmlTest( "Location tracking: room col", room->Column(), 45 );
542  XmlTest( "Location tracking: doors row", doors->Row(), 1 );
543  XmlTest( "Location tracking: doors col", doors->Column(), 51 );
544  XmlTest( "Location tracking: Comment row", comment->Row(), 2 );
545  XmlTest( "Location tracking: Comment col", comment->Column(), 3 );
546  XmlTest( "Location tracking: text row", text->Row(), 3 );
547  XmlTest( "Location tracking: text col", text->Column(), 24 );
548  XmlTest( "Location tracking: door0 row", door0->Row(), 3 );
549  XmlTest( "Location tracking: door0 col", door0->Column(), 5 );
550  XmlTest( "Location tracking: door1 row", door1->Row(), 4 );
551  XmlTest( "Location tracking: door1 col", door1->Column(), 5 );
552  }
553 
554 
555  // --------------------------------------------------------
556  // UTF-8 testing. It is important to test:
557  // 1. Making sure name, value, and text read correctly
558  // 2. Row, Col functionality
559  // 3. Correct output
560  // --------------------------------------------------------
561  printf ("\n** UTF-8 **\n");
562  {
563  TiXmlDocument doc( "utf8test.xml" );
564  doc.LoadFile();
565  if ( doc.Error() && doc.ErrorId() == TiXmlBase::TIXML_ERROR_OPENING_FILE ) {
566  printf( "WARNING: File 'utf8test.xml' not found.\n"
567  "(Are you running the test from the wrong directory?)\n"
568  "Could not test UTF-8 functionality.\n" );
569  }
570  else
571  {
572  TiXmlHandle docH( &doc );
573  // Get the attribute "value" from the "Russian" element and check it.
574  TiXmlElement* element = docH.FirstChildElement( "document" ).FirstChildElement( "Russian" ).Element();
575  const unsigned char correctValue[] = { 0xd1U, 0x86U, 0xd0U, 0xb5U, 0xd0U, 0xbdU, 0xd0U, 0xbdU,
576  0xd0U, 0xbeU, 0xd1U, 0x81U, 0xd1U, 0x82U, 0xd1U, 0x8cU, 0 };
577 
578  XmlTest( "UTF-8: Russian value.", (const char*)correctValue, element->Attribute( "value" ), true );
579  XmlTest( "UTF-8: Russian value row.", 4, element->Row() );
580  XmlTest( "UTF-8: Russian value column.", 5, element->Column() );
581 
582  const unsigned char russianElementName[] = { 0xd0U, 0xa0U, 0xd1U, 0x83U,
583  0xd1U, 0x81U, 0xd1U, 0x81U,
584  0xd0U, 0xbaU, 0xd0U, 0xb8U,
585  0xd0U, 0xb9U, 0 };
586  const char russianText[] = "<\xD0\xB8\xD0\xBC\xD0\xB5\xD0\xB5\xD1\x82>";
587 
588  TiXmlText* text = docH.FirstChildElement( "document" ).FirstChildElement( (const char*) russianElementName ).Child( 0 ).Text();
589  XmlTest( "UTF-8: Browsing russian element name.",
590  russianText,
591  text->Value(),
592  true );
593  XmlTest( "UTF-8: Russian element name row.", 7, text->Row() );
594  XmlTest( "UTF-8: Russian element name column.", 47, text->Column() );
595 
596  TiXmlDeclaration* dec = docH.Child( 0 ).Node()->ToDeclaration();
597  XmlTest( "UTF-8: Declaration column.", 1, dec->Column() );
598  XmlTest( "UTF-8: Document column.", 1, doc.Column() );
599 
600  // Now try for a round trip.
601  doc.SaveFile( "utf8testout.xml" );
602 
603  // Check the round trip.
604  char savedBuf[256];
605  char verifyBuf[256];
606  int okay = 1;
607 
608  FILE* saved = fopen( "utf8testout.xml", "r" );
609  FILE* verify = fopen( "utf8testverify.xml", "r" );
610 
611  //bool firstLineBOM=true;
612  if ( saved && verify )
613  {
614  while ( fgets( verifyBuf, 256, verify ) )
615  {
616  fgets( savedBuf, 256, saved );
617  NullLineEndings( verifyBuf );
618  NullLineEndings( savedBuf );
619 
620  if ( strcmp( verifyBuf, savedBuf ) )
621  {
622  printf( "verify:%s<\n", verifyBuf );
623  printf( "saved :%s<\n", savedBuf );
624  okay = 0;
625  break;
626  }
627  //firstLineBOM = false;
628  }
629  }
630  if ( saved )
631  fclose( saved );
632  if ( verify )
633  fclose( verify );
634  XmlTest( "UTF-8: Verified multi-language round trip.", 1, okay );
635 
636  // On most Western machines, this is an element that contains
637  // the word "resume" with the correct accents, in a latin encoding.
638  // It will be something else completely on non-wester machines,
639  // which is why TinyXml is switching to UTF-8.
640  const char latin[] = "<element>r\x82sum\x82</element>";
641 
642  TiXmlDocument latinDoc;
643  latinDoc.Parse( latin, 0, TIXML_ENCODING_LEGACY );
644 
645  text = latinDoc.FirstChildElement()->FirstChild()->ToText();
646  XmlTest( "Legacy encoding: Verify text element.", "r\x82sum\x82", text->Value() );
647  }
648  }
649 
651  // Copy and assignment
653  printf ("\n** Copy and Assignment **\n");
654  {
655  TiXmlElement element( "foo" );
656  element.Parse( "<element name='value' />", 0, TIXML_ENCODING_UNKNOWN );
657 
658  TiXmlElement elementCopy( element );
659  TiXmlElement elementAssign( "foo" );
660  elementAssign.Parse( "<incorrect foo='bar'/>", 0, TIXML_ENCODING_UNKNOWN );
661  elementAssign = element;
662 
663  XmlTest( "Copy/Assign: element copy #1.", "element", elementCopy.Value() );
664  XmlTest( "Copy/Assign: element copy #2.", "value", elementCopy.Attribute( "name" ) );
665  XmlTest( "Copy/Assign: element assign #1.", "element", elementAssign.Value() );
666  XmlTest( "Copy/Assign: element assign #2.", "value", elementAssign.Attribute( "name" ) );
667  XmlTest( "Copy/Assign: element assign #3.", true, ( 0 == elementAssign.Attribute( "foo" )) );
668 
669  TiXmlComment comment;
670  comment.Parse( "<!--comment-->", 0, TIXML_ENCODING_UNKNOWN );
671  TiXmlComment commentCopy( comment );
672  TiXmlComment commentAssign;
673  commentAssign = commentCopy;
674  XmlTest( "Copy/Assign: comment copy.", "comment", commentCopy.Value() );
675  XmlTest( "Copy/Assign: comment assign.", "comment", commentAssign.Value() );
676 
677  TiXmlUnknown unknown;
678  unknown.Parse( "<[unknown]>", 0, TIXML_ENCODING_UNKNOWN );
679  TiXmlUnknown unknownCopy( unknown );
680  TiXmlUnknown unknownAssign;
681  unknownAssign.Parse( "incorrect", 0, TIXML_ENCODING_UNKNOWN );
682  unknownAssign = unknownCopy;
683  XmlTest( "Copy/Assign: unknown copy.", "[unknown]", unknownCopy.Value() );
684  XmlTest( "Copy/Assign: unknown assign.", "[unknown]", unknownAssign.Value() );
685 
686  TiXmlText text( "TextNode" );
687  TiXmlText textCopy( text );
688  TiXmlText textAssign( "incorrect" );
689  textAssign = text;
690  XmlTest( "Copy/Assign: text copy.", "TextNode", textCopy.Value() );
691  XmlTest( "Copy/Assign: text assign.", "TextNode", textAssign.Value() );
692 
693  TiXmlDeclaration dec;
694  dec.Parse( "<?xml version='1.0' encoding='UTF-8'?>", 0, TIXML_ENCODING_UNKNOWN );
695  TiXmlDeclaration decCopy( dec );
696  TiXmlDeclaration decAssign;
697  decAssign = dec;
698 
699  XmlTest( "Copy/Assign: declaration copy.", "UTF-8", decCopy.Encoding() );
700  XmlTest( "Copy/Assign: text assign.", "UTF-8", decAssign.Encoding() );
701 
702  TiXmlDocument doc;
703  elementCopy.InsertEndChild( textCopy );
704  doc.InsertEndChild( decAssign );
705  doc.InsertEndChild( elementCopy );
706  doc.InsertEndChild( unknownAssign );
707 
708  TiXmlDocument docCopy( doc );
709  TiXmlDocument docAssign;
710  docAssign = docCopy;
711 
712  #ifdef TIXML_USE_STL
713  std::string original, copy, assign;
714  original << doc;
715  copy << docCopy;
716  assign << docAssign;
717  XmlTest( "Copy/Assign: document copy.", original.c_str(), copy.c_str(), true );
718  XmlTest( "Copy/Assign: document assign.", original.c_str(), assign.c_str(), true );
719 
720  #endif
721  }
722 
724 #ifdef TIXML_USE_STL
725  printf ("\n** Parsing, no Condense Whitespace **\n");
727  {
728  istringstream parse1( "<start>This is \ntext</start>" );
729  TiXmlElement text1( "text" );
730  parse1 >> text1;
731 
732  XmlTest ( "Condense white space OFF.", "This is \ntext",
733  text1.FirstChild()->Value(),
734  true );
735  }
737 #endif
738 
740  // GetText();
741  {
742  const char* str = "<foo>This is text</foo>";
743  TiXmlDocument doc;
744  doc.Parse( str );
745  const TiXmlElement* element = doc.RootElement();
746 
747  XmlTest( "GetText() normal use.", "This is text", element->GetText() );
748 
749  str = "<foo><b>This is text</b></foo>";
750  doc.Clear();
751  doc.Parse( str );
752  element = doc.RootElement();
753 
754  XmlTest( "GetText() contained element.", element->GetText() == 0, true );
755 
756  str = "<foo>This is <b>text</b></foo>";
757  doc.Clear();
759  doc.Parse( str );
761  element = doc.RootElement();
762 
763  XmlTest( "GetText() partial.", "This is ", element->GetText() );
764  }
765 
766 
768  // CDATA
769  {
770  const char* str = "<xmlElement>"
771  "<![CDATA["
772  "I am > the rules!\n"
773  "...since I make symbolic puns"
774  "]]>"
775  "</xmlElement>";
776  TiXmlDocument doc;
777  doc.Parse( str );
778  doc.Print();
779 
780  XmlTest( "CDATA parse.", doc.FirstChildElement()->FirstChild()->Value(),
781  "I am > the rules!\n...since I make symbolic puns",
782  true );
783 
784  #ifdef TIXML_USE_STL
785  //cout << doc << '\n';
786 
787  doc.Clear();
788 
789  istringstream parse0( str );
790  parse0 >> doc;
791  //cout << doc << '\n';
792 
793  XmlTest( "CDATA stream.", doc.FirstChildElement()->FirstChild()->Value(),
794  "I am > the rules!\n...since I make symbolic puns",
795  true );
796  #endif
797 
798  TiXmlDocument doc1 = doc;
799  //doc.Print();
800 
801  XmlTest( "CDATA copy.", doc1.FirstChildElement()->FirstChild()->Value(),
802  "I am > the rules!\n...since I make symbolic puns",
803  true );
804  }
805  {
806  // [ 1482728 ] Wrong wide char parsing
807  char buf[256];
808  buf[255] = 0;
809  for( int i=0; i<255; ++i ) {
810  buf[i] = (char)((i>=32) ? i : 32);
811  }
812  TIXML_STRING str( "<xmlElement><![CDATA[" );
813  str += buf;
814  str += "]]></xmlElement>";
815 
816  TiXmlDocument doc;
817  doc.Parse( str.c_str() );
818 
819  TiXmlPrinter printer;
820  printer.SetStreamPrinting();
821  doc.Accept( &printer );
822 
823  XmlTest( "CDATA with all bytes #1.", str.c_str(), printer.CStr(), true );
824 
825  #ifdef TIXML_USE_STL
826  doc.Clear();
827  istringstream iss( printer.Str() );
828  iss >> doc;
829  std::string out;
830  out << doc;
831  XmlTest( "CDATA with all bytes #2.", out.c_str(), printer.CStr(), true );
832  #endif
833  }
834  {
835  // [ 1480107 ] Bug-fix for STL-streaming of CDATA that contains tags
836  // CDATA streaming had a couple of bugs, that this tests for.
837  const char* str = "<xmlElement>"
838  "<![CDATA["
839  "<b>I am > the rules!</b>\n"
840  "...since I make symbolic puns"
841  "]]>"
842  "</xmlElement>";
843  TiXmlDocument doc;
844  doc.Parse( str );
845  doc.Print();
846 
847  XmlTest( "CDATA parse. [ 1480107 ]", doc.FirstChildElement()->FirstChild()->Value(),
848  "<b>I am > the rules!</b>\n...since I make symbolic puns",
849  true );
850 
851  #ifdef TIXML_USE_STL
852 
853  doc.Clear();
854 
855  istringstream parse0( str );
856  parse0 >> doc;
857 
858  XmlTest( "CDATA stream. [ 1480107 ]", doc.FirstChildElement()->FirstChild()->Value(),
859  "<b>I am > the rules!</b>\n...since I make symbolic puns",
860  true );
861  #endif
862 
863  TiXmlDocument doc1 = doc;
864  //doc.Print();
865 
866  XmlTest( "CDATA copy. [ 1480107 ]", doc1.FirstChildElement()->FirstChild()->Value(),
867  "<b>I am > the rules!</b>\n...since I make symbolic puns",
868  true );
869  }
871  // Visit()
872 
873 
874 
876  printf( "\n** Fuzzing... **\n" );
877 
878  const int FUZZ_ITERATION = 300;
879 
880  // The only goal is not to crash on bad input.
881  int len = (int) strlen( demoStart );
882  for( int i=0; i<FUZZ_ITERATION; ++i )
883  {
884  char* demoCopy = new char[ len+1 ];
885  strcpy( demoCopy, demoStart );
886 
887  demoCopy[ i%len ] = (char)((i+1)*3);
888  demoCopy[ (i*7)%len ] = '>';
889  demoCopy[ (i*11)%len ] = '<';
890 
891  TiXmlDocument xml;
892  xml.Parse( demoCopy );
893 
894  delete [] demoCopy;
895  }
896  printf( "** Fuzzing Complete. **\n" );
897 
899  printf ("\n** Bug regression tests **\n");
900 
901  // InsertBeforeChild and InsertAfterChild causes crash.
902  {
903  TiXmlElement parent( "Parent" );
904  TiXmlElement childText0( "childText0" );
905  TiXmlElement childText1( "childText1" );
906  TiXmlNode* childNode0 = parent.InsertEndChild( childText0 );
907  TiXmlNode* childNode1 = parent.InsertBeforeChild( childNode0, childText1 );
908 
909  XmlTest( "Test InsertBeforeChild on empty node.", ( childNode1 == parent.FirstChild() ), true );
910  }
911 
912  {
913  // InsertBeforeChild and InsertAfterChild causes crash.
914  TiXmlElement parent( "Parent" );
915  TiXmlElement childText0( "childText0" );
916  TiXmlElement childText1( "childText1" );
917  TiXmlNode* childNode0 = parent.InsertEndChild( childText0 );
918  TiXmlNode* childNode1 = parent.InsertAfterChild( childNode0, childText1 );
919 
920  XmlTest( "Test InsertAfterChild on empty node. ", ( childNode1 == parent.LastChild() ), true );
921  }
922 
923  // Reports of missing constructors, irregular string problems.
924  {
925  // Missing constructor implementation. No test -- just compiles.
926  TiXmlText text( "Missing" );
927 
928  #ifdef TIXML_USE_STL
929  // Missing implementation:
930  TiXmlDocument doc;
931  string name = "missing";
932  doc.LoadFile( name );
933 
934  TiXmlText textSTL( name );
935  #else
936  // verifying some basic string functions:
937  TiXmlString a;
938  TiXmlString b( "Hello" );
939  TiXmlString c( "ooga" );
940 
941  c = " World!";
942  a = b;
943  a += c;
944  a = a;
945 
946  XmlTest( "Basic TiXmlString test. ", "Hello World!", a.c_str() );
947  #endif
948  }
949 
950  // Long filenames crashing STL version
951  {
952  TiXmlDocument doc( "midsummerNightsDreamWithAVeryLongFilenameToConfuseTheStringHandlingRoutines.xml" );
953  bool loadOkay = doc.LoadFile();
954  loadOkay = true; // get rid of compiler warning.
955  // Won't pass on non-dev systems. Just a "no crash" check.
956  //XmlTest( "Long filename. ", true, loadOkay );
957  }
958 
959  {
960  // Entities not being written correctly.
961  // From Lynn Allen
962 
963  const char* passages =
964  "<?xml version=\"1.0\" standalone=\"no\" ?>"
965  "<passages count=\"006\" formatversion=\"20020620\">"
966  "<psg context=\"Line 5 has &quot;quotation marks&quot; and &apos;apostrophe marks&apos;."
967  " It also has &lt;, &gt;, and &amp;, as well as a fake copyright &#xA9;.\"> </psg>"
968  "</passages>";
969 
970  TiXmlDocument doc( "passages.xml" );
971  doc.Parse( passages );
973  const char* context = psg->Attribute( "context" );
974  const char* expected = "Line 5 has \"quotation marks\" and 'apostrophe marks'. It also has <, >, and &, as well as a fake copyright \xC2\xA9.";
975 
976  XmlTest( "Entity transformation: read. ", expected, context, true );
977 
978  FILE* textfile = fopen( "textfile.txt", "w" );
979  if ( textfile )
980  {
981  psg->Print( textfile, 0 );
982  fclose( textfile );
983  }
984  textfile = fopen( "textfile.txt", "r" );
985  assert( textfile );
986  if ( textfile )
987  {
988  char buf[ 1024 ];
989  fgets( buf, 1024, textfile );
990  XmlTest( "Entity transformation: write. ",
991  "<psg context=\'Line 5 has &quot;quotation marks&quot; and &apos;apostrophe marks&apos;."
992  " It also has &lt;, &gt;, and &amp;, as well as a fake copyright \xC2\xA9.' />",
993  buf,
994  true );
995  }
996  fclose( textfile );
997  }
998 
999  {
1000  FILE* textfile = fopen( "test5.xml", "w" );
1001  if ( textfile )
1002  {
1003  fputs("<?xml version='1.0'?><a.elem xmi.version='2.0'/>", textfile);
1004  fclose(textfile);
1005 
1006  TiXmlDocument doc;
1007  doc.LoadFile( "test5.xml" );
1008  XmlTest( "dot in element attributes and names", doc.Error(), 0);
1009  }
1010  }
1011 
1012  {
1013  FILE* textfile = fopen( "test6.xml", "w" );
1014  if ( textfile )
1015  {
1016  fputs("<element><Name>1.1 Start easy ignore fin thickness&#xA;</Name></element>", textfile );
1017  fclose(textfile);
1018 
1019  TiXmlDocument doc;
1020  bool result = doc.LoadFile( "test6.xml" );
1021  XmlTest( "Entity with one digit.", result, true );
1022 
1024  XmlTest( "Entity with one digit.",
1025  text->Value(), "1.1 Start easy ignore fin thickness\n" );
1026  }
1027  }
1028 
1029  {
1030  // DOCTYPE not preserved (950171)
1031  //
1032  const char* doctype =
1033  "<?xml version=\"1.0\" ?>"
1034  "<!DOCTYPE PLAY SYSTEM 'play.dtd'>"
1035  "<!ELEMENT title (#PCDATA)>"
1036  "<!ELEMENT books (title,authors)>"
1037  "<element />";
1038 
1039  TiXmlDocument doc;
1040  doc.Parse( doctype );
1041  doc.SaveFile( "test7.xml" );
1042  doc.Clear();
1043  doc.LoadFile( "test7.xml" );
1044 
1045  TiXmlHandle docH( &doc );
1046  TiXmlUnknown* unknown = docH.Child( 1 ).Unknown();
1047  XmlTest( "Correct value of unknown.", "!DOCTYPE PLAY SYSTEM 'play.dtd'", unknown->Value() );
1048  #ifdef TIXML_USE_STL
1049  TiXmlNode* node = docH.Child( 2 ).Node();
1050  std::string str;
1051  str << (*node);
1052  XmlTest( "Correct streaming of unknown.", "<!ELEMENT title (#PCDATA)>", str.c_str() );
1053  #endif
1054  }
1055 
1056  {
1057  // [ 791411 ] Formatting bug
1058  // Comments do not stream out correctly.
1059  const char* doctype =
1060  "<!-- Somewhat<evil> -->";
1061  TiXmlDocument doc;
1062  doc.Parse( doctype );
1063 
1064  TiXmlHandle docH( &doc );
1065  TiXmlComment* comment = docH.Child( 0 ).Node()->ToComment();
1066 
1067  XmlTest( "Comment formatting.", " Somewhat<evil> ", comment->Value() );
1068  #ifdef TIXML_USE_STL
1069  std::string str;
1070  str << (*comment);
1071  XmlTest( "Comment streaming.", "<!-- Somewhat<evil> -->", str.c_str() );
1072  #endif
1073  }
1074 
1075  {
1076  // [ 870502 ] White space issues
1077  TiXmlDocument doc;
1078  TiXmlText* text;
1079  TiXmlHandle docH( &doc );
1080 
1081  const char* doctype0 = "<element> This has leading and trailing space </element>";
1082  const char* doctype1 = "<element>This has internal space</element>";
1083  const char* doctype2 = "<element> This has leading, trailing, and internal space </element>";
1084 
1086  doc.Clear();
1087  doc.Parse( doctype0 );
1088  text = docH.FirstChildElement( "element" ).Child( 0 ).Text();
1089  XmlTest( "White space kept.", " This has leading and trailing space ", text->Value() );
1090 
1091  doc.Clear();
1092  doc.Parse( doctype1 );
1093  text = docH.FirstChildElement( "element" ).Child( 0 ).Text();
1094  XmlTest( "White space kept.", "This has internal space", text->Value() );
1095 
1096  doc.Clear();
1097  doc.Parse( doctype2 );
1098  text = docH.FirstChildElement( "element" ).Child( 0 ).Text();
1099  XmlTest( "White space kept.", " This has leading, trailing, and internal space ", text->Value() );
1100 
1102  doc.Clear();
1103  doc.Parse( doctype0 );
1104  text = docH.FirstChildElement( "element" ).Child( 0 ).Text();
1105  XmlTest( "White space condensed.", "This has leading and trailing space", text->Value() );
1106 
1107  doc.Clear();
1108  doc.Parse( doctype1 );
1109  text = docH.FirstChildElement( "element" ).Child( 0 ).Text();
1110  XmlTest( "White space condensed.", "This has internal space", text->Value() );
1111 
1112  doc.Clear();
1113  doc.Parse( doctype2 );
1114  text = docH.FirstChildElement( "element" ).Child( 0 ).Text();
1115  XmlTest( "White space condensed.", "This has leading, trailing, and internal space", text->Value() );
1116  }
1117 
1118  {
1119  // Double attributes
1120  const char* doctype = "<element attr='red' attr='blue' />";
1121 
1122  TiXmlDocument doc;
1123  doc.Parse( doctype );
1124 
1125  XmlTest( "Parsing repeated attributes.", true, doc.Error() ); // is an error to tinyxml (didn't use to be, but caused issues)
1126  //XmlTest( "Parsing repeated attributes.", "blue", doc.FirstChildElement( "element" )->Attribute( "attr" ) );
1127  }
1128 
1129  {
1130  // Embedded null in stream.
1131  const char* doctype = "<element att\0r='red' attr='blue' />";
1132 
1133  TiXmlDocument doc;
1134  doc.Parse( doctype );
1135  XmlTest( "Embedded null throws error.", true, doc.Error() );
1136 
1137  #ifdef TIXML_USE_STL
1138  istringstream strm( doctype );
1139  doc.Clear();
1140  doc.ClearError();
1141  strm >> doc;
1142  XmlTest( "Embedded null throws error.", true, doc.Error() );
1143  #endif
1144  }
1145 
1146  {
1147  // Legacy mode test. (This test may only pass on a western system)
1148  const char* str =
1149  "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"
1150  "<�>"
1151  "C�nt�nt������� "</�>"; TiXmlDocument doc; doc.Parse( str ); TiXmlHandle docHandle( &doc ); TiXmlHandle aHandle = docHandle.FirstChildElement( "�" ); TiXmlHandle tHandle = aHandle.Child( 0 ); assert( aHandle.Element() ); assert( tHandle.Text() ); XmlTest( "ISO-8859-1 Parsing.", "C�nt�nt�������", tHandle.Text()->Value() ); } { // Empty documents should return TIXML_ERROR_PARSING_EMPTY, bug 1070717 const char* str = " "; TiXmlDocument doc; doc.Parse( str ); XmlTest( "Empty document error TIXML_ERROR_DOCUMENT_EMPTY", TiXmlBase::TIXML_ERROR_DOCUMENT_EMPTY, doc.ErrorId() ); } #ifndef TIXML_USE_STL { // String equality. [ 1006409 ] string operator==/!= no worky in all cases TiXmlString temp; XmlTest( "Empty tinyxml string compare equal", ( temp == "" ), true ); TiXmlString foo; TiXmlString bar( "" ); XmlTest( "Empty tinyxml string compare equal", ( foo == bar ), true ); } #endif { // Bug [ 1195696 ] from marlonism TiXmlBase::SetCondenseWhiteSpace(false); TiXmlDocument xml; xml.Parse("<text><break/>This hangs</text>"); XmlTest( "Test safe error return.", xml.Error(), false ); } { // Bug [ 1243992 ] - another infinite loop TiXmlDocument doc; doc.SetCondenseWhiteSpace(false); doc.Parse("<p><pb></pb>test</p>"); } { // Low entities TiXmlDocument xml; xml.Parse( "<test>&#x0e;</test>" ); const char result[] = { 0x0e, 0 }; XmlTest( "Low entities.", xml.FirstChildElement()->GetText(), result ); xml.Print(); } { // Bug [ 1451649 ] Attribute values with trailing quotes not handled correctly TiXmlDocument xml; xml.Parse( "<foo attribute=bar\" />" ); XmlTest( "Throw error with bad end quotes.", xml.Error(), true ); } #ifdef TIXML_USE_STL { // Bug [ 1449463 ] Consider generic query TiXmlDocument xml; xml.Parse( "<foo bar='3' barStr='a string'/>" ); TiXmlElement* ele = xml.FirstChildElement(); double d; int i; float f; bool b; std::string str; XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "bar", &d ), TIXML_SUCCESS ); XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "bar", &i ), TIXML_SUCCESS ); XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "bar", &f ), TIXML_SUCCESS ); XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "bar", &b ), TIXML_WRONG_TYPE ); XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "nobar", &b ), TIXML_NO_ATTRIBUTE ); XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "barStr", &str ), TIXML_SUCCESS ); XmlTest( "QueryValueAttribute", (d==3.0), true ); XmlTest( "QueryValueAttribute", (i==3), true ); XmlTest( "QueryValueAttribute", (f==3.0f), true ); XmlTest( "QueryValueAttribute", (str==std::string( "a string" )), true ); } #endif #ifdef TIXML_USE_STL { // [ 1505267 ] redundant malloc in TiXmlElement::Attribute TiXmlDocument xml; xml.Parse( "<foo bar='3' />" ); TiXmlElement* ele = xml.FirstChildElement(); double d; int i; std::string bar = "bar"; const std::string* atrrib = ele->Attribute( bar ); ele->Attribute( bar, &d ); ele->Attribute( bar, &i ); XmlTest( "Attribute", atrrib->empty(), false ); XmlTest( "Attribute", (d==3.0), true ); XmlTest( "Attribute", (i==3), true ); } #endif { // [ 1356059 ] Allow TiXMLDocument to only be at the top level TiXmlDocument xml, xml2; xml.InsertEndChild( xml2 ); XmlTest( "Document only at top level.", xml.Error(), true ); XmlTest( "Document only at top level.", xml.ErrorId(), TiXmlBase::TIXML_ERROR_DOCUMENT_TOP_ONLY ); } { // [ 1663758 ] Failure to report error on bad XML TiXmlDocument xml; xml.Parse("<x>"); XmlTest("Missing end tag at end of input", xml.Error(), true); xml.Parse("<x> "); XmlTest("Missing end tag with trailing whitespace", xml.Error(), true); } { // [ 1635701 ] fail to parse files with a tag separated into two lines // I'm not sure this is a bug. Marked 'pending' for feedback. TiXmlDocument xml; xml.Parse( "<title><p>text</p\n><title>" ); //xml.Print(); //XmlTest( "Tag split by newline", xml.Error(), false ); } #ifdef TIXML_USE_STL { // [ 1475201 ] TinyXML parses entities in comments TiXmlDocument xml; istringstream parse1( "<!-- declarations for <head> & <body> -->" "<!-- far &amp; away -->" ); parse1 >> xml; TiXmlNode* e0 = xml.FirstChild(); TiXmlNode* e1 = e0->NextSibling(); TiXmlComment* c0 = e0->ToComment(); TiXmlComment* c1 = e1->ToComment(); XmlTest( "Comments ignore entities.", " declarations for <head> & <body> ", c0->Value(), true ); XmlTest( "Comments ignore entities.", " far &amp; away ", c1->Value(), true ); } #endif { // [ 1475201 ] TinyXML parses entities in comments TiXmlDocument xml; xml.Parse("<!-- declarations for <head> & <body> -->" "<!-- far &amp; away -->" ); TiXmlNode* e0 = xml.FirstChild(); TiXmlNode* e1 = e0->NextSibling(); TiXmlComment* c0 = e0->ToComment(); TiXmlComment* c1 = e1->ToComment(); XmlTest( "Comments ignore entities.", " declarations for <head> & <body> ", c0->Value(), true ); XmlTest( "Comments ignore entities.", " far &amp; away ", c1->Value(), true ); } { TiXmlDocument xml; xml.Parse( "<Parent>" "<child1 att=''/>" "<!-- With this comment, child2 will not be parsed! -->" "<child2 att=''/>" "</Parent>" ); int count = 0; TiXmlNode* ele = 0; while ( (ele = xml.FirstChildElement( "Parent" )->IterateChildren( ele ) ) != 0 ) { ++count; } XmlTest( "Comments iterate correctly.", 3, count ); } { // trying to repro ]1874301]. If it doesn't go into an infinite loop, all is well. unsigned char buf[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?><feed><![CDATA[Test XMLblablablalblbl"; buf[60] = 239; buf[61] = 0; TiXmlDocument doc; doc.Parse( (const char*)buf); } { // bug 1827248 Error while parsing a little bit malformed file // Actually not malformed - should work. TiXmlDocument xml; xml.Parse( "<attributelist> </attributelist >" ); XmlTest( "Handle end tag whitespace", false, xml.Error() ); } { // This one must not result in an infinite loop TiXmlDocument xml; xml.Parse( "<infinite>loop" ); XmlTest( "Infinite loop test.", true, true ); } { // 1709904 - can not repro the crash { TiXmlDocument xml; xml.Parse( "<tag>/</tag>" ); XmlTest( "Odd XML parsing.", xml.FirstChild()->Value(), "tag" ); } /* Could not repro. { TiXmlDocument xml; xml.LoadFile( "EQUI_Inventory.xml" ); //XmlTest( "Odd XML parsing.", xml.FirstChildElement()->Value(), "XML" ); TiXmlPrinter printer; xml.Accept( &printer ); fprintf( stdout, "%s", printer.CStr() ); }*/ } /* 1417717 experiment { TiXmlDocument xml; xml.Parse("<text>Dan & Tracie</text>"); xml.Print(stdout); } { TiXmlDocument xml; xml.Parse("<text>Dan &foo; Tracie</text>"); xml.Print(stdout); } */ #if defined( WIN32 ) && defined( TUNE ) _CrtMemCheckpoint( &endMemState ); //_CrtMemDumpStatistics( &endMemState ); _CrtMemState diffMemState; _CrtMemDifference( &diffMemState, &startMemState, &endMemState ); _CrtMemDumpStatistics( &diffMemState ); #endif printf ("\nPass %d, Fail %d\n", gPass, gFail); return gFail; } "
1152  "</�>";
1153 
1154  TiXmlDocument doc;
1155  doc.Parse( str );
1156 
1157  TiXmlHandle docHandle( &doc );
1158  TiXmlHandle aHandle = docHandle.FirstChildElement( "� ); TiXmlHandle tHandle = aHandle.Child( 0 ); assert( aHandle.Element() ); assert( tHandle.Text() ); XmlTest( "ISO-8859-1 Parsing.", "C�nt�nt�������", tHandle.Text()->Value() ); } { // Empty documents should return TIXML_ERROR_PARSING_EMPTY, bug 1070717 const char* str = " "; TiXmlDocument doc; doc.Parse( str ); XmlTest( "Empty document error TIXML_ERROR_DOCUMENT_EMPTY", TiXmlBase::TIXML_ERROR_DOCUMENT_EMPTY, doc.ErrorId() ); } #ifndef TIXML_USE_STL { // String equality. [ 1006409 ] string operator==/!= no worky in all cases TiXmlString temp; XmlTest( "Empty tinyxml string compare equal", ( temp == "" ), true ); TiXmlString foo; TiXmlString bar( "" ); XmlTest( "Empty tinyxml string compare equal", ( foo == bar ), true ); } #endif { // Bug [ 1195696 ] from marlonism TiXmlBase::SetCondenseWhiteSpace(false); TiXmlDocument xml; xml.Parse("<text><break/>This hangs</text>"); XmlTest( "Test safe error return.", xml.Error(), false ); } { // Bug [ 1243992 ] - another infinite loop TiXmlDocument doc; doc.SetCondenseWhiteSpace(false); doc.Parse("<p><pb></pb>test</p>"); } { // Low entities TiXmlDocument xml; xml.Parse( "<test>&#x0e;</test>" ); const char result[] = { 0x0e, 0 }; XmlTest( "Low entities.", xml.FirstChildElement()->GetText(), result ); xml.Print(); } { // Bug [ 1451649 ] Attribute values with trailing quotes not handled correctly TiXmlDocument xml; xml.Parse( "<foo attribute=bar\" />" ); XmlTest( "Throw error with bad end quotes.", xml.Error(), true ); } #ifdef TIXML_USE_STL { // Bug [ 1449463 ] Consider generic query TiXmlDocument xml; xml.Parse( "<foo bar='3' barStr='a string'/>" ); TiXmlElement* ele = xml.FirstChildElement(); double d; int i; float f; bool b; std::string str; XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "bar", &d ), TIXML_SUCCESS ); XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "bar", &i ), TIXML_SUCCESS ); XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "bar", &f ), TIXML_SUCCESS ); XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "bar", &b ), TIXML_WRONG_TYPE ); XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "nobar", &b ), TIXML_NO_ATTRIBUTE ); XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "barStr", &str ), TIXML_SUCCESS ); XmlTest( "QueryValueAttribute", (d==3.0), true ); XmlTest( "QueryValueAttribute", (i==3), true ); XmlTest( "QueryValueAttribute", (f==3.0f), true ); XmlTest( "QueryValueAttribute", (str==std::string( "a string" )), true ); } #endif #ifdef TIXML_USE_STL { // [ 1505267 ] redundant malloc in TiXmlElement::Attribute TiXmlDocument xml; xml.Parse( "<foo bar='3' />" ); TiXmlElement* ele = xml.FirstChildElement(); double d; int i; std::string bar = "bar"; const std::string* atrrib = ele->Attribute( bar ); ele->Attribute( bar, &d ); ele->Attribute( bar, &i ); XmlTest( "Attribute", atrrib->empty(), false ); XmlTest( "Attribute", (d==3.0), true ); XmlTest( "Attribute", (i==3), true ); } #endif { // [ 1356059 ] Allow TiXMLDocument to only be at the top level TiXmlDocument xml, xml2; xml.InsertEndChild( xml2 ); XmlTest( "Document only at top level.", xml.Error(), true ); XmlTest( "Document only at top level.", xml.ErrorId(), TiXmlBase::TIXML_ERROR_DOCUMENT_TOP_ONLY ); } { // [ 1663758 ] Failure to report error on bad XML TiXmlDocument xml; xml.Parse("<x>"); XmlTest("Missing end tag at end of input", xml.Error(), true); xml.Parse("<x> "); XmlTest("Missing end tag with trailing whitespace", xml.Error(), true); } { // [ 1635701 ] fail to parse files with a tag separated into two lines // I'm not sure this is a bug. Marked 'pending' for feedback. TiXmlDocument xml; xml.Parse( "<title><p>text</p\n><title>" ); //xml.Print(); //XmlTest( "Tag split by newline", xml.Error(), false ); } #ifdef TIXML_USE_STL { // [ 1475201 ] TinyXML parses entities in comments TiXmlDocument xml; istringstream parse1( "<!-- declarations for <head> & <body> -->" "<!-- far &amp; away -->" ); parse1 >> xml; TiXmlNode* e0 = xml.FirstChild(); TiXmlNode* e1 = e0->NextSibling(); TiXmlComment* c0 = e0->ToComment(); TiXmlComment* c1 = e1->ToComment(); XmlTest( "Comments ignore entities.", " declarations for <head> & <body> ", c0->Value(), true ); XmlTest( "Comments ignore entities.", " far &amp; away ", c1->Value(), true ); } #endif { // [ 1475201 ] TinyXML parses entities in comments TiXmlDocument xml; xml.Parse("<!-- declarations for <head> & <body> -->" "<!-- far &amp; away -->" ); TiXmlNode* e0 = xml.FirstChild(); TiXmlNode* e1 = e0->NextSibling(); TiXmlComment* c0 = e0->ToComment(); TiXmlComment* c1 = e1->ToComment(); XmlTest( "Comments ignore entities.", " declarations for <head> & <body> ", c0->Value(), true ); XmlTest( "Comments ignore entities.", " far &amp; away ", c1->Value(), true ); } { TiXmlDocument xml; xml.Parse( "<Parent>" "<child1 att=''/>" "<!-- With this comment, child2 will not be parsed! -->" "<child2 att=''/>" "</Parent>" ); int count = 0; TiXmlNode* ele = 0; while ( (ele = xml.FirstChildElement( "Parent" )->IterateChildren( ele ) ) != 0 ) { ++count; } XmlTest( "Comments iterate correctly.", 3, count ); } { // trying to repro ]1874301]. If it doesn't go into an infinite loop, all is well. unsigned char buf[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?><feed><![CDATA[Test XMLblablablalblbl"; buf[60] = 239; buf[61] = 0; TiXmlDocument doc; doc.Parse( (const char*)buf); } { // bug 1827248 Error while parsing a little bit malformed file // Actually not malformed - should work. TiXmlDocument xml; xml.Parse( "<attributelist> </attributelist >" ); XmlTest( "Handle end tag whitespace", false, xml.Error() ); } { // This one must not result in an infinite loop TiXmlDocument xml; xml.Parse( "<infinite>loop" ); XmlTest( "Infinite loop test.", true, true ); } { // 1709904 - can not repro the crash { TiXmlDocument xml; xml.Parse( "<tag>/</tag>" ); XmlTest( "Odd XML parsing.", xml.FirstChild()->Value(), "tag" ); } /* Could not repro. { TiXmlDocument xml; xml.LoadFile( "EQUI_Inventory.xml" ); //XmlTest( "Odd XML parsing.", xml.FirstChildElement()->Value(), "XML" ); TiXmlPrinter printer; xml.Accept( &printer ); fprintf( stdout, "%s", printer.CStr() ); }*/ } /* 1417717 experiment { TiXmlDocument xml; xml.Parse("<text>Dan & Tracie</text>"); xml.Print(stdout); } { TiXmlDocument xml; xml.Parse("<text>Dan &foo; Tracie</text>"); xml.Print(stdout); } */ #if defined( WIN32 ) && defined( TUNE ) _CrtMemCheckpoint( &endMemState ); //_CrtMemDumpStatistics( &endMemState ); _CrtMemState diffMemState; _CrtMemDifference( &diffMemState, &startMemState, &endMemState ); _CrtMemDumpStatistics( &diffMemState ); #endif printf ("\nPass %d, Fail %d\n", gPass, gFail); return gFail; } " );
1159  TiXmlHandle tHandle = aHandle.Child( 0 );
1160  assert( aHandle.Element() );
1161  assert( tHandle.Text() );
1162  XmlTest( "ISO-8859-1 Parsing.", "C�nt�nt�������, tHandle.Text()->Value() ); } { // Empty documents should return TIXML_ERROR_PARSING_EMPTY, bug 1070717 const char* str = " "; TiXmlDocument doc; doc.Parse( str ); XmlTest( "Empty document error TIXML_ERROR_DOCUMENT_EMPTY", TiXmlBase::TIXML_ERROR_DOCUMENT_EMPTY, doc.ErrorId() ); } #ifndef TIXML_USE_STL { // String equality. [ 1006409 ] string operator==/!= no worky in all cases TiXmlString temp; XmlTest( "Empty tinyxml string compare equal", ( temp == "" ), true ); TiXmlString foo; TiXmlString bar( "" ); XmlTest( "Empty tinyxml string compare equal", ( foo == bar ), true ); } #endif { // Bug [ 1195696 ] from marlonism TiXmlBase::SetCondenseWhiteSpace(false); TiXmlDocument xml; xml.Parse("<text><break/>This hangs</text>"); XmlTest( "Test safe error return.", xml.Error(), false ); } { // Bug [ 1243992 ] - another infinite loop TiXmlDocument doc; doc.SetCondenseWhiteSpace(false); doc.Parse("<p><pb></pb>test</p>"); } { // Low entities TiXmlDocument xml; xml.Parse( "<test>&#x0e;</test>" ); const char result[] = { 0x0e, 0 }; XmlTest( "Low entities.", xml.FirstChildElement()->GetText(), result ); xml.Print(); } { // Bug [ 1451649 ] Attribute values with trailing quotes not handled correctly TiXmlDocument xml; xml.Parse( "<foo attribute=bar\" />" ); XmlTest( "Throw error with bad end quotes.", xml.Error(), true ); } #ifdef TIXML_USE_STL { // Bug [ 1449463 ] Consider generic query TiXmlDocument xml; xml.Parse( "<foo bar='3' barStr='a string'/>" ); TiXmlElement* ele = xml.FirstChildElement(); double d; int i; float f; bool b; std::string str; XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "bar", &d ), TIXML_SUCCESS ); XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "bar", &i ), TIXML_SUCCESS ); XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "bar", &f ), TIXML_SUCCESS ); XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "bar", &b ), TIXML_WRONG_TYPE ); XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "nobar", &b ), TIXML_NO_ATTRIBUTE ); XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "barStr", &str ), TIXML_SUCCESS ); XmlTest( "QueryValueAttribute", (d==3.0), true ); XmlTest( "QueryValueAttribute", (i==3), true ); XmlTest( "QueryValueAttribute", (f==3.0f), true ); XmlTest( "QueryValueAttribute", (str==std::string( "a string" )), true ); } #endif #ifdef TIXML_USE_STL { // [ 1505267 ] redundant malloc in TiXmlElement::Attribute TiXmlDocument xml; xml.Parse( "<foo bar='3' />" ); TiXmlElement* ele = xml.FirstChildElement(); double d; int i; std::string bar = "bar"; const std::string* atrrib = ele->Attribute( bar ); ele->Attribute( bar, &d ); ele->Attribute( bar, &i ); XmlTest( "Attribute", atrrib->empty(), false ); XmlTest( "Attribute", (d==3.0), true ); XmlTest( "Attribute", (i==3), true ); } #endif { // [ 1356059 ] Allow TiXMLDocument to only be at the top level TiXmlDocument xml, xml2; xml.InsertEndChild( xml2 ); XmlTest( "Document only at top level.", xml.Error(), true ); XmlTest( "Document only at top level.", xml.ErrorId(), TiXmlBase::TIXML_ERROR_DOCUMENT_TOP_ONLY ); } { // [ 1663758 ] Failure to report error on bad XML TiXmlDocument xml; xml.Parse("<x>"); XmlTest("Missing end tag at end of input", xml.Error(), true); xml.Parse("<x> "); XmlTest("Missing end tag with trailing whitespace", xml.Error(), true); } { // [ 1635701 ] fail to parse files with a tag separated into two lines // I'm not sure this is a bug. Marked 'pending' for feedback. TiXmlDocument xml; xml.Parse( "<title><p>text</p\n><title>" ); //xml.Print(); //XmlTest( "Tag split by newline", xml.Error(), false ); } #ifdef TIXML_USE_STL { // [ 1475201 ] TinyXML parses entities in comments TiXmlDocument xml; istringstream parse1( "<!-- declarations for <head> & <body> -->" "<!-- far &amp; away -->" ); parse1 >> xml; TiXmlNode* e0 = xml.FirstChild(); TiXmlNode* e1 = e0->NextSibling(); TiXmlComment* c0 = e0->ToComment(); TiXmlComment* c1 = e1->ToComment(); XmlTest( "Comments ignore entities.", " declarations for <head> & <body> ", c0->Value(), true ); XmlTest( "Comments ignore entities.", " far &amp; away ", c1->Value(), true ); } #endif { // [ 1475201 ] TinyXML parses entities in comments TiXmlDocument xml; xml.Parse("<!-- declarations for <head> & <body> -->" "<!-- far &amp; away -->" ); TiXmlNode* e0 = xml.FirstChild(); TiXmlNode* e1 = e0->NextSibling(); TiXmlComment* c0 = e0->ToComment(); TiXmlComment* c1 = e1->ToComment(); XmlTest( "Comments ignore entities.", " declarations for <head> & <body> ", c0->Value(), true ); XmlTest( "Comments ignore entities.", " far &amp; away ", c1->Value(), true ); } { TiXmlDocument xml; xml.Parse( "<Parent>" "<child1 att=''/>" "<!-- With this comment, child2 will not be parsed! -->" "<child2 att=''/>" "</Parent>" ); int count = 0; TiXmlNode* ele = 0; while ( (ele = xml.FirstChildElement( "Parent" )->IterateChildren( ele ) ) != 0 ) { ++count; } XmlTest( "Comments iterate correctly.", 3, count ); } { // trying to repro ]1874301]. If it doesn't go into an infinite loop, all is well. unsigned char buf[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?><feed><![CDATA[Test XMLblablablalblbl"; buf[60] = 239; buf[61] = 0; TiXmlDocument doc; doc.Parse( (const char*)buf); } { // bug 1827248 Error while parsing a little bit malformed file // Actually not malformed - should work. TiXmlDocument xml; xml.Parse( "<attributelist> </attributelist >" ); XmlTest( "Handle end tag whitespace", false, xml.Error() ); } { // This one must not result in an infinite loop TiXmlDocument xml; xml.Parse( "<infinite>loop" ); XmlTest( "Infinite loop test.", true, true ); } { // 1709904 - can not repro the crash { TiXmlDocument xml; xml.Parse( "<tag>/</tag>" ); XmlTest( "Odd XML parsing.", xml.FirstChild()->Value(), "tag" ); } /* Could not repro. { TiXmlDocument xml; xml.LoadFile( "EQUI_Inventory.xml" ); //XmlTest( "Odd XML parsing.", xml.FirstChildElement()->Value(), "XML" ); TiXmlPrinter printer; xml.Accept( &printer ); fprintf( stdout, "%s", printer.CStr() ); }*/ } /* 1417717 experiment { TiXmlDocument xml; xml.Parse("<text>Dan & Tracie</text>"); xml.Print(stdout); } { TiXmlDocument xml; xml.Parse("<text>Dan &foo; Tracie</text>"); xml.Print(stdout); } */ #if defined( WIN32 ) && defined( TUNE ) _CrtMemCheckpoint( &endMemState ); //_CrtMemDumpStatistics( &endMemState ); _CrtMemState diffMemState; _CrtMemDifference( &diffMemState, &startMemState, &endMemState ); _CrtMemDumpStatistics( &diffMemState ); #endif printf ("\nPass %d, Fail %d\n", gPass, gFail); return gFail; } ", tHandle.Text()->Value() );
1163  }
1164 
1165  {
1166  // Empty documents should return TIXML_ERROR_PARSING_EMPTY, bug 1070717
1167  const char* str = " ";
1168  TiXmlDocument doc;
1169  doc.Parse( str );
1170  XmlTest( "Empty document error TIXML_ERROR_DOCUMENT_EMPTY", TiXmlBase::TIXML_ERROR_DOCUMENT_EMPTY, doc.ErrorId() );
1171  }
1172  #ifndef TIXML_USE_STL
1173  {
1174  // String equality. [ 1006409 ] string operator==/!= no worky in all cases
1175  TiXmlString temp;
1176  XmlTest( "Empty tinyxml string compare equal", ( temp == "" ), true );
1177 
1178  TiXmlString foo;
1179  TiXmlString bar( "" );
1180  XmlTest( "Empty tinyxml string compare equal", ( foo == bar ), true );
1181  }
1182 
1183  #endif
1184  {
1185  // Bug [ 1195696 ] from marlonism
1187  TiXmlDocument xml;
1188  xml.Parse("<text><break/>This hangs</text>");
1189  XmlTest( "Test safe error return.", xml.Error(), false );
1190  }
1191 
1192  {
1193  // Bug [ 1243992 ] - another infinite loop
1194  TiXmlDocument doc;
1195  doc.SetCondenseWhiteSpace(false);
1196  doc.Parse("<p><pb></pb>test</p>");
1197  }
1198  {
1199  // Low entities
1200  TiXmlDocument xml;
1201  xml.Parse( "<test>&#x0e;</test>" );
1202  const char result[] = { 0x0e, 0 };
1203  XmlTest( "Low entities.", xml.FirstChildElement()->GetText(), result );
1204  xml.Print();
1205  }
1206  {
1207  // Bug [ 1451649 ] Attribute values with trailing quotes not handled correctly
1208  TiXmlDocument xml;
1209  xml.Parse( "<foo attribute=bar\" />" );
1210  XmlTest( "Throw error with bad end quotes.", xml.Error(), true );
1211  }
1212  #ifdef TIXML_USE_STL
1213  {
1214  // Bug [ 1449463 ] Consider generic query
1215  TiXmlDocument xml;
1216  xml.Parse( "<foo bar='3' barStr='a string'/>" );
1217 
1218  TiXmlElement* ele = xml.FirstChildElement();
1219  double d;
1220  int i;
1221  float f;
1222  bool b;
1223  std::string str;
1224 
1225  XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "bar", &d ), TIXML_SUCCESS );
1226  XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "bar", &i ), TIXML_SUCCESS );
1227  XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "bar", &f ), TIXML_SUCCESS );
1228  XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "bar", &b ), TIXML_WRONG_TYPE );
1229  XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "nobar", &b ), TIXML_NO_ATTRIBUTE );
1230  XmlTest( "QueryValueAttribute", ele->QueryValueAttribute( "barStr", &str ), TIXML_SUCCESS );
1231 
1232  XmlTest( "QueryValueAttribute", (d==3.0), true );
1233  XmlTest( "QueryValueAttribute", (i==3), true );
1234  XmlTest( "QueryValueAttribute", (f==3.0f), true );
1235  XmlTest( "QueryValueAttribute", (str==std::string( "a string" )), true );
1236  }
1237  #endif
1238 
1239  #ifdef TIXML_USE_STL
1240  {
1241  // [ 1505267 ] redundant malloc in TiXmlElement::Attribute
1242  TiXmlDocument xml;
1243  xml.Parse( "<foo bar='3' />" );
1244  TiXmlElement* ele = xml.FirstChildElement();
1245  double d;
1246  int i;
1247 
1248  std::string bar = "bar";
1249 
1250  const std::string* atrrib = ele->Attribute( bar );
1251  ele->Attribute( bar, &d );
1252  ele->Attribute( bar, &i );
1253 
1254  XmlTest( "Attribute", atrrib->empty(), false );
1255  XmlTest( "Attribute", (d==3.0), true );
1256  XmlTest( "Attribute", (i==3), true );
1257  }
1258  #endif
1259 
1260  {
1261  // [ 1356059 ] Allow TiXMLDocument to only be at the top level
1262  TiXmlDocument xml, xml2;
1263  xml.InsertEndChild( xml2 );
1264  XmlTest( "Document only at top level.", xml.Error(), true );
1265  XmlTest( "Document only at top level.", xml.ErrorId(), TiXmlBase::TIXML_ERROR_DOCUMENT_TOP_ONLY );
1266  }
1267 
1268  {
1269  // [ 1663758 ] Failure to report error on bad XML
1270  TiXmlDocument xml;
1271  xml.Parse("<x>");
1272  XmlTest("Missing end tag at end of input", xml.Error(), true);
1273  xml.Parse("<x> ");
1274  XmlTest("Missing end tag with trailing whitespace", xml.Error(), true);
1275  }
1276 
1277  {
1278  // [ 1635701 ] fail to parse files with a tag separated into two lines
1279  // I'm not sure this is a bug. Marked 'pending' for feedback.
1280  TiXmlDocument xml;
1281  xml.Parse( "<title><p>text</p\n><title>" );
1282  //xml.Print();
1283  //XmlTest( "Tag split by newline", xml.Error(), false );
1284  }
1285 
1286  #ifdef TIXML_USE_STL
1287  {
1288  // [ 1475201 ] TinyXML parses entities in comments
1289  TiXmlDocument xml;
1290  istringstream parse1( "<!-- declarations for <head> & <body> -->"
1291  "<!-- far &amp; away -->" );
1292  parse1 >> xml;
1293 
1294  TiXmlNode* e0 = xml.FirstChild();
1295  TiXmlNode* e1 = e0->NextSibling();
1296  TiXmlComment* c0 = e0->ToComment();
1297  TiXmlComment* c1 = e1->ToComment();
1298 
1299  XmlTest( "Comments ignore entities.", " declarations for <head> & <body> ", c0->Value(), true );
1300  XmlTest( "Comments ignore entities.", " far &amp; away ", c1->Value(), true );
1301  }
1302  #endif
1303 
1304  {
1305  // [ 1475201 ] TinyXML parses entities in comments
1306  TiXmlDocument xml;
1307  xml.Parse("<!-- declarations for <head> & <body> -->"
1308  "<!-- far &amp; away -->" );
1309 
1310  TiXmlNode* e0 = xml.FirstChild();
1311  TiXmlNode* e1 = e0->NextSibling();
1312  TiXmlComment* c0 = e0->ToComment();
1313  TiXmlComment* c1 = e1->ToComment();
1314 
1315  XmlTest( "Comments ignore entities.", " declarations for <head> & <body> ", c0->Value(), true );
1316  XmlTest( "Comments ignore entities.", " far &amp; away ", c1->Value(), true );
1317  }
1318 
1319  {
1320  TiXmlDocument xml;
1321  xml.Parse( "<Parent>"
1322  "<child1 att=''/>"
1323  "<!-- With this comment, child2 will not be parsed! -->"
1324  "<child2 att=''/>"
1325  "</Parent>" );
1326  int count = 0;
1327 
1328  TiXmlNode* ele = 0;
1329  while ( (ele = xml.FirstChildElement( "Parent" )->IterateChildren( ele ) ) != 0 ) {
1330  ++count;
1331  }
1332  XmlTest( "Comments iterate correctly.", 3, count );
1333  }
1334 
1335  {
1336  // trying to repro ]1874301]. If it doesn't go into an infinite loop, all is well.
1337  unsigned char buf[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?><feed><![CDATA[Test XMLblablablalblbl";
1338  buf[60] = 239;
1339  buf[61] = 0;
1340 
1341  TiXmlDocument doc;
1342  doc.Parse( (const char*)buf);
1343  }
1344 
1345 
1346  {
1347  // bug 1827248 Error while parsing a little bit malformed file
1348  // Actually not malformed - should work.
1349  TiXmlDocument xml;
1350  xml.Parse( "<attributelist> </attributelist >" );
1351  XmlTest( "Handle end tag whitespace", false, xml.Error() );
1352  }
1353 
1354  {
1355  // This one must not result in an infinite loop
1356  TiXmlDocument xml;
1357  xml.Parse( "<infinite>loop" );
1358  XmlTest( "Infinite loop test.", true, true );
1359  }
1360 
1361  {
1362  // 1709904 - can not repro the crash
1363  {
1364  TiXmlDocument xml;
1365  xml.Parse( "<tag>/</tag>" );
1366  XmlTest( "Odd XML parsing.", xml.FirstChild()->Value(), "tag" );
1367  }
1368  /* Could not repro. {
1369  TiXmlDocument xml;
1370  xml.LoadFile( "EQUI_Inventory.xml" );
1371  //XmlTest( "Odd XML parsing.", xml.FirstChildElement()->Value(), "XML" );
1372  TiXmlPrinter printer;
1373  xml.Accept( &printer );
1374  fprintf( stdout, "%s", printer.CStr() );
1375  }*/
1376  }
1377 
1378  /* 1417717 experiment
1379  {
1380  TiXmlDocument xml;
1381  xml.Parse("<text>Dan & Tracie</text>");
1382  xml.Print(stdout);
1383  }
1384  {
1385  TiXmlDocument xml;
1386  xml.Parse("<text>Dan &foo; Tracie</text>");
1387  xml.Print(stdout);
1388  }
1389  */
1390 
1391  #if defined( WIN32 ) && defined( TUNE )
1392  _CrtMemCheckpoint( &endMemState );
1393  //_CrtMemDumpStatistics( &endMemState );
1394 
1395  _CrtMemState diffMemState;
1396  _CrtMemDifference( &diffMemState, &startMemState, &endMemState );
1397  _CrtMemDumpStatistics( &diffMemState );
1398  #endif
1399 
1400  printf ("\nPass %d, Fail %d\n", gPass, gFail);
1401  return gFail;
1402 }
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
TiXmlUnknown * Unknown() const
Definition: tinyxml.h:1720
int main()
Definition: xmltest.cpp:99
const TiXmlElement * RootElement() const
Definition: tinyxml.h:1461
bool Error() const
Definition: tinyxml.h:1469
TiXmlHandle FirstChild() const
Return a handle to the first child node.
Definition: tinyxml.cpp:1641
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
void SetDoubleAttribute(const char *name, double value)
Definition: tinyxml.cpp:769
int ErrorId() const
Definition: tinyxml.h:1477
list temp
Definition: bigtemp.py:9
void SetTabSize(int _tabsize)
Definition: tinyxml.h:1513
void ClearError()
Definition: tinyxml.h:1520
virtual const TiXmlComment * ToComment() const
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:708
virtual void Print(FILE *cfile, int depth) const
Definition: tinyxml.cpp:809
bool LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Definition: tinyxml.cpp:963
int ErrorCol() const
The column where the error occured. See ErrorRow()
Definition: tinyxml.h:1487
TiXmlNode * InsertEndChild(const TiXmlNode &addThis)
Definition: tinyxml.cpp:223
TiXmlNode * InsertBeforeChild(TiXmlNode *beforeThis, const TiXmlNode &addThis)
Definition: tinyxml.cpp:239
virtual const TiXmlDeclaration * ToDeclaration() const
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:711
TiXmlHandle FirstChildElement() const
Return a handle to the first child element.
Definition: tinyxml.cpp:1665
const char * Encoding() const
Encoding. Will return an empty string if none was found.
Definition: tinyxml.h:1320
const TiXmlNode * LastChild() const
Definition: tinyxml.h:540
void Print() const
Definition: tinyxml.h:1528
int ErrorRow() const
Definition: tinyxml.h:1486
TiXmlHandle ChildElement(const char *value, int index) const
Definition: tinyxml.cpp:1746
int Column() const
See Row()
Definition: tinyxml.h:254
const TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
Definition: tinyxml.h:531
const char * ErrorDesc() const
Contains a textual (english) description of the error if one occurs.
Definition: tinyxml.h:1472
void SetAttribute(const char *name, const char *_value)
Definition: tinyxml.cpp:789
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
bool SaveFile() const
Save a file using the current document value. Returns true if successful.
Definition: tinyxml.cpp:969
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
Definition: tinyxml.cpp:461
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
const char * c_str() const
Definition: tinystr.h:137
const TiXmlNode * PreviousSibling() const
Navigate to a sibling node.
Definition: tinyxml.h:623
TiXmlNode * InsertAfterChild(TiXmlNode *afterThis, const TiXmlNode &addThis)
Definition: tinyxml.cpp:272
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:707
TiXmlHandle Child(const char *value, int index) const
Definition: tinyxml.cpp:1708
TiXmlText * Text() const
Definition: tinyxml.h:1716
TiXmlNode * Node() const
Definition: tinyxml.h:1708
static void SetCondenseWhiteSpace(bool condense)
Definition: tinyxml.h:230
const TiXmlElement * NextSiblingElement() const
Definition: tinyxml.cpp:491
void NullLineEndings(char *p)
Definition: xmltest.cpp:81
virtual const char * Parse(const char *p, TiXmlParsingData *data=0, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
TiXmlNode * parent
Definition: tinyxml.h:764
int QueryIntAttribute(const char *name, int *_value) const
Definition: tinyxml.cpp:670
int Row() const
Definition: tinyxml.h:253
TiXmlElement * Element() const
Definition: tinyxml.h:1712
virtual bool Accept(TiXmlVisitor *content) const
Definition: tinyxml.cpp:1165
virtual const TiXmlText * ToText() const
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:710
bool XmlTest(const char *testString, const char *expected, const char *found, bool noEcho=false)
Definition: xmltest.cpp:39
int QueryDoubleAttribute(const char *name, double *_value) const
QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
Definition: tinyxml.cpp:729
const TiXmlNode * IterateChildren(const TiXmlNode *previous) const
Definition: tinyxml.cpp:394
const char * Value() const
Definition: tinyxml.h:496
const TiXmlAttribute * FirstAttribute() const
Access the first attribute in this element.
Definition: tinyxml.h:1093
bool RemoveChild(TiXmlNode *removeThis)
Delete a child of this node.
Definition: tinyxml.cpp:344
const char * GetText() const
Definition: tinyxml.cpp:909
void Clear()
Delete all the children of this node. Does not affect &#39;this&#39;.
Definition: tinyxml.cpp:178
const TiXmlNode * NextSibling() const
Navigate to a sibling node.
Definition: tinyxml.h:640
void SetStreamPrinting()
Definition: tinyxml.h:1780
const char * Attribute(const char *name) const
Definition: tinyxml.cpp:586
const char * CStr()
Return the result.
Definition: tinyxml.h:1784
#define TIXML_STRING
Definition: tinyxml.h:62