summaryrefslogtreecommitdiff
path: root/tests/test_dom_text.cpp
diff options
context:
space:
mode:
authorarseny.kapoulkine@gmail.com <arseny.kapoulkine@gmail.com@99668b35-9821-0410-8761-19e4c4f06640>2012-04-03 04:44:54 +0000
committerarseny.kapoulkine@gmail.com <arseny.kapoulkine@gmail.com@99668b35-9821-0410-8761-19e4c4f06640>2012-04-03 04:44:54 +0000
commita47bd44953e8544572127a2dce527c84aa8e1206 (patch)
tree58d66437bbd1fcc0aa7e48b265784e887d6da659 /tests/test_dom_text.cpp
parent40777b2ce1fd576fcdc58cb58fc60b81da3bf791 (diff)
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
Diffstat (limited to 'tests/test_dom_text.cpp')
-rw-r--r--tests/test_dom_text.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/test_dom_text.cpp b/tests/test_dom_text.cpp
index 7b51a6b..153c372 100644
--- a/tests/test_dom_text.cpp
+++ b/tests/test_dom_text.cpp
@@ -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(""));
}
+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>")
{
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());
}
+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);
+}