summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2015-04-12 02:34:48 -0700
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2015-04-12 02:34:48 -0700
commitc5d07e2c2825129a37e8d3cac4c19ff3692c11f6 (patch)
tree0f19e27bef313861146e4cfdad501e2e9cfde1f5 /tests
parent2537cccad34b64086ad2ff47db07c3674b9be07a (diff)
tests: Add a test that verifies absence of file leaks
If an out of memory error happens in load_file there's a danger of leaking the FILE object. Since there is a limited supply of the objects we can easily test that the leak does not happen.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_document.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/test_document.cpp b/tests/test_document.cpp
index d81458a..1545e19 100644
--- a/tests/test_document.cpp
+++ b/tests/test_document.cpp
@@ -302,11 +302,33 @@ TEST(document_load_file_error)
pugi::xml_document doc;
CHECK(doc.load_file("filedoesnotexist").status == status_file_not_found);
+}
+TEST(document_load_file_out_of_memory)
+{
test_runner::_memory_fail_threshold = 1;
+
+ pugi::xml_document doc;
CHECK_ALLOC_FAIL(CHECK(doc.load_file("tests/data/small.xml").status == status_out_of_memory));
}
+TEST(document_load_file_out_of_memory_file_leak)
+{
+ test_runner::_memory_fail_threshold = 1;
+
+ pugi::xml_document doc;
+
+ for (int i = 0; i < 256; ++i)
+ {
+ CHECK_ALLOC_FAIL(CHECK(doc.load_file("tests/data/small.xml").status == status_out_of_memory));
+ }
+
+ test_runner::_memory_fail_threshold = 0;
+
+ CHECK(doc.load_file("tests/data/small.xml"));
+ CHECK_NODE(doc, STR("<node />"));
+}
+
TEST(document_load_file_error_previous)
{
pugi::xml_document doc;