diff options
author | arseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640> | 2010-05-09 20:37:49 +0000 |
---|---|---|
committer | arseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640> | 2010-05-09 20:37:49 +0000 |
commit | 5ff56a6d68ce6fbab0980232d95b5d190e2ecdcf (patch) | |
tree | 734c2f28e532135fe7a2088be48f98c7b44cc5fd /tests/test.cpp | |
parent | e96af87b5dc678a64aad061cc2955eaa463c09a2 (diff) |
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
Diffstat (limited to 'tests/test.cpp')
-rw-r--r-- | tests/test.cpp | 64 |
1 files changed, 54 insertions, 10 deletions
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 <math.h>
#include <float.h>
+#include <algorithm>
+#include <vector>
+
+#ifndef PUGIXML_NO_XPATH
+static void build_document_order(std::vector<pugi::xpath_node>& 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<pugi::xpath_node> 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++;
|