summaryrefslogtreecommitdiff
path: root/tests/test_document.cpp
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2017-06-16 16:41:08 -0700
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2017-06-16 16:41:08 -0700
commit3aa2b40354208fd4171f5e4b2ddddaeb6ec881fb (patch)
treea13e7f95c34c9d7a623082acc49712779703bbe6 /tests/test_document.cpp
parentb6995f06b9b60eb8df5838572572bc2e4fd953c2 (diff)
tests: Add more coverage tests for stream loading
Cover more failure cases and simplify the streambuf implementation a bit.
Diffstat (limited to 'tests/test_document.cpp')
-rw-r--r--tests/test_document.cpp45
1 files changed, 40 insertions, 5 deletions
diff --git a/tests/test_document.cpp b/tests/test_document.cpp
index c7ceb8f..81c9014 100644
--- a/tests/test_document.cpp
+++ b/tests/test_document.cpp
@@ -186,11 +186,6 @@ public:
{
this->setg(begin, begin, end);
}
-
- typename std::basic_streambuf<T>::int_type underflow() PUGIXML_OVERRIDE
- {
- return this->gptr() == this->egptr() ? std::basic_streambuf<T>::traits_type::eof() : std::basic_streambuf<T>::traits_type::to_int_type(*this->gptr());
- }
};
TEST(document_load_stream_nonseekable)
@@ -257,6 +252,46 @@ TEST(document_load_stream_nonseekable_out_of_memory_large)
pugi::xml_document doc;
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"<node />";
+ char_array_buffer<wchar_t> buffer(contents, contents + sizeof(contents) / sizeof(contents[0]));
+ std::basic_istream<wchar_t> in(&buffer);
+
+ test_runner::_memory_fail_threshold = 1;
+
+ pugi::xml_document doc;
+ CHECK_ALLOC_FAIL(CHECK(doc.load(in).status == status_out_of_memory));
+}
+
+template <typename T> class seek_fail_buffer: public std::basic_streambuf<T>
+{
+public:
+ typename std::basic_streambuf<T>::pos_type seekoff(typename std::basic_streambuf<T>::off_type, std::ios_base::seekdir, std::ios_base::openmode) PUGIXML_OVERRIDE
+ {
+ // pretend that our buffer is seekable (this is called by tellg); actual seeks will fail
+ return 0;
+ }
+};
+
+TEST(document_load_stream_seekable_fail_seek)
+{
+ seek_fail_buffer<char> buffer;
+ std::basic_istream<char> in(&buffer);
+
+ pugi::xml_document doc;
+ CHECK(doc.load(in).status == status_io_error);
+}
+
+TEST(document_load_stream_wide_seekable_fail_seek)
+{
+ seek_fail_buffer<wchar_t> buffer;
+ std::basic_istream<wchar_t> in(&buffer);
+
+ pugi::xml_document doc;
+ CHECK(doc.load(in).status == status_io_error);
+}
#endif
TEST(document_load_string)