U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 1 | #include "tinyxml2.h"
|
| 2 |
|
| 3 | #include <stdio.h>
|
| 4 | #include <stdlib.h>
|
Lee Thomason | ec5a7b4 | 2012-02-13 18:16:52 -0800 | [diff] [blame] | 5 | #include <string.h>
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 6 |
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 7 | #if defined( WIN32 )
|
| 8 | #include <crtdbg.h>
|
| 9 | _CrtMemState startMemState;
|
| 10 | _CrtMemState endMemState;
|
| 11 | #endif
|
Lee Thomason | e9ecdab | 2012-02-13 18:11:20 -0800 | [diff] [blame] | 12 |
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 13 | using namespace tinyxml2;
|
Lee Thomason | ec5a7b4 | 2012-02-13 18:16:52 -0800 | [diff] [blame] | 14 | int gPass = 0;
|
| 15 | int gFail = 0;
|
| 16 |
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 17 | //#define DREAM_ONLY
|
| 18 |
|
| 19 | /*
|
| 20 | int gNew = 0;
|
| 21 | int gNewTotal = 0;
|
| 22 |
|
| 23 | void* operator new( size_t size )
|
| 24 | {
|
| 25 | ++gNew;
|
| 26 | return malloc( size );
|
| 27 | }
|
| 28 |
|
| 29 | void* operator new[]( size_t size )
|
| 30 | {
|
| 31 | ++gNew;
|
| 32 | return malloc( size );
|
| 33 | }
|
| 34 |
|
| 35 | void operator delete[]( void* mem )
|
| 36 | {
|
| 37 | free( mem );
|
| 38 | }
|
| 39 |
|
| 40 | void operator delete( void* mem )
|
| 41 | {
|
| 42 | free( mem );
|
| 43 | }
|
| 44 | */
|
| 45 |
|
| 46 |
|
U-Stream\Lee | 09a11c5 | 2012-02-17 08:31:16 -0800 | [diff] [blame] | 47 | bool XMLTest (const char* testString, const char* expected, const char* found, bool echo=true )
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 48 | {
|
| 49 | bool pass = !strcmp( expected, found );
|
| 50 | if ( pass )
|
| 51 | printf ("[pass]");
|
| 52 | else
|
| 53 | printf ("[fail]");
|
| 54 |
|
U-Stream\Lee | 09a11c5 | 2012-02-17 08:31:16 -0800 | [diff] [blame] | 55 | if ( !echo )
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 56 | printf (" %s\n", testString);
|
| 57 | else
|
| 58 | printf (" %s [%s][%s]\n", testString, expected, found);
|
| 59 |
|
| 60 | if ( pass )
|
| 61 | ++gPass;
|
| 62 | else
|
| 63 | ++gFail;
|
| 64 | return pass;
|
| 65 | }
|
| 66 |
|
| 67 |
|
U-Stream\Lee | 09a11c5 | 2012-02-17 08:31:16 -0800 | [diff] [blame] | 68 | bool XMLTest( const char* testString, int expected, int found, bool echo=true )
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 69 | {
|
| 70 | bool pass = ( expected == found );
|
| 71 | if ( pass )
|
| 72 | printf ("[pass]");
|
| 73 | else
|
| 74 | printf ("[fail]");
|
| 75 |
|
U-Stream\Lee | 09a11c5 | 2012-02-17 08:31:16 -0800 | [diff] [blame] | 76 | if ( !echo )
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 77 | printf (" %s\n", testString);
|
| 78 | else
|
| 79 | printf (" %s [%d][%d]\n", testString, expected, found);
|
| 80 |
|
| 81 | if ( pass )
|
| 82 | ++gPass;
|
| 83 | else
|
| 84 | ++gFail;
|
| 85 | return pass;
|
| 86 | }
|
Lee Thomason | ec5a7b4 | 2012-02-13 18:16:52 -0800 | [diff] [blame] | 87 |
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 88 |
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame^] | 89 | void NullLineEndings( char* p )
|
| 90 | {
|
| 91 | while( p && *p ) {
|
| 92 | if ( *p == '\n' || *p == '\r' ) {
|
| 93 | *p = 0;
|
| 94 | return;
|
| 95 | }
|
| 96 | ++p;
|
| 97 | }
|
| 98 | }
|
| 99 |
|
| 100 |
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 101 | int main( int argc, const char* argv )
|
| 102 | {
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 103 | #if defined( WIN32 )
|
| 104 | _CrtMemCheckpoint( &startMemState );
|
| 105 | #endif
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 106 | #ifndef DREAM_ONLY
|
Lee Thomason | e9ecdab | 2012-02-13 18:11:20 -0800 | [diff] [blame] | 107 | #if 0
|
U-Lama\Lee | 4cee611 | 2011-12-31 14:58:18 -0800 | [diff] [blame] | 108 | {
|
Lee Thomason | fde6a75 | 2012-01-14 18:08:12 -0800 | [diff] [blame] | 109 | static const char* test = "<!--hello world\n"
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 110 | " line 2\r"
|
| 111 | " line 3\r\n"
|
| 112 | " line 4\n\r"
|
| 113 | " line 5\r-->";
|
| 114 |
|
| 115 | XMLDocument doc;
|
| 116 | doc.Parse( test );
|
Lee Thomason | 50adb4c | 2012-02-13 15:07:09 -0800 | [diff] [blame] | 117 | doc.Print();
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 118 | }
|
| 119 | #endif
|
Lee Thomason | 50adb4c | 2012-02-13 15:07:09 -0800 | [diff] [blame] | 120 | #if 0
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 121 | {
|
Lee Thomason | 43f5930 | 2012-02-06 18:18:11 -0800 | [diff] [blame] | 122 | static const char* test[] = { "<element />",
|
| 123 | "<element></element>",
|
| 124 | "<element><subelement/></element>",
|
| 125 | "<element><subelement></subelement></element>",
|
| 126 | "<element><subelement><subsub/></subelement></element>",
|
| 127 | "<!--comment beside elements--><element><subelement></subelement></element>",
|
| 128 | "<!--comment beside elements, this time with spaces--> \n <element> <subelement> \n </subelement> </element>",
|
| 129 | "<element attrib1='foo' attrib2=\"bar\" ></element>",
|
| 130 | "<element attrib1='foo' attrib2=\"bar\" ><subelement attrib3='yeehaa' /></element>",
|
| 131 | "<element>Text inside element.</element>",
|
| 132 | "<element><b></b></element>",
|
| 133 | "<element>Text inside and <b>bolded</b> in the element.</element>",
|
| 134 | "<outer><element>Text inside and <b>bolded</b> in the element.</element></outer>",
|
Lee Thomason | 8ee7989 | 2012-01-25 17:44:30 -0800 | [diff] [blame] | 135 | "<element>This & That.</element>",
|
Lee Thomason | 18d68bd | 2012-01-26 18:17:26 -0800 | [diff] [blame] | 136 | "<element attrib='This<That' />",
|
Lee Thomason | dadcdfa | 2012-01-18 17:55:48 -0800 | [diff] [blame] | 137 | 0
|
| 138 | };
|
Lee Thomason | 6ee99fc | 2012-01-21 18:45:16 -0800 | [diff] [blame] | 139 | for( int i=0; test[i]; ++i ) {
|
Lee Thomason | dadcdfa | 2012-01-18 17:55:48 -0800 | [diff] [blame] | 140 | XMLDocument doc;
|
Lee Thomason | 6ee99fc | 2012-01-21 18:45:16 -0800 | [diff] [blame] | 141 | doc.Parse( test[i] );
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 142 | doc.Print();
|
Lee Thomason | ec975ce | 2012-01-23 11:42:06 -0800 | [diff] [blame] | 143 | printf( "----------------------------------------------\n" );
|
Lee Thomason | dadcdfa | 2012-01-18 17:55:48 -0800 | [diff] [blame] | 144 | }
|
U-Lama\Lee | 4cee611 | 2011-12-31 14:58:18 -0800 | [diff] [blame] | 145 | }
|
Lee Thomason | 50adb4c | 2012-02-13 15:07:09 -0800 | [diff] [blame] | 146 | #endif
|
Lee Thomason | e9ecdab | 2012-02-13 18:11:20 -0800 | [diff] [blame] | 147 | #if 0
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 148 | {
|
| 149 | static const char* test = "<element>Text before.</element>";
|
| 150 | XMLDocument doc;
|
| 151 | doc.Parse( test );
|
| 152 | XMLElement* root = doc.FirstChildElement();
|
| 153 | XMLElement* newElement = doc.NewElement( "Subelement" );
|
| 154 | root->InsertEndChild( newElement );
|
| 155 | doc.Print();
|
| 156 | }
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 157 | {
|
| 158 | XMLDocument* doc = new XMLDocument();
|
| 159 | static const char* test = "<element><sub/></element>";
|
| 160 | doc->Parse( test );
|
| 161 | delete doc;
|
| 162 | }
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 163 | #endif
|
Lee Thomason | e9ecdab | 2012-02-13 18:11:20 -0800 | [diff] [blame] | 164 | {
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame^] | 165 | #if 0
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 166 | // Test: Programmatic DOM
|
Lee Thomason | ec5a7b4 | 2012-02-13 18:16:52 -0800 | [diff] [blame] | 167 | // Build:
|
| 168 | // <element>
|
| 169 | // <!--comment-->
|
| 170 | // <sub attrib="1" />
|
| 171 | // <sub attrib="2" />
|
U-Stream\Lee | 09a11c5 | 2012-02-17 08:31:16 -0800 | [diff] [blame] | 172 | // <sub attrib="3" >& Text!</sub>
|
Lee Thomason | ec5a7b4 | 2012-02-13 18:16:52 -0800 | [diff] [blame] | 173 | // <element>
|
| 174 |
|
Lee Thomason | e9ecdab | 2012-02-13 18:11:20 -0800 | [diff] [blame] | 175 | XMLDocument* doc = new XMLDocument();
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 176 | XMLNode* element = doc->InsertEndChild( doc->NewElement( "element" ) );
|
| 177 |
|
| 178 | XMLElement* sub[3] = { doc->NewElement( "sub" ), doc->NewElement( "sub" ), doc->NewElement( "sub" ) };
|
| 179 | for( int i=0; i<3; ++i ) {
|
| 180 | sub[i]->SetAttribute( "attrib", i );
|
| 181 | }
|
| 182 | element->InsertEndChild( sub[2] );
|
| 183 | XMLNode* comment = element->InsertFirstChild( doc->NewComment( "comment" ) );
|
| 184 | element->InsertAfterChild( comment, sub[0] );
|
| 185 | element->InsertAfterChild( sub[0], sub[1] );
|
U-Stream\Lee | 09a11c5 | 2012-02-17 08:31:16 -0800 | [diff] [blame] | 186 | sub[2]->InsertFirstChild( doc->NewText( "& Text!" ));
|
Lee Thomason | e9ecdab | 2012-02-13 18:11:20 -0800 | [diff] [blame] | 187 | doc->Print();
|
U-Stream\Lee | 09a11c5 | 2012-02-17 08:31:16 -0800 | [diff] [blame] | 188 | XMLTest( "Programmatic DOM", "comment", doc->FirstChildElement( "element" )->FirstChild()->Value() );
|
| 189 | XMLTest( "Programmatic DOM", "0", doc->FirstChildElement( "element" )->FirstChildElement()->Attribute( "attrib" ) );
|
| 190 | XMLTest( "Programmatic DOM", 2, doc->FirstChildElement()->LastChildElement( "sub" )->IntAttribute( "attrib" ) );
|
| 191 | XMLTest( "Programmatic DOM", "& Text!",
|
| 192 | doc->FirstChildElement()->LastChildElement( "sub" )->FirstChild()->ToText()->Value() );
|
U-Stream\Lee | ae25a44 | 2012-02-17 17:48:16 -0800 | [diff] [blame] | 193 |
|
| 194 | // And now deletion:
|
| 195 | element->DeleteChild( sub[2] );
|
| 196 | doc->DeleteNode( comment );
|
| 197 |
|
| 198 | element->FirstChildElement()->SetAttribute( "attrib", true );
|
| 199 | element->LastChildElement()->DeleteAttribute( "attrib" );
|
| 200 |
|
| 201 | XMLTest( "Programmatic DOM", true, doc->FirstChildElement()->FirstChildElement()->BoolAttribute( "attrib" ) );
|
| 202 | int value = 10;
|
| 203 | int result = doc->FirstChildElement()->LastChildElement()->QueryIntAttribute( "attrib", &value );
|
| 204 | XMLTest( "Programmatic DOM", result, NO_ATTRIBUTE );
|
| 205 | XMLTest( "Programmatic DOM", value, 10 );
|
| 206 |
|
| 207 | doc->Print();
|
| 208 |
|
| 209 | XMLStreamer streamer;
|
| 210 | doc->Print( &streamer );
|
| 211 | printf( "%s", streamer.CStr() );
|
| 212 |
|
Lee Thomason | e9ecdab | 2012-02-13 18:11:20 -0800 | [diff] [blame] | 213 | delete doc;
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame^] | 214 | #endif
|
Lee Thomason | e9ecdab | 2012-02-13 18:11:20 -0800 | [diff] [blame] | 215 | }
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 216 | #endif
|
| 217 | {
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame^] | 218 | #if 0
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 219 | // Test: Dream
|
| 220 | // XML1 : 1,187,569 bytes in 31,209 allocations
|
| 221 | // XML2 : 469,073 bytes in 323 allocations
|
| 222 | //int newStart = gNew;
|
| 223 | XMLDocument doc;
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame^] | 224 | doc.LoadFile( "dream.xml" );
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 225 |
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame^] | 226 | doc.SaveFile( "dreamout.xml" );
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 227 | doc.PrintError();
|
| 228 |
|
| 229 | XMLTest( "Dream", "xml version=\"1.0\"",
|
| 230 | doc.FirstChild()->ToDeclaration()->Value() );
|
| 231 | XMLTest( "Dream", true, doc.FirstChild()->NextSibling()->ToUnknown() ? true : false );
|
| 232 | XMLTest( "Dream", "DOCTYPE PLAY SYSTEM \"play.dtd\"",
|
| 233 | doc.FirstChild()->NextSibling()->ToUnknown()->Value() );
|
| 234 | XMLTest( "Dream", "And Robin shall restore amends.",
|
| 235 | doc.LastChild()->LastChild()->LastChild()->LastChild()->LastChildElement()->GetText() );
|
| 236 | XMLTest( "Dream", "And Robin shall restore amends.",
|
| 237 | doc.LastChild()->LastChild()->LastChild()->LastChild()->LastChildElement()->GetText() );
|
| 238 |
|
| 239 | XMLDocument doc2;
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame^] | 240 | doc2.LoadFile( "dreamout.xml" );
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 241 | XMLTest( "Dream-out", "xml version=\"1.0\"",
|
| 242 | doc2.FirstChild()->ToDeclaration()->Value() );
|
| 243 | XMLTest( "Dream-out", true, doc2.FirstChild()->NextSibling()->ToUnknown() ? true : false );
|
| 244 | XMLTest( "Dream-out", "DOCTYPE PLAY SYSTEM \"play.dtd\"",
|
| 245 | doc2.FirstChild()->NextSibling()->ToUnknown()->Value() );
|
| 246 | XMLTest( "Dream-out", "And Robin shall restore amends.",
|
| 247 | doc2.LastChild()->LastChild()->LastChild()->LastChild()->LastChildElement()->GetText() );
|
| 248 |
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame^] | 249 | #endif
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 250 | //gNewTotal = gNew - newStart;
|
| 251 | }
|
Lee Thomason | ec5a7b4 | 2012-02-13 18:16:52 -0800 | [diff] [blame] | 252 |
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame^] | 253 | #if 0
|
| 254 | {
|
| 255 | const char* error = "<?xml version=\"1.0\" standalone=\"no\" ?>\n"
|
| 256 | "<passages count=\"006\" formatversion=\"20020620\">\n"
|
| 257 | " <wrong error>\n"
|
| 258 | "</passages>";
|
| 259 |
|
| 260 | XMLDocument doc;
|
| 261 | doc.Parse( error );
|
| 262 | XMLTest( "Bad XML", doc.ErrorID(), ERROR_PARSING_ATTRIBUTE );
|
| 263 | }
|
| 264 |
|
| 265 | {
|
| 266 | const char* str = "<doc attr0='1' attr1='2.0' attr2='foo' />";
|
| 267 |
|
| 268 | XMLDocument doc;
|
| 269 | doc.Parse( str );
|
| 270 |
|
| 271 | XMLElement* ele = doc.FirstChildElement();
|
| 272 |
|
| 273 | int iVal, result;
|
| 274 | double dVal;
|
| 275 |
|
| 276 | result = ele->QueryDoubleAttribute( "attr0", &dVal );
|
| 277 | XMLTest( "Query attribute: int as double", result, XML_NO_ERROR );
|
| 278 | XMLTest( "Query attribute: int as double", (int)dVal, 1 );
|
| 279 | result = ele->QueryDoubleAttribute( "attr1", &dVal );
|
| 280 | XMLTest( "Query attribute: double as double", (int)dVal, 2 );
|
| 281 | result = ele->QueryIntAttribute( "attr1", &iVal );
|
| 282 | XMLTest( "Query attribute: double as int", result, XML_NO_ERROR );
|
| 283 | XMLTest( "Query attribute: double as int", iVal, 2 );
|
| 284 | result = ele->QueryIntAttribute( "attr2", &iVal );
|
| 285 | XMLTest( "Query attribute: not a number", result, WRONG_ATTRIBUTE_TYPE );
|
| 286 | result = ele->QueryIntAttribute( "bar", &iVal );
|
| 287 | XMLTest( "Query attribute: does not exist", result, NO_ATTRIBUTE );
|
| 288 | }
|
| 289 |
|
| 290 | {
|
| 291 | const char* str = "<doc/>";
|
| 292 |
|
| 293 | XMLDocument doc;
|
| 294 | doc.Parse( str );
|
| 295 |
|
| 296 | XMLElement* ele = doc.FirstChildElement();
|
| 297 |
|
| 298 | int iVal;
|
| 299 | double dVal;
|
| 300 |
|
| 301 | ele->SetAttribute( "str", "strValue" );
|
| 302 | ele->SetAttribute( "int", 1 );
|
| 303 | ele->SetAttribute( "double", -1.0 );
|
| 304 |
|
| 305 | const char* cStr = ele->Attribute( "str" );
|
| 306 | ele->QueryIntAttribute( "int", &iVal );
|
| 307 | ele->QueryDoubleAttribute( "double", &dVal );
|
| 308 |
|
| 309 | XMLTest( "Attribute round trip. c-string.", "strValue", cStr );
|
| 310 | XMLTest( "Attribute round trip. int.", 1, iVal );
|
| 311 | XMLTest( "Attribute round trip. double.", -1, (int)dVal );
|
| 312 | }
|
| 313 |
|
| 314 | #endif
|
| 315 | {
|
| 316 | XMLDocument doc;
|
| 317 | doc.LoadFile( "utf8test.xml" );
|
| 318 |
|
| 319 | // Get the attribute "value" from the "Russian" element and check it.
|
| 320 | XMLElement* element = doc.FirstChildElement( "document" )->FirstChildElement( "Russian" );
|
| 321 | const unsigned char correctValue[] = { 0xd1U, 0x86U, 0xd0U, 0xb5U, 0xd0U, 0xbdU, 0xd0U, 0xbdU,
|
| 322 | 0xd0U, 0xbeU, 0xd1U, 0x81U, 0xd1U, 0x82U, 0xd1U, 0x8cU, 0 };
|
| 323 |
|
| 324 | XMLTest( "UTF-8: Russian value.", (const char*)correctValue, element->Attribute( "value" ) );
|
| 325 |
|
| 326 | const unsigned char russianElementName[] = { 0xd0U, 0xa0U, 0xd1U, 0x83U,
|
| 327 | 0xd1U, 0x81U, 0xd1U, 0x81U,
|
| 328 | 0xd0U, 0xbaU, 0xd0U, 0xb8U,
|
| 329 | 0xd0U, 0xb9U, 0 };
|
| 330 | const char russianText[] = "<\xD0\xB8\xD0\xBC\xD0\xB5\xD0\xB5\xD1\x82>";
|
| 331 |
|
| 332 | XMLText* text = doc.FirstChildElement( "document" )->FirstChildElement( (const char*) russianElementName )->FirstChild()->ToText();
|
| 333 | XMLTest( "UTF-8: Browsing russian element name.",
|
| 334 | russianText,
|
| 335 | text->Value() );
|
| 336 |
|
| 337 | // Now try for a round trip.
|
| 338 | doc.SaveFile( "utf8testout.xml" );
|
| 339 |
|
| 340 | // Check the round trip.
|
| 341 | char savedBuf[256];
|
| 342 | char verifyBuf[256];
|
| 343 | int okay = 0;
|
| 344 |
|
| 345 | FILE* saved = fopen( "utf8testout.xml", "r" );
|
| 346 | FILE* verify = fopen( "utf8testverify.xml", "r" );
|
| 347 |
|
| 348 | if ( saved && verify )
|
| 349 | {
|
| 350 | okay = 1;
|
| 351 | while ( fgets( verifyBuf, 256, verify ) )
|
| 352 | {
|
| 353 | fgets( savedBuf, 256, saved );
|
| 354 | NullLineEndings( verifyBuf );
|
| 355 | NullLineEndings( savedBuf );
|
| 356 |
|
| 357 | if ( strcmp( verifyBuf, savedBuf ) )
|
| 358 | {
|
| 359 | printf( "verify:%s<\n", verifyBuf );
|
| 360 | printf( "saved :%s<\n", savedBuf );
|
| 361 | okay = 0;
|
| 362 | break;
|
| 363 | }
|
| 364 | }
|
| 365 | }
|
| 366 | if ( saved )
|
| 367 | fclose( saved );
|
| 368 | if ( verify )
|
| 369 | fclose( verify );
|
| 370 | XMLTest( "UTF-8: Verified multi-language round trip.", 1, okay );
|
| 371 | }
|
| 372 |
|
| 373 |
|
| 374 | #if defined( WIN32 )
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 375 | _CrtMemCheckpoint( &endMemState );
|
| 376 | //_CrtMemDumpStatistics( &endMemState );
|
| 377 |
|
| 378 | _CrtMemState diffMemState;
|
| 379 | _CrtMemDifference( &diffMemState, &startMemState, &endMemState );
|
| 380 | _CrtMemDumpStatistics( &diffMemState );
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 381 | //printf( "new total=%d\n", gNewTotal );
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 382 | #endif
|
| 383 |
|
| 384 | printf ("\nPass %d, Fail %d\n", gPass, gFail);
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 385 | return 0;
|
| 386 | } |