From 5158ee903be463c189a80715f92235ceb04871a7 Mon Sep 17 00:00:00 2001
From: Arseny Kapoulkine
Date: Tue, 14 Apr 2015 19:19:13 -0700
Subject: Fix xpath_node_set assignment to provide strong exception guarantee
Since the type of the set was updated before assignment, assigning in
out-of-memory condition could change the type to not match the content.
---
tests/test_xpath_api.cpp | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
(limited to 'tests/test_xpath_api.cpp')
diff --git a/tests/test_xpath_api.cpp b/tests/test_xpath_api.cpp
index df078a0..4fc5be3 100644
--- a/tests/test_xpath_api.cpp
+++ b/tests/test_xpath_api.cpp
@@ -381,15 +381,20 @@ TEST_XML(xpath_api_node_set_assign_out_of_memory_preserve, "")
--
cgit v1.2.3
From 4eadece45f559825b236709ffb92037c6af5e962 Mon Sep 17 00:00:00 2001
From: Arseny Kapoulkine
Date: Tue, 21 Apr 2015 19:44:19 -0700
Subject: tests: Add move semantics tests
Also test ranged for and copying big xpath_variable_set objects (to make
sure we actually handle hash collisions properly)
---
tests/test_xpath_api.cpp | 221 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 221 insertions(+)
(limited to 'tests/test_xpath_api.cpp')
diff --git a/tests/test_xpath_api.cpp b/tests/test_xpath_api.cpp
index 4fc5be3..c070ed0 100644
--- a/tests/test_xpath_api.cpp
+++ b/tests/test_xpath_api.cpp
@@ -7,6 +7,7 @@
#include "helpers.hpp"
#include
+#include
TEST_XML(xpath_api_select_nodes, "")
{
@@ -407,4 +408,224 @@ TEST_XML(xpath_api_deprecated_select_single_node, "= 201103
+TEST_XML(xpath_api_nodeset_move_ctor, "")
+{
+ xpath_node_set set = doc.select_nodes(STR("node/bar/preceding::*"));
+
+ CHECK(set.size() == 2);
+ CHECK(set.type() == xpath_node_set::type_sorted_reverse);
+
+ test_runner::_memory_fail_threshold = 1;
+
+ xpath_node_set move = std::move(set);
+
+ CHECK(set.size() == 0);
+ CHECK(set.type() == xpath_node_set::type_unsorted);
+
+ CHECK(move.size() == 2);
+ CHECK(move.type() == xpath_node_set::type_sorted_reverse);
+ CHECK(move[1] == doc.first_child().first_child());
+}
+
+
+TEST_XML(xpath_api_nodeset_move_ctor_single, "")
+{
+ xpath_node_set set = doc.select_nodes(STR("node/bar"));
+
+ CHECK(set.size() == 1);
+ CHECK(set.type() == xpath_node_set::type_sorted);
+
+ test_runner::_memory_fail_threshold = 1;
+
+ xpath_node_set move = std::move(set);
+
+ CHECK(set.size() == 0);
+ CHECK(set.type() == xpath_node_set::type_unsorted);
+
+ CHECK(move.size() == 1);
+ CHECK(move.type() == xpath_node_set::type_sorted);
+ CHECK(move[0] == doc.first_child().last_child());
+}
+
+TEST(xpath_api_nodeset_move_ctor_empty)
+{
+ xpath_node_set set;
+ set.sort();
+
+ CHECK(set.size() == 0);
+ CHECK(set.type() == xpath_node_set::type_sorted);
+
+ test_runner::_memory_fail_threshold = 1;
+
+ xpath_node_set move = std::move(set);
+
+ CHECK(set.size() == 0);
+ CHECK(set.type() == xpath_node_set::type_unsorted);
+
+ CHECK(move.size() == 0);
+ CHECK(move.type() == xpath_node_set::type_sorted);
+}
+
+TEST_XML(xpath_api_nodeset_move_assign, "")
+{
+ xpath_node_set set = doc.select_nodes(STR("node/bar/preceding::*"));
+
+ CHECK(set.size() == 2);
+ CHECK(set.type() == xpath_node_set::type_sorted_reverse);
+
+ test_runner::_memory_fail_threshold = 1;
+
+ xpath_node_set move;
+
+ CHECK(move.size() == 0);
+ CHECK(move.type() == xpath_node_set::type_unsorted);
+
+ move = std::move(set);
+
+ CHECK(set.size() == 0);
+ CHECK(set.type() == xpath_node_set::type_unsorted);
+
+ CHECK(move.size() == 2);
+ CHECK(move.type() == xpath_node_set::type_sorted_reverse);
+ CHECK(move[1] == doc.first_child().first_child());
+}
+
+TEST_XML(xpath_api_nodeset_move_assign_destroy, "")
+{
+ xpath_node_set set = doc.select_nodes(STR("node/bar/preceding::*"));
+
+ CHECK(set.size() == 2);
+ CHECK(set.type() == xpath_node_set::type_sorted_reverse);
+
+ xpath_node_set all = doc.select_nodes(STR("//*"));
+
+ CHECK(all.size() == 4);
+
+ test_runner::_memory_fail_threshold = 1;
+
+ all = std::move(set);
+
+ CHECK(set.size() == 0);
+ CHECK(set.type() == xpath_node_set::type_unsorted);
+
+ CHECK(all.size() == 2);
+ CHECK(all.type() == xpath_node_set::type_sorted_reverse);
+ CHECK(all[1] == doc.first_child().first_child());
+}
+
+TEST_XML(xpath_api_nodeset_move_assign_single, "")
+{
+ xpath_node_set set = doc.select_nodes(STR("node/bar"));
+
+ CHECK(set.size() == 1);
+ CHECK(set.type() == xpath_node_set::type_sorted);
+
+ test_runner::_memory_fail_threshold = 1;
+
+ xpath_node_set move;
+
+ CHECK(move.size() == 0);
+ CHECK(move.type() == xpath_node_set::type_unsorted);
+
+ move = std::move(set);
+
+ CHECK(set.size() == 0);
+ CHECK(set.type() == xpath_node_set::type_unsorted);
+
+ CHECK(move.size() == 1);
+ CHECK(move.type() == xpath_node_set::type_sorted);
+ CHECK(move[0] == doc.first_child().last_child());
+}
+
+TEST(xpath_api_nodeset_move_assign_empty)
+{
+ xpath_node_set set;
+ set.sort();
+
+ CHECK(set.size() == 0);
+ CHECK(set.type() == xpath_node_set::type_sorted);
+
+ test_runner::_memory_fail_threshold = 1;
+
+ xpath_node_set move;
+
+ CHECK(move.size() == 0);
+ CHECK(move.type() == xpath_node_set::type_unsorted);
+
+ move = std::move(set);
+
+ CHECK(set.size() == 0);
+ CHECK(set.type() == xpath_node_set::type_unsorted);
+
+ CHECK(move.size() == 0);
+ CHECK(move.type() == xpath_node_set::type_sorted);
+}
+
+TEST(xpath_api_query_move)
+{
+ xml_node c;
+
+ xpath_query q1(STR("true()"));
+ xpath_query q4(STR("true() and false()"));
+
+ test_runner::_memory_fail_threshold = 1;
+
+ CHECK(q1);
+ CHECK(q1.evaluate_boolean(c));
+
+ xpath_query q2 = std::move(q1);
+ CHECK(!q1);
+ CHECK(!q1.evaluate_boolean(c));
+ CHECK(q2);
+ CHECK(q2.evaluate_boolean(c));
+
+ xpath_query q3;
+ CHECK(!q3);
+ CHECK(!q3.evaluate_boolean(c));
+
+ q3 = std::move(q2);
+ CHECK(!q2);
+ CHECK(!q2.evaluate_boolean(c));
+ CHECK(q3);
+ CHECK(q3.evaluate_boolean(c));
+
+ CHECK(q4);
+ CHECK(!q4.evaluate_boolean(c));
+
+ q4 = std::move(q3);
+
+ CHECK(!q3);
+ CHECK(!q3.evaluate_boolean(c));
+ CHECK(q4);
+ CHECK(q4.evaluate_boolean(c));
+
+ q4 = std::move(q4);
+
+ CHECK(q4);
+ CHECK(q4.evaluate_boolean(c));
+}
+
+TEST(xpath_api_query_vector)
+{
+ std::vector qv;
+
+ for (int i = 0; i < 10; ++i)
+ {
+ char_t expr[2];
+ expr[0] = '0' + i;
+ expr[1] = 0;
+
+ qv.push_back(xpath_query(expr));
+ }
+
+ double result = 0;
+
+ for (auto& q: qv)
+ result += q.evaluate_number(xml_node());
+
+ CHECK(result == 45);
+}
+#endif
#endif
--
cgit v1.2.3
From a6cc636a6b0d531686311b5666ea77225b10903e Mon Sep 17 00:00:00 2001
From: Arseny Kapoulkine
Date: Tue, 21 Apr 2015 21:07:58 -0700
Subject: tests: Fix MSVC warnings
---
tests/test_xpath_api.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'tests/test_xpath_api.cpp')
diff --git a/tests/test_xpath_api.cpp b/tests/test_xpath_api.cpp
index c070ed0..295bd95 100644
--- a/tests/test_xpath_api.cpp
+++ b/tests/test_xpath_api.cpp
@@ -614,7 +614,7 @@ TEST(xpath_api_query_vector)
for (int i = 0; i < 10; ++i)
{
char_t expr[2];
- expr[0] = '0' + i;
+ expr[0] = '0' + char_t(i);
expr[1] = 0;
qv.push_back(xpath_query(expr));
--
cgit v1.2.3