summaryrefslogtreecommitdiff
path: root/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals
diff options
context:
space:
mode:
Diffstat (limited to 'test/std/input.output/string.streams/stringbuf/stringbuf.virtuals')
-rw-r--r--test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/overflow.pass.cpp97
-rw-r--r--test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/pbackfail.pass.cpp92
-rw-r--r--test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/seekoff.pass.cpp143
-rw-r--r--test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/seekpos.pass.cpp77
-rw-r--r--test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/setbuf.pass.cpp32
-rw-r--r--test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/underflow.pass.cpp70
6 files changed, 511 insertions, 0 deletions
diff --git a/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/overflow.pass.cpp b/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/overflow.pass.cpp
new file mode 100644
index 0000000000000..3abf9423a12eb
--- /dev/null
+++ b/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/overflow.pass.cpp
@@ -0,0 +1,97 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
+// class basic_stringbuf
+
+// int_type overflow(int_type c = traits::eof());
+
+#include <sstream>
+#include <cassert>
+
+int overflow_called = 0;
+
+template <class CharT>
+struct testbuf
+ : public std::basic_stringbuf<CharT>
+{
+ typedef std::basic_stringbuf<CharT> base;
+ explicit testbuf(const std::basic_string<CharT>& str,
+ std::ios_base::openmode which = std::ios_base::in | std::ios_base::out)
+ : base(str, which) {}
+
+ typename base::int_type
+ overflow(typename base::int_type c = base::type_traits::eof())
+ {++overflow_called; return base::overflow(c);}
+
+ void pbump(int n) {base::pbump(n);}
+};
+
+int main()
+{
+ {
+ testbuf<char> sb("abc");
+ assert(sb.sputc('1') == '1');
+ assert(sb.str() == "1bc");
+ assert(sb.sputc('2') == '2');
+ assert(sb.str() == "12c");
+ assert(sb.sputc('3') == '3');
+ assert(sb.str() == "123");
+ assert(sb.sputc('4') == '4');
+ assert(sb.str() == "1234");
+ assert(sb.sputc('5') == '5');
+ assert(sb.str() == "12345");
+ assert(sb.sputc('6') == '6');
+ assert(sb.str() == "123456");
+ assert(sb.sputc('7') == '7');
+ assert(sb.str() == "1234567");
+ assert(sb.sputc('8') == '8');
+ assert(sb.str() == "12345678");
+ assert(sb.sputc('9') == '9');
+ assert(sb.str() == "123456789");
+ assert(sb.sputc('0') == '0');
+ assert(sb.str() == "1234567890");
+ assert(sb.sputc('1') == '1');
+ assert(sb.str() == "12345678901");
+ }
+ {
+ testbuf<wchar_t> sb(L"abc");
+ assert(sb.sputc(L'1') == L'1');
+ assert(sb.str() == L"1bc");
+ assert(sb.sputc(L'2') == L'2');
+ assert(sb.str() == L"12c");
+ assert(sb.sputc(L'3') == L'3');
+ assert(sb.str() == L"123");
+ assert(sb.sputc(L'4') == L'4');
+ assert(sb.str() == L"1234");
+ assert(sb.sputc(L'5') == L'5');
+ assert(sb.str() == L"12345");
+ assert(sb.sputc(L'6') == L'6');
+ assert(sb.str() == L"123456");
+ assert(sb.sputc(L'7') == L'7');
+ assert(sb.str() == L"1234567");
+ assert(sb.sputc(L'8') == L'8');
+ assert(sb.str() == L"12345678");
+ assert(sb.sputc(L'9') == L'9');
+ assert(sb.str() == L"123456789");
+ assert(sb.sputc(L'0') == L'0');
+ assert(sb.str() == L"1234567890");
+ assert(sb.sputc(L'1') == L'1');
+ assert(sb.str() == L"12345678901");
+ }
+ {
+ testbuf<char> sb("abc", std::ios_base::app | std::ios_base::out);
+ assert(sb.sputc('1') == '1');
+ assert(sb.str() == "abc1");
+ assert(sb.sputc('2') == '2');
+ assert(sb.str() == "abc12");
+ }
+}
diff --git a/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/pbackfail.pass.cpp b/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/pbackfail.pass.cpp
new file mode 100644
index 0000000000000..4af0e63029a7f
--- /dev/null
+++ b/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/pbackfail.pass.cpp
@@ -0,0 +1,92 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
+// class basic_stringbuf
+
+// int_type pbackfail(int_type c = traits::eof());
+
+#include <sstream>
+#include <cassert>
+
+template <class CharT>
+struct testbuf
+ : public std::basic_stringbuf<CharT>
+{
+ typedef std::basic_stringbuf<CharT> base;
+ explicit testbuf(const std::basic_string<CharT>& str,
+ std::ios_base::openmode which = std::ios_base::in | std::ios_base::out)
+ : base(str, which) {}
+
+ typename base::int_type
+ pbackfail(typename base::int_type c = base::type_traits::eof())
+ {return base::pbackfail(c);}
+
+ void pbump(int n) {base::pbump(n);}
+};
+
+int main()
+{
+ {
+ testbuf<char> sb("123", std::ios_base::in);
+ assert(sb.sgetc() == '1');
+ assert(sb.snextc() == '2');
+ assert(sb.snextc() == '3');
+ assert(sb.sgetc() == '3');
+ assert(sb.snextc() == std::char_traits<char>::eof());
+ assert(sb.pbackfail('3') == '3');
+ assert(sb.pbackfail('3') == std::char_traits<char>::eof());
+ assert(sb.pbackfail('2') == '2');
+ assert(sb.pbackfail(std::char_traits<char>::eof()) != std::char_traits<char>::eof());
+ assert(sb.pbackfail(std::char_traits<char>::eof()) == std::char_traits<char>::eof());
+ assert(sb.str() == "123");
+ }
+ {
+ testbuf<char> sb("123");
+ assert(sb.sgetc() == '1');
+ assert(sb.snextc() == '2');
+ assert(sb.snextc() == '3');
+ assert(sb.sgetc() == '3');
+ assert(sb.snextc() == std::char_traits<char>::eof());
+ assert(sb.pbackfail('3') == '3');
+ assert(sb.pbackfail('3') == '3');
+ assert(sb.pbackfail(std::char_traits<char>::eof()) != std::char_traits<char>::eof());
+ assert(sb.pbackfail(std::char_traits<char>::eof()) == std::char_traits<char>::eof());
+ assert(sb.str() == "133");
+ }
+ {
+ testbuf<wchar_t> sb(L"123", std::ios_base::in);
+ assert(sb.sgetc() == L'1');
+ assert(sb.snextc() == L'2');
+ assert(sb.snextc() == L'3');
+ assert(sb.sgetc() == L'3');
+ assert(sb.snextc() == std::char_traits<wchar_t>::eof());
+ assert(sb.pbackfail(L'3') == L'3');
+ assert(sb.pbackfail(L'3') == std::char_traits<wchar_t>::eof());
+ assert(sb.pbackfail(L'2') == L'2');
+ assert(sb.pbackfail(std::char_traits<wchar_t>::eof()) != std::char_traits<wchar_t>::eof());
+ assert(sb.pbackfail(std::char_traits<wchar_t>::eof()) == std::char_traits<wchar_t>::eof());
+ assert(sb.str() == L"123");
+ }
+ {
+ testbuf<wchar_t> sb(L"123");
+ assert(sb.sgetc() == L'1');
+ assert(sb.snextc() == L'2');
+ assert(sb.snextc() == L'3');
+ assert(sb.sgetc() == L'3');
+ assert(sb.snextc() == std::char_traits<wchar_t>::eof());
+ assert(sb.pbackfail(L'3') == L'3');
+ assert(sb.pbackfail(L'3') == L'3');
+ assert(sb.pbackfail(std::char_traits<wchar_t>::eof()) != std::char_traits<wchar_t>::eof());
+ assert(sb.pbackfail(std::char_traits<wchar_t>::eof()) == std::char_traits<wchar_t>::eof());
+ assert(sb.str() == L"133");
+ }
+}
diff --git a/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/seekoff.pass.cpp b/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/seekoff.pass.cpp
new file mode 100644
index 0000000000000..6d20db13189ae
--- /dev/null
+++ b/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/seekoff.pass.cpp
@@ -0,0 +1,143 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
+// class basic_stringbuf
+
+// pos_type seekoff(off_type off, ios_base::seekdir way,
+// ios_base::openmode which = ios_base::in | ios_base::out);
+
+#include <sstream>
+#include <cassert>
+
+int main()
+{
+ {
+ std::stringbuf sb("0123456789", std::ios_base::in);
+ assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::out) == -1);
+ assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::out) == -1);
+ assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::out) == -1);
+ assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::in | std::ios_base::out) == -1);
+ assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::in | std::ios_base::out) == -1);
+ assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::in | std::ios_base::out) == -1);
+ assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::in) == 3);
+ assert(sb.sgetc() == '3');
+ assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::in) == 6);
+ assert(sb.sgetc() == '6');
+ assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::in) == 7);
+ assert(sb.sgetc() == '7');
+ }
+ {
+ std::stringbuf sb("0123456789", std::ios_base::out);
+ assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::in) == -1);
+ assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::in) == -1);
+ assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::in) == -1);
+ assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::out | std::ios_base::in) == -1);
+ assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::out | std::ios_base::in) == -1);
+ assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::out | std::ios_base::in) == -1);
+ assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::out) == 3);
+ assert(sb.sputc('a') == 'a');
+ assert(sb.str() == "012a456789");
+ assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::out) == 7);
+ assert(sb.sputc('b') == 'b');
+ assert(sb.str() == "012a456b89");
+ assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::out) == 7);
+ assert(sb.sputc('c') == 'c');
+ assert(sb.str() == "012a456c89");
+ }
+ {
+ std::stringbuf sb("0123456789");
+ assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::in) == 3);
+ assert(sb.sgetc() == '3');
+ assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::in) == 6);
+ assert(sb.sgetc() == '6');
+ assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::in) == 7);
+ assert(sb.sgetc() == '7');
+ assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::out | std::ios_base::in) == 3);
+ assert(sb.sgetc() == '3');
+ assert(sb.sputc('a') == 'a');
+ assert(sb.str() == "012a456789");
+ assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::out | std::ios_base::in) == -1);
+ assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::out | std::ios_base::in) == 7);
+ assert(sb.sgetc() == '7');
+ assert(sb.sputc('c') == 'c');
+ assert(sb.str() == "012a456c89");
+ assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::out) == 3);
+ assert(sb.sputc('3') == '3');
+ assert(sb.str() == "0123456c89");
+ assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::out) == 7);
+ assert(sb.sputc('7') == '7');
+ assert(sb.str() == "0123456789");
+ assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::out) == 7);
+ assert(sb.sputc('c') == 'c');
+ assert(sb.str() == "0123456c89");
+ }
+ {
+ std::wstringbuf sb(L"0123456789", std::ios_base::in);
+ assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::out) == -1);
+ assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::out) == -1);
+ assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::out) == -1);
+ assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::in | std::ios_base::out) == -1);
+ assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::in | std::ios_base::out) == -1);
+ assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::in | std::ios_base::out) == -1);
+ assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::in) == 3);
+ assert(sb.sgetc() == L'3');
+ assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::in) == 6);
+ assert(sb.sgetc() == L'6');
+ assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::in) == 7);
+ assert(sb.sgetc() == L'7');
+ }
+ {
+ std::wstringbuf sb(L"0123456789", std::ios_base::out);
+ assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::in) == -1);
+ assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::in) == -1);
+ assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::in) == -1);
+ assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::out | std::ios_base::in) == -1);
+ assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::out | std::ios_base::in) == -1);
+ assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::out | std::ios_base::in) == -1);
+ assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::out) == 3);
+ assert(sb.sputc(L'a') == L'a');
+ assert(sb.str() == L"012a456789");
+ assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::out) == 7);
+ assert(sb.sputc(L'b') == L'b');
+ assert(sb.str() == L"012a456b89");
+ assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::out) == 7);
+ assert(sb.sputc(L'c') == L'c');
+ assert(sb.str() == L"012a456c89");
+ }
+ {
+ std::wstringbuf sb(L"0123456789");
+ assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::in) == 3);
+ assert(sb.sgetc() == L'3');
+ assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::in) == 6);
+ assert(sb.sgetc() == L'6');
+ assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::in) == 7);
+ assert(sb.sgetc() == L'7');
+ assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::out | std::ios_base::in) == 3);
+ assert(sb.sgetc() == L'3');
+ assert(sb.sputc(L'a') == L'a');
+ assert(sb.str() == L"012a456789");
+ assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::out | std::ios_base::in) == -1);
+ assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::out | std::ios_base::in) == 7);
+ assert(sb.sgetc() == L'7');
+ assert(sb.sputc(L'c') == L'c');
+ assert(sb.str() == L"012a456c89");
+ assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::out) == 3);
+ assert(sb.sputc(L'3') == L'3');
+ assert(sb.str() == L"0123456c89");
+ assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::out) == 7);
+ assert(sb.sputc(L'7') == L'7');
+ assert(sb.str() == L"0123456789");
+ assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::out) == 7);
+ assert(sb.sputc(L'c') == L'c');
+ assert(sb.str() == L"0123456c89");
+ }
+}
diff --git a/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/seekpos.pass.cpp b/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/seekpos.pass.cpp
new file mode 100644
index 0000000000000..2b809a887a35a
--- /dev/null
+++ b/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/seekpos.pass.cpp
@@ -0,0 +1,77 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
+// class basic_stringbuf
+
+// pos_type seekpos(pos_type sp,
+// ios_base::openmode which = ios_base::in | ios_base::out);
+
+#include <sstream>
+#include <cassert>
+
+int main()
+{
+ {
+ std::stringbuf sb("0123456789", std::ios_base::in);
+ assert(sb.pubseekpos(3, std::ios_base::out) == -1);
+ assert(sb.pubseekpos(3, std::ios_base::in | std::ios_base::out) == -1);
+ assert(sb.pubseekpos(3, std::ios_base::in) == 3);
+ assert(sb.sgetc() == '3');
+ }
+ {
+ std::stringbuf sb("0123456789", std::ios_base::out);
+ assert(sb.pubseekpos(3, std::ios_base::in) == -1);
+ assert(sb.pubseekpos(3, std::ios_base::out | std::ios_base::in) == -1);
+ assert(sb.pubseekpos(3, std::ios_base::out) == 3);
+ assert(sb.sputc('a') == 'a');
+ assert(sb.str() == "012a456789");
+ }
+ {
+ std::stringbuf sb("0123456789");
+ assert(sb.pubseekpos(3, std::ios_base::in) == 3);
+ assert(sb.sgetc() == '3');
+ assert(sb.pubseekpos(3, std::ios_base::out | std::ios_base::in) == 3);
+ assert(sb.sgetc() == '3');
+ assert(sb.sputc('a') == 'a');
+ assert(sb.str() == "012a456789");
+ assert(sb.pubseekpos(3, std::ios_base::out) == 3);
+ assert(sb.sputc('3') == '3');
+ assert(sb.str() == "0123456789");
+ }
+ {
+ std::wstringbuf sb(L"0123456789", std::ios_base::in);
+ assert(sb.pubseekpos(3, std::ios_base::out) == -1);
+ assert(sb.pubseekpos(3, std::ios_base::in | std::ios_base::out) == -1);
+ assert(sb.pubseekpos(3, std::ios_base::in) == 3);
+ assert(sb.sgetc() == L'3');
+ }
+ {
+ std::wstringbuf sb(L"0123456789", std::ios_base::out);
+ assert(sb.pubseekpos(3, std::ios_base::in) == -1);
+ assert(sb.pubseekpos(3, std::ios_base::out | std::ios_base::in) == -1);
+ assert(sb.pubseekpos(3, std::ios_base::out) == 3);
+ assert(sb.sputc(L'a') == L'a');
+ assert(sb.str() == L"012a456789");
+ }
+ {
+ std::wstringbuf sb(L"0123456789");
+ assert(sb.pubseekpos(3, std::ios_base::in) == 3);
+ assert(sb.sgetc() == L'3');
+ assert(sb.pubseekpos(3, std::ios_base::out | std::ios_base::in) == 3);
+ assert(sb.sgetc() == L'3');
+ assert(sb.sputc(L'a') == L'a');
+ assert(sb.str() == L"012a456789");
+ assert(sb.pubseekpos(3, std::ios_base::out) == 3);
+ assert(sb.sputc(L'3') == L'3');
+ assert(sb.str() == L"0123456789");
+ }
+}
diff --git a/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/setbuf.pass.cpp b/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/setbuf.pass.cpp
new file mode 100644
index 0000000000000..7130f5b8646f3
--- /dev/null
+++ b/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/setbuf.pass.cpp
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
+// class basic_stringbuf
+
+// basic_streambuf<charT,traits>* setbuf(charT* s, streamsize n);
+
+#include <sstream>
+#include <cassert>
+
+int main()
+{
+ {
+ std::stringbuf sb("0123456789");
+ assert(sb.pubsetbuf(0, 0) == &sb);
+ assert(sb.str() == "0123456789");
+ }
+ {
+ std::wstringbuf sb(L"0123456789");
+ assert(sb.pubsetbuf(0, 0) == &sb);
+ assert(sb.str() == L"0123456789");
+ }
+}
diff --git a/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/underflow.pass.cpp b/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/underflow.pass.cpp
new file mode 100644
index 0000000000000..3641af239d7d4
--- /dev/null
+++ b/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/underflow.pass.cpp
@@ -0,0 +1,70 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
+// class basic_stringbuf
+
+// int_type underflow();
+
+#include <sstream>
+#include <cassert>
+
+template <class CharT>
+struct testbuf
+ : public std::basic_stringbuf<CharT>
+{
+ typedef std::basic_stringbuf<CharT> base;
+ explicit testbuf(const std::basic_string<CharT>& str)
+ : base(str) {}
+
+ typename base::int_type underflow() {return base::underflow();}
+ void pbump(int n) {base::pbump(n);}
+};
+
+int main()
+{
+ {
+ testbuf<char> sb("123");
+ sb.pbump(3);
+ assert(sb.underflow() == '1');
+ assert(sb.underflow() == '1');
+ assert(sb.snextc() == '2');
+ assert(sb.underflow() == '2');
+ assert(sb.underflow() == '2');
+ assert(sb.snextc() == '3');
+ assert(sb.underflow() == '3');
+ assert(sb.underflow() == '3');
+ assert(sb.snextc() == std::char_traits<char>::eof());
+ assert(sb.underflow() == std::char_traits<char>::eof());
+ assert(sb.underflow() == std::char_traits<char>::eof());
+ sb.sputc('4');
+ assert(sb.underflow() == '4');
+ assert(sb.underflow() == '4');
+ }
+ {
+ testbuf<wchar_t> sb(L"123");
+ sb.pbump(3);
+ assert(sb.underflow() == L'1');
+ assert(sb.underflow() == L'1');
+ assert(sb.snextc() == L'2');
+ assert(sb.underflow() == L'2');
+ assert(sb.underflow() == L'2');
+ assert(sb.snextc() == L'3');
+ assert(sb.underflow() == L'3');
+ assert(sb.underflow() == L'3');
+ assert(sb.snextc() == std::char_traits<wchar_t>::eof());
+ assert(sb.underflow() == std::char_traits<wchar_t>::eof());
+ assert(sb.underflow() == std::char_traits<wchar_t>::eof());
+ sb.sputc(L'4');
+ assert(sb.underflow() == L'4');
+ assert(sb.underflow() == L'4');
+ }
+}