diff --git a/tests/test_xpath.cpp b/tests/test_xpath.cpp
index 5cafb47..fe1e312 100644
--- a/tests/test_xpath.cpp
+++ b/tests/test_xpath.cpp
@@ -449,16 +449,41 @@ TEST(xpath_out_of_memory_evaluate_substring)
CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(0, 0, xml_node()) == 1));
}
-/*
-TEST_XML(xpath_out_of_memory_evaluate_union, "")
+TEST_XML(xpath_out_of_memory_evaluate_union, "")
{
- test_runner::_memory_fail_threshold = 32768 + 4096 * 2;
+ // left hand side: size * sizeof(xpath_node) (8 on 32-bit, 16 on 64-bit)
+ // right hand side: same
+ // to make sure that when we append right hand side to left hand side, we run out of an XPath stack page (4K), we need slightly more than 2K/8 = 256 nodes on 32-bit, 128 nodes on 64-bit
+ size_t count = sizeof(void*) == 4 ? 300 : 150;
- xpath_query q(STR("a|(a|(a|(a|(a|(a|(a|(a|(a|(a|(a|(a|(a|(a|(a|(a|(a|(a|(a|(a|a)))))))))))))))))))"));
+ for (size_t i = 0; i < count; ++i)
+ doc.first_child().append_child(STR("a"));
+
+ xpath_query q(STR("a|a"));
+
+ test_runner::_memory_fail_threshold = 1;
CHECK_ALLOC_FAIL(CHECK(q.evaluate_node_set(doc.child(STR("node"))).empty()));
}
-*/
+
+TEST_XML(xpath_out_of_memory_evaluate_union_hash, "")
+{
+ // left hand side: size * sizeof(xpath_node) (8 on 32-bit, 16 on 64-bit)
+ // right hand side: same
+ // hash table: size * 1.5 * sizeof(void*)
+ // to make sure that when we append right hand side to left hand side, we do *not* run out of an XPath stack page (4K), we need slightly less than 2K/8 = 256 nodes on 32-bit, 128 nodes on 64-bit
+ size_t count = sizeof(void*) == 4 ? 200 : 100;
+
+ for (size_t i = 0; i < count; ++i)
+ doc.first_child().append_child(STR("a"));
+
+ xpath_query q(STR("a|a"));
+
+ test_runner::_memory_fail_threshold = 1;
+
+ CHECK_ALLOC_FAIL(CHECK(q.evaluate_node_set(doc.child(STR("node"))).empty()));
+}
+
TEST_XML(xpath_out_of_memory_evaluate_predicate, "")
{