15 Commits
5.0.0 ... 5.0.1

Author SHA1 Message Date
Lee Thomason
37bc3aca42 upping the version to 5.0.1 to fix release vs. source problem 2017-06-26 16:56:16 -07:00
Lee Thomason
8c9e3133c4 remove error string inline. hopefully helps with odd linking issues 2017-06-26 16:55:01 -07:00
Lee Thomason
563ee82093 Merge pull request #571 from hyperair/cmake-add-test
Use CTest to add xmltest as a testcase so `make test` works
2017-06-26 16:40:06 -07:00
Lee Thomason
4ee9ebdfd2 Merge pull request #570 from jasjuang/master
fix issue #516
2017-06-26 16:37:42 -07:00
Lee Thomason
a4f48c1167 Merge pull request #572 from Dmitry-Me/swapFoundAndExpected
"Found" and "expected" were swapped in some tests
2017-06-26 16:37:21 -07:00
Dmitry-Me
9832a5f05d "Found" and "expected" were swapped in some tests 2017-06-23 18:29:16 +03:00
Chow Loong Jin
48d45b29a9 Use make test in travis.yml 2017-06-22 01:20:55 +08:00
Chow Loong Jin
5381145957 Use CTest to add xmltest as a testcase so make test works 2017-06-22 01:14:07 +08:00
jasjuang
a5ab98a582 fix issue #516 2017-06-20 17:25:42 -07:00
Lee Thomason
369f306b37 Merge branch 'master' of github.com:leethomason/tinyxml2 2017-06-20 09:18:54 -07:00
Lee Thomason
8bba8b41d6 mark unused enums 2017-06-20 09:18:41 -07:00
Lee Thomason
3f169ac424 Merge pull request #568 from Dmitry-Me/checkParsingErrorEarlier
Test parsing result as early as possible
2017-06-20 09:17:21 -07:00
Lee Thomason
86be0cdfe5 Merge pull request #566 from redagito/master
CMake fix for static library only build
2017-06-20 09:08:39 -07:00
Dmitry-Me
aea64c4b75 Test parsing result as early as possible 2017-06-20 18:20:15 +03:00
Robert J
dfcf5488ea CMake fix for static library only build 2017-06-20 13:41:17 +02:00
6 changed files with 103 additions and 87 deletions

View File

@@ -12,4 +12,4 @@ before_script: cmake .
script: script:
- make -j3 - make -j3
- ./xmltest - make test

View File

