From 39e6b2701d97271d8a776bea5ed79ecabf352b86 Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Tue, 19 Jul 2011 15:20:39 +0000 Subject: tests: Added tests for non-seekable streams git-svn-id: http://pugixml.googlecode.com/svn/trunk@810 99668b35-9821-0410-8761-19e4c4f06640 --- tests/test_document.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 5 deletions(-) (limited to 'tests/test_document.cpp') 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) -- cgit v1.2.3