From 9292096c56286a65c0556eac341e1279102f5223 Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Sun, 29 Aug 2010 15:05:50 +0000 Subject: tests: Added support for XPath without exceptions git-svn-id: http://pugixml.googlecode.com/svn/trunk@637 99668b35-9821-0410-8761-19e4c4f06640 --- src/pugixpath.cpp | 2 +- tests/test.cpp | 4 ++++ tests/test_xpath_api.cpp | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/pugixpath.cpp b/src/pugixpath.cpp index 732a3c6..c86fbd5 100644 --- a/src/pugixpath.cpp +++ b/src/pugixpath.cpp @@ -3429,7 +3429,7 @@ namespace pugi if (m_root->rettype() != xpath_type_node_set) { #ifdef PUGIXML_NO_EXCEPTIONS - return xpath_node_set() + return xpath_node_set(); #else xpath_parse_result result = {"Expression does not evaluate to node set", 0}; throw xpath_exception(result); diff --git a/tests/test.cpp b/tests/test.cpp index 29d74c1..ac49872 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -96,6 +96,9 @@ bool test_xpath_number_nan(const pugi::xml_node& node, const pugi::char_t* query bool test_xpath_fail_compile(const pugi::char_t* query) { +#ifdef PUGIXML_NO_EXCEPTIONS + return !pugi::xpath_query(query); +#else try { pugi::xpath_query q(query); @@ -105,6 +108,7 @@ bool test_xpath_fail_compile(const pugi::char_t* query) { return true; } +#endif } void xpath_node_set_tester::check(bool condition) diff --git a/tests/test_xpath_api.cpp b/tests/test_xpath_api.cpp index ad05083..9f09826 100644 --- a/tests/test_xpath_api.cpp +++ b/tests/test_xpath_api.cpp @@ -38,17 +38,21 @@ TEST_XML(xpath_api_select_single_node, "< 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, "") { @@ -152,6 +156,12 @@ TEST_XML(xpath_api_evaluate, "") CHECK(ns.size() == 1 && ns[0].attribute() == doc.child(STR("node")).attribute(STR("attr"))); } +#ifdef PUGIXML_NO_EXCEPTIONS +TEST(xpath_api_evaluate_node_set) +{ + CHECK_XPATH_NODESET(xml_node(), STR("1")); +} +#else TEST(xpath_api_evaluate_node_set) { try @@ -159,11 +169,14 @@ TEST(xpath_api_evaluate_node_set) xpath_query q(STR("1")); q.evaluate_node_set(xml_node()); + + CHECK(!"Expected exception"); } catch (const xpath_exception&) { } } +#endif TEST(xpath_api_return_type) { @@ -172,4 +185,10 @@ TEST(xpath_api_return_type) CHECK(xpath_query(STR("'s'")).return_type() == xpath_type_string); CHECK(xpath_query(STR("true()")).return_type() == xpath_type_boolean); } + +// $$$ +// xpath_query bool conversion +// xpath_query::result / xpath_exception::result +// result offset +// xpath_query::rettype for no root #endif -- cgit v1.2.3