summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/pugixpath.cpp2
-rw-r--r--tests/test.hpp1
-rw-r--r--tests/test_xpath_api.cpp114
3 files changed, 90 insertions, 27 deletions
diff --git a/src/pugixpath.cpp b/src/pugixpath.cpp
index c86fbd5..0478f39 100644
--- a/src/pugixpath.cpp
+++ b/src/pugixpath.cpp
@@ -3352,7 +3352,7 @@ namespace pugi
const char* xpath_parse_result::description() const
{
- return error ? error : "Success";
+ return error ? error : "No error";
}
xpath_query::xpath_query(const char_t* query): m_alloc(0), m_root(0)
diff --git a/tests/test.hpp b/tests/test.hpp
index c269fb5..3308b1e 100644
--- a/tests/test.hpp
+++ b/tests/test.hpp
@@ -105,6 +105,7 @@ struct dummy_fixture {};
#define CHECK_JOIN(text, file, line) text file #line
#define CHECK_JOIN2(text, file, line) CHECK_JOIN(text, file, line)
#define CHECK_TEXT(condition, text) if (condition) ; else test_runner::_failure_message = CHECK_JOIN2(text, " at "__FILE__ ":", __LINE__), longjmp(test_runner::_failure_buffer, 1)
+#define CHECK_FORCE_FAIL(text) test_runner::_failure_message = CHECK_JOIN2(text, " at "__FILE__ ":", __LINE__), longjmp(test_runner::_failure_buffer, 1)
#if (defined(_MSC_VER) && _MSC_VER == 1200) || defined(__MWERKS__)
# define STRINGIZE(value) "??" // MSVC 6.0 and CodeWarrior have troubles stringizing stuff with strings w/escaping inside
diff --git a/tests/test_xpath_api.cpp b/tests/test_xpath_api.cpp
index 9f09826..87cc40a 100644
--- a/tests/test_xpath_api.cpp
+++ b/tests/test_xpath_api.cpp
@@ -38,22 +38,6 @@ TEST_XML(xpath_api_select_single_node, "<node><head/><foo id='1'/><foo/><tail/><
CHECK(n5.node().attribute(STR("id")).as_int() == 1);
}
-#ifndef PUGIXML_NO_EXCEPTIONS
-TEST(xpath_api_exception_what)
-{
- try
- {
- xpath_query q(STR(""));
-
- CHECK(!"Expected exception");
- }
- catch (const xpath_exception& e)
- {
- CHECK(e.what()[0] != 0);
- }
-}
-#endif
-
TEST_XML(xpath_api_node_bool_ops, "<node attr='value'/>")
{
generic_bool_ops_test(doc.select_single_node(STR("node")));
@@ -157,38 +141,116 @@ TEST_XML(xpath_api_evaluate, "<node attr='3'/>")
}
#ifdef PUGIXML_NO_EXCEPTIONS
-TEST(xpath_api_evaluate_node_set)
+TEST_XML(xpath_api_evaluate_fail, "<node attr='3'/>")
{
- CHECK_XPATH_NODESET(xml_node(), STR("1"));
+ CHECK_XPATH_BOOLEAN(doc, STR(""), false);
+ CHECK_XPATH_NUMBER_NAN(doc, STR(""));
+ CHECK_XPATH_STRING(doc, STR(""), STR(""));
+ CHECK_XPATH_NODESET(doc, STR(""));
}
-#else
-TEST(xpath_api_evaluate_node_set)
+#endif
+
+TEST(xpath_api_evaluate_node_set_fail)
{
+#ifdef PUGIXML_NO_EXCEPTIONS
+ CHECK_XPATH_NODESET(xml_node(), STR("1"));
+#else
try
{
xpath_query q(STR("1"));
q.evaluate_node_set(xml_node());
- CHECK(!"Expected exception");
+ CHECK_FORCE_FAIL("Expected exception");
}
catch (const xpath_exception&)
{
}
-}
#endif
+}
TEST(xpath_api_return_type)
{
+#ifdef PUGIXML_NO_EXCEPTIONS
+ CHECK(xpath_query(STR("")).return_type() == xpath_type_none);
+#endif
+
CHECK(xpath_query(STR("node")).return_type() == xpath_type_node_set);
CHECK(xpath_query(STR("1")).return_type() == xpath_type_number);
CHECK(xpath_query(STR("'s'")).return_type() == xpath_type_string);
CHECK(xpath_query(STR("true()")).return_type() == xpath_type_boolean);
}
+TEST(xpath_api_query_bool)
+{
+ xpath_query q(STR("node"));
+
+ CHECK(q);
+ CHECK((!q) == false);
+}
+
+#ifdef PUGIXML_NO_EXCEPTIONS
+TEST(xpath_api_query_bool_fail)
+{
+ xpath_query q(STR(""));
+
+ CHECK((q ? true : false) == false);
+ CHECK((!q) == true);
+}
+#endif
+
+TEST(xpath_api_query_result)
+{
+ xpath_query q(STR("node"));
+
+ CHECK(q.result());
+ CHECK(q.result().error == 0);
+ CHECK(q.result().offset == 0);
+ CHECK(strcmp(q.result().description(), "No error") == 0);
+}
+
+TEST(xpath_api_query_result_fail)
+{
+#ifndef PUGIXML_NO_EXCEPTIONS
+ try
+ {
+#endif
+ xpath_query q(STR("string-length(1, 2, 3)"));
+
+#ifndef PUGIXML_NO_EXCEPTIONS
+ CHECK_FORCE_FAIL("Expected exception");
+ }
+ catch (const xpath_exception& q)
+ {
+#endif
+ xpath_parse_result result = q.result();
+
+ CHECK(!result);
+ CHECK(result.error != 0 && result.error[0] != 0);
+ CHECK(result.description() == result.error);
+ CHECK(result.offset == 0); // $$$
+
+#ifndef PUGIXML_NO_EXCEPTIONS
+ }
+#endif
+}
+
+#ifndef PUGIXML_NO_EXCEPTIONS
+TEST(xpath_api_exception_what)
+{
+ try
+ {
+ xpath_query q(STR(""));
+
+ CHECK_FORCE_FAIL("Expected exception");
+ }
+ catch (const xpath_exception& e)
+ {
+ CHECK(e.what()[0] != 0);
+ }
+}
+#endif
+
// $$$
-// xpath_query bool conversion
-// xpath_query::result / xpath_exception::result
-// result offset
-// xpath_query::rettype for no root
+// out of memory during parsing/execution (?)
#endif