add test cases

This commit is contained in:
Lee Thomason
2019-08-10 17:49:42 -07:00
parent c36d59f6b5
commit effdf95f8c
3 changed files with 52 additions and 7 deletions

View File

@@ -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 )

View File

@@ -1222,7 +1222,9 @@ public:
void SetAttribute( unsigned value ); void SetAttribute( unsigned value );
/// 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,7 +1435,11 @@ public:
return QueryInt64Attribute(name, value); 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 ); return QueryBoolAttribute( name, value );
} }
@@ -1467,7 +1473,13 @@ public:
a->SetAttribute(value); 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 ) { void SetAttribute( const char* name, bool value ) {
XMLAttribute* a = FindOrCreateAttribute( name ); XMLAttribute* a = FindOrCreateAttribute( name );
a->SetAttribute( value ); a->SetAttribute( value );

View File

@@ -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,7 +865,23 @@ 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);
{ {
bool v = false; 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", 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,7 +968,8 @@ 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-bool", true); printer.PushAttribute("attrib-uint64", uint64_t(37));
printer.PushAttribute("attrib-bool", true);
printer.PushAttribute("attrib-double", 4.0); printer.PushAttribute("attrib-double", 4.0);
printer.CloseElement(); printer.CloseElement();
fclose(printerfp); fclose(printerfp);
@@ -964,7 +989,9 @@ 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-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); XMLTest("attrib-bool", true, attrib->BoolValue(), true);
attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-double"); attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-double");
XMLTest("attrib-double", 4.0, attrib->DoubleValue(), true); XMLTest("attrib-double", 4.0, attrib->DoubleValue(), true);