summaryrefslogtreecommitdiff
path: root/tests/test.cpp
diff options
context:
space:
mode:
authorarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-08-29 15:39:43 +0000
committerarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-08-29 15:39:43 +0000
commit61ceb10baf347bb19078afdb945a6cdec85777d7 (patch)
treebe25d2607d737657373db68b9fdd5c1f58fb2af1 /tests/test.cpp
parent23d84cdf7c9a7d91d46bd98aed070148cb697b77 (diff)
tests: Added more XPath variable tests
git-svn-id: http://pugixml.googlecode.com/svn/trunk@681 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests/test.cpp')
-rw-r--r--tests/test.cpp50
1 files changed, 35 insertions, 15 deletions
diff --git a/tests/test.cpp b/tests/test.cpp
index 9091f14..a48ef48 100644
--- a/tests/test.cpp
+++ b/tests/test.cpp
@@ -70,55 +70,75 @@ bool test_double_nan(double value)
}
#ifndef PUGIXML_NO_XPATH
-bool test_xpath_string(const pugi::xpath_node& node, const pugi::char_t* query, const pugi::char_t* expected)
+bool test_xpath_string(const pugi::xpath_node& node, const pugi::xpath_query& query, const pugi::char_t* expected)
{
- pugi::xpath_query q(query);
-
const size_t capacity = 64;
pugi::char_t result[capacity];
- size_t size = q.evaluate_string(result, capacity, node);
+ size_t size = query.evaluate_string(result, capacity, node);
if (size <= capacity) return test_string_equal(result, expected);
std::basic_string<pugi::char_t> buffer(size, ' ');
- return q.evaluate_string(&buffer[0], size, node) == size && test_string_equal(buffer.c_str(), expected);
+ return query.evaluate_string(&buffer[0], size, node) == size && test_string_equal(buffer.c_str(), expected);
+}
+
+bool test_xpath_boolean(const pugi::xpath_node& node, const pugi::xpath_query& query, bool expected)
+{
+ return query.evaluate_boolean(node) == expected;
+}
+
+bool test_xpath_number(const pugi::xpath_node& node, const pugi::xpath_query& query, double expected)
+{
+ double value = query.evaluate_number(node);
+ double absolute_error = fabs(value - expected);
+
+ const double tolerance = 1e-15f;
+ return absolute_error < tolerance || absolute_error < fabs(expected) * tolerance;
+}
+
+bool test_xpath_number_nan(const pugi::xpath_node& node, const pugi::xpath_query& query)
+{
+ return test_double_nan(query.evaluate_number(node));
+}
+
+bool test_xpath_string(const pugi::xpath_node& node, const pugi::char_t* query, const pugi::char_t* expected)
+{
+ pugi::xpath_query q(query);
+
+ return q && test_xpath_string(node, q, expected);
}
bool test_xpath_boolean(const pugi::xpath_node& node, const pugi::char_t* query, bool expected)
{
pugi::xpath_query q(query);
- return q.evaluate_boolean(node) == expected;
+ return q && test_xpath_boolean(node, q, expected);
}
bool test_xpath_number(const pugi::xpath_node& node, const pugi::char_t* query, double expected)
{
pugi::xpath_query q(query);
- double value = q.evaluate_number(node);
- double absolute_error = fabs(value - expected);
-
- const double tolerance = 1e-15f;
- return absolute_error < tolerance || absolute_error < fabs(expected) * tolerance;
+ return q && test_xpath_number(node, q, expected);
}
bool test_xpath_number_nan(const pugi::xpath_node& node, const pugi::char_t* query)
{
pugi::xpath_query q(query);
- return test_double_nan(q.evaluate_number(node));
+ return q && test_xpath_number_nan(node, q);
}
-bool test_xpath_fail_compile(const pugi::char_t* query)
+bool test_xpath_fail_compile(const pugi::char_t* query, pugi::xpath_variable_set* variables)
{
#ifdef PUGIXML_NO_EXCEPTIONS
- return !pugi::xpath_query(query);
+ return !pugi::xpath_query(query, variables);
#else
try
{
- pugi::xpath_query q(query);
+ pugi::xpath_query q(query, variables);
return false;
}
catch (const pugi::xpath_exception&)