From bd23216420aa9b31fae6891ac267cd0ce1dddbb8 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Fri, 16 Jun 2017 00:29:14 -0700 Subject: [PATCH] tests: Improve XPath test coverage Add more memory allocation failure tests. --- tests/test_xpath_variables.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/test_xpath_variables.cpp b/tests/test_xpath_variables.cpp index c64e0e6..9349004 100644 --- a/tests/test_xpath_variables.cpp +++ b/tests/test_xpath_variables.cpp @@ -302,7 +302,23 @@ TEST_XML(xpath_variables_select, "") TEST(xpath_variables_empty_name) { xpath_variable_set set; + CHECK(!set.add(STR(""), xpath_type_node_set)); CHECK(!set.add(STR(""), xpath_type_number)); + CHECK(!set.add(STR(""), xpath_type_string)); + CHECK(!set.add(STR(""), xpath_type_boolean)); +} + +TEST(xpath_variables_long_name_out_of_memory_add) +{ + std::basic_string name(1000, 'a'); + + test_runner::_memory_fail_threshold = 1000; + + xpath_variable_set set; + CHECK_ALLOC_FAIL(CHECK(!set.add(name.c_str(), xpath_type_node_set))); + CHECK_ALLOC_FAIL(CHECK(!set.add(name.c_str(), xpath_type_number))); + CHECK_ALLOC_FAIL(CHECK(!set.add(name.c_str(), xpath_type_string))); + CHECK_ALLOC_FAIL(CHECK(!set.add(name.c_str(), xpath_type_boolean))); } TEST_XML(xpath_variables_inside_filter, "") @@ -591,4 +607,19 @@ TEST(xpath_variables_copy_big_out_of_memory) CHECK(!copy.get(name)); } } + +TEST(xpath_variables_copy_big_value_out_of_memory) +{ + xpath_variable_set set; + + std::basic_string var(10000, 'a'); + set.set(STR("x"), var.c_str()); + + test_runner::_memory_fail_threshold = 15000; + + xpath_variable_set copy; + CHECK_ALLOC_FAIL(copy = set); + + CHECK(!copy.get(STR("x"))); +} #endif