summaryrefslogtreecommitdiff
path: root/tests/test_document.cpp
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2015-04-12 21:27:12 -0700
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2015-04-12 21:27:12 -0700
commit5edeaf67658a3ab27e9ace87ccff37aba8352607 (patch)
treeb49648254cc6c4de54dcacb88fcbdccd3bd1ebba /tests/test_document.cpp
parenta0d065cd22d1d43c417f6d3db88a04bf57b67ed0 (diff)
tests: Add more out of memory tests
Also add tests that verify save_file for absence of FILE leaks.
Diffstat (limited to 'tests/test_document.cpp')
-rw-r--r--tests/test_document.cpp37
1 files changed, 35 insertions, 2 deletions
diff --git a/tests/test_document.cpp b/tests/test_document.cpp
index 1545e19..9c8c860 100644
--- a/tests/test_document.cpp
+++ b/tests/test_document.cpp
@@ -319,9 +319,7 @@ TEST(document_load_file_out_of_memory_file_leak)
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;
@@ -329,6 +327,21 @@ TEST(document_load_file_out_of_memory_file_leak)
CHECK_NODE(doc, STR("<node />"));
}
+TEST(document_load_file_wide_out_of_memory_file_leak)
+{
+ test_runner::_memory_fail_threshold = 256;
+
+ pugi::xml_document doc;
+
+ for (int i = 0; i < 256; ++i)
+ CHECK_ALLOC_FAIL(CHECK(doc.load_file(L"tests/data/small.xml").status == status_out_of_memory));
+
+ test_runner::_memory_fail_threshold = 0;
+
+ CHECK(doc.load_file(L"tests/data/small.xml"));
+ CHECK_NODE(doc, STR("<node />"));
+}
+
TEST(document_load_file_error_previous)
{
pugi::xml_document doc;
@@ -556,6 +569,26 @@ TEST_XML(document_save_file_wide_text, "<node/>")
CHECK(test_file_contents(f.path, "<node />\n", 9));
}
+TEST_XML(document_save_file_leak, "<node/>")
+{
+ temp_file f;
+
+ for (int i = 0; i < 256; ++i)
+ CHECK(doc.save_file(f.path));
+}
+
+TEST_XML(document_save_file_wide_leak, "<node/>")
+{
+ temp_file f;
+
+ // widen the path
+ wchar_t wpath[sizeof(f.path)];
+ std::copy(f.path, f.path + strlen(f.path) + 1, wpath + 0);
+
+ for (int i = 0; i < 256; ++i)
+ CHECK(doc.save_file(wpath));
+}
+
TEST(document_load_buffer)
{
const pugi::char_t text[] = STR("<?xml?><node/>");