@@ -13,6 +13,7 @@ endif()
project(tinyxml2) project(tinyxml2)
include(GNUInstallDirs) include(GNUInstallDirs)
include(CTest)
#enable_testing() #enable_testing()
#CMAKE_BUILD_TOOL #CMAKE_BUILD_TOOL
@@ -20,8 +21,8 @@ include(GNUInstallDirs)
################################ ################################
# set lib version here # set lib version here
set(GENERIC_LIB_VERSION "4.0.1") set(GENERIC_LIB_VERSION "5.0.1")
set(GENERIC_LIB_SOVERSION "4") set(GENERIC_LIB_SOVERSION "5")
################################ ################################
# Add definitions # Add definitions
@@ -39,7 +40,7 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
option(BUILD_SHARED_LIBS "build as shared library" ON) option(BUILD_SHARED_LIBS "build as shared library" ON)
option(BUILD_STATIC_LIBS "build as static library" OFF) option(BUILD_STATIC_LIBS "build as static library" OFF)
option(BUILD_TESTS "build xmltest" ON) option(BUILD_TESTS "build xmltest (deprecated: Use BUILD_TESTING)" ON)
set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
@@ -91,7 +92,7 @@ set_target_properties(tinyxml2_static PROPERTIES
SOVERSION "${GENERIC_LIB_SOVERSION}") SOVERSION "${GENERIC_LIB_SOVERSION}")
set_target_properties( tinyxml2_static PROPERTIES OUTPUT_NAME tinyxml2 ) set_target_properties( tinyxml2_static PROPERTIES OUTPUT_NAME tinyxml2 )
target_compile_definitions(tinyxml2 PUBLIC -D_CRT_SECURE_NO_WARNINGS) target_compile_definitions(tinyxml2_static PUBLIC -D_CRT_SECURE_NO_WARNINGS)
if(DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11") if(DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11")
target_include_directories(tinyxml2_static PUBLIC target_include_directories(tinyxml2_static PUBLIC
@@ -99,7 +100,7 @@ if(DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11")
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>) $<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>)
if(MSVC) if(MSVC)
target_compile_definitions(tinyxml2 PUBLIC -D_CRT_SECURE_NO_WARNINGS) target_compile_definitions(tinyxml2_static PUBLIC -D_CRT_SECURE_NO_WARNINGS)
endif(MSVC) endif(MSVC)
else() else()
include_directories(${PROJECT_SOURCE_DIR}) include_directories(${PROJECT_SOURCE_DIR})
@@ -120,7 +121,7 @@ install(TARGETS tinyxml2_static
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif() endif()
if(BUILD_TESTS) if(BUILD_TESTING AND BUILD_TESTS)
add_executable(xmltest xmltest.cpp) add_executable(xmltest xmltest.cpp)
if(BUILD_SHARED_LIBS) if(BUILD_SHARED_LIBS)
add_dependencies(xmltest tinyxml2) add_dependencies(xmltest tinyxml2)
@@ -136,6 +137,8 @@ if(BUILD_TESTS)
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:xmltest>/resources/out COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:xmltest>/resources/out
COMMENT "Configuring xmltest resources directory: ${CMAKE_BINARY_DIR}/resources" COMMENT "Configuring xmltest resources directory: ${CMAKE_BINARY_DIR}/resources"
) )
add_test(NAME xmltest COMMAND xmltest)
endif() endif()
install(FILES tinyxml2.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) install(FILES tinyxml2.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
@@ -151,13 +154,15 @@ configure_file(tinyxml2.pc.in tinyxml2.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tinyxml2.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tinyxml2.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
# uninstall target # uninstall target
configure_file( if(NOT TARGET uninstall)
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" configure_file(
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
IMMEDIATE @ONLY) "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()
file(WRITE file(WRITE
${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake
@@ -168,4 +173,4 @@ install(FILES
DESTINATION lib/cmake/${CMAKE_PROJECT_NAME}) DESTINATION lib/cmake/${CMAKE_PROJECT_NAME})
install(EXPORT ${CMAKE_PROJECT_NAME}Targets install(EXPORT ${CMAKE_PROJECT_NAME}Targets
DESTINATION lib/cmake/${CMAKE_PROJECT_NAME}) DESTINATION lib/cmake/${CMAKE_PROJECT_NAME})

2
dox
View File

@@ -38,7 +38,7 @@ PROJECT_NAME = "TinyXML-2"
# could be handy for archiving the generated documentation or if some version # could be handy for archiving the generated documentation or if some version
# control system is used. # control system is used.
PROJECT_NUMBER = 4.0.1 PROJECT_NUMBER = 5.0.1
# Using the PROJECT_BRIEF tag one can provide an optional one line description # Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a # for a project that appears at the top of each page and should give viewer a

View File

@@ -1966,10 +1966,10 @@ const char* XMLDocument::_errorNames[XML_ERROR_COUNT] = {
"XML_ERROR_FILE_NOT_FOUND", "XML_ERROR_FILE_NOT_FOUND",
"XML_ERROR_FILE_COULD_NOT_BE_OPENED", "XML_ERROR_FILE_COULD_NOT_BE_OPENED",
"XML_ERROR_FILE_READ_ERROR", "XML_ERROR_FILE_READ_ERROR",
"XML_ERROR_ELEMENT_MISMATCH", "UNUSED_XML_ERROR_ELEMENT_MISMATCH",
"XML_ERROR_PARSING_ELEMENT", "XML_ERROR_PARSING_ELEMENT",
"XML_ERROR_PARSING_ATTRIBUTE", "XML_ERROR_PARSING_ATTRIBUTE",
"XML_ERROR_IDENTIFYING_TAG", "UNUSED_XML_ERROR_IDENTIFYING_TAG",
"XML_ERROR_PARSING_TEXT", "XML_ERROR_PARSING_TEXT",
"XML_ERROR_PARSING_CDATA", "XML_ERROR_PARSING_CDATA",
"XML_ERROR_PARSING_COMMENT", "XML_ERROR_PARSING_COMMENT",
@@ -2308,6 +2308,16 @@ void XMLDocument::SetError( XMLError error, const char* str1, const char* str2,
return errorName; return errorName;
} }
const char* XMLDocument::GetErrorStr1() const
{
return _errorStr1.GetStr();
}
const char* XMLDocument::GetErrorStr2() const
{
return _errorStr2.GetStr();
}
const char* XMLDocument::ErrorName() const const char* XMLDocument::ErrorName() const
{ {
return ErrorIDToName(_errorID); return ErrorIDToName(_errorID);

View File

@@ -98,7 +98,7 @@ distribution.
/* Versioning, past 1.0.14: /* Versioning, past 1.0.14:
http://semver.org/ http://semver.org/
*/ */
static const int TIXML2_MAJOR_VERSION = 4; static const int TIXML2_MAJOR_VERSION = 5;
static const int TIXML2_MINOR_VERSION = 0; static const int TIXML2_MINOR_VERSION = 0;
static const int TIXML2_PATCH_VERSION = 1; static const int TIXML2_PATCH_VERSION = 1;
@@ -513,10 +513,10 @@ enum XMLError {
XML_ERROR_FILE_NOT_FOUND, XML_ERROR_FILE_NOT_FOUND,
XML_ERROR_FILE_COULD_NOT_BE_OPENED, XML_ERROR_FILE_COULD_NOT_BE_OPENED,
XML_ERROR_FILE_READ_ERROR, XML_ERROR_FILE_READ_ERROR,
XML_ERROR_ELEMENT_MISMATCH, UNUSED_XML_ERROR_ELEMENT_MISMATCH, // remove at next major version
XML_ERROR_PARSING_ELEMENT, XML_ERROR_PARSING_ELEMENT,
XML_ERROR_PARSING_ATTRIBUTE, XML_ERROR_PARSING_ATTRIBUTE,
XML_ERROR_IDENTIFYING_TAG, UNUSED_XML_ERROR_IDENTIFYING_TAG, // remove at next major version
XML_ERROR_PARSING_TEXT, XML_ERROR_PARSING_TEXT,
XML_ERROR_PARSING_CDATA, XML_ERROR_PARSING_CDATA,
XML_ERROR_PARSING_COMMENT, XML_ERROR_PARSING_COMMENT,
@@ -1803,13 +1803,11 @@ public:
static const char* ErrorIDToName(XMLError errorID); static const char* ErrorIDToName(XMLError errorID);
/// Return a possibly helpful diagnostic location or string. /// Return a possibly helpful diagnostic location or string.
const char* GetErrorStr1() const { const char* GetErrorStr1() const;
return _errorStr1.GetStr();
}
/// Return a possibly helpful secondary diagnostic location or string. /// Return a possibly helpful secondary diagnostic location or string.
const char* GetErrorStr2() const { const char* GetErrorStr2() const;
return _errorStr2.GetStr();
}
/// Return the line where the error occured, or zero if unknown. /// Return the line where the error occured, or zero if unknown.
int GetErrorLineNum() const int GetErrorLineNum() const
{ {

View File

@@ -435,10 +435,10 @@ int main( int argc, const char ** argv )
XMLTest( "Programmatic DOM", true, doc->FirstChildElement()->FirstChildElement()->BoolAttribute( "attrib" ) ); XMLTest( "Programmatic DOM", true, doc->FirstChildElement()->FirstChildElement()->BoolAttribute( "attrib" ) );
int value1 = 10; int value1 = 10;
int value2 = doc->FirstChildElement()->LastChildElement()->IntAttribute( "attrib", 10 ); int value2 = doc->FirstChildElement()->LastChildElement()->IntAttribute( "attrib", 10 );
int result = doc->FirstChildElement()->LastChildElement()->QueryIntAttribute( "attrib", &value1 ); XMLError result = doc->FirstChildElement()->LastChildElement()->QueryIntAttribute( "attrib", &value1 );
XMLTest( "Programmatic DOM", result, (int)XML_NO_ATTRIBUTE ); XMLTest( "Programmatic DOM", XML_NO_ATTRIBUTE, result );
XMLTest( "Programmatic DOM", value1, 10 ); XMLTest( "Programmatic DOM", 10, value1 );
XMLTest( "Programmatic DOM", value2, 10 ); XMLTest( "Programmatic DOM", 10, value2 );
doc->Print(); doc->Print();
@@ -499,7 +499,7 @@ int main( int argc, const char ** argv )
XMLDocument doc; XMLDocument doc;
doc.Parse( error ); doc.Parse( error );
XMLTest( "Bad XML", doc.ErrorID(), XML_ERROR_PARSING_ATTRIBUTE ); XMLTest( "Bad XML", XML_ERROR_PARSING_ATTRIBUTE, doc.ErrorID() );
} }
{ {
@@ -510,30 +510,31 @@ int main( int argc, const char ** argv )
XMLElement* ele = doc.FirstChildElement(); XMLElement* ele = doc.FirstChildElement();
int iVal, result; int iVal;
XMLError result;
double dVal; double dVal;
result = ele->QueryDoubleAttribute( "attr0", &dVal ); result = ele->QueryDoubleAttribute( "attr0", &dVal );
XMLTest( "Query attribute: int as double", result, (int)XML_SUCCESS); XMLTest( "Query attribute: int as double", XML_SUCCESS, result);
XMLTest( "Query attribute: int as double", (int)dVal, 1 ); XMLTest( "Query attribute: int as double", 1, (int)dVal );
XMLTest( "Query attribute: int as double", (int)ele->DoubleAttribute("attr0"), 1); XMLTest( "Query attribute: int as double", 1, (int)ele->DoubleAttribute("attr0"));
result = ele->QueryDoubleAttribute( "attr1", &dVal ); result = ele->QueryDoubleAttribute( "attr1", &dVal );
XMLTest( "Query attribute: double as double", result, (int)XML_SUCCESS); XMLTest( "Query attribute: double as double", XML_SUCCESS, result);
XMLTest( "Query attribute: double as double", dVal, 2.0 ); XMLTest( "Query attribute: double as double", 2.0, dVal );
XMLTest( "Query attribute: double as double", ele->DoubleAttribute("attr1"), 2.0 ); XMLTest( "Query attribute: double as double", 2.0, ele->DoubleAttribute("attr1") );
result = ele->QueryIntAttribute( "attr1", &iVal ); result = ele->QueryIntAttribute( "attr1", &iVal );
XMLTest( "Query attribute: double as int", result, (int)XML_SUCCESS); XMLTest( "Query attribute: double as int", XML_SUCCESS, result);
XMLTest( "Query attribute: double as int", iVal, 2 ); XMLTest( "Query attribute: double as int", 2, iVal );
result = ele->QueryIntAttribute( "attr2", &iVal ); result = ele->QueryIntAttribute( "attr2", &iVal );
XMLTest( "Query attribute: not a number", result, (int)XML_WRONG_ATTRIBUTE_TYPE ); XMLTest( "Query attribute: not a number", XML_WRONG_ATTRIBUTE_TYPE, result );
XMLTest( "Query attribute: not a number", ele->DoubleAttribute("attr2", 4.0), 4.0 ); XMLTest( "Query attribute: not a number", 4.0, ele->DoubleAttribute("attr2", 4.0) );
result = ele->QueryIntAttribute( "bar", &iVal ); result = ele->QueryIntAttribute( "bar", &iVal );
XMLTest( "Query attribute: does not exist", result, (int)XML_NO_ATTRIBUTE ); XMLTest( "Query attribute: does not exist", XML_NO_ATTRIBUTE, result );
XMLTest( "Query attribute: does not exist", ele->BoolAttribute("bar", true), true ); XMLTest( "Query attribute: does not exist", true, ele->BoolAttribute("bar", true) );
} }
{ {
@@ -558,7 +559,7 @@ int main( int argc, const char ** argv )
ele->QueryAttribute( "int", &iVal2 ); ele->QueryAttribute( "int", &iVal2 );
ele->QueryAttribute( "double", &dVal2 ); ele->QueryAttribute( "double", &dVal2 );
XMLTest( "Attribute match test", ele->Attribute( "str", "strValue" ), "strValue" ); XMLTest( "Attribute match test", "strValue", ele->Attribute( "str", "strValue" ) );
XMLTest( "Attribute round trip. c-string.", "strValue", cStr ); XMLTest( "Attribute round trip. c-string.", "strValue", cStr );
XMLTest( "Attribute round trip. int.", 1, iVal ); XMLTest( "Attribute round trip. int.", 1, iVal );
XMLTest( "Attribute round trip. double.", -1, (int)dVal ); XMLTest( "Attribute round trip. double.", -1, (int)dVal );
@@ -796,7 +797,7 @@ int main( int argc, const char ** argv )
{ {
XMLDocument doc; XMLDocument doc;
doc.LoadFile("resources/printer.xml"); doc.LoadFile("resources/printer.xml");
XMLTest("XMLPrinter Stream mode: load", doc.ErrorID(), XML_SUCCESS, true); XMLTest("XMLPrinter Stream mode: load", XML_SUCCESS, doc.ErrorID(), true);
const XMLDocument& cdoc = doc; const XMLDocument& cdoc = doc;
@@ -829,8 +830,8 @@ int main( int argc, const char ** argv )
doc.Parse( str ); doc.Parse( str );
doc.Print(); doc.Print();
XMLTest( "CDATA parse.", doc.FirstChildElement()->FirstChild()->Value(), XMLTest( "CDATA parse.", "I am > the rules!\n...since I make symbolic puns",
"I am > the rules!\n...since I make symbolic puns", doc.FirstChildElement()->FirstChild()->Value(),
false ); false );
} }
@@ -846,8 +847,9 @@ int main( int argc, const char ** argv )
doc.Parse( str ); doc.Parse( str );
doc.Print(); doc.Print();
XMLTest( "CDATA parse. [ tixml1:1480107 ]", doc.FirstChildElement()->FirstChild()->Value(), XMLTest( "CDATA parse. [ tixml1:1480107 ]",
"<b>I am > the rules!</b>\n...since I make symbolic puns", "<b>I am > the rules!</b>\n...since I make symbolic puns",
doc.FirstChildElement()->FirstChild()->Value(),
false ); false );
} }
@@ -864,7 +866,7 @@ int main( int argc, const char ** argv )
XMLNode* childNode0 = parent->InsertEndChild( childText0 ); XMLNode* childNode0 = parent->InsertEndChild( childText0 );
XMLNode* childNode1 = parent->InsertAfterChild( childNode0, childText1 ); XMLNode* childNode1 = parent->InsertAfterChild( childNode0, childText1 );
XMLTest( "Test InsertAfterChild on empty node. ", ( childNode1 == parent->LastChild() ), true ); XMLTest( "Test InsertAfterChild on empty node. ", true, ( childNode1 == parent->LastChild() ) );
} }
{ {
@@ -919,10 +921,11 @@ int main( int argc, const char ** argv )
XMLDocument doc( false ); XMLDocument doc( false );
doc.Parse( passages ); doc.Parse( passages );
XMLTest( "No entity parsing.", doc.FirstChildElement()->FirstChildElement()->Attribute( "context" ), XMLTest( "No entity parsing.",
"Line 5 has &quot;quotation marks&quot; and &apos;apostrophe marks&apos;." ); "Line 5 has &quot;quotation marks&quot; and &apos;apostrophe marks&apos;.",
XMLTest( "No entity parsing.", doc.FirstChildElement()->FirstChildElement()->FirstChild()->Value(), doc.FirstChildElement()->FirstChildElement()->Attribute( "context" ) );
"Crazy &ttk;" ); XMLTest( "No entity parsing.", "Crazy &ttk;",
doc.FirstChildElement()->FirstChildElement()->FirstChild()->Value() );
doc.Print(); doc.Print();
} }
@@ -931,9 +934,9 @@ int main( int argc, const char ** argv )
XMLDocument doc; XMLDocument doc;
doc.Parse( test ); doc.Parse( test );
XMLTest( "dot in names", doc.Error(), false ); XMLTest( "dot in names", false, doc.Error() );
XMLTest( "dot in names", doc.FirstChildElement()->Name(), "a.elem" ); XMLTest( "dot in names", "a.elem", doc.FirstChildElement()->Name() );
XMLTest( "dot in names", doc.FirstChildElement()->Attribute( "xmi.version" ), "2.0" ); XMLTest( "dot in names", "2.0", doc.FirstChildElement()->Attribute( "xmi.version" ) );
} }
{ {
@@ -944,7 +947,7 @@ int main( int argc, const char ** argv )
XMLText* text = doc.FirstChildElement()->FirstChildElement()->FirstChild()->ToText(); XMLText* text = doc.FirstChildElement()->FirstChildElement()->FirstChild()->ToText();
XMLTest( "Entity with one digit.", XMLTest( "Entity with one digit.",
text->Value(), "1.1 Start easy ignore fin thickness\n", "1.1 Start easy ignore fin thickness\n", text->Value(),
false ); false );
} }
@@ -1022,7 +1025,7 @@ int main( int argc, const char ** argv )
XMLDocument doc; XMLDocument doc;
doc.Parse( "<test>&#x0e;</test>" ); doc.Parse( "<test>&#x0e;</test>" );
const char result[] = { 0x0e, 0 }; const char result[] = { 0x0e, 0 };
XMLTest( "Low entities.", doc.FirstChildElement()->GetText(), result ); XMLTest( "Low entities.", result, doc.FirstChildElement()->GetText() );
doc.Print(); doc.Print();
} }
@@ -1030,18 +1033,18 @@ int main( int argc, const char ** argv )
// Attribute values with trailing quotes not handled correctly // Attribute values with trailing quotes not handled correctly
XMLDocument doc; XMLDocument doc;
doc.Parse( "<foo attribute=bar\" />" ); doc.Parse( "<foo attribute=bar\" />" );
XMLTest( "Throw error with bad end quotes.", doc.Error(), true ); XMLTest( "Throw error with bad end quotes.", true, doc.Error() );
} }
{ {
// [ 1663758 ] Failure to report error on bad XML // [ 1663758 ] Failure to report error on bad XML
XMLDocument xml; XMLDocument xml;
xml.Parse("<x>"); xml.Parse("<x>");
XMLTest("Missing end tag at end of input", xml.Error(), true); XMLTest("Missing end tag at end of input", true, xml.Error());
xml.Parse("<x> "); xml.Parse("<x> ");
XMLTest("Missing end tag with trailing whitespace", xml.Error(), true); XMLTest("Missing end tag with trailing whitespace", true, xml.Error());
xml.Parse("<x></y>"); xml.Parse("<x></y>");
XMLTest("Mismatched tags", xml.ErrorID(), XML_ERROR_MISMATCHED_ELEMENT); XMLTest("Mismatched tags", XML_ERROR_MISMATCHED_ELEMENT, xml.ErrorID() );
} }
@@ -1286,7 +1289,7 @@ int main( int argc, const char ** argv )
doc.Parse( xml ); doc.Parse( xml );
XMLElement* ele = XMLHandle( doc ).FirstChildElement( "element" ).FirstChild().ToElement(); XMLElement* ele = XMLHandle( doc ).FirstChildElement( "element" ).FirstChild().ToElement();
XMLTest( "Handle, success, mutable", ele->Value(), "sub" ); XMLTest( "Handle, success, mutable", "sub", ele->Value() );
XMLHandle docH( doc ); XMLHandle docH( doc );
ele = docH.FirstChildElement( "none" ).FirstChildElement( "element" ).ToElement(); ele = docH.FirstChildElement( "none" ).FirstChildElement( "element" ).ToElement();
@@ -1315,8 +1318,8 @@ int main( int argc, const char ** argv )
doc.Print( &printer ); doc.Print( &printer );
static const char* result = "\xef\xbb\xbf<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; static const char* result = "\xef\xbb\xbf<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
XMLTest( "BOM and default declaration", printer.CStr(), result, false ); XMLTest( "BOM and default declaration", result, printer.CStr(), false );
XMLTest( "CStrSize", printer.CStrSize(), 42, false ); XMLTest( "CStrSize", 42, printer.CStrSize(), false );
} }
{ {
const char* xml = "<ipxml ws='1'><info bla=' /></ipxml>"; const char* xml = "<ipxml ws='1'><info bla=' /></ipxml>";
@@ -1346,50 +1349,50 @@ int main( int argc, const char ** argv )
pointElement->FirstChildElement( "valid" )->QueryBoolText( &boolValue ); pointElement->FirstChildElement( "valid" )->QueryBoolText( &boolValue );
XMLTest( "QueryIntText", intValue, 1, false ); XMLTest( "QueryIntText", 1, intValue, false );
XMLTest( "QueryUnsignedText", unsignedValue, (unsigned)1, false ); XMLTest( "QueryUnsignedText", (unsigned)1, unsignedValue, false );
XMLTest( "QueryFloatText", floatValue, 1.2f, false ); XMLTest( "QueryFloatText", 1.2f, floatValue, false );
XMLTest( "QueryDoubleText", doubleValue, 1.2, false ); XMLTest( "QueryDoubleText", 1.2, doubleValue, false );
XMLTest( "QueryBoolText", boolValue, true, false ); XMLTest( "QueryBoolText", true, boolValue, false );
} }
{ {
const char* xml = "<element><_sub/><:sub/><sub:sub/><sub-sub/></element>"; const char* xml = "<element><_sub/><:sub/><sub:sub/><sub-sub/></element>";
XMLDocument doc; XMLDocument doc;
doc.Parse( xml ); doc.Parse( xml );
XMLTest( "Non-alpha element lead letter parses.", doc.Error(), false ); XMLTest( "Non-alpha element lead letter parses.", false, doc.Error() );
} }
{ {
const char* xml = "<element _attr1=\"foo\" :attr2=\"bar\"></element>"; const char* xml = "<element _attr1=\"foo\" :attr2=\"bar\"></element>";
XMLDocument doc; XMLDocument doc;
doc.Parse( xml ); doc.Parse( xml );
XMLTest("Non-alpha attribute lead character parses.", doc.Error(), false); XMLTest("Non-alpha attribute lead character parses.", false, doc.Error());
} }
{ {
const char* xml = "<3lement></3lement>"; const char* xml = "<3lement></3lement>";
XMLDocument doc; XMLDocument doc;
doc.Parse( xml ); doc.Parse( xml );
XMLTest("Element names with lead digit fail to parse.", doc.Error(), true); XMLTest("Element names with lead digit fail to parse.", true, doc.Error());
} }
{ {
const char* xml = "<element/>WOA THIS ISN'T GOING TO PARSE"; const char* xml = "<element/>WOA THIS ISN'T GOING TO PARSE";
XMLDocument doc; XMLDocument doc;
doc.Parse( xml, 10 ); doc.Parse( xml, 10 );
XMLTest( "Set length of incoming data", doc.Error(), false ); XMLTest( "Set length of incoming data", false, doc.Error() );
} }
{ {
XMLDocument doc; XMLDocument doc;
XMLTest( "Document is initially empty", doc.NoChildren(), true ); XMLTest( "Document is initially empty", true, doc.NoChildren() );
doc.Clear(); doc.Clear();
XMLTest( "Empty is empty after Clear()", doc.NoChildren(), true ); XMLTest( "Empty is empty after Clear()", true, doc.NoChildren() );
doc.LoadFile( "resources/dream.xml" ); doc.LoadFile( "resources/dream.xml" );
XMLTest( "Document has something to Clear()", doc.NoChildren(), false ); XMLTest( "Document has something to Clear()", false, doc.NoChildren() );
doc.Clear(); doc.Clear();
XMLTest( "Document Clear()'s", doc.NoChildren(), true ); XMLTest( "Document Clear()'s", true, doc.NoChildren() );
} }
// ----------- Whitespace ------------ // ----------- Whitespace ------------
@@ -1693,15 +1696,15 @@ int main( int argc, const char ** argv )
XMLDocument doc; XMLDocument doc;
doc.Parse(xml0); doc.Parse(xml0);
XMLTest("Test that the code changes do not affect normal parsing", doc.Error(), false); XMLTest("Test that the code changes do not affect normal parsing", false, doc.Error() );
doc.Parse(xml1); doc.Parse(xml1);
XMLTest("Test that the second declaration is allowed", doc.Error(), false); XMLTest("Test that the second declaration is allowed", false, doc.Error() );
doc.Parse(xml2); doc.Parse(xml2);
XMLTest("Test that declaration after a child is not allowed", doc.ErrorID(), XML_ERROR_PARSING_DECLARATION); XMLTest("Test that declaration after a child is not allowed", XML_ERROR_PARSING_DECLARATION, doc.ErrorID() );
doc.Parse(xml3); doc.Parse(xml3);
XMLTest("Test that declaration after a child is not allowed", doc.ErrorID(), XML_ERROR_PARSING_DECLARATION); XMLTest("Test that declaration after a child is not allowed", XML_ERROR_PARSING_DECLARATION, doc.ErrorID() );
doc.Parse(xml4); doc.Parse(xml4);
XMLTest("Test that declaration inside a child is not allowed", doc.ErrorID(), XML_ERROR_PARSING_DECLARATION); XMLTest("Test that declaration inside a child is not allowed", XML_ERROR_PARSING_DECLARATION, doc.ErrorID() );
} }
{ {
@@ -1774,9 +1777,9 @@ int main( int argc, const char ** argv )
// an interesting test case. // an interesting test case.
XMLDocument doc; XMLDocument doc;
XMLError err = doc.Parse(xml); XMLError err = doc.Parse(xml);
XMLElement* playlist = doc.FirstChildElement("playlist"); XMLTest("Crash bug parsing", XML_SUCCESS, err );
XMLTest("Crash bug parsing", err, XML_SUCCESS); XMLElement* playlist = doc.FirstChildElement("playlist");
XMLTest("Crash bug parsing", true, playlist != 0); XMLTest("Crash bug parsing", true, playlist != 0);
tinyxml2::XMLElement* entry = playlist->FirstChildElement("entry"); tinyxml2::XMLElement* entry = playlist->FirstChildElement("entry");
@@ -1803,7 +1806,7 @@ int main( int argc, const char ** argv )
for (const XMLElement* p = playlist->FirstChildElement("property"); p; p = p->NextSiblingElement("property")) { for (const XMLElement* p = playlist->FirstChildElement("property"); p; p = p->NextSiblingElement("property")) {
nProperty++; nProperty++;
} }
XMLTest("Crash bug parsing", nProperty, 2); XMLTest("Crash bug parsing", 2, nProperty);
} }
// ----------- Line Number Tracking -------------- // ----------- Line Number Tracking --------------