tests: Added tests for as_string and default values in as_*
git-svn-id: http://pugixml.googlecode.com/svn/trunk@894 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
parent
40777b2ce1
commit
a47bd44953
@ -39,6 +39,24 @@ TEST_XML_FLAGS(dom_text_get, "<node><a>foo</a><b><node/><![CDATA[bar]]></b><c><?
|
|||||||
CHECK_STRING(xml_node().text().get(), STR(""));
|
CHECK_STRING(xml_node().text().get(), STR(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_XML_FLAGS(dom_text_as_string, "<node><a>foo</a><b><node/><![CDATA[bar]]></b><c><?pi value?></c><d/></node>", parse_default | parse_pi)
|
||||||
|
{
|
||||||
|
xml_node node = doc.child(STR("node"));
|
||||||
|
|
||||||
|
CHECK_STRING(node.child(STR("a")).text().as_string(), STR("foo"));
|
||||||
|
CHECK_STRING(node.child(STR("a")).first_child().text().as_string(), STR("foo"));
|
||||||
|
|
||||||
|
CHECK_STRING(node.child(STR("b")).text().as_string(), STR("bar"));
|
||||||
|
CHECK_STRING(node.child(STR("b")).last_child().text().as_string(), STR("bar"));
|
||||||
|
|
||||||
|
CHECK_STRING(node.child(STR("c")).text().as_string(), STR(""));
|
||||||
|
CHECK_STRING(node.child(STR("c")).first_child().text().as_string(), STR(""));
|
||||||
|
|
||||||
|
CHECK_STRING(node.child(STR("d")).text().as_string(), STR(""));
|
||||||
|
|
||||||
|
CHECK_STRING(xml_node().text().as_string(), STR(""));
|
||||||
|
}
|
||||||
|
|
||||||
TEST_XML(dom_text_as_int, "<node><text1>1</text1><text2>-1</text2><text3>-2147483648</text3><text4>2147483647</text4></node>")
|
TEST_XML(dom_text_as_int, "<node><text1>1</text1><text2>-1</text2><text3>-2147483648</text3><text4>2147483647</text4></node>")
|
||||||
{
|
{
|
||||||
xml_node node = doc.child(STR("node"));
|
xml_node node = doc.child(STR("node"));
|
||||||
@ -221,3 +239,14 @@ TEST_XML_FLAGS(dom_text_data, "<node><a>foo</a><b><![CDATA[bar]]></b><c><?pi val
|
|||||||
CHECK(!xml_text().data());
|
CHECK(!xml_text().data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(dom_text_defaults)
|
||||||
|
{
|
||||||
|
xml_text text;
|
||||||
|
|
||||||
|
CHECK_STRING(text.as_string(STR("foo")), STR("foo"));
|
||||||
|
CHECK(text.as_int(42) == 42);
|
||||||
|
CHECK(text.as_uint(42) == 42);
|
||||||
|
CHECK(text.as_double(42) == 42);
|
||||||
|
CHECK(text.as_float(42) == 42);
|
||||||
|
CHECK(text.as_bool(true) == true);
|
||||||
|
}
|
||||||
|
|||||||
@ -73,6 +73,14 @@ TEST_XML(dom_attr_name_value, "<node attr='1'/>")
|
|||||||
CHECK_NAME_VALUE(xml_attribute(), STR(""), STR(""));
|
CHECK_NAME_VALUE(xml_attribute(), STR(""), STR(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_XML(dom_attr_as_string, "<node attr='1'/>")
|
||||||
|
{
|
||||||
|
xml_attribute attr = doc.child(STR("node")).attribute(STR("attr"));
|
||||||
|
|
||||||
|
CHECK_STRING(attr.as_string(), STR("1"));
|
||||||
|
CHECK_STRING(xml_attribute().as_string(), STR(""));
|
||||||
|
}
|
||||||
|
|
||||||
TEST_XML(dom_attr_as_int, "<node attr1='1' attr2='-1' attr3='-2147483648' attr4='2147483647'/>")
|
TEST_XML(dom_attr_as_int, "<node attr1='1' attr2='-1' attr3='-2147483648' attr4='2147483647'/>")
|
||||||
{
|
{
|
||||||
xml_node node = doc.child(STR("node"));
|
xml_node node = doc.child(STR("node"));
|
||||||
@ -135,6 +143,18 @@ TEST_XML(dom_attr_as_bool, "<node attr1='0' attr2='1' attr3='true' attr4='True'
|
|||||||
CHECK(!node.attribute(STR("attr7")).as_bool());
|
CHECK(!node.attribute(STR("attr7")).as_bool());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(dom_attr_defaults)
|
||||||
|
{
|
||||||
|
xml_attribute attr;
|
||||||
|
|
||||||
|
CHECK_STRING(attr.as_string(STR("foo")), STR("foo"));
|
||||||
|
CHECK(attr.as_int(42) == 42);
|
||||||
|
CHECK(attr.as_uint(42) == 42);
|
||||||
|
CHECK(attr.as_double(42) == 42);
|
||||||
|
CHECK(attr.as_float(42) == 42);
|
||||||
|
CHECK(attr.as_bool(true) == true);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_XML(dom_attr_iterator, "<node><node1 attr1='0'/><node2 attr1='0' attr2='1'/><node3/></node>")
|
TEST_XML(dom_attr_iterator, "<node><node1 attr1='0'/><node2 attr1='0' attr2='1'/><node3/></node>")
|
||||||
{
|
{
|
||||||
xml_node node1 = doc.child(STR("node")).child(STR("node1"));
|
xml_node node1 = doc.child(STR("node")).child(STR("node1"));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user