summaryrefslogtreecommitdiff
path: root/tests/test_xpath_api.cpp
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2014-10-19 07:33:42 +0000
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2014-10-19 07:33:42 +0000
commitf6635588758ed1b650be22903c2e2e81273e05c5 (patch)
tree636fee26ff162d178e249c779f2af8d7e668981e /tests/test_xpath_api.cpp
parent72ec01c5f6d23405f30614d63fafa048279ca13d (diff)
XPath: Introduce xpath_query::evaluate_node
This method is equivalent to xml_node::select_single_node. This makes select_single_node faster in certain cases by avoiding an allocation and - more importantly - paves the way for future step optimizations. git-svn-id: https://pugixml.googlecode.com/svn/trunk@1064 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests/test_xpath_api.cpp')
-rw-r--r--tests/test_xpath_api.cpp33
1 files changed, 30 insertions, 3 deletions
diff --git a/tests/test_xpath_api.cpp b/tests/test_xpath_api.cpp
index d831712..8ec5694 100644
--- a/tests/test_xpath_api.cpp
+++ b/tests/test_xpath_api.cpp
@@ -154,6 +154,9 @@ TEST_XML(xpath_api_evaluate, "<node attr='3'/>")
xpath_node_set ns = q.evaluate_node_set(doc);
CHECK(ns.size() == 1 && ns[0].attribute() == doc.child(STR("node")).attribute(STR("attr")));
+
+ xpath_node nr = q.evaluate_node(doc);
+ CHECK(nr.attribute() == doc.child(STR("node")).attribute(STR("attr")));
}
TEST_XML(xpath_api_evaluate_attr, "<node attr='3'/>")
@@ -173,6 +176,9 @@ TEST_XML(xpath_api_evaluate_attr, "<node attr='3'/>")
xpath_node_set ns = q.evaluate_node_set(n);
CHECK(ns.size() == 1 && ns[0] == n);
+
+ xpath_node nr = q.evaluate_node(n);
+ CHECK(nr == n);
}
#ifdef PUGIXML_NO_EXCEPTIONS
@@ -190,18 +196,20 @@ TEST_XML(xpath_api_evaluate_fail, "<node attr='3'/>")
#endif
CHECK(q.evaluate_node_set(doc).empty());
+
+ CHECK(!q.evaluate_node(doc));
}
#endif
TEST(xpath_api_evaluate_node_set_fail)
{
+ xpath_query q(STR("1"));
+
#ifdef PUGIXML_NO_EXCEPTIONS
- CHECK_XPATH_NODESET(xml_node(), STR("1"));
+ CHECK(q.evaluate_node_set(xml_node()).empty());
#else
try
{
- xpath_query q(STR("1"));
-
q.evaluate_node_set(xml_node());
CHECK_FORCE_FAIL("Expected exception");
@@ -212,6 +220,25 @@ TEST(xpath_api_evaluate_node_set_fail)
#endif
}
+TEST(xpath_api_evaluate_node_fail)
+{
+ xpath_query q(STR("1"));
+
+#ifdef PUGIXML_NO_EXCEPTIONS
+ CHECK(!q.evaluate_node(xml_node()));
+#else
+ try
+ {
+ q.evaluate_node(xml_node());
+
+ CHECK_FORCE_FAIL("Expected exception");
+ }
+ catch (const xpath_exception&)
+ {
+ }
+#endif
+}
+
TEST(xpath_api_evaluate_string)
{
xpath_query q(STR("\"0123456789\""));