diff --git a/tests/test_document.cpp b/tests/test_document.cpp
index 11057ae..a799fbf 100644
--- a/tests/test_document.cpp
+++ b/tests/test_document.cpp
@@ -74,12 +74,9 @@ TEST(document_load_stream_error)
{
pugi::xml_document doc;
- std::ifstream fs1("filedoesnotexist");
- CHECK(doc.load(fs1).status == status_io_error);
+ std::ifstream fs("filedoesnotexist");
+ CHECK(doc.load(fs).status == status_io_error);
- std::ifstream fs2("con");
- CHECK(doc.load(fs2).status == status_io_error);
-
std::istringstream iss("");
test_runner::_memory_fail_threshold = 1;
CHECK(doc.load(iss).status == status_out_of_memory);
@@ -148,6 +145,57 @@ TEST(document_load_stream_wide_error_previous)
CHECK(doc.load(fs1).status == status_io_error);
CHECK(!doc.first_child());
}
+
+template class char_array_buffer: public std::basic_streambuf
+{
+public:
+ char_array_buffer(T* begin, T* end)
+ {
+ this->setg(begin, begin, end);
+ }
+
+ typename std::basic_streambuf::int_type underflow()
+ {
+ return this->gptr() == this->egptr() ? std::basic_streambuf::traits_type::eof() : std::basic_streambuf::traits_type::to_int_type(*this->gptr());
+ }
+};
+
+TEST(document_load_stream_nonseekable)
+{
+ char contents[] = "";
+ char_array_buffer buffer(contents, contents + sizeof(contents) / sizeof(contents[0]));
+ std::istream in(&buffer);
+
+ pugi::xml_document doc;
+ CHECK(doc.load(in));
+ CHECK_NODE(doc, STR(""));
+}
+
+TEST(document_load_stream_wide_nonseekable)
+{
+ wchar_t contents[] = L"";
+ char_array_buffer buffer(contents, contents + sizeof(contents) / sizeof(contents[0]));
+ std::basic_istream in(&buffer);
+
+ pugi::xml_document doc;
+ CHECK(doc.load(in));
+ CHECK_NODE(doc, STR(""));
+}
+
+TEST(document_load_stream_nonseekable_large)
+{
+ std::basic_string str;
+ str += STR("");
+ for (int i = 0; i < 10000; ++i) str += STR("");
+ str += STR("");
+
+ char_array_buffer buffer(&str[0], &str[0] + str.length());
+ std::basic_istream in(&buffer);
+
+ pugi::xml_document doc;
+ CHECK(doc.load(in));
+ CHECK_NODE(doc, str.c_str());
+}
#endif
TEST(document_load_string)