From 0237fb466e36bdfc82c5e9dab1791f546f7e2979 Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine@gmail.com" Date: Fri, 23 Mar 2012 03:25:03 +0000 Subject: tests: Added tests for read-only xml_text operations git-svn-id: http://pugixml.googlecode.com/svn/trunk@875 99668b35-9821-0410-8761-19e4c4f06640 --- tests/helpers.hpp | 8 ++++ tests/test_dom_text.cpp | 102 ++++++++++++++++++++++++++++++++++++++++++++ tests/test_dom_traverse.cpp | 8 ---- 3 files changed, 110 insertions(+), 8 deletions(-) create mode 100644 tests/test_dom_text.cpp diff --git a/tests/helpers.hpp b/tests/helpers.hpp index 172f231..439f8ea 100644 --- a/tests/helpers.hpp +++ b/tests/helpers.hpp @@ -103,4 +103,12 @@ template static void generic_rel_ops_test(T obj1, T obj2) CHECK(!(obj1 >= obj2)); } +template static void generic_empty_test(const T& obj) +{ + T null; + + CHECK(null.empty()); + CHECK(!obj.empty()); +} + #endif diff --git a/tests/test_dom_text.cpp b/tests/test_dom_text.cpp new file mode 100644 index 0000000..84815d6 --- /dev/null +++ b/tests/test_dom_text.cpp @@ -0,0 +1,102 @@ +#include "common.hpp" + +#include "helpers.hpp" + +TEST_XML_FLAGS(dom_text_empty, "foo", parse_default | parse_pi) +{ + xml_node node = doc.child(STR("node")); + + CHECK(node.child(STR("a")).text()); + CHECK(node.child(STR("b")).text()); + CHECK(!node.child(STR("c")).text()); + CHECK(!node.child(STR("d")).text()); + CHECK(!xml_node().text()); + CHECK(!xml_text()); + + generic_empty_test(node.child(STR("a")).text()); +} + +TEST_XML(dom_text_bool_ops, "foo") +{ + generic_bool_ops_test(doc.child(STR("node")).text()); +} + +TEST_XML_FLAGS(dom_text_get, "foo", parse_default | parse_pi) +{ + xml_node node = doc.child(STR("node")); + + CHECK_STRING(node.child(STR("a")).text().get(), STR("foo")); + CHECK_STRING(node.child(STR("a")).first_child().text().get(), STR("foo")); + + CHECK_STRING(node.child(STR("b")).text().get(), STR("bar")); + CHECK_STRING(node.child(STR("b")).first_child().text().get(), STR("bar")); + + CHECK_STRING(node.child(STR("c")).text().get(), STR("")); + CHECK_STRING(node.child(STR("c")).first_child().text().get(), STR("")); + + CHECK_STRING(node.child(STR("d")).text().get(), STR("")); + + CHECK_STRING(xml_node().text().get(), STR("")); +} + +TEST_XML(dom_text_as_int, "1-1-21474836482147483647") +{ + xml_node node = doc.child(STR("node")); + + CHECK(xml_text().as_int() == 0); + CHECK(node.child(STR("text1")).text().as_int() == 1); + CHECK(node.child(STR("text2")).text().as_int() == -1); + CHECK(node.child(STR("text3")).text().as_int() == -2147483647 - 1); + CHECK(node.child(STR("text4")).text().as_int() == 2147483647); +} + +TEST_XML(dom_text_as_uint, "0121474836474294967295") +{ + xml_node node = doc.child(STR("node")); + + CHECK(xml_text().as_uint() == 0); + CHECK(node.child(STR("text1")).text().as_uint() == 0); + CHECK(node.child(STR("text2")).text().as_uint() == 1); + CHECK(node.child(STR("text3")).text().as_uint() == 2147483647); + CHECK(node.child(STR("text4")).text().as_uint() == 4294967295u); +} + +TEST_XML(dom_text_as_float, "010.12-5.13e-43.14159265358979323846") +{ + xml_node node = doc.child(STR("node")); + + CHECK(xml_text().as_float() == 0); + CHECK_DOUBLE(node.child(STR("text1")).text().as_float(), 0); + CHECK_DOUBLE(node.child(STR("text2")).text().as_float(), 1); + CHECK_DOUBLE(node.child(STR("text3")).text().as_float(), 0.12); + CHECK_DOUBLE(node.child(STR("text4")).text().as_float(), -5.1); + CHECK_DOUBLE(node.child(STR("text5")).text().as_float(), 3e-4); + CHECK_DOUBLE(node.child(STR("text6")).text().as_float(), 3.14159265358979323846); +} + +TEST_XML(dom_text_as_double, "010.12-5.13e-43.14159265358979323846") +{ + xml_node node = doc.child(STR("node")); + + CHECK(xml_text().as_double() == 0); + CHECK_DOUBLE(node.child(STR("text1")).text().as_double(), 0); + CHECK_DOUBLE(node.child(STR("text2")).text().as_double(), 1); + CHECK_DOUBLE(node.child(STR("text3")).text().as_double(), 0.12); + CHECK_DOUBLE(node.child(STR("text4")).text().as_double(), -5.1); + CHECK_DOUBLE(node.child(STR("text5")).text().as_double(), 3e-4); + CHECK_DOUBLE(node.child(STR("text6")).text().as_double(), 3.14159265358979323846); +} + +TEST_XML(dom_text_as_bool, "01trueTrueYesyesfalse") +{ + xml_node node = doc.child(STR("node")); + + CHECK(!xml_text().as_bool()); + CHECK(!node.child(STR("text1")).text().as_bool()); + CHECK(node.child(STR("text2")).text().as_bool()); + CHECK(node.child(STR("text3")).text().as_bool()); + CHECK(node.child(STR("text4")).text().as_bool()); + CHECK(node.child(STR("text5")).text().as_bool()); + CHECK(node.child(STR("text6")).text().as_bool()); + CHECK(!node.child(STR("text7")).text().as_bool()); +} diff --git a/tests/test_dom_traverse.cpp b/tests/test_dom_traverse.cpp index f6a2495..15d6656 100644 --- a/tests/test_dom_traverse.cpp +++ b/tests/test_dom_traverse.cpp @@ -30,14 +30,6 @@ template static I move_iter(I base, int n) } #endif -template static void generic_empty_test(const T& obj) -{ - T null; - - CHECK(null.empty()); - CHECK(!obj.empty()); -} - TEST_XML(dom_attr_bool_ops, "") { generic_bool_ops_test(doc.child(STR("node")).attribute(STR("attr"))); -- cgit v1.2.3