add test cases
This commit is contained in:
@@ -1494,6 +1494,12 @@ void XMLAttribute::SetAttribute(int64_t v)
|
|||||||
_value.SetStr(buf);
|
_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 )
|
void XMLAttribute::SetAttribute( bool v )
|
||||||
|
|||||||
12
tinyxml2.h
12
tinyxml2.h
@@ -1223,6 +1223,8 @@ public:
|
|||||||
/// Set the attribute to value.
|
/// Set the attribute to value.
|
||||||
void SetAttribute(int64_t 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 );
|
void SetAttribute( bool value );
|
||||||
/// Set the attribute to value.
|
/// Set the attribute to value.
|
||||||
void SetAttribute( double value );
|
void SetAttribute( double value );
|
||||||
@@ -1433,6 +1435,10 @@ public:
|
|||||||
return QueryInt64Attribute(name, value);
|
return QueryInt64Attribute(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
XMLError QueryAttribute(const char* name, uint64_t* value) const {
|
||||||
|
return QueryUnsigned64Attribute(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
XMLError QueryAttribute( const char* name, bool* value ) const {
|
XMLError QueryAttribute( const char* name, bool* value ) const {
|
||||||
return QueryBoolAttribute( name, value );
|
return QueryBoolAttribute( name, value );
|
||||||
}
|
}
|
||||||
@@ -1467,6 +1473,12 @@ public:
|
|||||||
a->SetAttribute(value);
|
a->SetAttribute(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.
|
/// Sets the named attribute to value.
|
||||||
void SetAttribute( const char* name, bool value ) {
|
void SetAttribute( const char* name, bool value ) {
|
||||||
XMLAttribute* a = FindOrCreateAttribute( name );
|
XMLAttribute* a = FindOrCreateAttribute( name );
|
||||||
|
|||||||
27
xmltest.cpp
27
xmltest.cpp
@@ -804,6 +804,7 @@ int main( int argc, const char ** argv )
|
|||||||
// ---------- Attributes ---------
|
// ---------- Attributes ---------
|
||||||
{
|
{
|
||||||
static const int64_t BIG = -123456789012345678;
|
static const int64_t BIG = -123456789012345678;
|
||||||
|
static const uint64_t BIG_POS = 123456789012345678;
|
||||||
XMLDocument doc;
|
XMLDocument doc;
|
||||||
XMLElement* element = doc.NewElement("element");
|
XMLElement* element = doc.NewElement("element");
|
||||||
doc.InsertFirstChild(element);
|
doc.InsertFirstChild(element);
|
||||||
@@ -864,6 +865,22 @@ int main( int argc, const char ** argv )
|
|||||||
}
|
}
|
||||||
XMLTest("Attribute: int64_t", BIG, element->Int64Attribute("attrib"), true);
|
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);
|
element->SetAttribute("attrib", true);
|
||||||
{
|
{
|
||||||
@@ -931,6 +948,13 @@ int main( int argc, const char ** argv )
|
|||||||
XMLTest("Element: int64_t", XML_SUCCESS, queryResult, true);
|
XMLTest("Element: int64_t", XML_SUCCESS, queryResult, true);
|
||||||
XMLTest("Element: int64_t", BIG, v, 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 ------
|
// ---------- XMLPrinter stream mode ------
|
||||||
@@ -944,6 +968,7 @@ int main( int argc, const char ** argv )
|
|||||||
printer.PushAttribute("attrib-int", int(1));
|
printer.PushAttribute("attrib-int", int(1));
|
||||||
printer.PushAttribute("attrib-unsigned", unsigned(2));
|
printer.PushAttribute("attrib-unsigned", unsigned(2));
|
||||||
printer.PushAttribute("attrib-int64", int64_t(3));
|
printer.PushAttribute("attrib-int64", int64_t(3));
|
||||||
|
printer.PushAttribute("attrib-uint64", uint64_t(37));
|
||||||
printer.PushAttribute("attrib-bool", true);
|
printer.PushAttribute("attrib-bool", true);
|
||||||
printer.PushAttribute("attrib-double", 4.0);
|
printer.PushAttribute("attrib-double", 4.0);
|
||||||
printer.CloseElement();
|
printer.CloseElement();
|
||||||
@@ -964,6 +989,8 @@ int main( int argc, const char ** argv )
|
|||||||
XMLTest("attrib-unsigned", unsigned(2), attrib->UnsignedValue(), true);
|
XMLTest("attrib-unsigned", unsigned(2), attrib->UnsignedValue(), true);
|
||||||
attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-int64");
|
attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-int64");
|
||||||
XMLTest("attrib-int64", int64_t(3), attrib->Int64Value(), true);
|
XMLTest("attrib-int64", int64_t(3), attrib->Int64Value(), true);
|
||||||
|
attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-uint64");
|
||||||
|
XMLTest("attrib-uint64", uint64_t(37), attrib->Unsigned64Value(), true);
|
||||||
attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-bool");
|
attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-bool");
|
||||||
XMLTest("attrib-bool", true, attrib->BoolValue(), true);
|
XMLTest("attrib-bool", true, attrib->BoolValue(), true);
|
||||||
attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-double");
|
attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-double");
|
||||||
|
|||||||
Reference in New Issue
Block a user