diff options
author | arseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640> | 2009-11-08 14:36:12 +0000 |
---|---|---|
committer | arseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640> | 2009-11-08 14:36:12 +0000 |
commit | c5d97527366f9c39e84e3a4089ff74311b14c489 (patch) | |
tree | e4d581e6c67422eedec029142c65183e0a602b90 /tests | |
parent | 6783bf0c322e01ce23669730e6b35b3bafdf85b1 (diff) |
tests: Full public API coverage (except sort, which needs extensive coverage anyway)
git-svn-id: http://pugixml.googlecode.com/svn/trunk@224 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test.hpp | 5 | ||||
-rw-r--r-- | tests/test_xpath_api.cpp | 80 |
2 files changed, 85 insertions, 0 deletions
diff --git a/tests/test.hpp b/tests/test.hpp index 3071a47..0d54e6d 100644 --- a/tests/test.hpp +++ b/tests/test.hpp @@ -132,6 +132,11 @@ struct xpath_node_set_tester result = q.evaluate_node_set(node);
}
+ xpath_node_set_tester(const pugi::xpath_node_set& set, const char* message): last(0), message(message)
+ {
+ result = set;
+ }
+
~xpath_node_set_tester()
{
// check that we processed everything
diff --git a/tests/test_xpath_api.cpp b/tests/test_xpath_api.cpp index c032cb9..cd8c7e1 100644 --- a/tests/test_xpath_api.cpp +++ b/tests/test_xpath_api.cpp @@ -63,4 +63,84 @@ TEST_XML(xpath_api_node_eq_ops, "<node attr='value'/>") generic_eq_ops_test(doc.select_single_node("node"), doc.select_single_node("node/@attr"));
}
+TEST_XML(xpath_api_node_accessors, "<node attr='value'/>")
+{
+ xpath_node null;
+ xpath_node node = doc.select_single_node("node");
+ xpath_node attr = doc.select_single_node("node/@attr");
+
+ CHECK(!null.node());
+ CHECK(!null.attribute());
+ CHECK(!null.parent());
+
+ CHECK(node.node() == doc.child("node"));
+ CHECK(!node.attribute());
+ CHECK(node.parent() == doc);
+
+ CHECK(!attr.node());
+ CHECK(attr.attribute() == doc.child("node").attribute("attr"));
+ CHECK(attr.parent() == doc.child("node"));
+}
+
+inline void xpath_api_node_accessors_helper(const xpath_node_set& set)
+{
+ CHECK(set.size() == 2);
+ CHECK(set.type() == xpath_node_set::type_sorted);
+ CHECK(!set.empty());
+ CHECK_STRING(set[0].node().name(), "foo");
+ CHECK_STRING(set[1].node().name(), "foo");
+ CHECK(!set[2]);
+ CHECK(set.first() == set[0]);
+ CHECK(set.begin() + 2 == set.end());
+ CHECK(set.begin()[0] == set[0] && set.begin()[1] == set[1]);
+}
+
+TEST_XML(xpath_api_nodeset_accessors, "<node><foo/><foo/></node>")
+{
+ xpath_node_set null;
+ CHECK(null.size() == 0);
+ CHECK(null.type() == xpath_node_set::type_unsorted);
+ CHECK(null.empty());
+ CHECK(!null[0]);
+ CHECK(!null.first());
+ CHECK(null.begin() == null.end());
+
+ xpath_node_set set = doc.select_nodes("node/foo");
+ xpath_api_node_accessors_helper(set);
+
+ xpath_node_set copy = set;
+ xpath_api_node_accessors_helper(copy);
+
+ xpath_node_set assigned;
+ assigned = set;
+ xpath_api_node_accessors_helper(assigned);
+
+ xpath_node_set nullcopy = null;
+}
+
+TEST_XML(xpath_api_evaluate, "<node attr='3'/>")
+{
+ xpath_query q("node/@attr");
+
+ CHECK(q.evaluate_boolean(doc));
+ CHECK(q.evaluate_number(doc) == 3);
+ CHECK(q.evaluate_string(doc) == "3");
+
+ xpath_node_set ns = q.evaluate_node_set(doc);
+ CHECK(ns.size() == 1 && ns[0].attribute() == doc.child("node").attribute("attr"));
+}
+
+TEST(xpath_api_evaluate_node_set)
+{
+ try
+ {
+ xpath_query q("1");
+
+ q.evaluate_node_set(xml_node());
+ }
+ catch (const xpath_exception&)
+ {
+ }
+}
+
#endif
|