libcxx initial import
llvm-svn: 103490
diff --git a/libcxx/test/input.output/file.streams/fstreams/filebuf.virtuals/overflow.pass.cpp b/libcxx/test/input.output/file.streams/fstreams/filebuf.virtuals/overflow.pass.cpp
new file mode 100644
index 0000000..c01942b
--- /dev/null
+++ b/libcxx/test/input.output/file.streams/fstreams/filebuf.virtuals/overflow.pass.cpp
@@ -0,0 +1,140 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <fstream>
+
+// int_type overflow(int_type c = traits::eof());
+
+// This test is not entirely portable
+
+#include <fstream>
+#include <cassert>
+
+template <class CharT>
+struct test_buf
+ : public std::basic_filebuf<CharT>
+{
+ typedef std::basic_filebuf<CharT> base;
+ typedef typename base::char_type char_type;
+ typedef typename base::int_type int_type;
+ typedef typename base::traits_type traits_type;
+
+ char_type* pbase() const {return base::pbase();}
+ char_type* pptr() const {return base::pptr();}
+ char_type* epptr() const {return base::epptr();}
+ void gbump(int n) {base::gbump(n);}
+
+ virtual int_type overflow(int_type c = traits_type::eof()) {return base::overflow(c);}
+};
+
+int main()
+{
+ {
+ test_buf<char> f;
+ assert(f.open("overflow.dat", std::ios_base::out) != 0);
+ assert(f.is_open());
+ assert(f.pbase() == 0);
+ assert(f.pptr() == 0);
+ assert(f.epptr() == 0);
+ assert(f.overflow('a') == 'a');
+ assert(f.pbase() != 0);
+ assert(f.pptr() == f.pbase());
+ assert(f.epptr() - f.pbase() == 4095);
+ }
+ {
+ test_buf<char> f;
+ assert(f.open("overflow.dat", std::ios_base::in) != 0);
+ assert(f.is_open());
+ assert(f.sgetc() == 'a');
+ }
+ std::remove("overflow.dat");
+ {
+ test_buf<char> f;
+ f.pubsetbuf(0, 0);
+ assert(f.open("overflow.dat", std::ios_base::out) != 0);
+ assert(f.is_open());
+ assert(f.pbase() == 0);
+ assert(f.pptr() == 0);
+ assert(f.epptr() == 0);
+ assert(f.overflow('a') == 'a');
+ assert(f.pbase() == 0);
+ assert(f.pptr() == 0);
+ assert(f.epptr() == 0);
+ }
+ {
+ test_buf<char> f;
+ assert(f.open("overflow.dat", std::ios_base::in) != 0);
+ assert(f.is_open());
+ assert(f.sgetc() == 'a');
+ }
+ std::remove("overflow.dat");
+ {
+ test_buf<wchar_t> f;
+ assert(f.open("overflow.dat", std::ios_base::out) != 0);
+ assert(f.is_open());
+ assert(f.pbase() == 0);
+ assert(f.pptr() == 0);
+ assert(f.epptr() == 0);
+ assert(f.overflow(L'a') == L'a');
+ assert(f.pbase() != 0);
+ assert(f.pptr() == f.pbase());
+ assert(f.epptr() - f.pbase() == 4095);
+ }
+ {
+ test_buf<wchar_t> f;
+ assert(f.open("overflow.dat", std::ios_base::in) != 0);
+ assert(f.is_open());
+ assert(f.sgetc() == L'a');
+ }
+ std::remove("overflow.dat");
+ {
+ test_buf<wchar_t> f;
+ f.pubsetbuf(0, 0);
+ assert(f.open("overflow.dat", std::ios_base::out) != 0);
+ assert(f.is_open());
+ assert(f.pbase() == 0);
+ assert(f.pptr() == 0);
+ assert(f.epptr() == 0);
+ assert(f.overflow(L'a') == L'a');
+ assert(f.pbase() == 0);
+ assert(f.pptr() == 0);
+ assert(f.epptr() == 0);
+ }
+ {
+ test_buf<wchar_t> f;
+ assert(f.open("overflow.dat", std::ios_base::in) != 0);
+ assert(f.is_open());
+ assert(f.sgetc() == L'a');
+ }
+ std::remove("overflow.dat");
+ {
+ test_buf<wchar_t> f;
+ f.pubimbue(std::locale("en_US.UTF-8"));
+ assert(f.open("overflow.dat", std::ios_base::out) != 0);
+ assert(f.sputc(0x4E51) == 0x4E51);
+ assert(f.sputc(0x4E52) == 0x4E52);
+ assert(f.sputc(0x4E53) == 0x4E53);
+ }
+ {
+ test_buf<char> f;
+ assert(f.open("overflow.dat", std::ios_base::in) != 0);
+ assert(f.is_open());
+ assert(f.sbumpc() == 0xE4);
+ assert(f.sbumpc() == 0xB9);
+ assert(f.sbumpc() == 0x91);
+ assert(f.sbumpc() == 0xE4);
+ assert(f.sbumpc() == 0xB9);
+ assert(f.sbumpc() == 0x92);
+ assert(f.sbumpc() == 0xE4);
+ assert(f.sbumpc() == 0xB9);
+ assert(f.sbumpc() == 0x93);
+ assert(f.sbumpc() == -1);
+ }
+ std::remove("overflow.dat");
+}
diff --git a/libcxx/test/input.output/file.streams/fstreams/filebuf.virtuals/pbackfail.pass.cpp b/libcxx/test/input.output/file.streams/fstreams/filebuf.virtuals/pbackfail.pass.cpp
new file mode 100644
index 0000000..4b0a165
--- /dev/null
+++ b/libcxx/test/input.output/file.streams/fstreams/filebuf.virtuals/pbackfail.pass.cpp
@@ -0,0 +1,56 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <fstream>
+
+// int_type pbackfail(int_type c = traits::eof());
+
+// This test is not entirely portable
+
+#include <fstream>
+#include <cassert>
+
+template <class CharT>
+struct test_buf
+ : public std::basic_filebuf<CharT>
+{
+ typedef std::basic_filebuf<CharT> base;
+ typedef typename base::char_type char_type;
+ typedef typename base::int_type int_type;
+ typedef typename base::traits_type traits_type;
+
+ char_type* eback() const {return base::eback();}
+ char_type* gptr() const {return base::gptr();}
+ char_type* egptr() const {return base::egptr();}
+ void gbump(int n) {base::gbump(n);}
+
+ virtual int_type pbackfail(int_type c = traits_type::eof()) {return base::pbackfail(c);}
+};
+
+int main()
+{
+ {
+ test_buf<char> f;
+ assert(f.open("underflow.dat", std::ios_base::in) != 0);
+ assert(f.is_open());
+ assert(f.sbumpc() == '1');
+ assert(f.sgetc() == '2');
+ assert(f.pbackfail('a') == -1);
+ }
+ {
+ test_buf<char> f;
+ assert(f.open("underflow.dat", std::ios_base::in | std::ios_base::out) != 0);
+ assert(f.is_open());
+ assert(f.sbumpc() == '1');
+ assert(f.sgetc() == '2');
+ assert(f.pbackfail('a') == 'a');
+ assert(f.sbumpc() == 'a');
+ assert(f.sgetc() == '2');
+ }
+}
diff --git a/libcxx/test/input.output/file.streams/fstreams/filebuf.virtuals/seekoff.pass.cpp b/libcxx/test/input.output/file.streams/fstreams/filebuf.virtuals/seekoff.pass.cpp
new file mode 100644
index 0000000..27584ca
--- /dev/null
+++ b/libcxx/test/input.output/file.streams/fstreams/filebuf.virtuals/seekoff.pass.cpp
@@ -0,0 +1,83 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <fstream>
+
+// pos_type seekoff(off_type off, ios_base::seekdir way,
+// ios_base::openmode which = ios_base::in | ios_base::out);
+// pos_type seekpos(pos_type sp,
+// ios_base::openmode which = ios_base::in | ios_base::out);
+
+// This test is not entirely portable
+
+#include <fstream>
+#include <cassert>
+
+template <class CharT>
+struct test_buf
+ : public std::basic_filebuf<CharT>
+{
+ typedef std::basic_filebuf<CharT> base;
+ typedef typename base::char_type char_type;
+ typedef typename base::int_type int_type;
+ typedef typename base::pos_type pos_type;
+
+ char_type* eback() const {return base::eback();}
+ char_type* gptr() const {return base::gptr();}
+ char_type* egptr() const {return base::egptr();}
+ void gbump(int n) {base::gbump(n);}
+
+ virtual int_type underflow() {return base::underflow();}
+};
+
+int main()
+{
+ {
+ char buf[10];
+ typedef std::filebuf::pos_type pos_type;
+ std::filebuf f;
+ f.pubsetbuf(buf, sizeof(buf));
+ assert(f.open("seekoff.dat", std::ios_base::in | std::ios_base::out
+ | std::ios_base::trunc) != 0);
+ assert(f.is_open());
+ f.sputn("abcdefghijklmnopqrstuvwxyz", 26);
+ assert(buf[0] == 'v');
+ pos_type p = f.pubseekoff(-15, std::ios_base::cur);
+ assert(p == 11);
+ assert(f.sgetc() == 'l');
+ f.pubseekoff(0, std::ios_base::beg);
+ assert(f.sgetc() == 'a');
+ f.pubseekoff(-1, std::ios_base::end);
+ assert(f.sgetc() == 'z');
+ assert(f.pubseekpos(p) == p);
+ assert(f.sgetc() == 'l');
+ }
+ std::remove("seekoff.dat");
+ {
+ wchar_t buf[10];
+ typedef std::filebuf::pos_type pos_type;
+ std::wfilebuf f;
+ f.pubsetbuf(buf, sizeof(buf)/sizeof(buf[0]));
+ assert(f.open("seekoff.dat", std::ios_base::in | std::ios_base::out
+ | std::ios_base::trunc) != 0);
+ assert(f.is_open());
+ f.sputn(L"abcdefghijklmnopqrstuvwxyz", 26);
+ assert(buf[0] == L'v');
+ pos_type p = f.pubseekoff(-15, std::ios_base::cur);
+ assert(p == 11);
+ assert(f.sgetc() == L'l');
+ f.pubseekoff(0, std::ios_base::beg);
+ assert(f.sgetc() == L'a');
+ f.pubseekoff(-1, std::ios_base::end);
+ assert(f.sgetc() == L'z');
+ assert(f.pubseekpos(p) == p);
+ assert(f.sgetc() == L'l');
+ }
+ std::remove("seekoff.dat");
+}
diff --git a/libcxx/test/input.output/file.streams/fstreams/filebuf.virtuals/underflow.dat b/libcxx/test/input.output/file.streams/fstreams/filebuf.virtuals/underflow.dat
new file mode 100644
index 0000000..e2e107a
--- /dev/null
+++ b/libcxx/test/input.output/file.streams/fstreams/filebuf.virtuals/underflow.dat
@@ -0,0 +1 @@
+123456789
\ No newline at end of file
diff --git a/libcxx/test/input.output/file.streams/fstreams/filebuf.virtuals/underflow.pass.cpp b/libcxx/test/input.output/file.streams/fstreams/filebuf.virtuals/underflow.pass.cpp
new file mode 100644
index 0000000..c704d45
--- /dev/null
+++ b/libcxx/test/input.output/file.streams/fstreams/filebuf.virtuals/underflow.pass.cpp
@@ -0,0 +1,119 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <fstream>
+
+// int_type underflow();
+
+// This test is not entirely portable
+
+#include <fstream>
+#include <cassert>
+
+template <class CharT>
+struct test_buf
+ : public std::basic_filebuf<CharT>
+{
+ typedef std::basic_filebuf<CharT> base;
+ typedef typename base::char_type char_type;
+ typedef typename base::int_type int_type;
+
+ char_type* eback() const {return base::eback();}
+ char_type* gptr() const {return base::gptr();}
+ char_type* egptr() const {return base::egptr();}
+ void gbump(int n) {base::gbump(n);}
+
+ virtual int_type underflow() {return base::underflow();}
+};
+
+int main()
+{
+ {
+ test_buf<char> f;
+ assert(f.open("underflow.dat", std::ios_base::in) != 0);
+ assert(f.is_open());
+ assert(f.eback() == 0);
+ assert(f.gptr() == 0);
+ assert(f.egptr() == 0);
+ assert(f.underflow() == '1');
+ assert(f.eback() != 0);
+ assert(f.eback() == f.gptr());
+ assert(*f.gptr() == '1');
+ assert(f.egptr() - f.eback() == 9);
+ }
+ {
+ test_buf<char> f;
+ assert(f.open("underflow.dat", std::ios_base::in) != 0);
+ assert(f.pubsetbuf(0, 0));
+ assert(f.is_open());
+ assert(f.eback() == 0);
+ assert(f.gptr() == 0);
+ assert(f.egptr() == 0);
+ assert(f.underflow() == '1');
+ assert(f.eback() != 0);
+ assert(f.eback() == f.gptr());
+ assert(*f.gptr() == '1');
+ assert(f.egptr() - f.eback() == 8);
+ f.gbump(8);
+ assert(f.sgetc() == '9');
+ assert(f.eback()[0] == '5');
+ assert(f.eback()[1] == '6');
+ assert(f.eback()[2] == '7');
+ assert(f.eback()[3] == '8');
+ assert(f.gptr() - f.eback() == 4);
+ assert(*f.gptr() == '9');
+ assert(f.egptr() - f.gptr() == 1);
+ }
+ {
+ test_buf<wchar_t> f;
+ assert(f.open("underflow.dat", std::ios_base::in) != 0);
+ assert(f.is_open());
+ assert(f.eback() == 0);
+ assert(f.gptr() == 0);
+ assert(f.egptr() == 0);
+ assert(f.underflow() == L'1');
+ assert(f.eback() != 0);
+ assert(f.eback() == f.gptr());
+ assert(*f.gptr() == L'1');
+ assert(f.egptr() - f.eback() == 9);
+ }
+ {
+ test_buf<wchar_t> f;
+ assert(f.pubsetbuf(0, 0));
+ assert(f.open("underflow.dat", std::ios_base::in) != 0);
+ assert(f.is_open());
+ assert(f.eback() == 0);
+ assert(f.gptr() == 0);
+ assert(f.egptr() == 0);
+ assert(f.underflow() == L'1');
+ assert(f.eback() != 0);
+ assert(f.eback() == f.gptr());
+ assert(*f.gptr() == L'1');
+ assert(f.egptr() - f.eback() == 8);
+ f.gbump(8);
+ assert(f.sgetc() == L'9');
+ assert(f.eback()[0] == L'5');
+ assert(f.eback()[1] == L'6');
+ assert(f.eback()[2] == L'7');
+ assert(f.eback()[3] == L'8');
+ assert(f.gptr() - f.eback() == 4);
+ assert(*f.gptr() == L'9');
+ assert(f.egptr() - f.gptr() == 1);
+ }
+ {
+ test_buf<wchar_t> f;
+ f.pubimbue(std::locale("en_US.UTF-8"));
+ assert(f.open("underflow_utf8.dat", std::ios_base::in) != 0);
+ assert(f.is_open());
+ assert(f.sbumpc() == 0x4E51);
+ assert(f.sbumpc() == 0x4E52);
+ assert(f.sbumpc() == 0x4E53);
+ assert(f.sbumpc() == -1);
+ }
+}
diff --git a/libcxx/test/input.output/file.streams/fstreams/filebuf.virtuals/underflow_utf8.dat b/libcxx/test/input.output/file.streams/fstreams/filebuf.virtuals/underflow_utf8.dat
new file mode 100644
index 0000000..ee7063e
--- /dev/null
+++ b/libcxx/test/input.output/file.streams/fstreams/filebuf.virtuals/underflow_utf8.dat
@@ -0,0 +1 @@
+乑乒乓
\ No newline at end of file