From 86593c0999a6652be8e93556149cdbfdf410512b Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Fri, 16 Jun 2017 17:08:00 -0700 Subject: tests: Add more stream coverage tests Cover both char and wchar_t stream loading in a single run instead of using pugi::char_t. --- tests/test_document.cpp | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/tests/test_document.cpp b/tests/test_document.cpp index 81c9014..bb5ed63 100644 --- a/tests/test_document.cpp +++ b/tests/test_document.cpp @@ -237,15 +237,27 @@ TEST(document_load_stream_nonseekable_out_of_memory) CHECK_ALLOC_FAIL(CHECK(doc.load(in).status == status_out_of_memory)); } +TEST(document_load_stream_wide_nonseekable_out_of_memory) +{ + wchar_t contents[] = L""; + char_array_buffer buffer(contents, contents + sizeof(contents) / sizeof(contents[0])); + std::basic_istream in(&buffer); + + test_runner::_memory_fail_threshold = 1; + + pugi::xml_document doc; + CHECK_ALLOC_FAIL(CHECK(doc.load(in).status == status_out_of_memory)); +} + TEST(document_load_stream_nonseekable_out_of_memory_large) { - std::basic_string str; - str += STR(""); - for (int i = 0; i < 10000; ++i) str += STR(""); - str += STR(""); + std::basic_string str; + str += ""; + for (int i = 0; i < 10000; ++i) str += ""; + str += ""; - char_array_buffer buffer(&str[0], &str[0] + str.length()); - std::basic_istream in(&buffer); + char_array_buffer buffer(&str[0], &str[0] + str.length()); + std::basic_istream in(&buffer); test_runner::_memory_fail_threshold = 10000 * 8 * 3 / 2; @@ -253,13 +265,17 @@ TEST(document_load_stream_nonseekable_out_of_memory_large) CHECK_ALLOC_FAIL(CHECK(doc.load(in).status == status_out_of_memory)); } -TEST(document_load_stream_wide_nonseekable_out_of_memory) +TEST(document_load_stream_wide_nonseekable_out_of_memory_large) { - wchar_t contents[] = L""; - char_array_buffer buffer(contents, contents + sizeof(contents) / sizeof(contents[0])); + std::basic_string str; + str += L""; + for (int i = 0; i < 10000; ++i) str += L""; + str += L""; + + char_array_buffer buffer(&str[0], &str[0] + str.length()); std::basic_istream in(&buffer); - test_runner::_memory_fail_threshold = 1; + test_runner::_memory_fail_threshold = 10000 * 8 * 3 / 2; pugi::xml_document doc; CHECK_ALLOC_FAIL(CHECK(doc.load(in).status == status_out_of_memory)); -- cgit v1.2.3