tests: Extended XPath tests
git-svn-id: http://pugixml.googlecode.com/svn/trunk@638 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
parent
9292096c56
commit
12607d6047
@ -3352,7 +3352,7 @@ namespace pugi
|
|||||||
|
|
||||||
const char* xpath_parse_result::description() const
|
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)
|
xpath_query::xpath_query(const char_t* query): m_alloc(0), m_root(0)
|
||||||
|
|||||||
@ -105,6 +105,7 @@ struct dummy_fixture {};
|
|||||||
#define CHECK_JOIN(text, file, line) text file #line
|
#define CHECK_JOIN(text, file, line) text file #line
|
||||||
#define CHECK_JOIN2(text, file, line) CHECK_JOIN(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_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__)
|
#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
|
# define STRINGIZE(value) "??" // MSVC 6.0 and CodeWarrior have troubles stringizing stuff with strings w/escaping inside
|
||||||
|
|||||||
@ -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);
|
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'/>")
|
TEST_XML(xpath_api_node_bool_ops, "<node attr='value'/>")
|
||||||
{
|
{
|
||||||
generic_bool_ops_test(doc.select_single_node(STR("node")));
|
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
|
#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
|
#endif
|
||||||
TEST(xpath_api_evaluate_node_set)
|
|
||||||
|
TEST(xpath_api_evaluate_node_set_fail)
|
||||||
{
|
{
|
||||||
|
#ifdef PUGIXML_NO_EXCEPTIONS
|
||||||
|
CHECK_XPATH_NODESET(xml_node(), STR("1"));
|
||||||
|
#else
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
xpath_query q(STR("1"));
|
xpath_query q(STR("1"));
|
||||||
|
|
||||||
q.evaluate_node_set(xml_node());
|
q.evaluate_node_set(xml_node());
|
||||||
|
|
||||||
CHECK(!"Expected exception");
|
CHECK_FORCE_FAIL("Expected exception");
|
||||||
}
|
}
|
||||||
catch (const xpath_exception&)
|
catch (const xpath_exception&)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
TEST(xpath_api_return_type)
|
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("node")).return_type() == xpath_type_node_set);
|
||||||
CHECK(xpath_query(STR("1")).return_type() == xpath_type_number);
|
CHECK(xpath_query(STR("1")).return_type() == xpath_type_number);
|
||||||
CHECK(xpath_query(STR("'s'")).return_type() == xpath_type_string);
|
CHECK(xpath_query(STR("'s'")).return_type() == xpath_type_string);
|
||||||
CHECK(xpath_query(STR("true()")).return_type() == xpath_type_boolean);
|
CHECK(xpath_query(STR("true()")).return_type() == xpath_type_boolean);
|
||||||
}
|
}
|
||||||
|
|
||||||
// $$$
|
TEST(xpath_api_query_bool)
|
||||||
// xpath_query bool conversion
|
{
|
||||||
// xpath_query::result / xpath_exception::result
|
xpath_query q(STR("node"));
|
||||||
// result offset
|
|
||||||
// xpath_query::rettype for no root
|
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
|
||||||
|
|
||||||
|
// $$$
|
||||||
|
// out of memory during parsing/execution (?)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user