summaryrefslogtreecommitdiff
path: root/tests/test_xpath_variables.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_xpath_variables.cpp')
-rw-r--r--tests/test_xpath_variables.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/test_xpath_variables.cpp b/tests/test_xpath_variables.cpp
index 0d33312..b2ebc47 100644
--- a/tests/test_xpath_variables.cpp
+++ b/tests/test_xpath_variables.cpp
@@ -413,4 +413,64 @@ TEST_XML(xpath_variables_count_sum, "<node><c1>12</c1><c2>23</c2><c3>34</c3></no
CHECK_XPATH_NUMBER_VAR(xml_node(), STR("sum($c12) * count($c) - sum($c3)"), &set, 71);
}
+
+TEST_XML(xpath_variables_copy, "<node />")
+{
+ xpath_variable_set set1;
+ set1.set(STR("a"), true);
+ set1.set(STR("b"), 2.0);
+ set1.set(STR("c"), STR("string"));
+ set1.set(STR("d"), doc.select_nodes(STR("//*")));
+
+ CHECK_XPATH_STRING_VAR(xml_node(), STR("substring($c, count($d[$a]) + $b)"), &set1, STR("ring"));
+
+ xpath_variable_set set2 = set1;
+
+ CHECK_XPATH_STRING_VAR(xml_node(), STR("substring($c, count($d[$a]) + $b)"), &set2, STR("ring"));
+
+ xpath_variable_set set3;
+
+ CHECK(!set3.get(STR("a")));
+
+ set3 = set1;
+
+ CHECK_XPATH_STRING_VAR(xml_node(), STR("substring($c, count($d[$a]) + $b)"), &set2, STR("ring"));
+
+ set3 = set3;
+
+ CHECK_XPATH_STRING_VAR(xml_node(), STR("substring($c, count($d[$a]) + $b)"), &set2, STR("ring"));
+
+ set3 = xpath_variable_set();
+
+ CHECK(!set3.get(STR("a")));
+}
+
+TEST_XML(xpath_variables_copy_out_of_memory, "<node />")
+{
+ xpath_variable_set set1;
+ set1.set(STR("a"), true);
+ set1.set(STR("b"), 2.0);
+ set1.set(STR("c"), STR("string"));
+ set1.set(STR("d"), doc.select_nodes(STR("//*")));
+
+ xpath_variable_set set2 = set1;
+
+ test_runner::_memory_fail_threshold = 32768 + 75 * sizeof(void*);
+
+ CHECK_ALLOC_FAIL(xpath_variable_set set3 = set1);
+
+ xpath_variable_set set4;
+
+ CHECK_ALLOC_FAIL(set4 = set1);
+ CHECK(!set4.get(STR("a")) && !set4.get(STR("b")) && !set4.get(STR("c")) && !set4.get(STR("d")));
+
+ CHECK_ALLOC_FAIL(set2 = set1);
+
+ CHECK(set2.get(STR("a")) && set2.get(STR("b")) && set2.get(STR("c")) && set2.get(STR("d")));
+
+ CHECK(set2.get(STR("a"))->get_boolean() == true);
+ CHECK(set2.get(STR("b"))->get_number() == 2.0);
+ CHECK_STRING(set2.get(STR("c"))->get_string(), STR("string"));
+ CHECK(set2.get(STR("d"))->get_node_set().size() == 1);
+}
#endif