From effdf95f8c3eadf97b816cecdb4d49df9b585d86 Mon Sep 17 00:00:00 2001 From: Lee Thomason Date: Sat, 10 Aug 2019 17:49:42 -0700 Subject: [PATCH] add test cases --- tinyxml2.cpp | 6 ++++++ tinyxml2.h | 18 +++++++++++++++--- xmltest.cpp | 35 +++++++++++++++++++++++++++++++---- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index b1259dc..2622dd3 100755 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -1494,6 +1494,12 @@ void XMLAttribute::SetAttribute(int64_t v) _value.SetStr(buf); } +void XMLAttribute::SetAttribute(uint64_t v) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr(v, buf, BUF_SIZE); + _value.SetStr(buf); +} void XMLAttribute::SetAttribute( bool v ) diff --git a/tinyxml2.h b/tinyxml2.h index 92e3d67..e61ca6a 100755 --- a/tinyxml2.h +++ b/tinyxml2.h @@ -1222,7 +1222,9 @@ public: void SetAttribute( unsigned value ); /// Set the attribute to value. void SetAttribute(int64_t value); - /// Set the attribute to value. + /// Set the attribute to value. + void SetAttribute(uint64_t value); + /// Set the attribute to value. void SetAttribute( bool value ); /// Set the attribute to value. void SetAttribute( double value ); @@ -1433,7 +1435,11 @@ public: return QueryInt64Attribute(name, value); } - XMLError QueryAttribute( const char* name, bool* value ) const { + XMLError QueryAttribute(const char* name, uint64_t* value) const { + return QueryUnsigned64Attribute(name, value); + } + + XMLError QueryAttribute( const char* name, bool* value ) const { return QueryBoolAttribute( name, value ); } @@ -1467,7 +1473,13 @@ public: a->SetAttribute(value); } - /// Sets the named attribute to value. + /// Sets the named attribute to value. + void SetAttribute(const char* name, uint64_t value) { + XMLAttribute* a = FindOrCreateAttribute(name); + a->SetAttribute(value); + } + + /// Sets the named attribute to value. void SetAttribute( const char* name, bool value ) { XMLAttribute* a = FindOrCreateAttribute( name ); a->SetAttribute( value ); diff --git a/xmltest.cpp b/xmltest.cpp index a0aaee7..d2bc3ea 100644 --- a/xmltest.cpp +++ b/xmltest.cpp @@ -804,6 +804,7 @@ int main( int argc, const char ** argv ) // ---------- Attributes --------- { static const int64_t BIG = -123456789012345678; + static const uint64_t BIG_POS = 123456789012345678; XMLDocument doc; XMLElement* element = doc.NewElement("element"); doc.InsertFirstChild(element); @@ -864,7 +865,23 @@ int main( int argc, const char ** argv ) } XMLTest("Attribute: int64_t", BIG, element->Int64Attribute("attrib"), true); } - { + { + element->SetAttribute("attrib", BIG_POS); + { + uint64_t v = 0; + XMLError queryResult = element->QueryUnsigned64Attribute("attrib", &v); + XMLTest("Attribute: uint64_t", XML_SUCCESS, queryResult, true); + XMLTest("Attribute: uint64_t", BIG_POS, v, true); + } + { + uint64_t v = 0; + int queryResult = element->QueryAttribute("attrib", &v); + XMLTest("Attribute: uint64_t", (int)XML_SUCCESS, queryResult, true); + XMLTest("Attribute: uint64_t", BIG_POS, v, true); + } + XMLTest("Attribute: uint64_t", BIG_POS, element->Unsigned64Attribute("attrib"), true); + } + { element->SetAttribute("attrib", true); { bool v = false; @@ -931,7 +948,14 @@ int main( int argc, const char ** argv ) XMLTest("Element: int64_t", XML_SUCCESS, queryResult, true); XMLTest("Element: int64_t", BIG, v, true); } - } + { + element->SetText(BIG_POS); + uint64_t v = 0; + XMLError queryResult = element->QueryUnsigned64Text(&v); + XMLTest("Element: uint64_t", XML_SUCCESS, queryResult, true); + XMLTest("Element: uint64_t", BIG_POS, v, true); + } + } // ---------- XMLPrinter stream mode ------ { @@ -944,7 +968,8 @@ int main( int argc, const char ** argv ) printer.PushAttribute("attrib-int", int(1)); printer.PushAttribute("attrib-unsigned", unsigned(2)); printer.PushAttribute("attrib-int64", int64_t(3)); - printer.PushAttribute("attrib-bool", true); + printer.PushAttribute("attrib-uint64", uint64_t(37)); + printer.PushAttribute("attrib-bool", true); printer.PushAttribute("attrib-double", 4.0); printer.CloseElement(); fclose(printerfp); @@ -964,7 +989,9 @@ int main( int argc, const char ** argv ) XMLTest("attrib-unsigned", unsigned(2), attrib->UnsignedValue(), true); attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-int64"); XMLTest("attrib-int64", int64_t(3), attrib->Int64Value(), true); - attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-bool"); + attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-uint64"); + XMLTest("attrib-uint64", uint64_t(37), attrib->Unsigned64Value(), true); + attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-bool"); XMLTest("attrib-bool", true, attrib->BoolValue(), true); attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-double"); XMLTest("attrib-double", 4.0, attrib->DoubleValue(), true);