Skip to content
Snippets Groups Projects
Commit c5d07e2c authored by Arseny Kapoulkine's avatar Arseny Kapoulkine
Browse files

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.
parent 2537ccca
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment