diff options
author | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2017-06-23 08:44:52 -0700 |
---|---|---|
committer | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2017-06-23 08:44:52 -0700 |
commit | f3e0f4249c648807693cbbf3bf370bc85ce55f45 (patch) | |
tree | b229de81c5eb9eb8a766cd9f849682ce8d3d9f84 /tests/test_document.cpp | |
parent | 4564d31c76c0c7e4729c1e99fa96e0b82d447c40 (diff) |
tests: Add more stream coverage tests
These new tests test that tellg() can fail when being called the second
time, which leads to seekable implementation failing.
Diffstat (limited to 'tests/test_document.cpp')
-rw-r--r-- | tests/test_document.cpp | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/tests/test_document.cpp b/tests/test_document.cpp index ffe1e8b..ecbe6dc 100644 --- a/tests/test_document.cpp +++ b/tests/test_document.cpp @@ -337,14 +337,50 @@ TEST(document_load_stream_wide_seekable_fail_seek) CHECK(doc.load(in).status == status_io_error); } +template <typename T> class tell_fail_buffer: public std::basic_streambuf<T> +{ +public: + int seeks; + + tell_fail_buffer(): seeks(0) + { + } + + typename std::basic_streambuf<T>::pos_type seekoff(typename std::basic_streambuf<T>::off_type, std::ios_base::seekdir dir, std::ios_base::openmode) PUGIXML_OVERRIDE + { + seeks++; + + return seeks > 1 && dir == std::ios_base::cur ? -1 : 0; + } + + typename std::basic_streambuf<T>::pos_type seekpos(typename std::basic_streambuf<T>::pos_type, std::ios_base::openmode) PUGIXML_OVERRIDE + { + return 0; + } +}; + +TEST(document_load_stream_seekable_fail_tell) +{ + tell_fail_buffer<char> buffer; + std::basic_istream<char> in(&buffer); + + xml_document doc; + CHECK(doc.load(in).status == status_io_error); +} + +TEST(document_load_stream_wide_seekable_fail_tell) +{ + tell_fail_buffer<wchar_t> buffer; + std::basic_istream<wchar_t> in(&buffer); + + xml_document doc; + CHECK(doc.load(in).status == status_io_error); +} + #ifndef PUGIXML_NO_EXCEPTIONS template <typename T> class read_fail_buffer: public std::basic_streambuf<T> { public: - read_fail_buffer() - { - } - typename std::basic_streambuf<T>::int_type underflow() PUGIXML_OVERRIDE { throw std::runtime_error("underflow failed"); |