From 5ff56a6d68ce6fbab0980232d95b5d190e2ecdcf Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Sun, 9 May 2010 20:37:49 +0000 Subject: Removed document order optimization (it helps on a tiny percentage of queries), XPath tests now compute their own order git-svn-id: http://pugixml.googlecode.com/svn/trunk@400 99668b35-9821-0410-8761-19e4c4f06640 --- tests/test.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 10 deletions(-) (limited to 'tests/test.cpp') diff --git a/tests/test.cpp b/tests/test.cpp index ebd4bf4..1744e4f 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -1,3 +1,5 @@ +#define _SCL_SECURE_NO_WARNINGS + #include "test.hpp" #include "writer_string.hpp" @@ -5,6 +7,38 @@ #include #include +#include +#include + +#ifndef PUGIXML_NO_XPATH +static void build_document_order(std::vector& result, pugi::xml_node root) +{ + result.push_back(pugi::xpath_node()); + + pugi::xml_node cur = root; + + for (;;) + { + result.push_back(cur); + + for (pugi::xml_attribute a = cur.first_attribute(); a; a = a.next_attribute()) + result.push_back(pugi::xpath_node(a, cur)); + + if (cur.first_child()) + cur = cur.first_child(); + else if (cur.next_sibling()) + cur = cur.next_sibling(); + else + { + while (cur && !cur.next_sibling()) cur = cur.parent(); + cur = cur.next_sibling(); + + if (!cur) break; + } + } +} +#endif + bool test_string_equal(const pugi::char_t* lhs, const pugi::char_t* rhs) { return (!lhs || !rhs) ? lhs == rhs : pugi::impl::strequal(lhs, rhs); @@ -82,21 +116,33 @@ void xpath_node_set_tester::check(bool condition) } } -xpath_node_set_tester::xpath_node_set_tester(const pugi::xml_node& node, const pugi::char_t* query, const char* message): last(0), message(message) -{ - pugi::xpath_query q(query); - result = q.evaluate_node_set(node); -} - xpath_node_set_tester::xpath_node_set_tester(const pugi::xpath_node_set& set, const char* message): last(0), message(message) { result = set; + + if (result.empty()) + { + document_order = 0; + document_size = 0; + } + else + { + std::vector order; + build_document_order(order, (result[0].attribute() ? result[0].parent() : result[0].node()).root()); + + document_order = new pugi::xpath_node[order.size()]; + std::copy(order.begin(), order.end(), document_order); + + document_size = order.size(); + } } xpath_node_set_tester::~xpath_node_set_tester() { // check that we processed everything check(last == result.size()); + + delete[] document_order; } xpath_node_set_tester& xpath_node_set_tester::operator%(unsigned int expected) @@ -105,10 +151,8 @@ xpath_node_set_tester& xpath_node_set_tester::operator%(unsigned int expected) check(last < result.size()); // check document order - pugi::xpath_node node = result.begin()[last]; - unsigned int order = node.attribute() ? node.attribute().document_order() : node.node().document_order(); - - check(order == expected); + check(expected < document_size); + check(result.begin()[last] == document_order[expected]); // continue to the next element last++; -- cgit v1.2.3